@eldrajs/ui 0.2.8 → 0.2.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 (85) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +259 -87
  3. package/dist/{VariantPicker-CjWUVhlm.js → VariantPicker-Da41_oGA.js} +2244 -1399
  4. package/dist/componentNames.d.ts +1 -1
  5. package/dist/components/button/Button.vue.d.ts +3 -0
  6. package/dist/components/button/types.d.ts +32 -3
  7. package/dist/components/card/ContentCard.vue.d.ts +1 -1
  8. package/dist/components/checkbox/Checkbox.vue.d.ts +2 -0
  9. package/dist/components/checkbox/types.d.ts +12 -1
  10. package/dist/components/chip/Chip.vue.d.ts +4 -3
  11. package/dist/components/dialog/Dialog.vue.d.ts +12 -7
  12. package/dist/components/dialog/types.d.ts +11 -2
  13. package/dist/components/drawer/Drawer.vue.d.ts +1 -0
  14. package/dist/components/field-wrapper/FieldWrapper.vue.d.ts +3 -0
  15. package/dist/components/field-wrapper/RequiredMark.vue.d.ts +15 -0
  16. package/dist/components/field-wrapper/context.d.ts +8 -0
  17. package/dist/components/field-wrapper/types.d.ts +12 -4
  18. package/dist/components/filter-panel/FilterGroup.vue.d.ts +1 -0
  19. package/dist/components/filter-panel/FilterPanel.vue.d.ts +3 -2
  20. package/dist/components/filter-panel/facets/ColourFacet.vue.d.ts +1 -0
  21. package/dist/components/filter-panel/facets/ListFacet.vue.d.ts +1 -0
  22. package/dist/components/filter-panel/facets/RangeFacet.vue.d.ts +2 -1
  23. package/dist/components/filter-panel/facets/SizeFacet.vue.d.ts +1 -0
  24. package/dist/components/filter-panel/facets/ToggleFacet.vue.d.ts +1 -0
  25. package/dist/components/input/Input.vue.d.ts +7 -2
  26. package/dist/components/input/classes.d.ts +9 -0
  27. package/dist/components/input/reassertValue.d.ts +13 -0
  28. package/dist/components/input/types.d.ts +14 -5
  29. package/dist/components/input/useAdornmentRoom.d.ts +15 -0
  30. package/dist/components/lightbox/Lightbox.vue.d.ts +1 -0
  31. package/dist/components/nav-menu/NavMenu.vue.d.ts +1 -0
  32. package/dist/components/pagination/Pagination.vue.d.ts +154 -0
  33. package/dist/components/pagination/types.d.ts +31 -0
  34. package/dist/components/popover/Popover.vue.d.ts +28 -1
  35. package/dist/components/popover/types.d.ts +57 -3
  36. package/dist/components/product-card/ProductCard.vue.d.ts +1 -1
  37. package/dist/components/radio/Radio.vue.d.ts +33 -0
  38. package/dist/components/radio/RadioGroup.vue.d.ts +4 -0
  39. package/dist/components/radio/recipes.d.ts +37 -0
  40. package/dist/components/radio/types.d.ts +64 -3
  41. package/dist/components/range-slider/RangeSlider.vue.d.ts +1 -0
  42. package/dist/components/search-bar/SearchBar.vue.d.ts +1 -0
  43. package/dist/components/search-modal/SearchModal.vue.d.ts +1 -0
  44. package/dist/components/select/MultiSelect.vue.d.ts +48 -1
  45. package/dist/components/select/Select.vue.d.ts +20 -0
  46. package/dist/components/select/SelectPanel.vue.d.ts +23 -0
  47. package/dist/components/select/SelectTags.vue.d.ts +50 -0
  48. package/dist/components/select/openRegistry.d.ts +14 -4
  49. package/dist/components/select/panelParts.d.ts +28 -2
  50. package/dist/components/select/types.d.ts +45 -7
  51. package/dist/components/select/useOptionList.d.ts +31 -4
  52. package/dist/components/select/usePopover.d.ts +36 -39
  53. package/dist/components/select/useSummaryFit.d.ts +21 -0
  54. package/dist/components/select/useTagRows.d.ts +17 -0
  55. package/dist/components/site-form/SiteForm.vue.d.ts +2 -1
  56. package/dist/components/switch/Switch.vue.d.ts +15 -8
  57. package/dist/components/switch/types.d.ts +25 -1
  58. package/dist/components/tabs/Tab.vue.d.ts +1 -0
  59. package/dist/components/tabs/context.d.ts +6 -2
  60. package/dist/components/tabs/types.d.ts +9 -0
  61. package/dist/components/textarea/Textarea.vue.d.ts +21 -1
  62. package/dist/components/textarea/types.d.ts +11 -2
  63. package/dist/components/toast/Toast.vue.d.ts +2 -0
  64. package/dist/components/toast/Toaster.vue.d.ts +7 -1
  65. package/dist/components/toast/types.d.ts +43 -2
  66. package/dist/components.css +312 -13
  67. package/dist/composables/useDialog.d.ts +7 -3
  68. package/dist/composables/useEldraScope.d.ts +26 -0
  69. package/dist/composables/useFloating.d.ts +21 -8
  70. package/dist/composables/useOverlay.d.ts +10 -5
  71. package/dist/composables/useToast.d.ts +3 -0
  72. package/dist/index.d.ts +7 -4
  73. package/dist/index.js +1296 -405
  74. package/dist/messages/en-US.d.ts +2 -0
  75. package/dist/messages/is-IS.js +1 -0
  76. package/dist/resolver.js +1 -0
  77. package/dist/scoped.css +4623 -0
  78. package/dist/style.css +312 -13
  79. package/dist/tailwind.css +43 -12
  80. package/dist/useMessages-B5nzZghs.js +592 -0
  81. package/dist/vee-validate.js +42 -6
  82. package/dist/vue-i18n/index.d.ts +50 -0
  83. package/dist/vue-i18n/shapes.d.ts +40 -0
  84. package/dist/vue-i18n.js +289 -0
  85. package/package.json +16 -3
