@xk2800/nextjs-template 0.7.1-beta.9 → 0.7.2-beta.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/components/auth/oneTap.tsx +15 -5
- package/components/dashboard/admin/adminActivityLogsTable.tsx +4 -0
- package/components/dashboard/admin/adminUsersTable.tsx +154 -34
- package/components/dashboard/admin/impersonationLogCard.tsx +2 -2
- package/components/dashboard/appSidebar.tsx +2 -2
- package/components/dashboard/deleteAccountCard.tsx +31 -4
- package/components/dashboard/navStyleToggle.tsx +29 -0
- package/components/dashboard/topNav.tsx +95 -0
- package/components/email/email-template-banned.tsx +53 -0
- package/components/ui/alert-dialog.tsx +1 -1
- package/components/ui/avatar.tsx +1 -1
- package/components/ui/badge.tsx +4 -2
- package/components/ui/calendar.tsx +220 -0
- package/components/ui/category-selector.tsx +215 -0
- package/components/ui/chart.tsx +374 -0
- package/components/ui/column-picker.tsx +140 -0
- package/components/ui/command.tsx +184 -0
- package/components/ui/data-table.tsx +44 -6
- package/components/ui/date-picker-with-presets.tsx +122 -0
- package/components/ui/dialog.tsx +1 -1
- package/components/ui/disclaimer.tsx +4 -0
- package/components/ui/dropdown-menu.tsx +1 -1
- package/components/ui/field.tsx +248 -0
- package/components/ui/info-tooltip.tsx +53 -0
- package/components/ui/input.tsx +10 -1
- package/components/ui/label.tsx +1 -1
- package/components/ui/month-selector.tsx +194 -0
- package/components/ui/navigation-menu.tsx +168 -0
- package/components/ui/pagination.tsx +127 -0
- package/components/ui/popover.tsx +89 -0
- package/components/ui/source-selector.tsx +164 -0
- package/components/ui/switch.tsx +3 -3
- package/dist/activity/logger.d.mts +3 -1
- package/dist/activity/logger.d.ts +3 -1
- package/dist/activity/logger.js +20 -0
- package/dist/activity/logger.js.map +1 -1
- package/dist/activity/logger.mjs +4 -4
- package/dist/activity/queries.d.mts +1 -1
- package/dist/activity/queries.d.ts +1 -1
- package/dist/activity/queries.js +20 -0
- package/dist/activity/queries.js.map +1 -1
- package/dist/activity/queries.mjs +3 -3
- package/dist/admin/queries.js +20 -0
- package/dist/admin/queries.js.map +1 -1
- package/dist/admin/queries.mjs +3 -3
- package/dist/api/feedback.js +527 -70
- package/dist/api/feedback.js.map +1 -1
- package/dist/api/feedback.mjs +8 -8
- package/dist/api/marketing.js +527 -70
- package/dist/api/marketing.js.map +1 -1
- package/dist/api/marketing.mjs +10 -10
- package/dist/auth/helpers.d.mts +3 -3
- package/dist/auth/helpers.d.ts +3 -3
- package/dist/auth/helpers.js +525 -68
- package/dist/auth/helpers.js.map +1 -1
- package/dist/auth/helpers.mjs +8 -8
- package/dist/auth/index.d.mts +149 -10
- package/dist/auth/index.d.ts +149 -10
- package/dist/auth/index.js +525 -68
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/index.mjs +7 -7
- package/dist/auth-client/index.d.mts +16 -16
- package/dist/auth-client/index.d.ts +16 -16
- package/dist/{chunk-ZJMFE5B2.mjs → chunk-4C7JHGT5.mjs} +4 -4
- package/dist/{chunk-ZJMFE5B2.mjs.map → chunk-4C7JHGT5.mjs.map} +1 -1
- package/dist/{chunk-7F2POZM6.mjs → chunk-4F6KE47S.mjs} +4 -4
- package/dist/chunk-4F6KE47S.mjs.map +1 -0
- package/dist/{chunk-P2G23JMY.mjs → chunk-A6JXMHOQ.mjs} +5 -5
- package/dist/{chunk-P2G23JMY.mjs.map → chunk-A6JXMHOQ.mjs.map} +1 -1
- package/dist/{chunk-TKWNEKK6.mjs → chunk-HUEDEAY3.mjs} +8 -2
- package/dist/chunk-HUEDEAY3.mjs.map +1 -0
- package/dist/{chunk-6Z3WUSDJ.mjs → chunk-JUSU6UZA.mjs} +5 -5
- package/dist/{chunk-6Z3WUSDJ.mjs.map → chunk-JUSU6UZA.mjs.map} +1 -1
- package/dist/{chunk-TR5XFBTD.mjs → chunk-KA2KMGPY.mjs} +17 -3
- package/dist/chunk-KA2KMGPY.mjs.map +1 -0
- package/dist/{chunk-OVKVD2HH.mjs → chunk-L242CZ64.mjs} +3 -3
- package/dist/{chunk-OVKVD2HH.mjs.map → chunk-L242CZ64.mjs.map} +1 -1
- package/dist/{chunk-C6RGN6QA.mjs → chunk-NQELV53D.mjs} +4 -4
- package/dist/{chunk-C6RGN6QA.mjs.map → chunk-NQELV53D.mjs.map} +1 -1
- package/dist/chunk-VHNGYAIG.mjs +899 -0
- package/dist/chunk-VHNGYAIG.mjs.map +1 -0
- package/dist/{chunk-6MDQRT6U.mjs → chunk-YH53UPUW.mjs} +4 -4
- package/dist/{chunk-6MDQRT6U.mjs.map → chunk-YH53UPUW.mjs.map} +1 -1
- package/dist/config/env.d.mts +2 -0
- package/dist/config/env.d.ts +2 -0
- package/dist/config/env.js +6 -0
- package/dist/config/env.js.map +1 -1
- package/dist/config/env.mjs +1 -1
- package/dist/db/index.d.mts +1 -1
- package/dist/db/index.d.ts +1 -1
- package/dist/db/index.js +20 -0
- package/dist/db/index.js.map +1 -1
- package/dist/db/index.mjs +3 -3
- package/dist/db/schema.d.mts +1 -1
- package/dist/db/schema.d.ts +1 -1
- package/dist/db/schema.js +14 -0
- package/dist/db/schema.js.map +1 -1
- package/dist/db/schema.mjs +1 -1
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -1
- package/dist/errors.mjs +4 -4
- package/dist/marketing/index.js +6 -0
- package/dist/marketing/index.js.map +1 -1
- package/dist/marketing/index.mjs +3 -3
- package/dist/{schema-CN_Y6EXv.d.mts → schema-DzC5zdOq.d.mts} +146 -2
- package/dist/{schema-CN_Y6EXv.d.ts → schema-DzC5zdOq.d.ts} +146 -2
- package/dist/sessions/queries.js +20 -0
- package/dist/sessions/queries.js.map +1 -1
- package/dist/sessions/queries.mjs +3 -3
- package/dist/settings/queries.d.mts +1 -1
- package/dist/settings/queries.d.ts +1 -1
- package/dist/settings/queries.js +20 -0
- package/dist/settings/queries.js.map +1 -1
- package/dist/settings/queries.mjs +4 -4
- package/dist/users/queries.d.mts +3 -0
- package/dist/users/queries.d.ts +3 -0
- package/dist/users/queries.js +20 -0
- package/dist/users/queries.js.map +1 -1
- package/dist/users/queries.mjs +3 -3
- package/lib/recalculate-columns.ts +8 -2
- package/package.json +28 -18
- package/styles/theme.css +6 -0
- package/dist/chunk-7F2POZM6.mjs.map +0 -1
- package/dist/chunk-7QVIOQ47.mjs +0 -462
- package/dist/chunk-7QVIOQ47.mjs.map +0 -1
- package/dist/chunk-TKWNEKK6.mjs.map +0 -1
- package/dist/chunk-TR5XFBTD.mjs.map +0 -1
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import * as RechartsPrimitive from "recharts"
|
|
5
|
+
import type { TooltipValueType } from "recharts"
|
|
6
|
+
|
|
7
|
+
import { cn } from "../../lib/utils"
|
|
8
|
+
|
|
9
|
+
// Format: { THEME_NAME: CSS_SELECTOR }
|
|
10
|
+
const THEMES = { light: "", dark: ".dark" } as const
|
|
11
|
+
|
|
12
|
+
const INITIAL_DIMENSION = { width: 320, height: 200 } as const
|
|
13
|
+
type TooltipNameType = number | string
|
|
14
|
+
|
|
15
|
+
export type ChartConfig = Record<
|
|
16
|
+
string,
|
|
17
|
+
{
|
|
18
|
+
label?: React.ReactNode
|
|
19
|
+
icon?: React.ComponentType
|
|
20
|
+
} & (
|
|
21
|
+
| { color?: string; theme?: never }
|
|
22
|
+
| { color?: never; theme: Record<keyof typeof THEMES, string> }
|
|
23
|
+
)
|
|
24
|
+
>
|
|
25
|
+
|
|
26
|
+
type ChartContextProps = {
|
|
27
|
+
config: ChartConfig
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const ChartContext = React.createContext<ChartContextProps | null>(null)
|
|
31
|
+
|
|
32
|
+
function useChart() {
|
|
33
|
+
const context = React.useContext(ChartContext)
|
|
34
|
+
|
|
35
|
+
if (!context) {
|
|
36
|
+
throw new Error("useChart must be used within a <ChartContainer />")
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return context
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function ChartContainer({
|
|
43
|
+
id,
|
|
44
|
+
className,
|
|
45
|
+
children,
|
|
46
|
+
config,
|
|
47
|
+
initialDimension = INITIAL_DIMENSION,
|
|
48
|
+
...props
|
|
49
|
+
}: React.ComponentProps<"div"> & {
|
|
50
|
+
config: ChartConfig
|
|
51
|
+
children: React.ComponentProps<
|
|
52
|
+
typeof RechartsPrimitive.ResponsiveContainer
|
|
53
|
+
>["children"]
|
|
54
|
+
initialDimension?: {
|
|
55
|
+
width: number
|
|
56
|
+
height: number
|
|
57
|
+
}
|
|
58
|
+
}) {
|
|
59
|
+
const uniqueId = React.useId()
|
|
60
|
+
const chartId = `chart-${id ?? uniqueId.replace(/:/g, "")}`
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<ChartContext.Provider value={{ config }}>
|
|
64
|
+
<div
|
|
65
|
+
data-slot="chart"
|
|
66
|
+
data-chart={chartId}
|
|
67
|
+
className={cn(
|
|
68
|
+
"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",
|
|
69
|
+
className
|
|
70
|
+
)}
|
|
71
|
+
{...props}
|
|
72
|
+
>
|
|
73
|
+
<ChartStyle id={chartId} config={config} />
|
|
74
|
+
<RechartsPrimitive.ResponsiveContainer
|
|
75
|
+
initialDimension={initialDimension}
|
|
76
|
+
>
|
|
77
|
+
{children}
|
|
78
|
+
</RechartsPrimitive.ResponsiveContainer>
|
|
79
|
+
</div>
|
|
80
|
+
</ChartContext.Provider>
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
|
|
85
|
+
const colorConfig = Object.entries(config).filter(
|
|
86
|
+
([, config]) => config.theme ?? config.color
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
if (!colorConfig.length) {
|
|
90
|
+
return null
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return (
|
|
94
|
+
<style
|
|
95
|
+
dangerouslySetInnerHTML={{
|
|
96
|
+
__html: Object.entries(THEMES)
|
|
97
|
+
.map(
|
|
98
|
+
([theme, prefix]) => `
|
|
99
|
+
${prefix} [data-chart=${id}] {
|
|
100
|
+
${colorConfig
|
|
101
|
+
.map(([key, itemConfig]) => {
|
|
102
|
+
const color =
|
|
103
|
+
itemConfig.theme?.[theme as keyof typeof itemConfig.theme] ??
|
|
104
|
+
itemConfig.color
|
|
105
|
+
return color ? ` --color-${key}: ${color};` : null
|
|
106
|
+
})
|
|
107
|
+
.join("\n")}
|
|
108
|
+
}
|
|
109
|
+
`
|
|
110
|
+
)
|
|
111
|
+
.join("\n"),
|
|
112
|
+
}}
|
|
113
|
+
/>
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const ChartTooltip = RechartsPrimitive.Tooltip
|
|
118
|
+
|
|
119
|
+
function ChartTooltipContent({
|
|
120
|
+
active,
|
|
121
|
+
payload,
|
|
122
|
+
className,
|
|
123
|
+
indicator = "dot",
|
|
124
|
+
hideLabel = false,
|
|
125
|
+
hideIndicator = false,
|
|
126
|
+
label,
|
|
127
|
+
labelFormatter,
|
|
128
|
+
labelClassName,
|
|
129
|
+
formatter,
|
|
130
|
+
color,
|
|
131
|
+
nameKey,
|
|
132
|
+
labelKey,
|
|
133
|
+
}: React.ComponentProps<typeof RechartsPrimitive.Tooltip> &
|
|
134
|
+
React.ComponentProps<"div"> & {
|
|
135
|
+
hideLabel?: boolean
|
|
136
|
+
hideIndicator?: boolean
|
|
137
|
+
indicator?: "line" | "dot" | "dashed"
|
|
138
|
+
nameKey?: string
|
|
139
|
+
labelKey?: string
|
|
140
|
+
} & Omit<
|
|
141
|
+
RechartsPrimitive.DefaultTooltipContentProps<
|
|
142
|
+
TooltipValueType,
|
|
143
|
+
TooltipNameType
|
|
144
|
+
>,
|
|
145
|
+
"accessibilityLayer"
|
|
146
|
+
>) {
|
|
147
|
+
const { config } = useChart()
|
|
148
|
+
|
|
149
|
+
const tooltipLabel = React.useMemo(() => {
|
|
150
|
+
if (hideLabel || !payload?.length) {
|
|
151
|
+
return null
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const [item] = payload
|
|
155
|
+
const key = `${labelKey ?? item?.dataKey ?? item?.name ?? "value"}`
|
|
156
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
|
157
|
+
const value =
|
|
158
|
+
!labelKey && typeof label === "string"
|
|
159
|
+
? (config[label]?.label ?? label)
|
|
160
|
+
: itemConfig?.label
|
|
161
|
+
|
|
162
|
+
if (labelFormatter) {
|
|
163
|
+
return (
|
|
164
|
+
<div className={cn("font-medium", labelClassName)}>
|
|
165
|
+
{labelFormatter(value, payload)}
|
|
166
|
+
</div>
|
|
167
|
+
)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (!value) {
|
|
171
|
+
return null
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return <div className={cn("font-medium", labelClassName)}>{value}</div>
|
|
175
|
+
}, [
|
|
176
|
+
label,
|
|
177
|
+
labelFormatter,
|
|
178
|
+
payload,
|
|
179
|
+
hideLabel,
|
|
180
|
+
labelClassName,
|
|
181
|
+
config,
|
|
182
|
+
labelKey,
|
|
183
|
+
])
|
|
184
|
+
|
|
185
|
+
if (!active || !payload?.length) {
|
|
186
|
+
return null
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const nestLabel = payload.length === 1 && indicator !== "dot"
|
|
190
|
+
|
|
191
|
+
return (
|
|
192
|
+
<div
|
|
193
|
+
className={cn(
|
|
194
|
+
"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",
|
|
195
|
+
className
|
|
196
|
+
)}
|
|
197
|
+
>
|
|
198
|
+
{!nestLabel ? tooltipLabel : null}
|
|
199
|
+
<div className="grid gap-1.5">
|
|
200
|
+
{payload
|
|
201
|
+
.filter((item) => item.type !== "none")
|
|
202
|
+
.map((item, index) => {
|
|
203
|
+
const key = `${nameKey ?? item.name ?? item.dataKey ?? "value"}`
|
|
204
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
|
205
|
+
const indicatorColor = color ?? item.payload?.fill ?? item.color
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<div
|
|
209
|
+
key={index}
|
|
210
|
+
className={cn(
|
|
211
|
+
"flex w-full flex-wrap items-stretch gap-2 [&>svg]:h-2.5 [&>svg]:w-2.5 [&>svg]:text-muted-foreground",
|
|
212
|
+
indicator === "dot" && "items-center"
|
|
213
|
+
)}
|
|
214
|
+
>
|
|
215
|
+
{formatter && item?.value !== undefined && item.name ? (
|
|
216
|
+
formatter(item.value, item.name, item, index, item.payload)
|
|
217
|
+
) : (
|
|
218
|
+
<>
|
|
219
|
+
{itemConfig?.icon ? (
|
|
220
|
+
<itemConfig.icon />
|
|
221
|
+
) : (
|
|
222
|
+
!hideIndicator && (
|
|
223
|
+
<div
|
|
224
|
+
className={cn(
|
|
225
|
+
"shrink-0 rounded-[2px] border-(--color-border) bg-(--color-bg)",
|
|
226
|
+
{
|
|
227
|
+
"h-2.5 w-2.5": indicator === "dot",
|
|
228
|
+
"w-1": indicator === "line",
|
|
229
|
+
"w-0 border-[1.5px] border-dashed bg-transparent":
|
|
230
|
+
indicator === "dashed",
|
|
231
|
+
"my-0.5": nestLabel && indicator === "dashed",
|
|
232
|
+
}
|
|
233
|
+
)}
|
|
234
|
+
style={
|
|
235
|
+
{
|
|
236
|
+
"--color-bg": indicatorColor,
|
|
237
|
+
"--color-border": indicatorColor,
|
|
238
|
+
} as React.CSSProperties
|
|
239
|
+
}
|
|
240
|
+
/>
|
|
241
|
+
)
|
|
242
|
+
)}
|
|
243
|
+
<div
|
|
244
|
+
className={cn(
|
|
245
|
+
"flex flex-1 justify-between leading-none",
|
|
246
|
+
nestLabel ? "items-end" : "items-center"
|
|
247
|
+
)}
|
|
248
|
+
>
|
|
249
|
+
<div className="grid gap-1.5">
|
|
250
|
+
{nestLabel ? tooltipLabel : null}
|
|
251
|
+
<span className="text-muted-foreground">
|
|
252
|
+
{itemConfig?.label ?? item.name}
|
|
253
|
+
</span>
|
|
254
|
+
</div>
|
|
255
|
+
{item.value != null && (
|
|
256
|
+
<span className="font-mono font-medium text-foreground tabular-nums">
|
|
257
|
+
{typeof item.value === "number"
|
|
258
|
+
? item.value.toLocaleString()
|
|
259
|
+
: String(item.value)}
|
|
260
|
+
</span>
|
|
261
|
+
)}
|
|
262
|
+
</div>
|
|
263
|
+
</>
|
|
264
|
+
)}
|
|
265
|
+
</div>
|
|
266
|
+
)
|
|
267
|
+
})}
|
|
268
|
+
</div>
|
|
269
|
+
</div>
|
|
270
|
+
)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const ChartLegend = RechartsPrimitive.Legend
|
|
274
|
+
|
|
275
|
+
function ChartLegendContent({
|
|
276
|
+
className,
|
|
277
|
+
hideIcon = false,
|
|
278
|
+
payload,
|
|
279
|
+
verticalAlign = "bottom",
|
|
280
|
+
nameKey,
|
|
281
|
+
}: React.ComponentProps<"div"> & {
|
|
282
|
+
hideIcon?: boolean
|
|
283
|
+
nameKey?: string
|
|
284
|
+
} & RechartsPrimitive.DefaultLegendContentProps) {
|
|
285
|
+
const { config } = useChart()
|
|
286
|
+
|
|
287
|
+
if (!payload?.length) {
|
|
288
|
+
return null
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return (
|
|
292
|
+
<div
|
|
293
|
+
className={cn(
|
|
294
|
+
"flex items-center justify-center gap-4",
|
|
295
|
+
verticalAlign === "top" ? "pb-3" : "pt-3",
|
|
296
|
+
className
|
|
297
|
+
)}
|
|
298
|
+
>
|
|
299
|
+
{payload
|
|
300
|
+
.filter((item) => item.type !== "none")
|
|
301
|
+
.map((item, index) => {
|
|
302
|
+
const key = `${nameKey ?? item.dataKey ?? "value"}`
|
|
303
|
+
const itemConfig = getPayloadConfigFromPayload(config, item, key)
|
|
304
|
+
|
|
305
|
+
return (
|
|
306
|
+
<div
|
|
307
|
+
key={index}
|
|
308
|
+
className={cn(
|
|
309
|
+
"flex items-center gap-1.5 [&>svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground"
|
|
310
|
+
)}
|
|
311
|
+
>
|
|
312
|
+
{itemConfig?.icon && !hideIcon ? (
|
|
313
|
+
<itemConfig.icon />
|
|
314
|
+
) : (
|
|
315
|
+
<div
|
|
316
|
+
className="h-2 w-2 shrink-0 rounded-[2px]"
|
|
317
|
+
style={{
|
|
318
|
+
backgroundColor: item.color,
|
|
319
|
+
}}
|
|
320
|
+
/>
|
|
321
|
+
)}
|
|
322
|
+
{itemConfig?.label}
|
|
323
|
+
</div>
|
|
324
|
+
)
|
|
325
|
+
})}
|
|
326
|
+
</div>
|
|
327
|
+
)
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// Helper to extract item config from a payload.
|
|
331
|
+
function getPayloadConfigFromPayload(
|
|
332
|
+
config: ChartConfig,
|
|
333
|
+
payload: unknown,
|
|
334
|
+
key: string
|
|
335
|
+
) {
|
|
336
|
+
if (typeof payload !== "object" || payload === null) {
|
|
337
|
+
return undefined
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
const payloadPayload =
|
|
341
|
+
"payload" in payload &&
|
|
342
|
+
typeof payload.payload === "object" &&
|
|
343
|
+
payload.payload !== null
|
|
344
|
+
? payload.payload
|
|
345
|
+
: undefined
|
|
346
|
+
|
|
347
|
+
let configLabelKey: string = key
|
|
348
|
+
|
|
349
|
+
if (
|
|
350
|
+
key in payload &&
|
|
351
|
+
typeof payload[key as keyof typeof payload] === "string"
|
|
352
|
+
) {
|
|
353
|
+
configLabelKey = payload[key as keyof typeof payload] as string
|
|
354
|
+
} else if (
|
|
355
|
+
payloadPayload &&
|
|
356
|
+
key in payloadPayload &&
|
|
357
|
+
typeof payloadPayload[key as keyof typeof payloadPayload] === "string"
|
|
358
|
+
) {
|
|
359
|
+
configLabelKey = payloadPayload[
|
|
360
|
+
key as keyof typeof payloadPayload
|
|
361
|
+
] as string
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
return configLabelKey in config ? config[configLabelKey] : config[key]
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
export {
|
|
368
|
+
ChartContainer,
|
|
369
|
+
ChartTooltip,
|
|
370
|
+
ChartTooltipContent,
|
|
371
|
+
ChartLegend,
|
|
372
|
+
ChartLegendContent,
|
|
373
|
+
ChartStyle,
|
|
374
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { Columns3 } from "lucide-react"
|
|
5
|
+
|
|
6
|
+
import { Button } from "./button"
|
|
7
|
+
import {
|
|
8
|
+
DropdownMenu,
|
|
9
|
+
DropdownMenuCheckboxItem,
|
|
10
|
+
DropdownMenuContent,
|
|
11
|
+
DropdownMenuItem,
|
|
12
|
+
DropdownMenuLabel,
|
|
13
|
+
DropdownMenuSeparator,
|
|
14
|
+
DropdownMenuTrigger,
|
|
15
|
+
} from "./dropdown-menu"
|
|
16
|
+
import type { Column } from "../../lib/recalculate-columns"
|
|
17
|
+
|
|
18
|
+
// Lets an app switch every table's "Columns" menu on/off in one place (e.g. from a feature flag).
|
|
19
|
+
const ColumnPickerContext = React.createContext(true)
|
|
20
|
+
|
|
21
|
+
export function ColumnPickerProvider({
|
|
22
|
+
enabled,
|
|
23
|
+
children,
|
|
24
|
+
}: {
|
|
25
|
+
enabled: boolean
|
|
26
|
+
children: React.ReactNode
|
|
27
|
+
}) {
|
|
28
|
+
return (
|
|
29
|
+
<ColumnPickerContext.Provider value={enabled}>
|
|
30
|
+
{children}
|
|
31
|
+
</ColumnPickerContext.Provider>
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Whether the per-user column picker is switched on. Defaults to `true` outside a provider. */
|
|
36
|
+
export function useColumnPickerEnabled() {
|
|
37
|
+
return React.useContext(ColumnPickerContext)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const NONE: string[] = []
|
|
41
|
+
const storageKey = (tableId: string) => `data-table:hidden-columns:${tableId}`
|
|
42
|
+
const listeners = new Set<() => void>()
|
|
43
|
+
|
|
44
|
+
function subscribe(listener: () => void) {
|
|
45
|
+
listeners.add(listener)
|
|
46
|
+
window.addEventListener("storage", listener) // other tabs
|
|
47
|
+
return () => {
|
|
48
|
+
listeners.delete(listener)
|
|
49
|
+
window.removeEventListener("storage", listener)
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function read(tableId: string | undefined) {
|
|
54
|
+
if (!tableId) return null
|
|
55
|
+
try {
|
|
56
|
+
return localStorage.getItem(storageKey(tableId))
|
|
57
|
+
} catch {
|
|
58
|
+
return null
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Hidden column names for `tableId`, saved in localStorage (per browser/device).
|
|
64
|
+
* Stores the hidden set, so columns added to a table later default to visible.
|
|
65
|
+
* The server snapshot is empty, so saved choices apply right after hydration.
|
|
66
|
+
*/
|
|
67
|
+
export function useHiddenColumns(tableId: string | undefined) {
|
|
68
|
+
const raw = React.useSyncExternalStore(
|
|
69
|
+
subscribe,
|
|
70
|
+
() => read(tableId),
|
|
71
|
+
() => null,
|
|
72
|
+
)
|
|
73
|
+
const hidden = React.useMemo<string[]>(() => {
|
|
74
|
+
try {
|
|
75
|
+
return raw ? JSON.parse(raw) : NONE
|
|
76
|
+
} catch {
|
|
77
|
+
return NONE
|
|
78
|
+
}
|
|
79
|
+
}, [raw])
|
|
80
|
+
|
|
81
|
+
const setHidden = React.useCallback(
|
|
82
|
+
(next: string[]) => {
|
|
83
|
+
if (!tableId) return
|
|
84
|
+
try {
|
|
85
|
+
if (next.length) localStorage.setItem(storageKey(tableId), JSON.stringify(next))
|
|
86
|
+
else localStorage.removeItem(storageKey(tableId))
|
|
87
|
+
} catch {}
|
|
88
|
+
listeners.forEach((l) => l())
|
|
89
|
+
},
|
|
90
|
+
[tableId],
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
return [hidden, setHidden] as const
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Dropdown of checkboxes that shows/hides a table's columns, remembered per `tableId`. */
|
|
97
|
+
export function ColumnPicker<TRow>({
|
|
98
|
+
tableId,
|
|
99
|
+
columns,
|
|
100
|
+
}: {
|
|
101
|
+
tableId: string
|
|
102
|
+
columns: Column<TRow>[]
|
|
103
|
+
}) {
|
|
104
|
+
const [hidden, setHidden] = useHiddenColumns(tableId)
|
|
105
|
+
const toggle = (name: string) =>
|
|
106
|
+
setHidden(hidden.includes(name) ? hidden.filter((c) => c !== name) : [...hidden, name])
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<DropdownMenu>
|
|
110
|
+
<DropdownMenuTrigger asChild>
|
|
111
|
+
<Button variant="outline" size="sm" data-slot="column-picker">
|
|
112
|
+
<Columns3 />
|
|
113
|
+
Columns
|
|
114
|
+
</Button>
|
|
115
|
+
</DropdownMenuTrigger>
|
|
116
|
+
<DropdownMenuContent align="end">
|
|
117
|
+
<DropdownMenuLabel>Show columns</DropdownMenuLabel>
|
|
118
|
+
<DropdownMenuSeparator />
|
|
119
|
+
{columns.map((col) => (
|
|
120
|
+
<DropdownMenuCheckboxItem
|
|
121
|
+
key={col.name}
|
|
122
|
+
checked={!hidden.includes(col.name)}
|
|
123
|
+
onCheckedChange={() => toggle(col.name)}
|
|
124
|
+
onSelect={(e) => e.preventDefault()} // stay open to toggle several
|
|
125
|
+
>
|
|
126
|
+
{col.title || col.name}
|
|
127
|
+
</DropdownMenuCheckboxItem>
|
|
128
|
+
))}
|
|
129
|
+
{hidden.length > 0 && (
|
|
130
|
+
<>
|
|
131
|
+
<DropdownMenuSeparator />
|
|
132
|
+
<DropdownMenuItem onSelect={() => setHidden(NONE)}>
|
|
133
|
+
Reset to default
|
|
134
|
+
</DropdownMenuItem>
|
|
135
|
+
</>
|
|
136
|
+
)}
|
|
137
|
+
</DropdownMenuContent>
|
|
138
|
+
</DropdownMenu>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { Command as CommandPrimitive } from "cmdk"
|
|
5
|
+
import { SearchIcon } from "lucide-react"
|
|
6
|
+
|
|
7
|
+
import { cn } from "../../lib/utils"
|
|
8
|
+
import {
|
|
9
|
+
Dialog,
|
|
10
|
+
DialogContent,
|
|
11
|
+
DialogDescription,
|
|
12
|
+
DialogHeader,
|
|
13
|
+
DialogTitle,
|
|
14
|
+
} from "./dialog"
|
|
15
|
+
|
|
16
|
+
function Command({
|
|
17
|
+
className,
|
|
18
|
+
...props
|
|
19
|
+
}: React.ComponentProps<typeof CommandPrimitive>) {
|
|
20
|
+
return (
|
|
21
|
+
<CommandPrimitive
|
|
22
|
+
data-slot="command"
|
|
23
|
+
className={cn(
|
|
24
|
+
"flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
|
|
25
|
+
className
|
|
26
|
+
)}
|
|
27
|
+
{...props}
|
|
28
|
+
/>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function CommandDialog({
|
|
33
|
+
title = "Command Palette",
|
|
34
|
+
description = "Search for a command to run...",
|
|
35
|
+
children,
|
|
36
|
+
className,
|
|
37
|
+
showCloseButton = true,
|
|
38
|
+
...props
|
|
39
|
+
}: React.ComponentProps<typeof Dialog> & {
|
|
40
|
+
title?: string
|
|
41
|
+
description?: string
|
|
42
|
+
className?: string
|
|
43
|
+
showCloseButton?: boolean
|
|
44
|
+
}) {
|
|
45
|
+
return (
|
|
46
|
+
<Dialog {...props}>
|
|
47
|
+
<DialogHeader className="sr-only">
|
|
48
|
+
<DialogTitle>{title}</DialogTitle>
|
|
49
|
+
<DialogDescription>{description}</DialogDescription>
|
|
50
|
+
</DialogHeader>
|
|
51
|
+
<DialogContent
|
|
52
|
+
className={cn("overflow-hidden p-0", className)}
|
|
53
|
+
showCloseButton={showCloseButton}
|
|
54
|
+
>
|
|
55
|
+
<Command className="**:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5">
|
|
56
|
+
{children}
|
|
57
|
+
</Command>
|
|
58
|
+
</DialogContent>
|
|
59
|
+
</Dialog>
|
|
60
|
+
)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function CommandInput({
|
|
64
|
+
className,
|
|
65
|
+
...props
|
|
66
|
+
}: React.ComponentProps<typeof CommandPrimitive.Input>) {
|
|
67
|
+
return (
|
|
68
|
+
<div
|
|
69
|
+
data-slot="command-input-wrapper"
|
|
70
|
+
className="flex h-9 items-center gap-2 border-b px-3"
|
|
71
|
+
>
|
|
72
|
+
<SearchIcon className="size-4 shrink-0 opacity-50" />
|
|
73
|
+
<CommandPrimitive.Input
|
|
74
|
+
data-slot="command-input"
|
|
75
|
+
className={cn(
|
|
76
|
+
"flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
|
|
77
|
+
className
|
|
78
|
+
)}
|
|
79
|
+
{...props}
|
|
80
|
+
/>
|
|
81
|
+
</div>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function CommandList({
|
|
86
|
+
className,
|
|
87
|
+
...props
|
|
88
|
+
}: React.ComponentProps<typeof CommandPrimitive.List>) {
|
|
89
|
+
return (
|
|
90
|
+
<CommandPrimitive.List
|
|
91
|
+
data-slot="command-list"
|
|
92
|
+
className={cn(
|
|
93
|
+
"max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",
|
|
94
|
+
className
|
|
95
|
+
)}
|
|
96
|
+
{...props}
|
|
97
|
+
/>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function CommandEmpty({
|
|
102
|
+
...props
|
|
103
|
+
}: React.ComponentProps<typeof CommandPrimitive.Empty>) {
|
|
104
|
+
return (
|
|
105
|
+
<CommandPrimitive.Empty
|
|
106
|
+
data-slot="command-empty"
|
|
107
|
+
className="py-6 text-center text-sm"
|
|
108
|
+
{...props}
|
|
109
|
+
/>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function CommandGroup({
|
|
114
|
+
className,
|
|
115
|
+
...props
|
|
116
|
+
}: React.ComponentProps<typeof CommandPrimitive.Group>) {
|
|
117
|
+
return (
|
|
118
|
+
<CommandPrimitive.Group
|
|
119
|
+
data-slot="command-group"
|
|
120
|
+
className={cn(
|
|
121
|
+
"overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
|
|
122
|
+
className
|
|
123
|
+
)}
|
|
124
|
+
{...props}
|
|
125
|
+
/>
|
|
126
|
+
)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function CommandSeparator({
|
|
130
|
+
className,
|
|
131
|
+
...props
|
|
132
|
+
}: React.ComponentProps<typeof CommandPrimitive.Separator>) {
|
|
133
|
+
return (
|
|
134
|
+
<CommandPrimitive.Separator
|
|
135
|
+
data-slot="command-separator"
|
|
136
|
+
className={cn("-mx-1 h-px bg-border", className)}
|
|
137
|
+
{...props}
|
|
138
|
+
/>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function CommandItem({
|
|
143
|
+
className,
|
|
144
|
+
...props
|
|
145
|
+
}: React.ComponentProps<typeof CommandPrimitive.Item>) {
|
|
146
|
+
return (
|
|
147
|
+
<CommandPrimitive.Item
|
|
148
|
+
data-slot="command-item"
|
|
149
|
+
className={cn(
|
|
150
|
+
"relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",
|
|
151
|
+
className
|
|
152
|
+
)}
|
|
153
|
+
{...props}
|
|
154
|
+
/>
|
|
155
|
+
)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function CommandShortcut({
|
|
159
|
+
className,
|
|
160
|
+
...props
|
|
161
|
+
}: React.ComponentProps<"span">) {
|
|
162
|
+
return (
|
|
163
|
+
<span
|
|
164
|
+
data-slot="command-shortcut"
|
|
165
|
+
className={cn(
|
|
166
|
+
"ml-auto text-xs tracking-widest text-muted-foreground",
|
|
167
|
+
className
|
|
168
|
+
)}
|
|
169
|
+
{...props}
|
|
170
|
+
/>
|
|
171
|
+
)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export {
|
|
175
|
+
Command,
|
|
176
|
+
CommandDialog,
|
|
177
|
+
CommandInput,
|
|
178
|
+
CommandList,
|
|
179
|
+
CommandEmpty,
|
|
180
|
+
CommandGroup,
|
|
181
|
+
CommandItem,
|
|
182
|
+
CommandShortcut,
|
|
183
|
+
CommandSeparator,
|
|
184
|
+
}
|