@portabletext/editor 4.2.4 → 4.3.0

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
@@ -951,7 +951,7 @@ function performHotkey({
951
951
  const possibleMark = hotkeys[cat];
952
952
  if (possibleMark) {
953
953
  const mark = possibleMark[hotkey];
954
- editorActor.send({
954
+ mark && editorActor.send({
955
955
  type: "behavior event",
956
956
  behaviorEvent: {
957
957
  type: "decorator.toggle",
@@ -970,7 +970,7 @@ function performHotkey({
970
970
  const possibleCommand = hotkeys[cat];
971
971
  if (possibleCommand) {
972
972
  const command = possibleCommand[hotkey];
973
- command(event, portableTextEditor);
973
+ command && command(event, portableTextEditor);
974
974
  }
975
975
  }
976
976
  }
@@ -1249,10 +1249,10 @@ const slateOperationCallback = ({
1249
1249
  });
1250
1250
  function createDecorate(schema, slateEditor) {
1251
1251
  return function([node, path]) {
1252
- const defaultStyle = schema.styles.at(0)?.name;
1253
- if (slateEditor.value.length === 1 && isEmptyTextBlock({
1252
+ const defaultStyle = schema.styles.at(0)?.name, firstBlock = slateEditor.value[0];
1253
+ if (slateEditor.value.length === 1 && firstBlock && isEmptyTextBlock({
1254
1254
  schema
1255
- }, slateEditor.value[0]) && (!slateEditor.value[0].style || slateEditor.value[0].style === defaultStyle) && !slateEditor.value[0].listItem)
1255
+ }, firstBlock) && (!firstBlock.style || firstBlock.style === defaultStyle) && !firstBlock.listItem)
1256
1256
  return [{
1257
1257
  anchor: {
1258
1258
  path: [0, 0],
@@ -3082,7 +3082,7 @@ const entityMap = {
3082
3082
  "=": "="
3083
3083
  };
3084
3084
  function escapeHtml(str) {
3085
- return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s]);
3085
+ return String(str).replace(/[&<>"'`=/]/g, (s) => entityMap[s] ?? s);
3086
3086
  }
3087
3087
  function createCoreConverters(legacySchema) {
3088
3088
  return [converterJson, converterPortableText, converterTextMarkdown, createConverterTextHtml(legacySchema), createConverterTextPlain(legacySchema)];
@@ -3284,7 +3284,7 @@ function createEditableAPI(editor, editorActor) {
3284
3284
  at: [],
3285
3285
  match: (n) => n._key === element._key
3286
3286
  }) || [])[0] || [void 0];
3287
- node = ReactEditor.toDOMNode(editor, item);
3287
+ item && (node = ReactEditor.toDOMNode(editor, item));
3288
3288
  } catch {
3289
3289
  }
3290
3290
  return node;
@@ -3475,7 +3475,7 @@ function createPlaceholderBlock(context) {
3475
3475
  return {
3476
3476
  _type: context.schema.block.name,
3477
3477
  _key: context.keyGenerator(),
3478
- style: context.schema.styles[0].name ?? "normal",
3478
+ style: context.schema.styles[0]?.name ?? "normal",
3479
3479
  markDefs: [],
3480
3480
  children: [{
3481
3481
  _type: context.schema.span.name,
@@ -5129,7 +5129,10 @@ function splitNodePatch(schema, children, operation, beforeValue) {
5129
5129
  if (isTextBlock({
5130
5130
  schema
5131
5131
  }, oldBlock)) {
5132
- const targetValue = fromSlateBlock(children[operation.path[0] + 1], schema.block.name);
5132
+ const nextBlock = children[operation.path[0] + 1];
5133
+ if (!nextBlock)
5134
+ return patches;
5135
+ const targetValue = fromSlateBlock(nextBlock, schema.block.name);
5133
5136
  targetValue && (patches.push(insert([targetValue], "after", [{
5134
5137
  _key: splitBlock._key
5135
5138
  }])), oldBlock.children.slice(operation.position).forEach((span) => {
@@ -5190,7 +5193,10 @@ function mergeNodePatch(schema, children, operation, beforeValue) {
5190
5193
  const patches = [], block = beforeValue[operation.path[0]], updatedBlock = children[operation.path[0]];
5191
5194
  if (operation.path.length === 1)
5192
5195
  if (block?._key) {
5193
- const newBlock = fromSlateBlock(children[operation.path[0] - 1], schema.block.name);
5196
+ const prevBlock = children[operation.path[0] - 1];
5197
+ if (!prevBlock)
5198
+ throw new Error("Previous block not found!");
5199
+ const newBlock = fromSlateBlock(prevBlock, schema.block.name);
5194
5200
  patches.push(set(newBlock, [{
5195
5201
  _key: newBlock._key
5196
5202
  }])), patches.push(unset([{
@@ -5222,7 +5228,7 @@ function mergeNodePatch(schema, children, operation, beforeValue) {
5222
5228
  }
5223
5229
  function moveNodePatch(schema, beforeValue, operation) {
5224
5230
  const patches = [], block = beforeValue[operation.path[0]], targetBlock = beforeValue[operation.newPath[0]];
5225
- if (!targetBlock)
5231
+ if (!targetBlock || !block)
5226
5232
  return patches;
5227
5233
  if (operation.path.length === 1) {
5228
5234
  const position = operation.path[0] > operation.newPath[0] ? "before" : "after";
@@ -5237,6 +5243,8 @@ function moveNodePatch(schema, beforeValue, operation) {
5237
5243
  schema
5238
5244
  }, targetBlock)) {
5239
5245
  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]];
5246
+ if (!child || !targetChild || !childToInsert)
5247
+ return patches;
5240
5248
  patches.push(unset([{
5241
5249
  _key: block._key
5242
5250
  }, "children", {
@@ -5284,7 +5292,7 @@ function createPatchesPlugin({
5284
5292
  try {
5285
5293
  changed = applyPatch(editor, patch), changed ? debug.syncPatch(`(applied) ${JSON.stringify(patch, null, 2)}`) : debug.syncPatch(`(ignored) ${JSON.stringify(patch, null, 2)}`);
5286
5294
  } catch (error) {
5287
- console.error(`Applying patch ${JSON.stringify(patch)} failed due to: ${error.message}`);
5295
+ console.error(`Applying patch ${JSON.stringify(patch)} failed due to: ${error instanceof Error ? error.message : error}`);
5288
5296
  }
5289
5297
  });
5290
5298
  });
@@ -6196,14 +6204,25 @@ function setDragGhost({
6196
6204
  const addAnnotationOnCollapsedSelection = defineBehavior({
6197
6205
  on: "annotation.add",
6198
6206
  guard: ({
6199
- snapshot
6207
+ snapshot,
6208
+ event
6200
6209
  }) => {
6201
- if (!isSelectionCollapsed$1(snapshot))
6210
+ const at = event.at ?? snapshot.context.selection;
6211
+ if (!at)
6202
6212
  return !1;
6203
- const caretWordSelection = getCaretWordSelection(snapshot);
6204
- return !caretWordSelection || !isSelectionExpanded({
6213
+ const adjustedSnapshot = {
6214
+ ...snapshot,
6205
6215
  context: {
6206
6216
  ...snapshot.context,
6217
+ selection: at
6218
+ }
6219
+ };
6220
+ if (!isSelectionCollapsed$1(adjustedSnapshot))
6221
+ return !1;
6222
+ const caretWordSelection = getCaretWordSelection(adjustedSnapshot);
6223
+ return !caretWordSelection || !isSelectionExpanded({
6224
+ context: {
6225
+ ...adjustedSnapshot.context,
6207
6226
  selection: caretWordSelection
6208
6227
  }
6209
6228
  }) ? !1 : {
@@ -6228,15 +6247,28 @@ const addAnnotationOnCollapsedSelection = defineBehavior({
6228
6247
  guard: ({
6229
6248
  snapshot,
6230
6249
  event
6231
- }) => isActiveAnnotation(event.annotation.name, {
6232
- mode: "partial"
6233
- })(snapshot),
6250
+ }) => {
6251
+ const at = event.at ?? snapshot.context.selection;
6252
+ if (!at)
6253
+ return !1;
6254
+ const adjustedSnapshot = {
6255
+ ...snapshot,
6256
+ context: {
6257
+ ...snapshot.context,
6258
+ selection: at
6259
+ }
6260
+ };
6261
+ return isActiveAnnotation(event.annotation.name, {
6262
+ mode: "partial"
6263
+ })(adjustedSnapshot);
6264
+ },
6234
6265
  // Then the existing annotation is removed
6235
6266
  actions: [({
6236
6267
  event
6237
6268
  }) => [raise({
6238
6269
  type: "annotation.remove",
6239
- annotation: event.annotation
6270
+ annotation: event.annotation,
6271
+ at: event.at
6240
6272
  }), raise(event)]]
6241
6273
  }), stripAnnotationsOnFullSpanDeletion = defineBehavior({
6242
6274
  on: "delete",
@@ -7070,7 +7102,7 @@ function isAtTheBeginningOfBlock({
7070
7102
  context,
7071
7103
  block
7072
7104
  }) {
7073
- return !isTextBlock(context, block) || !context.selection || !isSelectionCollapsed(context.selection) ? !1 : getChildKeyFromSelectionPoint(context.selection.focus) === block.children[0]._key && context.selection.focus.offset === 0;
7105
+ return !isTextBlock(context, block) || !context.selection || !isSelectionCollapsed(context.selection) ? !1 : getChildKeyFromSelectionPoint(context.selection.focus) === block.children[0]?._key && context.selection.focus.offset === 0;
7074
7106
  }
7075
7107
  const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
7076
7108
  on: "delete.backward",
@@ -7098,7 +7130,7 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
7098
7130
  snapshot
7099
7131
  }) => {
7100
7132
  const selectionCollapsed = isSelectionCollapsed$1(snapshot), focusTextBlock = getFocusTextBlock(snapshot), focusSpan = getFocusSpan$1(snapshot);
7101
- return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
7133
+ return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]?._key === focusSpan.node._key && snapshot.context.selection?.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
7102
7134
  focusTextBlock,
7103
7135
  level: focusTextBlock.node.level - 1
7104
7136
  } : !1;
@@ -7531,17 +7563,26 @@ const addAnnotationOperationImplementation = ({
7531
7563
  });
7532
7564
  if (!parsedAnnotation)
7533
7565
  throw new Error(`Failed to parse annotation ${JSON.stringify(operation.annotation)}`);
7534
- const editor = operation.editor;
7535
- if (!editor.selection || Range.isCollapsed(editor.selection))
7566
+ const editor = operation.editor, at = operation.at ? toSlateRange({
7567
+ context: {
7568
+ schema: context.schema,
7569
+ value: operation.editor.value,
7570
+ selection: operation.at
7571
+ },
7572
+ blockIndexMap: operation.editor.blockIndexMap
7573
+ }) : null, effectiveSelection = at ?? editor.selection;
7574
+ if (!effectiveSelection || Range.isCollapsed(effectiveSelection))
7536
7575
  return;
7537
- const selectedBlocks = Editor.nodes(editor, {
7538
- at: editor.selection,
7576
+ const rangeRef = at ? Editor.rangeRef(editor, at, {
7577
+ affinity: "inward"
7578
+ }) : null, selectedBlocks = Editor.nodes(editor, {
7579
+ at: effectiveSelection,
7539
7580
  match: (node) => editor.isTextBlock(node),
7540
- reverse: Range.isBackward(editor.selection)
7581
+ reverse: Range.isBackward(effectiveSelection)
7541
7582
  });
7542
7583
  let blockIndex = 0;
7543
7584
  for (const [block, blockPath] of selectedBlocks) {
7544
- if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
7585
+ if (block.children.length === 0 || block.children.length === 1 && block.children[0]?.text === "")
7545
7586
  continue;
7546
7587
  const annotationKey = blockIndex === 0 ? parsedAnnotation._key : context.keyGenerator(), markDefs = block.markDefs ?? [];
7547
7588
  markDefs.find((markDef) => markDef._type === parsedAnnotation._type && markDef._key === annotationKey) === void 0 && Transforms.setNodes(editor, {
@@ -7551,13 +7592,17 @@ const addAnnotationOperationImplementation = ({
7551
7592
  }]
7552
7593
  }, {
7553
7594
  at: blockPath
7554
- }), Transforms.setNodes(editor, {}, {
7595
+ }), at ? Transforms.setNodes(editor, {}, {
7596
+ match: Text.isText,
7597
+ split: !0,
7598
+ at
7599
+ }) : Transforms.setNodes(editor, {}, {
7555
7600
  match: Text.isText,
7556
7601
  split: !0
7557
7602
  });
7558
- const children = Node.children(editor, blockPath);
7603
+ const children = Node.children(editor, blockPath), selectionRange = rangeRef?.current ?? editor.selection;
7559
7604
  for (const [span, path] of children) {
7560
- if (!editor.isTextSpan(span) || !Range.includes(editor.selection, path))
7605
+ if (!editor.isTextSpan(span) || !selectionRange || !Range.includes(selectionRange, path))
7561
7606
  continue;
7562
7607
  const marks = span.marks ?? [];
7563
7608
  Transforms.setNodes(editor, {
@@ -7568,18 +7613,27 @@ const addAnnotationOperationImplementation = ({
7568
7613
  }
7569
7614
  blockIndex++;
7570
7615
  }
7616
+ rangeRef?.unref();
7571
7617
  }, removeAnnotationOperationImplementation = ({
7618
+ context,
7572
7619
  operation
7573
7620
  }) => {
7574
- const editor = operation.editor;
7575
- if (editor.selection)
7576
- if (Range.isCollapsed(editor.selection)) {
7577
- const [block, blockPath] = Editor.node(editor, editor.selection, {
7621
+ const editor = operation.editor, at = operation.at ? toSlateRange({
7622
+ context: {
7623
+ schema: context.schema,
7624
+ value: operation.editor.value,
7625
+ selection: operation.at
7626
+ },
7627
+ blockIndexMap: operation.editor.blockIndexMap
7628
+ }) : null, effectiveSelection = at ?? editor.selection;
7629
+ if (effectiveSelection)
7630
+ if (Range.isCollapsed(effectiveSelection)) {
7631
+ const [block, blockPath] = Editor.node(editor, effectiveSelection, {
7578
7632
  depth: 1
7579
7633
  });
7580
7634
  if (!editor.isTextBlock(block))
7581
7635
  return;
7582
- const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === operation.annotation.name), [selectedChild, selectedChildPath] = Editor.node(editor, editor.selection, {
7636
+ const potentialAnnotations = (block.markDefs ?? []).filter((markDef) => markDef._type === operation.annotation.name), [selectedChild, selectedChildPath] = Editor.node(editor, effectiveSelection, {
7583
7637
  depth: 2
7584
7638
  });
7585
7639
  if (!editor.isTextSpan(selectedChild))
@@ -7610,19 +7664,27 @@ const addAnnotationOperationImplementation = ({
7610
7664
  at: childPath
7611
7665
  });
7612
7666
  } else {
7613
- Transforms.setNodes(editor, {}, {
7667
+ const rangeRef = at ? Editor.rangeRef(editor, at, {
7668
+ affinity: "inward"
7669
+ }) : null;
7670
+ at ? Transforms.setNodes(editor, {}, {
7671
+ match: (node) => editor.isTextSpan(node),
7672
+ split: !0,
7673
+ hanging: !0,
7674
+ at
7675
+ }) : Transforms.setNodes(editor, {}, {
7614
7676
  match: (node) => editor.isTextSpan(node),
7615
7677
  split: !0,
7616
7678
  hanging: !0
7617
7679
  });
7618
7680
  const blocks = Editor.nodes(editor, {
7619
- at: editor.selection,
7681
+ at: effectiveSelection,
7620
7682
  match: (node) => editor.isTextBlock(node)
7621
- });
7683
+ }), selectionRange = rangeRef?.current ?? editor.selection;
7622
7684
  for (const [block, blockPath] of blocks) {
7623
7685
  const children = Node.children(editor, blockPath);
7624
7686
  for (const [child, childPath] of children) {
7625
- if (!editor.isTextSpan(child) || !Range.includes(editor.selection, childPath))
7687
+ if (!editor.isTextSpan(child) || !selectionRange || !Range.includes(selectionRange, childPath))
7626
7688
  continue;
7627
7689
  const markDefs = block.markDefs ?? [], marks = child.marks ?? [], marksWithoutAnnotation = marks.filter((mark) => markDefs.find((markDef2) => markDef2._key === mark)?._type !== operation.annotation.name);
7628
7690
  marksWithoutAnnotation.length !== marks.length && Transforms.setNodes(editor, {
@@ -7632,6 +7694,7 @@ const addAnnotationOperationImplementation = ({
7632
7694
  });
7633
7695
  }
7634
7696
  }
7697
+ rangeRef?.unref();
7635
7698
  }
7636
7699
  }, blockSetOperationImplementation = ({
7637
7700
  context,
@@ -8256,7 +8319,7 @@ const historyRedoOperationImplementation = ({
8256
8319
  });
8257
8320
  });
8258
8321
  } catch (err) {
8259
- console.error(`Could not perform 'history.redo' operation: ${err.message}`), editor.remotePatches.splice(0, editor.remotePatches.length), Transforms.deselect(editor), editor.history = {
8322
+ console.error(`Could not perform 'history.redo' operation: ${err instanceof Error ? err.message : err}`), editor.remotePatches.splice(0, editor.remotePatches.length), Transforms.deselect(editor), editor.history = {
8260
8323
  undos: [],
8261
8324
  redos: []
8262
8325
  }, editor.withHistory = !0, editor.isRedoing = !1, editor.onChange();
@@ -8296,7 +8359,7 @@ const historyUndoOperationImplementation = ({
8296
8359
  });
8297
8360
  });
8298
8361
  } catch (err) {
8299
- console.error(`Could not perform 'history.undo' operation: ${err.message}`), editor.remotePatches.splice(0, editor.remotePatches.length), Transforms.deselect(editor), editor.history = {
8362
+ console.error(`Could not perform 'history.undo' operation: ${err instanceof Error ? err.message : err}`), editor.remotePatches.splice(0, editor.remotePatches.length), Transforms.deselect(editor), editor.history = {
8300
8363
  undos: [],
8301
8364
  redos: []
8302
8365
  }, editor.withHistory = !0, editor.isUndoing = !1, editor.onChange();
@@ -9217,7 +9280,7 @@ function performOperation({
9217
9280
  }
9218
9281
  }
9219
9282
  } catch (error) {
9220
- console.error(new Error(`Performing "${operation.type}" failed due to: ${error.message}`));
9283
+ console.error(new Error(`Performing "${operation.type}" failed due to: ${error instanceof Error ? error.message : error}`));
9221
9284
  }
9222
9285
  };
9223
9286
  Editor.isNormalizing(operation.editor) ? Editor.withoutNormalizing(operation.editor, perform) : perform();
@@ -9283,24 +9346,50 @@ const abstractAnnotationBehaviors = [defineBehavior({
9283
9346
  guard: ({
9284
9347
  snapshot,
9285
9348
  event
9286
- }) => isActiveAnnotation(event.annotation.name)(snapshot),
9349
+ }) => {
9350
+ const at = event.at ?? snapshot.context.selection;
9351
+ if (!at)
9352
+ return !1;
9353
+ const adjustedSnapshot = {
9354
+ ...snapshot,
9355
+ context: {
9356
+ ...snapshot.context,
9357
+ selection: at
9358
+ }
9359
+ };
9360
+ return isActiveAnnotation(event.annotation.name)(adjustedSnapshot);
9361
+ },
9287
9362
  actions: [({
9288
9363
  event
9289
9364
  }) => [raise({
9290
9365
  type: "annotation.remove",
9291
- annotation: event.annotation
9366
+ annotation: event.annotation,
9367
+ at: event.at
9292
9368
  })]]
9293
9369
  }), defineBehavior({
9294
9370
  on: "annotation.toggle",
9295
9371
  guard: ({
9296
9372
  snapshot,
9297
9373
  event
9298
- }) => !isActiveAnnotation(event.annotation.name)(snapshot),
9374
+ }) => {
9375
+ const at = event.at ?? snapshot.context.selection;
9376
+ if (!at)
9377
+ return !1;
9378
+ const adjustedSnapshot = {
9379
+ ...snapshot,
9380
+ context: {
9381
+ ...snapshot.context,
9382
+ selection: at
9383
+ }
9384
+ };
9385
+ return !isActiveAnnotation(event.annotation.name)(adjustedSnapshot);
9386
+ },
9299
9387
  actions: [({
9300
9388
  event
9301
9389
  }) => [raise({
9302
9390
  type: "annotation.add",
9303
- annotation: event.annotation
9391
+ annotation: event.annotation,
9392
+ at: event.at
9304
9393
  })]]
9305
9394
  })], abstractDecoratorBehaviors = [defineBehavior({
9306
9395
  on: "decorator.toggle",
@@ -11072,7 +11161,7 @@ function performEvent({
11072
11161
  dom: createEditorDom(sendBack, editor)
11073
11162
  });
11074
11163
  } catch (error) {
11075
- console.error(new Error(`Evaluating guard for "${event.type}" failed due to: ${error.message}`));
11164
+ console.error(new Error(`Evaluating guard for "${event.type}" failed due to: ${error instanceof Error ? error.message : error}`));
11076
11165
  }
11077
11166
  if (!shouldRun)
11078
11167
  continue;
@@ -11095,7 +11184,7 @@ function performEvent({
11095
11184
  dom: createEditorDom(sendBack, editor)
11096
11185
  }, shouldRun);
11097
11186
  } catch (error) {
11098
- console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
11187
+ console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error instanceof Error ? error.message : error}`));
11099
11188
  }
11100
11189
  if (actions.length === 0)
11101
11190
  continue;
@@ -11111,7 +11200,7 @@ function performEvent({
11111
11200
  send: sendBack
11112
11201
  });
11113
11202
  } catch (error) {
11114
- console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
11203
+ console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error instanceof Error ? error.message : error}`));
11115
11204
  }
11116
11205
  continue;
11117
11206
  }
@@ -11340,7 +11429,7 @@ const editorMachine = setup({
11340
11429
  try {
11341
11430
  ReactEditor.blur(event.editor);
11342
11431
  } catch (error) {
11343
- console.error(new Error(`Failed to blur editor: ${error.message}`));
11432
+ console.error(new Error(`Failed to blur editor: ${error instanceof Error ? error.message : error}`));
11344
11433
  }
11345
11434
  },
11346
11435
  "handle focus": ({
@@ -11355,7 +11444,7 @@ const editorMachine = setup({
11355
11444
  const currentSelection = slateEditor.selection;
11356
11445
  ReactEditor.focus(slateEditor), currentSelection && (Transforms.select(slateEditor, currentSelection), EDITOR_TO_PENDING_SELECTION.set(slateEditor, slateEditor.selection), slateEditor.onChange());
11357
11446
  } catch (error) {
11358
- console.error(new Error(`Failed to focus editor: ${error.message}`));
11447
+ console.error(new Error(`Failed to focus editor: ${error instanceof Error ? error.message : error}`));
11359
11448
  }
11360
11449
  },
11361
11450
  "handle behavior event": ({
@@ -11391,7 +11480,7 @@ const editorMachine = setup({
11391
11480
  }
11392
11481
  });
11393
11482
  } catch (error) {
11394
- console.error(new Error(`Raising "${event.behaviorEvent.type}" failed due to: ${error.message}`));
11483
+ console.error(new Error(`Raising "${event.behaviorEvent.type}" failed due to: ${error instanceof Error ? error.message : error}`));
11395
11484
  }
11396
11485
  },
11397
11486
  "sort behaviors": assign({
@@ -11601,7 +11690,7 @@ const editorMachine = setup({
11601
11690
  try {
11602
11691
  context.dragGhost.parentNode?.removeChild(context.dragGhost);
11603
11692
  } catch (error) {
11604
- console.error(new Error(`Removing the drag ghost failed due to: ${error.message}`));
11693
+ console.error(new Error(`Removing the drag ghost failed due to: ${error instanceof Error ? error.message : error}`));
11605
11694
  }
11606
11695
  }, assign({
11607
11696
  dragGhost: void 0
@@ -11847,7 +11936,7 @@ const editorMachine = setup({
11847
11936
  sendBack({
11848
11937
  type: "emit changes"
11849
11938
  });
11850
- }, process.env.NODE_ENV === "test" ? 250 : 1e3);
11939
+ }, 1e3);
11851
11940
  return () => {
11852
11941
  clearInterval(interval);
11853
11942
  };
@@ -12796,8 +12885,14 @@ function syncBlock({
12796
12885
  blockChanged: !1,
12797
12886
  blockValid: !0
12798
12887
  };
12799
- const validationValue = [value[index]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
12800
- return !validation.valid && validation.resolution?.autoResolve && validation.resolution?.patches.length > 0 && !context.readOnly && context.previousValue && context.previousValue !== value && (console.warn(`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${validation.resolution?.description}`), validation.resolution.patches.forEach((patch) => {
12888
+ const blockToValidate = value[index];
12889
+ if (!blockToValidate)
12890
+ return {
12891
+ blockChanged: !1,
12892
+ blockValid: !0
12893
+ };
12894
+ const validation = validateValue([blockToValidate], context.schema, context.keyGenerator);
12895
+ return !validation.valid && validation.resolution?.autoResolve && validation.resolution?.patches.length > 0 && !context.readOnly && context.previousValue && context.previousValue !== value && (console.warn(`${validation.resolution.action} for block with _key '${blockToValidate._key}'. ${validation.resolution?.description}`), validation.resolution.patches.forEach((patch) => {
12801
12896
  sendBack({
12802
12897
  type: "patch",
12803
12898
  patch