@wordpress/core-data 4.0.5 → 4.0.10-next.33ec3857e2.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 (85) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/actions.js +269 -244
  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 +22 -10
  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 +2 -1
  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 +77 -28
  32. package/build/reducer.js.map +1 -1
  33. package/build/resolvers.js +186 -158
  34. package/build/resolvers.js.map +1 -1
  35. package/build/selectors.js +31 -36
  36. package/build/selectors.js.map +1 -1
  37. package/build/utils/forward-resolver.js +11 -4
  38. package/build/utils/forward-resolver.js.map +1 -1
  39. package/build/utils/index.js +8 -8
  40. package/build/utils/on-sub-key.js +4 -2
  41. package/build/utils/on-sub-key.js.map +1 -1
  42. package/build-module/actions.js +257 -235
  43. package/build-module/actions.js.map +1 -1
  44. package/build-module/batch/create-batch.js +17 -9
  45. package/build-module/batch/create-batch.js.map +1 -1
  46. package/build-module/entities.js +21 -9
  47. package/build-module/entities.js.map +1 -1
  48. package/build-module/entity-provider.js +17 -12
  49. package/build-module/entity-provider.js.map +1 -1
  50. package/build-module/fetch/__experimental-fetch-link-suggestions.js +3 -1
  51. package/build-module/fetch/__experimental-fetch-link-suggestions.js.map +1 -1
  52. package/build-module/fetch/__experimental-fetch-url-data.js +2 -1
  53. package/build-module/fetch/__experimental-fetch-url-data.js.map +1 -1
  54. package/build-module/index.js +21 -3
  55. package/build-module/index.js.map +1 -1
  56. package/build-module/locks/actions.js +4 -3
  57. package/build-module/locks/actions.js.map +1 -1
  58. package/build-module/locks/reducer.js +4 -1
  59. package/build-module/locks/reducer.js.map +1 -1
  60. package/build-module/locks/selectors.js +4 -3
  61. package/build-module/locks/selectors.js.map +1 -1
  62. package/build-module/locks/utils.js +5 -3
  63. package/build-module/locks/utils.js.map +1 -1
  64. package/build-module/queried-data/actions.js +5 -2
  65. package/build-module/queried-data/actions.js.map +1 -1
  66. package/build-module/queried-data/reducer.js +15 -4
  67. package/build-module/queried-data/reducer.js.map +1 -1
  68. package/build-module/queried-data/selectors.js +2 -1
  69. package/build-module/queried-data/selectors.js.map +1 -1
  70. package/build-module/reducer.js +68 -20
  71. package/build-module/reducer.js.map +1 -1
  72. package/build-module/resolvers.js +185 -157
  73. package/build-module/resolvers.js.map +1 -1
  74. package/build-module/selectors.js +2 -15
  75. package/build-module/selectors.js.map +1 -1
  76. package/build-module/utils/forward-resolver.js +11 -4
  77. package/build-module/utils/forward-resolver.js.map +1 -1
  78. package/build-module/utils/on-sub-key.js +3 -1
  79. package/build-module/utils/on-sub-key.js.map +1 -1
  80. package/package.json +12 -12
  81. package/src/entities.js +12 -4
  82. package/src/resolvers.js +5 -0
  83. package/src/selectors.js +2 -15
  84. package/src/test/actions.js +2 -2
  85. package/src/test/selectors.js +4 -4
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.__experimentalGetCurrentThemeBaseGlobalStyles = exports.__experimentalGetCurrentGlobalStylesId = exports.__experimentalGetTemplateForLink = exports.getAutosave = exports.getAutosaves = exports.canUserEditEntityRecord = exports.canUser = exports.getEmbedPreview = exports.getThemeSupports = exports.getCurrentTheme = exports.getEntityRecords = exports.getEditedEntityRecord = exports.getRawEntityRecord = exports.getEntityRecord = exports.getCurrentUser = exports.getAuthors = void 0;
8
+ exports.getThemeSupports = exports.getRawEntityRecord = exports.getEntityRecords = exports.getEntityRecord = exports.getEmbedPreview = exports.getEditedEntityRecord = exports.getCurrentUser = exports.getCurrentTheme = exports.getAutosaves = exports.getAutosave = exports.getAuthors = exports.canUserEditEntityRecord = exports.canUser = exports.__experimentalGetTemplateForLink = exports.__experimentalGetCurrentThemeBaseGlobalStyles = exports.__experimentalGetCurrentGlobalStylesId = void 0;
9
9
 
