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