@wordpress/core-data 6.22.0 → 6.24.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 +5 -0
- package/README.md +77 -2
- package/build/actions.js +55 -0
- package/build/actions.js.map +1 -1
- package/build/entities.js +18 -3
- package/build/entities.js.map +1 -1
- package/build/entity-provider.js +7 -1
- package/build/entity-provider.js.map +1 -1
- package/build/entity-types/global-styles-revision.js +6 -0
- package/build/entity-types/global-styles-revision.js.map +1 -0
- package/build/entity-types/index.js.map +1 -1
- package/build/entity-types/post-revision.js +6 -0
- package/build/entity-types/post-revision.js.map +1 -0
- package/build/hooks/use-entity-record.js +16 -5
- package/build/hooks/use-entity-record.js.map +1 -1
- package/build/queried-data/reducer.js +3 -1
- package/build/queried-data/reducer.js.map +1 -1
- package/build/queried-data/selectors.js +3 -1
- package/build/queried-data/selectors.js.map +1 -1
- package/build/reducer.js +52 -4
- package/build/reducer.js.map +1 -1
- package/build/resolvers.js +131 -3
- package/build/resolvers.js.map +1 -1
- package/build/selectors.js +92 -1
- package/build/selectors.js.map +1 -1
- package/build-module/actions.js +52 -0
- package/build-module/actions.js.map +1 -1
- package/build-module/entities.js +18 -3
- package/build-module/entities.js.map +1 -1
- package/build-module/entity-provider.js +7 -1
- package/build-module/entity-provider.js.map +1 -1
- package/build-module/entity-types/global-styles-revision.js +2 -0
- package/build-module/entity-types/global-styles-revision.js.map +1 -0
- package/build-module/entity-types/index.js.map +1 -1
- package/build-module/entity-types/post-revision.js +2 -0
- package/build-module/entity-types/post-revision.js.map +1 -0
- package/build-module/hooks/use-entity-record.js +16 -5
- package/build-module/hooks/use-entity-record.js.map +1 -1
- package/build-module/queried-data/reducer.js +3 -1
- package/build-module/queried-data/reducer.js.map +1 -1
- package/build-module/queried-data/selectors.js +3 -1
- package/build-module/queried-data/selectors.js.map +1 -1
- package/build-module/reducer.js +51 -4
- package/build-module/reducer.js.map +1 -1
- package/build-module/resolvers.js +127 -2
- package/build-module/resolvers.js.map +1 -1
- package/build-module/selectors.js +88 -1
- package/build-module/selectors.js.map +1 -1
- package/build-types/actions.d.ts +14 -0
- package/build-types/actions.d.ts.map +1 -1
- package/build-types/entities.d.ts +23 -1
- package/build-types/entities.d.ts.map +1 -1
- package/build-types/entity-provider.d.ts.map +1 -1
- package/build-types/entity-types/global-styles-revision.d.ts +43 -0
- package/build-types/entity-types/global-styles-revision.d.ts.map +1 -0
- package/build-types/entity-types/index.d.ts +4 -2
- package/build-types/entity-types/index.d.ts.map +1 -1
- package/build-types/entity-types/post-revision.d.ts +76 -0
- package/build-types/entity-types/post-revision.d.ts.map +1 -0
- package/build-types/hooks/use-entity-record.d.ts.map +1 -1
- package/build-types/index.d.ts +19 -4
- package/build-types/index.d.ts.map +1 -1
- package/build-types/queried-data/selectors.d.ts.map +1 -1
- package/build-types/reducer.d.ts +10 -0
- package/build-types/reducer.d.ts.map +1 -1
- package/build-types/resolvers.d.ts +12 -0
- package/build-types/resolvers.d.ts.map +1 -1
- package/build-types/selectors.d.ts +54 -3
- package/build-types/selectors.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/actions.js +61 -0
- package/src/entities.js +33 -1
- package/src/entity-provider.js +8 -1
- package/src/entity-types/global-styles-revision.ts +47 -0
- package/src/entity-types/index.ts +6 -0
- package/src/entity-types/post-revision.ts +93 -0
- package/src/hooks/test/use-entity-record.js +41 -0
- package/src/hooks/use-entity-record.ts +30 -18
- package/src/queried-data/reducer.js +3 -3
- package/src/queried-data/selectors.js +3 -1
- package/src/queried-data/test/reducer.js +11 -0
- package/src/reducer.js +68 -2
- package/src/resolvers.js +176 -2
- package/src/selectors.ts +141 -1
- package/src/test/entities.js +9 -0
- package/src/test/reducer.js +235 -0
- package/src/test/selectors.js +96 -0
- package/tsconfig.tsbuildinfo +1 -1
package/build/entities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_changeCase","require","_apiFetch","_interopRequireDefault","_i18n","_actions","_sync","DEFAULT_ENTITY_KEY","exports","POST_RAW_ATTRIBUTES","rootEntitiesConfig","label","__","kind","name","baseURL","baseURLParams","_fields","join","syncConfig","fetch","apiFetch","path","applyChangesToDoc","doc","changes","document","getMap","Object","entries","forEach","key","value","get","set","fromCRDTDoc","toJSON","syncObjectType","getSyncObjectId","getTitle","record","_record$title","title","context","id","plural","rawAttributes","supportsPagination","transientEdits","blocks","rendered","additionalEntityConfigLoaders","loadEntities","loadPostTypeEntities","loadTaxonomyEntities","prePersistPostType","persistedRecord","edits","newEdits","status","postTypes","map","postType","_postType$rest_namesp","isTemplate","includes","namespace","rest_namespace","rest_base","selection","mergedEdits","meta","_record$slug","capitalCase","slug","String","__unstablePrePersist","undefined","__unstable_rest_base","taxonomies","taxonomy","_taxonomy$rest_namesp","getMethodName","prefix","usePlural","entityConfig","find","config","kindPrefix","pascalCase","nameSuffix","suffix","registerSyncConfigs","configs","getSyncProvider","register","editSyncConfig","getOrLoadEntitiesConfig","select","dispatch","getEntitiesConfig","length","window","__experimentalEnableSync","process","env","IS_GUTENBERG_PLUGIN","loader","l","addEntities"],"sources":["@wordpress/core-data/src/entities.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { capitalCase, pascalCase } from 'change-case';\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 { getSyncProvider } from './sync';\n\nexport const DEFAULT_ENTITY_KEY = 'id';\n\nconst POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];\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\tsyncConfig: {\n\t\t\tfetch: async () => {\n\t\t\t\treturn apiFetch( { path: '/' } );\n\t\t\t},\n\t\t\tapplyChangesToDoc: ( doc, changes ) => {\n\t\t\t\tconst document = doc.getMap( 'document' );\n\t\t\t\tObject.entries( changes ).forEach( ( [ key, value ] ) => {\n\t\t\t\t\tif ( document.get( key ) !== value ) {\n\t\t\t\t\t\tdocument.set( key, value );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t},\n\t\t\tfromCRDTDoc: ( doc ) => {\n\t\t\t\treturn doc.getMap( 'document' ).toJSON();\n\t\t\t},\n\t\t},\n\t\tsyncObjectType: 'root/base',\n\t\tgetSyncObjectId: () => 'index',\n\t},\n\t{\n\t\tlabel: __( 'Site' ),\n\t\tname: 'site',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/settings',\n\t\tgetTitle: ( record ) => {\n\t\t\treturn record?.title ?? __( 'Site Title' );\n\t\t},\n\t\tsyncConfig: {\n\t\t\tfetch: async () => {\n\t\t\t\treturn apiFetch( { path: '/wp/v2/settings' } );\n\t\t\t},\n\t\t\tapplyChangesToDoc: ( doc, changes ) => {\n\t\t\t\tconst document = doc.getMap( 'document' );\n\t\t\t\tObject.entries( changes ).forEach( ( [ key, value ] ) => {\n\t\t\t\t\tif ( document.get( key ) !== value ) {\n\t\t\t\t\t\tdocument.set( key, value );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t},\n\t\t\tfromCRDTDoc: ( doc ) => {\n\t\t\t\treturn doc.getMap( 'document' ).toJSON();\n\t\t\t},\n\t\t},\n\t\tsyncObjectType: 'root/site',\n\t\tgetSyncObjectId: () => 'index',\n\t},\n\t{\n\t\tlabel: __( 'Post Type' ),\n\t\tname: 'postType',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tsyncConfig: {\n\t\t\tfetch: async ( id ) => {\n\t\t\t\treturn apiFetch( {\n\t\t\t\t\tpath: `/wp/v2/types/${ id }?context=edit`,\n\t\t\t\t} );\n\t\t\t},\n\t\t\tapplyChangesToDoc: ( doc, changes ) => {\n\t\t\t\tconst document = doc.getMap( 'document' );\n\t\t\t\tObject.entries( changes ).forEach( ( [ key, value ] ) => {\n\t\t\t\t\tif ( document.get( key ) !== value ) {\n\t\t\t\t\t\tdocument.set( key, value );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t},\n\t\t\tfromCRDTDoc: ( doc ) => {\n\t\t\t\treturn doc.getMap( 'document' ).toJSON();\n\t\t\t},\n\t\t},\n\t\tsyncObjectType: 'root/postType',\n\t\tgetSyncObjectId: ( id ) => id,\n\t},\n\t{\n\t\tname: 'media',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/media',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'mediaItems',\n\t\tlabel: __( 'Media' ),\n\t\trawAttributes: [ 'caption', 'title', 'description' ],\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'taxonomy',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/taxonomies',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'taxonomies',\n\t\tlabel: __( 'Taxonomy' ),\n\t},\n\t{\n\t\tname: 'sidebar',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/sidebars',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'sidebars',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widget areas' ),\n\t},\n\t{\n\t\tname: 'widget',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widgets',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgets',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widgets' ),\n\t},\n\t{\n\t\tname: 'widgetType',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widget-types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgetTypes',\n\t\tlabel: __( 'Widget types' ),\n\t},\n\t{\n\t\tlabel: __( 'User' ),\n\t\tname: 'user',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/users',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'users',\n\t},\n\t{\n\t\tname: 'comment',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/comments',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'comments',\n\t\tlabel: __( 'Comment' ),\n\t},\n\t{\n\t\tname: 'menu',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menus',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menus',\n\t\tlabel: __( 'Menu' ),\n\t},\n\t{\n\t\tname: 'menuItem',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-items',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuItems',\n\t\tlabel: __( 'Menu Item' ),\n\t\trawAttributes: [ 'title' ],\n\t},\n\t{\n\t\tname: 'menuLocation',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-locations',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuLocations',\n\t\tlabel: __( 'Menu Location' ),\n\t\tkey: 'name',\n\t},\n\t{\n\t\tlabel: __( 'Global Styles' ),\n\t\tname: 'globalStyles',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/global-styles',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'globalStylesVariations', // Should be different than name.\n\t\tgetTitle: ( record ) => record?.title?.rendered || record?.title,\n\t},\n\t{\n\t\tlabel: __( 'Themes' ),\n\t\tname: 'theme',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/themes',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tkey: 'stylesheet',\n\t},\n\t{\n\t\tlabel: __( 'Plugins' ),\n\t\tname: 'plugin',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/plugins',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tkey: 'plugin',\n\t},\n\t{\n\t\tlabel: __( 'Status' ),\n\t\tname: 'status',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/statuses',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'statuses',\n\t\tkey: 'slug',\n\t},\n];\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 = {};\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} );\n\treturn Object.entries( postTypes ?? {} ).map( ( [ name, postType ] ) => {\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\tsyncConfig: {\n\t\t\t\tfetch: async ( id ) => {\n\t\t\t\t\treturn apiFetch( {\n\t\t\t\t\t\tpath: `/${ namespace }/${ postType.rest_base }/${ id }?context=edit`,\n\t\t\t\t\t} );\n\t\t\t\t},\n\t\t\t\tapplyChangesToDoc: ( doc, changes ) => {\n\t\t\t\t\tconst document = doc.getMap( 'document' );\n\t\t\t\t\tObject.entries( changes ).forEach( ( [ key, value ] ) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tdocument.get( key ) !== value &&\n\t\t\t\t\t\t\ttypeof value !== 'function'\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tdocument.set( key, value );\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t},\n\t\t\t\tfromCRDTDoc: ( doc ) => {\n\t\t\t\t\treturn doc.getMap( 'document' ).toJSON();\n\t\t\t\t},\n\t\t\t},\n\t\t\tsyncObjectType: 'postType/' + postType.name,\n\t\t\tgetSyncObjectId: ( id ) => id,\n\t\t\tsupportsPagination: true,\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} );\n\treturn Object.entries( taxonomies ?? {} ).map( ( [ name, taxonomy ] ) => {\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 = rootEntitiesConfig.find(\n\t\t( config ) => config.kind === kind && config.name === name\n\t);\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\nfunction registerSyncConfigs( configs ) {\n\tconfigs.forEach( ( { syncObjectType, syncConfig } ) => {\n\t\tgetSyncProvider().register( syncObjectType, syncConfig );\n\t\tconst editSyncConfig = { ...syncConfig };\n\t\tdelete editSyncConfig.fetch;\n\t\tgetSyncProvider().register( syncObjectType + '--edit', editSyncConfig );\n\t} );\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\tif ( window.__experimentalEnableSync ) {\n\t\t\t\tif ( process.env.IS_GUTENBERG_PLUGIN ) {\n\t\t\t\t\tregisterSyncConfigs( configs );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn configs;\n\t\t}\n\n\t\tconst loader = additionalEntityConfigLoaders.find(\n\t\t\t( l ) => l.kind === kind\n\t\t);\n\t\tif ( ! loader ) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconfigs = await loader.loadEntities();\n\t\tif ( window.__experimentalEnableSync ) {\n\t\t\tif ( process.env.IS_GUTENBERG_PLUGIN ) {\n\t\t\t\tregisterSyncConfigs( configs );\n\t\t\t}\n\t\t}\n\n\t\tdispatch( addEntities( configs ) );\n\n\t\treturn configs;\n\t};\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAIO,MAAMM,kBAAkB,GAAG,IAAI;AAACC,OAAA,CAAAD,kBAAA,GAAAA,kBAAA;AAEvC,MAAME,mBAAmB,GAAG,CAAE,OAAO,EAAE,SAAS,EAAE,SAAS,CAAE;AAEtD,MAAMC,kBAAkB,GAAG,CACjC;EACCC,KAAK,EAAE,IAAAC,QAAE,EAAE,MAAO,CAAC;EACnBC,IAAI,EAAE,MAAM;EACZC,IAAI,EAAE,gBAAgB;EACtBC,OAAO,EAAE,GAAG;EACZC,aAAa,EAAE;IACdC,OAAO,EAAE,CACR,aAAa,EACb,YAAY,EACZ,MAA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c,GAAG;MAAE,GAAG7E;IAAW,CAAC;IACxC,OAAO6E,cAAc,CAAC5E,KAAK;IAC3B,IAAA0E,qBAAe,EAAC,CAAC,CAACC,QAAQ,CAAE1D,cAAc,GAAG,QAAQ,EAAE2D,cAAe,CAAC;EACxE,CAAE,CAAC;AACJ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,uBAAuB,GACjCpF,IAAI,IACN,OAAQ;EAAEqF,MAAM;EAAEC;AAAS,CAAC,KAAM;EACjC,IAAIN,OAAO,GAAGK,MAAM,CAACE,iBAAiB,CAAEvF,IAAK,CAAC;EAC9C,IAAKgF,OAAO,IAAIA,OAAO,CAACQ,MAAM,KAAK,CAAC,EAAG;IACtC,IAAKC,MAAM,CAACC,wBAAwB,EAAG;MACtC,IAAKC,OAAO,CAACC,GAAG,CAACC,mBAAmB,EAAG;QACtCd,mBAAmB,CAAEC,OAAQ,CAAC;MAC/B;IACD;IAEA,OAAOA,OAAO;EACf;EAEA,MAAMc,MAAM,GAAGxD,6BAA6B,CAACmC,IAAI,CAC9CsB,CAAC,IAAMA,CAAC,CAAC/F,IAAI,KAAKA,IACrB,CAAC;EACD,IAAK,CAAE8F,MAAM,EAAG;IACf,OAAO,EAAE;EACV;EAEAd,OAAO,GAAG,MAAMc,MAAM,CAACvD,YAAY,CAAC,CAAC;EACrC,IAAKkD,MAAM,CAACC,wBAAwB,EAAG;IACtC,IAAKC,OAAO,CAACC,GAAG,CAACC,mBAAmB,EAAG;MACtCd,mBAAmB,CAAEC,OAAQ,CAAC;IAC/B;EACD;EAEAM,QAAQ,CAAE,IAAAU,oBAAW,EAAEhB,OAAQ,CAAE,CAAC;EAElC,OAAOA,OAAO;AACf,CAAC;AAACrF,OAAA,CAAAyF,uBAAA,GAAAA,uBAAA"}
|
|
1
|
+
{"version":3,"names":["_changeCase","require","_apiFetch","_interopRequireDefault","_i18n","_actions","_sync","DEFAULT_ENTITY_KEY","exports","POST_RAW_ATTRIBUTES","POST_TYPE_ENTITIES_WITH_REVISIONS_SUPPORT","rootEntitiesConfig","label","__","kind","name","baseURL","baseURLParams","_fields","join","syncConfig","fetch","apiFetch","path","applyChangesToDoc","doc","changes","document","getMap","Object","entries","forEach","key","value","get","set","fromCRDTDoc","toJSON","syncObjectType","getSyncObjectId","getTitle","record","_record$title","title","context","id","plural","rawAttributes","supportsPagination","transientEdits","blocks","rendered","getRevisionsUrl","parentId","revisionId","supports","revisions","additionalEntityConfigLoaders","loadEntities","loadPostTypeEntities","loadTaxonomyEntities","prePersistPostType","persistedRecord","edits","newEdits","status","postTypes","map","postType","_postType$rest_namesp","isTemplate","includes","namespace","rest_namespace","rest_base","selection","mergedEdits","meta","slug","_record$slug","capitalCase","String","__unstablePrePersist","undefined","__unstable_rest_base","revisionKey","taxonomies","taxonomy","_taxonomy$rest_namesp","getMethodName","prefix","usePlural","entityConfig","find","config","kindPrefix","pascalCase","nameSuffix","suffix","registerSyncConfigs","configs","getSyncProvider","register","editSyncConfig","getOrLoadEntitiesConfig","select","dispatch","getEntitiesConfig","length","window","__experimentalEnableSync","process","env","IS_GUTENBERG_PLUGIN","loader","l","addEntities"],"sources":["@wordpress/core-data/src/entities.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { capitalCase, pascalCase } from 'change-case';\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 { getSyncProvider } from './sync';\n\nexport const DEFAULT_ENTITY_KEY = 'id';\n\nconst POST_RAW_ATTRIBUTES = [ 'title', 'excerpt', 'content' ];\n\n// A hardcoded list of post types that support revisions.\n// Reflects post types in Core's src/wp-includes/post.php.\n// @TODO: Ideally this should be fetched from the `/types` REST API's view context.\nconst POST_TYPE_ENTITIES_WITH_REVISIONS_SUPPORT = [\n\t'post',\n\t'page',\n\t'wp_block',\n\t'wp_navigation',\n\t'wp_template',\n\t'wp_template_part',\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\tsyncConfig: {\n\t\t\tfetch: async () => {\n\t\t\t\treturn apiFetch( { path: '/' } );\n\t\t\t},\n\t\t\tapplyChangesToDoc: ( doc, changes ) => {\n\t\t\t\tconst document = doc.getMap( 'document' );\n\t\t\t\tObject.entries( changes ).forEach( ( [ key, value ] ) => {\n\t\t\t\t\tif ( document.get( key ) !== value ) {\n\t\t\t\t\t\tdocument.set( key, value );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t},\n\t\t\tfromCRDTDoc: ( doc ) => {\n\t\t\t\treturn doc.getMap( 'document' ).toJSON();\n\t\t\t},\n\t\t},\n\t\tsyncObjectType: 'root/base',\n\t\tgetSyncObjectId: () => 'index',\n\t},\n\t{\n\t\tlabel: __( 'Site' ),\n\t\tname: 'site',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/settings',\n\t\tgetTitle: ( record ) => {\n\t\t\treturn record?.title ?? __( 'Site Title' );\n\t\t},\n\t\tsyncConfig: {\n\t\t\tfetch: async () => {\n\t\t\t\treturn apiFetch( { path: '/wp/v2/settings' } );\n\t\t\t},\n\t\t\tapplyChangesToDoc: ( doc, changes ) => {\n\t\t\t\tconst document = doc.getMap( 'document' );\n\t\t\t\tObject.entries( changes ).forEach( ( [ key, value ] ) => {\n\t\t\t\t\tif ( document.get( key ) !== value ) {\n\t\t\t\t\t\tdocument.set( key, value );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t},\n\t\t\tfromCRDTDoc: ( doc ) => {\n\t\t\t\treturn doc.getMap( 'document' ).toJSON();\n\t\t\t},\n\t\t},\n\t\tsyncObjectType: 'root/site',\n\t\tgetSyncObjectId: () => 'index',\n\t},\n\t{\n\t\tlabel: __( 'Post Type' ),\n\t\tname: 'postType',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tsyncConfig: {\n\t\t\tfetch: async ( id ) => {\n\t\t\t\treturn apiFetch( {\n\t\t\t\t\tpath: `/wp/v2/types/${ id }?context=edit`,\n\t\t\t\t} );\n\t\t\t},\n\t\t\tapplyChangesToDoc: ( doc, changes ) => {\n\t\t\t\tconst document = doc.getMap( 'document' );\n\t\t\t\tObject.entries( changes ).forEach( ( [ key, value ] ) => {\n\t\t\t\t\tif ( document.get( key ) !== value ) {\n\t\t\t\t\t\tdocument.set( key, value );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t},\n\t\t\tfromCRDTDoc: ( doc ) => {\n\t\t\t\treturn doc.getMap( 'document' ).toJSON();\n\t\t\t},\n\t\t},\n\t\tsyncObjectType: 'root/postType',\n\t\tgetSyncObjectId: ( id ) => id,\n\t},\n\t{\n\t\tname: 'media',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/media',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'mediaItems',\n\t\tlabel: __( 'Media' ),\n\t\trawAttributes: [ 'caption', 'title', 'description' ],\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tname: 'taxonomy',\n\t\tkind: 'root',\n\t\tkey: 'slug',\n\t\tbaseURL: '/wp/v2/taxonomies',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'taxonomies',\n\t\tlabel: __( 'Taxonomy' ),\n\t},\n\t{\n\t\tname: 'sidebar',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/sidebars',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'sidebars',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widget areas' ),\n\t},\n\t{\n\t\tname: 'widget',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widgets',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgets',\n\t\ttransientEdits: { blocks: true },\n\t\tlabel: __( 'Widgets' ),\n\t},\n\t{\n\t\tname: 'widgetType',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/widget-types',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'widgetTypes',\n\t\tlabel: __( 'Widget types' ),\n\t},\n\t{\n\t\tlabel: __( 'User' ),\n\t\tname: 'user',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/users',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'users',\n\t},\n\t{\n\t\tname: 'comment',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/comments',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'comments',\n\t\tlabel: __( 'Comment' ),\n\t},\n\t{\n\t\tname: 'menu',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menus',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menus',\n\t\tlabel: __( 'Menu' ),\n\t},\n\t{\n\t\tname: 'menuItem',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-items',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuItems',\n\t\tlabel: __( 'Menu Item' ),\n\t\trawAttributes: [ 'title' ],\n\t},\n\t{\n\t\tname: 'menuLocation',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/menu-locations',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'menuLocations',\n\t\tlabel: __( 'Menu Location' ),\n\t\tkey: 'name',\n\t},\n\t{\n\t\tlabel: __( 'Global Styles' ),\n\t\tname: 'globalStyles',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/global-styles',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'globalStylesVariations', // Should be different from name.\n\t\tgetTitle: ( record ) => record?.title?.rendered || record?.title,\n\t\tgetRevisionsUrl: ( parentId, revisionId ) =>\n\t\t\t`/wp/v2/global-styles/${ parentId }/revisions${\n\t\t\t\trevisionId ? '/' + revisionId : ''\n\t\t\t}`,\n\t\tsupports: {\n\t\t\trevisions: true,\n\t\t},\n\t\tsupportsPagination: true,\n\t},\n\t{\n\t\tlabel: __( 'Themes' ),\n\t\tname: 'theme',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/themes',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tkey: 'stylesheet',\n\t},\n\t{\n\t\tlabel: __( 'Plugins' ),\n\t\tname: 'plugin',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/plugins',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tkey: 'plugin',\n\t},\n\t{\n\t\tlabel: __( 'Status' ),\n\t\tname: 'status',\n\t\tkind: 'root',\n\t\tbaseURL: '/wp/v2/statuses',\n\t\tbaseURLParams: { context: 'edit' },\n\t\tplural: 'statuses',\n\t\tkey: 'slug',\n\t},\n];\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 = {};\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} );\n\treturn Object.entries( postTypes ?? {} ).map( ( [ name, postType ] ) => {\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\tsupports: {\n\t\t\t\trevisions: POST_TYPE_ENTITIES_WITH_REVISIONS_SUPPORT.includes(\n\t\t\t\t\tpostType?.slug\n\t\t\t\t),\n\t\t\t},\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\tsyncConfig: {\n\t\t\t\tfetch: async ( id ) => {\n\t\t\t\t\treturn apiFetch( {\n\t\t\t\t\t\tpath: `/${ namespace }/${ postType.rest_base }/${ id }?context=edit`,\n\t\t\t\t\t} );\n\t\t\t\t},\n\t\t\t\tapplyChangesToDoc: ( doc, changes ) => {\n\t\t\t\t\tconst document = doc.getMap( 'document' );\n\t\t\t\t\tObject.entries( changes ).forEach( ( [ key, value ] ) => {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\tdocument.get( key ) !== value &&\n\t\t\t\t\t\t\ttypeof value !== 'function'\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tdocument.set( key, value );\n\t\t\t\t\t\t}\n\t\t\t\t\t} );\n\t\t\t\t},\n\t\t\t\tfromCRDTDoc: ( doc ) => {\n\t\t\t\t\treturn doc.getMap( 'document' ).toJSON();\n\t\t\t\t},\n\t\t\t},\n\t\t\tsyncObjectType: 'postType/' + postType.name,\n\t\t\tgetSyncObjectId: ( id ) => id,\n\t\t\tsupportsPagination: true,\n\t\t\tgetRevisionsUrl: ( parentId, revisionId ) =>\n\t\t\t\t`/${ namespace }/${\n\t\t\t\t\tpostType.rest_base\n\t\t\t\t}/${ parentId }/revisions${\n\t\t\t\t\trevisionId ? '/' + revisionId : ''\n\t\t\t\t}`,\n\t\t\trevisionKey: isTemplate ? 'wp_id' : DEFAULT_ENTITY_KEY,\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} );\n\treturn Object.entries( taxonomies ?? {} ).map( ( [ name, taxonomy ] ) => {\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 = rootEntitiesConfig.find(\n\t\t( config ) => config.kind === kind && config.name === name\n\t);\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\nfunction registerSyncConfigs( configs ) {\n\tconfigs.forEach( ( { syncObjectType, syncConfig } ) => {\n\t\tgetSyncProvider().register( syncObjectType, syncConfig );\n\t\tconst editSyncConfig = { ...syncConfig };\n\t\tdelete editSyncConfig.fetch;\n\t\tgetSyncProvider().register( syncObjectType + '--edit', editSyncConfig );\n\t} );\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\tif ( window.__experimentalEnableSync ) {\n\t\t\t\tif ( process.env.IS_GUTENBERG_PLUGIN ) {\n\t\t\t\t\tregisterSyncConfigs( configs );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn configs;\n\t\t}\n\n\t\tconst loader = additionalEntityConfigLoaders.find(\n\t\t\t( l ) => l.kind === kind\n\t\t);\n\t\tif ( ! loader ) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconfigs = await loader.loadEntities();\n\t\tif ( window.__experimentalEnableSync ) {\n\t\t\tif ( process.env.IS_GUTENBERG_PLUGIN ) {\n\t\t\t\tregisterSyncConfigs( configs );\n\t\t\t}\n\t\t}\n\n\t\tdispatch( addEntities( configs ) );\n\n\t\treturn configs;\n\t};\n"],"mappings":";;;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAKA,IAAAI,QAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AAfA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AAIO,MAAMM,kBAAkB,GAAG,IAAI;AAACC,OAAA,CAAAD,kBAAA,GAAAA,kBAAA;AAEvC,MAAME,mBAAmB,GAAG,CAAE,OAAO,EAAE,SAAS,EAAE,SAAS,CAAE;;AAE7D;AACA;AACA;AACA,MAAMC,yCAAyC,GAAG,CACjD,MAAM,EACN,MAAM,EACN,UAAU,EACV,eAAe,EACf,aAAa,EACb,kBAAkB,CAClB;AAEM,MAAMC,kBAAkB,GAAG,CACjC;EACCC,KAAK,EAAE,IAAAC,QAAE,EAAE,MAAO,CAAC;EACnBC,IAAI,EAAE,MAAM;EACZC,IAAI,EAAE,gBAAgB;EACtBC,OAAO,EAAE,GAAG;EACZC,aAAa,EAAE;IACdC,OAAO,EAAE,CACR,aAAa,EACb,YAAY,EACZ,MAAM,EACN,MAAM,EACN,WAAW,EACX,eAAe,EACf,WAAW,EACX,iBAAiB,EACjB,KAAK,CACL,CAACC,IAAI,CAAE,GAAI;EACb,CAAC;EACDC,UAAU,EAAE;IACXC,KAAK,EAAE,MAAAA,CAAA,KAAY;MAClB,OAAO,IAAAC,iBAAQ,EAAE;QAAEC,IAAI,EAAE;MAAI,CAAE,CAAC;IACjC,CAAC;IACDC,iBAAiB,EAAEA,CAAEC,GAAG,EAAEC,OAAO,KAAM;MACtC,MAAMC,QAAQ,GAAGF,GAAG,CAACG,MAAM,CAAE,UAAW,CAAC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AAC5F,OAAA,CAAAgG,uBAAA,GAAAA,uBAAA"}
|
package/build/entity-provider.js
CHANGED
|
@@ -167,6 +167,9 @@ function useEntityBlockEditor(kind, name, {
|
|
|
167
167
|
editedBlocks,
|
|
168
168
|
meta
|
|
169
169
|
} = (0, _data.useSelect)(select => {
|
|
170
|
+
if (!id) {
|
|
171
|
+
return {};
|
|
172
|
+
}
|
|
170
173
|
const {
|
|
171
174
|
getEditedEntityRecord
|
|
172
175
|
} = select(_name.STORE_NAME);
|
|
@@ -182,11 +185,14 @@ function useEntityBlockEditor(kind, name, {
|
|
|
182
185
|
editEntityRecord
|
|
183
186
|
} = (0, _data.useDispatch)(_name.STORE_NAME);
|
|
184
187
|
const blocks = (0, _element.useMemo)(() => {
|
|
188
|
+
if (!id) {
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
185
191
|
if (editedBlocks) {
|
|
186
192
|
return editedBlocks;
|
|
187
193
|
}
|
|
188
194
|
return content && typeof content !== 'function' ? (0, _blocks2.parse)(content) : EMPTY_ARRAY;
|
|
189
|
-
}, [editedBlocks, content]);
|
|
195
|
+
}, [id, editedBlocks, content]);
|
|
190
196
|
const updateFootnotes = (0, _element.useCallback)(_blocks => (0, _footnotes.updateFootnotesFromMeta)(_blocks, meta), [meta]);
|
|
191
197
|
const onChange = (0, _element.useCallback)((newBlocks, options) => {
|
|
192
198
|
const noChange = blocks === newBlocks;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_data","_blocks2","_name","_footnotes","_entities","EMPTY_ARRAY","entityContexts","rootEntitiesConfig","reduce","acc","loader","kind","name","context","createContext","undefined","additionalEntityConfigLoaders","getEntityContext","Error","EntityProvider","type","id","children","Provider","_react","createElement","value","useEntityId","useContext","useEntityProp","prop","_id","providerId","fullValue","useSelect","select","getEntityRecord","getEditedEntityRecord","STORE_NAME","record","editedRecord","editEntityRecord","useDispatch","setValue","useCallback","newValue","useEntityBlockEditor","content","editedBlocks","meta","blocks","__unstableCreateUndoLevel","useMemo","parse","updateFootnotes","_blocks","updateFootnotesFromMeta","onChange","newBlocks","options","noChange","selection","edits","blocksForSerialization","__unstableSerializeAndClean","isCached","onInput","footnotesChanges"],"sources":["@wordpress/core-data/src/entity-provider.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { updateFootnotesFromMeta } from './footnotes';\n\n/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Internal dependencies\n */\nimport { rootEntitiesConfig, additionalEntityConfigLoaders } from './entities';\n\nconst entityContexts = {\n\t...rootEntitiesConfig.reduce( ( acc, loader ) => {\n\t\tif ( ! acc[ loader.kind ] ) {\n\t\t\tacc[ loader.kind ] = {};\n\t\t}\n\t\tacc[ loader.kind ][ loader.name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t\treturn acc;\n\t}, {} ),\n\t...additionalEntityConfigLoaders.reduce( ( acc, loader ) => {\n\t\tacc[ loader.kind ] = {};\n\t\treturn acc;\n\t}, {} ),\n};\nconst getEntityContext = ( kind, name ) => {\n\tif ( ! entityContexts[ kind ] ) {\n\t\tthrow new Error( `Missing entity config for kind: ${ kind }.` );\n\t}\n\n\tif ( ! entityContexts[ kind ][ name ] ) {\n\t\tentityContexts[ kind ][ name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t}\n\n\treturn entityContexts[ kind ][ name ].context;\n};\n\n/**\n * Context provider component for providing\n * an entity for a specific entity.\n *\n * @param {Object} props The component's props.\n * @param {string} props.kind The entity kind.\n * @param {string} props.type The entity name.\n * @param {number} props.id The entity ID.\n * @param {*} props.children The children to wrap.\n *\n * @return {Object} The provided children, wrapped with\n * the entity's context provider.\n */\nexport default function EntityProvider( { kind, type: name, id, children } ) {\n\tconst Provider = getEntityContext( kind, name ).Provider;\n\treturn <Provider value={ id }>{ children }</Provider>;\n}\n\n/**\n * Hook that returns the ID for the nearest\n * provided entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n */\nexport function useEntityId( kind, name ) {\n\treturn useContext( getEntityContext( kind, name ) );\n}\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {string} prop The property name.\n * @param {string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport function useEntityProp( kind, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ editEntityRecord, kind, name, id, prop ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n\n/**\n * Hook that returns block content getters and setters for\n * the nearest provided entity of the specified type.\n *\n * The return value has the shape `[ blocks, onInput, onChange ]`.\n * `onInput` is for block changes that don't create undo levels\n * or dirty the post, non-persistent changes, and `onChange` is for\n * persistent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[WPBlock[], Function, Function]} The block array and setters.\n */\nexport function useEntityBlockEditor( kind, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst { content, editedBlocks, meta } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEditedEntityRecord } = select( STORE_NAME );\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn {\n\t\t\t\teditedBlocks: editedRecord.blocks,\n\t\t\t\tcontent: editedRecord.content,\n\t\t\t\tmeta: editedRecord.meta,\n\t\t\t};\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\tconst { __unstableCreateUndoLevel, editEntityRecord } =\n\t\tuseDispatch( STORE_NAME );\n\n\tconst blocks = useMemo( () => {\n\t\tif ( editedBlocks ) {\n\t\t\treturn editedBlocks;\n\t\t}\n\n\t\treturn content && typeof content !== 'function'\n\t\t\t? parse( content )\n\t\t\t: EMPTY_ARRAY;\n\t}, [ editedBlocks, content ] );\n\n\tconst updateFootnotes = useCallback(\n\t\t( _blocks ) => updateFootnotesFromMeta( _blocks, meta ),\n\t\t[ meta ]\n\t);\n\n\tconst onChange = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst noChange = blocks === newBlocks;\n\t\t\tif ( noChange ) {\n\t\t\t\treturn __unstableCreateUndoLevel( kind, name, id );\n\t\t\t}\n\t\t\tconst { selection } = options;\n\n\t\t\t// We create a new function here on every persistent edit\n\t\t\t// to make sure the edit makes the post dirty and creates\n\t\t\t// a new undo level.\n\t\t\tconst edits = {\n\t\t\t\tselection,\n\t\t\t\tcontent: ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t\t\t__unstableSerializeAndClean( blocksForSerialization ),\n\t\t\t\t...updateFootnotes( newBlocks ),\n\t\t\t};\n\n\t\t\teditEntityRecord( kind, name, id, edits, { isCached: false } );\n\t\t},\n\t\t[\n\t\t\tkind,\n\t\t\tname,\n\t\t\tid,\n\t\t\tblocks,\n\t\t\tupdateFootnotes,\n\t\t\t__unstableCreateUndoLevel,\n\t\t\teditEntityRecord,\n\t\t]\n\t);\n\n\tconst onInput = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst footnotesChanges = updateFootnotes( newBlocks );\n\t\t\tconst edits = { selection, ...footnotesChanges };\n\n\t\t\teditEntityRecord( kind, name, id, edits, { isCached: true } );\n\t\t},\n\t\t[ kind, name, id, updateFootnotes, editEntityRecord ]\n\t);\n\n\treturn [ blocks, onInput, onChange ];\n}\n"],"mappings":";;;;;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAMA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AAKA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AASA,IAAAK,SAAA,GAAAL,OAAA;AAzBA;AACA;AACA;;AAUA;AACA;AACA;;AAIA;;AAEA,MAAMM,WAAW,GAAG,EAAE;;AAEtB;AACA;AACA;;AAGA,MAAMC,cAAc,GAAG;EACtB,GAAGC,4BAAkB,CAACC,MAAM,CAAE,CAAEC,GAAG,EAAEC,MAAM,KAAM;IAChD,IAAK,CAAED,GAAG,CAAEC,MAAM,CAACC,IAAI,CAAE,EAAG;MAC3BF,GAAG,CAAEC,MAAM,CAACC,IAAI,CAAE,GAAG,CAAC,CAAC;IACxB;IACAF,GAAG,CAAEC,MAAM,CAACC,IAAI,CAAE,CAAED,MAAM,CAACE,IAAI,CAAE,GAAG;MACnC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ACD,CAAEtD,IAAI,EAAEC,IAAI,EAAES,EAAE,EAAEiC,eAAe,EAAEb,gBAAgB,CACpD,CAAC;EAED,OAAO,CAAES,MAAM,EAAEgB,OAAO,EAAET,QAAQ,CAAE;AACrC"}
|
|
1
|
+
{"version":3,"names":["_element","require","_data","_blocks2","_name","_footnotes","_entities","EMPTY_ARRAY","entityContexts","rootEntitiesConfig","reduce","acc","loader","kind","name","context","createContext","undefined","additionalEntityConfigLoaders","getEntityContext","Error","EntityProvider","type","id","children","Provider","_react","createElement","value","useEntityId","useContext","useEntityProp","prop","_id","providerId","fullValue","useSelect","select","getEntityRecord","getEditedEntityRecord","STORE_NAME","record","editedRecord","editEntityRecord","useDispatch","setValue","useCallback","newValue","useEntityBlockEditor","content","editedBlocks","meta","blocks","__unstableCreateUndoLevel","useMemo","parse","updateFootnotes","_blocks","updateFootnotesFromMeta","onChange","newBlocks","options","noChange","selection","edits","blocksForSerialization","__unstableSerializeAndClean","isCached","onInput","footnotesChanges"],"sources":["@wordpress/core-data/src/entity-provider.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseContext,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { parse, __unstableSerializeAndClean } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport { STORE_NAME } from './name';\nimport { updateFootnotesFromMeta } from './footnotes';\n\n/** @typedef {import('@wordpress/blocks').WPBlock} WPBlock */\n\nconst EMPTY_ARRAY = [];\n\n/**\n * Internal dependencies\n */\nimport { rootEntitiesConfig, additionalEntityConfigLoaders } from './entities';\n\nconst entityContexts = {\n\t...rootEntitiesConfig.reduce( ( acc, loader ) => {\n\t\tif ( ! acc[ loader.kind ] ) {\n\t\t\tacc[ loader.kind ] = {};\n\t\t}\n\t\tacc[ loader.kind ][ loader.name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t\treturn acc;\n\t}, {} ),\n\t...additionalEntityConfigLoaders.reduce( ( acc, loader ) => {\n\t\tacc[ loader.kind ] = {};\n\t\treturn acc;\n\t}, {} ),\n};\nconst getEntityContext = ( kind, name ) => {\n\tif ( ! entityContexts[ kind ] ) {\n\t\tthrow new Error( `Missing entity config for kind: ${ kind }.` );\n\t}\n\n\tif ( ! entityContexts[ kind ][ name ] ) {\n\t\tentityContexts[ kind ][ name ] = {\n\t\t\tcontext: createContext( undefined ),\n\t\t};\n\t}\n\n\treturn entityContexts[ kind ][ name ].context;\n};\n\n/**\n * Context provider component for providing\n * an entity for a specific entity.\n *\n * @param {Object} props The component's props.\n * @param {string} props.kind The entity kind.\n * @param {string} props.type The entity name.\n * @param {number} props.id The entity ID.\n * @param {*} props.children The children to wrap.\n *\n * @return {Object} The provided children, wrapped with\n * the entity's context provider.\n */\nexport default function EntityProvider( { kind, type: name, id, children } ) {\n\tconst Provider = getEntityContext( kind, name ).Provider;\n\treturn <Provider value={ id }>{ children }</Provider>;\n}\n\n/**\n * Hook that returns the ID for the nearest\n * provided entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n */\nexport function useEntityId( kind, name ) {\n\treturn useContext( getEntityContext( kind, name ) );\n}\n\n/**\n * Hook that returns the value and a setter for the\n * specified property of the nearest provided\n * entity of the specified type.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {string} prop The property name.\n * @param {string} [_id] An entity ID to use instead of the context-provided one.\n *\n * @return {[*, Function, *]} An array where the first item is the\n * property value, the second is the\n * setter and the third is the full value\n * \t\t\t\t\t\t\t object from REST API containing more\n * \t\t\t\t\t\t\t information like `raw`, `rendered` and\n * \t\t\t\t\t\t\t `protected` props.\n */\nexport function useEntityProp( kind, name, prop, _id ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\n\tconst { value, fullValue } = useSelect(\n\t\t( select ) => {\n\t\t\tconst { getEntityRecord, getEditedEntityRecord } =\n\t\t\t\tselect( STORE_NAME );\n\t\t\tconst record = getEntityRecord( kind, name, id ); // Trigger resolver.\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn record && editedRecord\n\t\t\t\t? {\n\t\t\t\t\t\tvalue: editedRecord[ prop ],\n\t\t\t\t\t\tfullValue: record[ prop ],\n\t\t\t\t }\n\t\t\t\t: {};\n\t\t},\n\t\t[ kind, name, id, prop ]\n\t);\n\tconst { editEntityRecord } = useDispatch( STORE_NAME );\n\tconst setValue = useCallback(\n\t\t( newValue ) => {\n\t\t\teditEntityRecord( kind, name, id, {\n\t\t\t\t[ prop ]: newValue,\n\t\t\t} );\n\t\t},\n\t\t[ editEntityRecord, kind, name, id, prop ]\n\t);\n\n\treturn [ value, setValue, fullValue ];\n}\n\n/**\n * Hook that returns block content getters and setters for\n * the nearest provided entity of the specified type.\n *\n * The return value has the shape `[ blocks, onInput, onChange ]`.\n * `onInput` is for block changes that don't create undo levels\n * or dirty the post, non-persistent changes, and `onChange` is for\n * persistent changes. They map directly to the props of a\n * `BlockEditorProvider` and are intended to be used with it,\n * or similar components or hooks.\n *\n * @param {string} kind The entity kind.\n * @param {string} name The entity name.\n * @param {Object} options\n * @param {string} [options.id] An entity ID to use instead of the context-provided one.\n *\n * @return {[WPBlock[], Function, Function]} The block array and setters.\n */\nexport function useEntityBlockEditor( kind, name, { id: _id } = {} ) {\n\tconst providerId = useEntityId( kind, name );\n\tconst id = _id ?? providerId;\n\tconst { content, editedBlocks, meta } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! id ) {\n\t\t\t\treturn {};\n\t\t\t}\n\t\t\tconst { getEditedEntityRecord } = select( STORE_NAME );\n\t\t\tconst editedRecord = getEditedEntityRecord( kind, name, id );\n\t\t\treturn {\n\t\t\t\teditedBlocks: editedRecord.blocks,\n\t\t\t\tcontent: editedRecord.content,\n\t\t\t\tmeta: editedRecord.meta,\n\t\t\t};\n\t\t},\n\t\t[ kind, name, id ]\n\t);\n\tconst { __unstableCreateUndoLevel, editEntityRecord } =\n\t\tuseDispatch( STORE_NAME );\n\n\tconst blocks = useMemo( () => {\n\t\tif ( ! id ) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif ( editedBlocks ) {\n\t\t\treturn editedBlocks;\n\t\t}\n\n\t\treturn content && typeof content !== 'function'\n\t\t\t? parse( content )\n\t\t\t: EMPTY_ARRAY;\n\t}, [ id, editedBlocks, content ] );\n\n\tconst updateFootnotes = useCallback(\n\t\t( _blocks ) => updateFootnotesFromMeta( _blocks, meta ),\n\t\t[ meta ]\n\t);\n\n\tconst onChange = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst noChange = blocks === newBlocks;\n\t\t\tif ( noChange ) {\n\t\t\t\treturn __unstableCreateUndoLevel( kind, name, id );\n\t\t\t}\n\t\t\tconst { selection } = options;\n\n\t\t\t// We create a new function here on every persistent edit\n\t\t\t// to make sure the edit makes the post dirty and creates\n\t\t\t// a new undo level.\n\t\t\tconst edits = {\n\t\t\t\tselection,\n\t\t\t\tcontent: ( { blocks: blocksForSerialization = [] } ) =>\n\t\t\t\t\t__unstableSerializeAndClean( blocksForSerialization ),\n\t\t\t\t...updateFootnotes( newBlocks ),\n\t\t\t};\n\n\t\t\teditEntityRecord( kind, name, id, edits, { isCached: false } );\n\t\t},\n\t\t[\n\t\t\tkind,\n\t\t\tname,\n\t\t\tid,\n\t\t\tblocks,\n\t\t\tupdateFootnotes,\n\t\t\t__unstableCreateUndoLevel,\n\t\t\teditEntityRecord,\n\t\t]\n\t);\n\n\tconst onInput = useCallback(\n\t\t( newBlocks, options ) => {\n\t\t\tconst { selection } = options;\n\t\t\tconst footnotesChanges = updateFootnotes( newBlocks );\n\t\t\tconst edits = { selection, ...footnotesChanges };\n\n\t\t\teditEntityRecord( kind, name, id, edits, { isCached: true } );\n\t\t},\n\t\t[ kind, name, id, updateFootnotes, editEntityRecord ]\n\t);\n\n\treturn [ blocks, onInput, onChange ];\n}\n"],"mappings":";;;;;;;;;;AAGA,IAAAA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AAG,CAAC,KACjD,IAAAC,oCAA2B,EAAED,sBAAuB,CAAC;MACtD,GAAGT,eAAe,CAAEI,SAAU;IAC/B,CAAC;IAEDjB,gBAAgB,CAAE9B,IAAI,EAAEC,IAAI,EAAES,EAAE,EAAEyC,KAAK,EAAE;MAAEG,QAAQ,EAAE;IAAM,CAAE,CAAC;EAC/D,CAAC,EACD,CACCtD,IAAI,EACJC,IAAI,EACJS,EAAE,EACF6B,MAAM,EACNI,eAAe,EACfH,yBAAyB,EACzBV,gBAAgB,CAElB,CAAC;EAED,MAAMyB,OAAO,GAAG,IAAAtB,oBAAW,EAC1B,CAAEc,SAAS,EAAEC,OAAO,KAAM;IACzB,MAAM;MAAEE;IAAU,CAAC,GAAGF,OAAO;IAC7B,MAAMQ,gBAAgB,GAAGb,eAAe,CAAEI,SAAU,CAAC;IACrD,MAAMI,KAAK,GAAG;MAAED,SAAS;MAAE,GAAGM;IAAiB,CAAC;IAEhD1B,gBAAgB,CAAE9B,IAAI,EAAEC,IAAI,EAAES,EAAE,EAAEyC,KAAK,EAAE;MAAEG,QAAQ,EAAE;IAAK,CAAE,CAAC;EAC9D,CAAC,EACD,CAAEtD,IAAI,EAAEC,IAAI,EAAES,EAAE,EAAEiC,eAAe,EAAEb,gBAAgB,CACpD,CAAC;EAED,OAAO,CAAES,MAAM,EAAEgB,OAAO,EAAET,QAAQ,CAAE;AACrC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/core-data/src/entity-types/global-styles-revision.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { Context, ContextualField, OmitNevers } from './helpers';\n\nimport type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';\n\ndeclare module './base-entity-records' {\n\texport namespace BaseEntityRecords {\n\t\texport interface GlobalStylesRevision< C extends Context > {\n\t\t\t/**\n\t\t\t * The ID for the author of the global styles revision.\n\t\t\t */\n\t\t\tauthor: number;\n\t\t\t/**\n\t\t\t * The date the post global styles revision published, in the site's timezone.\n\t\t\t */\n\t\t\tdate: string | null;\n\t\t\t/**\n\t\t\t * The date the global styles revision was published, as GMT.\n\t\t\t */\n\t\t\tdate_gmt: ContextualField< string | null, 'view' | 'edit', C >;\n\t\t\t/**\n\t\t\t * Unique identifier for the revision.\n\t\t\t */\n\t\t\tid: number;\n\t\t\t/**\n\t\t\t * The date the global styles revision was last modified, in the site's timezone.\n\t\t\t */\n\t\t\tmodified: ContextualField< string, 'view' | 'edit', C >;\n\t\t\t/**\n\t\t\t * The date the global styles revision was last modified, as GMT.\n\t\t\t */\n\t\t\tmodified_gmt: ContextualField< string, 'view' | 'edit', C >;\n\t\t\t/**\n\t\t\t * Identifier for the parent of the revision.\n\t\t\t */\n\t\t\tparent: number;\n\t\t\tstyles: Record< string, Object >;\n\t\t\tsettings: Record< string, Object >;\n\t\t}\n\t}\n}\n\nexport type GlobalStylesRevision< C extends Context = 'view' > = OmitNevers<\n\t_BaseEntityRecords.GlobalStylesRevision< C >\n>;\n"],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["@wordpress/core-data/src/entity-types/index.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { Context, Updatable } from './helpers';\nimport type { Attachment } from './attachment';\nimport type { Comment } from './comment';\nimport type { MenuLocation } from './menu-location';\nimport type { NavMenu } from './nav-menu';\nimport type { NavMenuItem } from './nav-menu-item';\nimport type { Page } from './page';\nimport type { Plugin } from './plugin';\nimport type { Post } from './post';\nimport type { Settings } from './settings';\nimport type { Sidebar } from './sidebar';\nimport type { Taxonomy } from './taxonomy';\nimport type { Theme } from './theme';\nimport type { User } from './user';\nimport type { Type } from './type';\nimport type { Widget } from './widget';\nimport type { WidgetType } from './widget-type';\nimport type { WpTemplate } from './wp-template';\nimport type { WpTemplatePart } from './wp-template-part';\n\nexport type { BaseEntityRecords } from './base-entity-records';\n\nexport type {\n\tAttachment,\n\tComment,\n\tContext,\n\tMenuLocation,\n\tNavMenu,\n\tNavMenuItem,\n\tPage,\n\tPlugin,\n\tPost,\n\tSettings,\n\tSidebar,\n\tTaxonomy,\n\tTheme,\n\tUpdatable,\n\tUser,\n\tType,\n\tWidget,\n\tWidgetType,\n\tWpTemplate,\n\tWpTemplatePart,\n};\n\n/**\n * An interface that may be extended to add types for new entities. Each entry\n * must be a union of entity definitions adhering to the EntityInterface type.\n *\n * Example:\n *\n * ```ts\n * import type { Context } from '@wordpress/core-data';\n * // ...\n *\n * interface Client {\n * id: number;\n * name: string;\n * // ...\n * }\n *\n * interface Order< C extends Context > {\n * id: number;\n * name: string;\n * // ...\n * }\n *\n * declare module '@wordpress/core-data' {\n * export interface PerPackageEntityRecords< C extends Context > {\n * myPlugin: Client | Order<C>>\n * }\n * }\n *\n * const c = getEntityRecord<Order>( 'myPlugin', 'order', 15 );\n * // c is of the type Order\n * ```\n */\nexport interface PerPackageEntityRecords< C extends Context > {\n\tcore:\n\t\t| Attachment< C >\n\t\t| Comment< C >\n\t\t| MenuLocation< C >\n\t\t| NavMenu< C >\n\t\t| NavMenuItem< C >\n\t\t| Page< C >\n\t\t| Plugin< C >\n\t\t| Post< C >\n\t\t| Settings< C >\n\t\t| Sidebar< C >\n\t\t| Taxonomy< C >\n\t\t| Theme< C >\n\t\t| User< C >\n\t\t| Type< C >\n\t\t| Widget< C >\n\t\t| WidgetType< C >\n\t\t| WpTemplate< C >\n\t\t| WpTemplatePart< C >;\n}\n\n/**\n * A union of all known record types.\n */\nexport type EntityRecord< C extends Context = 'edit' > =\n\tPerPackageEntityRecords< C >[ keyof PerPackageEntityRecords< C > ];\n"],"mappings":""}
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/core-data/src/entity-types/index.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { Context, Updatable } from './helpers';\nimport type { Attachment } from './attachment';\nimport type { Comment } from './comment';\nimport type { GlobalStylesRevision } from './global-styles-revision';\nimport type { MenuLocation } from './menu-location';\nimport type { NavMenu } from './nav-menu';\nimport type { NavMenuItem } from './nav-menu-item';\nimport type { Page } from './page';\nimport type { Plugin } from './plugin';\nimport type { Post } from './post';\nimport type { PostRevision } from './post-revision';\nimport type { Settings } from './settings';\nimport type { Sidebar } from './sidebar';\nimport type { Taxonomy } from './taxonomy';\nimport type { Theme } from './theme';\nimport type { User } from './user';\nimport type { Type } from './type';\nimport type { Widget } from './widget';\nimport type { WidgetType } from './widget-type';\nimport type { WpTemplate } from './wp-template';\nimport type { WpTemplatePart } from './wp-template-part';\n\nexport type { BaseEntityRecords } from './base-entity-records';\n\nexport type {\n\tAttachment,\n\tComment,\n\tContext,\n\tGlobalStylesRevision,\n\tMenuLocation,\n\tNavMenu,\n\tNavMenuItem,\n\tPage,\n\tPlugin,\n\tPost,\n\tPostRevision,\n\tSettings,\n\tSidebar,\n\tTaxonomy,\n\tTheme,\n\tUpdatable,\n\tUser,\n\tType,\n\tWidget,\n\tWidgetType,\n\tWpTemplate,\n\tWpTemplatePart,\n};\n\n/**\n * An interface that may be extended to add types for new entities. Each entry\n * must be a union of entity definitions adhering to the EntityInterface type.\n *\n * Example:\n *\n * ```ts\n * import type { Context } from '@wordpress/core-data';\n * // ...\n *\n * interface Client {\n * id: number;\n * name: string;\n * // ...\n * }\n *\n * interface Order< C extends Context > {\n * id: number;\n * name: string;\n * // ...\n * }\n *\n * declare module '@wordpress/core-data' {\n * export interface PerPackageEntityRecords< C extends Context > {\n * myPlugin: Client | Order<C>>\n * }\n * }\n *\n * const c = getEntityRecord<Order>( 'myPlugin', 'order', 15 );\n * // c is of the type Order\n * ```\n */\nexport interface PerPackageEntityRecords< C extends Context > {\n\tcore:\n\t\t| Attachment< C >\n\t\t| Comment< C >\n\t\t| GlobalStylesRevision< C >\n\t\t| MenuLocation< C >\n\t\t| NavMenu< C >\n\t\t| NavMenuItem< C >\n\t\t| Page< C >\n\t\t| Plugin< C >\n\t\t| Post< C >\n\t\t| PostRevision< C >\n\t\t| Settings< C >\n\t\t| Sidebar< C >\n\t\t| Taxonomy< C >\n\t\t| Theme< C >\n\t\t| User< C >\n\t\t| Type< C >\n\t\t| Widget< C >\n\t\t| WidgetType< C >\n\t\t| WpTemplate< C >\n\t\t| WpTemplatePart< C >;\n}\n\n/**\n * A union of all known record types.\n */\nexport type EntityRecord< C extends Context = 'edit' > =\n\tPerPackageEntityRecords< C >[ keyof PerPackageEntityRecords< C > ];\n"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/core-data/src/entity-types/post-revision.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type {\n\tContext,\n\tContextualField,\n\tRenderedText,\n\tOmitNevers,\n} from './helpers';\n\nimport type { BaseEntityRecords as _BaseEntityRecords } from './base-entity-records';\n\ndeclare module './base-entity-records' {\n\texport namespace BaseEntityRecords {\n\t\texport interface PostRevision< C extends Context > {\n\t\t\t/**\n\t\t\t * The ID for the author of the post revision.\n\t\t\t */\n\t\t\tauthor: number;\n\t\t\t/**\n\t\t\t * The content for the post.\n\t\t\t */\n\t\t\tcontent: ContextualField<\n\t\t\t\tRenderedText< C > & {\n\t\t\t\t\t/**\n\t\t\t\t\t * Whether the content is protected with a password.\n\t\t\t\t\t */\n\t\t\t\t\tis_protected: boolean;\n\t\t\t\t\t/**\n\t\t\t\t\t * Version of the content block format used by the post.\n\t\t\t\t\t */\n\t\t\t\t\tblock_version: ContextualField< string, 'edit', C >;\n\t\t\t\t},\n\t\t\t\t'view' | 'edit',\n\t\t\t\tC\n\t\t\t>;\n\t\t\t/**\n\t\t\t * The date the post was published, in the site's timezone.\n\t\t\t */\n\t\t\tdate: string | null;\n\t\t\t/**\n\t\t\t * The date the post was published, as GMT.\n\t\t\t */\n\t\t\tdate_gmt: ContextualField< string | null, 'view' | 'edit', C >;\n\t\t\t/**\n\t\t\t * The excerpt for the post revision.\n\t\t\t */\n\t\t\texcerpt: RenderedText< C > & {\n\t\t\t\tprotected: boolean;\n\t\t\t};\n\t\t\t/**\n\t\t\t * The globally unique identifier for the post.\n\t\t\t */\n\t\t\tguid: ContextualField< RenderedText< C >, 'view' | 'edit', C >;\n\t\t\t/**\n\t\t\t * Unique identifier for the revision.\n\t\t\t */\n\t\t\tid: number;\n\t\t\t/**\n\t\t\t * Meta fields.\n\t\t\t */\n\t\t\tmeta: ContextualField<\n\t\t\t\tRecord< string, string >,\n\t\t\t\t'view' | 'edit',\n\t\t\t\tC\n\t\t\t>;\n\t\t\t/**\n\t\t\t * The date the post was last modified, in the site's timezone.\n\t\t\t */\n\t\t\tmodified: ContextualField< string, 'view' | 'edit', C >;\n\t\t\t/**\n\t\t\t * The date the post revision was last modified, as GMT.\n\t\t\t */\n\t\t\tmodified_gmt: ContextualField< string, 'view' | 'edit', C >;\n\t\t\t/**\n\t\t\t * Identifier for the parent of the revision.\n\t\t\t */\n\t\t\tparent: number;\n\t\t\t/**\n\t\t\t * An alphanumeric identifier for the post unique to its type.\n\t\t\t */\n\t\t\tslug: string;\n\t\t\t/**\n\t\t\t * The title for the post revision.\n\t\t\t */\n\t\t\ttitle: RenderedText< C >;\n\t\t}\n\t}\n}\n\nexport type PostRevision< C extends Context = 'view' > = OmitNevers<\n\t_BaseEntityRecords.PostRevision< C >\n>;\n"],"mappings":""}
|
|
@@ -19,6 +19,8 @@ var _ = require("../");
|
|
|
19
19
|
* Internal dependencies
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
+
const EMPTY_OBJECT = {};
|
|
23
|
+
|
|
22
24
|
/**
|
|
23
25
|
* Resolves the specified entity record.
|
|
24
26
|
*
|
|
@@ -125,11 +127,20 @@ function useEntityRecord(kind, name, recordId, options = {
|
|
|
125
127
|
editedRecord,
|
|
126
128
|
hasEdits,
|
|
127
129
|
edits
|
|
128
|
-
} = (0, _data.useSelect)(select =>
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
} = (0, _data.useSelect)(select => {
|
|
131
|
+
if (!options.enabled) {
|
|
132
|
+
return {
|
|
133
|
+
editedRecord: EMPTY_OBJECT,
|
|
134
|
+
hasEdits: false,
|
|
135
|
+
edits: EMPTY_OBJECT
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
editedRecord: select(_.store).getEditedEntityRecord(kind, name, recordId),
|
|
140
|
+
hasEdits: select(_.store).hasEditsForEntityRecord(kind, name, recordId),
|
|
141
|
+
edits: select(_.store).getEntityRecordNonTransientEdits(kind, name, recordId)
|
|
142
|
+
};
|
|
143
|
+
}, [kind, name, recordId, options.enabled]);
|
|
133
144
|
const {
|
|
134
145
|
data: record,
|
|
135
146
|
...querySelectRest
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_deprecated","_interopRequireDefault","_element","_useQuerySelect","_","useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","useDispatch","coreStore","mutations","useMemo","edit","record","editOptions","save","saveOptions","throwOnError","editedRecord","hasEdits","edits","useSelect","select","getEditedEntityRecord","hasEditsForEntityRecord","getEntityRecordNonTransientEdits","data","querySelectRest","useQuerySelect","query","getEntityRecord","__experimentalUseEntityRecord","deprecated","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"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/** The edits to the edited entity record */\n\tedits: 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 * @since 6.1.0 Introduced in WordPress core.\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 { useCallback } from 'react';\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 { 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, editOptions: any = {} ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record, editOptions ),\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[ editEntityRecord, kind, name, recordId, saveEditedEntityRecord ]\n\t);\n\n\tconst { editedRecord, hasEdits, edits } = 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\tedits: select( coreStore ).getEntityRecordNonTransientEdits(\n\t\t\t\tkind,\n\t\t\t\tname,\n\t\t\t\trecordId\n\t\t\t),\n\t\t}
|
|
1
|
+
{"version":3,"names":["_data","require","_deprecated","_interopRequireDefault","_element","_useQuerySelect","_","EMPTY_OBJECT","useEntityRecord","kind","name","recordId","options","enabled","editEntityRecord","saveEditedEntityRecord","useDispatch","coreStore","mutations","useMemo","edit","record","editOptions","save","saveOptions","throwOnError","editedRecord","hasEdits","edits","useSelect","select","getEditedEntityRecord","hasEditsForEntityRecord","getEntityRecordNonTransientEdits","data","querySelectRest","useQuerySelect","query","getEntityRecord","__experimentalUseEntityRecord","deprecated","alternative","since"],"sources":["@wordpress/core-data/src/hooks/use-entity-record.ts"],"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/** The edits to the edited entity record */\n\tedits: 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\nconst EMPTY_OBJECT = {};\n\n/**\n * Resolves the specified entity record.\n *\n * @since 6.1.0 Introduced in WordPress core.\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 { useCallback } from 'react';\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 { 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, editOptions: any = {} ) =>\n\t\t\t\teditEntityRecord( kind, name, recordId, record, editOptions ),\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[ editEntityRecord, kind, name, recordId, saveEditedEntityRecord ]\n\t);\n\n\tconst { editedRecord, hasEdits, edits } = useSelect(\n\t\t( select ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\teditedRecord: EMPTY_OBJECT,\n\t\t\t\t\thasEdits: false,\n\t\t\t\t\tedits: EMPTY_OBJECT,\n\t\t\t\t};\n\t\t\t}\n\n\t\t\treturn {\n\t\t\t\teditedRecord: select( coreStore ).getEditedEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t\thasEdits: select( coreStore ).hasEditsForEntityRecord(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t\tedits: select( coreStore ).getEntityRecordNonTransientEdits(\n\t\t\t\t\tkind,\n\t\t\t\t\tname,\n\t\t\t\t\trecordId\n\t\t\t\t),\n\t\t\t};\n\t\t},\n\t\t[ kind, name, recordId, options.enabled ]\n\t);\n\n\tconst { data: record, ...querySelectRest } = useQuerySelect(\n\t\t( query ) => {\n\t\t\tif ( ! options.enabled ) {\n\t\t\t\treturn {\n\t\t\t\t\tdata: null,\n\t\t\t\t};\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\tedits,\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"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AAKA,IAAAI,eAAA,GAAAF,sBAAA,CAAAF,OAAA;AACA,IAAAK,CAAA,GAAAL,OAAA;AAXA;AACA;AACA;;AAKA;AACA;AACA;;AAiDA,MAAMM,YAAY,GAAG,CAAC,CAAC;;AAEvB;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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AAM,CAAEb,OAAU,CAAC,CAACe,uBAAuB,CACpDvB,IAAI,EACJC,IAAI,EACJC,QACD,CAAC;MACDiB,KAAK,EAAEE,MAAM,CAAEb,OAAU,CAAC,CAACgB,gCAAgC,CAC1DxB,IAAI,EACJC,IAAI,EACJC,QACD;IACD,CAAC;EACF,CAAC,EACD,CAAEF,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,CAACC,OAAO,CACxC,CAAC;EAED,MAAM;IAAEqB,IAAI,EAAEb,MAAM;IAAE,GAAGc;EAAgB,CAAC,GAAG,IAAAC,uBAAc,EACxDC,KAAK,IAAM;IACZ,IAAK,CAAEzB,OAAO,CAACC,OAAO,EAAG;MACxB,OAAO;QACNqB,IAAI,EAAE;MACP,CAAC;IACF;IACA,OAAOG,KAAK,CAAEpB,OAAU,CAAC,CAACqB,eAAe,CAAE7B,IAAI,EAAEC,IAAI,EAAEC,QAAS,CAAC;EAClE,CAAC,EACD,CAAEF,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAO,CAACC,OAAO,CACxC,CAAC;EAED,OAAO;IACNQ,MAAM;IACNK,YAAY;IACZC,QAAQ;IACRC,KAAK;IACL,GAAGO,eAAe;IAClB,GAAGjB;EACJ,CAAC;AACF;AAEO,SAASqB,6BAA6BA,CAC5C9B,IAAY,EACZC,IAAY,EACZC,QAAa,EACbC,OAAY,EACX;EACD,IAAA4B,mBAAU,EAAG,uCAAsC,EAAE;IACpDC,WAAW,EAAE,yBAAyB;IACtCC,KAAK,EAAE;EACR,CAAE,CAAC;EACH,OAAOlC,eAAe,CAAEC,IAAI,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,OAAQ,CAAC;AACxD"}
|
|
@@ -59,7 +59,9 @@ function getMergedItemIds(itemIds, nextItemIds, page, perPage) {
|
|
|
59
59
|
const mergedItemIds = new Array(size);
|
|
60
60
|
for (let i = 0; i < size; i++) {
|
|
61
61
|
// Preserve existing item ID except for subset of range of next items.
|
|
62
|
-
|
|
62
|
+
// We need to check against the possible maximum upper boundary because
|
|
63
|
+
// a page could receive fewer than what was previously stored.
|
|
64
|
+
const isInNextItemsRange = i >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + perPage;
|
|
63
65
|
mergedItemIds[i] = isInNextItemsRange ? nextItemIds[i - nextItemIdsStartIndex] : itemIds?.[i];
|
|
64
66
|
}
|
|
65
67
|
return mergedItemIds;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_compose","_utils","_entities","_getQueryParts","_interopRequireDefault","getContextFromAction","action","query","queryParts","getQueryParts","context","getMergedItemIds","itemIds","nextItemIds","page","perPage","_itemIds$length","receivedAllIds","nextItemIdsStartIndex","size","Math","max","length","mergedItemIds","Array","i","isInNextItemsRange","removeEntitiesById","entities","ids","Object","fromEntries","entries","filter","id","some","itemId","Number","isInteger","items","state","type","key","DEFAULT_ENTITY_KEY","reduce","accumulator","value","conservativeMapItem","map","contextState","itemIsComplete","isCompleteQuery","isArray","fields","result","item","receiveQueries","compose","ifMatchingAction","replaceAction","onSubKey","meta","queries","removedItems","queryGroup","contextQueries","queryItems","queryId","_default","combineReducers","exports","default"],"sources":["@wordpress/core-data/src/queried-data/reducer.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tconservativeMapItem,\n\tifMatchingAction,\n\treplaceAction,\n\tonSubKey,\n} from '../utils';\nimport { DEFAULT_ENTITY_KEY } from '../entities';\nimport getQueryParts from './get-query-parts';\n\nfunction getContextFromAction( action ) {\n\tconst { query } = action;\n\tif ( ! query ) {\n\t\treturn 'default';\n\t}\n\n\tconst queryParts = getQueryParts( query );\n\treturn queryParts.context;\n}\n\n/**\n * Returns a merged array of item IDs, given details of the received paginated\n * items. The array is sparse-like with `undefined` entries where holes exist.\n *\n * @param {?Array<number>} itemIds Original item IDs (default empty array).\n * @param {number[]} nextItemIds Item IDs to merge.\n * @param {number} page Page of items merged.\n * @param {number} perPage Number of items per page.\n *\n * @return {number[]} Merged array of item IDs.\n */\nexport function getMergedItemIds( itemIds, nextItemIds, page, perPage ) {\n\tconst receivedAllIds = page === 1 && perPage === -1;\n\tif ( receivedAllIds ) {\n\t\treturn nextItemIds;\n\t}\n\tconst nextItemIdsStartIndex = ( page - 1 ) * perPage;\n\n\t// If later page has already been received, default to the larger known\n\t// size of the existing array, else calculate as extending the existing.\n\tconst size = Math.max(\n\t\titemIds?.length ?? 0,\n\t\tnextItemIdsStartIndex + nextItemIds.length\n\t);\n\n\t// Preallocate array since size is known.\n\tconst mergedItemIds = new Array( size );\n\n\tfor ( let i = 0; i < size; i++ ) {\n\t\t// Preserve existing item ID except for subset of range of next items.\n\t\tconst isInNextItemsRange =\n\t\t\ti >= nextItemIdsStartIndex &&\n\t\t\ti < nextItemIdsStartIndex + nextItemIds.length;\n\n\t\tmergedItemIds[ i ] = isInNextItemsRange\n\t\t\t? nextItemIds[ i - nextItemIdsStartIndex ]\n\t\t\t: itemIds?.[ i ];\n\t}\n\n\treturn mergedItemIds;\n}\n\n/**\n * Helper function to filter out entities with certain IDs.\n * Entities are keyed by their ID.\n *\n * @param {Object} entities Entity objects, keyed by entity ID.\n * @param {Array} ids Entity IDs to filter out.\n *\n * @return {Object} Filtered entities.\n */\nfunction removeEntitiesById( entities, ids ) {\n\treturn Object.fromEntries(\n\t\tObject.entries( entities ).filter(\n\t\t\t( [ id ] ) =>\n\t\t\t\t! ids.some( ( itemId ) => {\n\t\t\t\t\tif ( Number.isInteger( itemId ) ) {\n\t\t\t\t\t\treturn itemId === +id;\n\t\t\t\t\t}\n\t\t\t\t\treturn itemId === id;\n\t\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Reducer tracking items state, keyed by ID. Items are assumed to be normal,\n * where identifiers are common across all queries.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nexport function items( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst key = action.key || DEFAULT_ENTITY_KEY;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...action.items.reduce( ( accumulator, value ) => {\n\t\t\t\t\t\tconst itemId = value[ key ];\n\t\t\t\t\t\taccumulator[ itemId ] = conservativeMapItem(\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ],\n\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn accumulator;\n\t\t\t\t\t}, {} ),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\treturn state;\n}\n\n/**\n * Reducer tracking item completeness, keyed by ID. A complete item is one for\n * which all fields are known. This is used in supporting `_fields` queries,\n * where not all properties associated with an entity are necessarily returned.\n * In such cases, completeness is used as an indication of whether it would be\n * safe to use queried data for a non-`_fields`-limited request.\n *\n * @param {Object<string,Object<string,boolean>>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object<string,Object<string,boolean>>} Next state.\n */\nexport function itemIsComplete( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst { query, key = DEFAULT_ENTITY_KEY } = action;\n\n\t\t\t// An item is considered complete if it is received without an associated\n\t\t\t// fields query. Ideally, this would be implemented in such a way where the\n\t\t\t// complete aggregate of all fields would satisfy completeness. Since the\n\t\t\t// fields are not consistent across all entities, this would require\n\t\t\t// introspection on the REST schema for each entity to know which fields\n\t\t\t// compose a complete item for that entity.\n\t\t\tconst queryParts = query ? getQueryParts( query ) : {};\n\t\t\tconst isCompleteQuery =\n\t\t\t\t! query || ! Array.isArray( queryParts.fields );\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...action.items.reduce( ( result, item ) => {\n\t\t\t\t\t\tconst itemId = item[ key ];\n\n\t\t\t\t\t\t// Defer to completeness if already assigned. Technically the\n\t\t\t\t\t\t// data may be outdated if receiving items for a field subset.\n\t\t\t\t\t\tresult[ itemId ] =\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ] || isCompleteQuery;\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}, {} ),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer tracking queries state, keyed by stable query key. Each reducer\n * query object includes `itemIds` and `requestingPageByPerPage`.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst receiveQueries = compose( [\n\t// Limit to matching action type so we don't attempt to replace action on\n\t// an unhandled action.\n\tifMatchingAction( ( action ) => 'query' in action ),\n\n\t// Inject query parts into action for use both in `onSubKey` and reducer.\n\treplaceAction( ( action ) => {\n\t\t// `ifMatchingAction` still passes on initialization, where state is\n\t\t// undefined and a query is not assigned. Avoid attempting to parse\n\t\t// parts. `onSubKey` will omit by lack of `stableKey`.\n\t\tif ( action.query ) {\n\t\t\treturn {\n\t\t\t\t...action,\n\t\t\t\t...getQueryParts( action.query ),\n\t\t\t};\n\t\t}\n\n\t\treturn action;\n\t} ),\n\n\tonSubKey( 'context' ),\n\n\t// Queries shape is shared, but keyed by query `stableKey` part. Original\n\t// reducer tracks only a single query object.\n\tonSubKey( 'stableKey' ),\n] )( ( state = {}, action ) => {\n\tconst { type, page, perPage, key = DEFAULT_ENTITY_KEY } = action;\n\n\tif ( type !== 'RECEIVE_ITEMS' ) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\titemIds: getMergedItemIds(\n\t\t\tstate?.itemIds || [],\n\t\t\taction.items.map( ( item ) => item[ key ] ),\n\t\t\tpage,\n\t\t\tperPage\n\t\t),\n\t\tmeta: action.meta,\n\t};\n} );\n\n/**\n * Reducer tracking queries state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst queries = ( state = {}, action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS':\n\t\t\treturn receiveQueries( state, action );\n\t\tcase 'REMOVE_ITEMS':\n\t\t\tconst removedItems = action.itemIds.reduce( ( result, itemId ) => {\n\t\t\t\tresult[ itemId ] = true;\n\t\t\t\treturn result;\n\t\t\t}, {} );\n\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map(\n\t\t\t\t\t( [ queryGroup, contextQueries ] ) => [\n\t\t\t\t\t\tqueryGroup,\n\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\tObject.entries( contextQueries ).map(\n\t\t\t\t\t\t\t\t( [ query, queryItems ] ) => [\n\t\t\t\t\t\t\t\t\tquery,\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t...queryItems,\n\t\t\t\t\t\t\t\t\t\titemIds: queryItems.itemIds.filter(\n\t\t\t\t\t\t\t\t\t\t\t( queryId ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t! removedItems[ queryId ]\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t]\n\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AAK;EACd;AACD,CAAC;AAAC,IAAA4B,QAAA,GAEa,IAAAC,qBAAe,EAAE;EAC/B9B,KAAK;EACLW,cAAc;EACdY;AACD,CAAE,CAAC;AAAAQ,OAAA,CAAAC,OAAA,GAAAH,QAAA"}
|
|
1
|
+
{"version":3,"names":["_data","require","_compose","_utils","_entities","_getQueryParts","_interopRequireDefault","getContextFromAction","action","query","queryParts","getQueryParts","context","getMergedItemIds","itemIds","nextItemIds","page","perPage","_itemIds$length","receivedAllIds","nextItemIdsStartIndex","size","Math","max","length","mergedItemIds","Array","i","isInNextItemsRange","removeEntitiesById","entities","ids","Object","fromEntries","entries","filter","id","some","itemId","Number","isInteger","items","state","type","key","DEFAULT_ENTITY_KEY","reduce","accumulator","value","conservativeMapItem","map","contextState","itemIsComplete","isCompleteQuery","isArray","fields","result","item","receiveQueries","compose","ifMatchingAction","replaceAction","onSubKey","meta","queries","removedItems","queryGroup","contextQueries","queryItems","queryId","_default","combineReducers","exports","default"],"sources":["@wordpress/core-data/src/queried-data/reducer.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { combineReducers } from '@wordpress/data';\nimport { compose } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport {\n\tconservativeMapItem,\n\tifMatchingAction,\n\treplaceAction,\n\tonSubKey,\n} from '../utils';\nimport { DEFAULT_ENTITY_KEY } from '../entities';\nimport getQueryParts from './get-query-parts';\n\nfunction getContextFromAction( action ) {\n\tconst { query } = action;\n\tif ( ! query ) {\n\t\treturn 'default';\n\t}\n\n\tconst queryParts = getQueryParts( query );\n\treturn queryParts.context;\n}\n\n/**\n * Returns a merged array of item IDs, given details of the received paginated\n * items. The array is sparse-like with `undefined` entries where holes exist.\n *\n * @param {?Array<number>} itemIds Original item IDs (default empty array).\n * @param {number[]} nextItemIds Item IDs to merge.\n * @param {number} page Page of items merged.\n * @param {number} perPage Number of items per page.\n *\n * @return {number[]} Merged array of item IDs.\n */\nexport function getMergedItemIds( itemIds, nextItemIds, page, perPage ) {\n\tconst receivedAllIds = page === 1 && perPage === -1;\n\tif ( receivedAllIds ) {\n\t\treturn nextItemIds;\n\t}\n\tconst nextItemIdsStartIndex = ( page - 1 ) * perPage;\n\n\t// If later page has already been received, default to the larger known\n\t// size of the existing array, else calculate as extending the existing.\n\tconst size = Math.max(\n\t\titemIds?.length ?? 0,\n\t\tnextItemIdsStartIndex + nextItemIds.length\n\t);\n\n\t// Preallocate array since size is known.\n\tconst mergedItemIds = new Array( size );\n\n\tfor ( let i = 0; i < size; i++ ) {\n\t\t// Preserve existing item ID except for subset of range of next items.\n\t\t// We need to check against the possible maximum upper boundary because\n\t\t// a page could receive fewer than what was previously stored.\n\t\tconst isInNextItemsRange =\n\t\t\ti >= nextItemIdsStartIndex && i < nextItemIdsStartIndex + perPage;\n\t\tmergedItemIds[ i ] = isInNextItemsRange\n\t\t\t? nextItemIds[ i - nextItemIdsStartIndex ]\n\t\t\t: itemIds?.[ i ];\n\t}\n\n\treturn mergedItemIds;\n}\n\n/**\n * Helper function to filter out entities with certain IDs.\n * Entities are keyed by their ID.\n *\n * @param {Object} entities Entity objects, keyed by entity ID.\n * @param {Array} ids Entity IDs to filter out.\n *\n * @return {Object} Filtered entities.\n */\nfunction removeEntitiesById( entities, ids ) {\n\treturn Object.fromEntries(\n\t\tObject.entries( entities ).filter(\n\t\t\t( [ id ] ) =>\n\t\t\t\t! ids.some( ( itemId ) => {\n\t\t\t\t\tif ( Number.isInteger( itemId ) ) {\n\t\t\t\t\t\treturn itemId === +id;\n\t\t\t\t\t}\n\t\t\t\t\treturn itemId === id;\n\t\t\t\t} )\n\t\t)\n\t);\n}\n\n/**\n * Reducer tracking items state, keyed by ID. Items are assumed to be normal,\n * where identifiers are common across all queries.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nexport function items( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst key = action.key || DEFAULT_ENTITY_KEY;\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...action.items.reduce( ( accumulator, value ) => {\n\t\t\t\t\t\tconst itemId = value[ key ];\n\t\t\t\t\t\taccumulator[ itemId ] = conservativeMapItem(\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ],\n\t\t\t\t\t\t\tvalue\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn accumulator;\n\t\t\t\t\t}, {} ),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\treturn state;\n}\n\n/**\n * Reducer tracking item completeness, keyed by ID. A complete item is one for\n * which all fields are known. This is used in supporting `_fields` queries,\n * where not all properties associated with an entity are necessarily returned.\n * In such cases, completeness is used as an indication of whether it would be\n * safe to use queried data for a non-`_fields`-limited request.\n *\n * @param {Object<string,Object<string,boolean>>} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object<string,Object<string,boolean>>} Next state.\n */\nexport function itemIsComplete( state = {}, action ) {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS': {\n\t\t\tconst context = getContextFromAction( action );\n\t\t\tconst { query, key = DEFAULT_ENTITY_KEY } = action;\n\n\t\t\t// An item is considered complete if it is received without an associated\n\t\t\t// fields query. Ideally, this would be implemented in such a way where the\n\t\t\t// complete aggregate of all fields would satisfy completeness. Since the\n\t\t\t// fields are not consistent across all entities, this would require\n\t\t\t// introspection on the REST schema for each entity to know which fields\n\t\t\t// compose a complete item for that entity.\n\t\t\tconst queryParts = query ? getQueryParts( query ) : {};\n\t\t\tconst isCompleteQuery =\n\t\t\t\t! query || ! Array.isArray( queryParts.fields );\n\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\t[ context ]: {\n\t\t\t\t\t...state[ context ],\n\t\t\t\t\t...action.items.reduce( ( result, item ) => {\n\t\t\t\t\t\tconst itemId = item[ key ];\n\n\t\t\t\t\t\t// Defer to completeness if already assigned. Technically the\n\t\t\t\t\t\t// data may be outdated if receiving items for a field subset.\n\t\t\t\t\t\tresult[ itemId ] =\n\t\t\t\t\t\t\tstate?.[ context ]?.[ itemId ] || isCompleteQuery;\n\n\t\t\t\t\t\treturn result;\n\t\t\t\t\t}, {} ),\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t\tcase 'REMOVE_ITEMS':\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map( ( [ itemId, contextState ] ) => [\n\t\t\t\t\titemId,\n\t\t\t\t\tremoveEntitiesById( contextState, action.itemIds ),\n\t\t\t\t] )\n\t\t\t);\n\t}\n\n\treturn state;\n}\n\n/**\n * Reducer tracking queries state, keyed by stable query key. Each reducer\n * query object includes `itemIds` and `requestingPageByPerPage`.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst receiveQueries = compose( [\n\t// Limit to matching action type so we don't attempt to replace action on\n\t// an unhandled action.\n\tifMatchingAction( ( action ) => 'query' in action ),\n\n\t// Inject query parts into action for use both in `onSubKey` and reducer.\n\treplaceAction( ( action ) => {\n\t\t// `ifMatchingAction` still passes on initialization, where state is\n\t\t// undefined and a query is not assigned. Avoid attempting to parse\n\t\t// parts. `onSubKey` will omit by lack of `stableKey`.\n\t\tif ( action.query ) {\n\t\t\treturn {\n\t\t\t\t...action,\n\t\t\t\t...getQueryParts( action.query ),\n\t\t\t};\n\t\t}\n\n\t\treturn action;\n\t} ),\n\n\tonSubKey( 'context' ),\n\n\t// Queries shape is shared, but keyed by query `stableKey` part. Original\n\t// reducer tracks only a single query object.\n\tonSubKey( 'stableKey' ),\n] )( ( state = {}, action ) => {\n\tconst { type, page, perPage, key = DEFAULT_ENTITY_KEY } = action;\n\n\tif ( type !== 'RECEIVE_ITEMS' ) {\n\t\treturn state;\n\t}\n\n\treturn {\n\t\titemIds: getMergedItemIds(\n\t\t\tstate?.itemIds || [],\n\t\t\taction.items.map( ( item ) => item[ key ] ),\n\t\t\tpage,\n\t\t\tperPage\n\t\t),\n\t\tmeta: action.meta,\n\t};\n} );\n\n/**\n * Reducer tracking queries state.\n *\n * @param {Object} state Current state.\n * @param {Object} action Dispatched action.\n *\n * @return {Object} Next state.\n */\nconst queries = ( state = {}, action ) => {\n\tswitch ( action.type ) {\n\t\tcase 'RECEIVE_ITEMS':\n\t\t\treturn receiveQueries( state, action );\n\t\tcase 'REMOVE_ITEMS':\n\t\t\tconst removedItems = action.itemIds.reduce( ( result, itemId ) => {\n\t\t\t\tresult[ itemId ] = true;\n\t\t\t\treturn result;\n\t\t\t}, {} );\n\n\t\t\treturn Object.fromEntries(\n\t\t\t\tObject.entries( state ).map(\n\t\t\t\t\t( [ queryGroup, contextQueries ] ) => [\n\t\t\t\t\t\tqueryGroup,\n\t\t\t\t\t\tObject.fromEntries(\n\t\t\t\t\t\t\tObject.entries( contextQueries ).map(\n\t\t\t\t\t\t\t\t( [ query, queryItems ] ) => [\n\t\t\t\t\t\t\t\t\tquery,\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t...queryItems,\n\t\t\t\t\t\t\t\t\t\titemIds: queryItems.itemIds.filter(\n\t\t\t\t\t\t\t\t\t\t\t( queryId ) =>\n\t\t\t\t\t\t\t\t\t\t\t\t! removedItems[ queryId ]\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t),\n\t\t\t\t\t]\n\t\t\t\t)\n\t\t\t);\n\t\tdefault:\n\t\t\treturn state;\n\t}\n};\n\nexport default combineReducers( {\n\titems,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ACLW,cAAc;EACdY;AACD,CAAE,CAAC;AAAAQ,OAAA,CAAAC,OAAA,GAAAH,QAAA"}
|
|
@@ -59,7 +59,9 @@ function getQueriedItemsUncached(state, query) {
|
|
|
59
59
|
if (Array.isArray(include) && !include.includes(itemId)) {
|
|
60
60
|
continue;
|
|
61
61
|
}
|
|
62
|
-
|
|
62
|
+
if (itemId === undefined) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
63
65
|
// Having a target item ID doesn't guarantee that this object has been queried.
|
|
64
66
|
if (!state.items[context]?.hasOwnProperty(itemId)) {
|
|
65
67
|
return null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_rememo","_interopRequireDefault","require","_equivalentKeyMap","_getQueryParts","_utils","queriedItemsCacheByState","WeakMap","getQueriedItemsUncached","state","query","stableKey","page","perPage","include","fields","context","getQueryParts","itemIds","queries","startOffset","endOffset","length","Math","min","items","i","itemId","Array","isArray","includes","hasOwnProperty","item","filteredItem","f","field","split","value","forEach","fieldName","setNestedValue","itemIsComplete","push","getQueriedItems","createSelector","queriedItemsCache","get","queriedItems","
|
|
1
|
+
{"version":3,"names":["_rememo","_interopRequireDefault","require","_equivalentKeyMap","_getQueryParts","_utils","queriedItemsCacheByState","WeakMap","getQueriedItemsUncached","state","query","stableKey","page","perPage","include","fields","context","getQueryParts","itemIds","queries","startOffset","endOffset","length","Math","min","items","i","itemId","Array","isArray","includes","undefined","hasOwnProperty","item","filteredItem","f","field","split","value","forEach","fieldName","setNestedValue","itemIsComplete","push","getQueriedItems","createSelector","queriedItemsCache","get","queriedItems","EquivalentKeyMap","set","exports","getQueriedTotalItems","_state$queries$contex","meta","totalItems"],"sources":["@wordpress/core-data/src/queried-data/selectors.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport createSelector from 'rememo';\nimport EquivalentKeyMap from 'equivalent-key-map';\n\n/**\n * Internal dependencies\n */\nimport getQueryParts from './get-query-parts';\nimport { setNestedValue } from '../utils';\n\n/**\n * Cache of state keys to EquivalentKeyMap where the inner map tracks queries\n * to their resulting items set. WeakMap allows garbage collection on expired\n * state references.\n *\n * @type {WeakMap<Object,EquivalentKeyMap>}\n */\nconst queriedItemsCacheByState = new WeakMap();\n\n/**\n * Returns items for a given query, or null if the items are not known.\n *\n * @param {Object} state State object.\n * @param {?Object} query Optional query.\n *\n * @return {?Array} Query items.\n */\nfunction getQueriedItemsUncached( state, query ) {\n\tconst { stableKey, page, perPage, include, fields, context } =\n\t\tgetQueryParts( query );\n\tlet itemIds;\n\n\tif ( state.queries?.[ context ]?.[ stableKey ] ) {\n\t\titemIds = state.queries[ context ][ stableKey ].itemIds;\n\t}\n\n\tif ( ! itemIds ) {\n\t\treturn null;\n\t}\n\n\tconst startOffset = perPage === -1 ? 0 : ( page - 1 ) * perPage;\n\tconst endOffset =\n\t\tperPage === -1\n\t\t\t? itemIds.length\n\t\t\t: Math.min( startOffset + perPage, itemIds.length );\n\n\tconst items = [];\n\tfor ( let i = startOffset; i < endOffset; i++ ) {\n\t\tconst itemId = itemIds[ i ];\n\t\tif ( Array.isArray( include ) && ! include.includes( itemId ) ) {\n\t\t\tcontinue;\n\t\t}\n\t\tif ( itemId === undefined ) {\n\t\t\tcontinue;\n\t\t}\n\t\t// Having a target item ID doesn't guarantee that this object has been queried.\n\t\tif ( ! state.items[ context ]?.hasOwnProperty( itemId ) ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst item = state.items[ context ][ itemId ];\n\n\t\tlet filteredItem;\n\t\tif ( Array.isArray( fields ) ) {\n\t\t\tfilteredItem = {};\n\n\t\t\tfor ( let f = 0; f < fields.length; f++ ) {\n\t\t\t\tconst field = fields[ f ].split( '.' );\n\t\t\t\tlet value = item;\n\t\t\t\tfield.forEach( ( fieldName ) => {\n\t\t\t\t\tvalue = value?.[ fieldName ];\n\t\t\t\t} );\n\n\t\t\t\tsetNestedValue( filteredItem, field, value );\n\t\t\t}\n\t\t} else {\n\t\t\t// If expecting a complete item, validate that completeness, or\n\t\t\t// otherwise abort.\n\t\t\tif ( ! state.itemIsComplete[ context ]?.[ itemId ] ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tfilteredItem = item;\n\t\t}\n\n\t\titems.push( filteredItem );\n\t}\n\n\treturn items;\n}\n\n/**\n * Returns items for a given query, or null if the items are not known. Caches\n * result both per state (by reference) and per query (by deep equality).\n * The caching approach is intended to be durable to query objects which are\n * deeply but not referentially equal, since otherwise:\n *\n * `getQueriedItems( state, {} ) !== getQueriedItems( state, {} )`\n *\n * @param {Object} state State object.\n * @param {?Object} query Optional query.\n *\n * @return {?Array} Query items.\n */\nexport const getQueriedItems = createSelector( ( state, query = {} ) => {\n\tlet queriedItemsCache = queriedItemsCacheByState.get( state );\n\tif ( queriedItemsCache ) {\n\t\tconst queriedItems = queriedItemsCache.get( query );\n\t\tif ( queriedItems !== undefined ) {\n\t\t\treturn queriedItems;\n\t\t}\n\t} else {\n\t\tqueriedItemsCache = new EquivalentKeyMap();\n\t\tqueriedItemsCacheByState.set( state, queriedItemsCache );\n\t}\n\n\tconst items = getQueriedItemsUncached( state, query );\n\tqueriedItemsCache.set( query, items );\n\treturn items;\n} );\n\nexport function getQueriedTotalItems( state, query = {} ) {\n\tconst { stableKey, context } = getQueryParts( query );\n\n\treturn state.queries?.[ context ]?.[ stableKey ]?.meta?.totalItems ?? null;\n}\n"],"mappings":";;;;;;;;AAGA,IAAAA,OAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAF,sBAAA,CAAAC,OAAA;AAKA,IAAAE,cAAA,GAAAH,sBAAA,CAAAC,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAVA;AACA;AACA;;AAIA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMI,wBAAwB,GAAG,IAAIC,OAAO,CAAC,CAAC;;AAE9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,uBAAuBA,CAAEC,KAAK,EAAEC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4C,GAAG,CAAEzC,KAAK,EAAEqC,iBAAkB,CAAC;EACzD;EAEA,MAAMrB,KAAK,GAAGjB,uBAAuB,CAAEC,KAAK,EAAEC,KAAM,CAAC;EACrDoC,iBAAiB,CAACI,GAAG,CAAExC,KAAK,EAAEe,KAAM,CAAC;EACrC,OAAOA,KAAK;AACb,CAAE,CAAC;AAAC0B,OAAA,CAAAP,eAAA,GAAAA,eAAA;AAEG,SAASQ,oBAAoBA,CAAE3C,KAAK,EAAEC,KAAK,GAAG,CAAC,CAAC,EAAG;EAAA,IAAA2C,qBAAA;EACzD,MAAM;IAAE1C,SAAS;IAAEK;EAAQ,CAAC,GAAG,IAAAC,sBAAa,EAAEP,KAAM,CAAC;EAErD,QAAA2C,qBAAA,GAAO5C,KAAK,CAACU,OAAO,GAAIH,OAAO,CAAE,GAAIL,SAAS,CAAE,EAAE2C,IAAI,EAAEC,UAAU,cAAAF,qBAAA,cAAAA,qBAAA,GAAI,IAAI;AAC3E"}
|
package/build/reducer.js
CHANGED
|
@@ -11,6 +11,7 @@ exports.currentGlobalStylesId = currentGlobalStylesId;
|
|
|
11
11
|
exports.currentTheme = currentTheme;
|
|
12
12
|
exports.currentUser = currentUser;
|
|
13
13
|
exports.default = void 0;
|
|
14
|
+
exports.defaultTemplates = defaultTemplates;
|
|
14
15
|
exports.editsReference = editsReference;
|
|
15
16
|
exports.embedPreviews = embedPreviews;
|
|
16
17
|
exports.entities = void 0;
|
|
@@ -250,8 +251,8 @@ function entity(entityConfig) {
|
|
|
250
251
|
// Inject the entity config into the action.
|
|
251
252
|
(0, _utils.replaceAction)(action => {
|
|
252
253
|
return {
|
|
253
|
-
|
|
254
|
-
|
|
254
|
+
key: entityConfig.key || _entities.DEFAULT_ENTITY_KEY,
|
|
255
|
+
...action
|
|
255
256
|
};
|
|
256
257
|
})])((0, _data.combineReducers)({
|
|
257
258
|
queriedData: _queriedData.reducer,
|
|
@@ -342,7 +343,34 @@ function entity(entityConfig) {
|
|
|
342
343
|
};
|
|
343
344
|
}
|
|
344
345
|
return state;
|
|
345
|
-
}
|
|
346
|
+
},
|
|
347
|
+
// Add revisions to the state tree if the post type supports it.
|
|
348
|
+
...(entityConfig?.supports?.revisions ? {
|
|
349
|
+
revisions: (state = {}, action) => {
|
|
350
|
+
// Use the same queriedDataReducer shape for revisions.
|
|
351
|
+
if (action.type === 'RECEIVE_ITEM_REVISIONS') {
|
|
352
|
+
const recordKey = action.recordKey;
|
|
353
|
+
delete action.recordKey;
|
|
354
|
+
const newState = (0, _queriedData.reducer)(state[recordKey], {
|
|
355
|
+
...action,
|
|
356
|
+
type: 'RECEIVE_ITEMS'
|
|
357
|
+
});
|
|
358
|
+
return {
|
|
359
|
+
...state,
|
|
360
|
+
[recordKey]: newState
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
if (action.type === 'REMOVE_ITEMS') {
|
|
364
|
+
return Object.fromEntries(Object.entries(state).filter(([id]) => !action.itemIds.some(itemId => {
|
|
365
|
+
if (Number.isInteger(itemId)) {
|
|
366
|
+
return itemId === +id;
|
|
367
|
+
}
|
|
368
|
+
return itemId === id;
|
|
369
|
+
})));
|
|
370
|
+
}
|
|
371
|
+
return state;
|
|
372
|
+
}
|
|
373
|
+
} : {})
|
|
346
374
|
}));
|
|
347
375
|
}
|
|
348
376
|
|
|
@@ -535,6 +563,25 @@ function themeGlobalStyleRevisions(state = {}, action) {
|
|
|
535
563
|
}
|
|
536
564
|
return state;
|
|
537
565
|
}
|
|
566
|
+
|
|
567
|
+
/**
|
|
568
|
+
* Reducer managing the template lookup per query.
|
|
569
|
+
*
|
|
570
|
+
* @param {Record<string, string>} state Current state.
|
|
571
|
+
* @param {Object} action Dispatched action.
|
|
572
|
+
*
|
|
573
|
+
* @return {Record<string, string>} Updated state.
|
|
574
|
+
*/
|
|
575
|
+
function defaultTemplates(state = {}, action) {
|
|
576
|
+
switch (action.type) {
|
|
577
|
+
case 'RECEIVE_DEFAULT_TEMPLATE':
|
|
578
|
+
return {
|
|
579
|
+
...state,
|
|
580
|
+
[JSON.stringify(action.query)]: action.templateId
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
return state;
|
|
584
|
+
}
|
|
538
585
|
var _default = (0, _data.combineReducers)({
|
|
539
586
|
terms,
|
|
540
587
|
users,
|
|
@@ -554,7 +601,8 @@ var _default = (0, _data.combineReducers)({
|
|
|
554
601
|
blockPatterns,
|
|
555
602
|
blockPatternCategories,
|
|
556
603
|
userPatternCategories,
|
|
557
|
-
navigationFallbackId
|
|
604
|
+
navigationFallbackId,
|
|
605
|
+
defaultTemplates
|
|
558
606
|
});
|
|
559
607
|
exports.default = _default;
|
|
560
608
|
//# sourceMappingURL=reducer.js.map
|