UNPKG

@public-ui/components

Version:

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

4 lines 2.41 kB
/*! * KoliBri - The accessible HTML-Standard */ import{q as t,H as e,s}from"./common-Dd0zJQbD.js";import{b as i,c as r}from"./label-Dnmzb2S_.js";import{v as o}from"./required-CnTTpFCN.js";import{v as a}from"./orientation-eCMt8CD1.js";import{I as n}from"./FormFieldStateWrapper-BJBSoSm4.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,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,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)?c(t,e.options,i):t.set(i,e))})};class u extends n{constructor(t,e,o){super(t,e,o),this.component=t}validateRequired(t){o(this.component,t)}componentWillLoad(){super.componentWillLoad(),this.validateRequired(this.component._required)}}class p extends u{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;if(Array.isArray(o)&&o.length>0){this.keyOptionMap.clear();const t=o.map(t=>{var e;return"object"==typeof t&&null!==t&&"string"==typeof t.label?Object.assign(Object.assign({},t),{value:null!==(e=t.value)&&void 0!==e?e:t.label}):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,s(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};