@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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import createSelector from 'rememo';
|
|
5
|
-
import { set
|
|
5
|
+
import { set } from 'lodash';
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
8
8
|
*/
|
|
@@ -31,8 +31,8 @@ const EMPTY_OBJECT = {};
|
|
|
31
31
|
* Returns true if a request is in progress for embed preview data, or false
|
|
32
32
|
* otherwise.
|
|
33
33
|
*
|
|
34
|
-
* @param
|
|
35
|
-
* @param
|
|
34
|
+
* @param state Data state.
|
|
35
|
+
* @param url URL the preview would be for.
|
|
36
36
|
*
|
|
37
37
|
* @return Whether a request is in progress for an embed preview.
|
|
38
38
|
*/
|
|
@@ -45,9 +45,9 @@ export const isRequestingEmbedPreview = createRegistrySelector(select => (state,
|
|
|
45
45
|
*
|
|
46
46
|
* @deprecated since 11.3. Callers should use `select( 'core' ).getUsers({ who: 'authors' })` instead.
|
|
47
47
|
*
|
|
48
|
-
* @param
|
|
49
|
-
* @param
|
|
50
|
-
*
|
|
48
|
+
* @param state Data state.
|
|
49
|
+
* @param query Optional object of query parameters to
|
|
50
|
+
* include with request.
|
|
51
51
|
* @return Authors list.
|
|
52
52
|
*/
|
|
53
53
|
|
|
@@ -62,7 +62,7 @@ export function getAuthors(state, query) {
|
|
|
62
62
|
/**
|
|
63
63
|
* Returns the current user.
|
|
64
64
|
*
|
|
65
|
-
* @param
|
|
65
|
+
* @param state Data state.
|
|
66
66
|
*
|
|
67
67
|
* @return Current user object.
|
|
68
68
|
*/
|
|
@@ -73,8 +73,8 @@ export function getCurrentUser(state) {
|
|
|
73
73
|
/**
|
|
74
74
|
* Returns all the users returned by a query ID.
|
|
75
75
|
*
|
|
76
|
-
* @param
|
|
77
|
-
* @param
|
|
76
|
+
* @param state Data state.
|
|
77
|
+
* @param queryID Query ID.
|
|
78
78
|
*
|
|
79
79
|
* @return Users list.
|
|
80
80
|
*/
|
|
@@ -89,8 +89,8 @@ export const getUserQueryResults = createSelector((state, queryID) => {
|
|
|
89
89
|
* Returns the loaded entities for the given kind.
|
|
90
90
|
*
|
|
91
91
|
* @deprecated since WordPress 6.0. Use getEntitiesConfig instead
|
|
92
|
-
* @param
|
|
93
|
-
* @param
|
|
92
|
+
* @param state Data state.
|
|
93
|
+
* @param kind Entity kind.
|
|
94
94
|
*
|
|
95
95
|
* @return Array of entities with config matching kind.
|
|
96
96
|
*/
|
|
@@ -105,8 +105,8 @@ export function getEntitiesByKind(state, kind) {
|
|
|
105
105
|
/**
|
|
106
106
|
* Returns the loaded entities for the given kind.
|
|
107
107
|
*
|
|
108
|
-
* @param
|
|
109
|
-
* @param
|
|
108
|
+
* @param state Data state.
|
|
109
|
+
* @param kind Entity kind.
|
|
110
110
|
*
|
|
111
111
|
* @return Array of entities with config matching kind.
|
|
112
112
|
*/
|
|
@@ -118,9 +118,9 @@ export function getEntitiesConfig(state, kind) {
|
|
|
118
118
|
* Returns the entity config given its kind and name.
|
|
119
119
|
*
|
|
120
120
|
* @deprecated since WordPress 6.0. Use getEntityConfig instead
|
|
121
|
-
* @param
|
|
122
|
-
* @param
|
|
123
|
-
* @param
|
|
121
|
+
* @param state Data state.
|
|
122
|
+
* @param kind Entity kind.
|
|
123
|
+
* @param name Entity name.
|
|
124
124
|
*
|
|
125
125
|
* @return Entity config
|
|
126
126
|
*/
|
|
@@ -135,9 +135,9 @@ export function getEntity(state, kind, name) {
|
|
|
135
135
|
/**
|
|
136
136
|
* Returns the entity config given its kind and name.
|
|
137
137
|
*
|
|
138
|
-
* @param
|
|
139
|
-
* @param
|
|
140
|
-
* @param
|
|
138
|
+
* @param state Data state.
|
|
139
|
+
* @param kind Entity kind.
|
|
140
|
+
* @param name Entity name.
|
|
141
141
|
*
|
|
142
142
|
* @return Entity config
|
|
143
143
|
*/
|
|
@@ -177,19 +177,19 @@ export function getEntityConfig(state, kind, name) {
|
|
|
177
177
|
* yet received, undefined if the value entity is known to not exist, or the
|
|
178
178
|
* entity object if it exists and is received.
|
|
179
179
|
*
|
|
180
|
-
* @param
|
|
181
|
-
* @param
|
|
182
|
-
* @param
|
|
183
|
-
* @param
|
|
184
|
-
* @param
|
|
185
|
-
*
|
|
180
|
+
* @param state State tree
|
|
181
|
+
* @param kind Entity kind.
|
|
182
|
+
* @param name Entity name.
|
|
183
|
+
* @param key Record's key
|
|
184
|
+
* @param query Optional query. If requesting specific
|
|
185
|
+
* fields, fields must always include the ID.
|
|
186
186
|
*
|
|
187
187
|
* @return Record.
|
|
188
188
|
*/
|
|
189
189
|
export const getEntityRecord = createSelector((state, kind, name, key, query) => {
|
|
190
|
-
var _query$context, _queriedState$items$c;
|
|
190
|
+
var _state$entities$recor, _state$entities$recor2, _state$entities$recor3, _query$context, _queriedState$items$c;
|
|
191
191
|
|
|
192
|
-
const queriedState =
|
|
192
|
+
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;
|
|
193
193
|
|
|
194
194
|
if (!queriedState) {
|
|
195
195
|
return undefined;
|
|
@@ -218,7 +218,10 @@ export const getEntityRecord = createSelector((state, kind, name, key, query) =>
|
|
|
218
218
|
|
|
219
219
|
for (let f = 0; f < fields.length; f++) {
|
|
220
220
|
const field = fields[f].split('.');
|
|
221
|
-
|
|
221
|
+
let value = item;
|
|
222
|
+
field.forEach(fieldName => {
|
|
223
|
+
value = value[fieldName];
|
|
224
|
+
});
|
|
222
225
|
set(filteredItem, field, value);
|
|
223
226
|
}
|
|
224
227
|
|
|
@@ -227,18 +230,18 @@ export const getEntityRecord = createSelector((state, kind, name, key, query) =>
|
|
|
227
230
|
|
|
228
231
|
return item;
|
|
229
232
|
}, (state, kind, name, recordId, query) => {
|
|
230
|
-
var _query$context2;
|
|
233
|
+
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;
|
|
231
234
|
|
|
232
235
|
const context = (_query$context2 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context2 !== void 0 ? _query$context2 : 'default';
|
|
233
|
-
return [
|
|
236
|
+
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]];
|
|
234
237
|
});
|
|
235
238
|
/**
|
|
236
239
|
* 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.
|
|
237
240
|
*
|
|
238
|
-
* @param
|
|
239
|
-
* @param
|
|
240
|
-
* @param
|
|
241
|
-
* @param
|
|
241
|
+
* @param state State tree
|
|
242
|
+
* @param kind Entity kind.
|
|
243
|
+
* @param name Entity name.
|
|
244
|
+
* @param key Record's key
|
|
242
245
|
*
|
|
243
246
|
* @return Record.
|
|
244
247
|
*/
|
|
@@ -250,10 +253,10 @@ export function __experimentalGetEntityRecordNoResolver(state, kind, name, key)
|
|
|
250
253
|
* Returns the entity's record object by key,
|
|
251
254
|
* with its attributes mapped to their raw values.
|
|
252
255
|
*
|
|
253
|
-
* @param
|
|
254
|
-
* @param
|
|
255
|
-
* @param
|
|
256
|
-
* @param
|
|
256
|
+
* @param state State tree.
|
|
257
|
+
* @param kind Entity kind.
|
|
258
|
+
* @param name Entity name.
|
|
259
|
+
* @param key Record's key.
|
|
257
260
|
*
|
|
258
261
|
* @return Object with the entity's raw attributes.
|
|
259
262
|
*/
|
|
@@ -262,10 +265,12 @@ export const getRawEntityRecord = createSelector((state, kind, name, key) => {
|
|
|
262
265
|
const record = getEntityRecord(state, kind, name, key);
|
|
263
266
|
return record && Object.keys(record).reduce((accumulator, _key) => {
|
|
264
267
|
if (isRawAttribute(getEntityConfig(state, kind, name), _key)) {
|
|
268
|
+
var _record$_key$raw, _record$_key;
|
|
269
|
+
|
|
265
270
|
// Because edits are the "raw" attribute values,
|
|
266
271
|
// we return those from record selectors to make rendering,
|
|
267
272
|
// comparisons, and joins with edits easier.
|
|
268
|
-
accumulator[_key] =
|
|
273
|
+
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];
|
|
269
274
|
} else {
|
|
270
275
|
accumulator[_key] = record[_key];
|
|
271
276
|
}
|
|
@@ -273,19 +278,19 @@ export const getRawEntityRecord = createSelector((state, kind, name, key) => {
|
|
|
273
278
|
return accumulator;
|
|
274
279
|
}, {});
|
|
275
280
|
}, (state, kind, name, recordId, query) => {
|
|
276
|
-
var _query$context3;
|
|
281
|
+
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;
|
|
277
282
|
|
|
278
283
|
const context = (_query$context3 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context3 !== void 0 ? _query$context3 : 'default';
|
|
279
|
-
return [state.entities.config,
|
|
284
|
+
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]];
|
|
280
285
|
});
|
|
281
286
|
/**
|
|
282
287
|
* Returns true if records have been received for the given set of parameters,
|
|
283
288
|
* or false otherwise.
|
|
284
289
|
*
|
|
285
|
-
* @param
|
|
286
|
-
* @param
|
|
287
|
-
* @param
|
|
288
|
-
* @param
|
|
290
|
+
* @param state State tree
|
|
291
|
+
* @param kind Entity kind.
|
|
292
|
+
* @param name Entity name.
|
|
293
|
+
* @param query Optional terms query.
|
|
289
294
|
*
|
|
290
295
|
* @return Whether entity records have been received.
|
|
291
296
|
*/
|
|
@@ -305,18 +310,20 @@ export function hasEntityRecords(state, kind, name, query) {
|
|
|
305
310
|
/**
|
|
306
311
|
* Returns the Entity's records.
|
|
307
312
|
*
|
|
308
|
-
* @param
|
|
309
|
-
* @param
|
|
310
|
-
* @param
|
|
311
|
-
* @param
|
|
312
|
-
*
|
|
313
|
+
* @param state State tree
|
|
314
|
+
* @param kind Entity kind.
|
|
315
|
+
* @param name Entity name.
|
|
316
|
+
* @param query Optional terms query. If requesting specific
|
|
317
|
+
* fields, fields must always include the ID.
|
|
313
318
|
*
|
|
314
319
|
* @return Records.
|
|
315
320
|
*/
|
|
316
321
|
export const getEntityRecords = (state, kind, name, query) => {
|
|
322
|
+
var _state$entities$recor24, _state$entities$recor25, _state$entities$recor26;
|
|
323
|
+
|
|
317
324
|
// Queried data state is prepopulated for all known entities. If this is not
|
|
318
325
|
// assigned for the given parameters, then it is known to not exist.
|
|
319
|
-
const queriedState =
|
|
326
|
+
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;
|
|
320
327
|
|
|
321
328
|
if (!queriedState) {
|
|
322
329
|
return null;
|
|
@@ -328,7 +335,7 @@ export const getEntityRecords = (state, kind, name, query) => {
|
|
|
328
335
|
/**
|
|
329
336
|
* Returns the list of dirty entity records.
|
|
330
337
|
*
|
|
331
|
-
* @param
|
|
338
|
+
* @param state State tree.
|
|
332
339
|
*
|
|
333
340
|
* @return The list of updated records
|
|
334
341
|
*/
|
|
@@ -368,7 +375,7 @@ export const __experimentalGetDirtyEntityRecords = createSelector(state => {
|
|
|
368
375
|
/**
|
|
369
376
|
* Returns the list of entities currently being saved.
|
|
370
377
|
*
|
|
371
|
-
* @param
|
|
378
|
+
* @param state State tree.
|
|
372
379
|
*
|
|
373
380
|
* @return The list of records being saved.
|
|
374
381
|
*/
|
|
@@ -407,16 +414,18 @@ export const __experimentalGetEntitiesBeingSaved = createSelector(state => {
|
|
|
407
414
|
/**
|
|
408
415
|
* Returns the specified entity record's edits.
|
|
409
416
|
*
|
|
410
|
-
* @param
|
|
411
|
-
* @param
|
|
412
|
-
* @param
|
|
413
|
-
* @param
|
|
417
|
+
* @param state State tree.
|
|
418
|
+
* @param kind Entity kind.
|
|
419
|
+
* @param name Entity name.
|
|
420
|
+
* @param recordId Record ID.
|
|
414
421
|
*
|
|
415
422
|
* @return The entity record's edits.
|
|
416
423
|
*/
|
|
417
424
|
|
|
418
425
|
export function getEntityRecordEdits(state, kind, name, recordId) {
|
|
419
|
-
|
|
426
|
+
var _state$entities$recor27, _state$entities$recor28, _state$entities$recor29, _state$entities$recor30;
|
|
427
|
+
|
|
428
|
+
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];
|
|
420
429
|
}
|
|
421
430
|
/**
|
|
422
431
|
* Returns the specified entity record's non transient edits.
|
|
@@ -425,10 +434,10 @@ export function getEntityRecordEdits(state, kind, name, recordId) {
|
|
|
425
434
|
* are not considered for change detection.
|
|
426
435
|
* They are defined in the entity's config.
|
|
427
436
|
*
|
|
428
|
-
* @param
|
|
429
|
-
* @param
|
|
430
|
-
* @param
|
|
431
|
-
* @param
|
|
437
|
+
* @param state State tree.
|
|
438
|
+
* @param kind Entity kind.
|
|
439
|
+
* @param name Entity name.
|
|
440
|
+
* @param recordId Record ID.
|
|
432
441
|
*
|
|
433
442
|
* @return The entity record's non transient edits.
|
|
434
443
|
*/
|
|
@@ -450,15 +459,19 @@ export const getEntityRecordNonTransientEdits = createSelector((state, kind, nam
|
|
|
450
459
|
|
|
451
460
|
return acc;
|
|
452
461
|
}, {});
|
|
453
|
-
}, (state, kind, name, recordId) =>
|
|
462
|
+
}, (state, kind, name, recordId) => {
|
|
463
|
+
var _state$entities$recor31, _state$entities$recor32, _state$entities$recor33, _state$entities$recor34;
|
|
464
|
+
|
|
465
|
+
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]];
|
|
466
|
+
});
|
|
454
467
|
/**
|
|
455
468
|
* Returns true if the specified entity record has edits,
|
|
456
469
|
* and false otherwise.
|
|
457
470
|
*
|
|
458
|
-
* @param
|
|
459
|
-
* @param
|
|
460
|
-
* @param
|
|
461
|
-
* @param
|
|
471
|
+
* @param state State tree.
|
|
472
|
+
* @param kind Entity kind.
|
|
473
|
+
* @param name Entity name.
|
|
474
|
+
* @param recordId Record ID.
|
|
462
475
|
*
|
|
463
476
|
* @return Whether the entity record has edits or not.
|
|
464
477
|
*/
|
|
@@ -469,10 +482,10 @@ export function hasEditsForEntityRecord(state, kind, name, recordId) {
|
|
|
469
482
|
/**
|
|
470
483
|
* Returns the specified entity record, merged with its edits.
|
|
471
484
|
*
|
|
472
|
-
* @param
|
|
473
|
-
* @param
|
|
474
|
-
* @param
|
|
475
|
-
* @param
|
|
485
|
+
* @param state State tree.
|
|
486
|
+
* @param kind Entity kind.
|
|
487
|
+
* @param name Entity name.
|
|
488
|
+
* @param recordId Record ID.
|
|
476
489
|
*
|
|
477
490
|
* @return The entity record, merged with its edits.
|
|
478
491
|
*/
|
|
@@ -480,84 +493,94 @@ export function hasEditsForEntityRecord(state, kind, name, recordId) {
|
|
|
480
493
|
export const getEditedEntityRecord = createSelector((state, kind, name, recordId) => ({ ...getRawEntityRecord(state, kind, name, recordId),
|
|
481
494
|
...getEntityRecordEdits(state, kind, name, recordId)
|
|
482
495
|
}), (state, kind, name, recordId, query) => {
|
|
483
|
-
var _query$context4;
|
|
496
|
+
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;
|
|
484
497
|
|
|
485
498
|
const context = (_query$context4 = query === null || query === void 0 ? void 0 : query.context) !== null && _query$context4 !== void 0 ? _query$context4 : 'default';
|
|
486
|
-
return [state.entities.config,
|
|
499
|
+
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]];
|
|
487
500
|
});
|
|
488
501
|
/**
|
|
489
502
|
* Returns true if the specified entity record is autosaving, and false otherwise.
|
|
490
503
|
*
|
|
491
|
-
* @param
|
|
492
|
-
* @param
|
|
493
|
-
* @param
|
|
494
|
-
* @param
|
|
504
|
+
* @param state State tree.
|
|
505
|
+
* @param kind Entity kind.
|
|
506
|
+
* @param name Entity name.
|
|
507
|
+
* @param recordId Record ID.
|
|
495
508
|
*
|
|
496
509
|
* @return Whether the entity record is autosaving or not.
|
|
497
510
|
*/
|
|
498
511
|
|
|
499
512
|
export function isAutosavingEntityRecord(state, kind, name, recordId) {
|
|
513
|
+
var _state$entities$recor47, _state$entities$recor48, _state$entities$recor49, _state$entities$recor50, _state$entities$recor51;
|
|
514
|
+
|
|
500
515
|
const {
|
|
501
516
|
pending,
|
|
502
517
|
isAutosave
|
|
503
|
-
} =
|
|
518
|
+
} = (_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 : {};
|
|
504
519
|
return Boolean(pending && isAutosave);
|
|
505
520
|
}
|
|
506
521
|
/**
|
|
507
522
|
* Returns true if the specified entity record is saving, and false otherwise.
|
|
508
523
|
*
|
|
509
|
-
* @param
|
|
510
|
-
* @param
|
|
511
|
-
* @param
|
|
512
|
-
* @param
|
|
524
|
+
* @param state State tree.
|
|
525
|
+
* @param kind Entity kind.
|
|
526
|
+
* @param name Entity name.
|
|
527
|
+
* @param recordId Record ID.
|
|
513
528
|
*
|
|
514
529
|
* @return Whether the entity record is saving or not.
|
|
515
530
|
*/
|
|
516
531
|
|
|
517
532
|
export function isSavingEntityRecord(state, kind, name, recordId) {
|
|
518
|
-
|
|
533
|
+
var _state$entities$recor52, _state$entities$recor53, _state$entities$recor54, _state$entities$recor55, _state$entities$recor56, _state$entities$recor57;
|
|
534
|
+
|
|
535
|
+
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;
|
|
519
536
|
}
|
|
520
537
|
/**
|
|
521
538
|
* Returns true if the specified entity record is deleting, and false otherwise.
|
|
522
539
|
*
|
|
523
|
-
* @param
|
|
524
|
-
* @param
|
|
525
|
-
* @param
|
|
526
|
-
* @param
|
|
540
|
+
* @param state State tree.
|
|
541
|
+
* @param kind Entity kind.
|
|
542
|
+
* @param name Entity name.
|
|
543
|
+
* @param recordId Record ID.
|
|
527
544
|
*
|
|
528
545
|
* @return Whether the entity record is deleting or not.
|
|
529
546
|
*/
|
|
530
547
|
|
|
531
548
|
export function isDeletingEntityRecord(state, kind, name, recordId) {
|
|
532
|
-
|
|
549
|
+
var _state$entities$recor58, _state$entities$recor59, _state$entities$recor60, _state$entities$recor61, _state$entities$recor62, _state$entities$recor63;
|
|
550
|
+
|
|
551
|
+
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;
|
|
533
552
|
}
|
|
534
553
|
/**
|
|
535
554
|
* Returns the specified entity record's last save error.
|
|
536
555
|
*
|
|
537
|
-
* @param
|
|
538
|
-
* @param
|
|
539
|
-
* @param
|
|
540
|
-
* @param
|
|
556
|
+
* @param state State tree.
|
|
557
|
+
* @param kind Entity kind.
|
|
558
|
+
* @param name Entity name.
|
|
559
|
+
* @param recordId Record ID.
|
|
541
560
|
*
|
|
542
561
|
* @return The entity record's save error.
|
|
543
562
|
*/
|
|
544
563
|
|
|
545
564
|
export function getLastEntitySaveError(state, kind, name, recordId) {
|
|
546
|
-
|
|
565
|
+
var _state$entities$recor64, _state$entities$recor65, _state$entities$recor66, _state$entities$recor67, _state$entities$recor68;
|
|
566
|
+
|
|
567
|
+
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;
|
|
547
568
|
}
|
|
548
569
|
/**
|
|
549
570
|
* Returns the specified entity record's last delete error.
|
|
550
571
|
*
|
|
551
|
-
* @param
|
|
552
|
-
* @param
|
|
553
|
-
* @param
|
|
554
|
-
* @param
|
|
572
|
+
* @param state State tree.
|
|
573
|
+
* @param kind Entity kind.
|
|
574
|
+
* @param name Entity name.
|
|
575
|
+
* @param recordId Record ID.
|
|
555
576
|
*
|
|
556
577
|
* @return The entity record's save error.
|
|
557
578
|
*/
|
|
558
579
|
|
|
559
580
|
export function getLastEntityDeleteError(state, kind, name, recordId) {
|
|
560
|
-
|
|
581
|
+
var _state$entities$recor69, _state$entities$recor70, _state$entities$recor71, _state$entities$recor72, _state$entities$recor73;
|
|
582
|
+
|
|
583
|
+
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;
|
|
561
584
|
}
|
|
562
585
|
/**
|
|
563
586
|
* Returns the current undo offset for the
|
|
@@ -566,7 +589,7 @@ export function getLastEntityDeleteError(state, kind, name, recordId) {
|
|
|
566
589
|
* of the history stack we are at. 0 is the
|
|
567
590
|
* last edit, -1 is the second last, and so on.
|
|
568
591
|
*
|
|
569
|
-
* @param
|
|
592
|
+
* @param state State tree.
|
|
570
593
|
*
|
|
571
594
|
* @return The current undo offset.
|
|
572
595
|
*/
|
|
@@ -578,7 +601,7 @@ function getCurrentUndoOffset(state) {
|
|
|
578
601
|
* Returns the previous edit from the current undo offset
|
|
579
602
|
* for the entity records edits history, if any.
|
|
580
603
|
*
|
|
581
|
-
* @param
|
|
604
|
+
* @param state State tree.
|
|
582
605
|
*
|
|
583
606
|
* @return The edit.
|
|
584
607
|
*/
|
|
@@ -591,7 +614,7 @@ export function getUndoEdit(state) {
|
|
|
591
614
|
* Returns the next edit from the current undo offset
|
|
592
615
|
* for the entity records edits history, if any.
|
|
593
616
|
*
|
|
594
|
-
* @param
|
|
617
|
+
* @param state State tree.
|
|
595
618
|
*
|
|
596
619
|
* @return The edit.
|
|
597
620
|
*/
|
|
@@ -603,7 +626,7 @@ export function getRedoEdit(state) {
|
|
|
603
626
|
* Returns true if there is a previous edit from the current undo offset
|
|
604
627
|
* for the entity records edits history, and false otherwise.
|
|
605
628
|
*
|
|
606
|
-
* @param
|
|
629
|
+
* @param state State tree.
|
|
607
630
|
*
|
|
608
631
|
* @return Whether there is a previous edit or not.
|
|
609
632
|
*/
|
|
@@ -615,7 +638,7 @@ export function hasUndo(state) {
|
|
|
615
638
|
* Returns true if there is a next edit from the current undo offset
|
|
616
639
|
* for the entity records edits history, and false otherwise.
|
|
617
640
|
*
|
|
618
|
-
* @param
|
|
641
|
+
* @param state State tree.
|
|
619
642
|
*
|
|
620
643
|
* @return Whether there is a next edit or not.
|
|
621
644
|
*/
|
|
@@ -626,7 +649,7 @@ export function hasRedo(state) {
|
|
|
626
649
|
/**
|
|
627
650
|
* Return the current theme.
|
|
628
651
|
*
|
|
629
|
-
* @param
|
|
652
|
+
* @param state Data state.
|
|
630
653
|
*
|
|
631
654
|
* @return The current theme.
|
|
632
655
|
*/
|
|
@@ -637,7 +660,7 @@ export function getCurrentTheme(state) {
|
|
|
637
660
|
/**
|
|
638
661
|
* Return the ID of the current global styles object.
|
|
639
662
|
*
|
|
640
|
-
* @param
|
|
663
|
+
* @param state Data state.
|
|
641
664
|
*
|
|
642
665
|
* @return The current global styles ID.
|
|
643
666
|
*/
|
|
@@ -648,7 +671,7 @@ export function __experimentalGetCurrentGlobalStylesId(state) {
|
|
|
648
671
|
/**
|
|
649
672
|
* Return theme supports data in the index.
|
|
650
673
|
*
|
|
651
|
-
* @param
|
|
674
|
+
* @param state Data state.
|
|
652
675
|
*
|
|
653
676
|
* @return Index data.
|
|
654
677
|
*/
|
|
@@ -661,8 +684,8 @@ export function getThemeSupports(state) {
|
|
|
661
684
|
/**
|
|
662
685
|
* Returns the embed preview for the given URL.
|
|
663
686
|
*
|
|
664
|
-
* @param
|
|
665
|
-
* @param
|
|
687
|
+
* @param state Data state.
|
|
688
|
+
* @param url Embedded URL.
|
|
666
689
|
*
|
|
667
690
|
* @return Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API.
|
|
668
691
|
*/
|
|
@@ -677,8 +700,8 @@ export function getEmbedPreview(state, url) {
|
|
|
677
700
|
* We need to be able to determine if a URL is embeddable or not, based on what we
|
|
678
701
|
* get back from the oEmbed preview API.
|
|
679
702
|
*
|
|
680
|
-
* @param
|
|
681
|
-
* @param
|
|
703
|
+
* @param state Data state.
|
|
704
|
+
* @param url Embedded URL.
|
|
682
705
|
*
|
|
683
706
|
* @return Is the preview for the URL an oEmbed link fallback.
|
|
684
707
|
*/
|
|
@@ -702,10 +725,10 @@ export function isPreviewEmbedFallback(state, url) {
|
|
|
702
725
|
*
|
|
703
726
|
* https://developer.wordpress.org/rest-api/reference/
|
|
704
727
|
*
|
|
705
|
-
* @param
|
|
706
|
-
* @param
|
|
707
|
-
* @param
|
|
708
|
-
* @param
|
|
728
|
+
* @param state Data state.
|
|
729
|
+
* @param action Action to check. One of: 'create', 'read', 'update', 'delete'.
|
|
730
|
+
* @param resource REST resource to check, e.g. 'media' or 'posts'.
|
|
731
|
+
* @param id Optional ID of the rest resource to check.
|
|
709
732
|
*
|
|
710
733
|
* @return Whether or not the user can perform the action,
|
|
711
734
|
* or `undefined` if the OPTIONS request is still being made.
|
|
@@ -713,7 +736,7 @@ export function isPreviewEmbedFallback(state, url) {
|
|
|
713
736
|
|
|
714
737
|
export function canUser(state, action, resource, id) {
|
|
715
738
|
const key = [action, resource, id].filter(Boolean).join('/');
|
|
716
|
-
return
|
|
739
|
+
return state.userPermissions[key];
|
|
717
740
|
}
|
|
718
741
|
/**
|
|
719
742
|
* Returns whether the current user can edit the given entity.
|
|
@@ -723,10 +746,10 @@ export function canUser(state, action, resource, id) {
|
|
|
723
746
|
*
|
|
724
747
|
* https://developer.wordpress.org/rest-api/reference/
|
|
725
748
|
*
|
|
726
|
-
* @param
|
|
727
|
-
* @param
|
|
728
|
-
* @param
|
|
729
|
-
* @param
|
|
749
|
+
* @param state Data state.
|
|
750
|
+
* @param kind Entity kind.
|
|
751
|
+
* @param name Entity name.
|
|
752
|
+
* @param recordId Record's id.
|
|
730
753
|
* @return Whether or not the user can edit,
|
|
731
754
|
* or `undefined` if the OPTIONS request is still being made.
|
|
732
755
|
*/
|
|
@@ -747,9 +770,9 @@ export function canUserEditEntityRecord(state, kind, name, recordId) {
|
|
|
747
770
|
* May return multiple autosaves since the backend stores one autosave per
|
|
748
771
|
* author for each post.
|
|
749
772
|
*
|
|
750
|
-
* @param
|
|
751
|
-
* @param
|
|
752
|
-
* @param
|
|
773
|
+
* @param state State tree.
|
|
774
|
+
* @param postType The type of the parent post.
|
|
775
|
+
* @param postId The id of the parent post.
|
|
753
776
|
*
|
|
754
777
|
* @return An array of autosaves for the post, or undefined if there is none.
|
|
755
778
|
*/
|
|
@@ -760,10 +783,10 @@ export function getAutosaves(state, postType, postId) {
|
|
|
760
783
|
/**
|
|
761
784
|
* Returns the autosave for the post and author.
|
|
762
785
|
*
|
|
763
|
-
* @param
|
|
764
|
-
* @param
|
|
765
|
-
* @param
|
|
766
|
-
* @param
|
|
786
|
+
* @param state State tree.
|
|
787
|
+
* @param postType The type of the parent post.
|
|
788
|
+
* @param postId The id of the parent post.
|
|
789
|
+
* @param authorId The id of the author.
|
|
767
790
|
*
|
|
768
791
|
* @return The autosave for the post and author.
|
|
769
792
|
*/
|
|
@@ -779,9 +802,9 @@ export function getAutosave(state, postType, postId, authorId) {
|
|
|
779
802
|
/**
|
|
780
803
|
* Returns true if the REST request for autosaves has completed.
|
|
781
804
|
*
|
|
782
|
-
* @param
|
|
783
|
-
* @param
|
|
784
|
-
* @param
|
|
805
|
+
* @param state State tree.
|
|
806
|
+
* @param postType The type of the parent post.
|
|
807
|
+
* @param postId The id of the parent post.
|
|
785
808
|
*
|
|
786
809
|
* @return True if the REST request was completed. False otherwise.
|
|
787
810
|
*/
|
|
@@ -803,7 +826,7 @@ export const hasFetchedAutosaves = createRegistrySelector(select => (state, post
|
|
|
803
826
|
* );
|
|
804
827
|
* ```
|
|
805
828
|
*
|
|
806
|
-
* @param
|
|
829
|
+
* @param state Editor state.
|
|
807
830
|
*
|
|
808
831
|
* @return A value whose reference will change only when an edit occurs.
|
|
809
832
|
*/
|
|
@@ -813,8 +836,8 @@ state => [], state => [state.undo.length, state.undo.offset, state.undo.flattene
|
|
|
813
836
|
/**
|
|
814
837
|
* Retrieve the frontend template used for a given link.
|
|
815
838
|
*
|
|
816
|
-
* @param
|
|
817
|
-
* @param
|
|
839
|
+
* @param state Editor state.
|
|
840
|
+
* @param link Link.
|
|
818
841
|
*
|
|
819
842
|
* @return The template record.
|
|
820
843
|
*/
|
|
@@ -833,7 +856,7 @@ export function __experimentalGetTemplateForLink(state, link) {
|
|
|
833
856
|
/**
|
|
834
857
|
* Retrieve the current theme's base global styles
|
|
835
858
|
*
|
|
836
|
-
* @param
|
|
859
|
+
* @param state Editor state.
|
|
837
860
|
*
|
|
838
861
|
* @return The Global Styles object.
|
|
839
862
|
*/
|
|
@@ -850,7 +873,7 @@ export function __experimentalGetCurrentThemeBaseGlobalStyles(state) {
|
|
|
850
873
|
/**
|
|
851
874
|
* Return the ID of the current global styles object.
|
|
852
875
|
*
|
|
853
|
-
* @param
|
|
876
|
+
* @param state Data state.
|
|
854
877
|
*
|
|
855
878
|
* @return The current global styles ID.
|
|
856
879
|
*/
|
|
@@ -867,7 +890,7 @@ export function __experimentalGetCurrentThemeGlobalStylesVariations(state) {
|
|
|
867
890
|
/**
|
|
868
891
|
* Retrieve the list of registered block patterns.
|
|
869
892
|
*
|
|
870
|
-
* @param
|
|
893
|
+
* @param state Data state.
|
|
871
894
|
*
|
|
872
895
|
* @return Block pattern list.
|
|
873
896
|
*/
|
|
@@ -878,7 +901,7 @@ export function getBlockPatterns(state) {
|
|
|
878
901
|
/**
|
|
879
902
|
* Retrieve the list of registered block pattern categories.
|
|
880
903
|
*
|
|
881
|
-
* @param
|
|
904
|
+
* @param state Data state.
|
|
882
905
|
*
|
|
883
906
|
* @return Block pattern category list.
|
|
884
907
|
*/
|