@@ -1,4 +1,5 @@
1
- import { O as CurrencyInput_default, _t as useMessages, b as focusInvalid, d as MultiSelect_default, i as SearchBar_default, it as CheckboxGroup_default, k as UnitInput_default, l as RadioGroup_default, n as Textarea_default, ot as Checkbox_default, r as Select_default, st as FIELD_KEY, t as VariantPicker_default, u as QuantityStepper_default, w as Input_default, x as Switch_default, xt as useUiId, y as FormLayout_default } from "./VariantPicker-CjWUVhlm.js";
1
+ import { D as FormLayout_default, Dt as useEldraScope, F as CurrencyInput_default, I as UnitInput_default, O as focusInvalid, _ as QuantityStepper_default, dt as CheckboxGroup_default, ft as Checkbox_default, gt as FIELD_KEY, i as SearchBar_default, j as Input_default, k as Switch_default, kt as useUiId, l as RadioGroup_default, n as Textarea_default, r as Select_default, t as VariantPicker_default, v as MultiSelect_default } from "./VariantPicker-Da41_oGA.js";
2
+ import { r as useMessages } from "./useMessages-B5nzZghs.js";
2
3
  import { Fragment, computed, createBlock, createElementBlock, createElementVNode, createSlots, createTextVNode, defineComponent, guardReactiveProps, inject, isRef, mergeProps, nextTick, normalizeClass, normalizeProps, onMounted, onScopeDispose, openBlock, provide, ref, renderList, renderSlot, toDisplayString, unref, watch, withCtx } from "vue";
3
4
  import { FormContextKey, useField, useForm } from "vee-validate";
4
5
  // src/vee-validate/context.ts
@@ -148,7 +149,9 @@ function useControlProps(props, omit) {
148
149
  });
149
150
  }
150
151
  // src/vee-validate/Form.vue?vue&type=script&setup=true&lang.ts
151
- var _hoisted_1 = ["href"];
152
+ var _hoisted_1 = ["data-eldra-scope"];
153
+ var _hoisted_2 = ["data-eldra-scope"];
154
+ var _hoisted_3 = ["href"];
152
155
  var SUMMARY_TITLE = "font-semibold";
153
156
  var SUMMARY_LIST = "mt-1 list-disc ps-4";
154
157
  var SUMMARY_LINK = "underline";
