@wordpress/core-data 4.11.0 → 4.14.1-next.d6164808d3.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 +10 -0
- package/README.md +124 -81
- package/build/actions.js +27 -0
- package/build/actions.js.map +1 -1
- package/build/batch/create-batch.js +3 -15
- package/build/batch/create-batch.js.map +1 -1
- package/build/entities.js +7 -5
- 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 +84 -2
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/hooks/use-resource-permissions.js +53 -6
- package/build/hooks/use-resource-permissions.js.map +1 -1
- package/build/index.js +1 -28
- package/build/index.js.map +1 -1
- package/build/resolvers.js +22 -24
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +5 -3
- package/build/selectors.js.map +1 -1
- package/build-module/actions.js +27 -0
- package/build-module/actions.js.map +1 -1
- package/build-module/batch/create-batch.js +3 -14
- package/build-module/batch/create-batch.js.map +1 -1
- package/build-module/entities.js +7 -6
- 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 +82 -2
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/hooks/use-resource-permissions.js +49 -5
- package/build-module/hooks/use-resource-permissions.js.map +1 -1
- package/build-module/index.js +0 -3
- package/build-module/index.js.map +1 -1
- package/build-module/resolvers.js +22 -24
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +6 -4
- package/build-module/selectors.js.map +1 -1
- package/package.json +12 -11
- package/src/actions.js +27 -0
- package/src/batch/create-batch.js +3 -12
- package/src/entities.ts +8 -6
- package/src/entity-types/theme.ts +4 -0
- package/src/hooks/index.ts +4 -0
- package/src/hooks/test/use-entity-record.js +9 -1
- package/src/hooks/test/use-resource-permissions.js +28 -36
- package/src/hooks/use-entity-record.ts +99 -2
- package/src/hooks/use-resource-permissions.ts +60 -18
- package/src/index.js +0 -3
- package/src/resolvers.js +41 -36
- package/src/selectors.ts +6 -4
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,
|
|
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,
|
|
340
|
-
const nameSuffix = (0,
|
|
341
|
-
const suffix = usePlural && 'plural' in entityConfig && entityConfig !== null && entityConfig !== void 0 && entityConfig.plural ? (0,
|
|
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
|
/**
|
package/build/entities.js.map
CHANGED
|
@@ -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;A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ies\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;;AAE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,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"]}
|
package/build/hooks/index.js
CHANGED
|
@@ -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; }
|
package/build/hooks/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/index.ts"],"names":[],"mappings":"
|
|
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"]}
|
|
@@ -8,8 +8,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
8
|
exports.__experimentalUseEntityRecord = __experimentalUseEntityRecord;
|
|
9
9
|
exports.default = useEntityRecord;
|
|
10
10
|
|
|
11
|
+
var _data = require("@wordpress/data");
|
|
12
|
+
|
|
11
13
|
var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
|
|
12
14
|
|
|
15
|
+
var _element = require("@wordpress/element");
|
|
16
|
+
|
|
13
17
|
var _useQuerySelect = _interopRequireDefault(require("./use-query-select"));
|
|
14
18
|
|
|
15
19
|
var _ = require("../");
|
|
@@ -51,6 +55,60 @@ var _ = require("../");
|
|
|
51
55
|
* application, the page and the resolution details will be retrieved from
|
|
52
56
|
* the store state using `getEntityRecord()`, or resolved if missing.
|
|
53
57
|
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```js
|
|
60
|
+
* import { useDispatch } from '@wordpress/data';
|
|
61
|
+
* import { useCallback } from '@wordpress/element';
|
|
62
|
+
* import { __ } from '@wordpress/i18n';
|
|
63
|
+
* import { TextControl } from '@wordpress/components';
|
|
64
|
+
* import { store as noticeStore } from '@wordpress/notices';
|
|
65
|
+
* import { useEntityRecord } from '@wordpress/core-data';
|
|
66
|
+
*
|
|
67
|
+
* function PageRenameForm( { id } ) {
|
|
68
|
+
* const page = useEntityRecord( 'postType', 'page', id );
|
|
69
|
+
* const { createSuccessNotice, createErrorNotice } =
|
|
70
|
+
* useDispatch( noticeStore );
|
|
71
|
+
*
|
|
72
|
+
* const setTitle = useCallback( ( title ) => {
|
|
73
|
+
* page.edit( { title } );
|
|
74
|
+
* }, [ page.edit ] );
|
|
75
|
+
*
|
|
76
|
+
* if ( page.isResolving ) {
|
|
77
|
+
* return 'Loading...';
|
|
78
|
+
* }
|
|
79
|
+
*
|
|
80
|
+
* async function onRename( event ) {
|
|
81
|
+
* event.preventDefault();
|
|
82
|
+
* try {
|
|
83
|
+
* await page.save();
|
|
84
|
+
* createSuccessNotice( __( 'Page renamed.' ), {
|
|
85
|
+
* type: 'snackbar',
|
|
86
|
+
* } );
|
|
87
|
+
* } catch ( error ) {
|
|
88
|
+
* createErrorNotice( error.message, { type: 'snackbar' } );
|
|
89
|
+
* }
|
|
90
|
+
* }
|
|
91
|
+
*
|
|
92
|
+
* return (
|
|
93
|
+
* <form onSubmit={ onRename }>
|
|
94
|
+
* <TextControl
|
|
95
|
+
* label={ __( 'Name' ) }
|
|
96
|
+
* value={ page.editedRecord.title }
|
|
97
|
+
* onChange={ setTitle }
|
|
98
|
+
* />
|
|
99
|
+
* <button type="submit">{ __( 'Save' ) }</button>
|
|
100
|
+
* </form>
|
|
101
|
+
* );
|
|
102
|
+
* }
|
|
103
|
+
*
|
|
104
|
+
* // Rendered in the application:
|
|
105
|
+
* // <PageRenameForm id={ 1 } />
|
|
106
|
+
* ```
|
|
107
|
+
*
|
|
108
|
+
* In the above example, updating and saving the page title is handled
|
|
109
|
+
* via the `edit()` and `save()` mutation helpers provided by
|
|
110
|
+
* `useEntityRecord()`;
|
|
111
|
+
*
|
|
54
112
|
* @return Entity record data.
|
|
55
113
|
* @template RecordType
|
|
56
114
|
*/
|
|
@@ -58,9 +116,30 @@ function useEntityRecord(kind, name, recordId) {
|
|
|
58
116
|
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
59
117
|
enabled: true
|
|
60
118
|
};
|
|
119
|
+
const {
|
|
120
|
+
editEntityRecord,
|
|
121
|
+
saveEditedEntityRecord
|
|
122
|
+
} = (0, _data.useDispatch)(_.store);
|
|
123
|
+
const mutations = (0, _element.useMemo)(() => ({
|
|
124
|
+
edit: record => editEntityRecord(kind, name, recordId, record),
|
|
125
|
+
save: function () {
|
|
126
|
+
let saveOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
127
|
+
return saveEditedEntityRecord(kind, name, recordId, {
|
|
128
|
+
throwOnError: true,
|
|
129
|
+
...saveOptions
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
}), [recordId]);
|
|
133
|
+
const {
|
|
134
|
+
editedRecord,
|
|
135
|
+
hasEdits
|
|
136
|
+
} = (0, _data.useSelect)(select => ({
|
|
137
|
+
editedRecord: select(_.store).getEditedEntityRecord(),
|
|
138
|
+
hasEdits: select(_.store).hasEditsForEntityRecord()
|
|
139
|
+
}), [kind, name, recordId]);
|
|
61
140
|
const {
|
|
62
141
|
data: record,
|
|
63
|
-
...
|
|
142
|
+
...querySelectRest
|
|
64
143
|
} = (0, _useQuerySelect.default)(query => {
|
|
65
144
|
if (!options.enabled) {
|
|
66
145
|
return null;
|
|
@@ -70,7 +149,10 @@ function useEntityRecord(kind, name, recordId) {
|
|
|
70
149
|
}, [kind, name, recordId, options.enabled]);
|
|
71
150
|
return {
|
|
72
151
|
record,
|
|
73
|
-
|
|
152
|
+
editedRecord,
|
|
153
|
+
hasEdits,
|
|
154
|
+
...querySelectRest,
|
|
155
|
+
...mutations
|
|
74
156
|
};
|
|
75
157
|
}
|
|
76
158
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"names":["useEntityRecord","kind","name","recordId","options","enabled","
|
|
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;AAC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GU;AAAnB,MAAuC,6BAC1CC,KAAF,IAAa;AACZ,QAAK,CAAElB,OAAO,CAACC,OAAf,EAAyB;AACxB,aAAO,IAAP;AACA;;AACD,WAAOiB,KAAK,CAAEd,OAAF,CAAL,CAAmBe,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 { 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\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"]}
|
|
@@ -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.
|
|
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
|
|
93
|
+
function useResourcePermissions(resource, id) {
|
|
57
94
|
return (0, _useQuerySelect.default)(resolve => {
|
|
58
95
|
const {
|
|
59
96
|
canUser
|
|
@@ -61,11 +98,12 @@ function __experimentalUseResourcePermissions(resource, id) {
|
|
|
61
98
|
const create = canUser('create', resource);
|
|
62
99
|
|
|
63
100
|
if (!id) {
|
|
64
|
-
return
|
|
101
|
+
return {
|
|
65
102
|
status: create.status,
|
|
66
103
|
isResolving: create.isResolving,
|
|
104
|
+
hasResolved: create.hasResolved,
|
|
67
105
|
canCreate: create.hasResolved && create.data
|
|
68
|
-
}
|
|
106
|
+
};
|
|
69
107
|
}
|
|
70
108
|
|
|
71
109
|
const update = canUser('update', resource, id);
|
|
@@ -82,13 +120,22 @@ function __experimentalUseResourcePermissions(resource, id) {
|
|
|
82
120
|
status = _constants.Status.Success;
|
|
83
121
|
}
|
|
84
122
|
|
|
85
|
-
return
|
|
123
|
+
return {
|
|
86
124
|
status,
|
|
87
125
|
isResolving,
|
|
126
|
+
hasResolved,
|
|
88
127
|
canCreate: hasResolved && create.data,
|
|
89
128
|
canUpdate: hasResolved && update.data,
|
|
90
129
|
canDelete: hasResolved && _delete.data
|
|
91
|
-
}
|
|
130
|
+
};
|
|
92
131
|
}, [resource, id]);
|
|
93
132
|
}
|
|
133
|
+
|
|
134
|
+
function __experimentalUseResourcePermissions(resource, id) {
|
|
135
|
+
(0, _deprecated.default)(`wp.data.__experimentalUseResourcePermissions`, {
|
|
136
|
+
alternative: 'wp.data.useResourcePermissions',
|
|
137
|
+
since: '6.1'
|
|
138
|
+
});
|
|
139
|
+
return useResourcePermissions(resource, id);
|
|
140
|
+
}
|
|
94
141
|
//# sourceMappingURL=use-resource-permissions.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-resource-permissions.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/hooks/use-resource-permissions.ts"],"names":["useResourcePermissions","resource","id","resolve","canUser","coreStore","create","status","isResolving","hasResolved","canCreate","data","update","_delete","Status","Idle","Resolving","Success","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;AA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;AAQA,GAlCK,EAmCN,CAAEV,QAAF,EAAYC,EAAZ,CAnCM,CAAP;AAqCA;;AAEM,SAASkB,oCAAT,CACNnB,QADM,EAENC,EAFM,EAGL;AACD,2BAAa,8CAAb,EAA4D;AAC3DmB,IAAAA,WAAW,EAAE,gCAD8C;AAE3DC,IAAAA,KAAK,EAAE;AAFoD,GAA5D;AAIA,SAAOtB,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\treturn {\n\t\t\t\t\tstatus: create.status,\n\t\t\t\t\tisResolving: create.isResolving,\n\t\t\t\t\thasResolved: create.hasResolved,\n\t\t\t\t\tcanCreate: create.hasResolved && create.data,\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\tstatus,\n\t\t\t\tisResolving,\n\t\t\t\thasResolved,\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?: IdType\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"]}
|
package/build/index.js
CHANGED
|
@@ -7,10 +7,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
var _exportNames = {
|
|
9
9
|
store: true,
|
|
10
|
-
EntityProvider: true
|
|
11
|
-
useEntityRecord: true,
|
|
12
|
-
useEntityRecords: true,
|
|
13
|
-
__experimentalUseResourcePermissions: true
|
|
10
|
+
EntityProvider: true
|
|
14
11
|
};
|
|
15
12
|
Object.defineProperty(exports, "EntityProvider", {
|
|
16
13
|
enumerable: true,
|
|
@@ -18,25 +15,7 @@ Object.defineProperty(exports, "EntityProvider", {
|
|
|
18
15
|
return _entityProvider.default;
|
|
19
16
|
}
|
|
20
17
|
});
|
|
21
|
-
Object.defineProperty(exports, "__experimentalUseResourcePermissions", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function () {
|
|
24
|
-
return _useResourcePermissions.default;
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
18
|
exports.store = void 0;
|
|
28
|
-
Object.defineProperty(exports, "useEntityRecord", {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
get: function () {
|
|
31
|
-
return _useEntityRecord.default;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
Object.defineProperty(exports, "useEntityRecords", {
|
|
35
|
-
enumerable: true,
|
|
36
|
-
get: function () {
|
|
37
|
-
return _useEntityRecords.default;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
19
|
|
|
41
20
|
var _data = require("@wordpress/data");
|
|
42
21
|
|
|
@@ -68,12 +47,6 @@ Object.keys(_entityProvider).forEach(function (key) {
|
|
|
68
47
|
});
|
|
69
48
|
});
|
|
70
49
|
|
|
71
|
-
var _useEntityRecord = _interopRequireDefault(require("./hooks/use-entity-record"));
|
|
72
|
-
|
|
73
|
-
var _useEntityRecords = _interopRequireDefault(require("./hooks/use-entity-records"));
|
|
74
|
-
|
|
75
|
-
var _useResourcePermissions = _interopRequireDefault(require("./hooks/use-resource-permissions"));
|
|
76
|
-
|
|
77
50
|
var _entityTypes = require("./entity-types");
|
|
78
51
|
|
|
79
52
|
Object.keys(_entityTypes).forEach(function (key) {
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","rootEntitiesConfig","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","getEntityRecords","entityResolvers","resolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","store","STORE_NAME"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["@wordpress/core-data/src/index.js"],"names":["entitySelectors","rootEntitiesConfig","reduce","result","entity","kind","name","state","key","query","selectors","getEntityRecord","getEntityRecords","entityResolvers","resolvers","pluralMethodName","args","shouldInvalidate","action","entityActions","actions","saveEntityRecord","deleteEntityRecord","storeConfig","reducer","store","STORE_NAME"],"mappings":";;;;;;;;;;;;;;;;;;;AAGA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAuDA;;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AACA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;;;;A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AgB,OAAGD;AAAnB;AAJgB,CAAR,CAApB;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMY,KAAK,GAAG,4BAAkBC,gBAAlB,EAA8BH,WAAW,EAAzC,CAAd;;AAEP,oBAAUE,KAAV","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createReduxStore, register } from '@wordpress/data';\n\n/**\n * Internal dependencies\n */\nimport reducer from './reducer';\nimport * as selectors from './selectors';\nimport * as actions from './actions';\nimport * as resolvers from './resolvers';\nimport createLocksActions from './locks/actions';\nimport { rootEntitiesConfig, getMethodName } from './entities';\nimport { STORE_NAME } from './name';\n\n// The entity selectors/resolvers and actions are shortcuts to their generic equivalents\n// (getEntityRecord, getEntityRecords, updateEntityRecord, updateEntityRecords)\n// Instead of getEntityRecord, the consumer could use more user-friendly named selector: getPostType, getTaxonomy...\n// The \"kind\" and the \"name\" of the entity are combined to generate these shortcuts.\n\nconst entitySelectors = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( state, key, query ) =>\n\t\tselectors.getEntityRecord( state, kind, name, key, query );\n\tresult[ getMethodName( kind, name, 'get', true ) ] = ( state, query ) =>\n\t\tselectors.getEntityRecords( state, kind, name, query );\n\treturn result;\n}, {} );\n\nconst entityResolvers = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name ) ] = ( key, query ) =>\n\t\tresolvers.getEntityRecord( kind, name, key, query );\n\tconst pluralMethodName = getMethodName( kind, name, 'get', true );\n\tresult[ pluralMethodName ] = ( ...args ) =>\n\t\tresolvers.getEntityRecords( kind, name, ...args );\n\tresult[ pluralMethodName ].shouldInvalidate = ( action ) =>\n\t\tresolvers.getEntityRecords.shouldInvalidate( action, kind, name );\n\treturn result;\n}, {} );\n\nconst entityActions = rootEntitiesConfig.reduce( ( result, entity ) => {\n\tconst { kind, name } = entity;\n\tresult[ getMethodName( kind, name, 'save' ) ] = ( key ) =>\n\t\tactions.saveEntityRecord( kind, name, key );\n\tresult[ getMethodName( kind, name, 'delete' ) ] = ( key, query ) =>\n\t\tactions.deleteEntityRecord( kind, name, key, query );\n\treturn result;\n}, {} );\n\nconst storeConfig = () => ( {\n\treducer,\n\tactions: { ...actions, ...entityActions, ...createLocksActions() },\n\tselectors: { ...selectors, ...entitySelectors },\n\tresolvers: { ...resolvers, ...entityResolvers },\n} );\n\n/**\n * Store definition for the code data namespace.\n *\n * @see https://github.com/WordPress/gutenberg/blob/HEAD/packages/data/README.md#createReduxStore\n *\n * @type {Object}\n */\nexport const store = createReduxStore( STORE_NAME, storeConfig() );\n\nregister( store );\n\nexport { default as EntityProvider } from './entity-provider';\nexport * from './entity-provider';\nexport * from './entity-types';\nexport * from './fetch';\nexport * from './hooks';\n"]}
|