@portabletext/editor 2.14.2 → 2.14.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_chunks-cjs/use-editor.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +1 -1
- package/lib/_chunks-es/use-editor.js.map +1 -1
- package/lib/index.cjs +388 -315
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +388 -315
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.js.map +1 -1
- package/package.json +6 -6
- package/src/editor/plugins/createWithUndoRedo.ts +78 -61
- package/src/editor/sync-machine.ts +415 -322
- package/src/internal-utils/validateValue.ts +3 -3
- package/src/internal-utils/values.ts +80 -70
package/lib/index.js
CHANGED
|
@@ -58,53 +58,58 @@ function keepObjectEquality(object, keyMap) {
|
|
|
58
58
|
function toSlateValue(value, {
|
|
59
59
|
schemaTypes
|
|
60
60
|
}, keyMap = {}) {
|
|
61
|
-
return value && Array.isArray(value) ? value.map((block) => {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return keepObjectEquality({
|
|
61
|
+
return value && Array.isArray(value) ? value.map((block) => toSlateBlock(block, {
|
|
62
|
+
schemaTypes
|
|
63
|
+
}, keyMap)) : [];
|
|
64
|
+
}
|
|
65
|
+
function toSlateBlock(block, {
|
|
66
|
+
schemaTypes
|
|
67
|
+
}, keyMap = {}) {
|
|
68
|
+
const {
|
|
69
|
+
_type,
|
|
70
|
+
_key,
|
|
71
|
+
...rest
|
|
72
|
+
} = block;
|
|
73
|
+
if (block && block._type === schemaTypes.block.name) {
|
|
74
|
+
const textBlock = block;
|
|
75
|
+
let hasInlines = !1;
|
|
76
|
+
const hasMissingStyle = typeof textBlock.style > "u", hasMissingMarkDefs = typeof textBlock.markDefs > "u", hasMissingChildren = typeof textBlock.children > "u", children = (textBlock.children || []).map((child) => {
|
|
77
|
+
const {
|
|
78
|
+
_type: cType,
|
|
79
|
+
_key: cKey,
|
|
80
|
+
...cRest
|
|
81
|
+
} = child;
|
|
82
|
+
return cType !== "span" ? (hasInlines = !0, keepObjectEquality({
|
|
83
|
+
_type: cType,
|
|
84
|
+
_key: cKey,
|
|
85
|
+
children: [{
|
|
86
|
+
_key: VOID_CHILD_KEY,
|
|
87
|
+
_type: "span",
|
|
88
|
+
text: "",
|
|
89
|
+
marks: []
|
|
90
|
+
}],
|
|
91
|
+
value: cRest,
|
|
92
|
+
__inline: !0
|
|
93
|
+
}, keyMap)) : child;
|
|
94
|
+
});
|
|
95
|
+
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && Element$1.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].name), keepObjectEquality({
|
|
97
96
|
_type,
|
|
98
97
|
_key,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
98
|
+
...rest,
|
|
99
|
+
children
|
|
100
|
+
}, keyMap));
|
|
101
|
+
}
|
|
102
|
+
return keepObjectEquality({
|
|
103
|
+
_type,
|
|
104
|
+
_key,
|
|
105
|
+
children: [{
|
|
106
|
+
_key: VOID_CHILD_KEY,
|
|
107
|
+
_type: "span",
|
|
108
|
+
text: "",
|
|
109
|
+
marks: []
|
|
110
|
+
}],
|
|
111
|
+
value: rest
|
|
112
|
+
}, keyMap);
|
|
108
113
|
}
|
|
109
114
|
function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
110
115
|
return value.map((block) => {
|
|
@@ -1990,7 +1995,7 @@ function validateSelection(slateEditor, editorElement) {
|
|
|
1990
1995
|
}
|
|
1991
1996
|
}
|
|
1992
1997
|
const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), debug$d = debugWithName("component:Editable"), PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
1993
|
-
const $ = c(
|
|
1998
|
+
const $ = c(176);
|
|
1994
1999
|
let hotkeys, onBeforeInput, onBlur, onClick, onCopy, onCut, onDrag, onDragEnd, onDragEnter, onDragLeave, onDragOver, onDragStart, onDrop, onFocus, onPaste, propsSelection, rangeDecorations, renderAnnotation, renderBlock, renderChild, renderDecorator, renderListItem, renderPlaceholder, renderStyle, restProps, scrollSelectionIntoView, spellCheck;
|
|
1995
2000
|
$[0] !== props ? ({
|
|
1996
2001
|
hotkeys,
|
|
@@ -2033,47 +2038,50 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2033
2038
|
$[30] !== rangeDecorations ? (t1 = rangeDecorations ?? [], $[30] = rangeDecorations, $[31] = t1) : t1 = $[31];
|
|
2034
2039
|
let t2;
|
|
2035
2040
|
$[32] !== editorActor ? (t2 = editorActor.getSnapshot(), $[32] = editorActor, $[33] = t2) : t2 = $[33];
|
|
2036
|
-
const t3 =
|
|
2037
|
-
setup: "setting up"
|
|
2038
|
-
});
|
|
2041
|
+
const t3 = t2.context.schema;
|
|
2039
2042
|
let t4;
|
|
2040
|
-
$[34] !==
|
|
2043
|
+
$[34] !== editorActor ? (t4 = editorActor.getSnapshot().matches({
|
|
2044
|
+
setup: "setting up"
|
|
2045
|
+
}), $[34] = editorActor, $[35] = t4) : t4 = $[35];
|
|
2046
|
+
const t5 = !t4;
|
|
2047
|
+
let t6;
|
|
2048
|
+
$[36] !== readOnly || $[37] !== slateEditor || $[38] !== t1 || $[39] !== t2.context.schema || $[40] !== t5 ? (t6 = {
|
|
2041
2049
|
input: {
|
|
2042
2050
|
rangeDecorations: t1,
|
|
2043
2051
|
readOnly,
|
|
2044
|
-
schema:
|
|
2052
|
+
schema: t3,
|
|
2045
2053
|
slateEditor,
|
|
2046
|
-
skipSetup:
|
|
2054
|
+
skipSetup: t5
|
|
2047
2055
|
}
|
|
2048
|
-
}, $[
|
|
2049
|
-
const rangeDecorationsActor = useActorRef(rangeDecorationsMachine,
|
|
2050
|
-
let
|
|
2051
|
-
$[
|
|
2056
|
+
}, $[36] = readOnly, $[37] = slateEditor, $[38] = t1, $[39] = t2.context.schema, $[40] = t5, $[41] = t6) : t6 = $[41];
|
|
2057
|
+
const rangeDecorationsActor = useActorRef(rangeDecorationsMachine, t6), decorate = useSelector(rangeDecorationsActor, _temp2);
|
|
2058
|
+
let t7, t8;
|
|
2059
|
+
$[42] !== rangeDecorationsActor || $[43] !== readOnly ? (t7 = () => {
|
|
2052
2060
|
rangeDecorationsActor.send({
|
|
2053
2061
|
type: "update read only",
|
|
2054
2062
|
readOnly
|
|
2055
2063
|
});
|
|
2056
|
-
},
|
|
2057
|
-
let
|
|
2058
|
-
$[
|
|
2064
|
+
}, t8 = [rangeDecorationsActor, readOnly], $[42] = rangeDecorationsActor, $[43] = readOnly, $[44] = t7, $[45] = t8) : (t7 = $[44], t8 = $[45]), useEffect(t7, t8);
|
|
2065
|
+
let t10, t9;
|
|
2066
|
+
$[46] !== rangeDecorations || $[47] !== rangeDecorationsActor ? (t9 = () => {
|
|
2059
2067
|
rangeDecorationsActor.send({
|
|
2060
2068
|
type: "range decorations updated",
|
|
2061
2069
|
rangeDecorations: rangeDecorations ?? []
|
|
2062
2070
|
});
|
|
2063
|
-
},
|
|
2071
|
+
}, t10 = [rangeDecorationsActor, rangeDecorations], $[46] = rangeDecorations, $[47] = rangeDecorationsActor, $[48] = t10, $[49] = t9) : (t10 = $[48], t9 = $[49]), useEffect(t9, t10);
|
|
2064
2072
|
bb0: {
|
|
2065
2073
|
if (readOnly)
|
|
2066
2074
|
break bb0;
|
|
2067
2075
|
createWithHotkeys(editorActor, portableTextEditor, hotkeys)(slateEditor);
|
|
2068
2076
|
}
|
|
2069
|
-
let t10;
|
|
2070
|
-
$[48] !== readOnly || $[49] !== renderBlock || $[50] !== renderChild || $[51] !== renderListItem || $[52] !== renderStyle || $[53] !== spellCheck ? (t10 = (eProps) => /* @__PURE__ */ jsx(RenderElement, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, spellCheck }), $[48] = readOnly, $[49] = renderBlock, $[50] = renderChild, $[51] = renderListItem, $[52] = renderStyle, $[53] = spellCheck, $[54] = t10) : t10 = $[54];
|
|
2071
|
-
const renderElement = t10;
|
|
2072
|
-
let t11;
|
|
2073
|
-
$[55] !== readOnly || $[56] !== renderAnnotation || $[57] !== renderChild || $[58] !== renderDecorator || $[59] !== renderPlaceholder ? (t11 = (leafProps) => /* @__PURE__ */ jsx(RenderLeaf, { ...leafProps, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder }), $[55] = readOnly, $[56] = renderAnnotation, $[57] = renderChild, $[58] = renderDecorator, $[59] = renderPlaceholder, $[60] = t11) : t11 = $[60];
|
|
2074
|
-
const renderLeaf = t11, renderText = _temp3;
|
|
2075
2077
|
let t12;
|
|
2076
|
-
$[
|
|
2078
|
+
$[50] !== readOnly || $[51] !== renderBlock || $[52] !== renderChild || $[53] !== renderListItem || $[54] !== renderStyle || $[55] !== spellCheck ? (t12 = (eProps) => /* @__PURE__ */ jsx(RenderElement, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, spellCheck }), $[50] = readOnly, $[51] = renderBlock, $[52] = renderChild, $[53] = renderListItem, $[54] = renderStyle, $[55] = spellCheck, $[56] = t12) : t12 = $[56];
|
|
2079
|
+
const renderElement = t12;
|
|
2080
|
+
let t13;
|
|
2081
|
+
$[57] !== readOnly || $[58] !== renderAnnotation || $[59] !== renderChild || $[60] !== renderDecorator || $[61] !== renderPlaceholder ? (t13 = (leafProps) => /* @__PURE__ */ jsx(RenderLeaf, { ...leafProps, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder }), $[57] = readOnly, $[58] = renderAnnotation, $[59] = renderChild, $[60] = renderDecorator, $[61] = renderPlaceholder, $[62] = t13) : t13 = $[62];
|
|
2082
|
+
const renderLeaf = t13, renderText = _temp3;
|
|
2083
|
+
let t14;
|
|
2084
|
+
$[63] !== editorActor || $[64] !== propsSelection || $[65] !== slateEditor ? (t14 = () => {
|
|
2077
2085
|
if (propsSelection) {
|
|
2078
2086
|
debug$d(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
2079
2087
|
const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name));
|
|
@@ -2093,10 +2101,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2093
2101
|
}), slateEditor.onChange());
|
|
2094
2102
|
}
|
|
2095
2103
|
}
|
|
2096
|
-
}, $[
|
|
2097
|
-
const restoreSelectionFromProps =
|
|
2098
|
-
let
|
|
2099
|
-
$[
|
|
2104
|
+
}, $[63] = editorActor, $[64] = propsSelection, $[65] = slateEditor, $[66] = t14) : t14 = $[66];
|
|
2105
|
+
const restoreSelectionFromProps = t14;
|
|
2106
|
+
let t15, t16;
|
|
2107
|
+
$[67] !== editorActor || $[68] !== rangeDecorationsActor || $[69] !== restoreSelectionFromProps ? (t15 = () => {
|
|
2100
2108
|
const onReady = editorActor.on("ready", () => {
|
|
2101
2109
|
rangeDecorationsActor.send({
|
|
2102
2110
|
type: "ready"
|
|
@@ -2109,13 +2117,13 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2109
2117
|
return () => {
|
|
2110
2118
|
onReady.unsubscribe(), onInvalidValue.unsubscribe(), onValueChanged.unsubscribe();
|
|
2111
2119
|
};
|
|
2112
|
-
},
|
|
2113
|
-
let
|
|
2114
|
-
$[
|
|
2120
|
+
}, t16 = [rangeDecorationsActor, editorActor, restoreSelectionFromProps], $[67] = editorActor, $[68] = rangeDecorationsActor, $[69] = restoreSelectionFromProps, $[70] = t15, $[71] = t16) : (t15 = $[70], t16 = $[71]), useEffect(t15, t16);
|
|
2121
|
+
let t17, t18;
|
|
2122
|
+
$[72] !== hasInvalidValue || $[73] !== propsSelection || $[74] !== restoreSelectionFromProps ? (t17 = () => {
|
|
2115
2123
|
propsSelection && !hasInvalidValue && restoreSelectionFromProps();
|
|
2116
|
-
},
|
|
2117
|
-
let
|
|
2118
|
-
$[
|
|
2124
|
+
}, t18 = [hasInvalidValue, propsSelection, restoreSelectionFromProps], $[72] = hasInvalidValue, $[73] = propsSelection, $[74] = restoreSelectionFromProps, $[75] = t17, $[76] = t18) : (t17 = $[75], t18 = $[76]), useEffect(t17, t18);
|
|
2125
|
+
let t19;
|
|
2126
|
+
$[77] !== editorActor || $[78] !== onCopy || $[79] !== slateEditor ? (t19 = (event) => {
|
|
2119
2127
|
if (onCopy)
|
|
2120
2128
|
onCopy(event) !== void 0 && event.preventDefault();
|
|
2121
2129
|
else if (event.nativeEvent.clipboardData) {
|
|
@@ -2144,10 +2152,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2144
2152
|
nativeEvent: event
|
|
2145
2153
|
});
|
|
2146
2154
|
}
|
|
2147
|
-
}, $[
|
|
2148
|
-
const handleCopy =
|
|
2149
|
-
let
|
|
2150
|
-
$[
|
|
2155
|
+
}, $[77] = editorActor, $[78] = onCopy, $[79] = slateEditor, $[80] = t19) : t19 = $[80];
|
|
2156
|
+
const handleCopy = t19;
|
|
2157
|
+
let t20;
|
|
2158
|
+
$[81] !== editorActor || $[82] !== onCut || $[83] !== slateEditor ? (t20 = (event_0) => {
|
|
2151
2159
|
if (onCut)
|
|
2152
2160
|
onCut(event_0) !== void 0 && event_0.preventDefault();
|
|
2153
2161
|
else if (event_0.nativeEvent.clipboardData) {
|
|
@@ -2172,10 +2180,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2172
2180
|
nativeEvent: event_0
|
|
2173
2181
|
});
|
|
2174
2182
|
}
|
|
2175
|
-
}, $[
|
|
2176
|
-
const handleCut =
|
|
2177
|
-
let
|
|
2178
|
-
$[
|
|
2183
|
+
}, $[81] = editorActor, $[82] = onCut, $[83] = slateEditor, $[84] = t20) : t20 = $[84];
|
|
2184
|
+
const handleCut = t20;
|
|
2185
|
+
let t21;
|
|
2186
|
+
$[85] !== editorActor || $[86] !== onPaste || $[87] !== portableTextEditor || $[88] !== relayActor || $[89] !== slateEditor ? (t21 = (event_1) => {
|
|
2179
2187
|
const value = fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditor)), path = (slateEditor.selection ? slateRangeToSelection({
|
|
2180
2188
|
schema: editorActor.getSnapshot().context.schema,
|
|
2181
2189
|
editor: slateEditor,
|
|
@@ -2259,18 +2267,18 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2259
2267
|
});
|
|
2260
2268
|
}
|
|
2261
2269
|
debug$d("No result from custom paste handler, pasting normally");
|
|
2262
|
-
}, $[
|
|
2263
|
-
const handlePaste =
|
|
2264
|
-
let
|
|
2265
|
-
$[
|
|
2270
|
+
}, $[85] = editorActor, $[86] = onPaste, $[87] = portableTextEditor, $[88] = relayActor, $[89] = slateEditor, $[90] = t21) : t21 = $[90];
|
|
2271
|
+
const handlePaste = t21;
|
|
2272
|
+
let t22;
|
|
2273
|
+
$[91] !== editorActor || $[92] !== onFocus || $[93] !== relayActor || $[94] !== slateEditor ? (t22 = (event_2) => {
|
|
2266
2274
|
onFocus && onFocus(event_2), event_2.isDefaultPrevented() || (relayActor.send({
|
|
2267
2275
|
type: "focused",
|
|
2268
2276
|
event: event_2
|
|
2269
2277
|
}), !slateEditor.selection && isEqualToEmptyEditor(slateEditor.children, editorActor.getSnapshot().context.schema) && (Transforms.select(slateEditor, Editor.start(slateEditor, [])), slateEditor.onChange()));
|
|
2270
|
-
}, $[
|
|
2271
|
-
const handleOnFocus =
|
|
2272
|
-
let
|
|
2273
|
-
$[
|
|
2278
|
+
}, $[91] = editorActor, $[92] = onFocus, $[93] = relayActor, $[94] = slateEditor, $[95] = t22) : t22 = $[95];
|
|
2279
|
+
const handleOnFocus = t22;
|
|
2280
|
+
let t23;
|
|
2281
|
+
$[96] !== editorActor || $[97] !== onClick || $[98] !== slateEditor ? (t23 = (event_3) => {
|
|
2274
2282
|
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
2275
2283
|
return;
|
|
2276
2284
|
const position_3 = getEventPosition({
|
|
@@ -2287,23 +2295,23 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2287
2295
|
editor: slateEditor,
|
|
2288
2296
|
nativeEvent: event_3
|
|
2289
2297
|
});
|
|
2290
|
-
}, $[
|
|
2291
|
-
const handleClick =
|
|
2292
|
-
let
|
|
2293
|
-
$[
|
|
2298
|
+
}, $[96] = editorActor, $[97] = onClick, $[98] = slateEditor, $[99] = t23) : t23 = $[99];
|
|
2299
|
+
const handleClick = t23;
|
|
2300
|
+
let t24;
|
|
2301
|
+
$[100] !== onBlur || $[101] !== relayActor ? (t24 = (event_4) => {
|
|
2294
2302
|
onBlur && onBlur(event_4), event_4.isPropagationStopped() || relayActor.send({
|
|
2295
2303
|
type: "blurred",
|
|
2296
2304
|
event: event_4
|
|
2297
2305
|
});
|
|
2298
|
-
}, $[
|
|
2299
|
-
const handleOnBlur =
|
|
2300
|
-
let
|
|
2301
|
-
$[
|
|
2306
|
+
}, $[100] = onBlur, $[101] = relayActor, $[102] = t24) : t24 = $[102];
|
|
2307
|
+
const handleOnBlur = t24;
|
|
2308
|
+
let t25;
|
|
2309
|
+
$[103] !== onBeforeInput ? (t25 = (event_5) => {
|
|
2302
2310
|
onBeforeInput && onBeforeInput(event_5);
|
|
2303
|
-
}, $[
|
|
2304
|
-
const handleOnBeforeInput =
|
|
2305
|
-
let
|
|
2306
|
-
$[
|
|
2311
|
+
}, $[103] = onBeforeInput, $[104] = t25) : t25 = $[104];
|
|
2312
|
+
const handleOnBeforeInput = t25;
|
|
2313
|
+
let t26;
|
|
2314
|
+
$[105] !== editorActor || $[106] !== props || $[107] !== slateEditor ? (t26 = (event_6) => {
|
|
2307
2315
|
props.onKeyDown && props.onKeyDown(event_6), event_6.isDefaultPrevented() || slateEditor.pteWithHotKeys(event_6), event_6.isDefaultPrevented() || editorActor.send({
|
|
2308
2316
|
type: "behavior event",
|
|
2309
2317
|
behaviorEvent: {
|
|
@@ -2320,10 +2328,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2320
2328
|
editor: slateEditor,
|
|
2321
2329
|
nativeEvent: event_6
|
|
2322
2330
|
});
|
|
2323
|
-
}, $[
|
|
2324
|
-
const handleKeyDown =
|
|
2325
|
-
let
|
|
2326
|
-
$[
|
|
2331
|
+
}, $[105] = editorActor, $[106] = props, $[107] = slateEditor, $[108] = t26) : t26 = $[108];
|
|
2332
|
+
const handleKeyDown = t26;
|
|
2333
|
+
let t27;
|
|
2334
|
+
$[109] !== editorActor || $[110] !== props || $[111] !== slateEditor ? (t27 = (event_7) => {
|
|
2327
2335
|
props.onKeyUp && props.onKeyUp(event_7), event_7.isDefaultPrevented() || editorActor.send({
|
|
2328
2336
|
type: "behavior event",
|
|
2329
2337
|
behaviorEvent: {
|
|
@@ -2340,26 +2348,26 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2340
2348
|
editor: slateEditor,
|
|
2341
2349
|
nativeEvent: event_7
|
|
2342
2350
|
});
|
|
2343
|
-
}, $[
|
|
2344
|
-
const handleKeyUp =
|
|
2345
|
-
let
|
|
2351
|
+
}, $[109] = editorActor, $[110] = props, $[111] = slateEditor, $[112] = t27) : t27 = $[112];
|
|
2352
|
+
const handleKeyUp = t27;
|
|
2353
|
+
let t28;
|
|
2346
2354
|
bb1: {
|
|
2347
2355
|
if (scrollSelectionIntoView === void 0) {
|
|
2348
|
-
|
|
2356
|
+
t28 = void 0;
|
|
2349
2357
|
break bb1;
|
|
2350
2358
|
}
|
|
2351
2359
|
if (scrollSelectionIntoView === null) {
|
|
2352
|
-
|
|
2360
|
+
t28 = noop;
|
|
2353
2361
|
break bb1;
|
|
2354
2362
|
}
|
|
2355
|
-
let
|
|
2356
|
-
$[
|
|
2363
|
+
let t292;
|
|
2364
|
+
$[113] !== portableTextEditor || $[114] !== scrollSelectionIntoView ? (t292 = (_editor, domRange) => {
|
|
2357
2365
|
scrollSelectionIntoView(portableTextEditor, domRange);
|
|
2358
|
-
}, $[
|
|
2366
|
+
}, $[113] = portableTextEditor, $[114] = scrollSelectionIntoView, $[115] = t292) : t292 = $[115], t28 = t292;
|
|
2359
2367
|
}
|
|
2360
|
-
const scrollSelectionIntoViewToSlate =
|
|
2361
|
-
let
|
|
2362
|
-
$[
|
|
2368
|
+
const scrollSelectionIntoViewToSlate = t28;
|
|
2369
|
+
let t29, t30;
|
|
2370
|
+
$[116] !== editorActor || $[117] !== slateEditor ? (t29 = () => {
|
|
2363
2371
|
const window2 = ReactEditor.getWindow(slateEditor), onDragEnd_0 = () => {
|
|
2364
2372
|
editorActor.send({
|
|
2365
2373
|
type: "dragend"
|
|
@@ -2372,9 +2380,9 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2372
2380
|
return window2.document.addEventListener("dragend", onDragEnd_0), window2.document.addEventListener("drop", onDrop_0), () => {
|
|
2373
2381
|
window2.document.removeEventListener("dragend", onDragEnd_0), window2.document.removeEventListener("drop", onDrop_0);
|
|
2374
2382
|
};
|
|
2375
|
-
},
|
|
2376
|
-
let
|
|
2377
|
-
$[
|
|
2383
|
+
}, t30 = [slateEditor, editorActor], $[116] = editorActor, $[117] = slateEditor, $[118] = t29, $[119] = t30) : (t29 = $[118], t30 = $[119]), useEffect(t29, t30);
|
|
2384
|
+
let t31;
|
|
2385
|
+
$[120] !== editorActor || $[121] !== onDragStart || $[122] !== slateEditor ? (t31 = (event_8) => {
|
|
2378
2386
|
if (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped())
|
|
2379
2387
|
return;
|
|
2380
2388
|
const position_4 = getEventPosition({
|
|
@@ -2402,10 +2410,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2402
2410
|
},
|
|
2403
2411
|
editor: slateEditor
|
|
2404
2412
|
}), !0;
|
|
2405
|
-
}, $[
|
|
2406
|
-
const handleDragStart =
|
|
2407
|
-
let
|
|
2408
|
-
$[
|
|
2413
|
+
}, $[120] = editorActor, $[121] = onDragStart, $[122] = slateEditor, $[123] = t31) : t31 = $[123];
|
|
2414
|
+
const handleDragStart = t31;
|
|
2415
|
+
let t32;
|
|
2416
|
+
$[124] !== editorActor || $[125] !== onDrag || $[126] !== slateEditor ? (t32 = (event_9) => {
|
|
2409
2417
|
if (onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped() || !getEventPosition({
|
|
2410
2418
|
editorActor,
|
|
2411
2419
|
slateEditor,
|
|
@@ -2421,10 +2429,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2421
2429
|
},
|
|
2422
2430
|
editor: slateEditor
|
|
2423
2431
|
}), !0;
|
|
2424
|
-
}, $[
|
|
2425
|
-
const handleDrag =
|
|
2426
|
-
let
|
|
2427
|
-
$[
|
|
2432
|
+
}, $[124] = editorActor, $[125] = onDrag, $[126] = slateEditor, $[127] = t32) : t32 = $[127];
|
|
2433
|
+
const handleDrag = t32;
|
|
2434
|
+
let t33;
|
|
2435
|
+
$[128] !== editorActor || $[129] !== onDragEnd || $[130] !== slateEditor ? (t33 = (event_10) => {
|
|
2428
2436
|
if (onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped()))
|
|
2429
2437
|
return editorActor.send({
|
|
2430
2438
|
type: "behavior event",
|
|
@@ -2436,10 +2444,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2436
2444
|
},
|
|
2437
2445
|
editor: slateEditor
|
|
2438
2446
|
}), !0;
|
|
2439
|
-
}, $[
|
|
2440
|
-
const handleDragEnd =
|
|
2441
|
-
let
|
|
2442
|
-
$[
|
|
2447
|
+
}, $[128] = editorActor, $[129] = onDragEnd, $[130] = slateEditor, $[131] = t33) : t33 = $[131];
|
|
2448
|
+
const handleDragEnd = t33;
|
|
2449
|
+
let t34;
|
|
2450
|
+
$[132] !== editorActor || $[133] !== onDragEnter || $[134] !== slateEditor ? (t34 = (event_11) => {
|
|
2443
2451
|
if (onDragEnter?.(event_11), event_11.isDefaultPrevented() || event_11.isPropagationStopped())
|
|
2444
2452
|
return;
|
|
2445
2453
|
const position_6 = getEventPosition({
|
|
@@ -2459,10 +2467,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2459
2467
|
},
|
|
2460
2468
|
editor: slateEditor
|
|
2461
2469
|
}), !0;
|
|
2462
|
-
}, $[
|
|
2463
|
-
const handleDragEnter =
|
|
2464
|
-
let
|
|
2465
|
-
$[
|
|
2470
|
+
}, $[132] = editorActor, $[133] = onDragEnter, $[134] = slateEditor, $[135] = t34) : t34 = $[135];
|
|
2471
|
+
const handleDragEnter = t34;
|
|
2472
|
+
let t35;
|
|
2473
|
+
$[136] !== editorActor || $[137] !== onDragOver || $[138] !== slateEditor ? (t35 = (event_12) => {
|
|
2466
2474
|
if (onDragOver?.(event_12), event_12.isDefaultPrevented() || event_12.isPropagationStopped())
|
|
2467
2475
|
return;
|
|
2468
2476
|
const position_7 = getEventPosition({
|
|
@@ -2484,10 +2492,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2484
2492
|
editor: slateEditor,
|
|
2485
2493
|
nativeEvent: event_12
|
|
2486
2494
|
}), !0;
|
|
2487
|
-
}, $[
|
|
2488
|
-
const handleDragOver =
|
|
2489
|
-
let
|
|
2490
|
-
$[
|
|
2495
|
+
}, $[136] = editorActor, $[137] = onDragOver, $[138] = slateEditor, $[139] = t35) : t35 = $[139];
|
|
2496
|
+
const handleDragOver = t35;
|
|
2497
|
+
let t36;
|
|
2498
|
+
$[140] !== editorActor || $[141] !== onDrop || $[142] !== slateEditor ? (t36 = (event_13) => {
|
|
2491
2499
|
if (onDrop?.(event_13), event_13.isDefaultPrevented() || event_13.isPropagationStopped())
|
|
2492
2500
|
return;
|
|
2493
2501
|
const position_8 = getEventPosition({
|
|
@@ -2512,10 +2520,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2512
2520
|
editor: slateEditor,
|
|
2513
2521
|
nativeEvent: event_13
|
|
2514
2522
|
}), !0;
|
|
2515
|
-
}, $[
|
|
2516
|
-
const handleDrop =
|
|
2517
|
-
let
|
|
2518
|
-
$[
|
|
2523
|
+
}, $[140] = editorActor, $[141] = onDrop, $[142] = slateEditor, $[143] = t36) : t36 = $[143];
|
|
2524
|
+
const handleDrop = t36;
|
|
2525
|
+
let t37;
|
|
2526
|
+
$[144] !== editorActor || $[145] !== onDragLeave || $[146] !== slateEditor ? (t37 = (event_14) => {
|
|
2519
2527
|
if (onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped() || !getEventPosition({
|
|
2520
2528
|
editorActor,
|
|
2521
2529
|
slateEditor,
|
|
@@ -2531,10 +2539,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2531
2539
|
},
|
|
2532
2540
|
editor: slateEditor
|
|
2533
2541
|
}), !0;
|
|
2534
|
-
}, $[
|
|
2535
|
-
const handleDragLeave =
|
|
2536
|
-
let
|
|
2537
|
-
$[
|
|
2542
|
+
}, $[144] = editorActor, $[145] = onDragLeave, $[146] = slateEditor, $[147] = t37) : t37 = $[147];
|
|
2543
|
+
const handleDragLeave = t37;
|
|
2544
|
+
let t38;
|
|
2545
|
+
$[148] !== forwardedRef || $[149] !== validateSelectionActor ? (t38 = (editorElement) => {
|
|
2538
2546
|
if (typeof forwardedRef == "function" ? forwardedRef(editorElement) : forwardedRef && (forwardedRef.current = editorElement), editorElement) {
|
|
2539
2547
|
const mutationObserver = new MutationObserver(() => {
|
|
2540
2548
|
validateSelectionActor.send({
|
|
@@ -2552,12 +2560,12 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2552
2560
|
mutationObserver.disconnect();
|
|
2553
2561
|
};
|
|
2554
2562
|
}
|
|
2555
|
-
}, $[
|
|
2556
|
-
const callbackRef =
|
|
2563
|
+
}, $[148] = forwardedRef, $[149] = validateSelectionActor, $[150] = t38) : t38 = $[150];
|
|
2564
|
+
const callbackRef = t38;
|
|
2557
2565
|
if (!portableTextEditor)
|
|
2558
2566
|
return null;
|
|
2559
|
-
let
|
|
2560
|
-
return $[
|
|
2567
|
+
let t39;
|
|
2568
|
+
return $[151] !== callbackRef || $[152] !== decorate || $[153] !== handleClick || $[154] !== handleCopy || $[155] !== handleCut || $[156] !== handleDrag || $[157] !== handleDragEnd || $[158] !== handleDragEnter || $[159] !== handleDragLeave || $[160] !== handleDragOver || $[161] !== handleDragStart || $[162] !== handleDrop || $[163] !== handleKeyDown || $[164] !== handleKeyUp || $[165] !== handleOnBeforeInput || $[166] !== handleOnBlur || $[167] !== handleOnFocus || $[168] !== handlePaste || $[169] !== hasInvalidValue || $[170] !== readOnly || $[171] !== renderElement || $[172] !== renderLeaf || $[173] !== restProps || $[174] !== scrollSelectionIntoViewToSlate ? (t39 = hasInvalidValue ? null : /* @__PURE__ */ jsx(Editable, { ...restProps, ref: callbackRef, "data-read-only": readOnly, autoFocus: !1, className: restProps.className || "pt-editable", decorate, onBlur: handleOnBlur, onCopy: handleCopy, onCut: handleCut, onClick: handleClick, onDOMBeforeInput: handleOnBeforeInput, onDragStart: handleDragStart, onDrag: handleDrag, onDragEnd: handleDragEnd, onDragEnter: handleDragEnter, onDragOver: handleDragOver, onDrop: handleDrop, onDragLeave: handleDragLeave, onFocus: handleOnFocus, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onPaste: handlePaste, readOnly, renderPlaceholder: void 0, renderElement, renderLeaf, renderText, scrollSelectionIntoView: scrollSelectionIntoViewToSlate }), $[151] = callbackRef, $[152] = decorate, $[153] = handleClick, $[154] = handleCopy, $[155] = handleCut, $[156] = handleDrag, $[157] = handleDragEnd, $[158] = handleDragEnter, $[159] = handleDragLeave, $[160] = handleDragOver, $[161] = handleDragStart, $[162] = handleDrop, $[163] = handleKeyDown, $[164] = handleKeyUp, $[165] = handleOnBeforeInput, $[166] = handleOnBlur, $[167] = handleOnFocus, $[168] = handlePaste, $[169] = hasInvalidValue, $[170] = readOnly, $[171] = renderElement, $[172] = renderLeaf, $[173] = restProps, $[174] = scrollSelectionIntoViewToSlate, $[175] = t39) : t39 = $[175], t39;
|
|
2561
2569
|
});
|
|
2562
2570
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
2563
2571
|
function _temp(s) {
|
|
@@ -3925,27 +3933,26 @@ function createWithUndoRedo(options) {
|
|
|
3925
3933
|
apply2(op);
|
|
3926
3934
|
return;
|
|
3927
3935
|
}
|
|
3928
|
-
const
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
if (
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
timestamp: /* @__PURE__ */ new Date()
|
|
3942
|
-
};
|
|
3943
|
-
undos.push(newStep), debug$b("Created new undo step", step);
|
|
3944
|
-
}
|
|
3945
|
-
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
3946
|
-
undos.shift();
|
|
3947
|
-
shouldClear(op) && (history.redos = []);
|
|
3936
|
+
const savingUndoSteps = isSaving(editor), currentUndoStepId = getCurrentUndoStepId(editor);
|
|
3937
|
+
if (!savingUndoSteps) {
|
|
3938
|
+
previousUndoStepId = currentUndoStepId, apply2(op);
|
|
3939
|
+
return;
|
|
3940
|
+
}
|
|
3941
|
+
op.type !== "set_selection" && (editor.history.redos = []);
|
|
3942
|
+
const step = editor.history.undos.at(editor.history.undos.length - 1);
|
|
3943
|
+
if (!step) {
|
|
3944
|
+
editor.history.undos.push({
|
|
3945
|
+
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
3946
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
3947
|
+
}), apply2(op), previousUndoStepId = currentUndoStepId;
|
|
3948
|
+
return;
|
|
3948
3949
|
}
|
|
3950
|
+
const selectingWithoutUndoStepId = op.type === "set_selection" && currentUndoStepId === void 0 && previousUndoStepId !== void 0, selectingWithDifferentUndoStepId = op.type === "set_selection" && currentUndoStepId !== void 0 && previousUndoStepId !== void 0 && previousUndoStepId !== currentUndoStepId, lastOp = step.operations.at(-1);
|
|
3951
|
+
for ((editor.operations.length > 0 ? currentUndoStepId === previousUndoStepId || isNormalizingNode(editor) : selectingWithoutUndoStepId || selectingWithDifferentUndoStepId || currentUndoStepId === void 0 && previousUndoStepId === void 0 ? shouldMerge(op, lastOp) || lastOp?.type === "set_selection" && op.type === "set_selection" : currentUndoStepId === previousUndoStepId || isNormalizingNode(editor)) ? step.operations.push(op) : editor.history.undos.push({
|
|
3952
|
+
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
3953
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
3954
|
+
}); editor.history.undos.length > UNDO_STEP_LIMIT; )
|
|
3955
|
+
editor.history.undos.shift();
|
|
3949
3956
|
previousUndoStepId = currentUndoStepId, apply2(op);
|
|
3950
3957
|
}, editor;
|
|
3951
3958
|
};
|
|
@@ -4104,7 +4111,7 @@ function adjustBlockPath(operation, level, blockIndex) {
|
|
|
4104
4111
|
}
|
|
4105
4112
|
return transformedOperation;
|
|
4106
4113
|
}
|
|
4107
|
-
const shouldMerge = (op, prev) => !!(op.type === "set_selection" || prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && Path.equals(op.path, prev.path) && op.text !== " " || prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && Path.equals(op.path, prev.path))
|
|
4114
|
+
const shouldMerge = (op, prev) => !!(op.type === "set_selection" || prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && Path.equals(op.path, prev.path) && op.text !== " " || prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && Path.equals(op.path, prev.path));
|
|
4108
4115
|
function withoutSaving(editor, fn) {
|
|
4109
4116
|
const prev = isSaving(editor);
|
|
4110
4117
|
SAVING.set(editor, !1), fn(), SAVING.set(editor, prev);
|
|
@@ -11308,7 +11315,9 @@ function validateValue(value, types, keyGenerator) {
|
|
|
11308
11315
|
}
|
|
11309
11316
|
}, !0;
|
|
11310
11317
|
}
|
|
11311
|
-
const allUsedMarks = uniq(flatten(textBlock.children.filter((
|
|
11318
|
+
const allUsedMarks = uniq(flatten(textBlock.children.filter((child) => isSpan({
|
|
11319
|
+
schema: types
|
|
11320
|
+
}, child)).map((cld) => cld.marks || [])));
|
|
11312
11321
|
if (Array.isArray(blk.markDefs) && blk.markDefs.length > 0) {
|
|
11313
11322
|
const unusedMarkDefs = uniq(blk.markDefs.map((def) => def._key).filter((key) => !allUsedMarks.includes(key)));
|
|
11314
11323
|
if (unusedMarkDefs.length > 0)
|
|
@@ -11713,75 +11722,24 @@ async function updateValue({
|
|
|
11713
11722
|
}) {
|
|
11714
11723
|
let doneSyncing = !1, isChanged = !1, isValid = !0;
|
|
11715
11724
|
const hadSelection = !!slateEditor.selection;
|
|
11716
|
-
if ((!value || value.length === 0) && (debug$2("Value is empty"),
|
|
11717
|
-
|
|
11718
|
-
|
|
11719
|
-
|
|
11720
|
-
|
|
11721
|
-
|
|
11722
|
-
|
|
11723
|
-
|
|
11724
|
-
|
|
11725
|
-
|
|
11726
|
-
|
|
11727
|
-
|
|
11728
|
-
|
|
11729
|
-
|
|
11730
|
-
|
|
11731
|
-
|
|
11732
|
-
|
|
11733
|
-
|
|
11734
|
-
});
|
|
11735
|
-
});
|
|
11736
|
-
}), isChanged = !0), value && value.length > 0) {
|
|
11737
|
-
const slateValueFromProps = toSlateValue(value, {
|
|
11738
|
-
schemaTypes: context.schema
|
|
11739
|
-
});
|
|
11740
|
-
streamBlocks ? await new Promise((resolve) => {
|
|
11741
|
-
Editor.withoutNormalizing(slateEditor, () => {
|
|
11742
|
-
withRemoteChanges(slateEditor, () => {
|
|
11743
|
-
withoutPatching(slateEditor, () => {
|
|
11744
|
-
if (doneSyncing) {
|
|
11745
|
-
resolve();
|
|
11746
|
-
return;
|
|
11747
|
-
}
|
|
11748
|
-
isChanged = removeExtraBlocks({
|
|
11749
|
-
slateEditor,
|
|
11750
|
-
slateValueFromProps
|
|
11751
|
-
}), (async () => {
|
|
11752
|
-
for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
|
|
11753
|
-
slateValue: slateValueFromProps
|
|
11754
|
-
})) {
|
|
11755
|
-
const {
|
|
11756
|
-
blockChanged,
|
|
11757
|
-
blockValid
|
|
11758
|
-
} = syncBlock({
|
|
11759
|
-
context,
|
|
11760
|
-
sendBack,
|
|
11761
|
-
block: currentBlock,
|
|
11762
|
-
index: currentBlockIndex,
|
|
11763
|
-
slateEditor,
|
|
11764
|
-
value
|
|
11765
|
-
});
|
|
11766
|
-
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
|
|
11767
|
-
break;
|
|
11768
|
-
}
|
|
11769
|
-
resolve();
|
|
11770
|
-
})();
|
|
11771
|
-
});
|
|
11772
|
-
});
|
|
11773
|
-
});
|
|
11774
|
-
}) : Editor.withoutNormalizing(slateEditor, () => {
|
|
11775
|
-
withRemoteChanges(slateEditor, () => {
|
|
11776
|
-
withoutPatching(slateEditor, () => {
|
|
11777
|
-
if (doneSyncing)
|
|
11778
|
-
return;
|
|
11779
|
-
isChanged = removeExtraBlocks({
|
|
11780
|
-
slateEditor,
|
|
11781
|
-
slateValueFromProps
|
|
11782
|
-
});
|
|
11783
|
-
let index = 0;
|
|
11784
|
-
for (const currentBlock of slateValueFromProps) {
|
|
11725
|
+
if ((!value || value.length === 0) && (debug$2("Value is empty"), clearEditor({
|
|
11726
|
+
slateEditor,
|
|
11727
|
+
doneSyncing,
|
|
11728
|
+
hadSelection
|
|
11729
|
+
}), isChanged = !0), value && value.length > 0)
|
|
11730
|
+
if (streamBlocks)
|
|
11731
|
+
await new Promise((resolve) => {
|
|
11732
|
+
if (doneSyncing) {
|
|
11733
|
+
resolve();
|
|
11734
|
+
return;
|
|
11735
|
+
}
|
|
11736
|
+
isChanged = removeExtraBlocks({
|
|
11737
|
+
slateEditor,
|
|
11738
|
+
value
|
|
11739
|
+
}), (async () => {
|
|
11740
|
+
for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
|
|
11741
|
+
value
|
|
11742
|
+
})) {
|
|
11785
11743
|
const {
|
|
11786
11744
|
blockChanged,
|
|
11787
11745
|
blockValid
|
|
@@ -11789,18 +11747,41 @@ async function updateValue({
|
|
|
11789
11747
|
context,
|
|
11790
11748
|
sendBack,
|
|
11791
11749
|
block: currentBlock,
|
|
11792
|
-
index,
|
|
11750
|
+
index: currentBlockIndex,
|
|
11793
11751
|
slateEditor,
|
|
11794
11752
|
value
|
|
11795
11753
|
});
|
|
11796
|
-
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !
|
|
11754
|
+
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
|
|
11797
11755
|
break;
|
|
11798
|
-
index++;
|
|
11799
11756
|
}
|
|
11800
|
-
|
|
11757
|
+
resolve();
|
|
11758
|
+
})();
|
|
11801
11759
|
});
|
|
11802
|
-
|
|
11803
|
-
|
|
11760
|
+
else {
|
|
11761
|
+
if (doneSyncing)
|
|
11762
|
+
return;
|
|
11763
|
+
isChanged = removeExtraBlocks({
|
|
11764
|
+
slateEditor,
|
|
11765
|
+
value
|
|
11766
|
+
});
|
|
11767
|
+
let index = 0;
|
|
11768
|
+
for (const block of value) {
|
|
11769
|
+
const {
|
|
11770
|
+
blockChanged,
|
|
11771
|
+
blockValid
|
|
11772
|
+
} = syncBlock({
|
|
11773
|
+
context,
|
|
11774
|
+
sendBack,
|
|
11775
|
+
block,
|
|
11776
|
+
index,
|
|
11777
|
+
slateEditor,
|
|
11778
|
+
value
|
|
11779
|
+
});
|
|
11780
|
+
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !blockValid)
|
|
11781
|
+
break;
|
|
11782
|
+
index++;
|
|
11783
|
+
}
|
|
11784
|
+
}
|
|
11804
11785
|
if (!isValid) {
|
|
11805
11786
|
debug$2("Invalid value, returning"), doneSyncing = !0, sendBack({
|
|
11806
11787
|
type: "done syncing",
|
|
@@ -11843,27 +11824,59 @@ async function updateValue({
|
|
|
11843
11824
|
value
|
|
11844
11825
|
});
|
|
11845
11826
|
}
|
|
11846
|
-
function
|
|
11827
|
+
async function* getStreamedBlocks({
|
|
11828
|
+
value
|
|
11829
|
+
}) {
|
|
11830
|
+
let index = 0;
|
|
11831
|
+
for await (const block of value)
|
|
11832
|
+
index % 10 === 0 && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
|
|
11833
|
+
}
|
|
11834
|
+
function clearEditor({
|
|
11847
11835
|
slateEditor,
|
|
11848
|
-
|
|
11836
|
+
doneSyncing,
|
|
11837
|
+
hadSelection
|
|
11849
11838
|
}) {
|
|
11850
|
-
|
|
11851
|
-
|
|
11852
|
-
|
|
11853
|
-
|
|
11854
|
-
|
|
11855
|
-
|
|
11839
|
+
Editor.withoutNormalizing(slateEditor, () => {
|
|
11840
|
+
withoutSaving(slateEditor, () => {
|
|
11841
|
+
withRemoteChanges(slateEditor, () => {
|
|
11842
|
+
withoutPatching(slateEditor, () => {
|
|
11843
|
+
if (doneSyncing)
|
|
11844
|
+
return;
|
|
11845
|
+
hadSelection && Transforms.deselect(slateEditor);
|
|
11846
|
+
const childrenLength = slateEditor.children.length;
|
|
11847
|
+
slateEditor.children.forEach((_, index) => {
|
|
11848
|
+
Transforms.removeNodes(slateEditor, {
|
|
11849
|
+
at: [childrenLength - 1 - index]
|
|
11850
|
+
});
|
|
11851
|
+
}), Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
|
|
11852
|
+
decorators: []
|
|
11853
|
+
}), {
|
|
11854
|
+
at: [0]
|
|
11855
|
+
}), hadSelection && Transforms.select(slateEditor, [0, 0]);
|
|
11856
|
+
});
|
|
11856
11857
|
});
|
|
11857
|
-
|
|
11858
|
-
}
|
|
11859
|
-
return isChanged;
|
|
11858
|
+
});
|
|
11859
|
+
});
|
|
11860
11860
|
}
|
|
11861
|
-
|
|
11862
|
-
|
|
11861
|
+
function removeExtraBlocks({
|
|
11862
|
+
slateEditor,
|
|
11863
|
+
value
|
|
11863
11864
|
}) {
|
|
11864
|
-
let
|
|
11865
|
-
|
|
11866
|
-
|
|
11865
|
+
let isChanged = !1;
|
|
11866
|
+
return Editor.withoutNormalizing(slateEditor, () => {
|
|
11867
|
+
withRemoteChanges(slateEditor, () => {
|
|
11868
|
+
withoutPatching(slateEditor, () => {
|
|
11869
|
+
const childrenLength = slateEditor.children.length;
|
|
11870
|
+
if (value.length < childrenLength) {
|
|
11871
|
+
for (let i = childrenLength - 1; i > value.length - 1; i--)
|
|
11872
|
+
Transforms.removeNodes(slateEditor, {
|
|
11873
|
+
at: [i]
|
|
11874
|
+
});
|
|
11875
|
+
isChanged = !0;
|
|
11876
|
+
}
|
|
11877
|
+
});
|
|
11878
|
+
});
|
|
11879
|
+
}), isChanged;
|
|
11867
11880
|
}
|
|
11868
11881
|
function syncBlock({
|
|
11869
11882
|
context,
|
|
@@ -11873,67 +11886,127 @@ function syncBlock({
|
|
|
11873
11886
|
slateEditor,
|
|
11874
11887
|
value
|
|
11875
11888
|
}) {
|
|
11876
|
-
|
|
11877
|
-
|
|
11878
|
-
|
|
11889
|
+
const oldBlock = slateEditor.children.at(index);
|
|
11890
|
+
if (!oldBlock) {
|
|
11891
|
+
const validation2 = validateValue([block], context.schema, context.keyGenerator);
|
|
11892
|
+
if (debug$2.enabled && debug$2("Validating and inserting new block in the end of the value", block), validation2.valid || validation2.resolution?.autoResolve) {
|
|
11893
|
+
const slateBlock = toSlateBlock(block, {
|
|
11894
|
+
schemaTypes: context.schema
|
|
11895
|
+
});
|
|
11896
|
+
return Editor.withoutNormalizing(slateEditor, () => {
|
|
11897
|
+
withRemoteChanges(slateEditor, () => {
|
|
11898
|
+
withoutPatching(slateEditor, () => {
|
|
11899
|
+
Transforms.insertNodes(slateEditor, slateBlock, {
|
|
11900
|
+
at: [index]
|
|
11901
|
+
});
|
|
11902
|
+
});
|
|
11903
|
+
});
|
|
11904
|
+
}), {
|
|
11905
|
+
blockChanged: !0,
|
|
11906
|
+
blockValid: !0
|
|
11907
|
+
};
|
|
11908
|
+
}
|
|
11909
|
+
return debug$2("Invalid", validation2), sendBack({
|
|
11910
|
+
type: "invalid value",
|
|
11911
|
+
resolution: validation2.resolution,
|
|
11912
|
+
value
|
|
11913
|
+
}), {
|
|
11914
|
+
blockChanged: !1,
|
|
11915
|
+
blockValid: !1
|
|
11916
|
+
};
|
|
11917
|
+
}
|
|
11918
|
+
if (isEqual(block, oldBlock))
|
|
11919
|
+
return {
|
|
11920
|
+
blockChanged: !1,
|
|
11921
|
+
blockValid: !0
|
|
11922
|
+
};
|
|
11923
|
+
const validationValue = [value[index]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
11924
|
+
return !validation.valid && validation.resolution?.autoResolve && validation.resolution?.patches.length > 0 && !context.readOnly && context.previousValue && context.previousValue !== value && (console.warn(`${validation.resolution.action} for block with _key '${validationValue[0]._key}'. ${validation.resolution?.description}`), validation.resolution.patches.forEach((patch) => {
|
|
11925
|
+
sendBack({
|
|
11926
|
+
type: "patch",
|
|
11927
|
+
patch
|
|
11928
|
+
});
|
|
11929
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === block._key ? (debug$2.enabled && debug$2("Updating block", oldBlock, block), Editor.withoutNormalizing(slateEditor, () => {
|
|
11879
11930
|
withRemoteChanges(slateEditor, () => {
|
|
11880
11931
|
withoutPatching(slateEditor, () => {
|
|
11881
|
-
|
|
11882
|
-
|
|
11883
|
-
|
|
11884
|
-
|
|
11885
|
-
|
|
11886
|
-
|
|
11887
|
-
|
|
11888
|
-
|
|
11889
|
-
|
|
11890
|
-
|
|
11891
|
-
|
|
11892
|
-
|
|
11893
|
-
|
|
11894
|
-
|
|
11895
|
-
|
|
11896
|
-
|
|
11897
|
-
|
|
11898
|
-
|
|
11899
|
-
type: "invalid value",
|
|
11900
|
-
resolution: validation.resolution,
|
|
11901
|
-
value
|
|
11902
|
-
}), blockValid = !1);
|
|
11903
|
-
}
|
|
11932
|
+
updateBlock({
|
|
11933
|
+
context,
|
|
11934
|
+
slateEditor,
|
|
11935
|
+
oldBlock,
|
|
11936
|
+
block,
|
|
11937
|
+
index
|
|
11938
|
+
});
|
|
11939
|
+
});
|
|
11940
|
+
});
|
|
11941
|
+
})) : (debug$2.enabled && debug$2("Replacing block", oldBlock, block), Editor.withoutNormalizing(slateEditor, () => {
|
|
11942
|
+
withRemoteChanges(slateEditor, () => {
|
|
11943
|
+
withoutPatching(slateEditor, () => {
|
|
11944
|
+
replaceBlock({
|
|
11945
|
+
context,
|
|
11946
|
+
slateEditor,
|
|
11947
|
+
block,
|
|
11948
|
+
index
|
|
11949
|
+
});
|
|
11904
11950
|
});
|
|
11905
11951
|
});
|
|
11952
|
+
})), {
|
|
11953
|
+
blockChanged: !0,
|
|
11954
|
+
blockValid: !0
|
|
11955
|
+
}) : (sendBack({
|
|
11956
|
+
type: "invalid value",
|
|
11957
|
+
resolution: validation.resolution,
|
|
11958
|
+
value
|
|
11906
11959
|
}), {
|
|
11907
|
-
blockChanged,
|
|
11908
|
-
blockValid
|
|
11909
|
-
};
|
|
11960
|
+
blockChanged: !1,
|
|
11961
|
+
blockValid: !1
|
|
11962
|
+
});
|
|
11910
11963
|
}
|
|
11911
|
-
function
|
|
11912
|
-
|
|
11964
|
+
function replaceBlock({
|
|
11965
|
+
context,
|
|
11966
|
+
slateEditor,
|
|
11967
|
+
block,
|
|
11968
|
+
index
|
|
11969
|
+
}) {
|
|
11970
|
+
const slateBlock = toSlateBlock(block, {
|
|
11971
|
+
schemaTypes: context.schema
|
|
11972
|
+
}), currentSelection = slateEditor.selection, selectionFocusOnBlock = currentSelection && currentSelection.focus.path[0] === index;
|
|
11913
11973
|
selectionFocusOnBlock && Transforms.deselect(slateEditor), Transforms.removeNodes(slateEditor, {
|
|
11914
|
-
at: [
|
|
11915
|
-
}), Transforms.insertNodes(slateEditor,
|
|
11916
|
-
at: [
|
|
11974
|
+
at: [index]
|
|
11975
|
+
}), Transforms.insertNodes(slateEditor, slateBlock, {
|
|
11976
|
+
at: [index]
|
|
11917
11977
|
}), slateEditor.onChange(), selectionFocusOnBlock && Transforms.select(slateEditor, currentSelection);
|
|
11918
11978
|
}
|
|
11919
|
-
function
|
|
11920
|
-
|
|
11921
|
-
|
|
11922
|
-
|
|
11979
|
+
function updateBlock({
|
|
11980
|
+
context,
|
|
11981
|
+
slateEditor,
|
|
11982
|
+
oldBlock,
|
|
11983
|
+
block,
|
|
11984
|
+
index
|
|
11985
|
+
}) {
|
|
11986
|
+
const slateBlock = toSlateBlock(block, {
|
|
11987
|
+
schemaTypes: context.schema
|
|
11988
|
+
});
|
|
11989
|
+
if (Transforms.setNodes(slateEditor, slateBlock, {
|
|
11990
|
+
at: [index]
|
|
11991
|
+
}), slateEditor.isTextBlock(slateBlock) && slateEditor.isTextBlock(oldBlock)) {
|
|
11923
11992
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
11924
|
-
|
|
11925
|
-
const childIndex = oldBlockChildrenLength - 1 -
|
|
11993
|
+
slateBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - slateBlock.children.length)).forEach((_, index2) => {
|
|
11994
|
+
const childIndex = oldBlockChildrenLength - 1 - index2;
|
|
11926
11995
|
childIndex > 0 && (debug$2("Removing child"), Transforms.removeNodes(slateEditor, {
|
|
11927
|
-
at: [
|
|
11996
|
+
at: [index2, childIndex]
|
|
11928
11997
|
}));
|
|
11929
|
-
}),
|
|
11930
|
-
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [
|
|
11998
|
+
}), slateBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
11999
|
+
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [index, currentBlockChildIndex];
|
|
11931
12000
|
if (isChildChanged)
|
|
11932
12001
|
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
11933
12002
|
debug$2("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
11934
12003
|
at: path
|
|
11935
12004
|
});
|
|
11936
|
-
const isSpanNode2 =
|
|
12005
|
+
const isSpanNode2 = isSpan({
|
|
12006
|
+
schema: context.schema
|
|
12007
|
+
}, currentBlockChild) && isSpan({
|
|
12008
|
+
schema: context.schema
|
|
12009
|
+
}, oldBlockChild);
|
|
11937
12010
|
isSpanNode2 && isTextChanged ? (oldBlockChild.text.length > 0 && deleteText(slateEditor, {
|
|
11938
12011
|
at: {
|
|
11939
12012
|
focus: {
|
|
@@ -11954,11 +12027,11 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
11954
12027
|
voids: !0
|
|
11955
12028
|
}));
|
|
11956
12029
|
} else oldBlockChild ? (debug$2("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
|
|
11957
|
-
at: [
|
|
12030
|
+
at: [index, currentBlockChildIndex]
|
|
11958
12031
|
}), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
11959
|
-
at: [
|
|
12032
|
+
at: [index, currentBlockChildIndex]
|
|
11960
12033
|
}), slateEditor.onChange()) : oldBlockChild || (debug$2("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
11961
|
-
at: [
|
|
12034
|
+
at: [index, currentBlockChildIndex]
|
|
11962
12035
|
}), slateEditor.onChange());
|
|
11963
12036
|
});
|
|
11964
12037
|
}
|