@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
5 lines • 5.71 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import{r as e,h as t,g as s}from"./index-BQlHOxik.js";import{a as i}from"./tslib.es6-QNbPBOk5.js";import{p as l,a,q as n,r as o,b as d,h as c}from"./component-names-Dy77vq43.js";import{t as r}from"./i18n-Br16IAnY.js";import{d as h,K as b}from"./events-VVvk1win.js";import"./common-Cx_AGO_M.js";import"./i18n-B2d_exHc.js";const u=e=>Number.isFinite(e)&&e!==undefined&&e>0?e:undefined;const _=class{constructor(t){e(this,t);this.headerCells=[];this.editingHeaderCells=[];this.errorMessage=null;this.translateTableSettings=r("kol-table-settings");this.translateTableSettingsCancel=r("kol-table-settings-cancel");this.translateTableSettingsApply=r("kol-table-settings-apply");this.translateErrorAllInvisible=r("kol-table-settings-error-all-invisible");this.translateColumnNotHidable=r("kol-table-settings-column-not-hidable");this._horizontalHeaderCells=[]}handleHeaderCellsChange(e){this.headerCells=e.map((e=>[...e]));this.editingHeaderCells=e.map((e=>e.map((e=>Object.assign({},e)))))}componentWillLoad(){this.handleHeaderCellsChange(this._horizontalHeaderCells)}getPrimaryRow(){var e;return(e=this.editingHeaderCells[this.editingHeaderCells.length-1])!==null&&e!==void 0?e:[]}updatePrimaryRow(e){this.editingHeaderCells=this.editingHeaderCells.map(((t,s,i)=>s===i.length-1?e:t))}moveColumn(e,t){const s=[...this.getPrimaryRow()];const i=s.findIndex((t=>t.key===e));if(i===-1)return;let l;if(t==="up"){if(i===0)return;l=i-1}else{if(i===s.length-1)return;l=i+1}const[a]=s.splice(i,1);s.splice(l,0,a);this.updatePrimaryRow(s)}handleVisibilityChange(e,t){const s=this.getPrimaryRow().map((s=>s.key===e&&s.hidable!==false?Object.assign(Object.assign({},s),{visible:Boolean(t)}):s));this.updatePrimaryRow(s)}handleWidthChange(e,t){const s=this.getPrimaryRow().map((s=>s.key===e&&s.resizable!==false?Object.assign(Object.assign({},s),{width:Number(t)}):s));this.updatePrimaryRow(s)}handleCancel(){var e;this.editingHeaderCells=this.headerCells.map((e=>[...e]));this.errorMessage=null;void((e=this.popoverRef)===null||e===void 0?void 0:e.hidePopover())}handleSubmit(e){var t;e.preventDefault();const s=this.getPrimaryRow();const l=s.some((e=>e.visible!==false));if(!l){this.errorMessage=this.translateErrorAllInvisible;return}else if(this.host){this.errorMessage=null;this.headerCells=this.editingHeaderCells.map((e=>e.map((e=>Object.assign({},e)))));const e=this.editingHeaderCells.map((e=>e.map((e=>{const t=e,{hidable:s,resizable:l,sortable:a,visible:n,width:o}=t,d=i(t,["hidable","resizable","sortable","visible","width"]);const c=Object.assign({},d);if(n!==undefined)c.visible=n;if(s!==undefined)c.hidable=s;if(a!==undefined)c.sortable=a;if(l!==undefined)c.resizable=l;if(o!==undefined&&o!==null)c.width=o;return c}))));h(this.host,b.changeHeaderCells,e);void((t=this.popoverRef)===null||t===void 0?void 0:t.hidePopover())}}render(){const e=this.getPrimaryRow();return t(c,{key:"47831336493b2b1455a9fb3033a7cfd2c0326bc8",ref:e=>this.popoverRef=e,class:"kol-table-settings",_icons:"kolicon-settings",_label:this.translateTableSettings,_popoverAlign:"top",_hideLabel:true},t("div",{key:"211428e2280c4277f22457101db760f291ea3b3c",class:"kol-table-settings__content"},t(l,{key:"1944bb47d22317f1957fafe9838dcca62f677040",_label:this.translateTableSettings,_level:0}),this.errorMessage&&t(a,{key:"1bf58753eee563a299905c0438e406dd69fbba1a",_type:"error",_label:this.errorMessage,_variant:"msg",class:"kol-table-settings__error-message"}),t("form",{key:"f0789d72f4f2a784a2d5171f7b29633c367b5878",onSubmit:this.handleSubmit.bind(this)},t("div",{key:"aa906b2c0d984c0cf4cdd3a27df0754cf36485b0",class:"kol-table-settings__columns-container"},t("div",{key:"edb6a15875d74f7828c8fdb8a271c4cf65a728c8",class:"kol-table-settings__columns"},e.map(((s,i)=>t("div",{key:s.key,class:"kol-table-settings__column"},t(n,{_checked:s.visible!==false,_label:`${s.label}${s.hidable===false?` (${this.translateColumnNotHidable})`:""}`,_value:true,_hideLabel:true,_disabled:s.hidable===false,_on:{onInput:(e,t)=>{var i;return this.handleVisibilityChange((i=s.key)!==null&&i!==void 0?i:"",t)}}}),t("span",{class:"kol-table-settings__column-label"},s.label),t(o,{_hideLabel:true,_value:u(s.width),_label:r("kol-table-settings-column-width",{placeholders:{column:s.label}}),_min:1,_disabled:s.resizable===false,_on:{onInput:(e,t)=>{var i;return this.handleWidthChange((i=s.key)!==null&&i!==void 0?i:"",t)}}}),t(d,{_icons:"kolicon-chevron-up",_label:r("kol-table-settings-move-up",{placeholders:{column:s.label}}),_hideLabel:true,_variant:"ghost",_on:{onClick:()=>{var e;return this.moveColumn((e=s.key)!==null&&e!==void 0?e:"","up")}},_disabled:s.sortable===false||i===0,"data-testid":"table-settings-move-up"}),t(d,{_icons:"kolicon-chevron-down",_label:r("kol-table-settings-move-down",{placeholders:{column:s.label}}),_hideLabel:true,_variant:"ghost",_on:{onClick:()=>{var e;return this.moveColumn((e=s.key)!==null&&e!==void 0?e:"","down")}},_disabled:s.sortable===false||i===e.length-1,"data-testid":"table-settings-move-down"})))))),t("div",{key:"95e16a238529a4cc22351c50153f0fd105321dd5",class:"kol-table-settings__actions"},t(d,{key:"b67cae11ce5ee0d1d3ad3cfe09a6bcbd273d99c9",_label:this.translateTableSettingsCancel,_variant:"secondary",_on:{onClick:()=>this.handleCancel()},"data-testid":"table-settings-cancel"}),t(d,{key:"3b119117b1303290c78297c981738696042c5fa4",_label:this.translateTableSettingsApply,_variant:"primary",_type:"submit","data-testid":"table-settings-apply"})))))}get host(){return s(this)}static get watchers(){return{_horizontalHeaderCells:["handleHeaderCellsChange"]}}};export{_ as kol_table_settings_wc};
//# sourceMappingURL=kol-table-settings-wc.entry.js.map