diff --git a/build/index.asset.php b/build/index.asset.php index b304c3bf..d69320f2 100644 --- a/build/index.asset.php +++ b/build/index.asset.php @@ -1 +1 @@ - array('wp-api-fetch', 'wp-components', 'wp-data', 'wp-edit-site', 'wp-element', 'wp-i18n', 'wp-notices', 'wp-plugins', 'wp-primitives'), 'version' => 'efb26a3f1a231e36b65f'); + array('wp-api-fetch', 'wp-components', 'wp-data', 'wp-edit-site', 'wp-element', 'wp-i18n', 'wp-notices', 'wp-plugins', 'wp-primitives'), 'version' => '093a79db63f8c804d2b2'); diff --git a/build/index.js b/build/index.js index 696c48b2..7c9eab44 100644 --- a/build/index.js +++ b/build/index.js @@ -234,6 +234,10 @@ const StyleVariations = () => { createErrorNotice } = (0,_wordpress_data__WEBPACK_IMPORTED_MODULE_7__.useDispatch)(_wordpress_notices__WEBPACK_IMPORTED_MODULE_6__.store); + if (!canReset) { + return null; // This requires the Gutenberg plugin. + } + async function createVariation() { try { const response = await _wordpress_api_fetch__WEBPACK_IMPORTED_MODULE_4___default()({ @@ -338,14 +342,20 @@ const BlankTheme = () => { }, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Create blank theme')))); }; -const CreateBlockThemePlugin = () => (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_edit_site__WEBPACK_IMPORTED_MODULE_2__.PluginSidebarMoreMenuItem, { - target: "create-block-theme-sidebar", - icon: _wordpress_icons__WEBPACK_IMPORTED_MODULE_8__["default"] -}, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Create Block Theme')), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_edit_site__WEBPACK_IMPORTED_MODULE_2__.PluginSidebar, { - name: "create-block-theme-sidebar", - icon: _wordpress_icons__WEBPACK_IMPORTED_MODULE_8__["default"], - title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Create Block Theme') -}, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(GlobalStylesProvider, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(StyleVariations, null), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(BlankTheme, null)))); +const CreateBlockThemePlugin = () => { + if (!GlobalStylesProvider) { + return null; // This feature requires the latest version of Gutenberg. + } + + return (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.Fragment, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_edit_site__WEBPACK_IMPORTED_MODULE_2__.PluginSidebarMoreMenuItem, { + target: "create-block-theme-sidebar", + icon: _wordpress_icons__WEBPACK_IMPORTED_MODULE_8__["default"] + }, (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Create Block Theme')), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(_wordpress_edit_site__WEBPACK_IMPORTED_MODULE_2__.PluginSidebar, { + name: "create-block-theme-sidebar", + icon: _wordpress_icons__WEBPACK_IMPORTED_MODULE_8__["default"], + title: (0,_wordpress_i18n__WEBPACK_IMPORTED_MODULE_3__.__)('Create Block Theme') + }, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(GlobalStylesProvider, null, (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(StyleVariations, null), (0,_wordpress_element__WEBPACK_IMPORTED_MODULE_0__.createElement)(BlankTheme, null)))); +}; (0,_wordpress_plugins__WEBPACK_IMPORTED_MODULE_1__.registerPlugin)('plugin-sidebar-expanded-test', { render: CreateBlockThemePlugin diff --git a/build/index.js.map b/build/index.js.map index 1e18c5b3..220f078a 100644 --- a/build/index.js.map +++ b/build/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","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AE,+CAAF;EAA1H,EAHD,EAIC,kEAAC,8DAAD;IAAa,KAAK,EAAGA,mDAAE,CAAE,QAAF,CAAvB;IAAsC,QAAQ,EAAK8B,KAAF,IAAaG,QAAQ,CAAE,EAAE,GAAGD,KAAL;MAAY,UAAUF;IAAtB,CAAF,CAAtE;IAA0G,WAAW,EAAG9B,mDAAE,CAAE,oBAAF;EAA1H,EAJD,EAKC,kEAAC,8DAAD;IAAa,KAAK,EAAGA,mDAAE,CAAE,YAAF,CAAvB;IAA0C,QAAQ,EAAK8B,KAAF,IAAaG,QAAQ,CAAE,EAAE,GAAGD,KAAL;MAAY,cAAcF;IAA1B,CAAF,CAA1E;IAAkH,WAAW,EAAG9B,mDAAE,CAAE,wBAAF;EAAlI,EALD,EAMC,kEAAC,yDAAD;IAAQ,OAAO,EAAC,WAAhB;IAA4B,OAAO,EAAG,MAAMkC,gBAAgB;EAA5D,GAAmElC,mDAAE,CAAE,oBAAF,CAArE,CAND,CADD,CADD;AAYA,CAzCD;;AA2CA,MAAMqC,sBAAsB,GAAG,MAC9B,kEAAC,wDAAD,QACC,kEAAC,2EAAD;EAA2B,MAAM,EAAC,4BAAlC;EAA+D,IAAI,EAAGxC,wDAAYA;AAAlF,GACGG,mDAAE,CAAE,oBAAF,CADL,CADD,EAIC,kEAAC,+DAAD;EAAe,IAAI,EAAC,4BAApB;EAAiD,IAAI,EAAGH,wDAAxD;EAAuE,KAAK,EAAGG,mDAAE,CAAE,oBAAF;AAAjF,GACC,kEAAC,oBAAD,QACC,kEAAC,eAAD,OADD,EAEC,kEAAC,UAAD,OAFD,CADD,CAJD,CADD;;AAcAN,kEAAc,CAAE,8BAAF,EAAkC;EAC/C4C,MAAM,EAAED;AADuC,CAAlC,CAAd,C","sources":["webpack://create-block-theme/./node_modules/@wordpress/icons/build-module/library/block-default.js","webpack://create-block-theme/external window [\"wp\",\"apiFetch\"]","webpack://create-block-theme/external window [\"wp\",\"components\"]","webpack://create-block-theme/external window [\"wp\",\"data\"]","webpack://create-block-theme/external window [\"wp\",\"editSite\"]","webpack://create-block-theme/external window [\"wp\",\"element\"]","webpack://create-block-theme/external window [\"wp\",\"i18n\"]","webpack://create-block-theme/external window [\"wp\",\"notices\"]","webpack://create-block-theme/external window [\"wp\",\"plugins\"]","webpack://create-block-theme/external window [\"wp\",\"primitives\"]","webpack://create-block-theme/webpack/bootstrap","webpack://create-block-theme/webpack/runtime/compat get default export","webpack://create-block-theme/webpack/runtime/define property getters","webpack://create-block-theme/webpack/runtime/hasOwnProperty shorthand","webpack://create-block-theme/webpack/runtime/make namespace object","webpack://create-block-theme/./src/index.js"],"sourcesContent":["import { createElement } from \"@wordpress/element\";\n\n/**\n * WordPress dependencies\n */\nimport { SVG, Path } from '@wordpress/primitives';\nconst blockDefault = createElement(SVG, {\n xmlns: \"http://www.w3.org/2000/svg\",\n viewBox: \"0 0 24 24\"\n}, createElement(Path, {\n d: \"M19 8h-1V6h-5v2h-2V6H6v2H5c-1.1 0-2 .9-2 2v8c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2v-8c0-1.1-.9-2-2-2zm.5 10c0 .3-.2.5-.5.5H5c-.3 0-.5-.2-.5-.5v-8c0-.3.2-.5.5-.5h14c.3 0 .5.2.5.5v8z\"\n}));\nexport default blockDefault;\n//# sourceMappingURL=block-default.js.map","module.exports = window[\"wp\"][\"apiFetch\"];","module.exports = window[\"wp\"][\"components\"];","module.exports = window[\"wp\"][\"data\"];","module.exports = window[\"wp\"][\"editSite\"];","module.exports = window[\"wp\"][\"element\"];","module.exports = window[\"wp\"][\"i18n\"];","module.exports = window[\"wp\"][\"notices\"];","module.exports = window[\"wp\"][\"plugins\"];","module.exports = window[\"wp\"][\"primitives\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { registerPlugin } from '@wordpress/plugins';\nimport { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/edit-site';\nimport { blockDefault } from '@wordpress/icons';\nimport { Fragment, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { Button, MenuGroup, MenuItem, PanelBody, TextControl } from '@wordpress/components';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useDispatch } from '@wordpress/data';\n\nconst GlobalStylesProvider = wp.editSite.GlobalStylesProvider;\n\nconst StyleVariations = () => {\n\tconst [ variationName, setVariationName ] = useState( '' );\n\tconst [ canReset, onReset ] = wp.editSite.useGlobalStylesReset();\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tasync function createVariation() {\n\t\ttry {\n\t\t\tconst response = await apiFetch( {\n\t\t\t\tpath: '/create-block-theme/v1/variation/' + variationName,\n\t\t\t} );\n\n\t\t\t// Clear global styles customizations\n\t\t\tonReset();\n\n\t\t\t// Reload variations\n\t\t\t// We need to invalidate and maybe refetch __experimentalGetCurrentThemeGlobalStylesVariations(),\n\t\t\tif ( response.req.status === 200 ) {\n\t\t\t\tcreateErrorNotice( __( 'Variation created successfully' ), { type: 'snackbar' } );\n\t\t\t}\n\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 site export.' );\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t}\n\t}\n\n\treturn (\n\t\t\n\t\t\t\n\t\t\t\t setVariationName( value ) } placeholder={ __( 'Variation name' ) }>\n\t\t\t\t\n\t\t\t\n\t\t\n\t);\n};\n\nconst BlankTheme = () => {\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst [ theme, setTheme ] = useState( {\n\t\t\"name\": \"\",\n\t\t\"description\": \"\",\n\t\t\"uri\": \"\",\n\t\t\"author\": \"\",\n\t\t\"author_uri\": \"\",\n\t} );\n\tasync function createBlankTheme() {\n\t\ttry {\n\t\t\tconst response = await apiFetch( {\n\t\t\t\tpath: '/create-block-theme/v1/blank-theme',\n\t\t\t\tmethod: 'POST',\n\t\t\t\tdata: theme,\n\t\t\t} );\n\n\t\t\tif ( response.req.status === 200 ) {\n\t\t\t\tcreateErrorNotice( __( 'New theme created' ), { type: 'snackbar' } );\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 site export.' );\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t}\n\t}\n\n\treturn (\n\t\t\n\t\t\t\n\t\t\t\t setTheme( { ...theme, \"name\": value } ) } placeholder={ __( 'Theme name' ) }>\n\t\t\t\t setTheme( { ...theme, \"description\": value } ) } placeholder={ __( 'A short description of the theme' ) }>\n\t\t\t\t setTheme( { ...theme, \"uri\": value } ) } placeholder={ __( 'https://github.com/wordpress/twentytwentytwo/' ) }>\n\t\t\t\t setTheme( { ...theme, \"author\": value } ) } placeholder={ __( 'the WordPress team' ) }>\n\t\t\t\t setTheme( { ...theme, \"author_uri\": value } ) } placeholder={ __( 'https://wordpress.org/' ) }>\n\t\t\t\t\n\t\t\t\n\t\t\n\t)\n}\n\nconst CreateBlockThemePlugin = () => (\n\t\n\t\t\n\t\t\t{ __( 'Create Block Theme' ) }\n\t\t\n\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\n\t\n);\n\nregisterPlugin( 'plugin-sidebar-expanded-test', {\n\trender: CreateBlockThemePlugin,\n} );\n"],"names":["registerPlugin","PluginSidebar","PluginSidebarMoreMenuItem","blockDefault","Fragment","useState","__","apiFetch","Button","MenuGroup","MenuItem","PanelBody","TextControl","store","noticesStore","useDispatch","GlobalStylesProvider","wp","editSite","StyleVariations","variationName","setVariationName","canReset","onReset","useGlobalStylesReset","createErrorNotice","createVariation","response","path","req","status","type","error","errorMessage","message","code","value","BlankTheme","theme","setTheme","createBlankTheme","method","data","CreateBlockThemePlugin","render"],"sourceRoot":""} \ No newline at end of file +{"version":3,"file":"index.js","mappings":";;;;;;;;;;;;;;;;;;AAAmD;;AAEnD;AACA;AACA;AACkD;AAClD,qBAAqB,iEAAa,CAAC,sDAAG;AACtC;AACA;AACA,CAAC,EAAE,iEAAa,CAAC,uDAAI;AACrB;AACA,CAAC;AACD,iEAAe,YAAY,EAAC;AAC5B;;;;;;;;;;ACbA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;;;;;ACAA;;;;;;UCAA;UACA;;UAEA;UACA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E,YAAF,CAAvB;IAA0C,QAAQ,EAAK8B,KAAF,IAAaG,QAAQ,CAAE,EAAE,GAAGD,KAAL;MAAY,cAAcF;IAA1B,CAAF,CAA1E;IAAkH,WAAW,EAAG9B,mDAAE,CAAE,wBAAF;EAAlI,EALD,EAMC,kEAAC,yDAAD;IAAQ,OAAO,EAAC,WAAhB;IAA4B,OAAO,EAAG,MAAMkC,gBAAgB;EAA5D,GAAmElC,mDAAE,CAAE,oBAAF,CAArE,CAND,CADD,CADD;AAYA,CAzCD;;AA2CA,MAAMqC,sBAAsB,GAAG,MAAM;EACpC,IAAK,CAAE3B,oBAAP,EAA8B;IAC7B,OAAO,IAAP,CAD6B,CAChB;EACb;;EAED,OACC,kEAAC,wDAAD,QACC,kEAAC,2EAAD;IAA2B,MAAM,EAAC,4BAAlC;IAA+D,IAAI,EAAGb,wDAAYA;EAAlF,GACGG,mDAAE,CAAE,oBAAF,CADL,CADD,EAIC,kEAAC,+DAAD;IAAe,IAAI,EAAC,4BAApB;IAAiD,IAAI,EAAGH,wDAAxD;IAAuE,KAAK,EAAGG,mDAAE,CAAE,oBAAF;EAAjF,GACC,kEAAC,oBAAD,QACC,kEAAC,eAAD,OADD,EAEC,kEAAC,UAAD,OAFD,CADD,CAJD,CADD;AAaA,CAlBD;;AAoBAN,kEAAc,CAAE,8BAAF,EAAkC;EAC/C4C,MAAM,EAAED;AADuC,CAAlC,CAAd,C","sources":["webpack://create-block-theme/./node_modules/@wordpress/icons/build-module/library/block-default.js","webpack://create-block-theme/external window [\"wp\",\"apiFetch\"]","webpack://create-block-theme/external window [\"wp\",\"components\"]","webpack://create-block-theme/external window [\"wp\",\"data\"]","webpack://create-block-theme/external window [\"wp\",\"editSite\"]","webpack://create-block-theme/external window [\"wp\",\"element\"]","webpack://create-block-theme/external window [\"wp\",\"i18n\"]","webpack://create-block-theme/external window [\"wp\",\"notices\"]","webpack://create-block-theme/external window [\"wp\",\"plugins\"]","webpack://create-block-theme/external window [\"wp\",\"primitives\"]","webpack://create-block-theme/webpack/bootstrap","webpack://create-block-theme/webpack/runtime/compat get default export","webpack://create-block-theme/webpack/runtime/define property getters","webpack://create-block-theme/webpack/runtime/hasOwnProperty shorthand","webpack://create-block-theme/webpack/runtime/make namespace object","webpack://create-block-theme/./src/index.js"],"sourcesContent":["import { createElement } from \"@wordpress/element\";\n\n/**\n * WordPress dependencies\n */\nimport { SVG, Path } from '@wordpress/primitives';\nconst blockDefault = createElement(SVG, {\n xmlns: \"http://www.w3.org/2000/svg\",\n viewBox: \"0 0 24 24\"\n}, createElement(Path, {\n d: \"M19 8h-1V6h-5v2h-2V6H6v2H5c-1.1 0-2 .9-2 2v8c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2v-8c0-1.1-.9-2-2-2zm.5 10c0 .3-.2.5-.5.5H5c-.3 0-.5-.2-.5-.5v-8c0-.3.2-.5.5-.5h14c.3 0 .5.2.5.5v8z\"\n}));\nexport default blockDefault;\n//# sourceMappingURL=block-default.js.map","module.exports = window[\"wp\"][\"apiFetch\"];","module.exports = window[\"wp\"][\"components\"];","module.exports = window[\"wp\"][\"data\"];","module.exports = window[\"wp\"][\"editSite\"];","module.exports = window[\"wp\"][\"element\"];","module.exports = window[\"wp\"][\"i18n\"];","module.exports = window[\"wp\"][\"notices\"];","module.exports = window[\"wp\"][\"plugins\"];","module.exports = window[\"wp\"][\"primitives\"];","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tvar cachedModule = __webpack_module_cache__[moduleId];\n\tif (cachedModule !== undefined) {\n\t\treturn cachedModule.exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// getDefaultExport function for compatibility with non-harmony modules\n__webpack_require__.n = (module) => {\n\tvar getter = module && module.__esModule ?\n\t\t() => (module['default']) :\n\t\t() => (module);\n\t__webpack_require__.d(getter, { a: getter });\n\treturn getter;\n};","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","import { registerPlugin } from '@wordpress/plugins';\nimport { PluginSidebar, PluginSidebarMoreMenuItem } from '@wordpress/edit-site';\nimport { blockDefault } from '@wordpress/icons';\nimport { Fragment, useState } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport apiFetch from '@wordpress/api-fetch';\nimport { Button, MenuGroup, MenuItem, PanelBody, TextControl } from '@wordpress/components';\nimport { store as noticesStore } from '@wordpress/notices';\nimport { useDispatch } from '@wordpress/data';\n\nconst GlobalStylesProvider = wp.editSite.GlobalStylesProvider;\n\nconst StyleVariations = () => {\n\tconst [ variationName, setVariationName ] = useState( '' );\n\tconst [ canReset, onReset ] = wp.editSite.useGlobalStylesReset();\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\n\tif ( ! canReset ) {\n\t\treturn null; // This requires the Gutenberg plugin.\n\t}\n\n\tasync function createVariation() {\n\t\ttry {\n\t\t\tconst response = await apiFetch( {\n\t\t\t\tpath: '/create-block-theme/v1/variation/' + variationName,\n\t\t\t} );\n\n\t\t\t// Clear global styles customizations\n\t\t\tonReset();\n\n\t\t\t// Reload variations\n\t\t\t// We need to invalidate and maybe refetch __experimentalGetCurrentThemeGlobalStylesVariations(),\n\t\t\tif ( response.req.status === 200 ) {\n\t\t\t\tcreateErrorNotice( __( 'Variation created successfully' ), { type: 'snackbar' } );\n\t\t\t}\n\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 site export.' );\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t}\n\t}\n\n\treturn (\n\t\t\n\t\t\t\n\t\t\t\t setVariationName( value ) } placeholder={ __( 'Variation name' ) }>\n\t\t\t\t\n\t\t\t\n\t\t\n\t);\n};\n\nconst BlankTheme = () => {\n\tconst { createErrorNotice } = useDispatch( noticesStore );\n\tconst [ theme, setTheme ] = useState( {\n\t\t\"name\": \"\",\n\t\t\"description\": \"\",\n\t\t\"uri\": \"\",\n\t\t\"author\": \"\",\n\t\t\"author_uri\": \"\",\n\t} );\n\tasync function createBlankTheme() {\n\t\ttry {\n\t\t\tconst response = await apiFetch( {\n\t\t\t\tpath: '/create-block-theme/v1/blank-theme',\n\t\t\t\tmethod: 'POST',\n\t\t\t\tdata: theme,\n\t\t\t} );\n\n\t\t\tif ( response.req.status === 200 ) {\n\t\t\t\tcreateErrorNotice( __( 'New theme created' ), { type: 'snackbar' } );\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 site export.' );\n\t\t\tcreateErrorNotice( errorMessage, { type: 'snackbar' } );\n\t\t}\n\t}\n\n\treturn (\n\t\t\n\t\t\t\n\t\t\t\t setTheme( { ...theme, \"name\": value } ) } placeholder={ __( 'Theme name' ) }>\n\t\t\t\t setTheme( { ...theme, \"description\": value } ) } placeholder={ __( 'A short description of the theme' ) }>\n\t\t\t\t setTheme( { ...theme, \"uri\": value } ) } placeholder={ __( 'https://github.com/wordpress/twentytwentytwo/' ) }>\n\t\t\t\t setTheme( { ...theme, \"author\": value } ) } placeholder={ __( 'the WordPress team' ) }>\n\t\t\t\t setTheme( { ...theme, \"author_uri\": value } ) } placeholder={ __( 'https://wordpress.org/' ) }>\n\t\t\t\t\n\t\t\t\n\t\t\n\t)\n}\n\nconst CreateBlockThemePlugin = () => {\n\tif ( ! GlobalStylesProvider ) {\n\t\treturn null; // This feature requires the latest version of Gutenberg.\n\t}\n\n\treturn (\n\t\t\n\t\t\t\n\t\t\t\t{ __( 'Create Block Theme' ) }\n\t\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\n\t\t\n\t);\n};\n\nregisterPlugin( 'plugin-sidebar-expanded-test', {\n\trender: CreateBlockThemePlugin,\n} );\n"],"names":["registerPlugin","PluginSidebar","PluginSidebarMoreMenuItem","blockDefault","Fragment","useState","__","apiFetch","Button","MenuGroup","MenuItem","PanelBody","TextControl","store","noticesStore","useDispatch","GlobalStylesProvider","wp","editSite","StyleVariations","variationName","setVariationName","canReset","onReset","useGlobalStylesReset","createErrorNotice","createVariation","response","path","req","status","type","error","errorMessage","message","code","value","BlankTheme","theme","setTheme","createBlankTheme","method","data","CreateBlockThemePlugin","render"],"sourceRoot":""} \ No newline at end of file diff --git a/src/index.js b/src/index.js index fc673768..a10b9942 100644 --- a/src/index.js +++ b/src/index.js @@ -15,6 +15,10 @@ const StyleVariations = () => { const [ canReset, onReset ] = wp.editSite.useGlobalStylesReset(); const { createErrorNotice } = useDispatch( noticesStore ); + if ( ! canReset ) { + return null; // This requires the Gutenberg plugin. + } + async function createVariation() { try { const response = await apiFetch( { @@ -92,19 +96,25 @@ const BlankTheme = () => { ) } -const CreateBlockThemePlugin = () => ( - - - { __( 'Create Block Theme' ) } - - - - - - - - -); +const CreateBlockThemePlugin = () => { + if ( ! GlobalStylesProvider ) { + return null; // This feature requires the latest version of Gutenberg. + } + + return ( + + + { __( 'Create Block Theme' ) } + + + + + + + + + ); +}; registerPlugin( 'plugin-sidebar-expanded-test', { render: CreateBlockThemePlugin,