@portabletext/editor 1.10.2 → 1.11.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/README.md +21 -27
- package/lib/index.d.mts +531 -206
- package/lib/index.d.ts +531 -206
- package/lib/index.esm.js +415 -367
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +458 -410
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +415 -367
- package/lib/index.mjs.map +1 -1
- package/package.json +10 -10
- package/src/editor/Editable.tsx +1 -1
- package/src/editor/PortableTextEditor.tsx +122 -95
- package/src/editor/behavior/behavior.types.ts +9 -0
- package/src/editor/components/Synchronizer.tsx +13 -68
- package/src/editor/create-slate-editor.tsx +2 -14
- package/src/editor/editor-event-listener.tsx +24 -0
- package/src/editor/editor-machine.ts +34 -4
- package/src/editor/editor-provider.tsx +81 -0
- package/src/editor/hooks/useSyncValue.ts +2 -3
- package/src/editor/plugins/with-plugins.ts +0 -27
- package/src/editor/use-editor.ts +89 -20
- package/src/index.ts +12 -4
- package/src/types/editor.ts +0 -1
package/lib/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var types = require("@sanity/types"), schema = require("@sanity/schema"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react
|
|
3
|
+
var types = require("@sanity/types"), schema = require("@sanity/schema"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), React = require("react"), slate = require("slate"), slateReact = require("slate-react"), debug$m = require("debug"), reactCompilerRuntime = require("react-compiler-runtime"), styledComponents = require("styled-components"), uniq = require("lodash/uniq.js"), rxjs = require("rxjs"), useEffectEvent = require("use-effect-event"), throttle = require("lodash/throttle.js"), debounce = require("lodash/debounce.js"), patches = require("@portabletext/patches"), flatten = require("lodash/flatten.js"), isPlainObject = require("lodash/isPlainObject.js"), getRandomValues = require("get-random-values-esm"), xstate = require("xstate"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), isHotkeyEsm = require("is-hotkey-esm"), blockTools = require("@sanity/block-tools");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
7
|
-
var startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$m), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), throttle__default = /* @__PURE__ */ _interopDefaultCompat(throttle), debounce__default = /* @__PURE__ */ _interopDefaultCompat(debounce), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject),
|
|
7
|
+
var startCase__default = /* @__PURE__ */ _interopDefaultCompat(startCase), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), React__default = /* @__PURE__ */ _interopDefaultCompat(React), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$m), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), throttle__default = /* @__PURE__ */ _interopDefaultCompat(throttle), debounce__default = /* @__PURE__ */ _interopDefaultCompat(debounce), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), getRandomValues__default = /* @__PURE__ */ _interopDefaultCompat(getRandomValues), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy);
|
|
8
8
|
function defineBehavior(behavior) {
|
|
9
9
|
return behavior;
|
|
10
10
|
}
|
|
@@ -296,6 +296,65 @@ const breakingBlockObject = {
|
|
|
296
296
|
blockObjects: coreBlockObjectBehaviors,
|
|
297
297
|
lists: coreListBehaviors
|
|
298
298
|
};
|
|
299
|
+
function createLinkBehaviors(config) {
|
|
300
|
+
const pasteLinkOnSelection = {
|
|
301
|
+
on: "paste",
|
|
302
|
+
guard: ({
|
|
303
|
+
context,
|
|
304
|
+
event
|
|
305
|
+
}) => {
|
|
306
|
+
const selectionCollapsed = selectionIsCollapsed(context), text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
|
|
307
|
+
url,
|
|
308
|
+
schema: context.schema
|
|
309
|
+
}) : void 0;
|
|
310
|
+
return annotation && !selectionCollapsed ? {
|
|
311
|
+
annotation
|
|
312
|
+
} : !1;
|
|
313
|
+
},
|
|
314
|
+
actions: [(_, {
|
|
315
|
+
annotation
|
|
316
|
+
}) => [{
|
|
317
|
+
type: "annotation.add",
|
|
318
|
+
annotation
|
|
319
|
+
}]]
|
|
320
|
+
}, pasteLinkAtCaret = {
|
|
321
|
+
on: "paste",
|
|
322
|
+
guard: ({
|
|
323
|
+
context,
|
|
324
|
+
event
|
|
325
|
+
}) => {
|
|
326
|
+
const focusSpan = getFocusSpan(context), selectionCollapsed = selectionIsCollapsed(context);
|
|
327
|
+
if (!focusSpan || !selectionCollapsed)
|
|
328
|
+
return !1;
|
|
329
|
+
const text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
|
|
330
|
+
url,
|
|
331
|
+
schema: context.schema
|
|
332
|
+
}) : void 0;
|
|
333
|
+
return url && annotation && selectionCollapsed ? {
|
|
334
|
+
focusSpan,
|
|
335
|
+
annotation,
|
|
336
|
+
url
|
|
337
|
+
} : !1;
|
|
338
|
+
},
|
|
339
|
+
actions: [(_, {
|
|
340
|
+
annotation,
|
|
341
|
+
url
|
|
342
|
+
}) => [{
|
|
343
|
+
type: "insert span",
|
|
344
|
+
text: url,
|
|
345
|
+
annotations: [annotation]
|
|
346
|
+
}]]
|
|
347
|
+
};
|
|
348
|
+
return [pasteLinkOnSelection, pasteLinkAtCaret];
|
|
349
|
+
}
|
|
350
|
+
function looksLikeUrl(text) {
|
|
351
|
+
let looksLikeUrl2 = !1;
|
|
352
|
+
try {
|
|
353
|
+
new URL(text), looksLikeUrl2 = !0;
|
|
354
|
+
} catch {
|
|
355
|
+
}
|
|
356
|
+
return looksLikeUrl2;
|
|
357
|
+
}
|
|
299
358
|
function isPortableTextSpan(node) {
|
|
300
359
|
return node._type === "span" && "text" in node && typeof node.text == "string" && (typeof node.marks > "u" || Array.isArray(node.marks) && node.marks.every((mark) => typeof mark == "string"));
|
|
301
360
|
}
|
|
@@ -552,65 +611,6 @@ function createMarkdownBehaviors(config) {
|
|
|
552
611
|
};
|
|
553
612
|
return [automaticBlockquoteOnSpace, automaticBreak, automaticHeadingOnSpace, clearStyleOnBackspace, automaticListOnSpace];
|
|
554
613
|
}
|
|
555
|
-
function createLinkBehaviors(config) {
|
|
556
|
-
const pasteLinkOnSelection = {
|
|
557
|
-
on: "paste",
|
|
558
|
-
guard: ({
|
|
559
|
-
context,
|
|
560
|
-
event
|
|
561
|
-
}) => {
|
|
562
|
-
const selectionCollapsed = selectionIsCollapsed(context), text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
|
|
563
|
-
url,
|
|
564
|
-
schema: context.schema
|
|
565
|
-
}) : void 0;
|
|
566
|
-
return annotation && !selectionCollapsed ? {
|
|
567
|
-
annotation
|
|
568
|
-
} : !1;
|
|
569
|
-
},
|
|
570
|
-
actions: [(_, {
|
|
571
|
-
annotation
|
|
572
|
-
}) => [{
|
|
573
|
-
type: "annotation.add",
|
|
574
|
-
annotation
|
|
575
|
-
}]]
|
|
576
|
-
}, pasteLinkAtCaret = {
|
|
577
|
-
on: "paste",
|
|
578
|
-
guard: ({
|
|
579
|
-
context,
|
|
580
|
-
event
|
|
581
|
-
}) => {
|
|
582
|
-
const focusSpan = getFocusSpan(context), selectionCollapsed = selectionIsCollapsed(context);
|
|
583
|
-
if (!focusSpan || !selectionCollapsed)
|
|
584
|
-
return !1;
|
|
585
|
-
const text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.linkAnnotation?.({
|
|
586
|
-
url,
|
|
587
|
-
schema: context.schema
|
|
588
|
-
}) : void 0;
|
|
589
|
-
return url && annotation && selectionCollapsed ? {
|
|
590
|
-
focusSpan,
|
|
591
|
-
annotation,
|
|
592
|
-
url
|
|
593
|
-
} : !1;
|
|
594
|
-
},
|
|
595
|
-
actions: [(_, {
|
|
596
|
-
annotation,
|
|
597
|
-
url
|
|
598
|
-
}) => [{
|
|
599
|
-
type: "insert span",
|
|
600
|
-
text: url,
|
|
601
|
-
annotations: [annotation]
|
|
602
|
-
}]]
|
|
603
|
-
};
|
|
604
|
-
return [pasteLinkOnSelection, pasteLinkAtCaret];
|
|
605
|
-
}
|
|
606
|
-
function looksLikeUrl(text) {
|
|
607
|
-
let looksLikeUrl2 = !1;
|
|
608
|
-
try {
|
|
609
|
-
new URL(text), looksLikeUrl2 = !0;
|
|
610
|
-
} catch {
|
|
611
|
-
}
|
|
612
|
-
return looksLikeUrl2;
|
|
613
|
-
}
|
|
614
614
|
function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
615
615
|
if (!portableTextType)
|
|
616
616
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
@@ -1140,15 +1140,15 @@ const debug$l = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
1140
1140
|
element,
|
|
1141
1141
|
readOnly,
|
|
1142
1142
|
blockRef
|
|
1143
|
-
} = t0, editor = slateReact.useSlateStatic(), dragGhostRef =
|
|
1143
|
+
} = t0, editor = slateReact.useSlateStatic(), dragGhostRef = React.useRef(), [isDragOver, setIsDragOver] = React.useState(!1);
|
|
1144
1144
|
let t1, t2;
|
|
1145
1145
|
$[0] !== editor || $[1] !== element ? (t2 = slate.Editor.isVoid(editor, element), $[0] = editor, $[1] = element, $[2] = t2) : t2 = $[2], t1 = t2;
|
|
1146
1146
|
const isVoid = t1;
|
|
1147
1147
|
let t3, t4;
|
|
1148
1148
|
$[3] !== editor || $[4] !== element ? (t4 = slate.Editor.isInline(editor, element), $[3] = editor, $[4] = element, $[5] = t4) : t4 = $[5], t3 = t4;
|
|
1149
|
-
const isInline = t3, [blockElement, setBlockElement] =
|
|
1149
|
+
const isInline = t3, [blockElement, setBlockElement] = React.useState(null);
|
|
1150
1150
|
let t5, t6;
|
|
1151
|
-
$[6] !== blockRef || $[7] !== editor || $[8] !== element ? (t5 = () => setBlockElement(blockRef ? blockRef.current : slateReact.ReactEditor.toDOMNode(editor, element)), t6 = [editor, element, blockRef], $[6] = blockRef, $[7] = editor, $[8] = element, $[9] = t5, $[10] = t6) : (t5 = $[9], t6 = $[10]),
|
|
1151
|
+
$[6] !== blockRef || $[7] !== editor || $[8] !== element ? (t5 = () => setBlockElement(blockRef ? blockRef.current : slateReact.ReactEditor.toDOMNode(editor, element)), t6 = [editor, element, blockRef], $[6] = blockRef, $[7] = editor, $[8] = element, $[9] = t5, $[10] = t6) : (t5 = $[9], t6 = $[10]), React.useEffect(t5, t6);
|
|
1152
1152
|
let t7;
|
|
1153
1153
|
$[11] !== blockElement || $[12] !== editor || $[13] !== element ? (t7 = (event) => {
|
|
1154
1154
|
const isMyDragOver = IS_DRAGGING_BLOCK_ELEMENT.get(editor);
|
|
@@ -1279,9 +1279,9 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
1279
1279
|
renderStyle,
|
|
1280
1280
|
spellCheck
|
|
1281
1281
|
}) => {
|
|
1282
|
-
const editor = slateReact.useSlateStatic(), selected = slateReact.useSelected(), blockRef =
|
|
1282
|
+
const editor = slateReact.useSlateStatic(), selected = slateReact.useSelected(), blockRef = React.useRef(null), inlineBlockObjectRef = React.useRef(null), focused = selected && editor.selection && slate.Range.isCollapsed(editor.selection) || !1, value = React.useMemo(() => fromSlateValue([element], schemaTypes.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0], [editor, element, schemaTypes.block.name]);
|
|
1283
1283
|
let renderedBlock = children, className;
|
|
1284
|
-
const blockPath =
|
|
1284
|
+
const blockPath = React.useMemo(() => [{
|
|
1285
1285
|
_key: element._key
|
|
1286
1286
|
}], [element]);
|
|
1287
1287
|
if (typeof element._type != "string")
|
|
@@ -1402,8 +1402,8 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
1402
1402
|
] }, element._key);
|
|
1403
1403
|
};
|
|
1404
1404
|
Element.displayName = "Element";
|
|
1405
|
-
const PortableTextEditorContext =
|
|
1406
|
-
const editor =
|
|
1405
|
+
const PortableTextEditorContext = React.createContext(null), usePortableTextEditor = () => {
|
|
1406
|
+
const editor = React.useContext(PortableTextEditorContext);
|
|
1407
1407
|
if (!editor)
|
|
1408
1408
|
throw new Error("The `usePortableTextEditor` hook must be used inside the <PortableTextEditor> component's context.");
|
|
1409
1409
|
return editor;
|
|
@@ -2752,19 +2752,20 @@ function useSyncValue(props) {
|
|
|
2752
2752
|
const {
|
|
2753
2753
|
editorActor,
|
|
2754
2754
|
portableTextEditor,
|
|
2755
|
-
readOnly
|
|
2756
|
-
|
|
2755
|
+
readOnly,
|
|
2756
|
+
slateEditor
|
|
2757
|
+
} = props, schemaTypes = editorActor.getSnapshot().context.schema, previousValue = React.useRef(), updateValueFunctionRef = React.useRef(), updateFromCurrentValue = React.useCallback(() => {
|
|
2757
2758
|
const currentValue = CURRENT_VALUE.get(portableTextEditor);
|
|
2758
2759
|
if (previousValue.current === currentValue) {
|
|
2759
2760
|
debug$j("Value is the same object as previous, not need to sync");
|
|
2760
2761
|
return;
|
|
2761
2762
|
}
|
|
2762
2763
|
updateValueFunctionRef.current && currentValue && (debug$j("Updating the value debounced"), updateValueFunctionRef.current(currentValue));
|
|
2763
|
-
}, [portableTextEditor]), updateValueDebounced =
|
|
2764
|
+
}, [portableTextEditor]), updateValueDebounced = React.useMemo(() => debounce__default.default(updateFromCurrentValue, 1e3, {
|
|
2764
2765
|
trailing: !0,
|
|
2765
2766
|
leading: !1
|
|
2766
2767
|
}), [updateFromCurrentValue]);
|
|
2767
|
-
return
|
|
2768
|
+
return React.useMemo(() => {
|
|
2768
2769
|
const updateFunction = (value) => {
|
|
2769
2770
|
CURRENT_VALUE.set(portableTextEditor, value);
|
|
2770
2771
|
const isProcessingLocalChanges = isChangingLocally(slateEditor), isProcessingRemoteChanges = isChangingRemotely(slateEditor);
|
|
@@ -2936,27 +2937,29 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
2936
2937
|
}
|
|
2937
2938
|
const debug$i = debugWithName("component:PortableTextEditor:Synchronizer"), debugVerbose$3 = debug$i.enabled && !1, FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3;
|
|
2938
2939
|
function Synchronizer(props) {
|
|
2939
|
-
const $ = reactCompilerRuntime.c(
|
|
2940
|
+
const $ = reactCompilerRuntime.c(26), readOnly = react.useSelector(props.editorActor, _temp), value = react.useSelector(props.editorActor, _temp2), {
|
|
2940
2941
|
editorActor,
|
|
2941
2942
|
getValue,
|
|
2942
|
-
|
|
2943
|
+
portableTextEditor,
|
|
2944
|
+
slateEditor
|
|
2943
2945
|
} = props;
|
|
2944
2946
|
let t0;
|
|
2945
2947
|
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0];
|
|
2946
|
-
const pendingPatches =
|
|
2948
|
+
const pendingPatches = React.useRef(t0);
|
|
2947
2949
|
let t1;
|
|
2948
|
-
$[1] !== editorActor || $[2] !== portableTextEditor || $[3] !== readOnly ? (t1 = {
|
|
2950
|
+
$[1] !== editorActor || $[2] !== portableTextEditor || $[3] !== readOnly || $[4] !== slateEditor ? (t1 = {
|
|
2949
2951
|
editorActor,
|
|
2950
2952
|
portableTextEditor,
|
|
2951
|
-
readOnly
|
|
2952
|
-
|
|
2953
|
-
|
|
2953
|
+
readOnly,
|
|
2954
|
+
slateEditor
|
|
2955
|
+
}, $[1] = editorActor, $[2] = portableTextEditor, $[3] = readOnly, $[4] = slateEditor, $[5] = t1) : t1 = $[5];
|
|
2956
|
+
const syncValue = useSyncValue(t1);
|
|
2954
2957
|
let t2, t3;
|
|
2955
|
-
$[
|
|
2958
|
+
$[6] !== slateEditor ? (t2 = () => {
|
|
2956
2959
|
IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !1);
|
|
2957
|
-
}, t3 = [slateEditor], $[
|
|
2960
|
+
}, t3 = [slateEditor], $[6] = slateEditor, $[7] = t2, $[8] = t3) : (t2 = $[7], t3 = $[8]), React.useEffect(t2, t3);
|
|
2958
2961
|
let t4;
|
|
2959
|
-
$[
|
|
2962
|
+
$[9] !== editorActor || $[10] !== getValue || $[11] !== slateEditor ? (t4 = () => {
|
|
2960
2963
|
if (pendingPatches.current.length > 0) {
|
|
2961
2964
|
debug$i("Flushing pending patches"), debugVerbose$3 && debug$i(`Patches:
|
|
2962
2965
|
${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
@@ -2968,17 +2971,14 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
|
2968
2971
|
}), pendingPatches.current = [];
|
|
2969
2972
|
}
|
|
2970
2973
|
IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !1);
|
|
2971
|
-
}, $[
|
|
2974
|
+
}, $[9] = editorActor, $[10] = getValue, $[11] = slateEditor, $[12] = t4) : t4 = $[12];
|
|
2972
2975
|
const onFlushPendingPatches = t4;
|
|
2973
2976
|
let t5, t6;
|
|
2974
|
-
$[
|
|
2977
|
+
$[13] !== onFlushPendingPatches ? (t5 = () => () => {
|
|
2975
2978
|
onFlushPendingPatches();
|
|
2976
|
-
}, t6 = [onFlushPendingPatches], $[
|
|
2977
|
-
let t7;
|
|
2978
|
-
$[
|
|
2979
|
-
const handleChange = useEffectEvent.useEffectEvent(t7);
|
|
2980
|
-
let t8, t9;
|
|
2981
|
-
$[17] !== editorActor || $[18] !== handleChange || $[19] !== onFlushPendingPatches || $[20] !== slateEditor ? (t8 = () => {
|
|
2979
|
+
}, t6 = [onFlushPendingPatches], $[13] = onFlushPendingPatches, $[14] = t5, $[15] = t6) : (t5 = $[14], t6 = $[15]), React.useEffect(t5, t6);
|
|
2980
|
+
let t7, t8;
|
|
2981
|
+
$[16] !== editorActor || $[17] !== onFlushPendingPatches || $[18] !== slateEditor ? (t7 = () => {
|
|
2982
2982
|
const onFlushPendingPatchesThrottled = throttle__default.default(() => {
|
|
2983
2983
|
if (slate.Editor.isNormalizing(slateEditor)) {
|
|
2984
2984
|
onFlushPendingPatches();
|
|
@@ -2989,90 +2989,76 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
|
2989
2989
|
leading: !1,
|
|
2990
2990
|
trailing: !0
|
|
2991
2991
|
});
|
|
2992
|
-
debug$i("Subscribing to
|
|
2993
|
-
const sub = editorActor.on("
|
|
2994
|
-
|
|
2995
|
-
case "patch": {
|
|
2996
|
-
IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !0), pendingPatches.current.push(event.patch), onFlushPendingPatchesThrottled(), handleChange(event);
|
|
2997
|
-
break bb22;
|
|
2998
|
-
}
|
|
2999
|
-
case "loading": {
|
|
3000
|
-
handleChange({
|
|
3001
|
-
type: "loading",
|
|
3002
|
-
isLoading: !0
|
|
3003
|
-
});
|
|
3004
|
-
break bb22;
|
|
3005
|
-
}
|
|
3006
|
-
case "done loading": {
|
|
3007
|
-
handleChange({
|
|
3008
|
-
type: "loading",
|
|
3009
|
-
isLoading: !1
|
|
3010
|
-
});
|
|
3011
|
-
break bb22;
|
|
3012
|
-
}
|
|
3013
|
-
case "focused": {
|
|
3014
|
-
handleChange({
|
|
3015
|
-
type: "focus",
|
|
3016
|
-
event: event.event
|
|
3017
|
-
});
|
|
3018
|
-
break bb22;
|
|
3019
|
-
}
|
|
3020
|
-
case "value changed": {
|
|
3021
|
-
handleChange({
|
|
3022
|
-
type: "value",
|
|
3023
|
-
value: event.value
|
|
3024
|
-
});
|
|
3025
|
-
break bb22;
|
|
3026
|
-
}
|
|
3027
|
-
case "invalid value": {
|
|
3028
|
-
handleChange({
|
|
3029
|
-
type: "invalidValue",
|
|
3030
|
-
resolution: event.resolution,
|
|
3031
|
-
value: event.value
|
|
3032
|
-
});
|
|
3033
|
-
break bb22;
|
|
3034
|
-
}
|
|
3035
|
-
case "error": {
|
|
3036
|
-
handleChange({
|
|
3037
|
-
...event,
|
|
3038
|
-
level: "warning"
|
|
3039
|
-
});
|
|
3040
|
-
break bb22;
|
|
3041
|
-
}
|
|
3042
|
-
case "annotation.add":
|
|
3043
|
-
case "annotation.remove":
|
|
3044
|
-
case "annotation.toggle":
|
|
3045
|
-
case "focus":
|
|
3046
|
-
case "patches":
|
|
3047
|
-
break bb22;
|
|
3048
|
-
default:
|
|
3049
|
-
handleChange(event);
|
|
3050
|
-
}
|
|
2992
|
+
debug$i("Subscribing to patch events");
|
|
2993
|
+
const sub = editorActor.on("patch", (event) => {
|
|
2994
|
+
IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !0), pendingPatches.current.push(event.patch), onFlushPendingPatchesThrottled();
|
|
3051
2995
|
});
|
|
3052
2996
|
return () => {
|
|
3053
|
-
debug$i("Unsubscribing to
|
|
2997
|
+
debug$i("Unsubscribing to patch events"), sub.unsubscribe();
|
|
3054
2998
|
};
|
|
3055
|
-
},
|
|
3056
|
-
const isInitialValueFromProps =
|
|
3057
|
-
let t10,
|
|
3058
|
-
return $[
|
|
2999
|
+
}, t8 = [editorActor, onFlushPendingPatches, slateEditor], $[16] = editorActor, $[17] = onFlushPendingPatches, $[18] = slateEditor, $[19] = t7, $[20] = t8) : (t7 = $[19], t8 = $[20]), React.useEffect(t7, t8);
|
|
3000
|
+
const isInitialValueFromProps = React.useRef(!0);
|
|
3001
|
+
let t10, t9;
|
|
3002
|
+
return $[21] !== editorActor || $[22] !== syncValue || $[23] !== value ? (t9 = () => {
|
|
3059
3003
|
debug$i("Value from props changed, syncing new value"), syncValue(value), isInitialValueFromProps.current && (editorActor.send({
|
|
3060
3004
|
type: "ready"
|
|
3061
3005
|
}), isInitialValueFromProps.current = !1);
|
|
3062
|
-
},
|
|
3006
|
+
}, t10 = [editorActor, syncValue, value], $[21] = editorActor, $[22] = syncValue, $[23] = value, $[24] = t10, $[25] = t9) : (t10 = $[24], t9 = $[25]), React.useEffect(t9, t10), null;
|
|
3063
3007
|
}
|
|
3064
3008
|
function _temp2(s_0) {
|
|
3065
3009
|
return s_0.context.value;
|
|
3066
3010
|
}
|
|
3067
|
-
function _temp
|
|
3011
|
+
function _temp(s) {
|
|
3068
3012
|
return s.context.readOnly;
|
|
3069
3013
|
}
|
|
3070
3014
|
Synchronizer.displayName = "Synchronizer";
|
|
3071
|
-
const
|
|
3015
|
+
const EditorActorContext = React.createContext({}), PortableTextEditorSelectionContext = React.createContext(null), usePortableTextEditorSelection = () => {
|
|
3016
|
+
const selection = React.useContext(PortableTextEditorSelectionContext);
|
|
3017
|
+
if (selection === void 0)
|
|
3018
|
+
throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
|
|
3019
|
+
return selection;
|
|
3020
|
+
}, debug$h = debugWithName("component:PortableTextEditor:SelectionProvider"), debugVerbose$2 = debug$h.enabled && !1;
|
|
3021
|
+
function PortableTextEditorSelectionProvider(props) {
|
|
3022
|
+
const $ = reactCompilerRuntime.c(6), [selection, setSelection] = React.useState(null);
|
|
3023
|
+
let t0, t1;
|
|
3024
|
+
$[0] !== props.editorActor ? (t0 = () => {
|
|
3025
|
+
debug$h("Subscribing to selection changes");
|
|
3026
|
+
const subscription = props.editorActor.on("selection", (event) => {
|
|
3027
|
+
React.startTransition(() => {
|
|
3028
|
+
debugVerbose$2 && debug$h("Setting selection"), setSelection(event.selection);
|
|
3029
|
+
});
|
|
3030
|
+
});
|
|
3031
|
+
return () => {
|
|
3032
|
+
debug$h("Unsubscribing to selection changes"), subscription.unsubscribe();
|
|
3033
|
+
};
|
|
3034
|
+
}, t1 = [props.editorActor], $[0] = props.editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), React.useEffect(t0, t1);
|
|
3035
|
+
let t2;
|
|
3036
|
+
return $[3] !== props.children || $[4] !== selection ? (t2 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children }), $[3] = props.children, $[4] = selection, $[5] = t2) : t2 = $[5], t2;
|
|
3037
|
+
}
|
|
3038
|
+
const defaultKeyGenerator = () => randomKey(12), getByteHexTable = /* @__PURE__ */ (() => {
|
|
3039
|
+
let table;
|
|
3040
|
+
return () => {
|
|
3041
|
+
if (table)
|
|
3042
|
+
return table;
|
|
3043
|
+
table = [];
|
|
3044
|
+
for (let i = 0; i < 256; ++i)
|
|
3045
|
+
table[i] = (i + 256).toString(16).slice(1);
|
|
3046
|
+
return table;
|
|
3047
|
+
};
|
|
3048
|
+
})();
|
|
3049
|
+
function whatwgRNG(length = 16) {
|
|
3050
|
+
const rnds8 = new Uint8Array(length);
|
|
3051
|
+
return getRandomValues__default.default(rnds8), rnds8;
|
|
3052
|
+
}
|
|
3053
|
+
function randomKey(length) {
|
|
3054
|
+
const table = getByteHexTable();
|
|
3055
|
+
return whatwgRNG(length).reduce((str, n) => str + table[n], "").slice(0, length);
|
|
3056
|
+
}
|
|
3057
|
+
const debug$g = debugWithName("operationToPatches");
|
|
3072
3058
|
function createOperationToPatches(types2) {
|
|
3073
3059
|
const textBlockName = types2.block.name;
|
|
3074
3060
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
3075
|
-
debug$
|
|
3061
|
+
debug$g.enabled && debug$g("Operation", JSON.stringify(operation, null, 2));
|
|
3076
3062
|
const block = editor.isTextBlock(editor.children[operation.path[0]]) && editor.children[operation.path[0]];
|
|
3077
3063
|
if (!block)
|
|
3078
3064
|
throw new Error("Could not find block");
|
|
@@ -3165,7 +3151,7 @@ function createOperationToPatches(types2) {
|
|
|
3165
3151
|
_key: block.children[operation.path[1] - 1]._key
|
|
3166
3152
|
}])];
|
|
3167
3153
|
}
|
|
3168
|
-
return debug$
|
|
3154
|
+
return debug$g("Something was inserted into a void block. Not producing editor patches."), [];
|
|
3169
3155
|
}
|
|
3170
3156
|
function splitNodePatch(editor, operation, beforeValue) {
|
|
3171
3157
|
const patches$1 = [], splitBlock = editor.children[operation.path[0]];
|
|
@@ -3223,9 +3209,9 @@ function createOperationToPatches(types2) {
|
|
|
3223
3209
|
_key: block._key
|
|
3224
3210
|
}, "children", {
|
|
3225
3211
|
_key: spanToRemove._key
|
|
3226
|
-
}])] : (debug$
|
|
3212
|
+
}])] : (debug$g("Span not found in editor trying to remove node"), []);
|
|
3227
3213
|
} else
|
|
3228
|
-
return debug$
|
|
3214
|
+
return debug$g("Not creating patch inside object block"), [];
|
|
3229
3215
|
}
|
|
3230
3216
|
function mergeNodePatch(editor, operation, beforeValue) {
|
|
3231
3217
|
const patches$1 = [], block = beforeValue[operation.path[0]], updatedBlock = editor.children[operation.path[0]];
|
|
@@ -3251,7 +3237,7 @@ function createOperationToPatches(types2) {
|
|
|
3251
3237
|
_key: removedSpan._key
|
|
3252
3238
|
}])) : console.warn(`Multiple spans have \`_key\` ${removedSpan._key}. It's ambiguous which one to remove.`, JSON.stringify(block, null, 2)));
|
|
3253
3239
|
} else
|
|
3254
|
-
debug$
|
|
3240
|
+
debug$g("Void nodes can't be merged, not creating any patches");
|
|
3255
3241
|
return patches$1;
|
|
3256
3242
|
}
|
|
3257
3243
|
function moveNodePatch(editor, operation, beforeValue) {
|
|
@@ -3496,13 +3482,13 @@ function createWithObjectKeys(editorActor, schemaTypes) {
|
|
|
3496
3482
|
}, editor;
|
|
3497
3483
|
};
|
|
3498
3484
|
}
|
|
3499
|
-
const debug$
|
|
3485
|
+
const debug$f = debugWithName("applyPatches"), debugVerbose$1 = debug$f.enabled && !0;
|
|
3500
3486
|
function createApplyPatch(schemaTypes) {
|
|
3501
3487
|
return (editor, patch) => {
|
|
3502
3488
|
let changed = !1;
|
|
3503
|
-
debugVerbose$
|
|
3489
|
+
debugVerbose$1 && (debug$f(`
|
|
3504
3490
|
|
|
3505
|
-
NEW PATCH =============================================================`), debug$
|
|
3491
|
+
NEW PATCH =============================================================`), debug$f(JSON.stringify(patch, null, 2)));
|
|
3506
3492
|
try {
|
|
3507
3493
|
switch (patch.type) {
|
|
3508
3494
|
case "insert":
|
|
@@ -3518,7 +3504,7 @@ NEW PATCH =============================================================`), debug
|
|
|
3518
3504
|
changed = diffMatchPatch(editor, patch);
|
|
3519
3505
|
break;
|
|
3520
3506
|
default:
|
|
3521
|
-
debug$
|
|
3507
|
+
debug$f("Unhandled patch", patch.type);
|
|
3522
3508
|
}
|
|
3523
3509
|
} catch (err) {
|
|
3524
3510
|
console.error(err);
|
|
@@ -3533,9 +3519,9 @@ function diffMatchPatch(editor, patch) {
|
|
|
3533
3519
|
childPath
|
|
3534
3520
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3535
3521
|
if (!block)
|
|
3536
|
-
return debug$
|
|
3522
|
+
return debug$f("Block not found"), !1;
|
|
3537
3523
|
if (!child || !childPath)
|
|
3538
|
-
return debug$
|
|
3524
|
+
return debug$f("Child not found"), !1;
|
|
3539
3525
|
if (!(block && editor.isTextBlock(block) && patch.path.length === 4 && patch.path[1] === "children" && patch.path[3] === "text") || !slate.Text.isText(child))
|
|
3540
3526
|
return !1;
|
|
3541
3527
|
const patches2 = parse(patch.value), [newValue] = apply(patches2, child.text, {
|
|
@@ -3565,9 +3551,9 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3565
3551
|
childPath: targetChildPath
|
|
3566
3552
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3567
3553
|
if (!targetBlock || !targetBlockPath)
|
|
3568
|
-
return debug$
|
|
3554
|
+
return debug$f("Block not found"), !1;
|
|
3569
3555
|
if (patch.path.length > 1 && patch.path[1] !== "children")
|
|
3570
|
-
return debug$
|
|
3556
|
+
return debug$f("Ignoring patch targeting void value"), !1;
|
|
3571
3557
|
if (patch.path.length === 1) {
|
|
3572
3558
|
const {
|
|
3573
3559
|
items: items2,
|
|
@@ -3575,7 +3561,7 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3575
3561
|
} = patch, blocksToInsert = toSlateValue(items2, {
|
|
3576
3562
|
schemaTypes
|
|
3577
3563
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetBlockIndex = targetBlockPath[0], normalizedIdx2 = position2 === "after" ? targetBlockIndex + 1 : targetBlockIndex;
|
|
3578
|
-
return debug$
|
|
3564
|
+
return debug$f(`Inserting blocks at path [${normalizedIdx2}]`), debugState(editor, "before"), slate.Transforms.insertNodes(editor, blocksToInsert, {
|
|
3579
3565
|
at: [normalizedIdx2]
|
|
3580
3566
|
}), debugState(editor, "after"), !0;
|
|
3581
3567
|
}
|
|
@@ -3584,14 +3570,14 @@ function insertPatch(editor, patch, schemaTypes) {
|
|
|
3584
3570
|
position
|
|
3585
3571
|
} = patch;
|
|
3586
3572
|
if (!targetChild || !targetChildPath)
|
|
3587
|
-
return debug$
|
|
3573
|
+
return debug$f("Child not found"), !1;
|
|
3588
3574
|
const childrenToInsert = targetBlock && toSlateValue([{
|
|
3589
3575
|
...targetBlock,
|
|
3590
3576
|
children: items
|
|
3591
3577
|
}], {
|
|
3592
3578
|
schemaTypes
|
|
3593
3579
|
}, KEY_TO_SLATE_ELEMENT.get(editor)), targetChildIndex = targetChildPath[1], normalizedIdx = position === "after" ? targetChildIndex + 1 : targetChildIndex, childInsertPath = [targetChildPath[0], normalizedIdx];
|
|
3594
|
-
return debug$
|
|
3580
|
+
return debug$f(`Inserting children at path ${childInsertPath}`), debugState(editor, "before"), childrenToInsert && slate.Element.isElement(childrenToInsert[0]) && slate.Transforms.insertNodes(editor, childrenToInsert[0].children, {
|
|
3595
3581
|
at: childInsertPath
|
|
3596
3582
|
}), debugState(editor, "after"), !0;
|
|
3597
3583
|
}
|
|
@@ -3605,14 +3591,14 @@ function setPatch(editor, patch) {
|
|
|
3605
3591
|
childPath
|
|
3606
3592
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3607
3593
|
if (!block)
|
|
3608
|
-
return debug$
|
|
3594
|
+
return debug$f("Block not found"), !1;
|
|
3609
3595
|
const isTextBlock = editor.isTextBlock(block);
|
|
3610
3596
|
if (isTextBlock && patch.path.length > 1 && patch.path[1] !== "children")
|
|
3611
|
-
return debug$
|
|
3597
|
+
return debug$f("Ignoring setting void value"), !1;
|
|
3612
3598
|
if (debugState(editor, "before"), isTextBlock && child && childPath) {
|
|
3613
3599
|
if (slate.Text.isText(value) && slate.Text.isText(child)) {
|
|
3614
3600
|
const newText = child.text;
|
|
3615
|
-
value.text !== newText && (debug$
|
|
3601
|
+
value.text !== newText && (debug$f("Setting text property"), editor.apply({
|
|
3616
3602
|
type: "remove_text",
|
|
3617
3603
|
path: childPath,
|
|
3618
3604
|
offset: 0,
|
|
@@ -3624,7 +3610,7 @@ function setPatch(editor, patch) {
|
|
|
3624
3610
|
text: value.text
|
|
3625
3611
|
}), editor.onChange());
|
|
3626
3612
|
} else
|
|
3627
|
-
debug$
|
|
3613
|
+
debug$f("Setting non-text property"), editor.apply({
|
|
3628
3614
|
type: "set_node",
|
|
3629
3615
|
path: childPath,
|
|
3630
3616
|
properties: {},
|
|
@@ -3632,7 +3618,7 @@ function setPatch(editor, patch) {
|
|
|
3632
3618
|
});
|
|
3633
3619
|
return !0;
|
|
3634
3620
|
} else if (slate.Element.isElement(block) && patch.path.length === 1 && blockPath) {
|
|
3635
|
-
debug$
|
|
3621
|
+
debug$f("Setting block property");
|
|
3636
3622
|
const {
|
|
3637
3623
|
children,
|
|
3638
3624
|
...nextRest
|
|
@@ -3649,7 +3635,7 @@ function setPatch(editor, patch) {
|
|
|
3649
3635
|
...prevRest
|
|
3650
3636
|
},
|
|
3651
3637
|
newProperties: nextRest
|
|
3652
|
-
}), debug$
|
|
3638
|
+
}), debug$f("Setting children"), block.children.forEach((c, cIndex) => {
|
|
3653
3639
|
editor.apply({
|
|
3654
3640
|
type: "remove_node",
|
|
3655
3641
|
path: blockPath.concat(block.children.length - 1 - cIndex),
|
|
@@ -3675,7 +3661,7 @@ function setPatch(editor, patch) {
|
|
|
3675
3661
|
}
|
|
3676
3662
|
function unsetPatch(editor, patch) {
|
|
3677
3663
|
if (patch.path.length === 0) {
|
|
3678
|
-
debug$
|
|
3664
|
+
debug$f("Removing everything"), debugState(editor, "before");
|
|
3679
3665
|
const previousSelection = editor.selection;
|
|
3680
3666
|
return slate.Transforms.deselect(editor), editor.children.forEach((_child, i) => {
|
|
3681
3667
|
slate.Transforms.removeNodes(editor, {
|
|
@@ -3702,13 +3688,13 @@ function unsetPatch(editor, patch) {
|
|
|
3702
3688
|
} = findBlockAndChildFromPath(editor, patch.path);
|
|
3703
3689
|
if (patch.path.length === 1) {
|
|
3704
3690
|
if (!block || !blockPath)
|
|
3705
|
-
return debug$
|
|
3691
|
+
return debug$f("Block not found"), !1;
|
|
3706
3692
|
const blockIndex = blockPath[0];
|
|
3707
|
-
return debug$
|
|
3693
|
+
return debug$f(`Removing block at path [${blockIndex}]`), debugState(editor, "before"), slate.Transforms.removeNodes(editor, {
|
|
3708
3694
|
at: [blockIndex]
|
|
3709
3695
|
}), debugState(editor, "after"), !0;
|
|
3710
3696
|
}
|
|
3711
|
-
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$
|
|
3697
|
+
return editor.isTextBlock(block) && patch.path[1] === "children" && patch.path.length === 3 ? !child || !childPath ? (debug$f("Child not found"), !1) : (debug$f(`Unsetting child at path ${JSON.stringify(childPath)}`), debugState(editor, "before"), debugVerbose$1 && debug$f(`Removing child at path ${JSON.stringify(childPath)}`), slate.Transforms.removeNodes(editor, {
|
|
3712
3698
|
at: childPath
|
|
3713
3699
|
}), debugState(editor, "after"), !0) : !1;
|
|
3714
3700
|
}
|
|
@@ -3716,7 +3702,7 @@ function isKeyedSegment(segment) {
|
|
|
3716
3702
|
return typeof segment == "object" && "_key" in segment;
|
|
3717
3703
|
}
|
|
3718
3704
|
function debugState(editor, stateName) {
|
|
3719
|
-
debugVerbose$
|
|
3705
|
+
debugVerbose$1 && (debug$f(`Children ${stateName}:`, JSON.stringify(editor.children, null, 2)), debug$f(`Selection ${stateName}: `, JSON.stringify(editor.selection, null, 2)));
|
|
3720
3706
|
}
|
|
3721
3707
|
function findBlockFromPath(editor, path) {
|
|
3722
3708
|
let blockIndex = -1;
|
|
@@ -3758,7 +3744,7 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
3758
3744
|
childPath: void 0
|
|
3759
3745
|
};
|
|
3760
3746
|
}
|
|
3761
|
-
const debug$
|
|
3747
|
+
const debug$e = debugWithName("plugin:withPatches");
|
|
3762
3748
|
function createWithPatches({
|
|
3763
3749
|
editorActor,
|
|
3764
3750
|
patchFunctions,
|
|
@@ -3784,7 +3770,7 @@ function createWithPatches({
|
|
|
3784
3770
|
withoutPatching(editor, () => {
|
|
3785
3771
|
withoutSaving(editor, () => {
|
|
3786
3772
|
patches2.forEach((patch) => {
|
|
3787
|
-
debug$
|
|
3773
|
+
debug$e.enabled && debug$e(`Handling remote patch ${JSON.stringify(patch)}`), changed = applyPatch(editor, patch);
|
|
3788
3774
|
});
|
|
3789
3775
|
});
|
|
3790
3776
|
});
|
|
@@ -3797,10 +3783,10 @@ function createWithPatches({
|
|
|
3797
3783
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
3798
3784
|
};
|
|
3799
3785
|
return subscriptions.push(() => {
|
|
3800
|
-
debug$
|
|
3786
|
+
debug$e("Subscribing to remote patches");
|
|
3801
3787
|
const sub = editorActor.on("patches", handlePatches);
|
|
3802
3788
|
return () => {
|
|
3803
|
-
debug$
|
|
3789
|
+
debug$e("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
3804
3790
|
};
|
|
3805
3791
|
}), editor.apply = (operation) => {
|
|
3806
3792
|
if (editorActor.getSnapshot().context.readOnly)
|
|
@@ -3853,7 +3839,7 @@ function createWithPatches({
|
|
|
3853
3839
|
}, editor;
|
|
3854
3840
|
};
|
|
3855
3841
|
}
|
|
3856
|
-
const debug$
|
|
3842
|
+
const debug$d = debugWithName("plugin:withPlaceholderBlock");
|
|
3857
3843
|
function createWithPlaceholderBlock(editorActor) {
|
|
3858
3844
|
return function(editor) {
|
|
3859
3845
|
const {
|
|
@@ -3873,7 +3859,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
3873
3859
|
const node = op.node;
|
|
3874
3860
|
if (op.path[0] === 0 && slate.Editor.isVoid(editor, node)) {
|
|
3875
3861
|
const nextPath = slate.Path.next(op.path);
|
|
3876
|
-
editor.children[nextPath[0]] || (debug$
|
|
3862
|
+
editor.children[nextPath[0]] || (debug$d("Adding placeholder block"), slate.Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
3877
3863
|
decorators: []
|
|
3878
3864
|
})));
|
|
3879
3865
|
}
|
|
@@ -3883,7 +3869,7 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
3883
3869
|
}, editor;
|
|
3884
3870
|
};
|
|
3885
3871
|
}
|
|
3886
|
-
const debug$
|
|
3872
|
+
const debug$c = debugWithName("plugin:withPortableTextBlockStyle");
|
|
3887
3873
|
function createWithPortableTextBlockStyle(editorActor, types2) {
|
|
3888
3874
|
const defaultStyle = types2.styles[0].value;
|
|
3889
3875
|
return function(editor) {
|
|
@@ -3896,7 +3882,7 @@ function createWithPortableTextBlockStyle(editorActor, types2) {
|
|
|
3896
3882
|
if (op.type === "split_node" && op.path.length === 1 && editor.isTextBlock(op.properties) && op.properties.style !== defaultStyle && op.path[0] === path[0] && !slate.Path.equals(path, op.path)) {
|
|
3897
3883
|
const [child] = slate.Editor.node(editor, [op.path[0] + 1, 0]);
|
|
3898
3884
|
if (slate.Text.isText(child) && child.text === "") {
|
|
3899
|
-
debug$
|
|
3885
|
+
debug$c(`Normalizing split node to ${defaultStyle} style`, op), editorActor.send({
|
|
3900
3886
|
type: "normalizing"
|
|
3901
3887
|
}), slate.Transforms.setNodes(editor, {
|
|
3902
3888
|
style: defaultStyle
|
|
@@ -3918,12 +3904,12 @@ function createWithPortableTextBlockStyle(editorActor, types2) {
|
|
|
3918
3904
|
at: editor.selection,
|
|
3919
3905
|
match: (node) => editor.isTextBlock(node)
|
|
3920
3906
|
})].forEach(([node, path]) => {
|
|
3921
|
-
editor.isTextBlock(node) && node.style === blockStyle ? (debug$
|
|
3907
|
+
editor.isTextBlock(node) && node.style === blockStyle ? (debug$c(`Unsetting block style '${blockStyle}'`), slate.Transforms.setNodes(editor, {
|
|
3922
3908
|
...node,
|
|
3923
3909
|
style: defaultStyle
|
|
3924
3910
|
}, {
|
|
3925
3911
|
at: path
|
|
3926
|
-
})) : (blockStyle ? debug$
|
|
3912
|
+
})) : (blockStyle ? debug$c(`Setting style '${blockStyle}'`) : debug$c("Setting default style", defaultStyle), slate.Transforms.setNodes(editor, {
|
|
3927
3913
|
...node,
|
|
3928
3914
|
style: blockStyle || defaultStyle
|
|
3929
3915
|
}, {
|
|
@@ -3933,11 +3919,11 @@ function createWithPortableTextBlockStyle(editorActor, types2) {
|
|
|
3933
3919
|
}, editor;
|
|
3934
3920
|
};
|
|
3935
3921
|
}
|
|
3936
|
-
const debug$
|
|
3922
|
+
const debug$b = debugWithName("plugin:withPortableTextLists"), MAX_LIST_LEVEL = 10;
|
|
3937
3923
|
function createWithPortableTextLists(types2) {
|
|
3938
3924
|
return function(editor) {
|
|
3939
3925
|
return editor.pteToggleListItem = (listItemStyle) => {
|
|
3940
|
-
editor.pteHasListStyle(listItemStyle) ? (debug$
|
|
3926
|
+
editor.pteHasListStyle(listItemStyle) ? (debug$b(`Remove list item '${listItemStyle}'`), editor.pteUnsetListItem(listItemStyle)) : (debug$b(`Add list item '${listItemStyle}'`), editor.pteSetListItem(listItemStyle));
|
|
3941
3927
|
}, editor.pteUnsetListItem = (listItemStyle) => {
|
|
3942
3928
|
editor.selection && [...slate.Editor.nodes(editor, {
|
|
3943
3929
|
at: editor.selection,
|
|
@@ -3953,7 +3939,7 @@ function createWithPortableTextLists(types2) {
|
|
|
3953
3939
|
listItem: void 0,
|
|
3954
3940
|
level: void 0
|
|
3955
3941
|
};
|
|
3956
|
-
debug$
|
|
3942
|
+
debug$b(`Unsetting list '${listItemStyle}'`), slate.Transforms.setNodes(editor, newNode, {
|
|
3957
3943
|
at: path
|
|
3958
3944
|
});
|
|
3959
3945
|
}
|
|
@@ -3963,7 +3949,7 @@ function createWithPortableTextLists(types2) {
|
|
|
3963
3949
|
at: editor.selection,
|
|
3964
3950
|
match: (node) => editor.isTextBlock(node)
|
|
3965
3951
|
})].forEach(([node, path]) => {
|
|
3966
|
-
debug$
|
|
3952
|
+
debug$b(`Setting list '${listItemStyle}'`), slate.Transforms.setNodes(editor, {
|
|
3967
3953
|
...node,
|
|
3968
3954
|
level: 1,
|
|
3969
3955
|
listItem: listItemStyle || types2.lists[0] && types2.lists[0].value
|
|
@@ -3979,7 +3965,7 @@ function createWithPortableTextLists(types2) {
|
|
|
3979
3965
|
match: (node) => slate.Element.isElement(node) && editor.isListBlock(node) && node.children.length === 1 && slate.Text.isText(node.children[0]) && node.children[0].text === ""
|
|
3980
3966
|
})];
|
|
3981
3967
|
return selectedBlocks.length === 0 ? !1 : (selectedBlocks.forEach(([node, path]) => {
|
|
3982
|
-
slate.Element.isElement(node) && (debug$
|
|
3968
|
+
slate.Element.isElement(node) && (debug$b("Unset list"), slate.Transforms.setNodes(editor, {
|
|
3983
3969
|
...node,
|
|
3984
3970
|
level: void 0,
|
|
3985
3971
|
listItem: void 0
|
|
@@ -3997,7 +3983,7 @@ function createWithPortableTextLists(types2) {
|
|
|
3997
3983
|
return selectedBlocks.length === 0 ? !1 : (selectedBlocks.forEach(([node, path]) => {
|
|
3998
3984
|
if (editor.isListBlock(node)) {
|
|
3999
3985
|
let level = node.level || 1;
|
|
4000
|
-
reverse ? (level--, debug$
|
|
3986
|
+
reverse ? (level--, debug$b("Decrementing list level", Math.min(MAX_LIST_LEVEL, Math.max(1, level)))) : (level++, debug$b("Incrementing list level", Math.min(MAX_LIST_LEVEL, Math.max(1, level)))), slate.Transforms.setNodes(editor, {
|
|
4001
3987
|
level: Math.min(MAX_LIST_LEVEL, Math.max(1, level))
|
|
4002
3988
|
}, {
|
|
4003
3989
|
at: path
|
|
@@ -4043,7 +4029,7 @@ function getNextSpan({
|
|
|
4043
4029
|
}
|
|
4044
4030
|
return nextSpan;
|
|
4045
4031
|
}
|
|
4046
|
-
const debug$
|
|
4032
|
+
const debug$a = debugWithName("plugin:withPortableTextMarkModel");
|
|
4047
4033
|
function createWithPortableTextMarkModel(editorActor, types2) {
|
|
4048
4034
|
return function(editor) {
|
|
4049
4035
|
const {
|
|
@@ -4057,7 +4043,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4057
4043
|
for (const [child, childPath] of children) {
|
|
4058
4044
|
const nextNode = node.children[childPath[1] + 1];
|
|
4059
4045
|
if (editor.isTextSpan(child) && editor.isTextSpan(nextNode) && child.marks?.every((mark) => nextNode.marks?.includes(mark)) && nextNode.marks?.every((mark) => child.marks?.includes(mark))) {
|
|
4060
|
-
debug$
|
|
4046
|
+
debug$a("Merging spans", JSON.stringify(child, null, 2), JSON.stringify(nextNode, null, 2)), editorActor.send({
|
|
4061
4047
|
type: "normalizing"
|
|
4062
4048
|
}), slate.Transforms.mergeNodes(editor, {
|
|
4063
4049
|
at: [childPath[0], childPath[1] + 1],
|
|
@@ -4070,7 +4056,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4070
4056
|
}
|
|
4071
4057
|
}
|
|
4072
4058
|
if (editor.isTextBlock(node) && !Array.isArray(node.markDefs)) {
|
|
4073
|
-
debug$
|
|
4059
|
+
debug$a("Adding .markDefs to block node"), editorActor.send({
|
|
4074
4060
|
type: "normalizing"
|
|
4075
4061
|
}), slate.Transforms.setNodes(editor, {
|
|
4076
4062
|
markDefs: []
|
|
@@ -4082,7 +4068,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4082
4068
|
return;
|
|
4083
4069
|
}
|
|
4084
4070
|
if (editor.isTextSpan(node) && !Array.isArray(node.marks)) {
|
|
4085
|
-
debug$
|
|
4071
|
+
debug$a("Adding .marks to span node"), editorActor.send({
|
|
4086
4072
|
type: "normalizing"
|
|
4087
4073
|
}), slate.Transforms.setNodes(editor, {
|
|
4088
4074
|
marks: []
|
|
@@ -4096,7 +4082,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4096
4082
|
if (editor.isTextSpan(node)) {
|
|
4097
4083
|
const blockPath = slate.Path.parent(path), [block] = slate.Editor.node(editor, blockPath), decorators2 = types2.decorators.map((decorator) => decorator.value), annotations = node.marks?.filter((mark) => !decorators2.includes(mark));
|
|
4098
4084
|
if (editor.isTextBlock(block) && node.text === "" && annotations && annotations.length > 0) {
|
|
4099
|
-
debug$
|
|
4085
|
+
debug$a("Removing annotations from empty span node"), editorActor.send({
|
|
4100
4086
|
type: "normalizing"
|
|
4101
4087
|
}), slate.Transforms.setNodes(editor, {
|
|
4102
4088
|
marks: node.marks?.filter((mark) => decorators2.includes(mark))
|
|
@@ -4114,7 +4100,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4114
4100
|
if (editor.isTextSpan(child)) {
|
|
4115
4101
|
const marks = child.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !node.markDefs?.find((def) => def._key === mark));
|
|
4116
4102
|
if (orphanedAnnotations.length > 0) {
|
|
4117
|
-
debug$
|
|
4103
|
+
debug$a("Removing orphaned annotations from span node"), editorActor.send({
|
|
4118
4104
|
type: "normalizing"
|
|
4119
4105
|
}), slate.Transforms.setNodes(editor, {
|
|
4120
4106
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -4132,7 +4118,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4132
4118
|
if (editor.isTextBlock(block)) {
|
|
4133
4119
|
const decorators2 = types2.decorators.map((decorator) => decorator.value), marks = node.marks ?? [], orphanedAnnotations = marks.filter((mark) => !decorators2.includes(mark) && !block.markDefs?.find((def) => def._key === mark));
|
|
4134
4120
|
if (orphanedAnnotations.length > 0) {
|
|
4135
|
-
debug$
|
|
4121
|
+
debug$a("Removing orphaned annotations from span node"), editorActor.send({
|
|
4136
4122
|
type: "normalizing"
|
|
4137
4123
|
}), slate.Transforms.setNodes(editor, {
|
|
4138
4124
|
marks: marks.filter((mark) => !orphanedAnnotations.includes(mark))
|
|
@@ -4150,7 +4136,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4150
4136
|
for (const markDef of markDefs)
|
|
4151
4137
|
markDefKeys.has(markDef._key) || (markDefKeys.add(markDef._key), newMarkDefs.push(markDef));
|
|
4152
4138
|
if (markDefs.length !== newMarkDefs.length) {
|
|
4153
|
-
debug$
|
|
4139
|
+
debug$a("Removing duplicate markDefs"), editorActor.send({
|
|
4154
4140
|
type: "normalizing"
|
|
4155
4141
|
}), slate.Transforms.setNodes(editor, {
|
|
4156
4142
|
markDefs: newMarkDefs
|
|
@@ -4165,7 +4151,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4165
4151
|
if (editor.isTextBlock(node) && !editor.operations.some((op) => op.type === "merge_node" && "markDefs" in op.properties && op.path.length === 1)) {
|
|
4166
4152
|
const newMarkDefs = (node.markDefs || []).filter((def) => node.children.find((child) => slate.Text.isText(child) && Array.isArray(child.marks) && child.marks.includes(def._key)));
|
|
4167
4153
|
if (node.markDefs && !isEqual__default.default(newMarkDefs, node.markDefs)) {
|
|
4168
|
-
debug$
|
|
4154
|
+
debug$a("Removing markDef not in use"), editorActor.send({
|
|
4169
4155
|
type: "normalizing"
|
|
4170
4156
|
}), slate.Transforms.setNodes(editor, {
|
|
4171
4157
|
markDefs: newMarkDefs
|
|
@@ -4382,7 +4368,7 @@ function createWithPortableTextMarkModel(editorActor, types2) {
|
|
|
4382
4368
|
const [targetBlock, targetPath] = slate.Editor.node(editor, [op.path[0] - 1]);
|
|
4383
4369
|
if (editor.isTextBlock(targetBlock)) {
|
|
4384
4370
|
const oldDefs = Array.isArray(targetBlock.markDefs) && targetBlock.markDefs || [], newMarkDefs = uniq__default.default([...oldDefs, ...op.properties.markDefs]);
|
|
4385
|
-
debug$
|
|
4371
|
+
debug$a("Copying markDefs over to merged block", op), slate.Transforms.setNodes(editor, {
|
|
4386
4372
|
markDefs: newMarkDefs
|
|
4387
4373
|
}, {
|
|
4388
4374
|
at: targetPath,
|
|
@@ -4534,7 +4520,7 @@ const toggleDecoratorActionImplementation = ({
|
|
|
4534
4520
|
decorator: action.decorator
|
|
4535
4521
|
}
|
|
4536
4522
|
});
|
|
4537
|
-
}, debug$
|
|
4523
|
+
}, debug$9 = debugWithName("plugin:withPortableTextSelections"), debugVerbose = debug$9.enabled && !1;
|
|
4538
4524
|
function createWithPortableTextSelections(editorActor, types2) {
|
|
4539
4525
|
let prevSelection = null;
|
|
4540
4526
|
return function(editor) {
|
|
@@ -4550,7 +4536,7 @@ function createWithPortableTextSelections(editorActor, types2) {
|
|
|
4550
4536
|
ptRange = toPortableTextRange(value, editor.selection, types2), SLATE_TO_PORTABLE_TEXT_RANGE.set(editor.selection, ptRange);
|
|
4551
4537
|
}
|
|
4552
4538
|
}
|
|
4553
|
-
debugVerbose
|
|
4539
|
+
debugVerbose && debug$9(`Emitting selection ${JSON.stringify(ptRange || null)} (${JSON.stringify(editor.selection)})`), ptRange ? editorActor.send({
|
|
4554
4540
|
type: "selection",
|
|
4555
4541
|
selection: ptRange
|
|
4556
4542
|
}) : editorActor.send({
|
|
@@ -4568,7 +4554,7 @@ function createWithPortableTextSelections(editorActor, types2) {
|
|
|
4568
4554
|
}, editor;
|
|
4569
4555
|
};
|
|
4570
4556
|
}
|
|
4571
|
-
const debug$
|
|
4557
|
+
const debug$8 = debugWithName("plugin:withSchemaTypes");
|
|
4572
4558
|
function createWithSchemaTypes({
|
|
4573
4559
|
editorActor,
|
|
4574
4560
|
schemaTypes
|
|
@@ -4581,7 +4567,7 @@ function createWithSchemaTypes({
|
|
|
4581
4567
|
return editor.normalizeNode = (entry) => {
|
|
4582
4568
|
const [node, path] = entry;
|
|
4583
4569
|
if (node._type === void 0 && path.length === 2) {
|
|
4584
|
-
debug$
|
|
4570
|
+
debug$8("Setting span type on text node without a type");
|
|
4585
4571
|
const span = node, key = span._key || editorActor.getSnapshot().context.keyGenerator();
|
|
4586
4572
|
editorActor.send({
|
|
4587
4573
|
type: "normalizing"
|
|
@@ -4597,7 +4583,7 @@ function createWithSchemaTypes({
|
|
|
4597
4583
|
return;
|
|
4598
4584
|
}
|
|
4599
4585
|
if (node._key === void 0 && (path.length === 1 || path.length === 2)) {
|
|
4600
|
-
debug$
|
|
4586
|
+
debug$8("Setting missing key on child node without a key");
|
|
4601
4587
|
const key = editorActor.getSnapshot().context.keyGenerator();
|
|
4602
4588
|
editorActor.send({
|
|
4603
4589
|
type: "normalizing"
|
|
@@ -4614,7 +4600,7 @@ function createWithSchemaTypes({
|
|
|
4614
4600
|
}, editor;
|
|
4615
4601
|
};
|
|
4616
4602
|
}
|
|
4617
|
-
const debug$
|
|
4603
|
+
const debug$7 = debugWithName("plugin:withUtils");
|
|
4618
4604
|
function createWithUtils({
|
|
4619
4605
|
editorActor,
|
|
4620
4606
|
schemaTypes
|
|
@@ -4629,14 +4615,14 @@ function createWithUtils({
|
|
|
4629
4615
|
depth: 2
|
|
4630
4616
|
});
|
|
4631
4617
|
if (!textNode || !slate.Text.isText(textNode) || textNode.text.length === 0) {
|
|
4632
|
-
debug$
|
|
4618
|
+
debug$7("pteExpandToWord: Can't expand to word here");
|
|
4633
4619
|
return;
|
|
4634
4620
|
}
|
|
4635
4621
|
const {
|
|
4636
4622
|
focus
|
|
4637
4623
|
} = selection, focusOffset = focus.offset, charsBefore = textNode.text.slice(0, focusOffset), charsAfter = textNode.text.slice(focusOffset, -1), isEmpty = (str) => str.match(/\s/g), whiteSpaceBeforeIndex = charsBefore.split("").reverse().findIndex((str) => isEmpty(str)), newStartOffset = whiteSpaceBeforeIndex > -1 ? charsBefore.length - whiteSpaceBeforeIndex : 0, whiteSpaceAfterIndex = charsAfter.split("").findIndex((obj) => isEmpty(obj)), newEndOffset = charsBefore.length + (whiteSpaceAfterIndex > -1 ? whiteSpaceAfterIndex : charsAfter.length + 1);
|
|
4638
4624
|
if (!(newStartOffset === newEndOffset || Number.isNaN(newStartOffset) || Number.isNaN(newEndOffset))) {
|
|
4639
|
-
debug$
|
|
4625
|
+
debug$7("pteExpandToWord: Expanding to focused word"), slate.Transforms.setSelection(editor, {
|
|
4640
4626
|
anchor: {
|
|
4641
4627
|
...selection.anchor,
|
|
4642
4628
|
offset: newStartOffset
|
|
@@ -4648,7 +4634,7 @@ function createWithUtils({
|
|
|
4648
4634
|
});
|
|
4649
4635
|
return;
|
|
4650
4636
|
}
|
|
4651
|
-
debug$
|
|
4637
|
+
debug$7("pteExpandToWord: Can't expand to word here");
|
|
4652
4638
|
}
|
|
4653
4639
|
}, editor.pteCreateTextBlock = (options) => toSlateValue([{
|
|
4654
4640
|
_type: schemaTypes.block.name,
|
|
@@ -4674,16 +4660,10 @@ function createWithUtils({
|
|
|
4674
4660
|
})[0], editor;
|
|
4675
4661
|
};
|
|
4676
4662
|
}
|
|
4677
|
-
const
|
|
4663
|
+
const withPlugins = (editor, options) => {
|
|
4678
4664
|
const e = editor, {
|
|
4679
4665
|
editorActor
|
|
4680
|
-
} = options, schemaTypes = editorActor.getSnapshot().context.schema
|
|
4681
|
-
e.destroy ? e.destroy() : originalFnMap.set(e, {
|
|
4682
|
-
apply: e.apply,
|
|
4683
|
-
onChange: e.onChange,
|
|
4684
|
-
normalizeNode: e.normalizeNode
|
|
4685
|
-
});
|
|
4686
|
-
const operationToPatches = createOperationToPatches(schemaTypes), withObjectKeys = createWithObjectKeys(editorActor, schemaTypes), withSchemaTypes = createWithSchemaTypes({
|
|
4666
|
+
} = options, schemaTypes = editorActor.getSnapshot().context.schema, operationToPatches = createOperationToPatches(schemaTypes), withObjectKeys = createWithObjectKeys(editorActor, schemaTypes), withSchemaTypes = createWithSchemaTypes({
|
|
4687
4667
|
editorActor,
|
|
4688
4668
|
schemaTypes
|
|
4689
4669
|
}), withPatches = createWithPatches({
|
|
@@ -4698,38 +4678,21 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
|
|
|
4698
4678
|
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor, schemaTypes), withPortableTextBlockStyle = createWithPortableTextBlockStyle(editorActor, schemaTypes), withPlaceholderBlock = createWithPlaceholderBlock(editorActor), withUtils = createWithUtils({
|
|
4699
4679
|
editorActor,
|
|
4700
4680
|
schemaTypes
|
|
4701
|
-
}), withPortableTextSelections = createWithPortableTextSelections(editorActor, schemaTypes)
|
|
4702
|
-
return
|
|
4703
|
-
|
|
4704
|
-
if (!originalFunctions)
|
|
4705
|
-
throw new Error("Could not find pristine versions of editor functions");
|
|
4706
|
-
e.apply = originalFunctions.apply, e.history = {
|
|
4707
|
-
undos: [],
|
|
4708
|
-
redos: []
|
|
4709
|
-
}, e.normalizeNode = originalFunctions.normalizeNode, e.onChange = originalFunctions.onChange;
|
|
4710
|
-
}, withEventListeners(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPortableTextLists(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e))))))))))));
|
|
4711
|
-
}, debug$7 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
|
|
4681
|
+
}), withPortableTextSelections = createWithPortableTextSelections(editorActor, schemaTypes);
|
|
4682
|
+
return createWithEventListeners(editorActor, options.subscriptions)(withSchemaTypes(withObjectKeys(withPortableTextMarkModel(withPortableTextBlockStyle(withPortableTextLists(withPlaceholderBlock(withUtils(withMaxBlocks(withUndoRedo(withPatches(withPortableTextSelections(e))))))))))));
|
|
4683
|
+
}, debug$6 = debugWithName("component:PortableTextEditor:SlateContainer"), slateEditors = /* @__PURE__ */ new WeakMap();
|
|
4712
4684
|
function createSlateEditor(config) {
|
|
4713
4685
|
const existingSlateEditor = slateEditors.get(config.editorActor);
|
|
4714
4686
|
if (existingSlateEditor)
|
|
4715
|
-
return debug$
|
|
4716
|
-
debug$
|
|
4717
|
-
|
|
4718
|
-
const instance = withPlugins(slateReact.withReact(slate.createEditor()), {
|
|
4687
|
+
return debug$6("Reusing existing Slate editor instance", config.editorActor.id), existingSlateEditor;
|
|
4688
|
+
debug$6("Creating new Slate editor instance", config.editorActor.id);
|
|
4689
|
+
const unsubscriptions = [], subscriptions = [], instance = withPlugins(slateReact.withReact(slate.createEditor()), {
|
|
4719
4690
|
editorActor: config.editorActor,
|
|
4720
4691
|
subscriptions
|
|
4721
4692
|
});
|
|
4722
4693
|
KEY_TO_VALUE_ELEMENT.set(instance, {}), KEY_TO_SLATE_ELEMENT.set(instance, {});
|
|
4723
4694
|
for (const subscription of subscriptions)
|
|
4724
4695
|
unsubscriptions.push(subscription());
|
|
4725
|
-
config.editorActor.subscribe((snapshot) => {
|
|
4726
|
-
if (snapshot.status !== "active") {
|
|
4727
|
-
debug$7("Destroying Slate editor"), instance.destroy();
|
|
4728
|
-
for (const unsubscribe of unsubscriptions)
|
|
4729
|
-
unsubscribe();
|
|
4730
|
-
subscriptions = [], unsubscriptions = [];
|
|
4731
|
-
}
|
|
4732
|
-
});
|
|
4733
4696
|
const initialValue = [instance.pteCreateTextBlock({
|
|
4734
4697
|
decorators: []
|
|
4735
4698
|
})], slateEditor = {
|
|
@@ -4738,7 +4701,7 @@ function createSlateEditor(config) {
|
|
|
4738
4701
|
};
|
|
4739
4702
|
return slateEditors.set(config.editorActor, slateEditor), slateEditor;
|
|
4740
4703
|
}
|
|
4741
|
-
const
|
|
4704
|
+
const debug$5 = debugWithName("API:editable");
|
|
4742
4705
|
function createEditableAPI(editor, editorActor) {
|
|
4743
4706
|
const types2 = editorActor.getSnapshot().context.schema;
|
|
4744
4707
|
return {
|
|
@@ -4819,7 +4782,7 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4819
4782
|
}], {
|
|
4820
4783
|
schemaTypes: editorActor.getSnapshot().context.schema
|
|
4821
4784
|
})[0].children[0], focusChildPath = editor.selection.focus.path.slice(0, 2), isSpanNode = child._type === types2.span.name, focusNode = slate.Node.get(editor, focusChildPath);
|
|
4822
|
-
return isSpanNode && focusNode._type !== types2.span.name && (debug$
|
|
4785
|
+
return isSpanNode && focusNode._type !== types2.span.name && (debug$5("Inserting span child next to inline object child, moving selection + 1"), editor.move({
|
|
4823
4786
|
distance: 1,
|
|
4824
4787
|
unit: "character"
|
|
4825
4788
|
})), slate.Transforms.insertNodes(editor, child, {
|
|
@@ -4951,18 +4914,18 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4951
4914
|
throw new Error("Invalid range");
|
|
4952
4915
|
if (range) {
|
|
4953
4916
|
if (!options?.mode || options?.mode === "selected") {
|
|
4954
|
-
debug$
|
|
4917
|
+
debug$5("Deleting content in selection"), slate.Transforms.delete(editor, {
|
|
4955
4918
|
at: range,
|
|
4956
4919
|
hanging: !0,
|
|
4957
4920
|
voids: !0
|
|
4958
4921
|
}), editor.onChange();
|
|
4959
4922
|
return;
|
|
4960
4923
|
}
|
|
4961
|
-
options?.mode === "blocks" && (debug$
|
|
4924
|
+
options?.mode === "blocks" && (debug$5("Deleting blocks touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
4962
4925
|
at: range,
|
|
4963
4926
|
voids: !0,
|
|
4964
4927
|
match: (node) => editor.isTextBlock(node) || !editor.isTextBlock(node) && slate.Element.isElement(node)
|
|
4965
|
-
})), options?.mode === "children" && (debug$
|
|
4928
|
+
})), options?.mode === "children" && (debug$5("Deleting children touched by selection"), slate.Transforms.removeNodes(editor, {
|
|
4966
4929
|
at: range,
|
|
4967
4930
|
voids: !0,
|
|
4968
4931
|
match: (node) => node._type === types2.span.name || // Text children
|
|
@@ -5125,7 +5088,7 @@ const addAnnotationActionImplementation = ({
|
|
|
5125
5088
|
action
|
|
5126
5089
|
}) => {
|
|
5127
5090
|
const editor = action.editor;
|
|
5128
|
-
if (debug$
|
|
5091
|
+
if (debug$5("Removing annotation", action.annotation.name), !!editor.selection)
|
|
5129
5092
|
if (slate.Range.isCollapsed(editor.selection)) {
|
|
5130
5093
|
const [block, blockPath] = slate.Editor.node(editor, editor.selection, {
|
|
5131
5094
|
depth: 1
|
|
@@ -5778,8 +5741,8 @@ const editorMachine = xstate.setup({
|
|
|
5778
5741
|
keyGenerator: input.keyGenerator,
|
|
5779
5742
|
pendingEvents: [],
|
|
5780
5743
|
schema: input.schema,
|
|
5781
|
-
readOnly: !1,
|
|
5782
|
-
maxBlocks:
|
|
5744
|
+
readOnly: input.readOnly ?? !1,
|
|
5745
|
+
maxBlocks: input.maxBlocks,
|
|
5783
5746
|
value: input.value
|
|
5784
5747
|
}),
|
|
5785
5748
|
on: {
|
|
@@ -5884,11 +5847,16 @@ const editorMachine = xstate.setup({
|
|
|
5884
5847
|
})
|
|
5885
5848
|
},
|
|
5886
5849
|
"toggle readOnly": {
|
|
5887
|
-
actions: xstate.assign({
|
|
5850
|
+
actions: [xstate.assign({
|
|
5888
5851
|
readOnly: ({
|
|
5889
5852
|
context
|
|
5890
5853
|
}) => !context.readOnly
|
|
5891
|
-
})
|
|
5854
|
+
}), xstate.emit(({
|
|
5855
|
+
context
|
|
5856
|
+
}) => ({
|
|
5857
|
+
type: "readOnly toggled",
|
|
5858
|
+
readOnly: context.readOnly
|
|
5859
|
+
}))]
|
|
5892
5860
|
},
|
|
5893
5861
|
"update maxBlocks": {
|
|
5894
5862
|
actions: xstate.assign({
|
|
@@ -5979,50 +5947,65 @@ const editorMachine = xstate.setup({
|
|
|
5979
5947
|
}
|
|
5980
5948
|
}
|
|
5981
5949
|
}
|
|
5982
|
-
})
|
|
5983
|
-
|
|
5984
|
-
|
|
5985
|
-
|
|
5986
|
-
|
|
5987
|
-
|
|
5988
|
-
|
|
5989
|
-
|
|
5990
|
-
|
|
5991
|
-
|
|
5992
|
-
|
|
5993
|
-
|
|
5994
|
-
|
|
5995
|
-
|
|
5996
|
-
|
|
5997
|
-
|
|
5998
|
-
|
|
5999
|
-
|
|
6000
|
-
|
|
6001
|
-
|
|
6002
|
-
|
|
6003
|
-
|
|
6004
|
-
}
|
|
6005
|
-
const defaultKeyGenerator = () => randomKey(12), getByteHexTable = /* @__PURE__ */ (() => {
|
|
6006
|
-
let table;
|
|
6007
|
-
return () => {
|
|
6008
|
-
if (table)
|
|
6009
|
-
return table;
|
|
6010
|
-
table = [];
|
|
6011
|
-
for (let i = 0; i < 256; ++i)
|
|
6012
|
-
table[i] = (i + 256).toString(16).slice(1);
|
|
6013
|
-
return table;
|
|
5950
|
+
});
|
|
5951
|
+
function createEditor(config) {
|
|
5952
|
+
const editorActor = xstate.createActor(editorMachine, {
|
|
5953
|
+
input: editorConfigToMachineInput(config)
|
|
5954
|
+
});
|
|
5955
|
+
editorActor.start();
|
|
5956
|
+
const slateEditor = createSlateEditor({
|
|
5957
|
+
editorActor
|
|
5958
|
+
}), editable = createEditableAPI(slateEditor.instance, editorActor);
|
|
5959
|
+
return {
|
|
5960
|
+
send: (event) => {
|
|
5961
|
+
editorActor.send(event);
|
|
5962
|
+
},
|
|
5963
|
+
on: (event, listener) => editorActor.on(
|
|
5964
|
+
event,
|
|
5965
|
+
// @ts-ignore
|
|
5966
|
+
listener
|
|
5967
|
+
),
|
|
5968
|
+
editable,
|
|
5969
|
+
_internal: {
|
|
5970
|
+
editorActor,
|
|
5971
|
+
slateEditor
|
|
5972
|
+
}
|
|
6014
5973
|
};
|
|
6015
|
-
})();
|
|
6016
|
-
function whatwgRNG(length = 16) {
|
|
6017
|
-
const rnds8 = new Uint8Array(length);
|
|
6018
|
-
return getRandomValues__default.default(rnds8), rnds8;
|
|
6019
5974
|
}
|
|
6020
|
-
function
|
|
6021
|
-
const
|
|
6022
|
-
|
|
5975
|
+
function useEditor(config) {
|
|
5976
|
+
const editorActor = react.useActorRef(editorMachine, {
|
|
5977
|
+
input: editorConfigToMachineInput(config)
|
|
5978
|
+
}), slateEditor = createSlateEditor({
|
|
5979
|
+
editorActor
|
|
5980
|
+
}), editable = React.useMemo(() => createEditableAPI(slateEditor.instance, editorActor), [slateEditor.instance, editorActor]), send = React.useCallback((event) => {
|
|
5981
|
+
editorActor.send(event);
|
|
5982
|
+
}, [editorActor]), on = React.useCallback((event_0, listener) => editorActor.on(
|
|
5983
|
+
event_0,
|
|
5984
|
+
// @ts-ignore
|
|
5985
|
+
listener
|
|
5986
|
+
), [editorActor]);
|
|
5987
|
+
return React.useMemo(() => ({
|
|
5988
|
+
send,
|
|
5989
|
+
on,
|
|
5990
|
+
editable,
|
|
5991
|
+
_internal: {
|
|
5992
|
+
editorActor,
|
|
5993
|
+
slateEditor
|
|
5994
|
+
}
|
|
5995
|
+
}), [send, on, editable, editorActor, slateEditor]);
|
|
5996
|
+
}
|
|
5997
|
+
function editorConfigToMachineInput(config) {
|
|
5998
|
+
return {
|
|
5999
|
+
behaviors: config.behaviors,
|
|
6000
|
+
keyGenerator: config.keyGenerator ?? defaultKeyGenerator,
|
|
6001
|
+
maxBlocks: config.maxBlocks,
|
|
6002
|
+
readOnly: config.readOnly,
|
|
6003
|
+
schema: config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : getPortableTextMemberSchemaTypes(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)),
|
|
6004
|
+
value: config.initialValue
|
|
6005
|
+
};
|
|
6023
6006
|
}
|
|
6024
6007
|
const debug$4 = debugWithName("component:PortableTextEditor");
|
|
6025
|
-
class PortableTextEditor extends
|
|
6008
|
+
class PortableTextEditor extends React.Component {
|
|
6026
6009
|
static displayName = "PortableTextEditor";
|
|
6027
6010
|
/**
|
|
6028
6011
|
* An observable of all the editor changes.
|
|
@@ -6032,66 +6015,49 @@ class PortableTextEditor extends react.Component {
|
|
|
6032
6015
|
* A lookup table for all the relevant schema types for this portable text type.
|
|
6033
6016
|
*/
|
|
6034
6017
|
/**
|
|
6018
|
+
* The editor instance
|
|
6019
|
+
*/
|
|
6020
|
+
/*
|
|
6035
6021
|
* The editor API (currently implemented with Slate).
|
|
6036
6022
|
*/
|
|
6037
6023
|
constructor(props) {
|
|
6038
|
-
|
|
6039
|
-
|
|
6040
|
-
|
|
6041
|
-
|
|
6042
|
-
|
|
6043
|
-
|
|
6044
|
-
|
|
6045
|
-
input: {
|
|
6046
|
-
keyGenerator: props.keyGenerator || defaultKeyGenerator,
|
|
6047
|
-
schema: this.schemaTypes,
|
|
6048
|
-
value: props.value
|
|
6049
|
-
}
|
|
6050
|
-
}), this.editorActor.start(), this.slateEditor = createSlateEditor({
|
|
6051
|
-
editorActor: this.editorActor
|
|
6052
|
-
}), props.readOnly && this.editorActor.send({
|
|
6053
|
-
type: "toggle readOnly"
|
|
6054
|
-
}), props.maxBlocks && this.editorActor.send({
|
|
6055
|
-
type: "update maxBlocks",
|
|
6056
|
-
maxBlocks: props.maxBlocks === void 0 ? void 0 : Number.parseInt(props.maxBlocks.toString(), 10)
|
|
6057
|
-
});
|
|
6058
|
-
}
|
|
6059
|
-
this.editable = createEditableAPI(this.slateEditor.instance, this.editorActor);
|
|
6024
|
+
super(props), props.editor ? this.editor = props.editor : this.editor = createEditor({
|
|
6025
|
+
keyGenerator: props.keyGenerator ?? defaultKeyGenerator,
|
|
6026
|
+
schema: props.schemaType,
|
|
6027
|
+
initialValue: props.value,
|
|
6028
|
+
maxBlocks: props.maxBlocks === void 0 ? void 0 : Number.parseInt(props.maxBlocks.toString(), 10),
|
|
6029
|
+
readOnly: props.readOnly
|
|
6030
|
+
}), this.schemaTypes = this.editor._internal.editorActor.getSnapshot().context.schema, this.editable = this.editor.editable;
|
|
6060
6031
|
}
|
|
6061
6032
|
componentDidUpdate(prevProps) {
|
|
6062
|
-
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = getPortableTextMemberSchemaTypes(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editorActor.send({
|
|
6033
|
+
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = getPortableTextMemberSchemaTypes(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editor._internal.editorActor.send({
|
|
6063
6034
|
type: "update schema",
|
|
6064
6035
|
schema: this.schemaTypes
|
|
6065
|
-
})), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editorActor.send({
|
|
6036
|
+
})), !this.props.editor && !prevProps.editor && (this.props.readOnly !== prevProps.readOnly && this.editor._internal.editorActor.send({
|
|
6066
6037
|
type: "toggle readOnly"
|
|
6067
|
-
}), this.props.maxBlocks !== prevProps.maxBlocks && this.editorActor.send({
|
|
6038
|
+
}), this.props.maxBlocks !== prevProps.maxBlocks && this.editor._internal.editorActor.send({
|
|
6068
6039
|
type: "update maxBlocks",
|
|
6069
6040
|
maxBlocks: this.props.maxBlocks === void 0 ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10)
|
|
6070
|
-
}), this.props.value !== prevProps.value && this.editorActor.send({
|
|
6041
|
+
}), this.props.value !== prevProps.value && this.editor._internal.editorActor.send({
|
|
6071
6042
|
type: "update value",
|
|
6072
6043
|
value: this.props.value
|
|
6073
6044
|
}), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this));
|
|
6074
6045
|
}
|
|
6075
6046
|
setEditable = (editable) => {
|
|
6076
|
-
this.editable = {
|
|
6077
|
-
...this.editable,
|
|
6047
|
+
this.editor.editable = {
|
|
6048
|
+
...this.editor.editable,
|
|
6078
6049
|
...editable
|
|
6079
6050
|
};
|
|
6080
6051
|
};
|
|
6081
|
-
getValue = () => {
|
|
6082
|
-
if (this.editable)
|
|
6083
|
-
return this.editable.getValue();
|
|
6084
|
-
};
|
|
6085
6052
|
render() {
|
|
6086
6053
|
const legacyPatches = this.props.editor ? void 0 : this.props.incomingPatches$ ?? this.props.patches$;
|
|
6087
6054
|
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
6088
|
-
legacyPatches ? /* @__PURE__ */ jsxRuntime.jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editorActor, patches$: legacyPatches }) : null,
|
|
6089
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
6090
|
-
|
|
6091
|
-
|
|
6092
|
-
|
|
6093
|
-
|
|
6094
|
-
] }) }) }) })
|
|
6055
|
+
legacyPatches ? /* @__PURE__ */ jsxRuntime.jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editor._internal.editorActor, patches$: legacyPatches }) : null,
|
|
6056
|
+
/* @__PURE__ */ jsxRuntime.jsx(RouteEventsToChanges, { editorActor: this.editor._internal.editorActor, onChange: (change) => {
|
|
6057
|
+
this.props.editor || this.props.onChange(change), this.change$.next(change);
|
|
6058
|
+
} }),
|
|
6059
|
+
/* @__PURE__ */ jsxRuntime.jsx(Synchronizer, { editorActor: this.editor._internal.editorActor, getValue: this.editor.editable.getValue, portableTextEditor: this, slateEditor: this.editor._internal.slateEditor.instance }),
|
|
6060
|
+
/* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: this.editor._internal.editorActor, children: /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: this.editor._internal.slateEditor.instance, initialValue: this.editor._internal.slateEditor.initialValue, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionProvider, { editorActor: this.editor._internal.editorActor, children: this.props.children }) }) }) })
|
|
6095
6061
|
] });
|
|
6096
6062
|
}
|
|
6097
6063
|
// Static API methods
|
|
@@ -6157,7 +6123,80 @@ function RoutePatchesObservableToEditorActor(props) {
|
|
|
6157
6123
|
return () => {
|
|
6158
6124
|
subscription.unsubscribe();
|
|
6159
6125
|
};
|
|
6160
|
-
}, t1 = [props.editorActor, props.patches$], $[0] = props.editorActor, $[1] = props.patches$, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]),
|
|
6126
|
+
}, t1 = [props.editorActor, props.patches$], $[0] = props.editorActor, $[1] = props.patches$, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), React.useEffect(t0, t1), null;
|
|
6127
|
+
}
|
|
6128
|
+
function RouteEventsToChanges(props) {
|
|
6129
|
+
const $ = reactCompilerRuntime.c(6);
|
|
6130
|
+
let t0;
|
|
6131
|
+
$[0] !== props ? (t0 = (change) => props.onChange(change), $[0] = props, $[1] = t0) : t0 = $[1];
|
|
6132
|
+
const handleChange = useEffectEvent.useEffectEvent(t0);
|
|
6133
|
+
let t1, t2;
|
|
6134
|
+
return $[2] !== handleChange || $[3] !== props.editorActor ? (t1 = () => {
|
|
6135
|
+
debug$4("Subscribing to editor changes");
|
|
6136
|
+
const sub = props.editorActor.on("*", (event) => {
|
|
6137
|
+
bb5: switch (event.type) {
|
|
6138
|
+
case "patch": {
|
|
6139
|
+
handleChange(event);
|
|
6140
|
+
break bb5;
|
|
6141
|
+
}
|
|
6142
|
+
case "loading": {
|
|
6143
|
+
handleChange({
|
|
6144
|
+
type: "loading",
|
|
6145
|
+
isLoading: !0
|
|
6146
|
+
});
|
|
6147
|
+
break bb5;
|
|
6148
|
+
}
|
|
6149
|
+
case "done loading": {
|
|
6150
|
+
handleChange({
|
|
6151
|
+
type: "loading",
|
|
6152
|
+
isLoading: !1
|
|
6153
|
+
});
|
|
6154
|
+
break bb5;
|
|
6155
|
+
}
|
|
6156
|
+
case "focused": {
|
|
6157
|
+
handleChange({
|
|
6158
|
+
type: "focus",
|
|
6159
|
+
event: event.event
|
|
6160
|
+
});
|
|
6161
|
+
break bb5;
|
|
6162
|
+
}
|
|
6163
|
+
case "value changed": {
|
|
6164
|
+
handleChange({
|
|
6165
|
+
type: "value",
|
|
6166
|
+
value: event.value
|
|
6167
|
+
});
|
|
6168
|
+
break bb5;
|
|
6169
|
+
}
|
|
6170
|
+
case "invalid value": {
|
|
6171
|
+
handleChange({
|
|
6172
|
+
type: "invalidValue",
|
|
6173
|
+
resolution: event.resolution,
|
|
6174
|
+
value: event.value
|
|
6175
|
+
});
|
|
6176
|
+
break bb5;
|
|
6177
|
+
}
|
|
6178
|
+
case "error": {
|
|
6179
|
+
handleChange({
|
|
6180
|
+
...event,
|
|
6181
|
+
level: "warning"
|
|
6182
|
+
});
|
|
6183
|
+
break bb5;
|
|
6184
|
+
}
|
|
6185
|
+
case "annotation.add":
|
|
6186
|
+
case "annotation.remove":
|
|
6187
|
+
case "annotation.toggle":
|
|
6188
|
+
case "focus":
|
|
6189
|
+
case "patches":
|
|
6190
|
+
case "readOnly toggled":
|
|
6191
|
+
break bb5;
|
|
6192
|
+
default:
|
|
6193
|
+
handleChange(event);
|
|
6194
|
+
}
|
|
6195
|
+
});
|
|
6196
|
+
return () => {
|
|
6197
|
+
debug$4("Unsubscribing to changes"), sub.unsubscribe();
|
|
6198
|
+
};
|
|
6199
|
+
}, t2 = [props.editorActor, handleChange], $[2] = handleChange, $[3] = props.editorActor, $[4] = t1, $[5] = t2) : (t1 = $[4], t2 = $[5]), React.useEffect(t1, t2), null;
|
|
6161
6200
|
}
|
|
6162
6201
|
const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
|
|
6163
6202
|
const {
|
|
@@ -6169,22 +6208,22 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6169
6208
|
renderChild,
|
|
6170
6209
|
renderDecorator,
|
|
6171
6210
|
renderAnnotation
|
|
6172
|
-
} = props, spanRef =
|
|
6211
|
+
} = props, spanRef = React.useRef(null), portableTextEditor = usePortableTextEditor(), blockSelected = slateReact.useSelected(), [focused, setFocused] = React.useState(!1), [selected, setSelected] = React.useState(!1), block = children.props.parent, path = React.useMemo(() => block ? [{
|
|
6173
6212
|
_key: block?._key
|
|
6174
6213
|
}, "children", {
|
|
6175
6214
|
_key: leaf._key
|
|
6176
|
-
}] : [], [block, leaf._key]), decoratorValues =
|
|
6177
|
-
|
|
6215
|
+
}] : [], [block, leaf._key]), decoratorValues = React.useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = React.useMemo(() => uniq__default.default((leaf.marks || EMPTY_MARKS).filter((mark) => decoratorValues.includes(mark))), [decoratorValues, leaf.marks]), annotationMarks = Array.isArray(leaf.marks) ? leaf.marks : EMPTY_MARKS, annotations = React.useMemo(() => annotationMarks.map((mark_0) => !decoratorValues.includes(mark_0) && block?.markDefs?.find((def) => def._key === mark_0)).filter(Boolean), [annotationMarks, block, decoratorValues]), shouldTrackSelectionAndFocus = annotations.length > 0 && blockSelected;
|
|
6216
|
+
React.useEffect(() => {
|
|
6178
6217
|
if (!shouldTrackSelectionAndFocus) {
|
|
6179
6218
|
setFocused(!1);
|
|
6180
6219
|
return;
|
|
6181
6220
|
}
|
|
6182
6221
|
const sel = PortableTextEditor.getSelection(portableTextEditor);
|
|
6183
|
-
sel && isEqual__default.default(sel.focus.path, path) && PortableTextEditor.isCollapsedSelection(portableTextEditor) &&
|
|
6222
|
+
sel && isEqual__default.default(sel.focus.path, path) && PortableTextEditor.isCollapsedSelection(portableTextEditor) && React.startTransition(() => {
|
|
6184
6223
|
setFocused(!0);
|
|
6185
6224
|
});
|
|
6186
6225
|
}, [shouldTrackSelectionAndFocus, path, portableTextEditor]);
|
|
6187
|
-
const setSelectedFromRange =
|
|
6226
|
+
const setSelectedFromRange = React.useCallback(() => {
|
|
6188
6227
|
if (!shouldTrackSelectionAndFocus)
|
|
6189
6228
|
return;
|
|
6190
6229
|
debug$3("Setting selection and focus from range");
|
|
@@ -6199,7 +6238,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6199
6238
|
} else
|
|
6200
6239
|
setSelected(!1);
|
|
6201
6240
|
}, [shouldTrackSelectionAndFocus]);
|
|
6202
|
-
|
|
6241
|
+
React.useEffect(() => {
|
|
6203
6242
|
if (!shouldTrackSelectionAndFocus)
|
|
6204
6243
|
return;
|
|
6205
6244
|
const onBlur = editorActor.on("blur", () => {
|
|
@@ -6213,8 +6252,8 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6213
6252
|
return () => {
|
|
6214
6253
|
onBlur.unsubscribe(), onFocus.unsubscribe(), onSelection.unsubscribe();
|
|
6215
6254
|
};
|
|
6216
|
-
}, [editorActor, path, portableTextEditor, setSelectedFromRange, shouldTrackSelectionAndFocus]),
|
|
6217
|
-
const content =
|
|
6255
|
+
}, [editorActor, path, portableTextEditor, setSelectedFromRange, shouldTrackSelectionAndFocus]), React.useEffect(() => setSelectedFromRange(), [setSelectedFromRange]);
|
|
6256
|
+
const content = React.useMemo(() => {
|
|
6218
6257
|
let returnedChildren = children;
|
|
6219
6258
|
if (slate.Text.isText(leaf) && leaf._type === schemaTypes.span.name && (marks.forEach((mark_1) => {
|
|
6220
6259
|
const schemaType = schemaTypes.decorators.find((dec_0) => dec_0.value === mark_1);
|
|
@@ -6280,7 +6319,7 @@ const debug$3 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
6280
6319
|
}
|
|
6281
6320
|
return returnedChildren;
|
|
6282
6321
|
}, [annotations, block, children, focused, leaf, marks, path, renderAnnotation, renderChild, renderDecorator, schemaTypes.annotations, schemaTypes.decorators, schemaTypes.span, selected]);
|
|
6283
|
-
return
|
|
6322
|
+
return React.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span", { ...attributes, ref: spanRef, children: content }, leaf._key), [leaf, attributes, content]);
|
|
6284
6323
|
};
|
|
6285
6324
|
Leaf.displayName = "Leaf";
|
|
6286
6325
|
const debug$2 = debugWithName("plugin:withHotKeys"), DEFAULT_HOTKEYS = {
|
|
@@ -6593,7 +6632,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6593
6632
|
pointerEvents: "none",
|
|
6594
6633
|
left: 0,
|
|
6595
6634
|
right: 0
|
|
6596
|
-
}, PortableTextEditable =
|
|
6635
|
+
}, PortableTextEditable = React.forwardRef(function(props, forwardedRef) {
|
|
6597
6636
|
const {
|
|
6598
6637
|
hotkeys,
|
|
6599
6638
|
onBlur,
|
|
@@ -6614,19 +6653,17 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6614
6653
|
scrollSelectionIntoView,
|
|
6615
6654
|
spellCheck,
|
|
6616
6655
|
...restProps
|
|
6617
|
-
} = props, portableTextEditor = usePortableTextEditor(), ref =
|
|
6618
|
-
|
|
6619
|
-
const rangeDecorationsRef =
|
|
6620
|
-
|
|
6621
|
-
} = portableTextEditor, slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name;
|
|
6622
|
-
react.useMemo(() => {
|
|
6656
|
+
} = props, portableTextEditor = usePortableTextEditor(), ref = React.useRef(null), [editableElement, setEditableElement] = React.useState(null), [hasInvalidValue, setHasInvalidValue] = React.useState(!1), [rangeDecorationState, setRangeDecorationsState] = React.useState([]);
|
|
6657
|
+
React.useImperativeHandle(forwardedRef, () => ref.current);
|
|
6658
|
+
const rangeDecorationsRef = React.useRef(rangeDecorations), editorActor = React.useContext(EditorActorContext), readOnly = react.useSelector(editorActor, (s) => s.context.readOnly), schemaTypes = react.useSelector(editorActor, (s_0) => s_0.context.schema), slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name;
|
|
6659
|
+
React.useMemo(() => {
|
|
6623
6660
|
const withInsertData = createWithInsertData(editorActor, schemaTypes);
|
|
6624
6661
|
if (readOnly)
|
|
6625
6662
|
return debug("Editable is in read only mode"), withInsertData(slateEditor);
|
|
6626
6663
|
const withHotKeys = createWithHotkeys(editorActor, portableTextEditor, hotkeys);
|
|
6627
6664
|
return debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor));
|
|
6628
6665
|
}, [editorActor, hotkeys, portableTextEditor, readOnly, schemaTypes, slateEditor]);
|
|
6629
|
-
const renderElement =
|
|
6666
|
+
const renderElement = React.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(Element, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = React.useCallback((lProps) => {
|
|
6630
6667
|
if (lProps.leaf._type === "span") {
|
|
6631
6668
|
let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
|
|
6632
6669
|
if (renderPlaceholder && lProps.leaf.placeholder && lProps.text.text === "")
|
|
@@ -6640,7 +6677,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6640
6677
|
})), rendered;
|
|
6641
6678
|
}
|
|
6642
6679
|
return lProps.children;
|
|
6643
|
-
}, [editorActor, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder, schemaTypes]), restoreSelectionFromProps =
|
|
6680
|
+
}, [editorActor, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder, schemaTypes]), restoreSelectionFromProps = React.useCallback(() => {
|
|
6644
6681
|
if (propsSelection) {
|
|
6645
6682
|
debug(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
6646
6683
|
const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children, blockTypeName));
|
|
@@ -6653,7 +6690,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6653
6690
|
}), slateEditor.onChange());
|
|
6654
6691
|
}
|
|
6655
6692
|
}
|
|
6656
|
-
}, [blockTypeName, editorActor, propsSelection, slateEditor]), syncRangeDecorations =
|
|
6693
|
+
}, [blockTypeName, editorActor, propsSelection, slateEditor]), syncRangeDecorations = React.useCallback((operation) => {
|
|
6657
6694
|
if (rangeDecorations && rangeDecorations.length > 0) {
|
|
6658
6695
|
const newSlateRanges = [];
|
|
6659
6696
|
if (rangeDecorations.forEach((rangeDecorationItem) => {
|
|
@@ -6686,7 +6723,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6686
6723
|
}
|
|
6687
6724
|
setRangeDecorationsState((rangeDecorationState_0) => rangeDecorationState_0.length > 0 ? [] : rangeDecorationState_0);
|
|
6688
6725
|
}, [portableTextEditor, rangeDecorations, schemaTypes, slateEditor]);
|
|
6689
|
-
|
|
6726
|
+
React.useEffect(() => {
|
|
6690
6727
|
const onReady = editorActor.on("ready", () => {
|
|
6691
6728
|
restoreSelectionFromProps();
|
|
6692
6729
|
}), onInvalidValue = editorActor.on("invalid value", () => {
|
|
@@ -6697,21 +6734,21 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6697
6734
|
return () => {
|
|
6698
6735
|
onReady.unsubscribe(), onInvalidValue.unsubscribe(), onValueChanged.unsubscribe();
|
|
6699
6736
|
};
|
|
6700
|
-
}, [editorActor, restoreSelectionFromProps]),
|
|
6737
|
+
}, [editorActor, restoreSelectionFromProps]), React.useEffect(() => {
|
|
6701
6738
|
propsSelection && !hasInvalidValue && restoreSelectionFromProps();
|
|
6702
6739
|
}, [hasInvalidValue, propsSelection, restoreSelectionFromProps]);
|
|
6703
|
-
const [syncedRangeDecorations, setSyncedRangeDecorations] =
|
|
6704
|
-
|
|
6740
|
+
const [syncedRangeDecorations, setSyncedRangeDecorations] = React.useState(!1);
|
|
6741
|
+
React.useEffect(() => {
|
|
6705
6742
|
syncedRangeDecorations || (setSyncedRangeDecorations(!0), syncRangeDecorations());
|
|
6706
|
-
}, [syncRangeDecorations, syncedRangeDecorations]),
|
|
6743
|
+
}, [syncRangeDecorations, syncedRangeDecorations]), React.useEffect(() => {
|
|
6707
6744
|
isEqual__default.default(rangeDecorations, rangeDecorationsRef.current) || syncRangeDecorations(), rangeDecorationsRef.current = rangeDecorations;
|
|
6708
|
-
}, [rangeDecorations, syncRangeDecorations]),
|
|
6745
|
+
}, [rangeDecorations, syncRangeDecorations]), React.useEffect(() => {
|
|
6709
6746
|
const teardown = withSyncRangeDecorations(slateEditor, syncRangeDecorations);
|
|
6710
6747
|
return () => teardown();
|
|
6711
6748
|
}, [slateEditor, syncRangeDecorations]);
|
|
6712
|
-
const handleCopy =
|
|
6749
|
+
const handleCopy = React.useCallback((event) => {
|
|
6713
6750
|
onCopy && onCopy(event) !== void 0 && event.preventDefault();
|
|
6714
|
-
}, [onCopy]), handlePaste =
|
|
6751
|
+
}, [onCopy]), handlePaste = React.useCallback((event_0) => {
|
|
6715
6752
|
const value_0 = PortableTextEditor.getValue(portableTextEditor), path = toPortableTextRange(value_0, slateEditor.selection, schemaTypes)?.focus.path || [], onPasteResult = onPaste?.({
|
|
6716
6753
|
event: event_0,
|
|
6717
6754
|
value: value_0,
|
|
@@ -6736,7 +6773,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6736
6773
|
},
|
|
6737
6774
|
editor: slateEditor
|
|
6738
6775
|
})), debug("No result from custom paste handler, pasting normally");
|
|
6739
|
-
}, [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor]), handleOnFocus =
|
|
6776
|
+
}, [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor]), handleOnFocus = React.useCallback((event_1) => {
|
|
6740
6777
|
if (onFocus && onFocus(event_1), !event_1.isDefaultPrevented()) {
|
|
6741
6778
|
const selection = PortableTextEditor.getSelection(portableTextEditor);
|
|
6742
6779
|
selection === null && (slate.Transforms.select(slateEditor, slate.Editor.start(slateEditor, [])), slateEditor.onChange()), editorActor.send({
|
|
@@ -6749,20 +6786,20 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6749
6786
|
selection
|
|
6750
6787
|
});
|
|
6751
6788
|
}
|
|
6752
|
-
}, [editorActor, onFocus, portableTextEditor, slateEditor]), handleClick =
|
|
6789
|
+
}, [editorActor, onFocus, portableTextEditor, slateEditor]), handleClick = React.useCallback((event_2) => {
|
|
6753
6790
|
onClick && onClick(event_2);
|
|
6754
6791
|
const focusBlockPath = slateEditor.selection ? slateEditor.selection.focus.path.slice(0, 1) : void 0, focusBlock = focusBlockPath ? slate.Node.descendant(slateEditor, focusBlockPath) : void 0, [_, lastNodePath] = slate.Node.last(slateEditor, []), lastBlockPath = lastNodePath.slice(0, 1), lastNodeFocused = focusBlockPath ? slate.Path.equals(lastBlockPath, focusBlockPath) : !1, lastBlockIsVoid = focusBlock ? !slateEditor.isTextBlock(focusBlock) : !1;
|
|
6755
6792
|
slateEditor.selection && slate.Range.isCollapsed(slateEditor.selection) && lastNodeFocused && lastBlockIsVoid && (slate.Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
|
|
6756
6793
|
decorators: []
|
|
6757
6794
|
})), slateEditor.onChange());
|
|
6758
|
-
}, [onClick, slateEditor]), handleOnBlur =
|
|
6795
|
+
}, [onClick, slateEditor]), handleOnBlur = React.useCallback((event_3) => {
|
|
6759
6796
|
onBlur && onBlur(event_3), event_3.isPropagationStopped() || editorActor.send({
|
|
6760
6797
|
type: "blur",
|
|
6761
6798
|
event: event_3
|
|
6762
6799
|
});
|
|
6763
|
-
}, [editorActor, onBlur]), handleOnBeforeInput =
|
|
6800
|
+
}, [editorActor, onBlur]), handleOnBeforeInput = React.useCallback((event_4) => {
|
|
6764
6801
|
onBeforeInput && onBeforeInput(event_4);
|
|
6765
|
-
}, [onBeforeInput]), validateSelection =
|
|
6802
|
+
}, [onBeforeInput]), validateSelection = React.useCallback(() => {
|
|
6766
6803
|
if (!slateEditor.selection)
|
|
6767
6804
|
return;
|
|
6768
6805
|
const root = slateReact.ReactEditor.findDocumentOrShadowRoot(slateEditor), {
|
|
@@ -6781,7 +6818,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6781
6818
|
debug("Could not resolve selection, selecting top document"), slate.Transforms.deselect(slateEditor), slateEditor.children.length > 0 && slate.Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
|
|
6782
6819
|
}
|
|
6783
6820
|
}, [ref, slateEditor]);
|
|
6784
|
-
|
|
6821
|
+
React.useEffect(() => {
|
|
6785
6822
|
if (editableElement) {
|
|
6786
6823
|
const mutationObserver = new MutationObserver(validateSelection);
|
|
6787
6824
|
return mutationObserver.observe(editableElement, {
|
|
@@ -6795,14 +6832,14 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6795
6832
|
};
|
|
6796
6833
|
}
|
|
6797
6834
|
}, [validateSelection, editableElement]);
|
|
6798
|
-
const handleKeyDown =
|
|
6835
|
+
const handleKeyDown = React.useCallback((event_5) => {
|
|
6799
6836
|
props.onKeyDown && props.onKeyDown(event_5), event_5.isDefaultPrevented() || slateEditor.pteWithHotKeys(event_5);
|
|
6800
|
-
}, [props, slateEditor]), scrollSelectionIntoViewToSlate =
|
|
6837
|
+
}, [props, slateEditor]), scrollSelectionIntoViewToSlate = React.useMemo(() => {
|
|
6801
6838
|
if (scrollSelectionIntoView !== void 0)
|
|
6802
6839
|
return scrollSelectionIntoView === null ? noop__default.default : (_editor, domRange) => {
|
|
6803
6840
|
scrollSelectionIntoView(portableTextEditor, domRange);
|
|
6804
6841
|
};
|
|
6805
|
-
}, [portableTextEditor, scrollSelectionIntoView]), decorate =
|
|
6842
|
+
}, [portableTextEditor, scrollSelectionIntoView]), decorate = React.useCallback(([, path_0]) => {
|
|
6806
6843
|
if (isEqualToEmptyEditor(slateEditor.children, schemaTypes))
|
|
6807
6844
|
return [{
|
|
6808
6845
|
anchor: {
|
|
@@ -6829,7 +6866,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6829
6866
|
}) || slate.Range.includes(item, path_0));
|
|
6830
6867
|
return result_1.length > 0 ? result_1 : [];
|
|
6831
6868
|
}, [slateEditor, schemaTypes, rangeDecorationState]);
|
|
6832
|
-
return
|
|
6869
|
+
return React.useEffect(() => {
|
|
6833
6870
|
ref.current = slateReact.ReactEditor.toDOMNode(slateEditor, slateEditor), setEditableElement(ref.current);
|
|
6834
6871
|
}, [slateEditor, ref]), portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsxRuntime.jsx(
|
|
6835
6872
|
slateReact.Editable,
|
|
@@ -6854,45 +6891,55 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6854
6891
|
) : null;
|
|
6855
6892
|
});
|
|
6856
6893
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6894
|
+
const EditorContext = React__default.default.createContext(void 0);
|
|
6895
|
+
function EditorProvider(props) {
|
|
6896
|
+
const $ = reactCompilerRuntime.c(30), editor = useEditor(props.config), editorActor = editor._internal.editorActor, slateEditor = editor._internal.slateEditor, editable = editor.editable;
|
|
6897
|
+
let t0, t1;
|
|
6898
|
+
$[0] !== editor ? (t1 = new PortableTextEditor({
|
|
6899
|
+
editor
|
|
6900
|
+
}), $[0] = editor, $[1] = t1) : t1 = $[1], t0 = t1;
|
|
6901
|
+
const portableTextEditor = t0;
|
|
6861
6902
|
let t2;
|
|
6862
|
-
$[
|
|
6863
|
-
|
|
6864
|
-
|
|
6865
|
-
keyGenerator: t0,
|
|
6866
|
-
schema: t1,
|
|
6867
|
-
value: config.initialValue
|
|
6868
|
-
}
|
|
6869
|
-
}, $[3] = config.behaviors, $[4] = config.initialValue, $[5] = t0, $[6] = t1, $[7] = t2) : t2 = $[7];
|
|
6870
|
-
const editorActor = react$1.useActorRef(editorMachine, t2);
|
|
6903
|
+
$[2] !== portableTextEditor.change$ ? (t2 = (change) => {
|
|
6904
|
+
portableTextEditor.change$.next(change);
|
|
6905
|
+
}, $[2] = portableTextEditor.change$, $[3] = t2) : t2 = $[3];
|
|
6871
6906
|
let t3;
|
|
6872
|
-
$[
|
|
6873
|
-
|
|
6874
|
-
}), $[8] = editorActor, $[9] =
|
|
6875
|
-
|
|
6876
|
-
|
|
6877
|
-
$[10] !== editorActor ? (t4 = (event) => {
|
|
6878
|
-
editorActor.send(event);
|
|
6879
|
-
}, t5 = (event_0, listener) => editorActor.on(event_0, listener), $[10] = editorActor, $[11] = t4, $[12] = t5) : (t4 = $[11], t5 = $[12]);
|
|
6907
|
+
$[4] !== editorActor || $[5] !== t2 ? (t3 = /* @__PURE__ */ jsxRuntime.jsx(RouteEventsToChanges, { editorActor, onChange: t2 }), $[4] = editorActor, $[5] = t2, $[6] = t3) : t3 = $[6];
|
|
6908
|
+
let t4;
|
|
6909
|
+
$[7] !== editable.getValue || $[8] !== editorActor || $[9] !== portableTextEditor || $[10] !== slateEditor.instance ? (t4 = /* @__PURE__ */ jsxRuntime.jsx(Synchronizer, { editorActor, getValue: editable.getValue, portableTextEditor, slateEditor: slateEditor.instance }), $[7] = editable.getValue, $[8] = editorActor, $[9] = portableTextEditor, $[10] = slateEditor.instance, $[11] = t4) : t4 = $[11];
|
|
6910
|
+
let t5;
|
|
6911
|
+
$[12] !== editorActor || $[13] !== props.children ? (t5 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionProvider, { editorActor, children: props.children }), $[12] = editorActor, $[13] = props.children, $[14] = t5) : t5 = $[14];
|
|
6880
6912
|
let t6;
|
|
6881
|
-
$[
|
|
6882
|
-
editorActor,
|
|
6883
|
-
slateEditor
|
|
6884
|
-
}, $[13] = editorActor, $[14] = slateEditor, $[15] = t6) : t6 = $[15];
|
|
6913
|
+
$[15] !== portableTextEditor || $[16] !== t5 ? (t6 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: portableTextEditor, children: t5 }), $[15] = portableTextEditor, $[16] = t5, $[17] = t6) : t6 = $[17];
|
|
6885
6914
|
let t7;
|
|
6886
|
-
|
|
6887
|
-
|
|
6888
|
-
|
|
6889
|
-
|
|
6890
|
-
|
|
6891
|
-
|
|
6915
|
+
$[18] !== slateEditor.initialValue || $[19] !== slateEditor.instance || $[20] !== t6 ? (t7 = /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: slateEditor.instance, initialValue: slateEditor.initialValue, children: t6 }), $[18] = slateEditor.initialValue, $[19] = slateEditor.instance, $[20] = t6, $[21] = t7) : t7 = $[21];
|
|
6916
|
+
let t8;
|
|
6917
|
+
$[22] !== editorActor || $[23] !== t7 ? (t8 = /* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: editorActor, children: t7 }), $[22] = editorActor, $[23] = t7, $[24] = t8) : t8 = $[24];
|
|
6918
|
+
let t9;
|
|
6919
|
+
return $[25] !== editor || $[26] !== t3 || $[27] !== t4 || $[28] !== t8 ? (t9 = /* @__PURE__ */ jsxRuntime.jsxs(EditorContext.Provider, { value: editor, children: [
|
|
6920
|
+
t3,
|
|
6921
|
+
t4,
|
|
6922
|
+
t8
|
|
6923
|
+
] }), $[25] = editor, $[26] = t3, $[27] = t4, $[28] = t8, $[29] = t9) : t9 = $[29], t9;
|
|
6924
|
+
}
|
|
6925
|
+
function useEditorContext() {
|
|
6926
|
+
const editor = React__default.default.useContext(EditorContext);
|
|
6927
|
+
if (!editor)
|
|
6928
|
+
throw new Error("No Editor set. Use EditorProvider to set one.");
|
|
6929
|
+
return editor;
|
|
6892
6930
|
}
|
|
6893
|
-
function
|
|
6894
|
-
|
|
6931
|
+
function EditorEventListener(props) {
|
|
6932
|
+
const $ = reactCompilerRuntime.c(4), editor = useEditorContext(), on = useEffectEvent.useEffectEvent(props.on);
|
|
6933
|
+
let t0, t1;
|
|
6934
|
+
return $[0] !== editor || $[1] !== on ? (t0 = () => {
|
|
6935
|
+
const subscription = editor.on("*", on);
|
|
6936
|
+
return () => {
|
|
6937
|
+
subscription.unsubscribe();
|
|
6938
|
+
};
|
|
6939
|
+
}, t1 = [editor, on], $[0] = editor, $[1] = on, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), React.useEffect(t0, t1), null;
|
|
6895
6940
|
}
|
|
6941
|
+
exports.EditorEventListener = EditorEventListener;
|
|
6942
|
+
exports.EditorProvider = EditorProvider;
|
|
6896
6943
|
exports.PortableTextEditable = PortableTextEditable;
|
|
6897
6944
|
exports.PortableTextEditor = PortableTextEditor;
|
|
6898
6945
|
exports.coreBehavior = coreBehavior;
|
|
@@ -6904,6 +6951,7 @@ exports.defineSchema = defineSchema;
|
|
|
6904
6951
|
exports.editorMachine = editorMachine;
|
|
6905
6952
|
exports.keyGenerator = defaultKeyGenerator;
|
|
6906
6953
|
exports.useEditor = useEditor;
|
|
6954
|
+
exports.useEditorContext = useEditorContext;
|
|
6907
6955
|
exports.usePortableTextEditor = usePortableTextEditor;
|
|
6908
6956
|
exports.usePortableTextEditorSelection = usePortableTextEditorSelection;
|
|
6909
6957
|
//# sourceMappingURL=index.js.map
|