@portabletext/editor 7.10.3 → 7.10.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/lib/index.js +6 -66
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -5934,7 +5934,7 @@ function RenderSpan(props) {
|
|
|
5934
5934
|
if (decoratorSchemaTypes.includes(mark_0))
|
|
5935
5935
|
return [];
|
|
5936
5936
|
const markDef_0 = block?.markDefs?.find((markDef) => markDef._key === mark_0);
|
|
5937
|
-
return markDef_0 ? [markDef_0] : [];
|
|
5937
|
+
return markDef_0 ? [markDef_0] : (console.warn(`Mark ${mark_0} is neither a decorator in the schema nor a markDef key in the block. The mark is kept in the value but does not render. If it is a decorator, add it to the schema.`), []);
|
|
5938
5938
|
}), children = props.children;
|
|
5939
5939
|
for (const mark_1 of decorators) {
|
|
5940
5940
|
const decoratorSchemaType = subSchema.decorators.find((dec) => dec.name === mark_1);
|
|
@@ -5942,7 +5942,7 @@ function RenderSpan(props) {
|
|
|
5942
5942
|
}
|
|
5943
5943
|
for (const annotationMarkDef of annotationMarkDefs) {
|
|
5944
5944
|
const annotationSchemaType = subSchema.annotations.find((t) => t.name === annotationMarkDef._type);
|
|
5945
|
-
annotationSchemaType && (block && props.renderAnnotation ? children = /* @__PURE__ */ jsx("span", { ref: spanRef, children: /* @__PURE__ */ jsx(RenderAnnotation, { renderAnnotation: props.renderAnnotation, block, editorElementRef: spanRef, focused, path: props.path, selected, schemaType: annotationSchemaType, value: annotationMarkDef, children }) }) : children = /* @__PURE__ */ jsx("span", { ref: spanRef, children }));
|
|
5945
|
+
annotationSchemaType || console.warn(`The schema has no annotation type ${annotationMarkDef._type}. The annotation is kept in the value but does not render. Add ${annotationMarkDef._type} to the schema to render it.`), annotationSchemaType && (block && props.renderAnnotation ? children = /* @__PURE__ */ jsx("span", { ref: spanRef, children: /* @__PURE__ */ jsx(RenderAnnotation, { renderAnnotation: props.renderAnnotation, block, editorElementRef: spanRef, focused, path: props.path, selected, schemaType: annotationSchemaType, value: annotationMarkDef, children }) }) : children = /* @__PURE__ */ jsx("span", { ref: spanRef, children }));
|
|
5946
5946
|
}
|
|
5947
5947
|
$[8] = block, $[9] = focused, $[10] = props.children, $[11] = props.leaf.marks, $[12] = props.path, $[13] = props.renderAnnotation, $[14] = props.renderDecorator, $[15] = selected, $[16] = subSchema.annotations, $[17] = subSchema.decorators, $[18] = annotationMarkDefs, $[19] = children;
|
|
5948
5948
|
} else
|
|
@@ -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 = {
|