@rokkit/ui 1.4.2 → 1.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 (53) hide show
  1. package/dist/components/CodeGroup.svelte +0 -1
  2. package/dist/components/CommandPalette.svelte +2 -1
  3. package/dist/components/CommandPalette.svelte.d.ts +2 -5
  4. package/dist/components/Dropdown.svelte +3 -22
  5. package/dist/components/Dropdown.svelte.d.ts +2 -20
  6. package/dist/components/FloatingAction.svelte +2 -2
  7. package/dist/components/FloatingAction.svelte.d.ts +2 -5
  8. package/dist/components/Grid.svelte +11 -15
  9. package/dist/components/Grid.svelte.d.ts +2 -43
  10. package/dist/components/LazyTree.svelte +11 -17
  11. package/dist/components/LazyTree.svelte.d.ts +2 -28
  12. package/dist/components/List.svelte +12 -21
  13. package/dist/components/List.svelte.d.ts +2 -47
  14. package/dist/components/Menu.svelte +12 -26
  15. package/dist/components/Menu.svelte.d.ts +2 -66
  16. package/dist/components/MultiSelect.svelte +12 -26
  17. package/dist/components/MultiSelect.svelte.d.ts +2 -23
  18. package/dist/components/Select.svelte +12 -27
  19. package/dist/components/Select.svelte.d.ts +2 -24
  20. package/dist/components/Swatch.svelte +1 -27
  21. package/dist/components/Swatch.svelte.d.ts +1 -27
  22. package/dist/components/Table.svelte +10 -3
  23. package/dist/components/Tabs.svelte +25 -7
  24. package/dist/components/Tabs.svelte.d.ts +9 -1
  25. package/dist/components/Toggle.svelte +14 -4
  26. package/dist/components/Toggle.svelte.d.ts +4 -1
  27. package/dist/components/Toolbar.svelte +2 -2
  28. package/dist/components/Toolbar.svelte.d.ts +1 -2
  29. package/dist/components/Tree.svelte +11 -14
  30. package/dist/components/Tree.svelte.d.ts +2 -29
  31. package/dist/components/UploadProgress.svelte +3 -4
  32. package/dist/components/UploadProgress.svelte.d.ts +1 -4
  33. package/dist/components/UploadTarget.svelte +2 -4
  34. package/dist/components/UploadTarget.svelte.d.ts +14 -4
  35. package/dist/types/chat.d.ts +15 -0
  36. package/dist/types/command-palette.d.ts +18 -0
  37. package/dist/types/command-palette.js +7 -0
  38. package/dist/types/floating-action.d.ts +5 -0
  39. package/dist/types/grid.d.ts +37 -0
  40. package/dist/types/grid.js +8 -0
  41. package/dist/types/index.d.ts +4 -0
  42. package/dist/types/index.js +8 -0
  43. package/dist/types/list.d.ts +22 -55
  44. package/dist/types/menu.d.ts +9 -2
  45. package/dist/types/select.d.ts +52 -62
  46. package/dist/types/snippets.d.ts +64 -0
  47. package/dist/types/snippets.js +16 -0
  48. package/dist/types/swatch.d.ts +39 -0
  49. package/dist/types/swatch.js +8 -0
  50. package/dist/types/table.d.ts +5 -0
  51. package/dist/types/toolbar.d.ts +5 -0
  52. package/dist/types/tree.d.ts +34 -66
  53. package/package.json +5 -5
@@ -91,3 +91,11 @@ export * from './stepper.js';
91
91
  export * from './tilt.js';
92
92
  // Chat Types
93
93
  export * from './chat.js';
94
+ // Shared snippet types for the item-rendering components
95
+ export * from './snippets.js';
96
+ // Grid
97
+ export * from './grid.js';
98
+ // CommandPalette
99
+ export * from './command-palette.js';
100
+ // Swatch
101
+ export * from './swatch.js';
@@ -5,6 +5,8 @@
5
5
  * Supports navigation links, button items, and grouped items with collapsible sections.
6
6
  * Field mapping and data access is handled by ProxyItem from @rokkit/states.
7
7
  */
8
+ import type { ProxyItem } from '@rokkit/states';
9
+ import type { ItemSnippets } from './snippets.js';
8
10
  /**
9
11
  * Field mapping configuration for list data.
10
12
  */
