@portabletext/editor 2.21.0 → 2.21.1
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 +19 -54
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
- package/src/editor/plugins/createWithEditableAPI.ts +10 -76
- package/src/editor/plugins/createWithUtils.ts +27 -30
- package/src/internal-utils/operation-to-patches.test.ts +61 -1
- package/src/operations/behavior.operation.insert.block.ts +4 -4
package/lib/index.js
CHANGED
|
@@ -4703,11 +4703,11 @@ function insertBlock(options) {
|
|
|
4703
4703
|
}), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
|
|
4704
4704
|
} else {
|
|
4705
4705
|
if (endBlock && isEqualToEmptyEditor([endBlock], context.schema)) {
|
|
4706
|
-
Transforms.
|
|
4707
|
-
at: endBlockPath
|
|
4708
|
-
}), Transforms.insertNodes(editor, [block], {
|
|
4706
|
+
Transforms.insertNodes(editor, [block], {
|
|
4709
4707
|
at: endBlockPath,
|
|
4710
4708
|
select: !1
|
|
4709
|
+
}), Transforms.removeNodes(editor, {
|
|
4710
|
+
at: Path.next(endBlockPath)
|
|
4711
4711
|
}), Transforms.deselect(editor), select === "start" ? Transforms.select(editor, Editor.start(editor, endBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, endBlockPath));
|
|
4712
4712
|
return;
|
|
4713
4713
|
}
|
|
@@ -6378,7 +6378,7 @@ function createWithUtils({
|
|
|
6378
6378
|
editorActor
|
|
6379
6379
|
}) {
|
|
6380
6380
|
return function(editor) {
|
|
6381
|
-
return editor.pteCreateTextBlock = (options) =>
|
|
6381
|
+
return editor.pteCreateTextBlock = (options) => toSlateBlock({
|
|
6382
6382
|
_type: editorActor.getSnapshot().context.schema.block.name,
|
|
6383
6383
|
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
6384
6384
|
style: editorActor.getSnapshot().context.schema.styles[0].name || "normal",
|
|
@@ -6397,9 +6397,9 @@ function createWithUtils({
|
|
|
6397
6397
|
name
|
|
6398
6398
|
}) => name === decorator))
|
|
6399
6399
|
}]
|
|
6400
|
-
}
|
|
6400
|
+
}, {
|
|
6401
6401
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
6402
|
-
})
|
|
6402
|
+
}), editor;
|
|
6403
6403
|
};
|
|
6404
6404
|
}
|
|
6405
6405
|
function pluginUpdateSelection({
|
|
@@ -10913,56 +10913,21 @@ function createEditableAPI(editor, editorActor) {
|
|
|
10913
10913
|
return fromSlateValue([block], types.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0].children[editor.selection.focus.path[1]];
|
|
10914
10914
|
}
|
|
10915
10915
|
},
|
|
10916
|
-
insertChild: (type, value) => {
|
|
10917
|
-
|
|
10918
|
-
|
|
10919
|
-
|
|
10920
|
-
|
|
10921
|
-
type: "insert.inline object",
|
|
10922
|
-
inlineObject: {
|
|
10923
|
-
name: type.name,
|
|
10924
|
-
value
|
|
10925
|
-
}
|
|
10926
|
-
},
|
|
10927
|
-
editor
|
|
10928
|
-
}), editor.selection ? slateRangeToSelection({
|
|
10929
|
-
schema: editorActor.getSnapshot().context.schema,
|
|
10930
|
-
editor,
|
|
10931
|
-
range: editor.selection
|
|
10932
|
-
})?.focus.path ?? [] : [];
|
|
10933
|
-
if (!editor.selection)
|
|
10934
|
-
throw new Error("The editor has no selection");
|
|
10935
|
-
const [focusBlock] = Array.from(Editor.nodes(editor, {
|
|
10936
|
-
at: editor.selection.focus.path.slice(0, 1),
|
|
10937
|
-
match: (n) => n._type === types.block.name
|
|
10938
|
-
}))[0] || [void 0];
|
|
10939
|
-
if (!focusBlock)
|
|
10940
|
-
throw new Error("No focused text block");
|
|
10941
|
-
if (type.name !== types.span.name && !types.inlineObjects.some((t) => t.name === type.name))
|
|
10942
|
-
throw new Error("This type cannot be inserted as a child to a text block");
|
|
10943
|
-
const child = toSlateValue([{
|
|
10944
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
10945
|
-
_type: types.block.name,
|
|
10946
|
-
children: [{
|
|
10947
|
-
_key: editorActor.getSnapshot().context.keyGenerator(),
|
|
10916
|
+
insertChild: (type, value) => (editorActor.send({
|
|
10917
|
+
type: "behavior event",
|
|
10918
|
+
behaviorEvent: {
|
|
10919
|
+
type: "insert.child",
|
|
10920
|
+
child: {
|
|
10948
10921
|
_type: type.name,
|
|
10949
10922
|
...value || {}
|
|
10950
|
-
}
|
|
10951
|
-
}
|
|
10952
|
-
|
|
10953
|
-
|
|
10954
|
-
|
|
10955
|
-
|
|
10956
|
-
|
|
10957
|
-
|
|
10958
|
-
select: !0,
|
|
10959
|
-
at: editor.selection
|
|
10960
|
-
}), editor.onChange(), editor.selection ? slateRangeToSelection({
|
|
10961
|
-
schema: editorActor.getSnapshot().context.schema,
|
|
10962
|
-
editor,
|
|
10963
|
-
range: editor.selection
|
|
10964
|
-
})?.focus.path ?? [] : [];
|
|
10965
|
-
},
|
|
10923
|
+
}
|
|
10924
|
+
},
|
|
10925
|
+
editor
|
|
10926
|
+
}), editor.selection ? slateRangeToSelection({
|
|
10927
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
10928
|
+
editor,
|
|
10929
|
+
range: editor.selection
|
|
10930
|
+
})?.focus.path ?? [] : []),
|
|
10966
10931
|
insertBlock: (type, value) => (editorActor.send({
|
|
10967
10932
|
type: "behavior event",
|
|
10968
10933
|
behaviorEvent: {
|