@djangocfg/ui-tools 2.1.315 → 2.1.316

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,442 @@
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import * as React$1 from 'react';
3
+ import { CSSProperties, ReactNode } from 'react';
4
+
5
+ type TreeDensity = 'compact' | 'cozy' | 'comfortable';
6
+ type TreeAccentIntensity = 'subtle' | 'default' | 'strong';
7
+ type TreeRadius = 'none' | 'sm' | 'md';
8
+ /**
9
+ * Cosmetic configuration. Every field is optional; missing values fall
10
+ * back to the `cozy` preset (a comfortable VSCode-Explorer-like density).
11
+ *
12
+ * Customize the look without re-implementing slots.
13
+ */
14
+ interface TreeAppearance {
15
+ /** Built-in size preset. Default: `'cozy'`. */
16
+ density?: TreeDensity;
17
+ /** Override row height in px (wins over density). */
18
+ rowHeight?: number;
19
+ /** Override icon + chevron size in px (wins over density). */
20
+ iconSize?: number;
21
+ /** Lucide stroke width for icon + chevron. Default: 1.5. */
22
+ iconStrokeWidth?: number;
23
+ /** Override label font size in px (wins over density). */
24
+ fontSize?: number;
25
+ /** Pixels between chevron / icon / label. Default depends on density. */
26
+ gap?: number;
27
+ /** Pixels between nesting levels. Default: 16. */
28
+ indent?: number;
29
+ /** Hover / selected highlight intensity. Default: `'default'`. */
30
+ accent?: TreeAccentIntensity;
31
+ /** Row corner radius. Default: `'sm'`. */
32
+ radius?: TreeRadius;
33
+ /** Indent-guide line opacity (0..1). Default: 0.4. */
34
+ indentGuideOpacity?: number;
35
+ /**
36
+ * Show a 2px primary-tinted bar on the left of the selected row.
37
+ * Mimics the VSCode active-tab indicator. Default: `true`.
38
+ */
39
+ showActiveIndicator?: boolean;
40
+ }
41
+ interface ResolvedAppearance {
42
+ density: TreeDensity;
43
+ rowHeight: number;
44
+ iconSize: number;
45
+ iconStrokeWidth: number;
46
+ fontSize: number;
47
+ gap: number;
48
+ indent: number;
49
+ accent: TreeAccentIntensity;
50
+ radius: TreeRadius;
51
+ indentGuideOpacity: number;
52
+ showActiveIndicator: boolean;
53
+ }
54
+ declare const DEFAULT_TREE_APPEARANCE: ResolvedAppearance;
55
+ /**
56
+ * Merge a partial appearance with the default + density preset.
57
+ *
58
+ * Explicit numeric overrides (e.g. `rowHeight`) win over the density preset.
59
+ */
60
+ declare function resolveAppearance(input?: TreeAppearance,
61
+ /** Outer `indent` prop (kept on TreeRoot for back-compat). */
62
+ outerIndent?: number): ResolvedAppearance;
63
+ /**
64
+ * Build the `style` object that exposes the resolved appearance to any
65
+ * descendant via CSS variables. Set on `<TreeRoot>`'s outer div.
66
+ */
67
+ declare function appearanceToStyle(a: ResolvedAppearance): CSSProperties;
68
+
69
+ type TreeItemId = string;
70
+ /** A single node in the consumer's tree data. Generic over your payload. */
71
+ interface TreeNode<T = unknown> {
72
+ id: TreeItemId;
73
+ data: T;
74
+ /** Inline children. Omit (and provide a `loadChildren`) for async loading. */
75
+ children?: TreeNode<T>[];
76
+ /**
77
+ * Set to `true` to mark a node as a folder even when its `children` array
78
+ * is empty (e.g. an unloaded async folder). Default: derived from
79
+ * `Array.isArray(children)`.
80
+ */
81
+ isFolder?: boolean;
82
+ /** Disable interaction. */
83
+ disabled?: boolean;
84
+ }
85
+ interface TreeLabels {
86
+ loading: string;
87
+ empty: string;
88
+ error: string;
89
+ searchPlaceholder: string;
90
+ searchMatches: (count: number) => string;
91
+ ariaLabel: string;
92
+ }
93
+ declare const DEFAULT_TREE_LABELS: TreeLabels;
94
+ type TreeSelectionMode = 'none' | 'single' | 'multiple';
95
+ /**
96
+ * Async loader: called the first time a folder is expanded with no inline
97
+ * `children`. Result is cached; concurrent expansions are de-duplicated.
98
+ */
99
+ type TreeLoadChildren<T> = (node: TreeNode<T>) => Promise<TreeNode<T>[]>;
100
+ interface TreeRowRenderProps<T> {
101
+ node: TreeNode<T>;
102
+ level: number;
103
+ isSelected: boolean;
104
+ isExpanded: boolean;
105
+ isFocused: boolean;
106
+ isFolder: boolean;
107
+ isLoading: boolean;
108
+ isMatchingSearch: boolean;
109
+ }
110
+ type TreeRowSlot<T> = (props: TreeRowRenderProps<T>) => ReactNode;
111
+ type TreeContextMenuSlot<T> = (props: TreeRowRenderProps<T>, trigger: ReactNode) => ReactNode;
112
+ interface TreeRootProps<T> {
113
+ /** Root nodes. Top-level items are rendered directly (no synthetic root). */
114
+ data: TreeNode<T>[];
115
+ /** Returns the human-readable name for a node (used by search/type-ahead). */
116
+ getItemName: (node: TreeNode<T>) => string;
117
+ /** Async loader for folders without inline `children`. */
118
+ loadChildren?: TreeLoadChildren<T>;
119
+ /** Selection behaviour. Default: `'single'`. */
120
+ selectionMode?: TreeSelectionMode;
121
+ /** Initially expanded ids. */
122
+ initialExpandedIds?: TreeItemId[];
123
+ /** Initially selected ids. */
124
+ initialSelectedIds?: TreeItemId[];
125
+ /** Pixels of indent per nesting level. Default: 16. (Shortcut for `appearance.indent`.) */
126
+ indent?: number;
127
+ /** Cosmetic configuration: density, sizes, accent intensity, radius. */
128
+ appearance?: TreeAppearance;
129
+ /** Triggered when selection changes. */
130
+ onSelectionChange?: (selectedIds: TreeItemId[]) => void;
131
+ /** Triggered when expanded set changes. */
132
+ onExpansionChange?: (expandedIds: TreeItemId[]) => void;
133
+ /** Enter / dblclick on a node. */
134
+ onActivate?: (node: TreeNode<T>) => void;
135
+ /** Show built-in search input. Default: false. */
136
+ enableSearch?: boolean;
137
+ /** Type printable letters to jump to a matching name. Default: true. */
138
+ enableTypeAhead?: boolean;
139
+ /** Render vertical indent guides under expanded folders. Default: false. */
140
+ showIndentGuides?: boolean;
141
+ /** Custom row renderer. Falls back to the default <TreeRow />. */
142
+ renderRow?: TreeRowSlot<T>;
143
+ /** Replace default folder/file icon. */
144
+ renderIcon?: TreeRowSlot<T>;
145
+ /** Replace default label rendering. */
146
+ renderLabel?: TreeRowSlot<T>;
147
+ /** Right-side actions slot (per row). */
148
+ renderActions?: TreeRowSlot<T>;
149
+ /** Wrap each row in a context menu (right-click). Receives the row meta + trigger element. */
150
+ renderContextMenu?: TreeContextMenuSlot<T>;
151
+ /** Override built-in copy in your locale. */
152
+ labels?: Partial<TreeLabels>;
153
+ /** Persist expanded + (optional) selected ids in localStorage under this key. */
154
+ persistKey?: string;
155
+ /** Persist selection alongside expansion. Default: false. */
156
+ persistSelection?: boolean;
157
+ className?: string;
158
+ style?: React.CSSProperties;
159
+ }
160
+ /** Internal flat-row representation used by the renderer + keyboard nav. */
161
+ interface FlatRow<T> {
162
+ node: TreeNode<T>;
163
+ level: number;
164
+ parentId: TreeItemId | null;
165
+ isFolder: boolean;
166
+ isExpanded: boolean;
167
+ isLoading: boolean;
168
+ hasError: boolean;
169
+ }
170
+
171
+ /**
172
+ * High-level entry point. Wraps Provider + (optional) search bar + content.
173
+ *
174
+ * For full control, compose with <TreeProvider>, <TreeContent>,
175
+ * <TreeSearchInput>, <TreeRow>, etc. directly from `@djangocfg/ui-tools/tree`.
176
+ */
177
+ declare function TreeRoot<T>(props: TreeRootProps<T>): react_jsx_runtime.JSX.Element;
178
+
179
+ type ChildEntryStatus = 'idle' | 'loading' | 'loaded' | 'error';
180
+ interface ChildEntry<T> {
181
+ status: ChildEntryStatus;
182
+ children: TreeNode<T>[];
183
+ error?: string;
184
+ }
185
+ type ChildCache<T> = Map<TreeItemId, ChildEntry<T>>;
186
+ declare const createChildCache: <T>() => ChildCache<T>;
187
+ /**
188
+ * Resolve a node's children for the current render.
189
+ *
190
+ * - If the node carries inline `children`, those win (no async fetch).
191
+ * - Otherwise we look in the cache.
192
+ *
193
+ * Returns `null` when nothing is loaded yet (caller may show a skeleton).
194
+ */
195
+ declare const resolveChildren: <T>(cache: ChildCache<T>, node: TreeNode<T>) => {
196
+ children: TreeNode<T>[] | null;
197
+ status: ChildEntryStatus;
198
+ error?: string;
199
+ };
200
+
201
+ interface TreeContextValue<T> {
202
+ expanded: ReadonlySet<TreeItemId>;
203
+ selected: ReadonlySet<TreeItemId>;
204
+ focused: TreeItemId | null;
205
+ query: string;
206
+ flatRows: FlatRow<T>[];
207
+ /** Search-matching node ids (subset of all flatRows). */
208
+ matchingIds: ReadonlySet<TreeItemId>;
209
+ expand: (id: TreeItemId) => void;
210
+ collapse: (id: TreeItemId) => void;
211
+ toggle: (id: TreeItemId) => void;
212
+ expandAll: () => void;
213
+ collapseAll: () => void;
214
+ select: (id: TreeItemId) => void;
215
+ setSelectedIds: (ids: TreeItemId[]) => void;
216
+ clearSelection: () => void;
217
+ setFocus: (id: TreeItemId | null) => void;
218
+ setQuery: (q: string) => void;
219
+ refresh: (id: TreeItemId) => Promise<void>;
220
+ refreshAll: () => Promise<void>;
221
+ activate: (node: TreeNode<T>) => void;
222
+ labels: TreeLabels;
223
+ /** Resolved cosmetic config — never null. */
224
+ appearance: ResolvedAppearance;
225
+ /** Convenience alias for `appearance.indent`. */
226
+ indent: number;
227
+ selectionMode: TreeSelectionMode;
228
+ enableSearch: boolean;
229
+ showIndentGuides: boolean;
230
+ getItemName: (node: TreeNode<T>) => string;
231
+ renderIcon?: TreeRowSlot<T>;
232
+ renderLabel?: TreeRowSlot<T>;
233
+ renderActions?: TreeRowSlot<T>;
234
+ renderContextMenu?: TreeContextMenuSlot<T>;
235
+ }
236
+ declare function useTreeContext<T>(): TreeContextValue<T>;
237
+ interface TreeProviderProps<T> extends Pick<TreeRootProps<T>, 'data' | 'getItemName' | 'loadChildren' | 'selectionMode' | 'initialExpandedIds' | 'initialSelectedIds' | 'indent' | 'appearance' | 'onSelectionChange' | 'onExpansionChange' | 'onActivate' | 'enableSearch' | 'showIndentGuides' | 'renderIcon' | 'renderLabel' | 'renderActions' | 'renderContextMenu' | 'labels' | 'persistKey' | 'persistSelection'> {
238
+ children: React$1.ReactNode;
239
+ }
240
+ declare function TreeProvider<T>(props: TreeProviderProps<T>): react_jsx_runtime.JSX.Element;
241
+
242
+ declare function useTreeLabels(): TreeLabels;
243
+ declare function useTreeRows<T>(): FlatRow<T>[];
244
+ declare function useTreeSelection<T>(): {
245
+ selectedIds: string[];
246
+ select: (id: TreeItemId) => void;
247
+ setSelectedIds: (ids: TreeItemId[]) => void;
248
+ clear: () => void;
249
+ isSelected: (id: TreeItemId) => boolean;
250
+ };
251
+ declare function useTreeExpansion<T>(): {
252
+ expandedIds: string[];
253
+ expand: (id: TreeItemId) => void;
254
+ collapse: (id: TreeItemId) => void;
255
+ toggle: (id: TreeItemId) => void;
256
+ expandAll: () => void;
257
+ collapseAll: () => void;
258
+ isExpanded: (id: TreeItemId) => boolean;
259
+ };
260
+ declare function useTreeFocus<T>(): {
261
+ focusedId: string;
262
+ setFocus: (id: TreeItemId | null) => void;
263
+ };
264
+ declare function useTreeSearch<T>(): {
265
+ isOpen: boolean;
266
+ query: string;
267
+ setQuery: (q: string) => void;
268
+ matchingIds: ReadonlySet<string>;
269
+ matchCount: number;
270
+ };
271
+ declare function useTreeActions<T>(): {
272
+ expand: (id: TreeItemId) => void;
273
+ collapse: (id: TreeItemId) => void;
274
+ toggle: (id: TreeItemId) => void;
275
+ expandAll: () => void;
276
+ collapseAll: () => void;
277
+ refresh: (id: TreeItemId) => Promise<void>;
278
+ refreshAll: () => Promise<void>;
279
+ activate: (node: TreeNode<T>) => void;
280
+ };
281
+
282
+ interface UseTreeTypeAheadOptions<T> {
283
+ /** Visible flat rows in render order. */
284
+ rows: FlatRow<T>[];
285
+ /** How to read the displayed name of a node (matched case-insensitively). */
286
+ getItemName: (node: TreeNode<T>) => string;
287
+ /** Element receiving keydown events. */
288
+ containerRef: React.RefObject<HTMLElement | null>;
289
+ /** Called with the matched node id so the consumer can focus / scroll. */
290
+ onMatch: (id: string) => void;
291
+ /** Disable without removing the call site. */
292
+ enabled?: boolean;
293
+ }
294
+ /**
295
+ * Type-ahead jump (Finder / VSCode style).
296
+ *
297
+ * Builds a rolling buffer of printable keys (within ~600 ms of each other)
298
+ * and notifies the consumer of the first row whose name starts with that
299
+ * prefix. Resets on Esc / Enter / navigation keys / timeout.
300
+ */
301
+ declare function useTreeTypeAhead<T>({ rows, getItemName, containerRef, onMatch, enabled, }: UseTreeTypeAheadOptions<T>): void;
302
+
303
+ interface UseTreeKeyboardOptions<T> {
304
+ rows: FlatRow<T>[];
305
+ focusedId: TreeItemId | null;
306
+ enabled?: boolean;
307
+ onFocus: (id: TreeItemId) => void;
308
+ onSelect: (id: TreeItemId) => void;
309
+ onActivate: (id: TreeItemId) => void;
310
+ onExpand: (id: TreeItemId) => void;
311
+ onCollapse: (id: TreeItemId) => void;
312
+ onClearSelection: () => void;
313
+ }
314
+ interface UseTreeKeyboardReturn {
315
+ /** Attach to the tree container. Hotkeys only fire when focus is inside. */
316
+ ref: (instance: HTMLElement | null) => void;
317
+ }
318
+ /**
319
+ * Standard tree keyboard navigation, scoped to the container ref.
320
+ *
321
+ * - ↑ / ↓ : prev / next visible row
322
+ * - Home / End : first / last visible row
323
+ * - → : expand folder; if already expanded, jump to first child
324
+ * - ← : collapse folder; if already collapsed (or leaf), jump to parent
325
+ * - Enter / Space : activate (folder => toggle, leaf => onActivate)
326
+ * - Esc : clear selection
327
+ *
328
+ * Built on `useHotkey` (react-hotkeys-hook) — focus gating is automatic; no
329
+ * manual `addEventListener` or `data-scope` juggling.
330
+ */
331
+ declare function useTreeKeyboard<T>({ rows, focusedId, enabled, onFocus, onSelect, onActivate, onExpand, onCollapse, onClearSelection, }: UseTreeKeyboardOptions<T>): UseTreeKeyboardReturn;
332
+
333
+ interface TreeChevronProps {
334
+ isExpanded: boolean;
335
+ isFolder: boolean;
336
+ className?: string;
337
+ }
338
+ declare function TreeChevron({ isExpanded, isFolder, className }: TreeChevronProps): react_jsx_runtime.JSX.Element;
339
+
340
+ interface TreeIconProps {
341
+ isFolder: boolean;
342
+ isExpanded: boolean;
343
+ className?: string;
344
+ }
345
+ declare function TreeIcon({ isFolder, isExpanded, className }: TreeIconProps): react_jsx_runtime.JSX.Element;
346
+
347
+ interface TreeLabelProps {
348
+ children: React.ReactNode;
349
+ isMatchingSearch?: boolean;
350
+ className?: string;
351
+ }
352
+ declare function TreeLabel({ children, isMatchingSearch, className }: TreeLabelProps): react_jsx_runtime.JSX.Element;
353
+
354
+ interface TreeRowProps<T> {
355
+ row: FlatRow<T>;
356
+ className?: string;
357
+ }
358
+ declare function TreeRow<T>({ row, className }: TreeRowProps<T>): react_jsx_runtime.JSX.Element;
359
+
360
+ interface TreeContentProps<T> {
361
+ /** Custom row renderer; falls back to <TreeRow />. */
362
+ children?: TreeRowSlot<T>;
363
+ className?: string;
364
+ /** Override aria-label for the container. */
365
+ ariaLabel?: string;
366
+ }
367
+ declare function TreeContent<T>({ children, className, ariaLabel }: TreeContentProps<T>): react_jsx_runtime.JSX.Element;
368
+
369
+ interface TreeSearchInputProps {
370
+ className?: string;
371
+ showMatches?: boolean;
372
+ }
373
+ declare function TreeSearchInput({ className, showMatches }: TreeSearchInputProps): react_jsx_runtime.JSX.Element;
374
+
375
+ interface TreeEmptyProps {
376
+ children: React.ReactNode;
377
+ className?: string;
378
+ }
379
+ declare function TreeEmpty({ children, className }: TreeEmptyProps): react_jsx_runtime.JSX.Element;
380
+
381
+ interface TreeSkeletonProps {
382
+ rows?: number;
383
+ className?: string;
384
+ }
385
+ declare function TreeSkeleton({ rows, className }: TreeSkeletonProps): react_jsx_runtime.JSX.Element;
386
+
387
+ interface TreeErrorProps {
388
+ children: React.ReactNode;
389
+ className?: string;
390
+ }
391
+ declare function TreeError({ children, className }: TreeErrorProps): react_jsx_runtime.JSX.Element;
392
+
393
+ interface TreeIndentGuidesProps {
394
+ level: number;
395
+ indent: number;
396
+ }
397
+ /**
398
+ * Vertical guide lines under nested rows. Renders one absolute-positioned
399
+ * 1px column per ancestor level. Decorative — `aria-hidden` and
400
+ * pointer-events disabled. Opacity comes from the tree appearance.
401
+ */
402
+ declare function TreeIndentGuides({ level, indent }: TreeIndentGuidesProps): react_jsx_runtime.JSX.Element;
403
+
404
+ interface FlattenInput<T> {
405
+ roots: TreeNode<T>[];
406
+ expandedIds: ReadonlySet<TreeItemId>;
407
+ cache: ChildCache<T>;
408
+ }
409
+ /**
410
+ * Walk the tree top-to-bottom and produce a flat list of visible rows.
411
+ *
412
+ * Visibility rule: a child row appears only when every ancestor is in
413
+ * `expandedIds`. The output is ordered exactly as it should render,
414
+ * which keeps keyboard navigation (next/prev row) trivial.
415
+ */
416
+ declare function flattenTree<T>({ roots, expandedIds, cache }: FlattenInput<T>): FlatRow<T>[];
417
+
418
+ interface PersistedTreeState {
419
+ expandedItems: TreeItemId[];
420
+ selectedItems: TreeItemId[];
421
+ }
422
+ declare function loadTreeState(key: string): PersistedTreeState | null;
423
+ declare function saveTreeState(key: string, state: PersistedTreeState): void;
424
+ declare function clearTreeState(key: string): void;
425
+
426
+ interface DemoNode {
427
+ name: string;
428
+ }
429
+ /**
430
+ * Build a deterministic synthetic tree for stories and tests.
431
+ *
432
+ * @example
433
+ * const data = createDemoTree({ depth: 4, breadth: 3 });
434
+ * <TreeRoot data={data} getItemName={(n) => n.data.name} />
435
+ */
436
+ declare function createDemoTree({ depth, breadth, rootPrefix, }?: {
437
+ depth?: number;
438
+ breadth?: number;
439
+ rootPrefix?: string;
440
+ }): TreeNode<DemoNode>[];
441
+
442
+ export { type ChildCache, type ChildEntry, type ChildEntryStatus, DEFAULT_TREE_APPEARANCE, DEFAULT_TREE_LABELS, type DemoNode, type FlatRow, type FlattenInput, type PersistedTreeState, type ResolvedAppearance, TreeRoot as Tree, type TreeAccentIntensity, type TreeAppearance, TreeChevron, type TreeChevronProps, TreeContent, type TreeContentProps, type TreeContextMenuSlot, type TreeContextValue, type TreeDensity, TreeEmpty, type TreeEmptyProps, TreeError, type TreeErrorProps, TreeIcon, type TreeIconProps, TreeIndentGuides, type TreeIndentGuidesProps, type TreeItemId, TreeLabel, type TreeLabelProps, type TreeLabels, type TreeLoadChildren, type TreeNode, TreeProvider, type TreeProviderProps, type TreeRadius, TreeRoot, type TreeRootProps, TreeRow, type TreeRowProps, type TreeRowRenderProps, type TreeRowSlot, TreeSearchInput, type TreeSearchInputProps, type TreeSelectionMode, TreeSkeleton, type TreeSkeletonProps, type UseTreeKeyboardOptions, type UseTreeTypeAheadOptions, appearanceToStyle, clearTreeState, createChildCache, createDemoTree, TreeRoot as default, flattenTree, loadTreeState, resolveAppearance, resolveChildren, saveTreeState, useTreeActions, useTreeContext, useTreeExpansion, useTreeFocus, useTreeKeyboard, useTreeLabels, useTreeRows, useTreeSearch, useTreeSelection, useTreeTypeAhead };
@@ -0,0 +1,5 @@
1
+ export { TreeError, TreeSkeleton, createDemoTree } from '../chunk-KR6B3LVY.mjs';
2
+ export { DEFAULT_TREE_APPEARANCE, DEFAULT_TREE_LABELS, TreeRoot as Tree, TreeChevron, TreeContent, TreeEmpty, TreeIcon, TreeIndentGuides, TreeLabel, TreeProvider, TreeRoot, TreeRow, TreeSearchInput, appearanceToStyle, clearTreeState, createChildCache, TreeRoot_default as default, flattenTree, loadTreeState, resolveAppearance, resolveChildren, saveTreeState, useTreeActions, useTreeContext, useTreeExpansion, useTreeFocus, useTreeKeyboard, useTreeLabels, useTreeRows, useTreeSearch, useTreeSelection, useTreeTypeAhead } from '../chunk-NFIMVYJU.mjs';
3
+ import '../chunk-CGILA3WO.mjs';
4
+ //# sourceMappingURL=index.mjs.map
5
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.mjs"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@djangocfg/ui-tools",
3
- "version": "2.1.315",
3
+ "version": "2.1.316",
4
4
  "description": "Heavy React tools with lazy loading - for Electron, Vite, CRA, Next.js apps",
