@wordpress/edit-site 6.30.1-next.836ecdcae.0 → 6.31.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/add-custom-template-modal-content.js +1 -1
- package/build/components/add-new-template/add-custom-template-modal-content.js.map +1 -1
- package/build/components/add-new-template/index.js +1 -5
- package/build/components/add-new-template/index.js.map +1 -1
- package/build/components/add-new-template/utils.js +8 -84
- package/build/components/add-new-template/utils.js.map +1 -1
- package/build/components/dataviews-actions/index.js +51 -1
- package/build/components/dataviews-actions/index.js.map +1 -1
- package/build/components/editor/index.js +1 -1
- package/build/components/editor/index.js.map +1 -1
- package/build/components/editor/use-resolve-edited-entity.js +42 -14
- package/build/components/editor/use-resolve-edited-entity.js.map +1 -1
- package/build/components/global-styles/screen-root.js +1 -7
- package/build/components/global-styles/screen-root.js.map +1 -1
- package/build/components/page-templates/fields.js +65 -5
- package/build/components/page-templates/fields.js.map +1 -1
- package/build/components/page-templates/hooks.js +1 -1
- package/build/components/page-templates/hooks.js.map +1 -1
- package/build/components/page-templates/index.js +103 -29
- package/build/components/page-templates/index.js.map +1 -1
- package/build/components/post-list/index.js +1 -4
- package/build/components/post-list/index.js.map +1 -1
- package/build/components/sidebar-navigation-screen-templates-browse/content.js +11 -5
- package/build/components/sidebar-navigation-screen-templates-browse/content.js.map +1 -1
- package/build/components/site-editor-routes/index.js +1 -1
- package/build/components/site-editor-routes/index.js.map +1 -1
- package/build/components/site-editor-routes/template-item.js +29 -23
- package/build/components/site-editor-routes/template-item.js.map +1 -1
- package/build/hooks/commands/use-common-commands.js +3 -118
- package/build/hooks/commands/use-common-commands.js.map +1 -1
- package/build-module/components/add-new-template/add-custom-template-modal-content.js +1 -1
- package/build-module/components/add-new-template/add-custom-template-modal-content.js.map +1 -1
- package/build-module/components/add-new-template/index.js +2 -6
- package/build-module/components/add-new-template/index.js.map +1 -1
- package/build-module/components/add-new-template/utils.js +8 -84
- package/build-module/components/add-new-template/utils.js.map +1 -1
- package/build-module/components/dataviews-actions/index.js +49 -0
- package/build-module/components/dataviews-actions/index.js.map +1 -1
- package/build-module/components/editor/index.js +1 -1
- package/build-module/components/editor/index.js.map +1 -1
- package/build-module/components/editor/use-resolve-edited-entity.js +42 -14
- package/build-module/components/editor/use-resolve-edited-entity.js.map +1 -1
- package/build-module/components/global-styles/screen-root.js +1 -7
- package/build-module/components/global-styles/screen-root.js.map +1 -1
- package/build-module/components/page-templates/fields.js +65 -5
- package/build-module/components/page-templates/fields.js.map +1 -1
- package/build-module/components/page-templates/hooks.js +1 -1
- package/build-module/components/page-templates/hooks.js.map +1 -1
- package/build-module/components/page-templates/index.js +105 -31
- package/build-module/components/page-templates/index.js.map +1 -1
- package/build-module/components/post-list/index.js +1 -4
- package/build-module/components/post-list/index.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js +11 -5
- package/build-module/components/sidebar-navigation-screen-templates-browse/content.js.map +1 -1
- package/build-module/components/site-editor-routes/index.js +2 -2
- package/build-module/components/site-editor-routes/index.js.map +1 -1
- package/build-module/components/site-editor-routes/template-item.js +28 -22
- package/build-module/components/site-editor-routes/template-item.js.map +1 -1
- package/build-module/hooks/commands/use-common-commands.js +5 -120
- package/build-module/hooks/commands/use-common-commands.js.map +1 -1
- package/build-style/posts-rtl.css +17 -10
- package/build-style/posts.css +17 -10
- package/build-style/style-rtl.css +17 -10
- package/build-style/style.css +17 -10
- package/package.json +41 -41
- package/src/components/add-new-template/add-custom-template-modal-content.js +1 -3
- package/src/components/add-new-template/index.js +1 -8
- package/src/components/add-new-template/utils.js +9 -118
- package/src/components/dataviews-actions/index.js +51 -0
- package/src/components/editor/index.js +1 -0
- package/src/components/editor/use-resolve-edited-entity.js +54 -7
- package/src/components/global-styles/screen-root.js +1 -7
- package/src/components/page-templates/fields.js +70 -4
- package/src/components/page-templates/hooks.js +1 -1
- package/src/components/page-templates/index.js +160 -57
- package/src/components/post-list/index.js +1 -2
- package/src/components/sidebar-navigation-screen-templates-browse/content.js +17 -7
- package/src/components/site-editor-routes/index.js +2 -1
- package/src/components/site-editor-routes/template-item.js +34 -26
- package/src/hooks/commands/use-common-commands.js +6 -135
package/CHANGELOG.md
CHANGED
|
@@ -132,7 +132,7 @@ function AddCustomTemplateModalContent({
|
|
|
132
132
|
onBack,
|
|
133
133
|
containerRef
|
|
134
134
|
}) {
|
|
135
|
-
const [showSearchEntities, setShowSearchEntities] = (0, _element.useState)(
|
|
135
|
+
const [showSearchEntities, setShowSearchEntities] = (0, _element.useState)();
|
|
136
136
|
|
|
137
137
|
// Focus on the first focusable element when the modal opens.
|
|
138
138
|
// We handle focus management in the parent modal, just need to focus on the first focusable element.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_element","require","_i18n","_components","_coreData","_htmlEntities","_compose","_dom","_utils","_jsxRuntime","EMPTY_ARRAY","SuggestionListItem","suggestion","search","onSelect","entityForSuggestions","baseCssClass","jsxs","Composite","Item","render","jsx","Button","__next40pxDefaultSize","role","className","onClick","config","getSpecificTemplate","children","__experimentalText","size","lineHeight","weight","TextHighlight","text","decodeEntities","name","highlight","link","useSearchSuggestions","query","useMemo","order","context","per_page","queryArgs","records","searchResults","hasResolved","searchHasResolved","useEntityRecords","type","slug","suggestions","setSuggestions","useState","useEffect","newSuggestions","length","recordNamePath","mapToIHasNameAndId","SuggestionList","setSearch","debouncedSearch","useDebouncedInput","labels","showSearchControl","setShowSearchControl","Fragment","SearchControl","__nextHasNoMarginBottom","onChange","value","label","search_items","placeholder","orientation","__","map","as","not_found","AddCustomTemplateModalContent","onBack","containerRef","showSearchEntities","setShowSearchEntities","hasGeneralTemplate","current","firstFocusable","focus","focusable","find","__experimentalVStack","spacing","alignment","Flex","gap","align","FlexItem","isBlock","title","description","templatePrefix","template","all_items","singular_name","justify","variant","_default","exports","default"],"sources":["@wordpress/edit-site/src/components/add-new-template/add-custom-template-modal-content.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tButton,\n\tFlex,\n\tFlexItem,\n\tSearchControl,\n\tTextHighlight,\n\tComposite,\n\t__experimentalText as Text,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useDebouncedInput } from '@wordpress/compose';\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { mapToIHasNameAndId } from './utils';\n\nconst EMPTY_ARRAY = [];\n\nfunction SuggestionListItem( {\n\tsuggestion,\n\tsearch,\n\tonSelect,\n\tentityForSuggestions,\n} ) {\n\tconst baseCssClass =\n\t\t'edit-site-custom-template-modal__suggestions_list__list-item';\n\treturn (\n\t\t<Composite.Item\n\t\t\trender={\n\t\t\t\t<Button\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\trole=\"option\"\n\t\t\t\t\tclassName={ baseCssClass }\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\tonSelect(\n\t\t\t\t\t\t\tentityForSuggestions.config.getSpecificTemplate(\n\t\t\t\t\t\t\t\tsuggestion\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\t>\n\t\t\t<Text\n\t\t\t\tsize=\"body\"\n\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\tweight={ 500 }\n\t\t\t\tclassName={ `${ baseCssClass }__title` }\n\t\t\t>\n\t\t\t\t<TextHighlight\n\t\t\t\t\ttext={ decodeEntities( suggestion.name ) }\n\t\t\t\t\thighlight={ search }\n\t\t\t\t/>\n\t\t\t</Text>\n\t\t\t{ suggestion.link && (\n\t\t\t\t<Text\n\t\t\t\t\tsize=\"body\"\n\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\tclassName={ `${ baseCssClass }__info` }\n\t\t\t\t>\n\t\t\t\t\t{ suggestion.link }\n\t\t\t\t</Text>\n\t\t\t) }\n\t\t</Composite.Item>\n\t);\n}\n\nfunction useSearchSuggestions( entityForSuggestions, search ) {\n\tconst { config } = entityForSuggestions;\n\tconst query = useMemo(\n\t\t() => ( {\n\t\t\torder: 'asc',\n\t\t\tcontext: 'view',\n\t\t\tsearch,\n\t\t\tper_page: search ? 20 : 10,\n\t\t\t...config.queryArgs( search ),\n\t\t} ),\n\t\t[ search, config ]\n\t);\n\tconst { records: searchResults, hasResolved: searchHasResolved } =\n\t\tuseEntityRecords(\n\t\t\tentityForSuggestions.type,\n\t\t\tentityForSuggestions.slug,\n\t\t\tquery\n\t\t);\n\tconst [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );\n\tuseEffect( () => {\n\t\tif ( ! searchHasResolved ) {\n\t\t\treturn;\n\t\t}\n\t\tlet newSuggestions = EMPTY_ARRAY;\n\t\tif ( searchResults?.length ) {\n\t\t\tnewSuggestions = searchResults;\n\t\t\tif ( config.recordNamePath ) {\n\t\t\t\tnewSuggestions = mapToIHasNameAndId(\n\t\t\t\t\tnewSuggestions,\n\t\t\t\t\tconfig.recordNamePath\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\t// Update suggestions only when the query has resolved, so as to keep\n\t\t// the previous results in the UI.\n\t\tsetSuggestions( newSuggestions );\n\t}, [ searchResults, searchHasResolved ] );\n\treturn suggestions;\n}\n\nfunction SuggestionList( { entityForSuggestions, onSelect } ) {\n\tconst [ search, setSearch, debouncedSearch ] = useDebouncedInput();\n\tconst suggestions = useSearchSuggestions(\n\t\tentityForSuggestions,\n\t\tdebouncedSearch\n\t);\n\tconst { labels } = entityForSuggestions;\n\tconst [ showSearchControl, setShowSearchControl ] = useState( false );\n\tif ( ! showSearchControl && suggestions?.length > 9 ) {\n\t\tsetShowSearchControl( true );\n\t}\n\treturn (\n\t\t<>\n\t\t\t{ showSearchControl && (\n\t\t\t\t<SearchControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tonChange={ setSearch }\n\t\t\t\t\tvalue={ search }\n\t\t\t\t\tlabel={ labels.search_items }\n\t\t\t\t\tplaceholder={ labels.search_items }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ !! suggestions?.length && (\n\t\t\t\t<Composite\n\t\t\t\t\torientation=\"vertical\"\n\t\t\t\t\trole=\"listbox\"\n\t\t\t\t\tclassName=\"edit-site-custom-template-modal__suggestions_list\"\n\t\t\t\t\taria-label={ __( 'Suggestions list' ) }\n\t\t\t\t>\n\t\t\t\t\t{ suggestions.map( ( suggestion ) => (\n\t\t\t\t\t\t<SuggestionListItem\n\t\t\t\t\t\t\tkey={ suggestion.slug }\n\t\t\t\t\t\t\tsuggestion={ suggestion }\n\t\t\t\t\t\t\tsearch={ debouncedSearch }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t</Composite>\n\t\t\t) }\n\t\t\t{ debouncedSearch && ! suggestions?.length && (\n\t\t\t\t<Text\n\t\t\t\t\tas=\"p\"\n\t\t\t\t\tclassName=\"edit-site-custom-template-modal__no-results\"\n\t\t\t\t>\n\t\t\t\t\t{ labels.not_found }\n\t\t\t\t</Text>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction AddCustomTemplateModalContent( {\n\tonSelect,\n\tentityForSuggestions,\n\tonBack,\n\tcontainerRef,\n} ) {\n\tconst [ showSearchEntities, setShowSearchEntities ] = useState(\n\t\tentityForSuggestions.hasGeneralTemplate\n\t);\n\n\t// Focus on the first focusable element when the modal opens.\n\t// We handle focus management in the parent modal, just need to focus on the first focusable element.\n\tuseEffect( () => {\n\t\tif ( containerRef.current ) {\n\t\t\tconst [ firstFocusable ] = focus.focusable.find(\n\t\t\t\tcontainerRef.current\n\t\t\t);\n\t\t\tfirstFocusable?.focus();\n\t\t}\n\t}, [ showSearchEntities ] );\n\n\treturn (\n\t\t<VStack\n\t\t\tspacing={ 4 }\n\t\t\tclassName=\"edit-site-custom-template-modal__contents-wrapper\"\n\t\t\talignment=\"left\"\n\t\t>\n\t\t\t{ ! showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<Text as=\"p\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Select whether to create a single template for all items or a specific one.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Text>\n\t\t\t\t\t<Flex\n\t\t\t\t\t\tclassName=\"edit-site-custom-template-modal__contents\"\n\t\t\t\t\t\tgap=\"4\"\n\t\t\t\t\t\talign=\"initial\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\tslug,\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\ttemplatePrefix,\n\t\t\t\t\t\t\t\t} = entityForSuggestions.template;\n\t\t\t\t\t\t\t\tonSelect( {\n\t\t\t\t\t\t\t\t\tslug,\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\ttemplatePrefix,\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\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tweight={ 500 }\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.all_items }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For all items' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowSearchEntities( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tweight={ 500 }\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.singular_name }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For a specific item' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t</Flex>\n\t\t\t\t\t<Flex justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ onBack }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Back' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</Flex>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<Text as=\"p\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'This template will be used only for the specific item chosen.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Text>\n\t\t\t\t\t<SuggestionList\n\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t/>\n\t\t\t\t\t<Flex justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t// If general template exists, go directly back to main screen\n\t\t\t\t\t\t\t\t// instead of showing the choice screen\n\t\t\t\t\t\t\t\tif ( entityForSuggestions.hasGeneralTemplate ) {\n\t\t\t\t\t\t\t\t\tonBack();\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tsetShowSearchEntities( false );\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\t\t{ __( 'Back' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</Flex>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</VStack>\n\t);\n}\n\nexport default AddCustomTemplateModalContent;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAUA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,IAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AAA6C,IAAAQ,WAAA,GAAAR,OAAA;AAvB7C;AACA;AACA;;AAkBA;AACA;AACA;;AAGA,MAAMS,WAAW,G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,OAAA,CAAAC,OAAA,GAEc7B,6BAA6B","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_element","require","_i18n","_components","_coreData","_htmlEntities","_compose","_dom","_utils","_jsxRuntime","EMPTY_ARRAY","SuggestionListItem","suggestion","search","onSelect","entityForSuggestions","baseCssClass","jsxs","Composite","Item","render","jsx","Button","__next40pxDefaultSize","role","className","onClick","config","getSpecificTemplate","children","__experimentalText","size","lineHeight","weight","TextHighlight","text","decodeEntities","name","highlight","link","useSearchSuggestions","query","useMemo","order","context","per_page","queryArgs","records","searchResults","hasResolved","searchHasResolved","useEntityRecords","type","slug","suggestions","setSuggestions","useState","useEffect","newSuggestions","length","recordNamePath","mapToIHasNameAndId","SuggestionList","setSearch","debouncedSearch","useDebouncedInput","labels","showSearchControl","setShowSearchControl","Fragment","SearchControl","__nextHasNoMarginBottom","onChange","value","label","search_items","placeholder","orientation","__","map","as","not_found","AddCustomTemplateModalContent","onBack","containerRef","showSearchEntities","setShowSearchEntities","current","firstFocusable","focus","focusable","find","__experimentalVStack","spacing","alignment","Flex","gap","align","FlexItem","isBlock","title","description","templatePrefix","template","all_items","singular_name","justify","variant","hasGeneralTemplate","_default","exports","default"],"sources":["@wordpress/edit-site/src/components/add-new-template/add-custom-template-modal-content.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport {\n\tButton,\n\tFlex,\n\tFlexItem,\n\tSearchControl,\n\tTextHighlight,\n\tComposite,\n\t__experimentalText as Text,\n\t__experimentalVStack as VStack,\n} from '@wordpress/components';\nimport { useEntityRecords } from '@wordpress/core-data';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useDebouncedInput } from '@wordpress/compose';\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { mapToIHasNameAndId } from './utils';\n\nconst EMPTY_ARRAY = [];\n\nfunction SuggestionListItem( {\n\tsuggestion,\n\tsearch,\n\tonSelect,\n\tentityForSuggestions,\n} ) {\n\tconst baseCssClass =\n\t\t'edit-site-custom-template-modal__suggestions_list__list-item';\n\treturn (\n\t\t<Composite.Item\n\t\t\trender={\n\t\t\t\t<Button\n\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\trole=\"option\"\n\t\t\t\t\tclassName={ baseCssClass }\n\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\tonSelect(\n\t\t\t\t\t\t\tentityForSuggestions.config.getSpecificTemplate(\n\t\t\t\t\t\t\t\tsuggestion\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\t>\n\t\t\t<Text\n\t\t\t\tsize=\"body\"\n\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\tweight={ 500 }\n\t\t\t\tclassName={ `${ baseCssClass }__title` }\n\t\t\t>\n\t\t\t\t<TextHighlight\n\t\t\t\t\ttext={ decodeEntities( suggestion.name ) }\n\t\t\t\t\thighlight={ search }\n\t\t\t\t/>\n\t\t\t</Text>\n\t\t\t{ suggestion.link && (\n\t\t\t\t<Text\n\t\t\t\t\tsize=\"body\"\n\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\tclassName={ `${ baseCssClass }__info` }\n\t\t\t\t>\n\t\t\t\t\t{ suggestion.link }\n\t\t\t\t</Text>\n\t\t\t) }\n\t\t</Composite.Item>\n\t);\n}\n\nfunction useSearchSuggestions( entityForSuggestions, search ) {\n\tconst { config } = entityForSuggestions;\n\tconst query = useMemo(\n\t\t() => ( {\n\t\t\torder: 'asc',\n\t\t\tcontext: 'view',\n\t\t\tsearch,\n\t\t\tper_page: search ? 20 : 10,\n\t\t\t...config.queryArgs( search ),\n\t\t} ),\n\t\t[ search, config ]\n\t);\n\tconst { records: searchResults, hasResolved: searchHasResolved } =\n\t\tuseEntityRecords(\n\t\t\tentityForSuggestions.type,\n\t\t\tentityForSuggestions.slug,\n\t\t\tquery\n\t\t);\n\tconst [ suggestions, setSuggestions ] = useState( EMPTY_ARRAY );\n\tuseEffect( () => {\n\t\tif ( ! searchHasResolved ) {\n\t\t\treturn;\n\t\t}\n\t\tlet newSuggestions = EMPTY_ARRAY;\n\t\tif ( searchResults?.length ) {\n\t\t\tnewSuggestions = searchResults;\n\t\t\tif ( config.recordNamePath ) {\n\t\t\t\tnewSuggestions = mapToIHasNameAndId(\n\t\t\t\t\tnewSuggestions,\n\t\t\t\t\tconfig.recordNamePath\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\t// Update suggestions only when the query has resolved, so as to keep\n\t\t// the previous results in the UI.\n\t\tsetSuggestions( newSuggestions );\n\t}, [ searchResults, searchHasResolved ] );\n\treturn suggestions;\n}\n\nfunction SuggestionList( { entityForSuggestions, onSelect } ) {\n\tconst [ search, setSearch, debouncedSearch ] = useDebouncedInput();\n\tconst suggestions = useSearchSuggestions(\n\t\tentityForSuggestions,\n\t\tdebouncedSearch\n\t);\n\tconst { labels } = entityForSuggestions;\n\tconst [ showSearchControl, setShowSearchControl ] = useState( false );\n\tif ( ! showSearchControl && suggestions?.length > 9 ) {\n\t\tsetShowSearchControl( true );\n\t}\n\treturn (\n\t\t<>\n\t\t\t{ showSearchControl && (\n\t\t\t\t<SearchControl\n\t\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\t\tonChange={ setSearch }\n\t\t\t\t\tvalue={ search }\n\t\t\t\t\tlabel={ labels.search_items }\n\t\t\t\t\tplaceholder={ labels.search_items }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ !! suggestions?.length && (\n\t\t\t\t<Composite\n\t\t\t\t\torientation=\"vertical\"\n\t\t\t\t\trole=\"listbox\"\n\t\t\t\t\tclassName=\"edit-site-custom-template-modal__suggestions_list\"\n\t\t\t\t\taria-label={ __( 'Suggestions list' ) }\n\t\t\t\t>\n\t\t\t\t\t{ suggestions.map( ( suggestion ) => (\n\t\t\t\t\t\t<SuggestionListItem\n\t\t\t\t\t\t\tkey={ suggestion.slug }\n\t\t\t\t\t\t\tsuggestion={ suggestion }\n\t\t\t\t\t\t\tsearch={ debouncedSearch }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) ) }\n\t\t\t\t</Composite>\n\t\t\t) }\n\t\t\t{ debouncedSearch && ! suggestions?.length && (\n\t\t\t\t<Text\n\t\t\t\t\tas=\"p\"\n\t\t\t\t\tclassName=\"edit-site-custom-template-modal__no-results\"\n\t\t\t\t>\n\t\t\t\t\t{ labels.not_found }\n\t\t\t\t</Text>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction AddCustomTemplateModalContent( {\n\tonSelect,\n\tentityForSuggestions,\n\tonBack,\n\tcontainerRef,\n} ) {\n\tconst [ showSearchEntities, setShowSearchEntities ] = useState();\n\n\t// Focus on the first focusable element when the modal opens.\n\t// We handle focus management in the parent modal, just need to focus on the first focusable element.\n\tuseEffect( () => {\n\t\tif ( containerRef.current ) {\n\t\t\tconst [ firstFocusable ] = focus.focusable.find(\n\t\t\t\tcontainerRef.current\n\t\t\t);\n\t\t\tfirstFocusable?.focus();\n\t\t}\n\t}, [ showSearchEntities ] );\n\n\treturn (\n\t\t<VStack\n\t\t\tspacing={ 4 }\n\t\t\tclassName=\"edit-site-custom-template-modal__contents-wrapper\"\n\t\t\talignment=\"left\"\n\t\t>\n\t\t\t{ ! showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<Text as=\"p\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Select whether to create a single template for all items or a specific one.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Text>\n\t\t\t\t\t<Flex\n\t\t\t\t\t\tclassName=\"edit-site-custom-template-modal__contents\"\n\t\t\t\t\t\tgap=\"4\"\n\t\t\t\t\t\talign=\"initial\"\n\t\t\t\t\t>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\tslug,\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\ttemplatePrefix,\n\t\t\t\t\t\t\t\t} = entityForSuggestions.template;\n\t\t\t\t\t\t\t\tonSelect( {\n\t\t\t\t\t\t\t\t\tslug,\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\ttemplatePrefix,\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\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tweight={ 500 }\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.all_items }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For all items' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t\t<FlexItem\n\t\t\t\t\t\t\tisBlock\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tsetShowSearchEntities( true );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tweight={ 500 }\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ entityForSuggestions.labels.singular_name }\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t\t<Text\n\t\t\t\t\t\t\t\tas=\"span\"\n\t\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// translators: The user is given the choice to set up a template for all items of a post type or taxonomy, or just a specific one.\n\t\t\t\t\t\t\t\t\t__( 'For a specific item' )\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t</Text>\n\t\t\t\t\t\t</FlexItem>\n\t\t\t\t\t</Flex>\n\t\t\t\t\t<Flex justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ onBack }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Back' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</Flex>\n\t\t\t\t</>\n\t\t\t) }\n\t\t\t{ showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<Text as=\"p\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'This template will be used only for the specific item chosen.'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Text>\n\t\t\t\t\t<SuggestionList\n\t\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t/>\n\t\t\t\t\t<Flex justify=\"right\">\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvariant=\"tertiary\"\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\t// If general template exists, go directly back to main screen\n\t\t\t\t\t\t\t\t// instead of showing the choice screen\n\t\t\t\t\t\t\t\tif ( entityForSuggestions.hasGeneralTemplate ) {\n\t\t\t\t\t\t\t\t\tonBack();\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tsetShowSearchEntities( false );\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\t\t{ __( 'Back' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</Flex>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</VStack>\n\t);\n}\n\nexport default AddCustomTemplateModalContent;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AAUA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,IAAA,GAAAN,OAAA;AAKA,IAAAO,MAAA,GAAAP,OAAA;AAA6C,IAAAQ,WAAA,GAAAR,OAAA;AAvB7C;AACA;AACA;;AAkBA;AACA;AACA;;AAGA,MAAMS,WAAW,GAAG,EAAE;AAEtB,SAASC,kBAAkBA,CAAE;EAC5BC,UAAU;EACVC,MAAM;EACNC,QAAQ;EACRC;AACD,CAAC,EAAG;EACH,MAAMC,YAAY,GACjB,8DAA8D;EAC/D,oBACC,IAAAP,WAAA,CAAAQ,IAAA,EAACd,WAAA,CAAAe,SAAS,CAACC,IAAI;IACdC,MAAM,eACL,IAAAX,WAAA,CAAAY,GAAA,EAAClB,WAAA,CAAAmB,MAAM;MACNC,qBAAqB;MACrBC,IAAI,EAAC,QAAQ;MACbC,SAAS,EAAGT,YAAc;MAC1BU,OAAO,EAAGA,CAAA,KACTZ,QAAQ,CACPC,oBAAoB,CAACY,MAAM,CAACC,mBAAmB,CAC9ChB,UACD,CACD;IACA,CACD,CACD;IAAA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,CAAA2B,kBAAI;QAACkD,EAAE,EAAC,GAAG;QAAAnD,QAAA,EACT,IAAAiD,QAAE,EACH,+DACD;MAAC,CACI,CAAC,eACP,IAAArE,WAAA,CAAAY,GAAA,EAACyC,cAAc;QACd/C,oBAAoB,EAAGA,oBAAsB;QAC7CD,QAAQ,EAAGA;MAAU,CACrB,CAAC,eACF,IAAAL,WAAA,CAAAY,GAAA,EAAClB,WAAA,CAAA4F,IAAI;QAACW,OAAO,EAAC,OAAO;QAAA7E,QAAA,eACpB,IAAApB,WAAA,CAAAY,GAAA,EAAClB,WAAA,CAAAmB,MAAM;UACNC,qBAAqB;UACrBoF,OAAO,EAAC,UAAU;UAClBjF,OAAO,EAAGA,CAAA,KAAM;YACf;YACA;YACA,IAAKX,oBAAoB,CAAC6F,kBAAkB,EAAG;cAC9CzB,MAAM,CAAC,CAAC;YACT,CAAC,MAAM;cACNG,qBAAqB,CAAE,KAAM,CAAC;YAC/B;UACD,CAAG;UAAAzD,QAAA,EAED,IAAAiD,QAAE,EAAE,MAAO;QAAC,CACP;MAAC,CACJ,CAAC;IAAA,CACN,CACF;EAAA,CACM,CAAC;AAEX;AAAC,IAAA+B,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEc7B,6BAA6B","ignoreList":[]}
|
|
@@ -277,12 +277,8 @@ function NewTemplate() {
|
|
|
277
277
|
});
|
|
278
278
|
}
|
|
279
279
|
function useMissingTemplates(setEntityForSuggestions, onClick) {
|
|
280
|
-
const existingTemplates = (0, _utils.useExistingTemplates)();
|
|
281
280
|
const defaultTemplateTypes = (0, _utils.useDefaultTemplateTypes)();
|
|
282
|
-
const
|
|
283
|
-
slug
|
|
284
|
-
}) => slug);
|
|
285
|
-
const missingDefaultTemplates = (defaultTemplateTypes || []).filter(template => DEFAULT_TEMPLATE_SLUGS.includes(template.slug) && !existingTemplateSlugs.includes(template.slug));
|
|
281
|
+
const missingDefaultTemplates = (defaultTemplateTypes || []).filter(template => DEFAULT_TEMPLATE_SLUGS.includes(template.slug));
|
|
286
282
|
const onClickMenuItem = _entityForSuggestions => {
|
|
287
283
|
onClick?.();
|
|
288
284
|
setEntityForSuggestions(_entityForSuggestions);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_clsx","_interopRequireDefault","require","_components","_htmlEntities","_element","_data","_coreData","_compose","_icons","_i18n","_notices","_router","_dom","_constants","_addCustomTemplateModalContent","_utils","_addCustomGenericTemplateModalContent","_lockUnlock","_jsxRuntime","useHistory","unlock","routerPrivateApis","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","home","verse","single","pin","page","archive","search","notFound","index","list","category","author","commentAuthorAvatar","taxonomy","blockMeta","date","calendar","tag","attachment","media","TemplateListItem","title","direction","className","description","icon","onClick","children","jsx","Button","__next40pxDefaultSize","label","showTooltip","jsxs","Flex","as","spacing","align","justify","style","width","Icon","__experimentalVStack","alignment","__experimentalText","weight","lineHeight","modalContentMap","templatesList","customTemplate","customGenericTemplate","NewTemplateModal","onClose","modalContent","setModalContent","useState","entityForSuggestions","setEntityForSuggestions","isSubmitting","setIsSubmitting","missingTemplates","useMissingTemplates","history","saveEntityRecord","useDispatch","coreStore","createErrorNotice","createSuccessNotice","noticesStore","containerRef","useRef","isMobile","useViewportMatch","homeUrl","useSelect","select","getEntityRecord","TEMPLATE_SHORT_DESCRIPTIONS","sprintf","__","Date","getFullYear","useEffect","current","firstFocusable","focus","focusable","find","createTemplate","template","isWPSuggestion","slug","newTemplate","TEMPLATE_POST_TYPE","toString","status","is_wp_suggestion","throwOnError","navigate","id","decodeEntities","rendered","type","error","errorMessage","message","code","onModalClose","modalTitle","labels","singular_name","Modal","clsx","onRequestClose","overlayClassName","undefined","ref","__experimentalGrid","columns","gap","map","layout","edit","default","onSelect","onBack","NewTemplate","showModal","setShowModal","postType","getPostType","Fragment","variant","add_new_item","existingTemplates","useExistingTemplates","defaultTemplateTypes","useDefaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","useTaxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","usePostTypeMenuItems","authorMenuItem","useAuthorMenuItem","forEach","menuItem","matchIndex","findIndex","push","sort","template1","template2","indexOf","usePostTypeArchiveMenuItems","_default","exports","memo"],"sources":["@wordpress/edit-site/src/components/add-new-template/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tModal,\n\t__experimentalGrid as Grid,\n\t__experimentalText as Text,\n\t__experimentalVStack as VStack,\n\tFlex,\n\tIcon,\n} from '@wordpress/components';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useState, memo, useRef, useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\tarchive,\n\tblockMeta,\n\tcalendar,\n\tcategory,\n\tcommentAuthorAvatar,\n\tedit,\n\thome,\n\tlayout,\n\tlist,\n\tmedia,\n\tnotFound,\n\tpage,\n\tpin,\n\tverse,\n\tsearch,\n\ttag,\n} from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { TEMPLATE_POST_TYPE } from '../../utils/constants';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModalContent from './add-custom-template-modal-content';\nimport {\n\tuseExistingTemplates,\n\tuseDefaultTemplateTypes,\n\tuseTaxonomiesMenuItems,\n\tusePostTypeMenuItems,\n\tuseAuthorMenuItem,\n\tusePostTypeArchiveMenuItems,\n} from './utils';\nimport AddCustomGenericTemplateModalContent from './add-custom-generic-template-modal-content';\nimport { unlock } from '../../lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'home',\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'search',\n\t'404',\n];\n\nconst TEMPLATE_ICONS = {\n\t'front-page': home,\n\thome: verse,\n\tsingle: pin,\n\tpage,\n\tarchive,\n\tsearch,\n\t404: notFound,\n\tindex: list,\n\tcategory,\n\tauthor: commentAuthorAvatar,\n\ttaxonomy: blockMeta,\n\tdate: calendar,\n\ttag,\n\tattachment: media,\n};\n\nfunction TemplateListItem( {\n\ttitle,\n\tdirection,\n\tclassName,\n\tdescription,\n\ticon,\n\tonClick,\n\tchildren,\n} ) {\n\treturn (\n\t\t<Button\n\t\t\t__next40pxDefaultSize\n\t\t\tclassName={ className }\n\t\t\tonClick={ onClick }\n\t\t\tlabel={ description }\n\t\t\tshowTooltip={ !! description }\n\t\t>\n\t\t\t<Flex\n\t\t\t\tas=\"span\"\n\t\t\t\tspacing={ 2 }\n\t\t\t\talign=\"center\"\n\t\t\t\tjustify=\"center\"\n\t\t\t\tstyle={ { width: '100%' } }\n\t\t\t\tdirection={ direction }\n\t\t\t>\n\t\t\t\t<div className=\"edit-site-add-new-template__template-icon\">\n\t\t\t\t\t<Icon icon={ icon } />\n\t\t\t\t</div>\n\t\t\t\t<VStack\n\t\t\t\t\tclassName=\"edit-site-add-new-template__template-name\"\n\t\t\t\t\talignment=\"center\"\n\t\t\t\t\tspacing={ 0 }\n\t\t\t\t>\n\t\t\t\t\t<Text\n\t\t\t\t\t\talign=\"center\"\n\t\t\t\t\t\tweight={ 500 }\n\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t>\n\t\t\t\t\t\t{ title }\n\t\t\t\t\t</Text>\n\t\t\t\t\t{ children }\n\t\t\t\t</VStack>\n\t\t\t</Flex>\n\t\t</Button>\n\t);\n}\n\nconst modalContentMap = {\n\ttemplatesList: 1,\n\tcustomTemplate: 2,\n\tcustomGenericTemplate: 3,\n};\n\nfunction NewTemplateModal( { onClose } ) {\n\tconst [ modalContent, setModalContent ] = useState(\n\t\tmodalContentMap.templatesList\n\t);\n\tconst [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );\n\tconst [ isSubmitting, setIsSubmitting ] = useState( false );\n\tconst missingTemplates = useMissingTemplates( setEntityForSuggestions, () =>\n\t\tsetModalContent( modalContentMap.customTemplate )\n\t);\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst containerRef = useRef( null );\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\n\tconst homeUrl = useSelect( ( select ) => {\n\t\t// Site index.\n\t\treturn select( coreStore ).getEntityRecord( 'root', '__unstableBase' )\n\t\t\t?.home;\n\t}, [] );\n\n\tconst TEMPLATE_SHORT_DESCRIPTIONS = {\n\t\t'front-page': homeUrl,\n\t\tdate: sprintf(\n\t\t\t// translators: %s: The homepage url.\n\t\t\t__( 'E.g. %s' ),\n\t\t\thomeUrl + '/' + new Date().getFullYear()\n\t\t),\n\t};\n\n\tuseEffect( () => {\n\t\t// Focus the first focusable element when component mounts or UI changes\n\t\t// We don't want to focus on the other modals because they have their own focus management.\n\t\tif (\n\t\t\tcontainerRef.current &&\n\t\t\tmodalContent === modalContentMap.templatesList\n\t\t) {\n\t\t\tconst [ firstFocusable ] = focus.focusable.find(\n\t\t\t\tcontainerRef.current\n\t\t\t);\n\t\t\tfirstFocusable?.focus();\n\t\t}\n\t}, [ modalContent ] );\n\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\tif ( isSubmitting ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsSubmitting( true );\n\t\ttry {\n\t\t\tconst { title, description, slug } = template;\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tTEMPLATE_POST_TYPE,\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\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// Navigate to the created template editor.\n\t\t\thistory.navigate(\n\t\t\t\t`/${ TEMPLATE_POST_TYPE }/${ newTemplate.id }?canvas=edit`\n\t\t\t);\n\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the created post or template, e.g: \"Hello world\".\n\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\tdecodeEntities( newTemplate.title?.rendered || title )\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} finally {\n\t\t\tsetIsSubmitting( false );\n\t\t}\n\t}\n\tconst onModalClose = () => {\n\t\tonClose();\n\t\tsetModalContent( modalContentMap.templatesList );\n\t};\n\n\tlet modalTitle = __( 'Add template' );\n\tif ( modalContent === modalContentMap.customTemplate ) {\n\t\tmodalTitle = sprintf(\n\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t__( 'Add template: %s' ),\n\t\t\tentityForSuggestions.labels.singular_name\n\t\t);\n\t} else if ( modalContent === modalContentMap.customGenericTemplate ) {\n\t\tmodalTitle = __( 'Create custom template' );\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle }\n\t\t\tclassName={ clsx( 'edit-site-add-new-template__modal', {\n\t\t\t\t'edit-site-add-new-template__modal_template_list':\n\t\t\t\t\tmodalContent === modalContentMap.templatesList,\n\t\t\t\t'edit-site-custom-template-modal':\n\t\t\t\t\tmodalContent === modalContentMap.customTemplate,\n\t\t\t} ) }\n\t\t\tonRequestClose={ onModalClose }\n\t\t\toverlayClassName={\n\t\t\t\tmodalContent === modalContentMap.customGenericTemplate\n\t\t\t\t\t? 'edit-site-custom-generic-template__modal'\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tref={ containerRef }\n\t\t>\n\t\t\t{ modalContent === modalContentMap.templatesList && (\n\t\t\t\t<Grid\n\t\t\t\t\tcolumns={ isMobile ? 2 : 3 }\n\t\t\t\t\tgap={ 4 }\n\t\t\t\t\talign=\"flex-start\"\n\t\t\t\t\tjustify=\"center\"\n\t\t\t\t\tclassName=\"edit-site-add-new-template__template-list__contents\"\n\t\t\t\t>\n\t\t\t\t\t<Flex className=\"edit-site-add-new-template__template-list__prompt\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Select what the new template should apply to:'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Flex>\n\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\tconst { title, slug, onClick } = template;\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<TemplateListItem\n\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\ttitle={ title }\n\t\t\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\t\t\tclassName=\"edit-site-add-new-template__template-button\"\n\t\t\t\t\t\t\t\tdescription={\n\t\t\t\t\t\t\t\t\tTEMPLATE_SHORT_DESCRIPTIONS[ slug ]\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\ticon={ TEMPLATE_ICONS[ slug ] || layout }\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tonClick\n\t\t\t\t\t\t\t\t\t\t? onClick( template )\n\t\t\t\t\t\t\t\t\t\t: createTemplate( template )\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\t<TemplateListItem\n\t\t\t\t\t\ttitle={ __( 'Custom template' ) }\n\t\t\t\t\t\tdirection=\"row\"\n\t\t\t\t\t\tclassName=\"edit-site-add-new-template__custom-template-button\"\n\t\t\t\t\t\ticon={ edit }\n\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\tsetModalContent(\n\t\t\t\t\t\t\t\tmodalContentMap.customGenericTemplate\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\t\t<Text\n\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'A custom template can be manually applied to any post or page.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</Text>\n\t\t\t\t\t</TemplateListItem>\n\t\t\t\t</Grid>\n\t\t\t) }\n\t\t\t{ modalContent === modalContentMap.customTemplate && (\n\t\t\t\t<AddCustomTemplateModalContent\n\t\t\t\t\tonSelect={ createTemplate }\n\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\tonBack={ () =>\n\t\t\t\t\t\tsetModalContent( modalContentMap.templatesList )\n\t\t\t\t\t}\n\t\t\t\t\tcontainerRef={ containerRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ modalContent === modalContentMap.customGenericTemplate && (\n\t\t\t\t<AddCustomGenericTemplateModalContent\n\t\t\t\t\tcreateTemplate={ createTemplate }\n\t\t\t\t\tonBack={ () =>\n\t\t\t\t\t\tsetModalContent( modalContentMap.templatesList )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Modal>\n\t);\n}\n\nfunction NewTemplate() {\n\tconst [ showModal, setShowModal ] = useState( false );\n\n\tconst { postType } = useSelect( ( select ) => {\n\t\tconst { getPostType } = select( coreStore );\n\n\t\treturn {\n\t\t\tpostType: getPostType( TEMPLATE_POST_TYPE ),\n\t\t};\n\t}, [] );\n\n\tif ( ! postType ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tonClick={ () => setShowModal( true ) }\n\t\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\t\t__next40pxDefaultSize\n\t\t\t>\n\t\t\t\t{ postType.labels.add_new_item }\n\t\t\t</Button>\n\t\t\t{ showModal && (\n\t\t\t\t<NewTemplateModal onClose={ () => setShowModal( false ) } />\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates( setEntityForSuggestions, onClick ) {\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\tonClick?.();\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\nexport default memo( NewTemplate );\n"],"mappings":";;;;;;;AAGA,IAAAA,KAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,WAAA,GAAAD,OAAA;AASA,IAAAE,aAAA,GAAAF,OAAA;AACA,IAAAG,QAAA,GAAAH,OAAA;AACA,IAAAI,KAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AACA,IAAAO,MAAA,GAAAP,OAAA;AAkBA,IAAAQ,KAAA,GAAAR,OAAA;AACA,IAAAS,QAAA,GAAAT,OAAA;AACA,IAAAU,OAAA,GAAAV,OAA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ACE,IAAI,KAAK+D,QAAQ,CAAC/D,IAC5C,CAAC;IACD;IACA;IACA;IACA;IACA;IACA,IAAKgE,UAAU,GAAG,CAAC,CAAC,EAAG;MACtBX,mCAAmC,CAAEW,UAAU,CAAE,GAAGD,QAAQ;IAC7D,CAAC,MAAM;MACNV,mCAAmC,CAACa,IAAI,CAAEH,QAAS,CAAC;IACrD;EACD,CAAE,CAAC;EACH;EACAV,mCAAmC,EAAEc,IAAI,CAAE,CAAEC,SAAS,EAAEC,SAAS,KAAM;IACtE,OACClK,sBAAsB,CAACmK,OAAO,CAAEF,SAAS,CAACpE,IAAK,CAAC,GAChD7F,sBAAsB,CAACmK,OAAO,CAAED,SAAS,CAACrE,IAAK,CAAC;EAElD,CAAE,CAAC;EACH,MAAM/B,gBAAgB,GAAG,CACxB,GAAGoF,mCAAmC,EACtC,GAAG,IAAAkB,kCAA2B,EAAC,CAAC,EAChC,GAAGb,kBAAkB,EACrB,GAAGH,mBAAmB,CACtB;EACD,OAAOtF,gBAAgB;AACxB;AAAC,IAAAuG,QAAA,GAAAC,OAAA,CAAAzC,OAAA,GAEc,IAAA0C,aAAI,EAAEvC,WAAY,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["_clsx","_interopRequireDefault","require","_components","_htmlEntities","_element","_data","_coreData","_compose","_icons","_i18n","_notices","_router","_dom","_constants","_addCustomTemplateModalContent","_utils","_addCustomGenericTemplateModalContent","_lockUnlock","_jsxRuntime","useHistory","unlock","routerPrivateApis","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","home","verse","single","pin","page","archive","search","notFound","index","list","category","author","commentAuthorAvatar","taxonomy","blockMeta","date","calendar","tag","attachment","media","TemplateListItem","title","direction","className","description","icon","onClick","children","jsx","Button","__next40pxDefaultSize","label","showTooltip","jsxs","Flex","as","spacing","align","justify","style","width","Icon","__experimentalVStack","alignment","__experimentalText","weight","lineHeight","modalContentMap","templatesList","customTemplate","customGenericTemplate","NewTemplateModal","onClose","modalContent","setModalContent","useState","entityForSuggestions","setEntityForSuggestions","isSubmitting","setIsSubmitting","missingTemplates","useMissingTemplates","history","saveEntityRecord","useDispatch","coreStore","createErrorNotice","createSuccessNotice","noticesStore","containerRef","useRef","isMobile","useViewportMatch","homeUrl","useSelect","select","getEntityRecord","TEMPLATE_SHORT_DESCRIPTIONS","sprintf","__","Date","getFullYear","useEffect","current","firstFocusable","focus","focusable","find","createTemplate","template","isWPSuggestion","slug","newTemplate","TEMPLATE_POST_TYPE","toString","status","is_wp_suggestion","throwOnError","navigate","id","decodeEntities","rendered","type","error","errorMessage","message","code","onModalClose","modalTitle","labels","singular_name","Modal","clsx","onRequestClose","overlayClassName","undefined","ref","__experimentalGrid","columns","gap","map","layout","edit","default","onSelect","onBack","NewTemplate","showModal","setShowModal","postType","getPostType","Fragment","variant","add_new_item","defaultTemplateTypes","useDefaultTemplateTypes","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","useTaxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","usePostTypeMenuItems","authorMenuItem","useAuthorMenuItem","forEach","menuItem","matchIndex","findIndex","push","sort","template1","template2","indexOf","usePostTypeArchiveMenuItems","_default","exports","memo"],"sources":["@wordpress/edit-site/src/components/add-new-template/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tModal,\n\t__experimentalGrid as Grid,\n\t__experimentalText as Text,\n\t__experimentalVStack as VStack,\n\tFlex,\n\tIcon,\n} from '@wordpress/components';\nimport { decodeEntities } from '@wordpress/html-entities';\nimport { useState, memo, useRef, useEffect } from '@wordpress/element';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { useViewportMatch } from '@wordpress/compose';\nimport {\n\tarchive,\n\tblockMeta,\n\tcalendar,\n\tcategory,\n\tcommentAuthorAvatar,\n\tedit,\n\thome,\n\tlayout,\n\tlist,\n\tmedia,\n\tnotFound,\n\tpage,\n\tpin,\n\tverse,\n\tsearch,\n\ttag,\n} from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { privateApis as routerPrivateApis } from '@wordpress/router';\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport { TEMPLATE_POST_TYPE } from '../../utils/constants';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModalContent from './add-custom-template-modal-content';\nimport {\n\tuseDefaultTemplateTypes,\n\tuseTaxonomiesMenuItems,\n\tusePostTypeMenuItems,\n\tuseAuthorMenuItem,\n\tusePostTypeArchiveMenuItems,\n} from './utils';\nimport AddCustomGenericTemplateModalContent from './add-custom-generic-template-modal-content';\nimport { unlock } from '../../lock-unlock';\n\nconst { useHistory } = unlock( routerPrivateApis );\n\nconst DEFAULT_TEMPLATE_SLUGS = [\n\t'front-page',\n\t'home',\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'search',\n\t'404',\n];\n\nconst TEMPLATE_ICONS = {\n\t'front-page': home,\n\thome: verse,\n\tsingle: pin,\n\tpage,\n\tarchive,\n\tsearch,\n\t404: notFound,\n\tindex: list,\n\tcategory,\n\tauthor: commentAuthorAvatar,\n\ttaxonomy: blockMeta,\n\tdate: calendar,\n\ttag,\n\tattachment: media,\n};\n\nfunction TemplateListItem( {\n\ttitle,\n\tdirection,\n\tclassName,\n\tdescription,\n\ticon,\n\tonClick,\n\tchildren,\n} ) {\n\treturn (\n\t\t<Button\n\t\t\t__next40pxDefaultSize\n\t\t\tclassName={ className }\n\t\t\tonClick={ onClick }\n\t\t\tlabel={ description }\n\t\t\tshowTooltip={ !! description }\n\t\t>\n\t\t\t<Flex\n\t\t\t\tas=\"span\"\n\t\t\t\tspacing={ 2 }\n\t\t\t\talign=\"center\"\n\t\t\t\tjustify=\"center\"\n\t\t\t\tstyle={ { width: '100%' } }\n\t\t\t\tdirection={ direction }\n\t\t\t>\n\t\t\t\t<div className=\"edit-site-add-new-template__template-icon\">\n\t\t\t\t\t<Icon icon={ icon } />\n\t\t\t\t</div>\n\t\t\t\t<VStack\n\t\t\t\t\tclassName=\"edit-site-add-new-template__template-name\"\n\t\t\t\t\talignment=\"center\"\n\t\t\t\t\tspacing={ 0 }\n\t\t\t\t>\n\t\t\t\t\t<Text\n\t\t\t\t\t\talign=\"center\"\n\t\t\t\t\t\tweight={ 500 }\n\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t>\n\t\t\t\t\t\t{ title }\n\t\t\t\t\t</Text>\n\t\t\t\t\t{ children }\n\t\t\t\t</VStack>\n\t\t\t</Flex>\n\t\t</Button>\n\t);\n}\n\nconst modalContentMap = {\n\ttemplatesList: 1,\n\tcustomTemplate: 2,\n\tcustomGenericTemplate: 3,\n};\n\nfunction NewTemplateModal( { onClose } ) {\n\tconst [ modalContent, setModalContent ] = useState(\n\t\tmodalContentMap.templatesList\n\t);\n\tconst [ entityForSuggestions, setEntityForSuggestions ] = useState( {} );\n\tconst [ isSubmitting, setIsSubmitting ] = useState( false );\n\tconst missingTemplates = useMissingTemplates( setEntityForSuggestions, () =>\n\t\tsetModalContent( modalContentMap.customTemplate )\n\t);\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst containerRef = useRef( null );\n\tconst isMobile = useViewportMatch( 'medium', '<' );\n\n\tconst homeUrl = useSelect( ( select ) => {\n\t\t// Site index.\n\t\treturn select( coreStore ).getEntityRecord( 'root', '__unstableBase' )\n\t\t\t?.home;\n\t}, [] );\n\n\tconst TEMPLATE_SHORT_DESCRIPTIONS = {\n\t\t'front-page': homeUrl,\n\t\tdate: sprintf(\n\t\t\t// translators: %s: The homepage url.\n\t\t\t__( 'E.g. %s' ),\n\t\t\thomeUrl + '/' + new Date().getFullYear()\n\t\t),\n\t};\n\n\tuseEffect( () => {\n\t\t// Focus the first focusable element when component mounts or UI changes\n\t\t// We don't want to focus on the other modals because they have their own focus management.\n\t\tif (\n\t\t\tcontainerRef.current &&\n\t\t\tmodalContent === modalContentMap.templatesList\n\t\t) {\n\t\t\tconst [ firstFocusable ] = focus.focusable.find(\n\t\t\t\tcontainerRef.current\n\t\t\t);\n\t\t\tfirstFocusable?.focus();\n\t\t}\n\t}, [ modalContent ] );\n\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\tif ( isSubmitting ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsSubmitting( true );\n\t\ttry {\n\t\t\tconst { title, description, slug } = template;\n\t\t\tconst newTemplate = await saveEntityRecord(\n\t\t\t\t'postType',\n\t\t\t\tTEMPLATE_POST_TYPE,\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\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// Navigate to the created template editor.\n\t\t\thistory.navigate(\n\t\t\t\t`/${ TEMPLATE_POST_TYPE }/${ newTemplate.id }?canvas=edit`\n\t\t\t);\n\n\t\t\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the created post or template, e.g: \"Hello world\".\n\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\tdecodeEntities( newTemplate.title?.rendered || title )\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} finally {\n\t\t\tsetIsSubmitting( false );\n\t\t}\n\t}\n\tconst onModalClose = () => {\n\t\tonClose();\n\t\tsetModalContent( modalContentMap.templatesList );\n\t};\n\n\tlet modalTitle = __( 'Add template' );\n\tif ( modalContent === modalContentMap.customTemplate ) {\n\t\tmodalTitle = sprintf(\n\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t__( 'Add template: %s' ),\n\t\t\tentityForSuggestions.labels.singular_name\n\t\t);\n\t} else if ( modalContent === modalContentMap.customGenericTemplate ) {\n\t\tmodalTitle = __( 'Create custom template' );\n\t}\n\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ modalTitle }\n\t\t\tclassName={ clsx( 'edit-site-add-new-template__modal', {\n\t\t\t\t'edit-site-add-new-template__modal_template_list':\n\t\t\t\t\tmodalContent === modalContentMap.templatesList,\n\t\t\t\t'edit-site-custom-template-modal':\n\t\t\t\t\tmodalContent === modalContentMap.customTemplate,\n\t\t\t} ) }\n\t\t\tonRequestClose={ onModalClose }\n\t\t\toverlayClassName={\n\t\t\t\tmodalContent === modalContentMap.customGenericTemplate\n\t\t\t\t\t? 'edit-site-custom-generic-template__modal'\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\tref={ containerRef }\n\t\t>\n\t\t\t{ modalContent === modalContentMap.templatesList && (\n\t\t\t\t<Grid\n\t\t\t\t\tcolumns={ isMobile ? 2 : 3 }\n\t\t\t\t\tgap={ 4 }\n\t\t\t\t\talign=\"flex-start\"\n\t\t\t\t\tjustify=\"center\"\n\t\t\t\t\tclassName=\"edit-site-add-new-template__template-list__contents\"\n\t\t\t\t>\n\t\t\t\t\t<Flex className=\"edit-site-add-new-template__template-list__prompt\">\n\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t'Select what the new template should apply to:'\n\t\t\t\t\t\t) }\n\t\t\t\t\t</Flex>\n\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\tconst { title, slug, onClick } = template;\n\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t<TemplateListItem\n\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\ttitle={ title }\n\t\t\t\t\t\t\t\tdirection=\"column\"\n\t\t\t\t\t\t\t\tclassName=\"edit-site-add-new-template__template-button\"\n\t\t\t\t\t\t\t\tdescription={\n\t\t\t\t\t\t\t\t\tTEMPLATE_SHORT_DESCRIPTIONS[ slug ]\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\ticon={ TEMPLATE_ICONS[ slug ] || layout }\n\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\tonClick\n\t\t\t\t\t\t\t\t\t\t? onClick( template )\n\t\t\t\t\t\t\t\t\t\t: createTemplate( template )\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\t<TemplateListItem\n\t\t\t\t\t\ttitle={ __( 'Custom template' ) }\n\t\t\t\t\t\tdirection=\"row\"\n\t\t\t\t\t\tclassName=\"edit-site-add-new-template__custom-template-button\"\n\t\t\t\t\t\ticon={ edit }\n\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\tsetModalContent(\n\t\t\t\t\t\t\t\tmodalContentMap.customGenericTemplate\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\t\t<Text\n\t\t\t\t\t\t\tlineHeight={ 1.53846153846 } // 20px\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __(\n\t\t\t\t\t\t\t\t'A custom template can be manually applied to any post or page.'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t</Text>\n\t\t\t\t\t</TemplateListItem>\n\t\t\t\t</Grid>\n\t\t\t) }\n\t\t\t{ modalContent === modalContentMap.customTemplate && (\n\t\t\t\t<AddCustomTemplateModalContent\n\t\t\t\t\tonSelect={ createTemplate }\n\t\t\t\t\tentityForSuggestions={ entityForSuggestions }\n\t\t\t\t\tonBack={ () =>\n\t\t\t\t\t\tsetModalContent( modalContentMap.templatesList )\n\t\t\t\t\t}\n\t\t\t\t\tcontainerRef={ containerRef }\n\t\t\t\t/>\n\t\t\t) }\n\t\t\t{ modalContent === modalContentMap.customGenericTemplate && (\n\t\t\t\t<AddCustomGenericTemplateModalContent\n\t\t\t\t\tcreateTemplate={ createTemplate }\n\t\t\t\t\tonBack={ () =>\n\t\t\t\t\t\tsetModalContent( modalContentMap.templatesList )\n\t\t\t\t\t}\n\t\t\t\t/>\n\t\t\t) }\n\t\t</Modal>\n\t);\n}\n\nfunction NewTemplate() {\n\tconst [ showModal, setShowModal ] = useState( false );\n\n\tconst { postType } = useSelect( ( select ) => {\n\t\tconst { getPostType } = select( coreStore );\n\n\t\treturn {\n\t\t\tpostType: getPostType( TEMPLATE_POST_TYPE ),\n\t\t};\n\t}, [] );\n\n\tif ( ! postType ) {\n\t\treturn null;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t<Button\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tonClick={ () => setShowModal( true ) }\n\t\t\t\tlabel={ postType.labels.add_new_item }\n\t\t\t\t__next40pxDefaultSize\n\t\t\t>\n\t\t\t\t{ postType.labels.add_new_item }\n\t\t\t</Button>\n\t\t\t{ showModal && (\n\t\t\t\t<NewTemplateModal onClose={ () => setShowModal( false ) } />\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates( setEntityForSuggestions, onClick ) {\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter(\n\t\t( template ) => DEFAULT_TEMPLATE_SLUGS.includes( template.slug )\n\t);\n\tconst onClickMenuItem = ( _entityForSuggestions ) => {\n\t\tonClick?.();\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\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5BG,cAAc,CACd,CAACE,OAAO,CAAIC,QAAQ,IAAM;IAC1B,IAAK,CAAEA,QAAQ,EAAG;MACjB;IACD;IACA,MAAMC,UAAU,GAAGX,mCAAmC,CAACY,SAAS,CAC7DhE,QAAQ,IAAMA,QAAQ,CAACE,IAAI,KAAK4D,QAAQ,CAAC5D,IAC5C,CAAC;IACD;IACA;IACA;IACA;IACA;IACA,IAAK6D,UAAU,GAAG,CAAC,CAAC,EAAG;MACtBX,mCAAmC,CAAEW,UAAU,CAAE,GAAGD,QAAQ;IAC7D,CAAC,MAAM;MACNV,mCAAmC,CAACa,IAAI,CAAEH,QAAS,CAAC;IACrD;EACD,CAAE,CAAC;EACH;EACAV,mCAAmC,EAAEc,IAAI,CAAE,CAAEC,SAAS,EAAEC,SAAS,KAAM;IACtE,OACC/J,sBAAsB,CAACgK,OAAO,CAAEF,SAAS,CAACjE,IAAK,CAAC,GAChD7F,sBAAsB,CAACgK,OAAO,CAAED,SAAS,CAAClE,IAAK,CAAC;EAElD,CAAE,CAAC;EACH,MAAM/B,gBAAgB,GAAG,CACxB,GAAGiF,mCAAmC,EACtC,GAAG,IAAAkB,kCAA2B,EAAC,CAAC,EAChC,GAAGb,kBAAkB,EACrB,GAAGH,mBAAmB,CACtB;EACD,OAAOnF,gBAAgB;AACxB;AAAC,IAAAoG,QAAA,GAAAC,OAAA,CAAAtC,OAAA,GAEc,IAAAuC,aAAI,EAAEpC,WAAY,CAAC","ignoreList":[]}
|
|
@@ -147,7 +147,6 @@ function usePostTypeArchiveMenuItems() {
|
|
|
147
147
|
}
|
|
148
148
|
const usePostTypeMenuItems = onClickMenuItem => {
|
|
149
149
|
const publicPostTypes = usePublicPostTypes();
|
|
150
|
-
const existingTemplates = useExistingTemplates();
|
|
151
150
|
const defaultTemplateTypes = useDefaultTemplateTypes();
|
|
152
151
|
// We need to keep track of naming conflicts. If a conflict
|
|
153
152
|
// occurs, we need to add slug.
|
|
@@ -178,9 +177,6 @@ const usePostTypeMenuItems = onClickMenuItem => {
|
|
|
178
177
|
return accumulator;
|
|
179
178
|
}, {}), [publicPostTypes]);
|
|
180
179
|
const postTypesInfo = useEntitiesInfo('postType', templatePrefixes);
|
|
181
|
-
const existingTemplateSlugs = (existingTemplates || []).map(({
|
|
182
|
-
slug
|
|
183
|
-
}) => slug);
|
|
184
180
|
const menuItems = (publicPostTypes || []).reduce((accumulator, postType) => {
|
|
185
181
|
const {
|
|
186
182
|
slug,
|
|
@@ -194,7 +190,6 @@ const usePostTypeMenuItems = onClickMenuItem => {
|
|
|
194
190
|
const defaultTemplateType = defaultTemplateTypes?.find(({
|
|
195
191
|
slug: _slug
|
|
196
192
|
}) => _slug === generalTemplateSlug);
|
|
197
|
-
const hasGeneralTemplate = existingTemplateSlugs?.includes(generalTemplateSlug);
|
|
198
193
|
const _needsUniqueIdentifier = needsUniqueIdentifier(postType);
|
|
199
194
|
let menuItemTitle = labels.template_name || (0, _i18n.sprintf)(
|
|
200
195
|
// translators: %s: Name of the post type e.g: "Post".
|
|
@@ -249,14 +244,12 @@ const usePostTypeMenuItems = onClickMenuItem => {
|
|
|
249
244
|
}
|
|
250
245
|
},
|
|
251
246
|
labels,
|
|
252
|
-
hasGeneralTemplate,
|
|
253
247
|
template
|
|
254
248
|
});
|
|
255
249
|
};
|
|
256
250
|
}
|
|
257
|
-
// We don't need to add the menu item if there are no
|
|
258
|
-
|
|
259
|
-
if (!hasGeneralTemplate || hasEntities) {
|
|
251
|
+
// We don't need to add the menu item if there are no entities.
|
|
252
|
+
if (hasEntities) {
|
|
260
253
|
accumulator.push(menuItem);
|
|
261
254
|
}
|
|
262
255
|
return accumulator;
|
|
@@ -458,7 +451,9 @@ function useAuthorMenuItem(onClickMenuItem) {
|
|
|
458
451
|
getSpecificTemplate: suggestion => {
|
|
459
452
|
const templateSlug = `author-${suggestion.slug}`;
|
|
460
453
|
return {
|
|
461
|
-
title:
|
|
454
|
+
title: (0, _i18n.sprintf)(
|
|
455
|
+
// translators: %s: Name of the author e.g: "Admin".
|
|
456
|
+
(0, _i18n.__)('Author: %s'), suggestion.name),
|
|
462
457
|
slug: templateSlug,
|
|
463
458
|
templatePrefix: 'author'
|
|
464
459
|
};
|
|
@@ -480,68 +475,6 @@ function useAuthorMenuItem(onClickMenuItem) {
|
|
|
480
475
|
}
|
|
481
476
|
}
|
|
482
477
|
|
|
483
|
-
/**
|
|
484
|
-
* Helper hook that filters all the existing templates by the given
|
|
485
|
-
* object with the entity's slug as key and the template prefix as value.
|
|
486
|
-
*
|
|
487
|
-
* Example:
|
|
488
|
-
* `existingTemplates` is: [ { slug: 'tag-apple' }, { slug: 'page-about' }, { slug: 'tag' } ]
|
|
489
|
-
* `templatePrefixes` is: { post_tag: 'tag' }
|
|
490
|
-
* It will return: { post_tag: ['apple'] }
|
|
491
|
-
*
|
|
492
|
-
* Note: We append the `-` to the given template prefix in this function for our checks.
|
|
493
|
-
*
|
|
494
|
-
* @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
|
|
495
|
-
* @return {Record<string,string[]>} An object with the entity's slug as key and an array with the existing template slugs as value.
|
|
496
|
-
*/
|
|
497
|
-
const useExistingTemplateSlugs = templatePrefixes => {
|
|
498
|
-
const existingTemplates = useExistingTemplates();
|
|
499
|
-
const existingSlugs = (0, _element.useMemo)(() => {
|
|
500
|
-
return Object.entries(templatePrefixes || {}).reduce((accumulator, [slug, prefix]) => {
|
|
501
|
-
const slugsWithTemplates = (existingTemplates || []).reduce((_accumulator, existingTemplate) => {
|
|
502
|
-
const _prefix = `${prefix}-`;
|
|
503
|
-
if (existingTemplate.slug.startsWith(_prefix)) {
|
|
504
|
-
_accumulator.push(existingTemplate.slug.substring(_prefix.length));
|
|
505
|
-
}
|
|
506
|
-
return _accumulator;
|
|
507
|
-
}, []);
|
|
508
|
-
if (slugsWithTemplates.length) {
|
|
509
|
-
accumulator[slug] = slugsWithTemplates;
|
|
510
|
-
}
|
|
511
|
-
return accumulator;
|
|
512
|
-
}, {});
|
|
513
|
-
}, [templatePrefixes, existingTemplates]);
|
|
514
|
-
return existingSlugs;
|
|
515
|
-
};
|
|
516
|
-
|
|
517
|
-
/**
|
|
518
|
-
* Helper hook that finds the existing records with an associated template,
|
|
519
|
-
* as they need to be excluded from the template suggestions.
|
|
520
|
-
*
|
|
521
|
-
* @param {string} entityName The entity's name.
|
|
522
|
-
* @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
|
|
523
|
-
* @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.
|
|
524
|
-
* @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the existing records as value.
|
|
525
|
-
*/
|
|
526
|
-
const useTemplatesToExclude = (entityName, templatePrefixes, additionalQueryParameters = {}) => {
|
|
527
|
-
const slugsToExcludePerEntity = useExistingTemplateSlugs(templatePrefixes);
|
|
528
|
-
const recordsToExcludePerEntity = (0, _data.useSelect)(select => {
|
|
529
|
-
return Object.entries(slugsToExcludePerEntity || {}).reduce((accumulator, [slug, slugsWithTemplates]) => {
|
|
530
|
-
const entitiesWithTemplates = select(_coreData.store).getEntityRecords(entityName, slug, {
|
|
531
|
-
_fields: 'id',
|
|
532
|
-
context: 'view',
|
|
533
|
-
slug: slugsWithTemplates,
|
|
534
|
-
...additionalQueryParameters[slug]
|
|
535
|
-
});
|
|
536
|
-
if (entitiesWithTemplates?.length) {
|
|
537
|
-
accumulator[slug] = entitiesWithTemplates;
|
|
538
|
-
}
|
|
539
|
-
return accumulator;
|
|
540
|
-
}, {});
|
|
541
|
-
}, [slugsToExcludePerEntity]);
|
|
542
|
-
return recordsToExcludePerEntity;
|
|
543
|
-
};
|
|
544
|
-
|
|
545
478
|
/**
|
|
546
479
|
* Helper hook that returns information about an entity having
|
|
547
480
|
* records that we can create a specific template for.
|
|
@@ -558,34 +491,25 @@ const useTemplatesToExclude = (entityName, templatePrefixes, additionalQueryPara
|
|
|
558
491
|
* @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the EntitiesInfo as value.
|
|
559
492
|
*/
|
|
560
493
|
const useEntitiesInfo = (entityName, templatePrefixes, additionalQueryParameters = EMPTY_OBJECT) => {
|
|
561
|
-
const recordsToExcludePerEntity = useTemplatesToExclude(entityName, templatePrefixes, additionalQueryParameters);
|
|
562
494
|
const entitiesHasRecords = (0, _data.useSelect)(select => {
|
|
563
495
|
return Object.keys(templatePrefixes || {}).reduce((accumulator, slug) => {
|
|
564
|
-
const existingEntitiesIds = recordsToExcludePerEntity?.[slug]?.map(({
|
|
565
|
-
id
|
|
566
|
-
}) => id) || [];
|
|
567
496
|
accumulator[slug] = !!select(_coreData.store).getEntityRecords(entityName, slug, {
|
|
568
497
|
per_page: 1,
|
|
569
498
|
_fields: 'id',
|
|
570
499
|
context: 'view',
|
|
571
|
-
exclude: existingEntitiesIds,
|
|
572
500
|
...additionalQueryParameters[slug]
|
|
573
501
|
})?.length;
|
|
574
502
|
return accumulator;
|
|
575
503
|
}, {});
|
|
576
|
-
}, [templatePrefixes,
|
|
504
|
+
}, [templatePrefixes, entityName, additionalQueryParameters]);
|
|
577
505
|
const entitiesInfo = (0, _element.useMemo)(() => {
|
|
578
506
|
return Object.keys(templatePrefixes || {}).reduce((accumulator, slug) => {
|
|
579
|
-
const existingEntitiesIds = recordsToExcludePerEntity?.[slug]?.map(({
|
|
580
|
-
id
|
|
581
|
-
}) => id) || [];
|
|
582
507
|
accumulator[slug] = {
|
|
583
|
-
hasEntities: entitiesHasRecords[slug]
|
|
584
|
-
existingEntitiesIds
|
|
508
|
+
hasEntities: entitiesHasRecords[slug]
|
|
585
509
|
};
|
|
586
510
|
return accumulator;
|
|
587
511
|
}, {});
|
|
588
|
-
}, [templatePrefixes,
|
|
512
|
+
}, [templatePrefixes, entitiesHasRecords]);
|
|
589
513
|
return entitiesInfo;
|
|
590
514
|
};
|
|
591
515
|
//# sourceMappingURL=utils.js.map
|