@portabletext/editor 2.14.2 → 2.14.4

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