@tiptap/extension-placeholder 3.0.0-next.4 → 3.0.0-next.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024, Tiptap GmbH
3
+ Copyright (c) 2025, Tiptap GmbH
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/index.cjs CHANGED
@@ -20,73 +20,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- Placeholder: () => Placeholder,
23
+ Placeholder: () => import_extensions2.Placeholder,
24
+ PlaceholderOptions: () => import_extensions2.PlaceholderOptions,
24
25
  default: () => index_default
25
26
  });
26
27
  module.exports = __toCommonJS(index_exports);
27
-
28
- // src/placeholder.ts
29
- var import_core = require("@tiptap/core");
30
- var import_state = require("@tiptap/pm/state");
31
- var import_view = require("@tiptap/pm/view");
32
- var Placeholder = import_core.Extension.create({
33
- name: "placeholder",
34
- addOptions() {
35
- return {
36
- emptyEditorClass: "is-editor-empty",
37
- emptyNodeClass: "is-empty",
38
- placeholder: "Write something \u2026",
39
- showOnlyWhenEditable: true,
40
- showOnlyCurrent: true,
41
- includeChildren: false
42
- };
43
- },
44
- addProseMirrorPlugins() {
45
- return [
46
- new import_state.Plugin({
47
- key: new import_state.PluginKey("placeholder"),
48
- props: {
49
- decorations: ({ doc, selection }) => {
50
- const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
51
- const { anchor } = selection;
52
- const decorations = [];
53
- if (!active) {
54
- return null;
55
- }
56
- const isEmptyDoc = this.editor.isEmpty;
57
- doc.descendants((node, pos) => {
58
- const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
59
- const isEmpty = !node.isLeaf && (0, import_core.isNodeEmpty)(node);
60
- if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
61
- const classes = [this.options.emptyNodeClass];
62
- if (isEmptyDoc) {
63
- classes.push(this.options.emptyEditorClass);
64
- }
65
- const decoration = import_view.Decoration.node(pos, pos + node.nodeSize, {
66
- class: classes.join(" "),
67
- "data-placeholder": typeof this.options.placeholder === "function" ? this.options.placeholder({
68
- editor: this.editor,
69
- node,
70
- pos,
71
- hasAnchor
72
- }) : this.options.placeholder
73
- });
74
- decorations.push(decoration);
75
- }
76
- return this.options.includeChildren;
77
- });
78
- return import_view.DecorationSet.create(doc, decorations);
79
- }
80
- }
81
- })
82
- ];
83
- }
84
- });
85
-
86
- // src/index.ts
87
- var index_default = Placeholder;
28
+ var import_extensions = require("@tiptap/extensions");
29
+ var import_extensions2 = require("@tiptap/extensions");
30
+ var index_default = import_extensions.Placeholder;
88
31
  // Annotate the CommonJS export names for ESM import in node:
89
32
  0 && (module.exports = {
90
- Placeholder
33
+ Placeholder,
34
+ PlaceholderOptions
91
35
  });
