torch-glare 2.1.1 → 2.1.3

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 (73) hide show
  1. package/apps/lib/components/Avatar.tsx +1 -1
  2. package/apps/lib/components/BadgeField.tsx +2 -2
  3. package/apps/lib/components/Card.tsx +68 -54
  4. package/apps/lib/components/DataViews/ARCHITECTURE.md +439 -0
  5. package/apps/lib/components/DataViews/DataViewRadio.tsx +47 -0
  6. package/apps/lib/components/DataViews/DataViewsConfigPanel.tsx +427 -0
  7. package/apps/lib/components/DataViews/DataViewsHeader.tsx +228 -0
  8. package/apps/lib/components/DataViews/DataViewsLayout.tsx +330 -0
  9. package/apps/lib/components/DataViews/FilterPanel.tsx +469 -0
  10. package/apps/lib/components/DataViews/HeaderSearch.tsx +97 -0
  11. package/apps/lib/components/DataViews/InboxView.tsx +495 -0
  12. package/apps/lib/components/DataViews/InboxViewCard.tsx +136 -0
  13. package/apps/lib/components/DataViews/KanbanView.tsx +353 -0
  14. package/apps/lib/components/DataViews/PanelControls.tsx +49 -0
  15. package/apps/lib/components/DataViews/SettingsPanel.tsx +285 -0
  16. package/apps/lib/components/DataViews/TableView.tsx +232 -0
  17. package/apps/lib/components/DataViews/TreeView.tsx +392 -0
  18. package/apps/lib/components/DataViews/badgeAdapter.ts +45 -0
  19. package/apps/lib/components/DataViews/fieldRenderers.tsx +334 -0
  20. package/apps/lib/components/DataViews/filters/DateRangePopover.tsx +113 -0
  21. package/apps/lib/components/DataViews/filters/PresetChips.tsx +45 -0
  22. package/apps/lib/components/DataViews/filters/RangeSliderWithInputs.tsx +154 -0
  23. package/apps/lib/components/DataViews/index.ts +36 -0
  24. package/apps/lib/components/DataViews/tree/TreeDrawer.tsx +54 -0
  25. package/apps/lib/components/DataViews/tree/TreeSidebar.tsx +77 -0
  26. package/apps/lib/components/DataViews/types.ts +206 -0
  27. package/apps/lib/components/Radio.tsx +18 -21
  28. package/apps/lib/components/Switch.tsx +3 -1
  29. package/apps/lib/components/Table.tsx +1 -1
  30. package/apps/lib/components/TreeFolder/TreeFolder.tsx +410 -0
  31. package/apps/lib/components/TreeFolder/TreeFolderBreadcrumb.tsx +80 -0
  32. package/apps/lib/components/TreeFolder/TreeFolderRow.tsx +363 -0
  33. package/apps/lib/components/TreeFolder/TreeFolderStyles.tsx +60 -0
  34. package/apps/lib/components/TreeFolder/icons.tsx +63 -0
  35. package/apps/lib/components/TreeFolder/index.ts +17 -0
  36. package/apps/lib/components/TreeFolder/treeFolderUtils.ts +114 -0
  37. package/apps/lib/components/TreeFolder/types.ts +77 -0
  38. package/apps/lib/components/TreeFolder/useTreeFolderDnD.ts +261 -0
  39. package/apps/lib/hooks/useDataViewsState.ts +169 -0
  40. package/apps/lib/hooks/useIsMobile.ts +21 -0
  41. package/apps/lib/layouts/DataViewCard.tsx +76 -0
  42. package/apps/lib/utils/dataViews/columnUtils.ts +130 -0
  43. package/apps/lib/utils/dataViews/fieldUtils.ts +198 -0
  44. package/apps/lib/utils/dataViews/nestedDataUtils.tsx +364 -0
  45. package/apps/lib/utils/dataViews/pathUtils.ts +132 -0
  46. package/apps/lib/utils/dataViews/rangeUtils.ts +225 -0
  47. package/apps/lib/utils/dataViews/treeUtils.ts +403 -0
  48. package/dist/bin/index.js +3 -3
  49. package/dist/bin/index.js.map +1 -1
  50. package/dist/src/commands/add.d.ts.map +1 -1
  51. package/dist/src/commands/add.js +29 -6
  52. package/dist/src/commands/add.js.map +1 -1
  53. package/dist/src/commands/utils.d.ts.map +1 -1
  54. package/dist/src/commands/utils.js +22 -2
  55. package/dist/src/commands/utils.js.map +1 -1
  56. package/dist/src/shared/copyComponentsRecursively.d.ts.map +1 -1
  57. package/dist/src/shared/copyComponentsRecursively.js +17 -2
  58. package/dist/src/shared/copyComponentsRecursively.js.map +1 -1
  59. package/dist/src/shared/getDependenciesAndInstallNestedComponents.d.ts +18 -4
  60. package/dist/src/shared/getDependenciesAndInstallNestedComponents.d.ts.map +1 -1
  61. package/dist/src/shared/getDependenciesAndInstallNestedComponents.js +110 -40
  62. package/dist/src/shared/getDependenciesAndInstallNestedComponents.js.map +1 -1
  63. package/docs/components/data-views-config-panel.md +204 -0
  64. package/docs/components/data-views-layout.md +270 -0
  65. package/docs/components/form-stepper.md +244 -0
  66. package/docs/components/stepper.md +215 -0
  67. package/docs/components/timeline.md +248 -0
  68. package/package.json +6 -6
  69. package/apps/lib/components/Charts-dev.tsx +0 -365
  70. package/apps/lib/components/Command-dev.tsx +0 -151
  71. package/apps/lib/components/IosDatePicker-dev.tsx +0 -341
  72. /package/docs/components/{labeled-checkbox.md → labeled-check-box.md} +0 -0
  73. /package/docs/components/{tree-dropdown.md → tree-drop-down.md} +0 -0