@@ -43,72 +45,37 @@ export declare const defaultListFields: Required<Omit<ListFields, 'fields'>>;
43
45
  */
44
46
  export type ListItem = Record<string, unknown>;
45
47
  /**
46
- * Handlers passed to custom item snippets
47
- */
48
- export interface ListItemHandlers {
49
- /** Call to trigger item selection (for button items) */
50
- onclick: () => void;
51
- /** Forward keyboard events for accessibility */
52
- onkeydown: (event: KeyboardEvent) => void;
53
- }
54
- /**
55
- * Snippet type for rendering list items.
56
- * Parameters: item, fields, handlers, isActive
57
- */
58
- export type ListItemSnippet = import('svelte').Snippet<[
59
- ListItem,
60
- ListFields,
61
- ListItemHandlers,
62
- boolean
63
- ]>;
64
- /**
65
- * Snippet type for rendering group labels
66
- * Parameters: item (group), fields, toggleExpanded, isExpanded
67
- */
68
- export type ListGroupLabelSnippet = import('svelte').Snippet<[
69
- ListItem,
70
- ListFields,
71
- () => void,
72
- boolean
73
- ]>;
74
- /**
75
- * Props for the List component
48
+ * Props for the List component.
49
+ *
50
+ * `List.svelte` annotates its own `$props()` with this interface, so the two
51
+ * cannot drift — which is how the previous version of this type came to
52
+ * describe `item` / `groupLabel` snippets and `multiselect` / `expanded` /
53
+ * `selected` props the component never read.
54
+ *
55
+ * Extends {@link ItemSnippets} for `itemContent` / `groupContent` plus the open
56
+ * index signature that per-item named snippets (`item.snippet = 'name'`) need.
76
57
  */
