@wordpress/edit-site 4.11.0 → 4.12.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.
Files changed (127) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/add-new-template/add-custom-template-modal.js +4 -2
  3. package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
  4. package/build/components/add-new-template/new-template.js +22 -2
  5. package/build/components/add-new-template/new-template.js.map +1 -1
  6. package/build/components/add-new-template/utils.js +152 -28
  7. package/build/components/add-new-template/utils.js.map +1 -1
  8. package/build/components/global-styles/dimensions-panel.js +6 -2
  9. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  10. package/build/components/global-styles/hooks.js +1 -1
  11. package/build/components/global-styles/hooks.js.map +1 -1
  12. package/build/components/global-styles/screen-color-palette.js +1 -1
  13. package/build/components/global-styles/screen-color-palette.js.map +1 -1
  14. package/build/components/global-styles/screen-colors.js +51 -7
  15. package/build/components/global-styles/screen-colors.js.map +1 -1
  16. package/build/components/global-styles/screen-heading-color.js +157 -0
  17. package/build/components/global-styles/screen-heading-color.js.map +1 -0
  18. package/build/components/global-styles/screen-typography-element.js +4 -0
  19. package/build/components/global-styles/screen-typography-element.js.map +1 -1
  20. package/build/components/global-styles/screen-typography.js +5 -0
  21. package/build/components/global-styles/screen-typography.js.map +1 -1
  22. package/build/components/global-styles/typography-panel.js +73 -12
  23. package/build/components/global-styles/typography-panel.js.map +1 -1
  24. package/build/components/global-styles/typography-utils.js +217 -0
  25. package/build/components/global-styles/typography-utils.js.map +1 -0
  26. package/build/components/global-styles/ui.js +11 -0
  27. package/build/components/global-styles/ui.js.map +1 -1
  28. package/build/components/global-styles/use-global-styles-output.js +61 -40
  29. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  30. package/build/components/global-styles/utils.js +17 -2
  31. package/build/components/global-styles/utils.js.map +1 -1
  32. package/build/components/header/index.js +15 -4
  33. package/build/components/header/index.js.map +1 -1
  34. package/build/components/header/undo-redo/redo.js +2 -1
  35. package/build/components/header/undo-redo/redo.js.map +1 -1
  36. package/build/components/list/actions/index.js +1 -1
  37. package/build/components/list/actions/index.js.map +1 -1
  38. package/build/components/save-button/index.js +2 -3
  39. package/build/components/save-button/index.js.map +1 -1
  40. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js +2 -2
  41. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  42. package/build/components/sidebar/template-card/template-actions.js +1 -1
  43. package/build/components/sidebar/template-card/template-actions.js.map +1 -1
  44. package/build/components/template-details/index.js +1 -1
  45. package/build/components/template-details/index.js.map +1 -1
  46. package/build/components/template-details/template-areas.js +1 -1
  47. package/build/components/template-details/template-areas.js.map +1 -1
  48. package/build/components/template-part-converter/convert-to-template-part.js +4 -1
  49. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  50. package/build-module/components/add-new-template/add-custom-template-modal.js +4 -2
  51. package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
  52. package/build-module/components/add-new-template/new-template.js +21 -3
  53. package/build-module/components/add-new-template/new-template.js.map +1 -1
  54. package/build-module/components/add-new-template/utils.js +147 -26
  55. package/build-module/components/add-new-template/utils.js.map +1 -1
  56. package/build-module/components/global-styles/dimensions-panel.js +6 -2
  57. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  58. package/build-module/components/global-styles/hooks.js +1 -1
  59. package/build-module/components/global-styles/hooks.js.map +1 -1
  60. package/build-module/components/global-styles/screen-color-palette.js +1 -1
  61. package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
  62. package/build-module/components/global-styles/screen-colors.js +51 -7
  63. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  64. package/build-module/components/global-styles/screen-heading-color.js +143 -0
  65. package/build-module/components/global-styles/screen-heading-color.js.map +1 -0
  66. package/build-module/components/global-styles/screen-typography-element.js +4 -0
  67. package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
  68. package/build-module/components/global-styles/screen-typography.js +5 -0
  69. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  70. package/build-module/components/global-styles/typography-panel.js +74 -13
  71. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  72. package/build-module/components/global-styles/typography-utils.js +204 -0
  73. package/build-module/components/global-styles/typography-utils.js.map +1 -0
  74. package/build-module/components/global-styles/ui.js +10 -0
  75. package/build-module/components/global-styles/ui.js.map +1 -1
  76. package/build-module/components/global-styles/use-global-styles-output.js +61 -44
  77. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  78. package/build-module/components/global-styles/utils.js +16 -2
  79. package/build-module/components/global-styles/utils.js.map +1 -1
  80. package/build-module/components/header/index.js +17 -6
  81. package/build-module/components/header/index.js.map +1 -1
  82. package/build-module/components/header/undo-redo/redo.js +3 -2
  83. package/build-module/components/header/undo-redo/redo.js.map +1 -1
  84. package/build-module/components/list/actions/index.js +1 -1
  85. package/build-module/components/list/actions/index.js.map +1 -1
  86. package/build-module/components/save-button/index.js +3 -4
  87. package/build-module/components/save-button/index.js.map +1 -1
  88. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js +3 -3
  89. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  90. package/build-module/components/sidebar/template-card/template-actions.js +1 -1
  91. package/build-module/components/sidebar/template-card/template-actions.js.map +1 -1
  92. package/build-module/components/template-details/index.js +1 -1
  93. package/build-module/components/template-details/index.js.map +1 -1
  94. package/build-module/components/template-details/template-areas.js +1 -1
  95. package/build-module/components/template-details/template-areas.js.map +1 -1
  96. package/build-module/components/template-part-converter/convert-to-template-part.js +3 -1
  97. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  98. package/build-style/style-rtl.css +13 -4
  99. package/build-style/style.css +13 -4
  100. package/package.json +29 -29
  101. package/src/components/add-new-template/add-custom-template-modal.js +12 -3
  102. package/src/components/add-new-template/new-template.js +40 -20
  103. package/src/components/add-new-template/utils.js +145 -16
  104. package/src/components/global-styles/dimensions-panel.js +5 -3
  105. package/src/components/global-styles/hooks.js +1 -0
  106. package/src/components/global-styles/screen-color-palette.js +1 -1
  107. package/src/components/global-styles/screen-colors.js +46 -4
  108. package/src/components/global-styles/screen-heading-color.js +201 -0
  109. package/src/components/global-styles/screen-typography-element.js +4 -0
  110. package/src/components/global-styles/screen-typography.js +6 -0
  111. package/src/components/global-styles/style.scss +13 -6
  112. package/src/components/global-styles/test/typography-utils.js +130 -0
  113. package/src/components/global-styles/test/use-global-styles-output.js +66 -3
  114. package/src/components/global-styles/typography-panel.js +85 -16
  115. package/src/components/global-styles/typography-utils.js +228 -0
  116. package/src/components/global-styles/ui.js +13 -0
  117. package/src/components/global-styles/use-global-styles-output.js +79 -48
  118. package/src/components/global-styles/utils.js +10 -0
  119. package/src/components/header/index.js +28 -3
  120. package/src/components/header/undo-redo/redo.js +6 -2
  121. package/src/components/list/actions/index.js +3 -1
  122. package/src/components/save-button/index.js +10 -13
  123. package/src/components/sidebar/navigation-menu-sidebar/navigation-menu.js +1 -5
  124. package/src/components/sidebar/template-card/template-actions.js +3 -1
  125. package/src/components/template-details/index.js +3 -1
  126. package/src/components/template-details/template-areas.js +3 -1
  127. package/src/components/template-part-converter/convert-to-template-part.js +3 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 4.12.0 (2022-08-10)
