@portabletext/editor 2.15.3 → 2.15.4
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-dts/behavior.types.action.d.cts +9 -9
- package/lib/index.cjs +30 -24
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +28 -23
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.ts +3 -3
- package/package.json +2 -2
- package/src/internal-utils/operation-to-patches.ts +34 -18
- package/src/operations/behavior.operation.child.unset.ts +14 -9
- package/src/test/vitest/step-definitions.tsx +4 -7
|
@@ -3,7 +3,7 @@ import { ArrayDefinition, ArraySchemaType, BlockDecoratorDefinition, BlockListDe
|
|
|
3
3
|
import { BaseRange, Descendant, Operation } from "slate";
|
|
4
4
|
import * as xstate229 from "xstate";
|
|
5
5
|
import { ActorRef, ActorRefFrom, EventObject, Snapshot } from "xstate";
|
|
6
|
-
import * as
|
|
6
|
+
import * as react20 from "react";
|
|
7
7
|
import React$1, { BaseSyntheticEvent, ClipboardEvent, Component, FocusEvent, JSX, KeyboardEvent as KeyboardEvent$1, MutableRefObject, PropsWithChildren, ReactElement, RefObject, TextareaHTMLAttributes } from "react";
|
|
8
8
|
import { Patch, Patch as Patch$1 } from "@portabletext/patches";
|
|
9
9
|
import * as _portabletext_schema5 from "@portabletext/schema";
|
|
@@ -219,7 +219,7 @@ declare class PortableTextEditor extends Component<PortableTextEditorProps<Inter
|
|
|
219
219
|
componentDidUpdate(prevProps: PortableTextEditorProps): void;
|
|
220
220
|
componentWillUnmount(): void;
|
|
221
221
|
setEditable: (editable: EditableAPI) => void;
|
|
222
|
-
render():
|
|
222
|
+
render(): react20.JSX.Element;
|
|
223
223
|
/**
|
|
224
224
|
* @deprecated
|
|
225
225
|
* Use built-in selectors or write your own: https://www.portabletext.org/reference/selectors/
|
|
@@ -614,7 +614,7 @@ type PortableTextEditableProps = Omit<TextareaHTMLAttributes<HTMLDivElement>, 'o
|
|
|
614
614
|
* ```
|
|
615
615
|
* @group Components
|
|
616
616
|
*/
|
|
617
|
-
declare const PortableTextEditable:
|
|
617
|
+
declare const PortableTextEditable: react20.ForwardRefExoticComponent<Omit<PortableTextEditableProps, "ref"> & react20.RefAttributes<Omit<HTMLDivElement, "as" | "onPaste" | "onBeforeInput">>>;
|
|
618
618
|
type DecoratedRange = BaseRange & {
|
|
619
619
|
rangeDecoration: RangeDecoration;
|
|
620
620
|
};
|
|
@@ -1532,7 +1532,7 @@ declare const editorMachine: xstate229.StateMachine<{
|
|
|
1532
1532
|
initialValue?: Array<PortableTextBlock>;
|
|
1533
1533
|
}, xstate229.NonReducibleUnknown, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
1534
1534
|
type: "blurred";
|
|
1535
|
-
event:
|
|
1535
|
+
event: react20.FocusEvent<HTMLDivElement, Element>;
|
|
1536
1536
|
} | {
|
|
1537
1537
|
type: "done loading";
|
|
1538
1538
|
} | {
|
|
@@ -1544,7 +1544,7 @@ declare const editorMachine: xstate229.StateMachine<{
|
|
|
1544
1544
|
data: unknown;
|
|
1545
1545
|
} | {
|
|
1546
1546
|
type: "focused";
|
|
1547
|
-
event:
|
|
1547
|
+
event: react20.FocusEvent<HTMLDivElement, Element>;
|
|
1548
1548
|
} | {
|
|
1549
1549
|
type: "invalid value";
|
|
1550
1550
|
resolution: InvalidValueResolution | null;
|
|
@@ -2205,7 +2205,7 @@ declare const editorMachine: xstate229.StateMachine<{
|
|
|
2205
2205
|
editor: PortableTextSlateEditor;
|
|
2206
2206
|
}, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
2207
2207
|
type: "blurred";
|
|
2208
|
-
event:
|
|
2208
|
+
event: react20.FocusEvent<HTMLDivElement, Element>;
|
|
2209
2209
|
} | {
|
|
2210
2210
|
type: "done loading";
|
|
2211
2211
|
} | {
|
|
@@ -2217,7 +2217,7 @@ declare const editorMachine: xstate229.StateMachine<{
|
|
|
2217
2217
|
data: unknown;
|
|
2218
2218
|
} | {
|
|
2219
2219
|
type: "focused";
|
|
2220
|
-
event:
|
|
2220
|
+
event: react20.FocusEvent<HTMLDivElement, Element>;
|
|
2221
2221
|
} | {
|
|
2222
2222
|
type: "invalid value";
|
|
2223
2223
|
resolution: InvalidValueResolution | null;
|
|
@@ -3078,7 +3078,7 @@ declare const editorMachine: xstate229.StateMachine<{
|
|
|
3078
3078
|
editor: PortableTextSlateEditor;
|
|
3079
3079
|
}, undefined, never, never, never, never, InternalPatchEvent | MutationEvent | PatchesEvent | {
|
|
3080
3080
|
type: "blurred";
|
|
3081
|
-
event:
|
|
3081
|
+
event: react20.FocusEvent<HTMLDivElement, Element>;
|
|
3082
3082
|
} | {
|
|
3083
3083
|
type: "done loading";
|
|
3084
3084
|
} | {
|
|
@@ -3090,7 +3090,7 @@ declare const editorMachine: xstate229.StateMachine<{
|
|
|
3090
3090
|
data: unknown;
|
|
3091
3091
|
} | {
|
|
3092
3092
|
type: "focused";
|
|
3093
|
-
event:
|
|
3093
|
+
event: react20.FocusEvent<HTMLDivElement, Element>;
|
|
3094
3094
|
} | {
|
|
3095
3095
|
type: "invalid value";
|
|
3096
3096
|
resolution: InvalidValueResolution | null;
|
package/lib/index.cjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: !0 });
|
|
3
|
-
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$g = require("debug"), slateDom = require("slate-dom"), util_isEmptyTextBlock = require("./_chunks-cjs/util.is-empty-text-block.cjs"), util_getTextBlockText = require("./_chunks-cjs/util.get-text-block-text.cjs"), isEqual = require("lodash/isEqual.js"), schema = require("@portabletext/schema"), selector_isAtTheStartOfBlock = require("./_chunks-cjs/selector.is-at-the-start-of-block.cjs"), selector_getSelectionText = require("./_chunks-cjs/selector.get-selection-text.cjs"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), xstate = require("xstate"), sanityBridge = require("@portabletext/sanity-bridge"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema$1 = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), patches = require("@portabletext/patches"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_sliceTextBlock = require("./_chunks-cjs/util.slice-text-block.cjs"),
|
|
3
|
+
var reactCompilerRuntime = require("react-compiler-runtime"), React = require("react"), useEditor = require("./_chunks-cjs/use-editor.cjs"), jsxRuntime = require("react/jsx-runtime"), react = require("@xstate/react"), noop = require("lodash/noop.js"), slate = require("slate"), slateReact = require("slate-react"), debug$g = require("debug"), slateDom = require("slate-dom"), util_isEmptyTextBlock = require("./_chunks-cjs/util.is-empty-text-block.cjs"), util_getTextBlockText = require("./_chunks-cjs/util.get-text-block-text.cjs"), isEqual = require("lodash/isEqual.js"), schema = require("@portabletext/schema"), selector_isAtTheStartOfBlock = require("./_chunks-cjs/selector.is-at-the-start-of-block.cjs"), selector_getSelectionText = require("./_chunks-cjs/selector.get-selection-text.cjs"), behaviors_index = require("./behaviors/index.cjs"), uniq = require("lodash/uniq.js"), xstate = require("xstate"), sanityBridge = require("@portabletext/sanity-bridge"), blockTools = require("@portabletext/block-tools"), toHtml = require("@portabletext/to-html"), schema$1 = require("@sanity/schema"), flatten = require("lodash/flatten.js"), omit = require("lodash/omit.js"), patches = require("@portabletext/patches"), util_childSelectionPointToBlockOffset = require("./_chunks-cjs/util.child-selection-point-to-block-offset.cjs"), util_sliceTextBlock = require("./_chunks-cjs/util.slice-text-block.cjs"), immer = require("immer"), keyboardShortcuts = require("@portabletext/keyboard-shortcuts"), isPlainObject = require("lodash/isPlainObject.js"), rxjs = require("rxjs");
|
|
4
4
|
function _interopDefaultCompat(e) {
|
|
5
5
|
return e && typeof e == "object" && "default" in e ? e : { default: e };
|
|
6
6
|
}
|
|
7
|
-
var noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$g), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit),
|
|
7
|
+
var noop__default = /* @__PURE__ */ _interopDefaultCompat(noop), debug__default = /* @__PURE__ */ _interopDefaultCompat(debug$g), isEqual__default = /* @__PURE__ */ _interopDefaultCompat(isEqual), uniq__default = /* @__PURE__ */ _interopDefaultCompat(uniq), flatten__default = /* @__PURE__ */ _interopDefaultCompat(flatten), omit__default = /* @__PURE__ */ _interopDefaultCompat(omit), isPlainObject__default = /* @__PURE__ */ _interopDefaultCompat(isPlainObject);
|
|
8
8
|
function EditorEventListener(props) {
|
|
9
9
|
const $ = reactCompilerRuntime.c(4), editor = useEditor.useEditor();
|
|
10
10
|
let t0, t1;
|
|
@@ -4429,15 +4429,9 @@ const addAnnotationOperationImplementation = ({
|
|
|
4429
4429
|
if (!child || !childPath)
|
|
4430
4430
|
throw new Error(`Unable to find child at ${JSON.stringify(operation.at)}`);
|
|
4431
4431
|
if (operation.editor.isTextSpan(child)) {
|
|
4432
|
-
operation.props.includes("text") && operation.editor.apply({
|
|
4433
|
-
type: "remove_text",
|
|
4434
|
-
path: childPath,
|
|
4435
|
-
offset: 0,
|
|
4436
|
-
text: child.text
|
|
4437
|
-
});
|
|
4438
4432
|
const newNode = {};
|
|
4439
4433
|
for (const prop of operation.props)
|
|
4440
|
-
if (prop !== "_type") {
|
|
4434
|
+
if (prop !== "text" && prop !== "_type") {
|
|
4441
4435
|
if (prop === "_key") {
|
|
4442
4436
|
newNode._key = context.keyGenerator();
|
|
4443
4437
|
continue;
|
|
@@ -4446,6 +4440,11 @@ const addAnnotationOperationImplementation = ({
|
|
|
4446
4440
|
}
|
|
4447
4441
|
slate.Transforms.setNodes(operation.editor, newNode, {
|
|
4448
4442
|
at: childPath
|
|
4443
|
+
}), operation.props.includes("text") && operation.editor.apply({
|
|
4444
|
+
type: "remove_text",
|
|
4445
|
+
path: childPath,
|
|
4446
|
+
offset: 0,
|
|
4447
|
+
text: child.text
|
|
4449
4448
|
});
|
|
4450
4449
|
return;
|
|
4451
4450
|
}
|
|
@@ -6031,8 +6030,8 @@ function setNodePatch(schema$12, children, operation) {
|
|
|
6031
6030
|
_key !== void 0 && patches$1.push(patches.set(_key, [{
|
|
6032
6031
|
_key: blockKey
|
|
6033
6032
|
}, "children", block.children.indexOf(child), "_key"]));
|
|
6034
|
-
const properties = "value" in operation.newProperties && typeof operation.newProperties.value == "object" ? operation.newProperties.value : {},
|
|
6035
|
-
for (const key of
|
|
6033
|
+
const properties = "value" in operation.newProperties && typeof operation.newProperties.value == "object" ? operation.newProperties.value : {}, keys = Object.keys(properties);
|
|
6034
|
+
for (const key of keys) {
|
|
6036
6035
|
const value = properties[key];
|
|
6037
6036
|
patches$1.push(patches.set(value, [{
|
|
6038
6037
|
_key: blockKey
|
|
@@ -6042,22 +6041,29 @@ function setNodePatch(schema$12, children, operation) {
|
|
|
6042
6041
|
}
|
|
6043
6042
|
return patches$1;
|
|
6044
6043
|
}
|
|
6045
|
-
const
|
|
6046
|
-
|
|
6047
|
-
|
|
6048
|
-
|
|
6049
|
-
patches$1.push(patches.set(
|
|
6044
|
+
const newPropNames = Object.keys(operation.newProperties);
|
|
6045
|
+
for (const keyName of newPropNames) {
|
|
6046
|
+
const value = operation.newProperties[keyName];
|
|
6047
|
+
if (keyName === "_key") {
|
|
6048
|
+
patches$1.push(patches.set(value, [{
|
|
6050
6049
|
_key: blockKey
|
|
6051
6050
|
}, "children", block.children.indexOf(child), keyName]));
|
|
6052
|
-
|
|
6053
|
-
const val = get__default.default(operation.newProperties, keyName);
|
|
6054
|
-
patches$1.push(patches.set(val, [{
|
|
6055
|
-
_key: blockKey
|
|
6056
|
-
}, "children", {
|
|
6057
|
-
_key: childKey
|
|
6058
|
-
}, keyName]));
|
|
6051
|
+
continue;
|
|
6059
6052
|
}
|
|
6060
|
-
|
|
6053
|
+
patches$1.push(patches.set(value, [{
|
|
6054
|
+
_key: blockKey
|
|
6055
|
+
}, "children", {
|
|
6056
|
+
_key: childKey
|
|
6057
|
+
}, keyName]));
|
|
6058
|
+
}
|
|
6059
|
+
const propNames = Object.keys(operation.properties);
|
|
6060
|
+
for (const keyName of propNames)
|
|
6061
|
+
keyName in operation.newProperties || patches$1.push(patches.unset([{
|
|
6062
|
+
_key: blockKey
|
|
6063
|
+
}, "children", {
|
|
6064
|
+
_key: childKey
|
|
6065
|
+
}, keyName]));
|
|
6066
|
+
return patches$1;
|
|
6061
6067
|
}
|
|
6062
6068
|
throw new Error("Could not find a valid child");
|
|
6063
6069
|
}
|