@tiptap/extension-unique-id 3.20.3 → 3.20.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs ADDED
@@ -0,0 +1,367 @@
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
+ UniqueID: () => UniqueID,
24
+ default: () => index_default,
25
+ generateUniqueIds: () => generateUniqueIds
26
+ });
27
+ module.exports = __toCommonJS(index_exports);
28
+
29
+ // src/unique-id.ts
30
+ var import_core = require("@tiptap/core");
31
+ var import_model = require("@tiptap/pm/model");
32
+ var import_state = require("@tiptap/pm/state");
33
+ var import_uuid = require("uuid");
34
+
35
+ // src/helpers/findDuplicates.ts
36
+ function findDuplicates(items) {
37
+ const seen = /* @__PURE__ */ new Set();
38
+ const duplicates = /* @__PURE__ */ new Set();
39
+ items.forEach((item) => {
40
+ if (seen.has(item)) {
41
+ duplicates.add(item);
42
+ } else {
43
+ seen.add(item);
44
+ }
45
+ });
46
+ return Array.from(duplicates);
47
+ }
48
+
49
+ // src/unique-id.ts
50
+ var resolveTypes = (types, extensions) => {
51
+ if (types !== "all") {
52
+ return types;
53
+ }
54
+ const { nodeExtensions } = (0, import_core.splitExtensions)(extensions);
55
+ return nodeExtensions.map((extension) => extension.name).filter((type) => type !== "doc" && type !== "text");
56
+ };
57
+ var UniqueID = import_core.Extension.create({
58
+ name: "uniqueID",
59
+ // we’ll set a very high priority to make sure this runs first
60
+ // and is compatible with `appendTransaction` hooks of other extensions
61
+ priority: 1e4,
62
+ addOptions() {
63
+ return {
64
+ attributeName: "id",
65
+ types: [],
66
+ generateID: () => (0, import_uuid.v4)(),
67
+ filterTransaction: null,
68
+ updateDocument: true
69
+ };
70
+ },
71
+ /**
72
+ * Extension storage for coordination between `addProseMirrorPlugins` and `appendTransaction`.
73
+ * `needsInitialIdGeneration` is set to `true` when the Collaboration extension is
74
+ * detected but no provider is available in its options, deferring ID creation
75
+ * to the first `y-sync$` transaction.
76
+ */
77
+ addStorage() {
78
+ return {
79
+ needsInitialIdGeneration: false
80
+ };
81
+ },
82
+ addGlobalAttributes() {
83
+ const types = resolveTypes(this.options.types, this.extensions);
84
+ return [
85
+ {
86
+ types,
87
+ attributes: {
88
+ [this.options.attributeName]: {
89
+ default: null,
90
+ parseHTML: (element) => element.getAttribute(`data-${this.options.attributeName}`),
91
+ renderHTML: (attributes) => {
92
+ if (!attributes[this.options.attributeName]) {
93
+ return {};
94
+ }
95
+ return {
96
+ [`data-${this.options.attributeName}`]: attributes[this.options.attributeName]
97
+ };
98
+ }
99
+ }
100
+ }
101
+ }
102
+ ];
103
+ },
104
+ // check initial content for missing ids
105
+ onCreate() {
106
+ var _a;
107
+ if (!this.options.updateDocument) {
108
+ return;
109
+ }
110
+ const collaboration = this.editor.extensionManager.extensions.find((ext) => ext.name === "collaboration");
111
+ const collaborationCaret = this.editor.extensionManager.extensions.find((ext) => ext.name === "collaborationCaret");
112
+ const collabExtensions = [collaboration, collaborationCaret].filter(Boolean);
113
+ const collab = collabExtensions.find((ext) => {
114
+ var _a2;
115
+ return (_a2 = ext == null ? void 0 : ext.options) == null ? void 0 : _a2.provider;
116
+ });
117
+ const provider = (_a = collab == null ? void 0 : collab.options) == null ? void 0 : _a.provider;
118
+ const createIds = () => {
119
+ const { view, state } = this.editor;
120
+ const { tr, doc } = state;
121
+ const types = resolveTypes(this.options.types, this.editor.extensionManager.extensions);
122
+ const { attributeName, generateID } = this.options;
123
+ const nodesWithoutId = (0, import_core.findChildren)(doc, (node) => {
124
+ return types.includes(node.type.name) && node.attrs[attributeName] === null;
125
+ });
126
+ nodesWithoutId.forEach(({ node, pos }) => {
127
+ tr.setNodeMarkup(pos, void 0, {
128
+ ...node.attrs,
129
+ [attributeName]: generateID({ node, pos })
130
+ });
131
+ });
132
+ tr.setMeta("addToHistory", false);
133
+ view.dispatch(tr);
134
+ if (provider) {
135
+ provider.off("synced", createIds);
136
+ }
137
+ };
138
+ if (collaboration) {
139
+ if (provider) {
140
+ provider.on("synced", createIds);
141
+ }
142
+ } else {
143
+ return createIds();
144
+ }
145
+ },
146
+ addProseMirrorPlugins() {
147
+ if (!this.options.updateDocument) {
148
+ return [];
149
+ }
150
+ const extensionStorage = this.storage;
151
+ const collaboration = this.editor.extensionManager.extensions.find((ext) => ext.name === "collaboration");
152
+ const collaborationCaret = this.editor.extensionManager.extensions.find((ext) => ext.name === "collaborationCaret");
153
+ const collabExtensions = [collaboration, collaborationCaret].filter(Boolean);
154
+ const collabWithProvider = collabExtensions.find((ext) => {
155
+ var _a;
156
+ return (_a = ext == null ? void 0 : ext.options) == null ? void 0 : _a.provider;
157
+ });
158
+ if (collaboration && !collabWithProvider) {
159
+ extensionStorage.needsInitialIdGeneration = true;
160
+ }
161
+ let dragSourceElement = null;
162
+ let transformPasted = false;
163
+ const types = resolveTypes(this.options.types, this.editor.extensionManager.extensions);
164
+ return [
165
+ new import_state.Plugin({
166
+ key: new import_state.PluginKey("uniqueID"),
167
+ appendTransaction: (transactions, oldState, newState) => {
168
+ const hasDocChanges = transactions.some((transaction) => transaction.docChanged) && !oldState.doc.eq(newState.doc);
169
+ const filterTransactions = this.options.filterTransaction && transactions.some((tr2) => {
170
+ var _a, _b;
171
+ return !((_b = (_a = this.options).filterTransaction) == null ? void 0 : _b.call(_a, tr2));
172
+ });
173
+ const isCollabTransaction = transactions.find((tr2) => tr2.getMeta("y-sync$"));
174
+ if (isCollabTransaction) {
175
+ if (extensionStorage.needsInitialIdGeneration) {
176
+ extensionStorage.needsInitialIdGeneration = false;
177
+ const { tr: tr2 } = newState;
178
+ const { attributeName: attributeName2, generateID: generateID2 } = this.options;
179
+ const allNodes = (0, import_core.findChildren)(newState.doc, (node) => types.includes(node.type.name));
180
+ const seen = /* @__PURE__ */ new Set();
181
+ allNodes.forEach(({ node, pos }) => {
182
+ const currentId = node.attrs[attributeName2];
183
+ if (currentId === null || seen.has(currentId)) {
184
+ tr2.setNodeMarkup(pos, void 0, {
185
+ ...node.attrs,
186
+ [attributeName2]: generateID2({ node, pos })
187
+ });
188
+ } else {
189
+ seen.add(currentId);
190
+ }
191
+ });
192
+ if (!tr2.steps.length) {
193
+ return;
194
+ }
195
+ tr2.setStoredMarks(newState.tr.storedMarks);
196
+ tr2.setMeta("__uniqueIDTransaction", true);
197
+ tr2.setMeta("addToHistory", false);
198
+ return tr2;
199
+ }
200
+ return;
201
+ }
202
+ if (!hasDocChanges || filterTransactions) {
203
+ return;
204
+ }
205
+ const { tr } = newState;
206
+ const { attributeName, generateID } = this.options;
207
+ const transform = (0, import_core.combineTransactionSteps)(oldState.doc, transactions);
208
+ const { mapping } = transform;
209
+ const changes = (0, import_core.getChangedRanges)(transform);
210
+ changes.forEach(({ newRange }) => {
211
+ const newNodes = (0, import_core.findChildrenInRange)(newState.doc, newRange, (node) => {
212
+ return types.includes(node.type.name);
213
+ });
214
+ const newIds = newNodes.map(({ node }) => node.attrs[attributeName]).filter((id) => id !== null);
215
+ newNodes.forEach(({ node, pos }, i) => {
216
+ var _a;
217
+ const id = (_a = tr.doc.nodeAt(pos)) == null ? void 0 : _a.attrs[attributeName];
218
+ if (id === null) {
219
+ tr.setNodeMarkup(pos, void 0, {
220
+ ...node.attrs,
221
+ [attributeName]: generateID({ node, pos })
222
+ });
223
+ return;
224
+ }
225
+ const nextNode = newNodes[i + 1];
226
+ if (nextNode && node.content.size === 0) {
227
+ const nextNodeInTr = tr.doc.nodeAt(nextNode.pos);
228
+ if ((nextNodeInTr == null ? void 0 : nextNodeInTr.attrs[attributeName]) && nextNodeInTr.attrs[attributeName] !== id) {
229
+ return;
230
+ }
231
+ tr.setNodeMarkup(nextNode.pos, void 0, {
232
+ ...nextNode.node.attrs,
233
+ [attributeName]: id
234
+ });
235
+ newIds[i + 1] = id;
236
+ const generatedId = generateID({ node, pos });
237
+ tr.setNodeMarkup(pos, void 0, {
238
+ ...node.attrs,
239
+ [attributeName]: generatedId
240
+ });
241
+ newIds[i] = generatedId;
242
+ return tr;
243
+ }
244
+ const duplicatedNewIds = findDuplicates(newIds);
245
+ const { deleted } = mapping.invert().mapResult(pos);
246
+ const newNode = deleted && duplicatedNewIds.includes(id);
247
+ if (newNode) {
248
+ tr.setNodeMarkup(pos, void 0, {
249
+ ...node.attrs,
250
+ [attributeName]: generateID({ node, pos })
251
+ });
252
+ }
253
+ });
254
+ });
255
+ if (!tr.steps.length) {
256
+ return;
257
+ }
258
+ tr.setStoredMarks(newState.tr.storedMarks);
259
+ tr.setMeta("__uniqueIDTransaction", true);
260
+ return tr;
261
+ },
262
+ // we register a global drag handler to track the current drag source element
263
+ view(view) {
264
+ const handleDragstart = (event) => {
265
+ var _a;
266
+ dragSourceElement = ((_a = view.dom.parentElement) == null ? void 0 : _a.contains(event.target)) ? view.dom.parentElement : null;
267
+ };
268
+ window.addEventListener("dragstart", handleDragstart);
269
+ return {
270
+ destroy() {
271
+ window.removeEventListener("dragstart", handleDragstart);
272
+ }
273
+ };
274
+ },
275
+ props: {
276
+ // `handleDOMEvents` is called before `transformPasted`
277
+ // so we can do some checks before
278
+ handleDOMEvents: {
279
+ // only create new ids for dropped content
280
+ // or dropped content while holding `alt`
281
+ // or content is dragged from another editor
282
+ drop: (view, event) => {
283
+ var _a, _b;
284
+ if (dragSourceElement !== view.dom.parentElement || ((_a = event.dataTransfer) == null ? void 0 : _a.effectAllowed) === "copyMove" || ((_b = event.dataTransfer) == null ? void 0 : _b.effectAllowed) === "copy") {
285
+ dragSourceElement = null;
286
+ transformPasted = true;
287
+ }
288
+ return false;
289
+ },
290
+ // always create new ids on pasted content
291
+ paste: () => {
292
+ transformPasted = true;
293
+ return false;
294
+ }
295
+ },
296
+ // we’ll remove ids for every pasted node
297
+ // so we can create a new one within `appendTransaction`
298
+ transformPasted: (slice) => {
299
+ if (!transformPasted) {
300
+ return slice;
301
+ }
302
+ const { attributeName } = this.options;
303
+ const removeId = (fragment) => {
304
+ const list = [];
305
+ fragment.forEach((node) => {
306
+ if (node.isText) {
307
+ list.push(node);
308
+ return;
309
+ }
310
+ if (!types.includes(node.type.name)) {
311
+ list.push(node.copy(removeId(node.content)));
312
+ return;
313
+ }
314
+ const nodeWithoutId = node.type.create(
315
+ {
316
+ ...node.attrs,
317
+ [attributeName]: null
318
+ },
319
+ removeId(node.content),
320
+ node.marks
321
+ );
322
+ list.push(nodeWithoutId);
323
+ });
324
+ return import_model.Fragment.from(list);
325
+ };
326
+ transformPasted = false;
327
+ return new import_model.Slice(removeId(slice.content), slice.openStart, slice.openEnd);
328
+ }
329
+ }
330
+ })
331
+ ];
332
+ }
333
+ });
334
+
335
+ // src/generate-unique-ids.ts
336
+ var import_core2 = require("@tiptap/core");
337
+ var import_model2 = require("@tiptap/pm/model");
338
+ var import_state2 = require("@tiptap/pm/state");
339
+ function generateUniqueIds(doc, extensions) {
340
+ const uniqueIDExtension = extensions.find((ext) => ext.name === "uniqueID");
341
+ if (!uniqueIDExtension) {
342
+ throw new Error("UniqueID extension not found in the extensions array");
343
+ }
344
+ const schema = (0, import_core2.getSchema)([...extensions.filter((ext) => ext.name !== "uniqueID"), uniqueIDExtension]);
345
+ const { types: configuredTypes, attributeName, generateID } = uniqueIDExtension.options;
346
+ const types = configuredTypes === "all" ? Object.keys(schema.nodes).filter((type) => type !== "doc" && type !== "text") : configuredTypes;
347
+ const contentNode = import_model2.Node.fromJSON(schema, doc);
348
+ const nodesWithoutId = (0, import_core2.findChildren)(contentNode, (node) => {
349
+ return !node.attrs[attributeName] && types.includes(node.type.name);
350
+ });
351
+ let tr = import_state2.EditorState.create({
352
+ doc: contentNode
353
+ }).tr;
354
+ for (const { node, pos } of nodesWithoutId) {
355
+ tr = tr.setNodeAttribute(pos, attributeName, generateID({ node, pos }));
356
+ }
357
+ return tr.doc.toJSON();
358
+ }
359
+
360
+ // src/index.ts
361
+ var index_default = UniqueID;
362
+ // Annotate the CommonJS export names for ESM import in node:
363
+ 0 && (module.exports = {
364
+ UniqueID,
365
+ generateUniqueIds
366
+ });
367
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/index.ts","../src/unique-id.ts","../src/helpers/findDuplicates.ts","../src/generate-unique-ids.ts"],"sourcesContent":["import { UniqueID } from './unique-id.js'\n\nexport * from './generate-unique-ids.js'\nexport * from './unique-id.js'\n\nexport default UniqueID\n","import {\n type Extensions,\n combineTransactionSteps,\n Extension,\n findChildren,\n findChildrenInRange,\n getChangedRanges,\n splitExtensions,\n} from '@tiptap/core'\nimport type { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Fragment, Slice } from '@tiptap/pm/model'\nimport type { Transaction } from '@tiptap/pm/state'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { v4 as uuidv4 } from 'uuid'\n\nimport { findDuplicates } from './helpers/findDuplicates.js'\n\nexport type UniqueIDGenerationContext = {\n node: ProseMirrorNode\n pos: number\n}\n\nexport interface UniqueIDOptions {\n /**\n * The name of the attribute to add the unique ID to.\n * @default \"id\"\n */\n attributeName: string\n /**\n * The types of nodes to add unique IDs to.\n * Use `\"all\"` to add IDs to every node type except `doc` and `text`.\n * @default []\n */\n types: string[] | 'all'\n /**\n * The function that generates the unique ID. By default, a UUID v4 is\n * generated. However, you can provide your own function to generate the\n * unique ID based on the node type and the position.\n */\n generateID: (ctx: UniqueIDGenerationContext) => any\n /**\n * Ignore some mutations, for example applied from other users through the collaboration plugin.\n *\n * @default null\n */\n filterTransaction: ((transaction: Transaction) => boolean) | null\n /**\n * Whether to update the document by adding unique IDs to the nodes. Set this\n * property to `false` if the document is in `readonly` mode, is immutable, or\n * you don't want it to be modified.\n *\n * @default true\n */\n updateDocument: boolean\n}\n\nconst resolveTypes = (types: UniqueIDOptions['types'], extensions: Extensions): string[] => {\n if (types !== 'all') {\n return types\n }\n\n const { nodeExtensions } = splitExtensions(extensions)\n\n return nodeExtensions.map(extension => extension.name).filter(type => type !== 'doc' && type !== 'text')\n}\n\nexport const UniqueID = Extension.create<UniqueIDOptions>({\n name: 'uniqueID',\n\n // we’ll set a very high priority to make sure this runs first\n // and is compatible with `appendTransaction` hooks of other extensions\n priority: 10000,\n\n addOptions() {\n return {\n attributeName: 'id',\n types: [],\n generateID: () => uuidv4(),\n filterTransaction: null,\n updateDocument: true,\n }\n },\n\n /**\n * Extension storage for coordination between `addProseMirrorPlugins` and `appendTransaction`.\n * `needsInitialIdGeneration` is set to `true` when the Collaboration extension is\n * detected but no provider is available in its options, deferring ID creation\n * to the first `y-sync$` transaction.\n */\n addStorage() {\n return {\n needsInitialIdGeneration: false,\n }\n },\n\n addGlobalAttributes() {\n const types = resolveTypes(this.options.types, this.extensions)\n\n return [\n {\n types,\n attributes: {\n [this.options.attributeName]: {\n default: null,\n parseHTML: element => element.getAttribute(`data-${this.options.attributeName}`),\n renderHTML: attributes => {\n if (!attributes[this.options.attributeName]) {\n return {}\n }\n\n return {\n [`data-${this.options.attributeName}`]: attributes[this.options.attributeName],\n }\n },\n },\n },\n },\n ]\n },\n\n // check initial content for missing ids\n onCreate() {\n if (!this.options.updateDocument) {\n return\n }\n\n const collaboration = this.editor.extensionManager.extensions.find(ext => ext.name === 'collaboration')\n const collaborationCaret = this.editor.extensionManager.extensions.find(ext => ext.name === 'collaborationCaret')\n\n const collabExtensions = [collaboration, collaborationCaret].filter(Boolean)\n const collab = collabExtensions.find(ext => ext?.options?.provider)\n const provider = collab?.options?.provider\n\n const createIds = () => {\n const { view, state } = this.editor\n const { tr, doc } = state\n const types = resolveTypes(this.options.types, this.editor.extensionManager.extensions)\n const { attributeName, generateID } = this.options\n const nodesWithoutId = findChildren(doc, node => {\n return types.includes(node.type.name) && node.attrs[attributeName] === null\n })\n\n nodesWithoutId.forEach(({ node, pos }) => {\n tr.setNodeMarkup(pos, undefined, {\n ...node.attrs,\n [attributeName]: generateID({ node, pos }),\n })\n })\n\n tr.setMeta('addToHistory', false)\n\n view.dispatch(tr)\n\n if (provider) {\n provider.off('synced', createIds)\n }\n }\n\n /**\n * We need to handle collaboration a bit different here\n * because we can't automatically add IDs when the provider is not yet synced\n * otherwise we end up with empty paragraphs\n */\n if (collaboration) {\n if (provider) {\n provider.on('synced', createIds)\n }\n // When collaboration is present but no provider is in extension options,\n // needsInitialIdGeneration was already set in addProseMirrorPlugins\n // (which runs synchronously during editor construction, before any\n // y-sync$ transaction can arrive).\n } else {\n return createIds()\n }\n },\n\n addProseMirrorPlugins() {\n if (!this.options.updateDocument) {\n return []\n }\n\n // Capture storage via closure so appendTransaction can access `needsInitialIdGeneration`.\n // `extensionManager.extensions` returns different objects than `this` due to\n // Tiptap's child-extension flattening, so we capture the reference directly.\n const extensionStorage = this.storage\n\n // Detect collaboration early — before any y-sync$ transaction can arrive.\n // onCreate runs on a deferred setTimeout(0), so a y-sync$ transaction could\n // be applied before it. Setting the flag here (synchronous during editor\n // construction) ensures the first y-sync$ is always handled.\n const collaboration = this.editor.extensionManager.extensions.find(ext => ext.name === 'collaboration')\n const collaborationCaret = this.editor.extensionManager.extensions.find(ext => ext.name === 'collaborationCaret')\n const collabExtensions = [collaboration, collaborationCaret].filter(Boolean)\n const collabWithProvider = collabExtensions.find(ext => ext?.options?.provider)\n\n if (collaboration && !collabWithProvider) {\n extensionStorage.needsInitialIdGeneration = true\n }\n\n let dragSourceElement: Element | null = null\n let transformPasted = false\n const types = resolveTypes(this.options.types, this.editor.extensionManager.extensions)\n\n return [\n new Plugin({\n key: new PluginKey('uniqueID'),\n\n appendTransaction: (transactions, oldState, newState) => {\n const hasDocChanges =\n transactions.some(transaction => transaction.docChanged) && !oldState.doc.eq(newState.doc)\n const filterTransactions =\n this.options.filterTransaction && transactions.some(tr => !this.options.filterTransaction?.(tr))\n\n const isCollabTransaction = transactions.find(tr => tr.getMeta('y-sync$'))\n\n if (isCollabTransaction) {\n if (extensionStorage.needsInitialIdGeneration) {\n extensionStorage.needsInitialIdGeneration = false\n\n // Run full-document ID creation after the first Yjs sync.\n // Use a seen-set so only the second+ occurrence of a duplicated\n // ID is regenerated, preserving one existing ID per value.\n const { tr } = newState\n const { attributeName, generateID } = this.options\n const allNodes = findChildren(newState.doc, node => types.includes(node.type.name))\n const seen = new Set<string>()\n\n allNodes.forEach(({ node, pos }) => {\n const currentId = node.attrs[attributeName]\n\n if (currentId === null || seen.has(currentId)) {\n tr.setNodeMarkup(pos, undefined, {\n ...node.attrs,\n [attributeName]: generateID({ node, pos }),\n })\n } else {\n seen.add(currentId)\n }\n })\n\n if (!tr.steps.length) {\n return\n }\n\n // Restore stored marks since setNodeMarkup resets them\n tr.setStoredMarks(newState.tr.storedMarks)\n // Mark this transaction as coming from UniqueID to prevent\n // infinite loops with other extensions (e.g., TrailingNode)\n tr.setMeta('__uniqueIDTransaction', true)\n tr.setMeta('addToHistory', false)\n return tr\n }\n\n return\n }\n\n if (!hasDocChanges || filterTransactions) {\n return\n }\n\n const { tr } = newState\n\n const { attributeName, generateID } = this.options\n const transform = combineTransactionSteps(oldState.doc, transactions as Transaction[])\n const { mapping } = transform\n\n // get changed ranges based on the old state\n const changes = getChangedRanges(transform)\n\n changes.forEach(({ newRange }) => {\n const newNodes = findChildrenInRange(newState.doc, newRange, node => {\n return types.includes(node.type.name)\n })\n\n const newIds = newNodes.map(({ node }) => node.attrs[attributeName]).filter(id => id !== null)\n\n newNodes.forEach(({ node, pos }, i) => {\n // instead of checking `node.attrs[attributeName]` directly\n // we look at the current state of the node within `tr.doc`.\n // this helps to prevent adding new ids to the same node\n // if the node changed multiple times within one transaction\n const id = tr.doc.nodeAt(pos)?.attrs[attributeName]\n\n if (id === null) {\n tr.setNodeMarkup(pos, undefined, {\n ...node.attrs,\n [attributeName]: generateID({ node, pos }),\n })\n\n return\n }\n\n const nextNode = newNodes[i + 1]\n\n if (nextNode && node.content.size === 0) {\n const nextNodeInTr = tr.doc.nodeAt(nextNode.pos)\n if (nextNodeInTr?.attrs[attributeName] && nextNodeInTr.attrs[attributeName] !== id) {\n return\n }\n\n tr.setNodeMarkup(nextNode.pos, undefined, {\n ...nextNode.node.attrs,\n [attributeName]: id,\n })\n newIds[i + 1] = id\n\n const generatedId = generateID({ node, pos })\n\n tr.setNodeMarkup(pos, undefined, {\n ...node.attrs,\n [attributeName]: generatedId,\n })\n newIds[i] = generatedId\n\n return tr\n }\n\n const duplicatedNewIds = findDuplicates(newIds)\n\n // check if the node doesn’t exist in the old state\n const { deleted } = mapping.invert().mapResult(pos)\n\n const newNode = deleted && duplicatedNewIds.includes(id)\n\n if (newNode) {\n tr.setNodeMarkup(pos, undefined, {\n ...node.attrs,\n [attributeName]: generateID({ node, pos }),\n })\n }\n })\n })\n\n if (!tr.steps.length) {\n return\n }\n\n // `tr.setNodeMarkup` resets the stored marks\n // so we'll restore them if they exist\n tr.setStoredMarks(newState.tr.storedMarks)\n\n // Mark this transaction as coming from UniqueID\n // to prevent infinite loops with other extensions (e.g., TrailingNode)\n tr.setMeta('__uniqueIDTransaction', true)\n\n return tr\n },\n\n // we register a global drag handler to track the current drag source element\n view(view) {\n const handleDragstart = (event: DragEvent) => {\n dragSourceElement = view.dom.parentElement?.contains(event.target as Element)\n ? view.dom.parentElement\n : null\n }\n\n window.addEventListener('dragstart', handleDragstart)\n\n return {\n destroy() {\n window.removeEventListener('dragstart', handleDragstart)\n },\n }\n },\n\n props: {\n // `handleDOMEvents` is called before `transformPasted`\n // so we can do some checks before\n handleDOMEvents: {\n // only create new ids for dropped content\n // or dropped content while holding `alt`\n // or content is dragged from another editor\n drop: (view, event) => {\n if (\n dragSourceElement !== view.dom.parentElement ||\n event.dataTransfer?.effectAllowed === 'copyMove' ||\n event.dataTransfer?.effectAllowed === 'copy'\n ) {\n dragSourceElement = null\n transformPasted = true\n }\n\n return false\n },\n // always create new ids on pasted content\n paste: () => {\n transformPasted = true\n\n return false\n },\n },\n\n // we’ll remove ids for every pasted node\n // so we can create a new one within `appendTransaction`\n transformPasted: slice => {\n if (!transformPasted) {\n return slice\n }\n\n const { attributeName } = this.options\n const removeId = (fragment: Fragment): Fragment => {\n const list: ProseMirrorNode[] = []\n\n fragment.forEach(node => {\n // don’t touch text nodes\n if (node.isText) {\n list.push(node)\n\n return\n }\n\n // check for any other child nodes\n if (!types.includes(node.type.name)) {\n list.push(node.copy(removeId(node.content)))\n\n return\n }\n\n // remove id\n const nodeWithoutId = node.type.create(\n {\n ...node.attrs,\n [attributeName]: null,\n },\n removeId(node.content),\n node.marks,\n )\n\n list.push(nodeWithoutId)\n })\n\n return Fragment.from(list)\n }\n\n // reset check\n transformPasted = false\n\n return new Slice(removeId(slice.content), slice.openStart, slice.openEnd)\n },\n },\n }),\n ]\n },\n})\n","/**\n * Returns a list of duplicated items within an array.\n */\nexport function findDuplicates(items: any[]): any[] {\n const seen = new Set()\n const duplicates = new Set<any>()\n\n items.forEach(item => {\n if (seen.has(item)) {\n duplicates.add(item)\n } else {\n seen.add(item)\n }\n })\n\n return Array.from(duplicates)\n}\n","import type { Extensions, JSONContent } from '@tiptap/core'\nimport { findChildren, getSchema } from '@tiptap/core'\nimport { Node } from '@tiptap/pm/model'\nimport { EditorState } from '@tiptap/pm/state'\n\nimport type { UniqueID } from './unique-id.js'\n\n/**\n * Creates a new document with unique IDs added to the nodes. Does the same\n * thing as the UniqueID extension, but without the need to create an `Editor`\n * instance. This lets you add unique IDs to the document in the server.\n *\n * When you call it, include the `UniqueID` extension in the `extensions` array.\n * The configuration from the `UniqueID` extension will be picked up\n * automatically, including its configuration options like `types` and\n * `attributeName`.\n *\n * @see `UniqueID` extension for more information.\n *\n * @throws {Error} If the `UniqueID` extension is not found in the extensions array.\n *\n * @example\n * const doc = {\n * type: 'doc',\n * content: [\n * { type: 'paragraph', content: [{ type: 'text', text: 'Hello, world!' }] }\n * ]\n * }\n * const newDoc = addUniqueIds(doc, [StarterKit, UniqueID.configure({ types: ['paragraph', 'heading'] })])\n * console.log(newDoc)\n * // Result:\n * // {\n * // type: 'doc',\n * // content: [\n * // { type: 'paragraph', content: [{ type: 'text', text: 'Hello, world!' }], id: '123' }\n * // ]\n * // }\n *\n * @param doc - A Tiptap JSON document to add unique IDs to.\n * @param extensions - The extensions to use. Must include the `UniqueID` extension.\n * @returns The updated Tiptap JSON document, with the unique IDs added to the nodes.\n */\nexport function generateUniqueIds(doc: JSONContent, extensions: Extensions): JSONContent {\n // Find the UniqueID extension in the extensions array. If it's not found, throw an error.\n const uniqueIDExtension = extensions.find(ext => ext.name === 'uniqueID') as typeof UniqueID | undefined\n if (!uniqueIDExtension) {\n throw new Error('UniqueID extension not found in the extensions array')\n }\n // Convert the JSON content to a ProseMirror node\n const schema = getSchema([...extensions.filter(ext => ext.name !== 'uniqueID'), uniqueIDExtension])\n const { types: configuredTypes, attributeName, generateID } = uniqueIDExtension.options\n const types =\n configuredTypes === 'all'\n ? Object.keys(schema.nodes).filter(type => type !== 'doc' && type !== 'text')\n : configuredTypes\n const contentNode = Node.fromJSON(schema, doc)\n\n // Find nodes that don't have a unique ID\n const nodesWithoutId = findChildren(contentNode, node => {\n return !node.attrs[attributeName] && types.includes(node.type.name)\n })\n\n // Edit the document to add unique IDs to the nodes that don't have a unique ID\n let tr = EditorState.create({\n doc: contentNode,\n }).tr\n // eslint-disable-next-line no-restricted-syntax\n for (const { node, pos } of nodesWithoutId) {\n tr = tr.setNodeAttribute(p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K,OAAO,KAAK,EAAE,OAAO,UAAQ,SAAS,SAAS,SAAS,MAAM,IAC1E;AACN,QAAM,cAAc,mBAAK,SAAS,QAAQ,GAAG;AAG7C,QAAM,qBAAiB,2BAAa,aAAa,UAAQ;AACvD,WAAO,CAAC,KAAK,MAAM,aAAa,KAAK,MAAM,SAAS,KAAK,KAAK,IAAI;AAAA,EACpE,CAAC;AAGD,MAAI,KAAK,0BAAY,OAAO;AAAA,IAC1B,KAAK;AAAA,EACP,CAAC,EAAE;AAEH,aAAW,EAAE,MAAM,IAAI,KAAK,gBAAgB;AAC1C,SAAK,GAAG,iBAAiB,KAAK,eAAe,WAAW,EAAE,MAAM,IAAI,CAAC,CAAC;AAAA,EACxE;AAGA,SAAO,GAAG,IAAI,OAAO;AACvB;;;AHpEA,IAAO,gBAAQ;","names":["uuidv4","_a","tr","attributeName","generateID","import_core","import_model","import_state"]}
@@ -0,0 +1,81 @@
1
+ import { Extension, JSONContent, Extensions } from '@tiptap/core';
2
+ import { Node } from '@tiptap/pm/model';
3
+ import { Transaction } from '@tiptap/pm/state';
4
+
5
+ type UniqueIDGenerationContext = {
6
+ node: Node;
7
+ pos: number;
8
+ };
9
+ interface UniqueIDOptions {
10
+ /**
11
+ * The name of the attribute to add the unique ID to.
12
+ * @default "id"
13
+ */
14
+ attributeName: string;
15
+ /**
16
+ * The types of nodes to add unique IDs to.
17
+ * Use `"all"` to add IDs to every node type except `doc` and `text`.
18
+ * @default []
19
+ */
20
+ types: string[] | 'all';
21
+ /**
22
+ * The function that generates the unique ID. By default, a UUID v4 is
23
+ * generated. However, you can provide your own function to generate the
24
+ * unique ID based on the node type and the position.
25
+ */
26
+ generateID: (ctx: UniqueIDGenerationContext) => any;
27
+ /**
28
+ * Ignore some mutations, for example applied from other users through the collaboration plugin.
29
+ *
30
+ * @default null
31
+ */
32
+ filterTransaction: ((transaction: Transaction) => boolean) | null;
33
+ /**
34
+ * Whether to update the document by adding unique IDs to the nodes. Set this
35
+ * property to `false` if the document is in `readonly` mode, is immutable, or
36
+ * you don't want it to be modified.
37
+ *
38
+ * @default true
39
+ */
40
+ updateDocument: boolean;
41
+ }
42
+ declare const UniqueID: Extension<UniqueIDOptions, any>;
43
+
44
+ /**
45
+ * Creates a new document with unique IDs added to the nodes. Does the same
46
+ * thing as the UniqueID extension, but without the need to create an `Editor`
47
+ * instance. This lets you add unique IDs to the document in the server.
48
+ *
49
+ * When you call it, include the `UniqueID` extension in the `extensions` array.
50
+ * The configuration from the `UniqueID` extension will be picked up
51
+ * automatically, including its configuration options like `types` and
52
+ * `attributeName`.
53
+ *
54
+ * @see `UniqueID` extension for more information.
55
+ *
56
+ * @throws {Error} If the `UniqueID` extension is not found in the extensions array.
57
+ *
58
+ * @example
59
+ * const doc = {
60
+ * type: 'doc',
61
+ * content: [
62
+ * { type: 'paragraph', content: [{ type: 'text', text: 'Hello, world!' }] }
63
+ * ]
64
+ * }
65
+ * const newDoc = addUniqueIds(doc, [StarterKit, UniqueID.configure({ types: ['paragraph', 'heading'] })])
66
+ * console.log(newDoc)
67
+ * // Result:
68
+ * // {
69
+ * // type: 'doc',
70
+ * // content: [
71
+ * // { type: 'paragraph', content: [{ type: 'text', text: 'Hello, world!' }], id: '123' }
72
+ * // ]
73
+ * // }
74
+ *
75
+ * @param doc - A Tiptap JSON document to add unique IDs to.
76
+ * @param extensions - The extensions to use. Must include the `UniqueID` extension.
77
+ * @returns The updated Tiptap JSON document, with the unique IDs added to the nodes.
78
+ */
79
+ declare function generateUniqueIds(doc: JSONContent, extensions: Extensions): JSONContent;
80
+
81
+ export { UniqueID, type UniqueIDGenerationContext, type UniqueIDOptions, UniqueID as default, generateUniqueIds };
@@ -0,0 +1,81 @@
1
+ import { Extension, JSONContent, Extensions } from '@tiptap/core';
2
+ import { Node } from '@tiptap/pm/model';
3
+ import { Transaction } from '@tiptap/pm/state';
4
+
5
+ type UniqueIDGenerationContext = {
6
+ node: Node;
7
+ pos: number;
8
+ };
9
+ interface UniqueIDOptions {
10
+ /**
11
+ * The name of the attribute to add the unique ID to.
12
+ * @default "id"
13
+ */
14
+ attributeName: string;
15
+ /**
16
+ * The types of nodes to add unique IDs to.
17
+ * Use `"all"` to add IDs to every node type except `doc` and `text`.
18
+ * @default []
19
+ */
20
+ types: string[] | 'all';
21
+ /**
22
+ * The function that generates the unique ID. By default, a UUID v4 is
23
+ * generated. However, you can provide your own function to generate the
24
+ * unique ID based on the node type and the position.
25
+ */
26
+ generateID: (ctx: UniqueIDGenerationContext) => any;
27
+ /**
28
+ * Ignore some mutations, for example applied from other users through the collaboration plugin.
29
+ *
30
+ * @default null
31
+ */
32
+ filterTransaction: ((transaction: Transaction) => boolean) | null;
33
+ /**
34
+ * Whether to update the document by adding unique IDs to the nodes. Set this
35
+ * property to `false` if the document is in `readonly` mode, is immutable, or
36
+ * you don't want it to be modified.
37
+ *
38
+ * @default true
39
+ */
40
+ updateDocument: boolean;
41
+ }
42
+ declare const UniqueID: Extension<UniqueIDOptions, any>;
43
+
44
+ /**
45
+ * Creates a new document with unique IDs added to the nodes. Does the same
46
+ * thing as the UniqueID extension, but without the need to create an `Editor`
47
+ * instance. This lets you add unique IDs to the document in the server.
48
+ *
49
+ * When you call it, include the `UniqueID` extension in the `extensions` array.
50
+ * The configuration from the `UniqueID` extension will be picked up
51
+ * automatically, including its configuration options like `types` and
52
+ * `attributeName`.
53
+ *
54
+ * @see `UniqueID` extension for more information.
55
+ *
56
+ * @throws {Error} If the `UniqueID` extension is not found in the extensions array.
57
+ *
58
+ * @example
59
+ * const doc = {
60
+ * type: 'doc',
61
+ * content: [
62
+ * { type: 'paragraph', content: [{ type: 'text', text: 'Hello, world!' }] }
63
+ * ]
64
+ * }
65
+ * const newDoc = addUniqueIds(doc, [StarterKit, UniqueID.configure({ types: ['paragraph', 'heading'] })])
66
+ * console.log(newDoc)
67
+ * // Result:
68
+ * // {
69
+ * // type: 'doc',
70
+ * // content: [
71
+ * // { type: 'paragraph', content: [{ type: 'text', text: 'Hello, world!' }], id: '123' }
72
+ * // ]
73
+ * // }
74
+ *
75
+ * @param doc - A Tiptap JSON document to add unique IDs to.
76
+ * @param extensions - The extensions to use. Must include the `UniqueID` extension.
77
+ * @returns The updated Tiptap JSON document, with the unique IDs added to the nodes.
78
+ */
79
+ declare function generateUniqueIds(doc: JSONContent, extensions: Extensions): JSONContent;
80
+
81
+ export { UniqueID, type UniqueIDGenerationContext, type UniqueIDOptions, UniqueID as default, generateUniqueIds };
package/dist/index.js ADDED
@@ -0,0 +1,346 @@
1
+ // src/unique-id.ts
2
+ import {
3
+ combineTransactionSteps,
4
+ Extension,
5
+ findChildren,
6
+ findChildrenInRange,
7
+ getChangedRanges,
8
+ splitExtensions
9
+ } from "@tiptap/core";
10
+ import { Fragment, Slice } from "@tiptap/pm/model";
11
+ import { Plugin, PluginKey } from "@tiptap/pm/state";
12
+ import { v4 as uuidv4 } from "uuid";
13
+
14
+ // src/helpers/findDuplicates.ts
15
+ function findDuplicates(items) {
16
+ const seen = /* @__PURE__ */ new Set();
17
+ const duplicates = /* @__PURE__ */ new Set();
18
+ items.forEach((item) => {
19
+ if (seen.has(item)) {
20
+ duplicates.add(item);
21
+ } else {
22
+ seen.add(item);
23
+ }
24
+ });
25
+ return Array.from(duplicates);
26
+ }
27
+
28
+ // src/unique-id.ts
29
+ var resolveTypes = (types, extensions) => {
30
+ if (types !== "all") {
31
+ return types;
32
+ }
33
+ const { nodeExtensions } = splitExtensions(extensions);
34
+ return nodeExtensions.map((extension) => extension.name).filter((type) => type !== "doc" && type !== "text");
35
+ };
36
+ var UniqueID = Extension.create({
37
+ name: "uniqueID",
38
+ // we’ll set a very high priority to make sure this runs first
39
+ // and is compatible with `appendTransaction` hooks of other extensions
40
+ priority: 1e4,
41
+ addOptions() {
42
+ return {
43
+ attributeName: "id",
44
+ types: [],
45
+ generateID: () => uuidv4(),
46
+ filterTransaction: null,
47
+ updateDocument: true
48
+ };
49
+ },
50
+ /**
51
+ * Extension storage for coordination between `addProseMirrorPlugins` and `appendTransaction`.
52
+ * `needsInitialIdGeneration` is set to `true` when the Collaboration extension is
53
+ * detected but no provider is available in its options, deferring ID creation
54
+ * to the first `y-sync$` transaction.
55
+ */
56
+ addStorage() {
57
+ return {
58
+ needsInitialIdGeneration: false
59
+ };
60
+ },
61
+ addGlobalAttributes() {
62
+ const types = resolveTypes(this.options.types, this.extensions);
63
+ return [
64
+ {
65
+ types,
66
+ attributes: {
67
+ [this.options.attributeName]: {
68
+ default: null,
69
+ parseHTML: (element) => element.getAttribute(`data-${this.options.attributeName}`),
70
+ renderHTML: (attributes) => {
71
+ if (!attributes[this.options.attributeName]) {
72
+ return {};
73
+ }
74
+ return {
75
+ [`data-${this.options.attributeName}`]: attributes[this.options.attributeName]
76
+ };
77
+ }
78
+ }
79
+ }
80
+ }
81
+ ];
82
+ },
83
+ // check initial content for missing ids
84
+ onCreate() {
85
+ var _a;
86
+ if (!this.options.updateDocument) {
87
+ return;
88
+ }
89
+ const collaboration = this.editor.extensionManager.extensions.find((ext) => ext.name === "collaboration");
90
+ const collaborationCaret = this.editor.extensionManager.extensions.find((ext) => ext.name === "collaborationCaret");
91
+ const collabExtensions = [collaboration, collaborationCaret].filter(Boolean);
92
+ const collab = collabExtensions.find((ext) => {
93
+ var _a2;
94
+ return (_a2 = ext == null ? void 0 : ext.options) == null ? void 0 : _a2.provider;
95
+ });
96
+ const provider = (_a = collab == null ? void 0 : collab.options) == null ? void 0 : _a.provider;
97
+ const createIds = () => {
98
+ const { view, state } = this.editor;
99
+ const { tr, doc } = state;
100
+ const types = resolveTypes(this.options.types, this.editor.extensionManager.extensions);
101
+ const { attributeName, generateID } = this.options;
102
+ const nodesWithoutId = findChildren(doc, (node) => {
103
+ return types.includes(node.type.name) && node.attrs[attributeName] === null;
104
+ });
105
+ nodesWithoutId.forEach(({ node, pos }) => {
106
+ tr.setNodeMarkup(pos, void 0, {
107
+ ...node.attrs,
108
+ [attributeName]: generateID({ node, pos })
109
+ });
110
+ });
111
+ tr.setMeta("addToHistory", false);
112
+ view.dispatch(tr);
113
+ if (provider) {
114
+ provider.off("synced", createIds);
115
+ }
116
+ };
117
+ if (collaboration) {
118
+ if (provider) {
119
+ provider.on("synced", createIds);
120
+ }
121
+ } else {
122
+ return createIds();
123
+ }
124
+ },
125
+ addProseMirrorPlugins() {
126
+ if (!this.options.updateDocument) {
127
+ return [];
128
+ }
129
+ const extensionStorage = this.storage;
130
+ const collaboration = this.editor.extensionManager.extensions.find((ext) => ext.name === "collaboration");
131
+ const collaborationCaret = this.editor.extensionManager.extensions.find((ext) => ext.name === "collaborationCaret");
132
+ const collabExtensions = [collaboration, collaborationCaret].filter(Boolean);
133
+ const collabWithProvider = collabExtensions.find((ext) => {
134
+ var _a;
135
+ return (_a = ext == null ? void 0 : ext.options) == null ? void 0 : _a.provider;
136
+ });
137
+ if (collaboration && !collabWithProvider) {
138
+ extensionStorage.needsInitialIdGeneration = true;
139
+ }
140
+ let dragSourceElement = null;
141
+ let transformPasted = false;
142
+ const types = resolveTypes(this.options.types, this.editor.extensionManager.extensions);
143
+ return [
144
+ new Plugin({
145
+ key: new PluginKey("uniqueID"),
146
+ appendTransaction: (transactions, oldState, newState) => {
147
+ const hasDocChanges = transactions.some((transaction) => transaction.docChanged) && !oldState.doc.eq(newState.doc);
148
+ const filterTransactions = this.options.filterTransaction && transactions.some((tr2) => {
149
+ var _a, _b;
150
+ return !((_b = (_a = this.options).filterTransaction) == null ? void 0 : _b.call(_a, tr2));
151
+ });
152
+ const isCollabTransaction = transactions.find((tr2) => tr2.getMeta("y-sync$"));
153
+ if (isCollabTransaction) {
154
+ if (extensionStorage.needsInitialIdGeneration) {
155
+ extensionStorage.needsInitialIdGeneration = false;
156
+ const { tr: tr2 } = newState;
157
+ const { attributeName: attributeName2, generateID: generateID2 } = this.options;
158
+ const allNodes = findChildren(newState.doc, (node) => types.includes(node.type.name));
159
+ const seen = /* @__PURE__ */ new Set();
160
+ allNodes.forEach(({ node, pos }) => {
161
+ const currentId = node.attrs[attributeName2];
162
+ if (currentId === null || seen.has(currentId)) {
163
+ tr2.setNodeMarkup(pos, void 0, {
164
+ ...node.attrs,
165
+ [attributeName2]: generateID2({ node, pos })
166
+ });
167
+ } else {
168
+ seen.add(currentId);
169
+ }
170
+ });
171
+ if (!tr2.steps.length) {
172
+ return;
173
+ }
174
+ tr2.setStoredMarks(newState.tr.storedMarks);
175
+ tr2.setMeta("__uniqueIDTransaction", true);
176
+ tr2.setMeta("addToHistory", false);
177
+ return tr2;
178
+ }
179
+ return;
180
+ }
181
+ if (!hasDocChanges || filterTransactions) {
182
+ return;
183
+ }
184
+ const { tr } = newState;
185
+ const { attributeName, generateID } = this.options;
186
+ const transform = combineTransactionSteps(oldState.doc, transactions);
187
+ const { mapping } = transform;
188
+ const changes = getChangedRanges(transform);
189
+ changes.forEach(({ newRange }) => {
190
+ const newNodes = findChildrenInRange(newState.doc, newRange, (node) => {
191
+ return types.includes(node.type.name);
192
+ });
193
+ const newIds = newNodes.map(({ node }) => node.attrs[attributeName]).filter((id) => id !== null);
194
+ newNodes.forEach(({ node, pos }, i) => {
195
+ var _a;
196
+ const id = (_a = tr.doc.nodeAt(pos)) == null ? void 0 : _a.attrs[attributeName];
197
+ if (id === null) {
198
+ tr.setNodeMarkup(pos, void 0, {
199
+ ...node.attrs,
200
+ [attributeName]: generateID({ node, pos })
201
+ });
202
+ return;
203
+ }
204
+ const nextNode = newNodes[i + 1];
205
+ if (nextNode && node.content.size === 0) {
206
+ const nextNodeInTr = tr.doc.nodeAt(nextNode.pos);
207
+ if ((nextNodeInTr == null ? void 0 : nextNodeInTr.attrs[attributeName]) && nextNodeInTr.attrs[attributeName] !== id) {
208
+ return;
209
+ }
210
+ tr.setNodeMarkup(nextNode.pos, void 0, {
211
+ ...nextNode.node.attrs,
212
+ [attributeName]: id
213
+ });
214
+ newIds[i + 1] = id;
215
+ const generatedId = generateID({ node, pos });
216
+ tr.setNodeMarkup(pos, void 0, {
217
+ ...node.attrs,
218
+ [attributeName]: generatedId
219
+ });
220
+ newIds[i] = generatedId;
221
+ return tr;
222
+ }
223
+ const duplicatedNewIds = findDuplicates(newIds);
224
+ const { deleted } = mapping.invert().mapResult(pos);
225
+ const newNode = deleted && duplicatedNewIds.includes(id);
226
+ if (newNode) {
227
+ tr.setNodeMarkup(pos, void 0, {
228
+ ...node.attrs,
229
+ [attributeName]: generateID({ node, pos })
230
+ });
231
+ }
232
+ });
233
+ });
234
+ if (!tr.steps.length) {
235
+ return;
236
+ }
237
+ tr.setStoredMarks(newState.tr.storedMarks);
238
+ tr.setMeta("__uniqueIDTransaction", true);
239
+ return tr;
240
+ },
241
+ // we register a global drag handler to track the current drag source element
242
+ view(view) {
243
+ const handleDragstart = (event) => {
244
+ var _a;
245
+ dragSourceElement = ((_a = view.dom.parentElement) == null ? void 0 : _a.contains(event.target)) ? view.dom.parentElement : null;
246
+ };
247
+ window.addEventListener("dragstart", handleDragstart);
248
+ return {
249
+ destroy() {
250
+ window.removeEventListener("dragstart", handleDragstart);
251
+ }
252
+ };
253
+ },
254
+ props: {
255
+ // `handleDOMEvents` is called before `transformPasted`
256
+ // so we can do some checks before
257
+ handleDOMEvents: {
258
+ // only create new ids for dropped content
259
+ // or dropped content while holding `alt`
260
+ // or content is dragged from another editor
261
+ drop: (view, event) => {
262
+ var _a, _b;
263
+ if (dragSourceElement !== view.dom.parentElement || ((_a = event.dataTransfer) == null ? void 0 : _a.effectAllowed) === "copyMove" || ((_b = event.dataTransfer) == null ? void 0 : _b.effectAllowed) === "copy") {
264
+ dragSourceElement = null;
265
+ transformPasted = true;
266
+ }
267
+ return false;
268
+ },
269
+ // always create new ids on pasted content
270
+ paste: () => {
271
+ transformPasted = true;
272
+ return false;
273
+ }
274
+ },
275
+ // we’ll remove ids for every pasted node
276
+ // so we can create a new one within `appendTransaction`
277
+ transformPasted: (slice) => {
278
+ if (!transformPasted) {
279
+ return slice;
280
+ }
281
+ const { attributeName } = this.options;
282
+ const removeId = (fragment) => {
283
+ const list = [];
284
+ fragment.forEach((node) => {
285
+ if (node.isText) {
286
+ list.push(node);
287
+ return;
288
+ }
289
+ if (!types.includes(node.type.name)) {
290
+ list.push(node.copy(removeId(node.content)));
291
+ return;
292
+ }
293
+ const nodeWithoutId = node.type.create(
294
+ {
295
+ ...node.attrs,
296
+ [attributeName]: null
297
+ },
298
+ removeId(node.content),
299
+ node.marks
300
+ );
301
+ list.push(nodeWithoutId);
302
+ });
303
+ return Fragment.from(list);
304
+ };
305
+ transformPasted = false;
306
+ return new Slice(removeId(slice.content), slice.openStart, slice.openEnd);
307
+ }
308
+ }
309
+ })
310
+ ];
311
+ }
312
+ });
313
+
314
+ // src/generate-unique-ids.ts
315
+ import { findChildren as findChildren2, getSchema } from "@tiptap/core";
316
+ import { Node } from "@tiptap/pm/model";
317
+ import { EditorState } from "@tiptap/pm/state";
318
+ function generateUniqueIds(doc, extensions) {
319
+ const uniqueIDExtension = extensions.find((ext) => ext.name === "uniqueID");
320
+ if (!uniqueIDExtension) {
321
+ throw new Error("UniqueID extension not found in the extensions array");
322
+ }
323
+ const schema = getSchema([...extensions.filter((ext) => ext.name !== "uniqueID"), uniqueIDExtension]);
324
+ const { types: configuredTypes, attributeName, generateID } = uniqueIDExtension.options;
325
+ const types = configuredTypes === "all" ? Object.keys(schema.nodes).filter((type) => type !== "doc" && type !== "text") : configuredTypes;
326
+ const contentNode = Node.fromJSON(schema, doc);
327
+ const nodesWithoutId = findChildren2(contentNode, (node) => {
328
+ return !node.attrs[attributeName] && types.includes(node.type.name);
329
+ });
330
+ let tr = EditorState.create({
331
+ doc: contentNode
332
+ }).tr;
333
+ for (const { node, pos } of nodesWithoutId) {
334
+ tr = tr.setNodeAttribute(pos, attributeName, generateID({ node, pos }));
335
+ }
336
+ return tr.doc.toJSON();
337
+ }
338
+
339
+ // src/index.ts
340
+ var index_default = UniqueID;
341
+ export {
342
+ UniqueID,
343
+ index_default as default,
344
+ generateUniqueIds
345
+ };
346
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/unique-id.ts","../src/helpers/findDuplicates.ts","../src/generate-unique-ids.ts","../src/index.ts"],"sourcesContent":["import {\n type Extensions,\n combineTransactionSteps,\n Extension,\n findChildren,\n findChildrenInRange,\n getChangedRanges,\n splitExtensions,\n} from '@tiptap/core'\nimport type { Node as ProseMirrorNode } from '@tiptap/pm/model'\nimport { Fragment, Slice } from '@tiptap/pm/model'\nimport type { Transaction } from '@tiptap/pm/state'\nimport { Plugin, PluginKey } from '@tiptap/pm/state'\nimport { v4 as uuidv4 } from 'uuid'\n\nimport { findDuplicates } from './helpers/findDuplicates.js'\n\nexport type UniqueIDGenerationContext = {\n node: ProseMirrorNode\n pos: number\n}\n\nexport interface UniqueIDOptions {\n /**\n * The name of the attribute to add the unique ID to.\n * @default \"id\"\n */\n attributeName: string\n /**\n * The types of nodes to add unique IDs to.\n * Use `\"all\"` to add IDs to every node type except `doc` and `text`.\n * @default []\n */\n types: string[] | 'all'\n /**\n * The function that generates the unique ID. By default, a UUID v4 is\n * generated. However, you can provide your own function to generate the\n * unique ID based on the node type and the position.\n */\n generateID: (ctx: UniqueIDGenerationContext) => any\n /**\n * Ignore some mutations, for example applied from other users through the collaboration plugin.\n *\n * @default null\n */\n filterTransaction: ((transaction: Transaction) => boolean) | null\n /**\n * Whether to update the document by adding unique IDs to the nodes. Set this\n * property to `false` if the document is in `readonly` mode, is immutable, or\n * you don't want it to be modified.\n *\n * @default true\n */\n updateDocument: boolean\n}\n\nconst resolveTypes = (types: UniqueIDOptions['types'], extensions: Extensions): string[] => {\n if (types !== 'all') {\n return types\n }\n\n const { nodeExtensions } = splitExtensions(extensions)\n\n return nodeExtensions.map(extension => extension.name).filter(type => type !== 'doc' && type !== 'text')\n}\n\nexport const UniqueID = Extension.create<UniqueIDOptions>({\n name: 'uniqueID',\n\n // we’ll set a very high priority to make sure this runs first\n // and is compatible with `appendTransaction` hooks of other extensions\n priority: 10000,\n\n addOptions() {\n return {\n attributeName: 'id',\n types: [],\n generateID: () => uuidv4(),\n filterTransaction: null,\n updateDocument: true,\n }\n },\n\n /**\n * Extension storage for coordination between `addProseMirrorPlugins` and `appendTransaction`.\n * `needsInitialIdGeneration` is set to `true` when the Collaboration extension is\n * detected but no provider is available in its options, deferring ID creation\n * to the first `y-sync$` transaction.\n */\n addStorage() {\n return {\n needsInitialIdGeneration: false,\n }\n },\n\n addGlobalAttributes() {\n const types = resolveTypes(this.options.types, this.extensions)\n\n return [\n {\n types,\n attributes: {\n [this.options.attributeName]: {\n default: null,\n parseHTML: element => element.getAttribute(`data-${this.options.attributeName}`),\n renderHTML: attributes => {\n if (!attributes[this.options.attributeName]) {\n return {}\n }\n\n return {\n [`data-${this.options.attributeName}`]: attributes[this.options.attributeName],\n }\n },\n },\n },\n },\n ]\n },\n\n // check initial content for missing ids\n onCreate() {\n if (!this.options.updateDocument) {\n return\n }\n\n const collaboration = this.editor.extensionManager.extensions.find(ext => ext.name === 'collaboration')\n const collaborationCaret = this.editor.extensionManager.extensions.find(ext => ext.name === 'collaborationCaret')\n\n const collabExtensions = [collaboration, collaborationCaret].filter(Boolean)\n const collab = collabExtensions.find(ext => ext?.options?.provider)\n const provider = collab?.options?.provider\n\n const createIds = () => {\n const { view, state } = this.editor\n const { tr, doc } = state\n const types = resolveTypes(this.options.types, this.editor.extensionManager.extensions)\n const { attributeName, generateID } = this.options\n const nodesWithoutId = findChildren(doc, node => {\n return types.includes(node.type.name) && node.attrs[attributeName] === null\n })\n\n nodesWithoutId.forEach(({ node, pos }) => {\n tr.setNodeMarkup(pos, undefined, {\n ...node.attrs,\n [attributeName]: generateID({ node, pos }),\n })\n })\n\n tr.setMeta('addToHistory', false)\n\n view.dispatch(tr)\n\n if (provider) {\n provider.off('synced', createIds)\n }\n }\n\n /**\n * We need to handle collaboration a bit different here\n * because we can't automatically add IDs when the provider is not yet synced\n * otherwise we end up with empty paragraphs\n */\n if (collaboration) {\n if (provider) {\n provider.on('synced', createIds)\n }\n // When collaboration is present but no provider is in extension options,\n // needsInitialIdGeneration was already set in addProseMirrorPlugins\n // (which runs synchronously during editor construction, before any\n // y-sync$ transaction can arrive).\n } else {\n return createIds()\n }\n },\n\n addProseMirrorPlugins() {\n if (!this.options.updateDocument) {\n return []\n }\n\n // Capture storage via closure so appendTransaction can access `needsInitialIdGeneration`.\n // `extensionManager.extensions` returns different objects than `this` due to\n // Tiptap's child-extension flattening, so we capture the reference directly.\n const extensionStorage = this.storage\n\n // Detect collaboration early — before any y-sync$ transaction can arrive.\n // onCreate runs on a deferred setTimeout(0), so a y-sync$ transaction could\n // be applied before it. Setting the flag here (synchronous during editor\n // construction) ensures the first y-sync$ is always handled.\n const collaboration = this.editor.extensionManager.extensions.find(ext => ext.name === 'collaboration')\n const collaborationCaret = this.editor.extensionManager.extensions.find(ext => ext.name === 'collaborationCaret')\n const collabExtensions = [collaboration, collaborationCaret].filter(Boolean)\n const collabWithProvider = collabExtensions.find(ext => ext?.options?.provider)\n\n if (collaboration && !collabWithProvider) {\n extensionStorage.needsInitialIdGeneration = true\n }\n\n let dragSourceElement: Element | null = null\n let transformPasted = false\n const types = resolveTypes(this.options.types, this.editor.extensionManager.extensions)\n\n return [\n new Plugin({\n key: new PluginKey('uniqueID'),\n\n appendTransaction: (transactions, oldState, newState) => {\n const hasDocChanges =\n transactions.some(transaction => transaction.docChanged) && !oldState.doc.eq(newState.doc)\n const filterTransactions =\n this.options.filterTransaction && transactions.some(tr => !this.options.filterTransaction?.(tr))\n\n const isCollabTransaction = transactions.find(tr => tr.getMeta('y-sync$'))\n\n if (isCollabTransaction) {\n if (extensionStorage.needsInitialIdGeneration) {\n extensionStorage.needsInitialIdGeneration = false\n\n // Run full-document ID creation after the first Yjs sync.\n // Use a seen-set so only the second+ occurrence of a duplicated\n // ID is regenerated, preserving one existing ID per value.\n const { tr } = newState\n const { attributeName, generateID } = this.options\n const allNodes = findChildren(newState.doc, node => types.includes(node.type.name))\n const seen = new Set<string>()\n\n allNodes.forEach(({ node, pos }) => {\n const currentId = node.attrs[attributeName]\n\n if (currentId === null || seen.has(currentId)) {\n tr.setNodeMarkup(pos, undefined, {\n ...node.attrs,\n [attributeName]: generateID({ node, pos }),\n })\n } else {\n seen.add(currentId)\n }\n })\n\n if (!tr.steps.length) {\n return\n }\n\n // Restore stored marks since setNodeMarkup resets them\n tr.setStoredMarks(newState.tr.storedMarks)\n // Mark this transaction as coming from UniqueID to prevent\n // infinite loops with other extensions (e.g., TrailingNode)\n tr.setMeta('__uniqueIDTransaction', true)\n tr.setMeta('addToHistory', false)\n return tr\n }\n\n return\n }\n\n if (!hasDocChanges || filterTransactions) {\n return\n }\n\n const { tr } = newState\n\n const { attributeName, generateID } = this.options\n const transform = combineTransactionSteps(oldState.doc, transactions as Transaction[])\n const { mapping } = transform\n\n // get changed ranges based on the old state\n const changes = getChangedRanges(transform)\n\n changes.forEach(({ newRange }) => {\n const newNodes = findChildrenInRange(newState.doc, newRange, node => {\n return types.includes(node.type.name)\n })\n\n const newIds = newNodes.map(({ node }) => node.attrs[attributeName]).filter(id => id !== null)\n\n newNodes.forEach(({ node, pos }, i) => {\n // instead of checking `node.attrs[attributeName]` directly\n // we look at the current state of the node within `tr.doc`.\n // this helps to prevent adding new ids to the same node\n // if the node changed multiple times within one transaction\n const id = tr.doc.nodeAt(pos)?.attrs[attributeName]\n\n if (id === null) {\n tr.setNodeMarkup(pos, undefined, {\n ...node.attrs,\n [attributeName]: generateID({ node, pos }),\n })\n\n return\n }\n\n const nextNode = newNodes[i + 1]\n\n if (nextNode && node.content.size === 0) {\n const nextNodeInTr = tr.doc.nodeAt(nextNode.pos)\n if (nextNodeInTr?.attrs[attributeName] && nextNodeInTr.attrs[attributeName] !== id) {\n return\n }\n\n tr.setNodeMarkup(nextNode.pos, undefined, {\n ...nextNode.node.attrs,\n [attributeName]: id,\n })\n newIds[i + 1] = id\n\n const generatedId = generateID({ node, pos })\n\n tr.setNodeMarkup(pos, undefined, {\n ...node.attrs,\n [attributeName]: generatedId,\n })\n newIds[i] = generatedId\n\n return tr\n }\n\n const duplicatedNewIds = findDuplicates(newIds)\n\n // check if the node doesn’t exist in the old state\n const { deleted } = mapping.invert().mapResult(pos)\n\n const newNode = deleted && duplicatedNewIds.includes(id)\n\n if (newNode) {\n tr.setNodeMarkup(pos, undefined, {\n ...node.attrs,\n [attributeName]: generateID({ node, pos }),\n })\n }\n })\n })\n\n if (!tr.steps.length) {\n return\n }\n\n // `tr.setNodeMarkup` resets the stored marks\n // so we'll restore them if they exist\n tr.setStoredMarks(newState.tr.storedMarks)\n\n // Mark this transaction as coming from UniqueID\n // to prevent infinite loops with other extensions (e.g., TrailingNode)\n tr.setMeta('__uniqueIDTransaction', true)\n\n return tr\n },\n\n // we register a global drag handler to track the current drag source element\n view(view) {\n const handleDragstart = (event: DragEvent) => {\n dragSourceElement = view.dom.parentElement?.contains(event.target as Element)\n ? view.dom.parentElement\n : null\n }\n\n window.addEventListener('dragstart', handleDragstart)\n\n return {\n destroy() {\n window.removeEventListener('dragstart', handleDragstart)\n },\n }\n },\n\n props: {\n // `handleDOMEvents` is called before `transformPasted`\n // so we can do some checks before\n handleDOMEvents: {\n // only create new ids for dropped content\n // or dropped content while holding `alt`\n // or content is dragged from another editor\n drop: (view, event) => {\n if (\n dragSourceElement !== view.dom.parentElement ||\n event.dataTransfer?.effectAllowed === 'copyMove' ||\n event.dataTransfer?.effectAllowed === 'copy'\n ) {\n dragSourceElement = null\n transformPasted = true\n }\n\n return false\n },\n // always create new ids on pasted content\n paste: () => {\n transformPasted = true\n\n return false\n },\n },\n\n // we’ll remove ids for every pasted node\n // so we can create a new one within `appendTransaction`\n transformPasted: slice => {\n if (!transformPasted) {\n return slice\n }\n\n const { attributeName } = this.options\n const removeId = (fragment: Fragment): Fragment => {\n const list: ProseMirrorNode[] = []\n\n fragment.forEach(node => {\n // don’t touch text nodes\n if (node.isText) {\n list.push(node)\n\n return\n }\n\n // check for any other child nodes\n if (!types.includes(node.type.name)) {\n list.push(node.copy(removeId(node.content)))\n\n return\n }\n\n // remove id\n const nodeWithoutId = node.type.create(\n {\n ...node.attrs,\n [attributeName]: null,\n },\n removeId(node.content),\n node.marks,\n )\n\n list.push(nodeWithoutId)\n })\n\n return Fragment.from(list)\n }\n\n // reset check\n transformPasted = false\n\n return new Slice(removeId(slice.content), slice.openStart, slice.openEnd)\n },\n },\n }),\n ]\n },\n})\n","/**\n * Returns a list of duplicated items within an array.\n */\nexport function findDuplicates(items: any[]): any[] {\n const seen = new Set()\n const duplicates = new Set<any>()\n\n items.forEach(item => {\n if (seen.has(item)) {\n duplicates.add(item)\n } else {\n seen.add(item)\n }\n })\n\n return Array.from(duplicates)\n}\n","import type { Extensions, JSONContent } from '@tiptap/core'\nimport { findChildren, getSchema } from '@tiptap/core'\nimport { Node } from '@tiptap/pm/model'\nimport { EditorState } from '@tiptap/pm/state'\n\nimport type { UniqueID } from './unique-id.js'\n\n/**\n * Creates a new document with unique IDs added to the nodes. Does the same\n * thing as the UniqueID extension, but without the need to create an `Editor`\n * instance. This lets you add unique IDs to the document in the server.\n *\n * When you call it, include the `UniqueID` extension in the `extensions` array.\n * The configuration from the `UniqueID` extension will be picked up\n * automatically, including its configuration options like `types` and\n * `attributeName`.\n *\n * @see `UniqueID` extension for more information.\n *\n * @throws {Error} If the `UniqueID` extension is not found in the extensions array.\n *\n * @example\n * const doc = {\n * type: 'doc',\n * content: [\n * { type: 'paragraph', content: [{ type: 'text', text: 'Hello, world!' }] }\n * ]\n * }\n * const newDoc = addUniqueIds(doc, [StarterKit, UniqueID.configure({ types: ['paragraph', 'heading'] })])\n * console.log(newDoc)\n * // Result:\n * // {\n * // type: 'doc',\n * // content: [\n * // { type: 'paragraph', content: [{ type: 'text', text: 'Hello, world!' }], id: '123' }\n * // ]\n * // }\n *\n * @param doc - A Tiptap JSON document to add unique IDs to.\n * @param extensions - The extensions to use. Must include the `UniqueID` extension.\n * @returns The updated Tiptap JSON document, with the unique IDs added to the nodes.\n */\nexport function generateUniqueIds(doc: JSONContent, extensions: Extensions): JSONContent {\n // Find the UniqueID extension in the extensions array. If it's not found, throw an error.\n const uniqueIDExtension = extensions.find(ext => ext.name === 'uniqueID') as typeof UniqueID | undefined\n if (!uniqueIDExtension) {\n throw new Error('UniqueID extension not found in the extensions array')\n }\n // Convert the JSON content to a ProseMirror node\n const schema = getSchema([...extensions.filter(ext => ext.name !== 'uniqueID'), uniqueIDExtension])\n const { types: configuredTypes, attributeName, generateID } = uniqueIDExtension.options\n const types =\n configuredTypes === 'all'\n ? Object.keys(schema.nodes).filter(type => type !== 'doc' && type !== 'text')\n : configuredTypes\n const contentNode = Node.fromJSON(schema, doc)\n\n // Find nodes that don't have a unique ID\n const nodesWithoutId = findChildren(contentNode, node => {\n return !node.attrs[attributeName] && types.includes(node.type.name)\n })\n\n // Edit the document to add unique IDs to the nodes that don't have a unique ID\n let tr = EditorState.create({\n doc: contentNode,\n }).tr\n // eslint-disable-next-line no-restricted-syntax\n for (const { node, pos } of nodesWithoutId) {\n tr = tr.setNodeAttribute(pos, attributeName, generateID({ node, pos }))\n }\n\n // Return the updated document\n return tr.doc.toJSON()\n}\n","import { UniqueID } from './unique-id.js'\n\nexport * from './generate-unique-ids.js'\nexport * from './unique-id.js'\n\nexport default UniqueID\n"],"mappings":";AAAA;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,UAAU,aAAa;AAEhC,SAAS,QAAQ,iBAAiB;AAClC,SAAS,MAAM,cAAc;;;ACVtB,SAAS,eAAe,OAAqB;AAClD,QAAM,OAAO,oBAAI,IAAI;AACrB,QAAM,aAAa,oBAAI,IAAS;AAEhC,QAAM,QAAQ,UAAQ;AACpB,QAAI,KAAK,IAAI,IAAI,GAAG;AAClB,iBAAW,IAAI,IAAI;AAAA,IACrB,OAAO;AACL,WAAK,IAAI,IAAI;AAAA,IACf;AAAA,EACF,CAAC;AAED,SAAO,MAAM,KAAK,UAAU;AAC9B;;;ADwCA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AAQ;","names":["_a","tr","attributeName","generateID","findChildren"]}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tiptap/extension-unique-id",
3
3
  "description": "unique id extension for tiptap",
4
- "version": "3.20.3",
4
+ "version": "3.20.5",
5
5
  "homepage": "https://tiptap.dev/api/extensions/unique-id",
6
6
  "keywords": [
7
7
  "tiptap",
@@ -31,16 +31,16 @@
31
31
  "dist"
32
32
  ],
33
33
  "peerDependencies": {
34
- "@tiptap/core": "^3.20.3",
35
- "@tiptap/pm": "^3.20.3"
34
+ "@tiptap/core": "^3.20.5",
35
+ "@tiptap/pm": "^3.20.5"
36
36
  },
37
37
  "dependencies": {
38
38
  "uuid": "^10.0.0"
39
39
  },
40
40
  "devDependencies": {
41
41
  "@types/uuid": "^10.0.0",
42
- "@tiptap/core": "^3.20.3",
43
- "@tiptap/pm": "^3.20.3"
42
+ "@tiptap/core": "^3.20.5",
43
+ "@tiptap/pm": "^3.20.5"
44
44
  },
45
45
  "repository": {
46
46
  "type": "git",