@proyecto-viviana/solid-stately 0.3.0 → 0.4.1

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 (77) hide show
  1. package/dist/calendar/IncompleteDate.d.ts +61 -0
  2. package/dist/calendar/createCalendarState.d.ts +20 -10
  3. package/dist/calendar/createDateFieldState.d.ts +65 -20
  4. package/dist/calendar/createRangeCalendarState.d.ts +20 -2
  5. package/dist/calendar/createTimeFieldState.d.ts +38 -67
  6. package/dist/calendar/index.d.ts +1 -1
  7. package/dist/calendar/intl/index.d.ts +10 -0
  8. package/dist/collections/ListCollection.d.ts +8 -0
  9. package/dist/collections/createListState.d.ts +16 -1
  10. package/dist/collections/createSelectionState.d.ts +17 -5
  11. package/dist/collections/getChildNodes.d.ts +19 -0
  12. package/dist/collections/index.d.ts +3 -2
  13. package/dist/collections/types.d.ts +9 -0
  14. package/dist/color/intl/index.d.ts +14 -0
  15. package/dist/combobox/createComboBoxState.d.ts +7 -0
  16. package/dist/dnd/createDroppableCollectionState.d.ts +17 -2
  17. package/dist/dnd/index.d.ts +1 -1
  18. package/dist/dnd/types.d.ts +3 -1
  19. package/dist/grid/types.d.ts +17 -3
  20. package/dist/index.d.ts +6 -6
  21. package/dist/index.js +4372 -1087
  22. package/dist/index.js.map +1 -1
  23. package/dist/select/createSelectState.d.ts +6 -0
  24. package/dist/selection/Selection.d.ts +16 -0
  25. package/dist/selection/SelectionManager.d.ts +119 -0
  26. package/dist/selection/createMultipleSelectionState.d.ts +59 -0
  27. package/dist/selection/index.d.ts +1 -0
  28. package/dist/table/TableCollection.d.ts +30 -0
  29. package/dist/table/createTreeGridState.d.ts +15 -0
  30. package/dist/table/index.d.ts +2 -1
  31. package/dist/table/types.d.ts +58 -0
  32. package/dist/toast/createToastState.d.ts +16 -0
  33. package/dist/toast/index.d.ts +1 -1
  34. package/dist/tree/types.d.ts +14 -6
  35. package/package.json +1 -1
  36. package/src/calendar/IncompleteDate.ts +430 -0
  37. package/src/calendar/createCalendarState.ts +129 -40
  38. package/src/calendar/createDateFieldState.ts +633 -477
  39. package/src/calendar/createRangeCalendarState.ts +343 -30
  40. package/src/calendar/createTimeFieldState.ts +179 -467
  41. package/src/calendar/index.ts +2 -0
  42. package/src/calendar/intl/index.ts +364 -0
  43. package/src/collections/ListCollection.ts +31 -0
  44. package/src/collections/createListState.ts +139 -17
  45. package/src/collections/createMenuState.ts +3 -0
  46. package/src/collections/createSelectionState.ts +38 -28
  47. package/src/collections/getChildNodes.ts +129 -0
  48. package/src/collections/index.ts +12 -0
  49. package/src/collections/types.ts +10 -0
  50. package/src/color/Color.ts +104 -133
  51. package/src/color/intl/index.ts +1409 -0
  52. package/src/combobox/createComboBoxState.ts +38 -13
  53. package/src/dnd/createDroppableCollectionState.ts +125 -6
  54. package/src/dnd/index.d.ts +1 -0
  55. package/src/dnd/index.ts +1 -0
  56. package/src/dnd/types.d.ts +3 -1
  57. package/src/dnd/types.ts +4 -1
  58. package/src/grid/createGridState.ts +36 -2
  59. package/src/grid/types.ts +17 -3
  60. package/src/index.d.ts +1 -0
  61. package/src/index.ts +14 -0
  62. package/src/select/createSelectState.ts +15 -2
  63. package/src/selection/Selection.ts +28 -0
  64. package/src/selection/SelectionManager.ts +541 -0
  65. package/src/selection/createMultipleSelectionState.ts +247 -0
  66. package/src/selection/index.ts +6 -0
  67. package/src/steplist/createStepListState.ts +27 -4
  68. package/src/table/TableCollection.ts +213 -43
  69. package/src/table/createTableState.ts +20 -0
  70. package/src/table/createTreeGridState.ts +146 -0
  71. package/src/table/index.ts +3 -0
  72. package/src/table/types.ts +66 -0
  73. package/src/tabs/createTabListState.ts +11 -9
  74. package/src/toast/createToastState.ts +43 -10
  75. package/src/toast/index.ts +1 -0
  76. package/src/tree/createTreeState.ts +37 -6
  77. package/src/tree/types.ts +14 -6
