@portabletext/editor 4.2.1 → 4.2.3
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-dts/behavior.types.action.d.ts +25 -24
- package/lib/index.js +788 -331
- package/lib/index.js.map +1 -1
- package/package.json +8 -8
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { c } from "react/compiler-runtime";
|
|
|
3
3
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
4
4
|
import { createContext, useContext, useRef, useState, useEffect, forwardRef, Component, startTransition } from "react";
|
|
5
5
|
import { Element as Element$1, Text, Range, Editor, Node, Point, Path, Transforms, createEditor, deleteText, Operation } from "slate";
|
|
6
|
-
import { useSlateStatic, ReactEditor, useSlate, Editable, withReact, Slate } from "slate-react";
|
|
6
|
+
import { useSlateStatic, useSlateSelector, ReactEditor, useSlate, Editable, withReact, Slate } from "slate-react";
|
|
7
7
|
import rawDebug from "debug";
|
|
8
8
|
import { DOMEditor, isDOMNode, EDITOR_TO_PENDING_SELECTION, IS_FOCUSED, IS_READ_ONLY } from "slate-dom";
|
|
9
9
|
import { getBlockEndPoint, getBlockStartPoint, getBlockKeyFromSelectionPoint, isSelectionCollapsed, isKeyedSegment, isEqualSelectionPoints, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, defaultKeyGenerator, parseBlocks, parseBlock, isListBlock, isTypedObject, getSelectionStartPoint as getSelectionStartPoint$1, getSelectionEndPoint as getSelectionEndPoint$1, parseAnnotation, parseMarkDefs, parseSpan, parseInlineObject } from "./_chunks-es/util.slice-blocks.js";
|
|
@@ -1575,90 +1575,90 @@ function RenderChild$1({
|
|
|
1575
1575
|
});
|
|
1576
1576
|
}
|
|
1577
1577
|
function RenderTextBlock(props) {
|
|
1578
|
-
const $ = c(
|
|
1578
|
+
const $ = c(76), blockRef = useRef(null), {
|
|
1579
1579
|
selectedBlockKeys,
|
|
1580
1580
|
focusedBlockKey
|
|
1581
1581
|
} = useContext(SelectionStateContext);
|
|
1582
1582
|
let t0;
|
|
1583
1583
|
$[0] !== props.textBlock._key || $[1] !== selectedBlockKeys ? (t0 = selectedBlockKeys.has(props.textBlock._key), $[0] = props.textBlock._key, $[1] = selectedBlockKeys, $[2] = t0) : t0 = $[2];
|
|
1584
|
-
const selected = t0, focused = focusedBlockKey === props.textBlock._key
|
|
1584
|
+
const selected = t0, focused = focusedBlockKey === props.textBlock._key;
|
|
1585
1585
|
let t1;
|
|
1586
|
-
$[3] !== props.textBlock._key
|
|
1587
|
-
const listIndex = t1;
|
|
1586
|
+
$[3] !== props.textBlock._key ? (t1 = (editor) => editor.listIndexMap.get(props.textBlock._key), $[3] = props.textBlock._key, $[4] = t1) : t1 = $[4];
|
|
1587
|
+
const listIndex = useSlateSelector(t1);
|
|
1588
1588
|
let children = props.children;
|
|
1589
1589
|
if (props.renderStyle && props.textBlock.style) {
|
|
1590
1590
|
let t22;
|
|
1591
|
-
$[
|
|
1591
|
+
$[5] !== props.legacySchema || $[6] !== props.textBlock.style ? (t22 = props.textBlock.style !== void 0 ? props.legacySchema.styles.find((style) => style.value === props.textBlock.style) : void 0, $[5] = props.legacySchema, $[6] = props.textBlock.style, $[7] = t22) : t22 = $[7];
|
|
1592
1592
|
const legacyStyleSchemaType = t22;
|
|
1593
1593
|
if (legacyStyleSchemaType) {
|
|
1594
1594
|
let t32;
|
|
1595
|
-
$[
|
|
1595
|
+
$[8] !== props.textBlock._key ? (t32 = [{
|
|
1596
1596
|
_key: props.textBlock._key
|
|
1597
|
-
}], $[
|
|
1597
|
+
}], $[8] = props.textBlock._key, $[9] = t32) : t32 = $[9];
|
|
1598
1598
|
let t42;
|
|
1599
|
-
$[
|
|
1599
|
+
$[10] !== children || $[11] !== focused || $[12] !== legacyStyleSchemaType || $[13] !== props.renderStyle || $[14] !== props.textBlock || $[15] !== selected || $[16] !== t32 ? (t42 = /* @__PURE__ */ jsx(RenderStyle, { renderStyle: props.renderStyle, block: props.textBlock, editorElementRef: blockRef, focused, path: t32, schemaType: legacyStyleSchemaType, selected, value: props.textBlock.style, children }), $[10] = children, $[11] = focused, $[12] = legacyStyleSchemaType, $[13] = props.renderStyle, $[14] = props.textBlock, $[15] = selected, $[16] = t32, $[17] = t42) : t42 = $[17], children = t42;
|
|
1600
1600
|
} else
|
|
1601
1601
|
console.error(`Unable to find Schema type for text block style ${props.textBlock.style}`);
|
|
1602
1602
|
}
|
|
1603
1603
|
if (props.renderListItem && props.textBlock.listItem) {
|
|
1604
1604
|
let t22;
|
|
1605
|
-
if ($[
|
|
1605
|
+
if ($[18] !== props.legacySchema.lists || $[19] !== props.textBlock.listItem) {
|
|
1606
1606
|
let t32;
|
|
1607
|
-
$[
|
|
1607
|
+
$[21] !== props.textBlock.listItem ? (t32 = (list) => list.value === props.textBlock.listItem, $[21] = props.textBlock.listItem, $[22] = t32) : t32 = $[22], t22 = props.legacySchema.lists.find(t32), $[18] = props.legacySchema.lists, $[19] = props.textBlock.listItem, $[20] = t22;
|
|
1608
1608
|
} else
|
|
1609
|
-
t22 = $[
|
|
1609
|
+
t22 = $[20];
|
|
1610
1610
|
const legacyListItemSchemaType = t22;
|
|
1611
1611
|
if (legacyListItemSchemaType) {
|
|
1612
1612
|
const t32 = props.textBlock.level ?? 1;
|
|
1613
1613
|
let t42;
|
|
1614
|
-
$[
|
|
1614
|
+
$[23] !== props.textBlock._key ? (t42 = [{
|
|
1615
1615
|
_key: props.textBlock._key
|
|
1616
|
-
}], $[
|
|
1616
|
+
}], $[23] = props.textBlock._key, $[24] = t42) : t42 = $[24];
|
|
1617
1617
|
let t52;
|
|
1618
|
-
$[
|
|
1618
|
+
$[25] !== children || $[26] !== focused || $[27] !== legacyListItemSchemaType || $[28] !== props.renderListItem || $[29] !== props.textBlock || $[30] !== selected || $[31] !== t32 || $[32] !== t42 ? (t52 = /* @__PURE__ */ jsx(RenderListItem, { renderListItem: props.renderListItem, block: props.textBlock, editorElementRef: blockRef, focused, level: t32, path: t42, selected, value: props.textBlock.listItem, schemaType: legacyListItemSchemaType, children }), $[25] = children, $[26] = focused, $[27] = legacyListItemSchemaType, $[28] = props.renderListItem, $[29] = props.textBlock, $[30] = selected, $[31] = t32, $[32] = t42, $[33] = t52) : t52 = $[33], children = t52;
|
|
1619
1619
|
} else
|
|
1620
1620
|
console.error(`Unable to find Schema type for text block list item ${props.textBlock.listItem}`);
|
|
1621
1621
|
}
|
|
1622
1622
|
const t2 = props.attributes;
|
|
1623
1623
|
let t3;
|
|
1624
|
-
$[
|
|
1624
|
+
$[34] !== props.textBlock.style ? (t3 = props.textBlock.style ? [`pt-text-block-style-${props.textBlock.style}`] : [], $[34] = props.textBlock.style, $[35] = t3) : t3 = $[35];
|
|
1625
1625
|
let t4;
|
|
1626
|
-
$[
|
|
1626
|
+
$[36] !== props.textBlock.level || $[37] !== props.textBlock.listItem ? (t4 = props.textBlock.listItem ? ["pt-list-item", `pt-list-item-${props.textBlock.listItem}`, `pt-list-item-level-${props.textBlock.level ?? 1}`] : [], $[36] = props.textBlock.level, $[37] = props.textBlock.listItem, $[38] = t4) : t4 = $[38];
|
|
1627
1627
|
let t5;
|
|
1628
|
-
$[
|
|
1628
|
+
$[39] !== t3 || $[40] !== t4 ? (t5 = ["pt-block", "pt-text-block", ...t3, ...t4], $[39] = t3, $[40] = t4, $[41] = t5) : t5 = $[41];
|
|
1629
1629
|
const t6 = t5.join(" ");
|
|
1630
1630
|
let t7;
|
|
1631
|
-
$[
|
|
1631
|
+
$[42] !== props.textBlock.listItem ? (t7 = props.textBlock.listItem !== void 0 ? {
|
|
1632
1632
|
"data-list-item": props.textBlock.listItem
|
|
1633
|
-
} : {}, $[
|
|
1633
|
+
} : {}, $[42] = props.textBlock.listItem, $[43] = t7) : t7 = $[43];
|
|
1634
1634
|
let t8;
|
|
1635
|
-
$[
|
|
1635
|
+
$[44] !== props.textBlock.level ? (t8 = props.textBlock.level !== void 0 ? {
|
|
1636
1636
|
"data-level": props.textBlock.level
|
|
1637
|
-
} : {}, $[
|
|
1637
|
+
} : {}, $[44] = props.textBlock.level, $[45] = t8) : t8 = $[45];
|
|
1638
1638
|
let t9;
|
|
1639
|
-
$[
|
|
1639
|
+
$[46] !== props.textBlock.style ? (t9 = props.textBlock.style !== void 0 ? {
|
|
1640
1640
|
"data-style": props.textBlock.style
|
|
1641
|
-
} : {}, $[
|
|
1641
|
+
} : {}, $[46] = props.textBlock.style, $[47] = t9) : t9 = $[47];
|
|
1642
1642
|
let t10;
|
|
1643
|
-
$[
|
|
1643
|
+
$[48] !== listIndex ? (t10 = listIndex !== void 0 ? {
|
|
1644
1644
|
"data-list-index": listIndex
|
|
1645
|
-
} : {}, $[
|
|
1645
|
+
} : {}, $[48] = listIndex, $[49] = t10) : t10 = $[49];
|
|
1646
1646
|
let t11;
|
|
1647
|
-
$[
|
|
1647
|
+
$[50] !== props.dropPosition ? (t11 = props.dropPosition === "start" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null, $[50] = props.dropPosition, $[51] = t11) : t11 = $[51];
|
|
1648
1648
|
let t12;
|
|
1649
|
-
$[
|
|
1649
|
+
$[52] !== children || $[53] !== focused || $[54] !== props.legacySchema || $[55] !== props.renderBlock || $[56] !== props.textBlock || $[57] !== selected ? (t12 = props.renderBlock ? /* @__PURE__ */ jsx(RenderBlock, { renderBlock: props.renderBlock, editorElementRef: blockRef, focused, level: props.textBlock.level, listItem: props.textBlock.listItem, path: [{
|
|
1650
1650
|
_key: props.textBlock._key
|
|
1651
|
-
}], selected, schemaType: props.legacySchema.block, style: props.textBlock.style, type: props.legacySchema.block, value: props.textBlock, children }) : children, $[
|
|
1651
|
+
}], selected, schemaType: props.legacySchema.block, style: props.textBlock.style, type: props.legacySchema.block, value: props.textBlock, children }) : children, $[52] = children, $[53] = focused, $[54] = props.legacySchema, $[55] = props.renderBlock, $[56] = props.textBlock, $[57] = selected, $[58] = t12) : t12 = $[58];
|
|
1652
1652
|
let t13;
|
|
1653
|
-
$[
|
|
1653
|
+
$[59] !== t12 ? (t13 = /* @__PURE__ */ jsx("div", { ref: blockRef, children: t12 }), $[59] = t12, $[60] = t13) : t13 = $[60];
|
|
1654
1654
|
let t14;
|
|
1655
|
-
$[
|
|
1655
|
+
$[61] !== props.dropPosition ? (t14 = props.dropPosition === "end" ? /* @__PURE__ */ jsx(DropIndicator, {}) : null, $[61] = props.dropPosition, $[62] = t14) : t14 = $[62];
|
|
1656
1656
|
let t15;
|
|
1657
|
-
return $[
|
|
1657
|
+
return $[63] !== props.attributes || $[64] !== props.spellCheck || $[65] !== props.textBlock._key || $[66] !== props.textBlock._type || $[67] !== t10 || $[68] !== t11 || $[69] !== t13 || $[70] !== t14 || $[71] !== t6 || $[72] !== t7 || $[73] !== t8 || $[74] !== t9 ? (t15 = /* @__PURE__ */ jsxs("div", { ...t2, className: t6, spellCheck: props.spellCheck, "data-block-key": props.textBlock._key, "data-block-name": props.textBlock._type, "data-block-type": "text", ...t7, ...t8, ...t9, ...t10, children: [
|
|
1658
1658
|
t11,
|
|
1659
1659
|
t13,
|
|
1660
1660
|
t14
|
|
1661
|
-
] }), $[
|
|
1661
|
+
] }), $[63] = props.attributes, $[64] = props.spellCheck, $[65] = props.textBlock._key, $[66] = props.textBlock._type, $[67] = t10, $[68] = t11, $[69] = t13, $[70] = t14, $[71] = t6, $[72] = t7, $[73] = t8, $[74] = t9, $[75] = t15) : t15 = $[75], t15;
|
|
1662
1662
|
}
|
|
1663
1663
|
function RenderBlock({
|
|
1664
1664
|
renderBlock,
|
|
@@ -3491,7 +3491,7 @@ function createBehaviorApiPlugin(editorActor) {
|
|
|
3491
3491
|
delete: editorDelete,
|
|
3492
3492
|
insertNodes,
|
|
3493
3493
|
select,
|
|
3494
|
-
setSelection
|
|
3494
|
+
setSelection: setSelection2
|
|
3495
3495
|
} = editor;
|
|
3496
3496
|
return editor.delete = (options) => {
|
|
3497
3497
|
if (editor.isNormalizingNode || editor.isPerformingBehaviorOperation) {
|
|
@@ -3645,7 +3645,7 @@ function createBehaviorApiPlugin(editorActor) {
|
|
|
3645
3645
|
});
|
|
3646
3646
|
}, editor.setSelection = (partialRange) => {
|
|
3647
3647
|
if (editor.isNormalizingNode || editor.isPerformingBehaviorOperation) {
|
|
3648
|
-
|
|
3648
|
+
setSelection2(partialRange);
|
|
3649
3649
|
return;
|
|
3650
3650
|
}
|
|
3651
3651
|
const anchor = partialRange.anchor ? slatePointToSelectionPoint({
|
|
@@ -3666,12 +3666,12 @@ function createBehaviorApiPlugin(editorActor) {
|
|
|
3666
3666
|
if (editor.selection) {
|
|
3667
3667
|
const newAnchor = partialRange.anchor ?? editor.selection.anchor, newFocus = partialRange.focus ?? editor.selection.focus;
|
|
3668
3668
|
if (Point.equals(newAnchor, editor.selection.anchor) && Point.equals(newFocus, editor.selection.focus)) {
|
|
3669
|
-
|
|
3669
|
+
setSelection2(partialRange);
|
|
3670
3670
|
return;
|
|
3671
3671
|
}
|
|
3672
3672
|
}
|
|
3673
3673
|
if (!anchor || !focus) {
|
|
3674
|
-
|
|
3674
|
+
setSelection2(partialRange);
|
|
3675
3675
|
return;
|
|
3676
3676
|
}
|
|
3677
3677
|
editorActor.send({
|
|
@@ -6271,25 +6271,44 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
6271
6271
|
guard: ({
|
|
6272
6272
|
snapshot,
|
|
6273
6273
|
event
|
|
6274
|
-
}) =>
|
|
6274
|
+
}) => {
|
|
6275
|
+
const at = event.at ?? snapshot.context.selection;
|
|
6276
|
+
if (!at)
|
|
6277
|
+
return !1;
|
|
6278
|
+
const adjustedSnapshot = {
|
|
6279
|
+
...snapshot,
|
|
6280
|
+
context: {
|
|
6281
|
+
...snapshot.context,
|
|
6282
|
+
selection: at
|
|
6283
|
+
}
|
|
6284
|
+
};
|
|
6285
|
+
return isActiveDecorator(event.decorator)(adjustedSnapshot);
|
|
6286
|
+
},
|
|
6275
6287
|
actions: [({
|
|
6276
6288
|
event
|
|
6277
6289
|
}) => [raise({
|
|
6278
6290
|
type: "decorator.remove",
|
|
6279
|
-
decorator: event.decorator
|
|
6291
|
+
decorator: event.decorator,
|
|
6292
|
+
at: event.at
|
|
6280
6293
|
})]]
|
|
6281
6294
|
}), defineBehavior({
|
|
6282
6295
|
on: "decorator.toggle",
|
|
6283
6296
|
guard: ({
|
|
6284
6297
|
snapshot,
|
|
6285
6298
|
event
|
|
6286
|
-
}) =>
|
|
6287
|
-
|
|
6288
|
-
|
|
6289
|
-
|
|
6290
|
-
|
|
6291
|
-
|
|
6292
|
-
|
|
6299
|
+
}) => {
|
|
6300
|
+
const at = event.at ?? snapshot.context.selection;
|
|
6301
|
+
if (!at)
|
|
6302
|
+
return !1;
|
|
6303
|
+
const adjustedSnapshot = {
|
|
6304
|
+
...snapshot,
|
|
6305
|
+
context: {
|
|
6306
|
+
...snapshot.context,
|
|
6307
|
+
selection: at
|
|
6308
|
+
}
|
|
6309
|
+
};
|
|
6310
|
+
return !isActiveDecorator(event.decorator)(adjustedSnapshot);
|
|
6311
|
+
},
|
|
6293
6312
|
actions: [({
|
|
6294
6313
|
event
|
|
6295
6314
|
}) => [raise({
|
|
@@ -6316,8 +6335,17 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
6316
6335
|
}) => {
|
|
6317
6336
|
if (event.direction !== "backward")
|
|
6318
6337
|
return !1;
|
|
6319
|
-
const
|
|
6320
|
-
if (!
|
|
6338
|
+
const at = event.at ?? snapshot.context.selection;
|
|
6339
|
+
if (!at)
|
|
6340
|
+
return !1;
|
|
6341
|
+
const adjustedSnapshot = {
|
|
6342
|
+
...snapshot,
|
|
6343
|
+
context: {
|
|
6344
|
+
...snapshot.context,
|
|
6345
|
+
selection: at
|
|
6346
|
+
}
|
|
6347
|
+
}, previousBlock = getPreviousBlock(adjustedSnapshot), focusTextBlock = getFocusTextBlock(adjustedSnapshot);
|
|
6348
|
+
if (!previousBlock || !focusTextBlock || !isAtTheStartOfBlock(focusTextBlock)(adjustedSnapshot))
|
|
6321
6349
|
return !1;
|
|
6322
6350
|
const previousBlockEndPoint = getBlockEndPoint({
|
|
6323
6351
|
context: snapshot.context,
|
|
@@ -6414,8 +6442,17 @@ const abstractAnnotationBehaviors = [defineBehavior({
|
|
|
6414
6442
|
}) => {
|
|
6415
6443
|
if (event.direction !== "forward")
|
|
6416
6444
|
return !1;
|
|
6417
|
-
const
|
|
6418
|
-
|
|
6445
|
+
const at = event.at ?? snapshot.context.selection;
|
|
6446
|
+
if (!at)
|
|
6447
|
+
return !1;
|
|
6448
|
+
const adjustedSnapshot = {
|
|
6449
|
+
...snapshot,
|
|
6450
|
+
context: {
|
|
6451
|
+
...snapshot.context,
|
|
6452
|
+
selection: at
|
|
6453
|
+
}
|
|
6454
|
+
}, nextBlock = getNextBlock(adjustedSnapshot), focusTextBlock = getFocusTextBlock(adjustedSnapshot);
|
|
6455
|
+
return !nextBlock || !focusTextBlock || !isAtTheEndOfBlock(focusTextBlock)(adjustedSnapshot) || !isTextBlock(snapshot.context, nextBlock.node) ? !1 : {
|
|
6419
6456
|
nextBlock
|
|
6420
6457
|
};
|
|
6421
6458
|
},
|
|
@@ -9104,7 +9141,13 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
9104
9141
|
snapshot,
|
|
9105
9142
|
event
|
|
9106
9143
|
}) => {
|
|
9107
|
-
const
|
|
9144
|
+
const adjustedSnapshot = {
|
|
9145
|
+
...snapshot,
|
|
9146
|
+
context: {
|
|
9147
|
+
...snapshot.context,
|
|
9148
|
+
selection: event.at ?? snapshot.context.selection
|
|
9149
|
+
}
|
|
9150
|
+
}, focusListBlock = getFocusListBlock(adjustedSnapshot);
|
|
9108
9151
|
if (!focusListBlock)
|
|
9109
9152
|
return !1;
|
|
9110
9153
|
const firstInsertedBlock = event.blocks.at(0), secondInsertedBlock = event.blocks.at(1), insertedListBlock = isListBlock(snapshot.context, firstInsertedBlock) ? firstInsertedBlock : isListBlock(snapshot.context, secondInsertedBlock) ? secondInsertedBlock : void 0;
|
|
@@ -9138,7 +9181,13 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
9138
9181
|
snapshot,
|
|
9139
9182
|
event
|
|
9140
9183
|
}) => {
|
|
9141
|
-
const
|
|
9184
|
+
const adjustedSnapshot = {
|
|
9185
|
+
...snapshot,
|
|
9186
|
+
context: {
|
|
9187
|
+
...snapshot.context,
|
|
9188
|
+
selection: event.at ?? snapshot.context.selection
|
|
9189
|
+
}
|
|
9190
|
+
}, focusListBlock = getFocusListBlock(adjustedSnapshot);
|
|
9142
9191
|
if (!focusListBlock || isEmptyTextBlock(snapshot.context, focusListBlock.node))
|
|
9143
9192
|
return !1;
|
|
9144
9193
|
const firstInsertedBlock = event.blocks.at(0), secondInsertedBlock = event.blocks.at(1), insertedListBlock = isListBlock(snapshot.context, firstInsertedBlock) ? firstInsertedBlock : isListBlock(snapshot.context, secondInsertedBlock) ? secondInsertedBlock : void 0;
|
|
@@ -9171,7 +9220,13 @@ const MAX_LIST_LEVEL = 10, clearListOnBackspace = defineBehavior({
|
|
|
9171
9220
|
}) => {
|
|
9172
9221
|
if (event.placement !== "auto" || event.block._type !== snapshot.context.schema.block.name || event.block.listItem !== void 0)
|
|
9173
9222
|
return !1;
|
|
9174
|
-
const
|
|
9223
|
+
const adjustedSnapshot = {
|
|
9224
|
+
...snapshot,
|
|
9225
|
+
context: {
|
|
9226
|
+
...snapshot.context,
|
|
9227
|
+
selection: event.at ?? snapshot.context.selection
|
|
9228
|
+
}
|
|
9229
|
+
}, focusListBlock = getFocusListBlock(adjustedSnapshot);
|
|
9175
9230
|
return !focusListBlock || !isEmptyTextBlock(snapshot.context, focusListBlock.node) ? !1 : {
|
|
9176
9231
|
level: focusListBlock.node.level,
|
|
9177
9232
|
listItem: focusListBlock.node.listItem
|
|
@@ -9237,6 +9292,31 @@ function getEventBehaviors(behaviorIndex, type) {
|
|
|
9237
9292
|
const global = behaviorIndex.global, namespace = type.includes(".") ? type.split(".").at(0) : type, namespaced = namespace ? behaviorIndex.namespaced.get(namespace) ?? [] : [], exact = behaviorIndex.exact.get(type) ?? [];
|
|
9238
9293
|
return [...global, ...namespaced, ...exact].sort((a, b) => a.sortOrder - b.sortOrder).map((sortedBehavior) => sortedBehavior.behavior);
|
|
9239
9294
|
}
|
|
9295
|
+
function createEditorSnapshot({
|
|
9296
|
+
converters,
|
|
9297
|
+
editor,
|
|
9298
|
+
keyGenerator,
|
|
9299
|
+
readOnly,
|
|
9300
|
+
schema
|
|
9301
|
+
}) {
|
|
9302
|
+
const selection = editor.selection ? slateRangeToSelection({
|
|
9303
|
+
schema,
|
|
9304
|
+
editor,
|
|
9305
|
+
range: editor.selection
|
|
9306
|
+
}) : null, context = {
|
|
9307
|
+
converters,
|
|
9308
|
+
keyGenerator,
|
|
9309
|
+
readOnly,
|
|
9310
|
+
schema,
|
|
9311
|
+
selection,
|
|
9312
|
+
value: editor.value
|
|
9313
|
+
};
|
|
9314
|
+
return {
|
|
9315
|
+
blockIndexMap: editor.blockIndexMap,
|
|
9316
|
+
context,
|
|
9317
|
+
decoratorState: editor.decoratorState
|
|
9318
|
+
};
|
|
9319
|
+
}
|
|
9240
9320
|
const addAnnotationOperationImplementation = ({
|
|
9241
9321
|
context,
|
|
9242
9322
|
operation
|
|
@@ -9587,84 +9667,96 @@ const addAnnotationOperationImplementation = ({
|
|
|
9587
9667
|
},
|
|
9588
9668
|
blockIndexMap: operation.editor.blockIndexMap
|
|
9589
9669
|
}) : operation.editor.selection;
|
|
9590
|
-
if (
|
|
9591
|
-
|
|
9592
|
-
|
|
9593
|
-
|
|
9594
|
-
|
|
9595
|
-
|
|
9596
|
-
|
|
9597
|
-
at: end,
|
|
9598
|
-
match: Text.isText,
|
|
9599
|
-
mode: "lowest",
|
|
9600
|
-
voids: !1,
|
|
9601
|
-
always: !endAtEndOfNode
|
|
9602
|
-
});
|
|
9603
|
-
const startAtStartOfNode = Editor.isStart(editor, start, start.path);
|
|
9604
|
-
if (Transforms.splitNodes(editor, {
|
|
9605
|
-
at: start,
|
|
9606
|
-
match: Text.isText,
|
|
9607
|
-
mode: "lowest",
|
|
9608
|
-
voids: !1,
|
|
9609
|
-
always: !startAtStartOfNode
|
|
9610
|
-
}), at = rangeRef.unref(), !at)
|
|
9611
|
-
throw new Error("Unable to add decorator without a selection");
|
|
9612
|
-
operation.at || Transforms.select(editor, at);
|
|
9613
|
-
const splitTextNodes = Editor.nodes(editor, {
|
|
9614
|
-
at,
|
|
9615
|
-
match: Text.isText
|
|
9616
|
-
});
|
|
9617
|
-
for (const [node, path] of splitTextNodes) {
|
|
9618
|
-
const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
9619
|
-
Transforms.setNodes(editor, {
|
|
9620
|
-
marks
|
|
9621
|
-
}, {
|
|
9622
|
-
at: path,
|
|
9670
|
+
if (at) {
|
|
9671
|
+
if (Range.isExpanded(at)) {
|
|
9672
|
+
const rangeRef = Editor.rangeRef(editor, at, {
|
|
9673
|
+
affinity: "inward"
|
|
9674
|
+
}), [start, end] = Range.edges(at), endAtEndOfNode = Editor.isEnd(editor, end, end.path);
|
|
9675
|
+
Transforms.splitNodes(editor, {
|
|
9676
|
+
at: end,
|
|
9623
9677
|
match: Text.isText,
|
|
9624
|
-
|
|
9625
|
-
|
|
9678
|
+
mode: "lowest",
|
|
9679
|
+
voids: !1,
|
|
9680
|
+
always: !endAtEndOfNode
|
|
9626
9681
|
});
|
|
9627
|
-
|
|
9628
|
-
|
|
9629
|
-
|
|
9630
|
-
|
|
9631
|
-
|
|
9632
|
-
|
|
9633
|
-
|
|
9634
|
-
|
|
9635
|
-
|
|
9636
|
-
|
|
9637
|
-
|
|
9638
|
-
|
|
9639
|
-
|
|
9640
|
-
marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
|
|
9641
|
-
}, {
|
|
9642
|
-
at: blockPath,
|
|
9643
|
-
match: (node) => editor.isTextSpan(node)
|
|
9682
|
+
const startAtStartOfNode = Editor.isStart(editor, start, start.path);
|
|
9683
|
+
if (Transforms.splitNodes(editor, {
|
|
9684
|
+
at: start,
|
|
9685
|
+
match: Text.isText,
|
|
9686
|
+
mode: "lowest",
|
|
9687
|
+
voids: !1,
|
|
9688
|
+
always: !startAtStartOfNode
|
|
9689
|
+
}), at = rangeRef.unref(), !at)
|
|
9690
|
+
throw new Error("Unable to add decorator without a selection");
|
|
9691
|
+
operation.at || Transforms.select(editor, at);
|
|
9692
|
+
const splitTextNodes = Editor.nodes(editor, {
|
|
9693
|
+
at,
|
|
9694
|
+
match: Text.isText
|
|
9644
9695
|
});
|
|
9645
|
-
|
|
9646
|
-
|
|
9647
|
-
|
|
9648
|
-
|
|
9649
|
-
|
|
9650
|
-
|
|
9651
|
-
|
|
9652
|
-
|
|
9696
|
+
for (const [node, path] of splitTextNodes) {
|
|
9697
|
+
const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
9698
|
+
Transforms.setNodes(editor, {
|
|
9699
|
+
marks
|
|
9700
|
+
}, {
|
|
9701
|
+
at: path,
|
|
9702
|
+
match: Text.isText,
|
|
9703
|
+
split: !0,
|
|
9704
|
+
hanging: !0
|
|
9705
|
+
});
|
|
9706
|
+
}
|
|
9707
|
+
} else {
|
|
9708
|
+
if (!Array.from(Editor.nodes(editor, {
|
|
9709
|
+
at,
|
|
9710
|
+
match: (node) => editor.isTextSpan(node)
|
|
9711
|
+
}))?.at(0))
|
|
9712
|
+
return;
|
|
9713
|
+
const [block, blockPath] = Editor.node(editor, at, {
|
|
9714
|
+
depth: 1
|
|
9715
|
+
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
9716
|
+
if (lonelyEmptySpan) {
|
|
9717
|
+
const existingMarks = lonelyEmptySpan.marks ?? [], existingMarksWithoutDecorator = existingMarks.filter((existingMark) => existingMark !== mark);
|
|
9718
|
+
Transforms.setNodes(editor, {
|
|
9719
|
+
marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
|
|
9720
|
+
}, {
|
|
9721
|
+
at: blockPath,
|
|
9722
|
+
match: (node) => editor.isTextSpan(node)
|
|
9723
|
+
});
|
|
9724
|
+
} else
|
|
9725
|
+
editor.decoratorState[mark] = !0;
|
|
9726
|
+
}
|
|
9727
|
+
if (editor.selection) {
|
|
9728
|
+
const selection = editor.selection;
|
|
9729
|
+
editor.selection = {
|
|
9730
|
+
...selection
|
|
9731
|
+
};
|
|
9732
|
+
}
|
|
9653
9733
|
}
|
|
9654
9734
|
}, decoratorRemoveOperationImplementation = ({
|
|
9735
|
+
context,
|
|
9655
9736
|
operation
|
|
9656
9737
|
}) => {
|
|
9657
|
-
const editor = operation.editor, mark = operation.decorator, {
|
|
9658
|
-
|
|
9659
|
-
|
|
9660
|
-
|
|
9661
|
-
|
|
9738
|
+
const editor = operation.editor, mark = operation.decorator, at = operation.at ? toSlateRange({
|
|
9739
|
+
context: {
|
|
9740
|
+
schema: context.schema,
|
|
9741
|
+
value: operation.editor.value,
|
|
9742
|
+
selection: operation.at
|
|
9743
|
+
},
|
|
9744
|
+
blockIndexMap: operation.editor.blockIndexMap
|
|
9745
|
+
}) : editor.selection;
|
|
9746
|
+
if (at) {
|
|
9747
|
+
if (Range.isExpanded(at)) {
|
|
9748
|
+
const rangeRef = Editor.rangeRef(editor, at, {
|
|
9749
|
+
affinity: "inward"
|
|
9750
|
+
});
|
|
9662
9751
|
Transforms.setNodes(editor, {}, {
|
|
9752
|
+
at,
|
|
9663
9753
|
match: Text.isText,
|
|
9664
9754
|
split: !0,
|
|
9665
9755
|
hanging: !0
|
|
9666
|
-
})
|
|
9667
|
-
|
|
9756
|
+
});
|
|
9757
|
+
const updatedAt = rangeRef.unref();
|
|
9758
|
+
updatedAt && [...Editor.nodes(editor, {
|
|
9759
|
+
at: updatedAt,
|
|
9668
9760
|
match: Text.isText
|
|
9669
9761
|
})].forEach(([node, path]) => {
|
|
9670
9762
|
const block = editor.children[path[0]];
|
|
@@ -9675,8 +9767,8 @@ const addAnnotationOperationImplementation = ({
|
|
|
9675
9767
|
at: path
|
|
9676
9768
|
});
|
|
9677
9769
|
});
|
|
9678
|
-
else {
|
|
9679
|
-
const [block, blockPath] = Editor.node(editor,
|
|
9770
|
+
} else {
|
|
9771
|
+
const [block, blockPath] = Editor.node(editor, at, {
|
|
9680
9772
|
depth: 1
|
|
9681
9773
|
}), lonelyEmptySpan = editor.isTextBlock(block) && block.children.length === 1 && editor.isTextSpan(block.children[0]) && block.children[0].text === "" ? block.children[0] : void 0;
|
|
9682
9774
|
if (lonelyEmptySpan) {
|
|
@@ -9691,9 +9783,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
9691
9783
|
editor.decoratorState[mark] = !1;
|
|
9692
9784
|
}
|
|
9693
9785
|
if (editor.selection) {
|
|
9694
|
-
const
|
|
9786
|
+
const selection = editor.selection;
|
|
9695
9787
|
editor.selection = {
|
|
9696
|
-
...
|
|
9788
|
+
...selection
|
|
9697
9789
|
};
|
|
9698
9790
|
}
|
|
9699
9791
|
}
|
|
@@ -10058,199 +10150,578 @@ function insertBlock(options) {
|
|
|
10058
10150
|
},
|
|
10059
10151
|
blockIndexMap: editor.blockIndexMap
|
|
10060
10152
|
}) : editor.selection;
|
|
10061
|
-
editor.children.length === 0
|
|
10062
|
-
|
|
10063
|
-
|
|
10153
|
+
if (editor.children.length === 0) {
|
|
10154
|
+
insertNodeAt(editor, [0], block, select);
|
|
10155
|
+
return;
|
|
10156
|
+
}
|
|
10064
10157
|
const start = at ? Range.start(at) : Editor.start(editor, []), end = at ? Range.end(at) : Editor.end(editor, []), [startBlock, startBlockPath] = Array.from(Editor.nodes(editor, {
|
|
10065
10158
|
at: start,
|
|
10066
10159
|
mode: "lowest",
|
|
10067
10160
|
match: (node, path) => Element$1.isElement(node) && path.length <= start.path.length
|
|
10068
|
-
})).at(0) ?? [void 0, void 0]
|
|
10161
|
+
})).at(0) ?? [void 0, void 0];
|
|
10162
|
+
let [endBlock, endBlockPath] = Array.from(Editor.nodes(editor, {
|
|
10069
10163
|
at: end,
|
|
10070
10164
|
mode: "lowest",
|
|
10071
10165
|
match: (node, path) => Element$1.isElement(node) && path.length <= end.path.length
|
|
10072
10166
|
})).at(0) ?? [void 0, void 0];
|
|
10073
10167
|
if (!startBlock || !startBlockPath || !endBlock || !endBlockPath)
|
|
10074
10168
|
throw new Error("Unable to insert block without a start and end block");
|
|
10169
|
+
if (placement === "before") {
|
|
10170
|
+
insertNodeAt(editor, startBlockPath, block, select);
|
|
10171
|
+
return;
|
|
10172
|
+
}
|
|
10173
|
+
if (placement === "after") {
|
|
10174
|
+
insertNodeAt(editor, Path.next(endBlockPath), block, select);
|
|
10175
|
+
return;
|
|
10176
|
+
}
|
|
10075
10177
|
if (!at) {
|
|
10076
|
-
if (
|
|
10077
|
-
|
|
10078
|
-
|
|
10079
|
-
|
|
10080
|
-
|
|
10081
|
-
const
|
|
10082
|
-
|
|
10083
|
-
|
|
10084
|
-
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
-
|
|
10088
|
-
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
|
|
10178
|
+
if (isEmptyTextBlock(context, endBlock)) {
|
|
10179
|
+
replaceEmptyTextBlock(editor, endBlockPath, block, select);
|
|
10180
|
+
return;
|
|
10181
|
+
}
|
|
10182
|
+
if (editor.isTextBlock(block) && editor.isTextBlock(endBlock)) {
|
|
10183
|
+
const selectionBefore = Editor.end(editor, endBlockPath);
|
|
10184
|
+
insertTextBlockFragment(editor, block, selectionBefore), select === "start" ? setSelectionToPoint(editor, selectionBefore) : select === "none" && clearSelection(editor);
|
|
10185
|
+
return;
|
|
10186
|
+
}
|
|
10187
|
+
insertNodeAt(editor, Path.next(endBlockPath), block, select);
|
|
10188
|
+
return;
|
|
10189
|
+
}
|
|
10190
|
+
if (Range.isExpanded(at) && !editor.isTextBlock(block)) {
|
|
10191
|
+
const atBeforeDelete = Editor.rangeRef(editor, at, {
|
|
10192
|
+
affinity: "inward"
|
|
10193
|
+
}), start2 = Range.start(at), startBlock2 = Node.get(editor, [start2.path[0]]), startOfBlock = Editor.start(editor, [start2.path[0]]), isAtStartOfBlock = Element$1.isElement(startBlock2) && Point.equals(start2, startOfBlock);
|
|
10194
|
+
deleteExpandedRange(editor, at);
|
|
10195
|
+
const atAfterDelete = atBeforeDelete.unref() ?? editor.selection, atBeforeInsert = atAfterDelete ? Editor.rangeRef(editor, atAfterDelete, {
|
|
10196
|
+
affinity: "inward"
|
|
10197
|
+
}) : void 0;
|
|
10198
|
+
if (atAfterDelete) {
|
|
10199
|
+
const insertPath = isAtStartOfBlock ? [atAfterDelete.anchor.path[0]] : [atAfterDelete.anchor.path[0] + 1];
|
|
10200
|
+
if (editor.apply({
|
|
10201
|
+
type: "insert_node",
|
|
10202
|
+
path: insertPath,
|
|
10203
|
+
node: block
|
|
10204
|
+
}), select !== "none") {
|
|
10205
|
+
const point = Editor.start(editor, insertPath);
|
|
10206
|
+
editor.apply({
|
|
10207
|
+
type: "set_selection",
|
|
10208
|
+
properties: editor.selection,
|
|
10209
|
+
newProperties: {
|
|
10210
|
+
anchor: point,
|
|
10211
|
+
focus: point
|
|
10212
|
+
}
|
|
10213
|
+
});
|
|
10094
10214
|
}
|
|
10095
|
-
|
|
10096
|
-
|
|
10097
|
-
|
|
10098
|
-
|
|
10099
|
-
|
|
10100
|
-
|
|
10215
|
+
}
|
|
10216
|
+
const atAfterInsert = atBeforeInsert?.unref() ?? editor.selection;
|
|
10217
|
+
if (select === "none" && atAfterInsert && editor.apply({
|
|
10218
|
+
type: "set_selection",
|
|
10219
|
+
properties: editor.selection,
|
|
10220
|
+
newProperties: atAfterInsert
|
|
10221
|
+
}), !editor.isTextBlock(block) && atAfterDelete) {
|
|
10222
|
+
const emptyBlockPath = isAtStartOfBlock ? [atAfterDelete.anchor.path[0] + 1] : [atAfterDelete.anchor.path[0]];
|
|
10223
|
+
try {
|
|
10224
|
+
const potentiallyEmptyBlock = Node.get(editor, emptyBlockPath);
|
|
10225
|
+
Element$1.isElement(potentiallyEmptyBlock) && isEmptyTextBlock(context, potentiallyEmptyBlock) && editor.apply({
|
|
10226
|
+
type: "remove_node",
|
|
10227
|
+
path: emptyBlockPath,
|
|
10228
|
+
node: potentiallyEmptyBlock
|
|
10229
|
+
});
|
|
10230
|
+
} catch {
|
|
10101
10231
|
}
|
|
10102
|
-
const nextPath = Path.next(endBlockPath);
|
|
10103
|
-
Transforms.insertNodes(editor, [block], {
|
|
10104
|
-
at: nextPath,
|
|
10105
|
-
select: !1
|
|
10106
|
-
}), select === "start" ? Transforms.select(editor, Editor.start(editor, nextPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, nextPath));
|
|
10107
10232
|
}
|
|
10108
10233
|
return;
|
|
10109
10234
|
}
|
|
10110
|
-
if (!at)
|
|
10111
|
-
|
|
10112
|
-
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
|
|
10116
|
-
|
|
10117
|
-
|
|
10118
|
-
|
|
10119
|
-
|
|
10120
|
-
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
|
|
10124
|
-
|
|
10125
|
-
|
|
10126
|
-
|
|
10127
|
-
|
|
10128
|
-
}
|
|
10129
|
-
|
|
10130
|
-
|
|
10131
|
-
|
|
10132
|
-
|
|
10133
|
-
|
|
10134
|
-
|
|
10135
|
-
|
|
10136
|
-
|
|
10137
|
-
|
|
10138
|
-
voids: !0,
|
|
10139
|
-
at: atAfterDelete ?? void 0,
|
|
10140
|
-
select: select !== "none"
|
|
10141
|
-
});
|
|
10142
|
-
const atAfterInsert = atBeforeInsert?.unref() ?? editor.selection;
|
|
10143
|
-
select === "none" && atAfterInsert && Transforms.select(editor, atAfterInsert), isEmptyTextBlock(context, focusBlock) && Transforms.removeNodes(editor, {
|
|
10144
|
-
at: focusBlockPath
|
|
10235
|
+
if (!editor.isTextBlock(block) && editor.isTextBlock(endBlock) && !Range.isExpanded(at)) {
|
|
10236
|
+
const selectionPoint = Range.start(at), blockPath = [selectionPoint.path[0]], blockStartPoint = Editor.start(editor, blockPath), blockEndPoint = Editor.end(editor, blockPath), isAtBlockStart = Point.equals(selectionPoint, blockStartPoint), isAtBlockEnd = Point.equals(selectionPoint, blockEndPoint);
|
|
10237
|
+
if (!isAtBlockStart && !isAtBlockEnd) {
|
|
10238
|
+
const currentBlock = Node.get(editor, blockPath), childIndex = selectionPoint.path[1], childOffset = selectionPoint.offset;
|
|
10239
|
+
if (childOffset > 0) {
|
|
10240
|
+
const textNode = Node.get(editor, selectionPoint.path);
|
|
10241
|
+
if (childOffset < textNode.text.length) {
|
|
10242
|
+
const {
|
|
10243
|
+
text: _2,
|
|
10244
|
+
...properties
|
|
10245
|
+
} = textNode;
|
|
10246
|
+
editor.apply({
|
|
10247
|
+
type: "split_node",
|
|
10248
|
+
path: selectionPoint.path,
|
|
10249
|
+
position: childOffset,
|
|
10250
|
+
properties
|
|
10251
|
+
});
|
|
10252
|
+
}
|
|
10253
|
+
}
|
|
10254
|
+
const splitAtIndex = childOffset > 0 ? childIndex + 1 : childIndex, {
|
|
10255
|
+
children: _,
|
|
10256
|
+
...blockProperties
|
|
10257
|
+
} = currentBlock;
|
|
10258
|
+
editor.apply({
|
|
10259
|
+
type: "split_node",
|
|
10260
|
+
path: blockPath,
|
|
10261
|
+
position: splitAtIndex,
|
|
10262
|
+
properties: blockProperties
|
|
10145
10263
|
});
|
|
10264
|
+
const insertPath = [blockPath[0] + 1];
|
|
10265
|
+
if (editor.apply({
|
|
10266
|
+
type: "insert_node",
|
|
10267
|
+
path: insertPath,
|
|
10268
|
+
node: block
|
|
10269
|
+
}), select === "none") {
|
|
10270
|
+
const firstBlockEndPoint = Editor.end(editor, blockPath);
|
|
10271
|
+
editor.apply({
|
|
10272
|
+
type: "set_selection",
|
|
10273
|
+
properties: editor.selection,
|
|
10274
|
+
newProperties: {
|
|
10275
|
+
anchor: firstBlockEndPoint,
|
|
10276
|
+
focus: firstBlockEndPoint
|
|
10277
|
+
}
|
|
10278
|
+
});
|
|
10279
|
+
} else if (select === "start") {
|
|
10280
|
+
const point = Editor.start(editor, insertPath);
|
|
10281
|
+
editor.apply({
|
|
10282
|
+
type: "set_selection",
|
|
10283
|
+
properties: editor.selection,
|
|
10284
|
+
newProperties: {
|
|
10285
|
+
anchor: point,
|
|
10286
|
+
focus: point
|
|
10287
|
+
}
|
|
10288
|
+
});
|
|
10289
|
+
} else if (select === "end") {
|
|
10290
|
+
const point = Editor.end(editor, insertPath);
|
|
10291
|
+
editor.apply({
|
|
10292
|
+
type: "set_selection",
|
|
10293
|
+
properties: editor.selection,
|
|
10294
|
+
newProperties: {
|
|
10295
|
+
anchor: point,
|
|
10296
|
+
focus: point
|
|
10297
|
+
}
|
|
10298
|
+
});
|
|
10299
|
+
}
|
|
10146
10300
|
return;
|
|
10147
10301
|
}
|
|
10148
|
-
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
|
|
10153
|
-
|
|
10154
|
-
|
|
10155
|
-
|
|
10156
|
-
|
|
10157
|
-
|
|
10158
|
-
|
|
10159
|
-
|
|
10160
|
-
if (endBlockMarkDefsKeys.includes(markDef._key)) {
|
|
10161
|
-
const newKey = context.keyGenerator();
|
|
10162
|
-
return markDefKeyMap.set(markDef._key, newKey), {
|
|
10163
|
-
...markDef,
|
|
10164
|
-
_key: newKey
|
|
10302
|
+
}
|
|
10303
|
+
if (editor.isTextBlock(endBlock) && editor.isTextBlock(block)) {
|
|
10304
|
+
let selectionStartPoint = Range.start(at), wasCrossBlockDeletion = !1;
|
|
10305
|
+
if (Range.isExpanded(at)) {
|
|
10306
|
+
const [start2, end2] = Range.edges(at), isCrossBlock = start2.path[0] !== end2.path[0];
|
|
10307
|
+
if (deleteExpandedRange(editor, at), isCrossBlock) {
|
|
10308
|
+
wasCrossBlockDeletion = !0;
|
|
10309
|
+
const startBlockPath2 = [start2.path[0]], mergedBlock = Node.get(editor, startBlockPath2);
|
|
10310
|
+
if (editor.isTextBlock(mergedBlock)) {
|
|
10311
|
+
const mergePoint = {
|
|
10312
|
+
path: [...startBlockPath2, start2.path[1]],
|
|
10313
|
+
offset: start2.offset
|
|
10165
10314
|
};
|
|
10315
|
+
setSelectionToPoint(editor, mergePoint), selectionStartPoint = mergePoint;
|
|
10166
10316
|
}
|
|
10167
|
-
|
|
10168
|
-
|
|
10169
|
-
|
|
10170
|
-
|
|
10171
|
-
|
|
10172
|
-
|
|
10173
|
-
|
|
10174
|
-
|
|
10175
|
-
|
|
10176
|
-
|
|
10177
|
-
|
|
10178
|
-
|
|
10179
|
-
|
|
10180
|
-
|
|
10181
|
-
|
|
10182
|
-
|
|
10183
|
-
|
|
10317
|
+
}
|
|
10318
|
+
const [newEndBlock, newEndBlockPath] = Array.from(Editor.nodes(editor, {
|
|
10319
|
+
at: Editor.end(editor, []),
|
|
10320
|
+
mode: "lowest",
|
|
10321
|
+
match: (node, path) => Element$1.isElement(node) && path.length === 1
|
|
10322
|
+
})).at(-1) ?? [void 0, void 0];
|
|
10323
|
+
newEndBlock && newEndBlockPath && Element$1.isElement(newEndBlock) && (endBlock = newEndBlock, endBlockPath = newEndBlockPath);
|
|
10324
|
+
}
|
|
10325
|
+
if (!editor.isTextBlock(endBlock))
|
|
10326
|
+
return;
|
|
10327
|
+
if (isEmptyTextBlock(context, endBlock)) {
|
|
10328
|
+
replaceEmptyTextBlock(editor, endBlockPath, block, select);
|
|
10329
|
+
return;
|
|
10330
|
+
}
|
|
10331
|
+
const endBlockChildKeys = endBlock.children.map((child) => child._key), endBlockMarkDefsKeys = endBlock.markDefs?.map((markDef) => markDef._key) ?? [], markDefKeyMap = /* @__PURE__ */ new Map(), adjustedMarkDefs = block.markDefs?.map((markDef) => {
|
|
10332
|
+
if (endBlockMarkDefsKeys.includes(markDef._key)) {
|
|
10333
|
+
const newKey = context.keyGenerator();
|
|
10334
|
+
return markDefKeyMap.set(markDef._key, newKey), {
|
|
10335
|
+
...markDef,
|
|
10336
|
+
_key: newKey
|
|
10337
|
+
};
|
|
10338
|
+
}
|
|
10339
|
+
return markDef;
|
|
10340
|
+
}), adjustedChildren = block.children.map((child) => {
|
|
10341
|
+
if (isSpan(context, child)) {
|
|
10342
|
+
const marks = child.marks?.map((mark) => markDefKeyMap.get(mark) || mark) ?? [];
|
|
10343
|
+
if (!isEqualMarks(child.marks, marks))
|
|
10344
|
+
return {
|
|
10345
|
+
...child,
|
|
10346
|
+
_key: endBlockChildKeys.includes(child._key) ? context.keyGenerator() : child._key,
|
|
10347
|
+
marks
|
|
10348
|
+
};
|
|
10349
|
+
}
|
|
10350
|
+
return endBlockChildKeys.includes(child._key) ? {
|
|
10351
|
+
...child,
|
|
10352
|
+
_key: context.keyGenerator()
|
|
10353
|
+
} : child;
|
|
10354
|
+
}), endBlockNode = Node.get(editor, endBlockPath);
|
|
10355
|
+
if (Element$1.isElement(endBlockNode) && editor.isTextBlock(endBlockNode)) {
|
|
10356
|
+
const properties = {
|
|
10357
|
+
markDefs: endBlockNode.markDefs
|
|
10358
|
+
}, newProperties = {
|
|
10184
10359
|
markDefs: [...endBlock.markDefs ?? [], ...adjustedMarkDefs ?? []]
|
|
10185
|
-
}, {
|
|
10186
|
-
at: endBlockPath
|
|
10187
|
-
});
|
|
10188
|
-
const adjustedBlock = isEqualChildren(block.children, adjustedChildren) ? block : {
|
|
10189
|
-
...block,
|
|
10190
|
-
children: adjustedChildren
|
|
10191
10360
|
};
|
|
10192
|
-
|
|
10193
|
-
|
|
10194
|
-
|
|
10195
|
-
|
|
10196
|
-
|
|
10197
|
-
}
|
|
10198
|
-
|
|
10199
|
-
|
|
10200
|
-
|
|
10201
|
-
|
|
10202
|
-
}
|
|
10203
|
-
|
|
10204
|
-
|
|
10205
|
-
|
|
10206
|
-
|
|
10207
|
-
|
|
10208
|
-
|
|
10209
|
-
|
|
10210
|
-
|
|
10211
|
-
|
|
10212
|
-
|
|
10213
|
-
Transforms.insertNodes(editor, [block], {
|
|
10214
|
-
at: nextPath,
|
|
10215
|
-
select: !1
|
|
10216
|
-
}), (select === "start" || select === "end") && Transforms.select(editor, Editor.start(editor, nextPath));
|
|
10217
|
-
} else if (Range.isExpanded(at) && Point.equals(selectionStartPoint, endBlockStartPoint) && Point.equals(selectionEndPoint, endBlockEndPoint2))
|
|
10218
|
-
Transforms.insertFragment(editor, [block], {
|
|
10219
|
-
at
|
|
10220
|
-
}), select === "start" ? Transforms.select(editor, Editor.start(editor, endBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, endBlockPath));
|
|
10221
|
-
else if (Range.isExpanded(at) && Point.equals(selectionStartPoint, endBlockStartPoint))
|
|
10222
|
-
Transforms.insertFragment(editor, [block], {
|
|
10223
|
-
at
|
|
10224
|
-
}), select === "start" ? Transforms.select(editor, Editor.start(editor, endBlockPath)) : select === "end" && Transforms.select(editor, Editor.end(editor, endBlockPath));
|
|
10225
|
-
else if (Range.isExpanded(at) && Point.equals(selectionEndPoint, endBlockEndPoint2))
|
|
10226
|
-
Transforms.insertFragment(editor, [block], {
|
|
10227
|
-
at
|
|
10228
|
-
}), select === "start" ? Transforms.select(editor, Editor.start(editor, Path.next(endBlockPath))) : select === "end" && Transforms.select(editor, Editor.end(editor, Path.next(endBlockPath)));
|
|
10361
|
+
editor.apply({
|
|
10362
|
+
type: "set_node",
|
|
10363
|
+
path: endBlockPath,
|
|
10364
|
+
properties,
|
|
10365
|
+
newProperties
|
|
10366
|
+
});
|
|
10367
|
+
}
|
|
10368
|
+
const adjustedBlock = isEqualChildren(block.children, adjustedChildren) ? block : {
|
|
10369
|
+
...block,
|
|
10370
|
+
children: adjustedChildren
|
|
10371
|
+
};
|
|
10372
|
+
if (select === "end") {
|
|
10373
|
+
const insertAt = editor.selection ? Range.end(editor.selection) : Editor.end(editor, endBlockPath);
|
|
10374
|
+
insertTextBlockFragment(editor, adjustedBlock, insertAt);
|
|
10375
|
+
return;
|
|
10376
|
+
}
|
|
10377
|
+
if (insertTextBlockFragment(editor, adjustedBlock, selectionStartPoint), select === "start")
|
|
10378
|
+
setSelectionToPoint(editor, selectionStartPoint);
|
|
10379
|
+
else if (select === "none")
|
|
10380
|
+
if (wasCrossBlockDeletion)
|
|
10381
|
+
setSelectionToPoint(editor, selectionStartPoint);
|
|
10229
10382
|
else {
|
|
10230
|
-
const
|
|
10231
|
-
|
|
10232
|
-
|
|
10233
|
-
|
|
10234
|
-
|
|
10235
|
-
|
|
10236
|
-
|
|
10237
|
-
|
|
10238
|
-
|
|
10239
|
-
|
|
10240
|
-
|
|
10241
|
-
|
|
10242
|
-
|
|
10243
|
-
|
|
10244
|
-
|
|
10383
|
+
const endBlockStartPoint = Editor.start(editor, endBlockPath);
|
|
10384
|
+
Point.equals(selectionStartPoint, endBlockStartPoint) || setSelectionToPoint(editor, selectionStartPoint);
|
|
10385
|
+
}
|
|
10386
|
+
} else {
|
|
10387
|
+
if (!editor.isTextBlock(endBlock)) {
|
|
10388
|
+
insertNodeAt(editor, [endBlockPath[0] + 1], block, select);
|
|
10389
|
+
return;
|
|
10390
|
+
}
|
|
10391
|
+
const endBlockStartPoint = Editor.start(editor, endBlockPath), endBlockEndPoint = Editor.end(editor, endBlockPath), selectionStartPoint = Range.start(at), selectionEndPoint = Range.end(at);
|
|
10392
|
+
if (Range.isCollapsed(at) && Point.equals(selectionStartPoint, endBlockStartPoint)) {
|
|
10393
|
+
editor.apply({
|
|
10394
|
+
type: "insert_node",
|
|
10395
|
+
path: endBlockPath,
|
|
10396
|
+
node: block
|
|
10397
|
+
}), select !== "none" && setSelection(editor, endBlockPath, "start"), isEmptyTextBlock(context, endBlock) && removeNodeAt(editor, Path.next(endBlockPath));
|
|
10398
|
+
return;
|
|
10399
|
+
}
|
|
10400
|
+
if (Range.isCollapsed(at) && Point.equals(selectionEndPoint, endBlockEndPoint)) {
|
|
10401
|
+
const nextPath = [endBlockPath[0] + 1];
|
|
10402
|
+
editor.apply({
|
|
10403
|
+
type: "insert_node",
|
|
10404
|
+
path: nextPath,
|
|
10405
|
+
node: block
|
|
10406
|
+
}), select !== "none" && setSelection(editor, nextPath, "start");
|
|
10407
|
+
return;
|
|
10408
|
+
}
|
|
10409
|
+
if (Range.isExpanded(at) && Point.equals(selectionStartPoint, endBlockStartPoint) && Point.equals(selectionEndPoint, endBlockEndPoint)) {
|
|
10410
|
+
editor.apply({
|
|
10411
|
+
type: "insert_node",
|
|
10412
|
+
path: endBlockPath,
|
|
10413
|
+
node: block
|
|
10414
|
+
}), removeNodeAt(editor, Path.next(endBlockPath)), select !== "none" && setSelection(editor, endBlockPath, select);
|
|
10415
|
+
return;
|
|
10416
|
+
}
|
|
10417
|
+
if (Range.isExpanded(at) && Point.equals(selectionStartPoint, endBlockStartPoint)) {
|
|
10418
|
+
const [, end2] = Range.edges(at), endNode = Node.get(editor, end2.path);
|
|
10419
|
+
end2.offset > 0 && editor.apply({
|
|
10420
|
+
type: "remove_text",
|
|
10421
|
+
path: end2.path,
|
|
10422
|
+
offset: 0,
|
|
10423
|
+
text: endNode.text.slice(0, end2.offset)
|
|
10424
|
+
});
|
|
10425
|
+
for (let i = end2.path[1] - 1; i >= 0; i--)
|
|
10426
|
+
removeNodeAt(editor, [...endBlockPath, i]);
|
|
10427
|
+
insertTextBlockFragment(editor, block, Editor.start(editor, endBlockPath)), select !== "none" && setSelection(editor, endBlockPath, select);
|
|
10428
|
+
return;
|
|
10429
|
+
}
|
|
10430
|
+
if (Range.isExpanded(at) && Point.equals(selectionEndPoint, endBlockEndPoint)) {
|
|
10431
|
+
const [start2] = Range.edges(at), blockNode = Node.get(editor, endBlockPath);
|
|
10432
|
+
for (let i = blockNode.children.length - 1; i > start2.path[1]; i--)
|
|
10433
|
+
removeNodeAt(editor, [...endBlockPath, i]);
|
|
10434
|
+
const startNode = Node.get(editor, start2.path);
|
|
10435
|
+
start2.offset < startNode.text.length && editor.apply({
|
|
10436
|
+
type: "remove_text",
|
|
10437
|
+
path: start2.path,
|
|
10438
|
+
offset: start2.offset,
|
|
10439
|
+
text: startNode.text.slice(start2.offset)
|
|
10440
|
+
}), insertTextBlockFragment(editor, block, start2), select !== "none" && setSelection(editor, Path.next(endBlockPath), select);
|
|
10441
|
+
return;
|
|
10442
|
+
}
|
|
10443
|
+
const [focusChild] = getFocusChild({
|
|
10444
|
+
editor
|
|
10445
|
+
});
|
|
10446
|
+
if (focusChild && editor.isTextSpan(focusChild)) {
|
|
10447
|
+
const startPoint = Range.start(at);
|
|
10448
|
+
if (editor.isTextBlock(block)) {
|
|
10449
|
+
const nodeToSplit = Node.get(editor, startPoint.path);
|
|
10450
|
+
if (Text.isText(nodeToSplit)) {
|
|
10451
|
+
const {
|
|
10452
|
+
text: _,
|
|
10453
|
+
...properties
|
|
10454
|
+
} = nodeToSplit;
|
|
10455
|
+
editor.apply({
|
|
10456
|
+
type: "split_node",
|
|
10457
|
+
path: startPoint.path,
|
|
10458
|
+
position: startPoint.offset,
|
|
10459
|
+
properties
|
|
10460
|
+
});
|
|
10461
|
+
}
|
|
10462
|
+
insertTextBlockFragment(editor, block, startPoint), select === "none" ? setSelectionToRange(editor, at) : setSelection(editor, [endBlockPath[0] + 1], "start");
|
|
10463
|
+
} else {
|
|
10464
|
+
let currentPath = startPoint.path, currentOffset = startPoint.offset;
|
|
10465
|
+
const cursorPositionRef = Editor.pointRef(editor, startPoint, {
|
|
10466
|
+
affinity: "backward"
|
|
10467
|
+
}), blockPath = [currentPath[0]], firstBlockPathRef = Editor.pathRef(editor, blockPath), textNode = Node.get(editor, currentPath);
|
|
10468
|
+
if (Text.isText(textNode) && currentOffset > 0 && currentOffset < textNode.text.length) {
|
|
10469
|
+
const {
|
|
10470
|
+
text: _,
|
|
10471
|
+
...properties
|
|
10472
|
+
} = textNode;
|
|
10473
|
+
editor.apply({
|
|
10474
|
+
type: "split_node",
|
|
10475
|
+
path: currentPath,
|
|
10476
|
+
position: currentOffset,
|
|
10477
|
+
properties
|
|
10478
|
+
}), currentPath = Path.next(currentPath), currentOffset = 0;
|
|
10479
|
+
}
|
|
10480
|
+
const splitAtIndex = currentOffset > 0 ? currentPath[1] + 1 : currentPath[1], blockToSplit = Node.get(editor, blockPath);
|
|
10481
|
+
if (splitAtIndex < blockToSplit.children.length && Element$1.isElement(blockToSplit)) {
|
|
10482
|
+
const {
|
|
10483
|
+
children: _,
|
|
10484
|
+
...blockProperties
|
|
10485
|
+
} = blockToSplit;
|
|
10486
|
+
editor.apply({
|
|
10487
|
+
type: "split_node",
|
|
10488
|
+
path: blockPath,
|
|
10489
|
+
position: splitAtIndex,
|
|
10490
|
+
properties: blockProperties
|
|
10491
|
+
});
|
|
10492
|
+
}
|
|
10493
|
+
const currentFirstBlockPath = firstBlockPathRef.unref(), insertPath = currentFirstBlockPath ? [currentFirstBlockPath[0] + 1] : [blockPath[0] + 1];
|
|
10494
|
+
if (editor.apply({
|
|
10495
|
+
type: "insert_node",
|
|
10496
|
+
path: insertPath,
|
|
10497
|
+
node: block
|
|
10498
|
+
}), select === "start" || select === "end") {
|
|
10499
|
+
const point = Editor.start(editor, insertPath);
|
|
10500
|
+
editor.apply({
|
|
10501
|
+
type: "set_selection",
|
|
10502
|
+
properties: editor.selection,
|
|
10503
|
+
newProperties: {
|
|
10504
|
+
anchor: point,
|
|
10505
|
+
focus: point
|
|
10506
|
+
}
|
|
10507
|
+
});
|
|
10508
|
+
} else {
|
|
10509
|
+
const point = cursorPositionRef.unref();
|
|
10510
|
+
point && editor.apply({
|
|
10511
|
+
type: "set_selection",
|
|
10512
|
+
properties: editor.selection,
|
|
10513
|
+
newProperties: {
|
|
10514
|
+
anchor: point,
|
|
10515
|
+
focus: point
|
|
10516
|
+
}
|
|
10517
|
+
});
|
|
10245
10518
|
}
|
|
10246
10519
|
}
|
|
10247
10520
|
} else {
|
|
10248
10521
|
const nextPath = [endBlockPath[0] + 1];
|
|
10249
|
-
|
|
10250
|
-
|
|
10251
|
-
|
|
10252
|
-
|
|
10522
|
+
editor.apply({
|
|
10523
|
+
type: "insert_node",
|
|
10524
|
+
path: nextPath,
|
|
10525
|
+
node: block
|
|
10526
|
+
}), select === "none" ? setSelectionToRange(editor, at) : setSelection(editor, nextPath, select);
|
|
10527
|
+
}
|
|
10528
|
+
}
|
|
10529
|
+
}
|
|
10530
|
+
function setSelection(editor, path, position) {
|
|
10531
|
+
const point = position === "start" ? Editor.start(editor, path) : Editor.end(editor, path);
|
|
10532
|
+
editor.apply({
|
|
10533
|
+
type: "set_selection",
|
|
10534
|
+
properties: editor.selection,
|
|
10535
|
+
newProperties: {
|
|
10536
|
+
anchor: point,
|
|
10537
|
+
focus: point
|
|
10538
|
+
}
|
|
10539
|
+
});
|
|
10540
|
+
}
|
|
10541
|
+
function clearSelection(editor) {
|
|
10542
|
+
editor.selection && editor.apply({
|
|
10543
|
+
type: "set_selection",
|
|
10544
|
+
properties: editor.selection,
|
|
10545
|
+
newProperties: null
|
|
10546
|
+
});
|
|
10547
|
+
}
|
|
10548
|
+
function setSelectionToPoint(editor, point) {
|
|
10549
|
+
editor.apply({
|
|
10550
|
+
type: "set_selection",
|
|
10551
|
+
properties: editor.selection,
|
|
10552
|
+
newProperties: {
|
|
10553
|
+
anchor: point,
|
|
10554
|
+
focus: point
|
|
10555
|
+
}
|
|
10556
|
+
});
|
|
10557
|
+
}
|
|
10558
|
+
function setSelectionToRange(editor, range) {
|
|
10559
|
+
editor.apply({
|
|
10560
|
+
type: "set_selection",
|
|
10561
|
+
properties: editor.selection,
|
|
10562
|
+
newProperties: range
|
|
10563
|
+
});
|
|
10564
|
+
}
|
|
10565
|
+
function insertNodeAt(editor, path, node, select) {
|
|
10566
|
+
editor.apply({
|
|
10567
|
+
type: "insert_node",
|
|
10568
|
+
path,
|
|
10569
|
+
node
|
|
10570
|
+
}), select !== "none" && setSelection(editor, path, select);
|
|
10571
|
+
}
|
|
10572
|
+
function removeNodeAt(editor, path) {
|
|
10573
|
+
const node = Node.get(editor, path);
|
|
10574
|
+
editor.apply({
|
|
10575
|
+
type: "remove_node",
|
|
10576
|
+
path,
|
|
10577
|
+
node
|
|
10578
|
+
});
|
|
10579
|
+
}
|
|
10580
|
+
function replaceEmptyTextBlock(editor, blockPath, newBlock, select) {
|
|
10581
|
+
const hadSelection = editor.selection !== null;
|
|
10582
|
+
if (editor.apply({
|
|
10583
|
+
type: "insert_node",
|
|
10584
|
+
path: blockPath,
|
|
10585
|
+
node: newBlock
|
|
10586
|
+
}), removeNodeAt(editor, Path.next(blockPath)), select === "none" && !hadSelection)
|
|
10587
|
+
return;
|
|
10588
|
+
const point = select === "end" ? Editor.end(editor, blockPath) : Editor.start(editor, blockPath);
|
|
10589
|
+
clearSelection(editor), editor.apply({
|
|
10590
|
+
type: "set_selection",
|
|
10591
|
+
properties: null,
|
|
10592
|
+
newProperties: {
|
|
10593
|
+
anchor: point,
|
|
10594
|
+
focus: point
|
|
10253
10595
|
}
|
|
10596
|
+
});
|
|
10597
|
+
}
|
|
10598
|
+
function deleteSameBlockRange(editor, start, end) {
|
|
10599
|
+
const blockPath = [start.path[0]];
|
|
10600
|
+
if (Path.equals(start.path, end.path)) {
|
|
10601
|
+
const textToRemove = Node.get(editor, start.path).text.slice(start.offset, end.offset);
|
|
10602
|
+
editor.apply({
|
|
10603
|
+
type: "remove_text",
|
|
10604
|
+
path: start.path,
|
|
10605
|
+
offset: start.offset,
|
|
10606
|
+
text: textToRemove
|
|
10607
|
+
});
|
|
10608
|
+
return;
|
|
10609
|
+
}
|
|
10610
|
+
const startNode = Node.get(editor, start.path);
|
|
10611
|
+
if (start.offset < startNode.text.length) {
|
|
10612
|
+
const textToRemove = startNode.text.slice(start.offset);
|
|
10613
|
+
editor.apply({
|
|
10614
|
+
type: "remove_text",
|
|
10615
|
+
path: start.path,
|
|
10616
|
+
offset: start.offset,
|
|
10617
|
+
text: textToRemove
|
|
10618
|
+
});
|
|
10619
|
+
}
|
|
10620
|
+
for (let i = end.path[1] - 1; i > start.path[1]; i--)
|
|
10621
|
+
removeNodeAt(editor, [...blockPath, i]);
|
|
10622
|
+
const newEndPath = [...blockPath, start.path[1] + 1], endNode = Node.get(editor, newEndPath);
|
|
10623
|
+
if (end.offset > 0) {
|
|
10624
|
+
const textToRemove = endNode.text.slice(0, end.offset);
|
|
10625
|
+
editor.apply({
|
|
10626
|
+
type: "remove_text",
|
|
10627
|
+
path: newEndPath,
|
|
10628
|
+
offset: 0,
|
|
10629
|
+
text: textToRemove
|
|
10630
|
+
});
|
|
10631
|
+
}
|
|
10632
|
+
const startNodeAfter = Node.get(editor, start.path), endNodeAfter = Node.get(editor, newEndPath);
|
|
10633
|
+
if (Text.isText(startNodeAfter) && Text.isText(endNodeAfter)) {
|
|
10634
|
+
const {
|
|
10635
|
+
text: _,
|
|
10636
|
+
...properties
|
|
10637
|
+
} = endNodeAfter;
|
|
10638
|
+
editor.apply({
|
|
10639
|
+
type: "merge_node",
|
|
10640
|
+
path: newEndPath,
|
|
10641
|
+
position: startNodeAfter.text.length,
|
|
10642
|
+
properties
|
|
10643
|
+
});
|
|
10644
|
+
}
|
|
10645
|
+
}
|
|
10646
|
+
function deleteCrossBlockRange(editor, start, end) {
|
|
10647
|
+
const startBlockPath = [start.path[0]];
|
|
10648
|
+
if (start.path.length > 1) {
|
|
10649
|
+
const startNode = Node.get(editor, start.path);
|
|
10650
|
+
if (start.offset < startNode.text.length) {
|
|
10651
|
+
const textToRemove = startNode.text.slice(start.offset);
|
|
10652
|
+
editor.apply({
|
|
10653
|
+
type: "remove_text",
|
|
10654
|
+
path: start.path,
|
|
10655
|
+
offset: start.offset,
|
|
10656
|
+
text: textToRemove
|
|
10657
|
+
});
|
|
10658
|
+
}
|
|
10659
|
+
const startBlock2 = Node.get(editor, startBlockPath);
|
|
10660
|
+
for (let i = startBlock2.children.length - 1; i > start.path[1]; i--)
|
|
10661
|
+
removeNodeAt(editor, [...startBlockPath, i]);
|
|
10662
|
+
}
|
|
10663
|
+
for (let i = end.path[0] - 1; i > start.path[0]; i--)
|
|
10664
|
+
removeNodeAt(editor, [i]);
|
|
10665
|
+
const adjustedEndBlockPath = [start.path[0] + 1];
|
|
10666
|
+
if (end.path.length > 1) {
|
|
10667
|
+
for (let i = 0; i < end.path[1]; i++)
|
|
10668
|
+
removeNodeAt(editor, [...adjustedEndBlockPath, 0]);
|
|
10669
|
+
const endNodePath = [...adjustedEndBlockPath, 0], endNode = Node.get(editor, endNodePath);
|
|
10670
|
+
if (end.offset > 0) {
|
|
10671
|
+
const textToRemove = endNode.text.slice(0, end.offset);
|
|
10672
|
+
editor.apply({
|
|
10673
|
+
type: "remove_text",
|
|
10674
|
+
path: endNodePath,
|
|
10675
|
+
offset: 0,
|
|
10676
|
+
text: textToRemove
|
|
10677
|
+
});
|
|
10678
|
+
}
|
|
10679
|
+
}
|
|
10680
|
+
const startBlock = Node.get(editor, startBlockPath), endBlock = Node.get(editor, adjustedEndBlockPath);
|
|
10681
|
+
if (editor.isTextBlock(startBlock) && editor.isTextBlock(endBlock)) {
|
|
10682
|
+
const {
|
|
10683
|
+
children: _,
|
|
10684
|
+
...properties
|
|
10685
|
+
} = endBlock;
|
|
10686
|
+
editor.apply({
|
|
10687
|
+
type: "merge_node",
|
|
10688
|
+
path: adjustedEndBlockPath,
|
|
10689
|
+
position: startBlock.children.length,
|
|
10690
|
+
properties
|
|
10691
|
+
});
|
|
10692
|
+
}
|
|
10693
|
+
}
|
|
10694
|
+
function deleteExpandedRange(editor, range) {
|
|
10695
|
+
const [start, end] = Range.edges(range);
|
|
10696
|
+
start.path[0] === end.path[0] ? deleteSameBlockRange(editor, start, end) : deleteCrossBlockRange(editor, start, end);
|
|
10697
|
+
}
|
|
10698
|
+
function insertTextBlockFragment(editor, block, at) {
|
|
10699
|
+
if (!Element$1.isElement(block) || !editor.isTextBlock(block))
|
|
10700
|
+
return;
|
|
10701
|
+
if (at.offset > 0) {
|
|
10702
|
+
const textNode = Node.get(editor, at.path);
|
|
10703
|
+
if (Text.isText(textNode)) {
|
|
10704
|
+
const {
|
|
10705
|
+
text: _,
|
|
10706
|
+
...properties
|
|
10707
|
+
} = textNode;
|
|
10708
|
+
editor.apply({
|
|
10709
|
+
type: "split_node",
|
|
10710
|
+
path: at.path,
|
|
10711
|
+
position: at.offset,
|
|
10712
|
+
properties
|
|
10713
|
+
});
|
|
10714
|
+
}
|
|
10715
|
+
}
|
|
10716
|
+
const parentPath = Path.parent(at.path);
|
|
10717
|
+
let insertIndex = at.path[at.path.length - 1] + (at.offset > 0 ? 1 : 0);
|
|
10718
|
+
for (const child of block.children) {
|
|
10719
|
+
const childPath = [...parentPath, insertIndex];
|
|
10720
|
+
editor.apply({
|
|
10721
|
+
type: "insert_node",
|
|
10722
|
+
path: childPath,
|
|
10723
|
+
node: child
|
|
10724
|
+
}), insertIndex++;
|
|
10254
10725
|
}
|
|
10255
10726
|
}
|
|
10256
10727
|
const insertChildOperationImplementation = ({
|
|
@@ -10585,9 +11056,10 @@ function performEvent({
|
|
|
10585
11056
|
forwardFromBehaviors,
|
|
10586
11057
|
event,
|
|
10587
11058
|
editor,
|
|
11059
|
+
converters,
|
|
10588
11060
|
keyGenerator,
|
|
11061
|
+
readOnly,
|
|
10589
11062
|
schema,
|
|
10590
|
-
getSnapshot,
|
|
10591
11063
|
nativeEvent,
|
|
10592
11064
|
sendBack
|
|
10593
11065
|
}) {
|
|
@@ -10605,10 +11077,16 @@ function performEvent({
|
|
|
10605
11077
|
editor
|
|
10606
11078
|
}
|
|
10607
11079
|
});
|
|
10608
|
-
}), editor.onChange();
|
|
11080
|
+
}), mode === "send" && editor.onChange();
|
|
10609
11081
|
return;
|
|
10610
11082
|
}
|
|
10611
|
-
const guardSnapshot =
|
|
11083
|
+
const guardSnapshot = createEditorSnapshot({
|
|
11084
|
+
converters,
|
|
11085
|
+
editor,
|
|
11086
|
+
keyGenerator,
|
|
11087
|
+
readOnly,
|
|
11088
|
+
schema
|
|
11089
|
+
});
|
|
10612
11090
|
let nativeEventPrevented = !1, defaultBehaviorOverwritten = !1, eventBehaviorIndex = -1;
|
|
10613
11091
|
for (const eventBehavior of eventBehaviors) {
|
|
10614
11092
|
eventBehaviorIndex++;
|
|
@@ -10628,7 +11106,13 @@ function performEvent({
|
|
|
10628
11106
|
let actionSetIndex = -1;
|
|
10629
11107
|
for (const actionSet of eventBehavior.actions) {
|
|
10630
11108
|
actionSetIndex++;
|
|
10631
|
-
const actionsSnapshot =
|
|
11109
|
+
const actionsSnapshot = createEditorSnapshot({
|
|
11110
|
+
converters,
|
|
11111
|
+
editor,
|
|
11112
|
+
keyGenerator,
|
|
11113
|
+
readOnly,
|
|
11114
|
+
schema
|
|
11115
|
+
});
|
|
10632
11116
|
let actions = [];
|
|
10633
11117
|
try {
|
|
10634
11118
|
actions = actionSet({
|
|
@@ -10666,9 +11150,10 @@ function performEvent({
|
|
|
10666
11150
|
forwardFromBehaviors: remainingBehaviors,
|
|
10667
11151
|
event: action.event,
|
|
10668
11152
|
editor,
|
|
11153
|
+
converters,
|
|
10669
11154
|
keyGenerator,
|
|
11155
|
+
readOnly,
|
|
10670
11156
|
schema,
|
|
10671
|
-
getSnapshot,
|
|
10672
11157
|
nativeEvent,
|
|
10673
11158
|
sendBack
|
|
10674
11159
|
});
|
|
@@ -10681,9 +11166,10 @@ function performEvent({
|
|
|
10681
11166
|
abstractBehaviorIndex,
|
|
10682
11167
|
event: action.event,
|
|
10683
11168
|
editor,
|
|
11169
|
+
converters,
|
|
10684
11170
|
keyGenerator,
|
|
11171
|
+
readOnly,
|
|
10685
11172
|
schema,
|
|
10686
|
-
getSnapshot,
|
|
10687
11173
|
nativeEvent,
|
|
10688
11174
|
sendBack
|
|
10689
11175
|
});
|
|
@@ -10695,9 +11181,10 @@ function performEvent({
|
|
|
10695
11181
|
abstractBehaviorIndex,
|
|
10696
11182
|
event: action.event,
|
|
10697
11183
|
editor,
|
|
11184
|
+
converters,
|
|
10698
11185
|
keyGenerator,
|
|
11186
|
+
readOnly,
|
|
10699
11187
|
schema,
|
|
10700
|
-
getSnapshot,
|
|
10701
11188
|
nativeEvent: void 0,
|
|
10702
11189
|
sendBack
|
|
10703
11190
|
});
|
|
@@ -10717,7 +11204,7 @@ function performEvent({
|
|
|
10717
11204
|
editor
|
|
10718
11205
|
}
|
|
10719
11206
|
});
|
|
10720
|
-
}), editor.onChange()) : nativeEventPrevented && nativeEvent?.preventDefault();
|
|
11207
|
+
}), mode === "send" && editor.onChange()) : nativeEventPrevented && (nativeEvent?.preventDefault(), mode === "send" && editor.onChange());
|
|
10721
11208
|
}
|
|
10722
11209
|
function sortByPriority(items) {
|
|
10723
11210
|
if (items.length === 0)
|
|
@@ -10762,31 +11249,6 @@ function sortByPriority(items) {
|
|
|
10762
11249
|
result.includes(item) || result.push(item);
|
|
10763
11250
|
return [...result, ...itemsWithoutPriority];
|
|
10764
11251
|
}
|
|
10765
|
-
function createEditorSnapshot({
|
|
10766
|
-
converters,
|
|
10767
|
-
editor,
|
|
10768
|
-
keyGenerator,
|
|
10769
|
-
readOnly,
|
|
10770
|
-
schema
|
|
10771
|
-
}) {
|
|
10772
|
-
const selection = editor.selection ? slateRangeToSelection({
|
|
10773
|
-
schema,
|
|
10774
|
-
editor,
|
|
10775
|
-
range: editor.selection
|
|
10776
|
-
}) : null, context = {
|
|
10777
|
-
converters,
|
|
10778
|
-
keyGenerator,
|
|
10779
|
-
readOnly,
|
|
10780
|
-
schema,
|
|
10781
|
-
selection,
|
|
10782
|
-
value: editor.value
|
|
10783
|
-
};
|
|
10784
|
-
return {
|
|
10785
|
-
blockIndexMap: editor.blockIndexMap,
|
|
10786
|
-
context,
|
|
10787
|
-
decoratorState: editor.decoratorState
|
|
10788
|
-
};
|
|
10789
|
-
}
|
|
10790
11252
|
function rerouteExternalBehaviorEvent({
|
|
10791
11253
|
event,
|
|
10792
11254
|
slateEditor
|
|
@@ -10937,16 +11399,11 @@ const editorMachine = setup({
|
|
|
10937
11399
|
abstractBehaviorIndex: context.abstractBehaviorIndex,
|
|
10938
11400
|
event: event.behaviorEvent,
|
|
10939
11401
|
editor: event.editor,
|
|
11402
|
+
converters: [...context.converters],
|
|
10940
11403
|
keyGenerator: context.keyGenerator,
|
|
10941
11404
|
schema: context.schema,
|
|
10942
|
-
|
|
10943
|
-
|
|
10944
|
-
editor: event.editor,
|
|
10945
|
-
keyGenerator: context.keyGenerator,
|
|
10946
|
-
readOnly: self.getSnapshot().matches({
|
|
10947
|
-
"edit mode": "read only"
|
|
10948
|
-
}),
|
|
10949
|
-
schema: context.schema
|
|
11405
|
+
readOnly: self.getSnapshot().matches({
|
|
11406
|
+
"edit mode": "read only"
|
|
10950
11407
|
}),
|
|
10951
11408
|
nativeEvent: event.nativeEvent,
|
|
10952
11409
|
sendBack: (eventSentBack) => {
|
|
@@ -13260,12 +13717,12 @@ const usePortableTextEditorSelection = () => {
|
|
|
13260
13717
|
const $ = c(5), editorActor = useContext(EditorActorContext);
|
|
13261
13718
|
let t0;
|
|
13262
13719
|
$[0] !== editorActor ? (t0 = editorActor.getSnapshot(), $[0] = editorActor, $[1] = t0) : t0 = $[1];
|
|
13263
|
-
const [selection,
|
|
13720
|
+
const [selection, setSelection2] = useState(t0.context.selection);
|
|
13264
13721
|
let t1, t2;
|
|
13265
13722
|
return $[2] !== editorActor ? (t1 = () => {
|
|
13266
13723
|
const subscription = editorActor.on("selection", (event) => {
|
|
13267
13724
|
startTransition(() => {
|
|
13268
|
-
|
|
13725
|
+
setSelection2(event.selection);
|
|
13269
13726
|
});
|
|
13270
13727
|
});
|
|
13271
13728
|
return () => {
|