@@ -0,0 +1,410 @@
1
+ "use client";
2
+
3
+ import {
4
+ forwardRef,
5
+ useCallback,
6
+ useImperativeHandle,
7
+ useMemo,
8
+ useRef,
9
+ useState,
10
+ type ReactNode,
11
+ } from "react";
12
+ import { cn } from "../../utils/cn";
13
+ import type { Themes } from "../../utils/types";
14
+ import { TreeFolderBreadcrumb } from "./TreeFolderBreadcrumb";
15
+ import { TreeFolderRow } from "./TreeFolderRow";
16
+ import { TreeFolderStyles } from "./TreeFolderStyles";
17
+ import {
18
+ applyMove,
19
+ descendantIds,
20
+ findNode,
21
+ findPath,
22
+ toBreadcrumb,
23
+ } from "./treeFolderUtils";
24
+ import type {
25
+ TreeFolderIconResolver,
26
+ TreeFolderMoveArgs,
27
+ TreeFolderNode,
28
+ TreeFolderVisibleRow,
29
+ } from "./types";
30
+ import { useTreeFolderDnD } from "./useTreeFolderDnD";
31
+
32
+ export type TreeFolderProps = {
33
+ data: TreeFolderNode[];
34
+ selectedId?: string | null;
35
+ defaultSelectedId?: string | null;
36
+ onSelectionChange?: (id: string | null) => void;
37
+
38
+ expandedIds?: string[];
39
+ defaultExpanded?: "all" | "roots" | "none" | string[];
40
+ onExpandedChange?: (ids: string[]) => void;
41
+
42
+ dndEnabled?: boolean;
43
+ onMove?: (args: TreeFolderMoveArgs) => void;
44
+ onDataChange?: (next: TreeFolderNode[]) => void;
45
+
46
+ iconFor?: TreeFolderIconResolver;
47
+
48
+ title?: string;
49
+ showBreadcrumb?: boolean;
50
+ showHeader?: boolean;
51
+ highlightAncestors?: boolean;
52
+ highlightSubtree?: boolean;
53
+ headerAccessory?: ReactNode;
54
+ emptyState?: ReactNode;
55
+
56
+ rowHeight?: number;
57
+ indent?: number;
58
+ /** Optional. If set, the row strip will be at least this wide (in px) — useful
59
+ * when you want the band to extend across a wider canvas regardless of content. */
60
+ contentMinWidth?: number;
61
+
62
+ className?: string;
63
+ theme?: Themes;
64
+ };
65
+
66
+ export type TreeFolderHandle = {
67
+ selectId: (id: string | null) => void;
68
+ expandAll: () => void;
69
+ collapseAll: () => void;
70
+ scrollToId: (id: string) => void;
71
+ };
72
+
73
+ const ROW_HEIGHT_DEFAULT = 28;
74
+ const INDENT_DEFAULT = 14;
75
+
76
+ function collectIds(nodes: TreeFolderNode[], out: string[] = []): string[] {
77
+ for (const n of nodes) {
78
+ out.push(n.id);
79
+ if (n.children) collectIds(n.children, out);
80
+ }
81
+ return out;
82
+ }
83
+
84
+ function rootIds(nodes: TreeFolderNode[]): string[] {
85
+ return nodes.map((n) => n.id);
86
+ }
87
+
88
+ function flattenVisible(
89
+ data: TreeFolderNode[],
90
+ expanded: Set<string>,
91
+ ): TreeFolderVisibleRow[] {
92
+ const out: TreeFolderVisibleRow[] = [];
93
+ // `ancestorHasMore` tracks, for each open ancestor depth on the descent
94
+ // path, whether that ancestor still has more siblings to render. We push
95
+ // before descending and pop on the way back up; each row snapshots the
96
+ // current state so its connector gutters know which verticals to draw.
97
+ const ancestorHasMore: boolean[] = [];
98
+ const walk = (
99
+ nodes: TreeFolderNode[],
100
+ level: number,
101
+ parentId: string | null,
102
+ ) => {
103
+ nodes.forEach((node, idx) => {
104
+ const isInternal = !!(node.children && node.children.length > 0);
105
+ const isOpen = isInternal && expanded.has(node.id);
106
+ const isLastChild = idx === nodes.length - 1;
107
+ out.push({
108
+ node,
109
+ level,
110
+ parentId,
111
+ childIndex: idx,
112
+ isOpen,
113
+ isInternal,
114
+ isLastChild,
115
+ ancestorHasMoreSiblings: ancestorHasMore.slice(),
116
+ });
117
+ if (isOpen && node.children) {
118
+ ancestorHasMore.push(!isLastChild);
119
+ walk(node.children, level + 1, node.id);
120
+ ancestorHasMore.pop();
121
+ }
122
+ });
123
+ };
124
+ walk(data, 0, null);
125
+ return out;
126
+ }
127
+
128
+ export const TreeFolder = forwardRef<TreeFolderHandle, TreeFolderProps>(
129
+ function TreeFolder(props, ref) {
130
+ const {
131
+ data,
132
+ selectedId: controlledSelected,
133
+ defaultSelectedId = null,
134
+ onSelectionChange,
135
+ expandedIds: controlledExpanded,
136
+ defaultExpanded = "roots",
137
+ onExpandedChange,
138
+ dndEnabled = true,
139
+ onMove,
140
+ onDataChange,
141
+ iconFor,
142
+ title = "Layers",
143
+ showBreadcrumb = true,
144
+ showHeader = true,
145
+ highlightAncestors = false,
146
+ highlightSubtree = true,
147
+ headerAccessory,
148
+ emptyState,
149
+ rowHeight = ROW_HEIGHT_DEFAULT,
150
+ indent = INDENT_DEFAULT,
151
+ contentMinWidth,
152
+ className,
153
+ theme,
154
+ } = props;
155
+
156
+ const scrollRef = useRef<HTMLDivElement | null>(null);
157
+
158
+ // ---- Selection state ----
159
+ const [internalSelected, setInternalSelected] = useState<string | null>(
160
+ defaultSelectedId,
161
+ );
162
+ const selectedId =
163
+ controlledSelected !== undefined ? controlledSelected : internalSelected;
164
+ const isSelectionControlled = controlledSelected !== undefined;
165
+
166
+ // ---- Expansion state ----
167
+ const [internalExpanded, setInternalExpanded] = useState<string[]>(() => {
168
+ if (Array.isArray(defaultExpanded)) return defaultExpanded;
169
+ if (defaultExpanded === "all") return collectIds(data);
170
+ if (defaultExpanded === "none") return [];
171
+ return rootIds(data);
172
+ });
173
+ const expandedIds = controlledExpanded ?? internalExpanded;
174
+ const isExpansionControlled = controlledExpanded !== undefined;
175
+ const expandedSet = useMemo(() => new Set(expandedIds), [expandedIds]);
176
+
177
+ // ---- Visible rows ----
178
+ const visibleRows = useMemo(
179
+ () => flattenVisible(data, expandedSet),
180
+ [data, expandedSet],
181
+ );
182
+ const rowsById = useMemo(() => {
183
+ const m = new Map<string, TreeFolderVisibleRow>();
184
+ for (const r of visibleRows) m.set(r.node.id, r);
185
+ return m;
186
+ }, [visibleRows]);
187
+
188
+ // ---- Ancestor + subtree highlight ----
189
+ const ancestorPath = useMemo(
190
+ () => (selectedId ? findPath(data, selectedId) : null),
191
+ [data, selectedId],
192
+ );
193
+ const ancestorIdSet = useMemo(
194
+ () => new Set((ancestorPath ?? []).slice(0, -1).map((n) => n.id)),
195
+ [ancestorPath],
196
+ );
197
+ const isAncestorFn = useCallback(
198
+ (id: string) => highlightAncestors && ancestorIdSet.has(id),
199
+ [highlightAncestors, ancestorIdSet],
200
+ );
201
+
202
+ const descendantIdSet = useMemo(() => {
203
+ if (!highlightSubtree || !selectedId) return new Set<string>();
204
+ const node = findNode(data, selectedId);
205
+ if (!node) return new Set<string>();
206
+ return descendantIds(node, false);
207
+ }, [data, selectedId, highlightSubtree]);
208
+ const isDescendantOfSelected = useCallback(
209
+ (id: string) => descendantIdSet.has(id),
210
+ [descendantIdSet],
211
+ );
212
+
213
+ const breadcrumbItems = useMemo(
214
+ () => (ancestorPath ? toBreadcrumb(ancestorPath) : []),
215
+ [ancestorPath],
216
+ );
217
+
218
+ // ---- Handlers ----
219
+ const handleSelect = useCallback(
220
+ (id: string | null) => {
221
+ if (!isSelectionControlled) setInternalSelected(id);
222
+ onSelectionChange?.(id);
223
+ },
224
+ [isSelectionControlled, onSelectionChange],
225
+ );
226
+
227
+ const handleToggle = useCallback(
228
+ (id: string) => {
229
+ const next = expandedIds.includes(id)
230
+ ? expandedIds.filter((x) => x !== id)
231
+ : [...expandedIds, id];
232
+ if (!isExpansionControlled) setInternalExpanded(next);
233
+ onExpandedChange?.(next);
234
+ },
235
+ [expandedIds, isExpansionControlled, onExpandedChange],
236
+ );
237
+
238
+ const handleMoveInternal = useCallback(
239
+ (args: TreeFolderMoveArgs) => {
240
+ onMove?.(args);
241
+ if (onDataChange) onDataChange(applyMove(data, args));
242
+ },
243
+ [data, onMove, onDataChange],
244
+ );
245
+
246
+ const scrollToId = useCallback((id: string) => {
247
+ const el = scrollRef.current?.querySelector<HTMLElement>(
248
+ `[data-row-id="${CSS.escape(id)}"]`,
249
+ );
250
+ el?.scrollIntoView({ block: "nearest", behavior: "smooth" });
251
+ }, []);
252
+
253
+ // ---- DnD ----
254
+ const { dragIds, dropTarget, getRowDragHandlers } = useTreeFolderDnD({
255
+ data,
256
+ rowsById,
257
+ scrollContainerRef: scrollRef,
258
+ enabled: dndEnabled,
259
+ onMove: handleMoveInternal,
260
+ canDrop: ({ parentId }) => {
261
+ // Honor per-node `droppable: false` on the resolved parent.
262
+ if (parentId == null) return true;
263
+ const target = findNode(data, parentId);
264
+ if (!target) return false;
265
+ if (target.disabled || target.droppable === false) return false;
266
+ return true;
267
+ },
268
+ });
269
+ const dragIdSet = useMemo(() => new Set(dragIds), [dragIds]);
270
+
271
+ // ---- Imperative handle ----
272
+ useImperativeHandle(
273
+ ref,
274
+ () => ({
275
+ selectId: (id: string | null) => {
276
+ if (!isSelectionControlled) setInternalSelected(id);
277
+ onSelectionChange?.(id);
278
+ if (id) scrollToId(id);
279
+ },
280
+ expandAll: () => {
281
+ const all = collectIds(data);
282
+ if (!isExpansionControlled) setInternalExpanded(all);
283
+ onExpandedChange?.(all);
284
+ },
285
+ collapseAll: () => {
286
+ if (!isExpansionControlled) setInternalExpanded([]);
287
+ onExpandedChange?.([]);
288
+ },
289
+ scrollToId,
290
+ }),
291
+ [
292
+ data,
293
+ isSelectionControlled,
294
+ isExpansionControlled,
295
+ onSelectionChange,
296
+ onExpandedChange,
297
+ scrollToId,
298
+ ],
299
+ );
300
+
301
+ const isEmpty = data.length === 0;
302
+ const stripStyle = contentMinWidth
303
+ ? { minWidth: contentMinWidth }
304
+ : undefined;
305
+
306
+ return (
307
+ <div
308
+ data-theme={theme}
309
+ className={cn(
310
+ "flex h-full w-full flex-col bg-background-presentation-body-overlay-primary text-content-presentation-global-primary",
311
+ className,
312
+ )}
313
+ >
314
+ {showHeader && (
315
+ <div className="px-3 py-2 border-b border-border-presentation-global-primary flex items-center justify-between gap-2 shrink-0">
316
+ <span className="text-xs font-semibold text-content-presentation-global-secondary uppercase tracking-wide truncate">
317
+ {title}
318
+ </span>
319
+ {headerAccessory}
320
+ </div>
321
+ )}
322
+
323
+ {showBreadcrumb && (
324
+ <div className="border-b border-border-presentation-global-primary shrink-0">
325
+ <TreeFolderBreadcrumb
326
+ items={breadcrumbItems}
327
+ onSelect={(id) => {
328
+ handleSelect(id);
329
+ scrollToId(id);
330
+ }}
331
+ />
332
+ </div>
333
+ )}
334
+
335
+ <TreeFolderStyles />
336
+ <div
337
+ ref={scrollRef}
338
+ role="tree"
339
+ className="tf-scroll flex-1 min-h-0 overflow-auto"
340
+ >
341
+ {isEmpty ? (
342
+ (emptyState ?? (
343
+ <div className="text-xs text-content-presentation-global-tertiary p-3">
344
+ Nothing here yet.
345
+ </div>
346
+ ))
347
+ ) : (
348
+ <div className="min-w-max" style={stripStyle}>
349
+ {visibleRows.map((row, idx) => {
350
+ const prevRow = visibleRows[idx - 1];
351
+ const nextRow = visibleRows[idx + 1];
352
+ const isSelected = selectedId === row.node.id;
353
+ const isDescendant =
354
+ isDescendantOfSelected(row.node.id) && !isSelected;
355
+ const inBand = isSelected || isDescendant;
356
+
357
+ // Neighbour-aware band rounding: a row is "in-band" if it's the selected
358
+ // node itself or one of its descendants. The Set lookup handles deep nesting.
359
+ const prevInBand =
360
+ inBand &&
361
+ !!prevRow &&
362
+ (prevRow.node.id === selectedId ||
363
+ descendantIdSet.has(prevRow.node.id));
364
+ const nextInBand =
365
+ inBand &&
366
+ !!nextRow &&
367
+ (nextRow.node.id === selectedId ||
368
+ descendantIdSet.has(nextRow.node.id));
369
+
370
+ const isDragging = dragIdSet.has(row.node.id);
371
+ const isDropTargetInside =
372
+ dropTarget?.rowId === row.node.id &&
373
+ dropTarget.position === "inside";
374
+ const isDropBefore =
375
+ dropTarget?.rowId === row.node.id &&
376
+ dropTarget.position === "before";
377
+ const isDropAfter =
378
+ dropTarget?.rowId === row.node.id &&
379
+ dropTarget.position === "after";
380
+
381
+ return (
382
+ <TreeFolderRow
383
+ key={row.node.id}
384
+ row={row}
385
+ rowHeight={rowHeight}
386
+ indent={indent}
387
+ iconFor={iconFor}
388
+ isSelected={isSelected}
389
+ isAncestor={isAncestorFn(row.node.id) && !isSelected}
390
+ isDescendantOfSelected={isDescendant}
391
+ isPrevInBand={prevInBand}
392
+ isNextInBand={nextInBand}
393
+ isDragging={isDragging}
394
+ isDropTargetInside={isDropTargetInside}
395
+ isDropBefore={isDropBefore}
396
+ isDropAfter={isDropAfter}
397
+ dndEnabled={dndEnabled}
398
+ onSelect={handleSelect}
399
+ onToggle={handleToggle}
400
+ dragHandlers={getRowDragHandlers(row.node.id)}
401
+ />
402
+ );
403
+ })}
404
+ </div>
405
+ )}
406
+ </div>
407
+ </div>
408
+ );
409
+ },
410
+ );
@@ -0,0 +1,80 @@
1
+ "use client"
2
+
3
+ import { ChevronRight } from "lucide-react"
4
+ import { cn } from "../../utils/cn"
5
+ import type { TreeFolderBreadcrumb as BreadcrumbItems } from "./types"
6
+
7
+ type Props = {
8
+ items: BreadcrumbItems
9
+ onSelect?: (id: string) => void
10
+ className?: string
11
+ maxItems?: number
12
+ }
13
+
14
+ export function TreeFolderBreadcrumb({
15
+ items,
16
+ onSelect,
17
+ className,
18
+ maxItems = 4,
19
+ }: Props) {
20
+ if (items.length === 0) {
21
+ return (
22
+ <div
23
+ className={cn(
24
+ "px-3 py-1.5 text-xs text-content-presentation-global-tertiary truncate",
25
+ className,
26
+ )}
27
+ >
28
+ No selection
29
+ </div>
30
+ )
31
+ }
32
+
33
+ const display =
34
+ items.length > maxItems
35
+ ? [items[0], { id: "__ellipsis", name: "…" }, ...items.slice(-(maxItems - 2))]
36
+ : items
37
+
38
+ return (
39
+ <nav
40
+ aria-label="Tree path"
41
+ className={cn(
42
+ "px-3 py-1.5 flex items-center gap-1 text-xs text-content-presentation-global-secondary min-w-0",
43
+ className,
44
+ )}
45
+ >
46
+ <ol className="flex items-center gap-1 min-w-0 flex-1">
47
+ {display.map((item, idx) => {
48
+ const isLast = idx === display.length - 1
49
+ const isEllipsis = item.id === "__ellipsis"
50
+ return (
51
+ <li key={`${item.id}-${idx}`} className="flex items-center gap-1 min-w-0">
52
+ {idx > 0 && (
53
+ <ChevronRight className="w-3 h-3 shrink-0 text-content-presentation-global-tertiary" />
54
+ )}
55
+ {isEllipsis ? (
56
+ <span className="text-content-presentation-global-tertiary">…</span>
57
+ ) : isLast ? (
58
+ <span
59
+ className="truncate text-content-presentation-global-primary font-medium"
60
+ title={item.name}
61
+ >
62
+ {item.name}
63
+ </span>
64
+ ) : (
65
+ <button
66
+ type="button"
67
+ onClick={() => onSelect?.(item.id)}
68
+ className="truncate hover:text-content-presentation-global-primary"
69
+ title={item.name}
70
+ >
71
+ {item.name}
72
+ </button>
73
+ )}
74
+ </li>
75
+ )
76
+ })}
77
+ </ol>
78
+ </nav>
79
+ )
80
+ }