@wordpress/customize-widgets 5.57.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 -95
- 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 +46 -72
- 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 +30 -31
- package/src/components/customize-widgets/index.jsx +5 -2
- package/src/components/customize-widgets/use-clear-selected-block.js +2 -1
- package/src/components/welcome-guide/index.jsx +6 -2
- package/CHANGELOG.md +0 -289
- package/build/filters/index.cjs.map +0 -7
- package/build-module/filters/index.mjs.map +0 -7
|
@@ -1,173 +1,133 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// packages/customize-widgets/src/components/error-boundary/index.jsx
|
|
20
|
-
var error_boundary_exports = {};
|
|
21
|
-
__export(error_boundary_exports, {
|
|
22
|
-
default: () => ErrorBoundary
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
23
5
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
6
|
+
let _wordpress_element = require("@wordpress/element");
|
|
7
|
+
let _wordpress_a11y = require("@wordpress/a11y");
|
|
8
|
+
let _wordpress_i18n = require("@wordpress/i18n");
|
|
9
|
+
let _wordpress_ui = require("@wordpress/ui");
|
|
10
|
+
let _wordpress_compose = require("@wordpress/compose");
|
|
11
|
+
let _wordpress_hooks = require("@wordpress/hooks");
|
|
12
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
13
|
+
// packages/customize-widgets/src/components/error-boundary/index.jsx
|
|
32
14
|
function getErrorNotice() {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
)
|
|
38
|
-
};
|
|
15
|
+
return {
|
|
16
|
+
title: (0, _wordpress_i18n.__)("The editor has crashed"),
|
|
17
|
+
description: (0, _wordpress_i18n.__)("An unknown error occurred. Reload your browser to try again, or copy the error to report the problem or search.")
|
|
18
|
+
};
|
|
39
19
|
}
|
|
40
20
|
function getErrorName(error) {
|
|
41
|
-
|
|
21
|
+
return error instanceof Error && error.name || "Error";
|
|
42
22
|
}
|
|
43
23
|
function getErrorMessage(error) {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (typeof error?.message === "string" && error.message) {
|
|
48
|
-
return error.message;
|
|
49
|
-
}
|
|
50
|
-
return "An unknown error occurred.";
|
|
24
|
+
if (typeof error === "string" && error) return error;
|
|
25
|
+
if (typeof error?.message === "string" && error.message) return error.message;
|
|
26
|
+
return "An unknown error occurred.";
|
|
51
27
|
}
|
|
52
28
|
function getErrorSections(error, componentStack) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
preformatted: true
|
|
74
|
-
});
|
|
75
|
-
return sections;
|
|
29
|
+
const sections = [{
|
|
30
|
+
label: getErrorName(error),
|
|
31
|
+
content: getErrorMessage(error)
|
|
32
|
+
}];
|
|
33
|
+
if (error?.stack) sections.push({
|
|
34
|
+
label: "Stack",
|
|
35
|
+
content: error.stack.trim(),
|
|
36
|
+
preformatted: true
|
|
37
|
+
});
|
|
38
|
+
if (componentStack) sections.push({
|
|
39
|
+
label: "Component stack",
|
|
40
|
+
content: componentStack.trim(),
|
|
41
|
+
preformatted: true
|
|
42
|
+
});
|
|
43
|
+
sections.push({
|
|
44
|
+
label: "Environment",
|
|
45
|
+
content: `User agent: ${window.navigator.userAgent}`,
|
|
46
|
+
preformatted: true
|
|
47
|
+
});
|
|
48
|
+
return sections;
|
|
76
49
|
}
|
|
77
50
|
function getErrorReport(error, componentStack) {
|
|
78
|
-
|
|
79
|
-
({ label, content, preformatted }) => `**${label}**
|
|
80
|
-
|
|
81
|
-
${preformatted ? `\`\`\`
|
|
82
|
-
${content}
|
|
83
|
-
\`\`\`` : content}`
|
|
84
|
-
);
|
|
85
|
-
return ["### Error report", ...sections].join("\n\n");
|
|
51
|
+
return ["### Error report", ...getErrorSections(error, componentStack).map(({ label, content, preformatted }) => `**${label}**\n\n${preformatted ? `\`\`\`\n${content}\n\`\`\`` : content}`)].join("\n\n");
|
|
86
52
|
}
|
|
87
53
|
function CopyButton({ text, children, variant = "outline" }) {
|
|
88
|
-
|
|
89
|
-
|
|
54
|
+
const ref = (0, _wordpress_compose.useCopyToClipboard)(text);
|
|
55
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Notice.ActionButton, {
|
|
56
|
+
variant,
|
|
57
|
+
ref,
|
|
58
|
+
children
|
|
59
|
+
});
|
|
90
60
|
}
|
|
91
61
|
function ErrorReport({ error, componentStack }) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
62
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Stack, {
|
|
63
|
+
className: "customize-widgets-error-boundary__report",
|
|
64
|
+
direction: "column",
|
|
65
|
+
gap: "md",
|
|
66
|
+
children: getErrorSections(error, componentStack).map(({ label, content }) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_ui.Stack, {
|
|
67
|
+
direction: "column",
|
|
68
|
+
gap: "xs",
|
|
69
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Text, {
|
|
70
|
+
variant: "heading-md",
|
|
71
|
+
children: label
|
|
72
|
+
}), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("pre", {
|
|
73
|
+
className: "customize-widgets-error-boundary__report-section",
|
|
74
|
+
children: content
|
|
75
|
+
})]
|
|
76
|
+
}, label))
|
|
77
|
+
});
|
|
106
78
|
}
|
|
107
79
|
function ErrorDetails({ error, componentStack }) {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
116
|
-
) })
|
|
117
|
-
] });
|
|
80
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_ui.CollapsibleCard.Root, {
|
|
81
|
+
className: "customize-widgets-error-boundary__details",
|
|
82
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.CollapsibleCard.Header, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Card.Title, { children: (0, _wordpress_i18n.__)("Error details") }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.CollapsibleCard.Content, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorReport, {
|
|
83
|
+
error,
|
|
84
|
+
componentStack
|
|
85
|
+
}) })]
|
|
86
|
+
});
|
|
118
87
|
}
|
|
119
|
-
var ErrorBoundary = class extends
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
globalThis.SCRIPT_DEBUG ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
162
|
-
ErrorDetails,
|
|
163
|
-
{
|
|
164
|
-
error,
|
|
165
|
-
componentStack
|
|
166
|
-
}
|
|
167
|
-
) : null
|
|
168
|
-
]
|
|
169
|
-
}
|
|
170
|
-
);
|
|
171
|
-
}
|
|
88
|
+
var ErrorBoundary = class extends _wordpress_element.Component {
|
|
89
|
+
constructor() {
|
|
90
|
+
super(...arguments);
|
|
91
|
+
this.state = {
|
|
92
|
+
error: null,
|
|
93
|
+
componentStack: null
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
componentDidCatch(error, errorInfo) {
|
|
97
|
+
const { title, description } = getErrorNotice();
|
|
98
|
+
(0, _wordpress_a11y.speak)(`${title}. ${description}`, "assertive");
|
|
99
|
+
this.setState({ componentStack: errorInfo?.componentStack });
|
|
100
|
+
(0, _wordpress_hooks.doAction)("editor.ErrorBoundary.errorLogged", error, errorInfo);
|
|
101
|
+
}
|
|
102
|
+
static getDerivedStateFromError(error) {
|
|
103
|
+
return { error };
|
|
104
|
+
}
|
|
105
|
+
render() {
|
|
106
|
+
const { error, componentStack } = this.state;
|
|
107
|
+
if (!error) return this.props.children;
|
|
108
|
+
const { title, description } = getErrorNotice();
|
|
109
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_ui.Stack, {
|
|
110
|
+
className: "customize-widgets-error-boundary",
|
|
111
|
+
direction: "column",
|
|
112
|
+
gap: "lg",
|
|
113
|
+
children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)(_wordpress_ui.Notice.Root, {
|
|
114
|
+
intent: "error",
|
|
115
|
+
children: [
|
|
116
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Notice.Title, { children: title }),
|
|
117
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Notice.Description, { children: description }),
|
|
118
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_wordpress_ui.Notice.Actions, { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CopyButton, {
|
|
119
|
+
variant: "solid",
|
|
120
|
+
text: () => getErrorReport(error, componentStack),
|
|
121
|
+
children: (0, _wordpress_i18n.__)("Copy error")
|
|
122
|
+
}) })
|
|
123
|
+
]
|
|
124
|
+
}), globalThis.SCRIPT_DEBUG ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ErrorDetails, {
|
|
125
|
+
error,
|
|
126
|
+
componentStack
|
|
127
|
+
}) : null]
|
|
128
|
+
});
|
|
129
|
+
}
|
|
172
130
|
};
|
|
173
|
-
|
|
131
|
+
exports.default = ErrorBoundary;
|
|
132
|
+
|
|
133
|
+
//# sourceMappingURL=index.cjs.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;AAAA;AAAA;AAAA;AAAA;AAAA,qBAA0B;AAC1B,kBAAsB;AACtB,kBAAmB;AACnB,gBAA2D;AAC3D,qBAAmC;AACnC,mBAAyB;AA6EvB;AA3EF,SAAS,iBAAiB;AACzB,SAAO;AAAA,IACN,WAAO,g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IAAI,KAAK;AACvC,QAAK,CAAE,OAAQ;AACd,aAAO,KAAK,MAAM;AAAA,IACnB;AAEA,UAAM,EAAE,OAAO,YAAY,IAAI,eAAe;AAE9C,WACC;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,WAAU;AAAA,QACV,KAAI;AAAA,QAEJ;AAAA,uDAAC,iBAAO,MAAP,EAAY,QAAO,SACnB;AAAA,wDAAC,iBAAO,OAAP,EAAe,iBAAO;AAAA,YACvB,4CAAC,iBAAO,aAAP,EAAqB,uBAAa;AAAA,YACnC,4CAAC,iBAAO,SAAP,EACA;AAAA,cAAC;AAAA;AAAA,gBACA,SAAQ;AAAA,gBACR,MAAO,MACN,eAAgB,OAAO,cAAe;AAAA,gBAGrC,8BAAI,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.cjs","names":["__","useCopyToClipboard","Notice","Stack","Text","CollapsibleCard","Card","Component"],"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,QAAA,GAAOA,gBAAAA,GAAAA,CAAI,wBAAyB;EACpC,cAAA,GAAaA,gBAAAA,GAAAA,CACZ,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,c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AA,IAAA,CAACA,cAAAA,OAAO,SAAR,EAAA,UACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,YAAD;MACC,SAAQ;MACR,YACC,eAAgB,OAAO,cAAe;MAGrCF,WAAAA,GAAAA,gBAAAA,GAAAA,CAAI,YAAa;KACR,CAAA,EACG,CAAA;IACJ;GACX,CAAA,GAAA,WAAW,eACZ,iBAAA,GAAA,kBAAA,IAAA,CAAC,cAAD;IACS;IACS;GACjB,CAAA,IACE,IACE;;CAET;AACD"}
|
|
@@ -1,88 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// packages/customize-widgets/src/components/focus-control/index.jsx
|
|
20
|
-
var focus_control_exports = {};
|
|
21
|
-
__export(focus_control_exports, {
|
|
22
|
-
default: () => FocusControl,
|
|
23
|
-
useFocusControl: () => useFocusControl
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
24
5
|
});
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
6
|
+
let _wordpress_element = require("@wordpress/element");
|
|
7
|
+
let ______utils_js = require("../../utils.cjs");
|
|
8
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
9
|
+
// packages/customize-widgets/src/components/focus-control/index.jsx
|
|
10
|
+
const FocusControlContext = (0, _wordpress_element.createContext)();
|
|
30
11
|
FocusControlContext.displayName = "FocusControlContext";
|
|
31
12
|
function FocusControl({ api, sidebarControls, children }) {
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
handleFocus
|
|
63
|
-
);
|
|
64
|
-
previewBound = true;
|
|
65
|
-
}
|
|
66
|
-
api.previewer.bind("ready", handleReady);
|
|
67
|
-
return () => {
|
|
68
|
-
api.previewer.unbind("ready", handleReady);
|
|
69
|
-
if (previewBound) {
|
|
70
|
-
api.previewer.preview.unbind(
|
|
71
|
-
"focus-control-for-setting",
|
|
72
|
-
handleFocus
|
|
73
|
-
);
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
}, [api, focusWidget]);
|
|
77
|
-
const context = (0, import_element.useMemo)(
|
|
78
|
-
() => [focusedWidgetIdRef, focusWidget],
|
|
79
|
-
[focusedWidgetIdRef, focusWidget]
|
|
80
|
-
);
|
|
81
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FocusControlContext.Provider, { value: context, children });
|
|
13
|
+
const [focusedWidgetIdRef, setFocusedWidgetIdRef] = (0, _wordpress_element.useState)({ current: null });
|
|
14
|
+
const focusWidget = (0, _wordpress_element.useCallback)((widgetId) => {
|
|
15
|
+
for (const sidebarControl of sidebarControls) if (sidebarControl.setting.get().includes(widgetId)) {
|
|
16
|
+
sidebarControl.sectionInstance.expand({ completeCallback() {
|
|
17
|
+
setFocusedWidgetIdRef({ current: widgetId });
|
|
18
|
+
} });
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
}, [sidebarControls]);
|
|
22
|
+
(0, _wordpress_element.useEffect)(() => {
|
|
23
|
+
function handleFocus(settingId) {
|
|
24
|
+
const widgetId = (0, ______utils_js.settingIdToWidgetId)(settingId);
|
|
25
|
+
focusWidget(widgetId);
|
|
26
|
+
}
|
|
27
|
+
let previewBound = false;
|
|
28
|
+
function handleReady() {
|
|
29
|
+
api.previewer.preview.bind("focus-control-for-setting", handleFocus);
|
|
30
|
+
previewBound = true;
|
|
31
|
+
}
|
|
32
|
+
api.previewer.bind("ready", handleReady);
|
|
33
|
+
return () => {
|
|
34
|
+
api.previewer.unbind("ready", handleReady);
|
|
35
|
+
if (previewBound) api.previewer.preview.unbind("focus-control-for-setting", handleFocus);
|
|
36
|
+
};
|
|
37
|
+
}, [api, focusWidget]);
|
|
38
|
+
const context = (0, _wordpress_element.useMemo)(() => [focusedWidgetIdRef, focusWidget], [focusedWidgetIdRef, focusWidget]);
|
|
39
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(FocusControlContext.Provider, {
|
|
40
|
+
value: context,
|
|
41
|
+
children
|
|
42
|
+
});
|
|
82
43
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
//# sourceMappingURL=index.cjs.map
|
|
44
|
+
const useFocusControl = () => (0, _wordpress_element.useContext)(FocusControlContext);
|
|
45
|
+
exports.default = FocusControl;
|
|
46
|
+
exports.useFocusControl = useFocusControl;
|
|
47
|
+
|
|
48
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/focus-control/index.jsx"],
|
|
4
|
-
"sourcesContent": ["import {\n\tcreateContext,\n\tuseState,\n\tuseEffect,\n\tuseContext,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { settingIdToWidgetId } from '../../utils';\n\nconst FocusControlContext = createContext();\nFocusControlContext.displayName = 'FocusControlContext';\n\nexport default function FocusControl( { api, sidebarControls, children } ) {\n\tconst [ focusedWidgetIdRef, setFocusedWidgetIdRef ] = useState( {\n\t\tcurrent: null,\n\t} );\n\n\tconst focusWidget = useCallback(\n\t\t( widgetId ) => {\n\t\t\tfor ( const sidebarControl of sidebarControls ) {\n\t\t\t\tconst widgets = sidebarControl.setting.get();\n\n\t\t\t\tif ( widgets.includes( widgetId ) ) {\n\t\t\t\t\tsidebarControl.sectionInstance.expand( {\n\t\t\t\t\t\t// Schedule it after the complete callback so that\n\t\t\t\t\t\t// it won't be overridden by the \"Back\" button focus.\n\t\t\t\t\t\tcompleteCallback() {\n\t\t\t\t\t\t\t// Create a \"ref-like\" object every time to ensure\n\t\t\t\t\t\t\t// the same widget id can also triggers the focus control.\n\t\t\t\t\t\t\tsetFocusedWidgetIdRef( { current: widgetId } );\n\t\t\t\t\t\t},\n\t\t\t\t\t} );\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[ sidebarControls ]\n\t);\n\n\tuseEffect( () => {\n\t\tfunction handleFocus( settingId ) {\n\t\t\tconst widgetId = settingIdToWidgetId( settingId );\n\n\t\t\tfocusWidget( widgetId );\n\t\t}\n\n\t\tlet previewBound = false;\n\n\t\tfunction handleReady() {\n\t\t\tapi.previewer.preview.bind(\n\t\t\t\t'focus-control-for-setting',\n\t\t\t\thandleFocus\n\t\t\t);\n\t\t\tpreviewBound = true;\n\t\t}\n\n\t\tapi.previewer.bind( 'ready', handleReady );\n\n\t\treturn () => {\n\t\t\tapi.previewer.unbind( 'ready', handleReady );\n\t\t\tif ( previewBound ) {\n\t\t\t\tapi.previewer.preview.unbind(\n\t\t\t\t\t'focus-control-for-setting',\n\t\t\t\t\thandleFocus\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t}, [ api, focusWidget ] );\n\n\tconst context = useMemo(\n\t\t() => [ focusedWidgetIdRef, focusWidget ],\n\t\t[ focusedWidgetIdRef, focusWidget ]\n\t);\n\n\treturn (\n\t\t<FocusControlContext.Provider value={ context }>\n\t\t\t{ children }\n\t\t</FocusControlContext.Provider>\n\t);\n}\n\nexport const useFocusControl = () => useContext( FocusControlContext );\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAOO;AACP,mBAAoC;AAqElC;AAnEF,IAAM,0BAAsB,8BAAc;AAC1C,oBAAoB,cAAc;AAEnB,SAAR,aAA+B,EAAE,KAAK,iBAAiB,SAAS,GAAI;AAC1E,QAAM,CAAE,oBAAoB,qBAAsB,QAAI,yBAAU;AAAA,IAC/D,SAAS;AAAA,EACV,CAAE;AAEF,QAAM,kBAAc;AAAA,IACnB,CAAE,aAAc;AACf,iBAAY,kBAAkB,iBAAkB;AAC/C,cAAM,UAAU,eAAe,QAAQ,IAAI;AAE3C,YAAK,QAAQ,SAAU,QAAS,GAAI;AACnC,yBAAe,gBAAgB,OAAQ;AAAA;AAAA;AAAA,YAGtC,mBAAmB;AAGlB,oCAAuB,EAAE,SAAS,SAAS,CAAE;AAAA,YAC9C;AAAA,UACD,CAAE;AAEF;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,IACA,CAAE,eAAgB;AAAA,EACnB;AAEA,gCAAW,MAAM;AAChB,aAAS,YAAa,WAAY;AACjC,YAAM,eAAW,kCAAqB,SAAU;AAEhD,kBAAa,QAAS;AAAA,IACvB;AAEA,QAAI,eAAe;AAEnB,aAAS,cAAc;AACtB,UAAI,UAAU,QAAQ;AAAA,QACrB;AAAA,QACA;AAAA,MACD;AACA,qBAAe;AAAA,IAChB;AAEA,QAAI,UAAU,KAAM,SAAS,WAAY;AAEzC,WAAO,MAAM;AACZ,UAAI,UAAU,OAAQ,SAAS,WAAY;AAC3C,UAAK,cAAe;AACnB,YAAI,UAAU,QAAQ;AAAA,UACrB;AAAA,UACA;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAAA,EACD,GAAG,CAAE,KAAK,WAAY,CAAE;AAExB,QAAM,cAAU;AAAA,IACf,MAAM,CAAE,oBAAoB,WAAY;AAAA,IACxC,CAAE,oBAAoB,WAAY;AAAA,EACnC;AAEA,SACC,4CAAC,oBAAoB,UAApB,EAA6B,OAAQ,SACnC,UACH;AAEF;AAEO,IAAM,kBAAkB,UAAM,2BAAY,mBAAoB;",
|
|
6
|
-
"names": []
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["createContext","useState","useCallback","settingIdToWidgetId","useMemo","useContext"],"sources":["../../../src/components/focus-control/index.jsx"],"sourcesContent":["import {\n\tcreateContext,\n\tuseState,\n\tuseEffect,\n\tuseContext,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\nimport { settingIdToWidgetId } from '../../utils';\n\nconst FocusControlContext = createContext();\nFocusControlContext.displayName = 'FocusControlContext';\n\nexport default function FocusControl( { api, sidebarControls, children } ) {\n\tconst [ focusedWidgetIdRef, setFocusedWidgetIdRef ] = useState( {\n\t\tcurrent: null,\n\t} );\n\n\tconst focusWidget = useCallback(\n\t\t( widgetId ) => {\n\t\t\tfor ( const sidebarControl of sidebarControls ) {\n\t\t\t\tconst widgets = sidebarControl.setting.get();\n\n\t\t\t\tif ( widgets.includes( widgetId ) ) {\n\t\t\t\t\tsidebarControl.sectionInstance.expand( {\n\t\t\t\t\t\t// Schedule it after the complete callback so that\n\t\t\t\t\t\t// it won't be overridden by the \"Back\" button focus.\n\t\t\t\t\t\tcompleteCallback() {\n\t\t\t\t\t\t\t// Create a \"ref-like\" object every time to ensure\n\t\t\t\t\t\t\t// the same widget id can also triggers the focus control.\n\t\t\t\t\t\t\tsetFocusedWidgetIdRef( { current: widgetId } );\n\t\t\t\t\t\t},\n\t\t\t\t\t} );\n\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\t[ sidebarControls ]\n\t);\n\n\tuseEffect( () => {\n\t\tfunction handleFocus( settingId ) {\n\t\t\tconst widgetId = settingIdToWidgetId( settingId );\n\n\t\t\tfocusWidget( widgetId );\n\t\t}\n\n\t\tlet previewBound = false;\n\n\t\tfunction handleReady() {\n\t\t\tapi.previewer.preview.bind(\n\t\t\t\t'focus-control-for-setting',\n\t\t\t\thandleFocus\n\t\t\t);\n\t\t\tpreviewBound = true;\n\t\t}\n\n\t\tapi.previewer.bind( 'ready', handleReady );\n\n\t\treturn () => {\n\t\t\tapi.previewer.unbind( 'ready', handleReady );\n\t\t\tif ( previewBound ) {\n\t\t\t\tapi.previewer.preview.unbind(\n\t\t\t\t\t'focus-control-for-setting',\n\t\t\t\t\thandleFocus\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t}, [ api, focusWidget ] );\n\n\tconst context = useMemo(\n\t\t() => [ focusedWidgetIdRef, focusWidget ],\n\t\t[ focusedWidgetIdRef, focusWidget ]\n\t);\n\n\treturn (\n\t\t<FocusControlContext.Provider value={ context }>\n\t\t\t{ children }\n\t\t</FocusControlContext.Provider>\n\t);\n}\n\nexport const useFocusControl = () => useContext( FocusControlContext );\n"],"mappings":";;;;;;;;;AAUA,MAAM,uBAAA,GAAsBA,mBAAAA,cAAAA,CAAc;AAC1C,oBAAoB,cAAc;AAElC,SAAwB,aAAc,EAAE,KAAK,iBAAiB,YAAa;CAC1E,MAAM,CAAE,oBAAoB,0BAAA,GAA0BC,mBAAAA,SAAAA,CAAU,EAC/D,SAAS,KACV,CAAE;CAEF,MAAM,eAAA,GAAcC,mBAAAA,YAAAA,EACjB,aAAc;EACf,KAAM,MAAM,kBAAkB,iBAG7B,IAFgB,eAAe,QAAQ,IAE5B,CAAC,CAAC,SAAU,QAAS,GAAI;GACnC,eAAe,gBAAgB,OAAQ,EAGtC,mBAAmB;IAGlB,sBAAuB,EAAE,SAAS,SAAS,CAAE;GAC9C,EACD,CAAE;GAEF;EACD;CAEF,GACA,CAAE,eAAgB,CACnB;CAEA,CAAA,GAAA,mBAAA,UAAA,OAAiB;EAChB,SAAS,YAAa,WAAY;GACjC,MAAM,YAAA,GAAWC,eAAAA,oBAAAA,CAAqB,SAAU;GAEhD,YAAa,QAAS;EACvB;EAEA,IAAI,eAAe;EAEnB,SAAS,cAAc;GACtB,IAAI,UAAU,QAAQ,KACrB,6BACA,WACD;GACA,eAAe;EAChB;EAEA,IAAI,UAAU,KAAM,SAAS,WAAY;EAEzC,aAAa;GACZ,IAAI,UAAU,OAAQ,SAAS,WAAY;GAC3C,IAAK,cACJ,IAAI,UAAU,QAAQ,OACrB,6BACA,WACD;EAEF;CACD,GAAG,CAAE,KAAK,WAAY,CAAE;CAExB,MAAM,WAAA,GAAUC,mBAAAA,QAAAA,OACT,CAAE,oBAAoB,WAAY,GACxC,CAAE,oBAAoB,WAAY,CACnC;CAEA,OACC,iBAAA,GAAA,kBAAA,IAAA,CAAC,oBAAoB,UAArB;EAA8B,OAAQ;EACnC;CAC2B,CAAA;AAEhC;AAEA,MAAa,yBAAA,GAAwBC,mBAAAA,WAAAA,CAAY,mBAAoB"}
|
|
@@ -1,52 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
-
|
|
19
|
-
// packages/customize-widgets/src/components/focus-control/use-blocks-focus-control.js
|
|
20
|
-
var use_blocks_focus_control_exports = {};
|
|
21
|
-
__export(use_blocks_focus_control_exports, {
|
|
22
|
-
default: () => useBlocksFocusControl
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, {
|
|
3
|
+
__esModule: { value: true },
|
|
4
|
+
[Symbol.toStringTag]: { value: "Module" }
|
|
23
5
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
6
|
+
let _wordpress_element = require("@wordpress/element");
|
|
7
|
+
let _wordpress_data = require("@wordpress/data");
|
|
8
|
+
let _wordpress_block_editor = require("@wordpress/block-editor");
|
|
9
|
+
let _wordpress_widgets = require("@wordpress/widgets");
|
|
10
|
+
let __index_jsx = require("./index.cjs");
|
|
11
|
+
// packages/customize-widgets/src/components/focus-control/use-blocks-focus-control.js
|
|
30
12
|
function useBlocksFocusControl(blocks) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
);
|
|
47
|
-
blockNode?.focus();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}, [focusedWidgetIdRef, selectBlock]);
|
|
13
|
+
const { selectBlock } = (0, _wordpress_data.useDispatch)(_wordpress_block_editor.store);
|
|
14
|
+
const [focusedWidgetIdRef] = (0, __index_jsx.useFocusControl)();
|
|
15
|
+
const blocksRef = (0, _wordpress_element.useRef)(blocks);
|
|
16
|
+
(0, _wordpress_element.useEffect)(() => {
|
|
17
|
+
blocksRef.current = blocks;
|
|
18
|
+
}, [blocks]);
|
|
19
|
+
(0, _wordpress_element.useEffect)(() => {
|
|
20
|
+
if (focusedWidgetIdRef.current) {
|
|
21
|
+
const focusedBlock = blocksRef.current.find((block) => (0, _wordpress_widgets.getWidgetIdFromBlock)(block) === focusedWidgetIdRef.current);
|
|
22
|
+
if (focusedBlock) {
|
|
23
|
+
selectBlock(focusedBlock.clientId);
|
|
24
|
+
document.querySelector(`[data-block="${focusedBlock.clientId}"]`)?.focus();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}, [focusedWidgetIdRef, selectBlock]);
|
|
51
28
|
}
|
|
52
|
-
|
|
29
|
+
exports.default = useBlocksFocusControl;
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=use-blocks-focus-control.cjs.map
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/components/focus-control/use-blocks-focus-control.js"],
|
|
4
|
-
"sourcesContent": ["import { useRef, useEffect } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { getWidgetIdFromBlock } from '@wordpress/widgets';\nimport { useFocusControl } from '.';\n\nexport default function useBlocksFocusControl( blocks ) {\n\tconst { selectBlock } = useDispatch( blockEditorStore );\n\tconst [ focusedWidgetIdRef ] = useFocusControl();\n\n\tconst blocksRef = useRef( blocks );\n\n\tuseEffect( () => {\n\t\tblocksRef.current = blocks;\n\t}, [ blocks ] );\n\n\tuseEffect( () => {\n\t\tif ( focusedWidgetIdRef.current ) {\n\t\t\tconst focusedBlock = blocksRef.current.find(\n\t\t\t\t( block ) =>\n\t\t\t\t\tgetWidgetIdFromBlock( block ) === focusedWidgetIdRef.current\n\t\t\t);\n\n\t\t\tif ( focusedBlock ) {\n\t\t\t\tselectBlock( focusedBlock.clientId );\n\t\t\t\t// If the block is already being selected, the DOM node won't\n\t\t\t\t// get focused again automatically.\n\t\t\t\t// We select the DOM and focus it manually here.\n\t\t\t\tconst blockNode = document.querySelector(\n\t\t\t\t\t`[data-block=\"${ focusedBlock.clientId }\"]`\n\t\t\t\t);\n\t\t\t\tblockNode?.focus();\n\t\t\t}\n\t\t}\n\t}, [ focusedWidgetIdRef, selectBlock ] );\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAkC;AAClC,kBAA4B;AAC5B,0BAA0C;AAC1C,qBAAqC;AACrC,eAAgC;AAEjB,SAAR,sBAAwC,QAAS;AACvD,QAAM,EAAE,YAAY,QAAI,yBAAa,oBAAAA,KAAiB;AACtD,QAAM,CAAE,kBAAmB,QAAI,0BAAgB;AAE/C,QAAM,gBAAY,uBAAQ,MAAO;AAEjC,gCAAW,MAAM;AAChB,cAAU,UAAU;AAAA,EACrB,GAAG,CAAE,MAAO,CAAE;AAEd,gCAAW,MAAM;AAChB,QAAK,mBAAmB,SAAU;AACjC,YAAM,eAAe,UAAU,QAAQ;AAAA,QACtC,CAAE,cACD,qCAAsB,KAAM,MAAM,mBAAmB;AAAA,MACvD;AAEA,UAAK,cAAe;AACnB,oBAAa,aAAa,QAAS;AAInC,cAAM,YAAY,SAAS;AAAA,UAC1B,gBAAiB,aAAa,QAAS;AAAA,QACxC;AACA,mBAAW,MAAM;AAAA,MAClB;AAAA,IACD;AAAA,EACD,GAAG,CAAE,oBAAoB,WAAY,CAAE;AACxC;",
|
|
6
|
-
"names": ["blockEditorStore"]
|
|
7
|
-
}
|
|
1
|
+
{"version":3,"file":"use-blocks-focus-control.cjs","names":["useDispatch","blockEditorStore","useFocusControl","useRef","getWidgetIdFromBlock"],"sources":["../../../src/components/focus-control/use-blocks-focus-control.js"],"sourcesContent":["import { useRef, useEffect } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { getWidgetIdFromBlock } from '@wordpress/widgets';\nimport { useFocusControl } from '.';\n\nexport default function useBlocksFocusControl( blocks ) {\n\tconst { selectBlock } = useDispatch( blockEditorStore );\n\tconst [ focusedWidgetIdRef ] = useFocusControl();\n\n\tconst blocksRef = useRef( blocks );\n\n\tuseEffect( () => {\n\t\tblocksRef.current = blocks;\n\t}, [ blocks ] );\n\n\tuseEffect( () => {\n\t\tif ( focusedWidgetIdRef.current ) {\n\t\t\tconst focusedBlock = blocksRef.current.find(\n\t\t\t\t( block ) =>\n\t\t\t\t\tgetWidgetIdFromBlock( block ) === focusedWidgetIdRef.current\n\t\t\t);\n\n\t\t\tif ( focusedBlock ) {\n\t\t\t\tselectBlock( focusedBlock.clientId );\n\t\t\t\t// If the block is already being selected, the DOM node won't\n\t\t\t\t// get focused again automatically.\n\t\t\t\t// We select the DOM and focus it manually here.\n\t\t\t\tconst blockNode = document.querySelector(\n\t\t\t\t\t`[data-block=\"${ focusedBlock.clientId }\"]`\n\t\t\t\t);\n\t\t\t\tblockNode?.focus();\n\t\t\t}\n\t\t}\n\t}, [ focusedWidgetIdRef, selectBlock ] );\n}\n"],"mappings":";;;;;;;;;;;AAMA,SAAwB,sBAAuB,QAAS;CACvD,MAAM,EAAE,iBAAA,GAAgBA,gBAAAA,YAAAA,CAAaC,wBAAAA,KAAiB;CACtD,MAAM,CAAE,uBAAA,GAAuBC,YAAAA,gBAAAA,CAAgB;CAE/C,MAAM,aAAA,GAAYC,mBAAAA,OAAAA,CAAQ,MAAO;CAEjC,CAAA,GAAA,mBAAA,UAAA,OAAiB;EAChB,UAAU,UAAU;CACrB,GAAG,CAAE,MAAO,CAAE;CAEd,CAAA,GAAA,mBAAA,UAAA,OAAiB;EAChB,IAAK,mBAAmB,SAAU;GACjC,MAAM,eAAe,UAAU,QAAQ,MACpC,WAAA,GACDC,mBAAAA,qBAAAA,CAAsB,KAAM,MAAM,mBAAmB,OACvD;GAEA,IAAK,cAAe;IACnB,YAAa,aAAa,QAAS;IAOnC,SAH2B,cAC1B,gBAAiB,aAAa,SAAU,GAEjC,CAAC,EAAE,MAAM;GAClB;EACD;CACD,GAAG,CAAE,oBAAoB,WAAY,CAAE;AACxC"}
|