@portabletext/editor 2.21.3 → 2.21.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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "2.21.
|
|
3
|
+
"version": "2.21.4",
|
|
4
4
|
"description": "Portable Text Editor made in React",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sanity",
|
|
@@ -73,9 +73,9 @@
|
|
|
73
73
|
"slate-dom": "^0.119.0",
|
|
74
74
|
"slate-react": "0.119.0",
|
|
75
75
|
"xstate": "^5.24.0",
|
|
76
|
-
"@portabletext/block-tools": "^4.0.2",
|
|
77
76
|
"@portabletext/keyboard-shortcuts": "^2.1.0",
|
|
78
77
|
"@portabletext/patches": "^2.0.0",
|
|
78
|
+
"@portabletext/block-tools": "^4.0.2",
|
|
79
79
|
"@portabletext/schema": "^2.0.0"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
@@ -107,8 +107,8 @@
|
|
|
107
107
|
"vitest": "^4.0.8",
|
|
108
108
|
"vitest-browser-react": "^2.0.2",
|
|
109
109
|
"@portabletext/sanity-bridge": "1.2.2",
|
|
110
|
-
"
|
|
111
|
-
"
|
|
110
|
+
"racejar": "2.0.0",
|
|
111
|
+
"@portabletext/test": "^1.0.0"
|
|
112
112
|
},
|
|
113
113
|
"peerDependencies": {
|
|
114
114
|
"@portabletext/sanity-bridge": "^1.2.2",
|
|
@@ -757,8 +757,10 @@ function syncBlock({
|
|
|
757
757
|
}
|
|
758
758
|
|
|
759
759
|
if (validation.valid || validation.resolution?.autoResolve) {
|
|
760
|
-
if (oldBlock._key === block._key) {
|
|
761
|
-
if (debug.enabled)
|
|
760
|
+
if (oldBlock._key === block._key && oldBlock._type === block._type) {
|
|
761
|
+
if (debug.enabled) {
|
|
762
|
+
debug('Updating block', oldBlock, block)
|
|
763
|
+
}
|
|
762
764
|
|
|
763
765
|
Editor.withoutNormalizing(slateEditor, () => {
|
|
764
766
|
withRemoteChanges(slateEditor, () => {
|
|
@@ -908,8 +910,11 @@ function updateBlock({
|
|
|
908
910
|
const path = [index, currentBlockChildIndex]
|
|
909
911
|
|
|
910
912
|
if (isChildChanged) {
|
|
911
|
-
// Update if this is the same child
|
|
912
|
-
if (
|
|
913
|
+
// Update if this is the same child (same key and type)
|
|
914
|
+
if (
|
|
915
|
+
currentBlockChild._key === oldBlockChild?._key &&
|
|
916
|
+
currentBlockChild._type === oldBlockChild?._type
|
|
917
|
+
) {
|
|
913
918
|
debug('Updating changed child', currentBlockChild, oldBlockChild)
|
|
914
919
|
|
|
915
920
|
Transforms.setNodes(slateEditor, currentBlockChild as Partial<Node>, {
|
|
@@ -949,7 +954,6 @@ function updateBlock({
|
|
|
949
954
|
)
|
|
950
955
|
}
|
|
951
956
|
} else if (oldBlockChild) {
|
|
952
|
-
// Replace the child if _key's are different
|
|
953
957
|
debug('Replacing child', currentBlockChild)
|
|
954
958
|
|
|
955
959
|
Transforms.removeNodes(slateEditor, {
|
|
@@ -141,6 +141,16 @@ describe('operationToPatches', () => {
|
|
|
141
141
|
),
|
|
142
142
|
).toMatchInlineSnapshot(`
|
|
143
143
|
[
|
|
144
|
+
{
|
|
145
|
+
"path": [
|
|
146
|
+
{
|
|
147
|
+
"_key": "1f2e64b47787",
|
|
148
|
+
},
|
|
149
|
+
"children",
|
|
150
|
+
],
|
|
151
|
+
"type": "setIfMissing",
|
|
152
|
+
"value": [],
|
|
153
|
+
},
|
|
144
154
|
{
|
|
145
155
|
"items": [
|
|
146
156
|
{
|
|
@@ -285,6 +295,16 @@ describe('operationToPatches', () => {
|
|
|
285
295
|
),
|
|
286
296
|
).toMatchInlineSnapshot(`
|
|
287
297
|
[
|
|
298
|
+
{
|
|
299
|
+
"path": [
|
|
300
|
+
{
|
|
301
|
+
"_key": "1f2e64b47787",
|
|
302
|
+
},
|
|
303
|
+
"children",
|
|
304
|
+
],
|
|
305
|
+
"type": "setIfMissing",
|
|
306
|
+
"value": [],
|
|
307
|
+
},
|
|
288
308
|
{
|
|
289
309
|
"items": [
|
|
290
310
|
{
|
|
@@ -314,6 +314,9 @@ export function insertNodePatch(
|
|
|
314
314
|
node._type = 'span'
|
|
315
315
|
node.marks = []
|
|
316
316
|
}
|
|
317
|
+
|
|
318
|
+
// Defensive setIfMissing to ensure children array exists before inserting
|
|
319
|
+
const setIfMissingPatch = setIfMissing([], [{_key: block._key}, 'children'])
|
|
317
320
|
const blk = fromSlateValue(
|
|
318
321
|
[
|
|
319
322
|
{
|
|
@@ -326,6 +329,7 @@ export function insertNodePatch(
|
|
|
326
329
|
)[0] as PortableTextTextBlock
|
|
327
330
|
const child = blk.children[0]
|
|
328
331
|
return [
|
|
332
|
+
setIfMissingPatch,
|
|
329
333
|
insert([child], position, [
|
|
330
334
|
{_key: block._key},
|
|
331
335
|
'children',
|
|
@@ -389,6 +393,8 @@ export function splitNodePatch(
|
|
|
389
393
|
)[0] as PortableTextTextBlock
|
|
390
394
|
).children
|
|
391
395
|
|
|
396
|
+
// Defensive setIfMissing to ensure children array exists before inserting
|
|
397
|
+
patches.push(setIfMissing([], [{_key: splitBlock._key}, 'children']))
|
|
392
398
|
patches.push(
|
|
393
399
|
insert(targetSpans, 'after', [
|
|
394
400
|
{_key: splitBlock._key},
|
|
@@ -563,6 +569,8 @@ export function moveNodePatch(
|
|
|
563
569
|
fromSlateValue([block], schema.block.name)[0] as PortableTextTextBlock
|
|
564
570
|
).children[operation.path[1]]
|
|
565
571
|
patches.push(unset([{_key: block._key}, 'children', {_key: child._key}]))
|
|
572
|
+
// Defensive setIfMissing to ensure children array exists before inserting
|
|
573
|
+
patches.push(setIfMissing([], [{_key: targetBlock._key}, 'children']))
|
|
566
574
|
patches.push(
|
|
567
575
|
insert([childToInsert], position, [
|
|
568
576
|
{_key: targetBlock._key},
|