@pingux/astro 2.32.0-alpha.8 → 2.32.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/lib/cjs/components/TreeView/TreeView.js +99 -11
- package/lib/cjs/components/TreeView/TreeView.stories.js +23 -10
- package/lib/cjs/components/TreeView/TreeView.styles.js +22 -2
- package/lib/cjs/components/TreeView/TreeView.test.js +91 -11
- package/lib/cjs/components/TreeView/TreeViewItem.js +112 -14
- package/lib/cjs/components/TreeView/TreeViewKeyboardDelegate.js +200 -0
- package/lib/cjs/components/TreeView/TreeViewKeyboardDelegate.test.js +511 -0
- package/lib/cjs/components/TreeView/TreeViewRow.js +20 -5
- package/lib/cjs/components/TreeView/TreeViewSection.js +164 -16
- package/lib/cjs/components/TreeView/TreeViewWrapper.js +40 -0
- package/lib/cjs/hooks/useField/index.d.ts +1 -0
- package/lib/cjs/hooks/useField/useField.d.ts +1686 -0
- package/lib/cjs/hooks/useField/useField.js +7 -16
- package/lib/cjs/hooks/useField/useField.test.d.ts +1 -0
- package/lib/cjs/hooks/useField/useField.test.js +6 -6
- package/lib/cjs/hooks/useModalState/index.d.ts +1 -0
- package/lib/cjs/hooks/useModalState/useModalState.d.ts +21 -0
- package/lib/cjs/hooks/useModalState/useModalState.js +0 -9
- package/lib/cjs/hooks/useModalState/useModalState.test.d.ts +1 -0
- package/lib/cjs/hooks/useMountTransition/index.d.ts +1 -0
- package/lib/cjs/hooks/useMountTransition/useMountTransition.d.ts +14 -0
- package/lib/cjs/hooks/useMountTransition/useMountTransition.js +0 -9
- package/lib/cjs/hooks/useMountTransition/useMountTransition.test.d.ts +1 -0
- package/lib/cjs/hooks/useMountTransition/useMountTransition.test.js +2 -2
- package/lib/cjs/hooks/useStatusClasses/index.d.ts +1 -0
- package/lib/cjs/hooks/useStatusClasses/useStatusClasses.d.ts +18 -0
- package/lib/cjs/hooks/useStatusClasses/useStatusClasses.js +0 -9
- package/lib/cjs/hooks/useStatusClasses/useStatusClasses.test.d.ts +1 -0
- package/lib/components/TreeView/TreeView.js +100 -12
- package/lib/components/TreeView/TreeView.stories.js +23 -10
- package/lib/components/TreeView/TreeView.styles.js +22 -2
- package/lib/components/TreeView/TreeView.test.js +92 -12
- package/lib/components/TreeView/TreeViewItem.js +111 -14
- package/lib/components/TreeView/TreeViewKeyboardDelegate.js +176 -0
- package/lib/components/TreeView/TreeViewKeyboardDelegate.test.js +496 -0
- package/lib/components/TreeView/TreeViewRow.js +20 -5
- package/lib/components/TreeView/TreeViewSection.js +161 -16
- package/lib/components/TreeView/TreeViewWrapper.js +31 -0
- package/lib/hooks/useField/useField.js +7 -16
- package/lib/hooks/useField/useField.test.js +6 -6
- package/lib/hooks/useModalState/useModalState.js +0 -10
- package/lib/hooks/useMountTransition/useMountTransition.js +0 -10
- package/lib/hooks/useMountTransition/useMountTransition.test.js +2 -2
- package/lib/hooks/useStatusClasses/useStatusClasses.js +0 -10
- package/package.json +1 -1
@@ -1,9 +1,13 @@
|
|
1
1
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
2
|
import React from 'react';
|
3
3
|
import { useTreeData } from 'react-stately';
|
4
|
+
import userEvent from '@testing-library/user-event';
|
5
|
+
import PropTypes from 'prop-types';
|
4
6
|
import { Item } from '../../index';
|
5
|
-
import {
|
7
|
+
import { render, screen } from '../../utils/testUtils/testWrapper';
|
6
8
|
import { SectionOrItemRender } from './TreeView';
|
9
|
+
import { refArray } from './TreeViewKeyboardDelegate.test';
|
10
|
+
import { addRefToArrayHelper, removeRefFromArrayHelper } from './TreeViewSection';
|
7
11
|
import TreeView from '.';
|
8
12
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
9
13
|
var testId = 'test-TreeView';
|
@@ -40,9 +44,12 @@ var data = [{
|
|
40
44
|
}, {
|
41
45
|
title: 'Single Item'
|
42
46
|
}];
|
47
|
+
var singleData = [{
|
48
|
+
title: 'Single Item'
|
49
|
+
}];
|
43
50
|
var TreeViewComponent = function TreeViewComponent(props) {
|
44
51
|
var tree = useTreeData({
|
45
|
-
initialItems: data,
|
52
|
+
initialItems: props.data,
|
46
53
|
getKey: function getKey(item) {
|
47
54
|
return item.title;
|
48
55
|
},
|
@@ -62,6 +69,9 @@ var TreeViewComponent = function TreeViewComponent(props) {
|
|
62
69
|
});
|
63
70
|
});
|
64
71
|
};
|
72
|
+
TreeViewComponent.propTypes = {
|
73
|
+
data: PropTypes.arrayOf(PropTypes.shape({}))
|
74
|
+
};
|
65
75
|
var offsetWidth;
|
66
76
|
var offsetHeight;
|
67
77
|
var scrollHeight;
|
@@ -95,16 +105,20 @@ test('TreeView component does load', function () {
|
|
95
105
|
expect(element).toBeInTheDocument();
|
96
106
|
});
|
97
107
|
test('Can select an Item using the mouse', function () {
|
98
|
-
render(___EmotionJSX(TreeViewComponent,
|
108
|
+
render(___EmotionJSX(TreeViewComponent, {
|
109
|
+
data: data
|
110
|
+
}));
|
99
111
|
var element = screen.queryByRole('treegrid');
|
100
112
|
expect(element).toBeInTheDocument();
|
101
113
|
var peopleElement = screen.queryByText('Single Item');
|
102
114
|
expect(peopleElement).not.toHaveClass('is-selected');
|
103
|
-
|
115
|
+
userEvent.click(peopleElement);
|
104
116
|
expect(peopleElement).toHaveClass('is-selected');
|
105
117
|
});
|
106
118
|
test('Renders both Sections and Items', function () {
|
107
|
-
render(___EmotionJSX(TreeViewComponent,
|
119
|
+
render(___EmotionJSX(TreeViewComponent, {
|
120
|
+
data: data
|
121
|
+
}));
|
108
122
|
var peopleElement = screen.getByText('Single Item');
|
109
123
|
expect(peopleElement).toBeInTheDocument();
|
110
124
|
var plantElement = screen.getByText('Other');
|
@@ -113,7 +127,9 @@ test('Renders both Sections and Items', function () {
|
|
113
127
|
expect(allListItems).toHaveLength(3);
|
114
128
|
});
|
115
129
|
test('Can expand an Item using the mouse', function () {
|
116
|
-
render(___EmotionJSX(TreeViewComponent,
|
130
|
+
render(___EmotionJSX(TreeViewComponent, {
|
131
|
+
data: data
|
132
|
+
}));
|
117
133
|
|
118
134
|
// The children of collapsed sections will not
|
119
135
|
// be rendered by default.
|
@@ -122,47 +138,91 @@ test('Can expand an Item using the mouse', function () {
|
|
122
138
|
// Clicking the dropdown icon, renders the children
|
123
139
|
// of the collapsed section.
|
124
140
|
var buttons = screen.queryAllByRole('button');
|
125
|
-
|
141
|
+
userEvent.click(buttons[0]);
|
126
142
|
expect(screen.queryByText(data[0].items[0].title)).toBeInTheDocument();
|
127
143
|
});
|
128
144
|
test('onExpandedChange change prop calls when used', function () {
|
129
145
|
var onPress = jest.fn();
|
130
146
|
render(___EmotionJSX(TreeViewComponent, {
|
147
|
+
data: data,
|
131
148
|
onExpandedChange: onPress
|
132
149
|
}));
|
133
150
|
expect(onPress).not.toHaveBeenCalled();
|
134
151
|
var buttons = screen.queryAllByRole('button');
|
135
|
-
|
152
|
+
userEvent.click(buttons[0]);
|
136
153
|
expect(onPress).toHaveBeenCalled();
|
137
154
|
});
|
138
155
|
test('disabledKeys prop disables items in the tree -- rendering them unclickable', function () {
|
139
156
|
render(___EmotionJSX(TreeViewComponent, {
|
157
|
+
data: data,
|
140
158
|
disabledKeys: ['Single Item']
|
141
159
|
}));
|
142
160
|
var listItems = screen.queryAllByRole('treeitem');
|
143
161
|
var thisItem = listItems[2];
|
144
162
|
expect(thisItem).not.toHaveClass('is-selected');
|
145
163
|
expect(thisItem).toHaveAttribute('aria-disabled', 'true');
|
146
|
-
|
147
|
-
fireEvent.mouseUp(thisItem);
|
164
|
+
userEvent.click(thisItem);
|
148
165
|
expect(thisItem).not.toHaveClass('is-selected');
|
149
166
|
expect(thisItem).toHaveAttribute('aria-selected', 'false');
|
150
167
|
});
|
151
168
|
test('displays correct aria attributes', function () {
|
152
|
-
render(___EmotionJSX(TreeViewComponent,
|
169
|
+
render(___EmotionJSX(TreeViewComponent, {
|
170
|
+
data: data
|
171
|
+
}));
|
153
172
|
var listItems = screen.getAllByRole('treeitem');
|
154
173
|
var lastTreeItem = listItems[2];
|
155
174
|
expect(lastTreeItem).toHaveAttribute('aria-level', '1');
|
156
175
|
expect(lastTreeItem).toHaveAttribute('aria-posinset', '3');
|
157
176
|
expect(lastTreeItem).toHaveAttribute('aria-setsize', '3');
|
158
177
|
var buttons = screen.queryAllByRole('button');
|
159
|
-
|
178
|
+
userEvent.click(buttons[1]);
|
160
179
|
var expandedItems = screen.getAllByRole('treeitem');
|
161
180
|
var nestedItem = expandedItems[2];
|
162
181
|
expect(nestedItem).toHaveAttribute('aria-level', '2');
|
163
182
|
expect(nestedItem).toHaveAttribute('aria-posinset', '1');
|
164
183
|
expect(nestedItem).toHaveAttribute('aria-setsize', '1');
|
165
184
|
});
|
185
|
+
test('onKeyDown calls passed in prop call back function', function () {
|
186
|
+
var callback = jest.fn();
|
187
|
+
render(___EmotionJSX(TreeViewComponent, {
|
188
|
+
data: data,
|
189
|
+
onKeyDown: callback
|
190
|
+
}));
|
191
|
+
var listItems = screen.queryAllByRole('treeitem');
|
192
|
+
var thisItem = listItems[0];
|
193
|
+
userEvent.type(thisItem, '{arrowleft}');
|
194
|
+
expect(callback).toHaveBeenCalled();
|
195
|
+
});
|
196
|
+
test('onKeyDown calls passed in prop call back function', function () {
|
197
|
+
var callback = jest.fn();
|
198
|
+
render(___EmotionJSX(TreeViewComponent, {
|
199
|
+
data: data,
|
200
|
+
onKeyDown: callback
|
201
|
+
}));
|
202
|
+
var listItems = screen.queryAllByRole('treeitem');
|
203
|
+
var thisItem = listItems[2];
|
204
|
+
userEvent.type(thisItem, '{arrowleft}');
|
205
|
+
expect(callback).toHaveBeenCalled();
|
206
|
+
});
|
207
|
+
test('onKeyDown does not call passed in prop call back function', function () {
|
208
|
+
var callback = jest.fn();
|
209
|
+
render(___EmotionJSX(TreeViewComponent, {
|
210
|
+
data: data
|
211
|
+
}));
|
212
|
+
var listItems = screen.queryAllByRole('treeitem');
|
213
|
+
var thisItem = listItems[2];
|
214
|
+
userEvent.type(thisItem, '{arrowleft}');
|
215
|
+
expect(callback).not.toHaveBeenCalled();
|
216
|
+
});
|
217
|
+
test('items still render if there is only one provided', function () {
|
218
|
+
var callback = jest.fn();
|
219
|
+
render(___EmotionJSX(TreeViewComponent, {
|
220
|
+
data: singleData,
|
221
|
+
onKeyDown: callback
|
222
|
+
}));
|
223
|
+
var listItem = screen.queryByText('Single Item');
|
224
|
+
expect(listItem).toBeInTheDocument();
|
225
|
+
});
|
166
226
|
var firstJSX = ___EmotionJSX("p", null, "first");
|
167
227
|
var secondJSX = ___EmotionJSX("p", null, "second");
|
168
228
|
test('Section or Item Render renders first item if condition is true', function () {
|
@@ -176,4 +236,24 @@ test('Section or Item Render renders second item if condition is false', functio
|
|
176
236
|
var thisItem = screen.getByText('second');
|
177
237
|
expect(thisItem).toBeInTheDocument();
|
178
238
|
expect(screen.queryByText('first')).not.toBeInTheDocument();
|
239
|
+
});
|
240
|
+
test('Handler function removes ref from array', function () {
|
241
|
+
var newArray = removeRefFromArrayHelper(refArray, 'test');
|
242
|
+
expect(newArray).toHaveLength(2);
|
243
|
+
});
|
244
|
+
test('Handler function does not remove ref from array', function () {
|
245
|
+
var newArray = removeRefFromArrayHelper(refArray, 'anothertest');
|
246
|
+
expect(newArray).toHaveLength(3);
|
247
|
+
});
|
248
|
+
test('Handler function does add ref to array', function () {
|
249
|
+
var newArray = addRefToArrayHelper(refArray, 'yetanothertest', {
|
250
|
+
current: 'currentlystilltesting'
|
251
|
+
});
|
252
|
+
expect(newArray).toHaveLength(4);
|
253
|
+
});
|
254
|
+
test('Handler function does not add ref to array', function () {
|
255
|
+
var newArray = addRefToArrayHelper(refArray, 'test', {
|
256
|
+
current: 'currentlystilltesting'
|
257
|
+
});
|
258
|
+
expect(newArray).toHaveLength(3);
|
179
259
|
});
|
@@ -1,15 +1,61 @@
|
|
1
1
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
|
-
import React, { forwardRef, useImperativeHandle, useRef } from 'react';
|
2
|
+
import React, { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
|
3
3
|
import FileIcon from '@pingux/mdi-react/FileIcon';
|
4
|
+
import { useFocusRing } from '@react-aria/focus';
|
4
5
|
import { useOption } from '@react-aria/listbox';
|
6
|
+
import { mergeProps } from '@react-aria/utils';
|
5
7
|
import PropTypes from 'prop-types';
|
6
8
|
import { useTreeViewContext } from '../../context/TreeViewContext';
|
9
|
+
import { useStatusClasses } from '../../hooks';
|
7
10
|
import { Box } from '../../index';
|
11
|
+
import { itemPressHandlers } from './TreeViewKeyboardDelegate';
|
8
12
|
import TreeViewRow from './TreeViewRow';
|
13
|
+
import { addRefToArrayHelper, removeRefFromArrayHelper } from './TreeViewSection';
|
9
14
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
15
|
+
export var onKeyDownItem = function onKeyDownItem(e, state, key, tree, isSelected, isExpanded, focusManager, flatKeyArray, refArray, pageLength) {
|
16
|
+
switch (e.which) {
|
17
|
+
case 32:
|
18
|
+
itemPressHandlers.onSpacePress(e, tree, key, isSelected);
|
19
|
+
break;
|
20
|
+
case 38:
|
21
|
+
itemPressHandlers.onUpPress(e, key, refArray, flatKeyArray);
|
22
|
+
e.preventDefault();
|
23
|
+
e.stopPropagation();
|
24
|
+
break;
|
25
|
+
case 40:
|
26
|
+
itemPressHandlers.onDownPress(e, key, refArray, flatKeyArray);
|
27
|
+
e.preventDefault();
|
28
|
+
e.stopPropagation();
|
29
|
+
break;
|
30
|
+
case 37:
|
31
|
+
case 39:
|
32
|
+
itemPressHandlers.onRightLeftItemPress(e);
|
33
|
+
break;
|
34
|
+
case 33:
|
35
|
+
itemPressHandlers.onPageUpPress(e, key, flatKeyArray, refArray, pageLength);
|
36
|
+
break;
|
37
|
+
case 34:
|
38
|
+
itemPressHandlers.onPageDownPress(e, key, flatKeyArray, refArray, pageLength);
|
39
|
+
break;
|
40
|
+
case 36:
|
41
|
+
itemPressHandlers.onHomePress(key, flatKeyArray, refArray);
|
42
|
+
e.preventDefault();
|
43
|
+
e.stopPropagation();
|
44
|
+
break;
|
45
|
+
case 35:
|
46
|
+
itemPressHandlers.onEndPress(key, flatKeyArray, refArray);
|
47
|
+
e.preventDefault();
|
48
|
+
e.stopPropagation();
|
49
|
+
break;
|
50
|
+
default:
|
51
|
+
break;
|
52
|
+
}
|
53
|
+
};
|
10
54
|
var TreeViewItem = /*#__PURE__*/forwardRef(function (props, ref) {
|
11
55
|
var item = props.item,
|
12
56
|
title = props.title,
|
57
|
+
focusManager = props.focusManager,
|
58
|
+
onKeyDown = props.onKeyDown,
|
13
59
|
level = props.level,
|
14
60
|
position = props.position,
|
15
61
|
setSize = props.setSize;
|
@@ -19,8 +65,16 @@ var TreeViewItem = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
19
65
|
useImperativeHandle(ref, function () {
|
20
66
|
return treeItemRef.current;
|
21
67
|
});
|
68
|
+
|
69
|
+
/* istanbul ignore next */
|
22
70
|
var _useTreeViewContext = useTreeViewContext(),
|
23
|
-
state = _useTreeViewContext.state
|
71
|
+
state = _useTreeViewContext.state,
|
72
|
+
tree = _useTreeViewContext.tree,
|
73
|
+
refArray = _useTreeViewContext.refArray,
|
74
|
+
setRefs = _useTreeViewContext.setRefs,
|
75
|
+
flatKeyArray = _useTreeViewContext.flatKeyArray,
|
76
|
+
pageLength = _useTreeViewContext.pageLength,
|
77
|
+
setLastFocusedItem = _useTreeViewContext.setLastFocusedItem;
|
24
78
|
var _useOption = useOption({
|
25
79
|
key: key
|
26
80
|
}, state, treeItemRef),
|
@@ -28,24 +82,65 @@ var TreeViewItem = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
28
82
|
isSelected = _useOption.isSelected,
|
29
83
|
isDisabled = _useOption.isDisabled;
|
30
84
|
var isExpanded = state.expandedKeys.has(key);
|
85
|
+
var onKeyDownFunction = function onKeyDownFunction(e) {
|
86
|
+
/* istanbul ignore next */
|
87
|
+
onKeyDownItem(e, state, key, tree, isSelected, isExpanded, focusManager, flatKeyArray, refArray, pageLength);
|
88
|
+
if (onKeyDown) {
|
89
|
+
onKeyDown(e, key);
|
90
|
+
}
|
91
|
+
};
|
92
|
+
|
93
|
+
// ignoring from tests, but this is actually being unit tested
|
94
|
+
/* istanbul ignore next */
|
95
|
+
var removeRefFromArray = function removeRefFromArray() {
|
96
|
+
setRefs(function (prev) {
|
97
|
+
return removeRefFromArrayHelper(prev, key);
|
98
|
+
});
|
99
|
+
};
|
100
|
+
var addRefToArray = function addRefToArray() {
|
101
|
+
setRefs(function (prev) {
|
102
|
+
return addRefToArrayHelper(prev, key, treeItemRef);
|
103
|
+
});
|
104
|
+
};
|
105
|
+
|
106
|
+
// adds and removes refs on mount and dismount
|
107
|
+
/* istanbul ignore next */
|
108
|
+
useEffect(function () {
|
109
|
+
// this runs on mount
|
110
|
+
addRefToArray();
|
111
|
+
return function () {
|
112
|
+
// this runs on cleanup
|
113
|
+
removeRefFromArray(key, refArray);
|
114
|
+
};
|
115
|
+
}, []);
|
116
|
+
var _useFocusRing = useFocusRing(),
|
117
|
+
isFocusVisible = _useFocusRing.isFocusVisible,
|
118
|
+
focusProps = _useFocusRing.focusProps;
|
119
|
+
var mergedProps = mergeProps(focusProps, optionProps, {
|
120
|
+
onFocus: function onFocus() {
|
121
|
+
return setLastFocusedItem(key);
|
122
|
+
}
|
123
|
+
});
|
124
|
+
var _useStatusClasses = useStatusClasses('', {
|
125
|
+
isFocused: isFocusVisible
|
126
|
+
}),
|
127
|
+
classNames = _useStatusClasses.classNames;
|
31
128
|
return ___EmotionJSX(Box, _extends({
|
32
129
|
as: "li",
|
33
130
|
isRow: true,
|
34
131
|
ref: treeItemRef,
|
35
|
-
"aria-disabled": isDisabled
|
132
|
+
"aria-disabled": isDisabled
|
133
|
+
}, mergedProps, {
|
134
|
+
role: "treeitem",
|
135
|
+
variant: "treeView.wrapper",
|
136
|
+
className: classNames,
|
137
|
+
"aria-selected": isSelected,
|
36
138
|
"aria-level": level,
|
37
139
|
"aria-posinset": position + 1,
|
38
|
-
"aria-setsize": setSize
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
width: '100%',
|
43
|
-
ml: '36px',
|
44
|
-
':not(:last-child)': {
|
45
|
-
pb: 'sm'
|
46
|
-
}
|
47
|
-
},
|
48
|
-
"aria-selected": isSelected
|
140
|
+
"aria-setsize": setSize,
|
141
|
+
onKeyDown: function onKeyDown(e) {
|
142
|
+
return onKeyDownFunction(e);
|
143
|
+
}
|
49
144
|
}), ___EmotionJSX(TreeViewRow, {
|
50
145
|
item: item,
|
51
146
|
title: title,
|
@@ -59,8 +154,10 @@ TreeViewItem.propTypes = {
|
|
59
154
|
item: PropTypes.shape({
|
60
155
|
key: PropTypes.string
|
61
156
|
}),
|
157
|
+
focusManager: PropTypes.shape({}),
|
62
158
|
name: PropTypes.string,
|
63
159
|
title: PropTypes.string,
|
160
|
+
onKeyDown: PropTypes.func,
|
64
161
|
level: PropTypes.number,
|
65
162
|
position: PropTypes.number,
|
66
163
|
setSize: PropTypes.number
|
@@ -0,0 +1,176 @@
|
|
1
|
+
import _findInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find";
|
2
|
+
import _findIndexInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/find-index";
|
3
|
+
var focusPrevious = function focusPrevious(index, refArray, flatKeyList) {
|
4
|
+
if (index !== 0) {
|
5
|
+
var key = flatKeyList[index - 1].key;
|
6
|
+
var _refArray$find = _findInstanceProperty(refArray).call(refArray, function (item) {
|
7
|
+
return item.key === key;
|
8
|
+
}),
|
9
|
+
thisRef = _refArray$find.thisRef;
|
10
|
+
thisRef.current.focus();
|
11
|
+
}
|
12
|
+
};
|
13
|
+
var focusNext = function focusNext(index, refArray, flatKeyList) {
|
14
|
+
if (index !== flatKeyList.length - 1) {
|
15
|
+
var key = flatKeyList[index + 1].key;
|
16
|
+
var _refArray$find2 = _findInstanceProperty(refArray).call(refArray, function (item) {
|
17
|
+
return item.key === key;
|
18
|
+
}),
|
19
|
+
thisRef = _refArray$find2.thisRef;
|
20
|
+
thisRef.current.focus();
|
21
|
+
}
|
22
|
+
};
|
23
|
+
export var verifyIndex = function verifyIndex(thisIndex, interval, length) {
|
24
|
+
var newIndex = thisIndex + interval;
|
25
|
+
if (newIndex < 0) {
|
26
|
+
return 0;
|
27
|
+
}
|
28
|
+
if (newIndex >= length) {
|
29
|
+
return length - 1;
|
30
|
+
}
|
31
|
+
return newIndex;
|
32
|
+
};
|
33
|
+
export var onHomePress = function onHomePress(key, flatKeyArray, refArray) {
|
34
|
+
var _thisRef$current;
|
35
|
+
var firstKey = flatKeyArray[0];
|
36
|
+
if (firstKey.key === key) {
|
37
|
+
return;
|
38
|
+
}
|
39
|
+
var _refArray$find3 = _findInstanceProperty(refArray).call(refArray, function (_item) {
|
40
|
+
return _item.key === firstKey.key;
|
41
|
+
}),
|
42
|
+
thisRef = _refArray$find3.thisRef;
|
43
|
+
(_thisRef$current = thisRef.current) === null || _thisRef$current === void 0 ? void 0 : _thisRef$current.focus();
|
44
|
+
};
|
45
|
+
export var onEndPress = function onEndPress(key, flatKeyArray, refArray) {
|
46
|
+
var _thisRef$current2;
|
47
|
+
var lastKey = flatKeyArray[flatKeyArray.length - 1];
|
48
|
+
if (lastKey.key === key) {
|
49
|
+
return;
|
50
|
+
}
|
51
|
+
var _refArray$find4 = _findInstanceProperty(refArray).call(refArray, function (_item) {
|
52
|
+
return _item.key === lastKey.key;
|
53
|
+
}),
|
54
|
+
thisRef = _refArray$find4.thisRef;
|
55
|
+
(_thisRef$current2 = thisRef.current) === null || _thisRef$current2 === void 0 ? void 0 : _thisRef$current2.focus();
|
56
|
+
};
|
57
|
+
export var pageUpOrDown = function pageUpOrDown(key, flatKeyArray, refArray, pageLength) {
|
58
|
+
var _thisRef$current3;
|
59
|
+
var thisIndex = _findIndexInstanceProperty(flatKeyArray).call(flatKeyArray, function (item) {
|
60
|
+
return item.key === key;
|
61
|
+
});
|
62
|
+
var newIndex = verifyIndex(thisIndex, pageLength, flatKeyArray.length);
|
63
|
+
var foundKey = flatKeyArray[newIndex].key;
|
64
|
+
var _refArray$find5 = _findInstanceProperty(refArray).call(refArray, function (_item) {
|
65
|
+
return _item.key === foundKey;
|
66
|
+
}),
|
67
|
+
thisRef = _refArray$find5.thisRef;
|
68
|
+
(_thisRef$current3 = thisRef.current) === null || _thisRef$current3 === void 0 ? void 0 : _thisRef$current3.focus();
|
69
|
+
};
|
70
|
+
export var onEnterPress = function onEnterPress(e, state, key) {
|
71
|
+
state.toggleKey(key);
|
72
|
+
e.preventDefault();
|
73
|
+
e.stopPropagation();
|
74
|
+
};
|
75
|
+
export var onLeftPress = function onLeftPress(e, focusManager, state, key, isExpanded, refArray) {
|
76
|
+
var isEventTargetAKey = _findInstanceProperty(refArray).call(refArray, function (_item) {
|
77
|
+
return _item.thisRef.current === e.target;
|
78
|
+
});
|
79
|
+
if (isExpanded && isEventTargetAKey) {
|
80
|
+
state.toggleKey(key);
|
81
|
+
}
|
82
|
+
if (isExpanded && !isEventTargetAKey) {
|
83
|
+
focusManager.focusPrevious();
|
84
|
+
}
|
85
|
+
e.preventDefault();
|
86
|
+
e.stopPropagation();
|
87
|
+
};
|
88
|
+
export var onSpacePress = function onSpacePress(e, tree, key, isSelected) {
|
89
|
+
if (isSelected) {
|
90
|
+
tree.setSelectedKeys([]);
|
91
|
+
} else {
|
92
|
+
tree.setSelectedKeys([key]);
|
93
|
+
}
|
94
|
+
e.preventDefault();
|
95
|
+
e.stopPropagation();
|
96
|
+
};
|
97
|
+
export var onUpPress = function onUpPress(e, key, refArray, flatKeyList) {
|
98
|
+
var foundIndex = _findIndexInstanceProperty(flatKeyList).call(flatKeyList, function (item) {
|
99
|
+
return item.key === key;
|
100
|
+
});
|
101
|
+
focusPrevious(foundIndex, refArray, flatKeyList);
|
102
|
+
e.preventDefault();
|
103
|
+
e.stopPropagation();
|
104
|
+
};
|
105
|
+
export var onTabPress = function onTabPress(e, refArray, focusManager, isSection) {
|
106
|
+
var isEventTargetAKey = _findInstanceProperty(refArray).call(refArray, function (_item) {
|
107
|
+
return _item.thisRef.current === e.target;
|
108
|
+
});
|
109
|
+
if (isEventTargetAKey && isSection) {
|
110
|
+
focusManager.focusNext();
|
111
|
+
e.preventDefault();
|
112
|
+
e.stopPropagation();
|
113
|
+
}
|
114
|
+
};
|
115
|
+
export var onRightPress = function onRightPress(e, focusManager, state, key, isExpanded, refArray) {
|
116
|
+
if (!isExpanded) {
|
117
|
+
state.toggleKey(key);
|
118
|
+
return;
|
119
|
+
}
|
120
|
+
var isEventTargetAKey = _findInstanceProperty(refArray).call(refArray, function (_item) {
|
121
|
+
return _item.thisRef.current === e.target;
|
122
|
+
});
|
123
|
+
if (isExpanded && isEventTargetAKey) {
|
124
|
+
focusManager.focusNext();
|
125
|
+
}
|
126
|
+
e.preventDefault();
|
127
|
+
e.stopPropagation();
|
128
|
+
};
|
129
|
+
export var onDownPress = function onDownPress(e, key, refArray, flatKeyList) {
|
130
|
+
// find the key
|
131
|
+
var foundIndex = _findIndexInstanceProperty(flatKeyList).call(flatKeyList, function (item) {
|
132
|
+
return item.key === key;
|
133
|
+
});
|
134
|
+
focusNext(foundIndex, refArray, flatKeyList);
|
135
|
+
// check if first or last
|
136
|
+
e.preventDefault();
|
137
|
+
e.stopPropagation();
|
138
|
+
};
|
139
|
+
export var onRightLeftItemPress = function onRightLeftItemPress(e) {
|
140
|
+
e.preventDefault();
|
141
|
+
e.stopPropagation();
|
142
|
+
};
|
143
|
+
export var onPageUpPress = function onPageUpPress(e, key, flatKeyArray, refArray, pageLength) {
|
144
|
+
pageUpOrDown(key, flatKeyArray, refArray, -Math.abs(pageLength));
|
145
|
+
e.preventDefault();
|
146
|
+
e.stopPropagation();
|
147
|
+
};
|
148
|
+
export var onPageDownPress = function onPageDownPress(e, key, flatKeyArray, refArray, pageLength) {
|
149
|
+
pageUpOrDown(key, flatKeyArray, refArray, Math.abs(pageLength));
|
150
|
+
e.preventDefault();
|
151
|
+
e.stopPropagation();
|
152
|
+
};
|
153
|
+
export var sectionPressHandlers = {
|
154
|
+
onEnterPress: onEnterPress,
|
155
|
+
onSpacePress: onSpacePress,
|
156
|
+
onLeftPress: onLeftPress,
|
157
|
+
onRightPress: onRightPress,
|
158
|
+
onUpPress: onUpPress,
|
159
|
+
onDownPress: onDownPress,
|
160
|
+
onTabPress: onTabPress,
|
161
|
+
onPageUpPress: onPageUpPress,
|
162
|
+
onPageDownPress: onPageDownPress,
|
163
|
+
onHomePress: onHomePress,
|
164
|
+
onEndPress: onEndPress
|
165
|
+
};
|
166
|
+
export var itemPressHandlers = {
|
167
|
+
onSpacePress: onSpacePress,
|
168
|
+
onDownPress: onDownPress,
|
169
|
+
onUpPress: onUpPress,
|
170
|
+
onRightLeftItemPress: onRightLeftItemPress,
|
171
|
+
onTabPress: onTabPress,
|
172
|
+
onPageUpPress: onPageUpPress,
|
173
|
+
onPageDownPress: onPageDownPress,
|
174
|
+
onHomePress: onHomePress,
|
175
|
+
onEndPress: onEndPress
|
176
|
+
};
|