@bixlab/mtone 0.1.0 → 0.3.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 CHANGED
@@ -1,336 +1,11 @@
1
1
  "use client";
2
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";
3
+ // src/card.tsx
4
+ import * as React2 from "react";
331
5
 
332
6
  // src/interactive.tsx
333
- import { useId as useId2, useState as useState2 } from "react";
7
+ import { useId, useState } from "react";
8
+ import { Check, ChevronDown, Minus, X } from "lucide-react";
334
9
  import { Checkbox as BCheckbox } from "@base-ui/react/checkbox";
335
10
  import { Switch as BSwitch } from "@base-ui/react/switch";
336
11
  import { Radio as BRadio } from "@base-ui/react/radio";
@@ -344,16 +19,16 @@ import { Menu } from "@base-ui/react/menu";
344
19
  import { ContextMenu as BContextMenu } from "@base-ui/react/context-menu";
345
20
  import { Popover as BPopover } from "@base-ui/react/popover";
346
21
  import { Tooltip as BTooltip } from "@base-ui/react/tooltip";
347
- import { Dialog } from "@base-ui/react/dialog";
22
+ import { Dialog as BDialog } from "@base-ui/react/dialog";
348
23
  import { AlertDialog } from "@base-ui/react/alert-dialog";
349
24
  import { Drawer as BDrawer } from "@base-ui/react/drawer";
350
25
 
351
26
  // src/toast.tsx
352
- import { CircleCheck, CircleX, Info as Info2, LoaderCircle as LoaderCircle2 } from "lucide-react";
27
+ import { CircleCheck, CircleX, Info, LoaderCircle } from "lucide-react";
353
28
  import {
354
29
  Toast as BToast
355
30
  } from "@base-ui/react/toast";
