@appcorp/shadcn 1.0.10

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 (78) hide show
  1. package/README.md +138 -0
  2. package/app/layout.d.ts +7 -0
  3. package/app/layout.js +18 -0
  4. package/app/page.d.ts +2 -0
  5. package/app/page.js +16 -0
  6. package/components/badge.d.ts +9 -0
  7. package/components/badge.js +82 -0
  8. package/components/button.d.ts +10 -0
  9. package/components/button.js +91 -0
  10. package/components/card.d.ts +9 -0
  11. package/components/card.js +94 -0
  12. package/components/carousel.d.ts +19 -0
  13. package/components/carousel.js +168 -0
  14. package/components/checkbox.d.ts +9 -0
  15. package/components/checkbox.js +87 -0
  16. package/components/combobox.d.ts +70 -0
  17. package/components/combobox.js +315 -0
  18. package/components/command.d.ts +18 -0
  19. package/components/command.js +115 -0
  20. package/components/context-menu.d.ts +25 -0
  21. package/components/context-menu.js +148 -0
  22. package/components/dialog.d.ts +15 -0
  23. package/components/dialog.js +118 -0
  24. package/components/drawer.d.ts +13 -0
  25. package/components/drawer.js +115 -0
  26. package/components/dropdown-menu.d.ts +25 -0
  27. package/components/dropdown-menu.js +148 -0
  28. package/components/enhanced-dropzone.d.ts +21 -0
  29. package/components/enhanced-dropzone.js +187 -0
  30. package/components/enhanced-table-footer-action.d.ts +35 -0
  31. package/components/enhanced-table-footer-action.js +110 -0
  32. package/components/enhanced-table-footer-page.d.ts +34 -0
  33. package/components/enhanced-table-footer-page.js +132 -0
  34. package/components/enhanced-table-footer-pagination.d.ts +38 -0
  35. package/components/enhanced-table-footer-pagination.js +116 -0
  36. package/components/enhanced-table-header-action.d.ts +7 -0
  37. package/components/enhanced-table-header-action.js +21 -0
  38. package/components/enhanced-table-header-search.d.ts +12 -0
  39. package/components/enhanced-table-header-search.js +17 -0
  40. package/components/enhanced-table.d.ts +87 -0
  41. package/components/enhanced-table.js +221 -0
  42. package/components/form.d.ts +24 -0
  43. package/components/form.js +125 -0
  44. package/components/input.d.ts +8 -0
  45. package/components/input.js +86 -0
  46. package/components/label.d.ts +7 -0
  47. package/components/label.js +68 -0
  48. package/components/popover.d.ts +7 -0
  49. package/components/popover.js +82 -0
  50. package/components/select.d.ts +15 -0
  51. package/components/select.js +127 -0
  52. package/components/separator.d.ts +4 -0
  53. package/components/separator.js +66 -0
  54. package/components/shadcn-io/color-picker/index.d.ts +43 -0
  55. package/components/shadcn-io/color-picker/index.js +304 -0
  56. package/components/shadcn-io/copy-button/index.d.ts +16 -0
  57. package/components/shadcn-io/copy-button/index.js +121 -0
  58. package/components/shadcn-io/dropzone/index.d.ts +19 -0
  59. package/components/shadcn-io/dropzone/index.js +131 -0
  60. package/components/shadcn-io/gantt/index.d.ts +145 -0
  61. package/components/shadcn-io/gantt/index.js +767 -0
  62. package/components/shadcn-io/table/index.d.ts +60 -0
  63. package/components/shadcn-io/table/index.js +138 -0
  64. package/components/sonner.d.ts +4 -0
  65. package/components/sonner.js +54 -0
  66. package/components/switch.d.ts +9 -0
  67. package/components/switch.js +89 -0
  68. package/components/table.d.ts +10 -0
  69. package/components/table.js +101 -0
  70. package/components/textarea.d.ts +8 -0
  71. package/components/textarea.js +86 -0
  72. package/lib/themes.d.ts +147 -0
  73. package/lib/themes.js +150 -0
  74. package/lib/toast-utils.d.ts +44 -0
  75. package/lib/toast-utils.js +212 -0
  76. package/lib/utils.d.ts +2 -0
  77. package/lib/utils.js +12 -0
  78. package/package.json +101 -0
