@wordpress/core-data 6.3.3 → 6.5.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.
- package/CHANGELOG.md +4 -0
- package/README.md +1 -1
- package/build/actions.js +6 -6
- package/build/actions.js.map +1 -1
- package/build/entities.js +7 -7
- package/build/entities.js.map +1 -1
- package/build/hooks/use-entity-record.js +4 -4
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +4 -4
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-resource-permissions.js +2 -2
- package/build/hooks/use-resource-permissions.js.map +1 -1
- package/build/queried-data/selectors.js +4 -1
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +3 -1
- package/build/reducer.js.map +1 -1
- package/build/selectors.js +158 -135
- package/build/selectors.js.map +1 -1
- package/build-module/actions.js +6 -6
- package/build-module/actions.js.map +1 -1
- package/build-module/entities.js +7 -6
- package/build-module/entities.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +4 -4
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +4 -4
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-resource-permissions.js +2 -2
- package/build-module/hooks/use-resource-permissions.js.map +1 -1
- package/build-module/queried-data/selectors.js +5 -2
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +4 -2
- package/build-module/reducer.js.map +1 -1
- package/build-module/selectors.js +159 -136
- package/build-module/selectors.js.map +1 -1
- package/build-types/actions.d.ts +1 -1
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/hooks/use-entity-record.d.ts +4 -4
- package/build-types/hooks/use-entity-records.d.ts +4 -4
- package/build-types/hooks/use-resource-permissions.d.ts +2 -2
- package/build-types/index.d.ts +1 -1
- package/build-types/queried-data/selectors.d.ts.map +1 -1
- package/build-types/reducer.d.ts.map +1 -1
- package/build-types/selectors.d.ts +130 -117
- package/build-types/selectors.d.ts.map +1 -1
- package/package.json +12 -12
- package/src/actions.js +6 -6
- package/src/entities.js +1 -2
- package/src/hooks/use-entity-record.ts +4 -4
- package/src/hooks/use-entity-records.ts +4 -4
- package/src/hooks/use-resource-permissions.ts +2 -2
- package/src/queried-data/selectors.js +5 -2
- package/src/reducer.js +2 -6
- package/src/selectors.ts +174 -218
- package/tsconfig.tsbuildinfo +1 -1
package/build/selectors.js
CHANGED
|
@@ -90,8 +90,8 @@ const EMPTY_OBJECT = {};
|
|
|
90
90
|
* Returns true if a request is in progress for embed preview data, or false
|
|
91
91
|
* otherwise.
|
|
92
92
|
*
|
|
93
|
-
* @param
|
|
94
|
-
* @param
|
|
93
|
+
* @param state Data state.
|
|
94
|
+
* @param url URL the preview would be for.
|
|
95
95
|
*
|
|
96
96
|
* @return Whether a request is in progress for an embed preview.
|
|
97
97
|
*/
|
|
@@ -104,9 +104,9 @@ const isRequestingEmbedPreview = (0, _data.createRegistrySelector)(select => (st
|
|
|
104
104
|
*
|
|
105
105
|
* @deprecated since 11.3. Callers should use `select( 'core' ).getUsers({ who: 'authors' })` instead.
|
|
106
106
|
*
|
|
107
|
-
* @param
|
|
108
|
-
* @param
|
|
109
|
-
*
|
|
107
|
+
* @param state Data state.
|
|
108
|
+
* @param query Optional object of query parameters to
|
|
109
|
+
* include with request.
|
|
110
110
|
* @return Authors list.
|
|
111
111
|
*/
|
|
112
112
|
|
|
@@ -123,7 +123,7 @@ function getAuthors(state, query) {
|
|
|
123
123
|
/**
|
|
124
124
|
* Returns the current user.
|
|
125
125
|
*
|
|
126
|
-
* @param
|
|
126
|
+
* @param state Data state.
|
|
127
127
|
*
|
|
128
128
|
* @return Current user object.
|
|
129
129
|
*/
|
|
@@ -135,8 +135,8 @@ function getCurrentUser(state) {
|
|
|
135
135
|
/**
|
|
136
136
|
* Returns all the users returned by a query ID.
|
|
137
137
|
*
|
|
138
|
-
* @param
|
|
139
|
-
* @param
|
|
138
|
+
* @param state Data state.
|
|
139
|
+
* @param queryID Query ID.
|
|
140
140
|
*
|
|
141
141
|
* @return Users list.
|
|
142
142
|
*/
|
|
@@ -152,8 +152,8 @@ const getUserQueryResults = (0, _rememo.default)((state, queryID) => {
|
|
|
152
152
|
* Returns the loaded entities for the given kind.
|
|
153
153
|
*
|
|
154
154
|
* @deprecated since WordPress 6.0. Use getEntitiesConfig instead
|
|
155
|
-
* @param
|
|
156
|
-
* @param
|
|
155
|
+
* @param state Data state.
|
|
156
|
+
* @param kind Entity kind.
|
|
157
157
|
*
|
|
158
158
|
* @return Array of entities with config matching kind.
|
|
159
159
|
*/
|
|
@@ -170,8 +170,8 @@ function getEntitiesByKind(state, kind) {
|
|
|
170
170
|
/**
|
|
171
171
|
* Returns the loaded entities for the given kind.
|
|
172
172
|
*
|
|
173
|
-
* @param
|
|
174
|
-
* @param
|
|
173
|
+
* @param state Data state.
|
|
174
|
+
* @param kind Entity kind.
|
|
175
175
|
*
|
|
176
176
|
* @return Array of entities with config matching kind.
|
|
177
177
|
*/
|
|
@@ -184,9 +184,9 @@ function getEntitiesConfig(state, kind) {
|
|
|
184
184
|
* Returns the entity config given its kind and name.
|
|
185
185
|
*
|
|
186
186
|
* @deprecated since WordPress 6.0. Use getEntityConfig instead
|
|
187
|
-
* @param
|
|
188
|
-
* @param
|
|
189
|
-
* @param
|
|
187
|
+
* @param state Data state.
|
|
188
|
+
* @param kind Entity kind.
|
|
189
|
+
* @param name Entity name.
|
|
190
190
|
*
|
|
191
191
|
* @return Entity config
|
|
192
192
|
*/
|
|
@@ -202,9 +202,9 @@ function getEntity(state, kind, name) {
|
|
|
202
202
|
/**
|
|
203
203
|
* Returns the entity config given its kind and name.
|
|
204
204
|
*
|
|
205
|
-
* @param
|
|
206
|
-
* @param
|
|
207
|
-
* @param
|
|
205
|
+
* @param state Data state.
|
|
206
|
+
* @param kind Entity kind.
|
|
207
|
+
* @param name Entity name.
|
|
208
208
|
*
|
|
209
209
|
* @return Entity config
|
|
210
210
|
*/
|
|
@@ -246,19 +246,19 @@ function getEntityConfig(state, kind, name) {
|
|
|
246
246
|
* yet received, undefined if the value entity is known to not exist, or the
|
|
247
247
|
* entity object if it exists and is received.
|
|
248
248
|
*
|
|
249
|
-
* @param
|
|
250
|
-
* @param
|
|
251
|
-
* @param
|
|
252
|
-
* @param
|
|
253
|
-
* @param
|
|
254
|
-
*
|
|
249
|
+
* @param state State tree
|
|
250
|
+
* @param kind Entity kind.
|
|
251
|
+
* @param name Entity name.
|
|
252
|
+
* @param key Record's key
|
|
253
|
+
* @param query Optional query. If requesting specific
|
|
254
|
+
* fields, fields must always include the ID.
|
|
255
255
|
*
|
|
256
256
|
* @return Record.
|
|
257
257
|
*/
|
|
258
258
|
const getEntityRecord = (0, _rememo.default)((state, kind, name, key, query) => {
|
|
259
|
-
var _query$context, _queriedState$items$c;
|
|
259
|
+
var _state$entities$recor, _state$entities$recor2, _state$entities$recor3, _query$context, _queriedState$items$c;
|
|
260
260
|
|
|
261
|
-
const queriedState = (
|
|
261
|
+
const queriedState = (_state$entities$recor = state.entities.records) === null || _state$entities$recor === void 0 ? void 0 : (_state$entities$recor2 = _state$entities$recor[kind]) === null || _state$entities$recor2 === void 0 ? void 0 : (_state$entities$recor3 = _state$entities$recor2[name]) === null || _state$entities$recor3 === void 0 ? void 0 : _state$entities$recor3.queriedData;
|
|
262
262
|
|
|
263
263
|
if (!queriedState) {
|
|
264
264
|
return undefined;
|
|
@@ -287,7 +287,10 @@ const getEntityRecord = (0, _rememo.default)((state, kind, name, key, query) =>
|
|
|
287
287
|
|
|
288
288
|
for (let f = 0; f < fields.length; f++) {
|
|
289
289
|
const field = fields[f].split('.');
|
|
290
|
-
|
|
290
|
+
let value = item;
|
|
291
|
+
field.forEach(fieldName => {
|
|
292
|
+
value = value[fieldName];
|
|
293
|
+
});
|
|
291
294
|
(0, _lodash.set)(filteredItem, field, value);
|
|
292
295
|
}
|
|
293
296
|
|
|
@@ -296,18 +299,18 @@ const getEntityRecord = (0, _rememo.default)((state, kind, name, key, query) =>
|
|
|
296
299
|
|
|
297
300
|
return item;
|
|
298
301
|
}, (state, kind, name, recordId, query) => {
|
|
299
|
-
var _query$context2;
|
|
302
|
+
var _query$context2, _state$entities$recor4, _state$entities$recor5, _state$entities$recor6, _state$entities$recor7, _state$entities$recor8, _state$entities$recor9, _state$entities$recor10, _state$entities$recor11, _state$entities$recor12, _state$entities$recor13;
|
|
300
303
|
|
|
301
304
|
const context = (_query$context2 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context2 !== void 0 ? _query$context2 : 'default';
|
|
302
|
-
return [(
|
|
305
|
+
return [(_state$entities$recor4 = state.entities.records) === null || _state$entities$recor4 === void 0 ? void 0 : (_state$entities$recor5 = _state$entities$recor4[kind]) === null || _state$entities$recor5 === void 0 ? void 0 : (_state$entities$recor6 = _state$entities$recor5[name]) === null || _state$entities$recor6 === void 0 ? void 0 : (_state$entities$recor7 = _state$entities$recor6.queriedData) === null || _state$entities$recor7 === void 0 ? void 0 : (_state$entities$recor8 = _state$entities$recor7.items[context]) === null || _state$entities$recor8 === void 0 ? void 0 : _state$entities$recor8[recordId], (_state$entities$recor9 = state.entities.records) === null || _state$entities$recor9 === void 0 ? void 0 : (_state$entities$recor10 = _state$entities$recor9[kind]) === null || _state$entities$recor10 === void 0 ? void 0 : (_state$entities$recor11 = _state$entities$recor10[name]) === null || _state$entities$recor11 === void 0 ? void 0 : (_state$entities$recor12 = _state$entities$recor11.queriedData) === null || _state$entities$recor12 === void 0 ? void 0 : (_state$entities$recor13 = _state$entities$recor12.itemIsComplete[context]) === null || _state$entities$recor13 === void 0 ? void 0 : _state$entities$recor13[recordId]];
|
|
303
306
|
});
|
|
304
307
|
/**
|
|
305
308
|
* Returns the Entity's record object by key. Doesn't trigger a resolver nor requests the entity records from the API if the entity record isn't available in the local state.
|
|
306
309
|
*
|
|
307
|
-
* @param
|
|
308
|
-
* @param
|
|
309
|
-
* @param
|
|
310
|
-
* @param
|
|
310
|
+
* @param state State tree
|
|
311
|
+
* @param kind Entity kind.
|
|
312
|
+
* @param name Entity name.
|
|
313
|
+
* @param key Record's key
|
|
311
314
|
*
|
|
312
315
|
* @return Record.
|
|
313
316
|
*/
|
|
@@ -321,10 +324,10 @@ function __experimentalGetEntityRecordNoResolver(state, kind, name, key) {
|
|
|
321
324
|
* Returns the entity's record object by key,
|
|
322
325
|
* with its attributes mapped to their raw values.
|
|
323
326
|
*
|
|
324
|
-
* @param
|
|
325
|
-
* @param
|
|
326
|
-
* @param
|
|
327
|
-
* @param
|
|
327
|
+
* @param state State tree.
|
|
328
|
+
* @param kind Entity kind.
|
|
329
|
+
* @param name Entity name.
|
|
330
|
+
* @param key Record's key.
|
|
328
331
|
*
|
|
329
332
|
* @return Object with the entity's raw attributes.
|
|
330
333
|
*/
|
|
@@ -334,10 +337,12 @@ const getRawEntityRecord = (0, _rememo.default)((state, kind, name, key) => {
|
|
|
334
337
|
const record = getEntityRecord(state, kind, name, key);
|
|
335
338
|
return record && Object.keys(record).reduce((accumulator, _key) => {
|
|
336
339
|
if ((0, _utils.isRawAttribute)(getEntityConfig(state, kind, name), _key)) {
|
|
340
|
+
var _record$_key$raw, _record$_key;
|
|
341
|
+
|
|
337
342
|
// Because edits are the "raw" attribute values,
|
|
338
343
|
// we return those from record selectors to make rendering,
|
|
339
344
|
// comparisons, and joins with edits easier.
|
|
340
|
-
accumulator[_key] = (
|
|
345
|
+
accumulator[_key] = (_record$_key$raw = (_record$_key = record[_key]) === null || _record$_key === void 0 ? void 0 : _record$_key.raw) !== null && _record$_key$raw !== void 0 ? _record$_key$raw : record[_key];
|
|
341
346
|
} else {
|
|
342
347
|
accumulator[_key] = record[_key];
|
|
343
348
|
}
|
|
@@ -345,19 +350,19 @@ const getRawEntityRecord = (0, _rememo.default)((state, kind, name, key) => {
|
|
|
345
350
|
return accumulator;
|
|
346
351
|
}, {});
|
|
347
352
|
}, (state, kind, name, recordId, query) => {
|
|
348
|
-
var _query$context3;
|
|
353
|
+
var _query$context3, _state$entities$recor14, _state$entities$recor15, _state$entities$recor16, _state$entities$recor17, _state$entities$recor18, _state$entities$recor19, _state$entities$recor20, _state$entities$recor21, _state$entities$recor22, _state$entities$recor23;
|
|
349
354
|
|
|
350
355
|
const context = (_query$context3 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context3 !== void 0 ? _query$context3 : 'default';
|
|
351
|
-
return [state.entities.config, (
|
|
356
|
+
return [state.entities.config, (_state$entities$recor14 = state.entities.records) === null || _state$entities$recor14 === void 0 ? void 0 : (_state$entities$recor15 = _state$entities$recor14[kind]) === null || _state$entities$recor15 === void 0 ? void 0 : (_state$entities$recor16 = _state$entities$recor15[name]) === null || _state$entities$recor16 === void 0 ? void 0 : (_state$entities$recor17 = _state$entities$recor16.queriedData) === null || _state$entities$recor17 === void 0 ? void 0 : (_state$entities$recor18 = _state$entities$recor17.items[context]) === null || _state$entities$recor18 === void 0 ? void 0 : _state$entities$recor18[recordId], (_state$entities$recor19 = state.entities.records) === null || _state$entities$recor19 === void 0 ? void 0 : (_state$entities$recor20 = _state$entities$recor19[kind]) === null || _state$entities$recor20 === void 0 ? void 0 : (_state$entities$recor21 = _state$entities$recor20[name]) === null || _state$entities$recor21 === void 0 ? void 0 : (_state$entities$recor22 = _state$entities$recor21.queriedData) === null || _state$entities$recor22 === void 0 ? void 0 : (_state$entities$recor23 = _state$entities$recor22.itemIsComplete[context]) === null || _state$entities$recor23 === void 0 ? void 0 : _state$entities$recor23[recordId]];
|
|
352
357
|
});
|
|
353
358
|
/**
|
|
354
359
|
* Returns true if records have been received for the given set of parameters,
|
|
355
360
|
* or false otherwise.
|
|
356
361
|
*
|
|
357
|
-
* @param
|
|
358
|
-
* @param
|
|
359
|
-
* @param
|
|
360
|
-
* @param
|
|
362
|
+
* @param state State tree
|
|
363
|
+
* @param kind Entity kind.
|
|
364
|
+
* @param name Entity name.
|
|
365
|
+
* @param query Optional terms query.
|
|
361
366
|
*
|
|
362
367
|
* @return Whether entity records have been received.
|
|
363
368
|
*/
|
|
@@ -380,18 +385,20 @@ function hasEntityRecords(state, kind, name, query) {
|
|
|
380
385
|
/**
|
|
381
386
|
* Returns the Entity's records.
|
|
382
387
|
*
|
|
383
|
-
* @param
|
|
384
|
-
* @param
|
|
385
|
-
* @param
|
|
386
|
-
* @param
|
|
387
|
-
*
|
|
388
|
+
* @param state State tree
|
|
389
|
+
* @param kind Entity kind.
|
|
390
|
+
* @param name Entity name.
|
|
391
|
+
* @param query Optional terms query. If requesting specific
|
|
392
|
+
* fields, fields must always include the ID.
|
|
388
393
|
*
|
|
389
394
|
* @return Records.
|
|
390
395
|
*/
|
|
391
396
|
const getEntityRecords = (state, kind, name, query) => {
|
|
397
|
+
var _state$entities$recor24, _state$entities$recor25, _state$entities$recor26;
|
|
398
|
+
|
|
392
399
|
// Queried data state is prepopulated for all known entities. If this is not
|
|
393
400
|
// assigned for the given parameters, then it is known to not exist.
|
|
394
|
-
const queriedState = (
|
|
401
|
+
const queriedState = (_state$entities$recor24 = state.entities.records) === null || _state$entities$recor24 === void 0 ? void 0 : (_state$entities$recor25 = _state$entities$recor24[kind]) === null || _state$entities$recor25 === void 0 ? void 0 : (_state$entities$recor26 = _state$entities$recor25[name]) === null || _state$entities$recor26 === void 0 ? void 0 : _state$entities$recor26.queriedData;
|
|
395
402
|
|
|
396
403
|
if (!queriedState) {
|
|
397
404
|
return null;
|
|
@@ -405,7 +412,7 @@ exports.getEntityRecords = getEntityRecords;
|
|
|
405
412
|
/**
|
|
406
413
|
* Returns the list of dirty entity records.
|
|
407
414
|
*
|
|
408
|
-
* @param
|
|
415
|
+
* @param state State tree.
|
|
409
416
|
*
|
|
410
417
|
* @return The list of updated records
|
|
411
418
|
*/
|
|
@@ -445,7 +452,7 @@ const __experimentalGetDirtyEntityRecords = (0, _rememo.default)(state => {
|
|
|
445
452
|
/**
|
|
446
453
|
* Returns the list of entities currently being saved.
|
|
447
454
|
*
|
|
448
|
-
* @param
|
|
455
|
+
* @param state State tree.
|
|
449
456
|
*
|
|
450
457
|
* @return The list of records being saved.
|
|
451
458
|
*/
|
|
@@ -487,10 +494,10 @@ const __experimentalGetEntitiesBeingSaved = (0, _rememo.default)(state => {
|
|
|
487
494
|
/**
|
|
488
495
|
* Returns the specified entity record's edits.
|
|
489
496
|
*
|
|
490
|
-
* @param
|
|
491
|
-
* @param
|
|
492
|
-
* @param
|
|
493
|
-
* @param
|
|
497
|
+
* @param state State tree.
|
|
498
|
+
* @param kind Entity kind.
|
|
499
|
+
* @param name Entity name.
|
|
500
|
+
* @param recordId Record ID.
|
|
494
501
|
*
|
|
495
502
|
* @return The entity record's edits.
|
|
496
503
|
*/
|
|
@@ -499,7 +506,9 @@ const __experimentalGetEntitiesBeingSaved = (0, _rememo.default)(state => {
|
|
|
499
506
|
exports.__experimentalGetEntitiesBeingSaved = __experimentalGetEntitiesBeingSaved;
|
|
500
507
|
|
|
501
508
|
function getEntityRecordEdits(state, kind, name, recordId) {
|
|
502
|
-
|
|
509
|
+
var _state$entities$recor27, _state$entities$recor28, _state$entities$recor29, _state$entities$recor30;
|
|
510
|
+
|
|
511
|
+
return (_state$entities$recor27 = state.entities.records) === null || _state$entities$recor27 === void 0 ? void 0 : (_state$entities$recor28 = _state$entities$recor27[kind]) === null || _state$entities$recor28 === void 0 ? void 0 : (_state$entities$recor29 = _state$entities$recor28[name]) === null || _state$entities$recor29 === void 0 ? void 0 : (_state$entities$recor30 = _state$entities$recor29.edits) === null || _state$entities$recor30 === void 0 ? void 0 : _state$entities$recor30[recordId];
|
|
503
512
|
}
|
|
504
513
|
/**
|
|
505
514
|
* Returns the specified entity record's non transient edits.
|
|
@@ -508,10 +517,10 @@ function getEntityRecordEdits(state, kind, name, recordId) {
|
|
|
508
517
|
* are not considered for change detection.
|
|
509
518
|
* They are defined in the entity's config.
|
|
510
519
|
*
|
|
511
|
-
* @param
|
|
512
|
-
* @param
|
|
513
|
-
* @param
|
|
514
|
-
* @param
|
|
520
|
+
* @param state State tree.
|
|
521
|
+
* @param kind Entity kind.
|
|
522
|
+
* @param name Entity name.
|
|
523
|
+
* @param recordId Record ID.
|
|
515
524
|
*
|
|
516
525
|
* @return The entity record's non transient edits.
|
|
517
526
|
*/
|
|
@@ -534,15 +543,19 @@ const getEntityRecordNonTransientEdits = (0, _rememo.default)((state, kind, name
|
|
|
534
543
|
|
|
535
544
|
return acc;
|
|
536
545
|
}, {});
|
|
537
|
-
}, (state, kind, name, recordId) =>
|
|
546
|
+
}, (state, kind, name, recordId) => {
|
|
547
|
+
var _state$entities$recor31, _state$entities$recor32, _state$entities$recor33, _state$entities$recor34;
|
|
548
|
+
|
|
549
|
+
return [state.entities.config, (_state$entities$recor31 = state.entities.records) === null || _state$entities$recor31 === void 0 ? void 0 : (_state$entities$recor32 = _state$entities$recor31[kind]) === null || _state$entities$recor32 === void 0 ? void 0 : (_state$entities$recor33 = _state$entities$recor32[name]) === null || _state$entities$recor33 === void 0 ? void 0 : (_state$entities$recor34 = _state$entities$recor33.edits) === null || _state$entities$recor34 === void 0 ? void 0 : _state$entities$recor34[recordId]];
|
|
550
|
+
});
|
|
538
551
|
/**
|
|
539
552
|
* Returns true if the specified entity record has edits,
|
|
540
553
|
* and false otherwise.
|
|
541
554
|
*
|
|
542
|
-
* @param
|
|
543
|
-
* @param
|
|
544
|
-
* @param
|
|
545
|
-
* @param
|
|
555
|
+
* @param state State tree.
|
|
556
|
+
* @param kind Entity kind.
|
|
557
|
+
* @param name Entity name.
|
|
558
|
+
* @param recordId Record ID.
|
|
546
559
|
*
|
|
547
560
|
* @return Whether the entity record has edits or not.
|
|
548
561
|
*/
|
|
@@ -555,10 +568,10 @@ function hasEditsForEntityRecord(state, kind, name, recordId) {
|
|
|
555
568
|
/**
|
|
556
569
|
* Returns the specified entity record, merged with its edits.
|
|
557
570
|
*
|
|
558
|
-
* @param
|
|
559
|
-
* @param
|
|
560
|
-
* @param
|
|
561
|
-
* @param
|
|
571
|
+
* @param state State tree.
|
|
572
|
+
* @param kind Entity kind.
|
|
573
|
+
* @param name Entity name.
|
|
574
|
+
* @param recordId Record ID.
|
|
562
575
|
*
|
|
563
576
|
* @return The entity record, merged with its edits.
|
|
564
577
|
*/
|
|
@@ -567,18 +580,18 @@ function hasEditsForEntityRecord(state, kind, name, recordId) {
|
|
|
567
580
|
const getEditedEntityRecord = (0, _rememo.default)((state, kind, name, recordId) => ({ ...getRawEntityRecord(state, kind, name, recordId),
|
|
568
581
|
...getEntityRecordEdits(state, kind, name, recordId)
|
|
569
582
|
}), (state, kind, name, recordId, query) => {
|
|
570
|
-
var _query$context4;
|
|
583
|
+
var _query$context4, _state$entities$recor35, _state$entities$recor36, _state$entities$recor37, _state$entities$recor38, _state$entities$recor39, _state$entities$recor40, _state$entities$recor41, _state$entities$recor42, _state$entities$recor43, _state$entities$recor44, _state$entities$recor45, _state$entities$recor46;
|
|
571
584
|
|
|
572
585
|
const context = (_query$context4 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context4 !== void 0 ? _query$context4 : 'default';
|
|
573
|
-
return [state.entities.config, (
|
|
586
|
+
return [state.entities.config, (_state$entities$recor35 = state.entities.records) === null || _state$entities$recor35 === void 0 ? void 0 : (_state$entities$recor36 = _state$entities$recor35[kind]) === null || _state$entities$recor36 === void 0 ? void 0 : (_state$entities$recor37 = _state$entities$recor36[name]) === null || _state$entities$recor37 === void 0 ? void 0 : (_state$entities$recor38 = _state$entities$recor37.queriedData.items[context]) === null || _state$entities$recor38 === void 0 ? void 0 : _state$entities$recor38[recordId], (_state$entities$recor39 = state.entities.records) === null || _state$entities$recor39 === void 0 ? void 0 : (_state$entities$recor40 = _state$entities$recor39[kind]) === null || _state$entities$recor40 === void 0 ? void 0 : (_state$entities$recor41 = _state$entities$recor40[name]) === null || _state$entities$recor41 === void 0 ? void 0 : (_state$entities$recor42 = _state$entities$recor41.queriedData.itemIsComplete[context]) === null || _state$entities$recor42 === void 0 ? void 0 : _state$entities$recor42[recordId], (_state$entities$recor43 = state.entities.records) === null || _state$entities$recor43 === void 0 ? void 0 : (_state$entities$recor44 = _state$entities$recor43[kind]) === null || _state$entities$recor44 === void 0 ? void 0 : (_state$entities$recor45 = _state$entities$recor44[name]) === null || _state$entities$recor45 === void 0 ? void 0 : (_state$entities$recor46 = _state$entities$recor45.edits) === null || _state$entities$recor46 === void 0 ? void 0 : _state$entities$recor46[recordId]];
|
|
574
587
|
});
|
|
575
588
|
/**
|
|
576
589
|
* Returns true if the specified entity record is autosaving, and false otherwise.
|
|
577
590
|
*
|
|
578
|
-
* @param
|
|
579
|
-
* @param
|
|
580
|
-
* @param
|
|
581
|
-
* @param
|
|
591
|
+
* @param state State tree.
|
|
592
|
+
* @param kind Entity kind.
|
|
593
|
+
* @param name Entity name.
|
|
594
|
+
* @param recordId Record ID.
|
|
582
595
|
*
|
|
583
596
|
* @return Whether the entity record is autosaving or not.
|
|
584
597
|
*/
|
|
@@ -586,71 +599,81 @@ const getEditedEntityRecord = (0, _rememo.default)((state, kind, name, recordId)
|
|
|
586
599
|
exports.getEditedEntityRecord = getEditedEntityRecord;
|
|
587
600
|
|
|
588
601
|
function isAutosavingEntityRecord(state, kind, name, recordId) {
|
|
602
|
+
var _state$entities$recor47, _state$entities$recor48, _state$entities$recor49, _state$entities$recor50, _state$entities$recor51;
|
|
603
|
+
|
|
589
604
|
const {
|
|
590
605
|
pending,
|
|
591
606
|
isAutosave
|
|
592
|
-
} = (
|
|
607
|
+
} = (_state$entities$recor47 = (_state$entities$recor48 = state.entities.records) === null || _state$entities$recor48 === void 0 ? void 0 : (_state$entities$recor49 = _state$entities$recor48[kind]) === null || _state$entities$recor49 === void 0 ? void 0 : (_state$entities$recor50 = _state$entities$recor49[name]) === null || _state$entities$recor50 === void 0 ? void 0 : (_state$entities$recor51 = _state$entities$recor50.saving) === null || _state$entities$recor51 === void 0 ? void 0 : _state$entities$recor51[recordId]) !== null && _state$entities$recor47 !== void 0 ? _state$entities$recor47 : {};
|
|
593
608
|
return Boolean(pending && isAutosave);
|
|
594
609
|
}
|
|
595
610
|
/**
|
|
596
611
|
* Returns true if the specified entity record is saving, and false otherwise.
|
|
597
612
|
*
|
|
598
|
-
* @param
|
|
599
|
-
* @param
|
|
600
|
-
* @param
|
|
601
|
-
* @param
|
|
613
|
+
* @param state State tree.
|
|
614
|
+
* @param kind Entity kind.
|
|
615
|
+
* @param name Entity name.
|
|
616
|
+
* @param recordId Record ID.
|
|
602
617
|
*
|
|
603
618
|
* @return Whether the entity record is saving or not.
|
|
604
619
|
*/
|
|
605
620
|
|
|
606
621
|
|
|
607
622
|
function isSavingEntityRecord(state, kind, name, recordId) {
|
|
608
|
-
|
|
623
|
+
var _state$entities$recor52, _state$entities$recor53, _state$entities$recor54, _state$entities$recor55, _state$entities$recor56, _state$entities$recor57;
|
|
624
|
+
|
|
625
|
+
return (_state$entities$recor52 = (_state$entities$recor53 = state.entities.records) === null || _state$entities$recor53 === void 0 ? void 0 : (_state$entities$recor54 = _state$entities$recor53[kind]) === null || _state$entities$recor54 === void 0 ? void 0 : (_state$entities$recor55 = _state$entities$recor54[name]) === null || _state$entities$recor55 === void 0 ? void 0 : (_state$entities$recor56 = _state$entities$recor55.saving) === null || _state$entities$recor56 === void 0 ? void 0 : (_state$entities$recor57 = _state$entities$recor56[recordId]) === null || _state$entities$recor57 === void 0 ? void 0 : _state$entities$recor57.pending) !== null && _state$entities$recor52 !== void 0 ? _state$entities$recor52 : false;
|
|
609
626
|
}
|
|
610
627
|
/**
|
|
611
628
|
* Returns true if the specified entity record is deleting, and false otherwise.
|
|
612
629
|
*
|
|
613
|
-
* @param
|
|
614
|
-
* @param
|
|
615
|
-
* @param
|
|
616
|
-
* @param
|
|
630
|
+
* @param state State tree.
|
|
631
|
+
* @param kind Entity kind.
|
|
632
|
+
* @param name Entity name.
|
|
633
|
+
* @param recordId Record ID.
|
|
617
634
|
*
|
|
618
635
|
* @return Whether the entity record is deleting or not.
|
|
619
636
|
*/
|
|
620
637
|
|
|
621
638
|
|
|
622
639
|
function isDeletingEntityRecord(state, kind, name, recordId) {
|
|
623
|
-
|
|
640
|
+
var _state$entities$recor58, _state$entities$recor59, _state$entities$recor60, _state$entities$recor61, _state$entities$recor62, _state$entities$recor63;
|
|
641
|
+
|
|
642
|
+
return (_state$entities$recor58 = (_state$entities$recor59 = state.entities.records) === null || _state$entities$recor59 === void 0 ? void 0 : (_state$entities$recor60 = _state$entities$recor59[kind]) === null || _state$entities$recor60 === void 0 ? void 0 : (_state$entities$recor61 = _state$entities$recor60[name]) === null || _state$entities$recor61 === void 0 ? void 0 : (_state$entities$recor62 = _state$entities$recor61.deleting) === null || _state$entities$recor62 === void 0 ? void 0 : (_state$entities$recor63 = _state$entities$recor62[recordId]) === null || _state$entities$recor63 === void 0 ? void 0 : _state$entities$recor63.pending) !== null && _state$entities$recor58 !== void 0 ? _state$entities$recor58 : false;
|
|
624
643
|
}
|
|
625
644
|
/**
|
|
626
645
|
* Returns the specified entity record's last save error.
|
|
627
646
|
*
|
|
628
|
-
* @param
|
|
629
|
-
* @param
|
|
630
|
-
* @param
|
|
631
|
-
* @param
|
|
647
|
+
* @param state State tree.
|
|
648
|
+
* @param kind Entity kind.
|
|
649
|
+
* @param name Entity name.
|
|
650
|
+
* @param recordId Record ID.
|
|
632
651
|
*
|
|
633
652
|
* @return The entity record's save error.
|
|
634
653
|
*/
|
|
635
654
|
|
|
636
655
|
|
|
637
656
|
function getLastEntitySaveError(state, kind, name, recordId) {
|
|
638
|
-
|
|
657
|
+
var _state$entities$recor64, _state$entities$recor65, _state$entities$recor66, _state$entities$recor67, _state$entities$recor68;
|
|
658
|
+
|
|
659
|
+
return (_state$entities$recor64 = state.entities.records) === null || _state$entities$recor64 === void 0 ? void 0 : (_state$entities$recor65 = _state$entities$recor64[kind]) === null || _state$entities$recor65 === void 0 ? void 0 : (_state$entities$recor66 = _state$entities$recor65[name]) === null || _state$entities$recor66 === void 0 ? void 0 : (_state$entities$recor67 = _state$entities$recor66.saving) === null || _state$entities$recor67 === void 0 ? void 0 : (_state$entities$recor68 = _state$entities$recor67[recordId]) === null || _state$entities$recor68 === void 0 ? void 0 : _state$entities$recor68.error;
|
|
639
660
|
}
|
|
640
661
|
/**
|
|
641
662
|
* Returns the specified entity record's last delete error.
|
|
642
663
|
*
|
|
643
|
-
* @param
|
|
644
|
-
* @param
|
|
645
|
-
* @param
|
|
646
|
-
* @param
|
|
664
|
+
* @param state State tree.
|
|
665
|
+
* @param kind Entity kind.
|
|
666
|
+
* @param name Entity name.
|
|
667
|
+
* @param recordId Record ID.
|
|
647
668
|
*
|
|
648
669
|
* @return The entity record's save error.
|
|
649
670
|
*/
|
|
650
671
|
|
|
651
672
|
|
|
652
673
|
function getLastEntityDeleteError(state, kind, name, recordId) {
|
|
653
|
-
|
|
674
|
+
var _state$entities$recor69, _state$entities$recor70, _state$entities$recor71, _state$entities$recor72, _state$entities$recor73;
|
|
675
|
+
|
|
676
|
+
return (_state$entities$recor69 = state.entities.records) === null || _state$entities$recor69 === void 0 ? void 0 : (_state$entities$recor70 = _state$entities$recor69[kind]) === null || _state$entities$recor70 === void 0 ? void 0 : (_state$entities$recor71 = _state$entities$recor70[name]) === null || _state$entities$recor71 === void 0 ? void 0 : (_state$entities$recor72 = _state$entities$recor71.deleting) === null || _state$entities$recor72 === void 0 ? void 0 : (_state$entities$recor73 = _state$entities$recor72[recordId]) === null || _state$entities$recor73 === void 0 ? void 0 : _state$entities$recor73.error;
|
|
654
677
|
}
|
|
655
678
|
/**
|
|
656
679
|
* Returns the current undo offset for the
|
|
@@ -659,7 +682,7 @@ function getLastEntityDeleteError(state, kind, name, recordId) {
|
|
|
659
682
|
* of the history stack we are at. 0 is the
|
|
660
683
|
* last edit, -1 is the second last, and so on.
|
|
661
684
|
*
|
|
662
|
-
* @param
|
|
685
|
+
* @param state State tree.
|
|
663
686
|
*
|
|
664
687
|
* @return The current undo offset.
|
|
665
688
|
*/
|
|
@@ -672,7 +695,7 @@ function getCurrentUndoOffset(state) {
|
|
|
672
695
|
* Returns the previous edit from the current undo offset
|
|
673
696
|
* for the entity records edits history, if any.
|
|
674
697
|
*
|
|
675
|
-
* @param
|
|
698
|
+
* @param state State tree.
|
|
676
699
|
*
|
|
677
700
|
* @return The edit.
|
|
678
701
|
*/
|
|
@@ -685,7 +708,7 @@ function getUndoEdit(state) {
|
|
|
685
708
|
* Returns the next edit from the current undo offset
|
|
686
709
|
* for the entity records edits history, if any.
|
|
687
710
|
*
|
|
688
|
-
* @param
|
|
711
|
+
* @param state State tree.
|
|
689
712
|
*
|
|
690
713
|
* @return The edit.
|
|
691
714
|
*/
|
|
@@ -698,7 +721,7 @@ function getRedoEdit(state) {
|
|
|
698
721
|
* Returns true if there is a previous edit from the current undo offset
|
|
699
722
|
* for the entity records edits history, and false otherwise.
|
|
700
723
|
*
|
|
701
|
-
* @param
|
|
724
|
+
* @param state State tree.
|
|
702
725
|
*
|
|
703
726
|
* @return Whether there is a previous edit or not.
|
|
704
727
|
*/
|
|
@@ -711,7 +734,7 @@ function hasUndo(state) {
|
|
|
711
734
|
* Returns true if there is a next edit from the current undo offset
|
|
712
735
|
* for the entity records edits history, and false otherwise.
|
|
713
736
|
*
|
|
714
|
-
* @param
|
|
737
|
+
* @param state State tree.
|
|
715
738
|
*
|
|
716
739
|
* @return Whether there is a next edit or not.
|
|
717
740
|
*/
|
|
@@ -723,7 +746,7 @@ function hasRedo(state) {
|
|
|
723
746
|
/**
|
|
724
747
|
* Return the current theme.
|
|
725
748
|
*
|
|
726
|
-
* @param
|
|
749
|
+
* @param state Data state.
|
|
727
750
|
*
|
|
728
751
|
* @return The current theme.
|
|
729
752
|
*/
|
|
@@ -735,7 +758,7 @@ function getCurrentTheme(state) {
|
|
|
735
758
|
/**
|
|
736
759
|
* Return the ID of the current global styles object.
|
|
737
760
|
*
|
|
738
|
-
* @param
|
|
761
|
+
* @param state Data state.
|
|
739
762
|
*
|
|
740
763
|
* @return The current global styles ID.
|
|
741
764
|
*/
|
|
@@ -747,7 +770,7 @@ function __experimentalGetCurrentGlobalStylesId(state) {
|
|
|
747
770
|
/**
|
|
748
771
|
* Return theme supports data in the index.
|
|
749
772
|
*
|
|
750
|
-
* @param
|
|
773
|
+
* @param state Data state.
|
|
751
774
|
*
|
|
752
775
|
* @return Index data.
|
|
753
776
|
*/
|
|
@@ -761,8 +784,8 @@ function getThemeSupports(state) {
|
|
|
761
784
|
/**
|
|
762
785
|
* Returns the embed preview for the given URL.
|
|
763
786
|
*
|
|
764
|
-
* @param
|
|
765
|
-
* @param
|
|
787
|
+
* @param state Data state.
|
|
788
|
+
* @param url Embedded URL.
|
|
766
789
|
*
|
|
767
790
|
* @return Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API.
|
|
768
791
|
*/
|
|
@@ -778,8 +801,8 @@ function getEmbedPreview(state, url) {
|
|
|
778
801
|
* We need to be able to determine if a URL is embeddable or not, based on what we
|
|
779
802
|
* get back from the oEmbed preview API.
|
|
780
803
|
*
|
|
781
|
-
* @param
|
|
782
|
-
* @param
|
|
804
|
+
* @param state Data state.
|
|
805
|
+
* @param url Embedded URL.
|
|
783
806
|
*
|
|
784
807
|
* @return Is the preview for the URL an oEmbed link fallback.
|
|
785
808
|
*/
|
|
@@ -804,10 +827,10 @@ function isPreviewEmbedFallback(state, url) {
|
|
|
804
827
|
*
|
|
805
828
|
* https://developer.wordpress.org/rest-api/reference/
|
|
806
829
|
*
|
|
807
|
-
* @param
|
|
808
|
-
* @param
|
|
809
|
-
* @param
|
|
810
|
-
* @param
|
|
830
|
+
* @param state Data state.
|
|
831
|
+
* @param action Action to check. One of: 'create', 'read', 'update', 'delete'.
|
|
832
|
+
* @param resource REST resource to check, e.g. 'media' or 'posts'.
|
|
833
|
+
* @param id Optional ID of the rest resource to check.
|
|
811
834
|
*
|
|
812
835
|
* @return Whether or not the user can perform the action,
|
|
813
836
|
* or `undefined` if the OPTIONS request is still being made.
|
|
@@ -816,7 +839,7 @@ function isPreviewEmbedFallback(state, url) {
|
|
|
816
839
|
|
|
817
840
|
function canUser(state, action, resource, id) {
|
|
818
841
|
const key = [action, resource, id].filter(Boolean).join('/');
|
|
819
|
-
return
|
|
842
|
+
return state.userPermissions[key];
|
|
820
843
|
}
|
|
821
844
|
/**
|
|
822
845
|
* Returns whether the current user can edit the given entity.
|
|
@@ -826,10 +849,10 @@ function canUser(state, action, resource, id) {
|
|
|
826
849
|
*
|
|
827
850
|
* https://developer.wordpress.org/rest-api/reference/
|
|
828
851
|
*
|
|
829
|
-
* @param
|
|
830
|
-
* @param
|
|
831
|
-
* @param
|
|
832
|
-
* @param
|
|
852
|
+
* @param state Data state.
|
|
853
|
+
* @param kind Entity kind.
|
|
854
|
+
* @param name Entity name.
|
|
855
|
+
* @param recordId Record's id.
|
|
833
856
|
* @return Whether or not the user can edit,
|
|
834
857
|
* or `undefined` if the OPTIONS request is still being made.
|
|
835
858
|
*/
|
|
@@ -851,9 +874,9 @@ function canUserEditEntityRecord(state, kind, name, recordId) {
|
|
|
851
874
|
* May return multiple autosaves since the backend stores one autosave per
|
|
852
875
|
* author for each post.
|
|
853
876
|
*
|
|
854
|
-
* @param
|
|
855
|
-
* @param
|
|
856
|
-
* @param
|
|
877
|
+
* @param state State tree.
|
|
878
|
+
* @param postType The type of the parent post.
|
|
879
|
+
* @param postId The id of the parent post.
|
|
857
880
|
*
|
|
858
881
|
* @return An array of autosaves for the post, or undefined if there is none.
|
|
859
882
|
*/
|
|
@@ -865,10 +888,10 @@ function getAutosaves(state, postType, postId) {
|
|
|
865
888
|
/**
|
|
866
889
|
* Returns the autosave for the post and author.
|
|
867
890
|
*
|
|
868
|
-
* @param
|
|
869
|
-
* @param
|
|
870
|
-
* @param
|
|
871
|
-
* @param
|
|
891
|
+
* @param state State tree.
|
|
892
|
+
* @param postType The type of the parent post.
|
|
893
|
+
* @param postId The id of the parent post.
|
|
894
|
+
* @param authorId The id of the author.
|
|
872
895
|
*
|
|
873
896
|
* @return The autosave for the post and author.
|
|
874
897
|
*/
|
|
@@ -885,9 +908,9 @@ function getAutosave(state, postType, postId, authorId) {
|
|
|
885
908
|
/**
|
|
886
909
|
* Returns true if the REST request for autosaves has completed.
|
|
887
910
|
*
|
|
888
|
-
* @param
|
|
889
|
-
* @param
|
|
890
|
-
* @param
|
|
911
|
+
* @param state State tree.
|
|
912
|
+
* @param postType The type of the parent post.
|
|
913
|
+
* @param postId The id of the parent post.
|
|
891
914
|
*
|
|
892
915
|
* @return True if the REST request was completed. False otherwise.
|
|
893
916
|
*/
|
|
@@ -910,7 +933,7 @@ const hasFetchedAutosaves = (0, _data.createRegistrySelector)(select => (state,
|
|
|
910
933
|
* );
|
|
911
934
|
* ```
|
|
912
935
|
*
|
|
913
|
-
* @param
|
|
936
|
+
* @param state Editor state.
|
|
914
937
|
*
|
|
915
938
|
* @return A value whose reference will change only when an edit occurs.
|
|
916
939
|
*/
|
|
@@ -921,8 +944,8 @@ state => [], state => [state.undo.length, state.undo.offset, state.undo.flattene
|
|
|
921
944
|
/**
|
|
922
945
|
* Retrieve the frontend template used for a given link.
|
|
923
946
|
*
|
|
924
|
-
* @param
|
|
925
|
-
* @param
|
|
947
|
+
* @param state Editor state.
|
|
948
|
+
* @param link Link.
|
|
926
949
|
*
|
|
927
950
|
* @return The template record.
|
|
928
951
|
*/
|
|
@@ -943,7 +966,7 @@ function __experimentalGetTemplateForLink(state, link) {
|
|
|
943
966
|
/**
|
|
944
967
|
* Retrieve the current theme's base global styles
|
|
945
968
|
*
|
|
946
|
-
* @param
|
|
969
|
+
* @param state Editor state.
|
|
947
970
|
*
|
|
948
971
|
* @return The Global Styles object.
|
|
949
972
|
*/
|
|
@@ -961,7 +984,7 @@ function __experimentalGetCurrentThemeBaseGlobalStyles(state) {
|
|
|
961
984
|
/**
|
|
962
985
|
* Return the ID of the current global styles object.
|
|
963
986
|
*
|
|
964
|
-
* @param
|
|
987
|
+
* @param state Data state.
|
|
965
988
|
*
|
|
966
989
|
* @return The current global styles ID.
|
|
967
990
|
*/
|
|
@@ -979,7 +1002,7 @@ function __experimentalGetCurrentThemeGlobalStylesVariations(state) {
|
|
|
979
1002
|
/**
|
|
980
1003
|
* Retrieve the list of registered block patterns.
|
|
981
1004
|
*
|
|
982
|
-
* @param
|
|
1005
|
+
* @param state Data state.
|
|
983
1006
|
*
|
|
984
1007
|
* @return Block pattern list.
|
|
985
1008
|
*/
|
|
@@ -991,7 +1014,7 @@ function getBlockPatterns(state) {
|
|
|
991
1014
|
/**
|
|
992
1015
|
* Retrieve the list of registered block pattern categories.
|
|
993
1016
|
*
|
|
994
|
-
* @param
|
|
1017
|
+
* @param state Data state.
|
|
995
1018
|
*
|
|
996
1019
|
* @return Block pattern category list.
|
|
997
1020
|
*/
|