@wordpress/core-data 7.41.0 → 7.41.2-next.v.202603102151.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.
Files changed (79) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/actions.cjs +8 -6
  3. package/build/actions.cjs.map +2 -2
  4. package/build/entity-provider.cjs +15 -6
  5. package/build/entity-provider.cjs.map +2 -2
  6. package/build/hooks/use-entity-prop.cjs +32 -2
  7. package/build/hooks/use-entity-prop.cjs.map +2 -2
  8. package/build/private-actions.cjs +1 -1
  9. package/build/private-actions.cjs.map +2 -2
  10. package/build/queried-data/actions.cjs +1 -1
  11. package/build/queried-data/actions.cjs.map +2 -2
  12. package/build/queried-data/reducer.cjs +19 -13
  13. package/build/queried-data/reducer.cjs.map +2 -2
  14. package/build/reducer.cjs +2 -1
  15. package/build/reducer.cjs.map +2 -2
  16. package/build/resolvers.cjs +4 -2
  17. package/build/resolvers.cjs.map +2 -2
  18. package/build/sync.cjs +3 -0
  19. package/build/sync.cjs.map +2 -2
  20. package/build/utils/crdt-blocks.cjs +22 -26
  21. package/build/utils/crdt-blocks.cjs.map +2 -2
  22. package/build/utils/crdt.cjs +1 -3
  23. package/build/utils/crdt.cjs.map +2 -2
  24. package/build/utils/user-permissions.cjs +1 -4
  25. package/build/utils/user-permissions.cjs.map +2 -2
  26. package/build-module/actions.mjs +13 -7
  27. package/build-module/actions.mjs.map +2 -2
  28. package/build-module/entity-provider.mjs +15 -6
  29. package/build-module/entity-provider.mjs.map +2 -2
  30. package/build-module/hooks/use-entity-prop.mjs +33 -3
  31. package/build-module/hooks/use-entity-prop.mjs.map +2 -2
  32. package/build-module/private-actions.mjs +1 -1
  33. package/build-module/private-actions.mjs.map +2 -2
  34. package/build-module/queried-data/actions.mjs +1 -1
  35. package/build-module/queried-data/actions.mjs.map +2 -2
  36. package/build-module/queried-data/reducer.mjs +19 -13
  37. package/build-module/queried-data/reducer.mjs.map +2 -2
  38. package/build-module/reducer.mjs +2 -1
  39. package/build-module/reducer.mjs.map +2 -2
  40. package/build-module/resolvers.mjs +4 -2
  41. package/build-module/resolvers.mjs.map +2 -2
  42. package/build-module/sync.mjs +2 -0
  43. package/build-module/sync.mjs.map +2 -2
  44. package/build-module/utils/crdt-blocks.mjs +22 -26
  45. package/build-module/utils/crdt-blocks.mjs.map +2 -2
  46. package/build-module/utils/crdt.mjs +1 -3
  47. package/build-module/utils/crdt.mjs.map +2 -2
  48. package/build-module/utils/user-permissions.mjs +1 -4
  49. package/build-module/utils/user-permissions.mjs.map +2 -2
  50. package/build-types/actions.d.ts.map +1 -1
  51. package/build-types/entity-provider.d.ts +11 -6
  52. package/build-types/entity-provider.d.ts.map +1 -1
  53. package/build-types/hooks/use-entity-prop.d.ts.map +1 -1
  54. package/build-types/index.d.ts.map +1 -1
  55. package/build-types/queried-data/reducer.d.ts.map +1 -1
  56. package/build-types/reducer.d.ts.map +1 -1
  57. package/build-types/resolvers.d.ts.map +1 -1
  58. package/build-types/sync.d.ts +2 -2
  59. package/build-types/sync.d.ts.map +1 -1
  60. package/build-types/utils/crdt-blocks.d.ts.map +1 -1
  61. package/build-types/utils/crdt.d.ts.map +1 -1
  62. package/build-types/utils/user-permissions.d.ts.map +1 -1
  63. package/package.json +18 -18
  64. package/src/actions.js +24 -10
  65. package/src/entity-provider.js +24 -11
  66. package/src/hooks/use-entity-prop.js +41 -3
  67. package/src/private-actions.js +1 -1
  68. package/src/queried-data/actions.js +1 -1
  69. package/src/queried-data/reducer.js +26 -14
  70. package/src/reducer.js +4 -1
  71. package/src/resolvers.js +5 -3
  72. package/src/sync.ts +2 -0
  73. package/src/test/private-actions.js +1 -1
  74. package/src/test/resolvers.js +24 -3
  75. package/src/test/store.js +116 -0
  76. package/src/utils/crdt-blocks.ts +47 -54
  77. package/src/utils/crdt.ts +2 -5
  78. package/src/utils/test/crdt-blocks.ts +42 -24
  79. package/src/utils/user-permissions.js +4 -5
@@ -31,6 +31,13 @@ jest.mock( '@wordpress/blocks', () => ( {
31
31
  name: 'core/paragraph',
32
32
  attributes: { content: { type: 'rich-text' } },
33
33
  },
34
+ {
35
+ name: 'core/image',
36
+ attributes: {
37
+ blob: { type: 'string', role: 'local' },
38
+ url: { type: 'string' },
39
+ },
40
+ },
34
41
  ],
35
42
  } ) );
36
43
 
@@ -175,32 +182,30 @@ describe( 'crdt-blocks', () => {
175
182
  expect( innerBlock.get( 'name' ) ).toBe( 'core/paragraph' );
176
183
  } );
177
184
 
