@wordpress/core-data 4.0.4 → 4.0.8

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 (99) hide show
  1. package/README.md +2 -4
  2. package/build/actions.js +321 -247
  3. package/build/actions.js.map +1 -1
  4. package/build/batch/create-batch.js +17 -9
  5. package/build/batch/create-batch.js.map +1 -1
  6. package/build/entities.js +67 -14
  7. package/build/entities.js.map +1 -1
  8. package/build/entity-provider.js +18 -13
  9. package/build/entity-provider.js.map +1 -1
  10. package/build/fetch/__experimental-fetch-link-suggestions.js +3 -1
  11. package/build/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  12. package/build/fetch/__experimental-fetch-url-data.js +3 -2
  13. package/build/fetch/__experimental-fetch-url-data.js.map +1 -1
  14. package/build/index.js +25 -5
  15. package/build/index.js.map +1 -1
  16. package/build/locks/actions.js +4 -3
  17. package/build/locks/actions.js.map +1 -1
  18. package/build/locks/reducer.js +4 -1
  19. package/build/locks/reducer.js.map +1 -1
  20. package/build/locks/selectors.js +4 -3
  21. package/build/locks/selectors.js.map +1 -1
  22. package/build/locks/utils.js +7 -5
  23. package/build/locks/utils.js.map +1 -1
  24. package/build/queried-data/actions.js +6 -3
  25. package/build/queried-data/actions.js.map +1 -1
  26. package/build/queried-data/get-query-parts.js +1 -1
  27. package/build/queried-data/reducer.js +17 -6
  28. package/build/queried-data/reducer.js.map +1 -1
  29. package/build/queried-data/selectors.js +2 -1
  30. package/build/queried-data/selectors.js.map +1 -1
  31. package/build/reducer.js +90 -43
  32. package/build/reducer.js.map +1 -1
  33. package/build/resolvers.js +216 -163
  34. package/build/resolvers.js.map +1 -1
  35. package/build/selectors.js +75 -22
  36. package/build/selectors.js.map +1 -1
  37. package/build/utils/forward-resolver.js +30 -0
  38. package/build/utils/forward-resolver.js.map +1 -0
  39. package/build/utils/index.js +9 -9
  40. package/build/utils/index.js.map +1 -1
  41. package/build/utils/on-sub-key.js +4 -2
  42. package/build/utils/on-sub-key.js.map +1 -1
  43. package/build-module/actions.js +306 -240
  44. package/build-module/actions.js.map +1 -1
  45. package/build-module/batch/create-batch.js +17 -9
  46. package/build-module/batch/create-batch.js.map +1 -1
  47. package/build-module/entities.js +66 -13
  48. package/build-module/entities.js.map +1 -1
  49. package/build-module/entity-provider.js +17 -12
  50. package/build-module/entity-provider.js.map +1 -1
  51. package/build-module/fetch/__experimental-fetch-link-suggestions.js +3 -1
  52. package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  53. package/build-module/fetch/__experimental-fetch-url-data.js +3 -2
  54. package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
  55. package/build-module/index.js +21 -3
  56. package/build-module/index.js.map +1 -1
  57. package/build-module/locks/actions.js +4 -3
  58. package/build-module/locks/actions.js.map +1 -1
  59. package/build-module/locks/reducer.js +4 -1
  60. package/build-module/locks/reducer.js.map +1 -1
  61. package/build-module/locks/selectors.js +4 -3
  62. package/build-module/locks/selectors.js.map +1 -1
  63. package/build-module/locks/utils.js +5 -3
  64. package/build-module/locks/utils.js.map +1 -1
  65. package/build-module/queried-data/actions.js +5 -2
  66. package/build-module/queried-data/actions.js.map +1 -1
  67. package/build-module/queried-data/reducer.js +15 -4
  68. package/build-module/queried-data/reducer.js.map +1 -1
  69. package/build-module/queried-data/selectors.js +2 -1
  70. package/build-module/queried-data/selectors.js.map +1 -1
  71. package/build-module/reducer.js +80 -34
  72. package/build-module/reducer.js.map +1 -1
  73. package/build-module/resolvers.js +211 -161
  74. package/build-module/resolvers.js.map +1 -1
  75. package/build-module/selectors.js +44 -3
  76. package/build-module/selectors.js.map +1 -1
  77. package/build-module/utils/forward-resolver.js +22 -0
  78. package/build-module/utils/forward-resolver.js.map +1 -0
  79. package/build-module/utils/index.js +1 -1
  80. package/build-module/utils/index.js.map +1 -1
  81. package/build-module/utils/on-sub-key.js +3 -1
  82. package/build-module/utils/on-sub-key.js.map +1 -1
  83. package/package.json +12 -12
  84. package/src/actions.js +51 -5
  85. package/src/entities.js +43 -6
  86. package/src/fetch/__experimental-fetch-url-data.js +1 -1
  87. package/src/reducer.js +14 -17
  88. package/src/resolvers.js +56 -19
  89. package/src/selectors.js +43 -4
  90. package/src/test/actions.js +89 -0
  91. package/src/test/selectors.js +56 -1
  92. package/src/utils/forward-resolver.js +14 -0
  93. package/src/utils/index.js +1 -1
  94. package/build/utils/if-not-resolved.js +0 -31
  95. package/build/utils/if-not-resolved.js.map +0 -1
  96. package/build-module/utils/if-not-resolved.js +0 -23
  97. package/build-module/utils/if-not-resolved.js.map +0 -1
  98. package/src/utils/if-not-resolved.js +0 -22
  99. package/src/utils/test/if-not-resolved.js +0 -76
@@ -14,7 +14,7 @@ import apiFetch from '@wordpress/api-fetch';
14
14
 
15
15
  import { STORE_NAME } from './name';
16
16
  import { getKindEntities, DEFAULT_ENTITY_KEY } from './entities';
17
- import { ifNotResolved, getNormalizedCommaSeparable } from './utils';
17
+ import { forwardResolver, getNormalizedCommaSeparable } from './utils';
18
18
  /**
19
19
  * Requests authors from the REST API.
20
20
  *
@@ -22,9 +22,10 @@ import { ifNotResolved, getNormalizedCommaSeparable } from './utils';
22
22
  * include with request.
23
23
  */
24
24
 