5
5
  "keywords": [
6
6
  "ui-tools",
@@ -75,9 +75,9 @@
75
75
  "require": "./src/tools/CodeEditor/index.ts"
76
76
  },
77
77
  "./tree": {
78
- "types": "./src/tools/Tree/index.tsx",
79
- "import": "./src/tools/Tree/index.tsx",
80
- "require": "./src/tools/Tree/index.tsx"
78
+ "types": "./dist/tree/index.d.ts",
79
+ "import": "./dist/tree/index.mjs",
80
+ "require": "./dist/tree/index.cjs"
81
81
  },
82
82
  "./styles": "./src/styles/index.css",
83
83
  "./dist.css": "./dist/index.css"
@@ -96,8 +96,8 @@
96
96
  "check": "tsc --noEmit"
97
97
  },
98
98
  "peerDependencies": {
99
- "@djangocfg/i18n": "^2.1.315",
100
- "@djangocfg/ui-core": "^2.1.315",
99
+ "@djangocfg/i18n": "^2.1.316",
100
+ "@djangocfg/ui-core": "^2.1.316",
101
101
  "consola": "^3.4.2",
102
102
  "lodash-es": "^4.18.1",
103
103
  "lucide-react": "^0.545.0",
@@ -149,10 +149,10 @@
149
149
  "@maplibre/maplibre-gl-geocoder": "^1.7.0"
150
150
  },
