@kodaris/krubble-components 1.0.56 → 1.0.57

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1479,7 +1479,7 @@ const ze="important",Oe=" !"+ze,Ke=xe(class extends ke{constructor(e){if(super(e
1479
1479
  :host {
1480
1480
  display: none;
1481
1481
  }
1482
- `,je([ue({type:String})],e.KRSelectOption.prototype,"value",void 0),je([ue({type:Boolean})],e.KRSelectOption.prototype,"disabled",void 0),e.KRSelectOption=je([he("kr-select-option")],e.KRSelectOption);const Ve={equals:{key:"equals",type:"comparison",dataTypes:["string","number","date","boolean"],label:"Equals"},n_equals:{key:"n_equals",type:"comparison",dataTypes:["string","number","date","boolean"],label:"Doesn't equal"},contains:{key:"contains",type:"comparison",dataTypes:["string"],label:"Contains"},n_contains:{key:"n_contains",type:"comparison",dataTypes:["string"],label:"Doesn't contain"},starts_with:{key:"starts_with",type:"comparison",dataTypes:["string"],label:"Starts with"},ends_with:{key:"ends_with",type:"comparison",dataTypes:["string"],label:"Ends with"},less_than:{key:"less_than",type:"comparison",dataTypes:["number","date"],label:"Less than"},less_than_equal:{key:"less_than_equal",type:"comparison",dataTypes:["number","date"],label:"Less than or equal"},greater_than:{key:"greater_than",type:"comparison",dataTypes:["number","date"],label:"Greater than"},greater_than_equal:{key:"greater_than_equal",type:"comparison",dataTypes:["number","date"],label:"Greater than or equal"},between:{key:"between",type:"range",dataTypes:["number","date"],label:"Between"},in:{key:"in",type:"list",dataTypes:["string","number"],label:"In"},empty:{key:"empty",type:"nil",dataTypes:["string","number","date","boolean"],label:"Empty"},n_empty:{key:"n_empty",type:"nil",dataTypes:["string","number","date","boolean"],label:"Not empty"}};function Ue(e){const t=[];for(const i of Object.values(Ve))i.dataTypes.includes(e)&&t.push({key:i.key,label:i.label});return t}const Ne=['"',"+","-","&&","||","!","(",")","{","}","[","]","^","~","*","?",":"],We=['\\"',"\\+","\\-","\\&\\&","\\|\\|","\\!","\\(","\\)","\\{","\\}","\\[","\\]","\\^","\\~","\\*","\\?","\\:"];function Xe(e,t=!0){return!0===e||!1===e?e.toString():null===e?"(*:* NOT *)":"number"==typeof e?e.toString():"string"==typeof e?(Ne.forEach(((t,i)=>{var s;e=e.replace(new RegExp(`${s=t,"string"!=typeof s?s:s.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}`,"g"),We[i])})),t?`"${e}"`:e.replace(/ /g,"\\ ")):e}function Ye(e,t=!1){const i=new Date(e);return i.setMinutes(i.getMinutes()-i.getTimezoneOffset()),t&&(i.setUTCHours(23),i.setUTCMinutes(59),i.setUTCSeconds(59),i.setUTCMilliseconds(999)),i.toISOString().replace(/:/g,"\\:")}function Ze(e,t){let i,s,o,r;if(e&&"start"in e&&"end"in e)i=new Date(e.start),s=new Date(e.end),o=t[0],r=t[1];else{if(!(e instanceof Date))return"[* TO *]";i=new Date(e),s=new Date(e),o=t[0],r=t[0]}return"year"===o?(i.setUTCMonth(0,1),i.setUTCHours(0,0,0,0)):"month"===o?(i.setUTCDate(1),i.setUTCHours(0,0,0,0)):"day"===o?i.setUTCHours(0,0,0,0):"time"===o&&i.setUTCSeconds(0,0),"year"===r?(s.setUTCMonth(11,31),s.setUTCHours(23,59,59,999)):"month"===r?(s.setUTCMonth(s.getUTCMonth()+1),s.setUTCDate(0),s.setUTCHours(23,59,59,999)):"day"===r?s.setUTCHours(23,59,59,999):"time"===r&&s.setUTCSeconds(59,999),`[${i.toISOString().replace(/:/g,"\\:")} TO ${s.toISOString().replace(/:/g,"\\:")}]`}function Qe(e,t){let i,s,o,r,l,a;return e&&"start"in e&&"end"in e?(i=new Date(e.start),s=new Date(e.end),o=t[0],r=t[1]):(i=new Date(e),s=new Date(e),o=t[0],r=t[0]),"year"===o?(i.setUTCMonth(0,1),i.setUTCHours(0,0,0,0),l=i):"month"===o?(i.setUTCDate(1),i.setUTCHours(0,0,0,0),l=i):"day"===o?(i.setUTCHours(0,0,0,0),l=i):"time"===o?(i.setUTCSeconds(0,0),l=i):l=i,"year"===r?(s.setUTCMonth(11,31),s.setUTCHours(23,59,59,999),a=s):"month"===r?(s.setUTCMonth(s.getUTCMonth()+1),s.setUTCDate(0),s.setUTCHours(23,59,59,999),a=s):"day"===r?(s.setUTCHours(23,59,59,999),a=s):"time"===r?(s.setUTCSeconds(59,999),a=s):a=s,[l.toISOString().replace(/\..+/,"").replace("T"," "),a.toISOString().replace(/\..+/,"").replace("T"," ")]}function Ge(e){return e=e.trim(),/^(\d{1,2})\/(\d{1,2})\/(\d{2})$/.test(e)||/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.test(e)?"day":/^(\d{1,2})\/(\d{1,2})\/(\d{4}),?\s+(\d{1,2}):(\d{2})\s*(AM|PM)?$/i.test(e)||/^(?:[A-Za-z]+,\s+)?([A-Za-z]+)\s+(\d{1,2}),?\s+(\d{4}),?\s+(\d{1,2}):(\d{2})\s*(AM|PM)?$/i.test(e)?"time":/^(?:[A-Za-z]+,\s+)?([A-Za-z]+)\s+(\d{1,2}),?\s+(\d{4})$/.test(e)?"day":/^(\d{2})$/.test(e)||/^(\d{4})$/.test(e)?"year":/^([A-Za-z]+)\s+(\d{4})$/.test(e)?"month":null}class Je{constructor(){this.field="",this.operator="equals",this.value=null,this.kql="",this.text="",this.type="",this.specificity=[]}setKql(e){if(this.kql=e.trim(),this.text="",this.specificity=[],this.value=null,this.kql)if(e.startsWith("="))this.operator="equals",this.text=e.substring(1).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith("!="))this.operator="n_equals",this.text=e.substring(2).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith("~")&&"string"===this.type)this.operator="contains",this.text=e.substring(1).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith("!~")&&"string"===this.type)this.operator="n_contains",this.text=e.substring(2).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.endsWith("*")&&"string"===this.type)this.operator="starts_with",this.text=e.substring(0,e.length-1),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith("*")&&"string"===this.type)this.operator="ends_with",this.text=e.substring(1),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if("EMPTY"===e)this.operator="empty",this.value=null,this.specificity=[];else if("NOT EMPTY"===e)this.operator="n_empty",this.value=null,this.specificity=[];else if(e.startsWith("<="))this.operator="less_than_equal",this.text=e.substring(2).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith("<"))this.operator="less_than",this.text=e.substring(1).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith(">="))this.operator="greater_than_equal",this.text=e.substring(2).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith(">"))this.operator="greater_than",this.text=e.substring(1).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith("[")&&e.endsWith("]")&&e.indexOf(" TO ")>-1){this.operator="between";const t=e.indexOf(" TO "),i=e.substring(1,t).trim(),s=e.substring(t+4,e.length-1).trim();this.text=`${i} - ${s}`,this.value={start:this._parse(i),end:this._parse(s)},this.specificity=[Ge(i),Ge(s)]}else e.startsWith("(")&&e.endsWith(")")?(this.operator="in",this.text=e.substring(1,e.length-1).trim(),this.value=this.text.split(",").map((e=>e.trim())).map((e=>this._parse(e))),this.specificity=[Ge(this.text)]):"date"===this.type||"boolean"===this.type||"number"===this.type?(this.operator="equals",this.text=this.kql,this.value=this._parse(this.text),this.specificity=[Ge(this.text)]):(this.operator="contains",this.text=e,this.value=this._parse(this.text),this.specificity=[Ge(this.text)]);else"string"===this.type?this.operator="contains":this.operator="equals"}setOperator(e){"empty"===this.operator||"n_empty"===this.operator||"between"===this.operator?(this.value=null,this.text=""):"in"===this.operator&&(this.value=[],this.text=""),this.operator=e,"empty"===this.operator?(this.value="EMPTY",this.text="EMPTY"):"n_empty"===this.operator?(this.value="NOT EMPTY",this.text="NOT EMPTY"):"between"===this.operator?(this.value=null,this.text=""):"in"===this.operator&&(this.value=[],this.text=""),this._buildKql()}setValue(e,t){this.value=e,t?this.specificity=[t]:e instanceof Date?this.specificity=["time"]:this.specificity=[],this._buildText(),this._buildKql()}setStart(e,t){void 0===this.value?.start&&(this.value={start:null,end:null}),this.value.start=e,t?this.specificity[0]=t:e instanceof Date&&(this.specificity[0]="time"),this._buildText(),this._buildKql()}setEnd(e,t){void 0===this.value?.end&&(this.value={start:null,end:null}),this.value.end=e,t?this.specificity[1]=t:e instanceof Date&&(this.specificity[1]="time"),this._buildText(),this._buildKql()}clear(){"string"===this.type?this.operator="contains":this.operator="equals",this.value=null,this.kql="",this.text="",this.specificity=[]}isEmpty(){return"empty"===this.operator||"n_empty"===this.operator?!this.text:"between"===this.operator?!this.value?.start&&!this.value?.end:"in"===this.operator?!this.value?.length:void 0===this.value||null===this.value||""===this.value}has(e){return!("in"!==this.operator||!Array.isArray(this.value))&&("boolean"===this.type&&"string"==typeof e&&("true"===e?e=!0:"false"===e&&(e=!1)),this.value.indexOf(e)>=0)}toggle(e){"in"!==this.operator&&this.setOperator("in"),"boolean"===this.type&&"string"==typeof e&&("true"===e?e=!0:"false"===e&&(e=!1));const t=this.value.indexOf(e);t>=0?this.value.splice(t,1):this.value.push(e),this._buildText(),this._buildKql()}isValid(){return!this.kql||!!this.field&&(!!this.operator&&("empty"===this.operator||("n_empty"===this.operator||("in"===this.operator?Array.isArray(this.value)&&this.value.length>0:"date"===this.type?"between"===this.operator?this.value?.start instanceof Date&&this.value?.end instanceof Date&&!isNaN(this.value.start.getTime())&&!isNaN(this.value.end.getTime()):this.value instanceof Date&&!isNaN(this.value.getTime()):"number"===this.type?"between"===this.operator?"number"==typeof this.value?.start&&"number"==typeof this.value?.end:"number"==typeof this.value:"boolean"===this.type?"boolean"==typeof this.value:"string"==typeof this.value&&!!this.value.trim().length))))}toSolrData(){const e={boost:null,fuzzy:null,not:!1,name:null,operation:null,tagged:!1,value:null};switch(e.name=this.field,this.operator){case"equals":this.value instanceof Date?(e.operation="EXPRESSION",e.value=Ze(this.value,this.specificity)):(e.operation="IS",e.value=this.value);break;case"n_equals":this.value instanceof Date?(e.operation="EXPRESSION",e.not=!0,e.value=Ze(this.value,this.specificity)):(e.operation="IS",e.not=!0,e.value=this.value);break;case"contains":e.operation="EXPRESSION",e.value=`*${Xe(this.value,!1)}*`;break;case"n_contains":e.operation="EXPRESSION",e.not=!0,e.value=`*${Xe(this.value,!1)}*`;break;case"starts_with":e.operation="EXPRESSION",e.value=`${Xe(this.value,!1)}*`;break;case"ends_with":e.operation="EXPRESSION",e.value=`*${Xe(this.value,!1)}`;break;case"empty":e.operation="EXPRESSION",e.not=!0,e.value="[* TO *]";break;case"n_empty":e.operation="EXPRESSION",e.value="[* TO *]";break;case"less_than":this.value instanceof Date?(e.operation="EXPRESSION",e.value=`[* TO ${Ye(this.value)}}`):(e.operation="EXPRESSION",e.value=`[* TO ${Xe(this.value,!0)}}`);break;case"less_than_equal":this.value instanceof Date?(e.operation="EXPRESSION",e.value=`[* TO ${Ye(this.value,!0)}]`):(e.operation="EXPRESSION",e.value=`[* TO ${Xe(this.value,!0)}]`);break;case"greater_than":this.value instanceof Date?(e.operation="EXPRESSION",e.value=`{${Ye(this.value,!0)} TO *]`):(e.operation="EXPRESSION",e.value=`{${Xe(this.value,!0)} TO *]`);break;case"greater_than_equal":this.value instanceof Date?(e.operation="EXPRESSION",e.value=`[${Ye(this.value)} TO *]`):(e.operation="EXPRESSION",e.value=`[${Xe(this.value,!0)} TO *]`);break;case"between":this.value?.start instanceof Date&&this.value?.end instanceof Date?(e.operation="EXPRESSION",e.value=Ze(this.value,this.specificity)):(e.operation="EXPRESSION",e.value=`[${this.value.start} TO ${this.value.end}]`);break;case"in":Array.isArray(this.value)&&this.value.length>0?(e.operation="EXPRESSION",e.value=`(${this.value.map((e=>Xe(e,!0))).join(" OR ")})`):(e.operation="EXPRESSION",e.value=Xe(this.value,!0));break;default:e.operation="EXPRESSION",e.value=Xe(this.value,!0)}return e}toDbParams(){const e={boost:null,fuzzy:null,not:!1,name:null,operation:null,tagged:!1,value:null,values:null};switch(e.name=this.field,this.operator){case"equals":"date"===this.type?(e.operation="BETWEEN",e.values=Qe(this.value,this.specificity)):(e.operation="IS",e.value=this.value);break;case"n_equals":"date"===this.type?(e.operation="BETWEEN",e.not=!0,e.values=Qe(this.value,this.specificity)):(e.operation="IS",e.value=this.value,e.not=!0);break;case"contains":e.operation="CONTAINS",e.value=this.value;break;case"n_contains":e.operation="CONTAINS",e.value=this.value,e.not=!0;break;case"starts_with":e.operation="STARTS_WITH",e.value=this.value;break;case"ends_with":e.operation="ENDS_WITH",e.value=this.value;break;case"empty":e.operation="IS_BLANK";break;case"n_empty":e.operation="IS_NOT_BLANK";break;case"less_than":e.operation="LESS_THAN",e.value=this.value;break;case"less_than_equal":e.operation="LESS_THAN_EQUAL",e.value=this.value;break;case"greater_than":e.operation="GREATER_THAN",e.value=this.value;break;case"greater_than_equal":e.operation="GREATER_THAN_EQUAL",e.value=this.value;break;case"between":e.operation="BETWEEN","date"===this.type?e.values=Qe(this.value,this.specificity):e.values=[this.value.start,this.value.end];break;case"in":e.operation="IN",e.values=this.value??[];break;default:throw Error(`${this.operator} operator not supported by db params.`)}return e}_buildText(){this.isEmpty()?this.text="":"between"===this.operator?this.text=`${this._format(this.value?.start)} - ${this._format(this.value?.end)}`:"in"===this.operator?this.text=this.value.map((e=>this._format(e))).join(","):this.text=this._format(this.value)}_format(e){if(e instanceof Date&&!isNaN(e.getTime())){return`${String(e.getUTCMonth()+1).padStart(2,"0")}/${String(e.getUTCDate()).padStart(2,"0")}/${e.getUTCFullYear()}`}return"boolean"==typeof e?e?"Yes":"No":String(e??"")}_parse(e){if(null==e||""===e)return null;if(this.type)switch(this.type){case"boolean":{const t=e.toString().toLowerCase();return!0===e||!1!==e&&("yes"===t||"no"!==t&&("1"===t||"0"!==t&&null))}case"date":return this._parseDate(e);case"number":{const t=Number(e.toString().replace(/[$,]+/g,""));return isNaN(t)?null:t}default:return e.toString()}return e}_parseDate(e){if(null==e||""===e)return null;const t={jan:0,january:0,feb:1,february:1,mar:2,march:2,apr:3,april:3,may:4,jun:5,june:5,jul:6,july:6,aug:7,august:7,sep:8,september:8,oct:9,october:9,nov:10,november:10,dec:11,december:11};let i;if(i=e.match(/^(\d{1,2})\/(\d{1,2})\/(\d{2})$/),i)return new Date(Date.UTC(2e3+parseInt(i[3]),parseInt(i[1])-1,parseInt(i[2])));if(i=e.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/),i)return new Date(Date.UTC(parseInt(i[3]),parseInt(i[1])-1,parseInt(i[2])));if(i=e.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4}),?\s+(\d{1,2}):(\d{2})\s*(AM|PM)?$/i),i){let e=parseInt(i[4]);return i[6]&&("PM"===i[6].toUpperCase()&&12!==e&&(e+=12),"AM"===i[6].toUpperCase()&&12===e&&(e=0)),new Date(Date.UTC(parseInt(i[3]),parseInt(i[1])-1,parseInt(i[2]),e,parseInt(i[5])))}if(i=e.match(/^(?:[A-Za-z]+,\s+)?([A-Za-z]+)\s+(\d{1,2}),?\s+(\d{4}),?\s+(\d{1,2}):(\d{2})\s*(AM|PM)?$/i),i){const e=t[i[1].toLowerCase()];if(void 0!==e){let t=parseInt(i[4]);return i[6]&&("PM"===i[6].toUpperCase()&&12!==t&&(t+=12),"AM"===i[6].toUpperCase()&&12===t&&(t=0)),new Date(Date.UTC(parseInt(i[3]),e,parseInt(i[2]),t,parseInt(i[5])))}}if(i=e.match(/^(?:[A-Za-z]+,\s+)?([A-Za-z]+)\s+(\d{1,2}),?\s+(\d{4})$/),i){const e=t[i[1].toLowerCase()];if(void 0!==e)return new Date(Date.UTC(parseInt(i[3]),e,parseInt(i[2])))}if(i=e.match(/^(\d{2})$/),i)return new Date(Date.UTC(2e3+parseInt(i[1]),0,1));if(i=e.match(/^(\d{4})$/),i)return new Date(Date.UTC(parseInt(i[1]),0,1));if(i=e.match(/^([A-Za-z]+)\s+(\d{4})$/),i){const e=t[i[1].toLowerCase()];if(void 0!==e)return new Date(Date.UTC(parseInt(i[2]),e,1))}return null}_buildKql(){if(this.isEmpty())this.kql="";else switch(this.operator){case"equals":this.kql=`= ${this.text}`;break;case"n_equals":this.kql=`!= ${this.text}`;break;case"contains":this.kql=`~ ${this.text}`;break;case"n_contains":this.kql=`!~ ${this.text}`;break;case"starts_with":this.kql=`${this.text}*`;break;case"ends_with":this.kql=`*${this.text}`;break;case"empty":this.kql="EMPTY";break;case"n_empty":this.kql="NOT EMPTY";break;case"less_than":this.kql=`< ${this.text}`;break;case"less_than_equal":this.kql=`<= ${this.text}`;break;case"greater_than":this.kql=`> ${this.text}`;break;case"greater_than_equal":this.kql=`>= ${this.text}`;break;case"between":this.kql=`[${this._format(this.value?.start??"")} TO ${this._format(this.value?.end??"")}]`;break;case"in":this.kql=`(${this.value.map((e=>this._format(e))).join(",")})`;break;default:throw Error(`Unknown operator ${this.operator}`)}}}var et=function(e,t,i,s){var o,r=arguments.length,l=r<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(l=(r<3?o(l):r>3?o(t,i,l):o(t,i))||l);return r>3&&l&&Object.defineProperty(t,i,l),l};class tt{constructor(){this.title="",this.actions=[],this.columns=[],this.displayedColumns=[],this.data=null,this.dataSource=null,this.refreshInterval=0,this.pageSize=0,this.rowClickable=!1,this.rowHref=null}}e.KRTable=class extends ae{constructor(){super(...arguments),this._scrollStyle="overlay",this._data=[],this._dataState="idle",this._page=1,this._pageSize=50,this._totalItems=0,this._totalPages=0,this._searchQuery="",this._canScrollLeft=!1,this._canScrollRight=!1,this._canScrollHorizontal=!1,this._columnPickerOpen=!1,this._filterPanelOpened=null,this._filterPanelTab="filter",this._buckets=new Map,this._filterPanelPos={top:0,left:0},this._sorts=[],this._resizing=null,this._resizeObserver=null,this._searchPositionLocked=!1,this._model=new tt,this.def={columns:[]},this._handleClickOutside=e=>{const t=e.composedPath();if(this._columnPickerOpen){const e=this.shadowRoot?.querySelector(".column-picker-wrapper");e&&!t.includes(e)&&(this._columnPickerOpen=!1)}this._filterPanelOpened&&(t.some((e=>e.classList?.contains("filter-panel")))||this._handleFilterApply())},this._handleResizeMove=e=>{if(!this._resizing)return;const t=this._model.columns.find((e=>e.id===this._resizing.columnId));if(t){const i=this._resizing.startWidth+(e.clientX-this._resizing.startX);t.width=`${Math.min(900,Math.max(50,i))}px`,this.requestUpdate()}},this._handleResizeEnd=()=>{this._resizing=null,document.removeEventListener("mousemove",this._handleResizeMove),document.removeEventListener("mouseup",this._handleResizeEnd)}}connectedCallback(){super.connectedCallback(),this.classList.toggle("kr-table--scroll-overlay","overlay"===this._scrollStyle),this.classList.toggle("kr-table--scroll-edge","edge"===this._scrollStyle),this._fetch(),this._initRefresh(),document.addEventListener("click",this._handleClickOutside),this._resizeObserver=new ResizeObserver((()=>{this._searchPositionLocked=!1,this._updateSearchPosition()})),this._resizeObserver.observe(this)}disconnectedCallback(){super.disconnectedCallback(),clearInterval(this._refreshTimer),document.removeEventListener("click",this._handleClickOutside),this._resizeObserver?.disconnect()}willUpdate(e){e.has("def")&&(this._model=new tt,this.def.title&&(this._model.title=this.def.title),this.def.actions&&(this._model.actions=this.def.actions),this.def.data&&(this._model.data=this.def.data),this.def.dataSource&&(this._model.dataSource=this.def.dataSource),"number"==typeof this.def.refreshInterval&&(this._model.refreshInterval=this.def.refreshInterval),"number"==typeof this.def.pageSize&&(this._model.pageSize=this.def.pageSize),this.def.rowClickable&&(this._model.rowClickable=this.def.rowClickable),this.def.rowHref&&(this._model.rowHref=this.def.rowHref),this._model.columns=this.def.columns.map((e=>{const t={...e,filter:null};return t.type||(t.type="string"),"actions"===t.type?(t.label=e.label??"",t.sticky="right",t.resizable=!1,t):((e.filterable||e.facetable)&&(t.filter=new Je,t.filter.field=e.id,t.filter.type=t.type,e.filter?(t.filter.setOperator(e.filter.operator),t.filter.setValue(e.filter.value)):e.facetable&&!e.filterable?(t.filter.operator="in",t.filter.value=[]):"string"===t.filter.type&&(t.filter.operator="contains")),t)})),this.def.displayedColumns?this._model.displayedColumns=this.def.displayedColumns:this._model.displayedColumns=this._model.columns.map((e=>e.id)),this._fetch(),this._initRefresh())}updated(e){this._updateScrollFlags(),this._syncSlottedContent()}_syncSlottedContent(){const e=this.getDisplayedColumns().filter((e=>e.render));e.length&&(this.querySelectorAll('[slot^="cell-"]').forEach((e=>e.remove())),this._data.forEach(((t,i)=>{e.forEach((e=>{const s=e.render(t);if(!s)return;const o=document.createElement("span");o.slot=`cell-${i}-${e.id}`,"actions"===e.type&&(o.style.display="flex",o.style.gap="8px"),"string"==typeof s?o.innerHTML=s:re(s,o),this.appendChild(o)}))})))}refresh(){this._fetch()}goToPrevPage(){this._page>1&&(this._page--,this._fetch())}goToNextPage(){this._page<this._totalPages&&(this._page++,this._fetch())}goToPage(e){e>=1&&e<=this._totalPages&&(this._page=e,this._fetch())}_toSolrData(){const e={page:this._page-1,size:this._pageSize,sorts:this._sorts,filterFields:[],queryFields:[],facetFields:[]};for(const t of this._model.columns){if(!t.filter||t.filter.isEmpty()||!t.filter.isValid())continue;const i=t.filter.toSolrData();t.facetable&&"in"===t.filter.operator&&(i.tagged=!0),e.filterFields.push(i)}for(const t of this._model.columns)t.facetable&&e.facetFields.push({name:t.id,type:"FIELD",limit:100,sort:"count",minimumCount:1});return this._searchQuery?.trim().length&&e.queryFields.push({name:"_text_",operation:"IS",value:Xe(this._searchQuery,!1)}),e}_toDbParams(){const e={page:this._page-1,size:this._pageSize,sorts:this._sorts,filterFields:[],queryFields:[],facetFields:[]};for(const t of this._model.columns)t.filter&&!t.filter.isEmpty()&&t.filter.isValid()&&e.filterFields.push(t.filter.toDbParams());return this._searchQuery?.trim().length&&this._model.columns.filter((e=>e.searchable)).forEach((t=>{e.queryFields.push({name:t.id,operation:"CONTAINS",value:this._searchQuery,and:!1})})),e}_fetch(){if(this._model.data)return this._data=this._model.data,this._totalItems=this._model.data.length,this._totalPages=Math.ceil(this._model.data.length/this._pageSize),void(this._dataState="success");if(!this._model.dataSource)return;let t;this._dataState="loading",t="db"===this._model.dataSource.mode?this._toDbParams():this._toSolrData(),this._model.dataSource.fetch(t).then((e=>{switch(this._model.dataSource?.mode){case"opensearch":throw Error("Opensearch not supported yet");case"db":{const t=e;this._data=t.data.content,this._totalItems=t.data.totalElements,this._totalPages=t.data.totalPages,this._pageSize=t.data.size;break}default:{const t=e;this._data=t.data.content,this._totalItems=t.data.totalElements,this._totalPages=t.data.totalPages,this._pageSize=t.data.size,this._parseFacetResults(t)}}this._dataState="success",this._updateSearchPosition()})).catch((t=>{this._dataState="error",e.KRSnackbar.show({message:t instanceof Error?t.message:"Failed to load data",type:"error"})}))}_parseFacetResults(e){if(e.data.facetFields){for(const t of this._model.columns){if(!t.facetable)continue;const i=e.data.facetFields[t.id];if(!i){this._buckets.set(t.id,[]);continue}const s=[];for(const e of i){let i=e.name;"boolean"===t.type&&"string"==typeof e.name&&("true"===e.name?i=!0:"false"===e.name&&(i=!1)),null===e.name&&e.count>0&&s.unshift({val:null,count:e.count}),null!==e.name&&s.push({val:i,count:e.count})}if(t.filter&&"in"===t.filter.operator&&Array.isArray(t.filter.value))for(const e of t.filter.value)s.some((t=>t.val===e))||s.push({val:e,count:0});this._buckets.set(t.id,s)}this._buckets=new Map(this._buckets)}}_initRefresh(){clearInterval(this._refreshTimer),this._model.refreshInterval&&this._model.refreshInterval>0&&(this._refreshTimer=window.setInterval((()=>{this._fetch()}),this._model.refreshInterval))}_handleSearch(e){const t=e.target;this._searchQuery=t.value,this._page=1,this._fetch()}_getGridTemplateColumns(){return this.getDisplayedColumns().map((e=>e.width?e.width:"actions"===e.type?"max-content":"minmax(80px, auto)")).join(" ")}_updateSearchPosition(){if(this._searchPositionLocked)return;const e=this.shadowRoot?.querySelector(".search"),t=e?.querySelector(".search-field");e&&t&&(e.style.justifyContent="center",t.style.marginLeft="",requestAnimationFrame((()=>{const i=e.getBoundingClientRect(),s=t.getBoundingClientRect().left-i.left;e.style.justifyContent="flex-start",t.style.marginLeft=`${s}px`,this._searchPositionLocked=!0})))}_toggleColumnPicker(){this._columnPickerOpen=!this._columnPickerOpen}_toggleColumn(e){this._model.displayedColumns.includes(e)?this._model.displayedColumns=this._model.displayedColumns.filter((t=>t!==e)):this._model.displayedColumns=[...this._model.displayedColumns,e],this.requestUpdate()}_handleRowMouseDown(){this._model.rowClickable&&window.getSelection()?.removeAllRanges()}_handleRowClick(e,t){if(!this._model.rowClickable)return;const i=window.getSelection();i&&i.toString().length>0||this.dispatchEvent(new CustomEvent("row-click",{detail:{row:e,rowIndex:t},bubbles:!0,composed:!0}))}getDisplayedColumns(){return this._model.displayedColumns.map((e=>this._model.columns.find((t=>t.id===e)))).sort(((e,t)=>"actions"===e.type&&"actions"!==t.type?1:"actions"!==e.type&&"actions"===t.type?-1:0))}_handleScroll(e){const t=e.target;this._canScrollLeft=t.scrollLeft>0,this._canScrollRight=t.scrollLeft<t.scrollWidth-t.clientWidth-1}_updateScrollFlags(){const e=this.shadowRoot?.querySelector(".content");e&&(this._canScrollLeft=e.scrollLeft>0,this._canScrollRight=e.scrollWidth>e.clientWidth&&e.scrollLeft<e.scrollWidth-e.clientWidth-1,this._canScrollHorizontal=e.scrollWidth>e.clientWidth),this.classList.toggle("kr-table--scroll-left-available",this._canScrollLeft),this.classList.toggle("kr-table--scroll-right-available",this._canScrollRight),this.classList.toggle("kr-table--scroll-horizontal-available",this._canScrollHorizontal),this.classList.toggle("kr-table--sticky-left",this.getDisplayedColumns().some((e=>"left"===e.sticky))),this.classList.toggle("kr-table--sticky-right",this.getDisplayedColumns().some((e=>"right"===e.sticky)))}_handleResizeStart(e,t){e.preventDefault();const i=this.shadowRoot?.querySelector(`.header-cell[data-column-id="${t}"]`);this._resizing={columnId:t,startX:e.clientX,startWidth:i?.offsetWidth||200},document.addEventListener("mousemove",this._handleResizeMove),document.addEventListener("mouseup",this._handleResizeEnd)}_handleSortClick(e,t){if(e.shiftKey){const e=this._sorts.findIndex((e=>e.sortBy===t.id));if(-1===e)this._sorts.push({sortBy:t.id,sortDirection:"asc"});else{const t=this._sorts[e];"asc"===t.sortDirection?t.sortDirection="desc":this._sorts.splice(e,1)}this.requestUpdate()}else{let e=null;1===this._sorts.length&&(e=this._sorts.find((e=>e.sortBy===t.id))),e?"asc"===e.sortDirection?this._sorts=[{sortBy:t.id,sortDirection:"desc"}]:this._sorts=[]:this._sorts=[{sortBy:t.id,sortDirection:"asc"}]}this._page=1,this._fetch()}_renderSortIndicator(e){if(!e.sortable)return V;const t=this._sorts.findIndex((t=>t.sortBy===e.id));if(-1===t)return F`
1482
+ `,je([ue({type:String})],e.KRSelectOption.prototype,"value",void 0),je([ue({type:Boolean})],e.KRSelectOption.prototype,"disabled",void 0),e.KRSelectOption=je([he("kr-select-option")],e.KRSelectOption);const Ve={equals:{key:"equals",type:"comparison",dataTypes:["string","number","date","boolean"],label:"Equals"},n_equals:{key:"n_equals",type:"comparison",dataTypes:["string","number","date","boolean"],label:"Doesn't equal"},contains:{key:"contains",type:"comparison",dataTypes:["string"],label:"Contains"},n_contains:{key:"n_contains",type:"comparison",dataTypes:["string"],label:"Doesn't contain"},starts_with:{key:"starts_with",type:"comparison",dataTypes:["string"],label:"Starts with"},ends_with:{key:"ends_with",type:"comparison",dataTypes:["string"],label:"Ends with"},less_than:{key:"less_than",type:"comparison",dataTypes:["number","date"],label:"Less than"},less_than_equal:{key:"less_than_equal",type:"comparison",dataTypes:["number","date"],label:"Less than or equal"},greater_than:{key:"greater_than",type:"comparison",dataTypes:["number","date"],label:"Greater than"},greater_than_equal:{key:"greater_than_equal",type:"comparison",dataTypes:["number","date"],label:"Greater than or equal"},between:{key:"between",type:"range",dataTypes:["number","date"],label:"Between"},in:{key:"in",type:"list",dataTypes:["string","number"],label:"In"},n_in:{key:"n_in",type:"list",dataTypes:["string","number","date","boolean"],label:"Not In"},empty:{key:"empty",type:"nil",dataTypes:["string","number","date","boolean"],label:"Empty"},n_empty:{key:"n_empty",type:"nil",dataTypes:["string","number","date","boolean"],label:"Not empty"}};function Ue(e){const t=[];for(const i of Object.values(Ve))i.dataTypes.includes(e)&&t.push({key:i.key,label:i.label});return t}const Ne=['"',"+","-","&&","||","!","(",")","{","}","[","]","^","~","*","?",":"],We=['\\"',"\\+","\\-","\\&\\&","\\|\\|","\\!","\\(","\\)","\\{","\\}","\\[","\\]","\\^","\\~","\\*","\\?","\\:"];function Xe(e,t=!0){return!0===e||!1===e?e.toString():null===e?"(*:* NOT *)":"number"==typeof e?e.toString():"string"==typeof e?(Ne.forEach(((t,i)=>{var s;e=e.replace(new RegExp(`${s=t,"string"!=typeof s?s:s.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")}`,"g"),We[i])})),t?`"${e}"`:e.replace(/ /g,"\\ ")):e}function Ye(e,t=!1){const i=new Date(e);return i.setMinutes(i.getMinutes()-i.getTimezoneOffset()),t&&(i.setUTCHours(23),i.setUTCMinutes(59),i.setUTCSeconds(59),i.setUTCMilliseconds(999)),i.toISOString().replace(/:/g,"\\:")}function Ze(e,t){let i,s,o,r;if(e&&"start"in e&&"end"in e)i=new Date(e.start),s=new Date(e.end),o=t[0],r=t[1];else{if(!(e instanceof Date))return"[* TO *]";i=new Date(e),s=new Date(e),o=t[0],r=t[0]}return"year"===o?(i.setUTCMonth(0,1),i.setUTCHours(0,0,0,0)):"month"===o?(i.setUTCDate(1),i.setUTCHours(0,0,0,0)):"day"===o?i.setUTCHours(0,0,0,0):"time"===o&&i.setUTCSeconds(0,0),"year"===r?(s.setUTCMonth(11,31),s.setUTCHours(23,59,59,999)):"month"===r?(s.setUTCMonth(s.getUTCMonth()+1),s.setUTCDate(0),s.setUTCHours(23,59,59,999)):"day"===r?s.setUTCHours(23,59,59,999):"time"===r&&s.setUTCSeconds(59,999),`[${i.toISOString().replace(/:/g,"\\:")} TO ${s.toISOString().replace(/:/g,"\\:")}]`}function Qe(e,t){let i,s,o,r,l,a;return e&&"start"in e&&"end"in e?(i=new Date(e.start),s=new Date(e.end),o=t[0],r=t[1]):(i=new Date(e),s=new Date(e),o=t[0],r=t[0]),"year"===o?(i.setUTCMonth(0,1),i.setUTCHours(0,0,0,0),l=i):"month"===o?(i.setUTCDate(1),i.setUTCHours(0,0,0,0),l=i):"day"===o?(i.setUTCHours(0,0,0,0),l=i):"time"===o?(i.setUTCSeconds(0,0),l=i):l=i,"year"===r?(s.setUTCMonth(11,31),s.setUTCHours(23,59,59,999),a=s):"month"===r?(s.setUTCMonth(s.getUTCMonth()+1),s.setUTCDate(0),s.setUTCHours(23,59,59,999),a=s):"day"===r?(s.setUTCHours(23,59,59,999),a=s):"time"===r?(s.setUTCSeconds(59,999),a=s):a=s,[l.toISOString().replace(/\..+/,"").replace("T"," "),a.toISOString().replace(/\..+/,"").replace("T"," ")]}function Ge(e){return e=e.trim(),/^(\d{1,2})\/(\d{1,2})\/(\d{2})$/.test(e)||/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/.test(e)?"day":/^(\d{1,2})\/(\d{1,2})\/(\d{4}),?\s+(\d{1,2}):(\d{2})\s*(AM|PM)?$/i.test(e)||/^(?:[A-Za-z]+,\s+)?([A-Za-z]+)\s+(\d{1,2}),?\s+(\d{4}),?\s+(\d{1,2}):(\d{2})\s*(AM|PM)?$/i.test(e)?"time":/^(?:[A-Za-z]+,\s+)?([A-Za-z]+)\s+(\d{1,2}),?\s+(\d{4})$/.test(e)?"day":/^(\d{2})$/.test(e)||/^(\d{4})$/.test(e)?"year":/^([A-Za-z]+)\s+(\d{4})$/.test(e)?"month":null}class Je{constructor(){this.field="",this.operator="equals",this.value=null,this.kql="",this.text="",this.type="",this.specificity=[]}setKql(e){if(this.kql=e.trim(),this.text="",this.specificity=[],this.value=null,this.kql)if(e.startsWith("="))this.operator="equals",this.text=e.substring(1).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith("!="))this.operator="n_equals",this.text=e.substring(2).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith("~")&&"string"===this.type)this.operator="contains",this.text=e.substring(1).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith("!~")&&"string"===this.type)this.operator="n_contains",this.text=e.substring(2).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.endsWith("*")&&"string"===this.type)this.operator="starts_with",this.text=e.substring(0,e.length-1),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith("*")&&"string"===this.type)this.operator="ends_with",this.text=e.substring(1),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if("EMPTY"===e)this.operator="empty",this.value=null,this.specificity=[];else if("NOT EMPTY"===e)this.operator="n_empty",this.value=null,this.specificity=[];else if(e.startsWith("<="))this.operator="less_than_equal",this.text=e.substring(2).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith("<"))this.operator="less_than",this.text=e.substring(1).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith(">="))this.operator="greater_than_equal",this.text=e.substring(2).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith(">"))this.operator="greater_than",this.text=e.substring(1).trim(),this.value=this._parse(this.text),this.specificity=[Ge(this.text)];else if(e.startsWith("[")&&e.endsWith("]")&&e.indexOf(" TO ")>-1){this.operator="between";const t=e.indexOf(" TO "),i=e.substring(1,t).trim(),s=e.substring(t+4,e.length-1).trim();this.text=`${i} - ${s}`,this.value={start:this._parse(i),end:this._parse(s)},this.specificity=[Ge(i),Ge(s)]}else e.startsWith("!(")&&e.endsWith(")")?(this.operator="n_in",this.text=e.substring(2,e.length-1).trim(),this.value=this.text.split(",").map((e=>e.trim())).map((e=>this._parse(e))),this.specificity=[Ge(this.text)]):e.startsWith("(")&&e.endsWith(")")?(this.operator="in",this.text=e.substring(1,e.length-1).trim(),this.value=this.text.split(",").map((e=>e.trim())).map((e=>this._parse(e))),this.specificity=[Ge(this.text)]):"date"===this.type||"boolean"===this.type||"number"===this.type?(this.operator="equals",this.text=this.kql,this.value=this._parse(this.text),this.specificity=[Ge(this.text)]):(this.operator="contains",this.text=e,this.value=this._parse(this.text),this.specificity=[Ge(this.text)]);else"string"===this.type?this.operator="contains":this.operator="equals"}setOperator(e){"empty"===this.operator||"n_empty"===this.operator||"between"===this.operator?(this.value=null,this.text=""):"in"!==this.operator&&"n_in"!==this.operator||(this.value=[],this.text=""),this.operator=e,"empty"===this.operator?(this.value="EMPTY",this.text="EMPTY"):"n_empty"===this.operator?(this.value="NOT EMPTY",this.text="NOT EMPTY"):"between"===this.operator?(this.value=null,this.text=""):"in"!==this.operator&&"n_in"!==this.operator||(this.value=[],this.text=""),this._buildKql()}setValue(e,t){this.value=e,t?this.specificity=[t]:e instanceof Date?this.specificity=["time"]:this.specificity=[],this._buildText(),this._buildKql()}setStart(e,t){void 0===this.value?.start&&(this.value={start:null,end:null}),this.value.start=e,t?this.specificity[0]=t:e instanceof Date&&(this.specificity[0]="time"),this._buildText(),this._buildKql()}setEnd(e,t){void 0===this.value?.end&&(this.value={start:null,end:null}),this.value.end=e,t?this.specificity[1]=t:e instanceof Date&&(this.specificity[1]="time"),this._buildText(),this._buildKql()}clear(){"string"===this.type?this.operator="contains":this.operator="equals",this.value=null,this.kql="",this.text="",this.specificity=[]}isEmpty(){return"empty"===this.operator||"n_empty"===this.operator?!this.text:"between"===this.operator?!this.value?.start&&!this.value?.end:"in"===this.operator||"n_in"===this.operator?!this.value?.length:void 0===this.value||null===this.value||""===this.value}has(e){return!("in"!==this.operator&&"n_in"!==this.operator||!Array.isArray(this.value))&&("boolean"===this.type&&"string"==typeof e&&("true"===e?e=!0:"false"===e&&(e=!1)),this.value.indexOf(e)>=0)}toggle(e){"in"!==this.operator&&"n_in"!==this.operator&&this.setOperator("in"),"boolean"===this.type&&"string"==typeof e&&("true"===e?e=!0:"false"===e&&(e=!1));const t=this.value.indexOf(e);t>=0?this.value.splice(t,1):this.value.push(e),this._buildText(),this._buildKql()}isValid(){return!this.kql||!!this.field&&(!!this.operator&&("empty"===this.operator||("n_empty"===this.operator||("in"===this.operator||"n_in"===this.operator?Array.isArray(this.value)&&this.value.length>0:"date"===this.type?"between"===this.operator?this.value?.start instanceof Date&&this.value?.end instanceof Date&&!isNaN(this.value.start.getTime())&&!isNaN(this.value.end.getTime()):this.value instanceof Date&&!isNaN(this.value.getTime()):"number"===this.type?"between"===this.operator?"number"==typeof this.value?.start&&"number"==typeof this.value?.end:"number"==typeof this.value:"boolean"===this.type?"boolean"==typeof this.value:"string"==typeof this.value&&!!this.value.trim().length))))}toSolrData(){const e={boost:null,fuzzy:null,not:!1,name:null,operation:null,tagged:!1,value:null};switch(e.name=this.field,this.operator){case"equals":this.value instanceof Date?(e.operation="EXPRESSION",e.value=Ze(this.value,this.specificity)):(e.operation="IS",e.value=this.value);break;case"n_equals":this.value instanceof Date?(e.operation="EXPRESSION",e.not=!0,e.value=Ze(this.value,this.specificity)):(e.operation="IS",e.not=!0,e.value=this.value);break;case"contains":e.operation="EXPRESSION",e.value=`*${Xe(this.value,!1)}*`;break;case"n_contains":e.operation="EXPRESSION",e.not=!0,e.value=`*${Xe(this.value,!1)}*`;break;case"starts_with":e.operation="EXPRESSION",e.value=`${Xe(this.value,!1)}*`;break;case"ends_with":e.operation="EXPRESSION",e.value=`*${Xe(this.value,!1)}`;break;case"empty":e.operation="EXPRESSION",e.not=!0,e.value="[* TO *]";break;case"n_empty":e.operation="EXPRESSION",e.value="[* TO *]";break;case"less_than":this.value instanceof Date?(e.operation="EXPRESSION",e.value=`[* TO ${Ye(this.value)}}`):(e.operation="EXPRESSION",e.value=`[* TO ${Xe(this.value,!0)}}`);break;case"less_than_equal":this.value instanceof Date?(e.operation="EXPRESSION",e.value=`[* TO ${Ye(this.value,!0)}]`):(e.operation="EXPRESSION",e.value=`[* TO ${Xe(this.value,!0)}]`);break;case"greater_than":this.value instanceof Date?(e.operation="EXPRESSION",e.value=`{${Ye(this.value,!0)} TO *]`):(e.operation="EXPRESSION",e.value=`{${Xe(this.value,!0)} TO *]`);break;case"greater_than_equal":this.value instanceof Date?(e.operation="EXPRESSION",e.value=`[${Ye(this.value)} TO *]`):(e.operation="EXPRESSION",e.value=`[${Xe(this.value,!0)} TO *]`);break;case"between":this.value?.start instanceof Date&&this.value?.end instanceof Date?(e.operation="EXPRESSION",e.value=Ze(this.value,this.specificity)):(e.operation="EXPRESSION",e.value=`[${this.value.start} TO ${this.value.end}]`);break;case"in":Array.isArray(this.value)&&this.value.length>0?(e.operation="EXPRESSION",e.value=`(${this.value.map((e=>Xe(e,!0))).join(" OR ")})`):(e.operation="EXPRESSION",e.value=Xe(this.value,!0));break;case"n_in":Array.isArray(this.value)&&this.value.length>0?(e.operation="EXPRESSION",e.not=!0,e.value=`(${this.value.map((e=>Xe(e,!0))).join(" OR ")})`):(e.operation="EXPRESSION",e.not=!0,e.value=Xe(this.value,!0));break;default:e.operation="EXPRESSION",e.value=Xe(this.value,!0)}return e}toDbParams(){const e={boost:null,fuzzy:null,not:!1,name:null,operation:null,tagged:!1,value:null,values:null};switch(e.name=this.field,this.operator){case"equals":"date"===this.type?(e.operation="BETWEEN",e.values=Qe(this.value,this.specificity)):(e.operation="IS",e.value=this.value);break;case"n_equals":"date"===this.type?(e.operation="BETWEEN",e.not=!0,e.values=Qe(this.value,this.specificity)):(e.operation="IS",e.value=this.value,e.not=!0);break;case"contains":e.operation="CONTAINS",e.value=this.value;break;case"n_contains":e.operation="CONTAINS",e.value=this.value,e.not=!0;break;case"starts_with":e.operation="STARTS_WITH",e.value=this.value;break;case"ends_with":e.operation="ENDS_WITH",e.value=this.value;break;case"empty":e.operation="IS_BLANK";break;case"n_empty":e.operation="IS_NOT_BLANK";break;case"less_than":e.operation="LESS_THAN",e.value=this.value;break;case"less_than_equal":e.operation="LESS_THAN_EQUAL",e.value=this.value;break;case"greater_than":e.operation="GREATER_THAN",e.value=this.value;break;case"greater_than_equal":e.operation="GREATER_THAN_EQUAL",e.value=this.value;break;case"between":e.operation="BETWEEN","date"===this.type?e.values=Qe(this.value,this.specificity):e.values=[this.value.start,this.value.end];break;case"in":e.operation="IN",e.values=this.value??[];break;case"n_in":e.operation="IN",e.not=!0,e.values=this.value??[];break;default:throw Error(`${this.operator} operator not supported by db params.`)}return e}_buildText(){this.isEmpty()?this.text="":"between"===this.operator?this.text=`${this._format(this.value?.start)} - ${this._format(this.value?.end)}`:"in"===this.operator||"n_in"===this.operator?this.text=this.value.map((e=>this._format(e))).join(","):this.text=this._format(this.value)}_format(e){if(e instanceof Date&&!isNaN(e.getTime())){return`${String(e.getUTCMonth()+1).padStart(2,"0")}/${String(e.getUTCDate()).padStart(2,"0")}/${e.getUTCFullYear()}`}return"boolean"==typeof e?e?"Yes":"No":String(e??"")}_parse(e){if(null==e||""===e)return null;if(this.type)switch(this.type){case"boolean":{const t=e.toString().toLowerCase();return!0===e||!1!==e&&("yes"===t||"no"!==t&&("1"===t||"0"!==t&&null))}case"date":return this._parseDate(e);case"number":{const t=Number(e.toString().replace(/[$,]+/g,""));return isNaN(t)?null:t}default:return e.toString()}return e}_parseDate(e){if(null==e||""===e)return null;const t={jan:0,january:0,feb:1,february:1,mar:2,march:2,apr:3,april:3,may:4,jun:5,june:5,jul:6,july:6,aug:7,august:7,sep:8,september:8,oct:9,october:9,nov:10,november:10,dec:11,december:11};let i;if(i=e.match(/^(\d{1,2})\/(\d{1,2})\/(\d{2})$/),i)return new Date(Date.UTC(2e3+parseInt(i[3]),parseInt(i[1])-1,parseInt(i[2])));if(i=e.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/),i)return new Date(Date.UTC(parseInt(i[3]),parseInt(i[1])-1,parseInt(i[2])));if(i=e.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4}),?\s+(\d{1,2}):(\d{2})\s*(AM|PM)?$/i),i){let e=parseInt(i[4]);return i[6]&&("PM"===i[6].toUpperCase()&&12!==e&&(e+=12),"AM"===i[6].toUpperCase()&&12===e&&(e=0)),new Date(Date.UTC(parseInt(i[3]),parseInt(i[1])-1,parseInt(i[2]),e,parseInt(i[5])))}if(i=e.match(/^(?:[A-Za-z]+,\s+)?([A-Za-z]+)\s+(\d{1,2}),?\s+(\d{4}),?\s+(\d{1,2}):(\d{2})\s*(AM|PM)?$/i),i){const e=t[i[1].toLowerCase()];if(void 0!==e){let t=parseInt(i[4]);return i[6]&&("PM"===i[6].toUpperCase()&&12!==t&&(t+=12),"AM"===i[6].toUpperCase()&&12===t&&(t=0)),new Date(Date.UTC(parseInt(i[3]),e,parseInt(i[2]),t,parseInt(i[5])))}}if(i=e.match(/^(?:[A-Za-z]+,\s+)?([A-Za-z]+)\s+(\d{1,2}),?\s+(\d{4})$/),i){const e=t[i[1].toLowerCase()];if(void 0!==e)return new Date(Date.UTC(parseInt(i[3]),e,parseInt(i[2])))}if(i=e.match(/^(\d{2})$/),i)return new Date(Date.UTC(2e3+parseInt(i[1]),0,1));if(i=e.match(/^(\d{4})$/),i)return new Date(Date.UTC(parseInt(i[1]),0,1));if(i=e.match(/^([A-Za-z]+)\s+(\d{4})$/),i){const e=t[i[1].toLowerCase()];if(void 0!==e)return new Date(Date.UTC(parseInt(i[2]),e,1))}return null}_buildKql(){if(this.isEmpty())this.kql="";else switch(this.operator){case"equals":this.kql=`= ${this.text}`;break;case"n_equals":this.kql=`!= ${this.text}`;break;case"contains":this.kql=`~ ${this.text}`;break;case"n_contains":this.kql=`!~ ${this.text}`;break;case"starts_with":this.kql=`${this.text}*`;break;case"ends_with":this.kql=`*${this.text}`;break;case"empty":this.kql="EMPTY";break;case"n_empty":this.kql="NOT EMPTY";break;case"less_than":this.kql=`< ${this.text}`;break;case"less_than_equal":this.kql=`<= ${this.text}`;break;case"greater_than":this.kql=`> ${this.text}`;break;case"greater_than_equal":this.kql=`>= ${this.text}`;break;case"between":this.kql=`[${this._format(this.value?.start??"")} TO ${this._format(this.value?.end??"")}]`;break;case"in":this.kql=`(${this.value.map((e=>this._format(e))).join(",")})`;break;case"n_in":this.kql=`!(${this.value.map((e=>this._format(e))).join(",")})`;break;default:throw Error(`Unknown operator ${this.operator}`)}}}var et=function(e,t,i,s){var o,r=arguments.length,l=r<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)l=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(o=e[a])&&(l=(r<3?o(l):r>3?o(t,i,l):o(t,i))||l);return r>3&&l&&Object.defineProperty(t,i,l),l};class tt{constructor(){this.title="",this.actions=[],this.columns=[],this.displayedColumns=[],this.data=null,this.dataSource=null,this.refreshInterval=0,this.pageSize=0,this.rowClickable=!1,this.rowHref=null}}e.KRTable=class extends ae{constructor(){super(...arguments),this._scrollStyle="overlay",this._data=[],this._dataState="idle",this._page=1,this._pageSize=50,this._totalItems=0,this._totalPages=0,this._searchQuery="",this._canScrollLeft=!1,this._canScrollRight=!1,this._canScrollHorizontal=!1,this._columnPickerOpen=!1,this._filterPanelOpened=null,this._filterPanelTab="filter",this._buckets=new Map,this._filterPanelPos={top:0,left:0},this._sorts=[],this._resizing=null,this._resizeObserver=null,this._searchPositionLocked=!1,this._model=new tt,this.def={columns:[]},this._handleClickOutside=e=>{const t=e.composedPath();if(this._columnPickerOpen){const e=this.shadowRoot?.querySelector(".column-picker-wrapper");e&&!t.includes(e)&&(this._columnPickerOpen=!1)}this._filterPanelOpened&&(t.some((e=>e.classList?.contains("filter-panel")))||this._handleFilterApply())},this._handleResizeMove=e=>{if(!this._resizing)return;const t=this._model.columns.find((e=>e.id===this._resizing.columnId));if(t){const i=this._resizing.startWidth+(e.clientX-this._resizing.startX);t.width=`${Math.min(900,Math.max(50,i))}px`,this.requestUpdate()}},this._handleResizeEnd=()=>{this._resizing=null,document.removeEventListener("mousemove",this._handleResizeMove),document.removeEventListener("mouseup",this._handleResizeEnd)}}connectedCallback(){super.connectedCallback(),this.classList.toggle("kr-table--scroll-overlay","overlay"===this._scrollStyle),this.classList.toggle("kr-table--scroll-edge","edge"===this._scrollStyle),this._fetch(),this._initRefresh(),document.addEventListener("click",this._handleClickOutside),this._resizeObserver=new ResizeObserver((()=>{this._searchPositionLocked=!1,this._updateSearchPosition()})),this._resizeObserver.observe(this)}disconnectedCallback(){super.disconnectedCallback(),clearInterval(this._refreshTimer),document.removeEventListener("click",this._handleClickOutside),this._resizeObserver?.disconnect()}willUpdate(e){e.has("def")&&(this._model=new tt,this.def.title&&(this._model.title=this.def.title),this.def.actions&&(this._model.actions=this.def.actions),this.def.data&&(this._model.data=this.def.data),this.def.dataSource&&(this._model.dataSource=this.def.dataSource),"number"==typeof this.def.refreshInterval&&(this._model.refreshInterval=this.def.refreshInterval),"number"==typeof this.def.pageSize&&(this._model.pageSize=this.def.pageSize),this.def.rowClickable&&(this._model.rowClickable=this.def.rowClickable),this.def.rowHref&&(this._model.rowHref=this.def.rowHref),this._model.columns=this.def.columns.map((e=>{const t={...e,filter:null};return t.type||(t.type="string"),"actions"===t.type?(t.label=e.label??"",t.sticky="right",t.resizable=!1,t):((e.filterable||e.facetable)&&(t.filter=new Je,t.filter.field=e.id,t.filter.type=t.type,e.filter?(t.filter.setOperator(e.filter.operator),t.filter.setValue(e.filter.value)):e.facetable&&!e.filterable?(t.filter.operator="in",t.filter.value=[]):"string"===t.filter.type&&(t.filter.operator="contains")),t)})),this.def.displayedColumns?this._model.displayedColumns=this.def.displayedColumns:this._model.displayedColumns=this._model.columns.map((e=>e.id)),this._fetch(),this._initRefresh())}updated(e){this._updateScrollFlags(),this._syncSlottedContent()}_syncSlottedContent(){const e=this.getDisplayedColumns().filter((e=>e.render));e.length&&(this.querySelectorAll('[slot^="cell-"]').forEach((e=>e.remove())),this._data.forEach(((t,i)=>{e.forEach((e=>{const s=e.render(t);if(!s)return;const o=document.createElement("span");o.slot=`cell-${i}-${e.id}`,"actions"===e.type&&(o.style.display="flex",o.style.gap="8px"),"string"==typeof s?o.innerHTML=s:re(s,o),this.appendChild(o)}))})))}refresh(){this._fetch()}goToPrevPage(){this._page>1&&(this._page--,this._fetch())}goToNextPage(){this._page<this._totalPages&&(this._page++,this._fetch())}goToPage(e){e>=1&&e<=this._totalPages&&(this._page=e,this._fetch())}_toSolrData(){const e={page:this._page-1,size:this._pageSize,sorts:this._sorts,filterFields:[],queryFields:[],facetFields:[]};for(const t of this._model.columns){if(!t.filter||t.filter.isEmpty()||!t.filter.isValid())continue;const i=t.filter.toSolrData();!t.facetable||"in"!==t.filter.operator&&"n_in"!==t.filter.operator||(i.tagged=!0),e.filterFields.push(i)}for(const t of this._model.columns)t.facetable&&e.facetFields.push({name:t.id,type:"FIELD",limit:100,sort:"count",minimumCount:1});return this._searchQuery?.trim().length&&e.queryFields.push({name:"_text_",operation:"IS",value:Xe(this._searchQuery,!1)}),e}_toDbParams(){const e={page:this._page-1,size:this._pageSize,sorts:this._sorts,filterFields:[],queryFields:[],facetFields:[]};for(const t of this._model.columns)t.filter&&!t.filter.isEmpty()&&t.filter.isValid()&&e.filterFields.push(t.filter.toDbParams());return this._searchQuery?.trim().length&&this._model.columns.filter((e=>e.searchable)).forEach((t=>{e.queryFields.push({name:t.id,operation:"CONTAINS",value:this._searchQuery,and:!1})})),e}_fetch(){if(this._model.data)return this._data=this._model.data,this._totalItems=this._model.data.length,this._totalPages=Math.ceil(this._model.data.length/this._pageSize),void(this._dataState="success");if(!this._model.dataSource)return;let t;this._dataState="loading",t="db"===this._model.dataSource.mode?this._toDbParams():this._toSolrData(),this._model.dataSource.fetch(t).then((e=>{switch(this._model.dataSource?.mode){case"opensearch":throw Error("Opensearch not supported yet");case"db":{const t=e;this._data=t.data.content,this._totalItems=t.data.totalElements,this._totalPages=t.data.totalPages,this._pageSize=t.data.size;break}default:{const t=e;this._data=t.data.content,this._totalItems=t.data.totalElements,this._totalPages=t.data.totalPages,this._pageSize=t.data.size,this._parseFacetResults(t)}}this._dataState="success",this._updateSearchPosition()})).catch((t=>{this._dataState="error",e.KRSnackbar.show({message:t instanceof Error?t.message:"Failed to load data",type:"error"})}))}_parseFacetResults(e){if(e.data.facetFields){for(const t of this._model.columns){if(!t.facetable)continue;const i=e.data.facetFields[t.id];if(!i){this._buckets.set(t.id,[]);continue}const s=[];for(const e of i){let i=e.name;"boolean"===t.type&&"string"==typeof e.name&&("true"===e.name?i=!0:"false"===e.name&&(i=!1)),null===e.name&&e.count>0&&s.unshift({val:null,count:e.count}),null!==e.name&&s.push({val:i,count:e.count})}if(t.filter&&("in"===t.filter.operator||"n_in"===t.filter.operator)&&Array.isArray(t.filter.value))for(const e of t.filter.value)s.some((t=>t.val===e))||s.push({val:e,count:0});this._buckets.set(t.id,s)}this._buckets=new Map(this._buckets)}}_initRefresh(){clearInterval(this._refreshTimer),this._model.refreshInterval&&this._model.refreshInterval>0&&(this._refreshTimer=window.setInterval((()=>{this._fetch()}),this._model.refreshInterval))}_handleSearch(e){const t=e.target;this._searchQuery=t.value,this._page=1,this._fetch()}_getGridTemplateColumns(){return this.getDisplayedColumns().map((e=>e.width?e.width:"actions"===e.type?"max-content":"minmax(80px, auto)")).join(" ")}_updateSearchPosition(){if(this._searchPositionLocked)return;const e=this.shadowRoot?.querySelector(".search"),t=e?.querySelector(".search-field");e&&t&&(e.style.justifyContent="center",t.style.marginLeft="",requestAnimationFrame((()=>{const i=e.getBoundingClientRect(),s=t.getBoundingClientRect().left-i.left;e.style.justifyContent="flex-start",t.style.marginLeft=`${s}px`,this._searchPositionLocked=!0})))}_toggleColumnPicker(){this._columnPickerOpen=!this._columnPickerOpen}_toggleColumn(e){this._model.displayedColumns.includes(e)?this._model.displayedColumns=this._model.displayedColumns.filter((t=>t!==e)):this._model.displayedColumns=[...this._model.displayedColumns,e],this.requestUpdate()}_handleRowMouseDown(){this._model.rowClickable&&window.getSelection()?.removeAllRanges()}_handleRowClick(e,t){if(!this._model.rowClickable)return;const i=window.getSelection();i&&i.toString().length>0||this.dispatchEvent(new CustomEvent("row-click",{detail:{row:e,rowIndex:t},bubbles:!0,composed:!0}))}getDisplayedColumns(){return this._model.displayedColumns.map((e=>this._model.columns.find((t=>t.id===e)))).sort(((e,t)=>"actions"===e.type&&"actions"!==t.type?1:"actions"!==e.type&&"actions"===t.type?-1:0))}_handleScroll(e){const t=e.target;this._canScrollLeft=t.scrollLeft>0,this._canScrollRight=t.scrollLeft<t.scrollWidth-t.clientWidth-1}_updateScrollFlags(){const e=this.shadowRoot?.querySelector(".content");e&&(this._canScrollLeft=e.scrollLeft>0,this._canScrollRight=e.scrollWidth>e.clientWidth&&e.scrollLeft<e.scrollWidth-e.clientWidth-1,this._canScrollHorizontal=e.scrollWidth>e.clientWidth),this.classList.toggle("kr-table--scroll-left-available",this._canScrollLeft),this.classList.toggle("kr-table--scroll-right-available",this._canScrollRight),this.classList.toggle("kr-table--scroll-horizontal-available",this._canScrollHorizontal),this.classList.toggle("kr-table--sticky-left",this.getDisplayedColumns().some((e=>"left"===e.sticky))),this.classList.toggle("kr-table--sticky-right",this.getDisplayedColumns().some((e=>"right"===e.sticky)))}_handleResizeStart(e,t){e.preventDefault();const i=this.shadowRoot?.querySelector(`.header-cell[data-column-id="${t}"]`);this._resizing={columnId:t,startX:e.clientX,startWidth:i?.offsetWidth||200},document.addEventListener("mousemove",this._handleResizeMove),document.addEventListener("mouseup",this._handleResizeEnd)}_handleSortClick(e,t){if(e.shiftKey){const e=this._sorts.findIndex((e=>e.sortBy===t.id));if(-1===e)this._sorts.push({sortBy:t.id,sortDirection:"asc"});else{const t=this._sorts[e];"asc"===t.sortDirection?t.sortDirection="desc":this._sorts.splice(e,1)}this.requestUpdate()}else{let e=null;1===this._sorts.length&&(e=this._sorts.find((e=>e.sortBy===t.id))),e?"asc"===e.sortDirection?this._sorts=[{sortBy:t.id,sortDirection:"desc"}]:this._sorts=[]:this._sorts=[{sortBy:t.id,sortDirection:"asc"}]}this._page=1,this._fetch()}_renderSortIndicator(e){if(!e.sortable)return V;const t=this._sorts.findIndex((t=>t.sortBy===e.id));if(-1===t)return F`
1483
1483
  <span class="header-cell__sort" @click=${t=>this._handleSortClick(t,e)}>
1484
1484
  <svg class="header-cell__sort-arrow header-cell__sort-arrow--ghost" viewBox="0 0 24 24" fill="currentColor">
1485
1485
  <path d="M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"/>
@@ -1610,7 +1610,7 @@ const ze="important",Oe=" !"+ze,Ke=xe(class extends ke{constructor(e){if(super(e
1610
1610
  @input=${t=>this._handleFilterNumberEndChange(t,e)}
1611
1611
  @keydown=${t=>this._handleFilterTextKeydown(t,e)}
1612
1612
  />
1613
- `:"in"===e.filter.operator?F`
1613
+ `:"in"===e.filter.operator||"n_in"===e.filter.operator?F`
1614
1614
  <textarea
1615
1615
  class="filter-panel__textarea"
1616
1616
  rows="3"