@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
4 lines • 2.34 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import{b as t,y as e,h as s,w as i,k as a}from"./index-88dea7b1.js";import{I as r}from"./getRenderStates-dba2a9a8.js";import{b as o,c as n}from"./label-5982d241.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===o(e.label,3)&&!1===n(e.label)&&t(`A differing Aria-Label (${e.label}) is not accessible. 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,o,a={})=>{e(t,"_options",(t=>"object"==typeof t&&null!==t&&"string"==typeof t.label&&t.label.length>0),o,void 0,a)},h=(t,o,a={})=>{e(t,"_options",f,o,void 0,a)},c=(t,e)=>{s(t,"_required",e)},u=["horizontal","vertical"],d=(t,e,o="")=>{e.forEach(((e,a)=>{const i=`${o}-${a}`;"object"==typeof e&&null!==e&&"string"==typeof e.label&&e.label.length>0&&(Array.isArray(e.options)?d(t,e.options,i):t.set(i,e))}))};class p extends r{constructor(t,e,o){super(t,e,o),this.component=t}validateRequired(t){c(this.component,t)}componentWillLoad(){super.componentWillLoad(),this.validateRequired(this.component._required)}}class b 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,a)=>{"_value"===a&&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(),d(this.keyOptionMap,o))},this.component=t}validateOrientation(t){i(this.component,"_orientation",(t=>"string"==typeof t&&u.includes(t)),new Set([`Orientation {${u.join(", ")}`]),t,{defaultValue:"vertical"})}validateOptions(t){l(this.component,t,{hooks:{afterPatch:this.afterPatchOptions,beforePatch:this.beforePatchOptions}})}validateValue(t){t=Array.isArray(t)?t[0]:t,a(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,b as a,l as b,d as f,h as v};