@wordpress/edit-widgets 5.22.0 → 5.24.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/header/document-tools/index.js +119 -0
- package/build/components/header/document-tools/index.js.map +1 -0
- package/build/components/header/index.js +23 -90
- package/build/components/header/index.js.map +1 -1
- package/build-module/components/header/document-tools/index.js +110 -0
- package/build-module/components/header/document-tools/index.js.map +1 -0
- package/build-module/components/header/index.js +26 -93
- package/build-module/components/header/index.js.map +1 -1
- package/build-style/style-rtl.css +8 -105
- package/build-style/style.css +8 -105
- package/package.json +28 -28
- package/src/components/header/document-tools/index.js +130 -0
- package/src/components/header/index.js +33 -114
- package/src/components/header/style.scss +10 -0
- package/src/components/layout/style.scss +0 -12
- package/src/components/widget-areas-block-editor-content/style.scss +0 -98
package/CHANGELOG.md
CHANGED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
var _data = require("@wordpress/data");
|
|
10
|
+
var _i18n = require("@wordpress/i18n");
|
|
11
|
+
var _components = require("@wordpress/components");
|
|
12
|
+
var _blockEditor = require("@wordpress/block-editor");
|
|
13
|
+
var _icons = require("@wordpress/icons");
|
|
14
|
+
var _element = require("@wordpress/element");
|
|
15
|
+
var _compose = require("@wordpress/compose");
|
|
16
|
+
var _undo = _interopRequireDefault(require("../undo-redo/undo"));
|
|
17
|
+
var _redo = _interopRequireDefault(require("../undo-redo/redo"));
|
|
18
|
+
var _useLastSelectedWidgetArea = _interopRequireDefault(require("../../../hooks/use-last-selected-widget-area"));
|
|
19
|
+
var _store = require("../../../store");
|
|
20
|
+
var _lockUnlock = require("../../../lock-unlock");
|
|
21
|
+
/**
|
|
22
|
+
* WordPress dependencies
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Internal dependencies
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
const {
|
|
30
|
+
useShouldContextualToolbarShow
|
|
31
|
+
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
32
|
+
function DocumentTools({
|
|
33
|
+
setListViewToggleElement
|
|
34
|
+
}) {
|
|
35
|
+
const isMediumViewport = (0, _compose.useViewportMatch)('medium');
|
|
36
|
+
const inserterButton = (0, _element.useRef)();
|
|
37
|
+
const widgetAreaClientId = (0, _useLastSelectedWidgetArea.default)();
|
|
38
|
+
const isLastSelectedWidgetAreaOpen = (0, _data.useSelect)(select => select(_store.store).getIsWidgetAreaOpen(widgetAreaClientId), [widgetAreaClientId]);
|
|
39
|
+
const {
|
|
40
|
+
isInserterOpen,
|
|
41
|
+
isListViewOpen
|
|
42
|
+
} = (0, _data.useSelect)(select => {
|
|
43
|
+
const {
|
|
44
|
+
isInserterOpened,
|
|
45
|
+
isListViewOpened
|
|
46
|
+
} = select(_store.store);
|
|
47
|
+
return {
|
|
48
|
+
isInserterOpen: isInserterOpened(),
|
|
49
|
+
isListViewOpen: isListViewOpened()
|
|
50
|
+
};
|
|
51
|
+
}, []);
|
|
52
|
+
const {
|
|
53
|
+
setIsWidgetAreaOpen,
|
|
54
|
+
setIsInserterOpened,
|
|
55
|
+
setIsListViewOpened
|
|
56
|
+
} = (0, _data.useDispatch)(_store.store);
|
|
57
|
+
const {
|
|
58
|
+
selectBlock
|
|
59
|
+
} = (0, _data.useDispatch)(_blockEditor.store);
|
|
60
|
+
const handleClick = () => {
|
|
61
|
+
if (isInserterOpen) {
|
|
62
|
+
// Focusing the inserter button closes the inserter popover.
|
|
63
|
+
setIsInserterOpened(false);
|
|
64
|
+
} else {
|
|
65
|
+
if (!isLastSelectedWidgetAreaOpen) {
|
|
66
|
+
// Select the last selected block if hasn't already.
|
|
67
|
+
selectBlock(widgetAreaClientId);
|
|
68
|
+
// Open the last selected widget area when opening the inserter.
|
|
69
|
+
setIsWidgetAreaOpen(widgetAreaClientId, true);
|
|
70
|
+
}
|
|
71
|
+
// The DOM updates resulting from selectBlock() and setIsInserterOpened() calls are applied the
|
|
72
|
+
// same tick and pretty much in a random order. The inserter is closed if any other part of the
|
|
73
|
+
// app receives focus. If selectBlock() happens to take effect after setIsInserterOpened() then
|
|
74
|
+
// the inserter is visible for a brief moment and then gets auto-closed due to focus moving to
|
|
75
|
+
// the selected block.
|
|
76
|
+
window.requestAnimationFrame(() => setIsInserterOpened(true));
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const toggleListView = (0, _element.useCallback)(() => setIsListViewOpened(!isListViewOpen), [setIsListViewOpened, isListViewOpen]);
|
|
80
|
+
const {
|
|
81
|
+
shouldShowContextualToolbar,
|
|
82
|
+
canFocusHiddenToolbar,
|
|
83
|
+
fixedToolbarCanBeFocused
|
|
84
|
+
} = useShouldContextualToolbarShow();
|
|
85
|
+
// If there's a block toolbar to be focused, disable the focus shortcut for the document toolbar.
|
|
86
|
+
// There's a fixed block toolbar when the fixed toolbar option is enabled or when the browser width is less than the large viewport.
|
|
87
|
+
const blockToolbarCanBeFocused = shouldShowContextualToolbar || canFocusHiddenToolbar || fixedToolbarCanBeFocused;
|
|
88
|
+
return (0, _react.createElement)(_blockEditor.NavigableToolbar, {
|
|
89
|
+
className: "edit-widgets-header-toolbar",
|
|
90
|
+
"aria-label": (0, _i18n.__)('Document tools'),
|
|
91
|
+
shouldUseKeyboardFocusShortcut: !blockToolbarCanBeFocused
|
|
92
|
+
}, (0, _react.createElement)(_components.ToolbarItem, {
|
|
93
|
+
ref: inserterButton,
|
|
94
|
+
as: _components.Button,
|
|
95
|
+
className: "edit-widgets-header-toolbar__inserter-toggle",
|
|
96
|
+
variant: "primary",
|
|
97
|
+
isPressed: isInserterOpen,
|
|
98
|
+
onMouseDown: event => {
|
|
99
|
+
event.preventDefault();
|
|
100
|
+
},
|
|
101
|
+
onClick: handleClick,
|
|
102
|
+
icon: _icons.plus
|
|
103
|
+
/* translators: button label text should, if possible, be under 16
|
|
104
|
+
characters. */,
|
|
105
|
+
label: (0, _i18n._x)('Toggle block inserter', 'Generic label for block inserter button')
|
|
106
|
+
}), isMediumViewport && (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(_undo.default, null), (0, _react.createElement)(_redo.default, null), (0, _react.createElement)(_components.ToolbarItem, {
|
|
107
|
+
as: _components.Button,
|
|
108
|
+
className: "edit-widgets-header-toolbar__list-view-toggle",
|
|
109
|
+
icon: _icons.listView,
|
|
110
|
+
isPressed: isListViewOpen
|
|
111
|
+
/* translators: button label text should, if possible, be under 16 characters. */,
|
|
112
|
+
label: (0, _i18n.__)('List View'),
|
|
113
|
+
onClick: toggleListView,
|
|
114
|
+
ref: setListViewToggleElement
|
|
115
|
+
})));
|
|
116
|
+
}
|
|
117
|
+
var _default = DocumentTools;
|
|
118
|
+
exports.default = _default;
|
|
119
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_data","require","_i18n","_components","_blockEditor","_icons","_element","_compose","_undo","_interopRequireDefault","_redo","_useLastSelectedWidgetArea","_store","_lockUnlock","useShouldContextualToolbarShow","unlock","blockEditorPrivateApis","DocumentTools","setListViewToggleElement","isMediumViewport","useViewportMatch","inserterButton","useRef","widgetAreaClientId","useLastSelectedWidgetArea","isLastSelectedWidgetAreaOpen","useSelect","select","editWidgetsStore","getIsWidgetAreaOpen","isInserterOpen","isListViewOpen","isInserterOpened","isListViewOpened","setIsWidgetAreaOpen","setIsInserterOpened","setIsListViewOpened","useDispatch","selectBlock","blockEditorStore","handleClick","window","requestAnimationFrame","toggleListView","useCallback","shouldShowContextualToolbar","canFocusHiddenToolbar","fixedToolbarCanBeFocused","blockToolbarCanBeFocused","_react","createElement","NavigableToolbar","className","__","shouldUseKeyboardFocusShortcut","ToolbarItem","ref","as","Button","variant","isPressed","onMouseDown","event","preventDefault","onClick","icon","plus","label","_x","Fragment","default","listView","_default","exports"],"sources":["@wordpress/edit-widgets/src/components/header/document-tools/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __, _x } from '@wordpress/i18n';\nimport { Button, ToolbarItem } from '@wordpress/components';\nimport {\n\tNavigableToolbar,\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { listView, plus } from '@wordpress/icons';\nimport { useCallback, useRef } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport UndoButton from '../undo-redo/undo';\nimport RedoButton from '../undo-redo/redo';\nimport useLastSelectedWidgetArea from '../../../hooks/use-last-selected-widget-area';\nimport { store as editWidgetsStore } from '../../../store';\nimport { unlock } from '../../../lock-unlock';\n\nconst { useShouldContextualToolbarShow } = unlock( blockEditorPrivateApis );\n\nfunction DocumentTools( { setListViewToggleElement } ) {\n\tconst isMediumViewport = useViewportMatch( 'medium' );\n\tconst inserterButton = useRef();\n\tconst widgetAreaClientId = useLastSelectedWidgetArea();\n\tconst isLastSelectedWidgetAreaOpen = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editWidgetsStore ).getIsWidgetAreaOpen(\n\t\t\t\twidgetAreaClientId\n\t\t\t),\n\t\t[ widgetAreaClientId ]\n\t);\n\tconst { isInserterOpen, isListViewOpen } = useSelect( ( select ) => {\n\t\tconst { isInserterOpened, isListViewOpened } =\n\t\t\tselect( editWidgetsStore );\n\t\treturn {\n\t\t\tisInserterOpen: isInserterOpened(),\n\t\t\tisListViewOpen: isListViewOpened(),\n\t\t};\n\t}, [] );\n\tconst { setIsWidgetAreaOpen, setIsInserterOpened, setIsListViewOpened } =\n\t\tuseDispatch( editWidgetsStore );\n\tconst { selectBlock } = useDispatch( blockEditorStore );\n\tconst handleClick = () => {\n\t\tif ( isInserterOpen ) {\n\t\t\t// Focusing the inserter button closes the inserter popover.\n\t\t\tsetIsInserterOpened( false );\n\t\t} else {\n\t\t\tif ( ! isLastSelectedWidgetAreaOpen ) {\n\t\t\t\t// Select the last selected block if hasn't already.\n\t\t\t\tselectBlock( widgetAreaClientId );\n\t\t\t\t// Open the last selected widget area when opening the inserter.\n\t\t\t\tsetIsWidgetAreaOpen( widgetAreaClientId, true );\n\t\t\t}\n\t\t\t// The DOM updates resulting from selectBlock() and setIsInserterOpened() calls are applied the\n\t\t\t// same tick and pretty much in a random order. The inserter is closed if any other part of the\n\t\t\t// app receives focus. If selectBlock() happens to take effect after setIsInserterOpened() then\n\t\t\t// the inserter is visible for a brief moment and then gets auto-closed due to focus moving to\n\t\t\t// the selected block.\n\t\t\twindow.requestAnimationFrame( () => setIsInserterOpened( true ) );\n\t\t}\n\t};\n\n\tconst toggleListView = useCallback(\n\t\t() => setIsListViewOpened( ! isListViewOpen ),\n\t\t[ setIsListViewOpened, isListViewOpen ]\n\t);\n\n\tconst {\n\t\tshouldShowContextualToolbar,\n\t\tcanFocusHiddenToolbar,\n\t\tfixedToolbarCanBeFocused,\n\t} = useShouldContextualToolbarShow();\n\t// If there's a block toolbar to be focused, disable the focus shortcut for the document toolbar.\n\t// There's a fixed block toolbar when the fixed toolbar option is enabled or when the browser width is less than the large viewport.\n\tconst blockToolbarCanBeFocused =\n\t\tshouldShowContextualToolbar ||\n\t\tcanFocusHiddenToolbar ||\n\t\tfixedToolbarCanBeFocused;\n\n\treturn (\n\t\t<NavigableToolbar\n\t\t\tclassName=\"edit-widgets-header-toolbar\"\n\t\t\taria-label={ __( 'Document tools' ) }\n\t\t\tshouldUseKeyboardFocusShortcut={ ! blockToolbarCanBeFocused }\n\t\t>\n\t\t\t<ToolbarItem\n\t\t\t\tref={ inserterButton }\n\t\t\t\tas={ Button }\n\t\t\t\tclassName=\"edit-widgets-header-toolbar__inserter-toggle\"\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tisPressed={ isInserterOpen }\n\t\t\t\tonMouseDown={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t} }\n\t\t\t\tonClick={ handleClick }\n\t\t\t\ticon={ plus }\n\t\t\t\t/* translators: button label text should, if possible, be under 16\n\t\t\t\t\tcharacters. */\n\t\t\t\tlabel={ _x(\n\t\t\t\t\t'Toggle block inserter',\n\t\t\t\t\t'Generic label for block inserter button'\n\t\t\t\t) }\n\t\t\t/>\n\t\t\t{ isMediumViewport && (\n\t\t\t\t<>\n\t\t\t\t\t<UndoButton />\n\t\t\t\t\t<RedoButton />\n\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\tclassName=\"edit-widgets-header-toolbar__list-view-toggle\"\n\t\t\t\t\t\ticon={ listView }\n\t\t\t\t\t\tisPressed={ isListViewOpen }\n\t\t\t\t\t\t/* translators: button label text should, if possible, be under 16 characters. */\n\t\t\t\t\t\tlabel={ __( 'List View' ) }\n\t\t\t\t\t\tonClick={ toggleListView }\n\t\t\t\t\t\tref={ setListViewToggleElement }\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</NavigableToolbar>\n\t);\n}\n\nexport default DocumentTools;\n"],"mappings":";;;;;;;;AAGA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAF,OAAA;AACA,IAAAG,YAAA,GAAAH,OAAA;AAKA,IAAAI,MAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AAKA,IAAAO,KAAA,GAAAC,sBAAA,CAAAR,OAAA;AACA,IAAAS,KAAA,GAAAD,sBAAA,CAAAR,OAAA;AACA,IAAAU,0BAAA,GAAAF,sBAAA,CAAAR,OAAA;AACA,IAAAW,MAAA,GAAAX,OAAA;AACA,IAAAY,WAAA,GAAAZ,OAAA;AAtB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A,CAAAC,aAAA,EAAC/C,WAAA,CAAAoD,WAAW;IACXE,EAAE,EAAGC,kBAAQ;IACbN,SAAS,EAAC,+CAA+C;IACzDa,IAAI,EAAGM,eAAU;IACjBX,SAAS,EAAG7B;IACZ;IACAoC,KAAK,EAAG,IAAAd,QAAE,EAAE,WAAY,CAAG;IAC3BW,OAAO,EAAGrB,cAAgB;IAC1Ba,GAAG,EAAGtC;EAA0B,CAChC,CACA,CAEc,CAAC;AAErB;AAAC,IAAAsD,QAAA,GAEcvD,aAAa;AAAAwD,OAAA,CAAAH,OAAA,GAAAE,QAAA"}
|
|
@@ -6,20 +6,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _react = require("react");
|
|
9
|
+
var _blockEditor = require("@wordpress/block-editor");
|
|
9
10
|
var _data = require("@wordpress/data");
|
|
11
|
+
var _element = require("@wordpress/element");
|
|
10
12
|
var _i18n = require("@wordpress/i18n");
|
|
11
13
|
var _components = require("@wordpress/components");
|
|
12
|
-
var _blockEditor = require("@wordpress/block-editor");
|
|
13
14
|
var _interface = require("@wordpress/interface");
|
|
14
|
-
var _icons = require("@wordpress/icons");
|
|
15
|
-
var _element = require("@wordpress/element");
|
|
16
15
|
var _compose = require("@wordpress/compose");
|
|
16
|
+
var _preferences = require("@wordpress/preferences");
|
|
17
|
+
var _documentTools = _interopRequireDefault(require("./document-tools"));
|
|
17
18
|
var _saveButton = _interopRequireDefault(require("../save-button"));
|
|
18
|
-
var _undo = _interopRequireDefault(require("./undo-redo/undo"));
|
|
19
|
-
var _redo = _interopRequireDefault(require("./undo-redo/redo"));
|
|
20
19
|
var _moreMenu = _interopRequireDefault(require("../more-menu"));
|
|
21
|
-
var _useLastSelectedWidgetArea = _interopRequireDefault(require("../../hooks/use-last-selected-widget-area"));
|
|
22
|
-
var _store = require("../../store");
|
|
23
20
|
var _lockUnlock = require("../../lock-unlock");
|
|
24
21
|
/**
|
|
25
22
|
* WordPress dependencies
|
|
@@ -30,101 +27,37 @@ var _lockUnlock = require("../../lock-unlock");
|
|
|
30
27
|
*/
|
|
31
28
|
|
|
32
29
|
const {
|
|
33
|
-
|
|
30
|
+
BlockContextualToolbar
|
|
34
31
|
} = (0, _lockUnlock.unlock)(_blockEditor.privateApis);
|
|
35
32
|
function Header({
|
|
36
33
|
setListViewToggleElement
|
|
37
34
|
}) {
|
|
38
|
-
const
|
|
39
|
-
const
|
|
40
|
-
const widgetAreaClientId = (0, _useLastSelectedWidgetArea.default)();
|
|
41
|
-
const isLastSelectedWidgetAreaOpen = (0, _data.useSelect)(select => select(_store.store).getIsWidgetAreaOpen(widgetAreaClientId), [widgetAreaClientId]);
|
|
42
|
-
const {
|
|
43
|
-
isInserterOpen,
|
|
44
|
-
isListViewOpen
|
|
45
|
-
} = (0, _data.useSelect)(select => {
|
|
46
|
-
const {
|
|
47
|
-
isInserterOpened,
|
|
48
|
-
isListViewOpened
|
|
49
|
-
} = select(_store.store);
|
|
50
|
-
return {
|
|
51
|
-
isInserterOpen: isInserterOpened(),
|
|
52
|
-
isListViewOpen: isListViewOpened()
|
|
53
|
-
};
|
|
54
|
-
}, []);
|
|
55
|
-
const {
|
|
56
|
-
setIsWidgetAreaOpen,
|
|
57
|
-
setIsInserterOpened,
|
|
58
|
-
setIsListViewOpened
|
|
59
|
-
} = (0, _data.useDispatch)(_store.store);
|
|
60
|
-
const {
|
|
61
|
-
selectBlock
|
|
62
|
-
} = (0, _data.useDispatch)(_blockEditor.store);
|
|
63
|
-
const handleClick = () => {
|
|
64
|
-
if (isInserterOpen) {
|
|
65
|
-
// Focusing the inserter button closes the inserter popover.
|
|
66
|
-
setIsInserterOpened(false);
|
|
67
|
-
} else {
|
|
68
|
-
if (!isLastSelectedWidgetAreaOpen) {
|
|
69
|
-
// Select the last selected block if hasn't already.
|
|
70
|
-
selectBlock(widgetAreaClientId);
|
|
71
|
-
// Open the last selected widget area when opening the inserter.
|
|
72
|
-
setIsWidgetAreaOpen(widgetAreaClientId, true);
|
|
73
|
-
}
|
|
74
|
-
// The DOM updates resulting from selectBlock() and setIsInserterOpened() calls are applied the
|
|
75
|
-
// same tick and pretty much in a random order. The inserter is closed if any other part of the
|
|
76
|
-
// app receives focus. If selectBlock() happens to take effect after setIsInserterOpened() then
|
|
77
|
-
// the inserter is visible for a brief moment and then gets auto-closed due to focus moving to
|
|
78
|
-
// the selected block.
|
|
79
|
-
window.requestAnimationFrame(() => setIsInserterOpened(true));
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
const toggleListView = (0, _element.useCallback)(() => setIsListViewOpened(!isListViewOpen), [setIsListViewOpened, isListViewOpen]);
|
|
35
|
+
const isLargeViewport = (0, _compose.useViewportMatch)('medium');
|
|
36
|
+
const blockToolbarRef = (0, _element.useRef)();
|
|
83
37
|
const {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
}
|
|
88
|
-
// If there's a block toolbar to be focused, disable the focus shortcut for the document toolbar.
|
|
89
|
-
// There's a fixed block toolbar when the fixed toolbar option is enabled or when the browser width is less than the large viewport.
|
|
90
|
-
const blockToolbarCanBeFocused = shouldShowContextualToolbar || canFocusHiddenToolbar || fixedToolbarCanBeFocused;
|
|
38
|
+
hasFixedToolbar
|
|
39
|
+
} = (0, _data.useSelect)(select => ({
|
|
40
|
+
hasFixedToolbar: !!select(_preferences.store).get('core/edit-widgets', 'fixedToolbar')
|
|
41
|
+
}), []);
|
|
91
42
|
return (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)("div", {
|
|
92
43
|
className: "edit-widgets-header"
|
|
93
44
|
}, (0, _react.createElement)("div", {
|
|
94
45
|
className: "edit-widgets-header__navigable-toolbar-wrapper"
|
|
95
|
-
},
|
|
46
|
+
}, isLargeViewport && (0, _react.createElement)("h1", {
|
|
96
47
|
className: "edit-widgets-header__title"
|
|
97
|
-
}, (0, _i18n.__)('Widgets')), !
|
|
48
|
+
}, (0, _i18n.__)('Widgets')), !isLargeViewport && (0, _react.createElement)(_components.VisuallyHidden, {
|
|
98
49
|
as: "h1",
|
|
99
50
|
className: "edit-widgets-header__title"
|
|
100
|
-
}, (0, _i18n.__)('Widgets')), (0, _react.createElement)(
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}, (0, _react.createElement)(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
onMouseDown: event => {
|
|
111
|
-
event.preventDefault();
|
|
112
|
-
},
|
|
113
|
-
onClick: handleClick,
|
|
114
|
-
icon: _icons.plus
|
|
115
|
-
/* translators: button label text should, if possible, be under 16
|
|
116
|
-
characters. */,
|
|
117
|
-
label: (0, _i18n._x)('Toggle block inserter', 'Generic label for block inserter button')
|
|
118
|
-
}), isMediumViewport && (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)(_undo.default, null), (0, _react.createElement)(_redo.default, null), (0, _react.createElement)(_components.ToolbarItem, {
|
|
119
|
-
as: _components.Button,
|
|
120
|
-
className: "edit-widgets-header-toolbar__list-view-toggle",
|
|
121
|
-
icon: _icons.listView,
|
|
122
|
-
isPressed: isListViewOpen
|
|
123
|
-
/* translators: button label text should, if possible, be under 16 characters. */,
|
|
124
|
-
label: (0, _i18n.__)('List View'),
|
|
125
|
-
onClick: toggleListView,
|
|
126
|
-
ref: setListViewToggleElement
|
|
127
|
-
})))), (0, _react.createElement)("div", {
|
|
51
|
+
}, (0, _i18n.__)('Widgets')), (0, _react.createElement)(_documentTools.default, {
|
|
52
|
+
setListViewToggleElement: setListViewToggleElement
|
|
53
|
+
}), hasFixedToolbar && isLargeViewport && (0, _react.createElement)(_react.Fragment, null, (0, _react.createElement)("div", {
|
|
54
|
+
className: "selected-block-tools-wrapper"
|
|
55
|
+
}, (0, _react.createElement)(BlockContextualToolbar, {
|
|
56
|
+
isFixed: true
|
|
57
|
+
})), (0, _react.createElement)(_components.Popover.Slot, {
|
|
58
|
+
ref: blockToolbarRef,
|
|
59
|
+
name: "block-toolbar"
|
|
60
|
+
}))), (0, _react.createElement)("div", {
|
|
128
61
|
className: "edit-widgets-header__actions"
|
|
129
62
|
}, (0, _react.createElement)(_saveButton.default, null), (0, _react.createElement)(_interface.PinnedItems.Slot, {
|
|
130
63
|
scope: "core/edit-widgets"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["_data","require","_i18n","_components","_blockEditor","_interface","_icons","_element","_compose","_saveButton","_interopRequireDefault","_undo","_redo","_moreMenu","_useLastSelectedWidgetArea","_store","_lockUnlock","useShouldContextualToolbarShow","unlock","blockEditorPrivateApis","Header","setListViewToggleElement","isMediumViewport","useViewportMatch","inserterButton","useRef","widgetAreaClientId","useLastSelectedWidgetArea","isLastSelectedWidgetAreaOpen","useSelect","select","editWidgetsStore","getIsWidgetAreaOpen","isInserterOpen","isListViewOpen","isInserterOpened","isListViewOpened","setIsWidgetAreaOpen","setIsInserterOpened","setIsListViewOpened","useDispatch","selectBlock","blockEditorStore","handleClick","window","requestAnimationFrame","toggleListView","useCallback","shouldShowContextualToolbar","canFocusHiddenToolbar","fixedToolbarCanBeFocused","blockToolbarCanBeFocused","_react","createElement","Fragment","className","__","VisuallyHidden","as","NavigableToolbar","shouldUseKeyboardFocusShortcut","ToolbarItem","ref","Button","variant","isPressed","onMouseDown","event","preventDefault","onClick","icon","plus","label","_x","default","listView","PinnedItems","Slot","scope","_default","exports"],"sources":["@wordpress/edit-widgets/src/components/header/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __, _x } from '@wordpress/i18n';\nimport { Button, ToolbarItem, VisuallyHidden } from '@wordpress/components';\nimport {\n\tNavigableToolbar,\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { PinnedItems } from '@wordpress/interface';\nimport { listView, plus } from '@wordpress/icons';\nimport { useCallback, useRef } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport SaveButton from '../save-button';\nimport UndoButton from './undo-redo/undo';\nimport RedoButton from './undo-redo/redo';\nimport MoreMenu from '../more-menu';\nimport useLastSelectedWidgetArea from '../../hooks/use-last-selected-widget-area';\nimport { store as editWidgetsStore } from '../../store';\nimport { unlock } from '../../lock-unlock';\n\nconst { useShouldContextualToolbarShow } = unlock( blockEditorPrivateApis );\n\nfunction Header( { setListViewToggleElement } ) {\n\tconst isMediumViewport = useViewportMatch( 'medium' );\n\tconst inserterButton = useRef();\n\tconst widgetAreaClientId = useLastSelectedWidgetArea();\n\tconst isLastSelectedWidgetAreaOpen = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editWidgetsStore ).getIsWidgetAreaOpen(\n\t\t\t\twidgetAreaClientId\n\t\t\t),\n\t\t[ widgetAreaClientId ]\n\t);\n\tconst { isInserterOpen, isListViewOpen } = useSelect( ( select ) => {\n\t\tconst { isInserterOpened, isListViewOpened } =\n\t\t\tselect( editWidgetsStore );\n\t\treturn {\n\t\t\tisInserterOpen: isInserterOpened(),\n\t\t\tisListViewOpen: isListViewOpened(),\n\t\t};\n\t}, [] );\n\tconst { setIsWidgetAreaOpen, setIsInserterOpened, setIsListViewOpened } =\n\t\tuseDispatch( editWidgetsStore );\n\tconst { selectBlock } = useDispatch( blockEditorStore );\n\tconst handleClick = () => {\n\t\tif ( isInserterOpen ) {\n\t\t\t// Focusing the inserter button closes the inserter popover.\n\t\t\tsetIsInserterOpened( false );\n\t\t} else {\n\t\t\tif ( ! isLastSelectedWidgetAreaOpen ) {\n\t\t\t\t// Select the last selected block if hasn't already.\n\t\t\t\tselectBlock( widgetAreaClientId );\n\t\t\t\t// Open the last selected widget area when opening the inserter.\n\t\t\t\tsetIsWidgetAreaOpen( widgetAreaClientId, true );\n\t\t\t}\n\t\t\t// The DOM updates resulting from selectBlock() and setIsInserterOpened() calls are applied the\n\t\t\t// same tick and pretty much in a random order. The inserter is closed if any other part of the\n\t\t\t// app receives focus. If selectBlock() happens to take effect after setIsInserterOpened() then\n\t\t\t// the inserter is visible for a brief moment and then gets auto-closed due to focus moving to\n\t\t\t// the selected block.\n\t\t\twindow.requestAnimationFrame( () => setIsInserterOpened( true ) );\n\t\t}\n\t};\n\n\tconst toggleListView = useCallback(\n\t\t() => setIsListViewOpened( ! isListViewOpen ),\n\t\t[ setIsListViewOpened, isListViewOpen ]\n\t);\n\n\tconst {\n\t\tshouldShowContextualToolbar,\n\t\tcanFocusHiddenToolbar,\n\t\tfixedToolbarCanBeFocused,\n\t} = useShouldContextualToolbarShow();\n\t// If there's a block toolbar to be focused, disable the focus shortcut for the document toolbar.\n\t// There's a fixed block toolbar when the fixed toolbar option is enabled or when the browser width is less than the large viewport.\n\tconst blockToolbarCanBeFocused =\n\t\tshouldShowContextualToolbar ||\n\t\tcanFocusHiddenToolbar ||\n\t\tfixedToolbarCanBeFocused;\n\n\treturn (\n\t\t<>\n\t\t\t<div className=\"edit-widgets-header\">\n\t\t\t\t<div className=\"edit-widgets-header__navigable-toolbar-wrapper\">\n\t\t\t\t\t{ isMediumViewport && (\n\t\t\t\t\t\t<h1 className=\"edit-widgets-header__title\">\n\t\t\t\t\t\t\t{ __( 'Widgets' ) }\n\t\t\t\t\t\t</h1>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ! isMediumViewport && (\n\t\t\t\t\t\t<VisuallyHidden\n\t\t\t\t\t\t\tas=\"h1\"\n\t\t\t\t\t\t\tclassName=\"edit-widgets-header__title\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Widgets' ) }\n\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t) }\n\t\t\t\t\t<NavigableToolbar\n\t\t\t\t\t\tclassName=\"edit-widgets-header-toolbar\"\n\t\t\t\t\t\taria-label={ __( 'Document tools' ) }\n\t\t\t\t\t\tshouldUseKeyboardFocusShortcut={\n\t\t\t\t\t\t\t! blockToolbarCanBeFocused\n\t\t\t\t\t\t}\n\t\t\t\t\t>\n\t\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\t\tref={ inserterButton }\n\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\tclassName=\"edit-widgets-header-toolbar__inserter-toggle\"\n\t\t\t\t\t\t\tvariant=\"primary\"\n\t\t\t\t\t\t\tisPressed={ isInserterOpen }\n\t\t\t\t\t\t\tonMouseDown={ ( event ) => {\n\t\t\t\t\t\t\t\tevent.preventDefault();\n\t\t\t\t\t\t\t} }\n\t\t\t\t\t\t\tonClick={ handleClick }\n\t\t\t\t\t\t\ticon={ plus }\n\t\t\t\t\t\t\t/* translators: button label text should, if possible, be under 16\n\t\t\t\t\tcharacters. */\n\t\t\t\t\t\t\tlabel={ _x(\n\t\t\t\t\t\t\t\t'Toggle block inserter',\n\t\t\t\t\t\t\t\t'Generic label for block inserter button'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t{ isMediumViewport && (\n\t\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t\t<UndoButton />\n\t\t\t\t\t\t\t\t<RedoButton />\n\t\t\t\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\t\t\t\tclassName=\"edit-widgets-header-toolbar__list-view-toggle\"\n\t\t\t\t\t\t\t\t\ticon={ listView }\n\t\t\t\t\t\t\t\t\tisPressed={ isListViewOpen }\n\t\t\t\t\t\t\t\t\t/* translators: button label text should, if possible, be under 16 characters. */\n\t\t\t\t\t\t\t\t\tlabel={ __( 'List View' ) }\n\t\t\t\t\t\t\t\t\tonClick={ toggleListView }\n\t\t\t\t\t\t\t\t\tref={ setListViewToggleElement }\n\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t</>\n\t\t\t\t\t\t) }\n\t\t\t\t\t</NavigableToolbar>\n\t\t\t\t</div>\n\t\t\t\t<div className=\"edit-widgets-header__actions\">\n\t\t\t\t\t<SaveButton />\n\t\t\t\t\t<PinnedIt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S,EAAC,+CAA+C;IACzDe,IAAI,EAAGK,eAAU;IACjBV,SAAS,EAAG/B;IACZ;IACAsC,KAAK,EAAG,IAAAhB,QAAE,EAAE,WAAY,CAAG;IAC3Ba,OAAO,EAAGvB,cAAgB;IAC1BgB,GAAG,EAAGzC;EAA0B,CAChC,CACA,CAEc,CACd,CAAC,EACN,IAAA+B,MAAA,CAAAC,aAAA;IAAKE,SAAS,EAAC;EAA8B,GAC5C,IAAAH,MAAA,CAAAC,aAAA,EAAC5C,WAAA,CAAAiE,OAAU,MAAE,CAAC,EACd,IAAAtB,MAAA,CAAAC,aAAA,EAAChD,UAAA,CAAAuE,WAAW,CAACC,IAAI;IAACC,KAAK,EAAC;EAAmB,CAAE,CAAC,EAC9C,IAAA1B,MAAA,CAAAC,aAAA,EAACxC,SAAA,CAAA6D,OAAQ,MAAE,CACP,CACD,CACJ,CAAC;AAEL;AAAC,IAAAK,QAAA,GAEc3D,MAAM;AAAA4D,OAAA,CAAAN,OAAA,GAAAK,QAAA"}
|
|
1
|
+
{"version":3,"names":["_blockEditor","require","_data","_element","_i18n","_components","_interface","_compose","_preferences","_documentTools","_interopRequireDefault","_saveButton","_moreMenu","_lockUnlock","BlockContextualToolbar","unlock","blockEditorPrivateApis","Header","setListViewToggleElement","isLargeViewport","useViewportMatch","blockToolbarRef","useRef","hasFixedToolbar","useSelect","select","preferencesStore","get","_react","createElement","Fragment","className","__","VisuallyHidden","as","default","isFixed","Popover","Slot","ref","name","PinnedItems","scope","_default","exports"],"sources":["@wordpress/edit-widgets/src/components/header/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';\nimport { useSelect } from '@wordpress/data';\nimport { useRef } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\nimport { Popover, VisuallyHidden } from '@wordpress/components';\nimport { PinnedItems } from '@wordpress/interface';\nimport { useViewportMatch } from '@wordpress/compose';\nimport { store as preferencesStore } from '@wordpress/preferences';\n\n/**\n * Internal dependencies\n */\nimport DocumentTools from './document-tools';\nimport SaveButton from '../save-button';\nimport MoreMenu from '../more-menu';\nimport { unlock } from '../../lock-unlock';\n\nconst { BlockContextualToolbar } = unlock( blockEditorPrivateApis );\n\nfunction Header( { setListViewToggleElement } ) {\n\tconst isLargeViewport = useViewportMatch( 'medium' );\n\tconst blockToolbarRef = useRef();\n\tconst { hasFixedToolbar } = useSelect(\n\t\t( select ) => ( {\n\t\t\thasFixedToolbar: !! select( preferencesStore ).get(\n\t\t\t\t'core/edit-widgets',\n\t\t\t\t'fixedToolbar'\n\t\t\t),\n\t\t} ),\n\t\t[]\n\t);\n\n\treturn (\n\t\t<>\n\t\t\t<div className=\"edit-widgets-header\">\n\t\t\t\t<div className=\"edit-widgets-header__navigable-toolbar-wrapper\">\n\t\t\t\t\t{ isLargeViewport && (\n\t\t\t\t\t\t<h1 className=\"edit-widgets-header__title\">\n\t\t\t\t\t\t\t{ __( 'Widgets' ) }\n\t\t\t\t\t\t</h1>\n\t\t\t\t\t) }\n\t\t\t\t\t{ ! isLargeViewport && (\n\t\t\t\t\t\t<VisuallyHidden\n\t\t\t\t\t\t\tas=\"h1\"\n\t\t\t\t\t\t\tclassName=\"edit-widgets-header__title\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'Widgets' ) }\n\t\t\t\t\t\t</VisuallyHidden>\n\t\t\t\t\t) }\n\t\t\t\t\t<DocumentTools\n\t\t\t\t\t\tsetListViewToggleElement={ setListViewToggleElement }\n\t\t\t\t\t/>\n\t\t\t\t\t{ hasFixedToolbar && isLargeViewport && (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t<div className=\"selected-block-tools-wrapper\">\n\t\t\t\t\t\t\t\t<BlockContextualToolbar isFixed />\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<Popover.Slot\n\t\t\t\t\t\t\t\tref={ blockToolbarRef }\n\t\t\t\t\t\t\t\tname=\"block-toolbar\"\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t</div>\n\t\t\t\t<div className=\"edit-widgets-header__actions\">\n\t\t\t\t\t<SaveButton />\n\t\t\t\t\t<PinnedItems.Slot scope=\"core/edit-widgets\" />\n\t\t\t\t\t<MoreMenu />\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</>\n\t);\n}\n\nexport default Header;\n"],"mappings":";;;;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AACA,IAAAI,WAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AACA,IAAAM,QAAA,GAAAN,OAAA;AACA,IAAAO,YAAA,GAAAP,OAAA;AAKA,IAAAQ,cAAA,GAAAC,sBAAA,CAAAT,OAAA;AACA,IAAAU,WAAA,GAAAD,sBAAA,CAAAT,OAAA;AACA,IAAAW,SAAA,GAAAF,sBAAA,CAAAT,OAAA;AACA,IAAAY,WAAA,GAAAZ,OAAA;AAlBA;AACA;AACA;;AAUA;AACA;AACA;;AAMA,MAAM;EAAEa;AAAuB,CAAC,GAAG,IAAAC,kBAAM,EAAEC,wBAAuB,CAAC;AAEnE,SAASC,MAAMA,CAAE;EAAEC;AAAyB,CAAC,EAAG;EAC/C,MAAMC,eAAe,GAAG,IAAAC,yBAAgB,EAAE,QAAS,CAAC;EACpD,MAAMC,eAAe,GAAG,IAAAC,eAAM,EAAC,CAAC;EAChC,MAAM;IAAEC;EAAgB,CAAC,GAAG,IAAAC,eAAS,EAClCC,MAAM,KAAQ;IACfF,eAAe,EAAE,CAAC,CAAEE,MAAM,CAAEC,kBAAiB,CAAC,CAACC,GAAG,CACjD,mBAAmB,EACnB,cACD;EACD,CAAC,CAAE,EACH,EACD,CAAC;EAED,OACC,IAAAC,MAAA,CAAAC,aAAA,EAAAD,MAAA,CAAAE,QAAA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AQ,QAAA,GAEc1B,MAAM;AAAA2B,OAAA,CAAAT,OAAA,GAAAQ,QAAA"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { createElement, Fragment } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* WordPress dependencies
|
|
4
|
+
*/
|
|
5
|
+
import { useSelect, useDispatch } from '@wordpress/data';
|
|
6
|
+
import { __, _x } from '@wordpress/i18n';
|
|
7
|
+
import { Button, ToolbarItem } from '@wordpress/components';
|
|
8
|
+
import { NavigableToolbar, store as blockEditorStore, privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
9
|
+
import { listView, plus } from '@wordpress/icons';
|
|
10
|
+
import { useCallback, useRef } from '@wordpress/element';
|
|
11
|
+
import { useViewportMatch } from '@wordpress/compose';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
16
|
+
import UndoButton from '../undo-redo/undo';
|
|
17
|
+
import RedoButton from '../undo-redo/redo';
|
|
18
|
+
import useLastSelectedWidgetArea from '../../../hooks/use-last-selected-widget-area';
|
|
19
|
+
import { store as editWidgetsStore } from '../../../store';
|
|
20
|
+
import { unlock } from '../../../lock-unlock';
|
|
21
|
+
const {
|
|
22
|
+
useShouldContextualToolbarShow
|
|
23
|
+
} = unlock(blockEditorPrivateApis);
|
|
24
|
+
function DocumentTools({
|
|
25
|
+
setListViewToggleElement
|
|
26
|
+
}) {
|
|
27
|
+
const isMediumViewport = useViewportMatch('medium');
|
|
28
|
+
const inserterButton = useRef();
|
|
29
|
+
const widgetAreaClientId = useLastSelectedWidgetArea();
|
|
30
|
+
const isLastSelectedWidgetAreaOpen = useSelect(select => select(editWidgetsStore).getIsWidgetAreaOpen(widgetAreaClientId), [widgetAreaClientId]);
|
|
31
|
+
const {
|
|
32
|
+
isInserterOpen,
|
|
33
|
+
isListViewOpen
|
|
34
|
+
} = useSelect(select => {
|
|
35
|
+
const {
|
|
36
|
+
isInserterOpened,
|
|
37
|
+
isListViewOpened
|
|
38
|
+
} = select(editWidgetsStore);
|
|
39
|
+
return {
|
|
40
|
+
isInserterOpen: isInserterOpened(),
|
|
41
|
+
isListViewOpen: isListViewOpened()
|
|
42
|
+
};
|
|
43
|
+
}, []);
|
|
44
|
+
const {
|
|
45
|
+
setIsWidgetAreaOpen,
|
|
46
|
+
setIsInserterOpened,
|
|
47
|
+
setIsListViewOpened
|
|
48
|
+
} = useDispatch(editWidgetsStore);
|
|
49
|
+
const {
|
|
50
|
+
selectBlock
|
|
51
|
+
} = useDispatch(blockEditorStore);
|
|
52
|
+
const handleClick = () => {
|
|
53
|
+
if (isInserterOpen) {
|
|
54
|
+
// Focusing the inserter button closes the inserter popover.
|
|
55
|
+
setIsInserterOpened(false);
|
|
56
|
+
} else {
|
|
57
|
+
if (!isLastSelectedWidgetAreaOpen) {
|
|
58
|
+
// Select the last selected block if hasn't already.
|
|
59
|
+
selectBlock(widgetAreaClientId);
|
|
60
|
+
// Open the last selected widget area when opening the inserter.
|
|
61
|
+
setIsWidgetAreaOpen(widgetAreaClientId, true);
|
|
62
|
+
}
|
|
63
|
+
// The DOM updates resulting from selectBlock() and setIsInserterOpened() calls are applied the
|
|
64
|
+
// same tick and pretty much in a random order. The inserter is closed if any other part of the
|
|
65
|
+
// app receives focus. If selectBlock() happens to take effect after setIsInserterOpened() then
|
|
66
|
+
// the inserter is visible for a brief moment and then gets auto-closed due to focus moving to
|
|
67
|
+
// the selected block.
|
|
68
|
+
window.requestAnimationFrame(() => setIsInserterOpened(true));
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const toggleListView = useCallback(() => setIsListViewOpened(!isListViewOpen), [setIsListViewOpened, isListViewOpen]);
|
|
72
|
+
const {
|
|
73
|
+
shouldShowContextualToolbar,
|
|
74
|
+
canFocusHiddenToolbar,
|
|
75
|
+
fixedToolbarCanBeFocused
|
|
76
|
+
} = useShouldContextualToolbarShow();
|
|
77
|
+
// If there's a block toolbar to be focused, disable the focus shortcut for the document toolbar.
|
|
78
|
+
// There's a fixed block toolbar when the fixed toolbar option is enabled or when the browser width is less than the large viewport.
|
|
79
|
+
const blockToolbarCanBeFocused = shouldShowContextualToolbar || canFocusHiddenToolbar || fixedToolbarCanBeFocused;
|
|
80
|
+
return createElement(NavigableToolbar, {
|
|
81
|
+
className: "edit-widgets-header-toolbar",
|
|
82
|
+
"aria-label": __('Document tools'),
|
|
83
|
+
shouldUseKeyboardFocusShortcut: !blockToolbarCanBeFocused
|
|
84
|
+
}, createElement(ToolbarItem, {
|
|
85
|
+
ref: inserterButton,
|
|
86
|
+
as: Button,
|
|
87
|
+
className: "edit-widgets-header-toolbar__inserter-toggle",
|
|
88
|
+
variant: "primary",
|
|
89
|
+
isPressed: isInserterOpen,
|
|
90
|
+
onMouseDown: event => {
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
},
|
|
93
|
+
onClick: handleClick,
|
|
94
|
+
icon: plus
|
|
95
|
+
/* translators: button label text should, if possible, be under 16
|
|
96
|
+
characters. */,
|
|
97
|
+
label: _x('Toggle block inserter', 'Generic label for block inserter button')
|
|
98
|
+
}), isMediumViewport && createElement(Fragment, null, createElement(UndoButton, null), createElement(RedoButton, null), createElement(ToolbarItem, {
|
|
99
|
+
as: Button,
|
|
100
|
+
className: "edit-widgets-header-toolbar__list-view-toggle",
|
|
101
|
+
icon: listView,
|
|
102
|
+
isPressed: isListViewOpen
|
|
103
|
+
/* translators: button label text should, if possible, be under 16 characters. */,
|
|
104
|
+
label: __('List View'),
|
|
105
|
+
onClick: toggleListView,
|
|
106
|
+
ref: setListViewToggleElement
|
|
107
|
+
})));
|
|
108
|
+
}
|
|
109
|
+
export default DocumentTools;
|
|
110
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useSelect","useDispatch","__","_x","Button","ToolbarItem","NavigableToolbar","store","blockEditorStore","privateApis","blockEditorPrivateApis","listView","plus","useCallback","useRef","useViewportMatch","UndoButton","RedoButton","useLastSelectedWidgetArea","editWidgetsStore","unlock","useShouldContextualToolbarShow","DocumentTools","setListViewToggleElement","isMediumViewport","inserterButton","widgetAreaClientId","isLastSelectedWidgetAreaOpen","select","getIsWidgetAreaOpen","isInserterOpen","isListViewOpen","isInserterOpened","isListViewOpened","setIsWidgetAreaOpen","setIsInserterOpened","setIsListViewOpened","selectBlock","handleClick","window","requestAnimationFrame","toggleListView","shouldShowContextualToolbar","canFocusHiddenToolbar","fixedToolbarCanBeFocused","blockToolbarCanBeFocused","createElement","className","shouldUseKeyboardFocusShortcut","ref","as","variant","isPressed","onMouseDown","event","preventDefault","onClick","icon","label","Fragment"],"sources":["@wordpress/edit-widgets/src/components/header/document-tools/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useSelect, useDispatch } from '@wordpress/data';\nimport { __, _x } from '@wordpress/i18n';\nimport { Button, ToolbarItem } from '@wordpress/components';\nimport {\n\tNavigableToolbar,\n\tstore as blockEditorStore,\n\tprivateApis as blockEditorPrivateApis,\n} from '@wordpress/block-editor';\nimport { listView, plus } from '@wordpress/icons';\nimport { useCallback, useRef } from '@wordpress/element';\nimport { useViewportMatch } from '@wordpress/compose';\n\n/**\n * Internal dependencies\n */\nimport UndoButton from '../undo-redo/undo';\nimport RedoButton from '../undo-redo/redo';\nimport useLastSelectedWidgetArea from '../../../hooks/use-last-selected-widget-area';\nimport { store as editWidgetsStore } from '../../../store';\nimport { unlock } from '../../../lock-unlock';\n\nconst { useShouldContextualToolbarShow } = unlock( blockEditorPrivateApis );\n\nfunction DocumentTools( { setListViewToggleElement } ) {\n\tconst isMediumViewport = useViewportMatch( 'medium' );\n\tconst inserterButton = useRef();\n\tconst widgetAreaClientId = useLastSelectedWidgetArea();\n\tconst isLastSelectedWidgetAreaOpen = useSelect(\n\t\t( select ) =>\n\t\t\tselect( editWidgetsStore ).getIsWidgetAreaOpen(\n\t\t\t\twidgetAreaClientId\n\t\t\t),\n\t\t[ widgetAreaClientId ]\n\t);\n\tconst { isInserterOpen, isListViewOpen } = useSelect( ( select ) => {\n\t\tconst { isInserterOpened, isListViewOpened } =\n\t\t\tselect( editWidgetsStore );\n\t\treturn {\n\t\t\tisInserterOpen: isInserterOpened(),\n\t\t\tisListViewOpen: isListViewOpened(),\n\t\t};\n\t}, [] );\n\tconst { setIsWidgetAreaOpen, setIsInserterOpened, setIsListViewOpened } =\n\t\tuseDispatch( editWidgetsStore );\n\tconst { selectBlock } = useDispatch( blockEditorStore );\n\tconst handleClick = () => {\n\t\tif ( isInserterOpen ) {\n\t\t\t// Focusing the inserter button closes the inserter popover.\n\t\t\tsetIsInserterOpened( false );\n\t\t} else {\n\t\t\tif ( ! isLastSelectedWidgetAreaOpen ) {\n\t\t\t\t// Select the last selected block if hasn't already.\n\t\t\t\tselectBlock( widgetAreaClientId );\n\t\t\t\t// Open the last selected widget area when opening the inserter.\n\t\t\t\tsetIsWidgetAreaOpen( widgetAreaClientId, true );\n\t\t\t}\n\t\t\t// The DOM updates resulting from selectBlock() and setIsInserterOpened() calls are applied the\n\t\t\t// same tick and pretty much in a random order. The inserter is closed if any other part of the\n\t\t\t// app receives focus. If selectBlock() happens to take effect after setIsInserterOpened() then\n\t\t\t// the inserter is visible for a brief moment and then gets auto-closed due to focus moving to\n\t\t\t// the selected block.\n\t\t\twindow.requestAnimationFrame( () => setIsInserterOpened( true ) );\n\t\t}\n\t};\n\n\tconst toggleListView = useCallback(\n\t\t() => setIsListViewOpened( ! isListViewOpen ),\n\t\t[ setIsListViewOpened, isListViewOpen ]\n\t);\n\n\tconst {\n\t\tshouldShowContextualToolbar,\n\t\tcanFocusHiddenToolbar,\n\t\tfixedToolbarCanBeFocused,\n\t} = useShouldContextualToolbarShow();\n\t// If there's a block toolbar to be focused, disable the focus shortcut for the document toolbar.\n\t// There's a fixed block toolbar when the fixed toolbar option is enabled or when the browser width is less than the large viewport.\n\tconst blockToolbarCanBeFocused =\n\t\tshouldShowContextualToolbar ||\n\t\tcanFocusHiddenToolbar ||\n\t\tfixedToolbarCanBeFocused;\n\n\treturn (\n\t\t<NavigableToolbar\n\t\t\tclassName=\"edit-widgets-header-toolbar\"\n\t\t\taria-label={ __( 'Document tools' ) }\n\t\t\tshouldUseKeyboardFocusShortcut={ ! blockToolbarCanBeFocused }\n\t\t>\n\t\t\t<ToolbarItem\n\t\t\t\tref={ inserterButton }\n\t\t\t\tas={ Button }\n\t\t\t\tclassName=\"edit-widgets-header-toolbar__inserter-toggle\"\n\t\t\t\tvariant=\"primary\"\n\t\t\t\tisPressed={ isInserterOpen }\n\t\t\t\tonMouseDown={ ( event ) => {\n\t\t\t\t\tevent.preventDefault();\n\t\t\t\t} }\n\t\t\t\tonClick={ handleClick }\n\t\t\t\ticon={ plus }\n\t\t\t\t/* translators: button label text should, if possible, be under 16\n\t\t\t\t\tcharacters. */\n\t\t\t\tlabel={ _x(\n\t\t\t\t\t'Toggle block inserter',\n\t\t\t\t\t'Generic label for block inserter button'\n\t\t\t\t) }\n\t\t\t/>\n\t\t\t{ isMediumViewport && (\n\t\t\t\t<>\n\t\t\t\t\t<UndoButton />\n\t\t\t\t\t<RedoButton />\n\t\t\t\t\t<ToolbarItem\n\t\t\t\t\t\tas={ Button }\n\t\t\t\t\t\tclassName=\"edit-widgets-header-toolbar__list-view-toggle\"\n\t\t\t\t\t\ticon={ listView }\n\t\t\t\t\t\tisPressed={ isListViewOpen }\n\t\t\t\t\t\t/* translators: button label text should, if possible, be under 16 characters. */\n\t\t\t\t\t\tlabel={ __( 'List View' ) }\n\t\t\t\t\t\tonClick={ toggleListView }\n\t\t\t\t\t\tref={ setListViewToggleElement }\n\t\t\t\t\t/>\n\t\t\t\t</>\n\t\t\t) }\n\t\t</NavigableToolbar>\n\t);\n}\n\nexport default DocumentTools;\n"],"mappings":";AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,WAAW,QAAQ,iBAAiB;AACxD,SAASC,EAAE,EAAEC,EAAE,QAAQ,iBAAiB;AACxC,SAASC,MAAM,EAA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IAEA8C,KAAK,EAAGvD,EAAE,CACT,uBAAuB,EACvB,yCACD;EAAG,CACH,CAAC,EACAqB,gBAAgB,IACjBsB,aAAA,CAAAa,QAAA,QACCb,aAAA,CAAC9B,UAAU,MAAE,CAAC,EACd8B,aAAA,CAAC7B,UAAU,MAAE,CAAC,EACd6B,aAAA,CAACzC,WAAW;IACX6C,EAAE,EAAG9C,MAAQ;IACb2C,SAAS,EAAC,+CAA+C;IACzDU,IAAI,EAAG9C,QAAU;IACjByC,SAAS,EAAGrB;IACZ;IACA2B,KAAK,EAAGxD,EAAE,CAAE,WAAY,CAAG;IAC3BsD,OAAO,EAAGf,cAAgB;IAC1BQ,GAAG,EAAG1B;EAA0B,CAChC,CACA,CAEc,CAAC;AAErB;AAEA,eAAeD,aAAa"}
|
|
@@ -2,121 +2,54 @@ import { createElement, Fragment } from "react";
|
|
|
2
2
|
/**
|
|
3
3
|
* WordPress dependencies
|
|
4
4
|
*/
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
5
|
+
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
|
|
6
|
+
import { useSelect } from '@wordpress/data';
|
|
7
|
+
import { useRef } from '@wordpress/element';
|
|
8
|
+
import { __ } from '@wordpress/i18n';
|
|
9
|
+
import { Popover, VisuallyHidden } from '@wordpress/components';
|
|
9
10
|
import { PinnedItems } from '@wordpress/interface';
|
|
10
|
-
import { listView, plus } from '@wordpress/icons';
|
|
11
|
-
import { useCallback, useRef } from '@wordpress/element';
|
|
12
11
|
import { useViewportMatch } from '@wordpress/compose';
|
|
12
|
+
import { store as preferencesStore } from '@wordpress/preferences';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Internal dependencies
|
|
16
16
|
*/
|
|
17
|
+
import DocumentTools from './document-tools';
|
|
17
18
|
import SaveButton from '../save-button';
|
|
18
|
-
import UndoButton from './undo-redo/undo';
|
|
19
|
-
import RedoButton from './undo-redo/redo';
|
|
20
19
|
import MoreMenu from '../more-menu';
|
|
21
|
-
import useLastSelectedWidgetArea from '../../hooks/use-last-selected-widget-area';
|
|
22
|
-
import { store as editWidgetsStore } from '../../store';
|
|
23
20
|
import { unlock } from '../../lock-unlock';
|
|
24
21
|
const {
|
|
25
|
-
|
|
22
|
+
BlockContextualToolbar
|
|
26
23
|
} = unlock(blockEditorPrivateApis);
|
|
27
24
|
function Header({
|
|
28
25
|
setListViewToggleElement
|
|
29
26
|
}) {
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const widgetAreaClientId = useLastSelectedWidgetArea();
|
|
33
|
-
const isLastSelectedWidgetAreaOpen = useSelect(select => select(editWidgetsStore).getIsWidgetAreaOpen(widgetAreaClientId), [widgetAreaClientId]);
|
|
27
|
+
const isLargeViewport = useViewportMatch('medium');
|
|
28
|
+
const blockToolbarRef = useRef();
|
|
34
29
|
const {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
isInserterOpened,
|
|
40
|
-
isListViewOpened
|
|
41
|
-
} = select(editWidgetsStore);
|
|
42
|
-
return {
|
|
43
|
-
isInserterOpen: isInserterOpened(),
|
|
44
|
-
isListViewOpen: isListViewOpened()
|
|
45
|
-
};
|
|
46
|
-
}, []);
|
|
47
|
-
const {
|
|
48
|
-
setIsWidgetAreaOpen,
|
|
49
|
-
setIsInserterOpened,
|
|
50
|
-
setIsListViewOpened
|
|
51
|
-
} = useDispatch(editWidgetsStore);
|
|
52
|
-
const {
|
|
53
|
-
selectBlock
|
|
54
|
-
} = useDispatch(blockEditorStore);
|
|
55
|
-
const handleClick = () => {
|
|
56
|
-
if (isInserterOpen) {
|
|
57
|
-
// Focusing the inserter button closes the inserter popover.
|
|
58
|
-
setIsInserterOpened(false);
|
|
59
|
-
} else {
|
|
60
|
-
if (!isLastSelectedWidgetAreaOpen) {
|
|
61
|
-
// Select the last selected block if hasn't already.
|
|
62
|
-
selectBlock(widgetAreaClientId);
|
|
63
|
-
// Open the last selected widget area when opening the inserter.
|
|
64
|
-
setIsWidgetAreaOpen(widgetAreaClientId, true);
|
|
65
|
-
}
|
|
66
|
-
// The DOM updates resulting from selectBlock() and setIsInserterOpened() calls are applied the
|
|
67
|
-
// same tick and pretty much in a random order. The inserter is closed if any other part of the
|
|
68
|
-
// app receives focus. If selectBlock() happens to take effect after setIsInserterOpened() then
|
|
69
|
-
// the inserter is visible for a brief moment and then gets auto-closed due to focus moving to
|
|
70
|
-
// the selected block.
|
|
71
|
-
window.requestAnimationFrame(() => setIsInserterOpened(true));
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
const toggleListView = useCallback(() => setIsListViewOpened(!isListViewOpen), [setIsListViewOpened, isListViewOpen]);
|
|
75
|
-
const {
|
|
76
|
-
shouldShowContextualToolbar,
|
|
77
|
-
canFocusHiddenToolbar,
|
|
78
|
-
fixedToolbarCanBeFocused
|
|
79
|
-
} = useShouldContextualToolbarShow();
|
|
80
|
-
// If there's a block toolbar to be focused, disable the focus shortcut for the document toolbar.
|
|
81
|
-
// There's a fixed block toolbar when the fixed toolbar option is enabled or when the browser width is less than the large viewport.
|
|
82
|
-
const blockToolbarCanBeFocused = shouldShowContextualToolbar || canFocusHiddenToolbar || fixedToolbarCanBeFocused;
|
|
30
|
+
hasFixedToolbar
|
|
31
|
+
} = useSelect(select => ({
|
|
32
|
+
hasFixedToolbar: !!select(preferencesStore).get('core/edit-widgets', 'fixedToolbar')
|
|
33
|
+
}), []);
|
|
83
34
|
return createElement(Fragment, null, createElement("div", {
|
|
84
35
|
className: "edit-widgets-header"
|
|
85
36
|
}, createElement("div", {
|
|
86
37
|
className: "edit-widgets-header__navigable-toolbar-wrapper"
|
|
87
|
-
},
|
|
38
|
+
}, isLargeViewport && createElement("h1", {
|
|
88
39
|
className: "edit-widgets-header__title"
|
|
89
|
-
}, __('Widgets')), !
|
|
40
|
+
}, __('Widgets')), !isLargeViewport && createElement(VisuallyHidden, {
|
|
90
41
|
as: "h1",
|
|
91
42
|
className: "edit-widgets-header__title"
|
|
92
|
-
}, __('Widgets')), createElement(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
}, createElement(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
onMouseDown: event => {
|
|
103
|
-
event.preventDefault();
|
|
104
|
-
},
|
|
105
|
-
onClick: handleClick,
|
|
106
|
-
icon: plus
|
|
107
|
-
/* translators: button label text should, if possible, be under 16
|
|
108
|
-
characters. */,
|
|
109
|
-
label: _x('Toggle block inserter', 'Generic label for block inserter button')
|
|
110
|
-
}), isMediumViewport && createElement(Fragment, null, createElement(UndoButton, null), createElement(RedoButton, null), createElement(ToolbarItem, {
|
|
111
|
-
as: Button,
|
|
112
|
-
className: "edit-widgets-header-toolbar__list-view-toggle",
|
|
113
|
-
icon: listView,
|
|
114
|
-
isPressed: isListViewOpen
|
|
115
|
-
/* translators: button label text should, if possible, be under 16 characters. */,
|
|
116
|
-
label: __('List View'),
|
|
117
|
-
onClick: toggleListView,
|
|
118
|
-
ref: setListViewToggleElement
|
|
119
|
-
})))), createElement("div", {
|
|
43
|
+
}, __('Widgets')), createElement(DocumentTools, {
|
|
44
|
+
setListViewToggleElement: setListViewToggleElement
|
|
45
|
+
}), hasFixedToolbar && isLargeViewport && createElement(Fragment, null, createElement("div", {
|
|
46
|
+
className: "selected-block-tools-wrapper"
|
|
47
|
+
}, createElement(BlockContextualToolbar, {
|
|
48
|
+
isFixed: true
|
|
49
|
+
})), createElement(Popover.Slot, {
|
|
50
|
+
ref: blockToolbarRef,
|
|
51
|
+
name: "block-toolbar"
|
|
52
|
+
}))), createElement("div", {
|
|
120
53
|
className: "edit-widgets-header__actions"
|
|
121
54
|
}, createElement(SaveButton, null), createElement(PinnedItems.Slot, {
|
|
122
55
|
scope: "core/edit-widgets"
|