torch-glare 2.4.4 → 2.5.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.
- package/apps/lib/components/DataViews/{badgeAdapter.ts → badge.ts} +2 -2
- package/apps/lib/components/DataViews/cell.tsx +324 -0
- package/apps/lib/components/DataViews/context.ts +144 -0
- package/apps/lib/components/DataViews/data-views.tsx +383 -0
- package/apps/lib/components/DataViews/filters/children.tsx +98 -0
- package/apps/lib/components/DataViews/filters/custom.tsx +34 -0
- package/apps/lib/components/DataViews/filters/filters.tsx +163 -0
- package/apps/lib/components/DataViews/filters/index.ts +4 -0
- package/apps/lib/components/DataViews/filters/labelled.tsx +20 -0
- package/apps/lib/components/DataViews/filters/presets.tsx +65 -0
- package/apps/lib/components/DataViews/filters/summary.tsx +65 -0
- package/apps/lib/components/DataViews/filters/sync.tsx +35 -0
- package/apps/lib/components/DataViews/filters/values.ts +173 -0
- package/apps/lib/components/DataViews/header.tsx +217 -0
- package/apps/lib/components/DataViews/hooks/index.ts +5 -0
- package/apps/lib/components/DataViews/hooks/useActiveRow.ts +22 -0
- package/apps/lib/components/DataViews/hooks/useControllable.ts +52 -0
- package/apps/lib/components/DataViews/index.ts +74 -26
- package/apps/lib/components/DataViews/panel/columns.tsx +153 -0
- package/apps/lib/components/DataViews/panel/controls.tsx +106 -0
- package/apps/lib/components/DataViews/panel/index.ts +3 -0
- package/apps/lib/components/DataViews/panel/panel.tsx +164 -0
- package/apps/lib/components/DataViews/panel/saved-views.tsx +67 -0
- package/apps/lib/components/DataViews/panel/section.tsx +79 -0
- package/apps/lib/components/DataViews/panel/sort.tsx +42 -0
- package/apps/lib/components/DataViews/panel/tab.tsx +31 -0
- package/apps/lib/components/DataViews/slots.ts +63 -0
- package/apps/lib/components/DataViews/states.tsx +38 -0
- package/apps/lib/components/DataViews/types.ts +485 -178
- package/apps/lib/components/DataViews/views/board-view.tsx +379 -0
- package/apps/lib/components/DataViews/views/card-rows.tsx +36 -0
- package/apps/lib/components/DataViews/views/inbox-view.tsx +257 -0
- package/apps/lib/components/DataViews/views/pane-views.tsx +192 -0
- package/apps/lib/components/DataViews/views/table-view.tsx +426 -0
- package/apps/lib/components/DataViews/views/tree-view.tsx +365 -0
- package/apps/lib/components/FormBuilder/context.ts +20 -6
- package/apps/lib/components/FormBuilder/field-kind.ts +28 -0
- package/apps/lib/components/FormBuilder/fields/DateField.tsx +3 -3
- package/apps/lib/components/FormBuilder/fields/FieldShell.tsx +7 -6
- package/apps/lib/components/FormBuilder/fields/PhoneField.tsx +30 -4
- package/apps/lib/components/FormBuilder/fields/SelectField.tsx +7 -7
- package/apps/lib/components/FormBuilder/fields/TableField.tsx +80 -52
- package/apps/lib/components/FormBuilder/fields/TextField.tsx +9 -9
- package/apps/lib/components/FormBuilder/form-builder.tsx +66 -6
- package/apps/lib/components/FormBuilder/index.ts +3 -1
- package/apps/lib/components/FormBuilder/types.ts +40 -0
- package/apps/lib/components/Input.tsx +3 -0
- package/apps/lib/components/SearchableTable.tsx +5 -4
- package/apps/lib/components/SectionBlock.tsx +58 -11
- package/apps/lib/components/Select.tsx +3 -1
- package/apps/lib/components/TabSwitch.tsx +16 -4
- package/apps/lib/components/Table.tsx +265 -67
- package/apps/lib/components/TreeFolder/TreeFolder.tsx +6 -3
- package/apps/lib/components/TreeFolder/TreeFolderRow.tsx +16 -14
- package/apps/lib/components/TreeFolder/index.ts +1 -1
- package/apps/lib/components/TreeFolder/useTreeFolderDnD.ts +70 -207
- package/apps/lib/hooks/useDragDrop.tsx +365 -0
- package/apps/lib/hooks/useInfiniteScroll.ts +108 -0
- package/apps/lib/registry.json +159 -4
- package/apps/lib/tsconfig.tsbuildinfo +1 -1
- package/apps/lib/utils/dataViews/path.ts +67 -0
- package/apps/lib/utils/dataViews/query.ts +73 -0
- package/apps/lib/utils/dataViews/types.ts +187 -0
- package/docs/components/breadcrumb.md +1 -1
- package/docs/components/button-group.md +1 -1
- package/docs/components/button.md +1 -1
- package/docs/components/card.md +1 -1
- package/docs/components/checkbox.md +1 -1
- package/docs/components/data-views/backend-response.md +324 -0
- package/docs/components/data-views/examples/a11y-rtl.md +250 -0
- package/docs/components/data-views/examples/api-orders-route.md +130 -0
- package/docs/components/data-views/examples/fields.md +362 -0
- package/docs/components/data-views/examples/filters.md +308 -0
- package/docs/components/data-views/examples/inbox-routing.md +218 -0
- package/docs/components/data-views/examples/index.md +29 -0
- package/docs/components/data-views/examples/overview.md +244 -0
- package/docs/components/data-views/examples/panel.md +212 -0
- package/docs/components/data-views/examples/scale.md +231 -0
- package/docs/components/data-views/examples/server-side.md +210 -0
- package/docs/components/data-views/examples/state.md +250 -0
- package/docs/components/data-views/examples/tree-custom.md +388 -0
- package/docs/components/data-views/examples/view-registry.md +313 -0
- package/docs/components/data-views/examples/views.md +534 -0
- package/docs/components/data-views/guide.md +405 -0
- package/docs/components/data-views/index.md +1504 -0
- package/docs/components/data-views/migration.md +79 -0
- package/docs/components/date-picker.md +0 -1
- package/docs/components/form-builder.md +19 -8
- package/docs/components/form-renderer.md +2 -1
- package/docs/components/form.md +1 -1
- package/docs/components/input-field.md +1 -1
- package/docs/components/input-otp.md +1 -1
- package/docs/components/input.md +1 -1
- package/docs/components/labeled-check-box.md +1 -1
- package/docs/components/labeled-radio.md +1 -1
- package/docs/components/radio-card.md +1 -1
- package/docs/components/radio.md +1 -1
- package/docs/components/search-field.md +1 -1
- package/docs/components/section-block.md +79 -3
- package/docs/components/select.md +1 -1
- package/docs/components/simple-select.md +1 -1
- package/docs/components/switch.md +1 -1
- package/docs/components/tab-switch.md +1 -1
- package/docs/components/table.md +45 -8
- package/docs/components/text-editor.md +1 -1
- package/docs/components/textarea.md +1 -1
- package/docs/components/toggle-button.md +1 -1
- package/docs/components/toggle.md +1 -1
- package/docs/components/tree-folder.md +110 -0
- package/docs/how-to/forms-with-form-builder.md +6 -4
- package/docs/reference/components.md +16 -6
- package/docs/tutorials/component-composition.md +11 -13
- package/package.json +3 -2
- package/apps/lib/components/DataViews/DataViewRadio.tsx +0 -49
- package/apps/lib/components/DataViews/DataViewsConfigPanel.tsx +0 -393
- package/apps/lib/components/DataViews/DataViewsHeader.tsx +0 -207
- package/apps/lib/components/DataViews/DataViewsLayout.tsx +0 -332
- package/apps/lib/components/DataViews/FilterPanel.tsx +0 -493
- package/apps/lib/components/DataViews/HeaderSearch.tsx +0 -93
- package/apps/lib/components/DataViews/InboxView.tsx +0 -463
- package/apps/lib/components/DataViews/InboxViewCard.tsx +0 -127
- package/apps/lib/components/DataViews/KanbanView.tsx +0 -336
- package/apps/lib/components/DataViews/PanelControls.tsx +0 -39
- package/apps/lib/components/DataViews/SettingsPanel.tsx +0 -279
- package/apps/lib/components/DataViews/TableView.tsx +0 -212
- package/apps/lib/components/DataViews/TreeView.tsx +0 -364
- package/apps/lib/components/DataViews/fieldRenderers.tsx +0 -299
- package/apps/lib/components/DataViews/filters/DatePickerRangeFilter.tsx +0 -87
- package/apps/lib/components/DataViews/filters/DateRangePopover.tsx +0 -120
- package/apps/lib/components/DataViews/filters/PresetChips.tsx +0 -45
- package/apps/lib/components/DataViews/filters/RangeSliderWithInputs.tsx +0 -165
- package/apps/lib/components/DataViews/tree/TreeDrawer.tsx +0 -50
- package/apps/lib/components/DataViews/tree/TreeSidebar.tsx +0 -74
- package/apps/lib/hooks/useDataViewsState.ts +0 -175
- package/apps/lib/utils/dataViews/columnUtils.ts +0 -132
- package/apps/lib/utils/dataViews/fieldUtils.ts +0 -197
- package/apps/lib/utils/dataViews/nestedDataUtils.tsx +0 -371
- package/apps/lib/utils/dataViews/pathUtils.ts +0 -139
- package/apps/lib/utils/dataViews/rangeUtils.ts +0 -234
- package/apps/lib/utils/dataViews/treeUtils.ts +0 -396
- package/docs/components/data-views-config-panel.md +0 -208
- package/docs/components/data-views-layout.md +0 -291
- package/docs/components/inbox-view.md +0 -170
- package/docs/components/kanban-view.md +0 -135
- package/docs/components/table-view.md +0 -141
- package/docs/components/tree-view.md +0 -147
- package/docs/how-to/data-views-from-backend-response.md +0 -194
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, { useMemo } from "react";
|
|
4
|
+
import { cn } from "../../../utils/cn";
|
|
5
|
+
import { getByPath } from "../../../utils/dataViews/path";
|
|
6
|
+
import type { FieldConfig, Row, TreeNode } from "../../../utils/dataViews/types";
|
|
7
|
+
import { TreeFolder, type TreeFolderNode } from "../../TreeFolder";
|
|
8
|
+
import { TabSwitch } from "../../TabSwitch";
|
|
9
|
+
import {
|
|
10
|
+
PaneCards,
|
|
11
|
+
PaneTab,
|
|
12
|
+
PaneTable,
|
|
13
|
+
TreePaneProvider,
|
|
14
|
+
flattenChildren,
|
|
15
|
+
isPaneViewElement,
|
|
16
|
+
paneViewOption,
|
|
17
|
+
type PaneViewElement,
|
|
18
|
+
} from "./pane-views";
|
|
19
|
+
import { SkeletonBar } from "../states";
|
|
20
|
+
import { useControllable } from "../hooks/useControllable";
|
|
21
|
+
import { DataContext, useDataViewsData, useDataViewsView } from "../context";
|
|
22
|
+
import { markView } from "../slots";
|
|
23
|
+
import type { TreePaneMode, TreeViewProps } from "../types";
|
|
24
|
+
|
|
25
|
+
/** Depth-first lookup by id. The tree is a shape the caller built, so there is no index to keep. */
|
|
26
|
+
function findNode(nodes: readonly TreeNode[], id: string | null): TreeNode | null {
|
|
27
|
+
if (!id) return null;
|
|
28
|
+
for (const node of nodes) {
|
|
29
|
+
if (node.id === id) return node;
|
|
30
|
+
const hit = findNode(node.children, id);
|
|
31
|
+
if (hit) return hit;
|
|
32
|
+
}
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* The pane beside the tree — the selected node's rows, in whichever tab is showing.
|
|
38
|
+
*
|
|
39
|
+
* The pane holds three things and owns none of them: a header (the node's name, its record count,
|
|
40
|
+
* your `paneActions`), a switch built from the tabs you rendered, and the tabs themselves. Each
|
|
41
|
+
* tab decides on its own whether it is the one showing, so adding a mode is rendering a component
|
|
42
|
+
* rather than extending a union here.
|
|
43
|
+
*
|
|
44
|
+
* Both scopes the tabs need are set up here: rows swapped to the node's, so a tab's
|
|
45
|
+
* `useDataViewsData()` sees what the pane lists rather than the whole set; and the mode, so each
|
|
46
|
+
* tab can self-select.
|
|
47
|
+
*/
|
|
48
|
+
function TreePane({
|
|
49
|
+
node,
|
|
50
|
+
rows,
|
|
51
|
+
labelField,
|
|
52
|
+
mode,
|
|
53
|
+
onModeChange,
|
|
54
|
+
actions,
|
|
55
|
+
tabs,
|
|
56
|
+
}: {
|
|
57
|
+
node: TreeNode | null;
|
|
58
|
+
rows: readonly Row[];
|
|
59
|
+
labelField?: FieldConfig;
|
|
60
|
+
mode: TreePaneMode;
|
|
61
|
+
onModeChange: (mode: TreePaneMode) => void;
|
|
62
|
+
actions?: TreeViewProps["paneActions"];
|
|
63
|
+
tabs: PaneViewElement[];
|
|
64
|
+
}) {
|
|
65
|
+
const data = useDataViewsData();
|
|
66
|
+
|
|
67
|
+
// The pane paints a different row set from the root's, and everything inside it reads `rows`
|
|
68
|
+
// from context — so the swap happens here, once, rather than as a prop on each child.
|
|
69
|
+
const scoped = useMemo(() => ({ ...data, rows }), [data, rows]);
|
|
70
|
+
const paneCtx = useMemo(() => ({ mode: String(mode), labelField }), [mode, labelField]);
|
|
71
|
+
|
|
72
|
+
// The title is the node's label as a **string**, not a `Cell`. A label field of kind
|
|
73
|
+
// `enum-badge` would paint a Badge chip, and a chip inside display-size uppercase type is not a
|
|
74
|
+
// title — it is a chip in the wrong place.
|
|
75
|
+
const title =
|
|
76
|
+
(node && labelField ? String(getByPath(node.row, labelField.path) ?? "") : "") || "Items";
|
|
77
|
+
|
|
78
|
+
const options = tabs.map(paneViewOption);
|
|
79
|
+
|
|
80
|
+
return (
|
|
81
|
+
<DataContext.Provider value={scoped}>
|
|
82
|
+
<TreePaneProvider value={paneCtx}>
|
|
83
|
+
<div className="flex min-h-0 flex-1 flex-col">
|
|
84
|
+
{/* The header belongs to the pane, not to the selection: it stays up with nothing chosen
|
|
85
|
+
so the switch is reachable and the pane is not a blank rounded box. Same
|
|
86
|
+
`display-medium-medium` + `uppercase` + `cv05` recipe as the rail's own header band,
|
|
87
|
+
so the two read as one row across the screen. */}
|
|
88
|
+
<div className="border-border-presentation-global-primary flex shrink-0 items-center justify-between gap-2 border-b px-3 py-2">
|
|
89
|
+
{/* `min-w-0` on the left group is what makes the title truncate before the switch
|
|
90
|
+
starts shrinking. */}
|
|
91
|
+
<div className="flex min-w-0 items-center gap-2">
|
|
92
|
+
<span
|
|
93
|
+
style={{ fontFeatureSettings: "'cv05' on" }}
|
|
94
|
+
className="typography-display-medium-medium text-content-presentation-global-primary truncate uppercase"
|
|
95
|
+
>
|
|
96
|
+
{title}
|
|
97
|
+
</span>
|
|
98
|
+
<div className="bg-border-presentation-global-primary h-6 w-px shrink-0" />
|
|
99
|
+
<span className="typography-body-medium-regular text-content-presentation-global-secondary truncate">
|
|
100
|
+
{node ? `${rows.length} record${rows.length === 1 ? "" : "s"}` : "Select an item"}
|
|
101
|
+
</span>
|
|
102
|
+
</div>
|
|
103
|
+
|
|
104
|
+
<div className="flex shrink-0 items-center gap-2">
|
|
105
|
+
{/* Your slot, before the switch so the switch keeps the corner it is drawn in. */}
|
|
106
|
+
{actions}
|
|
107
|
+
|
|
108
|
+
{/* One tab is a label, not a choice — the same rule `ViewSwitch` follows. The
|
|
109
|
+
`TabSwitch` default size is 24px tall with 14px icons, the metrics this pane is
|
|
110
|
+
drawn at, and it takes no `theme`: unlike `ViewSwitch` on the dark header bar,
|
|
111
|
+
the pane sits in the light content area. */}
|
|
112
|
+
{options.length > 1 && (
|
|
113
|
+
<TabSwitch
|
|
114
|
+
options={options}
|
|
115
|
+
value={String(mode)}
|
|
116
|
+
onValueChange={(next) => onModeChange(next)}
|
|
117
|
+
/>
|
|
118
|
+
)}
|
|
119
|
+
</div>
|
|
120
|
+
</div>
|
|
121
|
+
|
|
122
|
+
{/* Nothing selected is shown as nothing — the header already says "Select an item". */}
|
|
123
|
+
<div className="min-h-0 flex-1 overflow-auto">{node ? tabs : null}</div>
|
|
124
|
+
</div>
|
|
125
|
+
</TreePaneProvider>
|
|
126
|
+
</DataContext.Provider>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/** The tree's own metrics, so a skeleton row occupies exactly what a real node will. */
|
|
131
|
+
const TREE_ROW_HEIGHT = 28;
|
|
132
|
+
const TREE_INDENT = 14;
|
|
133
|
+
const SKELETON_NODES = [0, 1, 1, 0, 1, 1, 0] as const;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* The loading tree.
|
|
137
|
+
*
|
|
138
|
+
* Depths alternate so it reads as a hierarchy rather than a list, and each row is `TreeFolder`'s
|
|
139
|
+
* own 28px at its 14px indent — the nodes land exactly where the shimmer was.
|
|
140
|
+
*/
|
|
141
|
+
function SkeletonNodes() {
|
|
142
|
+
return (
|
|
143
|
+
<div className="flex flex-col px-2 py-1">
|
|
144
|
+
{SKELETON_NODES.map((depth, i) => (
|
|
145
|
+
<div
|
|
146
|
+
key={`skeleton-${i}`}
|
|
147
|
+
className="flex items-center gap-2"
|
|
148
|
+
style={{ height: TREE_ROW_HEIGHT, paddingInlineStart: 6 + depth * TREE_INDENT }}
|
|
149
|
+
>
|
|
150
|
+
<SkeletonBar className="h-[14px] w-[14px] shrink-0 rounded-[3px]" />
|
|
151
|
+
<SkeletonBar className={depth === 0 ? "w-[60%]" : "w-[45%]"} />
|
|
152
|
+
</div>
|
|
153
|
+
))}
|
|
154
|
+
</div>
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* `DataViews.Tree` — a hierarchy on the left, whatever you put in `children` on the right.
|
|
160
|
+
*
|
|
161
|
+
* The rail is the shared `TreeFolder`, which is where the row height, the indent, the connector
|
|
162
|
+
* lines, the selection band, the breadcrumb and the drag grip come from. Hand-rolling those is how
|
|
163
|
+
* this view stops looking like the file tree everywhere else in the product.
|
|
164
|
+
*
|
|
165
|
+
* You build `nodes`. The tree never derives a hierarchy from flat rows: which field is the parent
|
|
166
|
+
* key, whether orphans become roots, how cycles are handled — those are decisions only you can
|
|
167
|
+
* make correctly, and guessing them was most of what the old implementation got wrong.
|
|
168
|
+
*/
|
|
169
|
+
function TreeViewImpl({
|
|
170
|
+
nodes,
|
|
171
|
+
labelPath,
|
|
172
|
+
renderNode,
|
|
173
|
+
expanded,
|
|
174
|
+
onExpandedChange,
|
|
175
|
+
onNodeMove,
|
|
176
|
+
paneMode,
|
|
177
|
+
defaultPaneMode,
|
|
178
|
+
onPaneModeChange,
|
|
179
|
+
paneRows,
|
|
180
|
+
paneActions,
|
|
181
|
+
children,
|
|
182
|
+
className,
|
|
183
|
+
}: TreeViewProps) {
|
|
184
|
+
const { visibleFields, loading } = useDataViewsData();
|
|
185
|
+
// Selection is the root's `activeId`, the same one the inbox and board use — so a detail pane
|
|
186
|
+
// works the same wherever it is rendered, and there is one "what is selected" in the component.
|
|
187
|
+
const { activeId, setActiveId } = useDataViewsView();
|
|
188
|
+
|
|
189
|
+
const labelField =
|
|
190
|
+
(labelPath && visibleFields.find((f) => f.path === labelPath)) || visibleFields[0];
|
|
191
|
+
|
|
192
|
+
const [openIds, setOpenIds] = useControllable<readonly string[]>(
|
|
193
|
+
expanded,
|
|
194
|
+
onExpandedChange,
|
|
195
|
+
nodes.filter((n) => n.children.length > 0).map((n) => n.id),
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
const folderData = useMemo(
|
|
199
|
+
() => nodes.map((node) => toFolderNode(node, labelField, visibleFields, renderNode)),
|
|
200
|
+
[nodes, labelField, visibleFields, renderNode],
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
// ── The pane ──────────────────────────────────────────────────────────────
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* Children split two ways: the pane's tabs, and everything else.
|
|
207
|
+
*
|
|
208
|
+
* Everything else *is* the pane — the whole-pane override, header and switch included, which is
|
|
209
|
+
* what every tree written before these tabs existed passes.
|
|
210
|
+
*
|
|
211
|
+
* Pass **nothing** and there is no pane at all: a part exists because you rendered it, and the
|
|
212
|
+
* pane is no more exempt from that than the table or the rail. A tree with no tabs is a
|
|
213
|
+
* hierarchy, and it takes the whole width.
|
|
214
|
+
*/
|
|
215
|
+
const { tabs, override } = useMemo(() => {
|
|
216
|
+
const all = flattenChildren(children);
|
|
217
|
+
return {
|
|
218
|
+
tabs: all.filter(isPaneViewElement),
|
|
219
|
+
override: all.filter((child) => !isPaneViewElement(child)),
|
|
220
|
+
};
|
|
221
|
+
}, [children]);
|
|
222
|
+
|
|
223
|
+
const hasPane = override.length > 0 || tabs.length > 0;
|
|
224
|
+
|
|
225
|
+
// The starting mode is the **first tab's**, not a hardcoded `"table"` — a pane whose only tab is
|
|
226
|
+
// yours has to open on it, and would otherwise sit blank on a `"table"` that matches nothing and
|
|
227
|
+
// is not reachable, since one tab draws no switch.
|
|
228
|
+
const [mode, setMode] = useControllable(
|
|
229
|
+
paneMode,
|
|
230
|
+
onPaneModeChange,
|
|
231
|
+
defaultPaneMode ?? (tabs[0] ? paneViewOption(tabs[0]).value : ""),
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
const selectedNode = useMemo(() => findNode(nodes, activeId), [nodes, activeId]);
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* What the pane lists. A branch shows what is **under** it — a synthetic grouping node has no
|
|
238
|
+
* meaningful row of its own — and a leaf, having no descendants, shows itself.
|
|
239
|
+
*/
|
|
240
|
+
const paneRowsForNode = useMemo<readonly Row[]>(() => {
|
|
241
|
+
if (!selectedNode) return [];
|
|
242
|
+
if (paneRows) return paneRows(selectedNode);
|
|
243
|
+
const out: Row[] = [];
|
|
244
|
+
const walk = (node: TreeNode) => {
|
|
245
|
+
for (const child of node.children) {
|
|
246
|
+
out.push(child.row);
|
|
247
|
+
walk(child);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
walk(selectedNode);
|
|
251
|
+
return out.length > 0 ? out : [selectedNode.row];
|
|
252
|
+
}, [selectedNode, paneRows]);
|
|
253
|
+
|
|
254
|
+
return (
|
|
255
|
+
// A split view, so the gap between the rail and the pane is part of the design: it paints the
|
|
256
|
+
// shell's black over the Master Container's surface, and the two cards float on it. The table
|
|
257
|
+
// and board fill their container instead, which is why only these two do this.
|
|
258
|
+
<div className={cn("flex h-full gap-2 bg-black", className)}>
|
|
259
|
+
<div
|
|
260
|
+
className={cn(
|
|
261
|
+
"border-border-presentation-global-primary bg-background-presentation-form-base flex flex-col overflow-hidden rounded-[16px] border",
|
|
262
|
+
// Beside a pane the rail is a fixed 256px column; with no pane there is nothing to
|
|
263
|
+
// divide the width with, so it takes all of it.
|
|
264
|
+
hasPane ? "w-64 shrink-0" : "min-w-0 flex-1",
|
|
265
|
+
)}
|
|
266
|
+
>
|
|
267
|
+
<div className="border-border-presentation-global-primary border-b px-3 py-2">
|
|
268
|
+
<span
|
|
269
|
+
style={{ fontFeatureSettings: "'cv05' on" }}
|
|
270
|
+
className="typography-display-medium-medium text-content-presentation-global-primary uppercase"
|
|
271
|
+
>
|
|
272
|
+
{labelField?.label ?? "categories"}
|
|
273
|
+
</span>
|
|
274
|
+
</div>
|
|
275
|
+
<div className="flex-1 overflow-hidden">
|
|
276
|
+
{loading ? (
|
|
277
|
+
<SkeletonNodes />
|
|
278
|
+
) : (
|
|
279
|
+
<TreeFolder
|
|
280
|
+
data={folderData}
|
|
281
|
+
selectedId={activeId}
|
|
282
|
+
onSelectionChange={(id) => setActiveId(id ?? null)}
|
|
283
|
+
expandedIds={[...openIds]}
|
|
284
|
+
onExpandedChange={(next) => setOpenIds(next)}
|
|
285
|
+
dndEnabled={Boolean(onNodeMove)}
|
|
286
|
+
onMove={({ dragIds, parentId, index }) =>
|
|
287
|
+
// `TreeFolder` reports a drop as "these ids, into this parent, at this index".
|
|
288
|
+
// `MoveIntent` is one row at a time, so a multi-select drag emits one intent each.
|
|
289
|
+
dragIds.forEach((id) => onNodeMove?.({ id, from: null, to: parentId, index }))
|
|
290
|
+
}
|
|
291
|
+
showHeader={false}
|
|
292
|
+
showBreadcrumb
|
|
293
|
+
highlightAncestors
|
|
294
|
+
/>
|
|
295
|
+
)}
|
|
296
|
+
</div>
|
|
297
|
+
</div>
|
|
298
|
+
|
|
299
|
+
{/* No tabs and no pane of your own means no pane — not an empty one. */}
|
|
300
|
+
{hasPane && (
|
|
301
|
+
<div className="border-border-presentation-global-primary bg-background-presentation-form-base flex min-w-0 flex-1 flex-col overflow-hidden rounded-[16px] border">
|
|
302
|
+
{/* A pane of your own still wins outright — see the split above. */}
|
|
303
|
+
{override.length > 0 ? (
|
|
304
|
+
override
|
|
305
|
+
) : (
|
|
306
|
+
<TreePane
|
|
307
|
+
node={selectedNode}
|
|
308
|
+
rows={paneRowsForNode}
|
|
309
|
+
mode={mode}
|
|
310
|
+
onModeChange={setMode}
|
|
311
|
+
labelField={labelField}
|
|
312
|
+
actions={paneActions}
|
|
313
|
+
tabs={tabs}
|
|
314
|
+
/>
|
|
315
|
+
)}
|
|
316
|
+
</div>
|
|
317
|
+
)}
|
|
318
|
+
</div>
|
|
319
|
+
);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
/** A `TreeNode` painted the way the rail wants it: a name, and folder-vs-file by having children. */
|
|
323
|
+
function toFolderNode(
|
|
324
|
+
node: TreeNode,
|
|
325
|
+
labelField: FieldConfig | undefined,
|
|
326
|
+
fields: readonly FieldConfig[],
|
|
327
|
+
renderNode: TreeViewProps["renderNode"],
|
|
328
|
+
): TreeFolderNode {
|
|
329
|
+
const labelValue = labelField ? getByPath(node.row, labelField.path) : undefined;
|
|
330
|
+
const children = node.children.length
|
|
331
|
+
? node.children.map((c) => toFolderNode(c, labelField, fields, renderNode))
|
|
332
|
+
: undefined;
|
|
333
|
+
|
|
334
|
+
// The row belongs to `TreeFolder` — indent, connectors, selection band, drag grip. What a
|
|
335
|
+
// caller can vary is what sits *in* it, so this takes the three slots rather than markup.
|
|
336
|
+
const custom = renderNode?.({ node, row: node.row, fields });
|
|
337
|
+
|
|
338
|
+
return {
|
|
339
|
+
id: node.id,
|
|
340
|
+
name: custom?.name ?? (labelValue == null ? node.id : String(labelValue)),
|
|
341
|
+
icon: custom?.icon,
|
|
342
|
+
meta: custom?.meta,
|
|
343
|
+
type: children ? "folder" : "file",
|
|
344
|
+
data: node.row,
|
|
345
|
+
children,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* The tree, with its pane's tabs hanging off it — `DataViews.Tree.Table`, `.Cards` and `.Tab`.
|
|
351
|
+
* They live here rather than on the root because they are the *pane's* views, not the
|
|
352
|
+
* component's: rendering `DataViews.Table` adds a tab to the header's switcher, rendering
|
|
353
|
+
* `DataViews.Tree.Table` adds one to the pane's.
|
|
354
|
+
*/
|
|
355
|
+
export const TreeView = Object.assign(
|
|
356
|
+
markView(TreeViewImpl, {
|
|
357
|
+
defaultId: "tree",
|
|
358
|
+
defaultLabel: "Tree",
|
|
359
|
+
}),
|
|
360
|
+
{
|
|
361
|
+
Table: PaneTable,
|
|
362
|
+
Cards: PaneCards,
|
|
363
|
+
Tab: PaneTab,
|
|
364
|
+
},
|
|
365
|
+
);
|
|
@@ -25,13 +25,27 @@ export const DirectionContext = createContext<FieldDirection | undefined>(undefi
|
|
|
25
25
|
export const useDirection = () => useContext(DirectionContext);
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
28
|
+
* Field chrome mode — how much layout a field draws around its control.
|
|
29
|
+
*
|
|
30
|
+
* - `false` (the default) — the full `FieldSection` row: label, required marker, stacked hint.
|
|
31
|
+
* - `"table"` — a `FormBuilder.Table` cell: no row chrome, errors as a tooltip on the control,
|
|
32
|
+
* and the control takes the flush table border treatment via `onTable`.
|
|
33
|
+
* - `"bare"` — chrome-less anywhere else, e.g. a `DataViews` filter or config panel: no row and
|
|
34
|
+
* no stacked hint, but the control keeps its normal standalone border.
|
|
35
|
+
*
|
|
36
|
+
* The two chrome-less modes are deliberately distinct: dropping the label row and taking the
|
|
37
|
+
* table border are different decisions, and only a real table cell wants both.
|
|
32
38
|
*/
|
|
33
|
-
export
|
|
34
|
-
|
|
39
|
+
export type CellMode = "table" | "bare" | false;
|
|
40
|
+
|
|
41
|
+
export const CellContext = createContext<CellMode>(false);
|
|
42
|
+
|
|
43
|
+
/** The raw mode. Prefer `useBare` / `useOnTable` — they express the two real questions. */
|
|
44
|
+
export const useCellMode = () => useContext(CellContext);
|
|
45
|
+
/** True when the field renders without `FieldSection` chrome — `"table"` **or** `"bare"`. */
|
|
46
|
+
export const useBare = () => useContext(CellContext) !== false;
|
|
47
|
+
/** True only inside a `FormBuilder.Table` cell — drives the control's `onTable` border style. */
|
|
48
|
+
export const useOnTable = () => useContext(CellContext) === "table";
|
|
35
49
|
|
|
36
50
|
/**
|
|
37
51
|
* Step registry — a `FormBuilder.Step` provides this so the fields rendered
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { FieldKind } from "./types";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The stamp that tells a consumer what a `FormBuilder.*` field produces.
|
|
6
|
+
*
|
|
7
|
+
* A form is normally read by the resolver and the submit handler, both of which know the shape
|
|
8
|
+
* they expect. Some consumers do not: `DataViews.Filters` is handed arbitrary fields as children
|
|
9
|
+
* and has to turn each one's value into a filter — a list, a numeric range, a date range — without
|
|
10
|
+
* being told which is which.
|
|
11
|
+
*
|
|
12
|
+
* The alternative is comparing `element.type` against an imported component, which breaks across
|
|
13
|
+
* duplicated module instances and silently stops matching after a hot reload. A property on the
|
|
14
|
+
* component survives both.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
const KEY = "__fieldKind";
|
|
18
|
+
|
|
19
|
+
export function markFieldKind<T>(component: T, kind: FieldKind): T {
|
|
20
|
+
(component as Record<string, unknown>)[KEY] = kind;
|
|
21
|
+
return component;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The kind stamped on an element's component, or `undefined` if it is not a marked field. */
|
|
25
|
+
export function fieldKindOf(node: React.ReactNode): FieldKind | undefined {
|
|
26
|
+
if (!React.isValidElement(node)) return undefined;
|
|
27
|
+
return (node.type as unknown as Record<string, unknown> | undefined)?.[KEY] as FieldKind | undefined;
|
|
28
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
3
|
import { DatePicker } from "../../DatePicker";
|
|
4
|
-
import {
|
|
4
|
+
import { useOnTable } from "../context";
|
|
5
5
|
import type { DateFieldProps } from "../types";
|
|
6
6
|
import { FieldShell } from "./FieldShell";
|
|
7
7
|
|
|
@@ -11,7 +11,7 @@ import { FieldShell } from "./FieldShell";
|
|
|
11
11
|
* `.DateTime` (date + time). All back onto the one Glare `DatePicker`.
|
|
12
12
|
*/
|
|
13
13
|
export function DateField(props: DateFieldProps) {
|
|
14
|
-
const
|
|
14
|
+
const onTable = useOnTable();
|
|
15
15
|
|
|
16
16
|
return (
|
|
17
17
|
<FieldShell {...props}>
|
|
@@ -21,7 +21,7 @@ export function DateField(props: DateFieldProps) {
|
|
|
21
21
|
timePicker={props.timePicker}
|
|
22
22
|
dateFormat={props.dateFormat}
|
|
23
23
|
value={field.value}
|
|
24
|
-
onTable={
|
|
24
|
+
onTable={onTable}
|
|
25
25
|
onChange={(e) =>
|
|
26
26
|
field.onChange((e as unknown as { target: { value: unknown } }).target.value)
|
|
27
27
|
}
|
|
@@ -15,7 +15,7 @@ import { FieldSection } from "../../../layouts/FieldSection";
|
|
|
15
15
|
import { FormField, FormItem, FormControl } from "../../Form";
|
|
16
16
|
import { FieldHint } from "../../FieldHint";
|
|
17
17
|
import { Tooltip } from "../../Tooltip";
|
|
18
|
-
import { useDirection, useStepRegistry,
|
|
18
|
+
import { useDirection, useStepRegistry, useBare } from "../context";
|
|
19
19
|
|
|
20
20
|
export interface FieldShellProps {
|
|
21
21
|
name: string;
|
|
@@ -50,7 +50,7 @@ export function FieldShell({
|
|
|
50
50
|
children,
|
|
51
51
|
}: FieldShellProps) {
|
|
52
52
|
const form = useFormContext();
|
|
53
|
-
const
|
|
53
|
+
const bare = useBare();
|
|
54
54
|
const ctxDirection = useDirection();
|
|
55
55
|
// A field may pin its own direction (e.g. RichText forces vertical), else the form's. When
|
|
56
56
|
// neither is set this stays `undefined` — FieldSection then falls back to its responsive
|
|
@@ -74,10 +74,11 @@ export function FieldShell({
|
|
|
74
74
|
|
|
75
75
|
if (hidden) return null;
|
|
76
76
|
|
|
77
|
-
//
|
|
78
|
-
//
|
|
79
|
-
// one line tall. Step registration
|
|
80
|
-
|
|
77
|
+
// Chrome-less mode — a `FormBuilder.Table` cell (`"table"`) or a panel field (`"bare"`).
|
|
78
|
+
// Render just the control: no FieldSection label/row, and errors surface as a tooltip on the
|
|
79
|
+
// control rather than a stacked FieldHint, so a row stays one line tall. Step registration
|
|
80
|
+
// above still applies. The control's border treatment is the caller's call, via `useOnTable`.
|
|
81
|
+
if (bare) {
|
|
81
82
|
return (
|
|
82
83
|
<FormField
|
|
83
84
|
control={form.control}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { SearchableSelect } from "../../SearchableSelect";
|
|
4
4
|
import { InputField } from "../../InputField";
|
|
5
5
|
import { cn } from "../../../utils/cn";
|
|
6
|
-
import { useLoading,
|
|
6
|
+
import { useLoading, useBare, useOnTable } from "../context";
|
|
7
7
|
import type { PhoneFieldProps } from "../types";
|
|
8
8
|
import { FieldShell } from "./FieldShell";
|
|
9
9
|
import { COUNTRIES, countryByCode, countryByDial, flagEmoji } from "./countries";
|
|
@@ -37,12 +37,40 @@ function splitPhone(value: unknown, defaultDial: string): { dial: string; number
|
|
|
37
37
|
* `FormBuilder.Phone` — country dial-code (every country) + number. The picker is a
|
|
38
38
|
* `SearchableSelect` keyed by the unique ISO code (dial codes repeat) — type to filter by
|
|
39
39
|
* country name or dial. The value is stored as a `"+<dial> <number>"` string.
|
|
40
|
+
*
|
|
41
|
+
* **Inside a `FormBuilder.Table` cell** this collapses to a single plain number input: the
|
|
42
|
+
* fixed-width picker imposed a ~155px floor on the column and left the number truncated,
|
|
43
|
+
* and two controls in one cell is not a table column. Add a separate column (e.g. a
|
|
44
|
+
* `FormBuilder.Select` of dial codes) when a table needs the country code.
|
|
40
45
|
*/
|
|
41
46
|
export function PhoneField(props: PhoneFieldProps) {
|
|
42
47
|
const loading = useLoading();
|
|
43
|
-
|
|
48
|
+
// Neither a table cell nor a narrow config rail has room for the dial-code composite, so both
|
|
49
|
+
// collapse to a single tel input — but only a real table cell takes the flush border.
|
|
50
|
+
const bare = useBare();
|
|
51
|
+
const onTable = useOnTable();
|
|
44
52
|
const defaultDial = props.defaultCountry ?? "+964"; // Iraq
|
|
45
53
|
|
|
54
|
+
if (bare) {
|
|
55
|
+
return (
|
|
56
|
+
<FieldShell {...props}>
|
|
57
|
+
{(field) => (
|
|
58
|
+
<InputField
|
|
59
|
+
type="tel"
|
|
60
|
+
inputMode="tel"
|
|
61
|
+
value={typeof field.value === "string" ? field.value : ""}
|
|
62
|
+
onChange={(e) => field.onChange(e.target.value.replace(/[^\d\s+-]/g, ""))}
|
|
63
|
+
onBlur={field.onBlur}
|
|
64
|
+
placeholder={props.placeholder ?? "Phone number"}
|
|
65
|
+
disabled={props.disabled || loading}
|
|
66
|
+
onTable={onTable}
|
|
67
|
+
className="w-full"
|
|
68
|
+
/>
|
|
69
|
+
)}
|
|
70
|
+
</FieldShell>
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
|
|
46
74
|
return (
|
|
47
75
|
<FieldShell {...props}>
|
|
48
76
|
{(field) => {
|
|
@@ -59,7 +87,6 @@ export function PhoneField(props: PhoneFieldProps) {
|
|
|
59
87
|
onValueChange={(code) => commit(countryByCode(code)?.dial ?? dial, number)}
|
|
60
88
|
placeholder="+964"
|
|
61
89
|
size="M"
|
|
62
|
-
onTable={cell}
|
|
63
90
|
inputClassName="w-[100px] min-w-[0px]"
|
|
64
91
|
className={cn("w-[113px] shrink-0", disabled && "pointer-events-none opacity-60")}
|
|
65
92
|
/>
|
|
@@ -71,7 +98,6 @@ export function PhoneField(props: PhoneFieldProps) {
|
|
|
71
98
|
onChange={(e) => commit(dial, e.target.value.replace(/[^\d\s-]/g, ""))}
|
|
72
99
|
placeholder={props.placeholder ?? "Phone number"}
|
|
73
100
|
disabled={disabled}
|
|
74
|
-
onTable={cell}
|
|
75
101
|
className="w-full"
|
|
76
102
|
/>
|
|
77
103
|
</div>
|
|
@@ -4,14 +4,14 @@ import { SearchableSelect } from "../../SearchableSelect";
|
|
|
4
4
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../Select";
|
|
5
5
|
import { BadgeField } from "../../BadgeField";
|
|
6
6
|
import type { Tag } from "../../../hooks/useTagSelection";
|
|
7
|
-
import { useLoading,
|
|
7
|
+
import { useLoading, useOnTable } from "../context";
|
|
8
8
|
import type { SelectFieldProps, SearchableSelectFieldProps, OptionsFieldProps } from "../types";
|
|
9
9
|
import { FieldShell } from "./FieldShell";
|
|
10
10
|
|
|
11
11
|
/** `FormBuilder.Select` — the plain `Select` dropdown. */
|
|
12
12
|
export function SelectField(props: SelectFieldProps) {
|
|
13
13
|
const loading = useLoading();
|
|
14
|
-
const
|
|
14
|
+
const onTable = useOnTable();
|
|
15
15
|
|
|
16
16
|
return (
|
|
17
17
|
<FieldShell {...props}>
|
|
@@ -21,7 +21,7 @@ export function SelectField(props: SelectFieldProps) {
|
|
|
21
21
|
onValueChange={field.onChange}
|
|
22
22
|
disabled={props.disabled || loading}
|
|
23
23
|
>
|
|
24
|
-
<SelectTrigger size="XL" onTable={
|
|
24
|
+
<SelectTrigger size="XL" onTable={onTable} className="w-full">
|
|
25
25
|
<SelectValue placeholder={props.placeholder ?? "Select…"} />
|
|
26
26
|
</SelectTrigger>
|
|
27
27
|
<SelectContent>
|
|
@@ -42,7 +42,7 @@ export function SelectField(props: SelectFieldProps) {
|
|
|
42
42
|
* client-side filtering, or server-side search + infinite scroll via the async props.
|
|
43
43
|
*/
|
|
44
44
|
export function SearchableSelectField(props: SearchableSelectFieldProps) {
|
|
45
|
-
const
|
|
45
|
+
const onTable = useOnTable();
|
|
46
46
|
return (
|
|
47
47
|
<FieldShell {...props}>
|
|
48
48
|
{(field) => (
|
|
@@ -56,7 +56,7 @@ export function SearchableSelectField(props: SearchableSelectFieldProps) {
|
|
|
56
56
|
onLoadMore={props.onLoadMore}
|
|
57
57
|
hasMore={props.hasMore}
|
|
58
58
|
loading={props.loading}
|
|
59
|
-
onTable={
|
|
59
|
+
onTable={onTable}
|
|
60
60
|
className="w-full"
|
|
61
61
|
/>
|
|
62
62
|
)}
|
|
@@ -66,7 +66,7 @@ export function SearchableSelectField(props: SearchableSelectFieldProps) {
|
|
|
66
66
|
|
|
67
67
|
/** `FormBuilder.MultiSelect` / `.Tags` — BadgeField, value is `string[]`. */
|
|
68
68
|
export function MultiSelectField(props: OptionsFieldProps) {
|
|
69
|
-
const
|
|
69
|
+
const onTable = useOnTable();
|
|
70
70
|
return (
|
|
71
71
|
<FieldShell {...props}>
|
|
72
72
|
{(field) => {
|
|
@@ -81,7 +81,7 @@ export function MultiSelectField(props: OptionsFieldProps) {
|
|
|
81
81
|
<BadgeField
|
|
82
82
|
tags={tags}
|
|
83
83
|
onValueChange={(picked) => field.onChange(picked.map((t) => t.value ?? t.id))}
|
|
84
|
-
onTable={
|
|
84
|
+
onTable={onTable}
|
|
85
85
|
className="w-full"
|
|
86
86
|
/>
|
|
87
87
|
);
|