151
151
  "devDependencies": {
152
- "@djangocfg/i18n": "^2.1.315",
152
+ "@djangocfg/i18n": "^2.1.316",
153
153
  "@djangocfg/playground": "workspace:*",
154
- "@djangocfg/typescript-config": "^2.1.315",
155
- "@djangocfg/ui-core": "^2.1.315",
154
+ "@djangocfg/typescript-config": "^2.1.316",
155
+ "@djangocfg/ui-core": "^2.1.316",
156
156
  "@types/lodash-es": "^4.17.12",
157
157
  "@types/mapbox__mapbox-gl-draw": "^1.4.8",
158
158
  "@types/node": "^24.7.2",
@@ -97,9 +97,8 @@ function TreeRootShell<T>({
97
97
  const containerRef = useRef<HTMLDivElement>(null);
98
98
  const ctx = useTreeContext<T>();
99
99
 
100
- // Keyboard navigation (↑↓ ←→ Home/End Enter Esc).
101
- useTreeKeyboard<T>({
102
- containerRef,
100
+ // Keyboard navigation (↑↓ ←→ Home/End Enter Esc) — scoped via callback ref.
101
+ const { ref: keyboardRef } = useTreeKeyboard<T>({
103
102
  rows: ctx.flatRows,
104
103
  focusedId: ctx.focused,
105
104
  onFocus: ctx.setFocus,
@@ -113,6 +112,14 @@ function TreeRootShell<T>({
113
112
  onClearSelection: ctx.clearSelection,
114
113
  });
115
114
 
115
+ const setContainerRef = useCallback(
116
+ (instance: HTMLDivElement | null) => {
117
+ containerRef.current = instance;
118
+ keyboardRef(instance);
119
+ },
120
+ [keyboardRef],
121
+ );
122
+
116
123
  // Type-ahead jump.
117
124
  const onTypeAheadMatch = useCallback(
118
125
  (id: string) => {
@@ -136,7 +143,7 @@ function TreeRootShell<T>({
136
143
 
137
144
  return (
138
145
  <div
139
- ref={containerRef}
146
+ ref={setContainerRef}
140
147
  tabIndex={0}
141
148
  className={cn(
142
149
  'group/tree flex h-full w-full flex-col gap-2 outline-none',
@@ -69,15 +69,6 @@ export function TreeRow<T>({ row, className }: TreeRowProps<T>) {
69
69
  if (!isFolder) activate(node);
70
70
  };
71
71
 
72
- const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
73
- // Match native button keyboard semantics on the row itself.
74
- if (node.disabled) return;
75
- if (e.key === 'Enter' || e.key === ' ') {
76
- e.preventDefault();
77
- handleActivate();
78
- }
79
- };
80
-
81
72
  const trigger = (
82
73
  <div
83
74
  role="treeitem"
@@ -100,7 +91,6 @@ export function TreeRow<T>({ row, className }: TreeRowProps<T>) {
100
91
  }}
101
92
  onClick={handleClick}
102
93
  onDoubleClick={handleDoubleClick}
103
- onKeyDown={handleKeyDown}
104
94
  onFocus={() => setFocus(node.id)}
105
95
  className={cn(
106
96
  'group/row relative flex w-full select-none items-center pr-2 text-left',