25
- export const getAuthors = query => async ({
26
- dispatch
27
- }) => {
25
+ export const getAuthors = query => async _ref => {
26
+ let {
27
+ dispatch
28
+ } = _ref;
28
29
  const path = addQueryArgs('/wp/v2/users/?who=authors&per_page=100', query);
29
30
  const users = await apiFetch({
30
31
  path
@@ -35,9 +36,10 @@ export const getAuthors = query => async ({
35
36
  * Requests the current user from the REST API.
36
37
  */
37
38
 
38
- export const getCurrentUser = () => async ({
39
- dispatch
40
- }) => {
39
+ export const getCurrentUser = () => async _ref2 => {
40
+ let {
41
+ dispatch
42
+ } = _ref2;
41
43
  const currentUser = await apiFetch({
42
44
  path: '/wp/v2/users/me'
43
45
  });
@@ -53,78 +55,84 @@ export const getCurrentUser = () => async ({
53
55
  * include with request.
54
56
  */
55
57
 
56
- export const getEntityRecord = (kind, name, key = '', query) => async ({
57
- select,
58
- dispatch
59
- }) => {
60
- const entities = await dispatch(getKindEntities(kind));
61
- const entity = find(entities, {
62
- kind,
63
- name
64
- });
65
-
66
- if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
67
- return;
68
- }
58
+ export const getEntityRecord = function (kind, name) {
59
+ let key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
60
+ let query = arguments.length > 3 ? arguments[3] : undefined;
61
+ return async _ref3 => {
62
+ let {
63
+ select,
64
+ dispatch
65
+ } = _ref3;
66
+ const entities = await dispatch(getKindEntities(kind));
67
+ const entity = find(entities, {
68
+ kind,
69
+ name
70
+ });
69
71
 
70
- const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name, key], {
71
- exclusive: false
72
- });
72
+ if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
73
+ return;
74
+ }
73
75
 
74
- try {
75
- if (query !== undefined && query._fields) {
76
- // If requesting specific fields, items and query association to said
77
- // records are stored by ID reference. Thus, fields must always include
78
- // the ID.
79
- query = { ...query,
80
- _fields: uniq([...(getNormalizedCommaSeparable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join()
81
- };
82
- } // Disable reason: While true that an early return could leave `path`
83
- // unused, it's important that path is derived using the query prior to
84
- // additional query modifications in the condition below, since those
85
- // modifications are relevant to how the data is tracked in state, and not
86
- // for how the request is made to the REST API.
87
- // eslint-disable-next-line @wordpress/no-unused-vars-before-return
88
-
89
-
90
- const path = addQueryArgs(entity.baseURL + (key ? '/' + key : ''), { ...entity.baseURLParams,
91
- ...query
76
+ const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name, key], {
77
+ exclusive: false
92
78
  });
93
79
 
94
- if (query !== undefined) {
95
- query = { ...query,
96
- include: [key]
97
- }; // The resolution cache won't consider query as reusable based on the
98
- // fields, so it's tested here, prior to initiating the REST request,
99
- // and without causing `getEntityRecords` resolution to occur.
80
+ try {
81
+ if (query !== undefined && query._fields) {
82
+ // If requesting specific fields, items and query association to said
83
+ // records are stored by ID reference. Thus, fields must always include
84
+ // the ID.
85
+ query = { ...query,
86
+ _fields: uniq([...(getNormalizedCommaSeparable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join()
87
+ };
88
+ } // Disable reason: While true that an early return could leave `path`
89
+ // unused, it's important that path is derived using the query prior to
90
+ // additional query modifications in the condition below, since those
91
+ // modifications are relevant to how the data is tracked in state, and not
92
+ // for how the request is made to the REST API.
93
+ // eslint-disable-next-line @wordpress/no-unused-vars-before-return
94
+
95
+
96
+ const path = addQueryArgs(entity.baseURL + (key ? '/' + key : ''), { ...entity.baseURLParams,
97
+ ...query
98
+ });
99
+
100
+ if (query !== undefined) {
101
+ query = { ...query,
102
+ include: [key]
103
+ }; // The resolution cache won't consider query as reusable based on the
104
+ // fields, so it's tested here, prior to initiating the REST request,
105
+ // and without causing `getEntityRecords` resolution to occur.
100
106
 
101
- const hasRecords = select.hasEntityRecords(kind, name, query);
107
+ const hasRecords = select.hasEntityRecords(kind, name, query);
102
108
 
103
- if (hasRecords) {
104
- return;
109
+ if (hasRecords) {
110
+ return;
111
+ }
105
112
  }
106
- }
107
113
 
108
- const record = await apiFetch({
109
- path
110
- });
111
- dispatch.receiveEntityRecords(kind, name, record, query);
112
- } catch (error) {// We need a way to handle and access REST API errors in state
113
- // Until then, catching the error ensures the resolver is marked as resolved.
114
- } finally {
115
- dispatch.__unstableReleaseStoreLock(lock);
116
- }
114
+ const record = await apiFetch({
115
+ path
116
+ });
117
+ dispatch.receiveEntityRecords(kind, name, record, query);
118
+ } catch (error) {// We need a way to handle and access REST API errors in state
119
+ // Until then, catching the error ensures the resolver is marked as resolved.
120
+ // See similar implementation in `getEntityRecords()`.
121
+ } finally {
122
+ dispatch.__unstableReleaseStoreLock(lock);
123
+ }
124
+ };
117
125
  };
118
126
  /**
119
127
  * Requests an entity's record from the REST API.
120
128
  */
121
129
 
122
- export const getRawEntityRecord = ifNotResolved(getEntityRecord, 'getEntityRecord');
130
+ export const getRawEntityRecord = forwardResolver('getEntityRecord');
123
131
  /**
124
132
  * Requests an entity's record from the REST API.
125
133
  */
126
134
 
127
- export const getEditedEntityRecord = ifNotResolved(getRawEntityRecord, 'getRawEntityRecord');
135
+ export const getEditedEntityRecord = forwardResolver('getEntityRecord');
128
136
  /**
129
137
  * Requests the entity's records from the REST API.
130
138
  *
@@ -133,77 +141,84 @@ export const getEditedEntityRecord = ifNotResolved(getRawEntityRecord, 'getRawEn
133
141
  * @param {Object?} query Query Object.
134
142
  */
135
143
 
136
- export const getEntityRecords = (kind, name, query = {}) => async ({
137
- dispatch
138
- }) => {
139
- const entities = await dispatch(getKindEntities(kind));
140
- const entity = find(entities, {
141
- kind,
142
- name
143
- });
144
-
145
- if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
146
- return;
147
- }
148
-
149
- const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name], {
150
- exclusive: false
151
- });
144
+ export const getEntityRecords = function (kind, name) {
145
+ let query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
146
+ return async _ref4 => {
147
+ let {
148
+ dispatch
149
+ } = _ref4;
150
+ const entities = await dispatch(getKindEntities(kind));
151
+ const entity = find(entities, {
152
+ kind,
153
+ name
154
+ });
152
155
 
153
- try {
154
- var _query;
155
-
156
- if (query._fields) {
157
- // If requesting specific fields, items and query association to said
158
- // records are stored by ID reference. Thus, fields must always include
159
- // the ID.
160
- query = { ...query,
161
- _fields: uniq([...(getNormalizedCommaSeparable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join()
162
- };
156
+ if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
157
+ return;
163
158
  }
164
159
 
165
- const path = addQueryArgs(entity.baseURL, { ...entity.baseURLParams,
166
- ...query
160
+ const lock = await dispatch.__unstableAcquireStoreLock(STORE_NAME, ['entities', 'data', kind, name], {
161
+ exclusive: false
167
162
  });
168
- let records = Object.values(await apiFetch({
169
- path
170
- })); // If we request fields but the result doesn't contain the fields,
171
- // explicitely set these fields as "undefined"
172
- // that way we consider the query "fullfilled".
173
-
174
- if (query._fields) {
175
- records = records.map(record => {
176
- query._fields.split(',').forEach(field => {
177
- if (!record.hasOwnProperty(field)) {
178
- record[field] = undefined;
179
- }
180
- });
181
163
 
182
- return record;
183
- });
184
- }
164
+ try {
165
+ var _query;
185
166
 
186
- dispatch.receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to
187
- // resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
188
- // See https://github.com/WordPress/gutenberg/pull/26575
189
-
190
- if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) {
191
- const key = entity.key || DEFAULT_ENTITY_KEY;
192
- const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
193
- dispatch({
194
- type: 'START_RESOLUTIONS',
195
- selectorName: 'getEntityRecord',
196
- args: resolutionsArgs
197
- });
198
- dispatch({
199
- type: 'FINISH_RESOLUTIONS',
200
- selectorName: 'getEntityRecord',
201
- args: resolutionsArgs
167
+ if (query._fields) {
168
+ // If requesting specific fields, items and query association to said
169
+ // records are stored by ID reference. Thus, fields must always include
170
+ // the ID.
171
+ query = { ...query,
172
+ _fields: uniq([...(getNormalizedCommaSeparable(query._fields) || []), entity.key || DEFAULT_ENTITY_KEY]).join()
173
+ };
174
+ }
175
+
176
+ const path = addQueryArgs(entity.baseURL, { ...entity.baseURLParams,
177
+ ...query
202
178
  });
179
+ let records = Object.values(await apiFetch({
180
+ path
181
+ })); // If we request fields but the result doesn't contain the fields,
182
+ // explicitely set these fields as "undefined"
183
+ // that way we consider the query "fullfilled".
184
+
185
+ if (query._fields) {
186
+ records = records.map(record => {
187
+ query._fields.split(',').forEach(field => {
188
+ if (!record.hasOwnProperty(field)) {
189
+ record[field] = undefined;
190
+ }
191
+ });
192
+
193
+ return record;
194
+ });
195
+ }
196
+
197
+ dispatch.receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to
198
+ // resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
199
+ // See https://github.com/WordPress/gutenberg/pull/26575
200
+
201
+ if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) {
202
+ const key = entity.key || DEFAULT_ENTITY_KEY;
203
+ const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
204
+ dispatch({
205
+ type: 'START_RESOLUTIONS',
206
+ selectorName: 'getEntityRecord',
207
+ args: resolutionsArgs
208
+ });
209
+ dispatch({
210
+ type: 'FINISH_RESOLUTIONS',
211
+ selectorName: 'getEntityRecord',
212
+ args: resolutionsArgs
213
+ });
214
+ }
215
+ } catch (error) {// We need a way to handle and access REST API errors in state
216
+ // Until then, catching the error ensures the resolver is marked as resolved.
217
+ // See similar implementation in `getEntityRecord()`.
218
+ } finally {
219
+ dispatch.__unstableReleaseStoreLock(lock);
203
220
  }
204
- } finally {
205
- dispatch.__unstableReleaseStoreLock(lock);
206
- }
221
+ };
207
222
  };
208
223
 
209
224
  getEntityRecords.shouldInvalidate = (action, kind, name) => {
@@ -214,11 +229,13 @@ getEntityRecords.shouldInvalidate = (action, kind, name) => {
214
229
  */
215
230
 
216
231
 
217
- export const getCurrentTheme = () => async ({
218
- dispatch
219
- }) => {
220
- const activeThemes = await apiFetch({
221
- path: '/wp/v2/themes?status=active'
232
+ export const getCurrentTheme = () => async _ref5 => {
233
+ let {
234
+ dispatch,
235
+ resolveSelect
236
+ } = _ref5;
237
+ const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
238
+ status: 'active'
222
239
  });
223
240
  dispatch.receiveCurrentTheme(activeThemes[0]);
224
241
  };
@@ -226,23 +243,18 @@ export const getCurrentTheme = () => async ({
226
243
  * Requests theme supports data from the index.
227
244
  */
228
245
 
229
- export const getThemeSupports = () => async ({
230
- dispatch
231
- }) => {
232
- const activeThemes = await apiFetch({
233
- path: '/wp/v2/themes?status=active'
234
- });
235
- dispatch.receiveThemeSupports(activeThemes[0].theme_supports);
236
- };
246
+ export const getThemeSupports = forwardResolver('getCurrentTheme');
237
247
  /**
238
248
  * Requests a preview from the from the Embed API.
239
249
  *
240
250
  * @param {string} url URL to get the preview for.
241
251
  */
242
252
 
243
- export const getEmbedPreview = url => async ({
244
- dispatch
245
- }) => {
253
+ export const getEmbedPreview = url => async _ref6 => {
254
+ let {
255
+ dispatch
256
+ } = _ref6;
257
+
246
258
  try {
247
259
  const embedProxyResponse = await apiFetch({
248
260
  path: addQueryArgs('/oembed/1.0/proxy', {
@@ -265,9 +277,10 @@ export const getEmbedPreview = url => async ({
265
277
  * @param {?string} id ID of the rest resource to check.
266
278
  */
267
279
 
268
- export const canUser = (action, resource, id) => async ({
269
- dispatch
270
- }) => {
280
+ export const canUser = (action, resource, id) => async _ref7 => {
281
+ let {
282
+ dispatch
283
+ } = _ref7;
271
284
  const methods = {
272
285
  create: 'POST',
273
286
  read: 'GET',
@@ -324,9 +337,10 @@ export const canUser = (action, resource, id) => async ({
324
337
  * @param {string} recordId Record's id.
325
338
  */
326
339
 
327
- export const canUserEditEntityRecord = (kind, name, recordId) => async ({
328
- dispatch
329
- }) => {
340
+ export const canUserEditEntityRecord = (kind, name, recordId) => async _ref8 => {
341
+ let {
342
+ dispatch
343
+ } = _ref8;
330
344
  const entities = await dispatch(getKindEntities(kind));
331
345
  const entity = find(entities, {
332
346
  kind,
@@ -347,10 +361,11 @@ export const canUserEditEntityRecord = (kind, name, recordId) => async ({
347
361
  * @param {number} postId The id of the parent post.
348
362
  */
349
363
 
350
- export const getAutosaves = (postType, postId) => async ({
351
- dispatch,
352
- resolveSelect
353
- }) => {
364
+ export const getAutosaves = (postType, postId) => async _ref9 => {
365
+ let {
366
+ dispatch,
367
+ resolveSelect
368
+ } = _ref9;
354
369
  const {
355
370
  rest_base: restBase
356
371
  } = await resolveSelect.getPostType(postType);
@@ -372,9 +387,10 @@ export const getAutosaves = (postType, postId) => async ({
372
387
  * @param {number} postId The id of the parent post.
373
388
  */
374
389
 
375
- export const getAutosave = (postType, postId) => async ({
376
- resolveSelect
377
- }) => {
390
+ export const getAutosave = (postType, postId) => async _ref10 => {
391
+ let {
392
+ resolveSelect
393
+ } = _ref10;
378
394
  await resolveSelect.getAutosaves(postType, postId);
379
395
  };
380
396
  /**
@@ -383,10 +399,11 @@ export const getAutosave = (postType, postId) => async ({
383
399
  * @param {string} link Link.
384
400
  */
385
401
 
386
- export const __experimentalGetTemplateForLink = link => async ({
387
- dispatch,
388
- resolveSelect
389
- }) => {
402
+ export const __experimentalGetTemplateForLink = link => async _ref11 => {
403
+ let {
404
+ dispatch,
405
+ resolveSelect
406
+ } = _ref11;
390
407
  // Ideally this should be using an apiFetch call
391
408
  // We could potentially do so by adding a "filter" to the `wp_template` end point.
392
409
  // Also it seems the returned object is not a regular REST API post type.
@@ -395,9 +412,12 @@ export const __experimentalGetTemplateForLink = link => async ({
395
412
  try {
396
413
  template = await window.fetch(addQueryArgs(link, {
397
414
  '_wp-find-template': true
398
- })).then(res => res.json()).then(({
399
- data
400
- }) => data);
415
+ })).then(res => res.json()).then(_ref12 => {
416
+ let {
417
+ data
418
+ } = _ref12;
419
+ return data;
420
+ });
401
421
  } catch (e) {// For non-FSE themes, it is possible that this request returns an error.
402
422
  }
403
423
 
@@ -417,4 +437,34 @@ export const __experimentalGetTemplateForLink = link => async ({
417
437
  __experimentalGetTemplateForLink.shouldInvalidate = action => {
418
438
  return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template';
419
439
  };
440
+
441
+ export const __experimentalGetCurrentGlobalStylesId = () => async _ref13 => {
442
+ let {
443
+ dispatch,
444
+ resolveSelect
445
+ } = _ref13;
446
+ const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
447
+ status: 'active'
448
+ });
449
+ const globalStylesURL = get(activeThemes, [0, '_links', 'wp:user-global-styles', 0, 'href']);
450
+
451
+ if (globalStylesURL) {
452
+ const globalStylesObject = await apiFetch({
453
+ url: globalStylesURL
454
+ });
455
+
456
+ dispatch.__experimentalReceiveCurrentGlobalStylesId(globalStylesObject.id);
457
+ }
458
+ };
459
+ export const __experimentalGetCurrentThemeBaseGlobalStyles = () => async _ref14 => {
460
+ let {
461
+ resolveSelect,
462
+ dispatch
463
+ } = _ref14;
464
+ const currentTheme = await resolveSelect.getCurrentTheme();
465
+ const themeGlobalStyles = await apiFetch({
466
+ path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}`
467
+ });
468
+ await dispatch.__experimentalReceiveThemeBaseGlobalStyles(currentTheme.stylesheet, themeGlobalStyles);
469
+ };
420
470
  //# sourceMappingURL=resolvers.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["find","includes","get","hasIn","compact","uniq","addQueryArgs","apiFetch","STORE_NAME","getKindEntities","DEFAULT_ENTITY_KEY","ifNotResolved","getNormalizedCommaSeparable","getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","entities","entity","__experimentalNoFetch","lock","__unstableAcquireStoreLock","exclusive","undefined","_fields","join","baseURL","baseURLParams","include","hasRecords","hasEntityRecords","record","receiveEntityRecords","error","__unstableReleaseStoreLock","getRawEntityRecord","getEditedEntityRecord","getEntityRecords","records","Object","values","map","split","forEach","field","hasOwnProperty","context","resolutionsArgs","filter","type","selectorName","args","shouldInvalidate","action","invalidateCache","getCurrentTheme","activeThemes","receiveCurrentTheme","getThemeSupports","receiveThemeSupports","theme_supports","getEmbedPreview","url","embedProxyResponse","receiveEmbedPreview","canUser","resource","id","methods","create","read","update","delete","method","Error","response","parse","allowHeader","headers","isAllowed","receiveUserPermission","canUserEditEntityRecord","recordId","__unstable_rest_base","getAutosaves","postType","postId","resolveSelect","rest_base","restBase","getPostType","autosaves","length","receiveAutosaves","getAutosave","__experimentalGetTemplateForLink","link","template","window","fetch","then","res","json","data","e"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,QAAf,EAAyBC,GAAzB,EAA8BC,KAA9B,EAAqCC,OAArC,EAA8CC,IAA9C,QAA0D,QAA1D;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,QAA3B;AACA,SAASC,eAAT,EAA0BC,kBAA1B,QAAoD,YAApD;AACA,SAASC,aAAT,EAAwBC,2BAAxB,QAA2D,SAA3D;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMC,UAAU,GAAKC,KAAF,IAAa,OAAQ;AAAEC,EAAAA;AAAF,CAAR,KAA0B;AAChE,QAAMC,IAAI,GAAGV,YAAY,CACxB,wCADwB,EAExBQ,KAFwB,CAAzB;AAIA,QAAMG,KAAK,GAAG,MAAMV,QAAQ,CAAE;AAAES,IAAAA;AAAF,GAAF,CAA5B;AACAD,EAAAA,QAAQ,CAACG,gBAAT,CAA2BF,IAA3B,EAAiCC,KAAjC;AACA,CAPM;AASP;AACA;AACA;;AACA,OAAO,MAAME,cAAc,GAAG,MAAM,OAAQ;AAAEJ,EAAAA;AAAF,CAAR,KAA0B;AAC7D,QAAMK,WAAW,GAAG,MAAMb,QAAQ,CAAE;AAAES,IAAAA,IAAI,EAAE;AAAR,GAAF,CAAlC;AACAD,EAAAA,QAAQ,CAACM,kBAAT,CAA6BD,WAA7B;AACA,CAHM;AAKP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAME,eAAe,GAAG,CAAEC,IAAF,EAAQC,IAAR,EAAcC,GAAG,GAAG,EAApB,EAAwBX,KAAxB,KAAmC,OAAQ;AACzEY,EAAAA,MADyE;AAEzEX,EAAAA;AAFyE,CAAR,KAG3D;AACN,QAAMY,QAAQ,GAAG,MAAMZ,QAAQ,C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AACA;AACA;AACA,MAAIU,QAAJ;;AACA,MAAI;AACHA,IAAAA,QAAQ,GAAG,MAAMC,MAAM,CACrBC,KADe,CACRvG,YAAY,CAAEoG,IAAF,EAAQ;AAAE,2BAAqB;AAAvB,KAAR,CADJ,EAEfI,IAFe,CAEPC,GAAF,IAAWA,GAAG,CAACC,IAAJ,EAFF,EAGfF,IAHe,CAGT,CAAE;AAAEG,MAAAA;AAAF,KAAF,KAAgBA,IAHP,CAAjB;AAIA,GALD,CAKE,OAAQC,CAAR,EAAY,CACb;AACA;;AAED,MAAK,CAAEP,QAAP,EAAkB;AACjB;AACA;;AAED,QAAMlE,MAAM,GAAG,MAAMwD,aAAa,CAAC3E,eAAd,CACpB,UADoB,EAEpB,aAFoB,EAGpBqF,QAAQ,CAAC9B,EAHW,CAArB;;AAMA,MAAKpC,MAAL,EAAc;AACb1B,IAAAA,QAAQ,CAAC2B,oBAAT,CAA+B,UAA/B,EAA2C,aAA3C,EAA0D,CAAED,MAAF,CAA1D,EAAsE;AACrE,uBAAiBiE;AADoD,KAAtE;AAGA;AACD,CAhCM;;AAkCPD,gCAAgC,CAAC3C,gBAAjC,GAAsDC,MAAF,IAAc;AACjE,SACC,CAAEA,MAAM,CAACJ,IAAP,KAAgB,eAAhB,IAAmCI,MAAM,CAACJ,IAAP,KAAgB,cAArD,KACAI,MAAM,CAACC,eADP,IAEAD,MAAM,CAACxC,IAAP,KAAgB,UAFhB,IAGAwC,MAAM,CAACvC,IAAP,KAAgB,aAJjB;AAMA,CAPD","sourcesContent":["/**\n * External dependencies\n */\nimport { find, includes, get, hasIn, compact, uniq } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { getKindEntities, DEFAULT_ENTITY_KEY } from './entities';\nimport { ifNotResolved, getNormalizedCommaSeparable } from './utils';\n\n/**\n * Requests authors from the REST API.\n *\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getAuthors = ( query ) => async ( { dispatch } ) => {\n\tconst path = addQueryArgs(\n\t\t'/wp/v2/users/?who=authors&per_page=100',\n\t\tquery\n\t);\n\tconst users = await apiFetch( { path } );\n\tdispatch.receiveUserQuery( path, users );\n};\n\n/**\n * Requests the current user from the REST API.\n */\nexport const getCurrentUser = () => async ( { dispatch } ) => {\n\tconst currentUser = await apiFetch( { path: '/wp/v2/users/me' } );\n\tdispatch.receiveCurrentUser( currentUser );\n};\n\n/**\n * Requests an entity's record from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} key Record's key\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getEntityRecord = ( kind, name, key = '', query ) => async ( {\n\tselect,\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity || entity?.__experimentalNoFetch ) {\n\t\treturn;\n\t}\n\n\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'data', kind, name, key ],\n\t\t{ exclusive: false }\n\t);\n\n\ttry {\n\t\tif ( query !== undefined && query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentity.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\t// Disable reason: While true that an early return could leave `path`\n\t\t// unused, it's important that path is derived using the query prior to\n\t\t// additional query modifications in the condition below, since those\n\t\t// modifications are relevant to how the data is tracked in state, and not\n\t\t// for how the request is made to the REST API.\n\n\t\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\t\tconst path = addQueryArgs( entity.baseURL + ( key ? '/' + key : '' ), {\n\t\t\t...entity.baseURLParams,\n\t\t\t...query,\n\t\t} );\n\n\t\tif ( query !== undefined ) {\n\t\t\tquery = { ...query, include: [ key ] };\n\n\t\t\t// The resolution cache won't consider query as reusable based on the\n\t\t\t// fields, so it's tested here, prior to initiating the REST request,\n\t\t\t// and without causing `getEntityRecords` resolution to occur.\n\t\t\tconst hasRecords = select.hasEntityRecords( kind, name, query );\n\t\t\tif ( hasRecords ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst record = await apiFetch( { path } );\n\t\tdispatch.receiveEntityRecords( kind, name, record, query );\n\t} catch ( error ) {\n\t\t// We need a way to handle and access REST API errors in state\n\t\t// Until then, catching the error ensures the resolver is marked as resolved.\n\t} finally {\n\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t}\n};\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getRawEntityRecord = ifNotResolved(\n\tgetEntityRecord,\n\t'getEntityRecord'\n);\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getEditedEntityRecord = ifNotResolved(\n\tgetRawEntityRecord,\n\t'getRawEntityRecord'\n);\n\n/**\n * Requests the entity's records from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {Object?} query Query Object.\n */\nexport const getEntityRecords = ( kind, name, query = {} ) => async ( {\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity || entity?.__experimentalNoFetch ) {\n\t\treturn;\n\t}\n\n\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'data', kind, name ],\n\t\t{ exclusive: false }\n\t);\n\n\ttry {\n\t\tif ( query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentity.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\tconst path = addQueryArgs( entity.baseURL, {\n\t\t\t...entity.baseURLParams,\n\t\t\t...query,\n\t\t} );\n\n\t\tlet records = Object.values( await apiFetch( { path } ) );\n\t\t// If we request fields but the result doesn't contain the fields,\n\t\t// explicitely set these fields as \"undefined\"\n\t\t// that way we consider the query \"fullfilled\".\n\t\tif ( query._fields ) {\n\t\t\trecords = records.map( ( record ) => {\n\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t}\n\t\t\t\t} );\n\n\t\t\t\treturn record;\n\t\t\t} );\n\t\t}\n\n\t\tdispatch.receiveEntityRecords( kind, name, records, query );\n\n\t\t// When requesting all fields, the list of results can be used to\n\t\t// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.\n\t\t// See https://github.com/WordPress/gutenberg/pull/26575\n\t\tif ( ! query?._fields && ! query.context ) {\n\t\t\tconst key = entity.key || DEFAULT_ENTITY_KEY;\n\t\t\tconst resolutionsArgs = records\n\t\t\t\t.filter( ( record ) => record[ key ] )\n\t\t\t\t.map( ( record ) => [ kind, name, record[ key ] ] );\n\n\t\t\tdispatch( {\n\t\t\t\ttype: 'START_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t} );\n\t\t\tdispatch( {\n\t\t\t\ttype: 'FINISH_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t} );\n\t\t}\n\t} finally {\n\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t}\n};\n\ngetEntityRecords.shouldInvalidate = ( action, kind, name ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\tkind === action.kind &&\n\t\tname === action.name\n\t);\n};\n\n/**\n * Requests the current theme.\n */\nexport const getCurrentTheme = () => async ( { dispatch } ) => {\n\tconst activeThemes = await apiFetch( {\n\t\tpath: '/wp/v2/themes?status=active',\n\t} );\n\tdispatch.receiveCurrentTheme( activeThemes[ 0 ] );\n};\n\n/**\n * Requests theme supports data from the index.\n */\nexport const getThemeSupports = () => async ( { dispatch } ) => {\n\tconst activeThemes = await apiFetch( {\n\t\tpath: '/wp/v2/themes?status=active',\n\t} );\n\tdispatch.receiveThemeSupports( activeThemes[ 0 ].theme_supports );\n};\n\n/**\n * Requests a preview from the from the Embed API.\n *\n * @param {string} url URL to get the preview for.\n */\nexport const getEmbedPreview = ( url ) => async ( { dispatch } ) => {\n\ttry {\n\t\tconst embedProxyResponse = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/oembed/1.0/proxy', { url } ),\n\t\t} );\n\t\tdispatch.receiveEmbedPreview( url, embedProxyResponse );\n\t} catch ( error ) {\n\t\t// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.\n\t\tdispatch.receiveEmbedPreview( url, false );\n\t}\n};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} action Action to check. One of: 'create', 'read', 'update',\n * 'delete'.\n * @param {string} resource REST resource to check, e.g. 'media' or 'posts'.\n * @param {?string} id ID of the rest resource to check.\n */\nexport const canUser = ( action, resource, id ) => async ( { dispatch } ) => {\n\tconst methods = {\n\t\tcreate: 'POST',\n\t\tread: 'GET',\n\t\tupdate: 'PUT',\n\t\tdelete: 'DELETE',\n\t};\n\n\tconst method = methods[ action ];\n\tif ( ! method ) {\n\t\tthrow new Error( `'${ action }' is not a valid action.` );\n\t}\n\n\tconst path = id ? `/wp/v2/${ resource }/${ id }` : `/wp/v2/${ resource }`;\n\n\tlet response;\n\ttry {\n\t\tresponse = await apiFetch( {\n\t\t\tpath,\n\t\t\t// Ideally this would always be an OPTIONS request, but unfortunately there's\n\t\t\t// a bug in the REST API which causes the Allow header to not be sent on\n\t\t\t// OPTIONS requests to /posts/:id routes.\n\t\t\t// https://core.trac.wordpress.org/ticket/45753\n\t\t\tmethod: id ? 'GET' : 'OPTIONS',\n\t\t\tparse: false,\n\t\t} );\n\t} catch ( error ) {\n\t\t// Do nothing if our OPTIONS request comes back with an API error (4xx or\n\t\t// 5xx). The previously determined isAllowed value will remain in the store.\n\t\treturn;\n\t}\n\n\tlet allowHeader;\n\tif ( hasIn( response, [ 'headers', 'get' ] ) ) {\n\t\t// If the request is fetched using the fetch api, the header can be\n\t\t// retrieved using the 'get' method.\n\t\tallowHeader = response.headers.get( 'allow' );\n\t} else {\n\t\t// If the request was preloaded server-side and is returned by the\n\t\t// preloading middleware, the header will be a simple property.\n\t\tallowHeader = get( response, [ 'headers', 'Allow' ], '' );\n\t}\n\n\tconst key = compact( [ action, resource, id ] ).join( '/' );\n\tconst isAllowed = includes( allowHeader, method );\n\tdispatch.receiveUserPermission( key, isAllowed );\n};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} recordId Record's id.\n */\nexport const canUserEditEntityRecord = ( kind, name, recordId ) => async ( {\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity ) {\n\t\treturn;\n\t}\n\n\tconst resource = entity.__unstable_rest_base;\n\tawait dispatch( canUser( 'update', resource, recordId ) );\n};\n\n/**\n * Request autosave data from the REST API.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosaves = ( postType, postId ) => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\tconst { rest_base: restBase } = await resolveSelect.getPostType( postType );\n\tconst autosaves = await apiFetch( {\n\t\tpath: `/wp/v2/${ restBase }/${ postId }/autosaves?context=edit`,\n\t} );\n\n\tif ( autosaves && autosaves.length ) {\n\t\tdispatch.receiveAutosaves( postId, autosaves );\n\t}\n};\n\n/**\n * Request autosave data from the REST API.\n *\n * This resolver exists to ensure the underlying autosaves are fetched via\n * `getAutosaves` when a call to the `getAutosave` selector is made.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosave = ( postType, postId ) => async ( {\n\tresolveSelect,\n} ) => {\n\tawait resolveSelect.getAutosaves( postType, postId );\n};\n\n/**\n * Retrieve the frontend template used for a given link.\n *\n * @param {string} link Link.\n */\nexport const __experimentalGetTemplateForLink = ( link ) => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\t// Ideally this should be using an apiFetch call\n\t// We could potentially do so by adding a \"filter\" to the `wp_template` end point.\n\t// Also it seems the returned object is not a regular REST API post type.\n\tlet template;\n\ttry {\n\t\ttemplate = await window\n\t\t\t.fetch( addQueryArgs( link, { '_wp-find-template': true } ) )\n\t\t\t.then( ( res ) => res.json() )\n\t\t\t.then( ( { data } ) => data );\n\t} catch ( e ) {\n\t\t// For non-FSE themes, it is possible that this request returns an error.\n\t}\n\n\tif ( ! template ) {\n\t\treturn;\n\t}\n\n\tconst record = await resolveSelect.getEntityRecord(\n\t\t'postType',\n\t\t'wp_template',\n\t\ttemplate.id\n\t);\n\n\tif ( record ) {\n\t\tdispatch.receiveEntityRecords( 'postType', 'wp_template', [ record ], {\n\t\t\t'find-template': link,\n\t\t} );\n\t}\n};\n\n__experimentalGetTemplateForLink.shouldInvalidate = ( action ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\taction.kind === 'postType' &&\n\t\taction.name === 'wp_template'\n\t);\n};\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["find","includes","get","hasIn","compact","uniq","addQueryArgs","apiFetch","STORE_NAME","getKindEntities","DEFAULT_ENTITY_KEY","forwardResolver","getNormalizedCommaSeparable","getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","entities","entity","__experimentalNoFetch","lock","__unstableAcquireStoreLock","exclusive","undefined","_fields","join","baseURL","baseURLParams","include","hasRecords","hasEntityRecords","record","receiveEntityRecords","error","__unstableReleaseStoreLock","getRawEntityRecord","getEditedEntityRecord","getEntityRecords","records","Object","values","map","split","forEach","field","hasOwnProperty","context","resolutionsArgs","filter","type","selectorName","args","shouldInvalidate","action","invalidateCache","getCurrentTheme","resolveSelect","activeThemes","status","receiveCurrentTheme","getThemeSupports","getEmbedPreview","url","embedProxyResponse","receiveEmbedPreview","canUser","resource","id","methods","create","read","update","delete","method","Error","response","parse","allowHeader","headers","isAllowed","receiveUserPermission","canUserEditEntityRecord","recordId","__unstable_rest_base","getAutosaves","postType","postId","rest_base","restBase","getPostType","autosaves","length","receiveAutosaves","getAutosave","__experimentalGetTemplateForLink","link","template","window","fetch","then","res","json","data","e","__experimentalGetCurrentGlobalStylesId","globalStylesURL","globalStylesObject","__experimentalReceiveCurrentGlobalStylesId","__experimentalGetCurrentThemeBaseGlobalStyles","currentTheme","themeGlobalStyles","stylesheet","__experimentalReceiveThemeBaseGlobalStyles"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,IAAT,EAAeC,QAAf,EAAyBC,GAAzB,EAA8BC,KAA9B,EAAqCC,OAArC,EAA8CC,IAA9C,QAA0D,QAA1D;AAEA;AACA;AACA;;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,OAAOC,QAAP,MAAqB,sBAArB;AAEA;AACA;AACA;;AACA,SAASC,UAAT,QAA2B,QAA3B;AACA,SAASC,eAAT,EAA0BC,kBAA1B,QAAoD,YAApD;AACA,SAASC,eAAT,EAA0BC,2BAA1B,QAA6D,SAA7D;AAEA;AACA;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AMyC,6CAA6C,GAAG,MAAM,gBAG5D;AAAA,MAHoE;AAC1EpD,IAAAA,aAD0E;AAE1EnD,IAAAA;AAF0E,GAGpE;AACN,QAAMwG,YAAY,GAAG,MAAMrD,aAAa,CAACD,eAAd,EAA3B;AACA,QAAMuD,iBAAiB,GAAG,MAAMjH,QAAQ,CAAE;AACzCS,IAAAA,IAAI,EAAG,+BAA+BuG,YAAY,CAACE,UAAY;AADtB,GAAF,CAAxC;AAGA,QAAM1G,QAAQ,CAAC2G,0CAAT,CACLH,YAAY,CAACE,UADR,EAELD,iBAFK,CAAN;AAIA,CAZM","sourcesContent":["/**\n * External dependencies\n */\nimport { find, includes, get, hasIn, compact, uniq } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport { addQueryArgs } from '@wordpress/url';\nimport apiFetch from '@wordpress/api-fetch';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { getKindEntities, DEFAULT_ENTITY_KEY } from './entities';\nimport { forwardResolver, getNormalizedCommaSeparable } from './utils';\n\n/**\n * Requests authors from the REST API.\n *\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getAuthors = ( query ) => async ( { dispatch } ) => {\n\tconst path = addQueryArgs(\n\t\t'/wp/v2/users/?who=authors&per_page=100',\n\t\tquery\n\t);\n\tconst users = await apiFetch( { path } );\n\tdispatch.receiveUserQuery( path, users );\n};\n\n/**\n * Requests the current user from the REST API.\n */\nexport const getCurrentUser = () => async ( { dispatch } ) => {\n\tconst currentUser = await apiFetch( { path: '/wp/v2/users/me' } );\n\tdispatch.receiveCurrentUser( currentUser );\n};\n\n/**\n * Requests an entity's record from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {number|string} key Record's key\n * @param {Object|undefined} query Optional object of query parameters to\n * include with request.\n */\nexport const getEntityRecord = ( kind, name, key = '', query ) => async ( {\n\tselect,\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity || entity?.__experimentalNoFetch ) {\n\t\treturn;\n\t}\n\n\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'data', kind, name, key ],\n\t\t{ exclusive: false }\n\t);\n\n\ttry {\n\t\tif ( query !== undefined && query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentity.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\t// Disable reason: While true that an early return could leave `path`\n\t\t// unused, it's important that path is derived using the query prior to\n\t\t// additional query modifications in the condition below, since those\n\t\t// modifications are relevant to how the data is tracked in state, and not\n\t\t// for how the request is made to the REST API.\n\n\t\t// eslint-disable-next-line @wordpress/no-unused-vars-before-return\n\t\tconst path = addQueryArgs( entity.baseURL + ( key ? '/' + key : '' ), {\n\t\t\t...entity.baseURLParams,\n\t\t\t...query,\n\t\t} );\n\n\t\tif ( query !== undefined ) {\n\t\t\tquery = { ...query, include: [ key ] };\n\n\t\t\t// The resolution cache won't consider query as reusable based on the\n\t\t\t// fields, so it's tested here, prior to initiating the REST request,\n\t\t\t// and without causing `getEntityRecords` resolution to occur.\n\t\t\tconst hasRecords = select.hasEntityRecords( kind, name, query );\n\t\t\tif ( hasRecords ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t}\n\n\t\tconst record = await apiFetch( { path } );\n\t\tdispatch.receiveEntityRecords( kind, name, record, query );\n\t} catch ( error ) {\n\t\t// We need a way to handle and access REST API errors in state\n\t\t// Until then, catching the error ensures the resolver is marked as resolved.\n\t\t// See similar implementation in `getEntityRecords()`.\n\t} finally {\n\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t}\n};\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getRawEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests an entity's record from the REST API.\n */\nexport const getEditedEntityRecord = forwardResolver( 'getEntityRecord' );\n\n/**\n * Requests the entity's records from the REST API.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {Object?} query Query Object.\n */\nexport const getEntityRecords = ( kind, name, query = {} ) => async ( {\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity || entity?.__experimentalNoFetch ) {\n\t\treturn;\n\t}\n\n\tconst lock = await dispatch.__unstableAcquireStoreLock(\n\t\tSTORE_NAME,\n\t\t[ 'entities', 'data', kind, name ],\n\t\t{ exclusive: false }\n\t);\n\n\ttry {\n\t\tif ( query._fields ) {\n\t\t\t// If requesting specific fields, items and query association to said\n\t\t\t// records are stored by ID reference. Thus, fields must always include\n\t\t\t// the ID.\n\t\t\tquery = {\n\t\t\t\t...query,\n\t\t\t\t_fields: uniq( [\n\t\t\t\t\t...( getNormalizedCommaSeparable( query._fields ) || [] ),\n\t\t\t\t\tentity.key || DEFAULT_ENTITY_KEY,\n\t\t\t\t] ).join(),\n\t\t\t};\n\t\t}\n\n\t\tconst path = addQueryArgs( entity.baseURL, {\n\t\t\t...entity.baseURLParams,\n\t\t\t...query,\n\t\t} );\n\n\t\tlet records = Object.values( await apiFetch( { path } ) );\n\t\t// If we request fields but the result doesn't contain the fields,\n\t\t// explicitely set these fields as \"undefined\"\n\t\t// that way we consider the query \"fullfilled\".\n\t\tif ( query._fields ) {\n\t\t\trecords = records.map( ( record ) => {\n\t\t\t\tquery._fields.split( ',' ).forEach( ( field ) => {\n\t\t\t\t\tif ( ! record.hasOwnProperty( field ) ) {\n\t\t\t\t\t\trecord[ field ] = undefined;\n\t\t\t\t\t}\n\t\t\t\t} );\n\n\t\t\t\treturn record;\n\t\t\t} );\n\t\t}\n\n\t\tdispatch.receiveEntityRecords( kind, name, records, query );\n\n\t\t// When requesting all fields, the list of results can be used to\n\t\t// resolve the `getEntityRecord` selector in addition to `getEntityRecords`.\n\t\t// See https://github.com/WordPress/gutenberg/pull/26575\n\t\tif ( ! query?._fields && ! query.context ) {\n\t\t\tconst key = entity.key || DEFAULT_ENTITY_KEY;\n\t\t\tconst resolutionsArgs = records\n\t\t\t\t.filter( ( record ) => record[ key ] )\n\t\t\t\t.map( ( record ) => [ kind, name, record[ key ] ] );\n\n\t\t\tdispatch( {\n\t\t\t\ttype: 'START_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t} );\n\t\t\tdispatch( {\n\t\t\t\ttype: 'FINISH_RESOLUTIONS',\n\t\t\t\tselectorName: 'getEntityRecord',\n\t\t\t\targs: resolutionsArgs,\n\t\t\t} );\n\t\t}\n\t} catch ( error ) {\n\t\t// We need a way to handle and access REST API errors in state\n\t\t// Until then, catching the error ensures the resolver is marked as resolved.\n\t\t// See similar implementation in `getEntityRecord()`.\n\t} finally {\n\t\tdispatch.__unstableReleaseStoreLock( lock );\n\t}\n};\n\ngetEntityRecords.shouldInvalidate = ( action, kind, name ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\tkind === action.kind &&\n\t\tname === action.name\n\t);\n};\n\n/**\n * Requests the current theme.\n */\nexport const getCurrentTheme = () => async ( { dispatch, resolveSelect } ) => {\n\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t'root',\n\t\t'theme',\n\t\t{ status: 'active' }\n\t);\n\n\tdispatch.receiveCurrentTheme( activeThemes[ 0 ] );\n};\n\n/**\n * Requests theme supports data from the index.\n */\nexport const getThemeSupports = forwardResolver( 'getCurrentTheme' );\n\n/**\n * Requests a preview from the from the Embed API.\n *\n * @param {string} url URL to get the preview for.\n */\nexport const getEmbedPreview = ( url ) => async ( { dispatch } ) => {\n\ttry {\n\t\tconst embedProxyResponse = await apiFetch( {\n\t\t\tpath: addQueryArgs( '/oembed/1.0/proxy', { url } ),\n\t\t} );\n\t\tdispatch.receiveEmbedPreview( url, embedProxyResponse );\n\t} catch ( error ) {\n\t\t// Embed API 404s if the URL cannot be embedded, so we have to catch the error from the apiRequest here.\n\t\tdispatch.receiveEmbedPreview( url, false );\n\t}\n};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} action Action to check. One of: 'create', 'read', 'update',\n * 'delete'.\n * @param {string} resource REST resource to check, e.g. 'media' or 'posts'.\n * @param {?string} id ID of the rest resource to check.\n */\nexport const canUser = ( action, resource, id ) => async ( { dispatch } ) => {\n\tconst methods = {\n\t\tcreate: 'POST',\n\t\tread: 'GET',\n\t\tupdate: 'PUT',\n\t\tdelete: 'DELETE',\n\t};\n\n\tconst method = methods[ action ];\n\tif ( ! method ) {\n\t\tthrow new Error( `'${ action }' is not a valid action.` );\n\t}\n\n\tconst path = id ? `/wp/v2/${ resource }/${ id }` : `/wp/v2/${ resource }`;\n\n\tlet response;\n\ttry {\n\t\tresponse = await apiFetch( {\n\t\t\tpath,\n\t\t\t// Ideally this would always be an OPTIONS request, but unfortunately there's\n\t\t\t// a bug in the REST API which causes the Allow header to not be sent on\n\t\t\t// OPTIONS requests to /posts/:id routes.\n\t\t\t// https://core.trac.wordpress.org/ticket/45753\n\t\t\tmethod: id ? 'GET' : 'OPTIONS',\n\t\t\tparse: false,\n\t\t} );\n\t} catch ( error ) {\n\t\t// Do nothing if our OPTIONS request comes back with an API error (4xx or\n\t\t// 5xx). The previously determined isAllowed value will remain in the store.\n\t\treturn;\n\t}\n\n\tlet allowHeader;\n\tif ( hasIn( response, [ 'headers', 'get' ] ) ) {\n\t\t// If the request is fetched using the fetch api, the header can be\n\t\t// retrieved using the 'get' method.\n\t\tallowHeader = response.headers.get( 'allow' );\n\t} else {\n\t\t// If the request was preloaded server-side and is returned by the\n\t\t// preloading middleware, the header will be a simple property.\n\t\tallowHeader = get( response, [ 'headers', 'Allow' ], '' );\n\t}\n\n\tconst key = compact( [ action, resource, id ] ).join( '/' );\n\tconst isAllowed = includes( allowHeader, method );\n\tdispatch.receiveUserPermission( key, isAllowed );\n};\n\n/**\n * Checks whether the current user can perform the given action on the given\n * REST resource.\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} recordId Record's id.\n */\nexport const canUserEditEntityRecord = ( kind, name, recordId ) => async ( {\n\tdispatch,\n} ) => {\n\tconst entities = await dispatch( getKindEntities( kind ) );\n\tconst entity = find( entities, { kind, name } );\n\tif ( ! entity ) {\n\t\treturn;\n\t}\n\n\tconst resource = entity.__unstable_rest_base;\n\tawait dispatch( canUser( 'update', resource, recordId ) );\n};\n\n/**\n * Request autosave data from the REST API.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosaves = ( postType, postId ) => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\tconst { rest_base: restBase } = await resolveSelect.getPostType( postType );\n\tconst autosaves = await apiFetch( {\n\t\tpath: `/wp/v2/${ restBase }/${ postId }/autosaves?context=edit`,\n\t} );\n\n\tif ( autosaves && autosaves.length ) {\n\t\tdispatch.receiveAutosaves( postId, autosaves );\n\t}\n};\n\n/**\n * Request autosave data from the REST API.\n *\n * This resolver exists to ensure the underlying autosaves are fetched via\n * `getAutosaves` when a call to the `getAutosave` selector is made.\n *\n * @param {string} postType The type of the parent post.\n * @param {number} postId The id of the parent post.\n */\nexport const getAutosave = ( postType, postId ) => async ( {\n\tresolveSelect,\n} ) => {\n\tawait resolveSelect.getAutosaves( postType, postId );\n};\n\n/**\n * Retrieve the frontend template used for a given link.\n *\n * @param {string} link Link.\n */\nexport const __experimentalGetTemplateForLink = ( link ) => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\t// Ideally this should be using an apiFetch call\n\t// We could potentially do so by adding a \"filter\" to the `wp_template` end point.\n\t// Also it seems the returned object is not a regular REST API post type.\n\tlet template;\n\ttry {\n\t\ttemplate = await window\n\t\t\t.fetch( addQueryArgs( link, { '_wp-find-template': true } ) )\n\t\t\t.then( ( res ) => res.json() )\n\t\t\t.then( ( { data } ) => data );\n\t} catch ( e ) {\n\t\t// For non-FSE themes, it is possible that this request returns an error.\n\t}\n\n\tif ( ! template ) {\n\t\treturn;\n\t}\n\n\tconst record = await resolveSelect.getEntityRecord(\n\t\t'postType',\n\t\t'wp_template',\n\t\ttemplate.id\n\t);\n\n\tif ( record ) {\n\t\tdispatch.receiveEntityRecords( 'postType', 'wp_template', [ record ], {\n\t\t\t'find-template': link,\n\t\t} );\n\t}\n};\n\n__experimentalGetTemplateForLink.shouldInvalidate = ( action ) => {\n\treturn (\n\t\t( action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS' ) &&\n\t\taction.invalidateCache &&\n\t\taction.kind === 'postType' &&\n\t\taction.name === 'wp_template'\n\t);\n};\n\nexport const __experimentalGetCurrentGlobalStylesId = () => async ( {\n\tdispatch,\n\tresolveSelect,\n} ) => {\n\tconst activeThemes = await resolveSelect.getEntityRecords(\n\t\t'root',\n\t\t'theme',\n\t\t{ status: 'active' }\n\t);\n\tconst globalStylesURL = get( activeThemes, [\n\t\t0,\n\t\t'_links',\n\t\t'wp:user-global-styles',\n\t\t0,\n\t\t'href',\n\t] );\n\tif ( globalStylesURL ) {\n\t\tconst globalStylesObject = await apiFetch( {\n\t\t\turl: globalStylesURL,\n\t\t} );\n\t\tdispatch.__experimentalReceiveCurrentGlobalStylesId(\n\t\t\tglobalStylesObject.id\n\t\t);\n\t}\n};\n\nexport const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ( {\n\tresolveSelect,\n\tdispatch,\n} ) => {\n\tconst currentTheme = await resolveSelect.getCurrentTheme();\n\tconst themeGlobalStyles = await apiFetch( {\n\t\tpath: `/wp/v2/global-styles/themes/${ currentTheme.stylesheet }`,\n\t} );\n\tawait dispatch.__experimentalReceiveThemeBaseGlobalStyles(\n\t\tcurrentTheme.stylesheet,\n\t\tthemeGlobalStyles\n\t);\n};\n"]}