@portabletext/editor 1.35.0 → 1.35.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/lib/_chunks-cjs/{plugin.event-listener.cjs → editor-provider.cjs} +50 -20
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -0
- package/lib/_chunks-es/{plugin.event-listener.js → editor-provider.js} +51 -21
- package/lib/_chunks-es/editor-provider.js.map +1 -0
- package/lib/behaviors/index.d.cts +19377 -210
- package/lib/behaviors/index.d.ts +19377 -210
- package/lib/index.cjs +81 -51
- package/lib/index.cjs.map +1 -1
- package/lib/index.d.cts +318 -47
- package/lib/index.d.ts +318 -47
- package/lib/index.js +35 -4
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.cjs +22 -7
- package/lib/plugins/index.cjs.map +1 -1
- package/lib/plugins/index.d.cts +313 -2
- package/lib/plugins/index.d.ts +313 -2
- package/lib/plugins/index.js +18 -3
- package/lib/plugins/index.js.map +1 -1
- package/lib/selectors/index.d.cts +19504 -1
- package/lib/selectors/index.d.ts +19504 -1
- package/lib/utils/index.d.cts +19506 -2
- package/lib/utils/index.d.ts +19506 -2
- package/package.json +3 -3
- package/src/behavior-actions/behavior.action.decorator.add.ts +1 -0
- package/src/behavior-actions/behavior.action.delete.text.ts +1 -0
- package/src/behaviors/behavior.decorator-pair.ts +1 -0
- package/src/converters/converter.portable-text.deserialize.test.ts +3 -7
- package/src/converters/converter.portable-text.ts +7 -1
- package/src/converters/converter.text-html.deserialize.test.ts +3 -7
- package/src/converters/converter.text-html.serialize.test.ts +5 -10
- package/src/converters/converter.text-plain.test.ts +4 -6
- package/src/editor/Editable.tsx +26 -0
- package/src/editor/editor-machine.ts +170 -147
- package/src/editor/editor-selector.ts +3 -0
- package/src/editor/editor-snapshot.ts +13 -0
- package/src/editor/mutation-machine.ts +2 -0
- package/src/editor-event-listener.tsx +30 -0
- package/src/index.ts +1 -1
- package/src/internal-utils/create-test-snapshot.ts +23 -0
- package/src/plugins/plugin.one-line.tsx +1 -1
- package/src/selectors/selector.get-active-annotations.test.ts +4 -13
- package/src/selectors/selector.get-caret-word-selection.test.ts +3 -7
- package/src/selectors/selector.get-selected-spans.test.ts +5 -9
- package/src/selectors/selector.get-selection-text.test.ts +5 -7
- package/src/selectors/selector.get-trimmed-selection.test.ts +3 -5
- package/src/selectors/selector.is-active-decorator.test.ts +5 -9
- package/lib/_chunks-cjs/plugin.event-listener.cjs.map +0 -1
- package/lib/_chunks-es/plugin.event-listener.js.map +0 -1
|
@@ -1,7 +1,6 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
1
2
|
import { c } from "react-compiler-runtime";
|
|
2
3
|
import React, { createContext, useContext, useEffect, useState, startTransition, Component } from "react";
|
|
3
|
-
import { useEffectEvent } from "use-effect-event";
|
|
4
|
-
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
5
4
|
import { ReactEditor, withReact, Slate } from "slate-react";
|
|
6
5
|
import { useSelector, useActorRef } from "@xstate/react";
|
|
7
6
|
import debug$e from "debug";
|
|
@@ -28,6 +27,7 @@ import omit from "lodash/omit.js";
|
|
|
28
27
|
import startCase from "lodash.startcase";
|
|
29
28
|
import { defineBehavior, raise, coreBehaviors, isCustomBehaviorEvent } from "./behavior.core.js";
|
|
30
29
|
import { Subject } from "rxjs";
|
|
30
|
+
import { useEffectEvent } from "use-effect-event";
|
|
31
31
|
function createEditorSchema(portableTextType) {
|
|
32
32
|
if (!portableTextType)
|
|
33
33
|
throw new Error("Parameter 'portabletextType' missing (required)");
|
|
@@ -402,11 +402,13 @@ const FLUSH_PATCHES_THROTTLED_MS = process.env.NODE_ENV === "test" ? 500 : 1e3,
|
|
|
402
402
|
target: "idle",
|
|
403
403
|
actions: ["emit mutation", "clear pending patches"]
|
|
404
404
|
}, {
|
|
405
|
+
target: "has pending patches",
|
|
405
406
|
reenter: !0
|
|
406
407
|
}]
|
|
407
408
|
},
|
|
408
409
|
on: {
|
|
409
410
|
patch: {
|
|
411
|
+
target: "has pending patches",
|
|
410
412
|
actions: ["defer patch"],
|
|
411
413
|
reenter: !0
|
|
412
414
|
}
|
|
@@ -2354,7 +2356,11 @@ const converterJson = {
|
|
|
2354
2356
|
context: snapshot.context,
|
|
2355
2357
|
block,
|
|
2356
2358
|
options: {
|
|
2357
|
-
|
|
2359
|
+
/**
|
|
2360
|
+
* If we are dragging internally then we would like to keep the
|
|
2361
|
+
* dropped portable text as is.
|
|
2362
|
+
*/
|
|
2363
|
+
refreshKeys: !snapshot.beta.hasTag?.("dragging internally")
|
|
2358
2364
|
}
|
|
2359
2365
|
});
|
|
2360
2366
|
return parsedBlock ? [parsedBlock] : [];
|
|
@@ -2938,6 +2944,9 @@ const decoratorAddActionImplementation = ({
|
|
|
2938
2944
|
},
|
|
2939
2945
|
backward: editorSelection?.backward
|
|
2940
2946
|
}), trimmedSelection = getTrimmedSelection({
|
|
2947
|
+
beta: {
|
|
2948
|
+
hasTag: () => !1
|
|
2949
|
+
},
|
|
2941
2950
|
context: {
|
|
2942
2951
|
activeDecorators: [],
|
|
2943
2952
|
converters: [],
|
|
@@ -4151,6 +4160,9 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4151
4160
|
if (!selection)
|
|
4152
4161
|
throw new Error("Unable to find selection from block offsets");
|
|
4153
4162
|
const trimmedSelection = getTrimmedSelection({
|
|
4163
|
+
beta: {
|
|
4164
|
+
hasTag: () => !1
|
|
4165
|
+
},
|
|
4154
4166
|
context: {
|
|
4155
4167
|
converters: [],
|
|
4156
4168
|
schema: context.schema,
|
|
@@ -5914,7 +5926,8 @@ function createEditorSnapshot({
|
|
|
5914
5926
|
converters,
|
|
5915
5927
|
editor,
|
|
5916
5928
|
keyGenerator,
|
|
5917
|
-
schema
|
|
5929
|
+
schema,
|
|
5930
|
+
hasTag
|
|
5918
5931
|
}) {
|
|
5919
5932
|
const value = fromSlateValue(editor.children, schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), selection = toPortableTextRange(value, editor.selection, schema);
|
|
5920
5933
|
return {
|
|
@@ -5928,6 +5941,9 @@ function createEditorSnapshot({
|
|
|
5928
5941
|
schema,
|
|
5929
5942
|
selection,
|
|
5930
5943
|
value
|
|
5944
|
+
},
|
|
5945
|
+
beta: {
|
|
5946
|
+
hasTag
|
|
5931
5947
|
}
|
|
5932
5948
|
};
|
|
5933
5949
|
}
|
|
@@ -5936,7 +5952,8 @@ const editorMachine = setup({
|
|
|
5936
5952
|
context: {},
|
|
5937
5953
|
events: {},
|
|
5938
5954
|
emitted: {},
|
|
5939
|
-
input: {}
|
|
5955
|
+
input: {},
|
|
5956
|
+
tags: {}
|
|
5940
5957
|
},
|
|
5941
5958
|
actions: {
|
|
5942
5959
|
"add behavior to context": assign({
|
|
@@ -5995,7 +6012,8 @@ const editorMachine = setup({
|
|
|
5995
6012
|
"handle behavior event": enqueueActions(({
|
|
5996
6013
|
context,
|
|
5997
6014
|
event,
|
|
5998
|
-
enqueue
|
|
6015
|
+
enqueue,
|
|
6016
|
+
self
|
|
5999
6017
|
}) => {
|
|
6000
6018
|
assertEvent(event, ["behavior event", "custom behavior event"]);
|
|
6001
6019
|
const defaultAction = event.type === "custom behavior event" || event.behaviorEvent.type === "copy" || event.behaviorEvent.type === "deserialize" || event.behaviorEvent.type === "key.down" || event.behaviorEvent.type === "key.up" || event.behaviorEvent.type === "paste" || event.behaviorEvent.type === "serialize" ? void 0 : {
|
|
@@ -6031,7 +6049,8 @@ const editorMachine = setup({
|
|
|
6031
6049
|
converters: [...context.converters],
|
|
6032
6050
|
editor: event.editor,
|
|
6033
6051
|
keyGenerator: context.keyGenerator,
|
|
6034
|
-
schema: context.schema
|
|
6052
|
+
schema: context.schema,
|
|
6053
|
+
hasTag: (tag) => self.getSnapshot().hasTag(tag)
|
|
6035
6054
|
});
|
|
6036
6055
|
let behaviorOverwritten = !1;
|
|
6037
6056
|
for (const eventBehavior of eventBehaviors) {
|
|
@@ -6367,6 +6386,27 @@ const editorMachine = setup({
|
|
|
6367
6386
|
event
|
|
6368
6387
|
}) => event)
|
|
6369
6388
|
}
|
|
6389
|
+
},
|
|
6390
|
+
initial: "idle",
|
|
6391
|
+
states: {
|
|
6392
|
+
idle: {
|
|
6393
|
+
on: {
|
|
6394
|
+
dragstart: {
|
|
6395
|
+
target: "dragging internally"
|
|
6396
|
+
}
|
|
6397
|
+
}
|
|
6398
|
+
},
|
|
6399
|
+
"dragging internally": {
|
|
6400
|
+
tags: ["dragging internally"],
|
|
6401
|
+
on: {
|
|
6402
|
+
dragend: {
|
|
6403
|
+
target: "idle"
|
|
6404
|
+
},
|
|
6405
|
+
drop: {
|
|
6406
|
+
target: "idle"
|
|
6407
|
+
}
|
|
6408
|
+
}
|
|
6409
|
+
}
|
|
6370
6410
|
}
|
|
6371
6411
|
}
|
|
6372
6412
|
}
|
|
@@ -6474,6 +6514,9 @@ function getEditorSnapshot({
|
|
|
6474
6514
|
editorActorSnapshot,
|
|
6475
6515
|
slateEditorInstance
|
|
6476
6516
|
})
|
|
6517
|
+
},
|
|
6518
|
+
beta: {
|
|
6519
|
+
hasTag: (tag) => editorActorSnapshot.hasTag(tag)
|
|
6477
6520
|
}
|
|
6478
6521
|
};
|
|
6479
6522
|
}
|
|
@@ -7098,22 +7141,9 @@ function useEditor() {
|
|
|
7098
7141
|
throw new Error("No Editor set. Use EditorProvider to set one.");
|
|
7099
7142
|
return editor;
|
|
7100
7143
|
}
|
|
7101
|
-
function EventListenerPlugin(props) {
|
|
7102
|
-
const $ = c(5), editor = useEditor(), on = useEffectEvent(props.on);
|
|
7103
|
-
let t0;
|
|
7104
|
-
$[0] !== editor || $[1] !== on ? (t0 = () => {
|
|
7105
|
-
const subscription = editor.on("*", on);
|
|
7106
|
-
return () => {
|
|
7107
|
-
subscription.unsubscribe();
|
|
7108
|
-
};
|
|
7109
|
-
}, $[0] = editor, $[1] = on, $[2] = t0) : t0 = $[2];
|
|
7110
|
-
let t1;
|
|
7111
|
-
return $[3] !== editor ? (t1 = [editor], $[3] = editor, $[4] = t1) : t1 = $[4], useEffect(t0, t1), null;
|
|
7112
|
-
}
|
|
7113
7144
|
export {
|
|
7114
7145
|
EditorActorContext,
|
|
7115
7146
|
EditorProvider,
|
|
7116
|
-
EventListenerPlugin,
|
|
7117
7147
|
IS_DRAGGING,
|
|
7118
7148
|
IS_DRAGGING_BLOCK_ELEMENT,
|
|
7119
7149
|
IS_DRAGGING_BLOCK_TARGET_POSITION,
|
|
@@ -7134,4 +7164,4 @@ export {
|
|
|
7134
7164
|
usePortableTextEditor,
|
|
7135
7165
|
usePortableTextEditorSelection
|
|
7136
7166
|
};
|
|
7137
|
-
//# sourceMappingURL=
|
|
7167
|
+
//# sourceMappingURL=editor-provider.js.map
|