@wordpress/core-data 6.11.0 → 6.12.1

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 (131) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/README.md +5 -1
  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 +74 -23
  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 +11 -13
  18. package/build/hooks/use-entity-record.js.map +1 -1
  19. package/build/hooks/use-entity-records.js +4 -6
  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-apis.js +19 -0
  34. package/build/private-apis.js.map +1 -0
  35. package/build/private-selectors.js +37 -0
  36. package/build/private-selectors.js.map +1 -0
  37. package/build/queried-data/actions.js +2 -5
  38. package/build/queried-data/actions.js.map +1 -1
  39. package/build/queried-data/reducer.js +17 -47
  40. package/build/queried-data/reducer.js.map +1 -1
  41. package/build/queried-data/selectors.js +4 -11
  42. package/build/queried-data/selectors.js.map +1 -1
  43. package/build/reducer.js +167 -194
  44. package/build/reducer.js.map +1 -1
  45. package/build/resolvers.js +175 -220
  46. package/build/resolvers.js.map +1 -1
  47. package/build/selectors.js +53 -61
  48. package/build/selectors.js.map +1 -1
  49. package/build/utils/forward-resolver.js +4 -11
  50. package/build/utils/forward-resolver.js.map +1 -1
  51. package/build/utils/on-sub-key.js +1 -3
  52. package/build/utils/on-sub-key.js.map +1 -1
  53. package/build-module/actions.js +251 -276
  54. package/build-module/actions.js.map +1 -1
  55. package/build-module/batch/create-batch.js +8 -16
  56. package/build-module/batch/create-batch.js.map +1 -1
  57. package/build-module/batch/default-processor.js +1 -1
  58. package/build-module/batch/default-processor.js.map +1 -1
  59. package/build-module/entities.js +16 -25
  60. package/build-module/entities.js.map +1 -1
  61. package/build-module/entity-provider.js +71 -22
  62. package/build-module/entity-provider.js.map +1 -1
  63. package/build-module/fetch/__experimental-fetch-link-suggestions.js +2 -6
  64. package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  65. package/build-module/fetch/__experimental-fetch-url-data.js +1 -2
  66. package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
  67. package/build-module/hooks/use-entity-record.js +11 -13
  68. package/build-module/hooks/use-entity-record.js.map +1 -1
  69. package/build-module/hooks/use-entity-records.js +4 -6
  70. package/build-module/hooks/use-entity-records.js.map +1 -1
  71. package/build-module/hooks/use-query-select.js +1 -6
  72. package/build-module/hooks/use-query-select.js.map +1 -1
  73. package/build-module/index.js +1 -7
  74. package/build-module/index.js.map +1 -1
  75. package/build-module/locks/actions.js +3 -4
  76. package/build-module/locks/actions.js.map +1 -1
  77. package/build-module/locks/reducer.js +1 -4
  78. package/build-module/locks/reducer.js.map +1 -1
  79. package/build-module/locks/selectors.js +3 -4
  80. package/build-module/locks/selectors.js.map +1 -1
  81. package/build-module/locks/utils.js +3 -5
  82. package/build-module/locks/utils.js.map +1 -1
  83. package/build-module/private-apis.js +9 -0
  84. package/build-module/private-apis.js.map +1 -0
  85. package/build-module/private-selectors.js +28 -0
  86. package/build-module/private-selectors.js.map +1 -0
  87. package/build-module/queried-data/actions.js +2 -5
  88. package/build-module/queried-data/actions.js.map +1 -1
  89. package/build-module/queried-data/reducer.js +17 -47
  90. package/build-module/queried-data/reducer.js.map +1 -1
  91. package/build-module/queried-data/selectors.js +4 -11
  92. package/build-module/queried-data/selectors.js.map +1 -1
  93. package/build-module/reducer.js +168 -194
  94. package/build-module/reducer.js.map +1 -1
  95. package/build-module/resolvers.js +175 -220
  96. package/build-module/resolvers.js.map +1 -1
  97. package/build-module/selectors.js +55 -61
  98. package/build-module/selectors.js.map +1 -1
  99. package/build-module/utils/forward-resolver.js +4 -11
  100. package/build-module/utils/forward-resolver.js.map +1 -1
  101. package/build-module/utils/on-sub-key.js +1 -3
  102. package/build-module/utils/on-sub-key.js.map +1 -1
  103. package/build-types/actions.d.ts.map +1 -1
  104. package/build-types/entity-provider.d.ts.map +1 -1
  105. package/build-types/entity-types/wp-template.d.ts +4 -0
  106. package/build-types/entity-types/wp-template.d.ts.map +1 -1
  107. package/build-types/hooks/use-entity-record.d.ts.map +1 -1
  108. package/build-types/hooks/use-entity-records.d.ts +1 -1
  109. package/build-types/private-apis.d.ts +3 -0
  110. package/build-types/private-apis.d.ts.map +1 -0
  111. package/build-types/private-selectors.d.ts +25 -0
  112. package/build-types/private-selectors.d.ts.map +1 -0
  113. package/build-types/reducer.d.ts +6 -2
  114. package/build-types/reducer.d.ts.map +1 -1
  115. package/build-types/selectors.d.ts +16 -4
  116. package/build-types/selectors.d.ts.map +1 -1
  117. package/package.json +14 -12
  118. package/src/actions.js +9 -8
  119. package/src/entity-provider.js +72 -5
  120. package/src/entity-types/wp-template.ts +4 -0
  121. package/src/hooks/use-entity-record.ts +4 -2
  122. package/src/hooks/use-entity-records.ts +1 -1
  123. package/src/index.js +0 -1
  124. package/src/private-apis.js +10 -0
  125. package/src/private-selectors.ts +30 -0
  126. package/src/reducer.js +130 -104
  127. package/src/selectors.ts +33 -13
  128. package/src/test/reducer.js +89 -54
  129. package/src/test/selectors.js +8 -8
  130. package/tsconfig.json +2 -0
  131. package/tsconfig.tsbuildinfo +1 -1
