@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.cjs
CHANGED
|
@@ -29,53 +29,58 @@ function keepObjectEquality(object, keyMap) {
|
|
|
29
29
|
function toSlateValue(value, {
|
|
30
30
|
schemaTypes
|
|
31
31
|
}, keyMap = {}) {
|
|
32
|
-
return value && Array.isArray(value) ? value.map((block) => {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
return keepObjectEquality({
|
|
32
|
+
return value && Array.isArray(value) ? value.map((block) => toSlateBlock(block, {
|
|
33
|
+
schemaTypes
|
|
34
|
+
}, keyMap)) : [];
|
|
35
|
+
}
|
|
36
|
+
function toSlateBlock(block, {
|
|
37
|
+
schemaTypes
|
|
38
|
+
}, keyMap = {}) {
|
|
39
|
+
const {
|
|
40
|
+
_type,
|
|
41
|
+
_key,
|
|
42
|
+
...rest
|
|
43
|
+
} = block;
|
|
44
|
+
if (block && block._type === schemaTypes.block.name) {
|
|
45
|
+
const textBlock = block;
|
|
46
|
+
let hasInlines = !1;
|
|
47
|
+
const hasMissingStyle = typeof textBlock.style > "u", hasMissingMarkDefs = typeof textBlock.markDefs > "u", hasMissingChildren = typeof textBlock.children > "u", children = (textBlock.children || []).map((child) => {
|
|
48
|
+
const {
|
|
49
|
+
_type: cType,
|
|
50
|
+
_key: cKey,
|
|
51
|
+
...cRest
|
|
52
|
+
} = child;
|
|
53
|
+
return cType !== "span" ? (hasInlines = !0, keepObjectEquality({
|
|
54
|
+
_type: cType,
|
|
55
|
+
_key: cKey,
|
|
56
|
+
children: [{
|
|
57
|
+
_key: VOID_CHILD_KEY,
|
|
58
|
+
_type: "span",
|
|
59
|
+
text: "",
|
|
60
|
+
marks: []
|
|
61
|
+
}],
|
|
62
|
+
value: cRest,
|
|
63
|
+
__inline: !0
|
|
64
|
+
}, keyMap)) : child;
|
|
65
|
+
});
|
|
66
|
+
return !hasMissingStyle && !hasMissingMarkDefs && !hasMissingChildren && !hasInlines && slate.Element.isElement(block) ? block : (hasMissingStyle && (rest.style = schemaTypes.styles[0].name), keepObjectEquality({
|
|
68
67
|
_type,
|
|
69
68
|
_key,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
69
|
+
...rest,
|
|
70
|
+
children
|
|
71
|
+
}, keyMap));
|
|
72
|
+
}
|
|
73
|
+
return keepObjectEquality({
|
|
74
|
+
_type,
|
|
75
|
+
_key,
|
|
76
|
+
children: [{
|
|
77
|
+
_key: VOID_CHILD_KEY,
|
|
78
|
+
_type: "span",
|
|
79
|
+
text: "",
|
|
80
|
+
marks: []
|
|
81
|
+
}],
|
|
82
|
+
value: rest
|
|
83
|
+
}, keyMap);
|
|
79
84
|
}
|
|
80
85
|
function fromSlateValue(value, textBlockType, keyMap = {}) {
|
|
81
86
|
return value.map((block) => {
|
|
@@ -1961,7 +1966,7 @@ function validateSelection(slateEditor, editorElement) {
|
|
|
1961
1966
|
}
|
|
1962
1967
|
}
|
|
1963
1968
|
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 = React.forwardRef(function(props, forwardedRef) {
|
|
1964
|
-
const $ = reactCompilerRuntime.c(
|
|
1969
|
+
const $ = reactCompilerRuntime.c(176);
|
|
1965
1970
|
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;
|
|
1966
1971
|
$[0] !== props ? ({
|
|
1967
1972
|
hotkeys,
|
|
@@ -2004,47 +2009,50 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2004
2009
|
$[30] !== rangeDecorations ? (t1 = rangeDecorations ?? [], $[30] = rangeDecorations, $[31] = t1) : t1 = $[31];
|
|
2005
2010
|
let t2;
|
|
2006
2011
|
$[32] !== editorActor ? (t2 = editorActor.getSnapshot(), $[32] = editorActor, $[33] = t2) : t2 = $[33];
|
|
2007
|
-
const t3 =
|
|
2008
|
-
setup: "setting up"
|
|
2009
|
-
});
|
|
2012
|
+
const t3 = t2.context.schema;
|
|
2010
2013
|
let t4;
|
|
2011
|
-
$[34] !==
|
|
2014
|
+
$[34] !== editorActor ? (t4 = editorActor.getSnapshot().matches({
|
|
2015
|
+
setup: "setting up"
|
|
2016
|
+
}), $[34] = editorActor, $[35] = t4) : t4 = $[35];
|
|
2017
|
+
const t5 = !t4;
|
|
2018
|
+
let t6;
|
|
2019
|
+
$[36] !== readOnly || $[37] !== slateEditor || $[38] !== t1 || $[39] !== t2.context.schema || $[40] !== t5 ? (t6 = {
|
|
2012
2020
|
input: {
|
|
2013
2021
|
rangeDecorations: t1,
|
|
2014
2022
|
readOnly,
|
|
2015
|
-
schema:
|
|
2023
|
+
schema: t3,
|
|
2016
2024
|
slateEditor,
|
|
2017
|
-
skipSetup:
|
|
2025
|
+
skipSetup: t5
|
|
2018
2026
|
}
|
|
2019
|
-
}, $[
|
|
2020
|
-
const rangeDecorationsActor = react.useActorRef(rangeDecorationsMachine,
|
|
2021
|
-
let
|
|
2022
|
-
$[
|
|
2027
|
+
}, $[36] = readOnly, $[37] = slateEditor, $[38] = t1, $[39] = t2.context.schema, $[40] = t5, $[41] = t6) : t6 = $[41];
|
|
2028
|
+
const rangeDecorationsActor = react.useActorRef(rangeDecorationsMachine, t6), decorate = react.useSelector(rangeDecorationsActor, _temp2);
|
|
2029
|
+
let t7, t8;
|
|
2030
|
+
$[42] !== rangeDecorationsActor || $[43] !== readOnly ? (t7 = () => {
|
|
2023
2031
|
rangeDecorationsActor.send({
|
|
2024
2032
|
type: "update read only",
|
|
2025
2033
|
readOnly
|
|
2026
2034
|
});
|
|
2027
|
-
},
|
|
2028
|
-
let
|
|
2029
|
-
$[
|
|
2035
|
+
}, t8 = [rangeDecorationsActor, readOnly], $[42] = rangeDecorationsActor, $[43] = readOnly, $[44] = t7, $[45] = t8) : (t7 = $[44], t8 = $[45]), React.useEffect(t7, t8);
|
|
2036
|
+
let t10, t9;
|
|
2037
|
+
$[46] !== rangeDecorations || $[47] !== rangeDecorationsActor ? (t9 = () => {
|
|
2030
2038
|
rangeDecorationsActor.send({
|
|
2031
2039
|
type: "range decorations updated",
|
|
2032
2040
|
rangeDecorations: rangeDecorations ?? []
|
|
2033
2041
|
});
|
|
2034
|
-
},
|
|
2042
|
+
}, t10 = [rangeDecorationsActor, rangeDecorations], $[46] = rangeDecorations, $[47] = rangeDecorationsActor, $[48] = t10, $[49] = t9) : (t10 = $[48], t9 = $[49]), React.useEffect(t9, t10);
|
|
2035
2043
|
bb0: {
|
|
2036
2044
|
if (readOnly)
|
|
2037
2045
|
break bb0;
|
|
2038
2046
|
createWithHotkeys(editorActor, portableTextEditor, hotkeys)(slateEditor);
|
|
2039
2047
|
}
|
|
2040
|
-
let t10;
|
|
2041
|
-
$[48] !== readOnly || $[49] !== renderBlock || $[50] !== renderChild || $[51] !== renderListItem || $[52] !== renderStyle || $[53] !== spellCheck ? (t10 = (eProps) => /* @__PURE__ */ jsxRuntime.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];
|
|
2042
|
-
const renderElement = t10;
|
|
2043
|
-
let t11;
|
|
2044
|
-
$[55] !== readOnly || $[56] !== renderAnnotation || $[57] !== renderChild || $[58] !== renderDecorator || $[59] !== renderPlaceholder ? (t11 = (leafProps) => /* @__PURE__ */ jsxRuntime.jsx(RenderLeaf, { ...leafProps, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder }), $[55] = readOnly, $[56] = renderAnnotation, $[57] = renderChild, $[58] = renderDecorator, $[59] = renderPlaceholder, $[60] = t11) : t11 = $[60];
|
|
2045
|
-
const renderLeaf = t11, renderText = _temp3;
|
|
2046
2048
|
let t12;
|
|
2047
|
-
$[
|
|
2049
|
+
$[50] !== readOnly || $[51] !== renderBlock || $[52] !== renderChild || $[53] !== renderListItem || $[54] !== renderStyle || $[55] !== spellCheck ? (t12 = (eProps) => /* @__PURE__ */ jsxRuntime.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];
|
|
2050
|
+
const renderElement = t12;
|
|
2051
|
+
let t13;
|
|
2052
|
+
$[57] !== readOnly || $[58] !== renderAnnotation || $[59] !== renderChild || $[60] !== renderDecorator || $[61] !== renderPlaceholder ? (t13 = (leafProps) => /* @__PURE__ */ jsxRuntime.jsx(RenderLeaf, { ...leafProps, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder }), $[57] = readOnly, $[58] = renderAnnotation, $[59] = renderChild, $[60] = renderDecorator, $[61] = renderPlaceholder, $[62] = t13) : t13 = $[62];
|
|
2053
|
+
const renderLeaf = t13, renderText = _temp3;
|
|
2054
|
+
let t14;
|
|
2055
|
+
$[63] !== editorActor || $[64] !== propsSelection || $[65] !== slateEditor ? (t14 = () => {
|
|
2048
2056
|
if (propsSelection) {
|
|
2049
2057
|
debug$d(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
2050
2058
|
const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name));
|
|
@@ -2064,10 +2072,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2064
2072
|
}), slateEditor.onChange());
|
|
2065
2073
|
}
|
|
2066
2074
|
}
|
|
2067
|
-
}, $[
|
|
2068
|
-
const restoreSelectionFromProps =
|
|
2069
|
-
let
|
|
2070
|
-
$[
|
|
2075
|
+
}, $[63] = editorActor, $[64] = propsSelection, $[65] = slateEditor, $[66] = t14) : t14 = $[66];
|
|
2076
|
+
const restoreSelectionFromProps = t14;
|
|
2077
|
+
let t15, t16;
|
|
2078
|
+
$[67] !== editorActor || $[68] !== rangeDecorationsActor || $[69] !== restoreSelectionFromProps ? (t15 = () => {
|
|
2071
2079
|
const onReady = editorActor.on("ready", () => {
|
|
2072
2080
|
rangeDecorationsActor.send({
|
|
2073
2081
|
type: "ready"
|
|
@@ -2080,13 +2088,13 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2080
2088
|
return () => {
|
|
2081
2089
|
onReady.unsubscribe(), onInvalidValue.unsubscribe(), onValueChanged.unsubscribe();
|
|
2082
2090
|
};
|
|
2083
|
-
},
|
|
2084
|
-
let
|
|
2085
|
-
$[
|
|
2091
|
+
}, t16 = [rangeDecorationsActor, editorActor, restoreSelectionFromProps], $[67] = editorActor, $[68] = rangeDecorationsActor, $[69] = restoreSelectionFromProps, $[70] = t15, $[71] = t16) : (t15 = $[70], t16 = $[71]), React.useEffect(t15, t16);
|
|
2092
|
+
let t17, t18;
|
|
2093
|
+
$[72] !== hasInvalidValue || $[73] !== propsSelection || $[74] !== restoreSelectionFromProps ? (t17 = () => {
|
|
2086
2094
|
propsSelection && !hasInvalidValue && restoreSelectionFromProps();
|
|
2087
|
-
},
|
|
2088
|
-
let
|
|
2089
|
-
$[
|
|
2095
|
+
}, t18 = [hasInvalidValue, propsSelection, restoreSelectionFromProps], $[72] = hasInvalidValue, $[73] = propsSelection, $[74] = restoreSelectionFromProps, $[75] = t17, $[76] = t18) : (t17 = $[75], t18 = $[76]), React.useEffect(t17, t18);
|
|
2096
|
+
let t19;
|
|
2097
|
+
$[77] !== editorActor || $[78] !== onCopy || $[79] !== slateEditor ? (t19 = (event) => {
|
|
2090
2098
|
if (onCopy)
|
|
2091
2099
|
onCopy(event) !== void 0 && event.preventDefault();
|
|
2092
2100
|
else if (event.nativeEvent.clipboardData) {
|
|
@@ -2115,10 +2123,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2115
2123
|
nativeEvent: event
|
|
2116
2124
|
});
|
|
2117
2125
|
}
|
|
2118
|
-
}, $[
|
|
2119
|
-
const handleCopy =
|
|
2120
|
-
let
|
|
2121
|
-
$[
|
|
2126
|
+
}, $[77] = editorActor, $[78] = onCopy, $[79] = slateEditor, $[80] = t19) : t19 = $[80];
|
|
2127
|
+
const handleCopy = t19;
|
|
2128
|
+
let t20;
|
|
2129
|
+
$[81] !== editorActor || $[82] !== onCut || $[83] !== slateEditor ? (t20 = (event_0) => {
|
|
2122
2130
|
if (onCut)
|
|
2123
2131
|
onCut(event_0) !== void 0 && event_0.preventDefault();
|
|
2124
2132
|
else if (event_0.nativeEvent.clipboardData) {
|
|
@@ -2143,10 +2151,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2143
2151
|
nativeEvent: event_0
|
|
2144
2152
|
});
|
|
2145
2153
|
}
|
|
2146
|
-
}, $[
|
|
2147
|
-
const handleCut =
|
|
2148
|
-
let
|
|
2149
|
-
$[
|
|
2154
|
+
}, $[81] = editorActor, $[82] = onCut, $[83] = slateEditor, $[84] = t20) : t20 = $[84];
|
|
2155
|
+
const handleCut = t20;
|
|
2156
|
+
let t21;
|
|
2157
|
+
$[85] !== editorActor || $[86] !== onPaste || $[87] !== portableTextEditor || $[88] !== relayActor || $[89] !== slateEditor ? (t21 = (event_1) => {
|
|
2150
2158
|
const value = fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditor)), path = (slateEditor.selection ? slateRangeToSelection({
|
|
2151
2159
|
schema: editorActor.getSnapshot().context.schema,
|
|
2152
2160
|
editor: slateEditor,
|
|
@@ -2230,18 +2238,18 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2230
2238
|
});
|
|
2231
2239
|
}
|
|
2232
2240
|
debug$d("No result from custom paste handler, pasting normally");
|
|
2233
|
-
}, $[
|
|
2234
|
-
const handlePaste =
|
|
2235
|
-
let
|
|
2236
|
-
$[
|
|
2241
|
+
}, $[85] = editorActor, $[86] = onPaste, $[87] = portableTextEditor, $[88] = relayActor, $[89] = slateEditor, $[90] = t21) : t21 = $[90];
|
|
2242
|
+
const handlePaste = t21;
|
|
2243
|
+
let t22;
|
|
2244
|
+
$[91] !== editorActor || $[92] !== onFocus || $[93] !== relayActor || $[94] !== slateEditor ? (t22 = (event_2) => {
|
|
2237
2245
|
onFocus && onFocus(event_2), event_2.isDefaultPrevented() || (relayActor.send({
|
|
2238
2246
|
type: "focused",
|
|
2239
2247
|
event: event_2
|
|
2240
2248
|
}), !slateEditor.selection && isEqualToEmptyEditor(slateEditor.children, editorActor.getSnapshot().context.schema) && (slate.Transforms.select(slateEditor, slate.Editor.start(slateEditor, [])), slateEditor.onChange()));
|
|
2241
|
-
}, $[
|
|
2242
|
-
const handleOnFocus =
|
|
2243
|
-
let
|
|
2244
|
-
$[
|
|
2249
|
+
}, $[91] = editorActor, $[92] = onFocus, $[93] = relayActor, $[94] = slateEditor, $[95] = t22) : t22 = $[95];
|
|
2250
|
+
const handleOnFocus = t22;
|
|
2251
|
+
let t23;
|
|
2252
|
+
$[96] !== editorActor || $[97] !== onClick || $[98] !== slateEditor ? (t23 = (event_3) => {
|
|
2245
2253
|
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
2246
2254
|
return;
|
|
2247
2255
|
const position_3 = getEventPosition({
|
|
@@ -2258,23 +2266,23 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2258
2266
|
editor: slateEditor,
|
|
2259
2267
|
nativeEvent: event_3
|
|
2260
2268
|
});
|
|
2261
|
-
}, $[
|
|
2262
|
-
const handleClick =
|
|
2263
|
-
let
|
|
2264
|
-
$[
|
|
2269
|
+
}, $[96] = editorActor, $[97] = onClick, $[98] = slateEditor, $[99] = t23) : t23 = $[99];
|
|
2270
|
+
const handleClick = t23;
|
|
2271
|
+
let t24;
|
|
2272
|
+
$[100] !== onBlur || $[101] !== relayActor ? (t24 = (event_4) => {
|
|
2265
2273
|
onBlur && onBlur(event_4), event_4.isPropagationStopped() || relayActor.send({
|
|
2266
2274
|
type: "blurred",
|
|
2267
2275
|
event: event_4
|
|
2268
2276
|
});
|
|
2269
|
-
}, $[
|
|
2270
|
-
const handleOnBlur =
|
|
2271
|
-
let
|
|
2272
|
-
$[
|
|
2277
|
+
}, $[100] = onBlur, $[101] = relayActor, $[102] = t24) : t24 = $[102];
|
|
2278
|
+
const handleOnBlur = t24;
|
|
2279
|
+
let t25;
|
|
2280
|
+
$[103] !== onBeforeInput ? (t25 = (event_5) => {
|
|
2273
2281
|
onBeforeInput && onBeforeInput(event_5);
|
|
2274
|
-
}, $[
|
|
2275
|
-
const handleOnBeforeInput =
|
|
2276
|
-
let
|
|
2277
|
-
$[
|
|
2282
|
+
}, $[103] = onBeforeInput, $[104] = t25) : t25 = $[104];
|
|
2283
|
+
const handleOnBeforeInput = t25;
|
|
2284
|
+
let t26;
|
|
2285
|
+
$[105] !== editorActor || $[106] !== props || $[107] !== slateEditor ? (t26 = (event_6) => {
|
|
2278
2286
|
props.onKeyDown && props.onKeyDown(event_6), event_6.isDefaultPrevented() || slateEditor.pteWithHotKeys(event_6), event_6.isDefaultPrevented() || editorActor.send({
|
|
2279
2287
|
type: "behavior event",
|
|
2280
2288
|
behaviorEvent: {
|
|
@@ -2291,10 +2299,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2291
2299
|
editor: slateEditor,
|
|
2292
2300
|
nativeEvent: event_6
|
|
2293
2301
|
});
|
|
2294
|
-
}, $[
|
|
2295
|
-
const handleKeyDown =
|
|
2296
|
-
let
|
|
2297
|
-
$[
|
|
2302
|
+
}, $[105] = editorActor, $[106] = props, $[107] = slateEditor, $[108] = t26) : t26 = $[108];
|
|
2303
|
+
const handleKeyDown = t26;
|
|
2304
|
+
let t27;
|
|
2305
|
+
$[109] !== editorActor || $[110] !== props || $[111] !== slateEditor ? (t27 = (event_7) => {
|
|
2298
2306
|
props.onKeyUp && props.onKeyUp(event_7), event_7.isDefaultPrevented() || editorActor.send({
|
|
2299
2307
|
type: "behavior event",
|
|
2300
2308
|
behaviorEvent: {
|
|
@@ -2311,26 +2319,26 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2311
2319
|
editor: slateEditor,
|
|
2312
2320
|
nativeEvent: event_7
|
|
2313
2321
|
});
|
|
2314
|
-
}, $[
|
|
2315
|
-
const handleKeyUp =
|
|
2316
|
-
let
|
|
2322
|
+
}, $[109] = editorActor, $[110] = props, $[111] = slateEditor, $[112] = t27) : t27 = $[112];
|
|
2323
|
+
const handleKeyUp = t27;
|
|
2324
|
+
let t28;
|
|
2317
2325
|
bb1: {
|
|
2318
2326
|
if (scrollSelectionIntoView === void 0) {
|
|
2319
|
-
|
|
2327
|
+
t28 = void 0;
|
|
2320
2328
|
break bb1;
|
|
2321
2329
|
}
|
|
2322
2330
|
if (scrollSelectionIntoView === null) {
|
|
2323
|
-
|
|
2331
|
+
t28 = noop__default.default;
|
|
2324
2332
|
break bb1;
|
|
2325
2333
|
}
|
|
2326
|
-
let
|
|
2327
|
-
$[
|
|
2334
|
+
let t292;
|
|
2335
|
+
$[113] !== portableTextEditor || $[114] !== scrollSelectionIntoView ? (t292 = (_editor, domRange) => {
|
|
2328
2336
|
scrollSelectionIntoView(portableTextEditor, domRange);
|
|
2329
|
-
}, $[
|
|
2337
|
+
}, $[113] = portableTextEditor, $[114] = scrollSelectionIntoView, $[115] = t292) : t292 = $[115], t28 = t292;
|
|
2330
2338
|
}
|
|
2331
|
-
const scrollSelectionIntoViewToSlate =
|
|
2332
|
-
let
|
|
2333
|
-
$[
|
|
2339
|
+
const scrollSelectionIntoViewToSlate = t28;
|
|
2340
|
+
let t29, t30;
|
|
2341
|
+
$[116] !== editorActor || $[117] !== slateEditor ? (t29 = () => {
|
|
2334
2342
|
const window2 = slateReact.ReactEditor.getWindow(slateEditor), onDragEnd_0 = () => {
|
|
2335
2343
|
editorActor.send({
|
|
2336
2344
|
type: "dragend"
|
|
@@ -2343,9 +2351,9 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2343
2351
|
return window2.document.addEventListener("dragend", onDragEnd_0), window2.document.addEventListener("drop", onDrop_0), () => {
|
|
2344
2352
|
window2.document.removeEventListener("dragend", onDragEnd_0), window2.document.removeEventListener("drop", onDrop_0);
|
|
2345
2353
|
};
|
|
2346
|
-
},
|
|
2347
|
-
let
|
|
2348
|
-
$[
|
|
2354
|
+
}, t30 = [slateEditor, editorActor], $[116] = editorActor, $[117] = slateEditor, $[118] = t29, $[119] = t30) : (t29 = $[118], t30 = $[119]), React.useEffect(t29, t30);
|
|
2355
|
+
let t31;
|
|
2356
|
+
$[120] !== editorActor || $[121] !== onDragStart || $[122] !== slateEditor ? (t31 = (event_8) => {
|
|
2349
2357
|
if (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped())
|
|
2350
2358
|
return;
|
|
2351
2359
|
const position_4 = getEventPosition({
|
|
@@ -2373,10 +2381,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2373
2381
|
},
|
|
2374
2382
|
editor: slateEditor
|
|
2375
2383
|
}), !0;
|
|
2376
|
-
}, $[
|
|
2377
|
-
const handleDragStart =
|
|
2378
|
-
let
|
|
2379
|
-
$[
|
|
2384
|
+
}, $[120] = editorActor, $[121] = onDragStart, $[122] = slateEditor, $[123] = t31) : t31 = $[123];
|
|
2385
|
+
const handleDragStart = t31;
|
|
2386
|
+
let t32;
|
|
2387
|
+
$[124] !== editorActor || $[125] !== onDrag || $[126] !== slateEditor ? (t32 = (event_9) => {
|
|
2380
2388
|
if (onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped() || !getEventPosition({
|
|
2381
2389
|
editorActor,
|
|
2382
2390
|
slateEditor,
|
|
@@ -2392,10 +2400,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2392
2400
|
},
|
|
2393
2401
|
editor: slateEditor
|
|
2394
2402
|
}), !0;
|
|
2395
|
-
}, $[
|
|
2396
|
-
const handleDrag =
|
|
2397
|
-
let
|
|
2398
|
-
$[
|
|
2403
|
+
}, $[124] = editorActor, $[125] = onDrag, $[126] = slateEditor, $[127] = t32) : t32 = $[127];
|
|
2404
|
+
const handleDrag = t32;
|
|
2405
|
+
let t33;
|
|
2406
|
+
$[128] !== editorActor || $[129] !== onDragEnd || $[130] !== slateEditor ? (t33 = (event_10) => {
|
|
2399
2407
|
if (onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped()))
|
|
2400
2408
|
return editorActor.send({
|
|
2401
2409
|
type: "behavior event",
|
|
@@ -2407,10 +2415,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2407
2415
|
},
|
|
2408
2416
|
editor: slateEditor
|
|
2409
2417
|
}), !0;
|
|
2410
|
-
}, $[
|
|
2411
|
-
const handleDragEnd =
|
|
2412
|
-
let
|
|
2413
|
-
$[
|
|
2418
|
+
}, $[128] = editorActor, $[129] = onDragEnd, $[130] = slateEditor, $[131] = t33) : t33 = $[131];
|
|
2419
|
+
const handleDragEnd = t33;
|
|
2420
|
+
let t34;
|
|
2421
|
+
$[132] !== editorActor || $[133] !== onDragEnter || $[134] !== slateEditor ? (t34 = (event_11) => {
|
|
2414
2422
|
if (onDragEnter?.(event_11), event_11.isDefaultPrevented() || event_11.isPropagationStopped())
|
|
2415
2423
|
return;
|
|
2416
2424
|
const position_6 = getEventPosition({
|
|
@@ -2430,10 +2438,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2430
2438
|
},
|
|
2431
2439
|
editor: slateEditor
|
|
2432
2440
|
}), !0;
|
|
2433
|
-
}, $[
|
|
2434
|
-
const handleDragEnter =
|
|
2435
|
-
let
|
|
2436
|
-
$[
|
|
2441
|
+
}, $[132] = editorActor, $[133] = onDragEnter, $[134] = slateEditor, $[135] = t34) : t34 = $[135];
|
|
2442
|
+
const handleDragEnter = t34;
|
|
2443
|
+
let t35;
|
|
2444
|
+
$[136] !== editorActor || $[137] !== onDragOver || $[138] !== slateEditor ? (t35 = (event_12) => {
|
|
2437
2445
|
if (onDragOver?.(event_12), event_12.isDefaultPrevented() || event_12.isPropagationStopped())
|
|
2438
2446
|
return;
|
|
2439
2447
|
const position_7 = getEventPosition({
|
|
@@ -2455,10 +2463,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2455
2463
|
editor: slateEditor,
|
|
2456
2464
|
nativeEvent: event_12
|
|
2457
2465
|
}), !0;
|
|
2458
|
-
}, $[
|
|
2459
|
-
const handleDragOver =
|
|
2460
|
-
let
|
|
2461
|
-
$[
|
|
2466
|
+
}, $[136] = editorActor, $[137] = onDragOver, $[138] = slateEditor, $[139] = t35) : t35 = $[139];
|
|
2467
|
+
const handleDragOver = t35;
|
|
2468
|
+
let t36;
|
|
2469
|
+
$[140] !== editorActor || $[141] !== onDrop || $[142] !== slateEditor ? (t36 = (event_13) => {
|
|
2462
2470
|
if (onDrop?.(event_13), event_13.isDefaultPrevented() || event_13.isPropagationStopped())
|
|
2463
2471
|
return;
|
|
2464
2472
|
const position_8 = getEventPosition({
|
|
@@ -2483,10 +2491,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2483
2491
|
editor: slateEditor,
|
|
2484
2492
|
nativeEvent: event_13
|
|
2485
2493
|
}), !0;
|
|
2486
|
-
}, $[
|
|
2487
|
-
const handleDrop =
|
|
2488
|
-
let
|
|
2489
|
-
$[
|
|
2494
|
+
}, $[140] = editorActor, $[141] = onDrop, $[142] = slateEditor, $[143] = t36) : t36 = $[143];
|
|
2495
|
+
const handleDrop = t36;
|
|
2496
|
+
let t37;
|
|
2497
|
+
$[144] !== editorActor || $[145] !== onDragLeave || $[146] !== slateEditor ? (t37 = (event_14) => {
|
|
2490
2498
|
if (onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped() || !getEventPosition({
|
|
2491
2499
|
editorActor,
|
|
2492
2500
|
slateEditor,
|
|
@@ -2502,10 +2510,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2502
2510
|
},
|
|
2503
2511
|
editor: slateEditor
|
|
2504
2512
|
}), !0;
|
|
2505
|
-
}, $[
|
|
2506
|
-
const handleDragLeave =
|
|
2507
|
-
let
|
|
2508
|
-
$[
|
|
2513
|
+
}, $[144] = editorActor, $[145] = onDragLeave, $[146] = slateEditor, $[147] = t37) : t37 = $[147];
|
|
2514
|
+
const handleDragLeave = t37;
|
|
2515
|
+
let t38;
|
|
2516
|
+
$[148] !== forwardedRef || $[149] !== validateSelectionActor ? (t38 = (editorElement) => {
|
|
2509
2517
|
if (typeof forwardedRef == "function" ? forwardedRef(editorElement) : forwardedRef && (forwardedRef.current = editorElement), editorElement) {
|
|
2510
2518
|
const mutationObserver = new MutationObserver(() => {
|
|
2511
2519
|
validateSelectionActor.send({
|
|
@@ -2523,12 +2531,12 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2523
2531
|
mutationObserver.disconnect();
|
|
2524
2532
|
};
|
|
2525
2533
|
}
|
|
2526
|
-
}, $[
|
|
2527
|
-
const callbackRef =
|
|
2534
|
+
}, $[148] = forwardedRef, $[149] = validateSelectionActor, $[150] = t38) : t38 = $[150];
|
|
2535
|
+
const callbackRef = t38;
|
|
2528
2536
|
if (!portableTextEditor)
|
|
2529
2537
|
return null;
|
|
2530
|
-
let
|
|
2531
|
-
return $[
|
|
2538
|
+
let t39;
|
|
2539
|
+
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__ */ jsxRuntime.jsx(slateReact.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;
|
|
2532
2540
|
});
|
|
2533
2541
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
2534
2542
|
function _temp(s) {
|
|
@@ -3896,27 +3904,26 @@ function createWithUndoRedo(options) {
|
|
|
3896
3904
|
apply2(op);
|
|
3897
3905
|
return;
|
|
3898
3906
|
}
|
|
3899
|
-
const
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
if (
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
timestamp: /* @__PURE__ */ new Date()
|
|
3913
|
-
};
|
|
3914
|
-
undos.push(newStep), debug$b("Created new undo step", step);
|
|
3915
|
-
}
|
|
3916
|
-
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
3917
|
-
undos.shift();
|
|
3918
|
-
shouldClear(op) && (history.redos = []);
|
|
3907
|
+
const savingUndoSteps = isSaving(editor), currentUndoStepId = getCurrentUndoStepId(editor);
|
|
3908
|
+
if (!savingUndoSteps) {
|
|
3909
|
+
previousUndoStepId = currentUndoStepId, apply2(op);
|
|
3910
|
+
return;
|
|
3911
|
+
}
|
|
3912
|
+
op.type !== "set_selection" && (editor.history.redos = []);
|
|
3913
|
+
const step = editor.history.undos.at(editor.history.undos.length - 1);
|
|
3914
|
+
if (!step) {
|
|
3915
|
+
editor.history.undos.push({
|
|
3916
|
+
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
3917
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
3918
|
+
}), apply2(op), previousUndoStepId = currentUndoStepId;
|
|
3919
|
+
return;
|
|
3919
3920
|
}
|
|
3921
|
+
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);
|
|
3922
|
+
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({
|
|
3923
|
+
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
3924
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
3925
|
+
}); editor.history.undos.length > UNDO_STEP_LIMIT; )
|
|
3926
|
+
editor.history.undos.shift();
|
|
3920
3927
|
previousUndoStepId = currentUndoStepId, apply2(op);
|
|
3921
3928
|
}, editor;
|
|
3922
3929
|
};
|
|
@@ -4075,7 +4082,7 @@ function adjustBlockPath(operation, level, blockIndex) {
|
|
|
4075
4082
|
}
|
|
4076
4083
|
return transformedOperation;
|
|
4077
4084
|
}
|
|
4078
|
-
const shouldMerge = (op, prev) => !!(op.type === "set_selection" || prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && slate.Path.equals(op.path, prev.path) && op.text !== " " || prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && slate.Path.equals(op.path, prev.path))
|
|
4085
|
+
const shouldMerge = (op, prev) => !!(op.type === "set_selection" || prev && op.type === "insert_text" && prev.type === "insert_text" && op.offset === prev.offset + prev.text.length && slate.Path.equals(op.path, prev.path) && op.text !== " " || prev && op.type === "remove_text" && prev.type === "remove_text" && op.offset + op.text.length === prev.offset && slate.Path.equals(op.path, prev.path));
|
|
4079
4086
|
function withoutSaving(editor, fn) {
|
|
4080
4087
|
const prev = isSaving(editor);
|
|
4081
4088
|
SAVING.set(editor, !1), fn(), SAVING.set(editor, prev);
|
|
@@ -11279,7 +11286,9 @@ function validateValue(value, types, keyGenerator) {
|
|
|
11279
11286
|
}
|
|
11280
11287
|
}, !0;
|
|
11281
11288
|
}
|
|
11282
|
-
const allUsedMarks = uniq__default.default(flatten__default.default(textBlock.children.filter((
|
|
11289
|
+
const allUsedMarks = uniq__default.default(flatten__default.default(textBlock.children.filter((child) => schema.isSpan({
|
|
11290
|
+
schema: types
|
|
11291
|
+
}, child)).map((cld) => cld.marks || [])));
|
|
11283
11292
|
if (Array.isArray(blk.markDefs) && blk.markDefs.length > 0) {
|
|
11284
11293
|
const unusedMarkDefs = uniq__default.default(blk.markDefs.map((def) => def._key).filter((key) => !allUsedMarks.includes(key)));
|
|
11285
11294
|
if (unusedMarkDefs.length > 0)
|
|
@@ -11684,75 +11693,24 @@ async function updateValue({
|
|
|
11684
11693
|
}) {
|
|
11685
11694
|
let doneSyncing = !1, isChanged = !1, isValid = !0;
|
|
11686
11695
|
const hadSelection = !!slateEditor.selection;
|
|
11687
|
-
if ((!value || value.length === 0) && (debug$2("Value is empty"),
|
|
11688
|
-
|
|
11689
|
-
|
|
11690
|
-
|
|
11691
|
-
|
|
11692
|
-
|
|
11693
|
-
|
|
11694
|
-
|
|
11695
|
-
|
|
11696
|
-
|
|
11697
|
-
|
|
11698
|
-
|
|
11699
|
-
|
|
11700
|
-
|
|
11701
|
-
|
|
11702
|
-
|
|
11703
|
-
|
|
11704
|
-
|
|
11705
|
-
});
|
|
11706
|
-
});
|
|
11707
|
-
}), isChanged = !0), value && value.length > 0) {
|
|
11708
|
-
const slateValueFromProps = toSlateValue(value, {
|
|
11709
|
-
schemaTypes: context.schema
|
|
11710
|
-
});
|
|
11711
|
-
streamBlocks ? await new Promise((resolve) => {
|
|
11712
|
-
slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
11713
|
-
withRemoteChanges(slateEditor, () => {
|
|
11714
|
-
withoutPatching(slateEditor, () => {
|
|
11715
|
-
if (doneSyncing) {
|
|
11716
|
-
resolve();
|
|
11717
|
-
return;
|
|
11718
|
-
}
|
|
11719
|
-
isChanged = removeExtraBlocks({
|
|
11720
|
-
slateEditor,
|
|
11721
|
-
slateValueFromProps
|
|
11722
|
-
}), (async () => {
|
|
11723
|
-
for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
|
|
11724
|
-
slateValue: slateValueFromProps
|
|
11725
|
-
})) {
|
|
11726
|
-
const {
|
|
11727
|
-
blockChanged,
|
|
11728
|
-
blockValid
|
|
11729
|
-
} = syncBlock({
|
|
11730
|
-
context,
|
|
11731
|
-
sendBack,
|
|
11732
|
-
block: currentBlock,
|
|
11733
|
-
index: currentBlockIndex,
|
|
11734
|
-
slateEditor,
|
|
11735
|
-
value
|
|
11736
|
-
});
|
|
11737
|
-
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
|
|
11738
|
-
break;
|
|
11739
|
-
}
|
|
11740
|
-
resolve();
|
|
11741
|
-
})();
|
|
11742
|
-
});
|
|
11743
|
-
});
|
|
11744
|
-
});
|
|
11745
|
-
}) : slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
11746
|
-
withRemoteChanges(slateEditor, () => {
|
|
11747
|
-
withoutPatching(slateEditor, () => {
|
|
11748
|
-
if (doneSyncing)
|
|
11749
|
-
return;
|
|
11750
|
-
isChanged = removeExtraBlocks({
|
|
11751
|
-
slateEditor,
|
|
11752
|
-
slateValueFromProps
|
|
11753
|
-
});
|
|
11754
|
-
let index = 0;
|
|
11755
|
-
for (const currentBlock of slateValueFromProps) {
|
|
11696
|
+
if ((!value || value.length === 0) && (debug$2("Value is empty"), clearEditor({
|
|
11697
|
+
slateEditor,
|
|
11698
|
+
doneSyncing,
|
|
11699
|
+
hadSelection
|
|
11700
|
+
}), isChanged = !0), value && value.length > 0)
|
|
11701
|
+
if (streamBlocks)
|
|
11702
|
+
await new Promise((resolve) => {
|
|
11703
|
+
if (doneSyncing) {
|
|
11704
|
+
resolve();
|
|
11705
|
+
return;
|
|
11706
|
+
}
|
|
11707
|
+
isChanged = removeExtraBlocks({
|
|
11708
|
+
slateEditor,
|
|
11709
|
+
value
|
|
11710
|
+
}), (async () => {
|
|
11711
|
+
for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
|
|
11712
|
+
value
|
|
11713
|
+
})) {
|
|
11756
11714
|
const {
|
|
11757
11715
|
blockChanged,
|
|
11758
11716
|
blockValid
|
|
@@ -11760,18 +11718,41 @@ async function updateValue({
|
|
|
11760
11718
|
context,
|
|
11761
11719
|
sendBack,
|
|
11762
11720
|
block: currentBlock,
|
|
11763
|
-
index,
|
|
11721
|
+
index: currentBlockIndex,
|
|
11764
11722
|
slateEditor,
|
|
11765
11723
|
value
|
|
11766
11724
|
});
|
|
11767
|
-
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !
|
|
11725
|
+
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
|
|
11768
11726
|
break;
|
|
11769
|
-
index++;
|
|
11770
11727
|
}
|
|
11771
|
-
|
|
11728
|
+
resolve();
|
|
11729
|
+
})();
|
|
11772
11730
|
});
|
|
11773
|
-
|
|
11774
|
-
|
|
11731
|
+
else {
|
|
11732
|
+
if (doneSyncing)
|
|
11733
|
+
return;
|
|
11734
|
+
isChanged = removeExtraBlocks({
|
|
11735
|
+
slateEditor,
|
|
11736
|
+
value
|
|
11737
|
+
});
|
|
11738
|
+
let index = 0;
|
|
11739
|
+
for (const block of value) {
|
|
11740
|
+
const {
|
|
11741
|
+
blockChanged,
|
|
11742
|
+
blockValid
|
|
11743
|
+
} = syncBlock({
|
|
11744
|
+
context,
|
|
11745
|
+
sendBack,
|
|
11746
|
+
block,
|
|
11747
|
+
index,
|
|
11748
|
+
slateEditor,
|
|
11749
|
+
value
|
|
11750
|
+
});
|
|
11751
|
+
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !blockValid)
|
|
11752
|
+
break;
|
|
11753
|
+
index++;
|
|
11754
|
+
}
|
|
11755
|
+
}
|
|
11775
11756
|
if (!isValid) {
|
|
11776
11757
|
debug$2("Invalid value, returning"), doneSyncing = !0, sendBack({
|
|
11777
11758
|
type: "done syncing",
|
|
@@ -11814,27 +11795,59 @@ async function updateValue({
|
|
|
11814
11795
|
value
|
|
11815
11796
|
});
|
|
11816
11797
|
}
|
|
11817
|
-
function
|
|
11798
|
+
async function* getStreamedBlocks({
|
|
11799
|
+
value
|
|
11800
|
+
}) {
|
|
11801
|
+
let index = 0;
|
|
11802
|
+
for await (const block of value)
|
|
11803
|
+
index % 10 === 0 && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
|
|
11804
|
+
}
|
|
11805
|
+
function clearEditor({
|
|
11818
11806
|
slateEditor,
|
|
11819
|
-
|
|
11807
|
+
doneSyncing,
|
|
11808
|
+
hadSelection
|
|
11820
11809
|
}) {
|
|
11821
|
-
|
|
11822
|
-
|
|
11823
|
-
|
|
11824
|
-
|
|
11825
|
-
|
|
11826
|
-
|
|
11810
|
+
slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
11811
|
+
withoutSaving(slateEditor, () => {
|
|
11812
|
+
withRemoteChanges(slateEditor, () => {
|
|
11813
|
+
withoutPatching(slateEditor, () => {
|
|
11814
|
+
if (doneSyncing)
|
|
11815
|
+
return;
|
|
11816
|
+
hadSelection && slate.Transforms.deselect(slateEditor);
|
|
11817
|
+
const childrenLength = slateEditor.children.length;
|
|
11818
|
+
slateEditor.children.forEach((_, index) => {
|
|
11819
|
+
slate.Transforms.removeNodes(slateEditor, {
|
|
11820
|
+
at: [childrenLength - 1 - index]
|
|
11821
|
+
});
|
|
11822
|
+
}), slate.Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
|
|
11823
|
+
decorators: []
|
|
11824
|
+
}), {
|
|
11825
|
+
at: [0]
|
|
11826
|
+
}), hadSelection && slate.Transforms.select(slateEditor, [0, 0]);
|
|
11827
|
+
});
|
|
11827
11828
|
});
|
|
11828
|
-
|
|
11829
|
-
}
|
|
11830
|
-
return isChanged;
|
|
11829
|
+
});
|
|
11830
|
+
});
|
|
11831
11831
|
}
|
|
11832
|
-
|
|
11833
|
-
|
|
11832
|
+
function removeExtraBlocks({
|
|
11833
|
+
slateEditor,
|
|
11834
|
+
value
|
|
11834
11835
|
}) {
|
|
11835
|
-
let
|
|
11836
|
-
|
|
11837
|
-
|
|
11836
|
+
let isChanged = !1;
|
|
11837
|
+
return slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
11838
|
+
withRemoteChanges(slateEditor, () => {
|
|
11839
|
+
withoutPatching(slateEditor, () => {
|
|
11840
|
+
const childrenLength = slateEditor.children.length;
|
|
11841
|
+
if (value.length < childrenLength) {
|
|
11842
|
+
for (let i = childrenLength - 1; i > value.length - 1; i--)
|
|
11843
|
+
slate.Transforms.removeNodes(slateEditor, {
|
|
11844
|
+
at: [i]
|
|
11845
|
+
});
|
|
11846
|
+
isChanged = !0;
|
|
11847
|
+
}
|
|
11848
|
+
});
|
|
11849
|
+
});
|
|
11850
|
+
}), isChanged;
|
|
11838
11851
|
}
|
|
11839
11852
|
function syncBlock({
|
|
11840
11853
|
context,
|
|
@@ -11844,67 +11857,127 @@ function syncBlock({
|
|
|
11844
11857
|
slateEditor,
|
|
11845
11858
|
value
|
|
11846
11859
|
}) {
|
|
11847
|
-
|
|
11848
|
-
|
|
11849
|
-
|
|
11860
|
+
const oldBlock = slateEditor.children.at(index);
|
|
11861
|
+
if (!oldBlock) {
|
|
11862
|
+
const validation2 = validateValue([block], context.schema, context.keyGenerator);
|
|
11863
|
+
if (debug$2.enabled && debug$2("Validating and inserting new block in the end of the value", block), validation2.valid || validation2.resolution?.autoResolve) {
|
|
11864
|
+
const slateBlock = toSlateBlock(block, {
|
|
11865
|
+
schemaTypes: context.schema
|
|
11866
|
+
});
|
|
11867
|
+
return slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
11868
|
+
withRemoteChanges(slateEditor, () => {
|
|
11869
|
+
withoutPatching(slateEditor, () => {
|
|
11870
|
+
slate.Transforms.insertNodes(slateEditor, slateBlock, {
|
|
11871
|
+
at: [index]
|
|
11872
|
+
});
|
|
11873
|
+
});
|
|
11874
|
+
});
|
|
11875
|
+
}), {
|
|
11876
|
+
blockChanged: !0,
|
|
11877
|
+
blockValid: !0
|
|
11878
|
+
};
|
|
11879
|
+
}
|
|
11880
|
+
return debug$2("Invalid", validation2), sendBack({
|
|
11881
|
+
type: "invalid value",
|
|
11882
|
+
resolution: validation2.resolution,
|
|
11883
|
+
value
|
|
11884
|
+
}), {
|
|
11885
|
+
blockChanged: !1,
|
|
11886
|
+
blockValid: !1
|
|
11887
|
+
};
|
|
11888
|
+
}
|
|
11889
|
+
if (isEqual__default.default(block, oldBlock))
|
|
11890
|
+
return {
|
|
11891
|
+
blockChanged: !1,
|
|
11892
|
+
blockValid: !0
|
|
11893
|
+
};
|
|
11894
|
+
const validationValue = [value[index]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
|
|
11895
|
+
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) => {
|
|
11896
|
+
sendBack({
|
|
11897
|
+
type: "patch",
|
|
11898
|
+
patch
|
|
11899
|
+
});
|
|
11900
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === block._key ? (debug$2.enabled && debug$2("Updating block", oldBlock, block), slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
11850
11901
|
withRemoteChanges(slateEditor, () => {
|
|
11851
11902
|
withoutPatching(slateEditor, () => {
|
|
11852
|
-
|
|
11853
|
-
|
|
11854
|
-
|
|
11855
|
-
|
|
11856
|
-
|
|
11857
|
-
|
|
11858
|
-
|
|
11859
|
-
|
|
11860
|
-
|
|
11861
|
-
|
|
11862
|
-
|
|
11863
|
-
|
|
11864
|
-
|
|
11865
|
-
|
|
11866
|
-
|
|
11867
|
-
|
|
11868
|
-
|
|
11869
|
-
|
|
11870
|
-
type: "invalid value",
|
|
11871
|
-
resolution: validation.resolution,
|
|
11872
|
-
value
|
|
11873
|
-
}), blockValid = !1);
|
|
11874
|
-
}
|
|
11903
|
+
updateBlock({
|
|
11904
|
+
context,
|
|
11905
|
+
slateEditor,
|
|
11906
|
+
oldBlock,
|
|
11907
|
+
block,
|
|
11908
|
+
index
|
|
11909
|
+
});
|
|
11910
|
+
});
|
|
11911
|
+
});
|
|
11912
|
+
})) : (debug$2.enabled && debug$2("Replacing block", oldBlock, block), slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
11913
|
+
withRemoteChanges(slateEditor, () => {
|
|
11914
|
+
withoutPatching(slateEditor, () => {
|
|
11915
|
+
replaceBlock({
|
|
11916
|
+
context,
|
|
11917
|
+
slateEditor,
|
|
11918
|
+
block,
|
|
11919
|
+
index
|
|
11920
|
+
});
|
|
11875
11921
|
});
|
|
11876
11922
|
});
|
|
11923
|
+
})), {
|
|
11924
|
+
blockChanged: !0,
|
|
11925
|
+
blockValid: !0
|
|
11926
|
+
}) : (sendBack({
|
|
11927
|
+
type: "invalid value",
|
|
11928
|
+
resolution: validation.resolution,
|
|
11929
|
+
value
|
|
11877
11930
|
}), {
|
|
11878
|
-
blockChanged,
|
|
11879
|
-
blockValid
|
|
11880
|
-
};
|
|
11931
|
+
blockChanged: !1,
|
|
11932
|
+
blockValid: !1
|
|
11933
|
+
});
|
|
11881
11934
|
}
|
|
11882
|
-
function
|
|
11883
|
-
|
|
11935
|
+
function replaceBlock({
|
|
11936
|
+
context,
|
|
11937
|
+
slateEditor,
|
|
11938
|
+
block,
|
|
11939
|
+
index
|
|
11940
|
+
}) {
|
|
11941
|
+
const slateBlock = toSlateBlock(block, {
|
|
11942
|
+
schemaTypes: context.schema
|
|
11943
|
+
}), currentSelection = slateEditor.selection, selectionFocusOnBlock = currentSelection && currentSelection.focus.path[0] === index;
|
|
11884
11944
|
selectionFocusOnBlock && slate.Transforms.deselect(slateEditor), slate.Transforms.removeNodes(slateEditor, {
|
|
11885
|
-
at: [
|
|
11886
|
-
}), slate.Transforms.insertNodes(slateEditor,
|
|
11887
|
-
at: [
|
|
11945
|
+
at: [index]
|
|
11946
|
+
}), slate.Transforms.insertNodes(slateEditor, slateBlock, {
|
|
11947
|
+
at: [index]
|
|
11888
11948
|
}), slateEditor.onChange(), selectionFocusOnBlock && slate.Transforms.select(slateEditor, currentSelection);
|
|
11889
11949
|
}
|
|
11890
|
-
function
|
|
11891
|
-
|
|
11892
|
-
|
|
11893
|
-
|
|
11950
|
+
function updateBlock({
|
|
11951
|
+
context,
|
|
11952
|
+
slateEditor,
|
|
11953
|
+
oldBlock,
|
|
11954
|
+
block,
|
|
11955
|
+
index
|
|
11956
|
+
}) {
|
|
11957
|
+
const slateBlock = toSlateBlock(block, {
|
|
11958
|
+
schemaTypes: context.schema
|
|
11959
|
+
});
|
|
11960
|
+
if (slate.Transforms.setNodes(slateEditor, slateBlock, {
|
|
11961
|
+
at: [index]
|
|
11962
|
+
}), slateEditor.isTextBlock(slateBlock) && slateEditor.isTextBlock(oldBlock)) {
|
|
11894
11963
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
11895
|
-
|
|
11896
|
-
const childIndex = oldBlockChildrenLength - 1 -
|
|
11964
|
+
slateBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - slateBlock.children.length)).forEach((_, index2) => {
|
|
11965
|
+
const childIndex = oldBlockChildrenLength - 1 - index2;
|
|
11897
11966
|
childIndex > 0 && (debug$2("Removing child"), slate.Transforms.removeNodes(slateEditor, {
|
|
11898
|
-
at: [
|
|
11967
|
+
at: [index2, childIndex]
|
|
11899
11968
|
}));
|
|
11900
|
-
}),
|
|
11901
|
-
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild?.text), path = [
|
|
11969
|
+
}), slateBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
11970
|
+
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual__default.default(currentBlockChild, oldBlockChild), isTextChanged = !isEqual__default.default(currentBlockChild.text, oldBlockChild?.text), path = [index, currentBlockChildIndex];
|
|
11902
11971
|
if (isChildChanged)
|
|
11903
11972
|
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
11904
11973
|
debug$2("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
11905
11974
|
at: path
|
|
11906
11975
|
});
|
|
11907
|
-
const isSpanNode2 =
|
|
11976
|
+
const isSpanNode2 = schema.isSpan({
|
|
11977
|
+
schema: context.schema
|
|
11978
|
+
}, currentBlockChild) && schema.isSpan({
|
|
11979
|
+
schema: context.schema
|
|
11980
|
+
}, oldBlockChild);
|
|
11908
11981
|
isSpanNode2 && isTextChanged ? (oldBlockChild.text.length > 0 && slate.deleteText(slateEditor, {
|
|
11909
11982
|
at: {
|
|
11910
11983
|
focus: {
|
|
@@ -11925,11 +11998,11 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
11925
11998
|
voids: !0
|
|
11926
11999
|
}));
|
|
11927
12000
|
} else oldBlockChild ? (debug$2("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
|
|
11928
|
-
at: [
|
|
12001
|
+
at: [index, currentBlockChildIndex]
|
|
11929
12002
|
}), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
11930
|
-
at: [
|
|
12003
|
+
at: [index, currentBlockChildIndex]
|
|
11931
12004
|
}), slateEditor.onChange()) : oldBlockChild || (debug$2("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
11932
|
-
at: [
|
|
12005
|
+
at: [index, currentBlockChildIndex]
|
|
11933
12006
|
}), slateEditor.onChange());
|
|
11934
12007
|
});
|
|
11935
12008
|
}
|