mtxuilib 0.1.514 → 0.1.516

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.
@@ -0,0 +1,10 @@
1
+ import { type ChangeEventHandler } from "react";
2
+ type Props = {
3
+ value: string;
4
+ onChange?: ChangeEventHandler<HTMLTextAreaElement>;
5
+ className?: string;
6
+ readOnly?: boolean;
7
+ placeholder?: string;
8
+ };
9
+ export declare function AutoResizingTextarea({ value, onChange, className, readOnly, placeholder, }: Props): import("react/jsx-runtime").JSX.Element;
10
+ export {};
@@ -0,0 +1,21 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { cn } from "mtxuilib/lib/utils";
3
+ import { Textarea } from "mtxuilib/ui/textarea";
4
+ import { useLayoutEffect, useRef } from "react";
5
+ export function AutoResizingTextarea({ value, onChange, className, readOnly, placeholder, }) {
6
+ const ref = useRef(null);
7
+ useLayoutEffect(() => {
8
+ if (!ref.current) {
9
+ return;
10
+ }
11
+ ref.current.style.height = `${ref.current.scrollHeight + 2}px`;
12
+ }, []);
13
+ function setSize() {
14
+ if (!ref.current) {
15
+ return;
16
+ }
17
+ ref.current.style.height = "auto";
18
+ ref.current.style.height = `${ref.current.scrollHeight + 2}px`;
19
+ }
20
+ return (_jsx(Textarea, { value: value, onChange: onChange, readOnly: readOnly, placeholder: placeholder, ref: ref, onKeyDown: setSize, onInput: setSize, rows: 1, className: cn("min-h-0 resize-none overflow-y-hidden", className) }));
21
+ }
@@ -1,15 +1,19 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { Dialog, DialogContent, DialogTrigger } from "mtxuilib/ui/dialog";
4
- import { MtButton } from "mtxuilib/ui/mt/Button";
3
+ import { TooltipContent } from "@radix-ui/react-tooltip";
4
+ import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "mtxuilib/ui/dialog";
5
5
  import { useState } from "react";
6
+ import { Icons } from "../../icons/icons";
7
+ import { Button } from "../../ui/button";
8
+ import { Tooltip, TooltipTrigger } from "../../ui/tooltip";
6
9
  export const DebugValue = (props) => {
7
10
  const { title, data, className } = props;
8
11
  const [open, setOpen] = useState(false);
9
12
  if (process.env.NODE_ENV === "production") {
10
13
  return null;
11
14
  }
12
- return (_jsxs(Dialog, { open: open, onOpenChange: setOpen, children: [_jsx(DialogTrigger, { asChild: true, children: _jsx(MtButton, { variant: "outline", className: className, onClick: () => {
13
- console.log(data);
14
- }, children: title || "调试" }) }), _jsx(DialogContent, { className: "max-h-lvh w-full overflow-scroll ", children: _jsx("pre", { className: " text-xs", children: JSON.stringify(data, null, 2) }) })] }));
15
+ return (_jsxs(Dialog, { open: open, onOpenChange: setOpen, children: [_jsx(DialogTrigger, { asChild: true, children: _jsxs(Tooltip, { children: [_jsx(TooltipTrigger, { asChild: true, children: _jsx(Button, { size: "icon", variant: "outline", className: className, onClick: () => {
16
+ setOpen(!open);
17
+ console.log(data);
18
+ }, children: _jsx(Icons.bug, { className: "size-4" }) }) }), _jsx(TooltipContent, { children: title })] }) }), _jsxs(DialogContent, { className: "max-h-lvh w-full overflow-scroll min-w-xl ", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: title }), _jsx(DialogDescription, { className: "text-sm", children: " " })] }), _jsx("pre", { className: " text-xs", children: JSON.stringify(data, null, 2) })] })] }));
15
19
  };