@@ -0,0 +1,168 @@
1
+ "use client";
2
+ "use strict";
3
+ var __assign = (this && this.__assign) || function () {
4
+ __assign = Object.assign || function(t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
+ t[p] = s[p];
9
+ }
10
+ return t;
11
+ };
12
+ return __assign.apply(this, arguments);
13
+ };
14
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
26
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
27
+ }) : function(o, v) {
28
+ o["default"] = v;
29
+ });
30
+ var __importStar = (this && this.__importStar) || (function () {
31
+ var ownKeys = function(o) {
32
+ ownKeys = Object.getOwnPropertyNames || function (o) {
33
+ var ar = [];
34
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
35
+ return ar;
36
+ };
37
+ return ownKeys(o);
38
+ };
39
+ return function (mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ })();
47
+ var __rest = (this && this.__rest) || function (s, e) {
48
+ var t = {};
49
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
50
+ t[p] = s[p];
51
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
52
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
53
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
54
+ t[p[i]] = s[p[i]];
55
+ }
56
+ return t;
57
+ };
58
+ var __importDefault = (this && this.__importDefault) || function (mod) {
59
+ return (mod && mod.__esModule) ? mod : { "default": mod };
60
+ };
61
+ Object.defineProperty(exports, "__esModule", { value: true });
62
+ exports.Carousel = Carousel;
63
+ exports.CarouselContent = CarouselContent;
64
+ exports.CarouselItem = CarouselItem;
65
+ exports.CarouselPrevious = CarouselPrevious;
66
+ exports.CarouselNext = CarouselNext;
67
+ var React = __importStar(require("react"));
68
+ var embla_carousel_react_1 = __importDefault(require("embla-carousel-react"));
69
+ var lucide_react_1 = require("lucide-react");
70
+ var utils_1 = require("../lib/utils");
71
+ var button_1 = require("./button");
72
+ var CarouselContext = React.createContext(null);
73
+ function useCarousel() {
74
+ var context = React.useContext(CarouselContext);
75
+ if (!context) {
76
+ throw new Error("useCarousel must be used within a <Carousel />");
77
+ }
78
+ return context;
79
+ }
80
+ function Carousel(_a) {
81
+ var _b = _a.orientation, orientation = _b === void 0 ? "horizontal" : _b, opts = _a.opts, setApi = _a.setApi, plugins = _a.plugins, className = _a.className, children = _a.children, props = __rest(_a, ["orientation", "opts", "setApi", "plugins", "className", "children"]);
82
+ var _c = (0, embla_carousel_react_1.default)(__assign(__assign({}, opts), { axis: orientation === "horizontal" ? "x" : "y" }), plugins), carouselRef = _c[0], api = _c[1];
83
+ var _d = React.useState(false), canScrollPrev = _d[0], setCanScrollPrev = _d[1];
84
+ var _e = React.useState(false), canScrollNext = _e[0], setCanScrollNext = _e[1];
85
+ var onSelect = React.useCallback(function (api) {
86
+ if (!api)
87
+ return;
88
+ setCanScrollPrev(api.canScrollPrev());
89
+ setCanScrollNext(api.canScrollNext());
90
+ }, []);
91
+ var scrollPrev = React.useCallback(function () {
92
+ api === null || api === void 0 ? void 0 : api.scrollPrev();
93
+ }, [api]);
94
+ var scrollNext = React.useCallback(function () {
95
+ api === null || api === void 0 ? void 0 : api.scrollNext();
96
+ }, [api]);
97
+ var handleKeyDown = React.useCallback(function (event) {
98
+ if (event.key === "ArrowLeft") {
99
+ event.preventDefault();
100
+ scrollPrev();
101
+ }
102
+ else if (event.key === "ArrowRight") {
103
+ event.preventDefault();
104
+ scrollNext();
105
+ }
106
+ }, [scrollPrev, scrollNext]);
107
+ React.useEffect(function () {
108
+ if (!api || !setApi)
109
+ return;
110
+ setApi(api);
111
+ }, [api, setApi]);
112
+ React.useEffect(function () {
113
+ if (!api)
114
+ return;
115
+ onSelect(api);
116
+ api.on("reInit", onSelect);
117
+ api.on("select", onSelect);
118
+ return function () {
119
+ api === null || api === void 0 ? void 0 : api.off("select", onSelect);
120
+ };
121
+ }, [api, onSelect]);
122
+ return (React.createElement(CarouselContext.Provider, { value: {
123
+ carouselRef: carouselRef,
124
+ api: api,
125
+ opts: opts,
126
+ orientation: orientation || ((opts === null || opts === void 0 ? void 0 : opts.axis) === "y" ? "vertical" : "horizontal"),
127
+ scrollPrev: scrollPrev,
128
+ scrollNext: scrollNext,
129
+ canScrollPrev: canScrollPrev,
130
+ canScrollNext: canScrollNext,
131
+ } },
132
+ React.createElement("div", __assign({ onKeyDownCapture: handleKeyDown, className: (0, utils_1.cn)("relative", className), role: "region", "aria-roledescription": "carousel", "data-slot": "carousel" }, props), children)));
133
+ }
134
+ function CarouselContent(_a) {
135
+ var className = _a.className, props = __rest(_a, ["className"]);
136
+ var _b = useCarousel(), carouselRef = _b.carouselRef, orientation = _b.orientation;
137
+ return (React.createElement("div", { ref: carouselRef, className: "overflow-hidden", "data-slot": "carousel-content" },
138
+ React.createElement("div", __assign({ className: (0, utils_1.cn)("flex", orientation === "horizontal" ? "-ml-4" : "-mt-4 flex-col", className) }, props))));
139
+ }
140
+ function CarouselItem(_a) {
141
+ var className = _a.className, props = __rest(_a, ["className"]);
142
+ var orientation = useCarousel().orientation;
143
+ return (React.createElement("div", __assign({ role: "group", "aria-roledescription": "slide", "data-slot": "carousel-item", className: (0, utils_1.cn)("min-w-0 shrink-0 grow-0 basis-full", orientation === "horizontal" ? "pl-4" : "pt-4", className) }, props)));
144
+ }
145
+ function CarouselPrevious(_a) {
146
+ var className = _a.className, _b = _a.variant, variant = _b === void 0 ? "outline" : _b, _c = _a.size, size = _c === void 0 ? "icon" : _c, props = __rest(_a, ["className", "variant", "size"]);
147
+ var _d = useCarousel(), orientation = _d.orientation, scrollPrev = _d.scrollPrev, canScrollPrev = _d.canScrollPrev;
148
+ return (React.createElement(button_1.Button, __assign({}, props, { "data-slot": "carousel-previous", variant: variant, size: size, className: (0, utils_1.cn)("absolute size-8 rounded-full", orientation === "horizontal"
149
+ ? "top-1/2 -left-12 -translate-y-1/2"
150
+ : "-top-12 left-1/2 -translate-x-1/2 rotate-90", className), disabled: !canScrollPrev, onClick: function (e) {
151
+ e.stopPropagation();
152
+ scrollPrev();
153
+ } }),
154
+ React.createElement(lucide_react_1.ArrowLeft, null),
155
+ React.createElement("span", { className: "sr-only" }, "Previous slide")));
156
+ }
157
+ function CarouselNext(_a) {
158
+ var className = _a.className, _b = _a.variant, variant = _b === void 0 ? "outline" : _b, _c = _a.size, size = _c === void 0 ? "icon" : _c, props = __rest(_a, ["className", "variant", "size"]);
159
+ var _d = useCarousel(), orientation = _d.orientation, scrollNext = _d.scrollNext, canScrollNext = _d.canScrollNext;
160
+ return (React.createElement(button_1.Button, __assign({}, props, { "data-slot": "carousel-next", variant: variant, size: size, className: (0, utils_1.cn)("absolute size-8 rounded-full", orientation === "horizontal"
161
+ ? "top-1/2 -right-12 -translate-y-1/2"
162
+ : "-bottom-12 left-1/2 -translate-x-1/2 rotate-90", className), disabled: !canScrollNext, onClick: function (e) {
163
+ e.stopPropagation();
164
+ scrollNext();
165
+ } }),
166
+ React.createElement(lucide_react_1.ArrowRight, null),
167
+ React.createElement("span", { className: "sr-only" }, "Next slide")));
168
+ }
@@ -0,0 +1,9 @@
1
+ import * as React from "react";
2
+ import * as CheckboxPrimitive from "@radix-ui/react-checkbox";
3
+ interface CheckboxProps extends React.ComponentProps<typeof CheckboxPrimitive.Root> {
4
+ error?: string;
5
+ info?: string;
6
+ label?: string;
7
+ }
8
+ declare function Checkbox({ className, error, info, label, id, ...props }: CheckboxProps): React.JSX.Element;
9
+ export { Checkbox };
@@ -0,0 +1,87 @@
1
+ "use client";
2
+ "use strict";
3
+ var __assign = (this && this.__assign) || function () {
4
+ __assign = Object.assign || function(t) {
5
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
6
+ s = arguments[i];
7
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
8
+ t[p] = s[p];
9
+ }
10
+ return t;
11
+ };
12
+ return __assign.apply(this, arguments);
13
+ };
14
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ var desc = Object.getOwnPropertyDescriptor(m, k);
17
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
18
+ desc = { enumerable: true, get: function() { return m[k]; } };
19
+ }
20
+ Object.defineProperty(o, k2, desc);
21
+ }) : (function(o, m, k, k2) {
22
+ if (k2 === undefined) k2 = k;
23
+ o[k2] = m[k];
24
+ }));
25
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
26
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
27
+ }) : function(o, v) {
28
+ o["default"] = v;
29
+ });
30
+ var __importStar = (this && this.__importStar) || (function () {
31
+ var ownKeys = function(o) {
32
+ ownKeys = Object.getOwnPropertyNames || function (o) {
33
+ var ar = [];
34
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
35
+ return ar;
36
+ };
37
+ return ownKeys(o);
38
+ };
39
+ return function (mod) {
40
+ if (mod && mod.__esModule) return mod;
41
+ var result = {};
42
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
43
+ __setModuleDefault(result, mod);
44
+ return result;
45
+ };
46
+ })();
47
+ var __rest = (this && this.__rest) || function (s, e) {
48
+ var t = {};
49
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
50
+ t[p] = s[p];
51
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
52
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
53
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
54
+ t[p[i]] = s[p[i]];
55
+ }
56
+ return t;
57
+ };
58
+ Object.defineProperty(exports, "__esModule", { value: true });
59
+ exports.Checkbox = Checkbox;
60
+ var React = __importStar(require("react"));
61
+ var CheckboxPrimitive = __importStar(require("@radix-ui/react-checkbox"));
62
+ var lucide_react_1 = require("lucide-react");
63
+ var utils_1 = require("../lib/utils");
64
+ var label_1 = require("./label");
65
+ function Checkbox(_a) {
66
+ var className = _a.className, error = _a.error, info = _a.info, label = _a.label, id = _a.id, props = __rest(_a, ["className", "error", "info", "label", "id"]);
67
+ // Determine if there's an error (for aria-invalid and styling)
68
+ var hasError = Boolean(error);
69
+ var checkboxElement = (React.createElement(CheckboxPrimitive.Root, __assign({ id: id, "data-slot": "checkbox", "aria-invalid": hasError, className: (0, utils_1.cn)("peer border-input dark:bg-input/30 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:data-[state=checked]:bg-primary data-[state=checked]:border-primary focus-visible:border-ring focus-visible:ring-ring/50 aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive size-4 shrink-0 rounded-[4px] border shadow-xs transition-shadow outline-none focus-visible:ring-[3px] disabled:cursor-not-allowed disabled:opacity-50",
70
+ // Error state styling
71
+ hasError &&
72
+ "data-[state=checked]:bg-destructive data-[state=unchecked]:bg-destructive/20 border-destructive focus-visible:border-destructive focus-visible:ring-destructive/20", className) }, props),
73
+ React.createElement(CheckboxPrimitive.Indicator, { "data-slot": "checkbox-indicator", className: "flex items-center justify-center text-current transition-none" },
74
+ React.createElement(lucide_react_1.CheckIcon, { className: "size-3.5" }))));
75
+ // If label is provided, render the complete checkbox with label structure
76
+ if (label) {
77
+ return (React.createElement("div", { className: "w-full space-y-2" },
78
+ React.createElement("div", { className: "flex items-center space-x-2" },
79
+ checkboxElement,
80
+ React.createElement(label_1.Label, { htmlFor: id, className: "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70" }, label)),
81
+ (error || info) && (React.createElement("div", null, error ? (React.createElement("p", { className: "text-xs text-destructive" }, error)) : info ? (React.createElement("p", { className: "text-xs text-blue-600 dark:text-blue-400" }, info)) : null))));
82
+ }
83
+ // If no label, render just the checkbox with messages (backward compatibility)
84
+ return (React.createElement("div", { className: "w-full" },
85
+ checkboxElement,
86
+ (error || info) && (React.createElement("div", null, error ? (React.createElement("p", { className: "text-xs text-destructive" }, error)) : info ? (React.createElement("p", { className: "text-xs text-blue-600 dark:text-blue-400" }, info)) : null))));
87
+ }
@@ -0,0 +1,70 @@
1
+ import React from "react";
2
+ export interface ComboboxOption {
3
+ value: string;
4
+ label: string;
5
+ id?: string;
6
+ }
7
+ interface ComboboxProps {
8
+ options: ComboboxOption[];
9
+ value?: string;
10
+ onValueChange: (value: string) => void;
11
+ onSearchChange?: (search: string) => void;
12
+ placeholder?: string;
13
+ searchPlaceholder?: string;
14
+ emptyText?: string;
15
+ loading?: boolean;
16
+ disabled?: boolean;
17
+ className?: string;
18
+ maxHeight?: number;
19
+ showScrollIndicators?: boolean;
20
+ virtualizeThreshold?: number;
21
+ label?: string;
22
+ required?: boolean;
23
+ id?: string;
24
+ info?: string;
25
+ error?: string;
26
+ }
27
+ export declare function Combobox({ className, disabled, emptyText, error, id, info, label, loading, maxHeight, onSearchChange, onValueChange, options, placeholder, required, searchPlaceholder, showScrollIndicators, value, virtualizeThreshold, }: ComboboxProps): React.JSX.Element;
28
+ interface CompanyComboboxProps {
29
+ companies: Array<{
30
+ id?: string;
31
+ name: string;
32
+ }>;
33
+ value?: string;
34
+ onValueChange: (value: string) => void;
35
+ onSearchChange: (search: string) => void;
36
+ loading?: boolean;
37
+ placeholder?: string;
38
+ className?: string;
39
+ maxHeight?: number;
40
+ showScrollIndicators?: boolean;
41
+ label?: string;
42
+ required?: boolean;
43
+ id?: string;
44
+ info?: string;
45
+ error?: string;
46
+ }
47
+ export declare function CompanyCombobox({ companies, value, onValueChange, onSearchChange, loading, placeholder, className, maxHeight, showScrollIndicators, label, required, id, info, error, }: CompanyComboboxProps): React.JSX.Element;
48
+ interface CountryComboboxProps {
49
+ countries?: Array<{
50
+ name: string;
51
+ code?: string;
52
+ }> | Array<{
53
+ name: string;
54
+ }>;
55
+ value?: string;
56
+ onValueChange: (value: string) => void;
57
+ onSearchChange?: (search: string) => void;
58
+ loading?: boolean;
59
+ placeholder?: string;
60
+ className?: string;
61
+ maxHeight?: number;
62
+ showScrollIndicators?: boolean;
63
+ label?: string;
64
+ required?: boolean;
65
+ id?: string;
66
+ info?: string;
67
+ error?: string;
68
+ }
69
+ export declare function CountryCombobox({ countries, value, onValueChange, onSearchChange, loading, placeholder, className, maxHeight, showScrollIndicators, label, required, id, info, error, }: CountryComboboxProps): React.JSX.Element;
70
+ export {};
@@ -0,0 +1,315 @@
1
+ "use client";
2
+ "use strict";
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.Combobox = Combobox;
38
+ exports.CompanyCombobox = CompanyCombobox;
39
+ exports.CountryCombobox = CountryCombobox;
40
+ var react_1 = __importStar(require("react"));
41
+ var lucide_react_1 = require("lucide-react");
42
+ var utils_1 = require("../lib/utils");
43
+ var button_1 = require("./button");
44
+ var label_1 = require("./label");
45
+ var command_1 = require("./command");
46
+ var popover_1 = require("./popover");
47
+ function VirtualizedList(_a) {
48
+ var options = _a.options, selectedValue = _a.selectedValue, onSelect = _a.onSelect, scrollContainer = _a.scrollContainer;
49
+ var _b = (0, react_1.useState)({
50
+ start: 0,
51
+ end: Math.min(options.length, 25), // Increased initial visible items
52
+ }), visibleRange = _b[0], setVisibleRange = _b[1];
53
+ var handleScroll = (0, react_1.useCallback)(function () {
54
+ if (!scrollContainer.current)
55
+ return;
56
+ var _a = scrollContainer.current, scrollTop = _a.scrollTop, clientHeight = _a.clientHeight;
57
+ var itemHeight = 32; // Approximate item height
58
+ var containerHeight = clientHeight;
59
+ // Calculate visible range with proper bounds checking
60
+ var start = Math.max(0, Math.floor(scrollTop / itemHeight));
61
+ var visibleCount = Math.ceil(containerHeight / itemHeight);
62
+ var bufferSize = Math.min(10, Math.ceil(visibleCount * 0.5)); // Dynamic buffer
63
+ var end = Math.min(options.length, start + visibleCount + bufferSize);
64
+ var newRange = {
65
+ start: Math.max(0, start - bufferSize),
66
+ end: end,
67
+ };
68
+ // Only update if the range actually changed to prevent unnecessary re-renders
69
+ setVisibleRange(function (prevRange) {
70
+ if (prevRange.start !== newRange.start ||
71
+ prevRange.end !== newRange.end) {
72
+ return newRange;
73
+ }
74
+ return prevRange;
75
+ });
76
+ }, [options.length, scrollContainer]);
77
+ (0, react_1.useEffect)(function () {
78
+ var container = scrollContainer.current;
79
+ if (container) {
80
+ // Add scroll listener with passive option for better performance
81
+ container.addEventListener("scroll", handleScroll, { passive: true });
82
+ // Also listen to parent containers that might interfere (like drawer)
83
+ var parentContainer_1 = container.parentElement;
84
+ var parentScrollHandler_1 = function () { return handleScroll(); };
85
+ while (parentContainer_1) {
86
+ var hasOverflow = getComputedStyle(parentContainer_1).overflowY;
87
+ if (hasOverflow === "auto" || hasOverflow === "scroll") {
88
+ parentContainer_1.addEventListener("scroll", parentScrollHandler_1, {
89
+ passive: true,
90
+ });
91
+ break;
92
+ }
93
+ parentContainer_1 = parentContainer_1.parentElement;
94
+ }
95
+ return function () {
96
+ container.removeEventListener("scroll", handleScroll);
97
+ if (parentContainer_1) {
98
+ parentContainer_1.removeEventListener("scroll", parentScrollHandler_1);
99
+ }
100
+ };
101
+ }
102
+ }, [handleScroll, scrollContainer]);
103
+ // Reset visible range when options change (e.g., due to search filtering)
104
+ (0, react_1.useEffect)(function () {
105
+ var newEnd = Math.min(options.length, 25);
106
+ setVisibleRange(function () {
107
+ // Force update if options changed
108
+ return {
109
+ start: 0,
110
+ end: newEnd,
111
+ };
112
+ });
113
+ // Reset scroll position when options change
114
+ if (scrollContainer.current) {
115
+ scrollContainer.current.scrollTop = 0;
116
+ }
117
+ }, [options.length, options, scrollContainer]); // Watch both length and options array
118
+ // Ensure we always have valid visible range
119
+ var safeStart = Math.max(0, Math.min(visibleRange.start, options.length - 1));
120
+ var safeEnd = Math.max(safeStart + 1, Math.min(visibleRange.end, options.length));
121
+ var visibleOptions = options.slice(safeStart, safeEnd);
122
+ var topSpacer = safeStart * 32; // Approximate item height
123
+ var bottomSpacer = Math.max(0, (options.length - safeEnd) * 32);
124
+ return (react_1.default.createElement(react_1.default.Fragment, null,
125
+ topSpacer > 0 && react_1.default.createElement("div", { style: { height: topSpacer } }),
126
+ visibleOptions.map(function (option, index) { return (react_1.default.createElement(command_1.CommandItem, { key: "".concat(option.value, "-").concat(safeStart + index), value: option.label, onSelect: function () { return onSelect(option.value); }, className: "cursor-pointer hover:bg-accent hover:text-accent-foreground transition-colors h-8 flex items-center" },
127
+ react_1.default.createElement(lucide_react_1.Check, { className: (0, utils_1.cn)("mr-2 h-4 w-4", selectedValue === option.value ? "opacity-100" : "opacity-0") }),
128
+ react_1.default.createElement("span", { className: "truncate" }, option.label))); }),
129
+ bottomSpacer > 0 && react_1.default.createElement("div", { style: { height: bottomSpacer } })));
130
+ }
131
+ function Combobox(_a) {
132
+ var className = _a.className, _b = _a.disabled, disabled = _b === void 0 ? false : _b, _c = _a.emptyText, emptyText = _c === void 0 ? "No options found." : _c, error = _a.error, id = _a.id, info = _a.info, label = _a.label, _d = _a.loading, loading = _d === void 0 ? false : _d, _e = _a.maxHeight, maxHeight = _e === void 0 ? 256 : _e, onSearchChange = _a.onSearchChange, onValueChange = _a.onValueChange, _f = _a.options, options = _f === void 0 ? [] : _f, _g = _a.placeholder, placeholder = _g === void 0 ? "Select option..." : _g, _h = _a.required, required = _h === void 0 ? false : _h, _j = _a.searchPlaceholder, searchPlaceholder = _j === void 0 ? "Search..." : _j, _k = _a.showScrollIndicators, showScrollIndicators = _k === void 0 ? true : _k, value = _a.value, _l = _a.virtualizeThreshold, virtualizeThreshold = _l === void 0 ? 50 : _l;
133
+ var _m = (0, react_1.useState)(false), open = _m[0], setOpen = _m[1];
134
+ var _o = (0, react_1.useState)(""), searchValue = _o[0], setSearchValue = _o[1];
135
+ var _p = (0, react_1.useState)(false), canScrollUp = _p[0], setCanScrollUp = _p[1];
136
+ var _q = (0, react_1.useState)(false), canScrollDown = _q[0], setCanScrollDown = _q[1];
137
+ var scrollContainerRef = (0, react_1.useRef)(null);
138
+ var selectedOption = options.find(function (option) { return option.value === value; });
139
+ var shouldVirtualize = options.length > virtualizeThreshold;
140
+ // Filter options based on search - always handle filtering at this level for virtualization
141
+ var filteredOptions = react_1.default.useMemo(function () {
142
+ if (!searchValue) {
143
+ // No search query, return all options
144
+ return options;
145
+ }
146
+ if (onSearchChange && shouldVirtualize) {
147
+ // For virtualized lists with external search, let external handler manage it
148
+ // but still return all current options as they're already filtered externally
149
+ return options;
150
+ }
151
+ if (onSearchChange && !shouldVirtualize) {
152
+ // Non-virtualized with external search - let external handler manage
153
+ return options;
154
+ }
155
+ // Local filtering for non-external search or as fallback
156
+ return options.filter(function (option) {
157
+ return option.label.toLowerCase().includes(searchValue.toLowerCase());
158
+ });
159
+ }, [options, searchValue, onSearchChange, shouldVirtualize]);
160
+ var handleSearchChange = function (search) {
161
+ setSearchValue(search);
162
+ onSearchChange === null || onSearchChange === void 0 ? void 0 : onSearchChange(search);
163
+ };
164
+ var handleSelect = function (selectedValue) {
165
+ if (selectedValue === value) {
166
+ onValueChange("");
167
+ }
168
+ else {
169
+ onValueChange(selectedValue);
170
+ }
171
+ setOpen(false);
172
+ setSearchValue("");
173
+ };
174
+ // Handle scroll indicators
175
+ var updateScrollIndicators = function () {
176
+ if (!scrollContainerRef.current)
177
+ return;
178
+ var _a = scrollContainerRef.current, scrollTop = _a.scrollTop, scrollHeight = _a.scrollHeight, clientHeight = _a.clientHeight;
179
+ setCanScrollUp(scrollTop > 0);
180
+ setCanScrollDown(scrollTop < scrollHeight - clientHeight - 1);
181
+ };
182
+ // Update scroll indicators when options change or component opens
183
+ (0, react_1.useEffect)(function () {
184
+ if (open) {
185
+ // Small delay to ensure DOM is updated
186
+ setTimeout(updateScrollIndicators, 10);
187
+ }
188
+ }, [open, options]);
189
+ var scrollToTop = function () {
190
+ var _a;
191
+ (_a = scrollContainerRef.current) === null || _a === void 0 ? void 0 : _a.scrollTo({ top: 0, behavior: "smooth" });
192
+ };
193
+ var scrollToBottom = function () {
194
+ if (!scrollContainerRef.current)
195
+ return;
196
+ var scrollHeight = scrollContainerRef.current.scrollHeight;
197
+ scrollContainerRef.current.scrollTo({
198
+ top: scrollHeight,
199
+ behavior: "smooth",
200
+ });
201
+ };
202
+ var comboboxElement = (react_1.default.createElement(popover_1.Popover, { open: open, onOpenChange: setOpen, modal: true },
203
+ react_1.default.createElement(popover_1.PopoverTrigger, { asChild: true },
204
+ react_1.default.createElement(button_1.Button, { id: id, variant: "outline", role: "combobox", "aria-expanded": open, disabled: disabled, className: (0, utils_1.cn)("w-full justify-between", !selectedOption && "text-muted-foreground", className) },
205
+ (selectedOption === null || selectedOption === void 0 ? void 0 : selectedOption.label) || placeholder,
206
+ react_1.default.createElement(lucide_react_1.ChevronsUpDown, { className: "ml-2 h-4 w-4 shrink-0 opacity-50" }))),
207
+ react_1.default.createElement(popover_1.PopoverContent, { className: "w-[var(--radix-popover-trigger-width)] p-0", side: "bottom", align: "start", avoidCollisions: true, collisionPadding: 8, style: { zIndex: 1000 }, onOpenAutoFocus: function (e) { return e.preventDefault(); } },
208
+ react_1.default.createElement(command_1.Command, { shouldFilter: false },
209
+ react_1.default.createElement(command_1.CommandInput, { placeholder: searchPlaceholder, value: searchValue, onValueChange: handleSearchChange }),
210
+ react_1.default.createElement(command_1.CommandEmpty, null, loading ? (react_1.default.createElement("div", { className: "flex items-center justify-center py-6" },
211
+ react_1.default.createElement("div", { className: "animate-spin rounded-full h-4 w-4 border-b-2 border-primary" }),
212
+ react_1.default.createElement("span", { className: "ml-2 text-sm" }, "Searching..."))) : (emptyText)),
213
+ react_1.default.createElement("div", { className: "relative" },
214
+ showScrollIndicators && canScrollUp && (react_1.default.createElement("div", { className: "absolute top-0 left-0 right-0 z-10 h-8 bg-gradient-to-b from-background to-transparent pointer-events-none" },
215
+ react_1.default.createElement("button", { onClick: scrollToTop, className: "absolute top-1 left-1/2 transform -translate-x-1/2 p-1 rounded-full bg-background shadow-sm border pointer-events-auto hover:bg-muted transition-colors", "aria-label": "Scroll to top" },
216
+ react_1.default.createElement(lucide_react_1.ChevronUp, { className: "h-3 w-3" })))),
217
+ react_1.default.createElement(command_1.CommandGroup, { ref: scrollContainerRef, className: (0, utils_1.cn)("overflow-y-auto smooth-scroll", "scrollbar-thin scrollbar-thumb-muted-foreground/20 scrollbar-track-transparent hover:scrollbar-thumb-muted-foreground/40", "scroll-smooth", filteredOptions.length > 10 && "pb-2" // Extra padding for many options
218
+ ), style: { maxHeight: "".concat(maxHeight, "px") }, onScroll: updateScrollIndicators }, shouldVirtualize &&
219
+ filteredOptions.length > virtualizeThreshold ? (
220
+ // Virtualized rendering for large lists
221
+ react_1.default.createElement(VirtualizedList, { options: filteredOptions, selectedValue: value, onSelect: handleSelect, scrollContainer: scrollContainerRef })) : (
222
+ // Regular rendering for smaller lists or filtered results
223
+ filteredOptions.map(function (option) { return (react_1.default.createElement(command_1.CommandItem, { key: option.value, value: option.label, onSelect: function () { return handleSelect(option.value); }, className: "cursor-pointer hover:bg-accent hover:text-accent-foreground transition-colors" },
224
+ react_1.default.createElement(lucide_react_1.Check, { className: (0, utils_1.cn)("mr-2 h-4 w-4", value === option.value ? "opacity-100" : "opacity-0") }),
225
+ react_1.default.createElement("span", { className: "truncate" }, option.label))); }))),
226
+ showScrollIndicators && canScrollDown && (react_1.default.createElement("div", { className: "absolute bottom-0 left-0 right-0 z-10 h-8 bg-gradient-to-t from-background to-transparent pointer-events-none" },
227
+ react_1.default.createElement("button", { onClick: scrollToBottom, className: "absolute bottom-1 left-1/2 transform -translate-x-1/2 p-1 rounded-full bg-background shadow-sm border pointer-events-auto hover:bg-muted transition-colors", "aria-label": "Scroll to bottom" },
228
+ react_1.default.createElement(lucide_react_1.ChevronDown, { className: "h-3 w-3" })))))))));
229
+ // If label is provided, render the complete combobox with label structure
230
+ if (label) {
231
+ return (react_1.default.createElement("div", { className: "w-full space-y-2" },
232
+ react_1.default.createElement(label_1.Label, { htmlFor: id, required: required }, label),
233
+ comboboxElement,
234
+ error && (react_1.default.createElement("p", { className: "text-xs text-destructive dark:text-red-400" }, error)),
235
+ info && !error && (react_1.default.createElement("p", { className: "text-xs text-blue-600 dark:text-blue-400" }, info))));
236
+ }
237
+ // If no label, render just the combobox (backward compatibility)
238
+ return comboboxElement;
239
+ }
240
+ function CompanyCombobox(_a) {
241
+ var _b = _a.companies, companies = _b === void 0 ? [] : _b, value = _a.value, onValueChange = _a.onValueChange, onSearchChange = _a.onSearchChange, _c = _a.loading, loading = _c === void 0 ? false : _c, _d = _a.placeholder, placeholder = _d === void 0 ? "Select company..." : _d, className = _a.className, _e = _a.maxHeight, maxHeight = _e === void 0 ? 320 : _e, _f = _a.showScrollIndicators, showScrollIndicators = _f === void 0 ? true : _f, label = _a.label, _g = _a.required, required = _g === void 0 ? false : _g, id = _a.id, info = _a.info, error = _a.error;
242
+ var options = companies.map(function (company) {
243
+ var _a, _b;
244
+ return ({
245
+ value: ((_a = company.id) === null || _a === void 0 ? void 0 : _a.toString()) || "",
246
+ label: company.name,
247
+ id: (_b = company.id) === null || _b === void 0 ? void 0 : _b.toString(),
248
+ });
249
+ });
250
+ return (react_1.default.createElement(Combobox, { options: options, value: value, onValueChange: onValueChange, onSearchChange: onSearchChange, placeholder: placeholder, searchPlaceholder: "Search companies...", emptyText: "No companies found.", loading: loading, className: className, maxHeight: maxHeight, showScrollIndicators: showScrollIndicators, virtualizeThreshold: 100, label: label, required: required, id: id, info: info, error: error }));
251
+ }
252
+ function CountryCombobox(_a) {
253
+ var _b = _a.countries, countries = _b === void 0 ? [] : _b, value = _a.value, onValueChange = _a.onValueChange, onSearchChange = _a.onSearchChange, _c = _a.loading, loading = _c === void 0 ? false : _c, _d = _a.placeholder, placeholder = _d === void 0 ? "Select country..." : _d, className = _a.className, _e = _a.maxHeight, maxHeight = _e === void 0 ? 280 : _e, _f = _a.showScrollIndicators, showScrollIndicators = _f === void 0 ? true : _f, label = _a.label, _g = _a.required, required = _g === void 0 ? false : _g, id = _a.id, info = _a.info, error = _a.error;
254
+ // Default countries if none provided or if provided list is empty
255
+ var defaultCountries = [
256
+ { name: "Afghanistan", code: "AF" },
257
+ { name: "Albania", code: "AL" },
258
+ { name: "Algeria", code: "DZ" },
259
+ { name: "Argentina", code: "AR" },
260
+ { name: "Australia", code: "AU" },
261
+ { name: "Austria", code: "AT" },
262
+ { name: "Bangladesh", code: "BD" },
263
+ { name: "Belgium", code: "BE" },
264
+ { name: "Brazil", code: "BR" },
265
+ { name: "Canada", code: "CA" },
266
+ { name: "China", code: "CN" },
267
+ { name: "Denmark", code: "DK" },
268
+ { name: "Egypt", code: "EG" },
269
+ { name: "Finland", code: "FI" },
270
+ { name: "France", code: "FR" },
271
+ { name: "Germany", code: "DE" },
272
+ { name: "Greece", code: "GR" },
273
+ { name: "India", code: "IN" },
274
+ { name: "Indonesia", code: "ID" },
275
+ { name: "Iran", code: "IR" },
276
+ { name: "Iraq", code: "IQ" },
277
+ { name: "Ireland", code: "IE" },
278
+ { name: "Israel", code: "IL" },
279
+ { name: "Italy", code: "IT" },
280
+ { name: "Japan", code: "JP" },
281
+ { name: "Jordan", code: "JO" },
282
+ { name: "Kenya", code: "KE" },
283
+ { name: "Malaysia", code: "MY" },
284
+ { name: "Mexico", code: "MX" },
285
+ { name: "Netherlands", code: "NL" },
286
+ { name: "New Zealand", code: "NZ" },
287
+ { name: "Nigeria", code: "NG" },
288
+ { name: "Norway", code: "NO" },
289
+ { name: "Pakistan", code: "PK" },
290
+ { name: "Philippines", code: "PH" },
291
+ { name: "Poland", code: "PL" },
292
+ { name: "Portugal", code: "PT" },
293
+ { name: "Russia", code: "RU" },
294
+ { name: "Saudi Arabia", code: "SA" },
295
+ { name: "Singapore", code: "SG" },
296
+ { name: "South Africa", code: "ZA" },
297
+ { name: "South Korea", code: "KR" },
298
+ { name: "Spain", code: "ES" },
299
+ { name: "Sweden", code: "SE" },
300
+ { name: "Switzerland", code: "CH" },
301
+ { name: "Thailand", code: "TH" },
302
+ { name: "Turkey", code: "TR" },
303
+ { name: "Ukraine", code: "UA" },
304
+ { name: "United Arab Emirates", code: "AE" },
305
+ { name: "United Kingdom", code: "GB" },
306
+ { name: "United States", code: "US" },
307
+ { name: "Vietnam", code: "VN" },
308
+ ];
309
+ var countryList = countries.length > 0 ? countries : defaultCountries;
310
+ var options = countryList.map(function (country) { return ({
311
+ value: country.name,
312
+ label: country.name,
313
+ }); });
314
+ return (react_1.default.createElement(Combobox, { options: options, value: value, onValueChange: onValueChange, onSearchChange: onSearchChange, placeholder: placeholder, searchPlaceholder: "Search countries...", emptyText: "No countries found.", loading: loading, className: className, maxHeight: maxHeight, showScrollIndicators: showScrollIndicators, virtualizeThreshold: 30, label: label, required: required, id: id, info: info, error: error }));
315
+ }