@@ -37,10 +37,9 @@ var _utils = require("./utils");
37
37
  * @param {Object|undefined} query Optional object of query parameters to
38
38
  * include with request.
39
39
  */
40
- const getAuthors = query => async _ref => {
41
- let {
42
- dispatch
43
- } = _ref;
40
+ const getAuthors = query => async ({
41
+ dispatch
42
+ }) => {
44
43
  const path = (0, _url.addQueryArgs)('/wp/v2/users/?who=authors&per_page=100', query);
45
44
  const users = await (0, _apiFetch.default)({
46
45
  path
@@ -54,10 +53,9 @@ const getAuthors = query => async _ref => {
54
53
 
55
54
  exports.getAuthors = getAuthors;
56
55
 
57
- const getCurrentUser = () => async _ref2 => {
58
- let {
59
- dispatch
60
- } = _ref2;
56
+ const getCurrentUser = () => async ({
57
+ dispatch
58
+ }) => {
61
59
  const currentUser = await (0, _apiFetch.default)({
62
60
  path: '/wp/v2/users/me'
63
61
  });
@@ -77,67 +75,62 @@ const getCurrentUser = () => async _ref2 => {
77
75
 
78
76
  exports.getCurrentUser = getCurrentUser;
79
77
 
80
- const getEntityRecord = function (kind, name) {
81
- let key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
82
- let query = arguments.length > 3 ? arguments[3] : undefined;
83
- return async _ref3 => {
84
- let {
85
- select,
86
- dispatch
87
- } = _ref3;
88
- const configs = await dispatch((0, _entities.getOrLoadEntitiesConfig)(kind));
89
- const entityConfig = configs.find(config => config.name === name && config.kind === kind);
90
-
91
- if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
92
- return;
93
- }
78
+ const getEntityRecord = (kind, name, key = '', query) => async ({
79
+ select,
80
+ dispatch
81
+ }) => {
82
+ const configs = await dispatch((0, _entities.getOrLoadEntitiesConfig)(kind));
83
+ const entityConfig = configs.find(config => config.name === name && config.kind === kind);
94
84
 
95
- const lock = await dispatch.__unstableAcquireStoreLock(_name.STORE_NAME, ['entities', 'records', kind, name, key], {
96
- exclusive: false
97
- });
85
+ if (!entityConfig || entityConfig?.__experimentalNoFetch) {
86
+ return;
87
+ }
98
88
 
99
- try {
100
- if (query !== undefined && query._fields) {
101
- // If requesting specific fields, items and query association to said
102
- // records are stored by ID reference. Thus, fields must always include
103
- // the ID.
104
- query = { ...query,
105
- _fields: [...new Set([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entityConfig.key || _entities.DEFAULT_ENTITY_KEY])].join()
106
- };
107
- } // Disable reason: While true that an early return could leave `path`
108
- // unused, it's important that path is derived using the query prior to
109
- // additional query modifications in the condition below, since those
110
- // modifications are relevant to how the data is tracked in state, and not
111
- // for how the request is made to the REST API.
112
- // eslint-disable-next-line @wordpress/no-unused-vars-before-return
113
-
114
-
115
- const path = (0, _url.addQueryArgs)(entityConfig.baseURL + (key ? '/' + key : ''), { ...entityConfig.baseURLParams,
116
- ...query
117
- });
89
+ const lock = await dispatch.__unstableAcquireStoreLock(_name.STORE_NAME, ['entities', 'records', kind, name, key], {
90
+ exclusive: false
91
+ });
118
92
 
119
- if (query !== undefined) {
120
- query = { ...query,
121
- include: [key]
122
- }; // The resolution cache won't consider query as reusable based on the
123
- // fields, so it's tested here, prior to initiating the REST request,
124
- // and without causing `getEntityRecords` resolution to occur.
93
+ try {
94
+ if (query !== undefined && query._fields) {
95
+ // If requesting specific fields, items and query association to said
96
+ // records are stored by ID reference. Thus, fields must always include
97
+ // the ID.
98
+ query = { ...query,
99
+ _fields: [...new Set([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entityConfig.key || _entities.DEFAULT_ENTITY_KEY])].join()
100
+ };
101
+ } // Disable reason: While true that an early return could leave `path`
102
+ // unused, it's important that path is derived using the query prior to
103
+ // additional query modifications in the condition below, since those
104
+ // modifications are relevant to how the data is tracked in state, and not
105
+ // for how the request is made to the REST API.
106
+ // eslint-disable-next-line @wordpress/no-unused-vars-before-return
107
+
108
+
109
+ const path = (0, _url.addQueryArgs)(entityConfig.baseURL + (key ? '/' + key : ''), { ...entityConfig.baseURLParams,
110
+ ...query
111
+ });
125
112
 
126
- const hasRecords = select.hasEntityRecords(kind, name, query);
113
+ if (query !== undefined) {
114
+ query = { ...query,
115
+ include: [key]
116
+ }; // The resolution cache won't consider query as reusable based on the
117
+ // fields, so it's tested here, prior to initiating the REST request,
118
+ // and without causing `getEntityRecords` resolution to occur.
127
119
 
128
- if (hasRecords) {
129
- return;
130
- }
131
- }
120
+ const hasRecords = select.hasEntityRecords(kind, name, query);
132
121
 
133
- const record = await (0, _apiFetch.default)({
134
- path
135
- });
136
- dispatch.receiveEntityRecords(kind, name, record, query);
137
- } finally {
138
- dispatch.__unstableReleaseStoreLock(lock);
122
+ if (hasRecords) {
123
+ return;
124
+ }
139
125
  }
140
- };
126
+
127
+ const record = await (0, _apiFetch.default)({
128
+ path
129
+ });
130
+ dispatch.receiveEntityRecords(kind, name, record, query);
131
+ } finally {
132
+ dispatch.__unstableReleaseStoreLock(lock);
133
+ }
141
134
  };
142
135
  /**
143
136
  * Requests an entity's record from the REST API.
@@ -163,78 +156,72 @@ const getEditedEntityRecord = (0, _utils.forwardResolver)('getEntityRecord');
163
156
 
164
157
  exports.getEditedEntityRecord = getEditedEntityRecord;
165
158
 
166
- const getEntityRecords = function (kind, name) {
167
- let query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
168
- return async _ref4 => {
169
- let {
170
- dispatch
171
- } = _ref4;
172
- const configs = await dispatch((0, _entities.getOrLoadEntitiesConfig)(kind));
173
- const entityConfig = configs.find(config => config.name === name && config.kind === kind);
159
+ const getEntityRecords = (kind, name, query = {}) => async ({
160
+ dispatch
161
+ }) => {
162
+ const configs = await dispatch((0, _entities.getOrLoadEntitiesConfig)(kind));
163
+ const entityConfig = configs.find(config => config.name === name && config.kind === kind);
174
164
 
175
- if (!entityConfig || entityConfig !== null && entityConfig !== void 0 && entityConfig.__experimentalNoFetch) {
176
- return;
177
- }
165
+ if (!entityConfig || entityConfig?.__experimentalNoFetch) {
166
+ return;
167
+ }
178
168
 
179
- const lock = await dispatch.__unstableAcquireStoreLock(_name.STORE_NAME, ['entities', 'records', kind, name], {
180
- exclusive: false
181
- });
169
+ const lock = await dispatch.__unstableAcquireStoreLock(_name.STORE_NAME, ['entities', 'records', kind, name], {
170
+ exclusive: false
171
+ });
182
172
 
183
- try {
184
- var _query;
173
+ try {
174
+ if (query._fields) {
175
+ // If requesting specific fields, items and query association to said
176
+ // records are stored by ID reference. Thus, fields must always include
177
+ // the ID.
178
+ query = { ...query,
179
+ _fields: [...new Set([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entityConfig.key || _entities.DEFAULT_ENTITY_KEY])].join()
180
+ };
181
+ }
185
182
 
186
- if (query._fields) {
187
- // If requesting specific fields, items and query association to said
188
- // records are stored by ID reference. Thus, fields must always include
189
- // the ID.
190
- query = { ...query,
191
- _fields: [...new Set([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entityConfig.key || _entities.DEFAULT_ENTITY_KEY])].join()
192
- };
193
- }
183
+ const path = (0, _url.addQueryArgs)(entityConfig.baseURL, { ...entityConfig.baseURLParams,
184
+ ...query
185
+ });
186
+ let records = Object.values(await (0, _apiFetch.default)({
187
+ path
188
+ })); // If we request fields but the result doesn't contain the fields,
189
+ // explicitly set these fields as "undefined"
190
+ // that way we consider the query "fullfilled".
191
+
192
+ if (query._fields) {
193
+ records = records.map(record => {
194
+ query._fields.split(',').forEach(field => {
195
+ if (!record.hasOwnProperty(field)) {
196
+ record[field] = undefined;
197
+ }
198
+ });
194
199
 
195
- const path = (0, _url.addQueryArgs)(entityConfig.baseURL, { ...entityConfig.baseURLParams,
196
- ...query
200
+ return record;
197
201
  });
198
- let records = Object.values(await (0, _apiFetch.default)({
199
- path
200
- })); // If we request fields but the result doesn't contain the fields,
201
- // explicitly set these fields as "undefined"
202
- // that way we consider the query "fullfilled".
203
-
204
- if (query._fields) {
205
- records = records.map(record => {
206
- query._fields.split(',').forEach(field => {
207
- if (!record.hasOwnProperty(field)) {
208
- record[field] = undefined;
209
- }
210
- });
211
-
212
- return record;
213
- });
214
- }
202
+ }
215
203
 
216
- dispatch.receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to
217
- // resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
218
- // See https://github.com/WordPress/gutenberg/pull/26575
219
-
220
- if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) {
221
- const key = entityConfig.key || _entities.DEFAULT_ENTITY_KEY;
222
- const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
223
- dispatch({
224
- type: 'START_RESOLUTIONS',
225
- selectorName: 'getEntityRecord',
226
- args: resolutionsArgs
227
- });
228
- dispatch({
229
- type: 'FINISH_RESOLUTIONS',
230
- selectorName: 'getEntityRecord',
231
- args: resolutionsArgs
232
- });
233
- }
234
- } finally {
235
- dispatch.__unstableReleaseStoreLock(lock);
204
+ dispatch.receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to
205
+ // resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
206
+ // See https://github.com/WordPress/gutenberg/pull/26575
207
+
208
+ if (!query?._fields && !query.context) {
209
+ const key = entityConfig.key || _entities.DEFAULT_ENTITY_KEY;
210
+ const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
211
+ dispatch({
212
+ type: 'START_RESOLUTIONS',
213
+ selectorName: 'getEntityRecord',
214
+ args: resolutionsArgs
215
+ });
216
+ dispatch({
217
+ type: 'FINISH_RESOLUTIONS',
218
+ selectorName: 'getEntityRecord',
219
+ args: resolutionsArgs
220
+ });
236
221
  }
237
- };
222
+ } finally {
223
+ dispatch.__unstableReleaseStoreLock(lock);
224
+ }
238
225
  };
239
226
 
240
227
  exports.getEntityRecords = getEntityRecords;
@@ -247,11 +234,10 @@ getEntityRecords.shouldInvalidate = (action, kind, name) => {
247
234
  */
248
235
 
249
236
 
250
- const getCurrentTheme = () => async _ref5 => {
251
- let {
252
- dispatch,
253
- resolveSelect
254
- } = _ref5;
237
+ const getCurrentTheme = () => async ({
238
+ dispatch,
239
+ resolveSelect
240
+ }) => {
255
241
  const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
256
242
  status: 'active'
257
243
  });
@@ -272,11 +258,9 @@ const getThemeSupports = (0, _utils.forwardResolver)('getCurrentTheme');
272
258
 
273
259
  exports.getThemeSupports = getThemeSupports;
274
260
 
275
- const getEmbedPreview = url => async _ref6 => {
276
- let {
277
- dispatch
278
- } = _ref6;
279
-
261
+ const getEmbedPreview = url => async ({
262
+ dispatch
263
+ }) => {
280
264
  try {
281
265
  const embedProxyResponse = await (0, _apiFetch.default)({
282
266
  path: (0, _url.addQueryArgs)('/oembed/1.0/proxy', {
@@ -302,13 +286,10 @@ const getEmbedPreview = url => async _ref6 => {
302
286
 
303
287
  exports.getEmbedPreview = getEmbedPreview;
304
288
 
305
- const canUser = (requestedAction, resource, id) => async _ref7 => {
306
- var _response$headers;
307
-
308
- let {
309
- dispatch,
310
- registry
311
- } = _ref7;
289
+ const canUser = (requestedAction, resource, id) => async ({
290
+ dispatch,
291
+ registry
292
+ }) => {
312
293
  const {
313
294
  hasStartedResolution
314
295
  } = registry.select(_name.STORE_NAME);
@@ -349,8 +330,8 @@ const canUser = (requestedAction, resource, id) => async _ref7 => {
349
330
  // only return the result, without including response properties like the headers.
350
331
 
351
332
 
352
- const allowHeader = (_response$headers = response.headers) === null || _response$headers === void 0 ? void 0 : _response$headers.get('allow');
353
- const allowedMethods = (allowHeader === null || allowHeader === void 0 ? void 0 : allowHeader.allow) || allowHeader || '';
333
+ const allowHeader = response.headers?.get('allow');
334
+ const allowedMethods = allowHeader?.allow || allowHeader || '';
354
335
  const permissions = {};
355
336
  const methods = {
356
337
  create: 'POST',
@@ -379,10 +360,9 @@ const canUser = (requestedAction, resource, id) => async _ref7 => {
379
360
 
380
361
  exports.canUser = canUser;
381
362
 
382
- const canUserEditEntityRecord = (kind, name, recordId) => async _ref8 => {
383
- let {
384
- dispatch
385
- } = _ref8;
363
+ const canUserEditEntityRecord = (kind, name, recordId) => async ({
364
+ dispatch
365
+ }) => {
386
366
  const configs = await dispatch((0, _entities.getOrLoadEntitiesConfig)(kind));
387
367
  const entityConfig = configs.find(config => config.name === name && config.kind === kind);
388
368
 
@@ -403,11 +383,10 @@ const canUserEditEntityRecord = (kind, name, recordId) => async _ref8 => {
403
383
 
404
384
  exports.canUserEditEntityRecord = canUserEditEntityRecord;
405
385
 
406
- const getAutosaves = (postType, postId) => async _ref9 => {
407
- let {
408
- dispatch,
409
- resolveSelect
410
- } = _ref9;
386
+ const getAutosaves = (postType, postId) => async ({
387
+ dispatch,
388
+ resolveSelect
389
+ }) => {
411
390
  const {
412
391
  rest_base: restBase,
413
392
  rest_namespace: restNamespace = 'wp/v2'
@@ -433,10 +412,9 @@ const getAutosaves = (postType, postId) => async _ref9 => {
433
412
 
434
413
  exports.getAutosaves = getAutosaves;
435
414
 
436
- const getAutosave = (postType, postId) => async _ref10 => {
437
- let {
438
- resolveSelect
439
- } = _ref10;
415
+ const getAutosave = (postType, postId) => async ({
416
+ resolveSelect
417
+ }) => {
440
418
  await resolveSelect.getAutosaves(postType, postId);
441
419
  };
442
420
  /**
@@ -448,11 +426,10 @@ const getAutosave = (postType, postId) => async _ref10 => {
448
426
 
449
427
  exports.getAutosave = getAutosave;
450
428
 
451
- const __experimentalGetTemplateForLink = link => async _ref11 => {
452
- let {
453
- dispatch,
454
- resolveSelect
455
- } = _ref11;
429
+ const __experimentalGetTemplateForLink = link => async ({
430
+ dispatch,
431
+ resolveSelect
432
+ }) => {
456
433
  let template;
457
434
 
458
435
  try {
@@ -462,12 +439,9 @@ const __experimentalGetTemplateForLink = link => async _ref11 => {
462
439
  url: (0, _url.addQueryArgs)(link, {
463
440
  '_wp-find-template': true
464
441
  })
465
- }).then(_ref12 => {
466
- let {
467
- data
468
- } = _ref12;
469
- return data;
470
- });
442
+ }).then(({
443
+ data
444
+ }) => data);
471
445
  } catch (e) {// For non-FSE themes, it is possible that this request returns an error.
472
446
  }
473
447
 
@@ -490,17 +464,14 @@ __experimentalGetTemplateForLink.shouldInvalidate = action => {
490
464
  return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template';
491
465
  };
492
466
 
493
- const __experimentalGetCurrentGlobalStylesId = () => async _ref13 => {
494
- var _activeThemes$, _activeThemes$$_links, _activeThemes$$_links2, _activeThemes$$_links3;
495
-
496
- let {
497
- dispatch,
498
- resolveSelect
499
- } = _ref13;
467
+ const __experimentalGetCurrentGlobalStylesId = () => async ({
468
+ dispatch,
469
+ resolveSelect
470
+ }) => {
500
471
  const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
501
472
  status: 'active'
502
473
  });
503
- 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;
474
+ const globalStylesURL = activeThemes?.[0]?._links?.['wp:user-global-styles']?.[0]?.href;
504
475
 
505
476
  if (globalStylesURL) {
506
477
  const globalStylesObject = await (0, _apiFetch.default)({
@@ -513,11 +484,10 @@ const __experimentalGetCurrentGlobalStylesId = () => async _ref13 => {
513
484
 
514
485
  exports.__experimentalGetCurrentGlobalStylesId = __experimentalGetCurrentGlobalStylesId;
515
486
 
516
- const __experimentalGetCurrentThemeBaseGlobalStyles = () => async _ref14 => {
517
- let {
518
- resolveSelect,
519
- dispatch
520
- } = _ref14;
487
+ const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ({
488
+ resolveSelect,
489
+ dispatch
490
+ }) => {
521
491
  const currentTheme = await resolveSelect.getCurrentTheme();
522
492
  const themeGlobalStyles = await (0, _apiFetch.default)({
523
493
  path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}`
@@ -528,11 +498,10 @@ const __experimentalGetCurrentThemeBaseGlobalStyles = () => async _ref14 => {
528
498
 
529
499
  exports.__experimentalGetCurrentThemeBaseGlobalStyles = __experimentalGetCurrentThemeBaseGlobalStyles;
530
500
 
531
- const __experimentalGetCurrentThemeGlobalStylesVariations = () => async _ref15 => {
532
- let {
533
- resolveSelect,
534
- dispatch
535
- } = _ref15;
501
+ const __experimentalGetCurrentThemeGlobalStylesVariations = () => async ({
502
+ resolveSelect,
503
+ dispatch
504
+ }) => {
536
505
  const currentTheme = await resolveSelect.getCurrentTheme();
537
506
  const variations = await (0, _apiFetch.default)({
538
507
  path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}/variations`
@@ -547,25 +516,19 @@ const __experimentalGetCurrentThemeGlobalStylesVariations = () => async _ref15 =
547
516
 
548
517
  exports.__experimentalGetCurrentThemeGlobalStylesVariations = __experimentalGetCurrentThemeGlobalStylesVariations;
549
518
 
550
- const getCurrentThemeGlobalStylesRevisions = () => async _ref16 => {
551
- var _record$_links, _record$_links$versio, _record$_links$versio2;
552
-
553
- let {
554
- resolveSelect,
555
- dispatch
556
- } = _ref16;
519
+ const getCurrentThemeGlobalStylesRevisions = () => async ({
520
+ resolveSelect,
521
+ dispatch
522
+ }) => {
557
523
  const globalStylesId = await resolveSelect.__experimentalGetCurrentGlobalStylesId();
558
524
  const record = globalStylesId ? await resolveSelect.getEntityRecord('root', 'globalStyles', globalStylesId) : undefined;
559
- 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;
525
+ const revisionsURL = record?._links?.['version-history']?.[0]?.href;
560
526
 
561
527
  if (revisionsURL) {
562
528
  const resetRevisions = await (0, _apiFetch.default)({
563
529
  url: revisionsURL
564
530
  });
565
- const revisions = resetRevisions === null || resetRevisions === void 0 ? void 0 : resetRevisions.map(revision => Object.fromEntries(Object.entries(revision).map(_ref17 => {
566
- let [key, value] = _ref17;
567
- return [(0, _changeCase.camelCase)(key), value];
568
- })));
531
+ const revisions = resetRevisions?.map(revision => Object.fromEntries(Object.entries(revision).map(([key, value]) => [(0, _changeCase.camelCase)(key), value])));
569
532
  dispatch.receiveThemeGlobalStyleRevisions(globalStylesId, revisions);
570
533
  }
571
534
  };
@@ -576,17 +539,13 @@ getCurrentThemeGlobalStylesRevisions.shouldInvalidate = action => {
576
539
  return action.type === 'SAVE_ENTITY_RECORD_FINISH' && action.kind === 'root' && !action.error && action.name === 'globalStyles';
577
540
  };
578
541
 
579
- const getBlockPatterns = () => async _ref18 => {
580
- let {
581
- dispatch
582
- } = _ref18;
542
+ const getBlockPatterns = () => async ({
543
+ dispatch
544
+ }) => {
583
545
  const restPatterns = await (0, _apiFetch.default)({
584
546
  path: '/wp/v2/block-patterns/patterns'
585
547
  });
586
- const patterns = restPatterns === null || restPatterns === void 0 ? void 0 : restPatterns.map(pattern => Object.fromEntries(Object.entries(pattern).map(_ref19 => {
587
- let [key, value] = _ref19;
588
- return [(0, _changeCase.camelCase)(key), value];
589
- })));
548
+ const patterns = restPatterns?.map(pattern => Object.fromEntries(Object.entries(pattern).map(([key, value]) => [(0, _changeCase.camelCase)(key), value])));
590
549
  dispatch({
591
550
  type: 'RECEIVE_BLOCK_PATTERNS',
592
551
  patterns
@@ -595,10 +554,9 @@ const getBlockPatterns = () => async _ref18 => {
595
554
 
596
555
  exports.getBlockPatterns = getBlockPatterns;
597
556
 
598
- const getBlockPatternCategories = () => async _ref20 => {
599
- let {
600
- dispatch
601
- } = _ref20;
557
+ const getBlockPatternCategories = () => async ({
558
+ dispatch
559
+ }) => {
602
560
  const categories = await (0, _apiFetch.default)({
603
561
  path: '/wp/v2/block-patterns/categories'
604
562
  });
@@ -610,24 +568,21 @@ const getBlockPatternCategories = () => async _ref20 => {
610
568
 
611
569
  exports.getBlockPatternCategories = getBlockPatternCategories;
612
570
 
613
- const getNavigationFallbackId = () => async _ref21 => {
614
- var _fallback$_embedded;
615
-
616
- let {
617
- dispatch
618
- } = _ref21;
571
+ const getNavigationFallbackId = () => async ({
572
+ dispatch
573
+ }) => {
619
574
  const fallback = await (0, _apiFetch.default)({
620
575
  path: (0, _url.addQueryArgs)('/wp-block-editor/v1/navigation-fallback', {
621
576
  _embed: true
622
577
  })
623
578
  });
624
- const record = fallback === null || fallback === void 0 ? void 0 : (_fallback$_embedded = fallback._embedded) === null || _fallback$_embedded === void 0 ? void 0 : _fallback$_embedded.self;
625
- dispatch.receiveNavigationFallbackId(fallback === null || fallback === void 0 ? void 0 : fallback.id);
579
+ const record = fallback?._embedded?.self;
580
+ dispatch.receiveNavigationFallbackId(fallback?.id);
626
581
 
627
582
  if (record) {
628
583
  dispatch.receiveEntityRecords('postType', 'wp_navigation', record); // Resolve to avoid further network requests.
629
584
 
630
- dispatch.finishResolution('getEntityRecord', ['postType', 'wp_navigation', fallback === null || fallback === void 0 ? void 0 : fallback.id]);
585
+ dispatch.finishResolution('getEntityRecord', ['postType', 'wp_navigation', fallback?.id]);
631
586
  }
632
587
  };
633
588