@portabletext/editor 4.2.2 → 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 +24 -24
- package/lib/index.js +93 -93
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as _portabletext_schema6 from "@portabletext/schema";
|
|
2
2
|
import { AnnotationDefinition, AnnotationSchemaType, BaseDefinition, BlockObjectDefinition, BlockObjectSchemaType, DecoratorDefinition, DecoratorSchemaType, FieldDefinition, InlineObjectDefinition, InlineObjectSchemaType, ListDefinition, ListSchemaType, PortableTextBlock, PortableTextBlock as PortableTextBlock$1, PortableTextChild, PortableTextChild as PortableTextChild$1, PortableTextListBlock, PortableTextObject, PortableTextObject as PortableTextObject$1, PortableTextSpan, PortableTextSpan as PortableTextSpan$1, PortableTextTextBlock, PortableTextTextBlock as PortableTextTextBlock$1, Schema, SchemaDefinition, SchemaDefinition as SchemaDefinition$1, StyleDefinition, StyleSchemaType, TypedObject, defineSchema } from "@portabletext/schema";
|
|
3
3
|
import { BaseRange, Descendant, Operation, Range } from "slate";
|
|
4
|
-
import * as
|
|
4
|
+
import * as xstate75 from "xstate";
|
|
5
5
|
import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
|
|
6
|
-
import * as
|
|
6
|
+
import * as react8 from "react";
|
|
7
7
|
import React$1, { BaseSyntheticEvent, ClipboardEvent, Component, FocusEvent, JSX, MutableRefObject, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
|
|
8
8
|
import { Patch, Patch as Patch$1 } from "@portabletext/patches";
|
|
9
9
|
import { Observable, Subject } from "rxjs";
|
|
@@ -306,7 +306,7 @@ declare class PortableTextEditor extends Component<PortableTextEditorProps<Inter
|
|
|
306
306
|
componentDidUpdate(prevProps: PortableTextEditorProps): void;
|
|
307
307
|
componentWillUnmount(): void;
|
|
308
308
|
setEditable: (editable: EditableAPI) => void;
|
|
309
|
-
render():
|
|
309
|
+
render(): react8.JSX.Element;
|
|
310
310
|
/**
|
|
311
311
|
* @deprecated
|
|
312
312
|
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
@@ -715,7 +715,7 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
|
|
|
715
715
|
* ```
|
|
716
716
|
* @group Components
|
|
717
717
|
*/
|
|
718
|
-
declare const PortableTextEditable:
|
|
718
|
+
declare const PortableTextEditable: react8.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react8.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
|
|
719
719
|
/** @beta */
|
|
720
720
|
interface EditableAPIDeleteOptions {
|
|
721
721
|
mode?: 'blocks' | 'children' | 'selected';
|
|
@@ -1375,7 +1375,7 @@ type EditorActor = ActorRefFrom<typeof editorMachine>;
|
|
|
1375
1375
|
/**
|
|
1376
1376
|
* @internal
|
|
1377
1377
|
*/
|
|
1378
|
-
declare const editorMachine:
|
|
1378
|
+
declare const editorMachine: xstate75.StateMachine<{
|
|
1379
1379
|
behaviors: Set<BehaviorConfig>;
|
|
1380
1380
|
behaviorIndex: BehaviorIndex;
|
|
1381
1381
|
abstractBehaviorIndex: BehaviorIndex;
|
|
@@ -1439,46 +1439,46 @@ declare const editorMachine: xstate71.StateMachine<{
|
|
|
1439
1439
|
editor: PortableTextSlateEditor;
|
|
1440
1440
|
}, {}, never, {
|
|
1441
1441
|
type: "add behavior to context";
|
|
1442
|
-
params:
|
|
1442
|
+
params: xstate75.NonReducibleUnknown;
|
|
1443
1443
|
} | {
|
|
1444
1444
|
type: "remove behavior from context";
|
|
1445
|
-
params:
|
|
1445
|
+
params: xstate75.NonReducibleUnknown;
|
|
1446
1446
|
} | {
|
|
1447
1447
|
type: "add slate editor to context";
|
|
1448
|
-
params:
|
|
1448
|
+
params: xstate75.NonReducibleUnknown;
|
|
1449
1449
|
} | {
|
|
1450
1450
|
type: "emit patch event";
|
|
1451
|
-
params:
|
|
1451
|
+
params: xstate75.NonReducibleUnknown;
|
|
1452
1452
|
} | {
|
|
1453
1453
|
type: "emit mutation event";
|
|
1454
|
-
params:
|
|
1454
|
+
params: xstate75.NonReducibleUnknown;
|
|
1455
1455
|
} | {
|
|
1456
1456
|
type: "emit read only";
|
|
1457
|
-
params:
|
|
1457
|
+
params: xstate75.NonReducibleUnknown;
|
|
1458
1458
|
} | {
|
|
1459
1459
|
type: "emit editable";
|
|
1460
|
-
params:
|
|
1460
|
+
params: xstate75.NonReducibleUnknown;
|
|
1461
1461
|
} | {
|
|
1462
1462
|
type: "defer event";
|
|
1463
|
-
params:
|
|
1463
|
+
params: xstate75.NonReducibleUnknown;
|
|
1464
1464
|
} | {
|
|
1465
1465
|
type: "emit pending events";
|
|
1466
|
-
params:
|
|
1466
|
+
params: xstate75.NonReducibleUnknown;
|
|
1467
1467
|
} | {
|
|
1468
1468
|
type: "emit ready";
|
|
1469
|
-
params:
|
|
1469
|
+
params: xstate75.NonReducibleUnknown;
|
|
1470
1470
|
} | {
|
|
1471
1471
|
type: "clear pending events";
|
|
1472
|
-
params:
|
|
1472
|
+
params: xstate75.NonReducibleUnknown;
|
|
1473
1473
|
} | {
|
|
1474
1474
|
type: "defer incoming patches";
|
|
1475
|
-
params:
|
|
1475
|
+
params: xstate75.NonReducibleUnknown;
|
|
1476
1476
|
} | {
|
|
1477
1477
|
type: "emit pending incoming patches";
|
|
1478
|
-
params:
|
|
1478
|
+
params: xstate75.NonReducibleUnknown;
|
|
1479
1479
|
} | {
|
|
1480
1480
|
type: "clear pending incoming patches";
|
|
1481
|
-
params:
|
|
1481
|
+
params: xstate75.NonReducibleUnknown;
|
|
1482
1482
|
} | {
|
|
1483
1483
|
type: "handle blur";
|
|
1484
1484
|
params: unknown;
|
|
@@ -1490,7 +1490,7 @@ declare const editorMachine: xstate71.StateMachine<{
|
|
|
1490
1490
|
params: unknown;
|
|
1491
1491
|
} | {
|
|
1492
1492
|
type: "index behaviors";
|
|
1493
|
-
params:
|
|
1493
|
+
params: xstate75.NonReducibleUnknown;
|
|
1494
1494
|
}, {
|
|
1495
1495
|
type: "slate is busy";
|
|
1496
1496
|
params: unknown;
|
|
@@ -1520,9 +1520,9 @@ declare const editorMachine: xstate71.StateMachine<{
|
|
|
1520
1520
|
readOnly?: boolean;
|
|
1521
1521
|
schema: EditorSchema;
|
|
1522
1522
|
initialValue?: Array<PortableTextBlock>;
|
|
1523
|
-
},
|
|
1523
|
+
}, xstate75.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
1524
1524
|
type: "blurred";
|
|
1525
|
-
event:
|
|
1525
|
+
event: react8.FocusEvent<HTMLDivElement, Element>;
|
|
1526
1526
|
} | {
|
|
1527
1527
|
type: "done loading";
|
|
1528
1528
|
} | {
|
|
@@ -1534,7 +1534,7 @@ declare const editorMachine: xstate71.StateMachine<{
|
|
|
1534
1534
|
data: unknown;
|
|
1535
1535
|
} | {
|
|
1536
1536
|
type: "focused";
|
|
1537
|
-
event:
|
|
1537
|
+
event: react8.FocusEvent<HTMLDivElement, Element>;
|
|
1538
1538
|
} | {
|
|
1539
1539
|
type: "invalid value";
|
|
1540
1540
|
resolution: InvalidValueResolution | null;
|
|
@@ -1551,7 +1551,7 @@ declare const editorMachine: xstate71.StateMachine<{
|
|
|
1551
1551
|
} | {
|
|
1552
1552
|
type: "value changed";
|
|
1553
1553
|
value: Array<PortableTextBlock> | undefined;
|
|
1554
|
-
},
|
|
1554
|
+
}, xstate75.MetaObject, {
|
|
1555
1555
|
id: "editor";
|
|
1556
1556
|
states: {
|
|
1557
1557
|
readonly 'edit mode': {
|
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,
|
|
@@ -9667,69 +9667,69 @@ const addAnnotationOperationImplementation = ({
|
|
|
9667
9667
|
},
|
|
9668
9668
|
blockIndexMap: operation.editor.blockIndexMap
|
|
9669
9669
|
}) : operation.editor.selection;
|
|
9670
|
-
if (
|
|
9671
|
-
|
|
9672
|
-
|
|
9673
|
-
|
|
9674
|
-
|
|
9675
|
-
|
|
9676
|
-
|
|
9677
|
-
at: end,
|
|
9678
|
-
match: Text.isText,
|
|
9679
|
-
mode: "lowest",
|
|
9680
|
-
voids: !1,
|
|
9681
|
-
always: !endAtEndOfNode
|
|
9682
|
-
});
|
|
9683
|
-
const startAtStartOfNode = Editor.isStart(editor, start, start.path);
|
|
9684
|
-
if (Transforms.splitNodes(editor, {
|
|
9685
|
-
at: start,
|
|
9686
|
-
match: Text.isText,
|
|
9687
|
-
mode: "lowest",
|
|
9688
|
-
voids: !1,
|
|
9689
|
-
always: !startAtStartOfNode
|
|
9690
|
-
}), at = rangeRef.unref(), !at)
|
|
9691
|
-
throw new Error("Unable to add decorator without a selection");
|
|
9692
|
-
operation.at || Transforms.select(editor, at);
|
|
9693
|
-
const splitTextNodes = Editor.nodes(editor, {
|
|
9694
|
-
at,
|
|
9695
|
-
match: Text.isText
|
|
9696
|
-
});
|
|
9697
|
-
for (const [node, path] of splitTextNodes) {
|
|
9698
|
-
const marks = [...(Array.isArray(node.marks) ? node.marks : []).filter((eMark) => eMark !== mark), mark];
|
|
9699
|
-
Transforms.setNodes(editor, {
|
|
9700
|
-
marks
|
|
9701
|
-
}, {
|
|
9702
|
-
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,
|
|
9703
9677
|
match: Text.isText,
|
|
9704
|
-
|
|
9705
|
-
|
|
9678
|
+
mode: "lowest",
|
|
9679
|
+
voids: !1,
|
|
9680
|
+
always: !endAtEndOfNode
|
|
9706
9681
|
});
|
|
9707
|
-
|
|
9708
|
-
|
|
9709
|
-
|
|
9710
|
-
|
|
9711
|
-
|
|
9712
|
-
|
|
9713
|
-
|
|
9714
|
-
|
|
9715
|
-
|
|
9716
|
-
|
|
9717
|
-
|
|
9718
|
-
|
|
9719
|
-
|
|
9720
|
-
marks: existingMarks.length === existingMarksWithoutDecorator.length ? [...existingMarks, mark] : existingMarksWithoutDecorator
|
|
9721
|
-
}, {
|
|
9722
|
-
at: blockPath,
|
|
9723
|
-
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
|
|
9724
9695
|
});
|
|
9725
|
-
|
|
9726
|
-
|
|
9727
|
-
|
|
9728
|
-
|
|
9729
|
-
|
|
9730
|
-
|
|
9731
|
-
|
|
9732
|
-
|
|
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
|
+
}
|
|
9733
9733
|
}
|
|
9734
9734
|
}, decoratorRemoveOperationImplementation = ({
|
|
9735
9735
|
context,
|