@tiptap/extensions 3.30.2 → 3.30.3
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/character-count/index.cjs +84 -128
- package/dist/character-count/index.cjs.map +1 -1
- package/dist/character-count/index.d.cts +59 -58
- package/dist/character-count/index.d.cts.map +1 -0
- package/dist/character-count/index.d.ts +59 -58
- package/dist/character-count/index.d.ts.map +1 -0
- package/dist/character-count/index.js +82 -100
- package/dist/character-count/index.js.map +1 -1
- package/dist/drop-cursor/index.cjs +24 -44
- package/dist/drop-cursor/index.cjs.map +1 -1
- package/dist/drop-cursor/index.d.cts +23 -22
- package/dist/drop-cursor/index.d.cts.map +1 -0
- package/dist/drop-cursor/index.d.ts +23 -22
- package/dist/drop-cursor/index.d.ts.map +1 -0
- package/dist/drop-cursor/index.js +22 -16
- package/dist/drop-cursor/index.js.map +1 -1
- package/dist/focus/index.cjs +45 -92
- package/dist/focus/index.cjs.map +1 -1
- package/dist/focus/index.d.cts +22 -21
- package/dist/focus/index.d.cts.map +1 -0
- package/dist/focus/index.d.ts +22 -21
- package/dist/focus/index.d.ts.map +1 -0
- package/dist/focus/index.js +42 -63
- package/dist/focus/index.js.map +1 -1
- package/dist/gap-cursor/index.cjs +25 -48
- package/dist/gap-cursor/index.cjs.map +1 -1
- package/dist/gap-cursor/index.d.cts +16 -15
- package/dist/gap-cursor/index.d.cts.map +1 -0
- package/dist/gap-cursor/index.d.ts +16 -15
- package/dist/gap-cursor/index.d.ts.map +1 -0
- package/dist/gap-cursor/index.js +24 -21
- package/dist/gap-cursor/index.js.map +1 -1
- package/dist/index.cjs +666 -742
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +231 -220
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.ts +231 -220
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +653 -703
- package/dist/index.js.map +1 -1
- package/dist/placeholder/index.cjs +344 -376
- package/dist/placeholder/index.cjs.map +1 -1
- package/dist/placeholder/index.d.cts +73 -69
- package/dist/placeholder/index.d.cts.map +1 -0
- package/dist/placeholder/index.d.ts +73 -69
- package/dist/placeholder/index.d.ts.map +1 -0
- package/dist/placeholder/index.js +340 -346
- package/dist/placeholder/index.js.map +1 -1
- package/dist/selection/index.cjs +62 -86
- package/dist/selection/index.cjs.map +1 -1
- package/dist/selection/index.d.cts +11 -10
- package/dist/selection/index.d.cts.map +1 -0
- package/dist/selection/index.d.ts +11 -10
- package/dist/selection/index.d.ts.map +1 -0
- package/dist/selection/index.js +58 -56
- package/dist/selection/index.js.map +1 -1
- package/dist/trailing-node/index.cjs +59 -89
- package/dist/trailing-node/index.cjs.map +1 -1
- package/dist/trailing-node/index.d.cts +17 -16
- package/dist/trailing-node/index.d.cts.map +1 -0
- package/dist/trailing-node/index.d.ts +17 -16
- package/dist/trailing-node/index.d.ts.map +1 -0
- package/dist/trailing-node/index.js +55 -59
- package/dist/trailing-node/index.js.map +1 -1
- package/dist/undo-redo/index.cjs +45 -63
- package/dist/undo-redo/index.cjs.map +1 -1
- package/dist/undo-redo/index.d.cts +31 -30
- package/dist/undo-redo/index.d.cts.map +1 -0
- package/dist/undo-redo/index.d.ts +31 -30
- package/dist/undo-redo/index.d.ts.map +1 -0
- package/dist/undo-redo/index.js +43 -35
- package/dist/undo-redo/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -1,786 +1,710 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
const initialContentSize = this.storage.characters({ node: newState.doc });
|
|
90
|
-
if (initialContentSize > limit) {
|
|
91
|
-
const over = initialContentSize - limit;
|
|
92
|
-
const from = 0;
|
|
93
|
-
const to = over;
|
|
94
|
-
console.warn(
|
|
95
|
-
`[CharacterCount] Initial content exceeded limit of ${limit} characters. Content was automatically trimmed.`
|
|
96
|
-
);
|
|
97
|
-
const tr = newState.tr.deleteRange(from, to);
|
|
98
|
-
initialEvaluationDone = true;
|
|
99
|
-
return tr;
|
|
100
|
-
}
|
|
101
|
-
initialEvaluationDone = true;
|
|
102
|
-
},
|
|
103
|
-
filterTransaction: (transaction, state) => {
|
|
104
|
-
const limit = this.options.limit;
|
|
105
|
-
if (!transaction.docChanged || limit === 0 || limit === null || limit === void 0) {
|
|
106
|
-
return true;
|
|
107
|
-
}
|
|
108
|
-
const oldSize = this.storage.characters({ node: state.doc });
|
|
109
|
-
const newSize = this.storage.characters({ node: transaction.doc });
|
|
110
|
-
if (newSize <= limit) {
|
|
111
|
-
return true;
|
|
112
|
-
}
|
|
113
|
-
if (oldSize > limit && newSize > limit && newSize <= oldSize) {
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
if (oldSize > limit && newSize > limit && newSize > oldSize) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
const isPaste = transaction.getMeta("paste");
|
|
120
|
-
if (!isPaste) {
|
|
121
|
-
return false;
|
|
122
|
-
}
|
|
123
|
-
const pos = transaction.selection.$head.pos;
|
|
124
|
-
const over = newSize - limit;
|
|
125
|
-
const from = pos - over;
|
|
126
|
-
const to = pos;
|
|
127
|
-
transaction.deleteRange(from, to);
|
|
128
|
-
const updatedSize = this.storage.characters({ node: transaction.doc });
|
|
129
|
-
if (updatedSize > limit) {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
return true;
|
|
133
|
-
}
|
|
134
|
-
})
|
|
135
|
-
];
|
|
136
|
-
}
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _tiptap_core = require("@tiptap/core");
|
|
3
|
+
let _tiptap_pm_state = require("@tiptap/pm/state");
|
|
4
|
+
let _tiptap_pm_dropcursor = require("@tiptap/pm/dropcursor");
|
|
5
|
+
let _tiptap_pm_view = require("@tiptap/pm/view");
|
|
6
|
+
let _tiptap_pm_gapcursor = require("@tiptap/pm/gapcursor");
|
|
7
|
+
let _tiptap_pm_history = require("@tiptap/pm/history");
|
|
8
|
+
//#region src/character-count/character-count.ts
|
|
9
|
+
/**
|
|
10
|
+
* This extension allows you to count the characters and words of your document.
|
|
11
|
+
* @see https://tiptap.dev/api/extensions/character-count
|
|
12
|
+
*/
|
|
13
|
+
const CharacterCount = _tiptap_core.Extension.create({
|
|
14
|
+
name: "characterCount",
|
|
15
|
+
addOptions() {
|
|
16
|
+
return {
|
|
17
|
+
limit: null,
|
|
18
|
+
autoTrim: true,
|
|
19
|
+
mode: "textSize",
|
|
20
|
+
textCounter: (text) => text.length,
|
|
21
|
+
wordCounter: (text) => text.split(" ").filter((word) => word !== "").length
|
|
22
|
+
};
|
|
23
|
+
},
|
|
24
|
+
addStorage() {
|
|
25
|
+
return {
|
|
26
|
+
characters: () => 0,
|
|
27
|
+
words: () => 0
|
|
28
|
+
};
|
|
29
|
+
},
|
|
30
|
+
onBeforeCreate() {
|
|
31
|
+
this.storage.characters = (options) => {
|
|
32
|
+
const node = (options === null || options === void 0 ? void 0 : options.node) || this.editor.state.doc;
|
|
33
|
+
if (((options === null || options === void 0 ? void 0 : options.mode) || this.options.mode) === "textSize") {
|
|
34
|
+
const text = node.textBetween(0, node.content.size, void 0, " ");
|
|
35
|
+
return this.options.textCounter(text);
|
|
36
|
+
}
|
|
37
|
+
return node.nodeSize;
|
|
38
|
+
};
|
|
39
|
+
this.storage.words = (options) => {
|
|
40
|
+
const node = (options === null || options === void 0 ? void 0 : options.node) || this.editor.state.doc;
|
|
41
|
+
const text = node.textBetween(0, node.content.size, " ", " ");
|
|
42
|
+
return this.options.wordCounter(text);
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
addProseMirrorPlugins() {
|
|
46
|
+
let initialEvaluationDone = false;
|
|
47
|
+
return [new _tiptap_pm_state.Plugin({
|
|
48
|
+
key: new _tiptap_pm_state.PluginKey("characterCount"),
|
|
49
|
+
appendTransaction: (transactions, oldState, newState) => {
|
|
50
|
+
if (initialEvaluationDone) return;
|
|
51
|
+
const limit = this.options.limit;
|
|
52
|
+
const autoTrim = this.options.autoTrim;
|
|
53
|
+
if (limit === null || limit === void 0 || limit === 0 || autoTrim === false) {
|
|
54
|
+
initialEvaluationDone = true;
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
const initialContentSize = this.storage.characters({ node: newState.doc });
|
|
58
|
+
if (initialContentSize > limit) {
|
|
59
|
+
const over = initialContentSize - limit;
|
|
60
|
+
const from = 0;
|
|
61
|
+
const to = over;
|
|
62
|
+
console.warn(`[CharacterCount] Initial content exceeded limit of ${limit} characters. Content was automatically trimmed.`);
|
|
63
|
+
const tr = newState.tr.deleteRange(from, to);
|
|
64
|
+
initialEvaluationDone = true;
|
|
65
|
+
return tr;
|
|
66
|
+
}
|
|
67
|
+
initialEvaluationDone = true;
|
|
68
|
+
},
|
|
69
|
+
filterTransaction: (transaction, state) => {
|
|
70
|
+
const limit = this.options.limit;
|
|
71
|
+
if (!transaction.docChanged || limit === 0 || limit === null || limit === void 0) return true;
|
|
72
|
+
const oldSize = this.storage.characters({ node: state.doc });
|
|
73
|
+
const newSize = this.storage.characters({ node: transaction.doc });
|
|
74
|
+
if (newSize <= limit) return true;
|
|
75
|
+
if (oldSize > limit && newSize > limit && newSize <= oldSize) return true;
|
|
76
|
+
if (oldSize > limit && newSize > limit && newSize > oldSize) return false;
|
|
77
|
+
if (!transaction.getMeta("paste")) return false;
|
|
78
|
+
const pos = transaction.selection.$head.pos;
|
|
79
|
+
const from = pos - (newSize - limit);
|
|
80
|
+
const to = pos;
|
|
81
|
+
transaction.deleteRange(from, to);
|
|
82
|
+
if (this.storage.characters({ node: transaction.doc }) > limit) return false;
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
})];
|
|
86
|
+
}
|
|
137
87
|
});
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
88
|
+
//#endregion
|
|
89
|
+
//#region src/drop-cursor/drop-cursor.ts
|
|
90
|
+
/**
|
|
91
|
+
* This extension allows you to add a drop cursor to your editor.
|
|
92
|
+
* A drop cursor is a line that appears when you drag and drop content
|
|
93
|
+
* in-between nodes.
|
|
94
|
+
* @see https://tiptap.dev/api/extensions/dropcursor
|
|
95
|
+
*/
|
|
96
|
+
const Dropcursor = _tiptap_core.Extension.create({
|
|
97
|
+
name: "dropCursor",
|
|
98
|
+
addOptions() {
|
|
99
|
+
return {
|
|
100
|
+
color: "currentColor",
|
|
101
|
+
width: 1,
|
|
102
|
+
class: void 0
|
|
103
|
+
};
|
|
104
|
+
},
|
|
105
|
+
addProseMirrorPlugins() {
|
|
106
|
+
return [(0, _tiptap_pm_dropcursor.dropCursor)(this.options)];
|
|
107
|
+
}
|
|
154
108
|
});
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
if (node.isText) {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
const isCurrent = anchor >= pos && anchor <= pos + node.nodeSize - 1;
|
|
199
|
-
if (!isCurrent) {
|
|
200
|
-
return false;
|
|
201
|
-
}
|
|
202
|
-
currentLevel += 1;
|
|
203
|
-
const outOfScope = this.options.mode === "deepest" && maxLevels - currentLevel > 0 || this.options.mode === "shallowest" && currentLevel > 1;
|
|
204
|
-
if (outOfScope) {
|
|
205
|
-
return this.options.mode === "deepest";
|
|
206
|
-
}
|
|
207
|
-
decorations.push(
|
|
208
|
-
import_view.Decoration.node(pos, pos + node.nodeSize, {
|
|
209
|
-
class: this.options.className
|
|
210
|
-
})
|
|
211
|
-
);
|
|
212
|
-
});
|
|
213
|
-
return import_view.DecorationSet.create(doc, decorations);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
})
|
|
217
|
-
];
|
|
218
|
-
}
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/focus/focus.ts
|
|
111
|
+
/**
|
|
112
|
+
* This extension allows you to add a class to the focused node.
|
|
113
|
+
* @see https://www.tiptap.dev/api/extensions/focus
|
|
114
|
+
*/
|
|
115
|
+
const Focus = _tiptap_core.Extension.create({
|
|
116
|
+
name: "focus",
|
|
117
|
+
addOptions() {
|
|
118
|
+
return {
|
|
119
|
+
className: "has-focus",
|
|
120
|
+
mode: "all"
|
|
121
|
+
};
|
|
122
|
+
},
|
|
123
|
+
addProseMirrorPlugins() {
|
|
124
|
+
return [new _tiptap_pm_state.Plugin({
|
|
125
|
+
key: new _tiptap_pm_state.PluginKey("focus"),
|
|
126
|
+
props: { decorations: ({ doc, selection }) => {
|
|
127
|
+
const { isEditable, isFocused } = this.editor;
|
|
128
|
+
const { anchor } = selection;
|
|
129
|
+
const decorations = [];
|
|
130
|
+
if (!isEditable || !isFocused) return _tiptap_pm_view.DecorationSet.create(doc, []);
|
|
131
|
+
let maxLevels = 0;
|
|
132
|
+
if (this.options.mode === "deepest") doc.descendants((node, pos) => {
|
|
133
|
+
if (node.isText) return;
|
|
134
|
+
if (!(anchor >= pos && anchor <= pos + node.nodeSize - 1)) return false;
|
|
135
|
+
maxLevels += 1;
|
|
136
|
+
});
|
|
137
|
+
let currentLevel = 0;
|
|
138
|
+
doc.descendants((node, pos) => {
|
|
139
|
+
if (node.isText) return false;
|
|
140
|
+
if (!(anchor >= pos && anchor <= pos + node.nodeSize - 1)) return false;
|
|
141
|
+
currentLevel += 1;
|
|
142
|
+
if (this.options.mode === "deepest" && maxLevels - currentLevel > 0 || this.options.mode === "shallowest" && currentLevel > 1) return this.options.mode === "deepest";
|
|
143
|
+
decorations.push(_tiptap_pm_view.Decoration.node(pos, pos + node.nodeSize, { class: this.options.className }));
|
|
144
|
+
});
|
|
145
|
+
return _tiptap_pm_view.DecorationSet.create(doc, decorations);
|
|
146
|
+
} }
|
|
147
|
+
})];
|
|
148
|
+
}
|
|
219
149
|
});
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/gap-cursor/gap-cursor.ts
|
|
152
|
+
/**
|
|
153
|
+
* This extension allows you to add a gap cursor to your editor.
|
|
154
|
+
* A gap cursor is a cursor that appears when you click on a place
|
|
155
|
+
* where no content is present, for example inbetween nodes.
|
|
156
|
+
* @see https://tiptap.dev/api/extensions/gapcursor
|
|
157
|
+
*/
|
|
158
|
+
const Gapcursor = _tiptap_core.Extension.create({
|
|
159
|
+
name: "gapCursor",
|
|
160
|
+
addProseMirrorPlugins() {
|
|
161
|
+
return [(0, _tiptap_pm_gapcursor.gapCursor)()];
|
|
162
|
+
},
|
|
163
|
+
extendNodeSchema(extension) {
|
|
164
|
+
var _callOrReturn;
|
|
165
|
+
return { allowGapCursor: (_callOrReturn = (0, _tiptap_core.callOrReturn)((0, _tiptap_core.getExtensionField)(extension, "allowGapCursor", {
|
|
166
|
+
name: extension.name,
|
|
167
|
+
options: extension.options,
|
|
168
|
+
storage: extension.storage
|
|
169
|
+
}))) !== null && _callOrReturn !== void 0 ? _callOrReturn : null };
|
|
170
|
+
}
|
|
240
171
|
});
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/placeholder/constants.ts
|
|
174
|
+
/** The default data attribute label */
|
|
175
|
+
const DEFAULT_DATA_ATTRIBUTE = "placeholder";
|
|
176
|
+
/** The plugin key used to store and read the placeholder decoration set */
|
|
177
|
+
const PLUGIN_KEY = new _tiptap_pm_state.PluginKey("tiptap__placeholder");
|
|
178
|
+
//#endregion
|
|
179
|
+
//#region src/placeholder/utils/createPlaceholderDecoration.ts
|
|
180
|
+
/**
|
|
181
|
+
* Creates a ProseMirror node decoration that applies a placeholder
|
|
182
|
+
* CSS class and data attribute to an empty node.
|
|
183
|
+
* @param options.editor - The editor instance
|
|
184
|
+
* @param options.pos - The position of the node in the document
|
|
185
|
+
* @param options.node - The ProseMirror node
|
|
186
|
+
* @param options.isEmptyDoc - Whether the entire document is empty
|
|
187
|
+
* @param options.hasAnchor - Whether the selection anchor is within the node
|
|
188
|
+
* @param options.dataAttribute - The data attribute name (e.g. `data-placeholder`)
|
|
189
|
+
* @param options.classes - CSS classes for empty nodes and the empty editor
|
|
190
|
+
* @param options.placeholder - The placeholder text or a function that returns it
|
|
191
|
+
* @returns A ProseMirror node decoration with placeholder classes and data attribute
|
|
192
|
+
*/
|
|
260
193
|
function createPlaceholderDecoration(options) {
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
classes.push(emptyEditor);
|
|
274
|
-
}
|
|
275
|
-
return import_view2.Decoration.node(pos, pos + node.nodeSize, {
|
|
276
|
-
class: classes.join(" "),
|
|
277
|
-
[dataAttribute]: typeof placeholder === "function" ? placeholder({
|
|
278
|
-
editor,
|
|
279
|
-
node,
|
|
280
|
-
pos,
|
|
281
|
-
hasAnchor
|
|
282
|
-
}) : placeholder
|
|
283
|
-
});
|
|
194
|
+
const { editor, placeholder, dataAttribute, pos, node, isEmptyDoc, hasAnchor, classes: { emptyNode, emptyEditor } } = options;
|
|
195
|
+
const classes = [emptyNode];
|
|
196
|
+
if (isEmptyDoc) classes.push(emptyEditor);
|
|
197
|
+
return _tiptap_pm_view.Decoration.node(pos, pos + node.nodeSize, {
|
|
198
|
+
class: classes.join(" "),
|
|
199
|
+
[dataAttribute]: typeof placeholder === "function" ? placeholder({
|
|
200
|
+
editor,
|
|
201
|
+
node,
|
|
202
|
+
pos,
|
|
203
|
+
hasAnchor
|
|
204
|
+
}) : placeholder
|
|
205
|
+
});
|
|
284
206
|
}
|
|
285
|
-
|
|
286
|
-
|
|
207
|
+
//#endregion
|
|
208
|
+
//#region src/placeholder/utils/buildPlaceholderDecorations.ts
|
|
287
209
|
function resolveEmptyNodeClass(emptyNodeClass, props) {
|
|
288
|
-
|
|
210
|
+
return typeof emptyNodeClass === "function" ? emptyNodeClass(props) : emptyNodeClass;
|
|
289
211
|
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
})
|
|
324
|
-
},
|
|
325
|
-
node,
|
|
326
|
-
pos
|
|
327
|
-
})
|
|
328
|
-
);
|
|
329
|
-
}
|
|
330
|
-
return options.includeChildren;
|
|
331
|
-
});
|
|
332
|
-
return decorations;
|
|
212
|
+
/**
|
|
213
|
+
* Scans a document range for empty textblocks that should receive placeholder
|
|
214
|
+
* decorations. Used by the slow path and incremental state updates.
|
|
215
|
+
*/
|
|
216
|
+
function scanRangeForDecorations({ editor, options, dataAttribute, doc, selection, from, to }) {
|
|
217
|
+
const { anchor } = selection;
|
|
218
|
+
const decorations = [];
|
|
219
|
+
const isEmptyDoc = editor.isEmpty;
|
|
220
|
+
doc.nodesBetween(from, to, (node, pos) => {
|
|
221
|
+
const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
|
|
222
|
+
const isEmpty = !node.isLeaf && (0, _tiptap_core.isNodeEmpty)(node);
|
|
223
|
+
if (!node.type.isTextblock) return options.includeChildren;
|
|
224
|
+
if ((hasAnchor || !options.showOnlyCurrent) && isEmpty) decorations.push(createPlaceholderDecoration({
|
|
225
|
+
editor,
|
|
226
|
+
isEmptyDoc,
|
|
227
|
+
dataAttribute,
|
|
228
|
+
hasAnchor,
|
|
229
|
+
placeholder: options.placeholder,
|
|
230
|
+
classes: {
|
|
231
|
+
emptyEditor: options.emptyEditorClass,
|
|
232
|
+
emptyNode: resolveEmptyNodeClass(options.emptyNodeClass, {
|
|
233
|
+
editor,
|
|
234
|
+
node,
|
|
235
|
+
pos,
|
|
236
|
+
hasAnchor
|
|
237
|
+
})
|
|
238
|
+
},
|
|
239
|
+
node,
|
|
240
|
+
pos
|
|
241
|
+
}));
|
|
242
|
+
return options.includeChildren;
|
|
243
|
+
});
|
|
244
|
+
return decorations;
|
|
333
245
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
selection,
|
|
384
|
-
from: 0,
|
|
385
|
-
to: doc.content.size
|
|
386
|
-
})
|
|
387
|
-
);
|
|
388
|
-
}
|
|
389
|
-
return import_view3.DecorationSet.create(doc, decorations);
|
|
246
|
+
/**
|
|
247
|
+
* Builds the placeholder decorations for the current document state.
|
|
248
|
+
* @param options.editor - The editor instance.
|
|
249
|
+
* @param options.options - The resolved placeholder options.
|
|
250
|
+
* @param options.dataAttribute - The prepared `data-*` attribute name.
|
|
251
|
+
* @param options.doc - The current document node.
|
|
252
|
+
* @param options.selection - The current selection.
|
|
253
|
+
* @returns A decoration set, or `null` when no placeholders should be shown.
|
|
254
|
+
*/
|
|
255
|
+
function buildPlaceholderDecorations({ editor, options, dataAttribute, doc, selection }) {
|
|
256
|
+
if (!(editor.isEditable || !options.showOnlyWhenEditable)) return null;
|
|
257
|
+
const { anchor } = selection;
|
|
258
|
+
const decorations = [];
|
|
259
|
+
const isEmptyDoc = editor.isEmpty;
|
|
260
|
+
if (options.showOnlyCurrent && !options.includeChildren) {
|
|
261
|
+
const resolved = doc.resolve(anchor);
|
|
262
|
+
const node = resolved.depth > 0 ? resolved.node(1) : resolved.nodeAfter;
|
|
263
|
+
const nodeStart = resolved.depth > 0 ? resolved.before(1) : anchor;
|
|
264
|
+
if (node && node.type.isTextblock && (0, _tiptap_core.isNodeEmpty)(node)) {
|
|
265
|
+
const hasAnchor = anchor >= nodeStart && anchor <= nodeStart + node.nodeSize;
|
|
266
|
+
decorations.push(createPlaceholderDecoration({
|
|
267
|
+
editor,
|
|
268
|
+
isEmptyDoc,
|
|
269
|
+
dataAttribute,
|
|
270
|
+
hasAnchor,
|
|
271
|
+
placeholder: options.placeholder,
|
|
272
|
+
classes: {
|
|
273
|
+
emptyEditor: options.emptyEditorClass,
|
|
274
|
+
emptyNode: resolveEmptyNodeClass(options.emptyNodeClass, {
|
|
275
|
+
editor,
|
|
276
|
+
node,
|
|
277
|
+
pos: nodeStart,
|
|
278
|
+
hasAnchor
|
|
279
|
+
})
|
|
280
|
+
},
|
|
281
|
+
node,
|
|
282
|
+
pos: nodeStart
|
|
283
|
+
}));
|
|
284
|
+
}
|
|
285
|
+
} else decorations.push(...scanRangeForDecorations({
|
|
286
|
+
editor,
|
|
287
|
+
options,
|
|
288
|
+
dataAttribute,
|
|
289
|
+
doc,
|
|
290
|
+
selection,
|
|
291
|
+
from: 0,
|
|
292
|
+
to: doc.content.size
|
|
293
|
+
}));
|
|
294
|
+
return _tiptap_pm_view.DecorationSet.create(doc, decorations);
|
|
390
295
|
}
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
296
|
+
//#endregion
|
|
297
|
+
//#region src/placeholder/utils/resolveTopLevelRange.ts
|
|
298
|
+
/**
|
|
299
|
+
* Resolves a document position to the `[from, to)` range of its containing
|
|
300
|
+
* top-level block node in absolute document positions.
|
|
301
|
+
*/
|
|
397
302
|
function resolveTopLevelRange(doc, pos) {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
303
|
+
const resolved = doc.resolve(pos);
|
|
304
|
+
if (resolved.depth === 0) {
|
|
305
|
+
var _resolved$nodeAfter;
|
|
306
|
+
const node = (_resolved$nodeAfter = resolved.nodeAfter) !== null && _resolved$nodeAfter !== void 0 ? _resolved$nodeAfter : resolved.nodeBefore;
|
|
307
|
+
if (!node) return {
|
|
308
|
+
from: pos,
|
|
309
|
+
to: pos
|
|
310
|
+
};
|
|
311
|
+
const nodePos = resolved.nodeAfter ? pos : pos - node.nodeSize;
|
|
312
|
+
return {
|
|
313
|
+
from: nodePos,
|
|
314
|
+
to: nodePos + node.nodeSize
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
const topLevelPos = resolved.before(1);
|
|
318
|
+
return {
|
|
319
|
+
from: topLevelPos,
|
|
320
|
+
to: topLevelPos + resolved.node(1).nodeSize
|
|
321
|
+
};
|
|
411
322
|
}
|
|
323
|
+
/**
|
|
324
|
+
* Converts an absolute document range to content-relative positions used by
|
|
325
|
+
* `Node#nodesBetween` and `Node#forEach` offsets.
|
|
326
|
+
*/
|
|
412
327
|
function toContentRelativeRange(doc, range) {
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
328
|
+
return {
|
|
329
|
+
from: Math.max(0, range.from - 1),
|
|
330
|
+
to: Math.min(doc.content.size, range.to - 1)
|
|
331
|
+
};
|
|
417
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* Returns the top-level block ranges that intersect a document change range.
|
|
335
|
+
* Input `from`/`to` are absolute positions (e.g. from `getChangedRanges`).
|
|
336
|
+
* Returned ranges are content-relative, matching `Node#forEach` offsets.
|
|
337
|
+
*/
|
|
418
338
|
function getTopLevelBlocksInRange(doc, from, to) {
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
339
|
+
const ranges = [];
|
|
340
|
+
doc.forEach((node, offset) => {
|
|
341
|
+
const nodeStart = offset;
|
|
342
|
+
const nodeEnd = nodeStart + node.nodeSize;
|
|
343
|
+
const absNodeStart = nodeStart + 1;
|
|
344
|
+
const absNodeEnd = nodeEnd + 1;
|
|
345
|
+
if (absNodeStart < to && absNodeEnd > from) ranges.push({
|
|
346
|
+
from: nodeStart,
|
|
347
|
+
to: nodeEnd
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
return ranges;
|
|
430
351
|
}
|
|
352
|
+
/**
|
|
353
|
+
* Sorts ranges by start position and merges overlapping or adjacent ranges.
|
|
354
|
+
*/
|
|
431
355
|
function mergeRanges(ranges) {
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
} else {
|
|
443
|
-
merged.push({ ...current });
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
return merged;
|
|
356
|
+
if (ranges.length === 0) return [];
|
|
357
|
+
const sorted = [...ranges].sort((a, b) => a.from - b.from);
|
|
358
|
+
const merged = [{ ...sorted[0] }];
|
|
359
|
+
for (let i = 1; i < sorted.length; i += 1) {
|
|
360
|
+
const last = merged[merged.length - 1];
|
|
361
|
+
const current = sorted[i];
|
|
362
|
+
if (current.from <= last.to) last.to = Math.max(last.to, current.to);
|
|
363
|
+
else merged.push({ ...current });
|
|
364
|
+
}
|
|
365
|
+
return merged;
|
|
447
366
|
}
|
|
448
|
-
|
|
449
|
-
|
|
367
|
+
//#endregion
|
|
368
|
+
//#region src/placeholder/utils/placeholderStateField.ts
|
|
369
|
+
/**
|
|
370
|
+
* Expands a single changed range to the top-level blocks it touches.
|
|
371
|
+
* Also resolves blocks at range boundaries so split/merge edits update
|
|
372
|
+
* adjacent empty nodes (e.g. a new paragraph after Enter).
|
|
373
|
+
*/
|
|
450
374
|
function collectBlocksForChange(doc, change) {
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
doc,
|
|
457
|
-
resolveTopLevelRange(doc, Math.min(change.to, doc.content.size + 1) - 1)
|
|
458
|
-
)
|
|
459
|
-
);
|
|
460
|
-
} else if (change.from < doc.content.size + 1) {
|
|
461
|
-
ranges.push(
|
|
462
|
-
toContentRelativeRange(
|
|
463
|
-
doc,
|
|
464
|
-
resolveTopLevelRange(doc, Math.min(change.from + 1, doc.content.size))
|
|
465
|
-
)
|
|
466
|
-
);
|
|
467
|
-
}
|
|
468
|
-
return ranges;
|
|
375
|
+
const ranges = getTopLevelBlocksInRange(doc, change.from, change.to);
|
|
376
|
+
ranges.push(toContentRelativeRange(doc, resolveTopLevelRange(doc, change.from)));
|
|
377
|
+
if (change.to > change.from) ranges.push(toContentRelativeRange(doc, resolveTopLevelRange(doc, Math.min(change.to, doc.content.size + 1) - 1)));
|
|
378
|
+
else if (change.from < doc.content.size + 1) ranges.push(toContentRelativeRange(doc, resolveTopLevelRange(doc, Math.min(change.from + 1, doc.content.size))));
|
|
379
|
+
return ranges;
|
|
469
380
|
}
|
|
381
|
+
/**
|
|
382
|
+
* Collects content-relative top-level block ranges that need placeholder
|
|
383
|
+
* decorations recomputed after a transaction.
|
|
384
|
+
*/
|
|
470
385
|
function collectRescanRanges(tr, oldState, newState) {
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
newState.doc,
|
|
482
|
-
resolveTopLevelRange(newState.doc, tr.mapping.map(oldState.selection.anchor))
|
|
483
|
-
)
|
|
484
|
-
);
|
|
485
|
-
ranges.push(
|
|
486
|
-
toContentRelativeRange(
|
|
487
|
-
newState.doc,
|
|
488
|
-
resolveTopLevelRange(newState.doc, newState.selection.anchor)
|
|
489
|
-
)
|
|
490
|
-
);
|
|
491
|
-
}
|
|
492
|
-
return mergeRanges(ranges);
|
|
386
|
+
const ranges = [];
|
|
387
|
+
if (tr.docChanged) {
|
|
388
|
+
const changes = (0, _tiptap_core.getChangedRanges)(tr);
|
|
389
|
+
for (const change of changes) ranges.push(...collectBlocksForChange(newState.doc, change.newRange));
|
|
390
|
+
}
|
|
391
|
+
if (tr.selectionSet) {
|
|
392
|
+
ranges.push(toContentRelativeRange(newState.doc, resolveTopLevelRange(newState.doc, tr.mapping.map(oldState.selection.anchor))));
|
|
393
|
+
ranges.push(toContentRelativeRange(newState.doc, resolveTopLevelRange(newState.doc, newState.selection.anchor)));
|
|
394
|
+
}
|
|
395
|
+
return mergeRanges(ranges);
|
|
493
396
|
}
|
|
397
|
+
/** Clamps a content-relative range to `[0, doc.content.size]`. */
|
|
494
398
|
function clampRange(from, to, doc) {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
399
|
+
const clampedFrom = Math.max(0, Math.min(from, doc.content.size));
|
|
400
|
+
return {
|
|
401
|
+
from: clampedFrom,
|
|
402
|
+
to: Math.max(clampedFrom, Math.min(to, doc.content.size))
|
|
403
|
+
};
|
|
498
404
|
}
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
})
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
to
|
|
523
|
-
});
|
|
524
|
-
if (newDecos.length) {
|
|
525
|
-
next = next.add(doc, newDecos);
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
return next;
|
|
405
|
+
/**
|
|
406
|
+
* Removes and rebuilds placeholder decorations within the given ranges.
|
|
407
|
+
* Only drops decorations fully contained in a range so mapped decorations
|
|
408
|
+
* on neighbouring blocks (e.g. at a block boundary) are kept intact.
|
|
409
|
+
*/
|
|
410
|
+
function updateDecorationsInRanges({ decorations, ranges, editor, options, dataAttribute, doc, selection }) {
|
|
411
|
+
let next = decorations;
|
|
412
|
+
for (const range of ranges) {
|
|
413
|
+
const { from, to } = clampRange(range.from, range.to, doc);
|
|
414
|
+
const existing = next.find(from, to).filter((decoration) => decoration.from >= from && decoration.to <= to);
|
|
415
|
+
if (existing.length) next = next.remove(existing);
|
|
416
|
+
const newDecos = scanRangeForDecorations({
|
|
417
|
+
editor,
|
|
418
|
+
options,
|
|
419
|
+
dataAttribute,
|
|
420
|
+
doc,
|
|
421
|
+
selection,
|
|
422
|
+
from,
|
|
423
|
+
to
|
|
424
|
+
});
|
|
425
|
+
if (newDecos.length) next = next.add(doc, newDecos);
|
|
426
|
+
}
|
|
427
|
+
return next;
|
|
529
428
|
}
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
429
|
+
/**
|
|
430
|
+
* Creates the incremental `StateField<DecorationSet>` used by the slow path
|
|
431
|
+
* (`showOnlyCurrent: false` or `includeChildren: true`).
|
|
432
|
+
*
|
|
433
|
+
* Decorations are mapped through each transaction and only recomputed for
|
|
434
|
+
* top-level blocks touched by document or selection changes.
|
|
435
|
+
* @param options.editor - The editor instance.
|
|
436
|
+
* @param options.options - The resolved placeholder options.
|
|
437
|
+
* @param options.dataAttribute - The prepared `data-*` attribute name.
|
|
438
|
+
* @returns A ProseMirror state field storing the placeholder decoration set.
|
|
439
|
+
*/
|
|
440
|
+
function createPlaceholderStateField({ editor, options, dataAttribute }) {
|
|
441
|
+
return {
|
|
442
|
+
init(_config, state) {
|
|
443
|
+
const decorations = buildPlaceholderDecorations({
|
|
444
|
+
editor,
|
|
445
|
+
options,
|
|
446
|
+
dataAttribute,
|
|
447
|
+
doc: state.doc,
|
|
448
|
+
selection: state.selection
|
|
449
|
+
});
|
|
450
|
+
return decorations !== null && decorations !== void 0 ? decorations : _tiptap_pm_view.DecorationSet.empty;
|
|
451
|
+
},
|
|
452
|
+
apply(tr, prev, oldState, newState) {
|
|
453
|
+
if (!tr.docChanged && !tr.selectionSet) return prev;
|
|
454
|
+
return updateDecorationsInRanges({
|
|
455
|
+
decorations: prev.map(tr.mapping, tr.doc),
|
|
456
|
+
ranges: collectRescanRanges(tr, oldState, newState),
|
|
457
|
+
editor,
|
|
458
|
+
options,
|
|
459
|
+
dataAttribute,
|
|
460
|
+
doc: newState.doc,
|
|
461
|
+
selection: newState.selection
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
};
|
|
563
465
|
}
|
|
564
|
-
|
|
565
|
-
|
|
466
|
+
//#endregion
|
|
467
|
+
//#region src/placeholder/utils/preparePlaceholderAttribute.ts
|
|
468
|
+
/**
|
|
469
|
+
* Prepares the placeholder attribute by ensuring it is properly formatted.
|
|
470
|
+
* @param attr - The placeholder attribute string.
|
|
471
|
+
* @returns The prepared placeholder attribute string.
|
|
472
|
+
*/
|
|
566
473
|
function preparePlaceholderAttribute(attr) {
|
|
567
|
-
|
|
474
|
+
return attr.replace(/\s+/g, "-").replace(/[^a-zA-Z0-9-]/g, "").replace(/^[0-9-]+/, "").replace(/^-+/, "").toLowerCase();
|
|
568
475
|
}
|
|
569
|
-
|
|
570
|
-
|
|
476
|
+
//#endregion
|
|
477
|
+
//#region src/placeholder/plugins/PlaceholderPlugin.ts
|
|
478
|
+
/**
|
|
479
|
+
* Creates the ProseMirror plugin that renders placeholder decorations.
|
|
480
|
+
* @param options.editor - The editor instance.
|
|
481
|
+
* @param options.options - The resolved placeholder options.
|
|
482
|
+
* @returns The configured placeholder plugin.
|
|
483
|
+
*/
|
|
571
484
|
function createPlaceholderPlugin({ editor, options }) {
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
485
|
+
const dataAttribute = options.dataAttribute ? `data-${preparePlaceholderAttribute(options.dataAttribute)}` : `data-${DEFAULT_DATA_ATTRIBUTE}`;
|
|
486
|
+
const useResolvedPath = options.showOnlyCurrent && !options.includeChildren;
|
|
487
|
+
return new _tiptap_pm_state.Plugin({
|
|
488
|
+
key: PLUGIN_KEY,
|
|
489
|
+
...useResolvedPath ? {} : { state: createPlaceholderStateField({
|
|
490
|
+
editor,
|
|
491
|
+
options,
|
|
492
|
+
dataAttribute
|
|
493
|
+
}) },
|
|
494
|
+
props: { decorations: useResolvedPath ? ({ doc, selection }) => buildPlaceholderDecorations({
|
|
495
|
+
editor,
|
|
496
|
+
options,
|
|
497
|
+
dataAttribute,
|
|
498
|
+
doc,
|
|
499
|
+
selection
|
|
500
|
+
}) : (state) => {
|
|
501
|
+
var _PLUGIN_KEY$getState;
|
|
502
|
+
if (options.showOnlyWhenEditable && !editor.isEditable) return _tiptap_pm_view.DecorationSet.empty;
|
|
503
|
+
return (_PLUGIN_KEY$getState = PLUGIN_KEY.getState(state)) !== null && _PLUGIN_KEY$getState !== void 0 ? _PLUGIN_KEY$getState : _tiptap_pm_view.DecorationSet.empty;
|
|
504
|
+
} }
|
|
505
|
+
});
|
|
589
506
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region src/placeholder/placeholder.ts
|
|
509
|
+
/**
|
|
510
|
+
* This extension allows you to add a placeholder to your editor.
|
|
511
|
+
* A placeholder is a text that appears when the editor or a node is empty.
|
|
512
|
+
* @see https://www.tiptap.dev/api/extensions/placeholder
|
|
513
|
+
*/
|
|
514
|
+
const Placeholder = _tiptap_core.Extension.create({
|
|
515
|
+
name: "placeholder",
|
|
516
|
+
addOptions() {
|
|
517
|
+
return {
|
|
518
|
+
emptyEditorClass: "is-editor-empty",
|
|
519
|
+
emptyNodeClass: "is-empty",
|
|
520
|
+
dataAttribute: DEFAULT_DATA_ATTRIBUTE,
|
|
521
|
+
placeholder: "Write something …",
|
|
522
|
+
showOnlyWhenEditable: true,
|
|
523
|
+
showOnlyCurrent: true,
|
|
524
|
+
includeChildren: false
|
|
525
|
+
};
|
|
526
|
+
},
|
|
527
|
+
addProseMirrorPlugins() {
|
|
528
|
+
return [createPlaceholderPlugin({
|
|
529
|
+
editor: this.editor,
|
|
530
|
+
options: this.options
|
|
531
|
+
})];
|
|
532
|
+
}
|
|
608
533
|
});
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
534
|
+
//#endregion
|
|
535
|
+
//#region src/selection/selection.ts
|
|
536
|
+
/**
|
|
537
|
+
* Whether the native browser selection should be cleared on blur and restored on focus.
|
|
538
|
+
* Only applies to non-empty text selections in an editable editor.
|
|
539
|
+
*/
|
|
614
540
|
function shouldSyncDomSelection(state, editor) {
|
|
615
|
-
|
|
541
|
+
return !state.selection.empty && !(0, _tiptap_core.isNodeSelection)(state.selection) && editor.isEditable;
|
|
616
542
|
}
|
|
543
|
+
/**
|
|
544
|
+
* Whether the selection decoration should be rendered to keep the selection
|
|
545
|
+
* visible while the editor is blurred (and not dragging).
|
|
546
|
+
*/
|
|
617
547
|
function shouldPreserveSelection(state, editor) {
|
|
618
|
-
|
|
548
|
+
return shouldSyncDomSelection(state, editor) && !editor.isFocused && !editor.view.dragging;
|
|
619
549
|
}
|
|
620
550
|
function clearDomSelection() {
|
|
621
|
-
|
|
622
|
-
|
|
551
|
+
var _window$getSelection;
|
|
552
|
+
(_window$getSelection = window.getSelection()) === null || _window$getSelection === void 0 || _window$getSelection.removeAllRanges();
|
|
623
553
|
}
|
|
554
|
+
/**
|
|
555
|
+
* Sync the native selection from the editor state.
|
|
556
|
+
* @see https://prosemirror.net/docs/ref/#view.EditorView.focus
|
|
557
|
+
*/
|
|
624
558
|
function restoreDomSelection(view) {
|
|
625
|
-
|
|
559
|
+
view.focus();
|
|
626
560
|
}
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
restoreDomSelection(view);
|
|
665
|
-
}
|
|
666
|
-
});
|
|
667
|
-
return false;
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
})
|
|
672
|
-
];
|
|
673
|
-
}
|
|
561
|
+
/**
|
|
562
|
+
* This extension allows you to add a class to the selected text when the editor is blurred.
|
|
563
|
+
* It clears the native browser selection on blur (so `::selection` styles do not overlap the
|
|
564
|
+
* decoration) and restores it when the editor is focused again.
|
|
565
|
+
* @see https://www.tiptap.dev/api/extensions/selection
|
|
566
|
+
*/
|
|
567
|
+
const Selection = _tiptap_core.Extension.create({
|
|
568
|
+
name: "selection",
|
|
569
|
+
addOptions() {
|
|
570
|
+
return { className: "selection" };
|
|
571
|
+
},
|
|
572
|
+
addProseMirrorPlugins() {
|
|
573
|
+
const { editor, options } = this;
|
|
574
|
+
return [new _tiptap_pm_state.Plugin({
|
|
575
|
+
key: new _tiptap_pm_state.PluginKey("selection"),
|
|
576
|
+
props: {
|
|
577
|
+
decorations(state) {
|
|
578
|
+
if (!shouldPreserveSelection(state, editor)) return null;
|
|
579
|
+
return _tiptap_pm_view.DecorationSet.create(state.doc, [_tiptap_pm_view.Decoration.inline(state.selection.from, state.selection.to, { class: options.className })]);
|
|
580
|
+
},
|
|
581
|
+
handleDOMEvents: {
|
|
582
|
+
blur(view) {
|
|
583
|
+
if (!shouldSyncDomSelection(view.state, editor)) return false;
|
|
584
|
+
clearDomSelection();
|
|
585
|
+
return false;
|
|
586
|
+
},
|
|
587
|
+
focus(view) {
|
|
588
|
+
if (!shouldSyncDomSelection(view.state, editor)) return false;
|
|
589
|
+
requestAnimationFrame(() => {
|
|
590
|
+
if (!editor.isDestroyed && view.hasFocus()) restoreDomSelection(view);
|
|
591
|
+
});
|
|
592
|
+
return false;
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
})];
|
|
597
|
+
}
|
|
674
598
|
});
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
function nodeEqualsType({
|
|
681
|
-
types,
|
|
682
|
-
node
|
|
683
|
-
}) {
|
|
684
|
-
return node && Array.isArray(types) && types.includes(node.type) || (node == null ? void 0 : node.type) === types;
|
|
599
|
+
//#endregion
|
|
600
|
+
//#region src/trailing-node/trailing-node.ts
|
|
601
|
+
const skipTrailingNodeMeta = "skipTrailingNode";
|
|
602
|
+
function nodeEqualsType({ types, node }) {
|
|
603
|
+
return node && Array.isArray(types) && types.includes(node.type) || (node === null || node === void 0 ? void 0 : node.type) === types;
|
|
685
604
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
605
|
+
/**
|
|
606
|
+
* This extension allows you to add an extra node at the end of the document.
|
|
607
|
+
* @see https://www.tiptap.dev/api/extensions/trailing-node
|
|
608
|
+
*/
|
|
609
|
+
const TrailingNode = _tiptap_core.Extension.create({
|
|
610
|
+
name: "trailingNode",
|
|
611
|
+
addOptions() {
|
|
612
|
+
return {
|
|
613
|
+
node: void 0,
|
|
614
|
+
notAfter: []
|
|
615
|
+
};
|
|
616
|
+
},
|
|
617
|
+
addProseMirrorPlugins() {
|
|
618
|
+
var _this$editor$schema$t;
|
|
619
|
+
const plugin = new _tiptap_pm_state.PluginKey(this.name);
|
|
620
|
+
const defaultNode = this.options.node || ((_this$editor$schema$t = this.editor.schema.topNodeType.contentMatch.defaultType) === null || _this$editor$schema$t === void 0 ? void 0 : _this$editor$schema$t.name) || "paragraph";
|
|
621
|
+
const disabledNodes = Object.entries(this.editor.schema.nodes).map(([, value]) => value).filter((node) => (this.options.notAfter || []).concat(defaultNode).includes(node.name));
|
|
622
|
+
return [new _tiptap_pm_state.Plugin({
|
|
623
|
+
key: plugin,
|
|
624
|
+
appendTransaction: (transactions, __, state) => {
|
|
625
|
+
const { doc, tr, schema } = state;
|
|
626
|
+
const shouldInsertNodeAtEnd = plugin.getState(state);
|
|
627
|
+
const endPosition = doc.content.size;
|
|
628
|
+
const type = schema.nodes[defaultNode];
|
|
629
|
+
if (transactions.some((transaction) => transaction.getMeta("skipTrailingNode"))) return;
|
|
630
|
+
if (!shouldInsertNodeAtEnd) return;
|
|
631
|
+
return tr.insert(endPosition, type.create());
|
|
632
|
+
},
|
|
633
|
+
state: {
|
|
634
|
+
init: (_, state) => {
|
|
635
|
+
const lastNode = state.tr.doc.lastChild;
|
|
636
|
+
return !nodeEqualsType({
|
|
637
|
+
node: lastNode,
|
|
638
|
+
types: disabledNodes
|
|
639
|
+
});
|
|
640
|
+
},
|
|
641
|
+
apply: (tr, value) => {
|
|
642
|
+
if (!tr.docChanged) return value;
|
|
643
|
+
if (tr.getMeta("__uniqueIDTransaction")) return value;
|
|
644
|
+
const lastNode = tr.doc.lastChild;
|
|
645
|
+
return !nodeEqualsType({
|
|
646
|
+
node: lastNode,
|
|
647
|
+
types: disabledNodes
|
|
648
|
+
});
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
})];
|
|
652
|
+
}
|
|
734
653
|
});
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
Focus,
|
|
777
|
-
Gapcursor,
|
|
778
|
-
PLUGIN_KEY,
|
|
779
|
-
Placeholder,
|
|
780
|
-
Selection,
|
|
781
|
-
TrailingNode,
|
|
782
|
-
UndoRedo,
|
|
783
|
-
preparePlaceholderAttribute,
|
|
784
|
-
skipTrailingNodeMeta
|
|
654
|
+
//#endregion
|
|
655
|
+
//#region src/undo-redo/undo-redo.ts
|
|
656
|
+
/**
|
|
657
|
+
* This extension allows you to undo and redo recent changes.
|
|
658
|
+
* @see https://www.tiptap.dev/api/extensions/undo-redo
|
|
659
|
+
*
|
|
660
|
+
* **Important**: If the `@tiptap/extension-collaboration` package is used, make sure to remove
|
|
661
|
+
* the `undo-redo` extension, as it is not compatible with the `collaboration` extension.
|
|
662
|
+
*
|
|
663
|
+
* `@tiptap/extension-collaboration` uses its own history implementation.
|
|
664
|
+
*/
|
|
665
|
+
const UndoRedo = _tiptap_core.Extension.create({
|
|
666
|
+
name: "undoRedo",
|
|
667
|
+
addOptions() {
|
|
668
|
+
return {
|
|
669
|
+
depth: 100,
|
|
670
|
+
newGroupDelay: 500
|
|
671
|
+
};
|
|
672
|
+
},
|
|
673
|
+
addCommands() {
|
|
674
|
+
return {
|
|
675
|
+
undo: () => ({ state, dispatch }) => {
|
|
676
|
+
return (0, _tiptap_pm_history.undo)(state, dispatch);
|
|
677
|
+
},
|
|
678
|
+
redo: () => ({ state, dispatch }) => {
|
|
679
|
+
return (0, _tiptap_pm_history.redo)(state, dispatch);
|
|
680
|
+
}
|
|
681
|
+
};
|
|
682
|
+
},
|
|
683
|
+
addProseMirrorPlugins() {
|
|
684
|
+
return [(0, _tiptap_pm_history.history)(this.options)];
|
|
685
|
+
},
|
|
686
|
+
addKeyboardShortcuts() {
|
|
687
|
+
return {
|
|
688
|
+
"Mod-z": () => this.editor.commands.undo(),
|
|
689
|
+
"Shift-Mod-z": () => this.editor.commands.redo(),
|
|
690
|
+
"Mod-y": () => this.editor.commands.redo(),
|
|
691
|
+
"Mod-я": () => this.editor.commands.undo(),
|
|
692
|
+
"Shift-Mod-я": () => this.editor.commands.redo()
|
|
693
|
+
};
|
|
694
|
+
}
|
|
785
695
|
});
|
|
696
|
+
//#endregion
|
|
697
|
+
exports.CharacterCount = CharacterCount;
|
|
698
|
+
exports.DEFAULT_DATA_ATTRIBUTE = DEFAULT_DATA_ATTRIBUTE;
|
|
699
|
+
exports.Dropcursor = Dropcursor;
|
|
700
|
+
exports.Focus = Focus;
|
|
701
|
+
exports.Gapcursor = Gapcursor;
|
|
702
|
+
exports.PLUGIN_KEY = PLUGIN_KEY;
|
|
703
|
+
exports.Placeholder = Placeholder;
|
|
704
|
+
exports.Selection = Selection;
|
|
705
|
+
exports.TrailingNode = TrailingNode;
|
|
706
|
+
exports.UndoRedo = UndoRedo;
|
|
707
|
+
exports.preparePlaceholderAttribute = preparePlaceholderAttribute;
|
|
708
|
+
exports.skipTrailingNodeMeta = skipTrailingNodeMeta;
|
|
709
|
+
|
|
786
710
|
//# sourceMappingURL=index.cjs.map
|