@portabletext/editor 7.10.0 → 7.10.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/lib/index.js +55 -67
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -7717,6 +7717,15 @@ function transformRangeRef(ref, op, root) {
|
|
|
7717
7717
|
});
|
|
7718
7718
|
ref.current = path2, path2 == null && ref.unref();
|
|
7719
7719
|
}
|
|
7720
|
+
function splitNodePath(path2) {
|
|
7721
|
+
let nodePathEnd = path2.length;
|
|
7722
|
+
for (; nodePathEnd > 0 && typeof path2[nodePathEnd - 1] == "string"; )
|
|
7723
|
+
nodePathEnd--;
|
|
7724
|
+
return {
|
|
7725
|
+
nodePath: path2.slice(0, nodePathEnd),
|
|
7726
|
+
propertyPath: path2.slice(nodePathEnd)
|
|
7727
|
+
};
|
|
7728
|
+
}
|
|
7720
7729
|
function findNearestSpans(snapshot, path2) {
|
|
7721
7730
|
return {
|
|
7722
7731
|
previousSpan: findPreviousSpan(snapshot, path2),
|
|
@@ -7787,10 +7796,7 @@ function lastSpanIn(snapshot, path2) {
|
|
|
7787
7796
|
return entry;
|
|
7788
7797
|
}
|
|
7789
7798
|
function nodeParentPath(path2) {
|
|
7790
|
-
|
|
7791
|
-
for (; end2 > 0 && typeof path2[end2 - 1] == "string"; )
|
|
7792
|
-
end2--;
|
|
7793
|
-
return path2.slice(0, end2);
|
|
7799
|
+
return splitNodePath(path2.slice(0, -1)).nodePath;
|
|
7794
7800
|
}
|
|
7795
7801
|
function getValue(root, path2) {
|
|
7796
7802
|
let current = root;
|
|
@@ -8021,7 +8027,7 @@ function applyOperation(editor, op) {
|
|
|
8021
8027
|
const {
|
|
8022
8028
|
nodePath: setNodePath,
|
|
8023
8029
|
propertyPath: setPropertyPath
|
|
8024
|
-
} =
|
|
8030
|
+
} = splitNodePath(path2);
|
|
8025
8031
|
if (setNodePath.length === 0)
|
|
8026
8032
|
break;
|
|
8027
8033
|
if (setPropertyPath.length === 0) {
|
|
@@ -8122,7 +8128,7 @@ function applyOperation(editor, op) {
|
|
|
8122
8128
|
const {
|
|
8123
8129
|
nodePath: unsetNodePath,
|
|
8124
8130
|
propertyPath: unsetPropertyPath
|
|
8125
|
-
} =
|
|
8131
|
+
} = splitNodePath(path2);
|
|
8126
8132
|
if (unsetPropertyPath.length === 0 || unsetNodePath.length === 0)
|
|
8127
8133
|
break;
|
|
8128
8134
|
if (!op.inverse && !editor.isProcessingRemoteChanges) {
|
|
@@ -8229,26 +8235,6 @@ function resolveBlockIndex(editor, segment) {
|
|
|
8229
8235
|
const value = editor.snapshot.context.value, index = editor.blockIndexMap.get(serializePath([segment]));
|
|
8230
8236
|
return index !== void 0 && value[index]?._key === segment._key ? index : value.findIndex((block) => block._key === segment._key);
|
|
8231
8237
|
}
|
|
8232
|
-
function splitNodeAndPropertyPath(path2) {
|
|
8233
|
-
let lastKeyedOrNumericIndex = -1;
|
|
8234
|
-
for (let i = path2.length - 1; i >= 0; i--) {
|
|
8235
|
-
const segment = path2[i];
|
|
8236
|
-
if (isKeyedSegment(segment) || typeof segment == "number") {
|
|
8237
|
-
lastKeyedOrNumericIndex = i;
|
|
8238
|
-
break;
|
|
8239
|
-
}
|
|
8240
|
-
}
|
|
8241
|
-
if (lastKeyedOrNumericIndex === -1)
|
|
8242
|
-
return {
|
|
8243
|
-
nodePath: [],
|
|
8244
|
-
propertyPath: path2.filter((segment) => typeof segment == "string")
|
|
8245
|
-
};
|
|
8246
|
-
const nodePath = path2.slice(0, lastKeyedOrNumericIndex + 1), propertyPath = path2.slice(lastKeyedOrNumericIndex + 1).filter((segment) => typeof segment == "string");
|
|
8247
|
-
return {
|
|
8248
|
-
nodePath,
|
|
8249
|
-
propertyPath
|
|
8250
|
-
};
|
|
8251
|
-
}
|
|
8252
8238
|
function deepSet(node, propertyPath, value) {
|
|
8253
8239
|
if (propertyPath.length === 0)
|
|
8254
8240
|
return node;
|
|
@@ -10489,7 +10475,7 @@ function transformBlockIndexMap(map, op, beforeValue, afterValue, context) {
|
|
|
10489
10475
|
return;
|
|
10490
10476
|
}
|
|
10491
10477
|
if (typeof op.path[op.path.length - 1] == "string") {
|
|
10492
|
-
hasKeyedEntries(
|
|
10478
|
+
hasKeyedEntries(getValue(beforeValue, op.path)) && reconcileOwnerSubtree(map, context, beforeValue, afterValue, op.path);
|
|
10493
10479
|
return;
|
|
10494
10480
|
}
|
|
10495
10481
|
const removeIndex = childIndexFromMap(map, beforeValue, op.path);
|
|
@@ -10517,7 +10503,7 @@ function transformBlockIndexMap(map, op, beforeValue, afterValue, context) {
|
|
|
10517
10503
|
handleKeyChange(map, beforeValue, afterValue, op.path.slice(0, -1), context);
|
|
10518
10504
|
return;
|
|
10519
10505
|
}
|
|
10520
|
-
(op.value !== null && typeof op.value == "object" || hasKeyedEntries(
|
|
10506
|
+
(op.value !== null && typeof op.value == "object" || hasKeyedEntries(getValue(beforeValue, op.path))) && reconcileOwnerSubtree(map, context, beforeValue, afterValue, op.path);
|
|
10521
10507
|
return;
|
|
10522
10508
|
}
|
|
10523
10509
|
const childIndex = childIndexFromMap(map, beforeValue, op.path);
|
|
@@ -10654,33 +10640,14 @@ function resolveIndexableNode(context, value, keyedPath) {
|
|
|
10654
10640
|
};
|
|
10655
10641
|
}
|
|
10656
10642
|
function reconcileOwnerSubtree(map, context, beforeValue, afterValue, propertyPath) {
|
|
10657
|
-
|
|
10658
|
-
|
|
10659
|
-
ownerPathEnd--;
|
|
10660
|
-
if (ownerPathEnd === 0)
|
|
10661
|
-
return;
|
|
10662
|
-
const ownerPath = propertyPath.slice(0, ownerPathEnd);
|
|
10663
|
-
pruneSubtreeAtPath(
|
|
10643
|
+
const ownerPath = splitNodePath(propertyPath).nodePath;
|
|
10644
|
+
ownerPath.length !== 0 && (pruneSubtreeAtPath(
|
|
10664
10645
|
map,
|
|
10665
10646
|
beforeValue,
|
|
10666
10647
|
ownerPath,
|
|
10667
10648
|
/*keepSelf*/
|
|
10668
10649
|
!0
|
|
10669
|
-
), addSubtree(map, context, afterValue, ownerPath);
|
|
10670
|
-
}
|
|
10671
|
-
function resolveValueAtPath(value, path2) {
|
|
10672
|
-
let nodePathEnd = path2.length;
|
|
10673
|
-
for (; nodePathEnd > 0 && typeof path2[nodePathEnd - 1] == "string"; )
|
|
10674
|
-
nodePathEnd--;
|
|
10675
|
-
if (nodePathEnd === 0)
|
|
10676
|
-
return;
|
|
10677
|
-
let current = resolveNodeAtPath(value, path2.slice(0, nodePathEnd));
|
|
10678
|
-
for (let i = nodePathEnd; i < path2.length; i++) {
|
|
10679
|
-
if (current === null || typeof current != "object")
|
|
10680
|
-
return;
|
|
10681
|
-
current = current[path2[i]];
|
|
10682
|
-
}
|
|
10683
|
-
return current;
|
|
10650
|
+
), addSubtree(map, context, afterValue, ownerPath));
|
|
10684
10651
|
}
|
|
10685
10652
|
function hasKeyedEntries(value) {
|
|
10686
10653
|
return Array.isArray(value) && value.some((entry) => entry !== null && typeof entry == "object" && entry._key !== void 0);
|
|
@@ -16900,15 +16867,17 @@ function synthesizeBlockChildrenField(schema) {
|
|
|
16900
16867
|
of: ofMembers
|
|
16901
16868
|
};
|
|
16902
16869
|
}
|
|
16903
|
-
function resolveFieldOn(fields,
|
|
16870
|
+
function resolveFieldOn(fields, fieldName) {
|
|
16904
16871
|
const field = fields.find((candidate) => candidate.name === fieldName);
|
|
16905
|
-
|
|
16906
|
-
|
|
16907
|
-
|
|
16908
|
-
|
|
16909
|
-
|
|
16910
|
-
|
|
16911
|
-
}
|
|
16872
|
+
return field ? isChildArrayField(field) ? containsOnlyPrimitiveTypes(field) ? {
|
|
16873
|
+
failure: "field-primitive-only"
|
|
16874
|
+
} : {
|
|
16875
|
+
field
|
|
16876
|
+
} : {
|
|
16877
|
+
failure: "field-not-array"
|
|
16878
|
+
} : {
|
|
16879
|
+
failure: "field-missing"
|
|
16880
|
+
};
|
|
16912
16881
|
}
|
|
16913
16882
|
function findInlineDeclarationIn(parentOf, type) {
|
|
16914
16883
|
for (const member of parentOf)
|
|
@@ -16936,28 +16905,35 @@ function findInlineFields(schema, type) {
|
|
|
16936
16905
|
isChildArrayField(field) && walk(field.of);
|
|
16937
16906
|
return best;
|
|
16938
16907
|
}
|
|
16939
|
-
function
|
|
16908
|
+
function resolveContainerFieldResolution(schema, type, fieldName, parentOf) {
|
|
16940
16909
|
if (type === "block")
|
|
16941
|
-
return fieldName !== "children" ?
|
|
16910
|
+
return fieldName !== "children" ? {
|
|
16911
|
+
failure: "field-missing"
|
|
16912
|
+
} : {
|
|
16913
|
+
field: synthesizeBlockChildrenField(schema)
|
|
16914
|
+
};
|
|
16942
16915
|
if (parentOf) {
|
|
16943
16916
|
const inlineMatch = findInlineDeclarationIn(parentOf, type);
|
|
16944
16917
|
if (inlineMatch)
|
|
16945
|
-
return resolveFieldOn(inlineMatch,
|
|
16918
|
+
return resolveFieldOn(inlineMatch, fieldName);
|
|
16946
16919
|
}
|
|
16947
16920
|
const rootMatch = schema.blockObjects.find((blockObject) => blockObject.name === type), rootFields = rootMatch && "fields" in rootMatch && rootMatch.fields && rootMatch.fields.length > 0 ? rootMatch.fields : void 0, inlineFields = rootFields ? void 0 : findInlineFields(schema, type), fields = rootFields ?? inlineFields;
|
|
16948
|
-
|
|
16949
|
-
|
|
16921
|
+
return fields ? resolveFieldOn(fields, fieldName) : rootMatch ? {
|
|
16922
|
+
failure: "field-missing"
|
|
16923
|
+
} : {
|
|
16924
|
+
failure: "unknown-type"
|
|
16925
|
+
};
|
|
16950
16926
|
}
|
|
16951
16927
|
function resolveNestedContainer(schema, container, chain = [], onFailure = "warn", parentOf) {
|
|
16952
|
-
const
|
|
16953
|
-
if (
|
|
16954
|
-
const location = chain.length > 0 ? ` (nested inside ${chain.map((type) => `"${type}"`).join(" inside ")})` : "", message = `registerNode:
|
|
16928
|
+
const resolution = resolveContainerFieldResolution(schema, container.type, container.arrayField, parentOf);
|
|
16929
|
+
if ("failure" in resolution) {
|
|
16930
|
+
const location = chain.length > 0 ? ` (nested inside ${chain.map((type) => `"${type}"`).join(" inside ")})` : "", message = `registerNode: ${describeContainerFailure(resolution.failure, container)}${location}. Registration skipped.`;
|
|
16955
16931
|
if (onFailure === "throw")
|
|
16956
16932
|
throw new Error(message);
|
|
16957
16933
|
console.warn(message);
|
|
16958
16934
|
return;
|
|
16959
16935
|
}
|
|
16960
|
-
const nextChain = [...chain, container.type], resolvedOf = container.of ? container.of.flatMap((entry) => {
|
|
16936
|
+
const field = resolution.field, nextChain = [...chain, container.type], resolvedOf = container.of ? container.of.flatMap((entry) => {
|
|
16961
16937
|
if (entry.kind === "container") {
|
|
16962
16938
|
const resolved = resolveNestedContainer(schema, entry, nextChain, onFailure, field.of);
|
|
16963
16939
|
return resolved ? [resolved] : [];
|
|
@@ -16974,6 +16950,18 @@ function resolveNestedContainer(schema, container, chain = [], onFailure = "warn
|
|
|
16974
16950
|
} : {}
|
|
16975
16951
|
};
|
|
16976
16952
|
}
|
|
16953
|
+
function describeContainerFailure(failure, container) {
|
|
16954
|
+
switch (failure) {
|
|
16955
|
+
case "unknown-type":
|
|
16956
|
+
return `type "${container.type}" not found in the schema`;
|
|
16957
|
+
case "field-missing":
|
|
16958
|
+
return `field "${container.arrayField}" not found on type "${container.type}"`;
|
|
16959
|
+
case "field-not-array":
|
|
16960
|
+
return `field "${container.arrayField}" on type "${container.type}" is not an array`;
|
|
16961
|
+
case "field-primitive-only":
|
|
16962
|
+
return `field "${container.arrayField}" on type "${container.type}" contains only primitive types and cannot hold block content`;
|
|
16963
|
+
}
|
|
16964
|
+
}
|
|
16977
16965
|
function resolveTextBlockConfig(textBlock) {
|
|
16978
16966
|
const resolvedOf = textBlock.of ? textBlock.of.flatMap((entry) => entry.kind === "span" ? [{
|
|
16979
16967
|
span: entry
|