@portabletext/editor 7.10.3 → 7.10.5
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 +4 -64
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -9051,51 +9051,17 @@ const normalizeNode = (editor, entry) => {
|
|
|
9051
9051
|
if (isSpan({
|
|
9052
9052
|
schema: editor.snapshot.context.schema
|
|
9053
9053
|
}, node)) {
|
|
9054
|
-
const blockPath = parentPath(path2);
|
|
9055
|
-
if (!
|
|
9054
|
+
const blockPath = parentPath(path2), blockEntry = getTextBlock(editor.snapshot, blockPath);
|
|
9055
|
+
if (!blockEntry)
|
|
9056
9056
|
return;
|
|
9057
|
-
const
|
|
9057
|
+
const annotations = node.marks?.filter((mark) => blockEntry.node.markDefs?.some((markDef) => markDef._key === mark));
|
|
9058
9058
|
if (node.text === "" && annotations && annotations.length > 0) {
|
|
9059
9059
|
debug.normalization("removing annotations from empty span node"), setNodeProperties(editor, {
|
|
9060
|
-
marks: node.marks?.filter((mark) =>
|
|
9060
|
+
marks: node.marks?.filter((mark) => !annotations.includes(mark))
|
|
9061
9061
|
}, path2);
|
|
9062
9062
|
return;
|
|
9063
9063
|
}
|
|
9064
9064
|
}
|
|
9065
|
-
if (isTextBlock({
|
|
9066
|
-
schema: editor.snapshot.context.schema
|
|
9067
|
-
}, node)) {
|
|
9068
|
-
const decorators = getPathSubSchema(editor.snapshot, path2).decorators.map((decorator) => decorator.name);
|
|
9069
|
-
for (const {
|
|
9070
|
-
node: child,
|
|
9071
|
-
path: childPath
|
|
9072
|
-
} of getChildren(editor.snapshot, path2))
|
|
9073
|
-
if (isSpan({
|
|
9074
|
-
schema: editor.snapshot.context.schema
|
|
9075
|
-
}, child)) {
|
|
9076
|
-
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
9077
|
-
if (orphanedAnnotations.length > 0) {
|
|
9078
|
-
debug.normalization("removing orphaned annotations from span node"), setNodeProperties(editor, {
|
|
9079
|
-
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
9080
|
-
}, childPath);
|
|
9081
|
-
return;
|
|
9082
|
-
}
|
|
9083
|
-
}
|
|
9084
|
-
}
|
|
9085
|
-
if (isSpan({
|
|
9086
|
-
schema: editor.snapshot.context.schema
|
|
9087
|
-
}, node)) {
|
|
9088
|
-
const blockPath = parentPath(path2), blockEntry2 = getTextBlock(editor.snapshot, blockPath);
|
|
9089
|
-
if (blockEntry2) {
|
|
9090
|
-
const block = blockEntry2.node, decorators = getPathSubSchema(editor.snapshot, path2).decorators.map((decorator) => decorator.name), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
9091
|
-
if (orphanedAnnotations.length > 0) {
|
|
9092
|
-
debug.normalization("removing orphaned annotations from span node"), setNodeProperties(editor, {
|
|
9093
|
-
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
9094
|
-
}, path2);
|
|
9095
|
-
return;
|
|
9096
|
-
}
|
|
9097
|
-
}
|
|
9098
|
-
}
|
|
9099
9065
|
if (isTextBlock({
|
|
9100
9066
|
schema: editor.snapshot.context.schema
|
|
9101
9067
|
}, node)) {
|
|
@@ -18094,32 +18060,6 @@ function validateValue(value, types, keyGenerator) {
|
|
|
18094
18060
|
}
|
|
18095
18061
|
}, !0;
|
|
18096
18062
|
}
|
|
18097
|
-
const orphanedMarks = allUsedMarks.filter((mark) => !types.decorators.map((dec) => dec.name).includes(mark)).filter((mark) => textBlock.markDefs === void 0 || !textBlock.markDefs.find((def) => def._key === mark));
|
|
18098
|
-
if (orphanedMarks.length > 0) {
|
|
18099
|
-
const spanChildren = textBlock.children.filter((cld) => cld._type === types.span.name && Array.isArray(cld.marks) && cld.marks.some((mark) => orphanedMarks.includes(mark)));
|
|
18100
|
-
if (spanChildren) {
|
|
18101
|
-
const orphaned = orphanedMarks.join(", ");
|
|
18102
|
-
return resolution = {
|
|
18103
|
-
autoResolve: !0,
|
|
18104
|
-
patches: spanChildren.map((child) => set((child.marks || []).filter((cMrk) => !orphanedMarks.includes(cMrk)), [{
|
|
18105
|
-
_key: blk._key
|
|
18106
|
-
}, "children", {
|
|
18107
|
-
_key: child._key
|
|
18108
|
-
}, "marks"])),
|
|
18109
|
-
description: `Block with _key '${blk._key}' contains marks (${orphaned}) not supported by the current content model.`,
|
|
18110
|
-
action: "Remove invalid marks",
|
|
18111
|
-
item: blk,
|
|
18112
|
-
i18n: {
|
|
18113
|
-
description: "inputs.portable-text.invalid-value.orphaned-marks.description",
|
|
18114
|
-
action: "inputs.portable-text.invalid-value.orphaned-marks.action",
|
|
18115
|
-
values: {
|
|
18116
|
-
key: blk._key,
|
|
18117
|
-
orphanedMarks: orphanedMarks.map((m) => m.toString())
|
|
18118
|
-
}
|
|
18119
|
-
}
|
|
18120
|
-
}, !0;
|
|
18121
|
-
}
|
|
18122
|
-
}
|
|
18123
18063
|
textBlock.children.some((child, cIndex) => {
|
|
18124
18064
|
if (typeof child != "object" || child === null)
|
|
18125
18065
|
return resolution = {
|