@@ -6,6 +6,7 @@ import { type Accessor } from "solid-js";
6
6
  import { type MaybeAccessor } from "../utils";
7
7
  import type { Key, CollectionNode, Collection } from "../collections/types";
8
8
  import type { SelectionMode, Selection } from "../collections/types";
9
+ import type { SelectionManager } from "../selection/SelectionManager";
9
10
  export interface SelectStateProps<T = unknown> {
10
11
  /** The items to display in the select. */
11
12
  items: T[];
@@ -45,6 +46,11 @@ export interface SelectStateProps<T = unknown> {
45
46
  export interface SelectState<T = unknown> {
46
47
  /** The collection of items. */
47
48
  readonly collection: Accessor<Collection<T>>;
49
+ /**
50
+ * The collection-aware selection manager. Mirrors upstream `useSelectState`,
51
+ * which spreads the underlying `useListState` (including its selection manager).
52
+ */
53
+ readonly selectionManager: SelectionManager<T>;
48
54
  /** Whether the select dropdown is open. */
49
55
  readonly isOpen: Accessor<boolean>;
50
56
  /** Open the select dropdown. */
@@ -0,0 +1,16 @@
1
+ /**
2
+ * A Selection is a special Set containing Keys, which also has an anchor
3
+ * and current selected key for use when range selecting.
4
+ *
5
+ * Based on @react-stately/selection.
6
+ */
7
+ import type { Key } from "../collections/types";
8
+ /**
9
+ * A Selection is a special Set containing Keys, which also has an anchor
10
+ * and current selected key for use when range selecting.
11
+ */
12
+ export declare class Selection extends Set<Key> {
13
+ anchorKey: Key | null;
14
+ currentKey: Key | null;
15
+ constructor(keys?: Iterable<Key> | Selection, anchorKey?: Key | null, currentKey?: Key | null);
16
+ }
@@ -0,0 +1,119 @@
1
+ /**
2
+ * An interface for reading and updating multiple selection state.
3
+ *
4
+ * The upper of the two selection layers ported from upstream
5
+ * (`@react-stately/selection`'s `SelectionManager`): the collection-aware
6
+ * operations built on top of the raw {@link MultipleSelectionState}.
7
+ *
8
+ * React → Solid adaptations, all faithful to upstream's observable contract:
9
+ * - Upstream re-instantiates `SelectionManager` every render to capture a
10
+ * fresh `collection`. Here the manager is long-lived, so it captures a
11
+ * reactive `collection` accessor and reads it live via `get collection()`.
12
+ * - Upstream caches `_isSelectAll` for the lifetime of one render. A
13
+ * long-lived manager would let that cache go stale, so it is dropped and
14
+ * `isSelectAll` recomputes (it is consulted rarely — only by select-all UI).
15
+ * - Our `CollectionNode` has no `'cell'` type (grids/trees use a separate
16
+ * state engine), so the cell-selection branches are omitted.
17
+ *
18
+ * Based on @react-stately/selection.
19
+ */
20
+ import type { SelectionPressEvent } from "../collections/createSelectionState";
21
+ import type { Collection, DisabledBehavior, FocusStrategy, Key, Selection as SelectionValue, SelectionBehavior, SelectionMode } from "../collections/types";
22
+ import type { MultipleSelectionState } from "./createMultipleSelectionState";
23
+ /** A delegate that can resolve a key range without walking the collection (e.g. a virtualized layout). */
24
+ export interface LayoutDelegate {
25
+ getKeyRange?(from: Key, to: Key): Key[];
26
+ }
27
+ export interface SelectionManagerOptions<T = unknown> {
28
+ layoutDelegate?: LayoutDelegate;
29
+ /**
30
+ * The full (unfiltered) collection, used when materializing the 'all'
31
+ * selection so that filtered-out items (e.g. by Autocomplete) are still
32
+ * included.
33
+ */
34
+ fullCollection?: Collection<T>;
35
+ }
36
+ /**
37
+ * An interface for reading and updating multiple selection state.
38
+ */
39
+ export declare class SelectionManager<T = unknown> {
40
+ private collectionAccessor;
41
+ private state;
42
+ private layoutDelegate;
43
+ private fullCollection;
44
+ constructor(collection: () => Collection<T>, state: MultipleSelectionState, options?: SelectionManagerOptions<T>);
45
+ /** The collection the manager operates over (read live so it stays reactive). */
46
+ get collection(): Collection<T>;
47
+ /** The type of selection that is allowed in the collection. */
48
+ get selectionMode(): SelectionMode;
49
+ /** Whether the collection allows empty selection. */
50
+ get disallowEmptySelection(): boolean;
51
+ /** The selection behavior for the collection. */
52
+ get selectionBehavior(): SelectionBehavior;
53
+ /** Sets the selection behavior for the collection. */
54
+ setSelectionBehavior(selectionBehavior: SelectionBehavior): void;
55
+ /** Whether the collection is currently focused. */
56
+ get isFocused(): boolean;
57
+ /** Sets whether the collection is focused. */
58
+ setFocused(isFocused: boolean): void;
59
+ /** The current focused key in the collection. */
60
+ get focusedKey(): Key | null;
61
+ /** Whether the first or last child of the focused key should receive focus. */
62
+ get childFocusStrategy(): FocusStrategy | null;
63
+ /** Sets the focused key. */
64
+ setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy): void;
65
+ /** The currently selected keys in the collection (materialized — 'all' is expanded). */
66
+ get selectedKeys(): Set<Key>;
67
+ /** The raw selection value for the collection. Either 'all' for select all, or a set of keys. */
68
+ get rawSelection(): SelectionValue;
69
+ /** Last selection payload emitted through onSelectionChange. @internal */
70
+ get lastSelectionEvent(): SelectionValue | null;
71
+ /** Re-emits a selection payload without recomputing selection. @internal */
72
+ emitDuplicateSelectionEvent(keys?: SelectionValue | null): void;
73
+ /** Returns whether a key is selected. */
74
+ isSelected(key: Key): boolean;
75
+ /** Whether the selection is empty. */
76
+ get isEmpty(): boolean;
77
+ /** Whether all items in the collection are selected. */
78
+ get isSelectAll(): boolean;
79
+ get firstSelectedKey(): Key | null;
80
+ get lastSelectedKey(): Key | null;
81
+ get disabledKeys(): Set<Key>;
82
+ get disabledBehavior(): DisabledBehavior;
83
+ /** Extends the selection to the given key. */
84
+ extendSelection(toKey: Key): void;
85
+ private getKeyRange;
86
+ private getKeyRangeInternal;
87
+ private getKey;
88
+ /** Toggles whether the given key is selected. */
89
+ toggleSelection(key: Key): void;
90
+ /** Replaces the selection with only the given key. */
91
+ replaceSelection(key: Key): void;
92
+ /** Replaces the selection with the given keys. */
93
+ setSelectedKeys(keys: Iterable<Key>): void;
94
+ private getSelectAllKeys;
95
+ /** Selects all items in the collection. */
96
+ selectAll(): void;
97
+ /** Removes all keys from the selection. */
98
+ clearSelection(): void;
99
+ /** Toggles between select all and an empty selection. */
100
+ toggleSelectAll(): void;
101
+ select(key: Key, e?: SelectionPressEvent): void;
102
+ /** Returns whether the current selection is equal to the given selection. */
103
+ isSelectionEqual(selection: Set<Key>): boolean;
104
+ canSelectItem(key: Key): boolean;
105
+ private canSelectItemIn;
106
+ isDisabled(key: Key): boolean;
107
+ isLink(key: Key): boolean;
108
+ getItemProps(key: Key): Record<string, unknown> | undefined;
109
+ withCollection(collection: Collection<T>): SelectionManager<T>;
110
+ /**
111
+ * Like {@link withCollection}, but the collection is supplied as a live
112
+ * accessor so the returned manager stays reactive as the collection recomputes
113
+ * (e.g. an Autocomplete filter narrowing the list as the user types). The
114
+ * shared underlying selection/focus state is preserved, and the original
115
+ * (unfiltered) collection is retained as `fullCollection` so a select-all
116
+ * still materializes the filtered-out keys.
117
+ */
118
+ withCollectionAccessor(collection: () => Collection<T>): SelectionManager<T>;
119
+ }
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Raw multiple-selection + focus state for a collection.
3
+ *
4
+ * The lower of the two selection layers ported from upstream
5
+ * (`@react-stately/selection`'s `useMultipleSelectionState`): it owns the
6
+ * selected keys, focus, selection behavior, and disabled keys, but is NOT
7
+ * collection-aware. The collection-aware operations (toggle, extend, select
8
+ * all, range, etc.) live in {@link SelectionManager}, which is built on top of
9
+ * this state.
10
+ *
11
+ * Based on @react-stately/selection.
12
+ */
13
+ import { type Accessor } from "solid-js";
14
+ import { type MaybeAccessor } from "../utils";
15
+ import type { SelectionStateProps } from "../collections/createSelectionState";
16
+ import type { DisabledBehavior, FocusStrategy, Key, Selection, SelectionBehavior, SelectionMode } from "../collections/types";
17
+ /**
18
+ * The raw state consumed by {@link SelectionManager}. Mirrors upstream's
19
+ * `MultipleSelectionState`: property reads (not Solid accessors) so the manager
20
+ * can read `state.selectionMode` etc. exactly as upstream does — the getters
21
+ * read the underlying signals, so reads inside reactive scopes still track.
22
+ */
23
+ export interface MultipleSelectionState {
24
+ /** The type of selection that is allowed in the collection. */
25
+ readonly selectionMode: SelectionMode;
26
+ /** The selection behavior for the collection. */
27
+ readonly selectionBehavior: SelectionBehavior;
28
+ /** Sets the selection behavior for the collection. */
29
+ setSelectionBehavior(selectionBehavior: SelectionBehavior): void;
30
+ /** Whether the collection allows empty selection. */
31
+ readonly disallowEmptySelection: boolean;
32
+ /** Whether the collection is currently focused. */
33
+ readonly isFocused: boolean;
34
+ /** Sets whether the collection is focused. */
35
+ setFocused(isFocused: boolean): void;
36
+ /** The current focused key in the collection. */
37
+ readonly focusedKey: Key | null;
38
+ /** Whether the first or last child of the focused key should receive focus. */
39
+ readonly childFocusStrategy: FocusStrategy | null;
40
+ /** Sets the focused key, and optionally, whether the first or last child of that key should receive focus. */
41
+ setFocusedKey(key: Key | null, childFocusStrategy?: FocusStrategy): void;
42
+ /** The currently selected keys in the collection. */
43
+ readonly selectedKeys: Selection;
44
+ /** The last selection payload emitted through onSelectionChange. @internal */
45
+ readonly lastSelectionEvent: Selection | null;
46
+ /** Sets the selected keys in the collection. */
47
+ setSelectedKeys(keys: Selection): void;
48
+ /** Re-emits a selection payload without recomputing or mutating selection. @internal */
49
+ emitDuplicateSelectionEvent(keys?: Selection): void;
50
+ /** The currently disabled keys in the collection. */
51
+ readonly disabledKeys: Set<Key>;
52
+ /** Whether `disabledKeys` applies to all interactions, or only selection. */
53
+ readonly disabledBehavior: DisabledBehavior;
54
+ }
55
+ /**
56
+ * Manages raw state for multiple selection and focus in a collection.
57
+ */
58
+ export declare function createMultipleSelectionState(props?: MaybeAccessor<SelectionStateProps>): MultipleSelectionState;
59
+ export type { Accessor };
@@ -5,6 +5,7 @@
5
5
  * delegating to the existing Solid collection selection primitives.
6
6
  */
7
7
  export { createSelectionState, type SelectionStateProps, type SelectionState, } from "../collections/createSelectionState";
8
+ export { SelectionManager, type SelectionManagerOptions, type LayoutDelegate, } from "./SelectionManager";
8
9
  export type { Key, Selection, SelectionMode, SelectionBehavior, DisabledBehavior, FocusStrategy, } from "../collections/types";
9
10
  export type MultipleSelectionStateProps = import("../collections/createSelectionState").SelectionStateProps;
10
11
  export type MultipleSelectionState = import("../collections/createSelectionState").SelectionState;
@@ -1,6 +1,12 @@
1
1
  /**
2
2
  * TableCollection - A collection class for table data.
3
3
  * Based on @react-stately/table/TableCollection.
4
+ *
5
+ * Supports a plain (flat) table and, when an `expandedKeys` option is supplied, a
6
+ * tree grid: `childRows` are walked recursively, each parent row keeps its full
7
+ * structure (cells followed by every child row), and only rows whose ancestors are
8
+ * all expanded are flattened into the navigable body. Mirrors the structure produced
9
+ * by `@react-stately/table`'s `generateTreeGridCollection`.
4
10
  */
5
11
  import type { Key } from "../collections/types";
6
12
  import type { GridNode } from "../grid/types";
@@ -17,12 +23,30 @@ export declare class TableCollection<T = unknown> implements ITableCollection<T>
17
23
  private _keyMap;
18
24
  private _rowHeaderColumnKeys;
19
25
  private _size;
26
+ /** Visible rows in DFS order. Drives size, navigation, iteration and the `rows` list. */
27
+ private _flattenedRows;
28
+ private _treeColumn;
29
+ private _userColumnCount;
20
30
  constructor(options: TableCollectionOptions<T>);
21
31
  private buildColumns;
22
32
  private buildColumnNode;
23
33
  private getDefaultRowHeaderColumnKeys;
34
+ /** Counts the leaf columns supplied by the user (excludes the selection column). */
35
+ private countLeafColumns;
24
36
  private buildHeaderRows;
37
+ /**
38
+ * Builds the cell nodes for one row. Does not register the cells in the key map;
39
+ * the caller registers cells once the owning row is known to be present.
40
+ */
41
+ private buildCells;
25
42
  private buildRows;
43
+ /**
44
+ * Builds the tree-grid rows: every row keeps its full structure (cells then all child
45
+ * rows, expanded or not) while only the rows whose ancestors are all expanded are
46
+ * registered in the key map and pushed into the flattened body. Mirrors
47
+ * `generateTreeGridCollection` upstream.
48
+ */
49
+ private buildTreeRows;
26
50
  private isRowDefinition;
27
51
  get size(): number;
28
52
  get rows(): GridNode<T>[];
@@ -33,6 +57,12 @@ export declare class TableCollection<T = unknown> implements ITableCollection<T>
33
57
  get rowCount(): number;
34
58
  get columnCount(): number;
35
59
  get rowHeaderColumnKeys(): Set<Key>;
60
+ /** The key of the column that renders the tree-grid affordance, or `null` for a flat table. */
61
+ get treeColumn(): Key | null;
62
+ /** The number of leaf columns provided by the user (excludes the selection column). */
63
+ get userColumnCount(): number;
64
+ /** The key map of all present nodes (visible rows, their cells, columns and the body). */
65
+ get keyMap(): Map<Key, GridNode<T>>;
36
66
  getKeys(): Iterable<Key>;
37
67
  getItem(key: Key): GridNode<T> | null;
38
68
  at(index: number): GridNode<T> | null;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Tree grid state management for expandable Table rows.
3
+ * Based on @react-stately/table/useTreeGridState (the `UNSTABLE_` tree-grid feature).
4
+ *
5
+ * Owns the expanded-keys signal (controlled or uncontrolled), rebuilds the table
6
+ * collection from it, and layers the expansion API on top of {@link createTableState}.
7
+ */
8
+ import { type Accessor } from "solid-js";
9
+ import { TableCollection } from "./TableCollection";
10
+ import type { TreeGridState, TreeGridStateOptions } from "./types";
11
+ /**
12
+ * Creates state management for a tree grid (a table with expandable rows). Handles the
13
+ * expanded rows in addition to the selection, sort and focus handled by the table state.
14
+ */
15
+ export declare function createTreeGridState<T extends object, C extends TableCollection<T> = TableCollection<T>>(options: Accessor<TreeGridStateOptions<T, C>>): TreeGridState<T, C>;
@@ -3,7 +3,8 @@
3
3
  * Provides state hooks for Table components.
4
4
  */
5
5
  export { createTableState } from "./createTableState";
6
+ export { createTreeGridState } from "./createTreeGridState";
6
7
  export { createTableColumnResizeState } from "./createTableColumnResizeState";
7
8
  export { TableCollection, createTableCollection } from "./TableCollection";
8
- export type { TableState, TableStateOptions, TableCollection as ITableCollection, SortDescriptor, SortDirection, Sortable, ColumnDefinition, RowDefinition, TableCollectionOptions, } from "./types";
9
+ export type { TableState, TableStateOptions, TableCollection as ITableCollection, TreeGridState, TreeGridStateOptions, SortDescriptor, SortDirection, Sortable, ColumnDefinition, RowDefinition, TableCollectionOptions, } from "./types";
9
10
  export type { ColumnSize, ColumnResizeDefinition, TableColumnResizeStateProps, TableColumnResizeState, } from "./createTableColumnResizeState";
@@ -41,6 +41,8 @@ export interface TableCollection<T = unknown> extends GridCollection<T> {
41
41
  readonly head?: GridNode<T>;
42
42
  /** The node that makes up the body of the table. */
43
43
  readonly body: GridNode<T>;
44
+ /** The key of the column that renders the tree-grid expand/collapse affordance, if any. */
45
+ readonly treeColumn?: Key | null;
44
46
  }
45
47
  /**
46
48
  * State for a table component.
@@ -55,6 +57,51 @@ export interface TableState<T, C extends TableCollection<T> = TableCollection<T>
55
57
  readonly sortDescriptor: SortDescriptor | null;
56
58
  /** Sort by the given column and direction. */
57
59
  sort(columnKey: Key, direction?: SortDirection): void;
60
+ /**
61
+ * The set of expanded row keys for tree grids. A plain table reports an empty set.
62
+ */
63
+ readonly expandedKeys: "all" | Set<Key>;
64
+ /**
65
+ * The key of the column that renders the expand/collapse affordance, or `null` for a
66
+ * plain (non-tree) table.
67
+ */
68
+ readonly treeColumn: Key | null;
69
+ /** Toggles the expanded state of a row by its key (no-op for a plain table). */
70
+ toggleKey(key: Key): void;
71
+ }
72
+ /**
73
+ * State for a tree grid (expandable rows). Mirrors `@react-stately/table`'s
74
+ * `UNSTABLE_useTreeGridState` return value.
75
+ */
76
+ export interface TreeGridState<T, C extends TableCollection<T> = TableCollection<T>> extends TableState<T, C> {
77
+ /** A set of keys for rows that are expanded. */
78
+ readonly expandedKeys: "all" | Set<Key>;
79
+ /** The key map containing nodes representing the collection's tree grid structure. */
80
+ readonly keyMap: Map<Key, GridNode<T>>;
81
+ /** The number of leaf columns provided by the user (excludes selection/drag columns). */
82
+ readonly userColumnCount: number;
83
+ }
84
+ /**
85
+ * Options for creating tree grid state. Mirrors `TreeGridStateProps` upstream; the
86
+ * expansion props keep the `UNSTABLE_` prefix while the feature is unstable.
87
+ */
88
+ export interface TreeGridStateOptions<T, C extends TableCollection<T> = TableCollection<T>> extends Omit<TableStateOptions<T, C>, "collection"> {
89
+ /** Column definitions. */
90
+ columns: ColumnDefinition<T>[];
91
+ /** Row definitions (may contain `childRows` for nested rows). */
92
+ rows: RowDefinition<T>[];
93
+ /** Function to get the key from a data item. */
94
+ getKey?: (item: T) => Key;
95
+ /** Function to get the text value from a data item. */
96
+ getTextValue?: (item: T, column: ColumnDefinition<T>) => string;
97
+ /** Set of column keys that serve as row headers. */
98
+ rowHeaderColumnKeys?: Set<Key>;
99
+ /** The currently expanded keys in the collection (controlled). */
100
+ UNSTABLE_expandedKeys?: "all" | Iterable<Key>;
101
+ /** The initial expanded keys in the collection (uncontrolled). */
102
+ UNSTABLE_defaultExpandedKeys?: "all" | Iterable<Key>;
103
+ /** Handler that is called when rows are expanded or collapsed. */
104
+ UNSTABLE_onExpandedChange?: (keys: Set<Key>) => void;
58
105
  }
59
106
  /**
60
107
  * Options for creating table state.
@@ -64,6 +111,8 @@ export interface TableStateOptions<T, C extends TableCollection<T> = TableCollec
64
111
  collection: C;
65
112
  /** Keys of disabled rows. */
66
113
  disabledKeys?: Iterable<Key>;
114
+ /** Whether `disabledKeys` applies to all interactions, or only selection. @default "all" */
115
+ disabledBehavior?: "selection" | "all";
67
116
  /** Focus mode: 'row' or 'cell'. */
68
117
  focusMode?: "row" | "cell";
69
118
  /** Selection mode. */
@@ -135,4 +184,13 @@ export interface TableCollectionOptions<T = unknown> {
135
184
  showSelectionCheckboxes?: boolean;
136
185
  /** Set of column keys that serve as row headers. */
137
186
  rowHeaderColumnKeys?: Set<Key>;
187
+ /**
188
+ * The set of expanded row keys. Passing this (even an empty set) builds the collection
189
+ * in tree-grid mode: `childRows` are walked recursively, only rows whose ancestors are
190
+ * all expanded are flattened into the navigable body, and {@link TableCollection.treeColumn}
191
+ * resolves to a real column. Omit it for a plain (non-tree) table.
192
+ */
193
+ expandedKeys?: "all" | Set<Key>;
194
+ /** Explicit tree column key. Defaults to the first row-header column in tree-grid mode. */
195
+ treeColumn?: Key | null;
138
196
  }
@@ -27,11 +27,19 @@ export interface QueuedToast<T> {
27
27
  /** The timeout for the toast. */
28
28
  timeout?: number;
29
29
  }
30
+ /** The kind of queue mutation that triggered a notification, passed to `wrapUpdate`. */
31
+ export type ToastAction = "add" | "remove" | "clear";
30
32
  export interface ToastQueueOptions {
31
33
  /** The maximum number of toasts to display at once. */
32
34
  maxVisibleToasts?: number;
33
35
  /** Whether toasts should stack (true) or queue (false). */
34
36
  hasExitAnimation?: boolean;
37
+ /**
38
+ * Wraps each update to the visible toasts (e.g. in `document.startViewTransition()`),
39
+ * so the resulting re-render can be animated. Receives the action that triggered the
40
+ * update. Mirrors `@react-stately/toast`'s `wrapUpdate`.
41
+ */
42
+ wrapUpdate?: (fn: () => void, action: ToastAction) => void;
35
43
  }
36
44
  export interface ToastStateProps<T> {
37
45
  /** The toast queue to use. */
@@ -82,7 +90,15 @@ export declare class ToastQueue<T> {
82
90
  private maxVisibleToasts;
83
91
  private hasExitAnimation;
84
92
  private keyCounter;
93
+ private wrapUpdate?;
85
94
  constructor(options?: ToastQueueOptions);
95
+ /**
96
+ * Installs (or clears) the function that wraps visible-toast updates, so the
97
+ * resulting re-render can be animated. Used to attach `document.startViewTransition`
98
+ * to a shared queue (e.g. the global queue) after construction.
99
+ */
100
+ setWrapUpdate(wrapUpdate?: (fn: () => void, action: ToastAction) => void): void;
101
+ private runWithWrapUpdate;
86
102
  /**
87
103
  * Subscribe to queue changes.
88
104
  */
@@ -1 +1 @@
1
- export { createToastState, createToastQueue, ToastQueue, Timer, type ToastOptions, type QueuedToast, type ToastQueueOptions, type ToastStateProps, type ToastState, } from "./createToastState";
1
+ export { createToastState, createToastQueue, ToastQueue, Timer, type ToastOptions, type QueuedToast, type ToastQueueOptions, type ToastAction, type ToastStateProps, type ToastState, } from "./createToastState";
@@ -2,7 +2,7 @@
2
2
  * Tree collection types for Tree components.
3
3
  * Based on @react-stately/tree.
4
4
  */
5
- import type { Key, FocusStrategy } from "../collections/types";
5
+ import type { Key, FocusStrategy, Selection, SelectionBehavior } from "../collections/types";
6
6
  import type { GridNode, GridCollection } from "../grid/types";
7
7
  /**
8
8
  * Represents a node in a tree collection.
@@ -63,6 +63,8 @@ export interface TreeState<T, C extends TreeCollection<T> = TreeCollection<T>> {
63
63
  readonly collection: C;
64
64
  /** Keys of disabled items. */
65
65
  readonly disabledKeys: Set<Key>;
66
+ /** Whether `disabledKeys` applies to all interactions, or only selection. */
67
+ readonly disabledBehavior: "selection" | "all";
66
68
  /** Keys of expanded items. */
67
69
  readonly expandedKeys: Set<Key>;
68
70
  /** Whether keyboard navigation is disabled. */
@@ -76,9 +78,11 @@ export interface TreeState<T, C extends TreeCollection<T> = TreeCollection<T>> {
76
78
  /** The selection mode. */
77
79
  readonly selectionMode: "none" | "single" | "multiple";
78
80
  /** How selection behaves when pressing an item. */
79
- readonly selectionBehavior: "toggle" | "replace";
81
+ readonly selectionBehavior: SelectionBehavior;
82
+ /** Whether empty selection is disallowed. */
83
+ readonly disallowEmptySelection: boolean;
80
84
  /** The currently selected keys. */
81
- readonly selectedKeys: "all" | Set<Key>;
85
+ readonly selectedKeys: Selection;
82
86
  /** Check if a key is selected. */
83
87
  isSelected(key: Key): boolean;
84
88
  /** Check if a key is disabled. */
@@ -93,6 +97,10 @@ export interface TreeState<T, C extends TreeCollection<T> = TreeCollection<T>> {
93
97
  toggleSelection(key: Key): void;
94
98
  /** Replace selection with a key. */
95
99
  replaceSelection(key: Key): void;
100
+ /** Set the selected keys directly. */
101
+ setSelectedKeys(keys: Selection | Iterable<Key>): void;
102
+ /** Set how selection behaves when pressing an item. */
103
+ setSelectionBehavior(behavior: SelectionBehavior): void;
96
104
  /** Extend selection to a key (shift-click). */
97
105
  extendSelection(toKey: Key): void;
98
106
  /** Select all visible items. */
@@ -125,13 +133,13 @@ export interface TreeStateOptions<T, C extends TreeCollection<T> = TreeCollectio
125
133
  /** Selection mode. */
126
134
  selectionMode?: "none" | "single" | "multiple";
127
135
  /** Selection behavior. */
128
- selectionBehavior?: "toggle" | "replace";
136
+ selectionBehavior?: SelectionBehavior;
129
137
  /** Whether empty selection is disallowed. */
130
138
  disallowEmptySelection?: boolean;
131
139
  /** Currently selected keys (controlled). */
132
- selectedKeys?: "all" | Iterable<Key>;
140
+ selectedKeys?: Selection | Iterable<Key>;
133
141
  /** Default selected keys (uncontrolled). */
134
- defaultSelectedKeys?: "all" | Iterable<Key>;
142
+ defaultSelectedKeys?: Selection | Iterable<Key>;
135
143
  /** Handler for selection changes. */
136
144
  onSelectionChange?: (keys: "all" | Set<Key>) => void;
137
145
  /** Currently expanded keys (controlled). */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proyecto-viviana/solid-stately",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "A 1-1 SolidJS port of React Stately - headless state management for UI components",
5
5
  "keywords": [
6
6
  "headless",