@calcifer-design/ui 0.4.0 → 0.6.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.
Files changed (133) hide show
  1. package/dist/components/Breadcrumb/Breadcrumb.d.ts +24 -0
  2. package/dist/components/Breadcrumb/Breadcrumb.js +48 -0
  3. package/dist/components/Breadcrumb/Breadcrumb.module.js +10 -0
  4. package/dist/components/Breadcrumb/Breadcrumb_module.css +49 -0
  5. package/dist/components/CardList/CardList.d.ts +30 -0
  6. package/dist/components/CardList/CardList.js +35 -0
  7. package/dist/components/CardList/CardList.module.js +7 -0
  8. package/dist/components/CardList/CardList_module.css +20 -0
  9. package/dist/components/DataGrid/DataGrid.d.ts +3 -0
  10. package/dist/components/DataGrid/DataGrid.js +436 -0
  11. package/dist/components/DataGrid/DataGrid.module.js +36 -0
  12. package/dist/components/DataGrid/DataGrid_module.css +367 -0
  13. package/dist/components/DataGrid/GridCardHeader.d.ts +16 -0
  14. package/dist/components/DataGrid/GridCardHeader.js +40 -0
  15. package/dist/components/DataGrid/GridCheckbox.d.ts +15 -0
  16. package/dist/components/DataGrid/GridCheckbox.js +25 -0
  17. package/dist/components/DataGrid/GridHeaderCell.d.ts +14 -0
  18. package/dist/components/DataGrid/GridHeaderCell.js +29 -0
  19. package/dist/components/DataGrid/GridHeaderRow.d.ts +35 -0
  20. package/dist/components/DataGrid/GridHeaderRow.js +56 -0
  21. package/dist/components/DataGrid/GridRow.d.ts +69 -0
  22. package/dist/components/DataGrid/GridRow.js +139 -0
  23. package/dist/components/DataGrid/GridStateRows.d.ts +24 -0
  24. package/dist/components/DataGrid/GridStateRows.js +59 -0
  25. package/dist/components/DataGrid/columns.d.ts +40 -0
  26. package/dist/components/DataGrid/columns.js +37 -0
  27. package/dist/components/DataGrid/labels.d.ts +20 -0
  28. package/dist/components/DataGrid/labels.js +25 -0
  29. package/dist/components/DataGrid/types.d.ts +88 -0
  30. package/dist/components/DataGrid/types.js +0 -0
  31. package/dist/components/DataGrid/useGridEntries.d.ts +17 -0
  32. package/dist/components/DataGrid/useGridEntries.js +40 -0
  33. package/dist/components/DataGrid/useGridHighlight.d.ts +16 -0
  34. package/dist/components/DataGrid/useGridHighlight.js +24 -0
  35. package/dist/components/DataGrid/useGridKeyboard.d.ts +50 -0
  36. package/dist/components/DataGrid/useGridKeyboard.js +242 -0
  37. package/dist/components/DataGrid/useGridMetrics.d.ts +13 -0
  38. package/dist/components/DataGrid/useGridMetrics.js +35 -0
  39. package/dist/components/DataGrid/useLatest.d.ts +7 -0
  40. package/dist/components/DataGrid/useLatest.js +9 -0
  41. package/dist/components/DataGrid/useLoadMore.d.ts +30 -0
  42. package/dist/components/DataGrid/useLoadMore.js +39 -0
  43. package/dist/components/DataGrid/useRowExpansion.d.ts +14 -0
  44. package/dist/components/DataGrid/useRowExpansion.js +21 -0
  45. package/dist/components/DataGrid/useRowSelection.d.ts +43 -0
  46. package/dist/components/DataGrid/useRowSelection.js +107 -0
  47. package/dist/components/DatePicker/Calendar.d.ts +19 -0
  48. package/dist/components/DatePicker/Calendar.js +207 -0
  49. package/dist/components/DatePicker/DatePicker.d.ts +72 -0
  50. package/dist/components/DatePicker/DatePicker.js +116 -0
  51. package/dist/components/DatePicker/DatePicker.module.js +14 -0
  52. package/dist/components/DatePicker/DatePicker_module.css +112 -0
  53. package/dist/components/DatePicker/calendarDate.d.ts +46 -0
  54. package/dist/components/DatePicker/calendarDate.js +117 -0
  55. package/dist/components/Descriptions/Descriptions.d.ts +25 -0
  56. package/dist/components/Descriptions/Descriptions.js +44 -0
  57. package/dist/components/Descriptions/Descriptions.module.js +8 -0
  58. package/dist/components/Descriptions/Descriptions_module.css +47 -0
  59. package/dist/components/Field/Field.d.ts +1 -1
  60. package/dist/components/Field/Field.js +7 -1
  61. package/dist/components/Field/PickerField.d.ts +41 -0
  62. package/dist/components/Field/PickerField.js +115 -0
  63. package/dist/components/Field/PickerField.module.js +8 -0
  64. package/dist/components/Field/PickerField_module.css +36 -0
  65. package/dist/components/FilterBar/FilterBar.d.ts +55 -0
  66. package/dist/components/FilterBar/FilterBar.js +138 -0
  67. package/dist/components/FilterBar/FilterBar.module.js +13 -0
  68. package/dist/components/FilterBar/FilterBar_module.css +98 -0
  69. package/dist/components/Form/Form.d.ts +48 -0
  70. package/dist/components/Form/Form.js +38 -0
  71. package/dist/components/Form/Form.module.js +5 -0
  72. package/dist/components/Form/FormContext.d.ts +15 -0
  73. package/dist/components/Form/FormContext.js +20 -0
  74. package/dist/components/Form/Form_module.css +6 -0
  75. package/dist/components/PageShell/PageShell.d.ts +27 -0
  76. package/dist/components/PageShell/PageShell.js +35 -0
  77. package/dist/components/PageShell/PageShell.module.js +9 -0
  78. package/dist/components/PageShell/PageShell_module.css +56 -0
  79. package/dist/components/Segmented/Segmented.d.ts +49 -0
  80. package/dist/components/Segmented/Segmented.js +55 -0
  81. package/dist/components/Segmented/Segmented.module.js +7 -0
  82. package/dist/components/Segmented/Segmented_module.css +75 -0
  83. package/dist/components/Steps/Steps.d.ts +30 -0
  84. package/dist/components/Steps/Steps.js +63 -0
  85. package/dist/components/Steps/Steps.module.js +10 -0
  86. package/dist/components/Steps/Steps_module.css +126 -0
  87. package/dist/components/TextArea/TextArea.d.ts +16 -0
  88. package/dist/components/TextArea/TextArea.js +28 -0
  89. package/dist/components/TextArea/TextArea.module.js +5 -0
  90. package/dist/components/TextArea/TextArea_module.css +12 -0
  91. package/dist/components/TimePicker/TimePicker.d.ts +19 -0
  92. package/dist/components/TimePicker/TimePicker.js +17 -0
  93. package/dist/components/Timeline/Timeline.d.ts +39 -0
  94. package/dist/components/Timeline/Timeline.js +109 -0
  95. package/dist/components/Timeline/Timeline.module.js +12 -0
  96. package/dist/components/Timeline/Timeline_module.css +99 -0
  97. package/dist/components/Toolbar/InsideToolbarContext.d.ts +6 -0
  98. package/dist/components/Toolbar/InsideToolbarContext.js +3 -0
  99. package/dist/components/Toolbar/Toolbar.d.ts +46 -0
  100. package/dist/components/Toolbar/Toolbar.js +43 -0
  101. package/dist/components/Toolbar/Toolbar.module.js +7 -0
  102. package/dist/components/Toolbar/Toolbar_module.css +26 -0
  103. package/dist/components/Tree/Tree.d.ts +81 -0
  104. package/dist/components/Tree/Tree.js +232 -0
  105. package/dist/components/Tree/Tree.module.js +12 -0
  106. package/dist/components/Tree/Tree_module.css +124 -0
  107. package/dist/components/Tree/treeIndex.d.ts +23 -0
  108. package/dist/components/Tree/treeIndex.js +33 -0
  109. package/dist/components/TreeSelect/TreeSelect.d.ts +61 -0
  110. package/dist/components/TreeSelect/TreeSelect.js +117 -0
  111. package/dist/components/TreeSelect/TreeSelect.module.js +7 -0
  112. package/dist/components/TreeSelect/TreeSelect_module.css +22 -0
  113. package/dist/components/Upload/Upload.d.ts +66 -0
  114. package/dist/components/Upload/Upload.js +287 -0
  115. package/dist/components/Upload/Upload.module.js +12 -0
  116. package/dist/components/Upload/Upload_module.css +96 -0
  117. package/dist/components/ViewField/ViewField.d.ts +26 -0
  118. package/dist/components/ViewField/ViewField.js +29 -0
  119. package/dist/components/ViewField/ViewField.module.js +6 -0
  120. package/dist/components/ViewField/ViewField_module.css +17 -0
  121. package/dist/hooks/useFormReset.d.ts +10 -0
  122. package/dist/hooks/useFormReset.js +34 -0
  123. package/dist/icons/CalendarIcon.d.ts +2 -0
  124. package/dist/icons/CalendarIcon.js +26 -0
  125. package/dist/icons/ChevronRightIcon.d.ts +6 -0
  126. package/dist/icons/ChevronRightIcon.js +17 -0
  127. package/dist/icons/RefreshIcon.d.ts +6 -0
  128. package/dist/icons/RefreshIcon.js +22 -0
  129. package/dist/index.d.ts +39 -0
  130. package/dist/index.js +19 -0
  131. package/dist/styles/pair.module.js +6 -0
  132. package/dist/styles/pair_module.css +18 -0
  133. package/package.json +4 -3
