@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 +91 -54
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +91 -54
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
- package/src/editor/Editable.tsx +1 -16
- package/src/editor/plugins/slate-plugin.update-selection.ts +51 -0
- package/src/editor/plugins/with-plugins.ts +5 -6
- package/src/editor/relay-machine.ts +49 -2
- package/src/editor/plugins/createWithPortableTextSelections.ts +0 -60
package/lib/index.js
CHANGED
|
@@ -4571,40 +4571,6 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
4571
4571
|
}, editor;
|
|
4572
4572
|
};
|
|
4573
4573
|
}
|
|
4574
|
-
debugWithName("plugin:withPortableTextSelections");
|
|
4575
|
-
function createWithPortableTextSelections(editorActor) {
|
|
4576
|
-
let prevSelection = null;
|
|
4577
|
-
return function(editor) {
|
|
4578
|
-
const emitPortableTextSelection = () => {
|
|
4579
|
-
if (prevSelection !== editor.selection) {
|
|
4580
|
-
let ptRange = null;
|
|
4581
|
-
if (editor.selection) {
|
|
4582
|
-
const existing = SLATE_TO_PORTABLE_TEXT_RANGE.get(editor.selection);
|
|
4583
|
-
existing ? ptRange = existing : (ptRange = slateRangeToSelection({
|
|
4584
|
-
schema: editorActor.getSnapshot().context.schema,
|
|
4585
|
-
editor,
|
|
4586
|
-
range: editor.selection
|
|
4587
|
-
}), SLATE_TO_PORTABLE_TEXT_RANGE.set(editor.selection, ptRange));
|
|
4588
|
-
}
|
|
4589
|
-
ptRange ? editorActor.send({
|
|
4590
|
-
type: "update selection",
|
|
4591
|
-
selection: ptRange
|
|
4592
|
-
}) : editorActor.send({
|
|
4593
|
-
type: "update selection",
|
|
4594
|
-
selection: null
|
|
4595
|
-
});
|
|
4596
|
-
}
|
|
4597
|
-
prevSelection = editor.selection;
|
|
4598
|
-
}, {
|
|
4599
|
-
onChange
|
|
4600
|
-
} = editor;
|
|
4601
|
-
return editor.onChange = () => {
|
|
4602
|
-
onChange(), editorActor.getSnapshot().matches({
|
|
4603
|
-
setup: "setting up"
|
|
4604
|
-
}) || emitPortableTextSelection();
|
|
4605
|
-
}, editor;
|
|
4606
|
-
};
|
|
4607
|
-
}
|
|
4608
4574
|
const debug$b = debugWithName("plugin:withSchemaTypes");
|
|
4609
4575
|
function createWithSchemaTypes({
|
|
4610
4576
|
editorActor
|
|
@@ -4770,6 +4736,43 @@ function pluginUpdateMarkState(context, editor) {
|
|
|
4770
4736
|
});
|
|
4771
4737
|
}, editor;
|
|
4772
4738
|
}
|
|
4739
|
+
function pluginUpdateSelection({
|
|
4740
|
+
editor,
|
|
4741
|
+
editorActor
|
|
4742
|
+
}) {
|
|
4743
|
+
const updateSelection = () => {
|
|
4744
|
+
if (editor.selection) {
|
|
4745
|
+
const existingSelection = SLATE_TO_PORTABLE_TEXT_RANGE.get(editor.selection);
|
|
4746
|
+
if (existingSelection)
|
|
4747
|
+
editorActor.send({
|
|
4748
|
+
type: "update selection",
|
|
4749
|
+
selection: existingSelection
|
|
4750
|
+
});
|
|
4751
|
+
else {
|
|
4752
|
+
const selection = slateRangeToSelection({
|
|
4753
|
+
schema: editorActor.getSnapshot().context.schema,
|
|
4754
|
+
editor,
|
|
4755
|
+
range: editor.selection
|
|
4756
|
+
});
|
|
4757
|
+
SLATE_TO_PORTABLE_TEXT_RANGE.set(editor.selection, selection), editorActor.send({
|
|
4758
|
+
type: "update selection",
|
|
4759
|
+
selection
|
|
4760
|
+
});
|
|
4761
|
+
}
|
|
4762
|
+
} else
|
|
4763
|
+
editorActor.send({
|
|
4764
|
+
type: "update selection",
|
|
4765
|
+
selection: null
|
|
4766
|
+
});
|
|
4767
|
+
}, {
|
|
4768
|
+
onChange
|
|
4769
|
+
} = editor;
|
|
4770
|
+
return editor.onChange = () => {
|
|
4771
|
+
onChange(), editorActor.getSnapshot().matches({
|
|
4772
|
+
setup: "setting up"
|
|
4773
|
+
}) || updateSelection();
|
|
4774
|
+
}, editor;
|
|
4775
|
+
}
|
|
4773
4776
|
function isEditorNode(node) {
|
|
4774
4777
|
return typeof node == "object" && node !== null ? !("_type" in node) && "children" in node && Array.isArray(node.children) : !1;
|
|
4775
4778
|
}
|
|
@@ -5065,8 +5068,11 @@ const withPlugins = (editor, options) => {
|
|
|
5065
5068
|
subscriptions: options.subscriptions
|
|
5066
5069
|
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
5067
5070
|
editorActor
|
|
5068
|
-
})
|
|
5069
|
-
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(
|
|
5071
|
+
});
|
|
5072
|
+
return createWithEventListeners(editorActor)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(pluginUpdateSelection({
|
|
5073
|
+
editorActor,
|
|
5074
|
+
editor: pluginUpdateValue(editorActor.getSnapshot().context, pluginUpdateMarkState(editorActor.getSnapshot().context, e))
|
|
5075
|
+
}))))))))));
|
|
5070
5076
|
}, debug$a = debugWithName("setup");
|
|
5071
5077
|
function createSlateEditor(config) {
|
|
5072
5078
|
debug$a("Creating new Slate editor instance");
|
|
@@ -8451,16 +8457,58 @@ function isAnnotationActive({
|
|
|
8451
8457
|
}
|
|
8452
8458
|
const relayMachine = setup({
|
|
8453
8459
|
types: {
|
|
8460
|
+
context: {},
|
|
8454
8461
|
events: {},
|
|
8455
8462
|
emitted: {}
|
|
8456
8463
|
}
|
|
8457
8464
|
}).createMachine({
|
|
8458
8465
|
id: "relay",
|
|
8466
|
+
context: {
|
|
8467
|
+
prevSelection: null,
|
|
8468
|
+
lastEventWasFocused: !1
|
|
8469
|
+
},
|
|
8459
8470
|
on: {
|
|
8471
|
+
focused: {
|
|
8472
|
+
actions: [assign({
|
|
8473
|
+
lastEventWasFocused: !0
|
|
8474
|
+
}), emit(({
|
|
8475
|
+
event
|
|
8476
|
+
}) => event)]
|
|
8477
|
+
},
|
|
8478
|
+
selection: [{
|
|
8479
|
+
guard: ({
|
|
8480
|
+
context
|
|
8481
|
+
}) => context.lastEventWasFocused,
|
|
8482
|
+
actions: [assign({
|
|
8483
|
+
prevSelection: ({
|
|
8484
|
+
event
|
|
8485
|
+
}) => event.selection
|
|
8486
|
+
}), emit(({
|
|
8487
|
+
event
|
|
8488
|
+
}) => event), assign({
|
|
8489
|
+
lastEventWasFocused: !1
|
|
8490
|
+
})]
|
|
8491
|
+
}, {
|
|
8492
|
+
guard: ({
|
|
8493
|
+
context,
|
|
8494
|
+
event
|
|
8495
|
+
}) => context.prevSelection !== event.selection,
|
|
8496
|
+
actions: [assign({
|
|
8497
|
+
prevSelection: ({
|
|
8498
|
+
event
|
|
8499
|
+
}) => event.selection
|
|
8500
|
+
}), emit(({
|
|
8501
|
+
event
|
|
8502
|
+
}) => event), assign({
|
|
8503
|
+
lastEventWasFocused: !1
|
|
8504
|
+
})]
|
|
8505
|
+
}],
|
|
8460
8506
|
"*": {
|
|
8461
|
-
actions: emit(({
|
|
8507
|
+
actions: [emit(({
|
|
8462
8508
|
event
|
|
8463
|
-
}) => event)
|
|
8509
|
+
}) => event), assign({
|
|
8510
|
+
lastEventWasFocused: !1
|
|
8511
|
+
})]
|
|
8464
8512
|
}
|
|
8465
8513
|
}
|
|
8466
8514
|
});
|
|
@@ -10748,22 +10796,11 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = forwar
|
|
|
10748
10796
|
}
|
|
10749
10797
|
debug("No result from custom paste handler, pasting normally");
|
|
10750
10798
|
}, [editorActor, onPaste, portableTextEditor, relayActor, slateEditor]), handleOnFocus = useCallback((event_2) => {
|
|
10751
|
-
|
|
10752
|
-
|
|
10753
|
-
|
|
10754
|
-
|
|
10755
|
-
|
|
10756
|
-
const selection_3 = slateEditor.selection ? slateRangeToSelection({
|
|
10757
|
-
schema: editorActor.getSnapshot().context.schema,
|
|
10758
|
-
editor: slateEditor,
|
|
10759
|
-
range: slateEditor.selection
|
|
10760
|
-
}) : null;
|
|
10761
|
-
selection_3 && editorActor.send({
|
|
10762
|
-
type: "update selection",
|
|
10763
|
-
selection: selection_3
|
|
10764
|
-
});
|
|
10765
|
-
}
|
|
10766
|
-
}, [editorActor, onFocus, slateEditor, relayActor]), handleClick = useCallback((event_3) => {
|
|
10799
|
+
onFocus && onFocus(event_2), event_2.isDefaultPrevented() || relayActor.send({
|
|
10800
|
+
type: "focused",
|
|
10801
|
+
event: event_2
|
|
10802
|
+
});
|
|
10803
|
+
}, [onFocus, relayActor]), handleClick = useCallback((event_3) => {
|
|
10767
10804
|
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
10768
10805
|
return;
|
|
10769
10806
|
const position_3 = getEventPosition({
|