@portabletext/editor 3.3.12 → 3.3.13
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/lib/index.js +24 -46
- package/lib/index.js.map +1 -1
- package/package.json +6 -6
package/lib/index.js
CHANGED
|
@@ -164,13 +164,9 @@ function isDeepEqualSets(data, other) {
|
|
|
164
164
|
return !0;
|
|
165
165
|
}
|
|
166
166
|
const VOID_CHILD_KEY = "void-child";
|
|
167
|
-
function keepObjectEquality(context, object, keyMap) {
|
|
168
|
-
const value = keyMap[object._key];
|
|
169
|
-
return value && isEqualBlocks(context, object, value) ? value : (keyMap[object._key] = object, object);
|
|
170
|
-
}
|
|
171
167
|
function toSlateBlock(block, {
|
|
172
168
|
schemaTypes
|
|
173
|
-
}
|
|
169
|
+
}) {
|
|
174
170
|
const {
|
|
175
171
|
_type,
|
|
176
172
|
_key,
|
|
@@ -189,9 +185,7 @@ function toSlateBlock(block, {
|
|
|
189
185
|
_key: childKey,
|
|
190
186
|
_type: schemaTypes.span.name,
|
|
191
187
|
text: childProps.text
|
|
192
|
-
} : childType !== schemaTypes.span.name ? (hasInlines = !0,
|
|
193
|
-
schema: schemaTypes
|
|
194
|
-
}, {
|
|
188
|
+
} : childType !== schemaTypes.span.name ? (hasInlines = !0, {
|
|
195
189
|
_type: childType,
|
|
196
190
|
_key: childKey,
|
|
197
191
|
children: [{
|
|
@@ -202,20 +196,16 @@ function toSlateBlock(block, {
|
|
|
202
196
|
}],
|
|
203
197
|
value: childProps,
|
|
204
198
|
__inline: !0
|
|
205
|
-
}
|
|
199
|
+
}) : child;
|
|
206
200
|
});
|
|
207
|
-
return !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block :
|
|
208
|
-
schema: schemaTypes
|
|
209
|
-
}, {
|
|
201
|
+
return !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block : {
|
|
210
202
|
_type,
|
|
211
203
|
_key,
|
|
212
204
|
...rest,
|
|
213
205
|
children
|
|
214
|
-
}
|
|
206
|
+
};
|
|
215
207
|
}
|
|
216
|
-
return
|
|
217
|
-
schema: schemaTypes
|
|
218
|
-
}, {
|
|
208
|
+
return {
|
|
219
209
|
_type,
|
|
220
210
|
_key,
|
|
221
211
|
children: [{
|
|
@@ -225,9 +215,9 @@ function toSlateBlock(block, {
|
|
|
225
215
|
marks: []
|
|
226
216
|
}],
|
|
227
217
|
value: rest
|
|
228
|
-
}
|
|
218
|
+
};
|
|
229
219
|
}
|
|
230
|
-
function fromSlateBlock(
|
|
220
|
+
function fromSlateBlock(block, textBlockType) {
|
|
231
221
|
const {
|
|
232
222
|
_key,
|
|
233
223
|
_type
|
|
@@ -250,28 +240,28 @@ function fromSlateBlock(context, block, textBlockType, keyMap = {}) {
|
|
|
250
240
|
children: _c,
|
|
251
241
|
...rest
|
|
252
242
|
} = child;
|
|
253
|
-
return
|
|
243
|
+
return {
|
|
254
244
|
...rest,
|
|
255
245
|
...v,
|
|
256
246
|
_key: k,
|
|
257
247
|
_type: t
|
|
258
|
-
}
|
|
248
|
+
};
|
|
259
249
|
}
|
|
260
250
|
return child;
|
|
261
251
|
});
|
|
262
|
-
return hasInlines ?
|
|
252
|
+
return hasInlines ? {
|
|
263
253
|
...block,
|
|
264
254
|
children,
|
|
265
255
|
_key,
|
|
266
256
|
_type
|
|
267
|
-
}
|
|
257
|
+
} : block;
|
|
268
258
|
}
|
|
269
259
|
const blockValue = "value" in block && block.value;
|
|
270
|
-
return
|
|
260
|
+
return {
|
|
271
261
|
_key,
|
|
272
262
|
_type,
|
|
273
263
|
...typeof blockValue == "object" ? blockValue : {}
|
|
274
|
-
}
|
|
264
|
+
};
|
|
275
265
|
}
|
|
276
266
|
function isEqualToEmptyEditor(initialValue, blocks, schemaTypes) {
|
|
277
267
|
if (!blocks || blocks.length !== 1)
|
|
@@ -417,9 +407,7 @@ function elementToBlock({
|
|
|
417
407
|
schema,
|
|
418
408
|
element
|
|
419
409
|
}) {
|
|
420
|
-
return fromSlateBlock(
|
|
421
|
-
schema
|
|
422
|
-
}, element, schema.block.name);
|
|
410
|
+
return fromSlateBlock(element, schema.block.name);
|
|
423
411
|
}
|
|
424
412
|
function isBlockElement({
|
|
425
413
|
editor,
|
|
@@ -3120,7 +3108,7 @@ function createPlaceholderBlock(context) {
|
|
|
3120
3108
|
}]
|
|
3121
3109
|
};
|
|
3122
3110
|
}
|
|
3123
|
-
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(),
|
|
3111
|
+
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap();
|
|
3124
3112
|
function withRemoteChanges(editor, fn) {
|
|
3125
3113
|
const prev = isChangingRemotely(editor) || !1;
|
|
3126
3114
|
IS_PROCESSING_REMOTE_CHANGES.set(editor, !0), fn(), IS_PROCESSING_REMOTE_CHANGES.set(editor, prev);
|
|
@@ -5998,7 +5986,7 @@ function insertPatch(context, editor, patch) {
|
|
|
5998
5986
|
if (patch.path.length === 1 && patch.path[0] === 0) {
|
|
5999
5987
|
const blocksToInsert = patch.items.map((item) => toSlateBlock(item, {
|
|
6000
5988
|
schemaTypes: context.schema
|
|
6001
|
-
}
|
|
5989
|
+
}));
|
|
6002
5990
|
return Transforms.insertNodes(editor, blocksToInsert, {
|
|
6003
5991
|
at: [0]
|
|
6004
5992
|
}), !0;
|
|
@@ -6013,7 +6001,7 @@ function insertPatch(context, editor, patch) {
|
|
|
6013
6001
|
position: position2
|
|
6014
6002
|
} = patch, blocksToInsert = items2.map((item) => toSlateBlock(item, {
|
|
6015
6003
|
schemaTypes: context.schema
|
|
6016
|
-
}
|
|
6004
|
+
})), targetBlockIndex = block.index, normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex, editorWasEmptyBefore = isEqualToEmptyEditor(context.initialValue, editor.value, context.schema);
|
|
6017
6005
|
return Transforms.insertNodes(editor, blocksToInsert, {
|
|
6018
6006
|
at: [normalizedIdx2]
|
|
6019
6007
|
}), editorWasEmptyBefore && typeof patch.path[0] == "number" && patch.path[0] === 0 && Transforms.removeNodes(editor, {
|
|
@@ -6031,7 +6019,7 @@ function insertPatch(context, editor, patch) {
|
|
|
6031
6019
|
children: items
|
|
6032
6020
|
}, {
|
|
6033
6021
|
schemaTypes: context.schema
|
|
6034
|
-
}
|
|
6022
|
+
}), normalizedIdx = position === "after" ? targetChild.index + 1 : targetChild.index, childInsertPath = [block.index, normalizedIdx];
|
|
6035
6023
|
return childrenToInsert && Element$1.isElement(childrenToInsert) && Transforms.insertNodes(editor, childrenToInsert.children, {
|
|
6036
6024
|
at: childInsertPath
|
|
6037
6025
|
}), !0;
|
|
@@ -6416,13 +6404,9 @@ function insertNodePatch(schema, children, operation, beforeValue) {
|
|
|
6416
6404
|
const block = beforeValue[operation.path[0]];
|
|
6417
6405
|
if (operation.path.length === 1) {
|
|
6418
6406
|
const position = operation.path[0] === 0 ? "before" : "after", beforeBlock = beforeValue[operation.path[0] - 1], targetKey = operation.path[0] === 0 ? block?._key : beforeBlock?._key;
|
|
6419
|
-
return targetKey ? [insert([fromSlateBlock({
|
|
6420
|
-
schema
|
|
6421
|
-
}, operation.node, schema.block.name)], position, [{
|
|
6407
|
+
return targetKey ? [insert([fromSlateBlock(operation.node, schema.block.name)], position, [{
|
|
6422
6408
|
_key: targetKey
|
|
6423
|
-
}])] : [setIfMissing(beforeValue, []), insert([fromSlateBlock(
|
|
6424
|
-
schema
|
|
6425
|
-
}, operation.node, schema.block.name)], "before", [operation.path[0]])];
|
|
6409
|
+
}])] : [setIfMissing(beforeValue, []), insert([fromSlateBlock(operation.node, schema.block.name)], "before", [operation.path[0]])];
|
|
6426
6410
|
} else if (isTextBlock({
|
|
6427
6411
|
schema
|
|
6428
6412
|
}, block) && operation.path.length === 2 && children[operation.path[0]]) {
|
|
@@ -6455,9 +6439,7 @@ function splitNodePatch(schema, children, operation, beforeValue) {
|
|
|
6455
6439
|
if (isTextBlock({
|
|
6456
6440
|
schema
|
|
6457
6441
|
}, oldBlock)) {
|
|
6458
|
-
const targetValue = fromSlateBlock(
|
|
6459
|
-
schema
|
|
6460
|
-
}, children[operation.path[0] + 1], schema.block.name);
|
|
6442
|
+
const targetValue = fromSlateBlock(children[operation.path[0] + 1], schema.block.name);
|
|
6461
6443
|
targetValue && (patches.push(insert([targetValue], "after", [{
|
|
6462
6444
|
_key: splitBlock._key
|
|
6463
6445
|
}])), oldBlock.children.slice(operation.position).forEach((span) => {
|
|
@@ -6477,8 +6459,6 @@ function splitNodePatch(schema, children, operation, beforeValue) {
|
|
|
6477
6459
|
schema
|
|
6478
6460
|
}, splitSpan)) {
|
|
6479
6461
|
const targetSpans = fromSlateBlock({
|
|
6480
|
-
schema
|
|
6481
|
-
}, {
|
|
6482
6462
|
...splitBlock,
|
|
6483
6463
|
children: splitBlock.children.slice(operation.path[1] + 1, operation.path[1] + 2)
|
|
6484
6464
|
}, schema.block.name).children;
|
|
@@ -6520,9 +6500,7 @@ function mergeNodePatch(schema, children, operation, beforeValue) {
|
|
|
6520
6500
|
const patches = [], block = beforeValue[operation.path[0]], updatedBlock = children[operation.path[0]];
|
|
6521
6501
|
if (operation.path.length === 1)
|
|
6522
6502
|
if (block?._key) {
|
|
6523
|
-
const newBlock = fromSlateBlock(
|
|
6524
|
-
schema
|
|
6525
|
-
}, children[operation.path[0] - 1], schema.block.name);
|
|
6503
|
+
const newBlock = fromSlateBlock(children[operation.path[0] - 1], schema.block.name);
|
|
6526
6504
|
patches.push(set(newBlock, [{
|
|
6527
6505
|
_key: newBlock._key
|
|
6528
6506
|
}])), patches.push(unset([{
|
|
@@ -7198,7 +7176,7 @@ function createSlateEditor(config) {
|
|
|
7198
7176
|
relayActor: config.relayActor,
|
|
7199
7177
|
subscriptions: config.subscriptions
|
|
7200
7178
|
});
|
|
7201
|
-
return
|
|
7179
|
+
return buildIndexMaps({
|
|
7202
7180
|
schema: config.editorActor.getSnapshot().context.schema,
|
|
7203
7181
|
value: instance.value
|
|
7204
7182
|
}, {
|