@wordpress/edit-widgets 5.22.0 → 5.23.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.
@@ -1,101 +1,48 @@
1
1
  /**
2
2
  * WordPress dependencies
3
3
  */
4
- import { useSelect, useDispatch } from '@wordpress/data';
5
- import { __, _x } from '@wordpress/i18n';
6
- import { Button, ToolbarItem, VisuallyHidden } from '@wordpress/components';
7
- import {
8
- NavigableToolbar,
9
- store as blockEditorStore,
10
- privateApis as blockEditorPrivateApis,
11
- } from '@wordpress/block-editor';
4
+ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';
5
+ import { useSelect } from '@wordpress/data';
6
+ import { useRef } from '@wordpress/element';
7
+ import { __ } from '@wordpress/i18n';
8
+ import { Popover, VisuallyHidden } from '@wordpress/components';
12
9
  import { PinnedItems } from '@wordpress/interface';
13
- import { listView, plus } from '@wordpress/icons';
14
- import { useCallback, useRef } from '@wordpress/element';
15
10
  import { useViewportMatch } from '@wordpress/compose';
11
+ import { store as preferencesStore } from '@wordpress/preferences';
16
12
 
17
13
  /**
18
14
  * Internal dependencies
19
15
  */
16
+ import DocumentTools from './document-tools';
20
17
  import SaveButton from '../save-button';
21
- import UndoButton from './undo-redo/undo';
22
- import RedoButton from './undo-redo/redo';
23
18
  import MoreMenu from '../more-menu';
24
- import useLastSelectedWidgetArea from '../../hooks/use-last-selected-widget-area';
25
- import { store as editWidgetsStore } from '../../store';
26
19
  import { unlock } from '../../lock-unlock';
27
20
 
28
- const { useShouldContextualToolbarShow } = unlock( blockEditorPrivateApis );
21
+ const { BlockContextualToolbar } = unlock( blockEditorPrivateApis );
29
22
 
