@wordpress/customize-widgets 4.15.0 → 4.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/build/components/block-appender/index.js +6 -8
- package/build/components/block-appender/index.js.map +1 -1
- package/build/components/block-inspector-button/index.js +3 -9
- package/build/components/block-inspector-button/index.js.map +1 -1
- package/build/components/customize-widgets/index.js +4 -12
- package/build/components/customize-widgets/index.js.map +1 -1
- package/build/components/customize-widgets/use-clear-selected-block.js +12 -15
- package/build/components/customize-widgets/use-clear-selected-block.js.map +1 -1
- package/build/components/error-boundary/index.js +1 -14
- package/build/components/error-boundary/index.js.map +1 -1
- package/build/components/focus-control/index.js +1 -12
- package/build/components/focus-control/index.js.map +1 -1
- package/build/components/focus-control/use-blocks-focus-control.js +3 -9
- package/build/components/focus-control/use-blocks-focus-control.js.map +1 -1
- package/build/components/header/index.js +7 -18
- package/build/components/header/index.js.map +1 -1
- package/build/components/inserter/index.js +1 -10
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inserter/use-inserter.js +1 -6
- package/build/components/inserter/use-inserter.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/config.js +1 -2
- package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +1 -9
- package/build/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/index.js +4 -20
- package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build/components/keyboard-shortcut-help-modal/shortcut.js +1 -6
- package/build/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build/components/keyboard-shortcuts/index.js +1 -16
- package/build/components/keyboard-shortcuts/index.js.map +1 -1
- package/build/components/more-menu/index.js +2 -15
- package/build/components/more-menu/index.js.map +1 -1
- package/build/components/sidebar-block-editor/index.js +5 -22
- package/build/components/sidebar-block-editor/index.js.map +1 -1
- package/build/components/sidebar-block-editor/sidebar-adapter.js +13 -75
- package/build/components/sidebar-block-editor/sidebar-adapter.js.map +1 -1
- package/build/components/sidebar-block-editor/sidebar-editor-provider.js +1 -8
- package/build/components/sidebar-block-editor/sidebar-editor-provider.js.map +1 -1
- package/build/components/sidebar-block-editor/use-sidebar-block-editor.js +14 -24
- package/build/components/sidebar-block-editor/use-sidebar-block-editor.js.map +1 -1
- package/build/components/sidebar-controls/index.js +1 -5
- package/build/components/sidebar-controls/index.js.map +1 -1
- package/build/components/welcome-guide/index.js +1 -6
- package/build/components/welcome-guide/index.js.map +1 -1
- package/build/controls/inserter-outer-section.js +15 -24
- package/build/controls/inserter-outer-section.js.map +1 -1
- package/build/controls/inspector-section.js +0 -12
- package/build/controls/inspector-section.js.map +1 -1
- package/build/controls/sidebar-control.js +1 -12
- package/build/controls/sidebar-control.js.map +1 -1
- package/build/controls/sidebar-section.js +3 -14
- package/build/controls/sidebar-section.js.map +1 -1
- package/build/filters/index.js +0 -2
- package/build/filters/index.js.map +1 -1
- package/build/filters/move-to-sidebar.js +7 -17
- package/build/filters/move-to-sidebar.js.map +1 -1
- package/build/filters/replace-media-upload.js +1 -3
- package/build/filters/replace-media-upload.js.map +1 -1
- package/build/filters/wide-widget-display.js +3 -5
- package/build/filters/wide-widget-display.js.map +1 -1
- package/build/index.js +5 -20
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +1 -2
- package/build/lock-unlock.js.map +1 -1
- package/build/store/actions.js +0 -1
- package/build/store/actions.js.map +1 -1
- package/build/store/constants.js +0 -1
- package/build/store/constants.js.map +1 -1
- package/build/store/index.js +1 -10
- package/build/store/index.js.map +1 -1
- package/build/store/reducer.js +0 -5
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +9 -10
- package/build/store/selectors.js.map +1 -1
- package/build/utils.js +8 -18
- package/build/utils.js.map +1 -1
- package/build-module/components/block-appender/index.js +5 -5
- package/build-module/components/block-appender/index.js.map +1 -1
- package/build-module/components/block-inspector-button/index.js +2 -5
- package/build-module/components/block-inspector-button/index.js.map +1 -1
- package/build-module/components/customize-widgets/index.js +4 -4
- package/build-module/components/customize-widgets/index.js.map +1 -1
- package/build-module/components/customize-widgets/use-clear-selected-block.js +13 -12
- package/build-module/components/customize-widgets/use-clear-selected-block.js.map +1 -1
- package/build-module/components/error-boundary/index.js +0 -8
- package/build-module/components/error-boundary/index.js.map +1 -1
- package/build-module/components/focus-control/index.js +1 -8
- package/build-module/components/focus-control/index.js.map +1 -1
- package/build-module/components/focus-control/use-blocks-focus-control.js +3 -4
- package/build-module/components/focus-control/use-blocks-focus-control.js.map +1 -1
- package/build-module/components/header/index.js +8 -11
- package/build-module/components/header/index.js.map +1 -1
- package/build-module/components/inserter/index.js +1 -4
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inserter/use-inserter.js +1 -3
- package/build-module/components/inserter/use-inserter.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js +1 -6
- package/build-module/components/keyboard-shortcut-help-modal/dynamic-shortcut.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/index.js +5 -13
- package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js +0 -5
- package/build-module/components/keyboard-shortcut-help-modal/shortcut.js.map +1 -1
- package/build-module/components/keyboard-shortcuts/index.js +0 -9
- package/build-module/components/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/components/more-menu/index.js +2 -6
- package/build-module/components/more-menu/index.js.map +1 -1
- package/build-module/components/sidebar-block-editor/index.js +5 -9
- package/build-module/components/sidebar-block-editor/index.js.map +1 -1
- package/build-module/components/sidebar-block-editor/sidebar-adapter.js +12 -72
- package/build-module/components/sidebar-block-editor/sidebar-adapter.js.map +1 -1
- package/build-module/components/sidebar-block-editor/sidebar-editor-provider.js +1 -2
- package/build-module/components/sidebar-block-editor/sidebar-editor-provider.js.map +1 -1
- package/build-module/components/sidebar-block-editor/use-sidebar-block-editor.js +15 -20
- package/build-module/components/sidebar-block-editor/use-sidebar-block-editor.js.map +1 -1
- package/build-module/components/sidebar-controls/index.js +0 -1
- package/build-module/components/sidebar-controls/index.js.map +1 -1
- package/build-module/components/welcome-guide/index.js +0 -1
- package/build-module/components/welcome-guide/index.js.map +1 -1
- package/build-module/controls/inserter-outer-section.js +15 -20
- package/build-module/controls/inserter-outer-section.js.map +1 -1
- package/build-module/controls/inspector-section.js +0 -11
- package/build-module/controls/inspector-section.js.map +1 -1
- package/build-module/controls/sidebar-control.js +1 -8
- package/build-module/controls/sidebar-control.js.map +1 -1
- package/build-module/controls/sidebar-section.js +3 -12
- package/build-module/controls/sidebar-section.js.map +1 -1
- package/build-module/filters/index.js.map +1 -1
- package/build-module/filters/move-to-sidebar.js +7 -10
- package/build-module/filters/move-to-sidebar.js.map +1 -1
- package/build-module/filters/replace-media-upload.js +0 -2
- package/build-module/filters/replace-media-upload.js.map +1 -1
- package/build-module/filters/wide-widget-display.js +2 -3
- package/build-module/filters/wide-widget-display.js.map +1 -1
- package/build-module/index.js +5 -10
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/constants.js.map +1 -1
- package/build-module/store/index.js +3 -3
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/reducer.js +1 -3
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +10 -9
- package/build-module/store/selectors.js.map +1 -1
- package/build-module/utils.js +9 -14
- package/build-module/utils.js.map +1 -1
- package/package.json +22 -22
- package/src/store/selectors.js +10 -2
package/build/utils.js
CHANGED
|
@@ -6,13 +6,9 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.blockToWidget = blockToWidget;
|
|
7
7
|
exports.settingIdToWidgetId = settingIdToWidgetId;
|
|
8
8
|
exports.widgetToBlock = widgetToBlock;
|
|
9
|
-
|
|
10
9
|
var _blocks = require("@wordpress/blocks");
|
|
11
|
-
|
|
12
10
|
var _widgets = require("@wordpress/widgets");
|
|
13
|
-
|
|
14
11
|
// @ts-check
|
|
15
|
-
|
|
16
12
|
/**
|
|
17
13
|
* WordPress dependencies
|
|
18
14
|
*/
|
|
@@ -25,15 +21,14 @@ var _widgets = require("@wordpress/widgets");
|
|
|
25
21
|
*/
|
|
26
22
|
function settingIdToWidgetId(settingId) {
|
|
27
23
|
const matches = settingId.match(/^widget_(.+)(?:\[(\d+)\])$/);
|
|
28
|
-
|
|
29
24
|
if (matches) {
|
|
30
25
|
const idBase = matches[1];
|
|
31
26
|
const number = parseInt(matches[2], 10);
|
|
32
27
|
return `${idBase}-${number}`;
|
|
33
28
|
}
|
|
34
|
-
|
|
35
29
|
return settingId;
|
|
36
30
|
}
|
|
31
|
+
|
|
37
32
|
/**
|
|
38
33
|
* Transform a block to a customizable widget.
|
|
39
34
|
*
|
|
@@ -41,12 +36,9 @@ function settingIdToWidgetId(settingId) {
|
|
|
41
36
|
* @param {Object} existingWidget The widget to be extended from.
|
|
42
37
|
* @return {Object} The transformed widget.
|
|
43
38
|
*/
|
|
44
|
-
|
|
45
|
-
|
|
46
39
|
function blockToWidget(block, existingWidget = null) {
|
|
47
40
|
let widget;
|
|
48
41
|
const isValidLegacyWidgetBlock = block.name === 'core/legacy-widget' && (block.attributes.id || block.attributes.instance);
|
|
49
|
-
|
|
50
42
|
if (isValidLegacyWidgetBlock) {
|
|
51
43
|
if (block.attributes.id) {
|
|
52
44
|
// Widget that does not extend WP_Widget.
|
|
@@ -59,11 +51,13 @@ function blockToWidget(block, existingWidget = null) {
|
|
|
59
51
|
hash,
|
|
60
52
|
raw,
|
|
61
53
|
...rest
|
|
62
|
-
} = block.attributes.instance;
|
|
54
|
+
} = block.attributes.instance;
|
|
63
55
|
|
|
56
|
+
// Widget that extends WP_Widget.
|
|
64
57
|
widget = {
|
|
65
58
|
idBase: block.attributes.idBase,
|
|
66
|
-
instance: {
|
|
59
|
+
instance: {
|
|
60
|
+
...existingWidget?.instance,
|
|
67
61
|
// Required only for the customizer.
|
|
68
62
|
is_widget_customizer_js_value: true,
|
|
69
63
|
encoded_serialized_instance: encoded,
|
|
@@ -85,16 +79,17 @@ function blockToWidget(block, existingWidget = null) {
|
|
|
85
79
|
}
|
|
86
80
|
};
|
|
87
81
|
}
|
|
88
|
-
|
|
89
82
|
const {
|
|
90
83
|
form,
|
|
91
84
|
rendered,
|
|
92
85
|
...restExistingWidget
|
|
93
86
|
} = existingWidget || {};
|
|
94
|
-
return {
|
|
87
|
+
return {
|
|
88
|
+
...restExistingWidget,
|
|
95
89
|
...widget
|
|
96
90
|
};
|
|
97
91
|
}
|
|
92
|
+
|
|
98
93
|
/**
|
|
99
94
|
* Transform a widget to a block.
|
|
100
95
|
*
|
|
@@ -105,8 +100,6 @@ function blockToWidget(block, existingWidget = null) {
|
|
|
105
100
|
* @param {Object} widget.instance The instance of the widget.
|
|
106
101
|
* @return {WPBlock} The transformed block.
|
|
107
102
|
*/
|
|
108
|
-
|
|
109
|
-
|
|
110
103
|
function widgetToBlock({
|
|
111
104
|
id,
|
|
112
105
|
idBase,
|
|
@@ -120,10 +113,8 @@ function widgetToBlock({
|
|
|
120
113
|
raw_instance: raw,
|
|
121
114
|
...rest
|
|
122
115
|
} = instance;
|
|
123
|
-
|
|
124
116
|
if (idBase === 'block') {
|
|
125
117
|
var _raw$content;
|
|
126
|
-
|
|
127
118
|
const parsedBlocks = (0, _blocks.parse)((_raw$content = raw.content) !== null && _raw$content !== void 0 ? _raw$content : '', {
|
|
128
119
|
__unstableSkipAutop: true
|
|
129
120
|
});
|
|
@@ -145,7 +136,6 @@ function widgetToBlock({
|
|
|
145
136
|
id
|
|
146
137
|
});
|
|
147
138
|
}
|
|
148
|
-
|
|
149
139
|
return (0, _widgets.addWidgetIdToBlock)(block, id);
|
|
150
140
|
}
|
|
151
141
|
//# sourceMappingURL=utils.js.map
|
package/build/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_blocks","require","_widgets","settingIdToWidgetId","settingId","matches","match","idBase","number","parseInt","blockToWidget","block","existingWidget","widget","isValidLegacyWidgetBlock","name","attributes","id","instance","encoded","hash","raw","rest","is_widget_customizer_js_value","encoded_serialized_instance","instance_hash_key","raw_instance","content","serialize","widgetClass","form","rendered","restExistingWidget","widgetToBlock","_raw$content","parsedBlocks","parse","__unstableSkipAutop","length","createBlock","addWidgetIdToBlock"],"sources":["@wordpress/customize-widgets/src/utils.js"],"sourcesContent":["// @ts-check\n/**\n * WordPress dependencies\n */\nimport { serialize, parse, createBlock } from '@wordpress/blocks';\nimport { addWidgetIdToBlock } from '@wordpress/widgets';\n\n/**\n * Convert settingId to widgetId.\n *\n * @param {string} settingId The setting id.\n * @return {string} The widget id.\n */\nexport function settingIdToWidgetId( settingId ) {\n\tconst matches = settingId.match( /^widget_(.+)(?:\\[(\\d+)\\])$/ );\n\n\tif ( matches ) {\n\t\tconst idBase = matches[ 1 ];\n\t\tconst number = parseInt( matches[ 2 ], 10 );\n\n\t\treturn `${ idBase }-${ number }`;\n\t}\n\n\treturn settingId;\n}\n\n/**\n * Transform a block to a customizable widget.\n *\n * @param {WPBlock} block The block to be transformed from.\n * @param {Object} existingWidget The widget to be extended from.\n * @return {Object} The transformed widget.\n */\nexport function blockToWidget( block, existingWidget = null ) {\n\tlet widget;\n\n\tconst isValidLegacyWidgetBlock =\n\t\tblock.name === 'core/legacy-widget' &&\n\t\t( block.attributes.id || block.attributes.instance );\n\n\tif ( isValidLegacyWidgetBlock ) {\n\t\tif ( block.attributes.id ) {\n\t\t\t// Widget that does not extend WP_Widget.\n\t\t\twidget = {\n\t\t\t\tid: block.attributes.id,\n\t\t\t};\n\t\t} else {\n\t\t\tconst { encoded, hash, raw, ...rest } = block.attributes.instance;\n\n\t\t\t// Widget that extends WP_Widget.\n\t\t\twidget = {\n\t\t\t\tidBase: block.attributes.idBase,\n\t\t\t\tinstance: {\n\t\t\t\t\t...existingWidget?.instance,\n\t\t\t\t\t// Required only for the customizer.\n\t\t\t\t\tis_widget_customizer_js_value: true,\n\t\t\t\t\tencoded_serialized_instance: encoded,\n\t\t\t\t\tinstance_hash_key: hash,\n\t\t\t\t\traw_instance: raw,\n\t\t\t\t\t...rest,\n\t\t\t\t},\n\t\t\t};\n\t\t}\n\t} else {\n\t\tconst instance = {\n\t\t\tcontent: serialize( block ),\n\t\t};\n\t\twidget = {\n\t\t\tidBase: 'block',\n\t\t\twidgetClass: 'WP_Widget_Block',\n\t\t\tinstance: {\n\t\t\t\traw_instance: instance,\n\t\t\t},\n\t\t};\n\t}\n\n\tconst { form, rendered, ...restExistingWidget } = existingWidget || {};\n\n\treturn {\n\t\t...restExistingWidget,\n\t\t...widget,\n\t};\n}\n\n/**\n * Transform a widget to a block.\n *\n * @param {Object} widget The widget to be transformed from.\n * @param {string} widget.id The widget id.\n * @param {string} widget.idBase The id base of the widget.\n * @param {number} widget.number The number/index of the widget.\n * @param {Object} widget.instance The instance of the widget.\n * @return {WPBlock} The transformed block.\n */\nexport function widgetToBlock( { id, idBase, number, instance } ) {\n\tlet block;\n\n\tconst {\n\t\tencoded_serialized_instance: encoded,\n\t\tinstance_hash_key: hash,\n\t\traw_instance: raw,\n\t\t...rest\n\t} = instance;\n\n\tif ( idBase === 'block' ) {\n\t\tconst parsedBlocks = parse( raw.content ?? '', {\n\t\t\t__unstableSkipAutop: true,\n\t\t} );\n\t\tblock = parsedBlocks.length\n\t\t\t? parsedBlocks[ 0 ]\n\t\t\t: createBlock( 'core/paragraph', {} );\n\t} else if ( number ) {\n\t\t// Widget that extends WP_Widget.\n\t\tblock = createBlock( 'core/legacy-widget', {\n\t\t\tidBase,\n\t\t\tinstance: {\n\t\t\t\tencoded,\n\t\t\t\thash,\n\t\t\t\traw,\n\t\t\t\t...rest,\n\t\t\t},\n\t\t} );\n\t} else {\n\t\t// Widget that does not extend WP_Widget.\n\t\tblock = createBlock( 'core/legacy-widget', {\n\t\t\tid,\n\t\t} );\n\t}\n\n\treturn addWidgetIdToBlock( block, id );\n}\n"],"mappings":"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"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* WordPress dependencies
|
|
5
4
|
*/
|
|
@@ -8,21 +7,22 @@ import { ButtonBlockAppender, store as blockEditorStore } from '@wordpress/block
|
|
|
8
7
|
import { useSelect } from '@wordpress/data';
|
|
9
8
|
export default function BlockAppender(props) {
|
|
10
9
|
const ref = useRef();
|
|
11
|
-
const isBlocksListEmpty = useSelect(select => select(blockEditorStore).getBlockCount() === 0);
|
|
12
|
-
// being lost when emptying the widget area.
|
|
10
|
+
const isBlocksListEmpty = useSelect(select => select(blockEditorStore).getBlockCount() === 0);
|
|
13
11
|
|
|
12
|
+
// Move the focus to the block appender to prevent focus from
|
|
13
|
+
// being lost when emptying the widget area.
|
|
14
14
|
useEffect(() => {
|
|
15
15
|
if (isBlocksListEmpty && ref.current) {
|
|
16
16
|
const {
|
|
17
17
|
ownerDocument
|
|
18
18
|
} = ref.current;
|
|
19
|
-
|
|
20
19
|
if (!ownerDocument.activeElement || ownerDocument.activeElement === ownerDocument.body) {
|
|
21
20
|
ref.current.focus();
|
|
22
21
|
}
|
|
23
22
|
}
|
|
24
23
|
}, [isBlocksListEmpty]);
|
|
25
|
-
return createElement(ButtonBlockAppender, {
|
|
24
|
+
return createElement(ButtonBlockAppender, {
|
|
25
|
+
...props,
|
|
26
26
|
ref: ref
|
|
27
27
|
});
|
|
28
28
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useRef","useEffect","ButtonBlockAppender","store","blockEditorStore","useSelect","BlockAppender","props","ref","isBlocksListEmpty","select","getBlockCount","current","ownerDocument","activeElement","body","focus","createElement"],"sources":["@wordpress/customize-widgets/src/components/block-appender/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect } from '@wordpress/element';\nimport {\n\tButtonBlockAppender,\n\tstore as blockEditorStore,\n} from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\n\nexport default function BlockAppender( props ) {\n\tconst ref = useRef();\n\tconst isBlocksListEmpty = useSelect(\n\t\t( select ) => select( blockEditorStore ).getBlockCount() === 0\n\t);\n\n\t// Move the focus to the block appender to prevent focus from\n\t// being lost when emptying the widget area.\n\tuseEffect( () => {\n\t\tif ( isBlocksListEmpty && ref.current ) {\n\t\t\tconst { ownerDocument } = ref.current;\n\n\t\t\tif (\n\t\t\t\t! ownerDocument.activeElement ||\n\t\t\t\townerDocument.activeElement === ownerDocument.body\n\t\t\t) {\n\t\t\t\tref.current.focus();\n\t\t\t}\n\t\t}\n\t}, [ isBlocksListEmpty ] );\n\n\treturn <ButtonBlockAppender { ...props } ref={ ref } />;\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,MAAM,EAAEC,SAAS,QAAQ,oBAAoB;AACtD,SACCC,mBAAmB,EACnBC,KAAK,IAAIC,gBAAgB,QACnB,yBAAyB;AAChC,SAASC,SAAS,QAAQ,iBAAiB;AAE3C,eAAe,SAASC,aAAaA,CAAEC,KAAK,EAAG;EAC9C,MAAMC,GAAG,GAAGR,MAAM,CAAC,CAAC;EACpB,MAAMS,iBAAiB,GAAGJ,SAAS,CAChCK,MAAM,IAAMA,MAAM,CAAEN,gBAAiB,CAAC,CAACO,aAAa,CAAC,CAAC,KAAK,CAC9D,CAAC;;EAED;EACA;EACAV,SAAS,CAAE,MAAM;IAChB,IAAKQ,iBAAiB,IAAID,GAAG,CAACI,OAAO,EAAG;MACvC,MAAM;QAAEC;MAAc,CAAC,GAAGL,GAAG,CAACI,OAAO;MAErC,IACC,CAAEC,aAAa,CAACC,aAAa,IAC7BD,aAAa,CAACC,aAAa,KAAKD,aAAa,CAACE,IAAI,EACjD;QACDP,GAAG,CAACI,OAAO,CAACI,KAAK,CAAC,CAAC;MACpB;IACD;EACD,CAAC,EAAE,CAAEP,iBAAiB,CAAG,CAAC;EAE1B,OAAOQ,aAAA,CAACf,mBAAmB;IAAA,GAAMK,KAAK;IAAGC,GAAG,EAAGA;EAAK,CAAE,CAAC;AACxD"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* WordPress dependencies
|
|
5
4
|
*/
|
|
@@ -8,7 +7,6 @@ import { __ } from '@wordpress/i18n';
|
|
|
8
7
|
import { MenuItem } from '@wordpress/components';
|
|
9
8
|
import { useSelect } from '@wordpress/data';
|
|
10
9
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
11
|
-
|
|
12
10
|
function BlockInspectorButton({
|
|
13
11
|
inspector,
|
|
14
12
|
closeMenu,
|
|
@@ -21,13 +19,12 @@ function BlockInspectorButton({
|
|
|
21
19
|
// Open the inspector.
|
|
22
20
|
inspector.open({
|
|
23
21
|
returnFocusWhenClose: selectedBlock
|
|
24
|
-
});
|
|
25
|
-
|
|
22
|
+
});
|
|
23
|
+
// Then close the dropdown menu.
|
|
26
24
|
closeMenu();
|
|
27
25
|
},
|
|
28
26
|
...props
|
|
29
27
|
}, __('Show more settings'));
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
export default BlockInspectorButton;
|
|
33
30
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useMemo","__","MenuItem","useSelect","store","blockEditorStore","BlockInspectorButton","inspector","closeMenu","props","selectedBlockClientId","select","getSelectedBlockClientId","selectedBlock","document","getElementById","createElement","onClick","open","returnFocusWhenClose"],"sources":["@wordpress/customize-widgets/src/components/block-inspector-button/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { MenuItem } from '@wordpress/components';\nimport { useSelect } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\n\nfunction BlockInspectorButton( { inspector, closeMenu, ...props } ) {\n\tconst selectedBlockClientId = useSelect(\n\t\t( select ) => select( blockEditorStore ).getSelectedBlockClientId(),\n\t\t[]\n\t);\n\n\tconst selectedBlock = useMemo(\n\t\t() => document.getElementById( `block-${ selectedBlockClientId }` ),\n\t\t[ selectedBlockClientId ]\n\t);\n\n\treturn (\n\t\t<MenuItem\n\t\t\tonClick={ () => {\n\t\t\t\t// Open the inspector.\n\t\t\t\tinspector.open( {\n\t\t\t\t\treturnFocusWhenClose: selectedBlock,\n\t\t\t\t} );\n\t\t\t\t// Then close the dropdown menu.\n\t\t\t\tcloseMenu();\n\t\t\t} }\n\t\t\t{ ...props }\n\t\t>\n\t\t\t{ __( 'Show more settings' ) }\n\t\t</MenuItem>\n\t);\n}\n\nexport default BlockInspectorButton;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,OAAO,QAAQ,oBAAoB;AAC5C,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AAEnE,SAASC,oBAAoBA,CAAE;EAAEC,SAAS;EAAEC,SAAS;EAAE,GAAGC;AAAM,CAAC,EAAG;EACnE,MAAMC,qBAAqB,GAAGP,SAAS,CACpCQ,MAAM,IAAMA,MAAM,CAAEN,gBAAiB,CAAC,CAACO,wBAAwB,CAAC,CAAC,EACnE,EACD,CAAC;EAED,MAAMC,aAAa,GAAGb,OAAO,CAC5B,MAAMc,QAAQ,CAACC,cAAc,CAAG,SAASL,qBAAuB,EAAE,CAAC,EACnE,CAAEA,qBAAqB,CACxB,CAAC;EAED,OACCM,aAAA,CAACd,QAAQ;IACRe,OAAO,EAAGA,CAAA,KAAM;MACf;MACAV,SAAS,CAACW,IAAI,CAAE;QACfC,oBAAoB,EAAEN;MACvB,CAAE,CAAC;MACH;MACAL,SAAS,CAAC,CAAC;IACZ,CAAG;IAAA,GACEC;EAAK,GAERR,EAAE,CAAE,oBAAqB,CAClB,CAAC;AAEb;AAEA,eAAeK,oBAAoB"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* WordPress dependencies
|
|
5
4
|
*/
|
|
6
5
|
import { useState, useEffect, useRef, createPortal } from '@wordpress/element';
|
|
7
6
|
import { SlotFillProvider, Popover } from '@wordpress/components';
|
|
8
7
|
import { ShortcutProvider } from '@wordpress/keyboard-shortcuts';
|
|
8
|
+
|
|
9
9
|
/**
|
|
10
10
|
* Internal dependencies
|
|
11
11
|
*/
|
|
12
|
-
|
|
13
12
|
import ErrorBoundary from '../error-boundary';
|
|
14
13
|
import SidebarBlockEditor from '../sidebar-block-editor';
|
|
15
14
|
import FocusControl from '../focus-control';
|
|
@@ -40,9 +39,10 @@ export default function CustomizeWidgets({
|
|
|
40
39
|
sidebar: activeSidebarControl.sidebarAdapter,
|
|
41
40
|
inserter: activeSidebarControl.inserter,
|
|
42
41
|
inspector: activeSidebarControl.inspector
|
|
43
|
-
})), activeSidebarControl.container[0]);
|
|
44
|
-
// so that the popovers will appear above both of them.
|
|
42
|
+
})), activeSidebarControl.container[0]);
|
|
45
43
|
|
|
44
|
+
// We have to portal this to the parent of both the editor and the inspector,
|
|
45
|
+
// so that the popovers will appear above both of them.
|
|
46
46
|
const popover = parentContainer && createPortal(createElement("div", {
|
|
47
47
|
className: "customize-widgets-popover",
|
|
48
48
|
ref: popoverRef
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useState","useEffect","useRef","createPortal","SlotFillProvider","Popover","ShortcutProvider","ErrorBoundary","SidebarBlockEditor","FocusControl","SidebarControls","useClearSelectedBlock","CustomizeWidgets","api","sidebarControls","blockEditorSettings","activeSidebarControl","setActiveSidebarControl","parentContainer","document","getElementById","popoverRef","unsubscribers","map","sidebarControl","subscribe","expanded","forEach","unsubscriber","activeSidebar","createElement","key","id","sidebar","sidebarAdapter","inserter","inspector","container","popover","className","ref","Slot"],"sources":["@wordpress/customize-widgets/src/components/customize-widgets/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useEffect, useRef, createPortal } from '@wordpress/element';\nimport { SlotFillProvider, Popover } from '@wordpress/components';\nimport { ShortcutProvider } from '@wordpress/keyboard-shortcuts';\n\n/**\n * Internal dependencies\n */\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\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<ShortcutProvider>\n\t\t\t<SlotFillProvider>\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</SlotFillProvider>\n\t\t</ShortcutProvider>\n\t);\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,SAAS,EAAEC,MAAM,EAAEC,YAAY,QAAQ,oBAAoB;AAC9E,SAASC,gBAAgB,EAAEC,OAAO,QAAQ,uBAAuB;AACjE,SAASC,gBAAgB,QAAQ,+BAA+B;;AAEhE;AACA;AACA;AACA,OAAOC,aAAa,MAAM,mBAAmB;AAC7C,OAAOC,kBAAkB,MAAM,yBAAyB;AACxD,OAAOC,YAAY,MAAM,kBAAkB;AAC3C,OAAOC,eAAe,MAAM,qBAAqB;AACjD,OAAOC,qBAAqB,MAAM,4BAA4B;AAE9D,eAAe,SAASC,gBAAgBA,CAAE;EACzCC,GAAG;EACHC,eAAe;EACfC;AACD,CAAC,EAAG;EACH,MAAM,CAAEC,oBAAoB,EAAEC,uBAAuB,CAAE,GAAGjB,QAAQ,CAAE,IAAK,CAAC;EAC1E,MAAMkB,eAAe,GAAGC,QAAQ,CAACC,cAAc,CAC9C,0BACD,CAAC;EACD,MAAMC,UAAU,GAAGnB,MAAM,CAAC,CAAC;EAE3BS,qBAAqB,CAAEK,oBAAoB,EAAEK,UAAW,CAAC;EAEzDpB,SAAS,CAAE,MAAM;IAChB,MAAMqB,aAAa,GAAGR,eAAe,CAACS,GAAG,CAAIC,cAAc,IAC1DA,cAAc,CAACC,SAAS,CAAIC,QAAQ,IAAM;MACzC,IAAKA,QAAQ,EAAG;QACfT,uBAAuB,CAAEO,cAAe,CAAC;MAC1C;IACD,CAAE,CACH,CAAC;IAED,OAAO,MAAM;MACZF,aAAa,CAACK,OAAO,CAAIC,YAAY,IAAMA,YAAY,CAAC,CAAE,CAAC;IAC5D,CAAC;EACF,CAAC,EAAE,CAAEd,eAAe,CAAG,CAAC;EAExB,MAAMe,aAAa,GAClBb,oBAAoB,IACpBb,YAAY,CACX2B,aAAA,CAACvB,aAAa,QACbuB,aAAA,CAACtB,kBAAkB;IAClBuB,GAAG,EAAGf,oBAAoB,CAACgB,EAAI;IAC/BjB,mBAAmB,EAAGA,mBAAqB;IAC3CkB,OAAO,EAAGjB,oBAAoB,CAACkB,cAAgB;IAC/CC,QAAQ,EAAGnB,oBAAoB,CAACmB,QAAU;IAC1CC,SAAS,EAAGpB,oBAAoB,CAACoB;EAAW,CAC5C,CACa,CAAC,EAChBpB,oBAAoB,CAACqB,SAAS,CAAE,CAAC,CAClC,CAAC;;EAEF;EACA;EACA,MAAMC,OAAO,GACZpB,eAAe,IACff,YAAY,CACX2B,aAAA;IAAKS,SAAS,EAAC,2BAA2B;IAACC,GAAG,EAAGnB;EAAY,GAC5DS,aAAA,CAACzB,OAAO,CAACoC,IAAI,MAAE,CACX,CAAC,EACNvB,eACD,CAAC;EAEF,OACCY,aAAA,CAACxB,gBAAgB,QAChBwB,aAAA,CAAC1B,gBAAgB,QAChB0B,aAAA,CAACpB,eAAe;IACfI,eAAe,EAAGA,eAAiB;IACnCE,oBAAoB,EAAGA;EAAsB,GAE7Cc,aAAA,CAACrB,YAAY;IACZI,GAAG,EAAGA,GAAK;IACXC,eAAe,EAAGA;EAAiB,GAEjCe,aAAa,EACbS,OACW,CACE,CACA,CACD,CAAC;AAErB"}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { useEffect } from '@wordpress/element';
|
|
5
5
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
6
6
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
7
|
+
|
|
7
8
|
/**
|
|
8
9
|
* We can't just use <BlockSelectionClearer> because the customizer has
|
|
9
10
|
* many root nodes rather than just one in the post editor.
|
|
@@ -20,7 +21,6 @@ import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
|
20
21
|
* @param {Object} sidebarControl The sidebar control instance.
|
|
21
22
|
* @param {Object} popoverRef The ref object of the popover node container.
|
|
22
23
|
*/
|
|
23
|
-
|
|
24
24
|
export default function useClearSelectedBlock(sidebarControl, popoverRef) {
|
|
25
25
|
const {
|
|
26
26
|
hasSelectedBlock,
|
|
@@ -35,27 +35,28 @@ export default function useClearSelectedBlock(sidebarControl, popoverRef) {
|
|
|
35
35
|
const container = sidebarControl.container[0];
|
|
36
36
|
const ownerDocument = container.ownerDocument;
|
|
37
37
|
const ownerWindow = ownerDocument.defaultView;
|
|
38
|
-
|
|
39
38
|
function handleClearSelectedBlock(element) {
|
|
40
|
-
if (
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
if (
|
|
40
|
+
// 1. Make sure there are blocks being selected.
|
|
41
|
+
(hasSelectedBlock() || hasMultiSelection()) &&
|
|
42
|
+
// 2. The element should exist in the DOM (not deleted).
|
|
43
|
+
element && ownerDocument.contains(element) &&
|
|
44
|
+
// 3. It should also not exist in the container, the popover, nor the dialog.
|
|
45
|
+
!container.contains(element) && !popoverRef.current.contains(element) && !element.closest('[role="dialog"]') &&
|
|
46
|
+
// 4. The inspector should not be opened.
|
|
44
47
|
!inspector.expanded()) {
|
|
45
48
|
clearSelectedBlock();
|
|
46
49
|
}
|
|
47
|
-
}
|
|
48
|
-
|
|
50
|
+
}
|
|
49
51
|
|
|
52
|
+
// Handle mouse down in the same document.
|
|
50
53
|
function handleMouseDown(event) {
|
|
51
54
|
handleClearSelectedBlock(event.target);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
}
|
|
56
|
+
// Handle focusing outside the current document, like to iframes.
|
|
55
57
|
function handleBlur() {
|
|
56
58
|
handleClearSelectedBlock(ownerDocument.activeElement);
|
|
57
59
|
}
|
|
58
|
-
|
|
59
60
|
ownerDocument.addEventListener('mousedown', handleMouseDown);
|
|
60
61
|
ownerWindow.addEventListener('blur', handleBlur);
|
|
61
62
|
return () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useEffect","useDispatch","useSelect","store","blockEditorStore","useClearSelectedBlock","sidebarControl","popoverRef","hasSelectedBlock","hasMultiSelection","clearSelectedBlock","current","inspector","container","ownerDocument","ownerWindow","defaultView","handleClearSelectedBlock","element","contains","closest","expanded","handleMouseDown","event","target","handleBlur","activeElement","addEventListener","removeEventListener"],"sources":["@wordpress/customize-widgets/src/components/customize-widgets/use-clear-selected-block.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { 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.\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( '[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":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,oBAAoB;AAC9C,SAASC,WAAW,EAAEC,SAAS,QAAQ,iBAAiB;AACxD,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;;AAEnE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,qBAAqBA,CAAEC,cAAc,EAAEC,UAAU,EAAG;EAC3E,MAAM;IAAEC,gBAAgB;IAAEC;EAAkB,CAAC,GAC5CP,SAAS,CAAEE,gBAAiB,CAAC;EAC9B,MAAM;IAAEM;EAAmB,CAAC,GAAGT,WAAW,CAAEG,gBAAiB,CAAC;EAE9DJ,SAAS,CAAE,MAAM;IAChB,IAAKO,UAAU,CAACI,OAAO,IAAIL,cAAc,EAAG;MAC3C,MAAMM,SAAS,GAAGN,cAAc,CAACM,SAAS;MAC1C,MAAMC,SAAS,GAAGP,cAAc,CAACO,SAAS,CAAE,CAAC,CAAE;MAC/C,MAAMC,aAAa,GAAGD,SAAS,CAACC,aAAa;MAC7C,MAAMC,WAAW,GAAGD,aAAa,CAACE,WAAW;MAE7C,SAASC,wBAAwBA,CAAEC,OAAO,EAAG;QAC5C;QACC;QACA,CAAEV,gBAAgB,CAAC,CAAC,IAAIC,iBAAiB,CAAC,CAAC;QAC3C;QACAS,OAAO,IACPJ,aAAa,CAACK,QAAQ,CAAED,OAAQ,CAAC;QACjC;QACA,CAAEL,SAAS,CAACM,QAAQ,CAAED,OAAQ,CAAC,IAC/B,CAAEX,UAAU,CAACI,OAAO,CAACQ,QAAQ,CAAED,OAAQ,CAAC,IACxC,CAAEA,OAAO,CAACE,OAAO,CAAE,iBAAkB,CAAC;QACtC;QACA,CAAER,SAAS,CAACS,QAAQ,CAAC,CAAC,EACrB;UACDX,kBAAkB,CAAC,CAAC;QACrB;MACD;;MAEA;MACA,SAASY,eAAeA,CAAEC,KAAK,EAAG;QACjCN,wBAAwB,CAAEM,KAAK,CAACC,MAAO,CAAC;MACzC;MACA;MACA,SAASC,UAAUA,CAAA,EAAG;QACrBR,wBAAwB,CAAEH,aAAa,CAACY,aAAc,CAAC;MACxD;MAEAZ,aAAa,CAACa,gBAAgB,CAAE,WAAW,EAAEL,eAAgB,CAAC;MAC9DP,WAAW,CAACY,gBAAgB,CAAE,MAAM,EAAEF,UAAW,CAAC;MAElD,OAAO,MAAM;QACZX,aAAa,CAACc,mBAAmB,CAChC,WAAW,EACXN,eACD,CAAC;QACDP,WAAW,CAACa,mBAAmB,CAAE,MAAM,EAAEH,UAAW,CAAC;MACtD,CAAC;IACF;EACD,CAAC,EAAE,CACFlB,UAAU,EACVD,cAAc,EACdE,gBAAgB,EAChBC,iBAAiB,EACjBC,kBAAkB,CACjB,CAAC;AACJ"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* WordPress dependencies
|
|
5
4
|
*/
|
|
@@ -9,7 +8,6 @@ import { Button } from '@wordpress/components';
|
|
|
9
8
|
import { Warning } from '@wordpress/block-editor';
|
|
10
9
|
import { useCopyToClipboard } from '@wordpress/compose';
|
|
11
10
|
import { doAction } from '@wordpress/hooks';
|
|
12
|
-
|
|
13
11
|
function CopyButton({
|
|
14
12
|
text,
|
|
15
13
|
children
|
|
@@ -20,7 +18,6 @@ function CopyButton({
|
|
|
20
18
|
ref: ref
|
|
21
19
|
}, children);
|
|
22
20
|
}
|
|
23
|
-
|
|
24
21
|
export default class ErrorBoundary extends Component {
|
|
25
22
|
constructor() {
|
|
26
23
|
super(...arguments);
|
|
@@ -28,23 +25,19 @@ export default class ErrorBoundary extends Component {
|
|
|
28
25
|
error: null
|
|
29
26
|
};
|
|
30
27
|
}
|
|
31
|
-
|
|
32
28
|
componentDidCatch(error) {
|
|
33
29
|
this.setState({
|
|
34
30
|
error
|
|
35
31
|
});
|
|
36
32
|
doAction('editor.ErrorBoundary.errorLogged', error);
|
|
37
33
|
}
|
|
38
|
-
|
|
39
34
|
render() {
|
|
40
35
|
const {
|
|
41
36
|
error
|
|
42
37
|
} = this.state;
|
|
43
|
-
|
|
44
38
|
if (!error) {
|
|
45
39
|
return this.props.children;
|
|
46
40
|
}
|
|
47
|
-
|
|
48
41
|
return createElement(Warning, {
|
|
49
42
|
className: "customize-widgets-error-boundary",
|
|
50
43
|
actions: [createElement(CopyButton, {
|
|
@@ -53,6 +46,5 @@ export default class ErrorBoundary extends Component {
|
|
|
53
46
|
}, __('Copy Error'))]
|
|
54
47
|
}, __('The editor has encountered an unexpected error.'));
|
|
55
48
|
}
|
|
56
|
-
|
|
57
49
|
}
|
|
58
50
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["Component","__","Button","Warning","useCopyToClipboard","doAction","CopyButton","text","children","ref","createElement","variant","ErrorBoundary","constructor","arguments","state","error","componentDidCatch","setState","render","props","className","actions","key","stack"],"sources":["@wordpress/customize-widgets/src/components/error-boundary/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { Button } from '@wordpress/components';\nimport { Warning } from '@wordpress/block-editor';\nimport { useCopyToClipboard } from '@wordpress/compose';\nimport { doAction } from '@wordpress/hooks';\n\nfunction CopyButton( { text, children } ) {\n\tconst ref = useCopyToClipboard( text );\n\treturn (\n\t\t<Button variant=\"secondary\" ref={ ref }>\n\t\t\t{ children }\n\t\t</Button>\n\t);\n}\n\nexport default class ErrorBoundary extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\t\tthis.state = {\n\t\t\terror: null,\n\t\t};\n\t}\n\n\tcomponentDidCatch( error ) {\n\t\tthis.setState( { error } );\n\n\t\tdoAction( 'editor.ErrorBoundary.errorLogged', error );\n\t}\n\n\trender() {\n\t\tconst { error } = this.state;\n\t\tif ( ! error ) {\n\t\t\treturn this.props.children;\n\t\t}\n\n\t\treturn (\n\t\t\t<Warning\n\t\t\t\tclassName=\"customize-widgets-error-boundary\"\n\t\t\t\tactions={ [\n\t\t\t\t\t<CopyButton key=\"copy-error\" text={ error.stack }>\n\t\t\t\t\t\t{ __( 'Copy Error' ) }\n\t\t\t\t\t</CopyButton>,\n\t\t\t\t] }\n\t\t\t>\n\t\t\t\t{ __( 'The editor has encountered an unexpected error.' ) }\n\t\t\t</Warning>\n\t\t);\n\t}\n}\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,oBAAoB;AAC9C,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,MAAM,QAAQ,uBAAuB;AAC9C,SAASC,OAAO,QAAQ,yBAAyB;AACjD,SAASC,kBAAkB,QAAQ,oBAAoB;AACvD,SAASC,QAAQ,QAAQ,kBAAkB;AAE3C,SAASC,UAAUA,CAAE;EAAEC,IAAI;EAAEC;AAAS,CAAC,EAAG;EACzC,MAAMC,GAAG,GAAGL,kBAAkB,CAAEG,IAAK,CAAC;EACtC,OACCG,aAAA,CAACR,MAAM;IAACS,OAAO,EAAC,WAAW;IAACF,GAAG,EAAGA;EAAK,GACpCD,QACK,CAAC;AAEX;AAEA,eAAe,MAAMI,aAAa,SAASZ,SAAS,CAAC;EACpDa,WAAWA,CAAA,EAAG;IACb,KAAK,CAAE,GAAGC,SAAU,CAAC;IACrB,IAAI,CAACC,KAAK,GAAG;MACZC,KAAK,EAAE;IACR,CAAC;EACF;EAEAC,iBAAiBA,CAAED,KAAK,EAAG;IAC1B,IAAI,CAACE,QAAQ,CAAE;MAAEF;IAAM,CAAE,CAAC;IAE1BX,QAAQ,CAAE,kCAAkC,EAAEW,KAAM,CAAC;EACtD;EAEAG,MAAMA,CAAA,EAAG;IACR,MAAM;MAAEH;IAAM,CAAC,GAAG,IAAI,CAACD,KAAK;IAC5B,IAAK,CAAEC,KAAK,EAAG;MACd,OAAO,IAAI,CAACI,KAAK,CAACZ,QAAQ;IAC3B;IAEA,OACCE,aAAA,CAACP,OAAO;MACPkB,SAAS,EAAC,kCAAkC;MAC5CC,OAAO,EAAG,CACTZ,aAAA,CAACJ,UAAU;QAACiB,GAAG,EAAC,YAAY;QAAChB,IAAI,EAAGS,KAAK,CAACQ;MAAO,GAC9CvB,EAAE,CAAE,YAAa,CACR,CAAC;IACX,GAEDA,EAAE,CAAE,iDAAkD,CAChD,CAAC;EAEZ;AACD"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* WordPress dependencies
|
|
5
4
|
*/
|
|
6
5
|
import { createContext, useState, useEffect, useContext, useCallback, useMemo } from '@wordpress/element';
|
|
6
|
+
|
|
7
7
|
/**
|
|
8
8
|
* Internal dependencies
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
import { settingIdToWidgetId } from '../../utils';
|
|
12
11
|
const FocusControlContext = createContext();
|
|
13
12
|
export default function FocusControl({
|
|
@@ -21,7 +20,6 @@ export default function FocusControl({
|
|
|
21
20
|
const focusWidget = useCallback(widgetId => {
|
|
22
21
|
for (const sidebarControl of sidebarControls) {
|
|
23
22
|
const widgets = sidebarControl.setting.get();
|
|
24
|
-
|
|
25
23
|
if (widgets.includes(widgetId)) {
|
|
26
24
|
sidebarControl.sectionInstance.expand({
|
|
27
25
|
// Schedule it after the complete callback so that
|
|
@@ -33,7 +31,6 @@ export default function FocusControl({
|
|
|
33
31
|
current: widgetId
|
|
34
32
|
});
|
|
35
33
|
}
|
|
36
|
-
|
|
37
34
|
});
|
|
38
35
|
break;
|
|
39
36
|
}
|
|
@@ -44,18 +41,14 @@ export default function FocusControl({
|
|
|
44
41
|
const widgetId = settingIdToWidgetId(settingId);
|
|
45
42
|
focusWidget(widgetId);
|
|
46
43
|
}
|
|
47
|
-
|
|
48
44
|
let previewBound = false;
|
|
49
|
-
|
|
50
45
|
function handleReady() {
|
|
51
46
|
api.previewer.preview.bind('focus-control-for-setting', handleFocus);
|
|
52
47
|
previewBound = true;
|
|
53
48
|
}
|
|
54
|
-
|
|
55
49
|
api.previewer.bind('ready', handleReady);
|
|
56
50
|
return () => {
|
|
57
51
|
api.previewer.unbind('ready', handleReady);
|
|
58
|
-
|
|
59
52
|
if (previewBound) {
|
|
60
53
|
api.previewer.preview.unbind('focus-control-for-setting', handleFocus);
|
|
61
54
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createContext","useState","useEffect","useContext","useCallback","useMemo","settingIdToWidgetId","FocusControlContext","FocusControl","api","sidebarControls","children","focusedWidgetIdRef","setFocusedWidgetIdRef","current","focusWidget","widgetId","sidebarControl","widgets","setting","get","includes","sectionInstance","expand","completeCallback","handleFocus","settingId","previewBound","handleReady","previewer","preview","bind","unbind","context","createElement","Provider","value","useFocusControl"],"sources":["@wordpress/customize-widgets/src/components/focus-control/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport {\n\tcreateContext,\n\tuseState,\n\tuseEffect,\n\tuseContext,\n\tuseCallback,\n\tuseMemo,\n} from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { settingIdToWidgetId } from '../../utils';\n\nconst FocusControlContext = createContext();\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":";AAAA;AACA;AACA;AACA,SACCA,aAAa,EACbC,QAAQ,EACRC,SAAS,EACTC,UAAU,EACVC,WAAW,EACXC,OAAO,QACD,oBAAoB;;AAE3B;AACA;AACA;AACA,SAASC,mBAAmB,QAAQ,aAAa;AAEjD,MAAMC,mBAAmB,GAAGP,aAAa,CAAC,CAAC;AAE3C,eAAe,SAASQ,YAAYA,CAAE;EAAEC,GAAG;EAAEC,eAAe;EAAEC;AAAS,CAAC,EAAG;EAC1E,MAAM,CAAEC,kBAAkB,EAAEC,qBAAqB,CAAE,GAAGZ,QAAQ,CAAE;IAC/Da,OAAO,EAAE;EACV,CAAE,CAAC;EAEH,MAAMC,WAAW,GAAGX,WAAW,CAC5BY,QAAQ,IAAM;IACf,KAAM,MAAMC,cAAc,IAAIP,eAAe,EAAG;MAC/C,MAAMQ,OAAO,GAAGD,cAAc,CAACE,OAAO,CAACC,GAAG,CAAC,CAAC;MAE5C,IAAKF,OAAO,CAACG,QAAQ,CAAEL,QAAS,CAAC,EAAG;QACnCC,cAAc,CAACK,eAAe,CAACC,MAAM,CAAE;UACtC;UACA;UACAC,gBAAgBA,CAAA,EAAG;YAClB;YACA;YACAX,qBAAqB,CAAE;cAAEC,OAAO,EAAEE;YAAS,CAAE,CAAC;UAC/C;QACD,CAAE,CAAC;QAEH;MACD;IACD;EACD,CAAC,EACD,CAAEN,eAAe,CAClB,CAAC;EAEDR,SAAS,CAAE,MAAM;IAChB,SAASuB,WAAWA,CAAEC,SAAS,EAAG;MACjC,MAAMV,QAAQ,GAAGV,mBAAmB,CAAEoB,SAAU,CAAC;MAEjDX,WAAW,CAAEC,QAAS,CAAC;IACxB;IAEA,IAAIW,YAAY,GAAG,KAAK;IAExB,SAASC,WAAWA,CAAA,EAAG;MACtBnB,GAAG,CAACoB,SAAS,CAACC,OAAO,CAACC,IAAI,CACzB,2BAA2B,EAC3BN,WACD,CAAC;MACDE,YAAY,GAAG,IAAI;IACpB;IAEAlB,GAAG,CAACoB,SAAS,CAACE,IAAI,CAAE,OAAO,EAAEH,WAAY,CAAC;IAE1C,OAAO,MAAM;MACZnB,GAAG,CAACoB,SAAS,CAACG,MAAM,CAAE,OAAO,EAAEJ,WAAY,CAAC;MAC5C,IAAKD,YAAY,EAAG;QACnBlB,GAAG,CAACoB,SAAS,CAACC,OAAO,CAACE,MAAM,CAC3B,2BAA2B,EAC3BP,WACD,CAAC;MACF;IACD,CAAC;EACF,CAAC,EAAE,CAAEhB,GAAG,EAAEM,WAAW,CAAG,CAAC;EAEzB,MAAMkB,OAAO,GAAG5B,OAAO,CACtB,MAAM,CAAEO,kBAAkB,EAAEG,WAAW,CAAE,EACzC,CAAEH,kBAAkB,EAAEG,WAAW,CAClC,CAAC;EAED,OACCmB,aAAA,CAAC3B,mBAAmB,CAAC4B,QAAQ;IAACC,KAAK,EAAGH;EAAS,GAC5CtB,QAC2B,CAAC;AAEjC;AAEA,OAAO,MAAM0B,eAAe,GAAGA,CAAA,KAAMlC,UAAU,CAAEI,mBAAoB,CAAC"}
|
|
@@ -5,10 +5,10 @@ import { useRef, useEffect } from '@wordpress/element';
|
|
|
5
5
|
import { useDispatch } from '@wordpress/data';
|
|
6
6
|
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
7
7
|
import { getWidgetIdFromBlock } from '@wordpress/widgets';
|
|
8
|
+
|
|
8
9
|
/**
|
|
9
10
|
* Internal dependencies
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
12
|
import { useFocusControl } from '.';
|
|
13
13
|
export default function useBlocksFocusControl(blocks) {
|
|
14
14
|
const {
|
|
@@ -22,12 +22,11 @@ export default function useBlocksFocusControl(blocks) {
|
|
|
22
22
|
useEffect(() => {
|
|
23
23
|
if (focusedWidgetIdRef.current) {
|
|
24
24
|
const focusedBlock = blocksRef.current.find(block => getWidgetIdFromBlock(block) === focusedWidgetIdRef.current);
|
|
25
|
-
|
|
26
25
|
if (focusedBlock) {
|
|
27
|
-
selectBlock(focusedBlock.clientId);
|
|
26
|
+
selectBlock(focusedBlock.clientId);
|
|
27
|
+
// If the block is already being selected, the DOM node won't
|
|
28
28
|
// get focused again automatically.
|
|
29
29
|
// We select the DOM and focus it manually here.
|
|
30
|
-
|
|
31
30
|
const blockNode = document.querySelector(`[data-block="${focusedBlock.clientId}"]`);
|
|
32
31
|
blockNode?.focus();
|
|
33
32
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["useRef","useEffect","useDispatch","store","blockEditorStore","getWidgetIdFromBlock","useFocusControl","useBlocksFocusControl","blocks","selectBlock","focusedWidgetIdRef","blocksRef","current","focusedBlock","find","block","clientId","blockNode","document","querySelector","focus"],"sources":["@wordpress/customize-widgets/src/components/focus-control/use-blocks-focus-control.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect } from '@wordpress/element';\nimport { useDispatch } from '@wordpress/data';\nimport { store as blockEditorStore } from '@wordpress/block-editor';\nimport { getWidgetIdFromBlock } from '@wordpress/widgets';\n\n/**\n * Internal dependencies\n */\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":"AAAA;AACA;AACA;AACA,SAASA,MAAM,EAAEC,SAAS,QAAQ,oBAAoB;AACtD,SAASC,WAAW,QAAQ,iBAAiB;AAC7C,SAASC,KAAK,IAAIC,gBAAgB,QAAQ,yBAAyB;AACnE,SAASC,oBAAoB,QAAQ,oBAAoB;;AAEzD;AACA;AACA;AACA,SAASC,eAAe,QAAQ,GAAG;AAEnC,eAAe,SAASC,qBAAqBA,CAAEC,MAAM,EAAG;EACvD,MAAM;IAAEC;EAAY,CAAC,GAAGP,WAAW,CAAEE,gBAAiB,CAAC;EACvD,MAAM,CAAEM,kBAAkB,CAAE,GAAGJ,eAAe,CAAC,CAAC;EAEhD,MAAMK,SAAS,GAAGX,MAAM,CAAEQ,MAAO,CAAC;EAElCP,SAAS,CAAE,MAAM;IAChBU,SAAS,CAACC,OAAO,GAAGJ,MAAM;EAC3B,CAAC,EAAE,CAAEA,MAAM,CAAG,CAAC;EAEfP,SAAS,CAAE,MAAM;IAChB,IAAKS,kBAAkB,CAACE,OAAO,EAAG;MACjC,MAAMC,YAAY,GAAGF,SAAS,CAACC,OAAO,CAACE,IAAI,CACxCC,KAAK,IACNV,oBAAoB,CAAEU,KAAM,CAAC,KAAKL,kBAAkB,CAACE,OACvD,CAAC;MAED,IAAKC,YAAY,EAAG;QACnBJ,WAAW,CAAEI,YAAY,CAACG,QAAS,CAAC;QACpC;QACA;QACA;QACA,MAAMC,SAAS,GAAGC,QAAQ,CAACC,aAAa,CACtC,gBAAgBN,YAAY,CAACG,QAAU,IACzC,CAAC;QACDC,SAAS,EAAEG,KAAK,CAAC,CAAC;MACnB;IACD;EACD,CAAC,EAAE,CAAEV,kBAAkB,EAAED,WAAW,CAAG,CAAC;AACzC"}
|
|
@@ -1,26 +1,24 @@
|
|
|
1
1
|
import { createElement, Fragment } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* External dependencies
|
|
5
4
|
*/
|
|
6
5
|
import classnames from 'classnames';
|
|
6
|
+
|
|
7
7
|
/**
|
|
8
8
|
* WordPress dependencies
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
import { createPortal, useState, useEffect } from '@wordpress/element';
|
|
12
11
|
import { __, _x, isRTL } from '@wordpress/i18n';
|
|
13
12
|
import { ToolbarButton } from '@wordpress/components';
|
|
14
13
|
import { NavigableToolbar } from '@wordpress/block-editor';
|
|
15
14
|
import { displayShortcut, isAppleOS } from '@wordpress/keycodes';
|
|
16
15
|
import { plus, undo as undoIcon, redo as redoIcon } from '@wordpress/icons';
|
|
16
|
+
|
|
17
17
|
/**
|
|
18
18
|
* Internal dependencies
|
|
19
19
|
*/
|
|
20
|
-
|
|
21
20
|
import Inserter from '../inserter';
|
|
22
21
|
import MoreMenu from '../more-menu';
|
|
23
|
-
|
|
24
22
|
function Header({
|
|
25
23
|
sidebar,
|
|
26
24
|
inserter,
|
|
@@ -44,10 +42,10 @@ function Header({
|
|
|
44
42
|
"aria-label": __('Document tools')
|
|
45
43
|
}, createElement(ToolbarButton, {
|
|
46
44
|
icon: !isRTL() ? undoIcon : redoIcon
|
|
47
|
-
/* translators: button label text should, if possible, be under 16 characters.
|
|
48
|
-
,
|
|
45
|
+
/* translators: button label text should, if possible, be under 16 characters. */,
|
|
49
46
|
label: __('Undo'),
|
|
50
|
-
shortcut: displayShortcut.primary('z')
|
|
47
|
+
shortcut: displayShortcut.primary('z')
|
|
48
|
+
// If there are no undo levels we don't want to actually disable this
|
|
51
49
|
// button, because it will remove focus for keyboard users.
|
|
52
50
|
// See: https://github.com/WordPress/gutenberg/issues/3486
|
|
53
51
|
,
|
|
@@ -56,10 +54,10 @@ function Header({
|
|
|
56
54
|
className: "customize-widgets-editor-history-button undo-button"
|
|
57
55
|
}), createElement(ToolbarButton, {
|
|
58
56
|
icon: !isRTL() ? redoIcon : undoIcon
|
|
59
|
-
/* translators: button label text should, if possible, be under 16 characters.
|
|
60
|
-
,
|
|
57
|
+
/* translators: button label text should, if possible, be under 16 characters. */,
|
|
61
58
|
label: __('Redo'),
|
|
62
|
-
shortcut: shortcut
|
|
59
|
+
shortcut: shortcut
|
|
60
|
+
// If there are no undo levels we don't want to actually disable this
|
|
63
61
|
// button, because it will remove focus for keyboard users.
|
|
64
62
|
// See: https://github.com/WordPress/gutenberg/issues/3486
|
|
65
63
|
,
|
|
@@ -79,6 +77,5 @@ function Header({
|
|
|
79
77
|
setIsOpened: setIsInserterOpened
|
|
80
78
|
}), inserter.contentContainer[0]));
|
|
81
79
|
}
|
|
82
|
-
|
|
83
80
|
export default Header;
|
|
84
81
|
//# sourceMappingURL=index.js.map
|