@portabletext/editor 2.16.0 → 2.17.1
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/_chunks-cjs/selector.get-selection-text.cjs +1 -1
- package/lib/_chunks-cjs/selector.get-selection-text.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs +1 -0
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +2 -2
- package/lib/_chunks-dts/behavior.types.action.d.ts +5 -5
- package/lib/_chunks-es/selector.get-selection-text.js +1 -1
- package/lib/_chunks-es/selector.get-selection-text.js.map +1 -1
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js +1 -0
- package/lib/index.cjs +485 -511
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +488 -514
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +1 -0
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.d.cts +8 -1
- package/lib/selectors/index.d.ts +8 -1
- package/lib/selectors/index.js +2 -1
- package/lib/utils/index.d.ts +2 -2
- package/package.json +2 -2
- package/src/behaviors/behavior.abstract.delete.ts +12 -16
- package/src/behaviors/behavior.abstract.insert.ts +37 -6
- package/src/behaviors/behavior.abstract.split.ts +24 -89
- package/src/behaviors/behavior.core.lists.ts +9 -3
- package/src/behaviors/behavior.types.event.ts +1 -1
- package/src/editor/plugins/create-with-event-listeners.ts +30 -31
- package/src/operations/behavior.operation.delete.ts +76 -80
- package/src/selectors/index.ts +1 -0
- package/src/selectors/selector.is-selection-expanded.test.ts +63 -0
- package/src/selectors/selector.is-selection-expanded.ts +1 -1
package/lib/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import { useEditor, EditorContext } from "./_chunks-es/use-editor.js";
|
|
|
4
4
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
5
5
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
6
6
|
import noop from "lodash/noop.js";
|
|
7
|
-
import { Element as Element$1, Text, Range, Editor, Node, Point, Path, Transforms, Operation, deleteText,
|
|
7
|
+
import { Element as Element$1, Text, Range, Editor, Node, Point, Path, Transforms, Operation, deleteText, createEditor } from "slate";
|
|
8
8
|
import { useSelected, useSlateSelector, useSlateStatic, ReactEditor, useSlate, Editable, withReact, Slate } from "slate-react";
|
|
9
9
|
import debug$g from "debug";
|
|
10
10
|
import { DOMEditor, isDOMNode, EDITOR_TO_PENDING_SELECTION, IS_FOCUSED, IS_READ_ONLY } from "slate-dom";
|
|
@@ -4625,24 +4625,21 @@ const addAnnotationOperationImplementation = ({
|
|
|
4625
4625
|
context,
|
|
4626
4626
|
operation
|
|
4627
4627
|
}) => {
|
|
4628
|
-
const
|
|
4629
|
-
|
|
4630
|
-
|
|
4631
|
-
|
|
4632
|
-
|
|
4633
|
-
|
|
4634
|
-
|
|
4635
|
-
|
|
4636
|
-
|
|
4637
|
-
|
|
4638
|
-
|
|
4639
|
-
|
|
4640
|
-
if (endBlockIndex === void 0)
|
|
4641
|
-
throw new Error("Failed to get end block index");
|
|
4642
|
-
const endBlock = operation.editor.value.at(endBlockIndex);
|
|
4643
|
-
if (!endBlock)
|
|
4644
|
-
throw new Error("Failed to get end block");
|
|
4628
|
+
const at = operation.at ? toSlateRange({
|
|
4629
|
+
context: {
|
|
4630
|
+
schema: context.schema,
|
|
4631
|
+
value: operation.editor.value,
|
|
4632
|
+
selection: operation.at
|
|
4633
|
+
},
|
|
4634
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
4635
|
+
}) : void 0, selection = operation.editor.selection ? slateRangeToSelection({
|
|
4636
|
+
schema: context.schema,
|
|
4637
|
+
editor: operation.editor,
|
|
4638
|
+
range: operation.editor.selection
|
|
4639
|
+
}) : void 0, reverse = operation.direction === "backward", anchorPoint = operation.at?.anchor ?? selection?.anchor, focusPoint = operation.at?.focus ?? selection?.focus, startPoint = reverse ? focusPoint : anchorPoint, endPoint = reverse ? anchorPoint : focusPoint, startBlockKey = startPoint ? getBlockKeyFromSelectionPoint(startPoint) : void 0, endBlockKey = endPoint ? getBlockKeyFromSelectionPoint(endPoint) : void 0, startBlockIndex = startBlockKey ? operation.editor.blockIndexMap.get(startBlockKey) : void 0, endBlockIndex = endBlockKey ? operation.editor.blockIndexMap.get(endBlockKey) : void 0, startBlock = startBlockIndex ? operation.editor.value.at(startBlockIndex) : void 0, endBlock = endBlockIndex ? operation.editor.value.at(endBlockIndex) : void 0;
|
|
4645
4640
|
if (operation.unit === "block") {
|
|
4641
|
+
if (startBlockIndex === void 0 || endBlockIndex === void 0)
|
|
4642
|
+
throw new Error("Failed to get start or end block index");
|
|
4646
4643
|
Transforms.removeNodes(operation.editor, {
|
|
4647
4644
|
at: {
|
|
4648
4645
|
anchor: {
|
|
@@ -4658,17 +4655,10 @@ const addAnnotationOperationImplementation = ({
|
|
|
4658
4655
|
}), operation.editor.children.length === 0 && Transforms.insertNodes(operation.editor, createPlaceholderBlock(context));
|
|
4659
4656
|
return;
|
|
4660
4657
|
}
|
|
4661
|
-
const range = toSlateRange({
|
|
4662
|
-
context: {
|
|
4663
|
-
schema: context.schema,
|
|
4664
|
-
value: operation.editor.value,
|
|
4665
|
-
selection: operation.at
|
|
4666
|
-
},
|
|
4667
|
-
blockIndexMap: operation.editor.blockIndexMap
|
|
4668
|
-
});
|
|
4669
|
-
if (!range)
|
|
4670
|
-
throw new Error(`Failed to get Slate Range for selection ${JSON.stringify(operation.at)}`);
|
|
4671
4658
|
if (operation.direction === "backward" && operation.unit === "line") {
|
|
4659
|
+
const range = at ?? operation.editor.selection ?? void 0;
|
|
4660
|
+
if (!range)
|
|
4661
|
+
throw new Error("Unable to delete line without a selection");
|
|
4672
4662
|
const parentBlockEntry = Editor.above(operation.editor, {
|
|
4673
4663
|
match: (n) => Element$1.isElement(n) && Editor.isBlock(operation.editor, n),
|
|
4674
4664
|
at: range
|
|
@@ -4683,15 +4673,14 @@ const addAnnotationOperationImplementation = ({
|
|
|
4683
4673
|
}
|
|
4684
4674
|
}
|
|
4685
4675
|
}
|
|
4686
|
-
const hanging = isTextBlock(context, endBlock)
|
|
4687
|
-
deleteText(operation.editor, {
|
|
4688
|
-
at
|
|
4689
|
-
|
|
4690
|
-
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
focus: operation.editor.selection.focus
|
|
4676
|
+
const hanging = reverse ? endPoint ? isTextBlock(context, endBlock) ? endPoint.offset === 0 : !0 : !1 : startPoint ? isTextBlock(context, startBlock) ? startPoint.offset === 0 : !0 : !1;
|
|
4677
|
+
at ? deleteText(operation.editor, {
|
|
4678
|
+
at,
|
|
4679
|
+
hanging,
|
|
4680
|
+
reverse
|
|
4681
|
+
}) : deleteText(operation.editor, {
|
|
4682
|
+
hanging,
|
|
4683
|
+
reverse
|
|
4695
4684
|
});
|
|
4696
4685
|
};
|
|
4697
4686
|
function findCurrentLineRange(editor, parentRange) {
|
|
@@ -5255,21 +5244,12 @@ function createWithEventListeners(editorActor) {
|
|
|
5255
5244
|
editorDelete(options);
|
|
5256
5245
|
return;
|
|
5257
5246
|
}
|
|
5258
|
-
const
|
|
5259
|
-
if (!at) {
|
|
5260
|
-
console.error("Unexpected call to .delete(...) without `at` option");
|
|
5261
|
-
return;
|
|
5262
|
-
}
|
|
5263
|
-
const range = Editor.range(editor, at), selection = slateRangeToSelection({
|
|
5247
|
+
const range = options?.at ? Editor.range(editor, options.at) : void 0, selection = range ? slateRangeToSelection({
|
|
5264
5248
|
schema: editorActor.getSnapshot().context.schema,
|
|
5265
5249
|
editor,
|
|
5266
5250
|
range
|
|
5267
|
-
});
|
|
5268
|
-
|
|
5269
|
-
console.error("Unexpected call to .delete(...) with invalid `at` option");
|
|
5270
|
-
return;
|
|
5271
|
-
}
|
|
5272
|
-
editorActor.send({
|
|
5251
|
+
}) : void 0;
|
|
5252
|
+
selection ? editorActor.send({
|
|
5273
5253
|
type: "behavior event",
|
|
5274
5254
|
behaviorEvent: {
|
|
5275
5255
|
type: "delete",
|
|
@@ -5278,6 +5258,14 @@ function createWithEventListeners(editorActor) {
|
|
|
5278
5258
|
unit: options?.unit
|
|
5279
5259
|
},
|
|
5280
5260
|
editor
|
|
5261
|
+
}) : editorActor.send({
|
|
5262
|
+
type: "behavior event",
|
|
5263
|
+
behaviorEvent: {
|
|
5264
|
+
type: "delete",
|
|
5265
|
+
direction: options?.reverse ? "backward" : "forward",
|
|
5266
|
+
unit: options?.unit
|
|
5267
|
+
},
|
|
5268
|
+
editor
|
|
5281
5269
|
});
|
|
5282
5270
|
}, editor.deleteBackward = (unit) => {
|
|
5283
5271
|
if (isPerformingBehaviorOperation(editor)) {
|
|
@@ -7896,11 +7884,14 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
7896
7884
|
snapshot,
|
|
7897
7885
|
event
|
|
7898
7886
|
}) => {
|
|
7887
|
+
const at = event.at ?? snapshot.context.selection;
|
|
7888
|
+
if (!at)
|
|
7889
|
+
return !1;
|
|
7899
7890
|
const blocksToDelete = getSelectedBlocks({
|
|
7900
7891
|
...snapshot,
|
|
7901
7892
|
context: {
|
|
7902
7893
|
...snapshot.context,
|
|
7903
|
-
selection:
|
|
7894
|
+
selection: at
|
|
7904
7895
|
}
|
|
7905
7896
|
});
|
|
7906
7897
|
if (blocksToDelete.length < 2)
|
|
@@ -7911,12 +7902,12 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
7911
7902
|
const deleteStartPoint = getSelectionStartPoint$1({
|
|
7912
7903
|
context: {
|
|
7913
7904
|
...snapshot.context,
|
|
7914
|
-
selection:
|
|
7905
|
+
selection: at
|
|
7915
7906
|
}
|
|
7916
7907
|
}), deleteEndPoint = getSelectionEndPoint$1({
|
|
7917
7908
|
context: {
|
|
7918
7909
|
...snapshot.context,
|
|
7919
|
-
selection:
|
|
7910
|
+
selection: at
|
|
7920
7911
|
}
|
|
7921
7912
|
});
|
|
7922
7913
|
if (!deleteStartPoint || !deleteEndPoint)
|
|
@@ -8301,18 +8292,13 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
8301
8292
|
on: "delete.backward",
|
|
8302
8293
|
guard: ({
|
|
8303
8294
|
snapshot
|
|
8304
|
-
}) => snapshot.context.selection
|
|
8305
|
-
selection: snapshot.context.selection
|
|
8306
|
-
} : !1,
|
|
8295
|
+
}) => snapshot.context.selection,
|
|
8307
8296
|
actions: [({
|
|
8308
8297
|
event
|
|
8309
|
-
}, {
|
|
8310
|
-
selection
|
|
8311
8298
|
}) => [raise({
|
|
8312
8299
|
type: "delete",
|
|
8313
8300
|
direction: "backward",
|
|
8314
|
-
unit: event.unit
|
|
8315
|
-
at: selection
|
|
8301
|
+
unit: event.unit
|
|
8316
8302
|
})]]
|
|
8317
8303
|
}), defineBehavior({
|
|
8318
8304
|
on: "delete",
|
|
@@ -8356,18 +8342,13 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
8356
8342
|
on: "delete.forward",
|
|
8357
8343
|
guard: ({
|
|
8358
8344
|
snapshot
|
|
8359
|
-
}) => snapshot.context.selection
|
|
8360
|
-
selection: snapshot.context.selection
|
|
8361
|
-
} : !1,
|
|
8345
|
+
}) => snapshot.context.selection,
|
|
8362
8346
|
actions: [({
|
|
8363
8347
|
event
|
|
8364
|
-
}, {
|
|
8365
|
-
selection
|
|
8366
8348
|
}) => [raise({
|
|
8367
8349
|
type: "delete",
|
|
8368
8350
|
direction: "forward",
|
|
8369
|
-
unit: event.unit
|
|
8370
|
-
at: selection
|
|
8351
|
+
unit: event.unit
|
|
8371
8352
|
})]]
|
|
8372
8353
|
}), defineBehavior({
|
|
8373
8354
|
on: "delete",
|
|
@@ -8377,17 +8358,20 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
8377
8358
|
}) => {
|
|
8378
8359
|
if (event.direction !== "forward")
|
|
8379
8360
|
return !1;
|
|
8361
|
+
const at = event.at ?? snapshot.context.selection;
|
|
8362
|
+
if (!at)
|
|
8363
|
+
return !1;
|
|
8380
8364
|
const nextBlock = getNextBlock({
|
|
8381
8365
|
...snapshot,
|
|
8382
8366
|
context: {
|
|
8383
8367
|
...snapshot.context,
|
|
8384
|
-
selection:
|
|
8368
|
+
selection: at
|
|
8385
8369
|
}
|
|
8386
8370
|
}), focusTextBlock = getFocusTextBlock({
|
|
8387
8371
|
...snapshot,
|
|
8388
8372
|
context: {
|
|
8389
8373
|
...snapshot.context,
|
|
8390
|
-
selection:
|
|
8374
|
+
selection: at
|
|
8391
8375
|
}
|
|
8392
8376
|
});
|
|
8393
8377
|
if (!nextBlock || !focusTextBlock || !isEmptyTextBlock(snapshot.context, focusTextBlock.node))
|
|
@@ -8724,394 +8708,436 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
8724
8708
|
}
|
|
8725
8709
|
}]]
|
|
8726
8710
|
})
|
|
8727
|
-
], abstractInsertBehaviors = [
|
|
8728
|
-
|
|
8729
|
-
|
|
8730
|
-
|
|
8731
|
-
|
|
8732
|
-
|
|
8733
|
-
|
|
8711
|
+
], abstractInsertBehaviors = [
|
|
8712
|
+
defineBehavior({
|
|
8713
|
+
on: "insert.blocks",
|
|
8714
|
+
guard: ({
|
|
8715
|
+
event
|
|
8716
|
+
}) => {
|
|
8717
|
+
const onlyBlock = event.blocks.length === 1 ? event.blocks.at(0) : void 0;
|
|
8718
|
+
return onlyBlock ? {
|
|
8719
|
+
onlyBlock
|
|
8720
|
+
} : !1;
|
|
8721
|
+
},
|
|
8722
|
+
actions: [({
|
|
8723
|
+
event
|
|
8724
|
+
}, {
|
|
8734
8725
|
onlyBlock
|
|
8735
|
-
}
|
|
8736
|
-
|
|
8737
|
-
|
|
8738
|
-
|
|
8739
|
-
|
|
8740
|
-
|
|
8741
|
-
})
|
|
8742
|
-
|
|
8743
|
-
|
|
8744
|
-
|
|
8745
|
-
|
|
8746
|
-
|
|
8747
|
-
})
|
|
8748
|
-
|
|
8749
|
-
|
|
8750
|
-
|
|
8751
|
-
|
|
8752
|
-
|
|
8753
|
-
|
|
8754
|
-
|
|
8755
|
-
|
|
8756
|
-
|
|
8726
|
+
}) => [raise({
|
|
8727
|
+
type: "insert.block",
|
|
8728
|
+
block: onlyBlock,
|
|
8729
|
+
placement: event.placement,
|
|
8730
|
+
select: event.select ?? "end"
|
|
8731
|
+
})]]
|
|
8732
|
+
}),
|
|
8733
|
+
defineBehavior({
|
|
8734
|
+
on: "insert.blocks",
|
|
8735
|
+
guard: ({
|
|
8736
|
+
snapshot,
|
|
8737
|
+
event
|
|
8738
|
+
}) => {
|
|
8739
|
+
if (event.placement !== "before")
|
|
8740
|
+
return !1;
|
|
8741
|
+
const firstBlockKey = event.blocks.at(0)?._key ?? snapshot.context.keyGenerator(), lastBlockKey = event.blocks.at(-1)?._key ?? snapshot.context.keyGenerator();
|
|
8742
|
+
return {
|
|
8743
|
+
firstBlockKey,
|
|
8744
|
+
lastBlockKey
|
|
8745
|
+
};
|
|
8746
|
+
},
|
|
8747
|
+
actions: [({
|
|
8748
|
+
snapshot,
|
|
8749
|
+
event
|
|
8750
|
+
}, {
|
|
8757
8751
|
firstBlockKey,
|
|
8758
8752
|
lastBlockKey
|
|
8759
|
-
}
|
|
8760
|
-
|
|
8761
|
-
|
|
8762
|
-
|
|
8763
|
-
|
|
8764
|
-
|
|
8765
|
-
|
|
8766
|
-
|
|
8767
|
-
|
|
8768
|
-
|
|
8769
|
-
|
|
8770
|
-
|
|
8771
|
-
|
|
8772
|
-
|
|
8773
|
-
|
|
8774
|
-
|
|
8775
|
-
|
|
8776
|
-
|
|
8777
|
-
|
|
8778
|
-
|
|
8779
|
-
}]
|
|
8780
|
-
|
|
8781
|
-
|
|
8782
|
-
|
|
8783
|
-
|
|
8784
|
-
|
|
8785
|
-
|
|
8786
|
-
|
|
8787
|
-
|
|
8788
|
-
|
|
8789
|
-
|
|
8790
|
-
|
|
8791
|
-
|
|
8792
|
-
|
|
8793
|
-
|
|
8794
|
-
|
|
8795
|
-
|
|
8796
|
-
|
|
8797
|
-
|
|
8753
|
+
}) => [...event.blocks.map((block, index) => raise({
|
|
8754
|
+
type: "insert.block",
|
|
8755
|
+
block,
|
|
8756
|
+
placement: index === 0 ? "before" : "after",
|
|
8757
|
+
select: index !== event.blocks.length - 1 ? "end" : "none"
|
|
8758
|
+
})), ...event.select === "none" ? [raise({
|
|
8759
|
+
type: "select",
|
|
8760
|
+
at: snapshot.context.selection
|
|
8761
|
+
})] : event.select === "start" ? [raise({
|
|
8762
|
+
type: "select.block",
|
|
8763
|
+
at: [{
|
|
8764
|
+
_key: firstBlockKey
|
|
8765
|
+
}],
|
|
8766
|
+
select: "start"
|
|
8767
|
+
})] : [raise({
|
|
8768
|
+
type: "select.block",
|
|
8769
|
+
at: [{
|
|
8770
|
+
_key: lastBlockKey
|
|
8771
|
+
}],
|
|
8772
|
+
select: "end"
|
|
8773
|
+
})]]]
|
|
8774
|
+
}),
|
|
8775
|
+
defineBehavior({
|
|
8776
|
+
on: "insert.blocks",
|
|
8777
|
+
guard: ({
|
|
8778
|
+
snapshot,
|
|
8779
|
+
event
|
|
8780
|
+
}) => {
|
|
8781
|
+
if (event.placement !== "after")
|
|
8782
|
+
return !1;
|
|
8783
|
+
const firstBlockKey = event.blocks.at(0)?._key ?? snapshot.context.keyGenerator(), lastBlockKey = event.blocks.at(-1)?._key ?? snapshot.context.keyGenerator();
|
|
8784
|
+
return {
|
|
8785
|
+
firstBlockKey,
|
|
8786
|
+
lastBlockKey
|
|
8787
|
+
};
|
|
8788
|
+
},
|
|
8789
|
+
actions: [({
|
|
8790
|
+
snapshot,
|
|
8791
|
+
event
|
|
8792
|
+
}, {
|
|
8798
8793
|
firstBlockKey,
|
|
8799
8794
|
lastBlockKey
|
|
8800
|
-
}
|
|
8801
|
-
|
|
8802
|
-
|
|
8803
|
-
|
|
8804
|
-
|
|
8805
|
-
|
|
8806
|
-
|
|
8807
|
-
|
|
8808
|
-
|
|
8809
|
-
|
|
8810
|
-
|
|
8811
|
-
|
|
8812
|
-
|
|
8813
|
-
|
|
8814
|
-
|
|
8815
|
-
|
|
8816
|
-
|
|
8817
|
-
|
|
8818
|
-
|
|
8819
|
-
|
|
8820
|
-
}]
|
|
8821
|
-
|
|
8822
|
-
|
|
8823
|
-
|
|
8824
|
-
|
|
8825
|
-
|
|
8826
|
-
|
|
8827
|
-
|
|
8828
|
-
|
|
8829
|
-
|
|
8830
|
-
|
|
8831
|
-
|
|
8832
|
-
|
|
8833
|
-
|
|
8834
|
-
|
|
8835
|
-
|
|
8836
|
-
|
|
8837
|
-
|
|
8838
|
-
|
|
8839
|
-
|
|
8840
|
-
|
|
8841
|
-
|
|
8842
|
-
|
|
8795
|
+
}) => [...event.blocks.map((block, index) => raise({
|
|
8796
|
+
type: "insert.block",
|
|
8797
|
+
block,
|
|
8798
|
+
placement: "after",
|
|
8799
|
+
select: index !== event.blocks.length - 1 ? "end" : "none"
|
|
8800
|
+
})), ...event.select === "none" ? [raise({
|
|
8801
|
+
type: "select",
|
|
8802
|
+
at: snapshot.context.selection
|
|
8803
|
+
})] : event.select === "start" ? [raise({
|
|
8804
|
+
type: "select.block",
|
|
8805
|
+
at: [{
|
|
8806
|
+
_key: firstBlockKey
|
|
8807
|
+
}],
|
|
8808
|
+
select: "start"
|
|
8809
|
+
})] : [raise({
|
|
8810
|
+
type: "select.block",
|
|
8811
|
+
at: [{
|
|
8812
|
+
_key: lastBlockKey
|
|
8813
|
+
}],
|
|
8814
|
+
select: "end"
|
|
8815
|
+
})]]]
|
|
8816
|
+
}),
|
|
8817
|
+
defineBehavior({
|
|
8818
|
+
on: "insert.blocks",
|
|
8819
|
+
guard: ({
|
|
8820
|
+
snapshot,
|
|
8821
|
+
event
|
|
8822
|
+
}) => {
|
|
8823
|
+
if (event.placement !== "auto")
|
|
8824
|
+
return !1;
|
|
8825
|
+
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
8826
|
+
if (!focusTextBlock || !isEmptyTextBlock(snapshot.context, focusTextBlock.node))
|
|
8827
|
+
return !1;
|
|
8828
|
+
const firstBlockKey = event.blocks.at(0)?._key ?? snapshot.context.keyGenerator(), lastBlockKey = event.blocks.at(-1)?._key ?? snapshot.context.keyGenerator();
|
|
8829
|
+
return {
|
|
8830
|
+
focusTextBlock,
|
|
8831
|
+
firstBlockKey,
|
|
8832
|
+
lastBlockKey
|
|
8833
|
+
};
|
|
8834
|
+
},
|
|
8835
|
+
actions: [({
|
|
8836
|
+
event
|
|
8837
|
+
}, {
|
|
8843
8838
|
firstBlockKey,
|
|
8844
8839
|
lastBlockKey
|
|
8845
|
-
}
|
|
8846
|
-
|
|
8847
|
-
|
|
8848
|
-
|
|
8849
|
-
|
|
8850
|
-
|
|
8851
|
-
|
|
8852
|
-
|
|
8853
|
-
|
|
8854
|
-
|
|
8855
|
-
|
|
8856
|
-
|
|
8857
|
-
|
|
8858
|
-
|
|
8859
|
-
|
|
8860
|
-
|
|
8861
|
-
|
|
8862
|
-
|
|
8863
|
-
})
|
|
8864
|
-
|
|
8865
|
-
|
|
8866
|
-
|
|
8867
|
-
|
|
8868
|
-
|
|
8869
|
-
|
|
8870
|
-
|
|
8871
|
-
|
|
8872
|
-
|
|
8873
|
-
|
|
8874
|
-
|
|
8875
|
-
|
|
8876
|
-
|
|
8877
|
-
|
|
8878
|
-
|
|
8879
|
-
|
|
8880
|
-
|
|
8881
|
-
|
|
8882
|
-
|
|
8883
|
-
|
|
8884
|
-
|
|
8885
|
-
|
|
8886
|
-
|
|
8887
|
-
|
|
8888
|
-
|
|
8889
|
-
|
|
8890
|
-
|
|
8891
|
-
|
|
8892
|
-
|
|
8893
|
-
|
|
8894
|
-
|
|
8895
|
-
|
|
8896
|
-
|
|
8897
|
-
|
|
8898
|
-
|
|
8899
|
-
|
|
8840
|
+
}) => [...event.blocks.map((block, index) => raise({
|
|
8841
|
+
type: "insert.block",
|
|
8842
|
+
block,
|
|
8843
|
+
placement: index === 0 ? "auto" : "after",
|
|
8844
|
+
select: index !== event.blocks.length - 1 ? "end" : "none"
|
|
8845
|
+
})), ...event.select === "none" || event.select === "start" ? [raise({
|
|
8846
|
+
type: "select.block",
|
|
8847
|
+
at: [{
|
|
8848
|
+
_key: firstBlockKey
|
|
8849
|
+
}],
|
|
8850
|
+
select: "start"
|
|
8851
|
+
})] : [raise({
|
|
8852
|
+
type: "select.block",
|
|
8853
|
+
at: [{
|
|
8854
|
+
_key: lastBlockKey
|
|
8855
|
+
}],
|
|
8856
|
+
select: "end"
|
|
8857
|
+
})]]]
|
|
8858
|
+
}),
|
|
8859
|
+
defineBehavior({
|
|
8860
|
+
on: "insert.blocks",
|
|
8861
|
+
guard: ({
|
|
8862
|
+
snapshot,
|
|
8863
|
+
event
|
|
8864
|
+
}) => {
|
|
8865
|
+
if (event.placement !== "auto")
|
|
8866
|
+
return !1;
|
|
8867
|
+
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
8868
|
+
if (!focusTextBlock || !snapshot.context.selection)
|
|
8869
|
+
return !1;
|
|
8870
|
+
const focusBlockStartPoint = getBlockStartPoint({
|
|
8871
|
+
context: snapshot.context,
|
|
8872
|
+
block: focusTextBlock
|
|
8873
|
+
}), focusBlockEndPoint = getBlockEndPoint({
|
|
8874
|
+
context: snapshot.context,
|
|
8875
|
+
block: focusTextBlock
|
|
8876
|
+
}), focusTextBlockAfter = sliceTextBlock({
|
|
8877
|
+
context: {
|
|
8878
|
+
schema: snapshot.context.schema,
|
|
8879
|
+
selection: {
|
|
8880
|
+
anchor: snapshot.context.selection.focus,
|
|
8881
|
+
focus: focusBlockEndPoint
|
|
8882
|
+
}
|
|
8883
|
+
},
|
|
8884
|
+
block: focusTextBlock.node
|
|
8885
|
+
});
|
|
8886
|
+
return {
|
|
8887
|
+
firstBlockKey: event.blocks.at(0)?._key ?? snapshot.context.keyGenerator(),
|
|
8888
|
+
focusBlockStartPoint,
|
|
8889
|
+
focusBlockEndPoint,
|
|
8890
|
+
focusTextBlockAfter,
|
|
8891
|
+
selection: snapshot.context.selection
|
|
8892
|
+
};
|
|
8893
|
+
},
|
|
8894
|
+
actions: [({
|
|
8895
|
+
event
|
|
8896
|
+
}, {
|
|
8900
8897
|
focusBlockEndPoint,
|
|
8901
8898
|
focusTextBlockAfter,
|
|
8902
|
-
selection
|
|
8903
|
-
|
|
8904
|
-
|
|
8905
|
-
|
|
8906
|
-
|
|
8907
|
-
|
|
8908
|
-
|
|
8909
|
-
|
|
8910
|
-
|
|
8911
|
-
|
|
8912
|
-
|
|
8913
|
-
|
|
8914
|
-
|
|
8915
|
-
|
|
8916
|
-
|
|
8917
|
-
|
|
8918
|
-
|
|
8919
|
-
|
|
8920
|
-
|
|
8921
|
-
|
|
8922
|
-
|
|
8923
|
-
|
|
8924
|
-
|
|
8925
|
-
|
|
8926
|
-
|
|
8927
|
-
|
|
8928
|
-
|
|
8929
|
-
|
|
8930
|
-
|
|
8931
|
-
|
|
8932
|
-
|
|
8933
|
-
|
|
8934
|
-
|
|
8935
|
-
|
|
8936
|
-
|
|
8937
|
-
|
|
8938
|
-
|
|
8939
|
-
|
|
8940
|
-
|
|
8941
|
-
|
|
8942
|
-
|
|
8943
|
-
|
|
8944
|
-
|
|
8945
|
-
|
|
8946
|
-
}]
|
|
8947
|
-
|
|
8948
|
-
|
|
8949
|
-
|
|
8950
|
-
|
|
8951
|
-
|
|
8952
|
-
|
|
8953
|
-
|
|
8954
|
-
|
|
8955
|
-
}),
|
|
8956
|
-
|
|
8957
|
-
|
|
8958
|
-
|
|
8959
|
-
|
|
8960
|
-
|
|
8961
|
-
|
|
8962
|
-
|
|
8963
|
-
|
|
8964
|
-
|
|
8965
|
-
|
|
8966
|
-
|
|
8967
|
-
})
|
|
8968
|
-
|
|
8969
|
-
|
|
8970
|
-
|
|
8971
|
-
|
|
8972
|
-
|
|
8973
|
-
|
|
8974
|
-
|
|
8975
|
-
|
|
8976
|
-
|
|
8977
|
-
|
|
8978
|
-
|
|
8979
|
-
|
|
8980
|
-
lastBlockEndPoint: getBlockEndPoint({
|
|
8981
|
-
context: snapshot.context,
|
|
8982
|
-
block: lastBlock
|
|
8983
|
-
})
|
|
8984
|
-
};
|
|
8985
|
-
},
|
|
8986
|
-
actions: [({
|
|
8987
|
-
event
|
|
8988
|
-
}, {
|
|
8989
|
-
lastBlockEndPoint
|
|
8990
|
-
}) => [raise({
|
|
8991
|
-
type: "select",
|
|
8992
|
-
at: {
|
|
8993
|
-
anchor: lastBlockEndPoint,
|
|
8994
|
-
focus: lastBlockEndPoint
|
|
8995
|
-
}
|
|
8996
|
-
}), raise(event)]]
|
|
8997
|
-
}), defineBehavior({
|
|
8998
|
-
on: "insert.child",
|
|
8999
|
-
guard: ({
|
|
9000
|
-
snapshot
|
|
9001
|
-
}) => {
|
|
9002
|
-
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
9003
|
-
return snapshot.context.selection && !focusTextBlock;
|
|
9004
|
-
},
|
|
9005
|
-
actions: [({
|
|
9006
|
-
snapshot,
|
|
9007
|
-
event
|
|
9008
|
-
}) => [raise({
|
|
9009
|
-
type: "insert.block",
|
|
9010
|
-
block: {
|
|
9011
|
-
_type: snapshot.context.schema.block.name,
|
|
9012
|
-
children: [{
|
|
9013
|
-
_type: snapshot.context.schema.span.name,
|
|
9014
|
-
text: "",
|
|
9015
|
-
marks: []
|
|
9016
|
-
}]
|
|
8899
|
+
selection,
|
|
8900
|
+
firstBlockKey,
|
|
8901
|
+
focusBlockStartPoint
|
|
8902
|
+
}) => [...event.blocks.flatMap((block, index) => index === 0 ? [...isEqualSelectionPoints(selection.focus, focusBlockEndPoint) ? [] : [raise({
|
|
8903
|
+
type: "delete",
|
|
8904
|
+
at: {
|
|
8905
|
+
anchor: selection.focus,
|
|
8906
|
+
focus: focusBlockEndPoint
|
|
8907
|
+
}
|
|
8908
|
+
})], raise({
|
|
8909
|
+
type: "insert.block",
|
|
8910
|
+
block,
|
|
8911
|
+
placement: "auto",
|
|
8912
|
+
select: "end"
|
|
8913
|
+
})] : index === event.blocks.length - 1 ? [raise({
|
|
8914
|
+
type: "insert.block",
|
|
8915
|
+
block,
|
|
8916
|
+
placement: "after",
|
|
8917
|
+
select: "end"
|
|
8918
|
+
}), raise({
|
|
8919
|
+
type: "insert.block",
|
|
8920
|
+
block: focusTextBlockAfter,
|
|
8921
|
+
placement: "auto",
|
|
8922
|
+
select: event.select === "end" ? "none" : "end"
|
|
8923
|
+
})] : [raise({
|
|
8924
|
+
type: "insert.block",
|
|
8925
|
+
block,
|
|
8926
|
+
placement: "after",
|
|
8927
|
+
select: "end"
|
|
8928
|
+
})]), ...event.select === "none" ? [raise({
|
|
8929
|
+
type: "select",
|
|
8930
|
+
at: selection
|
|
8931
|
+
})] : event.select === "start" ? [isEqualSelectionPoints(selection.focus, focusBlockStartPoint) ? raise({
|
|
8932
|
+
type: "select.block",
|
|
8933
|
+
at: [{
|
|
8934
|
+
_key: firstBlockKey
|
|
8935
|
+
}],
|
|
8936
|
+
select: "start"
|
|
8937
|
+
}) : raise({
|
|
8938
|
+
type: "select",
|
|
8939
|
+
at: {
|
|
8940
|
+
anchor: selection.focus,
|
|
8941
|
+
focus: selection.focus
|
|
8942
|
+
}
|
|
8943
|
+
})] : []]]
|
|
8944
|
+
}),
|
|
8945
|
+
defineBehavior({
|
|
8946
|
+
on: "insert.blocks",
|
|
8947
|
+
guard: ({
|
|
8948
|
+
event
|
|
8949
|
+
}) => event.placement === "auto",
|
|
8950
|
+
actions: [({
|
|
8951
|
+
event
|
|
8952
|
+
}) => event.blocks.map((block, index) => raise({
|
|
8953
|
+
type: "insert.block",
|
|
8954
|
+
block,
|
|
8955
|
+
placement: index === 0 ? "auto" : "after",
|
|
8956
|
+
select: event.select ?? "end"
|
|
8957
|
+
}))]
|
|
8958
|
+
}),
|
|
8959
|
+
defineBehavior({
|
|
8960
|
+
on: "insert.break",
|
|
8961
|
+
actions: [() => [raise({
|
|
8962
|
+
type: "split"
|
|
8963
|
+
})]]
|
|
8964
|
+
}),
|
|
8965
|
+
defineBehavior({
|
|
8966
|
+
on: "insert.child",
|
|
8967
|
+
guard: ({
|
|
8968
|
+
snapshot
|
|
8969
|
+
}) => {
|
|
8970
|
+
const lastBlock = getLastBlock$1(snapshot);
|
|
8971
|
+
return !lastBlock || snapshot.context.selection ? !1 : {
|
|
8972
|
+
lastBlockEndPoint: getBlockEndPoint({
|
|
8973
|
+
context: snapshot.context,
|
|
8974
|
+
block: lastBlock
|
|
8975
|
+
})
|
|
8976
|
+
};
|
|
9017
8977
|
},
|
|
9018
|
-
|
|
9019
|
-
|
|
9020
|
-
|
|
9021
|
-
|
|
9022
|
-
|
|
9023
|
-
|
|
9024
|
-
|
|
9025
|
-
|
|
9026
|
-
|
|
9027
|
-
|
|
9028
|
-
|
|
9029
|
-
|
|
9030
|
-
|
|
9031
|
-
|
|
9032
|
-
|
|
9033
|
-
|
|
9034
|
-
|
|
9035
|
-
|
|
9036
|
-
|
|
8978
|
+
actions: [({
|
|
8979
|
+
event
|
|
8980
|
+
}, {
|
|
8981
|
+
lastBlockEndPoint
|
|
8982
|
+
}) => [raise({
|
|
8983
|
+
type: "select",
|
|
8984
|
+
at: {
|
|
8985
|
+
anchor: lastBlockEndPoint,
|
|
8986
|
+
focus: lastBlockEndPoint
|
|
8987
|
+
}
|
|
8988
|
+
}), raise(event)]]
|
|
8989
|
+
}),
|
|
8990
|
+
defineBehavior({
|
|
8991
|
+
on: "insert.child",
|
|
8992
|
+
guard: ({
|
|
8993
|
+
snapshot
|
|
8994
|
+
}) => {
|
|
8995
|
+
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
8996
|
+
return snapshot.context.selection && !focusTextBlock;
|
|
8997
|
+
},
|
|
8998
|
+
actions: [({
|
|
8999
|
+
snapshot,
|
|
9000
|
+
event
|
|
9001
|
+
}) => [raise({
|
|
9002
|
+
type: "insert.block",
|
|
9003
|
+
block: {
|
|
9004
|
+
_type: snapshot.context.schema.block.name,
|
|
9005
|
+
children: [{
|
|
9006
|
+
_type: snapshot.context.schema.span.name,
|
|
9007
|
+
text: "",
|
|
9008
|
+
marks: []
|
|
9009
|
+
}]
|
|
9010
|
+
},
|
|
9011
|
+
placement: "auto",
|
|
9012
|
+
select: "end"
|
|
9013
|
+
}), raise(event)]]
|
|
9014
|
+
}),
|
|
9015
|
+
defineBehavior({
|
|
9016
|
+
on: "insert.inline object",
|
|
9017
|
+
actions: [({
|
|
9018
|
+
event
|
|
9019
|
+
}) => [raise({
|
|
9020
|
+
type: "insert.child",
|
|
9021
|
+
child: {
|
|
9022
|
+
_type: event.inlineObject.name,
|
|
9023
|
+
...event.inlineObject.value
|
|
9024
|
+
}
|
|
9025
|
+
})]]
|
|
9026
|
+
}),
|
|
9027
|
+
defineBehavior({
|
|
9028
|
+
on: "insert.soft break",
|
|
9029
|
+
actions: [() => [raise({
|
|
9030
|
+
type: "insert.text",
|
|
9031
|
+
text: `
|
|
9037
9032
|
`
|
|
9038
|
-
|
|
9039
|
-
}),
|
|
9040
|
-
|
|
9041
|
-
|
|
9042
|
-
|
|
9043
|
-
|
|
9044
|
-
|
|
9045
|
-
|
|
9046
|
-
|
|
9047
|
-
|
|
9048
|
-
|
|
9049
|
-
|
|
9050
|
-
|
|
9051
|
-
|
|
9052
|
-
|
|
9053
|
-
|
|
9054
|
-
|
|
9055
|
-
|
|
9033
|
+
})]]
|
|
9034
|
+
}),
|
|
9035
|
+
defineBehavior({
|
|
9036
|
+
on: "insert.span",
|
|
9037
|
+
guard: ({
|
|
9038
|
+
snapshot
|
|
9039
|
+
}) => !getFocusTextBlock(snapshot),
|
|
9040
|
+
actions: [({
|
|
9041
|
+
snapshot,
|
|
9042
|
+
event
|
|
9043
|
+
}) => [raise({
|
|
9044
|
+
type: "insert.block",
|
|
9045
|
+
block: {
|
|
9046
|
+
_type: snapshot.context.schema.block.name,
|
|
9047
|
+
children: [{
|
|
9048
|
+
_type: snapshot.context.schema.span.name,
|
|
9049
|
+
text: "",
|
|
9050
|
+
marks: []
|
|
9051
|
+
}]
|
|
9052
|
+
},
|
|
9053
|
+
placement: "auto",
|
|
9054
|
+
select: "end"
|
|
9055
|
+
}), raise(event)]]
|
|
9056
|
+
}),
|
|
9057
|
+
defineBehavior({
|
|
9058
|
+
on: "insert.span",
|
|
9059
|
+
guard: ({
|
|
9060
|
+
snapshot,
|
|
9061
|
+
event
|
|
9062
|
+
}) => {
|
|
9063
|
+
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
9064
|
+
return {
|
|
9065
|
+
markDefs: event.annotations?.map((annotation) => ({
|
|
9066
|
+
_type: annotation.name,
|
|
9067
|
+
_key: snapshot.context.keyGenerator(),
|
|
9068
|
+
...annotation.value
|
|
9069
|
+
})) ?? [],
|
|
9070
|
+
focusTextBlock
|
|
9071
|
+
};
|
|
9056
9072
|
},
|
|
9057
|
-
|
|
9058
|
-
|
|
9059
|
-
|
|
9060
|
-
}
|
|
9061
|
-
|
|
9062
|
-
guard: ({
|
|
9063
|
-
snapshot,
|
|
9064
|
-
event
|
|
9065
|
-
}) => {
|
|
9066
|
-
const focusTextBlock = getFocusTextBlock(snapshot);
|
|
9067
|
-
return {
|
|
9068
|
-
markDefs: event.annotations?.map((annotation) => ({
|
|
9069
|
-
_type: annotation.name,
|
|
9070
|
-
_key: snapshot.context.keyGenerator(),
|
|
9071
|
-
...annotation.value
|
|
9072
|
-
})) ?? [],
|
|
9073
|
+
actions: [({
|
|
9074
|
+
snapshot,
|
|
9075
|
+
event
|
|
9076
|
+
}, {
|
|
9077
|
+
markDefs,
|
|
9073
9078
|
focusTextBlock
|
|
9074
|
-
}
|
|
9075
|
-
|
|
9076
|
-
|
|
9077
|
-
|
|
9078
|
-
|
|
9079
|
-
|
|
9080
|
-
|
|
9081
|
-
|
|
9082
|
-
|
|
9083
|
-
|
|
9084
|
-
|
|
9085
|
-
|
|
9086
|
-
|
|
9087
|
-
}
|
|
9088
|
-
})
|
|
9089
|
-
|
|
9090
|
-
|
|
9091
|
-
|
|
9092
|
-
|
|
9093
|
-
|
|
9094
|
-
|
|
9095
|
-
|
|
9096
|
-
|
|
9097
|
-
|
|
9098
|
-
|
|
9099
|
-
|
|
9100
|
-
|
|
9101
|
-
|
|
9102
|
-
|
|
9103
|
-
|
|
9104
|
-
|
|
9105
|
-
|
|
9106
|
-
|
|
9107
|
-
|
|
9108
|
-
|
|
9109
|
-
|
|
9110
|
-
|
|
9111
|
-
|
|
9112
|
-
|
|
9113
|
-
|
|
9114
|
-
|
|
9079
|
+
}) => [...focusTextBlock ? [raise({
|
|
9080
|
+
type: "block.set",
|
|
9081
|
+
at: focusTextBlock.path,
|
|
9082
|
+
props: {
|
|
9083
|
+
markDefs: [...focusTextBlock.node.markDefs ?? [], ...markDefs]
|
|
9084
|
+
}
|
|
9085
|
+
})] : [], raise({
|
|
9086
|
+
type: "insert.child",
|
|
9087
|
+
child: {
|
|
9088
|
+
_type: snapshot.context.schema.span.name,
|
|
9089
|
+
text: event.text,
|
|
9090
|
+
marks: [...event.decorators ?? [], ...markDefs.map((markDef) => markDef._key)]
|
|
9091
|
+
}
|
|
9092
|
+
})]]
|
|
9093
|
+
}),
|
|
9094
|
+
/**
|
|
9095
|
+
* If there's an expanded selection, then we delete the selection before we
|
|
9096
|
+
* insert the text.
|
|
9097
|
+
*/
|
|
9098
|
+
defineBehavior({
|
|
9099
|
+
on: "insert.text",
|
|
9100
|
+
guard: ({
|
|
9101
|
+
snapshot
|
|
9102
|
+
}) => isSelectionExpanded(snapshot),
|
|
9103
|
+
actions: [({
|
|
9104
|
+
event
|
|
9105
|
+
}) => [raise({
|
|
9106
|
+
type: "delete"
|
|
9107
|
+
}), raise(event)]]
|
|
9108
|
+
}),
|
|
9109
|
+
/**
|
|
9110
|
+
* If there's no selection, then we select the end of the editor before we
|
|
9111
|
+
* we insert the text.
|
|
9112
|
+
*/
|
|
9113
|
+
defineBehavior({
|
|
9114
|
+
on: "insert.text",
|
|
9115
|
+
guard: ({
|
|
9116
|
+
snapshot
|
|
9117
|
+
}) => {
|
|
9118
|
+
if (snapshot.context.selection)
|
|
9119
|
+
return !1;
|
|
9120
|
+
const lastBlok = getLastBlock$1(snapshot);
|
|
9121
|
+
return lastBlok ? {
|
|
9122
|
+
endPoint: getBlockEndPoint({
|
|
9123
|
+
context: snapshot.context,
|
|
9124
|
+
block: lastBlok
|
|
9125
|
+
})
|
|
9126
|
+
} : !1;
|
|
9127
|
+
},
|
|
9128
|
+
actions: [({
|
|
9129
|
+
event
|
|
9130
|
+
}, {
|
|
9131
|
+
endPoint
|
|
9132
|
+
}) => [raise({
|
|
9133
|
+
type: "select",
|
|
9134
|
+
at: {
|
|
9135
|
+
anchor: endPoint,
|
|
9136
|
+
focus: endPoint
|
|
9137
|
+
}
|
|
9138
|
+
}), raise(event)]]
|
|
9139
|
+
})
|
|
9140
|
+
], shiftLeft = createKeyboardShortcut({
|
|
9115
9141
|
default: [{
|
|
9116
9142
|
key: "ArrowLeft",
|
|
9117
9143
|
shift: !0,
|
|
@@ -9584,86 +9610,34 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
9584
9610
|
const selection = snapshot.context.selection;
|
|
9585
9611
|
if (!selection || isSelectionCollapsed(selection))
|
|
9586
9612
|
return !1;
|
|
9587
|
-
const
|
|
9588
|
-
|
|
9589
|
-
selection
|
|
9590
|
-
} : !1;
|
|
9591
|
-
},
|
|
9592
|
-
actions: [(_, {
|
|
9593
|
-
selection
|
|
9594
|
-
}) => [raise({
|
|
9595
|
-
type: "delete",
|
|
9596
|
-
at: selection
|
|
9597
|
-
})]]
|
|
9598
|
-
}),
|
|
9599
|
-
defineBehavior({
|
|
9600
|
-
on: "split",
|
|
9601
|
-
guard: ({
|
|
9602
|
-
snapshot
|
|
9603
|
-
}) => {
|
|
9604
|
-
const selection = snapshot.context.selection;
|
|
9605
|
-
if (!selection || isSelectionCollapsed(selection))
|
|
9613
|
+
const startPoint = getSelectionStartPoint(selection), endPoint = getSelectionEndPoint(selection);
|
|
9614
|
+
if (!startPoint || !endPoint)
|
|
9606
9615
|
return !1;
|
|
9607
|
-
const
|
|
9608
|
-
if (!
|
|
9616
|
+
const startBlock = getSelectionStartBlock$1(snapshot), endBlock = getSelectionEndBlock$1(snapshot);
|
|
9617
|
+
if (!startBlock || !endBlock)
|
|
9609
9618
|
return !1;
|
|
9610
|
-
const
|
|
9619
|
+
const startBlockStartPoint = getBlockStartPoint({
|
|
9611
9620
|
context: snapshot.context,
|
|
9612
|
-
block:
|
|
9613
|
-
}),
|
|
9621
|
+
block: startBlock
|
|
9622
|
+
}), endBlockEndPoint = getBlockEndPoint({
|
|
9614
9623
|
context: snapshot.context,
|
|
9615
|
-
block:
|
|
9616
|
-
})
|
|
9617
|
-
return
|
|
9618
|
-
startPoint,
|
|
9619
|
-
startBlockEndPoint,
|
|
9620
|
-
endPoint,
|
|
9621
|
-
endBlockStartPoint,
|
|
9622
|
-
blocksInBetween
|
|
9623
|
-
};
|
|
9624
|
+
block: endBlock
|
|
9625
|
+
});
|
|
9626
|
+
return !!(isTextBlock(snapshot.context, startBlock.node) && isTextBlock(snapshot.context, endBlock.node) && !isEqualSelectionPoints(startPoint, startBlockStartPoint) && !isEqualSelectionPoints(endPoint, endBlockEndPoint));
|
|
9624
9627
|
},
|
|
9625
|
-
actions: [(
|
|
9626
|
-
|
|
9627
|
-
|
|
9628
|
-
|
|
9629
|
-
endBlockStartPoint,
|
|
9630
|
-
blocksInBetween
|
|
9631
|
-
}) => [raise({
|
|
9632
|
-
type: "delete",
|
|
9633
|
-
at: {
|
|
9634
|
-
anchor: startPoint,
|
|
9635
|
-
focus: startBlockEndPoint
|
|
9636
|
-
}
|
|
9637
|
-
}), ...blocksInBetween.map((block) => raise({
|
|
9638
|
-
type: "delete.block",
|
|
9639
|
-
at: [{
|
|
9640
|
-
_key: block._key
|
|
9641
|
-
}]
|
|
9642
|
-
})), raise({
|
|
9643
|
-
type: "delete",
|
|
9644
|
-
at: {
|
|
9645
|
-
anchor: endBlockStartPoint,
|
|
9646
|
-
focus: endPoint
|
|
9647
|
-
}
|
|
9628
|
+
actions: [() => [raise({
|
|
9629
|
+
type: "delete"
|
|
9630
|
+
}), raise({
|
|
9631
|
+
type: "split"
|
|
9648
9632
|
})]]
|
|
9649
9633
|
}),
|
|
9650
9634
|
defineBehavior({
|
|
9651
9635
|
on: "split",
|
|
9652
9636
|
guard: ({
|
|
9653
9637
|
snapshot
|
|
9654
|
-
}) =>
|
|
9655
|
-
|
|
9656
|
-
|
|
9657
|
-
selection
|
|
9658
|
-
};
|
|
9659
|
-
},
|
|
9660
|
-
actions: [(_, {
|
|
9661
|
-
selection
|
|
9662
|
-
}) => [raise({
|
|
9663
|
-
type: "delete",
|
|
9664
|
-
at: selection
|
|
9665
|
-
}), raise({
|
|
9666
|
-
type: "split"
|
|
9638
|
+
}) => isSelectionExpanded(snapshot),
|
|
9639
|
+
actions: [() => [raise({
|
|
9640
|
+
type: "delete"
|
|
9667
9641
|
})]]
|
|
9668
9642
|
}),
|
|
9669
9643
|
defineBehavior({
|
|
@@ -12973,12 +12947,12 @@ function EditorProvider(props) {
|
|
|
12973
12947
|
return $[26] !== internalEditor_0.editor || $[27] !== t7 ? (t8 = /* @__PURE__ */ jsx(EditorContext.Provider, { value: internalEditor_0.editor, children: t7 }), $[26] = internalEditor_0.editor, $[27] = t7, $[28] = t8) : t8 = $[28], t8;
|
|
12974
12948
|
}
|
|
12975
12949
|
const usePortableTextEditorSelection = () => {
|
|
12976
|
-
const $ = c(3), editorActor = useContext(EditorActorContext), [selection,
|
|
12950
|
+
const $ = c(3), editorActor = useContext(EditorActorContext), [selection, setSelection] = useState(null);
|
|
12977
12951
|
let t0, t1;
|
|
12978
12952
|
return $[0] !== editorActor ? (t0 = () => {
|
|
12979
12953
|
const subscription = editorActor.on("selection", (event) => {
|
|
12980
12954
|
startTransition(() => {
|
|
12981
|
-
|
|
12955
|
+
setSelection(event.selection);
|
|
12982
12956
|
});
|
|
12983
12957
|
});
|
|
12984
12958
|
return () => {
|