@tiptap/extension-placeholder 2.0.0-beta.213 → 2.0.0-beta.215

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/dist/index.cjs CHANGED
@@ -1,64 +1,69 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/placeholder.ts
2
- var _core = require('@tiptap/core');
3
- var _state = require('@tiptap/pm/state');
4
- var _view = require('@tiptap/pm/view');
5
- var Placeholder = _core.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 (0, _state.Plugin)({
20
- props: {
21
- decorations: ({ doc, selection }) => {
22
- const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
23
- const { anchor } = selection;
24
- const decorations = [];
25
- if (!active) {
26
- return null;
27
- }
28
- const emptyDocInstance = doc.type.createAndFill();
29
- const isEditorEmpty = (emptyDocInstance == null ? void 0 : emptyDocInstance.sameMarkup(doc)) && emptyDocInstance.content.findDiffStart(doc.content) === null;
30
- doc.descendants((node, pos) => {
31
- const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
32
- const isEmpty = !node.isLeaf && !node.childCount;
33
- if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
34
- const classes = [this.options.emptyNodeClass];
35
- if (isEditorEmpty) {
36
- classes.push(this.options.emptyEditorClass);
37
- }
38
- const decoration = _view.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 _view.DecorationSet.create(doc, decorations);
52
- }
53
- }
54
- })
55
- ];
56
- }
57
- });
1
+ 'use strict';
58
2
 
59
- // src/index.ts
60
- var src_default = Placeholder;
3
+ Object.defineProperty(exports, '__esModule', { value: true });
61
4
 
5
+ var core = require('@tiptap/core');
6
+ var state = require('@tiptap/pm/state');
7
+ var view = require('@tiptap/pm/view');
62
8
 
9
+ const Placeholder = core.Extension.create({
10
+ name: 'placeholder',
11
+ addOptions() {
12
+ return {
13
+ emptyEditorClass: 'is-editor-empty',
14
+ emptyNodeClass: 'is-empty',
15
+ placeholder: 'Write something …',
16
+ showOnlyWhenEditable: true,
17
+ showOnlyCurrent: true,
18
+ includeChildren: false,
19
+ };
20
+ },
21
+ addProseMirrorPlugins() {
22
+ return [
23
+ new state.Plugin({
24
+ props: {
25
+ decorations: ({ doc, selection }) => {
26
+ const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
27
+ const { anchor } = selection;
28
+ const decorations = [];
29
+ if (!active) {
30
+ return null;
31
+ }
32
+ // only calculate isEmpty once due to its performance impacts (see issue #3360)
33
+ const emptyDocInstance = doc.type.createAndFill();
34
+ const isEditorEmpty = (emptyDocInstance === null || emptyDocInstance === void 0 ? void 0 : emptyDocInstance.sameMarkup(doc))
35
+ && emptyDocInstance.content.findDiffStart(doc.content) === null;
36
+ doc.descendants((node, pos) => {
37
+ const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
38
+ const isEmpty = !node.isLeaf && !node.childCount;
39
+ if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
40
+ const classes = [this.options.emptyNodeClass];
41
+ if (isEditorEmpty) {
42
+ classes.push(this.options.emptyEditorClass);
43
+ }
44
+ const decoration = view.Decoration.node(pos, pos + node.nodeSize, {
45
+ class: classes.join(' '),
46
+ 'data-placeholder': typeof this.options.placeholder === 'function'
47
+ ? this.options.placeholder({
48
+ editor: this.editor,
49
+ node,
50
+ pos,
51
+ hasAnchor,
52
+ })
53
+ : this.options.placeholder,
54
+ });
55
+ decorations.push(decoration);
56
+ }
57
+ return this.options.includeChildren;
58
+ });
59
+ return view.DecorationSet.create(doc, decorations);
60
+ },
61
+ },
62
+ }),
63
+ ];
64
+ },
65
+ });
63
66
 
