@wordpress/commands 0.10.0 → 0.11.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 +2 -0
- package/build/components/command-menu.js +25 -40
- package/build/components/command-menu.js.map +1 -1
- package/build/hooks/use-command-context.js +3 -7
- package/build/hooks/use-command-context.js.map +1 -1
- package/build/hooks/use-command-loader.js +0 -4
- package/build/hooks/use-command-loader.js.map +1 -1
- package/build/hooks/use-command.js +0 -4
- package/build/hooks/use-command.js.map +1 -1
- package/build/index.js +0 -6
- package/build/index.js.map +1 -1
- package/build/lock-unlock.js +1 -2
- package/build/lock-unlock.js.map +1 -1
- package/build/private-apis.js +1 -4
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +5 -11
- package/build/store/actions.js.map +1 -1
- package/build/store/index.js +2 -11
- package/build/store/index.js.map +1 -1
- package/build/store/private-actions.js +0 -1
- package/build/store/private-actions.js.map +1 -1
- package/build/store/reducer.js +7 -18
- package/build/store/reducer.js.map +1 -1
- package/build/store/selectors.js +33 -4
- package/build/store/selectors.js.map +1 -1
- package/build-module/components/command-menu.js +26 -35
- package/build-module/components/command-menu.js.map +1 -1
- package/build-module/hooks/use-command-context.js +5 -4
- package/build-module/hooks/use-command-context.js.map +1 -1
- package/build-module/hooks/use-command-loader.js +2 -2
- package/build-module/hooks/use-command-loader.js.map +1 -1
- package/build-module/hooks/use-command.js +2 -2
- package/build-module/hooks/use-command.js.map +1 -1
- package/build-module/index.js.map +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +5 -5
- package/build-module/store/actions.js.map +1 -1
- package/build-module/store/index.js +2 -2
- package/build-module/store/index.js.map +1 -1
- package/build-module/store/private-actions.js.map +1 -1
- package/build-module/store/reducer.js +8 -17
- package/build-module/store/reducer.js.map +1 -1
- package/build-module/store/selectors.js +34 -0
- package/build-module/store/selectors.js.map +1 -1
- package/build-style/style-rtl.css +36 -18
- package/build-style/style.css +36 -18
- package/package.json +12 -10
- package/src/components/command-menu.js +17 -7
- package/src/components/style.scss +38 -19
- package/src/store/selectors.js +30 -0
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { Command, useCommandState } from 'cmdk';
|
|
5
|
+
import classnames from 'classnames';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* WordPress dependencies
|
|
@@ -24,7 +25,7 @@ import {
|
|
|
24
25
|
store as keyboardShortcutsStore,
|
|
25
26
|
useShortcut,
|
|
26
27
|
} from '@wordpress/keyboard-shortcuts';
|
|
27
|
-
import { Icon } from '@wordpress/icons';
|
|
28
|
+
import { Icon, search as inputIcon } from '@wordpress/icons';
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
* Internal dependencies
|
|
@@ -53,9 +54,14 @@ function CommandMenuLoader( { name, search, hook, setLoader, close } ) {
|
|
|
53
54
|
>
|
|
54
55
|
<HStack
|
|
55
56
|
alignment="left"
|
|
56
|
-
className=
|
|
57
|
+
className={ classnames(
|
|
58
|
+
'commands-command-menu__item',
|
|
59
|
+
{
|
|
60
|
+
'has-icon': command.icon,
|
|
61
|
+
}
|
|
62
|
+
) }
|
|
57
63
|
>
|
|
58
|
-
<Icon icon={ command.icon } />
|
|
64
|
+
{ command.icon && <Icon icon={ command.icon } /> }
|
|
59
65
|
<span>
|
|
60
66
|
<TextHighlight
|
|
61
67
|
text={ command.label }
|
|
@@ -123,9 +129,11 @@ export function CommandMenuGroup( { isContextual, search, setLoader, close } ) {
|
|
|
123
129
|
>
|
|
124
130
|
<HStack
|
|
125
131
|
alignment="left"
|
|
126
|
-
className=
|
|
132
|
+
className={ classnames( 'commands-command-menu__item', {
|
|
133
|
+
'has-icon': command.icon,
|
|
134
|
+
} ) }
|
|
127
135
|
>
|
|
128
|
-
<Icon icon={ command.icon } />
|
|
136
|
+
{ command.icon && <Icon icon={ command.icon } /> }
|
|
129
137
|
<span>
|
|
130
138
|
<TextHighlight
|
|
131
139
|
text={ command.label }
|
|
@@ -168,8 +176,9 @@ function CommandInput( { isOpen, search, setSearch } ) {
|
|
|
168
176
|
ref={ commandMenuInput }
|
|
169
177
|
value={ search }
|
|
170
178
|
onValueChange={ setSearch }
|
|
171
|
-
placeholder={ __( '
|
|
179
|
+
placeholder={ __( 'Search for commands' ) }
|
|
172
180
|
aria-activedescendant={ selectedItemId }
|
|
181
|
+
icon={ search }
|
|
173
182
|
/>
|
|
174
183
|
);
|
|
175
184
|
}
|
|
@@ -188,7 +197,7 @@ export function CommandMenu() {
|
|
|
188
197
|
registerShortcut( {
|
|
189
198
|
name: 'core/commands',
|
|
190
199
|
category: 'global',
|
|
191
|
-
description: __( 'Open the command palette' ),
|
|
200
|
+
description: __( 'Open the command palette.' ),
|
|
192
201
|
keyCombination: {
|
|
193
202
|
modifier: 'primary',
|
|
194
203
|
character: 'k',
|
|
@@ -260,6 +269,7 @@ export function CommandMenu() {
|
|
|
260
269
|
onKeyDown={ onKeyDown }
|
|
261
270
|
>
|
|
262
271
|
<div className="commands-command-menu__header">
|
|
272
|
+
<Icon icon={ inputIcon } />
|
|
263
273
|
<CommandInput
|
|
264
274
|
search={ search }
|
|
265
275
|
setSearch={ setSearch }
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
// dirty hack to clean up modal
|
|
2
2
|
.commands-command-menu {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
border-radius: $grid-unit-05;
|
|
4
|
+
width: calc(100% - #{$grid-unit-40});
|
|
5
|
+
margin: auto;
|
|
6
|
+
max-width: 420px;
|
|
5
7
|
position: relative;
|
|
6
|
-
top: 15
|
|
8
|
+
top: calc(15% + #{$header-height});
|
|
9
|
+
|
|
10
|
+
@include break-small() {
|
|
11
|
+
top: 15%;
|
|
12
|
+
}
|
|
7
13
|
|
|
8
14
|
.components-modal__content {
|
|
9
15
|
margin: 0;
|
|
@@ -19,6 +25,7 @@
|
|
|
19
25
|
.commands-command-menu__header {
|
|
20
26
|
display: flex;
|
|
21
27
|
align-items: center;
|
|
28
|
+
padding-left: $grid-unit-20;
|
|
22
29
|
|
|
23
30
|
.components-button {
|
|
24
31
|
height: $grid-unit-70;
|
|
@@ -42,33 +49,32 @@
|
|
|
42
49
|
[cmdk-input] {
|
|
43
50
|
border: none;
|
|
44
51
|
width: 100%;
|
|
45
|
-
padding: $grid-unit-20;
|
|
52
|
+
padding: $grid-unit-20 $grid-unit-20 $grid-unit-20 $grid-unit-10;
|
|
46
53
|
outline: none;
|
|
47
54
|
color: $gray-900;
|
|
48
55
|
margin: 0;
|
|
49
|
-
font-size:
|
|
56
|
+
font-size: 16px;
|
|
50
57
|
line-height: 28px;
|
|
51
|
-
border-bottom: 1px solid $gray-200;
|
|
52
58
|
border-radius: 0;
|
|
53
59
|
|
|
54
60
|
&::placeholder {
|
|
55
|
-
color: $gray-
|
|
61
|
+
color: $gray-700;
|
|
56
62
|
}
|
|
57
63
|
|
|
58
64
|
&:focus {
|
|
59
65
|
box-shadow: none;
|
|
60
66
|
outline: none;
|
|
61
|
-
border-bottom: 1px solid $gray-200;
|
|
62
67
|
}
|
|
63
68
|
}
|
|
64
69
|
|
|
65
70
|
[cmdk-item] {
|
|
66
|
-
border-radius: $
|
|
71
|
+
border-radius: $radius-block-ui;
|
|
67
72
|
cursor: pointer;
|
|
68
73
|
display: flex;
|
|
69
74
|
align-items: center;
|
|
70
|
-
padding: $grid-unit;
|
|
71
75
|
color: $gray-900;
|
|
76
|
+
font-size: $default-font-size;
|
|
77
|
+
min-height: $button-size-next-default-40px;
|
|
72
78
|
|
|
73
79
|
&[aria-selected="true"],
|
|
74
80
|
&:active {
|
|
@@ -86,16 +92,25 @@
|
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
svg {
|
|
89
|
-
fill: $gray-
|
|
95
|
+
fill: $gray-900;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
> div {
|
|
99
|
+
padding: $grid-unit;
|
|
100
|
+
padding-left: $grid-unit-50; // Account for commands without icons.
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
> .has-icon {
|
|
104
|
+
padding-left: $grid-unit;
|
|
90
105
|
}
|
|
91
106
|
}
|
|
92
107
|
|
|
93
108
|
[cmdk-root] > [cmdk-list] {
|
|
94
|
-
max-height:
|
|
109
|
+
max-height: 368px; // Specific to not have commands overflow oddly.
|
|
95
110
|
overflow: auto;
|
|
96
111
|
|
|
97
|
-
&
|
|
98
|
-
padding: $grid-unit;
|
|
112
|
+
& [cmdk-list-sizer] > [cmdk-group] > [cmdk-group-items]:not(:empty) {
|
|
113
|
+
padding: 0 $grid-unit $grid-unit;
|
|
99
114
|
}
|
|
100
115
|
}
|
|
101
116
|
|
|
@@ -103,9 +118,9 @@
|
|
|
103
118
|
display: flex;
|
|
104
119
|
align-items: center;
|
|
105
120
|
justify-content: center;
|
|
106
|
-
height: $grid-unit-80;
|
|
107
121
|
white-space: pre-wrap;
|
|
108
|
-
color: $gray-
|
|
122
|
+
color: $gray-900;
|
|
123
|
+
padding: $grid-unit-10 0 $grid-unit-40;
|
|
109
124
|
}
|
|
110
125
|
|
|
111
126
|
[cmdk-loading] {
|
|
@@ -115,10 +130,14 @@
|
|
|
115
130
|
[cmdk-list-sizer] {
|
|
116
131
|
position: relative;
|
|
117
132
|
}
|
|
133
|
+
}
|
|
118
134
|
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
135
|
+
.commands-command-menu__item span {
|
|
136
|
+
// Ensure commands do not run off the edge (great for post titles).
|
|
137
|
+
display: inline-block;
|
|
138
|
+
overflow: hidden;
|
|
139
|
+
text-overflow: ellipsis;
|
|
140
|
+
white-space: nowrap;
|
|
122
141
|
}
|
|
123
142
|
|
|
124
143
|
.commands-command-menu__item mark {
|
package/src/store/selectors.js
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import createSelector from 'rememo';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Returns the registered static commands.
|
|
8
|
+
*
|
|
9
|
+
* @param {Object} state State tree.
|
|
10
|
+
* @param {boolean} contextual Whether to return only contextual commands.
|
|
11
|
+
*
|
|
12
|
+
* @return {import('./actions').WPCommandConfig[]} The list of registered commands.
|
|
13
|
+
*/
|
|
6
14
|
export const getCommands = createSelector(
|
|
7
15
|
( state, contextual = false ) =>
|
|
8
16
|
Object.values( state.commands ).filter( ( command ) => {
|
|
@@ -13,6 +21,14 @@ export const getCommands = createSelector(
|
|
|
13
21
|
( state ) => [ state.commands, state.context ]
|
|
14
22
|
);
|
|
15
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Returns the registered command loaders.
|
|
26
|
+
*
|
|
27
|
+
* @param {Object} state State tree.
|
|
28
|
+
* @param {boolean} contextual Whether to return only contextual command loaders.
|
|
29
|
+
*
|
|
30
|
+
* @return {import('./actions').WPCommandLoaderConfig[]} The list of registered command loaders.
|
|
31
|
+
*/
|
|
16
32
|
export const getCommandLoaders = createSelector(
|
|
17
33
|
( state, contextual = false ) =>
|
|
18
34
|
Object.values( state.commandLoaders ).filter( ( loader ) => {
|
|
@@ -23,10 +39,24 @@ export const getCommandLoaders = createSelector(
|
|
|
23
39
|
( state ) => [ state.commandLoaders, state.context ]
|
|
24
40
|
);
|
|
25
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Returns whether the command palette is open.
|
|
44
|
+
*
|
|
45
|
+
* @param {Object} state State tree.
|
|
46
|
+
*
|
|
47
|
+
* @return {boolean} Returns whether the command palette is open.
|
|
48
|
+
*/
|
|
26
49
|
export function isOpen( state ) {
|
|
27
50
|
return state.isOpen;
|
|
28
51
|
}
|
|
29
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Returns whether the active context.
|
|
55
|
+
*
|
|
56
|
+
* @param {Object} state State tree.
|
|
57
|
+
*
|
|
58
|
+
* @return {string} Context.
|
|
59
|
+
*/
|
|
30
60
|
export function getContext( state ) {
|
|
31
61
|
return state.context;
|
|
32
62
|
}
|