mtxuilib 0.1.451 → 0.1.453

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 @@
1
+ export declare function debounce<Args extends any[]>(fn: (...args: Args) => void, delay?: number): (...args: Args) => void;
@@ -0,0 +1,13 @@
1
+ "use client";
2
+ export function debounce(fn, delay = 100) {
3
+ if (delay === 0) {
4
+ return fn;
5
+ }
6
+ let timer;
7
+ return function (...args) {
8
+ clearTimeout(timer);
9
+ timer = window.setTimeout(() => {
10
+ fn.apply(this, args);
11
+ }, delay);
12
+ };
13
+ }
@@ -1,10 +1,10 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { Textarea } from "@headlessui/react";
4
3
  import { Label } from "@radix-ui/react-context-menu";
5
4
  import React from "react";
6
5
  import { useFormContext } from "react-hook-form";
7
6
  import { cn } from "../../../lib/utils";
7
+ import { Textarea } from "../../textarea";
8
8
  const TextAreaField = React.forwardRef(({ name, label, className, type, placeholder, ...rest }) => {
9
9
  const methods = useFormContext();
10
10
  return (_jsxs("div", { className: "group relative", children: [_jsx(Textarea, { className: cn("mt-2", "peer p-4 outline-none"), placeholder: " ", ...methods.register(name) }), _jsx(Label, { className: cn("pointer-events-none absolute left-[9px] top-px -translate-y-1/2 px-1 text-sm text-gray-500 transition-all duration-300", "group-focus-within:!top-2 group-focus-within:!text-sm group-focus-within:!text-blue-500 peer-placeholder-shown:top-1/2 peer-placeholder-shown:text-xl"), children: label })] }));
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mtxuilib",
3
3
  "private": false,
4
- "version": "0.1.451",
4
+ "version": "0.1.453",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -1,39 +0,0 @@
1
- import * as AccordionPrimitive from "@radix-ui/react-accordion";
2
- import type React from "react";
3
- import { type ReactNode } from "react";
4
- type TreeViewElement = {
5
- id: string;
6
- name: string;
7
- isSelectable?: boolean;
8
- children?: TreeViewElement[];
9
- };
10
- interface TreeViewComponentProps extends React.HTMLAttributes<HTMLDivElement> {
11
- }
12
- declare const Tree: React.ForwardRefExoticComponent<{
13
- initialSelectedId?: string;
14
- indicator?: boolean;
15
- elements?: TreeViewElement[];
16
- initialExpendedItems?: string[];
17
- openIcon?: React.ReactNode;
18
- closeIcon?: React.ReactNode;
19
- } & TreeViewComponentProps & React.RefAttributes<HTMLDivElement>>;
20
- interface FolderComponentProps extends React.ComponentPropsWithoutRef<typeof AccordionPrimitive.Item> {
21
- }
22
- declare const Folder: React.ForwardRefExoticComponent<{
23
- expendedItems?: string[];
24
- element: ReactNode;
25
- isSelectable?: boolean;
26
- isSelect?: boolean;
27
- } & FolderComponentProps & React.HTMLAttributes<HTMLDivElement> & React.RefAttributes<HTMLDivElement>>;
28
- declare const File: React.ForwardRefExoticComponent<{
29
- value: string;
30
- handleSelect?: (id: string) => void;
31
- isSelectable?: boolean;
32
- isSelect?: boolean;
33
- fileIcon?: React.ReactNode;
34
- } & Omit<AccordionPrimitive.AccordionTriggerProps & React.RefAttributes<HTMLButtonElement>, "ref"> & React.RefAttributes<HTMLButtonElement>>;
35
- declare const CollapseButton: React.ForwardRefExoticComponent<{
36
- elements: TreeViewElement[];
37
- expandAll?: boolean;
38
- } & React.HTMLAttributes<HTMLButtonElement> & React.RefAttributes<HTMLButtonElement>>;
39
- export { Tree, Folder, File, CollapseButton, type TreeViewElement };
@@ -1,132 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import * as AccordionPrimitive from "@radix-ui/react-accordion";
4
- import { FileIcon, FolderIcon, FolderOpenIcon } from "lucide-react";
5
- import { createContext, forwardRef, useCallback, useContext, useEffect, useState, } from "react";
6
- import { cn } from "../../../lib/utils";
7
- import { Button } from "../../button";
8
- import { ScrollArea } from "../../scroll-area";
9
- const TreeContext = createContext(null);
10
- const useTree = () => {
11
- const context = useContext(TreeContext);
12
- if (!context) {
13
- throw new Error("useTree must be used within a TreeProvider");
14
- }
15
- return context;
16
- };
17
- const Tree = forwardRef(({ className, elements, initialSelectedId, initialExpendedItems, children, indicator = true, openIcon, closeIcon, dir, ...props }, ref) => {
18
- const [selectedId, setSelectedId] = useState(initialSelectedId);
19
- const [expendedItems, setExpendedItems] = useState(initialExpendedItems);
20
- const selectItem = useCallback((id) => {
21
- setSelectedId(id);
22
- }, []);
23
- const handleExpand = useCallback((id) => {
24
- setExpendedItems((prev) => {
25
- if (prev?.includes(id)) {
26
- return prev.filter((item) => item !== id);
27
- }
28
- return [...(prev ?? []), id];
29
- });
30
- }, []);
31
- const expandSpecificTargetedElements = useCallback((elements, selectId) => {
32
- if (!elements || !selectId)
33
- return;
34
- const findParent = (currentElement, currentPath = []) => {
35
- const isSelectable = currentElement.isSelectable ?? true;
36
- const newPath = [...currentPath, currentElement.id];
37
- if (currentElement.id === selectId) {
38
- if (isSelectable) {
39
- setExpendedItems((prev) => [...(prev ?? []), ...newPath]);
40
- }
41
- else {
42
- if (newPath.includes(currentElement.id)) {
43
- newPath.pop();
44
- setExpendedItems((prev) => [...(prev ?? []), ...newPath]);
45
- }
46
- }
47
- return;
48
- }
49
- if (isSelectable &&
50
- currentElement.children &&
51
- currentElement.children.length > 0) {
52
- currentElement.children.forEach((child) => {
53
- findParent(child, newPath);
54
- });
55
- }
56
- };
57
- elements.forEach((element) => {
58
- findParent(element);
59
- });
60
- }, []);
61
- useEffect(() => {
62
- if (initialSelectedId) {
63
- expandSpecificTargetedElements(elements, initialSelectedId);
64
- }
65
- }, [initialSelectedId, elements]);
66
- const direction = dir === "rtl" ? "rtl" : "ltr";
67
- return (_jsx(TreeContext.Provider, { value: {
68
- selectedId,
69
- expendedItems,
70
- handleExpand,
71
- selectItem,
72
- setExpendedItems,
73
- indicator,
74
- openIcon,
75
- closeIcon,
76
- direction,
77
- }, children: _jsx("div", { className: cn("size-full", className), children: _jsx(ScrollArea, { ref: ref, className: "relative h-full px-2", dir: dir, children: _jsx(AccordionPrimitive.Root, { ...props, type: "multiple", defaultValue: expendedItems, value: expendedItems, className: "flex flex-col gap-1", onValueChange: (value) => setExpendedItems((prev) => [...(prev ?? []), value[0]]), dir: dir, children: children }) }) }) }));
78
- });
79
- Tree.displayName = "Tree";
80
- const TreeIndicator = forwardRef(({ className, ...props }, ref) => {
81
- const { direction } = useTree();
82
- return (_jsx("div", { dir: direction, ref: ref, className: cn("bg-muted absolute left-1.5 h-full w-px rounded-md py-3 duration-300 ease-in-out hover:bg-slate-300 rtl:right-1.5", className), ...props }));
83
- });
84
- TreeIndicator.displayName = "TreeIndicator";
85
- const Folder = forwardRef(({ className, element, value, isSelectable = true, isSelect, children, ...props }, ref) => {
86
- const { direction, handleExpand, expendedItems, indicator, setExpendedItems, openIcon, closeIcon, } = useTree();
87
- return (_jsxs(AccordionPrimitive.Item, { ...props, value: value, className: "relative h-full overflow-hidden ", children: [_jsxs(AccordionPrimitive.Trigger, { className: cn(`flex items-center gap-1 rounded-md text-sm`, className, {
88
- "bg-muted rounded-md": isSelect && isSelectable,
89
- "cursor-pointer": isSelectable,
90
- "cursor-not-allowed opacity-50": !isSelectable,
91
- }), disabled: !isSelectable, onClick: () => handleExpand(value), children: [expendedItems?.includes(value)
92
- ? openIcon ?? _jsx(FolderOpenIcon, { className: "h-4 w-4" })
93
- : closeIcon ?? _jsx(FolderIcon, { className: "h-4 w-4" }), _jsx("span", { children: element })] }), _jsxs(AccordionPrimitive.Content, { className: "data-[state=closed]:animate-accordion-up data-[state=open]:animate-accordion-down relative h-full overflow-hidden text-sm", children: [element && indicator && _jsx(TreeIndicator, { "aria-hidden": "true" }), _jsx(AccordionPrimitive.Root, { dir: direction, type: "multiple", className: "ml-5 flex flex-col gap-1 py-1 rtl:mr-5 ", defaultValue: expendedItems, value: expendedItems, onValueChange: (value) => {
94
- setExpendedItems?.((prev) => [...(prev ?? []), value[0]]);
95
- }, children: children })] })] }));
96
- });
97
- Folder.displayName = "Folder";
98
- const File = forwardRef(({ value, className, handleSelect, isSelectable = true, isSelect, fileIcon, children, ...props }, ref) => {
99
- const { direction, selectedId, selectItem } = useTree();
100
- const isSelected = isSelect ?? selectedId === value;
101
- return (_jsx(AccordionPrimitive.Item, { value: value, className: "relative", children: _jsxs(AccordionPrimitive.Trigger, { ref: ref, ...props, dir: direction, disabled: !isSelectable, "aria-label": "File", className: cn("flex items-center gap-1 cursor-pointer text-sm pr-1 rtl:pl-1 rtl:pr-0 rounded-md duration-200 ease-in-out", {
102
- "bg-muted": isSelected && isSelectable,
103
- }, isSelectable ? "cursor-pointer" : "cursor-not-allowed opacity-50", className), onClick: () => selectItem(value), children: [fileIcon ?? _jsx(FileIcon, { className: "h-4 w-4" }), children] }) }));
104
- });
105
- File.displayName = "File";
106
- const CollapseButton = forwardRef(({ className, elements, expandAll = false, children, ...props }, ref) => {
107
- const { expendedItems, setExpendedItems } = useTree();
108
- const expendAllTree = useCallback((elements) => {
109
- const expandTree = (element) => {
110
- const isSelectable = element.isSelectable ?? true;
111
- if (isSelectable && element.children && element.children.length > 0) {
112
- setExpendedItems?.((prev) => [...(prev ?? []), element.id]);
113
- element.children.forEach(expandTree);
114
- }
115
- };
116
- elements.forEach(expandTree);
117
- }, []);
118
- const closeAll = useCallback(() => {
119
- setExpendedItems?.([]);
120
- }, []);
121
- useEffect(() => {
122
- console.log(expandAll);
123
- if (expandAll) {
124
- expendAllTree(elements);
125
- }
126
- }, [expandAll]);
127
- return (_jsxs(Button, { variant: "ghost", className: "absolute bottom-1 right-2 h-8 w-fit p-1", onClick: expendedItems && expendedItems.length > 0
128
- ? closeAll
129
- : () => expendAllTree(elements), ref: ref, ...props, children: [children, _jsx("span", { className: "sr-only", children: "Toggle" })] }));
130
- });
131
- CollapseButton.displayName = "CollapseButton";
132
- export { Tree, Folder, File, CollapseButton };
@@ -1,24 +0,0 @@
1
- import type React from "react";
2
- import { type TreeViewElement } from "./mt-tree-view-api";
3
- interface TreeViewComponentProps extends React.HTMLAttributes<HTMLDivElement> {
4
- }
5
- type TreeViewProps = {
6
- initialSelectedId?: string;
7
- elements: TreeViewElement[];
8
- indicator?: boolean;
9
- } & ({
10
- initialExpendedItems?: string[];
11
- expandAll?: false;
12
- } | {
13
- initialExpendedItems?: undefined;
14
- expandAll: true;
15
- }) & TreeViewComponentProps;
16
- export declare const TreeView: {
17
- ({ elements, className, initialSelectedId, initialExpendedItems, expandAll, indicator, }: TreeViewProps): import("react/jsx-runtime").JSX.Element;
18
- displayName: string;
19
- };
20
- export declare const TreeItem: React.ForwardRefExoticComponent<{
21
- elements?: TreeViewElement[];
22
- indicator?: boolean;
23
- } & React.HTMLAttributes<HTMLUListElement> & React.RefAttributes<HTMLUListElement>>;
24
- export {};
@@ -1,25 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useVirtualizer } from "@tanstack/react-virtual";
4
- import { forwardRef, useCallback, useRef } from "react";
5
- import useResizeObserver from "use-resize-observer";
6
- import { cn } from "../../../lib/utils";
7
- import { CollapseButton, File, Folder, Tree, } from "./mt-tree-view-api";
8
- export const TreeView = ({ elements, className, initialSelectedId, initialExpendedItems, expandAll, indicator = false, }) => {
9
- const containerRef = useRef(null);
10
- const { getVirtualItems, getTotalSize } = useVirtualizer({
11
- count: elements.length,
12
- getScrollElement: () => containerRef.current,
13
- estimateSize: useCallback(() => 40, []),
14
- overscan: 5,
15
- });
16
- const { height = getTotalSize(), width } = useResizeObserver({
17
- ref: containerRef,
18
- });
19
- return (_jsx("div", { ref: containerRef, className: cn("w-full rounded-md overflow-hidden py-1 relative", className), children: _jsxs(Tree, { initialSelectedId: initialSelectedId, initialExpendedItems: initialExpendedItems, elements: elements, style: { height, width }, className: "w-full h-full overflow-y-auto", children: [getVirtualItems().map((element) => (_jsx(TreeItem, { "aria-label": "Root", elements: [elements[element.index]], indicator: indicator }, element.key))), _jsx(CollapseButton, { elements: elements, expandAll: expandAll, children: _jsx("span", { children: "Expand All" }) })] }) }));
20
- };
21
- TreeView.displayName = "TreeView";
22
- export const TreeItem = forwardRef(({ className, elements, indicator, ...props }, ref) => {
23
- return (_jsx("ul", { ref: ref, className: "w-full space-y-1 ", ...props, children: elements?.map((element) => (_jsx("li", { className: "w-full", children: element.children && element.children?.length > 0 ? (_jsx(Folder, { element: element.name, value: element.id, isSelectable: element.isSelectable, children: _jsx(TreeItem, { "aria-label": `folder ${element.name}`, elements: element.children, indicator: indicator }, element.id) })) : (_jsx(File, { value: element.id, "aria-label": `File ${element.name}`, isSelectable: element.isSelectable, children: _jsx("span", { children: element?.name }) }, element.id)) }, element.id))) }));
24
- });
25
- TreeItem.displayName = "TreeItem";
@@ -1,12 +0,0 @@
1
- import type { StaticImageData } from "next/image";
2
- interface ModalVideoProps {
3
- thumb: StaticImageData;
4
- thumbWidth: number;
5
- thumbHeight: number;
6
- thumbAlt: string;
7
- video: string;
8
- videoWidth: number;
9
- videoHeight: number;
10
- }
11
- export default function ModalVideo({ thumb, thumbWidth, thumbHeight, thumbAlt, video, videoWidth, videoHeight, }: ModalVideoProps): import("react/jsx-runtime").JSX.Element;
12
- export {};
@@ -1,12 +0,0 @@
1
- "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { Dialog, DialogPanel, Transition, TransitionChild, } from "@headlessui/react";
4
- import Image from "next/image";
5
- import { Fragment, useRef, useState } from "react";
6
- export default function ModalVideo({ thumb, thumbWidth, thumbHeight, thumbAlt, video, videoWidth, videoHeight, }) {
7
- const [modalOpen, setModalOpen] = useState(false);
8
- const videoRef = useRef(null);
9
- return (_jsxs("div", { className: "flex justify-center", children: [_jsxs("button", { className: "group relative flex items-center justify-center rounded-3xl focus:outline-none focus-visible:ring focus-visible:ring-indigo-300", onClick: () => {
10
- setModalOpen(true);
11
- }, "aria-label": "Watch the video", children: [_jsx(Image, { className: "rounded-3xl shadow-2xl transition-shadow duration-300 ease-in-out", src: thumb, width: thumbWidth, height: thumbHeight, priority: true, alt: thumbAlt }), _jsxs("svg", { className: "pointer-events-none absolute transition-transform duration-300 ease-in-out group-hover:scale-110", xmlns: "http://www.w3.org/2000/svg", width: "72", height: "72", children: [_jsx("circle", { className: "fill-white", cx: "36", cy: "36", r: "36", fillOpacity: ".8" }), _jsx("path", { className: "fill-indigo-500 drop-shadow-2xl", d: "M44 36a.999.999 0 0 0-.427-.82l-10-7A1 1 0 0 0 32 29V43a.999.999 0 0 0 1.573.82l10-7A.995.995 0 0 0 44 36V36c0 .001 0 .001 0 0Z" })] })] }), _jsx(Transition, { show: modalOpen, as: Fragment, afterEnter: () => videoRef.current?.play(), children: _jsxs(Dialog, { initialFocus: videoRef, onClose: () => setModalOpen(false), children: [_jsx(TransitionChild, { enter: "transition ease-out duration-200", enterFrom: "opacity-0", enterTo: "opacity-100", leave: "transition ease-out duration-100", leaveFrom: "opacity-100", leaveTo: "opacity-0", "aria-hidden": "true" }), _jsx(TransitionChild, { enter: "transition ease-out duration-300", enterFrom: "opacity-0 scale-75", enterTo: "opacity-100 scale-100", leave: "transition ease-out duration-200", leaveFrom: "opacity-100 scale-100", leaveTo: "opacity-0 scale-75", children: _jsx("div", { className: "mx-auto flex h-full max-w-5xl items-center", children: _jsx(DialogPanel, { className: "aspect-video max-h-full w-full overflow-hidden rounded-3xl bg-black shadow-2xl", children: _jsxs("video", { ref: videoRef, width: videoWidth, height: videoHeight, loop: true, controls: true, children: [_jsx("source", { src: video, type: "video/mp4" }), "Your browser does not support the video tag."] }) }) }) })] }) })] }));
12
- }