6
+
5
7
  ## 4.11.0 (2022-07-27)
6
8
 
7
9
  ## 4.10.0 (2022-07-13)
@@ -167,12 +167,14 @@ function AddCustomTemplateModal(_ref3) {
167
167
  const {
168
168
  slug,
169
169
  title,
170
- description
170
+ description,
171
+ templatePrefix
171
172
  } = entityForSuggestions.template;
172
173
  onSelect({
173
174
  slug,
174
175
  title,
175
- description
176
+ description,
177
+ templatePrefix
176
178
  });
177
179
  }
178
180
  }, (0, _element.createElement)(_components.__experimentalText, {
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/add-custom-template-modal.js"],"names":["EMPTY_ARRAY","SuggestionListItem","suggestion","search","onSelect","entityForSuggestions","composite","baseCssClass","Button","config","getSpecificTemplate","name","link","useDebouncedInput","input","setInput","debounced","setter","setDebounced","useSearchSuggestions","query","order","context","per_page","queryArgs","records","searchResults","hasResolved","searchHasResolved","type","slug","suggestions","setSuggestions","newSuggestions","length","recordNamePath","SuggestionList","orientation","setSearch","debouncedSearch","labels","showSearchControl","setShowSearchControl","search_items","map","not_found","AddCustomTemplateModal","onClose","showSearchEntities","setShowSearchEntities","hasGeneralTemplate","singular_name","title","description","template","all_items"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AACA;;AAYA;;AACA;;AAKA;;AAvBA;AACA;AACA;;AAkBA;AACA;AACA;AAGA,MAAMA,WAAW,GAAG,EAApB;;AAEA,SAASC,kBAAT,OAMI;AAAA,MANyB;AAC5BC,IAAAA,UAD4B;AAE5BC,IAAAA,MAF4B;AAG5BC,IAAAA,QAH4B;AAI5BC,IAAAA,oBAJ4B;AAK5BC,IAAAA;AAL4B,GAMzB;AACH,QAAMC,YAAY,GACjB,8DADD;AAEA,SACC,4BAAC,mCAAD;AACC,IAAA,IAAI,EAAC,QADN;AAEC,IAAA,EAAE,EAAGC;AAFN,KAGMF,SAHN;AAIC,IAAA,SAAS,EAAGC,YAJb;AAKC,IAAA,OAAO,EAAG,MACTH,QAAQ,CACPC,oBAAoB,CAACI,MAArB,CAA4BC,mBAA5B,CACCR,UADD,CADO;AANV,MAaC;AAAM,IAAA,SAAS,EAAI,GAAGK,YAAc;AAApC,KACC,4BAAC,yBAAD;AAAe,IAAA,IAAI,EAAGL,UAAU,CAACS,IAAjC;AAAwC,IAAA,SAAS,EAAGR;AAApD,IADD,CAbD,EAgBGD,UAAU,CAACU,IAAX,IACD;AAAM,IAAA,SAAS,EAAI,GAAGL,YAAc;AAApC,KACGL,UAAU,CAACU,IADd,CAjBF,CADD;AAwBA;;AAED,SAASC,iBAAT,GAA6B;AAC5B,QAAM,CAA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AAO,EAAG,MAAM;AACf,YAAM;AAAEsB,QAAAA,IAAF;AAAQsB,QAAAA,KAAR;AAAeC,QAAAA;AAAf,UACLhD,oBAAoB,CAACiD,QADtB;AAEAlD,MAAAA,QAAQ,CAAE;AAAE0B,QAAAA,IAAF;AAAQsB,QAAAA,KAAR;AAAeC,QAAAA;AAAf,OAAF,CAAR;AACA;AAPF,KASC,4BAAC,8BAAD;AAAM,IAAA,EAAE,EAAC,MAAT;AAAgB,IAAA,MAAM,EAAG;AAAzB,KACGhD,oBAAoB,CAACmC,MAArB,CAA4Be,SAD/B,CATD,EAYC,4BAAC,8BAAD;AAAM,IAAA,EAAE,EAAC;AAAT,KAEE;AACA,gBAAI,eAAJ,CAHF,CAZD,CALD,EAwBC,4BAAC,oBAAD;AACC,IAAA,OAAO,MADR;AAEC,IAAA,EAAE,EAAG/C,kBAFN;AAGC,IAAA,OAAO,EAAG,MAAM;AACfyC,MAAAA,qBAAqB,CAAE,IAAF,CAArB;AACA;AALF,KAOC,4BAAC,8BAAD;AAAM,IAAA,EAAE,EAAC,MAAT;AAAgB,IAAA,MAAM,EAAG;AAAzB,KACG5C,oBAAoB,CAACmC,MAArB,CAA4BW,aAD/B,CAPD,EAUC,4BAAC,8BAAD;AAAM,IAAA,EAAE,EAAC;AAAT,KAEE;AACA,gBAAI,qBAAJ,CAHF,CAVD,CAxBD,CAND,CAXF,EA6DGH,kBAAkB,IACnB,qDACC,uCACG,cACD,+DADC,CADH,CADD,EAMC,4BAAC,cAAD;AACC,IAAA,oBAAoB,EAAG3C,oBADxB;AAEC,IAAA,QAAQ,EAAGD;AAFZ,IAND,CA9DF,CADD;AA6EA;;eAEc0C,sB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\tFlex,\n\tFlexItem,\n\tModal,\n\tSearchControl,\n\tTextHighlight,\n\t__experimentalText as Text,\n\t__unstableComposite as Composite,\n\t__unstableUseCompositeState as useCompositeState,\n\t__unstableCompositeItem as CompositeItem,\n} from '@wordpress/components';\nimport { useDebounce } from '@wordpress/compose';\nimport { useEntityRecords } from '@wordpress/core-data';\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\tcomposite,\n} ) {\n\tconst baseCssClass =\n\t\t'edit-site-custom-template-modal__suggestions_list__list-item';\n\treturn (\n\t\t<CompositeItem\n\t\t\trole=\"option\"\n\t\t\tas={ Button }\n\t\t\t{ ...composite }\n\t\t\tclassName={ baseCssClass }\n\t\t\tonClick={ () =>\n\t\t\t\tonSelect(\n\t\t\t\t\tentityForSuggestions.config.getSpecificTemplate(\n\t\t\t\t\t\tsuggestion\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t}\n\t\t>\n\t\t\t<span className={ `${ baseCssClass }__title` }>\n\t\t\t\t<TextHighlight text={ suggestion.name } highlight={ search } />\n\t\t\t</span>\n\t\t\t{ suggestion.link && (\n\t\t\t\t<span className={ `${ baseCssClass }__info` }>\n\t\t\t\t\t{ suggestion.link }\n\t\t\t\t</span>\n\t\t\t) }\n\t\t</CompositeItem>\n\t);\n}\n\nfunction useDebouncedInput() {\n\tconst [ input, setInput ] = useState( '' );\n\tconst [ debounced, setter ] = useState( '' );\n\tconst setDebounced = useDebounce( setter, 250 );\n\tuseEffect( () => {\n\t\tif ( debounced !== input ) {\n\t\t\tsetDebounced( input );\n\t\t}\n\t}, [ debounced, input ] );\n\treturn [ input, setInput, debounced ];\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 ) return;\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 composite = useCompositeState( { orientation: 'vertical' } );\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\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\t{ ...composite }\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\tcomposite={ composite }\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<p className=\"edit-site-custom-template-modal__no-results\">\n\t\t\t\t\t{ labels.not_found }\n\t\t\t\t</p>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction AddCustomTemplateModal( { onClose, onSelect, entityForSuggestions } ) {\n\tconst [ showSearchEntities, setShowSearchEntities ] = useState(\n\t\tentityForSuggestions.hasGeneralTemplate\n\t);\n\tconst baseCssClass = 'edit-site-custom-template-modal';\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ sprintf(\n\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t__( 'Add template: %s' ),\n\t\t\t\tentityForSuggestions.labels.singular_name\n\t\t\t) }\n\t\t\tclassName={ baseCssClass }\n\t\t\tcloseLabel={ __( 'Close' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t>\n\t\t\t{ ! showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<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</p>\n\t\t\t\t\t<Flex\n\t\t\t\t\t\tclassName={ `${ baseCssClass }__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 { slug, title, description } =\n\t\t\t\t\t\t\t\t\tentityForSuggestions.template;\n\t\t\t\t\t\t\t\tonSelect( { slug, title, description } );\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Text as=\"span\" weight={ 600 }>\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 as=\"span\">\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 as=\"span\" weight={ 600 }>\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 as=\"span\">\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</>\n\t\t\t) }\n\t\t\t{ showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<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</p>\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</>\n\t\t\t) }\n\t\t</Modal>\n\t);\n}\n\nexport default AddCustomTemplateModal;\n"]}
1
+ {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/add-custom-template-modal.js"],"names":["EMPTY_ARRAY","SuggestionListItem","suggestion","search","onSelect","entityForSuggestions","composite","baseCssClass","Button","config","getSpecificTemplate","name","link","useDebouncedInput","input","setInput","debounced","setter","setDebounced","useSearchSuggestions","query","order","context","per_page","queryArgs","records","searchResults","hasResolved","searchHasResolved","type","slug","suggestions","setSuggestions","newSuggestions","length","recordNamePath","SuggestionList","orientation","setSearch","debouncedSearch","labels","showSearchControl","setShowSearchControl","search_items","map","not_found","AddCustomTemplateModal","onClose","showSearchEntities","setShowSearchEntities","hasGeneralTemplate","singular_name","title","description","templatePrefix","template","all_items"],"mappings":";;;;;;;;;AAGA;;;;AACA;;AACA;;AAYA;;AACA;;AAKA;;AAvBA;AACA;AACA;;AAkBA;AACA;AACA;AAGA,MAAMA,WAAW,GAAG,EAApB;;AAEA,SAASC,kBAAT,OAMI;AAAA,MANyB;AAC5BC,IAAAA,UAD4B;AAE5BC,IAAAA,MAF4B;AAG5BC,IAAAA,QAH4B;AAI5BC,IAAAA,oBAJ4B;AAK5BC,IAAAA;AAL4B,GAMzB;AACH,QAAMC,YAAY,GACjB,8DADD;AAEA,SACC,4BAAC,mCAAD;AACC,IAAA,IAAI,EAAC,QADN;AAEC,IAAA,EAAE,EAAGC;AAFN,KAGMF,SAHN;AAIC,IAAA,SAAS,EAAGC,YAJb;AAKC,IAAA,OAAO,EAAG,MACTH,QAAQ,CACPC,oBAAoB,CAACI,MAArB,CAA4BC,mBAA5B,CACCR,UADD,CADO;AANV,MAaC;A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qDACC,uCACG,cACD,+DADC,CADH,CADD,EAMC,4BAAC,cAAD;AACC,IAAA,oBAAoB,EAAG3C,oBADxB;AAEC,IAAA,QAAQ,EAAGD;AAFZ,IAND,CAvEF,CADD;AAsFA;;eAEc0C,sB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tButton,\n\tFlex,\n\tFlexItem,\n\tModal,\n\tSearchControl,\n\tTextHighlight,\n\t__experimentalText as Text,\n\t__unstableComposite as Composite,\n\t__unstableUseCompositeState as useCompositeState,\n\t__unstableCompositeItem as CompositeItem,\n} from '@wordpress/components';\nimport { useDebounce } from '@wordpress/compose';\nimport { useEntityRecords } from '@wordpress/core-data';\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\tcomposite,\n} ) {\n\tconst baseCssClass =\n\t\t'edit-site-custom-template-modal__suggestions_list__list-item';\n\treturn (\n\t\t<CompositeItem\n\t\t\trole=\"option\"\n\t\t\tas={ Button }\n\t\t\t{ ...composite }\n\t\t\tclassName={ baseCssClass }\n\t\t\tonClick={ () =>\n\t\t\t\tonSelect(\n\t\t\t\t\tentityForSuggestions.config.getSpecificTemplate(\n\t\t\t\t\t\tsuggestion\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t}\n\t\t>\n\t\t\t<span className={ `${ baseCssClass }__title` }>\n\t\t\t\t<TextHighlight text={ suggestion.name } highlight={ search } />\n\t\t\t</span>\n\t\t\t{ suggestion.link && (\n\t\t\t\t<span className={ `${ baseCssClass }__info` }>\n\t\t\t\t\t{ suggestion.link }\n\t\t\t\t</span>\n\t\t\t) }\n\t\t</CompositeItem>\n\t);\n}\n\nfunction useDebouncedInput() {\n\tconst [ input, setInput ] = useState( '' );\n\tconst [ debounced, setter ] = useState( '' );\n\tconst setDebounced = useDebounce( setter, 250 );\n\tuseEffect( () => {\n\t\tif ( debounced !== input ) {\n\t\t\tsetDebounced( input );\n\t\t}\n\t}, [ debounced, input ] );\n\treturn [ input, setInput, debounced ];\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 ) return;\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 composite = useCompositeState( { orientation: 'vertical' } );\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\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\t{ ...composite }\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\tcomposite={ composite }\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<p className=\"edit-site-custom-template-modal__no-results\">\n\t\t\t\t\t{ labels.not_found }\n\t\t\t\t</p>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction AddCustomTemplateModal( { onClose, onSelect, entityForSuggestions } ) {\n\tconst [ showSearchEntities, setShowSearchEntities ] = useState(\n\t\tentityForSuggestions.hasGeneralTemplate\n\t);\n\tconst baseCssClass = 'edit-site-custom-template-modal';\n\treturn (\n\t\t<Modal\n\t\t\ttitle={ sprintf(\n\t\t\t\t// translators: %s: Name of the post type e.g: \"Post\".\n\t\t\t\t__( 'Add template: %s' ),\n\t\t\t\tentityForSuggestions.labels.singular_name\n\t\t\t) }\n\t\t\tclassName={ baseCssClass }\n\t\t\tcloseLabel={ __( 'Close' ) }\n\t\t\tonRequestClose={ onClose }\n\t\t>\n\t\t\t{ ! showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<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</p>\n\t\t\t\t\t<Flex\n\t\t\t\t\t\tclassName={ `${ baseCssClass }__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 as=\"span\" weight={ 600 }>\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 as=\"span\">\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 as=\"span\" weight={ 600 }>\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 as=\"span\">\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</>\n\t\t\t) }\n\t\t\t{ showSearchEntities && (\n\t\t\t\t<>\n\t\t\t\t\t<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</p>\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</>\n\t\t\t) }\n\t\t</Modal>\n\t);\n}\n\nexport default AddCustomTemplateModal;\n"]}
@@ -9,6 +9,10 @@ exports.default = NewTemplate;
9
9
 
