@portabletext/editor 3.0.6 → 3.0.8

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 CHANGED
@@ -51,7 +51,7 @@ function toSlateBlock(block, {
51
51
  if (block && block._type === schemaTypes.block.name) {
52
52
  const textBlock = block;
53
53
  let hasInlines = !1;
54
- const hasMissingStyle = typeof textBlock.style > "u", hasMissingMarkDefs = typeof textBlock.markDefs > "u", hasMissingChildren = typeof textBlock.children > "u", children = (textBlock.children || []).map((child) => {
54
+ const hasMissingMarkDefs = typeof textBlock.markDefs > "u", hasMissingChildren = typeof textBlock.children > "u", children = (textBlock.children || []).map((child) => {
55
55
  const {
56
56
  _type: childType,
57
57
  _key: childKey,
@@ -74,12 +74,12 @@ function toSlateBlock(block, {
74
74
  __inline: !0
75
75
  }, keyMap)) : child;
76
76
  });
77
- return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].name), keepObjectEquality({
77
+ return !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block : keepObjectEquality({
78
78
  _type,
79
79
  _key,
80
80
  ...rest,
81
81
  children
82
- }, keyMap));
82
+ }, keyMap);
83
83
  }
84
84
  return keepObjectEquality({
85
85
  _type,
@@ -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,
@@ -142,8 +139,16 @@ function fromSlateBlock(block, textBlockType, keyMap = {}) {
142
139
  ...typeof blockValue == "object" ? blockValue : {}
143
140
  }, keyMap);
144
141
  }
145
- function isEqualToEmptyEditor(children, schemaTypes) {
146
- return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && Element$1.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].name && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !children[0].children[0].marks?.join("") && children[0].children[0].text === "";
142
+ function isEqualToEmptyEditor(blocks, schemaTypes) {
143
+ if (blocks.length !== 1)
144
+ return !1;
145
+ const firstBlock = blocks.at(0);
146
+ if (!firstBlock)
147
+ return !0;
148
+ if (!Element$1.isElement(firstBlock) || firstBlock._type !== schemaTypes.block.name || "listItem" in firstBlock || !("style" in firstBlock) || firstBlock.style !== schemaTypes.styles.at(0)?.name || !Array.isArray(firstBlock.children) || firstBlock.children.length !== 1)
149
+ return !1;
150
+ const firstChild = firstBlock.children.at(0);
151
+ return !(!firstChild || !Text.isText(firstChild) || !("_type" in firstChild) || firstChild._type !== schemaTypes.span.name || firstChild.text !== "" || firstChild.marks?.join(""));
147
152
  }
148
153
  function getFocusBlock({
149
154
  editor
@@ -1849,7 +1854,7 @@ const slateOperationCallback = ({
1849
1854
  });
1850
1855
  function createDecorate(schema, slateEditor) {
1851
1856
  return function([node, path]) {
1852
- if (isEqualToEmptyEditor(slateEditor.children, schema))
1857
+ if (isEqualToEmptyEditor(slateEditor.value, schema))
1853
1858
  return [{
1854
1859
  anchor: {
1855
1860
  path: [0, 0],
@@ -1955,7 +1960,7 @@ function validateSelection(slateEditor, editorElement) {
1955
1960
  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
1961
  }
1957
1962
  }
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) {
1963
+ const debug$g = debugWithName("component:Editable"), PortableTextEditable = forwardRef(function(props, forwardedRef) {
1959
1964
  const $ = c(176);
1960
1965
  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
1966
  $[0] !== props ? ({
@@ -2045,7 +2050,7 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
2045
2050
  $[63] !== editorActor || $[64] !== propsSelection || $[65] !== slateEditor ? (t14 = () => {
2046
2051
  if (propsSelection) {
2047
2052
  debug$g(`Selection from props ${JSON.stringify(propsSelection)}`);
2048
- const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name));
2053
+ const normalizedSelection = normalizeSelection(propsSelection, slateEditor.value);
2049
2054
  if (normalizedSelection !== null) {
2050
2055
  debug$g(`Normalized selection from props ${JSON.stringify(normalizedSelection)}`);
2051
2056
  const slateRange = toSlateRange({
@@ -2145,7 +2150,7 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
2145
2150
  const handleCut = t20;
2146
2151
  let t21;
2147
2152
  $[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({
2153
+ const value = slateEditor.value, path = (slateEditor.selection ? slateRangeToSelection({
2149
2154
  schema: editorActor.getSnapshot().context.schema,
2150
2155
  editor: slateEditor,
2151
2156
  range: slateEditor.selection
@@ -2864,6 +2869,7 @@ function createPlaceholderBlock(context) {
2864
2869
  }]
2865
2870
  };
2866
2871
  }
2872
+ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap();
2867
2873
  function withRemoteChanges(editor, fn) {
2868
2874
  const prev = isChangingRemotely(editor) || !1;
2869
2875
  IS_PROCESSING_REMOTE_CHANGES.set(editor, !0), fn(), IS_PROCESSING_REMOTE_CHANGES.set(editor, prev);
@@ -2974,7 +2980,7 @@ function pluginHistory({
2974
2980
  }) {
2975
2981
  return (editor) => {
2976
2982
  const remotePatches = getRemotePatches(editor);
2977
- let previousSnapshot = fromSlateValue(editor.children, editorActor.getSnapshot().context.schema.block.name), previousUndoStepId = getCurrentUndoStepId(editor);
2983
+ let previousSnapshot = editor.value, previousUndoStepId = getCurrentUndoStepId(editor);
2978
2984
  subscriptions.push(() => {
2979
2985
  const subscription = editorActor.on("patches", ({
2980
2986
  patches,
@@ -3075,7 +3081,7 @@ function createWithPortableTextMarkModel(editorActor) {
3075
3081
  const {
3076
3082
  apply: apply2,
3077
3083
  normalizeNode
3078
- } = editor, decorators = editorActor.getSnapshot().context.schema.decorators.map((t) => t.name);
3084
+ } = editor, decorators = editorActor.getSnapshot().context.schema.decorators.map((t) => t.name), defaultStyle = editorActor.getSnapshot().context.schema.styles.at(0)?.name;
3079
3085
  return editor.normalizeNode = (nodeEntry) => {
3080
3086
  const [node, path] = nodeEntry;
3081
3087
  if (editor.isTextBlock(node)) {
@@ -3103,6 +3109,16 @@ function createWithPortableTextMarkModel(editorActor) {
3103
3109
  });
3104
3110
  return;
3105
3111
  }
3112
+ if (defaultStyle && editor.isTextBlock(node) && typeof node.style > "u") {
3113
+ debug$e("Adding .style to block node"), withNormalizeNode(editor, () => {
3114
+ Transforms.setNodes(editor, {
3115
+ style: defaultStyle
3116
+ }, {
3117
+ at: path
3118
+ });
3119
+ });
3120
+ return;
3121
+ }
3106
3122
  if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
3107
3123
  debug$e("Adding .marks to span node"), withNormalizeNode(editor, () => {
3108
3124
  Transforms.setNodes(editor, {
@@ -4279,37 +4295,16 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
4279
4295
  context,
4280
4296
  operation
4281
4297
  }) => {
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];
4298
+ const blockKey = operation.at[0]._key, blockIndex = operation.editor.blockIndexMap.get(blockKey);
4299
+ if (blockIndex === void 0)
4300
+ throw new Error(`Unable to find block index for block key ${blockKey}`);
4301
+ const block = blockIndex !== void 0 ? operation.editor.value.at(blockIndex) : void 0;
4304
4302
  if (!block)
4305
4303
  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)) {
4304
+ if (isTextBlock(context, block)) {
4310
4305
  const propsToRemove = operation.props.filter((prop) => prop !== "_type"), updatedTextBlock = parseBlock({
4311
4306
  context,
4312
- block: omit(parsedBlock, propsToRemove),
4307
+ block: omit(block, propsToRemove),
4313
4308
  options: {
4314
4309
  normalize: !1,
4315
4310
  removeUnusedMarkDefs: !0,
@@ -4322,13 +4317,13 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
4322
4317
  for (const prop of propsToRemove)
4323
4318
  prop in updatedTextBlock ? propsToSet[prop] = updatedTextBlock[prop] : propsToSet[prop] = void 0;
4324
4319
  Transforms.setNodes(operation.editor, propsToSet, {
4325
- at: location
4320
+ at: [blockIndex]
4326
4321
  });
4327
4322
  return;
4328
4323
  }
4329
4324
  const updatedBlockObject = parseBlock({
4330
4325
  context,
4331
- block: omit(parsedBlock, operation.props.filter((prop) => prop !== "_type")),
4326
+ block: omit(block, operation.props.filter((prop) => prop !== "_type")),
4332
4327
  options: {
4333
4328
  normalize: !1,
4334
4329
  removeUnusedMarkDefs: !0,
@@ -4347,7 +4342,7 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
4347
4342
  _key,
4348
4343
  value: props
4349
4344
  }, {
4350
- at: location
4345
+ at: [blockIndex]
4351
4346
  });
4352
4347
  }, childSetOperationImplementation = ({
4353
4348
  context,
@@ -4429,26 +4424,21 @@ const debug$c = debugWithName("behavior.operation.history.redo"), historyRedoOpe
4429
4424
  context,
4430
4425
  operation
4431
4426
  }) => {
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, {
4427
+ const blockKey = operation.at[0]._key, blockIndex = operation.editor.blockIndexMap.get(blockKey);
4428
+ if (blockIndex === void 0)
4429
+ throw new Error(`Unable to find block index for block key ${blockKey}`);
4430
+ const block = blockIndex !== void 0 ? operation.editor.value.at(blockIndex) : void 0;
4431
+ if (!block)
4432
+ throw new Error(`Unable to find block at ${JSON.stringify(operation.at)}`);
4433
+ if (!isTextBlock(context, block))
4434
+ throw new Error(`Block ${JSON.stringify(blockKey)} is not a text block`);
4435
+ const childKey = operation.at[2]._key;
4436
+ if (!childKey)
4437
+ throw new Error(`Unable to find child key at ${JSON.stringify(operation.at)}`);
4438
+ const childIndex = block.children.findIndex((child2) => child2._key === childKey);
4439
+ if (childIndex === -1)
4440
+ throw new Error(`Unable to find child at ${JSON.stringify(operation.at)}`);
4441
+ const childEntry = Editor.node(operation.editor, [blockIndex, childIndex], {
4452
4442
  depth: 2
4453
4443
  }), child = childEntry?.[0], childPath = childEntry?.[1];
4454
4444
  if (!child || !childPath)
@@ -5637,7 +5627,7 @@ function insertPatch(editor, patch, schema) {
5637
5627
  position: position2
5638
5628
  } = patch, blocksToInsert = items2.map((item) => toSlateBlock(item, {
5639
5629
  schemaTypes: schema
5640
- }, KEY_TO_SLATE_ELEMENT.get(editor))), targetBlockIndex = block.index, normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex, editorWasEmptyBefore = isEqualToEmptyEditor(editor.children, schema);
5630
+ }, KEY_TO_SLATE_ELEMENT.get(editor))), targetBlockIndex = block.index, normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex, editorWasEmptyBefore = isEqualToEmptyEditor(editor.value, schema);
5641
5631
  return Transforms.insertNodes(editor, blocksToInsert, {
5642
5632
  at: [normalizedIdx2]
5643
5633
  }), editorWasEmptyBefore && typeof patch.path[0] == "number" && patch.path[0] === 0 && Transforms.removeNodes(editor, {
@@ -6204,7 +6194,7 @@ function moveNodePatch(schema, beforeValue, operation) {
6204
6194
  const position = operation.path[0] > operation.newPath[0] ? "before" : "after";
6205
6195
  patches.push(unset([{
6206
6196
  _key: block._key
6207
- }])), patches.push(insert([fromSlateBlock(block, schema.block.name)], position, [{
6197
+ }])), patches.push(insert([block], position, [{
6208
6198
  _key: targetBlock._key
6209
6199
  }]));
6210
6200
  } else if (operation.path.length === 2 && isTextBlock({
@@ -6212,7 +6202,7 @@ function moveNodePatch(schema, beforeValue, operation) {
6212
6202
  }, block) && isTextBlock({
6213
6203
  schema
6214
6204
  }, 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]];
6205
+ 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
6206
  patches.push(unset([{
6217
6207
  _key: block._key
6218
6208
  }, "children", {
@@ -6239,10 +6229,10 @@ function createWithPatches({
6239
6229
  relayActor,
6240
6230
  subscriptions
6241
6231
  }) {
6242
- let previousChildren;
6232
+ let previousValue;
6243
6233
  const applyPatch = createApplyPatch(editorActor.getSnapshot().context.schema);
6244
6234
  return function(editor) {
6245
- IS_PROCESSING_REMOTE_CHANGES.set(editor, !1), PATCHING.set(editor, !0), previousChildren = [...editor.children];
6235
+ IS_PROCESSING_REMOTE_CHANGES.set(editor, !1), PATCHING.set(editor, !0), previousValue = [...editor.value];
6246
6236
  const {
6247
6237
  apply: apply2
6248
6238
  } = editor;
@@ -6283,41 +6273,41 @@ function createWithPatches({
6283
6273
  };
6284
6274
  }), editor.apply = (operation) => {
6285
6275
  let patches = [];
6286
- previousChildren = editor.children;
6287
- const editorWasEmpty = isEqualToEmptyEditor(previousChildren, editorActor.getSnapshot().context.schema);
6276
+ previousValue = editor.value;
6277
+ const editorWasEmpty = isEqualToEmptyEditor(previousValue, editorActor.getSnapshot().context.schema);
6288
6278
  apply2(operation);
6289
- const editorIsEmpty = isEqualToEmptyEditor(editor.children, editorActor.getSnapshot().context.schema);
6279
+ const editorIsEmpty = isEqualToEmptyEditor(editor.value, editorActor.getSnapshot().context.schema);
6290
6280
  if (!isPatching(editor))
6291
6281
  return editor;
6292
- switch (editorWasEmpty && !editorIsEmpty && operation.type !== "set_selection" && patches.push(insert(previousChildren, "before", [0])), operation.type) {
6282
+ switch (editorWasEmpty && !editorIsEmpty && operation.type !== "set_selection" && patches.push(insert(previousValue, "before", [0])), operation.type) {
6293
6283
  case "insert_text":
6294
- patches = [...patches, ...insertTextPatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousChildren)];
6284
+ patches = [...patches, ...insertTextPatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
6295
6285
  break;
6296
6286
  case "remove_text":
6297
- patches = [...patches, ...removeTextPatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousChildren)];
6287
+ patches = [...patches, ...removeTextPatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
6298
6288
  break;
6299
6289
  case "remove_node":
6300
- patches = [...patches, ...removeNodePatch(editorActor.getSnapshot().context.schema, previousChildren, operation)];
6290
+ patches = [...patches, ...removeNodePatch(editorActor.getSnapshot().context.schema, previousValue, operation)];
6301
6291
  break;
6302
6292
  case "split_node":
6303
- patches = [...patches, ...splitNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousChildren)];
6293
+ patches = [...patches, ...splitNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
6304
6294
  break;
6305
6295
  case "insert_node":
6306
- patches = [...patches, ...insertNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousChildren)];
6296
+ patches = [...patches, ...insertNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
6307
6297
  break;
6308
6298
  case "set_node":
6309
6299
  patches = [...patches, ...setNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation)];
6310
6300
  break;
6311
6301
  case "merge_node":
6312
- patches = [...patches, ...mergeNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousChildren)];
6302
+ patches = [...patches, ...mergeNodePatch(editorActor.getSnapshot().context.schema, editor.children, operation, previousValue)];
6313
6303
  break;
6314
6304
  case "move_node":
6315
- patches = [...patches, ...moveNodePatch(editorActor.getSnapshot().context.schema, previousChildren, operation)];
6305
+ patches = [...patches, ...moveNodePatch(editorActor.getSnapshot().context.schema, previousValue, operation)];
6316
6306
  break;
6317
6307
  }
6318
6308
  if (!editorWasEmpty && editorIsEmpty && ["merge_node", "set_node", "remove_text", "remove_node"].includes(operation.type) && (patches = [...patches, unset([])], relayActor.send({
6319
6309
  type: "unset",
6320
- previousValue: fromSlateValue(previousChildren, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor))
6310
+ previousValue
6321
6311
  })), editorWasEmpty && patches.length > 0 && (patches = [setIfMissing([], []), ...patches]), patches.length > 0)
6322
6312
  for (const patch of patches)
6323
6313
  editorActor.send({
@@ -6785,14 +6775,14 @@ const withPlugins = (editor, options) => {
6785
6775
  }, debug$7 = debugWithName("setup");
6786
6776
  function createSlateEditor(config) {
6787
6777
  debug$7("Creating new Slate editor instance");
6788
- const instance = withPlugins(withReact(createEditor()), {
6778
+ const placeholderBlock = createPlaceholderBlock(config.editorActor.getSnapshot().context), editor = createEditor();
6779
+ editor.decoratedRanges = [], editor.decoratorState = {}, editor.value = [placeholderBlock], editor.blockIndexMap = /* @__PURE__ */ new Map(), editor.listIndexMap = /* @__PURE__ */ new Map();
6780
+ const instance = withPlugins(withReact(editor), {
6789
6781
  editorActor: config.editorActor,
6790
6782
  relayActor: config.relayActor,
6791
6783
  subscriptions: config.subscriptions
6792
6784
  });
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({
6785
+ KEY_TO_SLATE_ELEMENT.set(instance, {}), buildIndexMaps({
6796
6786
  schema: config.editorActor.getSnapshot().context.schema,
6797
6787
  value: instance.value
6798
6788
  }, {
@@ -10926,18 +10916,18 @@ function createEditableAPI(editor, editorActor) {
10926
10916
  slateSelection ? Transforms.select(editor, slateSelection) : Transforms.deselect(editor), editor.onChange();
10927
10917
  },
10928
10918
  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
- }
10919
+ if (!editor.selection)
10920
+ return;
10921
+ const focusBlockIndex = editor.selection.focus.path.at(0);
10922
+ if (focusBlockIndex !== void 0)
10923
+ return editor.value.at(focusBlockIndex);
10934
10924
  },
10935
10925
  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
- }
10926
+ if (!editor.selection)
10927
+ return;
10928
+ 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;
10929
+ if (block && isTextBlock(editorActor.getSnapshot().context, block))
10930
+ return focusChildIndex === void 0 ? void 0 : block.children.at(focusChildIndex);
10941
10931
  },
10942
10932
  insertChild: (type, value) => (editorActor.send({
10943
10933
  type: "behavior event",
@@ -10992,41 +10982,32 @@ function createEditableAPI(editor, editorActor) {
10992
10982
  },
10993
10983
  isVoid: (element) => ![types.block.name, types.span.name].includes(element._type),
10994
10984
  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
10985
+ const blockKey = getBlockKeyFromSelectionPoint({
10986
+ path
11011
10987
  });
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
- }
10988
+ if (!blockKey)
10989
+ return [void 0, void 0];
10990
+ const blockIndex = editor.blockIndexMap.get(blockKey);
10991
+ if (blockIndex === void 0)
10992
+ return [void 0, void 0];
10993
+ const block = editor.value.at(blockIndex);
10994
+ if (!block)
10995
+ return [void 0, void 0];
10996
+ const childKey = getChildKeyFromSelectionPoint({
10997
+ path
10998
+ });
10999
+ if (path.length === 1 && !childKey)
11000
+ return [block, [{
11001
+ _key: block._key
11002
+ }]];
11003
+ if (isTextBlock(editorActor.getSnapshot().context, block) && childKey) {
11004
+ const child = block.children.find((child2) => child2._key === childKey);
11005
+ if (child)
11006
+ return [child, [{
11007
+ _key: block._key
11008
+ }, "children", {
11009
+ _key: child._key
11010
+ }]];
11030
11011
  }
11031
11012
  return [void 0, void 0];
11032
11013
  },
@@ -11174,7 +11155,7 @@ function createEditableAPI(editor, editorActor) {
11174
11155
  }
11175
11156
  return ptRange;
11176
11157
  },
11177
- getValue: () => fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
11158
+ getValue: () => editor.value,
11178
11159
  isCollapsedSelection: () => !!editor.selection && Range.isCollapsed(editor.selection),
11179
11160
  isExpandedSelection: () => !!editor.selection && Range.isExpanded(editor.selection),
11180
11161
  insertBreak: () => {
@@ -12327,7 +12308,7 @@ function createActors(config) {
12327
12308
  config.editorActor.send({
12328
12309
  ...event,
12329
12310
  type: "internal.patch",
12330
- value: fromSlateValue(config.slateEditor.children, config.editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(config.slateEditor))
12311
+ value: config.slateEditor.value
12331
12312
  });
12332
12313
  break;
12333
12314
  default: