@wordpress/core-data 4.13.0 → 4.14.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.
Files changed (36) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/README.md +75 -4
  3. package/build/entities.js +7 -5
  4. package/build/entities.js.map +1 -1
  5. package/build/hooks/index.js +14 -0
  6. package/build/hooks/index.js.map +1 -1
  7. package/build/hooks/use-entity-record.js +8 -6
  8. package/build/hooks/use-entity-record.js.map +1 -1
  9. package/build/hooks/use-resource-permissions.js +72 -11
  10. package/build/hooks/use-resource-permissions.js.map +1 -1
  11. package/build/index.js +1 -28
  12. package/build/index.js.map +1 -1
  13. package/build/resolvers.js +17 -21
  14. package/build/resolvers.js.map +1 -1
  15. package/build-module/entities.js +7 -6
  16. package/build-module/entities.js.map +1 -1
  17. package/build-module/hooks/index.js +1 -0
  18. package/build-module/hooks/index.js.map +1 -1
  19. package/build-module/hooks/use-entity-record.js +8 -6
  20. package/build-module/hooks/use-entity-record.js.map +1 -1
  21. package/build-module/hooks/use-resource-permissions.js +68 -10
  22. package/build-module/hooks/use-resource-permissions.js.map +1 -1
  23. package/build-module/index.js +0 -3
  24. package/build-module/index.js.map +1 -1
  25. package/build-module/resolvers.js +17 -21
  26. package/build-module/resolvers.js.map +1 -1
  27. package/package.json +12 -11
  28. package/src/entities.ts +8 -6
  29. package/src/entity-types/theme.ts +4 -0
  30. package/src/hooks/index.ts +4 -0
  31. package/src/hooks/test/use-entity-record.js +41 -1
  32. package/src/hooks/test/use-resource-permissions.js +32 -36
  33. package/src/hooks/use-entity-record.ts +16 -6
  34. package/src/hooks/use-resource-permissions.ts +82 -20
  35. package/src/index.js +0 -3
  36. package/src/resolvers.js +36 -24
package/CHANGELOG.md CHANGED
@@ -2,6 +2,12 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.14.0 (2022-08-24)
6
+
7
+ ### New Features
8
+
9
+ - Stabilized the `useResourcePermissions` hook ([#43268](https://github.com/WordPress/gutenberg/pull/43268))
10
+
5
11
  ## 4.13.0 (2022-08-10)
6
12
 
7
13
  ## 4.12.0 (2022-07-27)
package/README.md CHANGED
@@ -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>
@@ -870,6 +875,72 @@ _Returns_
870
875
 
871
876
  - `EntityRecordsResolution< RecordType >`: Entity records data.
872
877
 
878
+ ### useResourcePermissions
879
+
880
+ Resolves resource permissions.
881
+
882
+ _Usage_
883
+
884
+ ```js
885
+ import { useResourcePermissions } from '@wordpress/core-data';
886
+
887
+ function PagesList() {
888
+ const { canCreate, isResolving } = useResourcePermissions( 'pages' );
889
+
890
+ if ( isResolving ) {
891
+ return 'Loading ...';
892
+ }
893
+
894
+ return (
895
+ <div>
896
+ { canCreate ? <button>+ Create a new page</button> : false }
897
+ // ...
898
+ </div>
899
+ );
900
+ }
901
+
902
+ // Rendered in the application:
903
+ // <PagesList />
904
+ ```
905
+
906
+ ```js
907
+ import { useResourcePermissions } from '@wordpress/core-data';
908
+
909
+ function Page( { pageId } ) {
910
+ const { canCreate, canUpdate, canDelete, isResolving } =
911
+ useResourcePermissions( 'pages', pageId );
912
+
913
+ if ( isResolving ) {
914
+ return 'Loading ...';
915
+ }
916
+
917
+ return (
918
+ <div>
919
+ { canCreate ? <button>+ Create a new page</button> : false }
920
+ { canUpdate ? <button>Edit page</button> : false }
921
+ { canDelete ? <button>Delete page</button> : false }
922
+ // ...
923
+ </div>
924
+ );
925
+ }
926
+
927
+ // Rendered in the application:
928
+ // <Page pageId={ 15 } />
929
+ ```
930
+
931
+ In the above example, when `PagesList` is rendered into an
932
+ application, the appropriate permissions and the resolution details will be retrieved from
933
+ the store state using `canUser()`, or resolved if missing.
934
+
935
+ _Parameters_
936
+
937
+ - _resource_ `string`: The resource in question, e.g. media.
938
+ - _id_ `IdType`: ID of a specific resource entry, if needed, e.g. 10.
939
+
940
+ _Returns_
941
+
942
+ - `ResourcePermissionsResolution< IdType >`: Entity records data.
943
+
873
944
  <!-- END TOKEN(Autogenerated hooks|src/hooks/index.ts) -->
874
945
 
875
946
  ## 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"));
@@ -273,9 +275,9 @@ async function loadPostTypeEntities() {
273
275
  },
274
276
  rawAttributes: POST_RAW_ATTRIBUTES,
275
277
  getTitle: record => {
276
- var _record$title2;
278
+ var _record$title2, _record$slug;
277
279
 
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, _lodash.startCase)(record.slug) : String(record.id));
280
+ 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
281
  },
280
282
  __unstablePrePersist: isTemplate ? undefined : prePersistPostType,
281
283
  __unstable_rest_base: postType.rest_base
@@ -336,9 +338,9 @@ const getMethodName = function (kind, name) {
336
338
  kind,
337
339
  name
338
340
  });
339
- const kindPrefix = kind === 'root' ? '' : (0, _lodash.upperFirst)((0, _lodash.camelCase)(kind));
340
- const nameSuffix = (0, _lodash.upperFirst)((0, _lodash.camelCase)(name)) + (usePlural ? 's' : '');
341
- const suffix = usePlural && 'plural' in entityConfig && entityConfig !== null && entityConfig !== void 0 && entityConfig.plural ? (0, _lodash.upperFirst)((0, _lodash.camelCase)(entityConfig.plural)) : nameSuffix;
341
+ const kindPrefix = kind === 'root' ? '' : (0, _changeCase.pascalCase)(kind);
342
+ const nameSuffix = (0, _changeCase.pascalCase)(name) + (usePlural ? 's' : '');
343
+ const suffix = usePlural && 'plural' in entityConfig && entityConfig !== null && entityConfig !== void 0 && entityConfig.plural ? (0, _changeCase.pascalCase)(entityConfig.plural) : nameSuffix;
342
344
  return `${prefix}${kindPrefix}${suffix}`;
343
345
  };
