@wordpress/components 23.9.0 → 24.0.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 +36 -0
- package/CONTRIBUTING.md +65 -1
- package/README.md +1 -3
- package/build/autocomplete/autocompleter-ui.js +0 -2
- package/build/autocomplete/autocompleter-ui.js.map +1 -1
- package/build/autocomplete/index.js +2 -0
- package/build/autocomplete/index.js.map +1 -1
- package/build/button/index.js +2 -0
- package/build/button/index.js.map +1 -1
- package/build/card/card-media/component.js +2 -1
- package/build/card/card-media/component.js.map +1 -1
- package/build/combobox-control/index.js +7 -5
- package/build/combobox-control/index.js.map +1 -1
- package/build/combobox-control/styles.js +3 -3
- package/build/combobox-control/styles.js.map +1 -1
- package/build/dimension-control/index.js +1 -1
- package/build/dimension-control/index.js.map +1 -1
- package/build/draggable/index.js +2 -7
- package/build/draggable/index.js.map +1 -1
- package/build/form-token-field/index.js +5 -3
- package/build/form-token-field/index.js.map +1 -1
- package/build/form-token-field/styles.js +3 -3
- package/build/form-token-field/styles.js.map +1 -1
- package/build/mobile/global-styles-context/index.native.js +13 -1
- package/build/mobile/global-styles-context/index.native.js.map +1 -1
- package/build/mobile/link-picker/link-picker-results.native.js +3 -1
- package/build/mobile/link-picker/link-picker-results.native.js.map +1 -1
- package/build/modal/index.js +2 -1
- package/build/modal/index.js.map +1 -1
- package/build/navigable-container/container.js +39 -19
- package/build/navigable-container/container.js.map +1 -1
- package/build/navigable-container/index.js.map +1 -1
- package/build/navigable-container/menu.js +37 -5
- package/build/navigable-container/menu.js.map +1 -1
- package/build/navigable-container/tabbable.js +45 -4
- package/build/navigable-container/tabbable.js.map +1 -1
- package/build/navigable-container/types.js +6 -0
- package/build/navigable-container/types.js.map +1 -0
- package/build/palette-edit/index.js +34 -12
- package/build/palette-edit/index.js.map +1 -1
- package/build/sandbox/index.native.js +6 -2
- package/build/sandbox/index.native.js.map +1 -1
- package/build/slot-fill/bubbles-virtually/fill.js +2 -1
- package/build/slot-fill/bubbles-virtually/fill.js.map +1 -1
- package/build/slot-fill/bubbles-virtually/slot-fill-provider.js +45 -35
- package/build/slot-fill/bubbles-virtually/slot-fill-provider.js.map +1 -1
- package/build/slot-fill/bubbles-virtually/use-slot.js +11 -26
- package/build/slot-fill/bubbles-virtually/use-slot.js.map +1 -1
- package/build/slot-fill/fill.js +7 -31
- package/build/slot-fill/fill.js.map +1 -1
- package/build/slot-fill/index.js.map +1 -1
- package/build/slot-fill/provider.js +0 -6
- package/build/slot-fill/provider.js.map +1 -1
- package/build/slot-fill/slot.js +0 -5
- package/build/slot-fill/slot.js.map +1 -1
- package/build/tab-panel/index.js.map +1 -1
- package/build/theme/color-algorithms.js +1 -1
- package/build/theme/color-algorithms.js.map +1 -1
- package/build/toolbar/toolbar-button/index.js +1 -2
- package/build/toolbar/toolbar-button/index.js.map +1 -1
- package/build/toolbar/toolbar-item/index.js +4 -2
- package/build/toolbar/toolbar-item/index.js.map +1 -1
- package/build/utils/colors-values.js +3 -3
- package/build/utils/colors-values.js.map +1 -1
- package/build/utils/use-deprecated-props.js +35 -0
- package/build/utils/use-deprecated-props.js.map +1 -0
- package/build-module/autocomplete/autocompleter-ui.js +1 -3
- package/build-module/autocomplete/autocompleter-ui.js.map +1 -1
- package/build-module/autocomplete/index.js +3 -3
- package/build-module/autocomplete/index.js.map +1 -1
- package/build-module/button/index.js +2 -0
- package/build-module/button/index.js.map +1 -1
- package/build-module/card/card-media/component.js +2 -1
- package/build-module/card/card-media/component.js.map +1 -1
- package/build-module/combobox-control/index.js +6 -5
- package/build-module/combobox-control/index.js.map +1 -1
- package/build-module/combobox-control/styles.js +3 -3
- package/build-module/combobox-control/styles.js.map +1 -1
- package/build-module/dimension-control/index.js +1 -1
- package/build-module/dimension-control/index.js.map +1 -1
- package/build-module/draggable/index.js +2 -7
- package/build-module/draggable/index.js.map +1 -1
- package/build-module/form-token-field/index.js +4 -3
- package/build-module/form-token-field/index.js.map +1 -1
- package/build-module/form-token-field/styles.js +3 -3
- package/build-module/form-token-field/styles.js.map +1 -1
- package/build-module/mobile/global-styles-context/index.native.js +13 -1
- package/build-module/mobile/global-styles-context/index.native.js.map +1 -1
- package/build-module/mobile/link-picker/link-picker-results.native.js +3 -1
- package/build-module/mobile/link-picker/link-picker-results.native.js.map +1 -1
- package/build-module/modal/index.js +2 -1
- package/build-module/modal/index.js.map +1 -1
- package/build-module/navigable-container/container.js +43 -19
- package/build-module/navigable-container/container.js.map +1 -1
- package/build-module/navigable-container/index.js +0 -2
- package/build-module/navigable-container/index.js.map +1 -1
- package/build-module/navigable-container/menu.js +36 -4
- package/build-module/navigable-container/menu.js.map +1 -1
- package/build-module/navigable-container/tabbable.js +44 -3
- package/build-module/navigable-container/tabbable.js.map +1 -1
- package/build-module/navigable-container/types.js +2 -0
- package/build-module/navigable-container/types.js.map +1 -0
- package/build-module/palette-edit/index.js +34 -13
- package/build-module/palette-edit/index.js.map +1 -1
- package/build-module/sandbox/index.native.js +6 -2
- package/build-module/sandbox/index.native.js.map +1 -1
- package/build-module/slot-fill/bubbles-virtually/fill.js +2 -1
- package/build-module/slot-fill/bubbles-virtually/fill.js.map +1 -1
- package/build-module/slot-fill/bubbles-virtually/slot-fill-provider.js +46 -36
- package/build-module/slot-fill/bubbles-virtually/slot-fill-provider.js.map +1 -1
- package/build-module/slot-fill/bubbles-virtually/use-slot.js +12 -27
- package/build-module/slot-fill/bubbles-virtually/use-slot.js.map +1 -1
- package/build-module/slot-fill/fill.js +7 -31
- package/build-module/slot-fill/fill.js.map +1 -1
- package/build-module/slot-fill/index.js +1 -2
- package/build-module/slot-fill/index.js.map +1 -1
- package/build-module/slot-fill/provider.js +0 -6
- package/build-module/slot-fill/provider.js.map +1 -1
- package/build-module/slot-fill/slot.js +0 -5
- package/build-module/slot-fill/slot.js.map +1 -1
- package/build-module/tab-panel/index.js.map +1 -1
- package/build-module/theme/color-algorithms.js +1 -1
- package/build-module/theme/color-algorithms.js.map +1 -1
- package/build-module/toolbar/toolbar-button/index.js +1 -2
- package/build-module/toolbar/toolbar-button/index.js.map +1 -1
- package/build-module/toolbar/toolbar-item/index.js +5 -2
- package/build-module/toolbar/toolbar-item/index.js.map +1 -1
- package/build-module/utils/colors-values.js +3 -3
- package/build-module/utils/colors-values.js.map +1 -1
- package/build-module/utils/use-deprecated-props.js +25 -0
- package/build-module/utils/use-deprecated-props.js.map +1 -0
- package/build-style/style-rtl.css +58 -55
- package/build-style/style.css +58 -55
- package/build-types/autocomplete/autocompleter-ui.d.ts.map +1 -1
- package/build-types/autocomplete/index.d.ts.map +1 -1
- package/build-types/autocomplete/types.d.ts +2 -18
- package/build-types/autocomplete/types.d.ts.map +1 -1
- package/build-types/button/deprecated.d.ts +6 -0
- package/build-types/button/deprecated.d.ts.map +1 -1
- package/build-types/button/index.d.ts.map +1 -1
- package/build-types/button/types.d.ts +7 -0
- package/build-types/button/types.d.ts.map +1 -1
- package/build-types/card/card-media/component.d.ts +2 -1
- package/build-types/card/card-media/component.d.ts.map +1 -1
- package/build-types/card/stories/index.d.ts +21 -1
- package/build-types/card/stories/index.d.ts.map +1 -1
- package/build-types/combobox-control/index.d.ts +1 -1
- package/build-types/combobox-control/index.d.ts.map +1 -1
- package/build-types/combobox-control/stories/index.d.ts.map +1 -1
- package/build-types/combobox-control/styles.d.ts +1 -1
- package/build-types/combobox-control/types.d.ts +8 -1
- package/build-types/combobox-control/types.d.ts.map +1 -1
- package/build-types/dimension-control/index.d.ts +1 -1
- package/build-types/draggable/index.d.ts.map +1 -1
- package/build-types/form-token-field/index.d.ts.map +1 -1
- package/build-types/form-token-field/styles.d.ts +1 -1
- package/build-types/form-token-field/types.d.ts +8 -1
- package/build-types/form-token-field/types.d.ts.map +1 -1
- package/build-types/modal/index.d.ts.map +1 -1
- package/build-types/navigable-container/container.d.ts +20 -1
- package/build-types/navigable-container/container.d.ts.map +1 -1
- package/build-types/navigable-container/index.d.ts +5 -2
- package/build-types/navigable-container/index.d.ts.map +1 -1
- package/build-types/navigable-container/menu.d.ts +45 -11
- package/build-types/navigable-container/menu.d.ts.map +1 -1
- package/build-types/navigable-container/stories/navigable-menu.d.ts +12 -0
- package/build-types/navigable-container/stories/navigable-menu.d.ts.map +1 -0
- package/build-types/navigable-container/stories/tabbable-container.d.ts +12 -0
- package/build-types/navigable-container/stories/tabbable-container.d.ts.map +1 -0
- package/build-types/navigable-container/tabbable.d.ts +52 -9
- package/build-types/navigable-container/tabbable.d.ts.map +1 -1
- package/build-types/navigable-container/test/navigable-menu.d.ts +2 -0
- package/build-types/navigable-container/test/navigable-menu.d.ts.map +1 -0
- package/build-types/navigable-container/test/tababble-container.d.ts +2 -0
- package/build-types/navigable-container/test/tababble-container.d.ts.map +1 -0
- package/build-types/navigable-container/types.d.ts +61 -0
- package/build-types/navigable-container/types.d.ts.map +1 -0
- package/build-types/navigator/navigator-back-button/component.d.ts +1 -0
- package/build-types/navigator/navigator-back-button/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-back-button/hook.d.ts +1 -0
- package/build-types/navigator/navigator-back-button/hook.d.ts.map +1 -1
- package/build-types/navigator/navigator-button/component.d.ts +1 -0
- package/build-types/navigator/navigator-button/component.d.ts.map +1 -1
- package/build-types/navigator/navigator-button/hook.d.ts +1 -0
- package/build-types/navigator/navigator-button/hook.d.ts.map +1 -1
- package/build-types/navigator/navigator-to-parent-button/component.d.ts +1 -0
- package/build-types/navigator/navigator-to-parent-button/component.d.ts.map +1 -1
- package/build-types/palette-edit/index.d.ts +1 -1
- package/build-types/palette-edit/index.d.ts.map +1 -1
- package/build-types/palette-edit/stories/index.d.ts.map +1 -1
- package/build-types/palette-edit/types.d.ts +8 -0
- package/build-types/palette-edit/types.d.ts.map +1 -1
- package/build-types/slot-fill/bubbles-virtually/fill.d.ts.map +1 -1
- package/build-types/slot-fill/bubbles-virtually/slot-fill-provider.d.ts.map +1 -1
- package/build-types/slot-fill/bubbles-virtually/use-slot.d.ts.map +1 -1
- package/build-types/slot-fill/fill.d.ts +4 -2
- package/build-types/slot-fill/fill.d.ts.map +1 -1
- package/build-types/slot-fill/index.d.ts +1 -2
- package/build-types/slot-fill/index.d.ts.map +1 -1
- package/build-types/slot-fill/provider.d.ts +0 -2
- package/build-types/slot-fill/provider.d.ts.map +1 -1
- package/build-types/slot-fill/slot.d.ts.map +1 -1
- package/build-types/toolbar/stories/index.d.ts.map +1 -1
- package/build-types/toolbar/toolbar-button/index.d.ts +6 -0
- package/build-types/toolbar/toolbar-button/index.d.ts.map +1 -1
- package/build-types/toolbar/toolbar-item/index.d.ts +6 -4
- package/build-types/toolbar/toolbar-item/index.d.ts.map +1 -1
- package/build-types/tree-grid/types.d.ts +7 -0
- package/build-types/tree-grid/types.d.ts.map +1 -1
- package/build-types/utils/use-deprecated-props.d.ts +9 -0
- package/build-types/utils/use-deprecated-props.d.ts.map +1 -0
- package/package.json +19 -19
- package/src/autocomplete/README.md +78 -52
- package/src/autocomplete/autocompleter-ui.tsx +0 -2
- package/src/autocomplete/index.tsx +1 -2
- package/src/autocomplete/types.ts +3 -19
- package/src/button/index.tsx +2 -0
- package/src/button/style.scss +13 -6
- package/src/button/types.ts +7 -0
- package/src/card/card-media/README.md +1 -1
- package/src/card/card-media/component.tsx +2 -1
- package/src/card/stories/index.tsx +47 -26
- package/src/checkbox-control/style.scss +1 -4
- package/src/combobox-control/index.tsx +24 -18
- package/src/combobox-control/stories/index.tsx +0 -1
- package/src/combobox-control/styles.ts +4 -4
- package/src/combobox-control/types.ts +8 -1
- package/src/custom-gradient-picker/style.scss +2 -2
- package/src/dimension-control/index.tsx +1 -1
- package/src/draggable/index.tsx +1 -9
- package/src/form-toggle/style.scss +1 -5
- package/src/form-token-field/index.tsx +7 -3
- package/src/form-token-field/styles.ts +4 -4
- package/src/form-token-field/types.ts +8 -1
- package/src/mobile/global-styles-context/index.native.js +12 -1
- package/src/mobile/link-picker/link-picker-results.native.js +3 -0
- package/src/modal/index.tsx +6 -1
- package/src/modal/style.scss +1 -1
- package/src/navigable-container/README.md +24 -13
- package/src/navigable-container/{container.js → container.tsx} +57 -27
- package/src/navigable-container/{index.js → index.tsx} +0 -1
- package/src/navigable-container/menu.tsx +100 -0
- package/src/navigable-container/stories/{navigable-menu.js → navigable-menu.tsx} +15 -10
- package/src/navigable-container/stories/{tabbable-container.js → tabbable-container.tsx} +15 -6
- package/src/navigable-container/tabbable.tsx +92 -0
- package/src/navigable-container/test/{navigable-menu.js → navigable-menu.tsx} +3 -1
- package/src/navigable-container/test/{tababble-container.js → tababble-container.tsx} +53 -24
- package/src/navigable-container/types.ts +76 -0
- package/src/palette-edit/index.tsx +45 -7
- package/src/palette-edit/stories/index.tsx +4 -0
- package/src/palette-edit/types.ts +11 -0
- package/src/sandbox/index.native.js +4 -0
- package/src/slot-fill/bubbles-virtually/fill.js +2 -1
- package/src/slot-fill/bubbles-virtually/slot-fill-provider.js +46 -60
- package/src/slot-fill/bubbles-virtually/use-slot.js +14 -41
- package/src/slot-fill/fill.js +4 -26
- package/src/slot-fill/index.js +1 -3
- package/src/slot-fill/provider.js +0 -6
- package/src/slot-fill/slot.js +0 -5
- package/src/style.scss +6 -0
- package/src/tab-panel/index.tsx +1 -1
- package/src/theme/color-algorithms.ts +1 -1
- package/src/theme/stories/index.tsx +1 -1
- package/src/theme/test/color-algorithms.ts +2 -2
- package/src/toggle-group-control/test/__snapshots__/index.tsx.snap +4 -4
- package/src/toolbar/stories/index.tsx +26 -24
- package/src/toolbar/toolbar-button/index.tsx +10 -13
- package/src/toolbar/toolbar-item/{index.js → index.tsx} +12 -3
- package/src/tree-grid/README.md +18 -0
- package/src/tree-grid/types.ts +7 -0
- package/src/utils/colors-values.js +3 -3
- package/src/utils/theme-variables.scss +4 -4
- package/src/utils/use-deprecated-props.ts +29 -0
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/CONTRIBUTING.md +0 -78
- package/src/README.md +0 -20
- package/src/navigable-container/menu.js +0 -62
- package/src/navigable-container/tabbable.js +0 -46
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import { createElement } from "@wordpress/element";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* External dependencies
|
|
6
|
+
*/
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* WordPress dependencies
|
|
7
10
|
*/
|
|
8
11
|
import { Component, forwardRef } from '@wordpress/element';
|
|
9
12
|
import { focus } from '@wordpress/dom';
|
|
13
|
+
/**
|
|
14
|
+
* Internal dependencies
|
|
15
|
+
*/
|
|
10
16
|
|
|
11
17
|
const noop = () => {};
|
|
12
18
|
|
|
@@ -25,8 +31,8 @@ function cycleValue(value, total, offset) {
|
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
class NavigableContainer extends Component {
|
|
28
|
-
constructor() {
|
|
29
|
-
super(
|
|
34
|
+
constructor(args) {
|
|
35
|
+
super(args);
|
|
30
36
|
this.onKeyDown = this.onKeyDown.bind(this);
|
|
31
37
|
this.bindContainer = this.bindContainer.bind(this);
|
|
32
38
|
this.getFocusableContext = this.getFocusableContext.bind(this);
|
|
@@ -34,18 +40,24 @@ class NavigableContainer extends Component {
|
|
|
34
40
|
}
|
|
35
41
|
|
|
36
42
|
componentDidMount() {
|
|
37
|
-
|
|
43
|
+
if (!this.container) {
|
|
44
|
+
return;
|
|
45
|
+
} // We use DOM event listeners instead of React event listeners
|
|
38
46
|
// because we want to catch events from the underlying DOM tree
|
|
39
47
|
// The React Tree can be different from the DOM tree when using
|
|
40
48
|
// portals. Block Toolbars for instance are rendered in a separate
|
|
41
49
|
// React Trees.
|
|
50
|
+
|
|
51
|
+
|
|
42
52
|
this.container.addEventListener('keydown', this.onKeyDown);
|
|
43
|
-
this.container.addEventListener('focus', this.onFocus);
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
componentWillUnmount() {
|
|
56
|
+
if (!this.container) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
|
|
47
60
|
this.container.removeEventListener('keydown', this.onKeyDown);
|
|
48
|
-
this.container.removeEventListener('focus', this.onFocus);
|
|
49
61
|
}
|
|
50
62
|
|
|
51
63
|
bindContainer(ref) {
|
|
@@ -62,6 +74,10 @@ class NavigableContainer extends Component {
|
|
|
62
74
|
}
|
|
63
75
|
|
|
64
76
|
getFocusableContext(target) {
|
|
77
|
+
if (!this.container) {
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
|
|
65
81
|
const {
|
|
66
82
|
onlyBrowserTabstops
|
|
67
83
|
} = this.props;
|
|
@@ -81,14 +97,12 @@ class NavigableContainer extends Component {
|
|
|
81
97
|
}
|
|
82
98
|
|
|
83
99
|
getFocusableIndex(focusables, target) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
if (directIndex !== -1) {
|
|
87
|
-
return directIndex;
|
|
88
|
-
}
|
|
100
|
+
return focusables.indexOf(target);
|
|
89
101
|
}
|
|
90
102
|
|
|
91
103
|
onKeyDown(event) {
|
|
104
|
+
var _event$target2, _event$target2$ownerD;
|
|
105
|
+
|
|
92
106
|
if (this.props.onKeyDown) {
|
|
93
107
|
this.props.onKeyDown(event);
|
|
94
108
|
}
|
|
@@ -105,19 +119,18 @@ class NavigableContainer extends Component {
|
|
|
105
119
|
const offset = eventToOffset(event); // eventToOffset returns undefined if the event is not handled by the component.
|
|
106
120
|
|
|
107
121
|
if (offset !== undefined && stopNavigationEvents) {
|
|
122
|
+
var _event$target;
|
|
123
|
+
|
|
108
124
|
// Prevents arrow key handlers bound to the document directly interfering.
|
|
109
125
|
event.stopImmediatePropagation(); // When navigating a collection of items, prevent scroll containers
|
|
110
126
|
// from scrolling. The preventDefault also prevents Voiceover from
|
|
111
127
|
// 'handling' the event, as voiceover will try to use arrow keys
|
|
112
128
|
// for highlighting text.
|
|
113
129
|
|
|
114
|
-
const targetRole = event.target.getAttribute('role');
|
|
115
|
-
const targetHasMenuItemRole = MENU_ITEM_ROLES.includes(targetRole);
|
|
116
|
-
// after this component has already moved it.
|
|
130
|
+
const targetRole = (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.getAttribute('role');
|
|
131
|
+
const targetHasMenuItemRole = !!targetRole && MENU_ITEM_ROLES.includes(targetRole);
|
|
117
132
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (targetHasMenuItemRole || isTab) {
|
|
133
|
+
if (targetHasMenuItemRole) {
|
|
121
134
|
event.preventDefault();
|
|
122
135
|
}
|
|
123
136
|
}
|
|
@@ -126,7 +139,13 @@ class NavigableContainer extends Component {
|
|
|
126
139
|
return;
|
|
127
140
|
}
|
|
128
141
|
|
|
129
|
-
const
|
|
142
|
+
const activeElement = (_event$target2 = event.target) === null || _event$target2 === void 0 ? void 0 : (_event$target2$ownerD = _event$target2.ownerDocument) === null || _event$target2$ownerD === void 0 ? void 0 : _event$target2$ownerD.activeElement;
|
|
143
|
+
|
|
144
|
+
if (!activeElement) {
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const context = getFocusableContext(activeElement);
|
|
130
149
|
|
|
131
150
|
if (!context) {
|
|
132
151
|
return;
|
|
@@ -140,7 +159,12 @@ class NavigableContainer extends Component {
|
|
|
140
159
|
|
|
141
160
|
if (nextIndex >= 0 && nextIndex < focusables.length) {
|
|
142
161
|
focusables[nextIndex].focus();
|
|
143
|
-
onNavigate(nextIndex, focusables[nextIndex]);
|
|
162
|
+
onNavigate(nextIndex, focusables[nextIndex]); // `preventDefault()` on tab to avoid having the browser move the focus
|
|
163
|
+
// after this component has already moved it.
|
|
164
|
+
|
|
165
|
+
if (event.code === 'Tab') {
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
}
|
|
144
168
|
}
|
|
145
169
|
}
|
|
146
170
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/navigable-container/container.js"],"names":["Component","forwardRef","focus","noop","MENU_ITEM_ROLES","cycleValue","value","total","offset","nextValue","NavigableContainer","constructor","arguments","onKeyDown","bind","bindContainer","getFocusableContext","getFocusableIndex","componentDidMount","container","addEventListener","onFocus","componentWillUnmount","removeEventListener","ref","forwardedRef","props","current","target","onlyBrowserTabstops","finder","tabbable","focusable","focusables","find","index","directIndex","indexOf","event","cycle","eventToOffset","onNavigate","stopNavigationEvents","undefined","stopImmediatePropagation","targetRole","getAttribute","targetHasMenuItemRole","includes","isTab","code","preventDefault","context","ownerDocument","activeElement","nextIndex","length","render","children","restProps","forwardedNavigableContainer","displayName"],"mappings":";;AAAA;;AACA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,UAApB,QAAsC,oBAAtC;AACA,SAASC,KAAT,QAAsB,gBAAtB;;AAEA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;;AACA,MAAMC,eAAe,GAAG,CAAE,UAAF,EAAc,eAAd,EAA+B,kBAA/B,CAAxB;;AAEA,SAASC,UAAT,CAAqBC,KAArB,EAA4BC,KAA5B,EAAmCC,MAAnC,EAA4C;AAC3C,QAAMC,SAAS,GAAGH,KAAK,GAAGE,MAA1B;;AACA,MAAKC,SAAS,GAAG,CAAjB,EAAqB;AACpB,WAAOF,KAAK,GAAGE,SAAf;AACA,GAFD,MAEO,IAAKA,SAAS,IAAIF,KAAlB,EAA0B;AAChC,WAAOE,SAAS,GAAGF,KAAnB;AACA;;AAED,SAAOE,SAAP;AACA;;AAED,MAAMC,kBAAN,SAAiCV,SAAjC,CAA2C;AAC1CW,EAAAA,WAAW,GAAG;AACb,UAAO,GAAGC,SAAV;AACA,SAAKC,SAAL,GAAiB,KAAKA,SAAL,CAAeC,IAAf,CAAqB,IAArB,CAAjB;AACA,SAAKC,aAAL,GAAqB,KAAKA,aAAL,CAAmBD,IAAnB,CAAyB,IAAzB,CAArB;AAEA,SAAKE,mBAAL,GAA2B,KAAKA,mBAAL,CAAyBF,IAAzB,CAA+B,IAA/B,CAA3B;AACA,SAAKG,iBAAL,GAAyB,KAAKA,iBAAL,CAA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AChB;AACA;;AAED,UAAM;AAAEjB,MAAAA,KAAF;AAASF,MAAAA;AAAT,QAAwBmB,OAA9B;AACA,UAAMG,SAAS,GAAGhB,KAAK,GACpBlC,UAAU,CAAE8B,KAAF,EAASF,UAAU,CAACuB,MAApB,EAA4BhD,MAA5B,CADU,GAEpB2B,KAAK,GAAG3B,MAFX;;AAGA,QAAK+C,SAAS,IAAI,CAAb,IAAkBA,SAAS,GAAGtB,UAAU,CAACuB,MAA9C,EAAuD;AACtDvB,MAAAA,UAAU,CAAEsB,SAAF,CAAV,CAAwBrD,KAAxB;AACAuC,MAAAA,UAAU,CAAEc,SAAF,EAAatB,UAAU,CAAEsB,SAAF,CAAvB,CAAV;AACA;AACD;;AAEDE,EAAAA,MAAM,GAAG;AACR,UAAM;AACLC,MAAAA,QADK;AAELhB,MAAAA,oBAFK;AAGLF,MAAAA,aAHK;AAILC,MAAAA,UAJK;AAKL5B,MAAAA,SALK;AAML0B,MAAAA,KANK;AAOLV,MAAAA,mBAPK;AAQLJ,MAAAA,YARK;AASL,SAAGkC;AATE,QAUF,KAAKjC,KAVT;AAWA,WACC;AAAK,MAAA,GAAG,EAAG,KAAKX;AAAhB,OAAqC4C,SAArC,GACGD,QADH,CADD;AAKA;;AAlIyC;;AAqI3C,MAAME,2BAA2B,GAAG,CAAElC,KAAF,EAASF,GAAT,KAAkB;AACrD,SAAO,cAAC,kBAAD,eAAyBE,KAAzB;AAAiC,IAAA,YAAY,EAAGF;AAAhD,KAAP;AACA,CAFD;;AAGAoC,2BAA2B,CAACC,WAA5B,GAA0C,oBAA1C;AAEA,eAAe5D,UAAU,CAAE2D,2BAAF,CAAzB","sourcesContent":["// @ts-nocheck\n/**\n * WordPress dependencies\n */\nimport { Component, forwardRef } from '@wordpress/element';\nimport { focus } from '@wordpress/dom';\n\nconst noop = () => {};\nconst MENU_ITEM_ROLES = [ 'menuitem', 'menuitemradio', 'menuitemcheckbox' ];\n\nfunction cycleValue( value, total, offset ) {\n\tconst nextValue = value + offset;\n\tif ( nextValue < 0 ) {\n\t\treturn total + nextValue;\n\t} else if ( nextValue >= total ) {\n\t\treturn nextValue - total;\n\t}\n\n\treturn nextValue;\n}\n\nclass NavigableContainer extends Component {\n\tconstructor() {\n\t\tsuper( ...arguments );\n\t\tthis.onKeyDown = this.onKeyDown.bind( this );\n\t\tthis.bindContainer = this.bindContainer.bind( this );\n\n\t\tthis.getFocusableContext = this.getFocusableContext.bind( this );\n\t\tthis.getFocusableIndex = this.getFocusableIndex.bind( this );\n\t}\n\n\tcomponentDidMount() {\n\t\t// We use DOM event listeners instead of React event listeners\n\t\t// because we want to catch events from the underlying DOM tree\n\t\t// The React Tree can be different from the DOM tree when using\n\t\t// portals. Block Toolbars for instance are rendered in a separate\n\t\t// React Trees.\n\t\tthis.container.addEventListener( 'keydown', this.onKeyDown );\n\t\tthis.container.addEventListener( 'focus', this.onFocus );\n\t}\n\n\tcomponentWillUnmount() {\n\t\tthis.container.removeEventListener( 'keydown', this.onKeyDown );\n\t\tthis.container.removeEventListener( 'focus', this.onFocus );\n\t}\n\n\tbindContainer( ref ) {\n\t\tconst { forwardedRef } = this.props;\n\t\tthis.container = ref;\n\n\t\tif ( typeof forwardedRef === 'function' ) {\n\t\t\tforwardedRef( ref );\n\t\t} else if ( forwardedRef && 'current' in forwardedRef ) {\n\t\t\tforwardedRef.current = ref;\n\t\t}\n\t}\n\n\tgetFocusableContext( target ) {\n\t\tconst { onlyBrowserTabstops } = this.props;\n\t\tconst finder = onlyBrowserTabstops ? focus.tabbable : focus.focusable;\n\t\tconst focusables = finder.find( this.container );\n\n\t\tconst index = this.getFocusableIndex( focusables, target );\n\t\tif ( index > -1 && target ) {\n\t\t\treturn { index, target, focusables };\n\t\t}\n\t\treturn null;\n\t}\n\n\tgetFocusableIndex( focusables, target ) {\n\t\tconst directIndex = focusables.indexOf( target );\n\t\tif ( directIndex !== -1 ) {\n\t\t\treturn directIndex;\n\t\t}\n\t}\n\n\tonKeyDown( event ) {\n\t\tif ( this.props.onKeyDown ) {\n\t\t\tthis.props.onKeyDown( event );\n\t\t}\n\n\t\tconst { getFocusableContext } = this;\n\t\tconst {\n\t\t\tcycle = true,\n\t\t\teventToOffset,\n\t\t\tonNavigate = noop,\n\t\t\tstopNavigationEvents,\n\t\t} = this.props;\n\n\t\tconst offset = eventToOffset( event );\n\n\t\t// eventToOffset returns undefined if the event is not handled by the component.\n\t\tif ( offset !== undefined && stopNavigationEvents ) {\n\t\t\t// Prevents arrow key handlers bound to the document directly interfering.\n\t\t\tevent.stopImmediatePropagation();\n\n\t\t\t// When navigating a collection of items, prevent scroll containers\n\t\t\t// from scrolling. The preventDefault also prevents Voiceover from\n\t\t\t// 'handling' the event, as voiceover will try to use arrow keys\n\t\t\t// for highlighting text.\n\t\t\tconst targetRole = event.target.getAttribute( 'role' );\n\t\t\tconst targetHasMenuItemRole =\n\t\t\t\tMENU_ITEM_ROLES.includes( targetRole );\n\n\t\t\t// `preventDefault()` on tab to avoid having the browser move the focus\n\t\t\t// after this component has already moved it.\n\t\t\tconst isTab = event.code === 'Tab';\n\n\t\t\tif ( targetHasMenuItemRole || isTab ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tif ( ! offset ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst context = getFocusableContext(\n\t\t\tevent.target.ownerDocument.activeElement\n\t\t);\n\t\tif ( ! context ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { index, focusables } = context;\n\t\tconst nextIndex = cycle\n\t\t\t? cycleValue( index, focusables.length, offset )\n\t\t\t: index + offset;\n\t\tif ( nextIndex >= 0 && nextIndex < focusables.length ) {\n\t\t\tfocusables[ nextIndex ].focus();\n\t\t\tonNavigate( nextIndex, focusables[ nextIndex ] );\n\t\t}\n\t}\n\n\trender() {\n\t\tconst {\n\t\t\tchildren,\n\t\t\tstopNavigationEvents,\n\t\t\teventToOffset,\n\t\t\tonNavigate,\n\t\t\tonKeyDown,\n\t\t\tcycle,\n\t\t\tonlyBrowserTabstops,\n\t\t\tforwardedRef,\n\t\t\t...restProps\n\t\t} = this.props;\n\t\treturn (\n\t\t\t<div ref={ this.bindContainer } { ...restProps }>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t);\n\t}\n}\n\nconst forwardedNavigableContainer = ( props, ref ) => {\n\treturn <NavigableContainer { ...props } forwardedRef={ ref } />;\n};\nforwardedNavigableContainer.displayName = 'NavigableContainer';\n\nexport default forwardRef( forwardedNavigableContainer );\n"]}
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/navigable-container/container.tsx"],"names":["Component","forwardRef","focus","noop","MENU_ITEM_ROLES","cycleValue","value","total","offset","nextValue","NavigableContainer","constructor","args","onKeyDown","bind","bindContainer","getFocusableContext","getFocusableIndex","componentDidMount","container","addEventListener","componentWillUnmount","removeEventListener","ref","forwardedRef","props","current","target","onlyBrowserTabstops","finder","tabbable","focusable","focusables","find","index","indexOf","event","cycle","eventToOffset","onNavigate","stopNavigationEvents","undefined","stopImmediatePropagation","targetRole","getAttribute","targetHasMenuItemRole","includes","preventDefault","activeElement","ownerDocument","context","nextIndex","length","code","render","children","restProps","forwardedNavigableContainer","displayName"],"mappings":";;;AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,SAAT,EAAoBC,UAApB,QAAsC,oBAAtC;AACA,SAASC,KAAT,QAAsB,gBAAtB;AAEA;AACA;AACA;;AAGA,MAAMC,IAAI,GAAG,MAAM,CAAE,CAArB;;AACA,MAAMC,eAAe,GAAG,CAAE,UAAF,EAAc,eAAd,EAA+B,kBAA/B,CAAxB;;AAEA,SAASC,UAAT,CAAqBC,KAArB,EAAoCC,KAApC,EAAmDC,MAAnD,EAAoE;AACnE,QAAMC,SAAS,GAAGH,KAAK,GAAGE,MAA1B;;AACA,MAAKC,SAAS,GAAG,CAAjB,EAAqB;AACpB,WAAOF,KAAK,GAAGE,SAAf;AACA,GAFD,MAEO,IAAKA,SAAS,IAAIF,KAAlB,EAA0B;AACh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AAWA,WACC;AAAK,MAAA,GAAG,EAAG,KAAKV;AAAhB,OAAqCyC,SAArC,GACGD,QADH,CADD;AAKA;;AApJoE;;AAuJtE,MAAME,2BAA2B,GAAG,CACnChC,KADmC,EAEnCF,GAFmC,KAG/B;AACJ,SAAO,cAAC,kBAAD,eAAyBE,KAAzB;AAAiC,IAAA,YAAY,EAAGF;AAAhD,KAAP;AACA,CALD;;AAMAkC,2BAA2B,CAACC,WAA5B,GAA0C,oBAA1C;AAEA,eAAezD,UAAU,CAAEwD,2BAAF,CAAzB","sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { Component, forwardRef } from '@wordpress/element';\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport type { NavigableContainerProps } from './types';\n\nconst noop = () => {};\nconst MENU_ITEM_ROLES = [ 'menuitem', 'menuitemradio', 'menuitemcheckbox' ];\n\nfunction cycleValue( value: number, total: number, offset: number ) {\n\tconst nextValue = value + offset;\n\tif ( nextValue < 0 ) {\n\t\treturn total + nextValue;\n\t} else if ( nextValue >= total ) {\n\t\treturn nextValue - total;\n\t}\n\n\treturn nextValue;\n}\n\nclass NavigableContainer extends Component< NavigableContainerProps > {\n\tcontainer?: HTMLDivElement;\n\n\tconstructor( args: NavigableContainerProps ) {\n\t\tsuper( args );\n\t\tthis.onKeyDown = this.onKeyDown.bind( this );\n\t\tthis.bindContainer = this.bindContainer.bind( this );\n\n\t\tthis.getFocusableContext = this.getFocusableContext.bind( this );\n\t\tthis.getFocusableIndex = this.getFocusableIndex.bind( this );\n\t}\n\n\tcomponentDidMount() {\n\t\tif ( ! this.container ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// We use DOM event listeners instead of React event listeners\n\t\t// because we want to catch events from the underlying DOM tree\n\t\t// The React Tree can be different from the DOM tree when using\n\t\t// portals. Block Toolbars for instance are rendered in a separate\n\t\t// React Trees.\n\t\tthis.container.addEventListener( 'keydown', this.onKeyDown );\n\t}\n\n\tcomponentWillUnmount() {\n\t\tif ( ! this.container ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.container.removeEventListener( 'keydown', this.onKeyDown );\n\t}\n\n\tbindContainer( ref: HTMLDivElement ) {\n\t\tconst { forwardedRef } = this.props;\n\t\tthis.container = ref;\n\n\t\tif ( typeof forwardedRef === 'function' ) {\n\t\t\tforwardedRef( ref );\n\t\t} else if ( forwardedRef && 'current' in forwardedRef ) {\n\t\t\tforwardedRef.current = ref;\n\t\t}\n\t}\n\n\tgetFocusableContext( target: Element ) {\n\t\tif ( ! this.container ) {\n\t\t\treturn null;\n\t\t}\n\n\t\tconst { onlyBrowserTabstops } = this.props;\n\t\tconst finder = onlyBrowserTabstops ? focus.tabbable : focus.focusable;\n\t\tconst focusables = finder.find( this.container ) as HTMLElement[];\n\n\t\tconst index = this.getFocusableIndex( focusables, target );\n\t\tif ( index > -1 && target ) {\n\t\t\treturn { index, target, focusables };\n\t\t}\n\t\treturn null;\n\t}\n\n\tgetFocusableIndex( focusables: Element[], target: Element ) {\n\t\treturn focusables.indexOf( target );\n\t}\n\n\tonKeyDown( event: KeyboardEvent ) {\n\t\tif ( this.props.onKeyDown ) {\n\t\t\tthis.props.onKeyDown( event );\n\t\t}\n\n\t\tconst { getFocusableContext } = this;\n\t\tconst {\n\t\t\tcycle = true,\n\t\t\teventToOffset,\n\t\t\tonNavigate = noop,\n\t\t\tstopNavigationEvents,\n\t\t} = this.props;\n\n\t\tconst offset = eventToOffset( event );\n\n\t\t// eventToOffset returns undefined if the event is not handled by the component.\n\t\tif ( offset !== undefined && stopNavigationEvents ) {\n\t\t\t// Prevents arrow key handlers bound to the document directly interfering.\n\t\t\tevent.stopImmediatePropagation();\n\n\t\t\t// When navigating a collection of items, prevent scroll containers\n\t\t\t// from scrolling. The preventDefault also prevents Voiceover from\n\t\t\t// 'handling' the event, as voiceover will try to use arrow keys\n\t\t\t// for highlighting text.\n\t\t\tconst targetRole = (\n\t\t\t\tevent.target as HTMLDivElement | null\n\t\t\t )?.getAttribute( 'role' );\n\t\t\tconst targetHasMenuItemRole =\n\t\t\t\t!! targetRole && MENU_ITEM_ROLES.includes( targetRole );\n\n\t\t\tif ( targetHasMenuItemRole ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\n\t\tif ( ! offset ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst activeElement = ( event.target as HTMLElement | null )\n\t\t\t?.ownerDocument?.activeElement;\n\t\tif ( ! activeElement ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst context = getFocusableContext( activeElement );\n\t\tif ( ! context ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst { index, focusables } = context;\n\t\tconst nextIndex = cycle\n\t\t\t? cycleValue( index, focusables.length, offset )\n\t\t\t: index + offset;\n\n\t\tif ( nextIndex >= 0 && nextIndex < focusables.length ) {\n\t\t\tfocusables[ nextIndex ].focus();\n\t\t\tonNavigate( nextIndex, focusables[ nextIndex ] );\n\n\t\t\t// `preventDefault()` on tab to avoid having the browser move the focus\n\t\t\t// after this component has already moved it.\n\t\t\tif ( event.code === 'Tab' ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\t\t}\n\t}\n\n\trender() {\n\t\tconst {\n\t\t\tchildren,\n\t\t\tstopNavigationEvents,\n\t\t\teventToOffset,\n\t\t\tonNavigate,\n\t\t\tonKeyDown,\n\t\t\tcycle,\n\t\t\tonlyBrowserTabstops,\n\t\t\tforwardedRef,\n\t\t\t...restProps\n\t\t} = this.props;\n\t\treturn (\n\t\t\t<div ref={ this.bindContainer } { ...restProps }>\n\t\t\t\t{ children }\n\t\t\t</div>\n\t\t);\n\t}\n}\n\nconst forwardedNavigableContainer = (\n\tprops: NavigableContainerProps,\n\tref: ForwardedRef< HTMLDivElement >\n) => {\n\treturn <NavigableContainer { ...props } forwardedRef={ ref } />;\n};\nforwardedNavigableContainer.displayName = 'NavigableContainer';\n\nexport default forwardRef( forwardedNavigableContainer );\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/navigable-container/index.
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/navigable-container/index.tsx"],"names":["default","NavigableMenu","TabbableContainer"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,IAAIC,aAApB,QAAyC,QAAzC;AACA,SAASD,OAAO,IAAIE,iBAApB,QAA6C,YAA7C","sourcesContent":["/**\n * Internal Dependencies\n */\nexport { default as NavigableMenu } from './menu';\nexport { default as TabbableContainer } from './tabbable';\n"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import { createElement } from "@wordpress/element";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* External dependencies
|
|
6
|
+
*/
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* WordPress dependencies
|
|
@@ -11,7 +14,7 @@ import { forwardRef } from '@wordpress/element';
|
|
|
11
14
|
*/
|
|
12
15
|
|
|
13
16
|
import NavigableContainer from './container';
|
|
14
|
-
export function
|
|
17
|
+
export function UnforwardedNavigableMenu(_ref, ref) {
|
|
15
18
|
let {
|
|
16
19
|
role = 'menu',
|
|
17
20
|
orientation = 'vertical',
|
|
@@ -45,6 +48,8 @@ export function NavigableMenu(_ref, ref) {
|
|
|
45
48
|
// in an offset.
|
|
46
49
|
return 0;
|
|
47
50
|
}
|
|
51
|
+
|
|
52
|
+
return undefined;
|
|
48
53
|
};
|
|
49
54
|
|
|
50
55
|
return createElement(NavigableContainer, _extends({
|
|
@@ -52,9 +57,36 @@ export function NavigableMenu(_ref, ref) {
|
|
|
52
57
|
stopNavigationEvents: true,
|
|
53
58
|
onlyBrowserTabstops: false,
|
|
54
59
|
role: role,
|
|
55
|
-
"aria-orientation": role
|
|
60
|
+
"aria-orientation": role !== 'presentation' && (orientation === 'vertical' || orientation === 'horizontal') ? orientation : undefined,
|
|
56
61
|
eventToOffset: eventToOffset
|
|
57
62
|
}, rest));
|
|
58
63
|
}
|
|
59
|
-
|
|
64
|
+
/**
|
|
65
|
+
* A container for a navigable menu.
|
|
66
|
+
*
|
|
67
|
+
* ```jsx
|
|
68
|
+
* import {
|
|
69
|
+
* NavigableMenu,
|
|
70
|
+
* Button,
|
|
71
|
+
* } from '@wordpress/components';
|
|
72
|
+
*
|
|
73
|
+
* function onNavigate( index, target ) {
|
|
74
|
+
* console.log( `Navigates to ${ index }`, target );
|
|
75
|
+
* }
|
|
76
|
+
*
|
|
77
|
+
* const MyNavigableContainer = () => (
|
|
78
|
+
* <div>
|
|
79
|
+
* <span>Navigable Menu:</span>
|
|
80
|
+
* <NavigableMenu onNavigate={ onNavigate } orientation="horizontal">
|
|
81
|
+
* <Button variant="secondary">Item 1</Button>
|
|
82
|
+
* <Button variant="secondary">Item 2</Button>
|
|
83
|
+
* <Button variant="secondary">Item 3</Button>
|
|
84
|
+
* </NavigableMenu>
|
|
85
|
+
* </div>
|
|
86
|
+
* );
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
export const NavigableMenu = forwardRef(UnforwardedNavigableMenu);
|
|
91
|
+
export default NavigableMenu;
|
|
60
92
|
//# sourceMappingURL=menu.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/navigable-container/menu.
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/navigable-container/menu.tsx"],"names":["forwardRef","NavigableContainer","UnforwardedNavigableMenu","ref","role","orientation","rest","eventToOffset","evt","code","next","previous","includes","undefined","NavigableMenu"],"mappings":";;;AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,oBAA3B;AAEA;AACA;AACA;;AACA,OAAOC,kBAAP,MAA+B,aAA/B;AAGA,OAAO,SAASC,wBAAT,OAENC,GAFM,EAGL;AAAA,MAFD;AAAEC,IAAAA,IAAI,GAAG,MAAT;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AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMQ,aAAa,GAAGd,UAAU,CAAEE,wBAAF,CAAhC;AAEP,eAAeY,aAAf","sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport NavigableContainer from './container';\nimport type { NavigableMenuProps } from './types';\n\nexport function UnforwardedNavigableMenu(\n\t{ role = 'menu', orientation = 'vertical', ...rest }: NavigableMenuProps,\n\tref: ForwardedRef< any >\n) {\n\tconst eventToOffset = ( evt: KeyboardEvent ) => {\n\t\tconst { code } = evt;\n\n\t\tlet next = [ 'ArrowDown' ];\n\t\tlet previous = [ 'ArrowUp' ];\n\n\t\tif ( orientation === 'horizontal' ) {\n\t\t\tnext = [ 'ArrowRight' ];\n\t\t\tprevious = [ 'ArrowLeft' ];\n\t\t}\n\n\t\tif ( orientation === 'both' ) {\n\t\t\tnext = [ 'ArrowRight', 'ArrowDown' ];\n\t\t\tprevious = [ 'ArrowLeft', 'ArrowUp' ];\n\t\t}\n\n\t\tif ( next.includes( code ) ) {\n\t\t\treturn 1;\n\t\t} else if ( previous.includes( code ) ) {\n\t\t\treturn -1;\n\t\t} else if (\n\t\t\t[ 'ArrowDown', 'ArrowUp', 'ArrowLeft', 'ArrowRight' ].includes(\n\t\t\t\tcode\n\t\t\t)\n\t\t) {\n\t\t\t// Key press should be handled, e.g. have event propagation and\n\t\t\t// default behavior handled by NavigableContainer but not result\n\t\t\t// in an offset.\n\t\t\treturn 0;\n\t\t}\n\n\t\treturn undefined;\n\t};\n\n\treturn (\n\t\t<NavigableContainer\n\t\t\tref={ ref }\n\t\t\tstopNavigationEvents\n\t\t\tonlyBrowserTabstops={ false }\n\t\t\trole={ role }\n\t\t\taria-orientation={\n\t\t\t\trole !== 'presentation' &&\n\t\t\t\t( orientation === 'vertical' || orientation === 'horizontal' )\n\t\t\t\t\t? orientation\n\t\t\t\t\t: undefined\n\t\t\t}\n\t\t\teventToOffset={ eventToOffset }\n\t\t\t{ ...rest }\n\t\t/>\n\t);\n}\n\n/**\n * A container for a navigable menu.\n *\n * ```jsx\n * import {\n * NavigableMenu,\n * Button,\n * } from '@wordpress/components';\n *\n * function onNavigate( index, target ) {\n * console.log( `Navigates to ${ index }`, target );\n * }\n *\n * const MyNavigableContainer = () => (\n * <div>\n * <span>Navigable Menu:</span>\n * <NavigableMenu onNavigate={ onNavigate } orientation=\"horizontal\">\n * <Button variant=\"secondary\">Item 1</Button>\n * <Button variant=\"secondary\">Item 2</Button>\n * <Button variant=\"secondary\">Item 3</Button>\n * </NavigableMenu>\n * </div>\n * );\n * ```\n */\nexport const NavigableMenu = forwardRef( UnforwardedNavigableMenu );\n\nexport default NavigableMenu;\n"]}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
2
2
|
import { createElement } from "@wordpress/element";
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* External dependencies
|
|
6
|
+
*/
|
|
4
7
|
|
|
5
8
|
/**
|
|
6
9
|
* WordPress dependencies
|
|
@@ -11,7 +14,7 @@ import { forwardRef } from '@wordpress/element';
|
|
|
11
14
|
*/
|
|
12
15
|
|
|
13
16
|
import NavigableContainer from './container';
|
|
14
|
-
export function
|
|
17
|
+
export function UnforwardedTabbableContainer(_ref, ref) {
|
|
15
18
|
let {
|
|
16
19
|
eventToOffset,
|
|
17
20
|
...props
|
|
@@ -41,6 +44,8 @@ export function TabbableContainer(_ref, ref) {
|
|
|
41
44
|
if (eventToOffset) {
|
|
42
45
|
return eventToOffset(evt);
|
|
43
46
|
}
|
|
47
|
+
|
|
48
|
+
return undefined;
|
|
44
49
|
};
|
|
45
50
|
|
|
46
51
|
return createElement(NavigableContainer, _extends({
|
|
@@ -50,5 +55,41 @@ export function TabbableContainer(_ref, ref) {
|
|
|
50
55
|
eventToOffset: innerEventToOffset
|
|
51
56
|
}, props));
|
|
52
57
|
}
|
|
53
|
-
|
|
58
|
+
/**
|
|
59
|
+
* A container for tabbable elements.
|
|
60
|
+
*
|
|
61
|
+
* ```jsx
|
|
62
|
+
* import {
|
|
63
|
+
* TabbableContainer,
|
|
64
|
+
* Button,
|
|
65
|
+
* } from '@wordpress/components';
|
|
66
|
+
*
|
|
67
|
+
* function onNavigate( index, target ) {
|
|
68
|
+
* console.log( `Navigates to ${ index }`, target );
|
|
69
|
+
* }
|
|
70
|
+
*
|
|
71
|
+
* const MyTabbableContainer = () => (
|
|
72
|
+
* <div>
|
|
73
|
+
* <span>Tabbable Container:</span>
|
|
74
|
+
* <TabbableContainer onNavigate={ onNavigate }>
|
|
75
|
+
* <Button variant="secondary" tabIndex="0">
|
|
76
|
+
* Section 1
|
|
77
|
+
* </Button>
|
|
78
|
+
* <Button variant="secondary" tabIndex="0">
|
|
79
|
+
* Section 2
|
|
80
|
+
* </Button>
|
|
81
|
+
* <Button variant="secondary" tabIndex="0">
|
|
82
|
+
* Section 3
|
|
83
|
+
* </Button>
|
|
84
|
+
* <Button variant="secondary" tabIndex="0">
|
|
85
|
+
* Section 4
|
|
86
|
+
* </Button>
|
|
87
|
+
* </TabbableContainer>
|
|
88
|
+
* </div>
|
|
89
|
+
* );
|
|
90
|
+
* ```
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
export const TabbableContainer = forwardRef(UnforwardedTabbableContainer);
|
|
94
|
+
export default TabbableContainer;
|
|
54
95
|
//# sourceMappingURL=tabbable.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/components/src/navigable-container/tabbable.
|
|
1
|
+
{"version":3,"sources":["@wordpress/components/src/navigable-container/tabbable.tsx"],"names":["forwardRef","NavigableContainer","UnforwardedTabbableContainer","ref","eventToOffset","props","innerEventToOffset","evt","code","shiftKey","undefined","TabbableContainer"],"mappings":";;;AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,UAAT,QAA2B,oBAA3B;AAEA;AACA;AACA;;AACA,OAAOC,kBAAP,MAA+B,aAA/B;AAGA,OAAO,SAASC,4BAAT,OAENC,GAFM,EAGL;AAAA,MAFD;AAAEC,IAAAA,aAAF;AAAiB,OAAGC;AAApB,GAEC;;AACD,QAAMC,kBAAkB,GAAKC,GAAF,IAA0B;AACpD,UAAM;AAAEC,MAAAA,IAAF;AAAQC,MAAAA;AAAR,QAAqBF,GAA3B;;AACA,QAAK,UAAUC,IAAf,EAAsB;AACrB,aAAOC,QAAQ,GAAG,CAAC,CAAJ,GAAQ,CAAvB;AACA,KAJmD,CAMpD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,QAAKL,aAAL,EAAqB;AACpB,aAAOA,aAAa,CAAEG,GAAF,CAApB;AACA;;AAED,WAAOG,SAAP;AACA,GAtBD;;AAwBA,SACC,cAAC,kBAAD;AACC,IAAA,GAAG,EAAGP,GADP;AAEC,IAAA,oBAAoB,MAFrB;AAGC,IAAA,mBAAmB,MAHpB;AAIC,IAAA,aAAa,EAAGG;AAJjB,KAKMD,KALN,EADD;AASA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMM,iBAAiB,GAAGX,UAAU,CAAEE,4BAAF,CAApC;AAEP,eAAeS,iBAAf","sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport NavigableContainer from './container';\nimport type { TabbableContainerProps } from './types';\n\nexport function UnforwardedTabbableContainer(\n\t{ eventToOffset, ...props }: TabbableContainerProps,\n\tref: ForwardedRef< any >\n) {\n\tconst innerEventToOffset = ( evt: KeyboardEvent ) => {\n\t\tconst { code, shiftKey } = evt;\n\t\tif ( 'Tab' === code ) {\n\t\t\treturn shiftKey ? -1 : 1;\n\t\t}\n\n\t\t// Allow custom handling of keys besides Tab.\n\t\t//\n\t\t// By default, TabbableContainer will move focus forward on Tab and\n\t\t// backward on Shift+Tab. The handler below will be used for all other\n\t\t// events. The semantics for `eventToOffset`'s return\n\t\t// values are the following:\n\t\t//\n\t\t// - +1: move focus forward\n\t\t// - -1: move focus backward\n\t\t// - 0: don't move focus, but acknowledge event and thus stop it\n\t\t// - undefined: do nothing, let the event propagate.\n\t\tif ( eventToOffset ) {\n\t\t\treturn eventToOffset( evt );\n\t\t}\n\n\t\treturn undefined;\n\t};\n\n\treturn (\n\t\t<NavigableContainer\n\t\t\tref={ ref }\n\t\t\tstopNavigationEvents\n\t\t\tonlyBrowserTabstops\n\t\t\teventToOffset={ innerEventToOffset }\n\t\t\t{ ...props }\n\t\t/>\n\t);\n}\n\n/**\n * A container for tabbable elements.\n *\n * ```jsx\n * import {\n * TabbableContainer,\n * Button,\n * } from '@wordpress/components';\n *\n * function onNavigate( index, target ) {\n * console.log( `Navigates to ${ index }`, target );\n * }\n *\n * const MyTabbableContainer = () => (\n * <div>\n * <span>Tabbable Container:</span>\n * <TabbableContainer onNavigate={ onNavigate }>\n * <Button variant=\"secondary\" tabIndex=\"0\">\n * Section 1\n * </Button>\n * <Button variant=\"secondary\" tabIndex=\"0\">\n * Section 2\n * </Button>\n * <Button variant=\"secondary\" tabIndex=\"0\">\n * Section 3\n * </Button>\n * <Button variant=\"secondary\" tabIndex=\"0\">\n * Section 4\n * </Button>\n * </TabbableContainer>\n * </div>\n * );\n * ```\n */\nexport const TabbableContainer = forwardRef( UnforwardedTabbableContainer );\n\nexport default TabbableContainer;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[]}
|
|
@@ -4,12 +4,13 @@ import { createElement, Fragment } from "@wordpress/element";
|
|
|
4
4
|
/**
|
|
5
5
|
* External dependencies
|
|
6
6
|
*/
|
|
7
|
+
import classnames from 'classnames';
|
|
7
8
|
import { paramCase as kebabCase } from 'change-case';
|
|
8
9
|
/**
|
|
9
10
|
* WordPress dependencies
|
|
10
11
|
*/
|
|
11
12
|
|
|
12
|
-
import { useState, useRef, useEffect, useCallback } from '@wordpress/element';
|
|
13
|
+
import { useState, useRef, useEffect, useCallback, useMemo } from '@wordpress/element';
|
|
13
14
|
import { __, sprintf } from '@wordpress/i18n';
|
|
14
15
|
import { lineSolid, moreVertical, plus } from '@wordpress/icons';
|
|
15
16
|
import { __experimentalUseFocusOutside as useFocusOutside, useDebounce } from '@wordpress/compose';
|
|
@@ -86,14 +87,19 @@ function ColorPickerPopover(_ref2) {
|
|
|
86
87
|
isGradient,
|
|
87
88
|
element,
|
|
88
89
|
onChange,
|
|
90
|
+
popoverProps: receivedPopoverProps,
|
|
89
91
|
onClose = () => {}
|
|
90
92
|
} = _ref2;
|
|
91
|
-
|
|
92
|
-
|
|
93
|
+
const popoverProps = useMemo(() => ({
|
|
94
|
+
shift: true,
|
|
93
95
|
offset: 20,
|
|
94
|
-
|
|
96
|
+
placement: 'left-start',
|
|
97
|
+
...receivedPopoverProps,
|
|
98
|
+
className: classnames('components-palette-edit__popover', receivedPopoverProps === null || receivedPopoverProps === void 0 ? void 0 : receivedPopoverProps.className)
|
|
99
|
+
}), [receivedPopoverProps]);
|
|
100
|
+
return createElement(Popover, _extends({}, popoverProps, {
|
|
95
101
|
onClose: onClose
|
|
96
|
-
}, !isGradient && createElement(ColorPicker, {
|
|
102
|
+
}), !isGradient && createElement(ColorPicker, {
|
|
97
103
|
color: element.color,
|
|
98
104
|
enableAlpha: true,
|
|
99
105
|
onChange: newColor => {
|
|
@@ -124,15 +130,24 @@ function Option(_ref3) {
|
|
|
124
130
|
onStartEditing,
|
|
125
131
|
onRemove,
|
|
126
132
|
onStopEditing,
|
|
133
|
+
popoverProps: receivedPopoverProps,
|
|
127
134
|
slugPrefix,
|
|
128
135
|
isGradient
|
|
129
136
|
} = _ref3;
|
|
130
137
|
const focusOutsideProps = useFocusOutside(onStopEditing);
|
|
131
|
-
const value = isGradient ? element.gradient : element.color;
|
|
138
|
+
const value = isGradient ? element.gradient : element.color; // Use internal state instead of a ref to make sure that the component
|
|
139
|
+
// re-renders when the popover's anchor updates.
|
|
140
|
+
|
|
141
|
+
const [popoverAnchor, setPopoverAnchor] = useState(null);
|
|
142
|
+
const popoverProps = useMemo(() => ({ ...receivedPopoverProps,
|
|
143
|
+
// Use the custom palette color item as the popover anchor.
|
|
144
|
+
anchor: popoverAnchor
|
|
145
|
+
}), [popoverAnchor, receivedPopoverProps]);
|
|
132
146
|
return createElement(PaletteItem, _extends({
|
|
133
147
|
className: isEditing ? 'is-selected' : undefined,
|
|
134
148
|
as: "div",
|
|
135
|
-
onClick: onStartEditing
|
|
149
|
+
onClick: onStartEditing,
|
|
150
|
+
ref: setPopoverAnchor
|
|
136
151
|
}, isEditing ? { ...focusOutsideProps
|
|
137
152
|
} : {
|
|
138
153
|
style: {
|
|
@@ -160,7 +175,8 @@ function Option(_ref3) {
|
|
|
160
175
|
}))), isEditing && createElement(ColorPickerPopover, {
|
|
161
176
|
isGradient: isGradient,
|
|
162
177
|
onChange: onChange,
|
|
163
|
-
element: element
|
|
178
|
+
element: element,
|
|
179
|
+
popoverProps: popoverProps
|
|
164
180
|
}));
|
|
165
181
|
}
|
|
166
182
|
|
|
@@ -182,7 +198,8 @@ function PaletteEditListView(_ref5) {
|
|
|
182
198
|
setEditingElement,
|
|
183
199
|
canOnlyChangeValues,
|
|
184
200
|
slugPrefix,
|
|
185
|
-
isGradient
|
|
201
|
+
isGradient,
|
|
202
|
+
popoverProps
|
|
186
203
|
} = _ref5;
|
|
187
204
|
// When unmounting the component if there are empty elements (the user did not complete the insertion) clean them.
|
|
188
205
|
const elementsReference = useRef();
|
|
@@ -242,7 +259,8 @@ function PaletteEditListView(_ref5) {
|
|
|
242
259
|
setEditingElement(null);
|
|
243
260
|
}
|
|
244
261
|
},
|
|
245
|
-
slugPrefix: slugPrefix
|
|
262
|
+
slugPrefix: slugPrefix,
|
|
263
|
+
popoverProps: popoverProps
|
|
246
264
|
}))));
|
|
247
265
|
}
|
|
248
266
|
|
|
@@ -278,7 +296,8 @@ export function PaletteEdit(_ref6) {
|
|
|
278
296
|
emptyMessage,
|
|
279
297
|
canOnlyChangeValues,
|
|
280
298
|
canReset,
|
|
281
|
-
slugPrefix = ''
|
|
299
|
+
slugPrefix = '',
|
|
300
|
+
popoverProps
|
|
282
301
|
} = _ref6;
|
|
283
302
|
const isGradient = !!gradients;
|
|
284
303
|
const elements = isGradient ? gradients : colors;
|
|
@@ -375,7 +394,8 @@ export function PaletteEdit(_ref6) {
|
|
|
375
394
|
editingElement: editingElement,
|
|
376
395
|
setEditingElement: setEditingElement,
|
|
377
396
|
slugPrefix: slugPrefix,
|
|
378
|
-
isGradient: isGradient
|
|
397
|
+
isGradient: isGradient,
|
|
398
|
+
popoverProps: popoverProps
|
|
379
399
|
}), !isEditing && editingElement !== null && createElement(ColorPickerPopover, {
|
|
380
400
|
isGradient: isGradient,
|
|
381
401
|
onClose: () => setEditingElement(null),
|
|
@@ -389,7 +409,8 @@ export function PaletteEdit(_ref6) {
|
|
|
389
409
|
return currentElement;
|
|
390
410
|
}));
|
|
391
411
|
},
|
|
392
|
-
element: elements[editingElement !== null && editingElement !== void 0 ? editingElement : -1]
|
|
412
|
+
element: elements[editingElement !== null && editingElement !== void 0 ? editingElement : -1],
|
|
413
|
+
popoverProps: popoverProps
|
|
393
414
|
}), !isEditing && (isGradient ? createElement(GradientPicker, {
|
|
394
415
|
__nextHasNoMargin: true,
|
|
395
416
|
gradients: gradients,
|