@starwind-ui/core 1.15.0 → 1.15.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/package.json +1 -1
- package/dist/index.d.ts +0 -28
- package/dist/index.js +0 -108
- package/dist/index.js.map +0 -1
- package/dist/src/components/accordion/Accordion.astro +0 -254
- package/dist/src/components/accordion/AccordionContent.astro +0 -33
- package/dist/src/components/accordion/AccordionItem.astro +0 -27
- package/dist/src/components/accordion/AccordionTrigger.astro +0 -32
- package/dist/src/components/accordion/index.ts +0 -15
- package/dist/src/components/alert/Alert.astro +0 -31
- package/dist/src/components/alert/AlertDescription.astro +0 -14
- package/dist/src/components/alert/AlertTitle.astro +0 -16
- package/dist/src/components/alert/index.ts +0 -13
- package/dist/src/components/alert-dialog/AlertDialog.astro +0 -275
- package/dist/src/components/alert-dialog/AlertDialogAction.astro +0 -44
- package/dist/src/components/alert-dialog/AlertDialogCancel.astro +0 -45
- package/dist/src/components/alert-dialog/AlertDialogContent.astro +0 -52
- package/dist/src/components/alert-dialog/AlertDialogDescription.astro +0 -18
- package/dist/src/components/alert-dialog/AlertDialogFooter.astro +0 -16
- package/dist/src/components/alert-dialog/AlertDialogHeader.astro +0 -14
- package/dist/src/components/alert-dialog/AlertDialogTitle.astro +0 -20
- package/dist/src/components/alert-dialog/AlertDialogTrigger.astro +0 -47
- package/dist/src/components/alert-dialog/index.ts +0 -46
- package/dist/src/components/aspect-ratio/AspectRatio.astro +0 -32
- package/dist/src/components/aspect-ratio/index.ts +0 -7
- package/dist/src/components/avatar/Avatar.astro +0 -29
- package/dist/src/components/avatar/AvatarFallback.astro +0 -18
- package/dist/src/components/avatar/AvatarImage.astro +0 -49
- package/dist/src/components/avatar/index.ts +0 -13
- package/dist/src/components/badge/Badge.astro +0 -55
- package/dist/src/components/badge/index.ts +0 -7
- package/dist/src/components/breadcrumb/Breadcrumb.astro +0 -11
- package/dist/src/components/breadcrumb/BreadcrumbEllipsis.astro +0 -28
- package/dist/src/components/breadcrumb/BreadcrumbItem.astro +0 -14
- package/dist/src/components/breadcrumb/BreadcrumbLink.astro +0 -22
- package/dist/src/components/breadcrumb/BreadcrumbList.astro +0 -16
- package/dist/src/components/breadcrumb/BreadcrumbPage.astro +0 -21
- package/dist/src/components/breadcrumb/BreadcrumbSeparator.astro +0 -23
- package/dist/src/components/breadcrumb/index.ts +0 -37
- package/dist/src/components/button/Button.astro +0 -55
- package/dist/src/components/button/index.ts +0 -7
- package/dist/src/components/button-group/ButtonGroup.astro +0 -62
- package/dist/src/components/button-group/ButtonGroupSeparator.astro +0 -27
- package/dist/src/components/button-group/ButtonGroupText.astro +0 -19
- package/dist/src/components/button-group/index.ts +0 -17
- package/dist/src/components/card/Card.astro +0 -14
- package/dist/src/components/card/CardContent.astro +0 -14
- package/dist/src/components/card/CardDescription.astro +0 -14
- package/dist/src/components/card/CardFooter.astro +0 -14
- package/dist/src/components/card/CardHeader.astro +0 -14
- package/dist/src/components/card/CardTitle.astro +0 -14
- package/dist/src/components/card/index.ts +0 -26
- package/dist/src/components/carousel/Carousel.astro +0 -55
- package/dist/src/components/carousel/CarouselContent.astro +0 -26
- package/dist/src/components/carousel/CarouselItem.astro +0 -26
- package/dist/src/components/carousel/CarouselNext.astro +0 -37
- package/dist/src/components/carousel/CarouselPrevious.astro +0 -37
- package/dist/src/components/carousel/carousel-script.ts +0 -191
- package/dist/src/components/carousel/index.ts +0 -32
- package/dist/src/components/checkbox/Checkbox.astro +0 -128
- package/dist/src/components/checkbox/index.ts +0 -7
- package/dist/src/components/collapsible/Collapsible.astro +0 -161
- package/dist/src/components/collapsible/CollapsibleContent.astro +0 -22
- package/dist/src/components/collapsible/CollapsibleTrigger.astro +0 -44
- package/dist/src/components/collapsible/index.ts +0 -13
- package/dist/src/components/dialog/Dialog.astro +0 -389
- package/dist/src/components/dialog/DialogClose.astro +0 -35
- package/dist/src/components/dialog/DialogContent.astro +0 -78
- package/dist/src/components/dialog/DialogDescription.astro +0 -14
- package/dist/src/components/dialog/DialogFooter.astro +0 -14
- package/dist/src/components/dialog/DialogHeader.astro +0 -14
- package/dist/src/components/dialog/DialogTitle.astro +0 -22
- package/dist/src/components/dialog/DialogTrigger.astro +0 -47
- package/dist/src/components/dialog/index.ts +0 -45
- package/dist/src/components/dropdown/Dropdown.astro +0 -377
- package/dist/src/components/dropdown/DropdownContent.astro +0 -81
- package/dist/src/components/dropdown/DropdownItem.astro +0 -48
- package/dist/src/components/dropdown/DropdownLabel.astro +0 -29
- package/dist/src/components/dropdown/DropdownSeparator.astro +0 -21
- package/dist/src/components/dropdown/DropdownTrigger.astro +0 -52
- package/dist/src/components/dropdown/index.ts +0 -33
- package/dist/src/components/dropzone/Dropzone.astro +0 -236
- package/dist/src/components/dropzone/DropzoneFilesList.astro +0 -26
- package/dist/src/components/dropzone/DropzoneLoadingIndicator.astro +0 -10
- package/dist/src/components/dropzone/DropzoneUploadIndicator.astro +0 -10
- package/dist/src/components/dropzone/index.ts +0 -24
- package/dist/src/components/image/Image.astro +0 -24
- package/dist/src/components/image/index.ts +0 -9
- package/dist/src/components/input/Input.astro +0 -25
- package/dist/src/components/input/index.ts +0 -7
- package/dist/src/components/input-otp/InputOtp.astro +0 -319
- package/dist/src/components/input-otp/InputOtpGroup.astro +0 -16
- package/dist/src/components/input-otp/InputOtpSeparator.astro +0 -25
- package/dist/src/components/input-otp/InputOtpSlot.astro +0 -48
- package/dist/src/components/input-otp/InputOtpTypes.ts +0 -6
- package/dist/src/components/input-otp/index.ts +0 -33
- package/dist/src/components/item/Item.astro +0 -52
- package/dist/src/components/item/ItemActions.astro +0 -16
- package/dist/src/components/item/ItemContent.astro +0 -16
- package/dist/src/components/item/ItemDescription.astro +0 -19
- package/dist/src/components/item/ItemFooter.astro +0 -16
- package/dist/src/components/item/ItemGroup.astro +0 -16
- package/dist/src/components/item/ItemHeader.astro +0 -16
- package/dist/src/components/item/ItemMedia.astro +0 -40
- package/dist/src/components/item/ItemSeparator.astro +0 -21
- package/dist/src/components/item/ItemTitle.astro +0 -16
- package/dist/src/components/item/index.ts +0 -50
- package/dist/src/components/kbd/Kbd.astro +0 -21
- package/dist/src/components/kbd/KbdGroup.astro +0 -16
- package/dist/src/components/kbd/index.ts +0 -11
- package/dist/src/components/label/Label.astro +0 -22
- package/dist/src/components/label/index.ts +0 -7
- package/dist/src/components/pagination/Pagination.astro +0 -20
- package/dist/src/components/pagination/PaginationContent.astro +0 -16
- package/dist/src/components/pagination/PaginationEllipsis.astro +0 -35
- package/dist/src/components/pagination/PaginationItem.astro +0 -16
- package/dist/src/components/pagination/PaginationLink.astro +0 -24
- package/dist/src/components/pagination/PaginationNext.astro +0 -30
- package/dist/src/components/pagination/PaginationPrevious.astro +0 -30
- package/dist/src/components/pagination/index.ts +0 -38
- package/dist/src/components/progress/Progress.astro +0 -155
- package/dist/src/components/progress/index.ts +0 -10
- package/dist/src/components/prose/Prose.astro +0 -617
- package/dist/src/components/prose/index.ts +0 -9
- package/dist/src/components/radio-group/RadioGroup.astro +0 -162
- package/dist/src/components/radio-group/RadioGroupItem.astro +0 -129
- package/dist/src/components/radio-group/RadioGroupTypes.ts +0 -6
- package/dist/src/components/radio-group/index.ts +0 -23
- package/dist/src/components/select/Select.astro +0 -751
- package/dist/src/components/select/SelectContent.astro +0 -94
- package/dist/src/components/select/SelectGroup.astro +0 -9
- package/dist/src/components/select/SelectItem.astro +0 -51
- package/dist/src/components/select/SelectLabel.astro +0 -14
- package/dist/src/components/select/SelectSearch.astro +0 -49
- package/dist/src/components/select/SelectSeparator.astro +0 -12
- package/dist/src/components/select/SelectTrigger.astro +0 -54
- package/dist/src/components/select/SelectTypes.ts +0 -13
- package/dist/src/components/select/SelectValue.astro +0 -19
- package/dist/src/components/select/index.ts +0 -49
- package/dist/src/components/separator/Separator.astro +0 -36
- package/dist/src/components/separator/index.ts +0 -7
- package/dist/src/components/sheet/Sheet.astro +0 -13
- package/dist/src/components/sheet/SheetClose.astro +0 -13
- package/dist/src/components/sheet/SheetContent.astro +0 -92
- package/dist/src/components/sheet/SheetDescription.astro +0 -16
- package/dist/src/components/sheet/SheetFooter.astro +0 -16
- package/dist/src/components/sheet/SheetHeader.astro +0 -16
- package/dist/src/components/sheet/SheetTitle.astro +0 -16
- package/dist/src/components/sheet/SheetTrigger.astro +0 -13
- package/dist/src/components/sheet/index.ts +0 -41
- package/dist/src/components/sidebar/Sidebar.astro +0 -213
- package/dist/src/components/sidebar/SidebarContent.astro +0 -24
- package/dist/src/components/sidebar/SidebarFooter.astro +0 -21
- package/dist/src/components/sidebar/SidebarGroup.astro +0 -21
- package/dist/src/components/sidebar/SidebarGroupContent.astro +0 -21
- package/dist/src/components/sidebar/SidebarGroupLabel.astro +0 -52
- package/dist/src/components/sidebar/SidebarHeader.astro +0 -21
- package/dist/src/components/sidebar/SidebarInput.astro +0 -22
- package/dist/src/components/sidebar/SidebarInset.astro +0 -21
- package/dist/src/components/sidebar/SidebarMenu.astro +0 -21
- package/dist/src/components/sidebar/SidebarMenuAction.astro +0 -59
- package/dist/src/components/sidebar/SidebarMenuBadge.astro +0 -30
- package/dist/src/components/sidebar/SidebarMenuButton.astro +0 -129
- package/dist/src/components/sidebar/SidebarMenuItem.astro +0 -21
- package/dist/src/components/sidebar/SidebarMenuSkeleton.astro +0 -40
- package/dist/src/components/sidebar/SidebarMenuSub.astro +0 -24
- package/dist/src/components/sidebar/SidebarMenuSubButton.astro +0 -49
- package/dist/src/components/sidebar/SidebarMenuSubItem.astro +0 -16
- package/dist/src/components/sidebar/SidebarProvider.astro +0 -213
- package/dist/src/components/sidebar/SidebarRail.astro +0 -71
- package/dist/src/components/sidebar/SidebarSeparator.astro +0 -22
- package/dist/src/components/sidebar/SidebarTrigger.astro +0 -66
- package/dist/src/components/sidebar/index.ts +0 -103
- package/dist/src/components/skeleton/Skeleton.astro +0 -14
- package/dist/src/components/skeleton/index.ts +0 -9
- package/dist/src/components/slider/Slider.astro +0 -411
- package/dist/src/components/slider/index.ts +0 -9
- package/dist/src/components/spinner/Spinner.astro +0 -21
- package/dist/src/components/spinner/index.ts +0 -7
- package/dist/src/components/switch/Switch.astro +0 -192
- package/dist/src/components/switch/SwitchTypes.ts +0 -6
- package/dist/src/components/switch/index.ts +0 -12
- package/dist/src/components/table/Table.astro +0 -18
- package/dist/src/components/table/TableBody.astro +0 -16
- package/dist/src/components/table/TableCaption.astro +0 -16
- package/dist/src/components/table/TableCell.astro +0 -16
- package/dist/src/components/table/TableFoot.astro +0 -16
- package/dist/src/components/table/TableHead.astro +0 -16
- package/dist/src/components/table/TableHeader.astro +0 -16
- package/dist/src/components/table/TableRow.astro +0 -16
- package/dist/src/components/table/index.ts +0 -42
- package/dist/src/components/tabs/Tabs.astro +0 -271
- package/dist/src/components/tabs/TabsContent.astro +0 -28
- package/dist/src/components/tabs/TabsList.astro +0 -22
- package/dist/src/components/tabs/TabsTrigger.astro +0 -34
- package/dist/src/components/tabs/index.ts +0 -20
- package/dist/src/components/textarea/Textarea.astro +0 -29
- package/dist/src/components/textarea/index.ts +0 -9
- package/dist/src/components/theme-toggle/ThemeToggle.astro +0 -208
- package/dist/src/components/theme-toggle/index.ts +0 -7
- package/dist/src/components/toast/ToastDescription.astro +0 -21
- package/dist/src/components/toast/ToastItem.astro +0 -54
- package/dist/src/components/toast/ToastTemplate.astro +0 -25
- package/dist/src/components/toast/ToastTitle.astro +0 -57
- package/dist/src/components/toast/Toaster.astro +0 -982
- package/dist/src/components/toast/index.ts +0 -29
- package/dist/src/components/toast/toast-manager.ts +0 -216
- package/dist/src/components/toggle/Toggle.astro +0 -174
- package/dist/src/components/toggle/ToggleTypes.ts +0 -14
- package/dist/src/components/toggle/index.ts +0 -8
- package/dist/src/components/tooltip/Tooltip.astro +0 -282
- package/dist/src/components/tooltip/TooltipContent.astro +0 -89
- package/dist/src/components/tooltip/TooltipTrigger.astro +0 -10
- package/dist/src/components/tooltip/index.ts +0 -16
- package/dist/src/components/video/Video.astro +0 -120
- package/dist/src/components/video/index.ts +0 -9
|
@@ -1,319 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props = HTMLAttributes<"div"> & {
|
|
6
|
-
maxLength?: number;
|
|
7
|
-
value?: string;
|
|
8
|
-
defaultValue?: string;
|
|
9
|
-
disabled?: boolean;
|
|
10
|
-
pattern?: RegExp | string;
|
|
11
|
-
name?: string;
|
|
12
|
-
id?: string;
|
|
13
|
-
required?: boolean;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const inputOtp = tv({
|
|
17
|
-
base: "starwind-input-otp flex items-center gap-2 outline-none has-disabled:opacity-50",
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const {
|
|
21
|
-
maxLength = 6,
|
|
22
|
-
value,
|
|
23
|
-
defaultValue,
|
|
24
|
-
disabled = false,
|
|
25
|
-
pattern,
|
|
26
|
-
name,
|
|
27
|
-
id,
|
|
28
|
-
required,
|
|
29
|
-
class: className,
|
|
30
|
-
...rest
|
|
31
|
-
} = Astro.props;
|
|
32
|
-
|
|
33
|
-
let patternStr = "\\d";
|
|
34
|
-
if (pattern) {
|
|
35
|
-
const stripAnchorsRegex = /^\^|\$$/g;
|
|
36
|
-
if (pattern instanceof RegExp) {
|
|
37
|
-
patternStr = pattern.source.replace(stripAnchorsRegex, "");
|
|
38
|
-
} else {
|
|
39
|
-
patternStr = pattern.replace(stripAnchorsRegex, "");
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
const numericPatterns = ["\\d", "[0-9]", "\\d+", "[0-9]+"];
|
|
44
|
-
const isNumericOnly = numericPatterns.includes(patternStr);
|
|
45
|
-
const inputMode = isNumericOnly ? "numeric" : "text";
|
|
46
|
-
---
|
|
47
|
-
|
|
48
|
-
<div
|
|
49
|
-
class={inputOtp({ class: className })}
|
|
50
|
-
data-max-length={maxLength}
|
|
51
|
-
data-value={value || defaultValue || ""}
|
|
52
|
-
data-disabled={disabled}
|
|
53
|
-
data-pattern={patternStr}
|
|
54
|
-
data-slot="input-otp"
|
|
55
|
-
tabindex={disabled ? "-1" : "0"}
|
|
56
|
-
{...rest}
|
|
57
|
-
>
|
|
58
|
-
<input
|
|
59
|
-
autocomplete="one-time-code"
|
|
60
|
-
inputmode={inputMode}
|
|
61
|
-
tabindex="-1"
|
|
62
|
-
name={name}
|
|
63
|
-
id={id}
|
|
64
|
-
class="sr-only"
|
|
65
|
-
required={required}
|
|
66
|
-
maxlength={maxLength.toString()}
|
|
67
|
-
value={value || defaultValue || ""}
|
|
68
|
-
disabled={disabled}
|
|
69
|
-
data-otp-hidden-input
|
|
70
|
-
/>
|
|
71
|
-
<slot />
|
|
72
|
-
</div>
|
|
73
|
-
|
|
74
|
-
<script>
|
|
75
|
-
import type { InputOtpChangeEvent } from "./InputOtpTypes";
|
|
76
|
-
|
|
77
|
-
class InputOtpHandler {
|
|
78
|
-
private container: HTMLElement;
|
|
79
|
-
private slots: HTMLElement[];
|
|
80
|
-
private hiddenInput: HTMLInputElement | null;
|
|
81
|
-
private maxLength: number;
|
|
82
|
-
private containerId: string;
|
|
83
|
-
private pattern: RegExp;
|
|
84
|
-
private observer: MutationObserver | null = null;
|
|
85
|
-
private currentIndex: number = 0;
|
|
86
|
-
private values: string[] = [];
|
|
87
|
-
|
|
88
|
-
constructor(container: HTMLElement, idx: number) {
|
|
89
|
-
this.container = container;
|
|
90
|
-
this.containerId = container.id || `starwind-input-otp-${idx}`;
|
|
91
|
-
if (!container.id) {
|
|
92
|
-
container.id = this.containerId;
|
|
93
|
-
}
|
|
94
|
-
this.maxLength = parseInt(container.dataset.maxLength || "6", 10);
|
|
95
|
-
const patternStr = container.dataset.pattern || "\\d";
|
|
96
|
-
this.pattern = new RegExp(`^${patternStr}$`);
|
|
97
|
-
this.slots = Array.from(container.querySelectorAll<HTMLElement>("[data-otp-slot]"));
|
|
98
|
-
this.hiddenInput = container.querySelector<HTMLInputElement>("input[data-otp-hidden-input]");
|
|
99
|
-
this.values = new Array(this.slots.length).fill("");
|
|
100
|
-
this.init();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private init() {
|
|
104
|
-
if (this.slots.length === 0) return;
|
|
105
|
-
|
|
106
|
-
const isDisabled = this.container.dataset.disabled === "true";
|
|
107
|
-
if (isDisabled) {
|
|
108
|
-
this.container.setAttribute("tabindex", "-1");
|
|
109
|
-
return;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const initialValue = this.container.dataset.value || "";
|
|
113
|
-
if (initialValue) {
|
|
114
|
-
this.setValue(initialValue);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
this.setupEventListeners();
|
|
118
|
-
this.setupValueSync();
|
|
119
|
-
this.updateSlots();
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
private setupValueSync() {
|
|
123
|
-
this.observer = new MutationObserver(() => {
|
|
124
|
-
const containerValue = this.container.dataset.value || "";
|
|
125
|
-
const currentValue = this.getValue();
|
|
126
|
-
if (containerValue !== currentValue) {
|
|
127
|
-
this.setValue(containerValue);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
this.observer.observe(this.container, {
|
|
132
|
-
attributes: true,
|
|
133
|
-
attributeFilter: ["data-value"],
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
private setupEventListeners() {
|
|
138
|
-
this.container.addEventListener("keydown", (e) => this.handleKeyDown(e));
|
|
139
|
-
this.container.addEventListener("focus", () => this.handleContainerFocus());
|
|
140
|
-
this.container.addEventListener("blur", () => this.handleContainerBlur());
|
|
141
|
-
this.container.addEventListener("paste", (e) => this.handlePaste(e));
|
|
142
|
-
this.container.addEventListener("click", (e) => this.handleClick(e));
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
private handleKeyDown(e: KeyboardEvent) {
|
|
146
|
-
const isDisabled = this.container.dataset.disabled === "true";
|
|
147
|
-
if (isDisabled) return;
|
|
148
|
-
|
|
149
|
-
if (e.key.length === 1 && !e.ctrlKey && !e.metaKey && !e.altKey) {
|
|
150
|
-
e.preventDefault();
|
|
151
|
-
const char = e.key;
|
|
152
|
-
if (this.pattern.test(char)) {
|
|
153
|
-
this.setSlotValue(this.currentIndex, char);
|
|
154
|
-
if (this.currentIndex < this.slots.length - 1) {
|
|
155
|
-
this.currentIndex++;
|
|
156
|
-
}
|
|
157
|
-
this.updateSlots();
|
|
158
|
-
this.updateValue();
|
|
159
|
-
}
|
|
160
|
-
} else if (e.key === "Backspace") {
|
|
161
|
-
e.preventDefault();
|
|
162
|
-
if (this.values[this.currentIndex]) {
|
|
163
|
-
this.setSlotValue(this.currentIndex, "");
|
|
164
|
-
} else if (this.currentIndex > 0) {
|
|
165
|
-
this.currentIndex--;
|
|
166
|
-
this.setSlotValue(this.currentIndex, "");
|
|
167
|
-
}
|
|
168
|
-
this.updateSlots();
|
|
169
|
-
this.updateValue();
|
|
170
|
-
} else if (e.key === "ArrowLeft") {
|
|
171
|
-
e.preventDefault();
|
|
172
|
-
if (this.currentIndex > 0) {
|
|
173
|
-
this.currentIndex--;
|
|
174
|
-
this.updateSlots();
|
|
175
|
-
}
|
|
176
|
-
} else if (e.key === "ArrowRight") {
|
|
177
|
-
e.preventDefault();
|
|
178
|
-
if (this.currentIndex < this.slots.length - 1) {
|
|
179
|
-
this.currentIndex++;
|
|
180
|
-
this.updateSlots();
|
|
181
|
-
}
|
|
182
|
-
} else if (e.key === "Delete") {
|
|
183
|
-
e.preventDefault();
|
|
184
|
-
this.setSlotValue(this.currentIndex, "");
|
|
185
|
-
this.updateSlots();
|
|
186
|
-
this.updateValue();
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
private handlePaste(e: ClipboardEvent) {
|
|
191
|
-
const isDisabled = this.container.dataset.disabled === "true";
|
|
192
|
-
if (isDisabled) return;
|
|
193
|
-
|
|
194
|
-
e.preventDefault();
|
|
195
|
-
const pastedData = e.clipboardData?.getData("text") || "";
|
|
196
|
-
const matchedChars = this.filterByPattern(pastedData).slice(0, this.maxLength);
|
|
197
|
-
|
|
198
|
-
if (matchedChars.length === 0) return;
|
|
199
|
-
|
|
200
|
-
for (let i = 0; i < matchedChars.length && this.currentIndex + i < this.slots.length; i++) {
|
|
201
|
-
this.setSlotValue(this.currentIndex + i, matchedChars[i]);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
this.currentIndex = Math.min(this.currentIndex + matchedChars.length, this.slots.length - 1);
|
|
205
|
-
this.updateSlots();
|
|
206
|
-
this.updateValue();
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
private handleClick(e: MouseEvent) {
|
|
210
|
-
const isDisabled = this.container.dataset.disabled === "true";
|
|
211
|
-
if (isDisabled) return;
|
|
212
|
-
|
|
213
|
-
const slot = (e.target as HTMLElement).closest<HTMLElement>("[data-otp-slot]");
|
|
214
|
-
if (slot) {
|
|
215
|
-
const index = this.slots.indexOf(slot);
|
|
216
|
-
if (index !== -1) {
|
|
217
|
-
this.currentIndex = index;
|
|
218
|
-
this.updateSlots();
|
|
219
|
-
this.container.focus();
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
private handleContainerFocus() {
|
|
225
|
-
this.updateSlots();
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
private handleContainerBlur() {
|
|
229
|
-
this.updateSlots();
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
private setSlotValue(index: number, value: string) {
|
|
233
|
-
if (index >= 0 && index < this.values.length) {
|
|
234
|
-
this.values[index] = value;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
private updateSlots() {
|
|
239
|
-
const isFocused = document.activeElement === this.container;
|
|
240
|
-
|
|
241
|
-
this.slots.forEach((slot, index) => {
|
|
242
|
-
const charElement = slot.querySelector("[data-otp-char]");
|
|
243
|
-
const caretElement = slot.querySelector("[data-otp-caret]");
|
|
244
|
-
const char = this.values[index] || "";
|
|
245
|
-
|
|
246
|
-
if (charElement) {
|
|
247
|
-
charElement.textContent = char;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const isActive = isFocused && index === this.currentIndex;
|
|
251
|
-
slot.setAttribute("data-active", isActive ? "true" : "false");
|
|
252
|
-
|
|
253
|
-
if (caretElement) {
|
|
254
|
-
if (isActive && !char) {
|
|
255
|
-
caretElement.classList.remove("hidden");
|
|
256
|
-
caretElement.classList.add("flex");
|
|
257
|
-
} else {
|
|
258
|
-
caretElement.classList.add("hidden");
|
|
259
|
-
caretElement.classList.remove("flex");
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
});
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
private filterByPattern(value: string): string[] {
|
|
266
|
-
return value.split("").filter((char) => this.pattern.test(char));
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
private setValue(value: string) {
|
|
270
|
-
const matchedChars = this.filterByPattern(value).slice(0, this.maxLength);
|
|
271
|
-
for (let i = 0; i < this.slots.length; i++) {
|
|
272
|
-
this.values[i] = matchedChars[i] || "";
|
|
273
|
-
}
|
|
274
|
-
this.currentIndex = Math.min(matchedChars.length, this.slots.length - 1);
|
|
275
|
-
this.updateSlots();
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
private updateValue() {
|
|
279
|
-
const value = this.values.join("");
|
|
280
|
-
this.container.dataset.value = value;
|
|
281
|
-
|
|
282
|
-
if (this.hiddenInput) {
|
|
283
|
-
this.hiddenInput.value = value;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
this.dispatchChangeEvent(value);
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
public getValue(): string {
|
|
290
|
-
return this.values.join("");
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
private dispatchChangeEvent(value: string) {
|
|
294
|
-
const event = new CustomEvent<InputOtpChangeEvent["detail"]>("starwind-input-otp:change", {
|
|
295
|
-
bubbles: true,
|
|
296
|
-
detail: {
|
|
297
|
-
value,
|
|
298
|
-
inputOtpId: this.containerId,
|
|
299
|
-
},
|
|
300
|
-
});
|
|
301
|
-
this.container.dispatchEvent(event);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
const inputOtpInstances = new WeakMap<HTMLElement, InputOtpHandler>();
|
|
306
|
-
let inputOtpCounter = 0;
|
|
307
|
-
|
|
308
|
-
const setupInputOtps = () => {
|
|
309
|
-
document.querySelectorAll<HTMLElement>(".starwind-input-otp").forEach((container) => {
|
|
310
|
-
if (!inputOtpInstances.has(container)) {
|
|
311
|
-
inputOtpInstances.set(container, new InputOtpHandler(container, inputOtpCounter++));
|
|
312
|
-
}
|
|
313
|
-
});
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
setupInputOtps();
|
|
317
|
-
document.addEventListener("astro:after-swap", setupInputOtps);
|
|
318
|
-
document.addEventListener("starwind:init", setupInputOtps);
|
|
319
|
-
</script>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props = HTMLAttributes<"div">;
|
|
6
|
-
|
|
7
|
-
export const inputOtpGroup = tv({
|
|
8
|
-
base: "flex items-center",
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const { class: className, ...rest } = Astro.props;
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
<div class={inputOtpGroup({ class: className })} data-slot="input-otp-group" {...rest}>
|
|
15
|
-
<slot />
|
|
16
|
-
</div>
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import MinusIcon from "@tabler/icons/outline/minus.svg";
|
|
3
|
-
import type { HTMLAttributes } from "astro/types";
|
|
4
|
-
import { tv } from "tailwind-variants";
|
|
5
|
-
|
|
6
|
-
type Props = HTMLAttributes<"div">;
|
|
7
|
-
|
|
8
|
-
export const inputOtpSeparator = tv({
|
|
9
|
-
base: "text-muted-foreground",
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
const { class: className, ...rest } = Astro.props;
|
|
13
|
-
---
|
|
14
|
-
|
|
15
|
-
<div
|
|
16
|
-
aria-hidden="true"
|
|
17
|
-
class={inputOtpSeparator({ class: className })}
|
|
18
|
-
data-slot="input-otp-separator"
|
|
19
|
-
role="separator"
|
|
20
|
-
{...rest}
|
|
21
|
-
>
|
|
22
|
-
<slot name="icon">
|
|
23
|
-
<MinusIcon class="size-6" />
|
|
24
|
-
</slot>
|
|
25
|
-
</div>
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv, type VariantProps } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props = HTMLAttributes<"div"> &
|
|
6
|
-
VariantProps<typeof inputOtpSlot> & {
|
|
7
|
-
index?: number;
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
export const inputOtpSlot = tv({
|
|
11
|
-
base: [
|
|
12
|
-
"border-input dark:bg-input/30 text-foreground border bg-transparent text-center shadow-xs",
|
|
13
|
-
"relative flex items-center justify-center border-y border-r text-sm transition-all outline-none",
|
|
14
|
-
"first:rounded-l-md first:border-l last:rounded-r-md disabled:cursor-not-allowed disabled:opacity-50",
|
|
15
|
-
"data-[active=true]:border-outline data-[active=true]:ring-outline/50 data-[active=true]:z-10 data-[active=true]:ring-3",
|
|
16
|
-
"data-[active=true]:aria-invalid:ring-error/40",
|
|
17
|
-
"aria-invalid:border-error data-[active=true]:aria-invalid:border-error",
|
|
18
|
-
],
|
|
19
|
-
variants: {
|
|
20
|
-
size: {
|
|
21
|
-
sm: "size-9 text-sm",
|
|
22
|
-
md: "size-11 text-base",
|
|
23
|
-
lg: "size-12 text-lg",
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
defaultVariants: { size: "md" },
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
const { size, index, class: className, ...rest } = Astro.props;
|
|
30
|
-
---
|
|
31
|
-
|
|
32
|
-
<div
|
|
33
|
-
class={inputOtpSlot({ size, class: className })}
|
|
34
|
-
data-otp-slot
|
|
35
|
-
data-index={index}
|
|
36
|
-
data-slot="input-otp-slot"
|
|
37
|
-
{...rest}
|
|
38
|
-
>
|
|
39
|
-
<span data-otp-char></span>
|
|
40
|
-
<div
|
|
41
|
-
class="pointer-events-none absolute inset-0 hidden items-center justify-center"
|
|
42
|
-
data-otp-caret
|
|
43
|
-
>
|
|
44
|
-
<slot name="caret">
|
|
45
|
-
<div class="animate-caret-blink bg-foreground h-4 w-px duration-1000"></div>
|
|
46
|
-
</slot>
|
|
47
|
-
</div>
|
|
48
|
-
</div>
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import InputOtp, { inputOtp } from "./InputOtp.astro";
|
|
2
|
-
import InputOtpGroup, { inputOtpGroup } from "./InputOtpGroup.astro";
|
|
3
|
-
import InputOtpSeparator, { inputOtpSeparator } from "./InputOtpSeparator.astro";
|
|
4
|
-
import InputOtpSlot, { inputOtpSlot } from "./InputOtpSlot.astro";
|
|
5
|
-
import type { InputOtpChangeEvent } from "./InputOtpTypes";
|
|
6
|
-
|
|
7
|
-
const REGEXP_ONLY_DIGITS_AND_CHARS = /^[A-Za-z0-9]+$/;
|
|
8
|
-
const REGEXP_ONLY_DIGITS = /^[0-9]+$/;
|
|
9
|
-
|
|
10
|
-
const InputOtpVariants = {
|
|
11
|
-
inputOtp,
|
|
12
|
-
inputOtpGroup,
|
|
13
|
-
inputOtpSeparator,
|
|
14
|
-
inputOtpSlot,
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export {
|
|
18
|
-
InputOtp,
|
|
19
|
-
type InputOtpChangeEvent,
|
|
20
|
-
InputOtpGroup,
|
|
21
|
-
InputOtpSeparator,
|
|
22
|
-
InputOtpSlot,
|
|
23
|
-
InputOtpVariants,
|
|
24
|
-
REGEXP_ONLY_DIGITS,
|
|
25
|
-
REGEXP_ONLY_DIGITS_AND_CHARS,
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export default {
|
|
29
|
-
Root: InputOtp,
|
|
30
|
-
Group: InputOtpGroup,
|
|
31
|
-
Separator: InputOtpSeparator,
|
|
32
|
-
Slot: InputOtpSlot,
|
|
33
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLTag, Polymorphic } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props<Tag extends HTMLTag> = Polymorphic<{ as: Tag }> & {
|
|
6
|
-
/**
|
|
7
|
-
* Variant of the item
|
|
8
|
-
* @default "default"
|
|
9
|
-
*/
|
|
10
|
-
variant?: "default" | "outline" | "muted";
|
|
11
|
-
/**
|
|
12
|
-
* Size of the item
|
|
13
|
-
* @default "default"
|
|
14
|
-
*/
|
|
15
|
-
size?: "default" | "sm";
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const item = tv({
|
|
19
|
-
base: [
|
|
20
|
-
"group/item flex flex-wrap items-center rounded-md border border-transparent text-sm transition-colors",
|
|
21
|
-
"[a]:hover:bg-accent/50 [a]:transition-colors",
|
|
22
|
-
"focus-visible:border-ring focus-visible:ring-outline/50 outline-none focus-visible:ring-[3px]",
|
|
23
|
-
],
|
|
24
|
-
variants: {
|
|
25
|
-
variant: {
|
|
26
|
-
default: "bg-transparent",
|
|
27
|
-
outline: "border-border",
|
|
28
|
-
muted: "bg-muted/50",
|
|
29
|
-
},
|
|
30
|
-
size: {
|
|
31
|
-
default: "gap-4 p-4",
|
|
32
|
-
sm: "gap-2.5 px-4 py-3",
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
defaultVariants: {
|
|
36
|
-
variant: "default",
|
|
37
|
-
size: "default",
|
|
38
|
-
},
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
const {
|
|
42
|
-
variant = "default",
|
|
43
|
-
size = "default",
|
|
44
|
-
class: className,
|
|
45
|
-
as: Tag = "div",
|
|
46
|
-
...rest
|
|
47
|
-
} = Astro.props;
|
|
48
|
-
---
|
|
49
|
-
|
|
50
|
-
<Tag class={item({ variant, size, class: className })} data-slot="item" {...rest}>
|
|
51
|
-
<slot />
|
|
52
|
-
</Tag>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props = HTMLAttributes<"div">;
|
|
6
|
-
|
|
7
|
-
export const itemActions = tv({
|
|
8
|
-
base: "flex items-center gap-2",
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const { class: className, ...rest } = Astro.props;
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
<div class={itemActions({ class: className })} data-slot="item-actions" {...rest}>
|
|
15
|
-
<slot />
|
|
16
|
-
</div>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props = HTMLAttributes<"div">;
|
|
6
|
-
|
|
7
|
-
export const itemContent = tv({
|
|
8
|
-
base: "flex flex-1 flex-col gap-1.5 [&+[data-slot=item-content]]:flex-none",
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const { class: className, ...rest } = Astro.props;
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
<div class={itemContent({ class: className })} data-slot="item-content" {...rest}>
|
|
15
|
-
<slot />
|
|
16
|
-
</div>
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props = HTMLAttributes<"p">;
|
|
6
|
-
|
|
7
|
-
export const itemDescription = tv({
|
|
8
|
-
base: [
|
|
9
|
-
"text-muted-foreground line-clamp-2 leading-snug font-normal text-balance",
|
|
10
|
-
"[&>a:hover]:text-primary [&>a]:underline [&>a]:underline-offset-4",
|
|
11
|
-
],
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
const { class: className, ...rest } = Astro.props;
|
|
15
|
-
---
|
|
16
|
-
|
|
17
|
-
<p class={itemDescription({ class: className })} data-slot="item-description" {...rest}>
|
|
18
|
-
<slot />
|
|
19
|
-
</p>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props = HTMLAttributes<"div">;
|
|
6
|
-
|
|
7
|
-
export const itemFooter = tv({
|
|
8
|
-
base: "flex basis-full items-center justify-between gap-2",
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const { class: className, ...rest } = Astro.props;
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
<div class={itemFooter({ class: className })} data-slot="item-footer" {...rest}>
|
|
15
|
-
<slot />
|
|
16
|
-
</div>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props = HTMLAttributes<"div">;
|
|
6
|
-
|
|
7
|
-
export const itemGroup = tv({
|
|
8
|
-
base: "group/item-group flex flex-col",
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const { class: className, ...rest } = Astro.props;
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
<div role="list" class={itemGroup({ class: className })} data-slot="item-group" {...rest}>
|
|
15
|
-
<slot />
|
|
16
|
-
</div>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props = HTMLAttributes<"div">;
|
|
6
|
-
|
|
7
|
-
export const itemHeader = tv({
|
|
8
|
-
base: "flex basis-full items-center justify-between gap-2",
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const { class: className, ...rest } = Astro.props;
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
<div class={itemHeader({ class: className })} data-slot="item-header" {...rest}>
|
|
15
|
-
<slot />
|
|
16
|
-
</div>
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props = HTMLAttributes<"div"> & {
|
|
6
|
-
/**
|
|
7
|
-
* Variant of the item media
|
|
8
|
-
* @default "default"
|
|
9
|
-
*/
|
|
10
|
-
variant?: "default" | "icon" | "image";
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export const itemMedia = tv({
|
|
14
|
-
base: [
|
|
15
|
-
"flex shrink-0 items-center justify-center gap-2 [&_svg]:pointer-events-none",
|
|
16
|
-
"group-has-[[data-slot=item-description]]/item:translate-y-0.5 group-has-[[data-slot=item-description]]/item:self-start",
|
|
17
|
-
],
|
|
18
|
-
variants: {
|
|
19
|
-
variant: {
|
|
20
|
-
default: "bg-transparent",
|
|
21
|
-
icon: "bg-muted size-8 rounded-sm border [&_svg:not([class*='size-'])]:size-4",
|
|
22
|
-
image: "size-10 overflow-hidden rounded-sm [&_img]:size-full [&_img]:object-cover",
|
|
23
|
-
},
|
|
24
|
-
},
|
|
25
|
-
defaultVariants: {
|
|
26
|
-
variant: "default",
|
|
27
|
-
},
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const { variant = "default", class: className, ...rest } = Astro.props;
|
|
31
|
-
---
|
|
32
|
-
|
|
33
|
-
<div
|
|
34
|
-
class={itemMedia({ variant, class: className })}
|
|
35
|
-
data-slot="item-media"
|
|
36
|
-
data-variant={variant}
|
|
37
|
-
{...rest}
|
|
38
|
-
>
|
|
39
|
-
<slot />
|
|
40
|
-
</div>
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { ComponentProps } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
import { Separator } from "@/components/starwind/separator";
|
|
6
|
-
|
|
7
|
-
type Props = ComponentProps<typeof Separator>;
|
|
8
|
-
|
|
9
|
-
export const itemSeparator = tv({
|
|
10
|
-
base: "my-0",
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const { class: className, orientation = "horizontal", ...rest } = Astro.props;
|
|
14
|
-
---
|
|
15
|
-
|
|
16
|
-
<Separator
|
|
17
|
-
orientation={orientation}
|
|
18
|
-
class={itemSeparator({ class: className })}
|
|
19
|
-
data-slot="item-separator"
|
|
20
|
-
{...rest}
|
|
21
|
-
/>
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HTMLAttributes } from "astro/types";
|
|
3
|
-
import { tv } from "tailwind-variants";
|
|
4
|
-
|
|
5
|
-
type Props = HTMLAttributes<"div">;
|
|
6
|
-
|
|
7
|
-
export const itemTitle = tv({
|
|
8
|
-
base: "flex w-fit items-center gap-2 leading-snug font-medium",
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const { class: className, ...rest } = Astro.props;
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
<div class={itemTitle({ class: className })} data-slot="item-title" {...rest}>
|
|
15
|
-
<slot />
|
|
16
|
-
</div>
|