344
346
  /**
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/entities.ts"],"names":["DEFAULT_ENTITY_KEY","POST_RAW_ATTRIBUTES","attachmentConfig","name","kind","baseURL","baseURLParams","context","plural","label","rawAttributes","siteConfig","getTitle","record","postTypeConfig","key","taxonomyConfig","sidebarConfig","transientEdits","blocks","widgetConfig","widgetTypeConfig","userConfig","commentConfig","menuConfig","menuItemConfig","menuLocationConfig","globalStyleConfig","title","rendered","themeConfig","pluginConfig","rootEntitiesConfig","_fields","join","additionalEntityConfigLoaders","loadEntities","loadPostTypeEntities","loadTaxonomyEntities","prePersistPostType","persistedRecord","edits","newEdits","status","postTypes","path","postType","isTemplate","includes","namespace","rest_namespace","rest_base","selection","mergedEdits","meta","slug","String","id","__unstablePrePersist","undefined","__unstable_rest_base","taxonomies","taxonomy","getMethodName","prefix","usePlural","entityConfig","kindPrefix","nameSuffix","suffix","getOrLoadEntitiesConfig","select","dispatch","configs","getEntitiesConfig","length","loader"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AAKA;;AAdA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;AAYO,MAAMA,kBAAkB,GAAG,IAA3B;;AAEP,MAAMC,mBAAmB,GAAG,CAAE,OAAF,EAAW,SAAX,EAAsB,SAAtB,CAA5B;AAYA,MAAMC,gBAA8C,GAAG;AACtDC,EAAAA,IAAI,EAAE,OADgD;AAEtDC,EAAAA,IAAI,EAAE,MAFgD;AAGtDC,EAAAA,OAAO,EAAE,cAH6C;AAItDC,EAAAA,aAAa,EAAE;AAAEC,IAAAA,OAAO,EAAE;AAAX,GAJuC;AAKtDC,EAAAA,MAAM,EAAE,YAL8C;AAMtDC,EAAAA,KAAK,EAAE,cAAI,OAAJ,CAN+C;AAOtDC,EAAAA,aAAa,EAAE,CAAE,SAAF,EAAa,OAAb,EAAsB,aAAtB;AAPuC,CAAvD;AAmBA,MAAMC,UAAkC,GAAG;AAC1CF,EAAAA,KAAK,EAAE,cAAI,MAAJ,CADmC;AAE1CN,EAAAA,IAAI,EAAE,MAFoC;AAG1CC,EAAAA,IAAI,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0D,YAAY,CAAC1D,MAAxB,CAAZ,CADH,GAEG4D,UAHJ;AAIA,SAAQ,GAAGJ,MAAQ,GAAGG,UAAY,GAAGE,MAAQ,EAA7C;AACA,CAfM;AAiBP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,uBAAuB,GACjClE,IAAF,IACA,cAAkC;AAAA,MAA1B;AAAEmE,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAA0B;AACjC,MAAIC,OAAO,GAAGF,MAAM,CAACG,iBAAP,CAA0BtE,IAA1B,CAAd;;AACA,MAAKqE,OAAO,IAAIA,OAAO,CAACE,MAAR,KAAmB,CAAnC,EAAuC;AACtC,WAAOF,OAAP;AACA;;AAED,QAAMG,MAAM,GAAG,kBAAMzC,6BAAN,EAAqC;AAAE/B,IAAAA;AAAF,GAArC,CAAf;;AACA,MAAK,CAAEwE,MAAP,EAAgB;AACf,WAAO,EAAP;AACA;;AAEDH,EAAAA,OAAO,GAAG,MAAMG,MAAM,CAACxC,YAAP,EAAhB;AACAoC,EAAAA,QAAQ,CAAE,0BAAaC,OAAb,CAAF,CAAR;AAEA,SAAOA,OAAP;AACA,CAjBK","sourcesContent":["/**\n * External dependencies\n */\nimport { upperFirst, camelCase, map, find, get, startCase } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { addEntities } from './actions';\nimport type * as Records from './entity-types';\nimport type {\n\tEntityType,\n\tContext,\n\tPost,\n\tTaxonomy,\n\tType,\n\tUpdatable,\n} from './entity-types';\n\nexport const DEFAULT_ENTITY_KEY = 'id';\n\nconst POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];\n\ntype AttachmentEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'media';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Attachment< C >,\n\tC\n>;\n\nconst attachmentConfig: AttachmentEntity[ 'config' ] = {\n\tname: 'media',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/media',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'mediaItems',\n\tlabel: __( 'Media' ),\n\trawAttributes: [ 'caption', 'title', 'description' ],\n};\n\ntype SiteEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'site';\n\t\tkind: 'root';\n\t},\n\tRecords.Settings< C >,\n\tC\n>;\n\nconst siteConfig: SiteEntity[ 'config' ] = {\n\tlabel: __( 'Site' ),\n\tname: 'site',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/settings',\n\tgetTitle: ( record: Records.Settings< 'edit' > ) => {\n\t\treturn get( record, [ 'title' ], __( 'Site Title' ) );\n\t},\n};\n\ntype PostTypeEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'postType';\n\t\tkind: 'root';\n\t\tkey: 'slug';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Type< C >,\n\tC\n>;\n\nconst postTypeConfig: PostTypeEntity[ 'config' ] = {\n\tlabel: __( 'Post Type' ),\n\tname: 'postType',\n\tkind: 'root',\n\tkey: 'slug',\n\tbaseURL: '/wp/v2/types',\n\tbaseURLParams: { context: 'edit' },\n};\n\ntype TaxonomyEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'taxonomy';\n\t\tkind: 'root';\n\t\tkey: 'slug';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Taxonomy< C >,\n\tC\n>;\n\nconst taxonomyConfig: TaxonomyEntity[ 'config' ] = {\n\tname: 'taxonomy',\n\tkind: 'root',\n\tkey: 'slug',\n\tbaseURL: '/wp/v2/taxonomies',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'taxonomies',\n\tlabel: __( 'Taxonomy' ),\n};\n\ntype SidebarEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'sidebar';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Sidebar< C >,\n\tC\n>;\n\nconst sidebarConfig: SidebarEntity[ 'config' ] = {\n\tname: 'sidebar',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/sidebars',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'sidebars',\n\ttransientEdits: { blocks: true },\n\tlabel: __( 'Widget areas' ),\n};\n\ntype WidgetEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'widget';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Widget< C >,\n\tC\n>;\nconst widgetConfig: WidgetEntity[ 'config' ] = {\n\tname: 'widget',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/widgets',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'widgets',\n\ttransientEdits: { blocks: true },\n\tlabel: __( 'Widgets' ),\n};\n\ntype WidgetTypeEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'widgetType';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.WidgetType< C >,\n\tC\n>;\nconst widgetTypeConfig: WidgetTypeEntity[ 'config' ] = {\n\tname: 'widgetType',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/widget-types',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'widgetTypes',\n\tlabel: __( 'Widget types' ),\n};\n\ntype UserEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'user';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.User< C >,\n\tC\n>;\nconst userConfig: UserEntity[ 'config' ] = {\n\tlabel: __( 'User' ),\n\tname: 'user',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/users',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'users',\n};\n\ntype CommentEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'comment';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Comment< C >,\n\tC\n>;\nconst commentConfig: CommentEntity[ 'config' ] = {\n\tname: 'comment',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/comments',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'comments',\n\tlabel: __( 'Comment' ),\n};\n\ntype NavMenuEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'menu';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.NavMenu< C >,\n\tC\n>;\n\nconst menuConfig: NavMenuEntity[ 'config' ] = {\n\tname: 'menu',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/menus',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'menus',\n\tlabel: __( 'Menu' ),\n};\n\ntype NavMenuItemEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'menuItem';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.NavMenuItem< C >,\n\tC\n>;\n\nconst menuItemConfig: NavMenuItemEntity[ 'config' ] = {\n\tname: 'menuItem',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/menu-items',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'menuItems',\n\tlabel: __( 'Menu Item' ),\n\trawAttributes: [ 'title' ],\n};\n\ntype MenuLocationEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'menuLocation';\n\t\tkind: 'root';\n\t\tkey: 'name';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.MenuLocation< C >,\n\tC\n>;\n\nconst menuLocationConfig: MenuLocationEntity[ 'config' ] = {\n\tname: 'menuLocation',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/menu-locations',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'menuLocations',\n\tlabel: __( 'Menu Location' ),\n\tkey: 'name',\n};\n\nconst globalStyleConfig = {\n\tlabel: __( 'Global Styles' ),\n\tname: 'globalStyles',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/global-styles',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'globalStylesVariations', // Should be different than name.\n\tgetTitle: ( record ) => record?.title?.rendered || record?.title,\n};\n\ntype ThemeEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'theme';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t\tkey: 'stylesheet';\n\t},\n\tRecords.Theme< C >,\n\tC\n>;\n\nconst themeConfig: ThemeEntity[ 'config' ] = {\n\tlabel: __( 'Themes' ),\n\tname: 'theme',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/themes',\n\tbaseURLParams: { context: 'edit' },\n\tkey: 'stylesheet',\n};\n\ntype PluginEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'plugin';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t\tkey: 'plugin';\n\t},\n\tRecords.Plugin< C >,\n\tC\n>;\nconst pluginConfig: PluginEntity[ 'config' ] = {\n\tlabel: __( 'Plugins' ),\n\tname: 'plugin',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/plugins',\n\tbaseURLParams: { context: 'edit' },\n\tkey: 'plugin',\n};\n\nexport const rootEntitiesConfig = [\n\t{\n\t\tlabel: __( 'Base' ),\n\t\tkind: 'root',\n\t\tname: '__unstableBase',\n\t\tbaseURL: '/',\n\t\tbaseURLParams: {\n\t\t\t_fields: [\n\t\t\t\t'description',\n\t\t\t\t'gmt_offset',\n\t\t\t\t'home',\n\t\t\t\t'name',\n\t\t\t\t'site_icon',\n\t\t\t\t'site_icon_url',\n\t\t\t\t'site_logo',\n\t\t\t\t'timezone_string',\n\t\t\t\t'url',\n\t\t\t].join( ',' ),\n\t\t},\n\t},\n\tsiteConfig,\n\tpostTypeConfig,\n\tattachmentConfig,\n\ttaxonomyConfig,\n\tsidebarConfig,\n\twidgetConfig,\n\twidgetTypeConfig,\n\tuserConfig,\n\tcommentConfig,\n\tmenuConfig,\n\tmenuItemConfig,\n\tmenuLocationConfig,\n\tglobalStyleConfig,\n\tthemeConfig,\n\tpluginConfig,\n];\n\ntype PostTypeConfig = {\n\tkind: 'postType';\n\tkey: 'id';\n\tdefaultContext: 'edit';\n};\n\ntype PostEntity< C extends Context = Context > = EntityType<\n\tPostTypeConfig & { name: 'post' },\n\tRecords.Post< C >,\n\tC\n>;\ntype PageEntity< C extends Context > = EntityType<\n\tPostTypeConfig & { name: 'page' },\n\tRecords.Page< C >,\n\tC\n>;\ntype WpTemplateEntity< C extends Context > = EntityType<\n\tPostTypeConfig & { name: 'wp_template' },\n\tRecords.WpTemplate< C >,\n\tC\n>;\ntype WpTemplatePartEntity< C extends Context > = EntityType<\n\tPostTypeConfig & { name: 'wp_template_part' },\n\tRecords.WpTemplatePart< C >,\n\tC\n>;\n\nexport type CoreEntities< C extends Context > =\n\t| SiteEntity< C >\n\t| PostTypeEntity< C >\n\t| AttachmentEntity< C >\n\t| TaxonomyEntity< C >\n\t| SidebarEntity< C >\n\t| WidgetEntity< C >\n\t| WidgetTypeEntity< C >\n\t| UserEntity< C >\n\t| CommentEntity< C >\n\t| NavMenuEntity< C >\n\t| NavMenuItemEntity< C >\n\t| MenuLocationEntity< C >\n\t| ThemeEntity< C >\n\t| PluginEntity< C >\n\t| PostEntity< C >\n\t| PageEntity< C >\n\t| WpTemplateEntity< C >\n\t| WpTemplatePartEntity< C >;\n\nexport const additionalEntityConfigLoaders = [\n\t{ kind: 'postType', loadEntities: loadPostTypeEntities },\n\t{ kind: 'taxonomy', loadEntities: loadTaxonomyEntities },\n];\n\n/**\n * Returns a function to be used to retrieve extra edits to apply before persisting a post type.\n *\n * @param {Object} persistedRecord Already persisted Post\n * @param {Object} edits Edits.\n * @return {Object} Updated edits.\n */\nexport const prePersistPostType = ( persistedRecord, edits ) => {\n\tconst newEdits = {} as Partial< Updatable< Post< 'edit' > > >;\n\n\tif ( persistedRecord?.status === 'auto-draft' ) {\n\t\t// Saving an auto-draft should create a draft by default.\n\t\tif ( ! edits.status && ! newEdits.status ) {\n\t\t\tnewEdits.status = 'draft';\n\t\t}\n\n\t\t// Fix the auto-draft default title.\n\t\tif (\n\t\t\t( ! edits.title || edits.title === 'Auto Draft' ) &&\n\t\t\t! newEdits.title &&\n\t\t\t( ! persistedRecord?.title ||\n\t\t\t\tpersistedRecord?.title === 'Auto Draft' )\n\t\t) {\n\t\t\tnewEdits.title = '';\n\t\t}\n\t}\n\n\treturn newEdits;\n};\n\n/**\n * Returns the list of post type entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadPostTypeEntities() {\n\tconst postTypes = ( await apiFetch( {\n\t\tpath: '/wp/v2/types?context=view',\n\t} ) ) as Record< string, Type< 'view' > >;\n\treturn map( postTypes, ( postType, name ) => {\n\t\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tname\n\t\t);\n\t\tconst namespace = postType?.rest_namespace ?? 'wp/v2';\n\t\treturn {\n\t\t\tkind: 'postType',\n\t\t\tbaseURL: `/${ namespace }/${ postType.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: postType.name,\n\t\t\ttransientEdits: {\n\t\t\t\tblocks: true,\n\t\t\t\tselection: true,\n\t\t\t},\n\t\t\tmergedEdits: { meta: true },\n\t\t\trawAttributes: POST_RAW_ATTRIBUTES,\n\t\t\tgetTitle: ( record ) =>\n\t\t\t\trecord?.title?.rendered ||\n\t\t\t\trecord?.title ||\n\t\t\t\t( isTemplate ? startCase( record.slug ) : String( record.id ) ),\n\t\t\t__unstablePrePersist: isTemplate ? undefined : prePersistPostType,\n\t\t\t__unstable_rest_base: postType.rest_base,\n\t\t};\n\t} );\n}\n\n/**\n * Returns the list of the taxonomies entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadTaxonomyEntities() {\n\tconst taxonomies = ( await apiFetch( {\n\t\tpath: '/wp/v2/taxonomies?context=view',\n\t} ) ) as Record< string, Taxonomy< 'view' > >;\n\treturn map( taxonomies, ( taxonomy, name ) => {\n\t\tconst namespace = taxonomy?.rest_namespace ?? 'wp/v2';\n\t\treturn {\n\t\t\tkind: 'taxonomy',\n\t\t\tbaseURL: `/${ namespace }/${ taxonomy.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: taxonomy.name,\n\t\t};\n\t} );\n}\n\n/**\n * Returns the entity's getter method name given its kind and name.\n *\n * @example\n * ```js\n * const nameSingular = getMethodName( 'root', 'theme', 'get' );\n * // nameSingular is getRootTheme\n *\n * const namePlural = getMethodName( 'root', 'theme', 'set' );\n * // namePlural is setRootThemes\n * ```\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} prefix Function prefix.\n * @param {boolean} usePlural Whether to use the plural form or not.\n *\n * @return {string} Method name\n */\nexport const getMethodName = (\n\tkind,\n\tname,\n\tprefix = 'get',\n\tusePlural = false\n) => {\n\tconst entityConfig = find( rootEntitiesConfig, { kind, name } );\n\tconst kindPrefix = kind === 'root' ? '' : upperFirst( camelCase( kind ) );\n\tconst nameSuffix =\n\t\tupperFirst( camelCase( name ) ) + ( usePlural ? 's' : '' );\n\tconst suffix =\n\t\tusePlural && 'plural' in entityConfig! && entityConfig?.plural\n\t\t\t? upperFirst( camelCase( entityConfig.plural ) )\n\t\t\t: nameSuffix;\n\treturn `${ prefix }${ kindPrefix }${ suffix }`;\n};\n\n/**\n * Loads the kind entities into the store.\n *\n * @param {string} kind Kind\n *\n * @return {(thunkArgs: object) => Promise<Array>} Entities\n */\nexport const getOrLoadEntitiesConfig =\n\t( kind ) =>\n\tasync ( { select, dispatch } ) => {\n\t\tlet configs = select.getEntitiesConfig( kind );\n\t\tif ( configs && configs.length !== 0 ) {\n\t\t\treturn configs;\n\t\t}\n\n\t\tconst loader = find( additionalEntityConfigLoaders, { kind } );\n\t\tif ( ! loader ) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconfigs = await loader.loadEntities();\n\t\tdispatch( addEntities( configs ) );\n\n\t\treturn configs;\n\t};\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/entities.ts"],"names":["DEFAULT_ENTITY_KEY","POST_RAW_ATTRIBUTES","attachmentConfig","name","kind","baseURL","baseURLParams","context","plural","label","rawAttributes","siteConfig","getTitle","record","postTypeConfig","key","taxonomyConfig","sidebarConfig","transientEdits","blocks","widgetConfig","widgetTypeConfig","userConfig","commentConfig","menuConfig","menuItemConfig","menuLocationConfig","globalStyleConfig","title","rendered","themeConfig","pluginConfig","rootEntitiesConfig","_fields","join","additionalEntityConfigLoaders","loadEntities","loadPostTypeEntities","loadTaxonomyEntities","prePersistPostType","persistedRecord","edits","newEdits","status","postTypes","path","postType","isTemplate","includes","namespace","rest_namespace","rest_base","selection","mergedEdits","meta","slug","String","id","__unstablePrePersist","undefined","__unstable_rest_base","taxonomies","taxonomy","getMethodName","prefix","usePlural","entityConfig","kindPrefix","nameSuffix","suffix","getOrLoadEntitiesConfig","select","dispatch","configs","getEntitiesConfig","length","loader"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AACA;;AAKA;;AAfA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;AAYO,MAAMA,kBAAkB,GAAG,IAA3B;;AAEP,MAAMC,mBAAmB,GAAG,CAAE,OAAF,EAAW,SAAX,EAAsB,SAAtB,CAA5B;AAYA,MAAMC,gBAA8C,GAAG;AACtDC,EAAAA,IAAI,EAAE,OADgD;AAEtDC,EAAAA,IAAI,EAAE,MAFgD;AAGtDC,EAAAA,OAAO,EAAE,cAH6C;AAItDC,EAAAA,aAAa,EAAE;AAAEC,IAAAA,OAAO,EAAE;AAAX,GAJuC;AAKtDC,EAAAA,MAAM,EAAE,YAL8C;AAMtDC,EAAAA,KAAK,EAAE,cAAI,OAAJ,CAN+C;AAOtDC,EAAAA,aAAa,EAAE,CAAE,SAAF,EAAa,OAAb,EAAsB,aAAtB;AAPuC,CAAvD;AAmBA,MAAMC,UAAkC,GAAG;AAC1CF,EAAAA,KAAK,EAAE,cAAI,MAAJ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AA0CA,YAAY,CAAE1D,MAAxD,GACG,4BAAY0D,YAAY,CAAC1D,MAAzB,CADH,GAEG4D,UAHJ;AAIA,SAAQ,GAAGJ,MAAQ,GAAGG,UAAY,GAAGE,MAAQ,EAA7C;AACA,CAdM;AAgBP;AACA;AACA;AACA;AACA;AACA;AACA;;;;;AACO,MAAMC,uBAAuB,GACjClE,IAAF,IACA,cAAkC;AAAA,MAA1B;AAAEmE,IAAAA,MAAF;AAAUC,IAAAA;AAAV,GAA0B;AACjC,MAAIC,OAAO,GAAGF,MAAM,CAACG,iBAAP,CAA0BtE,IAA1B,CAAd;;AACA,MAAKqE,OAAO,IAAIA,OAAO,CAACE,MAAR,KAAmB,CAAnC,EAAuC;AACtC,WAAOF,OAAP;AACA;;AAED,QAAMG,MAAM,GAAG,kBAAMzC,6BAAN,EAAqC;AAAE/B,IAAAA;AAAF,GAArC,CAAf;;AACA,MAAK,CAAEwE,MAAP,EAAgB;AACf,WAAO,EAAP;AACA;;AAEDH,EAAAA,OAAO,GAAG,MAAMG,MAAM,CAACxC,YAAP,EAAhB;AACAoC,EAAAA,QAAQ,CAAE,0BAAaC,OAAb,CAAF,CAAR;AAEA,SAAOA,OAAP;AACA,CAjBK","sourcesContent":["/**\n * External dependencies\n */\nimport { capitalCase, pascalCase } from 'change-case';\nimport { map, find, get } from 'lodash';\n\n/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport { addEntities } from './actions';\nimport type * as Records from './entity-types';\nimport type {\n\tEntityType,\n\tContext,\n\tPost,\n\tTaxonomy,\n\tType,\n\tUpdatable,\n} from './entity-types';\n\nexport const DEFAULT_ENTITY_KEY = 'id';\n\nconst POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];\n\ntype AttachmentEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'media';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Attachment< C >,\n\tC\n>;\n\nconst attachmentConfig: AttachmentEntity[ 'config' ] = {\n\tname: 'media',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/media',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'mediaItems',\n\tlabel: __( 'Media' ),\n\trawAttributes: [ 'caption', 'title', 'description' ],\n};\n\ntype SiteEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'site';\n\t\tkind: 'root';\n\t},\n\tRecords.Settings< C >,\n\tC\n>;\n\nconst siteConfig: SiteEntity[ 'config' ] = {\n\tlabel: __( 'Site' ),\n\tname: 'site',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/settings',\n\tgetTitle: ( record: Records.Settings< 'edit' > ) => {\n\t\treturn get( record, [ 'title' ], __( 'Site Title' ) );\n\t},\n};\n\ntype PostTypeEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'postType';\n\t\tkind: 'root';\n\t\tkey: 'slug';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Type< C >,\n\tC\n>;\n\nconst postTypeConfig: PostTypeEntity[ 'config' ] = {\n\tlabel: __( 'Post Type' ),\n\tname: 'postType',\n\tkind: 'root',\n\tkey: 'slug',\n\tbaseURL: '/wp/v2/types',\n\tbaseURLParams: { context: 'edit' },\n};\n\ntype TaxonomyEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'taxonomy';\n\t\tkind: 'root';\n\t\tkey: 'slug';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Taxonomy< C >,\n\tC\n>;\n\nconst taxonomyConfig: TaxonomyEntity[ 'config' ] = {\n\tname: 'taxonomy',\n\tkind: 'root',\n\tkey: 'slug',\n\tbaseURL: '/wp/v2/taxonomies',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'taxonomies',\n\tlabel: __( 'Taxonomy' ),\n};\n\ntype SidebarEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'sidebar';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Sidebar< C >,\n\tC\n>;\n\nconst sidebarConfig: SidebarEntity[ 'config' ] = {\n\tname: 'sidebar',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/sidebars',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'sidebars',\n\ttransientEdits: { blocks: true },\n\tlabel: __( 'Widget areas' ),\n};\n\ntype WidgetEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'widget';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Widget< C >,\n\tC\n>;\nconst widgetConfig: WidgetEntity[ 'config' ] = {\n\tname: 'widget',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/widgets',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'widgets',\n\ttransientEdits: { blocks: true },\n\tlabel: __( 'Widgets' ),\n};\n\ntype WidgetTypeEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'widgetType';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.WidgetType< C >,\n\tC\n>;\nconst widgetTypeConfig: WidgetTypeEntity[ 'config' ] = {\n\tname: 'widgetType',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/widget-types',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'widgetTypes',\n\tlabel: __( 'Widget types' ),\n};\n\ntype UserEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'user';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.User< C >,\n\tC\n>;\nconst userConfig: UserEntity[ 'config' ] = {\n\tlabel: __( 'User' ),\n\tname: 'user',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/users',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'users',\n};\n\ntype CommentEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'comment';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.Comment< C >,\n\tC\n>;\nconst commentConfig: CommentEntity[ 'config' ] = {\n\tname: 'comment',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/comments',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'comments',\n\tlabel: __( 'Comment' ),\n};\n\ntype NavMenuEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'menu';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.NavMenu< C >,\n\tC\n>;\n\nconst menuConfig: NavMenuEntity[ 'config' ] = {\n\tname: 'menu',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/menus',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'menus',\n\tlabel: __( 'Menu' ),\n};\n\ntype NavMenuItemEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'menuItem';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.NavMenuItem< C >,\n\tC\n>;\n\nconst menuItemConfig: NavMenuItemEntity[ 'config' ] = {\n\tname: 'menuItem',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/menu-items',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'menuItems',\n\tlabel: __( 'Menu Item' ),\n\trawAttributes: [ 'title' ],\n};\n\ntype MenuLocationEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'menuLocation';\n\t\tkind: 'root';\n\t\tkey: 'name';\n\t\tbaseURLParams: { context: 'edit' };\n\t},\n\tRecords.MenuLocation< C >,\n\tC\n>;\n\nconst menuLocationConfig: MenuLocationEntity[ 'config' ] = {\n\tname: 'menuLocation',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/menu-locations',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'menuLocations',\n\tlabel: __( 'Menu Location' ),\n\tkey: 'name',\n};\n\nconst globalStyleConfig = {\n\tlabel: __( 'Global Styles' ),\n\tname: 'globalStyles',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/global-styles',\n\tbaseURLParams: { context: 'edit' },\n\tplural: 'globalStylesVariations', // Should be different than name.\n\tgetTitle: ( record ) => record?.title?.rendered || record?.title,\n};\n\ntype ThemeEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'theme';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t\tkey: 'stylesheet';\n\t},\n\tRecords.Theme< C >,\n\tC\n>;\n\nconst themeConfig: ThemeEntity[ 'config' ] = {\n\tlabel: __( 'Themes' ),\n\tname: 'theme',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/themes',\n\tbaseURLParams: { context: 'edit' },\n\tkey: 'stylesheet',\n};\n\ntype PluginEntity< C extends Context = Context > = EntityType<\n\t{\n\t\tname: 'plugin';\n\t\tkind: 'root';\n\t\tbaseURLParams: { context: 'edit' };\n\t\tkey: 'plugin';\n\t},\n\tRecords.Plugin< C >,\n\tC\n>;\nconst pluginConfig: PluginEntity[ 'config' ] = {\n\tlabel: __( 'Plugins' ),\n\tname: 'plugin',\n\tkind: 'root',\n\tbaseURL: '/wp/v2/plugins',\n\tbaseURLParams: { context: 'edit' },\n\tkey: 'plugin',\n};\n\nexport const rootEntitiesConfig = [\n\t{\n\t\tlabel: __( 'Base' ),\n\t\tkind: 'root',\n\t\tname: '__unstableBase',\n\t\tbaseURL: '/',\n\t\tbaseURLParams: {\n\t\t\t_fields: [\n\t\t\t\t'description',\n\t\t\t\t'gmt_offset',\n\t\t\t\t'home',\n\t\t\t\t'name',\n\t\t\t\t'site_icon',\n\t\t\t\t'site_icon_url',\n\t\t\t\t'site_logo',\n\t\t\t\t'timezone_string',\n\t\t\t\t'url',\n\t\t\t].join( ',' ),\n\t\t},\n\t},\n\tsiteConfig,\n\tpostTypeConfig,\n\tattachmentConfig,\n\ttaxonomyConfig,\n\tsidebarConfig,\n\twidgetConfig,\n\twidgetTypeConfig,\n\tuserConfig,\n\tcommentConfig,\n\tmenuConfig,\n\tmenuItemConfig,\n\tmenuLocationConfig,\n\tglobalStyleConfig,\n\tthemeConfig,\n\tpluginConfig,\n];\n\ntype PostTypeConfig = {\n\tkind: 'postType';\n\tkey: 'id';\n\tdefaultContext: 'edit';\n};\n\ntype PostEntity< C extends Context = Context > = EntityType<\n\tPostTypeConfig & { name: 'post' },\n\tRecords.Post< C >,\n\tC\n>;\ntype PageEntity< C extends Context > = EntityType<\n\tPostTypeConfig & { name: 'page' },\n\tRecords.Page< C >,\n\tC\n>;\ntype WpTemplateEntity< C extends Context > = EntityType<\n\tPostTypeConfig & { name: 'wp_template' },\n\tRecords.WpTemplate< C >,\n\tC\n>;\ntype WpTemplatePartEntity< C extends Context > = EntityType<\n\tPostTypeConfig & { name: 'wp_template_part' },\n\tRecords.WpTemplatePart< C >,\n\tC\n>;\n\nexport type CoreEntities< C extends Context > =\n\t| SiteEntity< C >\n\t| PostTypeEntity< C >\n\t| AttachmentEntity< C >\n\t| TaxonomyEntity< C >\n\t| SidebarEntity< C >\n\t| WidgetEntity< C >\n\t| WidgetTypeEntity< C >\n\t| UserEntity< C >\n\t| CommentEntity< C >\n\t| NavMenuEntity< C >\n\t| NavMenuItemEntity< C >\n\t| MenuLocationEntity< C >\n\t| ThemeEntity< C >\n\t| PluginEntity< C >\n\t| PostEntity< C >\n\t| PageEntity< C >\n\t| WpTemplateEntity< C >\n\t| WpTemplatePartEntity< C >;\n\nexport const additionalEntityConfigLoaders = [\n\t{ kind: 'postType', loadEntities: loadPostTypeEntities },\n\t{ kind: 'taxonomy', loadEntities: loadTaxonomyEntities },\n];\n\n/**\n * Returns a function to be used to retrieve extra edits to apply before persisting a post type.\n *\n * @param {Object} persistedRecord Already persisted Post\n * @param {Object} edits Edits.\n * @return {Object} Updated edits.\n */\nexport const prePersistPostType = ( persistedRecord, edits ) => {\n\tconst newEdits = {} as Partial< Updatable< Post< 'edit' > > >;\n\n\tif ( persistedRecord?.status === 'auto-draft' ) {\n\t\t// Saving an auto-draft should create a draft by default.\n\t\tif ( ! edits.status && ! newEdits.status ) {\n\t\t\tnewEdits.status = 'draft';\n\t\t}\n\n\t\t// Fix the auto-draft default title.\n\t\tif (\n\t\t\t( ! edits.title || edits.title === 'Auto Draft' ) &&\n\t\t\t! newEdits.title &&\n\t\t\t( ! persistedRecord?.title ||\n\t\t\t\tpersistedRecord?.title === 'Auto Draft' )\n\t\t) {\n\t\t\tnewEdits.title = '';\n\t\t}\n\t}\n\n\treturn newEdits;\n};\n\n/**\n * Returns the list of post type entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadPostTypeEntities() {\n\tconst postTypes = ( await apiFetch( {\n\t\tpath: '/wp/v2/types?context=view',\n\t} ) ) as Record< string, Type< 'view' > >;\n\treturn map( postTypes, ( postType, name ) => {\n\t\tconst isTemplate = [ 'wp_template', 'wp_template_part' ].includes(\n\t\t\tname\n\t\t);\n\t\tconst namespace = postType?.rest_namespace ?? 'wp/v2';\n\t\treturn {\n\t\t\tkind: 'postType',\n\t\t\tbaseURL: `/${ namespace }/${ postType.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: postType.name,\n\t\t\ttransientEdits: {\n\t\t\t\tblocks: true,\n\t\t\t\tselection: true,\n\t\t\t},\n\t\t\tmergedEdits: { meta: true },\n\t\t\trawAttributes: POST_RAW_ATTRIBUTES,\n\t\t\tgetTitle: ( record ) =>\n\t\t\t\trecord?.title?.rendered ||\n\t\t\t\trecord?.title ||\n\t\t\t\t( isTemplate\n\t\t\t\t\t? capitalCase( record.slug ?? '' )\n\t\t\t\t\t: String( record.id ) ),\n\t\t\t__unstablePrePersist: isTemplate ? undefined : prePersistPostType,\n\t\t\t__unstable_rest_base: postType.rest_base,\n\t\t};\n\t} );\n}\n\n/**\n * Returns the list of the taxonomies entities.\n *\n * @return {Promise} Entities promise\n */\nasync function loadTaxonomyEntities() {\n\tconst taxonomies = ( await apiFetch( {\n\t\tpath: '/wp/v2/taxonomies?context=view',\n\t} ) ) as Record< string, Taxonomy< 'view' > >;\n\treturn map( taxonomies, ( taxonomy, name ) => {\n\t\tconst namespace = taxonomy?.rest_namespace ?? 'wp/v2';\n\t\treturn {\n\t\t\tkind: 'taxonomy',\n\t\t\tbaseURL: `/${ namespace }/${ taxonomy.rest_base }`,\n\t\t\tbaseURLParams: { context: 'edit' },\n\t\t\tname,\n\t\t\tlabel: taxonomy.name,\n\t\t};\n\t} );\n}\n\n/**\n * Returns the entity's getter method name given its kind and name.\n *\n * @example\n * ```js\n * const nameSingular = getMethodName( 'root', 'theme', 'get' );\n * // nameSingular is getRootTheme\n *\n * const namePlural = getMethodName( 'root', 'theme', 'set' );\n * // namePlural is setRootThemes\n * ```\n *\n * @param {string} kind Entity kind.\n * @param {string} name Entity name.\n * @param {string} prefix Function prefix.\n * @param {boolean} usePlural Whether to use the plural form or not.\n *\n * @return {string} Method name\n */\nexport const getMethodName = (\n\tkind,\n\tname,\n\tprefix = 'get',\n\tusePlural = false\n) => {\n\tconst entityConfig = find( rootEntitiesConfig, { kind, name } );\n\tconst kindPrefix = kind === 'root' ? '' : pascalCase( kind );\n\tconst nameSuffix = pascalCase( name ) + ( usePlural ? 's' : '' );\n\tconst suffix =\n\t\tusePlural && 'plural' in entityConfig! && entityConfig?.plural\n\t\t\t? pascalCase( entityConfig.plural )\n\t\t\t: nameSuffix;\n\treturn `${ prefix }${ kindPrefix }${ suffix }`;\n};\n\n/**\n * Loads the kind entities into the store.\n *\n * @param {string} kind Kind\n *\n * @return {(thunkArgs: object) => Promise<Array>} Entities\n */\nexport const getOrLoadEntitiesConfig =\n\t( kind ) =>\n\tasync ( { select, dispatch } ) => {\n\t\tlet configs = select.getEntitiesConfig( kind );\n\t\tif ( configs && configs.length !== 0 ) {\n\t\t\treturn configs;\n\t\t}\n\n\t\tconst loader = find( additionalEntityConfigLoaders, { kind } );\n\t\tif ( ! loader ) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconfigs = await loader.loadEntities();\n\t\tdispatch( addEntities( configs ) );\n\n\t\treturn configs;\n\t};\n"]}
@@ -15,6 +15,12 @@ Object.defineProperty(exports, "__experimentalUseEntityRecords", {
15
15
  return _useEntityRecords.__experimentalUseEntityRecords;
16
16
  }
17
17
  });
