@wordpress/core-data 7.43.2-next.v.202604091042.0 → 7.44.0
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/CHANGELOG.md +1 -1
- package/build/hooks/use-entity-prop.cjs +1 -1
- package/build/hooks/use-entity-prop.cjs.map +2 -2
- package/build/queried-data/reducer.cjs +2 -1
- package/build/queried-data/reducer.cjs.map +2 -2
- package/build/utils/crdt-blocks.cjs +54 -26
- package/build/utils/crdt-blocks.cjs.map +2 -2
- package/build/utils/crdt-selection.cjs.map +2 -2
- package/build/utils/crdt.cjs.map +2 -2
- package/build-module/hooks/use-entity-prop.mjs +1 -1
- package/build-module/hooks/use-entity-prop.mjs.map +2 -2
- package/build-module/queried-data/reducer.mjs +2 -1
- package/build-module/queried-data/reducer.mjs.map +2 -2
- package/build-module/utils/crdt-blocks.mjs +54 -26
- package/build-module/utils/crdt-blocks.mjs.map +2 -2
- package/build-module/utils/crdt-selection.mjs.map +2 -2
- package/build-module/utils/crdt.mjs.map +2 -2
- package/build-types/queried-data/reducer.d.ts.map +1 -1
- package/build-types/utils/crdt-blocks.d.ts.map +1 -1
- package/build-types/utils/crdt-selection.d.ts.map +1 -1
- package/build-types/utils/crdt.d.ts.map +1 -1
- package/package.json +18 -18
- package/src/hooks/use-entity-prop.js +1 -1
- package/src/queried-data/reducer.js +3 -1
- package/src/queried-data/test/reducer.js +7 -0
- package/src/utils/crdt-blocks.ts +103 -36
- package/src/utils/crdt-selection.ts +0 -1
- package/src/utils/crdt.ts +0 -1
- package/src/utils/test/crdt-blocks.ts +544 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"crdt.d.ts","sourceRoot":"","sources":["../../src/utils/crdt.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"crdt.d.ts","sourceRoot":"","sources":["../../src/utils/crdt.ts"],"names":[],"mappings":"AASA,OAAO,EACN,KAAK,OAAO,EAIZ,KAAK,UAAU,EAC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M,CAAC;IACjB,KAAK,EAAE,CAAC,CAAC,IAAI,CAAC;CACd;AAED,eAAO,MAAM,sCAAsC,mBAAmB,CAAC;AAsCvE;;;;;;;;GAQG;AACH,wBAAgB,yBAAyB,CACxC,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,WAAW,EACpB,gBAAgB,EAAE,GAAG,CAAE,MAAM,CAAE,GAC7B,IAAI,CAoIN;AAMD;;;;;;;;;GASG;AACH,wBAAgB,yBAAyB,CACxC,IAAI,EAAE,OAAO,EACb,YAAY,EAAE,IAAI,EAClB,gBAAgB,EAAE,GAAG,CAAE,MAAM,CAAE,GAC7B,WAAW,CA2Ib;AAED;;;GAGG;AACH,eAAO,MAAM,iBAAiB,EAAE,UAI/B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,2BAA2B,EAAE,UAKzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/core-data",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.44.0",
|
|
4
4
|
"description": "Access to and manipulation of core WordPress entities.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -49,22 +49,22 @@
|
|
|
49
49
|
"build-module/index.mjs"
|
|
50
50
|
],
|
|
51
51
|
"dependencies": {
|
|
52
|
-
"@wordpress/api-fetch": "^7.
|
|
53
|
-
"@wordpress/block-editor": "^15.
|
|
54
|
-
"@wordpress/blocks": "^15.
|
|
55
|
-
"@wordpress/compose": "^7.
|
|
56
|
-
"@wordpress/data": "^10.
|
|
57
|
-
"@wordpress/deprecated": "^4.
|
|
58
|
-
"@wordpress/element": "^6.44.
|
|
59
|
-
"@wordpress/html-entities": "^4.
|
|
60
|
-
"@wordpress/i18n": "^6.17.
|
|
61
|
-
"@wordpress/is-shallow-equal": "^5.
|
|
62
|
-
"@wordpress/private-apis": "^1.
|
|
63
|
-
"@wordpress/rich-text": "^7.
|
|
64
|
-
"@wordpress/sync": "^1.
|
|
65
|
-
"@wordpress/undo-manager": "^1.
|
|
66
|
-
"@wordpress/url": "^4.
|
|
67
|
-
"@wordpress/warning": "^3.
|
|
52
|
+
"@wordpress/api-fetch": "^7.44.0",
|
|
53
|
+
"@wordpress/block-editor": "^15.17.0",
|
|
54
|
+
"@wordpress/blocks": "^15.17.0",
|
|
55
|
+
"@wordpress/compose": "^7.44.0",
|
|
56
|
+
"@wordpress/data": "^10.44.0",
|
|
57
|
+
"@wordpress/deprecated": "^4.44.0",
|
|
58
|
+
"@wordpress/element": "^6.44.0",
|
|
59
|
+
"@wordpress/html-entities": "^4.44.0",
|
|
60
|
+
"@wordpress/i18n": "^6.17.0",
|
|
61
|
+
"@wordpress/is-shallow-equal": "^5.44.0",
|
|
62
|
+
"@wordpress/private-apis": "^1.44.0",
|
|
63
|
+
"@wordpress/rich-text": "^7.44.0",
|
|
64
|
+
"@wordpress/sync": "^1.44.0",
|
|
65
|
+
"@wordpress/undo-manager": "^1.44.0",
|
|
66
|
+
"@wordpress/url": "^4.44.0",
|
|
67
|
+
"@wordpress/warning": "^3.44.0",
|
|
68
68
|
"change-case": "^4.1.2",
|
|
69
69
|
"equivalent-key-map": "^0.2.2",
|
|
70
70
|
"fast-deep-equal": "^3.1.3",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
"publishConfig": {
|
|
85
85
|
"access": "public"
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "b862d8c84121a47bbeff882f6c87e61681ce2e0d"
|
|
88
88
|
}
|
|
@@ -51,6 +51,7 @@ export function getMergedItemIds(
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
const nextItemIdsStartIndex = offset ?? ( page - 1 ) * perPage;
|
|
54
|
+
const nextItemIdsRange = Math.max( perPage, nextItemIds.length );
|
|
54
55
|
|
|
55
56
|
// If later page has already been received, default to the larger known
|
|
56
57
|
// size of the existing array, else calculate as extending the existing.
|
|
@@ -67,7 +68,8 @@ export function getMergedItemIds(
|
|
|
67
68
|
// We need to check against the possible maximum upper boundary because
|
|
68
69
|
// a page could receive fewer than what was previously stored.
|
|
69
70
|
const isInNextItemsRange =
|
|
70
|
-
i >= nextItemIdsStartIndex &&
|
|
71
|
+
i >= nextItemIdsStartIndex &&
|
|
72
|
+
i < nextItemIdsStartIndex + nextItemIdsRange;
|
|
71
73
|
if ( isInNextItemsRange ) {
|
|
72
74
|
mergedItemIds[ i ] = nextItemIds[ i - nextItemIdsStartIndex ];
|
|
73
75
|
} else {
|
|
@@ -100,6 +100,13 @@ describe( 'getMergedItemIds', () => {
|
|
|
100
100
|
|
|
101
101
|
expect( result ).toEqual( [ 1, 2, 9, undefined, 5, 6 ] );
|
|
102
102
|
} );
|
|
103
|
+
|
|
104
|
+
it( 'should keep all received IDs when response exceeds default perPage', () => {
|
|
105
|
+
const nextItemIds = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ];
|
|
106
|
+
const result = getMergedItemIds( [], nextItemIds );
|
|
107
|
+
|
|
108
|
+
expect( result ).toEqual( nextItemIds );
|
|
109
|
+
} );
|
|
103
110
|
} );
|
|
104
111
|
|
|
105
112
|
describe( 'itemIsComplete', () => {
|
package/src/utils/crdt-blocks.ts
CHANGED
|
@@ -7,7 +7,6 @@ import fastDeepEqual from 'fast-deep-equal/es6/index.js';
|
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
|
-
// @ts-expect-error No exported types.
|
|
11
10
|
import { getBlockTypes } from '@wordpress/blocks';
|
|
12
11
|
import { RichTextData } from '@wordpress/rich-text';
|
|
13
12
|
import { Y } from '@wordpress/sync';
|
|
@@ -458,6 +457,7 @@ export function mergeCrdtBlocks(
|
|
|
458
457
|
for ( let i = 0; i < numOfUpdatesNeeded; i++, left++ ) {
|
|
459
458
|
const block = blocksToSync[ left ];
|
|
460
459
|
const yblock = yblocks.get( left );
|
|
460
|
+
|
|
461
461
|
Object.entries( block ).forEach( ( [ key, value ] ) => {
|
|
462
462
|
switch ( key ) {
|
|
463
463
|
case 'attributes': {
|
|
@@ -581,13 +581,33 @@ export function mergeCrdtBlocks(
|
|
|
581
581
|
}
|
|
582
582
|
}
|
|
583
583
|
|
|
584
|
+
/**
|
|
585
|
+
* Compare a plain array element against a Y.Map element for equality.
|
|
586
|
+
* Used by the left-right sweep diff in mergeYArray.
|
|
587
|
+
*
|
|
588
|
+
* @param newElement The plain object from the incoming array.
|
|
589
|
+
* @param yElement The Y.Map element from the existing Y.Array.
|
|
590
|
+
* @return True if the elements are deeply equal.
|
|
591
|
+
*/
|
|
592
|
+
function areArrayElementsEqual(
|
|
593
|
+
newElement: unknown,
|
|
594
|
+
yElement: unknown
|
|
595
|
+
): boolean {
|
|
596
|
+
if ( yElement instanceof Y.Map && isRecord( newElement ) ) {
|
|
597
|
+
return fastDeepEqual( newElement, yElement.toJSON() );
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
return fastDeepEqual( newElement, yElement );
|
|
601
|
+
}
|
|
602
|
+
|
|
584
603
|
/**
|
|
585
604
|
* Merge an incoming plain array into an existing Y.Array in-place.
|
|
586
605
|
*
|
|
587
|
-
*
|
|
588
|
-
*
|
|
589
|
-
*
|
|
590
|
-
*
|
|
606
|
+
* Uses the same left-right sweep diff approach as mergeCrdtBlocks:
|
|
607
|
+
* equal elements are skipped from both ends, then the middle section
|
|
608
|
+
* is updated, deleted, or inserted as needed. This preserves existing
|
|
609
|
+
* Y.Map/Y.Text objects for unchanged elements, so concurrent edits
|
|
610
|
+
* to those elements are not lost.
|
|
591
611
|
*
|
|
592
612
|
* @param yArray The existing Y.Array to update.
|
|
593
613
|
* @param newValue The new plain array to merge into the Y.Array.
|
|
@@ -605,40 +625,87 @@ function mergeYArray(
|
|
|
605
625
|
}
|
|
606
626
|
|
|
607
627
|
const query = schema.query;
|
|
628
|
+
const numOfCommonEntries = Math.min( newValue.length, yArray.length );
|
|
608
629
|
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
630
|
+
let left = 0;
|
|
631
|
+
let right = 0;
|
|
632
|
+
|
|
633
|
+
// Skip equal elements from left.
|
|
634
|
+
for (
|
|
635
|
+
;
|
|
636
|
+
left < numOfCommonEntries &&
|
|
637
|
+
areArrayElementsEqual( newValue[ left ], yArray.get( left ) );
|
|
638
|
+
left++
|
|
639
|
+
) {
|
|
640
|
+
/* nop */
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// Skip equal elements from right.
|
|
644
|
+
for (
|
|
645
|
+
;
|
|
646
|
+
right < numOfCommonEntries - left &&
|
|
647
|
+
areArrayElementsEqual(
|
|
648
|
+
newValue[ newValue.length - right - 1 ],
|
|
649
|
+
yArray.get( yArray.length - right - 1 )
|
|
650
|
+
);
|
|
651
|
+
right++
|
|
652
|
+
) {
|
|
653
|
+
/* nop */
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
// Updates: merge changed elements in-place.
|
|
657
|
+
const numOfUpdatesNeeded = numOfCommonEntries - left - right;
|
|
658
|
+
|
|
659
|
+
for ( let i = 0; i < numOfUpdatesNeeded; i++ ) {
|
|
660
|
+
const currentElement = yArray.get( left + i );
|
|
661
|
+
const newElement = newValue[ left + i ];
|
|
662
|
+
|
|
663
|
+
if ( currentElement instanceof Y.Map && isRecord( newElement ) ) {
|
|
664
|
+
mergeYMapValues(
|
|
665
|
+
currentElement,
|
|
666
|
+
newElement,
|
|
667
|
+
query,
|
|
668
|
+
cursorPosition
|
|
669
|
+
);
|
|
670
|
+
} else {
|
|
671
|
+
// Element is the wrong type (e.g. partial migration) or the
|
|
672
|
+
// incoming value is not an object. Rebuild the entire array.
|
|
673
|
+
yArray.delete( 0, yArray.length );
|
|
674
|
+
yArray.insert(
|
|
675
|
+
0,
|
|
676
|
+
newValue.map( ( item ) => createYMapFromQuery( query, item ) )
|
|
677
|
+
);
|
|
678
|
+
return;
|
|
634
679
|
}
|
|
635
|
-
}
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
// Deletes.
|
|
683
|
+
const numOfDeletionsNeeded = Math.max( 0, yArray.length - newValue.length );
|
|
684
|
+
|
|
685
|
+
if ( numOfDeletionsNeeded > 0 ) {
|
|
686
|
+
yArray.delete( left + numOfUpdatesNeeded, numOfDeletionsNeeded );
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// Inserts.
|
|
690
|
+
const numOfInsertionsNeeded = Math.max(
|
|
691
|
+
0,
|
|
692
|
+
newValue.length - yArray.length
|
|
693
|
+
);
|
|
694
|
+
|
|
695
|
+
if ( numOfInsertionsNeeded > 0 ) {
|
|
696
|
+
const insertAt = left + numOfUpdatesNeeded;
|
|
697
|
+
const itemsToInsert: Y.Map< unknown >[] = new Array(
|
|
698
|
+
numOfInsertionsNeeded
|
|
641
699
|
);
|
|
700
|
+
|
|
701
|
+
for ( let i = 0; i < numOfInsertionsNeeded; i++ ) {
|
|
702
|
+
itemsToInsert[ i ] = createYMapFromQuery(
|
|
703
|
+
query,
|
|
704
|
+
newValue[ insertAt + i ]
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
|
|
708
|
+
yArray.insert( insertAt, itemsToInsert );
|
|
642
709
|
}
|
|
643
710
|
}
|
|
644
711
|
|
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
import { dispatch, select } from '@wordpress/data';
|
|
5
5
|
// @ts-expect-error No exported types.
|
|
6
6
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
7
|
-
// @ts-expect-error No exported types.
|
|
8
7
|
import { isUnmodifiedBlock } from '@wordpress/blocks';
|
|
9
8
|
import { type CRDTDoc, Y } from '@wordpress/sync';
|
|
10
9
|
|