77
- export interface ListProps {
58
+ export interface ListProps extends ItemSnippets {
78
59
  /** Array of list items or groups */
79
- items?: ListItem[];
60
+ items?: unknown[];
80
61
  /** Field mapping configuration */
81
- fields?: ListFields;
82
- /** Currently selected value (for highlighting button items) */
62
+ fields?: Record<string, string>;
63
+ /** Selected value (bindable) — matched against each item's value field */
83
64
  value?: unknown;
84
65
  /** Size variant */
85
- size?: 'sm' | 'md' | 'lg';
66
+ size?: string;
86
67
  /** Whether the entire list is disabled */
87
68
  disabled?: boolean;
88
69
  /** Whether groups can be collapsed */
89
70
  collapsible?: boolean;
90
- /** Enable multiple item selection (Ctrl+click toggle, Shift+click range) */
91
- multiselect?: boolean;
92
- /** Which groups are expanded (bindable) - keyed by group value/text */
93
- expanded?: Record<string, boolean>;
94
- /** Selected items array (bindable) - populated in multiselect mode */
95
- selected?: unknown[];
96
- /** Active item value - List looks up item by this value to highlight it */
97
- active?: unknown;
98
- /** Called when a button item is selected */
99
- onselect?: (value: unknown, item: ListItem) => void;
100
- /** Called when selected items change in multiselect mode */
101
- onselectedchange?: (selected: unknown[]) => void;
102
- /** Called when expanded state changes (for bindable expanded) */
103
- onexpandedchange?: (expanded: Record<string, boolean>) => void;
104
- /** Additional CSS classes */
105
- class?: string;
71
+ /** Accessible name for the list */
72
+ label?: string;
106
73
  /** Icons for list group states (expand/collapse arrow) */
107
74
  icons?: ListStateIcons;
108
- /** Custom snippet for rendering list items */
109
- item?: ListItemSnippet;
110
- /** Custom snippet for rendering group labels/headers */
111
- groupLabel?: ListGroupLabelSnippet;
75
+ /** Called when an item is selected, with the item's `ProxyItem` */
76
+ onselect?: (value: unknown, proxy: ProxyItem) => void;
77
+ /** Additional CSS classes */
78
+ class?: string;
112
79
  }
113
80
  /**
114
81
  * Icons configuration for list collapsible group states.
@@ -5,12 +5,19 @@
5
5
  * Trigger action manages open/close. Dropdown content is identical to List.
6
6
  */
7
7
  import type { ProxyItem } from '@rokkit/states';
8
+ import type { ItemSnippets } from './snippets.js';
8
9
  /**
9
10
  * Props for the Menu component.
10
11
  * Content props (items, fields, value, size, disabled, collapsible, icons, onselect, class, snippets)
11
12
  * are identical to List. Additional props: label, icon, showArrow, align, direction.
12
13
  */
13
- export interface MenuProps {
14
+ /**
15
+ * Props for the Menu component.
16
+ *
17
+ * `Menu.svelte` annotates its own `$props()` with this interface, so the two
18
+ * cannot drift.
19
+ */
20
+ export interface MenuProps extends ItemSnippets {
14
21
  /** Array of items (same as List: supports groups, separators, nested children) */
15
22
  items?: unknown[];
16
23
  /** Field mapping — overrides BASE_FIELDS defaults (label → 'label', value → 'value', …) */
@@ -18,7 +25,7 @@ export interface MenuProps {
18
25
  /** Current active value (highlights matching item) */
19
26
  value?: unknown;
20
27
  /** Size variant */
21
- size?: 'sm' | 'md' | 'lg';
28
+ size?: string;
22
29
  /** Whether the entire menu is disabled */
23
30
  disabled?: boolean;
24
31
  /** Whether groups are collapsible (same as List) */
@@ -4,94 +4,84 @@
4
4
  * Provides types for the data-driven Select and MultiSelect components.
5
5
  * Field mapping and data access is handled by ProxyItem from @rokkit/states.
6
6
  */
7
- import type { Snippet } from 'svelte';
8
- import type { ProxyItem } from '@rokkit/states';
7
+ import type { ItemSnippets } from './snippets.js';
9
8
  /**
10
9
  * Generic select item - can be any object with mapped fields
11
10
  */
12
11
  export type SelectItem = Record<string, unknown>;
13
- /** @deprecated Legacy handlers — will be removed when PaletteManager migrates to Navigator stack */
14
- export interface SelectItemHandlers {
15
- onclick: () => void;
16
- onkeydown: (event: KeyboardEvent) => void;
17
- }
18
- /**
19
- * Snippet type for rendering a single option in the dropdown.
20
- * The component renders the focusable wrapper; the snippet renders the inner content.
21
- * Navigator handles click selection via data-path — no handlers needed in snippet.
22
- */
23
- export type SelectOptionSnippet = Snippet<[ProxyItem]>;
24
- /**
25
- * Snippet type for rendering a group header label.
26
- */
27
- export type SelectGroupLabelSnippet = Snippet<[ProxyItem]>;
28
- /**
29
- * Snippet type for rendering the selected value display in the trigger button.
30
- */
31
- export type SelectValueSnippet = Snippet<[ProxyItem]>;
32
12
  /**
33
- * Snippet type for rendering selected values in MultiSelect trigger.
34
- * Receives the array of selected ProxyItems.
35
- */
36
- export type MultiSelectValueSnippet = Snippet<[ProxyItem[]]>;
37
- /**
38
- * Common props shared between Select and MultiSelect
13
+ * Common props shared between Select, MultiSelect and Dropdown.
14
+ *
15
+ * Each component annotates its own `$props()` with the derived interface, so
16
+ * they cannot drift — which is how the previous version came to name the data
17
+ * prop `options` when every component takes `items`, and to declare
18
+ * `option` / `groupLabel` snippets the components never read.
39
19
  */
40
20
  export interface SelectBaseProps {
41
- /** Array of select options or groups */
42
- options?: SelectItem[];
43
- /** Field mapping — overrides BASE_FIELDS defaults (text → 'label', value → 'value', …) */
21
+ /** Array of options or groups */
22
+ items?: unknown[];
23
+ /** Field mapping — overrides BASE_FIELDS defaults */
44
24
  fields?: Record<string, string>;
45
25
  /** Placeholder text when no selection */
46
26
  placeholder?: string;
47
27
  /** Size variant */
48
- size?: 'sm' | 'md' | 'lg';
28
+ size?: string;
29
+ /** Whether the control is disabled */
30
+ disabled?: boolean;
49
31
  /** Dropdown alignment relative to trigger */
50
- align?: 'left' | 'right' | 'start' | 'end';
32
+ align?: 'start' | 'end';
51
33
  /** Dropdown slide direction */
52
34
  direction?: 'up' | 'down';
53
- /** Maximum visible rows in dropdown (default: 5) */
54
- maxRows?: number;
55
- /** Whether the select is disabled */
56
- disabled?: boolean;
35
+ /** Icons for dropdown arrow, check and remove */
36
+ icons?: SelectStateIcons;
57
37
  /** Additional CSS classes on root element */
58
38
  class?: string;
59
- /** Icons for select states (dropdown arrow, check, remove) */
60
- icons?: SelectStateIcons;
61
- /** Custom snippet for rendering options in dropdown */
62
- option?: SelectOptionSnippet;
63
- /** Custom snippet for rendering group labels */
64
- groupLabel?: SelectGroupLabelSnippet;
65
- /** Enable typeahead filter input in dropdown header */
66
- filterable?: boolean;
67
- /** Placeholder text for the filter input */
68
- filterPlaceholder?: string;
69
39
  }
70
40
  /**
71
- * Props for the Select component (single selection)
41
+ * Props for the Select component (single selection).
72
42
  */
73
- export interface SelectProps extends SelectBaseProps {
74
- /** Currently selected value (bindable) — extracted via item[fields.value] */
43
+ export interface SelectProps extends SelectBaseProps, ItemSnippets {
44
+ /** Selected value (bindable) — extracted via item[fields.value] */
75
45
  value?: unknown;
76
- /** Currently selected raw item (bindable) — full object from options array */
77
- selected?: SelectItem | null;
46
+ /** Selected raw item (bindable) */
47
+ selected?: unknown;
48
+ /** Enable the typeahead filter input in the dropdown header */
49
+ filterable?: boolean;
50
+ /** Placeholder for the filter input */
51
+ filterPlaceholder?: string;
52
+ /** Maximum visible rows in the dropdown */
53
+ maxRows?: number;
78
54
  /** Called when selection changes */
79
- onchange?: (value: unknown, item: SelectItem) => void;
80
- /** Custom snippet for rendering the selected value in the trigger */
81
- selectedValue?: SelectValueSnippet;
55
+ onchange?: (value: unknown, item: unknown) => void;
82
56
  }
83
57
  /**
84
- * Props for the MultiSelect component (multiple selection)
58
+ * Props for the MultiSelect component (multiple selection).
85
59
  */
86
- export interface MultiSelectProps extends SelectBaseProps {
87
- /** Currently selected values (bindable) - extracted primitives */
60
+ export interface MultiSelectProps extends SelectBaseProps, ItemSnippets {
61
+ /** Selected values (bindable) */
88
62
  value?: unknown[];
89
- /** Currently selected items (bindable) - full item objects for convenience */
90
- selected?: SelectItem[];
91
- /** Called when selection changes */
92
- onchange?: (values: unknown[], items: SelectItem[]) => void;
93
- /** Maximum number of tags to show before collapsing to count */
63
+ /** Selected items (bindable) */
64
+ selected?: unknown[];
65
+ /** Maximum tags shown before collapsing to a count */
94
66
  maxDisplay?: number;
67
+ /** Called when selection changes */
68
+ onchange?: (values: unknown[], items: unknown[]) => void;
69
+ }
70
+ /**
71
+ * Props for the Dropdown component.
72
+ *
73
+ * Unlike Select and MultiSelect it does not spread snippets, so it takes the
74
+ * base props only.
75
+ */
76
+ export interface DropdownProps extends SelectBaseProps {
77
+ /** Selected value (bindable) */
78
+ value?: unknown;
79
+ /** Trigger icon class */
80
+ icon?: string;
81
+ /** Whether to show the dropdown arrow indicator on the trigger */
82
+ showArrow?: boolean;
83
+ /** Called when selection changes */
84
+ onchange?: (value: unknown, item: unknown) => void;
95
85
  }
96
86
  /**
97
87
  * Icons configuration for select expand/collapse and selection states.
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Shared snippet types for the item-rendering components.
3
+ *
4
+ * List / Tree / Menu / Select / Grid and friends collect their snippets with a
5
+ * rest element (`...snippets`) behind an index signature, because a data item
6
+ * can name its own snippet (`item.snippet = 'name'`, resolved by
7
+ * `resolveSnippet`) — so arbitrary keys must stay accepted.
8
+ *
9
+ * The index signature alone typed every snippet as `unknown`, which made each
10
+ * consumer's snippet parameter implicitly `any`: a snippet body could read any
11
+ * property off `proxy` or pass it somewhere expecting a different type, and
12
+ * nothing complained until runtime. Declaring the documented snippets
13
+ * explicitly fixes that — TypeScript prefers an explicit member over the index
14
+ * signature, so the common case is checked while named snippets still work.
15
+ */
16
+ import type { Snippet } from 'svelte';
17
+ import type { ProxyItem } from '@rokkit/states';
18
+ /**
19
+ * Renders one item's inner content, given its `ProxyItem`.
20
+ *
21
+ * This is the shape of `itemContent` and `groupContent` — the fallbacks
22
+ * `resolveSnippet` reaches for (`ITEM_SNIPPET` / `GROUP_SNIPPET`), and the
23
+ * shape any per-item named snippet must also have.
24
+ */
25
+ export type ItemSnippet = Snippet<[ProxyItem]>;
26
+ /**
27
+ * Renders one item's inner content plus whether it is currently selected.
28
+ *
29
+ * Used where selection is part of the item's own rendering rather than the
30
+ * wrapper's — Tabs and Toggle both call their content snippet as
31
+ * `content(proxy, selected)`.
32
+ */
33
+ export type SelectableItemSnippet = Snippet<[ProxyItem, boolean]>;
34
+ /**
35
+ * The snippet bag an item-rendering component accepts.
36
+ *
37
+ * Spread into a component's props type so the documented snippets are typed
38
+ * while `item.snippet = 'name'` keeps working:
39
+ *
40
+ * ```ts
41
+ * let { items = [], ...snippets }: { items?: unknown[] } & ItemSnippets = $props()
42
+ * ```
43
+ */
44
+ export interface ItemSnippets<S = ItemSnippet> {
45
+ /** Inner content for a leaf item. */
46
+ itemContent?: S;
47
+ /** Inner content for a group/parent item. Falls back to `itemContent`. */
48
+ groupContent?: S;
49
+ /**
50
+ * Per-item named snippets, selected via the item's `snippet` field:
51
+ *
52
+ * ```svelte
53
+ * {#snippet pinned(proxy)}…{/snippet}
54
+ * <List items={[{ label: 'A', snippet: 'pinned' }]} snippets={{ pinned }} />
55
+ * ```
56
+ *
57
+ * A declared prop rather than an index signature. An index signature would
58
+ * have to admit every other prop too — TypeScript requires each declared
59
+ * member to conform to it — which forced it to `unknown` and silently
60
+ * accepted any misspelled prop name (`itemcontnt`, `onSelect`) on every
61
+ * component that used it.
62
+ */
63
+ snippets?: Record<string, S>;
64
+ }
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Shared snippet types for the item-rendering components.
3
+ *
4
+ * List / Tree / Menu / Select / Grid and friends collect their snippets with a
5
+ * rest element (`...snippets`) behind an index signature, because a data item
6
+ * can name its own snippet (`item.snippet = 'name'`, resolved by
7
+ * `resolveSnippet`) — so arbitrary keys must stay accepted.
8
+ *
9
+ * The index signature alone typed every snippet as `unknown`, which made each
10
+ * consumer's snippet parameter implicitly `any`: a snippet body could read any
11
+ * property off `proxy` or pass it somewhere expecting a different type, and
12
+ * nothing complained until runtime. Declaring the documented snippets
13
+ * explicitly fixes that — TypeScript prefers an explicit member over the index
14
+ * signature, so the common case is checked while named snippets still work.
15
+ */
16
+ export {};
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Swatch Component Types
3
+ *
4
+ * A group of selectable colour swatches. Options may be primitives (hex or
5
+ * colour-name strings) or objects whose fill/stroke/value are read through the
6
+ * usual field mapping.
7
+ */
8
+ import type { Snippet } from 'svelte';
9
+ import type { ProxyItem } from '@rokkit/states';
10
+ /**
11
+ * Props for the Swatch component.
12
+ *
13
+ * `Swatch.svelte` annotates its own `$props()` with this interface, so the two
14
+ * cannot drift.
15
+ */
16
+ export interface SwatchProps {
17
+ /** Color options — primitives (hex/name strings) or objects with mapped fields */
18
+ options?: Array<string | number | Record<string, unknown>>;
19
+ /** Field mapping for object options (value, fill, stroke, …) */
20
+ fields?: Record<string, string>;
21
+ /** Selected value (bindable). Array when `multiple`. */
22
+ value?: unknown;
23
+ /** Allow multiple selection */
24
+ multiple?: boolean;
25
+ /** Swatch shape */
26
+ shape?: 'square' | 'circle';
27
+ /** Size variant */
28
+ size?: 'sm' | 'md' | 'lg';
29
+ /** Disable the whole group */
30
+ disabled?: boolean;
31
+ /** Accessible group label */
32
+ label?: string;
33
+ /** Additional CSS classes */
34
+ class?: string;
35
+ /** Called when selection changes */
36
+ onchange?: (value: unknown, item: unknown) => void;
37
+ /** Custom snippet for rendering a swatch (receives proxy + selected) */
38
+ item?: Snippet<[ProxyItem, boolean]>;
39
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Swatch Component Types
3
+ *
4
+ * A group of selectable colour swatches. Options may be primitives (hex or
5
+ * colour-name strings) or objects whose fill/stroke/value are read through the
6
+ * usual field mapping.
7
+ */
8
+ export {};
@@ -143,6 +143,11 @@ export interface TableProps {
143
143
  row?: TableRowSnippet;
144
144
  /** Custom cell snippet */
145
145
  cell?: TableCellSnippet;
146
+ /**
147
+ * Per-column named snippets, selected via a column's `snippet` field. Takes
148
+ * precedence over `cell` for the columns that name one.
149
+ */
150
+ snippets?: Record<string, TableCellSnippet>;
146
151
  /** Empty state snippet */
147
152
  empty?: TableEmptySnippet;
148
153
  }
@@ -85,6 +85,11 @@ export interface ToolbarProps {
85
85
  class?: string;
86
86
  /** Custom snippet for rendering toolbar items */
87
87
  item?: ToolbarItemSnippet;
88
+ /**
89
+ * Per-item named snippets, selected via the item's `snippet` field. A declared
90
+ * prop rather than an index signature — see types/snippets.ts for why.
91
+ */
92
+ snippets?: Record<string, ToolbarItemSnippet>;
88
93
  /** Slot for start section content */
89
94
  start?: import('svelte').Snippet;
90
95
  /** Slot for center section content */
@@ -5,7 +5,8 @@
5
5
  * Supports hierarchical data with expand/collapse, tree lines, and custom icons.
6
6
  * Field mapping and data access is handled by ProxyItem from @rokkit/states.
7
7
  */
8
- import type { Snippet } from 'svelte';
8
+ import type { ItemSnippets } from './snippets.js';
9
+ import type { ProxyItem } from '@rokkit/states';
9
10
  /**
10
11
  * Field mapping configuration for tree data — what the consumer passes
11
12
  * to the Tree component. Both `expanded` and `level` are optional here
@@ -87,82 +88,49 @@ export interface TreeStateIcons {
87
88
  */
88
89
  export declare const defaultTreeStateIcons: TreeStateIcons;
89
90
  /**
90
- * Handlers passed to custom item snippets
91
- */
92
- export interface TreeItemHandlers {
93
- /** Call to trigger item selection */
94
- onclick: () => void;
95
- /** Call to toggle expand/collapse */
96
- ontoggle: () => void;
97
- /** Forward keyboard events for accessibility */
98
- onkeydown: (event: KeyboardEvent) => void;
99
- }
100
- /**
101
- * Snippet type for rendering tree nodes.
102
- * Parameters: item, fields, handlers, isActive, isExpanded, level
103
- */
104
- export type TreeItemSnippet = Snippet<[
105
- TreeItem,
106
- TreeFields,
107
- TreeItemHandlers,
108
- boolean,
109
- boolean,
110
- number
111
- ]>;
112
- /**
113
- * Snippet type for rendering the expand/collapse icon
114
- * Parameters: isExpanded, hasChildren, icons
115
- */
116
- export type TreeToggleSnippet = Snippet<[boolean, boolean, TreeStateIcons]>;
117
- /**
118
- * Snippet type for rendering tree line connectors
119
- * Parameters: lineType
91
+ * Props for the Tree component
120
92
  */
121
- export type TreeConnectorSnippet = Snippet<[TreeLineType]>;
122
93
  /**
123
- * Props for the Tree component
94
+ * Props for the Tree component.
95
+ *
96
+ * `Tree.svelte` annotates its own `$props()` with this interface, so the two
97
+ * cannot drift — which is how the previous version came to describe
98
+ * `multiselect`, `expanded`, `selected`, `expandAll`, `active` and four
99
+ * callbacks the component never read.
124
100
  */
125
- export interface TreeProps {
101
+ export interface TreeProps extends ItemSnippets {
126
102
  /** Array of tree items (hierarchical) */
127
- items?: TreeItem[];
103
+ items?: unknown[];
128
104
  /** Field mapping configuration */
129
- fields?: TreeFields;
130
- /** Currently selected value */
105
+ fields?: Record<string, string>;
106
+ /** Selected value (bindable) */
131
107
  value?: unknown;
132
108
  /** Size variant */
133
- size?: 'sm' | 'md' | 'lg';
134
- /** Tree line connector style — 'none' hides lines, 'solid'|'dashed'|'dotted' set the line style */
109
+ size?: string;
110
+ /** Connector style — 'none' hides the lines */
135
111
  lineStyle?: 'none' | 'solid' | 'dashed' | 'dotted';
136
- /** Enable multiple item selection (Ctrl+click toggle, Shift+click range) */
137
- multiselect?: boolean;
138
- /** Which nodes are expanded (bindable) - keyed by node value */
139
- expanded?: Record<string, boolean>;
140
- /** Selected items array (bindable) - populated in multiselect mode */
141
- selected?: unknown[];
142
- /** Expand all nodes by default */
143
- expandAll?: boolean;
144
- /** Active item value - Tree looks up item by this value to highlight it */
145
- active?: unknown;
112
+ /** Accessible label overrides */
113
+ labels?: Record<string, string>;
146
114
  /** Icons for expand/collapse states */
147
- icons?: TreeStateIcons;
148
- /** Called when an item is selected */
149
- onselect?: (value: unknown, item: TreeItem) => void;
150
- /** Called when selected items change in multiselect mode */
151
- onselectedchange?: (selected: unknown[]) => void;
152
- /** Called when expanded state changes */
153
- onexpandedchange?: (expanded: Record<string, boolean>) => void;
154
- /** Called when a node is toggled */
155
- ontoggle?: (value: unknown, item: TreeItem, isExpanded: boolean) => void;
156
- /** Called when expanding a node with unloaded children (children: true). Returns the children array. */
157
- onloadchildren?: (value: unknown, item: TreeItem) => Promise<TreeItem[]>;
115
+ icons?: {
116
+ opened?: string;
117
+ closed?: string;
118
+ };
119
+ /** Called when an item is selected, with the item's `ProxyItem` */
120
+ onselect?: (value: unknown, proxy: ProxyItem) => void;
158
121
  /** Additional CSS classes */
159
122
  class?: string;
160
- /** Custom snippet for rendering tree items */
161
- item?: TreeItemSnippet;
162
- /** Custom snippet for rendering expand/collapse toggle */
163
- toggle?: TreeToggleSnippet;
164
- /** Custom snippet for rendering tree line connectors */
165
- connector?: TreeConnectorSnippet;
123
+ }
124
+ /**
125
+ * Props for the LazyTree component — Tree plus on-demand child loading.
126
+ */
127
+ export interface LazyTreeProps extends TreeProps {
128
+ /** Size variant */
129
+ size?: 'sm' | 'md' | 'lg';
130
+ /** Called to fetch the children of a node being expanded */
131
+ onlazyload?: (current?: unknown) => Promise<unknown[]>;
132
+ /** Whether more nodes remain to load */
133
+ hasMore?: boolean;
166
134
  }
167
135
  /**
168
136
  * Constructs an array of line types for tree visualization.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rokkit/ui",
3
- "version": "1.4.2",
3
+ "version": "1.6.0",
4
4
  "description": "Data driven UI components for Rokkit applications",
5
5
  "repository": {
6
6
  "type": "git",
@@ -45,10 +45,10 @@
45
45
  "dropdown"
46
46
  ],
47
47
  "dependencies": {
48
- "@rokkit/core": "1.4.2",
49
- "@rokkit/data": "1.4.2",
50
- "@rokkit/states": "1.4.2",
51
- "@rokkit/actions": "1.4.2",
48
+ "@rokkit/core": "1.6.0",
49
+ "@rokkit/data": "1.6.0",
50
+ "@rokkit/states": "1.6.0",
51
+ "@rokkit/actions": "1.6.0",
52
52
  "marked": "^15.0.0",
53
53
  "dompurify": "^3.4.13"
54
54
  },