@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.js
CHANGED
|
@@ -449,7 +449,9 @@ function defineSchema(definition) {
|
|
|
449
449
|
function compileSchemaDefinition(definition) {
|
|
450
450
|
const blockObjects = definition?.blockObjects?.map((blockObject) => types.defineType({
|
|
451
451
|
type: "object",
|
|
452
|
-
|
|
452
|
+
// Very naive way to work around `SanitySchema.compile` adding default
|
|
453
|
+
// fields to objects with the name `image`
|
|
454
|
+
name: blockObject.name === "image" ? "tmp-image" : blockObject.name,
|
|
453
455
|
title: blockObject.title,
|
|
454
456
|
icon: blockObject.icon,
|
|
455
457
|
fields: []
|
|
@@ -496,8 +498,18 @@ function compileSchemaDefinition(definition) {
|
|
|
496
498
|
}]
|
|
497
499
|
}), schema$1 = schema.Schema.compile({
|
|
498
500
|
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
499
|
-
}).get("portable-text");
|
|
500
|
-
return
|
|
501
|
+
}).get("portable-text"), pteSchema = getPortableTextMemberSchemaTypes(schema$1);
|
|
502
|
+
return {
|
|
503
|
+
...pteSchema,
|
|
504
|
+
blockObjects: pteSchema.blockObjects.map((blockObject) => blockObject.name === "tmp-image" ? {
|
|
505
|
+
...blockObject,
|
|
506
|
+
name: "image",
|
|
507
|
+
type: {
|
|
508
|
+
...blockObject.type,
|
|
509
|
+
name: "image"
|
|
510
|
+
}
|
|
511
|
+
} : blockObject)
|
|
512
|
+
};
|
|
501
513
|
}
|
|
502
514
|
const rootName = "sanity-pte:";
|
|
503
515
|
debug__default.default(rootName);
|
|
@@ -3672,22 +3684,30 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
3672
3684
|
editor,
|
|
3673
3685
|
blockPath,
|
|
3674
3686
|
spanPath: [op.path[0], op.path[1] - 1]
|
|
3675
|
-
}), nextSpanAnnotations = nextSpan ? nextSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], annotationsEnding = previousSpanAnnotations?.filter((annotation) => !nextSpanAnnotations?.includes(annotation)) ?? [];
|
|
3676
|
-
if (
|
|
3687
|
+
}), nextSpanAnnotations = nextSpan ? nextSpan.marks?.filter((mark) => !decorators.includes(mark)) : [], annotationsEnding = previousSpanAnnotations?.filter((annotation) => !nextSpanAnnotations?.includes(annotation)) ?? [], atTheEndOfAnnotation = annotationsEnding.length > 0;
|
|
3688
|
+
if (atTheEndOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsEnding.includes(mark))) {
|
|
3677
3689
|
slate.Transforms.insertNodes(editor, {
|
|
3678
3690
|
...op.node,
|
|
3679
3691
|
marks: op.node.marks?.filter((mark) => !annotationsEnding.includes(mark)) ?? []
|
|
3680
3692
|
});
|
|
3681
3693
|
return;
|
|
3682
3694
|
}
|
|
3683
|
-
const annotationsStarting = nextSpanAnnotations?.filter((annotation) => !previousSpanAnnotations?.includes(annotation)) ?? [];
|
|
3684
|
-
if (
|
|
3695
|
+
const annotationsStarting = nextSpanAnnotations?.filter((annotation) => !previousSpanAnnotations?.includes(annotation)) ?? [], atTheStartOfAnnotation = annotationsStarting.length > 0;
|
|
3696
|
+
if (atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.some((mark) => annotationsStarting.includes(mark))) {
|
|
3685
3697
|
slate.Transforms.insertNodes(editor, {
|
|
3686
3698
|
...op.node,
|
|
3687
3699
|
marks: op.node.marks?.filter((mark) => !annotationsStarting.includes(mark)) ?? []
|
|
3688
3700
|
});
|
|
3689
3701
|
return;
|
|
3690
3702
|
}
|
|
3703
|
+
const nextSpanDecorators = nextSpan?.marks?.filter((mark) => decorators.includes(mark)) ?? [];
|
|
3704
|
+
if (nextSpanDecorators.length > 0 && atTheEndOfAnnotation && !atTheStartOfAnnotation && isPortableTextSpan(op.node) && op.node.marks?.length === 0) {
|
|
3705
|
+
slate.Transforms.insertNodes(editor, {
|
|
3706
|
+
...op.node,
|
|
3707
|
+
marks: nextSpanDecorators
|
|
3708
|
+
});
|
|
3709
|
+
return;
|
|
3710
|
+
}
|
|
3691
3711
|
}
|
|
3692
3712
|
}
|
|
3693
3713
|
if (op.type === "insert_text") {
|