@meta-1/design 0.0.159

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.
Files changed (99) hide show
  1. package/README.md +412 -0
  2. package/package.json +138 -0
  3. package/src/assets/icons/empty.svg +1 -0
  4. package/src/assets/icons/spin.svg +1 -0
  5. package/src/assets/locales/en-us.ts +74 -0
  6. package/src/assets/locales/zh-cn.ts +74 -0
  7. package/src/assets/locales/zh-tw.ts +74 -0
  8. package/src/assets/style/theme.css +173 -0
  9. package/src/components/icons/Empty.tsx +18 -0
  10. package/src/components/icons/Spin.tsx +16 -0
  11. package/src/components/icons/index.ts +2 -0
  12. package/src/components/ui/alert-dialog.tsx +111 -0
  13. package/src/components/ui/alert.tsx +49 -0
  14. package/src/components/ui/avatar.tsx +32 -0
  15. package/src/components/ui/badge.tsx +36 -0
  16. package/src/components/ui/breadcrumb.tsx +92 -0
  17. package/src/components/ui/button.tsx +52 -0
  18. package/src/components/ui/calendar.tsx +56 -0
  19. package/src/components/ui/card.tsx +56 -0
  20. package/src/components/ui/checkbox.tsx +28 -0
  21. package/src/components/ui/command.tsx +137 -0
  22. package/src/components/ui/dialog.tsx +127 -0
  23. package/src/components/ui/dropdown-menu.tsx +217 -0
  24. package/src/components/ui/form.tsx +138 -0
  25. package/src/components/ui/hover-card.tsx +36 -0
  26. package/src/components/ui/input-otp.tsx +66 -0
  27. package/src/components/ui/input.tsx +21 -0
  28. package/src/components/ui/label.tsx +21 -0
  29. package/src/components/ui/navigation-menu.tsx +142 -0
  30. package/src/components/ui/pagination.tsx +118 -0
  31. package/src/components/ui/popover.tsx +40 -0
  32. package/src/components/ui/progress.tsx +22 -0
  33. package/src/components/ui/radio-group.tsx +31 -0
  34. package/src/components/ui/resizable.tsx +46 -0
  35. package/src/components/ui/scroll-area.tsx +46 -0
  36. package/src/components/ui/select.tsx +158 -0
  37. package/src/components/ui/separator.tsx +26 -0
  38. package/src/components/ui/sheet.tsx +101 -0
  39. package/src/components/ui/skeleton.tsx +7 -0
  40. package/src/components/ui/sonner.tsx +23 -0
  41. package/src/components/ui/switch.tsx +26 -0
  42. package/src/components/ui/table.tsx +73 -0
  43. package/src/components/ui/tabs.tsx +40 -0
  44. package/src/components/ui/textarea.tsx +18 -0
  45. package/src/components/ui/tooltip.tsx +46 -0
  46. package/src/components/uix/action/index.tsx +37 -0
  47. package/src/components/uix/alert/index.tsx +43 -0
  48. package/src/components/uix/alert-dialog/index.tsx +109 -0
  49. package/src/components/uix/avatar/index.tsx +25 -0
  50. package/src/components/uix/breadcrumbs/index.tsx +38 -0
  51. package/src/components/uix/broadcast-channel-context/index.tsx +28 -0
  52. package/src/components/uix/button/index.tsx +29 -0
  53. package/src/components/uix/card/index.tsx +32 -0
  54. package/src/components/uix/checkbox/index.tsx +79 -0
  55. package/src/components/uix/checkbox-group/index.tsx +60 -0
  56. package/src/components/uix/combo-select/index.tsx +364 -0
  57. package/src/components/uix/config-provider/index.tsx +31 -0
  58. package/src/components/uix/data-table/index.tsx +491 -0
  59. package/src/components/uix/data-table/style.css +40 -0
  60. package/src/components/uix/date-picker/index.tsx +88 -0
  61. package/src/components/uix/date-range-picker/index.tsx +71 -0
  62. package/src/components/uix/dialog/index.tsx +70 -0
  63. package/src/components/uix/divider/index.tsx +23 -0
  64. package/src/components/uix/dropdown/index.tsx +117 -0
  65. package/src/components/uix/empty/index.tsx +29 -0
  66. package/src/components/uix/filters/index.tsx +105 -0
  67. package/src/components/uix/form/index.tsx +274 -0
  68. package/src/components/uix/image/index.tsx +13 -0
  69. package/src/components/uix/loading/index.tsx +24 -0
  70. package/src/components/uix/message/index.tsx +21 -0
  71. package/src/components/uix/pagination/index.tsx +180 -0
  72. package/src/components/uix/radio-group/index.tsx +35 -0
  73. package/src/components/uix/result/index.tsx +45 -0
  74. package/src/components/uix/select/index.tsx +93 -0
  75. package/src/components/uix/space/index.tsx +24 -0
  76. package/src/components/uix/spin/index.tsx +12 -0
  77. package/src/components/uix/steps/index.tsx +67 -0
  78. package/src/components/uix/switch/index.tsx +33 -0
  79. package/src/components/uix/tooltip/index.tsx +29 -0
  80. package/src/components/uix/tree/index.tsx +39 -0
  81. package/src/components/uix/tree/style.css +75 -0
  82. package/src/components/uix/tree-select/index.tsx +137 -0
  83. package/src/components/uix/tree-table/action.tsx +24 -0
  84. package/src/components/uix/tree-table/config.ts +2 -0
  85. package/src/components/uix/tree-table/index.tsx +86 -0
  86. package/src/components/uix/tree-table/utils.tsx +63 -0
  87. package/src/components/uix/uploader/index.tsx +237 -0
  88. package/src/components/uix/uploader/type.ts +20 -0
  89. package/src/components/uix/uploader/utils.ts +41 -0
  90. package/src/components/uix/value-formatter/index.tsx +59 -0
  91. package/src/hooks/index.ts +2 -0
  92. package/src/hooks/resize.ts +29 -0
  93. package/src/hooks/use.outside.ts +30 -0
  94. package/src/index.ts +159 -0
  95. package/src/lib/formatters.ts +13 -0
  96. package/src/lib/index.ts +4 -0
  97. package/src/lib/is.ts +6 -0
  98. package/src/lib/react-dom.ts +98 -0
  99. package/src/lib/utils.ts +39 -0
