@wordpress/block-library
Version:
Block library for the WordPress editor.
8 lines (7 loc) • 3.5 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../../src/navigation/use-navigation-entities.js"],
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEntityRecords } from '@wordpress/core-data';\n\n/**\n * @typedef {Object} NavigationEntitiesData\n * @property {Array|undefined} pages - a collection of WP Post entity objects of post type \"Page\".\n * @property {boolean} isResolvingPages - indicates whether the request to fetch pages is currently resolving.\n * @property {boolean} hasResolvedPages - indicates whether the request to fetch pages has finished resolving.\n * @property {Array|undefined} menus - a collection of Menu entity objects.\n * @property {boolean} isResolvingMenus - indicates whether the request to fetch menus is currently resolving.\n * @property {boolean} hasResolvedMenus - indicates whether the request to fetch menus has finished resolving.\n * @property {Array|undefined} menusItems - a collection of Menu Item entity objects for the current menuId.\n * @property {boolean} hasResolvedMenuItems - indicates whether the request to fetch menuItems has finished resolving.\n * @property {boolean} hasPages - indicates whether there is currently any data for pages.\n * @property {boolean} hasMenus - indicates whether there is currently any data for menus.\n */\n\n/**\n * Manages fetching and resolution state for all entities required\n * for the Navigation block.\n *\n * @param {number} menuId the menu for which to retrieve menuItem data.\n * @return { NavigationEntitiesData } the entity data.\n */\nexport default function useNavigationEntities( menuId ) {\n\tconst {\n\t\trecords: menus,\n\t\tisResolving: isResolvingMenus,\n\t\thasResolved: hasResolvedMenus,\n\t} = useEntityRecords( 'root', 'menu', { per_page: -1, context: 'view' } );\n\n\tconst {\n\t\trecords: pages,\n\t\tisResolving: isResolvingPages,\n\t\thasResolved: hasResolvedPages,\n\t} = useEntityRecords( 'postType', 'page', {\n\t\tparent: 0,\n\t\torder: 'asc',\n\t\torderby: 'id',\n\t\tper_page: -1,\n\t\tcontext: 'view',\n\t} );\n\n\tconst { records: menuItems, hasResolved: hasResolvedMenuItems } =\n\t\tuseEntityRecords(\n\t\t\t'root',\n\t\t\t'menuItem',\n\t\t\t{\n\t\t\t\tmenus: menuId,\n\t\t\t\tper_page: -1,\n\t\t\t\tcontext: 'view',\n\t\t\t},\n\t\t\t{ enabled: !! menuId }\n\t\t);\n\n\treturn {\n\t\tpages,\n\t\tisResolvingPages,\n\t\thasResolvedPages,\n\t\thasPages: !! ( hasResolvedPages && pages?.length ),\n\n\t\tmenus,\n\t\tisResolvingMenus,\n\t\thasResolvedMenus,\n\t\thasMenus: !! ( hasResolvedMenus && menus?.length ),\n\n\t\tmenuItems,\n\t\thasResolvedMenuItems,\n\t};\n}\n"],
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAiC;AAuBlB,SAAR,sBAAwC,QAAS;AACvD,QAAM;AAAA,IACL,SAAS;AAAA,IACT,aAAa;AAAA,IACb,aAAa;AAAA,EACd,QAAI,mCAAkB,QAAQ,QAAQ,EAAE,UAAU,IAAI,SAAS,OAAO,CAAE;AAExE,QAAM;AAAA,IACL,SAAS;AAAA,IACT,aAAa;AAAA,IACb,aAAa;AAAA,EACd,QAAI,mCAAkB,YAAY,QAAQ;AAAA,IACzC,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,SAAS;AAAA,IACT,UAAU;AAAA,IACV,SAAS;AAAA,EACV,CAAE;AAEF,QAAM,EAAE,SAAS,WAAW,aAAa,qBAAqB,QAC7D;AAAA,IACC;AAAA,IACA;AAAA,IACA;AAAA,MACC,OAAO;AAAA,MACP,UAAU;AAAA,MACV,SAAS;AAAA,IACV;AAAA,IACA,EAAE,SAAS,CAAC,CAAE,OAAO;AAAA,EACtB;AAED,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,CAAC,EAAI,oBAAoB,OAAO;AAAA,IAE1C;AAAA,IACA;AAAA,IACA;AAAA,IACA,UAAU,CAAC,EAAI,oBAAoB,OAAO;AAAA,IAE1C;AAAA,IACA;AAAA,EACD;AACD;",
"names": []
}