@wordpress/core-data 4.13.0 → 5.0.1-next.957ca95e4c.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 +12 -0
- package/README.md +148 -65
- package/build/entities.js +38 -51
- package/build/entities.js.map +1 -1
- package/build/hooks/index.js +14 -0
- package/build/hooks/index.js.map +1 -1
- package/build/hooks/use-entity-record.js +10 -6
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-entity-records.js +2 -0
- package/build/hooks/use-entity-records.js.map +1 -1
- package/build/hooks/use-query-select.js +5 -2
- package/build/hooks/use-query-select.js.map +1 -1
- package/build/hooks/use-resource-permissions.js +74 -11
- package/build/hooks/use-resource-permissions.js.map +1 -1
- package/build/index.js +1 -30
- package/build/index.js.map +1 -1
- package/build/resolvers.js +17 -21
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +9 -46
- package/build/selectors.js.map +1 -1
- package/build-module/entities.js +38 -52
- package/build-module/entities.js.map +1 -1
- package/build-module/hooks/index.js +1 -0
- package/build-module/hooks/index.js.map +1 -1
- package/build-module/hooks/use-entity-record.js +10 -6
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-entity-records.js +2 -0
- package/build-module/hooks/use-entity-records.js.map +1 -1
- package/build-module/hooks/use-query-select.js +4 -1
- package/build-module/hooks/use-query-select.js.map +1 -1
- package/build-module/hooks/use-resource-permissions.js +70 -10
- package/build-module/hooks/use-resource-permissions.js.map +1 -1
- package/build-module/index.js +0 -5
- package/build-module/index.js.map +1 -1
- package/build-module/resolvers.js +17 -21
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +7 -44
- package/build-module/selectors.js.map +1 -1
- package/build-types/actions.d.ts +188 -0
- package/build-types/actions.d.ts.map +1 -0
- package/build-types/batch/create-batch.d.ts +71 -0
- package/build-types/batch/create-batch.d.ts.map +1 -0
- package/build-types/batch/default-processor.d.ts +11 -0
- package/build-types/batch/default-processor.d.ts.map +1 -0
- package/build-types/batch/index.d.ts +3 -0
- package/build-types/batch/index.d.ts.map +1 -0
- package/build-types/entities.d.ts +128 -0
- package/build-types/entities.d.ts.map +1 -0
- package/build-types/entity-provider.d.ts +68 -0
- package/build-types/entity-provider.d.ts.map +1 -0
- package/build-types/entity-types/attachment.d.ts +121 -0
- package/build-types/entity-types/attachment.d.ts.map +1 -0
- package/build-types/entity-types/base-entity-records.d.ts +37 -0
- package/build-types/entity-types/base-entity-records.d.ts.map +1 -0
- package/build-types/entity-types/comment.d.ts +82 -0
- package/build-types/entity-types/comment.d.ts.map +1 -0
- package/build-types/entity-types/helpers.d.ts +123 -0
- package/build-types/entity-types/helpers.d.ts.map +1 -0
- package/build-types/entity-types/index.d.ts +64 -0
- package/build-types/entity-types/index.d.ts.map +1 -0
- package/build-types/entity-types/menu-location.d.ts +25 -0
- package/build-types/entity-types/menu-location.d.ts.map +1 -0
- package/build-types/entity-types/nav-menu-item.d.ts +88 -0
- package/build-types/entity-types/nav-menu-item.d.ts.map +1 -0
- package/build-types/entity-types/nav-menu.d.ts +45 -0
- package/build-types/entity-types/nav-menu.d.ts.map +1 -0
- package/build-types/entity-types/page.d.ts +120 -0
- package/build-types/entity-types/page.d.ts.map +1 -0
- package/build-types/entity-types/plugin.d.ts +62 -0
- package/build-types/entity-types/plugin.d.ts.map +1 -0
- package/build-types/entity-types/post.d.ts +128 -0
- package/build-types/entity-types/post.d.ts.map +1 -0
- package/build-types/entity-types/settings.d.ts +89 -0
- package/build-types/entity-types/settings.d.ts.map +1 -0
- package/build-types/entity-types/sidebar.d.ts +55 -0
- package/build-types/entity-types/sidebar.d.ts.map +1 -0
- package/build-types/entity-types/taxonomy.d.ts +83 -0
- package/build-types/entity-types/taxonomy.d.ts.map +1 -0
- package/build-types/entity-types/theme.d.ts +206 -0
- package/build-types/entity-types/theme.d.ts.map +1 -0
- package/build-types/entity-types/type.d.ts +71 -0
- package/build-types/entity-types/type.d.ts.map +1 -0
- package/build-types/entity-types/user.d.ts +93 -0
- package/build-types/entity-types/user.d.ts.map +1 -0
- package/build-types/entity-types/widget-type.d.ts +33 -0
- package/build-types/entity-types/widget-type.d.ts.map +1 -0
- package/build-types/entity-types/widget.d.ts +59 -0
- package/build-types/entity-types/widget.d.ts.map +1 -0
- package/build-types/entity-types/wp-template-part.d.ts +80 -0
- package/build-types/entity-types/wp-template-part.d.ts.map +1 -0
- package/build-types/entity-types/wp-template.d.ts +80 -0
- package/build-types/entity-types/wp-template.d.ts.map +1 -0
- package/build-types/fetch/__experimental-fetch-link-suggestions.d.ts +139 -0
- package/build-types/fetch/__experimental-fetch-link-suggestions.d.ts.map +1 -0
- package/build-types/fetch/__experimental-fetch-url-data.d.ts +35 -0
- package/build-types/fetch/__experimental-fetch-url-data.d.ts.map +1 -0
- package/build-types/fetch/index.d.ts +3 -0
- package/build-types/fetch/index.d.ts.map +1 -0
- package/build-types/hooks/constants.d.ts +7 -0
- package/build-types/hooks/constants.d.ts.map +1 -0
- package/build-types/hooks/index.d.ts +4 -0
- package/build-types/hooks/index.d.ts.map +1 -0
- package/build-types/hooks/memoize.d.ts +3 -0
- package/build-types/hooks/memoize.d.ts.map +1 -0
- package/build-types/hooks/use-entity-record.d.ts +124 -0
- package/build-types/hooks/use-entity-record.d.ts.map +1 -0
- package/build-types/hooks/use-entity-records.d.ts +49 -0
- package/build-types/hooks/use-entity-records.d.ts.map +1 -0
- package/build-types/hooks/use-query-select.d.ts +46 -0
- package/build-types/hooks/use-query-select.d.ts.map +1 -0
- package/build-types/hooks/use-resource-permissions.d.ts +99 -0
- package/build-types/hooks/use-resource-permissions.d.ts.map +1 -0
- package/build-types/index.d.ts +131 -0
- package/build-types/index.d.ts.map +1 -0
- package/build-types/locks/actions.d.ts +7 -0
- package/build-types/locks/actions.d.ts.map +1 -0
- package/build-types/locks/engine.d.ts +5 -0
- package/build-types/locks/engine.d.ts.map +1 -0
- package/build-types/locks/reducer.d.ts +10 -0
- package/build-types/locks/reducer.d.ts.map +1 -0
- package/build-types/locks/selectors.d.ts +5 -0
- package/build-types/locks/selectors.d.ts.map +1 -0
- package/build-types/locks/utils.d.ts +8 -0
- package/build-types/locks/utils.d.ts.map +1 -0
- package/build-types/name.d.ts +8 -0
- package/build-types/name.d.ts.map +1 -0
- package/build-types/queried-data/actions.d.ts +32 -0
- package/build-types/queried-data/actions.d.ts.map +1 -0
- package/build-types/queried-data/get-query-parts.d.ts +60 -0
- package/build-types/queried-data/get-query-parts.d.ts.map +1 -0
- package/build-types/queried-data/index.d.ts +4 -0
- package/build-types/queried-data/index.d.ts.map +1 -0
- package/build-types/queried-data/reducer.d.ts +54 -0
- package/build-types/queried-data/reducer.d.ts.map +1 -0
- package/build-types/queried-data/selectors.d.ts +16 -0
- package/build-types/queried-data/selectors.d.ts.map +1 -0
- package/build-types/reducer.d.ts +156 -0
- package/build-types/reducer.d.ts.map +1 -0
- package/build-types/resolvers.d.ts +74 -0
- package/build-types/resolvers.d.ts.map +1 -0
- package/build-types/selectors.d.ts +524 -0
- package/build-types/selectors.d.ts.map +1 -0
- package/build-types/types.d.ts +4 -0
- package/build-types/types.d.ts.map +1 -0
- package/build-types/utils/conservative-map-item.d.ts +12 -0
- package/build-types/utils/conservative-map-item.d.ts.map +1 -0
- package/build-types/utils/forward-resolver.d.ts +10 -0
- package/build-types/utils/forward-resolver.d.ts.map +1 -0
- package/build-types/utils/get-normalized-comma-separable.d.ts +12 -0
- package/build-types/utils/get-normalized-comma-separable.d.ts.map +1 -0
- package/build-types/utils/if-matching-action.d.ts +14 -0
- package/build-types/utils/if-matching-action.d.ts.map +1 -0
- package/build-types/utils/index.d.ts +9 -0
- package/build-types/utils/index.d.ts.map +1 -0
- package/build-types/utils/is-raw-attribute.d.ts +10 -0
- package/build-types/utils/is-raw-attribute.d.ts.map +1 -0
- package/build-types/utils/on-sub-key.d.ts +4 -0
- package/build-types/utils/on-sub-key.d.ts.map +1 -0
- package/build-types/utils/replace-action.d.ts +13 -0
- package/build-types/utils/replace-action.d.ts.map +1 -0
- package/build-types/utils/with-weak-map-cache.d.ts +12 -0
- package/build-types/utils/with-weak-map-cache.d.ts.map +1 -0
- package/package.json +13 -11
- package/src/entities.js +325 -0
- package/src/entity-types/attachment.ts +3 -4
- package/src/entity-types/comment.ts +3 -4
- package/src/entity-types/index.ts +31 -88
- package/src/entity-types/menu-location.ts +3 -4
- package/src/entity-types/nav-menu-item.ts +3 -4
- 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 +3 -4
- package/src/entity-types/taxonomy.ts +3 -4
- package/src/entity-types/theme.ts +7 -3
- package/src/entity-types/type.ts +3 -3
- package/src/entity-types/user.ts +3 -3
- package/src/entity-types/widget-type.ts +3 -4
- package/src/entity-types/widget.ts +3 -3
- package/src/entity-types/wp-template-part.ts +3 -4
- package/src/entity-types/wp-template.ts +3 -4
- package/src/hooks/index.ts +4 -0
- package/src/hooks/test/use-entity-record.js +41 -1
- package/src/hooks/test/use-resource-permissions.js +32 -36
- package/src/hooks/use-entity-record.ts +18 -6
- package/src/hooks/use-entity-records.ts +2 -0
- package/src/hooks/use-query-select.ts +4 -1
- package/src/hooks/use-resource-permissions.ts +84 -20
- package/src/index.js +0 -5
- package/src/resolvers.js +36 -24
- package/src/selectors.ts +202 -341
- package/tsconfig.json +21 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/build/entity-types/entities.js +0 -6
- package/build/entity-types/entities.js.map +0 -1
- package/build-module/entity-types/entities.js +0 -2
- package/build-module/entity-types/entities.js.map +0 -1
- package/src/entities.ts +0 -548
- package/src/entity-types/entities.ts +0 -130
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 5.0.0-next.0 (2022-08-29)
|
|
6
|
+
|
|
7
|
+
### Breaking Changes
|
|
8
|
+
|
|
9
|
+
– Add TypeScript types to the built package (via "types": "build-types" in the package.json)
|
|
10
|
+
|
|
11
|
+
## 4.14.0 (2022-08-24)
|
|
12
|
+
|
|
13
|
+
### New Features
|
|
14
|
+
|
|
15
|
+
- Stabilized the `useResourcePermissions` hook ([#43268](https://github.com/WordPress/gutenberg/pull/43268))
|
|
16
|
+
|
|
5
17
|
## 4.13.0 (2022-08-10)
|
|
6
18
|
|
|
7
19
|
## 4.12.0 (2022-07-27)
|
package/README.md
CHANGED
|
@@ -189,7 +189,7 @@ _Parameters_
|
|
|
189
189
|
- _state_ `State`: Data state.
|
|
190
190
|
- _action_ `string`: Action to check. One of: 'create', 'read', 'update', 'delete'.
|
|
191
191
|
- _resource_ `string`: REST resource to check, e.g. 'media' or 'posts'.
|
|
192
|
-
- _id_ `
|
|
192
|
+
- _id_ `EntityRecordKey`: Optional ID of the rest resource to check.
|
|
193
193
|
|
|
194
194
|
_Returns_
|
|
195
195
|
|
|
@@ -207,9 +207,9 @@ Calling this may trigger an OPTIONS request to the REST API via the
|
|
|
207
207
|
_Parameters_
|
|
208
208
|
|
|
209
209
|
- _state_ `State`: Data state.
|
|
210
|
-
- _kind_ `
|
|
211
|
-
- _name_ `
|
|
212
|
-
- _recordId_ `
|
|
210
|
+
- _kind_ `string`: Entity kind.
|
|
211
|
+
- _name_ `string`: Entity name.
|
|
212
|
+
- _recordId_ `EntityRecordKey`: Record's id.
|
|
213
213
|
|
|
214
214
|
_Returns_
|
|
215
215
|
|
|
@@ -224,11 +224,11 @@ Returns all available authors.
|
|
|
224
224
|
_Parameters_
|
|
225
225
|
|
|
226
226
|
- _state_ `State`: Data state.
|
|
227
|
-
- _query_ `
|
|
227
|
+
- _query_ `GetRecordsHttpQuery`: Optional object of query parameters to include with request.
|
|
228
228
|
|
|
229
229
|
_Returns_
|
|
230
230
|
|
|
231
|
-
- `User
|
|
231
|
+
- `ET.User[]`: Authors list.
|
|
232
232
|
|
|
233
233
|
### getAutosave
|
|
234
234
|
|
|
@@ -238,8 +238,8 @@ _Parameters_
|
|
|
238
238
|
|
|
239
239
|
- _state_ `State`: State tree.
|
|
240
240
|
- _postType_ `string`: The type of the parent post.
|
|
241
|
-
- _postId_ `
|
|
242
|
-
- _authorId_ `
|
|
241
|
+
- _postId_ `EntityRecordKey`: The id of the parent post.
|
|
242
|
+
- _authorId_ `EntityRecordKey`: The id of the author.
|
|
243
243
|
|
|
244
244
|
_Returns_
|
|
245
245
|
|
|
@@ -256,7 +256,7 @@ _Parameters_
|
|
|
256
256
|
|
|
257
257
|
- _state_ `State`: State tree.
|
|
258
258
|
- _postType_ `string`: The type of the parent post.
|
|
259
|
-
- _postId_ `
|
|
259
|
+
- _postId_ `EntityRecordKey`: The id of the parent post.
|
|
260
260
|
|
|
261
261
|
_Returns_
|
|
262
262
|
|
|
@@ -308,7 +308,7 @@ _Parameters_
|
|
|
308
308
|
|
|
309
309
|
_Returns_
|
|
310
310
|
|
|
311
|
-
- `
|
|
311
|
+
- `undefined< 'edit' >`: Current user object.
|
|
312
312
|
|
|
313
313
|
### getEditedEntityRecord
|
|
314
314
|
|
|
@@ -317,13 +317,13 @@ Returns the specified entity record, merged with its edits.
|
|
|
317
317
|
_Parameters_
|
|
318
318
|
|
|
319
319
|
- _state_ `State`: State tree.
|
|
320
|
-
- _kind_ `
|
|
321
|
-
- _name_ `
|
|
322
|
-
- _recordId_ `
|
|
320
|
+
- _kind_ `string`: Entity kind.
|
|
321
|
+
- _name_ `string`: Entity name.
|
|
322
|
+
- _recordId_ `EntityRecordKey`: Record ID.
|
|
323
323
|
|
|
324
324
|
_Returns_
|
|
325
325
|
|
|
326
|
-
- `EntityRecord | undefined`: The entity record, merged with its edits.
|
|
326
|
+
- `undefined< EntityRecord > | undefined`: The entity record, merged with its edits.
|
|
327
327
|
|
|
328
328
|
### getEmbedPreview
|
|
329
329
|
|
|
@@ -347,7 +347,7 @@ Returns the loaded entities for the given kind.
|
|
|
347
347
|
_Parameters_
|
|
348
348
|
|
|
349
349
|
- _state_ `State`: Data state.
|
|
350
|
-
- _kind_ `
|
|
350
|
+
- _kind_ `string`: Entity kind.
|
|
351
351
|
|
|
352
352
|
_Returns_
|
|
353
353
|
|
|
@@ -360,7 +360,7 @@ Returns the loaded entities for the given kind.
|
|
|
360
360
|
_Parameters_
|
|
361
361
|
|
|
362
362
|
- _state_ `State`: Data state.
|
|
363
|
-
- _kind_ `
|
|
363
|
+
- _kind_ `string`: Entity kind.
|
|
364
364
|
|
|
365
365
|
_Returns_
|
|
366
366
|
|
|
@@ -375,8 +375,8 @@ Returns the entity config given its kind and name.
|
|
|
375
375
|
_Parameters_
|
|
376
376
|
|
|
377
377
|
- _state_ `State`: Data state.
|
|
378
|
-
- _kind_ `
|
|
379
|
-
- _name_ `
|
|
378
|
+
- _kind_ `string`: Entity kind.
|
|
379
|
+
- _name_ `string`: Entity name.
|
|
380
380
|
|
|
381
381
|
_Returns_
|
|
382
382
|
|
|
@@ -389,8 +389,8 @@ Returns the entity config given its kind and name.
|
|
|
389
389
|
_Parameters_
|
|
390
390
|
|
|
391
391
|
- _state_ `State`: Data state.
|
|
392
|
-
- _kind_ `
|
|
393
|
-
- _name_ `
|
|
392
|
+
- _kind_ `string`: Entity kind.
|
|
393
|
+
- _name_ `string`: Entity name.
|
|
394
394
|
|
|
395
395
|
_Returns_
|
|
396
396
|
|
|
@@ -405,14 +405,14 @@ entity object if it exists and is received.
|
|
|
405
405
|
_Parameters_
|
|
406
406
|
|
|
407
407
|
- _state_ `State`: State tree
|
|
408
|
-
- _kind_ `
|
|
409
|
-
- _name_ `
|
|
410
|
-
- _key_ `
|
|
411
|
-
- _query_ Optional query. If requesting specific fields, fields must always include the ID.
|
|
408
|
+
- _kind_ `string`: Entity kind.
|
|
409
|
+
- _name_ `string`: Entity name.
|
|
410
|
+
- _key_ `EntityRecordKey`: Record's key
|
|
411
|
+
- _query_ `GetRecordsHttpQuery`: Optional query. If requesting specific fields, fields must always include the ID.
|
|
412
412
|
|
|
413
413
|
_Returns_
|
|
414
414
|
|
|
415
|
-
- Record.
|
|
415
|
+
- `EntityRecord | undefined`: Record.
|
|
416
416
|
|
|
417
417
|
### getEntityRecordEdits
|
|
418
418
|
|
|
@@ -421,9 +421,9 @@ Returns the specified entity record's edits.
|
|
|
421
421
|
_Parameters_
|
|
422
422
|
|
|
423
423
|
- _state_ `State`: State tree.
|
|
424
|
-
- _kind_ `
|
|
425
|
-
- _name_ `
|
|
426
|
-
- _recordId_ `
|
|
424
|
+
- _kind_ `string`: Entity kind.
|
|
425
|
+
- _name_ `string`: Entity name.
|
|
426
|
+
- _recordId_ `EntityRecordKey`: Record ID.
|
|
427
427
|
|
|
428
428
|
_Returns_
|
|
429
429
|
|
|
@@ -440,9 +440,9 @@ They are defined in the entity's config.
|
|
|
440
440
|
_Parameters_
|
|
441
441
|
|
|
442
442
|
- _state_ `State`: State tree.
|
|
443
|
-
- _kind_ `
|
|
444
|
-
- _name_ `
|
|
445
|
-
- _recordId_ `
|
|
443
|
+
- _kind_ `string`: Entity kind.
|
|
444
|
+
- _name_ `string`: Entity name.
|
|
445
|
+
- _recordId_ `EntityRecordKey`: Record ID.
|
|
446
446
|
|
|
447
447
|
_Returns_
|
|
448
448
|
|
|
@@ -455,13 +455,13 @@ Returns the Entity's records.
|
|
|
455
455
|
_Parameters_
|
|
456
456
|
|
|
457
457
|
- _state_ `State`: State tree
|
|
458
|
-
- _kind_ `
|
|
459
|
-
- _name_ `
|
|
460
|
-
- _query_ Optional terms query. If requesting specific fields, fields must always include the ID.
|
|
458
|
+
- _kind_ `string`: Entity kind.
|
|
459
|
+
- _name_ `string`: Entity name.
|
|
460
|
+
- _query_ `GetRecordsHttpQuery`: Optional terms query. If requesting specific fields, fields must always include the ID.
|
|
461
461
|
|
|
462
462
|
_Returns_
|
|
463
463
|
|
|
464
|
-
- Records.
|
|
464
|
+
- `EntityRecord[] | null`: Records.
|
|
465
465
|
|
|
466
466
|
### getLastEntityDeleteError
|
|
467
467
|
|
|
@@ -470,9 +470,9 @@ Returns the specified entity record's last delete error.
|
|
|
470
470
|
_Parameters_
|
|
471
471
|
|
|
472
472
|
- _state_ `State`: State tree.
|
|
473
|
-
- _kind_ `
|
|
474
|
-
- _name_ `
|
|
475
|
-
- _recordId_ `
|
|
473
|
+
- _kind_ `string`: Entity kind.
|
|
474
|
+
- _name_ `string`: Entity name.
|
|
475
|
+
- _recordId_ `EntityRecordKey`: Record ID.
|
|
476
476
|
|
|
477
477
|
_Returns_
|
|
478
478
|
|
|
@@ -485,9 +485,9 @@ Returns the specified entity record's last save error.
|
|
|
485
485
|
_Parameters_
|
|
486
486
|
|
|
487
487
|
- _state_ `State`: State tree.
|
|
488
|
-
- _kind_ `
|
|
489
|
-
- _name_ `
|
|
490
|
-
- _recordId_ `
|
|
488
|
+
- _kind_ `string`: Entity kind.
|
|
489
|
+
- _name_ `string`: Entity name.
|
|
490
|
+
- _recordId_ `EntityRecordKey`: Record ID.
|
|
491
491
|
|
|
492
492
|
_Returns_
|
|
493
493
|
|
|
@@ -501,9 +501,9 @@ with its attributes mapped to their raw values.
|
|
|
501
501
|
_Parameters_
|
|
502
502
|
|
|
503
503
|
- _state_ `State`: State tree.
|
|
504
|
-
- _kind_ `
|
|
505
|
-
- _name_ `
|
|
506
|
-
- _key_ `
|
|
504
|
+
- _kind_ `string`: Entity kind.
|
|
505
|
+
- _name_ `string`: Entity name.
|
|
506
|
+
- _key_ `EntityRecordKey`: Record's key.
|
|
507
507
|
|
|
508
508
|
_Returns_
|
|
509
509
|
|
|
@@ -579,7 +579,7 @@ _Parameters_
|
|
|
579
579
|
|
|
580
580
|
_Returns_
|
|
581
581
|
|
|
582
|
-
- `
|
|
582
|
+
- `undefined< 'edit' >[]`: Users list.
|
|
583
583
|
|
|
584
584
|
### hasEditsForEntityRecord
|
|
585
585
|
|
|
@@ -589,9 +589,9 @@ and false otherwise.
|
|
|
589
589
|
_Parameters_
|
|
590
590
|
|
|
591
591
|
- _state_ `State`: State tree.
|
|
592
|
-
- _kind_ `
|
|
593
|
-
- _name_ `
|
|
594
|
-
- _recordId_ `
|
|
592
|
+
- _kind_ `string`: Entity kind.
|
|
593
|
+
- _name_ `string`: Entity name.
|
|
594
|
+
- _recordId_ `EntityRecordKey`: Record ID.
|
|
595
595
|
|
|
596
596
|
_Returns_
|
|
597
597
|
|
|
@@ -605,9 +605,9 @@ or false otherwise.
|
|
|
605
605
|
_Parameters_
|
|
606
606
|
|
|
607
607
|
- _state_ `State`: State tree
|
|
608
|
-
- _kind_ `
|
|
609
|
-
- _name_ `
|
|
610
|
-
- _query_ `
|
|
608
|
+
- _kind_ `string`: Entity kind.
|
|
609
|
+
- _name_ `string`: Entity name.
|
|
610
|
+
- _query_ `GetRecordsHttpQuery`: Optional terms query.
|
|
611
611
|
|
|
612
612
|
_Returns_
|
|
613
613
|
|
|
@@ -621,7 +621,7 @@ _Parameters_
|
|
|
621
621
|
|
|
622
622
|
- _state_ `State`: State tree.
|
|
623
623
|
- _postType_ `string`: The type of the parent post.
|
|
624
|
-
- _postId_ `
|
|
624
|
+
- _postId_ `EntityRecordKey`: The id of the parent post.
|
|
625
625
|
|
|
626
626
|
_Returns_
|
|
627
627
|
|
|
@@ -660,9 +660,9 @@ Returns true if the specified entity record is autosaving, and false otherwise.
|
|
|
660
660
|
_Parameters_
|
|
661
661
|
|
|
662
662
|
- _state_ `State`: State tree.
|
|
663
|
-
- _kind_ `
|
|
664
|
-
- _name_ `
|
|
665
|
-
- _recordId_ `
|
|
663
|
+
- _kind_ `string`: Entity kind.
|
|
664
|
+
- _name_ `string`: Entity name.
|
|
665
|
+
- _recordId_ `EntityRecordKey`: Record ID.
|
|
666
666
|
|
|
667
667
|
_Returns_
|
|
668
668
|
|
|
@@ -675,9 +675,9 @@ Returns true if the specified entity record is deleting, and false otherwise.
|
|
|
675
675
|
_Parameters_
|
|
676
676
|
|
|
677
677
|
- _state_ `State`: State tree.
|
|
678
|
-
- _kind_ `
|
|
679
|
-
- _name_ `
|
|
680
|
-
- _recordId_ `
|
|
678
|
+
- _kind_ `string`: Entity kind.
|
|
679
|
+
- _name_ `string`: Entity name.
|
|
680
|
+
- _recordId_ `EntityRecordKey`: Record ID.
|
|
681
681
|
|
|
682
682
|
_Returns_
|
|
683
683
|
|
|
@@ -721,9 +721,9 @@ Returns true if the specified entity record is saving, and false otherwise.
|
|
|
721
721
|
_Parameters_
|
|
722
722
|
|
|
723
723
|
- _state_ `State`: State tree.
|
|
724
|
-
- _kind_ `
|
|
725
|
-
- _name_ `
|
|
726
|
-
- _recordId_ `
|
|
724
|
+
- _kind_ `string`: Entity kind.
|
|
725
|
+
- _name_ `string`: Entity name.
|
|
726
|
+
- _recordId_ `EntityRecordKey`: Record ID.
|
|
727
727
|
|
|
728
728
|
_Returns_
|
|
729
729
|
|
|
@@ -765,8 +765,8 @@ application, the page and the resolution details will be retrieved from
|
|
|
765
765
|
the store state using `getEntityRecord()`, or resolved if missing.
|
|
766
766
|
|
|
767
767
|
```js
|
|
768
|
-
import { useState } from '@wordpress/data';
|
|
769
768
|
import { useDispatch } from '@wordpress/data';
|
|
769
|
+
import { useCallback } from '@wordpress/element';
|
|
770
770
|
import { __ } from '@wordpress/i18n';
|
|
771
771
|
import { TextControl } from '@wordpress/components';
|
|
772
772
|
import { store as noticeStore } from '@wordpress/notices';
|
|
@@ -774,17 +774,22 @@ import { useEntityRecord } from '@wordpress/core-data';
|
|
|
774
774
|
|
|
775
775
|
function PageRenameForm( { id } ) {
|
|
776
776
|
const page = useEntityRecord( 'postType', 'page', id );
|
|
777
|
-
const [ title, setTitle ] = useState( () => page.record.title.rendered );
|
|
778
777
|
const { createSuccessNotice, createErrorNotice } =
|
|
779
778
|
useDispatch( noticeStore );
|
|
780
779
|
|
|
780
|
+
const setTitle = useCallback(
|
|
781
|
+
( title ) => {
|
|
782
|
+
page.edit( { title } );
|
|
783
|
+
},
|
|
784
|
+
[ page.edit ]
|
|
785
|
+
);
|
|
786
|
+
|
|
781
787
|
if ( page.isResolving ) {
|
|
782
788
|
return 'Loading...';
|
|
783
789
|
}
|
|
784
790
|
|
|
785
791
|
async function onRename( event ) {
|
|
786
792
|
event.preventDefault();
|
|
787
|
-
page.edit( { title } );
|
|
788
793
|
try {
|
|
789
794
|
await page.save();
|
|
790
795
|
createSuccessNotice( __( 'Page renamed.' ), {
|
|
@@ -799,7 +804,7 @@ function PageRenameForm( { id } ) {
|
|
|
799
804
|
<form onSubmit={ onRename }>
|
|
800
805
|
<TextControl
|
|
801
806
|
label={ __( 'Name' ) }
|
|
802
|
-
value={ title }
|
|
807
|
+
value={ page.editedRecord.title }
|
|
803
808
|
onChange={ setTitle }
|
|
804
809
|
/>
|
|
805
810
|
<button type="submit">{ __( 'Save' ) }</button>
|
|
@@ -826,6 +831,10 @@ _Returns_
|
|
|
826
831
|
|
|
827
832
|
- `EntityRecordResolution< RecordType >`: Entity record data.
|
|
828
833
|
|
|
834
|
+
_Changelog_
|
|
835
|
+
|
|
836
|
+
`6.1.0` Introduced in WordPress core.
|
|
837
|
+
|
|
829
838
|
### useEntityRecords
|
|
830
839
|
|
|
831
840
|
Resolves the specified entity records.
|
|
@@ -870,6 +879,80 @@ _Returns_
|
|
|
870
879
|
|
|
871
880
|
- `EntityRecordsResolution< RecordType >`: Entity records data.
|
|
872
881
|
|
|
882
|
+
_Changelog_
|
|
883
|
+
|
|
884
|
+
`6.1.0` Introduced in WordPress core.
|
|
885
|
+
|
|
886
|
+
### useResourcePermissions
|
|
887
|
+
|
|
888
|
+
Resolves resource permissions.
|
|
889
|
+
|
|
890
|
+
_Usage_
|
|
891
|
+
|
|
892
|
+
```js
|
|
893
|
+
import { useResourcePermissions } from '@wordpress/core-data';
|
|
894
|
+
|
|
895
|
+
function PagesList() {
|
|
896
|
+
const { canCreate, isResolving } = useResourcePermissions( 'pages' );
|
|
897
|
+
|
|
898
|
+
if ( isResolving ) {
|
|
899
|
+
return 'Loading ...';
|
|
900
|
+
}
|
|
901
|
+
|
|
902
|
+
return (
|
|
903
|
+
<div>
|
|
904
|
+
{ canCreate ? <button>+ Create a new page</button> : false }
|
|
905
|
+
// ...
|
|
906
|
+
</div>
|
|
907
|
+
);
|
|
908
|
+
}
|
|
909
|
+
|
|
910
|
+
// Rendered in the application:
|
|
911
|
+
// <PagesList />
|
|
912
|
+
```
|
|
913
|
+
|
|
914
|
+
```js
|
|
915
|
+
import { useResourcePermissions } from '@wordpress/core-data';
|
|
916
|
+
|
|
917
|
+
function Page( { pageId } ) {
|
|
918
|
+
const { canCreate, canUpdate, canDelete, isResolving } =
|
|
919
|
+
useResourcePermissions( 'pages', pageId );
|
|
920
|
+
|
|
921
|
+
if ( isResolving ) {
|
|
922
|
+
return 'Loading ...';
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
return (
|
|
926
|
+
<div>
|
|
927
|
+
{ canCreate ? <button>+ Create a new page</button> : false }
|
|
928
|
+
{ canUpdate ? <button>Edit page</button> : false }
|
|
929
|
+
{ canDelete ? <button>Delete page</button> : false }
|
|
930
|
+
// ...
|
|
931
|
+
</div>
|
|
932
|
+
);
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
// Rendered in the application:
|
|
936
|
+
// <Page pageId={ 15 } />
|
|
937
|
+
```
|
|
938
|
+
|
|
939
|
+
In the above example, when `PagesList` is rendered into an
|
|
940
|
+
application, the appropriate permissions and the resolution details will be retrieved from
|
|
941
|
+
the store state using `canUser()`, or resolved if missing.
|
|
942
|
+
|
|
943
|
+
_Parameters_
|
|
944
|
+
|
|
945
|
+
- _resource_ `string`: The resource in question, e.g. media.
|
|
946
|
+
- _id_ `IdType`: ID of a specific resource entry, if needed, e.g. 10.
|
|
947
|
+
|
|
948
|
+
_Returns_
|
|
949
|
+
|
|
950
|
+
- `ResourcePermissionsResolution< IdType >`: Entity records data.
|
|
951
|
+
|
|
952
|
+
_Changelog_
|
|
953
|
+
|
|
954
|
+
`6.1.0` Introduced in WordPress core.
|
|
955
|
+
|
|
873
956
|
<!-- END TOKEN(Autogenerated hooks|src/hooks/index.ts) -->
|
|
874
957
|
|
|
875
958
|
## Contributing to this package
|
package/build/entities.js
CHANGED
|
@@ -7,6 +7,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.rootEntitiesConfig = exports.prePersistPostType = exports.getOrLoadEntitiesConfig = exports.getMethodName = exports.additionalEntityConfigLoaders = exports.DEFAULT_ENTITY_KEY = void 0;
|
|
9
9
|
|
|
10
|
+
var _changeCase = require("change-case");
|
|
11
|
+
|
|
10
12
|
var _lodash = require("lodash");
|
|
11
13
|
|
|
12
14
|
var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
|
|
@@ -29,18 +31,15 @@ var _actions = require("./actions");
|
|
|
29
31
|
const DEFAULT_ENTITY_KEY = 'id';
|
|
30
32
|
exports.DEFAULT_ENTITY_KEY = DEFAULT_ENTITY_KEY;
|
|
31
33
|
const POST_RAW_ATTRIBUTES = ['title', 'excerpt', 'content'];
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
+
const rootEntitiesConfig = [{
|
|
35
|
+
label: (0, _i18n.__)('Base'),
|
|
34
36
|
kind: 'root',
|
|
35
|
-
|
|
37
|
+
name: '__unstableBase',
|
|
38
|
+
baseURL: '/',
|
|
36
39
|
baseURLParams: {
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
label: (0, _i18n.__)('Media'),
|
|
41
|
-
rawAttributes: ['caption', 'title', 'description']
|
|
42
|
-
};
|
|
43
|
-
const siteConfig = {
|
|
40
|
+
_fields: ['description', 'gmt_offset', 'home', 'name', 'site_icon', 'site_icon_url', 'site_logo', 'timezone_string', 'url'].join(',')
|
|
41
|
+
}
|
|
42
|
+
}, {
|
|
44
43
|
label: (0, _i18n.__)('Site'),
|
|
45
44
|
name: 'site',
|
|
46
45
|
kind: 'root',
|
|
@@ -48,8 +47,7 @@ const siteConfig = {
|
|
|
48
47
|
getTitle: record => {
|
|
49
48
|
return (0, _lodash.get)(record, ['title'], (0, _i18n.__)('Site Title'));
|
|
50
49
|
}
|
|
51
|
-
}
|
|
52
|
-
const postTypeConfig = {
|
|
50
|
+
}, {
|
|
53
51
|
label: (0, _i18n.__)('Post Type'),
|
|
54
52
|
name: 'postType',
|
|
55
53
|
kind: 'root',
|
|
@@ -58,8 +56,17 @@ const postTypeConfig = {
|
|
|
58
56
|
baseURLParams: {
|
|
59
57
|
context: 'edit'
|
|
60
58
|
}
|
|
61
|
-
}
|
|
62
|
-
|
|
59
|
+
}, {
|
|
60
|
+
name: 'media',
|
|
61
|
+
kind: 'root',
|
|
62
|
+
baseURL: '/wp/v2/media',
|
|
63
|
+
baseURLParams: {
|
|
64
|
+
context: 'edit'
|
|
65
|
+
},
|
|
66
|
+
plural: 'mediaItems',
|
|
67
|
+
label: (0, _i18n.__)('Media'),
|
|
68
|
+
rawAttributes: ['caption', 'title', 'description']
|
|
69
|
+
}, {
|
|
63
70
|
name: 'taxonomy',
|
|
64
71
|
kind: 'root',
|
|
65
72
|
key: 'slug',
|
|
@@ -69,8 +76,7 @@ const taxonomyConfig = {
|
|
|
69
76
|
},
|
|
70
77
|
plural: 'taxonomies',
|
|
71
78
|
label: (0, _i18n.__)('Taxonomy')
|
|
72
|
-
}
|
|
73
|
-
const sidebarConfig = {
|
|
79
|
+
}, {
|
|
74
80
|
name: 'sidebar',
|
|
75
81
|
kind: 'root',
|
|
76
82
|
baseURL: '/wp/v2/sidebars',
|
|
@@ -82,8 +88,7 @@ const sidebarConfig = {
|
|
|
82
88
|
blocks: true
|
|
83
89
|
},
|
|
84
90
|
label: (0, _i18n.__)('Widget areas')
|
|
85
|
-
}
|
|
86
|
-
const widgetConfig = {
|
|
91
|
+
}, {
|
|
87
92
|
name: 'widget',
|
|
88
93
|
kind: 'root',
|
|
89
94
|
baseURL: '/wp/v2/widgets',
|
|
@@ -95,8 +100,7 @@ const widgetConfig = {
|
|
|
95
100
|
blocks: true
|
|
96
101
|
},
|
|
97
102
|
label: (0, _i18n.__)('Widgets')
|
|
98
|
-
}
|
|
99
|
-
const widgetTypeConfig = {
|
|
103
|
+
}, {
|
|
100
104
|
name: 'widgetType',
|
|
101
105
|
kind: 'root',
|
|
102
106
|
baseURL: '/wp/v2/widget-types',
|
|
@@ -105,8 +109,7 @@ const widgetTypeConfig = {
|
|
|
105
109
|
},
|
|
106
110
|
plural: 'widgetTypes',
|
|
107
111
|
label: (0, _i18n.__)('Widget types')
|
|
108
|
-
}
|
|
109
|
-
const userConfig = {
|
|
112
|
+
}, {
|
|
110
113
|
label: (0, _i18n.__)('User'),
|
|
111
114
|
name: 'user',
|
|
112
115
|
kind: 'root',
|
|
@@ -115,8 +118,7 @@ const userConfig = {
|
|
|
115
118
|
context: 'edit'
|
|
116
119
|
},
|
|
117
120
|
plural: 'users'
|
|
118
|
-
}
|
|
119
|
-
const commentConfig = {
|
|
121
|
+
}, {
|
|
120
122
|
name: 'comment',
|
|
121
123
|
kind: 'root',
|
|
122
124
|
baseURL: '/wp/v2/comments',
|
|
@@ -125,8 +127,7 @@ const commentConfig = {
|
|
|
125
127
|
},
|
|
126
128
|
plural: 'comments',
|
|
127
129
|
label: (0, _i18n.__)('Comment')
|
|
128
|
-
}
|
|
129
|
-
const menuConfig = {
|
|
130
|
+
}, {
|
|
130
131
|
name: 'menu',
|
|
131
132
|
kind: 'root',
|
|
132
133
|
baseURL: '/wp/v2/menus',
|
|
@@ -135,8 +136,7 @@ const menuConfig = {
|
|
|
135
136
|
},
|
|
136
137
|
plural: 'menus',
|
|
137
138
|
label: (0, _i18n.__)('Menu')
|
|
138
|
-
}
|
|
139
|
-
const menuItemConfig = {
|
|
139
|
+
}, {
|
|
140
140
|
name: 'menuItem',
|
|
141
141
|
kind: 'root',
|
|
142
142
|
baseURL: '/wp/v2/menu-items',
|
|
@@ -146,8 +146,7 @@ const menuItemConfig = {
|
|
|
146
146
|
plural: 'menuItems',
|
|
147
147
|
label: (0, _i18n.__)('Menu Item'),
|
|
148
148
|
rawAttributes: ['title']
|
|
149
|
-
}
|
|
150
|
-
const menuLocationConfig = {
|
|
149
|
+
}, {
|
|
151
150
|
name: 'menuLocation',
|
|
152
151
|
kind: 'root',
|
|
153
152
|
baseURL: '/wp/v2/menu-locations',
|
|
@@ -157,8 +156,7 @@ const menuLocationConfig = {
|
|
|
157
156
|
plural: 'menuLocations',
|
|
158
157
|
label: (0, _i18n.__)('Menu Location'),
|
|
159
158
|
key: 'name'
|
|
160
|
-
}
|
|
161
|
-
const globalStyleConfig = {
|
|
159
|
+
}, {
|
|
162
160
|
label: (0, _i18n.__)('Global Styles'),
|
|
163
161
|
name: 'globalStyles',
|
|
164
162
|
kind: 'root',
|
|
@@ -173,8 +171,7 @@ const globalStyleConfig = {
|
|
|
173
171
|
|
|
174
172
|
return (record === null || record === void 0 ? void 0 : (_record$title = record.title) === null || _record$title === void 0 ? void 0 : _record$title.rendered) || (record === null || record === void 0 ? void 0 : record.title);
|
|
175
173
|
}
|
|
176
|
-
}
|
|
177
|
-
const themeConfig = {
|
|
174
|
+
}, {
|
|
178
175
|
label: (0, _i18n.__)('Themes'),
|
|
179
176
|
name: 'theme',
|
|
180
177
|
kind: 'root',
|
|
@@ -183,8 +180,7 @@ const themeConfig = {
|
|
|
183
180
|
context: 'edit'
|
|
184
181
|
},
|
|
185
182
|
key: 'stylesheet'
|
|
186
|
-
}
|
|
187
|
-
const pluginConfig = {
|
|
183
|
+
}, {
|
|
188
184
|
label: (0, _i18n.__)('Plugins'),
|
|
189
185
|
name: 'plugin',
|
|
190
186
|
kind: 'root',
|
|
@@ -193,16 +189,7 @@ const pluginConfig = {
|
|
|
193
189
|
context: 'edit'
|
|
194
190
|
},
|
|
195
191
|
key: 'plugin'
|
|
196
|
-
};
|
|
197
|
-
const rootEntitiesConfig = [{
|
|
198
|
-
label: (0, _i18n.__)('Base'),
|
|
199
|
-
kind: 'root',
|
|
200
|
-
name: '__unstableBase',
|
|
201
|
-
baseURL: '/',
|
|
202
|
-
baseURLParams: {
|
|
203
|
-
_fields: ['description', 'gmt_offset', 'home', 'name', 'site_icon', 'site_icon_url', 'site_logo', 'timezone_string', 'url'].join(',')
|
|
204
|
-
}
|
|
205
|
-
}, siteConfig, postTypeConfig, attachmentConfig, taxonomyConfig, sidebarConfig, widgetConfig, widgetTypeConfig, userConfig, commentConfig, menuConfig, menuItemConfig, menuLocationConfig, globalStyleConfig, themeConfig, pluginConfig];
|
|
192
|
+
}];
|
|
206
193
|
exports.rootEntitiesConfig = rootEntitiesConfig;
|
|
207
194
|
const additionalEntityConfigLoaders = [{
|
|
208
195
|
kind: 'postType',
|
|
@@ -273,9 +260,9 @@ async function loadPostTypeEntities() {
|
|
|
273
260
|
},
|
|
274
261
|
rawAttributes: POST_RAW_ATTRIBUTES,
|
|
275
262
|
getTitle: record => {
|
|
276
|
-
var _record$title2;
|
|
263
|
+
var _record$title2, _record$slug;
|
|
277
264
|
|
|
278
|
-
return (record === null || record === void 0 ? void 0 : (_record$title2 = record.title) === null || _record$title2 === void 0 ? void 0 : _record$title2.rendered) || (record === null || record === void 0 ? void 0 : record.title) || (isTemplate ? (0,
|
|
265
|
+
return (record === null || record === void 0 ? void 0 : (_record$title2 = record.title) === null || _record$title2 === void 0 ? void 0 : _record$title2.rendered) || (record === null || record === void 0 ? void 0 : record.title) || (isTemplate ? (0, _changeCase.capitalCase)((_record$slug = record.slug) !== null && _record$slug !== void 0 ? _record$slug : '') : String(record.id));
|
|
279
266
|
},
|
|
280
267
|
__unstablePrePersist: isTemplate ? undefined : prePersistPostType,
|
|
281
268
|
__unstable_rest_base: postType.rest_base
|
|
@@ -336,9 +323,9 @@ const getMethodName = function (kind, name) {
|
|
|
336
323
|
kind,
|
|
337
324
|
name
|
|
338
325
|
});
|
|
339
|
-
const kindPrefix = kind === 'root' ? '' : (0,
|
|
340
|
-
const nameSuffix = (0,
|
|
341
|
-
const suffix = usePlural && 'plural' in entityConfig && entityConfig !== null && entityConfig !== void 0 && entityConfig.plural ? (0,
|
|
326
|
+
const kindPrefix = kind === 'root' ? '' : (0, _changeCase.pascalCase)(kind);
|
|
327
|
+
const nameSuffix = (0, _changeCase.pascalCase)(name) + (usePlural ? 's' : '');
|
|
328
|
+
const suffix = usePlural && 'plural' in entityConfig && entityConfig !== null && entityConfig !== void 0 && entityConfig.plural ? (0, _changeCase.pascalCase)(entityConfig.plural) : nameSuffix;
|
|
342
329
|
return `${prefix}${kindPrefix}${suffix}`;
|
|
343
330
|
};
|
|
344
331
|
/**
|