@tiptap/extension-placeholder 3.0.0-next.3 → 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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025, Tiptap GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,14 +1,18 @@
1
1
  # @tiptap/extension-placeholder
2
+
2
3
  [![Version](https://img.shields.io/npm/v/@tiptap/extension-placeholder.svg?label=version)](https://www.npmjs.com/package/@tiptap/extension-placeholder)
3
4
  [![Downloads](https://img.shields.io/npm/dm/@tiptap/extension-placeholder.svg)](https://npmcharts.com/compare/tiptap?minimal=true)
4
5
  [![License](https://img.shields.io/npm/l/@tiptap/extension-placeholder.svg)](https://www.npmjs.com/package/@tiptap/extension-placeholder)
5
6
  [![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub)](https://github.com/sponsors/ueberdosis)
6
7
 
7
8
  ## Introduction
8
- Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as *New York Times*, *The Guardian* or *Atlassian*.
9
+
10
+ Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as _New York Times_, _The Guardian_ or _Atlassian_.
9
11
 
10
12
  ## Official Documentation
13
+
11
14
  Documentation can be found on the [Tiptap website](https://tiptap.dev).
12
15
 
13
16
  ## License
17
+
14
18
  Tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
package/dist/index.cjs CHANGED
@@ -18,75 +18,19 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // src/index.ts
21
- var src_exports = {};
22
- __export(src_exports, {
23
- Placeholder: () => Placeholder,
24
- default: () => src_default
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ Placeholder: () => import_extensions2.Placeholder,
24
+ PlaceholderOptions: () => import_extensions2.PlaceholderOptions,
25
+ default: () => index_default
25
26
  });
26
- module.exports = __toCommonJS(src_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 src_default = Placeholder;
27
+ module.exports = __toCommonJS(index_exports);
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: {\n editor: Editor\n node: ProsemirrorNode\n pos: number\n hasAnchor: boolean\n }) => 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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA+C;AAE/C,mBAAkC;AAClC,kBAA0C;AA+DnC,IAAM,cAAc,sBAAU,OAA2B;AAAA,EAC9D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,kBAAkB;AAAA,MAClB,gBAAgB;AAAA,MAChB,aAAa;AAAA,MACb,sBAAsB;AAAA,MACtB,iBAAiB;AAAA,MACjB,iBAAiB;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO;AAAA,MACL,IAAI,oBAAO;AAAA,QACT,KAAK,IAAI,uBAAU,aAAa;AAAA,QAChC,OAAO;AAAA,UACL,aAAa,CAAC,EAAE,KAAK,UAAU,MAAM;AACnC,kBAAM,SAAS,KAAK,OAAO,cAAc,CAAC,KAAK,QAAQ;AACvD,kBAAM,EAAE,OAAO,IAAI;AACnB,kBAAM,cAA4B,CAAC;AAEnC,gBAAI,CAAC,QAAQ;AACX,qBAAO;AAAA,YACT;AAEA,kBAAM,aAAa,KAAK,OAAO;AAE/B,gBAAI,YAAY,CAAC,MAAM,QAAQ;AAC7B,oBAAM,YAAY,UAAU,OAAO,UAAU,MAAM,KAAK;AACxD,oBAAM,UAAU,CAAC,KAAK,cAAU,yBAAY,IAAI;AAEhD,mBAAK,aAAa,CAAC,KAAK,QAAQ,oBAAoB,SAAS;AAC3D,sBAAM,UAAU,CAAC,KAAK,QAAQ,cAAc;AAE5C,oBAAI,YAAY;AACd,0BAAQ,KAAK,KAAK,QAAQ,gBAAgB;AAAA,gBAC5C;AAEA,sBAAM,aAAa,uBAAW,KAAK,KAAK,MAAM,KAAK,UAAU;AAAA,kBAC3D,OAAO,QAAQ,KAAK,GAAG;AAAA,kBACvB,oBACE,OAAO,KAAK,QAAQ,gBAAgB,aAChC,KAAK,QAAQ,YAAY;AAAA,oBACzB,QAAQ,KAAK;AAAA,oBACb;AAAA,oBACA;AAAA,oBACA;AAAA,kBACF,CAAC,IACC,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;;;ADhID,IAAO,cAAQ;","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
60
- var src_default = Placeholder;
2
+ import { Placeholder } from "@tiptap/extensions";
3
+ import { Placeholder as Placeholder2, PlaceholderOptions } from "@tiptap/extensions";
4
+ var index_default = Placeholder;
61
5
  export {
62
- Placeholder,
63
- src_default as default
6
+ Placeholder2 as Placeholder,
7
+ PlaceholderOptions,
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: {\n editor: Editor\n node: ProsemirrorNode\n pos: number\n hasAnchor: boolean\n }) => 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,qBAAqB;AA+DnC,IAAM,cAAc,UAAU,OAA2B;AAAA,EAC9D,MAAM;AAAA,EAEN,aAAa;AACX,WAAO;AAAA,MACL,kBAAkB;AAAA,MAClB,gBAAgB;AAAA,MAChB,aAAa;AAAA,MACb,sBAAsB;AAAA,MACtB,iBAAiB;AAAA,MACjB,iBAAiB;AAAA,IACnB;AAAA,EACF;AAAA,EAEA,wBAAwB;AACtB,WAAO;AAAA,MACL,IAAI,OAAO;AAAA,QACT,KAAK,IAAI,UAAU,aAAa;AAAA,QAChC,OAAO;AAAA,UACL,aAAa,CAAC,EAAE,KAAK,UAAU,MAAM;AACnC,kBAAM,SAAS,KAAK,OAAO,cAAc,CAAC,KAAK,QAAQ;AACvD,kBAAM,EAAE,OAAO,IAAI;AACnB,kBAAM,cAA4B,CAAC;AAEnC,gBAAI,CAAC,QAAQ;AACX,qBAAO;AAAA,YACT;AAEA,kBAAM,aAAa,KAAK,OAAO;AAE/B,gBAAI,YAAY,CAAC,MAAM,QAAQ;AAC7B,oBAAM,YAAY,UAAU,OAAO,UAAU,MAAM,KAAK;AACxD,oBAAM,UAAU,CAAC,KAAK,UAAU,YAAY,IAAI;AAEhD,mBAAK,aAAa,CAAC,KAAK,QAAQ,oBAAoB,SAAS;AAC3D,sBAAM,UAAU,CAAC,KAAK,QAAQ,cAAc;AAE5C,oBAAI,YAAY;AACd,0BAAQ,KAAK,KAAK,QAAQ,gBAAgB;AAAA,gBAC5C;AAEA,sBAAM,aAAa,WAAW,KAAK,KAAK,MAAM,KAAK,UAAU;AAAA,kBAC3D,OAAO,QAAQ,KAAK,GAAG;AAAA,kBACvB,oBACE,OAAO,KAAK,QAAQ,gBAAgB,aAChC,KAAK,QAAQ,YAAY;AAAA,oBACzB,QAAQ,KAAK;AAAA,oBACb;AAAA,oBACA;AAAA,oBACA;AAAA,kBACF,CAAC,IACC,KAAK,QAAQ;AAAA,gBACrB,CAAC;AAED,4BAAY,KAAK,UAAU;AAAA,cAC7B;AAEA,qBAAO,KAAK,QAAQ;AAAA,YACtB,CAAC;AAED,mBAAO,cAAc,OAAO,KAAK,WAAW;AAAA,UAC9C;AAAA,QACF;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF,CAAC;;;AChID,IAAO,cAAQ;","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.3",
4
+ "version": "3.0.0-next.5",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -15,7 +15,10 @@
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/index.d.ts",
18
+ "types": {
19
+ "import": "./dist/index.d.ts",
20
+ "require": "./dist/index.d.cts"
21
+ },
19
22
  "import": "./dist/index.js",
20
23
  "require": "./dist/index.cjs"
21
24
  }
@@ -28,12 +31,10 @@
28
31
  "dist"
29
32
  ],
30
33
  "devDependencies": {
31
- "@tiptap/core": "^3.0.0-next.3",
32
- "@tiptap/pm": "^3.0.0-next.3"
34
+ "@tiptap/extensions": "^3.0.0-next.5"
33
35
  },
34
36
  "peerDependencies": {
35
- "@tiptap/core": "^3.0.0-next.1",
36
- "@tiptap/pm": "^3.0.0-next.1"
37
+ "@tiptap/extensions": "^3.0.0-next.3"
37
38
  },
38
39
  "repository": {
39
40
  "type": "git",
@@ -41,6 +42,7 @@
41
42
  "directory": "packages/extension-placeholder"
42
43
  },
43
44
  "scripts": {
44
- "build": "tsup"
45
+ "build": "tsup",
46
+ "lint": "prettier ./src/ --check && eslint --cache --quiet --no-error-on-unmatched-pattern ./src/"
45
47
  }
46
- }
48
+ }
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,133 +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: {
27
- editor: Editor
28
- node: ProsemirrorNode
29
- pos: number
30
- hasAnchor: boolean
31
- }) => string)
32
- | string
33
-
34
- /**
35
- * **Checks if the placeholder should be only shown when the editor is editable.**
36
- *
37
- * If true, the placeholder will only be shown when the editor is editable.
38
- * If false, the placeholder will always be shown.
39
- * @default true
40
- */
41
- showOnlyWhenEditable: boolean
42
-
43
- /**
44
- * **Checks if the placeholder should be only shown when the current node is empty.**
45
- *
46
- * If true, the placeholder will only be shown when the current node is empty.
47
- * If false, the placeholder will be shown when any node is empty.
48
- * @default true
49
- */
50
- showOnlyCurrent: boolean
51
-
52
- /**
53
- * **Controls if the placeholder should be shown for all descendents.**
54
- *
55
- * If true, the placeholder will be shown for all descendents.
56
- * If false, the placeholder will only be shown for the current node.
57
- * @default false
58
- */
59
- includeChildren: boolean
60
- }
61
-
62
- /**
63
- * This extension allows you to add a placeholder to your editor.
64
- * A placeholder is a text that appears when the editor or a node is empty.
65
- * @see https://www.tiptap.dev/api/extensions/placeholder
66
- */
67
- export const Placeholder = Extension.create<PlaceholderOptions>({
68
- name: 'placeholder',
69
-
70
- addOptions() {
71
- return {
72
- emptyEditorClass: 'is-editor-empty',
73
- emptyNodeClass: 'is-empty',
74
- placeholder: 'Write something …',
75
- showOnlyWhenEditable: true,
76
- showOnlyCurrent: true,
77
- includeChildren: false,
78
- }
79
- },
80
-
81
- addProseMirrorPlugins() {
82
- return [
83
- new Plugin({
84
- key: new PluginKey('placeholder'),
85
- props: {
86
- decorations: ({ doc, selection }) => {
87
- const active = this.editor.isEditable || !this.options.showOnlyWhenEditable
88
- const { anchor } = selection
89
- const decorations: Decoration[] = []
90
-
91
- if (!active) {
92
- return null
93
- }
94
-
95
- const isEmptyDoc = this.editor.isEmpty
96
-
97
- doc.descendants((node, pos) => {
98
- const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize
99
- const isEmpty = !node.isLeaf && isNodeEmpty(node)
100
-
101
- if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
102
- const classes = [this.options.emptyNodeClass]
103
-
104
- if (isEmptyDoc) {
105
- classes.push(this.options.emptyEditorClass)
106
- }
107
-
108
- const decoration = Decoration.node(pos, pos + node.nodeSize, {
109
- class: classes.join(' '),
110
- 'data-placeholder':
111
- typeof this.options.placeholder === 'function'
112
- ? this.options.placeholder({
113
- editor: this.editor,
114
- node,
115
- pos,
116
- hasAnchor,
117
- })
118
- : this.options.placeholder,
119
- })
120
-
121
- decorations.push(decoration)
122
- }
123
-
124
- return this.options.includeChildren
125
- })
126
-
127
- return DecorationSet.create(doc, decorations)
128
- },
129
- },
130
- }),
131
- ]
132
- },
133
- })