@krak-stack/registry 0.7.0 → 0.8.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/CHANGELOG.md +13 -0
- package/dist/components/ui/cron-expression-editor.d.ts +14 -0
- package/dist/components/ui/cron-expression-editor.js +206 -0
- package/dist/components/ui/cron-expression-editor.schema.d.ts +7 -0
- package/dist/components/ui/form.d.ts +5 -5
- package/dist/components/ui/phone-number-input.d.ts +20 -0
- package/dist/components/ui/phone-number-input.js +682 -0
- package/dist/services/agent/client/index.js +2 -0
- package/dist/services/notification/client/index.js +135 -91
- package/dist/services/notification/public.js +135 -91
- package/package.json +11 -1
|
@@ -0,0 +1,682 @@
|
|
|
1
|
+
// ../../src/components/ui/phone-number-input.tsx
|
|
2
|
+
import { useId, useLayoutEffect, useRef as useRef2 } from "react";
|
|
3
|
+
import {
|
|
4
|
+
getCountries,
|
|
5
|
+
AsYouType,
|
|
6
|
+
getCountryCallingCode,
|
|
7
|
+
parsePhoneNumberFromString
|
|
8
|
+
} from "libphonenumber-js/max";
|
|
9
|
+
|
|
10
|
+
// ../../src/components/ui/input.tsx
|
|
11
|
+
import { Input as InputPrimitive } from "@base-ui/react/input";
|
|
12
|
+
|
|
13
|
+
// ../../src/lib/utils.ts
|
|
14
|
+
import { cn } from "cn";
|
|
15
|
+
|
|
16
|
+
// ../../src/components/ui/input.tsx
|
|
17
|
+
import { jsx } from "react/jsx-runtime";
|
|
18
|
+
function Input({ className, type, ...props }) {
|
|
19
|
+
return /* @__PURE__ */ jsx(InputPrimitive, {
|
|
20
|
+
type,
|
|
21
|
+
"data-slot": "input",
|
|
22
|
+
className: cn("h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-2.5 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 md:text-sm dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40", className),
|
|
23
|
+
...props
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// ../../src/components/ui/phone-number-input.tsx
|
|
28
|
+
import { useKrakstackLocale as useKrakstackLocale2 } from "@krak-stack/registry/krakstack-provider";
|
|
29
|
+
|
|
30
|
+
// ../../src/components/ui/button.tsx
|
|
31
|
+
import { Button as ButtonPrimitive } from "@base-ui/react/button";
|
|
32
|
+
import { cva } from "class-variance-authority";
|
|
33
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
34
|
+
var buttonVariants = cva("group/button inline-flex shrink-0 items-center justify-center rounded-md border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4", {
|
|
35
|
+
variants: {
|
|
36
|
+
variant: {
|
|
37
|
+
default: "bg-primary text-primary-foreground hover:bg-primary/80",
|
|
38
|
+
outline: "border-border bg-background shadow-xs hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",
|
|
39
|
+
secondary: "bg-secondary text-secondary-foreground hover:bg-[color-mix(in_oklch,var(--secondary),var(--foreground)_5%)] aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
|
|
40
|
+
ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
|
|
41
|
+
destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
|
|
42
|
+
link: "text-primary underline-offset-4 hover:underline"
|
|
43
|
+
},
|
|
44
|
+
size: {
|
|
45
|
+
default: "h-9 gap-1.5 px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
46
|
+
xs: "h-6 gap-1 rounded-[min(var(--radius-md),8px)] px-2 text-xs in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3",
|
|
47
|
+
sm: "h-8 gap-1 rounded-[min(var(--radius-md),10px)] px-2.5 in-data-[slot=button-group]:rounded-md has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5",
|
|
48
|
+
lg: "h-10 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2",
|
|
49
|
+
icon: "size-9",
|
|
50
|
+
"icon-xs": "size-6 rounded-[min(var(--radius-md),8px)] in-data-[slot=button-group]:rounded-md [&_svg:not([class*='size-'])]:size-3",
|
|
51
|
+
"icon-sm": "size-8 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-md",
|
|
52
|
+
"icon-lg": "size-10"
|
|
53
|
+
}
|
|
54
|
+
},
|
|
55
|
+
defaultVariants: {
|
|
56
|
+
variant: "default",
|
|
57
|
+
size: "default"
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
function Button({
|
|
61
|
+
className,
|
|
62
|
+
variant = "default",
|
|
63
|
+
size = "default",
|
|
64
|
+
...props
|
|
65
|
+
}) {
|
|
66
|
+
return /* @__PURE__ */ jsx2(ButtonPrimitive, {
|
|
67
|
+
"data-slot": "button",
|
|
68
|
+
className: cn(buttonVariants({ variant, size, className })),
|
|
69
|
+
...props
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ../../src/components/ui/virtualized-combobox.tsx
|
|
74
|
+
import { Combobox as ComboboxPrimitive } from "@base-ui/react";
|
|
75
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
76
|
+
import { Check, ChevronsUpDown, X } from "lucide-react";
|
|
77
|
+
import {
|
|
78
|
+
useCallback,
|
|
79
|
+
useEffect,
|
|
80
|
+
useImperativeHandle,
|
|
81
|
+
useRef
|
|
82
|
+
} from "react";
|
|
83
|
+
|
|
84
|
+
// ../../src/components/ui/input-group.tsx
|
|
85
|
+
import { cva as cva2 } from "class-variance-authority";
|
|
86
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
87
|
+
function InputGroup({ className, ...props }) {
|
|
88
|
+
return /* @__PURE__ */ jsx3("div", {
|
|
89
|
+
"data-slot": "input-group",
|
|
90
|
+
role: "group",
|
|
91
|
+
className: cn("group/input-group relative flex h-9 w-full min-w-0 items-center rounded-md border border-input shadow-xs transition-[color,box-shadow] outline-none in-data-[slot=combobox-content]:focus-within:border-inherit in-data-[slot=combobox-content]:focus-within:ring-0 has-[[data-slot=input-group-control]:focus-visible]:border-ring has-[[data-slot=input-group-control]:focus-visible]:ring-3 has-[[data-slot=input-group-control]:focus-visible]:ring-ring/50 has-[[data-slot][aria-invalid=true]]:border-destructive has-[[data-slot][aria-invalid=true]]:ring-3 has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>textarea]:h-auto dark:bg-input/30 dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40 has-[>[data-align=block-end]]:[&>input]:pt-3 has-[>[data-align=block-start]]:[&>input]:pb-3 has-[>[data-align=inline-end]]:[&>input]:pr-1.5 has-[>[data-align=inline-start]]:[&>input]:pl-1.5", className),
|
|
92
|
+
...props
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
var inputGroupAddonVariants = cva2("flex h-auto cursor-text items-center justify-center gap-2 py-1.5 text-sm font-medium text-muted-foreground select-none group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4", {
|
|
96
|
+
variants: {
|
|
97
|
+
align: {
|
|
98
|
+
"inline-start": "order-first pl-2 has-[>button]:-ml-1 has-[>kbd]:ml-[-0.15rem]",
|
|
99
|
+
"inline-end": "order-last pr-2 has-[>button]:-mr-1 has-[>kbd]:mr-[-0.15rem]",
|
|
100
|
+
"block-start": "order-first w-full justify-start px-2.5 pt-2 group-has-[>input]/input-group:pt-2 [.border-b]:pb-2",
|
|
101
|
+
"block-end": "order-last w-full justify-start px-2.5 pb-2 group-has-[>input]/input-group:pb-2 [.border-t]:pt-2"
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
defaultVariants: { align: "inline-start" }
|
|
105
|
+
});
|
|
106
|
+
var inputGroupButtonVariants = cva2("flex items-center gap-2 text-sm shadow-none", {
|
|
107
|
+
variants: {
|
|
108
|
+
size: {
|
|
109
|
+
xs: "h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-1.5 [&>svg:not([class*='size-'])]:size-3.5",
|
|
110
|
+
sm: "",
|
|
111
|
+
"icon-xs": "size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0",
|
|
112
|
+
"icon-sm": "size-8 p-0 has-[>svg]:p-0"
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
defaultVariants: { size: "xs" }
|
|
116
|
+
});
|
|
117
|
+
function InputGroupInput({
|
|
118
|
+
className,
|
|
119
|
+
...props
|
|
120
|
+
}) {
|
|
121
|
+
return /* @__PURE__ */ jsx3(Input, {
|
|
122
|
+
"data-slot": "input-group-control",
|
|
123
|
+
className: cn("flex-1 rounded-none border-0 bg-transparent shadow-none ring-0 focus-visible:ring-0 aria-invalid:ring-0 dark:bg-transparent", className),
|
|
124
|
+
...props
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ../../src/components/ui/virtualized-combobox.tsx
|
|
129
|
+
import { useKrakstackLocale } from "@krak-stack/registry/krakstack-provider";
|
|
130
|
+
import { jsx as jsx4, jsxs, Fragment } from "react/jsx-runtime";
|
|
131
|
+
"use client";
|
|
132
|
+
var messages = {
|
|
133
|
+
en: {
|
|
134
|
+
clear: "Clear selection",
|
|
135
|
+
search: "Search...",
|
|
136
|
+
selected: (count) => `${count} selected`,
|
|
137
|
+
selectMore: "Select more"
|
|
138
|
+
},
|
|
139
|
+
fr: {
|
|
140
|
+
clear: "Effacer la sélection",
|
|
141
|
+
search: "Rechercher...",
|
|
142
|
+
selected: (count) => `${count} sélectionnés`,
|
|
143
|
+
selectMore: "Sélectionner davantage"
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
var virtualizedComboboxMessages = (locale, translations) => ({
|
|
147
|
+
...locale.startsWith("fr") ? messages.fr : messages.en,
|
|
148
|
+
...translations?.[locale.split("-")[0] ?? locale],
|
|
149
|
+
...translations?.[locale]
|
|
150
|
+
});
|
|
151
|
+
var optionEquals = (item, selected) => item.value === selected.value;
|
|
152
|
+
var VirtualizedComboboxList = ({
|
|
153
|
+
emptyLabel,
|
|
154
|
+
groupSelections,
|
|
155
|
+
itemIndexRef,
|
|
156
|
+
locale = "en",
|
|
157
|
+
messages: messageOverrides,
|
|
158
|
+
renderItem,
|
|
159
|
+
selectedValues,
|
|
160
|
+
virtualizerRef
|
|
161
|
+
}) => {
|
|
162
|
+
const filteredItems = ComboboxPrimitive.useFilteredItems();
|
|
163
|
+
const labels = virtualizedComboboxMessages(locale, messageOverrides);
|
|
164
|
+
const itemEntries = filteredItems.map((item, index) => ({
|
|
165
|
+
kind: "item",
|
|
166
|
+
item,
|
|
167
|
+
index
|
|
168
|
+
}));
|
|
169
|
+
const selectedEntries = itemEntries.filter(({ item }) => selectedValues.has(item.value));
|
|
170
|
+
const availableEntries = itemEntries.filter(({ item }) => !selectedValues.has(item.value));
|
|
171
|
+
const entries = filteredItems.length === 0 ? [] : groupSelections ? [
|
|
172
|
+
...selectedEntries.length > 0 ? [
|
|
173
|
+
{
|
|
174
|
+
kind: "group",
|
|
175
|
+
key: "selected",
|
|
176
|
+
label: labels.selected(selectedValues.size)
|
|
177
|
+
},
|
|
178
|
+
...selectedEntries
|
|
179
|
+
] : [],
|
|
180
|
+
{
|
|
181
|
+
kind: "group",
|
|
182
|
+
key: "available",
|
|
183
|
+
label: labels.selectMore
|
|
184
|
+
},
|
|
185
|
+
...availableEntries
|
|
186
|
+
] : itemEntries;
|
|
187
|
+
const scrollRef = useRef(null);
|
|
188
|
+
const virtualizer = useVirtualizer({
|
|
189
|
+
count: entries.length,
|
|
190
|
+
getScrollElement: () => scrollRef.current,
|
|
191
|
+
getItemKey: (index) => {
|
|
192
|
+
const entry = entries[index];
|
|
193
|
+
return entry?.kind === "group" ? `group-${entry.key}` : entry?.item.value ?? index;
|
|
194
|
+
},
|
|
195
|
+
estimateSize: () => 36,
|
|
196
|
+
overscan: 8
|
|
197
|
+
});
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
itemIndexRef.current = new Map(entries.flatMap((entry, index) => entry.kind === "item" ? [[entry.index, index]] : []));
|
|
200
|
+
});
|
|
201
|
+
useImperativeHandle(virtualizerRef, () => virtualizer, [virtualizer]);
|
|
202
|
+
const handleScrollElementRef = useCallback((element) => {
|
|
203
|
+
scrollRef.current = element;
|
|
204
|
+
if (element)
|
|
205
|
+
virtualizer.measure();
|
|
206
|
+
}, [virtualizer]);
|
|
207
|
+
return /* @__PURE__ */ jsxs(Fragment, {
|
|
208
|
+
children: [
|
|
209
|
+
filteredItems.length === 0 && /* @__PURE__ */ jsx4("div", {
|
|
210
|
+
className: "text-muted-foreground flex min-h-0 flex-1 flex-col items-center justify-center overflow-auto py-6 text-center text-sm",
|
|
211
|
+
children: emptyLabel
|
|
212
|
+
}),
|
|
213
|
+
/* @__PURE__ */ jsx4(ComboboxPrimitive.List, {
|
|
214
|
+
className: "min-h-0 flex-1 scroll-py-1 overflow-auto overscroll-contain p-1",
|
|
215
|
+
hidden: filteredItems.length === 0,
|
|
216
|
+
ref: handleScrollElementRef,
|
|
217
|
+
style: {
|
|
218
|
+
height: Math.min(virtualizer.getTotalSize() + 8, 288),
|
|
219
|
+
maxHeight: "var(--available-height)"
|
|
220
|
+
},
|
|
221
|
+
children: /* @__PURE__ */ jsx4("div", {
|
|
222
|
+
className: "relative w-full",
|
|
223
|
+
role: "presentation",
|
|
224
|
+
style: { height: virtualizer.getTotalSize() },
|
|
225
|
+
children: virtualizer.getVirtualItems().map((virtualItem) => {
|
|
226
|
+
const entry = entries[virtualItem.index];
|
|
227
|
+
if (!entry)
|
|
228
|
+
return null;
|
|
229
|
+
const style = {
|
|
230
|
+
height: virtualItem.size,
|
|
231
|
+
transform: `translateY(${virtualItem.start}px)`
|
|
232
|
+
};
|
|
233
|
+
if (entry.kind === "group") {
|
|
234
|
+
return /* @__PURE__ */ jsx4(ComboboxPrimitive.Group, {
|
|
235
|
+
className: "contents",
|
|
236
|
+
children: /* @__PURE__ */ jsx4(ComboboxPrimitive.GroupLabel, {
|
|
237
|
+
className: "text-muted-foreground absolute top-0 left-0 w-full px-2 pt-3 pb-1 text-xs",
|
|
238
|
+
"data-index": virtualItem.index,
|
|
239
|
+
ref: virtualizer.measureElement,
|
|
240
|
+
style,
|
|
241
|
+
children: entry.label
|
|
242
|
+
})
|
|
243
|
+
}, entry.key);
|
|
244
|
+
}
|
|
245
|
+
return /* @__PURE__ */ jsxs(ComboboxPrimitive.Item, {
|
|
246
|
+
"aria-posinset": entry.index + 1,
|
|
247
|
+
"aria-setsize": filteredItems.length,
|
|
248
|
+
className: "data-highlighted:bg-accent data-highlighted:text-accent-foreground absolute top-0 left-0 flex w-full cursor-default items-center gap-2 rounded-sm py-1.5 pr-8 pl-2 text-sm outline-hidden select-none data-disabled:pointer-events-none data-disabled:opacity-50",
|
|
249
|
+
"data-index": virtualItem.index,
|
|
250
|
+
index: entry.index,
|
|
251
|
+
ref: virtualizer.measureElement,
|
|
252
|
+
style,
|
|
253
|
+
value: entry.item,
|
|
254
|
+
children: [
|
|
255
|
+
renderItem?.(entry.item) ?? /* @__PURE__ */ jsx4("span", {
|
|
256
|
+
className: "min-w-0 truncate",
|
|
257
|
+
children: entry.item.label
|
|
258
|
+
}),
|
|
259
|
+
/* @__PURE__ */ jsx4(ComboboxPrimitive.ItemIndicator, {
|
|
260
|
+
className: "absolute right-2 flex size-4 items-center justify-center",
|
|
261
|
+
children: /* @__PURE__ */ jsx4(Check, {})
|
|
262
|
+
})
|
|
263
|
+
]
|
|
264
|
+
}, entry.item.value);
|
|
265
|
+
})
|
|
266
|
+
})
|
|
267
|
+
})
|
|
268
|
+
]
|
|
269
|
+
});
|
|
270
|
+
};
|
|
271
|
+
var VirtualizedComboboxContent = ({
|
|
272
|
+
contentClassName,
|
|
273
|
+
emptyLabel,
|
|
274
|
+
groupSelections,
|
|
275
|
+
itemIndexRef,
|
|
276
|
+
locale = "en",
|
|
277
|
+
messages: messageOverrides,
|
|
278
|
+
renderItem,
|
|
279
|
+
selectedValues,
|
|
280
|
+
virtualizerRef
|
|
281
|
+
}) => {
|
|
282
|
+
const labels = virtualizedComboboxMessages(locale, messageOverrides);
|
|
283
|
+
return /* @__PURE__ */ jsx4(ComboboxPrimitive.Portal, {
|
|
284
|
+
children: /* @__PURE__ */ jsx4(ComboboxPrimitive.Positioner, {
|
|
285
|
+
align: "start",
|
|
286
|
+
className: "isolate z-50",
|
|
287
|
+
side: "bottom",
|
|
288
|
+
sideOffset: 6,
|
|
289
|
+
children: /* @__PURE__ */ jsxs(ComboboxPrimitive.Popup, {
|
|
290
|
+
className: cn("bg-popover text-popover-foreground ring-foreground/10 data-[side=bottom]:slide-in-from-top-2 data-[side=top]:slide-in-from-bottom-2 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-in-95 relative flex max-h-(--available-height) w-(--anchor-width) max-w-(--available-width) min-w-0 origin-(--transform-origin) flex-col overflow-hidden rounded-md shadow-md ring-1 duration-100", contentClassName),
|
|
291
|
+
children: [
|
|
292
|
+
/* @__PURE__ */ jsx4("div", {
|
|
293
|
+
className: "min-w-0 shrink-0 p-1 pb-0",
|
|
294
|
+
children: /* @__PURE__ */ jsx4(InputGroup, {
|
|
295
|
+
className: "border-input/30 bg-input/30 h-8 w-full min-w-0 shadow-none",
|
|
296
|
+
children: /* @__PURE__ */ jsx4(ComboboxPrimitive.Input, {
|
|
297
|
+
placeholder: labels.search,
|
|
298
|
+
render: /* @__PURE__ */ jsx4(InputGroupInput, {})
|
|
299
|
+
})
|
|
300
|
+
})
|
|
301
|
+
}),
|
|
302
|
+
/* @__PURE__ */ jsx4(VirtualizedComboboxList, {
|
|
303
|
+
emptyLabel,
|
|
304
|
+
groupSelections,
|
|
305
|
+
itemIndexRef,
|
|
306
|
+
locale,
|
|
307
|
+
messages: messageOverrides,
|
|
308
|
+
renderItem,
|
|
309
|
+
selectedValues,
|
|
310
|
+
virtualizerRef
|
|
311
|
+
})
|
|
312
|
+
]
|
|
313
|
+
})
|
|
314
|
+
})
|
|
315
|
+
});
|
|
316
|
+
};
|
|
317
|
+
var defaultTrigger = (ariaLabel, ariaInvalid, disabled, label, triggerId) => /* @__PURE__ */ jsxs(Button, {
|
|
318
|
+
"aria-label": ariaLabel,
|
|
319
|
+
"aria-invalid": ariaInvalid,
|
|
320
|
+
className: "w-full max-w-full min-w-0 justify-between overflow-hidden",
|
|
321
|
+
disabled,
|
|
322
|
+
id: triggerId,
|
|
323
|
+
type: "button",
|
|
324
|
+
variant: "outline",
|
|
325
|
+
children: [
|
|
326
|
+
/* @__PURE__ */ jsx4("span", {
|
|
327
|
+
className: "min-w-0 flex-1 truncate pr-7 text-left",
|
|
328
|
+
children: label
|
|
329
|
+
}),
|
|
330
|
+
/* @__PURE__ */ jsx4(ChevronsUpDown, {
|
|
331
|
+
className: "text-muted-foreground shrink-0 opacity-70"
|
|
332
|
+
})
|
|
333
|
+
]
|
|
334
|
+
});
|
|
335
|
+
var defaultClear = (label) => /* @__PURE__ */ jsx4(ComboboxPrimitive.Clear, {
|
|
336
|
+
"aria-label": label,
|
|
337
|
+
className: "text-muted-foreground hover:bg-muted hover:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 absolute top-1/2 right-7 z-10 flex size-6 -translate-y-1/2 items-center justify-center rounded-sm outline-none focus-visible:border focus-visible:ring-3",
|
|
338
|
+
type: "button",
|
|
339
|
+
children: /* @__PURE__ */ jsx4(X, {
|
|
340
|
+
className: "size-3.5"
|
|
341
|
+
})
|
|
342
|
+
});
|
|
343
|
+
var selectedLabel = (value, placeholder) => {
|
|
344
|
+
if (Array.isArray(value)) {
|
|
345
|
+
return value.length > 0 ? value.map(({ label }) => label).join(", ") : placeholder;
|
|
346
|
+
}
|
|
347
|
+
return value && "label" in value ? value.label : placeholder;
|
|
348
|
+
};
|
|
349
|
+
var useComboboxVirtualizerRef = (providedRef) => {
|
|
350
|
+
const localRef = useRef(null);
|
|
351
|
+
return providedRef ?? localRef;
|
|
352
|
+
};
|
|
353
|
+
var VirtualizedComboboxSingle = (props) => {
|
|
354
|
+
const virtualizerRef = useComboboxVirtualizerRef(props.virtualizerRef);
|
|
355
|
+
const itemIndexRef = useRef(new Map);
|
|
356
|
+
const labels = virtualizedComboboxMessages(props.locale ?? "en", props.messages);
|
|
357
|
+
return /* @__PURE__ */ jsxs(ComboboxPrimitive.Root, {
|
|
358
|
+
disabled: props.disabled,
|
|
359
|
+
inputValue: props.searchValue,
|
|
360
|
+
items: [...props.items],
|
|
361
|
+
itemToStringLabel: (item) => item.label,
|
|
362
|
+
isItemEqualToValue: optionEquals,
|
|
363
|
+
onInputValueChange: (value) => props.onSearchValueChange?.(value),
|
|
364
|
+
onItemHighlighted: (_, { index, reason }) => {
|
|
365
|
+
if (reason === "keyboard" && index >= 0) {
|
|
366
|
+
virtualizerRef.current?.scrollToIndex(itemIndexRef.current.get(index) ?? index, { align: "auto" });
|
|
367
|
+
}
|
|
368
|
+
},
|
|
369
|
+
onOpenChange: (open) => props.onOpenChange?.(open),
|
|
370
|
+
onValueChange: (value) => props.onValueChange(value),
|
|
371
|
+
open: props.open,
|
|
372
|
+
value: props.value,
|
|
373
|
+
virtualized: true,
|
|
374
|
+
children: [
|
|
375
|
+
/* @__PURE__ */ jsxs("div", {
|
|
376
|
+
className: "relative",
|
|
377
|
+
children: [
|
|
378
|
+
/* @__PURE__ */ jsx4(ComboboxPrimitive.Trigger, {
|
|
379
|
+
render: props.trigger ?? defaultTrigger(props.ariaLabel, props.ariaInvalid, props.disabled, selectedLabel(props.value, props.placeholder), props.triggerId)
|
|
380
|
+
}),
|
|
381
|
+
props.trigger ? null : defaultClear(labels.clear)
|
|
382
|
+
]
|
|
383
|
+
}),
|
|
384
|
+
/* @__PURE__ */ jsx4(VirtualizedComboboxContent, {
|
|
385
|
+
...props,
|
|
386
|
+
groupSelections: false,
|
|
387
|
+
itemIndexRef,
|
|
388
|
+
selectedValues: new Set(props.value ? [props.value.value] : []),
|
|
389
|
+
virtualizerRef
|
|
390
|
+
})
|
|
391
|
+
]
|
|
392
|
+
});
|
|
393
|
+
};
|
|
394
|
+
var VirtualizedComboboxMultiple = (props) => {
|
|
395
|
+
const virtualizerRef = useComboboxVirtualizerRef(props.virtualizerRef);
|
|
396
|
+
const itemIndexRef = useRef(new Map);
|
|
397
|
+
const labels = virtualizedComboboxMessages(props.locale ?? "en", props.messages);
|
|
398
|
+
return /* @__PURE__ */ jsxs(ComboboxPrimitive.Root, {
|
|
399
|
+
disabled: props.disabled,
|
|
400
|
+
inputValue: props.searchValue,
|
|
401
|
+
items: [...props.items],
|
|
402
|
+
itemToStringLabel: (item) => item.label,
|
|
403
|
+
isItemEqualToValue: optionEquals,
|
|
404
|
+
multiple: true,
|
|
405
|
+
onInputValueChange: (value) => props.onSearchValueChange?.(value),
|
|
406
|
+
onItemHighlighted: (_, { index, reason }) => {
|
|
407
|
+
if (reason === "keyboard" && index >= 0) {
|
|
408
|
+
virtualizerRef.current?.scrollToIndex(itemIndexRef.current.get(index) ?? index, { align: "auto" });
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
onOpenChange: (open) => props.onOpenChange?.(open),
|
|
412
|
+
onValueChange: (value) => props.onValueChange(value),
|
|
413
|
+
open: props.open,
|
|
414
|
+
value: [...props.value],
|
|
415
|
+
virtualized: true,
|
|
416
|
+
children: [
|
|
417
|
+
/* @__PURE__ */ jsxs("div", {
|
|
418
|
+
className: "relative",
|
|
419
|
+
children: [
|
|
420
|
+
/* @__PURE__ */ jsx4(ComboboxPrimitive.Trigger, {
|
|
421
|
+
render: props.trigger ?? defaultTrigger(props.ariaLabel, props.ariaInvalid, props.disabled, selectedLabel(props.value, props.placeholder), props.triggerId)
|
|
422
|
+
}),
|
|
423
|
+
props.trigger ? null : defaultClear(labels.clear)
|
|
424
|
+
]
|
|
425
|
+
}),
|
|
426
|
+
/* @__PURE__ */ jsx4(VirtualizedComboboxContent, {
|
|
427
|
+
...props,
|
|
428
|
+
groupSelections: true,
|
|
429
|
+
itemIndexRef,
|
|
430
|
+
selectedValues: new Set(props.value.map(({ value }) => value)),
|
|
431
|
+
virtualizerRef
|
|
432
|
+
})
|
|
433
|
+
]
|
|
434
|
+
});
|
|
435
|
+
};
|
|
436
|
+
function VirtualizedCombobox(props) {
|
|
437
|
+
const locale = useKrakstackLocale(props.locale);
|
|
438
|
+
return props.multiple ? /* @__PURE__ */ jsx4(VirtualizedComboboxMultiple, {
|
|
439
|
+
...props,
|
|
440
|
+
locale
|
|
441
|
+
}) : /* @__PURE__ */ jsx4(VirtualizedComboboxSingle, {
|
|
442
|
+
...props,
|
|
443
|
+
locale
|
|
444
|
+
});
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// ../../src/components/ui/phone-number-input.tsx
|
|
448
|
+
import { ChevronsUpDown as ChevronsUpDown2 } from "lucide-react";
|
|
449
|
+
import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
450
|
+
var normalizePhoneNumber = (value, country) => {
|
|
451
|
+
const phone = parsePhoneNumberFromString(value, {
|
|
452
|
+
defaultCountry: country,
|
|
453
|
+
extract: false
|
|
454
|
+
});
|
|
455
|
+
return phone?.isValid() ? {
|
|
456
|
+
e164: phone.number,
|
|
457
|
+
extension: phone.ext ?? null,
|
|
458
|
+
country: phone.country ?? null
|
|
459
|
+
} : null;
|
|
460
|
+
};
|
|
461
|
+
var PhoneNumberInput = ({
|
|
462
|
+
value,
|
|
463
|
+
country,
|
|
464
|
+
onCountryChange,
|
|
465
|
+
onValueChange,
|
|
466
|
+
countries = getCountries(),
|
|
467
|
+
locale,
|
|
468
|
+
label,
|
|
469
|
+
id,
|
|
470
|
+
onBlur,
|
|
471
|
+
name,
|
|
472
|
+
withExtension = false,
|
|
473
|
+
onKeyDown,
|
|
474
|
+
...props
|
|
475
|
+
}) => {
|
|
476
|
+
const generatedId = useId();
|
|
477
|
+
const inputId = id ?? generatedId;
|
|
478
|
+
const language = useKrakstackLocale2(locale);
|
|
479
|
+
const french = language.startsWith("fr");
|
|
480
|
+
const names = new Intl.DisplayNames([language], { type: "region" });
|
|
481
|
+
const options = [...new Set([country, ...countries])].sort((a, b) => (names.of(a) ?? a).localeCompare(names.of(b) ?? b, language));
|
|
482
|
+
const valid = normalizePhoneNumber(value, country);
|
|
483
|
+
const parsed = parsePhoneNumberFromString(value, {
|
|
484
|
+
defaultCountry: country,
|
|
485
|
+
extract: false
|
|
486
|
+
});
|
|
487
|
+
const callingCode = value.trim().startsWith("+") ? parsed?.countryCallingCode ?? getCountryCallingCode(country) : getCountryCallingCode(country);
|
|
488
|
+
const nationalDraft = value.trim().startsWith(`+${callingCode}`) ? value.trim().slice(callingCode.length + 1).trimStart() : value;
|
|
489
|
+
const extension = parsed?.ext ?? "";
|
|
490
|
+
const nationalDigits = (extension ? nationalDraft.replace(/(?:ext\.?|x|#|;ext=)\s*\d+\s*$/i, "") : nationalDraft).replace(/\D/g, "");
|
|
491
|
+
const formatCountry = parsed?.country ?? country;
|
|
492
|
+
const nationalValue = parsed?.isValid() ? parsed.formatNational({ formatExtension: (number) => number }) : new AsYouType(formatCountry).input(nationalDigits);
|
|
493
|
+
const pendingCaret = useRef2(null);
|
|
494
|
+
useLayoutEffect(() => {
|
|
495
|
+
const pending = pendingCaret.current;
|
|
496
|
+
if (!pending)
|
|
497
|
+
return;
|
|
498
|
+
pendingCaret.current = null;
|
|
499
|
+
let remaining = pending.digits;
|
|
500
|
+
let position = 0;
|
|
501
|
+
while (position < pending.element.value.length && remaining > 0) {
|
|
502
|
+
if (/\d/.test(pending.element.value[position]))
|
|
503
|
+
remaining--;
|
|
504
|
+
position++;
|
|
505
|
+
}
|
|
506
|
+
pending.element.setSelectionRange(position, position);
|
|
507
|
+
});
|
|
508
|
+
const emitNational = (draft, nextExtension = extension) => {
|
|
509
|
+
const digits = draft.replace(/\D/g, "");
|
|
510
|
+
const next = digits ? `+${callingCode} ${digits}${nextExtension ? ` ext. ${nextExtension}` : ""}` : "";
|
|
511
|
+
onValueChange(next, normalizePhoneNumber(next, country));
|
|
512
|
+
};
|
|
513
|
+
const countryLabel = french ? "Pays du numéro" : "Phone country";
|
|
514
|
+
const items = options.map((code) => ({
|
|
515
|
+
value: code,
|
|
516
|
+
label: `${names.of(code)} (${code}) +${getCountryCallingCode(code)}`
|
|
517
|
+
}));
|
|
518
|
+
return /* @__PURE__ */ jsxs2("div", {
|
|
519
|
+
className: "grid gap-2",
|
|
520
|
+
children: [
|
|
521
|
+
/* @__PURE__ */ jsx5("label", {
|
|
522
|
+
htmlFor: inputId,
|
|
523
|
+
className: "text-sm font-medium",
|
|
524
|
+
children: label ?? (french ? "Numéro de téléphone" : "Phone number")
|
|
525
|
+
}),
|
|
526
|
+
name ? /* @__PURE__ */ jsx5("input", {
|
|
527
|
+
type: "hidden",
|
|
528
|
+
name,
|
|
529
|
+
value,
|
|
530
|
+
disabled: props.disabled
|
|
531
|
+
}) : null,
|
|
532
|
+
/* @__PURE__ */ jsxs2("div", {
|
|
533
|
+
className: "flex min-w-0 gap-2",
|
|
534
|
+
children: [
|
|
535
|
+
/* @__PURE__ */ jsx5(VirtualizedCombobox, {
|
|
536
|
+
ariaLabel: countryLabel,
|
|
537
|
+
locale: language,
|
|
538
|
+
items,
|
|
539
|
+
value: items.find((item) => item.value === country) ?? null,
|
|
540
|
+
placeholder: country,
|
|
541
|
+
emptyLabel: french ? "Aucun pays correspondant." : "No matching countries.",
|
|
542
|
+
contentClassName: "w-72! max-w-[calc(100vw-2rem)]!",
|
|
543
|
+
disabled: props.disabled || props.readOnly,
|
|
544
|
+
trigger: /* @__PURE__ */ jsxs2(Button, {
|
|
545
|
+
type: "button",
|
|
546
|
+
variant: "outline",
|
|
547
|
+
"aria-label": countryLabel,
|
|
548
|
+
disabled: props.disabled || props.readOnly,
|
|
549
|
+
className: "shrink-0 gap-1.5 px-2.5",
|
|
550
|
+
children: [
|
|
551
|
+
/* @__PURE__ */ jsx5("span", {
|
|
552
|
+
children: country
|
|
553
|
+
}),
|
|
554
|
+
/* @__PURE__ */ jsxs2("span", {
|
|
555
|
+
className: "text-muted-foreground",
|
|
556
|
+
children: [
|
|
557
|
+
"+",
|
|
558
|
+
callingCode
|
|
559
|
+
]
|
|
560
|
+
}),
|
|
561
|
+
/* @__PURE__ */ jsx5(ChevronsUpDown2, {
|
|
562
|
+
"aria-hidden": "true",
|
|
563
|
+
className: "size-3.5 opacity-60"
|
|
564
|
+
})
|
|
565
|
+
]
|
|
566
|
+
}),
|
|
567
|
+
onValueChange: (item) => {
|
|
568
|
+
const selected = options.find((option) => option === item?.value);
|
|
569
|
+
if (!selected || selected === country)
|
|
570
|
+
return;
|
|
571
|
+
onCountryChange(selected);
|
|
572
|
+
const next = nationalDigits ? `+${getCountryCallingCode(selected)} ${nationalDigits}${extension ? ` ext. ${extension}` : ""}` : "";
|
|
573
|
+
onValueChange(next, normalizePhoneNumber(next, selected));
|
|
574
|
+
}
|
|
575
|
+
}),
|
|
576
|
+
/* @__PURE__ */ jsx5(Input, {
|
|
577
|
+
...props,
|
|
578
|
+
id: inputId,
|
|
579
|
+
type: "tel",
|
|
580
|
+
inputMode: "numeric",
|
|
581
|
+
autoComplete: props.autoComplete ?? "tel-national",
|
|
582
|
+
className: "min-w-0 flex-1",
|
|
583
|
+
value: nationalValue,
|
|
584
|
+
"aria-invalid": Boolean(value) && !valid,
|
|
585
|
+
"aria-describedby": `${inputId}-status ${props["aria-describedby"] ?? ""}`,
|
|
586
|
+
onChange: (event) => {
|
|
587
|
+
const draft = event.target.value;
|
|
588
|
+
const international = draft.trimStart().startsWith("+");
|
|
589
|
+
const pasted = parsePhoneNumberFromString(draft, {
|
|
590
|
+
defaultCountry: country,
|
|
591
|
+
extract: false
|
|
592
|
+
});
|
|
593
|
+
if (!international && !pasted?.ext) {
|
|
594
|
+
pendingCaret.current = {
|
|
595
|
+
element: event.target,
|
|
596
|
+
digits: draft.slice(0, event.target.selectionStart ?? draft.length).replace(/\D/g, "").length
|
|
597
|
+
};
|
|
598
|
+
emitNational(draft);
|
|
599
|
+
return;
|
|
600
|
+
}
|
|
601
|
+
const digits = draft.replace(/\D/g, "");
|
|
602
|
+
const next = pasted?.isValid() ? `${pasted.number}${pasted.ext ? ` ext. ${pasted.ext}` : ""}` : digits ? `${international ? "+" : `+${callingCode} `}${digits}` : "";
|
|
603
|
+
const details = normalizePhoneNumber(next, country);
|
|
604
|
+
if (international && details?.country && options.includes(details.country) && details.country !== country)
|
|
605
|
+
onCountryChange(details.country);
|
|
606
|
+
onValueChange(next, details);
|
|
607
|
+
},
|
|
608
|
+
onKeyDown: (event) => {
|
|
609
|
+
onKeyDown?.(event);
|
|
610
|
+
if (event.defaultPrevented || props.readOnly || props.disabled || event.ctrlKey || event.metaKey || event.altKey)
|
|
611
|
+
return;
|
|
612
|
+
if (event.key.length === 1 && /\D/.test(event.key)) {
|
|
613
|
+
event.preventDefault();
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (event.key !== "Backspace" && event.key !== "Delete")
|
|
617
|
+
return;
|
|
618
|
+
const element = event.currentTarget;
|
|
619
|
+
const start = element.selectionStart ?? 0;
|
|
620
|
+
if (start !== element.selectionEnd)
|
|
621
|
+
return;
|
|
622
|
+
const direction = event.key === "Backspace" ? -1 : 1;
|
|
623
|
+
let index = direction === -1 ? start - 1 : start;
|
|
624
|
+
if (index < 0 || index >= nationalValue.length || /\d/.test(nationalValue[index]))
|
|
625
|
+
return;
|
|
626
|
+
while (index >= 0 && index < nationalValue.length && /\D/.test(nationalValue[index]))
|
|
627
|
+
index += direction;
|
|
628
|
+
if (index < 0 || index >= nationalValue.length)
|
|
629
|
+
return;
|
|
630
|
+
event.preventDefault();
|
|
631
|
+
const next = nationalValue.slice(0, index) + nationalValue.slice(index + 1);
|
|
632
|
+
pendingCaret.current = {
|
|
633
|
+
element,
|
|
634
|
+
digits: nationalValue.slice(0, direction === -1 ? index : start).replace(/\D/g, "").length
|
|
635
|
+
};
|
|
636
|
+
emitNational(next);
|
|
637
|
+
},
|
|
638
|
+
onBlur: (event) => {
|
|
639
|
+
if (!props.readOnly && !props.disabled && valid) {
|
|
640
|
+
const formatted = parsePhoneNumberFromString(value, {
|
|
641
|
+
defaultCountry: country,
|
|
642
|
+
extract: false
|
|
643
|
+
})?.formatInternational();
|
|
644
|
+
if (formatted && formatted !== value)
|
|
645
|
+
onValueChange(formatted, valid);
|
|
646
|
+
}
|
|
647
|
+
onBlur?.(event);
|
|
648
|
+
}
|
|
649
|
+
})
|
|
650
|
+
]
|
|
651
|
+
}),
|
|
652
|
+
withExtension || extension ? /* @__PURE__ */ jsxs2("div", {
|
|
653
|
+
className: "grid max-w-32 gap-1.5",
|
|
654
|
+
children: [
|
|
655
|
+
/* @__PURE__ */ jsx5("label", {
|
|
656
|
+
htmlFor: `${inputId}-extension`,
|
|
657
|
+
className: "text-muted-foreground text-xs",
|
|
658
|
+
children: french ? "Poste" : "Extension"
|
|
659
|
+
}),
|
|
660
|
+
/* @__PURE__ */ jsx5(Input, {
|
|
661
|
+
id: `${inputId}-extension`,
|
|
662
|
+
type: "text",
|
|
663
|
+
inputMode: "numeric",
|
|
664
|
+
value: extension,
|
|
665
|
+
disabled: props.disabled,
|
|
666
|
+
readOnly: props.readOnly,
|
|
667
|
+
onChange: (event) => emitNational(nationalDigits, event.target.value.replace(/\D/g, ""))
|
|
668
|
+
})
|
|
669
|
+
]
|
|
670
|
+
}) : null,
|
|
671
|
+
/* @__PURE__ */ jsx5("p", {
|
|
672
|
+
id: `${inputId}-status`,
|
|
673
|
+
className: "text-muted-foreground text-xs",
|
|
674
|
+
children: valid ? `${valid.e164}${valid.extension ? ` ext. ${valid.extension}` : ""}` : french ? "Saisissez un numéro complet. La validation ne vérifie pas son propriétaire." : "Enter a complete number. Validation does not verify ownership."
|
|
675
|
+
})
|
|
676
|
+
]
|
|
677
|
+
});
|
|
678
|
+
};
|
|
679
|
+
export {
|
|
680
|
+
PhoneNumberInput,
|
|
681
|
+
normalizePhoneNumber
|
|
682
|
+
};
|