@tiptap/extension-placeholder 2.0.0-beta.2 → 2.0.0-beta.200
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/README.md +2 -2
- package/dist/packages/extension-placeholder/src/placeholder.d.ts +4 -1
- package/dist/tiptap-extension-placeholder.cjs.js +20 -12
- package/dist/tiptap-extension-placeholder.cjs.js.map +1 -1
- package/dist/tiptap-extension-placeholder.esm.js +21 -14
- package/dist/tiptap-extension-placeholder.esm.js.map +1 -1
- package/dist/tiptap-extension-placeholder.umd.js +24 -16
- package/dist/tiptap-extension-placeholder.umd.js.map +1 -1
- package/package.json +10 -7
- package/src/placeholder.ts +24 -12
- package/CHANGELOG.md +0 -16
- package/LICENSE.md +0 -21
- package/dist/tiptap-extension-placeholder.bundle.umd.min.js +0 -2
- package/dist/tiptap-extension-placeholder.bundle.umd.min.js.map +0 -1
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,11 @@ export interface PlaceholderOptions {
|
|
|
6
6
|
placeholder: ((PlaceholderProps: {
|
|
7
7
|
editor: Editor;
|
|
8
8
|
node: ProsemirrorNode;
|
|
9
|
+
pos: number;
|
|
10
|
+
hasAnchor: boolean;
|
|
9
11
|
}) => string) | string;
|
|
10
12
|
showOnlyWhenEditable: boolean;
|
|
11
13
|
showOnlyCurrent: boolean;
|
|
14
|
+
includeChildren: boolean;
|
|
12
15
|
}
|
|
13
|
-
export declare const Placeholder: Extension<PlaceholderOptions>;
|
|
16
|
+
export declare const Placeholder: Extension<PlaceholderOptions, any>;
|
|
@@ -3,17 +3,20 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var core = require('@tiptap/core');
|
|
6
|
-
var prosemirrorView = require('prosemirror-view');
|
|
7
6
|
var prosemirrorState = require('prosemirror-state');
|
|
7
|
+
var prosemirrorView = require('prosemirror-view');
|
|
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 [
|
|
@@ -24,14 +27,17 @@ const Placeholder = core.Extension.create({
|
|
|
24
27
|
const { anchor } = selection;
|
|
25
28
|
const decorations = [];
|
|
26
29
|
if (!active) {
|
|
27
|
-
return;
|
|
30
|
+
return null;
|
|
28
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)) && emptyDocInstance.content.findDiffStart(doc.content) === null;
|
|
29
35
|
doc.descendants((node, pos) => {
|
|
30
36
|
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
|
|
31
|
-
const isEmpty = !node.isLeaf &&
|
|
37
|
+
const isEmpty = !node.isLeaf && !node.childCount;
|
|
32
38
|
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
33
39
|
const classes = [this.options.emptyNodeClass];
|
|
34
|
-
if (
|
|
40
|
+
if (isEditorEmpty) {
|
|
35
41
|
classes.push(this.options.emptyEditorClass);
|
|
36
42
|
}
|
|
37
43
|
const decoration = prosemirrorView.Decoration.node(pos, pos + node.nodeSize, {
|
|
@@ -40,12 +46,14 @@ const Placeholder = core.Extension.create({
|
|
|
40
46
|
? this.options.placeholder({
|
|
41
47
|
editor: this.editor,
|
|
42
48
|
node,
|
|
49
|
+
pos,
|
|
50
|
+
hasAnchor,
|
|
43
51
|
})
|
|
44
52
|
: this.options.placeholder,
|
|
45
53
|
});
|
|
46
54
|
decorations.push(decoration);
|
|
47
55
|
}
|
|
48
|
-
return
|
|
56
|
+
return this.options.includeChildren;
|
|
49
57
|
});
|
|
50
58
|
return prosemirrorView.DecorationSet.create(doc, decorations);
|
|
51
59
|
},
|
|
@@ -56,5 +64,5 @@ const Placeholder = core.Extension.create({
|
|
|
56
64
|
});
|
|
57
65
|
|
|
58
66
|
exports.Placeholder = Placeholder;
|
|
59
|
-
exports
|
|
67
|
+
exports["default"] = Placeholder;
|
|
60
68
|
//# 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 { Plugin } from 'prosemirror-state'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n pos: number,\n hasAnchor: boolean,\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 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) && 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': 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":";;;;;;;;AAmBa,MAAA,WAAW,GAAGA,cAAS,CAAC,MAAM,CAAqB;AAC9D,IAAA,IAAI,EAAE,aAAa;IAEnB,UAAU,GAAA;QACR,OAAO;AACL,YAAA,gBAAgB,EAAE,iBAAi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AAO,CAAC,eAAe,KAAK,OAAO,EAAE;gCAC3D,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,CAAA;AAE7C,gCAAA,IAAI,aAAa,EAAE;oCACjB,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAA;AAC5C,iCAAA;AAED,gCAAA,MAAM,UAAU,GAAGC,0BAAU,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC,QAAQ,EAAE;AAC3D,oCAAA,KAAK,EAAE,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC;oCACxB,kBAAkB,EAAE,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,KAAK,UAAU;AAChE,0CAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;4CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;4CACnB,IAAI;4CACJ,GAAG;4CACH,SAAS;yCACV,CAAC;AACF,0CAAE,IAAI,CAAC,OAAO,CAAC,WAAW;AAC7B,iCAAA,CAAC,CAAA;AAEF,gCAAA,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,CAAA;AAC7B,6BAAA;AAED,4BAAA,OAAO,IAAI,CAAC,OAAO,CAAC,eAAe,CAAA;AACrC,yBAAC,CAAC,CAAA;wBAEF,OAAOC,6BAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;qBAC9C;AACF,iBAAA;aACF,CAAC;SACH,CAAA;KACF;AACF,CAAA;;;;;"}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
-
import { Extension
|
|
2
|
-
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
3
2
|
import { Plugin } from 'prosemirror-state';
|
|
3
|
+
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
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 [
|
|
@@ -20,14 +23,17 @@ const Placeholder = Extension.create({
|
|
|
20
23
|
const { anchor } = selection;
|
|
21
24
|
const decorations = [];
|
|
22
25
|
if (!active) {
|
|
23
|
-
return;
|
|
26
|
+
return null;
|
|
24
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)) && emptyDocInstance.content.findDiffStart(doc.content) === null;
|
|
25
31
|
doc.descendants((node, pos) => {
|
|
26
32
|
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
|
|
27
|
-
const isEmpty = !node.isLeaf &&
|
|
33
|
+
const isEmpty = !node.isLeaf && !node.childCount;
|
|
28
34
|
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
29
35
|
const classes = [this.options.emptyNodeClass];
|
|
30
|
-
if (
|
|
36
|
+
if (isEditorEmpty) {
|
|
31
37
|
classes.push(this.options.emptyEditorClass);
|
|
32
38
|
}
|
|
33
39
|
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
|
@@ -36,12 +42,14 @@ const Placeholder = Extension.create({
|
|
|
36
42
|
? this.options.placeholder({
|
|
37
43
|
editor: this.editor,
|
|
38
44
|
node,
|
|
45
|
+
pos,
|
|
46
|
+
hasAnchor,
|
|
39
47
|
})
|
|
40
48
|
: this.options.placeholder,
|
|
41
49
|
});
|
|
42
50
|
decorations.push(decoration);
|
|
43
51
|
}
|
|
44
|
-
return
|
|
52
|
+
return this.options.includeChildren;
|
|
45
53
|
});
|
|
46
54
|
return DecorationSet.create(doc, decorations);
|
|
47
55
|
},
|
|
@@ -51,6 +59,5 @@ const Placeholder = Extension.create({
|
|
|
51
59
|
},
|
|
52
60
|
});
|
|
53
61
|
|
|
54
|
-
export default
|
|
55
|
-
export { Placeholder };
|
|
62
|
+
export { Placeholder, Placeholder as default };
|
|
56
63
|
//# 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 { Plugin } from 'prosemirror-state'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n pos: number,\n hasAnchor: boolean,\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 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) && 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': 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":";;;;AAmBa,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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,UAAU;AAChE,0CAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC;4CACzB,MAAM,EAAE,IAAI,CAAC,MAAM;4CACnB,IAAI;4CACJ,GAAG;4CACH,SAAS;yCACV,CAAC;AACF,0CAAE,IAAI,CAAC,OAAO,CAAC,WAAW;AAC7B,iCAAA,CAAC,CAAA;AAEF,gCAAA,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC,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;;;;"}
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('prosemirror-
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', 'prosemirror-
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global[
|
|
5
|
-
}(this, (function (exports, core,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('prosemirror-state'), require('prosemirror-view')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', 'prosemirror-state', 'prosemirror-view'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-placeholder"] = {}, global.core, global.prosemirrorState, global.prosemirrorView));
|
|
5
|
+
})(this, (function (exports, core, prosemirrorState, prosemirrorView) { '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 [
|
|
@@ -22,14 +25,17 @@
|
|
|
22
25
|
const { anchor } = selection;
|
|
23
26
|
const decorations = [];
|
|
24
27
|
if (!active) {
|
|
25
|
-
return;
|
|
28
|
+
return null;
|
|
26
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)) && emptyDocInstance.content.findDiffStart(doc.content) === null;
|
|
27
33
|
doc.descendants((node, pos) => {
|
|
28
34
|
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
|
|
29
|
-
const isEmpty = !node.isLeaf &&
|
|
35
|
+
const isEmpty = !node.isLeaf && !node.childCount;
|
|
30
36
|
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
31
37
|
const classes = [this.options.emptyNodeClass];
|
|
32
|
-
if (
|
|
38
|
+
if (isEditorEmpty) {
|
|
33
39
|
classes.push(this.options.emptyEditorClass);
|
|
34
40
|
}
|
|
35
41
|
const decoration = prosemirrorView.Decoration.node(pos, pos + node.nodeSize, {
|
|
@@ -38,12 +44,14 @@
|
|
|
38
44
|
? this.options.placeholder({
|
|
39
45
|
editor: this.editor,
|
|
40
46
|
node,
|
|
47
|
+
pos,
|
|
48
|
+
hasAnchor,
|
|
41
49
|
})
|
|
42
50
|
: this.options.placeholder,
|
|
43
51
|
});
|
|
44
52
|
decorations.push(decoration);
|
|
45
53
|
}
|
|
46
|
-
return
|
|
54
|
+
return this.options.includeChildren;
|
|
47
55
|
});
|
|
48
56
|
return prosemirrorView.DecorationSet.create(doc, decorations);
|
|
49
57
|
},
|
|
@@ -54,9 +62,9 @@
|
|
|
54
62
|
});
|
|
55
63
|
|
|
56
64
|
exports.Placeholder = Placeholder;
|
|
57
|
-
exports
|
|
65
|
+
exports["default"] = Placeholder;
|
|
58
66
|
|
|
59
67
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
60
68
|
|
|
61
|
-
}))
|
|
69
|
+
}));
|
|
62
70
|
//# 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 { Plugin } from 'prosemirror-state'\nimport { Decoration, DecorationSet } from 'prosemirror-view'\n\nexport interface PlaceholderOptions {\n emptyEditorClass: string,\n emptyNodeClass: string,\n placeholder: ((PlaceholderProps: {\n editor: Editor,\n node: ProsemirrorNode,\n pos: number,\n hasAnchor: boolean,\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 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) && 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': 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":";;;;;;AAmBa,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,uBAAM,CAAC;EACT,gBAAA,KAAK,EAAE;sBACL,WAAW,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,KAAI;EAClC,wBAAA,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,oBAAoB,CAAA;EAC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,OAAO,CAAC,WAAW,KAAK,UAAU;EAChE,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;EAC7B,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,6BAAa,CAAC,MAAM,CAAC,GAAG,EAAE,WAAW,CAAC,CAAA;uBAC9C;EACF,iBAAA;eACF,CAAC;WACH,CAAA;OACF;EACF,CAAA;;;;;;;;;;;"}
|
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.200",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -15,19 +15,22 @@
|
|
|
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",
|
|
22
21
|
"dist"
|
|
23
22
|
],
|
|
24
23
|
"peerDependencies": {
|
|
25
|
-
"@tiptap/core": "^2.0.0-beta.
|
|
24
|
+
"@tiptap/core": "^2.0.0-beta.193"
|
|
26
25
|
},
|
|
27
26
|
"dependencies": {
|
|
28
|
-
"prosemirror-model": "^1.
|
|
29
|
-
"prosemirror-state": "^1.
|
|
30
|
-
"prosemirror-view": "^1.
|
|
27
|
+
"prosemirror-model": "^1.18.1",
|
|
28
|
+
"prosemirror-state": "^1.4.1",
|
|
29
|
+
"prosemirror-view": "^1.28.2"
|
|
31
30
|
},
|
|
32
|
-
"
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/ueberdosis/tiptap",
|
|
34
|
+
"directory": "packages/extension-placeholder"
|
|
35
|
+
}
|
|
33
36
|
}
|
package/src/placeholder.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Editor, Extension
|
|
1
|
+
import { Editor, Extension } from '@tiptap/core'
|
|
2
2
|
import { Node as ProsemirrorNode } from 'prosemirror-model'
|
|
3
|
-
import { Decoration, DecorationSet } from 'prosemirror-view'
|
|
4
3
|
import { Plugin } from 'prosemirror-state'
|
|
4
|
+
import { Decoration, DecorationSet } from 'prosemirror-view'
|
|
5
5
|
|
|
6
6
|
export interface PlaceholderOptions {
|
|
7
7
|
emptyEditorClass: string,
|
|
@@ -9,20 +9,26 @@ export interface PlaceholderOptions {
|
|
|
9
9
|
placeholder: ((PlaceholderProps: {
|
|
10
10
|
editor: Editor,
|
|
11
11
|
node: ProsemirrorNode,
|
|
12
|
+
pos: number,
|
|
13
|
+
hasAnchor: boolean,
|
|
12
14
|
}) => string) | string,
|
|
13
15
|
showOnlyWhenEditable: boolean,
|
|
14
16
|
showOnlyCurrent: boolean,
|
|
17
|
+
includeChildren: boolean,
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
export const Placeholder = Extension.create<PlaceholderOptions>({
|
|
18
21
|
name: 'placeholder',
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
addOptions() {
|
|
24
|
+
return {
|
|
25
|
+
emptyEditorClass: 'is-editor-empty',
|
|
26
|
+
emptyNodeClass: 'is-empty',
|
|
27
|
+
placeholder: 'Write something …',
|
|
28
|
+
showOnlyWhenEditable: true,
|
|
29
|
+
showOnlyCurrent: true,
|
|
30
|
+
includeChildren: false,
|
|
31
|
+
}
|
|
26
32
|
},
|
|
27
33
|
|
|
28
34
|
addProseMirrorPlugins() {
|
|
@@ -35,17 +41,21 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
|
|
|
35
41
|
const decorations: Decoration[] = []
|
|
36
42
|
|
|
37
43
|
if (!active) {
|
|
38
|
-
return
|
|
44
|
+
return null
|
|
39
45
|
}
|
|
40
46
|
|
|
47
|
+
// only calculate isEmpty once due to its performance impacts (see issue #3360)
|
|
48
|
+
const emptyDocInstance = doc.type.createAndFill()
|
|
49
|
+
const isEditorEmpty = emptyDocInstance?.sameMarkup(doc) && emptyDocInstance.content.findDiffStart(doc.content) === null
|
|
50
|
+
|
|
41
51
|
doc.descendants((node, pos) => {
|
|
42
52
|
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize)
|
|
43
|
-
const isEmpty = !node.isLeaf &&
|
|
53
|
+
const isEmpty = !node.isLeaf && !node.childCount
|
|
44
54
|
|
|
45
55
|
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
46
56
|
const classes = [this.options.emptyNodeClass]
|
|
47
57
|
|
|
48
|
-
if (
|
|
58
|
+
if (isEditorEmpty) {
|
|
49
59
|
classes.push(this.options.emptyEditorClass)
|
|
50
60
|
}
|
|
51
61
|
|
|
@@ -55,6 +65,8 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
|
|
|
55
65
|
? this.options.placeholder({
|
|
56
66
|
editor: this.editor,
|
|
57
67
|
node,
|
|
68
|
+
pos,
|
|
69
|
+
hasAnchor,
|
|
58
70
|
})
|
|
59
71
|
: this.options.placeholder,
|
|
60
72
|
})
|
|
@@ -62,7 +74,7 @@ export const Placeholder = Extension.create<PlaceholderOptions>({
|
|
|
62
74
|
decorations.push(decoration)
|
|
63
75
|
}
|
|
64
76
|
|
|
65
|
-
return
|
|
77
|
+
return this.options.includeChildren
|
|
66
78
|
})
|
|
67
79
|
|
|
68
80
|
return DecorationSet.create(doc, decorations)
|
package/CHANGELOG.md
DELETED
|
@@ -1,16 +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.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)
|
|
7
|
-
|
|
8
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
# 2.0.0-beta.1 (2021-03-24)
|
|
15
|
-
|
|
16
|
-
**Note:** Version bump only for package @tiptap/extension-placeholder
|
package/LICENSE.md
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2020, überdosis GbR
|
|
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.
|