@portabletext/editor 2.13.2 → 2.13.3
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-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.ts +61 -61
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/index.cjs +206 -140
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +208 -142
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +3 -3
- package/lib/selectors/index.d.cts +4 -1
- package/lib/selectors/index.d.ts +4 -1
- package/lib/utils/index.d.cts +2 -2
- package/package.json +10 -10
- package/src/editor/Editable.tsx +16 -76
- package/src/editor/validate-selection-machine.test.ts +47 -0
- package/src/editor/validate-selection-machine.ts +149 -0
- package/src/selectors/index.ts +1 -1
- package/src/selectors/selector.get-mark-state.ts +3 -0
- package/src/test/gherkin-parameter-types.ts +1 -1
package/lib/index.js
CHANGED
|
@@ -5,8 +5,8 @@ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
|
5
5
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
6
6
|
import noop from "lodash/noop.js";
|
|
7
7
|
import { Element as Element$1, Text, Range, Editor, Node, Point, Path, Transforms, Operation, deleteText, setSelection, createEditor } from "slate";
|
|
8
|
-
import { useSelected, useSlateSelector, useSlateStatic, useSlate, Editable,
|
|
9
|
-
import debug$
|
|
8
|
+
import { useSelected, useSlateSelector, useSlateStatic, ReactEditor, useSlate, Editable, withReact, Slate } from "slate-react";
|
|
9
|
+
import debug$g from "debug";
|
|
10
10
|
import { DOMEditor, isDOMNode, EDITOR_TO_PENDING_SELECTION, IS_FOCUSED, IS_READ_ONLY } from "slate-dom";
|
|
11
11
|
import { getBlockStartPoint, getBlockKeyFromSelectionPoint, getChildKeyFromSelectionPoint, blockOffsetToSpanSelectionPoint, defaultKeyGenerator, parseBlocks, parseBlock, parseAnnotation, parseSpan, parseInlineObject, isKeyedSegment, isListBlock, isTypedObject, getSelectionStartPoint, getSelectionEndPoint, getTextBlockText } from "./_chunks-es/util.slice-blocks.js";
|
|
12
12
|
import { getBlockEndPoint, isSelectionCollapsed, isEqualSelectionPoints, isEmptyTextBlock } from "./_chunks-es/util.is-selection-collapsed.js";
|
|
@@ -45,10 +45,10 @@ function EditorEventListener(props) {
|
|
|
45
45
|
}, t1 = [editor, props.on], $[0] = editor, $[1] = props.on, $[2] = t0, $[3] = t1) : (t0 = $[2], t1 = $[3]), useEffect(t0, t1), null;
|
|
46
46
|
}
|
|
47
47
|
const rootName = "sanity-pte:";
|
|
48
|
-
debug$
|
|
48
|
+
debug$g(rootName);
|
|
49
49
|
function debugWithName(name) {
|
|
50
50
|
const namespace = `${rootName}${name}`;
|
|
51
|
-
return debug$
|
|
51
|
+
return debug$g && debug$g.enabled(namespace) ? debug$g(namespace) : debug$g(rootName);
|
|
52
52
|
}
|
|
53
53
|
const VOID_CHILD_KEY = "void-child";
|
|
54
54
|
function keepObjectEquality(object, keyMap) {
|
|
@@ -1568,7 +1568,7 @@ function toKeyName(name) {
|
|
|
1568
1568
|
const keyName = name.toLowerCase();
|
|
1569
1569
|
return aliases[keyName] ?? keyName;
|
|
1570
1570
|
}
|
|
1571
|
-
const debug$
|
|
1571
|
+
const debug$f = debugWithName("plugin:withHotKeys");
|
|
1572
1572
|
function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions) {
|
|
1573
1573
|
const reservedHotkeys = ["enter", "tab", "shift", "delete", "end"], activeHotkeys = hotkeysFromOptions ?? {};
|
|
1574
1574
|
return function(editor) {
|
|
@@ -1583,7 +1583,7 @@ function createWithHotkeys(editorActor, portableTextEditor, hotkeysFromOptions)
|
|
|
1583
1583
|
const possibleMark = activeHotkeys[cat];
|
|
1584
1584
|
if (possibleMark) {
|
|
1585
1585
|
const mark = possibleMark[hotkey];
|
|
1586
|
-
debug$
|
|
1586
|
+
debug$f(`HotKey ${hotkey} to toggle ${mark}`), editorActor.send({
|
|
1587
1587
|
type: "behavior event",
|
|
1588
1588
|
behaviorEvent: {
|
|
1589
1589
|
type: "decorator.toggle",
|
|
@@ -1912,8 +1912,85 @@ function createDecorate(schema, slateEditor) {
|
|
|
1912
1912
|
}) || Range.includes(decoratedRange, path));
|
|
1913
1913
|
};
|
|
1914
1914
|
}
|
|
1915
|
-
const RelayActorContext = createContext({}), debug$
|
|
1916
|
-
|
|
1915
|
+
const RelayActorContext = createContext({}), debug$e = debugWithName("validate selection machine"), validateSelectionSetup = setup({
|
|
1916
|
+
types: {
|
|
1917
|
+
context: {},
|
|
1918
|
+
input: {},
|
|
1919
|
+
events: {}
|
|
1920
|
+
},
|
|
1921
|
+
guards: {
|
|
1922
|
+
"pending operations": ({
|
|
1923
|
+
context
|
|
1924
|
+
}) => context.slateEditor.operations.length > 0
|
|
1925
|
+
}
|
|
1926
|
+
}), validateSelectionAction = validateSelectionSetup.createAction(({
|
|
1927
|
+
context,
|
|
1928
|
+
event
|
|
1929
|
+
}) => {
|
|
1930
|
+
validateSelection(context.slateEditor, event.editorElement);
|
|
1931
|
+
}), validateSelectionMachine = validateSelectionSetup.createMachine({
|
|
1932
|
+
id: "validate selection",
|
|
1933
|
+
context: ({
|
|
1934
|
+
input
|
|
1935
|
+
}) => ({
|
|
1936
|
+
slateEditor: input.slateEditor
|
|
1937
|
+
}),
|
|
1938
|
+
initial: "idle",
|
|
1939
|
+
states: {
|
|
1940
|
+
idle: {
|
|
1941
|
+
on: {
|
|
1942
|
+
"validate selection": [{
|
|
1943
|
+
guard: "pending operations",
|
|
1944
|
+
target: "waiting"
|
|
1945
|
+
}, {
|
|
1946
|
+
actions: [validateSelectionAction],
|
|
1947
|
+
target: "idle"
|
|
1948
|
+
}]
|
|
1949
|
+
}
|
|
1950
|
+
},
|
|
1951
|
+
waiting: {
|
|
1952
|
+
after: {
|
|
1953
|
+
0: [{
|
|
1954
|
+
guard: "pending operations",
|
|
1955
|
+
target: ".",
|
|
1956
|
+
reenter: !0
|
|
1957
|
+
}, {
|
|
1958
|
+
target: "idle",
|
|
1959
|
+
actions: [validateSelectionAction]
|
|
1960
|
+
}]
|
|
1961
|
+
},
|
|
1962
|
+
on: {
|
|
1963
|
+
"validate selection": {
|
|
1964
|
+
target: ".",
|
|
1965
|
+
reenter: !0
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
});
|
|
1971
|
+
function validateSelection(slateEditor, editorElement) {
|
|
1972
|
+
if (!slateEditor.selection)
|
|
1973
|
+
return;
|
|
1974
|
+
let root;
|
|
1975
|
+
try {
|
|
1976
|
+
root = ReactEditor.findDocumentOrShadowRoot(slateEditor);
|
|
1977
|
+
} catch {
|
|
1978
|
+
}
|
|
1979
|
+
if (!root || editorElement !== root.activeElement)
|
|
1980
|
+
return;
|
|
1981
|
+
const domSelection = ReactEditor.getWindow(slateEditor).getSelection();
|
|
1982
|
+
if (!domSelection || domSelection.rangeCount === 0)
|
|
1983
|
+
return;
|
|
1984
|
+
const existingDOMRange = domSelection.getRangeAt(0);
|
|
1985
|
+
try {
|
|
1986
|
+
const newDOMRange = ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
|
|
1987
|
+
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug$e("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
1988
|
+
} catch {
|
|
1989
|
+
debug$e("Could not resolve selection, selecting top document"), Transforms.deselect(slateEditor), slateEditor.children.length > 0 && Transforms.select(slateEditor, Editor.start(slateEditor, [])), slateEditor.onChange();
|
|
1990
|
+
}
|
|
1991
|
+
}
|
|
1992
|
+
const debug$d = debugWithName("component:Editable"), PortableTextEditable = forwardRef(function(props, forwardedRef) {
|
|
1993
|
+
const $ = c(174);
|
|
1917
1994
|
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;
|
|
1918
1995
|
$[0] !== props ? ({
|
|
1919
1996
|
hotkeys,
|
|
@@ -1946,50 +2023,57 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
1946
2023
|
} = props, $[0] = props, $[1] = hotkeys, $[2] = onBeforeInput, $[3] = onBlur, $[4] = onClick, $[5] = onCopy, $[6] = onCut, $[7] = onDrag, $[8] = onDragEnd, $[9] = onDragEnter, $[10] = onDragLeave, $[11] = onDragOver, $[12] = onDragStart, $[13] = onDrop, $[14] = onFocus, $[15] = onPaste, $[16] = propsSelection, $[17] = rangeDecorations, $[18] = renderAnnotation, $[19] = renderBlock, $[20] = renderChild, $[21] = renderDecorator, $[22] = renderListItem, $[23] = renderPlaceholder, $[24] = renderStyle, $[25] = restProps, $[26] = scrollSelectionIntoView, $[27] = spellCheck) : (hotkeys = $[1], onBeforeInput = $[2], onBlur = $[3], onClick = $[4], onCopy = $[5], onCut = $[6], onDrag = $[7], onDragEnd = $[8], onDragEnter = $[9], onDragLeave = $[10], onDragOver = $[11], onDragStart = $[12], onDrop = $[13], onFocus = $[14], onPaste = $[15], propsSelection = $[16], rangeDecorations = $[17], renderAnnotation = $[18], renderBlock = $[19], renderChild = $[20], renderDecorator = $[21], renderListItem = $[22], renderPlaceholder = $[23], renderStyle = $[24], restProps = $[25], scrollSelectionIntoView = $[26], spellCheck = $[27]);
|
|
1947
2024
|
const portableTextEditor = usePortableTextEditor(), [hasInvalidValue, setHasInvalidValue] = useState(!1), editorActor = useContext(EditorActorContext), relayActor = useContext(RelayActorContext), readOnly = useSelector(editorActor, _temp), slateEditor = useSlate();
|
|
1948
2025
|
let t0;
|
|
1949
|
-
$[28] !==
|
|
2026
|
+
$[28] !== slateEditor ? (t0 = {
|
|
2027
|
+
input: {
|
|
2028
|
+
slateEditor
|
|
2029
|
+
}
|
|
2030
|
+
}, $[28] = slateEditor, $[29] = t0) : t0 = $[29];
|
|
2031
|
+
const validateSelectionActor = useActorRef(validateSelectionMachine, t0);
|
|
1950
2032
|
let t1;
|
|
1951
|
-
$[30] !==
|
|
1952
|
-
|
|
2033
|
+
$[30] !== rangeDecorations ? (t1 = rangeDecorations ?? [], $[30] = rangeDecorations, $[31] = t1) : t1 = $[31];
|
|
2034
|
+
let t2;
|
|
2035
|
+
$[32] !== editorActor ? (t2 = editorActor.getSnapshot(), $[32] = editorActor, $[33] = t2) : t2 = $[33];
|
|
2036
|
+
const t3 = !editorActor.getSnapshot().matches({
|
|
1953
2037
|
setup: "setting up"
|
|
1954
2038
|
});
|
|
1955
|
-
let
|
|
1956
|
-
$[
|
|
2039
|
+
let t4;
|
|
2040
|
+
$[34] !== readOnly || $[35] !== slateEditor || $[36] !== t1 || $[37] !== t2.context.schema || $[38] !== t3 ? (t4 = {
|
|
1957
2041
|
input: {
|
|
1958
|
-
rangeDecorations:
|
|
2042
|
+
rangeDecorations: t1,
|
|
1959
2043
|
readOnly,
|
|
1960
|
-
schema:
|
|
2044
|
+
schema: t2.context.schema,
|
|
1961
2045
|
slateEditor,
|
|
1962
|
-
skipSetup:
|
|
2046
|
+
skipSetup: t3
|
|
1963
2047
|
}
|
|
1964
|
-
}, $[
|
|
1965
|
-
const rangeDecorationsActor = useActorRef(rangeDecorationsMachine,
|
|
1966
|
-
let
|
|
1967
|
-
$[
|
|
2048
|
+
}, $[34] = readOnly, $[35] = slateEditor, $[36] = t1, $[37] = t2.context.schema, $[38] = t3, $[39] = t4) : t4 = $[39];
|
|
2049
|
+
const rangeDecorationsActor = useActorRef(rangeDecorationsMachine, t4), decorate = useSelector(rangeDecorationsActor, _temp2);
|
|
2050
|
+
let t5, t6;
|
|
2051
|
+
$[40] !== rangeDecorationsActor || $[41] !== readOnly ? (t5 = () => {
|
|
1968
2052
|
rangeDecorationsActor.send({
|
|
1969
2053
|
type: "update read only",
|
|
1970
2054
|
readOnly
|
|
1971
2055
|
});
|
|
1972
|
-
},
|
|
1973
|
-
let
|
|
1974
|
-
$[
|
|
2056
|
+
}, t6 = [rangeDecorationsActor, readOnly], $[40] = rangeDecorationsActor, $[41] = readOnly, $[42] = t5, $[43] = t6) : (t5 = $[42], t6 = $[43]), useEffect(t5, t6);
|
|
2057
|
+
let t7, t8;
|
|
2058
|
+
$[44] !== rangeDecorations || $[45] !== rangeDecorationsActor ? (t7 = () => {
|
|
1975
2059
|
rangeDecorationsActor.send({
|
|
1976
2060
|
type: "range decorations updated",
|
|
1977
2061
|
rangeDecorations: rangeDecorations ?? []
|
|
1978
2062
|
});
|
|
1979
|
-
},
|
|
2063
|
+
}, t8 = [rangeDecorationsActor, rangeDecorations], $[44] = rangeDecorations, $[45] = rangeDecorationsActor, $[46] = t7, $[47] = t8) : (t7 = $[46], t8 = $[47]), useEffect(t7, t8);
|
|
1980
2064
|
bb0: {
|
|
1981
2065
|
if (readOnly)
|
|
1982
2066
|
break bb0;
|
|
1983
2067
|
createWithHotkeys(editorActor, portableTextEditor, hotkeys)(slateEditor);
|
|
1984
2068
|
}
|
|
1985
|
-
let t9;
|
|
1986
|
-
$[46] !== readOnly || $[47] !== renderBlock || $[48] !== renderChild || $[49] !== renderListItem || $[50] !== renderStyle || $[51] !== spellCheck ? (t9 = (eProps) => /* @__PURE__ */ jsx(RenderElement, { ...eProps, readOnly, renderBlock, renderChild, renderListItem, renderStyle, spellCheck }), $[46] = readOnly, $[47] = renderBlock, $[48] = renderChild, $[49] = renderListItem, $[50] = renderStyle, $[51] = spellCheck, $[52] = t9) : t9 = $[52];
|
|
1987
|
-
const renderElement = t9;
|
|
1988
2069
|
let t10;
|
|
1989
|
-
$[
|
|
1990
|
-
const
|
|
2070
|
+
$[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];
|
|
2071
|
+
const renderElement = t10;
|
|
1991
2072
|
let t11;
|
|
1992
|
-
$[
|
|
2073
|
+
$[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];
|
|
2074
|
+
const renderLeaf = t11, renderText = _temp3;
|
|
2075
|
+
let t12;
|
|
2076
|
+
$[61] !== editorActor || $[62] !== propsSelection || $[63] !== slateEditor ? (t12 = () => {
|
|
1993
2077
|
if (propsSelection) {
|
|
1994
2078
|
debug$d(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
1995
2079
|
const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name));
|
|
@@ -2009,10 +2093,10 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2009
2093
|
}), slateEditor.onChange());
|
|
2010
2094
|
}
|
|
2011
2095
|
}
|
|
2012
|
-
}, $[
|
|
2013
|
-
const restoreSelectionFromProps =
|
|
2014
|
-
let
|
|
2015
|
-
$[
|
|
2096
|
+
}, $[61] = editorActor, $[62] = propsSelection, $[63] = slateEditor, $[64] = t12) : t12 = $[64];
|
|
2097
|
+
const restoreSelectionFromProps = t12;
|
|
2098
|
+
let t13, t14;
|
|
2099
|
+
$[65] !== editorActor || $[66] !== rangeDecorationsActor || $[67] !== restoreSelectionFromProps ? (t13 = () => {
|
|
2016
2100
|
const onReady = editorActor.on("ready", () => {
|
|
2017
2101
|
rangeDecorationsActor.send({
|
|
2018
2102
|
type: "ready"
|
|
@@ -2025,13 +2109,13 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2025
2109
|
return () => {
|
|
2026
2110
|
onReady.unsubscribe(), onInvalidValue.unsubscribe(), onValueChanged.unsubscribe();
|
|
2027
2111
|
};
|
|
2028
|
-
},
|
|
2029
|
-
let
|
|
2030
|
-
$[
|
|
2112
|
+
}, t14 = [rangeDecorationsActor, editorActor, restoreSelectionFromProps], $[65] = editorActor, $[66] = rangeDecorationsActor, $[67] = restoreSelectionFromProps, $[68] = t13, $[69] = t14) : (t13 = $[68], t14 = $[69]), useEffect(t13, t14);
|
|
2113
|
+
let t15, t16;
|
|
2114
|
+
$[70] !== hasInvalidValue || $[71] !== propsSelection || $[72] !== restoreSelectionFromProps ? (t15 = () => {
|
|
2031
2115
|
propsSelection && !hasInvalidValue && restoreSelectionFromProps();
|
|
2032
|
-
},
|
|
2033
|
-
let
|
|
2034
|
-
$[
|
|
2116
|
+
}, t16 = [hasInvalidValue, propsSelection, restoreSelectionFromProps], $[70] = hasInvalidValue, $[71] = propsSelection, $[72] = restoreSelectionFromProps, $[73] = t15, $[74] = t16) : (t15 = $[73], t16 = $[74]), useEffect(t15, t16);
|
|
2117
|
+
let t17;
|
|
2118
|
+
$[75] !== editorActor || $[76] !== onCopy || $[77] !== slateEditor ? (t17 = (event) => {
|
|
2035
2119
|
if (onCopy)
|
|
2036
2120
|
onCopy(event) !== void 0 && event.preventDefault();
|
|
2037
2121
|
else if (event.nativeEvent.clipboardData) {
|
|
@@ -2060,10 +2144,10 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2060
2144
|
nativeEvent: event
|
|
2061
2145
|
});
|
|
2062
2146
|
}
|
|
2063
|
-
}, $[
|
|
2064
|
-
const handleCopy =
|
|
2065
|
-
let
|
|
2066
|
-
$[
|
|
2147
|
+
}, $[75] = editorActor, $[76] = onCopy, $[77] = slateEditor, $[78] = t17) : t17 = $[78];
|
|
2148
|
+
const handleCopy = t17;
|
|
2149
|
+
let t18;
|
|
2150
|
+
$[79] !== editorActor || $[80] !== onCut || $[81] !== slateEditor ? (t18 = (event_0) => {
|
|
2067
2151
|
if (onCut)
|
|
2068
2152
|
onCut(event_0) !== void 0 && event_0.preventDefault();
|
|
2069
2153
|
else if (event_0.nativeEvent.clipboardData) {
|
|
@@ -2088,10 +2172,10 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2088
2172
|
nativeEvent: event_0
|
|
2089
2173
|
});
|
|
2090
2174
|
}
|
|
2091
|
-
}, $[
|
|
2092
|
-
const handleCut =
|
|
2093
|
-
let
|
|
2094
|
-
$[
|
|
2175
|
+
}, $[79] = editorActor, $[80] = onCut, $[81] = slateEditor, $[82] = t18) : t18 = $[82];
|
|
2176
|
+
const handleCut = t18;
|
|
2177
|
+
let t19;
|
|
2178
|
+
$[83] !== editorActor || $[84] !== onPaste || $[85] !== portableTextEditor || $[86] !== relayActor || $[87] !== slateEditor ? (t19 = (event_1) => {
|
|
2095
2179
|
const value = fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditor)), path = (slateEditor.selection ? slateRangeToSelection({
|
|
2096
2180
|
schema: editorActor.getSnapshot().context.schema,
|
|
2097
2181
|
editor: slateEditor,
|
|
@@ -2175,18 +2259,18 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2175
2259
|
});
|
|
2176
2260
|
}
|
|
2177
2261
|
debug$d("No result from custom paste handler, pasting normally");
|
|
2178
|
-
}, $[
|
|
2179
|
-
const handlePaste =
|
|
2180
|
-
let
|
|
2181
|
-
$[
|
|
2262
|
+
}, $[83] = editorActor, $[84] = onPaste, $[85] = portableTextEditor, $[86] = relayActor, $[87] = slateEditor, $[88] = t19) : t19 = $[88];
|
|
2263
|
+
const handlePaste = t19;
|
|
2264
|
+
let t20;
|
|
2265
|
+
$[89] !== editorActor || $[90] !== onFocus || $[91] !== relayActor || $[92] !== slateEditor ? (t20 = (event_2) => {
|
|
2182
2266
|
onFocus && onFocus(event_2), event_2.isDefaultPrevented() || (relayActor.send({
|
|
2183
2267
|
type: "focused",
|
|
2184
2268
|
event: event_2
|
|
2185
2269
|
}), !slateEditor.selection && isEqualToEmptyEditor(slateEditor.children, editorActor.getSnapshot().context.schema) && (Transforms.select(slateEditor, Editor.start(slateEditor, [])), slateEditor.onChange()));
|
|
2186
|
-
}, $[
|
|
2187
|
-
const handleOnFocus =
|
|
2188
|
-
let
|
|
2189
|
-
$[
|
|
2270
|
+
}, $[89] = editorActor, $[90] = onFocus, $[91] = relayActor, $[92] = slateEditor, $[93] = t20) : t20 = $[93];
|
|
2271
|
+
const handleOnFocus = t20;
|
|
2272
|
+
let t21;
|
|
2273
|
+
$[94] !== editorActor || $[95] !== onClick || $[96] !== slateEditor ? (t21 = (event_3) => {
|
|
2190
2274
|
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
2191
2275
|
return;
|
|
2192
2276
|
const position_3 = getEventPosition({
|
|
@@ -2203,23 +2287,23 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2203
2287
|
editor: slateEditor,
|
|
2204
2288
|
nativeEvent: event_3
|
|
2205
2289
|
});
|
|
2206
|
-
}, $[
|
|
2207
|
-
const handleClick =
|
|
2208
|
-
let
|
|
2209
|
-
$[
|
|
2290
|
+
}, $[94] = editorActor, $[95] = onClick, $[96] = slateEditor, $[97] = t21) : t21 = $[97];
|
|
2291
|
+
const handleClick = t21;
|
|
2292
|
+
let t22;
|
|
2293
|
+
$[98] !== onBlur || $[99] !== relayActor ? (t22 = (event_4) => {
|
|
2210
2294
|
onBlur && onBlur(event_4), event_4.isPropagationStopped() || relayActor.send({
|
|
2211
2295
|
type: "blurred",
|
|
2212
2296
|
event: event_4
|
|
2213
2297
|
});
|
|
2214
|
-
}, $[
|
|
2215
|
-
const handleOnBlur =
|
|
2216
|
-
let t22;
|
|
2217
|
-
$[99] !== onBeforeInput ? (t22 = (event_5) => {
|
|
2218
|
-
onBeforeInput && onBeforeInput(event_5);
|
|
2219
|
-
}, $[99] = onBeforeInput, $[100] = t22) : t22 = $[100];
|
|
2220
|
-
const handleOnBeforeInput = t22;
|
|
2298
|
+
}, $[98] = onBlur, $[99] = relayActor, $[100] = t22) : t22 = $[100];
|
|
2299
|
+
const handleOnBlur = t22;
|
|
2221
2300
|
let t23;
|
|
2222
|
-
$[101] !==
|
|
2301
|
+
$[101] !== onBeforeInput ? (t23 = (event_5) => {
|
|
2302
|
+
onBeforeInput && onBeforeInput(event_5);
|
|
2303
|
+
}, $[101] = onBeforeInput, $[102] = t23) : t23 = $[102];
|
|
2304
|
+
const handleOnBeforeInput = t23;
|
|
2305
|
+
let t24;
|
|
2306
|
+
$[103] !== editorActor || $[104] !== props || $[105] !== slateEditor ? (t24 = (event_6) => {
|
|
2223
2307
|
props.onKeyDown && props.onKeyDown(event_6), event_6.isDefaultPrevented() || slateEditor.pteWithHotKeys(event_6), event_6.isDefaultPrevented() || editorActor.send({
|
|
2224
2308
|
type: "behavior event",
|
|
2225
2309
|
behaviorEvent: {
|
|
@@ -2236,10 +2320,10 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2236
2320
|
editor: slateEditor,
|
|
2237
2321
|
nativeEvent: event_6
|
|
2238
2322
|
});
|
|
2239
|
-
}, $[
|
|
2240
|
-
const handleKeyDown =
|
|
2241
|
-
let
|
|
2242
|
-
$[
|
|
2323
|
+
}, $[103] = editorActor, $[104] = props, $[105] = slateEditor, $[106] = t24) : t24 = $[106];
|
|
2324
|
+
const handleKeyDown = t24;
|
|
2325
|
+
let t25;
|
|
2326
|
+
$[107] !== editorActor || $[108] !== props || $[109] !== slateEditor ? (t25 = (event_7) => {
|
|
2243
2327
|
props.onKeyUp && props.onKeyUp(event_7), event_7.isDefaultPrevented() || editorActor.send({
|
|
2244
2328
|
type: "behavior event",
|
|
2245
2329
|
behaviorEvent: {
|
|
@@ -2256,26 +2340,26 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2256
2340
|
editor: slateEditor,
|
|
2257
2341
|
nativeEvent: event_7
|
|
2258
2342
|
});
|
|
2259
|
-
}, $[
|
|
2260
|
-
const handleKeyUp =
|
|
2261
|
-
let
|
|
2343
|
+
}, $[107] = editorActor, $[108] = props, $[109] = slateEditor, $[110] = t25) : t25 = $[110];
|
|
2344
|
+
const handleKeyUp = t25;
|
|
2345
|
+
let t26;
|
|
2262
2346
|
bb1: {
|
|
2263
2347
|
if (scrollSelectionIntoView === void 0) {
|
|
2264
|
-
|
|
2348
|
+
t26 = void 0;
|
|
2265
2349
|
break bb1;
|
|
2266
2350
|
}
|
|
2267
2351
|
if (scrollSelectionIntoView === null) {
|
|
2268
|
-
|
|
2352
|
+
t26 = noop;
|
|
2269
2353
|
break bb1;
|
|
2270
2354
|
}
|
|
2271
|
-
let
|
|
2272
|
-
$[
|
|
2355
|
+
let t272;
|
|
2356
|
+
$[111] !== portableTextEditor || $[112] !== scrollSelectionIntoView ? (t272 = (_editor, domRange) => {
|
|
2273
2357
|
scrollSelectionIntoView(portableTextEditor, domRange);
|
|
2274
|
-
}, $[
|
|
2358
|
+
}, $[111] = portableTextEditor, $[112] = scrollSelectionIntoView, $[113] = t272) : t272 = $[113], t26 = t272;
|
|
2275
2359
|
}
|
|
2276
|
-
const scrollSelectionIntoViewToSlate =
|
|
2277
|
-
let
|
|
2278
|
-
$[
|
|
2360
|
+
const scrollSelectionIntoViewToSlate = t26;
|
|
2361
|
+
let t27, t28;
|
|
2362
|
+
$[114] !== editorActor || $[115] !== slateEditor ? (t27 = () => {
|
|
2279
2363
|
const window2 = ReactEditor.getWindow(slateEditor), onDragEnd_0 = () => {
|
|
2280
2364
|
editorActor.send({
|
|
2281
2365
|
type: "dragend"
|
|
@@ -2288,9 +2372,9 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2288
2372
|
return window2.document.addEventListener("dragend", onDragEnd_0), window2.document.addEventListener("drop", onDrop_0), () => {
|
|
2289
2373
|
window2.document.removeEventListener("dragend", onDragEnd_0), window2.document.removeEventListener("drop", onDrop_0);
|
|
2290
2374
|
};
|
|
2291
|
-
},
|
|
2292
|
-
let
|
|
2293
|
-
$[
|
|
2375
|
+
}, t28 = [slateEditor, editorActor], $[114] = editorActor, $[115] = slateEditor, $[116] = t27, $[117] = t28) : (t27 = $[116], t28 = $[117]), useEffect(t27, t28);
|
|
2376
|
+
let t29;
|
|
2377
|
+
$[118] !== editorActor || $[119] !== onDragStart || $[120] !== slateEditor ? (t29 = (event_8) => {
|
|
2294
2378
|
if (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped())
|
|
2295
2379
|
return;
|
|
2296
2380
|
const position_4 = getEventPosition({
|
|
@@ -2318,10 +2402,10 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2318
2402
|
},
|
|
2319
2403
|
editor: slateEditor
|
|
2320
2404
|
}), !0;
|
|
2321
|
-
}, $[
|
|
2322
|
-
const handleDragStart =
|
|
2323
|
-
let
|
|
2324
|
-
$[
|
|
2405
|
+
}, $[118] = editorActor, $[119] = onDragStart, $[120] = slateEditor, $[121] = t29) : t29 = $[121];
|
|
2406
|
+
const handleDragStart = t29;
|
|
2407
|
+
let t30;
|
|
2408
|
+
$[122] !== editorActor || $[123] !== onDrag || $[124] !== slateEditor ? (t30 = (event_9) => {
|
|
2325
2409
|
if (onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped() || !getEventPosition({
|
|
2326
2410
|
editorActor,
|
|
2327
2411
|
slateEditor,
|
|
@@ -2337,10 +2421,10 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2337
2421
|
},
|
|
2338
2422
|
editor: slateEditor
|
|
2339
2423
|
}), !0;
|
|
2340
|
-
}, $[
|
|
2341
|
-
const handleDrag =
|
|
2342
|
-
let
|
|
2343
|
-
$[
|
|
2424
|
+
}, $[122] = editorActor, $[123] = onDrag, $[124] = slateEditor, $[125] = t30) : t30 = $[125];
|
|
2425
|
+
const handleDrag = t30;
|
|
2426
|
+
let t31;
|
|
2427
|
+
$[126] !== editorActor || $[127] !== onDragEnd || $[128] !== slateEditor ? (t31 = (event_10) => {
|
|
2344
2428
|
if (onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped()))
|
|
2345
2429
|
return editorActor.send({
|
|
2346
2430
|
type: "behavior event",
|
|
@@ -2352,10 +2436,10 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2352
2436
|
},
|
|
2353
2437
|
editor: slateEditor
|
|
2354
2438
|
}), !0;
|
|
2355
|
-
}, $[
|
|
2356
|
-
const handleDragEnd =
|
|
2357
|
-
let
|
|
2358
|
-
$[
|
|
2439
|
+
}, $[126] = editorActor, $[127] = onDragEnd, $[128] = slateEditor, $[129] = t31) : t31 = $[129];
|
|
2440
|
+
const handleDragEnd = t31;
|
|
2441
|
+
let t32;
|
|
2442
|
+
$[130] !== editorActor || $[131] !== onDragEnter || $[132] !== slateEditor ? (t32 = (event_11) => {
|
|
2359
2443
|
if (onDragEnter?.(event_11), event_11.isDefaultPrevented() || event_11.isPropagationStopped())
|
|
2360
2444
|
return;
|
|
2361
2445
|
const position_6 = getEventPosition({
|
|
@@ -2375,10 +2459,10 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2375
2459
|
},
|
|
2376
2460
|
editor: slateEditor
|
|
2377
2461
|
}), !0;
|
|
2378
|
-
}, $[
|
|
2379
|
-
const handleDragEnter =
|
|
2380
|
-
let
|
|
2381
|
-
$[
|
|
2462
|
+
}, $[130] = editorActor, $[131] = onDragEnter, $[132] = slateEditor, $[133] = t32) : t32 = $[133];
|
|
2463
|
+
const handleDragEnter = t32;
|
|
2464
|
+
let t33;
|
|
2465
|
+
$[134] !== editorActor || $[135] !== onDragOver || $[136] !== slateEditor ? (t33 = (event_12) => {
|
|
2382
2466
|
if (onDragOver?.(event_12), event_12.isDefaultPrevented() || event_12.isPropagationStopped())
|
|
2383
2467
|
return;
|
|
2384
2468
|
const position_7 = getEventPosition({
|
|
@@ -2400,10 +2484,10 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2400
2484
|
editor: slateEditor,
|
|
2401
2485
|
nativeEvent: event_12
|
|
2402
2486
|
}), !0;
|
|
2403
|
-
}, $[
|
|
2404
|
-
const handleDragOver =
|
|
2405
|
-
let
|
|
2406
|
-
$[
|
|
2487
|
+
}, $[134] = editorActor, $[135] = onDragOver, $[136] = slateEditor, $[137] = t33) : t33 = $[137];
|
|
2488
|
+
const handleDragOver = t33;
|
|
2489
|
+
let t34;
|
|
2490
|
+
$[138] !== editorActor || $[139] !== onDrop || $[140] !== slateEditor ? (t34 = (event_13) => {
|
|
2407
2491
|
if (onDrop?.(event_13), event_13.isDefaultPrevented() || event_13.isPropagationStopped())
|
|
2408
2492
|
return;
|
|
2409
2493
|
const position_8 = getEventPosition({
|
|
@@ -2428,10 +2512,10 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2428
2512
|
editor: slateEditor,
|
|
2429
2513
|
nativeEvent: event_13
|
|
2430
2514
|
}), !0;
|
|
2431
|
-
}, $[
|
|
2432
|
-
const handleDrop =
|
|
2433
|
-
let
|
|
2434
|
-
$[
|
|
2515
|
+
}, $[138] = editorActor, $[139] = onDrop, $[140] = slateEditor, $[141] = t34) : t34 = $[141];
|
|
2516
|
+
const handleDrop = t34;
|
|
2517
|
+
let t35;
|
|
2518
|
+
$[142] !== editorActor || $[143] !== onDragLeave || $[144] !== slateEditor ? (t35 = (event_14) => {
|
|
2435
2519
|
if (onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped() || !getEventPosition({
|
|
2436
2520
|
editorActor,
|
|
2437
2521
|
slateEditor,
|
|
@@ -2447,15 +2531,18 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2447
2531
|
},
|
|
2448
2532
|
editor: slateEditor
|
|
2449
2533
|
}), !0;
|
|
2450
|
-
}, $[
|
|
2451
|
-
const handleDragLeave =
|
|
2452
|
-
let
|
|
2453
|
-
$[
|
|
2454
|
-
if (typeof forwardedRef == "function" ? forwardedRef(
|
|
2534
|
+
}, $[142] = editorActor, $[143] = onDragLeave, $[144] = slateEditor, $[145] = t35) : t35 = $[145];
|
|
2535
|
+
const handleDragLeave = t35;
|
|
2536
|
+
let t36;
|
|
2537
|
+
$[146] !== forwardedRef || $[147] !== validateSelectionActor ? (t36 = (editorElement) => {
|
|
2538
|
+
if (typeof forwardedRef == "function" ? forwardedRef(editorElement) : forwardedRef && (forwardedRef.current = editorElement), editorElement) {
|
|
2455
2539
|
const mutationObserver = new MutationObserver(() => {
|
|
2456
|
-
|
|
2540
|
+
validateSelectionActor.send({
|
|
2541
|
+
type: "validate selection",
|
|
2542
|
+
editorElement
|
|
2543
|
+
});
|
|
2457
2544
|
});
|
|
2458
|
-
return mutationObserver.observe(
|
|
2545
|
+
return mutationObserver.observe(editorElement, {
|
|
2459
2546
|
attributeOldValue: !1,
|
|
2460
2547
|
attributes: !1,
|
|
2461
2548
|
characterData: !1,
|
|
@@ -2465,35 +2552,14 @@ const RelayActorContext = createContext({}), debug$d = debugWithName("component:
|
|
|
2465
2552
|
mutationObserver.disconnect();
|
|
2466
2553
|
};
|
|
2467
2554
|
}
|
|
2468
|
-
}, $[
|
|
2469
|
-
const callbackRef =
|
|
2555
|
+
}, $[146] = forwardedRef, $[147] = validateSelectionActor, $[148] = t36) : t36 = $[148];
|
|
2556
|
+
const callbackRef = t36;
|
|
2470
2557
|
if (!portableTextEditor)
|
|
2471
2558
|
return null;
|
|
2472
|
-
let
|
|
2473
|
-
return $[
|
|
2559
|
+
let t37;
|
|
2560
|
+
return $[149] !== callbackRef || $[150] !== decorate || $[151] !== handleClick || $[152] !== handleCopy || $[153] !== handleCut || $[154] !== handleDrag || $[155] !== handleDragEnd || $[156] !== handleDragEnter || $[157] !== handleDragLeave || $[158] !== handleDragOver || $[159] !== handleDragStart || $[160] !== handleDrop || $[161] !== handleKeyDown || $[162] !== handleKeyUp || $[163] !== handleOnBeforeInput || $[164] !== handleOnBlur || $[165] !== handleOnFocus || $[166] !== handlePaste || $[167] !== hasInvalidValue || $[168] !== readOnly || $[169] !== renderElement || $[170] !== renderLeaf || $[171] !== restProps || $[172] !== scrollSelectionIntoViewToSlate ? (t37 = hasInvalidValue ? null : /* @__PURE__ */ jsx(Editable, { ...restProps, ref: callbackRef, "data-read-only": readOnly, autoFocus: !1, className: restProps.className || "pt-editable", decorate, onBlur: handleOnBlur, onCopy: handleCopy, onCut: handleCut, onClick: handleClick, onDOMBeforeInput: handleOnBeforeInput, onDragStart: handleDragStart, onDrag: handleDrag, onDragEnd: handleDragEnd, onDragEnter: handleDragEnter, onDragOver: handleDragOver, onDrop: handleDrop, onDragLeave: handleDragLeave, onFocus: handleOnFocus, onKeyDown: handleKeyDown, onKeyUp: handleKeyUp, onPaste: handlePaste, readOnly, renderPlaceholder: void 0, renderElement, renderLeaf, renderText, scrollSelectionIntoView: scrollSelectionIntoViewToSlate }), $[149] = callbackRef, $[150] = decorate, $[151] = handleClick, $[152] = handleCopy, $[153] = handleCut, $[154] = handleDrag, $[155] = handleDragEnd, $[156] = handleDragEnter, $[157] = handleDragLeave, $[158] = handleDragOver, $[159] = handleDragStart, $[160] = handleDrop, $[161] = handleKeyDown, $[162] = handleKeyUp, $[163] = handleOnBeforeInput, $[164] = handleOnBlur, $[165] = handleOnFocus, $[166] = handlePaste, $[167] = hasInvalidValue, $[168] = readOnly, $[169] = renderElement, $[170] = renderLeaf, $[171] = restProps, $[172] = scrollSelectionIntoViewToSlate, $[173] = t37) : t37 = $[173], t37;
|
|
2474
2561
|
});
|
|
2475
2562
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
2476
|
-
function validateSelection(slateEditor, activeElement) {
|
|
2477
|
-
if (!slateEditor.selection)
|
|
2478
|
-
return;
|
|
2479
|
-
let root;
|
|
2480
|
-
try {
|
|
2481
|
-
root = ReactEditor.findDocumentOrShadowRoot(slateEditor);
|
|
2482
|
-
} catch {
|
|
2483
|
-
}
|
|
2484
|
-
if (!root || activeElement !== root.activeElement)
|
|
2485
|
-
return;
|
|
2486
|
-
const domSelection = ReactEditor.getWindow(slateEditor).getSelection();
|
|
2487
|
-
if (!domSelection || domSelection.rangeCount === 0)
|
|
2488
|
-
return;
|
|
2489
|
-
const existingDOMRange = domSelection.getRangeAt(0);
|
|
2490
|
-
try {
|
|
2491
|
-
const newDOMRange = ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
|
|
2492
|
-
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug$d("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
2493
|
-
} catch {
|
|
2494
|
-
debug$d("Could not resolve selection, selecting top document"), Transforms.deselect(slateEditor), slateEditor.children.length > 0 && Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
|
|
2495
|
-
}
|
|
2496
|
-
}
|
|
2497
2563
|
function _temp(s) {
|
|
2498
2564
|
return s.matches({
|
|
2499
2565
|
"edit mode": "read only"
|