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.
- package/apps/lib/components/Avatar.tsx +1 -1
- package/apps/lib/components/BadgeField.tsx +2 -2
- package/apps/lib/components/Card.tsx +68 -54
- package/apps/lib/components/DataViews/ARCHITECTURE.md +439 -0
- package/apps/lib/components/DataViews/DataViewRadio.tsx +47 -0
- package/apps/lib/components/DataViews/DataViewsConfigPanel.tsx +427 -0
- package/apps/lib/components/DataViews/DataViewsHeader.tsx +228 -0
- package/apps/lib/components/DataViews/DataViewsLayout.tsx +330 -0
- package/apps/lib/components/DataViews/FilterPanel.tsx +469 -0
- package/apps/lib/components/DataViews/HeaderSearch.tsx +97 -0
- package/apps/lib/components/DataViews/InboxView.tsx +495 -0
- package/apps/lib/components/DataViews/InboxViewCard.tsx +136 -0
- package/apps/lib/components/DataViews/KanbanView.tsx +353 -0
- package/apps/lib/components/DataViews/PanelControls.tsx +49 -0
- package/apps/lib/components/DataViews/SettingsPanel.tsx +285 -0
- package/apps/lib/components/DataViews/TableView.tsx +232 -0
- package/apps/lib/components/DataViews/TreeView.tsx +392 -0
- package/apps/lib/components/DataViews/badgeAdapter.ts +45 -0
- package/apps/lib/components/DataViews/fieldRenderers.tsx +334 -0
- package/apps/lib/components/DataViews/filters/DateRangePopover.tsx +113 -0
- package/apps/lib/components/DataViews/filters/PresetChips.tsx +45 -0
- package/apps/lib/components/DataViews/filters/RangeSliderWithInputs.tsx +154 -0
- package/apps/lib/components/DataViews/index.ts +36 -0
- package/apps/lib/components/DataViews/tree/TreeDrawer.tsx +54 -0
- package/apps/lib/components/DataViews/tree/TreeSidebar.tsx +77 -0
- package/apps/lib/components/DataViews/types.ts +206 -0
- package/apps/lib/components/Radio.tsx +18 -21
- package/apps/lib/components/Switch.tsx +3 -1
- package/apps/lib/components/Table.tsx +1 -1
- package/apps/lib/components/TreeFolder/TreeFolder.tsx +410 -0
- package/apps/lib/components/TreeFolder/TreeFolderBreadcrumb.tsx +80 -0
- package/apps/lib/components/TreeFolder/TreeFolderRow.tsx +363 -0
- package/apps/lib/components/TreeFolder/TreeFolderStyles.tsx +60 -0
- package/apps/lib/components/TreeFolder/icons.tsx +63 -0
- package/apps/lib/components/TreeFolder/index.ts +17 -0
- package/apps/lib/components/TreeFolder/treeFolderUtils.ts +114 -0
- package/apps/lib/components/TreeFolder/types.ts +77 -0
- package/apps/lib/components/TreeFolder/useTreeFolderDnD.ts +261 -0
- package/apps/lib/hooks/useDataViewsState.ts +169 -0
- package/apps/lib/hooks/useIsMobile.ts +21 -0
- package/apps/lib/layouts/DataViewCard.tsx +76 -0
- package/apps/lib/utils/dataViews/columnUtils.ts +130 -0
- package/apps/lib/utils/dataViews/fieldUtils.ts +198 -0
- package/apps/lib/utils/dataViews/nestedDataUtils.tsx +364 -0
- package/apps/lib/utils/dataViews/pathUtils.ts +132 -0
- package/apps/lib/utils/dataViews/rangeUtils.ts +225 -0
- package/apps/lib/utils/dataViews/treeUtils.ts +403 -0
- package/dist/bin/index.js +3 -3
- package/dist/bin/index.js.map +1 -1
- package/dist/src/commands/add.d.ts.map +1 -1
- package/dist/src/commands/add.js +29 -6
- package/dist/src/commands/add.js.map +1 -1
- package/dist/src/commands/utils.d.ts.map +1 -1
- package/dist/src/commands/utils.js +22 -2
- package/dist/src/commands/utils.js.map +1 -1
- package/dist/src/shared/copyComponentsRecursively.d.ts.map +1 -1
- package/dist/src/shared/copyComponentsRecursively.js +17 -2
- package/dist/src/shared/copyComponentsRecursively.js.map +1 -1
- package/dist/src/shared/getDependenciesAndInstallNestedComponents.d.ts +18 -4
- package/dist/src/shared/getDependenciesAndInstallNestedComponents.d.ts.map +1 -1
- package/dist/src/shared/getDependenciesAndInstallNestedComponents.js +110 -40
- package/dist/src/shared/getDependenciesAndInstallNestedComponents.js.map +1 -1
- package/docs/components/data-views-config-panel.md +204 -0
- package/docs/components/data-views-layout.md +270 -0
- package/docs/components/form-stepper.md +244 -0
- package/docs/components/stepper.md +215 -0
- package/docs/components/timeline.md +248 -0
- package/package.json +6 -6
- package/apps/lib/components/Charts-dev.tsx +0 -365
- package/apps/lib/components/Command-dev.tsx +0 -151
- package/apps/lib/components/IosDatePicker-dev.tsx +0 -341
- /package/docs/components/{labeled-checkbox.md → labeled-check-box.md} +0 -0
- /package/docs/components/{tree-dropdown.md → tree-drop-down.md} +0 -0
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useMemo, useState } from "react";
|
|
4
|
+
import { FilterPanel } from "./FilterPanel";
|
|
5
|
+
import type {
|
|
6
|
+
DynamicRecord,
|
|
7
|
+
ViewConfig,
|
|
8
|
+
DynamicColumnConfig,
|
|
9
|
+
DynamicFilterConfig,
|
|
10
|
+
FilterState,
|
|
11
|
+
FilterValue,
|
|
12
|
+
FieldConfig,
|
|
13
|
+
} from "./types";
|
|
14
|
+
import { Card, CardContent, CardHeader } from "../Card";
|
|
15
|
+
import { Checkbox } from "../Checkbox";
|
|
16
|
+
import {
|
|
17
|
+
Table,
|
|
18
|
+
TableHeader,
|
|
19
|
+
TableBody,
|
|
20
|
+
TableHead,
|
|
21
|
+
TableRow,
|
|
22
|
+
TableCell,
|
|
23
|
+
TableCheckbox,
|
|
24
|
+
} from "../Table";
|
|
25
|
+
import {
|
|
26
|
+
getByPath,
|
|
27
|
+
matchesFilterValues,
|
|
28
|
+
} from "../../utils/dataViews/pathUtils";
|
|
29
|
+
import { renderField } from "./fieldRenderers";
|
|
30
|
+
import { visibleFields } from "../../utils/dataViews/fieldUtils";
|
|
31
|
+
import { useIsMobile } from "../../hooks/useIsMobile";
|
|
32
|
+
|
|
33
|
+
export type TableViewProps = {
|
|
34
|
+
data: DynamicRecord[];
|
|
35
|
+
columns?: DynamicColumnConfig[];
|
|
36
|
+
fields: FieldConfig[];
|
|
37
|
+
config: ViewConfig;
|
|
38
|
+
onDataUpdate?: (data: DynamicRecord[]) => void;
|
|
39
|
+
onSortChange?: (sortBy: string, sortOrder: "asc" | "desc") => void;
|
|
40
|
+
filters?: DynamicFilterConfig[];
|
|
41
|
+
filterState?: FilterState;
|
|
42
|
+
onFilterChange?: (filters: FilterState) => void;
|
|
43
|
+
showFilters?: boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
export function TableView({
|
|
47
|
+
data,
|
|
48
|
+
fields,
|
|
49
|
+
config,
|
|
50
|
+
onSortChange,
|
|
51
|
+
filters: filterConfig,
|
|
52
|
+
filterState: externalFilterState,
|
|
53
|
+
onFilterChange,
|
|
54
|
+
showFilters = true,
|
|
55
|
+
}: TableViewProps) {
|
|
56
|
+
const isMobile = useIsMobile();
|
|
57
|
+
const [internalFilters, setInternalFilters] = useState<FilterState>({});
|
|
58
|
+
|
|
59
|
+
const activeFilters = externalFilterState ?? internalFilters;
|
|
60
|
+
|
|
61
|
+
const sortPath = config.sortBy || null;
|
|
62
|
+
const sortDirection: "asc" | "desc" = config.sortOrder ?? "asc";
|
|
63
|
+
|
|
64
|
+
const handleSort = (path: string) => {
|
|
65
|
+
if (!onSortChange) return;
|
|
66
|
+
if (sortPath === path) {
|
|
67
|
+
onSortChange(path, sortDirection === "asc" ? "desc" : "asc");
|
|
68
|
+
} else {
|
|
69
|
+
onSortChange(path, "asc");
|
|
70
|
+
}
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const handleFilterChange = (path: string, value: FilterValue) => {
|
|
74
|
+
const newFilters: FilterState = { ...activeFilters, [path]: value };
|
|
75
|
+
if (onFilterChange) onFilterChange(newFilters);
|
|
76
|
+
else setInternalFilters(newFilters);
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const clearAllFilters = () => {
|
|
80
|
+
if (onFilterChange) onFilterChange({});
|
|
81
|
+
else setInternalFilters({});
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const filteredAndSortedData = useMemo(() => {
|
|
85
|
+
let filtered = data.filter((item) =>
|
|
86
|
+
Object.entries(activeFilters).every(([path, filterValues]) =>
|
|
87
|
+
matchesFilterValues(item, path, filterValues),
|
|
88
|
+
),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
if (sortPath) {
|
|
92
|
+
filtered = [...filtered].sort((a, b) => {
|
|
93
|
+
const aVal = getByPath(a, sortPath);
|
|
94
|
+
const bVal = getByPath(b, sortPath);
|
|
95
|
+
const modifier = sortDirection === "asc" ? 1 : -1;
|
|
96
|
+
|
|
97
|
+
if (aVal == null && bVal == null) return 0;
|
|
98
|
+
if (aVal == null) return 1;
|
|
99
|
+
if (bVal == null) return -1;
|
|
100
|
+
|
|
101
|
+
if (typeof aVal === "string" && typeof bVal === "string") {
|
|
102
|
+
return aVal.localeCompare(bVal) * modifier;
|
|
103
|
+
}
|
|
104
|
+
if (typeof aVal === "number" && typeof bVal === "number") {
|
|
105
|
+
return (aVal - bVal) * modifier;
|
|
106
|
+
}
|
|
107
|
+
return String(aVal).localeCompare(String(bVal)) * modifier;
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return filtered;
|
|
112
|
+
}, [data, activeFilters, sortPath, sortDirection]);
|
|
113
|
+
|
|
114
|
+
const displayFields = useMemo(
|
|
115
|
+
() => visibleFields(fields).sort((a, b) => (a.order ?? 0) - (b.order ?? 0)),
|
|
116
|
+
[fields],
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const filtersEnabled = showFilters && config.showFilters !== false;
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<div className="flex h-full bg-background-presentation-form-base">
|
|
123
|
+
{filtersEnabled && !isMobile && (
|
|
124
|
+
<FilterPanel
|
|
125
|
+
data={data}
|
|
126
|
+
fields={fields}
|
|
127
|
+
filters={activeFilters}
|
|
128
|
+
onFilterChange={handleFilterChange}
|
|
129
|
+
onClearAll={clearAllFilters}
|
|
130
|
+
filterConfig={filterConfig}
|
|
131
|
+
/>
|
|
132
|
+
)}
|
|
133
|
+
|
|
134
|
+
<div className="flex flex-1 flex-col gap-4 overflow-hidden">
|
|
135
|
+
{!isMobile ? (
|
|
136
|
+
<div className="flex-1 overflow-auto rounded-lg">
|
|
137
|
+
<Table className="w-full">
|
|
138
|
+
<TableHeader>
|
|
139
|
+
<TableRow>
|
|
140
|
+
<TableHead isDummy className="w-12">
|
|
141
|
+
<Checkbox />
|
|
142
|
+
</TableHead>
|
|
143
|
+
{displayFields.map((field) => (
|
|
144
|
+
<TableHead
|
|
145
|
+
key={field.path}
|
|
146
|
+
size="M"
|
|
147
|
+
sortType={
|
|
148
|
+
sortPath === field.path ? sortDirection : undefined
|
|
149
|
+
}
|
|
150
|
+
onSort={() => handleSort(field.path)}
|
|
151
|
+
>
|
|
152
|
+
{field.label}
|
|
153
|
+
</TableHead>
|
|
154
|
+
))}
|
|
155
|
+
</TableRow>
|
|
156
|
+
</TableHeader>
|
|
157
|
+
<TableBody>
|
|
158
|
+
{filteredAndSortedData.map((item, idx) => (
|
|
159
|
+
<TableRow key={item.id ?? idx}>
|
|
160
|
+
<TableCell isDummy className="w-12">
|
|
161
|
+
<TableCheckbox id={`row-${item.id ?? idx}`} />
|
|
162
|
+
</TableCell>
|
|
163
|
+
{displayFields.map((field) => (
|
|
164
|
+
<TableCell key={field.path}>
|
|
165
|
+
{/* `isolate` confines the Badge's mix-blend-luminosity
|
|
166
|
+
to a local stacking context and `transform-gpu`
|
|
167
|
+
promotes it to its own layer, so the table's
|
|
168
|
+
post-mount column reflow repaints cleanly instead
|
|
169
|
+
of leaving a ghosted/doubled badge frame. */}
|
|
170
|
+
<span className="isolate inline-flex transform-gpu">
|
|
171
|
+
{renderField(
|
|
172
|
+
getByPath(item, field.path),
|
|
173
|
+
field,
|
|
174
|
+
item,
|
|
175
|
+
)}
|
|
176
|
+
</span>
|
|
177
|
+
</TableCell>
|
|
178
|
+
))}
|
|
179
|
+
</TableRow>
|
|
180
|
+
))}
|
|
181
|
+
</TableBody>
|
|
182
|
+
</Table>
|
|
183
|
+
</div>
|
|
184
|
+
) : (
|
|
185
|
+
<div className="flex-1 overflow-auto">
|
|
186
|
+
<div className="grid gap-3">
|
|
187
|
+
{filteredAndSortedData.map((item, idx) => (
|
|
188
|
+
<Card key={item.id ?? idx} className="overflow-hidden">
|
|
189
|
+
<CardHeader className="pb-3">
|
|
190
|
+
<div className="flex items-start justify-between gap-3">
|
|
191
|
+
<div className="flex items-start gap-3 flex-1">
|
|
192
|
+
<Checkbox className="mt-1" />
|
|
193
|
+
<div className="flex-1">
|
|
194
|
+
{displayFields[0] && (
|
|
195
|
+
<p className="font-medium">
|
|
196
|
+
{String(
|
|
197
|
+
getByPath(item, displayFields[0].path) ?? "",
|
|
198
|
+
)}
|
|
199
|
+
</p>
|
|
200
|
+
)}
|
|
201
|
+
</div>
|
|
202
|
+
</div>
|
|
203
|
+
</div>
|
|
204
|
+
</CardHeader>
|
|
205
|
+
<CardContent className="space-y-2 pt-0">
|
|
206
|
+
{displayFields.slice(1).map((field) => (
|
|
207
|
+
<div
|
|
208
|
+
key={field.path}
|
|
209
|
+
className="flex items-center justify-between text-sm"
|
|
210
|
+
>
|
|
211
|
+
<span className="text-content-presentation-global-tertiary">
|
|
212
|
+
{field.label}:
|
|
213
|
+
</span>
|
|
214
|
+
<span>
|
|
215
|
+
{renderField(
|
|
216
|
+
getByPath(item, field.path),
|
|
217
|
+
field,
|
|
218
|
+
item,
|
|
219
|
+
)}
|
|
220
|
+
</span>
|
|
221
|
+
</div>
|
|
222
|
+
))}
|
|
223
|
+
</CardContent>
|
|
224
|
+
</Card>
|
|
225
|
+
))}
|
|
226
|
+
</div>
|
|
227
|
+
</div>
|
|
228
|
+
)}
|
|
229
|
+
</div>
|
|
230
|
+
</div>
|
|
231
|
+
);
|
|
232
|
+
}
|
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useMemo, useState } from "react";
|
|
4
|
+
import type {
|
|
5
|
+
DynamicRecord,
|
|
6
|
+
ViewConfig,
|
|
7
|
+
DynamicColumnConfig,
|
|
8
|
+
DynamicFilterConfig,
|
|
9
|
+
FieldConfig,
|
|
10
|
+
FilterState,
|
|
11
|
+
FilterValue,
|
|
12
|
+
TreeConfig,
|
|
13
|
+
} from "./types";
|
|
14
|
+
import {
|
|
15
|
+
applyMove,
|
|
16
|
+
autoDetectTreeShape,
|
|
17
|
+
buildTree,
|
|
18
|
+
findNodeById,
|
|
19
|
+
flatten,
|
|
20
|
+
initialExpansion,
|
|
21
|
+
pruneTree,
|
|
22
|
+
type TreeNode,
|
|
23
|
+
} from "../../utils/dataViews/treeUtils";
|
|
24
|
+
import {
|
|
25
|
+
getByPath,
|
|
26
|
+
matchesFilterValues,
|
|
27
|
+
} from "../../utils/dataViews/pathUtils";
|
|
28
|
+
import { visibleFields } from "../../utils/dataViews/fieldUtils";
|
|
29
|
+
import { renderField } from "./fieldRenderers";
|
|
30
|
+
import { useIsMobile } from "../../hooks/useIsMobile";
|
|
31
|
+
import { TableView } from "./TableView";
|
|
32
|
+
import { FilterPanel } from "./FilterPanel";
|
|
33
|
+
import { TreeSidebar } from "./tree/TreeSidebar";
|
|
34
|
+
import { TreeDrawer, TreeDrawerTrigger } from "./tree/TreeDrawer";
|
|
35
|
+
import { Card, CardContent, CardHeader } from "../Card";
|
|
36
|
+
import { Table2, LayoutGrid } from "lucide-react";
|
|
37
|
+
import { cn } from "../../utils/cn";
|
|
38
|
+
|
|
39
|
+
export type TreeViewProps = {
|
|
40
|
+
data: DynamicRecord[];
|
|
41
|
+
columns?: DynamicColumnConfig[];
|
|
42
|
+
fields: FieldConfig[];
|
|
43
|
+
config: ViewConfig;
|
|
44
|
+
treeConfig?: TreeConfig;
|
|
45
|
+
onDataUpdate?: (data: DynamicRecord[]) => void;
|
|
46
|
+
filters?: DynamicFilterConfig[];
|
|
47
|
+
filterState?: FilterState;
|
|
48
|
+
onFilterChange?: (filters: FilterState) => void;
|
|
49
|
+
showFilters?: boolean;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export function TreeView({
|
|
53
|
+
data,
|
|
54
|
+
columns,
|
|
55
|
+
fields,
|
|
56
|
+
config,
|
|
57
|
+
treeConfig,
|
|
58
|
+
onDataUpdate,
|
|
59
|
+
filters: filterConfig,
|
|
60
|
+
filterState: externalFilterState,
|
|
61
|
+
onFilterChange,
|
|
62
|
+
showFilters = true,
|
|
63
|
+
}: TreeViewProps) {
|
|
64
|
+
const isMobile = useIsMobile();
|
|
65
|
+
const [internalFilters, setInternalFilters] = useState<FilterState>({});
|
|
66
|
+
const activeFilters = externalFilterState ?? internalFilters;
|
|
67
|
+
|
|
68
|
+
const resolvedTree = useMemo(
|
|
69
|
+
() => autoDetectTreeShape(data, treeConfig ?? {}),
|
|
70
|
+
[data, treeConfig],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const display = useMemo(
|
|
74
|
+
() => visibleFields(fields).sort((a, b) => (a.order ?? 0) - (b.order ?? 0)),
|
|
75
|
+
[fields],
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
const labelField: FieldConfig = useMemo(() => {
|
|
79
|
+
const path = resolvedTree.nodeLabel;
|
|
80
|
+
if (path) {
|
|
81
|
+
const f = fields.find((x) => x.path === path);
|
|
82
|
+
if (f) return f;
|
|
83
|
+
return { path, label: path, type: "text" };
|
|
84
|
+
}
|
|
85
|
+
return display[0] ?? { path: resolvedTree.idField, type: "text" };
|
|
86
|
+
}, [resolvedTree, fields, display]);
|
|
87
|
+
|
|
88
|
+
const fullForest = useMemo(
|
|
89
|
+
() => buildTree(data, resolvedTree),
|
|
90
|
+
[data, resolvedTree],
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const filterEntries = useMemo(
|
|
94
|
+
() => Object.entries(activeFilters),
|
|
95
|
+
[activeFilters],
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
const visibleForest: TreeNode[] = useMemo(() => {
|
|
99
|
+
if (filterEntries.length === 0) return fullForest;
|
|
100
|
+
return pruneTree(fullForest, (record) =>
|
|
101
|
+
filterEntries.every(([path, value]) =>
|
|
102
|
+
matchesFilterValues(record, path, value),
|
|
103
|
+
),
|
|
104
|
+
);
|
|
105
|
+
}, [fullForest, filterEntries]);
|
|
106
|
+
|
|
107
|
+
const [expanded, setExpanded] = useState<Set<string>>(() =>
|
|
108
|
+
initialExpansion(fullForest, resolvedTree.defaultExpanded),
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
setExpanded(initialExpansion(fullForest, resolvedTree.defaultExpanded));
|
|
113
|
+
}, [fullForest, resolvedTree.defaultExpanded]);
|
|
114
|
+
|
|
115
|
+
const [selectedId, setSelectedId] = useState<string | null>(
|
|
116
|
+
() => fullForest[0]?.id ?? null,
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
if (selectedId && !findNodeById(visibleForest, selectedId)) {
|
|
121
|
+
setSelectedId(visibleForest[0]?.id ?? null);
|
|
122
|
+
}
|
|
123
|
+
}, [visibleForest, selectedId]);
|
|
124
|
+
|
|
125
|
+
const selectedNode = selectedId
|
|
126
|
+
? findNodeById(visibleForest, selectedId)
|
|
127
|
+
: null;
|
|
128
|
+
const recordsForRightPane = useMemo(
|
|
129
|
+
() => (selectedNode ? flatten(selectedNode) : []),
|
|
130
|
+
[selectedNode],
|
|
131
|
+
);
|
|
132
|
+
|
|
133
|
+
const toggle = (id: string) =>
|
|
134
|
+
setExpanded((prev) => {
|
|
135
|
+
const next = new Set(prev);
|
|
136
|
+
if (next.has(id)) next.delete(id);
|
|
137
|
+
else next.add(id);
|
|
138
|
+
return next;
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
const handleFilterChange = (path: string, value: FilterValue) => {
|
|
142
|
+
const next: FilterState = { ...activeFilters, [path]: value };
|
|
143
|
+
if (onFilterChange) onFilterChange(next);
|
|
144
|
+
else setInternalFilters(next);
|
|
145
|
+
};
|
|
146
|
+
const clearAllFilters = () => {
|
|
147
|
+
if (onFilterChange) onFilterChange({});
|
|
148
|
+
else setInternalFilters({});
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
const [drawerOpen, setDrawerOpen] = useState(false);
|
|
152
|
+
|
|
153
|
+
type RightPaneMode = "table" | "card";
|
|
154
|
+
const [rightPaneMode, setRightPaneMode] = useState<RightPaneMode>(
|
|
155
|
+
// "details" is a deprecated alias of "card".
|
|
156
|
+
treeConfig?.defaultRightPane === "details"
|
|
157
|
+
? "card"
|
|
158
|
+
: (treeConfig?.defaultRightPane ?? "table"),
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const dndEnabled = treeConfig?.dndEnabled !== false && !!onDataUpdate;
|
|
162
|
+
|
|
163
|
+
const handleMove = ({
|
|
164
|
+
dragIds,
|
|
165
|
+
parentId,
|
|
166
|
+
index,
|
|
167
|
+
}: {
|
|
168
|
+
dragIds: string[];
|
|
169
|
+
parentId: string | null;
|
|
170
|
+
index: number;
|
|
171
|
+
}) => {
|
|
172
|
+
if (!onDataUpdate) return;
|
|
173
|
+
const next = applyMove(data, resolvedTree, { dragIds, parentId, index });
|
|
174
|
+
onDataUpdate(next);
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const treeContent = (
|
|
178
|
+
<TreeSidebar
|
|
179
|
+
roots={visibleForest}
|
|
180
|
+
expanded={expanded}
|
|
181
|
+
selectedId={selectedId}
|
|
182
|
+
labelField={labelField}
|
|
183
|
+
dndEnabled={dndEnabled}
|
|
184
|
+
onToggle={toggle}
|
|
185
|
+
onSelect={(id) => {
|
|
186
|
+
setSelectedId(id);
|
|
187
|
+
if (isMobile) setDrawerOpen(false);
|
|
188
|
+
}}
|
|
189
|
+
onMove={handleMove}
|
|
190
|
+
/>
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
const filtersEnabled = showFilters && config.showFilters !== false;
|
|
194
|
+
|
|
195
|
+
return (
|
|
196
|
+
<div className="flex h-full gap-2">
|
|
197
|
+
{!isMobile && (
|
|
198
|
+
<div className="w-64 rounded-[16px] border border-border-presentation-global-primary bg-background-presentation-form-base overflow-hidden flex flex-col">
|
|
199
|
+
<div className="px-3 py-2 border-b border-border-presentation-global-primary">
|
|
200
|
+
<span
|
|
201
|
+
style={{ fontFeatureSettings: "'cv05' on" }}
|
|
202
|
+
className="typography-display-medium-medium uppercase text-content-presentation-global-primary"
|
|
203
|
+
>
|
|
204
|
+
categories
|
|
205
|
+
</span>
|
|
206
|
+
</div>
|
|
207
|
+
<div className="flex-1 overflow-hidden">{treeContent}</div>
|
|
208
|
+
</div>
|
|
209
|
+
)}
|
|
210
|
+
|
|
211
|
+
{!isMobile && filtersEnabled && (
|
|
212
|
+
<FilterPanel
|
|
213
|
+
data={data}
|
|
214
|
+
fields={fields}
|
|
215
|
+
filters={activeFilters}
|
|
216
|
+
onFilterChange={handleFilterChange}
|
|
217
|
+
onClearAll={clearAllFilters}
|
|
218
|
+
filterConfig={filterConfig}
|
|
219
|
+
/>
|
|
220
|
+
)}
|
|
221
|
+
|
|
222
|
+
<div className="flex-1 flex flex-col overflow-hidden rounded-[16px] border border-border-presentation-global-primary bg-background-presentation-form-base">
|
|
223
|
+
<div className="flex items-center justify-between gap-2 px-3 py-2 border-b border-border-presentation-global-primary bg-background-presentation-form-base">
|
|
224
|
+
<div className="flex items-center gap-2 min-w-0">
|
|
225
|
+
{isMobile && (
|
|
226
|
+
<TreeDrawerTrigger onClick={() => setDrawerOpen(true)} />
|
|
227
|
+
)}
|
|
228
|
+
<span
|
|
229
|
+
style={{ fontFeatureSettings: "'cv05' on" }}
|
|
230
|
+
className="typography-display-medium-medium uppercase text-content-presentation-global-primary truncate"
|
|
231
|
+
>
|
|
232
|
+
{selectedNode
|
|
233
|
+
? String(getByPath(selectedNode.record, labelField.path) ?? "Items")
|
|
234
|
+
: "Items"}
|
|
235
|
+
</span>
|
|
236
|
+
<div className="h-6 w-px bg-border-presentation-global-primary shrink-0" />
|
|
237
|
+
<span className="text-sm text-content-presentation-global-secondary truncate">
|
|
238
|
+
{selectedNode
|
|
239
|
+
? `${recordsForRightPane.length} record${recordsForRightPane.length === 1 ? "" : "s"}`
|
|
240
|
+
: "Select an item"}
|
|
241
|
+
</span>
|
|
242
|
+
</div>
|
|
243
|
+
|
|
244
|
+
{/* Segmented switcher — same style as the main view switcher
|
|
245
|
+
(DataViewsHeader): #252729 track, white active pill, divider
|
|
246
|
+
between two inactive tabs only. */}
|
|
247
|
+
<div className="flex items-center gap-[2px] rounded-[10px] bg-background-presentation-body-primary p-[2px] shadow-[inset_0_0_4px_0_rgba(0,0,0,0.08)] shrink-0">
|
|
248
|
+
{(
|
|
249
|
+
[
|
|
250
|
+
{ id: "table", label: "List", icon: <Table2 /> },
|
|
251
|
+
{ id: "card", label: "Cards", icon: <LayoutGrid /> },
|
|
252
|
+
] as const
|
|
253
|
+
).map((tab, idx) => {
|
|
254
|
+
const active = rightPaneMode === tab.id;
|
|
255
|
+
const prevActive = idx > 0 && rightPaneMode === "table";
|
|
256
|
+
const showDivider = idx > 0 && !active && !prevActive;
|
|
257
|
+
return (
|
|
258
|
+
<div key={tab.id} className="flex items-center">
|
|
259
|
+
{showDivider && (
|
|
260
|
+
<div className="mx-[3px] h-3 w-px bg-[#434446]" />
|
|
261
|
+
)}
|
|
262
|
+
<button
|
|
263
|
+
type="button"
|
|
264
|
+
aria-label={`${tab.label} mode`}
|
|
265
|
+
aria-pressed={active}
|
|
266
|
+
onClick={() => setRightPaneMode(tab.id)}
|
|
267
|
+
className={cn(
|
|
268
|
+
"flex h-6 items-center gap-[6px] rounded-[8px] px-3 text-[14px] font-[510] leading-none transition-all duration-200 ease-in-out",
|
|
269
|
+
active
|
|
270
|
+
? "bg-white text-black shadow-[0_0_10px_2px_rgba(0,0,0,0.25)]"
|
|
271
|
+
: "bg-transparent text-content-presentation-global-primary hover:bg-white/5",
|
|
272
|
+
)}
|
|
273
|
+
>
|
|
274
|
+
<span className="flex h-[14px] w-[14px] items-center justify-center [&_svg]:h-[14px] [&_svg]:w-[14px]">
|
|
275
|
+
{tab.icon}
|
|
276
|
+
</span>
|
|
277
|
+
<span className="max-w-[80px] truncate">{tab.label}</span>
|
|
278
|
+
</button>
|
|
279
|
+
</div>
|
|
280
|
+
);
|
|
281
|
+
})}
|
|
282
|
+
</div>
|
|
283
|
+
</div>
|
|
284
|
+
|
|
285
|
+
<div className="flex-1 overflow-hidden">
|
|
286
|
+
{selectedNode ? (
|
|
287
|
+
rightPaneMode === "table" ? (
|
|
288
|
+
<TableView
|
|
289
|
+
data={recordsForRightPane}
|
|
290
|
+
columns={columns}
|
|
291
|
+
fields={fields}
|
|
292
|
+
config={{ ...config, showFilters: false }}
|
|
293
|
+
onDataUpdate={onDataUpdate}
|
|
294
|
+
filters={filterConfig}
|
|
295
|
+
filterState={activeFilters}
|
|
296
|
+
onFilterChange={(next) => {
|
|
297
|
+
if (onFilterChange) onFilterChange(next);
|
|
298
|
+
else setInternalFilters(next);
|
|
299
|
+
}}
|
|
300
|
+
showFilters={false}
|
|
301
|
+
/>
|
|
302
|
+
) : (
|
|
303
|
+
<CardGrid
|
|
304
|
+
records={recordsForRightPane}
|
|
305
|
+
fields={fields}
|
|
306
|
+
labelField={labelField}
|
|
307
|
+
/>
|
|
308
|
+
)
|
|
309
|
+
) : (
|
|
310
|
+
<div className="h-full flex items-center justify-center text-sm text-content-presentation-global-tertiary">
|
|
311
|
+
No node selected.
|
|
312
|
+
</div>
|
|
313
|
+
)}
|
|
314
|
+
</div>
|
|
315
|
+
</div>
|
|
316
|
+
|
|
317
|
+
{isMobile && (
|
|
318
|
+
<TreeDrawer open={drawerOpen} onOpenChange={setDrawerOpen}>
|
|
319
|
+
{treeContent}
|
|
320
|
+
</TreeDrawer>
|
|
321
|
+
)}
|
|
322
|
+
</div>
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* Card mode for the Tree right pane: renders the same record set as Table
|
|
328
|
+
* mode, one library <Card> per record. The label field is the card header;
|
|
329
|
+
* the remaining visible fields are key/value rows in the card body.
|
|
330
|
+
*/
|
|
331
|
+
function CardGrid({
|
|
332
|
+
records,
|
|
333
|
+
fields,
|
|
334
|
+
labelField,
|
|
335
|
+
}: {
|
|
336
|
+
records: DynamicRecord[];
|
|
337
|
+
fields: FieldConfig[];
|
|
338
|
+
labelField: FieldConfig;
|
|
339
|
+
}) {
|
|
340
|
+
const bodyFields = visibleFields(fields)
|
|
341
|
+
.filter((f) => f.path !== labelField.path)
|
|
342
|
+
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0));
|
|
343
|
+
|
|
344
|
+
if (records.length === 0) {
|
|
345
|
+
return (
|
|
346
|
+
<div className="h-full flex items-center justify-center text-sm text-content-presentation-global-tertiary">
|
|
347
|
+
No records.
|
|
348
|
+
</div>
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
return (
|
|
353
|
+
<div className="h-full overflow-y-auto p-4 bg-background-presentation-body-primary">
|
|
354
|
+
<div className="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
|
355
|
+
{records.map((record, idx) => {
|
|
356
|
+
const labelValue = getByPath(record, labelField.path);
|
|
357
|
+
return (
|
|
358
|
+
<Card key={record.id ?? idx} className="overflow-hidden">
|
|
359
|
+
<CardHeader className="pb-2">
|
|
360
|
+
<div className="text-xs uppercase tracking-wide text-content-presentation-global-tertiary">
|
|
361
|
+
{labelField.label ?? labelField.path}
|
|
362
|
+
</div>
|
|
363
|
+
<div className="text-base font-semibold text-content-presentation-global-primary">
|
|
364
|
+
{renderField(labelValue, labelField, record)}
|
|
365
|
+
</div>
|
|
366
|
+
</CardHeader>
|
|
367
|
+
<CardContent className="space-y-2 pt-0">
|
|
368
|
+
{bodyFields.map((f) => {
|
|
369
|
+
const value = getByPath(record, f.path);
|
|
370
|
+
if (value == null) return null;
|
|
371
|
+
return (
|
|
372
|
+
<div
|
|
373
|
+
key={f.path}
|
|
374
|
+
className="flex items-center justify-between gap-3 text-sm"
|
|
375
|
+
>
|
|
376
|
+
<span className="text-content-presentation-global-tertiary">
|
|
377
|
+
{f.label ?? f.path}
|
|
378
|
+
</span>
|
|
379
|
+
<span className="text-content-presentation-global-primary text-right">
|
|
380
|
+
{renderField(value, f, record)}
|
|
381
|
+
</span>
|
|
382
|
+
</div>
|
|
383
|
+
);
|
|
384
|
+
})}
|
|
385
|
+
</CardContent>
|
|
386
|
+
</Card>
|
|
387
|
+
);
|
|
388
|
+
})}
|
|
389
|
+
</div>
|
|
390
|
+
</div>
|
|
391
|
+
);
|
|
392
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { BadgeVariant } from "./types"
|
|
2
|
+
|
|
3
|
+
type TorchBadgeColor =
|
|
4
|
+
| "gray"
|
|
5
|
+
| "slate"
|
|
6
|
+
| "red"
|
|
7
|
+
| "orange"
|
|
8
|
+
| "yellow"
|
|
9
|
+
| "green"
|
|
10
|
+
| "ocean"
|
|
11
|
+
| "blue"
|
|
12
|
+
| "purple"
|
|
13
|
+
| "rose"
|
|
14
|
+
|
|
15
|
+
type TorchBadgeStyle = "solid" | "subtle"
|
|
16
|
+
|
|
17
|
+
export type ResolvedBadgeProps = {
|
|
18
|
+
color: TorchBadgeColor
|
|
19
|
+
badgeStyle: TorchBadgeStyle
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Map the dataviews BadgeVariant set to torch-glare Badge props.
|
|
24
|
+
* Defaults to `subtle` style (glare's native default — colored dot + subtle bg).
|
|
25
|
+
* The legacy "Light" / "navy" / "bluePurple" variants explicitly request solid
|
|
26
|
+
* fills, kept distinct for backwards compat with the data-views examples.
|
|
27
|
+
*/
|
|
28
|
+
export function resolveBadgeVariant(variant?: BadgeVariant): ResolvedBadgeProps {
|
|
29
|
+
switch (variant) {
|
|
30
|
+
case "green": return { color: "green", badgeStyle: "subtle" }
|
|
31
|
+
case "greenLight": return { color: "green", badgeStyle: "subtle" }
|
|
32
|
+
case "cocktailGreen": return { color: "green", badgeStyle: "solid" }
|
|
33
|
+
case "yellow": return { color: "yellow", badgeStyle: "subtle" }
|
|
34
|
+
case "redOrange": return { color: "orange", badgeStyle: "subtle" }
|
|
35
|
+
case "redLight": return { color: "red", badgeStyle: "subtle" }
|
|
36
|
+
case "rose": return { color: "rose", badgeStyle: "subtle" }
|
|
37
|
+
case "purple": return { color: "purple", badgeStyle: "subtle" }
|
|
38
|
+
case "bluePurple": return { color: "purple", badgeStyle: "solid" }
|
|
39
|
+
case "blue": return { color: "blue", badgeStyle: "subtle" }
|
|
40
|
+
case "navy": return { color: "blue", badgeStyle: "solid" }
|
|
41
|
+
case "highlight": return { color: "yellow", badgeStyle: "subtle" }
|
|
42
|
+
case "gray":
|
|
43
|
+
default: return { color: "gray", badgeStyle: "subtle" }
|
|
44
|
+
}
|
|
45
|
+
}
|