18
+ Object.defineProperty(exports, "__experimentalUseResourcePermissions", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _useResourcePermissions.__experimentalUseResourcePermissions;
22
+ }
23
+ });
18
24
  Object.defineProperty(exports, "useEntityRecord", {
19
25
  enumerable: true,
20
26
  get: function () {
@@ -27,11 +33,19 @@ Object.defineProperty(exports, "useEntityRecords", {
27
33
  return _useEntityRecords.default;
28
34
  }
29
35
  });
36
+ Object.defineProperty(exports, "useResourcePermissions", {
37
+ enumerable: true,
38
+ get: function () {
39
+ return _useResourcePermissions.default;
40
+ }
41
+ });
30
42
 
31
43
  var _useEntityRecord = _interopRequireWildcard(require("./use-entity-record"));
32
44
 
33
45
  var _useEntityRecords = _interopRequireWildcard(require("./use-entity-records"));
34
46
 
47
+ var _useResourcePermissions = _interopRequireWildcard(require("./use-resource-permissions"));
48
+
35
49
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
36
50
 
37
51
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAIA","sourcesContent":["export {\n\tdefault as useEntityRecord,\n\t__experimentalUseEntityRecord,\n} from './use-entity-record';\nexport {\n\tdefault as useEntityRecords,\n\t__experimentalUseEntityRecords,\n} from './use-entity-records';\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/hooks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAIA;;AAIA","sourcesContent":["export {\n\tdefault as useEntityRecord,\n\t__experimentalUseEntityRecord,\n} from './use-entity-record';\nexport {\n\tdefault as useEntityRecords,\n\t__experimentalUseEntityRecords,\n} from './use-entity-records';\nexport {\n\tdefault as useResourcePermissions,\n\t__experimentalUseResourcePermissions,\n} from './use-resource-permissions';\n"]}
@@ -57,8 +57,8 @@ var _ = require("../");
57
57
  *
58
58
  * @example
59
59
  * ```js
60
- * import { useState } from '@wordpress/data';
61
60
  * import { useDispatch } from '@wordpress/data';
61
+ * import { useCallback } from '@wordpress/element';
62
62
  * import { __ } from '@wordpress/i18n';
63
63
  * import { TextControl } from '@wordpress/components';
64
64
  * import { store as noticeStore } from '@wordpress/notices';
@@ -66,17 +66,19 @@ var _ = require("../");
66
66
  *
67
67
  * function PageRenameForm( { id } ) {
68
68
  * const page = useEntityRecord( 'postType', 'page', id );
69
- * const [ title, setTitle ] = useState( () => page.record.title.rendered );
70
69
  * const { createSuccessNotice, createErrorNotice } =
71
70
  * useDispatch( noticeStore );
72
71
  *
72
+ * const setTitle = useCallback( ( title ) => {
73
+ * page.edit( { title } );
74
+ * }, [ page.edit ] );
75
+ *
73
76
  * if ( page.isResolving ) {
74
77
  * return 'Loading...';
75
78
  * }
76
79
  *
77
80
  * async function onRename( event ) {
78
81
  * event.preventDefault();
79
- * page.edit( { title } );
80
82
  * try {
81
83
  * await page.save();
82
84
  * createSuccessNotice( __( 'Page renamed.' ), {
@@ -91,7 +93,7 @@ var _ = require("../");
91
93
  * <form onSubmit={ onRename }>
92
94
  * <TextControl
93
95
  * label={ __( 'Name' ) }
94
- * value={ title }
96
+ * value={ page.editedRecord.title }
95
97
  * onChange={ setTitle }
96
98
  * />
97
99
  * <button type="submit">{ __( 'Save' ) }</button>
@@ -132,8 +134,8 @@ function useEntityRecord(kind, name, recordId) {
132
134
  editedRecord,
133
135
  hasEdits
134
136
  } = (0, _data.useSelect)(select => ({
135
- editedRecord: select(_.store).getEditedEntityRecord(),
136
- hasEdits: select(_.store).hasEditsForEntityRecord()
137
+ editedRecord: select(_.store).getEditedEntityRecord(kind, name, recordId),
138
+ hasEdits: select(_.store).hasEditsForEntityRecord(kind, name, recordId)
137
139
  }), [kind, name, recordId]);
138
140
  const {
139
141
  data: record,
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","coreStore","mutations","edit","record","save","saveOptions","throwOnError","editedRecord","hasEdits","select","getEditedEntityRecord","hasEditsForEntityRecord","data","querySelectRest","query","getEntityRecord","__experimentalUseEntityRecord","alternative","since"],"mappings":";;;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AAXA;AACA;AACA;;AAKA;AACA;AACA;;AA8CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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AmBe,eAAnB,CAAoCtB,IAApC,EAA0CC,IAA1C,EAAgDC,QAAhD,CAAP;AACA,GAN2C,EAO5C,CAAEF,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAO,CAACC,OAAhC,CAP4C,CAA7C;AAUA,SAAO;AACNM,IAAAA,MADM;AAENI,IAAAA,YAFM;AAGNC,IAAAA,QAHM;AAIN,OAAGK,eAJG;AAKN,OAAGZ;AALG,GAAP;AAOA;;AAEM,SAASe,6BAAT,CACNvB,IADM,EAENC,IAFM,EAGNC,QAHM,EAINC,OAJM,EAKL;AACD,2BAAa,uCAAb,EAAqD;AACpDqB,IAAAA,WAAW,EAAE,yBADuC;AAEpDC,IAAAA,KAAK,EAAE;AAF6C,GAArD;AAIA,SAAO1B,eAAe,CAAEC,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAxB,CAAtB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\nexport interface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: RecordType | null;\n\n\t/** The edited entity record */\n\teditedRecord: Partial< RecordType >;\n\n\t/** Apply local (in-browser) edits to the edited entity record */\n\tedit: ( diff: Partial< RecordType > ) => void;\n\n\t/** Persist the edits to the server */\n\tsave: () => Promise< void >;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Does the record have any local edits?\n\t */\n\thasEdits: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\nexport interface Options {\n\t/**\n\t * Whether to run the query or short-circuit and return null.\n\t *\n\t * @default true\n\t */\n\tenabled: boolean;\n}\n\n/**\n * Resolves the specified entity record.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param recordId ID of the requested entity record.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return record.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 1 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using `getEntityRecord()`, or resolved if missing.\n *\n * @example\n * ```js\n * import { useState } from '@wordpress/data';\n * import { useDispatch } from '@wordpress/data';\n * import { __ } from '@wordpress/i18n';\n * import { TextControl } from '@wordpress/components';\n * import { store as noticeStore } from '@wordpress/notices';\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageRenameForm( { id } ) {\n * \tconst page = useEntityRecord( 'postType', 'page', id );\n * \tconst [ title, setTitle ] = useState( () => page.record.title.rendered );\n * \tconst { createSuccessNotice, createErrorNotice } =\n * \t\tuseDispatch( noticeStore );\n *\n * \tif ( page.isResolving ) {\n * \t\treturn 'Loading...';\n * \t}\n *\n * \tasync function onRename( event ) {\n * \t\tevent.preventDefault();\n * \t\tpage.edit( { title } );\n * \t\ttry {\n * \t\t\tawait page.save();\n * \t\t\tcreateSuccessNotice( __( 'Page renamed.' ), {\n * \t\t\t\ttype: 'snackbar',\n * \t\t\t} );\n * \t\t} catch ( error ) {\n * \t\t\tcreateErrorNotice( error.message, { type: 'snackbar' } );\n * \t\t}\n * \t}\n *\n * \treturn (\n * \t\t<form onSubmit={ onRename }>\n * \t\t\t<TextControl\n * \t\t\t\tlabel={ __( 'Name' ) }\n * \t\t\t\tvalue={ title }\n * \t\t\t\tonChange={ setTitle }\n * \t\t\t/>\n * \t\t\t<button type=\"submit\">{ __( 'Save' ) }</button>\n * \t\t</form>\n * \t);\n * }\n *\n * // Rendered in the application:\n * // <PageRenameForm id={ 1 } />\n * ```\n *\n * In the above example, updating and saving the page title is handled\n * via the `edit()` and `save()` mutation helpers provided by\n * `useEntityRecord()`;\n *\n * @return Entity record data.\n * @template RecordType\n */\nexport default function useEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number,\n\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\n\tconst mutations = useMemo(\n\t\t() => ( {\n\t\t\tedit: ( record ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record ),\n\t\t\tsave: ( saveOptions: any = {} ) =>\n\t\t\t\tsaveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t...saveOptions,\n\t\t\t\t} ),\n\t\t} ),\n\t\t[ recordId ]\n\t);\n\n\tconst { editedRecord, hasEdits } = useSelect(\n\t\t( select ) => ( {\n\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(),\n\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(),\n\t\t} ),\n\t\t[ kind, name, recordId ]\n\t);\n\n\tconst { data: record, ...querySelectRest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecord( kind, name, recordId );\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\teditedRecord,\n\t\thasEdits,\n\t\t...querySelectRest,\n\t\t...mutations,\n\t};\n}\n\nexport function __experimentalUseEntityRecord(\n\tkind: string,\n\tname: string,\n\trecordId: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecord`, {\n\t\talternative: 'wp.data.useEntityRecord',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecord( kind, name, recordId, options );\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","coreStore","mutations","edit","record","save","saveOptions","throwOnError","editedRecord","hasEdits","select","getEditedEntityRecord","hasEditsForEntityRecord","data","querySelectRest","query","getEntityRecord","__experimentalUseEntityRecord","alternative","since"],"mappings":";;;;;;;;;;AAGA;;AACA;;AACA;;AAKA;;AACA;;AAXA;AACA;AACA;;AAKA;AACA;AACA;;AA8CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,eAAT,CACdC,IADc,EAEdC,IAFc,EAGdC,QAHc,EAKyB;AAAA,MADvCC,OACuC,uEADpB;AAAEC,IAAAA,OAAO,EAAE;AAAX,GACoB;AACvC,QAAM;AAAEC,IAAAA,gBAAF;AAAoBC,IAAAA;AAApB,MACL,uBAAaC,OAAb,CADD;AAGA,QAAMC,SAAS,GAAG,sBACjB,OAAQ;AACPC,IAAAA,IAAI,EAAIC,MAAF,IACLL,gBAAgB,CAAEL,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBQ,MAAxB,CAFV;AAGPC,IAAAA,IAAI,EAAE;AAAA,UAAEC,WAAF,uEAA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AK,EAAE;AAF6C,GAArD;AAIA,SAAO1B,eAAe,CAAEC,IAAF,EAAQC,IAAR,EAAcC,QAAd,EAAwBC,OAAxB,CAAtB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport deprecated from '@wordpress/deprecated';\nimport { useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useQuerySelect from './use-query-select';\nimport { store as coreStore } from '../';\nimport type { Status } from './constants';\n\nexport interface EntityRecordResolution< RecordType > {\n\t/** The requested entity record */\n\trecord: RecordType | null;\n\n\t/** The edited entity record */\n\teditedRecord: Partial< RecordType >;\n\n\t/** Apply local (in-browser) edits to the edited entity record */\n\tedit: ( diff: Partial< RecordType > ) => void;\n\n\t/** Persist the edits to the server */\n\tsave: () => Promise< void >;\n\n\t/**\n\t * Is the record still being resolved?\n\t */\n\tisResolving: boolean;\n\n\t/**\n\t * Does the record have any local edits?\n\t */\n\thasEdits: boolean;\n\n\t/**\n\t * Is the record resolved by now?\n\t */\n\thasResolved: boolean;\n\n\t/** Resolution status */\n\tstatus: Status;\n}\n\nexport interface Options {\n\t/**\n\t * Whether to run the query or short-circuit and return null.\n\t *\n\t * @default true\n\t */\n\tenabled: boolean;\n}\n\n/**\n * Resolves the specified entity record.\n *\n * @param kind Kind of the entity, e.g. `root` or a `postType`. See rootEntitiesConfig in ../entities.ts for a list of available kinds.\n * @param name Name of the entity, e.g. `plugin` or a `post`. See rootEntitiesConfig in ../entities.ts for a list of available names.\n * @param recordId ID of the requested entity record.\n * @param options Optional hook options.\n * @example\n * ```js\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageTitleDisplay( { id } ) {\n * const { record, isResolving } = useEntityRecord( 'postType', 'page', id );\n *\n * if ( isResolving ) {\n * return 'Loading...';\n * }\n *\n * return record.title;\n * }\n *\n * // Rendered in the application:\n * // <PageTitleDisplay id={ 1 } />\n * ```\n *\n * In the above example, when `PageTitleDisplay` is rendered into an\n * application, the page and the resolution details will be retrieved from\n * the store state using `getEntityRecord()`, or resolved if missing.\n *\n * @example\n * ```js\n * import { useDispatch } from '@wordpress/data';\n * import { useCallback } from '@wordpress/element';\n * import { __ } from '@wordpress/i18n';\n * import { TextControl } from '@wordpress/components';\n * import { store as noticeStore } from '@wordpress/notices';\n * import { useEntityRecord } from '@wordpress/core-data';\n *\n * function PageRenameForm( { id } ) {\n * \tconst page = useEntityRecord( 'postType', 'page', id );\n * \tconst { createSuccessNotice, createErrorNotice } =\n * \t\tuseDispatch( noticeStore );\n *\n * \tconst setTitle = useCallback( ( title ) => {\n * \t\tpage.edit( { title } );\n * \t}, [ page.edit ] );\n *\n * \tif ( page.isResolving ) {\n * \t\treturn 'Loading...';\n * \t}\n *\n * \tasync function onRename( event ) {\n * \t\tevent.preventDefault();\n * \t\ttry {\n * \t\t\tawait page.save();\n * \t\t\tcreateSuccessNotice( __( 'Page renamed.' ), {\n * \t\t\t\ttype: 'snackbar',\n * \t\t\t} );\n * \t\t} catch ( error ) {\n * \t\t\tcreateErrorNotice( error.message, { type: 'snackbar' } );\n * \t\t}\n * \t}\n *\n * \treturn (\n * \t\t<form onSubmit={ onRename }>\n * \t\t\t<TextControl\n * \t\t\t\tlabel={ __( 'Name' ) }\n * \t\t\t\tvalue={ page.editedRecord.title }\n * \t\t\t\tonChange={ setTitle }\n * \t\t\t/>\n * \t\t\t<button type=\"submit\">{ __( 'Save' ) }</button>\n * \t\t</form>\n * \t);\n * }\n *\n * // Rendered in the application:\n * // <PageRenameForm id={ 1 } />\n * ```\n *\n * In the above example, updating and saving the page title is handled\n * via the `edit()` and `save()` mutation helpers provided by\n * `useEntityRecord()`;\n *\n * @return Entity record data.\n * @template RecordType\n */\nexport default function useEntityRecord< RecordType >(\n\tkind: string,\n\tname: string,\n\trecordId: string | number,\n\toptions: Options = { enabled: true }\n): EntityRecordResolution< RecordType > {\n\tconst { editEntityRecord, saveEditedEntityRecord } =\n\t\tuseDispatch( coreStore );\n\n\tconst mutations = useMemo(\n\t\t() => ( {\n\t\t\tedit: ( record ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record ),\n\t\t\tsave: ( saveOptions: any = {} ) =>\n\t\t\t\tsaveEditedEntityRecord( kind, name, recordId, {\n\t\t\t\t\tthrowOnError: true,\n\t\t\t\t\t...saveOptions,\n\t\t\t\t} ),\n\t\t} ),\n\t\t[ recordId ]\n\t);\n\n\tconst { editedRecord, hasEdits } = useSelect(\n\t\t( select ) => ( {\n\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t} ),\n\t\t[ kind, name, recordId ]\n\t);\n\n\tconst { data: record, ...querySelectRest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn null;\n\t\t\t}\n\t\t\treturn query( coreStore ).getEntityRecord( kind, name, recordId );\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\treturn {\n\t\trecord,\n\t\teditedRecord,\n\t\thasEdits,\n\t\t...querySelectRest,\n\t\t...mutations,\n\t};\n}\n\nexport function __experimentalUseEntityRecord(\n\tkind: string,\n\tname: string,\n\trecordId: any,\n\toptions: any\n) {\n\tdeprecated( `wp.data.__experimentalUseEntityRecord`, {\n\t\talternative: 'wp.data.useEntityRecord',\n\t\tsince: '6.1',\n\t} );\n\treturn useEntityRecord( kind, name, recordId, options );\n}\n"]}
@@ -5,7 +5,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.default = __experimentalUseResourcePermissions;
8
+ exports.__experimentalUseResourcePermissions = __experimentalUseResourcePermissions;
9
+ exports.default = useResourcePermissions;
10
+
11
+ var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
9
12
 
10
13
  var _ = require("../");
11
14
 
@@ -13,6 +16,10 @@ var _constants = require("./constants");
13
16
 
14
17
  var _useQuerySelect = _interopRequireDefault(require("./use-query-select"));
15
18
 
19
+ /**
20
+ * WordPress dependencies
21
+ */
22
+
16
23
  /**
17
24
  * Internal dependencies
18
25
  */
@@ -46,6 +53,36 @@ var _useQuerySelect = _interopRequireDefault(require("./use-query-select"));
46
53
  * // <PagesList />
47
54
  * ```
48
55
  *
56
+ * @example
57
+ * ```js
58
+ * import { useResourcePermissions } from '@wordpress/core-data';
59
+ *
60
+ * function Page({ pageId }) {
61
+ * const {
62
+ * canCreate,
63
+ * canUpdate,
64
+ * canDelete,
65
+ * isResolving
66
+ * } = useResourcePermissions( 'pages', pageId );
67
+ *
68
+ * if ( isResolving ) {
69
+ * return 'Loading ...';
70
+ * }
71
+ *
72
+ * return (
73
+ * <div>
74
+ * {canCreate ? (<button>+ Create a new page</button>) : false}
75
+ * {canUpdate ? (<button>Edit page</button>) : false}
76
+ * {canDelete ? (<button>Delete page</button>) : false}
77
+ * // ...
78
+ * </div>
79
+ * );
80
+ * }
81
+ *
82
+ * // Rendered in the application:
83
+ * // <Page pageId={ 15 } />
84
+ * ```
85
+ *
49
86
  * In the above example, when `PagesList` is rendered into an
50
87
  * application, the appropriate permissions and the resolution details will be retrieved from
51
88
  * the store state using `canUser()`, or resolved if missing.
@@ -53,7 +90,7 @@ var _useQuerySelect = _interopRequireDefault(require("./use-query-select"));
53
90
  * @return Entity records data.
54
91
  * @template IdType
55
92
  */
56
- function __experimentalUseResourcePermissions(resource, id) {
93
+ function useResourcePermissions(resource, id) {
57
94
  return (0, _useQuerySelect.default)(resolve => {
58
95
  const {
59
96
  canUser
@@ -61,19 +98,33 @@ function __experimentalUseResourcePermissions(resource, id) {
61
98
  const create = canUser('create', resource);
62
99
 
63
100
  if (!id) {
64
- return [create.hasResolved, {
65
- status: create.status,
66
- isResolving: create.isResolving,
67
- canCreate: create.hasResolved && create.data
68
- }];
101
+ const read = canUser('read', resource);
102
+ const isResolving = create.isResolving || read.isResolving;
103
+ const hasResolved = create.hasResolved && read.hasResolved;
104
+ let status = _constants.Status.Idle;
105
+
106
+ if (isResolving) {
107
+ status = _constants.Status.Resolving;
108
+ } else if (hasResolved) {
109
+ status = _constants.Status.Success;
110
+ }
111
+
112
+ return {
113
+ status,
114
+ isResolving,
115
+ hasResolved,
116
+ canCreate: create.hasResolved && create.data,
117
+ canRead: read.hasResolved && read.data
118
+ };
69
119
  }
70
120
 
121
+ const read = canUser('read', resource, id);
71
122
  const update = canUser('update', resource, id);
72
123
 
73
124
  const _delete = canUser('delete', resource, id);
74
125
 
75
- const isResolving = create.isResolving || update.isResolving || _delete.isResolving;
76
- const hasResolved = create.hasResolved && update.hasResolved && _delete.hasResolved;
126
+ const isResolving = read.isResolving || create.isResolving || update.isResolving || _delete.isResolving;
127
+ const hasResolved = read.hasResolved && create.hasResolved && update.hasResolved && _delete.hasResolved;
77
128
  let status = _constants.Status.Idle;
78
129
 
79
130
  if (isResolving) {
@@ -82,13 +133,23 @@ function __experimentalUseResourcePermissions(resource, id) {
82
133
  status = _constants.Status.Success;
83
134
  }
84
135
 
85
- return [hasResolved, {
136
+ return {
86
137
  status,
87
138
  isResolving,
139
+ hasResolved,
140
+ canRead: hasResolved && read.data,
88
141
  canCreate: hasResolved && create.data,
89
142
  canUpdate: hasResolved && update.data,
90
143
  canDelete: hasResolved && _delete.data
91
- }];
144
+ };
92
145
  }, [resource, id]);
93
146
  }
147
+
148
+ function __experimentalUseResourcePermissions(resource, id) {
149
+ (0, _deprecated.default)(`wp.data.__experimentalUseResourcePermissions`, {
150
+ alternative: 'wp.data.useResourcePermissions',
151
+ since: '6.1'
152
+ });
153
+ return useResourcePermissions(resource, id);
154
+ }
94
155
  //# sourceMappingURL=use-resource-permissions.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/core-data/src/hooks/use-resource-permissions.ts"],"names":["__experimentalUseResourcePermissions","resource","id","resolve","canUser","coreStore","create","hasResolved","status","isResolving","canCreate","data","update","_delete","Status","Idle","Resolving","Success","canUpdate","canDelete"],"mappings":";;;;;;;;;AAGA;;AACA;;AACA;;AALA;AACA;AACA;;AAoCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,oCAAT,CACdC,QADc,EAEdC,EAFc,EAG4B;AAC1C,SAAO,6BACJC,OAAF,IAAe;AACd,UAAM;AAAEC,MAAAA;AAAF,QAAcD,OAAO,CAAEE,OAAF,CAA3B;AACA,UAAMC,MAAM,GAAGF,OAAO,CAAE,QAAF,EAAYH,QAAZ,CAAtB;;AACA,QAAK,CAAEC,EAAP,EAAY;AACX,aAAO,CACNI,MAAM,CAACC,WADD,EAEN;AACCC,QAAAA,MAAM,EAAEF,MAAM,CAACE,MADhB;AAECC,QAAAA,WAAW,EAAEH,MAAM,CAACG,WAFrB;AAGCC,QAAAA,SAAS,EAAEJ,MAAM,CAACC,WAAP,IAAsBD,MAAM,CAACK;AAHzC,OAFM,CAAP;AAQA;;AAED,UAAMC,MAAM,GAAGR,OAAO,CAAE,QAAF,EAAYH,QAAZ,EAAsBC,EAAtB,CAAtB;;AACA,UAAMW,OAAO,GAAGT,OAAO,CAAE,QAAF,EAAYH,QAAZ,EAAsBC,EAAtB,CAAvB;;AACA,UAAMO,WAAW,GAChBH,MAAM,CAACG,WAAP,IAAsBG,MAAM,CAACH,WAA7B,IAA4CI,OAAO,CAACJ,WADrD;AAEA,UAAMF,WAAW,GAChBD,MAAM,CAACC,WAAP,IAAsBK,MAAM,CAACL,WAA7B,IAA4CM,OAAO,CAACN,WADrD;AAGA,QAAIC,MAAM,GAAGM,kBAAOC,IAApB;;AACA,QAAKN,WAAL,EAAmB;AAClBD,MAAAA,MAAM,GAAGM,kBAAOE,SAAhB;AACA,KAFD,MAEO,IAAKT,WAAL,EAAmB;AACzBC,MAAAA,MAAM,GAAGM,kBAAOG,OAAhB;AACA;;AACD,WAAO,CACNV,WADM,EAEN;AACCC,MAAAA,MADD;AAECC,MAAAA,WAFD;AAGCC,MAAAA,SAAS,EAAEH,WAAW,IAAID,MAAM,CAACK,IAHlC;AAICO,MAAAA,SAAS,EAAEX,WAAW,IAAIK,MAAM,CAACD,IAJlC;AAKCQ,MAAAA,SAAS,EAAEZ,WAAW,IAAIM,OAAO,CAACF;AALnC,KAFM,CAAP;AAUA,GAtCK,EAuCN,CAAEV,QAAF,EAAYC,EAAZ,CAvCM,CAAP;AAyCA","sourcesContent":["/**\n * Internal dependencies\n */\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\nimport useQuerySelect from './use-query-select';\n\ninterface GlobalResourcePermissionsResolution {\n\t/** Can the current user create new resources of this type? */\n\tcanCreate: boolean;\n}\ninterface SpecificResourcePermissionsResolution {\n\t/** Can the current user update resources of this type? */\n\tcanUpdate: boolean;\n\t/** Can the current user delete resources of this type? */\n\tcanDelete: boolean;\n}\ninterface ResolutionDetails {\n\t/** Resolution status */\n\tstatus: Status;\n\t/**\n\t * Is the data still being resolved?\n\t */\n\tisResolving: boolean;\n}\n\n/**\n * Is the data resolved by now?\n */\ntype HasResolved = boolean;\n\ntype ResourcePermissionsResolution< IdType > = [\n\tHasResolved,\n\tResolutionDetails &\n\t\tGlobalResourcePermissionsResolution &\n\t\t( IdType extends void ? SpecificResourcePermissionsResolution : {} )\n];\n\n/**\n * Resolves resource permissions.\n *\n * @param resource The resource in question, e.g. media.\n * @param id ID of a specific resource entry, if needed, e.g. 10.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( 'pages' );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PagesList />\n * ```\n *\n * In the above example, when `PagesList` is rendered into an\n * application, the appropriate permissions and the resolution details will be retrieved from\n * the store state using `canUser()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template IdType\n */\nexport default function __experimentalUseResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser( 'create', resource );\n\t\t\tif ( ! id ) {\n\t\t\t\treturn [\n\t\t\t\t\tcreate.hasResolved,\n\t\t\t\t\t{\n\t\t\t\t\t\tstatus: create.status,\n\t\t\t\t\t\tisResolving: create.isResolving,\n\t\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t\t},\n\t\t\t\t];\n\t\t\t}\n\n\t\t\tconst update = canUser( 'update', resource, id );\n\t\t\tconst _delete = canUser( 'delete', resource, id );\n\t\t\tconst isResolving =\n\t\t\t\tcreate.isResolving || update.isResolving || _delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tcreate.hasResolved && update.hasResolved && _delete.hasResolved;\n\n\t\t\tlet status = Status.Idle;\n\t\t\tif ( isResolving ) {\n\t\t\t\tstatus = Status.Resolving;\n\t\t\t} else if ( hasResolved ) {\n\t\t\t\tstatus = Status.Success;\n\t\t\t}\n\t\t\treturn [\n\t\t\t\thasResolved,\n\t\t\t\t{\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t\t},\n\t\t\t];\n\t\t},\n\t\t[ resource, id ]\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/core-data/src/hooks/use-resource-permissions.ts"],"names":["useResourcePermissions","resource","id","resolve","canUser","coreStore","create","read","isResolving","hasResolved","status","Status","Idle","Resolving","Success","canCreate","data","canRead","update","_delete","canUpdate","canDelete","__experimentalUseResourcePermissions","alternative","since"],"mappings":";;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AAVA;AACA;AACA;;AAGA;AACA;AACA;;AAoCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,sBAAT,CACdC,QADc,EAEdC,EAFc,EAG4B;AAC1C,SAAO,6BACJC,OAAF,IAAe;AACd,UAAM;AAAEC,MAAAA;AAAF,QAAcD,OAAO,CAAEE,OAAF,CAA3B;AACA,UAAMC,MAAM,GAAGF,OAAO,CAAE,QAAF,EAAYH,QAAZ,CAAtB;;AACA,QAAK,CAAEC,EAAP,EAAY;AACX,YAAMK,IAAI,GAAGH,OAAO,CAAE,MAAF,EAAUH,QAAV,CAApB;AAEA,YAAMO,WAAW,GAAGF,MAAM,CAACE,WAAP,IAAsBD,IAAI,CAACC,WAA/C;AACA,YAAMC,WAAW,GAAGH,MAAM,CAACG,WAAP,IAAsBF,IAAI,CAACE,WAA/C;AACA,UAAIC,MAAM,GAAGC,kBAAOC,IAApB;;AACA,UAAKJ,WAAL,EAAmB;AAClBE,QAAAA,MAAM,GAAGC,kBAAOE,SAAhB;AACA,OAFD,MAEO,IAAKJ,WAAL,EAAmB;AACzBC,QAAAA,MAAM,GAAGC,kBAAOG,OAAhB;AACA;;AAED,aAAO;AACNJ,QAAAA,MADM;AAENF,QAAAA,WAFM;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yDA;;AAEM,SAASoB,oCAAT,CACNrB,QADM,EAENC,EAFM,EAGL;AACD,2BAAa,8CAAb,EAA4D;AAC3DqB,IAAAA,WAAW,EAAE,gCAD8C;AAE3DC,IAAAA,KAAK,EAAE;AAFoD,GAA5D;AAIA,SAAOxB,sBAAsB,CAAEC,QAAF,EAAYC,EAAZ,CAA7B;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { store as coreStore } from '../';\nimport { Status } from './constants';\nimport useQuerySelect from './use-query-select';\n\ninterface GlobalResourcePermissionsResolution {\n\t/** Can the current user create new resources of this type? */\n\tcanCreate: boolean;\n}\ninterface SpecificResourcePermissionsResolution {\n\t/** Can the current user update resources of this type? */\n\tcanUpdate: boolean;\n\t/** Can the current user delete resources of this type? */\n\tcanDelete: boolean;\n}\ninterface ResolutionDetails {\n\t/** Resolution status */\n\tstatus: Status;\n\t/**\n\t * Is the data still being resolved?\n\t */\n\tisResolving: boolean;\n}\n\n/**\n * Is the data resolved by now?\n */\ntype HasResolved = boolean;\n\ntype ResourcePermissionsResolution< IdType > = [\n\tHasResolved,\n\tResolutionDetails &\n\t\tGlobalResourcePermissionsResolution &\n\t\t( IdType extends void ? SpecificResourcePermissionsResolution : {} )\n];\n\n/**\n * Resolves resource permissions.\n *\n * @param resource The resource in question, e.g. media.\n * @param id ID of a specific resource entry, if needed, e.g. 10.\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function PagesList() {\n * const { canCreate, isResolving } = useResourcePermissions( 'pages' );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <PagesList />\n * ```\n *\n * @example\n * ```js\n * import { useResourcePermissions } from '@wordpress/core-data';\n *\n * function Page({ pageId }) {\n * const {\n * canCreate,\n * canUpdate,\n * canDelete,\n * isResolving\n * } = useResourcePermissions( 'pages', pageId );\n *\n * if ( isResolving ) {\n * return 'Loading ...';\n * }\n *\n * return (\n * <div>\n * {canCreate ? (<button>+ Create a new page</button>) : false}\n * {canUpdate ? (<button>Edit page</button>) : false}\n * {canDelete ? (<button>Delete page</button>) : false}\n * // ...\n * </div>\n * );\n * }\n *\n * // Rendered in the application:\n * // <Page pageId={ 15 } />\n * ```\n *\n * In the above example, when `PagesList` is rendered into an\n * application, the appropriate permissions and the resolution details will be retrieved from\n * the store state using `canUser()`, or resolved if missing.\n *\n * @return Entity records data.\n * @template IdType\n */\nexport default function useResourcePermissions< IdType = void >(\n\tresource: string,\n\tid?: IdType\n): ResourcePermissionsResolution< IdType > {\n\treturn useQuerySelect(\n\t\t( resolve ) => {\n\t\t\tconst { canUser } = resolve( coreStore );\n\t\t\tconst create = canUser( 'create', resource );\n\t\t\tif ( ! id ) {\n\t\t\t\tconst read = canUser( 'read', resource );\n\n\t\t\t\tconst isResolving = create.isResolving || read.isResolving;\n\t\t\t\tconst hasResolved = create.hasResolved && read.hasResolved;\n\t\t\t\tlet status = Status.Idle;\n\t\t\t\tif ( isResolving ) {\n\t\t\t\t\tstatus = Status.Resolving;\n\t\t\t\t} else if ( hasResolved ) {\n\t\t\t\t\tstatus = Status.Success;\n\t\t\t\t}\n\n\t\t\t\treturn {\n\t\t\t\t\tstatus,\n\t\t\t\t\tisResolving,\n\t\t\t\t\thasResolved,\n\t\t\t\t\tcanCreate: create.hasResolved && create.data,\n\t\t\t\t\tcanRead: read.hasResolved && read.data,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\tconst read = canUser( 'read', resource, id );\n\t\t\tconst update = canUser( 'update', resource, id );\n\t\t\tconst _delete = canUser( 'delete', resource, id );\n\t\t\tconst isResolving =\n\t\t\t\tread.isResolving ||\n\t\t\t\tcreate.isResolving ||\n\t\t\t\tupdate.isResolving ||\n\t\t\t\t_delete.isResolving;\n\t\t\tconst hasResolved =\n\t\t\t\tread.hasResolved &&\n\t\t\t\tcreate.hasResolved &&\n\t\t\t\tupdate.hasResolved &&\n\t\t\t\t_delete.hasResolved;\n\n\t\t\tlet status = Status.Idle;\n\t\t\tif ( isResolving ) {\n\t\t\t\tstatus = Status.Resolving;\n\t\t\t} else if ( hasResolved ) {\n\t\t\t\tstatus = Status.Success;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tstatus,\n\t\t\t\tisResolving,\n\t\t\t\thasResolved,\n\t\t\t\tcanRead: hasResolved && read.data,\n\t\t\t\tcanCreate: hasResolved && create.data,\n\t\t\t\tcanUpdate: hasResolved && update.data,\n\t\t\t\tcanDelete: hasResolved && _delete.data,\n\t\t\t};\n\t\t},\n\t\t[ resource, id ]\n\t);\n}\n\nexport function __experimentalUseResourcePermissions(\n\tresource: string,\n\tid?: unknown\n) {\n\tdeprecated( `wp.data.__experimentalUseResourcePermissions`, {\n\t\talternative: 'wp.data.useResourcePermissions',\n\t\tsince: '6.1',\n\t} );\n\treturn useResourcePermissions( resource, id );\n}\n"]}