@tiptap/extensions 3.30.1 → 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.
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 +25 -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 +24 -21
  32. package/dist/gap-cursor/index.js.map +1 -1
  33. package/dist/index.cjs +666 -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 +653 -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,710 @@
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
+ 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
- // 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");
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
- 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
- });
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
- // src/placeholder/utils/buildPlaceholderDecorations.ts
207
+ //#endregion
208
+ //#region src/placeholder/utils/buildPlaceholderDecorations.ts
287
209
  function resolveEmptyNodeClass(emptyNodeClass, props) {
288
- return typeof emptyNodeClass === "function" ? emptyNodeClass(props) : emptyNodeClass;
210
+ return typeof emptyNodeClass === "function" ? emptyNodeClass(props) : emptyNodeClass;
289
211
  }
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;
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
- 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);
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
- // 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
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
- 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 };
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
- return {
414
- from: Math.max(0, range.from - 1),
415
- to: Math.min(doc.content.size, range.to - 1)
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
- 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;
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
- 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;
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
- // src/placeholder/utils/placeholderStateField.ts
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
- 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;
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
- 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);
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
- 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 };
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
- 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;
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
- 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
- };
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
- // src/placeholder/utils/preparePlaceholderAttribute.ts
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
- return attr.replace(/\s+/g, "-").replace(/[^a-zA-Z0-9-]/g, "").replace(/^[0-9-]+/, "").replace(/^-+/, "").toLowerCase();
474
+ return attr.replace(/\s+/g, "-").replace(/[^a-zA-Z0-9-]/g, "").replace(/^[0-9-]+/, "").replace(/^-+/, "").toLowerCase();
568
475
  }
569
-
570
- // src/placeholder/plugins/PlaceholderPlugin.ts
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
- 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
- });
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
- // 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
- }
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
- // 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");
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
- return !state.selection.empty && !(0, import_core8.isNodeSelection)(state.selection) && editor.isEditable;
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
- return shouldSyncDomSelection(state, editor) && !editor.isFocused && !editor.view.dragging;
548
+ return shouldSyncDomSelection(state, editor) && !editor.isFocused && !editor.view.dragging;
619
549
  }
620
550
  function clearDomSelection() {
621
- var _a;
622
- (_a = window.getSelection()) == null ? void 0 : _a.removeAllRanges();
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
- view.focus();
559
+ view.focus();
626
560
  }
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
- }
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
- // 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;
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
- 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
- }
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
- // 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
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