@portabletext/editor 4.1.2 → 4.1.4
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/LICENSE +1 -1
- package/lib/index.js +30 -8
- package/lib/index.js.map +1 -1
- package/package.json +3 -3
package/LICENSE
CHANGED
package/lib/index.js
CHANGED
|
@@ -4000,6 +4000,7 @@ function createWithNormalize(editorActor) {
|
|
|
4000
4000
|
};
|
|
4001
4001
|
}
|
|
4002
4002
|
function createWithObjectKeys(editorActor) {
|
|
4003
|
+
const context = editorActor.getSnapshot().context;
|
|
4003
4004
|
return function(editor) {
|
|
4004
4005
|
const {
|
|
4005
4006
|
apply: apply2,
|
|
@@ -4015,23 +4016,35 @@ function createWithObjectKeys(editorActor) {
|
|
|
4015
4016
|
return;
|
|
4016
4017
|
}
|
|
4017
4018
|
if (operation.type === "split_node") {
|
|
4018
|
-
const
|
|
4019
|
+
const _key = operation.properties._key && keyExistsAtPath({
|
|
4020
|
+
blockIndexMap: editor.blockIndexMap,
|
|
4021
|
+
context: {
|
|
4022
|
+
schema: context.schema,
|
|
4023
|
+
value: editor.value
|
|
4024
|
+
}
|
|
4025
|
+
}, operation.path, operation.properties._key) ? void 0 : operation.properties._key;
|
|
4019
4026
|
apply2({
|
|
4020
4027
|
...operation,
|
|
4021
4028
|
properties: {
|
|
4022
4029
|
...operation.properties,
|
|
4023
|
-
_key:
|
|
4030
|
+
_key: _key === void 0 ? editorActor.getSnapshot().context.keyGenerator() : _key
|
|
4024
4031
|
}
|
|
4025
4032
|
});
|
|
4026
4033
|
return;
|
|
4027
4034
|
}
|
|
4028
4035
|
if (operation.type === "insert_node" && !Editor.isEditor(operation.node)) {
|
|
4029
|
-
const
|
|
4036
|
+
const _key = operation.node._key && keyExistsAtPath({
|
|
4037
|
+
blockIndexMap: editor.blockIndexMap,
|
|
4038
|
+
context: {
|
|
4039
|
+
schema: context.schema,
|
|
4040
|
+
value: editor.value
|
|
4041
|
+
}
|
|
4042
|
+
}, operation.path, operation.node._key) ? void 0 : operation.node._key;
|
|
4030
4043
|
apply2({
|
|
4031
4044
|
...operation,
|
|
4032
4045
|
node: {
|
|
4033
4046
|
...operation.node,
|
|
4034
|
-
_key:
|
|
4047
|
+
_key: _key === void 0 ? editorActor.getSnapshot().context.keyGenerator() : _key
|
|
4035
4048
|
}
|
|
4036
4049
|
});
|
|
4037
4050
|
return;
|
|
@@ -4166,6 +4179,14 @@ function createWithObjectKeys(editorActor) {
|
|
|
4166
4179
|
}, editor;
|
|
4167
4180
|
};
|
|
4168
4181
|
}
|
|
4182
|
+
function keyExistsAtPath(snapshot, path, key) {
|
|
4183
|
+
if (path.length === 1)
|
|
4184
|
+
return snapshot.blockIndexMap.has(key);
|
|
4185
|
+
if (path.length > 2)
|
|
4186
|
+
return !1;
|
|
4187
|
+
const parentBlockIndex = path.at(0), parentBlock = parentBlockIndex !== void 0 ? snapshot.context.value.at(parentBlockIndex) : void 0;
|
|
4188
|
+
return !parentBlock || !isTextBlock(snapshot.context, parentBlock) ? !1 : parentBlock.children.some((child) => child._key === key);
|
|
4189
|
+
}
|
|
4169
4190
|
function cloneDiff(diff2) {
|
|
4170
4191
|
const [type, patch] = diff2;
|
|
4171
4192
|
return [type, patch];
|
|
@@ -8283,7 +8304,7 @@ function insertBlock(options) {
|
|
|
8283
8304
|
})).at(0) ?? [void 0, void 0];
|
|
8284
8305
|
if (!startBlock || !startBlockPath || !endBlock || !endBlockPath)
|
|
8285
8306
|
throw new Error("Unable to insert block without a start and end block");
|
|
8286
|
-
if (!
|
|
8307
|
+
if (!at) {
|
|
8287
8308
|
if (placement === "before")
|
|
8288
8309
|
Transforms.insertNodes(editor, [block], {
|
|
8289
8310
|
at: [0]
|
|
@@ -8629,7 +8650,7 @@ function performOperation({
|
|
|
8629
8650
|
context,
|
|
8630
8651
|
operation
|
|
8631
8652
|
}) {
|
|
8632
|
-
|
|
8653
|
+
const perform = () => {
|
|
8633
8654
|
try {
|
|
8634
8655
|
switch (operation.type) {
|
|
8635
8656
|
case "annotation.add": {
|
|
@@ -8760,9 +8781,10 @@ function performOperation({
|
|
|
8760
8781
|
}
|
|
8761
8782
|
}
|
|
8762
8783
|
} catch (error) {
|
|
8763
|
-
console.error(new Error(`
|
|
8784
|
+
console.error(new Error(`Performing "${operation.type}" failed due to: ${error.message}`));
|
|
8764
8785
|
}
|
|
8765
|
-
}
|
|
8786
|
+
};
|
|
8787
|
+
Editor.isNormalizing(operation.editor) ? Editor.withoutNormalizing(operation.editor, perform) : perform();
|
|
8766
8788
|
}
|
|
8767
8789
|
const abstractAnnotationBehaviors = [defineBehavior({
|
|
8768
8790
|
on: "annotation.set",
|