@portabletext/editor 1.14.1 → 1.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/index.cjs +45 -44
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +232 -228
- package/lib/index.d.ts +232 -228
- package/lib/index.js +45 -44
- package/lib/index.js.map +1 -1
- package/package.json +19 -19
- package/src/editor/__tests__/PortableTextEditor.test.tsx +6 -6
- package/src/editor/__tests__/RangeDecorations.test.tsx +1 -1
- package/src/editor/__tests__/handleClick.test.tsx +4 -4
- package/src/editor/__tests__/insert-block.test.tsx +3 -3
- package/src/editor/__tests__/pteWarningsSelfSolving.test.tsx +6 -6
- package/src/editor/__tests__/self-solving.test.tsx +1 -1
- package/src/editor/behavior/behavior.actions.ts +2 -34
- package/src/editor/behavior/behavior.types.ts +31 -27
- package/src/editor/components/DraggableBlock.tsx +1 -1
- package/src/editor/components/Element.tsx +8 -2
- package/src/editor/components/Leaf.tsx +1 -1
- package/src/editor/create-editor.ts +18 -29
- package/src/editor/editor-machine.ts +27 -7
- package/src/editor/hooks/useSyncValue.test.tsx +2 -2
- package/src/editor/hooks/useSyncValue.ts +2 -2
- package/src/editor/nodes/DefaultObject.tsx +1 -0
- package/src/editor/plugins/__tests__/withEditableAPIDelete.test.tsx +4 -4
- package/src/editor/plugins/__tests__/withEditableAPIGetFragment.test.tsx +2 -2
- package/src/editor/plugins/__tests__/withEditableAPIInsert.test.tsx +7 -7
- package/src/editor/plugins/__tests__/withEditableAPISelectionsOverlapping.test.tsx +4 -4
- package/src/editor/plugins/__tests__/withPortableTextLists.test.tsx +1 -1
- package/src/editor/plugins/__tests__/withPortableTextMarkModel.test.tsx +9 -9
- package/src/editor/plugins/__tests__/withPortableTextSelections.test.tsx +1 -1
- package/src/editor/plugins/__tests__/withUndoRedo.test.tsx +2 -2
- package/src/index.ts +4 -2
- package/src/types/editor.ts +14 -13
- package/src/utils/__tests__/valueNormalization.test.tsx +1 -1
package/lib/index.cjs
CHANGED
|
@@ -1462,7 +1462,7 @@ const debug$k = debugWithName("components:DraggableBlock"), DraggableBlock = (t0
|
|
|
1462
1462
|
element,
|
|
1463
1463
|
readOnly,
|
|
1464
1464
|
blockRef
|
|
1465
|
-
} = t0, editor = slateReact.useSlateStatic(), dragGhostRef = React.useRef(), [isDragOver, setIsDragOver] = React.useState(!1);
|
|
1465
|
+
} = t0, editor = slateReact.useSlateStatic(), dragGhostRef = React.useRef(void 0), [isDragOver, setIsDragOver] = React.useState(!1);
|
|
1466
1466
|
let t1, t2;
|
|
1467
1467
|
$[0] !== editor || $[1] !== element ? (t2 = slate.Editor.isVoid(editor, element), $[0] = editor, $[1] = element, $[2] = t2) : t2 = $[2], t1 = t2;
|
|
1468
1468
|
const isVoid = t1;
|
|
@@ -3078,7 +3078,7 @@ function useSyncValue(props) {
|
|
|
3078
3078
|
portableTextEditor,
|
|
3079
3079
|
readOnly,
|
|
3080
3080
|
slateEditor
|
|
3081
|
-
} = props, schemaTypes = editorActor.getSnapshot().context.schema, previousValue = React.useRef(), updateValueFunctionRef = React.useRef(), updateFromCurrentValue = React.useCallback(() => {
|
|
3081
|
+
} = props, schemaTypes = editorActor.getSnapshot().context.schema, previousValue = React.useRef(void 0), updateValueFunctionRef = React.useRef(void 0), updateFromCurrentValue = React.useCallback(() => {
|
|
3082
3082
|
const currentValue = CURRENT_VALUE.get(portableTextEditor);
|
|
3083
3083
|
if (previousValue.current === currentValue) {
|
|
3084
3084
|
debug$i("Value is the same object as previous, not need to sync");
|
|
@@ -5905,8 +5905,6 @@ const insertBlockObjectActionImplementation = ({
|
|
|
5905
5905
|
}) => {
|
|
5906
5906
|
slateReact.ReactEditor.focus(action.editor);
|
|
5907
5907
|
},
|
|
5908
|
-
copy: () => {
|
|
5909
|
-
},
|
|
5910
5908
|
"delete.backward": ({
|
|
5911
5909
|
action
|
|
5912
5910
|
}) => {
|
|
@@ -6007,10 +6005,6 @@ const insertBlockObjectActionImplementation = ({
|
|
|
6007
6005
|
}) => {
|
|
6008
6006
|
action.effect();
|
|
6009
6007
|
},
|
|
6010
|
-
"key.down": () => {
|
|
6011
|
-
},
|
|
6012
|
-
"key.up": () => {
|
|
6013
|
-
},
|
|
6014
6008
|
"list item.add": addListItemActionImplementation,
|
|
6015
6009
|
"list item.remove": removeListItemActionImplementation,
|
|
6016
6010
|
"list item.toggle": toggleListItemActionImplementation,
|
|
@@ -6049,8 +6043,6 @@ const insertBlockObjectActionImplementation = ({
|
|
|
6049
6043
|
},
|
|
6050
6044
|
noop: () => {
|
|
6051
6045
|
},
|
|
6052
|
-
paste: () => {
|
|
6053
|
-
},
|
|
6054
6046
|
select: ({
|
|
6055
6047
|
action
|
|
6056
6048
|
}) => {
|
|
@@ -6271,8 +6263,6 @@ function performDefaultAction({
|
|
|
6271
6263
|
});
|
|
6272
6264
|
break;
|
|
6273
6265
|
}
|
|
6274
|
-
case "copy":
|
|
6275
|
-
break;
|
|
6276
6266
|
case "decorator.add": {
|
|
6277
6267
|
behaviorActionImplementations["decorator.add"]({
|
|
6278
6268
|
context,
|
|
@@ -6350,10 +6340,6 @@ function performDefaultAction({
|
|
|
6350
6340
|
});
|
|
6351
6341
|
break;
|
|
6352
6342
|
}
|
|
6353
|
-
case "key.down":
|
|
6354
|
-
break;
|
|
6355
|
-
case "key.up":
|
|
6356
|
-
break;
|
|
6357
6343
|
case "list item.toggle": {
|
|
6358
6344
|
behaviorActionImplementations["list item.toggle"]({
|
|
6359
6345
|
context,
|
|
@@ -6361,8 +6347,6 @@ function performDefaultAction({
|
|
|
6361
6347
|
});
|
|
6362
6348
|
break;
|
|
6363
6349
|
}
|
|
6364
|
-
case "paste":
|
|
6365
|
-
break;
|
|
6366
6350
|
default:
|
|
6367
6351
|
behaviorActionImplementations["style.toggle"]({
|
|
6368
6352
|
context,
|
|
@@ -6416,11 +6400,13 @@ const editorMachine = xstate.setup({
|
|
|
6416
6400
|
enqueue
|
|
6417
6401
|
}) => {
|
|
6418
6402
|
xstate.assertEvent(event, ["behavior event"]), debug$l("Behavior event", event);
|
|
6419
|
-
const defaultAction = {
|
|
6403
|
+
const defaultAction = event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" ? void 0 : {
|
|
6420
6404
|
...event.behaviorEvent,
|
|
6421
6405
|
editor: event.editor
|
|
6422
6406
|
}, eventBehaviors = context.behaviors.filter((behavior) => behavior.on === event.behaviorEvent.type);
|
|
6423
6407
|
if (eventBehaviors.length === 0) {
|
|
6408
|
+
if (!defaultAction)
|
|
6409
|
+
return;
|
|
6424
6410
|
enqueue.raise({
|
|
6425
6411
|
type: "behavior action intends",
|
|
6426
6412
|
editor: event.editor,
|
|
@@ -6430,7 +6416,9 @@ const editorMachine = xstate.setup({
|
|
|
6430
6416
|
}
|
|
6431
6417
|
const value = fromSlateValue(event.editor.children, context.schema.block.name, KEY_TO_VALUE_ELEMENT.get(event.editor)), selection = toPortableTextRange(value, event.editor.selection, context.schema);
|
|
6432
6418
|
if (!selection) {
|
|
6433
|
-
console.warn(`Unable to handle event ${event.type} due to missing selection`),
|
|
6419
|
+
if (console.warn(`Unable to handle event ${event.type} due to missing selection`), !defaultAction)
|
|
6420
|
+
return;
|
|
6421
|
+
enqueue.raise({
|
|
6434
6422
|
type: "behavior action intends",
|
|
6435
6423
|
editor: event.editor,
|
|
6436
6424
|
actionIntends: [defaultAction]
|
|
@@ -6463,11 +6451,15 @@ const editorMachine = xstate.setup({
|
|
|
6463
6451
|
break;
|
|
6464
6452
|
}
|
|
6465
6453
|
}
|
|
6466
|
-
behaviorOverwritten
|
|
6467
|
-
|
|
6468
|
-
|
|
6469
|
-
|
|
6470
|
-
|
|
6454
|
+
if (!behaviorOverwritten) {
|
|
6455
|
+
if (!defaultAction)
|
|
6456
|
+
return;
|
|
6457
|
+
enqueue.raise({
|
|
6458
|
+
type: "behavior action intends",
|
|
6459
|
+
editor: event.editor,
|
|
6460
|
+
actionIntends: [defaultAction]
|
|
6461
|
+
});
|
|
6462
|
+
}
|
|
6471
6463
|
})
|
|
6472
6464
|
}
|
|
6473
6465
|
}).createMachine({
|
|
@@ -6763,7 +6755,7 @@ function createEditor(config) {
|
|
|
6763
6755
|
},
|
|
6764
6756
|
on: (event, listener) => editorActor.on(
|
|
6765
6757
|
event,
|
|
6766
|
-
// @ts-
|
|
6758
|
+
// @ts-expect-error
|
|
6767
6759
|
listener
|
|
6768
6760
|
),
|
|
6769
6761
|
_internal: {
|
|
@@ -6774,26 +6766,35 @@ function createEditor(config) {
|
|
|
6774
6766
|
};
|
|
6775
6767
|
}
|
|
6776
6768
|
function useCreateEditor(config) {
|
|
6777
|
-
const
|
|
6778
|
-
|
|
6779
|
-
|
|
6769
|
+
const $ = reactCompilerRuntime.c(18);
|
|
6770
|
+
let t0;
|
|
6771
|
+
$[0] !== config ? (t0 = editorConfigToMachineInput(config), $[0] = config, $[1] = t0) : t0 = $[1];
|
|
6772
|
+
let t1;
|
|
6773
|
+
$[2] !== t0 ? (t1 = {
|
|
6774
|
+
input: t0
|
|
6775
|
+
}, $[2] = t0, $[3] = t1) : t1 = $[3];
|
|
6776
|
+
const editorActor = react.useActorRef(editorMachine, t1);
|
|
6777
|
+
let t2, slateEditor, t3;
|
|
6778
|
+
$[4] !== editorActor ? (slateEditor = createSlateEditor({
|
|
6780
6779
|
editorActor
|
|
6781
|
-
}),
|
|
6780
|
+
}), t3 = createEditableAPI(slateEditor.instance, editorActor), $[4] = editorActor, $[5] = slateEditor, $[6] = t3) : (slateEditor = $[5], t3 = $[6]);
|
|
6781
|
+
const editable = t3;
|
|
6782
|
+
let t4, t5;
|
|
6783
|
+
$[7] !== editorActor ? (t4 = (event) => {
|
|
6782
6784
|
editorActor.send(event);
|
|
6783
|
-
},
|
|
6784
|
-
|
|
6785
|
-
|
|
6786
|
-
|
|
6787
|
-
|
|
6788
|
-
|
|
6789
|
-
|
|
6790
|
-
|
|
6791
|
-
|
|
6792
|
-
|
|
6793
|
-
|
|
6794
|
-
|
|
6795
|
-
|
|
6796
|
-
}), [send, on, editable, editorActor, slateEditor]);
|
|
6785
|
+
}, t5 = (event_0, listener) => editorActor.on(event_0, listener), $[7] = editorActor, $[8] = t4, $[9] = t5) : (t4 = $[8], t5 = $[9]);
|
|
6786
|
+
let t6;
|
|
6787
|
+
$[10] !== editable || $[11] !== editorActor || $[12] !== slateEditor ? (t6 = {
|
|
6788
|
+
editable,
|
|
6789
|
+
editorActor,
|
|
6790
|
+
slateEditor
|
|
6791
|
+
}, $[10] = editable, $[11] = editorActor, $[12] = slateEditor, $[13] = t6) : t6 = $[13];
|
|
6792
|
+
let t7;
|
|
6793
|
+
return $[14] !== t4 || $[15] !== t5 || $[16] !== t6 ? (t7 = {
|
|
6794
|
+
send: t4,
|
|
6795
|
+
on: t5,
|
|
6796
|
+
_internal: t6
|
|
6797
|
+
}, $[14] = t4, $[15] = t5, $[16] = t6, $[17] = t7) : t7 = $[17], t2 = t7, t2;
|
|
6797
6798
|
}
|
|
6798
6799
|
function editorConfigToMachineInput(config) {
|
|
6799
6800
|
return {
|