@portabletext/editor 1.5.2 → 1.5.4-canary.0
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.esm.js +28 -8
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +28 -8
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +28 -8
- package/lib/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/editor/define-schema.ts +22 -2
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +20 -1
package/lib/index.esm.js
CHANGED
|
@@ -470,7 +470,9 @@ function defineSchema(definition) {
|
|
|
470
470
|
function compileSchemaDefinition(definition) {
|
|
471
471
|
const blockObjects = definition?.blockObjects?.map((blockObject) => defineType({
|
|
472
472
|
type: "object",
|
|
473
|
-
|
|
473
|
+
// Very naive way to work around `SanitySchema.compile` adding default
|
|
474
|
+
// fields to objects with the name `image`
|
|
475
|
+
name: blockObject.name === "image" ? "tmp-image" : blockObject.name,
|
|
474
476
|
title: blockObject.title,
|
|
475
477
|
icon: blockObject.icon,
|
|
476
478
|
fields: []
|
|
@@ -517,8 +519,18 @@ function compileSchemaDefinition(definition) {
|
|
|
517
519
|
}]
|
|
518
520
|
}), schema = Schema.compile({
|
|
519
521
|
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
520
|
-
}).get("portable-text");
|
|
521
|
-
return
|
|
522
|
+
}).get("portable-text"), pteSchema = getPortableTextMemberSchemaTypes(schema);
|
|
523
|
+
return {
|
|
524
|
+
...pteSchema,
|
|
525
|
+
blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? {
|
|
526
|
+
...blockObject,
|
|
527
|
+
name: "image",
|
|
528
|
+
type: {
|
|
529
|
+
...blockObject.type,
|
|
530
|
+
name: "image"
|
|
531
|
+
}
|
|
532
|
+
} : blockObject)
|
|
533
|
+
};
|
|
522
534
|
}
|
|
523
535
|
const rootName = "sanity-pte:";
|
|
524
536
|
debug$m(rootName);
|
|
@@ -3523,7 +3535,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3523
3535
|
const children = Node.children(editor, path);
|
|
3524
3536
|
for (const [child, childPath] of children) {
|
|
3525
3537
|
const nextNode = node.children[childPath[1] + 1];
|
|
3526
|
-
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) &&
|
|
3538
|
+
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
3527
3539
|
debug$c("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
3528
3540
|
type: "normalizing"
|
|
3529
3541
|
}), Transforms.mergeNodes(editor, {
|
|
@@ -3693,22 +3705,30 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3693
3705
|
editor,
|
|
3694
3706
|
blockPath,
|
|
3695
3707
|
spanPath: [op.path[0], op.path[1] - 1]
|
|
3696
|
-
}), nextSpanAnnotations = nextSpan ? nextSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], annotationsEnding = previousSpanAnnotations?.filter((annotation) => !nextSpanAnnotations?.includes(annotation)) ?? [];
|
|
3697
|
-
if (
|
|
3708
|
+
}), nextSpanAnnotations = nextSpan ? nextSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], annotationsEnding = previousSpanAnnotations?.filter((annotation) => !nextSpanAnnotations?.includes(annotation)) ?? [], atTheEndOfAnnotation = annotationsEnding.length > 0;
|
|
3709
|
+
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsEnding.includes(mark))) {
|
|
3698
3710
|
Transforms.insertNodes(editor, {
|
|
3699
3711
|
...op.node,
|
|
3700
3712
|
marks: op.node.marks?.filter((mark) => !annotationsEnding.includes(mark)) ?? []
|
|
3701
3713
|
});
|
|
3702
3714
|
return;
|
|
3703
3715
|
}
|
|
3704
|
-
const annotationsStarting = nextSpanAnnotations?.filter((annotation) => !previousSpanAnnotations?.includes(annotation)) ?? [];
|
|
3705
|
-
if (
|
|
3716
|
+
const annotationsStarting = nextSpanAnnotations?.filter((annotation) => !previousSpanAnnotations?.includes(annotation)) ?? [], atTheStartOfAnnotation = annotationsStarting.length > 0;
|
|
3717
|
+
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsStarting.includes(mark))) {
|
|
3706
3718
|
Transforms.insertNodes(editor, {
|
|
3707
3719
|
...op.node,
|
|
3708
3720
|
marks: op.node.marks?.filter((mark) => !annotationsStarting.includes(mark)) ?? []
|
|
3709
3721
|
});
|
|
3710
3722
|
return;
|
|
3711
3723
|
}
|
|
3724
|
+
const nextSpanDecorators = nextSpan?.marks?.filter((mark) => decorators.includes(mark)) ?? [];
|
|
3725
|
+
if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.length === 0) {
|
|
3726
|
+
Transforms.insertNodes(editor, {
|
|
3727
|
+
...op.node,
|
|
3728
|
+
marks: nextSpanDecorators
|
|
3729
|
+
});
|
|
3730
|
+
return;
|
|
3731
|
+
}
|
|
3712
3732
|
}
|
|
3713
3733
|
}
|
|
3714
3734
|
if (op.type === "insert_text") {
|