@portabletext/editor 4.3.2 → 4.3.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/index.js +14 -8
- package/lib/index.js.map +1 -1
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -18,7 +18,7 @@ import { htmlToBlocks } from "@portabletext/block-tools";
|
|
|
18
18
|
import { toHTML } from "@portabletext/to-html";
|
|
19
19
|
import { markdownToPortableText, portableTextToMarkdown } from "@portabletext/markdown";
|
|
20
20
|
import { Schema } from "@sanity/schema";
|
|
21
|
-
import { applyAll, unset, insert,
|
|
21
|
+
import { applyAll, unset, insert, setIfMissing, set, diffMatchPatch as diffMatchPatch$1 } from "@portabletext/patches";
|
|
22
22
|
import { createKeyboardShortcut, code, underline, italic, bold, undo, redo } from "@portabletext/keyboard-shortcuts";
|
|
23
23
|
import { EditorContext } from "./_chunks-es/use-editor.js";
|
|
24
24
|
import { useEditor } from "./_chunks-es/use-editor.js";
|
|
@@ -5106,11 +5106,13 @@ function insertNodePatch(schema, children, operation, beforeValue) {
|
|
|
5106
5106
|
_key: block._key
|
|
5107
5107
|
}, "children", {
|
|
5108
5108
|
_key: block.children[operation.path[1] - 1]._key
|
|
5109
|
-
}]
|
|
5109
|
+
}], setIfMissingPatch = setIfMissing([], [{
|
|
5110
|
+
_key: block._key
|
|
5111
|
+
}, "children"]);
|
|
5110
5112
|
if (Text.isText(operation.node))
|
|
5111
|
-
return [insert([operation.node], position, path)];
|
|
5113
|
+
return [setIfMissingPatch, insert([operation.node], position, path)];
|
|
5112
5114
|
const _type = operation.node._type, _key = operation.node._key, value = "value" in operation.node && typeof operation.node.value == "object" ? operation.node.value : {};
|
|
5113
|
-
return [insert([{
|
|
5115
|
+
return [setIfMissingPatch, insert([{
|
|
5114
5116
|
_type,
|
|
5115
5117
|
_key,
|
|
5116
5118
|
...value
|
|
@@ -5155,7 +5157,9 @@ function splitNodePatch(schema, children, operation, beforeValue) {
|
|
|
5155
5157
|
...splitBlock,
|
|
5156
5158
|
children: splitBlock.children.slice(operation.path[1] + 1, operation.path[1] + 2)
|
|
5157
5159
|
}, schema.block.name).children;
|
|
5158
|
-
patches.push(
|
|
5160
|
+
patches.push(setIfMissing([], [{
|
|
5161
|
+
_key: splitBlock._key
|
|
5162
|
+
}, "children"])), patches.push(insert(targetSpans, "after", [{
|
|
5159
5163
|
_key: splitBlock._key
|
|
5160
5164
|
}, "children", {
|
|
5161
5165
|
_key: splitSpan._key
|
|
@@ -5249,7 +5253,9 @@ function moveNodePatch(schema, beforeValue, operation) {
|
|
|
5249
5253
|
_key: block._key
|
|
5250
5254
|
}, "children", {
|
|
5251
5255
|
_key: child._key
|
|
5252
|
-
}])), patches.push(
|
|
5256
|
+
}])), patches.push(setIfMissing([], [{
|
|
5257
|
+
_key: targetBlock._key
|
|
5258
|
+
}, "children"])), patches.push(insert([childToInsert], position, [{
|
|
5253
5259
|
_key: targetBlock._key
|
|
5254
5260
|
}, "children", {
|
|
5255
5261
|
_key: targetChild._key
|
|
@@ -12901,7 +12907,7 @@ function syncBlock({
|
|
|
12901
12907
|
type: "patch",
|
|
12902
12908
|
patch
|
|
12903
12909
|
});
|
|
12904
|
-
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === block._key ? (debug.syncValue("Updating block", oldBlock, block), Editor.withoutNormalizing(slateEditor, () => {
|
|
12910
|
+
})), validation.valid || validation.resolution?.autoResolve ? (oldBlock._key === block._key && oldBlock._type === block._type ? (debug.syncValue("Updating block", oldBlock, block), Editor.withoutNormalizing(slateEditor, () => {
|
|
12905
12911
|
withRemoteChanges(slateEditor, () => {
|
|
12906
12912
|
withoutPatching(slateEditor, () => {
|
|
12907
12913
|
updateBlock({
|
|
@@ -12973,7 +12979,7 @@ function updateBlock({
|
|
|
12973
12979
|
}), slateBlock.children.forEach((currentBlockChild, currentBlockChildIndex) => {
|
|
12974
12980
|
const oldBlockChild = oldSlateBlock.children.at(currentBlockChildIndex), isChildChanged = !oldBlockChild || !isEqualChild(currentBlockChild, oldBlockChild), isTextChanged = oldBlockChild && Text.isText(oldBlockChild) && currentBlockChild.text !== oldBlockChild.text, path = [index, currentBlockChildIndex];
|
|
12975
12981
|
if (isChildChanged)
|
|
12976
|
-
if (currentBlockChild._key === oldBlockChild?._key) {
|
|
12982
|
+
if (currentBlockChild._key === oldBlockChild?._key && currentBlockChild._type === oldBlockChild?._type) {
|
|
12977
12983
|
debug.syncValue("Updating changed child", currentBlockChild, oldBlockChild), Transforms.setNodes(slateEditor, currentBlockChild, {
|
|
12978
12984
|
at: path
|
|
12979
12985
|
});
|