@wordpress/core-data 4.6.0 → 4.9.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 +11 -1
- package/README.md +209 -119
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +1 -1
- package/build/batch/create-batch.js.map +1 -1
- package/build/entities.js +49 -35
- package/build/entities.js.map +1 -1
- package/build/entity-provider.js.map +1 -1
- package/build/entity-types/entities.js +6 -0
- package/build/entity-types/entities.js.map +1 -0
- package/build/hooks/constants.js +0 -2
- package/build/hooks/constants.js.map +1 -1
- package/build/hooks/index.js +38 -0
- package/build/hooks/index.js.map +1 -0
- package/build/hooks/use-entity-record.js +22 -8
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +21 -8
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/index.js +17 -21
- package/build/index.js.map +1 -1
- package/build/queried-data/selectors.js.map +1 -1
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +206 -169
- package/build/selectors.js.map +1 -1
- package/build/utils/forward-resolver.js.map +1 -1
- package/build/utils/on-sub-key.js.map +1 -1
- package/build/utils/with-weak-map-cache.js +1 -7
- package/build/utils/with-weak-map-cache.js.map +1 -1
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +2 -2
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/entities.js +49 -35
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/entity-types/entities.js +2 -0
- package/build-module/entity-types/entities.js.map +1 -0
- package/build-module/hooks/constants.js +0 -1
- package/build-module/hooks/constants.js.map +1 -1
- package/build-module/hooks/index.js +3 -0
- package/build-module/hooks/index.js.map +1 -0
- package/build-module/hooks/use-entity-record.js +18 -7
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +17 -7
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/index.js +2 -3
- package/build-module/index.js.map +1 -1
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +203 -166
- package/build-module/selectors.js.map +1 -1
- package/build-module/utils/forward-resolver.js.map +1 -1
- package/build-module/utils/on-sub-key.js.map +1 -1
- package/build-module/utils/with-weak-map-cache.js +1 -6
- package/build-module/utils/with-weak-map-cache.js.map +1 -1
- package/package.json +12 -12
- package/src/actions.js +389 -372
- package/src/batch/create-batch.js +2 -2
- package/src/entities.ts +357 -135
- package/src/entity-provider.js +4 -6
- package/src/entity-types/attachment.ts +4 -3
- package/src/entity-types/comment.ts +4 -3
- package/src/entity-types/entities.ts +130 -0
- package/src/entity-types/index.ts +115 -20
- package/src/entity-types/menu-location.ts +4 -3
- package/src/entity-types/nav-menu-item.ts +4 -3
- package/src/entity-types/nav-menu.ts +3 -3
- package/src/entity-types/page.ts +3 -3
- package/src/entity-types/plugin.ts +3 -3
- package/src/entity-types/post.ts +3 -3
- package/src/entity-types/settings.ts +3 -3
- package/src/entity-types/sidebar.ts +4 -3
- package/src/entity-types/taxonomy.ts +4 -3
- package/src/entity-types/theme.ts +3 -3
- package/src/entity-types/type.ts +3 -3
- package/src/entity-types/user.ts +3 -3
- package/src/entity-types/widget-type.ts +4 -3
- package/src/entity-types/widget.ts +3 -3
- package/src/entity-types/wp-template-part.ts +4 -3
- package/src/entity-types/wp-template.ts +4 -3
- package/src/fetch/test/__experimental-fetch-link-suggestions.js +2 -4
- package/src/hooks/constants.ts +1 -2
- package/src/hooks/index.ts +8 -0
- package/src/hooks/test/use-query-select.js +4 -2
- package/src/hooks/use-entity-record.ts +31 -9
- package/src/hooks/use-entity-records.ts +28 -30
- package/src/hooks/use-query-select.ts +26 -24
- package/src/index.js +2 -3
- package/src/locks/test/selectors.js +2 -1
- package/src/queried-data/selectors.js +2 -8
- package/src/resolvers.js +344 -325
- package/src/selectors.ts +639 -296
- package/src/test/resolvers.js +1 -3
- package/src/test/selectors.js +1 -2
- package/src/utils/forward-resolver.js +6 -5
- package/src/utils/on-sub-key.js +20 -20
- package/src/utils/with-weak-map-cache.js +1 -6
|
@@ -18,6 +18,7 @@ import { STORE_NAME } from './name';
|
|
|
18
18
|
import { getQueriedItems } from './queried-data';
|
|
19
19
|
import { DEFAULT_ENTITY_KEY } from './entities';
|
|
20
20
|
import { getNormalizedCommaSeparable, isRawAttribute } from './utils';
|
|
21
|
+
|
|
21
22
|
/**
|
|
22
23
|
* Shared reference to an empty object for cases where it is important to avoid
|
|
23
24
|
* returning a new object reference on every invocation, as in a connected or
|
|
@@ -25,16 +26,15 @@ import { getNormalizedCommaSeparable, isRawAttribute } from './utils';
|
|
|
25
26
|
* This should be used as a last resort, since the normalized data should be
|
|
26
27
|
* maintained by the reducer result in state.
|
|
27
28
|
*/
|
|
28
|
-
|
|
29
29
|
const EMPTY_OBJECT = {};
|
|
30
30
|
/**
|
|
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
|
-
* @return
|
|
37
|
+
* @return Whether a request is in progress for an embed preview.
|
|
38
38
|
*/
|
|
39
39
|
|
|
40
40
|
export const isRequestingEmbedPreview = createRegistrySelector(select => (state, url) => {
|
|
@@ -45,10 +45,10 @@ 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
|
-
*
|
|
51
|
-
* @return
|
|
48
|
+
* @param state Data state.
|
|
49
|
+
* @param query Optional object of query parameters to
|
|
50
|
+
* include with request.
|
|
51
|
+
* @return Authors list.
|
|
52
52
|
*/
|
|
53
53
|
|
|
54
54
|
export function getAuthors(state, query) {
|
|
@@ -62,9 +62,9 @@ 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
|
-
* @return
|
|
67
|
+
* @return Current user object.
|
|
68
68
|
*/
|
|
69
69
|
|
|
70
70
|
export function getCurrentUser(state) {
|
|
@@ -73,10 +73,10 @@ 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
|
-
* @return
|
|
79
|
+
* @return Users list.
|
|
80
80
|
*/
|
|
81
81
|
|
|
82
82
|
export const getUserQueryResults = createSelector((state, queryID) => {
|
|
@@ -87,10 +87,10 @@ export const getUserQueryResults = createSelector((state, queryID) => {
|
|
|
87
87
|
* Returns the loaded entities for the given kind.
|
|
88
88
|
*
|
|
89
89
|
* @deprecated since WordPress 6.0. Use getEntitiesConfig instead
|
|
90
|
-
* @param
|
|
91
|
-
* @param
|
|
90
|
+
* @param state Data state.
|
|
91
|
+
* @param kind Entity kind.
|
|
92
92
|
*
|
|
93
|
-
* @return
|
|
93
|
+
* @return Array of entities with config matching kind.
|
|
94
94
|
*/
|
|
95
95
|
|
|
96
96
|
export function getEntitiesByKind(state, kind) {
|
|
@@ -103,10 +103,10 @@ export function getEntitiesByKind(state, kind) {
|
|
|
103
103
|
/**
|
|
104
104
|
* Returns the loaded entities for the given kind.
|
|
105
105
|
*
|
|
106
|
-
* @param
|
|
107
|
-
* @param
|
|
106
|
+
* @param state Data state.
|
|
107
|
+
* @param kind Entity kind.
|
|
108
108
|
*
|
|
109
|
-
* @return
|
|
109
|
+
* @return Array of entities with config matching kind.
|
|
110
110
|
*/
|
|
111
111
|
|
|
112
112
|
export function getEntitiesConfig(state, kind) {
|
|
@@ -118,11 +118,11 @@ 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
|
-
* @return
|
|
125
|
+
* @return Entity config
|
|
126
126
|
*/
|
|
127
127
|
|
|
128
128
|
export function getEntity(state, kind, name) {
|
|
@@ -135,11 +135,11 @@ 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
|
-
* @return
|
|
142
|
+
* @return Entity config
|
|
143
143
|
*/
|
|
144
144
|
|
|
145
145
|
export function getEntityConfig(state, kind, name) {
|
|
@@ -148,20 +148,38 @@ export function getEntityConfig(state, kind, name) {
|
|
|
148
148
|
name
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
|
+
/**
|
|
152
|
+
* GetEntityRecord is declared as an *interface*, but it actually describes
|
|
153
|
+
* the specifies the getEntityRecord *function* signature. It may seem unusual,
|
|
154
|
+
* but it's just how TypeScript implements function overloading.
|
|
155
|
+
*
|
|
156
|
+
* More accurately, GetEntityRecord distinguishes between two different signatures
|
|
157
|
+
* the getEntityRecord selector has:
|
|
158
|
+
*
|
|
159
|
+
* 1. When query._fields is not given, the returned type is EntityRecordOf< K, N, C >
|
|
160
|
+
* 2. When query._fields is given, the returned type is Partial<EntityRecordOf< K, N, C >>
|
|
161
|
+
*
|
|
162
|
+
* Unfortunately, due to a TypeScript limitation (https://github.com/microsoft/TypeScript/issues/23132)
|
|
163
|
+
* we can't use a single function signature with a return type such as:
|
|
164
|
+
*
|
|
165
|
+
* Fields extends undefined
|
|
166
|
+
* ? EntityRecordOf< K, N, C >
|
|
167
|
+
* : Partial< EntityRecordOf< K, N, C > >
|
|
168
|
+
*/
|
|
169
|
+
|
|
151
170
|
/**
|
|
152
171
|
* Returns the Entity's record object by key. Returns `null` if the value is not
|
|
153
172
|
* yet received, undefined if the value entity is known to not exist, or the
|
|
154
173
|
* entity object if it exists and is received.
|
|
155
174
|
*
|
|
156
|
-
* @param
|
|
157
|
-
* @param
|
|
158
|
-
* @param
|
|
159
|
-
* @param
|
|
160
|
-
* @param
|
|
175
|
+
* @param state State tree
|
|
176
|
+
* @param kind Entity kind.
|
|
177
|
+
* @param name Entity name.
|
|
178
|
+
* @param key Record's key
|
|
179
|
+
* @param query Optional query.
|
|
161
180
|
*
|
|
162
|
-
* @return
|
|
181
|
+
* @return Record.
|
|
163
182
|
*/
|
|
164
|
-
|
|
165
183
|
export const getEntityRecord = createSelector((state, kind, name, key, query) => {
|
|
166
184
|
var _query$context, _queriedState$items$c;
|
|
167
185
|
|
|
@@ -211,12 +229,12 @@ export const getEntityRecord = createSelector((state, kind, name, key, query) =>
|
|
|
211
229
|
/**
|
|
212
230
|
* 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.
|
|
213
231
|
*
|
|
214
|
-
* @param
|
|
215
|
-
* @param
|
|
216
|
-
* @param
|
|
217
|
-
* @param
|
|
232
|
+
* @param state State tree
|
|
233
|
+
* @param kind Entity kind.
|
|
234
|
+
* @param name Entity name.
|
|
235
|
+
* @param key Record's key
|
|
218
236
|
*
|
|
219
|
-
* @return
|
|
237
|
+
* @return Record.
|
|
220
238
|
*/
|
|
221
239
|
|
|
222
240
|
export function __experimentalGetEntityRecordNoResolver(state, kind, name, key) {
|
|
@@ -226,12 +244,12 @@ export function __experimentalGetEntityRecordNoResolver(state, kind, name, key)
|
|
|
226
244
|
* Returns the entity's record object by key,
|
|
227
245
|
* with its attributes mapped to their raw values.
|
|
228
246
|
*
|
|
229
|
-
* @param
|
|
230
|
-
* @param
|
|
231
|
-
* @param
|
|
232
|
-
* @param
|
|
247
|
+
* @param state State tree.
|
|
248
|
+
* @param kind Entity kind.
|
|
249
|
+
* @param name Entity name.
|
|
250
|
+
* @param key Record's key.
|
|
233
251
|
*
|
|
234
|
-
* @return
|
|
252
|
+
* @return Object with the entity's raw attributes.
|
|
235
253
|
*/
|
|
236
254
|
|
|
237
255
|
export const getRawEntityRecord = createSelector((state, kind, name, key) => {
|
|
@@ -258,29 +276,47 @@ export const getRawEntityRecord = createSelector((state, kind, name, key) => {
|
|
|
258
276
|
* Returns true if records have been received for the given set of parameters,
|
|
259
277
|
* or false otherwise.
|
|
260
278
|
*
|
|
261
|
-
* @param
|
|
262
|
-
* @param
|
|
263
|
-
* @param
|
|
264
|
-
* @param
|
|
279
|
+
* @param state State tree
|
|
280
|
+
* @param kind Entity kind.
|
|
281
|
+
* @param name Entity name.
|
|
282
|
+
* @param query Optional terms query.
|
|
265
283
|
*
|
|
266
|
-
* @return
|
|
284
|
+
* @return Whether entity records have been received.
|
|
267
285
|
*/
|
|
268
286
|
|
|
269
287
|
export function hasEntityRecords(state, kind, name, query) {
|
|
270
288
|
return Array.isArray(getEntityRecords(state, kind, name, query));
|
|
271
289
|
}
|
|
272
290
|
/**
|
|
273
|
-
*
|
|
291
|
+
* GetEntityRecord is declared as an *interface*, but it actually describes
|
|
292
|
+
* the specifies the getEntityRecord *function* signature. It may seem unusual,
|
|
293
|
+
* but it's just how TypeScript implements function overloading.
|
|
274
294
|
*
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
* @param {string} name Entity name.
|
|
278
|
-
* @param {?Object} query Optional terms query.
|
|
295
|
+
* More accurately, GetEntityRecord distinguishes between two different signatures
|
|
296
|
+
* the getEntityRecord selector has:
|
|
279
297
|
*
|
|
280
|
-
*
|
|
298
|
+
* 1. When query._fields is not given, the returned type is EntityRecordOf< K, N, C >[]
|
|
299
|
+
* 2. When query._fields is given, the returned type is Partial<EntityRecordOf< K, N, C >>[]
|
|
300
|
+
*
|
|
301
|
+
* Unfortunately, due to a TypeScript limitation (https://github.com/microsoft/TypeScript/issues/23132)
|
|
302
|
+
* we can't use a single function signature with a return type such as:
|
|
303
|
+
*
|
|
304
|
+
* Fields extends undefined
|
|
305
|
+
* ? EntityRecordOf< K, N, C >[]
|
|
306
|
+
* : Partial< EntityRecordOf< K, N, C > >[]
|
|
281
307
|
*/
|
|
282
308
|
|
|
283
|
-
|
|
309
|
+
/**
|
|
310
|
+
* Returns the Entity's records.
|
|
311
|
+
*
|
|
312
|
+
* @param state State tree
|
|
313
|
+
* @param kind Entity kind.
|
|
314
|
+
* @param name Entity name.
|
|
315
|
+
* @param query Optional terms query.
|
|
316
|
+
*
|
|
317
|
+
* @return Records.
|
|
318
|
+
*/
|
|
319
|
+
export const getEntityRecords = (state, kind, name, query) => {
|
|
284
320
|
// Queried data state is prepopulated for all known entities. If this is not
|
|
285
321
|
// assigned for the given parameters, then it is known to not exist.
|
|
286
322
|
const queriedState = get(state.entities.records, [kind, name, 'queriedData']);
|
|
@@ -290,15 +326,15 @@ export function getEntityRecords(state, kind, name, query) {
|
|
|
290
326
|
}
|
|
291
327
|
|
|
292
328
|
return getQueriedItems(queriedState, query);
|
|
293
|
-
}
|
|
329
|
+
};
|
|
330
|
+
|
|
294
331
|
/**
|
|
295
332
|
* Returns the list of dirty entity records.
|
|
296
333
|
*
|
|
297
|
-
* @param
|
|
334
|
+
* @param state State tree.
|
|
298
335
|
*
|
|
299
|
-
* @return
|
|
336
|
+
* @return The list of updated records
|
|
300
337
|
*/
|
|
301
|
-
|
|
302
338
|
export const __experimentalGetDirtyEntityRecords = createSelector(state => {
|
|
303
339
|
const {
|
|
304
340
|
entities: {
|
|
@@ -335,9 +371,9 @@ export const __experimentalGetDirtyEntityRecords = createSelector(state => {
|
|
|
335
371
|
/**
|
|
336
372
|
* Returns the list of entities currently being saved.
|
|
337
373
|
*
|
|
338
|
-
* @param
|
|
374
|
+
* @param state State tree.
|
|
339
375
|
*
|
|
340
|
-
* @return
|
|
376
|
+
* @return The list of records being saved.
|
|
341
377
|
*/
|
|
342
378
|
|
|
343
379
|
export const __experimentalGetEntitiesBeingSaved = createSelector(state => {
|
|
@@ -374,12 +410,12 @@ export const __experimentalGetEntitiesBeingSaved = createSelector(state => {
|
|
|
374
410
|
/**
|
|
375
411
|
* Returns the specified entity record's edits.
|
|
376
412
|
*
|
|
377
|
-
* @param
|
|
378
|
-
* @param
|
|
379
|
-
* @param
|
|
380
|
-
* @param
|
|
413
|
+
* @param state State tree.
|
|
414
|
+
* @param kind Entity kind.
|
|
415
|
+
* @param name Entity name.
|
|
416
|
+
* @param recordId Record ID.
|
|
381
417
|
*
|
|
382
|
-
* @return
|
|
418
|
+
* @return The entity record's edits.
|
|
383
419
|
*/
|
|
384
420
|
|
|
385
421
|
export function getEntityRecordEdits(state, kind, name, recordId) {
|
|
@@ -392,12 +428,12 @@ export function getEntityRecordEdits(state, kind, name, recordId) {
|
|
|
392
428
|
* are not considered for change detection.
|
|
393
429
|
* They are defined in the entity's config.
|
|
394
430
|
*
|
|
395
|
-
* @param
|
|
396
|
-
* @param
|
|
397
|
-
* @param
|
|
398
|
-
* @param
|
|
431
|
+
* @param state State tree.
|
|
432
|
+
* @param kind Entity kind.
|
|
433
|
+
* @param name Entity name.
|
|
434
|
+
* @param recordId Record ID.
|
|
399
435
|
*
|
|
400
|
-
* @return
|
|
436
|
+
* @return The entity record's non transient edits.
|
|
401
437
|
*/
|
|
402
438
|
|
|
403
439
|
export const getEntityRecordNonTransientEdits = createSelector((state, kind, name, recordId) => {
|
|
@@ -422,12 +458,12 @@ export const getEntityRecordNonTransientEdits = createSelector((state, kind, nam
|
|
|
422
458
|
* Returns true if the specified entity record has edits,
|
|
423
459
|
* and false otherwise.
|
|
424
460
|
*
|
|
425
|
-
* @param
|
|
426
|
-
* @param
|
|
427
|
-
* @param
|
|
428
|
-
* @param
|
|
461
|
+
* @param state State tree.
|
|
462
|
+
* @param kind Entity kind.
|
|
463
|
+
* @param name Entity name.
|
|
464
|
+
* @param recordId Record ID.
|
|
429
465
|
*
|
|
430
|
-
* @return
|
|
466
|
+
* @return Whether the entity record has edits or not.
|
|
431
467
|
*/
|
|
432
468
|
|
|
433
469
|
export function hasEditsForEntityRecord(state, kind, name, recordId) {
|
|
@@ -436,12 +472,12 @@ export function hasEditsForEntityRecord(state, kind, name, recordId) {
|
|
|
436
472
|
/**
|
|
437
473
|
* Returns the specified entity record, merged with its edits.
|
|
438
474
|
*
|
|
439
|
-
* @param
|
|
440
|
-
* @param
|
|
441
|
-
* @param
|
|
442
|
-
* @param
|
|
475
|
+
* @param state State tree.
|
|
476
|
+
* @param kind Entity kind.
|
|
477
|
+
* @param name Entity name.
|
|
478
|
+
* @param recordId Record ID.
|
|
443
479
|
*
|
|
444
|
-
* @return
|
|
480
|
+
* @return The entity record, merged with its edits.
|
|
445
481
|
*/
|
|
446
482
|
|
|
447
483
|
export const getEditedEntityRecord = createSelector((state, kind, name, recordId) => ({ ...getRawEntityRecord(state, kind, name, recordId),
|
|
@@ -455,12 +491,12 @@ export const getEditedEntityRecord = createSelector((state, kind, name, recordId
|
|
|
455
491
|
/**
|
|
456
492
|
* Returns true if the specified entity record is autosaving, and false otherwise.
|
|
457
493
|
*
|
|
458
|
-
* @param
|
|
459
|
-
* @param
|
|
460
|
-
* @param
|
|
461
|
-
* @param
|
|
494
|
+
* @param state State tree.
|
|
495
|
+
* @param kind Entity kind.
|
|
496
|
+
* @param name Entity name.
|
|
497
|
+
* @param recordId Record ID.
|
|
462
498
|
*
|
|
463
|
-
* @return
|
|
499
|
+
* @return Whether the entity record is autosaving or not.
|
|
464
500
|
*/
|
|
465
501
|
|
|
466
502
|
export function isAutosavingEntityRecord(state, kind, name, recordId) {
|
|
@@ -473,12 +509,12 @@ export function isAutosavingEntityRecord(state, kind, name, recordId) {
|
|
|
473
509
|
/**
|
|
474
510
|
* Returns true if the specified entity record is saving, and false otherwise.
|
|
475
511
|
*
|
|
476
|
-
* @param
|
|
477
|
-
* @param
|
|
478
|
-
* @param
|
|
479
|
-
* @param
|
|
512
|
+
* @param state State tree.
|
|
513
|
+
* @param kind Entity kind.
|
|
514
|
+
* @param name Entity name.
|
|
515
|
+
* @param recordId Record ID.
|
|
480
516
|
*
|
|
481
|
-
* @return
|
|
517
|
+
* @return Whether the entity record is saving or not.
|
|
482
518
|
*/
|
|
483
519
|
|
|
484
520
|
export function isSavingEntityRecord(state, kind, name, recordId) {
|
|
@@ -487,12 +523,12 @@ export function isSavingEntityRecord(state, kind, name, recordId) {
|
|
|
487
523
|
/**
|
|
488
524
|
* Returns true if the specified entity record is deleting, and false otherwise.
|
|
489
525
|
*
|
|
490
|
-
* @param
|
|
491
|
-
* @param
|
|
492
|
-
* @param
|
|
493
|
-
* @param
|
|
526
|
+
* @param state State tree.
|
|
527
|
+
* @param kind Entity kind.
|
|
528
|
+
* @param name Entity name.
|
|
529
|
+
* @param recordId Record ID.
|
|
494
530
|
*
|
|
495
|
-
* @return
|
|
531
|
+
* @return Whether the entity record is deleting or not.
|
|
496
532
|
*/
|
|
497
533
|
|
|
498
534
|
export function isDeletingEntityRecord(state, kind, name, recordId) {
|
|
@@ -501,12 +537,12 @@ export function isDeletingEntityRecord(state, kind, name, recordId) {
|
|
|
501
537
|
/**
|
|
502
538
|
* Returns the specified entity record's last save error.
|
|
503
539
|
*
|
|
504
|
-
* @param
|
|
505
|
-
* @param
|
|
506
|
-
* @param
|
|
507
|
-
* @param
|
|
540
|
+
* @param state State tree.
|
|
541
|
+
* @param kind Entity kind.
|
|
542
|
+
* @param name Entity name.
|
|
543
|
+
* @param recordId Record ID.
|
|
508
544
|
*
|
|
509
|
-
* @return
|
|
545
|
+
* @return The entity record's save error.
|
|
510
546
|
*/
|
|
511
547
|
|
|
512
548
|
export function getLastEntitySaveError(state, kind, name, recordId) {
|
|
@@ -515,12 +551,12 @@ export function getLastEntitySaveError(state, kind, name, recordId) {
|
|
|
515
551
|
/**
|
|
516
552
|
* Returns the specified entity record's last delete error.
|
|
517
553
|
*
|
|
518
|
-
* @param
|
|
519
|
-
* @param
|
|
520
|
-
* @param
|
|
521
|
-
* @param
|
|
554
|
+
* @param state State tree.
|
|
555
|
+
* @param kind Entity kind.
|
|
556
|
+
* @param name Entity name.
|
|
557
|
+
* @param recordId Record ID.
|
|
522
558
|
*
|
|
523
|
-
* @return
|
|
559
|
+
* @return The entity record's save error.
|
|
524
560
|
*/
|
|
525
561
|
|
|
526
562
|
export function getLastEntityDeleteError(state, kind, name, recordId) {
|
|
@@ -533,9 +569,9 @@ export function getLastEntityDeleteError(state, kind, name, recordId) {
|
|
|
533
569
|
* of the history stack we are at. 0 is the
|
|
534
570
|
* last edit, -1 is the second last, and so on.
|
|
535
571
|
*
|
|
536
|
-
* @param
|
|
572
|
+
* @param state State tree.
|
|
537
573
|
*
|
|
538
|
-
* @return
|
|
574
|
+
* @return The current undo offset.
|
|
539
575
|
*/
|
|
540
576
|
|
|
541
577
|
function getCurrentUndoOffset(state) {
|
|
@@ -545,9 +581,9 @@ function getCurrentUndoOffset(state) {
|
|
|
545
581
|
* Returns the previous edit from the current undo offset
|
|
546
582
|
* for the entity records edits history, if any.
|
|
547
583
|
*
|
|
548
|
-
* @param
|
|
584
|
+
* @param state State tree.
|
|
549
585
|
*
|
|
550
|
-
* @return
|
|
586
|
+
* @return The edit.
|
|
551
587
|
*/
|
|
552
588
|
|
|
553
589
|
|
|
@@ -558,9 +594,9 @@ export function getUndoEdit(state) {
|
|
|
558
594
|
* Returns the next edit from the current undo offset
|
|
559
595
|
* for the entity records edits history, if any.
|
|
560
596
|
*
|
|
561
|
-
* @param
|
|
597
|
+
* @param state State tree.
|
|
562
598
|
*
|
|
563
|
-
* @return
|
|
599
|
+
* @return The edit.
|
|
564
600
|
*/
|
|
565
601
|
|
|
566
602
|
export function getRedoEdit(state) {
|
|
@@ -570,9 +606,9 @@ export function getRedoEdit(state) {
|
|
|
570
606
|
* Returns true if there is a previous edit from the current undo offset
|
|
571
607
|
* for the entity records edits history, and false otherwise.
|
|
572
608
|
*
|
|
573
|
-
* @param
|
|
609
|
+
* @param state State tree.
|
|
574
610
|
*
|
|
575
|
-
* @return
|
|
611
|
+
* @return Whether there is a previous edit or not.
|
|
576
612
|
*/
|
|
577
613
|
|
|
578
614
|
export function hasUndo(state) {
|
|
@@ -582,9 +618,9 @@ export function hasUndo(state) {
|
|
|
582
618
|
* Returns true if there is a next edit from the current undo offset
|
|
583
619
|
* for the entity records edits history, and false otherwise.
|
|
584
620
|
*
|
|
585
|
-
* @param
|
|
621
|
+
* @param state State tree.
|
|
586
622
|
*
|
|
587
|
-
* @return
|
|
623
|
+
* @return Whether there is a next edit or not.
|
|
588
624
|
*/
|
|
589
625
|
|
|
590
626
|
export function hasRedo(state) {
|
|
@@ -593,9 +629,9 @@ export function hasRedo(state) {
|
|
|
593
629
|
/**
|
|
594
630
|
* Return the current theme.
|
|
595
631
|
*
|
|
596
|
-
* @param
|
|
632
|
+
* @param state Data state.
|
|
597
633
|
*
|
|
598
|
-
* @return
|
|
634
|
+
* @return The current theme.
|
|
599
635
|
*/
|
|
600
636
|
|
|
601
637
|
export function getCurrentTheme(state) {
|
|
@@ -604,9 +640,9 @@ export function getCurrentTheme(state) {
|
|
|
604
640
|
/**
|
|
605
641
|
* Return the ID of the current global styles object.
|
|
606
642
|
*
|
|
607
|
-
* @param
|
|
643
|
+
* @param state Data state.
|
|
608
644
|
*
|
|
609
|
-
* @return
|
|
645
|
+
* @return The current global styles ID.
|
|
610
646
|
*/
|
|
611
647
|
|
|
612
648
|
export function __experimentalGetCurrentGlobalStylesId(state) {
|
|
@@ -615,9 +651,9 @@ export function __experimentalGetCurrentGlobalStylesId(state) {
|
|
|
615
651
|
/**
|
|
616
652
|
* Return theme supports data in the index.
|
|
617
653
|
*
|
|
618
|
-
* @param
|
|
654
|
+
* @param state Data state.
|
|
619
655
|
*
|
|
620
|
-
* @return
|
|
656
|
+
* @return Index data.
|
|
621
657
|
*/
|
|
622
658
|
|
|
623
659
|
export function getThemeSupports(state) {
|
|
@@ -628,10 +664,10 @@ export function getThemeSupports(state) {
|
|
|
628
664
|
/**
|
|
629
665
|
* Returns the embed preview for the given URL.
|
|
630
666
|
*
|
|
631
|
-
* @param
|
|
632
|
-
* @param
|
|
667
|
+
* @param state Data state.
|
|
668
|
+
* @param url Embedded URL.
|
|
633
669
|
*
|
|
634
|
-
* @return
|
|
670
|
+
* @return Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API.
|
|
635
671
|
*/
|
|
636
672
|
|
|
637
673
|
export function getEmbedPreview(state, url) {
|
|
@@ -644,10 +680,10 @@ export function getEmbedPreview(state, url) {
|
|
|
644
680
|
* We need to be able to determine if a URL is embeddable or not, based on what we
|
|
645
681
|
* get back from the oEmbed preview API.
|
|
646
682
|
*
|
|
647
|
-
* @param
|
|
648
|
-
* @param
|
|
683
|
+
* @param state Data state.
|
|
684
|
+
* @param url Embedded URL.
|
|
649
685
|
*
|
|
650
|
-
* @return
|
|
686
|
+
* @return Is the preview for the URL an oEmbed link fallback.
|
|
651
687
|
*/
|
|
652
688
|
|
|
653
689
|
export function isPreviewEmbedFallback(state, url) {
|
|
@@ -669,12 +705,12 @@ export function isPreviewEmbedFallback(state, url) {
|
|
|
669
705
|
*
|
|
670
706
|
* https://developer.wordpress.org/rest-api/reference/
|
|
671
707
|
*
|
|
672
|
-
* @param
|
|
673
|
-
* @param
|
|
674
|
-
* @param
|
|
675
|
-
* @param
|
|
708
|
+
* @param state Data state.
|
|
709
|
+
* @param action Action to check. One of: 'create', 'read', 'update', 'delete'.
|
|
710
|
+
* @param resource REST resource to check, e.g. 'media' or 'posts'.
|
|
711
|
+
* @param id Optional ID of the rest resource to check.
|
|
676
712
|
*
|
|
677
|
-
* @return
|
|
713
|
+
* @return Whether or not the user can perform the action,
|
|
678
714
|
* or `undefined` if the OPTIONS request is still being made.
|
|
679
715
|
*/
|
|
680
716
|
|
|
@@ -690,11 +726,11 @@ export function canUser(state, action, resource, id) {
|
|
|
690
726
|
*
|
|
691
727
|
* https://developer.wordpress.org/rest-api/reference/
|
|
692
728
|
*
|
|
693
|
-
* @param
|
|
694
|
-
* @param
|
|
695
|
-
* @param
|
|
696
|
-
* @param
|
|
697
|
-
* @return
|
|
729
|
+
* @param state Data state.
|
|
730
|
+
* @param kind Entity kind.
|
|
731
|
+
* @param name Entity name.
|
|
732
|
+
* @param recordId Record's id.
|
|
733
|
+
* @return Whether or not the user can edit,
|
|
698
734
|
* or `undefined` if the OPTIONS request is still being made.
|
|
699
735
|
*/
|
|
700
736
|
|
|
@@ -714,11 +750,11 @@ export function canUserEditEntityRecord(state, kind, name, recordId) {
|
|
|
714
750
|
* May return multiple autosaves since the backend stores one autosave per
|
|
715
751
|
* author for each post.
|
|
716
752
|
*
|
|
717
|
-
* @param
|
|
718
|
-
* @param
|
|
719
|
-
* @param
|
|
753
|
+
* @param state State tree.
|
|
754
|
+
* @param postType The type of the parent post.
|
|
755
|
+
* @param postId The id of the parent post.
|
|
720
756
|
*
|
|
721
|
-
* @return
|
|
757
|
+
* @return An array of autosaves for the post, or undefined if there is none.
|
|
722
758
|
*/
|
|
723
759
|
|
|
724
760
|
export function getAutosaves(state, postType, postId) {
|
|
@@ -727,12 +763,12 @@ export function getAutosaves(state, postType, postId) {
|
|
|
727
763
|
/**
|
|
728
764
|
* Returns the autosave for the post and author.
|
|
729
765
|
*
|
|
730
|
-
* @param
|
|
731
|
-
* @param
|
|
732
|
-
* @param
|
|
733
|
-
* @param
|
|
766
|
+
* @param state State tree.
|
|
767
|
+
* @param postType The type of the parent post.
|
|
768
|
+
* @param postId The id of the parent post.
|
|
769
|
+
* @param authorId The id of the author.
|
|
734
770
|
*
|
|
735
|
-
* @return
|
|
771
|
+
* @return The autosave for the post and author.
|
|
736
772
|
*/
|
|
737
773
|
|
|
738
774
|
export function getAutosave(state, postType, postId, authorId) {
|
|
@@ -748,11 +784,11 @@ export function getAutosave(state, postType, postId, authorId) {
|
|
|
748
784
|
/**
|
|
749
785
|
* Returns true if the REST request for autosaves has completed.
|
|
750
786
|
*
|
|
751
|
-
* @param
|
|
752
|
-
* @param
|
|
753
|
-
* @param
|
|
787
|
+
* @param state State tree.
|
|
788
|
+
* @param postType The type of the parent post.
|
|
789
|
+
* @param postId The id of the parent post.
|
|
754
790
|
*
|
|
755
|
-
* @return
|
|
791
|
+
* @return True if the REST request was completed. False otherwise.
|
|
756
792
|
*/
|
|
757
793
|
|
|
758
794
|
export const hasFetchedAutosaves = createRegistrySelector(select => (state, postType, postId) => {
|
|
@@ -772,19 +808,20 @@ export const hasFetchedAutosaves = createRegistrySelector(select => (state, post
|
|
|
772
808
|
* );
|
|
773
809
|
* ```
|
|
774
810
|
*
|
|
775
|
-
* @param
|
|
811
|
+
* @param state Editor state.
|
|
776
812
|
*
|
|
777
|
-
* @return
|
|
813
|
+
* @return A value whose reference will change only when an edit occurs.
|
|
778
814
|
*/
|
|
779
815
|
|
|
780
|
-
export const getReferenceByDistinctEdits = createSelector(
|
|
816
|
+
export const getReferenceByDistinctEdits = createSelector( // This unused state argument is listed here for the documentation generating tool (docgen).
|
|
817
|
+
state => [], state => [state.undo.length, state.undo.offset, state.undo.flattenedUndo]);
|
|
781
818
|
/**
|
|
782
819
|
* Retrieve the frontend template used for a given link.
|
|
783
820
|
*
|
|
784
|
-
* @param
|
|
785
|
-
* @param
|
|
821
|
+
* @param state Editor state.
|
|
822
|
+
* @param link Link.
|
|
786
823
|
*
|
|
787
|
-
* @return
|
|
824
|
+
* @return The template record.
|
|
788
825
|
*/
|
|
789
826
|
|
|
790
827
|
export function __experimentalGetTemplateForLink(state, link) {
|
|
@@ -802,9 +839,9 @@ export function __experimentalGetTemplateForLink(state, link) {
|
|
|
802
839
|
/**
|
|
803
840
|
* Retrieve the current theme's base global styles
|
|
804
841
|
*
|
|
805
|
-
* @param
|
|
842
|
+
* @param state Editor state.
|
|
806
843
|
*
|
|
807
|
-
* @return
|
|
844
|
+
* @return The Global Styles object.
|
|
808
845
|
*/
|
|
809
846
|
|
|
810
847
|
export function __experimentalGetCurrentThemeBaseGlobalStyles(state) {
|
|
@@ -819,9 +856,9 @@ export function __experimentalGetCurrentThemeBaseGlobalStyles(state) {
|
|
|
819
856
|
/**
|
|
820
857
|
* Return the ID of the current global styles object.
|
|
821
858
|
*
|
|
822
|
-
* @param
|
|
859
|
+
* @param state Data state.
|
|
823
860
|
*
|
|
824
|
-
* @return
|
|
861
|
+
* @return The current global styles ID.
|
|
825
862
|
*/
|
|
826
863
|
|
|
827
864
|
export function __experimentalGetCurrentThemeGlobalStylesVariations(state) {
|
|
@@ -836,9 +873,9 @@ export function __experimentalGetCurrentThemeGlobalStylesVariations(state) {
|
|
|
836
873
|
/**
|
|
837
874
|
* Retrieve the list of registered block patterns.
|
|
838
875
|
*
|
|
839
|
-
* @param
|
|
876
|
+
* @param state Data state.
|
|
840
877
|
*
|
|
841
|
-
* @return
|
|
878
|
+
* @return Block pattern list.
|
|
842
879
|
*/
|
|
843
880
|
|
|
844
881
|
export function getBlockPatterns(state) {
|
|
@@ -847,9 +884,9 @@ export function getBlockPatterns(state) {
|
|
|
847
884
|
/**
|
|
848
885
|
* Retrieve the list of registered block pattern categories.
|
|
849
886
|
*
|
|
850
|
-
* @param
|
|
887
|
+
* @param state Data state.
|
|
851
888
|
*
|
|
852
|
-
* @return
|
|
889
|
+
* @return Block pattern category list.
|
|
853
890
|
*/
|
|
854
891
|
|
|
855
892
|
export function getBlockPatternCategories(state) {
|