@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/_chunks-cjs/{selector.is-active-style.cjs → selector.is-at-the-start-of-block.cjs} +90 -94
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -0
- package/lib/_chunks-cjs/use-editor.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +4 -0
- package/lib/_chunks-dts/behavior.types.action.d.ts +4 -0
- package/lib/_chunks-es/{selector.is-active-style.js → selector.is-at-the-start-of-block.js} +90 -94
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -0
- package/lib/_chunks-es/use-editor.js.map +1 -1
- package/lib/index.cjs +505 -363
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +426 -284
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.ts +3 -3
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.cjs +33 -33
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +2 -2
- package/lib/utils/index.d.cts +2 -2
- package/package.json +8 -8
- package/src/editor/editor-dom.ts +99 -0
- package/src/editor/plugins/createWithUndoRedo.ts +78 -61
- package/src/editor/sync-machine.ts +410 -311
- package/src/internal-utils/operation-to-patches.ts +39 -0
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-active-style.js.map +0 -1
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-
|
|
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(
|
|
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 =
|
|
2042
|
-
setup: "setting up"
|
|
2043
|
-
});
|
|
2041
|
+
const t3 = t2.context.schema;
|
|
2044
2042
|
let t4;
|
|
2045
|
-
$[34] !==
|
|
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:
|
|
2052
|
+
schema: t3,
|
|
2050
2053
|
slateEditor,
|
|
2051
|
-
skipSetup:
|
|
2054
|
+
skipSetup: t5
|
|
2052
2055
|
}
|
|
2053
|
-
}, $[
|
|
2054
|
-
const rangeDecorationsActor = useActorRef(rangeDecorationsMachine,
|
|
2055
|
-
let
|
|
2056
|
-
$[
|
|
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
|
-
},
|
|
2062
|
-
let
|
|
2063
|
-
$[
|
|
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
|
-
},
|
|
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
|
-
$[
|
|
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
|
-
}, $[
|
|
2102
|
-
const restoreSelectionFromProps =
|
|
2103
|
-
let
|
|
2104
|
-
$[
|
|
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
|
-
},
|
|
2118
|
-
let
|
|
2119
|
-
$[
|
|
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
|
-
},
|
|
2122
|
-
let
|
|
2123
|
-
$[
|
|
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
|
-
}, $[
|
|
2153
|
-
const handleCopy =
|
|
2154
|
-
let
|
|
2155
|
-
$[
|
|
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
|
-
}, $[
|
|
2181
|
-
const handleCut =
|
|
2182
|
-
let
|
|
2183
|
-
$[
|
|
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
|
-
}, $[
|
|
2268
|
-
const handlePaste =
|
|
2269
|
-
let
|
|
2270
|
-
$[
|
|
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
|
-
}, $[
|
|
2276
|
-
const handleOnFocus =
|
|
2277
|
-
let
|
|
2278
|
-
$[
|
|
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
|
-
}, $[
|
|
2296
|
-
const handleClick =
|
|
2297
|
-
let
|
|
2298
|
-
$[
|
|
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
|
-
}, $[
|
|
2304
|
-
const handleOnBlur =
|
|
2305
|
-
let
|
|
2306
|
-
$[
|
|
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
|
-
}, $[
|
|
2309
|
-
const handleOnBeforeInput =
|
|
2310
|
-
let
|
|
2311
|
-
$[
|
|
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
|
-
}, $[
|
|
2329
|
-
const handleKeyDown =
|
|
2330
|
-
let
|
|
2331
|
-
$[
|
|
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
|
-
}, $[
|
|
2349
|
-
const handleKeyUp =
|
|
2350
|
-
let
|
|
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
|
-
|
|
2356
|
+
t28 = void 0;
|
|
2354
2357
|
break bb1;
|
|
2355
2358
|
}
|
|
2356
2359
|
if (scrollSelectionIntoView === null) {
|
|
2357
|
-
|
|
2360
|
+
t28 = noop;
|
|
2358
2361
|
break bb1;
|
|
2359
2362
|
}
|
|
2360
|
-
let
|
|
2361
|
-
$[
|
|
2363
|
+
let t292;
|
|
2364
|
+
$[113] !== portableTextEditor || $[114] !== scrollSelectionIntoView ? (t292 = (_editor, domRange) => {
|
|
2362
2365
|
scrollSelectionIntoView(portableTextEditor, domRange);
|
|
2363
|
-
}, $[
|
|
2366
|
+
}, $[113] = portableTextEditor, $[114] = scrollSelectionIntoView, $[115] = t292) : t292 = $[115], t28 = t292;
|
|
2364
2367
|
}
|
|
2365
|
-
const scrollSelectionIntoViewToSlate =
|
|
2366
|
-
let
|
|
2367
|
-
$[
|
|
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
|
-
},
|
|
2381
|
-
let
|
|
2382
|
-
$[
|
|
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
|
-
}, $[
|
|
2411
|
-
const handleDragStart =
|
|
2412
|
-
let
|
|
2413
|
-
$[
|
|
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
|
-
}, $[
|
|
2430
|
-
const handleDrag =
|
|
2431
|
-
let
|
|
2432
|
-
$[
|
|
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
|
-
}, $[
|
|
2445
|
-
const handleDragEnd =
|
|
2446
|
-
let
|
|
2447
|
-
$[
|
|
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
|
-
}, $[
|
|
2468
|
-
const handleDragEnter =
|
|
2469
|
-
let
|
|
2470
|
-
$[
|
|
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
|
-
}, $[
|
|
2493
|
-
const handleDragOver =
|
|
2494
|
-
let
|
|
2495
|
-
$[
|
|
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
|
-
}, $[
|
|
2521
|
-
const handleDrop =
|
|
2522
|
-
let
|
|
2523
|
-
$[
|
|
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
|
-
}, $[
|
|
2540
|
-
const handleDragLeave =
|
|
2541
|
-
let
|
|
2542
|
-
$[
|
|
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
|
-
}, $[
|
|
2561
|
-
const callbackRef =
|
|
2563
|
+
}, $[148] = forwardedRef, $[149] = validateSelectionActor, $[150] = t38) : t38 = $[150];
|
|
2564
|
+
const callbackRef = t38;
|
|
2562
2565
|
if (!portableTextEditor)
|
|
2563
2566
|
return null;
|
|
2564
|
-
let
|
|
2565
|
-
return $[
|
|
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
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
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))
|
|
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 = []
|
|
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"),
|
|
11724
|
-
|
|
11725
|
-
|
|
11726
|
-
|
|
11727
|
-
|
|
11728
|
-
|
|
11729
|
-
|
|
11730
|
-
|
|
11731
|
-
|
|
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
|
-
|
|
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
|
-
|
|
11800
|
-
|
|
11801
|
-
|
|
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
|
-
|
|
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
|
|
11870
|
-
|
|
11871
|
-
|
|
11872
|
-
|
|
11873
|
-
|
|
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
|
|
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
|
-
|
|
11883
|
-
|
|
11884
|
-
|
|
11885
|
-
|
|
11886
|
-
|
|
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
|
-
|
|
11894
|
-
} else
|
|
11895
|
-
sendBack({
|
|
11896
|
-
type: "invalid value",
|
|
11897
|
-
resolution: validation.resolution,
|
|
11898
|
-
value
|
|
11899
|
-
}), blockValid = !1;
|
|
11957
|
+
isChanged = !0;
|
|
11900
11958
|
}
|
|
11901
|
-
|
|
11902
|
-
|
|
11903
|
-
|
|
11904
|
-
|
|
11905
|
-
|
|
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: [
|
|
11982
|
+
at: [index]
|
|
11909
11983
|
});
|
|
11910
|
-
}
|
|
11911
|
-
|
|
11912
|
-
|
|
11913
|
-
|
|
11914
|
-
|
|
11915
|
-
|
|
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
|
|
11925
|
-
|
|
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: [
|
|
11928
|
-
}), Transforms.insertNodes(slateEditor,
|
|
11929
|
-
at: [
|
|
12056
|
+
at: [index]
|
|
12057
|
+
}), Transforms.insertNodes(slateEditor, slateBlock, {
|
|
12058
|
+
at: [index]
|
|
11930
12059
|
}), slateEditor.onChange(), selectionFocusOnBlock && Transforms.select(slateEditor, currentSelection);
|
|
11931
12060
|
}
|
|
11932
|
-
function
|
|
11933
|
-
|
|
11934
|
-
|
|
11935
|
-
|
|
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
|
-
|
|
11938
|
-
const childIndex = oldBlockChildrenLength - 1 -
|
|
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: [
|
|
12078
|
+
at: [index2, childIndex]
|
|
11941
12079
|
}));
|
|
11942
|
-
}),
|
|
11943
|
-
const oldBlockChild = oldBlock.children[currentBlockChildIndex], isChildChanged = !isEqual(currentBlockChild, oldBlockChild), isTextChanged = !isEqual(currentBlockChild.text, oldBlockChild?.text), path = [
|
|
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 =
|
|
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: [
|
|
12112
|
+
at: [index, currentBlockChildIndex]
|
|
11971
12113
|
}), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
11972
|
-
at: [
|
|
12114
|
+
at: [index, currentBlockChildIndex]
|
|
11973
12115
|
}), slateEditor.onChange()) : oldBlockChild || (debug$2("Inserting new child", currentBlockChild), Transforms.insertNodes(slateEditor, currentBlockChild, {
|
|
11974
|
-
at: [
|
|
12116
|
+
at: [index, currentBlockChildIndex]
|
|
11975
12117
|
}), slateEditor.onChange());
|
|
11976
12118
|
});
|
|
11977
12119
|
}
|