@@ -0,0 +1,3 @@
1
+ import { createContext } from "react";
2
+ const InsideToolbarContext = createContext(false);
3
+ export { InsideToolbarContext };
@@ -0,0 +1,46 @@
1
+ import { Toolbar as BaseToolbar } from '@base-ui/react/toolbar';
2
+ import type { ComponentPropsWithoutRef, CSSProperties, ReactElement, ReactNode } from 'react';
3
+ export interface ToolbarProps {
4
+ /** Names the toolbar. Required: a toolbar has no visible name to fall back on. */
5
+ 'aria-label': string;
6
+ /** Which arrow keys move focus: left and right when `horizontal`, up and down when `vertical`. */
7
+ orientation?: 'horizontal' | 'vertical';
8
+ /** `ToolbarButton`, `ToolbarGroup`, `ToolbarSeparator` and `Segmented`. */
9
+ children: ReactNode;
10
+ }
11
+ /**
12
+ * A row or a column of controls that is one tab stop, whose arrow keys move focus and loop at the
13
+ * ends. Base UI's `Toolbar.Root` does not turn on Home and End and has no public prop to; the
14
+ * WAI-ARIA toolbar pattern lists them as optional.
15
+ */
16
+ export declare function Toolbar({ 'aria-label': ariaLabel, orientation, children, }: ToolbarProps): import("react").JSX.Element;
17
+ export interface ToolbarButtonProps extends Omit<ComponentPropsWithoutRef<typeof BaseToolbar.Button>, 'className' | 'style' | 'render' | 'focusableWhenDisabled' | 'nativeButton'> {
18
+ /** A `Button` or `IconButton` to wear. With none it wears a small secondary `Button`. */
19
+ render?: ReactElement;
20
+ /** Shows a busy state on the `Button` or `IconButton` it wears, and blocks activation. */
21
+ loading?: boolean;
22
+ className?: string;
23
+ style?: CSSProperties;
24
+ }
25
+ /**
26
+ * A button in the toolbar's roving focus. `render` picks its look: `<Button variant="ghost" />`
27
+ * or `<IconButton label="Approve">{icon}</IconButton>`. Base UI's part draws nothing of its own,
28
+ * so with no `render` it wears a small secondary `Button` rather than go unstyled.
29
+ *
30
+ * `disabled` and `loading` go here, not on the element in `render`. Here, Base UI keeps the button
31
+ * focusable and says so with `aria-disabled`. On a `Button` in `render`, `disabled` comes out
32
+ * natively disabled, out of the arrow keys' reach, and with a contradictory `aria-disabled="false"`;
33
+ * `loading` comes out dimmed and inert, with that same `aria-disabled="false"`. Measured.
34
+ */
35
+ export declare function ToolbarButton({ render, disabled, loading, ...rest }: ToolbarButtonProps): import("react").JSX.Element;
36
+ export interface ToolbarGroupProps {
37
+ /** Names the group for assistive technology. */
38
+ 'aria-label'?: string;
39
+ /** Disables every `ToolbarButton` inside it. */
40
+ disabled?: boolean;
41
+ children: ReactNode;
42
+ }
43
+ /** Groups related controls. It adds no tab stop: arrow keys pass straight through it. */
44
+ export declare function ToolbarGroup({ 'aria-label': ariaLabel, disabled, children }: ToolbarGroupProps): import("react").JSX.Element;
45
+ /** A rule between controls, drawn across the toolbar's own direction. */
46
+ export declare function ToolbarSeparator(): import("react").JSX.Element;
@@ -0,0 +1,43 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { Toolbar } from "@base-ui/react/toolbar";
3
+ import { Button } from "../Button/Button.js";
4
+ import { InsideToolbarContext } from "./InsideToolbarContext.js";
5
+ import Toolbar_module from "./Toolbar.module.js";
6
+ function Toolbar_Toolbar({ 'aria-label': ariaLabel, orientation = 'horizontal', children }) {
7
+ return /*#__PURE__*/ jsx(InsideToolbarContext.Provider, {
8
+ value: true,
9
+ children: /*#__PURE__*/ jsx(Toolbar.Root, {
10
+ className: Toolbar_module.root,
11
+ "aria-label": ariaLabel,
12
+ orientation: orientation,
13
+ children: children
14
+ })
15
+ });
16
+ }
17
+ function ToolbarButton({ render = /*#__PURE__*/ jsx(Button, {
18
+ variant: "secondary",
19
+ size: "sm"
20
+ }), disabled, loading, ...rest }) {
21
+ return /*#__PURE__*/ jsx(Toolbar.Button, {
22
+ render: render,
23
+ disabled: disabled || loading,
24
+ ...loading ? {
25
+ loading
26
+ } : null,
27
+ ...rest
28
+ });
29
+ }
30
+ function ToolbarGroup({ 'aria-label': ariaLabel, disabled, children }) {
31
+ return /*#__PURE__*/ jsx(Toolbar.Group, {
32
+ className: Toolbar_module.group,
33
+ "aria-label": ariaLabel,
34
+ disabled: disabled,
35
+ children: children
36
+ });
37
+ }
38
+ function ToolbarSeparator() {
39
+ return /*#__PURE__*/ jsx(Toolbar.Separator, {
40
+ className: Toolbar_module.separator
41
+ });
42
+ }
43
+ export { ToolbarButton, ToolbarGroup, ToolbarSeparator, Toolbar_Toolbar as Toolbar };
@@ -0,0 +1,7 @@
1
+ import "./Toolbar_module.css";
2
+ const Toolbar_module = {
3
+ root: "root-TasA5",
4
+ group: "group-gw9JG",
5
+ separator: "separator-pZlgb"
6
+ };
7
+ export default Toolbar_module;
@@ -0,0 +1,26 @@
1
+ .root-TasA5, .group-gw9JG {
2
+ align-items: center;
3
+ gap: var(--space-2);
4
+ flex-wrap: wrap;
5
+ display: flex;
6
+ }
7
+
8
+ .root-TasA5[data-orientation="vertical"], .group-gw9JG[data-orientation="vertical"] {
9
+ flex-direction: column;
10
+ align-items: stretch;
11
+ }
12
+
13
+ .separator-pZlgb {
14
+ background: var(--color-border-strong);
15
+ flex: none;
16
+ }
17
+
18
+ .separator-pZlgb[data-orientation="vertical"] {
19
+ align-self: stretch;
20
+ width: 1px;
21
+ }
22
+
23
+ .separator-pZlgb[data-orientation="horizontal"] {
24
+ height: 1px;
25
+ }
26
+
@@ -0,0 +1,81 @@
1
+ import { type ReactNode } from 'react';
2
+ export interface TreeItem {
3
+ /**
4
+ * Identifies the item across renders, and unique in the whole tree, not only among its siblings.
5
+ * A repeated id is left out, with everything under it: the first one in reading order stays.
6
+ */
7
+ id: string;
8
+ /** The visible text, the accessible name and what type-ahead matches. */
9
+ label: string;
10
+ /** Sits before the label. Decorative: it stays out of the accessible name. */
11
+ icon?: ReactNode;
12
+ /**
13
+ * Focusable and read out, as the WAI-ARIA pattern asks, but inert: it cannot be selected and does
14
+ * not open or close. It says nothing about what it holds, which an app can still open for it.
15
+ */
16
+ disabled?: boolean;
17
+ children?: TreeItem[];
18
+ }
19
+ export type TreeSelectionMode = 'none' | 'single' | 'multiple';
20
+ interface TreeBaseProps {
21
+ /**
22
+ * Static data. A new array of the same ids changes nothing but what is drawn. With none, nothing
23
+ * is drawn, and what to say instead is the app's.
24
+ */
25
+ items: TreeItem[];
26
+ /** Controlled: the ids of the open parents. Pair it with `onExpandedChange`. */
27
+ expandedIds?: string[];
28
+ /** Uncontrolled: the parents open at first. */
29
+ defaultExpandedIds?: string[];
30
+ /** Every open id, in one argument, each time a parent opens or closes. */
31
+ onExpandedChange?: (ids: string[]) => void;
32
+ /**
33
+ * `none`, the default: Enter, Space and a press on the row open and close a parent. `single` and
34
+ * `multiple`: they select, and the chevron or the Left and Right keys open and close. `single`
35
+ * cannot deselect: pressing the selected item again changes nothing, and only choosing another
36
+ * moves it. `multiple` toggles one item at a time; there is no range selection.
37
+ */
38
+ selectionMode?: TreeSelectionMode;
39
+ /**
40
+ * Controlled: the selected ids. Pair it with `onSelectedChange`. Under `single` the first id an
41
+ * item holds counts, and under `none` this is ignored. An id no item holds selects nothing.
42
+ */
43
+ selectedIds?: string[];
44
+ /** Uncontrolled: the ids selected at first. */
45
+ defaultSelectedIds?: string[];
46
+ /** Every selected id, in one argument, and only for a real change. */
47
+ onSelectedChange?: (ids: string[]) => void;
48
+ }
49
+ interface TreeNamedByLabel extends TreeBaseProps {
50
+ /** Names the tree. One of this and `aria-labelledby` is required. */
51
+ 'aria-label': string;
52
+ 'aria-labelledby'?: undefined;
53
+ }
54
+ interface TreeNamedByElement extends TreeBaseProps {
55
+ 'aria-label'?: undefined;
56
+ /** The id of the element that names the tree. */
57
+ 'aria-labelledby': string;
58
+ }
59
+ export type TreeProps = TreeNamedByLabel | TreeNamedByElement;
60
+ type TreeViewProps = TreeProps & {
61
+ /** A press on an item that can be chosen, including the one chosen already. `TreeSelect`'s. */
62
+ onItemChoose?: (id: string) => void;
63
+ };
64
+ /**
65
+ * The tree, with one prop more than the public `Tree`. Internal: not exported from `src/index.ts`.
66
+ *
67
+ * Open branches are nested in the DOM, so a browser works out each item's level and position in its
68
+ * set for itself, and `aria-level`, `aria-setsize` and `aria-posinset` would only repeat it.
69
+ */
70
+ export declare function TreeView({ items, expandedIds, defaultExpandedIds, onExpandedChange, selectionMode, selectedIds, defaultSelectedIds, onSelectedChange, onItemChoose, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy, }: TreeViewProps): import("react").JSX.Element | null;
71
+ /**
72
+ * A hierarchy to move through and select from, following the WAI-ARIA tree view pattern: one tab
73
+ * stop, arrow keys, Home, End and type-ahead. Left and Right swap in a right-to-left page.
74
+ *
75
+ * Tab lands on the selected item, or on the nearest open ancestor of one that is collapsed away,
76
+ * else on the first enabled item. Focus never goes with an item: when it is removed or collapsed
77
+ * away, focus moves to the nearest ancestor still shown. Only when every item goes does it fall to
78
+ * the page, and it is not taken back when items return.
79
+ */
80
+ export declare function Tree(props: TreeProps): import("react").JSX.Element;
81
+ export {};
@@ -0,0 +1,232 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useId, useLayoutEffect, useMemo, useRef, useState } from "react";
3
+ import { CheckIcon } from "../../icons/CheckIcon.js";
4
+ import { ChevronDownIcon } from "../../icons/ChevronDownIcon.js";
5
+ import { indexItems, visibleNodesOf } from "./treeIndex.js";
6
+ import Tree_module from "./Tree.module.js";
7
+ const TYPE_AHEAD_WINDOW = 500;
8
+ const KEYS_WITHIN_TYPING = new Set([
9
+ 'Shift',
10
+ 'CapsLock',
11
+ 'AltGraph',
12
+ 'Dead'
13
+ ]);
14
+ function nearestShown(visible, { id, ancestorIds }) {
15
+ return [
16
+ id,
17
+ ...ancestorIds
18
+ ].map((candidate)=>visible.find((node)=>node.id === candidate)).find((node)=>void 0 !== node);
19
+ }
20
+ function restingNode(visible, nodes, selected) {
21
+ const [firstHeld] = selected;
22
+ const collapsedAway = void 0 === firstHeld ? void 0 : nodes.get(firstHeld);
23
+ return visible.find((node)=>selected.has(node.id)) ?? (void 0 === collapsedAway ? void 0 : nearestShown(visible, collapsedAway)) ?? visible.find((node)=>!node.item.disabled) ?? visible[0];
24
+ }
25
+ function isPrintable(key) {
26
+ return 1 === Array.from(key).length;
27
+ }
28
+ function findTypedMatch(visible, from, typed) {
29
+ const wanted = typed.toLocaleLowerCase();
30
+ for(let offset = 0; offset < visible.length; offset += 1){
31
+ const candidate = visible[(from + offset) % visible.length];
32
+ if (candidate?.item.label.toLocaleLowerCase().startsWith(wanted)) return candidate;
33
+ }
34
+ }
35
+ function TreeView({ items, expandedIds, defaultExpandedIds, onExpandedChange, selectionMode = 'none', selectedIds, defaultSelectedIds, onSelectedChange, onItemChoose, 'aria-label': ariaLabel, 'aria-labelledby': ariaLabelledBy }) {
36
+ const baseId = useId();
37
+ const rootRef = useRef(null);
38
+ const itemElements = useRef(new Map());
39
+ const typedSoFar = useRef({
40
+ text: '',
41
+ at: -1 / 0
42
+ });
43
+ const [heldExpanded, setHeldExpanded] = useState(defaultExpandedIds ?? []);
44
+ const [heldSelected, setHeldSelected] = useState(defaultSelectedIds ?? []);
45
+ const [focused, setFocused] = useState(null);
46
+ const index = useMemo(()=>indexItems(items), [
47
+ items
48
+ ]);
49
+ const expanded = expandedIds ?? heldExpanded;
50
+ const expandedSet = useMemo(()=>new Set(expanded), [
51
+ expanded
52
+ ]);
53
+ const visible = useMemo(()=>visibleNodesOf(index.roots, expandedSet), [
54
+ index.roots,
55
+ expandedSet
56
+ ]);
57
+ const selected = selectedIds ?? heldSelected;
58
+ const selectedSet = useMemo(()=>{
59
+ if ('none' === selectionMode) return new Set();
60
+ const known = selected.filter((id)=>index.nodes.has(id));
61
+ return new Set('single' === selectionMode ? known.slice(0, 1) : known);
62
+ }, [
63
+ selectionMode,
64
+ selected,
65
+ index.nodes
66
+ ]);
67
+ const tabStop = (null === focused ? void 0 : nearestShown(visible, index.nodes.get(focused.id) ?? focused)) ?? restingNode(visible, index.nodes, selectedSet);
68
+ useLayoutEffect(()=>{
69
+ if (null === focused) return;
70
+ const stop = void 0 === tabStop ? void 0 : itemElements.current.get(tabStop.id);
71
+ if (void 0 === stop) setFocused(null);
72
+ else if (document.activeElement !== stop) stop.focus();
73
+ });
74
+ useLayoutEffect(()=>{
75
+ if (null !== rootRef.current) rootRef.current.dataset.direction = getComputedStyle(rootRef.current).direction;
76
+ });
77
+ const toggleExpanded = (node)=>{
78
+ if (node.item.disabled || 0 === node.children.length) return;
79
+ const next = expandedSet.has(node.id) ? expanded.filter((id)=>id !== node.id) : [
80
+ ...expanded,
81
+ node.id
82
+ ];
83
+ setHeldExpanded(next);
84
+ onExpandedChange?.(next);
85
+ };
86
+ const commitSelected = (next)=>{
87
+ setHeldSelected(next);
88
+ onSelectedChange?.(next);
89
+ };
90
+ const activate = (node)=>{
91
+ if ('none' === selectionMode) toggleExpanded(node);
92
+ else if (!node.item.disabled) {
93
+ if ('multiple' === selectionMode) commitSelected(selectedSet.has(node.id) ? selected.filter((id)=>id !== node.id) : [
94
+ ...selected,
95
+ node.id
96
+ ]);
97
+ else if (!selectedSet.has(node.id)) commitSelected([
98
+ node.id
99
+ ]);
100
+ onItemChoose?.(node.id);
101
+ }
102
+ };
103
+ const focusNode = (id)=>{
104
+ if (void 0 !== id) itemElements.current.get(id)?.focus();
105
+ };
106
+ const handleKeyDown = (event)=>{
107
+ if (event.altKey || event.ctrlKey || event.metaKey || void 0 === tabStop) return;
108
+ if (!isPrintable(event.key) && !KEYS_WITHIN_TYPING.has(event.key)) typedSoFar.current.text = '';
109
+ const position = visible.indexOf(tabStop);
110
+ const inRightToLeft = 'rtl' === getComputedStyle(event.currentTarget).direction;
111
+ const isOpen = tabStop.children.length > 0 && expandedSet.has(tabStop.id);
112
+ const isTyping = '' !== typedSoFar.current.text && event.timeStamp - typedSoFar.current.at <= TYPE_AHEAD_WINDOW;
113
+ const keyActions = {
114
+ ArrowDown: ()=>focusNode(visible[position + 1]?.id),
115
+ ArrowUp: ()=>focusNode(visible[position - 1]?.id),
116
+ Home: ()=>focusNode(visible[0]?.id),
117
+ End: ()=>focusNode(visible.at(-1)?.id),
118
+ Enter: ()=>activate(tabStop)
119
+ };
120
+ const moveInward = ()=>isOpen ? focusNode(tabStop.children[0]?.id) : toggleExpanded(tabStop);
121
+ const moveOutward = ()=>isOpen && !tabStop.item.disabled ? toggleExpanded(tabStop) : focusNode(tabStop.ancestorIds[0]);
122
+ keyActions[inRightToLeft ? 'ArrowLeft' : 'ArrowRight'] = moveInward;
123
+ keyActions[inRightToLeft ? 'ArrowRight' : 'ArrowLeft'] = moveOutward;
124
+ if (!isTyping) keyActions[' '] = ()=>activate(tabStop);
125
+ const keyAction = keyActions[event.key];
126
+ if (void 0 !== keyAction) {
127
+ event.preventDefault();
128
+ keyAction();
129
+ } else if (isPrintable(event.key)) {
130
+ event.preventDefault();
131
+ const text = (isTyping ? typedSoFar.current.text : '') + event.key;
132
+ typedSoFar.current = {
133
+ text,
134
+ at: event.timeStamp
135
+ };
136
+ const isOneLetter = Array.from(text).every((letter)=>letter === event.key);
137
+ const match = isOneLetter ? findTypedMatch(visible, position + 1, event.key) : findTypedMatch(visible, position, text);
138
+ focusNode(match?.id);
139
+ }
140
+ };
141
+ const renderNode = (node, level)=>{
142
+ const hasChildren = node.children.length > 0;
143
+ const isOpen = hasChildren && expandedSet.has(node.id);
144
+ const isSelected = selectedSet.has(node.id);
145
+ const labelId = `${baseId}-${node.ordinal}`;
146
+ const ariaSelected = isSelected || 'multiple' === selectionMode && !node.item.disabled ? isSelected : void 0;
147
+ return /*#__PURE__*/ jsxs("li", {
148
+ ref: (element)=>{
149
+ if (null !== element) itemElements.current.set(node.id, element);
150
+ return ()=>{
151
+ itemElements.current.delete(node.id);
152
+ };
153
+ },
154
+ role: "treeitem",
155
+ className: Tree_module.item,
156
+ tabIndex: node.id === tabStop?.id ? 0 : -1,
157
+ "aria-labelledby": labelId,
158
+ "aria-expanded": hasChildren ? isOpen : void 0,
159
+ "aria-selected": ariaSelected,
160
+ "aria-disabled": node.item.disabled ? true : void 0,
161
+ onFocus: (event)=>{
162
+ if (event.target === event.currentTarget) setFocused({
163
+ id: node.id,
164
+ ancestorIds: node.ancestorIds
165
+ });
166
+ },
167
+ children: [
168
+ /*#__PURE__*/ jsxs("div", {
169
+ className: Tree_module.row,
170
+ style: {
171
+ '--tree-level': level
172
+ },
173
+ onClick: ()=>activate(node),
174
+ children: [
175
+ hasChildren ? /*#__PURE__*/ jsx("span", {
176
+ className: Tree_module.toggle,
177
+ "data-toggle": "",
178
+ "aria-hidden": "true",
179
+ onClick: (event)=>{
180
+ event.stopPropagation();
181
+ toggleExpanded(node);
182
+ },
183
+ children: /*#__PURE__*/ jsx(ChevronDownIcon, {})
184
+ }) : /*#__PURE__*/ jsx("span", {
185
+ className: Tree_module.toggle
186
+ }),
187
+ node.item.icon ? /*#__PURE__*/ jsx("span", {
188
+ className: Tree_module.icon,
189
+ "aria-hidden": "true",
190
+ children: node.item.icon
191
+ }) : null,
192
+ /*#__PURE__*/ jsx("span", {
193
+ id: labelId,
194
+ className: Tree_module.label,
195
+ children: node.item.label
196
+ }),
197
+ isSelected ? /*#__PURE__*/ jsx("span", {
198
+ className: Tree_module.check,
199
+ "aria-hidden": "true",
200
+ children: /*#__PURE__*/ jsx(CheckIcon, {})
201
+ }) : null
202
+ ]
203
+ }),
204
+ isOpen ? /*#__PURE__*/ jsx("ul", {
205
+ role: "group",
206
+ className: Tree_module.group,
207
+ children: node.children.map((child)=>renderNode(child, level + 1))
208
+ }) : null
209
+ ]
210
+ }, node.id);
211
+ };
212
+ if (0 === index.roots.length) return null;
213
+ return /*#__PURE__*/ jsx("ul", {
214
+ ref: rootRef,
215
+ role: "tree",
216
+ className: Tree_module.root,
217
+ "aria-label": ariaLabel,
218
+ "aria-labelledby": ariaLabelledBy,
219
+ "aria-multiselectable": 'multiple' === selectionMode ? true : void 0,
220
+ onKeyDown: handleKeyDown,
221
+ onBlur: (event)=>{
222
+ if (!event.currentTarget.contains(event.relatedTarget)) setFocused(null);
223
+ },
224
+ children: index.roots.map((node)=>renderNode(node, 0))
225
+ });
226
+ }
227
+ function Tree(props) {
228
+ return /*#__PURE__*/ jsx(TreeView, {
229
+ ...props
230
+ });
231
+ }
232
+ export { Tree, TreeView };
@@ -0,0 +1,12 @@
1
+ import "./Tree_module.css";
2
+ const Tree_module = {
3
+ root: "root-dqkRl",
4
+ group: "group-nEZG3",
5
+ row: "row-Idt69",
6
+ item: "item-ZpP2D",
7
+ icon: "icon-Vc8zg",
8
+ check: "check-Ccwtp",
9
+ toggle: "toggle-Dv2Gv",
10
+ label: "label-u_zOq"
11
+ };
12
+ export default Tree_module;
@@ -0,0 +1,124 @@
1
+ .root-dqkRl, .group-nEZG3 {
2
+ margin: 0;
3
+ padding: 0;
4
+ list-style: none;
5
+ }
6
+
7
+ .root-dqkRl {
8
+ min-width: 0;
9
+ padding: var(--space-1);
10
+ }
11
+
12
+ .row-Idt69 {
13
+ --tree-indent: min(calc(var(--tree-level) * var(--space-4)), 40%);
14
+ align-items: center;
15
+ gap: var(--space-1);
16
+ min-height: var(--size-touch);
17
+ padding-inline: var(--tree-indent) var(--space-2);
18
+ border-radius: var(--radius-md);
19
+ color: var(--color-text);
20
+ font-size: var(--text-md);
21
+ line-height: var(--leading-snug);
22
+ cursor: pointer;
23
+ -webkit-user-select: none;
24
+ user-select: none;
25
+ transition-property: background-color, color;
26
+ transition-duration: var(--motion-duration-1);
27
+ transition-timing-function: var(--motion-ease);
28
+ -webkit-tap-highlight-color: transparent;
29
+ margin-block-end: var(--space-1);
30
+ display: flex;
31
+ }
32
+
33
+ .item-ZpP2D:focus-visible {
34
+ outline: none;
35
+ }
36
+
37
+ .item-ZpP2D:focus-visible > .row-Idt69 {
38
+ outline: var(--focus-ring-width) solid var(--color-focus);
39
+ outline-offset: var(--focus-ring-offset);
40
+ }
41
+
42
+ @media (hover: hover) {
43
+ .row-Idt69:hover {
44
+ background: var(--color-surface-2);
45
+ }
46
+
47
+ .item-ZpP2D[aria-selected="true"] > .row-Idt69:hover {
48
+ background: var(--color-accent-hover);
49
+ }
50
+ }
51
+
52
+ .item-ZpP2D[aria-selected="true"] > .row-Idt69 {
53
+ background: var(--color-accent);
54
+ color: var(--color-accent-text);
55
+ }
56
+
57
+ .item-ZpP2D[aria-disabled="true"] > .row-Idt69 {
58
+ cursor: not-allowed;
59
+ }
60
+
61
+ .item-ZpP2D[aria-disabled="true"] > .row-Idt69 > * {
62
+ opacity: .45;
63
+ }
64
+
65
+ .icon-Vc8zg, .check-Ccwtp {
66
+ flex: none;
67
+ display: inline-flex;
68
+ }
69
+
70
+ .icon-Vc8zg > svg, .check-Ccwtp > svg {
71
+ width: 1rem;
72
+ height: 1rem;
73
+ }
74
+
75
+ .toggle-Dv2Gv {
76
+ flex: none;
77
+ justify-content: center;
78
+ align-self: stretch;
79
+ align-items: center;
80
+ width: 2rem;
81
+ display: inline-flex;
82
+ }
83
+
84
+ .toggle-Dv2Gv > svg {
85
+ width: 1rem;
86
+ height: 1rem;
87
+ transition-property: transform;
88
+ transition-duration: var(--motion-duration-1);
89
+ transition-timing-function: var(--motion-ease);
90
+ transform: rotate(-90deg);
91
+ }
92
+
93
+ .root-dqkRl[data-direction="rtl"] .toggle-Dv2Gv > svg {
94
+ transform: rotate(90deg);
95
+ }
96
+
97
+ .item-ZpP2D[aria-expanded="true"] > .row-Idt69 > .toggle-Dv2Gv > svg, .root-dqkRl[data-direction="rtl"] .item-ZpP2D[aria-expanded="true"] > .row-Idt69 > .toggle-Dv2Gv > svg {
98
+ transform: none;
99
+ }
100
+
101
+ .label-u_zOq {
102
+ min-width: 0;
103
+ padding-block: var(--space-2);
104
+ overflow-wrap: anywhere;
105
+ flex: 1;
106
+ }
107
+
108
+ @media (forced-colors: active) {
109
+ .item-ZpP2D[aria-selected="true"] > .row-Idt69, .item-ZpP2D[aria-selected="true"] > .row-Idt69:hover {
110
+ forced-color-adjust: none;
111
+ color: highlighttext;
112
+ background: highlight;
113
+ outline-color: canvastext;
114
+ }
115
+
116
+ .item-ZpP2D[aria-disabled="true"] > .row-Idt69 > * {
117
+ opacity: 1;
118
+ }
119
+
120
+ .item-ZpP2D[aria-disabled="true"]:not([aria-selected="true"]) > .row-Idt69 {
121
+ color: graytext;
122
+ }
123
+ }
124
+
@@ -0,0 +1,23 @@
1
+ import type { TreeItem } from './Tree.js';
2
+ /** One item in its place. Internal, as `TreeSelect` and `Tree` share it. */
3
+ export interface TreeNode {
4
+ id: string;
5
+ item: TreeItem;
6
+ /** Nearest first. */
7
+ ancestorIds: string[];
8
+ children: TreeNode[];
9
+ /** Its place in the whole tree, which an element id can hold where any `id` string could not. */
10
+ ordinal: number;
11
+ }
12
+ export interface TreeIndex {
13
+ roots: TreeNode[];
14
+ nodes: Map<string, TreeNode>;
15
+ }
16
+ /**
17
+ * The tree with each id in one place. An id seen before is left out with everything it holds:
18
+ * selection, expansion and focus all speak in ids, so two items sharing one could not be told apart.
19
+ * That also stops an item that holds itself from going round for ever.
20
+ */
21
+ export declare function indexItems(items: TreeItem[]): TreeIndex;
22
+ /** What is shown, top to bottom: every root, and what each open parent holds. */
23
+ export declare function visibleNodesOf(roots: TreeNode[], expanded: ReadonlySet<string>): TreeNode[];
@@ -0,0 +1,33 @@
1
+ function indexItems(items) {
2
+ const nodes = new Map();
3
+ const collect = (level, ancestorIds)=>{
4
+ const collected = [];
5
+ for (const item of level)if (!nodes.has(item.id)) {
6
+ const node = {
7
+ id: item.id,
8
+ item,
9
+ ancestorIds,
10
+ children: [],
11
+ ordinal: nodes.size
12
+ };
13
+ nodes.set(item.id, node);
14
+ node.children = collect(item.children ?? [], [
15
+ item.id,
16
+ ...ancestorIds
17
+ ]);
18
+ collected.push(node);
19
+ }
20
+ return collected;
21
+ };
22
+ return {
23
+ roots: collect(items, []),
24
+ nodes
25
+ };
26
+ }
27
+ function visibleNodesOf(roots, expanded) {
28
+ return roots.flatMap((node)=>[
29
+ node,
30
+ ...expanded.has(node.id) ? visibleNodesOf(node.children, expanded) : []
31
+ ]);
32
+ }
33
+ export { indexItems, visibleNodesOf };