sit-onyx 0.1.0-alpha.2 → 0.1.0-alpha.4

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.
@@ -2,8 +2,17 @@ import type { ObjectToDottedStrings } from '../types/i18n';
2
2
  import type { DeepPartial } from '../types/utils';
3
3
  import { type MaybeRef } from "vue";
4
4
  import enUS from "./locales/en-US.json";
5
+ /**
6
+ * The type of the imported `enUS` above is a concrete type so the value type of each message
7
+ * is e.g. "{ myKey: 'HelloWorld'}" but it should be "{ myKey: string }".
8
+ * This utility type converts all values to be of type string (more generic)
9
+ * so we can actually use other locales as well.
10
+ */
11
+ type GetTypeOfTranslations<T> = T extends object ? {
12
+ [P in keyof T]?: GetTypeOfTranslations<T[P]>;
13
+ } : string;
5
14
  /** Available translations that are used by onyx components. */
6
- export type OnyxTranslations = typeof enUS;
15
+ export type OnyxTranslations = GetTypeOfTranslations<typeof enUS>;
7
16
  export type ProvideI18nOptions = {
8
17
  /**
9
18
  * Current locale / language to use.
@@ -44,3 +53,4 @@ export declare const injectI18n: () => {
44
53
  locale: import("vue").ComputedRef<string>;
45
54
  t: import("vue").ComputedRef<(key: ObjectToDottedStrings<OnyxTranslations>, placeholders?: Record<string, string | number | undefined>) => string>;
46
55
  };
56
+ export {};
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("vue"),M={tooShort:"Please lengthen this text to {minLength} characters or more (you are currently using 1 character) | Please lengthen this text to {minLength} characters or more (you are currently using {n} characters)",tooLong:"Please shorten this text to {maxLength} characters or less (you are currently using 1 character) | Please shorten this text to {maxLength} characters or less (you are currently using {n} characters)",rangeUnderflow:"Value must be greater than or equal to {min}",rangeOverflow:"Value must be less than or equal to {max}",patternMismatch:"Please match the format requested.",valueMissing:"Please fill in this field.",stepMismatch:"Please enter a value that is a multiple of {step}.",badInput:'"{value}" does not match the expected type.',typeMismatch:{generic:'"{value}" does not match the expected type.',email:'"{value}" must be a valid email address.',number:'"{value}" must be a number.',tel:'"{value}" must be a valid phone number.',url:'"{value}" must a valid URL.'}},p={validations:M},f=Symbol(),x=a=>{const n=t.computed(()=>t.unref(a==null?void 0:a.locale)??"en-US"),e=t.computed(()=>a!=null&&a.messages&&n.value in a.messages?a.messages[n.value]:p),r=t.computed(()=>(s,i={})=>{let l=y(s,e.value)??y(s,p)??"";const o=typeof i.n=="number"?i.n:void 0;return l=P(l,o),V(l,i)});return{locale:n,t:r}},S=a=>{t.provide(f,x(a))},I=()=>t.inject(f,()=>x(),!0),y=(a,n)=>{const e=a.split(".").reduce((r,s)=>!r||typeof r=="string"?r:r[s],n);return e&&typeof e=="string"?e:void 0},P=(a,n)=>{const e=a.split(" | ").map(s=>s.trim());if(e.length<=1)return a;let r=1;return n===0&&(r=0),n&&(n<=0||n>1)&&(r=2),e.length===2?r===1?e[0]:e[1]:e[r]},V=(a,n)=>n?Object.entries(n).reduce((r,[s,i])=>i===void 0?r:r.replace(new RegExp(`{${s}}`,"gi"),i.toString()),a).replace(/\s?{.*}\s?/gi,""):a,E=a=>{if(a.valueMissing)return"valueMissing";const n=Object.entries(Object.getOwnPropertyDescriptors(ValidityState.prototype)).filter(([e,r])=>e!=="valid"&&r.enumerable).map(([e])=>e);for(const e of n)if(e in a&&a[e])return e},L={key:0,class:"onyx-input__error","aria-live":"polite"},T={class:"onyx-input__info"},C=Object.keys(p.validations.typeMismatch),N=t.defineComponent({__name:"TestInput",props:{modelValue:{default:""},label:{default:""},errorMessage:{},required:{type:Boolean},pattern:{},type:{default:"text"},max:{},maxLength:{},min:{},step:{},minLength:{}},emits:["update:modelValue","change","validityChange"],setup(a,{emit:n}){var d;const e=a,r=n,{t:s}=I(),i=t.ref(!1),l=t.ref(null),o=t.ref((d=l.value)==null?void 0:d.validity),m=t.computed({get:()=>e.modelValue,set:u=>r("update:modelValue",u)}),_=t.computed(()=>{if(!o.value||o.value.valid)return"";const u=E(o.value);if(e.errorMessage||u==="customError")return e.errorMessage;if(!u)return"";if(u==="typeMismatch"){const c=C.includes(e.type)?e.type:"generic";return s.value(`validations.typeMismatch.${c}`,{value:m.value})}return s.value(`validations.${u}`,{value:m.value,n:m.value.toString().length,minLength:e.minLength,maxLength:e.maxLength,min:e.min,max:e.max,step:e.step})}),b=u=>{const c=u.target;r("change",c.value)};return t.watch([m,l],()=>{l.value&&(o.value=l.value.validity)}),t.watch(o,u=>{u&&r("validityChange",u)},{deep:!0}),t.watch([e.errorMessage,l],()=>{l.value&&l.value.setCustomValidity(e.errorMessage||"")},{immediate:!0}),(u,c)=>{var v,g;return t.openBlock(),t.createElementBlock("label",{class:t.normalizeClass(["onyx-input",{"onyx-input--touched":i.value}])},[t.createElementVNode("span",{class:t.normalizeClass(["onyx-input__label",{"onyx-input__label--required":e.required}])},t.toDisplayString(e.label),3),t.withDirectives(t.createElementVNode("input",t.mergeProps(e,{ref_key:"inputElement",ref:l,"onUpdate:modelValue":c[0]||(c[0]=h=>m.value=h),onChange:b,onBlur:c[1]||(c[1]=h=>i.value=!0)}),null,16),[[t.vModelDynamic,m.value]]),i.value&&!((v=o.value)!=null&&v.valid)?(t.openBlock(),t.createElementBlock("p",L,t.toDisplayString(_.value),1)):t.createCommentVNode("",!0),t.createElementVNode("p",T,'Model value: "'+t.toDisplayString(m.value)+'", is valid: '+t.toDisplayString((g=o.value)==null?void 0:g.valid),1)],2)}}}),O=(a,n)=>{const e=a.__vccOpts||a;for(const[r,s]of n)e[r]=s;return e},D=O(N,[["__scopeId","data-v-b84504d3"]]);exports.TestInput=D;exports.provideI18n=S;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const r=require("vue"),V={tooShort:"Please lengthen this text to {minLength} characters or more (you are currently using 1 character) | Please lengthen this text to {minLength} characters or more (you are currently using {n} characters)",tooLong:"Please shorten this text to {maxLength} characters or less (you are currently using 1 character) | Please shorten this text to {maxLength} characters or less (you are currently using {n} characters)",rangeUnderflow:"Value must be greater than or equal to {min}",rangeOverflow:"Value must be less than or equal to {max}",patternMismatch:"Please match the format requested.",valueMissing:"Please fill in this field.",stepMismatch:"Please enter a value that is a multiple of {step}.",badInput:'"{value}" does not match the expected type.',typeMismatch:{generic:'"{value}" does not match the expected type.',email:'"{value}" must be a valid email address.',number:'"{value}" must be a number.',tel:'"{value}" must be a valid phone number.',url:'"{value}" must a valid URL.'}},v={validations:V},_=Symbol(),b=t=>{const n=r.computed(()=>r.unref(t==null?void 0:t.locale)??"en-US"),e=r.computed(()=>t!=null&&t.messages&&n.value in t.messages?t.messages[n.value]:v),a=r.computed(()=>(s,l={})=>{let m=y(s,e.value)??y(s,v)??"";const o=typeof l.n=="number"?l.n:void 0;return m=I(m,o),T(m,l)});return{locale:n,t:a}},E=t=>{r.provide(_,b(t))},P=()=>r.inject(_,()=>b(),!0),y=(t,n)=>{const e=t.split(".").reduce((a,s)=>!a||typeof a=="string"?a:a[s],n);return e&&typeof e=="string"?e:void 0},I=(t,n)=>{const e=t.split(" | ").map(s=>s.trim());if(e.length<=1)return t;let a=1;return n===0&&(a=0),n&&(n<=0||n>1)&&(a=2),e.length===2?a===1?e[0]:e[1]:e[a]},T=(t,n)=>n?Object.entries(n).reduce((a,[s,l])=>l===void 0?a:a.replace(new RegExp(`{${s}}`,"gi"),l.toString()),t).replace(/\s?{.*}\s?/gi,""):t,x=()=>Object.entries(Object.getOwnPropertyDescriptors(ValidityState.prototype)).filter(([t,n])=>n.enumerable).map(([t])=>t),L=t=>x().reduce((n,e)=>(n[e]=t[e],n),{}),O=t=>{if(t.valueMissing)return"valueMissing";const n=x().filter(e=>e!=="valid").sort();for(const e of n)if(e in t&&t[e])return e},C=(t,n)=>{const e=Object.entries(t).filter(([s,l])=>l!==void 0),a=Object.entries(n).filter(([s,l])=>l!==void 0);return e.length!==a.length?!1:e.every(([s,l])=>l===n[s])},N={key:0,class:"onyx-input__error","aria-live":"polite"},q={class:"onyx-input__info"},w=Object.keys(v.validations.typeMismatch),D=r.defineComponent({__name:"TestInput",props:{modelValue:{default:""},label:{default:""},errorMessage:{},required:{type:Boolean},pattern:{},type:{default:"text"},max:{},maxLength:{},min:{},step:{},minLength:{}},emits:["update:modelValue","change","validityChange"],setup(t,{emit:n}){var p;const e=t,a=n,{t:s}=P(),{errorMessage:l}=r.toRefs(e),m=r.ref(!1),o=r.ref(null),u=r.ref((p=o.value)==null?void 0:p.validity),d=r.computed({get:()=>e.modelValue,set:i=>a("update:modelValue",i)}),M=r.computed(()=>{if(!u.value||u.value.valid)return"";const i=O(u.value);if(e.errorMessage||i==="customError")return e.errorMessage;if(!i)return"";if(i==="typeMismatch"){const c=w.includes(e.type)?e.type:"generic";return s.value(`validations.typeMismatch.${c}`,{value:d.value})}return s.value(`validations.${i}`,{value:d.value,n:d.value.toString().length,minLength:e.minLength,maxLength:e.maxLength,min:e.min,max:e.max,step:e.step})}),S=i=>{const c=i.target;a("change",c.value)};return r.watch([o,l],()=>{o.value&&o.value.setCustomValidity(e.errorMessage||"")}),r.watch([o,d,l],()=>{if(!o.value)return;const i=L(o.value.validity);(!u.value||!C(i,u.value))&&(u.value=i,a("validityChange",u.value))},{immediate:!0}),(i,c)=>{var g,h;return r.openBlock(),r.createElementBlock("label",{class:r.normalizeClass(["onyx-input",{"onyx-input--touched":m.value}])},[r.createElementVNode("span",{class:r.normalizeClass(["onyx-input__label",{"onyx-input__label--required":e.required}])},r.toDisplayString(e.label),3),r.withDirectives(r.createElementVNode("input",r.mergeProps(e,{ref_key:"inputElement",ref:o,"onUpdate:modelValue":c[0]||(c[0]=f=>d.value=f),onChange:S,onBlur:c[1]||(c[1]=f=>m.value=!0)}),null,16),[[r.vModelDynamic,d.value]]),m.value&&!((g=u.value)!=null&&g.valid)?(r.openBlock(),r.createElementBlock("p",N,r.toDisplayString(M.value),1)):r.createCommentVNode("",!0),r.createElementVNode("p",q,'Model value: "'+r.toDisplayString(d.value)+'", is valid: '+r.toDisplayString((h=u.value)==null?void 0:h.valid),1)],2)}}}),U=(t,n)=>{const e=t.__vccOpts||t;for(const[a,s]of n)e[a]=s;return e},j=U(D,[["__scopeId","data-v-6632dbdc"]]);exports.TestInput=j;exports.provideI18n=E;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { provide as E, inject as C, computed as m, unref as O, defineComponent as N, ref as p, watch as d, openBlock as b, createElementBlock as M, normalizeClass as L, createElementVNode as g, toDisplayString as v, withDirectives as q, mergeProps as U, vModelDynamic as k, createCommentVNode as w } from "vue";
2
- const D = {
1
+ import { provide as C, inject as U, computed as d, unref as q, defineComponent as w, toRefs as N, ref as p, watch as b, openBlock as M, createElementBlock as V, normalizeClass as E, createElementVNode as g, toDisplayString as v, withDirectives as j, mergeProps as D, vModelDynamic as k, createCommentVNode as z } from "vue";
2
+ const B = {
3
3
  tooShort: "Please lengthen this text to {minLength} characters or more (you are currently using 1 character) | Please lengthen this text to {minLength} characters or more (you are currently using {n} characters)",
4
4
  tooLong: "Please shorten this text to {maxLength} characters or less (you are currently using 1 character) | Please shorten this text to {maxLength} characters or less (you are currently using {n} characters)",
5
5
  rangeUnderflow: "Value must be greater than or equal to {min}",
@@ -16,41 +16,45 @@ const D = {
16
16
  url: '"{value}" must a valid URL.'
17
17
  }
18
18
  }, h = {
19
- validations: D
20
- }, I = Symbol(), V = (t) => {
21
- const r = m(() => O(t == null ? void 0 : t.locale) ?? "en-US"), e = m(() => t != null && t.messages && r.value in t.messages ? t.messages[r.value] : h), a = m(() => (n, u = {}) => {
22
- let s = P(n, e.value) ?? P(n, h) ?? "";
23
- const i = typeof u.n == "number" ? u.n : void 0;
24
- return s = B(s, i), $(s, u);
19
+ validations: B
20
+ }, L = Symbol(), S = (t) => {
21
+ const r = d(() => q(t == null ? void 0 : t.locale) ?? "en-US"), e = d(() => t != null && t.messages && r.value in t.messages ? t.messages[r.value] : h), a = d(() => (n, s = {}) => {
22
+ let c = P(n, e.value) ?? P(n, h) ?? "";
23
+ const i = typeof s.n == "number" ? s.n : void 0;
24
+ return c = $(c, i), A(c, s);
25
25
  });
26
26
  return { locale: r, t: a };
27
- }, G = (t) => {
28
- E(I, V(t));
29
- }, z = () => C(I, () => V(), !0), P = (t, r) => {
27
+ }, Z = (t) => {
28
+ C(L, S(t));
29
+ }, R = () => U(L, () => S(), !0), P = (t, r) => {
30
30
  const e = t.split(".").reduce((a, n) => !a || typeof a == "string" ? a : a[n], r);
31
31
  return e && typeof e == "string" ? e : void 0;
32
- }, B = (t, r) => {
32
+ }, $ = (t, r) => {
33
33
  const e = t.split(" | ").map((n) => n.trim());
34
34
  if (e.length <= 1)
35
35
  return t;
36
36
  let a = 1;
37
37
  return r === 0 && (a = 0), r && (r <= 0 || r > 1) && (a = 2), e.length === 2 ? a === 1 ? e[0] : e[1] : e[a];
38
- }, $ = (t, r) => r ? Object.entries(r).reduce((a, [n, u]) => u === void 0 ? a : a.replace(new RegExp(`{${n}}`, "gi"), u.toString()), t).replace(/\s?{.*}\s?/gi, "") : t, j = (t) => {
38
+ }, A = (t, r) => r ? Object.entries(r).reduce((a, [n, s]) => s === void 0 ? a : a.replace(new RegExp(`{${n}}`, "gi"), s.toString()), t).replace(/\s?{.*}\s?/gi, "") : t, I = () => Object.entries(Object.getOwnPropertyDescriptors(ValidityState.prototype)).filter(([t, r]) => r.enumerable).map(([t]) => t), F = (t) => I().reduce(
39
+ (r, e) => (r[e] = t[e], r),
40
+ {}
41
+ ), Y = (t) => {
39
42
  if (t.valueMissing)
40
43
  return "valueMissing";
41
- const r = Object.entries(
42
- Object.getOwnPropertyDescriptors(ValidityState.prototype)
43
- ).filter(([e, a]) => e !== "valid" && a.enumerable).map(([e]) => e);
44
+ const r = I().filter((e) => e !== "valid").sort();
44
45
  for (const e of r)
45
46
  if (e in t && t[e])
46
47
  return e;
47
- }, R = {
48
+ }, J = (t, r) => {
49
+ const e = Object.entries(t).filter(([n, s]) => s !== void 0), a = Object.entries(r).filter(([n, s]) => s !== void 0);
50
+ return e.length !== a.length ? !1 : e.every(([n, s]) => s === r[n]);
51
+ }, K = {
48
52
  key: 0,
49
53
  class: "onyx-input__error",
50
54
  "aria-live": "polite"
51
- }, A = { class: "onyx-input__info" }, Y = Object.keys(
55
+ }, G = { class: "onyx-input__info" }, H = Object.keys(
52
56
  h.validations.typeMismatch
53
- ), F = /* @__PURE__ */ N({
57
+ ), Q = /* @__PURE__ */ w({
54
58
  __name: "TestInput",
55
59
  props: {
56
60
  modelValue: { default: "" },
@@ -67,25 +71,25 @@ const D = {
67
71
  },
68
72
  emits: ["update:modelValue", "change", "validityChange"],
69
73
  setup(t, { emit: r }) {
70
- var y;
71
- const e = t, a = r, { t: n } = z(), u = p(!1), s = p(null), i = p((y = s.value) == null ? void 0 : y.validity), c = m({
74
+ var f;
75
+ const e = t, a = r, { t: n } = R(), { errorMessage: s } = N(e), c = p(!1), i = p(null), u = p((f = i.value) == null ? void 0 : f.validity), m = d({
72
76
  get: () => e.modelValue,
73
77
  set: (l) => a("update:modelValue", l)
74
- }), S = m(() => {
75
- if (!i.value || i.value.valid)
78
+ }), O = d(() => {
79
+ if (!u.value || u.value.valid)
76
80
  return "";
77
- const l = j(i.value);
81
+ const l = Y(u.value);
78
82
  if (e.errorMessage || l === "customError")
79
83
  return e.errorMessage;
80
84
  if (!l)
81
85
  return "";
82
86
  if (l === "typeMismatch") {
83
- const o = Y.includes(e.type) ? e.type : "generic";
84
- return n.value(`validations.typeMismatch.${o}`, { value: c.value });
87
+ const o = H.includes(e.type) ? e.type : "generic";
88
+ return n.value(`validations.typeMismatch.${o}`, { value: m.value });
85
89
  }
86
90
  return n.value(`validations.${l}`, {
87
- value: c.value,
88
- n: c.value.toString().length,
91
+ value: m.value,
92
+ n: m.value.toString().length,
89
93
  minLength: e.minLength,
90
94
  maxLength: e.maxLength,
91
95
  min: e.min,
@@ -96,49 +100,46 @@ const D = {
96
100
  const o = l.target;
97
101
  a("change", o.value);
98
102
  };
99
- return d([c, s], () => {
100
- s.value && (i.value = s.value.validity);
101
- }), d(
102
- i,
103
- (l) => {
104
- l && a("validityChange", l);
105
- },
106
- { deep: !0 }
107
- ), d(
108
- [e.errorMessage, s],
103
+ return b([i, s], () => {
104
+ i.value && i.value.setCustomValidity(e.errorMessage || "");
105
+ }), b(
106
+ [i, m, s],
109
107
  () => {
110
- s.value && s.value.setCustomValidity(e.errorMessage || "");
108
+ if (!i.value)
109
+ return;
110
+ const l = F(i.value.validity);
111
+ (!u.value || !J(l, u.value)) && (u.value = l, a("validityChange", u.value));
111
112
  },
112
113
  { immediate: !0 }
113
114
  ), (l, o) => {
114
- var f, x;
115
- return b(), M("label", {
116
- class: L(["onyx-input", { "onyx-input--touched": u.value }])
115
+ var y, _;
116
+ return M(), V("label", {
117
+ class: E(["onyx-input", { "onyx-input--touched": c.value }])
117
118
  }, [
118
119
  g("span", {
119
- class: L(["onyx-input__label", { "onyx-input__label--required": e.required }])
120
+ class: E(["onyx-input__label", { "onyx-input__label--required": e.required }])
120
121
  }, v(e.label), 3),
121
- q(g("input", U(e, {
122
+ j(g("input", D(e, {
122
123
  ref_key: "inputElement",
123
- ref: s,
124
- "onUpdate:modelValue": o[0] || (o[0] = (_) => c.value = _),
124
+ ref: i,
125
+ "onUpdate:modelValue": o[0] || (o[0] = (x) => m.value = x),
125
126
  onChange: T,
126
- onBlur: o[1] || (o[1] = (_) => u.value = !0)
127
+ onBlur: o[1] || (o[1] = (x) => c.value = !0)
127
128
  }), null, 16), [
128
- [k, c.value]
129
+ [k, m.value]
129
130
  ]),
130
- u.value && !((f = i.value) != null && f.valid) ? (b(), M("p", R, v(S.value), 1)) : w("", !0),
131
- g("p", A, 'Model value: "' + v(c.value) + '", is valid: ' + v((x = i.value) == null ? void 0 : x.valid), 1)
131
+ c.value && !((y = u.value) != null && y.valid) ? (M(), V("p", K, v(O.value), 1)) : z("", !0),
132
+ g("p", G, 'Model value: "' + v(m.value) + '", is valid: ' + v((_ = u.value) == null ? void 0 : _.valid), 1)
132
133
  ], 2);
133
134
  };
134
135
  }
135
- }), J = (t, r) => {
136
+ }), W = (t, r) => {
136
137
  const e = t.__vccOpts || t;
137
138
  for (const [a, n] of r)
138
139
  e[a] = n;
139
140
  return e;
140
- }, H = /* @__PURE__ */ J(F, [["__scopeId", "data-v-b84504d3"]]);
141
+ }, ee = /* @__PURE__ */ W(Q, [["__scopeId", "data-v-6632dbdc"]]);
141
142
  export {
142
- H as TestInput,
143
- G as provideI18n
143
+ ee as TestInput,
144
+ Z as provideI18n
144
145
  };
@@ -0,0 +1,14 @@
1
+ import AxeBuilder from "@axe-core/playwright";
2
+ import { test as base } from "@playwright/experimental-ct-vue";
3
+ export { expect } from "@playwright/experimental-ct-vue";
4
+ type AxeFixture = {
5
+ makeAxeBuilder: () => AxeBuilder;
6
+ };
7
+ /**
8
+ * Extends Playwright's base test by providing `makeAxeBuilder`
9
+ * This new `test` can be used in multiple test files, and each of them will get
10
+ * a consistently configured AxeBuilder instance.
11
+ *
12
+ * @see https://playwright.dev/docs/accessibility-testing#using-a-test-fixture-for-common-axe-configuration
13
+ */
14
+ export declare const test: ReturnType<typeof base.extend<AxeFixture>>;