@pingux/astro 2.50.0 → 2.51.0-alpha.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.
@@ -0,0 +1,117 @@
1
+ "use strict";
2
+
3
+ var _typeof = require("@babel/runtime-corejs3/helpers/typeof");
4
+ var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
5
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
6
+ var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
7
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
8
+ _Object$defineProperty(exports, "__esModule", {
9
+ value: true
10
+ });
11
+ exports.escapeFocusDelegate = exports["default"] = void 0;
12
+ var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
13
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectWithoutProperties"));
14
+ var _react = _interopRequireWildcard(require("react"));
15
+ var _reactAria = require("react-aria");
16
+ var _focus = require("@react-aria/focus");
17
+ var _propTypes = _interopRequireDefault(require("prop-types"));
18
+ var _index = require("../../index");
19
+ var _react2 = require("@emotion/react");
20
+ var _excluded = ["children", "gridCellProps", "focusManager", "isFocusEscaped", "setIsFocusEscaped", "focusProps", "focusWithinProps", "isFocused", "isFocusWithin"];
21
+ function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
22
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
+ var escapeFocusDelegate = function escapeFocusDelegate(e, setIsFocusEscaped, focusManager, isFocusEscaped) {
24
+ if (e.keyCode === 13) {
25
+ setIsFocusEscaped(true);
26
+ focusManager.focusNext();
27
+ e.stopPropagation();
28
+ e.preventDefault();
29
+ } else if (isFocusEscaped) {
30
+ switch (e.keyCode) {
31
+ case 37:
32
+ e.stopPropagation();
33
+ break;
34
+ case 39:
35
+ e.stopPropagation();
36
+ break;
37
+ case 38:
38
+ focusManager.focusPrevious();
39
+ e.stopPropagation();
40
+ e.preventDefault();
41
+ break;
42
+ case 40:
43
+ focusManager.focusNext();
44
+ e.stopPropagation();
45
+ e.preventDefault();
46
+ break;
47
+ default:
48
+ break;
49
+ }
50
+ }
51
+ };
52
+ exports.escapeFocusDelegate = escapeFocusDelegate;
53
+ var ExpandableItemChildrenContainer = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref) {
54
+ var children = props.children,
55
+ gridCellProps = props.gridCellProps,
56
+ focusManager = props.focusManager,
57
+ isFocusEscaped = props.isFocusEscaped,
58
+ setIsFocusEscaped = props.setIsFocusEscaped,
59
+ focusProps = props.focusProps,
60
+ focusWithinProps = props.focusWithinProps,
61
+ isFocused = props.isFocused,
62
+ isFocusWithin = props.isFocusWithin,
63
+ others = (0, _objectWithoutProperties2["default"])(props, _excluded);
64
+ var mergedProps = (0, _reactAria.mergeProps)(others, gridCellProps, focusProps, focusWithinProps);
65
+
66
+ // this handles instances where a user clicks into the container.
67
+ (0, _react.useEffect)(function () {
68
+ if (isFocusWithin && !isFocusEscaped && !isFocused) {
69
+ setIsFocusEscaped(true);
70
+ }
71
+ }, [isFocusWithin]);
72
+ return (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({
73
+ ref: ref
74
+ }, mergedProps, {
75
+ tabIndex: 0,
76
+ onKeyDown: function onKeyDown(e) {
77
+ escapeFocusDelegate(e, setIsFocusEscaped, focusManager, isFocusEscaped);
78
+ }
79
+ }), children);
80
+ });
81
+ ExpandableItemChildrenContainer.propTypes = {
82
+ gridCellProps: _propTypes["default"].shape({}),
83
+ focusManager: _propTypes["default"].shape({}),
84
+ focusProps: _propTypes["default"].shape({}),
85
+ focusWithinProps: _propTypes["default"].shape({}),
86
+ isFocusEscaped: _propTypes["default"].bool,
87
+ isFocused: _propTypes["default"].bool,
88
+ isFocusWithin: _propTypes["default"].bool,
89
+ expandableContainerOnBlur: _propTypes["default"].func,
90
+ expandableContainerOnFocus: _propTypes["default"].func,
91
+ setIsFocusEscaped: _propTypes["default"].func
92
+ };
93
+ var ListViewFocusWrapper = function ListViewFocusWrapper(props) {
94
+ var children = props.children,
95
+ containerProps = props.containerProps,
96
+ isFocusEscaped = props.isFocusEscaped;
97
+ var focusManager = (0, _focus.useFocusManager)();
98
+ return (0, _react2.jsx)(_focus.FocusScope, {
99
+ restoreFocus: false,
100
+ contain: isFocusEscaped
101
+ }, (0, _react2.jsx)(FocusableItem, null, (0, _react2.jsx)(ExpandableItemChildrenContainer, (0, _extends2["default"])({}, containerProps, {
102
+ focusManager: focusManager
103
+ }), children)));
104
+ };
105
+ var FocusableItem = function FocusableItem(props) {
106
+ var focusManager = (0, _focus.useFocusManager)();
107
+ var childWithFocusHandle = /*#__PURE__*/_react["default"].cloneElement(props.children, {
108
+ focusManager: focusManager
109
+ });
110
+ return childWithFocusHandle;
111
+ };
112
+ ListViewFocusWrapper.propTypes = {
113
+ containerProps: _propTypes["default"].shape({}),
114
+ isFocusEscaped: _propTypes["default"].bool
115
+ };
116
+ var _default = ListViewFocusWrapper;
117
+ exports["default"] = _default;
@@ -22,7 +22,6 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/he
22
22
  var _react = _interopRequireWildcard(require("react"));
