@pingux/astro 2.32.0-alpha.12 → 2.32.0-alpha.14
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/ImageUploadField/ImageUploadField.test.js +47 -14
- 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/useImageUploadState/index.d.ts +1 -0
- package/lib/cjs/hooks/useImageUploadState/useImageUploadState.d.ts +28 -0
- package/lib/cjs/hooks/useImageUploadState/useImageUploadState.js +9 -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/utils/testUtils/setupTests.d.ts +4 -0
- package/lib/cjs/utils/testUtils/testAxe.d.ts +2 -0
- package/lib/cjs/utils/testUtils/testTheme.d.ts +21 -0
- package/lib/cjs/utils/testUtils/testWrapper.d.ts +5 -0
- package/lib/cjs/utils/testUtils/testWrapper.js +3 -2
- package/lib/components/ImageUploadField/ImageUploadField.test.js +47 -14
- 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/useImageUploadState/useImageUploadState.js +9 -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/utils/testUtils/testWrapper.js +3 -2
- package/package.json +1 -1
@@ -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
|
+
};
|