@portabletext/editor 2.14.3 → 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-es/use-editor.js.map +1 -1
- package/lib/index.cjs +342 -282
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +342 -282
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.ts +3 -3
- 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 +410 -311
package/lib/index.cjs
CHANGED
|
@@ -1966,7 +1966,7 @@ function validateSelection(slateEditor, editorElement) {
|
|
|
1966
1966
|
}
|
|
1967
1967
|
}
|
|
1968
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) {
|
|
1969
|
-
const $ = reactCompilerRuntime.c(
|
|
1969
|
+
const $ = reactCompilerRuntime.c(176);
|
|
1970
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;
|
|
1971
1971
|
$[0] !== props ? ({
|
|
1972
1972
|
hotkeys,
|
|
@@ -2009,47 +2009,50 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2009
2009
|
$[30] !== rangeDecorations ? (t1 = rangeDecorations ?? [], $[30] = rangeDecorations, $[31] = t1) : t1 = $[31];
|
|
2010
2010
|
let t2;
|
|
2011
2011
|
$[32] !== editorActor ? (t2 = editorActor.getSnapshot(), $[32] = editorActor, $[33] = t2) : t2 = $[33];
|
|
2012
|
-
const t3 =
|
|
2013
|
-
setup: "setting up"
|
|
2014
|
-
});
|
|
2012
|
+
const t3 = t2.context.schema;
|
|
2015
2013
|
let t4;
|
|
2016
|
-
$[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 = {
|
|
2017
2020
|
input: {
|
|
2018
2021
|
rangeDecorations: t1,
|
|
2019
2022
|
readOnly,
|
|
2020
|
-
schema:
|
|
2023
|
+
schema: t3,
|
|
2021
2024
|
slateEditor,
|
|
2022
|
-
skipSetup:
|
|
2025
|
+
skipSetup: t5
|
|
2023
2026
|
}
|
|
2024
|
-
}, $[
|
|
2025
|
-
const rangeDecorationsActor = react.useActorRef(rangeDecorationsMachine,
|
|
2026
|
-
let
|
|
2027
|
-
$[
|
|
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 = () => {
|
|
2028
2031
|
rangeDecorationsActor.send({
|
|
2029
2032
|
type: "update read only",
|
|
2030
2033
|
readOnly
|
|
2031
2034
|
});
|
|
2032
|
-
},
|
|
2033
|
-
let
|
|
2034
|
-
$[
|
|
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 = () => {
|
|
2035
2038
|
rangeDecorationsActor.send({
|
|
2036
2039
|
type: "range decorations updated",
|
|
2037
2040
|
rangeDecorations: rangeDecorations ?? []
|
|
2038
2041
|
});
|
|
2039
|
-
},
|
|
2042
|
+
}, t10 = [rangeDecorationsActor, rangeDecorations], $[46] = rangeDecorations, $[47] = rangeDecorationsActor, $[48] = t10, $[49] = t9) : (t10 = $[48], t9 = $[49]), React.useEffect(t9, t10);
|
|
2040
2043
|
bb0: {
|
|
2041
2044
|
if (readOnly)
|
|
2042
2045
|
break bb0;
|
|
2043
2046
|
createWithHotkeys(editorActor, portableTextEditor, hotkeys)(slateEditor);
|
|
2044
2047
|
}
|
|
2045
|
-
let t10;
|
|
2046
|
-
$[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];
|
|
2047
|
-
const renderElement = t10;
|
|
2048
|
-
let t11;
|
|
2049
|
-
$[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];
|
|
2050
|
-
const renderLeaf = t11, renderText = _temp3;
|
|
2051
2048
|
let t12;
|
|
2052
|
-
$[
|
|
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 = () => {
|
|
2053
2056
|
if (propsSelection) {
|
|
2054
2057
|
debug$d(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
2055
2058
|
const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name));
|
|
@@ -2069,10 +2072,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2069
2072
|
}), slateEditor.onChange());
|
|
2070
2073
|
}
|
|
2071
2074
|
}
|
|
2072
|
-
}, $[
|
|
2073
|
-
const restoreSelectionFromProps =
|
|
2074
|
-
let
|
|
2075
|
-
$[
|
|
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 = () => {
|
|
2076
2079
|
const onReady = editorActor.on("ready", () => {
|
|
2077
2080
|
rangeDecorationsActor.send({
|
|
2078
2081
|
type: "ready"
|
|
@@ -2085,13 +2088,13 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2085
2088
|
return () => {
|
|
2086
2089
|
onReady.unsubscribe(), onInvalidValue.unsubscribe(), onValueChanged.unsubscribe();
|
|
2087
2090
|
};
|
|
2088
|
-
},
|
|
2089
|
-
let
|
|
2090
|
-
$[
|
|
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 = () => {
|
|
2091
2094
|
propsSelection && !hasInvalidValue && restoreSelectionFromProps();
|
|
2092
|
-
},
|
|
2093
|
-
let
|
|
2094
|
-
$[
|
|
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) => {
|
|
2095
2098
|
if (onCopy)
|
|
2096
2099
|
onCopy(event) !== void 0 && event.preventDefault();
|
|
2097
2100
|
else if (event.nativeEvent.clipboardData) {
|
|
@@ -2120,10 +2123,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2120
2123
|
nativeEvent: event
|
|
2121
2124
|
});
|
|
2122
2125
|
}
|
|
2123
|
-
}, $[
|
|
2124
|
-
const handleCopy =
|
|
2125
|
-
let
|
|
2126
|
-
$[
|
|
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) => {
|
|
2127
2130
|
if (onCut)
|
|
2128
2131
|
onCut(event_0) !== void 0 && event_0.preventDefault();
|
|
2129
2132
|
else if (event_0.nativeEvent.clipboardData) {
|
|
@@ -2148,10 +2151,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2148
2151
|
nativeEvent: event_0
|
|
2149
2152
|
});
|
|
2150
2153
|
}
|
|
2151
|
-
}, $[
|
|
2152
|
-
const handleCut =
|
|
2153
|
-
let
|
|
2154
|
-
$[
|
|
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) => {
|
|
2155
2158
|
const value = fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditor)), path = (slateEditor.selection ? slateRangeToSelection({
|
|
2156
2159
|
schema: editorActor.getSnapshot().context.schema,
|
|
2157
2160
|
editor: slateEditor,
|
|
@@ -2235,18 +2238,18 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2235
2238
|
});
|
|
2236
2239
|
}
|
|
2237
2240
|
debug$d("No result from custom paste handler, pasting normally");
|
|
2238
|
-
}, $[
|
|
2239
|
-
const handlePaste =
|
|
2240
|
-
let
|
|
2241
|
-
$[
|
|
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) => {
|
|
2242
2245
|
onFocus && onFocus(event_2), event_2.isDefaultPrevented() || (relayActor.send({
|
|
2243
2246
|
type: "focused",
|
|
2244
2247
|
event: event_2
|
|
2245
2248
|
}), !slateEditor.selection && isEqualToEmptyEditor(slateEditor.children, editorActor.getSnapshot().context.schema) && (slate.Transforms.select(slateEditor, slate.Editor.start(slateEditor, [])), slateEditor.onChange()));
|
|
2246
|
-
}, $[
|
|
2247
|
-
const handleOnFocus =
|
|
2248
|
-
let
|
|
2249
|
-
$[
|
|
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) => {
|
|
2250
2253
|
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
2251
2254
|
return;
|
|
2252
2255
|
const position_3 = getEventPosition({
|
|
@@ -2263,23 +2266,23 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2263
2266
|
editor: slateEditor,
|
|
2264
2267
|
nativeEvent: event_3
|
|
2265
2268
|
});
|
|
2266
|
-
}, $[
|
|
2267
|
-
const handleClick =
|
|
2268
|
-
let
|
|
2269
|
-
$[
|
|
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) => {
|
|
2270
2273
|
onBlur && onBlur(event_4), event_4.isPropagationStopped() || relayActor.send({
|
|
2271
2274
|
type: "blurred",
|
|
2272
2275
|
event: event_4
|
|
2273
2276
|
});
|
|
2274
|
-
}, $[
|
|
2275
|
-
const handleOnBlur =
|
|
2276
|
-
let
|
|
2277
|
-
$[
|
|
2277
|
+
}, $[100] = onBlur, $[101] = relayActor, $[102] = t24) : t24 = $[102];
|
|
2278
|
+
const handleOnBlur = t24;
|
|
2279
|
+
let t25;
|
|
2280
|
+
$[103] !== onBeforeInput ? (t25 = (event_5) => {
|
|
2278
2281
|
onBeforeInput && onBeforeInput(event_5);
|
|
2279
|
-
}, $[
|
|
2280
|
-
const handleOnBeforeInput =
|
|
2281
|
-
let
|
|
2282
|
-
$[
|
|
2282
|
+
}, $[103] = onBeforeInput, $[104] = t25) : t25 = $[104];
|
|
2283
|
+
const handleOnBeforeInput = t25;
|
|
2284
|
+
let t26;
|
|
2285
|
+
$[105] !== editorActor || $[106] !== props || $[107] !== slateEditor ? (t26 = (event_6) => {
|
|
2283
2286
|
props.onKeyDown && props.onKeyDown(event_6), event_6.isDefaultPrevented() || slateEditor.pteWithHotKeys(event_6), event_6.isDefaultPrevented() || editorActor.send({
|
|
2284
2287
|
type: "behavior event",
|
|
2285
2288
|
behaviorEvent: {
|
|
@@ -2296,10 +2299,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2296
2299
|
editor: slateEditor,
|
|
2297
2300
|
nativeEvent: event_6
|
|
2298
2301
|
});
|
|
2299
|
-
}, $[
|
|
2300
|
-
const handleKeyDown =
|
|
2301
|
-
let
|
|
2302
|
-
$[
|
|
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) => {
|
|
2303
2306
|
props.onKeyUp && props.onKeyUp(event_7), event_7.isDefaultPrevented() || editorActor.send({
|
|
2304
2307
|
type: "behavior event",
|
|
2305
2308
|
behaviorEvent: {
|
|
@@ -2316,26 +2319,26 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2316
2319
|
editor: slateEditor,
|
|
2317
2320
|
nativeEvent: event_7
|
|
2318
2321
|
});
|
|
2319
|
-
}, $[
|
|
2320
|
-
const handleKeyUp =
|
|
2321
|
-
let
|
|
2322
|
+
}, $[109] = editorActor, $[110] = props, $[111] = slateEditor, $[112] = t27) : t27 = $[112];
|
|
2323
|
+
const handleKeyUp = t27;
|
|
2324
|
+
let t28;
|
|
2322
2325
|
bb1: {
|
|
2323
2326
|
if (scrollSelectionIntoView === void 0) {
|
|
2324
|
-
|
|
2327
|
+
t28 = void 0;
|
|
2325
2328
|
break bb1;
|
|
2326
2329
|
}
|
|
2327
2330
|
if (scrollSelectionIntoView === null) {
|
|
2328
|
-
|
|
2331
|
+
t28 = noop__default.default;
|
|
2329
2332
|
break bb1;
|
|
2330
2333
|
}
|
|
2331
|
-
let
|
|
2332
|
-
$[
|
|
2334
|
+
let t292;
|
|
2335
|
+
$[113] !== portableTextEditor || $[114] !== scrollSelectionIntoView ? (t292 = (_editor, domRange) => {
|
|
2333
2336
|
scrollSelectionIntoView(portableTextEditor, domRange);
|
|
2334
|
-
}, $[
|
|
2337
|
+
}, $[113] = portableTextEditor, $[114] = scrollSelectionIntoView, $[115] = t292) : t292 = $[115], t28 = t292;
|
|
2335
2338
|
}
|
|
2336
|
-
const scrollSelectionIntoViewToSlate =
|
|
2337
|
-
let
|
|
2338
|
-
$[
|
|
2339
|
+
const scrollSelectionIntoViewToSlate = t28;
|
|
2340
|
+
let t29, t30;
|
|
2341
|
+
$[116] !== editorActor || $[117] !== slateEditor ? (t29 = () => {
|
|
2339
2342
|
const window2 = slateReact.ReactEditor.getWindow(slateEditor), onDragEnd_0 = () => {
|
|
2340
2343
|
editorActor.send({
|
|
2341
2344
|
type: "dragend"
|
|
@@ -2348,9 +2351,9 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2348
2351
|
return window2.document.addEventListener("dragend", onDragEnd_0), window2.document.addEventListener("drop", onDrop_0), () => {
|
|
2349
2352
|
window2.document.removeEventListener("dragend", onDragEnd_0), window2.document.removeEventListener("drop", onDrop_0);
|
|
2350
2353
|
};
|
|
2351
|
-
},
|
|
2352
|
-
let
|
|
2353
|
-
$[
|
|
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) => {
|
|
2354
2357
|
if (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped())
|
|
2355
2358
|
return;
|
|
2356
2359
|
const position_4 = getEventPosition({
|
|
@@ -2378,10 +2381,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2378
2381
|
},
|
|
2379
2382
|
editor: slateEditor
|
|
2380
2383
|
}), !0;
|
|
2381
|
-
}, $[
|
|
2382
|
-
const handleDragStart =
|
|
2383
|
-
let
|
|
2384
|
-
$[
|
|
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) => {
|
|
2385
2388
|
if (onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped() || !getEventPosition({
|
|
2386
2389
|
editorActor,
|
|
2387
2390
|
slateEditor,
|
|
@@ -2397,10 +2400,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2397
2400
|
},
|
|
2398
2401
|
editor: slateEditor
|
|
2399
2402
|
}), !0;
|
|
2400
|
-
}, $[
|
|
2401
|
-
const handleDrag =
|
|
2402
|
-
let
|
|
2403
|
-
$[
|
|
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) => {
|
|
2404
2407
|
if (onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped()))
|
|
2405
2408
|
return editorActor.send({
|
|
2406
2409
|
type: "behavior event",
|
|
@@ -2412,10 +2415,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2412
2415
|
},
|
|
2413
2416
|
editor: slateEditor
|
|
2414
2417
|
}), !0;
|
|
2415
|
-
}, $[
|
|
2416
|
-
const handleDragEnd =
|
|
2417
|
-
let
|
|
2418
|
-
$[
|
|
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) => {
|
|
2419
2422
|
if (onDragEnter?.(event_11), event_11.isDefaultPrevented() || event_11.isPropagationStopped())
|
|
2420
2423
|
return;
|
|
2421
2424
|
const position_6 = getEventPosition({
|
|
@@ -2435,10 +2438,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2435
2438
|
},
|
|
2436
2439
|
editor: slateEditor
|
|
2437
2440
|
}), !0;
|
|
2438
|
-
}, $[
|
|
2439
|
-
const handleDragEnter =
|
|
2440
|
-
let
|
|
2441
|
-
$[
|
|
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) => {
|
|
2442
2445
|
if (onDragOver?.(event_12), event_12.isDefaultPrevented() || event_12.isPropagationStopped())
|
|
2443
2446
|
return;
|
|
2444
2447
|
const position_7 = getEventPosition({
|
|
@@ -2460,10 +2463,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2460
2463
|
editor: slateEditor,
|
|
2461
2464
|
nativeEvent: event_12
|
|
2462
2465
|
}), !0;
|
|
2463
|
-
}, $[
|
|
2464
|
-
const handleDragOver =
|
|
2465
|
-
let
|
|
2466
|
-
$[
|
|
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) => {
|
|
2467
2470
|
if (onDrop?.(event_13), event_13.isDefaultPrevented() || event_13.isPropagationStopped())
|
|
2468
2471
|
return;
|
|
2469
2472
|
const position_8 = getEventPosition({
|
|
@@ -2488,10 +2491,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2488
2491
|
editor: slateEditor,
|
|
2489
2492
|
nativeEvent: event_13
|
|
2490
2493
|
}), !0;
|
|
2491
|
-
}, $[
|
|
2492
|
-
const handleDrop =
|
|
2493
|
-
let
|
|
2494
|
-
$[
|
|
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) => {
|
|
2495
2498
|
if (onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped() || !getEventPosition({
|
|
2496
2499
|
editorActor,
|
|
2497
2500
|
slateEditor,
|
|
@@ -2507,10 +2510,10 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2507
2510
|
},
|
|
2508
2511
|
editor: slateEditor
|
|
2509
2512
|
}), !0;
|
|
2510
|
-
}, $[
|
|
2511
|
-
const handleDragLeave =
|
|
2512
|
-
let
|
|
2513
|
-
$[
|
|
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) => {
|
|
2514
2517
|
if (typeof forwardedRef == "function" ? forwardedRef(editorElement) : forwardedRef && (forwardedRef.current = editorElement), editorElement) {
|
|
2515
2518
|
const mutationObserver = new MutationObserver(() => {
|
|
2516
2519
|
validateSelectionActor.send({
|
|
@@ -2528,12 +2531,12 @@ const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE
|
|
|
2528
2531
|
mutationObserver.disconnect();
|
|
2529
2532
|
};
|
|
2530
2533
|
}
|
|
2531
|
-
}, $[
|
|
2532
|
-
const callbackRef =
|
|
2534
|
+
}, $[148] = forwardedRef, $[149] = validateSelectionActor, $[150] = t38) : t38 = $[150];
|
|
2535
|
+
const callbackRef = t38;
|
|
2533
2536
|
if (!portableTextEditor)
|
|
2534
2537
|
return null;
|
|
2535
|
-
let
|
|
2536
|
-
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;
|
|
2537
2540
|
});
|
|
2538
2541
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
2539
2542
|
function _temp(s) {
|
|
@@ -3901,27 +3904,26 @@ function createWithUndoRedo(options) {
|
|
|
3901
3904
|
apply2(op);
|
|
3902
3905
|
return;
|
|
3903
3906
|
}
|
|
3904
|
-
const
|
|
3905
|
-
|
|
3906
|
-
|
|
3907
|
-
|
|
3908
|
-
undos
|
|
3909
|
-
} = history, step = undos[undos.length - 1], lastOp = step && step.operations && step.operations[step.operations.length - 1], overwrite = shouldOverwrite(op, lastOp), save = isSaving(editor), currentUndoStepId = getCurrentUndoStepId(editor);
|
|
3910
|
-
let merge = currentUndoStepId === previousUndoStepId || isNormalizingNode(editor);
|
|
3911
|
-
if (save) {
|
|
3912
|
-
if (step ? operations.length === 0 && (merge = currentUndoStepId === void 0 && previousUndoStepId === void 0 ? shouldMerge(op, lastOp) || overwrite : merge) : merge = !1, step && merge)
|
|
3913
|
-
step.operations.push(op);
|
|
3914
|
-
else {
|
|
3915
|
-
const newStep = {
|
|
3916
|
-
operations: [...editor.selection === null ? [] : [createSelectOperation(editor)], op],
|
|
3917
|
-
timestamp: /* @__PURE__ */ new Date()
|
|
3918
|
-
};
|
|
3919
|
-
undos.push(newStep), debug$b("Created new undo step", step);
|
|
3920
|
-
}
|
|
3921
|
-
for (; undos.length > UNDO_STEP_LIMIT; )
|
|
3922
|
-
undos.shift();
|
|
3923
|
-
shouldClear(op) && (history.redos = []);
|
|
3907
|
+
const savingUndoSteps = isSaving(editor), currentUndoStepId = getCurrentUndoStepId(editor);
|
|
3908
|
+
if (!savingUndoSteps) {
|
|
3909
|
+
previousUndoStepId = currentUndoStepId, apply2(op);
|
|
3910
|
+
return;
|
|
3924
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;
|
|
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();
|
|
3925
3927
|
previousUndoStepId = currentUndoStepId, apply2(op);
|
|
3926
3928
|
}, editor;
|
|
3927
3929
|
};
|
|
@@ -4080,7 +4082,7 @@ function adjustBlockPath(operation, level, blockIndex) {
|
|
|
4080
4082
|
}
|
|
4081
4083
|
return transformedOperation;
|
|
4082
4084
|
}
|
|
4083
|
-
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));
|
|
4084
4086
|
function withoutSaving(editor, fn) {
|
|
4085
4087
|
const prev = isSaving(editor);
|
|
4086
4088
|
SAVING.set(editor, !1), fn(), SAVING.set(editor, prev);
|
|
@@ -11691,89 +11693,67 @@ async function updateValue({
|
|
|
11691
11693
|
}) {
|
|
11692
11694
|
let doneSyncing = !1, isChanged = !1, isValid = !0;
|
|
11693
11695
|
const hadSelection = !!slateEditor.selection;
|
|
11694
|
-
if ((!value || value.length === 0) && (debug$2("Value is empty"),
|
|
11695
|
-
|
|
11696
|
-
|
|
11697
|
-
|
|
11698
|
-
|
|
11699
|
-
|
|
11700
|
-
|
|
11701
|
-
|
|
11702
|
-
|
|
11703
|
-
slate.Transforms.removeNodes(slateEditor, {
|
|
11704
|
-
at: [childrenLength - 1 - index]
|
|
11705
|
-
});
|
|
11706
|
-
}), slate.Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
|
|
11707
|
-
decorators: []
|
|
11708
|
-
}), {
|
|
11709
|
-
at: [0]
|
|
11710
|
-
}), hadSelection && slate.Transforms.select(slateEditor, [0, 0]);
|
|
11711
|
-
});
|
|
11712
|
-
});
|
|
11713
|
-
});
|
|
11714
|
-
}), isChanged = !0), value && value.length > 0 && (streamBlocks ? await new Promise((resolve) => {
|
|
11715
|
-
slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
11716
|
-
withRemoteChanges(slateEditor, () => {
|
|
11717
|
-
withoutPatching(slateEditor, () => {
|
|
11718
|
-
if (doneSyncing) {
|
|
11719
|
-
resolve();
|
|
11720
|
-
return;
|
|
11721
|
-
}
|
|
11722
|
-
isChanged = removeExtraBlocks({
|
|
11723
|
-
slateEditor,
|
|
11724
|
-
value
|
|
11725
|
-
}), (async () => {
|
|
11726
|
-
for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
|
|
11727
|
-
value
|
|
11728
|
-
})) {
|
|
11729
|
-
const {
|
|
11730
|
-
blockChanged,
|
|
11731
|
-
blockValid
|
|
11732
|
-
} = syncBlock({
|
|
11733
|
-
context,
|
|
11734
|
-
sendBack,
|
|
11735
|
-
block: currentBlock,
|
|
11736
|
-
index: currentBlockIndex,
|
|
11737
|
-
slateEditor,
|
|
11738
|
-
value
|
|
11739
|
-
});
|
|
11740
|
-
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
|
|
11741
|
-
break;
|
|
11742
|
-
}
|
|
11743
|
-
resolve();
|
|
11744
|
-
})();
|
|
11745
|
-
});
|
|
11746
|
-
});
|
|
11747
|
-
});
|
|
11748
|
-
}) : slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
11749
|
-
withRemoteChanges(slateEditor, () => {
|
|
11750
|
-
withoutPatching(slateEditor, () => {
|
|
11751
|
-
if (doneSyncing)
|
|
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();
|
|
11752
11705
|
return;
|
|
11706
|
+
}
|
|
11753
11707
|
isChanged = removeExtraBlocks({
|
|
11754
11708
|
slateEditor,
|
|
11755
11709
|
value
|
|
11756
|
-
})
|
|
11757
|
-
|
|
11758
|
-
for (const currentBlock of value) {
|
|
11759
|
-
const {
|
|
11760
|
-
blockChanged,
|
|
11761
|
-
blockValid
|
|
11762
|
-
} = syncBlock({
|
|
11763
|
-
context,
|
|
11764
|
-
sendBack,
|
|
11765
|
-
block: currentBlock,
|
|
11766
|
-
index,
|
|
11767
|
-
slateEditor,
|
|
11710
|
+
}), (async () => {
|
|
11711
|
+
for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
|
|
11768
11712
|
value
|
|
11769
|
-
})
|
|
11770
|
-
|
|
11771
|
-
|
|
11772
|
-
|
|
11773
|
-
|
|
11713
|
+
})) {
|
|
11714
|
+
const {
|
|
11715
|
+
blockChanged,
|
|
11716
|
+
blockValid
|
|
11717
|
+
} = syncBlock({
|
|
11718
|
+
context,
|
|
11719
|
+
sendBack,
|
|
11720
|
+
block: currentBlock,
|
|
11721
|
+
index: currentBlockIndex,
|
|
11722
|
+
slateEditor,
|
|
11723
|
+
value
|
|
11724
|
+
});
|
|
11725
|
+
if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
|
|
11726
|
+
break;
|
|
11727
|
+
}
|
|
11728
|
+
resolve();
|
|
11729
|
+
})();
|
|
11774
11730
|
});
|
|
11775
|
-
|
|
11776
|
-
|
|
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
|
+
}
|
|
11756
|
+
if (!isValid) {
|
|
11777
11757
|
debug$2("Invalid value, returning"), doneSyncing = !0, sendBack({
|
|
11778
11758
|
type: "done syncing",
|
|
11779
11759
|
value
|
|
@@ -11815,21 +11795,6 @@ async function updateValue({
|
|
|
11815
11795
|
value
|
|
11816
11796
|
});
|
|
11817
11797
|
}
|
|
11818
|
-
function removeExtraBlocks({
|
|
11819
|
-
slateEditor,
|
|
11820
|
-
value
|
|
11821
|
-
}) {
|
|
11822
|
-
let isChanged = !1;
|
|
11823
|
-
const childrenLength = slateEditor.children.length;
|
|
11824
|
-
if (value.length < childrenLength) {
|
|
11825
|
-
for (let i = childrenLength - 1; i > value.length - 1; i--)
|
|
11826
|
-
slate.Transforms.removeNodes(slateEditor, {
|
|
11827
|
-
at: [i]
|
|
11828
|
-
});
|
|
11829
|
-
isChanged = !0;
|
|
11830
|
-
}
|
|
11831
|
-
return isChanged;
|
|
11832
|
-
}
|
|
11833
11798
|
async function* getStreamedBlocks({
|
|
11834
11799
|
value
|
|
11835
11800
|
}) {
|
|
@@ -11837,87 +11802,182 @@ async function* getStreamedBlocks({
|
|
|
11837
11802
|
for await (const block of value)
|
|
11838
11803
|
index % 10 === 0 && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
|
|
11839
11804
|
}
|
|
11840
|
-
function
|
|
11841
|
-
|
|
11842
|
-
|
|
11843
|
-
|
|
11844
|
-
|
|
11805
|
+
function clearEditor({
|
|
11806
|
+
slateEditor,
|
|
11807
|
+
doneSyncing,
|
|
11808
|
+
hadSelection
|
|
11809
|
+
}) {
|
|
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
|
+
});
|
|
11828
|
+
});
|
|
11829
|
+
});
|
|
11830
|
+
});
|
|
11831
|
+
}
|
|
11832
|
+
function removeExtraBlocks({
|
|
11845
11833
|
slateEditor,
|
|
11846
11834
|
value
|
|
11847
11835
|
}) {
|
|
11848
|
-
let
|
|
11849
|
-
const currentBlock = block, currentBlockIndex = index, oldBlock = slateEditor.children[currentBlockIndex], hasChanges = oldBlock && !isEqual__default.default(currentBlock, oldBlock);
|
|
11836
|
+
let isChanged = !1;
|
|
11850
11837
|
return slate.Editor.withoutNormalizing(slateEditor, () => {
|
|
11851
11838
|
withRemoteChanges(slateEditor, () => {
|
|
11852
11839
|
withoutPatching(slateEditor, () => {
|
|
11853
|
-
|
|
11854
|
-
|
|
11855
|
-
|
|
11856
|
-
|
|
11857
|
-
|
|
11858
|
-
patch
|
|
11859
|
-
});
|
|
11860
|
-
})), validation.valid || validation.resolution?.autoResolve) {
|
|
11861
|
-
const slateBlock = toSlateBlock(currentBlock, {
|
|
11862
|
-
schemaTypes: context.schema
|
|
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]
|
|
11863
11845
|
});
|
|
11864
|
-
|
|
11865
|
-
} else
|
|
11866
|
-
sendBack({
|
|
11867
|
-
type: "invalid value",
|
|
11868
|
-
resolution: validation.resolution,
|
|
11869
|
-
value
|
|
11870
|
-
}), blockValid = !1;
|
|
11846
|
+
isChanged = !0;
|
|
11871
11847
|
}
|
|
11872
|
-
|
|
11873
|
-
|
|
11874
|
-
|
|
11875
|
-
|
|
11876
|
-
|
|
11877
|
-
|
|
11848
|
+
});
|
|
11849
|
+
});
|
|
11850
|
+
}), isChanged;
|
|
11851
|
+
}
|
|
11852
|
+
function syncBlock({
|
|
11853
|
+
context,
|
|
11854
|
+
sendBack,
|
|
11855
|
+
block,
|
|
11856
|
+
index,
|
|
11857
|
+
slateEditor,
|
|
11858
|
+
value
|
|
11859
|
+
}) {
|
|
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, () => {
|
|
11878
11870
|
slate.Transforms.insertNodes(slateEditor, slateBlock, {
|
|
11879
|
-
at: [
|
|
11871
|
+
at: [index]
|
|
11880
11872
|
});
|
|
11881
|
-
}
|
|
11882
|
-
|
|
11883
|
-
|
|
11884
|
-
|
|
11885
|
-
|
|
11886
|
-
|
|
11887
|
-
|
|
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, () => {
|
|
11901
|
+
withRemoteChanges(slateEditor, () => {
|
|
11902
|
+
withoutPatching(slateEditor, () => {
|
|
11903
|
+
updateBlock({
|
|
11904
|
+
context,
|
|
11905
|
+
slateEditor,
|
|
11906
|
+
oldBlock,
|
|
11907
|
+
block,
|
|
11908
|
+
index
|
|
11909
|
+
});
|
|
11888
11910
|
});
|
|
11889
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
|
+
});
|
|
11921
|
+
});
|
|
11922
|
+
});
|
|
11923
|
+
})), {
|
|
11924
|
+
blockChanged: !0,
|
|
11925
|
+
blockValid: !0
|
|
11926
|
+
}) : (sendBack({
|
|
11927
|
+
type: "invalid value",
|
|
11928
|
+
resolution: validation.resolution,
|
|
11929
|
+
value
|
|
11890
11930
|
}), {
|
|
11891
|
-
blockChanged,
|
|
11892
|
-
blockValid
|
|
11893
|
-
};
|
|
11931
|
+
blockChanged: !1,
|
|
11932
|
+
blockValid: !1
|
|
11933
|
+
});
|
|
11894
11934
|
}
|
|
11895
|
-
function
|
|
11896
|
-
|
|
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;
|
|
11897
11944
|
selectionFocusOnBlock && slate.Transforms.deselect(slateEditor), slate.Transforms.removeNodes(slateEditor, {
|
|
11898
|
-
at: [
|
|
11899
|
-
}), slate.Transforms.insertNodes(slateEditor,
|
|
11900
|
-
at: [
|
|
11945
|
+
at: [index]
|
|
11946
|
+
}), slate.Transforms.insertNodes(slateEditor, slateBlock, {
|
|
11947
|
+
at: [index]
|
|
11901
11948
|
}), slateEditor.onChange(), selectionFocusOnBlock && slate.Transforms.select(slateEditor, currentSelection);
|
|
11902
11949
|
}
|
|
11903
|
-
function
|
|
11904
|
-
|
|
11905
|
-
|
|
11906
|
-
|
|
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)) {
|
|
11907
11963
|
const oldBlockChildrenLength = oldBlock.children.length;
|
|
11908
|
-
|
|
11909
|
-
const childIndex = oldBlockChildrenLength - 1 -
|
|
11964
|
+
slateBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - slateBlock.children.length)).forEach((_, index2) => {
|
|
11965
|
+
const childIndex = oldBlockChildrenLength - 1 - index2;
|
|
11910
11966
|
childIndex > 0 && (debug$2("Removing child"), slate.Transforms.removeNodes(slateEditor, {
|
|
11911
|
-
at: [
|
|
11967
|
+
at: [index2, childIndex]
|
|
11912
11968
|
}));
|
|
11913
|
-
}),
|
|
11914
|
-
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];
|
|
11915
11971
|
if (isChildChanged)
|
|
11916
11972
|
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
11917
11973
|
debug$2("Updating changed child", currentBlockChild, oldBlockChild), slate.Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
11918
11974
|
at: path
|
|
11919
11975
|
});
|
|
11920
|
-
const isSpanNode2 =
|
|
11976
|
+
const isSpanNode2 = schema.isSpan({
|
|
11977
|
+
schema: context.schema
|
|
11978
|
+
}, currentBlockChild) && schema.isSpan({
|
|
11979
|
+
schema: context.schema
|
|
11980
|
+
}, oldBlockChild);
|
|
11921
11981
|
isSpanNode2 && isTextChanged ? (oldBlockChild.text.length > 0 && slate.deleteText(slateEditor, {
|
|
11922
11982
|
at: {
|
|
11923
11983
|
focus: {
|
|
@@ -11938,11 +11998,11 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
|
|
|
11938
11998
|
voids: !0
|
|
11939
11999
|
}));
|
|
11940
12000
|
} else oldBlockChild ? (debug$2("Replacing child", currentBlockChild), slate.Transforms.removeNodes(slateEditor, {
|
|
11941
|
-
at: [
|
|
12001
|
+
at: [index, currentBlockChildIndex]
|
|
11942
12002
|
}), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
11943
|
-
at: [
|
|
12003
|
+
at: [index, currentBlockChildIndex]
|
|
11944
12004
|
}), slateEditor.onChange()) : oldBlockChild || (debug$2("Inserting new child", currentBlockChild), slate.Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
11945
|
-
at: [
|
|
12005
|
+
at: [index, currentBlockChildIndex]
|
|
11946
12006
|
}), slateEditor.onChange());
|
|
11947
12007
|
});
|
|
11948
12008
|
}
|