@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
@@ -4,8 +4,19 @@ export interface EldraUiResolverOptions {
4
4
  }
5
5
  interface ResolvedComponent {
6
6
  name: string;
7
- from: '@eldrajs/ui';
7
+ from: '@eldrajs/ui' | '@eldrajs/ui/phone' | '@eldrajs/ui/flag';
8
8
  }
9
+ /**
10
+ * The components of `@eldrajs/ui/phone`, which the root entry does not export: that entry needs
11
+ * the optional `libphonenumber-js` peer. Named here as plain strings, so this entry never imports
12
+ * the phone one.
13
+ */
14
+ export declare const phoneComponentNames: readonly ["PhoneInput"];
15
+ /**
16
+ * The components of `@eldrajs/ui/flag`, which the root entry does not export either: its artwork
17
+ * is a chunk the root entry must never reach.
18
+ */
19
+ export declare const flagComponentNames: readonly ["CountryFlag"];
9
20
  /**
10
21
  * Resolver for [`unplugin-vue-components`](https://github.com/unplugin/unplugin-vue-components):
11
22
  *
@@ -20,7 +31,9 @@ interface ResolvedComponent {
20
31
  *
21
32
  * A template can then use `<EldraButton>`, `<EldraSelect>`, and so on, with no explicit import —
22
33
  * the plugin rewrites the tag into `import { Button } from '@eldrajs/ui'` (auto-imported, not
23
- * globally registered) the first time it sees it. `EldraUiResolver` resolves against exactly the
34
+ * globally registered) the first time it sees it. `<EldraPhoneInput>` resolves the same way from
35
+ * `@eldrajs/ui/phone` (`phoneComponentNames`), the entry that needs `libphonenumber-js`, and
36
+ * `<EldraCountryFlag>` from `@eldrajs/ui/flag` (`flagComponentNames`). `EldraUiResolver` resolves against exactly the
24
37
  * names in `componentNames` (`src/index.ts`'s component exports — see
25
38
  * `src/__tests__/componentNames.spec.ts` for the guard that keeps the two in sync); anything else,
26
39
  * including the private library's own `Ui*` names, resolves to `undefined` and is left for another
package/dist/resolver.js CHANGED
@@ -85,6 +85,19 @@ var componentNames = [
85
85
  // src/resolver.ts
86
86
  var componentNameSet = new Set(componentNames);
87
87
  /**
88
+ * The components of `@eldrajs/ui/phone`, which the root entry does not export: that entry needs
89
+ * the optional `libphonenumber-js` peer. Named here as plain strings, so this entry never imports
90
+ * the phone one.
91
+ */
92
+ var phoneComponentNames = ["PhoneInput"];
93
+ var phoneComponentNameSet = new Set(phoneComponentNames);
94
+ /**
95
+ * The components of `@eldrajs/ui/flag`, which the root entry does not export either: its artwork
96
+ * is a chunk the root entry must never reach.
97
+ */
98
+ var flagComponentNames = ["CountryFlag"];
99
+ var flagComponentNameSet = new Set(flagComponentNames);
100
+ /**
88
101
  * Resolver for [`unplugin-vue-components`](https://github.com/unplugin/unplugin-vue-components):
89
102
  *
90
103
  * ```ts
@@ -98,7 +111,9 @@ var componentNameSet = new Set(componentNames);
98
111
  *
99
112
  * A template can then use `<EldraButton>`, `<EldraSelect>`, and so on, with no explicit import —
100
113
  * the plugin rewrites the tag into `import { Button } from '@eldrajs/ui'` (auto-imported, not
101
- * globally registered) the first time it sees it. `EldraUiResolver` resolves against exactly the
114
+ * globally registered) the first time it sees it. `<EldraPhoneInput>` resolves the same way from
115
+ * `@eldrajs/ui/phone` (`phoneComponentNames`), the entry that needs `libphonenumber-js`, and
116
+ * `<EldraCountryFlag>` from `@eldrajs/ui/flag` (`flagComponentNames`). `EldraUiResolver` resolves against exactly the
102
117
  * names in `componentNames` (`src/index.ts`'s component exports — see
103
118
  * `src/__tests__/componentNames.spec.ts` for the guard that keeps the two in sync); anything else,
104
119
  * including the private library's own `Ui*` names, resolves to `undefined` and is left for another
@@ -115,12 +130,19 @@ function EldraUiResolver(options = {}) {
115
130
  resolve(name) {
116
131
  if (!name.startsWith(prefix)) return void 0;
117
132
  const componentName = name.slice(prefix.length);
118
- if (!componentNameSet.has(componentName)) return void 0;
119
- return {
133
+ if (componentNameSet.has(componentName)) return {
120
134
  name: componentName,
121
135
  from: "@eldrajs/ui"
122
136
  };
137
+ if (phoneComponentNameSet.has(componentName)) return {
138
+ name: componentName,
139
+ from: "@eldrajs/ui/phone"
140
+ };
141
+ if (flagComponentNameSet.has(componentName)) return {
142
+ name: componentName,
143
+ from: "@eldrajs/ui/flag"
144
+ };
123
145
  }
124
146
  };
125
147
  }
126
- export { EldraUiResolver, componentNames };
148
+ export { EldraUiResolver, componentNames, flagComponentNames, phoneComponentNames };
package/dist/style.css CHANGED
@@ -1119,6 +1119,10 @@
1119
1119
  height: .625rem;
1120
1120
  }
1121
1121
 
1122
+ .eldra\:h-3\.5 {
1123
+ height: .875rem;
1124
+ }
1125
+
1122
1126
  .eldra\:h-4\.5 {
1123
1127
  height: 1.125rem;
1124
1128
  }
@@ -1354,6 +1358,10 @@
1354
1358
  width: 1.125rem;
1355
1359
  }
1356
1360
 
1361
+ .eldra\:w-5 {
1362
+ width: var(--eldra-space-5);
1363
+ }
1364
+
1357
1365
  .eldra\:w-6 {
1358
1366
  width: var(--eldra-space-6);
1359
1367
  }
@@ -1990,6 +1998,12 @@
1990
1998
  scroll-behavior: smooth;
1991
1999
  }
1992
2000
 
2001
+ .eldra\:eldra-phone-flag {
2002
+ border-radius: var(--eldra-phone-flag-radius, 2px);
2003
+ box-shadow: 0 0 0 1px var(--eldra-phone-flag-border, var(--eldra-color-border));
2004
+ background-color: var(--eldra-phone-flag-fill, var(--eldra-color-surface-strong));
2005
+ }
2006
+
1993
2007
  .eldra\:eldra-link-radius {
1994
2008
  border-radius: var(--eldra-link-radius, 2px);
1995
2009
  }
@@ -2062,6 +2076,11 @@
2062
2076
  border-radius: var(--eldra-radius-xl);
2063
2077
  }
2064
2078
 
2079
+ .eldra\:rounded-s-\[calc\(var\(--eldra-input-radius\,var\(--eldra-radius-md\)\)-var\(--eldra-field-border-width\,1px\)\)\] {
2080
+ border-start-start-radius: calc(var(--eldra-input-radius, var(--eldra-radius-md)) - var(--eldra-field-border-width, 1px));
2081
+ border-end-start-radius: calc(var(--eldra-input-radius, var(--eldra-radius-md)) - var(--eldra-field-border-width, 1px));
2082
+ }
2083
+
2065
2084
  .eldra\:rounded-t-full {
2066
2085
  border-top-left-radius: var(--eldra-radius-full);
2067
2086
  border-top-right-radius: var(--eldra-radius-full);
@@ -2153,6 +2172,11 @@
2153
2172
  border-inline-start-width: 1px;
2154
2173
  }
2155
2174
 
2175
+ .eldra\:border-e {
2176
+ border-inline-end-style: var(--tw-border-style);
2177
+ border-inline-end-width: 1px;
2178
+ }
2179
+
2156
2180
  .eldra\:border-t {
2157
2181
  border-top-style: var(--tw-border-style);
2158
2182
  border-top-width: 1px;
@@ -2683,6 +2707,10 @@
2683
2707
  padding-inline-end: var(--eldra-space-1);
2684
2708
  }
2685
2709
 
2710
+ .eldra\:pe-2 {
2711
+ padding-inline-end: var(--eldra-space-2);
2712
+ }
2713
+
2686
2714
  .eldra\:pe-2\.5 {
2687
2715
  padding-inline-end: .625rem;
2688
2716
  }
@@ -3641,6 +3669,28 @@
3641
3669
  }
3642
3670
  }
3643
3671
 
3672
+ .eldra\:eldra-focus-has-open:has([aria-expanded="true"]) {
3673
+ --eldra-focus-alpha: 1;
3674
+ }
3675
+
3676
+ @supports not (color: color-mix(in srgb, red, red)) {
3677
+ .eldra\:eldra-focus-has-open:has([aria-expanded="true"]) {
3678
+ --tw-ring-offset-shadow: 0 0 0 var(--eldra-focus-offset) var(--eldra-color-focus-inner),
3679
+ 0 0 0 var(--eldra-focus-offset) var(--eldra-color-focus-inner),
3680
+ 0 0 0 var(--eldra-focus-offset) var(--eldra-color-focus-inner);
3681
+ --tw-ring-shadow: 0 0 0 calc(var(--eldra-focus-offset) + var(--eldra-focus-width))
3682
+ var(--eldra-color-focus);
3683
+ }
3684
+ }
3685
+
3686
+ @media (forced-colors: active) {
3687
+ .eldra\:eldra-focus-has-open:has([aria-expanded="true"]) {
3688
+ outline-width: var(--eldra-focus-width);
3689
+ outline-offset: var(--eldra-focus-offset);
3690
+ outline-color: highlight;
3691
+ }
3692
+ }
3693
+
3644
3694
  .eldra\:eldra-focus-open[aria-expanded="true"] {
3645
3695
  --eldra-focus-alpha: 1;
3646
3696
  }
@@ -4055,6 +4105,10 @@
4055
4105
  display: none;
4056
4106
  }
4057
4107
 
4108
+ .eldra\:focus-within\:border-text:focus-within {
4109
+ border-color: var(--eldra-color-text);
4110
+ }
4111
+
4058
4112
  @media (hover: hover) {
4059
4113
  .eldra\:hover\:border-danger:hover {
4060
4114
  border-color: var(--eldra-color-danger);
@@ -4219,6 +4273,16 @@
4219
4273
  outline-style: none;
4220
4274
  }
4221
4275
 
4276
+ .eldra\:focus-visible\:bg-\[color-mix\(in_oklab\,var\(--eldra-color-text\)\,transparent_94\%\)\]:focus-visible {
4277
+ background-color: var(--eldra-color-text);
4278
+ }
4279
+
4280
+ @supports (color: color-mix(in lab, red, red)) {
4281
+ .eldra\:focus-visible\:bg-\[color-mix\(in_oklab\,var\(--eldra-color-text\)\,transparent_94\%\)\]:focus-visible {
4282
+ background-color: color-mix(in oklab,var(--eldra-color-text),transparent 94%);
4283
+ }
4284
+ }
4285
+
4222
4286
  .eldra\:active\:scale-\[0\.98\]:active {
4223
4287
  scale: .98;
4224
4288
  }
@@ -0,0 +1,32 @@
1
+ import { inject, provide, useSlots } from "vue";
2
+ // src/composables/useEldraScope.ts
3
+ /** The injection key `provideEldraScope` provides under. */
4
+ var ELDRA_SCOPE_KEY = Symbol("eldra-scope");
5
+ /**
6
+ * Names a theming scope for every component of this package rendered below the caller (see the
7
+ * README, "Theming a subtree"). Call it in `setup()` of a wrapper or an app root.
8
+ *
9
+ * Each component then renders `data-eldra-scope="<name>"` on its root and on every part it
10
+ * teleports (panels, dialogs, toasts). The name is free; the consumer's own variable overrides
11
+ * target it (`[data-eldra-scope='studio'] { --eldra-color-primary: … }`). Without a provider the
12
+ * attribute is not rendered, so the output is unchanged.
13
+ */
14
+ function provideEldraScope(name = "default") {
15
+ provide(ELDRA_SCOPE_KEY, name || "default");
16
+ }
17
+ /**
18
+ * Internal: the theming hooks a component of this package binds. `scope` goes on every root,
19
+ * teleported root and kit-owned element sitting directly in a slot host, so a scope's variables
20
+ * reach it; it is `undefined` without a provider. `slotHost(...names)` is `data-eldra-slot`, on
21
+ * the element holding those slots, a hook for consumer CSS. It renders whenever one of the slots
22
+ * has content, provider or not, and never for a fallback, which is the kit's own markup.
23
+ */
24
+ function useEldraScope() {
25
+ const scope = inject(ELDRA_SCOPE_KEY, void 0);
26
+ const slots = useSlots();
27
+ return {
28
+ scope,
29
+ slotHost: (...names) => names.some((name) => slots[name] !== void 0) ? "" : void 0
30
+ };
31
+ }
32
+ export { provideEldraScope as n, useEldraScope as r, ELDRA_SCOPE_KEY as t };
@@ -0,0 +1,273 @@
1
+ import { G as FIELD_KEY, Q as useUiId } from "./usePopover-ECHpsSRF.js";
2
+ import { computed, inject, onMounted, onScopeDispose, shallowRef, watch } from "vue";
3
+ import { FormContextKey, useField } from "vee-validate";
4
+ // src/vee-validate/context.ts
5
+ /**
6
+ * The server's field errors, keyed by the path a `Field*` validates under (its `path`, or its
7
+ * `name` when there is none).
8
+ *
9
+ * `Form` provides it from its `apiErrors` prop and applies it to the form with vee-validate's own
10
+ * `setErrors`, so a 422 from the shop's API lands on the field it belongs to rather than in a
11
+ * banner above the form. Every `Field*` injects it and removes **its own** entry the moment its
12
+ * value changes — a server error is a statement about the value that was sent, so it stops being
13
+ * true as soon as the customer edits it, and nothing else would reliably clear it (a rule that
14
+ * already passes has no new message to overwrite it with).
15
+ *
16
+ * A server error on a *different* field stays on screen while this one is edited: each `Field*`
17
+ * holds the message it shows and changes it only at its own moments (its blur, a submit, its own
18
+ * edit of a server error — see `useFieldControl`). Underneath, vee-validate may already have
19
+ * dropped it: with a form-level `validationSchema`, validating one field revalidates every field
20
+ * that has been validated before (`validated-only`), and a field that now passes has its manually
21
+ * set error replaced by that pass. So the entry is gone for good at that field's next blur or the
22
+ * next submit; send the current map with each response rather than treating one as sticky.
23
+ *
24
+ * It is a plain `Ref`, so a consumer can provide one itself and drive server errors from outside a
25
+ * `Form`:
26
+ *
27
+ * ```ts
28
+ * import { API_ERRORS_KEY } from '@eldrajs/ui/vee-validate';
29
+ * provide(API_ERRORS_KEY, ref({ email: 'That address is already subscribed.' }));
30
+ * ```
31
+ */
32
+ var API_ERRORS_KEY = Symbol("eldra-ui:api-errors");
33
+ /** The key a `Form` provides its {@link FieldAnchorRegistry} on. Internal to this entry. */
34
+ var FIELD_ANCHORS_KEY = Symbol("eldra-ui:field-anchors");
35
+ /** The key a `Form` provides its {@link FieldMessageRegistry} on. Internal to this entry. */
36
+ var FIELD_MESSAGES_KEY = Symbol("eldra-ui:field-messages");
37
+ // src/vee-validate/useFieldControl.ts
38
+ /** The three props that decide when a field validates. Never forwarded to the wrapped control. */
39
+ var FIELD_VALIDATION_PROPS = [
40
+ "validateOnMount",
41
+ "validateOnBlur",
42
+ "validateOnValueUpdate"
43
+ ];
44
+ /**
45
+ * Their defaults for a **typed** control — `FieldInput`, `FieldTextarea`, `FieldCurrencyInput`,
46
+ * `FieldUnitInput`, `FieldSearchBar` — handed to `withDefaults(defineProps<…>(), …)`. A value
47
+ * there is built up one keystroke at a time, so validating each change would judge a half-typed
48
+ * value; the field validates when it is left instead.
49
+ *
50
+ * They have to be real defaults: Vue casts an absent boolean prop to `false`, never `undefined`,
51
+ * so without one `validateOnBlur` could not default to `true`.
52
+ */
53
+ var FIELD_VALIDATION_DEFAULTS = {
54
+ validateOnMount: false,
55
+ validateOnBlur: true,
56
+ validateOnValueUpdate: false
57
+ };
58
+ /**
59
+ * Their defaults for a **choice** control — `FieldCheckbox`, `FieldCheckboxGroup`,
60
+ * `FieldRadioGroup`, `FieldSwitch`, `FieldSelect`, `FieldMultiSelect`, `FieldVariantPicker`,
61
+ * `FieldQuantityStepper`. One click or selection is the whole value there — there is no typing in
62
+ * between, and often no blur afterwards — so a box that only validated on blur would go on saying
63
+ * "required" after it had been ticked. These validate on each change as well as on blur.
64
+ *
65
+ * `FieldQuantityStepper` belongs here although it has a text field: a `QuantityStepper` writes its
66
+ * value only when a typed number is committed (on blur or `Enter`) or a button is pressed, never
67
+ * per keystroke, so every change it reports is a complete quantity.
68
+ */
69
+ var FIELD_CHOICE_VALIDATION_DEFAULTS = {
70
+ validateOnMount: false,
71
+ validateOnBlur: true,
72
+ validateOnValueUpdate: true
73
+ };
74
+ /** The props a `Field*` keeps for itself and never forwards to the component it wraps. */
75
+ var FIELD_ONLY = [
76
+ "path",
77
+ "rules",
78
+ "label",
79
+ "id",
80
+ ...FIELD_VALIDATION_PROPS
81
+ ];
82
+ /**
83
+ * The whole of what a `Field*` does, minus the one component it renders.
84
+ *
85
+ * Each `Field*` is a thin SFC over this: `useField(name, rules, { label })` for the value and the
86
+ * validation, the message the field **shows**, the `id` the form's error summary links to, and the
87
+ * server error that stops being true as soon as the value changes. Keeping it here is what makes
88
+ * the thirteen components agree on all of that rather than thirteen files drifting apart.
89
+ *
90
+ * **When a field validates, and when its message changes.** The spec's rule (Form layout →
91
+ * Behaviour & motion) is "Validate on submit, then on blur for fields that were invalid after the
92
+ * first submit"; three props per field say which moments apply, and the message on screen changes
93
+ * at those moments and at no other:
94
+ *
95
+ * - **submit**, always: the form validates every field, and each one then shows its result;
96
+ * - **blur**, unless `validateOnBlur` is `false` (default `true`): the field is validated and
97
+ * shows its result. A blur always marks the field touched;
98
+ * - **a value change**, only with `validateOnValueUpdate`: the message follows every change once
99
+ * the field has been touched or the form submitted. Default `false` for a typed control, `true`
100
+ * for a choice control (see the two defaults objects above);
101
+ * - **mount**, only with `validateOnMount` (default `false`): validated and shown at once.
102
+ *
103
+ * So in a typed control, typing changes nothing the customer sees: no message appears, and one
104
+ * already showing stays until the next blur or submit. A choice control answers a click at once.
105
+ *
106
+ * **Why the shown message is held here** rather than read from vee-validate's `errorMessage`. That
107
+ * value can move at moments that are not this field's: with a `validationSchema` on the form,
108
+ * validating one field revalidates every field already validated (`validated-only`), so another
109
+ * field's blur would otherwise clear or change this field's message while it is being typed in.
110
+ * `shown` is a copy taken only at the moments listed above, which is what makes the props true in
111
+ * both setups, per-field `rules` and a form-level schema alike.
112
+ */
113
+ function useFieldControl(props, options) {
114
+ /**
115
+ * Where the value lives. `name` for every control whose `name` is the native form field name;
116
+ * `path` for the one whose is not — a `VariantPicker`'s `name` is the visible option name, so it
117
+ * would otherwise be both the legend and the key in `values`, and one of the two would be wrong.
118
+ */
119
+ const path = computed(() => props.path ?? props.name);
120
+ const rules = computed(() => props.rules);
121
+ /**
122
+ * `validateOnValueUpdate` is vee-validate's own option and is read once, here. `validateOnMount`
123
+ * is not handed over: the mount-time validation is run below instead, so its result can be shown
124
+ * when it settles (vee-validate's own run reports to nobody).
125
+ */
126
+ const { value, errorMessage, handleBlur, meta, validate } = useField(path, rules, {
127
+ label: () => props.label,
128
+ initialValue: options.initialValue,
129
+ validateOnValueUpdate: props.validateOnValueUpdate === true
130
+ });
131
+ const model = computed({
132
+ get: () => value.value ?? options.empty,
133
+ set: (next) => {
134
+ value.value = next;
135
+ }
136
+ });
137
+ /**
138
+ * The form above, for `submitCount`. Injected rather than taken from `useFormContext()` so a
139
+ * `Field*` used on its own — a single validated search box, say — works with no form at all.
140
+ */
141
+ const form = inject(FormContextKey, null);
142
+ const submitted = computed(() => (form?.submitCount.value ?? 0) > 0);
143
+ const apiErrors = inject(API_ERRORS_KEY, null);
144
+ const hasApiError = computed(() => apiErrors !== null && apiErrors.value[path.value] !== void 0);
145
+ /** The message on screen. See the doc comment above for the only moments it changes. */
146
+ const shown = shallowRef(void 0);
147
+ const messages = inject(FIELD_MESSAGES_KEY, null);
148
+ function show(message) {
149
+ shown.value = message;
150
+ messages?.report(path.value, message);
151
+ }
152
+ /** Take the field's current validation result as the message to show. */
153
+ function reveal() {
154
+ show(errorMessage.value);
155
+ }
156
+ /** Whether a live (`validateOnValueUpdate`) field has earned a message yet. */
157
+ const earned = computed(() => meta.touched || submitted.value);
158
+ watch([
159
+ errorMessage,
160
+ earned,
161
+ hasApiError
162
+ ], ([message, isEarned, isApi], [, , wasApi]) => {
163
+ /**
164
+ * A server error is never held back: it is the answer to a submit the customer has already
165
+ * made, so there is nothing left to wait for — which also covers a form rendered with errors
166
+ * from a round trip that happened before this page existed.
167
+ */
168
+ if (isApi) {
169
+ show(message);
170
+ return;
171
+ }
172
+ /** The server error went (the field was edited, or a new response left it out). */
173
+ if (wasApi) {
174
+ show(props.validateOnValueUpdate && isEarned ? message : void 0);
175
+ return;
176
+ }
177
+ if (props.validateOnValueUpdate && isEarned) {
178
+ show(message);
179
+ return;
180
+ }
181
+ /** A reset form: nothing touched, nothing submitted, nothing wrong — so nothing to show. */
182
+ if (message === void 0 && !isEarned && !props.validateOnMount) show(void 0);
183
+ });
184
+ /**
185
+ * Submit. Inside a `Form` the form says when its validation has finished (`settled`). Inside
186
+ * another vee-validate form there is no such signal, so the field validates itself when
187
+ * `submitCount` rises and shows that result.
188
+ */
189
+ if (messages !== null) watch(messages.settled, reveal);
190
+ else if (form !== null) watch(() => form.submitCount.value, (count) => {
191
+ if (count > 0) validate().then(reveal);
192
+ });
193
+ onMounted(() => {
194
+ if (props.validateOnMount) validate().then(reveal);
195
+ });
196
+ const error = computed(() => shown.value);
197
+ const invalid = computed(() => error.value !== void 0);
198
+ const wrapper = inject(FIELD_KEY, null);
199
+ const ownError = computed(() => wrapper === null ? error.value : void 0);
200
+ /**
201
+ * The id. A `FieldWrapper` already owns one and has tied its `<label for>` to it, so nothing is
202
+ * forwarded there — handing a `Checkbox` or a `Switch` an explicit `id` is what tells it the
203
+ * wrapper is *not* naming it, and it would draw a second label. Standing on its own, the field
204
+ * generates one so the error summary has something to link to.
205
+ */
206
+ const ownId = useUiId("field");
207
+ const id = computed(() => props.id ?? (wrapper === null && options.hasIdProp !== false ? ownId.value : void 0));
208
+ const anchorId = computed(() => props.id ?? wrapper?.value.id ?? (options.hasIdProp !== false ? ownId.value : void 0));
209
+ const anchors = inject(FIELD_ANCHORS_KEY, null);
210
+ if (anchors !== null) {
211
+ watch([path, anchorId], ([current, target], previous) => {
212
+ const previousPath = previous?.[0];
213
+ if (previousPath !== void 0 && previousPath !== current) anchors.unregister(previousPath);
214
+ anchors.register(current, target);
215
+ }, { immediate: true });
216
+ onScopeDispose(() => anchors.unregister(path.value));
217
+ }
218
+ if (messages !== null) {
219
+ watch(path, (current, previous) => {
220
+ if (previous !== void 0 && previous !== current) messages.forget(previous);
221
+ messages.report(current, shown.value);
222
+ }, { immediate: true });
223
+ onScopeDispose(() => messages.forget(path.value));
224
+ }
225
+ /**
226
+ * A server error is a statement about the value that was sent, so it stops being true the moment
227
+ * the customer edits the field — and nothing else would clear it, because a rule that already
228
+ * passes produces no new message to overwrite it with. Dropping the entry is what tells the
229
+ * `Form` to unset it (see `context.ts`), and the watcher above takes it off the screen.
230
+ */
231
+ if (apiErrors !== null) watch(value, () => {
232
+ if (!(path.value in apiErrors.value)) return;
233
+ const next = { ...apiErrors.value };
234
+ delete next[path.value];
235
+ apiErrors.value = next;
236
+ });
237
+ /**
238
+ * A blur always marks the field touched (`handleBlur`, told not to validate), and validates it
239
+ * unless `validateOnBlur` is `false`. The message changes when that validation has settled.
240
+ */
241
+ function onBlur(event) {
242
+ handleBlur(event, false);
243
+ if (props.validateOnBlur !== false) validate().then(reveal);
244
+ }
245
+ return {
246
+ model,
247
+ error,
248
+ invalid,
249
+ ownError,
250
+ id,
251
+ onBlur
252
+ };
253
+ }
254
+ /**
255
+ * Everything the `Field*` was given, minus what it keeps for itself — the props it forwards to the
256
+ * agnostic component underneath, typed as exactly that `Omit`.
257
+ *
258
+ * Built by walking the props object rather than by destructuring, so a prop added to any of the
259
+ * eleven components is forwarded the day it is added and nothing here has to be told about it.
260
+ * `undefined` values are forwarded too, which is exactly right: Vue applies a component's own
261
+ * `withDefaults` value for a prop that is `undefined`, so an unset prop still lands on its default.
262
+ */
263
+ function useControlProps(props, omit) {
264
+ return computed(() => {
265
+ const forwarded = {};
266
+ for (const [key, value] of Object.entries(props)) {
267
+ if (omit.includes(key)) continue;
268
+ forwarded[key] = value;
269
+ }
270
+ return forwarded;
271
+ });
272
+ }
273
+ export { useControlProps as a, FIELD_ANCHORS_KEY as c, FIELD_VALIDATION_PROPS as i, FIELD_MESSAGES_KEY as l, FIELD_ONLY as n, useFieldControl as o, FIELD_VALIDATION_DEFAULTS as r, API_ERRORS_KEY as s, FIELD_CHOICE_VALIDATION_DEFAULTS as t };
@@ -105,6 +105,8 @@ var enUS = {
105
105
  noneSelected: "None selected",
106
106
  /** Closes a `MultiSelect`'s popover. It commits nothing: every toggle already applied. */
107
107
  done: "Done",
108
+ /** A `MultiSelect` footer's button that selects every option shown (`selectAll`). */
109
+ selectAll: "Select all",
108
110
  /** The accessible name of a `QuantityStepper`'s minus button. */
109
111
  decrease: "Decrease",
110
112
  /** The accessible name of a `QuantityStepper`'s plus button. */
@@ -548,7 +550,26 @@ var enUS = {
548
550
  */
549
551
  stepCompleted: "completed",
550
552
  /** `StepIndicator`: the same, for a step after the current one. */
551
- stepNotStarted: "not started"
553
+ stepNotStarted: "not started",
554
+ /**
555
+ * `PhoneInput` (`@eldrajs/ui/phone`): the country button's accessible name, the chosen country
556
+ * and its dialling code ("Country: Iceland, +354").
557
+ */
558
+ phoneCountry: (name, code) => `Country: ${name}, ${code}`,
559
+ /** `PhoneInput`: the country list's accessible name. */
560
+ phoneCountryList: "Country",
561
+ /** `PhoneInput`: the search field over the country list, its placeholder and its name. */
562
+ phoneSearch: "Search country or code",
563
+ /** `PhoneInput`: the heading over the `preferredCountries`. */
564
+ phoneSuggested: "Suggested",
565
+ /** `PhoneInput`: the heading over every other country. */
566
+ phoneAllCountries: "All countries",
567
+ /** `PhoneInput`: the country list's empty state while a search is showing. */
568
+ phoneNoMatch: (query) => `No country matches “${query}”.`,
569
+ /** `phoneRule`: the number is not one the chosen country has. `country` is its localised name. */
570
+ phoneInvalid: (country) => `Enter a valid phone number for ${country}.`,
571
+ /** `phoneRule`: the same, when no country is known for the number. */
572
+ phoneInvalidNumber: "Enter a valid phone number."
552
573
  };
553
574
  // src/composables/useMessages.ts
554
575
  /**