@portabletext/editor 2.21.0 → 2.21.2

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.
@@ -1697,7 +1697,7 @@ declare const editorMachine: xstate229.StateMachine<{
1697
1697
  }, xstate229.AnyEventObject>;
1698
1698
  }) => {
1699
1699
  behaviors: Set<{
1700
- behavior: Behavior<"*" | "split" | `custom.${string}` | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle" | "clipboard.copy" | "clipboard.cut" | "clipboard.paste" | "drag.dragstart" | "drag.drag" | "drag.dragend" | "drag.dragenter" | "drag.dragover" | "drag.dragleave" | "drag.drop" | "input.*" | "keyboard.keydown" | "keyboard.keyup" | "mouse.click" | "style.*" | "history.*" | "split.*" | "delete.*" | "select.*" | "deserialize.*" | "serialize.*" | "annotation.*" | "block.*" | "child.*" | "decorator.*" | "insert.*" | "move.*" | "deserialization.*" | "list item.*" | "serialization.*" | "clipboard.*" | "drag.*" | "keyboard.*" | "mouse.*", true, {
1700
+ behavior: Behavior<"*" | "split" | `custom.${string}` | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle" | "clipboard.copy" | "clipboard.cut" | "clipboard.paste" | "drag.dragstart" | "drag.drag" | "drag.dragend" | "drag.dragenter" | "drag.dragover" | "drag.dragleave" | "drag.drop" | "input.*" | "keyboard.keydown" | "keyboard.keyup" | "mouse.click" | "history.*" | "split.*" | "delete.*" | "select.*" | "deserialize.*" | "serialize.*" | "annotation.*" | "block.*" | "child.*" | "decorator.*" | "insert.*" | "move.*" | "deserialization.*" | "list item.*" | "serialization.*" | "style.*" | "clipboard.*" | "drag.*" | "keyboard.*" | "mouse.*", true, {
1701
1701
  type: StrictExtract<"split" | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle", "annotation.add">;
1702
1702
  annotation: {
1703
1703
  name: string;
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.removeNodes(editor, {
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) => toSlateValue([{
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
- })[0], editor;
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
- if (type.name !== types.span.name)
10918
- return editorActor.send({
10919
- type: "behavior event",
10920
- behaviorEvent: {
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
- schemaTypes: editorActor.getSnapshot().context.schema
10953
- })[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode2 = child._type === types.span.name, focusNode = Node.get(editor, focusChildPath);
10954
- return isSpanNode2 && focusNode._type !== types.span.name && (debug$3("Inserting span child next to inline object child, moving selection + 1"), editor.move({
10955
- distance: 1,
10956
- unit: "character"
10957
- })), Transforms.insertNodes(editor, child, {
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: {