@wordpress/edit-site 4.12.0 → 4.13.1-next.957ca95e4c.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -0
- package/build/components/add-new-template/new-template.js +8 -3
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/add-new-template/utils.js +90 -52
- package/build/components/add-new-template/utils.js.map +1 -1
- package/build/components/block-editor/resizable-editor.js +26 -12
- package/build/components/block-editor/resizable-editor.js.map +1 -1
- package/build/components/global-styles/border-panel.js +3 -3
- package/build/components/global-styles/border-panel.js.map +1 -1
- package/build/components/global-styles/dimensions-panel.js +110 -7
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/hooks.js +4 -4
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/preview.js +2 -2
- package/build/components/global-styles/preview.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +28 -21
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +42 -10
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/global-styles/utils.js +39 -5
- package/build/components/global-styles/utils.js.map +1 -1
- package/build/components/header/document-actions/index.js +1 -0
- package/build/components/header/document-actions/index.js.map +1 -1
- package/build/components/header/index.js +5 -2
- package/build/components/header/index.js.map +1 -1
- package/build/components/header/mode-switcher/index.js +0 -4
- package/build/components/header/mode-switcher/index.js.map +1 -1
- package/build/components/header/more-menu/index.js +13 -3
- package/build/components/header/more-menu/index.js.map +1 -1
- package/build/components/sidebar/default-sidebar.js +11 -1
- package/build/components/sidebar/default-sidebar.js.map +1 -1
- package/build/components/sidebar/plugin-sidebar/index.js +11 -1
- package/build/components/sidebar/plugin-sidebar/index.js.map +1 -1
- package/build/components/template-details/edit-template-title.js +1 -1
- package/build/components/template-details/edit-template-title.js.map +1 -1
- package/build/components/template-details/index.js +18 -8
- package/build/components/template-details/index.js.map +1 -1
- package/build/components/template-details/template-part-area-selector.js +47 -0
- package/build/components/template-details/template-part-area-selector.js.map +1 -0
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/build-module/components/add-new-template/new-template.js +10 -5
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +87 -52
- package/build-module/components/add-new-template/utils.js.map +1 -1
- package/build-module/components/block-editor/resizable-editor.js +26 -12
- package/build-module/components/block-editor/resizable-editor.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +3 -3
- package/build-module/components/global-styles/border-panel.js.map +1 -1
- package/build-module/components/global-styles/dimensions-panel.js +108 -8
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +5 -5
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/preview.js +2 -2
- package/build-module/components/global-styles/preview.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +29 -22
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +42 -10
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/global-styles/utils.js +39 -5
- package/build-module/components/global-styles/utils.js.map +1 -1
- package/build-module/components/header/document-actions/index.js +1 -0
- package/build-module/components/header/document-actions/index.js.map +1 -1
- package/build-module/components/header/index.js +5 -2
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/header/mode-switcher/index.js +0 -4
- package/build-module/components/header/mode-switcher/index.js.map +1 -1
- package/build-module/components/header/more-menu/index.js +13 -3
- package/build-module/components/header/more-menu/index.js.map +1 -1
- package/build-module/components/sidebar/default-sidebar.js +9 -1
- package/build-module/components/sidebar/default-sidebar.js.map +1 -1
- package/build-module/components/sidebar/plugin-sidebar/index.js +9 -1
- package/build-module/components/sidebar/plugin-sidebar/index.js.map +1 -1
- package/build-module/components/template-details/edit-template-title.js +1 -1
- package/build-module/components/template-details/edit-template-title.js.map +1 -1
- package/build-module/components/template-details/index.js +18 -9
- package/build-module/components/template-details/index.js.map +1 -1
- package/build-module/components/template-details/template-part-area-selector.js +35 -0
- package/build-module/components/template-details/template-part-area-selector.js.map +1 -0
- package/build-module/index.js +1 -1
- package/build-module/index.js.map +1 -1
- package/build-style/style-rtl.css +4 -6
- package/build-style/style.css +4 -6
- package/package.json +29 -29
- package/src/components/add-new-template/new-template.js +15 -4
- package/src/components/add-new-template/utils.js +82 -20
- package/src/components/block-editor/resizable-editor.js +28 -18
- package/src/components/editor/style.scss +1 -0
- package/src/components/global-styles/border-panel.js +3 -3
- package/src/components/global-styles/dimensions-panel.js +155 -30
- package/src/components/global-styles/hooks.js +6 -8
- package/src/components/global-styles/preview.js +2 -2
- package/src/components/global-styles/style.scss +3 -2
- package/src/components/global-styles/test/use-global-styles-output.js +16 -3
- package/src/components/global-styles/test/utils.js +68 -8
- package/src/components/global-styles/typography-panel.js +96 -94
- package/src/components/global-styles/use-global-styles-output.js +41 -14
- package/src/components/global-styles/utils.js +29 -4
- package/src/components/header/document-actions/index.js +3 -0
- package/src/components/header/index.js +4 -1
- package/src/components/header/mode-switcher/index.js +0 -3
- package/src/components/header/more-menu/index.js +7 -2
- package/src/components/sidebar/default-sidebar.js +12 -0
- package/src/components/sidebar/plugin-sidebar/index.js +12 -0
- package/src/components/template-details/edit-template-title.js +7 -3
- package/src/components/template-details/index.js +20 -7
- package/src/components/template-details/style.scss +0 -5
- package/src/components/template-details/template-part-area-selector.js +38 -0
- package/src/index.js +1 -1
package/build/index.js
CHANGED
|
@@ -119,7 +119,7 @@ function reinitializeEditor(target, settings) {
|
|
|
119
119
|
keepCaretInsideBlock: false,
|
|
120
120
|
welcomeGuide: true,
|
|
121
121
|
welcomeGuideStyles: true,
|
|
122
|
-
|
|
122
|
+
showListViewByDefault: false
|
|
123
123
|
}); // Check if the block list view should be open by default.
|
|
124
124
|
|
|
125
125
|
if ((0, _data.select)(_preferences.store).get('core/edit-site', 'showListViewByDefault')) {
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/index.js"],"names":["reinitializeEditor","target","settings","__unstableHomeTemplate","reboot","bind","preferencesStore","setDefaults","editorMode","fixedToolbar","focusMode","keepCaretInsideBlock","welcomeGuide","welcomeGuideStyles","
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/index.js"],"names":["reinitializeEditor","target","settings","__unstableHomeTemplate","reboot","bind","preferencesStore","setDefaults","editorMode","fixedToolbar","focusMode","keepCaretInsideBlock","welcomeGuide","welcomeGuideStyles","showListViewByDefault","get","editSiteStore","setIsListViewOpened","interfaceStore","setDefaultComplementaryArea","updateSettings","editorStore","updateEditorSettings","defaultTemplateTypes","defaultTemplatePartAreas","isLandingOnListPage","window","location","href","setIsNavigationPanelOpened","viewportStore","isViewportMatch","initializeEditor","id","__experimentalFetchLinkSuggestions","search","searchOptions","__experimentalFetchRichUrlData","fetchUrlData","document","getElementById","blocksStore","__experimentalReapplyBlockTypeFilters","process","env","IS_GUTENBERG_PLUGIN","enableFSEBlocks"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AASA;;AANA;;AACA;;AAIA;;AAEA;;AAIA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AA4GA;;AACA;;AACA;;AACA;;AACA;;AA5IA;AACA;AACA;;AAmBA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,kBAAT,CAA6BC,MAA7B,EAAqCC,QAArC,EAAgD;AACtD;AACA,MAAK,CAAEA,QAAQ,CAACC,sBAAhB,EAAyC;AACxC,yBACC,4BAAC,gBAAD;AACC,MAAA,OAAO,EAAG,cACT,iEADS,CADX;AAIC,MAAA,aAAa,EAAC;AAJf,MADD,EAOCF,MAPD;AASA;AACA,GAbqD,CAetD;;;AACA,uCAAwBA,MAAxB;AACA,QAAMG,MAAM,GAAGJ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gBAAT,CAA2BC,EAA3B,EAA+B/B,QAA/B,EAA0C;AAChDA,EAAAA,QAAQ,CAACgC,kCAAT,GAA8C,CAAEC,MAAF,EAAUC,aAAV,KAC7C,kDAAsBD,MAAtB,EAA8BC,aAA9B,EAA6ClC,QAA7C,CADD;;AAEAA,EAAAA,QAAQ,CAACmC,8BAAT,GAA0CC,oCAA1C;AAEA,QAAMrC,MAAM,GAAGsC,QAAQ,CAACC,cAAT,CAAyBP,EAAzB,CAAf;;AAEA,sBAAUQ,aAAV,EAAwBC,qCAAxB;;AACA;;AACA,MAAKC,OAAO,CAACC,GAAR,CAAYC,mBAAjB,EAAuC;AACtC,oEAA8C;AAC7CC,MAAAA,eAAe,EAAE;AAD4B,KAA9C;AAGA;;AAED9C,EAAAA,kBAAkB,CAAEC,MAAF,EAAUC,QAAV,CAAlB;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { store as blocksStore } from '@wordpress/blocks';\nimport {\n\tregisterCoreBlocks,\n\t__experimentalRegisterExperimentalCoreBlocks,\n} from '@wordpress/block-library';\nimport { dispatch, select } from '@wordpress/data';\nimport { render, unmountComponentAtNode } from '@wordpress/element';\nimport {\n\t__experimentalFetchLinkSuggestions as fetchLinkSuggestions,\n\t__experimentalFetchUrlData as fetchUrlData,\n} from '@wordpress/core-data';\nimport { store as editorStore } from '@wordpress/editor';\nimport { store as interfaceStore } from '@wordpress/interface';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport { __ } from '@wordpress/i18n';\nimport { store as viewportStore } from '@wordpress/viewport';\nimport { getQueryArgs } from '@wordpress/url';\n\n/**\n * Internal dependencies\n */\nimport './hooks';\nimport { store as editSiteStore } from './store';\nimport EditSiteApp from './components/app';\nimport getIsListPage from './utils/get-is-list-page';\nimport ErrorBoundaryWarning from './components/error-boundary/warning';\n\n/**\n * Reinitializes the editor after the user chooses to reboot the editor after\n * an unhandled error occurs, replacing previously mounted editor element using\n * an initial state from prior to the crash.\n *\n * @param {Element} target DOM node in which editor is rendered.\n * @param {?Object} settings Editor settings object.\n */\nexport function reinitializeEditor( target, settings ) {\n\t// Display warning if editor wasn't able to resolve homepage template.\n\tif ( ! settings.__unstableHomeTemplate ) {\n\t\trender(\n\t\t\t<ErrorBoundaryWarning\n\t\t\t\tmessage={ __(\n\t\t\t\t\t'The editor is unable to find a block template for the homepage.'\n\t\t\t\t) }\n\t\t\t\tdashboardLink=\"index.php\"\n\t\t\t/>,\n\t\t\ttarget\n\t\t);\n\t\treturn;\n\t}\n\n\t// This will be a no-op if the target doesn't have any React nodes.\n\tunmountComponentAtNode( target );\n\tconst reboot = reinitializeEditor.bind( null, target, settings );\n\n\t// We dispatch actions and update the store synchronously before rendering\n\t// so that we won't trigger unnecessary re-renders with useEffect.\n\t{\n\t\tdispatch( preferencesStore ).setDefaults( 'core/edit-site', {\n\t\t\teditorMode: 'visual',\n\t\t\tfixedToolbar: false,\n\t\t\tfocusMode: false,\n\t\t\tkeepCaretInsideBlock: false,\n\t\t\twelcomeGuide: true,\n\t\t\twelcomeGuideStyles: true,\n\t\t\tshowListViewByDefault: false,\n\t\t} );\n\n\t\t// Check if the block list view should be open by default.\n\t\tif (\n\t\t\tselect( preferencesStore ).get(\n\t\t\t\t'core/edit-site',\n\t\t\t\t'showListViewByDefault'\n\t\t\t)\n\t\t) {\n\t\t\tdispatch( editSiteStore ).setIsListViewOpened( true );\n\t\t}\n\n\t\tdispatch( interfaceStore ).setDefaultComplementaryArea(\n\t\t\t'core/edit-site',\n\t\t\t'edit-site/template'\n\t\t);\n\n\t\tdispatch( editSiteStore ).updateSettings( settings );\n\n\t\t// Keep the defaultTemplateTypes in the core/editor settings too,\n\t\t// so that they can be selected with core/editor selectors in any editor.\n\t\t// This is needed because edit-site doesn't initialize with EditorProvider,\n\t\t// which internally uses updateEditorSettings as well.\n\t\tdispatch( editorStore ).updateEditorSettings( {\n\t\t\tdefaultTemplateTypes: settings.defaultTemplateTypes,\n\t\t\tdefaultTemplatePartAreas: settings.defaultTemplatePartAreas,\n\t\t} );\n\n\t\tconst isLandingOnListPage = getIsListPage(\n\t\t\tgetQueryArgs( window.location.href )\n\t\t);\n\n\t\tif ( isLandingOnListPage ) {\n\t\t\t// Default the navigation panel to be opened when we're in a bigger\n\t\t\t// screen and land in the list screen.\n\t\t\tdispatch( editSiteStore ).setIsNavigationPanelOpened(\n\t\t\t\tselect( viewportStore ).isViewportMatch( 'medium' )\n\t\t\t);\n\t\t}\n\t}\n\n\trender( <EditSiteApp reboot={ reboot } />, target );\n}\n\n/**\n * Initializes the site editor screen.\n *\n * @param {string} id ID of the root element to render the screen in.\n * @param {Object} settings Editor settings.\n */\nexport function initializeEditor( id, settings ) {\n\tsettings.__experimentalFetchLinkSuggestions = ( search, searchOptions ) =>\n\t\tfetchLinkSuggestions( search, searchOptions, settings );\n\tsettings.__experimentalFetchRichUrlData = fetchUrlData;\n\n\tconst target = document.getElementById( id );\n\n\tdispatch( blocksStore ).__experimentalReapplyBlockTypeFilters();\n\tregisterCoreBlocks();\n\tif ( process.env.IS_GUTENBERG_PLUGIN ) {\n\t\t__experimentalRegisterExperimentalCoreBlocks( {\n\t\t\tenableFSEBlocks: true,\n\t\t} );\n\t}\n\n\treinitializeEditor( target, settings );\n}\n\nexport { default as __experimentalMainDashboardButton } from './components/main-dashboard-button';\nexport { default as __experimentalNavigationToggle } from './components/navigation-sidebar/navigation-toggle';\nexport { default as PluginSidebar } from './components/sidebar/plugin-sidebar';\nexport { default as PluginSidebarMoreMenuItem } from './components/header/plugin-sidebar-more-menu-item';\nexport { default as PluginMoreMenuItem } from './components/header/plugin-more-menu-item';\n"]}
|
|
@@ -10,14 +10,14 @@ import { useState } from '@wordpress/element';
|
|
|
10
10
|
import { useDispatch } from '@wordpress/data';
|
|
11
11
|
import { store as coreStore } from '@wordpress/core-data';
|
|
12
12
|
import { archive, blockMeta, category, home, list, media, notFound, page, post, postAuthor, postDate, search, tag, layout as customGenericTemplateIcon } from '@wordpress/icons';
|
|
13
|
-
import { __ } from '@wordpress/i18n';
|
|
13
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
14
14
|
import { store as noticesStore } from '@wordpress/notices';
|
|
15
15
|
/**
|
|
16
16
|
* Internal dependencies
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
import AddCustomTemplateModal from './add-custom-template-modal';
|
|
20
|
-
import { useExistingTemplates, useDefaultTemplateTypes, useTaxonomiesMenuItems, usePostTypeMenuItems, useAuthorMenuItem } from './utils';
|
|
20
|
+
import { useExistingTemplates, useDefaultTemplateTypes, useTaxonomiesMenuItems, usePostTypeMenuItems, useAuthorMenuItem, usePostTypeArchiveMenuItems } from './utils';
|
|
21
21
|
import AddCustomGenericTemplateModal from './add-custom-generic-template-modal';
|
|
22
22
|
import { useHistory } from '../routes';
|
|
23
23
|
import { store as editSiteStore } from '../../store';
|
|
@@ -49,7 +49,8 @@ export default function NewTemplate(_ref) {
|
|
|
49
49
|
saveEntityRecord
|
|
50
50
|
} = useDispatch(coreStore);
|
|
51
51
|
const {
|
|
52
|
-
createErrorNotice
|
|
52
|
+
createErrorNotice,
|
|
53
|
+
createSuccessNotice
|
|
53
54
|
} = useDispatch(noticesStore);
|
|
54
55
|
const {
|
|
55
56
|
setTemplate
|
|
@@ -96,7 +97,11 @@ export default function NewTemplate(_ref) {
|
|
|
96
97
|
history.push({
|
|
97
98
|
postId: newTemplate.id,
|
|
98
99
|
postType: newTemplate.type
|
|
99
|
-
});
|
|
100
|
+
});
|
|
101
|
+
createSuccessNotice(sprintf( // translators: %s: Title of the created template e.g: "Category".
|
|
102
|
+
__('"%s" successfully created.'), title), {
|
|
103
|
+
type: 'snackbar'
|
|
104
|
+
});
|
|
100
105
|
} catch (error) {
|
|
101
106
|
const errorMessage = error.message && error.code !== 'unknown_error' ? error.message : __('An error occurred while creating the template.');
|
|
102
107
|
createErrorNotice(errorMessage, {
|
|
@@ -208,7 +213,7 @@ function useMissingTemplates(setEntityForSuggestions, setShowCustomTemplateModal
|
|
|
208
213
|
enhancedMissingDefaultTemplateTypes === null || enhancedMissingDefaultTemplateTypes === void 0 ? void 0 : enhancedMissingDefaultTemplateTypes.sort((template1, template2) => {
|
|
209
214
|
return DEFAULT_TEMPLATE_SLUGS.indexOf(template1.slug) - DEFAULT_TEMPLATE_SLUGS.indexOf(template2.slug);
|
|
210
215
|
});
|
|
211
|
-
const missingTemplates = [...enhancedMissingDefaultTemplateTypes, ...postTypesMenuItems, ...taxonomiesMenuItems];
|
|
216
|
+
const missingTemplates = [...enhancedMissingDefaultTemplateTypes, ...usePostTypeArchiveMenuItems(), ...postTypesMenuItems, ...taxonomiesMenuItems];
|
|
212
217
|
return missingTemplates;
|
|
213
218
|
}
|
|
214
219
|
//# sourceMappingURL=new-template.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["apiFetch","addQueryArgs","DropdownMenu","MenuGroup","MenuItem","NavigableMenu","useState","useDispatch","store","coreStore","archive","blockMeta","category","home","list","media","notFound","page","post","postAuthor","postDate","search","tag","layout","customGenericTemplateIcon","__","noticesStore","AddCustomTemplateModal","useExistingTemplates","useDefaultTemplateTypes","useTaxonomiesMenuItems","usePostTypeMenuItems","useAuthorMenuItem","AddCustomGenericTemplateModal","useHistory","editSiteStore","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","single","index","author","taxonomy","date","attachment","NewTemplate","postType","showCustomTemplateModal","setShowCustomTemplateModal","showCustomGenericTemplateModal","setShowCustomGenericTemplateModal","entityForSuggestions","setEntityForSuggestions","history","saveEntityRecord","createErrorNotice","setTemplate","createTemplate","template","isWPSuggestion","title","description","slug","templatePrefix","templateContent","content","fallbackTemplate","path","is_custom","template_prefix","newTemplate","toString","status","is_wp_suggestion","throwOnError","id","push","postId","type","error","errorMessage","message","code","missingTemplates","useMissingTemplates","length","labels","add_new","add_new_item","noArrow","variant","map","onClick","icon","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","authorMenuItem","forEach","menuItem","matchIndex","findIndex","sort","template1","template2","indexOf"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SACCC,YADD,EAECC,SAFD,EAGCC,QAHD,EAICC,aAJD,QAKO,uBALP;AAMA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SACCC,OADD,EAECC,SAFD,EAGCC,QAHD,EAICC,IAJD,EAKCC,IALD,EAMCC,KAND,EAOCC,QAPD,EAQCC,IARD,EASCC,IATD,EAUCC,UAVD,EAWCC,QAXD,EAYCC,MAZD,EAaCC,GAbD,EAcCC,MAAM,IAAIC,yBAdX,QAeO,kBAfP;AAgBA,SAASC,EAAT,QAAmB,iBAAnB;AACA,SAASjB,KAAK,IAAIkB,YAAlB,QAAsC,oBAAtC;AAEA;AACA;AACA;;AACA,OAAOC,sBAAP,MAAmC,6BAAnC;AACA,SACCC,oBADD,EAECC,uBAFD,EAGCC,sBAHD,EAICC,oBAJD,EAKCC,iBALD,QAMO,SANP;AAOA,OAAOC,6BAAP,MAA0C,qCAA1C;AACA,SAASC,UAAT,QAA2B,WAA3B;AACA,SAAS1B,KAAK,IAAI2B,aAAlB,QAAuC,aAAvC;AAEA,MAAMC,sBAAsB,GAAG,CAC9B,YAD8B,EAE9B,QAF8B,EAG9B,MAH8B,EAI9B,OAJ8B,EAK9B,SAL8B,EAM9B,QAN8B,EAO9B,UAP8B,EAQ9B,MAR8B,EAS9B,KAT8B,EAU9B,UAV8B,EAW9B,QAX8B,EAY9B,KAZ8B,CAA/B;AAeA,MAAMC,cAAc,GAAG;AACtB,gBAAcxB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AA9B,MACLzE,sBAAsB,CAAEqE,eAAF,CADvB;AAEA,QAAM;AAAEK,IAAAA,yBAAF;AAA6BC,IAAAA;AAA7B,MACL1E,oBAAoB,CAAEoE,eAAF,CADrB;AAGA,QAAMO,cAAc,GAAG1E,iBAAiB,CAAEmE,eAAF,CAAxC;AACA,GACC,GAAGG,0BADJ,EAEC,GAAGE,yBAFJ,EAGCE,cAHD,EAIEC,OAJF,CAIaC,QAAF,IAAgB;AAC1B,QAAK,CAAEA,QAAP,EAAkB;AACjB;AACA;;AACD,UAAMC,UAAU,GAAGR,mCAAmC,CAACS,SAApC,CAChBrD,QAAF,IAAgBA,QAAQ,CAACI,IAAT,KAAkB+C,QAAQ,CAAC/C,IADzB,CAAnB,CAJ0B,CAO1B;AACA;AACA;AACA;AACA;;AACA,QAAKgD,UAAU,GAAG,CAAC,CAAnB,EAAuB;AACtBR,MAAAA,mCAAmC,CAAEQ,UAAF,CAAnC,GAAoDD,QAApD;AACA,KAFD,MAEO;AACNP,MAAAA,mCAAmC,CAAC1B,IAApC,CAA0CiC,QAA1C;AACA;AACD,GArBD,EA1BC,CAgDD;;AACAP,EAAAA,mCAAmC,SAAnC,IAAAA,mCAAmC,WAAnC,YAAAA,mCAAmC,CAAEU,IAArC,CAA2C,CAAEC,SAAF,EAAaC,SAAb,KAA4B;AACtE,WACC7E,sBAAsB,CAAC8E,OAAvB,CAAgCF,SAAS,CAACnD,IAA1C,IACAzB,sBAAsB,CAAC8E,OAAvB,CAAgCD,SAAS,CAACpD,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMqB,gBAAgB,GAAG,CACxB,GAAGmB,mCADqB,EAExB,GAAGI,kBAFqB,EAGxB,GAAGF,mBAHqB,CAAzB;AAKA,SAAOrB,gBAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tNavigableMenu,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tarchive,\n\tblockMeta,\n\tcategory,\n\thome,\n\tlist,\n\tmedia,\n\tnotFound,\n\tpage,\n\tpost,\n\tpostAuthor,\n\tpostDate,\n\tsearch,\n\ttag,\n\tlayout as customGenericTemplateIcon,\n} from '@wordpress/icons';\nimport { __ } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModal from './add-custom-template-modal';\nimport {\n\tuseExistingTemplates,\n\tuseDefaultTemplateTypes,\n\tuseTaxonomiesMenuItems,\n\tusePostTypeMenuItems,\n\tuseAuthorMenuItem,\n} from './utils';\nimport AddCustomGenericTemplateModal from './add-custom-generic-template-modal';\nimport { useHistory } from '../routes';\nimport { store as editSiteStore } from '../../store';\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'single',\n\t'page',\n\t'index',\n\t'archive',\n\t'author',\n\t'category',\n\t'date',\n\t'tag',\n\t'taxonomy',\n\t'search',\n\t'404',\n];\n\nconst TEMPLATE_ICONS = {\n\t'front-page': home,\n\tsingle: post,\n\tpage,\n\tarchive,\n\tsearch,\n\t404: notFound,\n\tindex: list,\n\tcategory,\n\tauthor: postAuthor,\n\ttaxonomy: blockMeta,\n\tdate: postDate,\n\ttag,\n\tattachment: media,\n};\n\nexport default function NewTemplate( { postType } ) {\n\tconst [ showCustomTemplateModal, setShowCustomTemplateModal ] =\n\t\tuseState( false );\n\tconst [\n\t\tshowCustomGenericTemplateModal,\n\t\tsetShowCustomGenericTemplateModal,\n\t] = useState( false );\n\tconst [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );\n\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst { setTemplate } = useDispatch( editSiteStore );\n\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\ttry {\n\t\t\tconst { title, description, slug, templatePrefix } = template;\n\t\t\tlet templateContent = template.content;\n\t\t\t// Try to find fallback content from existing templates.\n\t\t\tif ( ! templateContent ) {\n\t\t\t\tconst fallbackTemplate = await apiFetch( {\n\t\t\t\t\tpath: addQueryArgs( '/wp/v2/templates/lookup', {\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tis_custom: ! isWPSuggestion,\n\t\t\t\t\t\ttemplate_prefix: templatePrefix,\n\t\t\t\t\t} ),\n\t\t\t\t} );\n\t\t\t\ttemplateContent = fallbackTemplate.content;\n\t\t\t}\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tdescription,\n\t\t\t\t\t// Slugs need to be strings, so this is for template `404`\n\t\t\t\t\tslug: slug.toString(),\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t\ttitle,\n\t\t\t\t\tcontent: templateContent,\n\t\t\t\t\t// This adds a post meta field in template that is part of `is_custom` value calculation.\n\t\t\t\t\tis_wp_suggestion: isWPSuggestion,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// Set template before navigating away to avoid initial stale value.\n\t\t\tsetTemplate( newTemplate.id, newTemplate.slug );\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: newTemplate.id,\n\t\t\t\tpostType: newTemplate.type,\n\t\t\t} );\n\n\t\t\t// TODO: Add a success notice?\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\n\tconst missingTemplates = useMissingTemplates(\n\t\tsetEntityForSuggestions,\n\t\tsetShowCustomTemplateModal\n\t);\n\tif ( ! missingTemplates.length ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t<DropdownMenu\n\t\t\t\tclassName=\"edit-site-new-template-dropdown\"\n\t\t\t\ticon={ null }\n\t\t\t\ttext={ postType.labels.add_new }\n\t\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\t\tpopoverProps={ {\n\t\t\t\t\tnoArrow: false,\n\t\t\t\t} }\n\t\t\t\ttoggleProps={ {\n\t\t\t\t\tvariant: 'primary',\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ () => (\n\t\t\t\t\t<NavigableMenu className=\"edit-site-new-template-dropdown__popover\">\n\t\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\tonClick,\n\t\t\t\t\t\t\t\t\ticon,\n\t\t\t\t\t\t\t\t} = template;\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\ticon ||\n\t\t\t\t\t\t\t\t\t\t\tTEMPLATE_ICONS[ slug ] ||\n\t\t\t\t\t\t\t\t\t\t\tpost\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\tinfo={ description }\n\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\tonClick\n\t\t\t\t\t\t\t\t\t\t\t\t? onClick( template )\n\t\t\t\t\t\t\t\t\t\t\t\t: createTemplate( template )\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\t\t{ title }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\ticon={ customGenericTemplateIcon }\n\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\tinfo={ __(\n\t\t\t\t\t\t\t\t\t'Custom templates can be applied to any post or page.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tkey=\"custom-template\"\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tsetShowCustomGenericTemplateModal( true )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Custom template' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t</NavigableMenu>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t\t{ showCustomTemplateModal && (\n\t\t\t\t<AddCustomTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomTemplateModal( false ) }\n\t\t\t\t\tonSelect={ createTemplate }\n\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showCustomGenericTemplateModal && (\n\t\t\t\t<AddCustomGenericTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomGenericTemplateModal( false ) }\n\t\t\t\t\tcreateTemplate={ createTemplate }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates(\n\tsetEntityForSuggestions,\n\tsetShowCustomTemplateModal\n) {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter(\n\t\t( template ) =>\n\t\t\tDEFAULT_TEMPLATE_SLUGS.includes( template.slug ) &&\n\t\t\t! existingTemplateSlugs.includes( template.slug )\n\t);\n\tconst onClickMenuItem = ( _entityForSuggestions ) => {\n\t\tsetShowCustomTemplateModal( true );\n\t\tsetEntityForSuggestions( _entityForSuggestions );\n\t};\n\t// We need to replace existing default template types with\n\t// the create specific template functionality. The original\n\t// info (title, description, etc.) is preserved in the\n\t// used hooks.\n\tconst enhancedMissingDefaultTemplateTypes = [ ...missingDefaultTemplates ];\n\tconst { defaultTaxonomiesMenuItems, taxonomiesMenuItems } =\n\t\tuseTaxonomiesMenuItems( onClickMenuItem );\n\tconst { defaultPostTypesMenuItems, postTypesMenuItems } =\n\t\tusePostTypeMenuItems( onClickMenuItem );\n\n\tconst authorMenuItem = useAuthorMenuItem( onClickMenuItem );\n\t[\n\t\t...defaultTaxonomiesMenuItems,\n\t\t...defaultPostTypesMenuItems,\n\t\tauthorMenuItem,\n\t].forEach( ( menuItem ) => {\n\t\tif ( ! menuItem ) {\n\t\t\treturn;\n\t\t}\n\t\tconst matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(\n\t\t\t( template ) => template.slug === menuItem.slug\n\t\t);\n\t\t// Some default template types might have been filtered above from\n\t\t// `missingDefaultTemplates` because they only check for the general\n\t\t// template. So here we either replace or append the item, augmented\n\t\t// with the check if it has available specific item to create a\n\t\t// template for.\n\t\tif ( matchIndex > -1 ) {\n\t\t\tenhancedMissingDefaultTemplateTypes[ matchIndex ] = menuItem;\n\t\t} else {\n\t\t\tenhancedMissingDefaultTemplateTypes.push( menuItem );\n\t\t}\n\t} );\n\t// Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.\n\tenhancedMissingDefaultTemplateTypes?.sort( ( template1, template2 ) => {\n\t\treturn (\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template1.slug ) -\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template2.slug )\n\t\t);\n\t} );\n\tconst missingTemplates = [\n\t\t...enhancedMissingDefaultTemplateTypes,\n\t\t...postTypesMenuItems,\n\t\t...taxonomiesMenuItems,\n\t];\n\treturn missingTemplates;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["apiFetch","addQueryArgs","DropdownMenu","MenuGroup","MenuItem","NavigableMenu","useState","useDispatch","store","coreStore","archive","blockMeta","category","home","list","media","notFound","page","post","postAuthor","postDate","search","tag","layout","customGenericTemplateIcon","__","sprintf","noticesStore","AddCustomTemplateModal","useExistingTemplates","useDefaultTemplateTypes","useTaxonomiesMenuItems","usePostTypeMenuItems","useAuthorMenuItem","usePostTypeArchiveMenuItems","AddCustomGenericTemplateModal","useHistory","editSiteStore","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","single","index","author","taxonomy","date","attachment","NewTemplate","postType","showCustomTemplateModal","setShowCustomTemplateModal","showCustomGenericTemplateModal","setShowCustomGenericTemplateModal","entityForSuggestions","setEntityForSuggestions","history","saveEntityRecord","createErrorNotice","createSuccessNotice","setTemplate","createTemplate","template","isWPSuggestion","title","description","slug","templatePrefix","templateContent","content","fallbackTemplate","path","is_custom","template_prefix","newTemplate","toString","status","is_wp_suggestion","throwOnError","id","push","postId","type","error","errorMessage","message","code","missingTemplates","useMissingTemplates","length","labels","add_new","add_new_item","noArrow","variant","map","onClick","icon","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","authorMenuItem","forEach","menuItem","matchIndex","findIndex","sort","template1","template2","indexOf"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SAASC,YAAT,QAA6B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AAAA,yBAAF;AAA6BC,IAAAA;AAA7B,MACL5E,oBAAoB,CAAEsE,eAAF,CADrB;AAGA,QAAMO,cAAc,GAAG5E,iBAAiB,CAAEqE,eAAF,CAAxC;AACA,GACC,GAAGG,0BADJ,EAEC,GAAGE,yBAFJ,EAGCE,cAHD,EAIEC,OAJF,CAIaC,QAAF,IAAgB;AAC1B,QAAK,CAAEA,QAAP,EAAkB;AACjB;AACA;;AACD,UAAMC,UAAU,GAAGR,mCAAmC,CAACS,SAApC,CAChBrD,QAAF,IAAgBA,QAAQ,CAACI,IAAT,KAAkB+C,QAAQ,CAAC/C,IADzB,CAAnB,CAJ0B,CAO1B;AACA;AACA;AACA;AACA;;AACA,QAAKgD,UAAU,GAAG,CAAC,CAAnB,EAAuB;AACtBR,MAAAA,mCAAmC,CAAEQ,UAAF,CAAnC,GAAoDD,QAApD;AACA,KAFD,MAEO;AACNP,MAAAA,mCAAmC,CAAC1B,IAApC,CAA0CiC,QAA1C;AACA;AACD,GArBD,EA1BC,CAgDD;;AACAP,EAAAA,mCAAmC,SAAnC,IAAAA,mCAAmC,WAAnC,YAAAA,mCAAmC,CAAEU,IAArC,CAA2C,CAAEC,SAAF,EAAaC,SAAb,KAA4B;AACtE,WACC9E,sBAAsB,CAAC+E,OAAvB,CAAgCF,SAAS,CAACnD,IAA1C,IACA1B,sBAAsB,CAAC+E,OAAvB,CAAgCD,SAAS,CAACpD,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMqB,gBAAgB,GAAG,CACxB,GAAGmB,mCADqB,EAExB,GAAGtE,2BAA2B,EAFN,EAGxB,GAAG0E,kBAHqB,EAIxB,GAAGF,mBAJqB,CAAzB;AAMA,SAAOrB,gBAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tNavigableMenu,\n} from '@wordpress/components';\nimport { useState } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tarchive,\n\tblockMeta,\n\tcategory,\n\thome,\n\tlist,\n\tmedia,\n\tnotFound,\n\tpage,\n\tpost,\n\tpostAuthor,\n\tpostDate,\n\tsearch,\n\ttag,\n\tlayout as customGenericTemplateIcon,\n} from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModal from './add-custom-template-modal';\nimport {\n\tuseExistingTemplates,\n\tuseDefaultTemplateTypes,\n\tuseTaxonomiesMenuItems,\n\tusePostTypeMenuItems,\n\tuseAuthorMenuItem,\n\tusePostTypeArchiveMenuItems,\n} from './utils';\nimport AddCustomGenericTemplateModal from './add-custom-generic-template-modal';\nimport { useHistory } from '../routes';\nimport { store as editSiteStore } from '../../store';\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'single',\n\t'page',\n\t'index',\n\t'archive',\n\t'author',\n\t'category',\n\t'date',\n\t'tag',\n\t'taxonomy',\n\t'search',\n\t'404',\n];\n\nconst TEMPLATE_ICONS = {\n\t'front-page': home,\n\tsingle: post,\n\tpage,\n\tarchive,\n\tsearch,\n\t404: notFound,\n\tindex: list,\n\tcategory,\n\tauthor: postAuthor,\n\ttaxonomy: blockMeta,\n\tdate: postDate,\n\ttag,\n\tattachment: media,\n};\n\nexport default function NewTemplate( { postType } ) {\n\tconst [ showCustomTemplateModal, setShowCustomTemplateModal ] =\n\t\tuseState( false );\n\tconst [\n\t\tshowCustomGenericTemplateModal,\n\t\tsetShowCustomGenericTemplateModal,\n\t] = useState( false );\n\tconst [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );\n\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst { setTemplate } = useDispatch( editSiteStore );\n\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\ttry {\n\t\t\tconst { title, description, slug, templatePrefix } = template;\n\t\t\tlet templateContent = template.content;\n\t\t\t// Try to find fallback content from existing templates.\n\t\t\tif ( ! templateContent ) {\n\t\t\t\tconst fallbackTemplate = await apiFetch( {\n\t\t\t\t\tpath: addQueryArgs( '/wp/v2/templates/lookup', {\n\t\t\t\t\t\tslug,\n\t\t\t\t\t\tis_custom: ! isWPSuggestion,\n\t\t\t\t\t\ttemplate_prefix: templatePrefix,\n\t\t\t\t\t} ),\n\t\t\t\t} );\n\t\t\t\ttemplateContent = fallbackTemplate.content;\n\t\t\t}\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\t'wp_template',\n\t\t\t\t{\n\t\t\t\t\tdescription,\n\t\t\t\t\t// Slugs need to be strings, so this is for template `404`\n\t\t\t\t\tslug: slug.toString(),\n\t\t\t\t\tstatus: 'publish',\n\t\t\t\t\ttitle,\n\t\t\t\t\tcontent: templateContent,\n\t\t\t\t\t// This adds a post meta field in template that is part of `is_custom` value calculation.\n\t\t\t\t\tis_wp_suggestion: isWPSuggestion,\n\t\t\t\t},\n\t\t\t\t{ throwOnError: true }\n\t\t\t);\n\n\t\t\t// Set template before navigating away to avoid initial stale value.\n\t\t\tsetTemplate( newTemplate.id, newTemplate.slug );\n\n\t\t\t// Navigate to the created template editor.\n\t\t\thistory.push( {\n\t\t\t\tpostId: newTemplate.id,\n\t\t\t\tpostType: newTemplate.type,\n\t\t\t} );\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the created template e.g: \"Category\".\n\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\ttitle\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t}\n\t}\n\n\tconst missingTemplates = useMissingTemplates(\n\t\tsetEntityForSuggestions,\n\t\tsetShowCustomTemplateModal\n\t);\n\tif ( ! missingTemplates.length ) {\n\t\treturn null;\n\t}\n\treturn (\n\t\t<>\n\t\t\t<DropdownMenu\n\t\t\t\tclassName=\"edit-site-new-template-dropdown\"\n\t\t\t\ticon={ null }\n\t\t\t\ttext={ postType.labels.add_new }\n\t\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\t\tpopoverProps={ {\n\t\t\t\t\tnoArrow: false,\n\t\t\t\t} }\n\t\t\t\ttoggleProps={ {\n\t\t\t\t\tvariant: 'primary',\n\t\t\t\t} }\n\t\t\t>\n\t\t\t\t{ () => (\n\t\t\t\t\t<NavigableMenu className=\"edit-site-new-template-dropdown__popover\">\n\t\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\tonClick,\n\t\t\t\t\t\t\t\t\ticon,\n\t\t\t\t\t\t\t\t} = template;\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\ticon ||\n\t\t\t\t\t\t\t\t\t\t\tTEMPLATE_ICONS[ slug ] ||\n\t\t\t\t\t\t\t\t\t\t\tpost\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\tinfo={ description }\n\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\tonClick\n\t\t\t\t\t\t\t\t\t\t\t\t? onClick( template )\n\t\t\t\t\t\t\t\t\t\t\t\t: createTemplate( template )\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\t\t{ title }\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\ticon={ customGenericTemplateIcon }\n\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\tinfo={ __(\n\t\t\t\t\t\t\t\t\t'Custom templates can be applied to any post or page.'\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tkey=\"custom-template\"\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tsetShowCustomGenericTemplateModal( true )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'Custom template' ) }\n\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t</NavigableMenu>\n\t\t\t\t) }\n\t\t\t</DropdownMenu>\n\t\t\t{ showCustomTemplateModal && (\n\t\t\t\t<AddCustomTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomTemplateModal( false ) }\n\t\t\t\t\tonSelect={ createTemplate }\n\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ showCustomGenericTemplateModal && (\n\t\t\t\t<AddCustomGenericTemplateModal\n\t\t\t\t\tonClose={ () => setShowCustomGenericTemplateModal( false ) }\n\t\t\t\t\tcreateTemplate={ createTemplate }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates(\n\tsetEntityForSuggestions,\n\tsetShowCustomTemplateModal\n) {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter(\n\t\t( template ) =>\n\t\t\tDEFAULT_TEMPLATE_SLUGS.includes( template.slug ) &&\n\t\t\t! existingTemplateSlugs.includes( template.slug )\n\t);\n\tconst onClickMenuItem = ( _entityForSuggestions ) => {\n\t\tsetShowCustomTemplateModal( true );\n\t\tsetEntityForSuggestions( _entityForSuggestions );\n\t};\n\t// We need to replace existing default template types with\n\t// the create specific template functionality. The original\n\t// info (title, description, etc.) is preserved in the\n\t// used hooks.\n\tconst enhancedMissingDefaultTemplateTypes = [ ...missingDefaultTemplates ];\n\tconst { defaultTaxonomiesMenuItems, taxonomiesMenuItems } =\n\t\tuseTaxonomiesMenuItems( onClickMenuItem );\n\tconst { defaultPostTypesMenuItems, postTypesMenuItems } =\n\t\tusePostTypeMenuItems( onClickMenuItem );\n\n\tconst authorMenuItem = useAuthorMenuItem( onClickMenuItem );\n\t[\n\t\t...defaultTaxonomiesMenuItems,\n\t\t...defaultPostTypesMenuItems,\n\t\tauthorMenuItem,\n\t].forEach( ( menuItem ) => {\n\t\tif ( ! menuItem ) {\n\t\t\treturn;\n\t\t}\n\t\tconst matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(\n\t\t\t( template ) => template.slug === menuItem.slug\n\t\t);\n\t\t// Some default template types might have been filtered above from\n\t\t// `missingDefaultTemplates` because they only check for the general\n\t\t// template. So here we either replace or append the item, augmented\n\t\t// with the check if it has available specific item to create a\n\t\t// template for.\n\t\tif ( matchIndex > -1 ) {\n\t\t\tenhancedMissingDefaultTemplateTypes[ matchIndex ] = menuItem;\n\t\t} else {\n\t\t\tenhancedMissingDefaultTemplateTypes.push( menuItem );\n\t\t}\n\t} );\n\t// Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.\n\tenhancedMissingDefaultTemplateTypes?.sort( ( template1, template2 ) => {\n\t\treturn (\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template1.slug ) -\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template2.slug )\n\t\t);\n\t} );\n\tconst missingTemplates = [\n\t\t...enhancedMissingDefaultTemplateTypes,\n\t\t...usePostTypeArchiveMenuItems(),\n\t\t...postTypesMenuItems,\n\t\t...taxonomiesMenuItems,\n\t];\n\treturn missingTemplates;\n}\n"]}
|
|
@@ -12,7 +12,7 @@ import { store as editorStore } from '@wordpress/editor';
|
|
|
12
12
|
import { decodeEntities } from '@wordpress/html-entities';
|
|
13
13
|
import { useMemo, useCallback } from '@wordpress/element';
|
|
14
14
|
import { __, sprintf } from '@wordpress/i18n';
|
|
15
|
-
import { blockMeta, post } from '@wordpress/icons';
|
|
15
|
+
import { blockMeta, post, archive } from '@wordpress/icons';
|
|
16
16
|
/**
|
|
17
17
|
* @typedef IHasNameAndId
|
|
18
18
|
* @property {string|number} id The entity's id.
|
|
@@ -79,15 +79,66 @@ const usePublicTaxonomies = () => {
|
|
|
79
79
|
}, [taxonomies]);
|
|
80
80
|
};
|
|
81
81
|
|
|
82
|
+
function usePostTypeNeedsUniqueIdentifier(publicPostTypes) {
|
|
83
|
+
const postTypeLabels = useMemo(() => publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator, _ref3) => {
|
|
84
|
+
let {
|
|
85
|
+
labels
|
|
86
|
+
} = _ref3;
|
|
87
|
+
const singularName = labels.singular_name.toLowerCase();
|
|
88
|
+
accumulator[singularName] = (accumulator[singularName] || 0) + 1;
|
|
89
|
+
return accumulator;
|
|
90
|
+
}, {}));
|
|
91
|
+
return useCallback(_ref4 => {
|
|
92
|
+
let {
|
|
93
|
+
labels,
|
|
94
|
+
slug
|
|
95
|
+
} = _ref4;
|
|
96
|
+
const singularName = labels.singular_name.toLowerCase();
|
|
97
|
+
return postTypeLabels[singularName] > 1 && singularName !== slug;
|
|
98
|
+
}, [postTypeLabels]);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function usePostTypeArchiveMenuItems() {
|
|
102
|
+
const publicPostTypes = usePublicPostTypes();
|
|
103
|
+
const postTypesWithArchives = useMemo(() => publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.filter(postType => postType.has_archive), [publicPostTypes]);
|
|
104
|
+
const existingTemplates = useExistingTemplates();
|
|
105
|
+
const needsUniqueIdentifier = usePostTypeNeedsUniqueIdentifier(postTypesWithArchives);
|
|
106
|
+
return useMemo(() => (postTypesWithArchives === null || postTypesWithArchives === void 0 ? void 0 : postTypesWithArchives.filter(postType => !(existingTemplates || []).some(existingTemplate => existingTemplate.slug === 'archive-' + postType.slug)).map(postType => {
|
|
107
|
+
var _postType$icon;
|
|
108
|
+
|
|
109
|
+
let title;
|
|
110
|
+
|
|
111
|
+
if (needsUniqueIdentifier(postType)) {
|
|
112
|
+
title = sprintf( // translators: %1s: Name of the post type e.g: "Post"; %2s: Slug of the post type e.g: "book".
|
|
113
|
+
__('Archive: %1$s (%2$s)'), postType.labels.singular_name, postType.slug);
|
|
114
|
+
} else {
|
|
115
|
+
title = sprintf( // translators: %s: Name of the post type e.g: "Post".
|
|
116
|
+
__('Archive: %s'), postType.labels.singular_name);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
slug: 'archive-' + postType.slug,
|
|
121
|
+
description: sprintf( // translators: %s: Name of the post type e.g: "Post".
|
|
122
|
+
__('Displays an archive with the latests posts of type: %s.'), postType.labels.singular_name),
|
|
123
|
+
title,
|
|
124
|
+
// `icon` is the `menu_icon` property of a post type. We
|
|
125
|
+
// only handle `dashicons` for now, even if the `menu_icon`
|
|
126
|
+
// also supports urls and svg as values.
|
|
127
|
+
icon: (_postType$icon = postType.icon) !== null && _postType$icon !== void 0 && _postType$icon.startsWith('dashicons-') ? postType.icon.slice(10) : archive,
|
|
128
|
+
templatePrefix: 'archive'
|
|
129
|
+
};
|
|
130
|
+
})) || [], [postTypesWithArchives, existingTemplates, needsUniqueIdentifier]);
|
|
131
|
+
}
|
|
82
132
|
export const usePostTypeMenuItems = onClickMenuItem => {
|
|
83
133
|
const publicPostTypes = usePublicPostTypes();
|
|
84
134
|
const existingTemplates = useExistingTemplates();
|
|
85
|
-
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
135
|
+
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
136
|
+
const needsUniqueIdentifier = usePostTypeNeedsUniqueIdentifier(publicPostTypes); // `page`is a special case in template hierarchy.
|
|
86
137
|
|
|
87
|
-
const templatePrefixes = useMemo(() => publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator,
|
|
138
|
+
const templatePrefixes = useMemo(() => publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator, _ref5) => {
|
|
88
139
|
let {
|
|
89
140
|
slug
|
|
90
|
-
} =
|
|
141
|
+
} = _ref5;
|
|
91
142
|
let suffix = slug;
|
|
92
143
|
|
|
93
144
|
if (slug !== 'page') {
|
|
@@ -96,28 +147,12 @@ export const usePostTypeMenuItems = onClickMenuItem => {
|
|
|
96
147
|
|
|
97
148
|
accumulator[slug] = suffix;
|
|
98
149
|
return accumulator;
|
|
99
|
-
}, {}), [publicPostTypes]);
|
|
100
|
-
// occurs, we need to add slug.
|
|
101
|
-
|
|
102
|
-
const postTypeLabels = publicPostTypes === null || publicPostTypes === void 0 ? void 0 : publicPostTypes.reduce((accumulator, _ref4) => {
|
|
103
|
-
let {
|
|
104
|
-
labels
|
|
105
|
-
} = _ref4;
|
|
106
|
-
const singularName = labels.singular_name.toLowerCase();
|
|
107
|
-
accumulator[singularName] = (accumulator[singularName] || 0) + 1;
|
|
108
|
-
return accumulator;
|
|
109
|
-
}, {});
|
|
110
|
-
|
|
111
|
-
const needsUniqueIdentifier = (labels, slug) => {
|
|
112
|
-
const singularName = labels.singular_name.toLowerCase();
|
|
113
|
-
return postTypeLabels[singularName] > 1 && singularName !== slug;
|
|
114
|
-
};
|
|
115
|
-
|
|
150
|
+
}, {}), [publicPostTypes]);
|
|
116
151
|
const postTypesInfo = useEntitiesInfo('postType', templatePrefixes);
|
|
117
|
-
const existingTemplateSlugs = (existingTemplates || []).map(
|
|
152
|
+
const existingTemplateSlugs = (existingTemplates || []).map(_ref6 => {
|
|
118
153
|
let {
|
|
119
154
|
slug
|
|
120
|
-
} =
|
|
155
|
+
} = _ref6;
|
|
121
156
|
return slug;
|
|
122
157
|
});
|
|
123
158
|
const menuItems = (publicPostTypes || []).reduce((accumulator, postType) => {
|
|
@@ -132,15 +167,15 @@ export const usePostTypeMenuItems = onClickMenuItem => {
|
|
|
132
167
|
// augment it with the specific template functionality.
|
|
133
168
|
|
|
134
169
|
const generalTemplateSlug = templatePrefixes[slug];
|
|
135
|
-
const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(
|
|
170
|
+
const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref7 => {
|
|
136
171
|
let {
|
|
137
172
|
slug: _slug
|
|
138
|
-
} =
|
|
173
|
+
} = _ref7;
|
|
139
174
|
return _slug === generalTemplateSlug;
|
|
140
175
|
});
|
|
141
176
|
const hasGeneralTemplate = existingTemplateSlugs === null || existingTemplateSlugs === void 0 ? void 0 : existingTemplateSlugs.includes(generalTemplateSlug);
|
|
142
177
|
|
|
143
|
-
const _needsUniqueIdentifier = needsUniqueIdentifier(
|
|
178
|
+
const _needsUniqueIdentifier = needsUniqueIdentifier(postType);
|
|
144
179
|
|
|
145
180
|
let menuItemTitle = sprintf( // translators: %s: Name of the post type e.g: "Post".
|
|
146
181
|
__('Single item: %s'), labels.singular_name);
|
|
@@ -172,10 +207,10 @@ export const usePostTypeMenuItems = onClickMenuItem => {
|
|
|
172
207
|
slug,
|
|
173
208
|
config: {
|
|
174
209
|
recordNamePath: 'title.rendered',
|
|
175
|
-
queryArgs:
|
|
210
|
+
queryArgs: _ref8 => {
|
|
176
211
|
let {
|
|
177
212
|
search
|
|
178
|
-
} =
|
|
213
|
+
} = _ref8;
|
|
179
214
|
return {
|
|
180
215
|
_fields: 'id,title,slug,link',
|
|
181
216
|
orderBy: search ? 'relevance' : 'modified',
|
|
@@ -241,10 +276,10 @@ export const useTaxonomiesMenuItems = onClickMenuItem => {
|
|
|
241
276
|
const existingTemplates = useExistingTemplates();
|
|
242
277
|
const defaultTemplateTypes = useDefaultTemplateTypes(); // `category` and `post_tag` are special cases in template hierarchy.
|
|
243
278
|
|
|
244
|
-
const templatePrefixes = useMemo(() => publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator,
|
|
279
|
+
const templatePrefixes = useMemo(() => publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator, _ref9) => {
|
|
245
280
|
let {
|
|
246
281
|
slug
|
|
247
|
-
} =
|
|
282
|
+
} = _ref9;
|
|
248
283
|
let suffix = slug;
|
|
249
284
|
|
|
250
285
|
if (!['category', 'post_tag'].includes(slug)) {
|
|
@@ -260,10 +295,10 @@ export const useTaxonomiesMenuItems = onClickMenuItem => {
|
|
|
260
295
|
}, {}), [publicTaxonomies]); // We need to keep track of naming conflicts. If a conflict
|
|
261
296
|
// occurs, we need to add slug.
|
|
262
297
|
|
|
263
|
-
const taxonomyLabels = publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator,
|
|
298
|
+
const taxonomyLabels = publicTaxonomies === null || publicTaxonomies === void 0 ? void 0 : publicTaxonomies.reduce((accumulator, _ref10) => {
|
|
264
299
|
let {
|
|
265
300
|
labels
|
|
266
|
-
} =
|
|
301
|
+
} = _ref10;
|
|
267
302
|
const singularName = labels.singular_name.toLowerCase();
|
|
268
303
|
accumulator[singularName] = (accumulator[singularName] || 0) + 1;
|
|
269
304
|
return accumulator;
|
|
@@ -279,10 +314,10 @@ export const useTaxonomiesMenuItems = onClickMenuItem => {
|
|
|
279
314
|
};
|
|
280
315
|
|
|
281
316
|
const taxonomiesInfo = useEntitiesInfo('taxonomy', templatePrefixes);
|
|
282
|
-
const existingTemplateSlugs = (existingTemplates || []).map(
|
|
317
|
+
const existingTemplateSlugs = (existingTemplates || []).map(_ref11 => {
|
|
283
318
|
let {
|
|
284
319
|
slug
|
|
285
|
-
} =
|
|
320
|
+
} = _ref11;
|
|
286
321
|
return slug;
|
|
287
322
|
});
|
|
288
323
|
const menuItems = (publicTaxonomies || []).reduce((accumulator, taxonomy) => {
|
|
@@ -296,10 +331,10 @@ export const useTaxonomiesMenuItems = onClickMenuItem => {
|
|
|
296
331
|
// augment it with the specific template functionality.
|
|
297
332
|
|
|
298
333
|
const generalTemplateSlug = templatePrefixes[slug];
|
|
299
|
-
const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(
|
|
334
|
+
const defaultTemplateType = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref12 => {
|
|
300
335
|
let {
|
|
301
336
|
slug: _slug
|
|
302
|
-
} =
|
|
337
|
+
} = _ref12;
|
|
303
338
|
return _slug === generalTemplateSlug;
|
|
304
339
|
});
|
|
305
340
|
const hasGeneralTemplate = existingTemplateSlugs === null || existingTemplateSlugs === void 0 ? void 0 : existingTemplateSlugs.includes(generalTemplateSlug);
|
|
@@ -331,10 +366,10 @@ export const useTaxonomiesMenuItems = onClickMenuItem => {
|
|
|
331
366
|
type: 'taxonomy',
|
|
332
367
|
slug,
|
|
333
368
|
config: {
|
|
334
|
-
queryArgs:
|
|
369
|
+
queryArgs: _ref13 => {
|
|
335
370
|
let {
|
|
336
371
|
search
|
|
337
|
-
} =
|
|
372
|
+
} = _ref13;
|
|
338
373
|
return {
|
|
339
374
|
_fields: 'id,name,slug,link',
|
|
340
375
|
orderBy: search ? 'name' : 'count',
|
|
@@ -402,10 +437,10 @@ function useAuthorNeedsUniqueIndentifier() {
|
|
|
402
437
|
per_page: -1
|
|
403
438
|
}), []);
|
|
404
439
|
const authorsCountByName = useMemo(() => {
|
|
405
|
-
return (authors || []).reduce((authorsCount,
|
|
440
|
+
return (authors || []).reduce((authorsCount, _ref14) => {
|
|
406
441
|
let {
|
|
407
442
|
name
|
|
408
|
-
} =
|
|
443
|
+
} = _ref14;
|
|
409
444
|
authorsCount[name] = (authorsCount[name] || 0) + 1;
|
|
410
445
|
return authorsCount;
|
|
411
446
|
}, {});
|
|
@@ -430,10 +465,10 @@ export function useAuthorMenuItem(onClickMenuItem) {
|
|
|
430
465
|
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
431
466
|
const authorInfo = useEntitiesInfo('root', USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX, USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS);
|
|
432
467
|
const authorNeedsUniqueId = useAuthorNeedsUniqueIndentifier();
|
|
433
|
-
let authorMenuItem = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(
|
|
468
|
+
let authorMenuItem = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref15 => {
|
|
434
469
|
let {
|
|
435
470
|
slug
|
|
436
|
-
} =
|
|
471
|
+
} = _ref15;
|
|
437
472
|
return slug === 'author';
|
|
438
473
|
});
|
|
439
474
|
|
|
@@ -445,10 +480,10 @@ export function useAuthorMenuItem(onClickMenuItem) {
|
|
|
445
480
|
};
|
|
446
481
|
}
|
|
447
482
|
|
|
448
|
-
const hasGeneralTemplate = !!(existingTemplates !== null && existingTemplates !== void 0 && existingTemplates.find(
|
|
483
|
+
const hasGeneralTemplate = !!(existingTemplates !== null && existingTemplates !== void 0 && existingTemplates.find(_ref16 => {
|
|
449
484
|
let {
|
|
450
485
|
slug
|
|
451
|
-
} =
|
|
486
|
+
} = _ref16;
|
|
452
487
|
return slug === 'author';
|
|
453
488
|
}));
|
|
454
489
|
|
|
@@ -462,10 +497,10 @@ export function useAuthorMenuItem(onClickMenuItem) {
|
|
|
462
497
|
type: 'root',
|
|
463
498
|
slug: 'user',
|
|
464
499
|
config: {
|
|
465
|
-
queryArgs:
|
|
500
|
+
queryArgs: _ref17 => {
|
|
466
501
|
let {
|
|
467
502
|
search
|
|
468
|
-
} =
|
|
503
|
+
} = _ref17;
|
|
469
504
|
return {
|
|
470
505
|
_fields: 'id,name,slug,link',
|
|
471
506
|
orderBy: search ? 'name' : 'registered_date',
|
|
@@ -522,8 +557,8 @@ export function useAuthorMenuItem(onClickMenuItem) {
|
|
|
522
557
|
const useExistingTemplateSlugs = templatePrefixes => {
|
|
523
558
|
const existingTemplates = useExistingTemplates();
|
|
524
559
|
const existingSlugs = useMemo(() => {
|
|
525
|
-
return Object.entries(templatePrefixes || {}).reduce((accumulator,
|
|
526
|
-
let [slug, prefix] =
|
|
560
|
+
return Object.entries(templatePrefixes || {}).reduce((accumulator, _ref18) => {
|
|
561
|
+
let [slug, prefix] = _ref18;
|
|
527
562
|
const slugsWithTemplates = (existingTemplates || []).reduce((_accumulator, existingTemplate) => {
|
|
528
563
|
const _prefix = `${prefix}-`;
|
|
529
564
|
|
|
@@ -558,8 +593,8 @@ const useTemplatesToExclude = function (entityName, templatePrefixes) {
|
|
|
558
593
|
let additionalQueryParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
559
594
|
const slugsToExcludePerEntity = useExistingTemplateSlugs(templatePrefixes);
|
|
560
595
|
const recordsToExcludePerEntity = useSelect(select => {
|
|
561
|
-
return Object.entries(slugsToExcludePerEntity || {}).reduce((accumulator,
|
|
562
|
-
let [slug, slugsWithTemplates] =
|
|
596
|
+
return Object.entries(slugsToExcludePerEntity || {}).reduce((accumulator, _ref19) => {
|
|
597
|
+
let [slug, slugsWithTemplates] = _ref19;
|
|
563
598
|
const entitiesWithTemplates = select(coreStore).getEntityRecords(entityName, slug, {
|
|
564
599
|
_fields: 'id',
|
|
565
600
|
context: 'view',
|
|
@@ -600,10 +635,10 @@ const useEntitiesInfo = function (entityName, templatePrefixes) {
|
|
|
600
635
|
return Object.keys(templatePrefixes || {}).reduce((accumulator, slug) => {
|
|
601
636
|
var _recordsToExcludePerE, _select$getEntityReco;
|
|
602
637
|
|
|
603
|
-
const existingEntitiesIds = (recordsToExcludePerEntity === null || recordsToExcludePerEntity === void 0 ? void 0 : (_recordsToExcludePerE = recordsToExcludePerEntity[slug]) === null || _recordsToExcludePerE === void 0 ? void 0 : _recordsToExcludePerE.map(
|
|
638
|
+
const existingEntitiesIds = (recordsToExcludePerEntity === null || recordsToExcludePerEntity === void 0 ? void 0 : (_recordsToExcludePerE = recordsToExcludePerEntity[slug]) === null || _recordsToExcludePerE === void 0 ? void 0 : _recordsToExcludePerE.map(_ref20 => {
|
|
604
639
|
let {
|
|
605
640
|
id
|
|
606
|
-
} =
|
|
641
|
+
} = _ref20;
|
|
607
642
|
return id;
|
|
608
643
|
})) || [];
|
|
609
644
|
accumulator[slug] = {
|