@tiptap/extension-unique-id 2.0.0-beta.4 → 2.22.1
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 -282
- 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 -282
- package/dist/index.js.map +1 -0
- package/dist/{tiptap-extension-unique-id.umd.js → index.umd.js} +255 -283
- 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 +97 -33
- 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
package/README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# @tiptap/extension-unique-id
|
|
2
|
+
[](https://www.npmjs.com/package/@tiptap/extension-unique-id)
|
|
3
|
+
[](https://npmcharts.com/compare/tiptap?minimal=true)
|
|
4
|
+
[](https://www.npmjs.com/package/@tiptap/extension-unique-id)
|
|
5
|
+
[](https://github.com/sponsors/ueberdosis)
|
|
6
|
+
|
|
7
|
+
## Introduction
|
|
8
|
+
Tiptap is a headless wrapper around [ProseMirror](https://ProseMirror.net) – a toolkit for building rich text WYSIWYG editors, which is already in use at many well-known companies such as *New York Times*, *The Guardian* or *Atlassian*.
|
|
9
|
+
|
|
10
|
+
## Official Documentation
|
|
11
|
+
Documentation can be found on the [Tiptap website](https://tiptap.dev).
|
|
12
|
+
|
|
13
|
+
## License
|
|
14
|
+
Tiptap is open sourced software licensed under the [MIT license](https://github.com/ueberdosis/tiptap/blob/main/LICENSE.md).
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"findDuplicates.d.ts","sourceRoot":"","sources":["../../src/helpers/findDuplicates.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,GAAG,EAAE,GAAG,GAAG,EAAE,CAKlD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Removes duplicated values within an array.
|
|
3
|
+
* Supports numbers, strings and objects.
|
|
4
|
+
*/
|
|
5
|
+
export declare function removeDuplicates<T>(array: T[], by?: {
|
|
6
|
+
(value: any, replacer?: (this: any, key: string, value: any) => any, space?: string | number): string;
|
|
7
|
+
(value: any, replacer?: (number | string)[] | null, space?: string | number): string;
|
|
8
|
+
}): T[];
|
|
9
|
+
//# sourceMappingURL=removeDuplicates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"removeDuplicates.d.ts","sourceRoot":"","sources":["../../src/helpers/removeDuplicates.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE,EAAE;;;CAAiB,GAAG,CAAC,EAAE,CAUxE"}
|
|
@@ -3,294 +3,265 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var core = require('@tiptap/core');
|
|
6
|
-
var
|
|
7
|
-
var
|
|
6
|
+
var model = require('@tiptap/pm/model');
|
|
7
|
+
var state = require('@tiptap/pm/state');
|
|
8
8
|
var uuid = require('uuid');
|
|
9
|
-
var prosemirrorTransform = require('prosemirror-transform');
|
|
10
9
|
|
|
11
|
-
/**
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Removes duplicated values within an array.
|
|
12
|
+
* Supports numbers, strings and objects.
|
|
13
|
+
*/
|
|
14
|
+
function removeDuplicates(array, by = JSON.stringify) {
|
|
15
|
+
const seen = {};
|
|
16
|
+
return array.filter(item => {
|
|
17
|
+
const key = by(item);
|
|
18
|
+
return Object.prototype.hasOwnProperty.call(seen, key)
|
|
19
|
+
? false
|
|
20
|
+
: (seen[key] = true);
|
|
21
|
+
});
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
/**
|
|
25
|
-
*
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
return
|
|
31
|
-
const key = by(item);
|
|
32
|
-
return Object.prototype.hasOwnProperty.call(seen, key)
|
|
33
|
-
? false
|
|
34
|
-
: (seen[key] = true);
|
|
35
|
-
});
|
|
24
|
+
/**
|
|
25
|
+
* Returns a list of duplicated items within an array.
|
|
26
|
+
*/
|
|
27
|
+
function findDuplicates(items) {
|
|
28
|
+
const filtered = items.filter((el, index) => items.indexOf(el) !== index);
|
|
29
|
+
const duplicates = removeDuplicates(filtered);
|
|
30
|
+
return duplicates;
|
|
36
31
|
}
|
|
37
32
|
|
|
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
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
// check for any other child nodes
|
|
271
|
-
if (!types.includes(node.type.name)) {
|
|
272
|
-
list.push(node.copy(removeId(node.content)));
|
|
273
|
-
return;
|
|
274
|
-
}
|
|
275
|
-
// remove id
|
|
276
|
-
const nodeWithoutId = node.type.create({
|
|
277
|
-
...node.attrs,
|
|
278
|
-
[attributeName]: null,
|
|
279
|
-
}, removeId(node.content), node.marks);
|
|
280
|
-
list.push(nodeWithoutId);
|
|
281
|
-
});
|
|
282
|
-
return prosemirrorModel.Fragment.from(list);
|
|
283
|
-
};
|
|
284
|
-
// reset check
|
|
285
|
-
transformPasted = false;
|
|
286
|
-
return new prosemirrorModel.Slice(removeId(slice.content), slice.openStart, slice.openEnd);
|
|
287
|
-
},
|
|
288
|
-
},
|
|
289
|
-
}),
|
|
290
|
-
];
|
|
291
|
-
},
|
|
33
|
+
const UniqueID = core.Extension.create({
|
|
34
|
+
name: 'uniqueID',
|
|
35
|
+
// we’ll set a very high priority to make sure this runs first
|
|
36
|
+
// and is compatible with `appendTransaction` hooks of other extensions
|
|
37
|
+
priority: 10000,
|
|
38
|
+
addOptions() {
|
|
39
|
+
return {
|
|
40
|
+
attributeName: 'id',
|
|
41
|
+
types: [],
|
|
42
|
+
generateID: () => uuid.v4(),
|
|
43
|
+
filterTransaction: null,
|
|
44
|
+
};
|
|
45
|
+
},
|
|
46
|
+
addGlobalAttributes() {
|
|
47
|
+
return [
|
|
48
|
+
{
|
|
49
|
+
types: this.options.types,
|
|
50
|
+
attributes: {
|
|
51
|
+
[this.options.attributeName]: {
|
|
52
|
+
default: null,
|
|
53
|
+
parseHTML: element => element.getAttribute(`data-${this.options.attributeName}`),
|
|
54
|
+
renderHTML: attributes => {
|
|
55
|
+
if (!attributes[this.options.attributeName]) {
|
|
56
|
+
return {};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
[`data-${this.options.attributeName}`]: attributes[this.options.attributeName],
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
];
|
|
66
|
+
},
|
|
67
|
+
// check initial content for missing ids
|
|
68
|
+
onCreate() {
|
|
69
|
+
const collab = this.editor.extensionManager.extensions.find(ext => ext.name === 'collaboration');
|
|
70
|
+
const provider = (collab === null || collab === void 0 ? void 0 : collab.options) ? collab.options.provider : undefined;
|
|
71
|
+
const createIds = () => {
|
|
72
|
+
const { view, state } = this.editor;
|
|
73
|
+
const { tr, doc } = state;
|
|
74
|
+
const { types, attributeName, generateID } = this.options;
|
|
75
|
+
const nodesWithoutId = core.findChildren(doc, node => {
|
|
76
|
+
return types.includes(node.type.name) && node.attrs[attributeName] === null;
|
|
77
|
+
});
|
|
78
|
+
nodesWithoutId.forEach(({ node, pos }) => {
|
|
79
|
+
tr.setNodeMarkup(pos, undefined, {
|
|
80
|
+
...node.attrs,
|
|
81
|
+
[attributeName]: generateID(),
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
tr.setMeta('addToHistory', false);
|
|
85
|
+
view.dispatch(tr);
|
|
86
|
+
if (provider) {
|
|
87
|
+
provider.off('synced', createIds);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* We need to handle collaboration a bit different here
|
|
92
|
+
* because we can't automatically add IDs when the provider is not yet synced
|
|
93
|
+
* otherwise we end up with empty paragraphs
|
|
94
|
+
*/
|
|
95
|
+
if (collab) {
|
|
96
|
+
if (!provider) {
|
|
97
|
+
return createIds();
|
|
98
|
+
}
|
|
99
|
+
provider.on('synced', createIds);
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
return createIds();
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
addProseMirrorPlugins() {
|
|
106
|
+
let dragSourceElement = null;
|
|
107
|
+
let transformPasted = false;
|
|
108
|
+
return [
|
|
109
|
+
new state.Plugin({
|
|
110
|
+
key: new state.PluginKey('uniqueID'),
|
|
111
|
+
appendTransaction: (transactions, oldState, newState) => {
|
|
112
|
+
const hasDocChanges = transactions.some(transaction => transaction.docChanged)
|
|
113
|
+
&& !oldState.doc.eq(newState.doc);
|
|
114
|
+
const filterTransactions = this.options.filterTransaction
|
|
115
|
+
&& transactions.some(tr => { var _a, _b; return !((_b = (_a = this.options).filterTransaction) === null || _b === void 0 ? void 0 : _b.call(_a, tr)); });
|
|
116
|
+
const isCollabTransaction = transactions.find(tr => tr.getMeta('y-sync$'));
|
|
117
|
+
if (isCollabTransaction) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (!hasDocChanges || filterTransactions) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
const { tr } = newState;
|
|
124
|
+
const { types, attributeName, generateID } = this.options;
|
|
125
|
+
const transform = core.combineTransactionSteps(oldState.doc, transactions);
|
|
126
|
+
const { mapping } = transform;
|
|
127
|
+
// get changed ranges based on the old state
|
|
128
|
+
const changes = core.getChangedRanges(transform);
|
|
129
|
+
changes.forEach(({ newRange }) => {
|
|
130
|
+
const newNodes = core.findChildrenInRange(newState.doc, newRange, node => {
|
|
131
|
+
return types.includes(node.type.name);
|
|
132
|
+
});
|
|
133
|
+
const newIds = newNodes
|
|
134
|
+
.map(({ node }) => node.attrs[attributeName])
|
|
135
|
+
.filter(id => id !== null);
|
|
136
|
+
newNodes.forEach(({ node, pos }, i) => {
|
|
137
|
+
var _a;
|
|
138
|
+
// instead of checking `node.attrs[attributeName]` directly
|
|
139
|
+
// we look at the current state of the node within `tr.doc`.
|
|
140
|
+
// this helps to prevent adding new ids to the same node
|
|
141
|
+
// if the node changed multiple times within one transaction
|
|
142
|
+
const id = (_a = tr.doc.nodeAt(pos)) === null || _a === void 0 ? void 0 : _a.attrs[attributeName];
|
|
143
|
+
if (id === null) {
|
|
144
|
+
tr.setNodeMarkup(pos, undefined, {
|
|
145
|
+
...node.attrs,
|
|
146
|
+
[attributeName]: generateID(),
|
|
147
|
+
});
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const nextNode = newNodes[i + 1];
|
|
151
|
+
if (nextNode && node.content.size === 0) {
|
|
152
|
+
tr.setNodeMarkup(nextNode.pos, undefined, {
|
|
153
|
+
...nextNode.node.attrs,
|
|
154
|
+
[attributeName]: id,
|
|
155
|
+
});
|
|
156
|
+
newIds[i + 1] = id;
|
|
157
|
+
if (nextNode.node.attrs[attributeName]) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
const generatedId = generateID();
|
|
161
|
+
tr.setNodeMarkup(pos, undefined, {
|
|
162
|
+
...node.attrs,
|
|
163
|
+
[attributeName]: generatedId,
|
|
164
|
+
});
|
|
165
|
+
newIds[i] = generatedId;
|
|
166
|
+
return tr;
|
|
167
|
+
}
|
|
168
|
+
const duplicatedNewIds = findDuplicates(newIds);
|
|
169
|
+
// check if the node doesn’t exist in the old state
|
|
170
|
+
const { deleted } = mapping.invert().mapResult(pos);
|
|
171
|
+
const newNode = deleted && duplicatedNewIds.includes(id);
|
|
172
|
+
if (newNode) {
|
|
173
|
+
tr.setNodeMarkup(pos, undefined, {
|
|
174
|
+
...node.attrs,
|
|
175
|
+
[attributeName]: generateID(),
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
});
|
|
180
|
+
if (!tr.steps.length) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
// `tr.setNodeMarkup` resets the stored marks
|
|
184
|
+
// so we’ll restore them if they exist
|
|
185
|
+
tr.setStoredMarks(newState.tr.storedMarks);
|
|
186
|
+
return tr;
|
|
187
|
+
},
|
|
188
|
+
// we register a global drag handler to track the current drag source element
|
|
189
|
+
view(view) {
|
|
190
|
+
const handleDragstart = (event) => {
|
|
191
|
+
var _a;
|
|
192
|
+
dragSourceElement = ((_a = view.dom.parentElement) === null || _a === void 0 ? void 0 : _a.contains(event.target))
|
|
193
|
+
? view.dom.parentElement
|
|
194
|
+
: null;
|
|
195
|
+
};
|
|
196
|
+
window.addEventListener('dragstart', handleDragstart);
|
|
197
|
+
return {
|
|
198
|
+
destroy() {
|
|
199
|
+
window.removeEventListener('dragstart', handleDragstart);
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
},
|
|
203
|
+
props: {
|
|
204
|
+
// `handleDOMEvents` is called before `transformPasted`
|
|
205
|
+
// so we can do some checks before
|
|
206
|
+
handleDOMEvents: {
|
|
207
|
+
// only create new ids for dropped content
|
|
208
|
+
// or dropped content while holding `alt`
|
|
209
|
+
// or content is dragged from another editor
|
|
210
|
+
drop: (view, event) => {
|
|
211
|
+
var _a, _b;
|
|
212
|
+
if (dragSourceElement !== view.dom.parentElement
|
|
213
|
+
|| ((_a = event.dataTransfer) === null || _a === void 0 ? void 0 : _a.effectAllowed) === 'copyMove'
|
|
214
|
+
|| ((_b = event.dataTransfer) === null || _b === void 0 ? void 0 : _b.effectAllowed) === 'copy') {
|
|
215
|
+
dragSourceElement = null;
|
|
216
|
+
transformPasted = true;
|
|
217
|
+
}
|
|
218
|
+
return false;
|
|
219
|
+
},
|
|
220
|
+
// always create new ids on pasted content
|
|
221
|
+
paste: () => {
|
|
222
|
+
transformPasted = true;
|
|
223
|
+
return false;
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
// we’ll remove ids for every pasted node
|
|
227
|
+
// so we can create a new one within `appendTransaction`
|
|
228
|
+
transformPasted: slice => {
|
|
229
|
+
if (!transformPasted) {
|
|
230
|
+
return slice;
|
|
231
|
+
}
|
|
232
|
+
const { types, attributeName } = this.options;
|
|
233
|
+
const removeId = (fragment) => {
|
|
234
|
+
const list = [];
|
|
235
|
+
fragment.forEach(node => {
|
|
236
|
+
// don’t touch text nodes
|
|
237
|
+
if (node.isText) {
|
|
238
|
+
list.push(node);
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
// check for any other child nodes
|
|
242
|
+
if (!types.includes(node.type.name)) {
|
|
243
|
+
list.push(node.copy(removeId(node.content)));
|
|
244
|
+
return;
|
|
245
|
+
}
|
|
246
|
+
// remove id
|
|
247
|
+
const nodeWithoutId = node.type.create({
|
|
248
|
+
...node.attrs,
|
|
249
|
+
[attributeName]: null,
|
|
250
|
+
}, removeId(node.content), node.marks);
|
|
251
|
+
list.push(nodeWithoutId);
|
|
252
|
+
});
|
|
253
|
+
return model.Fragment.from(list);
|
|
254
|
+
};
|
|
255
|
+
// reset check
|
|
256
|
+
transformPasted = false;
|
|
257
|
+
return new model.Slice(removeId(slice.content), slice.openStart, slice.openEnd);
|
|
258
|
+
},
|
|
259
|
+
},
|
|
260
|
+
}),
|
|
261
|
+
];
|
|
262
|
+
},
|
|
292
263
|
});
|
|
293
264
|
|
|
294
265
|
exports.UniqueID = UniqueID;
|
|
295
|
-
exports
|
|
296
|
-
//# sourceMappingURL=
|
|
266
|
+
exports.default = UniqueID;
|
|
267
|
+
//# sourceMappingURL=index.cjs.map
|