@tiptap/extension-placeholder 2.0.0-beta.42 → 2.0.0-beta.46
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/packages/extension-placeholder/src/index.d.ts +3 -0
- package/dist/packages/extension-placeholder/src/placeholder.d.ts +15 -0
- package/dist/tiptap-extension-placeholder.cjs.js +64 -0
- package/dist/tiptap-extension-placeholder.cjs.js.map +1 -0
- package/dist/tiptap-extension-placeholder.esm.js +59 -0
- package/dist/tiptap-extension-placeholder.esm.js.map +1 -0
- package/dist/tiptap-extension-placeholder.umd.js +66 -0
- package/dist/tiptap-extension-placeholder.umd.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Editor, Extension } from '@tiptap/core';
|
|
2
|
+
import { Node as ProsemirrorNode } from 'prosemirror-model';
|
|
3
|
+
export interface PlaceholderOptions {
|
|
4
|
+
emptyEditorClass: string;
|
|
5
|
+
emptyNodeClass: string;
|
|
6
|
+
placeholder: ((PlaceholderProps: {
|
|
7
|
+
editor: Editor;
|
|
8
|
+
node: ProsemirrorNode;
|
|
9
|
+
pos: number;
|
|
10
|
+
}) => string) | string;
|
|
11
|
+
showOnlyWhenEditable: boolean;
|
|
12
|
+
showOnlyCurrent: boolean;
|
|
13
|
+
includeChildren: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare const Placeholder: Extension<PlaceholderOptions, any>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var core = require('@tiptap/core');
|
|
6
|
+
var prosemirrorView = require('prosemirror-view');
|
|
7
|
+
var prosemirrorState = require('prosemirror-state');
|
|
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 prosemirrorState.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;
|
|
31
|
+
}
|
|
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 (this.editor.isEmpty) {
|
|
38
|
+
classes.push(this.options.emptyEditorClass);
|
|
39
|
+
}
|
|
40
|
+
const decoration = prosemirrorView.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
|
+
})
|
|
48
|
+
: this.options.placeholder,
|
|
49
|
+
});
|
|
50
|
+
decorations.push(decoration);
|
|
51
|
+
}
|
|
52
|
+
return this.options.includeChildren;
|
|
53
|
+
});
|
|
54
|
+
return prosemirrorView.DecorationSet.create(doc, decorations);
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
}),
|
|
58
|
+
];
|
|
59
|
+
},
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
exports.Placeholder = Placeholder;
|
|
63
|
+
exports["default"] = Placeholder;
|
|
64
|
+
//# sourceMappingURL=tiptap-extension-placeholder.cjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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;;;;;"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/core';
|
|
2
|
+
import { Decoration, DecorationSet } from 'prosemirror-view';
|
|
3
|
+
import { Plugin } from 'prosemirror-state';
|
|
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;
|
|
27
|
+
}
|
|
28
|
+
doc.descendants((node, pos) => {
|
|
29
|
+
const hasAnchor = anchor >= pos && anchor <= (pos + node.nodeSize);
|
|
30
|
+
const isEmpty = !node.isLeaf && !node.childCount;
|
|
31
|
+
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
32
|
+
const classes = [this.options.emptyNodeClass];
|
|
33
|
+
if (this.editor.isEmpty) {
|
|
34
|
+
classes.push(this.options.emptyEditorClass);
|
|
35
|
+
}
|
|
36
|
+
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
|
37
|
+
class: classes.join(' '),
|
|
38
|
+
'data-placeholder': typeof this.options.placeholder === 'function'
|
|
39
|
+
? this.options.placeholder({
|
|
40
|
+
editor: this.editor,
|
|
41
|
+
node,
|
|
42
|
+
pos,
|
|
43
|
+
})
|
|
44
|
+
: this.options.placeholder,
|
|
45
|
+
});
|
|
46
|
+
decorations.push(decoration);
|
|
47
|
+
}
|
|
48
|
+
return this.options.includeChildren;
|
|
49
|
+
});
|
|
50
|
+
return DecorationSet.create(doc, decorations);
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
}),
|
|
54
|
+
];
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export { Placeholder, Placeholder as default };
|
|
59
|
+
//# sourceMappingURL=tiptap-extension-placeholder.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,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,EA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C,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;;;;"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('prosemirror-view'), require('prosemirror-state')) :
|
|
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["@tiptap/extension-placeholder"] = {}, global.core, global.prosemirrorView, global.prosemirrorState));
|
|
5
|
+
})(this, (function (exports, core, prosemirrorView, prosemirrorState) { '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 prosemirrorState.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;
|
|
29
|
+
}
|
|
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 (this.editor.isEmpty) {
|
|
36
|
+
classes.push(this.options.emptyEditorClass);
|
|
37
|
+
}
|
|
38
|
+
const decoration = prosemirrorView.Decoration.node(pos, pos + node.nodeSize, {
|
|
39
|
+
class: classes.join(' '),
|
|
40
|
+
'data-placeholder': typeof this.options.placeholder === 'function'
|
|
41
|
+
? this.options.placeholder({
|
|
42
|
+
editor: this.editor,
|
|
43
|
+
node,
|
|
44
|
+
pos,
|
|
45
|
+
})
|
|
46
|
+
: this.options.placeholder,
|
|
47
|
+
});
|
|
48
|
+
decorations.push(decoration);
|
|
49
|
+
}
|
|
50
|
+
return this.options.includeChildren;
|
|
51
|
+
});
|
|
52
|
+
return prosemirrorView.DecorationSet.create(doc, decorations);
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
}),
|
|
56
|
+
];
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
exports.Placeholder = Placeholder;
|
|
61
|
+
exports["default"] = Placeholder;
|
|
62
|
+
|
|
63
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
64
|
+
|
|
65
|
+
}));
|
|
66
|
+
//# sourceMappingURL=tiptap-extension-placeholder.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,CAAC,MAAM,CAAqB;MAC9D,IAAI,EAAE,aAAa;MAEnB,UAAU;UACR,OAAO;cACL,gBAAgB,EAAE,iBAAiB;cACnC,cAAc,EAAE,UAAU;cAC1B,WAAW,EAAE,mBAAmB;cAChC,oBAAoB,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AC,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.46",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
"@tiptap/core": "^2.0.0-beta.1"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"prosemirror-model": "^1.
|
|
27
|
+
"prosemirror-model": "^1.16.1",
|
|
28
28
|
"prosemirror-state": "^1.3.4",
|
|
29
|
-
"prosemirror-view": "^1.
|
|
29
|
+
"prosemirror-view": "^1.23.5"
|
|
30
30
|
},
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
33
33
|
"url": "https://github.com/ueberdosis/tiptap",
|
|
34
34
|
"directory": "packages/extension-placeholder"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "e550d3c69e06a1fb153c3faf17ab78c3081ae61b"
|
|
37
37
|
}
|