@portabletext/editor 1.52.3 → 1.52.5

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.cjs CHANGED
@@ -4542,40 +4542,6 @@ function createWithPlaceholderBlock(editorActor) {
4542
4542
  }, editor;
4543
4543
  };
4544
4544
  }
4545
- debugWithName("plugin:withPortableTextSelections");
4546
- function createWithPortableTextSelections(editorActor) {
4547
- let prevSelection = null;
4548
- return function(editor) {
4549
- const emitPortableTextSelection = () => {
4550
- if (prevSelection !== editor.selection) {
4551
- let ptRange = null;
4552
- if (editor.selection) {
4553
- const existing = SLATE_TO_PORTABLE_TEXT_RANGE.get(editor.selection);
4554
- existing ? ptRange = existing : (ptRange = slateRangeToSelection({
4555
- schema: editorActor.getSnapshot().context.schema,
4556
- editor,
4557
- range: editor.selection
4558
- }), SLATE_TO_PORTABLE_TEXT_RANGE.set(editor.selection, ptRange));
4559
- }
4560
- ptRange ? editorActor.send({
4561
- type: "update selection",
4562
- selection: ptRange
4563
- }) : editorActor.send({
4564
- type: "update selection",
4565
- selection: null
4566
- });
4567
- }
4568
- prevSelection = editor.selection;
4569
- }, {
4570
- onChange
4571
- } = editor;
4572
- return editor.onChange = () => {
4573
- onChange(), editorActor.getSnapshot().matches({
4574
- setup: "setting up"
4575
- }) || emitPortableTextSelection();
4576
- }, editor;
4577
- };
4578
- }
4579
4545
  const debug$b = debugWithName("plugin:withSchemaTypes");
4580
4546
  function createWithSchemaTypes({
4581
4547
  editorActor
@@ -4741,6 +4707,43 @@ function pluginUpdateMarkState(context, editor) {
4741
4707
  });
4742
4708
  }, editor;
4743
4709
  }
4710
+ function pluginUpdateSelection({
4711
+ editor,
4712
+ editorActor
4713
+ }) {
4714
+ const updateSelection = () => {
4715
+ if (editor.selection) {
4716
+ const existingSelection = SLATE_TO_PORTABLE_TEXT_RANGE.get(editor.selection);
4717
+ if (existingSelection)
4718
+ editorActor.send({
4719
+ type: "update selection",
4720
+ selection: existingSelection
4721
+ });
4722
+ else {
4723
+ const selection = slateRangeToSelection({
4724
+ schema: editorActor.getSnapshot().context.schema,
4725
+ editor,
4726
+ range: editor.selection
4727
+ });
4728
+ SLATE_TO_PORTABLE_TEXT_RANGE.set(editor.selection, selection), editorActor.send({
4729
+ type: "update selection",
4730
+ selection
4731
+ });
4732
+ }
4733
+ } else
4734
+ editorActor.send({
4735
+ type: "update selection",
4736
+ selection: null
4737
+ });
4738
+ }, {
4739
+ onChange
4740
+ } = editor;
4741
+ return editor.onChange = () => {
4742
+ onChange(), editorActor.getSnapshot().matches({
4743
+ setup: "setting up"
4744
+ }) || updateSelection();
4745
+ }, editor;
4746
+ }
4744
4747
  function isEditorNode(node) {
4745
4748
  return typeof node == "object" && node !== null ? !("_type" in node) && "children" in node && Array.isArray(node.children) : !1;
4746
4749
  }
@@ -5036,8 +5039,11 @@ const withPlugins = (editor, options) => {
5036
5039
  subscriptions: options.subscriptions
5037
5040
  }), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
5038
5041
  editorActor
5039
- }), withPortableTextSelections = createWithPortableTextSelections(editorActor);
5040
- return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(pluginUpdateValue(editorActor.getSnapshot().context, pluginUpdateMarkState(editorActor.getSnapshot().context, e))))))))))));
5042
+ });
5043
+ return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(pluginUpdateSelection({
5044
+ editorActor,
5045
+ editor: pluginUpdateValue(editorActor.getSnapshot().context, pluginUpdateMarkState(editorActor.getSnapshot().context, e))
5046
+ }))))))))));
5041
5047
  }, debug$a = debugWithName("setup");
5042
5048
  function createSlateEditor(config) {
5043
5049
  debug$a("Creating new Slate editor instance");
@@ -8422,16 +8428,58 @@ function isAnnotationActive({
8422
8428
  }
8423
8429
  const relayMachine = xstate.setup({
8424
8430
  types: {
8431
+ context: {},
8425
8432
  events: {},
8426
8433
  emitted: {}
8427
8434
  }
8428
8435
  }).createMachine({
8429
8436
  id: "relay",
8437
+ context: {
8438
+ prevSelection: null,
8439
+ lastEventWasFocused: !1
8440
+ },
8430
8441
  on: {
8442
+ focused: {
8443
+ actions: [xstate.assign({
8444
+ lastEventWasFocused: !0
8445
+ }), xstate.emit(({
8446
+ event
8447
+ }) => event)]
8448
+ },
8449
+ selection: [{
8450
+ guard: ({
8451
+ context
8452
+ }) => context.lastEventWasFocused,
8453
+ actions: [xstate.assign({
8454
+ prevSelection: ({
8455
+ event
8456
+ }) => event.selection
8457
+ }), xstate.emit(({
8458
+ event
8459
+ }) => event), xstate.assign({
8460
+ lastEventWasFocused: !1
8461
+ })]
8462
+ }, {
8463
+ guard: ({
8464
+ context,
8465
+ event
8466
+ }) => context.prevSelection !== event.selection,
8467
+ actions: [xstate.assign({
8468
+ prevSelection: ({
8469
+ event
8470
+ }) => event.selection
8471
+ }), xstate.emit(({
8472
+ event
8473
+ }) => event), xstate.assign({
8474
+ lastEventWasFocused: !1
8475
+ })]
8476
+ }],
8431
8477
  "*": {
8432
- actions: xstate.emit(({
8478
+ actions: [xstate.emit(({
8433
8479
  event
8434
- }) => event)
8480
+ }) => event), xstate.assign({
8481
+ lastEventWasFocused: !1
8482
+ })]
8435
8483
  }
8436
8484
  }
8437
8485
  });
@@ -10719,22 +10767,11 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
10719
10767
  }
10720
10768
  debug("No result from custom paste handler, pasting normally");
10721
10769
  }, [editorActor, onPaste, portableTextEditor, relayActor, slateEditor]), handleOnFocus = React.useCallback((event_2) => {
10722
- if (onFocus && onFocus(event_2), !event_2.isDefaultPrevented()) {
10723
- relayActor.send({
10724
- type: "focused",
10725
- event: event_2
10726
- });
10727
- const selection_3 = slateEditor.selection ? slateRangeToSelection({
10728
- schema: editorActor.getSnapshot().context.schema,
10729
- editor: slateEditor,
10730
- range: slateEditor.selection
10731
- }) : null;
10732
- selection_3 && editorActor.send({
10733
- type: "update selection",
10734
- selection: selection_3
10735
- });
10736
- }
10737
- }, [editorActor, onFocus, slateEditor, relayActor]), handleClick = React.useCallback((event_3) => {
10770
+ onFocus && onFocus(event_2), event_2.isDefaultPrevented() || relayActor.send({
10771
+ type: "focused",
10772
+ event: event_2
10773
+ });
10774
+ }, [onFocus, relayActor]), handleClick = React.useCallback((event_3) => {
10738
10775
  if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
10739
10776
  return;
10740
10777
  const position_3 = getEventPosition({