@tiptap/extension-placeholder 3.0.0-next.4 → 3.0.0-next.6
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/dist/index.cjs +7 -63
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -59
- package/dist/index.d.ts +2 -59
- package/dist/index.js +4 -59
- package/dist/index.js.map +1 -1
- package/package.json +3 -5
- package/src/index.ts +2 -2
- package/src/placeholder.ts +0 -128
package/LICENSE.md
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -20,73 +20,17 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/index.ts
|
|
21
21
|
var index_exports = {};
|
|
22
22
|
__export(index_exports, {
|
|
23
|
-
Placeholder: () => Placeholder,
|
|
23
|
+
Placeholder: () => import_extensions2.Placeholder,
|
|
24
|
+
PlaceholderOptions: () => import_extensions2.PlaceholderOptions,
|
|
24
25
|
default: () => index_default
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(index_exports);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
var
|
|
30
|
-
var import_state = require("@tiptap/pm/state");
|
|
31
|
-
var import_view = require("@tiptap/pm/view");
|
|
32
|
-
var Placeholder = import_core.Extension.create({
|
|
33
|
-
name: "placeholder",
|
|
34
|
-
addOptions() {
|
|
35
|
-
return {
|
|
36
|
-
emptyEditorClass: "is-editor-empty",
|
|
37
|
-
emptyNodeClass: "is-empty",
|
|
38
|
-
placeholder: "Write something \u2026",
|
|
39
|
-
showOnlyWhenEditable: true,
|
|
40
|
-
showOnlyCurrent: true,
|
|
41
|
-
includeChildren: false
|
|
42
|
-
};
|
|
43
|
-
},
|
|
44
|
-
addProseMirrorPlugins() {
|
|
45
|
-
return [
|
|
46
|
-
new import_state.Plugin({
|
|
47
|
-
key: new import_state.PluginKey("placeholder"),
|
|
48
|
-
props: {
|
|
49
|
-
decorations: ({ doc, selection }) => {
|
|
50
|
-
const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
|
|
51
|
-
const { anchor } = selection;
|
|
52
|
-
const decorations = [];
|
|
53
|
-
if (!active) {
|
|
54
|
-
return null;
|
|
55
|
-
}
|
|
56
|
-
const isEmptyDoc = this.editor.isEmpty;
|
|
57
|
-
doc.descendants((node, pos) => {
|
|
58
|
-
const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
|
|
59
|
-
const isEmpty = !node.isLeaf && (0, import_core.isNodeEmpty)(node);
|
|
60
|
-
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
61
|
-
const classes = [this.options.emptyNodeClass];
|
|
62
|
-
if (isEmptyDoc) {
|
|
63
|
-
classes.push(this.options.emptyEditorClass);
|
|
64
|
-
}
|
|
65
|
-
const decoration = import_view.Decoration.node(pos, pos + node.nodeSize, {
|
|
66
|
-
class: classes.join(" "),
|
|
67
|
-
"data-placeholder": typeof this.options.placeholder === "function" ? this.options.placeholder({
|
|
68
|
-
editor: this.editor,
|
|
69
|
-
node,
|
|
70
|
-
pos,
|
|
71
|
-
hasAnchor
|
|
72
|
-
}) : this.options.placeholder
|
|
73
|
-
});
|
|
74
|
-
decorations.push(decoration);
|
|
75
|
-
}
|
|
76
|
-
return this.options.includeChildren;
|
|
77
|
-
});
|
|
78
|
-
return import_view.DecorationSet.create(doc, decorations);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
})
|
|
82
|
-
];
|
|
83
|
-
}
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// src/index.ts
|
|
87
|
-
var index_default = Placeholder;
|
|
28
|
+
var import_extensions = require("@tiptap/extensions");
|
|
29
|
+
var import_extensions2 = require("@tiptap/extensions");
|
|
30
|
+
var index_default = import_extensions.Placeholder;
|
|
88
31
|
// Annotate the CommonJS export names for ESM import in node:
|
|
89
32
|
0 && (module.exports = {
|
|
90
|
-
Placeholder
|
|
33
|
+
Placeholder,
|
|
34
|
+
PlaceholderOptions
|
|
91
35
|
});
|
|
92
36
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Placeholder } from '@tiptap/extensions'\n\nexport { Placeholder, PlaceholderOptions } from '@tiptap/extensions'\n\nexport default Placeholder\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAA4B;AAE5B,IAAAA,qBAAgD;AAEhD,IAAO,gBAAQ;","names":["import_extensions"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,59 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
interface PlaceholderOptions {
|
|
5
|
-
/**
|
|
6
|
-
* **The class name for the empty editor**
|
|
7
|
-
* @default 'is-editor-empty'
|
|
8
|
-
*/
|
|
9
|
-
emptyEditorClass: string;
|
|
10
|
-
/**
|
|
11
|
-
* **The class name for empty nodes**
|
|
12
|
-
* @default 'is-empty'
|
|
13
|
-
*/
|
|
14
|
-
emptyNodeClass: string;
|
|
15
|
-
/**
|
|
16
|
-
* **The placeholder content**
|
|
17
|
-
*
|
|
18
|
-
* You can use a function to return a dynamic placeholder or a string.
|
|
19
|
-
* @default 'Write something …'
|
|
20
|
-
*/
|
|
21
|
-
placeholder: ((PlaceholderProps: {
|
|
22
|
-
editor: Editor;
|
|
23
|
-
node: Node;
|
|
24
|
-
pos: number;
|
|
25
|
-
hasAnchor: boolean;
|
|
26
|
-
}) => string) | string;
|
|
27
|
-
/**
|
|
28
|
-
* **Checks if the placeholder should be only shown when the editor is editable.**
|
|
29
|
-
*
|
|
30
|
-
* If true, the placeholder will only be shown when the editor is editable.
|
|
31
|
-
* If false, the placeholder will always be shown.
|
|
32
|
-
* @default true
|
|
33
|
-
*/
|
|
34
|
-
showOnlyWhenEditable: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* **Checks if the placeholder should be only shown when the current node is empty.**
|
|
37
|
-
*
|
|
38
|
-
* If true, the placeholder will only be shown when the current node is empty.
|
|
39
|
-
* If false, the placeholder will be shown when any node is empty.
|
|
40
|
-
* @default true
|
|
41
|
-
*/
|
|
42
|
-
showOnlyCurrent: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* **Controls if the placeholder should be shown for all descendents.**
|
|
45
|
-
*
|
|
46
|
-
* If true, the placeholder will be shown for all descendents.
|
|
47
|
-
* If false, the placeholder will only be shown for the current node.
|
|
48
|
-
* @default false
|
|
49
|
-
*/
|
|
50
|
-
includeChildren: boolean;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* This extension allows you to add a placeholder to your editor.
|
|
54
|
-
* A placeholder is a text that appears when the editor or a node is empty.
|
|
55
|
-
* @see https://www.tiptap.dev/api/extensions/placeholder
|
|
56
|
-
*/
|
|
57
|
-
declare const Placeholder: Extension<PlaceholderOptions, any>;
|
|
58
|
-
|
|
59
|
-
export { Placeholder, type PlaceholderOptions, Placeholder as default };
|
|
1
|
+
import { Placeholder } from '@tiptap/extensions';
|
|
2
|
+
export { Placeholder, PlaceholderOptions, Placeholder as default } from '@tiptap/extensions';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,59 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
interface PlaceholderOptions {
|
|
5
|
-
/**
|
|
6
|
-
* **The class name for the empty editor**
|
|
7
|
-
* @default 'is-editor-empty'
|
|
8
|
-
*/
|
|
9
|
-
emptyEditorClass: string;
|
|
10
|
-
/**
|
|
11
|
-
* **The class name for empty nodes**
|
|
12
|
-
* @default 'is-empty'
|
|
13
|
-
*/
|
|
14
|
-
emptyNodeClass: string;
|
|
15
|
-
/**
|
|
16
|
-
* **The placeholder content**
|
|
17
|
-
*
|
|
18
|
-
* You can use a function to return a dynamic placeholder or a string.
|
|
19
|
-
* @default 'Write something …'
|
|
20
|
-
*/
|
|
21
|
-
placeholder: ((PlaceholderProps: {
|
|
22
|
-
editor: Editor;
|
|
23
|
-
node: Node;
|
|
24
|
-
pos: number;
|
|
25
|
-
hasAnchor: boolean;
|
|
26
|
-
}) => string) | string;
|
|
27
|
-
/**
|
|
28
|
-
* **Checks if the placeholder should be only shown when the editor is editable.**
|
|
29
|
-
*
|
|
30
|
-
* If true, the placeholder will only be shown when the editor is editable.
|
|
31
|
-
* If false, the placeholder will always be shown.
|
|
32
|
-
* @default true
|
|
33
|
-
*/
|
|
34
|
-
showOnlyWhenEditable: boolean;
|
|
35
|
-
/**
|
|
36
|
-
* **Checks if the placeholder should be only shown when the current node is empty.**
|
|
37
|
-
*
|
|
38
|
-
* If true, the placeholder will only be shown when the current node is empty.
|
|
39
|
-
* If false, the placeholder will be shown when any node is empty.
|
|
40
|
-
* @default true
|
|
41
|
-
*/
|
|
42
|
-
showOnlyCurrent: boolean;
|
|
43
|
-
/**
|
|
44
|
-
* **Controls if the placeholder should be shown for all descendents.**
|
|
45
|
-
*
|
|
46
|
-
* If true, the placeholder will be shown for all descendents.
|
|
47
|
-
* If false, the placeholder will only be shown for the current node.
|
|
48
|
-
* @default false
|
|
49
|
-
*/
|
|
50
|
-
includeChildren: boolean;
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* This extension allows you to add a placeholder to your editor.
|
|
54
|
-
* A placeholder is a text that appears when the editor or a node is empty.
|
|
55
|
-
* @see https://www.tiptap.dev/api/extensions/placeholder
|
|
56
|
-
*/
|
|
57
|
-
declare const Placeholder: Extension<PlaceholderOptions, any>;
|
|
58
|
-
|
|
59
|
-
export { Placeholder, type PlaceholderOptions, Placeholder as default };
|
|
1
|
+
import { Placeholder } from '@tiptap/extensions';
|
|
2
|
+
export { Placeholder, PlaceholderOptions, Placeholder as default } from '@tiptap/extensions';
|
package/dist/index.js
CHANGED
|
@@ -1,65 +1,10 @@
|
|
|
1
|
-
// src/placeholder.ts
|
|
2
|
-
import { Extension, isNodeEmpty } from "@tiptap/core";
|
|
3
|
-
import { Plugin, PluginKey } from "@tiptap/pm/state";
|
|
4
|
-
import { Decoration, DecorationSet } from "@tiptap/pm/view";
|
|
5
|
-
var Placeholder = Extension.create({
|
|
6
|
-
name: "placeholder",
|
|
7
|
-
addOptions() {
|
|
8
|
-
return {
|
|
9
|
-
emptyEditorClass: "is-editor-empty",
|
|
10
|
-
emptyNodeClass: "is-empty",
|
|
11
|
-
placeholder: "Write something \u2026",
|
|
12
|
-
showOnlyWhenEditable: true,
|
|
13
|
-
showOnlyCurrent: true,
|
|
14
|
-
includeChildren: false
|
|
15
|
-
};
|
|
16
|
-
},
|
|
17
|
-
addProseMirrorPlugins() {
|
|
18
|
-
return [
|
|
19
|
-
new Plugin({
|
|
20
|
-
key: new PluginKey("placeholder"),
|
|
21
|
-
props: {
|
|
22
|
-
decorations: ({ doc, selection }) => {
|
|
23
|
-
const active = this.editor.isEditable || !this.options.showOnlyWhenEditable;
|
|
24
|
-
const { anchor } = selection;
|
|
25
|
-
const decorations = [];
|
|
26
|
-
if (!active) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
const isEmptyDoc = this.editor.isEmpty;
|
|
30
|
-
doc.descendants((node, pos) => {
|
|
31
|
-
const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
|
|
32
|
-
const isEmpty = !node.isLeaf && isNodeEmpty(node);
|
|
33
|
-
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
34
|
-
const classes = [this.options.emptyNodeClass];
|
|
35
|
-
if (isEmptyDoc) {
|
|
36
|
-
classes.push(this.options.emptyEditorClass);
|
|
37
|
-
}
|
|
38
|
-
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
|
39
|
-
class: classes.join(" "),
|
|
40
|
-
"data-placeholder": typeof this.options.placeholder === "function" ? this.options.placeholder({
|
|
41
|
-
editor: this.editor,
|
|
42
|
-
node,
|
|
43
|
-
pos,
|
|
44
|
-
hasAnchor
|
|
45
|
-
}) : this.options.placeholder
|
|
46
|
-
});
|
|
47
|
-
decorations.push(decoration);
|
|
48
|
-
}
|
|
49
|
-
return this.options.includeChildren;
|
|
50
|
-
});
|
|
51
|
-
return DecorationSet.create(doc, decorations);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
})
|
|
55
|
-
];
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
|
|
59
1
|
// src/index.ts
|
|
2
|
+
import { Placeholder } from "@tiptap/extensions";
|
|
3
|
+
import { Placeholder as Placeholder2, PlaceholderOptions } from "@tiptap/extensions";
|
|
60
4
|
var index_default = Placeholder;
|
|
61
5
|
export {
|
|
62
|
-
Placeholder,
|
|
6
|
+
Placeholder2 as Placeholder,
|
|
7
|
+
PlaceholderOptions,
|
|
63
8
|
index_default as default
|
|
64
9
|
};
|
|
65
10
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { Placeholder } from '@tiptap/extensions'\n\nexport { Placeholder, PlaceholderOptions } from '@tiptap/extensions'\n\nexport default Placeholder\n"],"mappings":";AAAA,SAAS,mBAAmB;AAE5B,SAAS,eAAAA,cAAa,0BAA0B;AAEhD,IAAO,gBAAQ;","names":["Placeholder"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/extension-placeholder",
|
|
3
3
|
"description": "placeholder extension for tiptap",
|
|
4
|
-
"version": "3.0.0-next.
|
|
4
|
+
"version": "3.0.0-next.6",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -31,12 +31,10 @@
|
|
|
31
31
|
"dist"
|
|
32
32
|
],
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@tiptap/
|
|
35
|
-
"@tiptap/pm": "^3.0.0-next.4"
|
|
34
|
+
"@tiptap/extensions": "^3.0.0-next.6"
|
|
36
35
|
},
|
|
37
36
|
"peerDependencies": {
|
|
38
|
-
"@tiptap/
|
|
39
|
-
"@tiptap/pm": "^3.0.0-next.1"
|
|
37
|
+
"@tiptap/extensions": "^3.0.0-next.3"
|
|
40
38
|
},
|
|
41
39
|
"repository": {
|
|
42
40
|
"type": "git",
|
package/src/index.ts
CHANGED
package/src/placeholder.ts
DELETED
|
@@ -1,128 +0,0 @@
|
|
|
1
|
-
import { Editor, Extension, isNodeEmpty } from '@tiptap/core'
|
|
2
|
-
import { Node as ProsemirrorNode } from '@tiptap/pm/model'
|
|
3
|
-
import { Plugin, PluginKey } from '@tiptap/pm/state'
|
|
4
|
-
import { Decoration, DecorationSet } from '@tiptap/pm/view'
|
|
5
|
-
|
|
6
|
-
export interface PlaceholderOptions {
|
|
7
|
-
/**
|
|
8
|
-
* **The class name for the empty editor**
|
|
9
|
-
* @default 'is-editor-empty'
|
|
10
|
-
*/
|
|
11
|
-
emptyEditorClass: string
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* **The class name for empty nodes**
|
|
15
|
-
* @default 'is-empty'
|
|
16
|
-
*/
|
|
17
|
-
emptyNodeClass: string
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* **The placeholder content**
|
|
21
|
-
*
|
|
22
|
-
* You can use a function to return a dynamic placeholder or a string.
|
|
23
|
-
* @default 'Write something …'
|
|
24
|
-
*/
|
|
25
|
-
placeholder:
|
|
26
|
-
| ((PlaceholderProps: { editor: Editor; node: ProsemirrorNode; pos: number; hasAnchor: boolean }) => string)
|
|
27
|
-
| string
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* **Checks if the placeholder should be only shown when the editor is editable.**
|
|
31
|
-
*
|
|
32
|
-
* If true, the placeholder will only be shown when the editor is editable.
|
|
33
|
-
* If false, the placeholder will always be shown.
|
|
34
|
-
* @default true
|
|
35
|
-
*/
|
|
36
|
-
showOnlyWhenEditable: boolean
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* **Checks if the placeholder should be only shown when the current node is empty.**
|
|
40
|
-
*
|
|
41
|
-
* If true, the placeholder will only be shown when the current node is empty.
|
|
42
|
-
* If false, the placeholder will be shown when any node is empty.
|
|
43
|
-
* @default true
|
|
44
|
-
*/
|
|
45
|
-
showOnlyCurrent: boolean
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* **Controls if the placeholder should be shown for all descendents.**
|
|
49
|
-
*
|
|
50
|
-
* If true, the placeholder will be shown for all descendents.
|
|
51
|
-
* If false, the placeholder will only be shown for the current node.
|
|
52
|
-
* @default false
|
|
53
|
-
*/
|
|
54
|
-
includeChildren: boolean
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* This extension allows you to add a placeholder to your editor.
|
|
59
|
-
* A placeholder is a text that appears when the editor or a node is empty.
|
|
60
|
-
* @see https://www.tiptap.dev/api/extensions/placeholder
|
|
61
|
-
*/
|
|
62
|
-
export const Placeholder = Extension.create<PlaceholderOptions>({
|
|
63
|
-
name: 'placeholder',
|
|
64
|
-
|
|
65
|
-
addOptions() {
|
|
66
|
-
return {
|
|
67
|
-
emptyEditorClass: 'is-editor-empty',
|
|
68
|
-
emptyNodeClass: 'is-empty',
|
|
69
|
-
placeholder: 'Write something …',
|
|
70
|
-
showOnlyWhenEditable: true,
|
|
71
|
-
showOnlyCurrent: true,
|
|
72
|
-
includeChildren: false,
|
|
73
|
-
}
|
|
74
|
-
},
|
|
75
|
-
|
|
76
|
-
addProseMirrorPlugins() {
|
|
77
|
-
return [
|
|
78
|
-
new Plugin({
|
|
79
|
-
key: new PluginKey('placeholder'),
|
|
80
|
-
props: {
|
|
81
|
-
decorations: ({ doc, selection }) => {
|
|
82
|
-
const active = this.editor.isEditable || !this.options.showOnlyWhenEditable
|
|
83
|
-
const { anchor } = selection
|
|
84
|
-
const decorations: Decoration[] = []
|
|
85
|
-
|
|
86
|
-
if (!active) {
|
|
87
|
-
return null
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
const isEmptyDoc = this.editor.isEmpty
|
|
91
|
-
|
|
92
|
-
doc.descendants((node, pos) => {
|
|
93
|
-
const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize
|
|
94
|
-
const isEmpty = !node.isLeaf && isNodeEmpty(node)
|
|
95
|
-
|
|
96
|
-
if ((hasAnchor || !this.options.showOnlyCurrent) && isEmpty) {
|
|
97
|
-
const classes = [this.options.emptyNodeClass]
|
|
98
|
-
|
|
99
|
-
if (isEmptyDoc) {
|
|
100
|
-
classes.push(this.options.emptyEditorClass)
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
const decoration = Decoration.node(pos, pos + node.nodeSize, {
|
|
104
|
-
class: classes.join(' '),
|
|
105
|
-
'data-placeholder':
|
|
106
|
-
typeof this.options.placeholder === 'function'
|
|
107
|
-
? this.options.placeholder({
|
|
108
|
-
editor: this.editor,
|
|
109
|
-
node,
|
|
110
|
-
pos,
|
|
111
|
-
hasAnchor,
|
|
112
|
-
})
|
|
113
|
-
: this.options.placeholder,
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
decorations.push(decoration)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return this.options.includeChildren
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
return DecorationSet.create(doc, decorations)
|
|
123
|
-
},
|
|
124
|
-
},
|
|
125
|
-
}),
|
|
126
|
-
]
|
|
127
|
-
},
|
|
128
|
-
})
|