@wordpress/customize-widgets 5.54.0 → 5.55.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/build/components/block-appender/index.cjs +1 -1
- package/build/components/block-appender/index.cjs.map +1 -1
- package/build/components/block-inspector-button/index.cjs +1 -1
- package/build/components/block-inspector-button/index.cjs.map +1 -1
- package/build/components/customize-widgets/index.cjs +1 -1
- package/build/components/customize-widgets/index.cjs.map +1 -1
- package/build/components/error-boundary/index.cjs +115 -16
- package/build/components/error-boundary/index.cjs.map +3 -3
- package/build/components/focus-control/index.cjs +1 -1
- package/build/components/focus-control/index.cjs.map +1 -1
- package/build/components/header/index.cjs +1 -1
- package/build/components/header/index.cjs.map +1 -1
- package/build/components/inserter/index.cjs +1 -1
- package/build/components/inserter/index.cjs.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs +1 -1
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.cjs +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.cjs.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/shortcut.cjs +1 -1
- package/build/components/keyboard-shortcut-help-modal/shortcut.cjs.map +1 -1
- package/build/components/more-menu/index.cjs +1 -1
- package/build/components/more-menu/index.cjs.map +1 -1
- package/build/components/sidebar-block-editor/index.cjs +1 -2
- package/build/components/sidebar-block-editor/index.cjs.map +3 -3
- package/build/components/sidebar-block-editor/sidebar-editor-provider.cjs +1 -1
- package/build/components/sidebar-block-editor/sidebar-editor-provider.cjs.map +1 -1
- package/build/components/sidebar-controls/index.cjs +1 -1
- package/build/components/sidebar-controls/index.cjs.map +1 -1
- package/build/components/welcome-guide/index.cjs +1 -1
- package/build/components/welcome-guide/index.cjs.map +1 -1
- package/build/filters/move-to-sidebar.cjs +1 -1
- package/build/filters/move-to-sidebar.cjs.map +1 -1
- package/build/filters/wide-widget-display.cjs +1 -1
- package/build/filters/wide-widget-display.cjs.map +1 -1
- package/build/index.cjs +1 -1
- package/build/index.cjs.map +1 -1
- package/build-module/components/block-appender/index.mjs +1 -1
- package/build-module/components/block-appender/index.mjs.map +1 -1
- package/build-module/components/block-inspector-button/index.mjs +1 -1
- package/build-module/components/block-inspector-button/index.mjs.map +1 -1
- package/build-module/components/customize-widgets/index.mjs +1 -1
- package/build-module/components/customize-widgets/index.mjs.map +1 -1
- package/build-module/components/error-boundary/index.mjs +116 -17
- package/build-module/components/error-boundary/index.mjs.map +3 -3
- package/build-module/components/focus-control/index.mjs +1 -1
- package/build-module/components/focus-control/index.mjs.map +1 -1
- package/build-module/components/header/index.mjs +1 -1
- package/build-module/components/header/index.mjs.map +1 -1
- package/build-module/components/inserter/index.mjs +1 -1
- package/build-module/components/inserter/index.mjs.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.mjs +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.mjs.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs.map +1 -1
- package/build-module/components/more-menu/index.mjs +1 -1
- package/build-module/components/more-menu/index.mjs.map +1 -1
- package/build-module/components/sidebar-block-editor/index.mjs +1 -2
- package/build-module/components/sidebar-block-editor/index.mjs.map +3 -3
- package/build-module/components/sidebar-block-editor/sidebar-editor-provider.mjs +1 -1
- package/build-module/components/sidebar-block-editor/sidebar-editor-provider.mjs.map +1 -1
- package/build-module/components/sidebar-controls/index.mjs +1 -1
- package/build-module/components/sidebar-controls/index.mjs.map +1 -1
- package/build-module/components/welcome-guide/index.mjs +1 -1
- package/build-module/components/welcome-guide/index.mjs.map +1 -1
- package/build-module/filters/move-to-sidebar.mjs +1 -1
- package/build-module/filters/move-to-sidebar.mjs.map +1 -1
- package/build-module/filters/wide-widget-display.mjs +1 -1
- package/build-module/filters/wide-widget-display.mjs.map +1 -1
- package/build-module/index.mjs +1 -1
- package/build-module/index.mjs.map +1 -1
- package/build-style/style-rtl.css +17 -0
- package/build-style/style.css +17 -0
- package/package.json +27 -27
- package/src/components/error-boundary/index.jsx +177 -0
- package/src/components/error-boundary/style.scss +16 -0
- package/src/components/error-boundary/test/{error-boundary.js → error-boundary.jsdom.test.jsx} +7 -3
- package/src/components/sidebar-block-editor/{index.js → index.jsx} +0 -1
- package/src/style.scss +1 -0
- package/src/components/error-boundary/index.js +0 -50
- /package/src/components/block-appender/{index.js → index.jsx} +0 -0
- /package/src/components/block-inspector-button/{index.js → index.jsx} +0 -0
- /package/src/components/customize-widgets/{index.js → index.jsx} +0 -0
- /package/src/components/focus-control/{index.js → index.jsx} +0 -0
- /package/src/components/header/{index.js → index.jsx} +0 -0
- /package/src/components/inserter/{index.js → index.jsx} +0 -0
- /package/src/components/keyboard-shortcut-help-modal/{dynamic-shortcut.js → dynamic-shortcut.jsx} +0 -0
- /package/src/components/keyboard-shortcut-help-modal/{index.js → index.jsx} +0 -0
- /package/src/components/keyboard-shortcut-help-modal/{shortcut.js → shortcut.jsx} +0 -0
- /package/src/components/more-menu/{index.js → index.jsx} +0 -0
- /package/src/components/sidebar-block-editor/{sidebar-editor-provider.js → sidebar-editor-provider.jsx} +0 -0
- /package/src/components/sidebar-controls/{index.js → index.jsx} +0 -0
- /package/src/components/welcome-guide/{index.js → index.jsx} +0 -0
- /package/src/filters/{move-to-sidebar.js → move-to-sidebar.jsx} +0 -0
- /package/src/filters/{wide-widget-display.js → wide-widget-display.jsx} +0 -0
- /package/src/{index.js → index.jsx} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/sidebar-block-editor/sidebar-editor-provider.
|
|
3
|
+
"sources": ["../../../src/components/sidebar-block-editor/sidebar-editor-provider.jsx"],
|
|
4
4
|
"sourcesContent": ["import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport useSidebarBlockEditor from './use-sidebar-block-editor';\nimport useBlocksFocusControl from '../focus-control/use-blocks-focus-control';\nimport { unlock } from '../../lock-unlock';\n\nconst { ExperimentalBlockEditorProvider } = unlock( blockEditorPrivateApis );\n\nexport default function SidebarEditorProvider( {\n\tsidebar,\n\tsettings,\n\tchildren,\n} ) {\n\tconst [ blocks, onInput, onChange ] = useSidebarBlockEditor( sidebar );\n\n\tuseBlocksFocusControl( blocks );\n\n\treturn (\n\t\t<ExperimentalBlockEditorProvider\n\t\t\tvalue={ blocks }\n\t\t\tonInput={ onInput }\n\t\t\tonChange={ onChange }\n\t\t\tsettings={ settings }\n\t\t\tuseSubRegistry={ false }\n\t\t>\n\t\t\t{ children }\n\t\t</ExperimentalBlockEditorProvider>\n\t);\n}\n"],
|
|
5
5
|
"mappings": ";AAAA,SAAS,eAAe,8BAA8B;AACtD,OAAO,2BAA2B;AAClC,OAAO,2BAA2B;AAClC,SAAS,cAAc;AAcrB;AAZF,IAAM,EAAE,gCAAgC,IAAI,OAAQ,sBAAuB;AAE5D,SAAR,sBAAwC;AAAA,EAC9C;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM,CAAE,QAAQ,SAAS,QAAS,IAAI,sBAAuB,OAAQ;AAErE,wBAAuB,MAAO;AAE9B,SACC;AAAA,IAAC;AAAA;AAAA,MACA,OAAQ;AAAA,MACR;AAAA,MACA;AAAA,MACA;AAAA,MACA,gBAAiB;AAAA,MAEf;AAAA;AAAA,EACH;AAEF;",
|
|
6
6
|
"names": []
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/customize-widgets/src/components/sidebar-controls/index.
|
|
1
|
+
// packages/customize-widgets/src/components/sidebar-controls/index.jsx
|
|
2
2
|
import { createContext, useMemo, useContext } from "@wordpress/element";
|
|
3
3
|
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
var SidebarControlsContext = createContext();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/sidebar-controls/index.
|
|
3
|
+
"sources": ["../../../src/components/sidebar-controls/index.jsx"],
|
|
4
4
|
"sourcesContent": ["import { createContext, useMemo, useContext } from '@wordpress/element';\n\nexport const SidebarControlsContext = createContext();\nSidebarControlsContext.displayName = 'SidebarControlsContext';\n\nexport default function SidebarControls( {\n\tsidebarControls,\n\tactiveSidebarControl,\n\tchildren,\n} ) {\n\tconst context = useMemo(\n\t\t() => ( {\n\t\t\tsidebarControls,\n\t\t\tactiveSidebarControl,\n\t\t} ),\n\t\t[ sidebarControls, activeSidebarControl ]\n\t);\n\n\treturn (\n\t\t<SidebarControlsContext.Provider value={ context }>\n\t\t\t{ children }\n\t\t</SidebarControlsContext.Provider>\n\t);\n}\n\nexport function useSidebarControls() {\n\tconst { sidebarControls } = useContext( SidebarControlsContext );\n\n\treturn sidebarControls;\n}\n\nexport function useActiveSidebarControl() {\n\tconst { activeSidebarControl } = useContext( SidebarControlsContext );\n\n\treturn activeSidebarControl;\n}\n"],
|
|
5
5
|
"mappings": ";AAAA,SAAS,eAAe,SAAS,kBAAkB;AAmBjD;AAjBK,IAAM,yBAAyB,cAAc;AACpD,uBAAuB,cAAc;AAEtB,SAAR,gBAAkC;AAAA,EACxC;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM,UAAU;AAAA,IACf,OAAQ;AAAA,MACP;AAAA,MACA;AAAA,IACD;AAAA,IACA,CAAE,iBAAiB,oBAAqB;AAAA,EACzC;AAEA,SACC,oBAAC,uBAAuB,UAAvB,EAAgC,OAAQ,SACtC,UACH;AAEF;AAEO,SAAS,qBAAqB;AACpC,QAAM,EAAE,gBAAgB,IAAI,WAAY,sBAAuB;AAE/D,SAAO;AACR;AAEO,SAAS,0BAA0B;AACzC,QAAM,EAAE,qBAAqB,IAAI,WAAY,sBAAuB;AAEpE,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/customize-widgets/src/components/welcome-guide/index.
|
|
1
|
+
// packages/customize-widgets/src/components/welcome-guide/index.jsx
|
|
2
2
|
import { __ } from "@wordpress/i18n";
|
|
3
3
|
import { Button, ExternalLink } from "@wordpress/components";
|
|
4
4
|
import { useDispatch } from "@wordpress/data";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/welcome-guide/index.
|
|
3
|
+
"sources": ["../../../src/components/welcome-guide/index.jsx"],
|
|
4
4
|
"sourcesContent": ["import { __ } from '@wordpress/i18n';\nimport { Button, ExternalLink } from '@wordpress/components';\nimport { useDispatch } from '@wordpress/data';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\nexport default function WelcomeGuide( { sidebar } ) {\n\tconst { toggle } = useDispatch( preferencesStore );\n\n\tconst isEntirelyBlockWidgets = sidebar\n\t\t.getWidgets()\n\t\t.every( ( widget ) => widget.id.startsWith( 'block-' ) );\n\n\treturn (\n\t\t<div className=\"customize-widgets-welcome-guide\">\n\t\t\t<div className=\"customize-widgets-welcome-guide__image__wrapper\">\n\t\t\t\t<picture>\n\t\t\t\t\t<source\n\t\t\t\t\t\tsrcSet=\"https://s.w.org/images/block-editor/welcome-editor.svg\"\n\t\t\t\t\t\tmedia=\"(prefers-reduced-motion: reduce)\"\n\t\t\t\t\t/>\n\t\t\t\t\t<img\n\t\t\t\t\t\tclassName=\"customize-widgets-welcome-guide__image\"\n\t\t\t\t\t\tsrc=\"https://s.w.org/images/block-editor/welcome-editor.gif\"\n\t\t\t\t\t\twidth=\"312\"\n\t\t\t\t\t\theight=\"240\"\n\t\t\t\t\t\talt=\"\"\n\t\t\t\t\t/>\n\t\t\t\t</picture>\n\t\t\t</div>\n\t\t\t<h1 className=\"customize-widgets-welcome-guide__heading\">\n\t\t\t\t{ __( 'Welcome to block Widgets' ) }\n\t\t\t</h1>\n\t\t\t<p className=\"customize-widgets-welcome-guide__text\">\n\t\t\t\t{ isEntirelyBlockWidgets\n\t\t\t\t\t? __(\n\t\t\t\t\t\t\t'Your theme provides different “block” areas for you to add and edit content. Try adding a search bar, social icons, or other types of blocks here and see how they’ll look on your site.'\n\t\t\t\t\t )\n\t\t\t\t\t: __(\n\t\t\t\t\t\t\t'You can now add any block to your site’s widget areas. Don’t worry, all of your favorite widgets still work flawlessly.'\n\t\t\t\t\t ) }\n\t\t\t</p>\n\t\t\t<Button\n\t\t\t\tsize=\"compact\"\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tonClick={ () =>\n\t\t\t\t\ttoggle( 'core/customize-widgets', 'welcomeGuide' )\n\t\t\t\t}\n\t\t\t>\n\t\t\t\t{ __( 'Got it' ) }\n\t\t\t</Button>\n\t\t\t<hr className=\"customize-widgets-welcome-guide__separator\" />\n\t\t\t{ ! isEntirelyBlockWidgets && (\n\t\t\t\t<p className=\"customize-widgets-welcome-guide__more-info\">\n\t\t\t\t\t{ __( 'Want to stick with the old widgets?' ) }\n\t\t\t\t\t<br />\n\t\t\t\t\t<ExternalLink\n\t\t\t\t\t\thref={ __(\n\t\t\t\t\t\t\t'https://wordpress.org/plugins/classic-widgets/'\n\t\t\t\t\t\t) }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ __( 'Get the Classic Widgets plugin.' ) }\n\t\t\t\t\t</ExternalLink>\n\t\t\t\t</p>\n\t\t\t) }\n\t\t\t<p className=\"customize-widgets-welcome-guide__more-info\">\n\t\t\t\t{ __( 'New to the block editor?' ) }\n\t\t\t\t<br />\n\t\t\t\t<ExternalLink\n\t\t\t\t\thref={ __(\n\t\t\t\t\t\t'https://wordpress.org/documentation/article/wordpress-block-editor/'\n\t\t\t\t\t) }\n\t\t\t\t>\n\t\t\t\t\t{ __( \"Here's a detailed guide.\" ) }\n\t\t\t\t</ExternalLink>\n\t\t\t</p>\n\t\t</div>\n\t);\n}\n"],
|
|
5
5
|
"mappings": ";AAAA,SAAS,UAAU;AACnB,SAAS,QAAQ,oBAAoB;AACrC,SAAS,mBAAmB;AAC5B,SAAS,SAAS,wBAAwB;AAYtC,SACC,KADD;AAVW,SAAR,aAA+B,EAAE,QAAQ,GAAI;AACnD,QAAM,EAAE,OAAO,IAAI,YAAa,gBAAiB;AAEjD,QAAM,yBAAyB,QAC7B,WAAW,EACX,MAAO,CAAE,WAAY,OAAO,GAAG,WAAY,QAAS,CAAE;AAExD,SACC,qBAAC,SAAI,WAAU,mCACd;AAAA,wBAAC,SAAI,WAAU,mDACd,+BAAC,aACA;AAAA;AAAA,QAAC;AAAA;AAAA,UACA,QAAO;AAAA,UACP,OAAM;AAAA;AAAA,MACP;AAAA,MACA;AAAA,QAAC;AAAA;AAAA,UACA,WAAU;AAAA,UACV,KAAI;AAAA,UACJ,OAAM;AAAA,UACN,QAAO;AAAA,UACP,KAAI;AAAA;AAAA,MACL;AAAA,OACD,GACD;AAAA,IACA,oBAAC,QAAG,WAAU,4CACX,aAAI,0BAA2B,GAClC;AAAA,IACA,oBAAC,OAAE,WAAU,yCACV,mCACC;AAAA,MACA;AAAA,IACA,IACA;AAAA,MACA;AAAA,IACA,GACJ;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,MAAK;AAAA,QACL,SAAQ;AAAA,QACR,SAAU,MACT,OAAQ,0BAA0B,cAAe;AAAA,QAGhD,aAAI,QAAS;AAAA;AAAA,IAChB;AAAA,IACA,oBAAC,QAAG,WAAU,8CAA6C;AAAA,IACzD,CAAE,0BACH,qBAAC,OAAE,WAAU,8CACV;AAAA,SAAI,qCAAsC;AAAA,MAC5C,oBAAC,QAAG;AAAA,MACJ;AAAA,QAAC;AAAA;AAAA,UACA,MAAO;AAAA,YACN;AAAA,UACD;AAAA,UAEE,aAAI,iCAAkC;AAAA;AAAA,MACzC;AAAA,OACD;AAAA,IAED,qBAAC,OAAE,WAAU,8CACV;AAAA,SAAI,0BAA2B;AAAA,MACjC,oBAAC,QAAG;AAAA,MACJ;AAAA,QAAC;AAAA;AAAA,UACA,MAAO;AAAA,YACN;AAAA,UACD;AAAA,UAEE,aAAI,0BAA2B;AAAA;AAAA,MAClC;AAAA,OACD;AAAA,KACD;AAEF;",
|
|
6
6
|
"names": []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/filters/move-to-sidebar.
|
|
3
|
+
"sources": ["../../src/filters/move-to-sidebar.jsx"],
|
|
4
4
|
"sourcesContent": ["import {\n\tBlockControls,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { createHigherOrderComponent } from '@wordpress/compose';\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { addFilter } from '@wordpress/hooks';\nimport { MoveToWidgetArea, getWidgetIdFromBlock } from '@wordpress/widgets';\nimport {\n\tuseSidebarControls,\n\tuseActiveSidebarControl,\n} from '../components/sidebar-controls';\nimport { useFocusControl } from '../components/focus-control';\nimport { blockToWidget } from '../utils';\n\nconst withMoveToSidebarToolbarItem = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tlet widgetId = getWidgetIdFromBlock( props );\n\t\tconst sidebarControls = useSidebarControls();\n\t\tconst activeSidebarControl = useActiveSidebarControl();\n\t\tconst hasMultipleSidebars = sidebarControls?.length > 1;\n\t\tconst blockName = props.name;\n\t\tconst clientId = props.clientId;\n\t\tconst canInsertBlockInSidebar = useSelect(\n\t\t\t( select ) => {\n\t\t\t\t// Use an empty string to represent the root block list, which\n\t\t\t\t// in the customizer editor represents a sidebar/widget area.\n\t\t\t\treturn select( blockEditorStore ).canInsertBlockType(\n\t\t\t\t\tblockName,\n\t\t\t\t\t''\n\t\t\t\t);\n\t\t\t},\n\t\t\t[ blockName ]\n\t\t);\n\t\tconst block = useSelect(\n\t\t\t( select ) => select( blockEditorStore ).getBlock( clientId ),\n\t\t\t[ clientId ]\n\t\t);\n\t\tconst { removeBlock } = useDispatch( blockEditorStore );\n\t\tconst [ , focusWidget ] = useFocusControl();\n\n\t\tfunction moveToSidebar( sidebarControlId ) {\n\t\t\tconst newSidebarControl = sidebarControls.find(\n\t\t\t\t( sidebarControl ) => sidebarControl.id === sidebarControlId\n\t\t\t);\n\n\t\t\tif ( widgetId ) {\n\t\t\t\t/**\n\t\t\t\t * If there's a widgetId, move it to the other sidebar.\n\t\t\t\t */\n\t\t\t\tconst oldSetting = activeSidebarControl.setting;\n\t\t\t\tconst newSetting = newSidebarControl.setting;\n\n\t\t\t\toldSetting( oldSetting().filter( ( id ) => id !== widgetId ) );\n\t\t\t\tnewSetting( [ ...newSetting(), widgetId ] );\n\t\t\t} else {\n\t\t\t\t/**\n\t\t\t\t * If there isn't a widgetId, it's most likely a inner block.\n\t\t\t\t * First, remove the block in the original sidebar,\n\t\t\t\t * then, create a new widget in the new sidebar and get back its widgetId.\n\t\t\t\t */\n\t\t\t\tconst sidebarAdapter = newSidebarControl.sidebarAdapter;\n\n\t\t\t\tremoveBlock( clientId );\n\t\t\t\tconst addedWidgetIds = sidebarAdapter.setWidgets( [\n\t\t\t\t\t...sidebarAdapter.getWidgets(),\n\t\t\t\t\tblockToWidget( block ),\n\t\t\t\t] );\n\t\t\t\t// The last non-null id is the added widget's id.\n\t\t\t\twidgetId = addedWidgetIds.reverse().find( ( id ) => !! id );\n\t\t\t}\n\n\t\t\t// Move focus to the moved widget and expand the sidebar.\n\t\t\tfocusWidget( widgetId );\n\t\t}\n\n\t\treturn (\n\t\t\t<>\n\t\t\t\t<BlockEdit key=\"edit\" { ...props } />\n\t\t\t\t{ hasMultipleSidebars && canInsertBlockInSidebar && (\n\t\t\t\t\t<BlockControls>\n\t\t\t\t\t\t<MoveToWidgetArea\n\t\t\t\t\t\t\twidgetAreas={ sidebarControls.map(\n\t\t\t\t\t\t\t\t( sidebarControl ) => ( {\n\t\t\t\t\t\t\t\t\tid: sidebarControl.id,\n\t\t\t\t\t\t\t\t\tname: sidebarControl.params.label,\n\t\t\t\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t\t\t\tsidebarControl.params.description,\n\t\t\t\t\t\t\t\t} )\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\tcurrentWidgetAreaId={ activeSidebarControl?.id }\n\t\t\t\t\t\t\tonSelect={ moveToSidebar }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</BlockControls>\n\t\t\t\t) }\n\t\t\t</>\n\t\t);\n\t},\n\t'withMoveToSidebarToolbarItem'\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/customize-widgets/block-edit',\n\twithMoveToSidebarToolbarItem\n);\n"],
|
|
5
5
|
"mappings": ";AAAA;AAAA,EACC;AAAA,EACA,SAAS;AAAA,OACH;AACP,SAAS,kCAAkC;AAC3C,SAAS,WAAW,mBAAmB;AACvC,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB,4BAA4B;AACvD;AAAA,EACC;AAAA,EACA;AAAA,OACM;AACP,SAAS,uBAAuB;AAChC,SAAS,qBAAqB;AAgE3B,mBACC,KADD;AA9DH,IAAM,+BAA+B;AAAA,EACpC,CAAE,cAAe,CAAE,UAAW;AAC7B,QAAI,WAAW,qBAAsB,KAAM;AAC3C,UAAM,kBAAkB,mBAAmB;AAC3C,UAAM,uBAAuB,wBAAwB;AACrD,UAAM,sBAAsB,iBAAiB,SAAS;AACtD,UAAM,YAAY,MAAM;AACxB,UAAM,WAAW,MAAM;AACvB,UAAM,0BAA0B;AAAA,MAC/B,CAAE,WAAY;AAGb,eAAO,OAAQ,gBAAiB,EAAE;AAAA,UACjC;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAAA,MACA,CAAE,SAAU;AAAA,IACb;AACA,UAAM,QAAQ;AAAA,MACb,CAAE,WAAY,OAAQ,gBAAiB,EAAE,SAAU,QAAS;AAAA,MAC5D,CAAE,QAAS;AAAA,IACZ;AACA,UAAM,EAAE,YAAY,IAAI,YAAa,gBAAiB;AACtD,UAAM,CAAE,EAAE,WAAY,IAAI,gBAAgB;AAE1C,aAAS,cAAe,kBAAmB;AAC1C,YAAM,oBAAoB,gBAAgB;AAAA,QACzC,CAAE,mBAAoB,eAAe,OAAO;AAAA,MAC7C;AAEA,UAAK,UAAW;AAIf,cAAM,aAAa,qBAAqB;AACxC,cAAM,aAAa,kBAAkB;AAErC,mBAAY,WAAW,EAAE,OAAQ,CAAE,OAAQ,OAAO,QAAS,CAAE;AAC7D,mBAAY,CAAE,GAAG,WAAW,GAAG,QAAS,CAAE;AAAA,MAC3C,OAAO;AAMN,cAAM,iBAAiB,kBAAkB;AAEzC,oBAAa,QAAS;AACtB,cAAM,iBAAiB,eAAe,WAAY;AAAA,UACjD,GAAG,eAAe,WAAW;AAAA,UAC7B,cAAe,KAAM;AAAA,QACtB,CAAE;AAEF,mBAAW,eAAe,QAAQ,EAAE,KAAM,CAAE,OAAQ,CAAC,CAAE,EAAG;AAAA,MAC3D;AAGA,kBAAa,QAAS;AAAA,IACvB;AAEA,WACC,iCACC;AAAA,0BAAC,aAAuB,GAAG,SAAZ,MAAoB;AAAA,MACjC,uBAAuB,2BACxB,oBAAC,iBACA;AAAA,QAAC;AAAA;AAAA,UACA,aAAc,gBAAgB;AAAA,YAC7B,CAAE,oBAAsB;AAAA,cACvB,IAAI,eAAe;AAAA,cACnB,MAAM,eAAe,OAAO;AAAA,cAC5B,aACC,eAAe,OAAO;AAAA,YACxB;AAAA,UACD;AAAA,UACA,qBAAsB,sBAAsB;AAAA,UAC5C,UAAW;AAAA;AAAA,MACZ,GACD;AAAA,OAEF;AAAA,EAEF;AAAA,EACA;AACD;AAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;",
|
|
6
6
|
"names": []
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/customize-widgets/src/filters/wide-widget-display.
|
|
1
|
+
// packages/customize-widgets/src/filters/wide-widget-display.jsx
|
|
2
2
|
import { createHigherOrderComponent } from "@wordpress/compose";
|
|
3
3
|
import { addFilter } from "@wordpress/hooks";
|
|
4
4
|
import { jsx } from "react/jsx-runtime";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../src/filters/wide-widget-display.
|
|
3
|
+
"sources": ["../../src/filters/wide-widget-display.jsx"],
|
|
4
4
|
"sourcesContent": ["import { createHigherOrderComponent } from '@wordpress/compose';\nimport { addFilter } from '@wordpress/hooks';\n\nconst { wp } = window;\n\nconst withWideWidgetDisplay = createHigherOrderComponent(\n\t( BlockEdit ) => ( props ) => {\n\t\tconst { idBase } = props.attributes;\n\t\tconst isWide =\n\t\t\twp.customize.Widgets.data.availableWidgets.find(\n\t\t\t\t( widget ) => widget.id_base === idBase\n\t\t\t)?.is_wide ?? false;\n\n\t\treturn <BlockEdit key=\"edit\" { ...props } isWide={ isWide } />;\n\t},\n\t'withWideWidgetDisplay'\n);\n\naddFilter(\n\t'editor.BlockEdit',\n\t'core/customize-widgets/wide-widget-display',\n\twithWideWidgetDisplay\n);\n"],
|
|
5
5
|
"mappings": ";AAAA,SAAS,kCAAkC;AAC3C,SAAS,iBAAiB;AAYjB;AAVT,IAAM,EAAE,GAAG,IAAI;AAEf,IAAM,wBAAwB;AAAA,EAC7B,CAAE,cAAe,CAAE,UAAW;AAC7B,UAAM,EAAE,OAAO,IAAI,MAAM;AACzB,UAAM,SACL,GAAG,UAAU,QAAQ,KAAK,iBAAiB;AAAA,MAC1C,CAAE,WAAY,OAAO,YAAY;AAAA,IAClC,GAAG,WAAW;AAEf,WAAO,oBAAC,aAAuB,GAAG,OAAQ,UAApB,MAAsC;AAAA,EAC7D;AAAA,EACA;AACD;AAEA;AAAA,EACC;AAAA,EACA;AAAA,EACA;AACD;",
|
|
6
6
|
"names": []
|
package/build-module/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../src/index.
|
|
3
|
+
"sources": ["../src/index.jsx"],
|
|
4
4
|
"sourcesContent": ["import { createRoot, StrictMode } from '@wordpress/element';\nimport {\n\tregisterCoreBlocks,\n\t__experimentalGetCoreBlocks,\n\t__experimentalRegisterExperimentalCoreBlocks,\n} from '@wordpress/block-library';\nimport {\n\tregisterLegacyWidgetBlock,\n\tregisterLegacyWidgetVariations,\n\tregisterWidgetGroupBlock,\n} from '@wordpress/widgets';\nimport {\n\tsetFreeformContentHandlerName,\n\tstore as blocksStore,\n} from '@wordpress/blocks';\nimport { dispatch } from '@wordpress/data';\nimport { store as preferencesStore } from '@wordpress/preferences';\nimport CustomizeWidgets from './components/customize-widgets';\nimport getSidebarSection from './controls/sidebar-section';\nimport getSidebarControl from './controls/sidebar-control';\nimport './filters';\n\nconst { wp } = window;\n\nconst DISABLED_BLOCKS = [\n\t'core/more',\n\t'core/block',\n\t'core/freeform',\n\t'core/template-part',\n];\nconst ENABLE_EXPERIMENTAL_FSE_BLOCKS = false;\n\n/**\n * Initializes the widgets block editor in the customizer.\n *\n * @param {string} editorName The editor name.\n * @param {Object} blockEditorSettings Block editor settings.\n */\nexport function initialize( editorName, blockEditorSettings ) {\n\tdispatch( preferencesStore ).setDefaults( 'core/customize-widgets', {\n\t\tfixedToolbar: false,\n\t\twelcomeGuide: true,\n\t} );\n\n\tdispatch( blocksStore ).reapplyBlockTypeFilters();\n\tconst coreBlocks = __experimentalGetCoreBlocks().filter( ( block ) => {\n\t\treturn ! (\n\t\t\tDISABLED_BLOCKS.includes( block.name ) ||\n\t\t\tblock.name.startsWith( 'core/post' ) ||\n\t\t\tblock.name.startsWith( 'core/query' ) ||\n\t\t\tblock.name.startsWith( 'core/site' ) ||\n\t\t\tblock.name.startsWith( 'core/navigation' ) ||\n\t\t\tblock.name.startsWith( 'core/term' )\n\t\t);\n\t} );\n\tregisterCoreBlocks( coreBlocks );\n\tregisterLegacyWidgetBlock();\n\tif ( globalThis.IS_GUTENBERG_PLUGIN ) {\n\t\t__experimentalRegisterExperimentalCoreBlocks( {\n\t\t\tenableFSEBlocks: ENABLE_EXPERIMENTAL_FSE_BLOCKS,\n\t\t} );\n\t}\n\tregisterLegacyWidgetVariations( blockEditorSettings );\n\tregisterWidgetGroupBlock();\n\n\t// As we are unregistering `core/freeform` to avoid the Classic block, we must\n\t// replace it with something as the default freeform content handler. Failure to\n\t// do this will result in errors in the default block parser.\n\t// see: https://github.com/WordPress/gutenberg/issues/33097\n\tsetFreeformContentHandlerName( 'core/html' );\n\n\tconst SidebarControl = getSidebarControl( blockEditorSettings );\n\n\twp.customize.sectionConstructor.sidebar = getSidebarSection();\n\twp.customize.controlConstructor.sidebar_block_editor = SidebarControl;\n\n\tconst container = document.createElement( 'div' );\n\tdocument.body.appendChild( container );\n\n\twp.customize.bind( 'ready', () => {\n\t\tconst sidebarControls = [];\n\t\twp.customize.control.each( ( control ) => {\n\t\t\tif ( control instanceof SidebarControl ) {\n\t\t\t\tsidebarControls.push( control );\n\t\t\t}\n\t\t} );\n\n\t\tcreateRoot( container ).render(\n\t\t\t<StrictMode>\n\t\t\t\t<CustomizeWidgets\n\t\t\t\t\tapi={ wp.customize }\n\t\t\t\t\tsidebarControls={ sidebarControls }\n\t\t\t\t\tblockEditorSettings={ blockEditorSettings }\n\t\t\t\t/>\n\t\t\t</StrictMode>\n\t\t);\n\t} );\n}\nexport { store } from './store';\n"],
|
|
5
5
|
"mappings": ";AAAA,SAAS,YAAY,kBAAkB;AACvC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP;AAAA,EACC;AAAA,EACA,SAAS;AAAA,OACH;AACP,SAAS,gBAAgB;AACzB,SAAS,SAAS,wBAAwB;AAC1C,OAAO,sBAAsB;AAC7B,OAAO,uBAAuB;AAC9B,OAAO,uBAAuB;AAC9B,OAAO;AA8EP,SAAS,aAAa;AATlB;AAnEJ,IAAM,EAAE,GAAG,IAAI;AAEf,IAAM,kBAAkB;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD;AACA,IAAM,iCAAiC;AAQhC,SAAS,WAAY,YAAY,qBAAsB;AAC7D,WAAU,gBAAiB,EAAE,YAAa,0BAA0B;AAAA,IACnE,cAAc;AAAA,IACd,cAAc;AAAA,EACf,CAAE;AAEF,WAAU,WAAY,EAAE,wBAAwB;AAChD,QAAM,aAAa,4BAA4B,EAAE,OAAQ,CAAE,UAAW;AACrE,WAAO,EACN,gBAAgB,SAAU,MAAM,IAAK,KACrC,MAAM,KAAK,WAAY,WAAY,KACnC,MAAM,KAAK,WAAY,YAAa,KACpC,MAAM,KAAK,WAAY,WAAY,KACnC,MAAM,KAAK,WAAY,iBAAkB,KACzC,MAAM,KAAK,WAAY,WAAY;AAAA,EAErC,CAAE;AACF,qBAAoB,UAAW;AAC/B,4BAA0B;AAC1B,MAAK,WAAW,qBAAsB;AACrC,iDAA8C;AAAA,MAC7C,iBAAiB;AAAA,IAClB,CAAE;AAAA,EACH;AACA,iCAAgC,mBAAoB;AACpD,2BAAyB;AAMzB,gCAA+B,WAAY;AAE3C,QAAM,iBAAiB,kBAAmB,mBAAoB;AAE9D,KAAG,UAAU,mBAAmB,UAAU,kBAAkB;AAC5D,KAAG,UAAU,mBAAmB,uBAAuB;AAEvD,QAAM,YAAY,SAAS,cAAe,KAAM;AAChD,WAAS,KAAK,YAAa,SAAU;AAErC,KAAG,UAAU,KAAM,SAAS,MAAM;AACjC,UAAM,kBAAkB,CAAC;AACzB,OAAG,UAAU,QAAQ,KAAM,CAAE,YAAa;AACzC,UAAK,mBAAmB,gBAAiB;AACxC,wBAAgB,KAAM,OAAQ;AAAA,MAC/B;AAAA,IACD,CAAE;AAEF,eAAY,SAAU,EAAE;AAAA,MACvB,oBAAC,cACA;AAAA,QAAC;AAAA;AAAA,UACA,KAAM,GAAG;AAAA,UACT;AAAA,UACA;AAAA;AAAA,MACD,GACD;AAAA,IACD;AAAA,EACD,CAAE;AACH;",
|
|
6
6
|
"names": []
|
|
@@ -130,6 +130,23 @@
|
|
|
130
130
|
transform: translateX(100%);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
.customize-widgets-error-boundary {
|
|
134
|
+
font-family: var(--wpds-typography-font-family-body, -apple-system, system-ui, "Segoe UI", "Roboto", "Oxygen-Sans", "Ubuntu", "Cantarell", "Helvetica Neue", sans-serif);
|
|
135
|
+
padding: var(--wpds-dimension-padding-md, 12px);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.customize-widgets-error-boundary__report {
|
|
139
|
+
max-height: 420px;
|
|
140
|
+
overflow: auto;
|
|
141
|
+
overflow-anchor: none;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.customize-widgets-error-boundary__report-section {
|
|
145
|
+
margin: 0;
|
|
146
|
+
white-space: pre-wrap;
|
|
147
|
+
overflow-wrap: break-word;
|
|
148
|
+
}
|
|
149
|
+
|
|
133
150
|
@media (min-width: 600px) {
|
|
134
151
|
.customize-widgets-header {
|
|
135
152
|
margin-bottom: 44px;
|
package/build-style/style.css
CHANGED
|
@@ -130,6 +130,23 @@
|
|
|
130
130
|
transform: translateX(-100%);
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
+
.customize-widgets-error-boundary {
|
|
134
|
+
font-family: var(--wpds-typography-font-family-body, -apple-system, system-ui, "Segoe UI", "Roboto", "Oxygen-Sans", "Ubuntu", "Cantarell", "Helvetica Neue", sans-serif);
|
|
135
|
+
padding: var(--wpds-dimension-padding-md, 12px);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.customize-widgets-error-boundary__report {
|
|
139
|
+
max-height: 420px;
|
|
140
|
+
overflow: auto;
|
|
141
|
+
overflow-anchor: none;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.customize-widgets-error-boundary__report-section {
|
|
145
|
+
margin: 0;
|
|
146
|
+
white-space: pre-wrap;
|
|
147
|
+
overflow-wrap: break-word;
|
|
148
|
+
}
|
|
149
|
+
|
|
133
150
|
@media (min-width: 600px) {
|
|
134
151
|
.customize-widgets-header {
|
|
135
152
|
margin-bottom: 44px;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/customize-widgets",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.55.0",
|
|
4
4
|
"description": "Widgets blocks in Customizer Module for WordPress.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -39,36 +39,36 @@
|
|
|
39
39
|
},
|
|
40
40
|
"wpScript": true,
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@wordpress/admin-ui": "^2.
|
|
43
|
-
"@wordpress/base-styles": "^13.
|
|
44
|
-
"@wordpress/block-editor": "^17.
|
|
45
|
-
"@wordpress/block-library": "^
|
|
46
|
-
"@wordpress/blocks": "^
|
|
47
|
-
"@wordpress/components": "^40.
|
|
48
|
-
"@wordpress/compose": "^8.
|
|
49
|
-
"@wordpress/core-data": "^
|
|
50
|
-
"@wordpress/data": "^10.
|
|
51
|
-
"@wordpress/dom": "^4.
|
|
52
|
-
"@wordpress/element": "^8.
|
|
53
|
-
"@wordpress/hooks": "^4.
|
|
54
|
-
"@wordpress/i18n": "^6.
|
|
55
|
-
"@wordpress/icons": "^
|
|
56
|
-
"@wordpress/
|
|
57
|
-
"@wordpress/
|
|
58
|
-
"@wordpress/
|
|
59
|
-
"@wordpress/
|
|
60
|
-
"@wordpress/
|
|
61
|
-
"@wordpress/
|
|
62
|
-
"@wordpress/
|
|
63
|
-
"@wordpress/
|
|
64
|
-
"@wordpress/
|
|
65
|
-
"@wordpress/widgets": "^4.54.0",
|
|
42
|
+
"@wordpress/admin-ui": "^2.10.0",
|
|
43
|
+
"@wordpress/base-styles": "^13.1.0",
|
|
44
|
+
"@wordpress/block-editor": "^17.1.0",
|
|
45
|
+
"@wordpress/block-library": "^11.0.0",
|
|
46
|
+
"@wordpress/blocks": "^16.0.0",
|
|
47
|
+
"@wordpress/components": "^40.1.0",
|
|
48
|
+
"@wordpress/compose": "^8.8.0",
|
|
49
|
+
"@wordpress/core-data": "^8.0.0",
|
|
50
|
+
"@wordpress/data": "^10.55.0",
|
|
51
|
+
"@wordpress/dom": "^4.55.0",
|
|
52
|
+
"@wordpress/element": "^8.7.0",
|
|
53
|
+
"@wordpress/hooks": "^4.55.0",
|
|
54
|
+
"@wordpress/i18n": "^6.28.0",
|
|
55
|
+
"@wordpress/icons": "^16.0.0",
|
|
56
|
+
"@wordpress/is-shallow-equal": "^5.55.0",
|
|
57
|
+
"@wordpress/keyboard-shortcuts": "^5.55.0",
|
|
58
|
+
"@wordpress/keycodes": "^4.55.0",
|
|
59
|
+
"@wordpress/media-utils": "^5.55.0",
|
|
60
|
+
"@wordpress/preferences": "^4.55.0",
|
|
61
|
+
"@wordpress/private-apis": "^1.55.0",
|
|
62
|
+
"@wordpress/theme": "^2.1.0",
|
|
63
|
+
"@wordpress/ui": "^0.22.0",
|
|
64
|
+
"@wordpress/widgets": "^4.55.0",
|
|
66
65
|
"clsx": "^2.1.1",
|
|
67
66
|
"fast-deep-equal": "^3.1.3"
|
|
68
67
|
},
|
|
69
68
|
"devDependencies": {
|
|
70
69
|
"@testing-library/dom": "^10.4.1",
|
|
71
|
-
"@testing-library/react": "^16.3.
|
|
70
|
+
"@testing-library/react": "^16.3.3",
|
|
71
|
+
"vitest": "^5.0.0"
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"react": "^18 || ^19",
|
|
@@ -77,5 +77,5 @@
|
|
|
77
77
|
"publishConfig": {
|
|
78
78
|
"access": "public"
|
|
79
79
|
},
|
|
80
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "485f42ae8a1c58ceea18371a507fd4acfa86fbd8"
|
|
81
81
|
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import { Component } from '@wordpress/element';
|
|
2
|
+
import { __ } from '@wordpress/i18n';
|
|
3
|
+
// eslint-disable-next-line @wordpress/use-recommended-components -- The fallback UI renders outside the editor's notice system.
|
|
4
|
+
import { Card, CollapsibleCard, Notice, Stack, Text } from '@wordpress/ui';
|
|
5
|
+
import { useCopyToClipboard } from '@wordpress/compose';
|
|
6
|
+
import { doAction } from '@wordpress/hooks';
|
|
7
|
+
|
|
8
|
+
// A boundary catches whatever was thrown, which is not always an `Error`.
|
|
9
|
+
function getErrorName( error ) {
|
|
10
|
+
return ( error instanceof Error && error.name ) || 'Error';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function getErrorMessage( error ) {
|
|
14
|
+
if ( typeof error === 'string' && error ) {
|
|
15
|
+
return error;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if ( typeof error?.message === 'string' && error.message ) {
|
|
19
|
+
return error.message;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return 'An unknown error occurred.';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// The sections of the report, shared by the copied Markdown and the details
|
|
26
|
+
// panel so that the two cannot drift apart. Deliberately untranslated: both
|
|
27
|
+
// are developer-facing, and the report is pasted into a bug report.
|
|
28
|
+
function getErrorSections( error, componentStack ) {
|
|
29
|
+
const sections = [
|
|
30
|
+
{ label: getErrorName( error ), content: getErrorMessage( error ) },
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
if ( error?.stack ) {
|
|
34
|
+
sections.push( {
|
|
35
|
+
label: 'Stack',
|
|
36
|
+
content: error.stack.trim(),
|
|
37
|
+
preformatted: true,
|
|
38
|
+
} );
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if ( componentStack ) {
|
|
42
|
+
sections.push( {
|
|
43
|
+
label: 'Component stack',
|
|
44
|
+
content: componentStack.trim(),
|
|
45
|
+
preformatted: true,
|
|
46
|
+
} );
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
sections.push( {
|
|
50
|
+
label: 'Environment',
|
|
51
|
+
content: `User agent: ${ window.navigator.userAgent }`,
|
|
52
|
+
preformatted: true,
|
|
53
|
+
} );
|
|
54
|
+
|
|
55
|
+
return sections;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Markdown, so the report stays readable as plain text and renders when pasted
|
|
59
|
+
// into a bug report.
|
|
60
|
+
function getErrorReport( error, componentStack ) {
|
|
61
|
+
const sections = getErrorSections( error, componentStack ).map(
|
|
62
|
+
( { label, content, preformatted } ) =>
|
|
63
|
+
`**${ label }**\n\n${
|
|
64
|
+
preformatted ? `\`\`\`\n${ content }\n\`\`\`` : content
|
|
65
|
+
}`
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
return [ '### Error report', ...sections ].join( '\n\n' );
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function CopyButton( { text, children, variant = 'outline' } ) {
|
|
72
|
+
const ref = useCopyToClipboard( text );
|
|
73
|
+
return (
|
|
74
|
+
<Notice.ActionButton variant={ variant } ref={ ref }>
|
|
75
|
+
{ children }
|
|
76
|
+
</Notice.ActionButton>
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function ErrorReport( { error, componentStack } ) {
|
|
81
|
+
return (
|
|
82
|
+
<Stack
|
|
83
|
+
className="customize-widgets-error-boundary__report"
|
|
84
|
+
direction="column"
|
|
85
|
+
gap="md"
|
|
86
|
+
>
|
|
87
|
+
{ getErrorSections( error, componentStack ).map(
|
|
88
|
+
( { label, content } ) => (
|
|
89
|
+
<Stack key={ label } direction="column" gap="xs">
|
|
90
|
+
<Text variant="heading-md">{ label }</Text>
|
|
91
|
+
<pre className="customize-widgets-error-boundary__report-section">
|
|
92
|
+
{ content }
|
|
93
|
+
</pre>
|
|
94
|
+
</Stack>
|
|
95
|
+
)
|
|
96
|
+
) }
|
|
97
|
+
</Stack>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function ErrorDetails( { error, componentStack } ) {
|
|
102
|
+
return (
|
|
103
|
+
<CollapsibleCard.Root className="customize-widgets-error-boundary__details">
|
|
104
|
+
<CollapsibleCard.Header>
|
|
105
|
+
<Card.Title>{ __( 'Error details' ) }</Card.Title>
|
|
106
|
+
</CollapsibleCard.Header>
|
|
107
|
+
<CollapsibleCard.Content>
|
|
108
|
+
<ErrorReport
|
|
109
|
+
error={ error }
|
|
110
|
+
componentStack={ componentStack }
|
|
111
|
+
/>
|
|
112
|
+
</CollapsibleCard.Content>
|
|
113
|
+
</CollapsibleCard.Root>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export default class ErrorBoundary extends Component {
|
|
118
|
+
constructor() {
|
|
119
|
+
super( ...arguments );
|
|
120
|
+
|
|
121
|
+
this.state = {
|
|
122
|
+
error: null,
|
|
123
|
+
componentStack: null,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
componentDidCatch( error, errorInfo ) {
|
|
128
|
+
this.setState( { componentStack: errorInfo?.componentStack } );
|
|
129
|
+
doAction( 'editor.ErrorBoundary.errorLogged', error, errorInfo );
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
static getDerivedStateFromError( error ) {
|
|
133
|
+
return { error };
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
render() {
|
|
137
|
+
const { error, componentStack } = this.state;
|
|
138
|
+
if ( ! error ) {
|
|
139
|
+
return this.props.children;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return (
|
|
143
|
+
<Stack
|
|
144
|
+
className="customize-widgets-error-boundary"
|
|
145
|
+
direction="column"
|
|
146
|
+
gap="lg"
|
|
147
|
+
>
|
|
148
|
+
<Notice.Root intent="error">
|
|
149
|
+
<Notice.Title>
|
|
150
|
+
{ __( 'The editor has crashed' ) }
|
|
151
|
+
</Notice.Title>
|
|
152
|
+
<Notice.Description>
|
|
153
|
+
{ __(
|
|
154
|
+
'An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.'
|
|
155
|
+
) }
|
|
156
|
+
</Notice.Description>
|
|
157
|
+
<Notice.Actions>
|
|
158
|
+
<CopyButton
|
|
159
|
+
variant="solid"
|
|
160
|
+
text={ () =>
|
|
161
|
+
getErrorReport( error, componentStack )
|
|
162
|
+
}
|
|
163
|
+
>
|
|
164
|
+
{ __( 'Copy error' ) }
|
|
165
|
+
</CopyButton>
|
|
166
|
+
</Notice.Actions>
|
|
167
|
+
</Notice.Root>
|
|
168
|
+
{ globalThis.SCRIPT_DEBUG ? (
|
|
169
|
+
<ErrorDetails
|
|
170
|
+
error={ error }
|
|
171
|
+
componentStack={ componentStack }
|
|
172
|
+
/>
|
|
173
|
+
) : null }
|
|
174
|
+
</Stack>
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
.customize-widgets-error-boundary {
|
|
2
|
+
font-family: var(--wpds-typography-font-family-body);
|
|
3
|
+
padding: var(--wpds-dimension-padding-md);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.customize-widgets-error-boundary__report {
|
|
7
|
+
max-height: 420px;
|
|
8
|
+
overflow: auto;
|
|
9
|
+
overflow-anchor: none;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.customize-widgets-error-boundary__report-section {
|
|
13
|
+
margin: 0;
|
|
14
|
+
white-space: pre-wrap;
|
|
15
|
+
overflow-wrap: break-word;
|
|
16
|
+
}
|
package/src/components/error-boundary/test/{error-boundary.js → error-boundary.jsdom.test.jsx}
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
1
2
|
import { render } from '@testing-library/react';
|
|
2
3
|
import * as wpHooks from '@wordpress/hooks';
|
|
3
4
|
import ErrorBoundary from '../index';
|
|
@@ -10,8 +11,8 @@ const ChildComponent = () => {
|
|
|
10
11
|
|
|
11
12
|
describe( 'Error Boundary', () => {
|
|
12
13
|
describe( 'when error is thrown from a Child component', () => {
|
|
13
|
-
it( 'calls the `editor.ErrorBoundary.errorLogged` hook action with the error object', () => {
|
|
14
|
-
const doAction =
|
|
14
|
+
it( 'calls the `editor.ErrorBoundary.errorLogged` hook action with the error object and error info', () => {
|
|
15
|
+
const doAction = vi.spyOn( wpHooks, 'doAction' );
|
|
15
16
|
|
|
16
17
|
render(
|
|
17
18
|
<ErrorBoundary>
|
|
@@ -21,7 +22,10 @@ describe( 'Error Boundary', () => {
|
|
|
21
22
|
|
|
22
23
|
expect( doAction ).toHaveBeenCalledWith(
|
|
23
24
|
'editor.ErrorBoundary.errorLogged',
|
|
24
|
-
theError
|
|
25
|
+
theError,
|
|
26
|
+
expect.objectContaining( {
|
|
27
|
+
componentStack: expect.any( String ),
|
|
28
|
+
} )
|
|
25
29
|
);
|
|
26
30
|
expect( console ).toHaveErrored();
|
|
27
31
|
} );
|
package/src/style.scss
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
@use "@wordpress/base-styles/mixins" as *;
|
|
2
2
|
@use "@wordpress/base-styles/default-custom-properties";
|
|
3
3
|
@use "./components/block-inspector-button/style.scss" as *;
|
|
4
|
+
@use "./components/error-boundary/style.scss" as *;
|
|
4
5
|
@use "./components/header/style.scss" as *;
|
|
5
6
|
@use "./components/inserter/style.scss" as *;
|
|
6
7
|
@use "./components/keyboard-shortcut-help-modal/style.scss" as *;
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { Component } from '@wordpress/element';
|
|
2
|
-
import { __ } from '@wordpress/i18n';
|
|
3
|
-
import { Button } from '@wordpress/components';
|
|
4
|
-
import { Warning } from '@wordpress/block-editor';
|
|
5
|
-
import { useCopyToClipboard } from '@wordpress/compose';
|
|
6
|
-
import { doAction } from '@wordpress/hooks';
|
|
7
|
-
|
|
8
|
-
function CopyButton( { text, children } ) {
|
|
9
|
-
const ref = useCopyToClipboard( text );
|
|
10
|
-
return (
|
|
11
|
-
<Button size="compact" variant="secondary" ref={ ref }>
|
|
12
|
-
{ children }
|
|
13
|
-
</Button>
|
|
14
|
-
);
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export default class ErrorBoundary extends Component {
|
|
18
|
-
constructor() {
|
|
19
|
-
super( ...arguments );
|
|
20
|
-
this.state = {
|
|
21
|
-
error: null,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
componentDidCatch( error ) {
|
|
26
|
-
this.setState( { error } );
|
|
27
|
-
|
|
28
|
-
doAction( 'editor.ErrorBoundary.errorLogged', error );
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
render() {
|
|
32
|
-
const { error } = this.state;
|
|
33
|
-
if ( ! error ) {
|
|
34
|
-
return this.props.children;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
return (
|
|
38
|
-
<Warning
|
|
39
|
-
className="customize-widgets-error-boundary"
|
|
40
|
-
actions={ [
|
|
41
|
-
<CopyButton key="copy-error" text={ error.stack }>
|
|
42
|
-
{ __( 'Copy Error' ) }
|
|
43
|
-
</CopyButton>,
|
|
44
|
-
] }
|
|
45
|
-
>
|
|
46
|
-
{ __( 'The editor has encountered an unexpected error.' ) }
|
|
47
|
-
</Warning>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
/package/src/components/keyboard-shortcut-help-modal/{dynamic-shortcut.js → dynamic-shortcut.jsx}
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|