@portabletext/editor 2.12.1 → 2.12.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 +1 -1
- package/lib/_chunks-cjs/selector.is-selecting-entire-blocks.cjs.map +1 -1
- package/lib/_chunks-dts/behavior.types.action.d.cts +9 -9
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +1 -1
- package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +1 -1
- package/lib/index.cjs +88 -106
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +88 -106
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/lib/utils/index.d.cts +2 -2
- package/package.json +8 -8
- package/src/behaviors/behavior.abstract.keyboard.ts +13 -0
- package/src/behaviors/behavior.perform-event.ts +15 -1
- package/src/editor/Editable.tsx +1 -90
- package/src/selectors/selector.get-mark-state.test.ts +76 -0
- package/src/selectors/selector.get-mark-state.ts +1 -1
- package/src/test/gherkin-parameter-types.ts +1 -1
- package/src/test/vitest/step-definitions.tsx +4 -8
package/lib/index.cjs
CHANGED
|
@@ -1705,7 +1705,7 @@ function createDecorate(schema2, slateEditor) {
|
|
|
1705
1705
|
};
|
|
1706
1706
|
}
|
|
1707
1707
|
const RelayActorContext = React.createContext({}), debug$d = debugWithName("component:Editable"), PortableTextEditable = React.forwardRef(function(props, forwardedRef) {
|
|
1708
|
-
const $ = reactCompilerRuntime.c(
|
|
1708
|
+
const $ = reactCompilerRuntime.c(171);
|
|
1709
1709
|
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;
|
|
1710
1710
|
$[0] !== props ? ({
|
|
1711
1711
|
hotkeys,
|
|
@@ -2242,50 +2242,16 @@ const RelayActorContext = React.createContext({}), debug$d = debugWithName("comp
|
|
|
2242
2242
|
}, $[140] = editorActor, $[141] = onDragLeave, $[142] = slateEditor, $[143] = t34) : t34 = $[143];
|
|
2243
2243
|
const handleDragLeave = t34;
|
|
2244
2244
|
let t35;
|
|
2245
|
-
$[144] !== forwardedRef
|
|
2246
|
-
|
|
2247
|
-
|
|
2248
|
-
validateSelection(slateEditor, node);
|
|
2249
|
-
});
|
|
2250
|
-
return mutationObserver.observe(node, {
|
|
2251
|
-
attributeOldValue: !1,
|
|
2252
|
-
attributes: !1,
|
|
2253
|
-
characterData: !1,
|
|
2254
|
-
childList: !0,
|
|
2255
|
-
subtree: !0
|
|
2256
|
-
}), () => {
|
|
2257
|
-
mutationObserver.disconnect();
|
|
2258
|
-
};
|
|
2259
|
-
}
|
|
2260
|
-
}, $[144] = forwardedRef, $[145] = slateEditor, $[146] = t35) : t35 = $[146];
|
|
2245
|
+
$[144] !== forwardedRef ? (t35 = (node) => {
|
|
2246
|
+
typeof forwardedRef == "function" ? forwardedRef(node) : forwardedRef && (forwardedRef.current = node);
|
|
2247
|
+
}, $[144] = forwardedRef, $[145] = t35) : t35 = $[145];
|
|
2261
2248
|
const callbackRef = t35;
|
|
2262
2249
|
if (!portableTextEditor)
|
|
2263
2250
|
return null;
|
|
2264
2251
|
let t36;
|
|
2265
|
-
return $[
|
|
2252
|
+
return $[146] !== callbackRef || $[147] !== decorate || $[148] !== handleClick || $[149] !== handleCopy || $[150] !== handleCut || $[151] !== handleDrag || $[152] !== handleDragEnd || $[153] !== handleDragEnter || $[154] !== handleDragLeave || $[155] !== handleDragOver || $[156] !== handleDragStart || $[157] !== handleDrop || $[158] !== handleKeyDown || $[159] !== handleKeyUp || $[160] !== handleOnBeforeInput || $[161] !== handleOnBlur || $[162] !== handleOnFocus || $[163] !== handlePaste || $[164] !== hasInvalidValue || $[165] !== readOnly || $[166] !== renderElement || $[167] !== renderLeaf || $[168] !== restProps || $[169] !== 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 }), $[146] = callbackRef, $[147] = decorate, $[148] = handleClick, $[149] = handleCopy, $[150] = handleCut, $[151] = handleDrag, $[152] = handleDragEnd, $[153] = handleDragEnter, $[154] = handleDragLeave, $[155] = handleDragOver, $[156] = handleDragStart, $[157] = handleDrop, $[158] = handleKeyDown, $[159] = handleKeyUp, $[160] = handleOnBeforeInput, $[161] = handleOnBlur, $[162] = handleOnFocus, $[163] = handlePaste, $[164] = hasInvalidValue, $[165] = readOnly, $[166] = renderElement, $[167] = renderLeaf, $[168] = restProps, $[169] = scrollSelectionIntoViewToSlate, $[170] = t36) : t36 = $[170], t36;
|
|
2266
2253
|
});
|
|
2267
2254
|
PortableTextEditable.displayName = "ForwardRef(PortableTextEditable)";
|
|
2268
|
-
function validateSelection(slateEditor, activeElement) {
|
|
2269
|
-
if (!slateEditor.selection)
|
|
2270
|
-
return;
|
|
2271
|
-
let root;
|
|
2272
|
-
try {
|
|
2273
|
-
root = slateReact.ReactEditor.findDocumentOrShadowRoot(slateEditor);
|
|
2274
|
-
} catch {
|
|
2275
|
-
}
|
|
2276
|
-
if (!root || activeElement !== root.activeElement)
|
|
2277
|
-
return;
|
|
2278
|
-
const domSelection = slateReact.ReactEditor.getWindow(slateEditor).getSelection();
|
|
2279
|
-
if (!domSelection || domSelection.rangeCount === 0)
|
|
2280
|
-
return;
|
|
2281
|
-
const existingDOMRange = domSelection.getRangeAt(0);
|
|
2282
|
-
try {
|
|
2283
|
-
const newDOMRange = slateReact.ReactEditor.toDOMRange(slateEditor, slateEditor.selection);
|
|
2284
|
-
(newDOMRange.startOffset !== existingDOMRange.startOffset || newDOMRange.endOffset !== existingDOMRange.endOffset) && (debug$d("DOM range out of sync, validating selection"), domSelection?.removeAllRanges(), domSelection.addRange(newDOMRange));
|
|
2285
|
-
} catch {
|
|
2286
|
-
debug$d("Could not resolve selection, selecting top document"), slate.Transforms.deselect(slateEditor), slateEditor.children.length > 0 && slate.Transforms.select(slateEditor, [0, 0]), slateEditor.onChange();
|
|
2287
|
-
}
|
|
2288
|
-
}
|
|
2289
2255
|
function _temp(s) {
|
|
2290
2256
|
return s.matches({
|
|
2291
2257
|
"edit mode": "read only"
|
|
@@ -8710,6 +8676,20 @@ const abstractAnnotationBehaviors = [behaviors_index.defineBehavior({
|
|
|
8710
8676
|
type: "insert.break"
|
|
8711
8677
|
})]]
|
|
8712
8678
|
}),
|
|
8679
|
+
/**
|
|
8680
|
+
* On Firefox, Enter might collapse the selection. To mitigate this, we
|
|
8681
|
+
* `raise` an `insert.break` event manually.
|
|
8682
|
+
*/
|
|
8683
|
+
behaviors_index.defineBehavior({
|
|
8684
|
+
on: "keyboard.keydown",
|
|
8685
|
+
guard: ({
|
|
8686
|
+
snapshot,
|
|
8687
|
+
event
|
|
8688
|
+
}) => defaultKeyboardShortcuts.break.guard(event.originEvent) && selector_isSelectionExpanded.isSelectionExpanded(snapshot),
|
|
8689
|
+
actions: [() => [behaviors_index.raise({
|
|
8690
|
+
type: "insert.break"
|
|
8691
|
+
})]]
|
|
8692
|
+
}),
|
|
8713
8693
|
/**
|
|
8714
8694
|
* On WebKit, Shift+Enter results in an `insertParagraph` input event rather
|
|
8715
8695
|
* than an `insertLineBreak` input event. This Behavior makes sure we catch
|
|
@@ -9459,86 +9439,88 @@ function performEvent({
|
|
|
9459
9439
|
} catch (error) {
|
|
9460
9440
|
console.error(new Error(`Evaluating guard for "${event.type}" failed due to: ${error.message}`));
|
|
9461
9441
|
}
|
|
9462
|
-
if (shouldRun)
|
|
9463
|
-
|
|
9464
|
-
|
|
9465
|
-
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9469
|
-
|
|
9470
|
-
|
|
9471
|
-
|
|
9472
|
-
|
|
9473
|
-
|
|
9474
|
-
|
|
9475
|
-
}
|
|
9476
|
-
|
|
9477
|
-
|
|
9478
|
-
|
|
9479
|
-
|
|
9480
|
-
|
|
9481
|
-
|
|
9482
|
-
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9488
|
-
|
|
9489
|
-
|
|
9490
|
-
|
|
9491
|
-
}
|
|
9492
|
-
continue;
|
|
9493
|
-
}
|
|
9494
|
-
if (action.type === "forward") {
|
|
9495
|
-
const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
|
|
9496
|
-
performEvent({
|
|
9497
|
-
mode: mode === "execute" ? "execute" : "forward",
|
|
9498
|
-
behaviors,
|
|
9499
|
-
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9500
|
-
event: action.event,
|
|
9501
|
-
editor,
|
|
9502
|
-
keyGenerator,
|
|
9503
|
-
schema: schema2,
|
|
9504
|
-
getSnapshot,
|
|
9505
|
-
nativeEvent,
|
|
9506
|
-
sendBack
|
|
9507
|
-
});
|
|
9508
|
-
continue;
|
|
9509
|
-
}
|
|
9510
|
-
if (action.type === "raise") {
|
|
9511
|
-
performEvent({
|
|
9512
|
-
mode: mode === "execute" ? "execute" : "raise",
|
|
9513
|
-
behaviors,
|
|
9514
|
-
remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
|
|
9515
|
-
event: action.event,
|
|
9516
|
-
editor,
|
|
9517
|
-
keyGenerator,
|
|
9518
|
-
schema: schema2,
|
|
9519
|
-
getSnapshot,
|
|
9520
|
-
nativeEvent,
|
|
9521
|
-
sendBack
|
|
9442
|
+
if (!shouldRun)
|
|
9443
|
+
continue;
|
|
9444
|
+
defaultBehaviorOverwritten = !0, eventBehavior.actions.length === 0 && (nativeEventPrevented = !0);
|
|
9445
|
+
let actionSetIndex = -1;
|
|
9446
|
+
for (const actionSet of eventBehavior.actions) {
|
|
9447
|
+
actionSetIndex++;
|
|
9448
|
+
const actionsSnapshot = getSnapshot();
|
|
9449
|
+
let actions = [];
|
|
9450
|
+
try {
|
|
9451
|
+
actions = actionSet({
|
|
9452
|
+
snapshot: actionsSnapshot,
|
|
9453
|
+
event,
|
|
9454
|
+
dom: createEditorDom(sendBack, editor)
|
|
9455
|
+
}, shouldRun);
|
|
9456
|
+
} catch (error) {
|
|
9457
|
+
console.error(new Error(`Evaluating actions for "${event.type}" failed due to: ${error.message}`));
|
|
9458
|
+
}
|
|
9459
|
+
if (actions.length === 0)
|
|
9460
|
+
continue;
|
|
9461
|
+
nativeEventPrevented = actions.some((action) => action.type === "raise" || action.type === "execute") || !actions.some((action) => action.type === "forward");
|
|
9462
|
+
let undoStepCreated = !1;
|
|
9463
|
+
actionSetIndex > 0 && (createUndoStep(editor), undoStepCreated = !0), !undoStepCreated && actions.some((action) => action.type === "execute") && (createUndoStep(editor), undoStepCreated = !0);
|
|
9464
|
+
const actionTypes = actions.map((action) => action.type), uniqueActionTypes = new Set(actionTypes), raiseGroup = actionTypes.length > 1 && uniqueActionTypes.size === 1 && uniqueActionTypes.has("raise"), executeGroup = actionTypes.length > 1 && uniqueActionTypes.size === 1 && uniqueActionTypes.has("execute");
|
|
9465
|
+
withoutNormalizingConditional(editor, () => raiseGroup || executeGroup, () => {
|
|
9466
|
+
for (const action of actions) {
|
|
9467
|
+
if (action.type === "effect") {
|
|
9468
|
+
try {
|
|
9469
|
+
action.effect({
|
|
9470
|
+
send: sendBack
|
|
9522
9471
|
});
|
|
9523
|
-
|
|
9472
|
+
} catch (error) {
|
|
9473
|
+
console.error(new Error(`Executing effect as a result of "${event.type}" failed due to: ${error.message}`));
|
|
9524
9474
|
}
|
|
9475
|
+
continue;
|
|
9476
|
+
}
|
|
9477
|
+
if (action.type === "forward") {
|
|
9478
|
+
const remainingEventBehaviors2 = eventBehaviors.slice(eventBehaviorIndex + 1);
|
|
9525
9479
|
performEvent({
|
|
9526
|
-
mode: "execute",
|
|
9480
|
+
mode: mode === "execute" ? "execute" : "forward",
|
|
9527
9481
|
behaviors,
|
|
9528
|
-
remainingEventBehaviors:
|
|
9482
|
+
remainingEventBehaviors: remainingEventBehaviors2,
|
|
9529
9483
|
event: action.event,
|
|
9530
9484
|
editor,
|
|
9531
9485
|
keyGenerator,
|
|
9532
9486
|
schema: schema2,
|
|
9533
9487
|
getSnapshot,
|
|
9534
|
-
nativeEvent
|
|
9488
|
+
nativeEvent,
|
|
9535
9489
|
sendBack
|
|
9536
9490
|
});
|
|
9491
|
+
continue;
|
|
9537
9492
|
}
|
|
9538
|
-
|
|
9539
|
-
|
|
9540
|
-
|
|
9493
|
+
if (action.type === "raise") {
|
|
9494
|
+
performEvent({
|
|
9495
|
+
mode: mode === "execute" ? "execute" : "raise",
|
|
9496
|
+
behaviors,
|
|
9497
|
+
remainingEventBehaviors: mode === "execute" ? remainingEventBehaviors : behaviors,
|
|
9498
|
+
event: action.event,
|
|
9499
|
+
editor,
|
|
9500
|
+
keyGenerator,
|
|
9501
|
+
schema: schema2,
|
|
9502
|
+
getSnapshot,
|
|
9503
|
+
nativeEvent,
|
|
9504
|
+
sendBack
|
|
9505
|
+
});
|
|
9506
|
+
continue;
|
|
9507
|
+
}
|
|
9508
|
+
performEvent({
|
|
9509
|
+
mode: "execute",
|
|
9510
|
+
behaviors,
|
|
9511
|
+
remainingEventBehaviors: [],
|
|
9512
|
+
event: action.event,
|
|
9513
|
+
editor,
|
|
9514
|
+
keyGenerator,
|
|
9515
|
+
schema: schema2,
|
|
9516
|
+
getSnapshot,
|
|
9517
|
+
nativeEvent: void 0,
|
|
9518
|
+
sendBack
|
|
9519
|
+
});
|
|
9520
|
+
}
|
|
9521
|
+
}), undoStepCreated && clearUndoStep(editor);
|
|
9541
9522
|
}
|
|
9523
|
+
break;
|
|
9542
9524
|
}
|
|
9543
9525
|
!defaultBehaviorOverwritten && isSyntheticBehaviorEvent(event) ? (nativeEvent?.preventDefault(), mode === "send" && clearUndoStep(editor), withPerformingBehaviorOperation(editor, () => {
|
|
9544
9526
|
debug$6(`(execute:${eventCategory(event)})`, JSON.stringify(event, null, 2)), performOperation({
|