@portabletext/editor 1.18.7 → 1.20.0
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/behavior.core.cjs +52 -35
- package/lib/_chunks-cjs/behavior.core.cjs.map +1 -1
- package/lib/_chunks-cjs/selector.is-selection-collapsed.cjs.map +1 -1
- package/lib/_chunks-es/behavior.core.js +52 -35
- package/lib/_chunks-es/behavior.core.js.map +1 -1
- package/lib/_chunks-es/selector.is-selection-collapsed.js.map +1 -1
- package/lib/behaviors/index.cjs +1 -0
- package/lib/behaviors/index.cjs.map +1 -1
- package/lib/behaviors/index.d.cts +78 -86
- package/lib/behaviors/index.d.ts +78 -86
- package/lib/behaviors/index.js +3 -2
- package/lib/behaviors/index.js.map +1 -1
- package/lib/index.cjs +277 -422
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +488 -1127
- package/lib/index.d.ts +488 -1127
- package/lib/index.js +279 -425
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +12 -9
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +12 -9
- package/lib/selectors/index.js.map +1 -1
- package/package.json +5 -7
- package/src/behavior-actions/behavior.actions.ts +28 -36
- package/src/behaviors/behavior.core.decorators.ts +36 -42
- package/src/behaviors/behavior.core.ts +4 -3
- package/src/behaviors/behavior.types.ts +40 -26
- package/src/behaviors/index.ts +1 -0
- package/src/editor/PortableTextEditor.tsx +14 -16
- package/src/editor/__tests__/self-solving.test.tsx +4 -11
- package/src/editor/components/Element.tsx +17 -23
- package/src/editor/create-editor.ts +18 -3
- package/src/editor/editor-machine.ts +67 -45
- package/src/editor/nodes/DefaultObject.tsx +2 -2
- package/src/editor/plugins/create-with-event-listeners.ts +44 -57
- package/src/editor/plugins/createWithHotKeys.ts +1 -11
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +12 -1
- package/src/editor/plugins/createWithPortableTextSelections.ts +1 -5
- package/src/editor/with-applying-behavior-actions.ts +15 -0
- package/src/selectors/selector.get-selected-spans.test.ts +122 -0
- package/src/selectors/selector.get-selected-spans.ts +3 -1
- package/src/selectors/selector.is-active-decorator.test.ts +65 -0
- package/src/editor/nodes/index.ts +0 -189
package/lib/index.js
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { Schema } from "@sanity/schema";
|
|
2
2
|
import { defineType, defineField, isKeySegment, isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, isPortableTextListBlock } from "@sanity/types";
|
|
3
3
|
import startCase from "lodash.startcase";
|
|
4
|
-
import { jsx, Fragment
|
|
4
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
5
5
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
6
6
|
import isEqual from "lodash/isEqual.js";
|
|
7
7
|
import noop from "lodash/noop.js";
|
|
8
8
|
import React, { useRef, useState, useEffect, useMemo, createContext, useContext, startTransition, Component, useCallback, forwardRef, useImperativeHandle } from "react";
|
|
9
9
|
import { Editor, Element as Element$1, Range, Point, Text, Path, Transforms, Operation, Node, createEditor as createEditor$1, deleteBackward, deleteForward, insertText } from "slate";
|
|
10
10
|
import { useSlateStatic, ReactEditor, useSelected, withReact, Slate, useSlate, Editable } from "slate-react";
|
|
11
|
-
import debug$
|
|
11
|
+
import debug$k from "debug";
|
|
12
12
|
import { c } from "react-compiler-runtime";
|
|
13
|
-
import { styled } from "styled-components";
|
|
14
13
|
import uniq from "lodash/uniq.js";
|
|
15
14
|
import { Subject } from "rxjs";
|
|
16
15
|
import { useEffectEvent } from "use-effect-event";
|
|
@@ -140,10 +139,10 @@ function compileSchemaDefinition(definition) {
|
|
|
140
139
|
};
|
|
141
140
|
}
|
|
142
141
|
const rootName = "sanity-pte:";
|
|
143
|
-
debug$
|
|
142
|
+
debug$k(rootName);
|
|
144
143
|
function debugWithName(name) {
|
|
145
144
|
const namespace = `${rootName}${name}`;
|
|
146
|
-
return debug$
|
|
145
|
+
return debug$k && debug$k.enabled(namespace) ? debug$k(namespace) : debug$k(rootName);
|
|
147
146
|
}
|
|
148
147
|
function createKeyedPath(point, value, types) {
|
|
149
148
|
const blockPath = [point.path[0]];
|
|
@@ -214,7 +213,7 @@ function toSlateRange(selection, editor) {
|
|
|
214
213
|
path: toSlatePath(selection.focus.path, editor),
|
|
215
214
|
offset: selection.focus.offset
|
|
216
215
|
};
|
|
217
|
-
return focus.path.length === 0 || anchor.path.length === 0 ? null :
|
|
216
|
+
return focus.path.length === 0 || anchor.path.length === 0 ? null : focus ? {
|
|
218
217
|
anchor,
|
|
219
218
|
focus
|
|
220
219
|
} : null;
|
|
@@ -377,172 +376,20 @@ function isEqualToEmptyEditor(children, schemaTypes) {
|
|
|
377
376
|
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), IS_DRAGGING = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_ELEMENT = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_ELEMENT_TARGET = /* @__PURE__ */ new WeakMap(), IS_DRAGGING_BLOCK_TARGET_POSITION = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), DefaultObject = (props) => {
|
|
378
377
|
const $ = c(4);
|
|
379
378
|
let t0;
|
|
380
|
-
$[0]
|
|
379
|
+
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = {
|
|
380
|
+
userSelect: "none"
|
|
381
|
+
}, $[0] = t0) : t0 = $[0];
|
|
381
382
|
let t1;
|
|
382
|
-
return $[2] !==
|
|
383
|
+
return $[1] !== props.value._key || $[2] !== props.value._type ? (t1 = /* @__PURE__ */ jsxs("div", { style: t0, children: [
|
|
384
|
+
"[",
|
|
385
|
+
props.value._type,
|
|
386
|
+
": ",
|
|
387
|
+
props.value._key,
|
|
388
|
+
"]"
|
|
389
|
+
] }), $[1] = props.value._key, $[2] = props.value._type, $[3] = t1) : t1 = $[3], t1;
|
|
383
390
|
};
|
|
384
391
|
DefaultObject.displayName = "DefaultObject";
|
|
385
|
-
const
|
|
386
|
-
user-select: none;
|
|
387
|
-
border: ${(props) => props.selected ? "1px solid blue" : "1px solid transparent"};
|
|
388
|
-
`;
|
|
389
|
-
styled.span`
|
|
390
|
-
background: #999;
|
|
391
|
-
border: ${(props) => props.selected ? "1px solid blue" : "1px solid transparent"};
|
|
392
|
-
`;
|
|
393
|
-
const DefaultListItem = styled.div`
|
|
394
|
-
&.pt-list-item {
|
|
395
|
-
width: fit-content;
|
|
396
|
-
position: relative;
|
|
397
|
-
display: block;
|
|
398
|
-
|
|
399
|
-
/* Important 'transform' in order to force refresh the ::before and ::after rules
|
|
400
|
-
in Webkit: https://stackoverflow.com/a/21947628/831480
|
|
401
|
-
*/
|
|
402
|
-
transform: translateZ(0);
|
|
403
|
-
margin-left: ${(props) => getLeftPositionForListLevel(props.listLevel)};
|
|
404
|
-
}
|
|
405
|
-
&.pt-list-item > .pt-list-item-inner {
|
|
406
|
-
display: flex;
|
|
407
|
-
margin: 0;
|
|
408
|
-
padding: 0;
|
|
409
|
-
&:before {
|
|
410
|
-
justify-content: flex-start;
|
|
411
|
-
vertical-align: top;
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
&.pt-list-item-bullet > .pt-list-item-inner:before {
|
|
415
|
-
content: '${(props) => getContentForListLevelAndStyle(props.listLevel, props.listStyle)}';
|
|
416
|
-
font-size: 0.4375rem; /* 7px */
|
|
417
|
-
line-height: 1.5rem; /* Same as body text */
|
|
418
|
-
/* Optical alignment */
|
|
419
|
-
position: relative;
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
&.pt-list-item-bullet > .pt-list-item-inner {
|
|
423
|
-
&:before {
|
|
424
|
-
min-width: 1.5rem; /* Make sure space between bullet and text never shrinks */
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
&.pt-list-item-number {
|
|
428
|
-
counter-increment: ${(props) => getCounterIncrementForListLevel(props.listLevel)};
|
|
429
|
-
counter-reset: ${(props) => getCounterResetForListLevel(props.listLevel)};
|
|
430
|
-
}
|
|
431
|
-
& + :not(.pt-list-item-number) {
|
|
432
|
-
counter-reset: listItemNumber;
|
|
433
|
-
}
|
|
434
|
-
&.pt-list-item-number > .pt-list-item-inner:before {
|
|
435
|
-
content: ${(props) => getCounterContentForListLevel(props.listLevel)};
|
|
436
|
-
min-width: 1.5rem; /* Make sure space between number and text never shrinks */
|
|
437
|
-
/* Optical alignment */
|
|
438
|
-
position: relative;
|
|
439
|
-
top: 1px;
|
|
440
|
-
}
|
|
441
|
-
`, DefaultListItemInner = styled.div``;
|
|
442
|
-
function getLeftPositionForListLevel(level) {
|
|
443
|
-
switch (Number(level)) {
|
|
444
|
-
case 1:
|
|
445
|
-
return "1.5em";
|
|
446
|
-
case 2:
|
|
447
|
-
return "3em";
|
|
448
|
-
case 3:
|
|
449
|
-
return "4.5em";
|
|
450
|
-
case 4:
|
|
451
|
-
return "6em";
|
|
452
|
-
case 5:
|
|
453
|
-
return "7.5em";
|
|
454
|
-
case 6:
|
|
455
|
-
return "9em";
|
|
456
|
-
case 7:
|
|
457
|
-
return "10.5em";
|
|
458
|
-
case 8:
|
|
459
|
-
return "12em";
|
|
460
|
-
case 9:
|
|
461
|
-
return "13.5em";
|
|
462
|
-
case 10:
|
|
463
|
-
return "15em";
|
|
464
|
-
default:
|
|
465
|
-
return "0em";
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
const bullets = ["\u25CF", "\u25CB", "\u25A0"];
|
|
469
|
-
function getContentForListLevelAndStyle(level, style) {
|
|
470
|
-
const normalizedLevel = (level - 1) % 3;
|
|
471
|
-
return style === "bullet" ? bullets[normalizedLevel] : "*";
|
|
472
|
-
}
|
|
473
|
-
function getCounterIncrementForListLevel(level) {
|
|
474
|
-
switch (level) {
|
|
475
|
-
case 1:
|
|
476
|
-
return "listItemNumber";
|
|
477
|
-
case 2:
|
|
478
|
-
return "listItemAlpha";
|
|
479
|
-
case 3:
|
|
480
|
-
return "listItemRoman";
|
|
481
|
-
case 4:
|
|
482
|
-
return "listItemNumberNext";
|
|
483
|
-
case 5:
|
|
484
|
-
return "listItemLetterNext";
|
|
485
|
-
case 6:
|
|
486
|
-
return "listItemRomanNext";
|
|
487
|
-
case 7:
|
|
488
|
-
return "listItemNumberNextNext";
|
|
489
|
-
case 8:
|
|
490
|
-
return "listItemAlphaNextNext";
|
|
491
|
-
case 9:
|
|
492
|
-
return "listItemRomanNextNext";
|
|
493
|
-
default:
|
|
494
|
-
return "listItemNumberNextNextNext";
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
function getCounterResetForListLevel(level) {
|
|
498
|
-
switch (level) {
|
|
499
|
-
case 1:
|
|
500
|
-
return "listItemAlpha";
|
|
501
|
-
case 2:
|
|
502
|
-
return "listItemRoman";
|
|
503
|
-
case 3:
|
|
504
|
-
return "listItemNumberNext";
|
|
505
|
-
case 4:
|
|
506
|
-
return "listItemLetterNext";
|
|
507
|
-
case 5:
|
|
508
|
-
return "listItemRomanNext";
|
|
509
|
-
case 6:
|
|
510
|
-
return "listItemNumberNextNext";
|
|
511
|
-
case 7:
|
|
512
|
-
return "listItemAlphaNextNext";
|
|
513
|
-
case 8:
|
|
514
|
-
return "listItemRomanNextNext";
|
|
515
|
-
case 9:
|
|
516
|
-
return "listItemNumberNextNextNext";
|
|
517
|
-
default:
|
|
518
|
-
return "listItemNumberNextNextNext";
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
function getCounterContentForListLevel(level) {
|
|
522
|
-
switch (level) {
|
|
523
|
-
case 1:
|
|
524
|
-
return "counter(listItemNumber) '. '";
|
|
525
|
-
case 2:
|
|
526
|
-
return "counter(listItemAlpha, lower-alpha) '. '";
|
|
527
|
-
case 3:
|
|
528
|
-
return "counter(listItemRoman, lower-roman) '. '";
|
|
529
|
-
case 4:
|
|
530
|
-
return "counter(listItemNumberNext) '. '";
|
|
531
|
-
case 5:
|
|
532
|
-
return "counter(listItemLetterNext, lower-alpha) '. '";
|
|
533
|
-
case 6:
|
|
534
|
-
return "counter(listItemRomanNext, lower-roman) '. '";
|
|
535
|
-
case 7:
|
|
536
|
-
return "counter(listItemNumberNextNext) '. '";
|
|
537
|
-
case 8:
|
|
538
|
-
return "counter(listItemAlphaNextNext, lower-alpha) '. '";
|
|
539
|
-
case 9:
|
|
540
|
-
return "counter(listItemRomanNextNext, lower-roman) '. '";
|
|
541
|
-
default:
|
|
542
|
-
return "counter(listItemNumberNextNextNext) '. '";
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0) => {
|
|
392
|
+
const debug$j = debugWithName("components:DraggableBlock"), DraggableBlock = (t0) => {
|
|
546
393
|
const $ = c(51), {
|
|
547
394
|
children,
|
|
548
395
|
element,
|
|
@@ -580,39 +427,39 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
580
427
|
$[16] !== editor || $[17] !== element ? (t9 = (event_0) => {
|
|
581
428
|
const targetBlock = IS_DRAGGING_ELEMENT_TARGET.get(editor);
|
|
582
429
|
if (targetBlock) {
|
|
583
|
-
IS_DRAGGING.set(editor, !1), event_0.preventDefault(), event_0.stopPropagation(), IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$
|
|
430
|
+
IS_DRAGGING.set(editor, !1), event_0.preventDefault(), event_0.stopPropagation(), IS_DRAGGING_ELEMENT_TARGET.delete(editor), dragGhostRef.current && (debug$j("Removing drag ghost"), document.body.removeChild(dragGhostRef.current));
|
|
584
431
|
const dragPosition = IS_DRAGGING_BLOCK_TARGET_POSITION.get(editor);
|
|
585
432
|
IS_DRAGGING_BLOCK_TARGET_POSITION.delete(editor);
|
|
586
433
|
let targetPath = ReactEditor.findPath(editor, targetBlock);
|
|
587
434
|
const myPath = ReactEditor.findPath(editor, element), isBefore = Path.isBefore(myPath, targetPath);
|
|
588
435
|
if (dragPosition === "bottom" && !isBefore) {
|
|
589
436
|
if (targetPath[0] >= editor.children.length - 1) {
|
|
590
|
-
debug$
|
|
437
|
+
debug$j("target is already at the bottom, not moving");
|
|
591
438
|
return;
|
|
592
439
|
}
|
|
593
440
|
const originalPath = targetPath;
|
|
594
|
-
targetPath = Path.next(targetPath), debug$
|
|
441
|
+
targetPath = Path.next(targetPath), debug$j(`Adjusting targetPath from ${JSON.stringify(originalPath)} to ${JSON.stringify(targetPath)}`);
|
|
595
442
|
}
|
|
596
443
|
if (dragPosition === "top" && isBefore && targetPath[0] !== editor.children.length - 1) {
|
|
597
444
|
const originalPath_0 = targetPath;
|
|
598
|
-
targetPath = Path.previous(targetPath), debug$
|
|
445
|
+
targetPath = Path.previous(targetPath), debug$j(`Adjusting targetPath from ${JSON.stringify(originalPath_0)} to ${JSON.stringify(targetPath)}`);
|
|
599
446
|
}
|
|
600
447
|
if (Path.equals(targetPath, myPath)) {
|
|
601
|
-
event_0.preventDefault(), debug$
|
|
448
|
+
event_0.preventDefault(), debug$j("targetPath and myPath is the same, not moving");
|
|
602
449
|
return;
|
|
603
450
|
}
|
|
604
|
-
debug$
|
|
451
|
+
debug$j(`Moving element ${element._key} from path ${JSON.stringify(myPath)} to ${JSON.stringify(targetPath)} (${dragPosition})`), Transforms.moveNodes(editor, {
|
|
605
452
|
at: myPath,
|
|
606
453
|
to: targetPath
|
|
607
454
|
}), editor.onChange();
|
|
608
455
|
return;
|
|
609
456
|
}
|
|
610
|
-
debug$
|
|
457
|
+
debug$j("No target element, not doing anything");
|
|
611
458
|
}, $[16] = editor, $[17] = element, $[18] = t9) : t9 = $[18];
|
|
612
459
|
const handleDragEnd = t9;
|
|
613
460
|
let t10;
|
|
614
461
|
$[19] !== editor || $[20] !== element ? (t10 = (event_1) => {
|
|
615
|
-
IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$
|
|
462
|
+
IS_DRAGGING_BLOCK_ELEMENT.get(editor) && (debug$j("On drop (prevented)", element), event_1.preventDefault(), event_1.stopPropagation(), setIsDragOver(!1));
|
|
616
463
|
}, $[19] = editor, $[20] = element, $[21] = t10) : t10 = $[21];
|
|
617
464
|
const handleDrop = t10;
|
|
618
465
|
let t11;
|
|
@@ -629,10 +476,10 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
629
476
|
let t12;
|
|
630
477
|
$[26] !== blockElement || $[27] !== editor || $[28] !== handleDrag || $[29] !== isInline || $[30] !== isVoid ? (t12 = (event_3) => {
|
|
631
478
|
if (!isVoid || isInline) {
|
|
632
|
-
debug$
|
|
479
|
+
debug$j("Not dragging block"), IS_DRAGGING_BLOCK_ELEMENT.delete(editor), IS_DRAGGING.set(editor, !1);
|
|
633
480
|
return;
|
|
634
481
|
}
|
|
635
|
-
if (debug$
|
|
482
|
+
if (debug$j("Drag start"), IS_DRAGGING.set(editor, !0), event_3.dataTransfer && (event_3.dataTransfer.setData("application/portable-text", "something"), event_3.dataTransfer.effectAllowed = "move"), blockElement && blockElement instanceof HTMLElement) {
|
|
636
483
|
let dragGhost = blockElement.cloneNode(!0);
|
|
637
484
|
const customGhost = dragGhost.querySelector("[data-pt-drag-ghost-element]");
|
|
638
485
|
if (customGhost && (dragGhost = customGhost), dragGhost.setAttribute("data-dragged", ""), document.body) {
|
|
@@ -747,7 +594,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
747
594
|
let level;
|
|
748
595
|
if (isListItem && (typeof element.level == "number" && (level = element.level), className += ` pt-list-item pt-list-item-${element.listItem} pt-list-item-level-${level || 1}`), editor.isListBlock(value) && isListItem && element.listItem) {
|
|
749
596
|
const listType = schemaTypes.lists.find((item_0) => item_0.value === element.listItem);
|
|
750
|
-
renderListItem && listType
|
|
597
|
+
renderListItem && listType && (renderedBlock = renderListItem({
|
|
751
598
|
block: value,
|
|
752
599
|
children: renderedBlock,
|
|
753
600
|
focused,
|
|
@@ -757,7 +604,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
757
604
|
schemaType: listType,
|
|
758
605
|
level: value.level || 1,
|
|
759
606
|
editorElementRef: blockRef
|
|
760
|
-
})
|
|
607
|
+
}));
|
|
761
608
|
}
|
|
762
609
|
const renderProps = Object.defineProperty({
|
|
763
610
|
children: renderedBlock,
|
|
@@ -803,10 +650,7 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
803
650
|
}
|
|
804
651
|
return /* @__PURE__ */ jsxs("div", { ...attributes, className, children: [
|
|
805
652
|
children,
|
|
806
|
-
/* @__PURE__ */
|
|
807
|
-
renderedBlockFromProps && /* @__PURE__ */ jsx("div", { ref: blockRef, contentEditable: !1, children: renderedBlockFromProps }),
|
|
808
|
-
!renderedBlockFromProps && /* @__PURE__ */ jsx(DefaultBlockObject, { selected, children: /* @__PURE__ */ jsx(DefaultObject, { value }) })
|
|
809
|
-
] })
|
|
653
|
+
/* @__PURE__ */ jsx(DraggableBlock, { element, readOnly, blockRef, children: /* @__PURE__ */ jsx("div", { ref: blockRef, contentEditable: !1, children: renderedBlockFromProps || /* @__PURE__ */ jsx(DefaultObject, { value }) }) })
|
|
810
654
|
] }, element._key);
|
|
811
655
|
};
|
|
812
656
|
Element.displayName = "Element";
|
|
@@ -1907,7 +1751,7 @@ function isRedoing(editor) {
|
|
|
1907
1751
|
function setIsRedoing(editor, isRedoing2) {
|
|
1908
1752
|
IS_REDOING.set(editor, isRedoing2);
|
|
1909
1753
|
}
|
|
1910
|
-
const debug$
|
|
1754
|
+
const debug$i = debugWithName("plugin:withUndoRedo"), SAVING = /* @__PURE__ */ new WeakMap(), REMOTE_PATCHES = /* @__PURE__ */ new WeakMap(), UNDO_STEP_LIMIT = 1e3, isSaving = (editor) => {
|
|
1911
1755
|
const state = SAVING.get(editor);
|
|
1912
1756
|
return state === void 0 ? !0 : state;
|
|
1913
1757
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
@@ -1920,7 +1764,7 @@ function createWithUndoRedo(options) {
|
|
|
1920
1764
|
let previousSnapshot = fromSlateValue(editor.children, blockSchemaType.name);
|
|
1921
1765
|
const remotePatches = getRemotePatches(editor);
|
|
1922
1766
|
options.subscriptions.push(() => {
|
|
1923
|
-
debug$
|
|
1767
|
+
debug$i("Subscribing to patches");
|
|
1924
1768
|
const sub = editorActor.on("patches", ({
|
|
1925
1769
|
patches,
|
|
1926
1770
|
snapshot
|
|
@@ -1929,7 +1773,7 @@ function createWithUndoRedo(options) {
|
|
|
1929
1773
|
patches.forEach((patch) => {
|
|
1930
1774
|
if (!reset && patch.origin !== "local" && remotePatches) {
|
|
1931
1775
|
if (patch.type === "unset" && patch.path.length === 0) {
|
|
1932
|
-
debug$
|
|
1776
|
+
debug$i("Someone else cleared the content, resetting undo/redo history"), editor.history = {
|
|
1933
1777
|
undos: [],
|
|
1934
1778
|
redos: []
|
|
1935
1779
|
}, remotePatches.splice(0, remotePatches.length), SAVING.set(editor, !0), reset = !0;
|
|
@@ -1945,7 +1789,7 @@ function createWithUndoRedo(options) {
|
|
|
1945
1789
|
}), previousSnapshot = snapshot;
|
|
1946
1790
|
});
|
|
1947
1791
|
return () => {
|
|
1948
|
-
debug$
|
|
1792
|
+
debug$i("Unsubscribing to patches"), sub.unsubscribe();
|
|
1949
1793
|
};
|
|
1950
1794
|
}), editor.history = {
|
|
1951
1795
|
undos: [],
|
|
@@ -1984,7 +1828,7 @@ function createWithUndoRedo(options) {
|
|
|
1984
1828
|
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
1985
1829
|
timestamp: /* @__PURE__ */ new Date()
|
|
1986
1830
|
};
|
|
1987
|
-
undos.push(newStep), debug$
|
|
1831
|
+
undos.push(newStep), debug$i("Created new undo step", step);
|
|
1988
1832
|
}
|
|
1989
1833
|
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
1990
1834
|
undos.shift();
|
|
@@ -2001,7 +1845,7 @@ function createWithUndoRedo(options) {
|
|
|
2001
1845
|
} = editor.history;
|
|
2002
1846
|
if (undos.length > 0) {
|
|
2003
1847
|
const step = undos[undos.length - 1];
|
|
2004
|
-
if (debug$
|
|
1848
|
+
if (debug$i("Undoing", step), step.operations.length > 0) {
|
|
2005
1849
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2006
1850
|
let transformedOperations = step.operations;
|
|
2007
1851
|
otherPatches.forEach((item) => {
|
|
@@ -2019,7 +1863,7 @@ function createWithUndoRedo(options) {
|
|
|
2019
1863
|
});
|
|
2020
1864
|
}), editor.normalize(), editor.onChange();
|
|
2021
1865
|
} catch (err) {
|
|
2022
|
-
debug$
|
|
1866
|
+
debug$i("Could not perform undo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
2023
1867
|
undos: [],
|
|
2024
1868
|
redos: []
|
|
2025
1869
|
}, SAVING.set(editor, !0), setIsUndoing(editor, !1), editor.onChange();
|
|
@@ -2038,7 +1882,7 @@ function createWithUndoRedo(options) {
|
|
|
2038
1882
|
} = editor.history;
|
|
2039
1883
|
if (redos.length > 0) {
|
|
2040
1884
|
const step = redos[redos.length - 1];
|
|
2041
|
-
if (debug$
|
|
1885
|
+
if (debug$i("Redoing", step), step.operations.length > 0) {
|
|
2042
1886
|
const otherPatches = remotePatches.filter((item) => item.time >= step.timestamp);
|
|
2043
1887
|
let transformedOperations = step.operations;
|
|
2044
1888
|
otherPatches.forEach((item) => {
|
|
@@ -2055,7 +1899,7 @@ function createWithUndoRedo(options) {
|
|
|
2055
1899
|
});
|
|
2056
1900
|
}), editor.normalize(), editor.onChange();
|
|
2057
1901
|
} catch (err) {
|
|
2058
|
-
debug$
|
|
1902
|
+
debug$i("Could not perform redo step", err), remotePatches.splice(0, remotePatches.length), Transforms.deselect(editor), editor.history = {
|
|
2059
1903
|
undos: [],
|
|
2060
1904
|
redos: []
|
|
2061
1905
|
}, SAVING.set(editor, !0), setIsRedoing(editor, !1), editor.onChange();
|
|
@@ -2068,7 +1912,6 @@ function createWithUndoRedo(options) {
|
|
|
2068
1912
|
};
|
|
2069
1913
|
}
|
|
2070
1914
|
function transformOperation(editor, patch, operation, snapshot, previousSnapshot) {
|
|
2071
|
-
debugVerbose$3 && (debug$j(`Adjusting '${operation.type}' operation paths for '${patch.type}' patch`), debug$j(`Operation ${JSON.stringify(operation)}`), debug$j(`Patch ${JSON.stringify(patch)}`));
|
|
2072
1915
|
const transformedOperation = {
|
|
2073
1916
|
...operation
|
|
2074
1917
|
};
|
|
@@ -2076,16 +1919,16 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2076
1919
|
const insertBlockIndex = (snapshot || []).findIndex((blk) => isEqual({
|
|
2077
1920
|
_key: blk._key
|
|
2078
1921
|
}, patch.path[0]));
|
|
2079
|
-
return debug$
|
|
1922
|
+
return debug$i(`Adjusting block path (+${patch.items.length}) for '${transformedOperation.type}' operation and patch '${patch.type}'`), [adjustBlockPath(transformedOperation, patch.items.length, insertBlockIndex)];
|
|
2080
1923
|
}
|
|
2081
1924
|
if (patch.type === "unset" && patch.path.length === 1) {
|
|
2082
1925
|
const unsetBlockIndex = (previousSnapshot || []).findIndex((blk) => isEqual({
|
|
2083
1926
|
_key: blk._key
|
|
2084
1927
|
}, patch.path[0]));
|
|
2085
|
-
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$
|
|
1928
|
+
return "path" in transformedOperation && Array.isArray(transformedOperation.path) && transformedOperation.path[0] === unsetBlockIndex ? (debug$i("Skipping transformation that targeted removed block"), []) : [adjustBlockPath(transformedOperation, -1, unsetBlockIndex)];
|
|
2086
1929
|
}
|
|
2087
1930
|
if (patch.type === "unset" && patch.path.length === 0)
|
|
2088
|
-
return debug$
|
|
1931
|
+
return debug$i(`Adjusting selection for unset everything patch and ${operation.type} operation`), [];
|
|
2089
1932
|
if (patch.type === "diffMatchPatch") {
|
|
2090
1933
|
const operationTargetBlock = findOperationTargetBlock(editor, transformedOperation);
|
|
2091
1934
|
return !operationTargetBlock || !isEqual({
|
|
@@ -2365,7 +2208,7 @@ const syncValueCallback = ({
|
|
|
2365
2208
|
}
|
|
2366
2209
|
}
|
|
2367
2210
|
}
|
|
2368
|
-
}), debug$
|
|
2211
|
+
}), debug$h = debugWithName("hook:useSyncValue");
|
|
2369
2212
|
async function updateValue({
|
|
2370
2213
|
context,
|
|
2371
2214
|
sendBack,
|
|
@@ -2375,7 +2218,7 @@ async function updateValue({
|
|
|
2375
2218
|
}) {
|
|
2376
2219
|
let isChanged = !1, isValid = !0;
|
|
2377
2220
|
const hadSelection = !!slateEditor.selection;
|
|
2378
|
-
if ((!value || value.length === 0) && (debug$
|
|
2221
|
+
if ((!value || value.length === 0) && (debug$h("Value is empty"), Editor.withoutNormalizing(slateEditor, () => {
|
|
2379
2222
|
withoutSaving(slateEditor, () => {
|
|
2380
2223
|
withoutPatching(slateEditor, () => {
|
|
2381
2224
|
hadSelection && Transforms.deselect(slateEditor);
|
|
@@ -2431,14 +2274,14 @@ async function updateValue({
|
|
|
2431
2274
|
});
|
|
2432
2275
|
}
|
|
2433
2276
|
if (!isValid) {
|
|
2434
|
-
debug$
|
|
2277
|
+
debug$h("Invalid value, returning"), sendBack({
|
|
2435
2278
|
type: "done syncing",
|
|
2436
2279
|
value
|
|
2437
2280
|
});
|
|
2438
2281
|
return;
|
|
2439
2282
|
}
|
|
2440
2283
|
if (isChanged) {
|
|
2441
|
-
debug$
|
|
2284
|
+
debug$h("Server value changed, syncing editor");
|
|
2442
2285
|
try {
|
|
2443
2286
|
slateEditor.onChange();
|
|
2444
2287
|
} catch (err) {
|
|
@@ -2466,7 +2309,7 @@ async function updateValue({
|
|
|
2466
2309
|
value
|
|
2467
2310
|
});
|
|
2468
2311
|
} else
|
|
2469
|
-
debug$
|
|
2312
|
+
debug$h("Server value and editor value is equal, no need to sync.");
|
|
2470
2313
|
sendBack({
|
|
2471
2314
|
type: "done syncing",
|
|
2472
2315
|
value
|
|
@@ -2500,7 +2343,7 @@ function syncBlock({
|
|
|
2500
2343
|
type: "patch",
|
|
2501
2344
|
patch
|
|
2502
2345
|
});
|
|
2503
|
-
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$
|
|
2346
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === currentBlock._key ? (debug$h.enabled && debug$h("Updating block", oldBlock, currentBlock), _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex)) : (debug$h.enabled && debug$h("Replacing block", oldBlock, currentBlock), _replaceBlock(slateEditor, currentBlock, currentBlockIndex)), blockChanged = !0) : (sendBack({
|
|
2504
2347
|
type: "invalid value",
|
|
2505
2348
|
resolution: validation.resolution,
|
|
2506
2349
|
value
|
|
@@ -2508,9 +2351,9 @@ function syncBlock({
|
|
|
2508
2351
|
}
|
|
2509
2352
|
if (!oldBlock && blockValid) {
|
|
2510
2353
|
const validationValue = [value[currentBlockIndex]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
2511
|
-
debug$
|
|
2354
|
+
debug$h.enabled && debug$h("Validating and inserting new block in the end of the value", currentBlock), validation.valid || validation.resolution?.autoResolve ? Transforms.insertNodes(slateEditor, currentBlock, {
|
|
2512
2355
|
at: [currentBlockIndex]
|
|
2513
|
-
}) : (debug$
|
|
2356
|
+
}) : (debug$h("Invalid", validation), sendBack({
|
|
2514
2357
|
type: "invalid value",
|
|
2515
2358
|
resolution: validation.resolution,
|
|
2516
2359
|
value
|
|
@@ -2538,14 +2381,14 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2538
2381
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
2539
2382
|
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
|
|
2540
2383
|
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
2541
|
-
childIndex > 0 && (debug$
|
|
2384
|
+
childIndex > 0 && (debug$h("Removing child"), Transforms.removeNodes(slateEditor, {
|
|
2542
2385
|
at: [currentBlockIndex, childIndex]
|
|
2543
2386
|
}));
|
|
2544
2387
|
}), currentBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
2545
2388
|
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [currentBlockIndex, currentBlockChildIndex];
|
|
2546
2389
|
if (isChildChanged)
|
|
2547
2390
|
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
2548
|
-
debug$
|
|
2391
|
+
debug$h("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
2549
2392
|
at: path
|
|
2550
2393
|
});
|
|
2551
2394
|
const isSpanNode = Text.isText(currentBlockChild) && currentBlockChild._type === "span" && Text.isText(oldBlockChild) && oldBlockChild._type === "span";
|
|
@@ -2562,23 +2405,23 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2562
2405
|
}
|
|
2563
2406
|
}), Transforms.insertText(slateEditor, currentBlockChild.text, {
|
|
2564
2407
|
at: path
|
|
2565
|
-
}), slateEditor.onChange()) : isSpanNode || (debug$
|
|
2408
|
+
}), slateEditor.onChange()) : isSpanNode || (debug$h("Updating changed inline object child", currentBlockChild), Transforms.setNodes(slateEditor, {
|
|
2566
2409
|
_key: VOID_CHILD_KEY
|
|
2567
2410
|
}, {
|
|
2568
2411
|
at: [...path, 0],
|
|
2569
2412
|
voids: !0
|
|
2570
2413
|
}));
|
|
2571
|
-
} else oldBlockChild ? (debug$
|
|
2414
|
+
} else oldBlockChild ? (debug$h("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
|
|
2572
2415
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2573
2416
|
}), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
2574
2417
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2575
|
-
}), slateEditor.onChange()) : oldBlockChild || (debug$
|
|
2418
|
+
}), slateEditor.onChange()) : oldBlockChild || (debug$h("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
2576
2419
|
at: [currentBlockIndex, currentBlockChildIndex]
|
|
2577
2420
|
}), slateEditor.onChange());
|
|
2578
2421
|
});
|
|
2579
2422
|
}
|
|
2580
2423
|
}
|
|
2581
|
-
const debug$
|
|
2424
|
+
const debug$g = debugWithName("component:PortableTextEditor:Synchronizer");
|
|
2582
2425
|
function Synchronizer(props) {
|
|
2583
2426
|
const $ = c(40), {
|
|
2584
2427
|
editorActor,
|
|
@@ -2649,19 +2492,19 @@ function Synchronizer(props) {
|
|
|
2649
2492
|
}, t12 = [syncActorRef, readOnly], $[25] = readOnly, $[26] = syncActorRef, $[27] = t11, $[28] = t12) : (t11 = $[27], t12 = $[28]), useEffect(t11, t12);
|
|
2650
2493
|
let t13, t14;
|
|
2651
2494
|
$[29] !== syncActorRef || $[30] !== value ? (t13 = () => {
|
|
2652
|
-
debug$
|
|
2495
|
+
debug$g("Value from props changed, syncing new value"), syncActorRef.send({
|
|
2653
2496
|
type: "update value",
|
|
2654
2497
|
value
|
|
2655
2498
|
});
|
|
2656
2499
|
}, t14 = [syncActorRef, value], $[29] = syncActorRef, $[30] = value, $[31] = t13, $[32] = t14) : (t13 = $[31], t14 = $[32]), useEffect(t13, t14);
|
|
2657
2500
|
let t15;
|
|
2658
2501
|
$[33] !== editorActor || $[34] !== mutationActorRef ? (t15 = () => {
|
|
2659
|
-
debug$
|
|
2502
|
+
debug$g("Subscribing to patch events");
|
|
2660
2503
|
const sub = editorActor.on("patch", (event_1) => {
|
|
2661
2504
|
mutationActorRef.send(event_1);
|
|
2662
2505
|
});
|
|
2663
2506
|
return () => {
|
|
2664
|
-
debug$
|
|
2507
|
+
debug$g("Unsubscribing to patch events"), sub.unsubscribe();
|
|
2665
2508
|
};
|
|
2666
2509
|
}, $[33] = editorActor, $[34] = mutationActorRef, $[35] = t15) : t15 = $[35];
|
|
2667
2510
|
let t16;
|
|
@@ -2676,11 +2519,11 @@ function _temp(s) {
|
|
|
2676
2519
|
return s.context.value;
|
|
2677
2520
|
}
|
|
2678
2521
|
Synchronizer.displayName = "Synchronizer";
|
|
2679
|
-
const debug$
|
|
2522
|
+
const debug$f = debugWithName("operationToPatches");
|
|
2680
2523
|
function createOperationToPatches(types) {
|
|
2681
2524
|
const textBlockName = types.block.name;
|
|
2682
2525
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
2683
|
-
debug$
|
|
2526
|
+
debug$f.enabled && debug$f("Operation", JSON.stringify(operation, null, 2));
|
|
2684
2527
|
const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
|
|
2685
2528
|
if (!block)
|
|
2686
2529
|
throw new Error("Could not find block");
|
|
@@ -2773,7 +2616,7 @@ function createOperationToPatches(types) {
|
|
|
2773
2616
|
_key: block.children[operation.path[1] - 1]._key
|
|
2774
2617
|
}])];
|
|
2775
2618
|
}
|
|
2776
|
-
return debug$
|
|
2619
|
+
return debug$f("Something was inserted into a void block. Not producing editor patches."), [];
|
|
2777
2620
|
}
|
|
2778
2621
|
function splitNodePatch(editor, operation, beforeValue) {
|
|
2779
2622
|
const patches = [], splitBlock = editor.children[operation.path[0]];
|
|
@@ -2831,9 +2674,9 @@ function createOperationToPatches(types) {
|
|
|
2831
2674
|
_key: block._key
|
|
2832
2675
|
}, "children", {
|
|
2833
2676
|
_key: spanToRemove._key
|
|
2834
|
-
}])] : (debug$
|
|
2677
|
+
}])] : (debug$f("Span not found in editor trying to remove node"), []);
|
|
2835
2678
|
} else
|
|
2836
|
-
return debug$
|
|
2679
|
+
return debug$f("Not creating patch inside object block"), [];
|
|
2837
2680
|
}
|
|
2838
2681
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
2839
2682
|
const patches = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
@@ -2859,7 +2702,7 @@ function createOperationToPatches(types) {
|
|
|
2859
2702
|
_key: removedSpan._key
|
|
2860
2703
|
}])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
|
|
2861
2704
|
} else
|
|
2862
|
-
debug$
|
|
2705
|
+
debug$f("Void nodes can't be merged, not creating any patches");
|
|
2863
2706
|
return patches;
|
|
2864
2707
|
}
|
|
2865
2708
|
function moveNodePatch(editor, operation, beforeValue) {
|
|
@@ -2898,9 +2741,19 @@ function createOperationToPatches(types) {
|
|
|
2898
2741
|
splitNodePatch
|
|
2899
2742
|
};
|
|
2900
2743
|
}
|
|
2744
|
+
const IS_APPLYING_BEHAVIOR_ACTIONS = /* @__PURE__ */ new WeakMap();
|
|
2745
|
+
function withApplyingBehaviorActions(editor, fn) {
|
|
2746
|
+
const prev = isApplyingBehaviorActions(editor);
|
|
2747
|
+
IS_APPLYING_BEHAVIOR_ACTIONS.set(editor, !0), fn(), IS_APPLYING_BEHAVIOR_ACTIONS.set(editor, prev);
|
|
2748
|
+
}
|
|
2749
|
+
function isApplyingBehaviorActions(editor) {
|
|
2750
|
+
return IS_APPLYING_BEHAVIOR_ACTIONS.get(editor) ?? !1;
|
|
2751
|
+
}
|
|
2901
2752
|
function createWithEventListeners(editorActor, subscriptions) {
|
|
2902
2753
|
return function(editor) {
|
|
2903
|
-
|
|
2754
|
+
if (editorActor.getSnapshot().context.maxBlocks !== void 0)
|
|
2755
|
+
return editor;
|
|
2756
|
+
subscriptions.push(() => {
|
|
2904
2757
|
const subscription = editorActor.on("*", (event) => {
|
|
2905
2758
|
switch (event.type) {
|
|
2906
2759
|
case "annotation.add": {
|
|
@@ -2925,17 +2778,6 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2925
2778
|
});
|
|
2926
2779
|
break;
|
|
2927
2780
|
}
|
|
2928
|
-
case "annotation.toggle": {
|
|
2929
|
-
editorActor.send({
|
|
2930
|
-
type: "behavior event",
|
|
2931
|
-
behaviorEvent: {
|
|
2932
|
-
type: "annotation.toggle",
|
|
2933
|
-
annotation: event.annotation
|
|
2934
|
-
},
|
|
2935
|
-
editor
|
|
2936
|
-
});
|
|
2937
|
-
break;
|
|
2938
|
-
}
|
|
2939
2781
|
case "blur": {
|
|
2940
2782
|
editorActor.send({
|
|
2941
2783
|
type: "behavior event",
|
|
@@ -2946,28 +2788,6 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
2946
2788
|
});
|
|
2947
2789
|
break;
|
|
2948
2790
|
}
|
|
2949
|
-
case "decorator.add": {
|
|
2950
|
-
editorActor.send({
|
|
2951
|
-
type: "behavior event",
|
|
2952
|
-
behaviorEvent: {
|
|
2953
|
-
type: "decorator.add",
|
|
2954
|
-
decorator: event.decorator
|
|
2955
|
-
},
|
|
2956
|
-
editor
|
|
2957
|
-
});
|
|
2958
|
-
break;
|
|
2959
|
-
}
|
|
2960
|
-
case "decorator.remove": {
|
|
2961
|
-
editorActor.send({
|
|
2962
|
-
type: "behavior event",
|
|
2963
|
-
behaviorEvent: {
|
|
2964
|
-
type: "decorator.remove",
|
|
2965
|
-
decorator: event.decorator
|
|
2966
|
-
},
|
|
2967
|
-
editor
|
|
2968
|
-
});
|
|
2969
|
-
break;
|
|
2970
|
-
}
|
|
2971
2791
|
case "decorator.toggle": {
|
|
2972
2792
|
editorActor.send({
|
|
2973
2793
|
type: "behavior event",
|
|
@@ -3023,6 +2843,17 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
3023
2843
|
});
|
|
3024
2844
|
break;
|
|
3025
2845
|
}
|
|
2846
|
+
case "select": {
|
|
2847
|
+
editorActor.send({
|
|
2848
|
+
type: "behavior event",
|
|
2849
|
+
behaviorEvent: {
|
|
2850
|
+
type: "select",
|
|
2851
|
+
selection: event.selection
|
|
2852
|
+
},
|
|
2853
|
+
editor
|
|
2854
|
+
});
|
|
2855
|
+
break;
|
|
2856
|
+
}
|
|
3026
2857
|
case "style.toggle": {
|
|
3027
2858
|
editorActor.send({
|
|
3028
2859
|
type: "behavior event",
|
|
@@ -3039,25 +2870,11 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
3039
2870
|
return () => {
|
|
3040
2871
|
subscription.unsubscribe();
|
|
3041
2872
|
};
|
|
3042
|
-
})
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
decorator: mark
|
|
3048
|
-
},
|
|
3049
|
-
editor
|
|
3050
|
-
});
|
|
3051
|
-
}, editor.removeMark = (mark) => {
|
|
3052
|
-
editorActor.send({
|
|
3053
|
-
type: "behavior event",
|
|
3054
|
-
behaviorEvent: {
|
|
3055
|
-
type: "decorator.remove",
|
|
3056
|
-
decorator: mark
|
|
3057
|
-
},
|
|
3058
|
-
editor
|
|
3059
|
-
});
|
|
3060
|
-
}, editor.deleteBackward = (unit) => {
|
|
2873
|
+
});
|
|
2874
|
+
const {
|
|
2875
|
+
select
|
|
2876
|
+
} = editor;
|
|
2877
|
+
return editor.deleteBackward = (unit) => {
|
|
3061
2878
|
editorActor.send({
|
|
3062
2879
|
type: "behavior event",
|
|
3063
2880
|
behaviorEvent: {
|
|
@@ -3101,7 +2918,21 @@ function createWithEventListeners(editorActor, subscriptions) {
|
|
|
3101
2918
|
},
|
|
3102
2919
|
editor
|
|
3103
2920
|
});
|
|
3104
|
-
}
|
|
2921
|
+
}, editor.select = (location) => {
|
|
2922
|
+
if (isApplyingBehaviorActions(editor)) {
|
|
2923
|
+
select(location);
|
|
2924
|
+
return;
|
|
2925
|
+
}
|
|
2926
|
+
const range = Editor.range(editor, location);
|
|
2927
|
+
editorActor.send({
|
|
2928
|
+
type: "behavior event",
|
|
2929
|
+
behaviorEvent: {
|
|
2930
|
+
type: "select",
|
|
2931
|
+
selection: toPortableTextRange(fromSlateValue(editor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), range, editorActor.getSnapshot().context.schema)
|
|
2932
|
+
},
|
|
2933
|
+
editor
|
|
2934
|
+
});
|
|
2935
|
+
}, editor;
|
|
3105
2936
|
};
|
|
3106
2937
|
}
|
|
3107
2938
|
function createWithMaxBlocks(editorActor) {
|
|
@@ -3198,13 +3029,13 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3198
3029
|
}, editor;
|
|
3199
3030
|
};
|
|
3200
3031
|
}
|
|
3201
|
-
const debug$
|
|
3032
|
+
const debug$e = debugWithName("applyPatches"), debugVerbose = debug$e.enabled && !0;
|
|
3202
3033
|
function createApplyPatch(schemaTypes) {
|
|
3203
3034
|
return (editor, patch) => {
|
|
3204
3035
|
let changed = !1;
|
|
3205
|
-
debugVerbose
|
|
3036
|
+
debugVerbose && (debug$e(`
|
|
3206
3037
|
|
|
3207
|
-
NEW PATCH =============================================================`), debug$
|
|
3038
|
+
NEW PATCH =============================================================`), debug$e(JSON.stringify(patch, null, 2)));
|
|
3208
3039
|
try {
|
|
3209
3040
|
switch (patch.type) {
|
|
3210
3041
|
case "insert":
|
|
@@ -3220,7 +3051,7 @@ NEW PATCH =============================================================`), debug
|
|
|
3220
3051
|
changed = diffMatchPatch(editor, patch);
|
|
3221
3052
|
break;
|
|
3222
3053
|
default:
|
|
3223
|
-
debug$
|
|
3054
|
+
debug$e("Unhandled patch", patch.type);
|
|
3224
3055
|
}
|
|
3225
3056
|
} catch (err) {
|
|
3226
3057
|
console.error(err);
|
|
@@ -3235,9 +3066,9 @@ function diffMatchPatch(editor, patch) {
|
|
|
3235
3066
|
childPath
|
|
3236
3067
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3237
3068
|
if (!block)
|
|
3238
|
-
return debug$
|
|
3069
|
+
return debug$e("Block not found"), !1;
|
|
3239
3070
|
if (!child || !childPath)
|
|
3240
|
-
return debug$
|
|
3071
|
+
return debug$e("Child not found"), !1;
|
|
3241
3072
|
if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !Text.isText(child))
|
|
3242
3073
|
return !1;
|
|
3243
3074
|
const patches = parse(patch.value), [newValue] = apply(patches, child.text, {
|
|
@@ -3267,9 +3098,9 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3267
3098
|
childPath: targetChildPath
|
|
3268
3099
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3269
3100
|
if (!targetBlock || !targetBlockPath)
|
|
3270
|
-
return debug$
|
|
3101
|
+
return debug$e("Block not found"), !1;
|
|
3271
3102
|
if (patch.path.length > 1 && patch.path[1] !== "children")
|
|
3272
|
-
return debug$
|
|
3103
|
+
return debug$e("Ignoring patch targeting void value"), !1;
|
|
3273
3104
|
if (patch.path.length === 1) {
|
|
3274
3105
|
const {
|
|
3275
3106
|
items: items2,
|
|
@@ -3277,7 +3108,7 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3277
3108
|
} = patch, blocksToInsert = toSlateValue(items2, {
|
|
3278
3109
|
schemaTypes
|
|
3279
3110
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
|
|
3280
|
-
return debug$
|
|
3111
|
+
return debug$e(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), Transforms.insertNodes(editor, blocksToInsert, {
|
|
3281
3112
|
at: [normalizedIdx2]
|
|
3282
3113
|
}), debugState(editor, "after"), !0;
|
|
3283
3114
|
}
|
|
@@ -3286,14 +3117,14 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3286
3117
|
position
|
|
3287
3118
|
} = patch;
|
|
3288
3119
|
if (!targetChild || !targetChildPath)
|
|
3289
|
-
return debug$
|
|
3120
|
+
return debug$e("Child not found"), !1;
|
|
3290
3121
|
const childrenToInsert = targetBlock && toSlateValue([{
|
|
3291
3122
|
...targetBlock,
|
|
3292
3123
|
children: items
|
|
3293
3124
|
}], {
|
|
3294
3125
|
schemaTypes
|
|
3295
3126
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
3296
|
-
return debug$
|
|
3127
|
+
return debug$e(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && Element$1.isElement(childrenToInsert[0]) && Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
3297
3128
|
at: childInsertPath
|
|
3298
3129
|
}), debugState(editor, "after"), !0;
|
|
3299
3130
|
}
|
|
@@ -3307,14 +3138,14 @@ function setPatch(editor, patch) {
|
|
|
3307
3138
|
childPath
|
|
3308
3139
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3309
3140
|
if (!block)
|
|
3310
|
-
return debug$
|
|
3141
|
+
return debug$e("Block not found"), !1;
|
|
3311
3142
|
const isTextBlock = editor.isTextBlock(block);
|
|
3312
3143
|
if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
|
|
3313
|
-
return debug$
|
|
3144
|
+
return debug$e("Ignoring setting void value"), !1;
|
|
3314
3145
|
if (debugState(editor, "before"), isTextBlock && child && childPath) {
|
|
3315
3146
|
if (Text.isText(value) && Text.isText(child)) {
|
|
3316
3147
|
const newText = child.text;
|
|
3317
|
-
value.text !== newText && (debug$
|
|
3148
|
+
value.text !== newText && (debug$e("Setting text property"), editor.apply({
|
|
3318
3149
|
type: "remove_text",
|
|
3319
3150
|
path: childPath,
|
|
3320
3151
|
offset: 0,
|
|
@@ -3326,7 +3157,7 @@ function setPatch(editor, patch) {
|
|
|
3326
3157
|
text: value.text
|
|
3327
3158
|
}), editor.onChange());
|
|
3328
3159
|
} else
|
|
3329
|
-
debug$
|
|
3160
|
+
debug$e("Setting non-text property"), editor.apply({
|
|
3330
3161
|
type: "set_node",
|
|
3331
3162
|
path: childPath,
|
|
3332
3163
|
properties: {},
|
|
@@ -3334,7 +3165,7 @@ function setPatch(editor, patch) {
|
|
|
3334
3165
|
});
|
|
3335
3166
|
return !0;
|
|
3336
3167
|
} else if (Element$1.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
3337
|
-
debug$
|
|
3168
|
+
debug$e("Setting block property");
|
|
3338
3169
|
const {
|
|
3339
3170
|
children,
|
|
3340
3171
|
...nextRest
|
|
@@ -3351,7 +3182,7 @@ function setPatch(editor, patch) {
|
|
|
3351
3182
|
...prevRest
|
|
3352
3183
|
},
|
|
3353
3184
|
newProperties: nextRest
|
|
3354
|
-
}), debug$
|
|
3185
|
+
}), debug$e("Setting children"), block.children.forEach((c2, cIndex) => {
|
|
3355
3186
|
editor.apply({
|
|
3356
3187
|
type: "remove_node",
|
|
3357
3188
|
path: blockPath.concat(block.children.length - 1 - cIndex),
|
|
@@ -3377,7 +3208,7 @@ function setPatch(editor, patch) {
|
|
|
3377
3208
|
}
|
|
3378
3209
|
function unsetPatch(editor, patch) {
|
|
3379
3210
|
if (patch.path.length === 0) {
|
|
3380
|
-
debug$
|
|
3211
|
+
debug$e("Removing everything"), debugState(editor, "before");
|
|
3381
3212
|
const previousSelection = editor.selection;
|
|
3382
3213
|
return Transforms.deselect(editor), editor.children.forEach((_child, i) => {
|
|
3383
3214
|
Transforms.removeNodes(editor, {
|
|
@@ -3404,13 +3235,13 @@ function unsetPatch(editor, patch) {
|
|
|
3404
3235
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3405
3236
|
if (patch.path.length === 1) {
|
|
3406
3237
|
if (!block || !blockPath)
|
|
3407
|
-
return debug$
|
|
3238
|
+
return debug$e("Block not found"), !1;
|
|
3408
3239
|
const blockIndex = blockPath[0];
|
|
3409
|
-
return debug$
|
|
3240
|
+
return debug$e(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), Transforms.removeNodes(editor, {
|
|
3410
3241
|
at: [blockIndex]
|
|
3411
3242
|
}), debugState(editor, "after"), !0;
|
|
3412
3243
|
}
|
|
3413
|
-
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$
|
|
3244
|
+
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$e("Child not found"), !1) : (debug$e(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose && debug$e(`Removing child at path ${JSON.stringify(childPath)}`), Transforms.removeNodes(editor, {
|
|
3414
3245
|
at: childPath
|
|
3415
3246
|
}), debugState(editor, "after"), !0) : !1;
|
|
3416
3247
|
}
|
|
@@ -3418,7 +3249,7 @@ function isKeyedSegment(segment) {
|
|
|
3418
3249
|
return typeof segment == "object" && "_key" in segment;
|
|
3419
3250
|
}
|
|
3420
3251
|
function debugState(editor, stateName) {
|
|
3421
|
-
debugVerbose
|
|
3252
|
+
debugVerbose && (debug$e(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$e(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
|
|
3422
3253
|
}
|
|
3423
3254
|
function findBlockFromPath(editor, path) {
|
|
3424
3255
|
let blockIndex = -1;
|
|
@@ -3460,7 +3291,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3460
3291
|
childPath: void 0
|
|
3461
3292
|
};
|
|
3462
3293
|
}
|
|
3463
|
-
const debug$
|
|
3294
|
+
const debug$d = debugWithName("plugin:withPatches");
|
|
3464
3295
|
function createWithPatches({
|
|
3465
3296
|
editorActor,
|
|
3466
3297
|
patchFunctions,
|
|
@@ -3486,7 +3317,7 @@ function createWithPatches({
|
|
|
3486
3317
|
withoutPatching(editor, () => {
|
|
3487
3318
|
withoutSaving(editor, () => {
|
|
3488
3319
|
patches.forEach((patch) => {
|
|
3489
|
-
debug$
|
|
3320
|
+
debug$d.enabled && debug$d(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
|
|
3490
3321
|
});
|
|
3491
3322
|
});
|
|
3492
3323
|
});
|
|
@@ -3499,10 +3330,10 @@ function createWithPatches({
|
|
|
3499
3330
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
3500
3331
|
};
|
|
3501
3332
|
return subscriptions.push(() => {
|
|
3502
|
-
debug$
|
|
3333
|
+
debug$d("Subscribing to remote patches");
|
|
3503
3334
|
const sub = editorActor.on("patches", handlePatches);
|
|
3504
3335
|
return () => {
|
|
3505
|
-
debug$
|
|
3336
|
+
debug$d("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
3506
3337
|
};
|
|
3507
3338
|
}), editor.apply = (operation) => {
|
|
3508
3339
|
let patches = [];
|
|
@@ -3553,7 +3384,7 @@ function createWithPatches({
|
|
|
3553
3384
|
}, editor;
|
|
3554
3385
|
};
|
|
3555
3386
|
}
|
|
3556
|
-
const debug$
|
|
3387
|
+
const debug$c = debugWithName("plugin:withPlaceholderBlock");
|
|
3557
3388
|
function createWithPlaceholderBlock(editorActor) {
|
|
3558
3389
|
return function(editor) {
|
|
3559
3390
|
const {
|
|
@@ -3578,7 +3409,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
3578
3409
|
const node = op.node;
|
|
3579
3410
|
if (op.path[0] === 0 && Editor.isVoid(editor, node)) {
|
|
3580
3411
|
const nextPath = Path.next(op.path);
|
|
3581
|
-
editor.children[nextPath[0]] || (debug$
|
|
3412
|
+
editor.children[nextPath[0]] || (debug$c("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
3582
3413
|
decorators: []
|
|
3583
3414
|
})));
|
|
3584
3415
|
}
|
|
@@ -3587,7 +3418,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
3587
3418
|
}, editor;
|
|
3588
3419
|
};
|
|
3589
3420
|
}
|
|
3590
|
-
const debug$
|
|
3421
|
+
const debug$b = debugWithName("plugin:withPortableTextBlockStyle");
|
|
3591
3422
|
function createWithPortableTextBlockStyle(editorActor, types) {
|
|
3592
3423
|
const defaultStyle = types.styles[0].value;
|
|
3593
3424
|
return function(editor) {
|
|
@@ -3600,7 +3431,7 @@ function createWithPortableTextBlockStyle(editorActor, types) {
|
|
|
3600
3431
|
if (op.type === "split_node" && op.path.length === 1 && editor.isTextBlock(op.properties) && op.properties.style !== defaultStyle && op.path[0] === path[0] && !Path.equals(path, op.path)) {
|
|
3601
3432
|
const [child] = Editor.node(editor, [op.path[0] + 1, 0]);
|
|
3602
3433
|
if (Text.isText(child) && child.text === "") {
|
|
3603
|
-
debug$
|
|
3434
|
+
debug$b(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
|
|
3604
3435
|
type: "normalizing"
|
|
3605
3436
|
}), Transforms.setNodes(editor, {
|
|
3606
3437
|
style: defaultStyle
|
|
@@ -3660,7 +3491,7 @@ function getNextSpan({
|
|
|
3660
3491
|
}
|
|
3661
3492
|
return nextSpan;
|
|
3662
3493
|
}
|
|
3663
|
-
const debug$
|
|
3494
|
+
const debug$a = debugWithName("plugin:withPortableTextMarkModel");
|
|
3664
3495
|
function createWithPortableTextMarkModel(editorActor, types) {
|
|
3665
3496
|
return function(editor) {
|
|
3666
3497
|
const {
|
|
@@ -3674,7 +3505,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3674
3505
|
for (const [child, childPath] of children) {
|
|
3675
3506
|
const nextNode = node.children[childPath[1] + 1];
|
|
3676
3507
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
3677
|
-
debug$
|
|
3508
|
+
debug$a("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
3678
3509
|
type: "normalizing"
|
|
3679
3510
|
}), Transforms.mergeNodes(editor, {
|
|
3680
3511
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -3687,7 +3518,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3687
3518
|
}
|
|
3688
3519
|
}
|
|
3689
3520
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
3690
|
-
debug$
|
|
3521
|
+
debug$a("Adding .markDefs to block node"), editorActor.send({
|
|
3691
3522
|
type: "normalizing"
|
|
3692
3523
|
}), Transforms.setNodes(editor, {
|
|
3693
3524
|
markDefs: []
|
|
@@ -3699,7 +3530,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3699
3530
|
return;
|
|
3700
3531
|
}
|
|
3701
3532
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
3702
|
-
debug$
|
|
3533
|
+
debug$a("Adding .marks to span node"), editorActor.send({
|
|
3703
3534
|
type: "normalizing"
|
|
3704
3535
|
}), Transforms.setNodes(editor, {
|
|
3705
3536
|
marks: []
|
|
@@ -3713,7 +3544,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3713
3544
|
if (editor.isTextSpan(node)) {
|
|
3714
3545
|
const blockPath = Path.parent(path), [block] = Editor.node(editor, blockPath), decorators2 = types.decorators.map((decorator) => decorator.value), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
3715
3546
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
3716
|
-
debug$
|
|
3547
|
+
debug$a("Removing annotations from empty span node"), editorActor.send({
|
|
3717
3548
|
type: "normalizing"
|
|
3718
3549
|
}), Transforms.setNodes(editor, {
|
|
3719
3550
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -3731,7 +3562,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3731
3562
|
if (editor.isTextSpan(child)) {
|
|
3732
3563
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
3733
3564
|
if (orphanedAnnotations.length > 0) {
|
|
3734
|
-
debug$
|
|
3565
|
+
debug$a("Removing orphaned annotations from span node"), editorActor.send({
|
|
3735
3566
|
type: "normalizing"
|
|
3736
3567
|
}), Transforms.setNodes(editor, {
|
|
3737
3568
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3749,7 +3580,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3749
3580
|
if (editor.isTextBlock(block)) {
|
|
3750
3581
|
const decorators2 = types.decorators.map((decorator) => decorator.value), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
3751
3582
|
if (orphanedAnnotations.length > 0) {
|
|
3752
|
-
debug$
|
|
3583
|
+
debug$a("Removing orphaned annotations from span node"), editorActor.send({
|
|
3753
3584
|
type: "normalizing"
|
|
3754
3585
|
}), Transforms.setNodes(editor, {
|
|
3755
3586
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -3767,7 +3598,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3767
3598
|
for (const markDef of markDefs)
|
|
3768
3599
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
3769
3600
|
if (markDefs.length !== newMarkDefs.length) {
|
|
3770
|
-
debug$
|
|
3601
|
+
debug$a("Removing duplicate markDefs"), editorActor.send({
|
|
3771
3602
|
type: "normalizing"
|
|
3772
3603
|
}), Transforms.setNodes(editor, {
|
|
3773
3604
|
markDefs: newMarkDefs
|
|
@@ -3782,7 +3613,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3782
3613
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
3783
3614
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
3784
3615
|
if (node.markDefs && !isEqual(newMarkDefs, node.markDefs)) {
|
|
3785
|
-
debug$
|
|
3616
|
+
debug$a("Removing markDef not in use"), editorActor.send({
|
|
3786
3617
|
type: "normalizing"
|
|
3787
3618
|
}), Transforms.setNodes(editor, {
|
|
3788
3619
|
markDefs: newMarkDefs
|
|
@@ -3999,7 +3830,7 @@ function createWithPortableTextMarkModel(editorActor, types) {
|
|
|
3999
3830
|
const [targetBlock, targetPath] = Editor.node(editor, [op.path[0] - 1]);
|
|
4000
3831
|
if (editor.isTextBlock(targetBlock)) {
|
|
4001
3832
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq([...oldDefs, ...op.properties.markDefs]);
|
|
4002
|
-
debug$
|
|
3833
|
+
debug$a("Copying markDefs over to merged block", op), Transforms.setNodes(editor, {
|
|
4003
3834
|
markDefs: newMarkDefs
|
|
4004
3835
|
}, {
|
|
4005
3836
|
at: targetPath,
|
|
@@ -4060,7 +3891,12 @@ const addDecoratorActionImplementation = ({
|
|
|
4060
3891
|
editor.marks = marks;
|
|
4061
3892
|
}
|
|
4062
3893
|
}
|
|
4063
|
-
editor.
|
|
3894
|
+
if (editor.selection) {
|
|
3895
|
+
const selection = editor.selection;
|
|
3896
|
+
editor.selection = {
|
|
3897
|
+
...selection
|
|
3898
|
+
};
|
|
3899
|
+
}
|
|
4064
3900
|
}
|
|
4065
3901
|
}, removeDecoratorActionImplementation = ({
|
|
4066
3902
|
action
|
|
@@ -4068,7 +3904,7 @@ const addDecoratorActionImplementation = ({
|
|
|
4068
3904
|
const editor = action.editor, mark = action.decorator, {
|
|
4069
3905
|
selection
|
|
4070
3906
|
} = editor;
|
|
4071
|
-
if (selection)
|
|
3907
|
+
if (selection) {
|
|
4072
3908
|
if (Range.isExpanded(selection))
|
|
4073
3909
|
Transforms.setNodes(editor, {}, {
|
|
4074
3910
|
match: Text.isText,
|
|
@@ -4111,6 +3947,13 @@ const addDecoratorActionImplementation = ({
|
|
|
4111
3947
|
};
|
|
4112
3948
|
}
|
|
4113
3949
|
}
|
|
3950
|
+
if (editor.selection) {
|
|
3951
|
+
const selection2 = editor.selection;
|
|
3952
|
+
editor.selection = {
|
|
3953
|
+
...selection2
|
|
3954
|
+
};
|
|
3955
|
+
}
|
|
3956
|
+
}
|
|
4114
3957
|
};
|
|
4115
3958
|
function isDecoratorActive({
|
|
4116
3959
|
editor,
|
|
@@ -4151,7 +3994,8 @@ const toggleDecoratorActionImplementation = ({
|
|
|
4151
3994
|
decorator: action.decorator
|
|
4152
3995
|
}
|
|
4153
3996
|
});
|
|
4154
|
-
}
|
|
3997
|
+
};
|
|
3998
|
+
debugWithName("plugin:withPortableTextSelections");
|
|
4155
3999
|
function createWithPortableTextSelections(editorActor, types) {
|
|
4156
4000
|
let prevSelection = null;
|
|
4157
4001
|
return function(editor) {
|
|
@@ -4167,7 +4011,7 @@ function createWithPortableTextSelections(editorActor, types) {
|
|
|
4167
4011
|
ptRange = toPortableTextRange(value, editor.selection, types), SLATE_TO_PORTABLE_TEXT_RANGE.set(editor.selection, ptRange);
|
|
4168
4012
|
}
|
|
4169
4013
|
}
|
|
4170
|
-
|
|
4014
|
+
ptRange ? editorActor.send({
|
|
4171
4015
|
type: "selection",
|
|
4172
4016
|
selection: ptRange
|
|
4173
4017
|
}) : editorActor.send({
|
|
@@ -4180,10 +4024,9 @@ function createWithPortableTextSelections(editorActor, types) {
|
|
|
4180
4024
|
onChange
|
|
4181
4025
|
} = editor;
|
|
4182
4026
|
return editor.onChange = () => {
|
|
4183
|
-
|
|
4184
|
-
onChange(), hasChanges && !editorActor.getSnapshot().matches({
|
|
4027
|
+
onChange(), editorActor.getSnapshot().matches({
|
|
4185
4028
|
setup: "setting up"
|
|
4186
|
-
})
|
|
4029
|
+
}) || emitPortableTextSelection();
|
|
4187
4030
|
}, editor;
|
|
4188
4031
|
};
|
|
4189
4032
|
}
|
|
@@ -5418,16 +5261,6 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5418
5261
|
const nextBlockPath = [action.editor.selection.focus.path.slice(0, 1)[0] + 1];
|
|
5419
5262
|
Transforms.select(action.editor, nextBlockPath);
|
|
5420
5263
|
},
|
|
5421
|
-
reselect: ({
|
|
5422
|
-
action
|
|
5423
|
-
}) => {
|
|
5424
|
-
const selection = action.editor.selection;
|
|
5425
|
-
selection && (Transforms.select(action.editor, {
|
|
5426
|
-
...selection
|
|
5427
|
-
}), action.editor.selection = {
|
|
5428
|
-
...selection
|
|
5429
|
-
});
|
|
5430
|
-
},
|
|
5431
5264
|
"style.toggle": toggleStyleActionImplementation,
|
|
5432
5265
|
"style.add": addStyleActionImplementation,
|
|
5433
5266
|
"style.remove": removeStyleActionImplementation,
|
|
@@ -5439,6 +5272,27 @@ function performAction({
|
|
|
5439
5272
|
action
|
|
5440
5273
|
}) {
|
|
5441
5274
|
switch (action.type) {
|
|
5275
|
+
case "annotation.toggle": {
|
|
5276
|
+
behaviorActionImplementations["annotation.toggle"]({
|
|
5277
|
+
context,
|
|
5278
|
+
action
|
|
5279
|
+
});
|
|
5280
|
+
break;
|
|
5281
|
+
}
|
|
5282
|
+
case "decorator.add": {
|
|
5283
|
+
behaviorActionImplementations["decorator.add"]({
|
|
5284
|
+
context,
|
|
5285
|
+
action
|
|
5286
|
+
});
|
|
5287
|
+
break;
|
|
5288
|
+
}
|
|
5289
|
+
case "decorator.remove": {
|
|
5290
|
+
behaviorActionImplementations["decorator.remove"]({
|
|
5291
|
+
context,
|
|
5292
|
+
action
|
|
5293
|
+
});
|
|
5294
|
+
break;
|
|
5295
|
+
}
|
|
5442
5296
|
case "delete.block": {
|
|
5443
5297
|
behaviorActionImplementations["delete.block"]({
|
|
5444
5298
|
context,
|
|
@@ -5532,13 +5386,6 @@ function performAction({
|
|
|
5532
5386
|
});
|
|
5533
5387
|
break;
|
|
5534
5388
|
}
|
|
5535
|
-
case "reselect": {
|
|
5536
|
-
behaviorActionImplementations.reselect({
|
|
5537
|
-
context,
|
|
5538
|
-
action
|
|
5539
|
-
});
|
|
5540
|
-
break;
|
|
5541
|
-
}
|
|
5542
5389
|
case "style.add": {
|
|
5543
5390
|
behaviorActionImplementations["style.add"]({
|
|
5544
5391
|
context,
|
|
@@ -5593,13 +5440,6 @@ function performDefaultAction({
|
|
|
5593
5440
|
});
|
|
5594
5441
|
break;
|
|
5595
5442
|
}
|
|
5596
|
-
case "annotation.toggle": {
|
|
5597
|
-
behaviorActionImplementations["annotation.toggle"]({
|
|
5598
|
-
context,
|
|
5599
|
-
action
|
|
5600
|
-
});
|
|
5601
|
-
break;
|
|
5602
|
-
}
|
|
5603
5443
|
case "blur": {
|
|
5604
5444
|
behaviorActionImplementations.blur({
|
|
5605
5445
|
context,
|
|
@@ -5607,20 +5447,6 @@ function performDefaultAction({
|
|
|
5607
5447
|
});
|
|
5608
5448
|
break;
|
|
5609
5449
|
}
|
|
5610
|
-
case "decorator.add": {
|
|
5611
|
-
behaviorActionImplementations["decorator.add"]({
|
|
5612
|
-
context,
|
|
5613
|
-
action
|
|
5614
|
-
});
|
|
5615
|
-
break;
|
|
5616
|
-
}
|
|
5617
|
-
case "decorator.remove": {
|
|
5618
|
-
behaviorActionImplementations["decorator.remove"]({
|
|
5619
|
-
context,
|
|
5620
|
-
action
|
|
5621
|
-
});
|
|
5622
|
-
break;
|
|
5623
|
-
}
|
|
5624
5450
|
case "decorator.toggle": {
|
|
5625
5451
|
behaviorActionImplementations["decorator.toggle"]({
|
|
5626
5452
|
context,
|
|
@@ -5691,6 +5517,13 @@ function performDefaultAction({
|
|
|
5691
5517
|
});
|
|
5692
5518
|
break;
|
|
5693
5519
|
}
|
|
5520
|
+
case "select": {
|
|
5521
|
+
behaviorActionImplementations.select({
|
|
5522
|
+
context,
|
|
5523
|
+
action
|
|
5524
|
+
});
|
|
5525
|
+
break;
|
|
5526
|
+
}
|
|
5694
5527
|
default:
|
|
5695
5528
|
behaviorActionImplementations["style.toggle"]({
|
|
5696
5529
|
context,
|
|
@@ -5715,10 +5548,22 @@ const editorMachine = setup({
|
|
|
5715
5548
|
input: {}
|
|
5716
5549
|
},
|
|
5717
5550
|
actions: {
|
|
5551
|
+
"add behavior to context": assign({
|
|
5552
|
+
behaviors: ({
|
|
5553
|
+
context,
|
|
5554
|
+
event
|
|
5555
|
+
}) => (assertEvent(event, "add behavior"), /* @__PURE__ */ new Set([...context.behaviors, event.behavior]))
|
|
5556
|
+
}),
|
|
5557
|
+
"remove behavior from context": assign({
|
|
5558
|
+
behaviors: ({
|
|
5559
|
+
context,
|
|
5560
|
+
event
|
|
5561
|
+
}) => (assertEvent(event, "remove behavior"), context.behaviors.delete(event.behavior), /* @__PURE__ */ new Set([...context.behaviors]))
|
|
5562
|
+
}),
|
|
5718
5563
|
"assign behaviors": assign({
|
|
5719
5564
|
behaviors: ({
|
|
5720
5565
|
event
|
|
5721
|
-
}) => (assertEvent(event, "update behaviors"), event.behaviors)
|
|
5566
|
+
}) => (assertEvent(event, "update behaviors"), new Set(event.behaviors))
|
|
5722
5567
|
}),
|
|
5723
5568
|
"assign schema": assign({
|
|
5724
5569
|
schema: ({
|
|
@@ -5765,14 +5610,16 @@ const editorMachine = setup({
|
|
|
5765
5610
|
const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : {
|
|
5766
5611
|
...event.behaviorEvent,
|
|
5767
5612
|
editor: event.editor
|
|
5768
|
-
}, eventBehaviors = context.behaviors.filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
5613
|
+
}, eventBehaviors = [...context.behaviors.values()].filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
5769
5614
|
if (eventBehaviors.length === 0) {
|
|
5770
5615
|
if (!defaultAction)
|
|
5771
5616
|
return;
|
|
5772
|
-
|
|
5773
|
-
|
|
5774
|
-
|
|
5775
|
-
|
|
5617
|
+
withApplyingBehaviorActions(event.editor, () => {
|
|
5618
|
+
Editor.withoutNormalizing(event.editor, () => {
|
|
5619
|
+
performAction({
|
|
5620
|
+
context,
|
|
5621
|
+
action: defaultAction
|
|
5622
|
+
});
|
|
5776
5623
|
});
|
|
5777
5624
|
}), event.editor.onChange();
|
|
5778
5625
|
return;
|
|
@@ -5800,21 +5647,28 @@ const editorMachine = setup({
|
|
|
5800
5647
|
event: event.behaviorEvent
|
|
5801
5648
|
}, shouldRun));
|
|
5802
5649
|
for (const actionIntends of actionIntendSets)
|
|
5803
|
-
behaviorOverwritten = behaviorOverwritten || actionIntends.length > 0 && actionIntends.some((actionIntend) => actionIntend.type !== "effect"),
|
|
5804
|
-
|
|
5805
|
-
const
|
|
5806
|
-
|
|
5807
|
-
|
|
5808
|
-
|
|
5809
|
-
|
|
5810
|
-
|
|
5811
|
-
|
|
5812
|
-
|
|
5813
|
-
|
|
5814
|
-
|
|
5815
|
-
|
|
5816
|
-
|
|
5817
|
-
|
|
5650
|
+
behaviorOverwritten = behaviorOverwritten || actionIntends.length > 0 && actionIntends.some((actionIntend) => actionIntend.type !== "effect"), withApplyingBehaviorActions(event.editor, () => {
|
|
5651
|
+
Editor.withoutNormalizing(event.editor, () => {
|
|
5652
|
+
for (const actionIntend of actionIntends) {
|
|
5653
|
+
if (actionIntend.type === "raise") {
|
|
5654
|
+
enqueue.raise({
|
|
5655
|
+
type: "behavior event",
|
|
5656
|
+
behaviorEvent: actionIntend.event,
|
|
5657
|
+
editor: event.editor
|
|
5658
|
+
});
|
|
5659
|
+
continue;
|
|
5660
|
+
}
|
|
5661
|
+
const action = {
|
|
5662
|
+
...actionIntend,
|
|
5663
|
+
editor: event.editor
|
|
5664
|
+
};
|
|
5665
|
+
performAction({
|
|
5666
|
+
context,
|
|
5667
|
+
action
|
|
5668
|
+
});
|
|
5669
|
+
}
|
|
5670
|
+
});
|
|
5671
|
+
}), event.editor.onChange();
|
|
5818
5672
|
if (behaviorOverwritten) {
|
|
5819
5673
|
event.nativeEvent?.preventDefault();
|
|
5820
5674
|
break;
|
|
@@ -5823,10 +5677,12 @@ const editorMachine = setup({
|
|
|
5823
5677
|
if (!behaviorOverwritten) {
|
|
5824
5678
|
if (!defaultAction)
|
|
5825
5679
|
return;
|
|
5826
|
-
|
|
5827
|
-
|
|
5828
|
-
|
|
5829
|
-
|
|
5680
|
+
withApplyingBehaviorActions(event.editor, () => {
|
|
5681
|
+
Editor.withoutNormalizing(event.editor, () => {
|
|
5682
|
+
performAction({
|
|
5683
|
+
context,
|
|
5684
|
+
action: defaultAction
|
|
5685
|
+
});
|
|
5830
5686
|
});
|
|
5831
5687
|
}), event.editor.onChange();
|
|
5832
5688
|
}
|
|
@@ -5837,7 +5693,7 @@ const editorMachine = setup({
|
|
|
5837
5693
|
context: ({
|
|
5838
5694
|
input
|
|
5839
5695
|
}) => ({
|
|
5840
|
-
behaviors: input.behaviors ?? coreBehaviors,
|
|
5696
|
+
behaviors: new Set(input.behaviors ?? coreBehaviors),
|
|
5841
5697
|
keyGenerator: input.keyGenerator,
|
|
5842
5698
|
pendingEvents: [],
|
|
5843
5699
|
schema: input.schema,
|
|
@@ -5847,6 +5703,12 @@ const editorMachine = setup({
|
|
|
5847
5703
|
value: input.value
|
|
5848
5704
|
}),
|
|
5849
5705
|
on: {
|
|
5706
|
+
"add behavior": {
|
|
5707
|
+
actions: "add behavior to context"
|
|
5708
|
+
},
|
|
5709
|
+
"remove behavior": {
|
|
5710
|
+
actions: "remove behavior from context"
|
|
5711
|
+
},
|
|
5850
5712
|
unset: {
|
|
5851
5713
|
actions: emit(({
|
|
5852
5714
|
event
|
|
@@ -5967,17 +5829,7 @@ const editorMachine = setup({
|
|
|
5967
5829
|
"behavior event": {
|
|
5968
5830
|
actions: "handle behavior event"
|
|
5969
5831
|
},
|
|
5970
|
-
"annotation
|
|
5971
|
-
actions: emit(({
|
|
5972
|
-
event
|
|
5973
|
-
}) => event)
|
|
5974
|
-
},
|
|
5975
|
-
"annotation.remove": {
|
|
5976
|
-
actions: emit(({
|
|
5977
|
-
event
|
|
5978
|
-
}) => event)
|
|
5979
|
-
},
|
|
5980
|
-
"annotation.toggle": {
|
|
5832
|
+
"annotation.*": {
|
|
5981
5833
|
actions: emit(({
|
|
5982
5834
|
event
|
|
5983
5835
|
}) => event)
|
|
@@ -6007,6 +5859,11 @@ const editorMachine = setup({
|
|
|
6007
5859
|
event
|
|
6008
5860
|
}) => event)
|
|
6009
5861
|
},
|
|
5862
|
+
select: {
|
|
5863
|
+
actions: emit(({
|
|
5864
|
+
event
|
|
5865
|
+
}) => event)
|
|
5866
|
+
},
|
|
6010
5867
|
"style.*": {
|
|
6011
5868
|
actions: emit(({
|
|
6012
5869
|
event
|
|
@@ -6177,6 +6034,15 @@ function createEditorFromActor(editorActor) {
|
|
|
6177
6034
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
6178
6035
|
slateEditorInstance: slateEditor.instance
|
|
6179
6036
|
}),
|
|
6037
|
+
registerBehavior: (config) => (editorActor.send({
|
|
6038
|
+
type: "add behavior",
|
|
6039
|
+
behavior: config.behavior
|
|
6040
|
+
}), () => {
|
|
6041
|
+
editorActor.send({
|
|
6042
|
+
type: "remove behavior",
|
|
6043
|
+
behavior: config.behavior
|
|
6044
|
+
});
|
|
6045
|
+
}),
|
|
6180
6046
|
send: (event) => {
|
|
6181
6047
|
editorActor.send(event);
|
|
6182
6048
|
},
|
|
@@ -6197,7 +6063,7 @@ const EditorActorContext = createContext({}), PortableTextEditorSelectionContext
|
|
|
6197
6063
|
if (selection === void 0)
|
|
6198
6064
|
throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
|
|
6199
6065
|
return selection;
|
|
6200
|
-
}, debug$5 = debugWithName("component:PortableTextEditor:SelectionProvider")
|
|
6066
|
+
}, debug$5 = debugWithName("component:PortableTextEditor:SelectionProvider");
|
|
6201
6067
|
function PortableTextEditorSelectionProvider(props) {
|
|
6202
6068
|
const $ = c(6), [selection, setSelection] = useState(null);
|
|
6203
6069
|
let t0, t1;
|
|
@@ -6205,7 +6071,7 @@ function PortableTextEditorSelectionProvider(props) {
|
|
|
6205
6071
|
debug$5("Subscribing to selection changes");
|
|
6206
6072
|
const subscription = props.editorActor.on("selection", (event) => {
|
|
6207
6073
|
startTransition(() => {
|
|
6208
|
-
|
|
6074
|
+
setSelection(event.selection);
|
|
6209
6075
|
});
|
|
6210
6076
|
});
|
|
6211
6077
|
return () => {
|
|
@@ -6401,23 +6267,19 @@ function RouteEventsToChanges(props) {
|
|
|
6401
6267
|
});
|
|
6402
6268
|
break bb5;
|
|
6403
6269
|
}
|
|
6404
|
-
case "
|
|
6405
|
-
|
|
6406
|
-
case "annotation.toggle":
|
|
6407
|
-
case "blur":
|
|
6408
|
-
case "decorator.add":
|
|
6409
|
-
case "decorator.remove":
|
|
6410
|
-
case "decorator.toggle":
|
|
6411
|
-
case "focus":
|
|
6412
|
-
case "insert.block object":
|
|
6413
|
-
case "insert.inline object":
|
|
6414
|
-
case "list item.toggle":
|
|
6415
|
-
case "style.toggle":
|
|
6416
|
-
case "patches":
|
|
6417
|
-
case "editable":
|
|
6418
|
-
case "read only":
|
|
6270
|
+
case "mutation": {
|
|
6271
|
+
handleChange(event);
|
|
6419
6272
|
break bb5;
|
|
6420
|
-
|
|
6273
|
+
}
|
|
6274
|
+
case "ready": {
|
|
6275
|
+
handleChange(event);
|
|
6276
|
+
break bb5;
|
|
6277
|
+
}
|
|
6278
|
+
case "selection": {
|
|
6279
|
+
handleChange(event);
|
|
6280
|
+
break bb5;
|
|
6281
|
+
}
|
|
6282
|
+
case "unset":
|
|
6421
6283
|
handleChange(event);
|
|
6422
6284
|
}
|
|
6423
6285
|
});
|
|
@@ -6550,17 +6412,9 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6550
6412
|
return useMemo(() => /* @__PURE__ */ jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
|
|
6551
6413
|
};
|
|
6552
6414
|
Leaf.displayName = "Leaf";
|
|
6553
|
-
const debug$2 = debugWithName("plugin:withHotKeys")
|
|
6554
|
-
marks: {
|
|
6555
|
-
"mod+b": "strong",
|
|
6556
|
-
"mod+i": "em",
|
|
6557
|
-
"mod+u": "underline",
|
|
6558
|
-
"mod+'": "code"
|
|
6559
|
-
},
|
|
6560
|
-
custom: {}
|
|
6561
|
-
};
|
|
6415
|
+
const debug$2 = debugWithName("plugin:withHotKeys");
|
|
6562
6416
|
function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions) {
|
|
6563
|
-
const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions
|
|
6417
|
+
const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions ?? {};
|
|
6564
6418
|
return function(editor) {
|
|
6565
6419
|
return editor.pteWithHotKeys = (event) => {
|
|
6566
6420
|
Object.keys(activeHotkeys).forEach((cat) => {
|