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