@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
4 lines • 34.8 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import{proxyCustomElement,HTMLElement,h,Fragment}from"@stencil/core/internal/client";import{c as clsx}from"./clsx.js";import{e as KolIconTag,a as KolTooltipWcTag,d as KolButtonWcTag,t as KolTableSettingsWcTag}from"./component-names.js";import{t as translate}from"./i18n.js";import{Q as emptyStringByArrayHandler,o as objectObjectHandler,p as parseJson,w as watchValidator,s as setState}from"./common.js";import{b as validateHasSettingsMenu,v as validateTableData,a as validateTableDataFoot,e as validateTableCallbacks,c as validateTableSelection}from"./table-selection.js";import{v as validateLabel}from"./label.js";import{C as Callback}from"./keyboard.js";import{n as nonce}from"./dev.utils.js";import{d as dispatchDomEvent,K as KolEvent}from"./events.js";import{i as isObject,c as baseGetTag,r as root,a as isObjectLike,f as freeGlobal,b as isArray,S as Symbol}from"./isObject.js";const validateTableHeaderCells=(e,t)=>{emptyStringByArrayHandler(t,()=>{objectObjectHandler(t,()=>{try{t=parseJson(t)}catch(e){}watchValidator(e,"_headerCells",e=>{var t,a;return"object"==typeof e&&null!==e&&(void 0===e.horizontal||Array.isArray(e.horizontal)&&void 0===e.horizontal.find(e=>!Array.isArray(e)))&&(void 0===e.vertical||Array.isArray(e.vertical)&&void 0===e.vertical.find(e=>!Array.isArray(e)))&&[...null!==(t=e.horizontal)&&void 0!==t?t:[],...null!==(a=e.vertical)&&void 0!==a?a:[]].flat().every(e=>void 0===e.width||"number"==typeof e.width)&&!0},new Set(["TableHeaderCellsPropType"]),t)})})};var asyncTag="[object AsyncFunction]",funcTag$1="[object Function]",genTag="[object GeneratorFunction]",proxyTag="[object Proxy]";function isFunction(e){if(!isObject(e))return!1;var t=baseGetTag(e);return t==funcTag$1||t==genTag||t==asyncTag||t==proxyTag}var coreJsData=root["__core-js_shared__"],maskSrcKey=function(){var e=/[^.]+$/.exec(coreJsData&&coreJsData.keys&&coreJsData.keys.IE_PROTO||"");return e?"Symbol(src)_1."+e:""}();function isMasked(e){return!!maskSrcKey&&maskSrcKey in e}var funcProto$1=Function.prototype,funcToString$1=funcProto$1.toString;function toSource(e){if(null!=e){try{return funcToString$1.call(e)}catch(e){}try{return e+""}catch(e){}}return""}var reRegExpChar=/[\\^$.*+?()[\]{}|]/g,reIsHostCtor=/^\[object .+?Constructor\]$/,funcProto=Function.prototype,objectProto$9=Object.prototype,funcToString=funcProto.toString,hasOwnProperty$7=objectProto$9.hasOwnProperty,reIsNative=RegExp("^"+funcToString.call(hasOwnProperty$7).replace(reRegExpChar,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function baseIsNative(e){return!(!isObject(e)||isMasked(e))&&(isFunction(e)?reIsNative:reIsHostCtor).test(toSource(e))}function getValue(e,t){return null==e?void 0:e[t]}function getNative(e,t){var a=getValue(e,t);return baseIsNative(a)?a:void 0}var WeakMap=getNative(root,"WeakMap"),MAX_SAFE_INTEGER$1=9007199254740991,reIsUint=/^(?:0|[1-9]\d*)$/;function isIndex(e,t){var a=typeof e;return!!(t=null==t?MAX_SAFE_INTEGER$1:t)&&("number"==a||"symbol"!=a&&reIsUint.test(e))&&e>-1&&e%1==0&&e<t}function eq(e,t){return e===t||e!=e&&t!=t}var MAX_SAFE_INTEGER=9007199254740991;function isLength(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=MAX_SAFE_INTEGER}function isArrayLike(e){return null!=e&&isLength(e.length)&&!isFunction(e)}var objectProto$8=Object.prototype;function isPrototype(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||objectProto$8)}function baseTimes(e,t){for(var a=-1,r=Array(e);++a<e;)r[a]=t(a);return r}var argsTag$2="[object Arguments]";function baseIsArguments(e){return isObjectLike(e)&&baseGetTag(e)==argsTag$2}var objectProto$7=Object.prototype,hasOwnProperty$6=objectProto$7.hasOwnProperty,propertyIsEnumerable$1=objectProto$7.propertyIsEnumerable,isArguments=baseIsArguments(function(){return arguments}())?baseIsArguments:function(e){return isObjectLike(e)&&hasOwnProperty$6.call(e,"callee")&&!propertyIsEnumerable$1.call(e,"callee")};function stubFalse(){return!1}var freeExports$1="object"==typeof exports&&exports&&!exports.nodeType&&exports,freeModule$1=freeExports$1&&"object"==typeof module&&module&&!module.nodeType&&module,moduleExports$1=freeModule$1&&freeModule$1.exports===freeExports$1,Buffer=moduleExports$1?root.Buffer:void 0,nativeIsBuffer=Buffer?Buffer.isBuffer:void 0,isBuffer=nativeIsBuffer||stubFalse,argsTag$1="[object Arguments]",arrayTag$1="[object Array]",boolTag$1="[object Boolean]",dateTag$1="[object Date]",errorTag$1="[object Error]",funcTag="[object Function]",mapTag$2="[object Map]",numberTag$1="[object Number]",objectTag$2="[object Object]",regexpTag$1="[object RegExp]",setTag$2="[object Set]",stringTag$1="[object String]",weakMapTag$1="[object WeakMap]",arrayBufferTag$1="[object ArrayBuffer]",dataViewTag$2="[object DataView]",float32Tag="[object Float32Array]",float64Tag="[object Float64Array]",int8Tag="[object Int8Array]",int16Tag="[object Int16Array]",int32Tag="[object Int32Array]",uint8Tag="[object Uint8Array]",uint8ClampedTag="[object Uint8ClampedArray]",uint16Tag="[object Uint16Array]",uint32Tag="[object Uint32Array]",typedArrayTags={};function baseIsTypedArray(e){return isObjectLike(e)&&isLength(e.length)&&!!typedArrayTags[baseGetTag(e)]}function baseUnary(e){return function(t){return e(t)}}typedArrayTags[float32Tag]=typedArrayTags[float64Tag]=typedArrayTags[int8Tag]=typedArrayTags[int16Tag]=typedArrayTags[int32Tag]=typedArrayTags[uint8Tag]=typedArrayTags[uint8ClampedTag]=typedArrayTags[uint16Tag]=typedArrayTags[uint32Tag]=!0,typedArrayTags[argsTag$1]=typedArrayTags[arrayTag$1]=typedArrayTags[arrayBufferTag$1]=typedArrayTags[boolTag$1]=typedArrayTags[dataViewTag$2]=typedArrayTags[dateTag$1]=typedArrayTags[errorTag$1]=typedArrayTags[funcTag]=typedArrayTags[mapTag$2]=typedArrayTags[numberTag$1]=typedArrayTags[objectTag$2]=typedArrayTags[regexpTag$1]=typedArrayTags[setTag$2]=typedArrayTags[stringTag$1]=typedArrayTags[weakMapTag$1]=!1;var freeExports="object"==typeof exports&&exports&&!exports.nodeType&&exports,freeModule=freeExports&&"object"==typeof module&&module&&!module.nodeType&&module,moduleExports=freeModule&&freeModule.exports===freeExports,freeProcess=moduleExports&&freeGlobal.process,nodeUtil=function(){try{var e=freeModule&&freeModule.require&&freeModule.require("util").types;return e||freeProcess&&freeProcess.binding&&freeProcess.binding("util")}catch(e){}}(),nodeIsTypedArray=nodeUtil&&nodeUtil.isTypedArray,isTypedArray=nodeIsTypedArray?baseUnary(nodeIsTypedArray):baseIsTypedArray,objectProto$6=Object.prototype,hasOwnProperty$5=objectProto$6.hasOwnProperty;function arrayLikeKeys(e,t){var a=isArray(e),r=!a&&isArguments(e),o=!a&&!r&&isBuffer(e),s=!a&&!r&&!o&&isTypedArray(e),l=a||r||o||s,n=l?baseTimes(e.length,String):[],i=n.length;for(var c in e)!hasOwnProperty$5.call(e,c)||l&&("length"==c||o&&("offset"==c||"parent"==c)||s&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||isIndex(c,i))||n.push(c);return n}function overArg(e,t){return function(a){return e(t(a))}}var nativeKeys=overArg(Object.keys,Object),objectProto$5=Object.prototype,hasOwnProperty$4=objectProto$5.hasOwnProperty;function baseKeys(e){if(!isPrototype(e))return nativeKeys(e);var t=[];for(var a in Object(e))hasOwnProperty$4.call(e,a)&&"constructor"!=a&&t.push(a);return t}function keys(e){return isArrayLike(e)?arrayLikeKeys(e):baseKeys(e)}var nativeCreate=getNative(Object,"create");function hashClear(){this.__data__=nativeCreate?nativeCreate(null):{},this.size=0}function hashDelete(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t}var HASH_UNDEFINED$2="__lodash_hash_undefined__",objectProto$4=Object.prototype,hasOwnProperty$3=objectProto$4.hasOwnProperty;function hashGet(e){var t=this.__data__;if(nativeCreate){var a=t[e];return a===HASH_UNDEFINED$2?void 0:a}return hasOwnProperty$3.call(t,e)?t[e]:void 0}var objectProto$3=Object.prototype,hasOwnProperty$2=objectProto$3.hasOwnProperty;function hashHas(e){var t=this.__data__;return nativeCreate?void 0!==t[e]:hasOwnProperty$2.call(t,e)}var HASH_UNDEFINED$1="__lodash_hash_undefined__";function hashSet(e,t){var a=this.__data__;return this.size+=this.has(e)?0:1,a[e]=nativeCreate&&void 0===t?HASH_UNDEFINED$1:t,this}function Hash(e){var t=-1,a=null==e?0:e.length;for(this.clear();++t<a;){var r=e[t];this.set(r[0],r[1])}}function listCacheClear(){this.__data__=[],this.size=0}function assocIndexOf(e,t){for(var a=e.length;a--;)if(eq(e[a][0],t))return a;return-1}Hash.prototype.clear=hashClear,Hash.prototype.delete=hashDelete,Hash.prototype.get=hashGet,Hash.prototype.has=hashHas,Hash.prototype.set=hashSet;var arrayProto=Array.prototype,splice=arrayProto.splice;function listCacheDelete(e){var t=this.__data__,a=assocIndexOf(t,e);return!(a<0)&&(a==t.length-1?t.pop():splice.call(t,a,1),--this.size,!0)}function listCacheGet(e){var t=this.__data__,a=assocIndexOf(t,e);return a<0?void 0:t[a][1]}function listCacheHas(e){return assocIndexOf(this.__data__,e)>-1}function listCacheSet(e,t){var a=this.__data__,r=assocIndexOf(a,e);return r<0?(++this.size,a.push([e,t])):a[r][1]=t,this}function ListCache(e){var t=-1,a=null==e?0:e.length;for(this.clear();++t<a;){var r=e[t];this.set(r[0],r[1])}}ListCache.prototype.clear=listCacheClear,ListCache.prototype.delete=listCacheDelete,ListCache.prototype.get=listCacheGet,ListCache.prototype.has=listCacheHas,ListCache.prototype.set=listCacheSet;var Map$1=getNative(root,"Map");function mapCacheClear(){this.size=0,this.__data__={hash:new Hash,map:new(Map$1||ListCache),string:new Hash}}function isKeyable(e){var t=typeof e;return"string"==t||"number"==t||"symbol"==t||"boolean"==t?"__proto__"!==e:null===e}function getMapData(e,t){var a=e.__data__;return isKeyable(t)?a["string"==typeof t?"string":"hash"]:a.map}function mapCacheDelete(e){var t=getMapData(this,e).delete(e);return this.size-=t?1:0,t}function mapCacheGet(e){return getMapData(this,e).get(e)}function mapCacheHas(e){return getMapData(this,e).has(e)}function mapCacheSet(e,t){var a=getMapData(this,e),r=a.size;return a.set(e,t),this.size+=a.size==r?0:1,this}function MapCache(e){var t=-1,a=null==e?0:e.length;for(this.clear();++t<a;){var r=e[t];this.set(r[0],r[1])}}function arrayPush(e,t){for(var a=-1,r=t.length,o=e.length;++a<r;)e[o+a]=t[a];return e}function stackClear(){this.__data__=new ListCache,this.size=0}function stackDelete(e){var t=this.__data__,a=t.delete(e);return this.size=t.size,a}function stackGet(e){return this.__data__.get(e)}function stackHas(e){return this.__data__.has(e)}MapCache.prototype.clear=mapCacheClear,MapCache.prototype.delete=mapCacheDelete,MapCache.prototype.get=mapCacheGet,MapCache.prototype.has=mapCacheHas,MapCache.prototype.set=mapCacheSet;var LARGE_ARRAY_SIZE=200;function stackSet(e,t){var a=this.__data__;if(a instanceof ListCache){var r=a.__data__;if(!Map$1||r.length<LARGE_ARRAY_SIZE-1)return r.push([e,t]),this.size=++a.size,this;a=this.__data__=new MapCache(r)}return a.set(e,t),this.size=a.size,this}function Stack(e){var t=this.__data__=new ListCache(e);this.size=t.size}function arrayFilter(e,t){for(var a=-1,r=null==e?0:e.length,o=0,s=[];++a<r;){var l=e[a];t(l,a,e)&&(s[o++]=l)}return s}function stubArray(){return[]}Stack.prototype.clear=stackClear,Stack.prototype.delete=stackDelete,Stack.prototype.get=stackGet,Stack.prototype.has=stackHas,Stack.prototype.set=stackSet;var objectProto$2=Object.prototype,propertyIsEnumerable=objectProto$2.propertyIsEnumerable,nativeGetSymbols=Object.getOwnPropertySymbols,getSymbols=nativeGetSymbols?function(e){return null==e?[]:(e=Object(e),arrayFilter(nativeGetSymbols(e),function(t){return propertyIsEnumerable.call(e,t)}))}:stubArray;function baseGetAllKeys(e,t,a){var r=t(e);return isArray(e)?r:arrayPush(r,a(e))}function getAllKeys(e){return baseGetAllKeys(e,keys,getSymbols)}var DataView=getNative(root,"DataView"),Promise$1=getNative(root,"Promise"),Set$1=getNative(root,"Set"),mapTag$1="[object Map]",objectTag$1="[object Object]",promiseTag="[object Promise]",setTag$1="[object Set]",weakMapTag="[object WeakMap]",dataViewTag$1="[object DataView]",dataViewCtorString=toSource(DataView),mapCtorString=toSource(Map$1),promiseCtorString=toSource(Promise$1),setCtorString=toSource(Set$1),weakMapCtorString=toSource(WeakMap),getTag=baseGetTag;(DataView&&getTag(new DataView(new ArrayBuffer(1)))!=dataViewTag$1||Map$1&&getTag(new Map$1)!=mapTag$1||Promise$1&&getTag(Promise$1.resolve())!=promiseTag||Set$1&&getTag(new Set$1)!=setTag$1||WeakMap&&getTag(new WeakMap)!=weakMapTag)&&(getTag=function(e){var t=baseGetTag(e),a=t==objectTag$1?e.constructor:void 0,r=a?toSource(a):"";if(r)switch(r){case dataViewCtorString:return dataViewTag$1;case mapCtorString:return mapTag$1;case promiseCtorString:return promiseTag;case setCtorString:return setTag$1;case weakMapCtorString:return weakMapTag}return t});var Uint8Array=root.Uint8Array,HASH_UNDEFINED="__lodash_hash_undefined__";function setCacheAdd(e){return this.__data__.set(e,HASH_UNDEFINED),this}function setCacheHas(e){return this.__data__.has(e)}function SetCache(e){var t=-1,a=null==e?0:e.length;for(this.__data__=new MapCache;++t<a;)this.add(e[t])}function arraySome(e,t){for(var a=-1,r=null==e?0:e.length;++a<r;)if(t(e[a],a,e))return!0;return!1}function cacheHas(e,t){return e.has(t)}SetCache.prototype.add=SetCache.prototype.push=setCacheAdd,SetCache.prototype.has=setCacheHas;var COMPARE_PARTIAL_FLAG$3=1,COMPARE_UNORDERED_FLAG$1=2;function equalArrays(e,t,a,r,o,s){var l=a&COMPARE_PARTIAL_FLAG$3,n=e.length,i=t.length;if(n!=i&&!(l&&i>n))return!1;var c=s.get(e),h=s.get(t);if(c&&h)return c==t&&h==e;var d=-1,u=!0,b=a&COMPARE_UNORDERED_FLAG$1?new SetCache:void 0;for(s.set(e,t),s.set(t,e);++d<n;){var p=e[d],y=t[d];if(r)var g=l?r(y,p,d,t,e,s):r(p,y,d,e,t,s);if(void 0!==g){if(g)continue;u=!1;break}if(b){if(!arraySome(t,function(e,t){if(!cacheHas(b,t)&&(p===e||o(p,e,a,r,s)))return b.push(t)})){u=!1;break}}else if(p!==y&&!o(p,y,a,r,s)){u=!1;break}}return s.delete(e),s.delete(t),u}function mapToArray(e){var t=-1,a=Array(e.size);return e.forEach(function(e,r){a[++t]=[r,e]}),a}function setToArray(e){var t=-1,a=Array(e.size);return e.forEach(function(e){a[++t]=e}),a}var COMPARE_PARTIAL_FLAG$2=1,COMPARE_UNORDERED_FLAG=2,boolTag="[object Boolean]",dateTag="[object Date]",errorTag="[object Error]",mapTag="[object Map]",numberTag="[object Number]",regexpTag="[object RegExp]",setTag="[object Set]",stringTag="[object String]",symbolTag="[object Symbol]",arrayBufferTag="[object ArrayBuffer]",dataViewTag="[object DataView]",symbolProto=Symbol?Symbol.prototype:void 0,symbolValueOf=symbolProto?symbolProto.valueOf:void 0;function equalByTag(e,t,a,r,o,s,l){switch(a){case dataViewTag:if(e.byteLength!=t.byteLength||e.byteOffset!=t.byteOffset)return!1;e=e.buffer,t=t.buffer;case arrayBufferTag:return!(e.byteLength!=t.byteLength||!s(new Uint8Array(e),new Uint8Array(t)));case boolTag:case dateTag:case numberTag:return eq(+e,+t);case errorTag:return e.name==t.name&&e.message==t.message;case regexpTag:case stringTag:return e==t+"";case mapTag:var n=mapToArray;case setTag:var i=r&COMPARE_PARTIAL_FLAG$2;if(n||(n=setToArray),e.size!=t.size&&!i)return!1;var c=l.get(e);if(c)return c==t;r|=COMPARE_UNORDERED_FLAG,l.set(e,t);var h=equalArrays(n(e),n(t),r,o,s,l);return l.delete(e),h;case symbolTag:if(symbolValueOf)return symbolValueOf.call(e)==symbolValueOf.call(t)}return!1}var COMPARE_PARTIAL_FLAG$1=1,objectProto$1=Object.prototype,hasOwnProperty$1=objectProto$1.hasOwnProperty;function equalObjects(e,t,a,r,o,s){var l=a&COMPARE_PARTIAL_FLAG$1,n=getAllKeys(e),i=n.length;if(i!=getAllKeys(t).length&&!l)return!1;for(var c=i;c--;){var h=n[c];if(!(l?h in t:hasOwnProperty$1.call(t,h)))return!1}var d=s.get(e),u=s.get(t);if(d&&u)return d==t&&u==e;var b=!0;s.set(e,t),s.set(t,e);for(var p=l;++c<i;){var y=e[h=n[c]],g=t[h];if(r)var f=l?r(g,y,h,t,e,s):r(y,g,h,e,t,s);if(!(void 0===f?y===g||o(y,g,a,r,s):f)){b=!1;break}p||(p="constructor"==h)}if(b&&!p){var _=e.constructor,v=t.constructor;_==v||!("constructor"in e)||!("constructor"in t)||"function"==typeof _&&_ instanceof _&&"function"==typeof v&&v instanceof v||(b=!1)}return s.delete(e),s.delete(t),b}var COMPARE_PARTIAL_FLAG=1,argsTag="[object Arguments]",arrayTag="[object Array]",objectTag="[object Object]",objectProto=Object.prototype,hasOwnProperty=objectProto.hasOwnProperty;function baseIsEqualDeep(e,t,a,r,o,s){var l=isArray(e),n=isArray(t),i=l?arrayTag:getTag(e),c=n?arrayTag:getTag(t),h=(i=i==argsTag?objectTag:i)==objectTag,d=(c=c==argsTag?objectTag:c)==objectTag,u=i==c;if(u&&isBuffer(e)){if(!isBuffer(t))return!1;l=!0,h=!1}if(u&&!h)return s||(s=new Stack),l||isTypedArray(e)?equalArrays(e,t,a,r,o,s):equalByTag(e,t,i,a,r,o,s);if(!(a&COMPARE_PARTIAL_FLAG)){var b=h&&hasOwnProperty.call(e,"__wrapped__"),p=d&&hasOwnProperty.call(t,"__wrapped__");if(b||p){var y=b?e.value():e,g=p?t.value():t;return s||(s=new Stack),o(y,g,a,r,s)}}return!!u&&(s||(s=new Stack),equalObjects(e,t,a,r,o,s))}function baseIsEqual(e,t,a,r,o){return e===t||(null==e||null==t||!isObjectLike(e)&&!isObjectLike(t)?e!=e&&t!=t:baseIsEqualDeep(e,t,a,r,baseIsEqual,o))}function isEqual(e,t){return baseIsEqual(e,t)}const KolTableStateless=proxyCustomElement(class extends HTMLElement{constructor(e){super(),!1!==e&&this.__registerHost(),this.translateNoEntries=translate("kol-no-entries"),this.state={_data:[],_headerCells:{horizontal:[],vertical:[]},_label:"",_hasSettingsMenu:!1},this.horizontal=!0,this.cellsToRenderTimeouts=new Map,this.dataToKeyMap=new Map,this.checkboxRefs=[],this.translateSort=translate("kol-sort"),this.translateSortOrder=translate("kol-table-sort-order"),this.tableDivElementHasScrollbar=!1,this.renderTableRow=(e,t,a,r=!1)=>{var o,s;let l=String(t);return this.horizontal&&(null===(o=e[0])||void 0===o?void 0:o.data)&&(l=null!==(s=this.getDataKey(e[0].data))&&void 0!==s?s:l),h("tr",{class:clsx("kol-table__row",{"kol-table__row--body":!r,"kol-table__row--footer":r}),key:`row-${l}`},this.renderSelectionCell(e,t),e.map((e,r)=>this.renderTableCell(e,t,r,a)))},this.renderTableCell=(e,t,a,r)=>{if(!1===e.visible)return"";let o=`${t}-${a}-${e.label}`;if(e.data){const r=this.getDataKey(e.data);o=r?`${r}-${this.horizontal?a:t}`:o}if(e.headerCell)return this.renderHeadingCell(e,t,a,r);{const t="function"!=typeof e.render&&e.label===this.translateNoEntries;return h("td",{key:`cell-${o}`,class:clsx("kol-table__cell kol-table__cell--body",{[`kol-table__cell--align-${e.textAlign}`]:e.textAlign}),"aria-atomic":t?"false":void 0,"aria-live":t?"polite":void 0,"aria-relevant":t?"text":void 0,colSpan:e.colSpan,rowSpan:e.rowSpan,style:{textAlign:e.textAlign},ref:"function"==typeof e.render?t=>{this.cellRender(e,t)}:void 0},"function"!=typeof e.render?e.label:"")}}}validateHasSettingsMenu(e){validateHasSettingsMenu(this,e)}validateData(e){validateTableData(this,e,{beforePatch:e=>{this.updateDataToKeyMap(e)}})}validateDataFoot(e){validateTableDataFoot(this,e)}validateHeaderCells(e){validateTableHeaderCells(this,e),isEqual(this.previousHeaderCells,this.state._headerCells)||this.initializeHeaderCellSettings(),this.previousHeaderCells=this.state._headerCells}validateLabel(e){validateLabel(this,e,{required:!0})}validateOn(e){validateTableCallbacks(this,e)}validateSelection(e){validateTableSelection(this,e)}handleKeyDown(e){var t;if("ArrowUp"===e.key||"ArrowDown"===e.key){const a=null===(t=this.tableDivElement)||void 0===t?void 0:t.querySelector(":focus");let r=this.checkboxRefs.indexOf(a);r>-1&&(e.preventDefault(),"ArrowDown"===e.key?(r=(r+1)%this.checkboxRefs.length,this.checkboxRefs[r].focus()):"ArrowUp"===e.key&&(e.preventDefault(),r=(r+this.checkboxRefs.length-1)%this.checkboxRefs.length,this.checkboxRefs[r].focus()))}}componentDidRender(){this.checkDivElementScrollbar()}componentDidLoad(){this.tableDivElement&&ResizeObserver&&(this.tableDivElementResizeObserver=new ResizeObserver(this.checkDivElementScrollbar.bind(this)),this.tableDivElementResizeObserver.observe(this.tableDivElement))}handleSettingsChange(e){var t;const a=Object.assign(Object.assign({},this.state._headerCells),{horizontal:e.detail});setState(this,"_headerCells",a),"function"==typeof(null===(t=this.state._on)||void 0===t?void 0:t[Callback.onChangeHeaderCells])&&this.state._on[Callback.onChangeHeaderCells](e,a)}disconnectedCallback(){var e;null===(e=this.tableDivElementResizeObserver)||void 0===e||e.disconnect()}checkDivElementScrollbar(){this.tableDivElement&&(this.tableDivElementHasScrollbar=this.tableDivElement.scrollWidth>this.tableDivElement.clientWidth)}updateDataToKeyMap(e){e.forEach(e=>{this.dataToKeyMap.has(e)||this.dataToKeyMap.set(e,nonce())}),this.dataToKeyMap.forEach((t,a)=>{e.includes(a)||this.dataToKeyMap.delete(a)})}getDataKey(e){return this.dataToKeyMap.get(e)}cellRender(e,t){t&&(clearTimeout(this.cellsToRenderTimeouts.get(t)),this.cellsToRenderTimeouts.set(t,setTimeout(()=>{if("function"==typeof e.render){const a=e.render(t,e,e.data,this.state._data);"string"==typeof a&&(t.textContent=a)}})))}getNumberOfCols(e,t){let a=0;return e.forEach(e=>{let t=0;Array.isArray(e)&&e.forEach(e=>{var a;return t+=null!==(a=e.colSpan)&&void 0!==a?a:1}),a<t&&(a=t)}),0===a&&(a=t.length),a}getNumberOfRows(e,t){var a;let r=0;return e.forEach(e=>{let t=0;Array.isArray(e)&&e.forEach(e=>{var a;return t+=null!==(a=e.rowSpan)&&void 0!==a?a:1}),r<t&&(r=t)}),0===r?r=t.length:r-=(null===(a=this.state._dataFoot)||void 0===a?void 0:a.length)||0,r}getThePrimaryHeadersWithKeyOrRenderFunction(e){const t=[];return e.forEach(e=>{e.forEach(e=>{"string"!=typeof e.key&&"function"!=typeof e.render||t.push(e)})}),t}getPrimaryHeaders(e){var t,a;let r=this.getThePrimaryHeadersWithKeyOrRenderFunction(null!==(t=e.horizontal)&&void 0!==t?t:[]);return this.horizontal=!0,0===r.length&&(r=this.getThePrimaryHeadersWithKeyOrRenderFunction(null!==(a=e.vertical)&&void 0!==a?a:[]),r.length>0&&(this.horizontal=!1)),r}createDataField(e,t,a){var r;t.horizontal=Array.isArray(null==t?void 0:t.horizontal)?t.horizontal:[],t.vertical=Array.isArray(null==t?void 0:t.vertical)?t.vertical:[];const o=this.getPrimaryHeaders(t),s=this.getNumberOfCols(t.horizontal,e);let l=this.getNumberOfRows(t.vertical,e),n=0;a&&(n=l,l+=(null===(r=this.state._dataFoot)||void 0===r?void 0:r.length)||0);const i=[],c=[],h=[];t.vertical.forEach((e,t)=>{c[t]=0,h[t]=[]});const d=o;for(let r=n;r<l;r++){const o=[];t.vertical.forEach((e,t)=>{let a=0;if(h[t].forEach(e=>a+=e),a<=r){const s=e[r-a+c[t]];if("object"==typeof s){o.push(Object.assign(Object.assign({},s),{headerCell:!0,data:{}}));let e=1;if("number"==typeof s.rowSpan&&s.rowSpan>1&&(e=s.rowSpan),h[t].push(e),"number"==typeof s.colSpan&&s.colSpan>1)for(let a=1;a<s.colSpan;a++)h[t+a].push(e);c[t]++}}});for(let t=0;t<s;t++)if(!0===this.horizontal){const s=a&&this.state._dataFoot?this.state._dataFoot[r-n]:e[r];"object"!=typeof d[t]||null===d[t]||"object"!=typeof s||null===s||"string"!=typeof d[t].key&&"function"!=typeof d[t].render||o.push(Object.assign(Object.assign({},d[t]),{colSpan:void 0,rowSpan:void 0,data:s,label:s[d[t].key]}))}else"object"!=typeof d[r]||null===d[r]||"object"!=typeof e[t]||null===e[t]||"string"!=typeof d[r].key&&"function"!=typeof d[r].render||o.push(Object.assign(Object.assign({},d[r]),{colSpan:void 0,rowSpan:void 0,data:e[t],label:e[t][d[r].key]}));i.push(o)}if(0===e.length){let e=0,a=0;Array.isArray(t.horizontal)&&t.horizontal.length>0&&t.horizontal[0].forEach(t=>{e+=t.colSpan||1}),Array.isArray(t.vertical)&&t.vertical.length>0&&(e-=t.vertical.length,t.vertical[0].forEach(e=>{a+=e.rowSpan||1}));const r={colSpan:e,label:this.translateNoEntries,render:void 0,rowSpan:Math.max(a,1)};0===i.length?i.push([r]):i[0].push(r)}return i}handleSelectionChangeCallbackAndEvent(e,t){var a;"function"==typeof(null===(a=this.state._on)||void 0===a?void 0:a[Callback.onSelectionChange])&&this.state._on[Callback.onSelectionChange](e,t),this.host&&dispatchDomEvent(this.host,KolEvent.selectionChange,t)}initializeHeaderCellSettings(){if(this.state._headerCells&&this.state._headerCells.horizontal&&this.state._headerCells.horizontal.length>0){const e=Object.assign(Object.assign({},this.state._headerCells),{horizontal:this.state._headerCells.horizontal.map(e=>e.map(e=>Object.assign(Object.assign({},e),{visible:"boolean"!=typeof e.visible||e.visible,hidable:"boolean"!=typeof e.hidable||e.hidable})))});setState(this,"_headerCells",e)}}componentWillLoad(){this.validateData(this._data),this.validateDataFoot(this._dataFoot),this.validateHeaderCells(this._headerCells),this.validateLabel(this._label),this.validateOn(this._on),this.validateSelection(this._selection),this.validateHasSettingsMenu(this._hasSettingsMenu)}renderSelectionCell(e,t){var a;const r=this.state._selection;if(!r)return"";const o=this.getSelectionKeyPropertyName(),s=null===(a=e[0])||void 0===a?void 0:a.data;if(!s)return"";const l=s[o],n=r.multiple||void 0===r.multiple,i=(()=>{const e=null==r?void 0:r.selectedKeys;return(void 0===e?[]:Array.isArray(e)?e:[e]).some(e=>String(e)===String(l))})(),c=(()=>{const e=null==r?void 0:r.disabledKeys;return(void 0===e?[]:Array.isArray(e)?e:[e]).some(e=>String(e)===String(l))})(),d=r.label(s),u={name:"selection",checked:i,disabled:c,id:String(l),"aria-label":d};return h("td",{key:`tbody-${t}-selection`,class:"kol-table__cell kol-table__cell--selection"},h("div",{class:clsx("kol-table__selection",{"kol-table__selection--checked":i})},n?h("label",{class:clsx("kol-table__selection-label",{"kol-table__selection-label--disabled":c})},h(KolIconTag,{class:"kol-table__selection-icon",_icons:"kolicon "+(i?"kolicon-check":""),_label:""}),h("input",Object.assign({class:clsx("kol-table__selection-input kol-table__selection-input--checkbox"),ref:e=>e&&this.checkboxRefs.push(e)},u,{type:"checkbox",onInput:e=>{const t=(()=>{const e=null==r?void 0:r.selectedKeys;return void 0===e?[]:Array.isArray(e)?e:[e]})(),a=i?t.filter(e=>String(e)!==String(l)):[...t,l];this.handleSelectionChangeCallbackAndEvent(e,null!=a?a:[])}}))):h("label",{class:"kol-table__selection-label"},h("input",Object.assign({class:clsx("kol-table__selection-input kol-table__selection-input--radio")},u,{type:"radio",onInput:e=>{this.handleSelectionChangeCallbackAndEvent(e,[l])}}))),h(KolTooltipWcTag,{"aria-hidden":"true",class:"kol-table__selection-input-tooltip",_align:"right",_id:`${l}-label`,_label:d})))}getSelectionKeyPropertyName(){var e,t;return null!==(t=null===(e=this.state._selection)||void 0===e?void 0:e.keyPropertyName)&&void 0!==t?t:"id"}getDataWithSelectionEnabled(){const e=this.getSelectionKeyPropertyName();return this.state._data.filter(t=>{var a;const r=null===(a=this.state._selection)||void 0===a?void 0:a.disabledKeys;return!(void 0===r?[]:Array.isArray(r)?r:[r]).some(a=>String(a)===String(t[e]))})}getSelectedKeysWithoutDisabledKeys(){const e=(()=>{var e;const t=null===(e=this.state._selection)||void 0===e?void 0:e.selectedKeys;return void 0===t?[]:Array.isArray(t)?t:[t]})(),t=(()=>{var e;const t=null===(e=this.state._selection)||void 0===e?void 0:e.disabledKeys;return void 0===t?[]:Array.isArray(t)?t:[t]})();return e.filter(e=>!t.some(t=>String(t)===String(e)))}getSelectedKeysWithDisabledKeysOnly(){const e=(()=>{var e;const t=null===(e=this.state._selection)||void 0===e?void 0:e.selectedKeys;return void 0===t?[]:Array.isArray(t)?t:[t]})(),t=(()=>{var e;const t=null===(e=this.state._selection)||void 0===e?void 0:e.disabledKeys;return void 0===t?[]:Array.isArray(t)?t:[t]})();return e.filter(e=>t.some(t=>String(t)===String(e)))}getRevertedSelection(e){var t;const a=this.getSelectionKeyPropertyName(),r=null!==(t=this.getSelectedKeysWithDisabledKeysOnly())&&void 0!==t?t:[];return e&&r.push(...this.getDataWithSelectionEnabled().map(e=>null==e?void 0:e[a])),r}getTableMinWidth(){var e,t;const a=null!==(e=this.state._headerCells.horizontal)&&void 0!==e?e:[],r=[];a.forEach(e=>{e.forEach(e=>{!1!==e.visible&&void 0!==e.width&&e.width>0&&r.push(e.width)})});const o=null!==(t=this.state._headerCells.vertical)&&void 0!==t?t:[],s=[];o.forEach(e=>{e.forEach(e=>{void 0!==e.width&&e.width>0&&s.push(e.width)})});const l=[...s,...r];return 0===l.length?"0px":1===l.length?`${l[0]}px`:`calc(${l.map(e=>`${e}px`).join(" + ")})`}renderHeadingSelectionCell(){var e,t;const a=this.state._selection;if(!a)return h("td",{class:"kol-table__cell kol-table__cell--header",key:"thead-0"});if(!1===a.multiple)return h("td",{key:"thead-0-selection",class:"kol-table__cell kol-table__cell--header kol-table__cell--selection"});const r=null!==(t=null===(e=this.getSelectedKeysWithoutDisabledKeys())||void 0===e?void 0:e.length)&&void 0!==t?t:0,o=r===this.getDataWithSelectionEnabled().length,s=0!==r&&!o;let l="kol-table-selection-indeterminate";o&&!s&&(l="kol-table-selection-none"),0===r&&(l="kol-table-selection-all");const n=translate(l);return h("th",{key:"thead-0-selection",class:"kol-table__cell kol-table__cell--header kol-table__cell--selection"},h("div",{class:clsx("kol-table__selection",{"kol-table__selection--indeterminate":s,"kol-table__selection--checked":o})},h("label",{class:"kol-table__selection-label"},h(KolIconTag,{class:"kol-table__selection-icon",_icons:"kolicon "+(s?"kolicon-minus":o?"kolicon-check":""),_label:""}),h("input",{class:clsx("kol-table__selection-input kol-table__selection-input--checkbox"),"data-testid":"selection-checkbox-all",ref:e=>e&&this.checkboxRefs.push(e),name:"selection",checked:o&&!s,indeterminate:s,"aria-label":n,type:"checkbox",onInput:e=>{this.handleSelectionChangeCallbackAndEvent(e,this.getRevertedSelection(!o))}})),h(KolTooltipWcTag,{"aria-hidden":"true",class:"kol-table__selection-input-tooltip",_align:"right",_id:`${l}-label`,_label:n})))}renderHeaderTdCell(){const e=this.state._headerCells.horizontal,t=this.state._headerCells.vertical;if(!Array.isArray(e)||0===e.length||!Array.isArray(t)||0===t.length)return h(Fragment,null);const a=t.reduce((e,t)=>{var a;const r=null==t?void 0:t[0];return e+(null!==(a=null==r?void 0:r.width)&&void 0!==a?a:0)},0);return h("td",{"aria-hidden":"true",colSpan:t.length,rowSpan:e.length,style:a>0?{width:`${a}px`}:void 0})}formatSortOrderDescription(e){return this.translateSortOrder.replace("{{order}}",`${e}`)}getSortAriaDescription(e){return"number"==typeof e&&e>0?`${this.translateSort} – ${this.formatSortOrderDescription(e)}`:this.translateSort}renderHeadingCell(e,t,a,r){if(!1===e.visible)return"";const o=!1!==(null==e?void 0:e.sortable),s="string"==typeof e.sortDirection,l=o&&s;let n="none",i="kolicon-sort-neutral";if(l&&e.sortDirection)switch(e.sortDirection){case"ASC":i="kolicon-sort-asc",n="ascending";break;case"DESC":i="kolicon-sort-desc",n="descending";break;default:n="none"}const c=r?"row":"number"==typeof e.colSpan&&e.colSpan>1?"colgroup":"col",d="number"==typeof e.sortOrder&&e.sortOrder>0?e.sortOrder:void 0,u=this.getSortAriaDescription(d);return h("th",{key:`${t}-${a}-${e.label}`,class:clsx("kol-table__cell kol-table__cell--header",{[`kol-table__cell--align-${e.textAlign}`]:e.textAlign,[`kol-table__cell--${n}`]:n}),scope:c,colSpan:e.colSpan,rowSpan:e.rowSpan,style:void 0!==e.width?{width:`${e.width}px`}:void 0,"aria-sort":n,"data-sort":l&&e.sortDirection?`sort-${e.sortDirection}`:void 0},l&&e.sortDirection?h("span",{class:"kol-table__sort"},h(KolButtonWcTag,{class:"kol-table__sort-button",exportparts:"icon",_icons:{right:i},_label:e.label,_ariaDescription:u,_on:{onClick:t=>{var a;"function"==typeof(null===(a=this.state._on)||void 0===a?void 0:a.onSort)&&e.key&&e.sortDirection&&this.state._on.onSort(t,{key:e.key,currentSortDirection:e.sortDirection}),this.host&&dispatchDomEvent(this.host,KolEvent.sort,{key:e.key,currentSortDirection:e.sortDirection})}}}),d&&h("span",{"aria-hidden":"true",class:"kol-table__sort-order"},d)):e.label)}renderSpacer(e,t){var a,r;const o=(null===(a=this.state._headerCells.vertical)||void 0===a?void 0:a.length)||0,s=null===(r=null==t?void 0:t[0])||void 0===r?void 0:r.reduce((e,t)=>e+(t.colSpan||1),0),l=this.state._selection?1:0;return h("tr",{"aria-hidden":"true",class:clsx("kol-table__spacer",`kol-table__spacer--${e}`)},h("td",{class:clsx(`kol-table__spacer-line kol-table__spacer-line--${e}`),colSpan:o+s+l}))}renderFoot(){if(!this.state._dataFoot||0===this.state._dataFoot.length)return null;const e=this.createDataField(this.state._dataFoot,this.state._headerCells,!0);return h("tfoot",{class:"kol-table__footer"},[this.renderSpacer("foot",e),e.map((e,t)=>this.renderTableRow(e,t,!0,!0))])}render(){const e=this.createDataField(this.state._data,this.state._headerCells);this.checkboxRefs=[];const t=this.state._headerCells.horizontal;return h("div",{key:"3afe5c237067ccac3023d7fd53883e9057de27e0",class:"kol-table"},this.state._hasSettingsMenu&&h(KolTableSettingsWcTag,{key:"9b41896802e14e25f0234e3dd714972d9e6c77db",_horizontalHeaderCells:null!=t?t:[]}),h("div",{key:"d004c445641a06efe649a6de3c51a15a2502c0df",ref:e=>this.tableDivElement=e,class:"kol-table__scroll-container",tabindex:this.tableDivElementHasScrollbar?"-1":void 0},h("table",{key:"5119cd5e99cb529baf922b66fc0e3d917886ee07",class:"kol-table__table",style:{minWidth:this.getTableMinWidth()}},h("caption",{key:"961a09c0d6e5faff72e65ef9a3aeaa9df0f0ed41",class:"kol-table__focus-element kol-table__caption",id:"caption",tabindex:this.tableDivElementHasScrollbar?"0":void 0},this.state._label),Array.isArray(t)&&h("thead",{key:"12bb291debe3b8532f7ffa862a3e9698903598f5",class:"kol-table__head"},[t.map((e,t)=>h("tr",{class:"kol-table__head-row",key:`thead-${t}`},this.state._selection&&this.renderHeadingSelectionCell(),0===t&&this.renderHeaderTdCell(),Array.isArray(e)&&e.map((e,a)=>this.renderHeadingCell(e,t,a,!1)))),this.renderSpacer("head",t)]),h("tbody",{key:"bba0270d6ca03234ebe2b12b101c589439bda99d",class:"kol-table__body"},e.map((e,t)=>this.renderTableRow(e,t,!0))),this.renderFoot())))}get host(){return this}static get watchers(){return{_hasSettingsMenu:["validateHasSettingsMenu"],_data:["validateData"],_dataFoot:["validateDataFoot"],_headerCells:["validateHeaderCells"],_label:["validateLabel"],_on:["validateOn"],_selection:["validateSelection"]}}},[256,"kol-table-stateless-wc",{_data:[1],_dataFoot:[1,"_data-foot"],_headerCells:[1,"_header-cells"],_label:[1],_on:[16],_selection:[1],_hasSettingsMenu:[4,"_has-settings-menu"],state:[32],tableDivElementHasScrollbar:[32],previousHeaderCells:[32]},[[0,"keydown","handleKeyDown"],[0,"changeheadercells","handleSettingsChange"]],{_hasSettingsMenu:["validateHasSettingsMenu"],_data:["validateData"],_dataFoot:["validateDataFoot"],_headerCells:["validateHeaderCells"],_label:["validateLabel"],_on:["validateOn"],_selection:["validateSelection"]}]);function defineCustomElement$1(){if("undefined"==typeof customElements)return;["kol-table-stateless-wc"].forEach(e=>{if("kol-table-stateless-wc"===e)customElements.get(e)||customElements.define(e,KolTableStateless)})}const KolTableStatelessWc=KolTableStateless,defineCustomElement=defineCustomElement$1;export{KolTableStatelessWc,defineCustomElement};