23
23
  var _reactAria = require("react-aria");
24
24
  var _interactions = require("@react-aria/interactions");
25
- var _list = require("@react-aria/list");
26
25
  var _propTypes = _interopRequireDefault(require("prop-types"));
27
26
  var _hooks = require("../../hooks");
28
27
  var _index = require("../../index");
@@ -33,7 +32,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
33
32
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys2(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
34
33
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context2, _context3; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(source), !0)).call(_context2, function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context3 = ownKeys(Object(source))).call(_context3, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
35
34
  var ListViewItem = function ListViewItem(props) {
36
- var _context;
35
+ var _context, _item$rendered;
37
36
  var item = props.item,
38
37
  _props$item$props = props.item.props,
39
38
  listItemProps = _props$item$props.listItemProps,
@@ -58,24 +57,31 @@ var ListViewItem = function ListViewItem(props) {
58
57
  var _useFocusRing2 = (0, _reactAria.useFocusRing)(),
59
58
  focusProps = _useFocusRing2.focusProps,
60
59
  isFocusVisible = _useFocusRing2.isFocusVisible;
60
+ var onPointerLeaveFunction = /* istanbul ignore next */function onPointerLeaveFunction() {
61
+ state.hover.setHoveredItem('');
62
+ };
61
63
  var _useHover = (0, _interactions.useHover)({
62
64
  onHoverStart: function onHoverStart() {
63
65
  state.hover.setHoveredItem(item.key);
66
+ },
67
+ onHoverEnd: /* istanbul ignore next */
68
+ function onHoverEnd() {
69
+ onPointerLeaveFunction();
64
70
  }
65
71
  }),
66
- hoverProps = _useHover.hoverProps,
67
- isHovered = _useHover.isHovered;
68
- var _useListItem = (0, _list.useListItem)({
72
+ hoverProps = _useHover.hoverProps;
73
+ var _useGridListItem = (0, _reactAria.useGridListItem)({
69
74
  node: item,
70
- isVirtualized: true,
71
- isDisabled: isDisabled
75
+ isVirtualized: true
72
76
  }, state, rowRef),
73
- raRowProps = _useListItem.rowProps,
74
- gridCellProps = _useListItem.gridCellProps;
77
+ raRowProps = _useGridListItem.rowProps,
78
+ gridCellProps = _useGridListItem.gridCellProps;
75
79
  var isSelected = state.selectionManager.isSelected(item.key);
76
- var mergedProps = (0, _reactAria.mergeProps)(raRowProps, hoverProps, isFocusable ? _objectSpread(_objectSpread({}, focusProps), focusWithinProps) : {});
80
+ var mergedProps = (0, _reactAria.mergeProps)(raRowProps, hoverProps, isFocusable ? _objectSpread(_objectSpread({}, focusProps), focusWithinProps) : {}, {
81
+ onPointerLeave: onPointerLeaveFunction
82
+ });
77
83
  var _useStatusClasses = (0, _hooks.useStatusClasses)(className, {
78
- isHovered: isSelectable && isHovered && isHoverable && item.key === state.hover.hoveredItem,
84
+ isHovered: isSelectable && isHoverable && item.key === state.hover.hoveredItem,
79
85
  isSelected: isSelected,
80
86
  isFocused: isDisabled ? false : isFocusVisible || isFocusVisibleWithin,
81
87
  hasSeparator: hasSeparator,
@@ -85,7 +91,11 @@ var ListViewItem = function ListViewItem(props) {
85
91
 
86
92
  // Whether the current component should have legacy styles removed
87
93
  // TODO: [Astro 3.0.0] Remove the legacy styles and update the code here.
88
- var shouldOverRideLegacyStyles = (0, _includes["default"])(_context = (0, _keys["default"])(item.rendered.props)).call(_context, 'data');
94
+ var shouldOverRideLegacyStyles = (0, _includes["default"])(_context = (0, _keys["default"])(item === null || item === void 0 || (_item$rendered = item.rendered) === null || _item$rendered === void 0 ? void 0 : _item$rendered.props)).call(_context, 'data');
95
+
96
+ // Apply appropriate variant dependant on whether a legacy list item is used
97
+ /* istanbul ignore next */
98
+ var listItemVariant = shouldOverRideLegacyStyles ? 'listViewItem.styledListItem' : 'listViewItem.container';
89
99
  return (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({
90
100
  isDisabled: isDisabled,
91
101
  isRow: true,
@@ -95,10 +105,8 @@ var ListViewItem = function ListViewItem(props) {
95
105
  outline: 'none'
96
106
  }
97
107
  }), (0, _react2.jsx)(_index.Box, (0, _extends2["default"])({
98
- as: "div"
99
- // Apply appropriate variant dependant on whether a legacy list item is used
100
- ,
101
- variant: shouldOverRideLegacyStyles ? 'listViewItem.styledListItem' : 'listViewItem.container'
108
+ as: "div",
109
+ variant: listItemVariant
102
110
  }, gridCellProps, {
103
111
  isFocused: isDisabled ? false : isFocusVisible,
104
112
  isDisabled: isDisabled,
@@ -117,6 +117,36 @@ var rightOfData = {
117
117
  alignSelf: 'center',
118
118
  flexShrink: 0
119
119
  };
120
+ var expandableFocusContainer = {
121
+ px: 'sm',
122
+ outline: 'none',
123
+ border: 'none',
124
+ '&.is-focused': {
125
+ boxShadow: '0 0 0 1px inset #D033FF'
126
+ }
127
+ };
128
+ var expandableStyledListItem = {
129
+ display: 'flex',
130
+ padding: '0px 15px 0px 25px',
131
+ flex: '1 1 0px',
132
+ minHeight: '80px',
133
+ flexGrow: 1,
134
+ justifyContent: 'center',
135
+ bg: 'white',
136
+ '&.is-hovered': {
137
+ bg: 'accent.99',
138
+ cursor: 'pointer'
139
+ },
140
+ '&.is-focused': {
141
+ boxShadow: '0 0 0 1px inset #D033FF'
142
+ }
143
+ };
144
+ var expandableRow = {
145
+ '&.has-separator': {
146
+ borderBottom: '1px solid',
147
+ borderBottomColor: 'line.light'
148
+ }
149
+ };
120
150
  var _default = {
121
151
  container: container,
122
152
  controls: controls,
@@ -127,6 +157,9 @@ var _default = {
127
157
  rightOfData: rightOfData,
128
158
  styledContainer: styledContainer,
129
159
  styledListItem: styledListItem,
130
- loaderContainer: loaderContainer
160
+ loaderContainer: loaderContainer,
161
+ expandableFocusContainer: expandableFocusContainer,
162
+ expandableStyledListItem: expandableStyledListItem,
163
+ expandableRow: expandableRow
131
164
  };
132
165
  exports["default"] = _default;
@@ -0,0 +1 @@
1
+ export { default } from './useExpandableListViewItem';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
5
+ _Object$defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ _Object$defineProperty(exports, "default", {
9
+ enumerable: true,
10
+ get: function get() {
11
+ return _useExpandableListViewItem["default"];
12
+ }
13
+ });
14
+ var _useExpandableListViewItem = _interopRequireDefault(require("./useExpandableListViewItem"));
@@ -0,0 +1,51 @@
1
+ /// <reference types="react" />
2
+ import type { TreeState } from 'react-stately';
3
+ import type { SelectionManager } from '@react-stately/selection';
4
+ import type { GridNode } from '@react-types/grid';
5
+ interface UseExpandableListViewItemResult {
6
+ expandableRowProps: object;
7
+ cellProps: object;
8
+ expandableContainerProps: object;
9
+ expandableItemState: object;
10
+ }
11
+ interface UseExpandableListViewItem<T> {
12
+ /**
13
+ * This hook wraps the useListItem hook, and modifies it,
14
+ * providing expansion capabilities and the option for
15
+ * escaping the focus of the ListView grid.
16
+ *
17
+ * Returns four objects, three of which are spread into subcomponents,
18
+ * the fourth provides state handing props.
19
+ * @param {Object} [props] Properties provided to the underlying hooks
20
+ * @param {Boolean} [props.isHoverable] whether or not the option is hoverable
21
+ * @param {ReactRef} [props.expandableChildrenRef] the container of all of the expandable content
22
+ * @param {ReactRef} [props.expandableItemRowRef] the container of for the entire item
23
+ * @param {String} [props.className] custom css classname applied to the row
24
+ * @param {Object} [props.state] state prop passed from useTreeState. handles expansion
25
+ * @param {Object} [props.item] item object.
26
+ *
27
+ * @returns {Object} {expandableRowProps}: props spread into the entire row container
28
+ * @returns {Object} {cellProps}: props spread into the non-expanded content cell
29
+ * @returns {Object} {expandableContainerProps}: spread into the expanded content cell
30
+ * @returns {Object} {state}: expansion, focus, and additonal cell props
31
+ */
32
+ (props: ExpandableListViewItemProps<T>): UseExpandableListViewItemResult;
33
+ }
34
+ interface ListViewState<T> extends TreeState<T> {
35
+ hover: {
36
+ hoveredItem?: string;
37
+ setHoveredItem: (hoveredItem: string | number) => unknown;
38
+ };
39
+ isLink: boolean;
40
+ selectionManager: SelectionManager;
41
+ }
42
+ interface ExpandableListViewItemProps<T> {
43
+ expandableItemRowRef: React.MutableRefObject<HTMLDivElement | null>;
44
+ expandableChildrenRef: React.MutableRefObject<HTMLDivElement | null>;
45
+ className: string;
46
+ item: GridNode<T>;
47
+ state: ListViewState<T>;
48
+ key: string | number;
49
+ }
50
+ declare const useExpandableListViewItem: UseExpandableListViewItem<object>;
51
+ export default useExpandableListViewItem;
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+
3
+ var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
4
+ var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
5
+ var _filterInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
6
+ var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
7
+ var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
8
+ var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
9
+ var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
10
+ var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
11
+ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
12
+ _Object$defineProperty(exports, "__esModule", {
13
+ value: true
14
+ });
15
+ exports["default"] = void 0;
16
+ var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set"));
17
+ var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
18
+ var _from = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/array/from"));
19
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
20
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
21
+ var _react = require("react");
22
+ var _reactAria = require("react-aria");
23
+ var _interactions = require("@react-aria/interactions");
24
+ var _ = require("..");
25
+ function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
26
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context3, _context4; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context3 = ownKeys(Object(source), !0)).call(_context3, function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context4 = ownKeys(Object(source))).call(_context4, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
27
+ var useExpandableListViewItem = function useExpandableListViewItem(props) {
28
+ var _expandableChildrenRe3;
29
+ var item = props.item,
30
+ _props$item$props = props.item.props,
31
+ listItemProps = _props$item$props.listItemProps,
32
+ rowProps = _props$item$props.rowProps,
33
+ state = props.state,
34
+ expandableItemRowRef = props.expandableItemRowRef,
35
+ expandableChildrenRef = props.expandableChildrenRef,
36
+ className = props.className;
37
+ var hasSeparator = true;
38
+
39
+ // convenience extractions from props
40
+ var key = item.key;
41
+ var dataId = item.props['data-id'];
42
+ var isDisabled = state.disabledKeys.has(key);
43
+ var isSelectable = state.selectionManager.selectionMode !== 'none';
44
+ var isExpanded = state.expandedKeys.has(key);
45
+ var isSelected = state.selectionManager.isSelected(key);
46
+
47
+ // initialize state
48
+ var _useState = (0, _react.useState)(false),
49
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
50
+ isFocusEscaped = _useState2[0],
51
+ setIsFocusEscaped = _useState2[1];
52
+
53
+ // call spectrum hooks
54
+ var _useFocusRing = (0, _reactAria.useFocusRing)({
55
+ within: true
56
+ }),
57
+ isFocusVisibleWithin = _useFocusRing.isFocusVisible,
58
+ focusWithinProps = _useFocusRing.focusProps;
59
+ var _useFocusRing2 = (0, _reactAria.useFocusRing)(),
60
+ isFocusVisibleContainer = _useFocusRing2.isFocusVisible,
61
+ containerFocusProps = _useFocusRing2.focusProps;
62
+ var _useFocusRing3 = (0, _reactAria.useFocusRing)({
63
+ within: true
64
+ }),
65
+ isFocusWithinVisibleContainer = _useFocusRing3.isFocusVisible,
66
+ containerWithinFocusProps = _useFocusRing3.focusProps;
67
+ var _useFocusRing4 = (0, _reactAria.useFocusRing)(),
68
+ focusProps = _useFocusRing4.focusProps,
69
+ isFocusVisible = _useFocusRing4.isFocusVisible;
70
+ var _useHover = (0, _interactions.useHover)({
71
+ onHoverStart: /* istanbul ignore next */
72
+ function onHoverStart() {
73
+ state.hover.setHoveredItem(item.key);
74
+ },
75
+ onHoverEnd: /* istanbul ignore next */
76
+ function onHoverEnd() {
77
+ state.hover.setHoveredItem('');
78
+ }
79
+ }),
80
+ hoverProps = _useHover.hoverProps;
81
+ var _useGridListItem = (0, _reactAria.useGridListItem)({
82
+ node: item,
83
+ isVirtualized: true
84
+ }, state, expandableItemRowRef),
85
+ raRowProps = _useGridListItem.rowProps,
86
+ gridCellProps = _useGridListItem.gridCellProps;
87
+
88
+ // remove row mouse event props
89
+ // delete raRowProps.onClick;
90
+ delete raRowProps.onMouseDown;
91
+ delete raRowProps.onPointerDown;
92
+
93
+ // declare custom functions
94
+ var expandItem = function expandItem() {
95
+ var _context;
96
+ var newSet = new _set["default"]((0, _concat["default"])(_context = []).call(_context, (0, _from["default"])(state.expandedKeys), [key]));
97
+ state.setExpandedKeys(newSet);
98
+ };
99
+ var toggleExpanded = function toggleExpanded() {
100
+ if (isExpanded) {
101
+ var _context2;
102
+ var set = new _set["default"]((0, _concat["default"])(_context2 = []).call(_context2, (0, _from["default"])(state.expandedKeys)));
103
+ set["delete"](key);
104
+ state.setExpandedKeys(set);
105
+ } else {
106
+ expandItem();
107
+ }
108
+ };
109
+
110
+ // overrides the row navigation.
111
+ // if escape is pressed, focus is returned to the expanded content container
112
+
113
+ var onKeyDownEscapeFocusRowOverride = function onKeyDownEscapeFocusRowOverride(e) {
114
+ if (e.keyCode === 27) {
115
+ var _expandableChildrenRe;
116
+ /* istanbul ignore next */
117
+ setIsFocusEscaped(false);
118
+ /* istanbul ignore next */
119
+ expandableChildrenRef === null || expandableChildrenRef === void 0 || (_expandableChildrenRe = expandableChildrenRef.current) === null || _expandableChildrenRe === void 0 ? void 0 : _expandableChildrenRe.focus();
120
+ }
121
+ };
122
+
123
+ // if the row is expanded, and key left is pressed:
124
+ // return focus to the expanded content container
125
+ var listenOnRowForLeft = function listenOnRowForLeft(e) {
126
+ if (e.keyCode === 37 && e.target === expandableItemRowRef.current && isExpanded) {
127
+ var _expandableChildrenRe2;
128
+ expandableChildrenRef === null || expandableChildrenRef === void 0 || (_expandableChildrenRe2 = expandableChildrenRef.current) === null || _expandableChildrenRe2 === void 0 ? void 0 : _expandableChildrenRe2.focus();
129
+ } else if ((e.keyCode === 13 || e.keyCode === 32) && e.target === expandableItemRowRef.current) {
130
+ toggleExpanded();
131
+ } else if (raRowProps.onKeyDownCapture) {
132
+ raRowProps.onKeyDownCapture(e);
133
+ }
134
+ };
135
+
136
+ // if the expanded content container is focused, this function will call
137
+ // it returns focus to the row on right press, and calls the native left press
138
+ var expandedChildrenKeyCaptureOverride = function expandedChildrenKeyCaptureOverride(e) {
139
+ var _expandableItemRowRef;
140
+ // if left go back ie dont stifle
141
+ // if right, stifle, but then send back to row, using ref.
142
+ switch (e.keyCode) {
143
+ case 37:
144
+ if (!isFocusEscaped) {
145
+ if (raRowProps.onKeyDownCapture) {
146
+ raRowProps.onKeyDownCapture(e);
147
+ }
148
+ break;
149
+ }
150
+ break;
151
+ case 39:
152
+ expandableItemRowRef === null || expandableItemRowRef === void 0 || (_expandableItemRowRef = expandableItemRowRef.current) === null || _expandableItemRowRef === void 0 ? void 0 : _expandableItemRowRef.focus();
153
+ break;
154
+ default:
155
+ break;
156
+ }
157
+ };
158
+
159
+ // merge props and create status css classes
160
+ var mergedProps = (0, _reactAria.mergeProps)(raRowProps, focusProps, focusWithinProps);
161
+ var _useStatusClasses = (0, _.useStatusClasses)(className, {
162
+ isHovered: isSelectable && item.key === state.hover.hoveredItem,
163
+ isSelected: isSelected,
164
+ isFocused: isDisabled ? false : isFocusVisible || isFocusVisibleWithin && !isFocusEscaped && !isFocusVisibleContainer
165
+ }),
166
+ classNames = _useStatusClasses.classNames;
167
+ var _useStatusClasses2 = (0, _.useStatusClasses)('', {
168
+ isFocused: isFocusVisibleContainer
169
+ }),
170
+ focusContainerClassName = _useStatusClasses2.classNames;
171
+ var _useStatusClasses3 = (0, _.useStatusClasses)('', {
172
+ hasSeparator: hasSeparator
173
+ }),
174
+ rowClassName = _useStatusClasses3.classNames;
175
+ var expandableRowProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({
176
+ isDisabled: isDisabled,
177
+ ref: expandableItemRowRef
178
+ }, mergedProps), rowProps), {}, {
179
+ onKeyDownCapture: listenOnRowForLeft
180
+ }, isFocusEscaped && {
181
+ onKeyDown: onKeyDownEscapeFocusRowOverride
182
+ }), {}, {
183
+ sx: {
184
+ outline: 'none'
185
+ }
186
+ }, (isFocusVisibleContainer || isFocusEscaped) && {
187
+ onKeyDownCapture: function onKeyDownCapture(e) {
188
+ return expandedChildrenKeyCaptureOverride(e);
189
+ }
190
+ }), {}, {
191
+ className: rowClassName,
192
+ variant: 'listViewItem.expandableRow'
193
+ });
194
+ var cellProps = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, hoverProps), {}, {
195
+ variant: 'listViewItem.expandableStyledListItem',
196
+ sx: {
197
+ minHeight: '75px',
198
+ py: 'lg',
199
+ px: 'md'
200
+ }
201
+ }, gridCellProps), {}, {
202
+ isFocused: isDisabled ? false : isFocusVisible,
203
+ isDisabled: isDisabled,
204
+ isSelected: isSelected,
205
+ className: classNames,
206
+ 'data-id': dataId
207
+ }, listItemProps), {}, {
208
+ 'aria-expanded': isExpanded,
209
+ 'aria-controls': (_expandableChildrenRe3 = expandableChildrenRef.current) === null || _expandableChildrenRe3 === void 0 ? void 0 : _expandableChildrenRe3.id
210
+ });
211
+ var expandableContainerProps = {
212
+ ref: expandableChildrenRef,
213
+ isFocusEscaped: isFocusEscaped,
214
+ setIsFocusEscaped: setIsFocusEscaped,
215
+ className: focusContainerClassName,
216
+ isFocused: isFocusVisibleContainer,
217
+ focusProps: containerFocusProps,
218
+ focusWithinProps: containerWithinFocusProps,
219
+ isFocusWithin: isFocusWithinVisibleContainer,
220
+ 'data-testid': 'focuscontainer',
221
+ variant: 'listViewItem.expandableFocusContainer'
222
+ };
223
+ var expandableItemState = {
224
+ isExpanded: isExpanded,
225
+ isFocusEscaped: isFocusEscaped,
226
+ toggleExpanded: toggleExpanded,
227
+ gridCellProps: gridCellProps
228
+ };
229
+ return {
230
+ expandableRowProps: expandableRowProps,
231
+ cellProps: cellProps,
232
+ expandableContainerProps: expandableContainerProps,
233
+ expandableItemState: expandableItemState
234
+ };
235
+ };
236
+ var _default = useExpandableListViewItem;
237
+ exports["default"] = _default;
@@ -10,21 +10,22 @@ import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
10
10
  import _defineProperty from "@babel/runtime-corejs3/helpers/esm/defineProperty";
11
11
  import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
12
12
  import _objectWithoutProperties from "@babel/runtime-corejs3/helpers/esm/objectWithoutProperties";
13
- var _excluded = ["disabledKeys", "isHoverable", "loadingState", "onLoadMore", "onSelectionChange", "selectedKeys", "selectionMode", "selectionStyle", "items"];
13
+ var _excluded = ["disabledKeys", "isHoverable", "loadingState", "onLoadMore", "onSelectionChange", "onExpandedChange", "expandedKeys", "selectedKeys", "selectionMode", "selectionStyle", "items"];
14
14
  import _Object$values from "@babel/runtime-corejs3/core-js-stable/object/values";
15
15
  function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
16
16
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var _context, _context2; var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? _forEachInstanceProperty(_context = ownKeys(Object(source), !0)).call(_context, function (key) { _defineProperty(target, key, source[key]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(target, _Object$getOwnPropertyDescriptors(source)) : _forEachInstanceProperty(_context2 = ownKeys(Object(source))).call(_context2, function (key) { _Object$defineProperty(target, key, _Object$getOwnPropertyDescriptor(source, key)); }); } return target; }
17
17
  import React, { forwardRef, useImperativeHandle, useMemo, useRef, useState } from 'react';
18
+ import { useGridList } from 'react-aria';
19
+ import { useTreeState } from 'react-stately';
18
20
  import { useCollator } from '@react-aria/i18n';
19
- import { useList } from '@react-aria/list';
20
21
  import { Virtualizer, VirtualizerItem } from '@react-aria/virtualizer';
21
22
  import { ListLayout } from '@react-stately/layout';
22
- import { useListState } from '@react-stately/list';
23
23
  import PropTypes from 'prop-types';
24
24
  import loadingStates from '../../utils/devUtils/constants/loadingStates';
25
25
  import { isIterableProp } from '../../utils/devUtils/props/isIterable';
26
26
  import Loader from '../Loader';
27
27
  import { ListViewContext } from './ListViewContext';
28
+ import ListViewExpandableItem from './ListViewExpandableItem';
28
29
  import ListViewItem from './ListViewItem';
29
30
  import { jsx as ___EmotionJSX } from "@emotion/react";
30
31
  export var collectionTypes = {
@@ -48,7 +49,7 @@ export function useListLayout(state) {
48
49
  placeholderHeight: ROW_HEIGHT,
49
50
  collator: collator
50
51
  });
51
- }, [collator]);
52
+ }, [collator, state.collection]);
52
53
  layout.collection = state.collection;
53
54
  layout.disabledKeys = state.disabledKeys;
54
55
  return layout;
@@ -60,12 +61,14 @@ var ListView = /*#__PURE__*/forwardRef(function (props, ref) {
60
61
  loadingState = props.loadingState,
61
62
  onLoadMore = props.onLoadMore,
62
63
  onSelectionChange = props.onSelectionChange,
64
+ onExpandedChange = props.onExpandedChange,
65
+ expandedKeys = props.expandedKeys,
63
66
  selectedKeys = props.selectedKeys,
64
67
  selectionMode = props.selectionMode,
65
68
  selectionStyle = props.selectionStyle,
66
69
  items = props.items,
67
70
  others = _objectWithoutProperties(props, _excluded);
68
- var _useState = useState(null),
71
+ var _useState = useState(''),
69
72
  _useState2 = _slicedToArray(_useState, 2),
70
73
  hoveredItem = _useState2[0],
71
74
  setHoveredItem = _useState2[1];
@@ -84,8 +87,8 @@ var ListView = /*#__PURE__*/forwardRef(function (props, ref) {
84
87
  useImperativeHandle(ref, function () {
85
88
  return listViewRef.current;
86
89
  });
87
- var state = useListState(_objectSpread(_objectSpread({}, props), {}, {
88
- selectionBehavior: selectionStyle === 'highlight' ? 'replace' : 'toggle'
90
+ var state = useTreeState(_objectSpread(_objectSpread({}, props), {}, {
91
+ selectionMode: selectionMode === 'expansion' ? 'single' : selectionMode
89
92
  }));
90
93
  state.hover = {
91
94
  hoveredItem: hoveredItem,
@@ -97,12 +100,12 @@ var ListView = /*#__PURE__*/forwardRef(function (props, ref) {
97
100
  var collection = state.collection,
98
101
  selectionManager = state.selectionManager;
99
102
  var layout = useListLayout(state);
100
- var _useList = useList(_objectSpread(_objectSpread({}, props), {}, {
103
+ var _useGridList = useGridList(_objectSpread(_objectSpread({}, props), {}, {
101
104
  isVirtualized: true,
102
105
  keyboardDelegate: layout,
103
106
  loadingState: loadingState
104
107
  }), state, listViewRef),
105
- gridProps = _useList.gridProps;
108
+ gridProps = _useGridList.gridProps;
106
109
  // Sync loading state into the layout.
107
110
  layout.isLoading = isLoading;
108
111
  var focusedKey = selectionManager.focusedKey;
@@ -145,6 +148,13 @@ var ListView = /*#__PURE__*/forwardRef(function (props, ref) {
145
148
  shouldUseVirtualFocus: !isFocusable
146
149
  }), function (type, item) {
147
150
  if (type === 'item') {
151
+ if (props.selectionMode === 'expansion') {
152
+ return ___EmotionJSX(ListViewExpandableItem, {
153
+ isHoverable: isHoverable,
154
+ isFocusable: isFocusable,
155
+ item: item
156
+ });
157
+ }
148
158
  return ___EmotionJSX(ListViewItem, {
149
159
  isHoverable: isHoverable,
150
160
  isFocusable: isFocusable,
@@ -168,6 +178,12 @@ ListView.propTypes = {
168
178
  * interacted with.
169
179
  */
170
180
  disabledKeys: PropTypes.arrayOf(PropTypes.oneOfType([PropTypes.string, PropTypes.object])),
181
+ /** The initial expanded keys in the collection (uncontrolled). */
182
+ defaultExpandedKeys: isIterableProp,
183
+ /** The expanded keys in the collection (controlled). */
184
+ expandedKeys: isIterableProp,
185
+ /** Handler that is called when items are expanded or collapsed. */
186
+ onExpandedChange: PropTypes.func,
171
187
  /** The list of ListView items (controlled). */
172
188
  items: isIterableProp,
173
189
  /** The element's unique identifier. See [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/id). */
@@ -192,7 +208,7 @@ ListView.propTypes = {
192
208
  */
193
209
  selectedKeys: PropTypes.oneOfType([PropTypes.string, PropTypes.arrayOf(PropTypes.string)]),
194
210
  /** The type of selection that is allowed in the collection. */
195
- selectionMode: PropTypes.oneOf(['none', 'single', 'multiple']),
211
+ selectionMode: PropTypes.oneOf(['none', 'single', 'multiple', 'expansion']),
196
212
  /** */
197
213
  selectionStyle: PropTypes.oneOf(['highlight', undefined]),
198
214
  /** Callback function that fires when the selected key changes. */