@wordpress/core-data 6.10.0 → 6.12.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 (114) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +4 -0
  3. package/build/actions.js +252 -276
  4. package/build/actions.js.map +1 -1
  5. package/build/batch/create-batch.js +8 -16
  6. package/build/batch/create-batch.js.map +1 -1
  7. package/build/batch/default-processor.js +1 -1
  8. package/build/batch/default-processor.js.map +1 -1
  9. package/build/entities.js +16 -25
  10. package/build/entities.js.map +1 -1
  11. package/build/entity-provider.js +12 -17
  12. package/build/entity-provider.js.map +1 -1
  13. package/build/fetch/__experimental-fetch-link-suggestions.js +2 -6
  14. package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  15. package/build/fetch/__experimental-fetch-url-data.js +1 -2
  16. package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
  17. package/build/hooks/use-entity-record.js +7 -11
  18. package/build/hooks/use-entity-record.js.map +1 -1
  19. package/build/hooks/use-entity-records.js +3 -5
  20. package/build/hooks/use-entity-records.js.map +1 -1
  21. package/build/hooks/use-query-select.js +1 -6
  22. package/build/hooks/use-query-select.js.map +1 -1
  23. package/build/index.js +1 -7
  24. package/build/index.js.map +1 -1
  25. package/build/locks/actions.js +3 -4
  26. package/build/locks/actions.js.map +1 -1
  27. package/build/locks/reducer.js +1 -4
  28. package/build/locks/reducer.js.map +1 -1
  29. package/build/locks/selectors.js +3 -4
  30. package/build/locks/selectors.js.map +1 -1
  31. package/build/locks/utils.js +3 -5
  32. package/build/locks/utils.js.map +1 -1
  33. package/build/private-selectors.js +37 -0
  34. package/build/private-selectors.js.map +1 -0
  35. package/build/queried-data/actions.js +2 -5
  36. package/build/queried-data/actions.js.map +1 -1
  37. package/build/queried-data/reducer.js +17 -47
  38. package/build/queried-data/reducer.js.map +1 -1
  39. package/build/queried-data/selectors.js +4 -11
  40. package/build/queried-data/selectors.js.map +1 -1
  41. package/build/reducer.js +167 -194
  42. package/build/reducer.js.map +1 -1
  43. package/build/resolvers.js +175 -220
  44. package/build/resolvers.js.map +1 -1
  45. package/build/selectors.js +53 -61
  46. package/build/selectors.js.map +1 -1
  47. package/build/utils/forward-resolver.js +4 -11
  48. package/build/utils/forward-resolver.js.map +1 -1
  49. package/build/utils/on-sub-key.js +1 -3
  50. package/build/utils/on-sub-key.js.map +1 -1
  51. package/build-module/actions.js +251 -276
  52. package/build-module/actions.js.map +1 -1
  53. package/build-module/batch/create-batch.js +8 -16
  54. package/build-module/batch/create-batch.js.map +1 -1
  55. package/build-module/batch/default-processor.js +1 -1
  56. package/build-module/batch/default-processor.js.map +1 -1
  57. package/build-module/entities.js +16 -25
  58. package/build-module/entities.js.map +1 -1
  59. package/build-module/entity-provider.js +12 -17
  60. package/build-module/entity-provider.js.map +1 -1
  61. package/build-module/fetch/__experimental-fetch-link-suggestions.js +2 -6
  62. package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  63. package/build-module/fetch/__experimental-fetch-url-data.js +1 -2
  64. package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
  65. package/build-module/hooks/use-entity-record.js +7 -11
  66. package/build-module/hooks/use-entity-record.js.map +1 -1
  67. package/build-module/hooks/use-entity-records.js +3 -5
  68. package/build-module/hooks/use-entity-records.js.map +1 -1
  69. package/build-module/hooks/use-query-select.js +1 -6
  70. package/build-module/hooks/use-query-select.js.map +1 -1
  71. package/build-module/index.js +1 -7
  72. package/build-module/index.js.map +1 -1
  73. package/build-module/locks/actions.js +3 -4
  74. package/build-module/locks/actions.js.map +1 -1
  75. package/build-module/locks/reducer.js +1 -4
  76. package/build-module/locks/reducer.js.map +1 -1
  77. package/build-module/locks/selectors.js +3 -4
  78. package/build-module/locks/selectors.js.map +1 -1
  79. package/build-module/locks/utils.js +3 -5
  80. package/build-module/locks/utils.js.map +1 -1
  81. package/build-module/private-selectors.js +28 -0
  82. package/build-module/private-selectors.js.map +1 -0
  83. package/build-module/queried-data/actions.js +2 -5
  84. package/build-module/queried-data/actions.js.map +1 -1
  85. package/build-module/queried-data/reducer.js +17 -47
  86. package/build-module/queried-data/reducer.js.map +1 -1
  87. package/build-module/queried-data/selectors.js +4 -11
  88. package/build-module/queried-data/selectors.js.map +1 -1
  89. package/build-module/reducer.js +168 -194
  90. package/build-module/reducer.js.map +1 -1
  91. package/build-module/resolvers.js +175 -220
  92. package/build-module/resolvers.js.map +1 -1
  93. package/build-module/selectors.js +55 -61
  94. package/build-module/selectors.js.map +1 -1
  95. package/build-module/utils/forward-resolver.js +4 -11
  96. package/build-module/utils/forward-resolver.js.map +1 -1
  97. package/build-module/utils/on-sub-key.js +1 -3
  98. package/build-module/utils/on-sub-key.js.map +1 -1
  99. package/build-types/actions.d.ts.map +1 -1
  100. package/build-types/private-selectors.d.ts +25 -0
  101. package/build-types/private-selectors.d.ts.map +1 -0
  102. package/build-types/reducer.d.ts +6 -2
  103. package/build-types/reducer.d.ts.map +1 -1
  104. package/build-types/selectors.d.ts +16 -4
  105. package/build-types/selectors.d.ts.map +1 -1
  106. package/package.json +13 -13
  107. package/src/actions.js +9 -8
  108. package/src/index.js +0 -1
  109. package/src/private-selectors.ts +30 -0
  110. package/src/reducer.js +130 -104
  111. package/src/selectors.ts +33 -13
  112. package/src/test/reducer.js +89 -54
  113. package/src/test/selectors.js +8 -8
  114. package/tsconfig.tsbuildinfo +1 -1
