Files
outline/shared/editor/nodes/Doc.ts
Apoorv Mishra 2fe887ef57 Refactor Placeholder plugin to make it configurable (#9224)
* 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
2025-05-16 20:58:06 -04:00

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,
},
]),
];
}
}