@portabletext/editor 1.35.0 → 1.35.1
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} +48 -20
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -0
- package/lib/_chunks-es/{plugin.event-listener.js → editor-provider.js} +49 -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 +1 -1
- 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-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)");
|
|
@@ -2354,7 +2354,11 @@ const converterJson = {
|
|
|
2354
2354
|
context: snapshot.context,
|
|
2355
2355
|
block,
|
|
2356
2356
|
options: {
|
|
2357
|
-
|
|
2357
|
+
/**
|
|
2358
|
+
* If we are dragging internally then we would like to keep the
|
|
2359
|
+
* dropped portable text as is.
|
|
2360
|
+
*/
|
|
2361
|
+
refreshKeys: !snapshot.beta.hasTag?.("dragging internally")
|
|
2358
2362
|
}
|
|
2359
2363
|
});
|
|
2360
2364
|
return parsedBlock ? [parsedBlock] : [];
|
|
@@ -2938,6 +2942,9 @@ const decoratorAddActionImplementation = ({
|
|
|
2938
2942
|
},
|
|
2939
2943
|
backward: editorSelection?.backward
|
|
2940
2944
|
}), trimmedSelection = getTrimmedSelection({
|
|
2945
|
+
beta: {
|
|
2946
|
+
hasTag: () => !1
|
|
2947
|
+
},
|
|
2941
2948
|
context: {
|
|
2942
2949
|
activeDecorators: [],
|
|
2943
2950
|
converters: [],
|
|
@@ -4151,6 +4158,9 @@ const blockSetBehaviorActionImplementation = ({
|
|
|
4151
4158
|
if (!selection)
|
|
4152
4159
|
throw new Error("Unable to find selection from block offsets");
|
|
4153
4160
|
const trimmedSelection = getTrimmedSelection({
|
|
4161
|
+
beta: {
|
|
4162
|
+
hasTag: () => !1
|
|
4163
|
+
},
|
|
4154
4164
|
context: {
|
|
4155
4165
|
converters: [],
|
|
4156
4166
|
schema: context.schema,
|
|
@@ -5914,7 +5924,8 @@ function createEditorSnapshot({
|
|
|
5914
5924
|
converters,
|
|
5915
5925
|
editor,
|
|
5916
5926
|
keyGenerator,
|
|
5917
|
-
schema
|
|
5927
|
+
schema,
|
|
5928
|
+
hasTag
|
|
5918
5929
|
}) {
|
|
5919
5930
|
const value = fromSlateValue(editor.children, schema.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), selection = toPortableTextRange(value, editor.selection, schema);
|
|
5920
5931
|
return {
|
|
@@ -5928,6 +5939,9 @@ function createEditorSnapshot({
|
|
|
5928
5939
|
schema,
|
|
5929
5940
|
selection,
|
|
5930
5941
|
value
|
|
5942
|
+
},
|
|
5943
|
+
beta: {
|
|
5944
|
+
hasTag
|
|
5931
5945
|
}
|
|
5932
5946
|
};
|
|
5933
5947
|
}
|
|
@@ -5936,7 +5950,8 @@ const editorMachine = setup({
|
|
|
5936
5950
|
context: {},
|
|
5937
5951
|
events: {},
|
|
5938
5952
|
emitted: {},
|
|
5939
|
-
input: {}
|
|
5953
|
+
input: {},
|
|
5954
|
+
tags: {}
|
|
5940
5955
|
},
|
|
5941
5956
|
actions: {
|
|
5942
5957
|
"add behavior to context": assign({
|
|
@@ -5995,7 +6010,8 @@ const editorMachine = setup({
|
|
|
5995
6010
|
"handle behavior event": enqueueActions(({
|
|
5996
6011
|
context,
|
|
5997
6012
|
event,
|
|
5998
|
-
enqueue
|
|
6013
|
+
enqueue,
|
|
6014
|
+
self
|
|
5999
6015
|
}) => {
|
|
6000
6016
|
assertEvent(event, ["behavior event", "custom behavior event"]);
|
|
6001
6017
|
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 +6047,8 @@ const editorMachine = setup({
|
|
|
6031
6047
|
converters: [...context.converters],
|
|
6032
6048
|
editor: event.editor,
|
|
6033
6049
|
keyGenerator: context.keyGenerator,
|
|
6034
|
-
schema: context.schema
|
|
6050
|
+
schema: context.schema,
|
|
6051
|
+
hasTag: (tag) => self.getSnapshot().hasTag(tag)
|
|
6035
6052
|
});
|
|
6036
6053
|
let behaviorOverwritten = !1;
|
|
6037
6054
|
for (const eventBehavior of eventBehaviors) {
|
|
@@ -6367,6 +6384,27 @@ const editorMachine = setup({
|
|
|
6367
6384
|
event
|
|
6368
6385
|
}) => event)
|
|
6369
6386
|
}
|
|
6387
|
+
},
|
|
6388
|
+
initial: "idle",
|
|
6389
|
+
states: {
|
|
6390
|
+
idle: {
|
|
6391
|
+
on: {
|
|
6392
|
+
dragstart: {
|
|
6393
|
+
target: "dragging internally"
|
|
6394
|
+
}
|
|
6395
|
+
}
|
|
6396
|
+
},
|
|
6397
|
+
"dragging internally": {
|
|
6398
|
+
tags: ["dragging internally"],
|
|
6399
|
+
on: {
|
|
6400
|
+
dragend: {
|
|
6401
|
+
target: "idle"
|
|
6402
|
+
},
|
|
6403
|
+
drop: {
|
|
6404
|
+
target: "idle"
|
|
6405
|
+
}
|
|
6406
|
+
}
|
|
6407
|
+
}
|
|
6370
6408
|
}
|
|
6371
6409
|
}
|
|
6372
6410
|
}
|
|
@@ -6474,6 +6512,9 @@ function getEditorSnapshot({
|
|
|
6474
6512
|
editorActorSnapshot,
|
|
6475
6513
|
slateEditorInstance
|
|
6476
6514
|
})
|
|
6515
|
+
},
|
|
6516
|
+
beta: {
|
|
6517
|
+
hasTag: (tag) => editorActorSnapshot.hasTag(tag)
|
|
6477
6518
|
}
|
|
6478
6519
|
};
|
|
6479
6520
|
}
|
|
@@ -7098,22 +7139,9 @@ function useEditor() {
|
|
|
7098
7139
|
throw new Error("No Editor set. Use EditorProvider to set one.");
|
|
7099
7140
|
return editor;
|
|
7100
7141
|
}
|
|
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
7142
|
export {
|
|
7114
7143
|
EditorActorContext,
|
|
7115
7144
|
EditorProvider,
|
|
7116
|
-
EventListenerPlugin,
|
|
7117
7145
|
IS_DRAGGING,
|
|
7118
7146
|
IS_DRAGGING_BLOCK_ELEMENT,
|
|
7119
7147
|
IS_DRAGGING_BLOCK_TARGET_POSITION,
|
|
@@ -7134,4 +7162,4 @@ export {
|
|
|
7134
7162
|
usePortableTextEditor,
|
|
7135
7163
|
usePortableTextEditorSelection
|
|
7136
7164
|
};
|
|
7137
|
-
//# sourceMappingURL=
|
|
7165
|
+
//# sourceMappingURL=editor-provider.js.map
|