@@ -0,0 +1,29 @@
1
+ import { type RefObject, useCallback, useEffect, useState } from "react";
2
+
3
+ export interface Size {
4
+ width: number;
5
+ height: number;
6
+ }
7
+
8
+ export const useSize = (ref: RefObject<HTMLElement | null>) => {
9
+ const [size, setSize] = useState<Size>({ width: 0, height: 0 });
10
+
11
+ const resize = useCallback(() => {
12
+ setSize({
13
+ width: ref.current?.offsetWidth || 0,
14
+ height: ref.current?.offsetHeight || 0,
15
+ });
16
+ }, [ref]);
17
+
18
+ useEffect(() => {
19
+ const ro = new ResizeObserver(resize);
20
+ if (ref.current) {
21
+ ro.observe(ref.current);
22
+ }
23
+ return () => {
24
+ ro.disconnect();
25
+ };
26
+ }, [ref, resize]);
27
+
28
+ return size;
29
+ };
@@ -0,0 +1,30 @@
1
+ import { useEffect } from "react";
2
+
3
+ /**
4
+ * Hook that alerts clicks outside of the passed ref
5
+ */
6
+
7
+ // biome-ignore lint/suspicious/noExplicitAny: <refs>
8
+ export const useOutside = (call: () => void, refs: any) => {
9
+ useEffect(() => {
10
+ /**
11
+ * Alert if clicked on outside of element
12
+ */
13
+
14
+ // biome-ignore lint/suspicious/noExplicitAny: <event>
15
+ const handleClickOutside = (event: any) => {
16
+ if (!refs) return;
17
+ // biome-ignore lint/suspicious/noExplicitAny: <hit>
18
+ const hit = refs.filter((ref: any) => !ref.current.contains(event.target));
19
+ if (hit.length === refs.length) {
20
+ call();
21
+ }
22
+ };
23
+ // Bind the event listener
24
+ document.addEventListener("mousedown", handleClickOutside);
25
+ return () => {
26
+ // Unbind the event listener on clean up
27
+ document.removeEventListener("mousedown", handleClickOutside);
28
+ };
29
+ }, [refs, call]);
30
+ };
package/src/index.ts ADDED
@@ -0,0 +1,159 @@
1
+ // utils
2
+
3
+ export { toast } from "sonner";
4
+
5
+ export {
6
+ InputOTP,
7
+ InputOTPGroup,
8
+ InputOTPSeparator,
9
+ InputOTPSlot,
10
+ } from "@meta-1/design/components/ui/input-otp";
11
+ export { Badge } from "./components/ui/badge";
12
+ export {
13
+ Breadcrumb,
14
+ BreadcrumbItem,
15
+ BreadcrumbLink,
16
+ BreadcrumbList,
17
+ BreadcrumbPage,
18
+ BreadcrumbSeparator,
19
+ } from "./components/ui/breadcrumb";
20
+ export { Calendar } from "./components/ui/calendar";
21
+ export {
22
+ Command,
23
+ CommandEmpty,
24
+ CommandGroup,
25
+ CommandInput,
26
+ CommandItem,
27
+ CommandList,
28
+ CommandSeparator,
29
+ CommandShortcut,
30
+ } from "./components/ui/command";
31
+ export * from "./components/ui/dropdown-menu";
32
+ export {
33
+ HoverCard,
34
+ HoverCardContent,
35
+ HoverCardTrigger,
36
+ } from "./components/ui/hover-card";
37
+ export { Input } from "./components/ui/input";
38
+ export * from "./components/ui/navigation-menu";
39
+ export {
40
+ Popover,
41
+ PopoverContent,
42
+ PopoverTrigger,
43
+ } from "./components/ui/popover";
44
+ export { Progress } from "./components/ui/progress";
45
+ export {
46
+ RadioGroup,
47
+ RadioGroupItem,
48
+ } from "./components/ui/radio-group";
49
+ export {
50
+ ResizableHandle,
51
+ ResizablePanel,
52
+ ResizablePanelGroup,
53
+ } from "./components/ui/resizable";
54
+ export { ScrollArea, ScrollBar } from "./components/ui/scroll-area";
55
+ export { Separator } from "./components/ui/separator";
56
+ export {
57
+ Sheet,
58
+ SheetClose,
59
+ SheetContent,
60
+ SheetDescription,
61
+ SheetFooter,
62
+ SheetHeader,
63
+ SheetTitle,
64
+ SheetTrigger,
65
+ } from "./components/ui/sheet";
66
+ export { Skeleton } from "./components/ui/skeleton";
67
+ // base
68
+ export { Toaster } from "./components/ui/sonner";
69
+ export {
70
+ Table,
71
+ TableBody,
72
+ TableCaption,
73
+ TableCell,
74
+ TableFooter,
75
+ TableHead,
76
+ TableHeader,
77
+ TableRow,
78
+ } from "./components/ui/table";
79
+ export { Tabs, TabsContent, TabsList, TabsTrigger } from "./components/ui/tabs";
80
+ export { Textarea } from "./components/ui/textarea";
81
+ export type { ActionProps } from "./components/uix/action";
82
+ export { Action } from "./components/uix/action";
83
+ export type { AlertProps } from "./components/uix/alert";
84
+ // extend
85
+ export { Alert } from "./components/uix/alert";
86
+ export type { ConfirmProps } from "./components/uix/alert-dialog";
87
+ export { useAlert } from "./components/uix/alert-dialog";
88
+ export type { AvatarProps } from "./components/uix/avatar";
89
+ export { Avatar } from "./components/uix/avatar";
90
+ export type { BreadcrumbsItemProps, BreadcrumbsProps } from "./components/uix/breadcrumbs";
91
+ export { Breadcrumbs, BreadcrumbsItem } from "./components/uix/breadcrumbs";
92
+ export type { BroadcastChannelProviderProps } from "./components/uix/broadcast-channel-context";
93
+ export { BroadcastChannelProvider, useBroadcastChannel } from "./components/uix/broadcast-channel-context";
94
+ export type { ButtonProps } from "./components/uix/button";
95
+ export { Button } from "./components/uix/button";
96
+ export type { CardProps } from "./components/uix/card";
97
+ export { Card } from "./components/uix/card";
98
+ export type { CheckboxProps } from "./components/uix/checkbox";
99
+ export { Checkbox } from "./components/uix/checkbox";
100
+ export type { CheckboxGroupOptionProps, CheckboxGroupProps } from "./components/uix/checkbox-group";
101
+ export { CheckboxGroup } from "./components/uix/checkbox-group";
102
+ export type { ComboSelectOptionProps, ComboSelectProps } from "./components/uix/combo-select";
103
+ export { ComboSelect } from "./components/uix/combo-select";
104
+ export type { ConfigProviderProps } from "./components/uix/config-provider";
105
+ export { ConfigProvider } from "./components/uix/config-provider";
106
+ export type { DataTableColumn, DataTableProps } from "./components/uix/data-table";
107
+ export { DataTable } from "./components/uix/data-table";
108
+ export type { DatePickerProps } from "./components/uix/date-picker";
109
+ export { DatePicker } from "./components/uix/date-picker";
110
+ export type { DateRangePickerProps } from "./components/uix/date-range-picker";
111
+ export { DateRangePicker } from "./components/uix/date-range-picker";
112
+ export type { DialogProps } from "./components/uix/dialog";
113
+ export { Dialog } from "./components/uix/dialog";
114
+ export type { DividerProps } from "./components/uix/divider";
115
+ export { Divider } from "./components/uix/divider";
116
+ export type { DropdownMenuItemProps, DropdownProps } from "./components/uix/dropdown";
117
+ export { Dropdown } from "./components/uix/dropdown";
118
+ export type { EmptyProps } from "./components/uix/empty";
119
+ export { Empty } from "./components/uix/empty";
120
+ export type { FilterItemProps, FiltersProps } from "./components/uix/filters";
121
+ export { Filters } from "./components/uix/filters";
122
+ export type { FieldItem, FormInstance, FormProps, RenderProps } from "./components/uix/form";
123
+ export { Form, FormItem } from "./components/uix/form";
124
+ export type { ImageProps } from "./components/uix/image";
125
+ export { Image } from "./components/uix/image";
126
+ export type { LoadingProps } from "./components/uix/loading";
127
+ export { Loading } from "./components/uix/loading";
128
+ export { useMessage } from "./components/uix/message";
129
+ export type { PaginationProps } from "./components/uix/pagination";
130
+ export { Pagination } from "./components/uix/pagination";
131
+ export type { SimpleRadioGroupOptionProps, SimpleRadioGroupProps } from "./components/uix/radio-group";
132
+ export { SimpleRadioGroup } from "./components/uix/radio-group";
133
+ export type { ResultProps } from "./components/uix/result";
134
+ export { Result } from "./components/uix/result";
135
+ export type { SelectOptionProps, SelectProps } from "./components/uix/select";
136
+ export { Select } from "./components/uix/select";
137
+ export { Space } from "./components/uix/space";
138
+ export type { SpinProps } from "./components/uix/spin";
139
+ export { Spin } from "./components/uix/spin";
140
+ export type { StepsItemProps, StepsProps } from "./components/uix/steps";
141
+ export { Steps, StepsItem } from "./components/uix/steps";
142
+ export type { SwitchProps } from "./components/uix/switch";
143
+ export { Switch } from "./components/uix/switch";
144
+ export type { TooltipProps } from "./components/uix/tooltip";
145
+ export { Tooltip } from "./components/uix/tooltip";
146
+ export type { TreeData, TreeProps } from "./components/uix/tree";
147
+ export { Tree } from "./components/uix/tree";
148
+ export type { TreeSelectProps } from "./components/uix/tree-select";
149
+ export { TreeSelect } from "./components/uix/tree-select";
150
+ export type { TreeTableColumn, TreeTableProps } from "./components/uix/tree-table";
151
+ export { TreeTable } from "./components/uix/tree-table";
152
+ export type { UploaderProps } from "./components/uix/uploader";
153
+ export { Uploader } from "./components/uix/uploader";
154
+ export type { HandleProps, UploadFile } from "./components/uix/uploader/type";
155
+ export type { ValueFormatterProps } from "./components/uix/value-formatter";
156
+ export { register, ValueFormatter } from "./components/uix/value-formatter";
157
+ // hooks
158
+ export * from "./hooks";
159
+ export * from "./lib";
@@ -0,0 +1,13 @@
1
+ import day from "dayjs";
2
+
3
+ // biome-ignore lint/suspicious/noExplicitAny: <v>
4
+ export const time = (v: any, format = "YYYY-MM-DD HH:mm:ss") => {
5
+ if (!v) return "--";
6
+ const d = day(v);
7
+ return d.isValid() ? d.format(format) : "--";
8
+ };
9
+
10
+ // biome-ignore lint/suspicious/noExplicitAny: <v>
11
+ export const defaultValue = (v: any) => {
12
+ return v === 0 ? v : v || "--";
13
+ };
@@ -0,0 +1,4 @@
1
+ export * from "./formatters";
2
+ export * from "./is";
3
+ export * from "./react-dom";
4
+ export * from "./utils";
package/src/lib/is.ts ADDED
@@ -0,0 +1,6 @@
1
+ const opt = Object.prototype.toString;
2
+
3
+ // biome-ignore lint/suspicious/noExplicitAny: <isObject>
4
+ export function isObject(obj: any): obj is { [key: string]: any } {
5
+ return opt.call(obj) === "[object Object]";
6
+ }
@@ -0,0 +1,98 @@
1
+ /** biome-ignore-all lint/suspicious/noExplicitAny: <any> */
2
+
3
+ import type { ReactElement } from "react";
4
+ import ReactDOM from "react-dom";
5
+ import { createRoot as reactDOMCreateRoot } from "react-dom/client";
6
+
7
+ import { isObject } from "./is";
8
+
9
+ type CreateRootFnType = (container: Element | DocumentFragment) => {
10
+ render: (container: ReactElement) => void;
11
+ unmount: () => void;
12
+ _unmount: () => void;
13
+ };
14
+
15
+ const reactDOMCreateRootCopy = reactDOMCreateRoot as CreateRootFnType;
16
+
17
+ const __SECRET_INTERNALS__ = "__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED";
18
+
19
+ const CopyReactDOM = ReactDOM as typeof ReactDOM & {
20
+ createRoot: CreateRootFnType;
21
+ // https://github.com/facebook/react/blob/4ff5f5719b348d9d8db14aaa49a48532defb4ab7/packages/react-dom/src/client/ReactDOM.js#L181
22
+ [__SECRET_INTERNALS__]: {
23
+ usingClientEntryPoint?: boolean;
24
+ };
25
+ };
26
+
27
+ let copyRender: (
28
+ app: ReactElement,
29
+ container: Element | DocumentFragment,
30
+ ) => {
31
+ render: (container: ReactElement) => void;
32
+ _unmount: () => void;
33
+ };
34
+
35
+ const isReact18 = Number(CopyReactDOM.version?.split(".")[0]) > 17;
36
+ const isReact19 = Number(CopyReactDOM.version?.split(".")[0]) > 18;
37
+
38
+ const updateUsingClientEntryPoint = (skipWarning?: boolean) => {
39
+ // https://github.com/facebook/react/blob/17806594cc28284fe195f918e8d77de3516848ec/packages/react-dom/npm/client.js#L10
40
+ // Avoid console warning
41
+ if (isObject(CopyReactDOM[__SECRET_INTERNALS__])) {
42
+ CopyReactDOM[__SECRET_INTERNALS__].usingClientEntryPoint = skipWarning;
43
+ }
44
+ };
45
+
46
+ let createRoot: CreateRootFnType;
47
+ try {
48
+ createRoot = CopyReactDOM.createRoot;
49
+ } catch (_) {
50
+ //
51
+ }
52
+
53
+ if (isReact19) {
54
+ copyRender = (app: ReactElement, container: Element | DocumentFragment) => {
55
+ updateUsingClientEntryPoint(true);
56
+ const root = reactDOMCreateRootCopy(container);
57
+ updateUsingClientEntryPoint(false);
58
+
59
+ root.render(app);
60
+
61
+ root._unmount = () => {
62
+ setTimeout(() => {
63
+ root?.unmount?.();
64
+ });
65
+ };
66
+ return root;
67
+ };
68
+ } else if (isReact18) {
69
+ copyRender = (app: ReactElement, container: Element | DocumentFragment) => {
70
+ updateUsingClientEntryPoint(true);
71
+ const root = createRoot(container);
72
+ updateUsingClientEntryPoint(false);
73
+
74
+ root.render(app);
75
+
76
+ root._unmount = () => {
77
+ setTimeout(() => {
78
+ root?.unmount?.();
79
+ });
80
+ };
81
+ return root;
82
+ };
83
+ } else {
84
+ copyRender = (app: ReactElement, container: Element | DocumentFragment) => {
85
+ (CopyReactDOM as any).render(app, container);
86
+
87
+ return {
88
+ render: (app: ReactElement) => {
89
+ (CopyReactDOM as any).render(app, container);
90
+ },
91
+ _unmount() {
92
+ (CopyReactDOM as any).unmountComponentAtNode(container);
93
+ },
94
+ };
95
+ };
96
+ }
97
+
98
+ export const render = copyRender;
@@ -0,0 +1,39 @@
1
+ import { type ClassValue, clsx } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+
4
+ export function cn(...inputs: ClassValue[]) {
5
+ return twMerge(clsx(inputs));
6
+ }
7
+
8
+ // 简单的MD5实现(用于生成存储key)
9
+ export function md5Hash(text: string): string {
10
+ // 简化版MD5哈希算法
11
+ let hash = 0;
12
+ if (text.length === 0) return hash.toString();
13
+
14
+ for (let i = 0; i < text.length; i++) {
15
+ const char = text.charCodeAt(i);
16
+ hash = (hash << 5) - hash + char;
17
+ hash &= hash; // 转换为32位整数
18
+ }
19
+
20
+ // 转换为16进制并确保长度
21
+ return Math.abs(hash).toString(16).padStart(8, "0");
22
+ }
23
+
24
+ // 生成DataTable列配置的存储key
25
+ export function generateColumnStorageKey(
26
+ columns: Array<{ accessorKey?: string | number | symbol; id?: string }>,
27
+ ): string {
28
+ const keys = columns
29
+ .map((col) => {
30
+ const accessorKey = col.accessorKey ? String(col.accessorKey) : "";
31
+ const id = col.id || "";
32
+ return accessorKey || id;
33
+ })
34
+ .filter((key) => key)
35
+ .sort()
36
+ .join(",");
37
+
38
+ return md5Hash(keys);
39
+ }