@portabletext/editor 2.14.3 → 2.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -13,7 +13,7 @@ import { getBlockStartPoint, getBlockKeyFromSelectionPoint, getChildKeyFromSelec
13
13
  import isEqual from "lodash/isEqual.js";
14
14
  import { isTextBlock, isSpan, compileSchema } from "@portabletext/schema";
15
15
  import { defineSchema } from "@portabletext/schema";
16
- import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getActiveDecorators, getTrimmedSelection, isActiveAnnotation, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, getMarkState, getActiveAnnotationsMarks, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionEndPoint as getSelectionEndPoint$1, isActiveDecorator, getActiveAnnotations, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-active-style.js";
16
+ import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getActiveDecorators, getTrimmedSelection, isActiveAnnotation, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, getMarkState, getActiveAnnotationsMarks, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionEndPoint as getSelectionEndPoint$1, isActiveDecorator, getActiveAnnotations, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-at-the-start-of-block.js";
17
17
  import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, isSelectionExpanded, getFocusBlock as getFocusBlock$1, getSelectedValue, getSelectionStartPoint as getSelectionStartPoint$1, getFocusChild as getFocusChild$1 } from "./_chunks-es/selector.get-selection-text.js";
18
18
  import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
19
19
  import uniq from "lodash/uniq.js";
