@eldrajs/ui 0.3.7 → 0.3.9

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 (61) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/LICENSE-country-flag-icons +25 -0
  3. package/README.md +274 -66
  4. package/dist/CountryFlag-DOa8lOHp.js +71 -0
  5. package/dist/PhoneInput-CX83wgD0.js +695 -0
  6. package/dist/{VariantPicker-Cr_AkX47.js → VariantPicker-BqLbiONX.js} +122 -2302
  7. package/dist/components/chip/Chip.vue.d.ts +9 -0
  8. package/dist/components/dialog/Dialog.vue.d.ts +9 -0
  9. package/dist/components/drawer/Drawer.vue.d.ts +9 -0
  10. package/dist/components/filter-panel/FilterGroup.vue.d.ts +9 -0
  11. package/dist/components/filter-panel/FilterPanel.vue.d.ts +9 -0
  12. package/dist/components/filter-panel/facets/ColourFacet.vue.d.ts +9 -0
  13. package/dist/components/filter-panel/facets/ListFacet.vue.d.ts +9 -0
  14. package/dist/components/filter-panel/facets/RangeFacet.vue.d.ts +9 -0
  15. package/dist/components/filter-panel/facets/SizeFacet.vue.d.ts +9 -0
  16. package/dist/components/filter-panel/facets/ToggleFacet.vue.d.ts +9 -0
  17. package/dist/components/lightbox/Lightbox.vue.d.ts +9 -0
  18. package/dist/components/nav-menu/NavMenu.vue.d.ts +9 -0
  19. package/dist/components/pagination/Pagination.vue.d.ts +9 -0
  20. package/dist/components/range-slider/RangeSlider.vue.d.ts +9 -0
  21. package/dist/components/search-bar/SearchBar.vue.d.ts +9 -0
  22. package/dist/components/search-modal/SearchModal.vue.d.ts +9 -0
  23. package/dist/components/select/MultiSelect.vue.d.ts +10 -0
  24. package/dist/components/select/Select.vue.d.ts +9 -0
  25. package/dist/components/select/types.d.ts +7 -1
  26. package/dist/components/site-form/SiteForm.vue.d.ts +9 -0
  27. package/dist/components/toast/Toast.vue.d.ts +9 -0
  28. package/dist/components/toast/Toaster.vue.d.ts +9 -0
  29. package/dist/components.css +64 -0
  30. package/dist/flag/CountryFlag.vue.d.ts +9 -0
  31. package/dist/flag/flags.d.ts +8 -0
  32. package/dist/flag/index.d.ts +9 -0
  33. package/dist/flag.js +1 -0
  34. package/dist/index.js +4 -2
  35. package/dist/messages/en-US.d.ts +21 -0
  36. package/dist/messages/is-IS.js +10 -1
  37. package/dist/phone/PhoneInput.vue.d.ts +221 -0
  38. package/dist/phone/caret.d.ts +14 -0
  39. package/dist/phone/examples.d.ts +2 -0
  40. package/dist/phone/index.d.ts +13 -0
  41. package/dist/phone/phone.d.ts +62 -0
  42. package/dist/phone/phoneFlagData.d.ts +2 -0
  43. package/dist/phone/rule.d.ts +22 -0
  44. package/dist/phone/types.d.ts +63 -0
  45. package/dist/phone/vee-validate/FieldPhoneInput.vue.d.ts +24 -0
  46. package/dist/phone/vee-validate/index.d.ts +3 -0
  47. package/dist/phone/vee-validate/types.d.ts +3 -0
  48. package/dist/phone/vee-validate.js +96 -0
  49. package/dist/phone.js +3 -0
  50. package/dist/phoneFlagData-D9dDT2uC.js +261 -0
  51. package/dist/resolver.d.ts +15 -2
  52. package/dist/resolver.js +26 -4
  53. package/dist/style.css +64 -0
  54. package/dist/useEldraScope-BDbGzt7R.js +32 -0
  55. package/dist/useFieldControl-D1j54YON.js +273 -0
  56. package/dist/{useMessages-DOHGfip_.js → useMessages-CkhrRmu7.js} +22 -1
  57. package/dist/usePopover-ECHpsSRF.js +2199 -0
  58. package/dist/utilities.css +37 -0
  59. package/dist/vee-validate.js +7 -273
  60. package/dist/vue-i18n.js +4 -1
  61. package/package.json +23 -2
