UNPKG

@public-ui/components

Version:

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

5 lines 2.58 kB
/*! * KoliBri - The accessible HTML-Standard */ import{k as t,H as s,s as e}from"./common-Cx_AGO_M.js";import{h as i,c as r}from"./label-Fyi30H9j.js";import{v as o}from"./required-DFzRSWky.js";import{v as a}from"./orientation-CjNmUJp-.js";import{I as n}from"./FormFieldStateWrapper-BWTMRKXT.js";const f=s=>{if(typeof s==="object"&&s!==null){if(typeof s.label==="string"&&s.label.length>0){s.disabled=s.disabled===true;s.label=`${s.label}`.trim();if(i(s.label,3)===false&&r(s.label)===false){t(`A differing Aria-Label (${s.label}) is inaccessible. A differing Aria-Label should consist of at least three readable characters.`)}if(Array.isArray(s.options)){return s.options.find((t=>f(t)===false))===undefined}return true}else if(typeof s.label==="number"){return true}}return false};const l=(t,e,i={})=>{s(t,"_options",(t=>typeof t==="object"&&t!==null&&typeof t.label==="string"&&t.label.length>0),e,undefined,i)};const h=(t,e,i={})=>{s(t,"_options",f,e,undefined,i)};const c=(t,s,e="")=>{s.forEach(((s,i)=>{const r=`${e}-${i}`;if(typeof s==="object"&&s!==null&&typeof s.label==="string"&&s.label.length>0){if(Array.isArray(s.options)){c(t,s.options,r)}else{t.set(r,s)}}}))};class u extends n{constructor(t,s,e){super(t,s,e);this.component=t}validateRequired(t){o(this.component,t)}componentWillLoad(){super.componentWillLoad();this.validateRequired(this.component._required)}}class p extends u{constructor(t,s,e){super(t,s,e);this.keyOptionMap=new Map;this.getOptionByKey=t=>this.keyOptionMap.get(t);this.afterPatchOptions=(t,s,e,i)=>{if(i==="_value"){this.setFormAssociatedValue(t)}};this.beforePatchOptions=(t,s)=>{const e=s.has("_options")?s.get("_options"):this.component.state._options;if(Array.isArray(e)&&e.length>0){this.keyOptionMap.clear();const t=e.map((t=>{var s;if(typeof t==="object"&&t!==null&&typeof t.label==="string"){return Object.assign(Object.assign({},t),{value:(s=t.value)!==null&&s!==void 0?s:t.label})}return t}));c(this.keyOptionMap,t)}};this.component=t}validateOrientation(t){a(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{u as I,p as a,l as b,c as f,h as v}; //# sourceMappingURL=controller-DKPaX3Tu.js.map