@deque/cauldron-react 7.6.0-canary.02bddc70 → 7.6.0-canary.05d324ca
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.
|
@@ -14,15 +14,6 @@ interface CascadeOptions {
|
|
|
14
14
|
cascadeSelect: boolean;
|
|
15
15
|
cascadeDeselect: boolean;
|
|
16
16
|
}
|
|
17
|
-
/**
|
|
18
|
-
* Toggle a single node, applying cascade per the options (multiple mode only):
|
|
19
|
-
* - selecting + `cascadeSelect`: also selects all (non-disabled) descendants.
|
|
20
|
-
* - deselecting + `cascadeDeselect`: also deselects all descendants.
|
|
21
|
-
*
|
|
22
|
-
* In `single` mode only the clicked node is selected (clicking it again clears
|
|
23
|
-
* it); cascade does not apply.
|
|
24
|
-
*/
|
|
25
|
-
export declare function toggleSelection(nodes: TreeViewNode[], previous: Set<Key>, key: Key, selectionMode: 'single' | 'multiple', { cascadeSelect, cascadeDeselect }: CascadeOptions): Set<Key>;
|
|
26
17
|
/**
|
|
27
18
|
* Apply react-aria's proposed selection while enforcing cascade. Each key
|
|
28
19
|
* react-aria added cascades to its descendants when `cascadeSelect` is set; each
|
|
@@ -11,6 +11,8 @@ export declare const ROW_GAP = 2;
|
|
|
11
11
|
export declare const LIST_PADDING = 4;
|
|
12
12
|
type TreeViewProps = Cauldron.LabelProps & Omit<React.HTMLAttributes<HTMLDivElement>, 'children' | 'role' | 'dangerouslySetInnerHTML'> & {
|
|
13
13
|
items: TreeViewNode[];
|
|
14
|
+
/** Runs when an item is activated by a click, Space or Enter. Each of these
|
|
15
|
+
* also toggles the item's selection. Without selection, Space does not act. */
|
|
14
16
|
onAction?: (key: string) => void;
|
|
15
17
|
selectionMode?: 'none' | 'single' | 'multiple';
|
|
16
18
|
/** When true (multiple selection only), selecting a parent also selects all
|
package/lib/index.js
CHANGED
|
@@ -5606,45 +5606,6 @@ function collectDescendantKeys(node) {
|
|
|
5606
5606
|
function collectDisabledKeys(nodes) {
|
|
5607
5607
|
return nodes.flatMap(function (node) { return tslib.__spreadArray(tslib.__spreadArray([], tslib.__read((node.disabled ? [node.id] : [])), false), tslib.__read((node.children ? collectDisabledKeys(node.children) : [])), false); });
|
|
5608
5608
|
}
|
|
5609
|
-
/**
|
|
5610
|
-
* Toggle a single node, applying cascade per the options (multiple mode only):
|
|
5611
|
-
* - selecting + `cascadeSelect`: also selects all (non-disabled) descendants.
|
|
5612
|
-
* - deselecting + `cascadeDeselect`: also deselects all descendants.
|
|
5613
|
-
*
|
|
5614
|
-
* In `single` mode only the clicked node is selected (clicking it again clears
|
|
5615
|
-
* it); cascade does not apply.
|
|
5616
|
-
*/
|
|
5617
|
-
function toggleSelection(nodes, previous, key, selectionMode, _a) {
|
|
5618
|
-
var cascadeSelect = _a.cascadeSelect, cascadeDeselect = _a.cascadeDeselect;
|
|
5619
|
-
if (selectionMode === 'single') {
|
|
5620
|
-
var result_1 = new Set();
|
|
5621
|
-
if (!previous.has(key)) {
|
|
5622
|
-
result_1.add(key);
|
|
5623
|
-
}
|
|
5624
|
-
return result_1;
|
|
5625
|
-
}
|
|
5626
|
-
var result = new Set(previous);
|
|
5627
|
-
var node = findNode(nodes, key);
|
|
5628
|
-
var descendants = node ? collectDescendantKeys(node) : [];
|
|
5629
|
-
var disabled = new Set(collectDisabledKeys(nodes));
|
|
5630
|
-
if (!previous.has(key)) {
|
|
5631
|
-
result.add(key);
|
|
5632
|
-
if (cascadeSelect) {
|
|
5633
|
-
descendants.forEach(function (k) {
|
|
5634
|
-
if (!disabled.has(k)) {
|
|
5635
|
-
result.add(k);
|
|
5636
|
-
}
|
|
5637
|
-
});
|
|
5638
|
-
}
|
|
5639
|
-
}
|
|
5640
|
-
else {
|
|
5641
|
-
result.delete(key);
|
|
5642
|
-
if (cascadeDeselect) {
|
|
5643
|
-
descendants.forEach(function (k) { return result.delete(k); });
|
|
5644
|
-
}
|
|
5645
|
-
}
|
|
5646
|
-
return result;
|
|
5647
|
-
}
|
|
5648
5609
|
/**
|
|
5649
5610
|
* Apply react-aria's proposed selection while enforcing cascade. Each key
|
|
5650
5611
|
* react-aria added cascades to its descendants when `cascadeSelect` is set; each
|
|
@@ -5692,6 +5653,7 @@ var ROW_GAP = 2;
|
|
|
5692
5653
|
var LIST_PADDING = 4;
|
|
5693
5654
|
var TreeView = React.forwardRef(function (_a, ref) {
|
|
5694
5655
|
var items = _a.items, onAction = _a.onAction, _b = _a.selectionMode, selectionMode = _b === void 0 ? 'none' : _b, _c = _a.cascadeSelect, cascadeSelect = _c === void 0 ? false : _c, _d = _a.cascadeDeselect, cascadeDeselect = _d === void 0 ? false : _d, defaultExpandedKeys = _a.defaultExpandedKeys, _e = _a.virtualized, virtualized = _e === void 0 ? false : _e, height = _a.height, className = _a.className, style = _a.style, other = tslib.__rest(_a, ["items", "onAction", "selectionMode", "cascadeSelect", "cascadeDeselect", "defaultExpandedKeys", "virtualized", "height", "className", "style"]);
|
|
5656
|
+
var treeRef = useSharedRef(ref);
|
|
5695
5657
|
var _f = tslib.__read(React.useState(new Set()), 2), selectedKeys = _f[0], setSelectedKeys = _f[1];
|
|
5696
5658
|
var cascade = { cascadeSelect: cascadeSelect, cascadeDeselect: cascadeDeselect };
|
|
5697
5659
|
// Cascade only applies to multiple selection.
|
|
@@ -5706,16 +5668,48 @@ var TreeView = React.forwardRef(function (_a, ref) {
|
|
|
5706
5668
|
: selection;
|
|
5707
5669
|
});
|
|
5708
5670
|
};
|
|
5709
|
-
//
|
|
5710
|
-
//
|
|
5711
|
-
|
|
5712
|
-
|
|
5713
|
-
|
|
5714
|
-
|
|
5715
|
-
|
|
5716
|
-
|
|
5717
|
-
|
|
5718
|
-
|
|
5671
|
+
// react-aria only reports a press as an action while nothing is selected, so
|
|
5672
|
+
// activation is driven here and react-aria is left to own selection. Click,
|
|
5673
|
+
// Space and Enter all do the same thing: toggle the checkbox and run the action.
|
|
5674
|
+
// Without selection react-aria handles the action itself (see the Tree props).
|
|
5675
|
+
React.useEffect(function () {
|
|
5676
|
+
var node = treeRef.current;
|
|
5677
|
+
if (!node || !onAction || selectionMode === 'none')
|
|
5678
|
+
return;
|
|
5679
|
+
var rowKey = function (target) {
|
|
5680
|
+
var _a;
|
|
5681
|
+
var row = (_a = target === null || target === void 0 ? void 0 : target.closest) === null || _a === void 0 ? void 0 : _a.call(target, '[role="row"][data-key]');
|
|
5682
|
+
if (!row || row.getAttribute('aria-disabled') === 'true')
|
|
5683
|
+
return null;
|
|
5684
|
+
return row.getAttribute('data-key');
|
|
5685
|
+
};
|
|
5686
|
+
var handleKeyDown = function (event) {
|
|
5687
|
+
if (event.key !== 'Enter' && event.key !== ' ')
|
|
5688
|
+
return;
|
|
5689
|
+
if (event.repeat || event.defaultPrevented)
|
|
5690
|
+
return;
|
|
5691
|
+
var key = rowKey(event.target);
|
|
5692
|
+
if (key)
|
|
5693
|
+
onAction(key);
|
|
5694
|
+
};
|
|
5695
|
+
var handleClick = function (event) {
|
|
5696
|
+
var _a;
|
|
5697
|
+
var target = event.target;
|
|
5698
|
+
// The chevron expands rather than activates, and a click on the
|
|
5699
|
+
// checkbox box or label is re-dispatched on the checkbox itself.
|
|
5700
|
+
if ((_a = target === null || target === void 0 ? void 0 : target.closest) === null || _a === void 0 ? void 0 : _a.call(target, '.TreeView__chevron, label[for], .Checkbox__overlay'))
|
|
5701
|
+
return;
|
|
5702
|
+
var key = rowKey(target);
|
|
5703
|
+
if (key)
|
|
5704
|
+
onAction(key);
|
|
5705
|
+
};
|
|
5706
|
+
node.addEventListener('keydown', handleKeyDown);
|
|
5707
|
+
node.addEventListener('click', handleClick);
|
|
5708
|
+
return function () {
|
|
5709
|
+
node.removeEventListener('keydown', handleKeyDown);
|
|
5710
|
+
node.removeEventListener('click', handleClick);
|
|
5711
|
+
};
|
|
5712
|
+
}, [onAction, selectionMode, virtualized]);
|
|
5719
5713
|
// Disabled nodes are non-selectable; react-aria disables them via disabledKeys.
|
|
5720
5714
|
var disabledKeys = React.useMemo(function () { return collectDisabledKeys(items); }, [items]);
|
|
5721
5715
|
// Always control selection: react-aria's own state is lost if the tree
|
|
@@ -5727,9 +5721,11 @@ var TreeView = React.forwardRef(function (_a, ref) {
|
|
|
5727
5721
|
// The `height` prop outranks `style.height`, but only when it is actually
|
|
5728
5722
|
// set — spreading an undefined `height` would wipe the caller's own.
|
|
5729
5723
|
var mergedStyle = virtualized && height !== undefined ? tslib.__assign(tslib.__assign({}, style), { height: height }) : style;
|
|
5730
|
-
var tree = (React__default["default"].createElement(reactAriaComponents.Tree, tslib.__assign({ ref:
|
|
5724
|
+
var tree = (React__default["default"].createElement(reactAriaComponents.Tree, tslib.__assign({ ref: treeRef, className: classNames__default["default"]('TreeView', className, {
|
|
5731
5725
|
'TreeView--virtualized': virtualized
|
|
5732
|
-
}), selectionMode: selectionMode, defaultExpandedKeys: defaultExpandedKeys }, (disabledKeys.length > 0 ? { disabledKeys: disabledKeys } : {}), (onAction
|
|
5726
|
+
}), selectionMode: selectionMode, defaultExpandedKeys: defaultExpandedKeys }, (disabledKeys.length > 0 ? { disabledKeys: disabledKeys } : {}), (onAction && selectionMode === 'none'
|
|
5727
|
+
? { onAction: function (key) { return onAction(String(key)); } }
|
|
5728
|
+
: {}), selectionProps, other, { style: mergedStyle }), items.map(function (item) { return (React__default["default"].createElement(TreeViewItem, tslib.__assign({ key: item.id }, item))); })));
|
|
5733
5729
|
// Rows are absolutely positioned here, so the list layout owns their spacing
|
|
5734
5730
|
// rather than `.TreeView`'s flex `gap`/`padding`.
|
|
5735
5731
|
if (virtualized) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deque/cauldron-react",
|
|
3
|
-
"version": "7.6.0-canary.
|
|
3
|
+
"version": "7.6.0-canary.05d324ca",
|
|
4
4
|
"license": "MPL-2.0",
|
|
5
5
|
"description": "Fully accessible react components library for Deque Cauldron",
|
|
6
6
|
"homepage": "https://cauldron.dequelabs.com/",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"classnames": "^2.2.6",
|
|
20
20
|
"focusable": "^2.3.0",
|
|
21
21
|
"keyname": "^0.1.0",
|
|
22
|
-
"react-aria-components": "^1.
|
|
22
|
+
"react-aria-components": "^1.21.1",
|
|
23
23
|
"react-id-generator": "^3.0.1",
|
|
24
24
|
"react-syntax-highlighter": "^16.1.1",
|
|
25
25
|
"tslib": "^2.4.0"
|