@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.
@@ -1 +1 @@
1
- {"version":3,"file":"crdt.d.ts","sourceRoot":"","sources":["../../src/utils/crdt.ts"],"names":[],"mappings":"AAUA,OAAO,EACN,KAAK,OAAO,EAIZ,KAAK,UAAU,EACf,CAAC,EACD,MAAM,iBAAiB,CAAC;AAMzB,OAAO,EAIN,KAAK,KAAK,EAEV,KAAK,OAAO,EACZ,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAEjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAM5C,OAAO,EAIN,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,MAAM,cAAc,CAAC;AAGtB,MAAM,MAAM,WAAW,GAAG,OAAO,CAAE,IAAI,CAAE,GAAG;IAC3C,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IACjB,OAAO,CAAC,EAAE,IAAI,CAAE,SAAS,CAAE,GAAG,MAAM,CAAC;IACrC,OAAO,CAAC,EAAE,IAAI,CAAE,SAAS,CAAE,GAAG,MAAM,CAAC;IACrC,SAAS,CAAC,EAAE,WAAW,CAAC;IACxB,KAAK,CAAC,EAAE,IAAI,CAAE,OAAO,CAAE,GAAG,MAAM,CAAC;CACjC,CAAC;AAGF,MAAM,WAAW,WAAY,SAAQ,UAAU;IAC9C,MAAM,EAAE,MAAM,CAAC;IAEf,MAAM,EAAE,OAAO,GAAG,SAAS,CAAC;IAC5B,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC;IAChB,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC;IAChB,cAAc,EAAE,MAA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,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.43.2-next.v.202604091042.0+668146787",
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.43.1-next.v.202604091042.0+668146787",
53
- "@wordpress/block-editor": "^15.16.1-next.v.202604091042.0+668146787",
54
- "@wordpress/blocks": "^15.16.1-next.v.202604091042.0+668146787",
55
- "@wordpress/compose": "^7.43.1-next.v.202604091042.0+668146787",
56
- "@wordpress/data": "^10.43.1-next.v.202604091042.0+668146787",
57
- "@wordpress/deprecated": "^4.43.1-next.v.202604091042.0+668146787",
58
- "@wordpress/element": "^6.44.1-next.v.202604091042.0+668146787",
59
- "@wordpress/html-entities": "^4.43.1-next.v.202604091042.0+668146787",
60
- "@wordpress/i18n": "^6.17.1-next.v.202604091042.0+668146787",
61
- "@wordpress/is-shallow-equal": "^5.43.1-next.v.202604091042.0+668146787",
62
- "@wordpress/private-apis": "^1.43.1-next.v.202604091042.0+668146787",
63
- "@wordpress/rich-text": "^7.43.1-next.v.202604091042.0+668146787",
64
- "@wordpress/sync": "^1.43.1-next.v.202604091042.0+668146787",
65
- "@wordpress/undo-manager": "^1.43.1-next.v.202604091042.0+668146787",
66
- "@wordpress/url": "^4.43.1-next.v.202604091042.0+668146787",
67
- "@wordpress/warning": "^3.43.1-next.v.202604091042.0+668146787",
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": "73606df74f1c38a084bfa5db97205259ef817593"
87
+ "gitHead": "b862d8c84121a47bbeff882f6c87e61681ce2e0d"
88
88
  }
@@ -64,7 +64,7 @@ export default function useEntityProp( kind, name, prop, _id ) {
64
64
  );
65
65
  return revision
66
66
  ? {
67
- value: revision[ prop ],
67
+ value: revision[ prop ]?.raw ?? revision[ prop ],
68
68
  fullValue: revision[ prop ],
69
69
  }
70
70
  : {};
@@ -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 && i < nextItemIdsStartIndex + perPage;
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', () => {
@@ -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
- * When the array length is unchanged (stable structure), each element is
588
- * merged individually via `mergeYMapValues`, preserving concurrent edits to
589
- * different elements. When the length changes (structural edit such as row
590
- * insertion/deletion), the Y.Array is rebuilt from scratch.
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
- if ( yArray.length === newValue.length ) {
610
- // Same length: update each element in-place.
611
- for ( let i = 0; i < newValue.length; i++ ) {
612
- const currentElement = yArray.get( i );
613
- const newElement = newValue[ i ];
614
-
615
- if ( currentElement instanceof Y.Map && isRecord( newElement ) ) {
616
- mergeYMapValues(
617
- currentElement,
618
- newElement,
619
- query,
620
- cursorPosition
621
- );
622
- } else {
623
- // Element is the wrong type (e.g. partial migration) or the
624
- // incoming value is not an object. Rebuild the entire array.
625
- yArray.delete( 0, yArray.length );
626
- yArray.insert(
627
- 0,
628
- newValue.map( ( item ) =>
629
- createYMapFromQuery( query, item )
630
- )
631
- );
632
- return;
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
- } else {
636
- // Structure changed: rebuild the Y.Array.
637
- yArray.delete( 0, yArray.length );
638
- yArray.insert(
639
- 0,
640
- newValue.map( ( item ) => createYMapFromQuery( query, item ) )
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
 
package/src/utils/crdt.ts CHANGED
@@ -6,7 +6,6 @@ import fastDeepEqual from 'fast-deep-equal/es6/index.js';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- // @ts-expect-error No exported types.
10
9
  import { __unstableSerializeAndClean } from '@wordpress/blocks';
11
10
  import {
12
11
  type CRDTDoc,