@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.mjs
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, isKeySegment, isPortableTextListBlock } from "@sanity/types";
|
|
1
|
+
import { isPortableTextTextBlock, isPortableTextSpan as isPortableTextSpan$1, isKeySegment, defineType, defineField, isPortableTextListBlock } from "@sanity/types";
|
|
2
|
+
import { Schema } from "@sanity/schema";
|
|
3
|
+
import startCase from "lodash.startcase";
|
|
2
4
|
import { jsx, Fragment, jsxs } from "react/jsx-runtime";
|
|
3
5
|
import isEqual from "lodash/isEqual.js";
|
|
4
6
|
import noop from "lodash/noop.js";
|
|
5
|
-
import
|
|
7
|
+
import { useRef, useState, useEffect, useMemo, createContext, useContext, useCallback, startTransition, Component, forwardRef, useImperativeHandle } from "react";
|
|
6
8
|
import { Editor, Element as Element$1, Range, Point, Text, Path, Transforms, Node, Operation, createEditor, deleteBackward, deleteForward, insertText } from "slate";
|
|
7
9
|
import { useSlateStatic, ReactEditor, useSelected, withReact, Slate, useSlate, Editable } from "slate-react";
|
|
8
10
|
import debug$m from "debug";
|
|
@@ -10,8 +12,7 @@ import { c } from "react-compiler-runtime";
|
|
|
10
12
|
import { styled } from "styled-components";
|
|
11
13
|
import uniq from "lodash/uniq.js";
|
|
12
14
|
import { Subject } from "rxjs";
|
|
13
|
-
import { fromCallback, setup, assign, assertEvent, emit, enqueueActions, createActor
|
|
14
|
-
import { Schema } from "@sanity/schema";
|
|
15
|
+
import { fromCallback, setup, assign, assertEvent, emit, enqueueActions, createActor } from "xstate";
|
|
15
16
|
import { diffMatchPatch as diffMatchPatch$1, set, insert, setIfMissing, unset, applyAll } from "@portabletext/patches";
|
|
16
17
|
import get from "lodash/get.js";
|
|
17
18
|
import isUndefined from "lodash/isUndefined.js";
|
|
@@ -24,6 +25,7 @@ import throttle from "lodash/throttle.js";
|
|
|
24
25
|
import { useEffectEvent } from "use-effect-event";
|
|
25
26
|
import debounce from "lodash/debounce.js";
|
|
26
27
|
import { randomKey } from "@sanity/util/content";
|
|
28
|
+
import { useActorRef } from "@xstate/react";
|
|
27
29
|
function defineBehavior(behavior) {
|
|
28
30
|
return behavior;
|
|
29
31
|
}
|
|
@@ -264,6 +266,114 @@ function createMarkdownBehaviors(config) {
|
|
|
264
266
|
};
|
|
265
267
|
return [automaticStyleOnSpace, clearStyleOnBackspace, automaticListOnSpace];
|
|
266
268
|
}
|
|
269
|
+
function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
270
|
+
if (!portableTextType)
|
|
271
|
+
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
272
|
+
const blockType = portableTextType.of?.find(findBlockType);
|
|
273
|
+
if (!blockType)
|
|
274
|
+
throw new Error("Block type is not defined in this schema (required)");
|
|
275
|
+
const childrenField = blockType.fields?.find((field) => field.name === "children");
|
|
276
|
+
if (!childrenField)
|
|
277
|
+
throw new Error("Children field for block type found in schema (required)");
|
|
278
|
+
const ofType = childrenField.type.of;
|
|
279
|
+
if (!ofType)
|
|
280
|
+
throw new Error("Valid types for block children not found in schema (required)");
|
|
281
|
+
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
282
|
+
if (!spanType)
|
|
283
|
+
throw new Error("Span type not found in schema (required)");
|
|
284
|
+
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
|
|
285
|
+
return {
|
|
286
|
+
styles: resolveEnabledStyles(blockType),
|
|
287
|
+
decorators: resolveEnabledDecorators(spanType),
|
|
288
|
+
lists: resolveEnabledListItems(blockType),
|
|
289
|
+
block: blockType,
|
|
290
|
+
span: spanType,
|
|
291
|
+
portableText: portableTextType,
|
|
292
|
+
inlineObjects: inlineObjectTypes,
|
|
293
|
+
blockObjects: blockObjectTypes,
|
|
294
|
+
annotations: spanType.annotations
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
function resolveEnabledStyles(blockType) {
|
|
298
|
+
const styleField = blockType.fields?.find((btField) => btField.name === "style");
|
|
299
|
+
if (!styleField)
|
|
300
|
+
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
301
|
+
const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
|
|
302
|
+
if (!textStyles || textStyles.length === 0)
|
|
303
|
+
throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
|
|
304
|
+
return textStyles;
|
|
305
|
+
}
|
|
306
|
+
function resolveEnabledDecorators(spanType) {
|
|
307
|
+
return spanType.decorators;
|
|
308
|
+
}
|
|
309
|
+
function resolveEnabledListItems(blockType) {
|
|
310
|
+
const listField = blockType.fields?.find((btField) => btField.name === "listItem");
|
|
311
|
+
if (!listField)
|
|
312
|
+
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
313
|
+
const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
|
|
314
|
+
if (!listItems)
|
|
315
|
+
throw new Error("The list field need at least to be an empty array");
|
|
316
|
+
return listItems;
|
|
317
|
+
}
|
|
318
|
+
function findBlockType(type) {
|
|
319
|
+
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
320
|
+
}
|
|
321
|
+
function defineSchema(definition) {
|
|
322
|
+
return definition;
|
|
323
|
+
}
|
|
324
|
+
function compileSchemaDefinition(definition) {
|
|
325
|
+
const blockObjects = definition?.blockObjects?.map((blockObject) => defineType({
|
|
326
|
+
type: "object",
|
|
327
|
+
name: blockObject.name,
|
|
328
|
+
title: blockObject.title,
|
|
329
|
+
icon: blockObject.icon,
|
|
330
|
+
fields: []
|
|
331
|
+
})) ?? [], inlineObjects = definition?.inlineObjects?.map((inlineObject) => defineType({
|
|
332
|
+
type: "object",
|
|
333
|
+
name: inlineObject.name,
|
|
334
|
+
title: inlineObject.title,
|
|
335
|
+
icon: inlineObject.icon,
|
|
336
|
+
fields: []
|
|
337
|
+
})) ?? [], portableTextSchema = defineField({
|
|
338
|
+
type: "array",
|
|
339
|
+
name: "portable-text",
|
|
340
|
+
of: [...blockObjects.map((blockObject) => ({
|
|
341
|
+
type: blockObject.name
|
|
342
|
+
})), {
|
|
343
|
+
type: "block",
|
|
344
|
+
name: "block",
|
|
345
|
+
of: inlineObjects.map((inlineObject) => ({
|
|
346
|
+
type: inlineObject.name
|
|
347
|
+
})),
|
|
348
|
+
marks: {
|
|
349
|
+
decorators: definition?.decorators?.map((decorator) => ({
|
|
350
|
+
title: decorator.title ?? startCase(decorator.name),
|
|
351
|
+
value: decorator.name,
|
|
352
|
+
icon: decorator.icon
|
|
353
|
+
})) ?? [],
|
|
354
|
+
annotations: definition?.annotations?.map((annotation) => ({
|
|
355
|
+
name: annotation.name,
|
|
356
|
+
type: "object",
|
|
357
|
+
title: annotation.title,
|
|
358
|
+
icon: annotation.icon
|
|
359
|
+
})) ?? []
|
|
360
|
+
},
|
|
361
|
+
lists: definition?.lists?.map((list) => ({
|
|
362
|
+
value: list.name,
|
|
363
|
+
title: list.title ?? startCase(list.name),
|
|
364
|
+
icon: list.icon
|
|
365
|
+
})) ?? [],
|
|
366
|
+
styles: definition?.styles?.map((style) => ({
|
|
367
|
+
value: style.name,
|
|
368
|
+
title: style.title ?? startCase(style.name),
|
|
369
|
+
icon: style.icon
|
|
370
|
+
})) ?? []
|
|
371
|
+
}]
|
|
372
|
+
}), schema = Schema.compile({
|
|
373
|
+
types: [portableTextSchema, ...blockObjects, ...inlineObjects]
|
|
374
|
+
}).get("portable-text");
|
|
375
|
+
return getPortableTextMemberSchemaTypes(schema);
|
|
376
|
+
}
|
|
267
377
|
const rootName = "sanity-pte:";
|
|
268
378
|
debug$m(rootName);
|
|
269
379
|
function debugWithName(name) {
|
|
@@ -954,58 +1064,6 @@ function DefaultAnnotation(props) {
|
|
|
954
1064
|
return $[3] !== handleClick || $[4] !== props.children ? (t2 = /* @__PURE__ */ jsx("span", { style: t1, onClick: handleClick, children: props.children }), $[3] = handleClick, $[4] = props.children, $[5] = t2) : t2 = $[5], t2;
|
|
955
1065
|
}
|
|
956
1066
|
DefaultAnnotation.displayName = "DefaultAnnotation";
|
|
957
|
-
function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
958
|
-
if (!portableTextType)
|
|
959
|
-
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
960
|
-
const blockType = portableTextType.of?.find(findBlockType);
|
|
961
|
-
if (!blockType)
|
|
962
|
-
throw new Error("Block type is not defined in this schema (required)");
|
|
963
|
-
const childrenField = blockType.fields?.find((field) => field.name === "children");
|
|
964
|
-
if (!childrenField)
|
|
965
|
-
throw new Error("Children field for block type found in schema (required)");
|
|
966
|
-
const ofType = childrenField.type.of;
|
|
967
|
-
if (!ofType)
|
|
968
|
-
throw new Error("Valid types for block children not found in schema (required)");
|
|
969
|
-
const spanType = ofType.find((memberType) => memberType.name === "span");
|
|
970
|
-
if (!spanType)
|
|
971
|
-
throw new Error("Span type not found in schema (required)");
|
|
972
|
-
const inlineObjectTypes = ofType.filter((memberType) => memberType.name !== "span") || [], blockObjectTypes = portableTextType.of?.filter((field) => field.name !== blockType.name) || [];
|
|
973
|
-
return {
|
|
974
|
-
styles: resolveEnabledStyles(blockType),
|
|
975
|
-
decorators: resolveEnabledDecorators(spanType),
|
|
976
|
-
lists: resolveEnabledListItems(blockType),
|
|
977
|
-
block: blockType,
|
|
978
|
-
span: spanType,
|
|
979
|
-
portableText: portableTextType,
|
|
980
|
-
inlineObjects: inlineObjectTypes,
|
|
981
|
-
blockObjects: blockObjectTypes,
|
|
982
|
-
annotations: spanType.annotations
|
|
983
|
-
};
|
|
984
|
-
}
|
|
985
|
-
function resolveEnabledStyles(blockType) {
|
|
986
|
-
const styleField = blockType.fields?.find((btField) => btField.name === "style");
|
|
987
|
-
if (!styleField)
|
|
988
|
-
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
989
|
-
const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
|
|
990
|
-
if (!textStyles || textStyles.length === 0)
|
|
991
|
-
throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
|
|
992
|
-
return textStyles;
|
|
993
|
-
}
|
|
994
|
-
function resolveEnabledDecorators(spanType) {
|
|
995
|
-
return spanType.decorators;
|
|
996
|
-
}
|
|
997
|
-
function resolveEnabledListItems(blockType) {
|
|
998
|
-
const listField = blockType.fields?.find((btField) => btField.name === "listItem");
|
|
999
|
-
if (!listField)
|
|
1000
|
-
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
1001
|
-
const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
|
|
1002
|
-
if (!listItems)
|
|
1003
|
-
throw new Error("The list field need at least to be an empty array");
|
|
1004
|
-
return listItems;
|
|
1005
|
-
}
|
|
1006
|
-
function findBlockType(type) {
|
|
1007
|
-
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
1008
|
-
}
|
|
1009
1067
|
function compileType(rawType) {
|
|
1010
1068
|
return Schema.compile({
|
|
1011
1069
|
name: "blockTypeSchema",
|
|
@@ -2699,9 +2757,9 @@ function debugState(editor, stateName) {
|
|
|
2699
2757
|
}
|
|
2700
2758
|
function findBlockFromPath(editor, path) {
|
|
2701
2759
|
let blockIndex = -1;
|
|
2702
|
-
const block = editor.children.find((node,
|
|
2703
|
-
const isMatch = isKeyedSegment(path[0]) ? node._key === path[0]._key :
|
|
2704
|
-
return isMatch && (blockIndex =
|
|
2760
|
+
const block = editor.children.find((node, index) => {
|
|
2761
|
+
const isMatch = isKeyedSegment(path[0]) ? node._key === path[0]._key : index === path[0];
|
|
2762
|
+
return isMatch && (blockIndex = index), isMatch;
|
|
2705
2763
|
});
|
|
2706
2764
|
return block ? {
|
|
2707
2765
|
block,
|
|
@@ -2721,9 +2779,9 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
2721
2779
|
childPath: void 0
|
|
2722
2780
|
};
|
|
2723
2781
|
let childIndex = -1;
|
|
2724
|
-
const child = block.children.find((node,
|
|
2725
|
-
const isMatch = isKeyedSegment(path[2]) ? node._key === path[2]._key :
|
|
2726
|
-
return isMatch && (childIndex =
|
|
2782
|
+
const child = block.children.find((node, index) => {
|
|
2783
|
+
const isMatch = isKeyedSegment(path[2]) ? node._key === path[2]._key : index === path[2];
|
|
2784
|
+
return isMatch && (childIndex = index), isMatch;
|
|
2727
2785
|
});
|
|
2728
2786
|
return child ? {
|
|
2729
2787
|
block,
|
|
@@ -2920,9 +2978,9 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2920
2978
|
const {
|
|
2921
2979
|
diffs
|
|
2922
2980
|
} = diffPatch;
|
|
2923
|
-
if (diffs.forEach((diff2,
|
|
2981
|
+
if (diffs.forEach((diff2, index) => {
|
|
2924
2982
|
const [diffType, text] = diff2;
|
|
2925
|
-
diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(
|
|
2983
|
+
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));
|
|
2926
2984
|
}), 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") {
|
|
2927
2985
|
const currentFocus = transformedOperation.properties?.focus ? {
|
|
2928
2986
|
...transformedOperation.properties.focus
|
|
@@ -4016,10 +4074,10 @@ function validateValue(value, types, keyGenerator) {
|
|
|
4016
4074
|
}
|
|
4017
4075
|
},
|
|
4018
4076
|
value
|
|
4019
|
-
} : (value.some((blk,
|
|
4077
|
+
} : (value.some((blk, index) => {
|
|
4020
4078
|
if (!isPlainObject(blk))
|
|
4021
4079
|
return resolution = {
|
|
4022
|
-
patches: [unset([
|
|
4080
|
+
patches: [unset([index])],
|
|
4023
4081
|
description: `Block must be an object, got ${String(blk)}`,
|
|
4024
4082
|
action: "Unset invalid item",
|
|
4025
4083
|
item: blk,
|
|
@@ -4027,7 +4085,7 @@ function validateValue(value, types, keyGenerator) {
|
|
|
4027
4085
|
description: "inputs.portable-text.invalid-value.not-an-object.description",
|
|
4028
4086
|
action: "inputs.portable-text.invalid-value.not-an-object.action",
|
|
4029
4087
|
values: {
|
|
4030
|
-
index
|
|
4088
|
+
index
|
|
4031
4089
|
}
|
|
4032
4090
|
}
|
|
4033
4091
|
}, !0;
|
|
@@ -4036,15 +4094,15 @@ function validateValue(value, types, keyGenerator) {
|
|
|
4036
4094
|
patches: [set({
|
|
4037
4095
|
...blk,
|
|
4038
4096
|
_key: keyGenerator()
|
|
4039
|
-
}, [
|
|
4040
|
-
description: `Block at index ${
|
|
4097
|
+
}, [index])],
|
|
4098
|
+
description: `Block at index ${index} is missing required _key.`,
|
|
4041
4099
|
action: "Set the block with a random _key value",
|
|
4042
4100
|
item: blk,
|
|
4043
4101
|
i18n: {
|
|
4044
4102
|
description: "inputs.portable-text.invalid-value.missing-key.description",
|
|
4045
4103
|
action: "inputs.portable-text.invalid-value.missing-key.action",
|
|
4046
4104
|
values: {
|
|
4047
|
-
index
|
|
4105
|
+
index
|
|
4048
4106
|
}
|
|
4049
4107
|
}
|
|
4050
4108
|
}, !0;
|
|
@@ -4676,9 +4734,9 @@ function useSyncValue(props) {
|
|
|
4676
4734
|
withoutPatching(slateEditor, () => {
|
|
4677
4735
|
hadSelection && Transforms.deselect(slateEditor);
|
|
4678
4736
|
const childrenLength = slateEditor.children.length;
|
|
4679
|
-
slateEditor.children.forEach((_,
|
|
4737
|
+
slateEditor.children.forEach((_, index) => {
|
|
4680
4738
|
Transforms.removeNodes(slateEditor, {
|
|
4681
|
-
at: [childrenLength - 1 -
|
|
4739
|
+
at: [childrenLength - 1 - index]
|
|
4682
4740
|
});
|
|
4683
4741
|
}), Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
|
|
4684
4742
|
decorators: []
|
|
@@ -4783,8 +4841,8 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
4783
4841
|
at: [currentBlockIndex]
|
|
4784
4842
|
}), slateEditor.isTextBlock(currentBlock) && slateEditor.isTextBlock(oldBlock)) {
|
|
4785
4843
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
4786
|
-
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_,
|
|
4787
|
-
const childIndex = oldBlockChildrenLength - 1 -
|
|
4844
|
+
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index) => {
|
|
4845
|
+
const childIndex = oldBlockChildrenLength - 1 - index;
|
|
4788
4846
|
childIndex > 0 && (debug$5("Removing child"), Transforms.removeNodes(slateEditor, {
|
|
4789
4847
|
at: [currentBlockIndex, childIndex]
|
|
4790
4848
|
}));
|
|
@@ -6214,331 +6272,26 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6214
6272
|
) : null;
|
|
6215
6273
|
});
|
|
6216
6274
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
6217
|
-
var index = typeof document < "u" ? useLayoutEffect : useEffect, withSelector = { exports: {} }, withSelector_production_min = {}, shim = { exports: {} }, useSyncExternalStoreShim_production_min = {};
|
|
6218
|
-
/**
|
|
6219
|
-
* @license React
|
|
6220
|
-
* use-sync-external-store-shim.production.min.js
|
|
6221
|
-
*
|
|
6222
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6223
|
-
*
|
|
6224
|
-
* This source code is licensed under the MIT license found in the
|
|
6225
|
-
* LICENSE file in the root directory of this source tree.
|
|
6226
|
-
*/
|
|
6227
|
-
var hasRequiredUseSyncExternalStoreShim_production_min;
|
|
6228
|
-
function requireUseSyncExternalStoreShim_production_min() {
|
|
6229
|
-
if (hasRequiredUseSyncExternalStoreShim_production_min) return useSyncExternalStoreShim_production_min;
|
|
6230
|
-
hasRequiredUseSyncExternalStoreShim_production_min = 1;
|
|
6231
|
-
var e = require$$0;
|
|
6232
|
-
function h(a, b) {
|
|
6233
|
-
return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b;
|
|
6234
|
-
}
|
|
6235
|
-
var k = typeof Object.is == "function" ? Object.is : h, l = e.useState, m = e.useEffect, n = e.useLayoutEffect, p = e.useDebugValue;
|
|
6236
|
-
function q(a, b) {
|
|
6237
|
-
var d = b(), f = l({
|
|
6238
|
-
inst: {
|
|
6239
|
-
value: d,
|
|
6240
|
-
getSnapshot: b
|
|
6241
|
-
}
|
|
6242
|
-
}), c2 = f[0].inst, g = f[1];
|
|
6243
|
-
return n(function() {
|
|
6244
|
-
c2.value = d, c2.getSnapshot = b, r(c2) && g({
|
|
6245
|
-
inst: c2
|
|
6246
|
-
});
|
|
6247
|
-
}, [a, d, b]), m(function() {
|
|
6248
|
-
return r(c2) && g({
|
|
6249
|
-
inst: c2
|
|
6250
|
-
}), a(function() {
|
|
6251
|
-
r(c2) && g({
|
|
6252
|
-
inst: c2
|
|
6253
|
-
});
|
|
6254
|
-
});
|
|
6255
|
-
}, [a]), p(d), d;
|
|
6256
|
-
}
|
|
6257
|
-
function r(a) {
|
|
6258
|
-
var b = a.getSnapshot;
|
|
6259
|
-
a = a.value;
|
|
6260
|
-
try {
|
|
6261
|
-
var d = b();
|
|
6262
|
-
return !k(a, d);
|
|
6263
|
-
} catch {
|
|
6264
|
-
return !0;
|
|
6265
|
-
}
|
|
6266
|
-
}
|
|
6267
|
-
function t(a, b) {
|
|
6268
|
-
return b();
|
|
6269
|
-
}
|
|
6270
|
-
var u = typeof window > "u" || typeof window.document > "u" || typeof window.document.createElement > "u" ? t : q;
|
|
6271
|
-
return useSyncExternalStoreShim_production_min.useSyncExternalStore = e.useSyncExternalStore !== void 0 ? e.useSyncExternalStore : u, useSyncExternalStoreShim_production_min;
|
|
6272
|
-
}
|
|
6273
|
-
var useSyncExternalStoreShim_development = {};
|
|
6274
|
-
/**
|
|
6275
|
-
* @license React
|
|
6276
|
-
* use-sync-external-store-shim.development.js
|
|
6277
|
-
*
|
|
6278
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6279
|
-
*
|
|
6280
|
-
* This source code is licensed under the MIT license found in the
|
|
6281
|
-
* LICENSE file in the root directory of this source tree.
|
|
6282
|
-
*/
|
|
6283
|
-
var hasRequiredUseSyncExternalStoreShim_development;
|
|
6284
|
-
function requireUseSyncExternalStoreShim_development() {
|
|
6285
|
-
return hasRequiredUseSyncExternalStoreShim_development || (hasRequiredUseSyncExternalStoreShim_development = 1, process.env.NODE_ENV !== "production" && function() {
|
|
6286
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
6287
|
-
var React = require$$0, ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
6288
|
-
function error(format) {
|
|
6289
|
-
{
|
|
6290
|
-
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++)
|
|
6291
|
-
args[_key2 - 1] = arguments[_key2];
|
|
6292
|
-
printWarning("error", format, args);
|
|
6293
|
-
}
|
|
6294
|
-
}
|
|
6295
|
-
function printWarning(level, format, args) {
|
|
6296
|
-
{
|
|
6297
|
-
var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame, stack = ReactDebugCurrentFrame.getStackAddendum();
|
|
6298
|
-
stack !== "" && (format += "%s", args = args.concat([stack]));
|
|
6299
|
-
var argsWithFormat = args.map(function(item) {
|
|
6300
|
-
return String(item);
|
|
6301
|
-
});
|
|
6302
|
-
argsWithFormat.unshift("Warning: " + format), Function.prototype.apply.call(console[level], console, argsWithFormat);
|
|
6303
|
-
}
|
|
6304
|
-
}
|
|
6305
|
-
function is(x, y) {
|
|
6306
|
-
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
6307
|
-
}
|
|
6308
|
-
var objectIs = typeof Object.is == "function" ? Object.is : is, useState2 = React.useState, useEffect2 = React.useEffect, useLayoutEffect2 = React.useLayoutEffect, useDebugValue = React.useDebugValue, didWarnOld18Alpha = !1, didWarnUncachedGetSnapshot = !1;
|
|
6309
|
-
function useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
|
|
6310
|
-
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."));
|
|
6311
|
-
var value = getSnapshot();
|
|
6312
|
-
if (!didWarnUncachedGetSnapshot) {
|
|
6313
|
-
var cachedValue = getSnapshot();
|
|
6314
|
-
objectIs(value, cachedValue) || (error("The result of getSnapshot should be cached to avoid an infinite loop"), didWarnUncachedGetSnapshot = !0);
|
|
6315
|
-
}
|
|
6316
|
-
var _useState = useState2({
|
|
6317
|
-
inst: {
|
|
6318
|
-
value,
|
|
6319
|
-
getSnapshot
|
|
6320
|
-
}
|
|
6321
|
-
}), inst = _useState[0].inst, forceUpdate = _useState[1];
|
|
6322
|
-
return useLayoutEffect2(function() {
|
|
6323
|
-
inst.value = value, inst.getSnapshot = getSnapshot, checkIfSnapshotChanged(inst) && forceUpdate({
|
|
6324
|
-
inst
|
|
6325
|
-
});
|
|
6326
|
-
}, [subscribe, value, getSnapshot]), useEffect2(function() {
|
|
6327
|
-
checkIfSnapshotChanged(inst) && forceUpdate({
|
|
6328
|
-
inst
|
|
6329
|
-
});
|
|
6330
|
-
var handleStoreChange = function() {
|
|
6331
|
-
checkIfSnapshotChanged(inst) && forceUpdate({
|
|
6332
|
-
inst
|
|
6333
|
-
});
|
|
6334
|
-
};
|
|
6335
|
-
return subscribe(handleStoreChange);
|
|
6336
|
-
}, [subscribe]), useDebugValue(value), value;
|
|
6337
|
-
}
|
|
6338
|
-
function checkIfSnapshotChanged(inst) {
|
|
6339
|
-
var latestGetSnapshot = inst.getSnapshot, prevValue = inst.value;
|
|
6340
|
-
try {
|
|
6341
|
-
var nextValue = latestGetSnapshot();
|
|
6342
|
-
return !objectIs(prevValue, nextValue);
|
|
6343
|
-
} catch {
|
|
6344
|
-
return !0;
|
|
6345
|
-
}
|
|
6346
|
-
}
|
|
6347
|
-
function useSyncExternalStore$1(subscribe, getSnapshot, getServerSnapshot) {
|
|
6348
|
-
return getSnapshot();
|
|
6349
|
-
}
|
|
6350
|
-
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;
|
|
6351
|
-
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());
|
|
6352
|
-
}()), useSyncExternalStoreShim_development;
|
|
6353
|
-
}
|
|
6354
|
-
var hasRequiredShim;
|
|
6355
|
-
function requireShim() {
|
|
6356
|
-
return hasRequiredShim || (hasRequiredShim = 1, process.env.NODE_ENV === "production" ? shim.exports = requireUseSyncExternalStoreShim_production_min() : shim.exports = requireUseSyncExternalStoreShim_development()), shim.exports;
|
|
6357
|
-
}
|
|
6358
|
-
/**
|
|
6359
|
-
* @license React
|
|
6360
|
-
* use-sync-external-store-shim/with-selector.production.min.js
|
|
6361
|
-
*
|
|
6362
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6363
|
-
*
|
|
6364
|
-
* This source code is licensed under the MIT license found in the
|
|
6365
|
-
* LICENSE file in the root directory of this source tree.
|
|
6366
|
-
*/
|
|
6367
|
-
var hasRequiredWithSelector_production_min;
|
|
6368
|
-
function requireWithSelector_production_min() {
|
|
6369
|
-
if (hasRequiredWithSelector_production_min) return withSelector_production_min;
|
|
6370
|
-
hasRequiredWithSelector_production_min = 1;
|
|
6371
|
-
var h = require$$0, n = requireShim();
|
|
6372
|
-
function p(a, b) {
|
|
6373
|
-
return a === b && (a !== 0 || 1 / a === 1 / b) || a !== a && b !== b;
|
|
6374
|
-
}
|
|
6375
|
-
var q = typeof Object.is == "function" ? Object.is : p, r = n.useSyncExternalStore, t = h.useRef, u = h.useEffect, v = h.useMemo, w = h.useDebugValue;
|
|
6376
|
-
return withSelector_production_min.useSyncExternalStoreWithSelector = function(a, b, e, l, g) {
|
|
6377
|
-
var c2 = t(null);
|
|
6378
|
-
if (c2.current === null) {
|
|
6379
|
-
var f = {
|
|
6380
|
-
hasValue: !1,
|
|
6381
|
-
value: null
|
|
6382
|
-
};
|
|
6383
|
-
c2.current = f;
|
|
6384
|
-
} else f = c2.current;
|
|
6385
|
-
c2 = v(function() {
|
|
6386
|
-
function a2(a3) {
|
|
6387
|
-
if (!c3) {
|
|
6388
|
-
if (c3 = !0, d2 = a3, a3 = l(a3), g !== void 0 && f.hasValue) {
|
|
6389
|
-
var b2 = f.value;
|
|
6390
|
-
if (g(b2, a3)) return k = b2;
|
|
6391
|
-
}
|
|
6392
|
-
return k = a3;
|
|
6393
|
-
}
|
|
6394
|
-
if (b2 = k, q(d2, a3)) return b2;
|
|
6395
|
-
var e2 = l(a3);
|
|
6396
|
-
return g !== void 0 && g(b2, e2) ? b2 : (d2 = a3, k = e2);
|
|
6397
|
-
}
|
|
6398
|
-
var c3 = !1, d2, k, m = e === void 0 ? null : e;
|
|
6399
|
-
return [function() {
|
|
6400
|
-
return a2(b());
|
|
6401
|
-
}, m === null ? void 0 : function() {
|
|
6402
|
-
return a2(m());
|
|
6403
|
-
}];
|
|
6404
|
-
}, [b, e, l, g]);
|
|
6405
|
-
var d = r(a, c2[0], c2[1]);
|
|
6406
|
-
return u(function() {
|
|
6407
|
-
f.hasValue = !0, f.value = d;
|
|
6408
|
-
}, [d]), w(d), d;
|
|
6409
|
-
}, withSelector_production_min;
|
|
6410
|
-
}
|
|
6411
|
-
var withSelector_development = {};
|
|
6412
|
-
/**
|
|
6413
|
-
* @license React
|
|
6414
|
-
* use-sync-external-store-shim/with-selector.development.js
|
|
6415
|
-
*
|
|
6416
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
6417
|
-
*
|
|
6418
|
-
* This source code is licensed under the MIT license found in the
|
|
6419
|
-
* LICENSE file in the root directory of this source tree.
|
|
6420
|
-
*/
|
|
6421
|
-
var hasRequiredWithSelector_development;
|
|
6422
|
-
function requireWithSelector_development() {
|
|
6423
|
-
return hasRequiredWithSelector_development || (hasRequiredWithSelector_development = 1, process.env.NODE_ENV !== "production" && function() {
|
|
6424
|
-
typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
|
|
6425
|
-
var React = require$$0, shim2 = requireShim();
|
|
6426
|
-
function is(x, y) {
|
|
6427
|
-
return x === y && (x !== 0 || 1 / x === 1 / y) || x !== x && y !== y;
|
|
6428
|
-
}
|
|
6429
|
-
var objectIs = typeof Object.is == "function" ? Object.is : is, useSyncExternalStore = shim2.useSyncExternalStore, useRef2 = React.useRef, useEffect2 = React.useEffect, useMemo2 = React.useMemo, useDebugValue = React.useDebugValue;
|
|
6430
|
-
function useSyncExternalStoreWithSelector(subscribe, getSnapshot, getServerSnapshot, selector, isEqual2) {
|
|
6431
|
-
var instRef = useRef2(null), inst;
|
|
6432
|
-
instRef.current === null ? (inst = {
|
|
6433
|
-
hasValue: !1,
|
|
6434
|
-
value: null
|
|
6435
|
-
}, instRef.current = inst) : inst = instRef.current;
|
|
6436
|
-
var _useMemo = useMemo2(function() {
|
|
6437
|
-
var hasMemo = !1, memoizedSnapshot, memoizedSelection, memoizedSelector = function(nextSnapshot) {
|
|
6438
|
-
if (!hasMemo) {
|
|
6439
|
-
hasMemo = !0, memoizedSnapshot = nextSnapshot;
|
|
6440
|
-
var _nextSelection = selector(nextSnapshot);
|
|
6441
|
-
if (isEqual2 !== void 0 && inst.hasValue) {
|
|
6442
|
-
var currentSelection = inst.value;
|
|
6443
|
-
if (isEqual2(currentSelection, _nextSelection))
|
|
6444
|
-
return memoizedSelection = currentSelection, currentSelection;
|
|
6445
|
-
}
|
|
6446
|
-
return memoizedSelection = _nextSelection, _nextSelection;
|
|
6447
|
-
}
|
|
6448
|
-
var prevSnapshot = memoizedSnapshot, prevSelection = memoizedSelection;
|
|
6449
|
-
if (objectIs(prevSnapshot, nextSnapshot))
|
|
6450
|
-
return prevSelection;
|
|
6451
|
-
var nextSelection = selector(nextSnapshot);
|
|
6452
|
-
return isEqual2 !== void 0 && isEqual2(prevSelection, nextSelection) ? prevSelection : (memoizedSnapshot = nextSnapshot, memoizedSelection = nextSelection, nextSelection);
|
|
6453
|
-
}, maybeGetServerSnapshot = getServerSnapshot === void 0 ? null : getServerSnapshot, getSnapshotWithSelector = function() {
|
|
6454
|
-
return memoizedSelector(getSnapshot());
|
|
6455
|
-
}, getServerSnapshotWithSelector = maybeGetServerSnapshot === null ? void 0 : function() {
|
|
6456
|
-
return memoizedSelector(maybeGetServerSnapshot());
|
|
6457
|
-
};
|
|
6458
|
-
return [getSnapshotWithSelector, getServerSnapshotWithSelector];
|
|
6459
|
-
}, [getSnapshot, getServerSnapshot, selector, isEqual2]), getSelection = _useMemo[0], getServerSelection = _useMemo[1], value = useSyncExternalStore(subscribe, getSelection, getServerSelection);
|
|
6460
|
-
return useEffect2(function() {
|
|
6461
|
-
inst.hasValue = !0, inst.value = value;
|
|
6462
|
-
}, [value]), useDebugValue(value), value;
|
|
6463
|
-
}
|
|
6464
|
-
withSelector_development.useSyncExternalStoreWithSelector = useSyncExternalStoreWithSelector, typeof __REACT_DEVTOOLS_GLOBAL_HOOK__ < "u" && typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop == "function" && __REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStop(new Error());
|
|
6465
|
-
}()), withSelector_development;
|
|
6466
|
-
}
|
|
6467
|
-
var hasRequiredWithSelector;
|
|
6468
|
-
function requireWithSelector() {
|
|
6469
|
-
return hasRequiredWithSelector || (hasRequiredWithSelector = 1, process.env.NODE_ENV === "production" ? withSelector.exports = requireWithSelector_production_min() : withSelector.exports = requireWithSelector_development()), withSelector.exports;
|
|
6470
|
-
}
|
|
6471
|
-
requireWithSelector();
|
|
6472
|
-
requireShim();
|
|
6473
|
-
const forEachActor = (actorRef, callback) => {
|
|
6474
|
-
callback(actorRef);
|
|
6475
|
-
const children = actorRef.getSnapshot().children;
|
|
6476
|
-
children && Object.values(children).forEach((child) => {
|
|
6477
|
-
forEachActor(child, callback);
|
|
6478
|
-
});
|
|
6479
|
-
};
|
|
6480
|
-
function stopRootWithRehydration(actorRef) {
|
|
6481
|
-
const persistedSnapshots = [];
|
|
6482
|
-
forEachActor(actorRef, (ref) => {
|
|
6483
|
-
persistedSnapshots.push([ref, ref.getSnapshot()]), ref.observers = /* @__PURE__ */ new Set();
|
|
6484
|
-
});
|
|
6485
|
-
const systemSnapshot = actorRef.system.getSnapshot?.();
|
|
6486
|
-
actorRef.stop(), actorRef.system._snapshot = systemSnapshot, persistedSnapshots.forEach(([ref, snapshot]) => {
|
|
6487
|
-
ref._processingStatus = 0, ref._snapshot = snapshot;
|
|
6488
|
-
});
|
|
6489
|
-
}
|
|
6490
|
-
function useIdleActorRef(logic, ...[options]) {
|
|
6491
|
-
let [[currentConfig, actorRef], setCurrent] = useState(() => {
|
|
6492
|
-
const actorRef2 = createActor(logic, options);
|
|
6493
|
-
return [logic.config, actorRef2];
|
|
6494
|
-
});
|
|
6495
|
-
if (logic.config !== currentConfig) {
|
|
6496
|
-
const newActorRef = createActor(logic, {
|
|
6497
|
-
...options,
|
|
6498
|
-
snapshot: actorRef.getPersistedSnapshot({
|
|
6499
|
-
__unsafeAllowInlineActors: !0
|
|
6500
|
-
})
|
|
6501
|
-
});
|
|
6502
|
-
setCurrent([logic.config, newActorRef]), actorRef = newActorRef;
|
|
6503
|
-
}
|
|
6504
|
-
return index(() => {
|
|
6505
|
-
actorRef.logic.implementations = logic.implementations;
|
|
6506
|
-
}), actorRef;
|
|
6507
|
-
}
|
|
6508
|
-
function useActorRef(machine, ...[options, observerOrListener]) {
|
|
6509
|
-
const actorRef = useIdleActorRef(machine, options);
|
|
6510
|
-
return useEffect(() => {
|
|
6511
|
-
if (!observerOrListener)
|
|
6512
|
-
return;
|
|
6513
|
-
let sub = actorRef.subscribe(toObserver(observerOrListener));
|
|
6514
|
-
return () => {
|
|
6515
|
-
sub.unsubscribe();
|
|
6516
|
-
};
|
|
6517
|
-
}, [observerOrListener]), useEffect(() => (actorRef.start(), () => {
|
|
6518
|
-
stopRootWithRehydration(actorRef);
|
|
6519
|
-
}), [actorRef]), actorRef;
|
|
6520
|
-
}
|
|
6521
6275
|
function useEditor(config) {
|
|
6522
|
-
const $ = c(
|
|
6276
|
+
const $ = c(7);
|
|
6523
6277
|
let t0;
|
|
6524
|
-
$[0] !== config.schema ? (t0 = config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema), $[0] = config.
|
|
6525
|
-
|
|
6526
|
-
|
|
6527
|
-
|
|
6528
|
-
let t3;
|
|
6529
|
-
return $[4] !== config.behaviors || $[5] !== t2 || $[6] !== schema ? (t3 = {
|
|
6278
|
+
$[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];
|
|
6279
|
+
const schema = t0, t1 = config.keyGenerator ?? defaultKeyGenerator;
|
|
6280
|
+
let t2;
|
|
6281
|
+
return $[3] !== config.behaviors || $[4] !== t1 || $[5] !== schema ? (t2 = {
|
|
6530
6282
|
input: {
|
|
6531
6283
|
behaviors: config.behaviors,
|
|
6532
|
-
keyGenerator:
|
|
6284
|
+
keyGenerator: t1,
|
|
6533
6285
|
schema
|
|
6534
6286
|
}
|
|
6535
|
-
}, $[
|
|
6287
|
+
}, $[3] = config.behaviors, $[4] = t1, $[5] = schema, $[6] = t2) : t2 = $[6], useActorRef(editorMachine, t2);
|
|
6536
6288
|
}
|
|
6537
6289
|
export {
|
|
6538
6290
|
PortableTextEditable,
|
|
6539
6291
|
PortableTextEditor,
|
|
6540
6292
|
createMarkdownBehaviors,
|
|
6541
6293
|
defineBehavior,
|
|
6294
|
+
defineSchema,
|
|
6542
6295
|
editorMachine,
|
|
6543
6296
|
defaultKeyGenerator as keyGenerator,
|
|
6544
6297
|
useEditor,
|