64
- exports.Placeholder = Placeholder; exports.default = src_default;
67
+ exports.Placeholder = Placeholder;
68
+ exports["default"] = Placeholder;
69
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from '@tiptap/pm/model'\nimport { Plugin } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string\n emptyNodeClass: string\n placeholder:\n | ((PlaceholderProps: {\n editor: Editor\n node: ProsemirrorNode\n pos: number\n hasAnchor: boolean\n }) => string)\n | string\n showOnlyWhenEditable: boolean\n showOnlyCurrent: boolean\n includeChildren: boolean\n}\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 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 // only calculate isEmpty once due to its performance impacts (see issue #3360)\n const emptyDocInstance = doc.type.createAndFill()\n const isEditorEmpty = emptyDocInstance?.sameMarkup(doc)\n && emptyDocInstance.content.findDiffStart(doc.content) === null\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize\n const isEmpty = !node.isLeaf && !node.childCount\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const classes = [this.options.emptyNodeClass]\n\n if (isEditorEmpty) {\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"],"names":["Extension","Plugin","Decoration","DecorationSet"],"mappings":";;;;;;;;AAqBa,MAAA,WAAW,GAAGA,cAAS,CAAC,MAAM,CAAqB;AAC9D,IAAA,IAAI,EAAE,aAAa;IAEnB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,gBAAgB,EAAE,iBAAiB;AACnC,YAAA,cAAc,EAAE,UAAU;AAC1B,YAAA,WAAW,EAAE,mBAAmB;AAChC,YAAA,oBAAoB,EAAE,IAAI;AAC1B,YAAA,eAAe,EAAE,IAAI;AACrB,YAAA,eAAe,EAAE,KAAK;SACvB,CAAA;KACF;IAED,qBAAqB,GAAA;QACnB,OAAO;AACL,YAAA,IAAIC,YAAM,CAAC;AACT,gBAAA,KAAK,EAAE;oBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAI;AAClC,wBAAA,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAA;AAC3E,wBAAA,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;wBAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;wBAEpC,IAAI,CAAC,MAAM,EAAE;AACX,4BAAA,OAAO,IAAI,CAAA;AACZ,yBAAA;;wBAGD,MAAM,gBAAgB,GAAG,GAAG,CAAC,IAAI,CAAC,aAAa,EAAE,CAAA;AACjD,wBAAA,MAAM,aAAa,G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AI,CAAC,UAAU,CAAC,CAAA;AAC7B,6BAAA;AAED,4BAAA,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAA;AACrC,yBAAC,CAAC,CAAA;wBAEF,OAAOC,kBAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;AACF,iBAAA;aACF,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;;"}
package/dist/index.js CHANGED
@@ -1,64 +1,64 @@
1
- // src/placeholder.ts
2
- import { Extension } from "@tiptap/core";
3
- import { Plugin } 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
- props: {
21
- decorations: ({ doc, selection }) => {
22
- const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
23
- const { anchor } = selection;
24
- const decorations = [];
25
- if (!active) {
26
- return null;
27
- }
28
- const emptyDocInstance = doc.type.createAndFill();
29
- const isEditorEmpty = (emptyDocInstance == null ? void 0 : emptyDocInstance.sameMarkup(doc)) && emptyDocInstance.content.findDiffStart(doc.content) === null;
30
- doc.descendants((node, pos) => {
31
- const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
32
- const isEmpty = !node.isLeaf && !node.childCount;
33
- if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
34
- const classes = [this.options.emptyNodeClass];
35
- if (isEditorEmpty) {
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
- }
1
+ import { Extension } from '@tiptap/core';
2
+ import { Plugin } from '@tiptap/pm/state';
3
+ import { Decoration, DecorationSet } from '@tiptap/pm/view';
4
+
5
+ const Placeholder = Extension.create({
6
+ name: 'placeholder',
7
+ addOptions() {
8
+ return {
9
+ emptyEditorClass: 'is-editor-empty',
10
+ emptyNodeClass: 'is-empty',
11
+ placeholder: 'Write something …',
12
+ showOnlyWhenEditable: true,
13
+ showOnlyCurrent: true,
14
+ includeChildren: false,
15
+ };
16
+ },
17
+ addProseMirrorPlugins() {
18
+ return [
19
+ new Plugin({
20
+ props: {
21
+ decorations: ({ doc, selection }) => {
22
+ const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
23
+ const { anchor } = selection;
24
+ const decorations = [];
25
+ if (!active) {
26
+ return null;
27
+ }
28
+ // only calculate isEmpty once due to its performance impacts (see issue #3360)
29
+ const emptyDocInstance = doc.type.createAndFill();
30
+ const isEditorEmpty = (emptyDocInstance === null || emptyDocInstance === void 0 ? void 0 : emptyDocInstance.sameMarkup(doc))
31
+ && emptyDocInstance.content.findDiffStart(doc.content) === null;
32
+ doc.descendants((node, pos) => {
33
+ const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
34
+ const isEmpty = !node.isLeaf && !node.childCount;
35
+ if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
36
+ const classes = [this.options.emptyNodeClass];
37
+ if (isEditorEmpty) {
38
+ classes.push(this.options.emptyEditorClass);
39
+ }
40
+ const decoration = Decoration.node(pos, pos + node.nodeSize, {
41
+ class: classes.join(' '),
42
+ 'data-placeholder': typeof this.options.placeholder === 'function'
43
+ ? this.options.placeholder({
44
+ editor: this.editor,
45
+ node,
46
+ pos,
47
+ hasAnchor,
48
+ })
49
+ : this.options.placeholder,
50
+ });
51
+ decorations.push(decoration);
52
+ }
53
+ return this.options.includeChildren;
54
+ });
55
+ return DecorationSet.create(doc, decorations);
56
+ },
57
+ },
58
+ }),
59
+ ];
60
+ },
57
61
  });
58
62
 
59
- // src/index.ts
60
- var src_default = Placeholder;
61
- export {
62
- Placeholder,
63
- src_default as default
64
- };
63
+ export { Placeholder, Placeholder as default };
64
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from '@tiptap/pm/model'\nimport { Plugin } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string\n emptyNodeClass: string\n placeholder:\n | ((PlaceholderProps: {\n editor: Editor\n node: ProsemirrorNode\n pos: number\n hasAnchor: boolean\n }) => string)\n | string\n showOnlyWhenEditable: boolean\n showOnlyCurrent: boolean\n includeChildren: boolean\n}\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 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 // only calculate isEmpty once due to its performance impacts (see issue #3360)\n const emptyDocInstance = doc.type.createAndFill()\n const isEditorEmpty = emptyDocInstance?.sameMarkup(doc)\n && emptyDocInstance.content.findDiffStart(doc.content) === null\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize\n const isEmpty = !node.isLeaf && !node.childCount\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const classes = [this.options.emptyNodeClass]\n\n if (isEditorEmpty) {\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"],"names":[],"mappings":";;;;AAqBa,MAAA,WAAW,GAAG,SAAS,CAAC,MAAM,CAAqB;AAC9D,IAAA,IAAI,EAAE,aAAa;IAEnB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,gBAAgB,EAAE,iBAAiB;AACnC,YAAA,cAAc,EAAE,UAAU;AAC1B,YAAA,WAAW,EAAE,mBAAmB;AAChC,YAAA,oBAAoB,EAAE,IAAI;AAC1B,YAAA,eAAe,EAAE,IAAI;AACrB,YAAA,eAAe,EAAE,KAAK;SACvB,CAAA;KACF;IAED,qBAAqB,GAAA;QACnB,OAAO;AACL,YAAA,IAAI,MAAM,CAAC;AACT,gBAAA,KAAK,EAAE;oBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAI;AAClC,wBAAA,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAA;AAC3E,wBAAA,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;wBAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;wBAEpC,IAAI,CAAC,MAAM,EAAE;AACX,4BAAA,OAAO,IAAI,CAAA;AACZ,yBAAA;;wBAGD,MAAM,gBAAgB,GAAG,GAAG,CAAC,IAAI,CAAC,aAAa,EAAE,CAAA;AACjD,wBAAA,MAAM,aAAa,GAAG,CAAA,gBAAgB,K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CAAA;AAC7B,6BAAA;AAED,4BAAA,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAA;AACrC,yBAAC,CAAC,CAAA;wBAEF,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;AACF,iBAAA;aACF,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;"}
@@ -0,0 +1,71 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('@tiptap/pm/state'), require('@tiptap/pm/view')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', '@tiptap/pm/state', '@tiptap/pm/view'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-placeholder"] = {}, global.core, global.state, global.view));
5
+ })(this, (function (exports, core, state, view) { 'use strict';
6
+
7
+ const Placeholder = core.Extension.create({
8
+ name: 'placeholder',
9
+ addOptions() {
10
+ return {
11
+ emptyEditorClass: 'is-editor-empty',
12
+ emptyNodeClass: 'is-empty',
13
+ placeholder: 'Write something …',
14
+ showOnlyWhenEditable: true,
15
+ showOnlyCurrent: true,
16
+ includeChildren: false,
17
+ };
18
+ },
19
+ addProseMirrorPlugins() {
20
+ return [
21
+ new state.Plugin({
22
+ props: {
23
+ decorations: ({ doc, selection }) => {
24
+ const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
25
+ const { anchor } = selection;
26
+ const decorations = [];
27
+ if (!active) {
28
+ return null;
29
+ }
30
+ // only calculate isEmpty once due to its performance impacts (see issue #3360)
31
+ const emptyDocInstance = doc.type.createAndFill();
32
+ const isEditorEmpty = (emptyDocInstance === null || emptyDocInstance === void 0 ? void 0 : emptyDocInstance.sameMarkup(doc))
33
+ && emptyDocInstance.content.findDiffStart(doc.content) === null;
34
+ doc.descendants((node, pos) => {
35
+ const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
36
+ const isEmpty = !node.isLeaf && !node.childCount;
37
+ if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
38
+ const classes = [this.options.emptyNodeClass];
39
+ if (isEditorEmpty) {
40
+ classes.push(this.options.emptyEditorClass);
41
+ }
42
+ const decoration = view.Decoration.node(pos, pos + node.nodeSize, {
43
+ class: classes.join(' '),
44
+ 'data-placeholder': typeof this.options.placeholder === 'function'
45
+ ? this.options.placeholder({
46
+ editor: this.editor,
47
+ node,
48
+ pos,
49
+ hasAnchor,
50
+ })
51
+ : this.options.placeholder,
52
+ });
53
+ decorations.push(decoration);
54
+ }
55
+ return this.options.includeChildren;
56
+ });
57
+ return view.DecorationSet.create(doc, decorations);
58
+ },
59
+ },
60
+ }),
61
+ ];
62
+ },
63
+ });
64
+
65
+ exports.Placeholder = Placeholder;
66
+ exports["default"] = Placeholder;
67
+
68
+ Object.defineProperty(exports, '__esModule', { value: true });
69
+
70
+ }));
71
+ //# sourceMappingURL=index.umd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.umd.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from '@tiptap/pm/model'\nimport { Plugin } from '@tiptap/pm/state'\nimport { Decoration, DecorationSet } from '@tiptap/pm/view'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string\n emptyNodeClass: string\n placeholder:\n | ((PlaceholderProps: {\n editor: Editor\n node: ProsemirrorNode\n pos: number\n hasAnchor: boolean\n }) => string)\n | string\n showOnlyWhenEditable: boolean\n showOnlyCurrent: boolean\n includeChildren: boolean\n}\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 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 // only calculate isEmpty once due to its performance impacts (see issue #3360)\n const emptyDocInstance = doc.type.createAndFill()\n const isEditorEmpty = emptyDocInstance?.sameMarkup(doc)\n && emptyDocInstance.content.findDiffStart(doc.content) === null\n\n doc.descendants((node, pos) => {\n const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize\n const isEmpty = !node.isLeaf && !node.childCount\n\n if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {\n const classes = [this.options.emptyNodeClass]\n\n if (isEditorEmpty) {\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"],"names":["Extension","Plugin","Decoration","DecorationSet"],"mappings":";;;;;;AAqBa,QAAA,WAAW,GAAGA,cAAS,CAAC,MAAM,CAAqB;EAC9D,IAAA,IAAI,EAAE,aAAa;MAEnB,UAAU,GAAA;UACR,OAAO;EACL,YAAA,gBAAgB,EAAE,iBAAiB;EACnC,YAAA,cAAc,EAAE,UAAU;EAC1B,YAAA,WAAW,EAAE,mBAAmB;EAChC,YAAA,oBAAoB,EAAE,IAAI;EAC1B,YAAA,eAAe,EAAE,IAAI;EACrB,YAAA,eAAe,EAAE,KAAK;WACvB,CAAA;OACF;MAED,qBAAqB,GAAA;UACnB,OAAO;EACL,YAAA,IAAIC,YAAM,CAAC;EACT,gBAAA,KAAK,EAAE;sBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAI;EAClC,wBAAA,MAAM,MAAM,GAAG,IAAI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AAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;sCACxB,kBAAkB,EAChB,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,UAAU;EAC5C,0CAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;8CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;8CACnB,IAAI;8CACJ,GAAG;8CACH,SAAS;2CACV,CAAC;EACF,0CAAE,IAAI,CAAC,OAAO,CAAC,WAAW;EAC/B,iCAAA,CAAC,CAAA;EAEF,gCAAA,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;EAC7B,6BAAA;EAED,4BAAA,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAA;EACrC,yBAAC,CAAC,CAAA;0BAEF,OAAOC,kBAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;uBAC9C;EACF,iBAAA;eACF,CAAC;WACH,CAAA;OACF;EACF,CAAA;;;;;;;;;;;"}
@@ -0,0 +1,3 @@
1
+ import { Placeholder } from './placeholder';
2
+ export * from './placeholder';
3
+ export default Placeholder;
@@ -1,19 +1,16 @@
1
- import { Editor, Extension } from '@tiptap/core';
2
- import { Node } from '@tiptap/pm/model';
3
-
4
- interface PlaceholderOptions {
5
- emptyEditorClass: string;
6
- emptyNodeClass: string;
7
- placeholder: ((PlaceholderProps: {
8
- editor: Editor;
9
- node: Node;
10
- pos: number;
11
- hasAnchor: boolean;
12
- }) => string) | string;
13
- showOnlyWhenEditable: boolean;
14
- showOnlyCurrent: boolean;
15
- includeChildren: boolean;
16
- }
17
- declare const Placeholder: Extension<PlaceholderOptions, any>;
18
-
19
- export { Placeholder, PlaceholderOptions, Placeholder as default };
1
+ import { Editor, Extension } from '@tiptap/core';
2
+ import { Node as ProsemirrorNode } from '@tiptap/pm/model';
3
+ export interface PlaceholderOptions {
4
+ emptyEditorClass: string;
5
+ emptyNodeClass: string;
6
+ placeholder: ((PlaceholderProps: {
7
+ editor: Editor;
8
+ node: ProsemirrorNode;
9
+ pos: number;
10
+ hasAnchor: boolean;
11
+ }) => string) | string;
12
+ showOnlyWhenEditable: boolean;
13
+ showOnlyCurrent: boolean;
14
+ includeChildren: boolean;
15
+ }
16
+ export declare const Placeholder: Extension<PlaceholderOptions, any>;
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": "2.0.0-beta.213",
4
+ "version": "2.0.0-beta.215",
5
5
  "homepage": "https://tiptap.dev",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -15,14 +15,15 @@