@@ -0,0 +1,5 @@
1
+ type Props = {
2
+ value: string;
3
+ };
4
+ export declare function HiddenCopyableInput({ value }: Props): import("react/jsx-runtime").JSX.Element;
5
+ export {};
@@ -0,0 +1,23 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { CheckIcon, CopyIcon } from "@radix-ui/react-icons";
4
+ import { useState } from "react";
5
+ import { copyText } from "../lib/utils";
6
+ import { Button } from "../ui/button";
7
+ import { Input } from "../ui/input";
8
+ export function HiddenCopyableInput({ value }) {
9
+ const [hidden, setHidden] = useState(true);
10
+ const [copied, setCopied] = useState(false);
11
+ const buttonText = hidden ? "Reveal" : copied ? "Copied" : "Copy";
12
+ const inputValue = hidden ? "**** **** **** ****" : value;
13
+ return (_jsxs("div", { className: "relative w-full", children: [_jsx(Input, { value: inputValue, className: "h-10", readOnly: true }), _jsx("div", { className: "absolute inset-y-0 right-1 flex items-center", children: _jsxs(Button, { size: "sm", variant: "secondary", className: "cursor-pointer", onClick: () => {
14
+ if (hidden) {
15
+ setHidden(false);
16
+ return;
17
+ }
18
+ copyText(value).then(() => {
19
+ setCopied(true);
20
+ setTimeout(() => setCopied(false), 3000);
21
+ });
22
+ }, children: [!hidden && !copied && _jsx(CopyIcon, { className: "mr-2 h-4 w-4" }), !hidden && copied && _jsx(CheckIcon, { className: "mr-2 h-4 w-4" }), buttonText] }) })] }));
23
+ }
@@ -0,0 +1,5 @@
1
+ type Props = {
2
+ className?: string;
3
+ };
4
+ declare function GarbageIcon({ className }: Props): import("react/jsx-runtime").JSX.Element;
5
+ export { GarbageIcon };
@@ -0,0 +1,6 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ function GarbageIcon({ className }) {
4
+ return (_jsx("svg", { xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", strokeWidth: 1.5, stroke: "currentColor", className: className, children: _jsx("path", { strokeLinecap: "round", strokeLinejoin: "round", d: "m14.74 9-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 0 1-2.244 2.077H8.084a2.25 2.25 0 0 1-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 0 0-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 0 1 3.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 0 0-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 0 0-7.5 0" }) }));
5
+ }
6
+ export { GarbageIcon };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ "use client";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ function SaveIcon() {
4
+ return (_jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { d: "M7 3V6.4C7 6.96005 7 7.24008 7.10899 7.45399C7.20487 7.64215 7.35785 7.79513 7.54601 7.89101C7.75992 8 8.03995 8 8.6 8H15.4C15.9601 8 16.2401 8 16.454 7.89101C16.6422 7.79513 16.7951 7.64215 16.891 7.45399C17 7.24008 17 6.96005 17 6.4V4M17 21V14.6C17 14.0399 17 13.7599 16.891 13.546C16.7951 13.3578 16.6422 13.2049 16.454 13.109C16.2401 13 15.9601 13 15.4 13H8.6C8.03995 13 7.75992 13 7.54601 13.109C7.35785 13.2049 7.20487 13.3578 7.10899 13.546C7 13.7599 7 14.0399 7 14.6V21M21 9.32548V16.2C21 17.8802 21 18.7202 20.673 19.362C20.3854 19.9265 19.9265 20.3854 19.362 20.673C18.7202 21 17.8802 21 16.2 21H7.8C6.11984 21 5.27976 21 4.63803 20.673C4.07354 20.3854 3.6146 19.9265 3.32698 19.362C3 18.7202 3 17.8802 3 16.2V7.8C3 6.11984 3 5.27976 3.32698 4.63803C3.6146 4.07354 4.07354 3.6146 4.63803 3.32698C5.27976 3 6.11984 3 7.8 3H14.6745C15.1637 3 15.4083 3 15.6385 3.05526C15.8425 3.10425 16.0376 3.18506 16.2166 3.29472C16.4184 3.4184 16.5914 3.59135 16.9373 3.93726L20.0627 7.06274C20.4086 7.40865 20.5816 7.5816 20.7053 7.78343C20.8149 7.96237 20.8957 8.15746 20.9447 8.36154C21 8.59171 21 8.8363 21 9.32548Z", stroke: "#F8FAFC", strokeWidth: "1.6", strokeLinecap: "round", strokeLinejoin: "round" }) }));
5
+ }
@@ -41,4 +41,5 @@ export declare const getMessageFromCode: (resultCode: string) => "Invalid creden
41
41
  export declare const copyClipboard: (obj: any) => void;