@@ -0,0 +1,695 @@
1
+ import { G as FIELD_KEY, P as FIELD_TEXT, Q as useUiId, W as useEldraUiLocale, X as useControllableModel, Z as joinIds, c as useOptionList, d as SelectPanel_default, k as FIELD_RADIUS, t as usePopover, u as useListbox } from "./usePopover-ECHpsSRF.js";
2
+ import { r as useEldraScope } from "./useEldraScope-BDbGzt7R.js";
3
+ import { i as enUS, r as useMessages } from "./useMessages-CkhrRmu7.js";
4
+ import { t as CountryFlag_default } from "./CountryFlag-DOa8lOHp.js";
5
+ import { Fragment, Teleport, computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, inject, mergeProps, nextTick, normalizeClass, onMounted, openBlock, ref, renderSlot, toDisplayString, toValue, unref, watch, withCtx } from "vue";
6
+ import { comparator } from "@eldrajs/sdk/format";
7
+ import { AsYouType, Metadata, getCountries, getCountryCallingCode, getExampleNumber, isSupportedCountry, parseIncompletePhoneNumber, parsePhoneNumberFromString } from "libphonenumber-js/min";
8
+ import examples from "libphonenumber-js/mobile/examples";
9
+ import { displayNames } from "@eldrajs/sdk/format/display-names";
10
+ // src/phone/caret.ts
11
+ /**
12
+ * Caret bookkeeping for a field that is re-spaced on every keystroke. Writing an input's `value`
13
+ * moves the caret to the end, so the caret is put back by what the customer typed, not by offset:
14
+ * the digits (and a leading `+`) before it are counted in the old text, and it lands after the same
15
+ * number of them in the new one. Spaces, brackets and dashes belong to the format and count for
16
+ * nothing.
17
+ */
18
+ /** Whether the character at `index` is one the customer typed: a digit, or a `+` that leads. */
19
+ function significant(text, index, seen) {
20
+ const char = text[index];
21
+ if (char >= "0" && char <= "9") return true;
22
+ return char === "+" && seen === 0;
23
+ }
24
+ /** How many typed characters sit before `caret` in `text`. */
25
+ function significantBefore(text, caret) {
26
+ let count = 0;
27
+ const end = Math.min(caret, text.length);
28
+ for (let index = 0; index < end; index += 1) if (significant(text, index, count)) count += 1;
29
+ return count;
30
+ }
31
+ /**
32
+ * Where the caret goes in `text` so that `count` typed characters sit before it. Past the last one
33
+ * it goes to the very end, so a closing bracket the format added is behind the caret, not ahead.
34
+ */
35
+ function caretAfter(text, count) {
36
+ if (count <= 0) return 0;
37
+ let seen = 0;
38
+ for (let index = 0; index < text.length; index += 1) {
39
+ if (!significant(text, index, seen)) continue;
40
+ seen += 1;
41
+ if (seen === count) return significantBefore(text, text.length) === count ? text.length : index + 1;
42
+ }
43
+ return text.length;
44
+ }
45
+ // src/phone/examples.ts
46
+ /** A number the country could have, spaced as it writes one (`IS` → `611 1234`): a placeholder. */
47
+ function phoneExample(country) {
48
+ if (!isSupportedCountry(country)) return void 0;
49
+ return getExampleNumber(country, examples)?.formatNational();
50
+ }
51
+ // src/phone/phone.ts
52
+ /**
53
+ * Everything `@eldrajs/ui/phone` knows about phone numbers, with no Vue in it. This file and
54
+ * `./examples.ts` are the only places in the package that import `libphonenumber-js`, an optional
55
+ * peer: the root entry and `./vee-validate` never reach them
56
+ * (`src/__tests__/phoneIsolation.spec.ts`).
57
+ *
58
+ * The `min` metadata is the one imported. It accepts landlines and mobiles and rejects a number
59
+ * whose prefix the country does not use; `mobile` would refuse every landline.
60
+ */
61
+ var supported = (country) => country !== void 0 && isSupportedCountry(country);
62
+ var allCountries;
63
+ /** Every country a number can be written for, as ISO 3166-1 alpha-2 codes. */
64
+ function phoneCountries() {
65
+ allCountries ??= getCountries();
66
+ return allCountries;
67
+ }
68
+ /** A country's dialling code with no `+` (`IS` → `354`), or `''` for a country it does not know. */
69
+ function phoneCallingCode(country) {
70
+ return supported(country) ? getCountryCallingCode(country) : "";
71
+ }
72
+ var metadata;
73
+ /** The countries sharing a dialling code, the one the code belongs to first (`1` → `US`, …). */
74
+ function countriesForCallingCode(code) {
75
+ metadata ??= new Metadata();
76
+ return metadata.getCountryCodesForCallingCode(code) ?? [];
77
+ }
78
+ /**
79
+ * Takes a number apart. `country` is where a number written without a dialling code is from.
80
+ * `null` for text with no number in it.
81
+ */
82
+ function parsePhone(value, country) {
83
+ const parsed = parsePhoneNumberFromString(value, supported(country) ? country : void 0);
84
+ if (parsed === void 0) return null;
85
+ return {
86
+ e164: parsed.number,
87
+ country: parsed.country,
88
+ callingCode: parsed.countryCallingCode,
89
+ nationalNumber: parsed.nationalNumber,
90
+ national: parsed.formatNational(),
91
+ valid: parsed.isValid()
92
+ };
93
+ }
94
+ /**
95
+ * Whether `value` is a number that exists. With a `country` it must also be that country's: a
96
+ * Danish number is not valid for Iceland, however well formed.
97
+ */
98
+ function isValidPhone(value, country) {
99
+ const parts = parsePhone(value, country);
100
+ if (parts === null || !parts.valid) return false;
101
+ return country === void 0 || parts.country === country;
102
+ }
103
+ /** The country a dialling code selects: see `typePhone`. */
104
+ function countryForCode(code, detected, current, allowed) {
105
+ if (detected !== void 0 && allowed(detected)) return detected;
106
+ const sharing = countriesForCallingCode(code).filter(allowed);
107
+ return sharing.includes(current) ? current : sharing[0];
108
+ }
109
+ function national(digits, country, allowed, stripped) {
110
+ const code = supported(country) ? country : void 0;
111
+ const typed = new AsYouType(code);
112
+ let text = typed.input(digits);
113
+ const number = typed.getNumber();
114
+ const e164 = number?.number ?? "";
115
+ const actual = e164 === "" ? void 0 : parsePhoneNumberFromString(e164)?.country;
116
+ let next = country;
117
+ if (actual !== void 0 && actual !== country && allowed(actual)) {
118
+ next = actual;
119
+ text = new AsYouType(actual).input(digits);
120
+ }
121
+ return {
122
+ text,
123
+ country: next,
124
+ e164,
125
+ nationalNumber: number?.nationalNumber ?? "",
126
+ stripped
127
+ };
128
+ }
129
+ /**
130
+ * One edit of the field: `raw` is whatever the `<input>` now holds, `country` the one chosen.
131
+ *
132
+ * - The text is reduced to digits and re-spaced the way the country writes a number.
133
+ * - Text that starts with `+` picks its own country. As soon as the dialling code is complete the
134
+ * `+` and the code leave the text (the country button shows them) and the rest is the national
135
+ * number. A code several countries share keeps the current country if it is one of them, and
136
+ * otherwise takes the country the code belongs to, until the digits identify another.
137
+ * - `allowed` limits which countries the text may switch to. A dialling code of none of them stays
138
+ * in the text as typed.
139
+ */
140
+ function typePhone(raw, country, allowed = () => true) {
141
+ const chars = parseIncompletePhoneNumber(raw);
142
+ if (!chars.startsWith("+")) return national(chars, country, allowed, 0);
143
+ const typed = new AsYouType();
144
+ const text = typed.input(chars);
145
+ const code = typed.getCallingCode();
146
+ if (code !== void 0) {
147
+ const next = countryForCode(code, typed.getCountry(), country, allowed);
148
+ if (next !== void 0) return national(chars.slice(1 + code.length), next, allowed, 1 + code.length);
149
+ }
150
+ const number = typed.getNumber();
151
+ return {
152
+ text,
153
+ country,
154
+ e164: number?.number ?? "",
155
+ nationalNumber: number?.nationalNumber ?? "",
156
+ stripped: 0
157
+ };
158
+ }
159
+ /**
160
+ * The field's state for a value that arrives from outside (a bound `modelValue`, a saved address).
161
+ * A complete number is spaced as the country writes it in full, national prefix included
162
+ * (`07400 123456`), which is more than the as-you-type spacing knows for a number typed without it.
163
+ */
164
+ function readPhone(value, country, allowed = () => true) {
165
+ const state = typePhone(value, country, allowed);
166
+ const parts = state.e164 === "" ? null : parsePhone(state.e164);
167
+ if (parts !== null && parts.valid && parts.country === state.country) return {
168
+ ...state,
169
+ text: parts.national
170
+ };
171
+ return state;
172
+ }
173
+ // src/phone/rule.ts
174
+ /** A country's name in `locale` (`IS`, `is-IS` → `Ísland`); the code itself when it has none. */
175
+ function phoneCountryName(country, locale) {
176
+ try {
177
+ return displayNames(locale, { type: "region" }).of(country) ?? country;
178
+ } catch {
179
+ return country;
180
+ }
181
+ }
182
+ /**
183
+ * A validation rule for a `PhoneInput`'s value: `true`, or the message to show.
184
+ *
185
+ * An empty value passes: whether the field is required is another rule's question. The shape is
186
+ * vee-validate's rule function, and nothing here imports vee-validate, so it serves any form code.
187
+ */
188
+ function phoneRule(options = {}) {
189
+ return (value) => {
190
+ if (value === void 0 || value === null || value === "") return true;
191
+ const text = String(value);
192
+ const country = toValue(options.country);
193
+ if (isValidPhone(text, country)) return true;
194
+ const messages = {
195
+ ...enUS,
196
+ ...toValue(options.messages)
197
+ };
198
+ const named = country ?? parsePhone(text)?.country;
199
+ if (named === void 0) return messages.phoneInvalidNumber;
200
+ return messages.phoneInvalid(phoneCountryName(named, toValue(options.locale) ?? "en-US"));
201
+ };
202
+ }
203
+ // src/phone/PhoneInput.vue?vue&type=script&setup=true&lang.ts
204
+ var _hoisted_1 = ["data-eldra-scope"];
205
+ var _hoisted_2 = [
206
+ "aria-expanded",
207
+ "aria-controls",
208
+ "aria-label",
209
+ "aria-disabled",
210
+ "aria-readonly",
211
+ "disabled"
212
+ ];
213
+ var _hoisted_3 = ["data-eldra-slot"];
214
+ var _hoisted_4 = [
215
+ "id",
216
+ "value",
217
+ "placeholder",
218
+ "autocomplete",
219
+ "required",
220
+ "readonly",
221
+ "disabled",
222
+ "aria-invalid",
223
+ "aria-describedby"
224
+ ];
225
+ var _hoisted_5 = [
226
+ "name",
227
+ "value",
228
+ "disabled"
229
+ ];
230
+ var _hoisted_6 = { class: "eldra:eldra-select-match" };
231
+ var rootClass = "eldra:relative eldra:block eldra:w-full";
232
+ /**
233
+ * The field box: `Input`'s box (its border variable, its radius variable, its heights, its state
234
+ * colours), drawn on a wrapper because two controls sit in it. The one focus ring is the box's:
235
+ * `eldra-focus-proxy` turns it on while the number or the button is `:focus-visible`, and
236
+ * `eldra-focus-has-open` keeps it on while the list is open and focus is in the list's search
237
+ * field. No `transition-*` utility beside `eldra-focus`, which owns the transition list.
238
+ */
239
+ var LIVE_FILL = "eldra:bg-background eldra:text-text";
240
+ var REST = "eldra:border-border-strong eldra:hover:border-text eldra:focus-within:border-text";
241
+ var OPEN = "eldra:border-text";
242
+ var INVALID = "eldra:border-danger";
243
+ var DISABLED = "eldra:bg-surface-strong eldra:border-border eldra:border-dashed eldra:text-muted eldra:cursor-not-allowed";
244
+ var READONLY_FILL = "eldra:bg-surface eldra:text-text";
245
+ var BUTTON_BASE = "eldra:flex eldra:shrink-0 eldra:items-center eldra:gap-1.5 eldra:ps-2.5 eldra:pe-2 eldra:border-e eldra:border-border eldra:tabular-nums eldra:outline-none eldra:rounded-s-[calc(var(--eldra-input-radius,var(--eldra-radius-md))-var(--eldra-field-border-width,1px))]";
246
+ var BUTTON_LIVE = "eldra:cursor-pointer eldra:hover:bg-[color-mix(in_oklab,var(--eldra-color-text),transparent_94%)] eldra:focus-visible:bg-[color-mix(in_oklab,var(--eldra-color-text),transparent_94%)]";
247
+ // src/phone/PhoneInput.vue
248
+ var PhoneInput_default = /* @__PURE__ */ defineComponent({
249
+ inheritAttrs: false,
250
+ __name: "PhoneInput",
251
+ props: {
252
+ modelValue: { default: void 0 },
253
+ country: { default: void 0 },
254
+ defaultCountry: { default: void 0 },
255
+ preferredCountries: { default: void 0 },
256
+ countries: { default: void 0 },
257
+ locale: { default: void 0 },
258
+ size: { default: "md" },
259
+ id: { default: void 0 },
260
+ name: { default: void 0 },
261
+ placeholder: {
262
+ type: [String, Boolean],
263
+ default: void 0
264
+ },
265
+ autocomplete: { default: "tel-national" },
266
+ invalid: {
267
+ type: Boolean,
268
+ default: void 0
269
+ },
270
+ describedBy: { default: void 0 },
271
+ required: {
272
+ type: Boolean,
273
+ default: void 0
274
+ },
275
+ readonly: {
276
+ type: Boolean,
277
+ default: false
278
+ },
279
+ disabled: {
280
+ type: Boolean,
281
+ default: false
282
+ },
283
+ messages: { default: void 0 },
284
+ classes: { default: void 0 }
285
+ },
286
+ emits: [
287
+ "update:modelValue",
288
+ "update:country",
289
+ "change",
290
+ "focus",
291
+ "blur",
292
+ "open",
293
+ "close"
294
+ ],
295
+ setup(__props, { expose: __expose, emit: __emit }) {
296
+ const eldra = useEldraScope();
297
+ const props = __props;
298
+ const emit = __emit;
299
+ const m = useMessages(() => props.messages);
300
+ const providedLocale = useEldraUiLocale();
301
+ const locale = computed(() => props.locale ?? providedLocale.value);
302
+ const field = inject(FIELD_KEY, null);
303
+ const controlId = useUiId("phone", () => props.id ?? (field?.value.labelsControl === true ? field.value.id : void 0));
304
+ const describedBy = computed(() => joinIds(props.describedBy, field?.value.describedBy));
305
+ const isInvalid = computed(() => props.invalid ?? field?.value.invalid ?? false);
306
+ const isRequired = computed(() => props.required ?? field?.value.required ?? false);
307
+ const showsInvalid = computed(() => isInvalid.value && !props.disabled);
308
+ const panelId = computed(() => `${controlId.value}-panel`);
309
+ const listboxId = computed(() => `${controlId.value}-listbox`);
310
+ const known = new Set(phoneCountries());
311
+ /** The countries on offer, in the order given: every one, or the `countries` this field is limited to. */
312
+ const offered = computed(() => props.countries === void 0 ? phoneCountries() : [...new Set(props.countries)].filter((country) => known.has(country)));
313
+ const offeredSet = computed(() => new Set(offered.value));
314
+ const allowed = (country) => offeredSet.value.has(country);
315
+ const preferred = computed(() => [...new Set(props.preferredCountries ?? [])].filter((country) => allowed(country)));
316
+ function startingCountry() {
317
+ const limited = props.countries === void 0 ? void 0 : offered.value[0];
318
+ for (const country of [
319
+ props.country,
320
+ props.defaultCountry,
321
+ preferred.value[0],
322
+ limited,
323
+ "US"
324
+ ]) if (country !== void 0 && allowed(country)) return country;
325
+ return offered.value[0] ?? "US";
326
+ }
327
+ /** Controlled when the parent binds `modelValue`, self-managing when it does not. */
328
+ const model = useControllableModel(props, emit, () => "");
329
+ /**
330
+ * The field's own state: the text it shows and the country it is on. The text is not derived from
331
+ * the model, because the model cannot hold it: `07400` and `7400` are the same E.164 digits, and a
332
+ * field re-derived from the model on every keystroke would eat the `0` as it was typed. The model
333
+ * is read only when it holds something this state did not produce (`syncFromModel`).
334
+ */
335
+ const state = ref(readPhone(model.value, startingCountry(), allowed));
336
+ const text = computed(() => state.value.text);
337
+ const country = computed(() => state.value.country);
338
+ const callingCode = computed(() => phoneCallingCode(country.value));
339
+ function describe(next) {
340
+ return {
341
+ e164: next.e164,
342
+ country: next.country,
343
+ callingCode: phoneCallingCode(next.country),
344
+ nationalNumber: next.nationalNumber,
345
+ valid: isValidPhone(next.e164, next.country)
346
+ };
347
+ }
348
+ /** Takes a new state and tells the parent what changed. */
349
+ function commit(next) {
350
+ const previous = state.value;
351
+ state.value = next;
352
+ if (next.country !== previous.country) emit("update:country", next.country);
353
+ if (next.e164 !== model.value) model.value = next.e164;
354
+ if (next.country !== previous.country || next.e164 !== previous.e164) emit("change", describe(next));
355
+ nextTick(syncFromModel);
356
+ }
357
+ function syncFromModel() {
358
+ if (model.value === state.value.e164) return;
359
+ const previous = state.value;
360
+ state.value = readPhone(model.value, previous.country, allowed);
361
+ if (state.value.country !== previous.country) emit("update:country", state.value.country);
362
+ }
363
+ watch(model, syncFromModel);
364
+ /** The digits to carry over to another country: what was typed, without a dialling code. */
365
+ function carriedDigits() {
366
+ const current = state.value;
367
+ return current.text.trimStart().startsWith("+") ? current.nationalNumber : current.text;
368
+ }
369
+ /** A country chosen from the list, or bound from outside: the digits stay, re-spaced for it. */
370
+ function setCountry(next) {
371
+ if (next === country.value || !allowed(next)) return;
372
+ commit(typePhone(carriedDigits(), next, (candidate) => candidate === next));
373
+ }
374
+ watch(() => props.country, (next) => {
375
+ if (next !== void 0) setCountry(next);
376
+ });
377
+ onMounted(() => {
378
+ if (props.country !== void 0 && props.country !== country.value) emit("update:country", country.value);
379
+ });
380
+ const controlRef = ref(null);
381
+ function onInput(event) {
382
+ if (event.isComposing) return;
383
+ const element = event.target;
384
+ const raw = element.value;
385
+ const before = significantBefore(raw, element.selectionStart ?? raw.length);
386
+ const next = typePhone(raw, country.value, allowed);
387
+ element.value = next.text;
388
+ const caret = caretAfter(next.text, before - next.stripped);
389
+ element.setSelectionRange(caret, caret);
390
+ commit(next);
391
+ }
392
+ const placeholderText = computed(() => {
393
+ if (props.placeholder === false) return void 0;
394
+ return props.placeholder ?? phoneExample(country.value);
395
+ });
396
+ const countryName = (code) => phoneCountryName(code, locale.value);
397
+ /**
398
+ * Suggested countries first, in the order given, then every other one from A to Z in the locale's
399
+ * own order. A country is listed once: a suggested one is not repeated below. The dialling code
400
+ * and the ISO code are keywords, so "+45", "45" and "dk" all find Denmark.
401
+ */
402
+ const options = computed(() => {
403
+ const compare = comparator(locale.value);
404
+ const grouped = preferred.value.length > 0;
405
+ const entry = (code, group) => {
406
+ const dial = phoneCallingCode(code);
407
+ return {
408
+ value: code,
409
+ label: countryName(code),
410
+ meta: `+${dial}`,
411
+ keywords: [
412
+ `+${dial}`,
413
+ dial,
414
+ code
415
+ ],
416
+ group
417
+ };
418
+ };
419
+ const suggested = preferred.value.map((code) => entry(code, grouped ? m.value.phoneSuggested : void 0));
420
+ const rest = offered.value.filter((code) => !preferred.value.includes(code)).map((code) => entry(code, grouped ? m.value.phoneAllCountries : void 0)).sort((a, b) => compare(a.label, b.label));
421
+ return [...suggested, ...rest];
422
+ });
423
+ const indexOfValue = computed(() => new Map(options.value.map((option, index) => [option.value, index])));
424
+ const optionId = (value) => `${controlId.value}-o${indexOfValue.value.get(value) ?? 0}`;
425
+ const query = ref("");
426
+ const fieldRef = ref(null);
427
+ const buttonRef = ref(null);
428
+ const panelComponent = ref(null);
429
+ const panelRef = computed(() => panelComponent.value?.root ?? null);
430
+ const searchRef = computed(() => panelComponent.value?.searchInput ?? null);
431
+ const { sections, listOptions, hasOptions, highlights, renderMore, reveal, resetBatch } = useOptionList({
432
+ options: () => options.value,
433
+ query: () => query.value,
434
+ searchable: () => true,
435
+ controlId: () => controlId.value
436
+ });
437
+ const canOpen = () => !props.disabled && !props.readonly;
438
+ const { isOpen, panelStyle, placement, teleportTo, teleportDisabled, open: openPopover, close: closePopover, onTriggerPointerDown, onTriggerClick } = usePopover({
439
+ trigger: buttonRef,
440
+ content: panelRef,
441
+ anchor: fieldRef,
442
+ matchWidth: true,
443
+ canOpen,
444
+ onOpen: () => {
445
+ listbox.resetTypeahead();
446
+ emit("open");
447
+ },
448
+ onClose: () => {
449
+ listbox.resetTypeahead();
450
+ resetBatch();
451
+ query.value = "";
452
+ emit("close");
453
+ },
454
+ afterOpen: async () => {
455
+ await nextTick();
456
+ searchRef.value?.focus();
457
+ },
458
+ openFromPointer: () => openPanel()
459
+ });
460
+ const listbox = useListbox({
461
+ options: () => listOptions.value,
462
+ isOpen: () => isOpen.value,
463
+ canOpen,
464
+ searchable: () => true,
465
+ optionId,
466
+ open: () => openPanel(),
467
+ close: () => closePopover(),
468
+ select: (option) => choose(option),
469
+ startQuery: (character) => {
470
+ query.value = character;
471
+ },
472
+ escape: () => {
473
+ if (query.value === "") return false;
474
+ query.value = "";
475
+ return true;
476
+ }
477
+ });
478
+ watch(listbox.activeValue, reveal, { flush: "sync" });
479
+ watch(query, () => {
480
+ if (isOpen.value) listbox.activateFrom(void 0);
481
+ });
482
+ function openPanel() {
483
+ openPopover(() => listbox.activateFrom(country.value));
484
+ }
485
+ /** Choosing a country hands the keyboard to the number: that is what is typed next. */
486
+ function choose(option) {
487
+ setCountry(option.value);
488
+ closePopover(false);
489
+ controlRef.value?.focus();
490
+ }
491
+ const selectedValues = computed(() => [country.value]);
492
+ const emptyText = computed(() => query.value.trim() === "" ? m.value.noResults : m.value.phoneNoMatch(query.value.trim()));
493
+ const buttonLabel = computed(() => m.value.phoneCountry(countryName(country.value), `+${callingCode.value}`));
494
+ const FIELD_BOX = `eldra:flex eldra:w-full eldra:min-w-0 eldra:items-stretch eldra:eldra-field-border ${FIELD_RADIUS} eldra:eldra-focus eldra:eldra-focus-proxy eldra:eldra-focus-has-open`;
495
+ const FIELD_HEIGHT = {
496
+ sm: "eldra:control-h-sm",
497
+ md: "eldra:control-h",
498
+ lg: "eldra:control-h-lg"
499
+ };
500
+ function fieldState() {
501
+ if (props.disabled) return DISABLED;
502
+ if (props.readonly) return `${READONLY_FILL} ${showsInvalid.value ? INVALID : "eldra:border-border"}`;
503
+ return `${LIVE_FILL} ${showsInvalid.value ? INVALID : isOpen.value ? OPEN : REST}`;
504
+ }
505
+ const fieldClass = computed(() => [
506
+ FIELD_BOX,
507
+ FIELD_HEIGHT[props.size],
508
+ fieldState(),
509
+ showsInvalid.value && "eldra:eldra-field-invalid",
510
+ props.classes?.field
511
+ ]);
512
+ /** The start corners follow the box's, one border-width in, so the hover fill never pokes out. */
513
+ const buttonClass = computed(() => [
514
+ BUTTON_BASE,
515
+ FIELD_TEXT[props.size],
516
+ props.disabled ? "eldra:cursor-not-allowed" : props.readonly ? "eldra:cursor-default" : BUTTON_LIVE,
517
+ props.classes?.countryButton
518
+ ]);
519
+ const chevronClass = computed(() => [
520
+ "eldra:size-3.5 eldra:shrink-0 eldra:text-muted eldra:transition-transform eldra:duration-base",
521
+ isOpen.value && "eldra:rotate-180",
522
+ props.classes?.chevron
523
+ ]);
524
+ const controlClass = computed(() => [
525
+ "eldra:block eldra:min-w-0 eldra:flex-1 eldra:bg-transparent eldra:px-2.75 eldra:tabular-nums eldra:outline-none eldra:placeholder:text-muted",
526
+ FIELD_TEXT[props.size],
527
+ props.disabled && "eldra:cursor-not-allowed",
528
+ props.classes?.control
529
+ ]);
530
+ /** `control` is the number `<input>`; `country` the one the field is on, whoever chose it. */
531
+ __expose({
532
+ control: controlRef,
533
+ focus: () => controlRef.value?.focus(),
534
+ country
535
+ });
536
+ return (_ctx, _cache) => {
537
+ return openBlock(), createElementBlock("div", {
538
+ "data-eldra-ui": "",
539
+ "data-eldra-scope": unref(eldra).scope,
540
+ "data-part": "root",
541
+ class: normalizeClass([rootClass, _ctx.$attrs.class])
542
+ }, [
543
+ createElementVNode("div", {
544
+ ref_key: "fieldRef",
545
+ ref: fieldRef,
546
+ "data-part": "field",
547
+ class: normalizeClass(fieldClass.value)
548
+ }, [createElementVNode("button", {
549
+ ref_key: "buttonRef",
550
+ ref: buttonRef,
551
+ "data-part": "countryButton",
552
+ type: "button",
553
+ role: "combobox",
554
+ class: normalizeClass(buttonClass.value),
555
+ "aria-haspopup": "listbox",
556
+ "aria-expanded": unref(isOpen) ? "true" : "false",
557
+ "aria-controls": listboxId.value,
558
+ "aria-label": buttonLabel.value,
559
+ "aria-disabled": __props.disabled ? "true" : void 0,
560
+ "aria-readonly": __props.readonly ? "true" : void 0,
561
+ disabled: __props.disabled || void 0,
562
+ onPointerdown: _cache[0] || (_cache[0] = (...args) => unref(onTriggerPointerDown) && unref(onTriggerPointerDown)(...args)),
563
+ onClick: _cache[1] || (_cache[1] = (...args) => unref(onTriggerClick) && unref(onTriggerClick)(...args)),
564
+ onKeydown: _cache[2] || (_cache[2] = (...args) => unref(listbox).onKeydown && unref(listbox).onKeydown(...args))
565
+ }, [
566
+ createElementVNode("span", {
567
+ "data-eldra-slot": unref(eldra).slotHost("flag"),
568
+ class: "eldra:flex eldra:shrink-0"
569
+ }, [renderSlot(_ctx.$slots, "flag", { country: country.value }, () => [createVNode(CountryFlag_default, {
570
+ country: country.value,
571
+ class: normalizeClass(__props.classes?.flag)
572
+ }, null, 8, ["country", "class"])])], 8, _hoisted_3),
573
+ createElementVNode("span", {
574
+ "data-part": "callingCode",
575
+ class: normalizeClass(__props.classes?.callingCode)
576
+ }, "+" + toDisplayString(callingCode.value), 3),
577
+ !__props.readonly ? (openBlock(), createElementBlock("span", {
578
+ key: 0,
579
+ "data-part": "chevron",
580
+ class: normalizeClass(chevronClass.value),
581
+ "aria-hidden": "true"
582
+ }, [..._cache[6] || (_cache[6] = [createElementVNode("svg", {
583
+ class: "eldra:size-3.5",
584
+ viewBox: "0 0 24 24",
585
+ fill: "none",
586
+ stroke: "currentColor",
587
+ "stroke-width": "2",
588
+ "stroke-linecap": "round",
589
+ "stroke-linejoin": "round",
590
+ focusable: "false"
591
+ }, [createElementVNode("path", { d: "M6 9l6 6l6 -6" })], -1)])], 2)) : createCommentVNode("", true)
592
+ ], 42, _hoisted_2), createElementVNode("input", mergeProps({
593
+ ref_key: "controlRef",
594
+ ref: controlRef
595
+ }, {
596
+ ..._ctx.$attrs,
597
+ class: void 0
598
+ }, {
599
+ "data-part": "control",
600
+ type: "tel",
601
+ inputmode: "tel",
602
+ class: controlClass.value,
603
+ id: unref(controlId),
604
+ value: text.value,
605
+ placeholder: placeholderText.value,
606
+ autocomplete: __props.autocomplete,
607
+ required: isRequired.value || void 0,
608
+ readonly: __props.readonly || void 0,
609
+ disabled: __props.disabled || void 0,
610
+ "aria-invalid": isInvalid.value ? "true" : void 0,
611
+ "aria-describedby": describedBy.value,
612
+ onInput,
613
+ onFocus: _cache[3] || (_cache[3] = ($event) => emit("focus", $event)),
614
+ onBlur: _cache[4] || (_cache[4] = ($event) => emit("blur", $event))
615
+ }), null, 16, _hoisted_4)], 2),
616
+ __props.name ? (openBlock(), createElementBlock("input", {
617
+ key: 0,
618
+ "data-part": "native",
619
+ type: "hidden",
620
+ name: __props.name,
621
+ value: unref(model),
622
+ disabled: __props.disabled || void 0
623
+ }, null, 8, _hoisted_5)) : createCommentVNode("", true),
624
+ unref(isOpen) ? (openBlock(), createBlock(Teleport, {
625
+ key: 1,
626
+ to: unref(teleportTo),
627
+ disabled: unref(teleportDisabled)
628
+ }, [createVNode(SelectPanel_default, {
629
+ ref_key: "panelComponent",
630
+ ref: panelComponent,
631
+ "panel-id": panelId.value,
632
+ "listbox-id": listboxId.value,
633
+ sections: unref(sections),
634
+ "has-options": unref(hasOptions),
635
+ highlights: unref(highlights),
636
+ "option-id": optionId,
637
+ "active-value": unref(listbox).activeValue.value,
638
+ "selected-values": selectedValues.value,
639
+ searchable: true,
640
+ query: query.value,
641
+ "search-placeholder": unref(m).phoneSearch,
642
+ "empty-text": emptyText.value,
643
+ "fallback-label": unref(m).phoneCountryList,
644
+ "panel-style": unref(panelStyle),
645
+ placement: unref(placement),
646
+ classes: __props.classes,
647
+ onSearch: _cache[5] || (_cache[5] = ($event) => query.value = $event),
648
+ onSelect: choose,
649
+ onActivate: unref(listbox).setActive,
650
+ onScrollEnd: unref(renderMore),
651
+ onKeydown: unref(listbox).onKeydown
652
+ }, {
653
+ optionContent: withCtx(({ option, match }) => [
654
+ renderSlot(_ctx.$slots, "flag", { country: option.value }, () => [createVNode(CountryFlag_default, {
655
+ country: option.value,
656
+ class: normalizeClass(__props.classes?.flag)
657
+ }, null, 8, ["country", "class"])]),
658
+ createElementVNode("span", {
659
+ "data-part": "optionLabel",
660
+ class: normalizeClass(["eldra:min-w-0 eldra:flex-1", __props.classes?.optionLabel])
661
+ }, [match ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
662
+ createTextVNode(toDisplayString(match.before), 1),
663
+ createElementVNode("span", _hoisted_6, toDisplayString(match.match), 1),
664
+ createTextVNode(toDisplayString(match.after), 1)
665
+ ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createTextVNode(toDisplayString(option.label), 1)], 64))], 2),
666
+ createElementVNode("span", {
667
+ "data-part": "optionMeta",
668
+ class: normalizeClass(["eldra:ms-3 eldra:shrink-0 eldra:text-caption eldra:tabular-nums eldra:text-[color:var(--eldra-select-panel-muted,var(--eldra-color-muted))]", __props.classes?.optionMeta])
669
+ }, toDisplayString(option.meta), 3)
670
+ ]),
671
+ _: 3
672
+ }, 8, [
673
+ "panel-id",
674
+ "listbox-id",
675
+ "sections",
676
+ "has-options",
677
+ "highlights",
678
+ "active-value",
679
+ "selected-values",
680
+ "query",
681
+ "search-placeholder",
682
+ "empty-text",
683
+ "fallback-label",
684
+ "panel-style",
685
+ "placement",
686
+ "classes",
687
+ "onActivate",
688
+ "onScrollEnd",
689
+ "onKeydown"
690
+ ])], 8, ["to", "disabled"])) : createCommentVNode("", true)
691
+ ], 10, _hoisted_1);
692
+ };
693
+ }
694
+ });
695
+ export { parsePhone as a, phoneExample as c, isValidPhone as i, phoneCountryName as n, phoneCallingCode as o, phoneRule as r, phoneCountries as s, PhoneInput_default as t };