@@ -173,6 +176,16 @@ var Form_default = /* @__PURE__ */ defineComponent({
173
176
  },
174
177
  emits: ["submit", "invalid"],
175
178
  setup(__props, { expose: __expose, emit: __emit }) {
179
+ const eldra = useEldraScope();
180
+ /**
181
+ * `FormLayout` with a vee-validate form behind it.
182
+ *
183
+ * It renders a `FormLayout` and nothing else — every one of its props passes straight through — so
184
+ * the layout, the heading, the actions row, the container-query two-column grid and the polite
185
+ * status region are the same ones the agnostic component ships. What this adds is the form itself:
186
+ * `useForm`, the submit that only reaches the consumer with valid values, the error summary the
187
+ * spec asks a long form for, and the place a server's field errors attach to.
188
+ */
176
189
  const props = __props;
177
190
  const emit = __emit;
178
191
  const m = useMessages();
@@ -353,13 +366,19 @@ var Form_default = /* @__PURE__ */ defineComponent({
353
366
  _: 2
354
367
  }, [showSummary.value ? {
355
368
  name: "errorSummary",
356
- fn: withCtx(() => [renderSlot(_ctx.$slots, "errorSummary", normalizeProps(guardReactiveProps(slotProps.value)), () => [createElementVNode("p", { class: normalizeClass(SUMMARY_TITLE) }, toDisplayString(unref(m).formErrors(summary.value.length)), 1), createElementVNode("ul", { class: normalizeClass(SUMMARY_LIST) }, [(openBlock(true), createElementBlock(Fragment, null, renderList(summary.value, (entry) => {
369
+ fn: withCtx(() => [renderSlot(_ctx.$slots, "errorSummary", normalizeProps(guardReactiveProps(slotProps.value)), () => [createElementVNode("p", {
370
+ "data-eldra-scope": unref(eldra).scope,
371
+ class: normalizeClass(SUMMARY_TITLE)
372
+ }, toDisplayString(unref(m).formErrors(summary.value.length)), 9, _hoisted_1), createElementVNode("ul", {
373
+ "data-eldra-scope": unref(eldra).scope,
374
+ class: normalizeClass(SUMMARY_LIST)
375
+ }, [(openBlock(true), createElementBlock(Fragment, null, renderList(summary.value, (entry) => {
357
376
  return openBlock(), createElementBlock("li", { key: entry.name }, [entry.href !== void 0 ? (openBlock(), createElementBlock("a", {
358
377
  key: 0,
359
378
  href: entry.href,
360
379
  class: normalizeClass(SUMMARY_LINK)
361
- }, toDisplayString(entry.message), 9, _hoisted_1)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createTextVNode(toDisplayString(entry.message), 1)], 64))]);
362
- }), 128))])])]),
380
+ }, toDisplayString(entry.message), 9, _hoisted_3)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [createTextVNode(toDisplayString(entry.message), 1)], 64))]);
381
+ }), 128))], 8, _hoisted_2)])]),
363
382
  key: "0"