42
42
  export declare function isObject(object: any): boolean;
43
43
  export declare function deepEqual(object1: Record<string, any>, object2: Record<string, any>): boolean;
44
+ export declare function copyText(text: string): Promise<void>;
44
45
  export {};
package/dist/lib/utils.js CHANGED
@@ -264,3 +264,24 @@ export function deepEqual(object1, object2) {
264
264
  }
265
265
  return true;
266
266
  }
267
+ export async function copyText(text) {
268
+ if ("clipboard" in navigator) {
269
+ return navigator.clipboard.writeText(text);
270
+ }
271
+ else {
272
+ const textArea = document.createElement("textarea");
273
+ textArea.value = text;
274
+ textArea.style.opacity = "0";
275
+ document.body.appendChild(textArea);
276
+ textArea.focus();
277
+ textArea.select();
278
+ const success = document.execCommand("copy");
279
+ document.body.removeChild(textArea);
280
+ if (success) {
281
+ return Promise.resolve();
282
+ }
283
+ else {
284
+ return Promise.reject();
285
+ }
286
+ }
287
+ }
@@ -1,7 +1,7 @@
1
1
  import { type VariantProps } from "class-variance-authority";
2
2
  import * as React from "react";
3
3
  declare const buttonVariants: (props?: ({
4
- variant?: "link" | "secondary" | "destructive" | "default" | "outline" | "ghost" | null | undefined;
4
+ variant?: "link" | "secondary" | "destructive" | "default" | "outline" | "ghost" | "tertiary" | null | undefined;
5
5
  size?: "lg" | "sm" | "default" | "icon" | null | undefined;
6
6
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
7
7
  export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
package/dist/ui/button.js CHANGED
@@ -12,6 +12,7 @@ const buttonVariants = cva("inline-flex items-center justify-center whitespace-n
12
12
  secondary: "bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",
13
13
  ghost: "hover:bg-accent hover:text-accent-foreground",
14
14
  link: "text-primary underline-offset-4 hover:underline",
15
+ tertiary: "bg-tertiary/20 text-tertiary-foreground border border-slate-500 hover:bg-tertiary/10 rounded-lg",
15
16
  },
16
17
  size: {
17
18
  default: "h-9 px-4 py-2",
@@ -0,0 +1,22 @@
1
+ import { type VariantProps } from "class-variance-authority";
2
+ import * as React from "react";
3
+ declare const multiSelectVariants: (props?: ({
4
+ variant?: "secondary" | "destructive" | "default" | "inverted" | null | undefined;
5
+ } & import("class-variance-authority/types").ClassProp) | undefined) => string;
6
+ interface MultiSelectProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof multiSelectVariants> {
7
+ options: {
8
+ label: string;
9
+ value: string;
10
+ icon?: React.ComponentType<{
11
+ className?: string;
12
+ }>;
13
+ }[];
14
+ onValueChange: (value: string[]) => void;
15
+ value: string[];
16
+ placeholder?: string;
17
+ maxCount?: number;
18
+ modalPopover?: boolean;
19
+ className?: string;
20
+ }
21
+ export declare const MultiSelect: React.ForwardRefExoticComponent<MultiSelectProps & React.RefAttributes<HTMLButtonElement>>;
22
+ export {};
@@ -0,0 +1,85 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import { cva } from "class-variance-authority";
4
+ import * as React from "react";
5
+ import { CheckIcon, ChevronDownIcon, Cross2Icon, CrossCircledIcon, } from "@radix-ui/react-icons";
6
+ import { CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandSeparator, } from "cmdk";
7
+ import { cn } from "../../lib/utils";
8
+ import { Badge } from "../badge";
9
+ import { Button } from "../button";
10
+ import { Command } from "../command";
11
+ import { Popover, PopoverContent, PopoverTrigger } from "../popover";
12
+ import { Separator } from "../separator";
13
+ const multiSelectVariants = cva("m-1", {
14
+ variants: {
15
+ variant: {
16
+ default: "border-foreground/10 text-foreground bg-card hover:bg-card/80",
17
+ secondary: "border-foreground/10 bg-secondary text-secondary-foreground hover:bg-secondary/80",
18
+ destructive: "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",
19
+ inverted: "inverted",
20
+ },
21
+ },
22
+ defaultVariants: {
23
+ variant: "default",
24
+ },
25
+ });
26
+ export const MultiSelect = React.forwardRef(({ options, onValueChange, variant, value, placeholder = "Select options", maxCount = 3, modalPopover = false, className, ...props }, ref) => {
27
+ const [isPopoverOpen, setIsPopoverOpen] = React.useState(false);
28
+ const handleInputKeyDown = (event) => {
29
+ if (event.key === "Enter") {
30
+ setIsPopoverOpen(true);
31
+ }
32
+ else if (event.key === "Backspace" && !event.currentTarget.value) {
33
+ const newSelectedValues = [...value];
34
+ newSelectedValues.pop();
35
+ onValueChange(newSelectedValues);
36
+ }
37
+ };
38
+ const toggleOption = (option) => {
39
+ const newSelectedValues = value.includes(option)
40
+ ? value.filter((v) => v !== option)
41
+ : [...value, option];
42
+ onValueChange(newSelectedValues);
43
+ };
44
+ const handleClear = () => {
45
+ onValueChange([]);
46
+ };
47
+ const handleTogglePopover = () => {
48
+ setIsPopoverOpen((prev) => !prev);
49
+ };
50
+ const clearExtraOptions = () => {
51
+ const newSelectedValues = value.slice(0, maxCount);
52
+ onValueChange(newSelectedValues);
53
+ };
54
+ const toggleAll = () => {
55
+ if (value.length === options.length) {
56
+ handleClear();
57
+ }
58
+ else {
59
+ const allValues = options.map((option) => option.value);
60
+ onValueChange(allValues);
61
+ }
62
+ };
63
+ return (_jsxs(Popover, { open: isPopoverOpen, onOpenChange: setIsPopoverOpen, modal: modalPopover, children: [_jsx(PopoverTrigger, { asChild: true, children: _jsx(Button, { ref: ref, ...props, onClick: handleTogglePopover, className: cn("flex h-auto min-h-8 w-full items-center justify-between rounded-md border bg-inherit p-1 hover:bg-inherit", className), children: value.length > 0 ? (_jsxs("div", { className: "flex w-full items-center justify-between", children: [_jsxs("div", { className: "flex flex-wrap items-center", children: [value.slice(0, maxCount).map((value) => {
64
+ const option = options.find((o) => o.value === value);
65
+ const IconComponent = option?.icon;
66
+ return (_jsxs(Badge, { className: cn(multiSelectVariants({ variant })), children: [IconComponent && (_jsx(IconComponent, { className: "mr-2 h-4 w-4" })), option?.label, _jsx(CrossCircledIcon, { className: "ml-2 h-4 w-4 cursor-pointer", onClick: (event) => {
67
+ event.stopPropagation();
68
+ toggleOption(value);
69
+ } })] }, value));
70
+ }), value.length > maxCount && (_jsxs(Badge, { className: cn("border-foreground/1 bg-transparent text-foreground hover:bg-transparent", multiSelectVariants({ variant })), children: [`+ ${value.length - maxCount} more`, _jsx(CrossCircledIcon, { className: "ml-2 h-4 w-4 cursor-pointer", onClick: (event) => {
71
+ event.stopPropagation();
72
+ clearExtraOptions();
73
+ } })] }))] }), _jsxs("div", { className: "flex items-center justify-between", children: [_jsx(Cross2Icon, { className: "mx-2 h-4 cursor-pointer text-muted-foreground", onClick: (event) => {
74
+ event.stopPropagation();
75
+ handleClear();
76
+ } }), _jsx(Separator, { orientation: "vertical", className: "flex h-full min-h-6" }), _jsx(ChevronDownIcon, { className: "mx-2 h-4 cursor-pointer text-muted-foreground" })] })] })) : (_jsxs("div", { className: "mx-auto flex w-full items-center justify-between", children: [_jsx("span", { className: "mx-2 text-xs font-normal text-muted-foreground", children: placeholder }), _jsx(ChevronDownIcon, { className: "mx-2 h-4 cursor-pointer text-muted-foreground" })] })) }) }), _jsx(PopoverContent, { className: "w-auto p-0", align: "start", onEscapeKeyDown: () => setIsPopoverOpen(false), children: _jsxs(Command, { children: [_jsx(CommandInput, { placeholder: "Search...", onKeyDown: handleInputKeyDown }), _jsxs(CommandList, { children: [_jsx(CommandEmpty, { children: "No results found." }), _jsxs(CommandGroup, { children: [_jsxs(CommandItem, { onSelect: toggleAll, className: "cursor-pointer", children: [_jsx("div", { className: cn("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary", value.length === options.length
77
+ ? "bg-primary text-primary-foreground"
78
+ : "opacity-50 [&_svg]:invisible"), children: _jsx(CheckIcon, { className: "h-4 w-4" }) }), _jsx("span", { children: "(Select All)" })] }, "all"), options.map((option) => {
79
+ const isSelected = value.includes(option.value);
80
+ return (_jsxs(CommandItem, { onSelect: () => toggleOption(option.value), className: "cursor-pointer", children: [_jsx("div", { className: cn("mr-2 flex h-4 w-4 items-center justify-center rounded-sm border border-primary", isSelected
81
+ ? "bg-primary text-primary-foreground"
82
+ : "opacity-50 [&_svg]:invisible"), children: _jsx(CheckIcon, { className: "h-4 w-4" }) }), option.icon && (_jsx(option.icon, { className: "mr-2 h-4 w-4 text-muted-foreground" })), _jsx("span", { children: option.label })] }, option.value));
83
+ })] }), _jsx(CommandSeparator, {}), _jsx(CommandGroup, { children: _jsxs("div", { className: "flex items-center justify-between", children: [value.length > 0 && (_jsxs(_Fragment, { children: [_jsx(CommandItem, { onSelect: handleClear, className: "flex-1 cursor-pointer justify-center", children: "Clear" }), _jsx(Separator, { orientation: "vertical", className: "flex h-full min-h-6" })] })), _jsx(CommandItem, { onSelect: () => setIsPopoverOpen(false), className: "max-w-full flex-1 cursor-pointer justify-center", children: "Close" })] }) })] })] }) })] }));
84
+ });
85
+ MultiSelect.displayName = "MultiSelect";
@@ -3,3 +3,4 @@ import * as React from "react";
3
3
  declare const ScrollArea: React.ForwardRefExoticComponent<Omit<ScrollAreaPrimitive.ScrollAreaProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
4
4
  declare const ScrollBar: React.ForwardRefExoticComponent<Omit<ScrollAreaPrimitive.ScrollAreaScrollbarProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
5
5
  export { ScrollArea, ScrollBar };
6
+ export declare const ScrollAreaViewport: React.ForwardRefExoticComponent<Omit<ScrollAreaPrimitive.ScrollAreaViewportProps & React.RefAttributes<HTMLDivElement>, "ref"> & React.RefAttributes<HTMLDivElement>>;
@@ -10,3 +10,8 @@ const ScrollBar = React.forwardRef(({ className, orientation = "vertical", ...pr
10
10
  "h-2.5 flex-col border-t border-t-transparent p-px", className), ...props, children: _jsx(ScrollAreaPrimitive.ScrollAreaThumb, { className: cn("bg-border relative rounded-full", orientation === "vertical" && "flex-1") }) })));
11
11
  ScrollBar.displayName = ScrollAreaPrimitive.ScrollAreaScrollbar.displayName;
12
12
  export { ScrollArea, ScrollBar };
13
+ export const ScrollAreaViewport = React.forwardRef(({ children, ...props }, ref) => {
14
+ return (_jsx(ScrollAreaPrimitive.Viewport, { ref: ref, ...props, children: children }));
15
+ });
16
+ ScrollAreaViewport.displayName =
17
+ ScrollAreaPrimitive.ScrollAreaViewport.displayName;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mtxuilib",
3
3
  "private": false,
4
- "version": "0.1.514",
4
+ "version": "0.1.516",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },