@bixlab/mtone 0.0.0-stage → 0.1.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/index.js ADDED
@@ -0,0 +1,1928 @@
1
+ "use client";
2
+
3
+ // src/basic.tsx
4
+ import * as React from "react";
5
+ import { Button as BaseButton } from "@base-ui/react/button";
6
+ import { Input as BaseInput } from "@base-ui/react/input";
7
+ import {
8
+ LoaderCircle,
9
+ Search,
10
+ X,
11
+ FileText,
12
+ Inbox,
13
+ Info,
14
+ CheckCircle,
15
+ TriangleAlert,
16
+ AlertCircle
17
+ } from "lucide-react";
18
+ import { jsx, jsxs } from "react/jsx-runtime";
19
+ var cn = (...v) => v.filter(Boolean).join(" ");
20
+ var MtoneContext = React.createContext({
21
+ locale: "zh",
22
+ density: "compact"
23
+ });
24
+ var useMtone = () => React.useContext(MtoneContext);
25
+ function MtoneScope({
26
+ children,
27
+ className,
28
+ style,
29
+ ...props
30
+ }) {
31
+ const c = useMtone();
32
+ return /* @__PURE__ */ jsx(
33
+ "div",
34
+ {
35
+ ...props,
36
+ className: cn("mt-scope", className),
37
+ "data-density": c.density,
38
+ style: { ...c.tokens, ...style },
39
+ children
40
+ }
41
+ );
42
+ }
43
+ function MtoneProvider({
44
+ children,
45
+ locale = "zh",
46
+ density = "compact",
47
+ tokens
48
+ }) {
49
+ return /* @__PURE__ */ jsx(MtoneContext.Provider, { value: { locale, density, tokens }, children: /* @__PURE__ */ jsx(MtoneScope, { children }) });
50
+ }
51
+ var Button = React.forwardRef(
52
+ function Button2({
53
+ variant = "outline",
54
+ size = "md",
55
+ danger,
56
+ loading,
57
+ icon,
58
+ children,
59
+ className,
60
+ disabled,
61
+ ...props
62
+ }, ref) {
63
+ return /* @__PURE__ */ jsxs(
64
+ BaseButton,
65
+ {
66
+ ...props,
67
+ ref,
68
+ disabled: disabled || loading,
69
+ "aria-busy": loading || void 0,
70
+ className: cn(
71
+ "mt-btn",
72
+ `mt-btn-${variant}`,
73
+ `mt-size-${size}`,
74
+ danger && "mt-danger",
75
+ className
76
+ ),
77
+ children: [
78
+ loading ? /* @__PURE__ */ jsx(LoaderCircle, { className: "mt-spin", size: 14 }) : icon,
79
+ children
80
+ ]
81
+ }
82
+ );
83
+ }
84
+ );
85
+ var IconButton = React.forwardRef(function IconButton2(p, r) {
86
+ return /* @__PURE__ */ jsx(Button, { ...p, ref: r, className: cn("mt-icon-btn", p.className) });
87
+ });
88
+ var ButtonGroup = ({
89
+ className,
90
+ ...p
91
+ }) => /* @__PURE__ */ jsx("div", { role: "group", ...p, className: cn("mt-button-group", className) });
92
+ var Input = React.forwardRef(function Input2({ className, ...p }, r) {
93
+ return /* @__PURE__ */ jsx(BaseInput, { ...p, ref: r, className: cn("mt-input", className) });
94
+ });
95
+ var Textarea = React.forwardRef(function Textarea2({ className, ...p }, r) {
96
+ return /* @__PURE__ */ jsx(
97
+ "textarea",
98
+ {
99
+ ...p,
100
+ ref: r,
101
+ className: cn("mt-input mt-textarea", className)
102
+ }
103
+ );
104
+ });
105
+ var SearchInput = React.forwardRef(function SearchInput2(p, r) {
106
+ return /* @__PURE__ */ jsxs("span", { className: "mt-search", children: [
107
+ /* @__PURE__ */ jsx(Search, { size: 15 }),
108
+ /* @__PURE__ */ jsx(Input, { ...p, ref: r })
109
+ ] });
110
+ });
111
+ function FormField({
112
+ label,
113
+ error,
114
+ description,
115
+ required,
116
+ children
117
+ }) {
118
+ const id = React.useId();
119
+ const child = children;
120
+ const inputId = child.props.id || id;
121
+ return /* @__PURE__ */ jsxs("div", { className: "mt-field", children: [
122
+ /* @__PURE__ */ jsxs("label", { htmlFor: inputId, children: [
123
+ label,
124
+ required && /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: " *" })
125
+ ] }),
126
+ React.cloneElement(child, {
127
+ id: inputId,
128
+ required,
129
+ "aria-invalid": !!error,
130
+ "aria-describedby": error || description ? `${id}-help` : void 0
131
+ }),
132
+ (error || description) && /* @__PURE__ */ jsx("div", { id: `${id}-help`, className: cn("mt-help", !!error && "mt-error"), children: error || description })
133
+ ] });
134
+ }
135
+ var Form = ({
136
+ className,
137
+ ...p
138
+ }) => /* @__PURE__ */ jsx("form", { ...p, className: cn("mt-form", className) });
139
+ function Tag({
140
+ children,
141
+ tone = "neutral",
142
+ onRemove,
143
+ className,
144
+ ...p
145
+ }) {
146
+ const { locale } = useMtone();
147
+ return /* @__PURE__ */ jsxs("span", { ...p, className: cn("mt-tag", `mt-tone-${tone}`, className), children: [
148
+ children,
149
+ onRemove && /* @__PURE__ */ jsx(
150
+ "button",
151
+ {
152
+ type: "button",
153
+ onClick: onRemove,
154
+ "aria-label": locale === "zh" ? "\u79FB\u9664\u6807\u7B7E" : "Remove tag",
155
+ children: /* @__PURE__ */ jsx(X, { size: 11 })
156
+ }
157
+ )
158
+ ] });
159
+ }
160
+ var Badge = Tag;
161
+ var Status = ({
162
+ children,
163
+ tone = "neutral"
164
+ }) => /* @__PURE__ */ jsxs("span", { className: cn("mt-status", `mt-tone-${tone}`), children: [
165
+ /* @__PURE__ */ jsx("i", {}),
166
+ children
167
+ ] });
168
+ function Avatar({
169
+ src,
170
+ name = "",
171
+ size = 24
172
+ }) {
173
+ const [failed, setFailed] = React.useState(false);
174
+ React.useEffect(() => setFailed(false), [src]);
175
+ return /* @__PURE__ */ jsx(
176
+ "span",
177
+ {
178
+ className: "mt-avatar",
179
+ style: { width: size, height: size },
180
+ "aria-label": name,
181
+ children: src && !failed ? /* @__PURE__ */ jsx("img", { src, alt: name, onError: () => setFailed(true) }) : name.slice(0, 2).toUpperCase()
182
+ }
183
+ );
184
+ }
185
+ function AvatarGroup({
186
+ items,
187
+ max = 4
188
+ }) {
189
+ return /* @__PURE__ */ jsxs("span", { className: "mt-avatar-group", children: [
190
+ items.slice(0, max).map((x, i) => /* @__PURE__ */ jsx(Avatar, { ...x }, i)),
191
+ items.length > max && /* @__PURE__ */ jsx(Avatar, { name: `+${items.length - max}` })
192
+ ] });
193
+ }
194
+ function Progress({ value, label }) {
195
+ const n = Math.min(100, Math.max(0, Number.isFinite(value) ? value : 0));
196
+ return /* @__PURE__ */ jsx(
197
+ "div",
198
+ {
199
+ className: "mt-progress",
200
+ role: "progressbar",
201
+ "aria-label": label || "Progress",
202
+ "aria-valuemin": 0,
203
+ "aria-valuemax": 100,
204
+ "aria-valuenow": n,
205
+ children: /* @__PURE__ */ jsx("span", { style: { width: `${n}%` } })
206
+ }
207
+ );
208
+ }
209
+ var Text = ({
210
+ muted,
211
+ className,
212
+ ...p
213
+ }) => /* @__PURE__ */ jsx("span", { ...p, className: cn("mt-text", muted && "mt-muted", className) });
214
+ var Divider = () => /* @__PURE__ */ jsx("hr", { className: "mt-divider" });
215
+ var Card = ({
216
+ className,
217
+ ...p
218
+ }) => /* @__PURE__ */ jsx("div", { ...p, className: cn("mt-card", className) });
219
+ var List = ({
220
+ className,
221
+ ...p
222
+ }) => /* @__PURE__ */ jsx("ul", { ...p, className: cn("mt-list", className) });
223
+ function ListItem({
224
+ children,
225
+ icon,
226
+ description,
227
+ actions,
228
+ ...p
229
+ }) {
230
+ return /* @__PURE__ */ jsxs("li", { ...p, className: cn("mt-list-item", p.className), children: [
231
+ icon,
232
+ /* @__PURE__ */ jsxs("div", { className: "mt-list-content", children: [
233
+ /* @__PURE__ */ jsx("div", { children }),
234
+ description && /* @__PURE__ */ jsx("small", { children: description })
235
+ ] }),
236
+ actions
237
+ ] });
238
+ }
239
+ function DocumentList({ items }) {
240
+ return /* @__PURE__ */ jsx(List, { children: items.map((x) => /* @__PURE__ */ jsx(
241
+ ListItem,
242
+ {
243
+ icon: x.icon || /* @__PURE__ */ jsx(FileText, { size: 16 }),
244
+ description: x.description,
245
+ actions: /* @__PURE__ */ jsx("small", { children: x.updatedAt }),
246
+ children: /* @__PURE__ */ jsx("button", { className: "mt-link", type: "button", onClick: x.onClick, children: x.title })
247
+ },
248
+ x.id
249
+ )) });
250
+ }
251
+ function DocumentCard({
252
+ title,
253
+ description,
254
+ icon,
255
+ updatedAt,
256
+ onClick
257
+ }) {
258
+ return /* @__PURE__ */ jsxs(Card, { children: [
259
+ /* @__PURE__ */ jsx("div", { className: "mt-doc-icon", children: icon || /* @__PURE__ */ jsx(FileText, { size: 20 }) }),
260
+ /* @__PURE__ */ jsx("button", { type: "button", className: "mt-link", onClick, children: title }),
261
+ /* @__PURE__ */ jsx("p", { className: "mt-muted", children: description }),
262
+ /* @__PURE__ */ jsx("small", { children: updatedAt })
263
+ ] });
264
+ }
265
+ var PropertyList = ({ children }) => /* @__PURE__ */ jsx("dl", { className: "mt-properties", children });
266
+ var PropertyItem = ({
267
+ label,
268
+ children
269
+ }) => /* @__PURE__ */ jsxs("div", { children: [
270
+ /* @__PURE__ */ jsx("dt", { children: label }),
271
+ /* @__PURE__ */ jsx("dd", { children })
272
+ ] });
273
+ function Alert({
274
+ tone = "info",
275
+ title,
276
+ children,
277
+ onClose
278
+ }) {
279
+ const Icon = {
280
+ info: Info,
281
+ success: CheckCircle,
282
+ warning: TriangleAlert,
283
+ error: AlertCircle
284
+ }[tone];
285
+ return /* @__PURE__ */ jsxs(
286
+ "div",
287
+ {
288
+ role: tone === "error" ? "alert" : "status",
289
+ className: cn("mt-alert", `mt-alert-${tone}`),
290
+ children: [
291
+ /* @__PURE__ */ jsx(Icon, { size: 16 }),
292
+ /* @__PURE__ */ jsxs("div", { children: [
293
+ title && /* @__PURE__ */ jsx("strong", { children: title }),
294
+ children && /* @__PURE__ */ jsx("div", { children })
295
+ ] }),
296
+ onClose && /* @__PURE__ */ jsx(IconButton, { "aria-label": "Close", variant: "ghost", onClick: onClose, children: /* @__PURE__ */ jsx(X, { size: 14 }) })
297
+ ]
298
+ }
299
+ );
300
+ }
301
+ function Empty({
302
+ title,
303
+ description,
304
+ action
305
+ }) {
306
+ const { locale } = useMtone();
307
+ return /* @__PURE__ */ jsxs("div", { className: "mt-empty", children: [
308
+ /* @__PURE__ */ jsx(Inbox, { size: 28 }),
309
+ /* @__PURE__ */ jsx("strong", { children: title || (locale === "zh" ? "\u6682\u65E0\u5185\u5BB9" : "No content") }),
310
+ description && /* @__PURE__ */ jsx("span", { children: description }),
311
+ action
312
+ ] });
313
+ }
314
+ var Skeleton = ({
315
+ className,
316
+ ...p
317
+ }) => /* @__PURE__ */ jsx("div", { "aria-hidden": "true", ...p, className: cn("mt-skeleton", className) });
318
+ function Spinner({ label = "Loading" }) {
319
+ return /* @__PURE__ */ jsx("span", { className: "mt-spinner", role: "status", "aria-label": label, children: /* @__PURE__ */ jsx(LoaderCircle, { size: 16, className: "mt-spin" }) });
320
+ }
321
+
322
+ // src/navigation.tsx
323
+ import * as React3 from "react";
324
+ import {
325
+ ChevronRight,
326
+ X as X2,
327
+ PanelLeftClose,
328
+ PanelLeftOpen,
329
+ Circle
330
+ } from "lucide-react";
331
+
332
+ // src/interactive.tsx
333
+ import { useId as useId2, useState as useState2 } from "react";
334
+ import { Checkbox as BCheckbox } from "@base-ui/react/checkbox";
335
+ import { Switch as BSwitch } from "@base-ui/react/switch";
336
+ import { Radio as BRadio } from "@base-ui/react/radio";
337
+ import { RadioGroup as BRadioGroup } from "@base-ui/react/radio-group";
338
+ import { Select as BSelect } from "@base-ui/react/select";
339
+ import { Combobox } from "@base-ui/react/combobox";
340
+ import { Slider as BSlider } from "@base-ui/react/slider";
341
+ import { NumberField } from "@base-ui/react/number-field";
342
+ import { Tabs as BTabs } from "@base-ui/react/tabs";
343
+ import { Menu } from "@base-ui/react/menu";
344
+ import { ContextMenu as BContextMenu } from "@base-ui/react/context-menu";
345
+ import { Popover as BPopover } from "@base-ui/react/popover";
346
+ import { Tooltip as BTooltip } from "@base-ui/react/tooltip";
347
+ import { Dialog } from "@base-ui/react/dialog";
348
+ import { AlertDialog } from "@base-ui/react/alert-dialog";
349
+ import { Drawer as BDrawer } from "@base-ui/react/drawer";
350
+
351
+ // src/toast.tsx
352
+ import { CircleCheck, CircleX, Info as Info2, LoaderCircle as LoaderCircle2 } from "lucide-react";
353
+ import {
354
+ Toast as BToast
355
+ } from "@base-ui/react/toast";
356
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
357
+ function normalize(options, previous) {
358
+ const { body, position, children, data, ...rest } = options;
359
+ const meta = { ...previous?.data?.__mtoneToast };
360
+ if ("position" in options) meta.position = position;
361
+ if ("children" in options) meta.children = children;
362
+ return {
363
+ ...rest,
364
+ ..."body" in options ? { description: body } : {},
365
+ ..."data" in options || "position" in options || "children" in options ? {
366
+ data: {
367
+ ...previous?.data,
368
+ ...data,
369
+ __mtoneToast: meta
370
+ }
371
+ } : {}
372
+ };
373
+ }
374
+ function useToast() {
375
+ const manager = BToast.useToastManager();
376
+ const add = (options) => manager.add(
377
+ normalize(
378
+ options,
379
+ manager.toasts.find((t) => t.id === options.id)
380
+ )
381
+ );
382
+ const update = (id, options) => {
383
+ manager.update(
384
+ id,
385
+ (previous) => normalize(
386
+ typeof options === "function" ? options(previous) : options,
387
+ previous
388
+ )
389
+ );
390
+ };
391
+ const promise = (value, options) => {
392
+ const loading = typeof options.loading === "string" ? void 0 : options.loading;
393
+ const convert = (item) => typeof item === "string" ? item : normalize({
394
+ data: loading?.data,
395
+ position: loading?.position,
396
+ children: loading?.children,
397
+ ...item
398
+ });
399
+ const mapped = {
400
+ loading: convert(options.loading),
401
+ success: typeof options.success === "function" ? (result) => convert(
402
+ options.success(result)
403
+ ) : convert(options.success),
404
+ error: typeof options.error === "function" ? (error) => convert(
405
+ options.error(error)
406
+ ) : convert(options.error)
407
+ };
408
+ return manager.promise(value, mapped);
409
+ };
410
+ return {
411
+ ...manager,
412
+ add,
413
+ update,
414
+ promise,
415
+ success: (options) => add({ ...options, type: "success" }),
416
+ error: (options) => add({ ...options, type: "error" }),
417
+ info: (options) => add({ ...options, type: "info" })
418
+ };
419
+ }
420
+ var positions = [
421
+ "top-right",
422
+ "bottom-right",
423
+ "top-left",
424
+ "bottom-left",
425
+ "top-center",
426
+ "bottom-center",
427
+ "center",
428
+ "center-top"
429
+ ];
430
+ function ToastViewport({
431
+ position,
432
+ limit
433
+ }) {
434
+ const { toasts } = BToast.useToastManager();
435
+ const { locale } = useMtone();
436
+ const placement = (t) => positions.includes(t.data?.__mtoneToast?.position) ? t.data.__mtoneToast.position : position;
437
+ return /* @__PURE__ */ jsx2(BToast.Portal, { children: /* @__PURE__ */ jsx2(MtoneScope, { children: /* @__PURE__ */ jsx2(
438
+ BToast.Viewport,
439
+ {
440
+ className: "mt-toast-viewport",
441
+ "aria-label": locale === "zh" ? "\u901A\u77E5" : "Notifications",
442
+ children: toasts.map((t) => {
443
+ const peers = toasts.filter(
444
+ (other) => !other.limited && placement(other) === placement(t)
445
+ );
446
+ const index = peers.findIndex((other) => other.id === t.id);
447
+ const offset = peers.slice(0, Math.max(0, index)).reduce((sum, item) => sum + (item.height ?? 0) + 10, 0);
448
+ const total = peers.reduce((sum, item) => sum + (item.height ?? 0), 0) + Math.max(0, peers.length - 1) * 10;
449
+ const type = t.type === "success" || t.type === "error" || t.type === "loading" ? t.type : "info";
450
+ const Icon = type === "success" ? CircleCheck : type === "error" ? CircleX : type === "loading" ? LoaderCircle2 : Info2;
451
+ return /* @__PURE__ */ jsx2(
452
+ "div",
453
+ {
454
+ className: "mt-toast-stack",
455
+ "data-position": placement(t),
456
+ style: {
457
+ "--mt-toast-offset": `${offset}px`,
458
+ "--mt-toast-total": `${total}px`,
459
+ "--mt-toast-limit": Math.max(1, limit)
460
+ },
461
+ children: /* @__PURE__ */ jsx2(BToast.Root, { toast: t, className: "mt-toast", "data-type": type, children: /* @__PURE__ */ jsxs2(BToast.Content, { className: "mt-toast-content", children: [
462
+ /* @__PURE__ */ jsx2(
463
+ Icon,
464
+ {
465
+ className: `mt-toast-icon${type === "loading" ? " mt-spin" : ""}`,
466
+ size: 18,
467
+ "aria-hidden": "true"
468
+ }
469
+ ),
470
+ t.title != null && /* @__PURE__ */ jsx2(BToast.Title, { className: "mt-toast-title" }),
471
+ t.description != null && /* @__PURE__ */ jsx2(BToast.Description, { className: "mt-toast-description" }),
472
+ t.data?.__mtoneToast?.children != null && /* @__PURE__ */ jsx2("div", { className: "mt-toast-custom", children: t.data.__mtoneToast.children }, "custom"),
473
+ t.actionProps && /* @__PURE__ */ jsx2(BToast.Action, { className: "mt-action mt-toast-action" }),
474
+ /* @__PURE__ */ jsx2(
475
+ BToast.Close,
476
+ {
477
+ className: "mt-dialog-close",
478
+ "aria-label": locale === "zh" ? "\u5173\u95ED" : "Close",
479
+ children: "\xD7"
480
+ }
481
+ )
482
+ ] }) })
483
+ },
484
+ t.id
485
+ );
486
+ })
487
+ }
488
+ ) }) });
489
+ }
490
+ function ToastProvider({
491
+ children,
492
+ timeout = 5e3,
493
+ limit = 3,
494
+ position = "bottom-right"
495
+ }) {
496
+ return /* @__PURE__ */ jsxs2(BToast.Provider, { timeout, limit, children: [
497
+ children,
498
+ /* @__PURE__ */ jsx2(ToastViewport, { position, limit })
499
+ ] });
500
+ }
501
+ var Toast = ToastProvider;
502
+
503
+ // src/interactive.tsx
504
+ import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
505
+ function Checkbox({
506
+ label,
507
+ children,
508
+ className,
509
+ ...props
510
+ }) {
511
+ return /* @__PURE__ */ jsxs3("label", { className: cn("mt-check-label", className), children: [
512
+ /* @__PURE__ */ jsx3(BCheckbox.Root, { className: "mt-checkbox", ...props, children: /* @__PURE__ */ jsx3(BCheckbox.Indicator, { className: "mt-check-indicator", children: props.indeterminate ? "\u2212" : "\u2713" }) }),
513
+ label ?? children
514
+ ] });
515
+ }
516
+ function Switch({
517
+ label,
518
+ children,
519
+ className,
520
+ ...props
521
+ }) {
522
+ return /* @__PURE__ */ jsxs3("label", { className: cn("mt-check-label", className), children: [
523
+ /* @__PURE__ */ jsx3(BSwitch.Root, { className: "mt-switch", ...props, children: /* @__PURE__ */ jsx3(BSwitch.Thumb, { className: "mt-switch-thumb" }) }),
524
+ label ?? children
525
+ ] });
526
+ }
527
+ function RadioGroup({
528
+ options,
529
+ label,
530
+ className,
531
+ orientation = "vertical",
532
+ ...props
533
+ }) {
534
+ return /* @__PURE__ */ jsx3(
535
+ BRadioGroup,
536
+ {
537
+ "aria-label": label,
538
+ className: cn("mt-radio-group", `mt-${orientation}`, className),
539
+ ...props,
540
+ children: options.map((o) => /* @__PURE__ */ jsxs3("label", { className: "mt-check-label", children: [
541
+ /* @__PURE__ */ jsx3(
542
+ BRadio.Root,
543
+ {
544
+ value: o.value,
545
+ disabled: o.disabled,
546
+ className: "mt-radio",
547
+ children: /* @__PURE__ */ jsx3(BRadio.Indicator, { className: "mt-radio-indicator" })
548
+ }
549
+ ),
550
+ o.label
551
+ ] }, o.value))
552
+ }
553
+ );
554
+ }
555
+ function Select({
556
+ options,
557
+ label,
558
+ placeholder,
559
+ className,
560
+ ...props
561
+ }) {
562
+ const { locale } = useMtone();
563
+ return /* @__PURE__ */ jsxs3(BSelect.Root, { items: options, ...props, children: [
564
+ /* @__PURE__ */ jsxs3(
565
+ BSelect.Trigger,
566
+ {
567
+ "aria-label": label,
568
+ className: cn("mt-select", className),
569
+ children: [
570
+ /* @__PURE__ */ jsx3(
571
+ BSelect.Value,
572
+ {
573
+ placeholder: placeholder ?? (locale === "zh" ? "\u8BF7\u9009\u62E9" : "Select\u2026")
574
+ }
575
+ ),
576
+ /* @__PURE__ */ jsx3(BSelect.Icon, { className: "mt-select-icon", children: "\u2304" })
577
+ ]
578
+ }
579
+ ),
580
+ /* @__PURE__ */ jsx3(BSelect.Portal, { children: /* @__PURE__ */ jsx3(MtoneScope, { children: /* @__PURE__ */ jsx3(
581
+ BSelect.Positioner,
582
+ {
583
+ className: "mt-positioner",
584
+ sideOffset: 4,
585
+ alignItemWithTrigger: false,
586
+ children: /* @__PURE__ */ jsx3(BSelect.Popup, { className: "mt-popup", children: /* @__PURE__ */ jsx3(BSelect.List, { children: options.map((o) => /* @__PURE__ */ jsxs3(
587
+ BSelect.Item,
588
+ {
589
+ className: "mt-option",
590
+ value: o.value,
591
+ disabled: o.disabled,
592
+ children: [
593
+ /* @__PURE__ */ jsx3(BSelect.ItemText, { children: o.label }),
594
+ /* @__PURE__ */ jsx3(BSelect.ItemIndicator, { children: "\u2713" })
595
+ ]
596
+ },
597
+ o.value
598
+ )) }) })
599
+ }
600
+ ) }) })
601
+ ] });
602
+ }
603
+ function MultiSelect({
604
+ options,
605
+ label,
606
+ placeholder,
607
+ className,
608
+ ...props
609
+ }) {
610
+ const { locale } = useMtone();
611
+ const values = options.map((o) => o.value);
612
+ const labelFor = (v) => String(options.find((o) => o.value === v)?.label ?? v);
613
+ return /* @__PURE__ */ jsxs3(
614
+ Combobox.Root,
615
+ {
616
+ multiple: true,
617
+ items: values,
618
+ itemToStringLabel: labelFor,
619
+ ...props,
620
+ children: [
621
+ /* @__PURE__ */ jsxs3(Combobox.Chips, { className: cn("mt-multiselect", className), children: [
622
+ /* @__PURE__ */ jsx3(Combobox.Value, { children: (selected) => /* @__PURE__ */ jsx3(Fragment, { children: selected.map((v) => /* @__PURE__ */ jsxs3(Combobox.Chip, { className: "mt-chip", children: [
623
+ labelFor(v),
624
+ /* @__PURE__ */ jsx3(
625
+ Combobox.ChipRemove,
626
+ {
627
+ "aria-label": `${locale === "zh" ? "\u79FB\u9664" : "Remove"} ${labelFor(v)}`,
628
+ className: "mt-chip-remove",
629
+ children: "\xD7"
630
+ }
631
+ )
632
+ ] }, v)) }) }),
633
+ /* @__PURE__ */ jsx3(
634
+ Combobox.Input,
635
+ {
636
+ "aria-label": label,
637
+ placeholder: placeholder ?? (locale === "zh" ? "\u641C\u7D22\u2026" : "Search\u2026"),
638
+ className: "mt-combobox-input"
639
+ }
640
+ ),
641
+ /* @__PURE__ */ jsx3(
642
+ Combobox.Trigger,
643
+ {
644
+ className: "mt-combobox-trigger",
645
+ "aria-label": locale === "zh" ? "\u5C55\u5F00\u9009\u9879" : "Show options",
646
+ children: "\u2304"
647
+ }
648
+ )
649
+ ] }),
650
+ /* @__PURE__ */ jsx3(Combobox.Portal, { children: /* @__PURE__ */ jsx3(MtoneScope, { children: /* @__PURE__ */ jsx3(Combobox.Positioner, { className: "mt-positioner", sideOffset: 4, children: /* @__PURE__ */ jsxs3(Combobox.Popup, { className: "mt-popup", children: [
651
+ /* @__PURE__ */ jsx3(Combobox.Empty, { className: "mt-combobox-empty", children: locale === "zh" ? "\u65E0\u5339\u914D\u7ED3\u679C" : "No results" }),
652
+ /* @__PURE__ */ jsx3(Combobox.List, { children: (v) => /* @__PURE__ */ jsxs3(
653
+ Combobox.Item,
654
+ {
655
+ className: "mt-option",
656
+ value: v,
657
+ disabled: options.find((o) => o.value === v)?.disabled,
658
+ children: [
659
+ labelFor(v),
660
+ /* @__PURE__ */ jsx3(Combobox.ItemIndicator, { children: "\u2713" })
661
+ ]
662
+ },
663
+ v
664
+ ) })
665
+ ] }) }) }) })
666
+ ]
667
+ }
668
+ );
669
+ }
670
+ function Slider({ label, className, ...props }) {
671
+ return /* @__PURE__ */ jsx3(BSlider.Root, { className: cn("mt-slider", className), ...props, children: /* @__PURE__ */ jsx3(BSlider.Control, { className: "mt-slider-control", children: /* @__PURE__ */ jsxs3(BSlider.Track, { className: "mt-slider-track", children: [
672
+ /* @__PURE__ */ jsx3(BSlider.Indicator, { className: "mt-slider-indicator" }),
673
+ /* @__PURE__ */ jsx3(BSlider.Thumb, { className: "mt-slider-thumb", "aria-label": label })
674
+ ] }) }) });
675
+ }
676
+ function NumberInput({ label, className, ...props }) {
677
+ const { locale } = useMtone();
678
+ return /* @__PURE__ */ jsx3(NumberField.Root, { className: cn("mt-number", className), ...props, children: /* @__PURE__ */ jsxs3(NumberField.Group, { className: "mt-number-group", children: [
679
+ /* @__PURE__ */ jsx3(
680
+ NumberField.Decrement,
681
+ {
682
+ "aria-label": locale === "zh" ? "\u51CF\u5C11" : "Decrease",
683
+ className: "mt-number-step",
684
+ children: "\u2212"
685
+ }
686
+ ),
687
+ /* @__PURE__ */ jsx3(NumberField.Input, { className: "mt-number-input", "aria-label": label }),
688
+ /* @__PURE__ */ jsx3(
689
+ NumberField.Increment,
690
+ {
691
+ "aria-label": locale === "zh" ? "\u589E\u52A0" : "Increase",
692
+ className: "mt-number-step",
693
+ children: "+"
694
+ }
695
+ )
696
+ ] }) });
697
+ }
698
+ function Tabs({
699
+ items,
700
+ className,
701
+ onValueChange,
702
+ defaultValue,
703
+ ...props
704
+ }) {
705
+ return /* @__PURE__ */ jsxs3(
706
+ BTabs.Root,
707
+ {
708
+ className: cn("mt-tabs", className),
709
+ defaultValue: defaultValue ?? items[0]?.value,
710
+ onValueChange: (v) => onValueChange?.(String(v)),
711
+ ...props,
712
+ children: [
713
+ /* @__PURE__ */ jsx3(BTabs.List, { className: "mt-tab-list", children: items.map((i) => /* @__PURE__ */ jsx3(
714
+ BTabs.Tab,
715
+ {
716
+ className: "mt-tab",
717
+ value: i.value,
718
+ disabled: i.disabled,
719
+ children: i.label
720
+ },
721
+ i.value
722
+ )) }),
723
+ items.map((i) => /* @__PURE__ */ jsx3(BTabs.Panel, { className: "mt-tab-panel", value: i.value, children: i.content }, i.value))
724
+ ]
725
+ }
726
+ );
727
+ }
728
+ function Segmented({
729
+ options,
730
+ label,
731
+ className,
732
+ ...props
733
+ }) {
734
+ return /* @__PURE__ */ jsx3(
735
+ BRadioGroup,
736
+ {
737
+ className: cn("mt-segmented", className),
738
+ "aria-label": label,
739
+ ...props,
740
+ children: options.map((o) => /* @__PURE__ */ jsx3(
741
+ BRadio.Root,
742
+ {
743
+ value: o.value,
744
+ disabled: o.disabled,
745
+ className: "mt-segment",
746
+ children: o.label
747
+ },
748
+ o.value
749
+ ))
750
+ }
751
+ );
752
+ }
753
+ function MenuItems({
754
+ items,
755
+ onSelect
756
+ }) {
757
+ return /* @__PURE__ */ jsx3(Fragment, { children: items.map((i) => /* @__PURE__ */ jsxs3(
758
+ Menu.Item,
759
+ {
760
+ className: cn("mt-menu-item", i.danger ? "mt-danger" : ""),
761
+ disabled: i.disabled,
762
+ onClick: () => {
763
+ i.onSelect?.();
764
+ onSelect?.(i.key);
765
+ },
766
+ children: [
767
+ /* @__PURE__ */ jsxs3("span", { className: "mt-menu-label", children: [
768
+ i.icon && /* @__PURE__ */ jsx3("span", { "aria-hidden": "true", className: "mt-menu-icon", children: i.icon }),
769
+ i.label
770
+ ] }),
771
+ i.shortcut && /* @__PURE__ */ jsx3("span", { className: "mt-shortcut", children: i.shortcut })
772
+ ]
773
+ },
774
+ i.key
775
+ )) });
776
+ }
777
+ function DropdownMenu({
778
+ trigger,
779
+ items,
780
+ onSelect,
781
+ ...props
782
+ }) {
783
+ return /* @__PURE__ */ jsxs3(Menu.Root, { ...props, children: [
784
+ /* @__PURE__ */ jsx3(Menu.Trigger, { render: trigger }),
785
+ /* @__PURE__ */ jsx3(Menu.Portal, { children: /* @__PURE__ */ jsx3(MtoneScope, { children: /* @__PURE__ */ jsx3(
786
+ Menu.Positioner,
787
+ {
788
+ className: "mt-positioner",
789
+ sideOffset: 4,
790
+ align: "start",
791
+ children: /* @__PURE__ */ jsx3(Menu.Popup, { className: "mt-popup", children: /* @__PURE__ */ jsx3(MenuItems, { items, onSelect }) })
792
+ }
793
+ ) }) })
794
+ ] });
795
+ }
796
+ function ContextMenu({
797
+ children,
798
+ items,
799
+ onSelect,
800
+ ...props
801
+ }) {
802
+ return /* @__PURE__ */ jsxs3(BContextMenu.Root, { ...props, children: [
803
+ /* @__PURE__ */ jsx3(BContextMenu.Trigger, { children }),
804
+ /* @__PURE__ */ jsx3(BContextMenu.Portal, { children: /* @__PURE__ */ jsx3(MtoneScope, { children: /* @__PURE__ */ jsx3(BContextMenu.Positioner, { className: "mt-positioner", children: /* @__PURE__ */ jsx3(BContextMenu.Popup, { className: "mt-popup", children: /* @__PURE__ */ jsx3(MenuItems, { items, onSelect }) }) }) }) })
805
+ ] });
806
+ }
807
+ function Popover({
808
+ trigger,
809
+ content,
810
+ title,
811
+ side = "bottom",
812
+ ...props
813
+ }) {
814
+ return /* @__PURE__ */ jsxs3(BPopover.Root, { ...props, children: [
815
+ /* @__PURE__ */ jsx3(BPopover.Trigger, { render: trigger }),
816
+ /* @__PURE__ */ jsx3(BPopover.Portal, { children: /* @__PURE__ */ jsx3(MtoneScope, { children: /* @__PURE__ */ jsx3(
817
+ BPopover.Positioner,
818
+ {
819
+ className: "mt-positioner",
820
+ sideOffset: 6,
821
+ side,
822
+ children: /* @__PURE__ */ jsxs3(BPopover.Popup, { className: "mt-popup mt-popover", children: [
823
+ title && /* @__PURE__ */ jsx3(BPopover.Title, { className: "mt-popup-title", children: title }),
824
+ content
825
+ ] })
826
+ }
827
+ ) }) })
828
+ ] });
829
+ }
830
+ function Tooltip({
831
+ children,
832
+ content,
833
+ side = "top",
834
+ ...props
835
+ }) {
836
+ const id = useId2();
837
+ return /* @__PURE__ */ jsx3(BTooltip.Provider, { children: /* @__PURE__ */ jsxs3(BTooltip.Root, { ...props, children: [
838
+ /* @__PURE__ */ jsx3(BTooltip.Trigger, { render: children, "aria-describedby": id }),
839
+ /* @__PURE__ */ jsx3(BTooltip.Portal, { children: /* @__PURE__ */ jsx3(MtoneScope, { children: /* @__PURE__ */ jsx3(
840
+ BTooltip.Positioner,
841
+ {
842
+ className: "mt-positioner",
843
+ sideOffset: 6,
844
+ side,
845
+ children: /* @__PURE__ */ jsx3(BTooltip.Popup, { className: "mt-tooltip", role: "tooltip", id, children: content })
846
+ }
847
+ ) }) })
848
+ ] }) });
849
+ }
850
+ function Modal({
851
+ title,
852
+ description,
853
+ children,
854
+ footer,
855
+ trigger,
856
+ className,
857
+ ...props
858
+ }) {
859
+ const { locale } = useMtone();
860
+ return /* @__PURE__ */ jsxs3(Dialog.Root, { ...props, children: [
861
+ trigger && /* @__PURE__ */ jsx3(Dialog.Trigger, { render: trigger }),
862
+ /* @__PURE__ */ jsx3(Dialog.Portal, { children: /* @__PURE__ */ jsxs3(MtoneScope, { children: [
863
+ /* @__PURE__ */ jsx3(Dialog.Backdrop, { className: "mt-backdrop" }),
864
+ /* @__PURE__ */ jsxs3(Dialog.Popup, { className: cn("mt-modal", className), children: [
865
+ /* @__PURE__ */ jsx3(Dialog.Title, { className: "mt-dialog-title", children: title }),
866
+ description && /* @__PURE__ */ jsx3(Dialog.Description, { className: "mt-dialog-description", children: description }),
867
+ /* @__PURE__ */ jsx3(
868
+ Dialog.Close,
869
+ {
870
+ className: "mt-dialog-close",
871
+ "aria-label": locale === "zh" ? "\u5173\u95ED" : "Close",
872
+ children: "\xD7"
873
+ }
874
+ ),
875
+ /* @__PURE__ */ jsx3("div", { className: "mt-dialog-body", children }),
876
+ footer && /* @__PURE__ */ jsx3("div", { className: "mt-dialog-footer", children: footer })
877
+ ] })
878
+ ] }) })
879
+ ] });
880
+ }
881
+ function ConfirmDialog({
882
+ title,
883
+ description,
884
+ children,
885
+ trigger,
886
+ confirmText,
887
+ cancelText,
888
+ onConfirm,
889
+ danger,
890
+ open,
891
+ defaultOpen,
892
+ onOpenChange
893
+ }) {
894
+ const { locale } = useMtone();
895
+ const [localOpen, setOpen] = useState2(defaultOpen ?? false);
896
+ const [pending, setPending] = useState2(false);
897
+ const [error, setError] = useState2(false);
898
+ const change = (v) => {
899
+ setOpen(v);
900
+ onOpenChange?.(v);
901
+ };
902
+ const confirm = async () => {
903
+ setPending(true);
904
+ setError(false);
905
+ try {
906
+ await onConfirm?.();
907
+ change(false);
908
+ } catch {
909
+ setError(true);
910
+ } finally {
911
+ setPending(false);
912
+ }
913
+ };
914
+ return /* @__PURE__ */ jsxs3(AlertDialog.Root, { open: open ?? localOpen, onOpenChange: change, children: [
915
+ trigger && /* @__PURE__ */ jsx3(AlertDialog.Trigger, { render: trigger }),
916
+ /* @__PURE__ */ jsx3(AlertDialog.Portal, { children: /* @__PURE__ */ jsxs3(MtoneScope, { children: [
917
+ /* @__PURE__ */ jsx3(AlertDialog.Backdrop, { className: "mt-backdrop" }),
918
+ /* @__PURE__ */ jsxs3(AlertDialog.Popup, { className: "mt-modal", children: [
919
+ /* @__PURE__ */ jsx3(AlertDialog.Title, { className: "mt-dialog-title", children: title }),
920
+ description && /* @__PURE__ */ jsx3(AlertDialog.Description, { className: "mt-dialog-description", children: description }),
921
+ children,
922
+ error && /* @__PURE__ */ jsx3("p", { role: "alert", children: locale === "zh" ? "\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002" : "Something went wrong. Please try again." }),
923
+ /* @__PURE__ */ jsxs3("div", { className: "mt-dialog-footer", children: [
924
+ /* @__PURE__ */ jsx3(AlertDialog.Close, { className: "mt-action", disabled: pending, children: cancelText ?? (locale === "zh" ? "\u53D6\u6D88" : "Cancel") }),
925
+ /* @__PURE__ */ jsx3(
926
+ "button",
927
+ {
928
+ className: cn(
929
+ "mt-action",
930
+ "mt-action-primary",
931
+ danger ? "mt-action-danger" : ""
932
+ ),
933
+ disabled: pending,
934
+ onClick: confirm,
935
+ children: pending ? "\u2026" : confirmText ?? (locale === "zh" ? "\u786E\u8BA4" : "Confirm")
936
+ }
937
+ )
938
+ ] })
939
+ ] })
940
+ ] }) })
941
+ ] });
942
+ }
943
+ function Drawer({
944
+ title,
945
+ description,
946
+ children,
947
+ footer,
948
+ trigger,
949
+ className,
950
+ ...props
951
+ }) {
952
+ const { locale } = useMtone();
953
+ return /* @__PURE__ */ jsxs3(BDrawer.Root, { swipeDirection: "right", ...props, children: [
954
+ trigger && /* @__PURE__ */ jsx3(BDrawer.Trigger, { render: trigger }),
955
+ /* @__PURE__ */ jsx3(BDrawer.Portal, { children: /* @__PURE__ */ jsxs3(MtoneScope, { children: [
956
+ /* @__PURE__ */ jsx3(BDrawer.Backdrop, { className: "mt-backdrop" }),
957
+ /* @__PURE__ */ jsx3(BDrawer.Viewport, { className: "mt-drawer-viewport", children: /* @__PURE__ */ jsx3(BDrawer.Popup, { className: cn("mt-drawer", className), children: /* @__PURE__ */ jsxs3(BDrawer.Content, { children: [
958
+ /* @__PURE__ */ jsx3(BDrawer.Title, { className: "mt-dialog-title", children: title }),
959
+ description && /* @__PURE__ */ jsx3(BDrawer.Description, { className: "mt-dialog-description", children: description }),
960
+ /* @__PURE__ */ jsx3(
961
+ BDrawer.Close,
962
+ {
963
+ className: "mt-dialog-close",
964
+ "aria-label": locale === "zh" ? "\u5173\u95ED" : "Close",
965
+ children: "\xD7"
966
+ }
967
+ ),
968
+ /* @__PURE__ */ jsx3("div", { className: "mt-dialog-body", children }),
969
+ footer && /* @__PURE__ */ jsx3("div", { className: "mt-dialog-footer", children: footer })
970
+ ] }) }) })
971
+ ] }) })
972
+ ] });
973
+ }
974
+
975
+ // src/navigation.tsx
976
+ import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
977
+ var SidebarContext = React3.createContext(false);
978
+ function Sidebar({
979
+ className,
980
+ children,
981
+ header,
982
+ footer,
983
+ collapsePlacement = "header",
984
+ collapsible = false,
985
+ collapsed,
986
+ defaultCollapsed = false,
987
+ onCollapsedChange,
988
+ collapseLabel = "\u6536\u8D77\u4FA7\u8FB9\u680F",
989
+ expandLabel = "\u5C55\u5F00\u4FA7\u8FB9\u680F",
990
+ ...p
991
+ }) {
992
+ const [internal, setInternal] = React3.useState(defaultCollapsed);
993
+ const isCollapsed = collapsible && (collapsed ?? internal);
994
+ const contentId = React3.useId();
995
+ const toggle = collapsible && /* @__PURE__ */ jsx4(
996
+ IconButton,
997
+ {
998
+ className: "mt-sidebar-toggle",
999
+ variant: "ghost",
1000
+ "aria-label": isCollapsed ? expandLabel : collapseLabel,
1001
+ title: isCollapsed ? expandLabel : collapseLabel,
1002
+ "aria-expanded": !isCollapsed,
1003
+ "aria-controls": contentId,
1004
+ onClick: () => {
1005
+ if (collapsed === void 0) setInternal(!isCollapsed);
1006
+ onCollapsedChange?.(!isCollapsed);
1007
+ },
1008
+ children: isCollapsed ? /* @__PURE__ */ jsx4(PanelLeftOpen, { size: 16, "aria-hidden": "true" }) : /* @__PURE__ */ jsx4(PanelLeftClose, { size: 16, "aria-hidden": "true" })
1009
+ }
1010
+ );
1011
+ return /* @__PURE__ */ jsx4(SidebarContext.Provider, { value: isCollapsed, children: /* @__PURE__ */ jsxs4(
1012
+ "aside",
1013
+ {
1014
+ ...p,
1015
+ className: cn("mt-sidebar", className),
1016
+ "data-collapsed": isCollapsed,
1017
+ children: [
1018
+ header !== void 0 ? /* @__PURE__ */ jsxs4("div", { className: "mt-sidebar-heading", children: [
1019
+ /* @__PURE__ */ jsx4("div", { className: "mt-sidebar-brand", children: typeof header === "function" ? header(isCollapsed) : header }),
1020
+ collapsePlacement === "header" && toggle
1021
+ ] }) : collapsePlacement === "header" && toggle,
1022
+ collapsible || header !== void 0 ? /* @__PURE__ */ jsx4("div", { id: contentId, className: "mt-sidebar-content", children }) : children,
1023
+ (footer !== void 0 || collapsePlacement === "footer" && collapsible) && /* @__PURE__ */ jsxs4("div", { className: "mt-sidebar-footer", children: [
1024
+ footer !== void 0 && /* @__PURE__ */ jsx4("div", { className: "mt-sidebar-footer-content", children: typeof footer === "function" ? footer(isCollapsed) : footer }),
1025
+ collapsePlacement === "footer" && toggle
1026
+ ] })
1027
+ ]
1028
+ }
1029
+ ) });
1030
+ }
1031
+ var NavItem = React3.forwardRef(function NavItem2({ active, icon, children, className, ...p }, ref) {
1032
+ const collapsed = React3.useContext(SidebarContext);
1033
+ const [tipOpen, setTipOpen] = React3.useState(false);
1034
+ const label = p["aria-label"] ?? (typeof children === "string" || typeof children === "number" ? String(children) : void 0);
1035
+ const button = /* @__PURE__ */ jsxs4(
1036
+ "button",
1037
+ {
1038
+ type: "button",
1039
+ ...p,
1040
+ ref,
1041
+ "aria-current": active ? "page" : void 0,
1042
+ className: cn(
1043
+ "mt-nav-item",
1044
+ active && "mt-active",
1045
+ collapsed && "mt-nav-item-collapsed",
1046
+ className
1047
+ ),
1048
+ children: [
1049
+ icon || (collapsed ? /* @__PURE__ */ jsx4(Circle, { size: 16, "aria-hidden": "true" }) : null),
1050
+ collapsed ? /* @__PURE__ */ jsx4("span", { className: "mt-sidebar-sr-only", children }) : children
1051
+ ]
1052
+ }
1053
+ );
1054
+ return label ? /* @__PURE__ */ jsx4(
1055
+ Tooltip,
1056
+ {
1057
+ content: label,
1058
+ side: "right",
1059
+ open: collapsed && tipOpen,
1060
+ onOpenChange: (open) => setTipOpen(collapsed && open),
1061
+ children: button
1062
+ }
1063
+ ) : button;
1064
+ });
1065
+ function NavGroup({
1066
+ label,
1067
+ children
1068
+ }) {
1069
+ const collapsed = React3.useContext(SidebarContext);
1070
+ return /* @__PURE__ */ jsxs4("div", { className: cn("mt-nav-group", collapsed && "mt-nav-group-collapsed"), children: [
1071
+ label && /* @__PURE__ */ jsx4("div", { className: collapsed ? "mt-sidebar-sr-only" : "mt-nav-label", children: label }),
1072
+ children
1073
+ ] });
1074
+ }
1075
+ function Breadcrumb({
1076
+ items,
1077
+ "aria-label": label = "Breadcrumb"
1078
+ }) {
1079
+ return /* @__PURE__ */ jsx4("nav", { "aria-label": label, children: /* @__PURE__ */ jsx4("ol", { className: "mt-breadcrumb", children: items.map((x, i) => /* @__PURE__ */ jsxs4("li", { children: [
1080
+ i > 0 && /* @__PURE__ */ jsx4(ChevronRight, { size: 12 }),
1081
+ i === items.length - 1 ? /* @__PURE__ */ jsx4("span", { "aria-current": "page", children: x.label }) : /* @__PURE__ */ jsx4("a", { href: x.href, children: x.label })
1082
+ ] }, i)) }) });
1083
+ }
1084
+ function FilterChip({
1085
+ children,
1086
+ onRemove
1087
+ }) {
1088
+ const { locale } = useMtone();
1089
+ return /* @__PURE__ */ jsxs4("span", { className: "mt-filter-chip", children: [
1090
+ children,
1091
+ /* @__PURE__ */ jsx4(
1092
+ IconButton,
1093
+ {
1094
+ size: "sm",
1095
+ variant: "ghost",
1096
+ "aria-label": locale === "zh" ? "\u79FB\u9664\u7B5B\u9009" : "Remove filter",
1097
+ onClick: onRemove,
1098
+ children: /* @__PURE__ */ jsx4(X2, { size: 12 })
1099
+ }
1100
+ )
1101
+ ] });
1102
+ }
1103
+ var FilterBar = ({
1104
+ className,
1105
+ ...p
1106
+ }) => /* @__PURE__ */ jsx4("div", { ...p, className: cn("mt-filter-bar", className) });
1107
+
1108
+ // src/data.tsx
1109
+ import * as React4 from "react";
1110
+ import { ChevronDown, ChevronRight as ChevronRight2, Upload as UploadIcon } from "lucide-react";
1111
+ import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
1112
+ function Pagination({
1113
+ total,
1114
+ pageSize = 10,
1115
+ page,
1116
+ onPageChange,
1117
+ className
1118
+ }) {
1119
+ const zh = useMtone().locale === "zh";
1120
+ const count = Math.max(
1121
+ 1,
1122
+ Math.ceil(Math.max(0, total) / Math.max(1, pageSize))
1123
+ );
1124
+ const current = Math.min(count, Math.max(1, page));
1125
+ const pages = Array.from(
1126
+ /* @__PURE__ */ new Set([
1127
+ 1,
1128
+ ...Array.from(
1129
+ { length: count <= 7 ? count : 3 },
1130
+ (_, i) => count <= 7 ? i + 1 : current + i - 1
1131
+ ).filter((p) => p > 0 && p <= count),
1132
+ count
1133
+ ])
1134
+ ).sort((a, b) => a - b);
1135
+ return /* @__PURE__ */ jsxs5(
1136
+ "nav",
1137
+ {
1138
+ "aria-label": zh ? "\u5206\u9875" : "Pagination",
1139
+ className: cn("mt-pagination", className),
1140
+ children: [
1141
+ /* @__PURE__ */ jsx5("span", { children: zh ? `\u5171 ${total} \u6761` : `${total} items` }),
1142
+ /* @__PURE__ */ jsx5(
1143
+ Button,
1144
+ {
1145
+ "aria-label": zh ? "\u4E0A\u4E00\u9875" : "Previous page",
1146
+ disabled: current === 1,
1147
+ onClick: () => onPageChange(current - 1),
1148
+ children: "\u2039"
1149
+ }
1150
+ ),
1151
+ /* @__PURE__ */ jsx5("span", { className: "mt-pagination-pages", children: pages.map((p, i) => /* @__PURE__ */ jsxs5(React4.Fragment, { children: [
1152
+ i > 0 && p - pages[i - 1] > 1 && /* @__PURE__ */ jsx5("span", { "aria-hidden": "true", children: "\u2026" }),
1153
+ /* @__PURE__ */ jsx5(
1154
+ Button,
1155
+ {
1156
+ "aria-label": `${zh ? "\u7B2C" : "Page "}${p}${zh ? "\u9875" : ""}`,
1157
+ "aria-current": p === current ? "page" : void 0,
1158
+ variant: p === current ? "soft" : "ghost",
1159
+ onClick: () => onPageChange(p),
1160
+ children: p
1161
+ }
1162
+ )
1163
+ ] }, p)) }),
1164
+ /* @__PURE__ */ jsx5(
1165
+ Button,
1166
+ {
1167
+ "aria-label": zh ? "\u4E0B\u4E00\u9875" : "Next page",
1168
+ disabled: current === count,
1169
+ onClick: () => onPageChange(current + 1),
1170
+ children: "\u203A"
1171
+ }
1172
+ )
1173
+ ]
1174
+ }
1175
+ );
1176
+ }
1177
+ function Table({
1178
+ data,
1179
+ columns,
1180
+ rowKey,
1181
+ manual = false,
1182
+ loading = false,
1183
+ onChange,
1184
+ sort: controlledSort,
1185
+ filters: controlledFilters,
1186
+ selectable,
1187
+ selectedKeys,
1188
+ onSelectionChange,
1189
+ pagination = false,
1190
+ empty,
1191
+ className
1192
+ }) {
1193
+ const zh = useMtone().locale === "zh";
1194
+ const [internal, setInternal] = React4.useState({
1195
+ filters: {},
1196
+ page: 1,
1197
+ pageSize: pagination ? pagination.pageSize || 10 : 10
1198
+ });
1199
+ const [selected, setSelected] = React4.useState([]);
1200
+ const state = {
1201
+ ...internal,
1202
+ sort: controlledSort === void 0 ? internal.sort : controlledSort,
1203
+ filters: controlledFilters ?? internal.filters,
1204
+ page: pagination && pagination.page !== void 0 ? pagination.page : internal.page,
1205
+ pageSize: Math.max(1, pagination ? pagination.pageSize || 10 : 10)
1206
+ };
1207
+ const keys = selectedKeys ?? selected;
1208
+ const update = (patch) => {
1209
+ const next = { ...state, ...patch };
1210
+ setInternal(next);
1211
+ onChange?.(next);
1212
+ };
1213
+ const key = (row) => typeof rowKey === "function" ? rowKey(row) : row[rowKey];
1214
+ const val = (row, c) => row[c.dataIndex ?? c.key];
1215
+ let rows = [...data];
1216
+ if (!manual) {
1217
+ rows = rows.filter(
1218
+ (row) => columns.every(
1219
+ (c) => !state.filters[c.key] || String(val(row, c) ?? "").toLocaleLowerCase().includes(state.filters[c.key].toLocaleLowerCase())
1220
+ )
1221
+ );
1222
+ if (state.sort) {
1223
+ const c = columns.find((c2) => c2.key === state.sort.key);
1224
+ if (c)
1225
+ rows.sort((a, b) => {
1226
+ const x = val(a, c), y = val(b, c);
1227
+ return (typeof x === "number" && typeof y === "number" ? x - y : String(x ?? "").localeCompare(String(y ?? ""))) * (state.sort.direction === "asc" ? 1 : -1);
1228
+ });
1229
+ }
1230
+ }
1231
+ const total = manual && pagination ? pagination.total ?? rows.length : rows.length;
1232
+ const page = Math.min(
1233
+ Math.max(1, state.page),
1234
+ Math.max(1, Math.ceil(total / state.pageSize))
1235
+ );
1236
+ if (pagination && !manual)
1237
+ rows = rows.slice((page - 1) * state.pageSize, page * state.pageSize);
1238
+ const select = (next) => {
1239
+ setSelected(next);
1240
+ onSelectionChange?.(next);
1241
+ };
1242
+ const all = rows.length > 0 && rows.every((r) => keys.includes(key(r)));
1243
+ return /* @__PURE__ */ jsxs5("div", { className: cn("mt-table-wrap", className), children: [
1244
+ /* @__PURE__ */ jsx5("div", { className: "mt-table-scroll", children: /* @__PURE__ */ jsxs5("table", { className: "mt-table", "aria-busy": loading || void 0, children: [
1245
+ /* @__PURE__ */ jsx5("thead", { children: /* @__PURE__ */ jsxs5("tr", { children: [
1246
+ selectable && /* @__PURE__ */ jsx5("th", { children: /* @__PURE__ */ jsx5(
1247
+ "input",
1248
+ {
1249
+ type: "checkbox",
1250
+ "aria-label": zh ? "\u9009\u62E9\u6240\u6709\u884C" : "Select all rows",
1251
+ checked: all,
1252
+ onChange: () => select(
1253
+ all ? keys.filter((k) => !rows.some((r) => key(r) === k)) : [.../* @__PURE__ */ new Set([...keys, ...rows.map(key)])]
1254
+ )
1255
+ }
1256
+ ) }),
1257
+ columns.map((c) => /* @__PURE__ */ jsxs5(
1258
+ "th",
1259
+ {
1260
+ "aria-sort": state.sort?.key === c.key ? state.sort.direction === "asc" ? "ascending" : "descending" : void 0,
1261
+ children: [
1262
+ c.sortable ? /* @__PURE__ */ jsxs5(
1263
+ "button",
1264
+ {
1265
+ type: "button",
1266
+ className: "mt-table-sort",
1267
+ onClick: () => update({
1268
+ sort: state.sort?.key !== c.key ? { key: c.key, direction: "asc" } : state.sort.direction === "asc" ? { key: c.key, direction: "desc" } : void 0,
1269
+ page: 1
1270
+ }),
1271
+ children: [
1272
+ c.title,
1273
+ /* @__PURE__ */ jsx5("span", { "aria-hidden": "true", children: state.sort?.key === c.key ? state.sort.direction === "asc" ? " \u2191" : " \u2193" : " \u2195" })
1274
+ ]
1275
+ }
1276
+ ) : c.title,
1277
+ c.filterable && /* @__PURE__ */ jsx5(
1278
+ "input",
1279
+ {
1280
+ className: "mt-input mt-table-filter",
1281
+ "aria-label": `${zh ? "\u7B5B\u9009" : "Filter"} ${typeof c.title === "string" ? c.title : c.key}`,
1282
+ value: state.filters[c.key] || "",
1283
+ onChange: (e) => update({
1284
+ filters: {
1285
+ ...state.filters,
1286
+ [c.key]: e.target.value
1287
+ },
1288
+ page: 1
1289
+ })
1290
+ }
1291
+ )
1292
+ ]
1293
+ },
1294
+ c.key
1295
+ ))
1296
+ ] }) }),
1297
+ /* @__PURE__ */ jsxs5("tbody", { children: [
1298
+ loading && /* @__PURE__ */ jsx5("tr", { children: /* @__PURE__ */ jsx5(
1299
+ "td",
1300
+ {
1301
+ colSpan: columns.length + (selectable ? 1 : 0),
1302
+ className: "mt-table-empty",
1303
+ children: /* @__PURE__ */ jsx5("span", { role: "status", children: zh ? "\u52A0\u8F7D\u4E2D\u2026" : "Loading\u2026" })
1304
+ }
1305
+ ) }),
1306
+ rows.map((r, i) => /* @__PURE__ */ jsxs5(
1307
+ "tr",
1308
+ {
1309
+ "data-selected": keys.includes(key(r)) || void 0,
1310
+ children: [
1311
+ selectable && /* @__PURE__ */ jsx5("td", { children: /* @__PURE__ */ jsx5(
1312
+ "input",
1313
+ {
1314
+ type: "checkbox",
1315
+ "aria-label": `${zh ? "\u9009\u62E9\u884C" : "Select row"} ${key(r)}`,
1316
+ checked: keys.includes(key(r)),
1317
+ onChange: () => select(
1318
+ keys.includes(key(r)) ? keys.filter((k) => k !== key(r)) : [...keys, key(r)]
1319
+ )
1320
+ }
1321
+ ) }),
1322
+ columns.map((c) => /* @__PURE__ */ jsx5("td", { children: c.render ? c.render(val(r, c), r, i) : String(val(r, c) ?? "") }, c.key))
1323
+ ]
1324
+ },
1325
+ key(r)
1326
+ )),
1327
+ !loading && !rows.length && /* @__PURE__ */ jsx5("tr", { children: /* @__PURE__ */ jsx5(
1328
+ "td",
1329
+ {
1330
+ className: "mt-table-empty",
1331
+ colSpan: columns.length + (selectable ? 1 : 0),
1332
+ children: empty ?? (zh ? "\u6682\u65E0\u6570\u636E" : "No data")
1333
+ }
1334
+ ) })
1335
+ ] })
1336
+ ] }) }),
1337
+ pagination && /* @__PURE__ */ jsx5(
1338
+ Pagination,
1339
+ {
1340
+ total,
1341
+ pageSize: state.pageSize,
1342
+ page,
1343
+ onPageChange: (p) => {
1344
+ update({ page: p });
1345
+ pagination.onPageChange?.(p);
1346
+ }
1347
+ }
1348
+ )
1349
+ ] });
1350
+ }
1351
+ function Tree({
1352
+ items,
1353
+ value,
1354
+ defaultValue,
1355
+ onValueChange,
1356
+ expanded,
1357
+ defaultExpanded = [],
1358
+ onExpandedChange,
1359
+ label,
1360
+ className
1361
+ }) {
1362
+ const zh = useMtone().locale === "zh";
1363
+ const [selection, setSelection] = React4.useState(defaultValue);
1364
+ const [open, setOpen] = React4.useState(defaultExpanded);
1365
+ const [active, setActive] = React4.useState();
1366
+ const refs = React4.useRef(/* @__PURE__ */ new Map());
1367
+ const ids = expanded ?? open;
1368
+ const selected = value ?? selection;
1369
+ const visible = [];
1370
+ function walk(list, level, parent) {
1371
+ list.forEach((item) => {
1372
+ visible.push({ item, level, parent });
1373
+ if (ids.includes(item.id)) walk(item.children ?? [], level + 1, item.id);
1374
+ });
1375
+ }
1376
+ walk(items, 1);
1377
+ const enabled = visible.filter((x) => !x.item.disabled);
1378
+ const focusId = enabled.some((x) => x.item.id === active) ? active : enabled[0]?.item.id;
1379
+ const focus = (id) => {
1380
+ if (id && enabled.some((x) => x.item.id === id)) {
1381
+ setActive(id);
1382
+ refs.current.get(id)?.focus();
1383
+ }
1384
+ };
1385
+ const toggle = (id) => {
1386
+ const next = ids.includes(id) ? ids.filter((x) => x !== id) : [...ids, id];
1387
+ setOpen(next);
1388
+ onExpandedChange?.(next);
1389
+ };
1390
+ const choose = (item) => {
1391
+ if (!item.disabled) {
1392
+ setSelection(item.id);
1393
+ onValueChange?.(item.id);
1394
+ }
1395
+ };
1396
+ return /* @__PURE__ */ jsx5(
1397
+ "div",
1398
+ {
1399
+ className: cn("mt-tree", className),
1400
+ role: "tree",
1401
+ "aria-label": label ?? (zh ? "\u76EE\u5F55\u6811" : "Tree"),
1402
+ children: visible.map(({ item, level, parent }) => /* @__PURE__ */ jsxs5(
1403
+ "div",
1404
+ {
1405
+ ref: (el) => {
1406
+ if (el) refs.current.set(item.id, el);
1407
+ else refs.current.delete(item.id);
1408
+ },
1409
+ role: "treeitem",
1410
+ "aria-level": level,
1411
+ "aria-selected": selected === item.id,
1412
+ "aria-expanded": item.children?.length ? ids.includes(item.id) : void 0,
1413
+ "aria-disabled": item.disabled || void 0,
1414
+ tabIndex: !item.disabled && focusId === item.id ? 0 : -1,
1415
+ className: "mt-tree-item",
1416
+ style: { paddingInlineStart: 8 + (level - 1) * 18 },
1417
+ onFocus: () => setActive(item.id),
1418
+ onClick: () => {
1419
+ choose(item);
1420
+ if (!item.disabled) focus(item.id);
1421
+ },
1422
+ onKeyDown: (e) => {
1423
+ if (item.disabled) return;
1424
+ const index = enabled.findIndex((x) => x.item.id === item.id);
1425
+ if ([
1426
+ "ArrowDown",
1427
+ "ArrowUp",
1428
+ "ArrowRight",
1429
+ "ArrowLeft",
1430
+ "Home",
1431
+ "End",
1432
+ "Enter",
1433
+ " "
1434
+ ].includes(e.key))
1435
+ e.preventDefault();
1436
+ switch (e.key) {
1437
+ case "ArrowDown":
1438
+ focus(enabled[index + 1]?.item.id);
1439
+ break;
1440
+ case "ArrowUp":
1441
+ focus(enabled[index - 1]?.item.id);
1442
+ break;
1443
+ case "Home":
1444
+ focus(enabled[0]?.item.id);
1445
+ break;
1446
+ case "End":
1447
+ focus(enabled.at(-1)?.item.id);
1448
+ break;
1449
+ case "ArrowRight":
1450
+ if (item.children?.length) {
1451
+ if (!ids.includes(item.id)) toggle(item.id);
1452
+ else focus(enabled[index + 1]?.item.id);
1453
+ }
1454
+ break;
1455
+ case "ArrowLeft":
1456
+ if (ids.includes(item.id) && item.children?.length)
1457
+ toggle(item.id);
1458
+ else focus(parent);
1459
+ break;
1460
+ case "Enter":
1461
+ case " ":
1462
+ choose(item);
1463
+ }
1464
+ },
1465
+ children: [
1466
+ item.children?.length ? /* @__PURE__ */ jsx5(
1467
+ "span",
1468
+ {
1469
+ "aria-hidden": "true",
1470
+ className: "mt-tree-toggle",
1471
+ onClick: (e) => {
1472
+ e.stopPropagation();
1473
+ if (!item.disabled) toggle(item.id);
1474
+ },
1475
+ children: ids.includes(item.id) ? /* @__PURE__ */ jsx5(ChevronDown, { size: 14 }) : /* @__PURE__ */ jsx5(ChevronRight2, { size: 14 })
1476
+ }
1477
+ ) : /* @__PURE__ */ jsx5("span", { className: "mt-tree-toggle" }),
1478
+ item.icon,
1479
+ /* @__PURE__ */ jsx5("span", { children: item.label })
1480
+ ]
1481
+ },
1482
+ item.id
1483
+ ))
1484
+ }
1485
+ );
1486
+ }
1487
+ function DatePicker({
1488
+ value,
1489
+ defaultValue = "",
1490
+ onValueChange,
1491
+ min,
1492
+ max,
1493
+ disabledDate,
1494
+ disabled,
1495
+ label,
1496
+ clearable = true,
1497
+ className,
1498
+ name
1499
+ }) {
1500
+ const zh = useMtone().locale === "zh";
1501
+ const [local, setLocal] = React4.useState(defaultValue);
1502
+ const [error, setError] = React4.useState(false);
1503
+ const current = value ?? local;
1504
+ const id = React4.useId();
1505
+ const change = (next) => {
1506
+ const valid = !next || /^\d{4}-\d{2}-\d{2}$/.test(next) && (!min || next >= min) && (!max || next <= max) && !disabledDate?.(next);
1507
+ setError(!valid);
1508
+ if (valid) {
1509
+ setLocal(next);
1510
+ onValueChange?.(next);
1511
+ }
1512
+ };
1513
+ return /* @__PURE__ */ jsxs5("div", { className: cn("mt-date-picker", className), children: [
1514
+ /* @__PURE__ */ jsx5(
1515
+ "input",
1516
+ {
1517
+ className: "mt-input",
1518
+ type: "date",
1519
+ name,
1520
+ value: current,
1521
+ min,
1522
+ max,
1523
+ disabled,
1524
+ "aria-label": label ?? (zh ? "\u9009\u62E9\u65E5\u671F" : "Choose date"),
1525
+ "aria-invalid": error || void 0,
1526
+ "aria-describedby": error ? id : void 0,
1527
+ onChange: (e) => change(e.target.value)
1528
+ }
1529
+ ),
1530
+ clearable && current && /* @__PURE__ */ jsx5(
1531
+ Button,
1532
+ {
1533
+ variant: "ghost",
1534
+ disabled,
1535
+ "aria-label": zh ? "\u6E05\u9664\u65E5\u671F" : "Clear date",
1536
+ onClick: () => change(""),
1537
+ children: "\xD7"
1538
+ }
1539
+ ),
1540
+ error && /* @__PURE__ */ jsx5("span", { id, role: "alert", className: "mt-error", children: zh ? "\u6B64\u65E5\u671F\u4E0D\u53EF\u9009" : "This date is unavailable" })
1541
+ ] });
1542
+ }
1543
+ function Upload({
1544
+ upload,
1545
+ accept,
1546
+ maxSize,
1547
+ multiple = true,
1548
+ disabled,
1549
+ onChange,
1550
+ className,
1551
+ children
1552
+ }) {
1553
+ const zh = useMtone().locale === "zh";
1554
+ const [files, setFiles] = React4.useState([]);
1555
+ const [drag, setDrag] = React4.useState(false);
1556
+ const input = React4.useRef(null);
1557
+ const current = React4.useRef([]);
1558
+ const runs = React4.useRef(/* @__PURE__ */ new Map());
1559
+ const alive = React4.useRef(true);
1560
+ const changeRef = React4.useRef(onChange);
1561
+ changeRef.current = onChange;
1562
+ React4.useEffect(() => {
1563
+ alive.current = true;
1564
+ return () => {
1565
+ alive.current = false;
1566
+ runs.current.forEach((c) => c.abort());
1567
+ runs.current.clear();
1568
+ };
1569
+ }, []);
1570
+ const commit = (next) => {
1571
+ current.current = next;
1572
+ if (alive.current) {
1573
+ setFiles(next);
1574
+ changeRef.current?.(next);
1575
+ }
1576
+ };
1577
+ const patch = (id, p) => commit(current.current.map((f) => f.id === id ? { ...f, ...p } : f));
1578
+ const start = (entry) => {
1579
+ if (entry.validationError || disabled) return;
1580
+ runs.current.get(entry.id)?.abort();
1581
+ const controller = new AbortController();
1582
+ runs.current.set(entry.id, controller);
1583
+ patch(entry.id, { status: "uploading", progress: 0, error: void 0 });
1584
+ const valid = () => alive.current && !controller.signal.aborted && runs.current.get(entry.id) === controller;
1585
+ const context = {
1586
+ signal: controller.signal,
1587
+ onProgress: (n) => {
1588
+ if (valid())
1589
+ patch(entry.id, {
1590
+ progress: Math.max(0, Math.min(100, Number.isFinite(n) ? n : 0))
1591
+ });
1592
+ }
1593
+ };
1594
+ try {
1595
+ Promise.resolve(upload(entry.file, context)).then(
1596
+ () => {
1597
+ if (valid()) {
1598
+ patch(entry.id, { status: "success", progress: 100 });
1599
+ runs.current.delete(entry.id);
1600
+ }
1601
+ },
1602
+ (e) => {
1603
+ if (valid()) {
1604
+ patch(entry.id, {
1605
+ status: "error",
1606
+ error: e instanceof Error ? e.message : String(e)
1607
+ });
1608
+ runs.current.delete(entry.id);
1609
+ }
1610
+ }
1611
+ );
1612
+ } catch (e) {
1613
+ if (valid()) {
1614
+ patch(entry.id, {
1615
+ status: "error",
1616
+ error: e instanceof Error ? e.message : String(e)
1617
+ });
1618
+ runs.current.delete(entry.id);
1619
+ }
1620
+ }
1621
+ };
1622
+ const add = (list) => {
1623
+ if (disabled) return;
1624
+ (multiple ? list : list.slice(0, 1)).forEach((file) => {
1625
+ const matches = !accept || accept.split(",").some((raw) => {
1626
+ const rule = raw.trim().toLowerCase();
1627
+ return rule.startsWith(".") ? file.name.toLowerCase().endsWith(rule) : rule.endsWith("/*") ? file.type.toLowerCase().startsWith(rule.slice(0, -1)) : file.type.toLowerCase() === rule;
1628
+ });
1629
+ const validationError = !matches ? "type" : maxSize !== void 0 && file.size > maxSize ? "size" : void 0;
1630
+ const error = !matches ? zh ? "\u6587\u4EF6\u7C7B\u578B\u4E0D\u652F\u6301" : "Unsupported file type" : maxSize !== void 0 && file.size > maxSize ? zh ? "\u6587\u4EF6\u592A\u5927" : "File is too large" : void 0;
1631
+ const entry = {
1632
+ id: globalThis.crypto.randomUUID(),
1633
+ file,
1634
+ status: error ? "error" : "uploading",
1635
+ progress: 0,
1636
+ error,
1637
+ validationError
1638
+ };
1639
+ commit([...current.current, entry]);
1640
+ if (!error) start(entry);
1641
+ });
1642
+ };
1643
+ const cancel = (id) => {
1644
+ runs.current.get(id)?.abort();
1645
+ runs.current.delete(id);
1646
+ patch(id, { status: "cancelled" });
1647
+ };
1648
+ return /* @__PURE__ */ jsxs5("div", { className: cn("mt-upload", className), children: [
1649
+ /* @__PURE__ */ jsxs5(
1650
+ "div",
1651
+ {
1652
+ className: "mt-dropzone",
1653
+ "data-dragging": drag || void 0,
1654
+ onDragOver: (e) => {
1655
+ e.preventDefault();
1656
+ if (!disabled) setDrag(true);
1657
+ },
1658
+ onDragLeave: () => setDrag(false),
1659
+ onDrop: (e) => {
1660
+ e.preventDefault();
1661
+ setDrag(false);
1662
+ add(Array.from(e.dataTransfer.files));
1663
+ },
1664
+ children: [
1665
+ /* @__PURE__ */ jsx5(UploadIcon, { size: 22 }),
1666
+ children ?? /* @__PURE__ */ jsx5("span", { children: zh ? "\u62D6\u62FD\u6587\u4EF6\u5230\u6B64\u5904\uFF0C\u6216\u9009\u62E9\u6587\u4EF6" : "Drop files here, or choose files" }),
1667
+ /* @__PURE__ */ jsx5(
1668
+ "input",
1669
+ {
1670
+ ref: input,
1671
+ type: "file",
1672
+ "aria-label": zh ? "\u9009\u62E9\u6587\u4EF6" : "Choose files",
1673
+ accept,
1674
+ multiple,
1675
+ disabled,
1676
+ onChange: (e) => {
1677
+ add(Array.from(e.target.files ?? []));
1678
+ e.target.value = "";
1679
+ }
1680
+ }
1681
+ )
1682
+ ]
1683
+ }
1684
+ ),
1685
+ /* @__PURE__ */ jsx5("ul", { className: "mt-upload-list", children: files.map((f) => /* @__PURE__ */ jsxs5("li", { children: [
1686
+ /* @__PURE__ */ jsxs5("span", { className: "mt-upload-name", children: [
1687
+ f.file.name,
1688
+ /* @__PURE__ */ jsx5("small", { role: f.status === "error" ? "alert" : "status", children: f.error ?? {
1689
+ uploading: zh ? "\u4E0A\u4F20\u4E2D" : "Uploading",
1690
+ success: zh ? "\u4E0A\u4F20\u6210\u529F" : "Uploaded",
1691
+ cancelled: zh ? "\u5DF2\u53D6\u6D88" : "Cancelled",
1692
+ error: zh ? "\u4E0A\u4F20\u5931\u8D25" : "Failed"
1693
+ }[f.status] })
1694
+ ] }),
1695
+ f.status === "uploading" && /* @__PURE__ */ jsxs5(Fragment3, { children: [
1696
+ /* @__PURE__ */ jsx5(
1697
+ "progress",
1698
+ {
1699
+ value: f.progress,
1700
+ max: 100,
1701
+ "aria-label": `${f.file.name} ${zh ? "\u8FDB\u5EA6" : "progress"}`
1702
+ }
1703
+ ),
1704
+ /* @__PURE__ */ jsx5(Button, { onClick: () => cancel(f.id), children: zh ? "\u53D6\u6D88" : "Cancel" })
1705
+ ] }),
1706
+ (f.status === "cancelled" || f.status === "error") && /* @__PURE__ */ jsx5(
1707
+ Button,
1708
+ {
1709
+ disabled: disabled || !!f.validationError,
1710
+ onClick: () => start(f),
1711
+ children: zh ? "\u91CD\u8BD5" : "Retry"
1712
+ }
1713
+ ),
1714
+ /* @__PURE__ */ jsx5(
1715
+ Button,
1716
+ {
1717
+ variant: "ghost",
1718
+ "aria-label": `${zh ? "\u79FB\u9664" : "Remove"} ${f.file.name}`,
1719
+ onClick: () => {
1720
+ runs.current.get(f.id)?.abort();
1721
+ runs.current.delete(f.id);
1722
+ commit(current.current.filter((x) => x.id !== f.id));
1723
+ },
1724
+ children: "\xD7"
1725
+ }
1726
+ )
1727
+ ] }, f.id)) })
1728
+ ] });
1729
+ }
1730
+ var Dropzone = Upload;
1731
+
1732
+ // src/layout.tsx
1733
+ import * as React5 from "react";
1734
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
1735
+ function LayoutSider({
1736
+ logo,
1737
+ version,
1738
+ collapsedLogo,
1739
+ width = 240,
1740
+ collapsedWidth = 52,
1741
+ breakpoint,
1742
+ onBreakpoint,
1743
+ collapsed,
1744
+ defaultCollapsed = false,
1745
+ onCollapsedChange,
1746
+ collapsible = false,
1747
+ className,
1748
+ style,
1749
+ ...props
1750
+ }) {
1751
+ const [internal, setInternal] = React5.useState(defaultCollapsed);
1752
+ const previousBreakpoint = React5.useRef(void 0);
1753
+ const callbacks = React5.useRef({
1754
+ onBreakpoint,
1755
+ onCollapsedChange,
1756
+ collapsed
1757
+ });
1758
+ callbacks.current = { onBreakpoint, onCollapsedChange, collapsed };
1759
+ const update = (next) => {
1760
+ if (collapsed === void 0) setInternal(next);
1761
+ onCollapsedChange?.(next);
1762
+ };
1763
+ React5.useEffect(() => {
1764
+ if (!collapsible || !breakpoint || typeof window.matchMedia !== "function")
1765
+ return;
1766
+ const media = window.matchMedia(`(max-width: ${breakpoint - 0.02}px)`);
1767
+ const notify = (matches, initial2 = false) => {
1768
+ callbacks.current.onBreakpoint?.(matches);
1769
+ if (!initial2 || matches) {
1770
+ if (callbacks.current.collapsed === void 0) setInternal(matches);
1771
+ callbacks.current.onCollapsedChange?.(matches);
1772
+ }
1773
+ };
1774
+ const initial = previousBreakpoint.current === void 0 || previousBreakpoint.current === breakpoint;
1775
+ previousBreakpoint.current = breakpoint;
1776
+ notify(media.matches, initial);
1777
+ const listener = (event) => notify(event.matches);
1778
+ media.addEventListener("change", listener);
1779
+ return () => media.removeEventListener("change", listener);
1780
+ }, [breakpoint, collapsible]);
1781
+ const safeWidth = Number.isFinite(width) ? Math.max(40, width) : 240;
1782
+ const safeCollapsedWidth = Number.isFinite(collapsedWidth) ? Math.max(40, collapsedWidth) : 52;
1783
+ return /* @__PURE__ */ jsx6(
1784
+ Sidebar,
1785
+ {
1786
+ ...props,
1787
+ collapsible,
1788
+ collapsed: collapsed ?? internal,
1789
+ onCollapsedChange: update,
1790
+ collapsePlacement: "footer",
1791
+ footer: version != null ? (small) => small ? null : version : void 0,
1792
+ header: (small) => small ? collapsedLogo ?? logo : logo,
1793
+ className: cn("mt-layout-sider", className),
1794
+ style: {
1795
+ "--mt-layout-sider-width": `${safeWidth}px`,
1796
+ "--mt-layout-sider-collapsed-width": `${safeCollapsedWidth}px`,
1797
+ ...style
1798
+ }
1799
+ }
1800
+ );
1801
+ }
1802
+ function LayoutHeader({
1803
+ breadcrumb,
1804
+ extra,
1805
+ children,
1806
+ className,
1807
+ ...props
1808
+ }) {
1809
+ return /* @__PURE__ */ jsxs6("header", { ...props, className: cn("mt-layout-header", className), children: [
1810
+ /* @__PURE__ */ jsxs6("div", { className: "mt-layout-header-main", children: [
1811
+ breadcrumb,
1812
+ children
1813
+ ] }),
1814
+ extra != null && /* @__PURE__ */ jsx6("div", { className: "mt-layout-header-extra", children: extra })
1815
+ ] });
1816
+ }
1817
+ function LayoutContent({
1818
+ as: Element = "main",
1819
+ className,
1820
+ ...props
1821
+ }) {
1822
+ return /* @__PURE__ */ jsx6(Element, { ...props, className: cn("mt-layout-content", className) });
1823
+ }
1824
+ function LayoutFooter({
1825
+ className,
1826
+ ...props
1827
+ }) {
1828
+ return /* @__PURE__ */ jsx6("footer", { ...props, className: cn("mt-layout-footer", className) });
1829
+ }
1830
+ function containsSider(children) {
1831
+ return React5.Children.toArray(children).some(
1832
+ (child) => React5.isValidElement(child) && (child.type === LayoutSider || child.type === React5.Fragment && containsSider(
1833
+ child.props.children
1834
+ ))
1835
+ );
1836
+ }
1837
+ function LayoutRoot({
1838
+ hasSider,
1839
+ fullHeight = false,
1840
+ className,
1841
+ children,
1842
+ ...props
1843
+ }) {
1844
+ return /* @__PURE__ */ jsx6(
1845
+ "div",
1846
+ {
1847
+ ...props,
1848
+ className: cn(
1849
+ "mt-layout",
1850
+ (hasSider ?? containsSider(children)) && "mt-layout-has-sider",
1851
+ fullHeight && "mt-layout-full-height",
1852
+ className
1853
+ ),
1854
+ children
1855
+ }
1856
+ );
1857
+ }
1858
+ var Layout = Object.assign(LayoutRoot, {
1859
+ Sider: LayoutSider,
1860
+ Header: LayoutHeader,
1861
+ Content: LayoutContent,
1862
+ Footer: LayoutFooter
1863
+ });
1864
+ export {
1865
+ Alert,
1866
+ Avatar,
1867
+ AvatarGroup,
1868
+ Badge,
1869
+ Breadcrumb,
1870
+ Button,
1871
+ ButtonGroup,
1872
+ Card,
1873
+ Checkbox,
1874
+ ConfirmDialog,
1875
+ ContextMenu,
1876
+ DatePicker,
1877
+ Divider,
1878
+ DocumentCard,
1879
+ DocumentList,
1880
+ Drawer,
1881
+ DropdownMenu,
1882
+ Dropzone,
1883
+ Empty,
1884
+ FilterBar,
1885
+ FilterChip,
1886
+ Form,
1887
+ FormField,
1888
+ IconButton,
1889
+ Input,
1890
+ Layout,
1891
+ List,
1892
+ ListItem,
1893
+ Modal,
1894
+ MtoneProvider,
1895
+ MtoneScope,
1896
+ MultiSelect,
1897
+ NavGroup,
1898
+ NavItem,
1899
+ NumberInput,
1900
+ Pagination,
1901
+ Popover,
1902
+ Progress,
1903
+ PropertyItem,
1904
+ PropertyList,
1905
+ RadioGroup,
1906
+ SearchInput,
1907
+ Segmented,
1908
+ Select,
1909
+ Sidebar,
1910
+ Skeleton,
1911
+ Slider,
1912
+ Spinner,
1913
+ Status,
1914
+ Switch,
1915
+ Table,
1916
+ Tabs,
1917
+ Tag,
1918
+ Text,
1919
+ Textarea,
1920
+ Toast,
1921
+ ToastProvider,
1922
+ Tooltip,
1923
+ Tree,
1924
+ Upload,
1925
+ cn,
1926
+ useMtone,
1927
+ useToast
1928
+ };