364
383
  } : void 0, _ctx.$slots.actions ? {
365
384
  name: "actions",
@@ -379,6 +398,8 @@ var FieldCheckbox_default = /* @__PURE__ */ defineComponent({
379
398
  size: {},
380
399
  hint: {},
381
400
  required: { type: Boolean },
401
+ requiredMark: { type: Boolean },
402
+ error: {},
382
403
  disabled: { type: Boolean },
383
404
  controls: {},
384
405
  id: {},
@@ -548,7 +569,7 @@ var FieldInput_default = /* @__PURE__ */ defineComponent({
548
569
  name: {},
549
570
  placeholder: {},
550
571
  autocomplete: {},
551
- inputmode: {},
572
+ inputmode: { type: [String, Boolean] },
552
573
  min: {},
553
574
  max: {},
554
575
  step: {},
@@ -607,6 +628,8 @@ var FieldMultiSelect_default = /* @__PURE__ */ defineComponent({
607
628
  props: {
608
629
  placeholder: {},
609
630
  showTags: { type: Boolean },
631
+ tagPlacement: {},
632
+ maxTagRows: {},
610
633
  maxSummary: {},
611
634
  classes: {},
612
635
  options: {},
@@ -622,6 +645,9 @@ var FieldMultiSelect_default = /* @__PURE__ */ defineComponent({
622
645
  readonly: { type: Boolean },
623
646
  placement: {},
624
647
  teleport: { type: [Boolean, String] },
648
+ loading: { type: Boolean },
649
+ creatable: { type: Boolean },
650
+ renderBatch: {},
625
651
  messages: {},
626
652
  path: {},
627
653
  rules: { type: [
@@ -734,6 +760,9 @@ var FieldRadioGroup_default = /* @__PURE__ */ defineComponent({
734
760
  layout: {},
735
761
  size: {},
736
762
  required: { type: Boolean },
763
+ requiredMark: { type: Boolean },
764
+ help: {},
765
+ invalid: { type: Boolean },
737
766
  classes: {},
738
767
  path: {},
739
768
  rules: { type: [
@@ -863,6 +892,9 @@ var FieldSelect_default = /* @__PURE__ */ defineComponent({
863
892
  readonly: { type: Boolean },
864
893
  placement: {},
865
894
  teleport: { type: [Boolean, String] },
895
+ loading: { type: Boolean },
896
+ creatable: { type: Boolean },
897
+ renderBatch: {},
866
898
  messages: {},
867
899
  classes: {},
868
900
  path: {},
@@ -910,6 +942,9 @@ var FieldSwitch_default = /* @__PURE__ */ defineComponent({
910
942
  size: {},
911
943
  description: {},
912
944
  disabled: { type: Boolean },
945
+ requiredMark: { type: Boolean },
946
+ error: {},
947
+ invalid: { type: Boolean },
913
948
  id: {},
914
949
  name: {},
915
950
  classes: {},
@@ -959,6 +994,7 @@ var FieldTextarea_default = /* @__PURE__ */ defineComponent({
959
994
  maxLength: {},
960
995
  counter: { type: Boolean },
961
996
  hardLimit: { type: Boolean },
997
+ clearable: { type: Boolean },
962
998
  minHeight: {},
963
999
  required: { type: Boolean },
964
1000
  readonly: { type: Boolean },
@@ -0,0 +1,50 @@
1
+ import { UiMessages } from '../messages/en-US.js';
2
+ export { toVueI18nMessages } from './shapes.js';
3
+ /**
4
+ * The parts of a vue-i18n `Composer` (`useI18n()`, or `i18n.global` with `legacy: false`) this entry
5
+ * reads.
6
+ */
7
+ export interface EldraUiI18n {
8
+ t(key: string, named: Record<string, unknown>, plural: number): string;
9
+ t(key: string, named?: Record<string, unknown>): string;
10
+ te(key: string, locale?: string): boolean;
11
+ locale: {
12
+ value: string;
13
+ };
14
+ fallbackLocale?: {
15
+ value: unknown;
16
+ };
17
+ }
18
+ export interface EldraUiI18nOptions {
19
+ /** Where the kit's keys live in your messages. Default `'eldraUi'`: `eldraUi.close`, … */
20
+ prefix?: string;
21
+ /** Text for a key your messages leave out. Default: the English defaults (`enUS`). */
22
+ fallback?: UiMessages;
23
+ }
24
+ /**
25
+ * The kit's messages read through vue-i18n, for `MESSAGES_KEY`. Each key is looked up under
26
+ * `prefix`; one your messages do not have falls back to `fallback`, so a partial translation is
27
+ * fine. Strings are read when a component renders, so switching the locale updates the kit.
28
+ *
29
+ * ```ts
30
+ * app.provide(MESSAGES_KEY, eldraUiI18nMessages(i18n.global));
31
+ * ```
32
+ */
33
+ export declare function eldraUiI18nMessages(i18n: EldraUiI18n, options?: EldraUiI18nOptions): UiMessages;
34
+ /**
35
+ * Reads the kit's messages from the app's vue-i18n for this component and everything below it.
36
+ * Call it during `setup()`, usually in the app root; it uses the global composer unless you pass
37
+ * one (`i18n`).
38
+ */
39
+ export declare function useEldraUiI18n(options?: EldraUiI18nOptions & {
40
+ i18n?: EldraUiI18n;
41
+ }): void;
42
+ /**
43
+ * Icelandic plural forms for vue-i18n's `pluralRules`: a number ending in 1, except 11, is
44
+ * singular (21 vara, 11 vörur). vue-i18n's default rule treats only 1 as singular.
45
+ *
46
+ * ```ts
47
+ * createI18n({ pluralRules: { 'is-IS': icelandicPluralRule }, … });
48
+ * ```
49
+ */
50
+ export declare function icelandicPluralRule(choice: number, choicesLength: number): number;
@@ -0,0 +1,40 @@
1
+ import { UiMessages } from '../messages/en-US.js';
2
+ type MessageFunction = (...args: never[]) => string;
3
+ /** The messages that take arguments: every one needs a shape below, or this file does not compile. */
4
+ export type FunctionMessageKey = {
5
+ [K in keyof UiMessages]: UiMessages[K] extends MessageFunction ? K : never;
6
+ }[keyof UiMessages];
7
+ /**
8
+ * How a message function maps onto vue-i18n, which has named values and plural forms but no
9
+ * conditions.
10
+ *
11
+ * - `params` names each argument, in order: `createOption(query)` reads `{query}`.
12
+ * - `count` names the argument whose number picks the plural form (`{n} result | {n} results`).
13
+ * - `numbers` names the other numeric arguments (the rest are text).
14
+ * - `variant` picks a key suffix for a branch that is not a count: `pageN(n, true)` reads
15
+ * `pageN_current`, `resultsCount(n, 'shoes')` reads `resultsCount_query`. `variants` gives the
16
+ * arguments that produce each one ('' is the plain key), so a message set can be converted.
17
+ */
18
+ export interface MessageShape {
19
+ params: readonly string[];
20
+ count?: string;
21
+ numbers?: readonly string[];
22
+ variant?: (...args: unknown[]) => string | undefined;
23
+ variants?: Readonly<Record<string, (sample: unknown[]) => unknown[]>>;
24
+ }
25
+ export declare const SHAPES: {
26
+ readonly [K in FunctionMessageKey]: MessageShape;
27
+ };
28
+ /** The key a call reads: `pageN`, or `pageN_current` for the branch its arguments select. */
29
+ export declare function variantKey(key: FunctionMessageKey, args: unknown[]): string;
30
+ /**
31
+ * A complete message set (`enUS`, `isIS` or your own) as vue-i18n messages: plain strings, named
32
+ * values (`{query}`), plural forms (`{n} result | {n} results`) and a suffixed key per branch
33
+ * (`pageN_current`). Merge it under the prefix `useEldraUiI18n` reads:
34
+ *
35
+ * ```ts
36
+ * i18n.global.mergeLocaleMessage('is-IS', { eldraUi: toVueI18nMessages(isIS) });
37
+ * ```
38
+ */
39
+ export declare function toVueI18nMessages(messages: UiMessages): Record<string, string>;
40
+ export {};
@@ -0,0 +1,289 @@
1
+ import { i as enUS, n as provideEldraUiMessages } from "./useMessages-B5nzZghs.js";
2
+ import { t as formatConjunctionList } from "./listFormat-D9ecpDMT.js";
3
+ import { numberFormat } from "@eldrajs/sdk/format";
4
+ import { useI18n } from "vue-i18n";
5
+ // src/vue-i18n/shapes.ts
6
+ var text = (...params) => ({ params });
7
+ var counted = (param = "n") => ({
8
+ params: [param],
9
+ count: param
10
+ });
11
+ var withQuery = {
12
+ params: ["n", "query"],
13
+ count: "n",
14
+ variant: (_n, query) => query === void 0 || query === "" ? void 0 : "query",
15
+ variants: {
16
+ "": ([n]) => [n],
17
+ query: (sample) => sample
18
+ }
19
+ };
20
+ var SHAPES = {
21
+ closeDrawer: text("name"),
22
+ noResultsFor: text("query"),
23
+ noMatchesFor: text("query"),
24
+ createOption: text("query"),
25
+ moreSelected: counted(),
26
+ removeTag: text("label"),
27
+ selectedCount: counted(),
28
+ quantityUpdated: counted(),
29
+ minimumOf: text("name"),
30
+ maximumOf: text("name"),
31
+ counter: {
32
+ params: ["n", "max"],
33
+ numbers: ["n", "max"]
34
+ },
35
+ slideOf: {
36
+ params: ["position", "total"],
37
+ numbers: ["position", "total"]
38
+ },
39
+ goToSlide: {
40
+ params: ["n"],
41
+ numbers: ["n"]
42
+ },
43
+ imageOf: {
44
+ params: ["position", "total"],
45
+ numbers: ["position", "total"]
46
+ },
47
+ goToImage: {
48
+ params: ["n"],
49
+ numbers: ["n"]
50
+ },
51
+ charactersLeft: counted(),
52
+ overLimit: counted(),
53
+ quickAdd: text("title"),
54
+ swatchesAvailable: counted(),
55
+ stockLow: {
56
+ params: ["n"],
57
+ count: "n",
58
+ variant: (n) => n === null ? "unknown" : void 0,
59
+ variants: {
60
+ "": (sample) => sample,
61
+ unknown: () => [null]
62
+ }
63
+ },
64
+ stockPreorder: {
65
+ params: ["date"],
66
+ variant: (date) => date === void 0 || date === "" ? void 0 : "date",
67
+ variants: {
68
+ "": () => [],
69
+ date: (sample) => sample
70
+ }
71
+ },
72
+ perUnit: text("per"),
73
+ rating: {
74
+ params: ["value", "count"],
75
+ count: "count",
76
+ numbers: ["value"]
77
+ },
78
+ reviewCount: counted(),
79
+ resultsCount: withQuery,
80
+ viewAllResults: withQuery,
81
+ formErrors: counted(),
82
+ avatarGroup: {
83
+ params: [
84
+ "label",
85
+ "names",
86
+ "more"
87
+ ],
88
+ numbers: ["more"]
89
+ },
90
+ showMoreLevels: counted(),
91
+ navMenuOverview: text("label"),
92
+ pageN: {
93
+ params: ["n", "current"],
94
+ numbers: ["n"],
95
+ variant: (_n, current) => current ? "current" : void 0,
96
+ variants: {
97
+ "": ([n]) => [n, false],
98
+ current: ([n]) => [n, true]
99
+ }
100
+ },
101
+ pageOfTotal: {
102
+ params: ["page", "total"],
103
+ numbers: ["page", "total"]
104
+ },
105
+ showingOf: {
106
+ params: [
107
+ "shown",
108
+ "total",
109
+ "noun"
110
+ ],
111
+ numbers: ["shown", "total"]
112
+ },
113
+ filterPanelRemoveFilter: text("facet", "value"),
114
+ filterPanelShowAll: counted(),
115
+ filterPanelSearchLabel: text("facet"),
116
+ filterPanelSearchPlaceholder: text("facet"),
117
+ filterPanelValueName: {
118
+ params: ["label", "count"],
119
+ count: "count"
120
+ },
121
+ filterPanelSizeName: {
122
+ params: [
123
+ "system",
124
+ "label",
125
+ "count"
126
+ ],
127
+ count: "count"
128
+ },
129
+ filterPanelImpliedBy: text("parent"),
130
+ filterPanelUnder: text("parent"),
131
+ filterPanelShowResults: counted(),
132
+ formTooShort: counted("min"),
133
+ formTooLong: counted("max")
134
+ };
135
+ /** The key a call reads: `pageN`, or `pageN_current` for the branch its arguments select. */
136
+ function variantKey(key, args) {
137
+ const variant = SHAPES[key].variant?.(...args);
138
+ return variant ? `${key}_${variant}` : key;
139
+ }
140
+ var marker = (name) => `\u0001${name}\u0002`;
141
+ var SINGULAR = 1;
142
+ var PLURAL = 7;
143
+ var RATING = 8.3;
144
+ /** vue-i18n's message syntax characters, written as literals. */
145
+ function escape(literal) {
146
+ return literal.replace(/[{}@$|]/g, (char) => `{'${char}'}`);
147
+ }
148
+ function sentinelFor(name, index) {
149
+ return name === "value" ? RATING : 9101 + index * 101;
150
+ }
151
+ function template(fn, args, numbers) {
152
+ let out = fn(...args);
153
+ for (const [name, value] of numbers) {
154
+ const digits = value === RATING ? "8[.,]3" : String(value);
155
+ out = out.replace(new RegExp(`(?<!\\d|\\d[.,])${digits}(?!\\d|[.,]\\d)`, "g"), marker(name));
156
+ }
157
+ return escape(out).replace(/\u0001(\w+)\u0002/g, "{$1}");
158
+ }
159
+ /**
160
+ * A complete message set (`enUS`, `isIS` or your own) as vue-i18n messages: plain strings, named
161
+ * values (`{query}`), plural forms (`{n} result | {n} results`) and a suffixed key per branch
162
+ * (`pageN_current`). Merge it under the prefix `useEldraUiI18n` reads:
163
+ *
164
+ * ```ts
165
+ * i18n.global.mergeLocaleMessage('is-IS', { eldraUi: toVueI18nMessages(isIS) });
166
+ * ```
167
+ */
168
+ function toVueI18nMessages(messages) {
169
+ const out = {};
170
+ for (const [key, value] of Object.entries(messages)) {
171
+ if (typeof value === "string") {
172
+ out[key] = escape(value);
173
+ continue;
174
+ }
175
+ const fn = value;
176
+ const shape = SHAPES[key];
177
+ if (key === "avatarGroup") {
178
+ out.avatarGroup = template(fn, [
179
+ marker("label"),
180
+ [marker("names")],
181
+ 0
182
+ ], /* @__PURE__ */ new Map());
183
+ const more = 9101;
184
+ const withMore = fn(marker("label"), [], more);
185
+ const item = withMore.slice(withMore.indexOf(String(more)));
186
+ out.avatarGroup_more = template(() => item, [], /* @__PURE__ */ new Map([["n", more]]));
187
+ continue;
188
+ }
189
+ const sample = (n) => shape.params.map((name, index) => name === shape.count ? n : shape.numbers?.includes(name) ? sentinelFor(name, index) : marker(name));
190
+ const numbersAt = (n) => new Map(shape.params.flatMap((name, index) => name === shape.count ? [[name, n]] : shape.numbers?.includes(name) ? [[name, sentinelFor(name, index)]] : []));
191
+ for (const [variant, toArgs] of Object.entries(shape.variants ?? { "": (s) => s })) {
192
+ const target = variant ? `${key}_${variant}` : key;
193
+ if (!shape.count) {
194
+ out[target] = template(fn, toArgs(sample(PLURAL)), numbersAt(PLURAL));
195
+ continue;
196
+ }
197
+ const forms = [SINGULAR, PLURAL].map((n) => template(fn, toArgs(sample(n)), numbersAt(n)));
198
+ out[target] = forms[0] === forms[1] ? forms[1] : forms.join(" | ");
199
+ }
200
+ }
201
+ return out;
202
+ }
203
+ // src/vue-i18n/index.ts
204
+ /**
205
+ * The kit's messages read through vue-i18n, for `MESSAGES_KEY`. Each key is looked up under
206
+ * `prefix`; one your messages do not have falls back to `fallback`, so a partial translation is
207
+ * fine. Strings are read when a component renders, so switching the locale updates the kit.
208
+ *
209
+ * ```ts
210
+ * app.provide(MESSAGES_KEY, eldraUiI18nMessages(i18n.global));
211
+ * ```
212
+ */
213
+ function eldraUiI18nMessages(i18n, options = {}) {
214
+ const prefix = options.prefix ?? "eldraUi";
215
+ const fallback = options.fallback ?? enUS;
216
+ const path = (key) => `${prefix}.${key}`;
217
+ const fallbackLocales = () => {
218
+ const value = i18n.fallbackLocale?.value;
219
+ if (typeof value === "string") return [value];
220
+ return Array.isArray(value) ? value.filter((v) => typeof v === "string") : [];
221
+ };
222
+ const has = (key) => i18n.te(path(key)) || fallbackLocales().some((locale) => i18n.te(path(key), locale));
223
+ const messages = {};
224
+ for (const key of Object.keys(enUS)) {
225
+ if (typeof enUS[key] === "string") {
226
+ Object.defineProperty(messages, key, {
227
+ enumerable: true,
228
+ get: () => has(key) ? i18n.t(path(key)) : fallback[key]
229
+ });
230
+ continue;
231
+ }
232
+ const fnKey = key;
233
+ const shape = SHAPES[fnKey];
234
+ const original = fallback[fnKey];
235
+ messages[key] = (...args) => {
236
+ if (fnKey === "avatarGroup") return avatarGroup(args, original);
237
+ const target = variantKey(fnKey, args);
238
+ if (!has(target)) return original(...args);
239
+ const named = {};
240
+ shape.params.forEach((name, index) => {
241
+ named[name] = args[index];
242
+ });
243
+ if (fnKey === "rating") named.value = oneDecimal(args[0]);
244
+ const count = shape.count === void 0 ? void 0 : named[shape.count];
245
+ return typeof count === "number" ? i18n.t(path(target), named, count) : i18n.t(path(target), named);
246
+ };
247
+ }
248
+ function oneDecimal(value) {
249
+ return numberFormat(i18n.locale.value, {
250
+ minimumFractionDigits: 1,
251
+ maximumFractionDigits: 1
252
+ }).format(value);
253
+ }
254
+ function avatarGroup(args, original) {
255
+ const [label, names, more] = args;
256
+ if (!has("avatarGroup") || more > 0 && !has("avatarGroup_more")) return original(...args);
257
+ const items = more > 0 ? [...names, i18n.t(path("avatarGroup_more"), { n: more }, more)] : names;
258
+ return i18n.t(path("avatarGroup"), {
259
+ label,
260
+ names: formatConjunctionList(items, i18n.locale.value)
261
+ });
262
+ }
263
+ return messages;
264
+ }
265
+ /**
266
+ * Reads the kit's messages from the app's vue-i18n for this component and everything below it.
267
+ * Call it during `setup()`, usually in the app root; it uses the global composer unless you pass
268
+ * one (`i18n`).
269
+ */
270
+ function useEldraUiI18n(options = {}) {
271
+ const i18n = options.i18n ?? useI18n({ useScope: "global" });
272
+ provideEldraUiMessages(eldraUiI18nMessages(i18n, options));
273
+ }
274
+ /**
275
+ * Icelandic plural forms for vue-i18n's `pluralRules`: a number ending in 1, except 11, is
276
+ * singular (21 vara, 11 vörur). vue-i18n's default rule treats only 1 as singular.
277
+ *
278
+ * ```ts
279
+ * createI18n({ pluralRules: { 'is-IS': icelandicPluralRule }, … });
280
+ * ```
281
+ */
282
+ function icelandicPluralRule(choice, choicesLength) {
283
+ const n = Math.abs(choice);
284
+ const singular = n % 10 === 1 && n % 100 !== 11;
285
+ if (choicesLength === 2) return singular ? 0 : 1;
286
+ if (choicesLength === 3) return n === 0 ? 0 : singular ? 1 : 2;
287
+ return Math.min(n, choicesLength - 1);
288
+ }
289
+ export { eldraUiI18nMessages, icelandicPluralRule, toVueI18nMessages, useEldraUiI18n };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eldrajs/ui",
3
- "version": "0.2.8",
3
+ "version": "0.2.9",
4
4
  "description": "Accessible Vue 3 core components for Eldra storefronts: buttons, forms, selects, cards, overlays and navigation, themed through CSS design tokens.",
5
5
  "keywords": [
6
6
  "accessible",
@@ -41,6 +41,10 @@
41
41
  "types": "./dist/vee-validate/index.d.ts",
42
42
  "import": "./dist/vee-validate.js"
43
43
  },
44
+ "./vue-i18n": {
45
+ "types": "./dist/vue-i18n/index.d.ts",
46
+ "import": "./dist/vue-i18n.js"
47
+ },
44
48
  "./messages/is-IS": {
45
49
  "types": "./dist/messages/is-IS.d.ts",
46
50
  "import": "./dist/messages/is-IS.js"
@@ -49,6 +53,7 @@
49
53
  "./tailwind.css": "./dist/tailwind.css",
50
54
  "./style.css": "./dist/style.css",
51
55
  "./components.css": "./dist/components.css",
56
+ "./scoped.css": "./dist/scoped.css",
52
57
  "./package.json": "./package.json"
53
58
  },
54
59
  "publishConfig": {
@@ -58,7 +63,7 @@
58
63
  "dependencies": {
59
64
  "@floating-ui/vue": "^1.1.5",
60
65
  "tailwind-merge": "^3.0.0",
61
- "@eldrajs/sdk": "^0.4.0"
66
+ "@eldrajs/sdk": "^0.4.1"
62
67
  },
63
68
  "devDependencies": {
64
69
  "@playwright/test": "1.62.1",
@@ -74,6 +79,9 @@
74
79
  "happy-dom": "^21.0.4",
75
80
  "pixelmatch": "^7.1.0",
76
81
  "pngjs": "^7.0.0",
82
+ "postcss": "^8.5.32",
83
+ "postcss-selector-parser": "^7.1.6",
84
+ "postcss-value-parser": "^4.2.0",
77
85
  "storybook": "^10.2.19",
78
86
  "tailwindcss": "^4.1.14",
79
87
  "vee-validate": "^4.15.0",
@@ -81,15 +89,20 @@
81
89
  "vite-plugin-dts": "^5.1.0",
82
90
  "vitest-axe": "^0.1.0",
83
91
  "vue": "^3.5.30",
92
+ "vue-i18n": "^11.4.16",
84
93
  "vue-tsc": "^3.3.11"
85
94
  },
86
95
  "peerDependencies": {
87
96
  "vee-validate": "^4.12.0",
88
- "vue": "^3.5.0"
97
+ "vue": "^3.5.0",
98
+ "vue-i18n": "^11.0.0"
89
99
  },
90
100
  "peerDependenciesMeta": {
91
101
  "vee-validate": {
92
102
  "optional": true
103
+ },
104
+ "vue-i18n": {
105
+ "optional": true
93
106
  }
94
107
  },
95
108
  "engines": {