@portabletext/editor 1.3.0 → 1.4.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 +2805 -44
- package/lib/index.d.ts +2805 -44
- package/lib/index.esm.js +866 -372
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +928 -434
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +866 -372
- package/lib/index.mjs.map +1 -1
- package/package.json +2 -2
- package/src/editor/PortableTextEditor.tsx +160 -99
- package/src/editor/behavior/behavior.markdown.ts +203 -0
- package/src/editor/components/SlateContainer.tsx +2 -13
- package/src/editor/components/Synchronizer.tsx +25 -28
- package/src/editor/editor-machine.ts +27 -2
- package/src/editor/plugins/createWithPatches.ts +8 -13
- package/src/editor/plugins/createWithUndoRedo.ts +34 -33
- package/src/editor/plugins/index.ts +2 -4
- package/src/editor/use-editor.ts +45 -0
- package/src/index.ts +15 -8
- package/src/types/options.ts +0 -2
package/lib/index.js
CHANGED
|
@@ -1,10 +1,250 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var jsxRuntime = require("react/jsx-runtime"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"),
|
|
3
|
+
var types = require("@sanity/types"), jsxRuntime = require("react/jsx-runtime"), isEqual = require("lodash/isEqual.js"), noop = require("lodash/noop.js"), require$$0 = 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"), schema = require("@sanity/schema"), 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");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
7
|
-
var 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);
|
|
7
|
+
var isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), require$$0__default = /* @__PURE__ */ _interopDefaultCompat(require$$0), 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
|
+
function defineBehavior(behavior) {
|
|
9
|
+
return behavior;
|
|
10
|
+
}
|
|
11
|
+
function selectionIsCollapsed(context) {
|
|
12
|
+
return context.selection?.anchor.path.join() === context.selection?.focus.path.join() && context.selection?.anchor.offset === context.selection?.focus.offset;
|
|
13
|
+
}
|
|
14
|
+
function getFocusBlock(context) {
|
|
15
|
+
const key = context.selection && types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
16
|
+
return node && key ? {
|
|
17
|
+
node,
|
|
18
|
+
path: [{
|
|
19
|
+
_key: key
|
|
20
|
+
}]
|
|
21
|
+
} : void 0;
|
|
22
|
+
}
|
|
23
|
+
function getFocusTextBlock(context) {
|
|
24
|
+
const focusBlock = getFocusBlock(context);
|
|
25
|
+
return focusBlock && types.isPortableTextTextBlock(focusBlock.node) ? {
|
|
26
|
+
node: focusBlock.node,
|
|
27
|
+
path: focusBlock.path
|
|
28
|
+
} : void 0;
|
|
29
|
+
}
|
|
30
|
+
function getFocusBlockObject(context) {
|
|
31
|
+
const focusBlock = getFocusBlock(context);
|
|
32
|
+
return focusBlock && !types.isPortableTextTextBlock(focusBlock.node) ? {
|
|
33
|
+
node: focusBlock.node,
|
|
34
|
+
path: focusBlock.path
|
|
35
|
+
} : void 0;
|
|
36
|
+
}
|
|
37
|
+
function getFocusChild(context) {
|
|
38
|
+
const focusBlock = getFocusTextBlock(context);
|
|
39
|
+
if (!focusBlock)
|
|
40
|
+
return;
|
|
41
|
+
const key = context.selection && types.isKeySegment(context.selection.focus.path[2]) ? context.selection.focus.path[2]._key : void 0, node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
|
|
42
|
+
return node && key ? {
|
|
43
|
+
node,
|
|
44
|
+
path: [...focusBlock.path, "children", {
|
|
45
|
+
_key: key
|
|
46
|
+
}]
|
|
47
|
+
} : void 0;
|
|
48
|
+
}
|
|
49
|
+
function getFocusSpan(context) {
|
|
50
|
+
const focusChild = getFocusChild(context);
|
|
51
|
+
return focusChild && types.isPortableTextSpan(focusChild.node) ? {
|
|
52
|
+
node: focusChild.node,
|
|
53
|
+
path: focusChild.path
|
|
54
|
+
} : void 0;
|
|
55
|
+
}
|
|
56
|
+
function getSelectionStartBlock(context) {
|
|
57
|
+
const key = context.selection.backward ? types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0 : types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
58
|
+
return node && key ? {
|
|
59
|
+
node,
|
|
60
|
+
path: [{
|
|
61
|
+
_key: key
|
|
62
|
+
}]
|
|
63
|
+
} : void 0;
|
|
64
|
+
}
|
|
65
|
+
function getSelectionEndBlock(context) {
|
|
66
|
+
const key = context.selection.backward ? types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0 : types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
67
|
+
return node && key ? {
|
|
68
|
+
node,
|
|
69
|
+
path: [{
|
|
70
|
+
_key: key
|
|
71
|
+
}]
|
|
72
|
+
} : void 0;
|
|
73
|
+
}
|
|
74
|
+
function getPreviousBlock(context) {
|
|
75
|
+
let previousBlock;
|
|
76
|
+
const selectionStartBlock = getSelectionStartBlock(context);
|
|
77
|
+
if (!selectionStartBlock)
|
|
78
|
+
return;
|
|
79
|
+
let foundSelectionStartBlock = !1;
|
|
80
|
+
for (const block of context.value) {
|
|
81
|
+
if (block._key === selectionStartBlock.node._key) {
|
|
82
|
+
foundSelectionStartBlock = !0;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
previousBlock = {
|
|
86
|
+
node: block,
|
|
87
|
+
path: [{
|
|
88
|
+
_key: block._key
|
|
89
|
+
}]
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (foundSelectionStartBlock && previousBlock)
|
|
93
|
+
return previousBlock;
|
|
94
|
+
}
|
|
95
|
+
function getNextBlock(context) {
|
|
96
|
+
let nextBlock;
|
|
97
|
+
const selectionEndBlock = getSelectionEndBlock(context);
|
|
98
|
+
if (!selectionEndBlock)
|
|
99
|
+
return;
|
|
100
|
+
let foundSelectionEndBlock = !1;
|
|
101
|
+
for (const block of context.value) {
|
|
102
|
+
if (block._key === selectionEndBlock.node._key) {
|
|
103
|
+
foundSelectionEndBlock = !0;
|
|
104
|
+
continue;
|
|
105
|
+
}
|
|
106
|
+
if (foundSelectionEndBlock) {
|
|
107
|
+
nextBlock = {
|
|
108
|
+
node: block,
|
|
109
|
+
path: [{
|
|
110
|
+
_key: block._key
|
|
111
|
+
}]
|
|
112
|
+
};
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
if (foundSelectionEndBlock && nextBlock)
|
|
117
|
+
return nextBlock;
|
|
118
|
+
}
|
|
119
|
+
function isEmptyTextBlock(block) {
|
|
120
|
+
return block.children.length === 1 && block.children[0].text === "";
|
|
121
|
+
}
|
|
122
|
+
function createMarkdownBehaviors(config) {
|
|
123
|
+
const automaticStyleOnSpace = {
|
|
124
|
+
on: "insert text",
|
|
125
|
+
guard: ({
|
|
126
|
+
context,
|
|
127
|
+
event
|
|
128
|
+
}) => {
|
|
129
|
+
if (event.text !== " ")
|
|
130
|
+
return !1;
|
|
131
|
+
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
132
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
133
|
+
return !1;
|
|
134
|
+
const looksLikeMarkdownHeading = /^#+/.test(focusSpan.node.text), headingStyle = config.mapHeadingStyle(context.schema, focusSpan.node.text.length), looksLikeMarkdownQuote = /^>/.test(focusSpan.node.text), blockquoteStyle = config.mapBlockquoteStyle(context.schema);
|
|
135
|
+
return looksLikeMarkdownHeading && headingStyle !== void 0 ? {
|
|
136
|
+
focusTextBlock,
|
|
137
|
+
focusSpan,
|
|
138
|
+
style: headingStyle
|
|
139
|
+
} : looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
|
|
140
|
+
focusTextBlock,
|
|
141
|
+
focusSpan,
|
|
142
|
+
style: blockquoteStyle
|
|
143
|
+
} : !1;
|
|
144
|
+
},
|
|
145
|
+
actions: [() => [{
|
|
146
|
+
type: "insert text",
|
|
147
|
+
text: " "
|
|
148
|
+
}], (_, {
|
|
149
|
+
focusTextBlock,
|
|
150
|
+
focusSpan,
|
|
151
|
+
style
|
|
152
|
+
}) => [{
|
|
153
|
+
type: "set block",
|
|
154
|
+
style,
|
|
155
|
+
paths: [focusTextBlock.path]
|
|
156
|
+
}, {
|
|
157
|
+
type: "delete",
|
|
158
|
+
selection: {
|
|
159
|
+
anchor: {
|
|
160
|
+
path: focusSpan.path,
|
|
161
|
+
offset: 0
|
|
162
|
+
},
|
|
163
|
+
focus: {
|
|
164
|
+
path: focusSpan.path,
|
|
165
|
+
offset: focusSpan.node.text.length + 1
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}]]
|
|
169
|
+
}, clearStyleOnBackspace = {
|
|
170
|
+
on: "delete backward",
|
|
171
|
+
guard: ({
|
|
172
|
+
context
|
|
173
|
+
}) => {
|
|
174
|
+
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
175
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
176
|
+
return !1;
|
|
177
|
+
const defaultStyle = config.mapDefaultStyle(context.schema);
|
|
178
|
+
return defaultStyle && focusTextBlock.node.children.length === 1 && focusTextBlock.node.style !== config.mapDefaultStyle(context.schema) && focusSpan.node.text === "" ? {
|
|
179
|
+
defaultStyle,
|
|
180
|
+
focusTextBlock
|
|
181
|
+
} : !1;
|
|
182
|
+
},
|
|
183
|
+
actions: [(_, {
|
|
184
|
+
defaultStyle,
|
|
185
|
+
focusTextBlock
|
|
186
|
+
}) => [{
|
|
187
|
+
type: "set block",
|
|
188
|
+
style: defaultStyle,
|
|
189
|
+
paths: [focusTextBlock.path]
|
|
190
|
+
}]]
|
|
191
|
+
}, automaticListOnSpace = {
|
|
192
|
+
on: "insert text",
|
|
193
|
+
guard: ({
|
|
194
|
+
context,
|
|
195
|
+
event
|
|
196
|
+
}) => {
|
|
197
|
+
if (event.text !== " ")
|
|
198
|
+
return !1;
|
|
199
|
+
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
200
|
+
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
201
|
+
return !1;
|
|
202
|
+
const looksLikeUnorderedList = /^-/.test(focusSpan.node.text), unorderedListStyle = config.mapUnorderedListStyle(context.schema);
|
|
203
|
+
if (looksLikeUnorderedList && unorderedListStyle !== void 0)
|
|
204
|
+
return {
|
|
205
|
+
focusTextBlock,
|
|
206
|
+
focusSpan,
|
|
207
|
+
listItem: unorderedListStyle
|
|
208
|
+
};
|
|
209
|
+
const looksLikeOrderedList = /^1./.test(focusSpan.node.text), orderedListStyle = config.mapOrderedListStyle(context.schema);
|
|
210
|
+
return looksLikeOrderedList && orderedListStyle !== void 0 ? {
|
|
211
|
+
focusTextBlock,
|
|
212
|
+
focusSpan,
|
|
213
|
+
listItem: orderedListStyle
|
|
214
|
+
} : !1;
|
|
215
|
+
},
|
|
216
|
+
actions: [() => [{
|
|
217
|
+
type: "insert text",
|
|
218
|
+
text: " "
|
|
219
|
+
}], (_, {
|
|
220
|
+
focusTextBlock,
|
|
221
|
+
focusSpan,
|
|
222
|
+
listItem
|
|
223
|
+
}) => [{
|
|
224
|
+
type: "unset block",
|
|
225
|
+
props: ["style"],
|
|
226
|
+
paths: [focusTextBlock.path]
|
|
227
|
+
}, {
|
|
228
|
+
type: "set block",
|
|
229
|
+
listItem,
|
|
230
|
+
level: 1,
|
|
231
|
+
paths: [focusTextBlock.path]
|
|
232
|
+
}, {
|
|
233
|
+
type: "delete",
|
|
234
|
+
selection: {
|
|
235
|
+
anchor: {
|
|
236
|
+
path: focusSpan.path,
|
|
237
|
+
offset: 0
|
|
238
|
+
},
|
|
239
|
+
focus: {
|
|
240
|
+
path: focusSpan.path,
|
|
241
|
+
offset: focusSpan.node.text.length + 1
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}]]
|
|
245
|
+
};
|
|
246
|
+
return [automaticStyleOnSpace, clearStyleOnBackspace, automaticListOnSpace];
|
|
247
|
+
}
|
|
8
248
|
const rootName = "sanity-pte:";
|
|
9
249
|
debug__default.default(rootName);
|
|
10
250
|
function debugWithName(name) {
|
|
@@ -414,15 +654,15 @@ const debug$l = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
414
654
|
element,
|
|
415
655
|
readOnly,
|
|
416
656
|
blockRef
|
|
417
|
-
} = t0, editor = slateReact.useSlateStatic(), dragGhostRef =
|
|
657
|
+
} = t0, editor = slateReact.useSlateStatic(), dragGhostRef = require$$0.useRef(), [isDragOver, setIsDragOver] = require$$0.useState(!1);
|
|
418
658
|
let t1, t2;
|
|
419
659
|
$[0] !== editor || $[1] !== element ? (t2 = slate.Editor.isVoid(editor, element), $[0] = editor, $[1] = element, $[2] = t2) : t2 = $[2], t1 = t2;
|
|
420
660
|
const isVoid = t1;
|
|
421
661
|
let t3, t4;
|
|
422
662
|
$[3] !== editor || $[4] !== element ? (t4 = slate.Editor.isInline(editor, element), $[3] = editor, $[4] = element, $[5] = t4) : t4 = $[5], t3 = t4;
|
|
423
|
-
const isInline = t3, [blockElement, setBlockElement] =
|
|
663
|
+
const isInline = t3, [blockElement, setBlockElement] = require$$0.useState(null);
|
|
424
664
|
let t5, t6;
|
|
425
|
-
$[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]),
|
|
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]), require$$0.useEffect(t5, t6);
|
|
426
666
|
let t7;
|
|
427
667
|
$[11] !== editor || $[12] !== blockElement || $[13] !== element ? (t7 = (event) => {
|
|
428
668
|
const isMyDragOver = IS_DRAGGING_BLOCK_ELEMENT.get(editor);
|
|
@@ -553,9 +793,9 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
553
793
|
renderStyle,
|
|
554
794
|
spellCheck
|
|
555
795
|
}) => {
|
|
556
|
-
const editor = slateReact.useSlateStatic(), selected = slateReact.useSelected(), blockRef =
|
|
796
|
+
const editor = slateReact.useSlateStatic(), selected = slateReact.useSelected(), blockRef = require$$0.useRef(null), inlineBlockObjectRef = require$$0.useRef(null), focused = selected && editor.selection && slate.Range.isCollapsed(editor.selection) || !1, value = require$$0.useMemo(() => fromSlateValue([element], schemaTypes.block.name, KEY_TO_VALUE_ELEMENT.get(editor))[0], [editor, element, schemaTypes.block.name]);
|
|
557
797
|
let renderedBlock = children, className;
|
|
558
|
-
const blockPath =
|
|
798
|
+
const blockPath = require$$0.useMemo(() => [{
|
|
559
799
|
_key: element._key
|
|
560
800
|
}], [element]);
|
|
561
801
|
if (typeof element._type != "string")
|
|
@@ -676,8 +916,8 @@ const EMPTY_ANNOTATIONS = [], inlineBlockStyle = {
|
|
|
676
916
|
] }, element._key);
|
|
677
917
|
};
|
|
678
918
|
Element.displayName = "Element";
|
|
679
|
-
const PortableTextEditorContext =
|
|
680
|
-
const editor =
|
|
919
|
+
const PortableTextEditorContext = require$$0.createContext(null), usePortableTextEditor = () => {
|
|
920
|
+
const editor = require$$0.useContext(PortableTextEditorContext);
|
|
681
921
|
if (!editor)
|
|
682
922
|
throw new Error("The `usePortableTextEditor` hook must be used inside the <PortableTextEditor> component's context.");
|
|
683
923
|
return editor;
|
|
@@ -729,272 +969,31 @@ function resolveEnabledStyles(blockType) {
|
|
|
729
969
|
throw new Error("A field with name 'style' is not defined in the block type (required).");
|
|
730
970
|
const textStyles = styleField.type.options?.list && styleField.type.options.list?.filter((style) => style.value);
|
|
731
971
|
if (!textStyles || textStyles.length === 0)
|
|
732
|
-
throw new Error("The style fields need at least one style defined. I.e: {title: 'Normal', value: 'normal'}.");
|
|
733
|
-
return textStyles;
|
|
734
|
-
}
|
|
735
|
-
function resolveEnabledDecorators(spanType) {
|
|
736
|
-
return spanType.decorators;
|
|
737
|
-
}
|
|
738
|
-
function resolveEnabledListItems(blockType) {
|
|
739
|
-
const listField = blockType.fields?.find((btField) => btField.name === "listItem");
|
|
740
|
-
if (!listField)
|
|
741
|
-
throw new Error("A field with name 'listItem' is not defined in the block type (required).");
|
|
742
|
-
const listItems = listField.type.options?.list && listField.type.options.list.filter((list) => list.value);
|
|
743
|
-
if (!listItems)
|
|
744
|
-
throw new Error("The list field need at least to be an empty array");
|
|
745
|
-
return listItems;
|
|
746
|
-
}
|
|
747
|
-
function findBlockType(type) {
|
|
748
|
-
return type.type ? findBlockType(type.type) : type.name === "block" ? type : null;
|
|
749
|
-
}
|
|
750
|
-
function compileType(rawType) {
|
|
751
|
-
return schema.Schema.compile({
|
|
752
|
-
name: "blockTypeSchema",
|
|
753
|
-
types: [rawType]
|
|
754
|
-
}).get(rawType.name);
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
return context.selection?.anchor.path.join() === context.selection?.focus.path.join() && context.selection?.anchor.offset === context.selection?.focus.offset;
|
|
758
|
-
}
|
|
759
|
-
function getFocusBlock(context) {
|
|
760
|
-
const key = context.selection && types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
761
|
-
return node && key ? {
|
|
762
|
-
node,
|
|
763
|
-
path: [{
|
|
764
|
-
_key: key
|
|
765
|
-
}]
|
|
766
|
-
} : void 0;
|
|
767
|
-
}
|
|
768
|
-
function getFocusTextBlock(context) {
|
|
769
|
-
const focusBlock = getFocusBlock(context);
|
|
770
|
-
return focusBlock && types.isPortableTextTextBlock(focusBlock.node) ? {
|
|
771
|
-
node: focusBlock.node,
|
|
772
|
-
path: focusBlock.path
|
|
773
|
-
} : void 0;
|
|
774
|
-
}
|
|
775
|
-
function getFocusBlockObject(context) {
|
|
776
|
-
const focusBlock = getFocusBlock(context);
|
|
777
|
-
return focusBlock && !types.isPortableTextTextBlock(focusBlock.node) ? {
|
|
778
|
-
node: focusBlock.node,
|
|
779
|
-
path: focusBlock.path
|
|
780
|
-
} : void 0;
|
|
781
|
-
}
|
|
782
|
-
function getFocusChild(context) {
|
|
783
|
-
const focusBlock = getFocusTextBlock(context);
|
|
784
|
-
if (!focusBlock)
|
|
785
|
-
return;
|
|
786
|
-
const key = context.selection && types.isKeySegment(context.selection.focus.path[2]) ? context.selection.focus.path[2]._key : void 0, node = key ? focusBlock.node.children.find((span) => span._key === key) : void 0;
|
|
787
|
-
return node && key ? {
|
|
788
|
-
node,
|
|
789
|
-
path: [...focusBlock.path, "children", {
|
|
790
|
-
_key: key
|
|
791
|
-
}]
|
|
792
|
-
} : void 0;
|
|
793
|
-
}
|
|
794
|
-
function getFocusSpan(context) {
|
|
795
|
-
const focusChild = getFocusChild(context);
|
|
796
|
-
return focusChild && types.isPortableTextSpan(focusChild.node) ? {
|
|
797
|
-
node: focusChild.node,
|
|
798
|
-
path: focusChild.path
|
|
799
|
-
} : void 0;
|
|
800
|
-
}
|
|
801
|
-
function getSelectionStartBlock(context) {
|
|
802
|
-
const key = context.selection.backward ? types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0 : types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
803
|
-
return node && key ? {
|
|
804
|
-
node,
|
|
805
|
-
path: [{
|
|
806
|
-
_key: key
|
|
807
|
-
}]
|
|
808
|
-
} : void 0;
|
|
809
|
-
}
|
|
810
|
-
function getSelectionEndBlock(context) {
|
|
811
|
-
const key = context.selection.backward ? types.isKeySegment(context.selection.anchor.path[0]) ? context.selection.anchor.path[0]._key : void 0 : types.isKeySegment(context.selection.focus.path[0]) ? context.selection.focus.path[0]._key : void 0, node = key ? context.value.find((block) => block._key === key) : void 0;
|
|
812
|
-
return node && key ? {
|
|
813
|
-
node,
|
|
814
|
-
path: [{
|
|
815
|
-
_key: key
|
|
816
|
-
}]
|
|
817
|
-
} : void 0;
|
|
818
|
-
}
|
|
819
|
-
function getPreviousBlock(context) {
|
|
820
|
-
let previousBlock;
|
|
821
|
-
const selectionStartBlock = getSelectionStartBlock(context);
|
|
822
|
-
if (!selectionStartBlock)
|
|
823
|
-
return;
|
|
824
|
-
let foundSelectionStartBlock = !1;
|
|
825
|
-
for (const block of context.value) {
|
|
826
|
-
if (block._key === selectionStartBlock.node._key) {
|
|
827
|
-
foundSelectionStartBlock = !0;
|
|
828
|
-
break;
|
|
829
|
-
}
|
|
830
|
-
previousBlock = {
|
|
831
|
-
node: block,
|
|
832
|
-
path: [{
|
|
833
|
-
_key: block._key
|
|
834
|
-
}]
|
|
835
|
-
};
|
|
836
|
-
}
|
|
837
|
-
if (foundSelectionStartBlock && previousBlock)
|
|
838
|
-
return previousBlock;
|
|
839
|
-
}
|
|
840
|
-
function getNextBlock(context) {
|
|
841
|
-
let nextBlock;
|
|
842
|
-
const selectionEndBlock = getSelectionEndBlock(context);
|
|
843
|
-
if (!selectionEndBlock)
|
|
844
|
-
return;
|
|
845
|
-
let foundSelectionEndBlock = !1;
|
|
846
|
-
for (const block of context.value) {
|
|
847
|
-
if (block._key === selectionEndBlock.node._key) {
|
|
848
|
-
foundSelectionEndBlock = !0;
|
|
849
|
-
continue;
|
|
850
|
-
}
|
|
851
|
-
if (foundSelectionEndBlock) {
|
|
852
|
-
nextBlock = {
|
|
853
|
-
node: block,
|
|
854
|
-
path: [{
|
|
855
|
-
_key: block._key
|
|
856
|
-
}]
|
|
857
|
-
};
|
|
858
|
-
break;
|
|
859
|
-
}
|
|
860
|
-
}
|
|
861
|
-
if (foundSelectionEndBlock && nextBlock)
|
|
862
|
-
return nextBlock;
|
|
863
|
-
}
|
|
864
|
-
function isEmptyTextBlock(block) {
|
|
865
|
-
return block.children.length === 1 && block.children[0].text === "";
|
|
866
|
-
}
|
|
867
|
-
const breakingVoidBlock = {
|
|
868
|
-
on: "insert break",
|
|
869
|
-
guard: ({
|
|
870
|
-
context
|
|
871
|
-
}) => !!getFocusBlockObject(context),
|
|
872
|
-
actions: [() => [{
|
|
873
|
-
type: "insert text block",
|
|
874
|
-
decorators: []
|
|
875
|
-
}]]
|
|
876
|
-
}, deletingEmptyTextBlockAfterBlockObject = {
|
|
877
|
-
on: "delete backward",
|
|
878
|
-
guard: ({
|
|
879
|
-
context
|
|
880
|
-
}) => {
|
|
881
|
-
const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), previousBlock = getPreviousBlock(context);
|
|
882
|
-
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(previousBlock.node) ? {
|
|
883
|
-
focusTextBlock,
|
|
884
|
-
previousBlock
|
|
885
|
-
} : !1;
|
|
886
|
-
},
|
|
887
|
-
actions: [(_, {
|
|
888
|
-
focusTextBlock,
|
|
889
|
-
previousBlock
|
|
890
|
-
}) => [{
|
|
891
|
-
type: "delete",
|
|
892
|
-
selection: {
|
|
893
|
-
anchor: {
|
|
894
|
-
path: focusTextBlock.path,
|
|
895
|
-
offset: 0
|
|
896
|
-
},
|
|
897
|
-
focus: {
|
|
898
|
-
path: focusTextBlock.path,
|
|
899
|
-
offset: 0
|
|
900
|
-
}
|
|
901
|
-
}
|
|
902
|
-
}, {
|
|
903
|
-
type: "select",
|
|
904
|
-
selection: {
|
|
905
|
-
anchor: {
|
|
906
|
-
path: previousBlock.path,
|
|
907
|
-
offset: 0
|
|
908
|
-
},
|
|
909
|
-
focus: {
|
|
910
|
-
path: previousBlock.path,
|
|
911
|
-
offset: 0
|
|
912
|
-
}
|
|
913
|
-
}
|
|
914
|
-
}]]
|
|
915
|
-
}, deletingEmptyTextBlockBeforeBlockObject = {
|
|
916
|
-
on: "delete forward",
|
|
917
|
-
guard: ({
|
|
918
|
-
context
|
|
919
|
-
}) => {
|
|
920
|
-
const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), nextBlock = getNextBlock(context);
|
|
921
|
-
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(nextBlock.node) ? {
|
|
922
|
-
focusTextBlock,
|
|
923
|
-
nextBlock
|
|
924
|
-
} : !1;
|
|
925
|
-
},
|
|
926
|
-
actions: [(_, {
|
|
927
|
-
focusTextBlock,
|
|
928
|
-
nextBlock
|
|
929
|
-
}) => [{
|
|
930
|
-
type: "delete",
|
|
931
|
-
selection: {
|
|
932
|
-
anchor: {
|
|
933
|
-
path: focusTextBlock.path,
|
|
934
|
-
offset: 0
|
|
935
|
-
},
|
|
936
|
-
focus: {
|
|
937
|
-
path: focusTextBlock.path,
|
|
938
|
-
offset: 0
|
|
939
|
-
}
|
|
940
|
-
}
|
|
941
|
-
}, {
|
|
942
|
-
type: "select",
|
|
943
|
-
selection: {
|
|
944
|
-
anchor: {
|
|
945
|
-
path: nextBlock.path,
|
|
946
|
-
offset: 0
|
|
947
|
-
},
|
|
948
|
-
focus: {
|
|
949
|
-
path: nextBlock.path,
|
|
950
|
-
offset: 0
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
}]]
|
|
954
|
-
}, coreBlockObjectBehaviors = [breakingVoidBlock, deletingEmptyTextBlockAfterBlockObject, deletingEmptyTextBlockBeforeBlockObject], clearListOnBackspace = {
|
|
955
|
-
on: "delete backward",
|
|
956
|
-
guard: ({
|
|
957
|
-
context
|
|
958
|
-
}) => {
|
|
959
|
-
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
960
|
-
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
|
|
961
|
-
focusTextBlock
|
|
962
|
-
} : !1;
|
|
963
|
-
},
|
|
964
|
-
actions: [(_, {
|
|
965
|
-
focusTextBlock
|
|
966
|
-
}) => [{
|
|
967
|
-
type: "unset block",
|
|
968
|
-
props: ["listItem", "level"],
|
|
969
|
-
paths: [focusTextBlock.path]
|
|
970
|
-
}]]
|
|
971
|
-
}, unindentListOnBackspace = {
|
|
972
|
-
on: "delete backward",
|
|
973
|
-
guard: ({
|
|
974
|
-
context
|
|
975
|
-
}) => {
|
|
976
|
-
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
977
|
-
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
|
|
978
|
-
focusTextBlock,
|
|
979
|
-
level: focusTextBlock.node.level - 1
|
|
980
|
-
} : !1;
|
|
981
|
-
},
|
|
982
|
-
actions: [(_, {
|
|
983
|
-
focusTextBlock,
|
|
984
|
-
level
|
|
985
|
-
}) => [{
|
|
986
|
-
type: "set block",
|
|
987
|
-
level,
|
|
988
|
-
paths: [focusTextBlock.path]
|
|
989
|
-
}]]
|
|
990
|
-
}, coreListBehaviors = [clearListOnBackspace, unindentListOnBackspace], softReturn = {
|
|
991
|
-
on: "insert soft break",
|
|
992
|
-
actions: [() => [{
|
|
993
|
-
type: "insert text",
|
|
994
|
-
text: `
|
|
995
|
-
`
|
|
996
|
-
}]]
|
|
997
|
-
}, coreBehaviors = [softReturn, ...coreBlockObjectBehaviors, ...coreListBehaviors], debug$k = debugWithName("operationToPatches");
|
|
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
|
+
function compileType(rawType) {
|
|
991
|
+
return schema.Schema.compile({
|
|
992
|
+
name: "blockTypeSchema",
|
|
993
|
+
types: [rawType]
|
|
994
|
+
}).get(rawType.name);
|
|
995
|
+
}
|
|
996
|
+
const debug$k = debugWithName("operationToPatches");
|
|
998
997
|
function createOperationToPatches(types2) {
|
|
999
998
|
const textBlockName = types2.block.name;
|
|
1000
999
|
function insertTextPatch(editor, operation, beforeValue) {
|
|
@@ -2681,9 +2680,9 @@ function debugState(editor, stateName) {
|
|
|
2681
2680
|
}
|
|
2682
2681
|
function findBlockFromPath(editor, path) {
|
|
2683
2682
|
let blockIndex = -1;
|
|
2684
|
-
const block = editor.children.find((node,
|
|
2685
|
-
const isMatch = isKeyedSegment(path[0]) ? node._key === path[0]._key :
|
|
2686
|
-
return isMatch && (blockIndex =
|
|
2683
|
+
const block = editor.children.find((node, index2) => {
|
|
2684
|
+
const isMatch = isKeyedSegment(path[0]) ? node._key === path[0]._key : index2 === path[0];
|
|
2685
|
+
return isMatch && (blockIndex = index2), isMatch;
|
|
2687
2686
|
});
|
|
2688
2687
|
return block ? {
|
|
2689
2688
|
block,
|
|
@@ -2703,9 +2702,9 @@ function findBlockAndChildFromPath(editor, path) {
|
|
|
2703
2702
|
childPath: void 0
|
|
2704
2703
|
};
|
|
2705
2704
|
let childIndex = -1;
|
|
2706
|
-
const child = block.children.find((node,
|
|
2707
|
-
const isMatch = isKeyedSegment(path[2]) ? node._key === path[2]._key :
|
|
2708
|
-
return isMatch && (childIndex =
|
|
2705
|
+
const child = block.children.find((node, index2) => {
|
|
2706
|
+
const isMatch = isKeyedSegment(path[2]) ? node._key === path[2]._key : index2 === path[2];
|
|
2707
|
+
return isMatch && (childIndex = index2), isMatch;
|
|
2709
2708
|
});
|
|
2710
2709
|
return child ? {
|
|
2711
2710
|
block,
|
|
@@ -2733,16 +2732,16 @@ const debug$h = debugWithName("plugin:withUndoRedo"), debugVerbose$3 = debug$h.e
|
|
|
2733
2732
|
}, getRemotePatches = (editor) => (REMOTE_PATCHES.get(editor) || REMOTE_PATCHES.set(editor, []), REMOTE_PATCHES.get(editor) || []);
|
|
2734
2733
|
function createWithUndoRedo(options) {
|
|
2735
2734
|
const {
|
|
2735
|
+
editorActor,
|
|
2736
2736
|
readOnly,
|
|
2737
|
-
patches$,
|
|
2738
2737
|
blockSchemaType
|
|
2739
2738
|
} = options;
|
|
2740
2739
|
return (editor) => {
|
|
2741
2740
|
let previousSnapshot = fromSlateValue(editor.children, blockSchemaType.name);
|
|
2742
2741
|
const remotePatches = getRemotePatches(editor);
|
|
2743
|
-
|
|
2742
|
+
editor.subscriptions.push(() => {
|
|
2744
2743
|
debug$h("Subscribing to patches");
|
|
2745
|
-
const sub = patches
|
|
2744
|
+
const sub = editorActor.on("patches", ({
|
|
2746
2745
|
patches: patches2,
|
|
2747
2746
|
snapshot
|
|
2748
2747
|
}) => {
|
|
@@ -2902,9 +2901,9 @@ function transformOperation(editor, patch, operation, snapshot, previousSnapshot
|
|
|
2902
2901
|
const {
|
|
2903
2902
|
diffs
|
|
2904
2903
|
} = diffPatch;
|
|
2905
|
-
if (diffs.forEach((diff2,
|
|
2904
|
+
if (diffs.forEach((diff2, index2) => {
|
|
2906
2905
|
const [diffType, text] = diff2;
|
|
2907
|
-
diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(
|
|
2906
|
+
diffType === DIFF_INSERT ? (adjustOffsetBy += text.length, changedOffset += text.length) : diffType === DIFF_DELETE ? (adjustOffsetBy -= text.length, changedOffset -= text.length) : diffType === DIFF_EQUAL && (diffs.slice(index2).every(([dType]) => dType === DIFF_EQUAL) || (changedOffset += text.length));
|
|
2908
2907
|
}), 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") {
|
|
2909
2908
|
const currentFocus = transformedOperation.properties?.focus ? {
|
|
2910
2909
|
...transformedOperation.properties.focus
|
|
@@ -2982,7 +2981,6 @@ function findOperationTargetBlock(editor, operation) {
|
|
|
2982
2981
|
const debug$g = debugWithName("plugin:withPatches");
|
|
2983
2982
|
function createWithPatches({
|
|
2984
2983
|
editorActor,
|
|
2985
|
-
patches$,
|
|
2986
2984
|
patchFunctions,
|
|
2987
2985
|
readOnly,
|
|
2988
2986
|
schemaTypes
|
|
@@ -3018,11 +3016,11 @@ function createWithPatches({
|
|
|
3018
3016
|
const remotePatches = patches2.filter((p) => p.origin !== "local");
|
|
3019
3017
|
remotePatches.length !== 0 && (bufferedPatches = bufferedPatches.concat(remotePatches), handleBufferedRemotePatches());
|
|
3020
3018
|
};
|
|
3021
|
-
return
|
|
3022
|
-
debug$g("Subscribing to patches
|
|
3023
|
-
const sub = patches
|
|
3019
|
+
return editor.subscriptions.push(() => {
|
|
3020
|
+
debug$g("Subscribing to remote patches");
|
|
3021
|
+
const sub = editorActor.on("patches", handlePatches);
|
|
3024
3022
|
return () => {
|
|
3025
|
-
debug$g("Unsubscribing to patches
|
|
3023
|
+
debug$g("Unsubscribing to remote patches"), sub.unsubscribe();
|
|
3026
3024
|
};
|
|
3027
3025
|
}), editor.apply = (operation) => {
|
|
3028
3026
|
if (readOnly)
|
|
@@ -3999,10 +3997,10 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
3999
3997
|
}
|
|
4000
3998
|
},
|
|
4001
3999
|
value
|
|
4002
|
-
} : (value.some((blk,
|
|
4000
|
+
} : (value.some((blk, index2) => {
|
|
4003
4001
|
if (!isPlainObject__default.default(blk))
|
|
4004
4002
|
return resolution = {
|
|
4005
|
-
patches: [patches.unset([
|
|
4003
|
+
patches: [patches.unset([index2])],
|
|
4006
4004
|
description: `Block must be an object, got ${String(blk)}`,
|
|
4007
4005
|
action: "Unset invalid item",
|
|
4008
4006
|
item: blk,
|
|
@@ -4010,7 +4008,7 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
4010
4008
|
description: "inputs.portable-text.invalid-value.not-an-object.description",
|
|
4011
4009
|
action: "inputs.portable-text.invalid-value.not-an-object.action",
|
|
4012
4010
|
values: {
|
|
4013
|
-
index
|
|
4011
|
+
index: index2
|
|
4014
4012
|
}
|
|
4015
4013
|
}
|
|
4016
4014
|
}, !0;
|
|
@@ -4019,15 +4017,15 @@ function validateValue(value, types$1, keyGenerator) {
|
|
|
4019
4017
|
patches: [patches.set({
|
|
4020
4018
|
...blk,
|
|
4021
4019
|
_key: keyGenerator()
|
|
4022
|
-
}, [
|
|
4023
|
-
description: `Block at index ${
|
|
4020
|
+
}, [index2])],
|
|
4021
|
+
description: `Block at index ${index2} is missing required _key.`,
|
|
4024
4022
|
action: "Set the block with a random _key value",
|
|
4025
4023
|
item: blk,
|
|
4026
4024
|
i18n: {
|
|
4027
4025
|
description: "inputs.portable-text.invalid-value.missing-key.description",
|
|
4028
4026
|
action: "inputs.portable-text.invalid-value.missing-key.action",
|
|
4029
4027
|
values: {
|
|
4030
|
-
index
|
|
4028
|
+
index: index2
|
|
4031
4029
|
}
|
|
4032
4030
|
}
|
|
4033
4031
|
}, !0;
|
|
@@ -4511,7 +4509,6 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
|
|
|
4511
4509
|
const e = editor, {
|
|
4512
4510
|
editorActor,
|
|
4513
4511
|
portableTextEditor,
|
|
4514
|
-
patches$,
|
|
4515
4512
|
readOnly,
|
|
4516
4513
|
maxBlocks
|
|
4517
4514
|
} = options, {
|
|
@@ -4527,13 +4524,12 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
|
|
|
4527
4524
|
schemaTypes
|
|
4528
4525
|
}), withEditableAPI = createWithEditableAPI(editorActor, portableTextEditor, schemaTypes), withPatches = createWithPatches({
|
|
4529
4526
|
editorActor,
|
|
4530
|
-
patches$,
|
|
4531
4527
|
patchFunctions: operationToPatches,
|
|
4532
4528
|
readOnly,
|
|
4533
4529
|
schemaTypes
|
|
4534
4530
|
}), withMaxBlocks = createWithMaxBlocks(maxBlocks || -1), withPortableTextLists = createWithPortableTextLists(schemaTypes), withUndoRedo = createWithUndoRedo({
|
|
4531
|
+
editorActor,
|
|
4535
4532
|
readOnly,
|
|
4536
|
-
patches$,
|
|
4537
4533
|
blockSchemaType: schemaTypes.block
|
|
4538
4534
|
}), withPortableTextMarkModel = createWithPortableTextMarkModel(editorActor, schemaTypes), withPortableTextBlockStyle = createWithPortableTextBlockStyle(editorActor, schemaTypes), withPlaceholderBlock = createWithPlaceholderBlock(), withUtils = createWithUtils({
|
|
4539
4535
|
editorActor,
|
|
@@ -4566,15 +4562,14 @@ const originalFnMap = /* @__PURE__ */ new WeakMap(), withPlugins = (editor, opti
|
|
|
4566
4562
|
};
|
|
4567
4563
|
}, debug$6 = debugWithName("component:PortableTextEditor:SlateContainer");
|
|
4568
4564
|
function SlateContainer(props) {
|
|
4569
|
-
const $ = reactCompilerRuntime.c(
|
|
4565
|
+
const $ = reactCompilerRuntime.c(26), {
|
|
4570
4566
|
editorActor,
|
|
4571
|
-
patches$,
|
|
4572
4567
|
portableTextEditor,
|
|
4573
4568
|
readOnly,
|
|
4574
4569
|
maxBlocks
|
|
4575
4570
|
} = props;
|
|
4576
4571
|
let t0;
|
|
4577
|
-
$[0] !== editorActor || $[1] !== maxBlocks || $[2] !==
|
|
4572
|
+
$[0] !== editorActor || $[1] !== maxBlocks || $[2] !== portableTextEditor || $[3] !== readOnly ? (t0 = () => {
|
|
4578
4573
|
debug$6("Creating new Slate editor instance");
|
|
4579
4574
|
const {
|
|
4580
4575
|
editor,
|
|
@@ -4582,47 +4577,45 @@ function SlateContainer(props) {
|
|
|
4582
4577
|
} = withPlugins(slateReact.withReact(slate.createEditor()), {
|
|
4583
4578
|
editorActor,
|
|
4584
4579
|
maxBlocks,
|
|
4585
|
-
patches$,
|
|
4586
4580
|
portableTextEditor,
|
|
4587
4581
|
readOnly
|
|
4588
4582
|
});
|
|
4589
4583
|
return KEY_TO_VALUE_ELEMENT.set(editor, {}), KEY_TO_SLATE_ELEMENT.set(editor, {}), [editor, _sub];
|
|
4590
|
-
}, $[0] = editorActor, $[1] = maxBlocks, $[2] =
|
|
4591
|
-
const [t1] =
|
|
4584
|
+
}, $[0] = editorActor, $[1] = maxBlocks, $[2] = portableTextEditor, $[3] = readOnly, $[4] = t0) : t0 = $[4];
|
|
4585
|
+
const [t1] = require$$0.useState(t0), [slateEditor, subscribe] = t1;
|
|
4592
4586
|
let t2, t3;
|
|
4593
|
-
$[
|
|
4587
|
+
$[5] !== subscribe ? (t2 = () => {
|
|
4594
4588
|
const unsubscribe = subscribe();
|
|
4595
4589
|
return () => {
|
|
4596
4590
|
unsubscribe();
|
|
4597
4591
|
};
|
|
4598
|
-
}, t3 = [subscribe], $[
|
|
4592
|
+
}, t3 = [subscribe], $[5] = subscribe, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), require$$0.useEffect(t2, t3);
|
|
4599
4593
|
let t4, t5;
|
|
4600
|
-
$[
|
|
4594
|
+
$[8] !== slateEditor || $[9] !== editorActor || $[10] !== maxBlocks || $[11] !== portableTextEditor || $[12] !== readOnly ? (t4 = () => {
|
|
4601
4595
|
debug$6("Re-initializing plugin chain"), withPlugins(slateEditor, {
|
|
4602
4596
|
editorActor,
|
|
4603
4597
|
maxBlocks,
|
|
4604
|
-
patches$,
|
|
4605
4598
|
portableTextEditor,
|
|
4606
4599
|
readOnly
|
|
4607
4600
|
});
|
|
4608
|
-
}, t5 = [editorActor, portableTextEditor, maxBlocks, readOnly,
|
|
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]), require$$0.useEffect(t4, t5);
|
|
4609
4602
|
let t6, t7;
|
|
4610
|
-
$[
|
|
4603
|
+
$[15] !== slateEditor ? (t7 = slateEditor.pteCreateTextBlock({
|
|
4611
4604
|
decorators: []
|
|
4612
|
-
}), $[
|
|
4605
|
+
}), $[15] = slateEditor, $[16] = t7) : t7 = $[16];
|
|
4613
4606
|
let t8;
|
|
4614
|
-
$[
|
|
4607
|
+
$[17] !== t7 ? (t8 = [t7], $[17] = t7, $[18] = t8) : t8 = $[18], t6 = t8;
|
|
4615
4608
|
const initialValue = t6;
|
|
4616
4609
|
let t9, t10;
|
|
4617
|
-
$[
|
|
4610
|
+
$[19] !== slateEditor ? (t9 = () => () => {
|
|
4618
4611
|
debug$6("Destroying Slate editor"), slateEditor.destroy();
|
|
4619
|
-
}, t10 = [slateEditor], $[
|
|
4612
|
+
}, t10 = [slateEditor], $[19] = slateEditor, $[20] = t9, $[21] = t10) : (t9 = $[20], t10 = $[21]), require$$0.useEffect(t9, t10);
|
|
4620
4613
|
let t11;
|
|
4621
|
-
return $[
|
|
4614
|
+
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;
|
|
4622
4615
|
}
|
|
4623
4616
|
SlateContainer.displayName = "SlateContainer";
|
|
4624
|
-
const PortableTextEditorReadOnlyContext =
|
|
4625
|
-
const readOnly =
|
|
4617
|
+
const PortableTextEditorReadOnlyContext = require$$0.createContext(!1), usePortableTextEditorReadOnlyStatus = () => {
|
|
4618
|
+
const readOnly = require$$0.useContext(PortableTextEditorReadOnlyContext);
|
|
4626
4619
|
if (readOnly === void 0)
|
|
4627
4620
|
throw new Error("The `usePortableTextEditorReadOnly` hook must be used inside the <PortableTextEditor> component's context.");
|
|
4628
4621
|
return readOnly;
|
|
@@ -4632,18 +4625,18 @@ function useSyncValue(props) {
|
|
|
4632
4625
|
editorActor,
|
|
4633
4626
|
portableTextEditor,
|
|
4634
4627
|
readOnly
|
|
4635
|
-
} = props, schemaTypes = editorActor.getSnapshot().context.schema, previousValue =
|
|
4628
|
+
} = props, schemaTypes = editorActor.getSnapshot().context.schema, previousValue = require$$0.useRef(), slateEditor = slateReact.useSlate(), updateValueFunctionRef = require$$0.useRef(), updateFromCurrentValue = require$$0.useCallback(() => {
|
|
4636
4629
|
const currentValue = CURRENT_VALUE.get(portableTextEditor);
|
|
4637
4630
|
if (previousValue.current === currentValue) {
|
|
4638
4631
|
debug$5("Value is the same object as previous, not need to sync");
|
|
4639
4632
|
return;
|
|
4640
4633
|
}
|
|
4641
4634
|
updateValueFunctionRef.current && currentValue && (debug$5("Updating the value debounced"), updateValueFunctionRef.current(currentValue));
|
|
4642
|
-
}, [portableTextEditor]), updateValueDebounced =
|
|
4635
|
+
}, [portableTextEditor]), updateValueDebounced = require$$0.useMemo(() => debounce__default.default(updateFromCurrentValue, 1e3, {
|
|
4643
4636
|
trailing: !0,
|
|
4644
4637
|
leading: !1
|
|
4645
4638
|
}), [updateFromCurrentValue]);
|
|
4646
|
-
return
|
|
4639
|
+
return require$$0.useMemo(() => {
|
|
4647
4640
|
const updateFunction = (value) => {
|
|
4648
4641
|
CURRENT_VALUE.set(portableTextEditor, value);
|
|
4649
4642
|
const isProcessingLocalChanges = isChangingLocally(slateEditor), isProcessingRemoteChanges = isChangingRemotely(slateEditor);
|
|
@@ -4664,9 +4657,9 @@ function useSyncValue(props) {
|
|
|
4664
4657
|
withoutPatching(slateEditor, () => {
|
|
4665
4658
|
hadSelection && slate.Transforms.deselect(slateEditor);
|
|
4666
4659
|
const childrenLength = slateEditor.children.length;
|
|
4667
|
-
slateEditor.children.forEach((_,
|
|
4660
|
+
slateEditor.children.forEach((_, index2) => {
|
|
4668
4661
|
slate.Transforms.removeNodes(slateEditor, {
|
|
4669
|
-
at: [childrenLength - 1 -
|
|
4662
|
+
at: [childrenLength - 1 - index2]
|
|
4670
4663
|
});
|
|
4671
4664
|
}), slate.Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
|
|
4672
4665
|
decorators: []
|
|
@@ -4771,8 +4764,8 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
4771
4764
|
at: [currentBlockIndex]
|
|
4772
4765
|
}), slateEditor.isTextBlock(currentBlock) && slateEditor.isTextBlock(oldBlock)) {
|
|
4773
4766
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
4774
|
-
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_,
|
|
4775
|
-
const childIndex = oldBlockChildrenLength - 1 -
|
|
4767
|
+
currentBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - currentBlock.children.length)).forEach((_, index2) => {
|
|
4768
|
+
const childIndex = oldBlockChildrenLength - 1 - index2;
|
|
4776
4769
|
childIndex > 0 && (debug$5("Removing child"), slate.Transforms.removeNodes(slateEditor, {
|
|
4777
4770
|
at: [currentBlockIndex, childIndex]
|
|
4778
4771
|
}));
|
|
@@ -4815,20 +4808,28 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
4815
4808
|
}
|
|
4816
4809
|
const debug$4 = debugWithName("component:PortableTextEditor:Synchronizer"), debugVerbose$1 = debug$4.enabled && !1, FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3;
|
|
4817
4810
|
function Synchronizer(props) {
|
|
4818
|
-
const portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), {
|
|
4811
|
+
const $ = reactCompilerRuntime.c(35), portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), {
|
|
4819
4812
|
editorActor,
|
|
4820
4813
|
getValue,
|
|
4821
4814
|
onChange,
|
|
4822
4815
|
value
|
|
4823
|
-
} = props
|
|
4816
|
+
} = props;
|
|
4817
|
+
let t0;
|
|
4818
|
+
$[0] === Symbol.for("react.memo_cache_sentinel") ? (t0 = [], $[0] = t0) : t0 = $[0];
|
|
4819
|
+
const pendingPatches = require$$0.useRef(t0);
|
|
4820
|
+
let t1;
|
|
4821
|
+
$[1] !== editorActor || $[2] !== portableTextEditor || $[3] !== readOnly ? (t1 = {
|
|
4824
4822
|
editorActor,
|
|
4825
4823
|
portableTextEditor,
|
|
4826
4824
|
readOnly
|
|
4827
|
-
}
|
|
4828
|
-
|
|
4825
|
+
}, $[1] = editorActor, $[2] = portableTextEditor, $[3] = readOnly, $[4] = t1) : t1 = $[4];
|
|
4826
|
+
const syncValue = useSyncValue(t1), slateEditor = slateReact.useSlate();
|
|
4827
|
+
let t2, t3;
|
|
4828
|
+
$[5] !== slateEditor ? (t2 = () => {
|
|
4829
4829
|
IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !1);
|
|
4830
|
-
}, [slateEditor]);
|
|
4831
|
-
|
|
4830
|
+
}, t3 = [slateEditor], $[5] = slateEditor, $[6] = t2, $[7] = t3) : (t2 = $[6], t3 = $[7]), require$$0.useEffect(t2, t3);
|
|
4831
|
+
let t4;
|
|
4832
|
+
$[8] !== getValue || $[9] !== editorActor || $[10] !== slateEditor ? (t4 = () => {
|
|
4832
4833
|
if (pendingPatches.current.length > 0) {
|
|
4833
4834
|
debug$4("Flushing pending patches"), debugVerbose$1 && debug$4(`Patches:
|
|
4834
4835
|
${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
@@ -4840,61 +4841,68 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
|
4840
4841
|
}), pendingPatches.current = [];
|
|
4841
4842
|
}
|
|
4842
4843
|
IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !1);
|
|
4843
|
-
}, [editorActor, slateEditor,
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
}
|
|
4848
|
-
onFlushPendingPatchesThrottled();
|
|
4849
|
-
}, FLUSH_PATCHES_THROTTLED_MS, {
|
|
4850
|
-
leading: !1,
|
|
4851
|
-
trailing: !0
|
|
4852
|
-
}), [onFlushPendingPatches, slateEditor]);
|
|
4853
|
-
react.useEffect(() => () => {
|
|
4844
|
+
}, $[8] = getValue, $[9] = editorActor, $[10] = slateEditor, $[11] = t4) : t4 = $[11];
|
|
4845
|
+
const onFlushPendingPatches = t4;
|
|
4846
|
+
let t5, t6;
|
|
4847
|
+
$[12] !== onFlushPendingPatches ? (t5 = () => () => {
|
|
4854
4848
|
onFlushPendingPatches();
|
|
4855
|
-
}, [onFlushPendingPatches]);
|
|
4856
|
-
|
|
4857
|
-
|
|
4849
|
+
}, t6 = [onFlushPendingPatches], $[12] = onFlushPendingPatches, $[13] = t5, $[14] = t6) : (t5 = $[13], t6 = $[14]), require$$0.useEffect(t5, t6);
|
|
4850
|
+
let t7;
|
|
4851
|
+
$[15] !== onChange ? (t7 = (change) => onChange(change), $[15] = onChange, $[16] = t7) : t7 = $[16];
|
|
4852
|
+
const handleChange = useEffectEvent.useEffectEvent(t7);
|
|
4853
|
+
let t8, t9;
|
|
4854
|
+
$[17] !== slateEditor || $[18] !== onFlushPendingPatches || $[19] !== editorActor || $[20] !== handleChange ? (t8 = () => {
|
|
4855
|
+
const onFlushPendingPatchesThrottled = throttle__default.default(() => {
|
|
4856
|
+
if (slate.Editor.isNormalizing(slateEditor)) {
|
|
4857
|
+
onFlushPendingPatches();
|
|
4858
|
+
return;
|
|
4859
|
+
}
|
|
4860
|
+
onFlushPendingPatchesThrottled();
|
|
4861
|
+
}, FLUSH_PATCHES_THROTTLED_MS, {
|
|
4862
|
+
leading: !1,
|
|
4863
|
+
trailing: !0
|
|
4864
|
+
});
|
|
4858
4865
|
debug$4("Subscribing to editor changes");
|
|
4859
4866
|
const sub = editorActor.on("*", (event) => {
|
|
4860
|
-
switch (event.type) {
|
|
4861
|
-
case "patch":
|
|
4867
|
+
bb18: switch (event.type) {
|
|
4868
|
+
case "patch": {
|
|
4862
4869
|
IS_PROCESSING_LOCAL_CHANGES.set(slateEditor, !0), pendingPatches.current.push(event.patch), onFlushPendingPatchesThrottled(), handleChange(event);
|
|
4863
|
-
break;
|
|
4870
|
+
break bb18;
|
|
4871
|
+
}
|
|
4864
4872
|
case "loading": {
|
|
4865
4873
|
handleChange({
|
|
4866
4874
|
type: "loading",
|
|
4867
4875
|
isLoading: !0
|
|
4868
4876
|
});
|
|
4869
|
-
break;
|
|
4877
|
+
break bb18;
|
|
4870
4878
|
}
|
|
4871
4879
|
case "done loading": {
|
|
4872
4880
|
handleChange({
|
|
4873
4881
|
type: "loading",
|
|
4874
4882
|
isLoading: !1
|
|
4875
4883
|
});
|
|
4876
|
-
break;
|
|
4884
|
+
break bb18;
|
|
4877
4885
|
}
|
|
4878
4886
|
case "offline": {
|
|
4879
4887
|
handleChange({
|
|
4880
4888
|
type: "connection",
|
|
4881
4889
|
value: "offline"
|
|
4882
4890
|
});
|
|
4883
|
-
break;
|
|
4891
|
+
break bb18;
|
|
4884
4892
|
}
|
|
4885
4893
|
case "online": {
|
|
4886
4894
|
handleChange({
|
|
4887
4895
|
type: "connection",
|
|
4888
4896
|
value: "online"
|
|
4889
4897
|
});
|
|
4890
|
-
break;
|
|
4898
|
+
break bb18;
|
|
4891
4899
|
}
|
|
4892
4900
|
case "value changed": {
|
|
4893
4901
|
handleChange({
|
|
4894
4902
|
type: "value",
|
|
4895
4903
|
value: event.value
|
|
4896
4904
|
});
|
|
4897
|
-
break;
|
|
4905
|
+
break bb18;
|
|
4898
4906
|
}
|
|
4899
4907
|
case "invalid value": {
|
|
4900
4908
|
handleChange({
|
|
@@ -4902,15 +4910,17 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
|
4902
4910
|
resolution: event.resolution,
|
|
4903
4911
|
value: event.value
|
|
4904
4912
|
});
|
|
4905
|
-
break;
|
|
4913
|
+
break bb18;
|
|
4906
4914
|
}
|
|
4907
4915
|
case "error": {
|
|
4908
4916
|
handleChange({
|
|
4909
4917
|
...event,
|
|
4910
4918
|
level: "warning"
|
|
4911
4919
|
});
|
|
4912
|
-
break;
|
|
4920
|
+
break bb18;
|
|
4913
4921
|
}
|
|
4922
|
+
case "patches":
|
|
4923
|
+
break bb18;
|
|
4914
4924
|
default:
|
|
4915
4925
|
handleChange(event);
|
|
4916
4926
|
}
|
|
@@ -4918,27 +4928,29 @@ ${JSON.stringify(pendingPatches.current, null, 2)}`);
|
|
|
4918
4928
|
return () => {
|
|
4919
4929
|
debug$4("Unsubscribing to changes"), sub.unsubscribe();
|
|
4920
4930
|
};
|
|
4921
|
-
}, [handleChange,
|
|
4922
|
-
|
|
4931
|
+
}, t9 = [editorActor, handleChange, onFlushPendingPatches, slateEditor], $[17] = slateEditor, $[18] = onFlushPendingPatches, $[19] = editorActor, $[20] = handleChange, $[21] = t8, $[22] = t9) : (t8 = $[21], t9 = $[22]), require$$0.useEffect(t8, t9);
|
|
4932
|
+
let t10;
|
|
4933
|
+
$[23] !== syncValue || $[24] !== value ? (t10 = () => {
|
|
4923
4934
|
debug$4("Editor is online, syncing from props.value"), syncValue(value);
|
|
4924
|
-
}, [syncValue, value]);
|
|
4925
|
-
|
|
4926
|
-
|
|
4927
|
-
|
|
4928
|
-
|
|
4935
|
+
}, $[23] = syncValue, $[24] = value, $[25] = t10) : t10 = $[25];
|
|
4936
|
+
const handleOnline = t10;
|
|
4937
|
+
let t11, t12;
|
|
4938
|
+
$[26] !== editorActor || $[27] !== handleOnline ? (t11 = () => {
|
|
4939
|
+
const subscription = editorActor.on("online", handleOnline);
|
|
4929
4940
|
return () => {
|
|
4930
4941
|
subscription.unsubscribe();
|
|
4931
4942
|
};
|
|
4932
|
-
}, [handleOnline, editorActor,
|
|
4933
|
-
const isInitialValueFromProps =
|
|
4934
|
-
|
|
4943
|
+
}, t12 = [handleOnline, editorActor], $[26] = editorActor, $[27] = handleOnline, $[28] = t11, $[29] = t12) : (t11 = $[28], t12 = $[29]), require$$0.useEffect(t11, t12);
|
|
4944
|
+
const isInitialValueFromProps = require$$0.useRef(!0);
|
|
4945
|
+
let t13, t14;
|
|
4946
|
+
return $[30] !== syncValue || $[31] !== value || $[32] !== editorActor ? (t13 = () => {
|
|
4935
4947
|
debug$4("Value from props changed, syncing new value"), syncValue(value), isInitialValueFromProps.current && (editorActor.send({
|
|
4936
4948
|
type: "ready"
|
|
4937
4949
|
}), isInitialValueFromProps.current = !1);
|
|
4938
|
-
}, [editorActor, syncValue, value]), null;
|
|
4950
|
+
}, t14 = [editorActor, syncValue, value], $[30] = syncValue, $[31] = value, $[32] = editorActor, $[33] = t13, $[34] = t14) : (t13 = $[33], t14 = $[34]), require$$0.useEffect(t13, t14), null;
|
|
4939
4951
|
}
|
|
4940
4952
|
Synchronizer.displayName = "Synchronizer";
|
|
4941
|
-
const EditorActorContext =
|
|
4953
|
+
const EditorActorContext = require$$0.createContext({}), insertBreakActionImplementation = ({
|
|
4942
4954
|
context,
|
|
4943
4955
|
action
|
|
4944
4956
|
}) => {
|
|
@@ -5250,7 +5262,137 @@ function performDefaultAction({
|
|
|
5250
5262
|
});
|
|
5251
5263
|
}
|
|
5252
5264
|
}
|
|
5253
|
-
const
|
|
5265
|
+
const breakingVoidBlock = {
|
|
5266
|
+
on: "insert break",
|
|
5267
|
+
guard: ({
|
|
5268
|
+
context
|
|
5269
|
+
}) => !!getFocusBlockObject(context),
|
|
5270
|
+
actions: [() => [{
|
|
5271
|
+
type: "insert text block",
|
|
5272
|
+
decorators: []
|
|
5273
|
+
}]]
|
|
5274
|
+
}, deletingEmptyTextBlockAfterBlockObject = {
|
|
5275
|
+
on: "delete backward",
|
|
5276
|
+
guard: ({
|
|
5277
|
+
context
|
|
5278
|
+
}) => {
|
|
5279
|
+
const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), previousBlock = getPreviousBlock(context);
|
|
5280
|
+
return !focusTextBlock || !selectionCollapsed || !previousBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(previousBlock.node) ? {
|
|
5281
|
+
focusTextBlock,
|
|
5282
|
+
previousBlock
|
|
5283
|
+
} : !1;
|
|
5284
|
+
},
|
|
5285
|
+
actions: [(_, {
|
|
5286
|
+
focusTextBlock,
|
|
5287
|
+
previousBlock
|
|
5288
|
+
}) => [{
|
|
5289
|
+
type: "delete",
|
|
5290
|
+
selection: {
|
|
5291
|
+
anchor: {
|
|
5292
|
+
path: focusTextBlock.path,
|
|
5293
|
+
offset: 0
|
|
5294
|
+
},
|
|
5295
|
+
focus: {
|
|
5296
|
+
path: focusTextBlock.path,
|
|
5297
|
+
offset: 0
|
|
5298
|
+
}
|
|
5299
|
+
}
|
|
5300
|
+
}, {
|
|
5301
|
+
type: "select",
|
|
5302
|
+
selection: {
|
|
5303
|
+
anchor: {
|
|
5304
|
+
path: previousBlock.path,
|
|
5305
|
+
offset: 0
|
|
5306
|
+
},
|
|
5307
|
+
focus: {
|
|
5308
|
+
path: previousBlock.path,
|
|
5309
|
+
offset: 0
|
|
5310
|
+
}
|
|
5311
|
+
}
|
|
5312
|
+
}]]
|
|
5313
|
+
}, deletingEmptyTextBlockBeforeBlockObject = {
|
|
5314
|
+
on: "delete forward",
|
|
5315
|
+
guard: ({
|
|
5316
|
+
context
|
|
5317
|
+
}) => {
|
|
5318
|
+
const focusTextBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context), nextBlock = getNextBlock(context);
|
|
5319
|
+
return !focusTextBlock || !selectionCollapsed || !nextBlock ? !1 : isEmptyTextBlock(focusTextBlock.node) && !types.isPortableTextTextBlock(nextBlock.node) ? {
|
|
5320
|
+
focusTextBlock,
|
|
5321
|
+
nextBlock
|
|
5322
|
+
} : !1;
|
|
5323
|
+
},
|
|
5324
|
+
actions: [(_, {
|
|
5325
|
+
focusTextBlock,
|
|
5326
|
+
nextBlock
|
|
5327
|
+
}) => [{
|
|
5328
|
+
type: "delete",
|
|
5329
|
+
selection: {
|
|
5330
|
+
anchor: {
|
|
5331
|
+
path: focusTextBlock.path,
|
|
5332
|
+
offset: 0
|
|
5333
|
+
},
|
|
5334
|
+
focus: {
|
|
5335
|
+
path: focusTextBlock.path,
|
|
5336
|
+
offset: 0
|
|
5337
|
+
}
|
|
5338
|
+
}
|
|
5339
|
+
}, {
|
|
5340
|
+
type: "select",
|
|
5341
|
+
selection: {
|
|
5342
|
+
anchor: {
|
|
5343
|
+
path: nextBlock.path,
|
|
5344
|
+
offset: 0
|
|
5345
|
+
},
|
|
5346
|
+
focus: {
|
|
5347
|
+
path: nextBlock.path,
|
|
5348
|
+
offset: 0
|
|
5349
|
+
}
|
|
5350
|
+
}
|
|
5351
|
+
}]]
|
|
5352
|
+
}, coreBlockObjectBehaviors = [breakingVoidBlock, deletingEmptyTextBlockAfterBlockObject, deletingEmptyTextBlockBeforeBlockObject], clearListOnBackspace = {
|
|
5353
|
+
on: "delete backward",
|
|
5354
|
+
guard: ({
|
|
5355
|
+
context
|
|
5356
|
+
}) => {
|
|
5357
|
+
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
5358
|
+
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level === 1 ? {
|
|
5359
|
+
focusTextBlock
|
|
5360
|
+
} : !1;
|
|
5361
|
+
},
|
|
5362
|
+
actions: [(_, {
|
|
5363
|
+
focusTextBlock
|
|
5364
|
+
}) => [{
|
|
5365
|
+
type: "unset block",
|
|
5366
|
+
props: ["listItem", "level"],
|
|
5367
|
+
paths: [focusTextBlock.path]
|
|
5368
|
+
}]]
|
|
5369
|
+
}, unindentListOnBackspace = {
|
|
5370
|
+
on: "delete backward",
|
|
5371
|
+
guard: ({
|
|
5372
|
+
context
|
|
5373
|
+
}) => {
|
|
5374
|
+
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
5375
|
+
return !selectionCollapsed || !focusTextBlock || !focusSpan ? !1 : focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0 && focusTextBlock.node.level !== void 0 && focusTextBlock.node.level > 1 ? {
|
|
5376
|
+
focusTextBlock,
|
|
5377
|
+
level: focusTextBlock.node.level - 1
|
|
5378
|
+
} : !1;
|
|
5379
|
+
},
|
|
5380
|
+
actions: [(_, {
|
|
5381
|
+
focusTextBlock,
|
|
5382
|
+
level
|
|
5383
|
+
}) => [{
|
|
5384
|
+
type: "set block",
|
|
5385
|
+
level,
|
|
5386
|
+
paths: [focusTextBlock.path]
|
|
5387
|
+
}]]
|
|
5388
|
+
}, coreListBehaviors = [clearListOnBackspace, unindentListOnBackspace], softReturn = {
|
|
5389
|
+
on: "insert soft break",
|
|
5390
|
+
actions: [() => [{
|
|
5391
|
+
type: "insert text",
|
|
5392
|
+
text: `
|
|
5393
|
+
`
|
|
5394
|
+
}]]
|
|
5395
|
+
}, coreBehaviors = [softReturn, ...coreBlockObjectBehaviors, ...coreListBehaviors], networkLogic = xstate.fromCallback(({
|
|
5254
5396
|
sendBack
|
|
5255
5397
|
}) => {
|
|
5256
5398
|
const onlineHandler = () => {
|
|
@@ -5273,6 +5415,11 @@ const networkLogic = xstate.fromCallback(({
|
|
|
5273
5415
|
input: {}
|
|
5274
5416
|
},
|
|
5275
5417
|
actions: {
|
|
5418
|
+
"assign behaviors": xstate.assign({
|
|
5419
|
+
behaviors: ({
|
|
5420
|
+
event
|
|
5421
|
+
}) => (xstate.assertEvent(event, "update behaviors"), [...coreBehaviors, ...event.behaviors])
|
|
5422
|
+
}),
|
|
5276
5423
|
"assign schema": xstate.assign({
|
|
5277
5424
|
schema: ({
|
|
5278
5425
|
event
|
|
@@ -5365,7 +5512,7 @@ const networkLogic = xstate.fromCallback(({
|
|
|
5365
5512
|
context: ({
|
|
5366
5513
|
input
|
|
5367
5514
|
}) => ({
|
|
5368
|
-
behaviors: input.behaviors,
|
|
5515
|
+
behaviors: input.behaviors ? [...coreBehaviors, ...input.behaviors] : coreBehaviors,
|
|
5369
5516
|
keyGenerator: input.keyGenerator,
|
|
5370
5517
|
pendingEvents: [],
|
|
5371
5518
|
schema: input.schema
|
|
@@ -5430,11 +5577,19 @@ const networkLogic = xstate.fromCallback(({
|
|
|
5430
5577
|
type: "loading"
|
|
5431
5578
|
})
|
|
5432
5579
|
},
|
|
5580
|
+
patches: {
|
|
5581
|
+
actions: xstate.emit(({
|
|
5582
|
+
event
|
|
5583
|
+
}) => event)
|
|
5584
|
+
},
|
|
5433
5585
|
"done loading": {
|
|
5434
5586
|
actions: xstate.emit({
|
|
5435
5587
|
type: "done loading"
|
|
5436
5588
|
})
|
|
5437
5589
|
},
|
|
5590
|
+
"update behaviors": {
|
|
5591
|
+
actions: "assign behaviors"
|
|
5592
|
+
},
|
|
5438
5593
|
"update schema": {
|
|
5439
5594
|
actions: "assign schema"
|
|
5440
5595
|
},
|
|
@@ -5508,31 +5663,31 @@ const networkLogic = xstate.fromCallback(({
|
|
|
5508
5663
|
}
|
|
5509
5664
|
}
|
|
5510
5665
|
}
|
|
5511
|
-
}), PortableTextEditorSelectionContext =
|
|
5512
|
-
const selection =
|
|
5666
|
+
}), PortableTextEditorSelectionContext = require$$0.createContext(null), usePortableTextEditorSelection = () => {
|
|
5667
|
+
const selection = require$$0.useContext(PortableTextEditorSelectionContext);
|
|
5513
5668
|
if (selection === void 0)
|
|
5514
5669
|
throw new Error("The `usePortableTextEditorSelection` hook must be used inside the <PortableTextEditor> component's context.");
|
|
5515
5670
|
return selection;
|
|
5516
5671
|
}, debug$3 = debugWithName("component:PortableTextEditor:SelectionProvider"), debugVerbose = debug$3.enabled && !1;
|
|
5517
5672
|
function PortableTextEditorSelectionProvider(props) {
|
|
5518
|
-
const $ = reactCompilerRuntime.c(6), [selection, setSelection] =
|
|
5673
|
+
const $ = reactCompilerRuntime.c(6), [selection, setSelection] = require$$0.useState(null);
|
|
5519
5674
|
let t0, t1;
|
|
5520
5675
|
$[0] !== props.editorActor ? (t0 = () => {
|
|
5521
5676
|
debug$3("Subscribing to selection changes");
|
|
5522
5677
|
const subscription = props.editorActor.on("selection", (event) => {
|
|
5523
|
-
|
|
5678
|
+
require$$0.startTransition(() => {
|
|
5524
5679
|
debugVerbose && debug$3("Setting selection"), setSelection(event.selection);
|
|
5525
5680
|
});
|
|
5526
5681
|
});
|
|
5527
5682
|
return () => {
|
|
5528
5683
|
debug$3("Unsubscribing to selection changes"), subscription.unsubscribe();
|
|
5529
5684
|
};
|
|
5530
|
-
}, t1 = [props.editorActor], $[0] = props.editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]),
|
|
5685
|
+
}, t1 = [props.editorActor], $[0] = props.editorActor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), require$$0.useEffect(t0, t1);
|
|
5531
5686
|
let t2;
|
|
5532
5687
|
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;
|
|
5533
5688
|
}
|
|
5534
5689
|
const defaultKeyGenerator = () => content.randomKey(12), debug$2 = debugWithName("component:PortableTextEditor");
|
|
5535
|
-
class PortableTextEditor extends
|
|
5690
|
+
class PortableTextEditor extends require$$0.Component {
|
|
5536
5691
|
static displayName = "PortableTextEditor";
|
|
5537
5692
|
/**
|
|
5538
5693
|
* An observable of all the editor changes.
|
|
@@ -5545,18 +5700,21 @@ class PortableTextEditor extends react.Component {
|
|
|
5545
5700
|
* The editor API (currently implemented with Slate).
|
|
5546
5701
|
*/
|
|
5547
5702
|
constructor(props) {
|
|
5548
|
-
if (super(props),
|
|
5549
|
-
|
|
5550
|
-
|
|
5551
|
-
|
|
5552
|
-
|
|
5553
|
-
|
|
5554
|
-
|
|
5555
|
-
|
|
5556
|
-
|
|
5703
|
+
if (super(props), props.editor)
|
|
5704
|
+
this.editorActor = props.editor, this.editorActor.start(), this.schemaTypes = this.editorActor.getSnapshot().context.schema;
|
|
5705
|
+
else {
|
|
5706
|
+
if (!props.schemaType)
|
|
5707
|
+
throw new Error('PortableTextEditor: missing "schemaType" property');
|
|
5708
|
+
props.incomingPatches$ && console.warn("The prop 'incomingPatches$' is deprecated and renamed to 'patches$'"), this.schemaTypes = getPortableTextMemberSchemaTypes(props.schemaType.hasOwnProperty("jsonType") ? props.schemaType : compileType(props.schemaType)), this.editorActor = props.editor ?? xstate.createActor(editorMachine, {
|
|
5709
|
+
input: {
|
|
5710
|
+
keyGenerator: props.keyGenerator || defaultKeyGenerator,
|
|
5711
|
+
schema: this.schemaTypes
|
|
5712
|
+
}
|
|
5713
|
+
}), this.editorActor.start();
|
|
5714
|
+
}
|
|
5557
5715
|
}
|
|
5558
5716
|
componentDidUpdate(prevProps) {
|
|
5559
|
-
this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = getPortableTextMemberSchemaTypes(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editorActor.send({
|
|
5717
|
+
!this.props.editor && !prevProps.editor && this.props.schemaType !== prevProps.schemaType && (this.schemaTypes = getPortableTextMemberSchemaTypes(this.props.schemaType.hasOwnProperty("jsonType") ? this.props.schemaType : compileType(this.props.schemaType)), this.editorActor.send({
|
|
5560
5718
|
type: "update schema",
|
|
5561
5719
|
schema: this.schemaTypes
|
|
5562
5720
|
})), this.props.editorRef !== prevProps.editorRef && this.props.editorRef && (this.props.editorRef.current = this);
|
|
@@ -5572,18 +5730,16 @@ class PortableTextEditor extends react.Component {
|
|
|
5572
5730
|
return this.editable.getValue();
|
|
5573
5731
|
};
|
|
5574
5732
|
render() {
|
|
5575
|
-
const
|
|
5576
|
-
|
|
5577
|
-
|
|
5578
|
-
|
|
5579
|
-
|
|
5580
|
-
|
|
5581
|
-
|
|
5582
|
-
|
|
5583
|
-
|
|
5584
|
-
|
|
5585
|
-
children
|
|
5586
|
-
] }) }) }) }) });
|
|
5733
|
+
const maxBlocks = this.props.editor || typeof this.props.maxBlocks > "u" ? void 0 : Number.parseInt(this.props.maxBlocks.toString(), 10) || void 0, readOnly = !!this.props.readOnly, legacyPatches = this.props.editor ? void 0 : this.props.incomingPatches$ ?? this.props.patches$;
|
|
5734
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
5735
|
+
legacyPatches ? /* @__PURE__ */ jsxRuntime.jsx(RoutePatchesObservableToEditorActor, { editorActor: this.editorActor, patches$: legacyPatches }) : null,
|
|
5736
|
+
/* @__PURE__ */ jsxRuntime.jsx(EditorActorContext.Provider, { value: this.editorActor, children: /* @__PURE__ */ jsxRuntime.jsx(SlateContainer, { editorActor: this.editorActor, maxBlocks, portableTextEditor: this, readOnly, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorContext.Provider, { value: this, children: /* @__PURE__ */ jsxRuntime.jsx(PortableTextEditorReadOnlyContext.Provider, { value: readOnly, children: /* @__PURE__ */ jsxRuntime.jsxs(PortableTextEditorSelectionProvider, { editorActor: this.editorActor, children: [
|
|
5737
|
+
/* @__PURE__ */ jsxRuntime.jsx(Synchronizer, { editorActor: this.editorActor, getValue: this.getValue, onChange: (change) => {
|
|
5738
|
+
this.props.editor || this.props.onChange(change), this.change$.next(change);
|
|
5739
|
+
}, value: this.props.value }),
|
|
5740
|
+
this.props.children
|
|
5741
|
+
] }) }) }) }) })
|
|
5742
|
+
] });
|
|
5587
5743
|
}
|
|
5588
5744
|
// Static API methods
|
|
5589
5745
|
static activeAnnotations = (editor) => editor && editor.editable ? editor.editable.activeAnnotations() : [];
|
|
@@ -5635,6 +5791,21 @@ class PortableTextEditor extends react.Component {
|
|
|
5635
5791
|
};
|
|
5636
5792
|
static isSelectionsOverlapping = (editor, selectionA, selectionB) => editor.editable?.isSelectionsOverlapping(selectionA, selectionB);
|
|
5637
5793
|
}
|
|
5794
|
+
function RoutePatchesObservableToEditorActor(props) {
|
|
5795
|
+
const $ = reactCompilerRuntime.c(4);
|
|
5796
|
+
let t0, t1;
|
|
5797
|
+
return $[0] !== props.patches$ || $[1] !== props.editorActor ? (t0 = () => {
|
|
5798
|
+
const subscription = props.patches$.subscribe((payload) => {
|
|
5799
|
+
props.editorActor.send({
|
|
5800
|
+
type: "patches",
|
|
5801
|
+
...payload
|
|
5802
|
+
});
|
|
5803
|
+
});
|
|
5804
|
+
return () => {
|
|
5805
|
+
subscription.unsubscribe();
|
|
5806
|
+
};
|
|
5807
|
+
}, t1 = [props.editorActor, props.patches$], $[0] = props.patches$, $[1] = props.editorActor, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), require$$0.useEffect(t0, t1), null;
|
|
5808
|
+
}
|
|
5638
5809
|
const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (props) => {
|
|
5639
5810
|
const {
|
|
5640
5811
|
editorActor,
|
|
@@ -5645,22 +5816,22 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
5645
5816
|
renderChild,
|
|
5646
5817
|
renderDecorator,
|
|
5647
5818
|
renderAnnotation
|
|
5648
|
-
} = props, spanRef =
|
|
5819
|
+
} = props, spanRef = require$$0.useRef(null), portableTextEditor = usePortableTextEditor(), blockSelected = slateReact.useSelected(), [focused, setFocused] = require$$0.useState(!1), [selected, setSelected] = require$$0.useState(!1), block = children.props.parent, path = require$$0.useMemo(() => block ? [{
|
|
5649
5820
|
_key: block?._key
|
|
5650
5821
|
}, "children", {
|
|
5651
5822
|
_key: leaf._key
|
|
5652
|
-
}] : [], [block, leaf._key]), decoratorValues =
|
|
5653
|
-
|
|
5823
|
+
}] : [], [block, leaf._key]), decoratorValues = require$$0.useMemo(() => schemaTypes.decorators.map((dec) => dec.value), [schemaTypes.decorators]), marks = require$$0.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 = require$$0.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;
|
|
5824
|
+
require$$0.useEffect(() => {
|
|
5654
5825
|
if (!shouldTrackSelectionAndFocus) {
|
|
5655
5826
|
setFocused(!1);
|
|
5656
5827
|
return;
|
|
5657
5828
|
}
|
|
5658
5829
|
const sel = PortableTextEditor.getSelection(portableTextEditor);
|
|
5659
|
-
sel && isEqual__default.default(sel.focus.path, path) && PortableTextEditor.isCollapsedSelection(portableTextEditor) &&
|
|
5830
|
+
sel && isEqual__default.default(sel.focus.path, path) && PortableTextEditor.isCollapsedSelection(portableTextEditor) && require$$0.startTransition(() => {
|
|
5660
5831
|
setFocused(!0);
|
|
5661
5832
|
});
|
|
5662
5833
|
}, [shouldTrackSelectionAndFocus, path, portableTextEditor]);
|
|
5663
|
-
const setSelectedFromRange =
|
|
5834
|
+
const setSelectedFromRange = require$$0.useCallback(() => {
|
|
5664
5835
|
if (!shouldTrackSelectionAndFocus)
|
|
5665
5836
|
return;
|
|
5666
5837
|
debug$1("Setting selection and focus from range");
|
|
@@ -5675,7 +5846,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
5675
5846
|
} else
|
|
5676
5847
|
setSelected(!1);
|
|
5677
5848
|
}, [shouldTrackSelectionAndFocus]);
|
|
5678
|
-
|
|
5849
|
+
require$$0.useEffect(() => {
|
|
5679
5850
|
if (!shouldTrackSelectionAndFocus)
|
|
5680
5851
|
return;
|
|
5681
5852
|
const onBlur = editorActor.on("blur", () => {
|
|
@@ -5689,8 +5860,8 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
5689
5860
|
return () => {
|
|
5690
5861
|
onBlur.unsubscribe(), onFocus.unsubscribe(), onSelection.unsubscribe();
|
|
5691
5862
|
};
|
|
5692
|
-
}, [editorActor, path, portableTextEditor, setSelectedFromRange, shouldTrackSelectionAndFocus]),
|
|
5693
|
-
const content2 =
|
|
5863
|
+
}, [editorActor, path, portableTextEditor, setSelectedFromRange, shouldTrackSelectionAndFocus]), require$$0.useEffect(() => setSelectedFromRange(), [setSelectedFromRange]);
|
|
5864
|
+
const content2 = require$$0.useMemo(() => {
|
|
5694
5865
|
let returnedChildren = children;
|
|
5695
5866
|
if (slate.Text.isText(leaf) && leaf._type === schemaTypes.span.name && (marks.forEach((mark_1) => {
|
|
5696
5867
|
const schemaType = schemaTypes.decorators.find((dec_0) => dec_0.value === mark_1);
|
|
@@ -5756,7 +5927,7 @@ const debug$1 = debugWithName("components:Leaf"), EMPTY_MARKS = [], Leaf = (prop
|
|
|
5756
5927
|
}
|
|
5757
5928
|
return returnedChildren;
|
|
5758
5929
|
}, [annotations, block, children, focused, leaf, marks, path, renderAnnotation, renderChild, renderDecorator, schemaTypes.annotations, schemaTypes.decorators, schemaTypes.span, selected]);
|
|
5759
|
-
return
|
|
5930
|
+
return require$$0.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("span", { ...attributes, ref: spanRef, children: content2 }, leaf._key), [leaf, attributes, content2]);
|
|
5760
5931
|
};
|
|
5761
5932
|
Leaf.displayName = "Leaf";
|
|
5762
5933
|
const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
@@ -5765,7 +5936,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5765
5936
|
pointerEvents: "none",
|
|
5766
5937
|
left: 0,
|
|
5767
5938
|
right: 0
|
|
5768
|
-
}, PortableTextEditable =
|
|
5939
|
+
}, PortableTextEditable = require$$0.forwardRef(function(props, forwardedRef) {
|
|
5769
5940
|
const {
|
|
5770
5941
|
hotkeys,
|
|
5771
5942
|
onBlur,
|
|
@@ -5786,13 +5957,13 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5786
5957
|
scrollSelectionIntoView,
|
|
5787
5958
|
spellCheck,
|
|
5788
5959
|
...restProps
|
|
5789
|
-
} = props, portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), ref =
|
|
5790
|
-
|
|
5791
|
-
const rangeDecorationsRef =
|
|
5960
|
+
} = props, portableTextEditor = usePortableTextEditor(), readOnly = usePortableTextEditorReadOnlyStatus(), ref = require$$0.useRef(null), [editableElement, setEditableElement] = require$$0.useState(null), [hasInvalidValue, setHasInvalidValue] = require$$0.useState(!1), [rangeDecorationState, setRangeDecorationsState] = require$$0.useState([]);
|
|
5961
|
+
require$$0.useImperativeHandle(forwardedRef, () => ref.current);
|
|
5962
|
+
const rangeDecorationsRef = require$$0.useRef(rangeDecorations), editorActor = require$$0.useContext(EditorActorContext), {
|
|
5792
5963
|
schemaTypes
|
|
5793
|
-
} = portableTextEditor, slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name, withInsertData =
|
|
5794
|
-
|
|
5795
|
-
const renderElement =
|
|
5964
|
+
} = portableTextEditor, slateEditor = slateReact.useSlate(), blockTypeName = schemaTypes.block.name, withInsertData = require$$0.useMemo(() => createWithInsertData(editorActor, schemaTypes), [editorActor, schemaTypes]), withHotKeys = require$$0.useMemo(() => createWithHotkeys(portableTextEditor, hotkeys), [hotkeys, portableTextEditor]);
|
|
5965
|
+
require$$0.useMemo(() => readOnly ? (debug("Editable is in read only mode"), withInsertData(slateEditor)) : (debug("Editable is in edit mode"), withInsertData(withHotKeys(slateEditor))), [readOnly, slateEditor, withHotKeys, withInsertData]);
|
|
5966
|
+
const renderElement = require$$0.useCallback((eProps) => /* @__PURE__ */ jsxRuntime.jsx(Element, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, schemaTypes, spellCheck }), [schemaTypes, spellCheck, readOnly, renderBlock, renderChild, renderListItem, renderStyle]), renderLeaf = require$$0.useCallback((lProps) => {
|
|
5796
5967
|
if (lProps.leaf._type === "span") {
|
|
5797
5968
|
let rendered = /* @__PURE__ */ jsxRuntime.jsx(Leaf, { ...lProps, editorActor, schemaTypes, renderAnnotation, renderChild, renderDecorator, readOnly });
|
|
5798
5969
|
if (renderPlaceholder && lProps.leaf.placeholder && lProps.text.text === "")
|
|
@@ -5806,7 +5977,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5806
5977
|
})), rendered;
|
|
5807
5978
|
}
|
|
5808
5979
|
return lProps.children;
|
|
5809
|
-
}, [editorActor, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder, schemaTypes]), restoreSelectionFromProps =
|
|
5980
|
+
}, [editorActor, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder, schemaTypes]), restoreSelectionFromProps = require$$0.useCallback(() => {
|
|
5810
5981
|
if (propsSelection) {
|
|
5811
5982
|
debug(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
5812
5983
|
const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children, blockTypeName));
|
|
@@ -5819,7 +5990,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5819
5990
|
}), slateEditor.onChange());
|
|
5820
5991
|
}
|
|
5821
5992
|
}
|
|
5822
|
-
}, [blockTypeName, editorActor, propsSelection, slateEditor]), syncRangeDecorations =
|
|
5993
|
+
}, [blockTypeName, editorActor, propsSelection, slateEditor]), syncRangeDecorations = require$$0.useCallback((operation) => {
|
|
5823
5994
|
if (rangeDecorations && rangeDecorations.length > 0) {
|
|
5824
5995
|
const newSlateRanges = [];
|
|
5825
5996
|
if (rangeDecorations.forEach((rangeDecorationItem) => {
|
|
@@ -5852,7 +6023,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5852
6023
|
}
|
|
5853
6024
|
setRangeDecorationsState((rangeDecorationState_0) => rangeDecorationState_0.length > 0 ? [] : rangeDecorationState_0);
|
|
5854
6025
|
}, [portableTextEditor, rangeDecorations, schemaTypes, slateEditor]);
|
|
5855
|
-
|
|
6026
|
+
require$$0.useEffect(() => {
|
|
5856
6027
|
const onReady = editorActor.on("ready", () => {
|
|
5857
6028
|
restoreSelectionFromProps();
|
|
5858
6029
|
}), onInvalidValue = editorActor.on("invalid value", () => {
|
|
@@ -5863,22 +6034,22 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5863
6034
|
return () => {
|
|
5864
6035
|
onReady.unsubscribe(), onInvalidValue.unsubscribe(), onValueChanged.unsubscribe();
|
|
5865
6036
|
};
|
|
5866
|
-
}, [editorActor, restoreSelectionFromProps]),
|
|
6037
|
+
}, [editorActor, restoreSelectionFromProps]), require$$0.useEffect(() => {
|
|
5867
6038
|
propsSelection && !hasInvalidValue && restoreSelectionFromProps();
|
|
5868
6039
|
}, [hasInvalidValue, propsSelection, restoreSelectionFromProps]);
|
|
5869
|
-
const originalApply =
|
|
5870
|
-
|
|
6040
|
+
const originalApply = require$$0.useMemo(() => slateEditor.apply, [slateEditor]), [syncedRangeDecorations, setSyncedRangeDecorations] = require$$0.useState(!1);
|
|
6041
|
+
require$$0.useEffect(() => {
|
|
5871
6042
|
syncedRangeDecorations || (setSyncedRangeDecorations(!0), syncRangeDecorations());
|
|
5872
|
-
}, [syncRangeDecorations, syncedRangeDecorations]),
|
|
6043
|
+
}, [syncRangeDecorations, syncedRangeDecorations]), require$$0.useEffect(() => {
|
|
5873
6044
|
isEqual__default.default(rangeDecorations, rangeDecorationsRef.current) || syncRangeDecorations(), rangeDecorationsRef.current = rangeDecorations;
|
|
5874
|
-
}, [rangeDecorations, syncRangeDecorations]),
|
|
6045
|
+
}, [rangeDecorations, syncRangeDecorations]), require$$0.useEffect(() => (slateEditor.apply = (op) => {
|
|
5875
6046
|
originalApply(op), op.type !== "set_selection" && syncRangeDecorations(op);
|
|
5876
6047
|
}, () => {
|
|
5877
6048
|
slateEditor.apply = originalApply;
|
|
5878
6049
|
}), [originalApply, slateEditor, syncRangeDecorations]);
|
|
5879
|
-
const handleCopy =
|
|
6050
|
+
const handleCopy = require$$0.useCallback((event) => {
|
|
5880
6051
|
onCopy && onCopy(event) !== void 0 && event.preventDefault();
|
|
5881
|
-
}, [onCopy]), handlePaste =
|
|
6052
|
+
}, [onCopy]), handlePaste = require$$0.useCallback((event_0) => {
|
|
5882
6053
|
if (event_0.preventDefault(), !slateEditor.selection)
|
|
5883
6054
|
return;
|
|
5884
6055
|
if (!onPaste) {
|
|
@@ -5902,7 +6073,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5902
6073
|
type: "done loading"
|
|
5903
6074
|
});
|
|
5904
6075
|
}));
|
|
5905
|
-
}, [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor]), handleOnFocus =
|
|
6076
|
+
}, [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor]), handleOnFocus = require$$0.useCallback((event_1) => {
|
|
5906
6077
|
if (onFocus && onFocus(event_1), !event_1.isDefaultPrevented()) {
|
|
5907
6078
|
const selection = PortableTextEditor.getSelection(portableTextEditor);
|
|
5908
6079
|
selection === null && (slate.Transforms.select(slateEditor, slate.Editor.start(slateEditor, [])), slateEditor.onChange()), editorActor.send({
|
|
@@ -5915,7 +6086,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5915
6086
|
selection
|
|
5916
6087
|
});
|
|
5917
6088
|
}
|
|
5918
|
-
}, [editorActor, onFocus, portableTextEditor, slateEditor]), handleClick =
|
|
6089
|
+
}, [editorActor, onFocus, portableTextEditor, slateEditor]), handleClick = require$$0.useCallback((event_2) => {
|
|
5919
6090
|
if (onClick && onClick(event_2), slateEditor.selection && event_2.target === event_2.currentTarget) {
|
|
5920
6091
|
const [lastBlock, path_0] = slate.Node.last(slateEditor, []), focusPath = slateEditor.selection.focus.path.slice(0, 1), lastPath = path_0.slice(0, 1);
|
|
5921
6092
|
if (slate.Path.equals(focusPath, lastPath)) {
|
|
@@ -5925,14 +6096,14 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5925
6096
|
})), slateEditor.onChange());
|
|
5926
6097
|
}
|
|
5927
6098
|
}
|
|
5928
|
-
}, [onClick, slateEditor]), handleOnBlur =
|
|
6099
|
+
}, [onClick, slateEditor]), handleOnBlur = require$$0.useCallback((event_3) => {
|
|
5929
6100
|
onBlur && onBlur(event_3), event_3.isPropagationStopped() || editorActor.send({
|
|
5930
6101
|
type: "blur",
|
|
5931
6102
|
event: event_3
|
|
5932
6103
|
});
|
|
5933
|
-
}, [editorActor, onBlur]), handleOnBeforeInput =
|
|
6104
|
+
}, [editorActor, onBlur]), handleOnBeforeInput = require$$0.useCallback((event_4) => {
|
|
5934
6105
|
onBeforeInput && onBeforeInput(event_4);
|
|
5935
|
-
}, [onBeforeInput]), validateSelection =
|
|
6106
|
+
}, [onBeforeInput]), validateSelection = require$$0.useCallback(() => {
|
|
5936
6107
|
if (!slateEditor.selection)
|
|
5937
6108
|
return;
|
|
5938
6109
|
const root = slateReact.ReactEditor.findDocumentOrShadowRoot(slateEditor), {
|
|
@@ -5951,7 +6122,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5951
6122
|
debug("Could not resolve selection, selecting top document"), slate.Transforms.deselect(slateEditor), slateEditor.children.length > 0 && slate.Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
|
|
5952
6123
|
}
|
|
5953
6124
|
}, [ref, slateEditor]);
|
|
5954
|
-
|
|
6125
|
+
require$$0.useEffect(() => {
|
|
5955
6126
|
if (editableElement) {
|
|
5956
6127
|
const mutationObserver = new MutationObserver(validateSelection);
|
|
5957
6128
|
return mutationObserver.observe(editableElement, {
|
|
@@ -5965,14 +6136,14 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5965
6136
|
};
|
|
5966
6137
|
}
|
|
5967
6138
|
}, [validateSelection, editableElement]);
|
|
5968
|
-
const handleKeyDown =
|
|
6139
|
+
const handleKeyDown = require$$0.useCallback((event_5) => {
|
|
5969
6140
|
props.onKeyDown && props.onKeyDown(event_5), event_5.isDefaultPrevented() || slateEditor.pteWithHotKeys(event_5);
|
|
5970
|
-
}, [props, slateEditor]), scrollSelectionIntoViewToSlate =
|
|
6141
|
+
}, [props, slateEditor]), scrollSelectionIntoViewToSlate = require$$0.useMemo(() => {
|
|
5971
6142
|
if (scrollSelectionIntoView !== void 0)
|
|
5972
6143
|
return scrollSelectionIntoView === null ? noop__default.default : (_editor, domRange) => {
|
|
5973
6144
|
scrollSelectionIntoView(portableTextEditor, domRange);
|
|
5974
6145
|
};
|
|
5975
|
-
}, [portableTextEditor, scrollSelectionIntoView]), decorate =
|
|
6146
|
+
}, [portableTextEditor, scrollSelectionIntoView]), decorate = require$$0.useCallback(([, path_1]) => {
|
|
5976
6147
|
if (isEqualToEmptyEditor(slateEditor.children, schemaTypes))
|
|
5977
6148
|
return [{
|
|
5978
6149
|
anchor: {
|
|
@@ -5999,7 +6170,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
5999
6170
|
}) || slate.Range.includes(item, path_1));
|
|
6000
6171
|
return result_1.length > 0 ? result_1 : [];
|
|
6001
6172
|
}, [slateEditor, schemaTypes, rangeDecorationState]);
|
|
6002
|
-
return
|
|
6173
|
+
return require$$0.useEffect(() => {
|
|
6003
6174
|
ref.current = slateReact.ReactEditor.toDOMNode(slateEditor, slateEditor), setEditableElement(ref.current);
|
|
6004
6175
|
}, [slateEditor, ref]), portableTextEditor ? hasInvalidValue ? null : /* @__PURE__ */ jsxRuntime.jsx(
|
|
6005
6176
|
slateReact.Editable,
|
|
@@ -6024,10 +6195,333 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6024
6195
|
) : null;
|
|
6025
6196
|
});
|
|
6026
6197
|
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
|
+
function useEditor(config) {
|
|
6503
|
+
const $ = reactCompilerRuntime.c(8);
|
|
6504
|
+
let t0;
|
|
6505
|
+
$[0] !== config.schema ? (t0 = config.schema.hasOwnProperty("jsonType") ? config.schema : compileType(config.schema), $[0] = config.schema, $[1] = t0) : t0 = $[1];
|
|
6506
|
+
let t1;
|
|
6507
|
+
$[2] !== t0 ? (t1 = getPortableTextMemberSchemaTypes(t0), $[2] = t0, $[3] = t1) : t1 = $[3];
|
|
6508
|
+
const schema2 = t1, t2 = config.keyGenerator ?? defaultKeyGenerator;
|
|
6509
|
+
let t3;
|
|
6510
|
+
return $[4] !== config.behaviors || $[5] !== t2 || $[6] !== schema2 ? (t3 = {
|
|
6511
|
+
input: {
|
|
6512
|
+
behaviors: config.behaviors,
|
|
6513
|
+
keyGenerator: t2,
|
|
6514
|
+
schema: schema2
|
|
6515
|
+
}
|
|
6516
|
+
}, $[4] = config.behaviors, $[5] = t2, $[6] = schema2, $[7] = t3) : t3 = $[7], useActorRef(editorMachine, t3);
|
|
6517
|
+
}
|
|
6027
6518
|
exports.PortableTextEditable = PortableTextEditable;
|
|
6028
6519
|
exports.PortableTextEditor = PortableTextEditor;
|
|
6520
|
+
exports.createMarkdownBehaviors = createMarkdownBehaviors;
|
|
6521
|
+
exports.defineBehavior = defineBehavior;
|
|
6029
6522
|
exports.editorMachine = editorMachine;
|
|
6030
6523
|
exports.keyGenerator = defaultKeyGenerator;
|
|
6524
|
+
exports.useEditor = useEditor;
|
|
6031
6525
|
exports.usePortableTextEditor = usePortableTextEditor;
|
|
6032
6526
|
exports.usePortableTextEditorSelection = usePortableTextEditorSelection;
|
|
6033
6527
|
//# sourceMappingURL=index.js.map
|