@portabletext/editor 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.d.mts +104 -29
- package/lib/index.d.ts +104 -29
- package/lib/index.esm.js +140 -387
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +203 -452
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +140 -387
- package/lib/index.mjs.map +1 -1
- package/package.json +12 -9
- package/src/editor/PortableTextEditor.tsx +8 -11
- package/src/editor/define-schema.ts +111 -0
- package/src/editor/plugins/createWithEditableAPI.ts +12 -6
- package/src/editor/use-editor.ts +19 -7
- package/src/index.ts +11 -5
- package/src/types/editor.ts +10 -10
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"), jsxRuntime = require("react/jsx-runtime"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"),
|
|
3
|
+
var types = require("@sanity/types"), schema = require("@sanity/schema"), startCase = require("lodash.startcase"), jsxRuntime = require("react/jsx-runtime"), 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"), xstate = require("xstate"), patches = require("@portabletext/patches"), get = require("lodash/get.js"), isUndefined = require("lodash/isUndefined.js"), omitBy = require("lodash/omitBy.js"), flatten = require("lodash/flatten.js"), isHotkeyEsm = require("is-hotkey-esm"), blockTools = require("@sanity/block-tools"), isPlainObject = require("lodash/isPlainObject.js"), throttle = require("lodash/throttle.js"), useEffectEvent = require("use-effect-event"), debounce = require("lodash/debounce.js"), content = require("@sanity/util/content"), react$1 = require("@xstate/react");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
7
|
-
var
|
|
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), get__default = /* @__PURE__ */ _interopDefaultCompat(get), isUndefined__default = /* @__PURE__ */ _interopDefaultCompat(isUndefined), omitBy__default = /* @__PURE__ */ _interopDefaultCompat(omitBy), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject), throttle__default = /* @__PURE__ */ _interopDefaultCompat(throttle), debounce__default = /* @__PURE__ */ _interopDefaultCompat(debounce);
|
|
8
8
|
function defineBehavior(behavior) {
|
|
9
9
|
return behavior;
|
|
10
10
|
}
|
|
@@ -245,6 +245,114 @@ function createMarkdownBehaviors(config) {
|
|
|
245
245
|
};
|
|
246
246
|
return [automaticStyleOnSpace, clearStyleOnBackspace, automaticListOnSpace];
|
|
247
247
|
}
|
|
248
|
+
function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
249
|
+
if (!portableTextType)
|
|
250
|
+
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
251
|
+
const blockType = portableTextType.of?.find(findBlockType);
|
|
252
|
+
if (!blockType)
|
|
253
|
+
throw new Error("Block type is not defined in this schema (required)");
|
|
254
|
+
const childrenField = blockType.fields?.find((field) => field.name === "children");
|
|
255
|
+
if (!childrenField)
|
|
256
|
+
throw new Error("Children field for block type found in schema (required)");
|
|
257
|
+
const ofType = childrenField.type.of;
|
|
258
|
+
if (!ofType)
|
|
259
|
+
throw new Error("Valid types for block children not found in schema (required)");
|
|
260
|
+
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
261
|
+
if (!spanType)
|
|
262
|
+
throw new Error("Span type not found in schema (required)");
|
|
263
|
+
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
|
|
264
|
+
return {
|
|
265
|
+
styles: resolveEnabledStyles(blockType),
|
|
266
|
+
decorators: resolveEnabledDecorators(spanType),
|
|
267
|
+
lists: resolveEnabledListItems(blockType),
|
|
268
|
+
block: blockType,
|
|
269
|
+
span: spanType,
|
|
270
|
+
portableText: portableTextType,
|
|
271
|
+
inlineObjects: inlineObjectTypes,
|
|
272
|
+
blockObjects: blockObjectTypes,
|
|
273
|
+
annotations: spanType.annotations
|
|
274
|
+
};
|
|
275
|
+
}
|
|
276
|
+
function resolveEnabledStyles(blockType) {
|
|
277
|
+
const styleField = blockType.fields?.find((btField) => btField.name === "style");
|
|
278
|
+
if (!styleField)
|
|
279
|
+
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
280
|
+
const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
|
|
281
|
+
if (!textStyles || textStyles.length === 0)
|
|
282
|
+
throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
|
|
283
|
+
return textStyles;
|
|
284
|
+
}
|
|
285
|
+
function resolveEnabledDecorators(spanType) {
|
|
286
|
+
return spanType.decorators;
|
|
287
|
+
}
|
|
288
|
+
function resolveEnabledListItems(blockType) {
|
|
289
|
+
const listField = blockType.fields?.find((btField) => btField.name === "listItem");
|
|
290
|
+
if (!listField)
|
|
291
|
+
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
292
|
+
const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
|
|
293
|
+
if (!listItems)
|
|
294
|
+
throw new Error("The list field need at least to be an empty array");
|
|
295
|
+
return listItems;
|
|
296
|
+
}
|
|
297
|
+
function findBlockType(type) {
|
|
298
|
+
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
299
|
+
}
|
|
300
|
+
function defineSchema(definition) {
|
|
301
|
+
return definition;
|
|
302
|
+
}
|
|
303
|
+
function compileSchemaDefinition(definition) {
|
|
304
|
+
const blockObjects = definition?.blockObjects?.map((blockObject) => types.defineType({
|
|
305
|
+
type: "object",
|
|
306
|
+
name: blockObject.name,
|
|
307
|
+
title: blockObject.title,
|
|
308
|
+
icon: blockObject.icon,
|
|
309
|
+
fields: []
|
|
310
|
+
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => types.defineType({
|
|
311
|
+
type: "object",
|
|
312
|
+
name: inlineObject.name,
|
|
313
|
+
title: inlineObject.title,
|
|
314
|
+
icon: inlineObject.icon,
|
|
315
|
+
fields: []
|
|
316
|
+
})) ?? [], portableTextSchema = types.defineField({
|
|
317
|
+
type: "array",
|
|
318
|
+
name: "portable-text",
|
|
319
|
+
of: [...blockObjects.map((blockObject) => ({
|
|
320
|
+
type: blockObject.name
|
|
321
|
+
})), {
|
|
322
|
+
type: "block",
|
|
323
|
+
name: "block",
|
|
324
|
+
of: inlineObjects.map((inlineObject) => ({
|
|
325
|
+
type: inlineObject.name
|
|
326
|
+
})),
|
|
327
|
+
marks: {
|
|
328
|
+
decorators: definition?.decorators?.map((decorator) => ({
|
|
329
|
+
title: decorator.title ?? startCase__default.default(decorator.name),
|
|
330
|
+
value: decorator.name,
|
|
331
|
+
icon: decorator.icon
|
|
332
|
+
})) ?? [],
|
|
333
|
+
annotations: definition?.annotations?.map((annotation) => ({
|
|
334
|
+
name: annotation.name,
|
|
335
|
+
type: "object",
|
|
336
|
+
title: annotation.title,
|
|
337
|
+
icon: annotation.icon
|
|
338
|
+
})) ?? []
|
|
339
|
+
},
|
|
340
|
+
lists: definition?.lists?.map((list) => ({
|
|
341
|
+
value: list.name,
|
|
342
|
+
title: list.title ?? startCase__default.default(list.name),
|
|
343
|
+
icon: list.icon
|
|
344
|
+
})) ?? [],
|
|
345
|
+
styles: definition?.styles?.map((style) => ({
|
|
346
|
+
value: style.name,
|
|
347
|
+
title: style.title ?? startCase__default.default(style.name),
|
|
348
|
+
icon: style.icon
|
|
349
|
+
})) ?? []
|
|
350
|
+
}]
|
|
351
|
+
}), schema$1 = schema.Schema.compile({
|
|
352
|
+
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
353
|
+
}).get("portable-text");
|
|
354
|
+
return getPortableTextMemberSchemaTypes(schema$1);
|
|
355
|
+
}
|
|
248
356
|
const rootName = "sanity-pte:";
|
|
249
357
|
debug__default.default(rootName);
|
|
250
358
|
function debugWithName(name) {
|
|
@@ -654,15 +762,15 @@ const debug$l = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
654
762
|
element,
|
|
655
763
|
readOnly,
|
|
656
764
|
blockRef
|
|
657
|
-
} = t0, editor = slateReact.useSlateStatic(), dragGhostRef =
|
|
765
|
+
} = t0, editor = slateReact.useSlateStatic(), dragGhostRef = react.useRef(), [isDragOver, setIsDragOver] = react.useState(!1);
|
|
658
766
|
let t1, t2;
|
|
659
767
|
$[0] !== editor || $[1] !== element ? (t2 = slate.Editor.isVoid(editor, element), $[0] = editor, $[1] = element, $[2] = t2) : t2 = $[2], t1 = t2;
|
|
660
768
|
const isVoid = t1;
|
|
661
769
|
let t3, t4;
|
|
662
770
|
$[3] !== editor || $[4] !== element ? (t4 = slate.Editor.isInline(editor, element), $[3] = editor, $[4] = element, $[5] = t4) : t4 = $[5], t3 = t4;
|
|
663
|
-
const isInline = t3, [blockElement, setBlockElement] =
|
|
771
|
+
const isInline = t3, [blockElement, setBlockElement] = react.useState(null);
|
|
664
772
|
let t5, t6;
|
|
665
|
-
$[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]),
|
|
773
|
+
$[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);
|
|
666
774
|
let t7;
|
|
667
775
|
$[11] !== editor || $[12] !== blockElement || $[13] !== element ? (t7 = (event) => {
|
|
668
776
|
const isMyDragOver = IS_DRAGGING_BLOCK_ELEMENT.get(editor);
|
|
@@ -793,9 +901,9 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
793
901
|
renderStyle,
|
|
794
902
|
spellCheck
|
|
795
903
|
}) => {
|
|
796
|
-
const editor = slateReact.useSlateStatic(), selected = slateReact.useSelected(), blockRef =
|
|
904
|
+
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]);
|
|
797
905
|
let renderedBlock = children, className;
|
|
798
|
-
const blockPath =
|
|
906
|
+
const blockPath = react.useMemo(() => [{
|
|
799
907
|
_key: element._key
|
|
800
908
|
}], [element]);
|
|
801
909
|
if (typeof element._type != "string")
|
|
@@ -916,8 +1024,8 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
916
1024
|
] }, element._key);
|
|
917
1025
|
};
|
|
918
1026
|
Element.displayName = "Element";
|
|
919
|
-
const PortableTextEditorContext =
|
|
920
|
-
const editor =
|
|
1027
|
+
const PortableTextEditorContext = react.createContext(null), usePortableTextEditor = () => {
|
|
1028
|
+
const editor = react.useContext(PortableTextEditorContext);
|
|
921
1029
|
if (!editor)
|
|
922
1030
|
throw new Error("The `usePortableTextEditor` hook must be used inside the <PortableTextEditor> component's context.");
|
|
923
1031
|
return editor;
|
|
@@ -935,58 +1043,6 @@ function DefaultAnnotation(props) {
|
|
|
935
1043
|
return $[3] !== handleClick || $[4] !== props.children ? (t2 = /* @__PURE__ */ jsxRuntime.jsx("span", { style: t1, onClick: handleClick, children: props.children }), $[3] = handleClick, $[4] = props.children, $[5] = t2) : t2 = $[5], t2;
|
|
936
1044
|
}
|
|
937
1045
|
DefaultAnnotation.displayName = "DefaultAnnotation";
|
|
938
|
-
function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
939
|
-
if (!portableTextType)
|
|
940
|
-
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
941
|
-
const blockType = portableTextType.of?.find(findBlockType);
|
|
942
|
-
if (!blockType)
|
|
943
|
-
throw new Error("Block type is not defined in this schema (required)");
|
|
944
|
-
const childrenField = blockType.fields?.find((field) => field.name === "children");
|
|
945
|
-
if (!childrenField)
|
|
946
|
-
throw new Error("Children field for block type found in schema (required)");
|
|
947
|
-
const ofType = childrenField.type.of;
|
|
948
|
-
if (!ofType)
|
|
949
|
-
throw new Error("Valid types for block children not found in schema (required)");
|
|
950
|
-
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
951
|
-
if (!spanType)
|
|
952
|
-
throw new Error("Span type not found in schema (required)");
|
|
953
|
-
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
|
|
954
|
-
return {
|
|
955
|
-
styles: resolveEnabledStyles(blockType),
|
|
956
|
-
decorators: resolveEnabledDecorators(spanType),
|
|
957
|
-
lists: resolveEnabledListItems(blockType),
|
|
958
|
-
block: blockType,
|
|
959
|
-
span: spanType,
|
|
960
|
-
portableText: portableTextType,
|
|
961
|
-
inlineObjects: inlineObjectTypes,
|
|
962
|
-
blockObjects: blockObjectTypes,
|
|
963
|
-
annotations: spanType.annotations
|
|
964
|
-
};
|
|
965
|
-
}
|
|
966
|
-
function resolveEnabledStyles(blockType) {
|
|
967
|
-
const styleField = blockType.fields?.find((btField) => btField.name === "style");
|
|
968
|
-
if (!styleField)
|
|
969
|
-
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
970
|
-
const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
|
|
971
|
-
if (!textStyles || textStyles.length === 0)
|
|
972
|
-
throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
|
|
973
|
-
return textStyles;
|
|
974
|
-
}
|
|
975
|
-
function resolveEnabledDecorators(spanType) {
|
|
976
|
-
return spanType.decorators;
|
|
977
|
-
}
|
|
978
|
-
function resolveEnabledListItems(blockType) {
|
|
979
|
-
const listField = blockType.fields?.find((btField) => btField.name === "listItem");
|
|
980
|
-
if (!listField)
|
|
981
|
-
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
982
|
-
const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
|
|
983
|
-
if (!listItems)
|
|
984
|
-
throw new Error("The list field need at least to be an empty array");
|
|
985
|
-
return listItems;
|
|
986
|
-
}
|
|
987
|
-
function findBlockType(type) {
|
|
988
|
-
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
989
|
-
}
|
|
990
1046
|
function compileType(rawType) {
|
|
991
1047
|
return schema.Schema.compile({
|
|
992
1048
|
name: "blockTypeSchema",
|
|
@@ -2680,9 +2736,9 @@ function debugState(editor, stateName) {
|
|
|
2680
2736
|
}
|
|
2681
2737
|
function findBlockFromPath(editor, path) {
|
|
2682
2738
|
let blockIndex = -1;
|
|
2683
|
-
const block = editor.children.find((node,
|
|
2684
|
-
const isMatch = isKeyedSegment(path[0]) ? node._key === path[0]._key :
|
|
2685
|
-
return isMatch && (blockIndex =
|
|
2739
|
+
const block = editor.children.find((node, index) => {
|
|
2740
|
+
const isMatch = isKeyedSegment(path[0]) ? node._key === path[0]._key : index === path[0];
|
|
2741
|
+
return isMatch && (blockIndex = index), isMatch;
|
|
2686
2742
|
});
|
|
2687
2743
|
return block ? {
|
|
2688
2744
|
block,
|
|
@@ -2702,9 +2758,9 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
2702
2758
|
childPath: void 0
|
|
2703
2759
|
};
|
|
2704
2760
|
let childIndex = -1;
|
|
2705
|
-
const child = block.children.find((node,
|
|
2706
|
-
const isMatch = isKeyedSegment(path[2]) ? node._key === path[2]._key :
|
|
2707
|
-
return isMatch && (childIndex =
|
|
2761
|
+
const child = block.children.find((node, index) => {
|
|
2762
|
+
const isMatch = isKeyedSegment(path[2]) ? node._key === path[2]._key : index === path[2];
|
|
2763
|
+
return isMatch && (childIndex = index), isMatch;
|
|
2708
2764
|
});
|
|
2709
2765
|
return child ? {
|
|
2710
2766
|
block,
|
|
@@ -2901,9 +2957,9 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2901
2957
|
const {
|
|
2902
2958
|
diffs
|
|
2903
2959
|
} = diffPatch;
|
|
2904
|
-
if (diffs.forEach((diff2,
|
|
2960
|
+
if (diffs.forEach((diff2, index) => {
|
|
2905
2961
|
const [diffType, text] = diff2;
|
|
2906
|
-
diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(
|
|
2962
|
+
diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(index).every(([dType]) => dType === DIFF_EQUAL) || (changedOffset += text.length));
|
|
2907
2963
|
}), transformedOperation.type === "insert_text" && changedOffset < transformedOperation.offset && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "remove_text" && changedOffset <= transformedOperation.offset - transformedOperation.text.length && (transformedOperation.offset += adjustOffsetBy), transformedOperation.type === "set_selection") {
|
|
2908
2964
|
const currentFocus = transformedOperation.properties?.focus ? {
|
|
2909
2965
|
...transformedOperation.properties.focus
|
|
@@ -3997,10 +4053,10 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
3997
4053
|
}
|
|
3998
4054
|
},
|
|
3999
4055
|
value
|
|
4000
|
-
} : (value.some((blk,
|
|
4056
|
+
} : (value.some((blk, index) => {
|
|
4001
4057
|
if (!isPlainObject__default.default(blk))
|
|
4002
4058
|
return resolution = {
|
|
4003
|
-
patches: [patches.unset([
|
|
4059
|
+
patches: [patches.unset([index])],
|
|
4004
4060
|
description: `Block must be an object, got ${String(blk)}`,
|
|
4005
4061
|
action: "Unset invalid item",
|
|
4006
4062
|
item: blk,
|
|
@@ -4008,7 +4064,7 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
4008
4064
|
description: "inputs.portable-text.invalid-value.not-an-object.description",
|
|
4009
4065
|
action: "inputs.portable-text.invalid-value.not-an-object.action",
|
|
4010
4066
|
values: {
|
|
4011
|
-
index
|
|
4067
|
+
index
|
|
4012
4068
|
}
|
|
4013
4069
|
}
|
|
4014
4070
|
}, !0;
|
|
@@ -4017,15 +4073,15 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
4017
4073
|
patches: [patches.set({
|
|
4018
4074
|
...blk,
|
|
4019
4075
|
_key: keyGenerator()
|
|
4020
|
-
}, [
|
|
4021
|
-
description: `Block at index ${
|
|
4076
|
+
}, [index])],
|
|
4077
|
+
description: `Block at index ${index} is missing required _key.`,
|
|
4022
4078
|
action: "Set the block with a random _key value",
|
|
4023
4079
|
item: blk,
|
|
4024
4080
|
i18n: {
|
|
4025
4081
|
description: "inputs.portable-text.invalid-value.missing-key.description",
|
|
4026
4082
|
action: "inputs.portable-text.invalid-value.missing-key.action",
|
|
4027
4083
|
values: {
|
|
4028
|
-
index
|
|
4084
|
+
index
|
|
4029
4085
|
}
|
|
4030
4086
|
}
|
|
4031
4087
|
}, !0;
|
|
@@ -4582,14 +4638,14 @@ function SlateContainer(props) {
|
|
|
4582
4638
|
});
|
|
4583
4639
|
return KEY_TO_VALUE_ELEMENT.set(editor, {}), KEY_TO_SLATE_ELEMENT.set(editor, {}), [editor, _sub];
|
|
4584
4640
|
}, $[0] = editorActor, $[1] = maxBlocks, $[2] = portableTextEditor, $[3] = readOnly, $[4] = t0) : t0 = $[4];
|
|
4585
|
-
const [t1] =
|
|
4641
|
+
const [t1] = react.useState(t0), [slateEditor, subscribe] = t1;
|
|
4586
4642
|
let t2, t3;
|
|
4587
4643
|
$[5] !== subscribe ? (t2 = () => {
|
|
4588
4644
|
const unsubscribe = subscribe();
|
|
4589
4645
|
return () => {
|
|
4590
4646
|
unsubscribe();
|
|
4591
4647
|
};
|
|
4592
|
-
}, t3 = [subscribe], $[5] = subscribe, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]),
|
|
4648
|
+
}, t3 = [subscribe], $[5] = subscribe, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), react.useEffect(t2, t3);
|
|
4593
4649
|
let t4, t5;
|
|
4594
4650
|
$[8] !== slateEditor || $[9] !== editorActor || $[10] !== maxBlocks || $[11] !== portableTextEditor || $[12] !== readOnly ? (t4 = () => {
|
|
4595
4651
|
debug$6("Re-initializing plugin chain"), withPlugins(slateEditor, {
|
|
@@ -4598,7 +4654,7 @@ function SlateContainer(props) {
|
|
|
4598
4654
|
portableTextEditor,
|
|
4599
4655
|
readOnly
|
|
4600
4656
|
});
|
|
4601
|
-
}, t5 = [editorActor, portableTextEditor, maxBlocks, readOnly, slateEditor], $[8] = slateEditor, $[9] = editorActor, $[10] = maxBlocks, $[11] = portableTextEditor, $[12] = readOnly, $[13] = t4, $[14] = t5) : (t4 = $[13], t5 = $[14]),
|
|
4657
|
+
}, t5 = [editorActor, portableTextEditor, maxBlocks, readOnly, slateEditor], $[8] = slateEditor, $[9] = editorActor, $[10] = maxBlocks, $[11] = portableTextEditor, $[12] = readOnly, $[13] = t4, $[14] = t5) : (t4 = $[13], t5 = $[14]), react.useEffect(t4, t5);
|
|
4602
4658
|
let t6, t7;
|
|
4603
4659
|
$[15] !== slateEditor ? (t7 = slateEditor.pteCreateTextBlock({
|
|
4604
4660
|
decorators: []
|
|
@@ -4609,13 +4665,13 @@ function SlateContainer(props) {
|
|
|
4609
4665
|
let t9, t10;
|
|
4610
4666
|
$[19] !== slateEditor ? (t9 = () => () => {
|
|
4611
4667
|
debug$6("Destroying Slate editor"), slateEditor.destroy();
|
|
4612
|
-
}, t10 = [slateEditor], $[19] = slateEditor, $[20] = t9, $[21] = t10) : (t9 = $[20], t10 = $[21]),
|
|
4668
|
+
}, t10 = [slateEditor], $[19] = slateEditor, $[20] = t9, $[21] = t10) : (t9 = $[20], t10 = $[21]), react.useEffect(t9, t10);
|
|
4613
4669
|
let t11;
|
|
4614
4670
|
return $[22] !== slateEditor || $[23] !== initialValue || $[24] !== props.children ? (t11 = /* @__PURE__ */ jsxRuntime.jsx(slateReact.Slate, { editor: slateEditor, initialValue, children: props.children }), $[22] = slateEditor, $[23] = initialValue, $[24] = props.children, $[25] = t11) : t11 = $[25], t11;
|
|
4615
4671
|
}
|
|
4616
4672
|
SlateContainer.displayName = "SlateContainer";
|
|
4617
|
-
const PortableTextEditorReadOnlyContext =
|
|
4618
|
-
const readOnly =
|
|
4673
|
+
const PortableTextEditorReadOnlyContext = react.createContext(!1), usePortableTextEditorReadOnlyStatus = () => {
|
|
4674
|
+
const readOnly = react.useContext(PortableTextEditorReadOnlyContext);
|
|
4619
4675
|
if (readOnly === void 0)
|
|
4620
4676
|
throw new Error("The `usePortableTextEditorReadOnly` hook must be used inside the <PortableTextEditor> component's context.");
|
|
4621
4677
|
return readOnly;
|
|
@@ -4625,18 +4681,18 @@ function useSyncValue(props) {
|
|
|
4625
4681
|
editorActor,
|
|
4626
4682
|
portableTextEditor,
|
|
4627
4683
|
readOnly
|
|
4628
|
-
} = props, schemaTypes = editorActor.getSnapshot().context.schema, previousValue =
|
|
4684
|
+
} = props, schemaTypes = editorActor.getSnapshot().context.schema, previousValue = react.useRef(), slateEditor = slateReact.useSlate(), updateValueFunctionRef = react.useRef(), updateFromCurrentValue = react.useCallback(() => {
|
|
4629
4685
|
const currentValue = CURRENT_VALUE.get(portableTextEditor);
|
|
4630
4686
|
if (previousValue.current === currentValue) {
|
|
4631
4687
|
debug$5("Value is the same object as previous, not need to sync");
|
|
4632
4688
|
return;
|
|
4633
4689
|
}
|
|
4634
4690
|
updateValueFunctionRef.current && currentValue && (debug$5("Updating the value debounced"), updateValueFunctionRef.current(currentValue));
|
|
4635
|
-
}, [portableTextEditor]), updateValueDebounced =
|
|
4691
|
+
}, [portableTextEditor]), updateValueDebounced = react.useMemo(() => debounce__default.default(updateFromCurrentValue, 1e3, {
|
|
4636
4692
|
trailing: !0,
|
|
4637
4693
|
leading: !1
|
|
4638
4694
|
}), [updateFromCurrentValue]);
|
|
4639
|
-
return
|
|
4695
|
+
return react.useMemo(() => {
|
|
4640
4696
|
const updateFunction = (value) => {
|
|
4641
4697
|
CURRENT_VALUE.set(portableTextEditor, value);
|
|
4642
4698
|
const isProcessingLocalChanges = isChangingLocally(slateEditor), isProcessingRemoteChanges = isChangingRemotely(slateEditor);
|
|
@@ -4657,9 +4713,9 @@ function useSyncValue(props) {
|
|
|
4657
4713
|
withoutPatching(slateEditor, () => {
|
|
4658
4714
|
hadSelection && slate.Transforms.deselect(slateEditor);
|
|
4659
4715
|
const childrenLength = slateEditor.children.length;
|
|
4660
|
-
slateEditor.children.forEach((_,
|
|
4716
|
+
slateEditor.children.forEach((_, index) => {
|
|
4661
4717
|
slate.Transforms.removeNodes(slateEditor, {
|
|
4662
|
-
at: [childrenLength - 1 -
|
|
4718
|
+
at: [childrenLength - 1 - index]
|
|
4663
4719
|
});
|
|
4664
4720
|
}), slate.Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
|
|
4665
4721
|
decorators: []
|
|
@@ -4764,8 +4820,8 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
4764
4820
|
at: [currentBlockIndex]
|
|
4765
4821
|
}), slateEditor.isTextBlock(currentBlock) && slateEditor.isTextBlock(oldBlock)) {
|
|
4766
4822
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
4767
|
-
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_,
|
|
4768
|
-
const childIndex = oldBlockChildrenLength - 1 -
|
|
4823
|
+
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
|
|
4824
|
+
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
4769
4825
|
childIndex > 0 && (debug$5("Removing child"), slate.Transforms.removeNodes(slateEditor, {
|
|
4770
4826
|
at: [currentBlockIndex, childIndex]
|
|
4771
4827
|
}));
|
|
@@ -4816,7 +4872,7 @@ function Synchronizer(props) {
|
|
|
4816
4872
|
} = props;
|
|
4817
4873
|
let t0;
|
|
4818
4874
|
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0];
|
|
4819
|
-
const pendingPatches =
|
|
4875
|
+
const pendingPatches = react.useRef(t0);
|
|
4820
4876
|
let t1;
|
|
4821
4877
|
$[1] !== editorActor || $[2] !== portableTextEditor || $[3] !== readOnly ? (t1 = {
|
|
4822
4878
|
editorActor,
|
|
@@ -4827,7 +4883,7 @@ function Synchronizer(props) {
|
|
|
4827
4883
|
let t2, t3;
|
|
4828
4884
|
$[5] !== slateEditor ? (t2 = () => {
|
|
4829
4885
|
IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !1);
|
|
4830
|
-
}, t3 = [slateEditor], $[5] = slateEditor, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]),
|
|
4886
|
+
}, t3 = [slateEditor], $[5] = slateEditor, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), react.useEffect(t2, t3);
|
|
4831
4887
|
let t4;
|
|
4832
4888
|
$[8] !== getValue || $[9] !== editorActor || $[10] !== slateEditor ? (t4 = () => {
|
|
4833
4889
|
if (pendingPatches.current.length > 0) {
|
|
@@ -4846,7 +4902,7 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
|
4846
4902
|
let t5, t6;
|
|
4847
4903
|
$[12] !== onFlushPendingPatches ? (t5 = () => () => {
|
|
4848
4904
|
onFlushPendingPatches();
|
|
4849
|
-
}, t6 = [onFlushPendingPatches], $[12] = onFlushPendingPatches, $[13] = t5, $[14] = t6) : (t5 = $[13], t6 = $[14]),
|
|
4905
|
+
}, t6 = [onFlushPendingPatches], $[12] = onFlushPendingPatches, $[13] = t5, $[14] = t6) : (t5 = $[13], t6 = $[14]), react.useEffect(t5, t6);
|
|
4850
4906
|
let t7;
|
|
4851
4907
|
$[15] !== onChange ? (t7 = (change) => onChange(change), $[15] = onChange, $[16] = t7) : t7 = $[16];
|
|
4852
4908
|
const handleChange = useEffectEvent.useEffectEvent(t7);
|
|
@@ -4928,7 +4984,7 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
|
4928
4984
|
return () => {
|
|
4929
4985
|
debug$4("Unsubscribing to changes"), sub.unsubscribe();
|
|
4930
4986
|
};
|
|
4931
|
-
}, t9 = [editorActor, handleChange, onFlushPendingPatches, slateEditor], $[17] = slateEditor, $[18] = onFlushPendingPatches, $[19] = editorActor, $[20] = handleChange, $[21] = t8, $[22] = t9) : (t8 = $[21], t9 = $[22]),
|
|
4987
|
+
}, t9 = [editorActor, handleChange, onFlushPendingPatches, slateEditor], $[17] = slateEditor, $[18] = onFlushPendingPatches, $[19] = editorActor, $[20] = handleChange, $[21] = t8, $[22] = t9) : (t8 = $[21], t9 = $[22]), react.useEffect(t8, t9);
|
|
4932
4988
|
let t10;
|
|
4933
4989
|
$[23] !== syncValue || $[24] !== value ? (t10 = () => {
|
|
4934
4990
|
debug$4("Editor is online, syncing from props.value"), syncValue(value);
|
|
@@ -4940,17 +4996,17 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
|
4940
4996
|
return () => {
|
|
4941
4997
|
subscription.unsubscribe();
|
|
4942
4998
|
};
|
|
4943
|
-
}, t12 = [handleOnline, editorActor], $[26] = editorActor, $[27] = handleOnline, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]),
|
|
4944
|
-
const isInitialValueFromProps =
|
|
4999
|
+
}, t12 = [handleOnline, editorActor], $[26] = editorActor, $[27] = handleOnline, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), react.useEffect(t11, t12);
|
|
5000
|
+
const isInitialValueFromProps = react.useRef(!0);
|
|
4945
5001
|
let t13, t14;
|
|
4946
5002
|
return $[30] !== syncValue || $[31] !== value || $[32] !== editorActor ? (t13 = () => {
|
|
4947
5003
|
debug$4("Value from props changed, syncing new value"), syncValue(value), isInitialValueFromProps.current && (editorActor.send({
|
|
4948
5004
|
type: "ready"
|
|
4949
5005
|
}), isInitialValueFromProps.current = !1);
|
|
4950
|
-
}, t14 = [editorActor, syncValue, value], $[30] = syncValue, $[31] = value, $[32] = editorActor, $[33] = t13, $[34] = t14) : (t13 = $[33], t14 = $[34]),
|
|
5006
|
+
}, t14 = [editorActor, syncValue, value], $[30] = syncValue, $[31] = value, $[32] = editorActor, $[33] = t13, $[34] = t14) : (t13 = $[33], t14 = $[34]), react.useEffect(t13, t14), null;
|
|
4951
5007
|
}
|
|
4952
5008
|
Synchronizer.displayName = "Synchronizer";
|
|
4953
|
-
const EditorActorContext =
|
|
5009
|
+
const EditorActorContext = react.createContext({}), insertBreakActionImplementation = ({
|
|
4954
5010
|
context,
|
|
4955
5011
|
action
|
|
4956
5012
|
}) => {
|
|
@@ -5663,31 +5719,31 @@ const breakingVoidBlock = {
|
|
|
5663
5719
|
}
|
|
5664
5720
|
}
|
|
5665
5721
|
}
|
|
5666
|
-
}), PortableTextEditorSelectionContext =
|
|
5667
|
-
const selection =
|
|
5722
|
+
}), PortableTextEditorSelectionContext = react.createContext(null), usePortableTextEditorSelection = () => {
|
|
5723
|
+
const selection = react.useContext(PortableTextEditorSelectionContext);
|
|
5668
5724
|
if (selection === void 0)
|
|
5669
5725
|
throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
|
|
5670
5726
|
return selection;
|
|
5671
5727
|
}, debug$3 = debugWithName("component:PortableTextEditor:SelectionProvider"), debugVerbose = debug$3.enabled && !1;
|
|
5672
5728
|
function PortableTextEditorSelectionProvider(props) {
|
|
5673
|
-
const $ = reactCompilerRuntime.c(6), [selection, setSelection] =
|
|
5729
|
+
const $ = reactCompilerRuntime.c(6), [selection, setSelection] = react.useState(null);
|
|
5674
5730
|
let t0, t1;
|
|
5675
5731
|
$[0] !== props.editorActor ? (t0 = () => {
|
|
5676
5732
|
debug$3("Subscribing to selection changes");
|
|
5677
5733
|
const subscription = props.editorActor.on("selection", (event) => {
|
|
5678
|
-
|
|
5734
|
+
react.startTransition(() => {
|
|
5679
5735
|
debugVerbose && debug$3("Setting selection"), setSelection(event.selection);
|
|
5680
5736
|
});
|
|
5681
5737
|
});
|
|
5682
5738
|
return () => {
|
|
5683
5739
|
debug$3("Unsubscribing to selection changes"), subscription.unsubscribe();
|
|
5684
5740
|
};
|
|
5685
|
-
}, t1 = [props.editorActor], $[0] = props.editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]),
|
|
5741
|
+
}, t1 = [props.editorActor], $[0] = props.editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), react.useEffect(t0, t1);
|
|
5686
5742
|
let t2;
|
|
5687
5743
|
return $[3] !== selection || $[4] !== props.children ? (t2 = /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorSelectionContext.Provider, { value: selection, children: props.children }), $[3] = selection, $[4] = props.children, $[5] = t2) : t2 = $[5], t2;
|
|
5688
5744
|
}
|
|
5689
5745
|
const defaultKeyGenerator = () => content.randomKey(12), debug$2 = debugWithName("component:PortableTextEditor");
|
|
5690
|
-
class PortableTextEditor extends
|
|
5746
|
+
class PortableTextEditor extends react.Component {
|
|
5691
5747
|
static displayName = "PortableTextEditor";
|
|
5692
5748
|
/**
|
|
5693
5749
|
* An observable of all the editor changes.
|
|
@@ -5804,7 +5860,7 @@ function RoutePatchesObservableToEditorActor(props) {
|
|
|
5804
5860
|
return () => {
|
|
5805
5861
|
subscription.unsubscribe();
|
|
5806
5862
|
};
|
|
5807
|
-
}, t1 = [props.editorActor, props.patches$], $[0] = props.patches$, $[1] = props.editorActor, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]),
|
|
5863
|
+
}, t1 = [props.editorActor, props.patches$], $[0] = props.patches$, $[1] = props.editorActor, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), react.useEffect(t0, t1), null;
|
|
5808
5864
|
}
|
|
5809
5865
|
const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
|
|
5810
5866
|
const {
|
|
@@ -5816,22 +5872,22 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
5816
5872
|
renderChild,
|
|
5817
5873
|
renderDecorator,
|
|
5818
5874
|
renderAnnotation
|
|
5819
|
-
} = props, spanRef =
|
|
5875
|
+
} = 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 ? [{
|
|
5820
5876
|
_key: block?._key
|
|
5821
5877
|
}, "children", {
|
|
5822
5878
|
_key: leaf._key
|
|
5823
|
-
}] : [], [block, leaf._key]), decoratorValues =
|
|
5824
|
-
|
|
5879
|
+
}] : [], [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;
|
|
5880
|
+
react.useEffect(() => {
|
|
5825
5881
|
if (!shouldTrackSelectionAndFocus) {
|
|
5826
5882
|
setFocused(!1);
|
|
5827
5883
|
return;
|
|
5828
5884
|
}
|
|
5829
5885
|
const sel = PortableTextEditor.getSelection(portableTextEditor);
|
|
5830
|
-
sel && isEqual__default.default(sel.focus.path, path) && PortableTextEditor.isCollapsedSelection(portableTextEditor) &&
|
|
5886
|
+
sel && isEqual__default.default(sel.focus.path, path) && PortableTextEditor.isCollapsedSelection(portableTextEditor) && react.startTransition(() => {
|
|
5831
5887
|
setFocused(!0);
|
|
5832
5888
|
});
|
|
5833
5889
|
}, [shouldTrackSelectionAndFocus, path, portableTextEditor]);
|
|
5834
|
-
const setSelectedFromRange =
|
|
5890
|
+
const setSelectedFromRange = react.useCallback(() => {
|
|
5835
5891
|
if (!shouldTrackSelectionAndFocus)
|
|
5836
5892
|
return;
|
|
5837
5893
|
debug$1("Setting selection and focus from range");
|
|
@@ -5846,7 +5902,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
5846
5902
|
} else
|
|
5847
5903
|
setSelected(!1);
|
|
5848
5904
|
}, [shouldTrackSelectionAndFocus]);
|
|
5849
|
-
|
|
5905
|
+
react.useEffect(() => {
|
|
5850
5906
|
if (!shouldTrackSelectionAndFocus)
|
|
5851
5907
|
return;
|
|
5852
5908
|
const onBlur = editorActor.on("blur", () => {
|
|
@@ -5860,8 +5916,8 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
5860
5916
|
return () => {
|
|
5861
5917
|
onBlur.unsubscribe(), onFocus.unsubscribe(), onSelection.unsubscribe();
|
|
5862
5918
|
};
|
|
5863
|
-
}, [editorActor, path, portableTextEditor, setSelectedFromRange, shouldTrackSelectionAndFocus]),
|
|
5864
|
-
const content2 =
|
|
5919
|
+
}, [editorActor, path, portableTextEditor, setSelectedFromRange, shouldTrackSelectionAndFocus]), react.useEffect(() => setSelectedFromRange(), [setSelectedFromRange]);
|
|
5920
|
+
const content2 = react.useMemo(() => {
|
|
5865
5921
|
let returnedChildren = children;
|
|
5866
5922
|
if (slate.Text.isText(leaf) && leaf._type === schemaTypes.span.name && (marks.forEach((mark_1) => {
|
|
5867
5923
|
const schemaType = schemaTypes.decorators.find((dec_0) => dec_0.value === mark_1);
|
|
@@ -5927,7 +5983,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
5927
5983
|
}
|
|
5928
5984
|
return returnedChildren;
|
|
5929
5985
|
}, [annotations, block, children, focused, leaf, marks, path, renderAnnotation, renderChild, renderDecorator, schemaTypes.annotations, schemaTypes.decorators, schemaTypes.span, selected]);
|
|
5930
|
-
return
|
|
5986
|
+
return react.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span", { ...attributes, ref: spanRef, children: content2 }, leaf._key), [leaf, attributes, content2]);
|
|
5931
5987
|
};
|
|
5932
5988
|
Leaf.displayName = "Leaf";
|
|
5933
5989
|
const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
@@ -5936,7 +5992,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5936
5992
|
pointerEvents: "none",
|
|
5937
5993
|
left: 0,
|
|
5938
5994
|
right: 0
|
|
5939
|
-
}, PortableTextEditable =
|
|
5995
|
+
}, PortableTextEditable = react.forwardRef(function(props, forwardedRef) {
|
|
5940
5996
|
const {
|
|
5941
5997
|
hotkeys,
|
|
5942
5998
|
onBlur,
|
|
@@ -5957,13 +6013,13 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5957
6013
|
scrollSelectionIntoView,
|
|
5958
6014
|
spellCheck,
|
|
5959
6015
|
...restProps
|
|
5960
|
-
} = props, portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), ref =
|
|
5961
|
-
|
|
5962
|
-
const rangeDecorationsRef =
|
|
6016
|
+
} = props, portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), ref = react.useRef(null), [editableElement, setEditableElement] = react.useState(null), [hasInvalidValue, setHasInvalidValue] = react.useState(!1), [rangeDecorationState, setRangeDecorationsState] = react.useState([]);
|
|
6017
|
+
react.useImperativeHandle(forwardedRef, () => ref.current);
|
|
6018
|
+
const rangeDecorationsRef = react.useRef(rangeDecorations), editorActor = react.useContext(EditorActorContext), {
|
|
5963
6019
|
schemaTypes
|
|
5964
|
-
} = portableTextEditor, slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name, withInsertData =
|
|
5965
|
-
|
|
5966
|
-
const renderElement =
|
|
6020
|
+
} = portableTextEditor, slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name, withInsertData = react.useMemo(() => createWithInsertData(editorActor, schemaTypes), [editorActor, schemaTypes]), withHotKeys = react.useMemo(() => createWithHotkeys(portableTextEditor, hotkeys), [hotkeys, portableTextEditor]);
|
|
6021
|
+
react.useMemo(() => readOnly ? (debug("Editable is in read only mode"), withInsertData(slateEditor)) : (debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor))), [readOnly, slateEditor, withHotKeys, withInsertData]);
|
|
6022
|
+
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) => {
|
|
5967
6023
|
if (lProps.leaf._type === "span") {
|
|
5968
6024
|
let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
|
|
5969
6025
|
if (renderPlaceholder && lProps.leaf.placeholder && lProps.text.text === "")
|
|
@@ -5977,7 +6033,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5977
6033
|
})), rendered;
|
|
5978
6034
|
}
|
|
5979
6035
|
return lProps.children;
|
|
5980
|
-
}, [editorActor, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder, schemaTypes]), restoreSelectionFromProps =
|
|
6036
|
+
}, [editorActor, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder, schemaTypes]), restoreSelectionFromProps = react.useCallback(() => {
|
|
5981
6037
|
if (propsSelection) {
|
|
5982
6038
|
debug(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
5983
6039
|
const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children, blockTypeName));
|
|
@@ -5990,7 +6046,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5990
6046
|
}), slateEditor.onChange());
|
|
5991
6047
|
}
|
|
5992
6048
|
}
|
|
5993
|
-
}, [blockTypeName, editorActor, propsSelection, slateEditor]), syncRangeDecorations =
|
|
6049
|
+
}, [blockTypeName, editorActor, propsSelection, slateEditor]), syncRangeDecorations = react.useCallback((operation) => {
|
|
5994
6050
|
if (rangeDecorations && rangeDecorations.length > 0) {
|
|
5995
6051
|
const newSlateRanges = [];
|
|
5996
6052
|
if (rangeDecorations.forEach((rangeDecorationItem) => {
|
|
@@ -6023,7 +6079,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6023
6079
|
}
|
|
6024
6080
|
setRangeDecorationsState((rangeDecorationState_0) => rangeDecorationState_0.length > 0 ? [] : rangeDecorationState_0);
|
|
6025
6081
|
}, [portableTextEditor, rangeDecorations, schemaTypes, slateEditor]);
|
|
6026
|
-
|
|
6082
|
+
react.useEffect(() => {
|
|
6027
6083
|
const onReady = editorActor.on("ready", () => {
|
|
6028
6084
|
restoreSelectionFromProps();
|
|
6029
6085
|
}), onInvalidValue = editorActor.on("invalid value", () => {
|
|
@@ -6034,22 +6090,22 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6034
6090
|
return () => {
|
|
6035
6091
|
onReady.unsubscribe(), onInvalidValue.unsubscribe(), onValueChanged.unsubscribe();
|
|
6036
6092
|
};
|
|
6037
|
-
}, [editorActor, restoreSelectionFromProps]),
|
|
6093
|
+
}, [editorActor, restoreSelectionFromProps]), react.useEffect(() => {
|
|
6038
6094
|
propsSelection && !hasInvalidValue && restoreSelectionFromProps();
|
|
6039
6095
|
}, [hasInvalidValue, propsSelection, restoreSelectionFromProps]);
|
|
6040
|
-
const originalApply =
|
|
6041
|
-
|
|
6096
|
+
const originalApply = react.useMemo(() => slateEditor.apply, [slateEditor]), [syncedRangeDecorations, setSyncedRangeDecorations] = react.useState(!1);
|
|
6097
|
+
react.useEffect(() => {
|
|
6042
6098
|
syncedRangeDecorations || (setSyncedRangeDecorations(!0), syncRangeDecorations());
|
|
6043
|
-
}, [syncRangeDecorations, syncedRangeDecorations]),
|
|
6099
|
+
}, [syncRangeDecorations, syncedRangeDecorations]), react.useEffect(() => {
|
|
6044
6100
|
isEqual__default.default(rangeDecorations, rangeDecorationsRef.current) || syncRangeDecorations(), rangeDecorationsRef.current = rangeDecorations;
|
|
6045
|
-
}, [rangeDecorations, syncRangeDecorations]),
|
|
6101
|
+
}, [rangeDecorations, syncRangeDecorations]), react.useEffect(() => (slateEditor.apply = (op) => {
|
|
6046
6102
|
originalApply(op), op.type !== "set_selection" && syncRangeDecorations(op);
|
|
6047
6103
|
}, () => {
|
|
6048
6104
|
slateEditor.apply = originalApply;
|
|
6049
6105
|
}), [originalApply, slateEditor, syncRangeDecorations]);
|
|
6050
|
-
const handleCopy =
|
|
6106
|
+
const handleCopy = react.useCallback((event) => {
|
|
6051
6107
|
onCopy && onCopy(event) !== void 0 && event.preventDefault();
|
|
6052
|
-
}, [onCopy]), handlePaste =
|
|
6108
|
+
}, [onCopy]), handlePaste = react.useCallback((event_0) => {
|
|
6053
6109
|
if (event_0.preventDefault(), !slateEditor.selection)
|
|
6054
6110
|
return;
|
|
6055
6111
|
if (!onPaste) {
|
|
@@ -6073,7 +6129,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6073
6129
|
type: "done loading"
|
|
6074
6130
|
});
|
|
6075
6131
|
}));
|
|
6076
|
-
}, [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor]), handleOnFocus =
|
|
6132
|
+
}, [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor]), handleOnFocus = react.useCallback((event_1) => {
|
|
6077
6133
|
if (onFocus && onFocus(event_1), !event_1.isDefaultPrevented()) {
|
|
6078
6134
|
const selection = PortableTextEditor.getSelection(portableTextEditor);
|
|
6079
6135
|
selection === null && (slate.Transforms.select(slateEditor, slate.Editor.start(slateEditor, [])), slateEditor.onChange()), editorActor.send({
|
|
@@ -6086,7 +6142,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6086
6142
|
selection
|
|
6087
6143
|
});
|
|
6088
6144
|
}
|
|
6089
|
-
}, [editorActor, onFocus, portableTextEditor, slateEditor]), handleClick =
|
|
6145
|
+
}, [editorActor, onFocus, portableTextEditor, slateEditor]), handleClick = react.useCallback((event_2) => {
|
|
6090
6146
|
if (onClick && onClick(event_2), slateEditor.selection && event_2.target === event_2.currentTarget) {
|
|
6091
6147
|
const [lastBlock, path_0] = slate.Node.last(slateEditor, []), focusPath = slateEditor.selection.focus.path.slice(0, 1), lastPath = path_0.slice(0, 1);
|
|
6092
6148
|
if (slate.Path.equals(focusPath, lastPath)) {
|
|
@@ -6096,14 +6152,14 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6096
6152
|
})), slateEditor.onChange());
|
|
6097
6153
|
}
|
|
6098
6154
|
}
|
|
6099
|
-
}, [onClick, slateEditor]), handleOnBlur =
|
|
6155
|
+
}, [onClick, slateEditor]), handleOnBlur = react.useCallback((event_3) => {
|
|
6100
6156
|
onBlur && onBlur(event_3), event_3.isPropagationStopped() || editorActor.send({
|
|
6101
6157
|
type: "blur",
|
|
6102
6158
|
event: event_3
|
|
6103
6159
|
});
|
|
6104
|
-
}, [editorActor, onBlur]), handleOnBeforeInput =
|
|
6160
|
+
}, [editorActor, onBlur]), handleOnBeforeInput = react.useCallback((event_4) => {
|
|
6105
6161
|
onBeforeInput && onBeforeInput(event_4);
|
|
6106
|
-
}, [onBeforeInput]), validateSelection =
|
|
6162
|
+
}, [onBeforeInput]), validateSelection = react.useCallback(() => {
|
|
6107
6163
|
if (!slateEditor.selection)
|
|
6108
6164
|
return;
|
|
6109
6165
|
const root = slateReact.ReactEditor.findDocumentOrShadowRoot(slateEditor), {
|
|
@@ -6122,7 +6178,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6122
6178
|
debug("Could not resolve selection, selecting top document"), slate.Transforms.deselect(slateEditor), slateEditor.children.length > 0 && slate.Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
|
|
6123
6179
|
}
|
|
6124
6180
|
}, [ref, slateEditor]);
|
|
6125
|
-
|
|
6181
|
+
react.useEffect(() => {
|
|
6126
6182
|
if (editableElement) {
|
|
6127
6183
|
const mutationObserver = new MutationObserver(validateSelection);
|
|
6128
6184
|
return mutationObserver.observe(editableElement, {
|
|
@@ -6136,14 +6192,14 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6136
6192
|
};
|
|
6137
6193
|
}
|
|
6138
6194
|
}, [validateSelection, editableElement]);
|
|
6139
|
-
const handleKeyDown =
|
|
6195
|
+
const handleKeyDown = react.useCallback((event_5) => {
|
|
6140
6196
|
props.onKeyDown && props.onKeyDown(event_5), event_5.isDefaultPrevented() || slateEditor.pteWithHotKeys(event_5);
|
|
6141
|
-
}, [props, slateEditor]), scrollSelectionIntoViewToSlate =
|
|
6197
|
+
}, [props, slateEditor]), scrollSelectionIntoViewToSlate = react.useMemo(() => {
|
|
6142
6198
|
if (scrollSelectionIntoView !== void 0)
|
|
6143
6199
|
return scrollSelectionIntoView === null ? noop__default.default : (_editor, domRange) => {
|
|
6144
6200
|
scrollSelectionIntoView(portableTextEditor, domRange);
|
|
6145
6201
|
};
|
|
6146
|
-
}, [portableTextEditor, scrollSelectionIntoView]), decorate =
|
|
6202
|
+
}, [portableTextEditor, scrollSelectionIntoView]), decorate = react.useCallback(([, path_1]) => {
|
|
6147
6203
|
if (isEqualToEmptyEditor(slateEditor.children, schemaTypes))
|
|
6148
6204
|
return [{
|
|
6149
6205
|
anchor: {
|
|
@@ -6170,7 +6226,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6170
6226
|
}) || slate.Range.includes(item, path_1));
|
|
6171
6227
|
return result_1.length > 0 ? result_1 : [];
|
|
6172
6228
|
}, [slateEditor, schemaTypes, rangeDecorationState]);
|
|
6173
|
-
return
|
|
6229
|
+
return react.useEffect(() => {
|
|
6174
6230
|
ref.current = slateReact.ReactEditor.toDOMNode(slateEditor, slateEditor), setEditableElement(ref.current);
|
|
6175
6231
|
}, [slateEditor, ref]), portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsxRuntime.jsx(
|
|
6176
6232
|
slateReact.Editable,
|
|
@@ -6195,330 +6251,25 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6195
6251
|
) : null;
|
|
6196
6252
|
});
|
|
6197
6253
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
6198
|
-
var index = typeof document < "u" ? require$$0.useLayoutEffect : require$$0.useEffect, withSelector = { exports: {} }, withSelector_production_min = {}, shim = { exports: {} }, useSyncExternalStoreShim_production_min = {};
|
|
6199
|
-
/**
|
|
6200
|
-
* @license React
|
|
6201
|
-
* use-sync-external-store-shim.production.min.js
|
|
6202
|
-
*
|
|
6203
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6204
|
-
*
|
|
6205
|
-
* This source code is licensed under the MIT license found in the
|
|
6206
|
-
* LICENSE file in the root directory of this source tree.
|
|
6207
|
-
*/
|
|
6208
|
-
var hasRequiredUseSyncExternalStoreShim_production_min;
|
|
6209
|
-
function requireUseSyncExternalStoreShim_production_min() {
|
|
6210
|
-
if (hasRequiredUseSyncExternalStoreShim_production_min) return useSyncExternalStoreShim_production_min;
|
|
6211
|
-
hasRequiredUseSyncExternalStoreShim_production_min = 1;
|
|
6212
|
-
var e = require$$0__default.default;
|
|
6213
|
-
function h(a, b) {
|
|
6214
|
-
return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b;
|
|
6215
|
-
}
|
|
6216
|
-
var k = typeof Object.is == "function" ? Object.is : h, l = e.useState, m = e.useEffect, n = e.useLayoutEffect, p = e.useDebugValue;
|
|
6217
|
-
function q(a, b) {
|
|
6218
|
-
var d = b(), f = l({
|
|
6219
|
-
inst: {
|
|
6220
|
-
value: d,
|
|
6221
|
-
getSnapshot: b
|
|
6222
|
-
}
|
|
6223
|
-
}), c = f[0].inst, g = f[1];
|
|
6224
|
-
return n(function() {
|
|
6225
|
-
c.value = d, c.getSnapshot = b, r(c) && g({
|
|
6226
|
-
inst: c
|
|
6227
|
-
});
|
|
6228
|
-
}, [a, d, b]), m(function() {
|
|
6229
|
-
return r(c) && g({
|
|
6230
|
-
inst: c
|
|
6231
|
-
}), a(function() {
|
|
6232
|
-
r(c) && g({
|
|
6233
|
-
inst: c
|
|
6234
|
-
});
|
|
6235
|
-
});
|
|
6236
|
-
}, [a]), p(d), d;
|
|
6237
|
-
}
|
|
6238
|
-
function r(a) {
|
|
6239
|
-
var b = a.getSnapshot;
|
|
6240
|
-
a = a.value;
|
|
6241
|
-
try {
|
|
6242
|
-
var d = b();
|
|
6243
|
-
return !k(a, d);
|
|
6244
|
-
} catch {
|
|
6245
|
-
return !0;
|
|
6246
|
-
}
|
|
6247
|
-
}
|
|
6248
|
-
function t(a, b) {
|
|
6249
|
-
return b();
|
|
6250
|
-
}
|
|
6251
|
-
var u = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? t : q;
|
|
6252
|
-
return useSyncExternalStoreShim_production_min.useSyncExternalStore = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : u, useSyncExternalStoreShim_production_min;
|
|
6253
|
-
}
|
|
6254
|
-
var useSyncExternalStoreShim_development = {};
|
|
6255
|
-
/**
|
|
6256
|
-
* @license React
|
|
6257
|
-
* use-sync-external-store-shim.development.js
|
|
6258
|
-
*
|
|
6259
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6260
|
-
*
|
|
6261
|
-
* This source code is licensed under the MIT license found in the
|
|
6262
|
-
* LICENSE file in the root directory of this source tree.
|
|
6263
|
-
*/
|
|
6264
|
-
var hasRequiredUseSyncExternalStoreShim_development;
|
|
6265
|
-
function requireUseSyncExternalStoreShim_development() {
|
|
6266
|
-
return hasRequiredUseSyncExternalStoreShim_development || (hasRequiredUseSyncExternalStoreShim_development = 1, process.env.NODE_ENV !== "production" && function() {
|
|
6267
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
6268
|
-
var React = require$$0__default.default, ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
6269
|
-
function error(format) {
|
|
6270
|
-
{
|
|
6271
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++)
|
|
6272
|
-
args[_key2 - 1] = arguments[_key2];
|
|
6273
|
-
printWarning("error", format, args);
|
|
6274
|
-
}
|
|
6275
|
-
}
|
|
6276
|
-
function printWarning(level, format, args) {
|
|
6277
|
-
{
|
|
6278
|
-
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame, stack = ReactDebugCurrentFrame.getStackAddendum();
|
|
6279
|
-
stack !== "" && (format += "%s", args = args.concat([stack]));
|
|
6280
|
-
var argsWithFormat = args.map(function(item) {
|
|
6281
|
-
return String(item);
|
|
6282
|
-
});
|
|
6283
|
-
argsWithFormat.unshift("Warning: " + format), Function.prototype.apply.call(console[level], console, argsWithFormat);
|
|
6284
|
-
}
|
|
6285
|
-
}
|
|
6286
|
-
function is(x, y) {
|
|
6287
|
-
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
6288
|
-
}
|
|
6289
|
-
var objectIs = typeof Object.is == "function" ? Object.is : is, useState = React.useState, useEffect = React.useEffect, useLayoutEffect = React.useLayoutEffect, useDebugValue = React.useDebugValue, didWarnOld18Alpha = !1, didWarnUncachedGetSnapshot = !1;
|
|
6290
|
-
function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
|
|
6291
|
-
didWarnOld18Alpha || React.startTransition !== void 0 && (didWarnOld18Alpha = !0, error("You are using an outdated, pre-release alpha of React 18 that does not support useSyncExternalStore. The use-sync-external-store shim will not work correctly. Upgrade to a newer pre-release."));
|
|
6292
|
-
var value = getSnapshot();
|
|
6293
|
-
if (!didWarnUncachedGetSnapshot) {
|
|
6294
|
-
var cachedValue = getSnapshot();
|
|
6295
|
-
objectIs(value, cachedValue) || (error("The result of getSnapshot should be cached to avoid an infinite loop"), didWarnUncachedGetSnapshot = !0);
|
|
6296
|
-
}
|
|
6297
|
-
var _useState = useState({
|
|
6298
|
-
inst: {
|
|
6299
|
-
value,
|
|
6300
|
-
getSnapshot
|
|
6301
|
-
}
|
|
6302
|
-
}), inst = _useState[0].inst, forceUpdate = _useState[1];
|
|
6303
|
-
return useLayoutEffect(function() {
|
|
6304
|
-
inst.value = value, inst.getSnapshot = getSnapshot, checkIfSnapshotChanged(inst) && forceUpdate({
|
|
6305
|
-
inst
|
|
6306
|
-
});
|
|
6307
|
-
}, [subscribe, value, getSnapshot]), useEffect(function() {
|
|
6308
|
-
checkIfSnapshotChanged(inst) && forceUpdate({
|
|
6309
|
-
inst
|
|
6310
|
-
});
|
|
6311
|
-
var handleStoreChange = function() {
|
|
6312
|
-
checkIfSnapshotChanged(inst) && forceUpdate({
|
|
6313
|
-
inst
|
|
6314
|
-
});
|
|
6315
|
-
};
|
|
6316
|
-
return subscribe(handleStoreChange);
|
|
6317
|
-
}, [subscribe]), useDebugValue(value), value;
|
|
6318
|
-
}
|
|
6319
|
-
function checkIfSnapshotChanged(inst) {
|
|
6320
|
-
var latestGetSnapshot = inst.getSnapshot, prevValue = inst.value;
|
|
6321
|
-
try {
|
|
6322
|
-
var nextValue = latestGetSnapshot();
|
|
6323
|
-
return !objectIs(prevValue, nextValue);
|
|
6324
|
-
} catch {
|
|
6325
|
-
return !0;
|
|
6326
|
-
}
|
|
6327
|
-
}
|
|
6328
|
-
function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
|
|
6329
|
-
return getSnapshot();
|
|
6330
|
-
}
|
|
6331
|
-
var canUseDOM = typeof window < "u" && typeof window.document < "u" && typeof window.document.createElement < "u", isServerEnvironment = !canUseDOM, shim2 = isServerEnvironment ? useSyncExternalStore$1 : useSyncExternalStore, useSyncExternalStore$2 = React.useSyncExternalStore !== void 0 ? React.useSyncExternalStore : shim2;
|
|
6332
|
-
useSyncExternalStoreShim_development.useSyncExternalStore = useSyncExternalStore$2, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
6333
|
-
}()), useSyncExternalStoreShim_development;
|
|
6334
|
-
}
|
|
6335
|
-
var hasRequiredShim;
|
|
6336
|
-
function requireShim() {
|
|
6337
|
-
return hasRequiredShim || (hasRequiredShim = 1, process.env.NODE_ENV === "production" ? shim.exports = requireUseSyncExternalStoreShim_production_min() : shim.exports = requireUseSyncExternalStoreShim_development()), shim.exports;
|
|
6338
|
-
}
|
|
6339
|
-
/**
|
|
6340
|
-
* @license React
|
|
6341
|
-
* use-sync-external-store-shim/with-selector.production.min.js
|
|
6342
|
-
*
|
|
6343
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6344
|
-
*
|
|
6345
|
-
* This source code is licensed under the MIT license found in the
|
|
6346
|
-
* LICENSE file in the root directory of this source tree.
|
|
6347
|
-
*/
|
|
6348
|
-
var hasRequiredWithSelector_production_min;
|
|
6349
|
-
function requireWithSelector_production_min() {
|
|
6350
|
-
if (hasRequiredWithSelector_production_min) return withSelector_production_min;
|
|
6351
|
-
hasRequiredWithSelector_production_min = 1;
|
|
6352
|
-
var h = require$$0__default.default, n = requireShim();
|
|
6353
|
-
function p(a, b) {
|
|
6354
|
-
return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b;
|
|
6355
|
-
}
|
|
6356
|
-
var q = typeof Object.is == "function" ? Object.is : p, r = n.useSyncExternalStore, t = h.useRef, u = h.useEffect, v = h.useMemo, w = h.useDebugValue;
|
|
6357
|
-
return withSelector_production_min.useSyncExternalStoreWithSelector = function(a, b, e, l, g) {
|
|
6358
|
-
var c = t(null);
|
|
6359
|
-
if (c.current === null) {
|
|
6360
|
-
var f = {
|
|
6361
|
-
hasValue: !1,
|
|
6362
|
-
value: null
|
|
6363
|
-
};
|
|
6364
|
-
c.current = f;
|
|
6365
|
-
} else f = c.current;
|
|
6366
|
-
c = v(function() {
|
|
6367
|
-
function a2(a3) {
|
|
6368
|
-
if (!c2) {
|
|
6369
|
-
if (c2 = !0, d2 = a3, a3 = l(a3), g !== void 0 && f.hasValue) {
|
|
6370
|
-
var b2 = f.value;
|
|
6371
|
-
if (g(b2, a3)) return k = b2;
|
|
6372
|
-
}
|
|
6373
|
-
return k = a3;
|
|
6374
|
-
}
|
|
6375
|
-
if (b2 = k, q(d2, a3)) return b2;
|
|
6376
|
-
var e2 = l(a3);
|
|
6377
|
-
return g !== void 0 && g(b2, e2) ? b2 : (d2 = a3, k = e2);
|
|
6378
|
-
}
|
|
6379
|
-
var c2 = !1, d2, k, m = e === void 0 ? null : e;
|
|
6380
|
-
return [function() {
|
|
6381
|
-
return a2(b());
|
|
6382
|
-
}, m === null ? void 0 : function() {
|
|
6383
|
-
return a2(m());
|
|
6384
|
-
}];
|
|
6385
|
-
}, [b, e, l, g]);
|
|
6386
|
-
var d = r(a, c[0], c[1]);
|
|
6387
|
-
return u(function() {
|
|
6388
|
-
f.hasValue = !0, f.value = d;
|
|
6389
|
-
}, [d]), w(d), d;
|
|
6390
|
-
}, withSelector_production_min;
|
|
6391
|
-
}
|
|
6392
|
-
var withSelector_development = {};
|
|
6393
|
-
/**
|
|
6394
|
-
* @license React
|
|
6395
|
-
* use-sync-external-store-shim/with-selector.development.js
|
|
6396
|
-
*
|
|
6397
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6398
|
-
*
|
|
6399
|
-
* This source code is licensed under the MIT license found in the
|
|
6400
|
-
* LICENSE file in the root directory of this source tree.
|
|
6401
|
-
*/
|
|
6402
|
-
var hasRequiredWithSelector_development;
|
|
6403
|
-
function requireWithSelector_development() {
|
|
6404
|
-
return hasRequiredWithSelector_development || (hasRequiredWithSelector_development = 1, process.env.NODE_ENV !== "production" && function() {
|
|
6405
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
6406
|
-
var React = require$$0__default.default, shim2 = requireShim();
|
|
6407
|
-
function is(x, y) {
|
|
6408
|
-
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
6409
|
-
}
|
|
6410
|
-
var objectIs = typeof Object.is == "function" ? Object.is : is, useSyncExternalStore = shim2.useSyncExternalStore, useRef = React.useRef, useEffect = React.useEffect, useMemo = React.useMemo, useDebugValue = React.useDebugValue;
|
|
6411
|
-
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual2) {
|
|
6412
|
-
var instRef = useRef(null), inst;
|
|
6413
|
-
instRef.current === null ? (inst = {
|
|
6414
|
-
hasValue: !1,
|
|
6415
|
-
value: null
|
|
6416
|
-
}, instRef.current = inst) : inst = instRef.current;
|
|
6417
|
-
var _useMemo = useMemo(function() {
|
|
6418
|
-
var hasMemo = !1, memoizedSnapshot, memoizedSelection, memoizedSelector = function(nextSnapshot) {
|
|
6419
|
-
if (!hasMemo) {
|
|
6420
|
-
hasMemo = !0, memoizedSnapshot = nextSnapshot;
|
|
6421
|
-
var _nextSelection = selector(nextSnapshot);
|
|
6422
|
-
if (isEqual2 !== void 0 && inst.hasValue) {
|
|
6423
|
-
var currentSelection = inst.value;
|
|
6424
|
-
if (isEqual2(currentSelection, _nextSelection))
|
|
6425
|
-
return memoizedSelection = currentSelection, currentSelection;
|
|
6426
|
-
}
|
|
6427
|
-
return memoizedSelection = _nextSelection, _nextSelection;
|
|
6428
|
-
}
|
|
6429
|
-
var prevSnapshot = memoizedSnapshot, prevSelection = memoizedSelection;
|
|
6430
|
-
if (objectIs(prevSnapshot, nextSnapshot))
|
|
6431
|
-
return prevSelection;
|
|
6432
|
-
var nextSelection = selector(nextSnapshot);
|
|
6433
|
-
return isEqual2 !== void 0 && isEqual2(prevSelection, nextSelection) ? prevSelection : (memoizedSnapshot = nextSnapshot, memoizedSelection = nextSelection, nextSelection);
|
|
6434
|
-
}, maybeGetServerSnapshot = getServerSnapshot === void 0 ? null : getServerSnapshot, getSnapshotWithSelector = function() {
|
|
6435
|
-
return memoizedSelector(getSnapshot());
|
|
6436
|
-
}, getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? void 0 : function() {
|
|
6437
|
-
return memoizedSelector(maybeGetServerSnapshot());
|
|
6438
|
-
};
|
|
6439
|
-
return [getSnapshotWithSelector, getServerSnapshotWithSelector];
|
|
6440
|
-
}, [getSnapshot, getServerSnapshot, selector, isEqual2]), getSelection = _useMemo[0], getServerSelection = _useMemo[1], value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
|
|
6441
|
-
return useEffect(function() {
|
|
6442
|
-
inst.hasValue = !0, inst.value = value;
|
|
6443
|
-
}, [value]), useDebugValue(value), value;
|
|
6444
|
-
}
|
|
6445
|
-
withSelector_development.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
6446
|
-
}()), withSelector_development;
|
|
6447
|
-
}
|
|
6448
|
-
var hasRequiredWithSelector;
|
|
6449
|
-
function requireWithSelector() {
|
|
6450
|
-
return hasRequiredWithSelector || (hasRequiredWithSelector = 1, process.env.NODE_ENV === "production" ? withSelector.exports = requireWithSelector_production_min() : withSelector.exports = requireWithSelector_development()), withSelector.exports;
|
|
6451
|
-
}
|
|
6452
|
-
requireWithSelector();
|
|
6453
|
-
requireShim();
|
|
6454
|
-
const forEachActor = (actorRef, callback) => {
|
|
6455
|
-
callback(actorRef);
|
|
6456
|
-
const children = actorRef.getSnapshot().children;
|
|
6457
|
-
children && Object.values(children).forEach((child) => {
|
|
6458
|
-
forEachActor(child, callback);
|
|
6459
|
-
});
|
|
6460
|
-
};
|
|
6461
|
-
function stopRootWithRehydration(actorRef) {
|
|
6462
|
-
const persistedSnapshots = [];
|
|
6463
|
-
forEachActor(actorRef, (ref) => {
|
|
6464
|
-
persistedSnapshots.push([ref, ref.getSnapshot()]), ref.observers = /* @__PURE__ */ new Set();
|
|
6465
|
-
});
|
|
6466
|
-
const systemSnapshot = actorRef.system.getSnapshot?.();
|
|
6467
|
-
actorRef.stop(), actorRef.system._snapshot = systemSnapshot, persistedSnapshots.forEach(([ref, snapshot]) => {
|
|
6468
|
-
ref._processingStatus = 0, ref._snapshot = snapshot;
|
|
6469
|
-
});
|
|
6470
|
-
}
|
|
6471
|
-
function useIdleActorRef(logic, ...[options]) {
|
|
6472
|
-
let [[currentConfig, actorRef], setCurrent] = require$$0.useState(() => {
|
|
6473
|
-
const actorRef2 = xstate.createActor(logic, options);
|
|
6474
|
-
return [logic.config, actorRef2];
|
|
6475
|
-
});
|
|
6476
|
-
if (logic.config !== currentConfig) {
|
|
6477
|
-
const newActorRef = xstate.createActor(logic, {
|
|
6478
|
-
...options,
|
|
6479
|
-
snapshot: actorRef.getPersistedSnapshot({
|
|
6480
|
-
__unsafeAllowInlineActors: !0
|
|
6481
|
-
})
|
|
6482
|
-
});
|
|
6483
|
-
setCurrent([logic.config, newActorRef]), actorRef = newActorRef;
|
|
6484
|
-
}
|
|
6485
|
-
return index(() => {
|
|
6486
|
-
actorRef.logic.implementations = logic.implementations;
|
|
6487
|
-
}), actorRef;
|
|
6488
|
-
}
|
|
6489
|
-
function useActorRef(machine, ...[options, observerOrListener]) {
|
|
6490
|
-
const actorRef = useIdleActorRef(machine, options);
|
|
6491
|
-
return require$$0.useEffect(() => {
|
|
6492
|
-
if (!observerOrListener)
|
|
6493
|
-
return;
|
|
6494
|
-
let sub = actorRef.subscribe(xstate.toObserver(observerOrListener));
|
|
6495
|
-
return () => {
|
|
6496
|
-
sub.unsubscribe();
|
|
6497
|
-
};
|
|
6498
|
-
}, [observerOrListener]), require$$0.useEffect(() => (actorRef.start(), () => {
|
|
6499
|
-
stopRootWithRehydration(actorRef);
|
|
6500
|
-
}), [actorRef]), actorRef;
|
|
6501
|
-
}
|
|
6502
6254
|
function useEditor(config) {
|
|
6503
|
-
const $ = reactCompilerRuntime.c(
|
|
6255
|
+
const $ = reactCompilerRuntime.c(7);
|
|
6504
6256
|
let t0;
|
|
6505
|
-
$[0] !== config.schema ? (t0 = config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema), $[0] = config.
|
|
6506
|
-
|
|
6507
|
-
|
|
6508
|
-
|
|
6509
|
-
let t3;
|
|
6510
|
-
return $[4] !== config.behaviors || $[5] !== t2 || $[6] !== schema2 ? (t3 = {
|
|
6257
|
+
$[0] !== config.schemaDefinition || $[1] !== config.schema ? (t0 = config.schemaDefinition ? compileSchemaDefinition(config.schemaDefinition) : getPortableTextMemberSchemaTypes(config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema)), $[0] = config.schemaDefinition, $[1] = config.schema, $[2] = t0) : t0 = $[2];
|
|
6258
|
+
const schema2 = t0, t1 = config.keyGenerator ?? defaultKeyGenerator;
|
|
6259
|
+
let t2;
|
|
6260
|
+
return $[3] !== config.behaviors || $[4] !== t1 || $[5] !== schema2 ? (t2 = {
|
|
6511
6261
|
input: {
|
|
6512
6262
|
behaviors: config.behaviors,
|
|
6513
|
-
keyGenerator:
|
|
6263
|
+
keyGenerator: t1,
|
|
6514
6264
|
schema: schema2
|
|
6515
6265
|
}
|
|
6516
|
-
}, $[
|
|
6266
|
+
}, $[3] = config.behaviors, $[4] = t1, $[5] = schema2, $[6] = t2) : t2 = $[6], react$1.useActorRef(editorMachine, t2);
|
|
6517
6267
|
}
|
|
6518
6268
|
exports.PortableTextEditable = PortableTextEditable;
|
|
6519
6269
|
exports.PortableTextEditor = PortableTextEditor;
|
|
6520
6270
|
exports.createMarkdownBehaviors = createMarkdownBehaviors;
|
|
6521
6271
|
exports.defineBehavior = defineBehavior;
|
|
6272
|
+
exports.defineSchema = defineSchema;
|
|
6522
6273
|
exports.editorMachine = editorMachine;
|
|
6523
6274
|
exports.keyGenerator = defaultKeyGenerator;
|
|
6524
6275
|
exports.useEditor = useEditor;
|