@portabletext/editor 1.11.0 → 1.11.2
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/README.md +10 -1
- package/lib/index.esm.js +27 -21
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +27 -21
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +27 -21
- package/lib/index.mjs.map +1 -1
- package/package.json +7 -7
- package/src/editor/behavior/behavior.action.insert-break.ts +3 -3
- package/src/editor/behavior/behavior.action.insert-span.ts +2 -2
- package/src/editor/behavior/behavior.actions.ts +4 -4
- package/src/editor/editor-machine.ts +5 -2
- package/src/editor/plugins/createWithEditableAPI.ts +5 -5
- package/src/editor/plugins/createWithMaxBlocks.ts +1 -0
- package/src/editor/plugins/createWithPlaceholderBlock.ts +1 -0
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +4 -4
- package/src/editor/plugins/createWithUndoRedo.ts +1 -0
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ In order to provide a robust and consistent end-user experience, the editor is b
|
|
|
21
21
|
> [!WARNING]
|
|
22
22
|
> The `@portabletext/editor` is currently on the path to deprecate legacy APIs and introduce new ones. The end goals are to make the editor easier to use outside of `Sanity` (and without `@sanity/*` libraries) as well as providing a brand new API to configure the behavior of the editor.
|
|
23
23
|
>
|
|
24
|
-
> This means that the `defineSchema` and `
|
|
24
|
+
> This means that the `defineSchema` and `EditorProvider` APIs showcased here are still experimental APIs tagged with `@alpha` and cannot be considered stable yet. At the same time, the examples below showcase usages of legacy static methods on the `PortableTextEditor` (for example, `PortableTextEditor.isMarkActive(...)` and `PortableTextEditor.toggleMark(...)`) that will soon be discouraged and deprecrated.
|
|
25
25
|
|
|
26
26
|
Check [/examples/basic/src/App.tsx](/examples/basic/src/App.tsx) for a basic example of how to set up the edior. Most of the source code from this example app can also be found in the instructions below.
|
|
27
27
|
|
|
@@ -369,3 +369,12 @@ function Toolbar() {
|
|
|
369
369
|
)
|
|
370
370
|
}
|
|
371
371
|
```
|
|
372
|
+
|
|
373
|
+
## Behavior API (Coming Soon)
|
|
374
|
+
|
|
375
|
+
The Behavior API is a new way of interfacing with the Portable Text Editor. It allows you to think of and treat the editor as a state machine by:
|
|
376
|
+
|
|
377
|
+
1. Declaratively hooking into editor **events** and defining new behaviors using `defineBehavior`. (A "Behavior" (1) listens for an **event**, (2) uses a **guard** to determine whether it should run and (3) raises a set of **actions** to be performed on the editor.)
|
|
378
|
+
2. Imperatively trigger **events** using `editor.send(…)` which in turn can trigger behaviors defined using `defineBehavior`.
|
|
379
|
+
3. Deriving editor **state** using **pure functions**.
|
|
380
|
+
4. Subscribe to **emitted** editor **events** using `editor.on(…)`.
|
package/lib/index.esm.js
CHANGED
|
@@ -2559,8 +2559,10 @@ function createWithUndoRedo(options) {
|
|
|
2559
2559
|
apply: apply2
|
|
2560
2560
|
} = editor;
|
|
2561
2561
|
return editor.apply = (op) => {
|
|
2562
|
-
if (editorActor.getSnapshot().context.readOnly)
|
|
2562
|
+
if (editorActor.getSnapshot().context.readOnly) {
|
|
2563
|
+
apply2(op);
|
|
2563
2564
|
return;
|
|
2565
|
+
}
|
|
2564
2566
|
if (isChangingRemotely(editor)) {
|
|
2565
2567
|
apply2(op);
|
|
2566
2568
|
return;
|
|
@@ -3419,8 +3421,10 @@ function createWithMaxBlocks(editorActor) {
|
|
|
3419
3421
|
apply: apply2
|
|
3420
3422
|
} = editor;
|
|
3421
3423
|
return editor.apply = (operation) => {
|
|
3422
|
-
if (editorActor.getSnapshot().context.readOnly)
|
|
3424
|
+
if (editorActor.getSnapshot().context.readOnly) {
|
|
3425
|
+
apply2(operation);
|
|
3423
3426
|
return;
|
|
3427
|
+
}
|
|
3424
3428
|
if (isChangingRemotely(editor)) {
|
|
3425
3429
|
apply2(operation);
|
|
3426
3430
|
return;
|
|
@@ -3867,26 +3871,28 @@ function createWithPlaceholderBlock(editorActor) {
|
|
|
3867
3871
|
apply: apply2
|
|
3868
3872
|
} = editor;
|
|
3869
3873
|
return editor.apply = (op) => {
|
|
3870
|
-
if (
|
|
3871
|
-
if (isChangingRemotely(editor)) {
|
|
3872
|
-
apply2(op);
|
|
3873
|
-
return;
|
|
3874
|
-
}
|
|
3875
|
-
if (isUndoing(editor) || isRedoing(editor)) {
|
|
3876
|
-
apply2(op);
|
|
3877
|
-
return;
|
|
3878
|
-
}
|
|
3879
|
-
if (op.type === "remove_node") {
|
|
3880
|
-
const node = op.node;
|
|
3881
|
-
if (op.path[0] === 0 && Editor.isVoid(editor, node)) {
|
|
3882
|
-
const nextPath = Path.next(op.path);
|
|
3883
|
-
editor.children[nextPath[0]] || (debug$d("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
3884
|
-
decorators: []
|
|
3885
|
-
})));
|
|
3886
|
-
}
|
|
3887
|
-
}
|
|
3874
|
+
if (editorActor.getSnapshot().context.readOnly) {
|
|
3888
3875
|
apply2(op);
|
|
3876
|
+
return;
|
|
3889
3877
|
}
|
|
3878
|
+
if (isChangingRemotely(editor)) {
|
|
3879
|
+
apply2(op);
|
|
3880
|
+
return;
|
|
3881
|
+
}
|
|
3882
|
+
if (isUndoing(editor) || isRedoing(editor)) {
|
|
3883
|
+
apply2(op);
|
|
3884
|
+
return;
|
|
3885
|
+
}
|
|
3886
|
+
if (op.type === "remove_node") {
|
|
3887
|
+
const node = op.node;
|
|
3888
|
+
if (op.path[0] === 0 && Editor.isVoid(editor, node)) {
|
|
3889
|
+
const nextPath = Path.next(op.path);
|
|
3890
|
+
editor.children[nextPath[0]] || (debug$d("Adding placeholder block"), Editor.insertNode(editor, editor.pteCreateTextBlock({
|
|
3891
|
+
decorators: []
|
|
3892
|
+
})));
|
|
3893
|
+
}
|
|
3894
|
+
}
|
|
3895
|
+
apply2(op);
|
|
3890
3896
|
}, editor;
|
|
3891
3897
|
};
|
|
3892
3898
|
}
|
|
@@ -5738,7 +5744,7 @@ const editorMachine = setup({
|
|
|
5738
5744
|
event: event.behaviorEvent
|
|
5739
5745
|
}, shouldRun));
|
|
5740
5746
|
for (const actionIntends of actionIntendSets)
|
|
5741
|
-
behaviorOverwritten = actionIntends.length > 0 && actionIntends.some((actionIntend) => actionIntend.type !== "effect"), enqueue.raise({
|
|
5747
|
+
behaviorOverwritten = behaviorOverwritten || actionIntends.length > 0 && actionIntends.some((actionIntend) => actionIntend.type !== "effect"), enqueue.raise({
|
|
5742
5748
|
type: "behavior action intends",
|
|
5743
5749
|
editor: event.editor,
|
|
5744
5750
|
actionIntends
|