UNPKG

@public-ui/components

Version:

Contains all web components that belong to KoliBri - The accessible HTML-Standard.

4 lines 2.24 kB
/*! * KoliBri - The accessible HTML-Standard */ import{t,H as s,s as e}from"./common-7RW_NFNf.js";import{b as i,c as r}from"./label-DAfXJvJZ.js";import{v as a}from"./required-DZ5CUsrb.js";import{I as o}from"./FormFieldStateWrapper-BlcmQgCr.js";import{v as n}from"./orientation-BV4mvHIC.js";const f=e=>{if("object"==typeof e&&null!==e){if("string"==typeof e.label&&e.label.length>0)return e.disabled=!0===e.disabled,e.label=`${e.label}`.trim(),!1===i(e.label,3)&&!1===r(e.label)&&t(`A differing Aria-Label (${e.label}) is inaccessible. A differing Aria-Label should consist of at least three readable characters.`),!Array.isArray(e.options)||void 0===e.options.find((t=>!1===f(t)));if("number"==typeof e.label)return!0}return!1},l=(t,e,o={})=>{s(t,"_options",(t=>"object"==typeof t&&null!==t&&"string"==typeof t.label&&t.label.length>0),e,void 0,o)},h=(t,e,o={})=>{s(t,"_options",f,e,void 0,o)},c=(t,e,o="")=>{e.forEach(((e,i)=>{const a=`${o}-${i}`;"object"==typeof e&&null!==e&&"string"==typeof e.label&&e.label.length>0&&(Array.isArray(e.options)?c(t,e.options,a):t.set(a,e))}))};class p extends o{constructor(t,e,o){super(t,e,o),this.component=t}validateRequired(t){a(this.component,t)}componentWillLoad(){super.componentWillLoad(),this.validateRequired(this.component._required)}}class u extends p{constructor(t,e,o){super(t,e,o),this.keyOptionMap=new Map,this.getOptionByKey=t=>this.keyOptionMap.get(t),this.afterPatchOptions=(t,e,o,i)=>{"_value"===i&&this.setFormAssociatedValue(t)},this.beforePatchOptions=(t,e)=>{const o=e.has("_options")?e.get("_options"):this.component.state._options;Array.isArray(o)&&o.length>0&&(this.keyOptionMap.clear(),c(this.keyOptionMap,o))},this.component=t}validateOrientation(t){n(this.component,t,"vertical")}validateOptions(t){l(this.component,t,{hooks:{afterPatch:this.afterPatchOptions,beforePatch:this.beforePatchOptions}})}validateValue(t){t=Array.isArray(t)?t[0]:t,e(this.component,"_value",t,{afterPatch:this.afterPatchOptions,beforePatch:this.beforePatchOptions})}componentWillLoad(){super.componentWillLoad(),this.validateOrientation(this.component._orientation),this.validateOptions(this.component._options),this.validateValue(this.component._value)}}export{p as I,u as a,l as b,c as f,h as v};