@@ -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);
@@ -5959,7 +5961,24 @@ function setNodePatch(schema, children, operation) {
5959
5961
  }, block)) {
5960
5962
  const child = block.children[operation.path[1]];
5961
5963
  if (child) {
5962
- const blockKey = block._key, childKey = child._key, patches = [], keys = Object.keys(operation.newProperties);
5964
+ const blockKey = block._key, childKey = child._key, patches = [];
5965
+ if (Element$1.isElement(child)) {
5966
+ const _key = operation.newProperties._key;
5967
+ _key !== void 0 && patches.push(set(_key, [{
5968
+ _key: blockKey
5969
+ }, "children", block.children.indexOf(child), "_key"]));
5970
+ const properties = "value" in operation.newProperties && typeof operation.newProperties.value == "object" ? operation.newProperties.value : {}, keys2 = Object.keys(properties);
5971
+ for (const key of keys2) {
5972
+ const value = properties[key];
5973
+ patches.push(set(value, [{
5974
+ _key: blockKey
5975
+ }, "children", {
5976
+ _key: childKey
5977
+ }, key]));
5978
+ }
5979
+ return patches;
5980
+ }
5981
+ const keys = Object.keys(operation.newProperties);
5963
5982
  return keys.forEach((keyName) => {
5964
5983
  if (keys.length === 1 && keyName === "_key") {
5965
5984
  const val = get(operation.newProperties, keyName);
@@ -6726,6 +6745,10 @@ function createEditorDom(sendBack, slateEditor) {
6726
6745
  return {
6727
6746
  getBlockNodes: (snapshot) => getBlockNodes(slateEditor, snapshot),
6728
6747
  getChildNodes: (snapshot) => getChildNodes(slateEditor, snapshot),
6748
+ getEditorElement: () => getEditorElement(slateEditor),
6749
+ getSelectionRect: (snapshot) => getSelectionRect(snapshot),
6750
+ getStartBlockElement: (snapshot) => getStartBlockElement(slateEditor, snapshot),
6751
+ getEndBlockElement: (snapshot) => getEndBlockElement(slateEditor, snapshot),
6729
6752
  setDragGhost: ({
6730
6753
  event,
6731
6754
  ghost
@@ -6768,6 +6791,67 @@ function getChildNodes(slateEditor, snapshot) {
6768
6791
  return [];
6769
6792
  }
6770
6793
  }
6794
+ function getEditorElement(slateEditor) {
6795
+ try {
6796
+ return DOMEditor.toDOMNode(slateEditor, slateEditor);
6797
+ } catch {
6798
+ return;
6799
+ }
6800
+ }
6801
+ function getSelectionRect(snapshot) {
6802
+ if (!snapshot.context.selection)
6803
+ return null;
6804
+ try {
6805
+ const selection = window.getSelection();
6806
+ return selection ? selection.getRangeAt(0).getBoundingClientRect() : null;
6807
+ } catch {
6808
+ return null;
6809
+ }
6810
+ }
6811
+ function getStartBlockElement(slateEditor, snapshot) {
6812
+ const startBlock = getSelectionStartBlock$1(snapshot);
6813
+ if (!startBlock)
6814
+ return null;
6815
+ const startBlockNode = getBlockNodes(slateEditor, {
6816
+ ...snapshot,
6817
+ context: {
6818
+ ...snapshot.context,
6819
+ selection: {
6820
+ anchor: {
6821
+ path: startBlock.path,
6822
+ offset: 0
6823
+ },
6824
+ focus: {
6825
+ path: startBlock.path,
6826
+ offset: 0
6827
+ }
6828
+ }
6829
+ }
6830
+ })?.at(0);
6831
+ return startBlockNode && startBlockNode instanceof Element ? startBlockNode : null;
6832
+ }
6833
+ function getEndBlockElement(slateEditor, snapshot) {
6834
+ const endBlock = getSelectionEndBlock$1(snapshot);
6835
+ if (!endBlock)
6836
+ return null;
6837
+ const endBlockNode = getBlockNodes(slateEditor, {
6838
+ ...snapshot,
6839
+ context: {
6840
+ ...snapshot.context,
6841
+ selection: {
6842
+ anchor: {
6843
+ path: endBlock.path,
6844
+ offset: 0
6845
+ },
6846
+ focus: {
6847
+ path: endBlock.path,
6848
+ offset: 0
6849
+ }
6850
+ }
6851
+ }
6852
+ })?.at(0);
6853
+ return endBlockNode && endBlockNode instanceof Element ? endBlockNode : null;
6854
+ }
6771
6855
  function setDragGhost({
6772
6856
  sendBack,
6773
6857
  event,
@@ -11720,89 +11804,67 @@ async function updateValue({
11720
11804
  }) {
11721
11805
  let doneSyncing = !1, isChanged = !1, isValid = !0;
11722
11806
  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)
11807
+ if ((!value || value.length === 0) && (debug$2("Value is empty"), clearEditor({
11808
+ slateEditor,
11809
+ doneSyncing,
11810
+ hadSelection
11811
+ }), isChanged = !0), value && value.length > 0)
11812
+ if (streamBlocks)
11813
+ await new Promise((resolve) => {
11814
+ if (doneSyncing) {
11815
+ resolve();
11781
11816
  return;
11817
+ }
11782
11818
  isChanged = removeExtraBlocks({
11783
11819
  slateEditor,
11784
11820
  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,
11821
+ }), (async () => {
11822
+ for await (const [currentBlock, currentBlockIndex] of getStreamedBlocks({
11797
11823
  value
11798
- });
11799
- if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !blockValid)
11800
- break;
11801
- index++;
11802
- }
11824
+ })) {
11825
+ const {
11826
+ blockChanged,
11827
+ blockValid
11828
+ } = syncBlock({
11829
+ context,
11830
+ sendBack,
11831
+ block: currentBlock,
11832
+ index: currentBlockIndex,
11833
+ slateEditor,
11834
+ value
11835
+ });
11836
+ if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !isValid)
11837
+ break;
11838
+ }
11839
+ resolve();
11840
+ })();
11803
11841
  });
11804
- });
11805
- })), !isValid) {
11842
+ else {
11843
+ if (doneSyncing)
11844
+ return;
11845
+ isChanged = removeExtraBlocks({
11846
+ slateEditor,
11847
+ value
11848
+ });
11849
+ let index = 0;
11850
+ for (const block of value) {
11851
+ const {
11852
+ blockChanged,
11853
+ blockValid
11854
+ } = syncBlock({
11855
+ context,
11856
+ sendBack,
11857
+ block,
11858
+ index,
11859
+ slateEditor,
11860
+ value
11861
+ });
11862
+ if (isChanged = blockChanged || isChanged, isValid = isValid && blockValid, !blockValid)
11863
+ break;
11864
+ index++;
11865
+ }
11866
+ }
11867
+ if (!isValid) {
11806
11868
  debug$2("Invalid value, returning"), doneSyncing = !0, sendBack({
11807
11869
  type: "done syncing",
11808
11870
  value
@@ -11844,21 +11906,6 @@ async function updateValue({
11844
11906
  value
11845
11907
  });
11846
11908
  }
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
11909
  async function* getStreamedBlocks({
11863
11910
  value
11864
11911
  }) {
@@ -11866,87 +11913,182 @@ async function* getStreamedBlocks({
11866
11913
  for await (const block of value)
11867
11914
  index % 10 === 0 && await new Promise((resolve) => setTimeout(resolve, 0)), yield [block, index], index++;
11868
11915
  }
11869
- function syncBlock({
11870
- context,
11871
- sendBack,
11872
- block,
11873
- index,
11916
+ function clearEditor({
11917
+ slateEditor,
11918
+ doneSyncing,
11919
+ hadSelection
11920
+ }) {
11921
+ Editor.withoutNormalizing(slateEditor, () => {
11922
+ withoutSaving(slateEditor, () => {
11923
+ withRemoteChanges(slateEditor, () => {
11924
+ withoutPatching(slateEditor, () => {
11925
+ if (doneSyncing)
11926
+ return;
11927
+ hadSelection && Transforms.deselect(slateEditor);
11928
+ const childrenLength = slateEditor.children.length;
11929
+ slateEditor.children.forEach((_, index) => {
11930
+ Transforms.removeNodes(slateEditor, {
11931
+ at: [childrenLength - 1 - index]
11932
+ });
11933
+ }), Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
11934
+ decorators: []
11935
+ }), {
11936
+ at: [0]
11937
+ }), hadSelection && Transforms.select(slateEditor, [0, 0]);
11938
+ });
11939
+ });
11940
+ });
11941
+ });
11942
+ }
11943
+ function removeExtraBlocks({
11874
11944
  slateEditor,
11875
11945
  value
11876
11946
  }) {
11877
- let blockChanged = !1, blockValid = !0;
11878
- const currentBlock = block, currentBlockIndex = index, oldBlock = slateEditor.children[currentBlockIndex], hasChanges = oldBlock && !isEqual(currentBlock, oldBlock);
11947
+ let isChanged = !1;
11879
11948
  return Editor.withoutNormalizing(slateEditor, () => {
11880
11949
  withRemoteChanges(slateEditor, () => {
11881
11950
  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
11951
+ const childrenLength = slateEditor.children.length;
11952
+ if (value.length < childrenLength) {
11953
+ for (let i = childrenLength - 1; i > value.length - 1; i--)
11954
+ Transforms.removeNodes(slateEditor, {
11955
+ at: [i]
11892
11956
  });
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;
11957
+ isChanged = !0;
11900
11958
  }
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
- });
11959
+ });
11960
+ });
11961
+ }), isChanged;
11962
+ }
11963
+ function syncBlock({
11964
+ context,
11965
+ sendBack,
11966
+ block,
11967
+ index,
11968
+ slateEditor,
11969
+ value
11970
+ }) {
11971
+ const oldBlock = slateEditor.children.at(index);
11972
+ if (!oldBlock) {
11973
+ const validation2 = validateValue([block], context.schema, context.keyGenerator);
11974
+ if (debug$2.enabled && debug$2("Validating and inserting new block in the end of the value", block), validation2.valid || validation2.resolution?.autoResolve) {
11975
+ const slateBlock = toSlateBlock(block, {
11976
+ schemaTypes: context.schema
11977
+ });
11978
+ return Editor.withoutNormalizing(slateEditor, () => {
11979
+ withRemoteChanges(slateEditor, () => {
11980
+ withoutPatching(slateEditor, () => {
11907
11981
  Transforms.insertNodes(slateEditor, slateBlock, {
11908
- at: [currentBlockIndex]
11982
+ at: [index]
11909
11983
  });
11910
- } else
11911
- debug$2("Invalid", validation), sendBack({
11912
- type: "invalid value",
11913
- resolution: validation.resolution,
11914
- value
11915
- }), blockValid = !1;
11916
- }
11984
+ });
11985
+ });
11986
+ }), {
11987
+ blockChanged: !0,
11988
+ blockValid: !0
11989
+ };
11990
+ }
11991
+ return debug$2("Invalid", validation2), sendBack({
11992
+ type: "invalid value",
11993
+ resolution: validation2.resolution,
11994
+ value
11995
+ }), {
11996
+ blockChanged: !1,
11997
+ blockValid: !1
11998
+ };
11999
+ }
12000
+ if (isEqual(block, oldBlock))
12001
+ return {
12002
+ blockChanged: !1,
12003
+ blockValid: !0
12004
+ };
12005
+ const validationValue = [value[index]], validation = validateValue(validationValue, context.schema, context.keyGenerator);
12006
+ 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) => {
12007
+ sendBack({
12008
+ type: "patch",
12009
+ patch
12010
+ });
12011
+ })), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === block._key ? (debug$2.enabled && debug$2("Updating block", oldBlock, block), Editor.withoutNormalizing(slateEditor, () => {
12012
+ withRemoteChanges(slateEditor, () => {
12013
+ withoutPatching(slateEditor, () => {
12014
+ updateBlock({
12015
+ context,
12016
+ slateEditor,
12017
+ oldBlock,
12018
+ block,
12019
+ index
12020
+ });
11917
12021
  });
11918
12022
  });
12023
+ })) : (debug$2.enabled && debug$2("Replacing block", oldBlock, block), Editor.withoutNormalizing(slateEditor, () => {
12024
+ withRemoteChanges(slateEditor, () => {
12025
+ withoutPatching(slateEditor, () => {
12026
+ replaceBlock({
12027
+ context,
12028
+ slateEditor,
12029
+ block,
12030
+ index
12031
+ });
12032
+ });
12033
+ });
12034
+ })), {
12035
+ blockChanged: !0,
12036
+ blockValid: !0
12037
+ }) : (sendBack({
12038
+ type: "invalid value",
12039
+ resolution: validation.resolution,
12040
+ value
11919
12041
  }), {
11920
- blockChanged,
11921
- blockValid
11922
- };
12042
+ blockChanged: !1,
12043
+ blockValid: !1
12044
+ });
11923
12045
  }
