mirror of
https://github.com/outline/outline.git
synced 2026-11-21 05:24:03 +03:00
* fix: refactor to make configurable * fix: make it a reusable plugin so that it can be colocated with nodes eligible for placeholders * fix: cond -> condition * fix: `pos` -> `$start` as param * fix: cleanup
43 lines
958 B
TypeScript
43 lines
958 B
TypeScript
import isNull from "lodash/isNull";
|
|
import {
|
|
NodeSpec,
|
|
Node as ProsemirrorNode,
|
|
ResolvedPos,
|
|
} from "prosemirror-model";
|
|
import { EditorState } from "prosemirror-state";
|
|
import { PlaceholderPlugin } from "../plugins/PlaceholderPlugin";
|
|
import Node from "./Node";
|
|
|
|
export default class Doc extends Node {
|
|
get name() {
|
|
return "doc";
|
|
}
|
|
|
|
get schema(): NodeSpec {
|
|
return {
|
|
content: "block+",
|
|
};
|
|
}
|
|
|
|
get plugins() {
|
|
return [
|
|
new PlaceholderPlugin([
|
|
{
|
|
condition: (
|
|
node: ProsemirrorNode,
|
|
$start: ResolvedPos,
|
|
parent: ProsemirrorNode | null,
|
|
state: EditorState
|
|
) =>
|
|
node.textContent === "" &&
|
|
!isNull(parent) &&
|
|
parent.type === state.doc.type &&
|
|
parent.childCount === 1 &&
|
|
$start.index($start.depth - 1) === 0,
|
|
text: this.options.placeholder,
|
|
},
|
|
]),
|
|
];
|
|
}
|
|
}
|