rockin 0.0.34 → 0.0.35
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/chunk-3CZ2LLUN.js +198 -0
- package/dist/{chunk-7ZCRGTLA.js → chunk-54ZJAEO5.js} +5 -5
- package/dist/chunk-5GM3YR42.js +228 -0
- package/dist/chunk-6XUTSMTJ.js +183 -0
- package/dist/chunk-7JJBATB2.js +35 -0
- package/dist/chunk-BITCJZQZ.js +31 -0
- package/dist/chunk-COPQJFDI.js +158 -0
- package/dist/chunk-D6TULSM6.js +785 -0
- package/dist/chunk-DVNTJNDP.js +55 -0
- package/dist/chunk-EKDBYSMI.js +87 -0
- package/dist/chunk-FGWWRPMR.js +71 -0
- package/dist/chunk-G233W3IR.js +17 -0
- package/dist/chunk-G4NDAZTB.js +13 -0
- package/dist/chunk-GY2BX5SK.js +26 -0
- package/dist/chunk-MZBLIA6C.js +20 -0
- package/dist/chunk-OSVLAX37.js +101 -0
- package/dist/chunk-PRGKTXJU.js +20 -0
- package/dist/chunk-RUKQ532H.js +253 -0
- package/dist/chunk-S4H2HENE.js +113 -0
- package/dist/chunk-UHZTEDHK.js +61 -0
- package/dist/chunk-VFDNWPOI.js +293 -0
- package/dist/chunk-W4EIJWHF.js +150 -0
- package/dist/hooks/index.js +18 -9
- package/dist/index.js +4 -4
- package/dist/provider.js +3 -3
- package/dist/ui/accordion.js +95 -0
- package/dist/ui/alert-dialog.js +178 -0
- package/dist/ui/apple/english.js +7 -0
- package/dist/ui/apple/hindi.js +7 -0
- package/dist/ui/apple/index.js +52 -0
- package/dist/ui/apple/spanish.js +7 -0
- package/dist/ui/ariakit.js +7 -0
- package/dist/ui/autocomplete.js +296 -0
- package/dist/ui/avatar.js +106 -0
- package/dist/ui/badge.js +50 -0
- package/dist/ui/bridge.js +109 -0
- package/dist/ui/bubble.js +118 -0
- package/dist/ui/button-group.js +14 -0
- package/dist/ui/button.js +9 -0
- package/dist/ui/card.js +102 -0
- package/dist/ui/carousel.js +205 -0
- package/dist/ui/chart.js +253 -0
- package/dist/ui/checkbox.js +34 -0
- package/dist/ui/code-block.js +128 -0
- package/dist/ui/combobox.js +41 -0
- package/dist/ui/command.js +199 -0
- package/dist/ui/dashed.js +57 -0
- package/dist/ui/data-table/index.js +233 -0
- package/dist/ui/dialog.js +26 -0
- package/dist/ui/dock.js +86 -0
- package/dist/ui/drawer.js +216 -0
- package/dist/ui/dropdown-menu.js +35 -0
- package/dist/ui/empty.js +17 -0
- package/dist/ui/farmer/div.js +38 -0
- package/dist/ui/farmer/variants.js +314 -0
- package/dist/ui/field.js +224 -0
- package/dist/ui/filters.js +1524 -0
- package/dist/ui/image.js +88 -0
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +57 -8502
- package/dist/ui/input-group.js +20 -0
- package/dist/ui/input-otp.js +83 -0
- package/dist/ui/input.js +7 -0
- package/dist/ui/item.js +200 -0
- package/dist/ui/jelly.js +30 -0
- package/dist/ui/kbd.js +9 -0
- package/dist/ui/label.js +7 -0
- package/dist/ui/message-scroller.js +122 -0
- package/dist/ui/message.js +93 -0
- package/dist/ui/numberstepper.js +416 -0
- package/dist/ui/otp.js +403 -0
- package/dist/ui/popover.js +83 -0
- package/dist/ui/qr-code.js +124 -0
- package/dist/ui/quantity.js +48 -0
- package/dist/ui/radio-group.js +42 -0
- package/dist/ui/resizable.js +52 -0
- package/dist/ui/scroll-area.js +9 -0
- package/dist/ui/select.js +194 -0
- package/dist/ui/separator.js +7 -0
- package/dist/ui/skeleton.js +25 -0
- package/dist/ui/sonner.js +22 -0
- package/dist/ui/sortable.js +503 -0
- package/dist/ui/swipe-actions.js +45 -0
- package/dist/ui/switch.js +34 -0
- package/dist/ui/textarea.js +7 -0
- package/dist/ui/theme-toggle.js +141 -0
- package/dist/ui/tooltip.js +13 -0
- package/package.json +1 -1
- package/dist/chunk-4KFB6AJH.js +0 -1330
- /package/dist/{chunk-FYFBWCMJ.js → chunk-GBVAFFZR.js} +0 -0
package/dist/chunk-4KFB6AJH.js
DELETED
|
@@ -1,1330 +0,0 @@
|
|
|
1
|
-
// src/ui/button.tsx
|
|
2
|
-
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
3
|
-
import { cva } from "class-variance-authority";
|
|
4
|
-
import { cn } from "cn";
|
|
5
|
-
import { jsx } from "react/jsx-runtime";
|
|
6
|
-
var buttonVariants = cva(
|
|
7
|
-
"group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-[background-color,border-color,color,box-shadow,opacity,transform] duration-150 ease-[var(--ease-out)] outline-none select-none focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/50 not-data-disabled:active:not-aria-[haspopup]:translate-y-px disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20 motion-reduce:transition-none dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-disabled:cursor-not-allowed data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg]:opacity-70 [&_svg:not([class*='size-'])]:size-4",
|
|
8
|
-
{
|
|
9
|
-
variants: {
|
|
10
|
-
variant: {
|
|
11
|
-
default: "bg-primary text-primary-foreground not-data-disabled:hover:bg-primary/80",
|
|
12
|
-
outline: "border-border bg-background not-data-disabled:hover:bg-muted not-data-disabled:hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:not-data-disabled:hover:bg-input/50",
|
|
13
|
-
secondary: "bg-secondary text-secondary-foreground not-data-disabled:hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
|
14
|
-
ghost: "not-data-disabled:hover:bg-muted not-data-disabled:hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:not-data-disabled:hover:bg-muted/50",
|
|
15
|
-
destructive: "bg-destructive/10 text-destructive not-data-disabled:hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:not-data-disabled:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
|
|
16
|
-
link: "text-primary underline-offset-4 not-data-disabled:hover:underline"
|
|
17
|
-
},
|
|
18
|
-
size: {
|
|
19
|
-
default: "h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
20
|
-
xs: "h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
|
21
|
-
sm: "h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5",
|
|
22
|
-
lg: "h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
23
|
-
icon: "size-8",
|
|
24
|
-
"icon-xs": "size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3",
|
|
25
|
-
"icon-sm": "size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg",
|
|
26
|
-
"icon-lg": "size-9",
|
|
27
|
-
"icon-title": "size-8 sm:h-8 sm:w-auto sm:gap-1.5 sm:px-2.5 sm:has-data-[icon=inline-end]:pr-2 sm:has-data-[icon=inline-start]:pl-2"
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
defaultVariants: {
|
|
31
|
-
variant: "default",
|
|
32
|
-
size: "default"
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
function Button({
|
|
37
|
-
className,
|
|
38
|
-
variant = "default",
|
|
39
|
-
size = "default",
|
|
40
|
-
...props
|
|
41
|
-
}) {
|
|
42
|
-
return /* @__PURE__ */ jsx(
|
|
43
|
-
ButtonPrimitive,
|
|
44
|
-
{
|
|
45
|
-
"data-slot": "button",
|
|
46
|
-
className: cn(buttonVariants({ variant, size, className })),
|
|
47
|
-
...props
|
|
48
|
-
}
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// src/ui/input.tsx
|
|
53
|
-
import { Input as InputPrimitive } from "@base-ui/react/input";
|
|
54
|
-
import { cn as cn2 } from "cn";
|
|
55
|
-
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
56
|
-
function Input({
|
|
57
|
-
className,
|
|
58
|
-
type,
|
|
59
|
-
inputMode,
|
|
60
|
-
onWheel,
|
|
61
|
-
...props
|
|
62
|
-
}) {
|
|
63
|
-
const isNumberInput = type === "number";
|
|
64
|
-
return /* @__PURE__ */ jsx2(
|
|
65
|
-
InputPrimitive,
|
|
66
|
-
{
|
|
67
|
-
type,
|
|
68
|
-
"data-slot": "input",
|
|
69
|
-
inputMode: isNumberInput ? "decimal" : inputMode,
|
|
70
|
-
onWheel: isNumberInput ? (event) => {
|
|
71
|
-
event.currentTarget.blur();
|
|
72
|
-
onWheel?.(event);
|
|
73
|
-
} : onWheel,
|
|
74
|
-
className: cn2(
|
|
75
|
-
"h-8 w-full min-w-0 rounded-lg border border-input bg-transparent px-2.5 py-1 text-base transition-colors outline-none file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
|
76
|
-
isNumberInput && "[appearance:textfield] [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none",
|
|
77
|
-
className
|
|
78
|
-
),
|
|
79
|
-
...props
|
|
80
|
-
}
|
|
81
|
-
);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// src/ui/textarea.tsx
|
|
85
|
-
import { cn as cn3 } from "cn";
|
|
86
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
87
|
-
function Textarea({ className, ...props }) {
|
|
88
|
-
return /* @__PURE__ */ jsx3(
|
|
89
|
-
"textarea",
|
|
90
|
-
{
|
|
91
|
-
"data-slot": "textarea",
|
|
92
|
-
className: cn3(
|
|
93
|
-
"flex field-sizing-content min-h-16 w-full rounded-lg border border-input bg-transparent px-2.5 py-2 text-base transition-colors outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:bg-input/50 disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:disabled:bg-input/80 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40",
|
|
94
|
-
className
|
|
95
|
-
),
|
|
96
|
-
...props
|
|
97
|
-
}
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// src/ui/input-group.tsx
|
|
102
|
-
import { cva as cva2 } from "class-variance-authority";
|
|
103
|
-
import { cn as cn4 } from "cn";
|
|
104
|
-
import { jsx as jsx4 } from "react/jsx-runtime";
|
|
105
|
-
function InputGroup({ className, ...props }) {
|
|
106
|
-
return /* @__PURE__ */ jsx4(
|
|
107
|
-
"div",
|
|
108
|
-
{
|
|
109
|
-
"data-slot": "input-group",
|
|
110
|
-
role: "group",
|
|
111
|
-
className: cn4(
|
|
112
|
-
"group/input-group relative flex h-8 w-full min-w-0 items-center rounded-lg border border-input transition-colors outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-disabled:bg-input/50 has-disabled:opacity-50 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-2 has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-2 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto dark:bg-input/30 dark:has-disabled:bg-input/80 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5",
|
|
113
|
-
className
|
|
114
|
-
),
|
|
115
|
-
...props
|
|
116
|
-
}
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
var inputGroupAddonVariants = cva2(
|
|
120
|
-
"flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4",
|
|
121
|
-
{
|
|
122
|
-
variants: {
|
|
123
|
-
align: {
|
|
124
|
-
"inline-start": "order-first pl-2 has-[>button]:ml-[-0.3rem] has-[>kbd]:ml-[-0.15rem]",
|
|
125
|
-
"inline-end": "order-last pr-2 has-[>button]:mr-[-0.3rem] has-[>kbd]:mr-[-0.15rem]",
|
|
126
|
-
"block-start": "order-first w-full justify-start px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2",
|
|
127
|
-
"block-end": "order-last w-full justify-start px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2"
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
defaultVariants: {
|
|
131
|
-
align: "inline-start"
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
);
|
|
135
|
-
function InputGroupAddon({
|
|
136
|
-
className,
|
|
137
|
-
align = "inline-start",
|
|
138
|
-
focusInput = true,
|
|
139
|
-
...props
|
|
140
|
-
}) {
|
|
141
|
-
return /* @__PURE__ */ jsx4(
|
|
142
|
-
"div",
|
|
143
|
-
{
|
|
144
|
-
role: "group",
|
|
145
|
-
"data-slot": "input-group-addon",
|
|
146
|
-
"data-align": align,
|
|
147
|
-
className: cn4(inputGroupAddonVariants({ align }), className),
|
|
148
|
-
onClick: (e) => {
|
|
149
|
-
if (e.target.closest("button")) {
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
if (!focusInput) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
e.currentTarget.parentElement?.querySelector("input")?.focus();
|
|
156
|
-
},
|
|
157
|
-
...props
|
|
158
|
-
}
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
var inputGroupButtonVariants = cva2(
|
|
162
|
-
"flex items-center gap-2 text-sm shadow-none",
|
|
163
|
-
{
|
|
164
|
-
variants: {
|
|
165
|
-
size: {
|
|
166
|
-
xs: "h-6 gap-1 rounded-[calc(var(--radius)-3px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
|
|
167
|
-
sm: "",
|
|
168
|
-
"icon-xs": "size-6 rounded-[calc(var(--radius)-3px)] p-0 has-[>svg]:p-0",
|
|
169
|
-
"icon-sm": "size-8 p-0 has-[>svg]:p-0",
|
|
170
|
-
"bar-icon": "size-7 rounded-[calc(var(--radius)-3px)] p-0 has-[>svg]:p-0"
|
|
171
|
-
}
|
|
172
|
-
},
|
|
173
|
-
defaultVariants: {
|
|
174
|
-
size: "xs"
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
);
|
|
178
|
-
function InputGroupButton({
|
|
179
|
-
className,
|
|
180
|
-
type = "button",
|
|
181
|
-
variant = "ghost",
|
|
182
|
-
size = "xs",
|
|
183
|
-
...props
|
|
184
|
-
}) {
|
|
185
|
-
return /* @__PURE__ */ jsx4(
|
|
186
|
-
Button,
|
|
187
|
-
{
|
|
188
|
-
type,
|
|
189
|
-
"data-size": size,
|
|
190
|
-
variant,
|
|
191
|
-
className: cn4(inputGroupButtonVariants({ size }), className),
|
|
192
|
-
...props
|
|
193
|
-
}
|
|
194
|
-
);
|
|
195
|
-
}
|
|
196
|
-
function InputGroupText({ className, ...props }) {
|
|
197
|
-
return /* @__PURE__ */ jsx4(
|
|
198
|
-
"span",
|
|
199
|
-
{
|
|
200
|
-
className: cn4(
|
|
201
|
-
"flex items-center gap-2 text-sm text-muted-foreground [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4",
|
|
202
|
-
className
|
|
203
|
-
),
|
|
204
|
-
...props
|
|
205
|
-
}
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
function InputGroupInput({
|
|
209
|
-
className,
|
|
210
|
-
...props
|
|
211
|
-
}) {
|
|
212
|
-
return /* @__PURE__ */ jsx4(
|
|
213
|
-
Input,
|
|
214
|
-
{
|
|
215
|
-
"data-slot": "input-group-control",
|
|
216
|
-
className: cn4(
|
|
217
|
-
"flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent",
|
|
218
|
-
className
|
|
219
|
-
),
|
|
220
|
-
...props
|
|
221
|
-
}
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
function InputGroupTextarea({
|
|
225
|
-
className,
|
|
226
|
-
...props
|
|
227
|
-
}) {
|
|
228
|
-
return /* @__PURE__ */ jsx4(
|
|
229
|
-
Textarea,
|
|
230
|
-
{
|
|
231
|
-
"data-slot": "input-group-control",
|
|
232
|
-
className: cn4(
|
|
233
|
-
"flex-1 resize-none rounded-none border-0 bg-transparent py-2 shadow-none ring-0 focus-visible:ring-0 disabled:bg-transparent aria-invalid:ring-0 dark:bg-transparent dark:disabled:bg-transparent",
|
|
234
|
-
className
|
|
235
|
-
),
|
|
236
|
-
...props
|
|
237
|
-
}
|
|
238
|
-
);
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// src/ui/combobox.tsx
|
|
242
|
-
import { Combobox as ComboboxPrimitive } from "@base-ui/react";
|
|
243
|
-
import * as React from "react";
|
|
244
|
-
import { cn as cn5 } from "cn";
|
|
245
|
-
import { Check, ChevronDown, Xmark } from "@gravity-ui/icons";
|
|
246
|
-
import { jsx as jsx5, jsxs } from "react/jsx-runtime";
|
|
247
|
-
var Combobox = ComboboxPrimitive.Root;
|
|
248
|
-
function ComboboxValue({ ...props }) {
|
|
249
|
-
return /* @__PURE__ */ jsx5(ComboboxPrimitive.Value, { "data-slot": "combobox-value", ...props });
|
|
250
|
-
}
|
|
251
|
-
function ComboboxTrigger({
|
|
252
|
-
className,
|
|
253
|
-
children,
|
|
254
|
-
...props
|
|
255
|
-
}) {
|
|
256
|
-
return /* @__PURE__ */ jsxs(
|
|
257
|
-
ComboboxPrimitive.Trigger,
|
|
258
|
-
{
|
|
259
|
-
"data-slot": "combobox-trigger",
|
|
260
|
-
className: cn5("[&_svg:not([class*='size-'])]:size-4", className),
|
|
261
|
-
...props,
|
|
262
|
-
children: [
|
|
263
|
-
children,
|
|
264
|
-
/* @__PURE__ */ jsx5(ChevronDown, { className: "pointer-events-none size-4 text-muted-foreground" })
|
|
265
|
-
]
|
|
266
|
-
}
|
|
267
|
-
);
|
|
268
|
-
}
|
|
269
|
-
function ComboboxClear({ className, ...props }) {
|
|
270
|
-
return /* @__PURE__ */ jsx5(
|
|
271
|
-
ComboboxPrimitive.Clear,
|
|
272
|
-
{
|
|
273
|
-
"data-slot": "combobox-clear",
|
|
274
|
-
render: /* @__PURE__ */ jsx5(InputGroupButton, { variant: "ghost", size: "icon-xs" }),
|
|
275
|
-
className: cn5(className),
|
|
276
|
-
...props,
|
|
277
|
-
children: /* @__PURE__ */ jsx5(Xmark, { className: "pointer-events-none" })
|
|
278
|
-
}
|
|
279
|
-
);
|
|
280
|
-
}
|
|
281
|
-
function ComboboxInput({
|
|
282
|
-
className,
|
|
283
|
-
children,
|
|
284
|
-
disabled = false,
|
|
285
|
-
showTrigger = true,
|
|
286
|
-
showClear = false,
|
|
287
|
-
startContent,
|
|
288
|
-
endContent,
|
|
289
|
-
...props
|
|
290
|
-
}) {
|
|
291
|
-
return /* @__PURE__ */ jsxs(InputGroup, { className: cn5("w-auto", className), children: [
|
|
292
|
-
/* @__PURE__ */ jsx5(
|
|
293
|
-
ComboboxPrimitive.Input,
|
|
294
|
-
{
|
|
295
|
-
render: /* @__PURE__ */ jsx5(InputGroupInput, { disabled }),
|
|
296
|
-
...props
|
|
297
|
-
}
|
|
298
|
-
),
|
|
299
|
-
startContent && /* @__PURE__ */ jsx5(InputGroupAddon, { align: "inline-start", children: startContent }),
|
|
300
|
-
/* @__PURE__ */ jsxs(InputGroupAddon, { align: "inline-end", className: "pr-0", children: [
|
|
301
|
-
showTrigger && /* @__PURE__ */ jsx5(
|
|
302
|
-
InputGroupButton,
|
|
303
|
-
{
|
|
304
|
-
size: "icon-xs",
|
|
305
|
-
variant: "ghost",
|
|
306
|
-
render: /* @__PURE__ */ jsx5(ComboboxTrigger, {}),
|
|
307
|
-
"data-slot": "input-group-button",
|
|
308
|
-
className: "group-has-data-[slot=combobox-clear]/input-group:hidden data-pressed:bg-transparent",
|
|
309
|
-
disabled
|
|
310
|
-
}
|
|
311
|
-
),
|
|
312
|
-
showClear && /* @__PURE__ */ jsx5(ComboboxClear, { disabled })
|
|
313
|
-
] }),
|
|
314
|
-
/* @__PURE__ */ jsx5(InputGroupAddon, { align: "inline-end", children: endContent }),
|
|
315
|
-
children
|
|
316
|
-
] });
|
|
317
|
-
}
|
|
318
|
-
function ComboboxContent({
|
|
319
|
-
className,
|
|
320
|
-
side = "bottom",
|
|
321
|
-
sideOffset = 6,
|
|
322
|
-
align = "start",
|
|
323
|
-
alignOffset = 0,
|
|
324
|
-
anchor,
|
|
325
|
-
...props
|
|
326
|
-
}) {
|
|
327
|
-
return /* @__PURE__ */ jsx5(ComboboxPrimitive.Portal, { children: /* @__PURE__ */ jsx5(
|
|
328
|
-
ComboboxPrimitive.Positioner,
|
|
329
|
-
{
|
|
330
|
-
side,
|
|
331
|
-
sideOffset,
|
|
332
|
-
align,
|
|
333
|
-
alignOffset,
|
|
334
|
-
anchor,
|
|
335
|
-
className: "isolate z-50",
|
|
336
|
-
children: /* @__PURE__ */ jsx5(
|
|
337
|
-
ComboboxPrimitive.Popup,
|
|
338
|
-
{
|
|
339
|
-
"data-slot": "combobox-content",
|
|
340
|
-
"data-chips": !!anchor,
|
|
341
|
-
className: cn5(
|
|
342
|
-
"group/combobox-content relative max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-[calc(var(--anchor-width)+(--spacing(7)))] origin-(--transform-origin) overflow-hidden rounded-lg bg-background text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[chips=true]:min-w-(--anchor-width) data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 *:data-[slot=input-group]:m-1 *:data-[slot=input-group]:mb-0 *:data-[slot=input-group]:h-8 *:data-[slot=input-group]:border-input/30 *:data-[slot=input-group]:bg-input/30 *:data-[slot=input-group]:shadow-none data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
|
343
|
-
className
|
|
344
|
-
),
|
|
345
|
-
...props
|
|
346
|
-
}
|
|
347
|
-
)
|
|
348
|
-
}
|
|
349
|
-
) });
|
|
350
|
-
}
|
|
351
|
-
function ComboboxList({ className, ...props }) {
|
|
352
|
-
return /* @__PURE__ */ jsx5(
|
|
353
|
-
ComboboxPrimitive.List,
|
|
354
|
-
{
|
|
355
|
-
"data-slot": "combobox-list",
|
|
356
|
-
className: cn5(
|
|
357
|
-
"no-scrollbar max-h-[min(calc(--spacing(72)-(--spacing(9))),calc(var(--available-height)-(--spacing(9))))] scroll-py-1 overflow-y-auto overscroll-contain p-1 data-empty:p-0",
|
|
358
|
-
className
|
|
359
|
-
),
|
|
360
|
-
...props
|
|
361
|
-
}
|
|
362
|
-
);
|
|
363
|
-
}
|
|
364
|
-
function ComboboxItem({
|
|
365
|
-
className,
|
|
366
|
-
children,
|
|
367
|
-
...props
|
|
368
|
-
}) {
|
|
369
|
-
return /* @__PURE__ */ jsxs(
|
|
370
|
-
ComboboxPrimitive.Item,
|
|
371
|
-
{
|
|
372
|
-
"data-slot": "combobox-item",
|
|
373
|
-
className: cn5(
|
|
374
|
-
"relative flex w-full cursor-default items-center gap-2 rounded-md py-1 pr-8 pl-1.5 text-sm outline-hidden select-none data-highlighted:bg-accent data-highlighted:text-accent-foreground not-data-[variant=destructive]:data-highlighted:**:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
|
|
375
|
-
className
|
|
376
|
-
),
|
|
377
|
-
...props,
|
|
378
|
-
children: [
|
|
379
|
-
children,
|
|
380
|
-
/* @__PURE__ */ jsx5(
|
|
381
|
-
ComboboxPrimitive.ItemIndicator,
|
|
382
|
-
{
|
|
383
|
-
render: /* @__PURE__ */ jsx5("span", { className: "pointer-events-none absolute right-2 flex size-4 items-center justify-center" }),
|
|
384
|
-
children: /* @__PURE__ */ jsx5(Check, { className: "pointer-events-none" })
|
|
385
|
-
}
|
|
386
|
-
)
|
|
387
|
-
]
|
|
388
|
-
}
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
function ComboboxGroup({ className, ...props }) {
|
|
392
|
-
return /* @__PURE__ */ jsx5(
|
|
393
|
-
ComboboxPrimitive.Group,
|
|
394
|
-
{
|
|
395
|
-
"data-slot": "combobox-group",
|
|
396
|
-
className: cn5(className),
|
|
397
|
-
...props
|
|
398
|
-
}
|
|
399
|
-
);
|
|
400
|
-
}
|
|
401
|
-
function ComboboxLabel({
|
|
402
|
-
className,
|
|
403
|
-
...props
|
|
404
|
-
}) {
|
|
405
|
-
return /* @__PURE__ */ jsx5(
|
|
406
|
-
ComboboxPrimitive.GroupLabel,
|
|
407
|
-
{
|
|
408
|
-
"data-slot": "combobox-label",
|
|
409
|
-
className: cn5("px-2 py-1.5 text-xs text-muted-foreground", className),
|
|
410
|
-
...props
|
|
411
|
-
}
|
|
412
|
-
);
|
|
413
|
-
}
|
|
414
|
-
function ComboboxCollection({ ...props }) {
|
|
415
|
-
return /* @__PURE__ */ jsx5(ComboboxPrimitive.Collection, { "data-slot": "combobox-collection", ...props });
|
|
416
|
-
}
|
|
417
|
-
function ComboboxEmpty({ className, ...props }) {
|
|
418
|
-
return /* @__PURE__ */ jsx5(
|
|
419
|
-
ComboboxPrimitive.Empty,
|
|
420
|
-
{
|
|
421
|
-
"data-slot": "combobox-empty",
|
|
422
|
-
className: cn5(
|
|
423
|
-
"hidden w-full justify-center py-2 text-center text-sm text-muted-foreground group-data-empty/combobox-content:flex",
|
|
424
|
-
className
|
|
425
|
-
),
|
|
426
|
-
...props
|
|
427
|
-
}
|
|
428
|
-
);
|
|
429
|
-
}
|
|
430
|
-
function ComboboxSeparator({
|
|
431
|
-
className,
|
|
432
|
-
...props
|
|
433
|
-
}) {
|
|
434
|
-
return /* @__PURE__ */ jsx5(
|
|
435
|
-
ComboboxPrimitive.Separator,
|
|
436
|
-
{
|
|
437
|
-
"data-slot": "combobox-separator",
|
|
438
|
-
className: cn5("-mx-1 my-1 h-px bg-border", className),
|
|
439
|
-
...props
|
|
440
|
-
}
|
|
441
|
-
);
|
|
442
|
-
}
|
|
443
|
-
function ComboboxChips({
|
|
444
|
-
className,
|
|
445
|
-
...props
|
|
446
|
-
}) {
|
|
447
|
-
return /* @__PURE__ */ jsx5(
|
|
448
|
-
ComboboxPrimitive.Chips,
|
|
449
|
-
{
|
|
450
|
-
"data-slot": "combobox-chips",
|
|
451
|
-
className: cn5(
|
|
452
|
-
"flex min-h-8 flex-wrap items-center gap-1 rounded-lg border border-input bg-transparent bg-clip-padding px-2.5 py-1 text-sm transition-colors focus-within:border-ring focus-within:ring-2 focus-within:ring-ring/50 has-aria-invalid:border-destructive has-aria-invalid:ring-2 has-aria-invalid:ring-destructive/20 has-data-[slot=combobox-chip]:px-1 dark:bg-input/30 dark:has-aria-invalid:border-destructive/50 dark:has-aria-invalid:ring-destructive/40",
|
|
453
|
-
className
|
|
454
|
-
),
|
|
455
|
-
...props
|
|
456
|
-
}
|
|
457
|
-
);
|
|
458
|
-
}
|
|
459
|
-
function ComboboxChip({
|
|
460
|
-
className,
|
|
461
|
-
children,
|
|
462
|
-
showRemove = true,
|
|
463
|
-
...props
|
|
464
|
-
}) {
|
|
465
|
-
return /* @__PURE__ */ jsxs(
|
|
466
|
-
ComboboxPrimitive.Chip,
|
|
467
|
-
{
|
|
468
|
-
"data-slot": "combobox-chip",
|
|
469
|
-
className: cn5(
|
|
470
|
-
"flex h-[calc(--spacing(5.25))] w-fit items-center justify-center gap-1 rounded-sm bg-muted px-1.5 text-xs font-medium whitespace-nowrap text-foreground has-disabled:pointer-events-none has-disabled:cursor-not-allowed has-disabled:opacity-50 has-data-[slot=combobox-chip-remove]:pr-0",
|
|
471
|
-
className
|
|
472
|
-
),
|
|
473
|
-
...props,
|
|
474
|
-
children: [
|
|
475
|
-
children,
|
|
476
|
-
showRemove && /* @__PURE__ */ jsx5(
|
|
477
|
-
ComboboxPrimitive.ChipRemove,
|
|
478
|
-
{
|
|
479
|
-
render: /* @__PURE__ */ jsx5(Button, { variant: "ghost", size: "icon-xs" }),
|
|
480
|
-
className: "-ml-1 opacity-50 hover:opacity-100",
|
|
481
|
-
"data-slot": "combobox-chip-remove",
|
|
482
|
-
children: /* @__PURE__ */ jsx5(Xmark, { className: "pointer-events-none" })
|
|
483
|
-
}
|
|
484
|
-
)
|
|
485
|
-
]
|
|
486
|
-
}
|
|
487
|
-
);
|
|
488
|
-
}
|
|
489
|
-
function ComboboxChipsInput({
|
|
490
|
-
className,
|
|
491
|
-
...props
|
|
492
|
-
}) {
|
|
493
|
-
return /* @__PURE__ */ jsx5(
|
|
494
|
-
ComboboxPrimitive.Input,
|
|
495
|
-
{
|
|
496
|
-
"data-slot": "combobox-chip-input",
|
|
497
|
-
className: cn5("min-w-16 flex-1 outline-none", className),
|
|
498
|
-
...props
|
|
499
|
-
}
|
|
500
|
-
);
|
|
501
|
-
}
|
|
502
|
-
function useComboboxAnchor() {
|
|
503
|
-
return React.useRef(null);
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
// src/ui/data-table/core/data-table-root.tsx
|
|
507
|
-
import * as React2 from "react";
|
|
508
|
-
import { cn as cn6 } from "cn";
|
|
509
|
-
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
510
|
-
var DataTableContext = React2.createContext(
|
|
511
|
-
null
|
|
512
|
-
);
|
|
513
|
-
function useDataTable() {
|
|
514
|
-
const context = React2.useContext(DataTableContext);
|
|
515
|
-
if (!context) {
|
|
516
|
-
throw new Error(
|
|
517
|
-
"DataTable components must be rendered inside DataTableRoot"
|
|
518
|
-
);
|
|
519
|
-
}
|
|
520
|
-
return context;
|
|
521
|
-
}
|
|
522
|
-
function DataTableRoot({
|
|
523
|
-
data,
|
|
524
|
-
columns,
|
|
525
|
-
children,
|
|
526
|
-
isLoading = false,
|
|
527
|
-
pageSize = 10,
|
|
528
|
-
getRowId = (_, index) => String(index),
|
|
529
|
-
className
|
|
530
|
-
}) {
|
|
531
|
-
const [globalFilter, setGlobalFilterState] = React2.useState("");
|
|
532
|
-
const [pageIndex, setPageIndexState] = React2.useState(0);
|
|
533
|
-
const filteredData = React2.useMemo(() => {
|
|
534
|
-
const query = globalFilter.trim().toLowerCase();
|
|
535
|
-
if (!query) return data;
|
|
536
|
-
return data.filter(
|
|
537
|
-
(row) => columns.some((column) => {
|
|
538
|
-
if (column.enableSearch === false) return false;
|
|
539
|
-
const value = column.accessorFn ? column.accessorFn(row) : column.accessorKey ? row[column.accessorKey] : void 0;
|
|
540
|
-
return String(value ?? "").toLowerCase().includes(query);
|
|
541
|
-
})
|
|
542
|
-
);
|
|
543
|
-
}, [columns, data, globalFilter]);
|
|
544
|
-
const safePageSize = Math.max(1, pageSize);
|
|
545
|
-
const pageCount = Math.max(1, Math.ceil(filteredData.length / safePageSize));
|
|
546
|
-
const safePageIndex = Math.min(pageIndex, pageCount - 1);
|
|
547
|
-
const pageData = filteredData.slice(
|
|
548
|
-
safePageIndex * safePageSize,
|
|
549
|
-
(safePageIndex + 1) * safePageSize
|
|
550
|
-
);
|
|
551
|
-
React2.useEffect(() => {
|
|
552
|
-
setPageIndexState((current) => Math.min(current, pageCount - 1));
|
|
553
|
-
}, [pageCount]);
|
|
554
|
-
const contextValue = React2.useMemo(
|
|
555
|
-
() => ({
|
|
556
|
-
data,
|
|
557
|
-
columns,
|
|
558
|
-
filteredData,
|
|
559
|
-
pageData,
|
|
560
|
-
pageIndex: safePageIndex,
|
|
561
|
-
pageSize: safePageSize,
|
|
562
|
-
pageCount,
|
|
563
|
-
globalFilter,
|
|
564
|
-
isLoading,
|
|
565
|
-
getRowId,
|
|
566
|
-
setGlobalFilter: (value) => {
|
|
567
|
-
setGlobalFilterState(value);
|
|
568
|
-
setPageIndexState(0);
|
|
569
|
-
},
|
|
570
|
-
setPageIndex: (value) => setPageIndexState(Math.max(0, Math.min(value, pageCount - 1)))
|
|
571
|
-
}),
|
|
572
|
-
[
|
|
573
|
-
columns,
|
|
574
|
-
filteredData,
|
|
575
|
-
pageCount,
|
|
576
|
-
pageData,
|
|
577
|
-
safePageIndex,
|
|
578
|
-
safePageSize,
|
|
579
|
-
globalFilter,
|
|
580
|
-
isLoading,
|
|
581
|
-
getRowId
|
|
582
|
-
]
|
|
583
|
-
);
|
|
584
|
-
return /* @__PURE__ */ jsx6(DataTableContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx6("div", { className: cn6("w-full space-y-3", className), children }) });
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
// src/ui/data-table/hooks/use-data-table-pagination.ts
|
|
588
|
-
function useDataTablePagination() {
|
|
589
|
-
const { pageIndex, pageSize, pageCount, setPageIndex } = useDataTable();
|
|
590
|
-
return {
|
|
591
|
-
pageIndex,
|
|
592
|
-
pageSize,
|
|
593
|
-
pageCount,
|
|
594
|
-
canPreviousPage: pageIndex > 0,
|
|
595
|
-
canNextPage: pageIndex < pageCount - 1,
|
|
596
|
-
goToPage: setPageIndex,
|
|
597
|
-
previousPage: () => setPageIndex(pageIndex - 1),
|
|
598
|
-
nextPage: () => setPageIndex(pageIndex + 1),
|
|
599
|
-
firstPage: () => setPageIndex(0),
|
|
600
|
-
lastPage: () => setPageIndex(pageCount - 1)
|
|
601
|
-
};
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
// src/ui/data-table/hooks/use-data-table-rows.ts
|
|
605
|
-
function useDataTableRows() {
|
|
606
|
-
const { data, filteredData, pageData, isLoading } = useDataTable();
|
|
607
|
-
return {
|
|
608
|
-
data,
|
|
609
|
-
rows: pageData,
|
|
610
|
-
pageRows: pageData,
|
|
611
|
-
filteredRows: filteredData,
|
|
612
|
-
totalRows: filteredData.length,
|
|
613
|
-
isLoading
|
|
614
|
-
};
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
// src/ui/data-table/hooks/use-data-table-search.ts
|
|
618
|
-
function useDataTableSearch() {
|
|
619
|
-
const { globalFilter, setGlobalFilter } = useDataTable();
|
|
620
|
-
return {
|
|
621
|
-
search: globalFilter,
|
|
622
|
-
setSearch: setGlobalFilter,
|
|
623
|
-
clearSearch: () => setGlobalFilter("")
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
// src/ui/data-table/data-grid.tsx
|
|
628
|
-
import * as React3 from "react";
|
|
629
|
-
import { cn as cn7 } from "cn";
|
|
630
|
-
import { Fragment, jsx as jsx7, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
631
|
-
function useDataGrid({
|
|
632
|
-
columnIds = [],
|
|
633
|
-
columns,
|
|
634
|
-
initialRows = [],
|
|
635
|
-
getRowId = (row, index) => String(row.id ?? index),
|
|
636
|
-
maxRows = 200
|
|
637
|
-
} = {}) {
|
|
638
|
-
const [rows, setRows] = React3.useState(initialRows);
|
|
639
|
-
const resolvedColumns = React3.useMemo(
|
|
640
|
-
() => columns ?? columnIds.map((id) => ({
|
|
641
|
-
id,
|
|
642
|
-
accessorKey: id,
|
|
643
|
-
header: id
|
|
644
|
-
})),
|
|
645
|
-
[columnIds, columns]
|
|
646
|
-
);
|
|
647
|
-
const getRow = React3.useCallback(
|
|
648
|
-
(rowId) => rows.find((row, index) => getRowId(row, index) === rowId),
|
|
649
|
-
[getRowId, rows]
|
|
650
|
-
);
|
|
651
|
-
const getCellValue = React3.useCallback(
|
|
652
|
-
(rowId, columnId) => {
|
|
653
|
-
const row = getRow(rowId);
|
|
654
|
-
return row?.[columnId];
|
|
655
|
-
},
|
|
656
|
-
[getRow]
|
|
657
|
-
);
|
|
658
|
-
const updateCell = React3.useCallback(
|
|
659
|
-
(rowId, columnId, value) => {
|
|
660
|
-
setRows(
|
|
661
|
-
(current) => current.map(
|
|
662
|
-
(row, index) => getRowId(row, index) === rowId ? { ...row, [columnId]: value } : row
|
|
663
|
-
)
|
|
664
|
-
);
|
|
665
|
-
},
|
|
666
|
-
[getRowId]
|
|
667
|
-
);
|
|
668
|
-
const updateRows = React3.useCallback(
|
|
669
|
-
(updater) => setRows((current) => updater(current).slice(0, maxRows)),
|
|
670
|
-
[maxRows]
|
|
671
|
-
);
|
|
672
|
-
const insertRows = React3.useCallback(
|
|
673
|
-
(nextRows, index = rows.length) => {
|
|
674
|
-
setRows((current) => {
|
|
675
|
-
const safeIndex = Math.max(0, Math.min(index, current.length));
|
|
676
|
-
return [
|
|
677
|
-
...current.slice(0, safeIndex),
|
|
678
|
-
...nextRows,
|
|
679
|
-
...current.slice(safeIndex)
|
|
680
|
-
].slice(0, maxRows);
|
|
681
|
-
});
|
|
682
|
-
},
|
|
683
|
-
[maxRows, rows.length]
|
|
684
|
-
);
|
|
685
|
-
const deleteRows = React3.useCallback(
|
|
686
|
-
(rowIds) => {
|
|
687
|
-
const ids = new Set(rowIds);
|
|
688
|
-
setRows(
|
|
689
|
-
(current) => current.filter((row, index) => !ids.has(getRowId(row, index)))
|
|
690
|
-
);
|
|
691
|
-
},
|
|
692
|
-
[getRowId]
|
|
693
|
-
);
|
|
694
|
-
const moveRow = React3.useCallback(
|
|
695
|
-
(rowId, toIndex) => {
|
|
696
|
-
setRows((current) => {
|
|
697
|
-
const fromIndex = current.findIndex(
|
|
698
|
-
(row2, index) => getRowId(row2, index) === rowId
|
|
699
|
-
);
|
|
700
|
-
if (fromIndex < 0) return current;
|
|
701
|
-
const next = [...current];
|
|
702
|
-
const [row] = next.splice(fromIndex, 1);
|
|
703
|
-
next.splice(Math.max(0, Math.min(toIndex, next.length)), 0, row);
|
|
704
|
-
return next;
|
|
705
|
-
});
|
|
706
|
-
},
|
|
707
|
-
[getRowId]
|
|
708
|
-
);
|
|
709
|
-
return React3.useMemo(
|
|
710
|
-
() => ({
|
|
711
|
-
rows,
|
|
712
|
-
columns: resolvedColumns,
|
|
713
|
-
getRowId,
|
|
714
|
-
getRow,
|
|
715
|
-
getCellValue,
|
|
716
|
-
updateCell,
|
|
717
|
-
updateRows,
|
|
718
|
-
insertRows,
|
|
719
|
-
deleteRows,
|
|
720
|
-
moveRow
|
|
721
|
-
}),
|
|
722
|
-
[
|
|
723
|
-
getCellValue,
|
|
724
|
-
getRow,
|
|
725
|
-
getRowId,
|
|
726
|
-
resolvedColumns,
|
|
727
|
-
rows,
|
|
728
|
-
updateCell,
|
|
729
|
-
updateRows,
|
|
730
|
-
insertRows,
|
|
731
|
-
deleteRows,
|
|
732
|
-
moveRow,
|
|
733
|
-
maxRows
|
|
734
|
-
]
|
|
735
|
-
);
|
|
736
|
-
}
|
|
737
|
-
var DataGridContext = React3.createContext(null);
|
|
738
|
-
function useDataGridContext() {
|
|
739
|
-
const context = React3.useContext(DataGridContext);
|
|
740
|
-
if (!context) throw new Error("DataGrid components must be inside DataGrid");
|
|
741
|
-
return context;
|
|
742
|
-
}
|
|
743
|
-
var DataGridCellContext = React3.createContext(null);
|
|
744
|
-
function DataGrid({
|
|
745
|
-
grid,
|
|
746
|
-
children,
|
|
747
|
-
className
|
|
748
|
-
}) {
|
|
749
|
-
const rootRef = React3.useRef(null);
|
|
750
|
-
const [activeCell, setActiveCell] = React3.useState(null);
|
|
751
|
-
const [selection, setSelection] = React3.useState(null);
|
|
752
|
-
const contextValue = React3.useMemo(
|
|
753
|
-
() => ({
|
|
754
|
-
...grid,
|
|
755
|
-
activeCell,
|
|
756
|
-
selection,
|
|
757
|
-
setActiveCell,
|
|
758
|
-
setSelection,
|
|
759
|
-
rootRef
|
|
760
|
-
}),
|
|
761
|
-
[activeCell, grid, selection]
|
|
762
|
-
);
|
|
763
|
-
function selectedCoordinates() {
|
|
764
|
-
if (!selection) return null;
|
|
765
|
-
const rowIndexes = [
|
|
766
|
-
grid.rows.findIndex((row, index) => grid.getRowId(row, index) === selection.anchor.rowId),
|
|
767
|
-
grid.rows.findIndex((row, index) => grid.getRowId(row, index) === selection.focus.rowId)
|
|
768
|
-
].sort((a, b) => a - b);
|
|
769
|
-
const columnIndexes = [
|
|
770
|
-
grid.columns.findIndex((column) => column.id === selection.anchor.columnId),
|
|
771
|
-
grid.columns.findIndex((column) => column.id === selection.focus.columnId)
|
|
772
|
-
].sort((a, b) => a - b);
|
|
773
|
-
if (rowIndexes.some((index) => index < 0) || columnIndexes.some((index) => index < 0)) return null;
|
|
774
|
-
return { rowIndexes, columnIndexes };
|
|
775
|
-
}
|
|
776
|
-
function focusCell(rowIndex, columnIndex) {
|
|
777
|
-
const row = grid.rows[rowIndex];
|
|
778
|
-
const column = grid.columns[columnIndex];
|
|
779
|
-
if (!row || !column) return;
|
|
780
|
-
const rowId = grid.getRowId(row, rowIndex);
|
|
781
|
-
const cell = rootRef.current?.querySelector(
|
|
782
|
-
`[data-grid-row-id="${CSS.escape(rowId)}"] [data-grid-column-id="${CSS.escape(column.id)}"]`
|
|
783
|
-
);
|
|
784
|
-
cell?.focus();
|
|
785
|
-
}
|
|
786
|
-
function handleCopy(event) {
|
|
787
|
-
const coordinates = selectedCoordinates();
|
|
788
|
-
if (!coordinates) return;
|
|
789
|
-
const value = coordinates.rowIndexes.map(
|
|
790
|
-
(rowIndex) => coordinates.columnIndexes.map(
|
|
791
|
-
(columnIndex) => String(grid.getCellValue(grid.getRowId(grid.rows[rowIndex], rowIndex), grid.columns[columnIndex].id) ?? "")
|
|
792
|
-
).join(" ")
|
|
793
|
-
).join("\n");
|
|
794
|
-
event.preventDefault();
|
|
795
|
-
event.clipboardData.setData("text/plain", value);
|
|
796
|
-
}
|
|
797
|
-
function handlePaste(event) {
|
|
798
|
-
if (!activeCell) return;
|
|
799
|
-
const startRow = grid.rows.findIndex(
|
|
800
|
-
(row, index) => grid.getRowId(row, index) === activeCell.rowId
|
|
801
|
-
);
|
|
802
|
-
const startColumn = grid.columns.findIndex(
|
|
803
|
-
(column) => column.id === activeCell.columnId
|
|
804
|
-
);
|
|
805
|
-
if (startRow < 0 || startColumn < 0) return;
|
|
806
|
-
const matrix = event.clipboardData.getData("text/plain").split(/\r?\n/).map((row) => row.split(" "));
|
|
807
|
-
event.preventDefault();
|
|
808
|
-
grid.updateRows(
|
|
809
|
-
(rows) => rows.map((row, rowIndex) => {
|
|
810
|
-
const values = matrix[rowIndex - startRow];
|
|
811
|
-
if (!values) return row;
|
|
812
|
-
const next = { ...row };
|
|
813
|
-
values.forEach((value, columnOffset) => {
|
|
814
|
-
const column = grid.columns[startColumn + columnOffset];
|
|
815
|
-
if (column) Object.assign(next, { [column.id]: value });
|
|
816
|
-
});
|
|
817
|
-
return next;
|
|
818
|
-
})
|
|
819
|
-
);
|
|
820
|
-
}
|
|
821
|
-
const childArray = React3.Children.toArray(children);
|
|
822
|
-
const headerRows = childArray.filter(
|
|
823
|
-
(child) => React3.isValidElement(child) && Boolean(child.props.header)
|
|
824
|
-
);
|
|
825
|
-
const bodyRows = childArray.filter(
|
|
826
|
-
(child) => !React3.isValidElement(child) || !child.props.header
|
|
827
|
-
);
|
|
828
|
-
return /* @__PURE__ */ jsx7(DataGridContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx7(
|
|
829
|
-
"div",
|
|
830
|
-
{
|
|
831
|
-
ref: rootRef,
|
|
832
|
-
className: cn7("w-full space-y-2 outline-none", className),
|
|
833
|
-
onCopy: handleCopy,
|
|
834
|
-
onPaste: handlePaste,
|
|
835
|
-
children: /* @__PURE__ */ jsxs2("table", { className: "w-full border-collapse text-sm", children: [
|
|
836
|
-
headerRows.length > 0 && /* @__PURE__ */ jsx7("thead", { children: headerRows }),
|
|
837
|
-
/* @__PURE__ */ jsx7("tbody", { children: bodyRows })
|
|
838
|
-
] })
|
|
839
|
-
}
|
|
840
|
-
) });
|
|
841
|
-
}
|
|
842
|
-
function DataGridRow({
|
|
843
|
-
row,
|
|
844
|
-
rowId,
|
|
845
|
-
children,
|
|
846
|
-
header = false,
|
|
847
|
-
className
|
|
848
|
-
}) {
|
|
849
|
-
const grid = useDataGridContext();
|
|
850
|
-
const resolvedRowId = rowId ?? (row ? grid.getRowId(row, 0) : "");
|
|
851
|
-
const resolvedRow = row ?? grid.getRow(resolvedRowId);
|
|
852
|
-
return /* @__PURE__ */ jsx7(
|
|
853
|
-
"tr",
|
|
854
|
-
{
|
|
855
|
-
"data-grid-row-id": resolvedRowId,
|
|
856
|
-
"data-grid-header": header || void 0,
|
|
857
|
-
className: cn7("border-b last:border-0", className),
|
|
858
|
-
children: resolvedRow && children
|
|
859
|
-
}
|
|
860
|
-
);
|
|
861
|
-
}
|
|
862
|
-
function DataGridColumn({
|
|
863
|
-
column,
|
|
864
|
-
children,
|
|
865
|
-
className
|
|
866
|
-
}) {
|
|
867
|
-
return /* @__PURE__ */ jsx7("th", { className: cn7("min-w-0 px-3 py-2 text-left", className), children: children ?? column.header });
|
|
868
|
-
}
|
|
869
|
-
function DataGridCell({
|
|
870
|
-
row,
|
|
871
|
-
rowId,
|
|
872
|
-
columnId,
|
|
873
|
-
children,
|
|
874
|
-
state = "valid",
|
|
875
|
-
className
|
|
876
|
-
}) {
|
|
877
|
-
const grid = useDataGridContext();
|
|
878
|
-
const resolvedRowId = rowId ?? (row ? grid.getRowId(row, 0) : "");
|
|
879
|
-
const value = grid.getCellValue(resolvedRowId, columnId);
|
|
880
|
-
const rowIndex = grid.rows.findIndex(
|
|
881
|
-
(currentRow, index) => grid.getRowId(currentRow, index) === resolvedRowId
|
|
882
|
-
);
|
|
883
|
-
const columnIndex = grid.columns.findIndex((column) => column.id === columnId);
|
|
884
|
-
const isActive = grid.activeCell?.rowId === resolvedRowId && grid.activeCell.columnId === columnId;
|
|
885
|
-
const isSelected = (() => {
|
|
886
|
-
if (!grid.selection) return false;
|
|
887
|
-
const anchorRow = grid.rows.findIndex(
|
|
888
|
-
(currentRow, index) => grid.getRowId(currentRow, index) === grid.selection?.anchor.rowId
|
|
889
|
-
);
|
|
890
|
-
const focusRow = grid.rows.findIndex(
|
|
891
|
-
(currentRow, index) => grid.getRowId(currentRow, index) === grid.selection?.focus.rowId
|
|
892
|
-
);
|
|
893
|
-
const anchorColumn = grid.columns.findIndex(
|
|
894
|
-
(column) => column.id === grid.selection?.anchor.columnId
|
|
895
|
-
);
|
|
896
|
-
const focusColumn = grid.columns.findIndex(
|
|
897
|
-
(column) => column.id === grid.selection?.focus.columnId
|
|
898
|
-
);
|
|
899
|
-
return rowIndex >= Math.min(anchorRow, focusRow) && rowIndex <= Math.max(anchorRow, focusRow) && columnIndex >= Math.min(anchorColumn, focusColumn) && columnIndex <= Math.max(anchorColumn, focusColumn);
|
|
900
|
-
})();
|
|
901
|
-
function focusCell(nextRowIndex, nextColumnIndex) {
|
|
902
|
-
const nextRow = grid.rows[nextRowIndex];
|
|
903
|
-
const nextColumn = grid.columns[nextColumnIndex];
|
|
904
|
-
if (!nextRow || !nextColumn) return;
|
|
905
|
-
const nextRowId = grid.getRowId(nextRow, nextRowIndex);
|
|
906
|
-
grid.setActiveCell({ rowId: nextRowId, columnId: nextColumn.id });
|
|
907
|
-
const nextPosition = { rowId: nextRowId, columnId: nextColumn.id };
|
|
908
|
-
if (grid.activeCell && grid.selection?.anchor && pendingShift.current) {
|
|
909
|
-
grid.setSelection({ anchor: grid.selection.anchor, focus: nextPosition });
|
|
910
|
-
} else {
|
|
911
|
-
grid.setSelection({ anchor: nextPosition, focus: nextPosition });
|
|
912
|
-
}
|
|
913
|
-
const target = grid.rootRef.current?.querySelector(
|
|
914
|
-
`[data-grid-row-id="${CSS.escape(nextRowId)}"] [data-grid-column-id="${CSS.escape(nextColumn.id)}"]`
|
|
915
|
-
);
|
|
916
|
-
target?.focus();
|
|
917
|
-
}
|
|
918
|
-
const pendingShift = React3.useRef(false);
|
|
919
|
-
function fillSelection() {
|
|
920
|
-
if (!grid.selection) return;
|
|
921
|
-
const anchorRow = grid.rows.findIndex(
|
|
922
|
-
(currentRow, index) => grid.getRowId(currentRow, index) === grid.selection?.anchor.rowId
|
|
923
|
-
);
|
|
924
|
-
const focusRow = grid.rows.findIndex(
|
|
925
|
-
(currentRow, index) => grid.getRowId(currentRow, index) === grid.selection?.focus.rowId
|
|
926
|
-
);
|
|
927
|
-
const anchorColumn = grid.columns.findIndex(
|
|
928
|
-
(column) => column.id === grid.selection?.anchor.columnId
|
|
929
|
-
);
|
|
930
|
-
const focusColumn = grid.columns.findIndex(
|
|
931
|
-
(column) => column.id === grid.selection?.focus.columnId
|
|
932
|
-
);
|
|
933
|
-
if (anchorRow < 0 || focusRow < 0 || anchorColumn < 0 || focusColumn < 0) return;
|
|
934
|
-
const source = grid.getCellValue(
|
|
935
|
-
grid.getRowId(grid.rows[anchorRow], anchorRow),
|
|
936
|
-
grid.columns[anchorColumn].id
|
|
937
|
-
);
|
|
938
|
-
const minRow = Math.min(anchorRow, focusRow);
|
|
939
|
-
const maxRow = Math.max(anchorRow, focusRow);
|
|
940
|
-
const minColumn = Math.min(anchorColumn, focusColumn);
|
|
941
|
-
const maxColumn = Math.max(anchorColumn, focusColumn);
|
|
942
|
-
grid.updateRows(
|
|
943
|
-
(rows) => rows.map((row2, rowIndex2) => {
|
|
944
|
-
if (rowIndex2 < minRow || rowIndex2 > maxRow) return row2;
|
|
945
|
-
const next = { ...row2 };
|
|
946
|
-
for (let columnIndex2 = minColumn; columnIndex2 <= maxColumn; columnIndex2 += 1) {
|
|
947
|
-
Object.assign(next, { [grid.columns[columnIndex2].id]: source });
|
|
948
|
-
}
|
|
949
|
-
return next;
|
|
950
|
-
})
|
|
951
|
-
);
|
|
952
|
-
}
|
|
953
|
-
function onKeyDown(event) {
|
|
954
|
-
const target = event.target;
|
|
955
|
-
const isEditor = target.tagName === "INPUT" || target.tagName === "TEXTAREA";
|
|
956
|
-
if (isEditor && ["ArrowLeft", "ArrowRight"].includes(event.key)) return;
|
|
957
|
-
if (event.altKey && (event.key === "ArrowUp" || event.key === "ArrowDown")) {
|
|
958
|
-
event.preventDefault();
|
|
959
|
-
grid.moveRow(resolvedRowId, rowIndex + (event.key === "ArrowUp" ? -1 : 1));
|
|
960
|
-
return;
|
|
961
|
-
}
|
|
962
|
-
let nextRowIndex = rowIndex;
|
|
963
|
-
let nextColumnIndex = columnIndex;
|
|
964
|
-
if (event.key === "ArrowUp") nextRowIndex -= 1;
|
|
965
|
-
if (event.key === "ArrowDown" || event.key === "Enter") nextRowIndex += 1;
|
|
966
|
-
if (event.key === "ArrowLeft") nextColumnIndex -= 1;
|
|
967
|
-
if (event.key === "ArrowRight" || event.key === "Tab") nextColumnIndex += event.shiftKey ? -1 : 1;
|
|
968
|
-
if (event.key === "Home") nextColumnIndex = 0;
|
|
969
|
-
if (event.key === "End") nextColumnIndex = grid.columns.length - 1;
|
|
970
|
-
if (event.key === "PageUp") nextRowIndex = 0;
|
|
971
|
-
if (event.key === "PageDown") nextRowIndex = grid.rows.length - 1;
|
|
972
|
-
if (nextRowIndex === rowIndex && nextColumnIndex === columnIndex) return;
|
|
973
|
-
event.preventDefault();
|
|
974
|
-
pendingShift.current = event.shiftKey;
|
|
975
|
-
focusCell(nextRowIndex, nextColumnIndex);
|
|
976
|
-
pendingShift.current = false;
|
|
977
|
-
}
|
|
978
|
-
const selectionBounds = grid.selection ? {
|
|
979
|
-
minRow: Math.min(
|
|
980
|
-
grid.rows.findIndex((row2, index) => grid.getRowId(row2, index) === grid.selection?.anchor.rowId),
|
|
981
|
-
grid.rows.findIndex((row2, index) => grid.getRowId(row2, index) === grid.selection?.focus.rowId)
|
|
982
|
-
),
|
|
983
|
-
maxRow: Math.max(
|
|
984
|
-
grid.rows.findIndex((row2, index) => grid.getRowId(row2, index) === grid.selection?.anchor.rowId),
|
|
985
|
-
grid.rows.findIndex((row2, index) => grid.getRowId(row2, index) === grid.selection?.focus.rowId)
|
|
986
|
-
),
|
|
987
|
-
minColumn: Math.min(
|
|
988
|
-
grid.columns.findIndex((column) => column.id === grid.selection?.anchor.columnId),
|
|
989
|
-
grid.columns.findIndex((column) => column.id === grid.selection?.focus.columnId)
|
|
990
|
-
),
|
|
991
|
-
maxColumn: Math.max(
|
|
992
|
-
grid.columns.findIndex((column) => column.id === grid.selection?.anchor.columnId),
|
|
993
|
-
grid.columns.findIndex((column) => column.id === grid.selection?.focus.columnId)
|
|
994
|
-
)
|
|
995
|
-
} : null;
|
|
996
|
-
const showFillHandle = selectionBounds && (selectionBounds.minRow !== selectionBounds.maxRow || selectionBounds.minColumn !== selectionBounds.maxColumn) && rowIndex === selectionBounds.maxRow && columnIndex === selectionBounds.maxColumn;
|
|
997
|
-
return /* @__PURE__ */ jsx7(
|
|
998
|
-
DataGridCellContext.Provider,
|
|
999
|
-
{
|
|
1000
|
-
value: { rowId: resolvedRowId, columnId, value },
|
|
1001
|
-
children: /* @__PURE__ */ jsxs2(
|
|
1002
|
-
"td",
|
|
1003
|
-
{
|
|
1004
|
-
"data-grid-row-id": resolvedRowId,
|
|
1005
|
-
"data-grid-column-id": columnId,
|
|
1006
|
-
tabIndex: 0,
|
|
1007
|
-
onFocus: () => {
|
|
1008
|
-
grid.setActiveCell({ rowId: resolvedRowId, columnId });
|
|
1009
|
-
if (!grid.selection) {
|
|
1010
|
-
grid.setSelection({
|
|
1011
|
-
anchor: { rowId: resolvedRowId, columnId },
|
|
1012
|
-
focus: { rowId: resolvedRowId, columnId }
|
|
1013
|
-
});
|
|
1014
|
-
}
|
|
1015
|
-
},
|
|
1016
|
-
onClick: (event) => {
|
|
1017
|
-
if (event.shiftKey && grid.activeCell) {
|
|
1018
|
-
grid.setSelection({ anchor: grid.activeCell, focus: { rowId: resolvedRowId, columnId } });
|
|
1019
|
-
} else {
|
|
1020
|
-
grid.setSelection({
|
|
1021
|
-
anchor: { rowId: resolvedRowId, columnId },
|
|
1022
|
-
focus: { rowId: resolvedRowId, columnId }
|
|
1023
|
-
});
|
|
1024
|
-
}
|
|
1025
|
-
grid.setActiveCell({ rowId: resolvedRowId, columnId });
|
|
1026
|
-
},
|
|
1027
|
-
onKeyDown,
|
|
1028
|
-
"aria-invalid": state === "invalid" || void 0,
|
|
1029
|
-
className: cn7(
|
|
1030
|
-
"relative min-h-9 border-r border-b px-2 py-1.5 align-middle outline-none",
|
|
1031
|
-
isSelected && "bg-accent/40",
|
|
1032
|
-
isActive && "ring-2 ring-inset ring-primary",
|
|
1033
|
-
state === "invalid" && "border-destructive/60 bg-destructive/10",
|
|
1034
|
-
state === "pending" && "opacity-70",
|
|
1035
|
-
className
|
|
1036
|
-
),
|
|
1037
|
-
children: [
|
|
1038
|
-
children,
|
|
1039
|
-
showFillHandle && /* @__PURE__ */ jsx7(
|
|
1040
|
-
"button",
|
|
1041
|
-
{
|
|
1042
|
-
type: "button",
|
|
1043
|
-
"aria-label": "Fill selected cells",
|
|
1044
|
-
className: "absolute right-0 bottom-0 z-10 size-2 cursor-crosshair border border-background bg-primary",
|
|
1045
|
-
onMouseDown: (event) => event.preventDefault(),
|
|
1046
|
-
onClick: fillSelection
|
|
1047
|
-
}
|
|
1048
|
-
)
|
|
1049
|
-
]
|
|
1050
|
-
}
|
|
1051
|
-
)
|
|
1052
|
-
}
|
|
1053
|
-
);
|
|
1054
|
-
}
|
|
1055
|
-
function useGridCell() {
|
|
1056
|
-
const cell = React3.useContext(DataGridCellContext);
|
|
1057
|
-
const grid = useDataGridContext();
|
|
1058
|
-
if (!cell) throw new Error("Grid cell components must be inside DataGridCell");
|
|
1059
|
-
return { ...cell, grid };
|
|
1060
|
-
}
|
|
1061
|
-
function GridTextCell({
|
|
1062
|
-
value,
|
|
1063
|
-
onChange,
|
|
1064
|
-
placeholder
|
|
1065
|
-
}) {
|
|
1066
|
-
const cell = useGridCell();
|
|
1067
|
-
const currentValue = value ?? String(cell.value ?? "");
|
|
1068
|
-
return /* @__PURE__ */ jsx7(
|
|
1069
|
-
Input,
|
|
1070
|
-
{
|
|
1071
|
-
className: "h-7 w-full min-w-0 bg-transparent text-sm outline-none placeholder:text-muted-foreground",
|
|
1072
|
-
onChange: (event) => {
|
|
1073
|
-
const nextValue = event.target.value;
|
|
1074
|
-
onChange?.(nextValue);
|
|
1075
|
-
cell.grid.updateCell(cell.rowId, cell.columnId, nextValue);
|
|
1076
|
-
},
|
|
1077
|
-
placeholder,
|
|
1078
|
-
value: currentValue
|
|
1079
|
-
}
|
|
1080
|
-
);
|
|
1081
|
-
}
|
|
1082
|
-
function GridNumberCell({
|
|
1083
|
-
value,
|
|
1084
|
-
onChange,
|
|
1085
|
-
min,
|
|
1086
|
-
max,
|
|
1087
|
-
step = "any",
|
|
1088
|
-
allowEmpty = true
|
|
1089
|
-
}) {
|
|
1090
|
-
const cell = useGridCell();
|
|
1091
|
-
const currentValue = value ?? (typeof cell.value === "number" ? cell.value : String(cell.value ?? ""));
|
|
1092
|
-
const [invalid, setInvalid] = React3.useState(false);
|
|
1093
|
-
return /* @__PURE__ */ jsx7(
|
|
1094
|
-
Input,
|
|
1095
|
-
{
|
|
1096
|
-
"aria-invalid": invalid || void 0,
|
|
1097
|
-
className: cn7(
|
|
1098
|
-
"h-7 w-full min-w-0 bg-transparent text-sm outline-none",
|
|
1099
|
-
invalid && "border-destructive ring-2 ring-destructive/20"
|
|
1100
|
-
),
|
|
1101
|
-
onChange: (event) => {
|
|
1102
|
-
const rawValue = event.target.value;
|
|
1103
|
-
if (!rawValue && allowEmpty) {
|
|
1104
|
-
setInvalid(false);
|
|
1105
|
-
cell.grid.updateCell(cell.rowId, cell.columnId, "");
|
|
1106
|
-
return;
|
|
1107
|
-
}
|
|
1108
|
-
const nextValue = event.target.valueAsNumber;
|
|
1109
|
-
if (Number.isNaN(nextValue)) return;
|
|
1110
|
-
const nextInvalid = min !== void 0 && nextValue < min || max !== void 0 && nextValue > max;
|
|
1111
|
-
setInvalid(nextInvalid);
|
|
1112
|
-
onChange?.(nextValue);
|
|
1113
|
-
cell.grid.updateCell(cell.rowId, cell.columnId, nextValue);
|
|
1114
|
-
},
|
|
1115
|
-
min,
|
|
1116
|
-
max,
|
|
1117
|
-
step,
|
|
1118
|
-
type: "number",
|
|
1119
|
-
value: currentValue
|
|
1120
|
-
}
|
|
1121
|
-
);
|
|
1122
|
-
}
|
|
1123
|
-
function GridComboboxCell({
|
|
1124
|
-
options,
|
|
1125
|
-
value,
|
|
1126
|
-
onChange
|
|
1127
|
-
}) {
|
|
1128
|
-
const cell = useGridCell();
|
|
1129
|
-
const currentValue = value ?? String(cell.value ?? "");
|
|
1130
|
-
return /* @__PURE__ */ jsxs2(
|
|
1131
|
-
Combobox,
|
|
1132
|
-
{
|
|
1133
|
-
onValueChange: (nextValue) => {
|
|
1134
|
-
if (nextValue === null) return;
|
|
1135
|
-
onChange?.(nextValue);
|
|
1136
|
-
cell.grid.updateCell(cell.rowId, cell.columnId, nextValue);
|
|
1137
|
-
},
|
|
1138
|
-
value: currentValue,
|
|
1139
|
-
children: [
|
|
1140
|
-
/* @__PURE__ */ jsx7(
|
|
1141
|
-
ComboboxInput,
|
|
1142
|
-
{
|
|
1143
|
-
className: "h-7 w-full min-w-0 border-0 bg-transparent px-0 shadow-none",
|
|
1144
|
-
showClear: false
|
|
1145
|
-
}
|
|
1146
|
-
),
|
|
1147
|
-
/* @__PURE__ */ jsx7(ComboboxContent, { children: /* @__PURE__ */ jsx7(ComboboxList, { children: options.map((option) => /* @__PURE__ */ jsx7(ComboboxItem, { value: option.value, children: option.label }, option.value)) }) })
|
|
1148
|
-
]
|
|
1149
|
-
}
|
|
1150
|
-
);
|
|
1151
|
-
}
|
|
1152
|
-
function GridAsyncComboboxCell({
|
|
1153
|
-
value,
|
|
1154
|
-
onChange,
|
|
1155
|
-
loadOptions,
|
|
1156
|
-
placeholder = "Search...",
|
|
1157
|
-
minQueryLength = 0,
|
|
1158
|
-
debounceMs = 250
|
|
1159
|
-
}) {
|
|
1160
|
-
const cell = useGridCell();
|
|
1161
|
-
const selectedValue = value ?? String(cell.value ?? "");
|
|
1162
|
-
const [query, setQuery] = React3.useState("");
|
|
1163
|
-
const [options, setOptions] = React3.useState([]);
|
|
1164
|
-
const [selectedOption, setSelectedOption] = React3.useState(null);
|
|
1165
|
-
const [isLoading, setIsLoading] = React3.useState(false);
|
|
1166
|
-
const requestId = React3.useRef(0);
|
|
1167
|
-
const loadOptionsRef = React3.useRef(loadOptions);
|
|
1168
|
-
React3.useEffect(() => {
|
|
1169
|
-
loadOptionsRef.current = loadOptions;
|
|
1170
|
-
}, [loadOptions]);
|
|
1171
|
-
const stableLoadOptions = React3.useCallback(
|
|
1172
|
-
(search) => loadOptionsRef.current(search),
|
|
1173
|
-
[]
|
|
1174
|
-
);
|
|
1175
|
-
React3.useEffect(() => {
|
|
1176
|
-
const currentRequestId = ++requestId.current;
|
|
1177
|
-
const normalizedQuery = query.trim();
|
|
1178
|
-
if (normalizedQuery.length < minQueryLength) {
|
|
1179
|
-
setOptions([]);
|
|
1180
|
-
setIsLoading(false);
|
|
1181
|
-
return;
|
|
1182
|
-
}
|
|
1183
|
-
const timeout = window.setTimeout(async () => {
|
|
1184
|
-
setIsLoading(true);
|
|
1185
|
-
try {
|
|
1186
|
-
const nextOptions = await stableLoadOptions(normalizedQuery);
|
|
1187
|
-
if (currentRequestId === requestId.current) {
|
|
1188
|
-
setOptions(nextOptions);
|
|
1189
|
-
}
|
|
1190
|
-
} catch {
|
|
1191
|
-
if (currentRequestId === requestId.current) {
|
|
1192
|
-
setOptions([]);
|
|
1193
|
-
}
|
|
1194
|
-
} finally {
|
|
1195
|
-
if (currentRequestId === requestId.current) {
|
|
1196
|
-
setIsLoading(false);
|
|
1197
|
-
}
|
|
1198
|
-
}
|
|
1199
|
-
}, debounceMs);
|
|
1200
|
-
return () => {
|
|
1201
|
-
window.clearTimeout(timeout);
|
|
1202
|
-
if (requestId.current === currentRequestId) {
|
|
1203
|
-
requestId.current += 1;
|
|
1204
|
-
}
|
|
1205
|
-
};
|
|
1206
|
-
}, [debounceMs, minQueryLength, query, stableLoadOptions]);
|
|
1207
|
-
const selectedItem = options.find((option) => option.value === selectedValue) ?? (selectedOption?.value === selectedValue ? selectedOption : null);
|
|
1208
|
-
return /* @__PURE__ */ jsxs2(
|
|
1209
|
-
Combobox,
|
|
1210
|
-
{
|
|
1211
|
-
items: options,
|
|
1212
|
-
itemToStringLabel: (item) => item?.label ?? "",
|
|
1213
|
-
itemToStringValue: (item) => item?.value ?? "",
|
|
1214
|
-
onValueChange: (nextOption) => {
|
|
1215
|
-
if (nextOption === null) return;
|
|
1216
|
-
setSelectedOption(nextOption);
|
|
1217
|
-
onChange?.(nextOption.value, nextOption);
|
|
1218
|
-
cell.grid.updateCell(cell.rowId, cell.columnId, nextOption.value);
|
|
1219
|
-
setQuery(nextOption.label);
|
|
1220
|
-
},
|
|
1221
|
-
value: selectedItem,
|
|
1222
|
-
children: [
|
|
1223
|
-
/* @__PURE__ */ jsx7(
|
|
1224
|
-
ComboboxInput,
|
|
1225
|
-
{
|
|
1226
|
-
className: "h-7 w-full min-w-0 border-0 bg-transparent px-0 shadow-none",
|
|
1227
|
-
onChange: (event) => setQuery(event.target.value),
|
|
1228
|
-
placeholder,
|
|
1229
|
-
showClear: false,
|
|
1230
|
-
value: query
|
|
1231
|
-
}
|
|
1232
|
-
),
|
|
1233
|
-
/* @__PURE__ */ jsxs2(ComboboxContent, { children: [
|
|
1234
|
-
isLoading && /* @__PURE__ */ jsx7(ComboboxEmpty, { children: "Loading..." }),
|
|
1235
|
-
!isLoading && query.trim().length >= minQueryLength && options.length === 0 && /* @__PURE__ */ jsx7(ComboboxEmpty, { children: "No results found." }),
|
|
1236
|
-
/* @__PURE__ */ jsx7(ComboboxList, { children: options.map((option) => /* @__PURE__ */ jsx7(ComboboxItem, { value: option, children: option.label }, option.value)) })
|
|
1237
|
-
] })
|
|
1238
|
-
]
|
|
1239
|
-
}
|
|
1240
|
-
);
|
|
1241
|
-
}
|
|
1242
|
-
function DataTableColumnResize() {
|
|
1243
|
-
return /* @__PURE__ */ jsx7("span", { "aria-hidden": true, className: "absolute inset-y-0 right-0 w-px" });
|
|
1244
|
-
}
|
|
1245
|
-
function DataGridClipboard({
|
|
1246
|
-
children
|
|
1247
|
-
}) {
|
|
1248
|
-
return /* @__PURE__ */ jsx7(Fragment, { children });
|
|
1249
|
-
}
|
|
1250
|
-
function DataGridFillHandle({
|
|
1251
|
-
children
|
|
1252
|
-
}) {
|
|
1253
|
-
return /* @__PURE__ */ jsx7(Fragment, { children });
|
|
1254
|
-
}
|
|
1255
|
-
function DataGridMove({ children }) {
|
|
1256
|
-
return /* @__PURE__ */ jsx7(Fragment, { children });
|
|
1257
|
-
}
|
|
1258
|
-
|
|
1259
|
-
// src/hooks/useMediaQuery.ts
|
|
1260
|
-
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
1261
|
-
function useMediaQuery(query) {
|
|
1262
|
-
const [matches, setMatches] = useState3(false);
|
|
1263
|
-
useEffect3(() => {
|
|
1264
|
-
const mediaQuery = window.matchMedia(query);
|
|
1265
|
-
const handleChange = () => setMatches(mediaQuery.matches);
|
|
1266
|
-
handleChange();
|
|
1267
|
-
mediaQuery.addEventListener("change", handleChange);
|
|
1268
|
-
return () => mediaQuery.removeEventListener("change", handleChange);
|
|
1269
|
-
}, [query]);
|
|
1270
|
-
return matches;
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
|
-
// src/hooks/useMounted.ts
|
|
1274
|
-
import { useEffect as useEffect4, useState as useState4 } from "react";
|
|
1275
|
-
function useMounted() {
|
|
1276
|
-
const [mounted, setMounted] = useState4(false);
|
|
1277
|
-
useEffect4(() => {
|
|
1278
|
-
setMounted(true);
|
|
1279
|
-
}, []);
|
|
1280
|
-
return { mounted };
|
|
1281
|
-
}
|
|
1282
|
-
|
|
1283
|
-
export {
|
|
1284
|
-
buttonVariants,
|
|
1285
|
-
Button,
|
|
1286
|
-
Input,
|
|
1287
|
-
Textarea,
|
|
1288
|
-
InputGroup,
|
|
1289
|
-
InputGroupAddon,
|
|
1290
|
-
InputGroupButton,
|
|
1291
|
-
InputGroupText,
|
|
1292
|
-
InputGroupInput,
|
|
1293
|
-
InputGroupTextarea,
|
|
1294
|
-
Combobox,
|
|
1295
|
-
ComboboxValue,
|
|
1296
|
-
ComboboxTrigger,
|
|
1297
|
-
ComboboxInput,
|
|
1298
|
-
ComboboxContent,
|
|
1299
|
-
ComboboxList,
|
|
1300
|
-
ComboboxItem,
|
|
1301
|
-
ComboboxGroup,
|
|
1302
|
-
ComboboxLabel,
|
|
1303
|
-
ComboboxCollection,
|
|
1304
|
-
ComboboxEmpty,
|
|
1305
|
-
ComboboxSeparator,
|
|
1306
|
-
ComboboxChips,
|
|
1307
|
-
ComboboxChip,
|
|
1308
|
-
ComboboxChipsInput,
|
|
1309
|
-
useComboboxAnchor,
|
|
1310
|
-
useDataTable,
|
|
1311
|
-
DataTableRoot,
|
|
1312
|
-
useDataTablePagination,
|
|
1313
|
-
useDataTableRows,
|
|
1314
|
-
useDataTableSearch,
|
|
1315
|
-
useDataGrid,
|
|
1316
|
-
DataGrid,
|
|
1317
|
-
DataGridRow,
|
|
1318
|
-
DataGridColumn,
|
|
1319
|
-
DataGridCell,
|
|
1320
|
-
GridTextCell,
|
|
1321
|
-
GridNumberCell,
|
|
1322
|
-
GridComboboxCell,
|
|
1323
|
-
GridAsyncComboboxCell,
|
|
1324
|
-
DataTableColumnResize,
|
|
1325
|
-
DataGridClipboard,
|
|
1326
|
-
DataGridFillHandle,
|
|
1327
|
-
DataGridMove,
|
|
1328
|
-
useMediaQuery,
|
|
1329
|
-
useMounted
|
|
1330
|
-
};
|