@portabletext/editor 1.5.2 → 1.5.3
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 +27 -7
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +27 -7
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +27 -7
- package/lib/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/editor/define-schema.ts +22 -2
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +18 -0
package/lib/index.mjs
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);
|
|
@@ -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") {
|