@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
@@ -1,404 +1,372 @@
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/placeholder/index.ts
21
- var index_exports = {};
22
- __export(index_exports, {
23
- DEFAULT_DATA_ATTRIBUTE: () => DEFAULT_DATA_ATTRIBUTE,
24
- PLUGIN_KEY: () => PLUGIN_KEY,
25
- Placeholder: () => Placeholder,
26
- preparePlaceholderAttribute: () => preparePlaceholderAttribute
27
- });
28
- module.exports = __toCommonJS(index_exports);
29
-
30
- // src/placeholder/constants.ts
31
- var import_state = require("@tiptap/pm/state");
32
- var DEFAULT_DATA_ATTRIBUTE = "placeholder";
33
- var PLUGIN_KEY = new import_state.PluginKey("tiptap__placeholder");
34
-
35
- // src/placeholder/placeholder.ts
36
- var import_core3 = require("@tiptap/core");
37
-
38
- // src/placeholder/plugins/PlaceholderPlugin.ts
39
- var import_state2 = require("@tiptap/pm/state");
40
- var import_view4 = require("@tiptap/pm/view");
41
-
42
- // src/placeholder/utils/buildPlaceholderDecorations.ts
43
- var import_core = require("@tiptap/core");
44
- var import_view2 = require("@tiptap/pm/view");
45
-
46
- // src/placeholder/utils/createPlaceholderDecoration.ts
47
- var import_view = require("@tiptap/pm/view");
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ let _tiptap_pm_state = require("@tiptap/pm/state");
3
+ let _tiptap_core = require("@tiptap/core");
4
+ let _tiptap_pm_view = require("@tiptap/pm/view");
5
+ //#region src/placeholder/constants.ts
6
+ /** The default data attribute label */
7
+ const DEFAULT_DATA_ATTRIBUTE = "placeholder";
8
+ /** The plugin key used to store and read the placeholder decoration set */
9
+ const PLUGIN_KEY = new _tiptap_pm_state.PluginKey("tiptap__placeholder");
10
+ //#endregion
11
+ //#region src/placeholder/utils/createPlaceholderDecoration.ts
12
+ /**
13
+ * Creates a ProseMirror node decoration that applies a placeholder
14
+ * CSS class and data attribute to an empty node.
15
+ * @param options.editor - The editor instance
16
+ * @param options.pos - The position of the node in the document
17
+ * @param options.node - The ProseMirror node
18
+ * @param options.isEmptyDoc - Whether the entire document is empty
19
+ * @param options.hasAnchor - Whether the selection anchor is within the node
20
+ * @param options.dataAttribute - The data attribute name (e.g. `data-placeholder`)
21
+ * @param options.classes - CSS classes for empty nodes and the empty editor
22
+ * @param options.placeholder - The placeholder text or a function that returns it
23
+ * @returns A ProseMirror node decoration with placeholder classes and data attribute
24
+ */
48
25
  function createPlaceholderDecoration(options) {
49
- const {
50
- editor,
51
- placeholder,
52
- dataAttribute,
53
- pos,
54
- node,
55
- isEmptyDoc,
56
- hasAnchor,
57
- classes: { emptyNode, emptyEditor }
58
- } = options;
59
- const classes = [emptyNode];
60
- if (isEmptyDoc) {
61
- classes.push(emptyEditor);
62
- }
63
- return import_view.Decoration.node(pos, pos + node.nodeSize, {
64
- class: classes.join(" "),
65
- [dataAttribute]: typeof placeholder === "function" ? placeholder({
66
- editor,
67
- node,
68
- pos,
69
- hasAnchor
70
- }) : placeholder
71
- });
26
+ const { editor, placeholder, dataAttribute, pos, node, isEmptyDoc, hasAnchor, classes: { emptyNode, emptyEditor } } = options;
27
+ const classes = [emptyNode];
28
+ if (isEmptyDoc) classes.push(emptyEditor);
29
+ return _tiptap_pm_view.Decoration.node(pos, pos + node.nodeSize, {
30
+ class: classes.join(" "),
31
+ [dataAttribute]: typeof placeholder === "function" ? placeholder({
32
+ editor,
33
+ node,
34
+ pos,
35
+ hasAnchor
36
+ }) : placeholder
37
+ });
72
38
  }