356
- import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
31
+ import { jsx, jsxs } from "react/jsx-runtime";
357
32
  function normalize(options, previous) {
358
33
  const { body, position, children, data, ...rest } = options;
359
34
  const meta = { ...previous?.data?.__mtoneToast };
@@ -434,7 +109,7 @@ function ToastViewport({
434
109
  const { toasts } = BToast.useToastManager();
435
110
  const { locale } = useMtone();
436
111
  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(
112
+ return /* @__PURE__ */ jsx(BToast.Portal, { children: /* @__PURE__ */ jsx(MtoneScope, { children: /* @__PURE__ */ jsx(
438
113
  BToast.Viewport,
439
114
  {
440
115
  className: "mt-toast-viewport",
@@ -447,8 +122,8 @@ function ToastViewport({
447
122
  const offset = peers.slice(0, Math.max(0, index)).reduce((sum, item) => sum + (item.height ?? 0) + 10, 0);
448
123
  const total = peers.reduce((sum, item) => sum + (item.height ?? 0), 0) + Math.max(0, peers.length - 1) * 10;
449
124
  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(
125
+ const Icon = type === "success" ? CircleCheck : type === "error" ? CircleX : type === "loading" ? LoaderCircle : Info;
126
+ return /* @__PURE__ */ jsx(
452
127
  "div",
453
128
  {
454
129
  className: "mt-toast-stack",
@@ -458,8 +133,8 @@ function ToastViewport({
458
133
  "--mt-toast-total": `${total}px`,
459
134
  "--mt-toast-limit": Math.max(1, limit)
460
135
  },
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(
136
+ children: /* @__PURE__ */ jsx(BToast.Root, { toast: t, className: "mt-toast", "data-type": type, children: /* @__PURE__ */ jsxs(BToast.Content, { className: "mt-toast-content", children: [
137
+ /* @__PURE__ */ jsx(
463
138
  Icon,
464
139
  {
465
140
  className: `mt-toast-icon${type === "loading" ? " mt-spin" : ""}`,
@@ -467,11 +142,11 @@ function ToastViewport({
467
142
  "aria-hidden": "true"
468
143
  }
469
144
  ),
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(
145
+ t.title != null && /* @__PURE__ */ jsx(BToast.Title, { className: "mt-toast-title" }),
146
+ t.description != null && /* @__PURE__ */ jsx(BToast.Description, { className: "mt-toast-description" }),
147
+ t.data?.__mtoneToast?.children != null && /* @__PURE__ */ jsx("div", { className: "mt-toast-custom", children: t.data.__mtoneToast.children }, "custom"),
148
+ t.actionProps && /* @__PURE__ */ jsx(BToast.Action, { className: "mt-action mt-toast-action" }),
149
+ /* @__PURE__ */ jsx(
475
150
  BToast.Close,
476
151
  {
477
152
  className: "mt-dialog-close",
@@ -493,23 +168,23 @@ function ToastProvider({
493
168
  limit = 3,
494
169
  position = "bottom-right"
495
170
  }) {
496
- return /* @__PURE__ */ jsxs2(BToast.Provider, { timeout, limit, children: [
171
+ return /* @__PURE__ */ jsxs(BToast.Provider, { timeout, limit, children: [
497
172
  children,
498
- /* @__PURE__ */ jsx2(ToastViewport, { position, limit })
173
+ /* @__PURE__ */ jsx(ToastViewport, { position, limit })
499
174
  ] });
500
175
  }
501
176
  var Toast = ToastProvider;
502
177
 
503
178
  // src/interactive.tsx
504
- import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
179
+ import { Fragment, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
505
180
  function Checkbox({
506
181
  label,
507
182
  children,
508
183
  className,
509
184
  ...props
510
185
  }) {
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" }) }),
186
+ return /* @__PURE__ */ jsxs2("label", { className: cn("mt-check-label", className), children: [
187
+ /* @__PURE__ */ jsx2(BCheckbox.Root, { className: "mt-checkbox", ...props, children: /* @__PURE__ */ jsx2(BCheckbox.Indicator, { className: "mt-check-indicator", "aria-hidden": "true", children: props.indeterminate ? /* @__PURE__ */ jsx2(Minus, { size: 12, strokeWidth: 1.5, "aria-hidden": "true" }) : /* @__PURE__ */ jsx2(Check, { size: 12, strokeWidth: 1.5, "aria-hidden": "true" }) }) }),
513
188
  label ?? children
514
189
  ] });
515
190
  }
@@ -519,8 +194,8 @@ function Switch({
519
194
  className,
520
195
  ...props
521
196
  }) {
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" }) }),
197
+ return /* @__PURE__ */ jsxs2("label", { className: cn("mt-check-label", className), children: [
198
+ /* @__PURE__ */ jsx2(BSwitch.Root, { className: "mt-switch", ...props, children: /* @__PURE__ */ jsx2(BSwitch.Thumb, { className: "mt-switch-thumb" }) }),
524
199
  label ?? children
525
200
  ] });
526
201
  }
@@ -531,20 +206,20 @@ function RadioGroup({
531
206
  orientation = "vertical",
532
207
  ...props
533
208
  }) {
534
- return /* @__PURE__ */ jsx3(
209
+ return /* @__PURE__ */ jsx2(
535
210
  BRadioGroup,
536
211
  {
537
212
  "aria-label": label,
538
213
  className: cn("mt-radio-group", `mt-${orientation}`, className),
539
214
  ...props,
540
- children: options.map((o) => /* @__PURE__ */ jsxs3("label", { className: "mt-check-label", children: [
541
- /* @__PURE__ */ jsx3(
215
+ children: options.map((o) => /* @__PURE__ */ jsxs2("label", { className: "mt-check-label", children: [
216
+ /* @__PURE__ */ jsx2(
542
217
  BRadio.Root,
543
218
  {
544
219
  value: o.value,
545
220
  disabled: o.disabled,
546
221
  className: "mt-radio",
547
- children: /* @__PURE__ */ jsx3(BRadio.Indicator, { className: "mt-radio-indicator" })
222
+ children: /* @__PURE__ */ jsx2(BRadio.Indicator, { className: "mt-radio-indicator" })
548
223
  }
549
224
  ),
550
225
  o.label
@@ -557,41 +232,61 @@ function Select({
557
232
  label,
558
233
  placeholder,
559
234
  className,
235
+ id,
236
+ onBlur,
237
+ "aria-invalid": invalid,
238
+ "aria-describedby": describedBy,
239
+ "aria-labelledby": labelledBy,
240
+ "aria-busy": busy,
560
241
  ...props
561
242
  }) {
562
243
  const { locale } = useMtone();
563
- return /* @__PURE__ */ jsxs3(BSelect.Root, { items: options, ...props, children: [
564
- /* @__PURE__ */ jsxs3(
244
+ return /* @__PURE__ */ jsxs2(BSelect.Root, { items: options, ...props, children: [
245
+ /* @__PURE__ */ jsxs2(
565
246
  BSelect.Trigger,
566
247
  {
248
+ id,
249
+ onBlur,
250
+ "aria-invalid": invalid,
251
+ "aria-describedby": describedBy,
252
+ "aria-labelledby": labelledBy,
253
+ "aria-busy": busy,
567
254
  "aria-label": label,
568
255
  className: cn("mt-select", className),
569
256
  children: [
570
- /* @__PURE__ */ jsx3(
257
+ /* @__PURE__ */ jsx2(
571
258
  BSelect.Value,
572
259
  {
260
+ className: "mt-select-value",
573
261
  placeholder: placeholder ?? (locale === "zh" ? "\u8BF7\u9009\u62E9" : "Select\u2026")
574
262
  }
575
263
  ),
576
- /* @__PURE__ */ jsx3(BSelect.Icon, { className: "mt-select-icon", children: "\u2304" })
264
+ /* @__PURE__ */ jsx2(BSelect.Icon, { className: "mt-select-icon", children: /* @__PURE__ */ jsx2(ChevronDown, { size: 16, "aria-hidden": "true" }) })
577
265
  ]
578
266
  }
579
267
  ),
580
- /* @__PURE__ */ jsx3(BSelect.Portal, { children: /* @__PURE__ */ jsx3(MtoneScope, { children: /* @__PURE__ */ jsx3(
268
+ /* @__PURE__ */ jsx2(BSelect.Portal, { children: /* @__PURE__ */ jsx2(MtoneScope, { children: /* @__PURE__ */ jsx2(
581
269
  BSelect.Positioner,
582
270
  {
583
271
  className: "mt-positioner",
584
272
  sideOffset: 4,
585
273
  alignItemWithTrigger: false,
586
- children: /* @__PURE__ */ jsx3(BSelect.Popup, { className: "mt-popup", children: /* @__PURE__ */ jsx3(BSelect.List, { children: options.map((o) => /* @__PURE__ */ jsxs3(
274
+ children: /* @__PURE__ */ jsx2(BSelect.Popup, { className: "mt-popup", children: /* @__PURE__ */ jsx2(BSelect.List, { children: options.map((o) => /* @__PURE__ */ jsxs2(
587
275
  BSelect.Item,
588
276
  {
589
277
  className: "mt-option",
590
278
  value: o.value,
591
279
  disabled: o.disabled,
592
280
  children: [
593
- /* @__PURE__ */ jsx3(BSelect.ItemText, { children: o.label }),
594
- /* @__PURE__ */ jsx3(BSelect.ItemIndicator, { children: "\u2713" })
281
+ /* @__PURE__ */ jsx2(BSelect.ItemText, { children: o.label }),
282
+ /* @__PURE__ */ jsx2(
283
+ BSelect.ItemIndicator,
284
+ {
285
+ className: "mt-select-item-indicator",
286
+ "aria-hidden": "true",
287
+ children: /* @__PURE__ */ jsx2(Check, { size: 16, strokeWidth: 1.5, "aria-hidden": "true" })
288
+ }
289
+ )
595
290
  ]
596
291
  },
597
292
  o.value
@@ -600,17 +295,24 @@ function Select({
600
295
  ) }) })
601
296
  ] });
602
297
  }
298
+ Select.formValueType = "nullable";
603
299
  function MultiSelect({
604
300
  options,
605
301
  label,
606
302
  placeholder,
607
303
  className,
304
+ id,
305
+ onBlur,
306
+ "aria-invalid": invalid,
307
+ "aria-describedby": describedBy,
308
+ "aria-labelledby": labelledBy,
309
+ "aria-busy": busy,
608
310
  ...props
609
311
  }) {
610
312
  const { locale } = useMtone();
611
313
  const values = options.map((o) => o.value);
612
314
  const labelFor = (v) => String(options.find((o) => o.value === v)?.label ?? v);
613
- return /* @__PURE__ */ jsxs3(
315
+ return /* @__PURE__ */ jsxs2(
614
316
  Combobox.Root,
615
317
  {
616
318
  multiple: true,
@@ -618,10 +320,10 @@ function MultiSelect({
618
320
  itemToStringLabel: labelFor,
619
321
  ...props,
620
322
  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: [
323
+ /* @__PURE__ */ jsxs2(Combobox.Chips, { "aria-invalid": invalid, className: cn("mt-multiselect", className), children: [
324
+ /* @__PURE__ */ jsx2(Combobox.Value, { children: (selected) => /* @__PURE__ */ jsx2(Fragment, { children: selected.map((v) => /* @__PURE__ */ jsxs2(Combobox.Chip, { className: "mt-chip", children: [
623
325
  labelFor(v),
624
- /* @__PURE__ */ jsx3(
326
+ /* @__PURE__ */ jsx2(
625
327
  Combobox.ChipRemove,
626
328
  {
627
329
  "aria-label": `${locale === "zh" ? "\u79FB\u9664" : "Remove"} ${labelFor(v)}`,
@@ -630,26 +332,32 @@ function MultiSelect({
630
332
  }
631
333
  )
632
334
  ] }, v)) }) }),
633
- /* @__PURE__ */ jsx3(
335
+ /* @__PURE__ */ jsx2(
634
336
  Combobox.Input,
635
337
  {
338
+ id,
339
+ onBlur,
340
+ "aria-invalid": invalid,
341
+ "aria-describedby": describedBy,
342
+ "aria-labelledby": labelledBy,
343
+ "aria-busy": busy,
636
344
  "aria-label": label,
637
345
  placeholder: placeholder ?? (locale === "zh" ? "\u641C\u7D22\u2026" : "Search\u2026"),
638
346
  className: "mt-combobox-input"
639
347
  }
640
348
  ),
641
- /* @__PURE__ */ jsx3(
349
+ /* @__PURE__ */ jsx2(
642
350
  Combobox.Trigger,
643
351
  {
644
352
  className: "mt-combobox-trigger",
645
353
  "aria-label": locale === "zh" ? "\u5C55\u5F00\u9009\u9879" : "Show options",
646
- children: "\u2304"
354
+ children: /* @__PURE__ */ jsx2(ChevronDown, { size: 16, "aria-hidden": "true" })
647
355
  }
648
356
  )
649
357
  ] }),
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(
358
+ /* @__PURE__ */ jsx2(Combobox.Portal, { children: /* @__PURE__ */ jsx2(MtoneScope, { children: /* @__PURE__ */ jsx2(Combobox.Positioner, { className: "mt-positioner", sideOffset: 4, children: /* @__PURE__ */ jsxs2(Combobox.Popup, { className: "mt-popup", children: [
359
+ /* @__PURE__ */ jsx2(Combobox.Empty, { className: "mt-combobox-empty", children: locale === "zh" ? "\u65E0\u5339\u914D\u7ED3\u679C" : "No results" }),
360
+ /* @__PURE__ */ jsx2(Combobox.List, { children: (v) => /* @__PURE__ */ jsxs2(
653
361
  Combobox.Item,
654
362
  {
655
363
  className: "mt-option",
@@ -657,7 +365,7 @@ function MultiSelect({
657
365
  disabled: options.find((o) => o.value === v)?.disabled,
658
366
  children: [
659
367
  labelFor(v),
660
- /* @__PURE__ */ jsx3(Combobox.ItemIndicator, { children: "\u2713" })
368
+ /* @__PURE__ */ jsx2(Combobox.ItemIndicator, { className: "mt-select-item-indicator", "aria-hidden": "true", children: /* @__PURE__ */ jsx2(Check, { size: 16, strokeWidth: 1.5, "aria-hidden": "true" }) })
661
369
  ]
662
370
  },
663
371
  v
@@ -667,16 +375,17 @@ function MultiSelect({
667
375
  }
668
376
  );
669
377
  }
378
+ MultiSelect.formValueType = "array";
670
379
  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 })
380
+ return /* @__PURE__ */ jsx2(BSlider.Root, { className: cn("mt-slider", className), ...props, children: /* @__PURE__ */ jsx2(BSlider.Control, { className: "mt-slider-control", children: /* @__PURE__ */ jsxs2(BSlider.Track, { className: "mt-slider-track", children: [
381
+ /* @__PURE__ */ jsx2(BSlider.Indicator, { className: "mt-slider-indicator" }),
382
+ /* @__PURE__ */ jsx2(BSlider.Thumb, { className: "mt-slider-thumb", "aria-label": label })
674
383
  ] }) }) });
675
384
  }
676
385
  function NumberInput({ label, className, ...props }) {
677
386
  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(
387
+ return /* @__PURE__ */ jsx2(NumberField.Root, { className: cn("mt-number", className), ...props, children: /* @__PURE__ */ jsxs2(NumberField.Group, { className: "mt-number-group", children: [
388
+ /* @__PURE__ */ jsx2(
680
389
  NumberField.Decrement,
681
390
  {
682
391
  "aria-label": locale === "zh" ? "\u51CF\u5C11" : "Decrease",
@@ -684,8 +393,8 @@ function NumberInput({ label, className, ...props }) {
684
393
  children: "\u2212"
685
394
  }
686
395
  ),
687
- /* @__PURE__ */ jsx3(NumberField.Input, { className: "mt-number-input", "aria-label": label }),
688
- /* @__PURE__ */ jsx3(
396
+ /* @__PURE__ */ jsx2(NumberField.Input, { className: "mt-number-input", "aria-label": label }),
397
+ /* @__PURE__ */ jsx2(
689
398
  NumberField.Increment,
690
399
  {
691
400
  "aria-label": locale === "zh" ? "\u589E\u52A0" : "Increase",
@@ -702,7 +411,7 @@ function Tabs({
702
411
  defaultValue,
703
412
  ...props
704
413
  }) {
705
- return /* @__PURE__ */ jsxs3(
414
+ return /* @__PURE__ */ jsxs2(
706
415
  BTabs.Root,
707
416
  {
708
417
  className: cn("mt-tabs", className),
@@ -710,7 +419,7 @@ function Tabs({
710
419
  onValueChange: (v) => onValueChange?.(String(v)),
711
420
  ...props,
712
421
  children: [
713
- /* @__PURE__ */ jsx3(BTabs.List, { className: "mt-tab-list", children: items.map((i) => /* @__PURE__ */ jsx3(
422
+ /* @__PURE__ */ jsx2(BTabs.List, { className: "mt-tab-list", children: items.map((i) => /* @__PURE__ */ jsx2(
714
423
  BTabs.Tab,
715
424
  {
716
425
  className: "mt-tab",
@@ -720,7 +429,7 @@ function Tabs({
720
429
  },
721
430
  i.value
722
431
  )) }),
723
- items.map((i) => /* @__PURE__ */ jsx3(BTabs.Panel, { className: "mt-tab-panel", value: i.value, children: i.content }, i.value))
432
+ items.map((i) => /* @__PURE__ */ jsx2(BTabs.Panel, { className: "mt-tab-panel", value: i.value, children: i.content }, i.value))
724
433
  ]
725
434
  }
726
435
  );
@@ -731,13 +440,13 @@ function Segmented({
731
440
  className,
732
441
  ...props
733
442
  }) {
734
- return /* @__PURE__ */ jsx3(
443
+ return /* @__PURE__ */ jsx2(
735
444
  BRadioGroup,
736
445
  {
737
446
  className: cn("mt-segmented", className),
738
447
  "aria-label": label,
739
448
  ...props,
740
- children: options.map((o) => /* @__PURE__ */ jsx3(
449
+ children: options.map((o) => /* @__PURE__ */ jsx2(
741
450
  BRadio.Root,
742
451
  {
743
452
  value: o.value,
@@ -754,7 +463,7 @@ function MenuItems({
754
463
  items,
755
464
  onSelect
756
465
  }) {
757
- return /* @__PURE__ */ jsx3(Fragment, { children: items.map((i) => /* @__PURE__ */ jsxs3(
466
+ return /* @__PURE__ */ jsx2(Fragment, { children: items.map((i) => /* @__PURE__ */ jsxs2(
758
467
  Menu.Item,
759
468
  {
760
469
  className: cn("mt-menu-item", i.danger ? "mt-danger" : ""),
@@ -764,11 +473,11 @@ function MenuItems({
764
473
  onSelect?.(i.key);
765
474
  },
766
475
  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
476
+ /* @__PURE__ */ jsxs2("span", { className: "mt-menu-label", children: [
477
+ /* @__PURE__ */ jsx2("span", { "aria-hidden": "true", className: "mt-menu-icon", children: i.icon }),
478
+ /* @__PURE__ */ jsx2("span", { className: "mt-menu-text", children: i.label })
770
479
  ] }),
771
- i.shortcut && /* @__PURE__ */ jsx3("span", { className: "mt-shortcut", children: i.shortcut })
480
+ i.shortcut && /* @__PURE__ */ jsx2("span", { className: "mt-shortcut", children: i.shortcut })
772
481
  ]
773
482
  },
774
483
  i.key
@@ -780,15 +489,15 @@ function DropdownMenu({
780
489
  onSelect,
781
490
  ...props
782
491
  }) {
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(
492
+ return /* @__PURE__ */ jsxs2(Menu.Root, { ...props, children: [
493
+ /* @__PURE__ */ jsx2(Menu.Trigger, { render: trigger }),
494
+ /* @__PURE__ */ jsx2(Menu.Portal, { children: /* @__PURE__ */ jsx2(MtoneScope, { children: /* @__PURE__ */ jsx2(
786
495
  Menu.Positioner,
787
496
  {
788
497
  className: "mt-positioner",
789
498
  sideOffset: 4,
790
499
  align: "start",
791
- children: /* @__PURE__ */ jsx3(Menu.Popup, { className: "mt-popup", children: /* @__PURE__ */ jsx3(MenuItems, { items, onSelect }) })
500
+ children: /* @__PURE__ */ jsx2(Menu.Popup, { className: "mt-popup", children: /* @__PURE__ */ jsx2(MenuItems, { items, onSelect }) })
792
501
  }
793
502
  ) }) })
794
503
  ] });
@@ -799,9 +508,9 @@ function ContextMenu({
799
508
  onSelect,
800
509
  ...props
801
510
  }) {
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 }) }) }) }) })
511
+ return /* @__PURE__ */ jsxs2(BContextMenu.Root, { ...props, children: [
512
+ /* @__PURE__ */ jsx2(BContextMenu.Trigger, { children }),
513
+ /* @__PURE__ */ jsx2(BContextMenu.Portal, { children: /* @__PURE__ */ jsx2(MtoneScope, { children: /* @__PURE__ */ jsx2(BContextMenu.Positioner, { className: "mt-positioner", children: /* @__PURE__ */ jsx2(BContextMenu.Popup, { className: "mt-popup", children: /* @__PURE__ */ jsx2(MenuItems, { items, onSelect }) }) }) }) })
805
514
  ] });
806
515
  }
807
516
  function Popover({
@@ -811,16 +520,16 @@ function Popover({
811
520
  side = "bottom",
812
521
  ...props
813
522
  }) {
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(
523
+ return /* @__PURE__ */ jsxs2(BPopover.Root, { ...props, children: [
524
+ /* @__PURE__ */ jsx2(BPopover.Trigger, { render: trigger }),
525
+ /* @__PURE__ */ jsx2(BPopover.Portal, { children: /* @__PURE__ */ jsx2(MtoneScope, { children: /* @__PURE__ */ jsx2(
817
526
  BPopover.Positioner,
818
527
  {
819
528
  className: "mt-positioner",
820
529
  sideOffset: 6,
821
530
  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 }),
531
+ children: /* @__PURE__ */ jsxs2(BPopover.Popup, { className: "mt-popup mt-popover", children: [
532
+ title && /* @__PURE__ */ jsx2(BPopover.Title, { className: "mt-popup-title", children: title }),
824
533
  content
825
534
  ] })
826
535
  }
@@ -833,21 +542,22 @@ function Tooltip({
833
542
  side = "top",
834
543
  ...props
835
544
  }) {
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(
545
+ const id = useId();
546
+ return /* @__PURE__ */ jsx2(BTooltip.Provider, { children: /* @__PURE__ */ jsxs2(BTooltip.Root, { ...props, children: [
547
+ /* @__PURE__ */ jsx2(BTooltip.Trigger, { render: children, "aria-describedby": id }),
548
+ /* @__PURE__ */ jsx2(BTooltip.Portal, { children: /* @__PURE__ */ jsx2(MtoneScope, { children: /* @__PURE__ */ jsx2(
840
549
  BTooltip.Positioner,
841
550
  {
842
551
  className: "mt-positioner",
843
552
  sideOffset: 6,
844
553
  side,
845
- children: /* @__PURE__ */ jsx3(BTooltip.Popup, { className: "mt-tooltip", role: "tooltip", id, children: content })
554
+ children: /* @__PURE__ */ jsx2(BTooltip.Popup, { className: "mt-tooltip", role: "tooltip", id, children: content })
846
555
  }
847
556
  ) }) })
848
557
  ] }) });
849
558
  }
850
- function Modal({
559
+ function Dialog({
560
+ modal = true,
851
561
  title,
852
562
  description,
853
563
  children,
@@ -857,27 +567,31 @@ function Modal({
857
567
  ...props
858
568
  }) {
859
569
  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 })
570
+ const hasTitle = title !== null && title !== void 0 && title !== false && title !== "";
571
+ return /* @__PURE__ */ jsxs2(BDialog.Root, { ...props, modal: true, disablePointerDismissal: modal, children: [
572
+ trigger && /* @__PURE__ */ jsx2(BDialog.Trigger, { render: trigger }),
573
+ /* @__PURE__ */ jsx2(BDialog.Portal, { children: /* @__PURE__ */ jsxs2(MtoneScope, { children: [
574
+ /* @__PURE__ */ jsx2(BDialog.Backdrop, { className: "mt-backdrop" }),
575
+ /* @__PURE__ */ jsxs2(BDialog.Popup, { className: cn("mt-modal", "mt-modal-dialog", className), children: [
576
+ /* @__PURE__ */ jsxs2("div", { className: "mt-modal-header", children: [
577
+ /* @__PURE__ */ jsx2(BDialog.Title, { className: cn("mt-dialog-title", !hasTitle && "mt-modal-title-hidden"), children: hasTitle ? title : locale === "zh" ? "\u5BF9\u8BDD\u6846" : "Dialog" }),
578
+ /* @__PURE__ */ jsx2(
579
+ BDialog.Close,
580
+ {
581
+ className: "mt-dialog-close",
582
+ "aria-label": locale === "zh" ? "\u5173\u95ED" : "Close",
583
+ children: /* @__PURE__ */ jsx2(X, { size: 18, "aria-hidden": "true" })
584
+ }
585
+ )
586
+ ] }),
587
+ description && /* @__PURE__ */ jsx2(BDialog.Description, { className: "mt-dialog-description", children: description }),
588
+ /* @__PURE__ */ jsx2("div", { className: "mt-dialog-body", children }),
589
+ footer && /* @__PURE__ */ jsx2("div", { className: "mt-dialog-footer", children: footer })
877
590
  ] })
878
591
  ] }) })
879
592
  ] });
880
593
  }
594
+ var Modal = Dialog;
881
595
  function ConfirmDialog({
882
596
  title,
883
597
  description,
@@ -892,9 +606,9 @@ function ConfirmDialog({
892
606
  onOpenChange
893
607
  }) {
894
608
  const { locale } = useMtone();
895
- const [localOpen, setOpen] = useState2(defaultOpen ?? false);
896
- const [pending, setPending] = useState2(false);
897
- const [error, setError] = useState2(false);
609
+ const [localOpen, setOpen] = useState(defaultOpen ?? false);
610
+ const [pending, setPending] = useState(false);
611
+ const [error, setError] = useState(false);
898
612
  const change = (v) => {
899
613
  setOpen(v);
900
614
  onOpenChange?.(v);
@@ -911,18 +625,18 @@ function ConfirmDialog({
911
625
  setPending(false);
912
626
  }
913
627
  };
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 }),
628
+ return /* @__PURE__ */ jsxs2(AlertDialog.Root, { open: open ?? localOpen, onOpenChange: change, children: [
629
+ trigger && /* @__PURE__ */ jsx2(AlertDialog.Trigger, { render: trigger }),
630
+ /* @__PURE__ */ jsx2(AlertDialog.Portal, { children: /* @__PURE__ */ jsxs2(MtoneScope, { children: [
631
+ /* @__PURE__ */ jsx2(AlertDialog.Backdrop, { className: "mt-backdrop" }),
632
+ /* @__PURE__ */ jsxs2(AlertDialog.Popup, { className: "mt-modal", children: [
633
+ /* @__PURE__ */ jsx2(AlertDialog.Title, { className: "mt-dialog-title", children: title }),
634
+ description && /* @__PURE__ */ jsx2(AlertDialog.Description, { className: "mt-dialog-description", children: description }),
921
635
  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(
636
+ error && /* @__PURE__ */ jsx2("p", { role: "alert", children: locale === "zh" ? "\u64CD\u4F5C\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002" : "Something went wrong. Please try again." }),
637
+ /* @__PURE__ */ jsxs2("div", { className: "mt-dialog-footer", children: [
638
+ /* @__PURE__ */ jsx2(AlertDialog.Close, { className: "mt-action", disabled: pending, children: cancelText ?? (locale === "zh" ? "\u53D6\u6D88" : "Cancel") }),
639
+ /* @__PURE__ */ jsx2(
926
640
  "button",
927
641
  {
928
642
  className: cn(
@@ -950,14 +664,14 @@ function Drawer({
950
664
  ...props
951
665
  }) {
952
666
  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(
667
+ return /* @__PURE__ */ jsxs2(BDrawer.Root, { swipeDirection: "right", ...props, children: [
668
+ trigger && /* @__PURE__ */ jsx2(BDrawer.Trigger, { render: trigger }),
669
+ /* @__PURE__ */ jsx2(BDrawer.Portal, { children: /* @__PURE__ */ jsxs2(MtoneScope, { children: [
670
+ /* @__PURE__ */ jsx2(BDrawer.Backdrop, { className: "mt-backdrop" }),
671
+ /* @__PURE__ */ jsx2(BDrawer.Viewport, { className: "mt-drawer-viewport", children: /* @__PURE__ */ jsx2(BDrawer.Popup, { className: cn("mt-drawer", className), children: /* @__PURE__ */ jsxs2(BDrawer.Content, { children: [
672
+ /* @__PURE__ */ jsx2(BDrawer.Title, { className: "mt-dialog-title", children: title }),
673
+ description && /* @__PURE__ */ jsx2(BDrawer.Description, { className: "mt-dialog-description", children: description }),
674
+ /* @__PURE__ */ jsx2(
961
675
  BDrawer.Close,
962
676
  {
963
677
  className: "mt-dialog-close",
@@ -965,150 +679,2381 @@ function Drawer({
965
679
  children: "\xD7"
966
680
  }
967
681
  ),
968
- /* @__PURE__ */ jsx3("div", { className: "mt-dialog-body", children }),
969
- footer && /* @__PURE__ */ jsx3("div", { className: "mt-dialog-footer", children: footer })
682
+ /* @__PURE__ */ jsx2("div", { className: "mt-dialog-body", children }),
683
+ footer && /* @__PURE__ */ jsx2("div", { className: "mt-dialog-footer", children: footer })
970
684
  ] }) }) })
971
685
  ] }) })
972
686
  ] });
973
687
  }
974
688
 
975
- // src/navigation.tsx
689
+ // src/card.tsx
690
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
691
+ function hasContent(value) {
692
+ return React2.Children.toArray(value).some((child) => {
693
+ if (React2.isValidElement(child) && child.type === React2.Fragment) {
694
+ return hasContent(child.props.children);
695
+ }
696
+ return child !== "";
697
+ });
698
+ }
699
+ function resolve(value, props) {
700
+ return typeof value === "function" ? value({ props }) : value ?? {};
701
+ }
702
+ function tokenStyles(tokens) {
703
+ const result = {};
704
+ for (const [key, value] of Object.entries(tokens ?? {})) {
705
+ if (value !== void 0)
706
+ result["--mt-card-" + key.replace(/([a-z])([A-Z])/g, "$1-$2").toLowerCase()] = typeof value === "number" ? value + "px" : value;
707
+ }
708
+ return result;
709
+ }
710
+ function CardRoot(props) {
711
+ const {
712
+ children,
713
+ title,
714
+ htmlTitle,
715
+ extra,
716
+ cover,
717
+ actions,
718
+ loading = false,
719
+ loadingLabel,
720
+ size = "medium",
721
+ variant = "outlined",
722
+ hoverable = false,
723
+ type,
724
+ tabList,
725
+ activeTabKey,
726
+ defaultActiveTabKey,
727
+ onTabChange,
728
+ tabBarExtraContent,
729
+ tabProps,
730
+ classNames,
731
+ styles,
732
+ tokens,
733
+ className,
734
+ style,
735
+ ...native
736
+ } = props;
737
+ const { locale } = useMtone();
738
+ const [localTab, setLocalTab] = React2.useState(defaultActiveTabKey);
739
+ const available = tabList ?? [];
740
+ const first = available.find((tab) => !tab.disabled)?.key;
741
+ const selected = activeTabKey !== void 0 ? activeTabKey : available.some((tab) => tab.key === localTab && !tab.disabled) ? localTab : first;
742
+ React2.useEffect(() => {
743
+ if (activeTabKey === void 0 && !available.some((tab) => tab.key === localTab && !tab.disabled) && localTab !== first)
744
+ setLocalTab(first);
745
+ }, [activeTabKey, available, localTab, first]);
746
+ const structured = [
747
+ "title",
748
+ "extra",
749
+ "cover",
750
+ "actions",
751
+ "loading",
752
+ "loadingLabel",
753
+ "size",
754
+ "variant",
755
+ "hoverable",
756
+ "type",
757
+ "tabList",
758
+ "activeTabKey",
759
+ "defaultActiveTabKey",
760
+ "onTabChange",
761
+ "tabBarExtraContent",
762
+ "tabProps",
763
+ "classNames",
764
+ "styles",
765
+ "tokens"
766
+ ].some((key) => props[key] !== void 0);
767
+ if (!structured)
768
+ return /* @__PURE__ */ jsx3(
769
+ "div",
770
+ {
771
+ ...native,
772
+ title: htmlTitle,
773
+ className: cn("mt-card", className),
774
+ style,
775
+ children
776
+ }
777
+ );
778
+ const classes = resolve(classNames, props), css = resolve(styles, props);
779
+ const hasHeader = hasContent(title) || hasContent(extra);
780
+ const hasTabs = available.length > 0;
781
+ const loadingText = loadingLabel ?? (locale === "zh" ? "\u6B63\u5728\u52A0\u8F7D" : "Loading");
782
+ const body = (content) => /* @__PURE__ */ jsx3("div", { className: cn("mt-card-body", classes.body), style: css.body, children: loading ? /* @__PURE__ */ jsxs3("div", { className: "mt-card-loading", role: "status", "aria-label": loadingText, children: [
783
+ /* @__PURE__ */ jsx3(Skeleton, { style: { width: "60%", height: 16 } }),
784
+ /* @__PURE__ */ jsx3(Skeleton, { style: { height: 12 } }),
785
+ /* @__PURE__ */ jsx3(Skeleton, { style: { width: "80%", height: 12 } })
786
+ ] }) : content });
787
+ return /* @__PURE__ */ jsxs3(
788
+ "div",
789
+ {
790
+ ...native,
791
+ title: htmlTitle,
792
+ "aria-busy": loading || native["aria-busy"],
793
+ className: cn(
794
+ "mt-card",
795
+ "mt-card-structured",
796
+ size === "small" && "mt-card-small",
797
+ variant === "borderless" && "mt-card-borderless",
798
+ hoverable && "mt-card-hoverable",
799
+ type === "inner" && "mt-card-inner",
800
+ classes.root,
801
+ className
802
+ ),
803
+ style: { ...tokenStyles(tokens), ...css.root, ...style },
804
+ children: [
805
+ hasHeader && /* @__PURE__ */ jsxs3(
806
+ "div",
807
+ {
808
+ className: cn("mt-card-header", classes.header),
809
+ style: css.header,
810
+ children: [
811
+ hasContent(title) && /* @__PURE__ */ jsx3(
812
+ "div",
813
+ {
814
+ className: cn("mt-card-title", classes.title),
815
+ style: css.title,
816
+ children: title
817
+ }
818
+ ),
819
+ hasContent(extra) && /* @__PURE__ */ jsx3(
820
+ "div",
821
+ {
822
+ className: cn("mt-card-extra", classes.extra),
823
+ style: css.extra,
824
+ children: extra
825
+ }
826
+ )
827
+ ]
828
+ }
829
+ ),
830
+ hasContent(cover) && /* @__PURE__ */ jsx3("div", { className: cn("mt-card-cover", classes.cover), style: css.cover, children: cover }),
831
+ hasTabs ? /* @__PURE__ */ jsxs3(
832
+ "div",
833
+ {
834
+ className: cn("mt-card-tabs-layout", classes.tabs),
835
+ style: css.tabs,
836
+ children: [
837
+ /* @__PURE__ */ jsx3(
838
+ Tabs,
839
+ {
840
+ ...tabProps,
841
+ className: cn("mt-card-tabs", tabProps?.className),
842
+ value: selected ?? "",
843
+ onValueChange: (key) => {
844
+ if (activeTabKey === void 0) setLocalTab(key);
845
+ onTabChange?.(key);
846
+ },
847
+ items: available.map((tab) => ({
848
+ value: tab.key,
849
+ label: tab.label,
850
+ disabled: tab.disabled,
851
+ content: body(tab.content === void 0 ? children : tab.content)
852
+ }))
853
+ }
854
+ ),
855
+ hasContent(tabBarExtraContent) && /* @__PURE__ */ jsx3("div", { className: "mt-card-tab-extra", children: tabBarExtraContent })
856
+ ]
857
+ }
858
+ ) : body(children),
859
+ !!actions?.length && /* @__PURE__ */ jsx3(
860
+ "ul",
861
+ {
862
+ className: cn("mt-card-actions", classes.actions),
863
+ style: css.actions,
864
+ children: actions.map((action, i) => /* @__PURE__ */ jsx3("li", { children: action }, i))
865
+ }
866
+ )
867
+ ]
868
+ }
869
+ );
870
+ }
871
+ function CardMeta(props) {
872
+ const {
873
+ avatar,
874
+ title,
875
+ htmlTitle,
876
+ description,
877
+ className,
878
+ style,
879
+ classNames,
880
+ styles,
881
+ children,
882
+ ...native
883
+ } = props;
884
+ const classes = resolve(classNames, props), css = resolve(styles, props);
885
+ return /* @__PURE__ */ jsxs3(
886
+ "div",
887
+ {
888
+ ...native,
889
+ title: htmlTitle,
890
+ className: cn("mt-card-meta", classes.root, className),
891
+ style: { ...css.root, ...style },
892
+ children: [
893
+ hasContent(avatar) && /* @__PURE__ */ jsx3(
894
+ "div",
895
+ {
896
+ className: cn("mt-card-meta-avatar", classes.avatar),
897
+ style: css.avatar,
898
+ children: avatar
899
+ }
900
+ ),
901
+ /* @__PURE__ */ jsxs3(
902
+ "div",
903
+ {
904
+ className: cn("mt-card-meta-section", classes.section),
905
+ style: css.section,
906
+ children: [
907
+ hasContent(title) && /* @__PURE__ */ jsx3(
908
+ "div",
909
+ {
910
+ className: cn("mt-card-meta-title", classes.title),
911
+ style: css.title,
912
+ children: title
913
+ }
914
+ ),
915
+ hasContent(description) && /* @__PURE__ */ jsx3(
916
+ "div",
917
+ {
918
+ className: cn("mt-card-meta-description", classes.description),
919
+ style: css.description,
920
+ children: description
921
+ }
922
+ ),
923
+ children
924
+ ]
925
+ }
926
+ )
927
+ ]
928
+ }
929
+ );
930
+ }
931
+ function CardGrid({ hoverable = true, className, ...props }) {
932
+ return /* @__PURE__ */ jsx3(
933
+ "div",
934
+ {
935
+ ...props,
936
+ className: cn(
937
+ "mt-card-grid",
938
+ hoverable && "mt-card-grid-hoverable",
939
+ className
940
+ )
941
+ }
942
+ );
943
+ }
944
+ var Card = Object.assign(CardRoot, { Meta: CardMeta, Grid: CardGrid });
945
+
946
+ // src/basic.tsx
947
+ import * as React4 from "react";
948
+ import { Button as BaseButton } from "@base-ui/react/button";
949
+ import { Input as BaseInput } from "@base-ui/react/input";
950
+ import {
951
+ LoaderCircle as LoaderCircle2,
952
+ Search,
953
+ X as X2,
954
+ FileText,
955
+ Inbox,
956
+ Info as Info2,
957
+ CheckCircle,
958
+ TriangleAlert,
959
+ AlertCircle
960
+ } from "lucide-react";
961
+
962
+ // src/form.tsx
963
+ import React3 from "react";
964
+
965
+ // src/form-store.ts
966
+ var own = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
967
+ var empty = (value) => value == null || value === "" || Array.isArray(value) && value.length === 0;
968
+ async function validateRule(name, rule, value, values) {
969
+ const failure = (message) => rule.message ?? message;
970
+ if (empty(value) && rule.required) return failure(`${name} is required`);
971
+ if (!empty(value)) {
972
+ if (rule.whitespace && typeof value === "string" && value.trim() === "")
973
+ return failure(`${name} cannot be blank`);
974
+ let typeValid = true;
975
+ switch (rule.type) {
976
+ case "string":
977
+ typeValid = typeof value === "string";
978
+ break;
979
+ case "number":
980
+ typeValid = typeof value === "number" && Number.isFinite(value);
981
+ break;
982
+ case "integer":
983
+ typeValid = typeof value === "number" && Number.isInteger(value);
984
+ break;
985
+ case "boolean":
986
+ typeValid = typeof value === "boolean";
987
+ break;
988
+ case "array":
989
+ typeValid = Array.isArray(value);
990
+ break;
991
+ case "email":
992
+ typeValid = typeof value === "string" && /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(value);
993
+ break;
994
+ case "url": {
995
+ try {
996
+ const url = new URL(typeof value === "string" ? value : "");
997
+ typeValid = !!url.protocol && !!url.hostname;
998
+ } catch {
999
+ typeValid = false;
1000
+ }
1001
+ break;
1002
+ }
1003
+ }
1004
+ if (!typeValid) return failure(`${name} must be ${rule.type}`);
1005
+ const size = typeof value === "number" ? value : typeof value === "string" || Array.isArray(value) ? value.length : void 0;
1006
+ if (rule.len !== void 0 && size !== rule.len)
1007
+ return failure(`${name} must have length ${rule.len}`);
1008
+ if (rule.min !== void 0 && (size === void 0 || !Number.isFinite(size) || size < rule.min))
1009
+ return failure(`${name} must be at least ${rule.min}`);
1010
+ if (rule.max !== void 0 && (size === void 0 || !Number.isFinite(size) || size > rule.max))
1011
+ return failure(`${name} must be at most ${rule.max}`);
1012
+ if (rule.pattern && (typeof value !== "string" || !new RegExp(rule.pattern.source, rule.pattern.flags).test(value)))
1013
+ return failure(`${name} has an invalid format`);
1014
+ }
1015
+ if (rule.validator) {
1016
+ try {
1017
+ const result = await rule.validator(rule, value, { ...values });
1018
+ if (typeof result === "string") return failure(result);
1019
+ } catch (error) {
1020
+ return failure(
1021
+ error instanceof Error ? error.message : typeof error === "string" ? error : `${name} is invalid`
1022
+ );
1023
+ }
1024
+ }
1025
+ return void 0;
1026
+ }
1027
+ function createFormStore(initialValues = {}) {
1028
+ let baseline = { ...initialValues };
1029
+ let values = { ...initialValues };
1030
+ const fieldDefaults = /* @__PURE__ */ new Map();
1031
+ const fields = /* @__PURE__ */ new Map();
1032
+ const listeners = /* @__PURE__ */ new Set();
1033
+ let version = 0;
1034
+ let revision = 0;
1035
+ const publish = () => {
1036
+ version++;
1037
+ for (const listener of [...listeners]) listener();
1038
+ };
1039
+ const invalidate = () => {
1040
+ revision++;
1041
+ for (const field of fields.values()) {
1042
+ field.epoch++;
1043
+ field.validating = false;
1044
+ }
1045
+ };
1046
+ const getFieldsError = (names = [...fields.keys()]) => [...new Set(names)].map((name) => ({
1047
+ name,
1048
+ errors: [...fields.get(name)?.errors ?? []]
1049
+ }));
1050
+ const setFieldsValue = (next) => {
1051
+ invalidate();
1052
+ values = { ...values, ...next };
1053
+ for (const name of Object.keys(next)) {
1054
+ const field = fields.get(name);
1055
+ if (field) field.errors = [];
1056
+ }
1057
+ publish();
1058
+ };
1059
+ return {
1060
+ getFieldValue: (name) => own(values, name) ? values[name] : void 0,
1061
+ getFieldsValue: () => ({ ...values }),
1062
+ setFieldValue: (name, value) => setFieldsValue({ [name]: value }),
1063
+ setFieldsValue,
1064
+ getFieldError: (name) => [...fields.get(name)?.errors ?? []],
1065
+ getFieldsError,
1066
+ isFieldValidating: (name) => fields.get(name)?.validating ?? false,
1067
+ subscribe(listener) {
1068
+ listeners.add(listener);
1069
+ return () => {
1070
+ listeners.delete(listener);
1071
+ };
1072
+ },
1073
+ getSnapshot: () => version,
1074
+ register(name, config) {
1075
+ invalidate();
1076
+ const previous = fields.get(name);
1077
+ if (!fieldDefaults.has(name) && own(config, "initialValue"))
1078
+ fieldDefaults.set(name, config.initialValue);
1079
+ if (!own(values, name)) {
1080
+ if (own(baseline, name)) values = { ...values, [name]: baseline[name] };
1081
+ else if (fieldDefaults.has(name))
1082
+ values = { ...values, [name]: fieldDefaults.get(name) };
1083
+ }
1084
+ const field = {
1085
+ token: Symbol(name),
1086
+ get rules() {
1087
+ return config.rules ?? [];
1088
+ },
1089
+ epoch: 0,
1090
+ validating: false,
1091
+ errors: previous?.errors ?? []
1092
+ };
1093
+ fields.set(name, field);
1094
+ publish();
1095
+ return () => {
1096
+ if (fields.get(name)?.token !== field.token) return;
1097
+ invalidate();
1098
+ fields.delete(name);
1099
+ publish();
1100
+ };
1101
+ },
1102
+ setInitialValues(next) {
1103
+ invalidate();
1104
+ baseline = { ...next };
1105
+ for (const name of Object.keys(next))
1106
+ if (!own(values, name)) values = { ...values, [name]: next[name] };
1107
+ publish();
1108
+ },
1109
+ resetFields(names) {
1110
+ invalidate();
1111
+ const targets = names ? [...new Set(names)] : [
1112
+ .../* @__PURE__ */ new Set([
1113
+ ...Object.keys(values),
1114
+ ...Object.keys(baseline),
1115
+ ...fieldDefaults.keys(),
1116
+ ...fields.keys()
1117
+ ])
1118
+ ];
1119
+ const next = { ...values };
1120
+ for (const name of targets) {
1121
+ if (own(baseline, name))
1122
+ Object.defineProperty(next, name, {
1123
+ value: baseline[name],
1124
+ enumerable: true,
1125
+ configurable: true,
1126
+ writable: true
1127
+ });
1128
+ else if (fieldDefaults.has(name))
1129
+ Object.defineProperty(next, name, {
1130
+ value: fieldDefaults.get(name),
1131
+ enumerable: true,
1132
+ configurable: true,
1133
+ writable: true
1134
+ });
1135
+ else delete next[name];
1136
+ const field = fields.get(name);
1137
+ if (field) field.errors = [];
1138
+ }
1139
+ values = next;
1140
+ publish();
1141
+ },
1142
+ async validateFields(names) {
1143
+ const snapshot = { ...values };
1144
+ const startedRevision = revision;
1145
+ const targets = [...new Set(names ?? [...fields.keys()])].flatMap(
1146
+ (name) => {
1147
+ const field = fields.get(name);
1148
+ if (!field) return [];
1149
+ field.epoch++;
1150
+ field.validating = true;
1151
+ return [{ name, field, epoch: field.epoch }];
1152
+ }
1153
+ );
1154
+ if (targets.length) publish();
1155
+ const stale = (target) => revision !== startedRevision || fields.get(target.name) !== target.field || target.field.epoch !== target.epoch;
1156
+ const results = await Promise.all(
1157
+ targets.map(async (target) => {
1158
+ let error;
1159
+ for (const rule of target.field.rules) {
1160
+ if (stale(target)) break;
1161
+ error = await validateRule(
1162
+ target.name,
1163
+ rule,
1164
+ own(snapshot, target.name) ? snapshot[target.name] : void 0,
1165
+ snapshot
1166
+ );
1167
+ if (error !== void 0) break;
1168
+ }
1169
+ if (!stale(target)) {
1170
+ target.field.errors = error === void 0 ? [] : [error];
1171
+ target.field.validating = false;
1172
+ publish();
1173
+ }
1174
+ return {
1175
+ name: target.name,
1176
+ errors: error === void 0 ? [] : [error]
1177
+ };
1178
+ })
1179
+ );
1180
+ const outOfDate = revision !== startedRevision || targets.some(stale);
1181
+ const errorFields = results.filter((result) => result.errors.length > 0);
1182
+ if (outOfDate || errorFields.length)
1183
+ throw {
1184
+ values: snapshot,
1185
+ errorFields,
1186
+ outOfDate
1187
+ };
1188
+ return snapshot;
1189
+ }
1190
+ };
1191
+ }
1192
+
1193
+ // src/form.tsx
976
1194
  import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
977
- var SidebarContext = React3.createContext(false);
978
- function Sidebar({
1195
+ var Context = React3.createContext(null);
1196
+ var emptySubscribe = () => () => {
1197
+ };
1198
+ var emptySnapshot = () => 0;
1199
+ function useForm() {
1200
+ const [form] = React3.useState(() => createFormStore());
1201
+ return [form];
1202
+ }
1203
+ function FormField({
1204
+ label,
1205
+ error,
1206
+ description,
1207
+ required,
1208
+ children,
1209
+ name,
1210
+ rules,
1211
+ initialValue,
1212
+ validateTrigger,
1213
+ valuePropName = "value",
1214
+ trigger: triggerProp,
1215
+ getValueFromEvent
1216
+ }) {
1217
+ const context = React3.useContext(Context);
1218
+ const form = name !== void 0 ? context?.form : void 0;
1219
+ React3.useSyncExternalStore(form?.subscribe ?? emptySubscribe, form?.getSnapshot ?? emptySnapshot, emptySnapshot);
1220
+ const generatedId = React3.useId();
1221
+ const child = children;
1222
+ const inputId = child.props.id || generatedId;
1223
+ const kind = child.type.formValueType;
1224
+ const trigger = triggerProp ?? (kind ? "onValueChange" : "onChange");
1225
+ const rulesRef = React3.useRef({ rules, required });
1226
+ rulesRef.current = { rules, required };
1227
+ React3.useEffect(() => {
1228
+ if (!form || name === void 0) return;
1229
+ return form.register(name, { get rules() {
1230
+ const latest = rulesRef.current;
1231
+ return latest.required && !latest.rules?.some((rule) => rule.required) ? [{ required: true }, ...latest.rules ?? []] : latest.rules ?? [];
1232
+ }, initialValue });
1233
+ }, [form, name]);
1234
+ const messages = form && name !== void 0 ? form.getFieldError(name) : [];
1235
+ const managedError = messages.length ? messages.join(" ") : void 0;
1236
+ const shownError = error !== void 0 ? error : managedError;
1237
+ const invalid = !!shownError;
1238
+ const busy = form && name !== void 0 ? form.isFieldValidating(name) : false;
1239
+ const help = shownError || description;
1240
+ const helpId = `${generatedId}-help`;
1241
+ const requiredValue = required ?? rules?.some((rule) => rule.required) ?? child.props.required;
1242
+ const props = {
1243
+ id: inputId,
1244
+ required: requiredValue,
1245
+ "aria-invalid": invalid || (error === void 0 && !form ? child.props["aria-invalid"] : false),
1246
+ "aria-describedby": [child.props["aria-describedby"], help ? helpId : void 0].filter(Boolean).join(" ") || void 0,
1247
+ "aria-busy": busy || void 0
1248
+ };
1249
+ if (form && name !== void 0) {
1250
+ const value = form.getFieldValue(name);
1251
+ props[valuePropName] = value ?? (valuePropName === "checked" ? false : trigger === "onValueChange" ? kind === "array" || Array.isArray(initialValue) ? [] : null : "");
1252
+ props.name = name;
1253
+ const modes = validateTrigger ?? context?.validateTrigger ?? "onChange";
1254
+ const shouldValidate = (mode) => modes !== false && (Array.isArray(modes) ? modes.includes(mode) : modes === mode);
1255
+ const validate = () => {
1256
+ void form.validateFields([name]).catch(() => {
1257
+ });
1258
+ };
1259
+ props[trigger] = (...args) => {
1260
+ const event = args[0];
1261
+ const next = getValueFromEvent ? getValueFromEvent(...args) : event?.target ? event.target[valuePropName] : event;
1262
+ form.setFieldValue(name, next);
1263
+ child.props[trigger]?.(...args);
1264
+ context?.onValuesChange?.({ [name]: next }, form.getFieldsValue());
1265
+ if (trigger !== "onBlur" && shouldValidate("onChange")) validate();
1266
+ };
1267
+ const changeHandler = props[trigger];
1268
+ props.onBlur = (...args) => {
1269
+ if (trigger === "onBlur") changeHandler(...args);
1270
+ else child.props.onBlur?.(...args);
1271
+ if (shouldValidate("onBlur")) validate();
1272
+ };
1273
+ }
1274
+ return /* @__PURE__ */ jsxs4("div", { className: "mt-field", "data-field-name": name, children: [
1275
+ /* @__PURE__ */ jsxs4("label", { htmlFor: inputId, children: [
1276
+ label,
1277
+ requiredValue && /* @__PURE__ */ jsx4("span", { "aria-hidden": "true", children: " *" })
1278
+ ] }),
1279
+ React3.cloneElement(child, props),
1280
+ help && /* @__PURE__ */ jsx4("div", { id: helpId, className: `mt-help${invalid ? " mt-error" : ""}`, "aria-live": "polite", children: help })
1281
+ ] });
1282
+ }
1283
+ function FormRoot({
1284
+ form: supplied,
1285
+ initialValues,
1286
+ validateTrigger = "onChange",
1287
+ onFinish,
1288
+ onFinishFailed,
1289
+ onValuesChange,
979
1290
  className,
1291
+ onSubmit,
1292
+ onReset,
1293
+ noValidate,
980
1294
  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
1295
+ ...props
991
1296
  }) {
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,
1297
+ const [local] = useForm();
1298
+ const form = supplied ?? local;
1299
+ const initialised = React3.useRef(null);
1300
+ if (initialised.current !== form) {
1301
+ form.setInitialValues(initialValues ?? {});
1302
+ initialised.current = form;
1303
+ }
1304
+ React3.useSyncExternalStore(form.subscribe, form.getSnapshot, emptySnapshot);
1305
+ const managed = !!supplied || !!onFinish || form.getFieldsError().length > 0;
1306
+ const revision = React3.useRef(0);
1307
+ React3.useEffect(() => () => {
1308
+ revision.current++;
1309
+ }, []);
1310
+ return /* @__PURE__ */ jsx4(Context.Provider, { value: { form, validateTrigger, onValuesChange }, children: /* @__PURE__ */ jsx4(
1311
+ "form",
997
1312
  {
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);
1313
+ ...props,
1314
+ className: ["mt-form", className].filter(Boolean).join(" "),
1315
+ noValidate: noValidate ?? (managed || void 0),
1316
+ onReset: (event) => {
1317
+ onReset?.(event);
1318
+ if (!event.defaultPrevented && managed) {
1319
+ revision.current++;
1320
+ form.resetFields();
1321
+ }
1322
+ },
1323
+ onSubmit: (event) => {
1324
+ onSubmit?.(event);
1325
+ if (!managed || event.defaultPrevented) return;
1326
+ event.preventDefault();
1327
+ const attempt = ++revision.current;
1328
+ void form.validateFields().then((values) => {
1329
+ if (attempt === revision.current) onFinish?.(values);
1330
+ }, (error) => {
1331
+ if (attempt !== revision.current || error.outOfDate) return;
1332
+ onFinishFailed?.(error);
1333
+ });
1007
1334
  },
1008
- children: isCollapsed ? /* @__PURE__ */ jsx4(PanelLeftOpen, { size: 16, "aria-hidden": "true" }) : /* @__PURE__ */ jsx4(PanelLeftClose, { size: 16, "aria-hidden": "true" })
1335
+ children
1009
1336
  }
1010
- );
1011
- return /* @__PURE__ */ jsx4(SidebarContext.Provider, { value: isCollapsed, children: /* @__PURE__ */ jsxs4(
1012
- "aside",
1337
+ ) });
1338
+ }
1339
+ var Form = Object.assign(FormRoot, { useForm, Item: FormField });
1340
+
1341
+ // src/basic.tsx
1342
+ import { jsx as jsx5, jsxs as jsxs5 } from "react/jsx-runtime";
1343
+ var cn = (...v) => v.filter(Boolean).join(" ");
1344
+ var MtoneContext = React4.createContext({
1345
+ locale: "zh",
1346
+ density: "compact"
1347
+ });
1348
+ var useMtone = () => React4.useContext(MtoneContext);
1349
+ function MtoneScope({
1350
+ children,
1351
+ className,
1352
+ style,
1353
+ ...props
1354
+ }) {
1355
+ const c = useMtone();
1356
+ return /* @__PURE__ */ jsx5(
1357
+ "div",
1013
1358
  {
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
- ]
1359
+ ...props,
1360
+ className: cn("mt-scope", className),
1361
+ "data-density": c.density,
1362
+ style: { ...c.tokens, ...style },
1363
+ children
1028
1364
  }
1029
- ) });
1365
+ );
1030
1366
  }
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",
1367
+ function MtoneProvider({
1368
+ children,
1369
+ locale = "zh",
1370
+ density = "compact",
1371
+ tokens
1372
+ }) {
1373
+ return /* @__PURE__ */ jsx5(MtoneContext.Provider, { value: { locale, density, tokens }, children: /* @__PURE__ */ jsx5(MtoneScope, { children }) });
1374
+ }
1375
+ var Button = React4.forwardRef(
1376
+ function Button2({
1377
+ variant = "outline",
1378
+ size = "md",
1379
+ danger,
1380
+ loading,
1381
+ icon,
1382
+ children,
1383
+ className,
1384
+ disabled,
1385
+ ...props
1386
+ }, ref) {
1387
+ return /* @__PURE__ */ jsxs5(
1388
+ BaseButton,
1389
+ {
1390
+ ...props,
1391
+ ref,
1392
+ disabled: disabled || loading,
1393
+ "aria-busy": loading || void 0,
1394
+ className: cn(
1395
+ "mt-btn",
1396
+ `mt-btn-${variant}`,
1397
+ `mt-size-${size}`,
1398
+ danger && "mt-danger",
1399
+ className
1400
+ ),
1401
+ children: [
1402
+ loading ? /* @__PURE__ */ jsx5(LoaderCircle2, { className: "mt-spin", size: 14 }) : icon,
1403
+ children
1404
+ ]
1405
+ }
1406
+ );
1407
+ }
1408
+ );
1409
+ var IconButton = React4.forwardRef(function IconButton2(p, r) {
1410
+ return /* @__PURE__ */ jsx5(Button, { ...p, ref: r, className: cn("mt-icon-btn", p.className) });
1411
+ });
1412
+ var ButtonGroup = ({
1413
+ className,
1414
+ ...p
1415
+ }) => /* @__PURE__ */ jsx5("div", { role: "group", ...p, className: cn("mt-button-group", className) });
1416
+ var Input = React4.forwardRef(function Input2({ className, ...p }, r) {
1417
+ return /* @__PURE__ */ jsx5(BaseInput, { ...p, ref: r, className: cn("mt-input mt-input-control", className) });
1418
+ });
1419
+ var Textarea = React4.forwardRef(function Textarea2({ className, ...p }, r) {
1420
+ return /* @__PURE__ */ jsx5(
1421
+ "textarea",
1422
+ {
1423
+ ...p,
1424
+ ref: r,
1425
+ className: cn("mt-input mt-textarea", className)
1426
+ }
1427
+ );
1428
+ });
1429
+ var SearchInput = React4.forwardRef(function SearchInput2({ className, ...p }, r) {
1430
+ return /* @__PURE__ */ jsxs5("span", { className: "mt-search", children: [
1431
+ /* @__PURE__ */ jsx5(Search, { size: 15 }),
1432
+ /* @__PURE__ */ jsx5(BaseInput, { ...p, ref: r, className: cn("mt-input", className) })
1433
+ ] });
1434
+ });
1435
+ function Badge({
1436
+ children,
1437
+ tone = "neutral",
1438
+ onRemove,
1439
+ className,
1440
+ ...p
1441
+ }) {
1442
+ const { locale } = useMtone();
1443
+ return /* @__PURE__ */ jsxs5("span", { ...p, className: cn("mt-badge", `mt-tone-${tone}`, className), children: [
1444
+ children,
1445
+ onRemove && /* @__PURE__ */ jsx5(
1446
+ "button",
1447
+ {
1448
+ type: "button",
1449
+ onClick: onRemove,
1450
+ "aria-label": locale === "zh" ? "\u79FB\u9664\u6807\u7B7E" : "Remove tag",
1451
+ children: /* @__PURE__ */ jsx5(X2, { size: 11 })
1452
+ }
1453
+ )
1454
+ ] });
1455
+ }
1456
+ var Status = ({
1457
+ children,
1458
+ tone = "neutral"
1459
+ }) => /* @__PURE__ */ jsxs5("span", { className: cn("mt-status", `mt-tone-${tone}`), children: [
1460
+ /* @__PURE__ */ jsx5("i", {}),
1461
+ children
1462
+ ] });
1463
+ function Avatar({
1464
+ src,
1465
+ name = "",
1466
+ size = 24
1467
+ }) {
1468
+ const [failed, setFailed] = React4.useState(false);
1469
+ React4.useEffect(() => setFailed(false), [src]);
1470
+ return /* @__PURE__ */ jsx5(
1471
+ "span",
1472
+ {
1473
+ className: "mt-avatar",
1474
+ style: { width: size, height: size },
1475
+ "aria-label": name,
1476
+ children: src && !failed ? /* @__PURE__ */ jsx5("img", { src, alt: name, onError: () => setFailed(true) }) : name.slice(0, 2).toUpperCase()
1477
+ }
1478
+ );
1479
+ }
1480
+ function AvatarGroup({
1481
+ items,
1482
+ max = 4
1483
+ }) {
1484
+ return /* @__PURE__ */ jsxs5("span", { className: "mt-avatar-group", children: [
1485
+ items.slice(0, max).map((x, i) => /* @__PURE__ */ jsx5(Avatar, { ...x }, i)),
1486
+ items.length > max && /* @__PURE__ */ jsx5(Avatar, { name: `+${items.length - max}` })
1487
+ ] });
1488
+ }
1489
+ function Progress({ value, label }) {
1490
+ const n = Math.min(100, Math.max(0, Number.isFinite(value) ? value : 0));
1491
+ return /* @__PURE__ */ jsx5(
1492
+ "div",
1493
+ {
1494
+ className: "mt-progress",
1495
+ role: "progressbar",
1496
+ "aria-label": label || "Progress",
1497
+ "aria-valuemin": 0,
1498
+ "aria-valuemax": 100,
1499
+ "aria-valuenow": n,
1500
+ children: /* @__PURE__ */ jsx5("span", { style: { width: `${n}%` } })
1501
+ }
1502
+ );
1503
+ }
1504
+ var Text = ({
1505
+ muted,
1506
+ className,
1507
+ ...p
1508
+ }) => /* @__PURE__ */ jsx5("span", { ...p, className: cn("mt-text", muted && "mt-muted", className) });
1509
+ var Divider = () => /* @__PURE__ */ jsx5("hr", { className: "mt-divider" });
1510
+ var List = ({
1511
+ className,
1512
+ ...p
1513
+ }) => /* @__PURE__ */ jsx5("ul", { ...p, className: cn("mt-list", className) });
1514
+ function ListItem({
1515
+ children,
1516
+ icon,
1517
+ description,
1518
+ actions,
1519
+ ...p
1520
+ }) {
1521
+ return /* @__PURE__ */ jsxs5("li", { ...p, className: cn("mt-list-item", p.className), children: [
1522
+ icon,
1523
+ /* @__PURE__ */ jsxs5("div", { className: "mt-list-content", children: [
1524
+ /* @__PURE__ */ jsx5("div", { children }),
1525
+ description && /* @__PURE__ */ jsx5("small", { children: description })
1526
+ ] }),
1527
+ actions
1528
+ ] });
1529
+ }
1530
+ function DocumentList({ items }) {
1531
+ return /* @__PURE__ */ jsx5(List, { children: items.map((x) => /* @__PURE__ */ jsx5(
1532
+ ListItem,
1533
+ {
1534
+ icon: x.icon || /* @__PURE__ */ jsx5(FileText, { size: 16 }),
1535
+ description: x.description,
1536
+ actions: /* @__PURE__ */ jsx5("small", { children: x.updatedAt }),
1537
+ children: /* @__PURE__ */ jsx5("button", { className: "mt-link", type: "button", onClick: x.onClick, children: x.title })
1538
+ },
1539
+ x.id
1540
+ )) });
1541
+ }
1542
+ function DocumentCard({
1543
+ title,
1544
+ description,
1545
+ icon,
1546
+ updatedAt,
1547
+ onClick
1548
+ }) {
1549
+ return /* @__PURE__ */ jsxs5(Card, { children: [
1550
+ /* @__PURE__ */ jsx5("div", { className: "mt-doc-icon", children: icon || /* @__PURE__ */ jsx5(FileText, { size: 20 }) }),
1551
+ /* @__PURE__ */ jsx5("button", { type: "button", className: "mt-link", onClick, children: title }),
1552
+ /* @__PURE__ */ jsx5("p", { className: "mt-muted", children: description }),
1553
+ /* @__PURE__ */ jsx5("small", { children: updatedAt })
1554
+ ] });
1555
+ }
1556
+ var PropertyList = ({ children }) => /* @__PURE__ */ jsx5("dl", { className: "mt-properties", children });
1557
+ var PropertyItem = ({
1558
+ label,
1559
+ children
1560
+ }) => /* @__PURE__ */ jsxs5("div", { children: [
1561
+ /* @__PURE__ */ jsx5("dt", { children: label }),
1562
+ /* @__PURE__ */ jsx5("dd", { children })
1563
+ ] });
1564
+ function Alert({
1565
+ tone = "info",
1566
+ title,
1567
+ children,
1568
+ onClose
1569
+ }) {
1570
+ const Icon = {
1571
+ info: Info2,
1572
+ success: CheckCircle,
1573
+ warning: TriangleAlert,
1574
+ error: AlertCircle
1575
+ }[tone];
1576
+ return /* @__PURE__ */ jsxs5(
1577
+ "div",
1578
+ {
1579
+ role: tone === "error" ? "alert" : "status",
1580
+ className: cn("mt-alert", `mt-alert-${tone}`),
1581
+ children: [
1582
+ /* @__PURE__ */ jsx5(Icon, { size: 16 }),
1583
+ /* @__PURE__ */ jsxs5("div", { children: [
1584
+ title && /* @__PURE__ */ jsx5("strong", { children: title }),
1585
+ children && /* @__PURE__ */ jsx5("div", { children })
1586
+ ] }),
1587
+ onClose && /* @__PURE__ */ jsx5(IconButton, { "aria-label": "Close", variant: "ghost", onClick: onClose, children: /* @__PURE__ */ jsx5(X2, { size: 14 }) })
1588
+ ]
1589
+ }
1590
+ );
1591
+ }
1592
+ function Empty({
1593
+ title,
1594
+ description,
1595
+ action
1596
+ }) {
1597
+ const { locale } = useMtone();
1598
+ return /* @__PURE__ */ jsxs5("div", { className: "mt-empty", children: [
1599
+ /* @__PURE__ */ jsx5(Inbox, { size: 28 }),
1600
+ /* @__PURE__ */ jsx5("strong", { children: title || (locale === "zh" ? "\u6682\u65E0\u5185\u5BB9" : "No content") }),
1601
+ description && /* @__PURE__ */ jsx5("span", { children: description }),
1602
+ action
1603
+ ] });
1604
+ }
1605
+ var Skeleton = ({
1606
+ className,
1607
+ ...p
1608
+ }) => /* @__PURE__ */ jsx5("div", { "aria-hidden": "true", ...p, className: cn("mt-skeleton", className) });
1609
+ function Spinner({ label = "Loading" }) {
1610
+ return /* @__PURE__ */ jsx5("span", { className: "mt-spinner", role: "status", "aria-label": label, children: /* @__PURE__ */ jsx5(LoaderCircle2, { size: 16, className: "mt-spin" }) });
1611
+ }
1612
+
1613
+ // src/navigation.tsx
1614
+ import * as React5 from "react";
1615
+ import {
1616
+ ChevronRight,
1617
+ X as X3,
1618
+ PanelLeftClose,
1619
+ PanelLeftOpen,
1620
+ Circle
1621
+ } from "lucide-react";
1622
+ import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
1623
+ var SidebarContext = React5.createContext(false);
1624
+ function Sidebar({
1625
+ className,
1626
+ children,
1627
+ header,
1628
+ footer,
1629
+ collapsePlacement = "header",
1630
+ collapsible = false,
1631
+ collapsed,
1632
+ defaultCollapsed = false,
1633
+ onCollapsedChange,
1634
+ collapseLabel = "\u6536\u8D77\u4FA7\u8FB9\u680F",
1635
+ expandLabel = "\u5C55\u5F00\u4FA7\u8FB9\u680F",
1636
+ ...p
1637
+ }) {
1638
+ const [internal, setInternal] = React5.useState(defaultCollapsed);
1639
+ const isCollapsed = collapsible && (collapsed ?? internal);
1640
+ const contentId = React5.useId();
1641
+ const toggle = collapsible && /* @__PURE__ */ jsx6(
1642
+ IconButton,
1643
+ {
1644
+ className: "mt-sidebar-toggle",
1645
+ variant: "ghost",
1646
+ "aria-label": isCollapsed ? expandLabel : collapseLabel,
1647
+ title: isCollapsed ? expandLabel : collapseLabel,
1648
+ "aria-expanded": !isCollapsed,
1649
+ "aria-controls": contentId,
1650
+ onClick: () => {
1651
+ if (collapsed === void 0) setInternal(!isCollapsed);
1652
+ onCollapsedChange?.(!isCollapsed);
1653
+ },
1654
+ children: isCollapsed ? /* @__PURE__ */ jsx6(PanelLeftOpen, { size: 16, "aria-hidden": "true" }) : /* @__PURE__ */ jsx6(PanelLeftClose, { size: 16, "aria-hidden": "true" })
1655
+ }
1656
+ );
1657
+ return /* @__PURE__ */ jsx6(SidebarContext.Provider, { value: isCollapsed, children: /* @__PURE__ */ jsxs6(
1658
+ "aside",
1659
+ {
1660
+ ...p,
1661
+ className: cn("mt-sidebar", className),
1662
+ "data-collapsed": isCollapsed,
1663
+ children: [
1664
+ header !== void 0 ? /* @__PURE__ */ jsxs6("div", { className: "mt-sidebar-heading", children: [
1665
+ /* @__PURE__ */ jsx6("div", { className: "mt-sidebar-brand", children: typeof header === "function" ? header(isCollapsed) : header }),
1666
+ collapsePlacement === "header" && toggle
1667
+ ] }) : collapsePlacement === "header" && toggle,
1668
+ collapsible || header !== void 0 ? /* @__PURE__ */ jsx6("div", { id: contentId, className: "mt-sidebar-content", children }) : children,
1669
+ (footer !== void 0 || collapsePlacement === "footer" && collapsible) && /* @__PURE__ */ jsxs6("div", { className: "mt-sidebar-footer", children: [
1670
+ footer !== void 0 && /* @__PURE__ */ jsx6("div", { className: "mt-sidebar-footer-content", children: typeof footer === "function" ? footer(isCollapsed) : footer }),
1671
+ collapsePlacement === "footer" && toggle
1672
+ ] })
1673
+ ]
1674
+ }
1675
+ ) });
1676
+ }
1677
+ var NavItem = React5.forwardRef(function NavItem2({ active, icon, children, className, ...p }, ref) {
1678
+ const collapsed = React5.useContext(SidebarContext);
1679
+ const [tipOpen, setTipOpen] = React5.useState(false);
1680
+ const label = p["aria-label"] ?? (typeof children === "string" || typeof children === "number" ? String(children) : void 0);
1681
+ const button = /* @__PURE__ */ jsxs6(
1682
+ "button",
1683
+ {
1684
+ type: "button",
1685
+ ...p,
1686
+ ref,
1687
+ "aria-current": active ? "page" : void 0,
1688
+ className: cn(
1689
+ "mt-nav-item",
1690
+ active && "mt-active",
1691
+ collapsed && "mt-nav-item-collapsed",
1692
+ className
1693
+ ),
1694
+ children: [
1695
+ icon || (collapsed ? /* @__PURE__ */ jsx6(Circle, { size: 16, "aria-hidden": "true" }) : null),
1696
+ collapsed ? /* @__PURE__ */ jsx6("span", { className: "mt-sidebar-sr-only", children }) : children
1697
+ ]
1698
+ }
1699
+ );
1700
+ return label ? /* @__PURE__ */ jsx6(
1701
+ Tooltip,
1702
+ {
1703
+ content: label,
1704
+ side: "right",
1705
+ open: collapsed && tipOpen,
1706
+ onOpenChange: (open) => setTipOpen(collapsed && open),
1707
+ children: button
1708
+ }
1709
+ ) : button;
1710
+ });
1711
+ function NavGroup({
1712
+ label,
1713
+ children
1714
+ }) {
1715
+ const collapsed = React5.useContext(SidebarContext);
1716
+ return /* @__PURE__ */ jsxs6("div", { className: cn("mt-nav-group", collapsed && "mt-nav-group-collapsed"), children: [
1717
+ label && /* @__PURE__ */ jsx6("div", { className: collapsed ? "mt-sidebar-sr-only" : "mt-nav-label", children: label }),
1718
+ children
1719
+ ] });
1720
+ }
1721
+ function Breadcrumb({
1722
+ items,
1723
+ "aria-label": label = "Breadcrumb"
1724
+ }) {
1725
+ return /* @__PURE__ */ jsx6("nav", { "aria-label": label, children: /* @__PURE__ */ jsx6("ol", { className: "mt-breadcrumb", children: items.map((x, i) => /* @__PURE__ */ jsxs6("li", { children: [
1726
+ i > 0 && /* @__PURE__ */ jsx6(ChevronRight, { size: 12 }),
1727
+ i === items.length - 1 ? /* @__PURE__ */ jsx6("span", { "aria-current": "page", children: x.label }) : /* @__PURE__ */ jsx6("a", { href: x.href, children: x.label })
1728
+ ] }, i)) }) });
1729
+ }
1730
+ function FilterChip({
1731
+ children,
1732
+ onRemove
1733
+ }) {
1734
+ const { locale } = useMtone();
1735
+ return /* @__PURE__ */ jsxs6("span", { className: "mt-filter-chip", children: [
1736
+ /* @__PURE__ */ jsx6("span", { className: "mt-filter-chip-label", children }),
1737
+ /* @__PURE__ */ jsx6(
1738
+ IconButton,
1739
+ {
1740
+ size: "sm",
1741
+ variant: "ghost",
1742
+ "aria-label": locale === "zh" ? "\u79FB\u9664\u7B5B\u9009" : "Remove filter",
1743
+ onClick: onRemove,
1744
+ children: /* @__PURE__ */ jsx6(X3, { size: 12 })
1745
+ }
1746
+ )
1747
+ ] });
1748
+ }
1749
+ var FilterBar = ({
1750
+ className,
1751
+ ...p
1752
+ }) => /* @__PURE__ */ jsx6("div", { ...p, className: cn("mt-filter-bar", className) });
1753
+
1754
+ // src/data.tsx
1755
+ import * as React10 from "react";
1756
+ import { ChevronDown as ChevronDown4, ChevronRight as ChevronRight4, Upload as UploadIcon } from "lucide-react";
1757
+
1758
+ // src/table.tsx
1759
+ import * as React9 from "react";
1760
+ import RcTableImport, {
1761
+ VirtualTable,
1762
+ EXPAND_COLUMN,
1763
+ Summary
1764
+ } from "@rc-component/table";
1765
+ import {
1766
+ ChevronDown as ChevronDown3,
1767
+ ChevronRight as ChevronRight3,
1768
+ ArrowUp,
1769
+ ArrowDown,
1770
+ ArrowUpDown
1771
+ } from "lucide-react";
1772
+
1773
+ // src/table-model.ts
1774
+ var getColumnKey = (c, index) => String(
1775
+ c.key ?? (Array.isArray(c.dataIndex) ? c.dataIndex.join(".") : c.dataIndex) ?? index
1776
+ );
1777
+ var getValue = (row, c) => {
1778
+ const path = c.dataIndex ?? c.key;
1779
+ return (Array.isArray(path) ? path : [path]).reduce(
1780
+ (v, k) => v?.[k],
1781
+ row
1782
+ );
1783
+ };
1784
+ function flattenColumns(columns) {
1785
+ return columns.flatMap(
1786
+ (c) => c.children ? flattenColumns(c.children) : [c]
1787
+ );
1788
+ }
1789
+ function processTableData(data, columns, sorts, filters, textFilters, manual, childrenName = "children") {
1790
+ if (manual) return data;
1791
+ const leaves = flattenColumns(columns);
1792
+ const indexed = leaves.map((c, i) => ({ c, key: getColumnKey(c, i) }));
1793
+ const active = sorts.map((s) => ({ ...s, c: indexed.find((x) => x.key === s.key)?.c })).filter((s) => s.c).sort(
1794
+ (a, b) => ((typeof b.c.sorter === "object" ? b.c.sorter.multiple : 0) ?? 0) - ((typeof a.c.sorter === "object" ? a.c.sorter.multiple : 0) ?? 0)
1795
+ );
1796
+ const walk = (rows) => rows.filter(
1797
+ (row) => indexed.every(({ c, key }) => {
1798
+ const text = textFilters[key];
1799
+ if (text && !String(getValue(row, c) ?? "").toLocaleLowerCase().includes(text.toLocaleLowerCase()))
1800
+ return false;
1801
+ const values = filters[key];
1802
+ return !values?.length || !c.onFilter || values.some((v) => c.onFilter(v, row));
1803
+ })
1804
+ ).map((row) => {
1805
+ const children = row?.[childrenName];
1806
+ return Array.isArray(children) ? { ...row, [childrenName]: walk(children) } : row;
1807
+ }).sort((a, b) => {
1808
+ for (const { c, order } of active) {
1809
+ const compare = typeof c.sorter === "function" ? c.sorter : typeof c.sorter === "object" ? c.sorter.compare : void 0;
1810
+ let value = 0;
1811
+ if (compare) value = compare(a, b, order);
1812
+ else if (c.sortable) {
1813
+ const x = getValue(a, c), y = getValue(b, c);
1814
+ value = typeof x === "number" && typeof y === "number" ? x - y : String(x ?? "").localeCompare(String(y ?? ""));
1815
+ }
1816
+ if (value) return order === "ascend" ? value : -value;
1817
+ }
1818
+ return 0;
1819
+ });
1820
+ return walk(data);
1821
+ }
1822
+
1823
+ // src/table-filter.tsx
1824
+ import * as React6 from "react";
1825
+ import { Popover as Popover2 } from "@base-ui/react/popover";
1826
+ import { Filter, ChevronRight as ChevronRight2 } from "lucide-react";
1827
+ import { Fragment as Fragment3, jsx as jsx7, jsxs as jsxs7 } from "react/jsx-runtime";
1828
+ var sameValues = (a, b) => a.length === b.length && a.every((value, index) => value === b[index]);
1829
+ function plainText(node) {
1830
+ if (typeof node === "string" || typeof node === "number") return String(node);
1831
+ if (Array.isArray(node)) return node.map(plainText).join("");
1832
+ if (React6.isValidElement(node))
1833
+ return plainText(node.props.children);
1834
+ return "";
1835
+ }
1836
+ function itemValues(item) {
1837
+ return [item.value, ...(item.children ?? []).flatMap(itemValues)];
1838
+ }
1839
+ function MixedCheckbox({
1840
+ mixed,
1841
+ ...props
1842
+ }) {
1843
+ const input = React6.useRef(null);
1844
+ React6.useEffect(() => {
1845
+ if (input.current) input.current.indeterminate = mixed;
1846
+ }, [mixed]);
1847
+ return /* @__PURE__ */ jsx7(
1848
+ "input",
1849
+ {
1850
+ ...props,
1851
+ ref: input,
1852
+ "aria-checked": mixed ? "mixed" : props.checked
1853
+ }
1854
+ );
1855
+ }
1856
+ function TableFilter({
1857
+ column,
1858
+ columnKey,
1859
+ value,
1860
+ onChange,
1861
+ zh,
1862
+ locale,
1863
+ getPopupContainer
1864
+ }) {
1865
+ const [internalOpen, setInternalOpen] = React6.useState(false);
1866
+ const open = column.filterDropdownProps?.open ?? internalOpen;
1867
+ const [draft, setDraftState] = React6.useState(
1868
+ value ?? []
1869
+ );
1870
+ const draftRef = React6.useRef(draft);
1871
+ const committed = React6.useRef(value ?? []);
1872
+ const previousValue = React6.useRef(value);
1873
+ const previousOpen = React6.useRef(false);
1874
+ const [search, setSearch] = React6.useState("");
1875
+ const [collapsed, setCollapsed] = React6.useState(
1876
+ /* @__PURE__ */ new Set()
1877
+ );
1878
+ const trigger = React6.useRef(null);
1879
+ const [portalContainer, setPortalContainer] = React6.useState();
1880
+ const id = React6.useId();
1881
+ const title = typeof column.title === "function" ? columnKey : plainText(column.title) || columnKey;
1882
+ const filterLabel = `${locale?.filterTitle ?? (zh ? "\u7B5B\u9009" : "Filter")} ${title}`;
1883
+ const multiple = column.filterMultiple !== false;
1884
+ const isTree = column.filterMode === "tree";
1885
+ const setDraft = React6.useCallback((keys) => {
1886
+ draftRef.current = keys;
1887
+ setDraftState(keys);
1888
+ }, []);
1889
+ React6.useEffect(() => {
1890
+ const changed = !sameValues(previousValue.current ?? [], value ?? []);
1891
+ if (changed || open && !previousOpen.current) {
1892
+ setDraft(value ?? []);
1893
+ committed.current = value ?? [];
1894
+ if (open && !previousOpen.current) setSearch("");
1895
+ }
1896
+ previousValue.current = value;
1897
+ previousOpen.current = open;
1898
+ }, [value, open, setDraft]);
1899
+ React6.useLayoutEffect(() => {
1900
+ if (trigger.current && getPopupContainer)
1901
+ setPortalContainer(getPopupContainer(trigger.current));
1902
+ else setPortalContainer(void 0);
1903
+ }, [getPopupContainer, open]);
1904
+ const commit = (keys, force = false) => {
1905
+ if (force || !sameValues(committed.current, keys)) {
1906
+ committed.current = [...keys];
1907
+ onChange(keys.length ? [...keys] : null);
1908
+ }
1909
+ };
1910
+ const changeOpen = (next, applyOnClose = true) => {
1911
+ if (!next && open && applyOnClose && column.filterOnClose !== false)
1912
+ commit(draftRef.current);
1913
+ if (next) {
1914
+ setDraft(value ?? []);
1915
+ committed.current = value ?? [];
1916
+ setSearch("");
1917
+ }
1918
+ setInternalOpen(next);
1919
+ column.filterDropdownProps?.onOpenChange?.(next);
1920
+ };
1921
+ const confirm = (options) => {
1922
+ commit(draftRef.current, true);
1923
+ if (options?.closeDropdown !== false) changeOpen(false, false);
1924
+ };
1925
+ const clearFilters = (options) => {
1926
+ const next = column.filterResetToDefaultFilteredValue ? column.defaultFilteredValue ?? [] : [];
1927
+ setDraft(next);
1928
+ if (options?.confirm !== false) commit(next, true);
1929
+ if (options?.closeDropdown) changeOpen(false, false);
1930
+ };
1931
+ const toggle = (item) => {
1932
+ if (!multiple) {
1933
+ setDraft([item.value]);
1934
+ return;
1935
+ }
1936
+ const values = isTree ? itemValues(item) : [item.value];
1937
+ const all = values.every((key) => draftRef.current.includes(key));
1938
+ const next = new Set(
1939
+ all ? draftRef.current.filter((key) => !values.includes(key)) : [...draftRef.current, ...values]
1940
+ );
1941
+ if (isTree) {
1942
+ const reconcile = (items2) => items2.forEach((node) => {
1943
+ if (!node.children?.length) return;
1944
+ reconcile(node.children);
1945
+ if (node.children.every(
1946
+ (child) => itemValues(child).every((key) => next.has(key))
1947
+ ))
1948
+ next.add(node.value);
1949
+ else next.delete(node.value);
1950
+ });
1951
+ reconcile(column.filters ?? []);
1952
+ }
1953
+ setDraft([...next]);
1954
+ };
1955
+ const matches = (item) => !search || (typeof column.filterSearch === "function" ? column.filterSearch(search, item) : plainText(item.text).toLocaleLowerCase().includes(search.toLocaleLowerCase()));
1956
+ const visibleItems = (items2) => items2.flatMap((item) => {
1957
+ const children = item.children ? visibleItems(item.children) : void 0;
1958
+ return matches(item) || children?.length ? [{ ...item, children }] : [];
1959
+ });
1960
+ const originalItems = React6.useMemo(() => {
1961
+ const map = /* @__PURE__ */ new Map();
1962
+ const visit = (items2) => items2.forEach((item) => {
1963
+ map.set(item.value, item);
1964
+ if (item.children) visit(item.children);
1965
+ });
1966
+ visit(column.filters ?? []);
1967
+ return map;
1968
+ }, [column.filters]);
1969
+ const items = visibleItems(column.filters ?? []);
1970
+ const renderItems = (entries, depth = 0) => entries.map((item, index) => {
1971
+ const original = originalItems.get(item.value) ?? item;
1972
+ const descendants = isTree ? itemValues(original) : [item.value];
1973
+ const checked = multiple && isTree ? descendants.every((key) => draft.includes(key)) : draft.includes(item.value);
1974
+ const mixed = multiple && isTree && !checked && descendants.some((key) => draft.includes(key));
1975
+ const expanded = !!search || !collapsed.has(item.value);
1976
+ const children = !!item.children?.length;
1977
+ const label = plainText(item.text) || String(item.value);
1978
+ return /* @__PURE__ */ jsxs7(
1979
+ "li",
1980
+ {
1981
+ className: "mt-table-filter-item",
1982
+ role: isTree ? "treeitem" : void 0,
1983
+ "aria-expanded": isTree && children ? expanded : void 0,
1984
+ children: [
1985
+ /* @__PURE__ */ jsxs7(
1986
+ "div",
1987
+ {
1988
+ className: "mt-table-filter-option",
1989
+ style: { paddingInlineStart: depth * 14 },
1990
+ children: [
1991
+ isTree && children && /* @__PURE__ */ jsx7(
1992
+ "button",
1993
+ {
1994
+ type: "button",
1995
+ className: "mt-table-filter-expand",
1996
+ "aria-label": `${expanded ? zh ? "\u6536\u8D77" : "Collapse" : zh ? "\u5C55\u5F00" : "Expand"} ${label}`,
1997
+ onClick: () => setCollapsed((previous) => {
1998
+ const next = new Set(previous);
1999
+ next.has(item.value) ? next.delete(item.value) : next.add(item.value);
2000
+ return next;
2001
+ }),
2002
+ children: /* @__PURE__ */ jsx7(
2003
+ ChevronRight2,
2004
+ {
2005
+ size: 12,
2006
+ "aria-hidden": "true",
2007
+ style: { transform: expanded ? "rotate(90deg)" : void 0 }
2008
+ }
2009
+ )
2010
+ }
2011
+ ),
2012
+ /* @__PURE__ */ jsxs7("label", { className: "mt-table-filter-label", children: [
2013
+ /* @__PURE__ */ jsx7(
2014
+ MixedCheckbox,
2015
+ {
2016
+ type: multiple ? "checkbox" : "radio",
2017
+ name: multiple ? void 0 : id,
2018
+ checked,
2019
+ mixed,
2020
+ "aria-label": label,
2021
+ onChange: () => toggle(original)
2022
+ }
2023
+ ),
2024
+ /* @__PURE__ */ jsx7("span", { children: item.text })
2025
+ ] })
2026
+ ]
2027
+ }
2028
+ ),
2029
+ children && expanded && /* @__PURE__ */ jsx7(
2030
+ "ul",
2031
+ {
2032
+ className: "mt-table-filter-items",
2033
+ role: isTree ? "group" : void 0,
2034
+ children: renderItems(item.children, depth + 1)
2035
+ }
2036
+ )
2037
+ ]
2038
+ },
2039
+ `${typeof item.value}:${String(item.value)}:${index}`
2040
+ );
2041
+ });
2042
+ const active = column.filtered ?? !!value?.length;
2043
+ const icon = typeof column.filterIcon === "function" ? column.filterIcon(active) : column.filterIcon ?? /* @__PURE__ */ jsx7(Filter, { size: 13, strokeWidth: 1.5, "aria-hidden": "true" });
2044
+ const customProps = {
2045
+ prefixCls: "mt-table-filter",
2046
+ selectedKeys: draft,
2047
+ setSelectedKeys: setDraft,
2048
+ confirm,
2049
+ clearFilters,
2050
+ close: () => changeOpen(false, false),
2051
+ filters: column.filters,
2052
+ visible: open
2053
+ };
2054
+ return /* @__PURE__ */ jsxs7(Popover2.Root, { open, onOpenChange: (next) => changeOpen(next), children: [
2055
+ /* @__PURE__ */ jsx7(
2056
+ Popover2.Trigger,
2057
+ {
2058
+ ref: trigger,
2059
+ type: "button",
2060
+ className: cn(
2061
+ "mt-table-filter-trigger",
2062
+ active && "mt-table-filter-active"
2063
+ ),
2064
+ "aria-label": filterLabel,
2065
+ onClick: (event) => event.stopPropagation(),
2066
+ children: icon
2067
+ }
2068
+ ),
2069
+ /* @__PURE__ */ jsx7(Popover2.Portal, { container: portalContainer, children: /* @__PURE__ */ jsx7(MtoneScope, { children: /* @__PURE__ */ jsx7(
2070
+ Popover2.Positioner,
2071
+ {
2072
+ side: "bottom",
2073
+ align: "end",
2074
+ sideOffset: 4,
2075
+ className: "mt-positioner",
2076
+ children: /* @__PURE__ */ jsx7(
2077
+ Popover2.Popup,
2078
+ {
2079
+ className: cn(
2080
+ "mt-popup",
2081
+ "mt-table-filter-popup",
2082
+ column.filterDropdownProps?.className
2083
+ ),
2084
+ style: column.filterDropdownProps?.style,
2085
+ "aria-label": filterLabel,
2086
+ onClick: (event) => event.stopPropagation(),
2087
+ children: column.filterDropdown !== void 0 ? typeof column.filterDropdown === "function" ? column.filterDropdown(customProps) : column.filterDropdown : /* @__PURE__ */ jsxs7(Fragment3, { children: [
2088
+ column.filterSearch && /* @__PURE__ */ jsx7(
2089
+ "input",
2090
+ {
2091
+ type: "search",
2092
+ className: "mt-input mt-table-filter-search",
2093
+ "aria-label": locale?.filterSearchPlaceholder ?? (zh ? "\u641C\u7D22\u7B5B\u9009\u9879" : "Search filters"),
2094
+ placeholder: locale?.filterSearchPlaceholder ?? (zh ? "\u641C\u7D22\u7B5B\u9009\u9879" : "Search filters"),
2095
+ value: search,
2096
+ onChange: (event) => setSearch(event.target.value)
2097
+ }
2098
+ ),
2099
+ /* @__PURE__ */ jsx7(
2100
+ "ul",
2101
+ {
2102
+ className: "mt-table-filter-items",
2103
+ role: isTree ? "tree" : void 0,
2104
+ "aria-label": isTree ? filterLabel : void 0,
2105
+ children: renderItems(items)
2106
+ }
2107
+ ),
2108
+ !items.length && /* @__PURE__ */ jsx7("div", { className: "mt-table-filter-no-results", children: zh ? "\u65E0\u5339\u914D\u9879" : "No matches" }),
2109
+ /* @__PURE__ */ jsxs7("div", { className: "mt-table-filter-actions", children: [
2110
+ /* @__PURE__ */ jsx7(Button, { variant: "ghost", onClick: () => clearFilters(), children: locale?.filterReset ?? (zh ? "\u91CD\u7F6E" : "Reset") }),
2111
+ /* @__PURE__ */ jsx7(Button, { variant: "soft", onClick: () => confirm(), children: locale?.filterConfirm ?? (zh ? "\u786E\u5B9A" : "OK") })
2112
+ ] })
2113
+ ] })
2114
+ }
2115
+ )
2116
+ }
2117
+ ) }) })
2118
+ ] });
2119
+ }
2120
+
2121
+ // src/table-selection.tsx
2122
+ import * as React7 from "react";
2123
+ import { ChevronDown as ChevronDown2 } from "lucide-react";
2124
+ import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
2125
+ function useTableSelection({
2126
+ data,
2127
+ pageData,
2128
+ getRowKey,
2129
+ childrenColumnName,
2130
+ rowSelection,
2131
+ selectedKeys,
2132
+ selectable,
2133
+ onSelectionChange,
2134
+ zh,
2135
+ locale = {}
2136
+ }) {
2137
+ const config = rowSelection ?? {};
2138
+ const enabled = !!rowSelection || !!selectable;
2139
+ const [internalKeys, setInternalKeys] = React7.useState(
2140
+ () => config.defaultSelectedRowKeys ?? []
2141
+ );
2142
+ const radioName = React7.useId();
2143
+ const lastSelectedKey = React7.useRef(void 0);
2144
+ const recordCache = React7.useRef(/* @__PURE__ */ new Map());
2145
+ const map = /* @__PURE__ */ new Map();
2146
+ const flatten = (rows, parent) => rows.map((row) => {
2147
+ const key = getRowKey(row);
2148
+ const node = {
2149
+ key,
2150
+ row,
2151
+ parent,
2152
+ children: [],
2153
+ disabled: !!config.getCheckboxProps?.(row).disabled
2154
+ };
2155
+ map.set(key, node);
2156
+ const children = row[childrenColumnName];
2157
+ node.children = Array.isArray(children) ? flatten(children, node) : [];
2158
+ return node;
2159
+ });
2160
+ const roots = flatten(data);
2161
+ const pageKeys = [];
2162
+ const visitPage = (rows) => rows.forEach((row) => {
2163
+ pageKeys.push(getRowKey(row));
2164
+ const children = row[childrenColumnName];
2165
+ if (Array.isArray(children)) visitPage(children);
2166
+ });
2167
+ visitPage(pageData);
2168
+ const uniquePageKeys = [...new Set(pageKeys)];
2169
+ const availableKeys = uniquePageKeys.filter(
2170
+ (key) => !map.get(key)?.disabled && map.has(key)
2171
+ );
2172
+ const preserve = config.preserveSelectedRowKeys ?? !rowSelection;
2173
+ const inputKeys = config.selectedRowKeys ?? selectedKeys ?? internalKeys;
2174
+ const validKeys = inputKeys.filter((key) => preserve || map.has(key));
2175
+ const inputSet = new Set(
2176
+ config.type === "radio" ? validKeys.slice(0, 1) : validKeys
2177
+ );
2178
+ React7.useEffect(() => {
2179
+ if ((!preserve || config.type === "radio") && config.selectedRowKeys === void 0 && selectedKeys === void 0 && inputSet.size !== inputKeys.length) {
2180
+ setInternalKeys([...inputSet]);
2181
+ }
2182
+ });
2183
+ const associated = config.checkStrictly === false && config.type !== "radio";
2184
+ const descendants = (node, fn) => {
2185
+ if (node.disabled) return;
2186
+ fn(node);
2187
+ node.children.forEach((child) => descendants(child, fn));
2188
+ };
2189
+ const conduct = (source) => {
2190
+ const checked2 = new Set(source);
2191
+ const half2 = /* @__PURE__ */ new Set();
2192
+ if (!associated) return { checked: checked2, half: half2 };
2193
+ [...checked2].forEach((key) => {
2194
+ const node = map.get(key);
2195
+ if (node) descendants(node, (item) => checked2.add(item.key));
2196
+ });
2197
+ const derive = (node) => {
2198
+ node.children.forEach(derive);
2199
+ if (node.disabled) return;
2200
+ const children = node.children.filter((child) => !child.disabled);
2201
+ if (!children.length) return;
2202
+ if (children.every((child) => checked2.has(child.key)))
2203
+ checked2.add(node.key);
2204
+ else {
2205
+ checked2.delete(node.key);
2206
+ if (children.some(
2207
+ (child) => checked2.has(child.key) || half2.has(child.key)
2208
+ ))
2209
+ half2.add(node.key);
2210
+ }
2211
+ };
2212
+ roots.forEach(derive);
2213
+ return { checked: checked2, half: half2 };
2214
+ };
2215
+ const { checked, half } = conduct(inputSet);
2216
+ const effectiveKeys = [...checked];
2217
+ React7.useEffect(() => {
2218
+ const next = /* @__PURE__ */ new Map();
2219
+ effectiveKeys.forEach((key) => {
2220
+ const row = map.get(key)?.row ?? recordCache.current.get(key);
2221
+ if (row !== void 0) next.set(key, row);
2222
+ });
2223
+ recordCache.current = next;
2224
+ });
2225
+ const records = (keys) => keys.map((key) => map.get(key)?.row ?? recordCache.current.get(key)).filter((row) => row !== void 0);
2226
+ const apply = (next, type) => {
2227
+ const result = [...conduct(next).checked].filter(
2228
+ (key) => preserve || map.has(key)
2229
+ );
2230
+ if (config.selectedRowKeys === void 0 && selectedKeys === void 0)
2231
+ setInternalKeys(result);
2232
+ config.onChange?.(result, records(result), { type });
2233
+ onSelectionChange?.(result);
2234
+ return result;
2235
+ };
2236
+ const changeNodes = (base, keys, value) => {
2237
+ const next = new Set(base);
2238
+ keys.forEach((key) => {
2239
+ const node = map.get(key);
2240
+ if (!node || node.disabled) return;
2241
+ const change = (item) => {
2242
+ if (value) next.add(item.key);
2243
+ else next.delete(item.key);
2244
+ };
2245
+ if (associated) {
2246
+ descendants(node, change);
2247
+ if (!value) {
2248
+ let parent = node.parent;
2249
+ while (parent && !parent.disabled) {
2250
+ next.delete(parent.key);
2251
+ parent = parent.parent;
2252
+ }
2253
+ }
2254
+ } else change(node);
2255
+ });
2256
+ return next;
2257
+ };
2258
+ const onRowChange = (row, event) => {
2259
+ const key = getRowKey(row), node = map.get(key);
2260
+ if (!node || node.disabled) return;
2261
+ const selected = event.target.checked;
2262
+ if (config.type === "radio") {
2263
+ const result2 = apply(/* @__PURE__ */ new Set([key]), "single");
2264
+ config.onSelect?.(row, true, records(result2), event.nativeEvent);
2265
+ lastSelectedKey.current = key;
2266
+ return;
2267
+ }
2268
+ const start = lastSelectedKey.current === void 0 ? -1 : uniquePageKeys.indexOf(lastSelectedKey.current);
2269
+ const end = uniquePageKeys.indexOf(key);
2270
+ const range = event.nativeEvent.shiftKey && start !== -1 && end !== -1;
2271
+ const changedKeys = range ? uniquePageKeys.slice(Math.min(start, end), Math.max(start, end) + 1).filter((k) => !map.get(k)?.disabled) : [key];
2272
+ const next = changeNodes(checked, changedKeys, selected);
2273
+ const result = apply(next, range ? "multiple" : "single");
2274
+ if (range)
2275
+ config.onSelectMultiple?.(
2276
+ selected,
2277
+ records(result),
2278
+ records(changedKeys.filter((k) => checked.has(k) !== selected))
2279
+ );
2280
+ else config.onSelect?.(row, selected, records(result), event.nativeEvent);
2281
+ lastSelectedKey.current = key;
2282
+ };
2283
+ const pageAll = availableKeys.length > 0 && availableKeys.every((key) => checked.has(key));
2284
+ const pageSome = !pageAll && availableKeys.some((key) => checked.has(key) || half.has(key));
2285
+ const selectPage = () => {
2286
+ const selected = !pageAll;
2287
+ const result = apply(changeNodes(checked, availableKeys, selected), "all");
2288
+ config.onSelectAll?.(
2289
+ selected,
2290
+ records(result),
2291
+ records(availableKeys.filter((key) => checked.has(key) !== selected))
2292
+ );
2293
+ };
2294
+ const executeSelection = (selection) => {
2295
+ if (selection === "all") {
2296
+ apply(
2297
+ changeNodes(
2298
+ checked,
2299
+ [...map.keys()].filter((k) => !map.get(k)?.disabled),
2300
+ true
2301
+ ),
2302
+ "all"
2303
+ );
2304
+ } else if (selection === "none") {
2305
+ const next = new Set([...checked].filter((k) => map.get(k)?.disabled));
2306
+ apply(next, "none");
2307
+ config.onSelectNone?.();
2308
+ } else {
2309
+ let next = new Set(checked);
2310
+ const add = availableKeys.filter((key) => !checked.has(key));
2311
+ const remove = availableKeys.filter((key) => checked.has(key));
2312
+ next = changeNodes(next, remove, false);
2313
+ next = changeNodes(next, add, true);
2314
+ const result = apply(next, "invert");
2315
+ config.onSelectInvert?.(result);
2316
+ }
2317
+ };
2318
+ if (!enabled) return { column: null, selectedKeys: effectiveKeys };
2319
+ const headerProps = config.getTitleCheckboxProps?.() ?? {};
2320
+ const checkbox = config.type === "radio" || config.hideSelectAll ? null : /* @__PURE__ */ jsx8(
2321
+ "input",
2322
+ {
2323
+ ...headerProps,
2324
+ type: "checkbox",
2325
+ "aria-label": headerProps["aria-label"] ?? locale.selectionAll ?? (zh ? "\u9009\u62E9\u6240\u6709\u884C" : "Select all rows"),
2326
+ checked: pageAll,
2327
+ ref: (input) => {
2328
+ if (input) input.indeterminate = pageSome;
2329
+ },
2330
+ disabled: headerProps.disabled || !availableKeys.length,
2331
+ onClick: (event) => {
2332
+ event.stopPropagation();
2333
+ headerProps.onClick?.(event);
2334
+ },
2335
+ onChange: (event) => {
2336
+ headerProps.onChange?.(event);
2337
+ if (!event.defaultPrevented) selectPage();
2338
+ }
2339
+ }
2340
+ );
2341
+ const commands = config.selections === true ? ["all", "invert", "none"] : config.selections || [];
2342
+ const labels = {
2343
+ all: locale.selectAll ?? (zh ? "\u9009\u62E9\u5168\u90E8" : "Select all"),
2344
+ invert: locale.selectInvert ?? (zh ? "\u53CD\u9009\u5F53\u524D\u9875" : "Invert page selection"),
2345
+ none: locale.selectNone ?? (zh ? "\u6E05\u7A7A\u9009\u62E9" : "Select none")
2346
+ };
2347
+ const hasActions = config.type !== "radio" && !config.hideSelectAll && commands.length > 0;
2348
+ const controlsClass = "mt-table-selection-controls" + (hasActions ? " mt-table-selection-controls-with-actions" : "");
2349
+ const title = /* @__PURE__ */ jsxs8("span", { className: controlsClass, children: [
2350
+ checkbox,
2351
+ hasActions && /* @__PURE__ */ jsx8(
2352
+ DropdownMenu,
2353
+ {
2354
+ trigger: /* @__PURE__ */ jsx8(
2355
+ "button",
2356
+ {
2357
+ type: "button",
2358
+ className: "mt-table-selection-actions",
2359
+ "aria-label": locale.selectionActions ?? (zh ? "\u9009\u62E9\u64CD\u4F5C" : "Selection actions"),
2360
+ onClick: (event) => event.stopPropagation(),
2361
+ children: /* @__PURE__ */ jsx8(ChevronDown2, { size: 12, "aria-hidden": "true" })
2362
+ }
2363
+ ),
2364
+ items: commands.map((command, index) => ({
2365
+ key: String(index),
2366
+ label: typeof command === "string" ? labels[command] : command.text,
2367
+ onSelect: () => {
2368
+ if (typeof command === "string") executeSelection(command);
2369
+ else command.onSelect(availableKeys);
2370
+ }
2371
+ }))
2372
+ }
2373
+ )
2374
+ ] });
2375
+ return {
2376
+ selectedKeys: effectiveKeys,
2377
+ column: {
2378
+ key: "__mtone_selection__",
2379
+ title: typeof config.columnTitle === "function" ? config.columnTitle(title) : config.columnTitle ?? title,
2380
+ width: config.columnWidth ?? (hasActions ? 64 : 40),
2381
+ fixed: config.fixed,
2382
+ align: config.align ?? "center",
2383
+ className: "mt-table-selection-column",
2384
+ onCell: config.onCell,
2385
+ render: (_value, row, index) => {
2386
+ const key = getRowKey(row), props = config.getCheckboxProps?.(row) ?? {};
2387
+ const selected = checked.has(key);
2388
+ const control = /* @__PURE__ */ jsx8(
2389
+ "input",
2390
+ {
2391
+ ...props,
2392
+ type: config.type ?? "checkbox",
2393
+ name: config.type === "radio" ? props.name ?? radioName : props.name,
2394
+ "aria-label": props["aria-label"] ?? (typeof locale.selectRow === "function" ? locale.selectRow(key) : `${locale.selectRow ?? (zh ? "\u9009\u62E9\u884C" : "Select row")} ${String(key)}`),
2395
+ checked: selected,
2396
+ ref: (input) => {
2397
+ if (input) input.indeterminate = half.has(key);
2398
+ },
2399
+ onClick: (event) => {
2400
+ event.stopPropagation();
2401
+ props.onClick?.(event);
2402
+ },
2403
+ onChange: (event) => {
2404
+ props.onChange?.(event);
2405
+ if (!event.defaultPrevented) onRowChange(row, event);
2406
+ }
2407
+ }
2408
+ );
2409
+ return /* @__PURE__ */ jsx8("span", { className: controlsClass, children: config.renderCell ? config.renderCell(selected, row, index, control) : control });
2410
+ }
2411
+ }
2412
+ };
2413
+ }
2414
+
2415
+ // src/table-pagination.tsx
2416
+ import * as React8 from "react";
2417
+ import { jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
2418
+ function TablePaginationBar({
2419
+ config,
2420
+ total,
2421
+ current,
2422
+ pageSize,
2423
+ onChange,
2424
+ zh,
2425
+ placement,
2426
+ className,
2427
+ style
2428
+ }) {
2429
+ const count = Math.max(1, Math.ceil(total / pageSize));
2430
+ const [jump, setJump] = React8.useState("");
2431
+ if (config.hideOnSinglePage && count <= 1) return null;
2432
+ const change = (p, size = pageSize) => {
2433
+ if (!config.disabled)
2434
+ onChange(
2435
+ Math.min(Math.max(1, p), Math.max(1, Math.ceil(total / size))),
2436
+ size
2437
+ );
2438
+ };
2439
+ const pages = Array.from(
2440
+ /* @__PURE__ */ new Set([
2441
+ 1,
2442
+ ...Array.from(
2443
+ { length: count <= 7 ? count : 3 },
2444
+ (_, i) => count <= 7 ? i + 1 : current + i - 1
2445
+ ).filter((p) => p > 0 && p <= count),
2446
+ count
2447
+ ])
2448
+ ).sort((a, b) => a - b);
2449
+ const render = (page, type, node) => config.itemRender ? config.itemRender(page, type, node) : node;
2450
+ return /* @__PURE__ */ jsxs9(
2451
+ "nav",
2452
+ {
2453
+ "aria-label": zh ? "\u5206\u9875" : "Pagination",
2454
+ className: cn(
2455
+ "mt-pagination",
2456
+ "mt-table-pagination",
2457
+ placement.endsWith("Center") && "mt-pagination-center",
2458
+ (placement.endsWith("Start") || placement.endsWith("Left")) && "mt-pagination-start",
2459
+ config.className,
2460
+ className
2461
+ ),
2462
+ style: { ...config.style, ...style },
2463
+ children: [
2464
+ /* @__PURE__ */ jsx9("span", { className: "mt-pagination-total", children: config.showTotal ? config.showTotal(
2465
+ total,
2466
+ total ? [
2467
+ Math.min((current - 1) * pageSize + 1, total),
2468
+ Math.min(current * pageSize, total)
2469
+ ] : [0, 0]
2470
+ ) : zh ? `\u5171 ${total} \u6761` : `${total} items` }),
2471
+ /* @__PURE__ */ jsx9(
2472
+ Button,
2473
+ {
2474
+ "aria-label": zh ? "\u4E0A\u4E00\u9875" : "Previous page",
2475
+ disabled: config.disabled || current === 1,
2476
+ onClick: () => change(current - 1),
2477
+ children: render(current - 1, "prev", /* @__PURE__ */ jsx9("span", { children: "\u2039" }))
2478
+ }
2479
+ ),
2480
+ config.simple ? /* @__PURE__ */ jsxs9("span", { children: [
2481
+ current,
2482
+ " / ",
2483
+ count
2484
+ ] }) : /* @__PURE__ */ jsx9("span", { className: "mt-pagination-pages", children: pages.map((p, i) => /* @__PURE__ */ jsxs9(React8.Fragment, { children: [
2485
+ i > 0 && p - pages[i - 1] > 1 && /* @__PURE__ */ jsx9("span", { "aria-hidden": "true", children: "\u2026" }),
2486
+ /* @__PURE__ */ jsx9(
2487
+ Button,
2488
+ {
2489
+ disabled: config.disabled,
2490
+ "aria-label": `${zh ? "\u7B2C" : "Page "}${p}${zh ? "\u9875" : ""}`,
2491
+ "aria-current": p === current ? "page" : void 0,
2492
+ variant: p === current ? "soft" : "ghost",
2493
+ onClick: () => change(p),
2494
+ children: render(p, "page", /* @__PURE__ */ jsx9("span", { children: p }))
2495
+ }
2496
+ )
2497
+ ] }, p)) }),
2498
+ /* @__PURE__ */ jsx9(
2499
+ Button,
2500
+ {
2501
+ "aria-label": zh ? "\u4E0B\u4E00\u9875" : "Next page",
2502
+ disabled: config.disabled || current === count,
2503
+ onClick: () => change(current + 1),
2504
+ children: render(current + 1, "next", /* @__PURE__ */ jsx9("span", { children: "\u203A" }))
2505
+ }
2506
+ ),
2507
+ config.showSizeChanger && /* @__PURE__ */ jsx9(
2508
+ Select,
2509
+ {
2510
+ className: "mt-table-page-size",
2511
+ label: zh ? "\u6BCF\u9875\u6761\u6570" : "Page size",
2512
+ disabled: config.disabled,
2513
+ value: String(pageSize),
2514
+ onValueChange: (value) => {
2515
+ if (value !== null) change(1, Number(value));
2516
+ },
2517
+ options: [
2518
+ .../* @__PURE__ */ new Set([
2519
+ ...(config.pageSizeOptions ?? [10, 20, 50, 100]).map(Number),
2520
+ pageSize
2521
+ ])
2522
+ ].filter((s) => s > 0).sort((a, b) => a - b).map((s) => ({
2523
+ value: String(s),
2524
+ label: `${s}${zh ? " \u6761/\u9875" : " / page"}`
2525
+ }))
2526
+ }
2527
+ ),
2528
+ config.showQuickJumper && /* @__PURE__ */ jsxs9(
2529
+ "form",
2530
+ {
2531
+ className: "mt-table-quick-jump",
2532
+ onSubmit: (e) => {
2533
+ e.preventDefault();
2534
+ const value = Number(jump);
2535
+ if (Number.isFinite(value) && value > 0) change(Math.floor(value));
2536
+ setJump("");
2537
+ },
2538
+ children: [
2539
+ /* @__PURE__ */ jsxs9("label", { children: [
2540
+ zh ? "\u8DF3\u81F3" : "Go to",
2541
+ " ",
2542
+ /* @__PURE__ */ jsx9(
2543
+ "input",
2544
+ {
2545
+ className: "mt-input",
2546
+ inputMode: "numeric",
2547
+ "aria-label": zh ? "\u8DF3\u8F6C\u9875\u7801" : "Go to page",
2548
+ disabled: config.disabled,
2549
+ value: jump,
2550
+ onChange: (e) => setJump(e.target.value)
2551
+ }
2552
+ )
2553
+ ] }),
2554
+ /* @__PURE__ */ jsx9(Button, { type: "submit", disabled: config.disabled, children: zh ? "\u8DF3\u8F6C" : "Go" })
2555
+ ]
2556
+ }
2557
+ )
2558
+ ]
2559
+ }
2560
+ );
2561
+ }
2562
+
2563
+ // src/table.tsx
2564
+ import { Fragment as Fragment6, jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
2565
+ var SELECTION_COLUMN = Object.freeze({ key: "__mt_selection_column" });
2566
+ function Column(_props) {
2567
+ return null;
2568
+ }
2569
+ function ColumnGroup(_props) {
2570
+ return null;
2571
+ }
2572
+ function jsxColumns(children) {
2573
+ const result = [];
2574
+ React9.Children.forEach(children, (child) => {
2575
+ if (!React9.isValidElement(child)) return;
2576
+ const p = child.props;
2577
+ if (child.type === React9.Fragment) {
2578
+ result.push(...jsxColumns(p.children));
2579
+ return;
2580
+ }
2581
+ result.push({
2582
+ ...p,
2583
+ key: child.key ?? p.key,
2584
+ ...child.type === ColumnGroup ? { children: jsxColumns(p.children) } : {}
2585
+ });
2586
+ });
2587
+ return result;
2588
+ }
2589
+ var RcTable = RcTableImport.default ?? RcTableImport;
2590
+ var Engine = RcTable;
2591
+ var VirtualEngine = VirtualTable;
2592
+ var breakpoints = { xs: 0, sm: 576, md: 768, lg: 992, xl: 1200, xxl: 1600 };
2593
+ function useResponsive() {
2594
+ const [width, set] = React9.useState(null);
2595
+ React9.useEffect(() => {
2596
+ const update = () => set(window.innerWidth);
2597
+ update();
2598
+ window.addEventListener("resize", update);
2599
+ return () => window.removeEventListener("resize", update);
2600
+ }, []);
2601
+ return width;
2602
+ }
2603
+ function TableInner(props, forwardedRef) {
2604
+ const {
2605
+ dataSource,
2606
+ data,
2607
+ columns: columnsProp,
2608
+ children,
2609
+ column: shared,
2610
+ manual = false,
2611
+ sort: legacySort,
2612
+ filters: legacyFilters,
2613
+ onChange,
2614
+ onTableChange,
2615
+ pagination = false,
2616
+ rowSelection,
2617
+ selectable,
2618
+ selectedKeys,
2619
+ onSelectionChange,
2620
+ loading = false,
2621
+ empty: empty2,
2622
+ locale = {},
2623
+ size = "middle",
2624
+ bordered = false,
2625
+ className,
2626
+ style,
2627
+ classNames,
2628
+ styles,
2629
+ sortDirections = ["ascend", "descend"],
2630
+ showSorterTooltip = true,
2631
+ getPopupContainer,
2632
+ virtual,
2633
+ virtualItemHeight = 38,
2634
+ scroll,
2635
+ expandable,
2636
+ components,
2637
+ rowKey = "key",
2638
+ rowClassName,
2639
+ onRow,
2640
+ ...engineProps
2641
+ } = props;
2642
+ const zh = useMtone().locale === "zh";
2643
+ const width = useResponsive();
2644
+ const source = dataSource ?? data ?? [];
2645
+ const rawColumns = React9.useMemo(
2646
+ () => columnsProp ?? jsxColumns(children),
2647
+ [columnsProp, children]
2648
+ );
2649
+ const columns = React9.useMemo(() => {
2650
+ const walk = (cols) => cols.flatMap((c) => {
2651
+ if (c === EXPAND_COLUMN || c === SELECTION_COLUMN) return [c];
2652
+ const merged = { ...shared, ...c };
2653
+ if (width !== null && merged.responsive && !merged.responsive.some(
2654
+ (b) => b === "xs" ? width < 576 : width >= breakpoints[b]
2655
+ ))
2656
+ return [];
2657
+ if (merged.children) {
2658
+ const children2 = walk(merged.children);
2659
+ return children2.length ? [{ ...merged, children: children2 }] : [];
2660
+ }
2661
+ return [merged];
2662
+ });
2663
+ return walk(rawColumns);
2664
+ }, [rawColumns, shared, width]);
2665
+ const leaves = flattenColumns(columns);
2666
+ const indexed = leaves.map((c, i) => ({ c, key: getColumnKey(c, i) }));
2667
+ const [sortState, setSortState] = React9.useState(
2668
+ () => indexed.flatMap(
2669
+ ({ c, key }) => c.defaultSortOrder ? [{ key, order: c.defaultSortOrder }] : []
2670
+ )
2671
+ );
2672
+ const [filterState, setFilterState] = React9.useState(
2673
+ () => Object.fromEntries(
2674
+ indexed.filter((x) => x.c.defaultFilteredValue).map(({ c, key }) => [key, c.defaultFilteredValue])
2675
+ )
2676
+ );
2677
+ const [textState, setTextState] = React9.useState({});
2678
+ const [pageState, setPage] = React9.useState(
2679
+ pagination ? pagination.defaultCurrent ?? pagination.page ?? pagination.current ?? 1 : 1
2680
+ );
2681
+ const [sizeState, setSize] = React9.useState(
2682
+ pagination ? pagination.defaultPageSize ?? pagination.pageSize ?? 10 : 10
2683
+ );
2684
+ const controlledSortColumns = indexed.filter(
2685
+ ({ c }) => c.sortOrder !== void 0
2686
+ );
2687
+ const activeSorts = legacySort !== void 0 ? legacySort ? [
2688
+ {
2689
+ key: legacySort.key,
2690
+ order: legacySort.direction === "asc" ? "ascend" : "descend"
2691
+ }
2692
+ ] : [] : controlledSortColumns.length ? controlledSortColumns.flatMap(
2693
+ ({ c, key }) => c.sortOrder ? [{ key, order: c.sortOrder }] : []
2694
+ ) : sortState;
2695
+ const activeFilters = { ...filterState };
2696
+ indexed.forEach(({ c, key }) => {
2697
+ if (c.filteredValue !== void 0) activeFilters[key] = c.filteredValue;
2698
+ });
2699
+ const activeText = legacyFilters ?? textState;
2700
+ const getKey = React9.useCallback(
2701
+ (r) => typeof rowKey === "function" ? rowKey(r) : r[rowKey],
2702
+ [rowKey]
2703
+ );
2704
+ const childrenName = expandable?.childrenColumnName ?? "children";
2705
+ const processed = processTableData(
2706
+ source,
2707
+ columns,
2708
+ activeSorts,
2709
+ activeFilters,
2710
+ activeText,
2711
+ manual,
2712
+ childrenName
2713
+ );
2714
+ const pageSize = Math.max(
2715
+ 1,
2716
+ Number(pagination ? pagination.pageSize ?? sizeState : 10) || 10
2717
+ );
2718
+ const total = manual && pagination ? pagination.total ?? processed.length : processed.length;
2719
+ const requestedPage = pagination ? pagination.current ?? pagination.page ?? pageState : 1;
2720
+ const page = Math.min(
2721
+ Math.max(1, requestedPage),
2722
+ Math.max(1, Math.ceil(total / pageSize))
2723
+ );
2724
+ const pageData = pagination && !manual ? processed.slice((page - 1) * pageSize, page * pageSize) : processed;
2725
+ const tableRef = React9.useRef(null);
2726
+ React9.useImperativeHandle(
2727
+ forwardedRef,
2728
+ () => ({
2729
+ get nativeElement() {
2730
+ return tableRef.current.nativeElement;
2731
+ },
2732
+ scrollTo: (config) => tableRef.current?.scrollTo(config)
2733
+ }),
2734
+ []
2735
+ );
2736
+ const emit = (action, next = {}) => {
2737
+ const sorts = next.sorts ?? activeSorts, filters = next.filters ?? activeFilters, text = next.text ?? activeText, current = next.page ?? page, size2 = next.pageSize ?? pageSize;
2738
+ const first = sorts[0];
2739
+ const state = {
2740
+ sort: first ? {
2741
+ key: first.key,
2742
+ direction: first.order === "ascend" ? "asc" : "desc"
2743
+ } : void 0,
2744
+ filters: text,
2745
+ page: current,
2746
+ pageSize: size2
2747
+ };
2748
+ onChange?.(state);
2749
+ const result = sorts.map((s) => {
2750
+ const c = indexed.find((x) => x.key === s.key)?.c;
2751
+ return {
2752
+ column: c,
2753
+ columnKey: c?.key ?? s.key,
2754
+ field: c?.dataIndex,
2755
+ order: s.order
2756
+ };
2757
+ });
2758
+ const isMultiple = sorts.length > 1 || indexed.some(
2759
+ ({ c }) => typeof c.sorter === "object" && c.sorter.multiple !== void 0
2760
+ );
2761
+ const nextData = processTableData(
2762
+ source,
2763
+ columns,
2764
+ sorts,
2765
+ filters,
2766
+ text,
2767
+ manual,
2768
+ childrenName
2769
+ );
2770
+ onTableChange?.(
2771
+ {
2772
+ ...pagination || {},
2773
+ current,
2774
+ page: current,
2775
+ pageSize: size2,
2776
+ total: manual ? total : nextData.length
2777
+ },
2778
+ filters,
2779
+ isMultiple ? result : result[0] ?? {},
2780
+ { currentDataSource: nextData, action }
2781
+ );
2782
+ if (scroll?.scrollToFirstRowOnChange !== false)
2783
+ tableRef.current?.scrollTo({ top: 0 });
2784
+ };
2785
+ const changePage = (current, size2) => {
2786
+ setPage(current);
2787
+ setSize(size2);
2788
+ if (pagination) {
2789
+ pagination.onChange?.(current, size2);
2790
+ pagination.onPageChange?.(current);
2791
+ if (size2 !== pageSize) pagination.onShowSizeChange?.(current, size2);
2792
+ }
2793
+ emit("paginate", { page: current, pageSize: size2 });
2794
+ };
2795
+ const changeSort = (c, key) => {
2796
+ const dirs = c.sortDirections ?? sortDirections, old = activeSorts.find((s) => s.key === key)?.order;
2797
+ const index = old ? dirs.indexOf(old) : -1;
2798
+ const order = dirs[index + 1] ?? null;
2799
+ const multi = typeof c.sorter === "object" && c.sorter.multiple !== void 0;
2800
+ let sorts = multi ? activeSorts.filter(
2801
+ (s) => s.key !== key && typeof indexed.find((x) => x.key === s.key)?.c.sorter === "object"
2802
+ ) : [];
2803
+ if (order) sorts = [...sorts, { key, order }];
2804
+ setSortState(sorts);
2805
+ setPage(1);
2806
+ emit("sort", { sorts, page: 1 });
2807
+ };
2808
+ const titleProps = {
2809
+ sortColumns: activeSorts.flatMap((s) => {
2810
+ const c = indexed.find((x) => x.key === s.key)?.c;
2811
+ return c ? [{ column: c, order: s.order }] : [];
2812
+ }),
2813
+ filters: activeFilters
2814
+ };
2815
+ let leafIndex = 0;
2816
+ const decorate = (cols) => cols.flatMap((c) => {
2817
+ if (c.hidden) {
2818
+ leafIndex += c.children ? flattenColumns(c.children).length : 1;
2819
+ return [];
2820
+ }
2821
+ if (c === EXPAND_COLUMN || c === SELECTION_COLUMN) {
2822
+ leafIndex++;
2823
+ return c;
2824
+ }
2825
+ const key = getColumnKey(c, leafIndex), title = typeof c.title === "function" ? c.title(titleProps) : c.title;
2826
+ if (c.children) {
2827
+ const children2 = decorate(c.children);
2828
+ return children2.length ? { ...c, title, children: children2 } : [];
2829
+ }
2830
+ leafIndex++;
2831
+ const sort = activeSorts.find((s) => s.key === key)?.order ?? null, sortable = !!(c.sorter || c.sortable);
2832
+ const label = typeof title === "string" ? title : key;
2833
+ const tooltip = c.showSorterTooltip ?? showSorterTooltip;
2834
+ const directions = c.sortDirections ?? sortDirections;
2835
+ const nextOrder = directions[(sort ? directions.indexOf(sort) : -1) + 1] ?? null;
2836
+ const sortHint = typeof tooltip === "object" && tooltip.title !== void 0 ? tooltip.title : nextOrder === "ascend" ? locale.triggerAsc ?? (zh ? "\u70B9\u51FB\u5347\u5E8F" : "Sort ascending") : nextOrder === "descend" ? locale.triggerDesc ?? (zh ? "\u70B9\u51FB\u964D\u5E8F" : "Sort descending") : locale.cancelSort ?? (zh ? "\u53D6\u6D88\u6392\u5E8F" : "Cancel sorting");
2837
+ const icon = /* @__PURE__ */ jsx10("span", { className: "mt-table-sort-icon", children: c.sortIcon ? c.sortIcon({ sortOrder: sort }) : sort === "ascend" ? /* @__PURE__ */ jsx10(ArrowUp, { size: 13, "aria-hidden": "true" }) : sort === "descend" ? /* @__PURE__ */ jsx10(ArrowDown, { size: 13, "aria-hidden": "true" }) : /* @__PURE__ */ jsx10(ArrowUpDown, { size: 13, "aria-hidden": "true" }) });
2838
+ const iconOnly = typeof tooltip === "object" && tooltip.target === "sorter-icon";
2839
+ const sortButton = /* @__PURE__ */ jsxs10(
2840
+ "button",
2841
+ {
2842
+ type: "button",
2843
+ className: "mt-table-sort",
2844
+ onClick: () => changeSort(c, key),
2845
+ children: [
2846
+ title,
2847
+ tooltip && iconOnly ? /* @__PURE__ */ jsx10(Tooltip, { content: sortHint, children: icon }) : icon
2848
+ ]
2849
+ }
2850
+ );
2851
+ const heading = sortable ? tooltip && !iconOnly ? /* @__PURE__ */ jsx10(Tooltip, { content: sortHint, children: sortButton }) : sortButton : title;
2852
+ return {
2853
+ ...c,
2854
+ key,
2855
+ dataIndex: c.dataIndex ?? (c.key == null ? void 0 : String(c.key)),
2856
+ title: /* @__PURE__ */ jsxs10(Fragment6, { children: [
2857
+ /* @__PURE__ */ jsxs10(
2858
+ "div",
2859
+ {
2860
+ className: "mt-table-heading",
2861
+ style: {
2862
+ justifyContent: c.align === "center" ? "center" : c.align === "right" || c.align === "end" ? "flex-end" : void 0
2863
+ },
2864
+ children: [
2865
+ heading,
2866
+ (c.filters || c.filterDropdown) && /* @__PURE__ */ jsx10(
2867
+ TableFilter,
2868
+ {
2869
+ column: c,
2870
+ columnKey: key,
2871
+ value: activeFilters[key] ?? null,
2872
+ zh,
2873
+ locale,
2874
+ getPopupContainer,
2875
+ onChange: (values) => {
2876
+ const filters = { ...activeFilters, [key]: values };
2877
+ setFilterState(filters);
2878
+ setPage(1);
2879
+ emit("filter", { filters, page: 1 });
2880
+ }
2881
+ }
2882
+ )
2883
+ ]
2884
+ }
2885
+ ),
2886
+ c.filterable && /* @__PURE__ */ jsx10(
2887
+ "input",
2888
+ {
2889
+ className: "mt-input mt-table-filter",
2890
+ "aria-label": `${zh ? "\u7B5B\u9009" : "Filter"} ${label}`,
2891
+ value: activeText[key] ?? "",
2892
+ onChange: (e) => {
2893
+ const text = { ...activeText, [key]: e.target.value };
2894
+ setTextState(text);
2895
+ setPage(1);
2896
+ emit("filter", { text, page: 1 });
2897
+ }
2898
+ }
2899
+ )
2900
+ ] }),
2901
+ onHeaderCell: (col) => ({
2902
+ ...c.onHeaderCell?.(col),
2903
+ "aria-sort": sort === "ascend" ? "ascending" : sort === "descend" ? "descending" : void 0
2904
+ })
2905
+ };
2906
+ });
2907
+ const selection = useTableSelection({
2908
+ data: source,
2909
+ pageData,
2910
+ getRowKey: getKey,
2911
+ childrenColumnName: childrenName,
2912
+ rowSelection,
2913
+ selectedKeys,
2914
+ selectable,
2915
+ onSelectionChange,
2916
+ zh,
2917
+ locale
2918
+ });
2919
+ let renderedColumns = decorate(columns);
2920
+ const hasSelectionMarker = renderedColumns.includes(
2921
+ SELECTION_COLUMN
2922
+ );
2923
+ renderedColumns = renderedColumns.flatMap(
2924
+ (c) => c === SELECTION_COLUMN ? selection.column ? [selection.column] : [] : [c]
2925
+ );
2926
+ if (selection.column && !hasSelectionMarker)
2927
+ renderedColumns.unshift(selection.column);
2928
+ const treeExpandColumnIndex = flattenColumns(renderedColumns).filter((column) => column !== EXPAND_COLUMN).findIndex((column) => column !== selection.column);
2929
+ const resolvedExpandable = !expandable?.expandedRowRender ? {
2930
+ ...expandable,
2931
+ indentSize: expandable?.indentSize ?? 15,
2932
+ expandIconColumnIndex: expandable?.expandIconColumnIndex ?? treeExpandColumnIndex
2933
+ } : expandable;
2934
+ const resolvedClasses = typeof classNames === "function" ? classNames({ props }) : classNames ?? {};
2935
+ const resolvedStyles = typeof styles === "function" ? styles({ props }) : styles ?? {};
2936
+ const spinning = typeof loading === "object" ? loading.spinning !== false : loading;
2937
+ const [showLoading, setShowLoading] = React9.useState(
2938
+ spinning && !(typeof loading === "object" && loading.delay)
2939
+ );
2940
+ React9.useEffect(() => {
2941
+ if (!spinning) {
2942
+ setShowLoading(false);
2943
+ return;
2944
+ }
2945
+ const delay = typeof loading === "object" ? loading.delay ?? 0 : 0;
2946
+ if (!delay) {
2947
+ setShowLoading(true);
2948
+ return;
2949
+ }
2950
+ const timeout = setTimeout(() => setShowLoading(true), delay);
2951
+ return () => clearTimeout(timeout);
2952
+ }, [spinning, typeof loading === "object" ? loading.delay : 0]);
2953
+ const loadingContent = typeof loading === "object" ? loading.indicator ?? loading.tip : void 0;
2954
+ const rcComponents = {
2955
+ ...components,
2956
+ ExpandIcon: components?.ExpandIcon ?? ((p) => p.type === "row" && expandable?.expandIcon ? expandable.expandIcon({ prefixCls: "mt-table", expanded: p.expanded, expandable: p.expandable, record: p.record, onExpand: (_record, event) => p.onClick(event) }) : p.expandable ? /* @__PURE__ */ jsx10(
2957
+ "button",
2958
+ {
2959
+ type: "button",
2960
+ className: "mt-table-expand",
2961
+ "aria-label": p.type === "all" ? p.expanded ? zh ? "\u6536\u8D77\u6240\u6709\u884C" : "Collapse all rows" : zh ? "\u5C55\u5F00\u6240\u6709\u884C" : "Expand all rows" : p.expanded ? locale.collapse ?? (zh ? "\u6536\u8D77\u884C" : "Collapse row") : locale.expand ?? (zh ? "\u5C55\u5F00\u884C" : "Expand row"),
2962
+ "aria-expanded": p.expanded,
2963
+ onClick: p.onClick,
2964
+ children: p.expanded ? /* @__PURE__ */ jsx10(ChevronDown3, { size: 14 }) : /* @__PURE__ */ jsx10(ChevronRight3, { size: 14 })
2965
+ }
2966
+ ) : /* @__PURE__ */ jsx10("span", { className: "mt-table-expand-placeholder" }))
2967
+ };
2968
+ const rcProps = {
2969
+ ...engineProps,
2970
+ ref: tableRef,
2971
+ prefixCls: "mt-table",
2972
+ className: cn("mt-table-engine", showLoading && "mt-table-is-loading"),
2973
+ data: pageData,
2974
+ columns: renderedColumns,
2975
+ rowKey,
2976
+ scroll,
2977
+ expandable: resolvedExpandable,
2978
+ components: rcComponents,
2979
+ emptyText: showLoading ? null : empty2 ?? locale.emptyText ?? (zh ? "\u6682\u65E0\u6570\u636E" : "No data"),
2980
+ classNames: resolvedClasses,
2981
+ styles: resolvedStyles,
2982
+ rowClassName: (r, i, indent) => cn(
2983
+ typeof rowClassName === "function" ? rowClassName(r, i, indent) : rowClassName,
2984
+ selection.selectedKeys.includes(getKey(r)) && "mt-table-row-selected"
2985
+ ),
2986
+ onRow: (r, i) => ({
2987
+ ...onRow?.(r, i),
2988
+ "data-selected": selection.selectedKeys.includes(getKey(r)) || void 0
2989
+ }),
2990
+ "aria-busy": spinning || void 0
2991
+ };
2992
+ const positions2 = pagination ? pagination.placement ?? pagination.position ?? ["bottomEnd"] : [];
2993
+ const paginationNodes = (location) => pagination ? positions2.filter((p) => p.startsWith(location)).map((p) => /* @__PURE__ */ jsx10(
2994
+ TablePaginationBar,
2995
+ {
2996
+ config: pagination,
2997
+ total,
2998
+ current: page,
2999
+ pageSize,
3000
+ onChange: changePage,
3001
+ zh,
3002
+ placement: p,
3003
+ className: resolvedClasses.pagination,
3004
+ style: resolvedStyles.pagination
3005
+ },
3006
+ p
3007
+ )) : null;
3008
+ return /* @__PURE__ */ jsxs10(
3009
+ "div",
1037
3010
  {
1038
- type: "button",
1039
- ...p,
1040
- ref,
1041
- "aria-current": active ? "page" : void 0,
1042
3011
  className: cn(
1043
- "mt-nav-item",
1044
- active && "mt-active",
1045
- collapsed && "mt-nav-item-collapsed",
3012
+ "mt-table-wrap",
3013
+ `mt-table-size-${size}`,
3014
+ bordered && "mt-table-bordered",
3015
+ resolvedClasses.root,
1046
3016
  className
1047
3017
  ),
3018
+ style: { ...style, ...resolvedStyles.root },
3019
+ "aria-busy": spinning || void 0,
1048
3020
  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
3021
+ paginationNodes("top"),
3022
+ /* @__PURE__ */ jsxs10("div", { className: "mt-table-container", children: [
3023
+ virtual ? /* @__PURE__ */ jsx10(
3024
+ VirtualEngine,
3025
+ {
3026
+ ...rcProps,
3027
+ scroll: {
3028
+ x: typeof scroll?.x === "number" ? scroll.x : 1e3,
3029
+ y: typeof scroll?.y === "number" ? scroll.y : 400
3030
+ },
3031
+ listItemHeight: virtualItemHeight
3032
+ }
3033
+ ) : /* @__PURE__ */ jsx10(Engine, { ...rcProps }),
3034
+ showLoading && /* @__PURE__ */ jsx10("div", { className: "mt-table-loading", role: "status", children: loadingContent ?? (zh ? "\u52A0\u8F7D\u4E2D\u2026" : "Loading\u2026") })
3035
+ ] }),
3036
+ paginationNodes("bottom")
1051
3037
  ]
1052
3038
  }
1053
3039
  );
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
3040
  }
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) });
3041
+ var Table = Object.assign(
3042
+ React9.forwardRef(TableInner),
3043
+ {
3044
+ Column,
3045
+ ColumnGroup,
3046
+ Summary,
3047
+ EXPAND_COLUMN,
3048
+ SELECTION_COLUMN,
3049
+ SELECTION_ALL: "all",
3050
+ SELECTION_INVERT: "invert",
3051
+ SELECTION_NONE: "none"
3052
+ }
3053
+ );
1107
3054
 
1108
3055
  // 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";
3056
+ import { Fragment as Fragment8, jsx as jsx11, jsxs as jsxs11 } from "react/jsx-runtime";
1112
3057
  function Pagination({
1113
3058
  total,
1114
3059
  pageSize = 10,
@@ -1132,14 +3077,14 @@ function Pagination({
1132
3077
  count
1133
3078
  ])
1134
3079
  ).sort((a, b) => a - b);
1135
- return /* @__PURE__ */ jsxs5(
3080
+ return /* @__PURE__ */ jsxs11(
1136
3081
  "nav",
1137
3082
  {
1138
3083
  "aria-label": zh ? "\u5206\u9875" : "Pagination",
1139
3084
  className: cn("mt-pagination", className),
1140
3085
  children: [
1141
- /* @__PURE__ */ jsx5("span", { children: zh ? `\u5171 ${total} \u6761` : `${total} items` }),
1142
- /* @__PURE__ */ jsx5(
3086
+ /* @__PURE__ */ jsx11("span", { children: zh ? `\u5171 ${total} \u6761` : `${total} items` }),
3087
+ /* @__PURE__ */ jsx11(
1143
3088
  Button,
1144
3089
  {
1145
3090
  "aria-label": zh ? "\u4E0A\u4E00\u9875" : "Previous page",
@@ -1148,9 +3093,9 @@ function Pagination({
1148
3093
  children: "\u2039"
1149
3094
  }
1150
3095
  ),
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(
3096
+ /* @__PURE__ */ jsx11("span", { className: "mt-pagination-pages", children: pages.map((p, i) => /* @__PURE__ */ jsxs11(React10.Fragment, { children: [
3097
+ i > 0 && p - pages[i - 1] > 1 && /* @__PURE__ */ jsx11("span", { "aria-hidden": "true", children: "\u2026" }),
3098
+ /* @__PURE__ */ jsx11(
1154
3099
  Button,
1155
3100
  {
1156
3101
  "aria-label": `${zh ? "\u7B2C" : "Page "}${p}${zh ? "\u9875" : ""}`,
@@ -1161,7 +3106,7 @@ function Pagination({
1161
3106
  }
1162
3107
  )
1163
3108
  ] }, p)) }),
1164
- /* @__PURE__ */ jsx5(
3109
+ /* @__PURE__ */ jsx11(
1165
3110
  Button,
1166
3111
  {
1167
3112
  "aria-label": zh ? "\u4E0B\u4E00\u9875" : "Next page",
@@ -1174,180 +3119,6 @@ function Pagination({
1174
3119
  }
1175
3120
  );
1176
3121
  }
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
3122
  function Tree({
1352
3123
  items,
1353
3124
  value,
@@ -1360,10 +3131,10 @@ function Tree({
1360
3131
  className
1361
3132
  }) {
1362
3133
  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());
3134
+ const [selection, setSelection] = React10.useState(defaultValue);
3135
+ const [open, setOpen] = React10.useState(defaultExpanded);
3136
+ const [active, setActive] = React10.useState();
3137
+ const refs = React10.useRef(/* @__PURE__ */ new Map());
1367
3138
  const ids = expanded ?? open;
1368
3139
  const selected = value ?? selection;
1369
3140
  const visible = [];
@@ -1393,13 +3164,13 @@ function Tree({
1393
3164
  onValueChange?.(item.id);
1394
3165
  }
1395
3166
  };
1396
- return /* @__PURE__ */ jsx5(
3167
+ return /* @__PURE__ */ jsx11(
1397
3168
  "div",
1398
3169
  {
1399
3170
  className: cn("mt-tree", className),
1400
3171
  role: "tree",
1401
3172
  "aria-label": label ?? (zh ? "\u76EE\u5F55\u6811" : "Tree"),
1402
- children: visible.map(({ item, level, parent }) => /* @__PURE__ */ jsxs5(
3173
+ children: visible.map(({ item, level, parent }) => /* @__PURE__ */ jsxs11(
1403
3174
  "div",
1404
3175
  {
1405
3176
  ref: (el) => {
@@ -1463,7 +3234,7 @@ function Tree({
1463
3234
  }
1464
3235
  },
1465
3236
  children: [
1466
- item.children?.length ? /* @__PURE__ */ jsx5(
3237
+ item.children?.length ? /* @__PURE__ */ jsx11(
1467
3238
  "span",
1468
3239
  {
1469
3240
  "aria-hidden": "true",
@@ -1472,11 +3243,11 @@ function Tree({
1472
3243
  e.stopPropagation();
1473
3244
  if (!item.disabled) toggle(item.id);
1474
3245
  },
1475
- children: ids.includes(item.id) ? /* @__PURE__ */ jsx5(ChevronDown, { size: 14 }) : /* @__PURE__ */ jsx5(ChevronRight2, { size: 14 })
3246
+ children: ids.includes(item.id) ? /* @__PURE__ */ jsx11(ChevronDown4, { size: 14 }) : /* @__PURE__ */ jsx11(ChevronRight4, { size: 14 })
1476
3247
  }
1477
- ) : /* @__PURE__ */ jsx5("span", { className: "mt-tree-toggle" }),
3248
+ ) : /* @__PURE__ */ jsx11("span", { className: "mt-tree-toggle" }),
1478
3249
  item.icon,
1479
- /* @__PURE__ */ jsx5("span", { children: item.label })
3250
+ /* @__PURE__ */ jsx11("span", { children: item.label })
1480
3251
  ]
1481
3252
  },
1482
3253
  item.id
@@ -1498,10 +3269,10 @@ function DatePicker({
1498
3269
  name
1499
3270
  }) {
1500
3271
  const zh = useMtone().locale === "zh";
1501
- const [local, setLocal] = React4.useState(defaultValue);
1502
- const [error, setError] = React4.useState(false);
3272
+ const [local, setLocal] = React10.useState(defaultValue);
3273
+ const [error, setError] = React10.useState(false);
1503
3274
  const current = value ?? local;
1504
- const id = React4.useId();
3275
+ const id = React10.useId();
1505
3276
  const change = (next) => {
1506
3277
  const valid = !next || /^\d{4}-\d{2}-\d{2}$/.test(next) && (!min || next >= min) && (!max || next <= max) && !disabledDate?.(next);
1507
3278
  setError(!valid);
@@ -1510,8 +3281,8 @@ function DatePicker({
1510
3281
  onValueChange?.(next);
1511
3282
  }
1512
3283
  };
1513
- return /* @__PURE__ */ jsxs5("div", { className: cn("mt-date-picker", className), children: [
1514
- /* @__PURE__ */ jsx5(
3284
+ return /* @__PURE__ */ jsxs11("div", { className: cn("mt-date-picker", className), children: [
3285
+ /* @__PURE__ */ jsx11("span", { className: "mt-date-field", children: /* @__PURE__ */ jsx11(
1515
3286
  "input",
1516
3287
  {
1517
3288
  className: "mt-input",
@@ -1526,8 +3297,8 @@ function DatePicker({
1526
3297
  "aria-describedby": error ? id : void 0,
1527
3298
  onChange: (e) => change(e.target.value)
1528
3299
  }
1529
- ),
1530
- clearable && current && /* @__PURE__ */ jsx5(
3300
+ ) }),
3301
+ clearable && current && /* @__PURE__ */ jsx11(
1531
3302
  Button,
1532
3303
  {
1533
3304
  variant: "ghost",
@@ -1537,7 +3308,7 @@ function DatePicker({
1537
3308
  children: "\xD7"
1538
3309
  }
1539
3310
  ),
1540
- error && /* @__PURE__ */ jsx5("span", { id, role: "alert", className: "mt-error", children: zh ? "\u6B64\u65E5\u671F\u4E0D\u53EF\u9009" : "This date is unavailable" })
3311
+ error && /* @__PURE__ */ jsx11("span", { id, role: "alert", className: "mt-error", children: zh ? "\u6B64\u65E5\u671F\u4E0D\u53EF\u9009" : "This date is unavailable" })
1541
3312
  ] });
1542
3313
  }
1543
3314
  function Upload({
@@ -1551,15 +3322,15 @@ function Upload({
1551
3322
  children
1552
3323
  }) {
1553
3324
  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);
3325
+ const [files, setFiles] = React10.useState([]);
3326
+ const [drag, setDrag] = React10.useState(false);
3327
+ const input = React10.useRef(null);
3328
+ const current = React10.useRef([]);
3329
+ const runs = React10.useRef(/* @__PURE__ */ new Map());
3330
+ const alive = React10.useRef(true);
3331
+ const changeRef = React10.useRef(onChange);
1561
3332
  changeRef.current = onChange;
1562
- React4.useEffect(() => {
3333
+ React10.useEffect(() => {
1563
3334
  alive.current = true;
1564
3335
  return () => {
1565
3336
  alive.current = false;
@@ -1645,8 +3416,8 @@ function Upload({
1645
3416
  runs.current.delete(id);
1646
3417
  patch(id, { status: "cancelled" });
1647
3418
  };
1648
- return /* @__PURE__ */ jsxs5("div", { className: cn("mt-upload", className), children: [
1649
- /* @__PURE__ */ jsxs5(
3419
+ return /* @__PURE__ */ jsxs11("div", { className: cn("mt-upload", className), children: [
3420
+ /* @__PURE__ */ jsxs11(
1650
3421
  "div",
1651
3422
  {
1652
3423
  className: "mt-dropzone",
@@ -1662,9 +3433,9 @@ function Upload({
1662
3433
  add(Array.from(e.dataTransfer.files));
1663
3434
  },
1664
3435
  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(
3436
+ /* @__PURE__ */ jsx11(UploadIcon, { size: 22 }),
3437
+ children ?? /* @__PURE__ */ jsx11("span", { children: zh ? "\u62D6\u62FD\u6587\u4EF6\u5230\u6B64\u5904\uFF0C\u6216\u9009\u62E9\u6587\u4EF6" : "Drop files here, or choose files" }),
3438
+ /* @__PURE__ */ jsx11(
1668
3439
  "input",
1669
3440
  {
1670
3441
  ref: input,
@@ -1682,18 +3453,18 @@ function Upload({
1682
3453
  ]
1683
3454
  }
1684
3455
  ),
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: [
3456
+ /* @__PURE__ */ jsx11("ul", { className: "mt-upload-list", children: files.map((f) => /* @__PURE__ */ jsxs11("li", { children: [
3457
+ /* @__PURE__ */ jsxs11("span", { className: "mt-upload-name", children: [
1687
3458
  f.file.name,
1688
- /* @__PURE__ */ jsx5("small", { role: f.status === "error" ? "alert" : "status", children: f.error ?? {
3459
+ /* @__PURE__ */ jsx11("small", { role: f.status === "error" ? "alert" : "status", children: f.error ?? {
1689
3460
  uploading: zh ? "\u4E0A\u4F20\u4E2D" : "Uploading",
1690
3461
  success: zh ? "\u4E0A\u4F20\u6210\u529F" : "Uploaded",
1691
3462
  cancelled: zh ? "\u5DF2\u53D6\u6D88" : "Cancelled",
1692
3463
  error: zh ? "\u4E0A\u4F20\u5931\u8D25" : "Failed"
1693
3464
  }[f.status] })
1694
3465
  ] }),
1695
- f.status === "uploading" && /* @__PURE__ */ jsxs5(Fragment3, { children: [
1696
- /* @__PURE__ */ jsx5(
3466
+ f.status === "uploading" && /* @__PURE__ */ jsxs11(Fragment8, { children: [
3467
+ /* @__PURE__ */ jsx11(
1697
3468
  "progress",
1698
3469
  {
1699
3470
  value: f.progress,
@@ -1701,9 +3472,9 @@ function Upload({
1701
3472
  "aria-label": `${f.file.name} ${zh ? "\u8FDB\u5EA6" : "progress"}`
1702
3473
  }
1703
3474
  ),
1704
- /* @__PURE__ */ jsx5(Button, { onClick: () => cancel(f.id), children: zh ? "\u53D6\u6D88" : "Cancel" })
3475
+ /* @__PURE__ */ jsx11(Button, { onClick: () => cancel(f.id), children: zh ? "\u53D6\u6D88" : "Cancel" })
1705
3476
  ] }),
1706
- (f.status === "cancelled" || f.status === "error") && /* @__PURE__ */ jsx5(
3477
+ (f.status === "cancelled" || f.status === "error") && /* @__PURE__ */ jsx11(
1707
3478
  Button,
1708
3479
  {
1709
3480
  disabled: disabled || !!f.validationError,
@@ -1711,7 +3482,7 @@ function Upload({
1711
3482
  children: zh ? "\u91CD\u8BD5" : "Retry"
1712
3483
  }
1713
3484
  ),
1714
- /* @__PURE__ */ jsx5(
3485
+ /* @__PURE__ */ jsx11(
1715
3486
  Button,
1716
3487
  {
1717
3488
  variant: "ghost",
@@ -1730,8 +3501,8 @@ function Upload({
1730
3501
  var Dropzone = Upload;
1731
3502
 
1732
3503
  // src/layout.tsx
1733
- import * as React5 from "react";
1734
- import { jsx as jsx6, jsxs as jsxs6 } from "react/jsx-runtime";
3504
+ import * as React11 from "react";
3505
+ import { jsx as jsx12, jsxs as jsxs12 } from "react/jsx-runtime";
1735
3506
  function LayoutSider({
1736
3507
  logo,
1737
3508
  version,
@@ -1748,9 +3519,9 @@ function LayoutSider({
1748
3519
  style,
1749
3520
  ...props
1750
3521
  }) {
1751
- const [internal, setInternal] = React5.useState(defaultCollapsed);
1752
- const previousBreakpoint = React5.useRef(void 0);
1753
- const callbacks = React5.useRef({
3522
+ const [internal, setInternal] = React11.useState(defaultCollapsed);
3523
+ const previousBreakpoint = React11.useRef(void 0);
3524
+ const callbacks = React11.useRef({
1754
3525
  onBreakpoint,
1755
3526
  onCollapsedChange,
1756
3527
  collapsed
@@ -1760,7 +3531,7 @@ function LayoutSider({
1760
3531
  if (collapsed === void 0) setInternal(next);
1761
3532
  onCollapsedChange?.(next);
1762
3533
  };
1763
- React5.useEffect(() => {
3534
+ React11.useEffect(() => {
1764
3535
  if (!collapsible || !breakpoint || typeof window.matchMedia !== "function")
1765
3536
  return;
1766
3537
  const media = window.matchMedia(`(max-width: ${breakpoint - 0.02}px)`);
@@ -1780,7 +3551,7 @@ function LayoutSider({
1780
3551
  }, [breakpoint, collapsible]);
1781
3552
  const safeWidth = Number.isFinite(width) ? Math.max(40, width) : 240;
1782
3553
  const safeCollapsedWidth = Number.isFinite(collapsedWidth) ? Math.max(40, collapsedWidth) : 52;
1783
- return /* @__PURE__ */ jsx6(
3554
+ return /* @__PURE__ */ jsx12(
1784
3555
  Sidebar,
1785
3556
  {
1786
3557
  ...props,
@@ -1806,12 +3577,12 @@ function LayoutHeader({
1806
3577
  className,
1807
3578
  ...props
1808
3579
  }) {
1809
- return /* @__PURE__ */ jsxs6("header", { ...props, className: cn("mt-layout-header", className), children: [
1810
- /* @__PURE__ */ jsxs6("div", { className: "mt-layout-header-main", children: [
3580
+ return /* @__PURE__ */ jsxs12("header", { ...props, className: cn("mt-layout-header", className), children: [
3581
+ /* @__PURE__ */ jsxs12("div", { className: "mt-layout-header-main", children: [
1811
3582
  breadcrumb,
1812
3583
  children
1813
3584
  ] }),
1814
- extra != null && /* @__PURE__ */ jsx6("div", { className: "mt-layout-header-extra", children: extra })
3585
+ extra != null && /* @__PURE__ */ jsx12("div", { className: "mt-layout-header-extra", children: extra })
1815
3586
  ] });
1816
3587
  }
1817
3588
  function LayoutContent({
@@ -1819,17 +3590,17 @@ function LayoutContent({
1819
3590
  className,
1820
3591
  ...props
1821
3592
  }) {
1822
- return /* @__PURE__ */ jsx6(Element, { ...props, className: cn("mt-layout-content", className) });
3593
+ return /* @__PURE__ */ jsx12(Element, { ...props, className: cn("mt-layout-content", className) });
1823
3594
  }
1824
3595
  function LayoutFooter({
1825
3596
  className,
1826
3597
  ...props
1827
3598
  }) {
1828
- return /* @__PURE__ */ jsx6("footer", { ...props, className: cn("mt-layout-footer", className) });
3599
+ return /* @__PURE__ */ jsx12("footer", { ...props, className: cn("mt-layout-footer", className) });
1829
3600
  }
1830
3601
  function containsSider(children) {
1831
- return React5.Children.toArray(children).some(
1832
- (child) => React5.isValidElement(child) && (child.type === LayoutSider || child.type === React5.Fragment && containsSider(
3602
+ return React11.Children.toArray(children).some(
3603
+ (child) => React11.isValidElement(child) && (child.type === LayoutSider || child.type === React11.Fragment && containsSider(
1833
3604
  child.props.children
1834
3605
  ))
1835
3606
  );
@@ -1841,7 +3612,7 @@ function LayoutRoot({
1841
3612
  children,
1842
3613
  ...props
1843
3614
  }) {
1844
- return /* @__PURE__ */ jsx6(
3615
+ return /* @__PURE__ */ jsx12(
1845
3616
  "div",
1846
3617
  {
1847
3618
  ...props,
@@ -1861,6 +3632,766 @@ var Layout = Object.assign(LayoutRoot, {
1861
3632
  Content: LayoutContent,
1862
3633
  Footer: LayoutFooter
1863
3634
  });
3635
+
3636
+ // src/spotlight.tsx
3637
+ import React12 from "react";
3638
+ import { Search as Search2 } from "lucide-react";
3639
+ import { jsx as jsx13, jsxs as jsxs13 } from "react/jsx-runtime";
3640
+ function Spotlight({
3641
+ actions,
3642
+ trigger,
3643
+ open,
3644
+ defaultOpen = false,
3645
+ onOpenChange,
3646
+ query,
3647
+ defaultQuery = "",
3648
+ onQueryChange,
3649
+ shortcut = "k",
3650
+ enableInInputs = false,
3651
+ title,
3652
+ placeholder,
3653
+ nothingFound,
3654
+ limit = 20,
3655
+ filter,
3656
+ onActionSelect,
3657
+ closeOnSelect = true,
3658
+ resetQueryOnClose = true,
3659
+ className
3660
+ }) {
3661
+ const { locale } = useMtone();
3662
+ const zh = locale === "zh";
3663
+ const [localOpen, setLocalOpen] = React12.useState(defaultOpen);
3664
+ const [localQuery, setLocalQuery] = React12.useState(defaultQuery);
3665
+ const [active, setActive] = React12.useState(null);
3666
+ const shown = open ?? localOpen;
3667
+ const search = query ?? localQuery;
3668
+ const input = React12.useRef(null);
3669
+ const id = React12.useId();
3670
+ const changeQuery = (next) => {
3671
+ if (query === void 0) setLocalQuery(next);
3672
+ onQueryChange?.(next);
3673
+ setActive(null);
3674
+ };
3675
+ const changeOpen = (next) => {
3676
+ if (open === void 0) setLocalOpen(next);
3677
+ onOpenChange?.(next);
3678
+ if (!next && resetQueryOnClose) changeQuery("");
3679
+ };
3680
+ React12.useEffect(() => {
3681
+ if (!shortcut) return;
3682
+ const listener = (event) => {
3683
+ const target = event.target instanceof HTMLElement ? event.target : null;
3684
+ if (event.defaultPrevented || event.repeat || event.isComposing || event.altKey || event.shiftKey || !(event.ctrlKey || event.metaKey) || event.key.toLowerCase() !== shortcut.toLowerCase()) return;
3685
+ if (!enableInInputs && target !== input.current && target?.closest('input, textarea, select, [contenteditable]:not([contenteditable="false"])')) return;
3686
+ event.preventDefault();
3687
+ changeOpen(!shown);
3688
+ };
3689
+ document.addEventListener("keydown", listener);
3690
+ return () => document.removeEventListener("keydown", listener);
3691
+ });
3692
+ React12.useEffect(() => {
3693
+ if (!shown) return;
3694
+ const frame = requestAnimationFrame(() => input.current?.focus());
3695
+ return () => cancelAnimationFrame(frame);
3696
+ }, [shown]);
3697
+ const normalized = search.trim().toLocaleLowerCase();
3698
+ const matches = actions.filter((action) => filter ? filter(search, action) : [action.label, action.description, ...Array.isArray(action.keywords) ? action.keywords : [action.keywords]].filter(Boolean).join(" ").toLocaleLowerCase().includes(normalized)).slice(0, Math.max(0, Number.isFinite(limit) ? Math.floor(limit) : 20));
3699
+ const enabled = matches.filter((action) => !action.disabled);
3700
+ const current = enabled.find((action) => action.id === active)?.id ?? enabled[0]?.id;
3701
+ React12.useEffect(() => {
3702
+ if (shown && current) document.getElementById(`${id}-${encodeURIComponent(current)}`)?.scrollIntoView({ block: "nearest" });
3703
+ }, [current, shown, id]);
3704
+ const select = (action) => {
3705
+ if (action.disabled) return;
3706
+ if (closeOnSelect) changeOpen(false);
3707
+ action.onSelect?.();
3708
+ onActionSelect?.(action);
3709
+ };
3710
+ const groups = [];
3711
+ for (const action of matches) {
3712
+ const last = groups[groups.length - 1];
3713
+ if (last && last.label === action.group) last.actions.push(action);
3714
+ else groups.push({ label: action.group, actions: [action] });
3715
+ }
3716
+ return /* @__PURE__ */ jsxs13(
3717
+ Dialog,
3718
+ {
3719
+ title: title ?? (zh ? "\u5FEB\u6377\u64CD\u4F5C" : "Command palette"),
3720
+ trigger,
3721
+ open: shown,
3722
+ onOpenChange: changeOpen,
3723
+ modal: false,
3724
+ className: ["mt-spotlight", className].filter(Boolean).join(" "),
3725
+ children: [
3726
+ /* @__PURE__ */ jsxs13("div", { className: "mt-spotlight-search", children: [
3727
+ /* @__PURE__ */ jsx13(Search2, { size: 18, "aria-hidden": "true" }),
3728
+ /* @__PURE__ */ jsx13(
3729
+ Input,
3730
+ {
3731
+ ref: input,
3732
+ value: search,
3733
+ onChange: (event) => changeQuery(event.target.value),
3734
+ placeholder: placeholder ?? (zh ? "\u641C\u7D22\u64CD\u4F5C\u6216\u9875\u9762\u2026" : "Search actions or pages\u2026"),
3735
+ "aria-label": placeholder ?? (zh ? "\u641C\u7D22\u64CD\u4F5C" : "Search actions"),
3736
+ role: "combobox",
3737
+ "aria-autocomplete": "list",
3738
+ "aria-expanded": shown,
3739
+ "aria-controls": `${id}-list`,
3740
+ "aria-activedescendant": current ? `${id}-${encodeURIComponent(current)}` : void 0,
3741
+ onKeyDown: (event) => {
3742
+ if (event.nativeEvent.isComposing) return;
3743
+ if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key)) {
3744
+ event.preventDefault();
3745
+ const index = enabled.findIndex((action) => action.id === current);
3746
+ const next = event.key === "Home" ? 0 : event.key === "End" ? enabled.length - 1 : (index + (event.key === "ArrowDown" ? 1 : -1) + enabled.length) % enabled.length;
3747
+ setActive(enabled[next]?.id ?? null);
3748
+ } else if (event.key === "Enter" && current) {
3749
+ event.preventDefault();
3750
+ const action = enabled.find((action2) => action2.id === current);
3751
+ if (action) select(action);
3752
+ }
3753
+ }
3754
+ }
3755
+ )
3756
+ ] }),
3757
+ /* @__PURE__ */ jsx13("div", { id: `${id}-list`, role: "listbox", "aria-label": zh ? "\u641C\u7D22\u7ED3\u679C" : "Search results", className: "mt-spotlight-list", children: groups.map((group, index) => /* @__PURE__ */ jsxs13("div", { role: "group", "aria-label": group.label, children: [
3758
+ group.label && /* @__PURE__ */ jsx13("div", { className: "mt-spotlight-group", "aria-hidden": "true", children: group.label }),
3759
+ group.actions.map((action) => /* @__PURE__ */ jsxs13(
3760
+ "div",
3761
+ {
3762
+ id: `${id}-${encodeURIComponent(action.id)}`,
3763
+ role: "option",
3764
+ "aria-selected": current === action.id,
3765
+ "aria-disabled": action.disabled || void 0,
3766
+ className: "mt-spotlight-option",
3767
+ onMouseDown: (event) => event.preventDefault(),
3768
+ onMouseMove: () => !action.disabled && setActive(action.id),
3769
+ onClick: () => select(action),
3770
+ children: [
3771
+ action.icon && /* @__PURE__ */ jsx13("span", { className: "mt-spotlight-icon", "aria-hidden": "true", children: action.icon }),
3772
+ /* @__PURE__ */ jsxs13("span", { className: "mt-spotlight-text", children: [
3773
+ /* @__PURE__ */ jsx13("span", { children: action.label }),
3774
+ action.description && /* @__PURE__ */ jsx13("small", { children: action.description })
3775
+ ] }),
3776
+ action.rightSection && /* @__PURE__ */ jsx13("span", { className: "mt-spotlight-right", children: action.rightSection })
3777
+ ]
3778
+ },
3779
+ action.id
3780
+ ))
3781
+ ] }, index)) }),
3782
+ !matches.length && /* @__PURE__ */ jsx13("div", { role: "status", className: "mt-spotlight-empty", children: nothingFound ?? (zh ? "\u6CA1\u6709\u627E\u5230\u76F8\u5173\u64CD\u4F5C" : "No actions found") }),
3783
+ /* @__PURE__ */ jsx13("div", { className: "mt-spotlight-footer", children: zh ? "\u2191 \u2193 \u9009\u62E9 \xB7 Enter \u6267\u884C \xB7 Esc \u5173\u95ED" : "\u2191 \u2193 Navigate \xB7 Enter Select \xB7 Esc Close" })
3784
+ ]
3785
+ }
3786
+ );
3787
+ }
3788
+
3789
+ // src/splitter.tsx
3790
+ import * as React13 from "react";
3791
+ import {
3792
+ Group,
3793
+ Panel as ResizablePanel,
3794
+ Separator
3795
+ } from "react-resizable-panels";
3796
+
3797
+ // src/splitter-utils.ts
3798
+ function validateSplitterSize(value, name) {
3799
+ if (value === void 0) return;
3800
+ const valid = typeof value === "number" ? Number.isFinite(value) && value >= 0 : /^(?:\d+(?:\.\d+)?|\.\d+)(?:%|px)$/.test(value) && Number.isFinite(parseFloat(value));
3801
+ if (!valid)
3802
+ throw new Error(
3803
+ `Splitter: ${name} must be a non-negative finite pixel number or an explicit %/px string.`
3804
+ );
3805
+ }
3806
+ function splitterSizeToPixels(value, available) {
3807
+ validateSplitterSize(value, "size");
3808
+ return typeof value === "number" ? value : value.endsWith("%") ? parseFloat(value) * available / 100 : parseFloat(value);
3809
+ }
3810
+ function splitterControlledLayout(sizes, ids, available) {
3811
+ if (sizes.length !== ids.length)
3812
+ throw new Error("Splitter: sizes must contain one size for every Panel.");
3813
+ sizes.forEach((size, i) => validateSplitterSize(size, `sizes[${i}]`));
3814
+ const values = sizes.map((size) => splitterSizeToPixels(size, available)), total = values.reduce((a, b) => a + b, 0);
3815
+ if (!Number.isFinite(total) || total <= 0)
3816
+ throw new Error("Splitter: controlled sizes must have a positive total.");
3817
+ return Object.fromEntries(
3818
+ ids.map((id, i) => [id, values[i] / total * 100])
3819
+ );
3820
+ }
3821
+ function splitterLayoutsEqual(a, b) {
3822
+ return Object.keys(a).length === Object.keys(b).length && Object.keys(a).every((key) => Math.abs(a[key] - (b[key] ?? -1e3)) < 1e-3);
3823
+ }
3824
+ function splitterPairTarget(total, ratio, phase, a, b) {
3825
+ const valid = (value, c) => value >= c.min - 1e-3 && value <= c.max + 1e-3 || c.collapsible && Math.abs(value - c.collapsed) < 1e-3;
3826
+ let first;
3827
+ if (phase === "first") first = a.collapsed;
3828
+ else if (phase === "second") first = total - b.collapsed;
3829
+ else {
3830
+ const desired = total * ratio;
3831
+ if (valid(desired, a) && valid(total - desired, b)) first = desired;
3832
+ else {
3833
+ const lower = Math.max(a.min, total - b.max);
3834
+ const upper = Math.min(a.max, total - b.min);
3835
+ if (lower > upper) return null;
3836
+ first = Math.max(lower, Math.min(upper, desired));
3837
+ }
3838
+ }
3839
+ const second = total - first;
3840
+ return Number.isFinite(first) && valid(first, a) && valid(second, b) ? [first, second] : null;
3841
+ }
3842
+
3843
+ // src/splitter.tsx
3844
+ import { jsx as jsx14 } from "react/jsx-runtime";
3845
+ import { createElement } from "react";
3846
+ function SplitterPanel(_props) {
3847
+ return null;
3848
+ }
3849
+ function collect(children) {
3850
+ const result = [];
3851
+ React13.Children.forEach(children, (child) => {
3852
+ if (child == null || typeof child === "boolean") return;
3853
+ if (!React13.isValidElement(child))
3854
+ throw new Error("Splitter: children must be Splitter.Panel elements.");
3855
+ if (child.type === React13.Fragment) {
3856
+ result.push(
3857
+ ...collect(child.props.children)
3858
+ );
3859
+ } else if (child.type === SplitterPanel)
3860
+ result.push(child);
3861
+ else
3862
+ throw new Error(
3863
+ "Splitter: children must be Splitter.Panel elements (Fragments are supported)."
3864
+ );
3865
+ });
3866
+ return result;
3867
+ }
3868
+ var resizeKeys = /* @__PURE__ */ new Set([
3869
+ "ArrowLeft",
3870
+ "ArrowRight",
3871
+ "ArrowUp",
3872
+ "ArrowDown",
3873
+ "Home",
3874
+ "End",
3875
+ "Enter"
3876
+ ]);
3877
+ function SplitterRoot(props) {
3878
+ const {
3879
+ children,
3880
+ orientation = "horizontal",
3881
+ sizes,
3882
+ disabled = false,
3883
+ lazy = false,
3884
+ onResize,
3885
+ onResizeStart,
3886
+ onResizeEnd,
3887
+ onCollapse,
3888
+ onDraggerDoubleClick,
3889
+ className,
3890
+ style,
3891
+ onPointerDownCapture,
3892
+ onKeyDownCapture,
3893
+ onPointerMoveCapture,
3894
+ onPointerUpCapture,
3895
+ onPointerCancelCapture,
3896
+ ...native
3897
+ } = props;
3898
+ const { locale } = useMtone();
3899
+ const prefix = React13.useId();
3900
+ const panels = collect(children);
3901
+ const ids = panels.map(
3902
+ (child, i) => child.props.id ?? `${prefix}-${child.key ?? i}`
3903
+ );
3904
+ if (panels.length > 0 && panels.every(
3905
+ (panel) => panel.props.groupResizeBehavior === "preserve-pixel-size"
3906
+ ))
3907
+ throw new Error(
3908
+ "Splitter: at least one Panel must preserve relative size."
3909
+ );
3910
+ if (new Set(ids).size !== ids.length)
3911
+ throw new Error("Splitter: Panel ids must be unique.");
3912
+ panels.forEach(({ props: p }, i) => {
3913
+ for (const name of ["defaultSize", "min", "max", "collapsedSize"])
3914
+ validateSplitterSize(p[name], `Panel ${i} ${name}`);
3915
+ const unit = (v) => typeof v === "number" || v.endsWith("px") ? "px" : "%";
3916
+ if (p.min !== void 0 && p.max !== void 0 && unit(p.min) === unit(p.max) && parseFloat(String(p.min)) > parseFloat(String(p.max)))
3917
+ throw new Error("Splitter: Panel min cannot exceed max.");
3918
+ });
3919
+ if (sizes) splitterControlledLayout(sizes, ids, 100);
3920
+ const group = React13.useRef(null), element = React13.useRef(null), panelRefs = React13.useRef(/* @__PURE__ */ new Map());
3921
+ const layout = React13.useRef({}), [view, setView] = React13.useState({}), [axis, setAxis] = React13.useState(0), [collapsed, setCollapsed] = React13.useState({});
3922
+ const collapsedRef = React13.useRef({});
3923
+ const initial = React13.useRef(null);
3924
+ const phases = React13.useRef(
3925
+ /* @__PURE__ */ new Map()
3926
+ );
3927
+ const cyclePending = React13.useRef(false);
3928
+ const cycleToken = React13.useRef(0);
3929
+ const queuedCycle = React13.useRef(null);
3930
+ const cycleHandler = React13.useRef(() => {
3931
+ });
3932
+ const touchTap = React13.useRef(null);
3933
+ const touchDown = React13.useRef(null);
3934
+ const lastTouchCycle = React13.useRef(-Infinity);
3935
+ const suppress = React13.useRef(false), mounted = React13.useRef(true), lastApplied = React13.useRef(null), session = React13.useRef(null);
3936
+ const latest = React13.useRef({
3937
+ ids,
3938
+ panels,
3939
+ sizes,
3940
+ onResize,
3941
+ onResizeStart,
3942
+ onResizeEnd,
3943
+ onCollapse
3944
+ });
3945
+ latest.current = {
3946
+ ids,
3947
+ panels,
3948
+ sizes,
3949
+ onResize,
3950
+ onResizeStart,
3951
+ onResizeEnd,
3952
+ onCollapse
3953
+ };
3954
+ const measure = () => {
3955
+ const el = element.current;
3956
+ if (!el) return 0;
3957
+ const horizontal2 = orientation === "horizontal";
3958
+ const rootRect = el.getBoundingClientRect();
3959
+ const scale = (horizontal2 ? rootRect.width / el.offsetWidth : rootRect.height / el.offsetHeight) || 1;
3960
+ return Array.from(el.children).filter((node) => node.hasAttribute("data-panel")).reduce((total, node) => {
3961
+ const panel = node, rect = panel.getBoundingClientRect();
3962
+ const measured = (horizontal2 ? rect.width : rect.height) / scale;
3963
+ const rounded = horizontal2 ? panel.offsetWidth : panel.offsetHeight;
3964
+ return total + (Math.abs(measured - rounded) < 1 ? measured : rounded);
3965
+ }, 0);
3966
+ };
3967
+ const pixels = (values = layout.current) => {
3968
+ const available = measure();
3969
+ return latest.current.ids.map(
3970
+ (id) => (values[id] ?? 0) * available / 100
3971
+ );
3972
+ };
3973
+ const write = (next) => {
3974
+ if (!group.current || !mounted.current) return;
3975
+ suppress.current = true;
3976
+ try {
3977
+ const applied = group.current.setLayout(next);
3978
+ layout.current = applied;
3979
+ setView(applied);
3980
+ return applied;
3981
+ } finally {
3982
+ suppress.current = false;
3983
+ }
3984
+ };
3985
+ const begin = (pointerId, pointerType, boundary) => {
3986
+ if (session.current || disabled) return;
3987
+ session.current = {
3988
+ before: { ...layout.current },
3989
+ phasesBefore: new Map(phases.current),
3990
+ pointerId,
3991
+ pointerType,
3992
+ boundary
3993
+ };
3994
+ latest.current.onResizeStart?.(pixels());
3995
+ };
3996
+ const finish = () => {
3997
+ if (!session.current) return;
3998
+ session.current = null;
3999
+ latest.current.onResizeEnd?.(pixels());
4000
+ };
4001
+ const reportCollapse = () => {
4002
+ const next = Object.fromEntries(
4003
+ latest.current.ids.map((id) => [
4004
+ id,
4005
+ panelRefs.current.get(id)?.isCollapsed() ?? false
4006
+ ])
4007
+ );
4008
+ const prev = collapsedRef.current;
4009
+ const changed = latest.current.ids.some(
4010
+ (id) => prev[id] !== void 0 && prev[id] !== next[id]
4011
+ );
4012
+ if (Object.keys(prev).length !== Object.keys(next).length || latest.current.ids.some((id) => prev[id] !== next[id])) {
4013
+ collapsedRef.current = next;
4014
+ setCollapsed(next);
4015
+ }
4016
+ if (changed)
4017
+ latest.current.onCollapse?.(
4018
+ latest.current.ids.map((id) => next[id]),
4019
+ pixels()
4020
+ );
4021
+ };
4022
+ React13.useLayoutEffect(() => {
4023
+ const el = element.current;
4024
+ if (!el) return;
4025
+ const observer = new ResizeObserver(() => setAxis(measure()));
4026
+ setAxis(measure());
4027
+ observer.observe(el);
4028
+ return () => observer.disconnect();
4029
+ }, [orientation, ids.join("|")]);
4030
+ React13.useLayoutEffect(() => {
4031
+ if (!sizes || !group.current || axis <= 0 || !ids.every((id) => layout.current[id] !== void 0))
4032
+ return;
4033
+ const key = JSON.stringify([ids, sizes, axis]);
4034
+ const prior = lastApplied.current;
4035
+ if (prior?.key === key && splitterLayoutsEqual(layout.current, prior.layout))
4036
+ return;
4037
+ const applied = write(splitterControlledLayout(sizes, ids, axis));
4038
+ if (applied) {
4039
+ lastApplied.current = { key, layout: applied };
4040
+ reportCollapse();
4041
+ }
4042
+ });
4043
+ React13.useEffect(() => {
4044
+ mounted.current = true;
4045
+ const win = element.current?.ownerDocument.defaultView;
4046
+ if (!win) return;
4047
+ const end = (event) => {
4048
+ if ("pointerId" in event && event.pointerId !== session.current?.pointerId)
4049
+ return;
4050
+ const activeSession = session.current;
4051
+ requestAnimationFrame(() => {
4052
+ if (mounted.current && session.current === activeSession) {
4053
+ reportCollapse();
4054
+ finish();
4055
+ }
4056
+ });
4057
+ };
4058
+ const cancel = (event) => {
4059
+ if (event.pointerId !== session.current?.pointerId) return;
4060
+ const activeSession = session.current;
4061
+ const before = activeSession?.before;
4062
+ if (!before) return;
4063
+ session.current.cancelled = true;
4064
+ queueMicrotask(() => {
4065
+ if (mounted.current && session.current === activeSession) {
4066
+ phases.current = new Map(activeSession.phasesBefore);
4067
+ write(before);
4068
+ latest.current.onResize?.(pixels(before));
4069
+ reportCollapse();
4070
+ finish();
4071
+ }
4072
+ });
4073
+ };
4074
+ const escape = (e) => {
4075
+ if (e.key !== "Escape" || session.current?.pointerId === void 0)
4076
+ return;
4077
+ e.preventDefault();
4078
+ const s = session.current;
4079
+ const target = element.current;
4080
+ target?.dispatchEvent(
4081
+ new PointerEvent("pointercancel", {
4082
+ bubbles: true,
4083
+ pointerId: s.pointerId ?? 1,
4084
+ pointerType: s.pointerType ?? "mouse"
4085
+ })
4086
+ );
4087
+ };
4088
+ win.addEventListener("pointerup", end);
4089
+ win.addEventListener("pointercancel", cancel, true);
4090
+ win.addEventListener("keydown", escape, true);
4091
+ win.addEventListener("blur", end);
4092
+ return () => {
4093
+ mounted.current = false;
4094
+ session.current = null;
4095
+ cyclePending.current = false;
4096
+ queuedCycle.current = null;
4097
+ cycleToken.current++;
4098
+ win.removeEventListener("pointerup", end);
4099
+ win.removeEventListener("pointercancel", cancel, true);
4100
+ win.removeEventListener("keydown", escape, true);
4101
+ win.removeEventListener("blur", end);
4102
+ };
4103
+ }, [orientation]);
4104
+ const topology = JSON.stringify(ids);
4105
+ React13.useLayoutEffect(() => {
4106
+ if (axis > 0 && ids.every((id) => layout.current[id] !== void 0) && initial.current?.key !== topology) {
4107
+ initial.current = { key: topology, layout: { ...layout.current } };
4108
+ phases.current.clear();
4109
+ cyclePending.current = false;
4110
+ queuedCycle.current = null;
4111
+ cycleToken.current++;
4112
+ }
4113
+ });
4114
+ React13.useEffect(() => {
4115
+ phases.current.clear();
4116
+ }, [orientation]);
4117
+ const cycle = (boundary) => {
4118
+ const current = latest.current;
4119
+ const a = current.panels[boundary]?.props, b = current.panels[boundary + 1]?.props;
4120
+ if (disabled || !a || !b || a.resizable === false || b.resizable === false || !a.collapsible && !b.collapsible)
4121
+ return;
4122
+ if (cyclePending.current) {
4123
+ queuedCycle.current = { boundary, topology: JSON.stringify(current.ids) };
4124
+ return;
4125
+ }
4126
+ const aid = current.ids[boundary], bid = current.ids[boundary + 1];
4127
+ const key = JSON.stringify([aid, bid]);
4128
+ const snapshot = initial.current;
4129
+ if (!snapshot || snapshot.key !== JSON.stringify(current.ids)) return;
4130
+ const previous = phases.current.get(key);
4131
+ const phase = a.collapsible && b.collapsible ? previous === "first" ? "initial" : previous === "initial" ? "second" : "first" : previous === (a.collapsible ? "first" : "second") ? "initial" : a.collapsible ? "first" : "second";
4132
+ const available = measure();
4133
+ if (available <= 0) return;
4134
+ const percent = (value) => splitterSizeToPixels(value, available) / available * 100;
4135
+ const constraint = (p) => ({
4136
+ min: percent(p.min ?? (p.collapsible ? "10%" : 0)),
4137
+ max: percent(p.max ?? "100%"),
4138
+ collapsed: percent(p.collapsedSize ?? 0),
4139
+ collapsible: !!p.collapsible
4140
+ });
4141
+ const initialTotal = snapshot.layout[aid] + snapshot.layout[bid];
4142
+ const target = splitterPairTarget(
4143
+ layout.current[aid] + layout.current[bid],
4144
+ initialTotal > 0 ? snapshot.layout[aid] / initialTotal : 0.5,
4145
+ phase,
4146
+ constraint(a),
4147
+ constraint(b)
4148
+ );
4149
+ if (!target) return;
4150
+ const before = { ...layout.current };
4151
+ const next = { ...before, [aid]: target[0], [bid]: target[1] };
4152
+ if (splitterLayoutsEqual(before, next)) {
4153
+ phases.current.set(key, phase);
4154
+ return;
4155
+ }
4156
+ cyclePending.current = true;
4157
+ const token = ++cycleToken.current;
4158
+ finish();
4159
+ begin();
4160
+ const applied = write(next);
4161
+ if (!applied || !splitterLayoutsEqual(applied, next)) {
4162
+ write(before);
4163
+ cyclePending.current = false;
4164
+ finish();
4165
+ return;
4166
+ }
4167
+ current.onResize?.(pixels(applied));
4168
+ requestAnimationFrame(() => {
4169
+ if (!mounted.current || cycleToken.current !== token) return;
4170
+ if (initial.current === snapshot && splitterLayoutsEqual(layout.current, applied))
4171
+ phases.current.set(key, phase);
4172
+ cyclePending.current = false;
4173
+ reportCollapse();
4174
+ finish();
4175
+ const queued = queuedCycle.current;
4176
+ queuedCycle.current = null;
4177
+ if (queued && queued.topology === JSON.stringify(latest.current.ids)) {
4178
+ cycleHandler.current(queued.boundary);
4179
+ }
4180
+ });
4181
+ };
4182
+ cycleHandler.current = cycle;
4183
+ const horizontal = orientation === "horizontal";
4184
+ return /* @__PURE__ */ jsx14(
4185
+ Group,
4186
+ {
4187
+ ...native,
4188
+ orientation,
4189
+ disabled,
4190
+ resizePreviewMode: lazy ? "separator" : "panel",
4191
+ groupRef: group,
4192
+ elementRef: element,
4193
+ className: cn("mt-splitter", className),
4194
+ style: { ...style, position: "relative" },
4195
+ "data-orientation": orientation,
4196
+ onPointerDownCapture: (e) => {
4197
+ onPointerDownCapture?.(e);
4198
+ if (e.button !== 0 || disabled || e.target.closest("[data-group]") !== element.current)
4199
+ return;
4200
+ const el = element.current;
4201
+ const radius = e.pointerType === "touch" ? 10 : 5;
4202
+ const target = Array.from(el?.children ?? []).find((node) => {
4203
+ if (!node.hasAttribute("data-separator") || node.getAttribute("aria-disabled") === "true")
4204
+ return false;
4205
+ const r = node.getBoundingClientRect();
4206
+ return horizontal ? Math.abs(e.clientX - (r.left + r.width / 2)) <= radius && e.clientY >= r.top && e.clientY <= r.bottom : Math.abs(e.clientY - (r.top + r.height / 2)) <= radius && e.clientX >= r.left && e.clientX <= r.right;
4207
+ });
4208
+ if (target) {
4209
+ begin(
4210
+ e.pointerId,
4211
+ e.pointerType,
4212
+ Number(target.getAttribute("data-boundary"))
4213
+ );
4214
+ if (e.pointerType === "touch" && session.current?.pointerId === e.pointerId)
4215
+ touchDown.current = {
4216
+ boundary: Number(target.getAttribute("data-boundary")),
4217
+ x: e.clientX,
4218
+ y: e.clientY,
4219
+ time: performance.now(),
4220
+ pointerId: e.pointerId,
4221
+ moved: false
4222
+ };
4223
+ }
4224
+ },
4225
+ onPointerMoveCapture: (e) => {
4226
+ onPointerMoveCapture?.(e);
4227
+ const down = touchDown.current;
4228
+ if (down?.pointerId === e.pointerId && Math.hypot(e.clientX - down.x, e.clientY - down.y) > 8)
4229
+ down.moved = true;
4230
+ },
4231
+ onPointerCancelCapture: (e) => {
4232
+ onPointerCancelCapture?.(e);
4233
+ if (touchDown.current?.pointerId === e.pointerId) {
4234
+ touchDown.current = null;
4235
+ touchTap.current = null;
4236
+ }
4237
+ },
4238
+ onPointerUpCapture: (e) => {
4239
+ onPointerUpCapture?.(e);
4240
+ const down = touchDown.current;
4241
+ if (!down || down.pointerId !== e.pointerId) return;
4242
+ touchDown.current = null;
4243
+ const now = performance.now();
4244
+ if (down.moved || now - down.time > 350 || Math.hypot(e.clientX - down.x, e.clientY - down.y) > 8) {
4245
+ touchTap.current = null;
4246
+ return;
4247
+ }
4248
+ const prior = touchTap.current;
4249
+ if (prior && prior.boundary === down.boundary && now - prior.time < 350 && Math.hypot(e.clientX - prior.x, e.clientY - prior.y) < 24) {
4250
+ touchTap.current = null;
4251
+ lastTouchCycle.current = now;
4252
+ finish();
4253
+ onDraggerDoubleClick?.(down.boundary);
4254
+ cycle(down.boundary);
4255
+ } else
4256
+ touchTap.current = {
4257
+ boundary: down.boundary,
4258
+ x: e.clientX,
4259
+ y: e.clientY,
4260
+ time: now
4261
+ };
4262
+ },
4263
+ onKeyDownCapture: (e) => {
4264
+ onKeyDownCapture?.(e);
4265
+ if (!e.defaultPrevented && resizeKeys.has(e.key) && e.target.hasAttribute("data-separator") && e.target.parentElement === element.current && e.target.getAttribute("aria-disabled") !== "true") {
4266
+ if (e.key === "Enter") {
4267
+ e.preventDefault();
4268
+ e.stopPropagation();
4269
+ if (!e.repeat)
4270
+ cycle(
4271
+ Number(e.target.getAttribute("data-boundary"))
4272
+ );
4273
+ return;
4274
+ }
4275
+ const boundary = Number(
4276
+ e.target.getAttribute("data-boundary")
4277
+ );
4278
+ phases.current.delete(
4279
+ JSON.stringify([ids[boundary], ids[boundary + 1]])
4280
+ );
4281
+ begin(void 0, void 0, boundary);
4282
+ const activeSession = session.current;
4283
+ requestAnimationFrame(() => {
4284
+ if (mounted.current && session.current === activeSession) {
4285
+ reportCollapse();
4286
+ finish();
4287
+ }
4288
+ });
4289
+ }
4290
+ },
4291
+ onLayoutChange: (next) => {
4292
+ if (!latest.current.ids.every((id) => next[id] !== void 0)) return;
4293
+ layout.current = next;
4294
+ setView(next);
4295
+ if (!suppress.current && session.current && !session.current.cancelled) {
4296
+ if (!cyclePending.current && session.current.boundary !== void 0) {
4297
+ const boundary = session.current.boundary;
4298
+ phases.current.delete(
4299
+ JSON.stringify([
4300
+ latest.current.ids[boundary],
4301
+ latest.current.ids[boundary + 1]
4302
+ ])
4303
+ );
4304
+ }
4305
+ latest.current.onResize?.(pixels(next));
4306
+ }
4307
+ },
4308
+ onLayoutChanged: (next, meta) => {
4309
+ if (!latest.current.ids.every((id) => next[id] !== void 0)) return;
4310
+ layout.current = next;
4311
+ if (!suppress.current) {
4312
+ if (meta.isUserInteraction && session.current?.pointerId === void 0) {
4313
+ const activeSession = session.current;
4314
+ requestAnimationFrame(() => {
4315
+ if (mounted.current && session.current === activeSession) {
4316
+ reportCollapse();
4317
+ finish();
4318
+ }
4319
+ });
4320
+ } else if (!session.current) reportCollapse();
4321
+ }
4322
+ },
4323
+ children: panels.flatMap((child, i) => {
4324
+ const {
4325
+ id: _,
4326
+ label,
4327
+ defaultSize,
4328
+ min,
4329
+ max,
4330
+ resizable = true,
4331
+ collapsible = false,
4332
+ collapsedSize = 0,
4333
+ groupResizeBehavior,
4334
+ children: panelChildren,
4335
+ ...p
4336
+ } = child.props;
4337
+ const id = ids[i];
4338
+ const content = /* @__PURE__ */ createElement(
4339
+ ResizablePanel,
4340
+ {
4341
+ ...p,
4342
+ key: id,
4343
+ id,
4344
+ "aria-label": label ?? p["aria-label"],
4345
+ panelRef: (api) => {
4346
+ if (api) panelRefs.current.set(id, api);
4347
+ else panelRefs.current.delete(id);
4348
+ },
4349
+ defaultSize,
4350
+ minSize: min ?? (collapsible ? "10%" : 0),
4351
+ maxSize: max,
4352
+ disabled: !resizable,
4353
+ collapsible,
4354
+ collapsedSize,
4355
+ groupResizeBehavior,
4356
+ className: cn("mt-splitter-panel", p.className)
4357
+ },
4358
+ /* @__PURE__ */ jsx14(
4359
+ "div",
4360
+ {
4361
+ className: "mt-splitter-content",
4362
+ inert: view[id] === 0,
4363
+ "aria-hidden": view[id] === 0 || void 0,
4364
+ children: panelChildren
4365
+ }
4366
+ )
4367
+ );
4368
+ return i === panels.length - 1 ? [content] : [
4369
+ content,
4370
+ /* @__PURE__ */ jsx14(
4371
+ Separator,
4372
+ {
4373
+ id: `${id}-separator`,
4374
+ className: "mt-splitter-separator",
4375
+ "data-boundary": i,
4376
+ disableDoubleClick: true,
4377
+ "aria-description": locale === "zh" ? "\u53CC\u51FB\u3001\u89E6\u5C4F\u53CC\u51FB\u6216\u6309 Enter \u5FAA\u73AF\u6536\u8D77\u76F8\u90BB\u9762\u677F\u4E0E\u6062\u590D\u521D\u59CB\u6BD4\u4F8B" : "Double-click, double-tap, or press Enter to cycle adjacent panel collapse and initial proportions",
4378
+ disabled: disabled || !resizable || panels[i + 1].props.resizable === false,
4379
+ "aria-label": locale === "zh" ? `\u8C03\u6574\u5206\u680F ${i + 1}` : `Resize panels ${i + 1}`,
4380
+ onDoubleClick: () => {
4381
+ if (performance.now() - lastTouchCycle.current < 700) return;
4382
+ onDraggerDoubleClick?.(i);
4383
+ cycle(i);
4384
+ },
4385
+ children: /* @__PURE__ */ jsx14("span", { className: "mt-splitter-grip", "aria-hidden": "true" })
4386
+ },
4387
+ `${id}-separator`
4388
+ )
4389
+ ];
4390
+ })
4391
+ }
4392
+ );
4393
+ }
4394
+ var Splitter = Object.assign(SplitterRoot, { Panel: SplitterPanel });
1864
4395
  export {
1865
4396
  Alert,
1866
4397
  Avatar,
@@ -1874,6 +4405,7 @@ export {
1874
4405
  ConfirmDialog,
1875
4406
  ContextMenu,
1876
4407
  DatePicker,
4408
+ Dialog,
1877
4409
  Divider,
1878
4410
  DocumentCard,
1879
4411
  DocumentList,
@@ -1910,11 +4442,12 @@ export {
1910
4442
  Skeleton,
1911
4443
  Slider,
1912
4444
  Spinner,
4445
+ Splitter,
4446
+ Spotlight,
1913
4447
  Status,
1914
4448
  Switch,
1915
4449
  Table,
1916
4450
  Tabs,
1917
- Tag,
1918
4451
  Text,
1919
4452
  Textarea,
1920
4453
  Toast,