11924
- function _replaceBlock(slateEditor, currentBlock, currentBlockIndex) {
11925
- const currentSelection = slateEditor.selection, selectionFocusOnBlock = currentSelection && currentSelection.focus.path[0] === currentBlockIndex;
12046
+ function replaceBlock({
12047
+ context,
12048
+ slateEditor,
12049
+ block,
12050
+ index
12051
+ }) {
12052
+ const slateBlock = toSlateBlock(block, {
12053
+ schemaTypes: context.schema
12054
+ }), currentSelection = slateEditor.selection, selectionFocusOnBlock = currentSelection && currentSelection.focus.path[0] === index;
11926
12055
  selectionFocusOnBlock && Transforms.deselect(slateEditor), Transforms.removeNodes(slateEditor, {
11927
- at: [currentBlockIndex]
11928
- }), Transforms.insertNodes(slateEditor, currentBlock, {
11929
- at: [currentBlockIndex]
12056
+ at: [index]
12057
+ }), Transforms.insertNodes(slateEditor, slateBlock, {
12058
+ at: [index]
11930
12059
  }), slateEditor.onChange(), selectionFocusOnBlock && Transforms.select(slateEditor, currentSelection);
11931
12060
  }
11932
- function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
11933
- if (Transforms.setNodes(slateEditor, currentBlock, {
11934
- at: [currentBlockIndex]
11935
- }), slateEditor.isTextBlock(currentBlock) && slateEditor.isTextBlock(oldBlock)) {
12061
+ function updateBlock({
12062
+ context,
12063
+ slateEditor,
12064
+ oldBlock,
12065
+ block,
12066
+ index
12067
+ }) {
12068
+ const slateBlock = toSlateBlock(block, {
12069
+ schemaTypes: context.schema
12070
+ });
12071
+ if (Transforms.setNodes(slateEditor, slateBlock, {
12072
+ at: [index]
12073
+ }), slateEditor.isTextBlock(slateBlock) && slateEditor.isTextBlock(oldBlock)) {
11936
12074
  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;
12075
+ slateBlock.children.length < oldBlockChildrenLength && Array.from(Array(oldBlockChildrenLength - slateBlock.children.length)).forEach((_, index2) => {
12076
+ const childIndex = oldBlockChildrenLength - 1 - index2;
11939
12077
  childIndex > 0 && (debug$2("Removing child"), Transforms.removeNodes(slateEditor, {
11940
- at: [currentBlockIndex, childIndex]
12078
+ at: [index2, childIndex]
11941
12079
  }));
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];
12080
+ }), slateBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
12081
+ const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [index, currentBlockChildIndex];
11944
12082
  if (isChildChanged)
11945
12083
  if (currentBlockChild._key === oldBlockChild?._key) {
11946
12084
  debug$2("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
11947
12085
  at: path
11948
12086
  });
11949
- const isSpanNode2 = Text.isText(currentBlockChild) && currentBlockChild._type === "span" && Text.isText(oldBlockChild) && oldBlockChild._type === "span";
12087
+ const isSpanNode2 = isSpan({
12088
+ schema: context.schema
12089
+ }, currentBlockChild) && isSpan({
12090
+ schema: context.schema
12091
+ }, oldBlockChild);
11950
12092
  isSpanNode2 && isTextChanged ? (oldBlockChild.text.length > 0 && deleteText(slateEditor, {
11951
12093
  at: {
11952
12094
  focus: {
@@ -11967,11 +12109,11 @@ function _updateBlock(slateEditor, currentBlock, oldBlock, currentBlockIndex) {
11967
12109
  voids: !0
11968
12110
  }));
11969
12111
  } else oldBlockChild ? (debug$2("Replacing child", currentBlockChild), Transforms.removeNodes(slateEditor, {
11970
- at: [currentBlockIndex, currentBlockChildIndex]
12112
+ at: [index, currentBlockChildIndex]
11971
12113
  }), Transforms.insertNodes(slateEditor, currentBlockChild, {
11972
- at: [currentBlockIndex, currentBlockChildIndex]
12114
+ at: [index, currentBlockChildIndex]
11973
12115
  }), slateEditor.onChange()) : oldBlockChild || (debug$2("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
11974
- at: [currentBlockIndex, currentBlockChildIndex]
12116
+ at: [index, currentBlockChildIndex]
11975
12117
  }), slateEditor.onChange());
11976
12118
  });
11977
12119
  }