@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
4 lines • 3.02 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import{m as a11yHint,G as watchJsonArrayString,s as setState}from"./common-BXXICkFX.js";import{b as hasEnoughReadableChars,c as containsOnlyNumbers}from"./label-Dkj9sxQK.js";import{v as validateRequired}from"./required-IJ-wNQGn.js";import{v as validateOrientation}from"./orientation-uIK98CL3.js";import{I as InputController}from"./FormFieldStateWrapper-COm9oJpc.js";const validateInputSelectOptions=t=>{if("object"==typeof t&&null!==t){if("string"==typeof t.label&&t.label.length>0)return t.disabled=!0===t.disabled,t.label=`${t.label}`.trim(),!1===hasEnoughReadableChars(t.label,3)&&!1===containsOnlyNumbers(t.label)&&a11yHint(`A differing Aria-Label (${t.label}) is inaccessible. A differing Aria-Label should consist of at least three readable characters.`),!Array.isArray(t.options)||void 0===t.options.find(t=>!1===validateInputSelectOptions(t));if("number"==typeof t.label)return!0}return!1},validateOptions=(t,e,a={})=>{watchJsonArrayString(t,"_options",t=>"object"==typeof t&&null!==t&&"string"==typeof t.label&&t.label.length>0,e,void 0,a)},validateOptionsWithOptgroup=(t,e,a={})=>{watchJsonArrayString(t,"_options",validateInputSelectOptions,e,void 0,a)},fillKeyOptionMap=(t,e,a="")=>{e.forEach((e,o)=>{const i=`${a}-${o}`;"object"==typeof e&&null!==e&&"string"==typeof e.label&&e.label.length>0&&(Array.isArray(e.options)?fillKeyOptionMap(t,e.options,i):t.set(i,e))})};class InputCheckboxRadioController extends InputController{constructor(t,e,a){super(t,e,a),this.component=t}validateRequired(t){validateRequired(this.component,t)}componentWillLoad(){super.componentWillLoad(),this.validateRequired(this.component._required)}}class InputRadioController extends InputCheckboxRadioController{constructor(t,e,a){super(t,e,a),this.keyOptionMap=new Map,this.getOptionByKey=t=>this.keyOptionMap.get(t),this.afterPatchOptions=(t,e,a,o)=>{"_value"===o&&this.setFormAssociatedValue(t)},this.beforePatchOptions=(t,e)=>{const a=e.has("_options")?e.get("_options"):this.component.state._options;if(Array.isArray(a)&&a.length>0){this.keyOptionMap.clear();const t=a.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});fillKeyOptionMap(this.keyOptionMap,t)}},this.component=t}validateOrientation(t){validateOrientation(this.component,t,"vertical")}validateOptions(t){validateOptions(this.component,t,{hooks:{afterPatch:this.afterPatchOptions,beforePatch:this.beforePatchOptions}})}validateValue(t){t=Array.isArray(t)?t[0]:t,setState(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{InputCheckboxRadioController as I,InputRadioController as a,validateOptions as b,fillKeyOptionMap as f,validateOptionsWithOptgroup as v};