@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/src/selectors.ts
CHANGED
|
@@ -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
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
@@ -36,6 +36,7 @@ export interface State {
|
|
|
36
36
|
themeBaseGlobalStyles: Record< string, Object >;
|
|
37
37
|
themeGlobalStyleVariations: Record< string, string >;
|
|
38
38
|
undo: UndoState;
|
|
39
|
+
userPermissions: Record< string, boolean >;
|
|
39
40
|
users: UserState;
|
|
40
41
|
}
|
|
41
42
|
|
|
@@ -46,9 +47,20 @@ interface EntitiesState {
|
|
|
46
47
|
records: Record< string, Record< string, EntityState< ET.EntityRecord > > >;
|
|
47
48
|
}
|
|
48
49
|
|
|
50
|
+
interface QueriedData {
|
|
51
|
+
items: Record< ET.Context, Record< number, ET.EntityRecord > >;
|
|
52
|
+
itemIsComplete: Record< ET.Context, Record< number, boolean > >;
|
|
53
|
+
queries: Record< ET.Context, Record< string, Array< number > > >;
|
|
54
|
+
}
|
|
55
|
+
|
|
49
56
|
interface EntityState< EntityRecord extends ET.EntityRecord > {
|
|
50
57
|
edits: Record< string, Partial< EntityRecord > >;
|
|
51
|
-
saving: Record<
|
|
58
|
+
saving: Record<
|
|
59
|
+
string,
|
|
60
|
+
Partial< { pending: boolean; isAutosave: boolean; error: Error } >
|
|
61
|
+
>;
|
|
62
|
+
deleting: Record< string, Partial< { pending: boolean; error: Error } > >;
|
|
63
|
+
queriedData: QueriedData;
|
|
52
64
|
}
|
|
53
65
|
|
|
54
66
|
interface EntityConfig {
|
|
@@ -86,8 +98,8 @@ const EMPTY_OBJECT = {};
|
|
|
86
98
|
* Returns true if a request is in progress for embed preview data, or false
|
|
87
99
|
* otherwise.
|
|
88
100
|
*
|
|
89
|
-
* @param
|
|
90
|
-
* @param
|
|
101
|
+
* @param state Data state.
|
|
102
|
+
* @param url URL the preview would be for.
|
|
91
103
|
*
|
|
92
104
|
* @return Whether a request is in progress for an embed preview.
|
|
93
105
|
*/
|
|
@@ -105,9 +117,9 @@ export const isRequestingEmbedPreview = createRegistrySelector(
|
|
|
105
117
|
*
|
|
106
118
|
* @deprecated since 11.3. Callers should use `select( 'core' ).getUsers({ who: 'authors' })` instead.
|
|
107
119
|
*
|
|
108
|
-
* @param
|
|
109
|
-
* @param
|
|
110
|
-
*
|
|
120
|
+
* @param state Data state.
|
|
121
|
+
* @param query Optional object of query parameters to
|
|
122
|
+
* include with request.
|
|
111
123
|
* @return Authors list.
|
|
112
124
|
*/
|
|
113
125
|
export function getAuthors(
|
|
@@ -129,7 +141,7 @@ export function getAuthors(
|
|
|
129
141
|
/**
|
|
130
142
|
* Returns the current user.
|
|
131
143
|
*
|
|
132
|
-
* @param
|
|
144
|
+
* @param state Data state.
|
|
133
145
|
*
|
|
134
146
|
* @return Current user object.
|
|
135
147
|
*/
|
|
@@ -140,8 +152,8 @@ export function getCurrentUser( state: State ): ET.User< 'edit' > {
|
|
|
140
152
|
/**
|
|
141
153
|
* Returns all the users returned by a query ID.
|
|
142
154
|
*
|
|
143
|
-
* @param
|
|
144
|
-
* @param
|
|
155
|
+
* @param state Data state.
|
|
156
|
+
* @param queryID Query ID.
|
|
145
157
|
*
|
|
146
158
|
* @return Users list.
|
|
147
159
|
*/
|
|
@@ -161,8 +173,8 @@ export const getUserQueryResults = createSelector(
|
|
|
161
173
|
* Returns the loaded entities for the given kind.
|
|
162
174
|
*
|
|
163
175
|
* @deprecated since WordPress 6.0. Use getEntitiesConfig instead
|
|
164
|
-
* @param
|
|
165
|
-
* @param
|
|
176
|
+
* @param state Data state.
|
|
177
|
+
* @param kind Entity kind.
|
|
166
178
|
*
|
|
167
179
|
* @return Array of entities with config matching kind.
|
|
168
180
|
*/
|
|
@@ -177,8 +189,8 @@ export function getEntitiesByKind( state: State, kind: string ): Array< any > {
|
|
|
177
189
|
/**
|
|
178
190
|
* Returns the loaded entities for the given kind.
|
|
179
191
|
*
|
|
180
|
-
* @param
|
|
181
|
-
* @param
|
|
192
|
+
* @param state Data state.
|
|
193
|
+
* @param kind Entity kind.
|
|
182
194
|
*
|
|
183
195
|
* @return Array of entities with config matching kind.
|
|
184
196
|
*/
|
|
@@ -190,9 +202,9 @@ export function getEntitiesConfig( state: State, kind: string ): Array< any > {
|
|
|
190
202
|
* Returns the entity config given its kind and name.
|
|
191
203
|
*
|
|
192
204
|
* @deprecated since WordPress 6.0. Use getEntityConfig instead
|
|
193
|
-
* @param
|
|
194
|
-
* @param
|
|
195
|
-
* @param
|
|
205
|
+
* @param state Data state.
|
|
206
|
+
* @param kind Entity kind.
|
|
207
|
+
* @param name Entity name.
|
|
196
208
|
*
|
|
197
209
|
* @return Entity config
|
|
198
210
|
*/
|
|
@@ -207,9 +219,9 @@ export function getEntity( state: State, kind: string, name: string ): any {
|
|
|
207
219
|
/**
|
|
208
220
|
* Returns the entity config given its kind and name.
|
|
209
221
|
*
|
|
210
|
-
* @param
|
|
211
|
-
* @param
|
|
212
|
-
* @param
|
|
222
|
+
* @param state Data state.
|
|
223
|
+
* @param kind Entity kind.
|
|
224
|
+
* @param name Entity name.
|
|
213
225
|
*
|
|
214
226
|
* @return Entity config
|
|
215
227
|
*/
|
|
@@ -277,12 +289,12 @@ export interface GetEntityRecord {
|
|
|
277
289
|
* yet received, undefined if the value entity is known to not exist, or the
|
|
278
290
|
* entity object if it exists and is received.
|
|
279
291
|
*
|
|
280
|
-
* @param
|
|
281
|
-
* @param
|
|
282
|
-
* @param
|
|
283
|
-
* @param
|
|
284
|
-
* @param
|
|
285
|
-
*
|
|
292
|
+
* @param state State tree
|
|
293
|
+
* @param kind Entity kind.
|
|
294
|
+
* @param name Entity name.
|
|
295
|
+
* @param key Record's key
|
|
296
|
+
* @param query Optional query. If requesting specific
|
|
297
|
+
* fields, fields must always include the ID.
|
|
286
298
|
*
|
|
287
299
|
* @return Record.
|
|
288
300
|
*/
|
|
@@ -298,11 +310,8 @@ export const getEntityRecord = createSelector(
|
|
|
298
310
|
key: EntityRecordKey,
|
|
299
311
|
query?: GetRecordsHttpQuery
|
|
300
312
|
): EntityRecord | undefined => {
|
|
301
|
-
const queriedState =
|
|
302
|
-
kind
|
|
303
|
-
name,
|
|
304
|
-
'queriedData',
|
|
305
|
-
] );
|
|
313
|
+
const queriedState =
|
|
314
|
+
state.entities.records?.[ kind ]?.[ name ]?.queriedData;
|
|
306
315
|
if ( ! queriedState ) {
|
|
307
316
|
return undefined;
|
|
308
317
|
}
|
|
@@ -323,7 +332,10 @@ export const getEntityRecord = createSelector(
|
|
|
323
332
|
const fields = getNormalizedCommaSeparable( query._fields ) ?? [];
|
|
324
333
|
for ( let f = 0; f < fields.length; f++ ) {
|
|
325
334
|
const field = fields[ f ].split( '.' );
|
|
326
|
-
|
|
335
|
+
let value = item;
|
|
336
|
+
field.forEach( ( fieldName ) => {
|
|
337
|
+
value = value[ fieldName ];
|
|
338
|
+
} );
|
|
327
339
|
set( filteredItem, field, value );
|
|
328
340
|
}
|
|
329
341
|
return filteredItem as EntityRecord;
|
|
@@ -334,22 +346,11 @@ export const getEntityRecord = createSelector(
|
|
|
334
346
|
( state: State, kind, name, recordId, query ) => {
|
|
335
347
|
const context = query?.context ?? 'default';
|
|
336
348
|
return [
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
context,
|
|
343
|
-
recordId,
|
|
344
|
-
] ),
|
|
345
|
-
get( state.entities.records, [
|
|
346
|
-
kind,
|
|
347
|
-
name,
|
|
348
|
-
'queriedData',
|
|
349
|
-
'itemIsComplete',
|
|
350
|
-
context,
|
|
351
|
-
recordId,
|
|
352
|
-
] ),
|
|
349
|
+
state.entities.records?.[ kind ]?.[ name ]?.queriedData?.items[
|
|
350
|
+
context
|
|
351
|
+
]?.[ recordId ],
|
|
352
|
+
state.entities.records?.[ kind ]?.[ name ]?.queriedData
|
|
353
|
+
?.itemIsComplete[ context ]?.[ recordId ],
|
|
353
354
|
];
|
|
354
355
|
}
|
|
355
356
|
) as GetEntityRecord;
|
|
@@ -357,10 +358,10 @@ export const getEntityRecord = createSelector(
|
|
|
357
358
|
/**
|
|
358
359
|
* 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.
|
|
359
360
|
*
|
|
360
|
-
* @param
|
|
361
|
-
* @param
|
|
362
|
-
* @param
|
|
363
|
-
* @param
|
|
361
|
+
* @param state State tree
|
|
362
|
+
* @param kind Entity kind.
|
|
363
|
+
* @param name Entity name.
|
|
364
|
+
* @param key Record's key
|
|
364
365
|
*
|
|
365
366
|
* @return Record.
|
|
366
367
|
*/
|
|
@@ -374,10 +375,10 @@ export function __experimentalGetEntityRecordNoResolver<
|
|
|
374
375
|
* Returns the entity's record object by key,
|
|
375
376
|
* with its attributes mapped to their raw values.
|
|
376
377
|
*
|
|
377
|
-
* @param
|
|
378
|
-
* @param
|
|
379
|
-
* @param
|
|
380
|
-
* @param
|
|
378
|
+
* @param state State tree.
|
|
379
|
+
* @param kind Entity kind.
|
|
380
|
+
* @param name Entity name.
|
|
381
|
+
* @param key Record's key.
|
|
381
382
|
*
|
|
382
383
|
* @return Object with the entity's raw attributes.
|
|
383
384
|
*/
|
|
@@ -403,11 +404,7 @@ export const getRawEntityRecord = createSelector(
|
|
|
403
404
|
// Because edits are the "raw" attribute values,
|
|
404
405
|
// we return those from record selectors to make rendering,
|
|
405
406
|
// comparisons, and joins with edits easier.
|
|
406
|
-
accumulator[ _key ] =
|
|
407
|
-
record[ _key ],
|
|
408
|
-
'raw',
|
|
409
|
-
record[ _key ]
|
|
410
|
-
);
|
|
407
|
+
accumulator[ _key ] = record[ _key ]?.raw ?? record[ _key ];
|
|
411
408
|
} else {
|
|
412
409
|
accumulator[ _key ] = record[ _key ];
|
|
413
410
|
}
|
|
@@ -425,22 +422,11 @@ export const getRawEntityRecord = createSelector(
|
|
|
425
422
|
const context = query?.context ?? 'default';
|
|
426
423
|
return [
|
|
427
424
|
state.entities.config,
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
context,
|
|
434
|
-
recordId,
|
|
435
|
-
] ),
|
|
436
|
-
get( state.entities.records, [
|
|
437
|
-
kind,
|
|
438
|
-
name,
|
|
439
|
-
'queriedData',
|
|
440
|
-
'itemIsComplete',
|
|
441
|
-
context,
|
|
442
|
-
recordId,
|
|
443
|
-
] ),
|
|
425
|
+
state.entities.records?.[ kind ]?.[ name ]?.queriedData?.items[
|
|
426
|
+
context
|
|
427
|
+
]?.[ recordId ],
|
|
428
|
+
state.entities.records?.[ kind ]?.[ name ]?.queriedData
|
|
429
|
+
?.itemIsComplete[ context ]?.[ recordId ],
|
|
444
430
|
];
|
|
445
431
|
}
|
|
446
432
|
);
|
|
@@ -449,10 +435,10 @@ export const getRawEntityRecord = createSelector(
|
|
|
449
435
|
* Returns true if records have been received for the given set of parameters,
|
|
450
436
|
* or false otherwise.
|
|
451
437
|
*
|
|
452
|
-
* @param
|
|
453
|
-
* @param
|
|
454
|
-
* @param
|
|
455
|
-
* @param
|
|
438
|
+
* @param state State tree
|
|
439
|
+
* @param kind Entity kind.
|
|
440
|
+
* @param name Entity name.
|
|
441
|
+
* @param query Optional terms query.
|
|
456
442
|
*
|
|
457
443
|
* @return Whether entity records have been received.
|
|
458
444
|
*/
|
|
@@ -499,11 +485,11 @@ export interface GetEntityRecords {
|
|
|
499
485
|
/**
|
|
500
486
|
* Returns the Entity's records.
|
|
501
487
|
*
|
|
502
|
-
* @param
|
|
503
|
-
* @param
|
|
504
|
-
* @param
|
|
505
|
-
* @param
|
|
506
|
-
*
|
|
488
|
+
* @param state State tree
|
|
489
|
+
* @param kind Entity kind.
|
|
490
|
+
* @param name Entity name.
|
|
491
|
+
* @param query Optional terms query. If requesting specific
|
|
492
|
+
* fields, fields must always include the ID.
|
|
507
493
|
*
|
|
508
494
|
* @return Records.
|
|
509
495
|
*/
|
|
@@ -519,11 +505,8 @@ export const getEntityRecords = ( <
|
|
|
519
505
|
): EntityRecord[] | null => {
|
|
520
506
|
// Queried data state is prepopulated for all known entities. If this is not
|
|
521
507
|
// assigned for the given parameters, then it is known to not exist.
|
|
522
|
-
const queriedState =
|
|
523
|
-
kind
|
|
524
|
-
name,
|
|
525
|
-
'queriedData',
|
|
526
|
-
] );
|
|
508
|
+
const queriedState =
|
|
509
|
+
state.entities.records?.[ kind ]?.[ name ]?.queriedData;
|
|
527
510
|
if ( ! queriedState ) {
|
|
528
511
|
return null;
|
|
529
512
|
}
|
|
@@ -539,7 +522,7 @@ type DirtyEntityRecord = {
|
|
|
539
522
|
/**
|
|
540
523
|
* Returns the list of dirty entity records.
|
|
541
524
|
*
|
|
542
|
-
* @param
|
|
525
|
+
* @param state State tree.
|
|
543
526
|
*
|
|
544
527
|
* @return The list of updated records
|
|
545
528
|
*/
|
|
@@ -596,7 +579,7 @@ export const __experimentalGetDirtyEntityRecords = createSelector(
|
|
|
596
579
|
/**
|
|
597
580
|
* Returns the list of entities currently being saved.
|
|
598
581
|
*
|
|
599
|
-
* @param
|
|
582
|
+
* @param state State tree.
|
|
600
583
|
*
|
|
601
584
|
* @return The list of records being saved.
|
|
602
585
|
*/
|
|
@@ -648,10 +631,10 @@ export const __experimentalGetEntitiesBeingSaved = createSelector(
|
|
|
648
631
|
/**
|
|
649
632
|
* Returns the specified entity record's edits.
|
|
650
633
|
*
|
|
651
|
-
* @param
|
|
652
|
-
* @param
|
|
653
|
-
* @param
|
|
654
|
-
* @param
|
|
634
|
+
* @param state State tree.
|
|
635
|
+
* @param kind Entity kind.
|
|
636
|
+
* @param name Entity name.
|
|
637
|
+
* @param recordId Record ID.
|
|
655
638
|
*
|
|
656
639
|
* @return The entity record's edits.
|
|
657
640
|
*/
|
|
@@ -661,12 +644,9 @@ export function getEntityRecordEdits(
|
|
|
661
644
|
name: string,
|
|
662
645
|
recordId: EntityRecordKey
|
|
663
646
|
): Optional< any > {
|
|
664
|
-
return
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
'edits',
|
|
668
|
-
recordId as string | number,
|
|
669
|
-
] );
|
|
647
|
+
return state.entities.records?.[ kind ]?.[ name ]?.edits?.[
|
|
648
|
+
recordId as string | number
|
|
649
|
+
];
|
|
670
650
|
}
|
|
671
651
|
|
|
672
652
|
/**
|
|
@@ -676,10 +656,10 @@ export function getEntityRecordEdits(
|
|
|
676
656
|
* are not considered for change detection.
|
|
677
657
|
* They are defined in the entity's config.
|
|
678
658
|
*
|
|
679
|
-
* @param
|
|
680
|
-
* @param
|
|
681
|
-
* @param
|
|
682
|
-
* @param
|
|
659
|
+
* @param state State tree.
|
|
660
|
+
* @param kind Entity kind.
|
|
661
|
+
* @param name Entity name.
|
|
662
|
+
* @param recordId Record ID.
|
|
683
663
|
*
|
|
684
664
|
* @return The entity record's non transient edits.
|
|
685
665
|
*/
|
|
@@ -704,7 +684,7 @@ export const getEntityRecordNonTransientEdits = createSelector(
|
|
|
704
684
|
},
|
|
705
685
|
( state: State, kind: string, name: string, recordId: EntityRecordKey ) => [
|
|
706
686
|
state.entities.config,
|
|
707
|
-
|
|
687
|
+
state.entities.records?.[ kind ]?.[ name ]?.edits?.[ recordId ],
|
|
708
688
|
]
|
|
709
689
|
);
|
|
710
690
|
|
|
@@ -712,10 +692,10 @@ export const getEntityRecordNonTransientEdits = createSelector(
|
|
|
712
692
|
* Returns true if the specified entity record has edits,
|
|
713
693
|
* and false otherwise.
|
|
714
694
|
*
|
|
715
|
-
* @param
|
|
716
|
-
* @param
|
|
717
|
-
* @param
|
|
718
|
-
* @param
|
|
695
|
+
* @param state State tree.
|
|
696
|
+
* @param kind Entity kind.
|
|
697
|
+
* @param name Entity name.
|
|
698
|
+
* @param recordId Record ID.
|
|
719
699
|
*
|
|
720
700
|
* @return Whether the entity record has edits or not.
|
|
721
701
|
*/
|
|
@@ -736,10 +716,10 @@ export function hasEditsForEntityRecord(
|
|
|
736
716
|
/**
|
|
737
717
|
* Returns the specified entity record, merged with its edits.
|
|
738
718
|
*
|
|
739
|
-
* @param
|
|
740
|
-
* @param
|
|
741
|
-
* @param
|
|
742
|
-
* @param
|
|
719
|
+
* @param state State tree.
|
|
720
|
+
* @param kind Entity kind.
|
|
721
|
+
* @param name Entity name.
|
|
722
|
+
* @param recordId Record ID.
|
|
743
723
|
*
|
|
744
724
|
* @return The entity record, merged with its edits.
|
|
745
725
|
*/
|
|
@@ -763,23 +743,12 @@ export const getEditedEntityRecord = createSelector(
|
|
|
763
743
|
const context = query?.context ?? 'default';
|
|
764
744
|
return [
|
|
765
745
|
state.entities.config,
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
recordId,
|
|
773
|
-
] ),
|
|
774
|
-
get( state.entities.records, [
|
|
775
|
-
kind,
|
|
776
|
-
name,
|
|
777
|
-
'queriedData',
|
|
778
|
-
'itemIsComplete',
|
|
779
|
-
context,
|
|
780
|
-
recordId,
|
|
781
|
-
] ),
|
|
782
|
-
get( state.entities.records, [ kind, name, 'edits', recordId ] ),
|
|
746
|
+
state.entities.records?.[ kind ]?.[ name ]?.queriedData.items[
|
|
747
|
+
context
|
|
748
|
+
]?.[ recordId ],
|
|
749
|
+
state.entities.records?.[ kind ]?.[ name ]?.queriedData
|
|
750
|
+
.itemIsComplete[ context ]?.[ recordId ],
|
|
751
|
+
state.entities.records?.[ kind ]?.[ name ]?.edits?.[ recordId ],
|
|
783
752
|
];
|
|
784
753
|
}
|
|
785
754
|
);
|
|
@@ -787,10 +756,10 @@ export const getEditedEntityRecord = createSelector(
|
|
|
787
756
|
/**
|
|
788
757
|
* Returns true if the specified entity record is autosaving, and false otherwise.
|
|
789
758
|
*
|
|
790
|
-
* @param
|
|
791
|
-
* @param
|
|
792
|
-
* @param
|
|
793
|
-
* @param
|
|
759
|
+
* @param state State tree.
|
|
760
|
+
* @param kind Entity kind.
|
|
761
|
+
* @param name Entity name.
|
|
762
|
+
* @param recordId Record ID.
|
|
794
763
|
*
|
|
795
764
|
* @return Whether the entity record is autosaving or not.
|
|
796
765
|
*/
|
|
@@ -800,21 +769,18 @@ export function isAutosavingEntityRecord(
|
|
|
800
769
|
name: string,
|
|
801
770
|
recordId: EntityRecordKey
|
|
802
771
|
): boolean {
|
|
803
|
-
const { pending, isAutosave } =
|
|
804
|
-
state.entities.records
|
|
805
|
-
[ kind, name, 'saving', recordId ],
|
|
806
|
-
{}
|
|
807
|
-
);
|
|
772
|
+
const { pending, isAutosave } =
|
|
773
|
+
state.entities.records?.[ kind ]?.[ name ]?.saving?.[ recordId ] ?? {};
|
|
808
774
|
return Boolean( pending && isAutosave );
|
|
809
775
|
}
|
|
810
776
|
|
|
811
777
|
/**
|
|
812
778
|
* Returns true if the specified entity record is saving, and false otherwise.
|
|
813
779
|
*
|
|
814
|
-
* @param
|
|
815
|
-
* @param
|
|
816
|
-
* @param
|
|
817
|
-
* @param
|
|
780
|
+
* @param state State tree.
|
|
781
|
+
* @param kind Entity kind.
|
|
782
|
+
* @param name Entity name.
|
|
783
|
+
* @param recordId Record ID.
|
|
818
784
|
*
|
|
819
785
|
* @return Whether the entity record is saving or not.
|
|
820
786
|
*/
|
|
@@ -824,20 +790,20 @@ export function isSavingEntityRecord(
|
|
|
824
790
|
name: string,
|
|
825
791
|
recordId: EntityRecordKey
|
|
826
792
|
): boolean {
|
|
827
|
-
return
|
|
828
|
-
state.entities.records
|
|
829
|
-
|
|
830
|
-
false
|
|
793
|
+
return (
|
|
794
|
+
state.entities.records?.[ kind ]?.[ name ]?.saving?.[
|
|
795
|
+
recordId as EntityRecordKey
|
|
796
|
+
]?.pending ?? false
|
|
831
797
|
);
|
|
832
798
|
}
|
|
833
799
|
|
|
834
800
|
/**
|
|
835
801
|
* Returns true if the specified entity record is deleting, and false otherwise.
|
|
836
802
|
*
|
|
837
|
-
* @param
|
|
838
|
-
* @param
|
|
839
|
-
* @param
|
|
840
|
-
* @param
|
|
803
|
+
* @param state State tree.
|
|
804
|
+
* @param kind Entity kind.
|
|
805
|
+
* @param name Entity name.
|
|
806
|
+
* @param recordId Record ID.
|
|
841
807
|
*
|
|
842
808
|
* @return Whether the entity record is deleting or not.
|
|
843
809
|
*/
|
|
@@ -847,20 +813,20 @@ export function isDeletingEntityRecord(
|
|
|
847
813
|
name: string,
|
|
848
814
|
recordId: EntityRecordKey
|
|
849
815
|
): boolean {
|
|
850
|
-
return
|
|
851
|
-
state.entities.records
|
|
852
|
-
|
|
853
|
-
false
|
|
816
|
+
return (
|
|
817
|
+
state.entities.records?.[ kind ]?.[ name ]?.deleting?.[
|
|
818
|
+
recordId as EntityRecordKey
|
|
819
|
+
]?.pending ?? false
|
|
854
820
|
);
|
|
855
821
|
}
|
|
856
822
|
|
|
857
823
|
/**
|
|
858
824
|
* Returns the specified entity record's last save error.
|
|
859
825
|
*
|
|
860
|
-
* @param
|
|
861
|
-
* @param
|
|
862
|
-
* @param
|
|
863
|
-
* @param
|
|
826
|
+
* @param state State tree.
|
|
827
|
+
* @param kind Entity kind.
|
|
828
|
+
* @param name Entity name.
|
|
829
|
+
* @param recordId Record ID.
|
|
864
830
|
*
|
|
865
831
|
* @return The entity record's save error.
|
|
866
832
|
*/
|
|
@@ -870,22 +836,17 @@ export function getLastEntitySaveError(
|
|
|
870
836
|
name: string,
|
|
871
837
|
recordId: EntityRecordKey
|
|
872
838
|
): any {
|
|
873
|
-
return
|
|
874
|
-
|
|
875
|
-
name,
|
|
876
|
-
'saving',
|
|
877
|
-
recordId,
|
|
878
|
-
'error',
|
|
879
|
-
] );
|
|
839
|
+
return state.entities.records?.[ kind ]?.[ name ]?.saving?.[ recordId ]
|
|
840
|
+
?.error;
|
|
880
841
|
}
|
|
881
842
|
|
|
882
843
|
/**
|
|
883
844
|
* Returns the specified entity record's last delete error.
|
|
884
845
|
*
|
|
885
|
-
* @param
|
|
886
|
-
* @param
|
|
887
|
-
* @param
|
|
888
|
-
* @param
|
|
846
|
+
* @param state State tree.
|
|
847
|
+
* @param kind Entity kind.
|
|
848
|
+
* @param name Entity name.
|
|
849
|
+
* @param recordId Record ID.
|
|
889
850
|
*
|
|
890
851
|
* @return The entity record's save error.
|
|
891
852
|
*/
|
|
@@ -895,13 +856,8 @@ export function getLastEntityDeleteError(
|
|
|
895
856
|
name: string,
|
|
896
857
|
recordId: EntityRecordKey
|
|
897
858
|
): any {
|
|
898
|
-
return
|
|
899
|
-
|
|
900
|
-
name,
|
|
901
|
-
'deleting',
|
|
902
|
-
recordId,
|
|
903
|
-
'error',
|
|
904
|
-
] );
|
|
859
|
+
return state.entities.records?.[ kind ]?.[ name ]?.deleting?.[ recordId ]
|
|
860
|
+
?.error;
|
|
905
861
|
}
|
|
906
862
|
|
|
907
863
|
/**
|
|
@@ -911,7 +867,7 @@ export function getLastEntityDeleteError(
|
|
|
911
867
|
* of the history stack we are at. 0 is the
|
|
912
868
|
* last edit, -1 is the second last, and so on.
|
|
913
869
|
*
|
|
914
|
-
* @param
|
|
870
|
+
* @param state State tree.
|
|
915
871
|
*
|
|
916
872
|
* @return The current undo offset.
|
|
917
873
|
*/
|
|
@@ -923,7 +879,7 @@ function getCurrentUndoOffset( state: State ): number {
|
|
|
923
879
|
* Returns the previous edit from the current undo offset
|
|
924
880
|
* for the entity records edits history, if any.
|
|
925
881
|
*
|
|
926
|
-
* @param
|
|
882
|
+
* @param state State tree.
|
|
927
883
|
*
|
|
928
884
|
* @return The edit.
|
|
929
885
|
*/
|
|
@@ -935,7 +891,7 @@ export function getUndoEdit( state: State ): Optional< any > {
|
|
|
935
891
|
* Returns the next edit from the current undo offset
|
|
936
892
|
* for the entity records edits history, if any.
|
|
937
893
|
*
|
|
938
|
-
* @param
|
|
894
|
+
* @param state State tree.
|
|
939
895
|
*
|
|
940
896
|
* @return The edit.
|
|
941
897
|
*/
|
|
@@ -947,7 +903,7 @@ export function getRedoEdit( state: State ): Optional< any > {
|
|
|
947
903
|
* Returns true if there is a previous edit from the current undo offset
|
|
948
904
|
* for the entity records edits history, and false otherwise.
|
|
949
905
|
*
|
|
950
|
-
* @param
|
|
906
|
+
* @param state State tree.
|
|
951
907
|
*
|
|
952
908
|
* @return Whether there is a previous edit or not.
|
|
953
909
|
*/
|
|
@@ -959,7 +915,7 @@ export function hasUndo( state: State ): boolean {
|
|
|
959
915
|
* Returns true if there is a next edit from the current undo offset
|
|
960
916
|
* for the entity records edits history, and false otherwise.
|
|
961
917
|
*
|
|
962
|
-
* @param
|
|
918
|
+
* @param state State tree.
|
|
963
919
|
*
|
|
964
920
|
* @return Whether there is a next edit or not.
|
|
965
921
|
*/
|
|
@@ -970,7 +926,7 @@ export function hasRedo( state: State ): boolean {
|
|
|
970
926
|
/**
|
|
971
927
|
* Return the current theme.
|
|
972
928
|
*
|
|
973
|
-
* @param
|
|
929
|
+
* @param state Data state.
|
|
974
930
|
*
|
|
975
931
|
* @return The current theme.
|
|
976
932
|
*/
|
|
@@ -981,7 +937,7 @@ export function getCurrentTheme( state: State ): any {
|
|
|
981
937
|
/**
|
|
982
938
|
* Return the ID of the current global styles object.
|
|
983
939
|
*
|
|
984
|
-
* @param
|
|
940
|
+
* @param state Data state.
|
|
985
941
|
*
|
|
986
942
|
* @return The current global styles ID.
|
|
987
943
|
*/
|
|
@@ -992,7 +948,7 @@ export function __experimentalGetCurrentGlobalStylesId( state: State ): string {
|
|
|
992
948
|
/**
|
|
993
949
|
* Return theme supports data in the index.
|
|
994
950
|
*
|
|
995
|
-
* @param
|
|
951
|
+
* @param state Data state.
|
|
996
952
|
*
|
|
997
953
|
* @return Index data.
|
|
998
954
|
*/
|
|
@@ -1003,8 +959,8 @@ export function getThemeSupports( state: State ): any {
|
|
|
1003
959
|
/**
|
|
1004
960
|
* Returns the embed preview for the given URL.
|
|
1005
961
|
*
|
|
1006
|
-
* @param
|
|
1007
|
-
* @param
|
|
962
|
+
* @param state Data state.
|
|
963
|
+
* @param url Embedded URL.
|
|
1008
964
|
*
|
|
1009
965
|
* @return Undefined if the preview has not been fetched, otherwise, the preview fetched from the embed preview API.
|
|
1010
966
|
*/
|
|
@@ -1019,8 +975,8 @@ export function getEmbedPreview( state: State, url: string ): any {
|
|
|
1019
975
|
* We need to be able to determine if a URL is embeddable or not, based on what we
|
|
1020
976
|
* get back from the oEmbed preview API.
|
|
1021
977
|
*
|
|
1022
|
-
* @param
|
|
1023
|
-
* @param
|
|
978
|
+
* @param state Data state.
|
|
979
|
+
* @param url Embedded URL.
|
|
1024
980
|
*
|
|
1025
981
|
* @return Is the preview for the URL an oEmbed link fallback.
|
|
1026
982
|
*/
|
|
@@ -1042,10 +998,10 @@ export function isPreviewEmbedFallback( state: State, url: string ): boolean {
|
|
|
1042
998
|
*
|
|
1043
999
|
* https://developer.wordpress.org/rest-api/reference/
|
|
1044
1000
|
*
|
|
1045
|
-
* @param
|
|
1046
|
-
* @param
|
|
1047
|
-
* @param
|
|
1048
|
-
* @param
|
|
1001
|
+
* @param state Data state.
|
|
1002
|
+
* @param action Action to check. One of: 'create', 'read', 'update', 'delete'.
|
|
1003
|
+
* @param resource REST resource to check, e.g. 'media' or 'posts'.
|
|
1004
|
+
* @param id Optional ID of the rest resource to check.
|
|
1049
1005
|
*
|
|
1050
1006
|
* @return Whether or not the user can perform the action,
|
|
1051
1007
|
* or `undefined` if the OPTIONS request is still being made.
|
|
@@ -1057,7 +1013,7 @@ export function canUser(
|
|
|
1057
1013
|
id?: EntityRecordKey
|
|
1058
1014
|
): boolean | undefined {
|
|
1059
1015
|
const key = [ action, resource, id ].filter( Boolean ).join( '/' );
|
|
1060
|
-
return
|
|
1016
|
+
return state.userPermissions[ key ];
|
|
1061
1017
|
}
|
|
1062
1018
|
|
|
1063
1019
|
/**
|
|
@@ -1068,10 +1024,10 @@ export function canUser(
|
|
|
1068
1024
|
*
|
|
1069
1025
|
* https://developer.wordpress.org/rest-api/reference/
|
|
1070
1026
|
*
|
|
1071
|
-
* @param
|
|
1072
|
-
* @param
|
|
1073
|
-
* @param
|
|
1074
|
-
* @param
|
|
1027
|
+
* @param state Data state.
|
|
1028
|
+
* @param kind Entity kind.
|
|
1029
|
+
* @param name Entity name.
|
|
1030
|
+
* @param recordId Record's id.
|
|
1075
1031
|
* @return Whether or not the user can edit,
|
|
1076
1032
|
* or `undefined` if the OPTIONS request is still being made.
|
|
1077
1033
|
*/
|
|
@@ -1096,9 +1052,9 @@ export function canUserEditEntityRecord(
|
|
|
1096
1052
|
* May return multiple autosaves since the backend stores one autosave per
|
|
1097
1053
|
* author for each post.
|
|
1098
1054
|
*
|
|
1099
|
-
* @param
|
|
1100
|
-
* @param
|
|
1101
|
-
* @param
|
|
1055
|
+
* @param state State tree.
|
|
1056
|
+
* @param postType The type of the parent post.
|
|
1057
|
+
* @param postId The id of the parent post.
|
|
1102
1058
|
*
|
|
1103
1059
|
* @return An array of autosaves for the post, or undefined if there is none.
|
|
1104
1060
|
*/
|
|
@@ -1113,10 +1069,10 @@ export function getAutosaves(
|
|
|
1113
1069
|
/**
|
|
1114
1070
|
* Returns the autosave for the post and author.
|
|
1115
1071
|
*
|
|
1116
|
-
* @param
|
|
1117
|
-
* @param
|
|
1118
|
-
* @param
|
|
1119
|
-
* @param
|
|
1072
|
+
* @param state State tree.
|
|
1073
|
+
* @param postType The type of the parent post.
|
|
1074
|
+
* @param postId The id of the parent post.
|
|
1075
|
+
* @param authorId The id of the author.
|
|
1120
1076
|
*
|
|
1121
1077
|
* @return The autosave for the post and author.
|
|
1122
1078
|
*/
|
|
@@ -1140,9 +1096,9 @@ export function getAutosave< EntityRecord extends ET.EntityRecord< any > >(
|
|
|
1140
1096
|
/**
|
|
1141
1097
|
* Returns true if the REST request for autosaves has completed.
|
|
1142
1098
|
*
|
|
1143
|
-
* @param
|
|
1144
|
-
* @param
|
|
1145
|
-
* @param
|
|
1099
|
+
* @param state State tree.
|
|
1100
|
+
* @param postType The type of the parent post.
|
|
1101
|
+
* @param postId The id of the parent post.
|
|
1146
1102
|
*
|
|
1147
1103
|
* @return True if the REST request was completed. False otherwise.
|
|
1148
1104
|
*/
|
|
@@ -1174,7 +1130,7 @@ export const hasFetchedAutosaves = createRegistrySelector(
|
|
|
1174
1130
|
* );
|
|
1175
1131
|
* ```
|
|
1176
1132
|
*
|
|
1177
|
-
* @param
|
|
1133
|
+
* @param state Editor state.
|
|
1178
1134
|
*
|
|
1179
1135
|
* @return A value whose reference will change only when an edit occurs.
|
|
1180
1136
|
*/
|
|
@@ -1191,8 +1147,8 @@ export const getReferenceByDistinctEdits = createSelector(
|
|
|
1191
1147
|
/**
|
|
1192
1148
|
* Retrieve the frontend template used for a given link.
|
|
1193
1149
|
*
|
|
1194
|
-
* @param
|
|
1195
|
-
* @param
|
|
1150
|
+
* @param state Editor state.
|
|
1151
|
+
* @param link Link.
|
|
1196
1152
|
*
|
|
1197
1153
|
* @return The template record.
|
|
1198
1154
|
*/
|
|
@@ -1223,7 +1179,7 @@ export function __experimentalGetTemplateForLink(
|
|
|
1223
1179
|
/**
|
|
1224
1180
|
* Retrieve the current theme's base global styles
|
|
1225
1181
|
*
|
|
1226
|
-
* @param
|
|
1182
|
+
* @param state Editor state.
|
|
1227
1183
|
*
|
|
1228
1184
|
* @return The Global Styles object.
|
|
1229
1185
|
*/
|
|
@@ -1240,7 +1196,7 @@ export function __experimentalGetCurrentThemeBaseGlobalStyles(
|
|
|
1240
1196
|
/**
|
|
1241
1197
|
* Return the ID of the current global styles object.
|
|
1242
1198
|
*
|
|
1243
|
-
* @param
|
|
1199
|
+
* @param state Data state.
|
|
1244
1200
|
*
|
|
1245
1201
|
* @return The current global styles ID.
|
|
1246
1202
|
*/
|
|
@@ -1257,7 +1213,7 @@ export function __experimentalGetCurrentThemeGlobalStylesVariations(
|
|
|
1257
1213
|
/**
|
|
1258
1214
|
* Retrieve the list of registered block patterns.
|
|
1259
1215
|
*
|
|
1260
|
-
* @param
|
|
1216
|
+
* @param state Data state.
|
|
1261
1217
|
*
|
|
1262
1218
|
* @return Block pattern list.
|
|
1263
1219
|
*/
|
|
@@ -1268,7 +1224,7 @@ export function getBlockPatterns( state: State ): Array< any > {
|
|
|
1268
1224
|
/**
|
|
1269
1225
|
* Retrieve the list of registered block pattern categories.
|
|
1270
1226
|
*
|
|
1271
|
-
* @param
|
|
1227
|
+
* @param state Data state.
|
|
1272
1228
|
*
|
|
1273
1229
|
* @return Block pattern category list.
|
|
1274
1230
|
*/
|