@portabletext/editor 7.10.7 → 7.10.8
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.js +64 -3
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import { setup, fromCallback, assign, and, assertEvent, enqueueActions, emit, no
|
|
|
18
18
|
import { htmlToPortableText } from "@portabletext/html";
|
|
19
19
|
import { toHTML } from "@portabletext/to-html";
|
|
20
20
|
import { markdownToPortableText, portableTextToMarkdown } from "@portabletext/markdown";
|
|
21
|
-
import {
|
|
21
|
+
import { unset, applyAll, set, insert, setIfMissing, diffMatchPatch as diffMatchPatch$1 } from "@portabletext/patches";
|
|
22
22
|
import "xstate/guards";
|
|
23
23
|
import { EditorContext as EditorContext$1 } from "./_chunks-es/use-editor.js";
|
|
24
24
|
import { useEditor } from "./_chunks-es/use-editor.js";
|
|
@@ -7950,6 +7950,17 @@ function applyOperation(editor, op) {
|
|
|
7950
7950
|
let {
|
|
7951
7951
|
node
|
|
7952
7952
|
} = op;
|
|
7953
|
+
if (!targetsStructuralChildren(editor, path2)) {
|
|
7954
|
+
applyOnRootBlock(editor, path2, {
|
|
7955
|
+
type: "insert",
|
|
7956
|
+
path: path2.slice(1),
|
|
7957
|
+
position: op.position,
|
|
7958
|
+
// Sidecar array members aren't necessarily objects (e.g. `marks`
|
|
7959
|
+
// holds strings), so the node is plain JSON data here.
|
|
7960
|
+
items: [node]
|
|
7961
|
+
}), transformSelection = !0;
|
|
7962
|
+
break;
|
|
7963
|
+
}
|
|
7953
7964
|
modifyChildren(editor, parentPath(path2), (children) => {
|
|
7954
7965
|
!editor.isProcessingRemoteChanges && !editor.isUndoing && !editor.isRedoing && node._key !== void 0 && children.some((sibling) => sibling._key === node._key) && (node = {
|
|
7955
7966
|
...node,
|
|
@@ -8038,6 +8049,10 @@ function applyOperation(editor, op) {
|
|
|
8038
8049
|
if (setNodePath.length === 0)
|
|
8039
8050
|
break;
|
|
8040
8051
|
if (setPropertyPath.length === 0) {
|
|
8052
|
+
if (!targetsStructuralChildren(editor, setNodePath)) {
|
|
8053
|
+
applyOnRootBlock(editor, path2, set(value, path2.slice(1))), transformSelection = !0;
|
|
8054
|
+
break;
|
|
8055
|
+
}
|
|
8041
8056
|
value !== null && typeof value == "object" && !Array.isArray(value) && modifyDescendant(editor, setNodePath, () => value), transformSelection = !0;
|
|
8042
8057
|
break;
|
|
8043
8058
|
}
|
|
@@ -8079,6 +8094,18 @@ function applyOperation(editor, op) {
|
|
|
8079
8094
|
break;
|
|
8080
8095
|
}
|
|
8081
8096
|
const lastSegment = path2[path2.length - 1];
|
|
8097
|
+
if ((isKeyedSegment(lastSegment) || typeof lastSegment == "number") && !targetsStructuralChildren(editor, path2)) {
|
|
8098
|
+
if (!op.inverse && !editor.isProcessingRemoteChanges) {
|
|
8099
|
+
const arrayValue = getValue(editor.snapshot.context.value, path2.slice(0, -1));
|
|
8100
|
+
Array.isArray(arrayValue) && (op.inverse = {
|
|
8101
|
+
type: "set",
|
|
8102
|
+
path: path2.slice(0, -1),
|
|
8103
|
+
value: arrayValue
|
|
8104
|
+
});
|
|
8105
|
+
}
|
|
8106
|
+
applyOnRootBlock(editor, path2, unset(path2.slice(1))), transformSelection = !0;
|
|
8107
|
+
break;
|
|
8108
|
+
}
|
|
8082
8109
|
if (isKeyedSegment(lastSegment) || typeof lastSegment == "number") {
|
|
8083
8110
|
if (editor.snapshot.context.selection) {
|
|
8084
8111
|
let selection = {
|
|
@@ -8223,6 +8250,29 @@ function applyOperation(editor, op) {
|
|
|
8223
8250
|
});
|
|
8224
8251
|
}
|
|
8225
8252
|
}
|
|
8253
|
+
function targetsStructuralChildren(editor, path2) {
|
|
8254
|
+
if (path2.length < 2)
|
|
8255
|
+
return !0;
|
|
8256
|
+
const fieldSegment = path2[path2.length - 2];
|
|
8257
|
+
return typeof fieldSegment != "string" ? !0 : getChildFieldName({
|
|
8258
|
+
schema: editor.snapshot.context.schema,
|
|
8259
|
+
containers: editor.snapshot.context.containers,
|
|
8260
|
+
value: editor.snapshot.context.value
|
|
8261
|
+
}, path2.slice(0, -2)) === fieldSegment;
|
|
8262
|
+
}
|
|
8263
|
+
function applyOnRootBlock(editor, path2, patch) {
|
|
8264
|
+
const blockSegment = findBlockSegment(path2);
|
|
8265
|
+
if (!blockSegment)
|
|
8266
|
+
return;
|
|
8267
|
+
const blockIndex = resolveBlockIndex(editor, blockSegment);
|
|
8268
|
+
if (blockIndex === -1)
|
|
8269
|
+
return;
|
|
8270
|
+
const block = editor.snapshot.context.value[blockIndex];
|
|
8271
|
+
if (!block)
|
|
8272
|
+
return;
|
|
8273
|
+
const updatedBlock = applyAll(block, [patch]), newValue = editor.snapshot.context.value.slice();
|
|
8274
|
+
newValue[blockIndex] = updatedBlock, editor.snapshot.context.value = newValue;
|
|
8275
|
+
}
|
|
8226
8276
|
function replaceLastSegment(path2, segment) {
|
|
8227
8277
|
if (path2.length === 0)
|
|
8228
8278
|
return [segment];
|
|
@@ -10124,8 +10174,19 @@ function createApplyPatch(context) {
|
|
|
10124
10174
|
};
|
|
10125
10175
|
}
|
|
10126
10176
|
function diffMatchPatch(editor, patch) {
|
|
10127
|
-
if (patch.path.at(-1) !== "text")
|
|
10128
|
-
|
|
10177
|
+
if (patch.path.at(-1) !== "text") {
|
|
10178
|
+
const currentValue = getValue(editor.snapshot.context.value, patch.path);
|
|
10179
|
+
if (typeof currentValue != "string")
|
|
10180
|
+
return !1;
|
|
10181
|
+
const [newValue2] = apply(parse(patch.value), currentValue, {
|
|
10182
|
+
allowExceedingIndices: !0
|
|
10183
|
+
});
|
|
10184
|
+
return editor.apply({
|
|
10185
|
+
type: "set",
|
|
10186
|
+
path: patch.path,
|
|
10187
|
+
value: newValue2
|
|
10188
|
+
}), !0;
|
|
10189
|
+
}
|
|
10129
10190
|
const spanPath = patch.path.slice(0, -1), spanEntry = getNode(editor.snapshot, spanPath);
|
|
10130
10191
|
if (!spanEntry || !isSpan({
|
|
10131
10192
|
schema: editor.snapshot.context.schema
|