@portabletext/editor 2.4.3 → 2.5.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-dts/behavior.types.action.d.cts +25 -10
- package/lib/_chunks-dts/behavior.types.action.d.ts +25 -10
- package/lib/index.cjs +214 -140
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +215 -141
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/lib/plugins/index.d.ts +3 -3
- package/package.json +5 -5
- package/src/editor/Editable.tsx +90 -103
package/lib/index.cjs
CHANGED
|
@@ -1008,7 +1008,7 @@ function RenderTextBlock(props) {
|
|
|
1008
1008
|
] });
|
|
1009
1009
|
}
|
|
1010
1010
|
function RenderElement(props) {
|
|
1011
|
-
const $ = reactCompilerRuntime.c(34), editorActor = React.useContext(EditorActorContext), schema2 = react.useSelector(editorActor, _temp$
|
|
1011
|
+
const $ = reactCompilerRuntime.c(34), editorActor = React.useContext(EditorActorContext), schema2 = react.useSelector(editorActor, _temp$2), legacySchema = react.useSelector(editorActor, _temp2$1), slateStatic = slateReact.useSlateStatic();
|
|
1012
1012
|
if ("__inline" in props.element && props.element.__inline === !0) {
|
|
1013
1013
|
let t02;
|
|
1014
1014
|
return $[0] !== legacySchema || $[1] !== props.attributes || $[2] !== props.children || $[3] !== props.element || $[4] !== props.readOnly || $[5] !== props.renderChild || $[6] !== schema2 ? (t02 = /* @__PURE__ */ jsxRuntime.jsx(RenderInlineObject, { attributes: props.attributes, element: props.element, legacySchema, readOnly: props.readOnly, renderChild: props.renderChild, schema: schema2, children: props.children }), $[0] = legacySchema, $[1] = props.attributes, $[2] = props.children, $[3] = props.element, $[4] = props.readOnly, $[5] = props.renderChild, $[6] = schema2, $[7] = t02) : t02 = $[7], t02;
|
|
@@ -1028,10 +1028,10 @@ function RenderElement(props) {
|
|
|
1028
1028
|
let t1;
|
|
1029
1029
|
return $[25] !== block || $[26] !== legacySchema || $[27] !== props.attributes || $[28] !== props.children || $[29] !== props.element || $[30] !== props.readOnly || $[31] !== props.renderBlock || $[32] !== schema2 ? (t1 = /* @__PURE__ */ jsxRuntime.jsx(RenderBlockObject, { attributes: props.attributes, blockObject: block, element: props.element, legacySchema, readOnly: props.readOnly, renderBlock: props.renderBlock, schema: schema2, children: props.children }), $[25] = block, $[26] = legacySchema, $[27] = props.attributes, $[28] = props.children, $[29] = props.element, $[30] = props.readOnly, $[31] = props.renderBlock, $[32] = schema2, $[33] = t1) : t1 = $[33], t1;
|
|
1030
1030
|
}
|
|
1031
|
-
function _temp2(s_0) {
|
|
1031
|
+
function _temp2$1(s_0) {
|
|
1032
1032
|
return s_0.context.getLegacySchema();
|
|
1033
1033
|
}
|
|
1034
|
-
function _temp$
|
|
1034
|
+
function _temp$2(s) {
|
|
1035
1035
|
return s.context.schema;
|
|
1036
1036
|
}
|
|
1037
1037
|
const PortableTextEditorContext = React.createContext(null), usePortableTextEditor = () => {
|
|
@@ -10853,7 +10853,7 @@ const PLACEHOLDER_STYLE = {
|
|
|
10853
10853
|
right: 0
|
|
10854
10854
|
};
|
|
10855
10855
|
function RenderLeaf(props) {
|
|
10856
|
-
const $ = reactCompilerRuntime.c(12), editorActor = React.useContext(EditorActorContext), schema2 = react.useSelector(editorActor, _temp);
|
|
10856
|
+
const $ = reactCompilerRuntime.c(12), editorActor = React.useContext(EditorActorContext), schema2 = react.useSelector(editorActor, _temp$1);
|
|
10857
10857
|
if (props.leaf._type !== schema2.span.name)
|
|
10858
10858
|
return props.children;
|
|
10859
10859
|
let t0;
|
|
@@ -10879,7 +10879,7 @@ function RenderLeaf(props) {
|
|
|
10879
10879
|
}
|
|
10880
10880
|
return renderedSpan;
|
|
10881
10881
|
}
|
|
10882
|
-
function _temp(s) {
|
|
10882
|
+
function _temp$1(s) {
|
|
10883
10883
|
return s.context.schema;
|
|
10884
10884
|
}
|
|
10885
10885
|
function RenderText(props) {
|
|
@@ -11344,7 +11344,9 @@ function createDecorate(schema2, slateEditor) {
|
|
|
11344
11344
|
};
|
|
11345
11345
|
}
|
|
11346
11346
|
const debug = debugWithName("component:Editable"), PortableTextEditable = React.forwardRef(function(props, forwardedRef) {
|
|
11347
|
-
const
|
|
11347
|
+
const $ = reactCompilerRuntime.c(172);
|
|
11348
|
+
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;
|
|
11349
|
+
$[0] !== props ? ({
|
|
11348
11350
|
hotkeys,
|
|
11349
11351
|
onBlur,
|
|
11350
11352
|
onFocus,
|
|
@@ -11372,33 +11374,53 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11372
11374
|
scrollSelectionIntoView,
|
|
11373
11375
|
spellCheck,
|
|
11374
11376
|
...restProps
|
|
11375
|
-
} = props,
|
|
11376
|
-
React.
|
|
11377
|
-
|
|
11378
|
-
|
|
11379
|
-
|
|
11377
|
+
} = 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]);
|
|
11378
|
+
const portableTextEditor = usePortableTextEditor(), [hasInvalidValue, setHasInvalidValue] = React.useState(!1), editorActor = React.useContext(EditorActorContext), relayActor = React.useContext(RelayActorContext), readOnly = react.useSelector(editorActor, _temp), slateEditor = slateReact.useSlate();
|
|
11379
|
+
let t0;
|
|
11380
|
+
$[28] !== rangeDecorations ? (t0 = rangeDecorations ?? [], $[28] = rangeDecorations, $[29] = t0) : t0 = $[29];
|
|
11381
|
+
let t1;
|
|
11382
|
+
$[30] !== editorActor ? (t1 = editorActor.getSnapshot(), $[30] = editorActor, $[31] = t1) : t1 = $[31];
|
|
11383
|
+
const t2 = !editorActor.getSnapshot().matches({
|
|
11384
|
+
setup: "setting up"
|
|
11385
|
+
});
|
|
11386
|
+
let t3;
|
|
11387
|
+
$[32] !== readOnly || $[33] !== slateEditor || $[34] !== t0 || $[35] !== t1.context.schema || $[36] !== t2 ? (t3 = {
|
|
11380
11388
|
input: {
|
|
11381
|
-
rangeDecorations:
|
|
11389
|
+
rangeDecorations: t0,
|
|
11382
11390
|
readOnly,
|
|
11383
|
-
schema:
|
|
11391
|
+
schema: t1.context.schema,
|
|
11384
11392
|
slateEditor,
|
|
11385
|
-
skipSetup:
|
|
11386
|
-
setup: "setting up"
|
|
11387
|
-
})
|
|
11393
|
+
skipSetup: t2
|
|
11388
11394
|
}
|
|
11389
|
-
}
|
|
11390
|
-
|
|
11395
|
+
}, $[32] = readOnly, $[33] = slateEditor, $[34] = t0, $[35] = t1.context.schema, $[36] = t2, $[37] = t3) : t3 = $[37];
|
|
11396
|
+
const rangeDecorationsActor = react.useActorRef(rangeDecorationsMachine, t3), decorate = react.useSelector(rangeDecorationsActor, _temp2);
|
|
11397
|
+
let t4, t5;
|
|
11398
|
+
$[38] !== rangeDecorationsActor || $[39] !== readOnly ? (t4 = () => {
|
|
11391
11399
|
rangeDecorationsActor.send({
|
|
11392
11400
|
type: "update read only",
|
|
11393
11401
|
readOnly
|
|
11394
11402
|
});
|
|
11395
|
-
}, [rangeDecorationsActor, readOnly]), React.useEffect(
|
|
11403
|
+
}, t5 = [rangeDecorationsActor, readOnly], $[38] = rangeDecorationsActor, $[39] = readOnly, $[40] = t4, $[41] = t5) : (t4 = $[40], t5 = $[41]), React.useEffect(t4, t5);
|
|
11404
|
+
let t6, t7;
|
|
11405
|
+
$[42] !== rangeDecorations || $[43] !== rangeDecorationsActor ? (t6 = () => {
|
|
11396
11406
|
rangeDecorationsActor.send({
|
|
11397
11407
|
type: "range decorations updated",
|
|
11398
11408
|
rangeDecorations: rangeDecorations ?? []
|
|
11399
11409
|
});
|
|
11400
|
-
}, [rangeDecorationsActor, rangeDecorations]
|
|
11401
|
-
|
|
11410
|
+
}, t7 = [rangeDecorationsActor, rangeDecorations], $[42] = rangeDecorations, $[43] = rangeDecorationsActor, $[44] = t6, $[45] = t7) : (t6 = $[44], t7 = $[45]), React.useEffect(t6, t7);
|
|
11411
|
+
bb0: {
|
|
11412
|
+
if (readOnly)
|
|
11413
|
+
break bb0;
|
|
11414
|
+
createWithHotkeys(editorActor, portableTextEditor, hotkeys)(slateEditor);
|
|
11415
|
+
}
|
|
11416
|
+
let t9;
|
|
11417
|
+
$[46] !== readOnly || $[47] !== renderBlock || $[48] !== renderChild || $[49] !== renderListItem || $[50] !== renderStyle || $[51] !== spellCheck ? (t9 = (eProps) => /* @__PURE__ */ jsxRuntime.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];
|
|
11418
|
+
const renderElement = t9;
|
|
11419
|
+
let t10;
|
|
11420
|
+
$[53] !== readOnly || $[54] !== renderAnnotation || $[55] !== renderChild || $[56] !== renderDecorator || $[57] !== renderPlaceholder ? (t10 = (leafProps) => /* @__PURE__ */ jsxRuntime.jsx(RenderLeaf, { ...leafProps, readOnly, renderAnnotation, renderChild, renderDecorator, renderPlaceholder }), $[53] = readOnly, $[54] = renderAnnotation, $[55] = renderChild, $[56] = renderDecorator, $[57] = renderPlaceholder, $[58] = t10) : t10 = $[58];
|
|
11421
|
+
const renderLeaf = t10, renderText = _temp3;
|
|
11422
|
+
let t11;
|
|
11423
|
+
$[59] !== editorActor || $[60] !== propsSelection || $[61] !== slateEditor ? (t11 = () => {
|
|
11402
11424
|
if (propsSelection) {
|
|
11403
11425
|
debug(`Selection from props ${JSON.stringify(propsSelection)}`);
|
|
11404
11426
|
const normalizedSelection = normalizeSelection(propsSelection, fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name));
|
|
@@ -11412,14 +11434,16 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11412
11434
|
},
|
|
11413
11435
|
blockIndexMap: slateEditor.blockIndexMap
|
|
11414
11436
|
});
|
|
11415
|
-
slateRange && (slate.Transforms.select(slateEditor, slateRange), slateEditor.operations.some(
|
|
11437
|
+
slateRange && (slate.Transforms.select(slateEditor, slateRange), slateEditor.operations.some(_temp4) || editorActor.send({
|
|
11416
11438
|
type: "update selection",
|
|
11417
11439
|
selection: normalizedSelection
|
|
11418
11440
|
}), slateEditor.onChange());
|
|
11419
11441
|
}
|
|
11420
11442
|
}
|
|
11421
|
-
}, [editorActor, propsSelection, slateEditor]);
|
|
11422
|
-
|
|
11443
|
+
}, $[59] = editorActor, $[60] = propsSelection, $[61] = slateEditor, $[62] = t11) : t11 = $[62];
|
|
11444
|
+
const restoreSelectionFromProps = t11;
|
|
11445
|
+
let t12, t13;
|
|
11446
|
+
$[63] !== editorActor || $[64] !== rangeDecorationsActor || $[65] !== restoreSelectionFromProps ? (t12 = () => {
|
|
11423
11447
|
const onReady = editorActor.on("ready", () => {
|
|
11424
11448
|
rangeDecorationsActor.send({
|
|
11425
11449
|
type: "ready"
|
|
@@ -11432,10 +11456,13 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11432
11456
|
return () => {
|
|
11433
11457
|
onReady.unsubscribe(), onInvalidValue.unsubscribe(), onValueChanged.unsubscribe();
|
|
11434
11458
|
};
|
|
11435
|
-
}, [rangeDecorationsActor, editorActor, restoreSelectionFromProps]), React.useEffect(
|
|
11459
|
+
}, t13 = [rangeDecorationsActor, editorActor, restoreSelectionFromProps], $[63] = editorActor, $[64] = rangeDecorationsActor, $[65] = restoreSelectionFromProps, $[66] = t12, $[67] = t13) : (t12 = $[66], t13 = $[67]), React.useEffect(t12, t13);
|
|
11460
|
+
let t14, t15;
|
|
11461
|
+
$[68] !== hasInvalidValue || $[69] !== propsSelection || $[70] !== restoreSelectionFromProps ? (t14 = () => {
|
|
11436
11462
|
propsSelection && !hasInvalidValue && restoreSelectionFromProps();
|
|
11437
|
-
}, [hasInvalidValue, propsSelection, restoreSelectionFromProps]);
|
|
11438
|
-
|
|
11463
|
+
}, t15 = [hasInvalidValue, propsSelection, restoreSelectionFromProps], $[68] = hasInvalidValue, $[69] = propsSelection, $[70] = restoreSelectionFromProps, $[71] = t14, $[72] = t15) : (t14 = $[71], t15 = $[72]), React.useEffect(t14, t15);
|
|
11464
|
+
let t16;
|
|
11465
|
+
$[73] !== editorActor || $[74] !== onCopy || $[75] !== slateEditor ? (t16 = (event) => {
|
|
11439
11466
|
if (onCopy)
|
|
11440
11467
|
onCopy(event) !== void 0 && event.preventDefault();
|
|
11441
11468
|
else if (event.nativeEvent.clipboardData) {
|
|
@@ -11464,7 +11491,10 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11464
11491
|
nativeEvent: event
|
|
11465
11492
|
});
|
|
11466
11493
|
}
|
|
11467
|
-
}, [
|
|
11494
|
+
}, $[73] = editorActor, $[74] = onCopy, $[75] = slateEditor, $[76] = t16) : t16 = $[76];
|
|
11495
|
+
const handleCopy = t16;
|
|
11496
|
+
let t17;
|
|
11497
|
+
$[77] !== editorActor || $[78] !== onCut || $[79] !== slateEditor ? (t17 = (event_0) => {
|
|
11468
11498
|
if (onCut)
|
|
11469
11499
|
onCut(event_0) !== void 0 && event_0.preventDefault();
|
|
11470
11500
|
else if (event_0.nativeEvent.clipboardData) {
|
|
@@ -11489,7 +11519,10 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11489
11519
|
nativeEvent: event_0
|
|
11490
11520
|
});
|
|
11491
11521
|
}
|
|
11492
|
-
}, [
|
|
11522
|
+
}, $[77] = editorActor, $[78] = onCut, $[79] = slateEditor, $[80] = t17) : t17 = $[80];
|
|
11523
|
+
const handleCut = t17;
|
|
11524
|
+
let t18;
|
|
11525
|
+
$[81] !== editorActor || $[82] !== onPaste || $[83] !== portableTextEditor || $[84] !== relayActor || $[85] !== slateEditor ? (t18 = (event_1) => {
|
|
11493
11526
|
const value = fromSlateValue(slateEditor.children, editorActor.getSnapshot().context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(slateEditor)), path = (slateEditor.selection ? slateRangeToSelection({
|
|
11494
11527
|
schema: editorActor.getSnapshot().context.schema,
|
|
11495
11528
|
editor: slateEditor,
|
|
@@ -11525,26 +11558,27 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11525
11558
|
editor: slateEditor,
|
|
11526
11559
|
nativeEvent: event_1
|
|
11527
11560
|
});
|
|
11528
|
-
} else
|
|
11529
|
-
|
|
11530
|
-
|
|
11531
|
-
|
|
11532
|
-
|
|
11533
|
-
|
|
11534
|
-
|
|
11535
|
-
|
|
11536
|
-
|
|
11537
|
-
|
|
11538
|
-
|
|
11539
|
-
|
|
11540
|
-
|
|
11541
|
-
|
|
11542
|
-
|
|
11543
|
-
|
|
11544
|
-
|
|
11545
|
-
|
|
11546
|
-
|
|
11547
|
-
|
|
11561
|
+
} else
|
|
11562
|
+
result_1.insert ? editorActor.send({
|
|
11563
|
+
type: "behavior event",
|
|
11564
|
+
behaviorEvent: {
|
|
11565
|
+
type: "insert.blocks",
|
|
11566
|
+
blocks: util_sliceBlocks.parseBlocks({
|
|
11567
|
+
context: {
|
|
11568
|
+
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
11569
|
+
schema: editorActor.getSnapshot().context.schema
|
|
11570
|
+
},
|
|
11571
|
+
blocks: result_1.insert,
|
|
11572
|
+
options: {
|
|
11573
|
+
refreshKeys: !1,
|
|
11574
|
+
validateFields: !1
|
|
11575
|
+
}
|
|
11576
|
+
}),
|
|
11577
|
+
placement: "auto"
|
|
11578
|
+
},
|
|
11579
|
+
editor: slateEditor
|
|
11580
|
+
}) : console.warn("Your onPaste function returned something unexpected:", result_1);
|
|
11581
|
+
}).catch(_temp5).finally(() => {
|
|
11548
11582
|
relayActor.send({
|
|
11549
11583
|
type: "done loading"
|
|
11550
11584
|
});
|
|
@@ -11572,12 +11606,18 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11572
11606
|
});
|
|
11573
11607
|
}
|
|
11574
11608
|
debug("No result from custom paste handler, pasting normally");
|
|
11575
|
-
}, [editorActor, onPaste, portableTextEditor, relayActor, slateEditor
|
|
11609
|
+
}, $[81] = editorActor, $[82] = onPaste, $[83] = portableTextEditor, $[84] = relayActor, $[85] = slateEditor, $[86] = t18) : t18 = $[86];
|
|
11610
|
+
const handlePaste = t18;
|
|
11611
|
+
let t19;
|
|
11612
|
+
$[87] !== editorActor || $[88] !== onFocus || $[89] !== relayActor || $[90] !== slateEditor ? (t19 = (event_2) => {
|
|
11576
11613
|
onFocus && onFocus(event_2), event_2.isDefaultPrevented() || (relayActor.send({
|
|
11577
11614
|
type: "focused",
|
|
11578
11615
|
event: event_2
|
|
11579
11616
|
}), !slateEditor.selection && isEqualToEmptyEditor(slateEditor.children, editorActor.getSnapshot().context.schema) && (slate.Transforms.select(slateEditor, slate.Editor.start(slateEditor, [])), slateEditor.onChange()));
|
|
11580
|
-
}, [editorActor, onFocus, relayActor, slateEditor
|
|
11617
|
+
}, $[87] = editorActor, $[88] = onFocus, $[89] = relayActor, $[90] = slateEditor, $[91] = t19) : t19 = $[91];
|
|
11618
|
+
const handleOnFocus = t19;
|
|
11619
|
+
let t20;
|
|
11620
|
+
$[92] !== editorActor || $[93] !== onClick || $[94] !== slateEditor ? (t20 = (event_3) => {
|
|
11581
11621
|
if (onClick && onClick(event_3), event_3.isDefaultPrevented() || event_3.isPropagationStopped())
|
|
11582
11622
|
return;
|
|
11583
11623
|
const position_3 = getEventPosition({
|
|
@@ -11594,47 +11634,23 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11594
11634
|
editor: slateEditor,
|
|
11595
11635
|
nativeEvent: event_3
|
|
11596
11636
|
});
|
|
11597
|
-
}, [
|
|
11637
|
+
}, $[92] = editorActor, $[93] = onClick, $[94] = slateEditor, $[95] = t20) : t20 = $[95];
|
|
11638
|
+
const handleClick = t20;
|
|
11639
|
+
let t21;
|
|
11640
|
+
$[96] !== onBlur || $[97] !== relayActor ? (t21 = (event_4) => {
|
|
11598
11641
|
onBlur && onBlur(event_4), event_4.isPropagationStopped() || relayActor.send({
|
|
11599
11642
|
type: "blurred",
|
|
11600
11643
|
event: event_4
|
|
11601
11644
|
});
|
|
11602
|
-
}, [
|
|
11645
|
+
}, $[96] = onBlur, $[97] = relayActor, $[98] = t21) : t21 = $[98];
|
|
11646
|
+
const handleOnBlur = t21;
|
|
11647
|
+
let t22;
|
|
11648
|
+
$[99] !== onBeforeInput ? (t22 = (event_5) => {
|
|
11603
11649
|
onBeforeInput && onBeforeInput(event_5);
|
|
11604
|
-
}, [onBeforeInput
|
|
11605
|
-
|
|
11606
|
-
|
|
11607
|
-
|
|
11608
|
-
activeElement
|
|
11609
|
-
} = root;
|
|
11610
|
-
if (ref.current !== activeElement)
|
|
11611
|
-
return;
|
|
11612
|
-
const domSelection = slateReact.ReactEditor.getWindow(slateEditor).getSelection();
|
|
11613
|
-
if (!domSelection || domSelection.rangeCount === 0)
|
|
11614
|
-
return;
|
|
11615
|
-
const existingDOMRange = domSelection.getRangeAt(0);
|
|
11616
|
-
try {
|
|
11617
|
-
const newDOMRange = slateReact.ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
|
|
11618
|
-
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
11619
|
-
} catch {
|
|
11620
|
-
debug("Could not resolve selection, selecting top document"), slate.Transforms.deselect(slateEditor), slateEditor.children.length > 0 && slate.Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
|
|
11621
|
-
}
|
|
11622
|
-
}, [ref, slateEditor]);
|
|
11623
|
-
React.useEffect(() => {
|
|
11624
|
-
if (editableElement) {
|
|
11625
|
-
const mutationObserver = new MutationObserver(validateSelection);
|
|
11626
|
-
return mutationObserver.observe(editableElement, {
|
|
11627
|
-
attributeOldValue: !1,
|
|
11628
|
-
attributes: !1,
|
|
11629
|
-
characterData: !1,
|
|
11630
|
-
childList: !0,
|
|
11631
|
-
subtree: !0
|
|
11632
|
-
}), () => {
|
|
11633
|
-
mutationObserver.disconnect();
|
|
11634
|
-
};
|
|
11635
|
-
}
|
|
11636
|
-
}, [validateSelection, editableElement]);
|
|
11637
|
-
const handleKeyDown = React.useCallback((event_6) => {
|
|
11650
|
+
}, $[99] = onBeforeInput, $[100] = t22) : t22 = $[100];
|
|
11651
|
+
const handleOnBeforeInput = t22;
|
|
11652
|
+
let t23;
|
|
11653
|
+
$[101] !== editorActor || $[102] !== props || $[103] !== slateEditor ? (t23 = (event_6) => {
|
|
11638
11654
|
props.onKeyDown && props.onKeyDown(event_6), event_6.isDefaultPrevented() || slateEditor.pteWithHotKeys(event_6), event_6.isDefaultPrevented() || editorActor.send({
|
|
11639
11655
|
type: "behavior event",
|
|
11640
11656
|
behaviorEvent: {
|
|
@@ -11651,7 +11667,10 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11651
11667
|
editor: slateEditor,
|
|
11652
11668
|
nativeEvent: event_6
|
|
11653
11669
|
});
|
|
11654
|
-
}, [
|
|
11670
|
+
}, $[101] = editorActor, $[102] = props, $[103] = slateEditor, $[104] = t23) : t23 = $[104];
|
|
11671
|
+
const handleKeyDown = t23;
|
|
11672
|
+
let t24;
|
|
11673
|
+
$[105] !== editorActor || $[106] !== props || $[107] !== slateEditor ? (t24 = (event_7) => {
|
|
11655
11674
|
props.onKeyUp && props.onKeyUp(event_7), event_7.isDefaultPrevented() || editorActor.send({
|
|
11656
11675
|
type: "behavior event",
|
|
11657
11676
|
behaviorEvent: {
|
|
@@ -11668,16 +11687,27 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11668
11687
|
editor: slateEditor,
|
|
11669
11688
|
nativeEvent: event_7
|
|
11670
11689
|
});
|
|
11671
|
-
}, [
|
|
11672
|
-
|
|
11673
|
-
|
|
11674
|
-
|
|
11675
|
-
|
|
11676
|
-
|
|
11677
|
-
|
|
11678
|
-
|
|
11679
|
-
|
|
11680
|
-
|
|
11690
|
+
}, $[105] = editorActor, $[106] = props, $[107] = slateEditor, $[108] = t24) : t24 = $[108];
|
|
11691
|
+
const handleKeyUp = t24;
|
|
11692
|
+
let t25;
|
|
11693
|
+
bb1: {
|
|
11694
|
+
if (scrollSelectionIntoView === void 0) {
|
|
11695
|
+
t25 = void 0;
|
|
11696
|
+
break bb1;
|
|
11697
|
+
}
|
|
11698
|
+
if (scrollSelectionIntoView === null) {
|
|
11699
|
+
t25 = noop__default.default;
|
|
11700
|
+
break bb1;
|
|
11701
|
+
}
|
|
11702
|
+
let t262;
|
|
11703
|
+
$[109] !== portableTextEditor || $[110] !== scrollSelectionIntoView ? (t262 = (_editor, domRange) => {
|
|
11704
|
+
scrollSelectionIntoView(portableTextEditor, domRange);
|
|
11705
|
+
}, $[109] = portableTextEditor, $[110] = scrollSelectionIntoView, $[111] = t262) : t262 = $[111], t25 = t262;
|
|
11706
|
+
}
|
|
11707
|
+
const scrollSelectionIntoViewToSlate = t25;
|
|
11708
|
+
let t26, t27;
|
|
11709
|
+
$[112] !== editorActor || $[113] !== slateEditor ? (t26 = () => {
|
|
11710
|
+
const window2 = slateReact.ReactEditor.getWindow(slateEditor), onDragEnd_0 = () => {
|
|
11681
11711
|
editorActor.send({
|
|
11682
11712
|
type: "dragend"
|
|
11683
11713
|
});
|
|
@@ -11686,11 +11716,12 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11686
11716
|
type: "drop"
|
|
11687
11717
|
});
|
|
11688
11718
|
};
|
|
11689
|
-
return
|
|
11690
|
-
|
|
11719
|
+
return window2.document.addEventListener("dragend", onDragEnd_0), window2.document.addEventListener("drop", onDrop_0), () => {
|
|
11720
|
+
window2.document.removeEventListener("dragend", onDragEnd_0), window2.document.removeEventListener("drop", onDrop_0);
|
|
11691
11721
|
};
|
|
11692
|
-
}, [slateEditor, editorActor]);
|
|
11693
|
-
|
|
11722
|
+
}, t27 = [slateEditor, editorActor], $[112] = editorActor, $[113] = slateEditor, $[114] = t26, $[115] = t27) : (t26 = $[114], t27 = $[115]), React.useEffect(t26, t27);
|
|
11723
|
+
let t28;
|
|
11724
|
+
$[116] !== editorActor || $[117] !== onDragStart || $[118] !== slateEditor ? (t28 = (event_8) => {
|
|
11694
11725
|
if (onDragStart?.(event_8), event_8.isDefaultPrevented() || event_8.isPropagationStopped())
|
|
11695
11726
|
return;
|
|
11696
11727
|
const position_4 = getEventPosition({
|
|
@@ -11718,7 +11749,10 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11718
11749
|
},
|
|
11719
11750
|
editor: slateEditor
|
|
11720
11751
|
}), !0;
|
|
11721
|
-
}, [
|
|
11752
|
+
}, $[116] = editorActor, $[117] = onDragStart, $[118] = slateEditor, $[119] = t28) : t28 = $[119];
|
|
11753
|
+
const handleDragStart = t28;
|
|
11754
|
+
let t29;
|
|
11755
|
+
$[120] !== editorActor || $[121] !== onDrag || $[122] !== slateEditor ? (t29 = (event_9) => {
|
|
11722
11756
|
if (onDrag?.(event_9), !(event_9.isDefaultPrevented() || event_9.isPropagationStopped() || !getEventPosition({
|
|
11723
11757
|
editorActor,
|
|
11724
11758
|
slateEditor,
|
|
@@ -11734,7 +11768,10 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11734
11768
|
},
|
|
11735
11769
|
editor: slateEditor
|
|
11736
11770
|
}), !0;
|
|
11737
|
-
}, [
|
|
11771
|
+
}, $[120] = editorActor, $[121] = onDrag, $[122] = slateEditor, $[123] = t29) : t29 = $[123];
|
|
11772
|
+
const handleDrag = t29;
|
|
11773
|
+
let t30;
|
|
11774
|
+
$[124] !== editorActor || $[125] !== onDragEnd || $[126] !== slateEditor ? (t30 = (event_10) => {
|
|
11738
11775
|
if (onDragEnd?.(event_10), !(event_10.isDefaultPrevented() || event_10.isPropagationStopped()))
|
|
11739
11776
|
return editorActor.send({
|
|
11740
11777
|
type: "behavior event",
|
|
@@ -11746,7 +11783,10 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11746
11783
|
},
|
|
11747
11784
|
editor: slateEditor
|
|
11748
11785
|
}), !0;
|
|
11749
|
-
}, [
|
|
11786
|
+
}, $[124] = editorActor, $[125] = onDragEnd, $[126] = slateEditor, $[127] = t30) : t30 = $[127];
|
|
11787
|
+
const handleDragEnd = t30;
|
|
11788
|
+
let t31;
|
|
11789
|
+
$[128] !== editorActor || $[129] !== onDragEnter || $[130] !== slateEditor ? (t31 = (event_11) => {
|
|
11750
11790
|
if (onDragEnter?.(event_11), event_11.isDefaultPrevented() || event_11.isPropagationStopped())
|
|
11751
11791
|
return;
|
|
11752
11792
|
const position_6 = getEventPosition({
|
|
@@ -11766,7 +11806,10 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11766
11806
|
},
|
|
11767
11807
|
editor: slateEditor
|
|
11768
11808
|
}), !0;
|
|
11769
|
-
}, [
|
|
11809
|
+
}, $[128] = editorActor, $[129] = onDragEnter, $[130] = slateEditor, $[131] = t31) : t31 = $[131];
|
|
11810
|
+
const handleDragEnter = t31;
|
|
11811
|
+
let t32;
|
|
11812
|
+
$[132] !== editorActor || $[133] !== onDragOver || $[134] !== slateEditor ? (t32 = (event_12) => {
|
|
11770
11813
|
if (onDragOver?.(event_12), event_12.isDefaultPrevented() || event_12.isPropagationStopped())
|
|
11771
11814
|
return;
|
|
11772
11815
|
const position_7 = getEventPosition({
|
|
@@ -11788,7 +11831,10 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11788
11831
|
editor: slateEditor,
|
|
11789
11832
|
nativeEvent: event_12
|
|
11790
11833
|
}), !0;
|
|
11791
|
-
}, [
|
|
11834
|
+
}, $[132] = editorActor, $[133] = onDragOver, $[134] = slateEditor, $[135] = t32) : t32 = $[135];
|
|
11835
|
+
const handleDragOver = t32;
|
|
11836
|
+
let t33;
|
|
11837
|
+
$[136] !== editorActor || $[137] !== onDrop || $[138] !== slateEditor ? (t33 = (event_13) => {
|
|
11792
11838
|
if (onDrop?.(event_13), event_13.isDefaultPrevented() || event_13.isPropagationStopped())
|
|
11793
11839
|
return;
|
|
11794
11840
|
const position_8 = getEventPosition({
|
|
@@ -11813,7 +11859,10 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11813
11859
|
editor: slateEditor,
|
|
11814
11860
|
nativeEvent: event_13
|
|
11815
11861
|
}), !0;
|
|
11816
|
-
}, [
|
|
11862
|
+
}, $[136] = editorActor, $[137] = onDrop, $[138] = slateEditor, $[139] = t33) : t33 = $[139];
|
|
11863
|
+
const handleDrop = t33;
|
|
11864
|
+
let t34;
|
|
11865
|
+
$[140] !== editorActor || $[141] !== onDragLeave || $[142] !== slateEditor ? (t34 = (event_14) => {
|
|
11817
11866
|
if (onDragLeave?.(event_14), !(event_14.isDefaultPrevented() || event_14.isPropagationStopped() || !getEventPosition({
|
|
11818
11867
|
editorActor,
|
|
11819
11868
|
slateEditor,
|
|
@@ -11829,41 +11878,66 @@ const debug = debugWithName("component:Editable"), PortableTextEditable = React.
|
|
|
11829
11878
|
},
|
|
11830
11879
|
editor: slateEditor
|
|
11831
11880
|
}), !0;
|
|
11832
|
-
}, [onDragLeave,
|
|
11833
|
-
|
|
11834
|
-
|
|
11835
|
-
|
|
11836
|
-
|
|
11837
|
-
|
|
11838
|
-
|
|
11839
|
-
|
|
11840
|
-
|
|
11841
|
-
|
|
11842
|
-
|
|
11843
|
-
|
|
11844
|
-
|
|
11845
|
-
|
|
11846
|
-
|
|
11847
|
-
|
|
11848
|
-
|
|
11849
|
-
onDragEnter: handleDragEnter,
|
|
11850
|
-
onDragOver: handleDragOver,
|
|
11851
|
-
onDrop: handleDrop,
|
|
11852
|
-
onDragLeave: handleDragLeave,
|
|
11853
|
-
onFocus: handleOnFocus,
|
|
11854
|
-
onKeyDown: handleKeyDown,
|
|
11855
|
-
onKeyUp: handleKeyUp,
|
|
11856
|
-
onPaste: handlePaste,
|
|
11857
|
-
readOnly,
|
|
11858
|
-
renderPlaceholder: void 0,
|
|
11859
|
-
renderElement,
|
|
11860
|
-
renderLeaf,
|
|
11861
|
-
renderText,
|
|
11862
|
-
scrollSelectionIntoView: scrollSelectionIntoViewToSlate
|
|
11881
|
+
}, $[140] = editorActor, $[141] = onDragLeave, $[142] = slateEditor, $[143] = t34) : t34 = $[143];
|
|
11882
|
+
const handleDragLeave = t34;
|
|
11883
|
+
let t35;
|
|
11884
|
+
$[144] !== forwardedRef || $[145] !== slateEditor ? (t35 = (node) => {
|
|
11885
|
+
if (typeof forwardedRef == "function" ? forwardedRef(node) : forwardedRef && (forwardedRef.current = node), node) {
|
|
11886
|
+
const mutationObserver = new MutationObserver(() => {
|
|
11887
|
+
validateSelection(slateEditor, node);
|
|
11888
|
+
});
|
|
11889
|
+
return mutationObserver.observe(node, {
|
|
11890
|
+
attributeOldValue: !1,
|
|
11891
|
+
attributes: !1,
|
|
11892
|
+
characterData: !1,
|
|
11893
|
+
childList: !0,
|
|
11894
|
+
subtree: !0
|
|
11895
|
+
}), () => {
|
|
11896
|
+
mutationObserver.disconnect();
|
|
11897
|
+
};
|
|
11863
11898
|
}
|
|
11864
|
-
) :
|
|
11899
|
+
}, $[144] = forwardedRef, $[145] = slateEditor, $[146] = t35) : t35 = $[146];
|
|
11900
|
+
const callbackRef = t35;
|
|
11901
|
+
if (!portableTextEditor)
|
|
11902
|
+
return null;
|
|
11903
|
+
let t36;
|
|
11904
|
+
return $[147] !== callbackRef || $[148] !== decorate || $[149] !== handleClick || $[150] !== handleCopy || $[151] !== handleCut || $[152] !== handleDrag || $[153] !== handleDragEnd || $[154] !== handleDragEnter || $[155] !== handleDragLeave || $[156] !== handleDragOver || $[157] !== handleDragStart || $[158] !== handleDrop || $[159] !== handleKeyDown || $[160] !== handleKeyUp || $[161] !== handleOnBeforeInput || $[162] !== handleOnBlur || $[163] !== handleOnFocus || $[164] !== handlePaste || $[165] !== hasInvalidValue || $[166] !== readOnly || $[167] !== renderElement || $[168] !== renderLeaf || $[169] !== restProps || $[170] !== scrollSelectionIntoViewToSlate ? (t36 = 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 }), $[147] = callbackRef, $[148] = decorate, $[149] = handleClick, $[150] = handleCopy, $[151] = handleCut, $[152] = handleDrag, $[153] = handleDragEnd, $[154] = handleDragEnter, $[155] = handleDragLeave, $[156] = handleDragOver, $[157] = handleDragStart, $[158] = handleDrop, $[159] = handleKeyDown, $[160] = handleKeyUp, $[161] = handleOnBeforeInput, $[162] = handleOnBlur, $[163] = handleOnFocus, $[164] = handlePaste, $[165] = hasInvalidValue, $[166] = readOnly, $[167] = renderElement, $[168] = renderLeaf, $[169] = restProps, $[170] = scrollSelectionIntoViewToSlate, $[171] = t36) : t36 = $[171], t36;
|
|
11865
11905
|
});
|
|
11866
11906
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
11907
|
+
function validateSelection(slateEditor, activeElement) {
|
|
11908
|
+
if (!slateEditor.selection)
|
|
11909
|
+
return;
|
|
11910
|
+
const root = slateReact.ReactEditor.findDocumentOrShadowRoot(slateEditor);
|
|
11911
|
+
if (activeElement !== root.activeElement)
|
|
11912
|
+
return;
|
|
11913
|
+
const domSelection = slateReact.ReactEditor.getWindow(slateEditor).getSelection();
|
|
11914
|
+
if (!domSelection || domSelection.rangeCount === 0)
|
|
11915
|
+
return;
|
|
11916
|
+
const existingDOMRange = domSelection.getRangeAt(0);
|
|
11917
|
+
try {
|
|
11918
|
+
const newDOMRange = slateReact.ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
|
|
11919
|
+
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
11920
|
+
} catch {
|
|
11921
|
+
debug("Could not resolve selection, selecting top document"), slate.Transforms.deselect(slateEditor), slateEditor.children.length > 0 && slate.Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
|
|
11922
|
+
}
|
|
11923
|
+
}
|
|
11924
|
+
function _temp(s) {
|
|
11925
|
+
return s.matches({
|
|
11926
|
+
"edit mode": "read only"
|
|
11927
|
+
});
|
|
11928
|
+
}
|
|
11929
|
+
function _temp2(s_0) {
|
|
11930
|
+
return s_0.context.decorate?.fn;
|
|
11931
|
+
}
|
|
11932
|
+
function _temp3(props_0) {
|
|
11933
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RenderText, { ...props_0 });
|
|
11934
|
+
}
|
|
11935
|
+
function _temp4(o) {
|
|
11936
|
+
return o.type === "set_selection";
|
|
11937
|
+
}
|
|
11938
|
+
function _temp5(error) {
|
|
11939
|
+
return console.warn(error), error;
|
|
11940
|
+
}
|
|
11867
11941
|
function useConstant(factory) {
|
|
11868
11942
|
const ref = React__default.default.useRef(null);
|
|
11869
11943
|
return ref.current || (ref.current = {
|