15
15
  "type": "module",
16
16
  "exports": {
17
17
  ".": {
18
- "types": "./dist/index.d.ts",
18
+ "types": "./dist/packages/extension-placeholder/src/index.d.ts",
19
19
  "import": "./dist/index.js",
20
20
  "require": "./dist/index.cjs"
21
21
  }
22
22
  },
23
23
  "main": "dist/index.cjs",
24
24
  "module": "dist/index.js",
25
- "types": "dist/index.d.ts",
25
+ "umd": "dist/index.umd.js",
26
+ "types": "dist/packages/extension-placeholder/src/index.d.ts",
26
27
  "files": [
27
28
  "src",
28
29
  "dist"
@@ -32,8 +33,8 @@
32
33
  "@tiptap/pm": "^2.0.0-beta.209"
33
34
  },
34
35
  "devDependencies": {
35
- "@tiptap/core": "^2.0.0-beta.213",
36
- "@tiptap/pm": "^2.0.0-beta.213"
36
+ "@tiptap/core": "^2.0.0-beta.215",
37
+ "@tiptap/pm": "^2.0.0-beta.215"
37
38
  },
38
39
  "repository": {
39
40
  "type": "git",
@@ -41,17 +42,7 @@
41
42
  "directory": "packages/extension-placeholder"
42
43
  },
43
44
  "scripts": {
44
- "build": "tsup"
45
- },
46
- "tsup": {
47
- "entry": [
48
- "src/index.ts"
49
- ],
50
- "dts": true,
51
- "splitting": true,
52
- "format": [
53
- "esm",
54
- "cjs"
55
- ]
45
+ "clean": "rm -rf dist",
46
+ "build": "npm run clean && rollup -c"
56
47
  }
57
48
  }