@portabletext/editor 3.0.6 → 3.0.7

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.
@@ -6,7 +6,7 @@ import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
6
6
  import * as react18 from "react";
7
7
  import React$1, { BaseSyntheticEvent, ClipboardEvent, Component, FocusEvent, JSX, KeyboardEvent as KeyboardEvent$1, MutableRefObject, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
8
8
  import { Patch, Patch as Patch$1 } from "@portabletext/patches";
9
- import * as _portabletext_schema6 from "@portabletext/schema";
9
+ import * as _portabletext_schema5 from "@portabletext/schema";
10
10
  import { AnnotationDefinition, AnnotationSchemaType, BaseDefinition, BlockObjectDefinition, BlockObjectSchemaType, DecoratorDefinition, DecoratorSchemaType, FieldDefinition, InlineObjectDefinition, InlineObjectSchemaType, ListDefinition, ListSchemaType, PortableTextObject as PortableTextObject$1, PortableTextSpan as PortableTextSpan$1, PortableTextTextBlock as PortableTextTextBlock$1, Schema, SchemaDefinition, SchemaDefinition as SchemaDefinition$1, StyleDefinition, StyleSchemaType, defineSchema } from "@portabletext/schema";
11
11
  import { Observable, Subject } from "rxjs";
12
12
  import { DOMNode } from "slate-dom";
@@ -1935,7 +1935,7 @@ declare const editorMachine: xstate228.StateMachine<{
1935
1935
  keyGenerator: () => string;
1936
1936
  pendingEvents: never[];
1937
1937
  pendingIncomingPatchesEvents: never[];
1938
- schema: _portabletext_schema6.Schema;
1938
+ schema: _portabletext_schema5.Schema;
1939
1939
  selection: null;
1940
1940
  initialReadOnly: boolean;
1941
1941
  initialValue: PortableTextBlock[] | undefined;
package/lib/index.js CHANGED
@@ -93,9 +93,6 @@ function toSlateBlock(block, {
93
93
  value: rest
94
94
  }, keyMap);
95
95
  }
96
- function fromSlateValue(value, textBlockType, keyMap = {}) {
97
- return value.map((block) => fromSlateBlock(block, textBlockType, keyMap));
98
- }
99
96
  function fromSlateBlock(block, textBlockType, keyMap = {}) {
100
97
  const {
101
98
  _key,
@@ -1849,7 +1846,7 @@ const slateOperationCallback = ({
1849
1846
  });
1850
1847
  function createDecorate(schema, slateEditor) {
1851
1848
  return function([node, path]) {
1852
- if (isEqualToEmptyEditor(slateEditor.children, schema))
1849
+ if (isEqualToEmptyEditor(slateEditor.value, schema))
1853
1850
  return [{
1854
1851
  anchor: {
1855
1852
  path: [0, 0],
@@ -1955,7 +1952,7 @@ function validateSelection(slateEditor, editorElement) {
1955
1952
  debug$h("Could not resolve selection, selecting top document"), Transforms.deselect(slateEditor), slateEditor.children.length > 0 && Transforms.select(slateEditor, Editor.start(slateEditor, [])), slateEditor.onChange();
1956
1953
  }
1957
1954
  }
1958
- const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), debug$g = debugWithName("component:Editable"), PortableTextEditable = forwardRef(function(props, forwardedRef) {
1955
+ const debug$g = debugWithName("component:Editable"), PortableTextEditable = forwardRef(function(props, forwardedRef) {
1959
1956
  const $ = c(176);
1960
1957
  let hotkeys, onBeforeInput, onBlur, onClick, onCopy, onCut, onDrag, onDragEnd, onDragEnter, onDragLeave, onDragOver, onDragStart, onDrop, onFocus, onPaste, propsSelection, rangeDecorations, renderAnnotation, renderBlock, renderChild, renderDecorator, renderListItem, renderPlaceholder, renderStyle, restProps, scrollSelectionIntoView, spellCheck;
1961
1958
  $[0] !== props ? ({
@@ -2045,7 +2042,7 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
2045
2042
  $[63] !== editorActor || $[64] !== propsSelection || $[65] !== slateEditor ? (t14 = () => {
2046
2043
  if (propsSelection) {
2047
2044
  debug$g(`Selection from props ${JSON.stringify(propsSelection)}`);
2048
- const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name));
2045
+ const normalizedSelection = normalizeSelection(propsSelection, slateEditor.value);
2049
2046
  if (normalizedSelection !== null) {
2050
2047
  debug$g(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
2051
2048
  const slateRange = toSlateRange({
@@ -2145,7 +2142,7 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
2145
2142
  const handleCut = t20;
2146
2143
  let t21;
2147
2144
  $[85] !== editorActor || $[86] !== onPaste || $[87] !== portableTextEditor || $[88] !== relayActor || $[89] !== slateEditor ? (t21 = (event_1) => {
2148
- const value = fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditor)), path = (slateEditor.selection ? slateRangeToSelection({
2145
+ const value = slateEditor.value, path = (slateEditor.selection ? slateRangeToSelection({
2149
2146
  schema: editorActor.getSnapshot().context.schema,
2150
2147
  editor: slateEditor,
2151
2148
  range: slateEditor.selection
@@ -2864,6 +2861,7 @@ function createPlaceholderBlock(context) {
2864
2861
  }]
2865
2862
  };
2866
2863
  }
2864
+ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap();
2867
2865
  function withRemoteChanges(editor, fn) {
2868
2866
  const prev = isChangingRemotely(editor) || !1;
2869
2867
  IS_PROCESSING_REMOTE_CHANGES.set(editor, !0), fn(), IS_PROCESSING_REMOTE_CHANGES.set(editor, prev);
@@ -2974,7 +2972,7 @@ function pluginHistory({
2974
2972
  }) {
2975
2973
  return (editor) => {
2976
2974
  const remotePatches = getRemotePatches(editor);
2977
- let previousSnapshot = fromSlateValue(editor.children, editorActor.getSnapshot().context.schema.block.name), previousUndoStepId = getCurrentUndoStepId(editor);
2975
+ let previousSnapshot = editor.value, previousUndoStepId = getCurrentUndoStepId(editor);
2978
2976
  subscriptions.push(() => {
2979
2977
  const subscription = editorActor.on("patches", ({
2980
2978
  patches,
@@ -4279,37 +4277,16 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
4279
4277
  context,
4280
4278
  operation
4281
4279
  }) => {
4282
- const location = toSlateRange({
4283
- context: {
4284
- schema: context.schema,
4285
- value: operation.editor.value,
4286
- selection: {
4287
- anchor: {
4288
- path: operation.at,
4289
- offset: 0
4290
- },
4291
- focus: {
4292
- path: operation.at,
4293
- offset: 0
4294
- }
4295
- }
4296
- },
4297
- blockIndexMap: operation.editor.blockIndexMap
4298
- });
4299
- if (!location)
4300
- throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
4301
- const block = Editor.node(operation.editor, location, {
4302
- depth: 1
4303
- })?.[0];
4280
+ const blockKey = operation.at[0]._key, blockIndex = operation.editor.blockIndexMap.get(blockKey);
4281
+ if (blockIndex === void 0)
4282
+ throw new Error(`Unable to find block index for block key ${blockKey}`);
4283
+ const block = blockIndex !== void 0 ? operation.editor.value.at(blockIndex) : void 0;
4304
4284
  if (!block)
4305
4285
  throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
4306
- const parsedBlock = fromSlateBlock(block, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(operation.editor));
4307
- if (!parsedBlock)
4308
- throw new Error(`Unable to parse block at ${JSON.stringify(operation.at)}`);
4309
- if (isTextBlock(context, parsedBlock)) {
4286
+ if (isTextBlock(context, block)) {
4310
4287
  const propsToRemove = operation.props.filter((prop) => prop !== "_type"), updatedTextBlock = parseBlock({
4311
4288
  context,
4312
- block: omit(parsedBlock, propsToRemove),
4289
+ block: omit(block, propsToRemove),
4313
4290
  options: {
4314
4291
  normalize: !1,
4315
4292
  removeUnusedMarkDefs: !0,
@@ -4322,13 +4299,13 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
4322
4299
  for (const prop of propsToRemove)
4323
4300
  prop in updatedTextBlock ? propsToSet[prop] = updatedTextBlock[prop] : propsToSet[prop] = void 0;
4324
4301
  Transforms.setNodes(operation.editor, propsToSet, {
4325
- at: location
4302
+ at: [blockIndex]
4326
4303
  });
4327
4304
  return;
4328
4305
  }
4329
4306
  const updatedBlockObject = parseBlock({
4330
4307
  context,
4331
- block: omit(parsedBlock, operation.props.filter((prop) => prop !== "_type")),
4308
+ block: omit(block, operation.props.filter((prop) => prop !== "_type")),
4332
4309
  options: {
4333
4310
  normalize: !1,
4334
4311
  removeUnusedMarkDefs: !0,
@@ -4347,7 +4324,7 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
4347
4324
  _key,
4348
4325
  value: props
4349
4326
  }, {
4350
- at: location
4327
+ at: [blockIndex]
4351
4328
  });
4352
4329
  }, childSetOperationImplementation = ({
4353
4330
  context,
@@ -4429,26 +4406,21 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
4429
4406
  context,
4430
4407
  operation
4431
4408
  }) => {
4432
- const location = toSlateRange({
4433
- context: {
4434
- schema: context.schema,
4435
- value: operation.editor.value,
4436
- selection: {
4437
- anchor: {
4438
- path: operation.at,
4439
- offset: 0
4440
- },
4441
- focus: {
4442
- path: operation.at,
4443
- offset: 0
4444
- }
4445
- }
4446
- },
4447
- blockIndexMap: operation.editor.blockIndexMap
4448
- });
4449
- if (!location)
4450
- throw new Error(`Unable to convert ${JSON.stringify(operation.at)} into a Slate Range`);
4451
- const childEntry = Editor.node(operation.editor, location, {
4409
+ const blockKey = operation.at[0]._key, blockIndex = operation.editor.blockIndexMap.get(blockKey);
4410
+ if (blockIndex === void 0)
4411
+ throw new Error(`Unable to find block index for block key ${blockKey}`);
4412
+ const block = blockIndex !== void 0 ? operation.editor.value.at(blockIndex) : void 0;
4413
+ if (!block)
4414
+ throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
4415
+ if (!isTextBlock(context, block))
4416
+ throw new Error(`Block ${JSON.stringify(blockKey)} is not a text block`);
4417
+ const childKey = operation.at[2]._key;
4418
+ if (!childKey)
4419
+ throw new Error(`Unable to find child key at ${JSON.stringify(operation.at)}`);
4420
+ const childIndex = block.children.findIndex((child2) => child2._key === childKey);
4421
+ if (childIndex === -1)
4422
+ throw new Error(`Unable to find child at ${JSON.stringify(operation.at)}`);
4423
+ const childEntry = Editor.node(operation.editor, [blockIndex, childIndex], {
4452
4424
  depth: 2
4453
4425
  }), child = childEntry?.[0], childPath = childEntry?.[1];
4454
4426
  if (!child || !childPath)
@@ -5637,7 +5609,7 @@ function insertPatch(editor, patch, schema) {
5637
5609
  position: position2
5638
5610
  } = patch, blocksToInsert = items2.map((item) => toSlateBlock(item, {
5639
5611
  schemaTypes: schema
5640
- }, KEY_TO_SLATE_ELEMENT.get(editor))), targetBlockIndex = block.index, normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex, editorWasEmptyBefore = isEqualToEmptyEditor(editor.children, schema);
5612
+ }, KEY_TO_SLATE_ELEMENT.get(editor))), targetBlockIndex = block.index, normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex, editorWasEmptyBefore = isEqualToEmptyEditor(editor.value, schema);
5641
5613
  return Transforms.insertNodes(editor, blocksToInsert, {
5642
5614
  at: [normalizedIdx2]
5643
5615
  }), editorWasEmptyBefore && typeof patch.path[0] == "number" && patch.path[0] === 0 && Transforms.removeNodes(editor, {
@@ -6204,7 +6176,7 @@ function moveNodePatch(schema, beforeValue, operation) {
6204
6176
  const position = operation.path[0] > operation.newPath[0] ? "before" : "after";
6205
6177
  patches.push(unset([{
6206
6178
  _key: block._key
6207
- }])), patches.push(insert([fromSlateBlock(block, schema.block.name)], position, [{
6179
+ }])), patches.push(insert([block], position, [{
6208
6180
  _key: targetBlock._key
6209
6181
  }]));
6210
6182
  } else if (operation.path.length === 2 && isTextBlock({
@@ -6212,7 +6184,7 @@ function moveNodePatch(schema, beforeValue, operation) {
6212
6184
  }, block) && isTextBlock({
6213
6185
  schema
6214
6186
  }, targetBlock)) {
6215
- const child = block.children[operation.path[1]], targetChild = targetBlock.children[operation.newPath[1]], position = operation.newPath[1] === targetBlock.children.length ? "after" : "before", childToInsert = fromSlateBlock(block, schema.block.name).children[operation.path[1]];
6187
+ const child = block.children[operation.path[1]], targetChild = targetBlock.children[operation.newPath[1]], position = operation.newPath[1] === targetBlock.children.length ? "after" : "before", childToInsert = block.children[operation.path[1]];
6216
6188
  patches.push(unset([{
6217
6189
  _key: block._key
6218
6190
  }, "children", {
@@ -6239,10 +6211,10 @@ function createWithPatches({
6239
6211
  relayActor,
6240
6212
  subscriptions
6241
6213
  }) {
6242
- let previousChildren;
6214
+ let previousValue;
6243
6215
  const applyPatch = createApplyPatch(editorActor.getSnapshot().context.schema);
6244
6216
  return function(editor) {
6245
- IS_PROCESSING_REMOTE_CHANGES.set(editor, !1), PATCHING.set(editor, !0), previousChildren = [...editor.children];
6217
+ IS_PROCESSING_REMOTE_CHANGES.set(editor, !1), PATCHING.set(editor, !0), previousValue = [...editor.value];
6246
6218
  const {
6247
6219
  apply: apply2
6248
6220
  } = editor;
@@ -6283,41 +6255,41 @@ function createWithPatches({
6283
6255
  };
6284
6256
  }), editor.apply = (operation) => {
6285
6257
  let patches = [];
6286
- previousChildren = editor.children;
6287
- const editorWasEmpty = isEqualToEmptyEditor(previousChildren, editorActor.getSnapshot().context.schema);
6258
+ previousValue = editor.value;
6259
+ const editorWasEmpty = isEqualToEmptyEditor(previousValue, editorActor.getSnapshot().context.schema);
6288
6260
  apply2(operation);
6289
- const editorIsEmpty = isEqualToEmptyEditor(editor.children, editorActor.getSnapshot().context.schema);
6261
+ const editorIsEmpty = isEqualToEmptyEditor(editor.value, editorActor.getSnapshot().context.schema);
6290
6262
  if (!isPatching(editor))
6291
6263
  return editor;
6292
- switch (editorWasEmpty && !editorIsEmpty && operation.type !== "set_selection" && patches.push(insert(previousChildren, "before", [0])), operation.type) {
6264
+ switch (editorWasEmpty && !editorIsEmpty && operation.type !== "set_selection" && patches.push(insert(previousValue, "before", [0])), operation.type) {
6293
6265
  case "insert_text":
6294
- patches = [...patches, ...insertTextPatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousChildren)];
6266
+ patches = [...patches, ...insertTextPatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
6295
6267
  break;
6296
6268
  case "remove_text":
6297
- patches = [...patches, ...removeTextPatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousChildren)];
6269
+ patches = [...patches, ...removeTextPatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
6298
6270
  break;
6299
6271
  case "remove_node":
6300
- patches = [...patches, ...removeNodePatch(editorActor.getSnapshot().context.schema, previousChildren, operation)];
6272
+ patches = [...patches, ...removeNodePatch(editorActor.getSnapshot().context.schema, previousValue, operation)];
6301
6273
  break;
6302
6274
  case "split_node":
6303
- patches = [...patches, ...splitNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousChildren)];
6275
+ patches = [...patches, ...splitNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
6304
6276
  break;
6305
6277
  case "insert_node":
6306
- patches = [...patches, ...insertNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousChildren)];
6278
+ patches = [...patches, ...insertNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
6307
6279
  break;
6308
6280
  case "set_node":
6309
6281
  patches = [...patches, ...setNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation)];
6310
6282
  break;
6311
6283
  case "merge_node":
6312
- patches = [...patches, ...mergeNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousChildren)];
6284
+ patches = [...patches, ...mergeNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
6313
6285
  break;
6314
6286
  case "move_node":
6315
- patches = [...patches, ...moveNodePatch(editorActor.getSnapshot().context.schema, previousChildren, operation)];
6287
+ patches = [...patches, ...moveNodePatch(editorActor.getSnapshot().context.schema, previousValue, operation)];
6316
6288
  break;
6317
6289
  }
6318
6290
  if (!editorWasEmpty && editorIsEmpty && ["merge_node", "set_node", "remove_text", "remove_node"].includes(operation.type) && (patches = [...patches, unset([])], relayActor.send({
6319
6291
  type: "unset",
6320
- previousValue: fromSlateValue(previousChildren, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor))
6292
+ previousValue
6321
6293
  })), editorWasEmpty && patches.length > 0 && (patches = [setIfMissing([], []), ...patches]), patches.length > 0)
6322
6294
  for (const patch of patches)
6323
6295
  editorActor.send({
@@ -6785,14 +6757,14 @@ const withPlugins = (editor, options) => {
6785
6757
  }, debug$7 = debugWithName("setup");
6786
6758
  function createSlateEditor(config) {
6787
6759
  debug$7("Creating new Slate editor instance");
6788
- const instance = withPlugins(withReact(createEditor()), {
6760
+ const placeholderBlock = createPlaceholderBlock(config.editorActor.getSnapshot().context), editor = createEditor();
6761
+ editor.decoratedRanges = [], editor.decoratorState = {}, editor.value = [placeholderBlock], editor.blockIndexMap = /* @__PURE__ */ new Map(), editor.listIndexMap = /* @__PURE__ */ new Map();
6762
+ const instance = withPlugins(withReact(editor), {
6789
6763
  editorActor: config.editorActor,
6790
6764
  relayActor: config.relayActor,
6791
6765
  subscriptions: config.subscriptions
6792
6766
  });
6793
- KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {}), instance.decoratedRanges = [], instance.decoratorState = {};
6794
- const placeholderBlock = createPlaceholderBlock(config.editorActor.getSnapshot().context);
6795
- instance.value = [placeholderBlock], instance.blockIndexMap = /* @__PURE__ */ new Map(), instance.listIndexMap = /* @__PURE__ */ new Map(), buildIndexMaps({
6767
+ KEY_TO_SLATE_ELEMENT.set(instance, {}), buildIndexMaps({
6796
6768
  schema: config.editorActor.getSnapshot().context.schema,
6797
6769
  value: instance.value
6798
6770
  }, {
@@ -10926,18 +10898,18 @@ function createEditableAPI(editor, editorActor) {
10926
10898
  slateSelection ? Transforms.select(editor, slateSelection) : Transforms.deselect(editor), editor.onChange();
10927
10899
  },
10928
10900
  focusBlock: () => {
10929
- if (editor.selection) {
10930
- const block = Node.descendant(editor, editor.selection.focus.path.slice(0, 1));
10931
- if (block)
10932
- return fromSlateBlock(block, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor));
10933
- }
10901
+ if (!editor.selection)
10902
+ return;
10903
+ const focusBlockIndex = editor.selection.focus.path.at(0);
10904
+ if (focusBlockIndex !== void 0)
10905
+ return editor.value.at(focusBlockIndex);
10934
10906
  },
10935
10907
  focusChild: () => {
10936
- if (editor.selection) {
10937
- const block = Node.descendant(editor, editor.selection.focus.path.slice(0, 1));
10938
- if (block && editor.isTextBlock(block))
10939
- return fromSlateBlock(block, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)).children[editor.selection.focus.path[1]];
10940
- }
10908
+ if (!editor.selection)
10909
+ return;
10910
+ const focusBlockIndex = editor.selection.focus.path.at(0), focusChildIndex = editor.selection.focus.path.at(1), block = focusBlockIndex !== void 0 ? editor.value.at(focusBlockIndex) : void 0;
10911
+ if (block && isTextBlock(editorActor.getSnapshot().context, block))
10912
+ return focusChildIndex === void 0 ? void 0 : block.children.at(focusChildIndex);
10941
10913
  },
10942
10914
  insertChild: (type, value) => (editorActor.send({
10943
10915
  type: "behavior event",
@@ -10992,41 +10964,32 @@ function createEditableAPI(editor, editorActor) {
10992
10964
  },
10993
10965
  isVoid: (element) => ![types.block.name, types.span.name].includes(element._type),
10994
10966
  findByPath: (path) => {
10995
- const slatePath = toSlateRange({
10996
- context: {
10997
- schema: editorActor.getSnapshot().context.schema,
10998
- value: editor.value,
10999
- selection: {
11000
- focus: {
11001
- path,
11002
- offset: 0
11003
- },
11004
- anchor: {
11005
- path,
11006
- offset: 0
11007
- }
11008
- }
11009
- },
11010
- blockIndexMap: editor.blockIndexMap
10967
+ const blockKey = getBlockKeyFromSelectionPoint({
10968
+ path
11011
10969
  });
11012
- if (slatePath) {
11013
- const [block, blockPath] = Editor.node(editor, slatePath.focus.path.slice(0, 1));
11014
- if (block && blockPath && typeof block._key == "string") {
11015
- if (path.length === 1 && slatePath.focus.path.length === 1)
11016
- return [fromSlateBlock(block, types.block.name), [{
11017
- _key: block._key
11018
- }]];
11019
- const ptBlock = fromSlateBlock(block, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor));
11020
- if (editor.isTextBlock(ptBlock)) {
11021
- const ptChild = ptBlock.children[slatePath.focus.path[1]];
11022
- if (ptChild)
11023
- return [ptChild, [{
11024
- _key: block._key
11025
- }, "children", {
11026
- _key: ptChild._key
11027
- }]];
11028
- }
11029
- }
10970
+ if (!blockKey)
10971
+ return [void 0, void 0];
10972
+ const blockIndex = editor.blockIndexMap.get(blockKey);
10973
+ if (blockIndex === void 0)
10974
+ return [void 0, void 0];
10975
+ const block = editor.value.at(blockIndex);
10976
+ if (!block)
10977
+ return [void 0, void 0];
10978
+ const childKey = getChildKeyFromSelectionPoint({
10979
+ path
10980
+ });
10981
+ if (path.length === 1 && !childKey)
10982
+ return [block, [{
10983
+ _key: block._key
10984
+ }]];
10985
+ if (isTextBlock(editorActor.getSnapshot().context, block) && childKey) {
10986
+ const child = block.children.find((child2) => child2._key === childKey);
10987
+ if (child)
10988
+ return [child, [{
10989
+ _key: block._key
10990
+ }, "children", {
10991
+ _key: child._key
10992
+ }]];
11030
10993
  }
11031
10994
  return [void 0, void 0];
11032
10995
  },
@@ -11174,7 +11137,7 @@ function createEditableAPI(editor, editorActor) {
11174
11137
  }
11175
11138
  return ptRange;
11176
11139
  },
11177
- getValue: () => fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
11140
+ getValue: () => editor.value,
11178
11141
  isCollapsedSelection: () => !!editor.selection && Range.isCollapsed(editor.selection),
11179
11142
  isExpandedSelection: () => !!editor.selection && Range.isExpanded(editor.selection),
11180
11143
  insertBreak: () => {
@@ -12327,7 +12290,7 @@ function createActors(config) {
12327
12290
  config.editorActor.send({
12328
12291
  ...event,
12329
12292
  type: "internal.patch",
12330
- value: fromSlateValue(config.slateEditor.children, config.editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(config.slateEditor))
12293
+ value: config.slateEditor.value
12331
12294
  });
12332
12295
  break;
12333
12296
  default: