create-expo-updates-server 0.1.5 → 0.2.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/dist/template/.dockerignore +16 -0
- package/dist/template/README.md +51 -660
- package/dist/template/app/api/admin/device-targets/route.test.ts +43 -0
- package/dist/template/app/api/admin/device-targets/route.ts +91 -0
- package/dist/template/app/api/admin/devices/route.test.ts +41 -0
- package/dist/template/app/api/admin/devices/route.ts +15 -0
- package/dist/template/app/api/admin/updates/[encodedKey]/audience/route.ts +75 -0
- package/dist/template/app/api/device-heartbeat/route.ts +2 -0
- package/dist/template/app/globals.css +114 -15
- package/dist/template/app/layout.tsx +12 -4
- package/dist/template/app/login/page.tsx +22 -18
- package/dist/template/app/updates/[encodedKey]/page.tsx +112 -88
- package/dist/template/app/updates/devices/page.tsx +264 -0
- package/dist/template/app/updates/embedded/page.tsx +102 -68
- package/dist/template/app/updates/emergency-redirects/page.tsx +144 -111
- package/dist/template/app/updates/layout.tsx +6 -1
- package/dist/template/app/updates/page.tsx +262 -212
- package/dist/template/components/admin/admin-shell.tsx +196 -0
- package/dist/template/components/admin/language-switcher.tsx +25 -0
- package/dist/template/components/admin/theme-provider.tsx +15 -0
- package/dist/template/components/ui/alert.tsx +65 -0
- package/dist/template/components/ui/badge.tsx +47 -0
- package/dist/template/components/ui/button.tsx +63 -0
- package/dist/template/components/ui/card.tsx +91 -0
- package/dist/template/components/ui/chart.tsx +373 -0
- package/dist/template/components/ui/checkbox.tsx +31 -0
- package/dist/template/components/ui/dialog.tsx +158 -0
- package/dist/template/components/ui/dropdown-menu.tsx +256 -0
- package/dist/template/components/ui/input.tsx +20 -0
- package/dist/template/components/ui/label.tsx +23 -0
- package/dist/template/components/ui/native-select.tsx +61 -0
- package/dist/template/components/ui/popover.tsx +88 -0
- package/dist/template/components/ui/scroll-area.tsx +57 -0
- package/dist/template/components/ui/select.tsx +189 -0
- package/dist/template/components/ui/separator.tsx +27 -0
- package/dist/template/components/ui/sheet.tsx +142 -0
- package/dist/template/components/ui/sidebar.tsx +736 -0
- package/dist/template/components/ui/skeleton.tsx +13 -0
- package/dist/template/components/ui/switch.tsx +34 -0
- package/dist/template/components/ui/table.tsx +115 -0
- package/dist/template/components/ui/tabs.tsx +90 -0
- package/dist/template/components/ui/textarea.tsx +17 -0
- package/dist/template/components/ui/tooltip.tsx +56 -0
- package/dist/template/components.json +22 -0
- package/dist/template/docs/admin-ui.md +35 -0
- package/dist/template/docs/device-targeting.md +129 -0
- package/dist/template/docs/doctor.md +137 -0
- package/dist/template/docs/expo-app-setup.md +174 -47
- package/dist/template/docs/getting-started.md +105 -146
- package/dist/template/docs/getting-started.ru.md +106 -191
- package/dist/template/docs/index.md +14 -33
- package/dist/template/docs/installation-telemetry.md +233 -0
- package/dist/template/docs/migrations/2026-10-16-manifest-identity.sql +89 -0
- package/dist/template/docs/migrations/2026-10-19-device-heartbeat.sql +131 -0
- package/dist/template/docs/migrations/2026-10-22-device-analytics.sql +264 -0
- package/dist/template/docs/migrations/2026-10-22-device-targeting-activation.sql +108 -0
- package/dist/template/docs/migrations/2026-10-22-device-targeting.sql +130 -0
- package/dist/template/docs/migrations/2026-10-22-device-version-metadata.sql +154 -0
- package/dist/template/docs/migrations/schema.sql +868 -6
- package/dist/template/docs/npm-installer.md +15 -30
- package/dist/template/docs/operations-guide.md +87 -0
- package/dist/template/docs/ota-client-lifecycle.md +263 -0
- package/dist/template/docs/ota-update-policy.md +36 -2
- package/dist/template/docs/supabase-setup.md +4 -0
- package/dist/template/hooks/use-mobile.ts +21 -0
- package/dist/template/lib/utils.ts +6 -0
- package/dist/template/package-lock.json +2325 -101
- package/dist/template/package.json +13 -3
- package/dist/template/scripts/configure-expo-app.mjs +11 -15
- package/dist/template/scripts/doctor.mjs +51 -0
- package/dist/template/scripts/ensure-test-bucket.mjs +21 -0
- package/dist/template/scripts/lib/device-identity.test.ts +29 -0
- package/dist/template/scripts/lib/doctor-probes.mjs +139 -0
- package/dist/template/scripts/lib/doctor.mjs +208 -0
- package/dist/template/scripts/lib/doctor.test.mjs +262 -0
- package/dist/template/scripts/lib/expo-app-configurator.mjs +14 -9
- package/dist/template/scripts/lib/expo-app-configurator.test.ts +3 -2
- package/dist/template/scripts/lib/ota-client-configurator.mjs +69 -0
- package/dist/template/scripts/lib/ota-client-configurator.test.ts +88 -0
- package/dist/template/scripts/lib/ota-client.test.ts +55 -0
- package/dist/template/scripts/lib/ota-root-hook-patcher.mjs +173 -0
- package/dist/template/scripts/lib/ota-root-hook-patcher.test.ts +123 -0
- package/dist/template/scripts/lib/ota-update-controller.test.ts +231 -0
- package/dist/template/scripts/tests/device-analytics-migrations.mjs +80 -0
- package/dist/template/scripts/tests/device-analytics.mjs +126 -0
- package/dist/template/scripts/tests/device-heartbeat.mjs +86 -0
- package/dist/template/scripts/tests/device-targeting-activation.mjs +111 -0
- package/dist/template/scripts/tests/device-targeting.mjs +39 -0
- package/dist/template/scripts/tests/device-version-metadata.mjs +31 -0
- package/dist/template/scripts/tests/manifest-identity-concurrency.mjs +106 -0
- package/dist/template/scripts/tests/manifest-identity.sql +204 -0
- package/dist/template/src/client/admin-types.ts +1 -0
- package/dist/template/src/client/devices/analytics.tsx +429 -0
- package/dist/template/src/client/devices/device-name.tsx +82 -0
- package/dist/template/src/client/devices/registry.tsx +399 -0
- package/dist/template/src/client/devices/use-devices-report.ts +108 -0
- package/dist/template/src/client/devices/version-adoption-chart.tsx +269 -0
- package/dist/template/src/client/devices/version-groups.test.ts +57 -0
- package/dist/template/src/client/devices/version-groups.ts +101 -0
- package/dist/template/src/client/distribution-control.tsx +135 -81
- package/dist/template/src/client/guard-action-combobox.tsx +13 -24
- package/dist/template/src/client/i18n/en.json +286 -0
- package/dist/template/src/client/i18n/messages.test.ts +42 -0
- package/dist/template/src/client/i18n/messages.ts +31 -0
- package/dist/template/src/client/i18n/provider.tsx +55 -0
- package/dist/template/src/client/i18n/use-formatters.ts +38 -0
- package/dist/template/src/client/logout-button.tsx +3 -1
- package/dist/template/src/client/update-audience-editor.tsx +285 -0
- package/dist/template/src/client/update-policy-editor.tsx +53 -41
- package/dist/template/src/server/controllers/manifest.test.ts +250 -7
- package/dist/template/src/server/controllers/manifest.ts +39 -31
- package/dist/template/src/server/devices/audience.test.ts +48 -0
- package/dist/template/src/server/devices/audience.ts +86 -0
- package/dist/template/src/server/devices/heartbeat.test.ts +39 -0
- package/dist/template/src/server/devices/heartbeat.ts +75 -0
- package/dist/template/src/server/devices/report-types.ts +114 -0
- package/dist/template/src/server/devices/report.test.ts +29 -0
- package/dist/template/src/server/devices/report.ts +27 -0
- package/dist/template/src/server/lib/admin-audience-activation.test.ts +94 -0
- package/dist/template/src/server/lib/admin-updates.ts +32 -168
- package/dist/template/src/server/lib/distribution-control.test.ts +23 -2
- package/dist/template/src/server/lib/distribution-control.ts +13 -4
- package/dist/template/src/server/lib/supabase.js +10 -10
- package/dist/template/src/server/lib/supabase.test.ts +11 -0
- package/dist/template/src/server/manifest/manifest-identity.test.ts +30 -0
- package/dist/template/src/server/manifest/manifest-identity.ts +24 -0
- package/dist/template/src/server/manifest/manifest-repository.ts +31 -102
- package/dist/template/src/server/manifest/manifest-response.ts +1 -1
- package/dist/template/templates/expo-app/ota-client/README.md +59 -0
- package/dist/template/templates/expo-app/ota-client/controller.js +60 -0
- package/dist/template/templates/expo-app/ota-client/device-identity.js +26 -0
- package/dist/template/templates/expo-app/ota-client/docs/update-lifecycle.md +52 -0
- package/dist/template/templates/expo-app/ota-client/index.d.ts +47 -0
- package/dist/template/templates/expo-app/ota-client/index.js +3 -0
- package/dist/template/templates/expo-app/ota-client/model/hooks/useOtaUpdates.js +48 -0
- package/dist/template/templates/expo-app/ota-client/model/update-controller.js +182 -0
- package/dist/template/templates/expo-app/ota-client/runtime.js +112 -0
- package/dist/template/templates/expo-app/ota-client/ui/ota-update-gate.js +56 -0
- package/dist/template-manifest.json +582 -77
- package/lib/cli.mjs +4 -6
- package/package.json +1 -1
|
@@ -0,0 +1,373 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "@/lib/utils";
|
|
5
|
+
import * as RechartsPrimitive from "recharts";
|
|
6
|
+
import type { TooltipValueType } from "recharts";
|
|
7
|
+
|
|
8
|
+
// Format: { THEME_NAME: CSS_SELECTOR }
|
|
9
|
+
const THEMES = { light: "", dark: ".dark" } as const;
|
|
10
|
+
|
|
11
|
+
const INITIAL_DIMENSION = { width: 320, height: 200 } as const;
|
|
12
|
+
type TooltipNameType = number | string;
|
|
13
|
+
|
|
14
|
+
export type ChartConfig = Record<
|
|
15
|
+
string,
|
|
16
|
+
{
|
|
17
|
+
label?: React.ReactNode;
|
|
18
|
+
icon?: React.ComponentType;
|
|
19
|
+
} & (
|
|
20
|
+
| { color?: string; theme?: never }
|
|
21
|
+
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
|
22
|
+
)
|
|
23
|
+
>;
|
|
24
|
+
|
|
25
|
+
type ChartContextProps = {
|
|
26
|
+
config: ChartConfig;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const ChartContext = React.createContext<ChartContextProps | null>(null);
|
|
30
|
+
|
|
31
|
+
function useChart() {
|
|
32
|
+
const context = React.useContext(ChartContext);
|
|
33
|
+
|
|
34
|
+
if (!context) {
|
|
35
|
+
throw new Error("useChart must be used within a <ChartContainer />");
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return context;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function ChartContainer({
|
|
42
|
+
id,
|
|
43
|
+
className,
|
|
44
|
+
children,
|
|
45
|
+
config,
|
|
46
|
+
initialDimension = INITIAL_DIMENSION,
|
|
47
|
+
...props
|
|
48
|
+
}: React.ComponentProps<"div"> & {
|
|
49
|
+
config: ChartConfig;
|
|
50
|
+
children: React.ComponentProps<
|
|
51
|
+
typeof RechartsPrimitive.ResponsiveContainer
|
|
52
|
+
>["children"];
|
|
53
|
+
initialDimension?: {
|
|
54
|
+
width: number;
|
|
55
|
+
height: number;
|
|
56
|
+
};
|
|
57
|
+
}) {
|
|
58
|
+
const uniqueId = React.useId();
|
|
59
|
+
const chartId = `chart-${id ?? uniqueId.replace(/:/g, "")}`;
|
|
60
|
+
|
|
61
|
+
return (
|
|
62
|
+
<ChartContext.Provider value={{ config }}>
|
|
63
|
+
<div
|
|
64
|
+
data-slot="chart"
|
|
65
|
+
data-chart={chartId}
|
|
66
|
+
className={cn(
|
|
67
|
+
"flex aspect-video justify-center text-xs [&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
|
|
68
|
+
className,
|
|
69
|
+
)}
|
|
70
|
+
{...props}
|
|
71
|
+
>
|
|
72
|
+
<ChartStyle id={chartId} config={config} />
|
|
73
|
+
<RechartsPrimitive.ResponsiveContainer
|
|
74
|
+
initialDimension={initialDimension}
|
|
75
|
+
>
|
|
76
|
+
{children}
|
|
77
|
+
</RechartsPrimitive.ResponsiveContainer>
|
|
78
|
+
</div>
|
|
79
|
+
</ChartContext.Provider>
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
|
84
|
+
const colorConfig = Object.entries(config).filter(
|
|
85
|
+
([, config]) => config.theme ?? config.color,
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
if (!colorConfig.length) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<style
|
|
94
|
+
dangerouslySetInnerHTML={{
|
|
95
|
+
__html: Object.entries(THEMES)
|
|
96
|
+
.map(
|
|
97
|
+
([theme, prefix]) => `
|
|
98
|
+
${prefix} [data-chart=${id}] {
|
|
99
|
+
${colorConfig
|
|
100
|
+
.map(([key, itemConfig]) => {
|
|
101
|
+
const color =
|
|
102
|
+
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ??
|
|
103
|
+
itemConfig.color;
|
|
104
|
+
return color ? ` --color-${key}: ${color};` : null;
|
|
105
|
+
})
|
|
106
|
+
.join("\n")}
|
|
107
|
+
}
|
|
108
|
+
`,
|
|
109
|
+
)
|
|
110
|
+
.join("\n"),
|
|
111
|
+
}}
|
|
112
|
+
/>
|
|
113
|
+
);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const ChartTooltip = RechartsPrimitive.Tooltip;
|
|
117
|
+
|
|
118
|
+
function ChartTooltipContent({
|
|
119
|
+
active,
|
|
120
|
+
payload,
|
|
121
|
+
className,
|
|
122
|
+
indicator = "dot",
|
|
123
|
+
hideLabel = false,
|
|
124
|
+
hideIndicator = false,
|
|
125
|
+
label,
|
|
126
|
+
labelFormatter,
|
|
127
|
+
labelClassName,
|
|
128
|
+
formatter,
|
|
129
|
+
color,
|
|
130
|
+
nameKey,
|
|
131
|
+
labelKey,
|
|
132
|
+
}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
|
|
133
|
+
React.ComponentProps<"div"> & {
|
|
134
|
+
hideLabel?: boolean;
|
|
135
|
+
hideIndicator?: boolean;
|
|
136
|
+
indicator?: "line" | "dot" | "dashed";
|
|
137
|
+
nameKey?: string;
|
|
138
|
+
labelKey?: string;
|
|
139
|
+
} & Omit<
|
|
140
|
+
RechartsPrimitive.DefaultTooltipContentProps<
|
|
141
|
+
TooltipValueType,
|
|
142
|
+
TooltipNameType
|
|
143
|
+
>,
|
|
144
|
+
"accessibilityLayer"
|
|
145
|
+
>) {
|
|
146
|
+
const { config } = useChart();
|
|
147
|
+
|
|
148
|
+
const tooltipLabel = React.useMemo(() => {
|
|
149
|
+
if (hideLabel || !payload?.length) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
const [item] = payload;
|
|
154
|
+
const key = `${labelKey ?? item?.dataKey ?? item?.name ?? "value"}`;
|
|
155
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
156
|
+
const value =
|
|
157
|
+
!labelKey && typeof label === "string"
|
|
158
|
+
? (config[label]?.label ?? label)
|
|
159
|
+
: itemConfig?.label;
|
|
160
|
+
|
|
161
|
+
if (labelFormatter) {
|
|
162
|
+
return (
|
|
163
|
+
<div className={cn("font-medium", labelClassName)}>
|
|
164
|
+
{labelFormatter(value, payload)}
|
|
165
|
+
</div>
|
|
166
|
+
);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (!value) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return <div className={cn("font-medium", labelClassName)}>{value}</div>;
|
|
174
|
+
}, [
|
|
175
|
+
label,
|
|
176
|
+
labelFormatter,
|
|
177
|
+
payload,
|
|
178
|
+
hideLabel,
|
|
179
|
+
labelClassName,
|
|
180
|
+
config,
|
|
181
|
+
labelKey,
|
|
182
|
+
]);
|
|
183
|
+
|
|
184
|
+
if (!active || !payload?.length) {
|
|
185
|
+
return null;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
const nestLabel = payload.length === 1 && indicator !== "dot";
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<div
|
|
192
|
+
className={cn(
|
|
193
|
+
"grid min-w-[8rem] items-start gap-1.5 rounded-lg border border-border/50 bg-background px-2.5 py-1.5 text-xs shadow-xl",
|
|
194
|
+
className,
|
|
195
|
+
)}
|
|
196
|
+
>
|
|
197
|
+
{!nestLabel ? tooltipLabel : null}
|
|
198
|
+
<div className="grid gap-1.5">
|
|
199
|
+
{payload
|
|
200
|
+
.filter((item) => item.type !== "none")
|
|
201
|
+
.map((item, index) => {
|
|
202
|
+
const key = `${nameKey ?? item.name ?? item.dataKey ?? "value"}`;
|
|
203
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
204
|
+
const indicatorColor = color ?? item.payload?.fill ?? item.color;
|
|
205
|
+
|
|
206
|
+
return (
|
|
207
|
+
<div
|
|
208
|
+
key={index}
|
|
209
|
+
className={cn(
|
|
210
|
+
"flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",
|
|
211
|
+
indicator === "dot" && "items-center",
|
|
212
|
+
)}
|
|
213
|
+
>
|
|
214
|
+
{formatter && item?.value !== undefined && item.name ? (
|
|
215
|
+
formatter(item.value, item.name, item, index, item.payload)
|
|
216
|
+
) : (
|
|
217
|
+
<>
|
|
218
|
+
{itemConfig?.icon ? (
|
|
219
|
+
<itemConfig.icon />
|
|
220
|
+
) : (
|
|
221
|
+
!hideIndicator && (
|
|
222
|
+
<div
|
|
223
|
+
className={cn(
|
|
224
|
+
"shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
|
|
225
|
+
{
|
|
226
|
+
"h-2.5 w-2.5": indicator === "dot",
|
|
227
|
+
"w-1": indicator === "line",
|
|
228
|
+
"w-0 border-[1.5px] border-dashed bg-transparent":
|
|
229
|
+
indicator === "dashed",
|
|
230
|
+
"my-0.5": nestLabel && indicator === "dashed",
|
|
231
|
+
},
|
|
232
|
+
)}
|
|
233
|
+
style={
|
|
234
|
+
{
|
|
235
|
+
"--color-bg": indicatorColor,
|
|
236
|
+
"--color-border": indicatorColor,
|
|
237
|
+
} as React.CSSProperties
|
|
238
|
+
}
|
|
239
|
+
/>
|
|
240
|
+
)
|
|
241
|
+
)}
|
|
242
|
+
<div
|
|
243
|
+
className={cn(
|
|
244
|
+
"flex flex-1 justify-between leading-none",
|
|
245
|
+
nestLabel ? "items-end" : "items-center",
|
|
246
|
+
)}
|
|
247
|
+
>
|
|
248
|
+
<div className="grid gap-1.5">
|
|
249
|
+
{nestLabel ? tooltipLabel : null}
|
|
250
|
+
<span className="text-muted-foreground">
|
|
251
|
+
{itemConfig?.label ?? item.name}
|
|
252
|
+
</span>
|
|
253
|
+
</div>
|
|
254
|
+
{item.value != null && (
|
|
255
|
+
<span className="font-mono font-medium text-foreground tabular-nums">
|
|
256
|
+
{typeof item.value === "number"
|
|
257
|
+
? item.value.toLocaleString()
|
|
258
|
+
: String(item.value)}
|
|
259
|
+
</span>
|
|
260
|
+
)}
|
|
261
|
+
</div>
|
|
262
|
+
</>
|
|
263
|
+
)}
|
|
264
|
+
</div>
|
|
265
|
+
);
|
|
266
|
+
})}
|
|
267
|
+
</div>
|
|
268
|
+
</div>
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
const ChartLegend = RechartsPrimitive.Legend;
|
|
273
|
+
|
|
274
|
+
function ChartLegendContent({
|
|
275
|
+
className,
|
|
276
|
+
hideIcon = false,
|
|
277
|
+
payload,
|
|
278
|
+
verticalAlign = "bottom",
|
|
279
|
+
nameKey,
|
|
280
|
+
}: React.ComponentProps<"div"> & {
|
|
281
|
+
hideIcon?: boolean;
|
|
282
|
+
nameKey?: string;
|
|
283
|
+
} & RechartsPrimitive.DefaultLegendContentProps) {
|
|
284
|
+
const { config } = useChart();
|
|
285
|
+
|
|
286
|
+
if (!payload?.length) {
|
|
287
|
+
return null;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return (
|
|
291
|
+
<div
|
|
292
|
+
className={cn(
|
|
293
|
+
"flex items-center justify-center gap-4",
|
|
294
|
+
verticalAlign === "top" ? "pb-3" : "pt-3",
|
|
295
|
+
className,
|
|
296
|
+
)}
|
|
297
|
+
>
|
|
298
|
+
{payload
|
|
299
|
+
.filter((item) => item.type !== "none")
|
|
300
|
+
.map((item, index) => {
|
|
301
|
+
const key = `${nameKey ?? item.dataKey ?? "value"}`;
|
|
302
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key);
|
|
303
|
+
|
|
304
|
+
return (
|
|
305
|
+
<div
|
|
306
|
+
key={index}
|
|
307
|
+
className={cn(
|
|
308
|
+
"flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground",
|
|
309
|
+
)}
|
|
310
|
+
>
|
|
311
|
+
{itemConfig?.icon && !hideIcon ? (
|
|
312
|
+
<itemConfig.icon />
|
|
313
|
+
) : (
|
|
314
|
+
<div
|
|
315
|
+
className="h-2 w-2 shrink-0 rounded-[2px]"
|
|
316
|
+
style={{
|
|
317
|
+
backgroundColor: item.color,
|
|
318
|
+
}}
|
|
319
|
+
/>
|
|
320
|
+
)}
|
|
321
|
+
{itemConfig?.label}
|
|
322
|
+
</div>
|
|
323
|
+
);
|
|
324
|
+
})}
|
|
325
|
+
</div>
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
// Helper to extract item config from a payload.
|
|
330
|
+
function getPayloadConfigFromPayload(
|
|
331
|
+
config: ChartConfig,
|
|
332
|
+
payload: unknown,
|
|
333
|
+
key: string,
|
|
334
|
+
) {
|
|
335
|
+
if (typeof payload !== "object" || payload === null) {
|
|
336
|
+
return undefined;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
const payloadPayload =
|
|
340
|
+
"payload" in payload &&
|
|
341
|
+
typeof payload.payload === "object" &&
|
|
342
|
+
payload.payload !== null
|
|
343
|
+
? payload.payload
|
|
344
|
+
: undefined;
|
|
345
|
+
|
|
346
|
+
let configLabelKey: string = key;
|
|
347
|
+
|
|
348
|
+
if (
|
|
349
|
+
key in payload &&
|
|
350
|
+
typeof payload[key as keyof typeof payload] === "string"
|
|
351
|
+
) {
|
|
352
|
+
configLabelKey = payload[key as keyof typeof payload] as string;
|
|
353
|
+
} else if (
|
|
354
|
+
payloadPayload &&
|
|
355
|
+
key in payloadPayload &&
|
|
356
|
+
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
|
357
|
+
) {
|
|
358
|
+
configLabelKey = payloadPayload[
|
|
359
|
+
key as keyof typeof payloadPayload
|
|
360
|
+
] as string;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
return configLabelKey in config ? config[configLabelKey] : config[key];
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
export {
|
|
367
|
+
ChartContainer,
|
|
368
|
+
ChartTooltip,
|
|
369
|
+
ChartTooltipContent,
|
|
370
|
+
ChartLegend,
|
|
371
|
+
ChartLegendContent,
|
|
372
|
+
ChartStyle,
|
|
373
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "@/lib/utils";
|
|
5
|
+
import { CheckIcon } from "lucide-react";
|
|
6
|
+
import { Checkbox as CheckboxPrimitive } from "radix-ui";
|
|
7
|
+
|
|
8
|
+
function Checkbox({
|
|
9
|
+
className,
|
|
10
|
+
...props
|
|
11
|
+
}: React.ComponentProps<typeof CheckboxPrimitive.Root>) {
|
|
12
|
+
return (
|
|
13
|
+
<CheckboxPrimitive.Root
|
|
14
|
+
data-slot="checkbox"
|
|
15
|
+
className={cn(
|
|
16
|
+
"peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary",
|
|
17
|
+
className,
|
|
18
|
+
)}
|
|
19
|
+
{...props}
|
|
20
|
+
>
|
|
21
|
+
<CheckboxPrimitive.Indicator
|
|
22
|
+
data-slot="checkbox-indicator"
|
|
23
|
+
className="grid place-content-center text-current transition-none"
|
|
24
|
+
>
|
|
25
|
+
<CheckIcon className="size-3.5" />
|
|
26
|
+
</CheckboxPrimitive.Indicator>
|
|
27
|
+
</CheckboxPrimitive.Root>
|
|
28
|
+
);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export { Checkbox };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "@/lib/utils";
|
|
5
|
+
import { XIcon } from "lucide-react";
|
|
6
|
+
import { Dialog as DialogPrimitive } from "radix-ui";
|
|
7
|
+
|
|
8
|
+
import { Button } from "@/components/ui/button";
|
|
9
|
+
|
|
10
|
+
function Dialog({
|
|
11
|
+
...props
|
|
12
|
+
}: React.ComponentProps<typeof DialogPrimitive.Root>) {
|
|
13
|
+
return <DialogPrimitive.Root data-slot="dialog" {...props} />;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function DialogTrigger({
|
|
17
|
+
...props
|
|
18
|
+
}: React.ComponentProps<typeof DialogPrimitive.Trigger>) {
|
|
19
|
+
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function DialogPortal({
|
|
23
|
+
...props
|
|
24
|
+
}: React.ComponentProps<typeof DialogPrimitive.Portal>) {
|
|
25
|
+
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function DialogClose({
|
|
29
|
+
...props
|
|
30
|
+
}: React.ComponentProps<typeof DialogPrimitive.Close>) {
|
|
31
|
+
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function DialogOverlay({
|
|
35
|
+
className,
|
|
36
|
+
...props
|
|
37
|
+
}: React.ComponentProps<typeof DialogPrimitive.Overlay>) {
|
|
38
|
+
return (
|
|
39
|
+
<DialogPrimitive.Overlay
|
|
40
|
+
data-slot="dialog-overlay"
|
|
41
|
+
className={cn(
|
|
42
|
+
"fixed inset-0 z-50 bg-black/50 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:animate-in data-[state=open]:fade-in-0",
|
|
43
|
+
className,
|
|
44
|
+
)}
|
|
45
|
+
{...props}
|
|
46
|
+
/>
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function DialogContent({
|
|
51
|
+
className,
|
|
52
|
+
children,
|
|
53
|
+
showCloseButton = true,
|
|
54
|
+
...props
|
|
55
|
+
}: React.ComponentProps<typeof DialogPrimitive.Content> & {
|
|
56
|
+
showCloseButton?: boolean;
|
|
57
|
+
}) {
|
|
58
|
+
return (
|
|
59
|
+
<DialogPortal data-slot="dialog-portal">
|
|
60
|
+
<DialogOverlay />
|
|
61
|
+
<DialogPrimitive.Content
|
|
62
|
+
data-slot="dialog-content"
|
|
63
|
+
className={cn(
|
|
64
|
+
"fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-lg border bg-background p-6 shadow-lg duration-200 outline-none data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95 sm:max-w-lg",
|
|
65
|
+
className,
|
|
66
|
+
)}
|
|
67
|
+
{...props}
|
|
68
|
+
>
|
|
69
|
+
{children}
|
|
70
|
+
{showCloseButton && (
|
|
71
|
+
<DialogPrimitive.Close
|
|
72
|
+
data-slot="dialog-close"
|
|
73
|
+
className="absolute top-4 right-4 rounded-xs opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:ring-2 focus:ring-ring focus:ring-offset-2 focus:outline-hidden disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4"
|
|
74
|
+
>
|
|
75
|
+
<XIcon />
|
|
76
|
+
<span className="sr-only">Close</span>
|
|
77
|
+
</DialogPrimitive.Close>
|
|
78
|
+
)}
|
|
79
|
+
</DialogPrimitive.Content>
|
|
80
|
+
</DialogPortal>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
85
|
+
return (
|
|
86
|
+
<div
|
|
87
|
+
data-slot="dialog-header"
|
|
88
|
+
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
|
|
89
|
+
{...props}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function DialogFooter({
|
|
95
|
+
className,
|
|
96
|
+
showCloseButton = false,
|
|
97
|
+
children,
|
|
98
|
+
...props
|
|
99
|
+
}: React.ComponentProps<"div"> & {
|
|
100
|
+
showCloseButton?: boolean;
|
|
101
|
+
}) {
|
|
102
|
+
return (
|
|
103
|
+
<div
|
|
104
|
+
data-slot="dialog-footer"
|
|
105
|
+
className={cn(
|
|
106
|
+
"flex flex-col-reverse gap-2 sm:flex-row sm:justify-end",
|
|
107
|
+
className,
|
|
108
|
+
)}
|
|
109
|
+
{...props}
|
|
110
|
+
>
|
|
111
|
+
{children}
|
|
112
|
+
{showCloseButton && (
|
|
113
|
+
<DialogPrimitive.Close asChild>
|
|
114
|
+
<Button variant="outline">Close</Button>
|
|
115
|
+
</DialogPrimitive.Close>
|
|
116
|
+
)}
|
|
117
|
+
</div>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function DialogTitle({
|
|
122
|
+
className,
|
|
123
|
+
...props
|
|
124
|
+
}: React.ComponentProps<typeof DialogPrimitive.Title>) {
|
|
125
|
+
return (
|
|
126
|
+
<DialogPrimitive.Title
|
|
127
|
+
data-slot="dialog-title"
|
|
128
|
+
className={cn("text-lg leading-none font-semibold", className)}
|
|
129
|
+
{...props}
|
|
130
|
+
/>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
function DialogDescription({
|
|
135
|
+
className,
|
|
136
|
+
...props
|
|
137
|
+
}: React.ComponentProps<typeof DialogPrimitive.Description>) {
|
|
138
|
+
return (
|
|
139
|
+
<DialogPrimitive.Description
|
|
140
|
+
data-slot="dialog-description"
|
|
141
|
+
className={cn("text-sm text-muted-foreground", className)}
|
|
142
|
+
{...props}
|
|
143
|
+
/>
|
|
144
|
+
);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export {
|
|
148
|
+
Dialog,
|
|
149
|
+
DialogClose,
|
|
150
|
+
DialogContent,
|
|
151
|
+
DialogDescription,
|
|
152
|
+
DialogFooter,
|
|
153
|
+
DialogHeader,
|
|
154
|
+
DialogOverlay,
|
|
155
|
+
DialogPortal,
|
|
156
|
+
DialogTitle,
|
|
157
|
+
DialogTrigger,
|
|
158
|
+
};
|