10
10
  var _lodash = require("lodash");
11
11
 
@@ -37,9 +37,10 @@ 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 ({
41
- dispatch
42
- }) => {
40
+ const getAuthors = query => async _ref => {
41
+ let {
42
+ dispatch
43
+ } = _ref;
43
44
  const path = (0, _url.addQueryArgs)('/wp/v2/users/?who=authors&per_page=100', query);
44
45
  const users = await (0, _apiFetch.default)({
45
46
  path
@@ -53,9 +54,10 @@ const getAuthors = query => async ({
53
54
 
54
55
  exports.getAuthors = getAuthors;
55
56
 
56
- const getCurrentUser = () => async ({
57
- dispatch
58
- }) => {
57
+ const getCurrentUser = () => async _ref2 => {
58
+ let {
59
+ dispatch
60
+ } = _ref2;
59
61
  const currentUser = await (0, _apiFetch.default)({
60
62
  path: '/wp/v2/users/me'
61
63
  });
@@ -74,67 +76,73 @@ const getCurrentUser = () => async ({
74
76
 
75
77
  exports.getCurrentUser = getCurrentUser;
76
78
 
77
- const getEntityRecord = (kind, name, key = '', query) => async ({
78
- select,
79
- dispatch
80
- }) => {
81
- const entities = await dispatch((0, _entities.getKindEntities)(kind));
82
- const entity = (0, _lodash.find)(entities, {
83
- kind,
84
- name
85
- });
86
-
87
- if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
88
- return;
89
- }
79
+ const getEntityRecord = function (kind, name) {
80
+ let key = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
81
+ let query = arguments.length > 3 ? arguments[3] : undefined;
82
+ return async _ref3 => {
83
+ let {
84
+ select,
85
+ dispatch
86
+ } = _ref3;
87
+ const entities = await dispatch((0, _entities.getKindEntities)(kind));
88
+ const entity = (0, _lodash.find)(entities, {
89
+ kind,
90
+ name
91
+ });
90
92
 
91
- const lock = await dispatch.__unstableAcquireStoreLock(_name.STORE_NAME, ['entities', 'data', kind, name, key], {
92
- exclusive: false
93
- });
93
+ if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
94
+ return;
95
+ }
94
96
 
95
- try {
96
- if (query !== undefined && query._fields) {
97
- // If requesting specific fields, items and query association to said
98
- // records are stored by ID reference. Thus, fields must always include
99
- // the ID.
100
- query = { ...query,
101
- _fields: (0, _lodash.uniq)([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entity.key || _entities.DEFAULT_ENTITY_KEY]).join()
102
- };
103
- } // Disable reason: While true that an early return could leave `path`
104
- // unused, it's important that path is derived using the query prior to
105
- // additional query modifications in the condition below, since those
106
- // modifications are relevant to how the data is tracked in state, and not
107
- // for how the request is made to the REST API.
108
- // eslint-disable-next-line @wordpress/no-unused-vars-before-return
109
-
110
-
111
- const path = (0, _url.addQueryArgs)(entity.baseURL + (key ? '/' + key : ''), { ...entity.baseURLParams,
112
- ...query
97
+ const lock = await dispatch.__unstableAcquireStoreLock(_name.STORE_NAME, ['entities', 'data', kind, name, key], {
98
+ exclusive: false
113
99
  });
114
100
 
115
- if (query !== undefined) {
116
- query = { ...query,
117
- include: [key]
118
- }; // The resolution cache won't consider query as reusable based on the
119
- // fields, so it's tested here, prior to initiating the REST request,
120
- // and without causing `getEntityRecords` resolution to occur.
101
+ try {
102
+ if (query !== undefined && query._fields) {
103
+ // If requesting specific fields, items and query association to said
104
+ // records are stored by ID reference. Thus, fields must always include
105
+ // the ID.
106
+ query = { ...query,
107
+ _fields: (0, _lodash.uniq)([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entity.key || _entities.DEFAULT_ENTITY_KEY]).join()
108
+ };
109
+ } // Disable reason: While true that an early return could leave `path`
110
+ // unused, it's important that path is derived using the query prior to
111
+ // additional query modifications in the condition below, since those
112
+ // modifications are relevant to how the data is tracked in state, and not
113
+ // for how the request is made to the REST API.
114
+ // eslint-disable-next-line @wordpress/no-unused-vars-before-return
115
+
116
+
117
+ const path = (0, _url.addQueryArgs)(entity.baseURL + (key ? '/' + key : ''), { ...entity.baseURLParams,
118
+ ...query
119
+ });
120
+
121
+ if (query !== undefined) {
122
+ query = { ...query,
123
+ include: [key]
124
+ }; // The resolution cache won't consider query as reusable based on the
125
+ // fields, so it's tested here, prior to initiating the REST request,
126
+ // and without causing `getEntityRecords` resolution to occur.
121
127
 
122
- const hasRecords = select.hasEntityRecords(kind, name, query);
128
+ const hasRecords = select.hasEntityRecords(kind, name, query);
123
129
 
124
- if (hasRecords) {
125
- return;
130
+ if (hasRecords) {
131
+ return;
132
+ }
126
133
  }
127
- }
128
134
 
129
- const record = await (0, _apiFetch.default)({
130
- path
131
- });
132
- dispatch.receiveEntityRecords(kind, name, record, query);
133
- } catch (error) {// We need a way to handle and access REST API errors in state
134
- // Until then, catching the error ensures the resolver is marked as resolved.
135
- } finally {
136
- dispatch.__unstableReleaseStoreLock(lock);
137
- }
135
+ const record = await (0, _apiFetch.default)({
136
+ path
137
+ });
138
+ dispatch.receiveEntityRecords(kind, name, record, query);
139
+ } catch (error) {// We need a way to handle and access REST API errors in state
140
+ // Until then, catching the error ensures the resolver is marked as resolved.
141
+ // See similar implementation in `getEntityRecords()`.
142
+ } finally {
143
+ dispatch.__unstableReleaseStoreLock(lock);
144
+ }
145
+ };
138
146
  };
139
147
  /**
140
148
  * Requests an entity's record from the REST API.
@@ -159,77 +167,84 @@ const getEditedEntityRecord = (0, _utils.forwardResolver)('getEntityRecord');
159
167
 
160
168
  exports.getEditedEntityRecord = getEditedEntityRecord;
161
169
 
162
- const getEntityRecords = (kind, name, query = {}) => async ({
163
- dispatch
164
- }) => {
165
- const entities = await dispatch((0, _entities.getKindEntities)(kind));
166
- const entity = (0, _lodash.find)(entities, {
167
- kind,
168
- name
169
- });
170
-
171
- if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
172
- return;
173
- }
174
-
175
- const lock = await dispatch.__unstableAcquireStoreLock(_name.STORE_NAME, ['entities', 'data', kind, name], {
176
- exclusive: false
177
- });
170
+ const getEntityRecords = function (kind, name) {
171
+ let query = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
172
+ return async _ref4 => {
173
+ let {
174
+ dispatch
175
+ } = _ref4;
176
+ const entities = await dispatch((0, _entities.getKindEntities)(kind));
177
+ const entity = (0, _lodash.find)(entities, {
178
+ kind,
179
+ name
180
+ });
178
181
 
179
- try {
180
- var _query;
181
-
182
- if (query._fields) {
183
- // If requesting specific fields, items and query association to said
184
- // records are stored by ID reference. Thus, fields must always include
185
- // the ID.
186
- query = { ...query,
187
- _fields: (0, _lodash.uniq)([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entity.key || _entities.DEFAULT_ENTITY_KEY]).join()
188
- };
182
+ if (!entity || entity !== null && entity !== void 0 && entity.__experimentalNoFetch) {
183
+ return;
189
184
  }
190
185
 
191
- const path = (0, _url.addQueryArgs)(entity.baseURL, { ...entity.baseURLParams,
192
- ...query
186
+ const lock = await dispatch.__unstableAcquireStoreLock(_name.STORE_NAME, ['entities', 'data', kind, name], {
187
+ exclusive: false
193
188
  });
194
- let records = Object.values(await (0, _apiFetch.default)({
195
- path
196
- })); // If we request fields but the result doesn't contain the fields,
197
- // explicitely set these fields as "undefined"
198
- // that way we consider the query "fullfilled".
199
-
200
- if (query._fields) {
201
- records = records.map(record => {
202
- query._fields.split(',').forEach(field => {
203
- if (!record.hasOwnProperty(field)) {
204
- record[field] = undefined;
205
- }
206
- });
207
189
 
208
- return record;
209
- });
210
- }
190
+ try {
191
+ var _query;
211
192
 
212
- dispatch.receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to
213
- // resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
214
- // See https://github.com/WordPress/gutenberg/pull/26575
215
-
216
- if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) {
217
- const key = entity.key || _entities.DEFAULT_ENTITY_KEY;
218
- const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
219
- dispatch({
220
- type: 'START_RESOLUTIONS',
221
- selectorName: 'getEntityRecord',
222
- args: resolutionsArgs
223
- });
224
- dispatch({
225
- type: 'FINISH_RESOLUTIONS',
226
- selectorName: 'getEntityRecord',
227
- args: resolutionsArgs
193
+ if (query._fields) {
194
+ // If requesting specific fields, items and query association to said
195
+ // records are stored by ID reference. Thus, fields must always include
196
+ // the ID.
197
+ query = { ...query,
198
+ _fields: (0, _lodash.uniq)([...((0, _utils.getNormalizedCommaSeparable)(query._fields) || []), entity.key || _entities.DEFAULT_ENTITY_KEY]).join()
199
+ };
200
+ }
201
+
202
+ const path = (0, _url.addQueryArgs)(entity.baseURL, { ...entity.baseURLParams,
203
+ ...query
228
204
  });
205
+ let records = Object.values(await (0, _apiFetch.default)({
206
+ path
207
+ })); // If we request fields but the result doesn't contain the fields,
208
+ // explicitely set these fields as "undefined"
209
+ // that way we consider the query "fullfilled".
210
+
211
+ if (query._fields) {
212
+ records = records.map(record => {
213
+ query._fields.split(',').forEach(field => {
214
+ if (!record.hasOwnProperty(field)) {
215
+ record[field] = undefined;
216
+ }
217
+ });
218
+
219
+ return record;
220
+ });
221
+ }
222
+
223
+ dispatch.receiveEntityRecords(kind, name, records, query); // When requesting all fields, the list of results can be used to
224
+ // resolve the `getEntityRecord` selector in addition to `getEntityRecords`.
225
+ // See https://github.com/WordPress/gutenberg/pull/26575
226
+
227
+ if (!((_query = query) !== null && _query !== void 0 && _query._fields) && !query.context) {
228
+ const key = entity.key || _entities.DEFAULT_ENTITY_KEY;
229
+ const resolutionsArgs = records.filter(record => record[key]).map(record => [kind, name, record[key]]);
230
+ dispatch({
231
+ type: 'START_RESOLUTIONS',
232
+ selectorName: 'getEntityRecord',
233
+ args: resolutionsArgs
234
+ });
235
+ dispatch({
236
+ type: 'FINISH_RESOLUTIONS',
237
+ selectorName: 'getEntityRecord',
238
+ args: resolutionsArgs
239
+ });
240
+ }
241
+ } catch (error) {// We need a way to handle and access REST API errors in state
242
+ // Until then, catching the error ensures the resolver is marked as resolved.
243
+ // See similar implementation in `getEntityRecord()`.
244
+ } finally {
245
+ dispatch.__unstableReleaseStoreLock(lock);
229
246
  }
230
- } finally {
231
- dispatch.__unstableReleaseStoreLock(lock);
232
- }
247
+ };
233
248
  };
234
249
 
235
250
  exports.getEntityRecords = getEntityRecords;
@@ -242,10 +257,11 @@ getEntityRecords.shouldInvalidate = (action, kind, name) => {
242
257
  */
243
258
 
244
259
 
245
- const getCurrentTheme = () => async ({
246
- dispatch,
247
- resolveSelect
248
- }) => {
260
+ const getCurrentTheme = () => async _ref5 => {
261
+ let {
262
+ dispatch,
263
+ resolveSelect
264
+ } = _ref5;
249
265
  const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
250
266
  status: 'active'
251
267
  });
@@ -266,9 +282,11 @@ const getThemeSupports = (0, _utils.forwardResolver)('getCurrentTheme');
266
282
 
267
283
  exports.getThemeSupports = getThemeSupports;
268
284
 
269
- const getEmbedPreview = url => async ({
270
- dispatch
271
- }) => {
285
+ const getEmbedPreview = url => async _ref6 => {
286
+ let {
287
+ dispatch
288
+ } = _ref6;
289
+
272
290
  try {
273
291
  const embedProxyResponse = await (0, _apiFetch.default)({
274
292
  path: (0, _url.addQueryArgs)('/oembed/1.0/proxy', {
@@ -294,9 +312,10 @@ const getEmbedPreview = url => async ({
294
312
 
295
313
  exports.getEmbedPreview = getEmbedPreview;
296
314
 
297
- const canUser = (action, resource, id) => async ({
298
- dispatch
299
- }) => {
315
+ const canUser = (action, resource, id) => async _ref7 => {
316
+ let {
317
+ dispatch
318
+ } = _ref7;
300
319
  const methods = {
301
320
  create: 'POST',
302
321
  read: 'GET',
@@ -356,9 +375,10 @@ const canUser = (action, resource, id) => async ({
356
375
 
357
376
  exports.canUser = canUser;
358
377
 
359
- const canUserEditEntityRecord = (kind, name, recordId) => async ({
360
- dispatch
361
- }) => {
378
+ const canUserEditEntityRecord = (kind, name, recordId) => async _ref8 => {
379
+ let {
380
+ dispatch
381
+ } = _ref8;
362
382
  const entities = await dispatch((0, _entities.getKindEntities)(kind));
363
383
  const entity = (0, _lodash.find)(entities, {
364
384
  kind,
@@ -382,10 +402,11 @@ const canUserEditEntityRecord = (kind, name, recordId) => async ({
382
402
 
383
403
  exports.canUserEditEntityRecord = canUserEditEntityRecord;
384
404
 
385
- const getAutosaves = (postType, postId) => async ({
386
- dispatch,
387
- resolveSelect
388
- }) => {
405
+ const getAutosaves = (postType, postId) => async _ref9 => {
406
+ let {
407
+ dispatch,
408
+ resolveSelect
409
+ } = _ref9;
389
410
  const {
390
411
  rest_base: restBase
391
412
  } = await resolveSelect.getPostType(postType);
@@ -410,9 +431,10 @@ const getAutosaves = (postType, postId) => async ({
410
431
 
411
432
  exports.getAutosaves = getAutosaves;
412
433
 
413
- const getAutosave = (postType, postId) => async ({
414
- resolveSelect
415
- }) => {
434
+ const getAutosave = (postType, postId) => async _ref10 => {
435
+ let {
436
+ resolveSelect
437
+ } = _ref10;
416
438
  await resolveSelect.getAutosaves(postType, postId);
417
439
  };
418
440
  /**
@@ -424,10 +446,11 @@ const getAutosave = (postType, postId) => async ({
424
446
 
425
447
  exports.getAutosave = getAutosave;
426
448
 
427
- const __experimentalGetTemplateForLink = link => async ({
428
- dispatch,
429
- resolveSelect
430
- }) => {
449
+ const __experimentalGetTemplateForLink = link => async _ref11 => {
450
+ let {
451
+ dispatch,
452
+ resolveSelect
453
+ } = _ref11;
431
454
  // Ideally this should be using an apiFetch call
432
455
  // We could potentially do so by adding a "filter" to the `wp_template` end point.
433
456
  // Also it seems the returned object is not a regular REST API post type.
@@ -436,9 +459,12 @@ const __experimentalGetTemplateForLink = link => async ({
436
459
  try {
437
460
  template = await window.fetch((0, _url.addQueryArgs)(link, {
438
461
  '_wp-find-template': true
439
- })).then(res => res.json()).then(({
440
- data
441
- }) => data);
462
+ })).then(res => res.json()).then(_ref12 => {
463
+ let {
464
+ data
465
+ } = _ref12;
466
+ return data;
467
+ });
442
468
  } catch (e) {// For non-FSE themes, it is possible that this request returns an error.
443
469
  }
444
470
 
@@ -461,10 +487,11 @@ __experimentalGetTemplateForLink.shouldInvalidate = action => {
461
487
  return (action.type === 'RECEIVE_ITEMS' || action.type === 'REMOVE_ITEMS') && action.invalidateCache && action.kind === 'postType' && action.name === 'wp_template';
462
488
  };
463
489
 
464
- const __experimentalGetCurrentGlobalStylesId = () => async ({
465
- dispatch,
466
- resolveSelect
467
- }) => {
490
+ const __experimentalGetCurrentGlobalStylesId = () => async _ref13 => {
491
+ let {
492
+ dispatch,
493
+ resolveSelect
494
+ } = _ref13;
468
495
  const activeThemes = await resolveSelect.getEntityRecords('root', 'theme', {
469
496
  status: 'active'
470
497
  });
@@ -481,10 +508,11 @@ const __experimentalGetCurrentGlobalStylesId = () => async ({
481
508
 
482
509
  exports.__experimentalGetCurrentGlobalStylesId = __experimentalGetCurrentGlobalStylesId;
483
510
 
484
- const __experimentalGetCurrentThemeBaseGlobalStyles = () => async ({
485
- resolveSelect,
486
- dispatch
487
- }) => {
511
+ const __experimentalGetCurrentThemeBaseGlobalStyles = () => async _ref14 => {
512
+ let {
513
+ resolveSelect,
514
+ dispatch
515
+ } = _ref14;
488
516
  const currentTheme = await resolveSelect.getCurrentTheme();
489
517
  const themeGlobalStyles = await (0, _apiFetch.default)({
490
518
  path: `/wp/v2/global-styles/themes/${currentTheme.stylesheet}`
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","entities","entity","__experimentalNoFetch","lock","__unstableAcquireStoreLock","STORE_NAME","exclusive","undefined","_fields","DEFAULT_ENTITY_KEY","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","get","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":";;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AAhBA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,UAAU,GAAKC,KAAF,IAAa,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AACzC,IAAP,KAAgB,aAJjB;AAMA,CAPD;;AASO,MAAM6F,sCAAsC,GAAG,MAAM,OAAQ;AACnEtG,EAAAA,QADmE;AAEnEqD,EAAAA;AAFmE,CAAR,KAGrD;AACN,QAAMC,YAAY,GAAG,MAAMD,aAAa,CAACnB,gBAAd,CAC1B,MAD0B,EAE1B,OAF0B,EAG1B;AAAEqB,IAAAA,MAAM,EAAE;AAAV,GAH0B,CAA3B;AAKA,QAAMgD,eAAe,GAAG,iBAAKjD,YAAL,EAAmB,CAC1C,CAD0C,EAE1C,QAF0C,EAG1C,uBAH0C,EAI1C,CAJ0C,EAK1C,MAL0C,CAAnB,CAAxB;;AAOA,MAAKiD,eAAL,EAAuB;AACtB,UAAMC,kBAAkB,GAAG,MAAM,uBAAU;AAC1C7C,MAAAA,GAAG,EAAE4C;AADqC,KAAV,CAAjC;;AAGAvG,IAAAA,QAAQ,CAACyG,0CAAT,CACCD,kBAAkB,CAACxC,EADpB;AAGA;AACD,CAxBM;;;;AA0BA,MAAM0C,6CAA6C,GAAG,MAAM,OAAQ;AAC1ErD,EAAAA,aAD0E;AAE1ErD,EAAAA;AAF0E,CAAR,KAG5D;AACN,QAAM2G,YAAY,GAAG,MAAMtD,aAAa,CAACD,eAAd,EAA3B;AACA,QAAMwD,iBAAiB,GAAG,MAAM,uBAAU;AACzC3G,IAAAA,IAAI,EAAG,+BAA+B0G,YAAY,CAACE,UAAY;AADtB,GAAV,CAAhC;AAGA,QAAM7G,QAAQ,CAAC8G,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} 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} 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"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/resolvers.js"],"names":["getAuthors","query","dispatch","path","users","receiveUserQuery","getCurrentUser","currentUser","receiveCurrentUser","getEntityRecord","kind","name","key","select","entities","entity","__experimentalNoFetch","lock","__unstableAcquireStoreLock","STORE_NAME","exclusive","undefined","_fields","DEFAULT_ENTITY_KEY","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","get","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":";;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AACA;;AACA;;AAhBA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAKA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,UAAU,GAAKC,KAAF,IAAa,cAA0B;AAAA,MAAlB;AAAEC,IAAAA;AAAF,GAAkB;AAChE,QAAMC,IAAI,GAAG,uBACZ,wCADY,EAEZF,KAFY,CAAb;AAIA,QAAMG,KAAK,GAAG,MAAM,uBAAU;AAAED,IAAAA;AAAF,GAAV,CAApB;AACAD,EAAAA,QAAQ,CAACG,gBAAT,CAA2BF,IAA3B,EAAiCC,KAAjC;AACA,CAPM;AASP;AACA;AACA;;;;;AACO,MAAME,cAAc,GAAG,MAAM,eAA0B;AAAA,MAAlB;AAAEJ,IAAAA;AAAF,GAAkB;AAC7D,QAAMK,WAAW,GAAG,MAAM,uBAAU;AAAEJ,IAAAA,IAAI,EAAE;AAAR,GAAV,CAA1B;AACAD,EAAAA,QAAQ,CAACM,kBAAT,CAA6BD,WAA7B;AACA,CAHM;AAKP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAME,eAAe,GAAG,UAAEC,IAAF,EAAQC,IAAR;AAAA,MAAcC,GAAd,uEAAoB,EAApB;AAAA,MAAwBX,KAAxB;AAAA,SAAmC,eAG3D;AAAA,QAHmE;AACzEY,MAAAA,MADyE;AAEzEX,MAAAA;AAFyE,KAGnE;AACN,UAAMY,QAAQ,GAAG,MAAMZ,QAAQ,CAAE,+BAAiBQ,IAAjB,CAAF,CAA/B;AACA,UAAMK,MAAM,GAAG,kBAAMD,QAAN,EAAgB;AAAE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;;AA0BA,MAAM0C,6CAA6C,GAAG,MAAM,gBAG5D;AAAA,MAHoE;AAC1ErD,IAAAA,aAD0E;AAE1ErD,IAAAA;AAF0E,GAGpE;AACN,QAAM2G,YAAY,GAAG,MAAMtD,aAAa,CAACD,eAAd,EAA3B;AACA,QAAMwD,iBAAiB,GAAG,MAAM,uBAAU;AACzC3G,IAAAA,IAAI,EAAG,+BAA+B0G,YAAY,CAACE,UAAY;AADtB,GAAV,CAAhC;AAGA,QAAM7G,QAAQ,CAAC8G,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"]}