@wordpress/customize-widgets 6.0.0 → 6.1.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/build/components/block-appender/index.cjs +24 -41
- package/build/components/block-appender/index.cjs.map +1 -7
- package/build/components/block-inspector-button/index.cjs +24 -52
- package/build/components/block-inspector-button/index.cjs.map +1 -7
- package/build/components/customize-widgets/index.cjs +76 -97
- package/build/components/customize-widgets/index.cjs.map +1 -7
- package/build/components/customize-widgets/use-clear-selected-block.cjs +58 -67
- package/build/components/customize-widgets/use-clear-selected-block.cjs.map +1 -7
- package/build/components/error-boundary/index.cjs +115 -155
- package/build/components/error-boundary/index.cjs.map +1 -7
- package/build/components/focus-control/index.cjs +44 -84
- package/build/components/focus-control/index.cjs.map +1 -7
- package/build/components/focus-control/use-blocks-focus-control.cjs +28 -49
- package/build/components/focus-control/use-blocks-focus-control.cjs.map +1 -7
- package/build/components/header/index.cjs +84 -122
- package/build/components/header/index.cjs.map +1 -7
- package/build/components/inserter/index.cjs +43 -78
- package/build/components/inserter/index.cjs.map +1 -7
- package/build/components/inserter/use-inserter.cjs +22 -54
- package/build/components/inserter/use-inserter.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/config.cjs +88 -85
- package/build/components/keyboard-shortcut-help-modal/config.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs +40 -57
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/index.cjs +103 -165
- package/build/components/keyboard-shortcut-help-modal/index.cjs.map +1 -7
- package/build/components/keyboard-shortcut-help-modal/shortcut.cjs +37 -76
- package/build/components/keyboard-shortcut-help-modal/shortcut.cjs.map +1 -7
- package/build/components/keyboard-shortcuts/index.cjs +70 -100
- package/build/components/keyboard-shortcuts/index.cjs.map +1 -7
- package/build/components/more-menu/index.cjs +103 -151
- package/build/components/more-menu/index.cjs.map +1 -7
- package/build/components/sidebar-block-editor/index.cjs +122 -155
- package/build/components/sidebar-block-editor/index.cjs.map +1 -7
- package/build/components/sidebar-block-editor/sidebar-adapter.cjs +207 -270
- package/build/components/sidebar-block-editor/sidebar-adapter.cjs.map +1 -7
- package/build/components/sidebar-block-editor/sidebar-editor-provider.cjs +40 -50
- package/build/components/sidebar-block-editor/sidebar-editor-provider.cjs.map +1 -7
- package/build/components/sidebar-block-editor/use-sidebar-block-editor.cjs +75 -110
- package/build/components/sidebar-block-editor/use-sidebar-block-editor.cjs.map +1 -7
- package/build/components/sidebar-controls/index.cjs +27 -53
- package/build/components/sidebar-controls/index.cjs.map +1 -7
- package/build/components/welcome-guide/index.cjs +70 -94
- package/build/components/welcome-guide/index.cjs.map +1 -7
- package/build/controls/inserter-outer-section.cjs +68 -110
- package/build/controls/inserter-outer-section.cjs.map +1 -7
- package/build/controls/inspector-section.cjs +57 -90
- package/build/controls/inspector-section.cjs.map +1 -7
- package/build/controls/sidebar-control.cjs +55 -69
- package/build/controls/sidebar-control.cjs.map +1 -7
- package/build/controls/sidebar-section.cjs +79 -103
- package/build/controls/sidebar-section.cjs.map +1 -7
- package/build/filters/index.cjs +8 -5
- package/build/filters/move-to-sidebar.cjs +62 -78
- package/build/filters/move-to-sidebar.cjs.map +1 -7
- package/build/filters/replace-media-upload.cjs +11 -9
- package/build/filters/replace-media-upload.cjs.map +1 -7
- package/build/filters/wide-widget-display.cjs +20 -20
- package/build/filters/wide-widget-display.cjs.map +1 -7
- package/build/index.cjs +84 -91
- package/build/index.cjs.map +1 -7
- package/build/lock-unlock.cjs +10 -35
- package/build/lock-unlock.cjs.map +1 -7
- package/build/store/actions.cjs +49 -32
- package/build/store/actions.cjs.map +1 -7
- package/build/store/constants.cjs +12 -29
- package/build/store/constants.cjs.map +1 -7
- package/build/store/index.cjs +49 -41
- package/build/store/index.cjs.map +1 -7
- package/build/store/reducer.cjs +20 -33
- package/build/store/reducer.cjs.map +1 -7
- package/build/store/selectors.cjs +47 -38
- package/build/store/selectors.cjs.map +1 -7
- package/build/utils.cjs +81 -108
- package/build/utils.cjs.map +1 -7
- package/build-module/components/block-appender/index.mjs +18 -23
- package/build-module/components/block-appender/index.mjs.map +1 -7
- package/build-module/components/block-inspector-button/index.mjs +15 -28
- package/build-module/components/block-inspector-button/index.mjs.map +1 -7
- package/build-module/components/customize-widgets/index.mjs +45 -73
- package/build-module/components/customize-widgets/index.mjs.map +1 -7
- package/build-module/components/customize-widgets/use-clear-selected-block.mjs +52 -46
- package/build-module/components/customize-widgets/use-clear-selected-block.mjs.map +1 -7
- package/build-module/components/error-boundary/index.mjs +103 -128
- package/build-module/components/error-boundary/index.mjs.map +1 -7
- package/build-module/components/focus-control/index.mjs +37 -66
- package/build-module/components/focus-control/index.mjs.map +1 -7
- package/build-module/components/focus-control/use-blocks-focus-control.mjs +21 -27
- package/build-module/components/focus-control/use-blocks-focus-control.mjs.map +1 -7
- package/build-module/components/header/index.mjs +55 -92
- package/build-module/components/header/index.mjs.map +1 -7
- package/build-module/components/inserter/index.mjs +33 -53
- package/build-module/components/inserter/index.mjs.map +1 -7
- package/build-module/components/inserter/use-inserter.mjs +17 -34
- package/build-module/components/inserter/use-inserter.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/config.mjs +83 -61
- package/build-module/components/keyboard-shortcut-help-modal/config.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs +19 -33
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/index.mjs +75 -139
- package/build-module/components/keyboard-shortcut-help-modal/index.mjs.map +1 -7
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs +31 -55
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.mjs.map +1 -7
- package/build-module/components/keyboard-shortcuts/index.mjs +62 -79
- package/build-module/components/keyboard-shortcuts/index.mjs.map +1 -7
- package/build-module/components/more-menu/index.mjs +76 -128
- package/build-module/components/more-menu/index.mjs.map +1 -7
- package/build-module/components/sidebar-block-editor/index.mjs +86 -128
- package/build-module/components/sidebar-block-editor/index.mjs.map +1 -7
- package/build-module/components/sidebar-block-editor/sidebar-adapter.mjs +202 -250
- package/build-module/components/sidebar-block-editor/sidebar-adapter.mjs.map +1 -7
- package/build-module/components/sidebar-block-editor/sidebar-editor-provider.mjs +17 -25
- package/build-module/components/sidebar-block-editor/sidebar-editor-provider.mjs.map +1 -7
- package/build-module/components/sidebar-block-editor/use-sidebar-block-editor.mjs +54 -86
- package/build-module/components/sidebar-block-editor/use-sidebar-block-editor.mjs.map +1 -7
- package/build-module/components/sidebar-controls/index.mjs +19 -27
- package/build-module/components/sidebar-controls/index.mjs.map +1 -7
- package/build-module/components/welcome-guide/index.mjs +62 -71
- package/build-module/components/welcome-guide/index.mjs.map +1 -7
- package/build-module/controls/inserter-outer-section.mjs +61 -88
- package/build-module/controls/inserter-outer-section.mjs.map +1 -7
- package/build-module/controls/inspector-section.mjs +52 -70
- package/build-module/controls/inspector-section.mjs.map +1 -7
- package/build-module/controls/sidebar-control.mjs +33 -45
- package/build-module/controls/sidebar-control.mjs.map +1 -7
- package/build-module/controls/sidebar-section.mjs +59 -80
- package/build-module/controls/sidebar-section.mjs.map +1 -7
- package/build-module/filters/index.mjs +0 -2
- package/build-module/filters/move-to-sidebar.mjs +52 -79
- package/build-module/filters/move-to-sidebar.mjs.map +1 -7
- package/build-module/filters/replace-media-upload.mjs +5 -8
- package/build-module/filters/replace-media-upload.mjs.map +1 -7
- package/build-module/filters/wide-widget-display.mjs +13 -18
- package/build-module/filters/wide-widget-display.mjs.map +1 -7
- package/build-module/index.mjs +53 -71
- package/build-module/index.mjs.map +1 -7
- package/build-module/lock-unlock.mjs +5 -10
- package/build-module/lock-unlock.mjs.map +1 -7
- package/build-module/store/actions.mjs +44 -8
- package/build-module/store/actions.mjs.map +1 -7
- package/build-module/store/constants.mjs +7 -5
- package/build-module/store/constants.mjs.map +1 -7
- package/build-module/store/index.mjs +15 -11
- package/build-module/store/index.mjs.map +1 -7
- package/build-module/store/reducer.mjs +15 -13
- package/build-module/store/reducer.mjs.map +1 -7
- package/build-module/store/selectors.mjs +41 -13
- package/build-module/store/selectors.mjs.map +1 -7
- package/build-module/utils.mjs +74 -82
- package/build-module/utils.mjs.map +1 -7
- package/package.json +27 -27
- package/src/components/customize-widgets/index.jsx +2 -2
- package/src/components/welcome-guide/index.jsx +6 -2
- package/build/filters/index.cjs.map +0 -7
- package/build-module/filters/index.mjs.map +0 -7
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
// packages/customize-widgets/src/components/customize-widgets/index.jsx
|
|
2
1
|
import { getAdminThemeColors } from "@wordpress/admin-ui";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
useEffect,
|
|
6
|
-
useRef,
|
|
7
|
-
createPortal,
|
|
8
|
-
useMemo
|
|
9
|
-
} from "@wordpress/element";
|
|
10
|
-
import { SlotFillProvider, Popover } from "@wordpress/components";
|
|
2
|
+
import { createPortal, useEffect, useMemo, useRef, useState } from "@wordpress/element";
|
|
3
|
+
import { Popover, SlotFillProvider } from "@wordpress/components";
|
|
11
4
|
import { ThemeProvider } from "@wordpress/theme";
|
|
12
5
|
import { useEnableWpCompatOverlaySlot } from "@wordpress/ui";
|
|
13
6
|
import ErrorBoundary from "../error-boundary/index.mjs";
|
|
@@ -16,68 +9,47 @@ import FocusControl from "../focus-control/index.mjs";
|
|
|
16
9
|
import SidebarControls from "../sidebar-controls/index.mjs";
|
|
17
10
|
import useClearSelectedBlock from "./use-clear-selected-block.mjs";
|
|
18
11
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
parentContainer
|
|
60
|
-
);
|
|
61
|
-
return /* @__PURE__ */ jsx(SlotFillProvider, { children: /* @__PURE__ */ jsx(ThemeProvider, { isRoot: true, color: { primary: adminPrimary }, children: /* @__PURE__ */ jsx(
|
|
62
|
-
SidebarControls,
|
|
63
|
-
{
|
|
64
|
-
sidebarControls,
|
|
65
|
-
activeSidebarControl,
|
|
66
|
-
children: /* @__PURE__ */ jsxs(
|
|
67
|
-
FocusControl,
|
|
68
|
-
{
|
|
69
|
-
api,
|
|
70
|
-
sidebarControls,
|
|
71
|
-
children: [
|
|
72
|
-
activeSidebar,
|
|
73
|
-
popover
|
|
74
|
-
]
|
|
75
|
-
}
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
) }) });
|
|
12
|
+
// packages/customize-widgets/src/components/customize-widgets/index.jsx
|
|
13
|
+
function CustomizeWidgets({ api, sidebarControls, blockEditorSettings }) {
|
|
14
|
+
const [activeSidebarControl, setActiveSidebarControl] = useState(null);
|
|
15
|
+
const parentContainer = document.getElementById("customize-theme-controls");
|
|
16
|
+
const popoverRef = useRef();
|
|
17
|
+
const adminPrimary = useMemo(() => getAdminThemeColors().primary, []);
|
|
18
|
+
useEnableWpCompatOverlaySlot();
|
|
19
|
+
useClearSelectedBlock(activeSidebarControl, popoverRef);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const unsubscribers = sidebarControls.map((sidebarControl) => sidebarControl.subscribe((expanded) => {
|
|
22
|
+
if (expanded) setActiveSidebarControl(sidebarControl);
|
|
23
|
+
}));
|
|
24
|
+
return () => {
|
|
25
|
+
unsubscribers.forEach((unsubscriber) => unsubscriber());
|
|
26
|
+
};
|
|
27
|
+
}, [sidebarControls]);
|
|
28
|
+
const activeSidebar = activeSidebarControl && createPortal(/* @__PURE__ */ jsx(ErrorBoundary, { children: /* @__PURE__ */ jsx(SidebarBlockEditor, {
|
|
29
|
+
blockEditorSettings,
|
|
30
|
+
sidebar: activeSidebarControl.sidebarAdapter,
|
|
31
|
+
inserter: activeSidebarControl.inserter,
|
|
32
|
+
inspector: activeSidebarControl.inspector
|
|
33
|
+
}, activeSidebarControl.id) }), activeSidebarControl.container[0]);
|
|
34
|
+
const popover = parentContainer && createPortal(/* @__PURE__ */ jsx("div", {
|
|
35
|
+
className: "customize-widgets-popover",
|
|
36
|
+
ref: popoverRef,
|
|
37
|
+
children: /* @__PURE__ */ jsx(Popover.Slot, {})
|
|
38
|
+
}), parentContainer);
|
|
39
|
+
return /* @__PURE__ */ jsx(SlotFillProvider, { children: /* @__PURE__ */ jsx(ThemeProvider, {
|
|
40
|
+
isRoot: true,
|
|
41
|
+
color: { primary: adminPrimary },
|
|
42
|
+
children: /* @__PURE__ */ jsx(SidebarControls, {
|
|
43
|
+
sidebarControls,
|
|
44
|
+
activeSidebarControl,
|
|
45
|
+
children: /* @__PURE__ */ jsxs(FocusControl, {
|
|
46
|
+
api,
|
|
47
|
+
sidebarControls,
|
|
48
|
+
children: [activeSidebar, popover]
|
|
49
|
+
})
|
|
50
|
+
})
|
|
51
|
+
}) });
|
|
79
52
|
}
|
|
80
|
-
export {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
//# sourceMappingURL=index.mjs.map
|
|
53
|
+
export { CustomizeWidgets as default };
|
|
54
|
+
|
|
55
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/customize-widgets/index.jsx"],
|
|
4
|
-
"sourcesContent": ["import { getAdminThemeColors } from '@wordpress/admin-ui';\nimport {\n\tuseState,\n\tuseEffect,\n\tuseRef,\n\tcreatePortal,\n\tuseMemo,\n} from '@wordpress/element';\nimport { SlotFillProvider, Popover } from '@wordpress/components';\nimport { ThemeProvider } from '@wordpress/theme';\nimport { useEnableWpCompatOverlaySlot } from '@wordpress/ui';\nimport ErrorBoundary from '../error-boundary';\nimport SidebarBlockEditor from '../sidebar-block-editor';\nimport FocusControl from '../focus-control';\nimport SidebarControls from '../sidebar-controls';\nimport useClearSelectedBlock from './use-clear-selected-block';\n\nexport default function CustomizeWidgets( {\n\tapi,\n\tsidebarControls,\n\tblockEditorSettings,\n} ) {\n\tconst [ activeSidebarControl, setActiveSidebarControl ] = useState( null );\n\tconst parentContainer = document.getElementById(\n\t\t'customize-theme-controls'\n\t);\n\tconst popoverRef = useRef();\n\tconst adminPrimary = useMemo( () => getAdminThemeColors().primary, [] );\n\n\t// `useClearSelectedBlock` relies on the slot marker to spot overlays.\n\tuseEnableWpCompatOverlaySlot();\n\tuseClearSelectedBlock( activeSidebarControl, popoverRef );\n\n\tuseEffect( () => {\n\t\tconst unsubscribers = sidebarControls.map( ( sidebarControl ) =>\n\t\t\tsidebarControl.subscribe( ( expanded ) => {\n\t\t\t\tif ( expanded ) {\n\t\t\t\t\tsetActiveSidebarControl( sidebarControl );\n\t\t\t\t}\n\t\t\t} )\n\t\t);\n\n\t\treturn () => {\n\t\t\tunsubscribers.forEach( ( unsubscriber ) => unsubscriber() );\n\t\t};\n\t}, [ sidebarControls ] );\n\n\tconst activeSidebar =\n\t\tactiveSidebarControl &&\n\t\tcreatePortal(\n\t\t\t<ErrorBoundary>\n\t\t\t\t<SidebarBlockEditor\n\t\t\t\t\tkey={ activeSidebarControl.id }\n\t\t\t\t\tblockEditorSettings={ blockEditorSettings }\n\t\t\t\t\tsidebar={ activeSidebarControl.sidebarAdapter }\n\t\t\t\t\tinserter={ activeSidebarControl.inserter }\n\t\t\t\t\tinspector={ activeSidebarControl.inspector }\n\t\t\t\t/>\n\t\t\t</ErrorBoundary>,\n\t\t\tactiveSidebarControl.container[ 0 ]\n\t\t);\n\n\t// We have to portal this to the parent of both the editor and the inspector,\n\t// so that the popovers will appear above both of them.\n\tconst popover =\n\t\tparentContainer &&\n\t\tcreatePortal(\n\t\t\t<div className=\"customize-widgets-popover\" ref={ popoverRef }>\n\t\t\t\t<Popover.Slot />\n\t\t\t</div>,\n\t\t\tparentContainer\n\t\t);\n\n\treturn (\n\t\t<SlotFillProvider>\n\t\t\t<ThemeProvider isRoot color={ { primary: adminPrimary } }>\n\t\t\t\t<SidebarControls\n\t\t\t\t\tsidebarControls={ sidebarControls }\n\t\t\t\t\tactiveSidebarControl={ activeSidebarControl }\n\t\t\t\t>\n\t\t\t\t\t<FocusControl\n\t\t\t\t\t\tapi={ api }\n\t\t\t\t\t\tsidebarControls={ sidebarControls }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ activeSidebar }\n\t\t\t\t\t\t{ popover }\n\t\t\t\t\t</FocusControl>\n\t\t\t\t</SidebarControls>\n\t\t\t</ThemeProvider>\n\t\t</SlotFillProvider>\n\t);\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,2BAA2B;AACpC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,SAAS,kBAAkB,eAAe;AAC1C,SAAS,qBAAqB;AAC9B,SAAS,oCAAoC;AAC7C,OAAO,mBAAmB;AAC1B,OAAO,wBAAwB;AAC/B,OAAO,kBAAkB;AACzB,OAAO,qBAAqB;AAC5B,OAAO,2BAA2B;AAoC9B,cA6BC,YA7BD;AAlCW,SAAR,iBAAmC;AAAA,EACzC;AAAA,EACA;AAAA,EACA;AACD,GAAI;AACH,QAAM,CAAE,sBAAsB,uBAAwB,IAAI,SAAU,IAAK;AACzE,QAAM,kBAAkB,SAAS;AAAA,IAChC;AAAA,EACD;AACA,QAAM,aAAa,OAAO;AAC1B,QAAM,eAAe,QAAS,MAAM,oBAAoB,EAAE,SAAS,CAAC,CAAE;AAGtE,+BAA6B;AAC7B,wBAAuB,sBAAsB,UAAW;AAExD,YAAW,MAAM;AAChB,UAAM,gBAAgB,gBAAgB;AAAA,MAAK,CAAE,mBAC5C,eAAe,UAAW,CAAE,aAAc;AACzC,YAAK,UAAW;AACf,kCAAyB,cAAe;AAAA,QACzC;AAAA,MACD,CAAE;AAAA,IACH;AAEA,WAAO,MAAM;AACZ,oBAAc,QAAS,CAAE,iBAAkB,aAAa,CAAE;AAAA,IAC3D;AAAA,EACD,GAAG,CAAE,eAAgB,CAAE;AAEvB,QAAM,gBACL,wBACA;AAAA,IACC,oBAAC,iBACA;AAAA,MAAC;AAAA;AAAA,QAEA;AAAA,QACA,SAAU,qBAAqB;AAAA,QAC/B,UAAW,qBAAqB;AAAA,QAChC,WAAY,qBAAqB;AAAA;AAAA,MAJ3B,qBAAqB;AAAA,IAK5B,GACD;AAAA,IACA,qBAAqB,UAAW,CAAE;AAAA,EACnC;AAID,QAAM,UACL,mBACA;AAAA,IACC,oBAAC,SAAI,WAAU,6BAA4B,KAAM,YAChD,8BAAC,QAAQ,MAAR,EAAa,GACf;AAAA,IACA;AAAA,EACD;AAED,SACC,oBAAC,oBACA,8BAAC,iBAAc,QAAM,MAAC,OAAQ,EAAE,SAAS,aAAa,GACrD;AAAA,IAAC;AAAA;AAAA,MACA;AAAA,MACA;AAAA,MAEA;AAAA,QAAC;AAAA;AAAA,UACA;AAAA,UACA;AAAA,UAEE;AAAA;AAAA,YACA;AAAA;AAAA;AAAA,MACH;AAAA;AAAA,EACD,GACD,GACD;AAEF;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["WCPopover"],"sources":["../../../src/components/customize-widgets/index.jsx"],"sourcesContent":["import { getAdminThemeColors } from '@wordpress/admin-ui';\nimport {\n\tuseState,\n\tuseEffect,\n\tuseRef,\n\tcreatePortal,\n\tuseMemo,\n} from '@wordpress/element';\nimport { SlotFillProvider, Popover as WCPopover } from '@wordpress/components';\nimport { ThemeProvider } from '@wordpress/theme';\nimport { useEnableWpCompatOverlaySlot } from '@wordpress/ui';\nimport ErrorBoundary from '../error-boundary';\nimport SidebarBlockEditor from '../sidebar-block-editor';\nimport FocusControl from '../focus-control';\nimport SidebarControls from '../sidebar-controls';\nimport useClearSelectedBlock from './use-clear-selected-block';\n\nexport default function CustomizeWidgets( {\n\tapi,\n\tsidebarControls,\n\tblockEditorSettings,\n} ) {\n\tconst [ activeSidebarControl, setActiveSidebarControl ] = useState( null );\n\tconst parentContainer = document.getElementById(\n\t\t'customize-theme-controls'\n\t);\n\tconst popoverRef = useRef();\n\tconst adminPrimary = useMemo( () => getAdminThemeColors().primary, [] );\n\n\t// `useClearSelectedBlock` relies on the slot marker to spot overlays.\n\tuseEnableWpCompatOverlaySlot();\n\tuseClearSelectedBlock( activeSidebarControl, popoverRef );\n\n\tuseEffect( () => {\n\t\tconst unsubscribers = sidebarControls.map( ( sidebarControl ) =>\n\t\t\tsidebarControl.subscribe( ( expanded ) => {\n\t\t\t\tif ( expanded ) {\n\t\t\t\t\tsetActiveSidebarControl( sidebarControl );\n\t\t\t\t}\n\t\t\t} )\n\t\t);\n\n\t\treturn () => {\n\t\t\tunsubscribers.forEach( ( unsubscriber ) => unsubscriber() );\n\t\t};\n\t}, [ sidebarControls ] );\n\n\tconst activeSidebar =\n\t\tactiveSidebarControl &&\n\t\tcreatePortal(\n\t\t\t<ErrorBoundary>\n\t\t\t\t<SidebarBlockEditor\n\t\t\t\t\tkey={ activeSidebarControl.id }\n\t\t\t\t\tblockEditorSettings={ blockEditorSettings }\n\t\t\t\t\tsidebar={ activeSidebarControl.sidebarAdapter }\n\t\t\t\t\tinserter={ activeSidebarControl.inserter }\n\t\t\t\t\tinspector={ activeSidebarControl.inspector }\n\t\t\t\t/>\n\t\t\t</ErrorBoundary>,\n\t\t\tactiveSidebarControl.container[ 0 ]\n\t\t);\n\n\t// We have to portal this to the parent of both the editor and the inspector,\n\t// so that the popovers will appear above both of them.\n\tconst popover =\n\t\tparentContainer &&\n\t\tcreatePortal(\n\t\t\t<div className=\"customize-widgets-popover\" ref={ popoverRef }>\n\t\t\t\t<WCPopover.Slot />\n\t\t\t</div>,\n\t\t\tparentContainer\n\t\t);\n\n\treturn (\n\t\t<SlotFillProvider>\n\t\t\t<ThemeProvider isRoot color={ { primary: adminPrimary } }>\n\t\t\t\t<SidebarControls\n\t\t\t\t\tsidebarControls={ sidebarControls }\n\t\t\t\t\tactiveSidebarControl={ activeSidebarControl }\n\t\t\t\t>\n\t\t\t\t\t<FocusControl\n\t\t\t\t\t\tapi={ api }\n\t\t\t\t\t\tsidebarControls={ sidebarControls }\n\t\t\t\t\t>\n\t\t\t\t\t\t{ activeSidebar }\n\t\t\t\t\t\t{ popover }\n\t\t\t\t\t</FocusControl>\n\t\t\t\t</SidebarControls>\n\t\t\t</ThemeProvider>\n\t\t</SlotFillProvider>\n\t);\n}\n"],"mappings":";;;;;;;;;;;;AAiBA,SAAwB,iBAAkB,EACzC,KACA,iBACA,uBACG;CACH,MAAM,CAAE,sBAAsB,2BAA4B,SAAU,IAAK;CACzE,MAAM,kBAAkB,SAAS,eAChC,0BACD;CACA,MAAM,aAAa,OAAO;CAC1B,MAAM,eAAe,cAAe,oBAAoB,CAAC,CAAC,SAAS,CAAC,CAAE;CAGtE,6BAA6B;CAC7B,sBAAuB,sBAAsB,UAAW;CAExD,gBAAiB;EAChB,MAAM,gBAAgB,gBAAgB,KAAO,mBAC5C,eAAe,WAAa,aAAc;GACzC,IAAK,UACJ,wBAAyB,cAAe;EAE1C,CAAE,CACH;EAEA,aAAa;GACZ,cAAc,SAAW,iBAAkB,aAAa,CAAE;EAC3D;CACD,GAAG,CAAE,eAAgB,CAAE;CAEvB,MAAM,gBACL,wBACA,aACC,oBAAC,eAAD,EAAA,UACC,oBAAC,oBAAD;EAEuB;EACtB,SAAU,qBAAqB;EAC/B,UAAW,qBAAqB;EAChC,WAAY,qBAAqB;CACjC,GALM,qBAAqB,EAK3B,EACa,CAAA,GACf,qBAAqB,UAAW,EACjC;CAID,MAAM,UACL,mBACA,aACC,oBAAC,OAAD;EAAK,WAAU;EAA4B,KAAM;EAChD,UAAA,oBAACA,QAAU,MAAX,CAAiB,CAAA;CACb,CAAA,GACL,eACD;CAED,OACC,oBAAC,kBAAD,EAAA,UACC,oBAAC,eAAD;EAAe,QAAA;EAAO,OAAQ,EAAE,SAAS,aAAa;EACrD,UAAA,oBAAC,iBAAD;GACmB;GACK;GAEvB,UAAA,qBAAC,cAAD;IACO;IACY;IAFnB,UAAA,CAIG,eACA,OACW;;EACE,CAAA;CACH,CAAA,EACE,CAAA;AAEpB"}
|
|
@@ -1,50 +1,56 @@
|
|
|
1
|
-
// packages/customize-widgets/src/components/customize-widgets/use-clear-selected-block.js
|
|
2
1
|
import { useEffect } from "@wordpress/element";
|
|
3
2
|
import { useDispatch, useSelect } from "@wordpress/data";
|
|
4
|
-
import { store
|
|
3
|
+
import { store } from "@wordpress/block-editor";
|
|
4
|
+
// packages/customize-widgets/src/components/customize-widgets/use-clear-selected-block.js
|
|
5
|
+
/**
|
|
6
|
+
* We can't just use <BlockSelectionClearer> because the customizer has
|
|
7
|
+
* many root nodes rather than just one in the post editor.
|
|
8
|
+
* We need to listen to the focus events in all those roots, and also in
|
|
9
|
+
* the preview iframe.
|
|
10
|
+
* This hook will clear the selected block when focusing outside the editor,
|
|
11
|
+
* with a few exceptions:
|
|
12
|
+
* 1. Focusing on popovers, including `@wordpress/ui` overlays.
|
|
13
|
+
* 2. Focusing on the inspector.
|
|
14
|
+
* 3. Focusing on any modals/dialogs.
|
|
15
|
+
* These cases are normally triggered by user interactions from the editor,
|
|
16
|
+
* not by explicitly focusing outside the editor, hence no need for clearing.
|
|
17
|
+
*
|
|
18
|
+
* @param {Object} sidebarControl The sidebar control instance.
|
|
19
|
+
* @param {Object} popoverRef The ref object of the popover node container.
|
|
20
|
+
*/
|
|
5
21
|
function useClearSelectedBlock(sidebarControl, popoverRef) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}, [
|
|
40
|
-
popoverRef,
|
|
41
|
-
sidebarControl,
|
|
42
|
-
hasSelectedBlock,
|
|
43
|
-
hasMultiSelection,
|
|
44
|
-
clearSelectedBlock
|
|
45
|
-
]);
|
|
22
|
+
const { hasSelectedBlock, hasMultiSelection } = useSelect(store);
|
|
23
|
+
const { clearSelectedBlock } = useDispatch(store);
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (popoverRef.current && sidebarControl) {
|
|
26
|
+
const inspector = sidebarControl.inspector;
|
|
27
|
+
const container = sidebarControl.container[0];
|
|
28
|
+
const ownerDocument = container.ownerDocument;
|
|
29
|
+
const ownerWindow = ownerDocument.defaultView;
|
|
30
|
+
function handleClearSelectedBlock(element) {
|
|
31
|
+
if ((hasSelectedBlock() || hasMultiSelection()) && element && ownerDocument.contains(element) && !container.contains(element) && !popoverRef.current.contains(element) && !element.closest("[data-wp-compat-overlay-slot]") && !element.closest("[role=\"dialog\"]") && !inspector.expanded()) clearSelectedBlock();
|
|
32
|
+
}
|
|
33
|
+
function handleMouseDown(event) {
|
|
34
|
+
handleClearSelectedBlock(event.target);
|
|
35
|
+
}
|
|
36
|
+
function handleBlur() {
|
|
37
|
+
handleClearSelectedBlock(ownerDocument.activeElement);
|
|
38
|
+
}
|
|
39
|
+
ownerDocument.addEventListener("mousedown", handleMouseDown);
|
|
40
|
+
ownerWindow.addEventListener("blur", handleBlur);
|
|
41
|
+
return () => {
|
|
42
|
+
ownerDocument.removeEventListener("mousedown", handleMouseDown);
|
|
43
|
+
ownerWindow.removeEventListener("blur", handleBlur);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}, [
|
|
47
|
+
popoverRef,
|
|
48
|
+
sidebarControl,
|
|
49
|
+
hasSelectedBlock,
|
|
50
|
+
hasMultiSelection,
|
|
51
|
+
clearSelectedBlock
|
|
52
|
+
]);
|
|
46
53
|
}
|
|
47
|
-
export {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
//# sourceMappingURL=use-clear-selected-block.mjs.map
|
|
54
|
+
export { useClearSelectedBlock as default };
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=use-clear-selected-block.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/customize-widgets/use-clear-selected-block.js"],
|
|
4
|
-
"sourcesContent": ["import { useEffect } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * We can't just use <BlockSelectionClearer> because the customizer has\n * many root nodes rather than just one in the post editor.\n * We need to listen to the focus events in all those roots, and also in\n * the preview iframe.\n * This hook will clear the selected block when focusing outside the editor,\n * with a few exceptions:\n * 1. Focusing on popovers, including `@wordpress/ui` overlays.\n * 2. Focusing on the inspector.\n * 3. Focusing on any modals/dialogs.\n * These cases are normally triggered by user interactions from the editor,\n * not by explicitly focusing outside the editor, hence no need for clearing.\n *\n * @param {Object} sidebarControl The sidebar control instance.\n * @param {Object} popoverRef The ref object of the popover node container.\n */\nexport default function useClearSelectedBlock( sidebarControl, popoverRef ) {\n\tconst { hasSelectedBlock, hasMultiSelection } =\n\t\tuseSelect( blockEditorStore );\n\tconst { clearSelectedBlock } = useDispatch( blockEditorStore );\n\n\tuseEffect( () => {\n\t\tif ( popoverRef.current && sidebarControl ) {\n\t\t\tconst inspector = sidebarControl.inspector;\n\t\t\tconst container = sidebarControl.container[ 0 ];\n\t\t\tconst ownerDocument = container.ownerDocument;\n\t\t\tconst ownerWindow = ownerDocument.defaultView;\n\n\t\t\tfunction handleClearSelectedBlock( element ) {\n\t\t\t\tif (\n\t\t\t\t\t// 1. Make sure there are blocks being selected.\n\t\t\t\t\t( hasSelectedBlock() || hasMultiSelection() ) &&\n\t\t\t\t\t// 2. The element should exist in the DOM (not deleted).\n\t\t\t\t\telement &&\n\t\t\t\t\townerDocument.contains( element ) &&\n\t\t\t\t\t// 3. It should also not exist in the container, the popover, nor the dialog.\n\t\t\t\t\t! container.contains( element ) &&\n\t\t\t\t\t! popoverRef.current.contains( element ) &&\n\t\t\t\t\t! element.closest( '[data-wp-compat-overlay-slot]' ) &&\n\t\t\t\t\t! element.closest( '[role=\"dialog\"]' ) &&\n\t\t\t\t\t// 4. The inspector should not be opened.\n\t\t\t\t\t! inspector.expanded()\n\t\t\t\t) {\n\t\t\t\t\tclearSelectedBlock();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Handle mouse down in the same document.\n\t\t\tfunction handleMouseDown( event ) {\n\t\t\t\thandleClearSelectedBlock( event.target );\n\t\t\t}\n\t\t\t// Handle focusing outside the current document, like to iframes.\n\t\t\tfunction handleBlur() {\n\t\t\t\thandleClearSelectedBlock( ownerDocument.activeElement );\n\t\t\t}\n\n\t\t\townerDocument.addEventListener( 'mousedown', handleMouseDown );\n\t\t\townerWindow.addEventListener( 'blur', handleBlur );\n\n\t\t\treturn () => {\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'mousedown',\n\t\t\t\t\thandleMouseDown\n\t\t\t\t);\n\t\t\t\townerWindow.removeEventListener( 'blur', handleBlur );\n\t\t\t};\n\t\t}\n\t}, [\n\t\tpopoverRef,\n\t\tsidebarControl,\n\t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|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"use-clear-selected-block.mjs","names":["blockEditorStore"],"sources":["../../../src/components/customize-widgets/use-clear-selected-block.js"],"sourcesContent":["import { useEffect } from '@wordpress/element';\nimport { useDispatch, useSelect } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\n/**\n * We can't just use <BlockSelectionClearer> because the customizer has\n * many root nodes rather than just one in the post editor.\n * We need to listen to the focus events in all those roots, and also in\n * the preview iframe.\n * This hook will clear the selected block when focusing outside the editor,\n * with a few exceptions:\n * 1. Focusing on popovers, including `@wordpress/ui` overlays.\n * 2. Focusing on the inspector.\n * 3. Focusing on any modals/dialogs.\n * These cases are normally triggered by user interactions from the editor,\n * not by explicitly focusing outside the editor, hence no need for clearing.\n *\n * @param {Object} sidebarControl The sidebar control instance.\n * @param {Object} popoverRef The ref object of the popover node container.\n */\nexport default function useClearSelectedBlock( sidebarControl, popoverRef ) {\n\tconst { hasSelectedBlock, hasMultiSelection } =\n\t\tuseSelect( blockEditorStore );\n\tconst { clearSelectedBlock } = useDispatch( blockEditorStore );\n\n\tuseEffect( () => {\n\t\tif ( popoverRef.current && sidebarControl ) {\n\t\t\tconst inspector = sidebarControl.inspector;\n\t\t\tconst container = sidebarControl.container[ 0 ];\n\t\t\tconst ownerDocument = container.ownerDocument;\n\t\t\tconst ownerWindow = ownerDocument.defaultView;\n\n\t\t\tfunction handleClearSelectedBlock( element ) {\n\t\t\t\tif (\n\t\t\t\t\t// 1. Make sure there are blocks being selected.\n\t\t\t\t\t( hasSelectedBlock() || hasMultiSelection() ) &&\n\t\t\t\t\t// 2. The element should exist in the DOM (not deleted).\n\t\t\t\t\telement &&\n\t\t\t\t\townerDocument.contains( element ) &&\n\t\t\t\t\t// 3. It should also not exist in the container, the popover, nor the dialog.\n\t\t\t\t\t! container.contains( element ) &&\n\t\t\t\t\t! popoverRef.current.contains( element ) &&\n\t\t\t\t\t! element.closest( '[data-wp-compat-overlay-slot]' ) &&\n\t\t\t\t\t! element.closest( '[role=\"dialog\"]' ) &&\n\t\t\t\t\t// 4. The inspector should not be opened.\n\t\t\t\t\t! inspector.expanded()\n\t\t\t\t) {\n\t\t\t\t\tclearSelectedBlock();\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Handle mouse down in the same document.\n\t\t\tfunction handleMouseDown( event ) {\n\t\t\t\thandleClearSelectedBlock( event.target );\n\t\t\t}\n\t\t\t// Handle focusing outside the current document, like to iframes.\n\t\t\tfunction handleBlur() {\n\t\t\t\thandleClearSelectedBlock( ownerDocument.activeElement );\n\t\t\t}\n\n\t\t\townerDocument.addEventListener( 'mousedown', handleMouseDown );\n\t\t\townerWindow.addEventListener( 'blur', handleBlur );\n\n\t\t\treturn () => {\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'mousedown',\n\t\t\t\t\thandleMouseDown\n\t\t\t\t);\n\t\t\t\townerWindow.removeEventListener( 'blur', handleBlur );\n\t\t\t};\n\t\t}\n\t}, [\n\t\tpopoverRef,\n\t\tsidebarControl,\n\t\thasSelectedBlock,\n\t\thasMultiSelection,\n\t\tclearSelectedBlock,\n\t] );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAoBA,SAAwB,sBAAuB,gBAAgB,YAAa;CAC3E,MAAM,EAAE,kBAAkB,sBACzB,UAAWA,KAAiB;CAC7B,MAAM,EAAE,uBAAuB,YAAaA,KAAiB;CAE7D,gBAAiB;EAChB,IAAK,WAAW,WAAW,gBAAiB;GAC3C,MAAM,YAAY,eAAe;GACjC,MAAM,YAAY,eAAe,UAAW;GAC5C,MAAM,gBAAgB,UAAU;GAChC,MAAM,cAAc,cAAc;GAElC,SAAS,yBAA0B,SAAU;IAC5C,KAEG,iBAAiB,KAAK,kBAAkB,MAE1C,WACA,cAAc,SAAU,OAAQ,KAEhC,CAAE,UAAU,SAAU,OAAQ,KAC9B,CAAE,WAAW,QAAQ,SAAU,OAAQ,KACvC,CAAE,QAAQ,QAAS,+BAAgC,KACnD,CAAE,QAAQ,QAAS,mBAAkB,KAErC,CAAE,UAAU,SAAS,GAErB,mBAAmB;GAErB;GAGA,SAAS,gBAAiB,OAAQ;IACjC,yBAA0B,MAAM,MAAO;GACxC;GAEA,SAAS,aAAa;IACrB,yBAA0B,cAAc,aAAc;GACvD;GAEA,cAAc,iBAAkB,aAAa,eAAgB;GAC7D,YAAY,iBAAkB,QAAQ,UAAW;GAEjD,aAAa;IACZ,cAAc,oBACb,aACA,eACD;IACA,YAAY,oBAAqB,QAAQ,UAAW;GACrD;EACD;CACD,GAAG;EACF;EACA;EACA;EACA;EACA;CACD,CAAE;AACH"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// packages/customize-widgets/src/components/error-boundary/index.jsx
|
|
2
1
|
import { Component } from "@wordpress/element";
|
|
3
2
|
import { speak } from "@wordpress/a11y";
|
|
4
3
|
import { __ } from "@wordpress/i18n";
|
|
@@ -6,148 +5,124 @@ import { Card, CollapsibleCard, Notice, Stack, Text } from "@wordpress/ui";
|
|
|
6
5
|
import { useCopyToClipboard } from "@wordpress/compose";
|
|
7
6
|
import { doAction } from "@wordpress/hooks";
|
|
8
7
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
8
|
+
// packages/customize-widgets/src/components/error-boundary/index.jsx
|
|
9
9
|
function getErrorNotice() {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
)
|
|
15
|
-
};
|
|
10
|
+
return {
|
|
11
|
+
title: __("The editor has crashed"),
|
|
12
|
+
description: __("An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.")
|
|
13
|
+
};
|
|
16
14
|
}
|
|
17
15
|
function getErrorName(error) {
|
|
18
|
-
|
|
16
|
+
return error instanceof Error && error.name || "Error";
|
|
19
17
|
}
|
|
20
18
|
function getErrorMessage(error) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (typeof error?.message === "string" && error.message) {
|
|
25
|
-
return error.message;
|
|
26
|
-
}
|
|
27
|
-
return "An unknown error occurred.";
|
|
19
|
+
if (typeof error === "string" && error) return error;
|
|
20
|
+
if (typeof error?.message === "string" && error.message) return error.message;
|
|
21
|
+
return "An unknown error occurred.";
|
|
28
22
|
}
|
|
29
23
|
function getErrorSections(error, componentStack) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
preformatted: true
|
|
51
|
-
});
|
|
52
|
-
return sections;
|
|
24
|
+
const sections = [{
|
|
25
|
+
label: getErrorName(error),
|
|
26
|
+
content: getErrorMessage(error)
|
|
27
|
+
}];
|
|
28
|
+
if (error?.stack) sections.push({
|
|
29
|
+
label: "Stack",
|
|
30
|
+
content: error.stack.trim(),
|
|
31
|
+
preformatted: true
|
|
32
|
+
});
|
|
33
|
+
if (componentStack) sections.push({
|
|
34
|
+
label: "Component stack",
|
|
35
|
+
content: componentStack.trim(),
|
|
36
|
+
preformatted: true
|
|
37
|
+
});
|
|
38
|
+
sections.push({
|
|
39
|
+
label: "Environment",
|
|
40
|
+
content: `User agent: ${window.navigator.userAgent}`,
|
|
41
|
+
preformatted: true
|
|
42
|
+
});
|
|
43
|
+
return sections;
|
|
53
44
|
}
|
|
54
45
|
function getErrorReport(error, componentStack) {
|
|
55
|
-
|
|
56
|
-
({ label, content, preformatted }) => `**${label}**
|
|
57
|
-
|
|
58
|
-
${preformatted ? `\`\`\`
|
|
59
|
-
${content}
|
|
60
|
-
\`\`\`` : content}`
|
|
61
|
-
);
|
|
62
|
-
return ["### Error report", ...sections].join("\n\n");
|
|
46
|
+
return ["### Error report", ...getErrorSections(error, componentStack).map(({ label, content, preformatted }) => `**${label}**\n\n${preformatted ? `\`\`\`\n${content}\n\`\`\`` : content}`)].join("\n\n");
|
|
63
47
|
}
|
|
64
48
|
function CopyButton({ text, children, variant = "outline" }) {
|
|
65
|
-
|
|
66
|
-
|
|
49
|
+
const ref = useCopyToClipboard(text);
|
|
50
|
+
return /* @__PURE__ */ jsx(Notice.ActionButton, {
|
|
51
|
+
variant,
|
|
52
|
+
ref,
|
|
53
|
+
children
|
|
54
|
+
});
|
|
67
55
|
}
|
|
68
56
|
function ErrorReport({ error, componentStack }) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
57
|
+
return /* @__PURE__ */ jsx(Stack, {
|
|
58
|
+
className: "customize-widgets-error-boundary__report",
|
|
59
|
+
direction: "column",
|
|
60
|
+
gap: "md",
|
|
61
|
+
children: getErrorSections(error, componentStack).map(({ label, content }) => /* @__PURE__ */ jsxs(Stack, {
|
|
62
|
+
direction: "column",
|
|
63
|
+
gap: "xs",
|
|
64
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
65
|
+
variant: "heading-md",
|
|
66
|
+
children: label
|
|
67
|
+
}), /* @__PURE__ */ jsx("pre", {
|
|
68
|
+
className: "customize-widgets-error-boundary__report-section",
|
|
69
|
+
children: content
|
|
70
|
+
})]
|
|
71
|
+
}, label))
|
|
72
|
+
});
|
|
83
73
|
}
|
|
84
74
|
function ErrorDetails({ error, componentStack }) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
) })
|
|
94
|
-
] });
|
|
75
|
+
return /* @__PURE__ */ jsxs(CollapsibleCard.Root, {
|
|
76
|
+
className: "customize-widgets-error-boundary__details",
|
|
77
|
+
children: [/* @__PURE__ */ jsx(CollapsibleCard.Header, { children: /* @__PURE__ */ jsx(Card.Title, { children: __("Error details") }) }), /* @__PURE__ */ jsx(CollapsibleCard.Content, { children: /* @__PURE__ */ jsx(ErrorReport, {
|
|
78
|
+
error,
|
|
79
|
+
componentStack
|
|
80
|
+
}) })]
|
|
81
|
+
});
|
|
95
82
|
}
|
|
96
83
|
var ErrorBoundary = class extends Component {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
globalThis.SCRIPT_DEBUG ? /* @__PURE__ */ jsx(
|
|
139
|
-
ErrorDetails,
|
|
140
|
-
{
|
|
141
|
-
error,
|
|
142
|
-
componentStack
|
|
143
|
-
}
|
|
144
|
-
) : null
|
|
145
|
-
]
|
|
146
|
-
}
|
|
147
|
-
);
|
|
148
|
-
}
|
|
84
|
+
constructor() {
|
|
85
|
+
super(...arguments);
|
|
86
|
+
this.state = {
|
|
87
|
+
error: null,
|
|
88
|
+
componentStack: null
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
componentDidCatch(error, errorInfo) {
|
|
92
|
+
const { title, description } = getErrorNotice();
|
|
93
|
+
speak(`${title}. ${description}`, "assertive");
|
|
94
|
+
this.setState({ componentStack: errorInfo?.componentStack });
|
|
95
|
+
doAction("editor.ErrorBoundary.errorLogged", error, errorInfo);
|
|
96
|
+
}
|
|
97
|
+
static getDerivedStateFromError(error) {
|
|
98
|
+
return { error };
|
|
99
|
+
}
|
|
100
|
+
render() {
|
|
101
|
+
const { error, componentStack } = this.state;
|
|
102
|
+
if (!error) return this.props.children;
|
|
103
|
+
const { title, description } = getErrorNotice();
|
|
104
|
+
return /* @__PURE__ */ jsxs(Stack, {
|
|
105
|
+
className: "customize-widgets-error-boundary",
|
|
106
|
+
direction: "column",
|
|
107
|
+
gap: "lg",
|
|
108
|
+
children: [/* @__PURE__ */ jsxs(Notice.Root, {
|
|
109
|
+
intent: "error",
|
|
110
|
+
children: [
|
|
111
|
+
/* @__PURE__ */ jsx(Notice.Title, { children: title }),
|
|
112
|
+
/* @__PURE__ */ jsx(Notice.Description, { children: description }),
|
|
113
|
+
/* @__PURE__ */ jsx(Notice.Actions, { children: /* @__PURE__ */ jsx(CopyButton, {
|
|
114
|
+
variant: "solid",
|
|
115
|
+
text: () => getErrorReport(error, componentStack),
|
|
116
|
+
children: __("Copy error")
|
|
117
|
+
}) })
|
|
118
|
+
]
|
|
119
|
+
}), globalThis.SCRIPT_DEBUG ? /* @__PURE__ */ jsx(ErrorDetails, {
|
|
120
|
+
error,
|
|
121
|
+
componentStack
|
|
122
|
+
}) : null]
|
|
123
|
+
});
|
|
124
|
+
}
|
|
149
125
|
};
|
|
150
|
-
export {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
//# sourceMappingURL=index.mjs.map
|
|
126
|
+
export { ErrorBoundary as default };
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/error-boundary/index.jsx"],
|
|
4
|
-
"sourcesContent": ["import { Component } from '@wordpress/element';\nimport { speak } from '@wordpress/a11y';\nimport { __ } from '@wordpress/i18n';\nimport { Card, CollapsibleCard, Notice, Stack, Text } from '@wordpress/ui';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { doAction } from '@wordpress/hooks';\n\nfunction getErrorNotice() {\n\treturn {\n\t\ttitle: __( 'The editor has crashed' ),\n\t\tdescription: __(\n\t\t\t'An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.'\n\t\t),\n\t};\n}\n\n// A boundary catches whatever was thrown, which is not always an `Error`.\nfunction getErrorName( error ) {\n\treturn ( error instanceof Error && error.name ) || 'Error';\n}\n\nfunction getErrorMessage( error ) {\n\tif ( typeof error === 'string' && error ) {\n\t\treturn error;\n\t}\n\n\tif ( typeof error?.message === 'string' && error.message ) {\n\t\treturn error.message;\n\t}\n\n\treturn 'An unknown error occurred.';\n}\n\n// The sections of the report, shared by the copied Markdown and the details\n// panel so that the two cannot drift apart. Deliberately untranslated: both\n// are developer-facing, and the report is pasted into a bug report.\nfunction getErrorSections( error, componentStack ) {\n\tconst sections = [\n\t\t{ label: getErrorName( error ), content: getErrorMessage( error ) },\n\t];\n\n\tif ( error?.stack ) {\n\t\tsections.push( {\n\t\t\tlabel: 'Stack',\n\t\t\tcontent: error.stack.trim(),\n\t\t\tpreformatted: true,\n\t\t} );\n\t}\n\n\tif ( componentStack ) {\n\t\tsections.push( {\n\t\t\tlabel: 'Component stack',\n\t\t\tcontent: componentStack.trim(),\n\t\t\tpreformatted: true,\n\t\t} );\n\t}\n\n\tsections.push( {\n\t\tlabel: 'Environment',\n\t\tcontent: `User agent: ${ window.navigator.userAgent }`,\n\t\tpreformatted: true,\n\t} );\n\n\treturn sections;\n}\n\n// Markdown, so the report stays readable as plain text and renders when pasted\n// into a bug report.\nfunction getErrorReport( error, componentStack ) {\n\tconst sections = getErrorSections( error, componentStack ).map(\n\t\t( { label, content, preformatted } ) =>\n\t\t\t`**${ label }**\\n\\n${\n\t\t\t\tpreformatted ? `\\`\\`\\`\\n${ content }\\n\\`\\`\\`` : content\n\t\t\t}`\n\t);\n\n\treturn [ '### Error report', ...sections ].join( '\\n\\n' );\n}\n\nfunction CopyButton( { text, children, variant = 'outline' } ) {\n\tconst ref = useCopyToClipboard( text );\n\treturn (\n\t\t<Notice.ActionButton variant={ variant } ref={ ref }>\n\t\t\t{ children }\n\t\t</Notice.ActionButton>\n\t);\n}\n\nfunction ErrorReport( { error, componentStack } ) {\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"customize-widgets-error-boundary__report\"\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"md\"\n\t\t>\n\t\t\t{ getErrorSections( error, componentStack ).map(\n\t\t\t\t( { label, content } ) => (\n\t\t\t\t\t<Stack key={ label } direction=\"column\" gap=\"xs\">\n\t\t\t\t\t\t<Text variant=\"heading-md\">{ label }</Text>\n\t\t\t\t\t\t<pre className=\"customize-widgets-error-boundary__report-section\">\n\t\t\t\t\t\t\t{ content }\n\t\t\t\t\t\t</pre>\n\t\t\t\t\t</Stack>\n\t\t\t\t)\n\t\t\t) }\n\t\t</Stack>\n\t);\n}\n\nfunction ErrorDetails( { error, componentStack } ) {\n\treturn (\n\t\t<CollapsibleCard.Root className=\"customize-widgets-error-boundary__details\">\n\t\t\t<CollapsibleCard.Header>\n\t\t\t\t<Card.Title>{ __( 'Error details' ) }</Card.Title>\n\t\t\t</CollapsibleCard.Header>\n\t\t\t<CollapsibleCard.Content>\n\t\t\t\t<ErrorReport\n\t\t\t\t\terror={ error }\n\t\t\t\t\tcomponentStack={ componentStack }\n\t\t\t\t/>\n\t\t\t</CollapsibleCard.Content>\n\t\t</CollapsibleCard.Root>\n\t);\n}\n\nexport default class ErrorBoundary extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\n\t\tthis.state = {\n\t\t\terror: null,\n\t\t\tcomponentStack: null,\n\t\t};\n\t}\n\n\tcomponentDidCatch( error, errorInfo ) {\n\t\tconst { title, description } = getErrorNotice();\n\t\tspeak( `${ title }. ${ description }`, 'assertive' );\n\t\tthis.setState( { componentStack: errorInfo?.componentStack } );\n\t\tdoAction( 'editor.ErrorBoundary.errorLogged', error, errorInfo );\n\t}\n\n\tstatic getDerivedStateFromError( error ) {\n\t\treturn { error };\n\t}\n\n\trender() {\n\t\tconst { error, componentStack } = this.state;\n\t\tif ( ! error ) {\n\t\t\treturn this.props.children;\n\t\t}\n\n\t\tconst { title, description } = getErrorNotice();\n\n\t\treturn (\n\t\t\t<Stack\n\t\t\t\tclassName=\"customize-widgets-error-boundary\"\n\t\t\t\tdirection=\"column\"\n\t\t\t\tgap=\"lg\"\n\t\t\t>\n\t\t\t\t<Notice.Root intent=\"error\">\n\t\t\t\t\t<Notice.Title>{ title }</Notice.Title>\n\t\t\t\t\t<Notice.Description>{ description }</Notice.Description>\n\t\t\t\t\t<Notice.Actions>\n\t\t\t\t\t\t<CopyButton\n\t\t\t\t\t\t\tvariant=\"solid\"\n\t\t\t\t\t\t\ttext={ () =>\n\t\t\t\t\t\t\t\tgetErrorReport( error, componentStack )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Copy error' ) }\n\t\t\t\t\t\t</CopyButton>\n\t\t\t\t\t</Notice.Actions>\n\t\t\t\t</Notice.Root>\n\t\t\t\t{ globalThis.SCRIPT_DEBUG ? (\n\t\t\t\t\t<ErrorDetails\n\t\t\t\t\t\terror={ error }\n\t\t\t\t\t\tcomponentStack={ componentStack }\n\t\t\t\t\t/>\n\t\t\t\t) : null }\n\t\t\t</Stack>\n\t\t);\n\t}\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,iBAAiB;AAC1B,SAAS,aAAa;AACtB,SAAS,UAAU;AACnB,SAAS,MAAM,iBAAiB,QAAQ,OAAO,YAAY;AAC3D,SAAS,0BAA0B;AACnC,SAAS,gBAAgB;AA6EvB,cAeG,YAfH;AA3EF,SAAS,iBAAiB;AACzB,SAAO;AAAA,IACN,OAAO,GAAI,wBAAyB;AAAA,IACpC,aAAa;AAAA,MACZ;AAAA,IACD;AAAA,EACD;AACD;AAGA,SAAS,aA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,YAAY,IAAI,eAAe;AAE9C,WACC;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,WAAU;AAAA,QACV,KAAI;AAAA,QAEJ;AAAA,+BAAC,OAAO,MAAP,EAAY,QAAO,SACnB;AAAA,gCAAC,OAAO,OAAP,EAAe,iBAAO;AAAA,YACvB,oBAAC,OAAO,aAAP,EAAqB,uBAAa;AAAA,YACnC,oBAAC,OAAO,SAAP,EACA;AAAA,cAAC;AAAA;AAAA,gBACA,SAAQ;AAAA,gBACR,MAAO,MACN,eAAgB,OAAO,cAAe;AAAA,gBAGrC,aAAI,YAAa;AAAA;AAAA,YACpB,GACD;AAAA,aACD;AAAA,UACE,WAAW,eACZ;AAAA,YAAC;AAAA;AAAA,cACA;AAAA,cACA;AAAA;AAAA,UACD,IACG;AAAA;AAAA;AAAA,IACL;AAAA,EAEF;AACD;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/components/error-boundary/index.jsx"],"sourcesContent":["import { Component } from '@wordpress/element';\nimport { speak } from '@wordpress/a11y';\nimport { __ } from '@wordpress/i18n';\nimport { Card, CollapsibleCard, Notice, Stack, Text } from '@wordpress/ui';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { doAction } from '@wordpress/hooks';\n\nfunction getErrorNotice() {\n\treturn {\n\t\ttitle: __( 'The editor has crashed' ),\n\t\tdescription: __(\n\t\t\t'An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.'\n\t\t),\n\t};\n}\n\n// A boundary catches whatever was thrown, which is not always an `Error`.\nfunction getErrorName( error ) {\n\treturn ( error instanceof Error && error.name ) || 'Error';\n}\n\nfunction getErrorMessage( error ) {\n\tif ( typeof error === 'string' && error ) {\n\t\treturn error;\n\t}\n\n\tif ( typeof error?.message === 'string' && error.message ) {\n\t\treturn error.message;\n\t}\n\n\treturn 'An unknown error occurred.';\n}\n\n// The sections of the report, shared by the copied Markdown and the details\n// panel so that the two cannot drift apart. Deliberately untranslated: both\n// are developer-facing, and the report is pasted into a bug report.\nfunction getErrorSections( error, componentStack ) {\n\tconst sections = [\n\t\t{ label: getErrorName( error ), content: getErrorMessage( error ) },\n\t];\n\n\tif ( error?.stack ) {\n\t\tsections.push( {\n\t\t\tlabel: 'Stack',\n\t\t\tcontent: error.stack.trim(),\n\t\t\tpreformatted: true,\n\t\t} );\n\t}\n\n\tif ( componentStack ) {\n\t\tsections.push( {\n\t\t\tlabel: 'Component stack',\n\t\t\tcontent: componentStack.trim(),\n\t\t\tpreformatted: true,\n\t\t} );\n\t}\n\n\tsections.push( {\n\t\tlabel: 'Environment',\n\t\tcontent: `User agent: ${ window.navigator.userAgent }`,\n\t\tpreformatted: true,\n\t} );\n\n\treturn sections;\n}\n\n// Markdown, so the report stays readable as plain text and renders when pasted\n// into a bug report.\nfunction getErrorReport( error, componentStack ) {\n\tconst sections = getErrorSections( error, componentStack ).map(\n\t\t( { label, content, preformatted } ) =>\n\t\t\t`**${ label }**\\n\\n${\n\t\t\t\tpreformatted ? `\\`\\`\\`\\n${ content }\\n\\`\\`\\`` : content\n\t\t\t}`\n\t);\n\n\treturn [ '### Error report', ...sections ].join( '\\n\\n' );\n}\n\nfunction CopyButton( { text, children, variant = 'outline' } ) {\n\tconst ref = useCopyToClipboard( text );\n\treturn (\n\t\t<Notice.ActionButton variant={ variant } ref={ ref }>\n\t\t\t{ children }\n\t\t</Notice.ActionButton>\n\t);\n}\n\nfunction ErrorReport( { error, componentStack } ) {\n\treturn (\n\t\t<Stack\n\t\t\tclassName=\"customize-widgets-error-boundary__report\"\n\t\t\tdirection=\"column\"\n\t\t\tgap=\"md\"\n\t\t>\n\t\t\t{ getErrorSections( error, componentStack ).map(\n\t\t\t\t( { label, content } ) => (\n\t\t\t\t\t<Stack key={ label } direction=\"column\" gap=\"xs\">\n\t\t\t\t\t\t<Text variant=\"heading-md\">{ label }</Text>\n\t\t\t\t\t\t<pre className=\"customize-widgets-error-boundary__report-section\">\n\t\t\t\t\t\t\t{ content }\n\t\t\t\t\t\t</pre>\n\t\t\t\t\t</Stack>\n\t\t\t\t)\n\t\t\t) }\n\t\t</Stack>\n\t);\n}\n\nfunction ErrorDetails( { error, componentStack } ) {\n\treturn (\n\t\t<CollapsibleCard.Root className=\"customize-widgets-error-boundary__details\">\n\t\t\t<CollapsibleCard.Header>\n\t\t\t\t<Card.Title>{ __( 'Error details' ) }</Card.Title>\n\t\t\t</CollapsibleCard.Header>\n\t\t\t<CollapsibleCard.Content>\n\t\t\t\t<ErrorReport\n\t\t\t\t\terror={ error }\n\t\t\t\t\tcomponentStack={ componentStack }\n\t\t\t\t/>\n\t\t\t</CollapsibleCard.Content>\n\t\t</CollapsibleCard.Root>\n\t);\n}\n\nexport default class ErrorBoundary extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\n\t\tthis.state = {\n\t\t\terror: null,\n\t\t\tcomponentStack: null,\n\t\t};\n\t}\n\n\tcomponentDidCatch( error, errorInfo ) {\n\t\tconst { title, description } = getErrorNotice();\n\t\tspeak( `${ title }. ${ description }`, 'assertive' );\n\t\tthis.setState( { componentStack: errorInfo?.componentStack } );\n\t\tdoAction( 'editor.ErrorBoundary.errorLogged', error, errorInfo );\n\t}\n\n\tstatic getDerivedStateFromError( error ) {\n\t\treturn { error };\n\t}\n\n\trender() {\n\t\tconst { error, componentStack } = this.state;\n\t\tif ( ! error ) {\n\t\t\treturn this.props.children;\n\t\t}\n\n\t\tconst { title, description } = getErrorNotice();\n\n\t\treturn (\n\t\t\t<Stack\n\t\t\t\tclassName=\"customize-widgets-error-boundary\"\n\t\t\t\tdirection=\"column\"\n\t\t\t\tgap=\"lg\"\n\t\t\t>\n\t\t\t\t<Notice.Root intent=\"error\">\n\t\t\t\t\t<Notice.Title>{ title }</Notice.Title>\n\t\t\t\t\t<Notice.Description>{ description }</Notice.Description>\n\t\t\t\t\t<Notice.Actions>\n\t\t\t\t\t\t<CopyButton\n\t\t\t\t\t\t\tvariant=\"solid\"\n\t\t\t\t\t\t\ttext={ () =>\n\t\t\t\t\t\t\t\tgetErrorReport( error, componentStack )\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Copy error' ) }\n\t\t\t\t\t\t</CopyButton>\n\t\t\t\t\t</Notice.Actions>\n\t\t\t\t</Notice.Root>\n\t\t\t\t{ globalThis.SCRIPT_DEBUG ? (\n\t\t\t\t\t<ErrorDetails\n\t\t\t\t\t\terror={ error }\n\t\t\t\t\t\tcomponentStack={ componentStack }\n\t\t\t\t\t/>\n\t\t\t\t) : null }\n\t\t\t</Stack>\n\t\t);\n\t}\n}\n"],"mappings":";;;;;;;;AAOA,SAAS,iBAAiB;CACzB,OAAO;EACN,OAAO,GAAI,wBAAyB;EACpC,aAAa,GACZ,iHACD;CACD;AACD;AAGA,SAAS,aAAc,OAAQ;CAC9B,OAAS,iBAAiB,SAAS,MAAM,QAAU;AACpD;AAEA,SAAS,gBAAiB,OAAQ;CACjC,IAAK,OAAO,UAAU,YAAY,OACjC,OAAO;CAGR,IAAK,OAAO,OAAO,YAAY,YAAY,MAAM,SAChD,OAAO,MAAM;CAGd,OAAO;AACR;AAKA,SAAS,iBAAkB,OAAO,gBAAiB;CAClD,MAAM,WAAW,CAChB;EAAE,OAAO,aAAc,KAAM;EAAG,SAAS,gBAAiB,KAAM;CAAE,CACnE;CAEA,IAAK,OAAO,OACX,SAAS,KAAM;EACd,OAAO;EACP,SAAS,MAAM,MAAM,KAAK;EAC1B,cAAc;CACf,CAAE;CAGH,IAAK,gBACJ,SAAS,KAAM;EACd,OAAO;EACP,SAAS,eAAe,KAAK;EAC7B,cAAc;CACf,CAAE;CAGH,SAAS,KAAM;EACd,OAAO;EACP,SAAS,eAAgB,OAAO,UAAU;EAC1C,cAAc;CACf,CAAE;CAEF,OAAO;AACR;AAIA,SAAS,eAAgB,OAAO,gBAAiB;CAQhD,OAAO,CAAE,oBAAoB,GAPZ,iBAAkB,OAAO,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