@bixlab/mtone 0.6.0 → 0.8.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/README.md +2 -2
- package/dist/index.d.ts +43 -7
- package/dist/index.js +225 -20
- package/dist/styles.css +1 -1
- package/llms.txt +57 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ import { MtoneProvider, Button, Select } from '@bixlab/mtone';
|
|
|
13
13
|
import '@bixlab/mtone/styles.css';
|
|
14
14
|
|
|
15
15
|
export function App() {
|
|
16
|
-
return <MtoneProvider locale="zh"
|
|
16
|
+
return <MtoneProvider locale="zh">
|
|
17
17
|
<Button variant="solid">新建</Button>
|
|
18
18
|
<Select label="知识库" options={[{value:'notes',label:'研究笔记'}]} />
|
|
19
19
|
</MtoneProvider>;
|
|
@@ -38,7 +38,7 @@ Node 24 recommended. The documentation app lives in `apps/docs`; its static buil
|
|
|
38
38
|
|
|
39
39
|
Buttons, forms, selection controls, navigation, directory tree, tabs, menus, lists, table, status and property displays, dialogs/drawers, feedback and upload. No block editor or backend. See [API](https://github.com/xingjianxu/mtone/blob/master/docs/API.md), [coverage](https://github.com/xingjianxu/mtone/blob/master/docs/COVERAGE.md) and [verification](https://github.com/xingjianxu/mtone/blob/master/docs/VERIFICATION.md).
|
|
40
40
|
|
|
41
|
-
Default style: text #37352F, muted #787774, border #E9E9E7, subtle surface #F7F7F5, white canvas, 14px text,
|
|
41
|
+
Default style: text #37352F, muted #787774, border #E9E9E7, subtle surface #F7F7F5, white canvas, 14px text, 34px standard controls, 4px radius. CSS is precompiled, prefixed and contains no Tailwind Preflight. Existing applications remain light by default. Since 0.7.0, set `theme="dark"` or `theme="system"` on `MtoneProvider`; system mode follows the operating system without reloading. `MtoneScope` can override the mode locally and mtone popups follow their trigger context. The library leaves preference storage to the application. To migrate from the two density modes, remove the `density` prop from `MtoneProvider`; explicit component size options are unchanged.
|
|
42
42
|
|
|
43
43
|
## License
|
|
44
44
|
|
package/dist/index.d.ts
CHANGED
|
@@ -682,27 +682,40 @@ interface ListProps<T = unknown> extends Omit<React__default.HTMLAttributes<HTML
|
|
|
682
682
|
ref?: React__default.Ref<ListHandle>;
|
|
683
683
|
}
|
|
684
684
|
/** Compact native list, with optional grouped and windowed data rendering. */
|
|
685
|
-
declare function
|
|
685
|
+
declare function ListRoot<T = unknown>({ children, items, getKey, renderItem, groupBy, renderGroup, stickyGroups, height, contentWidth, virtual, estimatedItemHeight, estimatedGroupHeight, overscan, hoverable, emptyContent, loading, loadingContent, onEndReached, endThreshold, ref, className, style, onScroll, ...props }: ListProps<T>): React__default.JSX.Element;
|
|
686
|
+
/** Drag grip for a controlled sortable list. Supply keyboard reordering separately. */
|
|
687
|
+
type ListSortHandleProps = Omit<React__default.HTMLAttributes<HTMLSpanElement>, "children" | "draggable">;
|
|
688
|
+
declare function ListSortHandle({ className, title, ...props }: ListSortHandleProps): React__default.JSX.Element;
|
|
686
689
|
interface ListItemProps extends React__default.LiHTMLAttributes<HTMLLIElement> {
|
|
690
|
+
sortHandle?: ListSortHandleProps;
|
|
687
691
|
icon?: React__default.ReactNode;
|
|
688
692
|
description?: React__default.ReactNode;
|
|
689
693
|
actions?: React__default.ReactNode;
|
|
690
694
|
}
|
|
691
|
-
declare function ListItem({ children, icon, description, actions, ...props }: ListItemProps): React__default.JSX.Element;
|
|
695
|
+
declare function ListItem({ children, sortHandle, icon, description, actions, ...props }: ListItemProps): React__default.JSX.Element;
|
|
696
|
+
declare const List: typeof ListRoot & {
|
|
697
|
+
SortHandle: typeof ListSortHandle;
|
|
698
|
+
};
|
|
692
699
|
|
|
693
700
|
declare const cn: (...v: (string | false | null | undefined)[]) => string;
|
|
694
701
|
type Locale = "zh" | "en";
|
|
695
702
|
type Tokens = React.CSSProperties & Record<`--mt-${string}`, string | number>;
|
|
703
|
+
type MtoneTheme = "light" | "dark" | "system";
|
|
696
704
|
type Context = {
|
|
705
|
+
theme: MtoneTheme;
|
|
697
706
|
locale: Locale;
|
|
698
|
-
density: "compact" | "comfortable";
|
|
699
707
|
tokens?: Tokens;
|
|
700
708
|
};
|
|
701
709
|
declare const useMtone: () => Context;
|
|
702
|
-
|
|
703
|
-
|
|
710
|
+
interface MtoneScopeProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
711
|
+
/** Inherits the surrounding mtone theme when omitted. */
|
|
712
|
+
theme?: MtoneTheme;
|
|
713
|
+
}
|
|
714
|
+
declare function MtoneScope({ children, className, style, theme, ...props }: MtoneScopeProps): React.JSX.Element;
|
|
715
|
+
type MtoneProviderProps = Partial<Context> & {
|
|
704
716
|
children: React.ReactNode;
|
|
705
|
-
}
|
|
717
|
+
};
|
|
718
|
+
declare function MtoneProvider({ children, locale, tokens, theme, }: MtoneProviderProps): React.JSX.Element;
|
|
706
719
|
type ButtonProps = Omit<React.ComponentPropsWithoutRef<typeof Button$1>, "className"> & {
|
|
707
720
|
className?: string;
|
|
708
721
|
variant?: "blue" | "solid" | "outline" | "soft" | "ghost";
|
|
@@ -2016,4 +2029,27 @@ type TreeSelectProps = TreeSelectCommonProps & ({
|
|
|
2016
2029
|
});
|
|
2017
2030
|
declare const TreeSelect: React.ForwardRefExoticComponent<TreeSelectProps & React.RefAttributes<HTMLButtonElement>>;
|
|
2018
2031
|
|
|
2019
|
-
|
|
2032
|
+
interface TagSelectOption {
|
|
2033
|
+
value: string;
|
|
2034
|
+
label: React.ReactNode;
|
|
2035
|
+
disabled?: boolean;
|
|
2036
|
+
}
|
|
2037
|
+
interface TagSelectProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "children" | "onChange"> {
|
|
2038
|
+
options: readonly TagSelectOption[];
|
|
2039
|
+
value?: readonly string[];
|
|
2040
|
+
defaultValue?: readonly string[];
|
|
2041
|
+
onValueChange?: (value: string[]) => void;
|
|
2042
|
+
disabled?: boolean;
|
|
2043
|
+
selectAll?: boolean;
|
|
2044
|
+
selectAllLabel?: string;
|
|
2045
|
+
expandable?: boolean;
|
|
2046
|
+
expanded?: boolean;
|
|
2047
|
+
defaultExpanded?: boolean;
|
|
2048
|
+
onExpandedChange?: (expanded: boolean) => void;
|
|
2049
|
+
expandLabel?: string;
|
|
2050
|
+
collapseLabel?: string;
|
|
2051
|
+
}
|
|
2052
|
+
/** An inline group of multi-select tags with optional responsive row disclosure. */
|
|
2053
|
+
declare function TagSelect({ options, value, defaultValue, onValueChange, disabled, selectAll, selectAllLabel, expandable, expanded, defaultExpanded, onExpandedChange, expandLabel, collapseLabel, className, ...props }: TagSelectProps): React.JSX.Element;
|
|
2054
|
+
|
|
2055
|
+
export { AdminLayout, type AdminLayoutContentProps, type AdminLayoutHeaderProps, type AdminLayoutProps, type AdminLayoutSiderProps, Affix, type AffixProps, Alert, AutoComplete, type AutoCompleteGroup, type AutoCompleteOption, type AutoCompleteProps, Avatar, type AvatarBreakpoint, AvatarGroup, type AvatarGroupProps, type AvatarProps, type AvatarSize, Badge, Blockquote, type BlockquoteProps, Breadcrumb, type BreadcrumbItem, type BreadcrumbProps, Button, ButtonGroup, type ButtonGroupProps, type ButtonProps, Calendar, type CalendarCellInfo, type CalendarHeaderInfo, type CalendarMode, type CalendarProps, type CalendarSelectInfo, type CalendarSemanticSlot, Card, type CardGridProps, type CardMetaProps, type CardMetaSemantic, type CardProps, type CardSemantic, type CardTabItem, type CardTokens, Cascader, type CascaderKey, type CascaderOption, CascaderPanel, type CascaderPanelProps, type CascaderPath, type CascaderProps, Checkbox, type CheckboxProps, ConfirmDialog, type ConfirmDialogProps, ContextMenu, DatePicker, type DatePickerProps, Dialog, type DialogProps, DirectoryTree, Divider, type DividerProps, DocumentCard, type DocumentItem, DocumentList, Drawer, Dropdown, type DropdownAlign, type DropdownLayoutProps, DropdownMenu, type DropdownMenuProps, type DropdownProps, Dropzone, Empty, Fieldset, type FieldsetProps, FilterBar, FilterChip, Form, FormField, type FormFieldProps, type FormInstance, type FormProps, type FormRule, type FormValidateTrigger, type FormValidationError, type FormValues, HoverCard, type HoverCardProps, IconButton, Image, ImageGroup, type ImageGroupProps, type ImageItem, ImagePreview, type ImagePreviewProps, type ImageProps, Input, type InputControlSize, type InputOTPProps, type InputPasswordProps, type InputProps, type InputSearchProps, type InputTextAreaProps, type InputVariant, Link, type LinkProps, List, type ListHandle, ListItem, type ListItemProps, type ListProps, type ListScrollTarget, type ListSortHandleProps, LoadingOverlay, type LoadingOverlayProps, type Locale, Mention, type MentionOption, Mentions, type MentionsProps, type MentionsRef, type MentionsSemantic, Menu, type MenuCheckboxItem, type MenuDivider, type MenuEntry, type MenuGroup, type MenuItem, type MenuProps, type MenuRadioGroup, Menubar, type MenubarMenu, type MenubarProps, Modal, type ModalProps, MtoneProvider, type MtoneProviderProps, MtoneScope, type MtoneScopeProps, type MtoneTheme, MultiSelect, type MultiSelectProps, NavGroup, NavItem, NumberInput, type NumberInputProps, type OpenProps, type Option, Pagination, type PaginationProps, Paragraph, type ParagraphProps, Popconfirm, type PopconfirmPlacement, type PopconfirmProps, Popover, type PopoverProps, Progress, type ProgressColor, type ProgressProps, type ProgressStatus, type ProgressType, PropertyItem, PropertyList, RadioGroup, type RadioGroupProps, Rate, type RateCharacterInfo, type RateProps, Result, type ResultProps, type ResultSemantic, type ResultStatus, SearchInput, Segmented, Select, type SelectProps, Sidebar, type SidebarProps, Skeleton, Slider, type SliderProps, type SortOrder, Spinner, Splitter, type SplitterPanelProps, type SplitterProps, type SplitterSize, Spotlight, type SpotlightAction, type SpotlightProps, Status, Switch, type TabItem, Table, type TableClassNames, type TableColumn, type TableColumnTitleProps, type TableColumnsType, type TableExpandableConfig, type TableFilterDropdownProps, type TableFilterItem, type TableFilterValue, type TableFilters, type TableLocale, TableOfContents, type TableOfContentsHandle, type TableOfContentsItem, type TableOfContentsProps, type TablePagination, type TableProps, type TableRef, type TableRowSelection, type TableSelectionType, type TableSortResult, type TableState, type TableStyles, Tabs, type TabsProps, TagSelect, type TagSelectOption, type TagSelectProps, Text, type TextProps, Textarea, Timeline, type TimelineItem, type TimelinePlacement, type TimelineProps, type TimelineSemantic, Title, type TitleProps, Toast, type ToastOptions, type ToastPosition, type ToastPromiseOptions, ToastProvider, type ToastProviderProps, type ToastType, type ToastUpdateOptions, type Tokens, type Tone, Tooltip, Transfer, type TransferDirection, type TransferItem, type TransferListContext, type TransferProps, Tree, type TreeCheckedKeys, type TreeDropInfo, type TreeItem, type TreeKey, type TreeNode, type TreeNodeInfo, type TreeProps, type TreeRef, TreeSelect, type TreeSelectCommonProps, type TreeSelectProps, Typography, type TypographyCopyable, type TypographyEditable, type TypographyEllipsis, type TypographyTone, Upload, type UploadAdapter, type UploadContext, type UploadFile, type UploadProps, cn, getMentions, useMtone, useToast };
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
useRef,
|
|
11
11
|
useState
|
|
12
12
|
} from "react";
|
|
13
|
+
import { GripVertical } from "lucide-react";
|
|
13
14
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
14
15
|
var identity = (key) => `${typeof key}:${String(key)}`;
|
|
15
16
|
var positive = (value, fallback) => Number.isFinite(value) && value > 0 ? value : fallback;
|
|
@@ -23,11 +24,12 @@ function MeasuredRow({
|
|
|
23
24
|
id,
|
|
24
25
|
measure,
|
|
25
26
|
children,
|
|
27
|
+
measureChild = false,
|
|
26
28
|
...props
|
|
27
29
|
}) {
|
|
28
30
|
const ref = useRef(null);
|
|
29
31
|
useLayoutEffect(() => {
|
|
30
|
-
const element = ref.current;
|
|
32
|
+
const element = measureChild ? ref.current?.firstElementChild : ref.current;
|
|
31
33
|
if (!element) return;
|
|
32
34
|
const update = () => measure(id, element.getBoundingClientRect().height);
|
|
33
35
|
update();
|
|
@@ -35,10 +37,10 @@ function MeasuredRow({
|
|
|
35
37
|
const observer = new ResizeObserver(update);
|
|
36
38
|
observer.observe(element);
|
|
37
39
|
return () => observer.disconnect();
|
|
38
|
-
}, [id, measure]);
|
|
40
|
+
}, [id, measure, measureChild]);
|
|
39
41
|
return /* @__PURE__ */ jsx("li", { ...props, ref, children });
|
|
40
42
|
}
|
|
41
|
-
function
|
|
43
|
+
function ListRoot({
|
|
42
44
|
children,
|
|
43
45
|
items,
|
|
44
46
|
getKey,
|
|
@@ -189,7 +191,7 @@ function List({
|
|
|
189
191
|
(i) => layout.offsets[i].top <= top
|
|
190
192
|
);
|
|
191
193
|
if (active !== void 0 && !indices.includes(active))
|
|
192
|
-
indices.
|
|
194
|
+
indices.unshift(active);
|
|
193
195
|
}
|
|
194
196
|
return indices;
|
|
195
197
|
}, [
|
|
@@ -312,10 +314,30 @@ function List({
|
|
|
312
314
|
const row = rows[index];
|
|
313
315
|
const group = row.kind === "group";
|
|
314
316
|
const nextGroup = group ? nextGroups.get(index) : void 0;
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
nextGroup === void 0 ?
|
|
318
|
-
|
|
317
|
+
if (windowed && stickyGroups && row.kind === "group") {
|
|
318
|
+
const start = layout.offsets[index].top;
|
|
319
|
+
const end = nextGroup === void 0 ? layout.total : layout.offsets[nextGroup].top;
|
|
320
|
+
return /* @__PURE__ */ jsx(
|
|
321
|
+
MeasuredRow,
|
|
322
|
+
{
|
|
323
|
+
id: row.id,
|
|
324
|
+
measure,
|
|
325
|
+
measureChild: true,
|
|
326
|
+
role: "presentation",
|
|
327
|
+
className: "mt-list-group-boundary",
|
|
328
|
+
style: { top: start, height: end - start, minWidth: contentWidth },
|
|
329
|
+
children: /* @__PURE__ */ jsx(
|
|
330
|
+
"div",
|
|
331
|
+
{
|
|
332
|
+
className: "mt-list-group mt-list-group-sticky",
|
|
333
|
+
"data-list-group": String(row.key),
|
|
334
|
+
children: renderGroup?.(row.key, row.items) ?? String(row.key)
|
|
335
|
+
}
|
|
336
|
+
)
|
|
337
|
+
},
|
|
338
|
+
row.id
|
|
339
|
+
);
|
|
340
|
+
}
|
|
319
341
|
return /* @__PURE__ */ jsx(
|
|
320
342
|
MeasuredRow,
|
|
321
343
|
{
|
|
@@ -332,7 +354,7 @@ function List({
|
|
|
332
354
|
),
|
|
333
355
|
style: {
|
|
334
356
|
minWidth: contentWidth,
|
|
335
|
-
...windowed ? { position: "absolute", top:
|
|
357
|
+
...windowed ? { position: "absolute", top: layout.offsets[index].top, width: "100%" } : {}
|
|
336
358
|
},
|
|
337
359
|
children: row.kind === "group" ? renderGroup?.(row.key, row.items) ?? String(row.key) : renderItem ? renderItem(row.item, row.index) : String(row.item ?? "")
|
|
338
360
|
},
|
|
@@ -345,14 +367,19 @@ function List({
|
|
|
345
367
|
}
|
|
346
368
|
);
|
|
347
369
|
}
|
|
370
|
+
function ListSortHandle({ className, title = "\u62D6\u52A8\u6392\u5E8F", ...props }) {
|
|
371
|
+
return /* @__PURE__ */ jsx("span", { ...props, title, "aria-hidden": "true", draggable: true, className: cn("mt-list-sort-handle", className), children: /* @__PURE__ */ jsx(GripVertical, { size: 16, focusable: "false" }) });
|
|
372
|
+
}
|
|
348
373
|
function ListItem({
|
|
349
374
|
children,
|
|
375
|
+
sortHandle,
|
|
350
376
|
icon,
|
|
351
377
|
description,
|
|
352
378
|
actions,
|
|
353
379
|
...props
|
|
354
380
|
}) {
|
|
355
381
|
return /* @__PURE__ */ jsxs("li", { ...props, className: cn("mt-list-item", props.className), children: [
|
|
382
|
+
sortHandle && /* @__PURE__ */ jsx(ListSortHandle, { ...sortHandle }),
|
|
356
383
|
icon,
|
|
357
384
|
/* @__PURE__ */ jsxs("div", { className: "mt-list-content", children: [
|
|
358
385
|
/* @__PURE__ */ jsx("div", { children }),
|
|
@@ -361,6 +388,7 @@ function ListItem({
|
|
|
361
388
|
actions
|
|
362
389
|
] });
|
|
363
390
|
}
|
|
391
|
+
var List = Object.assign(ListRoot, { SortHandle: ListSortHandle });
|
|
364
392
|
|
|
365
393
|
// src/fieldset-context.ts
|
|
366
394
|
import * as React2 from "react";
|
|
@@ -3641,36 +3669,47 @@ import { jsx as jsx14, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
|
3641
3669
|
var cn = (...v) => v.filter(Boolean).join(" ");
|
|
3642
3670
|
var MtoneContext = React15.createContext({
|
|
3643
3671
|
locale: "zh",
|
|
3644
|
-
|
|
3672
|
+
theme: "light"
|
|
3645
3673
|
});
|
|
3646
3674
|
var useMtone = () => React15.useContext(MtoneContext);
|
|
3647
3675
|
function MtoneScope({
|
|
3648
3676
|
children,
|
|
3649
3677
|
className,
|
|
3650
3678
|
style,
|
|
3679
|
+
theme,
|
|
3651
3680
|
...props
|
|
3652
3681
|
}) {
|
|
3653
|
-
const
|
|
3682
|
+
const inherited = useMtone();
|
|
3683
|
+
const c = React15.useMemo(
|
|
3684
|
+
() => theme && theme !== inherited.theme ? { ...inherited, theme } : inherited,
|
|
3685
|
+
[inherited, theme]
|
|
3686
|
+
);
|
|
3654
3687
|
const floatingOwners = React15.useContext(FloatingOwnerContext);
|
|
3655
3688
|
return /* @__PURE__ */ jsx14(
|
|
3656
3689
|
"div",
|
|
3657
3690
|
{
|
|
3658
3691
|
...props,
|
|
3659
3692
|
className: cn("mt-scope", className),
|
|
3660
|
-
"data-
|
|
3693
|
+
"data-mt-theme": c.theme,
|
|
3661
3694
|
"data-mt-floating-owners": floatingOwners.length ? floatingOwners.join(" ") : void 0,
|
|
3662
3695
|
style: { ...c.tokens, ...style },
|
|
3663
|
-
children
|
|
3696
|
+
children: /* @__PURE__ */ jsx14(MtoneContext.Provider, { value: c, children })
|
|
3664
3697
|
}
|
|
3665
3698
|
);
|
|
3666
3699
|
}
|
|
3667
3700
|
function MtoneProvider({
|
|
3668
3701
|
children,
|
|
3669
3702
|
locale = "zh",
|
|
3670
|
-
|
|
3671
|
-
|
|
3703
|
+
tokens,
|
|
3704
|
+
theme
|
|
3672
3705
|
}) {
|
|
3673
|
-
|
|
3706
|
+
const inherited = useMtone();
|
|
3707
|
+
const resolvedTheme = theme ?? inherited.theme;
|
|
3708
|
+
const value = React15.useMemo(
|
|
3709
|
+
() => ({ locale, tokens, theme: resolvedTheme }),
|
|
3710
|
+
[locale, tokens, resolvedTheme]
|
|
3711
|
+
);
|
|
3712
|
+
return /* @__PURE__ */ jsx14(MtoneContext.Provider, { value, children: /* @__PURE__ */ jsx14(MtoneScope, { children }) });
|
|
3674
3713
|
}
|
|
3675
3714
|
var Button = React15.forwardRef(
|
|
3676
3715
|
function Button2({
|
|
@@ -3893,7 +3932,8 @@ function Sidebar({
|
|
|
3893
3932
|
var NavItem = React16.forwardRef(function NavItem2({ active, icon, children, className, ...p }, ref) {
|
|
3894
3933
|
const collapsed = React16.useContext(SidebarContext);
|
|
3895
3934
|
const [tipOpen, setTipOpen] = React16.useState(false);
|
|
3896
|
-
const
|
|
3935
|
+
const plainLabel = typeof children === "string" || typeof children === "number";
|
|
3936
|
+
const label = p["aria-label"] ?? (plainLabel ? String(children) : void 0);
|
|
3897
3937
|
const button = /* @__PURE__ */ jsxs14(
|
|
3898
3938
|
"button",
|
|
3899
3939
|
{
|
|
@@ -3909,7 +3949,7 @@ var NavItem = React16.forwardRef(function NavItem2({ active, icon, children, cla
|
|
|
3909
3949
|
),
|
|
3910
3950
|
children: [
|
|
3911
3951
|
icon || (collapsed ? /* @__PURE__ */ jsx15(Circle, { size: 16, "aria-hidden": "true" }) : null),
|
|
3912
|
-
collapsed ? /* @__PURE__ */ jsx15("span", { className: "mt-sidebar-sr-only", children }) : children
|
|
3952
|
+
collapsed ? /* @__PURE__ */ jsx15("span", { className: "mt-sidebar-sr-only", children }) : plainLabel ? /* @__PURE__ */ jsx15("span", { className: "mt-nav-item-label", children }) : children
|
|
3913
3953
|
]
|
|
3914
3954
|
}
|
|
3915
3955
|
);
|
|
@@ -7436,7 +7476,7 @@ var Mentions = React26.forwardRef(
|
|
|
7436
7476
|
...native
|
|
7437
7477
|
}, forwardedRef) {
|
|
7438
7478
|
disabled = useFieldsetDisabled(disabled);
|
|
7439
|
-
const { locale,
|
|
7479
|
+
const { locale, theme, tokens } = useMtone();
|
|
7440
7480
|
const inputRef = React26.useRef(null), popupRef = React26.useRef(null);
|
|
7441
7481
|
const [internal, setInternal] = React26.useState(defaultValue), text = controlled ?? internal;
|
|
7442
7482
|
const [focused, setFocused] = React26.useState(false), [composing, setComposing] = React26.useState(false), [dismissed, setDismissed] = React26.useState(false);
|
|
@@ -7614,7 +7654,7 @@ var Mentions = React26.forwardRef(
|
|
|
7614
7654
|
{
|
|
7615
7655
|
ref: popupRef,
|
|
7616
7656
|
className: cn("mt-scope", "mt-mentions-popup", classNames?.popup),
|
|
7617
|
-
"data-
|
|
7657
|
+
"data-mt-theme": theme,
|
|
7618
7658
|
style: {
|
|
7619
7659
|
...tokens,
|
|
7620
7660
|
...styles?.popup,
|
|
@@ -11256,6 +11296,170 @@ var TreeSelect = React41.forwardRef(
|
|
|
11256
11296
|
);
|
|
11257
11297
|
}
|
|
11258
11298
|
);
|
|
11299
|
+
|
|
11300
|
+
// src/tag-select.tsx
|
|
11301
|
+
import * as React42 from "react";
|
|
11302
|
+
import { ChevronDown as ChevronDown9 } from "lucide-react";
|
|
11303
|
+
import { jsx as jsx41, jsxs as jsxs37 } from "react/jsx-runtime";
|
|
11304
|
+
function TagSelect({
|
|
11305
|
+
options,
|
|
11306
|
+
value,
|
|
11307
|
+
defaultValue = [],
|
|
11308
|
+
onValueChange,
|
|
11309
|
+
disabled,
|
|
11310
|
+
selectAll = false,
|
|
11311
|
+
selectAllLabel = "\u5168\u9009",
|
|
11312
|
+
expandable = true,
|
|
11313
|
+
expanded,
|
|
11314
|
+
defaultExpanded = false,
|
|
11315
|
+
onExpandedChange,
|
|
11316
|
+
expandLabel = "\u5C55\u5F00",
|
|
11317
|
+
collapseLabel = "\u6536\u8D77",
|
|
11318
|
+
className,
|
|
11319
|
+
...props
|
|
11320
|
+
}) {
|
|
11321
|
+
const isDisabled = useFieldsetDisabled(disabled);
|
|
11322
|
+
const [internalValue, setInternalValue] = React42.useState(defaultValue);
|
|
11323
|
+
const [internalExpanded, setInternalExpanded] = React42.useState(defaultExpanded);
|
|
11324
|
+
const [visibleCount, setVisibleCount] = React42.useState(
|
|
11325
|
+
options.length + Number(selectAll)
|
|
11326
|
+
);
|
|
11327
|
+
const [overflow, setOverflow] = React42.useState(false);
|
|
11328
|
+
const isExpanded = expanded ?? internalExpanded;
|
|
11329
|
+
const selected = new Set(value ?? internalValue);
|
|
11330
|
+
const enabledValues = selectAll ? options.filter((option) => !option.disabled).map((option) => option.value) : [];
|
|
11331
|
+
const selectedEnabled = enabledValues.filter(
|
|
11332
|
+
(item) => selected.has(item)
|
|
11333
|
+
).length;
|
|
11334
|
+
const allSelected = enabledValues.length > 0 && selectedEnabled === enabledValues.length;
|
|
11335
|
+
const commitSelection = (next) => {
|
|
11336
|
+
if (value === void 0) setInternalValue(next);
|
|
11337
|
+
onValueChange?.(next);
|
|
11338
|
+
};
|
|
11339
|
+
const list = React42.useRef(null);
|
|
11340
|
+
const trigger = React42.useRef(null);
|
|
11341
|
+
const id = React42.useId();
|
|
11342
|
+
React42.useLayoutEffect(() => {
|
|
11343
|
+
const row = list.current;
|
|
11344
|
+
if (!row || !expandable) return;
|
|
11345
|
+
const update = () => {
|
|
11346
|
+
const first = row.firstElementChild;
|
|
11347
|
+
if (!first) {
|
|
11348
|
+
setVisibleCount(0);
|
|
11349
|
+
setOverflow(false);
|
|
11350
|
+
return;
|
|
11351
|
+
}
|
|
11352
|
+
const at = first.offsetTop;
|
|
11353
|
+
const children = Array.from(row.children);
|
|
11354
|
+
const available = row.parentElement?.parentElement?.clientWidth ?? 0;
|
|
11355
|
+
setOverflow(
|
|
11356
|
+
available > 0 && children.length > 1 && children.reduce((sum, child) => {
|
|
11357
|
+
const rectWidth = child.getBoundingClientRect().width;
|
|
11358
|
+
return sum + Math.min(
|
|
11359
|
+
available,
|
|
11360
|
+
child.scrollWidth > child.clientWidth ? child.scrollWidth + 2 : rectWidth
|
|
11361
|
+
);
|
|
11362
|
+
}, 0) + (children.length - 1) * (parseFloat(getComputedStyle(row).columnGap) || 0) > available + 0.5
|
|
11363
|
+
);
|
|
11364
|
+
const next = children.findIndex((child) => child.offsetTop > at + 1);
|
|
11365
|
+
const count = next < 0 ? children.length : next;
|
|
11366
|
+
const focused = children.indexOf(document.activeElement);
|
|
11367
|
+
if (!isExpanded && focused >= count) {
|
|
11368
|
+
if (!isDisabled) trigger.current?.focus();
|
|
11369
|
+
else children.find((child) => !child.hasAttribute("disabled"))?.focus();
|
|
11370
|
+
}
|
|
11371
|
+
setVisibleCount(count);
|
|
11372
|
+
};
|
|
11373
|
+
update();
|
|
11374
|
+
if (typeof ResizeObserver === "undefined") {
|
|
11375
|
+
window.addEventListener("resize", update);
|
|
11376
|
+
return () => window.removeEventListener("resize", update);
|
|
11377
|
+
}
|
|
11378
|
+
const observer = new ResizeObserver(update);
|
|
11379
|
+
observer.observe(row);
|
|
11380
|
+
for (const child of row.children) observer.observe(child);
|
|
11381
|
+
return () => observer.disconnect();
|
|
11382
|
+
}, [options, expandable, isExpanded, isDisabled, selectAll, selectAllLabel]);
|
|
11383
|
+
const hasOverflow = expandable && overflow;
|
|
11384
|
+
return /* @__PURE__ */ jsxs37(
|
|
11385
|
+
"div",
|
|
11386
|
+
{
|
|
11387
|
+
role: "group",
|
|
11388
|
+
...props,
|
|
11389
|
+
className: ["mt-tag-select", className].filter(Boolean).join(" "),
|
|
11390
|
+
children: [
|
|
11391
|
+
/* @__PURE__ */ jsx41(
|
|
11392
|
+
"div",
|
|
11393
|
+
{
|
|
11394
|
+
className: "mt-tag-select-viewport",
|
|
11395
|
+
"data-collapsed": hasOverflow && !isExpanded ? "" : void 0,
|
|
11396
|
+
children: /* @__PURE__ */ jsxs37("div", { className: "mt-tag-select-options", id, ref: list, children: [
|
|
11397
|
+
selectAll && /* @__PURE__ */ jsx41(
|
|
11398
|
+
"button",
|
|
11399
|
+
{
|
|
11400
|
+
type: "button",
|
|
11401
|
+
className: "mt-tag-select-option",
|
|
11402
|
+
"aria-pressed": allSelected ? true : selectedEnabled > 0 ? "mixed" : false,
|
|
11403
|
+
disabled: isDisabled || enabledValues.length === 0,
|
|
11404
|
+
onClick: () => {
|
|
11405
|
+
const enabled = new Set(enabledValues);
|
|
11406
|
+
commitSelection(
|
|
11407
|
+
allSelected ? [...selected].filter((item) => !enabled.has(item)) : [.../* @__PURE__ */ new Set([...selected, ...enabledValues])]
|
|
11408
|
+
);
|
|
11409
|
+
},
|
|
11410
|
+
children: selectAllLabel
|
|
11411
|
+
}
|
|
11412
|
+
),
|
|
11413
|
+
options.map((option, index) => {
|
|
11414
|
+
const checked = selected.has(option.value);
|
|
11415
|
+
const hidden = hasOverflow && !isExpanded && index + Number(selectAll) >= visibleCount;
|
|
11416
|
+
return /* @__PURE__ */ jsx41(
|
|
11417
|
+
"button",
|
|
11418
|
+
{
|
|
11419
|
+
type: "button",
|
|
11420
|
+
className: "mt-tag-select-option",
|
|
11421
|
+
"aria-pressed": checked,
|
|
11422
|
+
"data-overflow": hidden ? "" : void 0,
|
|
11423
|
+
tabIndex: hidden ? -1 : void 0,
|
|
11424
|
+
disabled: isDisabled || option.disabled,
|
|
11425
|
+
onClick: () => {
|
|
11426
|
+
const next = checked ? Array.from(selected).filter(
|
|
11427
|
+
(item) => item !== option.value
|
|
11428
|
+
) : [...selected, option.value];
|
|
11429
|
+
commitSelection(next);
|
|
11430
|
+
},
|
|
11431
|
+
children: option.label
|
|
11432
|
+
},
|
|
11433
|
+
option.value
|
|
11434
|
+
);
|
|
11435
|
+
})
|
|
11436
|
+
] })
|
|
11437
|
+
}
|
|
11438
|
+
),
|
|
11439
|
+
expandable && /* @__PURE__ */ jsxs37(
|
|
11440
|
+
"button",
|
|
11441
|
+
{
|
|
11442
|
+
ref: trigger,
|
|
11443
|
+
hidden: !hasOverflow,
|
|
11444
|
+
className: "mt-tag-select-trigger",
|
|
11445
|
+
type: "button",
|
|
11446
|
+
"aria-controls": id,
|
|
11447
|
+
"aria-expanded": isExpanded,
|
|
11448
|
+
disabled: isDisabled,
|
|
11449
|
+
onClick: () => {
|
|
11450
|
+
if (expanded === void 0) setInternalExpanded(!isExpanded);
|
|
11451
|
+
onExpandedChange?.(!isExpanded);
|
|
11452
|
+
},
|
|
11453
|
+
children: [
|
|
11454
|
+
isExpanded ? collapseLabel : expandLabel,
|
|
11455
|
+
/* @__PURE__ */ jsx41(ChevronDown9, { size: 14, "aria-hidden": "true" })
|
|
11456
|
+
]
|
|
11457
|
+
}
|
|
11458
|
+
)
|
|
11459
|
+
]
|
|
11460
|
+
}
|
|
11461
|
+
);
|
|
11462
|
+
}
|
|
11259
11463
|
export {
|
|
11260
11464
|
AdminLayout,
|
|
11261
11465
|
Affix,
|
|
@@ -11336,6 +11540,7 @@ export {
|
|
|
11336
11540
|
Table,
|
|
11337
11541
|
TableOfContents,
|
|
11338
11542
|
Tabs,
|
|
11543
|
+
TagSelect,
|
|
11339
11544
|
Text,
|
|
11340
11545
|
Textarea,
|
|
11341
11546
|
Timeline,
|