30
23
  function Header( { setListViewToggleElement } ) {
31
- const isMediumViewport = useViewportMatch( 'medium' );
32
- const inserterButton = useRef();
33
- const widgetAreaClientId = useLastSelectedWidgetArea();
34
- const isLastSelectedWidgetAreaOpen = useSelect(
35
- ( select ) =>
36
- select( editWidgetsStore ).getIsWidgetAreaOpen(
37
- widgetAreaClientId
24
+ const isLargeViewport = useViewportMatch( 'medium' );
25
+ const blockToolbarRef = useRef();
26
+ const { hasFixedToolbar } = useSelect(
27
+ ( select ) => ( {
28
+ hasFixedToolbar: !! select( preferencesStore ).get(
29
+ 'core/edit-widgets',
30
+ 'fixedToolbar'
38
31
  ),
39
- [ widgetAreaClientId ]
32
+ } ),
33
+ []
40
34
  );
41
- const { isInserterOpen, isListViewOpen } = useSelect( ( select ) => {
42
- const { isInserterOpened, isListViewOpened } =
43
- select( editWidgetsStore );
44
- return {
45
- isInserterOpen: isInserterOpened(),
46
- isListViewOpen: isListViewOpened(),
47
- };
48
- }, [] );
49
- const { setIsWidgetAreaOpen, setIsInserterOpened, setIsListViewOpened } =
50
- useDispatch( editWidgetsStore );
51
- const { selectBlock } = 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
-
72
- const toggleListView = useCallback(
73
- () => setIsListViewOpened( ! isListViewOpen ),
74
- [ setIsListViewOpened, isListViewOpen ]
75
- );
76
-
77
- const {
78
- shouldShowContextualToolbar,
79
- canFocusHiddenToolbar,
80
- fixedToolbarCanBeFocused,
81
- } = useShouldContextualToolbarShow();
82
- // If there's a block toolbar to be focused, disable the focus shortcut for the document toolbar.
83
- // There's a fixed block toolbar when the fixed toolbar option is enabled or when the browser width is less than the large viewport.
84
- const blockToolbarCanBeFocused =
85
- shouldShowContextualToolbar ||
86
- canFocusHiddenToolbar ||
87
- fixedToolbarCanBeFocused;
88
35
 
89
36
  return (
90
37
  <>
91
38
  <div className="edit-widgets-header">
92
39
  <div className="edit-widgets-header__navigable-toolbar-wrapper">
93
- { isMediumViewport && (
40
+ { isLargeViewport && (
94
41
  <h1 className="edit-widgets-header__title">
95
42
  { __( 'Widgets' ) }
96
43
  </h1>
97
44
  ) }
98
- { ! isMediumViewport && (
45
+ { ! isLargeViewport && (
99
46
  <VisuallyHidden
100
47
  as="h1"
101
48
  className="edit-widgets-header__title"
@@ -103,48 +50,20 @@ function Header( { setListViewToggleElement } ) {
103
50
  { __( 'Widgets' ) }
104
51
  </VisuallyHidden>
105
52
  ) }
106
- <NavigableToolbar
107
- className="edit-widgets-header-toolbar"
108
- aria-label={ __( 'Document tools' ) }
109
- shouldUseKeyboardFocusShortcut={
110
- ! blockToolbarCanBeFocused
111
- }
112
- >
113
- <ToolbarItem
114
- ref={ inserterButton }
115
- as={ Button }
116
- className="edit-widgets-header-toolbar__inserter-toggle"
117
- variant="primary"
118
- isPressed={ isInserterOpen }
119
- onMouseDown={ ( event ) => {
120
- event.preventDefault();
121
- } }
122
- onClick={ handleClick }
123
- icon={ plus }
124
- /* translators: button label text should, if possible, be under 16
125
- characters. */
126
- label={ _x(
127
- 'Toggle block inserter',
128
- 'Generic label for block inserter button'
129
- ) }
130
- />
131
- { isMediumViewport && (
132
- <>
133
- <UndoButton />
134
- <RedoButton />
135
- <ToolbarItem
136
- as={ Button }
137
- className="edit-widgets-header-toolbar__list-view-toggle"
138
- icon={ listView }
139
- isPressed={ isListViewOpen }
140
- /* translators: button label text should, if possible, be under 16 characters. */
141
- label={ __( 'List View' ) }
142
- onClick={ toggleListView }
143
- ref={ setListViewToggleElement }
144
- />
145
- </>
146
- ) }
147
- </NavigableToolbar>
53
+ <DocumentTools
54
+ setListViewToggleElement={ setListViewToggleElement }
55
+ />
56
+ { hasFixedToolbar && isLargeViewport && (
57
+ <>
58
+ <div className="selected-block-tools-wrapper">
59
+ <BlockContextualToolbar isFixed />
60
+ </div>
61
+ <Popover.Slot
62
+ ref={ blockToolbarRef }
63
+ name="block-toolbar"
64
+ />
65
+ </>
66
+ ) }
148
67
  </div>
149
68
  <div className="edit-widgets-header__actions">
150
69
  <SaveButton />
@@ -9,12 +9,22 @@
9
9
  @include break-small {
10
10
  overflow: visible;
11
11
  }
12
+
13
+ .selected-block-tools-wrapper {
14
+ overflow-x: hidden;
15
+ }
16
+
17
+ .block-editor-block-contextual-toolbar.is-fixed {
18
+ border: none;
19
+ }
12
20
  }
13
21
 
14
22
  .edit-widgets-header__navigable-toolbar-wrapper {
15
23
  display: flex;
16
24
  align-items: center;
17
25
  justify-content: center;
26
+ flex-shrink: 2;
27
+ overflow-x: hidden;
18
28
  padding-left: $grid-unit-20;
19
29
  }
20
30
 
@@ -22,15 +22,3 @@
22
22
  height: 100%;
23
23
  }
24
24
  }
25
-
26
- .blocks-widgets-container {
27
- // making the header be lower than the content
28
- // so the fixed toolbar can be positioned on top of it
29
- // but only on desktop
30
- @include break-medium() {
31
- .interface-interface-skeleton__header:not(:focus-within) {
32
- z-index: 19;
33
- }
34
- }
35
-
36
- }
@@ -34,101 +34,3 @@
34
34
  }
35
35
  }
36
36
  }
37
-
38
- // Fixed contextual toolbar
39
- @include editor-left(".edit-widgets-block-editor .block-editor-block-contextual-toolbar.is-fixed");
40
-
41
-
42
- .edit-widgets-block-editor .block-editor-block-contextual-toolbar.is-fixed {
43
- position: sticky;
44
- top: 0;
45
- z-index: z-index(".block-editor-block-popover");
46
- display: block;
47
- width: 100%;
48
-
49
- // on desktop and tablet viewports the toolbar is fixed
50
- // on top of interface header
51
- $toolbar-margin: $grid-unit-80 * 3 - 2 * $grid-unit + $grid-unit-05;
52
-
53
- @include break-medium() {
54
- // leave room for block inserter, undo and redo, list view
55
- margin-left: $toolbar-margin;
56
- // position on top of interface header
57
- position: fixed;
58
- top: $admin-bar-height;
59
- // Don't fill up when empty
60
- min-height: initial;
61
- // remove the border
62
- border-bottom: none;
63
- // has to be flex for collapse button to fit
64
- display: flex;
65
-
66
- // Mimic the height of the parent, vertically align center, and provide a max-height.
67
- height: $header-height;
68
- align-items: center;
69
-
70
-
71
- // on tablet viewports the toolbar is fixed
72
- // on top of interface header and covers the whole header
73
- // except for the inserter on the left
74
- width: calc(100% - #{$toolbar-margin});
75
-
76
- &.is-collapsed {
77
- width: initial;
78
- }
79
-
80
- &:empty {
81
- width: initial;
82
- }
83
-
84
- .is-fullscreen-mode & {
85
- // leave room for block inserter, undo and redo, list view
86
- // and some margin left
87
- margin-left: $grid-unit-80 * 4 - 2 * $grid-unit;
88
-
89
- top: 0;
90
-
91
- &.is-collapsed {
92
- width: initial;
93
- }
94
-
95
- &:empty {
96
- width: initial;
97
- }
98
- }
99
-
100
- .show-icon-labels & {
101
- margin-left: $grid-unit-80 + 2 * $grid-unit; // inserter and margin
102
- width: calc(100% + 40px - #{$toolbar-margin}); //there are no undo, redo and list view buttons
103
-
104
- .is-fullscreen-mode & {
105
- margin-left: $grid-unit * 18; // site hub, inserter and margin
106
- }
107
- }
108
-
109
- .blocks-widgets-container & {
110
- margin-left: $grid-unit-80 * 2.4;
111
-
112
- &.is-collapsed {
113
- margin-left: $grid-unit-80 * 4.2;
114
- }
115
- }
116
- }
117
-
118
- // on desktop viewports the toolbar is fixed
119
- // on top of interface header and leaves room
120
- // for the block inserter the publish button
121
- @include break-large() {
122
- width: auto;
123
- .show-icon-labels & {
124
- width: auto; //there are no undo, redo and list view buttons
125
- }
126
-
127
- .is-fullscreen-mode & {
128
- // in full screen mode we need to account for
129
- // the combined with of the tools at the right of the header and the margin left
130
- // of the toolbar which includes four buttons
131
- width: calc(100% - 280px - #{4 * $grid-unit-80});
132
- }
133
- }
134
- }