@tiptap/extension-placeholder 2.0.0-beta.4 → 2.0.0-beta.40
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 +1 -1
- package/README.md +2 -2
- package/dist/packages/extension-placeholder/src/placeholder.d.ts +3 -1
- package/dist/tiptap-extension-placeholder.cjs.js +13 -9
- package/dist/tiptap-extension-placeholder.cjs.js.map +1 -1
- package/dist/tiptap-extension-placeholder.esm.js +14 -11
- package/dist/tiptap-extension-placeholder.esm.js.map +1 -1
- package/dist/tiptap-extension-placeholder.umd.js +16 -12
- package/dist/tiptap-extension-placeholder.umd.js.map +1 -1
- package/package.json +9 -5
- package/src/placeholder.ts +15 -9
- package/CHANGELOG.md +0 -32
- package/dist/tiptap-extension-placeholder.bundle.umd.min.js +0 -2
- package/dist/tiptap-extension-placeholder.bundle.umd.min.js.map +0 -1
package/LICENSE.md
CHANGED
package/README.md
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
## Introduction
|
|
8
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
9
|
|
|
10
|
-
##
|
|
10
|
+
## Official Documentation
|
|
11
11
|
Documentation can be found on the [tiptap website](https://tiptap.dev).
|
|
12
12
|
|
|
13
13
|
## License
|
|
14
|
-
tiptap is open
|
|
14
|
+
tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
|
|
@@ -6,8 +6,10 @@ export interface PlaceholderOptions {
|
|
|
6
6
|
placeholder: ((PlaceholderProps: {
|
|
7
7
|
editor: Editor;
|
|
8
8
|
node: ProsemirrorNode;
|
|
9
|
+
pos: number;
|
|
9
10
|
}) => string) | string;
|
|
10
11
|
showOnlyWhenEditable: boolean;
|
|
11
12
|
showOnlyCurrent: boolean;
|
|
13
|
+
includeChildren: boolean;
|
|
12
14
|
}
|
|
13
|
-
export declare const Placeholder: Extension<PlaceholderOptions>;
|
|
15
|
+
export declare const Placeholder: Extension<PlaceholderOptions, any>;
|
|
@@ -8,12 +8,15 @@ var prosemirrorState = require('prosemirror-state');
|
|
|
8
8
|
|
|
9
9
|
const Placeholder = core.Extension.create({
|
|
10
10
|
name: 'placeholder',
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
+
};
|
|
17
20
|
},
|
|
18
21
|
addProseMirrorPlugins() {
|
|
19
22
|
return [
|
|
@@ -28,7 +31,7 @@ const Placeholder = core.Extension.create({
|
|
|
28
31
|
}
|
|
29
32
|
doc.descendants((node, pos) => {
|
|
30
33
|
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
|
|
31
|
-
const isEmpty = !node.isLeaf &&
|
|
34
|
+
const isEmpty = !node.isLeaf && !node.childCount;
|
|
32
35
|
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
33
36
|
const classes = [this.options.emptyNodeClass];
|
|
34
37
|
if (this.editor.isEmpty) {
|
|
@@ -40,12 +43,13 @@ const Placeholder = core.Extension.create({
|
|
|
40
43
|
? this.options.placeholder({
|
|
41
44
|
editor: this.editor,
|
|
42
45
|
node,
|
|
46
|
+
pos,
|
|
43
47
|
})
|
|
44
48
|
: this.options.placeholder,
|
|
45
49
|
});
|
|
46
50
|
decorations.push(decoration);
|
|
47
51
|
}
|
|
48
|
-
return
|
|
52
|
+
return this.options.includeChildren;
|
|
49
53
|
});
|
|
50
54
|
return prosemirrorView.DecorationSet.create(doc, decorations);
|
|
51
55
|
},
|
|
@@ -56,5 +60,5 @@ const Placeholder = core.Extension.create({
|
|
|
56
60
|
});
|
|
57
61
|
|
|
58
62
|
exports.Placeholder = Placeholder;
|
|
59
|
-
exports
|
|
63
|
+
exports["default"] = Placeholder;
|
|
60
64
|
//# sourceMappingURL=tiptap-extension-placeholder.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap-extension-placeholder.cjs.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension
|
|
1
|
+
{"version":3,"file":"tiptap-extension-placeholder.cjs.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from 'prosemirror-model'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\nimport { Plugin } from 'prosemirror-state'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n pos: number,\n }) => string) | 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\n }\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 (this.editor.isEmpty) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder': typeof this.options.placeholder === 'function'\n ? this.options.placeholder({\n editor: this.editor,\n node,\n pos,\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":";;;;;;;;MAkBa,WAAW,GAAGA,cAAS,CAAC,MAAM,CAAqB;IAC9D,IAAI,EAAE,aAAa;IAEnB,UAAU;QACR,OAAO;YACL,gBAAgB,EAAE,iBAAiB;YACnC,cAAc,EAAE,UAAU;YAC1B,WAAW,EAAE,mBAAmB;YAChC,oBAAoB,EAAE,IAAI;YAC1B,eAAe,EAAE,IAAI;YACrB,eAAe,EAAE,KAAK;SACvB,CAAA;KACF;IAED,qBAAqB;QACnB,OAAO;YACL,IAAIC,uBAAM,CAAC;gBACT,KAAK,EAAE;oBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE;wBAC9B,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAA;wBAC3E,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAA;wBAC5B,MAAM,WAAW,GAAiB,EAAE,CAAA;wBAEpC,IAAI,CAAC,MAAM,EAAE;4BACX,OAAM;yBACP;wBAED,GAAG,CAAC,WAAW,CAAC,CAAC,IAAI,EAAE,GAAG;4BACxB,MAAM,SAAS,GAAG,MAAM,IAAI,GAAG,IAAI,MAAM,KAAK,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAA;4BAClE,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,IAAI,CAAC,UAAU,CAAA;4BAEhD,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,eAAe,KAAK,OAAO,EAAE;gCAC3D,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;gCAE7C,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE;oCACvB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;iCAC5C;gCAED,MAAM,UAAU,GAAGC,0BAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;oCAC3D,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;oCACxB,kBAAkB,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,UAAU;0CAC9D,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;4CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;4CACnB,IAAI;4CACJ,GAAG;yCACJ,CAAC;0CACA,IAAI,CAAC,OAAO,CAAC,WAAW;iCAC7B,CAAC,CAAA;gCAEF,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;6BAC7B;4BAED,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAA;yBACpC,CAAC,CAAA;wBAEF,OAAOC,6BAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;iBACF;aACF,CAAC;SACH,CAAA;KACF;CACF;;;;;"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { Extension
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
2
|
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
3
3
|
import { Plugin } from 'prosemirror-state';
|
|
4
4
|
|
|
5
5
|
const Placeholder = Extension.create({
|
|
6
6
|
name: 'placeholder',
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
};
|
|
13
16
|
},
|
|
14
17
|
addProseMirrorPlugins() {
|
|
15
18
|
return [
|
|
@@ -24,7 +27,7 @@ const Placeholder = Extension.create({
|
|
|
24
27
|
}
|
|
25
28
|
doc.descendants((node, pos) => {
|
|
26
29
|
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
|
|
27
|
-
const isEmpty = !node.isLeaf &&
|
|
30
|
+
const isEmpty = !node.isLeaf && !node.childCount;
|
|
28
31
|
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
29
32
|
const classes = [this.options.emptyNodeClass];
|
|
30
33
|
if (this.editor.isEmpty) {
|
|
@@ -36,12 +39,13 @@ const Placeholder = Extension.create({
|
|
|
36
39
|
? this.options.placeholder({
|
|
37
40
|
editor: this.editor,
|
|
38
41
|
node,
|
|
42
|
+
pos,
|
|
39
43
|
})
|
|
40
44
|
: this.options.placeholder,
|
|
41
45
|
});
|
|
42
46
|
decorations.push(decoration);
|
|
43
47
|
}
|
|
44
|
-
return
|
|
48
|
+
return this.options.includeChildren;
|
|
45
49
|
});
|
|
46
50
|
return DecorationSet.create(doc, decorations);
|
|
47
51
|
},
|
|
@@ -51,6 +55,5 @@ const Placeholder = Extension.create({
|
|
|
51
55
|
},
|
|
52
56
|
});
|
|
53
57
|
|
|
54
|
-
export default
|
|
55
|
-
export { Placeholder };
|
|
58
|
+
export { Placeholder, Placeholder as default };
|
|
56
59
|
//# sourceMappingURL=tiptap-extension-placeholder.esm.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap-extension-placeholder.esm.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension
|
|
1
|
+
{"version":3,"file":"tiptap-extension-placeholder.esm.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from 'prosemirror-model'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\nimport { Plugin } from 'prosemirror-state'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n pos: number,\n }) => string) | 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\n }\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 (this.editor.isEmpty) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder': typeof this.options.placeholder === 'function'\n ? this.options.placeholder({\n editor: this.editor,\n node,\n pos,\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":";;;;MAkBa,WAAW,GAAG,SAAS,CAAC,MAAM,CAAqB;IAC9D,IAAI,E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,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;oCACxB,kBAAkB,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,UAAU;0CAC9D,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;4CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;4CACnB,IAAI;4CACJ,GAAG;yCACJ,CAAC;0CACA,IAAI,CAAC,OAAO,CAAC,WAAW;iCAC7B,CAAC,CAAA;gCAEF,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;6BAC7B;4BAED,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAA;yBACpC,CAAC,CAAA;wBAEF,OAAO,aAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;iBACF;aACF,CAAC;SACH,CAAA;KACF;CACF;;;;"}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('prosemirror-view'), require('prosemirror-state')) :
|
|
3
3
|
typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', 'prosemirror-view', 'prosemirror-state'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global[
|
|
5
|
-
}(this, (function (exports, core, prosemirrorView, prosemirrorState) { 'use strict';
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-placeholder"] = {}, global.core, global.prosemirrorView, global.prosemirrorState));
|
|
5
|
+
})(this, (function (exports, core, prosemirrorView, prosemirrorState) { 'use strict';
|
|
6
6
|
|
|
7
7
|
const Placeholder = core.Extension.create({
|
|
8
8
|
name: 'placeholder',
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
+
};
|
|
15
18
|
},
|
|
16
19
|
addProseMirrorPlugins() {
|
|
17
20
|
return [
|
|
@@ -26,7 +29,7 @@
|
|
|
26
29
|
}
|
|
27
30
|
doc.descendants((node, pos) => {
|
|
28
31
|
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
|
|
29
|
-
const isEmpty = !node.isLeaf &&
|
|
32
|
+
const isEmpty = !node.isLeaf && !node.childCount;
|
|
30
33
|
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
31
34
|
const classes = [this.options.emptyNodeClass];
|
|
32
35
|
if (this.editor.isEmpty) {
|
|
@@ -38,12 +41,13 @@
|
|
|
38
41
|
? this.options.placeholder({
|
|
39
42
|
editor: this.editor,
|
|
40
43
|
node,
|
|
44
|
+
pos,
|
|
41
45
|
})
|
|
42
46
|
: this.options.placeholder,
|
|
43
47
|
});
|
|
44
48
|
decorations.push(decoration);
|
|
45
49
|
}
|
|
46
|
-
return
|
|
50
|
+
return this.options.includeChildren;
|
|
47
51
|
});
|
|
48
52
|
return prosemirrorView.DecorationSet.create(doc, decorations);
|
|
49
53
|
},
|
|
@@ -54,9 +58,9 @@
|
|
|
54
58
|
});
|
|
55
59
|
|
|
56
60
|
exports.Placeholder = Placeholder;
|
|
57
|
-
exports
|
|
61
|
+
exports["default"] = Placeholder;
|
|
58
62
|
|
|
59
63
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
60
64
|
|
|
61
|
-
}))
|
|
65
|
+
}));
|
|
62
66
|
//# sourceMappingURL=tiptap-extension-placeholder.umd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tiptap-extension-placeholder.umd.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension
|
|
1
|
+
{"version":3,"file":"tiptap-extension-placeholder.umd.js","sources":["../src/placeholder.ts"],"sourcesContent":["import { Editor, Extension } from '@tiptap/core'\nimport { Node as ProsemirrorNode } from 'prosemirror-model'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\nimport { Plugin } from 'prosemirror-state'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n pos: number,\n }) => string) | 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\n }\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 (this.editor.isEmpty) {\n classes.push(this.options.emptyEditorClass)\n }\n\n const decoration = Decoration.node(pos, pos + node.nodeSize, {\n class: classes.join(' '),\n 'data-placeholder': typeof this.options.placeholder === 'function'\n ? this.options.placeholder({\n editor: this.editor,\n node,\n pos,\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":";;;;;;QAkBa,WAAW,GAAGA,cAAS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,CAAC,QAAQ,EAAE;sCAC3D,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;sCACxB,kBAAkB,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,UAAU;4CAC9D,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;8CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;8CACnB,IAAI;8CACJ,GAAG;2CACJ,CAAC;4CACA,IAAI,CAAC,OAAO,CAAC,WAAW;mCAC7B,CAAC,CAAA;kCAEF,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;+BAC7B;8BAED,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAA;2BACpC,CAAC,CAAA;0BAEF,OAAOC,6BAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;uBAC9C;mBACF;eACF,CAAC;WACH,CAAA;OACF;GACF;;;;;;;;;;;"}
|
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.
|
|
4
|
+
"version": "2.0.0-beta.40",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
"main": "dist/tiptap-extension-placeholder.cjs.js",
|
|
16
16
|
"umd": "dist/tiptap-extension-placeholder.umd.js",
|
|
17
17
|
"module": "dist/tiptap-extension-placeholder.esm.js",
|
|
18
|
-
"unpkg": "dist/tiptap-extension-placeholder.bundle.umd.min.js",
|
|
19
18
|
"types": "dist/packages/extension-placeholder/src/index.d.ts",
|
|
20
19
|
"files": [
|
|
21
20
|
"src",
|
|
@@ -25,9 +24,14 @@
|
|
|
25
24
|
"@tiptap/core": "^2.0.0-beta.1"
|
|
26
25
|
},
|
|
27
26
|
"dependencies": {
|
|
28
|
-
"prosemirror-model": "^1.
|
|
27
|
+
"prosemirror-model": "^1.15.0",
|
|
29
28
|
"prosemirror-state": "^1.3.4",
|
|
30
|
-
"prosemirror-view": "^1.
|
|
29
|
+
"prosemirror-view": "^1.22.0"
|
|
31
30
|
},
|
|
32
|
-
"
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/ueberdosis/tiptap",
|
|
34
|
+
"directory": "packages/extension-placeholder"
|
|
35
|
+
},
|
|
36
|
+
"gitHead": "926cfcd6025c6a333ed0b53b9a687c238a9a69b3"
|
|
33
37
|
}
|
package/src/placeholder.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Editor, Extension
|
|
1
|
+
import { Editor, Extension } from '@tiptap/core'
|
|
2
2
|
import { Node as ProsemirrorNode } from 'prosemirror-model'
|
|
3
3
|
import { Decoration, DecorationSet } from 'prosemirror-view'
|
|
4
4
|
import { Plugin } from 'prosemirror-state'
|
|
@@ -9,20 +9,25 @@ export interface PlaceholderOptions {
|
|
|
9
9
|
placeholder: ((PlaceholderProps: {
|
|
10
10
|
editor: Editor,
|
|
11
11
|
node: ProsemirrorNode,
|
|
12
|
+
pos: number,
|
|
12
13
|
}) => string) | string,
|
|
13
14
|
showOnlyWhenEditable: boolean,
|
|
14
15
|
showOnlyCurrent: boolean,
|
|
16
|
+
includeChildren: boolean,
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
export const Placeholder = Extension.create<PlaceholderOptions>({
|
|
18
20
|
name: 'placeholder',
|
|
19
21
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
addOptions() {
|
|
23
|
+
return {
|
|
24
|
+
emptyEditorClass: 'is-editor-empty',
|
|
25
|
+
emptyNodeClass: 'is-empty',
|
|
26
|
+
placeholder: 'Write something …',
|
|
27
|
+
showOnlyWhenEditable: true,
|
|
28
|
+
showOnlyCurrent: true,
|
|
29
|
+
includeChildren: false,
|
|
30
|
+
}
|
|
26
31
|
},
|
|
27
32
|
|
|
28
33
|
addProseMirrorPlugins() {
|
|
@@ -40,7 +45,7 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
|
|
|
40
45
|
|
|
41
46
|
doc.descendants((node, pos) => {
|
|
42
47
|
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)
|
|
43
|
-
const isEmpty = !node.isLeaf &&
|
|
48
|
+
const isEmpty = !node.isLeaf && !node.childCount
|
|
44
49
|
|
|
45
50
|
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
46
51
|
const classes = [this.options.emptyNodeClass]
|
|
@@ -55,6 +60,7 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
|
|
|
55
60
|
? this.options.placeholder({
|
|
56
61
|
editor: this.editor,
|
|
57
62
|
node,
|
|
63
|
+
pos,
|
|
58
64
|
})
|
|
59
65
|
: this.options.placeholder,
|
|
60
66
|
})
|
|
@@ -62,7 +68,7 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
|
|
|
62
68
|
decorations.push(decoration)
|
|
63
69
|
}
|
|
64
70
|
|
|
65
|
-
return
|
|
71
|
+
return this.options.includeChildren
|
|
66
72
|
})
|
|
67
73
|
|
|
68
74
|
return DecorationSet.create(doc, decorations)
|
package/CHANGELOG.md
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
All notable changes to this project will be documented in this file.
|
|
4
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
-
|
|
6
|
-
# [2.0.0-beta.4](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-placeholder@2.0.0-beta.3...@tiptap/extension-placeholder@2.0.0-beta.4) (2021-04-06)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# [2.0.0-beta.3](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-placeholder@2.0.0-beta.2...@tiptap/extension-placeholder@2.0.0-beta.3) (2021-03-31)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
# [2.0.0-beta.2](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-placeholder@2.0.0-beta.1...@tiptap/extension-placeholder@2.0.0-beta.2) (2021-03-28)
|
|
23
|
-
|
|
24
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
# 2.0.0-beta.1 (2021-03-24)
|
|
31
|
-
|
|
32
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|