@wordpress/edit-site 5.3.7 → 5.3.8
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/build/components/add-new-template/new-template.js +16 -10
- package/build/components/add-new-template/new-template.js.map +1 -1
- package/build/components/sidebar-navigation-screen-navigation-menus/index.js +1 -40
- package/build/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
- package/build/components/style-book/index.js +134 -19
- package/build/components/style-book/index.js.map +1 -1
- package/build-module/components/add-new-template/new-template.js +18 -11
- package/build-module/components/add-new-template/new-template.js.map +1 -1
- package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js +2 -39
- package/build-module/components/sidebar-navigation-screen-navigation-menus/index.js.map +1 -1
- package/build-module/components/style-book/index.js +135 -22
- package/build-module/components/style-book/index.js.map +1 -1
- package/build-style/style-rtl.css +16 -44
- package/build-style/style.css +16 -44
- package/package.json +10 -10
- package/src/components/add-new-template/new-template.js +57 -32
- package/src/components/add-new-template/style.scss +12 -1
- package/src/components/sidebar-navigation-screen-navigation-menus/index.js +3 -40
- package/src/components/sidebar-navigation-screen-navigation-menus/style.scss +4 -0
- package/src/components/site-hub/style.scss +1 -1
- package/src/components/style-book/index.js +209 -54
- package/src/components/style-book/style.scss +1 -45
|
@@ -5,7 +5,7 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
5
5
|
*/
|
|
6
6
|
import apiFetch from '@wordpress/api-fetch';
|
|
7
7
|
import { addQueryArgs } from '@wordpress/url';
|
|
8
|
-
import { DropdownMenu, MenuGroup, MenuItem,
|
|
8
|
+
import { DropdownMenu, MenuGroup, MenuItem, Tooltip, VisuallyHidden } from '@wordpress/components';
|
|
9
9
|
import { useState } from '@wordpress/element';
|
|
10
10
|
import { useDispatch } from '@wordpress/data';
|
|
11
11
|
import { store as coreStore } from '@wordpress/core-data';
|
|
@@ -132,6 +132,8 @@ export default function NewTemplate(_ref) {
|
|
|
132
132
|
return null;
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
+
const customTemplateDescription = __('A custom template can be manually applied to any post or page.');
|
|
136
|
+
|
|
135
137
|
return createElement(Fragment, null, createElement(DropdownMenu, {
|
|
136
138
|
className: "edit-site-new-template-dropdown",
|
|
137
139
|
icon: showIcon ? plus : null,
|
|
@@ -141,8 +143,8 @@ export default function NewTemplate(_ref) {
|
|
|
141
143
|
noArrow: false
|
|
142
144
|
},
|
|
143
145
|
toggleProps: toggleProps
|
|
144
|
-
}, () => createElement(Fragment, null, isCreatingTemplate && createElement(TemplateActionsLoadingScreen, null), createElement(
|
|
145
|
-
className: "edit-site-new-template-
|
|
146
|
+
}, () => createElement(Fragment, null, isCreatingTemplate && createElement(TemplateActionsLoadingScreen, null), createElement("div", {
|
|
147
|
+
className: "edit-site-new-template-dropdown__menu-groups"
|
|
146
148
|
}, createElement(MenuGroup, {
|
|
147
149
|
label: postType.labels.add_new_item
|
|
148
150
|
}, missingTemplates.map(template => {
|
|
@@ -153,20 +155,25 @@ export default function NewTemplate(_ref) {
|
|
|
153
155
|
onClick,
|
|
154
156
|
icon
|
|
155
157
|
} = template;
|
|
156
|
-
return createElement(
|
|
158
|
+
return createElement(Tooltip, {
|
|
159
|
+
key: slug,
|
|
160
|
+
position: "top right",
|
|
161
|
+
text: description,
|
|
162
|
+
className: "edit-site-new-template-dropdown__menu-item-tooltip"
|
|
163
|
+
}, createElement(MenuItem, {
|
|
157
164
|
icon: icon || TEMPLATE_ICONS[slug] || post,
|
|
158
165
|
iconPosition: "left",
|
|
159
|
-
info: description,
|
|
160
|
-
key: slug,
|
|
161
166
|
onClick: () => onClick ? onClick(template) : createTemplate(template)
|
|
162
|
-
}, title);
|
|
163
|
-
})), createElement(MenuGroup, null, createElement(
|
|
167
|
+
}, title, createElement(VisuallyHidden, null, description)));
|
|
168
|
+
})), createElement(MenuGroup, null, createElement(Tooltip, {
|
|
169
|
+
position: "top right",
|
|
170
|
+
text: customTemplateDescription,
|
|
171
|
+
className: "edit-site-new-template-dropdown__menu-item-tooltip"
|
|
172
|
+
}, createElement(MenuItem, {
|
|
164
173
|
icon: customGenericTemplateIcon,
|
|
165
174
|
iconPosition: "left",
|
|
166
|
-
info: __('Custom templates can be applied to any post or page.'),
|
|
167
|
-
key: "custom-template",
|
|
168
175
|
onClick: () => setShowCustomGenericTemplateModal(true)
|
|
169
|
-
}, __('Custom template')))))), showCustomTemplateModal && createElement(AddCustomTemplateModal, {
|
|
176
|
+
}, __('Custom template'), createElement(VisuallyHidden, null, customTemplateDescription))))))), showCustomTemplateModal && createElement(AddCustomTemplateModal, {
|
|
170
177
|
onClose: () => setShowCustomTemplateModal(false),
|
|
171
178
|
onSelect: createTemplate,
|
|
172
179
|
entityForSuggestions: entityForSuggestions,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["apiFetch","addQueryArgs","DropdownMenu","MenuGroup","MenuItem","NavigableMenu","useState","useDispatch","store","coreStore","archive","blockMeta","category","home","list","media","notFound","page","plus","post","postAuthor","postDate","search","tag","layout","customGenericTemplateIcon","__","sprintf","noticesStore","AddCustomTemplateModal","useExistingTemplates","useDefaultTemplateTypes","useTaxonomiesMenuItems","usePostTypeMenuItems","useAuthorMenuItem","usePostTypeArchiveMenuItems","AddCustomGenericTemplateModal","TemplateActionsLoadingScreen","useHistory","editSiteStore","unlock","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","single","index","author","taxonomy","date","attachment","NewTemplate","postType","toggleProps","showIcon","showCustomTemplateModal","setShowCustomTemplateModal","showCustomGenericTemplateModal","setShowCustomGenericTemplateModal","entityForSuggestions","setEntityForSuggestions","isCreatingTemplate","setIsCreatingTemplate","history","saveEntityRecord","createErrorNotice","createSuccessNotice","setTemplate","setCanvasMode","createTemplate","template","isWPSuggestion","title","description","slug","templatePrefix","templateContent","content","fallbackTemplate","path","is_custom","template_prefix","raw","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","map","onClick","icon","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","authorMenuItem","forEach","menuItem","matchIndex","findIndex","sort","template1","template2","indexOf"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SACCC,YADD,EAECC,SAFD,EAGCC,QAHD,EAICC,aAJD,QAKO,uBALP;AAMA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SACCC,OADD,EAECC,SAFD,EAGCC,QAHD,EAICC,IAJD,EAKCC,IALD,EAMCC,KAND,EAOCC,QAPD,EAQCC,IARD,EASCC,IATD,EAUCC,IAVD,EAWCC,UAXD,EAYCC,QAZD,EAaCC,MAbD,EAcCC,GAdD,EAeCC,MAAM,IAAIC,yBAfX,QAgBO,kBAhBP;AAiBA,SAASC,EAAT,EAAaC,OAAb,QAA4B,iBAA5B;AACA,SAASnB,KAAK,IAAIoB,YAAlB,QAAsC,oBAAtC;AAEA;AACA;AACA;;AACA,OAAOC,sBAAP,MAAmC,6BAAnC;AACA,SACCC,oBADD,EAECC,uBAFD,EAGCC,sBAHD,EAICC,oBAJD,EAKCC,iBALD,EAMCC,2BAND,QAOO,SAPP;AAQA,OAAOC,6BAAP,MAA0C,qCAA1C;AACA,OAAOC,4BAAP,MAAyC,mCAAzC;AACA,SAASC,UAAT,QAA2B,WAA3B;AACA,SAAS9B,KAAK,IAAI+B,aAAlB,QAAuC,aAAvC;AACA,SAASC,MAAT,QAAuB,oBAAvB;AAEA,MAAMC,sBAAsB,GAAG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EA,QAAP,EAAkB;AACjB;AACA;;AACD,UAAMC,UAAU,GAAGR,mCAAmC,CAACS,SAApC,CAChBrD,QAAF,IAAgBA,QAAQ,CAACI,IAAT,KAAkB+C,QAAQ,CAAC/C,IADzB,CAAnB,CAJ0B,CAO1B;AACA;AACA;AACA;AACA;;AACA,QAAKgD,UAAU,GAAG,CAAC,CAAnB,EAAuB;AACtBR,MAAAA,mCAAmC,CAAEQ,UAAF,CAAnC,GAAoDD,QAApD;AACA,KAFD,MAEO;AACNP,MAAAA,mCAAmC,CAACzB,IAApC,CAA0CgC,QAA1C;AACA;AACD,GArBD,EA1BC,CAgDD;;AACAP,EAAAA,mCAAmC,SAAnC,IAAAA,mCAAmC,WAAnC,YAAAA,mCAAmC,CAAEU,IAArC,CAA2C,CAAEC,SAAF,EAAaC,SAAb,KAA4B;AACtE,WACCnF,sBAAsB,CAACoF,OAAvB,CAAgCF,SAAS,CAACnD,IAA1C,IACA/B,sBAAsB,CAACoF,OAAvB,CAAgCD,SAAS,CAACpD,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMsB,gBAAgB,GAAG,CACxB,GAAGkB,mCADqB,EAExB,GAAG7E,2BAA2B,EAFN,EAGxB,GAAGiF,kBAHqB,EAIxB,GAAGF,mBAJqB,CAAzB;AAMA,SAAOpB,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\tplus,\n\tpost,\n\tpostAuthor,\n\tpostDate,\n\tsearch,\n\ttag,\n\tlayout as customGenericTemplateIcon,\n} from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModal from './add-custom-template-modal';\nimport {\n\tuseExistingTemplates,\n\tuseDefaultTemplateTypes,\n\tuseTaxonomiesMenuItems,\n\tusePostTypeMenuItems,\n\tuseAuthorMenuItem,\n\tusePostTypeArchiveMenuItems,\n} from './utils';\nimport AddCustomGenericTemplateModal from './add-custom-generic-template-modal';\nimport TemplateActionsLoadingScreen from './template-actions-loading-screen';\nimport { useHistory } from '../routes';\nimport { store as editSiteStore } from '../../store';\nimport { unlock } from '../../private-apis';\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( {\n\tpostType,\n\ttoggleProps,\n\tshowIcon = true,\n} ) {\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\tconst [ isCreatingTemplate, setIsCreatingTemplate ] = useState( false );\n\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst { setTemplate, setCanvasMode } = unlock(\n\t\tuseDispatch( editSiteStore )\n\t);\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\tif ( isCreatingTemplate ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsCreatingTemplate( 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.raw;\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\t\t\t// Switch to edit mode.\n\t\t\tsetCanvasMode( 'edit' );\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\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the created template e.g: \"Category\".\n\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\ttitle\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t} finally {\n\t\t\tsetIsCreatingTemplate( false );\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={ showIcon ? plus : null }\n\t\t\t\ttext={ showIcon ? null : 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={ toggleProps }\n\t\t\t>\n\t\t\t\t{ () => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ isCreatingTemplate && (\n\t\t\t\t\t\t\t<TemplateActionsLoadingScreen />\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<NavigableMenu className=\"edit-site-new-template-dropdown__popover\">\n\t\t\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\t\tonClick,\n\t\t\t\t\t\t\t\t\t\ticon,\n\t\t\t\t\t\t\t\t\t} = template;\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\t\ticon ||\n\t\t\t\t\t\t\t\t\t\t\t\tTEMPLATE_ICONS[ slug ] ||\n\t\t\t\t\t\t\t\t\t\t\t\tpost\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\t\tinfo={ description }\n\t\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\t\tonClick\n\t\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\t: createTemplate( template )\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\ticon={ customGenericTemplateIcon }\n\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\tinfo={ __(\n\t\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\t) }\n\t\t\t\t\t\t\t\t\tkey=\"custom-template\"\n\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\tsetShowCustomGenericTemplateModal(\n\t\t\t\t\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t{ __( 'Custom template' ) }\n\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t</NavigableMenu>\n\t\t\t\t\t</>\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\tisCreatingTemplate={ isCreatingTemplate }\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\tisCreatingTemplate={ isCreatingTemplate }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates(\n\tsetEntityForSuggestions,\n\tsetShowCustomTemplateModal\n) {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter(\n\t\t( template ) =>\n\t\t\tDEFAULT_TEMPLATE_SLUGS.includes( template.slug ) &&\n\t\t\t! existingTemplateSlugs.includes( template.slug )\n\t);\n\tconst onClickMenuItem = ( _entityForSuggestions ) => {\n\t\tsetShowCustomTemplateModal( true );\n\t\tsetEntityForSuggestions( _entityForSuggestions );\n\t};\n\t// We need to replace existing default template types with\n\t// the create specific template functionality. The original\n\t// info (title, description, etc.) is preserved in the\n\t// used hooks.\n\tconst enhancedMissingDefaultTemplateTypes = [ ...missingDefaultTemplates ];\n\tconst { defaultTaxonomiesMenuItems, taxonomiesMenuItems } =\n\t\tuseTaxonomiesMenuItems( onClickMenuItem );\n\tconst { defaultPostTypesMenuItems, postTypesMenuItems } =\n\t\tusePostTypeMenuItems( onClickMenuItem );\n\n\tconst authorMenuItem = useAuthorMenuItem( onClickMenuItem );\n\t[\n\t\t...defaultTaxonomiesMenuItems,\n\t\t...defaultPostTypesMenuItems,\n\t\tauthorMenuItem,\n\t].forEach( ( menuItem ) => {\n\t\tif ( ! menuItem ) {\n\t\t\treturn;\n\t\t}\n\t\tconst matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(\n\t\t\t( template ) => template.slug === menuItem.slug\n\t\t);\n\t\t// Some default template types might have been filtered above from\n\t\t// `missingDefaultTemplates` because they only check for the general\n\t\t// template. So here we either replace or append the item, augmented\n\t\t// with the check if it has available specific item to create a\n\t\t// template for.\n\t\tif ( matchIndex > -1 ) {\n\t\t\tenhancedMissingDefaultTemplateTypes[ matchIndex ] = menuItem;\n\t\t} else {\n\t\t\tenhancedMissingDefaultTemplateTypes.push( menuItem );\n\t\t}\n\t} );\n\t// Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.\n\tenhancedMissingDefaultTemplateTypes?.sort( ( template1, template2 ) => {\n\t\treturn (\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template1.slug ) -\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template2.slug )\n\t\t);\n\t} );\n\tconst missingTemplates = [\n\t\t...enhancedMissingDefaultTemplateTypes,\n\t\t...usePostTypeArchiveMenuItems(),\n\t\t...postTypesMenuItems,\n\t\t...taxonomiesMenuItems,\n\t];\n\treturn missingTemplates;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/add-new-template/new-template.js"],"names":["apiFetch","addQueryArgs","DropdownMenu","MenuGroup","MenuItem","Tooltip","VisuallyHidden","useState","useDispatch","store","coreStore","archive","blockMeta","category","home","list","media","notFound","page","plus","post","postAuthor","postDate","search","tag","layout","customGenericTemplateIcon","__","sprintf","noticesStore","AddCustomTemplateModal","useExistingTemplates","useDefaultTemplateTypes","useTaxonomiesMenuItems","usePostTypeMenuItems","useAuthorMenuItem","usePostTypeArchiveMenuItems","AddCustomGenericTemplateModal","TemplateActionsLoadingScreen","useHistory","editSiteStore","unlock","DEFAULT_TEMPLATE_SLUGS","TEMPLATE_ICONS","single","index","author","taxonomy","date","attachment","NewTemplate","postType","toggleProps","showIcon","showCustomTemplateModal","setShowCustomTemplateModal","showCustomGenericTemplateModal","setShowCustomGenericTemplateModal","entityForSuggestions","setEntityForSuggestions","isCreatingTemplate","setIsCreatingTemplate","history","saveEntityRecord","createErrorNotice","createSuccessNotice","setTemplate","setCanvasMode","createTemplate","template","isWPSuggestion","title","description","slug","templatePrefix","templateContent","content","fallbackTemplate","path","is_custom","template_prefix","raw","newTemplate","toString","status","is_wp_suggestion","throwOnError","id","push","postId","type","error","errorMessage","message","code","missingTemplates","useMissingTemplates","length","customTemplateDescription","labels","add_new","add_new_item","noArrow","map","onClick","icon","existingTemplates","defaultTemplateTypes","existingTemplateSlugs","missingDefaultTemplates","filter","includes","onClickMenuItem","_entityForSuggestions","enhancedMissingDefaultTemplateTypes","defaultTaxonomiesMenuItems","taxonomiesMenuItems","defaultPostTypesMenuItems","postTypesMenuItems","authorMenuItem","forEach","menuItem","matchIndex","findIndex","sort","template1","template2","indexOf"],"mappings":";;AAAA;AACA;AACA;AACA,OAAOA,QAAP,MAAqB,sBAArB;AACA,SAASC,YAAT,QAA6B,gBAA7B;AACA,SACCC,YADD,EAECC,SAFD,EAGCC,QAHD,EAICC,OAJD,EAKCC,cALD,QAMO,uBANP;AAOA,SAASC,QAAT,QAAyB,oBAAzB;AACA,SAASC,WAAT,QAA4B,iBAA5B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SACCC,OADD,EAECC,SAFD,EAGCC,QAHD,EAICC,IAJD,EAKCC,IALD,EAMCC,KAND,EAOCC,QAPD,EAQCC,IARD,EASCC,IATD,EAUCC,IAVD,EAWCC,UAXD,EAYCC,QAZD,EAaCC,MAbD,EAcCC,GAdD,EAeCC,MAAM,IAAIC,yBAfX,QAgBO,kBAhBP;AAiBA,SAASC,EAAT,EA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S,CAACpD,IAA1C,IACA/B,sBAAsB,CAACqF,OAAvB,CAAgCD,SAAS,CAACrD,IAA1C,CAFD;AAIA,GALD;AAMA,QAAMsB,gBAAgB,GAAG,CACxB,GAAGmB,mCADqB,EAExB,GAAG9E,2BAA2B,EAFN,EAGxB,GAAGkF,kBAHqB,EAIxB,GAAGF,mBAJqB,CAAzB;AAMA,SAAOrB,gBAAP;AACA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport apiFetch from '@wordpress/api-fetch';\nimport { addQueryArgs } from '@wordpress/url';\nimport {\n\tDropdownMenu,\n\tMenuGroup,\n\tMenuItem,\n\tTooltip,\n\tVisuallyHidden,\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\tplus,\n\tpost,\n\tpostAuthor,\n\tpostDate,\n\tsearch,\n\ttag,\n\tlayout as customGenericTemplateIcon,\n} from '@wordpress/icons';\nimport { __, sprintf } from '@wordpress/i18n';\nimport { store as noticesStore } from '@wordpress/notices';\n\n/**\n * Internal dependencies\n */\nimport AddCustomTemplateModal from './add-custom-template-modal';\nimport {\n\tuseExistingTemplates,\n\tuseDefaultTemplateTypes,\n\tuseTaxonomiesMenuItems,\n\tusePostTypeMenuItems,\n\tuseAuthorMenuItem,\n\tusePostTypeArchiveMenuItems,\n} from './utils';\nimport AddCustomGenericTemplateModal from './add-custom-generic-template-modal';\nimport TemplateActionsLoadingScreen from './template-actions-loading-screen';\nimport { useHistory } from '../routes';\nimport { store as editSiteStore } from '../../store';\nimport { unlock } from '../../private-apis';\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( {\n\tpostType,\n\ttoggleProps,\n\tshowIcon = true,\n} ) {\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\tconst [ isCreatingTemplate, setIsCreatingTemplate ] = useState( false );\n\n\tconst history = useHistory();\n\tconst { saveEntityRecord } = useDispatch( coreStore );\n\tconst { createErrorNotice, createSuccessNotice } =\n\t\tuseDispatch( noticesStore );\n\tconst { setTemplate, setCanvasMode } = unlock(\n\t\tuseDispatch( editSiteStore )\n\t);\n\tasync function createTemplate( template, isWPSuggestion = true ) {\n\t\tif ( isCreatingTemplate ) {\n\t\t\treturn;\n\t\t}\n\t\tsetIsCreatingTemplate( 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.raw;\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\t\t\t// Switch to edit mode.\n\t\t\tsetCanvasMode( 'edit' );\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\tcreateSuccessNotice(\n\t\t\t\tsprintf(\n\t\t\t\t\t// translators: %s: Title of the created template e.g: \"Category\".\n\t\t\t\t\t__( '\"%s\" successfully created.' ),\n\t\t\t\t\ttitle\n\t\t\t\t),\n\t\t\t\t{\n\t\t\t\t\ttype: 'snackbar',\n\t\t\t\t}\n\t\t\t);\n\t\t} catch ( error ) {\n\t\t\tconst errorMessage =\n\t\t\t\terror.message && error.code !== 'unknown_error'\n\t\t\t\t\t? error.message\n\t\t\t\t\t: __( 'An error occurred while creating the template.' );\n\n\t\t\tcreateErrorNotice( errorMessage, {\n\t\t\t\ttype: 'snackbar',\n\t\t\t} );\n\t\t} finally {\n\t\t\tsetIsCreatingTemplate( false );\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\n\tconst customTemplateDescription = __(\n\t\t'A custom template can be manually applied to any post or page.'\n\t);\n\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={ showIcon ? plus : null }\n\t\t\t\ttext={ showIcon ? null : 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={ toggleProps }\n\t\t\t>\n\t\t\t\t{ () => (\n\t\t\t\t\t<>\n\t\t\t\t\t\t{ isCreatingTemplate && (\n\t\t\t\t\t\t\t<TemplateActionsLoadingScreen />\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t<div className=\"edit-site-new-template-dropdown__menu-groups\">\n\t\t\t\t\t\t\t<MenuGroup label={ postType.labels.add_new_item }>\n\t\t\t\t\t\t\t\t{ missingTemplates.map( ( template ) => {\n\t\t\t\t\t\t\t\t\tconst {\n\t\t\t\t\t\t\t\t\t\ttitle,\n\t\t\t\t\t\t\t\t\t\tdescription,\n\t\t\t\t\t\t\t\t\t\tslug,\n\t\t\t\t\t\t\t\t\t\tonClick,\n\t\t\t\t\t\t\t\t\t\ticon,\n\t\t\t\t\t\t\t\t\t} = template;\n\t\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t\t<Tooltip\n\t\t\t\t\t\t\t\t\t\t\tkey={ slug }\n\t\t\t\t\t\t\t\t\t\t\tposition=\"top right\"\n\t\t\t\t\t\t\t\t\t\t\ttext={ description }\n\t\t\t\t\t\t\t\t\t\t\tclassName=\"edit-site-new-template-dropdown__menu-item-tooltip\"\n\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\t\t\ticon={\n\t\t\t\t\t\t\t\t\t\t\t\t\ticon ||\n\t\t\t\t\t\t\t\t\t\t\t\t\tTEMPLATE_ICONS[ slug ] ||\n\t\t\t\t\t\t\t\t\t\t\t\t\tpost\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\t\t\tonClick\n\t\t\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\t\t: createTemplate(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\ttemplate\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t )\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t\t\t{ title }\n\t\t\t\t\t\t\t\t\t\t\t\t{ /* TODO: This probably won't be needed if the <Tooltip> component is accessible.\n\t\t\t\t\t\t\t\t\t\t\t\t * @see https://github.com/WordPress/gutenberg/issues/48222 */ }\n\t\t\t\t\t\t\t\t\t\t\t\t<VisuallyHidden>\n\t\t\t\t\t\t\t\t\t\t\t\t\t{ description }\n\t\t\t\t\t\t\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} ) }\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t\t<MenuGroup>\n\t\t\t\t\t\t\t\t<Tooltip\n\t\t\t\t\t\t\t\t\tposition=\"top right\"\n\t\t\t\t\t\t\t\t\ttext={ customTemplateDescription }\n\t\t\t\t\t\t\t\t\tclassName=\"edit-site-new-template-dropdown__menu-item-tooltip\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<MenuItem\n\t\t\t\t\t\t\t\t\t\ticon={ customGenericTemplateIcon }\n\t\t\t\t\t\t\t\t\t\ticonPosition=\"left\"\n\t\t\t\t\t\t\t\t\t\tonClick={ () =>\n\t\t\t\t\t\t\t\t\t\t\tsetShowCustomGenericTemplateModal(\n\t\t\t\t\t\t\t\t\t\t\t\ttrue\n\t\t\t\t\t\t\t\t\t\t\t)\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{ __( 'Custom template' ) }\n\t\t\t\t\t\t\t\t\t\t{ /* TODO: This probably won't be needed if the <Tooltip> component is accessible.\n\t\t\t\t\t\t\t\t\t\t * @see https://github.com/WordPress/gutenberg/issues/48222 */ }\n\t\t\t\t\t\t\t\t\t\t<VisuallyHidden>\n\t\t\t\t\t\t\t\t\t\t\t{ customTemplateDescription }\n\t\t\t\t\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t\t\t\t\t</MenuItem>\n\t\t\t\t\t\t\t\t</Tooltip>\n\t\t\t\t\t\t\t</MenuGroup>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</>\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\tisCreatingTemplate={ isCreatingTemplate }\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\tisCreatingTemplate={ isCreatingTemplate }\n\t\t\t\t/>\n\t\t\t) }\n\t\t</>\n\t);\n}\n\nfunction useMissingTemplates(\n\tsetEntityForSuggestions,\n\tsetShowCustomTemplateModal\n) {\n\tconst existingTemplates = useExistingTemplates();\n\tconst defaultTemplateTypes = useDefaultTemplateTypes();\n\tconst existingTemplateSlugs = ( existingTemplates || [] ).map(\n\t\t( { slug } ) => slug\n\t);\n\tconst missingDefaultTemplates = ( defaultTemplateTypes || [] ).filter(\n\t\t( template ) =>\n\t\t\tDEFAULT_TEMPLATE_SLUGS.includes( template.slug ) &&\n\t\t\t! existingTemplateSlugs.includes( template.slug )\n\t);\n\tconst onClickMenuItem = ( _entityForSuggestions ) => {\n\t\tsetShowCustomTemplateModal( true );\n\t\tsetEntityForSuggestions( _entityForSuggestions );\n\t};\n\t// We need to replace existing default template types with\n\t// the create specific template functionality. The original\n\t// info (title, description, etc.) is preserved in the\n\t// used hooks.\n\tconst enhancedMissingDefaultTemplateTypes = [ ...missingDefaultTemplates ];\n\tconst { defaultTaxonomiesMenuItems, taxonomiesMenuItems } =\n\t\tuseTaxonomiesMenuItems( onClickMenuItem );\n\tconst { defaultPostTypesMenuItems, postTypesMenuItems } =\n\t\tusePostTypeMenuItems( onClickMenuItem );\n\n\tconst authorMenuItem = useAuthorMenuItem( onClickMenuItem );\n\t[\n\t\t...defaultTaxonomiesMenuItems,\n\t\t...defaultPostTypesMenuItems,\n\t\tauthorMenuItem,\n\t].forEach( ( menuItem ) => {\n\t\tif ( ! menuItem ) {\n\t\t\treturn;\n\t\t}\n\t\tconst matchIndex = enhancedMissingDefaultTemplateTypes.findIndex(\n\t\t\t( template ) => template.slug === menuItem.slug\n\t\t);\n\t\t// Some default template types might have been filtered above from\n\t\t// `missingDefaultTemplates` because they only check for the general\n\t\t// template. So here we either replace or append the item, augmented\n\t\t// with the check if it has available specific item to create a\n\t\t// template for.\n\t\tif ( matchIndex > -1 ) {\n\t\t\tenhancedMissingDefaultTemplateTypes[ matchIndex ] = menuItem;\n\t\t} else {\n\t\t\tenhancedMissingDefaultTemplateTypes.push( menuItem );\n\t\t}\n\t} );\n\t// Update the sort order to match the DEFAULT_TEMPLATE_SLUGS order.\n\tenhancedMissingDefaultTemplateTypes?.sort( ( template1, template2 ) => {\n\t\treturn (\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template1.slug ) -\n\t\t\tDEFAULT_TEMPLATE_SLUGS.indexOf( template2.slug )\n\t\t);\n\t} );\n\tconst missingTemplates = [\n\t\t...enhancedMissingDefaultTemplateTypes,\n\t\t...usePostTypeArchiveMenuItems(),\n\t\t...postTypesMenuItems,\n\t\t...taxonomiesMenuItems,\n\t];\n\treturn missingTemplates;\n}\n"]}
|
|
@@ -7,7 +7,7 @@ import { __ } from '@wordpress/i18n';
|
|
|
7
7
|
import { useCallback, useMemo } from '@wordpress/element';
|
|
8
8
|
import { useSelect } from '@wordpress/data';
|
|
9
9
|
import { store as coreStore } from '@wordpress/core-data';
|
|
10
|
-
import { BlockEditorProvider
|
|
10
|
+
import { BlockEditorProvider } from '@wordpress/block-editor';
|
|
11
11
|
import { createBlock } from '@wordpress/blocks';
|
|
12
12
|
/**
|
|
13
13
|
* Internal dependencies
|
|
@@ -16,7 +16,6 @@ import { createBlock } from '@wordpress/blocks';
|
|
|
16
16
|
import SidebarNavigationScreen from '../sidebar-navigation-screen';
|
|
17
17
|
import { useHistory } from '../routes';
|
|
18
18
|
import NavigationMenuContent from './navigation-menu-content';
|
|
19
|
-
import SidebarButton from '../sidebar-button';
|
|
20
19
|
import { NavigationMenuLoader } from './loader';
|
|
21
20
|
import { unlock } from '../../private-apis';
|
|
22
21
|
import { store as editSiteStore } from '../../store';
|
|
@@ -41,7 +40,6 @@ function SidebarNavigationScreenWrapper(_ref) {
|
|
|
41
40
|
});
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
const prioritizedInserterBlocks = ['core/navigation-link/page', 'core/navigation-link'];
|
|
45
43
|
export default function SidebarNavigationScreenNavigationMenus() {
|
|
46
44
|
var _orderedNavigationMen;
|
|
47
45
|
|
|
@@ -99,24 +97,6 @@ export default function SidebarNavigationScreenNavigationMenus() {
|
|
|
99
97
|
});
|
|
100
98
|
}
|
|
101
99
|
}, [history]);
|
|
102
|
-
const orderInitialBlockItems = useCallback(items => {
|
|
103
|
-
items.sort((_ref2, _ref3) => {
|
|
104
|
-
let {
|
|
105
|
-
id: aName
|
|
106
|
-
} = _ref2;
|
|
107
|
-
let {
|
|
108
|
-
id: bName
|
|
109
|
-
} = _ref3;
|
|
110
|
-
// Sort block items according to `prioritizedInserterBlocks`.
|
|
111
|
-
let aIndex = prioritizedInserterBlocks.indexOf(aName);
|
|
112
|
-
let bIndex = prioritizedInserterBlocks.indexOf(bName); // All other block items should come after that.
|
|
113
|
-
|
|
114
|
-
if (aIndex < 0) aIndex = prioritizedInserterBlocks.length;
|
|
115
|
-
if (bIndex < 0) bIndex = prioritizedInserterBlocks.length;
|
|
116
|
-
return aIndex - bIndex;
|
|
117
|
-
});
|
|
118
|
-
return items;
|
|
119
|
-
}, []);
|
|
120
100
|
|
|
121
101
|
if (hasResolvedNavigationMenus && !hasNavigationMenus) {
|
|
122
102
|
return createElement(SidebarNavigationScreenWrapper, null, __('There are no Navigation Menus.'));
|
|
@@ -126,29 +106,12 @@ export default function SidebarNavigationScreenNavigationMenus() {
|
|
|
126
106
|
return createElement(SidebarNavigationScreenWrapper, null, createElement(NavigationMenuLoader, null));
|
|
127
107
|
}
|
|
128
108
|
|
|
129
|
-
const {
|
|
130
|
-
PrivateInserter
|
|
131
|
-
} = unlock(blockEditorPrivateApis);
|
|
132
109
|
return createElement(BlockEditorProvider, {
|
|
133
110
|
settings: storedSettings,
|
|
134
111
|
value: blocks,
|
|
135
112
|
onChange: noop,
|
|
136
113
|
onInput: noop
|
|
137
|
-
}, createElement(SidebarNavigationScreenWrapper, {
|
|
138
|
-
actions: createElement(PrivateInserter, {
|
|
139
|
-
rootClientId: blocks[0].clientId,
|
|
140
|
-
position: "bottom right",
|
|
141
|
-
isAppender: true,
|
|
142
|
-
selectBlockOnInsert: false,
|
|
143
|
-
shouldDirectInsert: false,
|
|
144
|
-
__experimentalIsQuick: true,
|
|
145
|
-
toggleProps: {
|
|
146
|
-
as: SidebarButton,
|
|
147
|
-
label: __('Add menu item')
|
|
148
|
-
},
|
|
149
|
-
orderInitialBlockItems: orderInitialBlockItems
|
|
150
|
-
})
|
|
151
|
-
}, createElement("div", {
|
|
114
|
+
}, createElement(SidebarNavigationScreenWrapper, null, createElement("div", {
|
|
152
115
|
className: "edit-site-sidebar-navigation-screen-navigation-menus__content"
|
|
153
116
|
}, createElement(NavigationMenuContent, {
|
|
154
117
|
rootClientId: blocks[0].clientId,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js"],"names":["__","useCallback","useMemo","useSelect","store","coreStore","BlockEditorProvider","privateApis","blockEditorPrivateApis","createBlock","SidebarNavigationScreen","useHistory","NavigationMenuContent","SidebarButton","NavigationMenuLoader","unlock","editSiteStore","noop","NAVIGATION_MENUS_QUERY","per_page","status","SidebarNavigationScreenWrapper","children","actions","prioritizedInserterBlocks","SidebarNavigationScreenNavigationMenus","history","navigationMenus","hasResolvedNavigationMenus","storedSettings","select","getSettings","getEntityRecords","hasFinishedResolution","navigationMenusQuery","orderedNavigationMenus","sort","menuA","menuB","menuADate","Date","date","menuBDate","getTime","firstNavigationMenu","id","blocks","ref","isLoading","hasNavigationMenus","length","onSelect","selectedBlock","attributes","name","kind","type","push","postType","postId","orderInitialBlockItems","items","aName","bName","aIndex","indexOf","bIndex","PrivateInserter","clientId","as","label"],"mappings":";;AAAA;AACA;AACA;AACA,SAASA,EAAT,QAAmB,iBAAnB;AACA,SAASC,WAAT,EAAsBC,OAAtB,QAAqC,oBAArC;AACA,SAASC,SAAT,QAA0B,iBAA1B;AACA,SAASC,KAAK,IAAIC,SAAlB,QAAmC,sBAAnC;AACA,SACCC,mBADD,EAECC,WAAW,IAAIC,sBAFhB,QAGO,yBAHP;AAIA,SAASC,WAAT,QAA4B,mBAA5B;AAEA;AACA;AACA;;AACA,OAAOC,uBAAP,MAAoC,8BAApC;AACA,SAASC,UAAT,QAA2B,WAA3B;AACA,OAAOC,qBAAP,MAAkC,2BAAlC;AACA,OAAOC,aAAP,MAA0B,mBAA1B;AACA,SAASC,oBAAT,QAAqC,UAArC;AACA,SAASC,MAAT,QAAuB,oBAAvB;AACA,SAASX,KAAK,IAAIY,aAAlB,QAAuC,aAAvC;;AAEA,MAAMC,IAAI,GAA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A,QAAQ,EAAG7B,IAHZ;AAIC,IAAA,OAAO,EAAGA;AAJX,KAMC,cAAC,8BAAD;AACC,IAAA,OAAO,EACN,cAAC,eAAD;AACC,MAAA,YAAY,EAAG6B,MAAM,CAAE,CAAF,CAAN,CAAYsB,QAD5B;AAEC,MAAA,QAAQ,EAAC,cAFV;AAGC,MAAA,UAAU,MAHX;AAIC,MAAA,mBAAmB,EAAG,KAJvB;AAKC,MAAA,kBAAkB,EAAG,KALtB;AAMC,MAAA,qBAAqB,MANtB;AAOC,MAAA,WAAW,EAAG;AACbC,QAAAA,EAAE,EAAExD,aADS;AAEbyD,QAAAA,KAAK,EAAEtE,EAAE,CAAE,eAAF;AAFI,OAPf;AAWC,MAAA,sBAAsB,EAAG4D;AAX1B;AAFF,KAiBC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,cAAC,qBAAD;AACC,IAAA,YAAY,EAAGd,MAAM,CAAE,CAAF,CAAN,CAAYsB,QAD5B;AAEC,IAAA,QAAQ,EAAGjB;AAFZ,IADD,CAjBD,CAND,CADD;AAiCA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport {\n\tBlockEditorProvider,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { createBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationScreen from '../sidebar-navigation-screen';\nimport { useHistory } from '../routes';\nimport NavigationMenuContent from './navigation-menu-content';\nimport SidebarButton from '../sidebar-button';\nimport { NavigationMenuLoader } from './loader';\nimport { unlock } from '../../private-apis';\nimport { store as editSiteStore } from '../../store';\n\nconst noop = () => {};\nconst NAVIGATION_MENUS_QUERY = { per_page: -1, status: 'publish' };\n\nfunction SidebarNavigationScreenWrapper( { children, actions } ) {\n\treturn (\n\t\t<SidebarNavigationScreen\n\t\t\ttitle={ __( 'Navigation' ) }\n\t\t\tactions={ actions }\n\t\t\tdescription={ __(\n\t\t\t\t'Browse your site, edit pages, and manage your primary navigation menu.'\n\t\t\t) }\n\t\t\tcontent={ children }\n\t\t/>\n\t);\n}\n\nconst prioritizedInserterBlocks = [\n\t'core/navigation-link/page',\n\t'core/navigation-link',\n];\n\nexport default function SidebarNavigationScreenNavigationMenus() {\n\tconst history = useHistory();\n\tconst { navigationMenus, hasResolvedNavigationMenus, storedSettings } =\n\t\tuseSelect( ( select ) => {\n\t\t\tconst { getSettings } = unlock( select( editSiteStore ) );\n\t\t\tconst { getEntityRecords, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\n\t\t\tconst navigationMenusQuery = [\n\t\t\t\t'postType',\n\t\t\t\t'wp_navigation',\n\t\t\t\tNAVIGATION_MENUS_QUERY,\n\t\t\t];\n\t\t\treturn {\n\t\t\t\tstoredSettings: getSettings( false ),\n\t\t\t\tnavigationMenus: getEntityRecords( ...navigationMenusQuery ),\n\t\t\t\thasResolvedNavigationMenus: hasFinishedResolution(\n\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\tnavigationMenusQuery\n\t\t\t\t),\n\t\t\t};\n\t\t}, [] );\n\n\t// Sort navigation menus by date.\n\tconst orderedNavigationMenus = useMemo(\n\t\t() =>\n\t\t\tnavigationMenus?.sort( ( menuA, menuB ) => {\n\t\t\t\tconst menuADate = new Date( menuA.date );\n\t\t\t\tconst menuBDate = new Date( menuB.date );\n\t\t\t\treturn menuADate.getTime() > menuBDate.getTime();\n\t\t\t} ),\n\t\t[ navigationMenus ]\n\t);\n\tconst firstNavigationMenu = orderedNavigationMenus?.[ 0 ]?.id;\n\tconst blocks = useMemo( () => {\n\t\treturn [\n\t\t\tcreateBlock( 'core/navigation', { ref: firstNavigationMenu } ),\n\t\t];\n\t}, [ firstNavigationMenu ] );\n\n\tconst isLoading = ! hasResolvedNavigationMenus;\n\tconst hasNavigationMenus = !! navigationMenus?.length;\n\n\tconst onSelect = useCallback(\n\t\t( selectedBlock ) => {\n\t\t\tconst { attributes, name } = selectedBlock;\n\t\t\tif (\n\t\t\t\tattributes.kind === 'post-type' &&\n\t\t\t\tattributes.id &&\n\t\t\t\tattributes.type &&\n\t\t\t\thistory\n\t\t\t) {\n\t\t\t\thistory.push( {\n\t\t\t\t\tpostType: attributes.type,\n\t\t\t\t\tpostId: attributes.id,\n\t\t\t\t} );\n\t\t\t}\n\t\t\tif ( name === 'core/page-list-item' && attributes.id && history ) {\n\t\t\t\thistory.push( {\n\t\t\t\t\tpostType: 'page',\n\t\t\t\t\tpostId: attributes.id,\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[ history ]\n\t);\n\tconst orderInitialBlockItems = useCallback( ( items ) => {\n\t\titems.sort( ( { id: aName }, { id: bName } ) => {\n\t\t\t// Sort block items according to `prioritizedInserterBlocks`.\n\t\t\tlet aIndex = prioritizedInserterBlocks.indexOf( aName );\n\t\t\tlet bIndex = prioritizedInserterBlocks.indexOf( bName );\n\t\t\t// All other block items should come after that.\n\t\t\tif ( aIndex < 0 ) aIndex = prioritizedInserterBlocks.length;\n\t\t\tif ( bIndex < 0 ) bIndex = prioritizedInserterBlocks.length;\n\t\t\treturn aIndex - bIndex;\n\t\t} );\n\t\treturn items;\n\t}, [] );\n\n\tif ( hasResolvedNavigationMenus && ! hasNavigationMenus ) {\n\t\treturn (\n\t\t\t<SidebarNavigationScreenWrapper>\n\t\t\t\t{ __( 'There are no Navigation Menus.' ) }\n\t\t\t</SidebarNavigationScreenWrapper>\n\t\t);\n\t}\n\n\tif ( ! hasResolvedNavigationMenus || isLoading ) {\n\t\treturn (\n\t\t\t<SidebarNavigationScreenWrapper>\n\t\t\t\t<NavigationMenuLoader />\n\t\t\t</SidebarNavigationScreenWrapper>\n\t\t);\n\t}\n\tconst { PrivateInserter } = unlock( blockEditorPrivateApis );\n\treturn (\n\t\t<BlockEditorProvider\n\t\t\tsettings={ storedSettings }\n\t\t\tvalue={ blocks }\n\t\t\tonChange={ noop }\n\t\t\tonInput={ noop }\n\t\t>\n\t\t\t<SidebarNavigationScreenWrapper\n\t\t\t\tactions={\n\t\t\t\t\t<PrivateInserter\n\t\t\t\t\t\trootClientId={ blocks[ 0 ].clientId }\n\t\t\t\t\t\tposition=\"bottom right\"\n\t\t\t\t\t\tisAppender\n\t\t\t\t\t\tselectBlockOnInsert={ false }\n\t\t\t\t\t\tshouldDirectInsert={ false }\n\t\t\t\t\t\t__experimentalIsQuick\n\t\t\t\t\t\ttoggleProps={ {\n\t\t\t\t\t\t\tas: SidebarButton,\n\t\t\t\t\t\t\tlabel: __( 'Add menu item' ),\n\t\t\t\t\t\t} }\n\t\t\t\t\t\torderInitialBlockItems={ orderInitialBlockItems }\n\t\t\t\t\t/>\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t<div className=\"edit-site-sidebar-navigation-screen-navigation-menus__content\">\n\t\t\t\t\t<NavigationMenuContent\n\t\t\t\t\t\trootClientId={ blocks[ 0 ].clientId }\n\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t</SidebarNavigationScreenWrapper>\n\t\t</BlockEditorProvider>\n\t);\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/sidebar-navigation-screen-navigation-menus/index.js"],"names":["__","useCallback","useMemo","useSelect","store","coreStore","BlockEditorProvider","createBlock","SidebarNavigationScreen","useHistory","NavigationMenuContent","NavigationMenuLoader","unlock","editSiteStore","noop","NAVIGATION_MENUS_QUERY","per_page","status","SidebarNavigationScreenWrapper","children","actions","SidebarNavigationScreenNavigationMenus","history","navigationMenus","hasResolvedNavigationMenus","storedSettings","select","getSettings","getEntityRecords","hasFinishedResolution","navigationMenusQuery","orderedNavigationMenus","sort","menuA","menuB","menuADate","Date","date","menuBDate","getTime","firstNavigationMenu","id","blocks","ref","isLoading","hasNavigationMenus","length","onSelect","selectedBlock","attributes","name","kind","type","push","postType","postId","clientId"],"m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ependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { useCallback, useMemo } from '@wordpress/element';\nimport { useSelect } from '@wordpress/data';\nimport { store as coreStore } from '@wordpress/core-data';\nimport { BlockEditorProvider } from '@wordpress/block-editor';\nimport { createBlock } from '@wordpress/blocks';\n\n/**\n * Internal dependencies\n */\nimport SidebarNavigationScreen from '../sidebar-navigation-screen';\nimport { useHistory } from '../routes';\nimport NavigationMenuContent from './navigation-menu-content';\nimport { NavigationMenuLoader } from './loader';\nimport { unlock } from '../../private-apis';\nimport { store as editSiteStore } from '../../store';\n\nconst noop = () => {};\nconst NAVIGATION_MENUS_QUERY = { per_page: -1, status: 'publish' };\n\nfunction SidebarNavigationScreenWrapper( { children, actions } ) {\n\treturn (\n\t\t<SidebarNavigationScreen\n\t\t\ttitle={ __( 'Navigation' ) }\n\t\t\tactions={ actions }\n\t\t\tdescription={ __(\n\t\t\t\t'Browse your site, edit pages, and manage your primary navigation menu.'\n\t\t\t) }\n\t\t\tcontent={ children }\n\t\t/>\n\t);\n}\n\nexport default function SidebarNavigationScreenNavigationMenus() {\n\tconst history = useHistory();\n\tconst { navigationMenus, hasResolvedNavigationMenus, storedSettings } =\n\t\tuseSelect( ( select ) => {\n\t\t\tconst { getSettings } = unlock( select( editSiteStore ) );\n\t\t\tconst { getEntityRecords, hasFinishedResolution } =\n\t\t\t\tselect( coreStore );\n\n\t\t\tconst navigationMenusQuery = [\n\t\t\t\t'postType',\n\t\t\t\t'wp_navigation',\n\t\t\t\tNAVIGATION_MENUS_QUERY,\n\t\t\t];\n\t\t\treturn {\n\t\t\t\tstoredSettings: getSettings( false ),\n\t\t\t\tnavigationMenus: getEntityRecords( ...navigationMenusQuery ),\n\t\t\t\thasResolvedNavigationMenus: hasFinishedResolution(\n\t\t\t\t\t'getEntityRecords',\n\t\t\t\t\tnavigationMenusQuery\n\t\t\t\t),\n\t\t\t};\n\t\t}, [] );\n\n\t// Sort navigation menus by date.\n\tconst orderedNavigationMenus = useMemo(\n\t\t() =>\n\t\t\tnavigationMenus?.sort( ( menuA, menuB ) => {\n\t\t\t\tconst menuADate = new Date( menuA.date );\n\t\t\t\tconst menuBDate = new Date( menuB.date );\n\t\t\t\treturn menuADate.getTime() > menuBDate.getTime();\n\t\t\t} ),\n\t\t[ navigationMenus ]\n\t);\n\tconst firstNavigationMenu = orderedNavigationMenus?.[ 0 ]?.id;\n\tconst blocks = useMemo( () => {\n\t\treturn [\n\t\t\tcreateBlock( 'core/navigation', { ref: firstNavigationMenu } ),\n\t\t];\n\t}, [ firstNavigationMenu ] );\n\n\tconst isLoading = ! hasResolvedNavigationMenus;\n\tconst hasNavigationMenus = !! navigationMenus?.length;\n\n\tconst onSelect = useCallback(\n\t\t( selectedBlock ) => {\n\t\t\tconst { attributes, name } = selectedBlock;\n\t\t\tif (\n\t\t\t\tattributes.kind === 'post-type' &&\n\t\t\t\tattributes.id &&\n\t\t\t\tattributes.type &&\n\t\t\t\thistory\n\t\t\t) {\n\t\t\t\thistory.push( {\n\t\t\t\t\tpostType: attributes.type,\n\t\t\t\t\tpostId: attributes.id,\n\t\t\t\t} );\n\t\t\t}\n\t\t\tif ( name === 'core/page-list-item' && attributes.id && history ) {\n\t\t\t\thistory.push( {\n\t\t\t\t\tpostType: 'page',\n\t\t\t\t\tpostId: attributes.id,\n\t\t\t\t} );\n\t\t\t}\n\t\t},\n\t\t[ history ]\n\t);\n\n\tif ( hasResolvedNavigationMenus && ! hasNavigationMenus ) {\n\t\treturn (\n\t\t\t<SidebarNavigationScreenWrapper>\n\t\t\t\t{ __( 'There are no Navigation Menus.' ) }\n\t\t\t</SidebarNavigationScreenWrapper>\n\t\t);\n\t}\n\n\tif ( ! hasResolvedNavigationMenus || isLoading ) {\n\t\treturn (\n\t\t\t<SidebarNavigationScreenWrapper>\n\t\t\t\t<NavigationMenuLoader />\n\t\t\t</SidebarNavigationScreenWrapper>\n\t\t);\n\t}\n\n\treturn (\n\t\t<BlockEditorProvider\n\t\t\tsettings={ storedSettings }\n\t\t\tvalue={ blocks }\n\t\t\tonChange={ noop }\n\t\t\tonInput={ noop }\n\t\t>\n\t\t\t<SidebarNavigationScreenWrapper>\n\t\t\t\t<div className=\"edit-site-sidebar-navigation-screen-navigation-menus__content\">\n\t\t\t\t\t<NavigationMenuContent\n\t\t\t\t\t\trootClientId={ blocks[ 0 ].clientId }\n\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t/>\n\t\t\t\t</div>\n\t\t\t</SidebarNavigationScreenWrapper>\n\t\t</BlockEditorProvider>\n\t);\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
|
+
import { createElement, Fragment } from "@wordpress/element";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* External dependencies
|
|
@@ -8,10 +9,11 @@ import classnames from 'classnames';
|
|
|
8
9
|
* WordPress dependencies
|
|
9
10
|
*/
|
|
10
11
|
|
|
11
|
-
import { Button, TabPanel, createSlotFill, __experimentalUseSlotFills as useSlotFills } from '@wordpress/components';
|
|
12
|
+
import { Button, __unstableComposite as Composite, __unstableUseCompositeState as useCompositeState, __unstableCompositeItem as CompositeItem, Disabled, TabPanel, createSlotFill, __experimentalUseSlotFills as useSlotFills } from '@wordpress/components';
|
|
12
13
|
import { __, sprintf } from '@wordpress/i18n';
|
|
13
14
|
import { getCategories, getBlockTypes, getBlockFromExample, createBlock } from '@wordpress/blocks';
|
|
14
|
-
import {
|
|
15
|
+
import { BlockList, privateApis as blockEditorPrivateApis, store as blockEditorStore, __unstableEditorStyles as EditorStyles, __unstableIframe as Iframe } from '@wordpress/block-editor';
|
|
16
|
+
import { useSelect } from '@wordpress/data';
|
|
15
17
|
import { closeSmall } from '@wordpress/icons';
|
|
16
18
|
import { useResizeObserver, useFocusOnMount, useFocusReturn, useMergeRefs } from '@wordpress/compose';
|
|
17
19
|
import { useMemo, memo } from '@wordpress/element';
|
|
@@ -22,13 +24,83 @@ import { ESCAPE } from '@wordpress/keycodes';
|
|
|
22
24
|
|
|
23
25
|
import { unlock } from '../../private-apis';
|
|
24
26
|
const {
|
|
27
|
+
ExperimentalBlockEditorProvider,
|
|
25
28
|
useGlobalStyle
|
|
26
29
|
} = unlock(blockEditorPrivateApis);
|
|
27
30
|
const SLOT_FILL_NAME = 'EditSiteStyleBook';
|
|
28
31
|
const {
|
|
29
32
|
Slot: StyleBookSlot,
|
|
30
33
|
Fill: StyleBookFill
|
|
31
|
-
} = createSlotFill(SLOT_FILL_NAME);
|
|
34
|
+
} = createSlotFill(SLOT_FILL_NAME); // The content area of the Style Book is rendered within an iframe so that global styles
|
|
35
|
+
// are applied to elements within the entire content area. To support elements that are
|
|
36
|
+
// not part of the block previews, such as headings and layout for the block previews,
|
|
37
|
+
// additional CSS rules need to be passed into the iframe. These are hard-coded below.
|
|
38
|
+
// Note that button styles are unset, and then focus rules from the `Button` component are
|
|
39
|
+
// applied to the `button` element, targeted via `.edit-site-style-book__example`.
|
|
40
|
+
// This is to ensure that browser default styles for buttons are not applied to the previews.
|
|
41
|
+
|
|
42
|
+
const STYLE_BOOK_IFRAME_STYLES = `
|
|
43
|
+
.edit-site-style-book__examples {
|
|
44
|
+
max-width: 900px;
|
|
45
|
+
margin: 0 auto;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.edit-site-style-book__example {
|
|
49
|
+
border-radius: 2px;
|
|
50
|
+
cursor: pointer;
|
|
51
|
+
display: flex;
|
|
52
|
+
flex-direction: column;
|
|
53
|
+
gap: 40px;
|
|
54
|
+
margin-bottom: 40px;
|
|
55
|
+
padding: 16px;
|
|
56
|
+
width: 100%;
|
|
57
|
+
box-sizing: border-box;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.edit-site-style-book__example.is-selected {
|
|
61
|
+
box-shadow: 0 0 0 1px var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.edit-site-style-book__example:focus:not(:disabled) {
|
|
65
|
+
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));
|
|
66
|
+
outline: 3px solid transparent;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.edit-site-style-book__examples.is-wide .edit-site-style-book__example {
|
|
70
|
+
flex-direction: row;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.edit-site-style-book__example-title {
|
|
74
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen-Sans, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
|
|
75
|
+
font-size: 11px;
|
|
76
|
+
font-weight: 500;
|
|
77
|
+
line-height: normal;
|
|
78
|
+
margin: 0;
|
|
79
|
+
text-align: left;
|
|
80
|
+
text-transform: uppercase;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
.edit-site-style-book__examples.is-wide .edit-site-style-book__example-title {
|
|
84
|
+
text-align: right;
|
|
85
|
+
width: 120px;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.edit-site-style-book__example-preview {
|
|
89
|
+
width: 100%;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
.edit-site-style-book__example-preview .block-editor-block-list__insertion-point,
|
|
93
|
+
.edit-site-style-book__example-preview .block-list-appender {
|
|
94
|
+
display: none;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
.edit-site-style-book__example-preview .is-root-container > .wp-block:first-child {
|
|
98
|
+
margin-top: 0;
|
|
99
|
+
}
|
|
100
|
+
.edit-site-style-book__example-preview .is-root-container > .wp-block:last-child {
|
|
101
|
+
margin-bottom: 0;
|
|
102
|
+
}
|
|
103
|
+
`;
|
|
32
104
|
|
|
33
105
|
function getExamples() {
|
|
34
106
|
// Use our own example for the Heading block so that we can show multiple
|
|
@@ -87,6 +159,10 @@ function StyleBook(_ref) {
|
|
|
87
159
|
title: category.title,
|
|
88
160
|
icon: category.icon
|
|
89
161
|
})), [examples]);
|
|
162
|
+
const originalSettings = useSelect(select => select(blockEditorStore).getSettings(), []);
|
|
163
|
+
const settings = useMemo(() => ({ ...originalSettings,
|
|
164
|
+
__unstableIsPreviewMode: true
|
|
165
|
+
}), [originalSettings]);
|
|
90
166
|
|
|
91
167
|
function closeOnEscape(event) {
|
|
92
168
|
if (event.keyCode === ESCAPE && !event.defaultPrevented) {
|
|
@@ -115,25 +191,48 @@ function StyleBook(_ref) {
|
|
|
115
191
|
}), createElement(TabPanel, {
|
|
116
192
|
className: "edit-site-style-book__tab-panel",
|
|
117
193
|
tabs: tabs
|
|
118
|
-
}, tab => createElement(
|
|
194
|
+
}, tab => createElement(Iframe, {
|
|
195
|
+
className: "edit-site-style-book__iframe",
|
|
196
|
+
head: createElement(Fragment, null, createElement(EditorStyles, {
|
|
197
|
+
styles: settings.styles
|
|
198
|
+
}), createElement("style", null, // Forming a "block formatting context" to prevent margin collapsing.
|
|
199
|
+
// @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context
|
|
200
|
+
`.is-root-container { display: flow-root; }
|
|
201
|
+
body { position: relative; padding: 32px !important; }` + STYLE_BOOK_IFRAME_STYLES)),
|
|
202
|
+
name: "style-book-canvas",
|
|
203
|
+
tabIndex: 0
|
|
204
|
+
}, settings.svgFilters, createElement(Examples, {
|
|
205
|
+
className: classnames('edit-site-style-book__examples', {
|
|
206
|
+
'is-wide': sizes.width > 600
|
|
207
|
+
}),
|
|
119
208
|
examples: examples,
|
|
120
209
|
category: tab.name,
|
|
210
|
+
label: sprintf( // translators: %s: Category of blocks, e.g. Text.
|
|
211
|
+
__('Examples of blocks in the %s category'), tab.title),
|
|
121
212
|
isSelected: isSelected,
|
|
122
213
|
onSelect: onSelect
|
|
123
|
-
}))));
|
|
214
|
+
})))));
|
|
124
215
|
}
|
|
125
216
|
|
|
126
217
|
const Examples = memo(_ref2 => {
|
|
127
218
|
let {
|
|
219
|
+
className,
|
|
128
220
|
examples,
|
|
129
221
|
category,
|
|
222
|
+
label,
|
|
130
223
|
isSelected,
|
|
131
224
|
onSelect
|
|
132
225
|
} = _ref2;
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
}
|
|
226
|
+
const composite = useCompositeState({
|
|
227
|
+
orientation: 'vertical'
|
|
228
|
+
});
|
|
229
|
+
return createElement(Composite, _extends({}, composite, {
|
|
230
|
+
className: className,
|
|
231
|
+
"aria-label": label
|
|
232
|
+
}), examples.filter(example => example.category === category).map(example => createElement(Example, {
|
|
136
233
|
key: example.name,
|
|
234
|
+
id: `example-${example.name}`,
|
|
235
|
+
composite: composite,
|
|
137
236
|
title: example.title,
|
|
138
237
|
blocks: example.blocks,
|
|
139
238
|
isSelected: isSelected(example.name),
|
|
@@ -142,32 +241,46 @@ const Examples = memo(_ref2 => {
|
|
|
142
241
|
}
|
|
143
242
|
})));
|
|
144
243
|
});
|
|
145
|
-
|
|
244
|
+
|
|
245
|
+
const Example = _ref3 => {
|
|
146
246
|
let {
|
|
247
|
+
composite,
|
|
248
|
+
id,
|
|
147
249
|
title,
|
|
148
250
|
blocks,
|
|
149
251
|
isSelected,
|
|
150
252
|
onClick
|
|
151
253
|
} = _ref3;
|
|
152
|
-
|
|
254
|
+
const originalSettings = useSelect(select => select(blockEditorStore).getSettings(), []);
|
|
255
|
+
const settings = useMemo(() => ({ ...originalSettings,
|
|
256
|
+
__unstableIsPreviewMode: true
|
|
257
|
+
}), [originalSettings]); // Cache the list of blocks to avoid additional processing when the component is re-rendered.
|
|
258
|
+
|
|
259
|
+
const renderedBlocks = useMemo(() => Array.isArray(blocks) ? blocks : [blocks], [blocks]);
|
|
260
|
+
return createElement(CompositeItem, _extends({}, composite, {
|
|
153
261
|
className: classnames('edit-site-style-book__example', {
|
|
154
262
|
'is-selected': isSelected
|
|
155
263
|
}),
|
|
264
|
+
id: id,
|
|
156
265
|
"aria-label": sprintf( // translators: %s: Title of a block, e.g. Heading.
|
|
157
266
|
__('Open %s styles in Styles panel'), title),
|
|
158
|
-
onClick: onClick
|
|
159
|
-
|
|
267
|
+
onClick: onClick,
|
|
268
|
+
role: "button",
|
|
269
|
+
as: "div"
|
|
270
|
+
}), createElement("span", {
|
|
160
271
|
className: "edit-site-style-book__example-title"
|
|
161
272
|
}, title), createElement("div", {
|
|
162
|
-
className: "edit-site-style-book__example-preview"
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
}
|
|
170
|
-
|
|
273
|
+
className: "edit-site-style-book__example-preview",
|
|
274
|
+
"aria-hidden": true
|
|
275
|
+
}, createElement(Disabled, {
|
|
276
|
+
className: "edit-site-style-book__example-preview__content"
|
|
277
|
+
}, createElement(ExperimentalBlockEditorProvider, {
|
|
278
|
+
value: renderedBlocks,
|
|
279
|
+
settings: settings
|
|
280
|
+
}, createElement(BlockList, {
|
|
281
|
+
renderAppender: false
|
|
282
|
+
})))));
|
|
283
|
+
};
|
|
171
284
|
|
|
172
285
|
function useHasStyleBook() {
|
|
173
286
|
const fills = useSlotFills(SLOT_FILL_NAME);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/edit-site/src/components/style-book/index.js"],"names":["classnames","Button","TabPanel","createSlotFill","__experimentalUseSlotFills","useSlotFills","__","sprintf","getCategories","getBlockTypes","getBlockFromExample","createBlock","BlockPreview","privateApis","blockEditorPrivateApis","closeSmall","useResizeObserver","useFocusOnMount","useFocusReturn","useMergeRefs","useMemo","memo","ESCAPE","unlock","useGlobalStyle","SLOT_FILL_NAME","Slot","StyleBookSlot","Fill","StyleBookFill","getExamples","headingsExample","name","title","category","blocks","content","level","otherExamples","filter","blockType","example","supports","inserter","map","StyleBook","isSelected","onSelect","onClose","resizeObserver","sizes","focusOnMountRef","sectionFocusReturnRef","textColor","backgroundColor","examples","tabs","some","slug","icon","closeOnEscape","event","keyCode","defaultPrevented","preventDefault","width","color","background","tab","Examples","Example","onClick","css","useHasStyleBook","fills","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AAO,GAAGjD,IAAI,CAAE;AAAA,MAAE;AAAEY,IAAAA,KAAF;AAASE,IAAAA,MAAT;AAAiBW,IAAAA,UAAjB;AAA6ByB,IAAAA;AAA7B,GAAF;AAAA,SACrB;AACC,IAAA,SAAS,EAAGvE,UAAU,CAAE,+BAAF,EAAmC;AACxD,qBAAe8C;AADyC,KAAnC,CADvB;AAIC,kBAAavC,OAAO,EACnB;AACAD,IAAAA,EAAE,CAAE,gCAAF,CAFiB,EAGnB2B,KAHmB,CAJrB;AASC,IAAA,OAAO,EAAGsC;AATX,KAWC;AAAM,IAAA,SAAS,EAAC;AAAhB,KAAwDtC,KAAxD,CAXD,EAYC;AAAK,IAAA,SAAS,EAAC;AAAf,KACC,cAAC,YAAD;AACC,IAAA,MAAM,EAAGE,MADV;AAEC,IAAA,aAAa,EAAG,CAFjB;AAGC,IAAA,gBAAgB,EAAG,CAClB;AACCqC,MAAAA,GAAG,EACF,6CACA;AAHF,KADkB;AAHpB,IADD,CAZD,CADqB;AAAA,CAAF,CAApB;;AA6BA,SAASC,eAAT,GAA2B;AAC1B,QAAMC,KAAK,GAAGrE,YAAY,CAAEoB,cAAF,CAA1B;AACA,SAAO,CAAC,EAAEiD,KAAF,aAAEA,KAAF,eAAEA,KAAK,CAAEC,MAAT,CAAR;AACA;;AAED9B,SAAS,CAACnB,IAAV,GAAiBC,aAAjB;AACA,eAAekB,SAAf;AACA,SAAS4B,eAAT","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\tTabPanel,\n\tcreateSlotFill,\n\t__experimentalUseSlotFills as useSlotFills,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tgetCategories,\n\tgetBlockTypes,\n\tgetBlockFromExample,\n\tcreateBlock,\n} from '@wordpress/blocks';\nimport {\n\tBlockPreview,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { closeSmall } from '@wordpress/icons';\nimport {\n\tuseResizeObserver,\n\tuseFocusOnMount,\n\tuseFocusReturn,\n\tuseMergeRefs,\n} from '@wordpress/compose';\nimport { useMemo, memo } from '@wordpress/element';\nimport { ESCAPE } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../private-apis';\n\nconst { useGlobalStyle } = unlock( blockEditorPrivateApis );\n\nconst SLOT_FILL_NAME = 'EditSiteStyleBook';\nconst { Slot: StyleBookSlot, Fill: StyleBookFill } =\n\tcreateSlotFill( SLOT_FILL_NAME );\n\nfunction getExamples() {\n\t// Use our own example for the Heading block so that we can show multiple\n\t// heading levels.\n\tconst headingsExample = {\n\t\tname: 'core/heading',\n\t\ttitle: __( 'Headings' ),\n\t\tcategory: 'text',\n\t\tblocks: [\n\t\t\tcreateBlock( 'core/heading', {\n\t\t\t\tcontent: __( 'Code Is Poetry' ),\n\t\t\t\tlevel: 1,\n\t\t\t} ),\n\t\t\tcreateBlock( 'core/heading', {\n\t\t\t\tcontent: __( 'Code Is Poetry' ),\n\t\t\t\tlevel: 2,\n\t\t\t} ),\n\t\t\tcreateBlock( 'core/heading', {\n\t\t\t\tcontent: __( 'Code Is Poetry' ),\n\t\t\t\tlevel: 3,\n\t\t\t} ),\n\t\t\tcreateBlock( 'core/heading', {\n\t\t\t\tcontent: __( 'Code Is Poetry' ),\n\t\t\t\tlevel: 4,\n\t\t\t} ),\n\t\t\tcreateBlock( 'core/heading', {\n\t\t\t\tcontent: __( 'Code Is Poetry' ),\n\t\t\t\tlevel: 5,\n\t\t\t} ),\n\t\t],\n\t};\n\n\tconst otherExamples = getBlockTypes()\n\t\t.filter( ( blockType ) => {\n\t\t\tconst { name, example, supports } = blockType;\n\t\t\treturn (\n\t\t\t\tname !== 'core/heading' &&\n\t\t\t\t!! example &&\n\t\t\t\tsupports.inserter !== false\n\t\t\t);\n\t\t} )\n\t\t.map( ( blockType ) => ( {\n\t\t\tname: blockType.name,\n\t\t\ttitle: blockType.title,\n\t\t\tcategory: blockType.category,\n\t\t\tblocks: getBlockFromExample( blockType.name, blockType.example ),\n\t\t} ) );\n\n\treturn [ headingsExample, ...otherExamples ];\n}\n\nfunction StyleBook( { isSelected, onSelect, onClose } ) {\n\tconst [ resizeObserver, sizes ] = useResizeObserver();\n\tconst focusOnMountRef = useFocusOnMount( 'firstElement' );\n\tconst sectionFocusReturnRef = useFocusReturn();\n\n\tconst [ textColor ] = useGlobalStyle( 'color.text' );\n\tconst [ backgroundColor ] = useGlobalStyle( 'color.background' );\n\tconst examples = useMemo( getExamples, [] );\n\tconst tabs = useMemo(\n\t\t() =>\n\t\t\tgetCategories()\n\t\t\t\t.filter( ( category ) =>\n\t\t\t\t\texamples.some(\n\t\t\t\t\t\t( example ) => example.category === category.slug\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t.map( ( category ) => ( {\n\t\t\t\t\tname: category.slug,\n\t\t\t\t\ttitle: category.title,\n\t\t\t\t\ticon: category.icon,\n\t\t\t\t} ) ),\n\t\t[ examples ]\n\t);\n\n\tfunction closeOnEscape( event ) {\n\t\tif ( event.keyCode === ESCAPE && ! event.defaultPrevented ) {\n\t\t\tevent.preventDefault();\n\t\t\tonClose();\n\t\t}\n\t}\n\n\treturn (\n\t\t<StyleBookFill>\n\t\t\t{ /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ }\n\t\t\t<section\n\t\t\t\tclassName={ classnames( 'edit-site-style-book', {\n\t\t\t\t\t'is-wide': sizes.width > 600,\n\t\t\t\t} ) }\n\t\t\t\tstyle={ {\n\t\t\t\t\tcolor: textColor,\n\t\t\t\t\tbackground: backgroundColor,\n\t\t\t\t} }\n\t\t\t\taria-label={ __( 'Style Book' ) }\n\t\t\t\tonKeyDown={ closeOnEscape }\n\t\t\t\tref={ useMergeRefs( [\n\t\t\t\t\tsectionFocusReturnRef,\n\t\t\t\t\tfocusOnMountRef,\n\t\t\t\t] ) }\n\t\t\t>\n\t\t\t\t{ resizeObserver }\n\t\t\t\t<Button\n\t\t\t\t\tclassName=\"edit-site-style-book__close-button\"\n\t\t\t\t\ticon={ closeSmall }\n\t\t\t\t\tlabel={ __( 'Close Style Book' ) }\n\t\t\t\t\tonClick={ onClose }\n\t\t\t\t\tshowTooltip={ false }\n\t\t\t\t/>\n\t\t\t\t<TabPanel\n\t\t\t\t\tclassName=\"edit-site-style-book__tab-panel\"\n\t\t\t\t\ttabs={ tabs }\n\t\t\t\t>\n\t\t\t\t\t{ ( tab ) => (\n\t\t\t\t\t\t<Examples\n\t\t\t\t\t\t\texamples={ examples }\n\t\t\t\t\t\t\tcategory={ tab.name }\n\t\t\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t/>\n\t\t\t\t\t) }\n\t\t\t\t</TabPanel>\n\t\t\t</section>\n\t\t</StyleBookFill>\n\t);\n}\n\nconst Examples = memo( ( { examples, category, isSelected, onSelect } ) => (\n\t<div className=\"edit-site-style-book__examples\">\n\t\t{ examples\n\t\t\t.filter( ( example ) => example.category === category )\n\t\t\t.map( ( example ) => (\n\t\t\t\t<Example\n\t\t\t\t\tkey={ example.name }\n\t\t\t\t\ttitle={ example.title }\n\t\t\t\t\tblocks={ example.blocks }\n\t\t\t\t\tisSelected={ isSelected( example.name ) }\n\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\tonSelect( example.name );\n\t\t\t\t\t} }\n\t\t\t\t/>\n\t\t\t) ) }\n\t</div>\n) );\n\nconst Example = memo( ( { title, blocks, isSelected, onClick } ) => (\n\t<button\n\t\tclassName={ classnames( 'edit-site-style-book__example', {\n\t\t\t'is-selected': isSelected,\n\t\t} ) }\n\t\taria-label={ sprintf(\n\t\t\t// translators: %s: Title of a block, e.g. Heading.\n\t\t\t__( 'Open %s styles in Styles panel' ),\n\t\t\ttitle\n\t\t) }\n\t\tonClick={ onClick }\n\t>\n\t\t<span className=\"edit-site-style-book__example-title\">{ title }</span>\n\t\t<div className=\"edit-site-style-book__example-preview\">\n\t\t\t<BlockPreview\n\t\t\t\tblocks={ blocks }\n\t\t\t\tviewportWidth={ 0 }\n\t\t\t\tadditionalStyles={ [\n\t\t\t\t\t{\n\t\t\t\t\t\tcss:\n\t\t\t\t\t\t\t'.wp-block:first-child { margin-top: 0; }' +\n\t\t\t\t\t\t\t'.wp-block:last-child { margin-bottom: 0; }',\n\t\t\t\t\t},\n\t\t\t\t] }\n\t\t\t/>\n\t\t</div>\n\t</button>\n) );\n\nfunction useHasStyleBook() {\n\tconst fills = useSlotFills( SLOT_FILL_NAME );\n\treturn !! fills?.length;\n}\n\nStyleBook.Slot = StyleBookSlot;\nexport default StyleBook;\nexport { useHasStyleBook };\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/edit-site/src/components/style-book/index.js"],"names":["classnames","Button","__unstableComposite","Composite","__unstableUseCompositeState","useCompositeState","__unstableCompositeItem","CompositeItem","Disabled","TabPanel","createSlotFill","__experimentalUseSlotFills","useSlotFills","__","sprintf","getCategories","getBlockTypes","getBlockFromExample","createBlock","BlockList","privateApis","blockEditorPrivateApis","store","blockEditorStore","__unstableEditorStyles","EditorStyles","__unstableIframe","Iframe","useSelect","closeSmall","useResizeObserver","useFocusOnMount","useFocusReturn","useMergeRefs","useMemo","memo","ESCAPE","unlock","ExperimentalBlockEditorProvider","useGlobalStyle","SLOT_FILL_NAME","Slot","StyleBookSlot","Fill","StyleBookFill","STYLE_BOOK_IFRAME_STYLES","getExamples","headingsExample","name","title","category","blocks","content","level","otherExamples","filter","blockType","example","supports","inserter","map","StyleBook","isSelected","onSelect","onClose","resizeObserver","sizes","focusOnMountRef","sectionFocusReturnRef","textColor","backgroundColor","examples","tabs","some","slug","icon","originalSettings","select","getSettings","settings","__unstableIsPreviewMode","closeOnEscape","event","keyCode","defaultPrevented","preventDefault","width","color","background","tab","styles","svgFilters","Examples","className","label","composite","orientation","Example","id","onClick","renderedBlocks","Array","isArray","useHasStyleBook","fills","length"],"mappings":";;;AAAA;AACA;AAC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AGoC,EALN;AAMC,kBAAapF,OAAO,EACnB;AACAD,IAAAA,EAAE,CAAE,gCAAF,CAFiB,EAGnBoC,KAHmB,CANrB;AAWC,IAAA,OAAO,EAAGkD,OAXX;AAYC,IAAA,IAAI,EAAC,QAZN;AAaC,IAAA,EAAE,EAAC;AAbJ,MAeC;AAAM,IAAA,SAAS,EAAC;AAAhB,KACGlD,KADH,CAfD,EAkBC;AAAK,IAAA,SAAS,EAAC,uCAAf;AAAuD;AAAvD,KACC,cAAC,QAAD;AAAU,IAAA,SAAS,EAAC;AAApB,KACC,cAAC,+BAAD;AACC,IAAA,KAAK,EAAGmD,cADT;AAEC,IAAA,QAAQ,EAAGrB;AAFZ,KAIC,cAAC,SAAD;AAAW,IAAA,cAAc,EAAG;AAA5B,IAJD,CADD,CADD,CAlBD,CADD;AA+BA,CA/CD;;AAiDA,SAASwB,eAAT,GAA2B;AAC1B,QAAMC,KAAK,GAAG5F,YAAY,CAAE4B,cAAF,CAA1B;AACA,SAAO,CAAC,EAAEgE,KAAF,aAAEA,KAAF,eAAEA,KAAK,CAAEC,MAAT,CAAR;AACA;;AAED5C,SAAS,CAACpB,IAAV,GAAiBC,aAAjB;AACA,eAAemB,SAAf;AACA,SAAS0C,eAAT","sourcesContent":["/**\n * External dependencies\n */\nimport classnames from 'classnames';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tButton,\n\t__unstableComposite as Composite,\n\t__unstableUseCompositeState as useCompositeState,\n\t__unstableCompositeItem as CompositeItem,\n\tDisabled,\n\tTabPanel,\n\tcreateSlotFill,\n\t__experimentalUseSlotFills as useSlotFills,\n} from '@wordpress/components';\nimport { __, sprintf } from '@wordpress/i18n';\nimport {\n\tgetCategories,\n\tgetBlockTypes,\n\tgetBlockFromExample,\n\tcreateBlock,\n} from '@wordpress/blocks';\nimport {\n\tBlockList,\n\tprivateApis as blockEditorPrivateApis,\n\tstore as blockEditorStore,\n\t__unstableEditorStyles as EditorStyles,\n\t__unstableIframe as Iframe,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { closeSmall } from '@wordpress/icons';\nimport {\n\tuseResizeObserver,\n\tuseFocusOnMount,\n\tuseFocusReturn,\n\tuseMergeRefs,\n} from '@wordpress/compose';\nimport { useMemo, memo } from '@wordpress/element';\nimport { ESCAPE } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { unlock } from '../../private-apis';\n\nconst { ExperimentalBlockEditorProvider, useGlobalStyle } = unlock(\n\tblockEditorPrivateApis\n);\n\nconst SLOT_FILL_NAME = 'EditSiteStyleBook';\nconst { Slot: StyleBookSlot, Fill: StyleBookFill } =\n\tcreateSlotFill( SLOT_FILL_NAME );\n\n// The content area of the Style Book is rendered within an iframe so that global styles\n// are applied to elements within the entire content area. To support elements that are\n// not part of the block previews, such as headings and layout for the block previews,\n// additional CSS rules need to be passed into the iframe. These are hard-coded below.\n// Note that button styles are unset, and then focus rules from the `Button` component are\n// applied to the `button` element, targeted via `.edit-site-style-book__example`.\n// This is to ensure that browser default styles for buttons are not applied to the previews.\nconst STYLE_BOOK_IFRAME_STYLES = `\n\t.edit-site-style-book__examples {\n\t\tmax-width: 900px;\n\t\tmargin: 0 auto;\n\t}\n\n\t.edit-site-style-book__example {\n\t\tborder-radius: 2px;\n\t\tcursor: pointer;\n\t\tdisplay: flex;\n\t\tflex-direction: column;\n\t\tgap: 40px;\n\t\tmargin-bottom: 40px;\n\t\tpadding: 16px;\n\t\twidth: 100%;\n\t\tbox-sizing: border-box;\n\t}\n\n\t.edit-site-style-book__example.is-selected {\n\t\tbox-shadow: 0 0 0 1px var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));\n\t}\n\n\t.edit-site-style-book__example:focus:not(:disabled) {\n\t\tbox-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-components-color-accent, var(--wp-admin-theme-color, #007cba));\n\t\toutline: 3px solid transparent;\n\t}\n\n\t.edit-site-style-book__examples.is-wide .edit-site-style-book__example {\n\t\tflex-direction: row;\n\t}\n\n\t.edit-site-style-book__example-title {\n\t\tfont-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", Roboto, Oxygen-Sans, Ubuntu, Cantarell, \"Helvetica Neue\", sans-serif;\n\t\tfont-size: 11px;\n\t\tfont-weight: 500;\n\t\tline-height: normal;\n\t\tmargin: 0;\n\t\ttext-align: left;\n\t\ttext-transform: uppercase;\n\t}\n\n\t.edit-site-style-book__examples.is-wide .edit-site-style-book__example-title {\n\t\ttext-align: right;\n\t\twidth: 120px;\n\t}\n\n\t.edit-site-style-book__example-preview {\n\t\twidth: 100%;\n\t}\n\n\t.edit-site-style-book__example-preview .block-editor-block-list__insertion-point,\n\t.edit-site-style-book__example-preview .block-list-appender {\n\t\tdisplay: none;\n\t}\n\n\t.edit-site-style-book__example-preview .is-root-container > .wp-block:first-child {\n\t\tmargin-top: 0;\n\t}\n\t.edit-site-style-book__example-preview .is-root-container > .wp-block:last-child {\n\t\tmargin-bottom: 0;\n\t}\n`;\n\nfunction getExamples() {\n\t// Use our own example for the Heading block so that we can show multiple\n\t// heading levels.\n\tconst headingsExample = {\n\t\tname: 'core/heading',\n\t\ttitle: __( 'Headings' ),\n\t\tcategory: 'text',\n\t\tblocks: [\n\t\t\tcreateBlock( 'core/heading', {\n\t\t\t\tcontent: __( 'Code Is Poetry' ),\n\t\t\t\tlevel: 1,\n\t\t\t} ),\n\t\t\tcreateBlock( 'core/heading', {\n\t\t\t\tcontent: __( 'Code Is Poetry' ),\n\t\t\t\tlevel: 2,\n\t\t\t} ),\n\t\t\tcreateBlock( 'core/heading', {\n\t\t\t\tcontent: __( 'Code Is Poetry' ),\n\t\t\t\tlevel: 3,\n\t\t\t} ),\n\t\t\tcreateBlock( 'core/heading', {\n\t\t\t\tcontent: __( 'Code Is Poetry' ),\n\t\t\t\tlevel: 4,\n\t\t\t} ),\n\t\t\tcreateBlock( 'core/heading', {\n\t\t\t\tcontent: __( 'Code Is Poetry' ),\n\t\t\t\tlevel: 5,\n\t\t\t} ),\n\t\t],\n\t};\n\n\tconst otherExamples = getBlockTypes()\n\t\t.filter( ( blockType ) => {\n\t\t\tconst { name, example, supports } = blockType;\n\t\t\treturn (\n\t\t\t\tname !== 'core/heading' &&\n\t\t\t\t!! example &&\n\t\t\t\tsupports.inserter !== false\n\t\t\t);\n\t\t} )\n\t\t.map( ( blockType ) => ( {\n\t\t\tname: blockType.name,\n\t\t\ttitle: blockType.title,\n\t\t\tcategory: blockType.category,\n\t\t\tblocks: getBlockFromExample( blockType.name, blockType.example ),\n\t\t} ) );\n\n\treturn [ headingsExample, ...otherExamples ];\n}\n\nfunction StyleBook( { isSelected, onSelect, onClose } ) {\n\tconst [ resizeObserver, sizes ] = useResizeObserver();\n\tconst focusOnMountRef = useFocusOnMount( 'firstElement' );\n\tconst sectionFocusReturnRef = useFocusReturn();\n\n\tconst [ textColor ] = useGlobalStyle( 'color.text' );\n\tconst [ backgroundColor ] = useGlobalStyle( 'color.background' );\n\tconst examples = useMemo( getExamples, [] );\n\tconst tabs = useMemo(\n\t\t() =>\n\t\t\tgetCategories()\n\t\t\t\t.filter( ( category ) =>\n\t\t\t\t\texamples.some(\n\t\t\t\t\t\t( example ) => example.category === category.slug\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t\t.map( ( category ) => ( {\n\t\t\t\t\tname: category.slug,\n\t\t\t\t\ttitle: category.title,\n\t\t\t\t\ticon: category.icon,\n\t\t\t\t} ) ),\n\t\t[ examples ]\n\t);\n\n\tconst originalSettings = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings(),\n\t\t[]\n\t);\n\tconst settings = useMemo(\n\t\t() => ( { ...originalSettings, __unstableIsPreviewMode: true } ),\n\t\t[ originalSettings ]\n\t);\n\n\tfunction closeOnEscape( event ) {\n\t\tif ( event.keyCode === ESCAPE && ! event.defaultPrevented ) {\n\t\t\tevent.preventDefault();\n\t\t\tonClose();\n\t\t}\n\t}\n\n\treturn (\n\t\t<StyleBookFill>\n\t\t\t{ /* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */ }\n\t\t\t<section\n\t\t\t\tclassName={ classnames( 'edit-site-style-book', {\n\t\t\t\t\t'is-wide': sizes.width > 600,\n\t\t\t\t} ) }\n\t\t\t\tstyle={ {\n\t\t\t\t\tcolor: textColor,\n\t\t\t\t\tbackground: backgroundColor,\n\t\t\t\t} }\n\t\t\t\taria-label={ __( 'Style Book' ) }\n\t\t\t\tonKeyDown={ closeOnEscape }\n\t\t\t\tref={ useMergeRefs( [\n\t\t\t\t\tsectionFocusReturnRef,\n\t\t\t\t\tfocusOnMountRef,\n\t\t\t\t] ) }\n\t\t\t>\n\t\t\t\t{ resizeObserver }\n\t\t\t\t<Button\n\t\t\t\t\tclassName=\"edit-site-style-book__close-button\"\n\t\t\t\t\ticon={ closeSmall }\n\t\t\t\t\tlabel={ __( 'Close Style Book' ) }\n\t\t\t\t\tonClick={ onClose }\n\t\t\t\t\tshowTooltip={ false }\n\t\t\t\t/>\n\t\t\t\t<TabPanel\n\t\t\t\t\tclassName=\"edit-site-style-book__tab-panel\"\n\t\t\t\t\ttabs={ tabs }\n\t\t\t\t>\n\t\t\t\t\t{ ( tab ) => (\n\t\t\t\t\t\t<Iframe\n\t\t\t\t\t\t\tclassName=\"edit-site-style-book__iframe\"\n\t\t\t\t\t\t\thead={\n\t\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t\t<EditorStyles styles={ settings.styles } />\n\t\t\t\t\t\t\t\t\t<style>\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t// Forming a \"block formatting context\" to prevent margin collapsing.\n\t\t\t\t\t\t\t\t\t\t\t// @see https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context\n\t\t\t\t\t\t\t\t\t\t\t`.is-root-container { display: flow-root; }\n\t\t\t\t\t\t\t\t\t\t\tbody { position: relative; padding: 32px !important; }` +\n\t\t\t\t\t\t\t\t\t\t\t\tSTYLE_BOOK_IFRAME_STYLES\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t</style>\n\t\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tname=\"style-book-canvas\"\n\t\t\t\t\t\t\ttabIndex={ 0 }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ /* Filters need to be rendered before children to avoid Safari rendering issues. */ }\n\t\t\t\t\t\t\t{ settings.svgFilters }\n\t\t\t\t\t\t\t<Examples\n\t\t\t\t\t\t\t\tclassName={ classnames(\n\t\t\t\t\t\t\t\t\t'edit-site-style-book__examples',\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t'is-wide': sizes.width > 600,\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\texamples={ examples }\n\t\t\t\t\t\t\t\tcategory={ tab.name }\n\t\t\t\t\t\t\t\tlabel={ sprintf(\n\t\t\t\t\t\t\t\t\t// translators: %s: Category of blocks, e.g. Text.\n\t\t\t\t\t\t\t\t\t__(\n\t\t\t\t\t\t\t\t\t\t'Examples of blocks in the %s category'\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\ttab.title\n\t\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t\tisSelected={ isSelected }\n\t\t\t\t\t\t\t\tonSelect={ onSelect }\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</Iframe>\n\t\t\t\t\t) }\n\t\t\t\t</TabPanel>\n\t\t\t</section>\n\t\t</StyleBookFill>\n\t);\n}\n\nconst Examples = memo(\n\t( { className, examples, category, label, isSelected, onSelect } ) => {\n\t\tconst composite = useCompositeState( { orientation: 'vertical' } );\n\t\treturn (\n\t\t\t<Composite\n\t\t\t\t{ ...composite }\n\t\t\t\tclassName={ className }\n\t\t\t\taria-label={ label }\n\t\t\t>\n\t\t\t\t{ examples\n\t\t\t\t\t.filter( ( example ) => example.category === category )\n\t\t\t\t\t.map( ( example ) => (\n\t\t\t\t\t\t<Example\n\t\t\t\t\t\t\tkey={ example.name }\n\t\t\t\t\t\t\tid={ `example-${ example.name }` }\n\t\t\t\t\t\t\tcomposite={ composite }\n\t\t\t\t\t\t\ttitle={ example.title }\n\t\t\t\t\t\t\tblocks={ example.blocks }\n\t\t\t\t\t\t\tisSelected={ isSelected( example.name ) }\n\t\t\t\t\t\t\tonClick={ () => {\n\t\t\t\t\t\t\t\tonSelect( example.name );\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</Composite>\n\t\t);\n\t}\n);\n\nconst Example = ( { composite, id, title, blocks, isSelected, onClick } ) => {\n\tconst originalSettings = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSettings(),\n\t\t[]\n\t);\n\tconst settings = useMemo(\n\t\t() => ( { ...originalSettings, __unstableIsPreviewMode: true } ),\n\t\t[ originalSettings ]\n\t);\n\n\t// Cache the list of blocks to avoid additional processing when the component is re-rendered.\n\tconst renderedBlocks = useMemo(\n\t\t() => ( Array.isArray( blocks ) ? blocks : [ blocks ] ),\n\t\t[ blocks ]\n\t);\n\n\treturn (\n\t\t<CompositeItem\n\t\t\t{ ...composite }\n\t\t\tclassName={ classnames( 'edit-site-style-book__example', {\n\t\t\t\t'is-selected': isSelected,\n\t\t\t} ) }\n\t\t\tid={ id }\n\t\t\taria-label={ sprintf(\n\t\t\t\t// translators: %s: Title of a block, e.g. Heading.\n\t\t\t\t__( 'Open %s styles in Styles panel' ),\n\t\t\t\ttitle\n\t\t\t) }\n\t\t\tonClick={ onClick }\n\t\t\trole=\"button\"\n\t\t\tas=\"div\"\n\t\t>\n\t\t\t<span className=\"edit-site-style-book__example-title\">\n\t\t\t\t{ title }\n\t\t\t</span>\n\t\t\t<div className=\"edit-site-style-book__example-preview\" aria-hidden>\n\t\t\t\t<Disabled className=\"edit-site-style-book__example-preview__content\">\n\t\t\t\t\t<ExperimentalBlockEditorProvider\n\t\t\t\t\t\tvalue={ renderedBlocks }\n\t\t\t\t\t\tsettings={ settings }\n\t\t\t\t\t>\n\t\t\t\t\t\t<BlockList renderAppender={ false } />\n\t\t\t\t\t</ExperimentalBlockEditorProvider>\n\t\t\t\t</Disabled>\n\t\t\t</div>\n\t\t</CompositeItem>\n\t);\n};\n\nfunction useHasStyleBook() {\n\tconst fills = useSlotFills( SLOT_FILL_NAME );\n\treturn !! fills?.length;\n}\n\nStyleBook.Slot = StyleBookSlot;\nexport default StyleBook;\nexport { useHasStyleBook };\n"]}
|