178
- it( 'skips gallery blocks with unuploaded images (blob attributes)', () => {
179
- const galleryWithBlobs: Block[] = [
185
+ it( 'strips local attributes when syncing blocks', () => {
186
+ const imageWithBlob: Block[] = [
180
187
  {
181
- name: 'core/gallery',
182
- attributes: {},
183
- innerBlocks: [
184
- {
185
- name: 'core/image',
186
- attributes: {
187
- url: 'http://example.com/image.jpg',
188
- blob: 'blob:...',
189
- },
190
- innerBlocks: [],
191
- },
192
- ],
188
+ name: 'core/image',
189
+ attributes: {
190
+ url: 'http://example.com/image.jpg',
191
+ blob: 'blob:...',
192
+ },
193
+ innerBlocks: [],
193
194
  },
194
195
  ];
195
196
 
196
- mergeCrdtBlocks( yblocks, galleryWithBlobs, null );
197
+ mergeCrdtBlocks( yblocks, imageWithBlob, null );
197
198
 
198
- // Gallery block should not be synced because it has blob attributes
199
- expect( yblocks.length ).toBe( 0 );
199
+ expect( yblocks.length ).toBe( 1 );
200
+ const block = yblocks.get( 0 );
201
+ expect( block.get( 'name' ) ).toBe( 'core/image' );
202
+ const attrs = block.get( 'attributes' ) as YBlockAttributes;
203
+ expect( attrs.get( 'url' ) ).toBe( 'http://example.com/image.jpg' );
204
+ expect( attrs.has( 'blob' ) ).toBe( false );
200
205
  } );
201
206
 
202
- it( 'syncs gallery blocks without blob attributes', () => {
203
- const galleryWithoutBlobs: Block[] = [
207
+ it( 'strips local attributes from inner blocks', () => {
208
+ const galleryWithBlobs: Block[] = [
204
209
  {
205
210
  name: 'core/gallery',
206
211
  attributes: {},
@@ -209,6 +214,7 @@ describe( 'crdt-blocks', () => {
209
214
  name: 'core/image',
210
215
  attributes: {
211
216
  url: 'http://example.com/image.jpg',
217
+ blob: 'blob:...',
212
218
  },
213
219
  innerBlocks: [],
214
220
  },
@@ -216,11 +222,17 @@ describe( 'crdt-blocks', () => {
216
222
  },
217
223
  ];
218
224
 
219
- mergeCrdtBlocks( yblocks, galleryWithoutBlobs, null );
225
+ mergeCrdtBlocks( yblocks, galleryWithBlobs, null );
220
226
 
221
227
  expect( yblocks.length ).toBe( 1 );
222
- const block = yblocks.get( 0 );
223
- expect( block.get( 'name' ) ).toBe( 'core/gallery' );
228
+ const gallery = yblocks.get( 0 );
229
+ expect( gallery.get( 'name' ) ).toBe( 'core/gallery' );
230
+ const innerBlocks = gallery.get( 'innerBlocks' ) as YBlocks;
231
+ expect( innerBlocks.length ).toBe( 1 );
232
+ const image = innerBlocks.get( 0 );
233
+ const attrs = image.get( 'attributes' ) as YBlockAttributes;
234
+ expect( attrs.get( 'url' ) ).toBe( 'http://example.com/image.jpg' );
235
+ expect( attrs.has( 'blob' ) ).toBe( false );
224
236
  } );
225
237
 
226
238
  it( 'handles block reordering', () => {
@@ -522,7 +534,7 @@ describe( 'crdt-blocks', () => {
522
534
  expect( content2.toString() ).toBe( 'Freeform content' );
523
535
  } );
524
536
 
525
- it( 'syncs nested blocks with blob attributes', () => {
537
+ it( 'strips local attributes from deeply nested blocks', () => {
526
538
  const nestedGallery: Block[] = [
527
539
  {
528
540
  name: 'core/group',
@@ -554,7 +566,13 @@ describe( 'crdt-blocks', () => {
554
566
 
555
567
  const innerBlocks = groupBlock.get( 'innerBlocks' ) as YBlocks;
556
568
  expect( innerBlocks.length ).toBe( 1 );
557
- expect( innerBlocks.get( 0 ).get( 'name' ) ).toBe( 'core/gallery' );
569
+ const gallery = innerBlocks.get( 0 );
570
+ const galleryInner = gallery.get( 'innerBlocks' ) as YBlocks;
571
+ expect( galleryInner.length ).toBe( 1 );
572
+ const image = galleryInner.get( 0 );
573
+ const attrs = image.get( 'attributes' ) as YBlockAttributes;
574
+ expect( attrs.get( 'url' ) ).toBe( 'http://example.com/image.jpg' );
575
+ expect( attrs.has( 'blob' ) ).toBe( false );
558
576
  } );
559
577
 
560
578
  it( 'handles complex block reordering', () => {
@@ -7,18 +7,17 @@ export const ALLOWED_RESOURCE_ACTIONS = [
7
7
 
8
8
  export function getUserPermissionsFromAllowHeader( allowedMethods ) {
9
9
  const permissions = {};
10
- if ( ! allowedMethods ) {
11
- return permissions;
12
- }
13
-
14
10
  const methods = {
15
11
  create: 'POST',
16
12
  read: 'GET',
17
13
  update: 'PUT',
18
14
  delete: 'DELETE',
19
15
  };
16
+
20
17
  for ( const [ actionName, methodName ] of Object.entries( methods ) ) {
21
- permissions[ actionName ] = allowedMethods.includes( methodName );
18
+ permissions[ actionName ] = allowedMethods
19
+ ? allowedMethods.includes( methodName )
20
+ : false;
22
21
  }
23
22
 
24
23
  return permissions;