@tiptap/extension-unique-id 2.0.0-beta.3 → 2.22.0
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/README.md +14 -0
- package/dist/helpers/findDuplicates.d.ts +5 -0
- package/dist/helpers/findDuplicates.d.ts.map +1 -0
- package/dist/helpers/removeDuplicates.d.ts +9 -0
- package/dist/helpers/removeDuplicates.d.ts.map +1 -0
- package/dist/{tiptap-extension-unique-id.cjs.js → index.cjs} +253 -280
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/{tiptap-extension-unique-id.esm.js → index.js} +253 -280
- package/dist/index.js.map +1 -0
- package/dist/{tiptap-extension-unique-id.umd.js → index.umd.js} +255 -281
- package/dist/index.umd.js.map +1 -0
- package/dist/{tiptap-pro/packages/extension-unique-id/src/unique-id.d.ts → unique-id.d.ts} +10 -9
- package/dist/unique-id.d.ts.map +1 -0
- package/package.json +31 -13
- package/src/helpers/findDuplicates.ts +2 -2
- package/src/helpers/removeDuplicates.ts +1 -1
- package/src/index.ts +2 -2
- package/src/unique-id.ts +104 -38
- package/dist/tiptap-extension-unique-id.cjs.js.map +0 -1
- package/dist/tiptap-extension-unique-id.esm.js.map +0 -1
- package/dist/tiptap-extension-unique-id.umd.js.map +0 -1
- package/dist/tiptap-pro/packages/extension-unique-id/src/helpers/combineTransactionSteps.d.ts +0 -7
- package/dist/tiptap-pro/packages/extension-unique-id/src/helpers/findDuplicates.d.ts +0 -4
- package/dist/tiptap-pro/packages/extension-unique-id/src/helpers/getChangedRanges.d.ts +0 -12
- package/dist/tiptap-pro/packages/extension-unique-id/src/helpers/removeDuplicates.d.ts +0 -8
- package/dist/tiptap-pro/packages/extension-unique-id/src/index.d.ts +0 -3
- package/src/helpers/arrayDifference.ts +0 -35
- package/src/helpers/combineTransactionSteps.ts +0 -18
- package/src/helpers/getChangedRanges.ts +0 -78
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/helpers/removeDuplicates.ts","../src/helpers/findDuplicates.ts","../src/unique-id.ts"],"sourcesContent":["/**\n * Removes duplicated values within an array.\n * Supports numbers, strings and objects.\n */\nexport function removeDuplicates<T>(array: T[], by = JSON.stringify): T[] {\n const seen: Record<any, any> = {}\n\n return array.filter(item => {\n const key = by(item)\n\n return Object.prototype.hasOwnProperty.call(seen, key)\n ? false\n : (seen[key] = true)\n })\n}\n","import { removeDuplicates } from './removeDuplicates.js'\n\n/**\n * Returns a list of duplicated items within an array.\n */\nexport function findDuplicates(items: any[]): any[] {\n const filtered = items.filter((el, index) => items.indexOf(el) !== index)\n const duplicates = removeDuplicates(filtered)\n\n return duplicates\n}\n","import {\n combineTransactionSteps,\n Extension,\n findChildren,\n findChildrenInRange,\n getChangedRanges,\n} from '@tiptap/core'\nimport { Fragment, Node as ProseMirrorNode, Slice } from '@tiptap/pm/model'\nimport { Plugin, PluginKey, Transaction } from '@tiptap/pm/state'\nimport { v4 as uuidv4 } from 'uuid'\n\nimport { findDuplicates } from './helpers/findDuplicates.js'\n\nexport interface UniqueIDOptions {\n attributeName: string,\n types: string[],\n generateID: () => any,\n filterTransaction: ((transaction: Transaction) => boolean) | null,\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 }\n },\n\n addGlobalAttributes() {\n return [\n {\n types: this.options.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 const collab = this.editor.extensionManager.extensions.find(ext => ext.name === 'collaboration')\n const provider = collab?.options ? collab.options.provider : undefined\n\n const createIds = () => {\n const { view, state } = this.editor\n const { tr, doc } = state\n const { types, 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(),\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 (collab) {\n if (!provider) {\n return createIds()\n }\n\n provider.on('synced', createIds)\n } else {\n return createIds()\n }\n },\n\n addProseMirrorPlugins() {\n let dragSourceElement: Element | null = null\n let transformPasted = false\n\n return [\n new Plugin({\n key: new PluginKey('uniqueID'),\n\n appendTransaction: (transactions, oldState, newState) => {\n const hasDocChanges = transactions.some(transaction => transaction.docChanged)\n && !oldState.doc.eq(newState.doc)\n const filterTransactions = this.options.filterTransaction\n && transactions.some(tr => !this.options.filterTransaction?.(tr))\n\n const isCollabTransaction = transactions.find(tr => tr.getMeta('y-sync$'))\n\n if (isCollabTransaction) {\n return\n }\n\n if (!hasDocChanges || filterTransactions) {\n return\n }\n\n const { tr } = newState\n\n const { types, 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\n .map(({ node }) => node.attrs[attributeName])\n .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(),\n })\n\n return\n }\n\n const nextNode = newNodes[i + 1]\n\n if (nextNode && node.content.size === 0) {\n tr.setNodeMarkup(nextNode.pos, undefined, {\n ...nextNode.node.attrs,\n [attributeName]: id,\n })\n newIds[i + 1] = id\n\n if (nextNode.node.attrs[attributeName]) {\n return\n }\n\n const generatedId = generateID()\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(),\n })\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 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 { types, 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"],"names":["uuidv4"],"mappings":";;;;;AAAA;;;AAGG;AACG,SAAU,gBAAgB,CAAI,KAAU,EAAE,EAAE,GAAG,IAAI,CAAC,SAAS,EAAA;IACjE,MAAM,IAAI,GAAqB,EAAE;AAEjC,IAAA,OAAO,KAAK,CAAC,MAAM,CAAC,IAAI,IAAG;AACzB,QAAA,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;QAEpB,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG;AACnD,cAAE;eACC,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;AACxB,KAAC,CAAC;AACJ;;ACZA;;AAEG;AACG,SAAU,cAAc,CAAC,KAAY,EAAA;IACzC,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,KAAK,KAAK,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,KAAK,CAAC;AACzE,IAAA,MAAM,UAAU,GAAG,gBAAgB,CAAC,QAAQ,CAAC;AAE7C,IAAA,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AE;AACf,oCAAA,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC;oCAEf;;;AAIF,gCAAA,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;AACnC,oCAAA,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC;oCAE5C;;;AAIF,gCAAA,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CACpC;oCACE,GAAG,IAAI,CAAC,KAAK;oCACb,CAAC,aAAa,GAAG,IAAI;iCACtB,EACD,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,EACtB,IAAI,CAAC,KAAK,CACX;AAED,gCAAA,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC;AAC1B,6BAAC,CAAC;AAEF,4BAAA,OAAO,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC;AAC5B,yBAAC;;wBAGD,eAAe,GAAG,KAAK;AAEvB,wBAAA,OAAO,IAAI,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC;qBAC1E;AACF,iBAAA;aACF,CAAC;SACH;KACF;AAEF,CAAA;;;;"}
|
|
@@ -1,294 +1,268 @@
|
|
|
1
1
|
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', '
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-unique-id"] = {}, global.core, global.
|
|
5
|
-
})(this, (function (exports, core,
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('@tiptap/pm/model'), require('@tiptap/pm/state'), require('uuid')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', '@tiptap/pm/model', '@tiptap/pm/state', 'uuid'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@tiptap/extension-unique-id"] = {}, global.core, global.model, global.state, global.uuid));
|
|
5
|
+
})(this, (function (exports, core, model, state, uuid) { 'use strict';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
*
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
/**
|
|
8
|
+
* Removes duplicated values within an array.
|
|
9
|
+
* Supports numbers, strings and objects.
|
|
10
|
+
*/
|
|
11
|
+
function removeDuplicates(array, by = JSON.stringify) {
|
|
12
|
+
const seen = {};
|
|
13
|
+
return array.filter(item => {
|
|
14
|
+
const key = by(item);
|
|
15
|
+
return Object.prototype.hasOwnProperty.call(seen, key)
|
|
16
|
+
? false
|
|
17
|
+
: (seen[key] = true);
|
|
18
|
+
});
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const
|
|
26
|
-
return
|
|
27
|
-
const key = by(item);
|
|
28
|
-
return Object.prototype.hasOwnProperty.call(seen, key)
|
|
29
|
-
? false
|
|
30
|
-
: (seen[key] = true);
|
|
31
|
-
});
|
|
21
|
+
/**
|
|
22
|
+
* Returns a list of duplicated items within an array.
|
|
23
|
+
*/
|
|
24
|
+
function findDuplicates(items) {
|
|
25
|
+
const filtered = items.filter((el, index) => items.indexOf(el) !== index);
|
|
26
|
+
const duplicates = removeDuplicates(filtered);
|
|
27
|
+
return duplicates;
|
|
32
28
|
}
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
},
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
// check for any other child nodes
|
|
265
|
-
if (!types.includes(node.type.name)) {
|
|
266
|
-
list.push(node.copy(removeId(node.content)));
|
|
267
|
-
return;
|
|
268
|
-
}
|
|
269
|
-
// remove id
|
|
270
|
-
const nodeWithoutId = node.type.create({
|
|
271
|
-
...node.attrs,
|
|
272
|
-
[attributeName]: null,
|
|
273
|
-
}, removeId(node.content), node.marks);
|
|
274
|
-
list.push(nodeWithoutId);
|
|
275
|
-
});
|
|
276
|
-
return prosemirrorModel.Fragment.from(list);
|
|
277
|
-
};
|
|
278
|
-
// reset check
|
|
279
|
-
transformPasted = false;
|
|
280
|
-
return new prosemirrorModel.Slice(removeId(slice.content), slice.openStart, slice.openEnd);
|
|
281
|
-
},
|
|
282
|
-
},
|
|
283
|
-
}),
|
|
284
|
-
];
|
|
285
|
-
},
|
|
30
|
+
const UniqueID = core.Extension.create({
|
|
31
|
+
name: 'uniqueID',
|
|
32
|
+
// we’ll set a very high priority to make sure this runs first
|
|
33
|
+
// and is compatible with `appendTransaction` hooks of other extensions
|
|
34
|
+
priority: 10000,
|
|
35
|
+
addOptions() {
|
|
36
|
+
return {
|
|
37
|
+
attributeName: 'id',
|
|
38
|
+
types: [],
|
|
39
|
+
generateID: () => uuid.v4(),
|
|
40
|
+
filterTransaction: null,
|
|
41
|
+
};
|
|
42
|
+
},
|
|
43
|
+
addGlobalAttributes() {
|
|
44
|
+
return [
|
|
45
|
+
{
|
|
46
|
+
types: this.options.types,
|
|
47
|
+
attributes: {
|
|
48
|
+
[this.options.attributeName]: {
|
|
49
|
+
default: null,
|
|
50
|
+
parseHTML: element => element.getAttribute(`data-${this.options.attributeName}`),
|
|
51
|
+
renderHTML: attributes => {
|
|
52
|
+
if (!attributes[this.options.attributeName]) {
|
|
53
|
+
return {};
|
|
54
|
+
}
|
|
55
|
+
return {
|
|
56
|
+
[`data-${this.options.attributeName}`]: attributes[this.options.attributeName],
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
];
|
|
63
|
+
},
|
|
64
|
+
// check initial content for missing ids
|
|
65
|
+
onCreate() {
|
|
66
|
+
const collab = this.editor.extensionManager.extensions.find(ext => ext.name === 'collaboration');
|
|
67
|
+
const provider = (collab === null || collab === void 0 ? void 0 : collab.options) ? collab.options.provider : undefined;
|
|
68
|
+
const createIds = () => {
|
|
69
|
+
const { view, state } = this.editor;
|
|
70
|
+
const { tr, doc } = state;
|
|
71
|
+
const { types, attributeName, generateID } = this.options;
|
|
72
|
+
const nodesWithoutId = core.findChildren(doc, node => {
|
|
73
|
+
return types.includes(node.type.name) && node.attrs[attributeName] === null;
|
|
74
|
+
});
|
|
75
|
+
nodesWithoutId.forEach(({ node, pos }) => {
|
|
76
|
+
tr.setNodeMarkup(pos, undefined, {
|
|
77
|
+
...node.attrs,
|
|
78
|
+
[attributeName]: generateID(),
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
tr.setMeta('addToHistory', false);
|
|
82
|
+
view.dispatch(tr);
|
|
83
|
+
if (provider) {
|
|
84
|
+
provider.off('synced', createIds);
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* We need to handle collaboration a bit different here
|
|
89
|
+
* because we can't automatically add IDs when the provider is not yet synced
|
|
90
|
+
* otherwise we end up with empty paragraphs
|
|
91
|
+
*/
|
|
92
|
+
if (collab) {
|
|
93
|
+
if (!provider) {
|
|
94
|
+
return createIds();
|
|
95
|
+
}
|
|
96
|
+
provider.on('synced', createIds);
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
return createIds();
|
|
100
|
+
}
|
|
101
|
+
},
|
|
102
|
+
addProseMirrorPlugins() {
|
|
103
|
+
let dragSourceElement = null;
|
|
104
|
+
let transformPasted = false;
|
|
105
|
+
return [
|
|
106
|
+
new state.Plugin({
|
|
107
|
+
key: new state.PluginKey('uniqueID'),
|
|
108
|
+
appendTransaction: (transactions, oldState, newState) => {
|
|
109
|
+
const hasDocChanges = transactions.some(transaction => transaction.docChanged)
|
|
110
|
+
&& !oldState.doc.eq(newState.doc);
|
|
111
|
+
const filterTransactions = this.options.filterTransaction
|
|
112
|
+
&& transactions.some(tr => { var _a, _b; return !((_b = (_a = this.options).filterTransaction) === null || _b === void 0 ? void 0 : _b.call(_a, tr)); });
|
|
113
|
+
const isCollabTransaction = transactions.find(tr => tr.getMeta('y-sync$'));
|
|
114
|
+
if (isCollabTransaction) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
if (!hasDocChanges || filterTransactions) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const { tr } = newState;
|
|
121
|
+
const { types, attributeName, generateID } = this.options;
|
|
122
|
+
const transform = core.combineTransactionSteps(oldState.doc, transactions);
|
|
123
|
+
const { mapping } = transform;
|
|
124
|
+
// get changed ranges based on the old state
|
|
125
|
+
const changes = core.getChangedRanges(transform);
|
|
126
|
+
changes.forEach(({ newRange }) => {
|
|
127
|
+
const newNodes = core.findChildrenInRange(newState.doc, newRange, node => {
|
|
128
|
+
return types.includes(node.type.name);
|
|
129
|
+
});
|
|
130
|
+
const newIds = newNodes
|
|
131
|
+
.map(({ node }) => node.attrs[attributeName])
|
|
132
|
+
.filter(id => id !== null);
|
|
133
|
+
newNodes.forEach(({ node, pos }, i) => {
|
|
134
|
+
var _a;
|
|
135
|
+
// instead of checking `node.attrs[attributeName]` directly
|
|
136
|
+
// we look at the current state of the node within `tr.doc`.
|
|
137
|
+
// this helps to prevent adding new ids to the same node
|
|
138
|
+
// if the node changed multiple times within one transaction
|
|
139
|
+
const id = (_a = tr.doc.nodeAt(pos)) === null || _a === void 0 ? void 0 : _a.attrs[attributeName];
|
|
140
|
+
if (id === null) {
|
|
141
|
+
tr.setNodeMarkup(pos, undefined, {
|
|
142
|
+
...node.attrs,
|
|
143
|
+
[attributeName]: generateID(),
|
|
144
|
+
});
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
const nextNode = newNodes[i + 1];
|
|
148
|
+
if (nextNode && node.content.size === 0) {
|
|
149
|
+
tr.setNodeMarkup(nextNode.pos, undefined, {
|
|
150
|
+
...nextNode.node.attrs,
|
|
151
|
+
[attributeName]: id,
|
|
152
|
+
});
|
|
153
|
+
newIds[i + 1] = id;
|
|
154
|
+
if (nextNode.node.attrs[attributeName]) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const generatedId = generateID();
|
|
158
|
+
tr.setNodeMarkup(pos, undefined, {
|
|
159
|
+
...node.attrs,
|
|
160
|
+
[attributeName]: generatedId,
|
|
161
|
+
});
|
|
162
|
+
newIds[i] = generatedId;
|
|
163
|
+
return tr;
|
|
164
|
+
}
|
|
165
|
+
const duplicatedNewIds = findDuplicates(newIds);
|
|
166
|
+
// check if the node doesn’t exist in the old state
|
|
167
|
+
const { deleted } = mapping.invert().mapResult(pos);
|
|
168
|
+
const newNode = deleted && duplicatedNewIds.includes(id);
|
|
169
|
+
if (newNode) {
|
|
170
|
+
tr.setNodeMarkup(pos, undefined, {
|
|
171
|
+
...node.attrs,
|
|
172
|
+
[attributeName]: generateID(),
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
});
|
|
177
|
+
if (!tr.steps.length) {
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
// `tr.setNodeMarkup` resets the stored marks
|
|
181
|
+
// so we’ll restore them if they exist
|
|
182
|
+
tr.setStoredMarks(newState.tr.storedMarks);
|
|
183
|
+
return tr;
|
|
184
|
+
},
|
|
185
|
+
// we register a global drag handler to track the current drag source element
|
|
186
|
+
view(view) {
|
|
187
|
+
const handleDragstart = (event) => {
|
|
188
|
+
var _a;
|
|
189
|
+
dragSourceElement = ((_a = view.dom.parentElement) === null || _a === void 0 ? void 0 : _a.contains(event.target))
|
|
190
|
+
? view.dom.parentElement
|
|
191
|
+
: null;
|
|
192
|
+
};
|
|
193
|
+
window.addEventListener('dragstart', handleDragstart);
|
|
194
|
+
return {
|
|
195
|
+
destroy() {
|
|
196
|
+
window.removeEventListener('dragstart', handleDragstart);
|
|
197
|
+
},
|
|
198
|
+
};
|
|
199
|
+
},
|
|
200
|
+
props: {
|
|
201
|
+
// `handleDOMEvents` is called before `transformPasted`
|
|
202
|
+
// so we can do some checks before
|
|
203
|
+
handleDOMEvents: {
|
|
204
|
+
// only create new ids for dropped content
|
|
205
|
+
// or dropped content while holding `alt`
|
|
206
|
+
// or content is dragged from another editor
|
|
207
|
+
drop: (view, event) => {
|
|
208
|
+
var _a, _b;
|
|
209
|
+
if (dragSourceElement !== view.dom.parentElement
|
|
210
|
+
|| ((_a = event.dataTransfer) === null || _a === void 0 ? void 0 : _a.effectAllowed) === 'copyMove'
|
|
211
|
+
|| ((_b = event.dataTransfer) === null || _b === void 0 ? void 0 : _b.effectAllowed) === 'copy') {
|
|
212
|
+
dragSourceElement = null;
|
|
213
|
+
transformPasted = true;
|
|
214
|
+
}
|
|
215
|
+
return false;
|
|
216
|
+
},
|
|
217
|
+
// always create new ids on pasted content
|
|
218
|
+
paste: () => {
|
|
219
|
+
transformPasted = true;
|
|
220
|
+
return false;
|
|
221
|
+
},
|
|
222
|
+
},
|
|
223
|
+
// we’ll remove ids for every pasted node
|
|
224
|
+
// so we can create a new one within `appendTransaction`
|
|
225
|
+
transformPasted: slice => {
|
|
226
|
+
if (!transformPasted) {
|
|
227
|
+
return slice;
|
|
228
|
+
}
|
|
229
|
+
const { types, attributeName } = this.options;
|
|
230
|
+
const removeId = (fragment) => {
|
|
231
|
+
const list = [];
|
|
232
|
+
fragment.forEach(node => {
|
|
233
|
+
// don’t touch text nodes
|
|
234
|
+
if (node.isText) {
|
|
235
|
+
list.push(node);
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
// check for any other child nodes
|
|
239
|
+
if (!types.includes(node.type.name)) {
|
|
240
|
+
list.push(node.copy(removeId(node.content)));
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
// remove id
|
|
244
|
+
const nodeWithoutId = node.type.create({
|
|
245
|
+
...node.attrs,
|
|
246
|
+
[attributeName]: null,
|
|
247
|
+
}, removeId(node.content), node.marks);
|
|
248
|
+
list.push(nodeWithoutId);
|
|
249
|
+
});
|
|
250
|
+
return model.Fragment.from(list);
|
|
251
|
+
};
|
|
252
|
+
// reset check
|
|
253
|
+
transformPasted = false;
|
|
254
|
+
return new model.Slice(removeId(slice.content), slice.openStart, slice.openEnd);
|
|
255
|
+
},
|
|
256
|
+
},
|
|
257
|
+
}),
|
|
258
|
+
];
|
|
259
|
+
},
|
|
286
260
|
});
|
|
287
261
|
|
|
288
262
|
exports.UniqueID = UniqueID;
|
|
289
|
-
exports
|
|
263
|
+
exports.default = UniqueID;
|
|
290
264
|
|
|
291
265
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
292
266
|
|
|
293
267
|
}));
|
|
294
|
-
//# sourceMappingURL=
|
|
268
|
+
//# sourceMappingURL=index.umd.js.map
|