92
36
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/placeholder.ts"],"sourcesContent":["import { Placeholder } from './placeholder.js'\n\nexport * from './placeholder.js'\n\nexport default Placeholder\n","import { Editor, Extension, isNodeEmpty } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface PlaceholderOptions {\n /**\n * **The class name for the empty editor**\n * @default 'is-editor-empty'\n */\n emptyEditorClass: string\n\n /**\n * **The class name for empty nodes**\n * @default 'is-empty'\n */\n emptyNodeClass: string\n\n /**\n * **The placeholder content**\n *\n * You can use a function to return a dynamic placeholder or a string.\n * @default 'Write something …'\n */\n placeholder:\n | ((PlaceholderProps: { editor: Editor; node: ProsemirrorNode; pos: number; hasAnchor: boolean }) => string)\n | string\n\n /**\n * **Checks if the placeholder should be only shown when the editor is editable.**\n *\n * If true, the placeholder will only be shown when the editor is editable.\n * If false, the placeholder will always be shown.\n * @default true\n */\n showOnlyWhenEditable: boolean\n\n /**\n * **Checks if the placeholder should be only shown when the current node is empty.**\n *\n * If true, the placeholder will only be shown when the current node is empty.\n * If false, the placeholder will be shown when any node is empty.\n * @default true\n */\n showOnlyCurrent: boolean\n\n /**\n * **Controls if the placeholder should be shown for all descendents.**\n *\n * If true, the placeholder will be shown for all descendents.\n * If false, the placeholder will only be shown for the current node.\n * @default false\n */\n includeChildren: boolean\n}\n\n/**\n * This extension allows you to add a placeholder to your editor.\n * A placeholder is a text that appears when the editor or a node is empty.\n * @see https://www.tiptap.dev/api/extensions/placeholder\n */\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n addOptions() {\n return {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n includeChildren: false,\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('placeholder'),\n props: {\n decorations: ({ doc, selection }) => {\n const active = this.editor.isEditable || !this.options.showOnlyWhenEditable\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!active) {\n return null\n }\n\n const isEmptyDoc = this.editor.isEmpty\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize\n const isEmpty = !node.isLeaf && isNodeEmpty(node)\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const classes = [this.options.emptyNodeClass]\n\n if (isEmptyDoc) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder':\n typeof this.options.placeholder === 'function'\n ? this.options.placeholder({\n editor: this.editor,\n node,\n pos,\n hasAnchor,\n })\n : this.options.placeholder,\n })\n\n decorations.push(decoration)\n }\n\n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QAAQ,YAAY;AAAA,oBACvB,QAAQ,KAAK;AAAA,oBACb;AAAA,oBACA;AAAA,oBACA;AAAA,kBACF,CAAC,IACD,KAAK,QAAQ;AAAA,gBACrB,CAAC;AAED,4BAAY,KAAK,UAAU;AAAA,cAC7B;AAEA,qBAAO,KAAK,QAAQ;AAAA,YACtB,CAAC;AAED,mBAAO,0BAAc,OAAO,KAAK,WAAW;AAAA,UAC9C;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;AD3HD,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Placeholder } from '@tiptap/extensions'\n\nexport { Placeholder, PlaceholderOptions } from '@tiptap/extensions'\n\nexport default Placeholder\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA4B;AAE5B,IAAAA,qBAAgD;AAEhD,IAAO,gBAAQ;","names":["import_extensions"]}
package/dist/index.d.cts CHANGED
@@ -1,59 +1,2 @@
1
- import { Editor, Extension } from '@tiptap/core';
2
- import { Node } from '@tiptap/pm/model';
3
-
4
- interface PlaceholderOptions {
5
- /**
6
- * **The class name for the empty editor**
7
- * @default 'is-editor-empty'
8
- */
9
- emptyEditorClass: string;
10
- /**
11
- * **The class name for empty nodes**
12
- * @default 'is-empty'
13
- */
14
- emptyNodeClass: string;
15
- /**
16
- * **The placeholder content**
17
- *
18
- * You can use a function to return a dynamic placeholder or a string.
19
- * @default 'Write something …'
20
- */
21
- placeholder: ((PlaceholderProps: {
22
- editor: Editor;
23
- node: Node;
24
- pos: number;
25
- hasAnchor: boolean;
26
- }) => string) | string;
27
- /**
28
- * **Checks if the placeholder should be only shown when the editor is editable.**
29
- *
30
- * If true, the placeholder will only be shown when the editor is editable.
31
- * If false, the placeholder will always be shown.
32
- * @default true
33
- */
34
- showOnlyWhenEditable: boolean;
35
- /**
36
- * **Checks if the placeholder should be only shown when the current node is empty.**
37
- *
38
- * If true, the placeholder will only be shown when the current node is empty.
39
- * If false, the placeholder will be shown when any node is empty.
40
- * @default true
41
- */
42
- showOnlyCurrent: boolean;
43
- /**
44
- * **Controls if the placeholder should be shown for all descendents.**
45
- *
46
- * If true, the placeholder will be shown for all descendents.
47
- * If false, the placeholder will only be shown for the current node.
48
- * @default false
49
- */
50
- includeChildren: boolean;
51
- }
52
- /**
53
- * This extension allows you to add a placeholder to your editor.
54
- * A placeholder is a text that appears when the editor or a node is empty.
55
- * @see https://www.tiptap.dev/api/extensions/placeholder
56
- */
57
- declare const Placeholder: Extension<PlaceholderOptions, any>;
58
-
59
- export { Placeholder, type PlaceholderOptions, Placeholder as default };
1
+ import { Placeholder } from '@tiptap/extensions';
2
+ export { Placeholder, PlaceholderOptions, Placeholder as default } from '@tiptap/extensions';
package/dist/index.d.ts CHANGED
@@ -1,59 +1,2 @@
1
- import { Editor, Extension } from '@tiptap/core';
2
- import { Node } from '@tiptap/pm/model';
3
-
4
- interface PlaceholderOptions {
5
- /**
6
- * **The class name for the empty editor**
7
- * @default 'is-editor-empty'
8
- */
9
- emptyEditorClass: string;
10
- /**
11
- * **The class name for empty nodes**
12
- * @default 'is-empty'
13
- */
14
- emptyNodeClass: string;
15
- /**
16
- * **The placeholder content**
17
- *
18
- * You can use a function to return a dynamic placeholder or a string.
19
- * @default 'Write something …'
20
- */
21
- placeholder: ((PlaceholderProps: {
22
- editor: Editor;
23
- node: Node;
24
- pos: number;
25
- hasAnchor: boolean;
26
- }) => string) | string;
27
- /**
28
- * **Checks if the placeholder should be only shown when the editor is editable.**
29
- *
30
- * If true, the placeholder will only be shown when the editor is editable.
31
- * If false, the placeholder will always be shown.
32
- * @default true
33
- */
34
- showOnlyWhenEditable: boolean;
35
- /**
36
- * **Checks if the placeholder should be only shown when the current node is empty.**
37
- *
38
- * If true, the placeholder will only be shown when the current node is empty.
39
- * If false, the placeholder will be shown when any node is empty.
40
- * @default true
41
- */
42
- showOnlyCurrent: boolean;
43
- /**
44
- * **Controls if the placeholder should be shown for all descendents.**
45
- *
46
- * If true, the placeholder will be shown for all descendents.
47
- * If false, the placeholder will only be shown for the current node.
48
- * @default false
49
- */
50
- includeChildren: boolean;
51
- }
52
- /**
53
- * This extension allows you to add a placeholder to your editor.
54
- * A placeholder is a text that appears when the editor or a node is empty.
55
- * @see https://www.tiptap.dev/api/extensions/placeholder
56
- */
57
- declare const Placeholder: Extension<PlaceholderOptions, any>;
58
-
59
- export { Placeholder, type PlaceholderOptions, Placeholder as default };
1
+ import { Placeholder } from '@tiptap/extensions';
2
+ export { Placeholder, PlaceholderOptions, Placeholder as default } from '@tiptap/extensions';
package/dist/index.js CHANGED
@@ -1,65 +1,10 @@
1
- // src/placeholder.ts
2
- import { Extension, isNodeEmpty } from "@tiptap/core";
3
- import { Plugin, PluginKey } from "@tiptap/pm/state";
4
- import { Decoration, DecorationSet } from "@tiptap/pm/view";
5
- var Placeholder = Extension.create({
6
- name: "placeholder",
7
- addOptions() {
8
- return {
9
- emptyEditorClass: "is-editor-empty",
10
- emptyNodeClass: "is-empty",
11
- placeholder: "Write something \u2026",
12
- showOnlyWhenEditable: true,
13
- showOnlyCurrent: true,
14
- includeChildren: false
15
- };
16
- },
17
- addProseMirrorPlugins() {
18
- return [
19
- new Plugin({
20
- key: new PluginKey("placeholder"),
21
- props: {
22
- decorations: ({ doc, selection }) => {
23
- const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
24
- const { anchor } = selection;
25
- const decorations = [];
26
- if (!active) {
27
- return null;
28
- }
29
- const isEmptyDoc = this.editor.isEmpty;
30
- doc.descendants((node, pos) => {
31
- const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
32
- const isEmpty = !node.isLeaf && isNodeEmpty(node);
33
- if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
34
- const classes = [this.options.emptyNodeClass];
35
- if (isEmptyDoc) {
36
- classes.push(this.options.emptyEditorClass);
37
- }
38
- const decoration = Decoration.node(pos, pos + node.nodeSize, {
39
- class: classes.join(" "),
40
- "data-placeholder": typeof this.options.placeholder === "function" ? this.options.placeholder({
41
- editor: this.editor,
42
- node,
43
- pos,
44
- hasAnchor
45
- }) : this.options.placeholder
46
- });
47
- decorations.push(decoration);
48
- }
49
- return this.options.includeChildren;
50
- });
51
- return DecorationSet.create(doc, decorations);
52
- }
53
- }
54
- })
55
- ];
56
- }
57
- });
58
-
59
1
  // src/index.ts
2
+ import { Placeholder } from "@tiptap/extensions";
3
+ import { Placeholder as Placeholder2, PlaceholderOptions } from "@tiptap/extensions";
60
4
  var index_default = Placeholder;
61
5
  export {
62
- Placeholder,
6
+ Placeholder2 as Placeholder,
7
+ PlaceholderOptions,
63
8
  index_default as default
64
9
  };
65
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/placeholder.ts","../src/index.ts"],"sourcesContent":["import { Editor, Extension, isNodeEmpty } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from '@tiptap/pm/model'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface PlaceholderOptions {\n /**\n * **The class name for the empty editor**\n * @default 'is-editor-empty'\n */\n emptyEditorClass: string\n\n /**\n * **The class name for empty nodes**\n * @default 'is-empty'\n */\n emptyNodeClass: string\n\n /**\n * **The placeholder content**\n *\n * You can use a function to return a dynamic placeholder or a string.\n * @default 'Write something …'\n */\n placeholder:\n | ((PlaceholderProps: { editor: Editor; node: ProsemirrorNode; pos: number; hasAnchor: boolean }) => string)\n | string\n\n /**\n * **Checks if the placeholder should be only shown when the editor is editable.**\n *\n * If true, the placeholder will only be shown when the editor is editable.\n * If false, the placeholder will always be shown.\n * @default true\n */\n showOnlyWhenEditable: boolean\n\n /**\n * **Checks if the placeholder should be only shown when the current node is empty.**\n *\n * If true, the placeholder will only be shown when the current node is empty.\n * If false, the placeholder will be shown when any node is empty.\n * @default true\n */\n showOnlyCurrent: boolean\n\n /**\n * **Controls if the placeholder should be shown for all descendents.**\n *\n * If true, the placeholder will be shown for all descendents.\n * If false, the placeholder will only be shown for the current node.\n * @default false\n */\n includeChildren: boolean\n}\n\n/**\n * This extension allows you to add a placeholder to your editor.\n * A placeholder is a text that appears when the editor or a node is empty.\n * @see https://www.tiptap.dev/api/extensions/placeholder\n */\nexport const Placeholder = Extension.create<PlaceholderOptions>({\n name: 'placeholder',\n\n addOptions() {\n return {\n emptyEditorClass: 'is-editor-empty',\n emptyNodeClass: 'is-empty',\n placeholder: 'Write something …',\n showOnlyWhenEditable: true,\n showOnlyCurrent: true,\n includeChildren: false,\n }\n },\n\n addProseMirrorPlugins() {\n return [\n new Plugin({\n key: new PluginKey('placeholder'),\n props: {\n decorations: ({ doc, selection }) => {\n const active = this.editor.isEditable || !this.options.showOnlyWhenEditable\n const { anchor } = selection\n const decorations: Decoration[] = []\n\n if (!active) {\n return null\n }\n\n const isEmptyDoc = this.editor.isEmpty\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize\n const isEmpty = !node.isLeaf && isNodeEmpty(node)\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const classes = [this.options.emptyNodeClass]\n\n if (isEmptyDoc) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder':\n typeof this.options.placeholder === 'function'\n ? this.options.placeholder({\n editor: this.editor,\n node,\n pos,\n hasAnchor,\n })\n : this.options.placeholder,\n })\n\n decorations.push(decoration)\n }\n\n return this.options.includeChildren\n })\n\n return DecorationSet.create(doc, decorations)\n },\n },\n }),\n ]\n },\n})\n","import { Placeholder } from './placeholder.js'\n\nexport * from './placeholder.js'\n\nexport default Placeholder\n"],"mappings":";AAAA,SAAiB,WAAW,mBAAmB;AAE/C,SAAS,QAAQ,iBAAiB;AAClC,SAAS,YAAY,qBA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AK,QAAQ;AAAA,YACtB,CAAC;AAED,mBAAO,cAAc,OAAO,KAAK,WAAW;AAAA,UAC9C;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;AC3HD,IAAO,gBAAQ;","names":[]}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Placeholder } from '@tiptap/extensions'\n\nexport { Placeholder, PlaceholderOptions } from '@tiptap/extensions'\n\nexport default Placeholder\n"],"mappings":";AAAA,SAAS,mBAAmB;AAE5B,SAAS,eAAAA,cAAa,0BAA0B;AAEhD,IAAO,gBAAQ;","names":["Placeholder"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/extension-placeholder",
3
3
  "description": "placeholder extension for tiptap",
4
- "version": "3.0.0-next.4",
4
+ "version": "3.0.0-next.5",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -31,12 +31,10 @@
31
31
  "dist"
32
32
  ],
33
33
  "devDependencies": {
34
- "@tiptap/core": "^3.0.0-next.4",
35
- "@tiptap/pm": "^3.0.0-next.4"
34
+ "@tiptap/extensions": "^3.0.0-next.5"
36
35
  },
37
36
  "peerDependencies": {
38
- "@tiptap/core": "^3.0.0-next.1",
39
- "@tiptap/pm": "^3.0.0-next.1"
37
+ "@tiptap/extensions": "^3.0.0-next.3"
40
38
  },
41
39
  "repository": {
42
40
  "type": "git",
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Placeholder } from './placeholder.js'
1
+ import { Placeholder } from '@tiptap/extensions'
2
2
 
3
- export * from './placeholder.js'
3
+ export { Placeholder, PlaceholderOptions } from '@tiptap/extensions'
4
4
 
5
5
  export default Placeholder
@@ -1,128 +0,0 @@
1
- import { Editor, Extension, isNodeEmpty } from '@tiptap/core'
2
- import { Node as ProsemirrorNode } from '@tiptap/pm/model'
3
- import { Plugin, PluginKey } from '@tiptap/pm/state'
4
- import { Decoration, DecorationSet } from '@tiptap/pm/view'
5
-
6
- export interface PlaceholderOptions {
7
- /**
8
- * **The class name for the empty editor**
9
- * @default 'is-editor-empty'
10
- */
11
- emptyEditorClass: string
12
-
13
- /**
14
- * **The class name for empty nodes**
15
- * @default 'is-empty'
16
- */
17
- emptyNodeClass: string
18
-
19
- /**
20
- * **The placeholder content**
21
- *
22
- * You can use a function to return a dynamic placeholder or a string.
23
- * @default 'Write something …'
24
- */
25
- placeholder:
26
- | ((PlaceholderProps: { editor: Editor; node: ProsemirrorNode; pos: number; hasAnchor: boolean }) => string)
27
- | string
28
-
29
- /**
30
- * **Checks if the placeholder should be only shown when the editor is editable.**
31
- *
32
- * If true, the placeholder will only be shown when the editor is editable.
33
- * If false, the placeholder will always be shown.
34
- * @default true
35
- */
36
- showOnlyWhenEditable: boolean
37
-
38
- /**
39
- * **Checks if the placeholder should be only shown when the current node is empty.**
40
- *
41
- * If true, the placeholder will only be shown when the current node is empty.
42
- * If false, the placeholder will be shown when any node is empty.
43
- * @default true
44
- */
45
- showOnlyCurrent: boolean
46
-
47
- /**
48
- * **Controls if the placeholder should be shown for all descendents.**
49
- *
50
- * If true, the placeholder will be shown for all descendents.
51
- * If false, the placeholder will only be shown for the current node.
52
- * @default false
53
- */
54
- includeChildren: boolean
55
- }
56
-
57
- /**
58
- * This extension allows you to add a placeholder to your editor.
59
- * A placeholder is a text that appears when the editor or a node is empty.
60
- * @see https://www.tiptap.dev/api/extensions/placeholder
61
- */
62
- export const Placeholder = Extension.create<PlaceholderOptions>({
63
- name: 'placeholder',
64
-
65
- addOptions() {
66
- return {
67
- emptyEditorClass: 'is-editor-empty',
68
- emptyNodeClass: 'is-empty',
69
- placeholder: 'Write something …',
70
- showOnlyWhenEditable: true,
71
- showOnlyCurrent: true,
72
- includeChildren: false,
73
- }
74
- },
75
-
76
- addProseMirrorPlugins() {
77
- return [
78
- new Plugin({
79
- key: new PluginKey('placeholder'),
80
- props: {
81
- decorations: ({ doc, selection }) => {
82
- const active = this.editor.isEditable || !this.options.showOnlyWhenEditable
83
- const { anchor } = selection
84
- const decorations: Decoration[] = []
85
-
86
- if (!active) {
87
- return null
88
- }
89
-
90
- const isEmptyDoc = this.editor.isEmpty
91
-
92
- doc.descendants((node, pos) => {
93
- const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize
94
- const isEmpty = !node.isLeaf && isNodeEmpty(node)
95
-
96
- if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
97
- const classes = [this.options.emptyNodeClass]
98
-
99
- if (isEmptyDoc) {
100
- classes.push(this.options.emptyEditorClass)
101
- }
102
-
103
- const decoration = Decoration.node(pos, pos + node.nodeSize, {
104
- class: classes.join(' '),
105
- 'data-placeholder':
106
- typeof this.options.placeholder === 'function'
107
- ? this.options.placeholder({
108
- editor: this.editor,
109
- node,
110
- pos,
111
- hasAnchor,
112
- })
113
- : this.options.placeholder,
114
- })
115
-
116
- decorations.push(decoration)
117
- }
118
-
119
- return this.options.includeChildren
120
- })
121
-
122
- return DecorationSet.create(doc, decorations)
123
- },
124
- },
125
- }),
126
- ]
127
- },
128
- })