@tiptap/extensions 3.30.2 → 3.30.4

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