10
10
  var _element = require("@wordpress/element");
11
11
 
12
+ var _apiFetch = _interopRequireDefault(require("@wordpress/api-fetch"));
13
+
14
+ var _url = require("@wordpress/url");
15
+
12
16
  var _components = require("@wordpress/components");
13
17
 
14
18
  var _data = require("@wordpress/data");
@@ -80,14 +84,29 @@ function NewTemplate(_ref) {
80
84
  const {
81
85
  title,
82
86
  description,
83
- slug
87
+ slug,
88
+ templatePrefix
84
89
  } = template;
90
+ let templateContent = template.content; // Try to find fallback content from existing templates.
91
+
92
+ if (!templateContent) {
93
+ const fallbackTemplate = await (0, _apiFetch.default)({
94
+ path: (0, _url.addQueryArgs)('/wp/v2/templates/lookup', {
95
+ slug,
96
+ is_custom: !isWPSuggestion,
97
+ template_prefix: templatePrefix
98
+ })
99
+ });
100
+ templateContent = fallbackTemplate.content;
101
+ }
102
+
85
103
  const newTemplate = await saveEntityRecord('postType', 'wp_template', {
86
104
  description,
87
105
  // Slugs need to be strings, so this is for template `404`
88
106
  slug: slug.toString(),
89
107
  status: 'publish',
90
108
  title,
109
+ content: templateContent,
91
110
  // This adds a post meta field in template that is part of `is_custom` value calculation.
92
111
  is_wp_suggestion: isWPSuggestion
93
112
  }, {
@@ -189,7 +208,8 @@ function useMissingTemplates(setEntityForSuggestions, setShowCustomTemplateModal
189
208
  defaultPostTypesMenuItems,
190
209
  postTypesMenuItems
191
210
  } = (0, _utils.usePostTypeMenuItems)(onClickMenuItem);
192
- [...defaultTaxonomiesMenuItems, ...defaultPostTypesMenuItems].forEach(menuItem => {
211
+ const authorMenuItem = (0, _utils.useAuthorMenuItem)(onClickMenuItem);
212
+ [...defaultTaxonomiesMenuItems, ...defaultPostTypesMenuItems, authorMenuItem].forEach(menuItem => {
193
213
  if (!menuItem) {
194
214
  return;
195
215
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","home","single","post","page","archive","search","notFound","index","list","category","author","postAuthor","taxonomy","blockMeta","date","postDate","tag","attachment","media","NewTemplate","postType","showCustomTemplateModal","setShowCustomTemplateModal","showCustomGenericTemplateModal","setShowCustomGenericTemplateModal","entityForSuggestions","setEntityForSuggestions","history","saveEntityRecord","coreStore","createErrorNotice","noticesStore","setTemplate","editSiteStore","createTemplate","template","isWPSuggestion","title","description","slug","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","customGenericTemplateIcon","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","forEach","menuItem","matchIndex","findIndex","sort","template1","template2","indexOf"],"mappings":";;;;;;;;;AASA;;AANA;;AAOA;;AACA;;AACA;;AAgBA;;AACA;;AAKA;;AACA;;AAMA;;AACA;;AACA;;AA3CA;AACA;AACA;;AA6BA;AACA;AACA;AAYA,MAAMA,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,gBAAcC,WADQ;AAEtBC,EAAAA,MAAM,EAAEC,WAFc;AAGtBC,EAAAA,IAAI,EAAJA,WAHsB;AAItBC,EAAAA,OAAO,EAAPA,cAJsB;AAKtBC,EAAAA,MAAM,EAANA,aALsB;AAMtB,OAAKC,eANiB;AAOtBC,EAAAA,KAAK,EAAEC,WAPe;AAQtBC,EAAAA,QAAQ,EAARA,eARsB;AAStBC,EAAAA,MAAM,EAAEC,iBATc;AAUtBC,EAAAA,QAAQ,EAAEC,gBAVY;AAWtBC,EAAAA,IAAI,EAAEC,eAXgB;AAYtBC,EAAAA,GAAG,EAAHA,UAZsB;AAatBC,EAAAA,UAAU,EAAEC;AAbU,CAAvB;;AAgBe,SAASC,WAAT,OAAqC;AAAA,MAAf;AAAEC,IAAAA;AAAF,GAAe;AACnD,QAAM,CAAEC,uBAAF,EAA2BC,0BAA3B,IACL,uBAAU,KAAV,CADD;AAEA,QAAM,CACLC,8BADK,EAELC,iCAFK,IAGF,uBAAU,KAAV,CAHJ;AAIA,QAAM,CAAE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AeD;AACA;AACA;AACA;;;AACA,QAAMC,mCAAmC,GAAG,CAAE,GAAGL,uBAAL,CAA5C;AACA,QAAM;AAAEM,IAAAA,0BAAF;AAA8BC,IAAAA;AAA9B,MACL,mCAAwBJ,eAAxB,CADD;AAEA,QAAM;AAAEK,IAAAA,yBAAF;AAA6BC,IAAAA;AAA7B,MACL,iCAAsBN,eAAtB,CADD;AAEA,GAAE,GAAGG,0BAAL,EAAiC,GAAGE,yBAApC,EAAgEE,OAAhE,CACGC,QAAF,IAAgB;AACf,QAAK,CAAEA,QAAP,EAAkB;AACjB;AACA;;AACD,UAAMC,UAAU,GAAGP,mCAAmC,CAACQ,SAApC,CAChB9C,QAAF,IAAgBA,QAAQ,CAACI,IAAT,KAAkBwC,QAAQ,CAACxC,IADzB,CAAnB,CAJe,CAOf;AACA;AACA;AACA;AACA;;AACA,QAAKyC,UAAU,GAAG,CAAC,CAAnB,EAAuB;AACtBP,MAAAA,mCAAmC,CAAEO,UAAF,CAAnC,GAAoDD,QAApD;AACA,KAFD,MAEO;AACNN,MAAAA,mCAAmC,CAAC3B,IAApC,CAA0CiC,QAA1C;AACA;AACD,GAlBF,EAxBC,CA4CD;;AACAN,EAAAA,mCAAmC,SAAnC,IAAAA,mCAAmC,WAAnC,YAAAA,mCAAmC,CAAES,IAArC,CAA2C,CAAEC,SAAF,EAAaC,SAAb,KAA4B;AACtE,WACCtF,sBAAsB,CAACuF,OAAvB,CAAgCF,SAAS,CAAC5C,IAA1C,IACAzC,sBAAsB,CAACuF,OAAvB,CAAgCD,SAAS,CAAC7C,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMc,gBAAgB,GAAG,CACxB,GAAGoB,mCADqB,EAExB,GAAGI,kBAFqB,EAGxB,GAAGF,mBAHqB,CAAzB;AAKA,SAAOtB,gBAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\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} 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 } = template;\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\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\t[ ...defaultTaxonomiesMenuItems, ...defaultPostTypesMenuItems ].forEach(\n\t\t( menuItem ) => {\n\t\t\tif ( ! menuItem ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(\n\t\t\t\t( template ) => template.slug === menuItem.slug\n\t\t\t);\n\t\t\t// Some default template types might have been filtered above from\n\t\t\t// `missingDefaultTemplates` because they only check for the general\n\t\t\t// template. So here we either replace or append the item, augmented\n\t\t\t// with the check if it has available specific item to create a\n\t\t\t// template for.\n\t\t\tif ( matchIndex > -1 ) {\n\t\t\t\tenhancedMissingDefaultTemplateTypes[ matchIndex ] = menuItem;\n\t\t\t} else {\n\t\t\t\tenhancedMissingDefaultTemplateTypes.push( menuItem );\n\t\t\t}\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":["DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","home","single","post","page","archive","search","notFound","index","list","category","author","postAuthor","taxonomy","blockMeta","date","postDate","tag","attachment","media","NewTemplate","postType","showCustomTemplateModal","setShowCustomTemplateModal","showCustomGenericTemplateModal","setShowCustomGenericTemplateModal","entityForSuggestions","setEntityForSuggestions","history","saveEntityRecord","coreStore","createErrorNotice","noticesStore","setTemplate","editSiteStore","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","customGenericTemplateIcon","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","authorMenuItem","forEach","menuItem","matchIndex","findIndex","sort","template1","template2","indexOf"],"mappings":";;;;;;;;;AAWA;;AARA;;AACA;;AACA;;AAOA;;AACA;;AACA;;AAgBA;;AACA;;AAKA;;AACA;;AAOA;;AACA;;AACA;;AA9CA;AACA;AACA;;AA+BA;AACA;AACA;AAaA,MAAMA,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,gBAAcC,WADQ;AAEtBC,EAAAA,MAAM,EAAEC,WAFc;AAGtBC,EAAAA,IAAI,EAAJA,WAHsB;AAItBC,EAAAA,OAAO,EAAPA,cAJsB;AAKtBC,EAAAA,MAAM,EAANA,aALsB;AAMtB,OAAKC,eANiB;AAOtBC,EAAAA,KAAK,EAAEC,WAPe;AAQtBC,EAAAA,QAAQ,EAARA,eARsB;AAStBC,EAAAA,MAAM,EAAEC,iBATc;AAUtBC,EAAAA,QAAQ,EAAEC,gBAVY;AAWtBC,EAAAA,IAAI,EAAEC,e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AAkBgD,QAAQ,CAAChD,IADzB,CAAnB,CAJ0B,CAO1B;AACA;AACA;AACA;AACA;;AACA,QAAKiD,UAAU,GAAG,CAAC,CAAnB,EAAuB;AACtBR,MAAAA,mCAAmC,CAAEQ,UAAF,CAAnC,GAAoDD,QAApD;AACA,KAFD,MAEO;AACNP,MAAAA,mCAAmC,CAAC3B,IAApC,CAA0CkC,QAA1C;AACA;AACD,GArBD,EA1BC,CAgDD;;AACAP,EAAAA,mCAAmC,SAAnC,IAAAA,mCAAmC,WAAnC,YAAAA,mCAAmC,CAAEU,IAArC,CAA2C,CAAEC,SAAF,EAAaC,SAAb,KAA4B;AACtE,WACC9F,sBAAsB,CAAC+F,OAAvB,CAAgCF,SAAS,CAACpD,IAA1C,IACAzC,sBAAsB,CAAC+F,OAAvB,CAAgCD,SAAS,CAACrD,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMqB,gBAAgB,GAAG,CACxB,GAAGoB,mCADqB,EAExB,GAAGI,kBAFqB,EAGxB,GAAGF,mBAHqB,CAAzB;AAKA,SAAOtB,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"]}
@@ -3,7 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.useTaxonomiesMenuItems = exports.usePostTypeMenuItems = exports.useExistingTemplates = exports.useDefaultTemplateTypes = exports.mapToIHasNameAndId = void 0;
6
+ exports.mapToIHasNameAndId = void 0;
7
+ exports.useAuthorMenuItem = useAuthorMenuItem;
8
+ exports.useTaxonomiesMenuItems = exports.usePostTypeMenuItems = exports.useExistingTemplates = exports.useDefaultTemplateTypes = void 0;
7
9
 
8
10
  var _lodash = require("lodash");
9
11
 
@@ -173,7 +175,8 @@ const usePostTypeMenuItems = onClickMenuItem => {
173
175
  (0, _i18n.__)('Single item: %1$s (%2$s)'), labels.singular_name, slug);
174
176
  }
175
177
 
176
- const menuItem = defaultTemplateType ? { ...defaultTemplateType
178
+ const menuItem = defaultTemplateType ? { ...defaultTemplateType,
179
+ templatePrefix: templatePrefixes[slug]
177
180
  } : {
178
181
  slug: generalTemplateSlug,
179
182
  title: menuItemTitle,
@@ -182,7 +185,8 @@ const usePostTypeMenuItems = onClickMenuItem => {
182
185
  // `icon` is the `menu_icon` property of a post type. We
183
186
  // only handle `dashicons` for now, even if the `menu_icon`
184
187
  // also supports urls and svg as values.
185
- icon: icon !== null && icon !== void 0 && icon.startsWith('dashicons-') ? icon.slice(10) : _icons.post
188
+ icon: icon !== null && icon !== void 0 && icon.startsWith('dashicons-') ? icon.slice(10) : _icons.post,
189
+ templatePrefix: templatePrefixes[slug]
186
190
  };
187
191
  const hasEntities = postTypesInfo === null || postTypesInfo === void 0 ? void 0 : (_postTypesInfo$slug = postTypesInfo[slug]) === null || _postTypesInfo$slug === void 0 ? void 0 : _postTypesInfo$slug.hasEntities; // We have a different template creation flow only if they have entities.
188
192
 
@@ -211,13 +215,14 @@ const usePostTypeMenuItems = onClickMenuItem => {
211
215
 
212
216
  if (_needsUniqueIdentifier) {
213
217
  title = (0, _i18n.sprintf)( // translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the template title and %2$s is the slug of the post type, e.g. "Project: Hello (project_type)"
214
- (0, _i18n.__)('%1$s %2$s'), title, `(${slug})`);
218
+ (0, _i18n.__)('%1$s (%2$s)'), title, slug);
215
219
  }
216
220
 
217
221
  return {
218
222
  title,
219
223
  description,
220
- slug: `${templatePrefixes[slug]}-${suggestion.slug}`
224
+ slug: `${templatePrefixes[slug]}-${suggestion.slug}`,
225
+ templatePrefix: templatePrefixes[slug]
221
226
  };
222
227
  }
223
228
  },
@@ -336,13 +341,15 @@ const useTaxonomiesMenuItems = onClickMenuItem => {
336
341
  (0, _i18n.__)('%1$s (%2$s)'), labels.singular_name, slug);
337
342
  }
338
343
 
339
- const menuItem = defaultTemplateType ? { ...defaultTemplateType
344
+ const menuItem = defaultTemplateType ? { ...defaultTemplateType,
345
+ templatePrefix: templatePrefixes[slug]
340
346
  } : {
341
347
  slug: generalTemplateSlug,
342
348
  title: menuItemTitle,
343
349
  description: (0, _i18n.sprintf)( // translators: %s: Name of the taxonomy e.g: "Product Categories".
344
350
  (0, _i18n.__)('Displays taxonomy: %s.'), labels.singular_name),
345
- icon: _icons.blockMeta
351
+ icon: _icons.blockMeta,
352
+ templatePrefix: templatePrefixes[slug]
346
353
  };
347
354
  const hasEntities = taxonomiesInfo === null || taxonomiesInfo === void 0 ? void 0 : (_taxonomiesInfo$slug = taxonomiesInfo[slug]) === null || _taxonomiesInfo$slug === void 0 ? void 0 : _taxonomiesInfo$slug.hasEntities; // We have a different template creation flow only if they have entities.
348
355
 
@@ -370,13 +377,14 @@ const useTaxonomiesMenuItems = onClickMenuItem => {
370
377
 
371
378
  if (_needsUniqueIdentifier) {
372
379
  title = (0, _i18n.sprintf)( // translators: Represents the title of a user's custom template in the Site Editor, where %1$s is the template title and %2$s is the slug of the taxonomy, e.g. "Category: shoes (product_tag)"
373
- (0, _i18n.__)('%1$s %2$s'), title, `(${slug})`);
380
+ (0, _i18n.__)('%1$s (%2$s)'), title, slug);
374
381
  }
375
382
 
376
383
  return {
377
384
  title,
378
385
  description,
379
- slug: `${templatePrefixes[slug]}-${suggestion.slug}`
386
+ slug: `${templatePrefixes[slug]}-${suggestion.slug}`,
387
+ templatePrefix: templatePrefixes[slug]
380
388
  };
381
389
  }
382
390
  },
@@ -415,14 +423,126 @@ const useTaxonomiesMenuItems = onClickMenuItem => {
415
423
  }), [menuItems]);
416
424
  return taxonomiesMenuItems;
417
425
  };
426
+
427
+ exports.useTaxonomiesMenuItems = useTaxonomiesMenuItems;
428
+
429
+ function useAuthorNeedsUniqueIndentifier() {
430
+ const authors = (0, _data.useSelect)(select => select(_coreData.store).getUsers({
431
+ who: 'authors',
432
+ per_page: -1
433
+ }), []);
434
+ const authorsCountByName = (0, _element.useMemo)(() => {
435
+ return (authors || []).reduce((authorsCount, _ref13) => {
436
+ let {
437
+ name
438
+ } = _ref13;
439
+ authorsCount[name] = (authorsCount[name] || 0) + 1;
440
+ return authorsCount;
441
+ }, {});
442
+ }, [authors]);
443
+ return (0, _element.useCallback)(name => {
444
+ return authorsCountByName[name] > 1;
445
+ }, [authorsCountByName]);
446
+ }
447
+
448
+ const USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX = {
449
+ user: 'author'
450
+ };
451
+ const USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS = {
452
+ user: {
453
+ who: 'authors'
454
+ }
455
+ };
456
+
457
+ function useAuthorMenuItem(onClickMenuItem) {
458
+ var _authorInfo$user, _authorInfo$user2;
459
+
460
+ const existingTemplates = useExistingTemplates();
461
+ const defaultTemplateTypes = useDefaultTemplateTypes();
462
+ const authorInfo = useEntitiesInfo('root', USE_AUTHOR_MENU_ITEM_TEMPLATE_PREFIX, USE_AUTHOR_MENU_ITEM_QUERY_PARAMETERS);
463
+ const authorNeedsUniqueId = useAuthorNeedsUniqueIndentifier();
464
+ let authorMenuItem = defaultTemplateTypes === null || defaultTemplateTypes === void 0 ? void 0 : defaultTemplateTypes.find(_ref14 => {
465
+ let {
466
+ slug
467
+ } = _ref14;
468
+ return slug === 'author';
469
+ });
470
+
471
+ if (!authorMenuItem) {
472
+ authorMenuItem = {
473
+ description: (0, _i18n.__)('Displays latest posts written by a single author.'),
474
+ slug: 'author',
475
+ title: 'Author'
476
+ };
477
+ }
478
+
479
+ const hasGeneralTemplate = !!(existingTemplates !== null && existingTemplates !== void 0 && existingTemplates.find(_ref15 => {
480
+ let {
481
+ slug
482
+ } = _ref15;
483
+ return slug === 'author';
484
+ }));
485
+
486
+ if ((_authorInfo$user = authorInfo.user) !== null && _authorInfo$user !== void 0 && _authorInfo$user.hasEntities) {
487
+ authorMenuItem = { ...authorMenuItem,
488
+ templatePrefix: 'author'
489
+ };
490
+
491
+ authorMenuItem.onClick = template => {
492
+ onClickMenuItem({
493
+ type: 'root',
494
+ slug: 'user',
495
+ config: {
496
+ queryArgs: _ref16 => {
497
+ let {
498
+ search
499
+ } = _ref16;
500
+ return {
501
+ _fields: 'id,name,slug,link',
502
+ orderBy: search ? 'name' : 'registered_date',
503
+ exclude: authorInfo.user.existingEntitiesIds,
504
+ who: 'authors'
505
+ };
506
+ },
507
+ getSpecificTemplate: suggestion => {
508
+ const needsUniqueId = authorNeedsUniqueId(suggestion.name);
509
+ const title = needsUniqueId ? (0, _i18n.sprintf)( // translators: %1$s: Represents the name of an author e.g: "Jorge", %2$s: Represents the slug of an author e.g: "author-jorge-slug".
510
+ (0, _i18n.__)('Author: %1$s (%2$s)'), suggestion.name, suggestion.slug) : (0, _i18n.sprintf)( // translators: %s: Represents the name of an author e.g: "Jorge".
511
+ (0, _i18n.__)('Author: %s'), suggestion.name);
512
+ const description = (0, _i18n.sprintf)( // translators: %s: Represents the name of an author e.g: "Jorge".
513
+ (0, _i18n.__)('Template for Author: %s'), suggestion.name);
514
+ return {
515
+ title,
516
+ description,
517
+ slug: `author-${suggestion.slug}`,
518
+ templatePrefix: 'author'
519
+ };
520
+ }
521
+ },
522
+ labels: {
523
+ singular_name: (0, _i18n.__)('Author'),
524
+ search_items: (0, _i18n.__)('Search Authors'),
525
+ not_found: (0, _i18n.__)('No authors found.'),
526
+ all_items: (0, _i18n.__)('All Authors')
527
+ },
528
+ hasGeneralTemplate,
529
+ template
530
+ });
531
+ };
532
+ }
533
+
534
+ if (!hasGeneralTemplate || (_authorInfo$user2 = authorInfo.user) !== null && _authorInfo$user2 !== void 0 && _authorInfo$user2.hasEntities) {
535
+ return authorMenuItem;
536
+ }
537
+ }
418
538
  /**
419
539
  * Helper hook that filters all the existing templates by the given
420
540
  * object with the entity's slug as key and the template prefix as value.
421
541
  *
422
542
  * Example:
423
- * `existingTemplates` is: [ { slug: tag-apple }, { slug: page-about }, { slug: tag } ]
543
+ * `existingTemplates` is: [ { slug: 'tag-apple' }, { slug: 'page-about' }, { slug: 'tag' } ]
424
544
  * `templatePrefixes` is: { post_tag: 'tag' }
425
- * It will return: { post_tag: [apple] }
545
+ * It will return: { post_tag: ['apple'] }
426
546
  *
427
547
  * Note: We append the `-` to the given template prefix in this function for our checks.
428
548
  *
@@ -431,13 +551,11 @@ const useTaxonomiesMenuItems = onClickMenuItem => {
431
551
  */
432
552
 
433
553
 
434
- exports.useTaxonomiesMenuItems = useTaxonomiesMenuItems;
435
-
436
554
  const useExistingTemplateSlugs = templatePrefixes => {
437
555
  const existingTemplates = useExistingTemplates();
438
556
  const existingSlugs = (0, _element.useMemo)(() => {
439
- return Object.entries(templatePrefixes || {}).reduce((accumulator, _ref13) => {
440
- let [slug, prefix] = _ref13;
557
+ return Object.entries(templatePrefixes || {}).reduce((accumulator, _ref17) => {
558
+ let [slug, prefix] = _ref17;
441
559
  const slugsWithTemplates = (existingTemplates || []).reduce((_accumulator, existingTemplate) => {
442
560
  const _prefix = `${prefix}-`;
443
561
 
@@ -461,21 +579,24 @@ const useExistingTemplateSlugs = templatePrefixes => {
461
579
  * Helper hook that finds the existing records with an associated template,
462
580
  * as they need to be excluded from the template suggestions.
463
581
  *
464
- * @param {string} entityName The entity's name.
465
- * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
582
+ * @param {string} entityName The entity's name.
583
+ * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
584
+ * @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.
466
585
  * @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the existing records as value.
467
586
  */
468
587
 
469
588
 
470
- const useTemplatesToExclude = (entityName, templatePrefixes) => {
589
+ const useTemplatesToExclude = function (entityName, templatePrefixes) {
590
+ let additionalQueryParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
471
591
  const slugsToExcludePerEntity = useExistingTemplateSlugs(templatePrefixes);
472
592
  const recordsToExcludePerEntity = (0, _data.useSelect)(select => {
473
- return Object.entries(slugsToExcludePerEntity || {}).reduce((accumulator, _ref14) => {
474
- let [slug, slugsWithTemplates] = _ref14;
593
+ return Object.entries(slugsToExcludePerEntity || {}).reduce((accumulator, _ref18) => {
594
+ let [slug, slugsWithTemplates] = _ref18;
475
595
  const entitiesWithTemplates = select(_coreData.store).getEntityRecords(entityName, slug, {
476
596
  _fields: 'id',
477
597
  context: 'view',
478
- slug: slugsWithTemplates
598
+ slug: slugsWithTemplates,
599
+ ...additionalQueryParameters[slug]
479
600
  });
480
601
 
481
602
  if (entitiesWithTemplates !== null && entitiesWithTemplates !== void 0 && entitiesWithTemplates.length) {
@@ -497,22 +618,24 @@ const useTemplatesToExclude = (entityName, templatePrefixes) => {
497
618
  * First we need to find the existing records with an associated template,
498
619
  * to query afterwards for any remaining record, by excluding them.
499
620
  *
500
- * @param {string} entityName The entity's name.
501
- * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
621
+ * @param {string} entityName The entity's name.
622
+ * @param {Record<string,string>} templatePrefixes An object with the entity's slug as key and the template prefix as value.
623
+ * @param {Record<string,Object>} additionalQueryParameters An object with the entity's slug as key and additional query parameters as value.
502
624
  * @return {Record<string,EntitiesInfo>} An object with the entity's slug as key and the EntitiesInfo as value.
503
625
  */
504
626
 
505
627
 
506
- const useEntitiesInfo = (entityName, templatePrefixes) => {
507
- const recordsToExcludePerEntity = useTemplatesToExclude(entityName, templatePrefixes);
628
+ const useEntitiesInfo = function (entityName, templatePrefixes) {
629
+ let additionalQueryParameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
630
+ const recordsToExcludePerEntity = useTemplatesToExclude(entityName, templatePrefixes, additionalQueryParameters);
508
631
  const entitiesInfo = (0, _data.useSelect)(select => {
509
632
  return Object.keys(templatePrefixes || {}).reduce((accumulator, slug) => {
510
633
  var _recordsToExcludePerE, _select$getEntityReco;
511
634
 
512
- const existingEntitiesIds = (recordsToExcludePerEntity === null || recordsToExcludePerEntity === void 0 ? void 0 : (_recordsToExcludePerE = recordsToExcludePerEntity[slug]) === null || _recordsToExcludePerE === void 0 ? void 0 : _recordsToExcludePerE.map(_ref15 => {
635
+ const existingEntitiesIds = (recordsToExcludePerEntity === null || recordsToExcludePerEntity === void 0 ? void 0 : (_recordsToExcludePerE = recordsToExcludePerEntity[slug]) === null || _recordsToExcludePerE === void 0 ? void 0 : _recordsToExcludePerE.map(_ref19 => {
513
636
  let {
514
637
  id
515
- } = _ref15;
638
+ } = _ref19;
516
639
  return id;
517
640
  })) || [];
518
641
  accumulator[slug] = {
@@ -520,7 +643,8 @@ const useEntitiesInfo = (entityName, templatePrefixes) => {
520
643
  per_page: 1,
521
644
  _fields: 'id',
522
645
  context: 'view',
523
- exclude: existingEntitiesIds
646
+ exclude: existingEntitiesIds,
647
+ ...additionalQueryParameters[slug]
524
648
  })) !== null && _select$getEntityReco !== void 0 && _select$getEntityReco.length),
525
649
  existingEntitiesIds
526
650
  };