@@ -22,10 +22,9 @@ import { forwardResolver, getNormalizedCommaSeparable } from './utils';
22
22
  * include with request.
23
23
  */
24
24
 
25
- export const getAuthors = query => async _ref => {
26
- let {
27
- dispatch
28
- } = _ref;
25
+ export const getAuthors = query => async ({
26
+ dispatch
27
+ }) => {
29
28
  const path = addQueryArgs('/wp/v2/users/?who=authors&per_page=100', query);
30
29
  const users = await apiFetch({
31
30
  path
@@ -36,10 +35,9 @@ export const getAuthors = query => async _ref => {
36
35
  * Requests the current user from the REST API.
37
36
  */
38
37
 
39
- export const getCurrentUser = () => async _ref2 => {
40
- let {
41
- dispatch
42
- } = _ref2;
38
+ export const getCurrentUser = () => async ({
39
+ dispatch
40
+ }) => {
43
41
  const currentUser = await apiFetch({
44
42
  path: '/wp/v2/users/me'
45
43
  });
@@ -56,67 +54,62 @@ export const getCurrentUser = () => async _ref2 => {
56
54
  * fields, fields must always include the ID.
57
55
  */
58
56
 
59
- export const getEntityRecord = function (kind, name) {
60
- let key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
61
- let query = arguments.length > 3 ? arguments[3] : undefined;
62
- return async _ref3 => {
63
- let {
64
- select,
65
- dispatch
66
- } = _ref3;
67
- const configs = await dispatch(getOrLoadEntitiesConfig(kind));
68
- const entityConfig = configs.find(config => config.name === name && config.kind === kind);
69
-
70
- if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
71
- return;
72
- }
57
+ export const getEntityRecord = (kind, name, key = '', query) => async ({
58
+ select,
59
+ dispatch
60
+ }) => {
61
+ const configs = await dispatch(getOrLoadEntitiesConfig(kind));
62
+ const entityConfig = configs.find(config => config.name === name && config.kind === kind);
73
63
 
74
- const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, key], {
75
- exclusive: false
76
- });
64
+ if (!entityConfig || entityConfig?.__experimentalNoFetch) {
65
+ return;
66
+ }
77
67
 
78
- try {
79
- if (query !== undefined && query._fields) {
80
- // If requesting specific fields, items and query association to said
81
- // records are stored by ID reference. Thus, fields must always include
82
- // the ID.
83
- query = { ...query,
84
- _fields: [...new Set([...(getNormalizedCommaSeparable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY])].join()
85
- };
86
- } // Disable reason: While true that an early return could leave `path`
87
- // unused, it's important that path is derived using the query prior to
88
- // additional query modifications in the condition below, since those
89
- // modifications are relevant to how the data is tracked in state, and not
90
- // for how the request is made to the REST API.
91
- // eslint-disable-next-line @wordpress/no-unused-vars-before-return
92
-
93
-
94
- const path = addQueryArgs(entityConfig.baseURL + (key ? '/' + key : ''), { ...entityConfig.baseURLParams,
95
- ...query
96
- });
68
+ const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name, key], {
69
+ exclusive: false
70
+ });
97
71
 
98
- if (query !== undefined) {
99
- query = { ...query,
100
- include: [key]
101
- }; // The resolution cache won't consider query as reusable based on the
102
- // fields, so it's tested here, prior to initiating the REST request,
103
- // and without causing `getEntityRecords` resolution to occur.
72
+ try {
73
+ if (query !== undefined && query._fields) {
74
+ // If requesting specific fields, items and query association to said
75
+ // records are stored by ID reference. Thus, fields must always include
76
+ // the ID.
77
+ query = { ...query,
78
+ _fields: [...new Set([...(getNormalizedCommaSeparable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY])].join()
79
+ };
80
+ } // Disable reason: While true that an early return could leave `path`
81
+ // unused, it's important that path is derived using the query prior to
82
+ // additional query modifications in the condition below, since those
83
+ // modifications are relevant to how the data is tracked in state, and not
84
+ // for how the request is made to the REST API.
85
+ // eslint-disable-next-line @wordpress/no-unused-vars-before-return
86
+
87
+
88
+ const path = addQueryArgs(entityConfig.baseURL + (key ? '/' + key : ''), { ...entityConfig.baseURLParams,
89
+ ...query
90
+ });
104
91
 
105
- const hasRecords = select.hasEntityRecords(kind, name, query);
92
+ if (query !== undefined) {
93
+ query = { ...query,
94
+ include: [key]
95
+ }; // The resolution cache won't consider query as reusable based on the
96
+ // fields, so it's tested here, prior to initiating the REST request,
97
+ // and without causing `getEntityRecords` resolution to occur.
106
98
 
107
- if (hasRecords) {
108
- return;
109
- }
110
- }
99
+ const hasRecords = select.hasEntityRecords(kind, name, query);
111
100
 
112
- const record = await apiFetch({
113
- path
114
- });
115
- dispatch.receiveEntityRecords(kind, name, record, query);
116
- } finally {
117
- dispatch.__unstableReleaseStoreLock(lock);
101
+ if (hasRecords) {
102
+ return;
103
+ }
118
104
  }
119
- };
105
+
106
+ const record = await apiFetch({
107
+ path
108
+ });
109
+ dispatch.receiveEntityRecords(kind, name, record, query);
110
+ } finally {
111
+ dispatch.__unstableReleaseStoreLock(lock);
112
+ }
120
113
  };
121
114
  /**
122
115
  * Requests an entity's record from the REST API.
@@ -137,78 +130,72 @@ export const getEditedEntityRecord = forwardResolver('getEntityRecord');
137
130
  * must always include the ID.
138
131
  */
139
132
 
140
- export const getEntityRecords = function (kind, name) {
141
- let query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
142
- return async _ref4 => {
143
- let {
144
- dispatch
145
- } = _ref4;
146
- const configs = await dispatch(getOrLoadEntitiesConfig(kind));
147
- const entityConfig = configs.find(config => config.name === name && config.kind === kind);
133
+ export const getEntityRecords = (kind, name, query = {}) => async ({
134
+ dispatch
135
+ }) => {
136
+ const configs = await dispatch(getOrLoadEntitiesConfig(kind));
137
+ const entityConfig = configs.find(config => config.name === name && config.kind === kind);
148
138
 
149
- if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
150
- return;
151
- }
139
+ if (!entityConfig || entityConfig?.__experimentalNoFetch) {
140
+ return;
141
+ }
152
142
 
153
- const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name], {
154
- exclusive: false
155
- });
143
+ const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'records', kind, name], {
144
+ exclusive: false
145
+ });
156
146
 
157
- try {
158
- var _query;
147
+ try {
148
+ if (query._fields) {
149
+ // If requesting specific fields, items and query association to said
150
+ // records are stored by ID reference. Thus, fields must always include
151
+ // the ID.
152
+ query = { ...query,
153
+ _fields: [...new Set([...(getNormalizedCommaSeparable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY])].join()
154
+ };
155
+ }
159
156
 
160
- if (query._fields) {
161
- // If requesting specific fields, items and query association to said
162
- // records are stored by ID reference. Thus, fields must always include
163
- // the ID.
164
- query = { ...query,
165
- _fields: [...new Set([...(getNormalizedCommaSeparable(query._fields) || []), entityConfig.key || DEFAULT_ENTITY_KEY])].join()
166
- };
167
- }
157
+ const path = addQueryArgs(entityConfig.baseURL, { ...entityConfig.baseURLParams,
158
+ ...query
159
+ });
160
+ let records = Object.values(await apiFetch({
161
+ path
162
+ })); // If we request fields but the result doesn't contain the fields,
163
+ // explicitly set these fields as "undefined"
164
+ // that way we consider the query "fullfilled".
165
+
166
+ if (query._fields) {
167
+ records = records.map(record => {
168
+ query._fields.split(',').forEach(field => {
169
+ if (!record.hasOwnProperty(field)) {
170
+ record[field] = undefined;
171
+ }
172
+ });
168
173
 
169
- const path = addQueryArgs(entityConfig.baseURL, { ...entityConfig.baseURLParams,
170
- ...query
174
+ return record;
171
175
  });
172
- let records = Object.values(await apiFetch({
173
- path
174
- })); // If we request fields but the result doesn't contain the fields,
175
- // explicitly set these fields as "undefined"
176
- // that way we consider the query "fullfilled".
177
-
178
- if (query._fields) {
179
- records = records.map(record => {
180
- query._fields.split(',').forEach(field => {
181
- if (!record.hasOwnProperty(field)) {
182
- record[field] = undefined;
183
- }
184
- });
185
-
186
- return record;
187
- });
188
- }
176
+ }
189
177
 
190
- dispatch.receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to
191
- // resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
192
- // See https://github.com/WordPress/gutenberg/pull/26575
193
-
194
- if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) {
195
- const key = entityConfig.key || DEFAULT_ENTITY_KEY;
196
- const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
197
- dispatch({
198
- type: 'START_RESOLUTIONS',
199
- selectorName: 'getEntityRecord',
200
- args: resolutionsArgs
201
- });
202
- dispatch({
203
- type: 'FINISH_RESOLUTIONS',
204
- selectorName: 'getEntityRecord',
205
- args: resolutionsArgs
206
- });
207
- }
208
- } finally {
209
- dispatch.__unstableReleaseStoreLock(lock);
178
+ dispatch.receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to
179
+ // resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
180
+ // See https://github.com/WordPress/gutenberg/pull/26575
181
+
182
+ if (!query?._fields && !query.context) {
183
+ const key = entityConfig.key || DEFAULT_ENTITY_KEY;
184
+ const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
185
+ dispatch({
186
+ type: 'START_RESOLUTIONS',
187
+ selectorName: 'getEntityRecord',
188
+ args: resolutionsArgs
189
+ });
190
+ dispatch({
191
+ type: 'FINISH_RESOLUTIONS',
192
+ selectorName: 'getEntityRecord',
193
+ args: resolutionsArgs
194
+ });
210
195
  }
211
- };
196
+ } finally {
197
+ dispatch.__unstableReleaseStoreLock(lock);
198
+ }
212
199
  };
213
200
 
214
201
  getEntityRecords.shouldInvalidate = (action, kind, name) => {
@@ -219,11 +206,10 @@ getEntityRecords.shouldInvalidate = (action, kind, name) => {
219
206
  */
220
207
 
221
208
 
222
- export const getCurrentTheme = () => async _ref5 => {
223
- let {
224
- dispatch,
225
- resolveSelect
226
- } = _ref5;
209
+ export const getCurrentTheme = () => async ({
210
+ dispatch,
211
+ resolveSelect
212
+ }) => {
227
213
  const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
228
214
  status: 'active'
229
215
  });
@@ -240,11 +226,9 @@ export const getThemeSupports = forwardResolver('getCurrentTheme');
240
226
  * @param {string} url URL to get the preview for.
241
227
  */
242
228
 
243
- export const getEmbedPreview = url => async _ref6 => {
244
- let {
245
- dispatch
246
- } = _ref6;
247
-
229
+ export const getEmbedPreview = url => async ({
230
+ dispatch
231
+ }) => {
248
232
  try {
249
233
  const embedProxyResponse = await apiFetch({
250
234
  path: addQueryArgs('/oembed/1.0/proxy', {
@@ -267,13 +251,10 @@ export const getEmbedPreview = url => async _ref6 => {
267
251
  * @param {?string} id ID of the rest resource to check.
268
252
  */
269
253
 
270
- export const canUser = (requestedAction, resource, id) => async _ref7 => {
271
- var _response$headers;
272
-
273
- let {
274
- dispatch,
275
- registry
276
- } = _ref7;
254
+ export const canUser = (requestedAction, resource, id) => async ({
255
+ dispatch,
256
+ registry
257
+ }) => {
277
258
  const {
278
259
  hasStartedResolution
279
260
  } = registry.select(STORE_NAME);
@@ -314,8 +295,8 @@ export const canUser = (requestedAction, resource, id) => async _ref7 => {
314
295
  // only return the result, without including response properties like the headers.
315
296
 
316
297
 
317
- const allowHeader = (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers.get('allow');
318
- const allowedMethods = (allowHeader === null || allowHeader === void 0 ? void 0 : allowHeader.allow) || allowHeader || '';
298
+ const allowHeader = response.headers?.get('allow');
299
+ const allowedMethods = allowHeader?.allow || allowHeader || '';
319
300
  const permissions = {};
320
301
  const methods = {
321
302
  create: 'POST',
@@ -341,10 +322,9 @@ export const canUser = (requestedAction, resource, id) => async _ref7 => {
341
322
  * @param {string} recordId Record's id.
342
323
  */
343
324
 
344
- export const canUserEditEntityRecord = (kind, name, recordId) => async _ref8 => {
345
- let {
346
- dispatch
347
- } = _ref8;
325
+ export const canUserEditEntityRecord = (kind, name, recordId) => async ({
326
+ dispatch
327
+ }) => {
348
328
  const configs = await dispatch(getOrLoadEntitiesConfig(kind));
349
329
  const entityConfig = configs.find(config => config.name === name && config.kind === kind);
350
330
 
@@ -362,11 +342,10 @@ export const canUserEditEntityRecord = (kind, name, recordId) => async _ref8 =>
362
342
  * @param {number} postId The id of the parent post.
363
343
  */
364
344
 
365
- export const getAutosaves = (postType, postId) => async _ref9 => {
366
- let {
367
- dispatch,
368
- resolveSelect
369
- } = _ref9;
345
+ export const getAutosaves = (postType, postId) => async ({
346
+ dispatch,
347
+ resolveSelect
348
+ }) => {
370
349
  const {
371
350
  rest_base: restBase,
372
351
  rest_namespace: restNamespace = 'wp/v2'
@@ -389,10 +368,9 @@ export const getAutosaves = (postType, postId) => async _ref9 => {
389
368
  * @param {number} postId The id of the parent post.
390
369
  */
391
370
 
392
- export const getAutosave = (postType, postId) => async _ref10 => {
393
- let {
394
- resolveSelect
395
- } = _ref10;
371
+ export const getAutosave = (postType, postId) => async ({
372
+ resolveSelect
373
+ }) => {
396
374
  await resolveSelect.getAutosaves(postType, postId);
397
375
  };
398
376
  /**
@@ -401,11 +379,10 @@ export const getAutosave = (postType, postId) => async _ref10 => {
401
379
  * @param {string} link Link.
402
380
  */
403
381
 
404
- export const __experimentalGetTemplateForLink = link => async _ref11 => {
405
- let {
406
- dispatch,
407
- resolveSelect
408
- } = _ref11;
382
+ export const __experimentalGetTemplateForLink = link => async ({
383
+ dispatch,
384
+ resolveSelect
385
+ }) => {
409
386
  let template;
410
387
 
411
388
  try {
@@ -415,12 +392,9 @@ export const __experimentalGetTemplateForLink = link => async _ref11 => {
415
392
  url: addQueryArgs(link, {
416
393
  '_wp-find-template': true
417
394
  })
418
- }).then(_ref12 => {
419
- let {
420
- data
421
- } = _ref12;
422
- return data;
423
- });
395
+ }).then(({
396
+ data
397
+ }) => data);
424
398
  } catch (e) {// For non-FSE themes, it is possible that this request returns an error.
425
399
  }
426
400
 
@@ -441,17 +415,14 @@ __experimentalGetTemplateForLink.shouldInvalidate = action => {
441
415
  return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template';
442
416
  };
443
417
 
444
- export const __experimentalGetCurrentGlobalStylesId = () => async _ref13 => {
445
- var _activeThemes$, _activeThemes$$_links, _activeThemes$$_links2, _activeThemes$$_links3;
446
-
447
- let {
448
- dispatch,
449
- resolveSelect
450
- } = _ref13;
418
+ export const __experimentalGetCurrentGlobalStylesId = () => async ({
419
+ dispatch,
420
+ resolveSelect
421
+ }) => {
451
422
  const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
452
423
  status: 'active'
453
424
  });
454
- const globalStylesURL = activeThemes === null || activeThemes === void 0 ? void 0 : (_activeThemes$ = activeThemes[0]) === null || _activeThemes$ === void 0 ? void 0 : (_activeThemes$$_links = _activeThemes$._links) === null || _activeThemes$$_links === void 0 ? void 0 : (_activeThemes$$_links2 = _activeThemes$$_links['wp:user-global-styles']) === null || _activeThemes$$_links2 === void 0 ? void 0 : (_activeThemes$$_links3 = _activeThemes$$_links2[0]) === null || _activeThemes$$_links3 === void 0 ? void 0 : _activeThemes$$_links3.href;
425
+ const globalStylesURL = activeThemes?.[0]?._links?.['wp:user-global-styles']?.[0]?.href;
455
426
 
456
427
  if (globalStylesURL) {
457
428
  const globalStylesObject = await apiFetch({
@@ -461,11 +432,10 @@ export const __experimentalGetCurrentGlobalStylesId = () => async _ref13 => {
461
432
  dispatch.__experimentalReceiveCurrentGlobalStylesId(globalStylesObject.id);
462
433
  }
463
434
  };
464
- export const __experimentalGetCurrentThemeBaseGlobalStyles = () => async _ref14 => {
465
- let {
466
- resolveSelect,
467
- dispatch
468
- } = _ref14;
435
+ export const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ({
436
+ resolveSelect,
437
+ dispatch
438
+ }) => {
469
439
  const currentTheme = await resolveSelect.getCurrentTheme();
470
440
  const themeGlobalStyles = await apiFetch({
471
441
  path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}`
@@ -473,11 +443,10 @@ export const __experimentalGetCurrentThemeBaseGlobalStyles = () => async _ref14
473
443
 
474
444
  dispatch.__experimentalReceiveThemeBaseGlobalStyles(currentTheme.stylesheet, themeGlobalStyles);
475
445
  };
476
- export const __experimentalGetCurrentThemeGlobalStylesVariations = () => async _ref15 => {
477
- let {
478
- resolveSelect,
479
- dispatch
480
- } = _ref15;
446
+ export const __experimentalGetCurrentThemeGlobalStylesVariations = () => async ({
447
+ resolveSelect,
448
+ dispatch
449
+ }) => {
481
450
  const currentTheme = await resolveSelect.getCurrentTheme();
482
451
  const variations = await apiFetch({
483
452
  path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}/variations`
@@ -489,25 +458,19 @@ export const __experimentalGetCurrentThemeGlobalStylesVariations = () => async _
489
458
  * Fetches and returns the revisions of the current global styles theme.
490
459
  */
491
460
 
492
- export const getCurrentThemeGlobalStylesRevisions = () => async _ref16 => {
493
- var _record$_links, _record$_links$versio, _record$_links$versio2;
494
-
495
- let {
496
- resolveSelect,
497
- dispatch
498
- } = _ref16;
461
+ export const getCurrentThemeGlobalStylesRevisions = () => async ({
462
+ resolveSelect,
463
+ dispatch
464
+ }) => {
499
465
  const globalStylesId = await resolveSelect.__experimentalGetCurrentGlobalStylesId();
500
466
  const record = globalStylesId ? await resolveSelect.getEntityRecord('root', 'globalStyles', globalStylesId) : undefined;
501
- const revisionsURL = record === null || record === void 0 ? void 0 : (_record$_links = record._links) === null || _record$_links === void 0 ? void 0 : (_record$_links$versio = _record$_links['version-history']) === null || _record$_links$versio === void 0 ? void 0 : (_record$_links$versio2 = _record$_links$versio[0]) === null || _record$_links$versio2 === void 0 ? void 0 : _record$_links$versio2.href;
467
+ const revisionsURL = record?._links?.['version-history']?.[0]?.href;
502
468
 
503
469
  if (revisionsURL) {
504
470
  const resetRevisions = await apiFetch({
505
471
  url: revisionsURL
506
472
  });
507
- const revisions = resetRevisions === null || resetRevisions === void 0 ? void 0 : resetRevisions.map(revision => Object.fromEntries(Object.entries(revision).map(_ref17 => {
508
- let [key, value] = _ref17;
509
- return [camelCase(key), value];
510
- })));
473
+ const revisions = resetRevisions?.map(revision => Object.fromEntries(Object.entries(revision).map(([key, value]) => [camelCase(key), value])));
511
474
  dispatch.receiveThemeGlobalStyleRevisions(globalStylesId, revisions);
512
475
  }
513
476
  };
@@ -516,26 +479,21 @@ getCurrentThemeGlobalStylesRevisions.shouldInvalidate = action => {
516
479
  return action.type === 'SAVE_ENTITY_RECORD_FINISH' && action.kind === 'root' && !action.error && action.name === 'globalStyles';
517
480
  };
518
481
 
519
- export const getBlockPatterns = () => async _ref18 => {
520
- let {
521
- dispatch
522
- } = _ref18;
482
+ export const getBlockPatterns = () => async ({
483
+ dispatch
484
+ }) => {
523
485
  const restPatterns = await apiFetch({
524
486
  path: '/wp/v2/block-patterns/patterns'
525
487
  });
526
- const patterns = restPatterns === null || restPatterns === void 0 ? void 0 : restPatterns.map(pattern => Object.fromEntries(Object.entries(pattern).map(_ref19 => {
527
- let [key, value] = _ref19;
528
- return [camelCase(key), value];
529
- })));
488
+ const patterns = restPatterns?.map(pattern => Object.fromEntries(Object.entries(pattern).map(([key, value]) => [camelCase(key), value])));
530
489
  dispatch({
531
490
  type: 'RECEIVE_BLOCK_PATTERNS',
532
491
  patterns
533
492
  });
534
493
  };
535
- export const getBlockPatternCategories = () => async _ref20 => {
536
- let {
537
- dispatch
538
- } = _ref20;
494
+ export const getBlockPatternCategories = () => async ({
495
+ dispatch
496
+ }) => {
539
497
  const categories = await apiFetch({
540
498
  path: '/wp/v2/block-patterns/categories'
541
499
  });
@@ -544,24 +502,21 @@ export const getBlockPatternCategories = () => async _ref20 => {
544
502
  categories
545
503
  });
546
504
  };
547
- export const getNavigationFallbackId = () => async _ref21 => {
548
- var _fallback$_embedded;
549
-
550
- let {
551
- dispatch
552
- } = _ref21;
505
+ export const getNavigationFallbackId = () => async ({
506
+ dispatch
507
+ }) => {
553
508
  const fallback = await apiFetch({
554
509
  path: addQueryArgs('/wp-block-editor/v1/navigation-fallback', {
555
510
  _embed: true
556
511
  })
557
512
  });
558
- const record = fallback === null || fallback === void 0 ? void 0 : (_fallback$_embedded = fallback._embedded) === null || _fallback$_embedded === void 0 ? void 0 : _fallback$_embedded.self;
559
- dispatch.receiveNavigationFallbackId(fallback === null || fallback === void 0 ? void 0 : fallback.id);
513
+ const record = fallback?._embedded?.self;
514
+ dispatch.receiveNavigationFallbackId(fallback?.id);
560
515
 
561
516
  if (record) {
562
517
  dispatch.receiveEntityRecords('postType', 'wp_navigation', record); // Resolve to avoid further network requests.
563
518
 
564
- dispatch.finishResolution('getEntityRecord', ['postType', 'wp_navigation', fallback === null || fallback === void 0 ? void 0 : fallback.id]);
519
+ dispatch.finishResolution('getEntityRecord', ['postType', 'wp_navigation', fallback?.id]);
565
520
  }
566
521
  };
567
522
  //# sourceMappingURL=resolvers.js.map