73
-
74
- // src/placeholder/utils/buildPlaceholderDecorations.ts
39
+ //#endregion
40
+ //#region src/placeholder/utils/buildPlaceholderDecorations.ts
75
41
  function resolveEmptyNodeClass(emptyNodeClass, props) {
76
- return typeof emptyNodeClass === "function" ? emptyNodeClass(props) : emptyNodeClass;
42
+ return typeof emptyNodeClass === "function" ? emptyNodeClass(props) : emptyNodeClass;
77
43
  }
78
- function scanRangeForDecorations({
79
- editor,
80
- options,
81
- dataAttribute,
82
- doc,
83
- selection,
84
- from,
85
- to
86
- }) {
87
- const { anchor } = selection;
88
- const decorations = [];
89
- const isEmptyDoc = editor.isEmpty;
90
- doc.nodesBetween(from, to, (node, pos) => {
91
- const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
92
- const isEmpty = !node.isLeaf && (0, import_core.isNodeEmpty)(node);
93
- if (!node.type.isTextblock) {
94
- return options.includeChildren;
95
- }
96
- if ((hasAnchor || !options.showOnlyCurrent) && isEmpty) {
97
- decorations.push(
98
- createPlaceholderDecoration({
99
- editor,
100
- isEmptyDoc,
101
- dataAttribute,
102
- hasAnchor,
103
- placeholder: options.placeholder,
104
- classes: {
105
- emptyEditor: options.emptyEditorClass,
106
- emptyNode: resolveEmptyNodeClass(options.emptyNodeClass, {
107
- editor,
108
- node,
109
- pos,
110
- hasAnchor
111
- })
112
- },
113
- node,
114
- pos
115
- })
116
- );
117
- }
118
- return options.includeChildren;
119
- });
120
- return decorations;
44
+ /**
45
+ * Scans a document range for empty textblocks that should receive placeholder
46
+ * decorations. Used by the slow path and incremental state updates.
47
+ */
48
+ function scanRangeForDecorations({ editor, options, dataAttribute, doc, selection, from, to }) {
49
+ const { anchor } = selection;
50
+ const decorations = [];
51
+ const isEmptyDoc = editor.isEmpty;
52
+ doc.nodesBetween(from, to, (node, pos) => {
53
+ const hasAnchor = anchor >= pos && anchor <= pos + node.nodeSize;
54
+ const isEmpty = !node.isLeaf && (0, _tiptap_core.isNodeEmpty)(node);
55
+ if (!node.type.isTextblock) return options.includeChildren;
56
+ if ((hasAnchor || !options.showOnlyCurrent) && isEmpty) decorations.push(createPlaceholderDecoration({
57
+ editor,
58
+ isEmptyDoc,
59
+ dataAttribute,
60
+ hasAnchor,
61
+ placeholder: options.placeholder,
62
+ classes: {
63
+ emptyEditor: options.emptyEditorClass,
64
+ emptyNode: resolveEmptyNodeClass(options.emptyNodeClass, {
65
+ editor,
66
+ node,
67
+ pos,
68
+ hasAnchor
69
+ })
70
+ },
71
+ node,
72
+ pos
73
+ }));
74
+ return options.includeChildren;
75
+ });
76
+ return decorations;
121
77
  }
122
- function buildPlaceholderDecorations({
123
- editor,
124
- options,
125
- dataAttribute,
126
- doc,
127
- selection
128
- }) {
129
- const active = editor.isEditable || !options.showOnlyWhenEditable;
130
- if (!active) {
131
- return null;
132
- }
133
- const { anchor } = selection;
134
- const decorations = [];
135
- const isEmptyDoc = editor.isEmpty;
136
- const useResolvedPath = options.showOnlyCurrent && !options.includeChildren;
137
- if (useResolvedPath) {
138
- const resolved = doc.resolve(anchor);
139
- const node = resolved.depth > 0 ? resolved.node(1) : resolved.nodeAfter;
140
- const nodeStart = resolved.depth > 0 ? resolved.before(1) : anchor;
141
- if (node && node.type.isTextblock && (0, import_core.isNodeEmpty)(node)) {
142
- const hasAnchor = anchor >= nodeStart && anchor <= nodeStart + node.nodeSize;
143
- decorations.push(
144
- createPlaceholderDecoration({
145
- editor,
146
- isEmptyDoc,
147
- dataAttribute,
148
- hasAnchor,
149
- placeholder: options.placeholder,
150
- classes: {
151
- emptyEditor: options.emptyEditorClass,
152
- emptyNode: resolveEmptyNodeClass(options.emptyNodeClass, {
153
- editor,
154
- node,
155
- pos: nodeStart,
156
- hasAnchor
157
- })
158
- },
159
- node,
160
- pos: nodeStart
161
- })
162
- );
163
- }
164
- } else {
165
- decorations.push(
166
- ...scanRangeForDecorations({
167
- editor,
168
- options,
169
- dataAttribute,
170
- doc,
171
- selection,
172
- from: 0,
173
- to: doc.content.size
174
- })
175
- );
176
- }
177
- return import_view2.DecorationSet.create(doc, decorations);
78
+ /**
79
+ * Builds the placeholder decorations for the current document state.
80
+ * @param options.editor - The editor instance.
81
+ * @param options.options - The resolved placeholder options.
82
+ * @param options.dataAttribute - The prepared `data-*` attribute name.
83
+ * @param options.doc - The current document node.
84
+ * @param options.selection - The current selection.
85
+ * @returns A decoration set, or `null` when no placeholders should be shown.
86
+ */
87
+ function buildPlaceholderDecorations({ editor, options, dataAttribute, doc, selection }) {
88
+ if (!(editor.isEditable || !options.showOnlyWhenEditable)) return null;
89
+ const { anchor } = selection;
90
+ const decorations = [];
91
+ const isEmptyDoc = editor.isEmpty;
92
+ if (options.showOnlyCurrent && !options.includeChildren) {
93
+ const resolved = doc.resolve(anchor);
94
+ const node = resolved.depth > 0 ? resolved.node(1) : resolved.nodeAfter;
95
+ const nodeStart = resolved.depth > 0 ? resolved.before(1) : anchor;
96
+ if (node && node.type.isTextblock && (0, _tiptap_core.isNodeEmpty)(node)) {
97
+ const hasAnchor = anchor >= nodeStart && anchor <= nodeStart + node.nodeSize;
98
+ decorations.push(createPlaceholderDecoration({
99
+ editor,
100
+ isEmptyDoc,
101
+ dataAttribute,
102
+ hasAnchor,
103
+ placeholder: options.placeholder,
104
+ classes: {
105
+ emptyEditor: options.emptyEditorClass,
106
+ emptyNode: resolveEmptyNodeClass(options.emptyNodeClass, {
107
+ editor,
108
+ node,
109
+ pos: nodeStart,
110
+ hasAnchor
111
+ })
112
+ },
113
+ node,
114
+ pos: nodeStart
115
+ }));
116
+ }
117
+ } else decorations.push(...scanRangeForDecorations({
118
+ editor,
119
+ options,
120
+ dataAttribute,
121
+ doc,
122
+ selection,
123
+ from: 0,
124
+ to: doc.content.size
125
+ }));
126
+ return _tiptap_pm_view.DecorationSet.create(doc, decorations);
178
127
  }
179
-
180
- // src/placeholder/utils/placeholderStateField.ts
181
- var import_core2 = require("@tiptap/core");
182
- var import_view3 = require("@tiptap/pm/view");
183
-
184
- // src/placeholder/utils/resolveTopLevelRange.ts
128
+ //#endregion
129
+ //#region src/placeholder/utils/resolveTopLevelRange.ts
130
+ /**
131
+ * Resolves a document position to the `[from, to)` range of its containing
132
+ * top-level block node in absolute document positions.
133
+ */
185
134
  function resolveTopLevelRange(doc, pos) {
186
- var _a;
187
- const resolved = doc.resolve(pos);
188
- if (resolved.depth === 0) {
189
- const node2 = (_a = resolved.nodeAfter) != null ? _a : resolved.nodeBefore;
190
- if (!node2) {
191
- return { from: pos, to: pos };
192
- }
193
- const nodePos = resolved.nodeAfter ? pos : pos - node2.nodeSize;
194
- return { from: nodePos, to: nodePos + node2.nodeSize };
195
- }
196
- const topLevelPos = resolved.before(1);
197
- const node = resolved.node(1);
198
- return { from: topLevelPos, to: topLevelPos + node.nodeSize };
135
+ const resolved = doc.resolve(pos);
136
+ if (resolved.depth === 0) {
137
+ var _resolved$nodeAfter;
138
+ const node = (_resolved$nodeAfter = resolved.nodeAfter) !== null && _resolved$nodeAfter !== void 0 ? _resolved$nodeAfter : resolved.nodeBefore;
139
+ if (!node) return {
140
+ from: pos,
141
+ to: pos
142
+ };
143
+ const nodePos = resolved.nodeAfter ? pos : pos - node.nodeSize;
144
+ return {
145
+ from: nodePos,
146
+ to: nodePos + node.nodeSize
147
+ };
148
+ }
149
+ const topLevelPos = resolved.before(1);
150
+ return {
151
+ from: topLevelPos,
152
+ to: topLevelPos + resolved.node(1).nodeSize
153
+ };
199
154
  }
155
+ /**
156
+ * Converts an absolute document range to content-relative positions used by
157
+ * `Node#nodesBetween` and `Node#forEach` offsets.
158
+ */
200
159
  function toContentRelativeRange(doc, range) {
201
- return {
202
- from: Math.max(0, range.from - 1),
203
- to: Math.min(doc.content.size, range.to - 1)
204
- };
160
+ return {
161
+ from: Math.max(0, range.from - 1),
162
+ to: Math.min(doc.content.size, range.to - 1)
163
+ };
205
164
  }
165
+ /**
166
+ * Returns the top-level block ranges that intersect a document change range.
167
+ * Input `from`/`to` are absolute positions (e.g. from `getChangedRanges`).
168
+ * Returned ranges are content-relative, matching `Node#forEach` offsets.
169
+ */
206
170
  function getTopLevelBlocksInRange(doc, from, to) {
207
- const ranges = [];
208
- doc.forEach((node, offset) => {
209
- const nodeStart = offset;
210
- const nodeEnd = nodeStart + node.nodeSize;
211
- const absNodeStart = nodeStart + 1;
212
- const absNodeEnd = nodeEnd + 1;
213
- if (absNodeStart < to && absNodeEnd > from) {
214
- ranges.push({ from: nodeStart, to: nodeEnd });
215
- }
216
- });
217
- return ranges;
171
+ const ranges = [];
172
+ doc.forEach((node, offset) => {
173
+ const nodeStart = offset;
174
+ const nodeEnd = nodeStart + node.nodeSize;
175
+ const absNodeStart = nodeStart + 1;
176
+ const absNodeEnd = nodeEnd + 1;
177
+ if (absNodeStart < to && absNodeEnd > from) ranges.push({
178
+ from: nodeStart,
179
+ to: nodeEnd
180
+ });
181
+ });
182
+ return ranges;
218
183
  }
184
+ /**
185
+ * Sorts ranges by start position and merges overlapping or adjacent ranges.
186
+ */
219
187
  function mergeRanges(ranges) {
220
- if (ranges.length === 0) {
221
- return [];
222
- }
223
- const sorted = [...ranges].sort((a, b) => a.from - b.from);
224
- const merged = [{ ...sorted[0] }];
225
- for (let i = 1; i < sorted.length; i += 1) {
226
- const last = merged[merged.length - 1];
227
- const current = sorted[i];
228
- if (current.from <= last.to) {
229
- last.to = Math.max(last.to, current.to);
230
- } else {
231
- merged.push({ ...current });
232
- }
233
- }
234
- return merged;
188
+ if (ranges.length === 0) return [];
189
+ const sorted = [...ranges].sort((a, b) => a.from - b.from);
190
+ const merged = [{ ...sorted[0] }];
191
+ for (let i = 1; i < sorted.length; i += 1) {
192
+ const last = merged[merged.length - 1];
193
+ const current = sorted[i];
194
+ if (current.from <= last.to) last.to = Math.max(last.to, current.to);
195
+ else merged.push({ ...current });
196
+ }
197
+ return merged;
235
198
  }
236
-
237
- // src/placeholder/utils/placeholderStateField.ts
199
+ //#endregion
200
+ //#region src/placeholder/utils/placeholderStateField.ts
201
+ /**
202
+ * Expands a single changed range to the top-level blocks it touches.
203
+ * Also resolves blocks at range boundaries so split/merge edits update
204
+ * adjacent empty nodes (e.g. a new paragraph after Enter).
205
+ */
238
206
  function collectBlocksForChange(doc, change) {
239
- const ranges = getTopLevelBlocksInRange(doc, change.from, change.to);
240
- ranges.push(toContentRelativeRange(doc, resolveTopLevelRange(doc, change.from)));
241
- if (change.to > change.from) {
242
- ranges.push(
243
- toContentRelativeRange(
244
- doc,
245
- resolveTopLevelRange(doc, Math.min(change.to, doc.content.size + 1) - 1)
246
- )
247
- );
248
- } else if (change.from < doc.content.size + 1) {
249
- ranges.push(
250
- toContentRelativeRange(
251
- doc,
252
- resolveTopLevelRange(doc, Math.min(change.from + 1, doc.content.size))
253
- )
254
- );
255
- }
256
- return ranges;
207
+ const ranges = getTopLevelBlocksInRange(doc, change.from, change.to);
208
+ ranges.push(toContentRelativeRange(doc, resolveTopLevelRange(doc, change.from)));
209
+ if (change.to > change.from) ranges.push(toContentRelativeRange(doc, resolveTopLevelRange(doc, Math.min(change.to, doc.content.size + 1) - 1)));
210
+ else if (change.from < doc.content.size + 1) ranges.push(toContentRelativeRange(doc, resolveTopLevelRange(doc, Math.min(change.from + 1, doc.content.size))));
211
+ return ranges;
257
212
  }
213
+ /**
214
+ * Collects content-relative top-level block ranges that need placeholder
215
+ * decorations recomputed after a transaction.
216
+ */
258
217
  function collectRescanRanges(tr, oldState, newState) {
259
- const ranges = [];
260
- if (tr.docChanged) {
261
- const changes = (0, import_core2.getChangedRanges)(tr);
262
- for (const change of changes) {
263
- ranges.push(...collectBlocksForChange(newState.doc, change.newRange));
264
- }
265
- }
266
- if (tr.selectionSet) {
267
- ranges.push(
268
- toContentRelativeRange(
269
- newState.doc,
270
- resolveTopLevelRange(newState.doc, tr.mapping.map(oldState.selection.anchor))
271
- )
272
- );
273
- ranges.push(
274
- toContentRelativeRange(
275
- newState.doc,
276
- resolveTopLevelRange(newState.doc, newState.selection.anchor)
277
- )
278
- );
279
- }
280
- return mergeRanges(ranges);
218
+ const ranges = [];
219
+ if (tr.docChanged) {
220
+ const changes = (0, _tiptap_core.getChangedRanges)(tr);
221
+ for (const change of changes) ranges.push(...collectBlocksForChange(newState.doc, change.newRange));
222
+ }
223
+ if (tr.selectionSet) {
224
+ ranges.push(toContentRelativeRange(newState.doc, resolveTopLevelRange(newState.doc, tr.mapping.map(oldState.selection.anchor))));
225
+ ranges.push(toContentRelativeRange(newState.doc, resolveTopLevelRange(newState.doc, newState.selection.anchor)));
226
+ }
227
+ return mergeRanges(ranges);
281
228
  }
229
+ /** Clamps a content-relative range to `[0, doc.content.size]`. */
282
230
  function clampRange(from, to, doc) {
283
- const clampedFrom = Math.max(0, Math.min(from, doc.content.size));
284
- const clampedTo = Math.max(clampedFrom, Math.min(to, doc.content.size));
285
- return { from: clampedFrom, to: clampedTo };
231
+ const clampedFrom = Math.max(0, Math.min(from, doc.content.size));
232
+ return {
233
+ from: clampedFrom,
234
+ to: Math.max(clampedFrom, Math.min(to, doc.content.size))
235
+ };
286
236
  }
287
- function updateDecorationsInRanges({
288
- decorations,
289
- ranges,
290
- editor,
291
- options,
292
- dataAttribute,
293
- doc,
294
- selection
295
- }) {
296
- let next = decorations;
297
- for (const range of ranges) {
298
- const { from, to } = clampRange(range.from, range.to, doc);
299
- const existing = next.find(from, to).filter((decoration) => decoration.from >= from && decoration.to <= to);
300
- if (existing.length) {
301
- next = next.remove(existing);
302
- }
303
- const newDecos = scanRangeForDecorations({
304
- editor,
305
- options,
306
- dataAttribute,
307
- doc,
308
- selection,
309
- from,
310
- to
311
- });
312
- if (newDecos.length) {
313
- next = next.add(doc, newDecos);
314
- }
315
- }
316
- return next;
237
+ /**
238
+ * Removes and rebuilds placeholder decorations within the given ranges.
239
+ * Only drops decorations fully contained in a range so mapped decorations
240
+ * on neighbouring blocks (e.g. at a block boundary) are kept intact.
241
+ */
242
+ function updateDecorationsInRanges({ decorations, ranges, editor, options, dataAttribute, doc, selection }) {
243
+ let next = decorations;
244
+ for (const range of ranges) {
245
+ const { from, to } = clampRange(range.from, range.to, doc);
246
+ const existing = next.find(from, to).filter((decoration) => decoration.from >= from && decoration.to <= to);
247
+ if (existing.length) next = next.remove(existing);
248
+ const newDecos = scanRangeForDecorations({
249
+ editor,
250
+ options,
251
+ dataAttribute,
252
+ doc,
253
+ selection,
254
+ from,
255
+ to
256
+ });
257
+ if (newDecos.length) next = next.add(doc, newDecos);
258
+ }
259
+ return next;
317
260
  }
318
- function createPlaceholderStateField({
319
- editor,
320
- options,
321
- dataAttribute
322
- }) {
323
- return {
324
- init(_config, state) {
325
- const decorations = buildPlaceholderDecorations({
326
- editor,
327
- options,
328
- dataAttribute,
329
- doc: state.doc,
330
- selection: state.selection
331
- });
332
- return decorations != null ? decorations : import_view3.DecorationSet.empty;
333
- },
334
- apply(tr, prev, oldState, newState) {
335
- if (!tr.docChanged && !tr.selectionSet) {
336
- return prev;
337
- }
338
- const mapped = prev.map(tr.mapping, tr.doc);
339
- const ranges = collectRescanRanges(tr, oldState, newState);
340
- return updateDecorationsInRanges({
341
- decorations: mapped,
342
- ranges,
343
- editor,
344
- options,
345
- dataAttribute,
346
- doc: newState.doc,
347
- selection: newState.selection
348
- });
349
- }
350
- };
261
+ /**
262
+ * Creates the incremental `StateField<DecorationSet>` used by the slow path
263
+ * (`showOnlyCurrent: false` or `includeChildren: true`).
264
+ *
265
+ * Decorations are mapped through each transaction and only recomputed for
266
+ * top-level blocks touched by document or selection changes.
267
+ * @param options.editor - The editor instance.
268
+ * @param options.options - The resolved placeholder options.
269
+ * @param options.dataAttribute - The prepared `data-*` attribute name.
270
+ * @returns A ProseMirror state field storing the placeholder decoration set.
271
+ */
272
+ function createPlaceholderStateField({ editor, options, dataAttribute }) {
273
+ return {
274
+ init(_config, state) {
275
+ const decorations = buildPlaceholderDecorations({
276
+ editor,
277
+ options,
278
+ dataAttribute,
279
+ doc: state.doc,
280
+ selection: state.selection
281
+ });
282
+ return decorations !== null && decorations !== void 0 ? decorations : _tiptap_pm_view.DecorationSet.empty;
283
+ },
284
+ apply(tr, prev, oldState, newState) {
285
+ if (!tr.docChanged && !tr.selectionSet) return prev;
286
+ return updateDecorationsInRanges({
287
+ decorations: prev.map(tr.mapping, tr.doc),
288
+ ranges: collectRescanRanges(tr, oldState, newState),
289
+ editor,
290
+ options,
291
+ dataAttribute,
292
+ doc: newState.doc,
293
+ selection: newState.selection
294
+ });
295
+ }
296
+ };
351
297
  }
352
-
353
- // src/placeholder/utils/preparePlaceholderAttribute.ts
298
+ //#endregion
299
+ //#region src/placeholder/utils/preparePlaceholderAttribute.ts
300
+ /**
301
+ * Prepares the placeholder attribute by ensuring it is properly formatted.
302
+ * @param attr - The placeholder attribute string.
303
+ * @returns The prepared placeholder attribute string.
304
+ */
354
305
  function preparePlaceholderAttribute(attr) {
355
- return attr.replace(/\s+/g, "-").replace(/[^a-zA-Z0-9-]/g, "").replace(/^[0-9-]+/, "").replace(/^-+/, "").toLowerCase();
306
+ return attr.replace(/\s+/g, "-").replace(/[^a-zA-Z0-9-]/g, "").replace(/^[0-9-]+/, "").replace(/^-+/, "").toLowerCase();
356
307
  }
357
-
358
- // src/placeholder/plugins/PlaceholderPlugin.ts
308
+ //#endregion
309
+ //#region src/placeholder/plugins/PlaceholderPlugin.ts
310
+ /**
311
+ * Creates the ProseMirror plugin that renders placeholder decorations.
312
+ * @param options.editor - The editor instance.
313
+ * @param options.options - The resolved placeholder options.
314
+ * @returns The configured placeholder plugin.
315
+ */
359
316
  function createPlaceholderPlugin({ editor, options }) {
360
- const dataAttribute = options.dataAttribute ? `data-${preparePlaceholderAttribute(options.dataAttribute)}` : `data-${DEFAULT_DATA_ATTRIBUTE}`;
361
- const useResolvedPath = options.showOnlyCurrent && !options.includeChildren;
362
- return new import_state2.Plugin({
363
- key: PLUGIN_KEY,
364
- ...useResolvedPath ? {} : {
365
- state: createPlaceholderStateField({ editor, options, dataAttribute })
366
- },
367
- props: {
368
- decorations: useResolvedPath ? ({ doc, selection }) => buildPlaceholderDecorations({ editor, options, dataAttribute, doc, selection }) : (state) => {
369
- var _a;
370
- if (options.showOnlyWhenEditable && !editor.isEditable) {
371
- return import_view4.DecorationSet.empty;
372
- }
373
- return (_a = PLUGIN_KEY.getState(state)) != null ? _a : import_view4.DecorationSet.empty;
374
- }
375
- }
376
- });
317
+ const dataAttribute = options.dataAttribute ? `data-${preparePlaceholderAttribute(options.dataAttribute)}` : `data-${DEFAULT_DATA_ATTRIBUTE}`;
318
+ const useResolvedPath = options.showOnlyCurrent && !options.includeChildren;
319
+ return new _tiptap_pm_state.Plugin({
320
+ key: PLUGIN_KEY,
321
+ ...useResolvedPath ? {} : { state: createPlaceholderStateField({
322
+ editor,
323
+ options,
324
+ dataAttribute
325
+ }) },
326
+ props: { decorations: useResolvedPath ? ({ doc, selection }) => buildPlaceholderDecorations({
327
+ editor,
328
+ options,
329
+ dataAttribute,
330
+ doc,
331
+ selection
332
+ }) : (state) => {
333
+ var _PLUGIN_KEY$getState;
334
+ if (options.showOnlyWhenEditable && !editor.isEditable) return _tiptap_pm_view.DecorationSet.empty;
335
+ return (_PLUGIN_KEY$getState = PLUGIN_KEY.getState(state)) !== null && _PLUGIN_KEY$getState !== void 0 ? _PLUGIN_KEY$getState : _tiptap_pm_view.DecorationSet.empty;
336
+ } }
337
+ });
377
338
  }
378
-
379
- // src/placeholder/placeholder.ts
380
- var Placeholder = import_core3.Extension.create({
381
- name: "placeholder",
382
- addOptions() {
383
- return {
384
- emptyEditorClass: "is-editor-empty",
385
- emptyNodeClass: "is-empty",
386
- dataAttribute: DEFAULT_DATA_ATTRIBUTE,
387
- placeholder: "Write something \u2026",
388
- showOnlyWhenEditable: true,
389
- showOnlyCurrent: true,
390
- includeChildren: false
391
- };
392
- },
393
- addProseMirrorPlugins() {
394
- return [createPlaceholderPlugin({ editor: this.editor, options: this.options })];
395
- }
396
- });
397
- // Annotate the CommonJS export names for ESM import in node:
398
- 0 && (module.exports = {
399
- DEFAULT_DATA_ATTRIBUTE,
400
- PLUGIN_KEY,
401
- Placeholder,
402
- preparePlaceholderAttribute
339
+ //#endregion
340
+ //#region src/placeholder/placeholder.ts
341
+ /**
342
+ * This extension allows you to add a placeholder to your editor.
343
+ * A placeholder is a text that appears when the editor or a node is empty.
344
+ * @see https://www.tiptap.dev/api/extensions/placeholder
345
+ */
346
+ const Placeholder = _tiptap_core.Extension.create({
347
+ name: "placeholder",
348
+ addOptions() {
349
+ return {
350
+ emptyEditorClass: "is-editor-empty",
351
+ emptyNodeClass: "is-empty",
352
+ dataAttribute: DEFAULT_DATA_ATTRIBUTE,
353
+ placeholder: "Write something …",
354
+ showOnlyWhenEditable: true,
355
+ showOnlyCurrent: true,
356
+ includeChildren: false
357
+ };
358
+ },
359
+ addProseMirrorPlugins() {
360
+ return [createPlaceholderPlugin({
361
+ editor: this.editor,
362
+ options: this.options
363
+ })];
364
+ }
403
365
  });
366
+ //#endregion
367
+ exports.DEFAULT_DATA_ATTRIBUTE = DEFAULT_DATA_ATTRIBUTE;
368
+ exports.PLUGIN_KEY = PLUGIN_KEY;
369
+ exports.Placeholder = Placeholder;
370
+ exports.preparePlaceholderAttribute = preparePlaceholderAttribute;
371
+
404
372
  //# sourceMappingURL=index.cjs.map