@deftui/react 0.2.5 → 0.3.1
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.mts +7 -5
- package/dist/index.mjs +4 -4
- package/dist/styles.css +3 -0
- package/dist/vendor/README.md +10 -9
- package/dist/vendor/coss/calendar.d.mts +4 -0
- package/dist/vendor/coss/calendar.mjs +70 -0
- package/dist/vendor/coss/card.d.mts +23 -0
- package/dist/vendor/coss/card.mjs +160 -0
- package/dist/vendor/coss/dialog.d.mts +1 -1
- package/dist/vendor/coss/dialog.mjs +1 -1
- package/dist/vendor/coss/table.d.mts +15 -0
- package/dist/vendor/coss/table.mjs +73 -0
- package/dist/vendor/reui.io/cascader/cascader-async.d.mts +20 -0
- package/dist/vendor/reui.io/cascader/cascader-async.mjs +578 -0
- package/dist/vendor/reui.io/cascader/cascader-context.d.mts +12 -0
- package/dist/vendor/reui.io/cascader/cascader-context.mjs +56 -0
- package/dist/vendor/reui.io/cascader/cascader-footer.d.mts +60 -0
- package/dist/vendor/reui.io/cascader/cascader-footer.mjs +445 -0
- package/dist/vendor/reui.io/cascader/cascader-i18n.mjs +64 -0
- package/dist/vendor/reui.io/cascader/cascader-item.d.mts +92 -0
- package/dist/vendor/reui.io/cascader/cascader-item.mjs +533 -0
- package/dist/vendor/reui.io/cascader/cascader-lib.d.mts +3 -0
- package/dist/vendor/reui.io/cascader/cascader-lib.mjs +688 -0
- package/dist/vendor/reui.io/cascader/cascader-nav.d.mts +56 -0
- package/dist/vendor/reui.io/cascader/cascader-nav.mjs +310 -0
- package/dist/vendor/reui.io/cascader/cascader-types.d.mts +140 -0
- package/dist/vendor/reui.io/cascader/cascader-virtual.d.mts +18 -0
- package/dist/vendor/reui.io/cascader/cascader-virtual.mjs +159 -0
- package/dist/vendor/reui.io/cascader/cascader.d.mts +299 -0
- package/dist/vendor/reui.io/cascader/cascader.mjs +1470 -0
- package/dist/vendor/reui.io/timeline.d.mts +21 -0
- package/dist/vendor/reui.io/timeline.mjs +127 -0
- package/dist/vendor/tailored/lightbox.d.mts +1 -1
- package/dist/vendor/tailored/lightbox.mjs +1 -1
- package/dist/widgets/datetime.d.mts +1 -1
- package/dist/widgets/datetime.mjs +6 -1
- package/dist/widgets/export.d.mts +28 -0
- package/dist/widgets/index.d.mts +69 -20
- package/dist/widgets/index.mjs +61 -11
- package/package.json +2 -2
- package/dist/vendor/shadcn/calendar.d.mts +0 -10
- package/dist/vendor/shadcn/calendar.mjs +0 -107
- package/dist/vendor/shadcn/card.d.mts +0 -11
- package/dist/vendor/shadcn/card.mjs +0 -55
- package/dist/vendor/shadcn/table.d.mts +0 -9
- package/dist/vendor/shadcn/table.mjs +0 -59
- package/dist/vendor/tailored/file-tree.d.mts +0 -21
- package/dist/vendor/tailored/file-tree.mjs +0 -146
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { Button, buttonVariants } from "./button.mjs";
|
|
3
|
-
import { cn } from "cn";
|
|
4
|
-
import * as React$1 from "react";
|
|
5
|
-
import { jsx } from "react/jsx-runtime";
|
|
6
|
-
import { ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
|
|
7
|
-
import { DayPicker, getDefaultClassNames } from "@daypicker/react";
|
|
8
|
-
// src/vendor/shadcn/calendar.tsx
|
|
9
|
-
function Calendar({ className, classNames, showOutsideDays = true, captionLayout = "label", buttonVariant = "ghost", locale, formatters, components, ...props }) {
|
|
10
|
-
const defaultClassNames = getDefaultClassNames();
|
|
11
|
-
return /* @__PURE__ */ jsx(DayPicker, {
|
|
12
|
-
showOutsideDays,
|
|
13
|
-
className: cn("group/calendar bg-background p-3 [--cell-radius:var(--radius-md)] [--cell-size:--spacing(8)] in-data-[slot=card-content]:bg-transparent in-data-[slot=popover-content]:bg-transparent", String.raw`rtl:**:[.rdp-button\_next>svg]:rotate-180`, String.raw`rtl:**:[.rdp-button\_previous>svg]:rotate-180`, className),
|
|
14
|
-
captionLayout,
|
|
15
|
-
locale,
|
|
16
|
-
formatters: {
|
|
17
|
-
formatMonthDropdown: (date) => date.toLocaleString(locale?.code, { month: "short" }),
|
|
18
|
-
...formatters
|
|
19
|
-
},
|
|
20
|
-
classNames: {
|
|
21
|
-
root: cn("w-fit", defaultClassNames.root),
|
|
22
|
-
months: cn("relative flex flex-col gap-4 md:flex-row", defaultClassNames.months),
|
|
23
|
-
month: cn("flex w-full flex-col gap-4", defaultClassNames.month),
|
|
24
|
-
nav: cn("absolute inset-x-0 top-0 flex w-full items-center justify-between gap-1", defaultClassNames.nav),
|
|
25
|
-
button_previous: cn(buttonVariants({ variant: buttonVariant }), "size-(--cell-size) p-0 select-none aria-disabled:opacity-50", defaultClassNames.button_previous),
|
|
26
|
-
button_next: cn(buttonVariants({ variant: buttonVariant }), "size-(--cell-size) p-0 select-none aria-disabled:opacity-50", defaultClassNames.button_next),
|
|
27
|
-
month_caption: cn("flex h-(--cell-size) w-full items-center justify-center px-(--cell-size)", defaultClassNames.month_caption),
|
|
28
|
-
dropdowns: cn("flex h-(--cell-size) w-full items-center justify-center gap-1.5 text-sm font-medium", defaultClassNames.dropdowns),
|
|
29
|
-
dropdown_root: cn("relative rounded-(--cell-radius)", defaultClassNames.dropdown_root),
|
|
30
|
-
dropdown: cn("absolute inset-0 bg-popover opacity-0", defaultClassNames.dropdown),
|
|
31
|
-
caption_label: cn("font-medium select-none", captionLayout === "label" ? "text-sm" : "flex items-center gap-1 rounded-(--cell-radius) text-sm [&>svg]:size-3.5 [&>svg]:text-muted-foreground", defaultClassNames.caption_label),
|
|
32
|
-
month_grid: cn("w-full border-collapse", defaultClassNames.month_grid),
|
|
33
|
-
weekdays: cn("flex", defaultClassNames.weekdays),
|
|
34
|
-
weekday: cn("flex-1 rounded-(--cell-radius) text-[0.8rem] font-normal text-muted-foreground select-none", defaultClassNames.weekday),
|
|
35
|
-
week: cn("mt-2 flex w-full", defaultClassNames.week),
|
|
36
|
-
week_number_header: cn("w-(--cell-size) select-none", defaultClassNames.week_number_header),
|
|
37
|
-
week_number: cn("text-[0.8rem] text-muted-foreground select-none", defaultClassNames.week_number),
|
|
38
|
-
day: cn("group/day relative aspect-square h-full w-full rounded-(--cell-radius) p-0 text-center select-none [&:last-child[data-selected=true]_button]:rounded-r-(--cell-radius)", props.showWeekNumber ? "[&:nth-child(2)[data-selected=true]_button]:rounded-l-(--cell-radius)" : "[&:first-child[data-selected=true]_button]:rounded-l-(--cell-radius)", defaultClassNames.day),
|
|
39
|
-
range_start: cn("relative isolate z-0 rounded-l-(--cell-radius) bg-muted after:absolute after:inset-y-0 after:right-0 after:w-4 after:bg-muted", defaultClassNames.range_start),
|
|
40
|
-
range_middle: cn("rounded-none", defaultClassNames.range_middle),
|
|
41
|
-
range_end: cn("relative isolate z-0 rounded-r-(--cell-radius) bg-muted after:absolute after:inset-y-0 after:left-0 after:w-4 after:bg-muted", defaultClassNames.range_end),
|
|
42
|
-
today: cn("rounded-(--cell-radius) bg-muted text-foreground data-[selected=true]:rounded-none", defaultClassNames.today),
|
|
43
|
-
outside: cn("text-muted-foreground aria-selected:text-muted-foreground", defaultClassNames.outside),
|
|
44
|
-
disabled: cn("text-muted-foreground opacity-50", defaultClassNames.disabled),
|
|
45
|
-
hidden: cn("invisible", defaultClassNames.hidden),
|
|
46
|
-
...classNames
|
|
47
|
-
},
|
|
48
|
-
components: {
|
|
49
|
-
Root: ({ className, rootRef, ...props }) => {
|
|
50
|
-
return /* @__PURE__ */ jsx("div", {
|
|
51
|
-
"data-slot": "calendar",
|
|
52
|
-
ref: rootRef,
|
|
53
|
-
className: cn(className),
|
|
54
|
-
...props
|
|
55
|
-
});
|
|
56
|
-
},
|
|
57
|
-
Chevron: ({ className, orientation, ...props }) => {
|
|
58
|
-
if (orientation === "left") return /* @__PURE__ */ jsx(ChevronLeftIcon, {
|
|
59
|
-
className: cn("size-4", className),
|
|
60
|
-
...props
|
|
61
|
-
});
|
|
62
|
-
if (orientation === "right") return /* @__PURE__ */ jsx(ChevronRightIcon, {
|
|
63
|
-
className: cn("size-4", className),
|
|
64
|
-
...props
|
|
65
|
-
});
|
|
66
|
-
return /* @__PURE__ */ jsx(ChevronDownIcon, {
|
|
67
|
-
className: cn("size-4", className),
|
|
68
|
-
...props
|
|
69
|
-
});
|
|
70
|
-
},
|
|
71
|
-
DayButton: ({ ...props }) => /* @__PURE__ */ jsx(CalendarDayButton, {
|
|
72
|
-
locale,
|
|
73
|
-
...props
|
|
74
|
-
}),
|
|
75
|
-
WeekNumber: ({ children, ...props }) => {
|
|
76
|
-
return /* @__PURE__ */ jsx("td", {
|
|
77
|
-
...props,
|
|
78
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
79
|
-
className: "flex size-(--cell-size) items-center justify-center text-center",
|
|
80
|
-
children
|
|
81
|
-
})
|
|
82
|
-
});
|
|
83
|
-
},
|
|
84
|
-
...components
|
|
85
|
-
},
|
|
86
|
-
...props
|
|
87
|
-
});
|
|
88
|
-
}
|
|
89
|
-
function CalendarDayButton({ className, day, modifiers, locale, ...props }) {
|
|
90
|
-
const defaultClassNames = getDefaultClassNames();
|
|
91
|
-
const ref = React$1.useRef(null);
|
|
92
|
-
React$1.useEffect(() => {
|
|
93
|
-
if (modifiers.focused) ref.current?.focus();
|
|
94
|
-
}, [modifiers.focused]);
|
|
95
|
-
return /* @__PURE__ */ jsx(Button, {
|
|
96
|
-
variant: "ghost",
|
|
97
|
-
size: "icon",
|
|
98
|
-
"data-day": day.date.toLocaleDateString(locale?.code),
|
|
99
|
-
"data-selected-single": modifiers.selected && !modifiers.range_start && !modifiers.range_end && !modifiers.range_middle,
|
|
100
|
-
"data-range-start": modifiers.range_start,
|
|
101
|
-
"data-range-end": modifiers.range_end,
|
|
102
|
-
"data-range-middle": modifiers.range_middle,
|
|
103
|
-
className: cn("relative isolate z-10 flex aspect-square size-auto w-full min-w-(--cell-size) flex-col gap-1 border-0 leading-none font-normal group-data-[focused=true]/day:relative group-data-[focused=true]/day:z-10 group-data-[focused=true]/day:border-ring group-data-[focused=true]/day:ring-[3px] group-data-[focused=true]/day:ring-ring/50 data-[range-end=true]:rounded-(--cell-radius) data-[range-end=true]:rounded-r-(--cell-radius) data-[range-end=true]:bg-primary data-[range-end=true]:text-primary-foreground data-[range-middle=true]:rounded-none data-[range-middle=true]:bg-muted data-[range-middle=true]:text-foreground data-[range-start=true]:rounded-(--cell-radius) data-[range-start=true]:rounded-l-(--cell-radius) data-[range-start=true]:bg-primary data-[range-start=true]:text-primary-foreground data-[selected-single=true]:bg-primary data-[selected-single=true]:text-primary-foreground dark:hover:text-foreground [&>span]:text-xs [&>span]:opacity-70", defaultClassNames.day, className),
|
|
104
|
-
...props
|
|
105
|
-
});
|
|
106
|
-
}
|
|
107
|
-
export { Calendar, CalendarDayButton };
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import * as React$1 from "react";
|
|
2
|
-
declare function Card({ className, size, ...props }: React$1.ComponentProps<"div"> & {
|
|
3
|
-
size?: "default" | "sm";
|
|
4
|
-
}): React$1.JSX.Element;
|
|
5
|
-
declare function CardHeader({ className, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
|
|
6
|
-
declare function CardTitle({ className, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
|
|
7
|
-
declare function CardDescription({ className, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
|
|
8
|
-
declare function CardAction({ className, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
|
|
9
|
-
declare function CardContent({ className, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
|
|
10
|
-
declare function CardFooter({ className, ...props }: React$1.ComponentProps<"div">): React$1.JSX.Element;
|
|
11
|
-
export { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle };
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { cn } from "cn";
|
|
2
|
-
import "react";
|
|
3
|
-
import { jsx } from "react/jsx-runtime";
|
|
4
|
-
// src/vendor/shadcn/card.tsx
|
|
5
|
-
function Card({ className, size = "default", ...props }) {
|
|
6
|
-
return /* @__PURE__ */ jsx("div", {
|
|
7
|
-
"data-slot": "card",
|
|
8
|
-
"data-size": size,
|
|
9
|
-
className: cn("group/card flex flex-col gap-(--card-spacing) overflow-hidden rounded-xl bg-card py-(--card-spacing) text-sm text-card-foreground shadow-xs ring-1 ring-foreground/10 [--card-spacing:--spacing(6)] has-[>img:first-child]:pt-0 data-[size=sm]:[--card-spacing:--spacing(4)] *:[img:first-child]:rounded-t-xl *:[img:last-child]:rounded-b-xl", className),
|
|
10
|
-
...props
|
|
11
|
-
});
|
|
12
|
-
}
|
|
13
|
-
function CardHeader({ className, ...props }) {
|
|
14
|
-
return /* @__PURE__ */ jsx("div", {
|
|
15
|
-
"data-slot": "card-header",
|
|
16
|
-
className: cn("group/card-header @container/card-header grid auto-rows-min items-start gap-1 rounded-t-xl px-(--card-spacing) has-data-[slot=card-action]:grid-cols-[1fr_auto] has-data-[slot=card-description]:grid-rows-[auto_auto] [.border-b]:pb-(--card-spacing)", className),
|
|
17
|
-
...props
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
function CardTitle({ className, ...props }) {
|
|
21
|
-
return /* @__PURE__ */ jsx("div", {
|
|
22
|
-
"data-slot": "card-title",
|
|
23
|
-
className: cn("text-base leading-normal font-medium group-data-[size=sm]/card:text-sm", className),
|
|
24
|
-
...props
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
function CardDescription({ className, ...props }) {
|
|
28
|
-
return /* @__PURE__ */ jsx("div", {
|
|
29
|
-
"data-slot": "card-description",
|
|
30
|
-
className: cn("text-sm text-muted-foreground", className),
|
|
31
|
-
...props
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
function CardAction({ className, ...props }) {
|
|
35
|
-
return /* @__PURE__ */ jsx("div", {
|
|
36
|
-
"data-slot": "card-action",
|
|
37
|
-
className: cn("col-start-2 row-span-2 row-start-1 self-start justify-self-end", className),
|
|
38
|
-
...props
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
function CardContent({ className, ...props }) {
|
|
42
|
-
return /* @__PURE__ */ jsx("div", {
|
|
43
|
-
"data-slot": "card-content",
|
|
44
|
-
className: cn("flex flex-col gap-3 px-(--card-spacing)", className),
|
|
45
|
-
...props
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
function CardFooter({ className, ...props }) {
|
|
49
|
-
return /* @__PURE__ */ jsx("div", {
|
|
50
|
-
"data-slot": "card-footer",
|
|
51
|
-
className: cn("flex items-center rounded-b-xl px-(--card-spacing) [.border-t]:pt-(--card-spacing)", className),
|
|
52
|
-
...props
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
export { Card, CardAction, CardContent, CardDescription, CardFooter, CardHeader, CardTitle };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import * as React$1 from "react";
|
|
2
|
-
declare function Table({ className, ...props }: React$1.ComponentProps<"table">): React$1.JSX.Element;
|
|
3
|
-
declare function TableHeader({ className, ...props }: React$1.ComponentProps<"thead">): React$1.JSX.Element;
|
|
4
|
-
declare function TableBody({ className, ...props }: React$1.ComponentProps<"tbody">): React$1.JSX.Element;
|
|
5
|
-
declare function TableFooter({ className, ...props }: React$1.ComponentProps<"tfoot">): React$1.JSX.Element;
|
|
6
|
-
declare function TableRow({ className, ...props }: React$1.ComponentProps<"tr">): React$1.JSX.Element;
|
|
7
|
-
declare function TableHead({ className, ...props }: React$1.ComponentProps<"th">): React$1.JSX.Element;
|
|
8
|
-
declare function TableCell({ className, ...props }: React$1.ComponentProps<"td">): React$1.JSX.Element;
|
|
9
|
-
export { Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow };
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { cn } from "cn";
|
|
3
|
-
import "react";
|
|
4
|
-
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
// src/vendor/shadcn/table.tsx
|
|
6
|
-
function Table({ className, ...props }) {
|
|
7
|
-
return /* @__PURE__ */ jsx("div", {
|
|
8
|
-
"data-slot": "table-container",
|
|
9
|
-
className: "relative w-full overflow-x-auto",
|
|
10
|
-
children: /* @__PURE__ */ jsx("table", {
|
|
11
|
-
"data-slot": "table",
|
|
12
|
-
className: cn("w-full caption-bottom text-sm", className),
|
|
13
|
-
...props
|
|
14
|
-
})
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
function TableHeader({ className, ...props }) {
|
|
18
|
-
return /* @__PURE__ */ jsx("thead", {
|
|
19
|
-
"data-slot": "table-header",
|
|
20
|
-
className: cn("[&_tr]:border-b", className),
|
|
21
|
-
...props
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
function TableBody({ className, ...props }) {
|
|
25
|
-
return /* @__PURE__ */ jsx("tbody", {
|
|
26
|
-
"data-slot": "table-body",
|
|
27
|
-
className: cn("[&_tr:last-child]:border-0", className),
|
|
28
|
-
...props
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
function TableFooter({ className, ...props }) {
|
|
32
|
-
return /* @__PURE__ */ jsx("tfoot", {
|
|
33
|
-
"data-slot": "table-footer",
|
|
34
|
-
className: cn("border-t bg-muted/50 font-medium [&>tr]:last:border-b-0", className),
|
|
35
|
-
...props
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
function TableRow({ className, ...props }) {
|
|
39
|
-
return /* @__PURE__ */ jsx("tr", {
|
|
40
|
-
"data-slot": "table-row",
|
|
41
|
-
className: cn("border-b transition-colors hover:bg-muted/50 has-aria-expanded:bg-muted/50 data-[state=selected]:bg-muted", className),
|
|
42
|
-
...props
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
function TableHead({ className, ...props }) {
|
|
46
|
-
return /* @__PURE__ */ jsx("th", {
|
|
47
|
-
"data-slot": "table-head",
|
|
48
|
-
className: cn("h-10 px-2 text-left align-middle font-medium whitespace-nowrap text-foreground [&:has([role=checkbox])]:pr-0", className),
|
|
49
|
-
...props
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
function TableCell({ className, ...props }) {
|
|
53
|
-
return /* @__PURE__ */ jsx("td", {
|
|
54
|
-
"data-slot": "table-cell",
|
|
55
|
-
className: cn("p-2 align-middle whitespace-nowrap [&:has([role=checkbox])]:pr-0", className),
|
|
56
|
-
...props
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
export { Table, TableBody, TableCell, TableFooter, TableHead, TableHeader, TableRow };
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as React$1 from "react";
|
|
2
|
-
export type FileTreeNode = {
|
|
3
|
-
id: string;
|
|
4
|
-
name: string;
|
|
5
|
-
kind?: "file" | "folder";
|
|
6
|
-
children?: FileTreeNode[];
|
|
7
|
-
meta?: React$1.ReactNode;
|
|
8
|
-
icon?: React$1.ReactNode;
|
|
9
|
-
};
|
|
10
|
-
export type FileTreeProps = Omit<React$1.HTMLAttributes<HTMLDivElement>, "children" | "onSelect"> & {
|
|
11
|
-
nodes: FileTreeNode[];
|
|
12
|
-
expandedIds?: string[];
|
|
13
|
-
defaultExpandedIds?: string[];
|
|
14
|
-
onExpandedChange?: (ids: string[]) => void;
|
|
15
|
-
selectedId?: string | null;
|
|
16
|
-
defaultSelectedId?: string | null;
|
|
17
|
-
onSelect?: (node: FileTreeNode) => void;
|
|
18
|
-
label?: string;
|
|
19
|
-
};
|
|
20
|
-
/** https://ui.tinkererslabs.com/docs/components/file-tree/ */
|
|
21
|
-
export declare function FileTree({ nodes, expandedIds, defaultExpandedIds, onExpandedChange, selectedId, defaultSelectedId, onSelect, label, className, ...rootProps }: FileTreeProps): React$1.JSX.Element;
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { cn } from "../shadcn/lib/utils.mjs";
|
|
3
|
-
import * as React$1 from "react";
|
|
4
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
-
import { ChevronRight, File, Folder, FolderOpen } from "lucide-react";
|
|
6
|
-
// src/vendor/tailored/file-tree.tsx
|
|
7
|
-
function isFolder(node) {
|
|
8
|
-
return node.kind === "folder" || Array.isArray(node.children);
|
|
9
|
-
}
|
|
10
|
-
function flatten(nodes, expanded, level = 1) {
|
|
11
|
-
return nodes.flatMap((node) => {
|
|
12
|
-
const folder = isFolder(node);
|
|
13
|
-
const open = folder && expanded.has(node.id);
|
|
14
|
-
const self = {
|
|
15
|
-
node,
|
|
16
|
-
level,
|
|
17
|
-
isFolder: folder,
|
|
18
|
-
isExpanded: open
|
|
19
|
-
};
|
|
20
|
-
if (!open || !node.children) return [self];
|
|
21
|
-
return [self, ...flatten(node.children, expanded, level + 1)];
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
/** https://ui.tinkererslabs.com/docs/components/file-tree/ */
|
|
25
|
-
function FileTree({ nodes, expandedIds, defaultExpandedIds = [], onExpandedChange, selectedId, defaultSelectedId = null, onSelect, label = "Files", className, ...rootProps }) {
|
|
26
|
-
const [uncontrolledExpanded, setUncontrolledExpanded] = React$1.useState(defaultExpandedIds);
|
|
27
|
-
const [uncontrolledSelected, setUncontrolledSelected] = React$1.useState(defaultSelectedId);
|
|
28
|
-
const expandedList = expandedIds ?? uncontrolledExpanded;
|
|
29
|
-
const expanded = React$1.useMemo(() => new Set(expandedList), [expandedList]);
|
|
30
|
-
const selected = selectedId === void 0 ? uncontrolledSelected : selectedId;
|
|
31
|
-
const rows = React$1.useMemo(() => flatten(nodes, expanded), [nodes, expanded]);
|
|
32
|
-
const containerRef = React$1.useRef(null);
|
|
33
|
-
const setExpanded = (ids) => {
|
|
34
|
-
if (expandedIds === void 0) setUncontrolledExpanded(ids);
|
|
35
|
-
onExpandedChange?.(ids);
|
|
36
|
-
};
|
|
37
|
-
const toggle = (id, open) => {
|
|
38
|
-
const shouldOpen = open ?? !expanded.has(id);
|
|
39
|
-
if (shouldOpen === expanded.has(id)) return;
|
|
40
|
-
setExpanded(shouldOpen ? [...expandedList, id] : expandedList.filter((entry) => entry !== id));
|
|
41
|
-
};
|
|
42
|
-
const select = (node) => {
|
|
43
|
-
if (selectedId === void 0) setUncontrolledSelected(node.id);
|
|
44
|
-
onSelect?.(node);
|
|
45
|
-
};
|
|
46
|
-
const focusRow = (index) => {
|
|
47
|
-
const target = rows[index];
|
|
48
|
-
if (!target) return;
|
|
49
|
-
containerRef.current?.querySelector(`[data-node="${CSS.escape(target.node.id)}"]`)?.focus();
|
|
50
|
-
};
|
|
51
|
-
const onKeyDown = (event, row, index) => {
|
|
52
|
-
switch (event.key) {
|
|
53
|
-
case "ArrowDown":
|
|
54
|
-
event.preventDefault();
|
|
55
|
-
focusRow(Math.min(index + 1, rows.length - 1));
|
|
56
|
-
break;
|
|
57
|
-
case "ArrowUp":
|
|
58
|
-
event.preventDefault();
|
|
59
|
-
focusRow(Math.max(index - 1, 0));
|
|
60
|
-
break;
|
|
61
|
-
case "ArrowRight":
|
|
62
|
-
event.preventDefault();
|
|
63
|
-
if (row.isFolder && !row.isExpanded) toggle(row.node.id, true);
|
|
64
|
-
else if (row.isFolder) focusRow(index + 1);
|
|
65
|
-
break;
|
|
66
|
-
case "ArrowLeft": {
|
|
67
|
-
event.preventDefault();
|
|
68
|
-
if (row.isFolder && row.isExpanded) {
|
|
69
|
-
toggle(row.node.id, false);
|
|
70
|
-
break;
|
|
71
|
-
}
|
|
72
|
-
const parent = rows.slice(0, index).reverse().findIndex((entry) => entry.level < row.level);
|
|
73
|
-
if (parent >= 0) focusRow(index - 1 - parent);
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
case "Home":
|
|
77
|
-
event.preventDefault();
|
|
78
|
-
focusRow(0);
|
|
79
|
-
break;
|
|
80
|
-
case "End":
|
|
81
|
-
event.preventDefault();
|
|
82
|
-
focusRow(rows.length - 1);
|
|
83
|
-
break;
|
|
84
|
-
case "Enter":
|
|
85
|
-
case " ":
|
|
86
|
-
event.preventDefault();
|
|
87
|
-
if (row.isFolder) toggle(row.node.id);
|
|
88
|
-
select(row.node);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
const activeIndex = Math.max(rows.findIndex((row) => row.node.id === selected), 0);
|
|
92
|
-
return /* @__PURE__ */ jsx("div", {
|
|
93
|
-
ref: containerRef,
|
|
94
|
-
"data-slot": "file-tree",
|
|
95
|
-
className: cn("border-border bg-card text-card-foreground rounded-[var(--radius)] border p-1.5", className),
|
|
96
|
-
...rootProps,
|
|
97
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
98
|
-
role: "tree",
|
|
99
|
-
"aria-label": label,
|
|
100
|
-
children: rows.map((row, index) => {
|
|
101
|
-
const isSelected = row.node.id === selected;
|
|
102
|
-
const Icon = row.isFolder ? row.isExpanded ? FolderOpen : Folder : File;
|
|
103
|
-
return /* @__PURE__ */ jsxs("div", {
|
|
104
|
-
role: "treeitem",
|
|
105
|
-
"data-node": row.node.id,
|
|
106
|
-
"data-slot": "file-tree-item",
|
|
107
|
-
"aria-level": row.level,
|
|
108
|
-
"aria-selected": isSelected,
|
|
109
|
-
"aria-expanded": row.isFolder ? row.isExpanded : void 0,
|
|
110
|
-
tabIndex: index === activeIndex ? 0 : -1,
|
|
111
|
-
className: cn("focus-visible:ring-ring flex min-h-9 cursor-default items-center gap-1.5 rounded-[calc(var(--radius)-0.35rem)] pr-2 text-sm focus-visible:ring-2 focus-visible:outline-none", isSelected ? "bg-muted font-semibold" : "hover:bg-muted/60 transition-colors duration-150 motion-reduce:transition-none"),
|
|
112
|
-
style: { paddingLeft: `${(row.level - 1) * .85 + .35}rem` },
|
|
113
|
-
onClick: () => {
|
|
114
|
-
if (row.isFolder) toggle(row.node.id);
|
|
115
|
-
select(row.node);
|
|
116
|
-
},
|
|
117
|
-
onKeyDown: (event) => onKeyDown(event, row, index),
|
|
118
|
-
children: [
|
|
119
|
-
/* @__PURE__ */ jsx("span", {
|
|
120
|
-
className: "flex size-4 shrink-0 items-center justify-center",
|
|
121
|
-
children: row.isFolder ? /* @__PURE__ */ jsx(ChevronRight, {
|
|
122
|
-
"aria-hidden": "true",
|
|
123
|
-
size: 13,
|
|
124
|
-
className: cn("text-muted-foreground transition-transform duration-150 motion-reduce:transition-none", row.isExpanded && "rotate-90")
|
|
125
|
-
}) : null
|
|
126
|
-
}),
|
|
127
|
-
/* @__PURE__ */ jsx("span", {
|
|
128
|
-
"aria-hidden": "true",
|
|
129
|
-
className: "text-muted-foreground shrink-0",
|
|
130
|
-
children: row.node.icon ?? /* @__PURE__ */ jsx(Icon, { size: 15 })
|
|
131
|
-
}),
|
|
132
|
-
/* @__PURE__ */ jsx("span", {
|
|
133
|
-
className: "min-w-0 flex-1 truncate",
|
|
134
|
-
children: row.node.name
|
|
135
|
-
}),
|
|
136
|
-
row.node.meta ? /* @__PURE__ */ jsx("span", {
|
|
137
|
-
className: "text-muted-foreground shrink-0 text-xs",
|
|
138
|
-
children: row.node.meta
|
|
139
|
-
}) : null
|
|
140
|
-
]
|
|
141
|
-
}, row.node.id);
|
|
142
|
-
})
|
|
143
|
-
})
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
export { FileTree };
|