@livenetworks/ashlar 1.4.1 → 1.5.1
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.
- package/js/ln-data-table/ln-data-table.js +1 -1
- package/js/ln-data-table/src/ln-data-table.js +0 -16
- package/js/ln-filter/README.md +99 -99
- package/js/ln-table/ln-table-sort.js +1 -1
- package/js/ln-table/src/ln-table-sort.js +156 -168
- package/package.json +3 -2
- package/scss/components/_filter.scss +25 -0
- package/scss/components/_ln-table.scss +1 -2
- package/scss/components/_table.scss +55 -1
- package/scss/config/mixins/_diagnostics.scss +37 -0
- package/scss/config/mixins/_filter.scss +49 -0
- package/scss/config/mixins/_index.scss +2 -1
- package/scss/config/mixins/_ln-table.scss +10 -91
- package/scss/config/mixins/_table.scss +202 -33
- package/scss/ln-ashlar-dev.scss +21 -0
- package/scss/ln-ashlar.scss +1 -1
- package/scss/components/_data-table.scss +0 -83
- package/scss/config/mixins/_data-table.scss +0 -346
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";const x={};function F(o,r){x[o]||(x[o]=document.querySelector('[data-ln-template="'+o+'"]'));const _=x[o];return _?_.content.cloneNode(!0):(console.warn("["+r+'] Template "'+o+'" not found'),null)}function m(o,r,_){o.dispatchEvent(new CustomEvent(r,{bubbles:!0,detail:_||{}}))}function D(o,r){if(!o||!r)return o;const _=o.querySelectorAll("[data-ln-field]");for(let u=0;u<_.length;u++){const a=_[u],g=a.getAttribute("data-ln-field");r[g]!=null&&(a.textContent=r[g])}const y=o.querySelectorAll("[data-ln-attr]");for(let u=0;u<y.length;u++){const a=y[u],g=a.getAttribute("data-ln-attr").split(",");for(let e=0;e<g.length;e++){const t=g[e].trim().split(":");if(t.length!==2)continue;const n=t[0].trim(),l=t[1].trim();r[l]!=null&&a.setAttribute(n,r[l])}}const C=o.querySelectorAll("[data-ln-show]");for(let u=0;u<C.length;u++){const a=C[u],g=a.getAttribute("data-ln-show");g in r&&a.classList.toggle("hidden",!r[g])}const S=o.querySelectorAll("[data-ln-class]");for(let u=0;u<S.length;u++){const a=S[u],g=a.getAttribute("data-ln-class").split(",");for(let e=0;e<g.length;e++){const t=g[e].trim().split(":");if(t.length!==2)continue;const n=t[0].trim(),l=t[1].trim();l in r&&a.classList.toggle(n,!!r[l])}}return o}function T(o,r){if(!o||!r)return o;const _=document.createTreeWalker(o,NodeFilter.SHOW_TEXT);for(;_.nextNode();){const y=_.currentNode;y.textContent.indexOf("{{")!==-1&&(y.textContent=y.textContent.replace(/\{\{\s*(\w+)\s*\}\}/g,function(C,S){return r[S]!==void 0?r[S]:""}))}return o}function R(o,r){if(!document.body){document.addEventListener("DOMContentLoaded",function(){R(o,r)}),console.warn("["+r+'] Script loaded before <body> — add "defer" to your <script> tag');return}o()}function E(o,r,_){if(o){const y=o.querySelector('[data-ln-template="'+r+'"]');if(y)return y.content.cloneNode(!0)}return F(r,_)}function I(o,r,_,y){if(o.nodeType!==1)return;const S=r.indexOf("[")!==-1||r.indexOf(".")!==-1||r.indexOf("#")!==-1?r:"["+r+"]",u=Array.from(o.querySelectorAll(S));o.matches&&o.matches(S)&&u.push(o);for(const a of u)a[_]||(a[_]=new y(a))}function O(o,r,_,y,C={}){const S=C.extraAttributes||[],u=C.onAttributeChange||null,a=C.onInit||null;function g(e){const t=e||document.body;I(t,o,r,_),a&&a(t)}return R(function(){const e=new MutationObserver(function(n){for(let l=0;l<n.length;l++){const i=n[l];if(i.type==="childList"){for(let s=0;s<i.addedNodes.length;s++){const c=i.addedNodes[s];c.nodeType===1&&(I(c,o,r,_),a&&a(c))}for(let s=0;s<i.removedNodes.length;s++){const c=i.removedNodes[s];if(c.nodeType===1){const f=o.indexOf("[")!==-1||o.indexOf(".")!==-1||o.indexOf("#")!==-1?o:"["+o+"]",p=Array.from(c.querySelectorAll(f));c.matches&&c.matches(f)&&p.push(c);for(let A=0;A<p.length;A++){const v=p[A];if(!document.contains(v)){const w=v[r];w&&typeof w.destroy=="function"&&w.destroy()}}}}}else i.type==="attributes"&&(u&&i.target[r]?u(i.target,i.attributeName):(I(i.target,o,r,_),a&&a(i.target)))}});let t=[];if(o.indexOf("[")!==-1){const n=/\[([\w-]+)/g;let l;for(;(l=n.exec(o))!==null;)t.push(l[1])}else t.push(o);e.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:t.concat(S)})},y),window[r]=g,document.readyState==="loading"?document.addEventListener("DOMContentLoaded",function(){g(document.body)}):g(document.body),g}const q={};function H(o,r){q[o]=r}function N(o){return q[o]||{ingress:r=>r,egress:r=>r}}typeof window<"u"&&(window.lnCore=window.lnCore||{},window.lnCore.registerDataMapper=H,window.lnCore.getDataMapper=N),(function(){const o="data-ln-data-table",r="lnDataTable";if(window[r]!==void 0)return;const C=typeof Intl<"u"?new Intl.NumberFormat(document.documentElement.lang||void 0):null;function S(e){return C?C.format(e):String(e)}function u(e){let t=e.parentElement;for(;t&&t!==document.body&&t!==document.documentElement;){const l=getComputedStyle(t).overflowY;if(l==="auto"||l==="scroll")return t;t=t.parentElement}return null}function a(e){this.dom=e,this.name=e.getAttribute(o)||"",this.table=e.querySelector("table"),this.tbody=e.querySelector("[data-ln-data-table-body]")||e.querySelector("tbody"),this.thead=e.querySelector("thead"),this.ths=this.thead?Array.from(this.thead.querySelectorAll("th")):[],this.isLoaded=!1,this.totalCount=0,this.visibleCount=0,this.currentSort=null,this.currentFilters={},this.currentSearch="",this.selectedIds=new Set,this._data=[],this._lastTotal=0,this._lastFiltered=0,this._filterOptions={},this._filterableFields=this.ths.filter(function(n){return n.getAttribute("data-ln-col")&&n.querySelector("[data-ln-col-filter]")}).map(function(n){return n.getAttribute("data-ln-col")}),this._virtual=!1,this._rowHeight=0,this._vStart=-1,this._vEnd=-1,this._rafId=null,this._scrollHandler=null,this._scrollContainer=null,this._totalSpan=e.querySelector("[data-ln-data-table-total]"),this._filteredSpan=e.querySelector("[data-ln-data-table-filtered]"),this._filteredSpan&&(this._filteredWrap=this._filteredSpan.parentElement!==e?this._filteredSpan.closest("[data-ln-data-table-filtered-wrap]")||this._filteredSpan.parentNode:null),this._selectedSpan=e.querySelector("[data-ln-data-table-selected]"),this._selectedSpan&&(this._selectedWrap=this._selectedSpan.parentElement!==e?this._selectedSpan.closest("[data-ln-data-table-selected-wrap]")||this._selectedSpan.parentNode:null);const t=this;return this._onSetData=function(n){const l=n.detail||{};t._data=l.data||[],t._lastTotal=l.total!=null?l.total:t._data.length,t._lastFiltered=l.filtered!=null?l.filtered:t._data.length,t.totalCount=t._lastTotal,t.visibleCount=t._lastFiltered,t.isLoaded=!0,t._updateFilterOptions(l.filterOptions),t._vStart=-1,t._vEnd=-1,t._renderRows(),t._updateFooter(),m(e,"ln-data-table:rendered",{table:t.name,total:t.totalCount,visible:t.visibleCount})},e.addEventListener("ln-data-table:set-data",this._onSetData),this._onSetLoading=function(n){const l=n.detail&&n.detail.loading;e.classList.toggle("ln-data-table--loading",!!l),l&&(t.isLoaded=!1)},e.addEventListener("ln-data-table:set-loading",this._onSetLoading),this._sortButtons=Array.from(e.querySelectorAll("[data-ln-col-sort]")),this._onSortClick=function(n){const l=n.target.closest("[data-ln-col-sort]");if(!l)return;const i=l.closest("th");if(!i)return;const s=i.getAttribute("data-ln-col");s&&t._handleSort(s,i)},this.thead&&this.thead.addEventListener("click",this._onSortClick),this._activeDropdown=null,this._onFilterClick=function(n){const l=n.target.closest("[data-ln-col-filter]");if(!l)return;n.stopPropagation();const i=l.closest("th");if(!i)return;const s=i.getAttribute("data-ln-col");if(s){if(t._activeDropdown&&t._activeDropdown.field===s){t._closeFilterDropdown();return}t._openFilterDropdown(s,i,l)}},this.thead&&this.thead.addEventListener("click",this._onFilterClick),this._onDocClick=function(){t._activeDropdown&&t._closeFilterDropdown()},document.addEventListener("click",this._onDocClick),this._onClearAll=function(n){n.target.closest("[data-ln-data-table-clear-all]")&&(t.currentFilters={},t._updateFilterIndicators(),m(e,"ln-data-table:clear-filters",{table:t.name}),t._requestData())},e.addEventListener("click",this._onClearAll),this._selectable=e.hasAttribute("data-ln-data-table-selectable"),this._selectableActive=!1,this._selectable&&this._enableSelection(),this._onRowClick=function(n){if(n.target.closest("[data-ln-row-select]")||n.target.closest("[data-ln-row-action]")||n.target.closest("a")||n.target.closest("button")||n.ctrlKey||n.metaKey||n.button===1)return;const l=n.target.closest("[data-ln-row]");if(!l)return;const i=l.getAttribute("data-ln-row-id"),s=l._lnRecord||{};m(e,"ln-data-table:row-click",{table:t.name,id:i,record:s})},this.tbody&&this.tbody.addEventListener("click",this._onRowClick),this._onRowAction=function(n){const l=n.target.closest("[data-ln-row-action]");if(!l)return;n.stopPropagation();const i=l.closest("[data-ln-row]");if(!i)return;const s=l.getAttribute("data-ln-row-action"),c=i.getAttribute("data-ln-row-id"),d=i._lnRecord||{};m(e,"ln-data-table:row-action",{table:t.name,id:c,action:s,record:d})},this.tbody&&this.tbody.addEventListener("click",this._onRowAction),this._searchInput=e.querySelector("[data-ln-data-table-search]"),this._searchInput&&(this._onSearchInput=function(){t.currentSearch=t._searchInput.value,m(e,"ln-data-table:search",{table:t.name,query:t.currentSearch}),t._requestData()},this._searchInput.addEventListener("input",this._onSearchInput)),this._focusedRowIndex=-1,this._onKeydown=function(n){if(!e.contains(document.activeElement)&&document.activeElement!==document.body||document.activeElement&&(document.activeElement.tagName==="INPUT"||document.activeElement.tagName==="TEXTAREA"))return;if(n.key==="/"){t._searchInput&&(n.preventDefault(),t._searchInput.focus());return}const l=t.tbody?Array.from(t.tbody.querySelectorAll("[data-ln-row]")):[];if(l.length)switch(n.key){case"ArrowDown":n.preventDefault(),t._focusedRowIndex=Math.min(t._focusedRowIndex+1,l.length-1),t._focusRow(l);break;case"ArrowUp":n.preventDefault(),t._focusedRowIndex=Math.max(t._focusedRowIndex-1,0),t._focusRow(l);break;case"Home":n.preventDefault(),t._focusedRowIndex=0,t._focusRow(l);break;case"End":n.preventDefault(),t._focusedRowIndex=l.length-1,t._focusRow(l);break;case"Enter":if(t._focusedRowIndex>=0&&t._focusedRowIndex<l.length){n.preventDefault();const i=l[t._focusedRowIndex];m(e,"ln-data-table:row-click",{table:t.name,id:i.getAttribute("data-ln-row-id"),record:i._lnRecord||{}})}break;case" ":if(t._selectable&&t._focusedRowIndex>=0&&t._focusedRowIndex<l.length){n.preventDefault();const i=l[t._focusedRowIndex].querySelector("[data-ln-row-select]");i&&(i.checked=!i.checked,i.dispatchEvent(new Event("change",{bubbles:!0})))}break;case"Escape":t._activeDropdown&&t._closeFilterDropdown();break}},document.addEventListener("keydown",this._onKeydown),m(e,"ln-data-table:request-data",{table:this.name,sort:this.currentSort,filters:this.currentFilters,search:this.currentSearch}),this}a.prototype._handleSort=function(e,t){let n;!this.currentSort||this.currentSort.field!==e?n="asc":this.currentSort.direction==="asc"?n="desc":n=null;for(let l=0;l<this.ths.length;l++)this.ths[l].classList.remove("ln-sort-asc","ln-sort-desc");n?(this.currentSort={field:e,direction:n},t.classList.add(n==="asc"?"ln-sort-asc":"ln-sort-desc")):this.currentSort=null,m(this.dom,"ln-data-table:sort",{table:this.name,field:e,direction:n}),this._requestData()},a.prototype._requestData=function(){m(this.dom,"ln-data-table:request-data",{table:this.name,sort:this.currentSort,filters:this.currentFilters,search:this.currentSearch})},a.prototype._updateSelectAll=function(){if(!this._selectAllCheckbox||!this.tbody)return;const e=this.tbody.querySelectorAll("[data-ln-row]");let t=e.length>0;for(let n=0;n<e.length;n++){const l=e[n].getAttribute("data-ln-row-id");if(l!=null&&!this.selectedIds.has(l)){t=!1;break}}this._selectAllCheckbox.checked=t},Object.defineProperty(a.prototype,"selectedCount",{get:function(){return this.selectedIds.size},set:function(){}}),a.prototype._enableSelection=function(){if(this._selectableActive)return;this._selectableActive=!0;const e=this;if(this._onSelectionChange=function(t){const n=t.target.closest("[data-ln-row-select]");if(!n)return;const l=n.closest("[data-ln-row]");if(!l)return;const i=l.getAttribute("data-ln-row-id");i!=null&&(n.checked?(e.selectedIds.add(i),l.classList.add("ln-row-selected")):(e.selectedIds.delete(i),l.classList.remove("ln-row-selected")),e.selectedCount=e.selectedIds.size,e._updateSelectAll(),e._updateFooter(),m(e.dom,"ln-data-table:select",{table:e.name,selectedIds:e.selectedIds,count:e.selectedCount}))},this.tbody&&this.tbody.addEventListener("change",this._onSelectionChange),this._selectAllCheckbox=this.dom.querySelector('[data-ln-col-select] input[type="checkbox"]')||this.dom.querySelector("[data-ln-col-select]"),this._selectAllCheckbox&&this._selectAllCheckbox.tagName==="TH"){const t=document.createElement("input");t.type="checkbox",t.setAttribute("aria-label","Select all"),this._selectAllCheckbox.appendChild(t),this._selectAllCheckbox=t}if(this._selectAllCheckbox&&(this._onSelectAll=function(){const t=e._selectAllCheckbox.checked,n=e.tbody?e.tbody.querySelectorAll("[data-ln-row]"):[];for(let l=0;l<n.length;l++){const i=n[l].getAttribute("data-ln-row-id"),s=n[l].querySelector("[data-ln-row-select]");i!=null&&(t?(e.selectedIds.add(i),n[l].classList.add("ln-row-selected")):(e.selectedIds.delete(i),n[l].classList.remove("ln-row-selected")),s&&(s.checked=t))}e.selectedCount=e.selectedIds.size,m(e.dom,"ln-data-table:select-all",{table:e.name,selected:t}),m(e.dom,"ln-data-table:select",{table:e.name,selectedIds:e.selectedIds,count:e.selectedCount}),e._updateFooter()},this._selectAllCheckbox.addEventListener("change",this._onSelectAll)),this.tbody){const t=this.tbody.querySelectorAll("[data-ln-row]");for(let n=0;n<t.length;n++){const l=t[n].querySelector("[data-ln-row-select]"),i=t[n].getAttribute("data-ln-row-id");l&&l.checked&&i!=null&&(this.selectedIds.add(i),t[n].classList.add("ln-row-selected"))}this.selectedCount=this.selectedIds.size,this.selectedCount>0&&this._updateSelectAll()}},a.prototype._disableSelection=function(){if(!this._selectableActive)return;this._selectableActive=!1,this.tbody&&this._onSelectionChange&&this.tbody.removeEventListener("change",this._onSelectionChange),this._selectAllCheckbox&&this._onSelectAll&&this._selectAllCheckbox.removeEventListener("change",this._onSelectAll);const e=this.dom.querySelector("[data-ln-col-select]");if(e){const t=e.querySelector('input[type="checkbox"]');t&&t.remove()}if(this._selectAllCheckbox=null,this.selectedIds.clear(),this.selectedCount=0,this.tbody){const t=this.tbody.querySelectorAll("[data-ln-row]");for(let n=0;n<t.length;n++){t[n].classList.remove("ln-row-selected");const l=t[n].querySelector("[data-ln-row-select]");l&&(l.checked=!1)}}this._updateFooter()},a.prototype._focusRow=function(e){for(let t=0;t<e.length;t++)e[t].classList.remove("ln-row-focused"),e[t].removeAttribute("tabindex");if(this._focusedRowIndex>=0&&this._focusedRowIndex<e.length){const t=e[this._focusedRowIndex];t.classList.add("ln-row-focused"),t.setAttribute("tabindex","0"),t.focus(),t.scrollIntoView({block:"nearest"})}},a.prototype._openFilterDropdown=function(e,t,n){this._closeFilterDropdown();const l=E(this.dom,this.name+"-column-filter","ln-data-table")||E(this.dom,"column-filter","ln-data-table");if(!l)return;const i=l.firstElementChild;if(!i)return;const s=this._getUniqueValues(e),c=i.querySelector("[data-ln-filter-options]"),d=i.querySelector("[data-ln-filter-search]"),f=this.currentFilters[e]||[],p=this;if(d&&s.length<=8&&d.classList.add("hidden"),c){const v=c.querySelector("[data-ln-filter-reset]");v&&(v.checked=f.length===0);const w=E(i,this.name+"-column-filter-item","ln-data-table")||E(i,"column-filter-item","ln-data-table");if(w)for(let h=0;h<s.length;h++){const b=s[h],k=w.cloneNode(!0);D(k,{value:b});const L=k.querySelector('input[type="checkbox"]');L&&(L.value=b,L.checked=f.length>0&&f.indexOf(b)!==-1),c.appendChild(k)}c.addEventListener("change",function(h){h.target.type==="checkbox"&&(p._applyFilterMutualExclusion(h.target,c),p._onFilterChange(e,c))})}d&&d.addEventListener("input",function(){const v=d.value.toLowerCase(),w=c.querySelectorAll("li");for(let h=0;h<w.length;h++){const b=w[h].textContent.toLowerCase();w[h].classList.toggle("hidden",v&&b.indexOf(v)===-1)}});const A=i.querySelector("[data-ln-filter-clear]");A&&A.addEventListener("click",function(){delete p.currentFilters[e],p._closeFilterDropdown(),p._updateFilterIndicators(),m(p.dom,"ln-data-table:filter",{table:p.name,field:e,values:[]}),p._requestData()}),t.appendChild(i),this._activeDropdown={field:e,th:t,el:i},i.addEventListener("click",function(v){v.stopPropagation()})},a.prototype._closeFilterDropdown=function(){this._activeDropdown&&(this._activeDropdown.el&&this._activeDropdown.el.parentNode&&this._activeDropdown.el.parentNode.removeChild(this._activeDropdown.el),this._activeDropdown=null)},a.prototype._applyFilterMutualExclusion=function(e,t){const n=e.hasAttribute("data-ln-filter-reset"),l=t.querySelector("[data-ln-filter-reset]"),i=t.querySelectorAll('input[type="checkbox"]:not([data-ln-filter-reset])');if(n){e.checked=!0;for(let s=0;s<i.length;s++)i[s].checked=!1}else if(e.checked)l&&(l.checked=!1);else{let s=!1;for(let c=0;c<i.length;c++)if(i[c].checked){s=!0;break}!s&&l&&(l.checked=!0)}},a.prototype._onFilterChange=function(e,t){const n=t.querySelector("[data-ln-filter-reset]"),l=t.querySelectorAll('input[type="checkbox"]:not([data-ln-filter-reset])'),i=[];for(let c=0;c<l.length;c++)l[c].checked&&i.push(l[c].value);const s=n&&n.checked||i.length===0;s?delete this.currentFilters[e]:this.currentFilters[e]=i,this._updateFilterIndicators(),m(this.dom,"ln-data-table:filter",{table:this.name,field:e,values:s?[]:i}),this._requestData()},a.prototype._updateFilterOptions=function(e){if(e!==null&&typeof e=="object"&&!Array.isArray(e)){const t=Object.keys(e);for(let n=0;n<t.length;n++){const l=t[n],i=e[l];if(!Array.isArray(i))continue;const s={},c=[];for(let d=0;d<i.length;d++){const f=String(i[d]);s[f]||(s[f]=!0,c.push(f))}this._filterOptions[l]=c.sort()}}else{const t=this._filterableFields,n=this._data;for(let l=0;l<t.length;l++){const i=t[l];this._filterOptions[i]||(this._filterOptions[i]=[]);const s=this._filterOptions[i],c={};for(let d=0;d<s.length;d++)c[s[d]]=!0;for(let d=0;d<n.length;d++){const f=n[d][i];if(f!=null){const p=String(f);c[p]||(c[p]=!0,s.push(p))}}s.sort()}}},a.prototype._getUniqueValues=function(e){return(this._filterOptions[e]||[]).slice().sort()},a.prototype._updateFilterIndicators=function(){const e=this.ths;for(let t=0;t<e.length;t++){const n=e[t],l=n.getAttribute("data-ln-col");if(!l)continue;const i=n.querySelector("[data-ln-col-filter]");if(!i)continue;const s=this.currentFilters[l]&&this.currentFilters[l].length>0;i.classList.toggle("ln-filter-active",!!s)}},a.prototype._renderRows=function(){if(!this.tbody)return;const e=this._data,t=this._lastTotal,n=this._lastFiltered;if(t===0){this._disableVirtualScroll(),this._showEmptyState(this.name+"-empty");return}if(e.length===0||n===0){this._disableVirtualScroll(),this._showEmptyState(this.name+"-empty-filtered");return}e.length>200?(this._enableVirtualScroll(),this._renderVirtual()):(this._disableVirtualScroll(),this._renderAll())},a.prototype._renderAll=function(){const e=this._data,t=document.createDocumentFragment();for(let n=0;n<e.length;n++){const l=this._buildRow(e[n]);if(!l)break;t.appendChild(l)}this.tbody.textContent="",this.tbody.appendChild(t),this._selectable&&this._updateSelectAll()},a.prototype._buildRow=function(e){const t=E(this.dom,this.name+"-row","ln-data-table");if(!t)return null;const n=t.querySelector("[data-ln-row]")||t.firstElementChild;if(!n)return null;if(this._fillRow(n,e),n._lnRecord=e,e.id!=null&&n.setAttribute("data-ln-row-id",e.id),this._selectable&&e.id!=null&&this.selectedIds.has(String(e.id))){n.classList.add("ln-row-selected");const l=n.querySelector("[data-ln-row-select]");l&&(l.checked=!0)}return n},a.prototype._enableVirtualScroll=function(){if(this._virtual)return;this._virtual=!0,this._vStart=-1,this._vEnd=-1;const e=this;if(!this._rowHeight){const n=this._buildRow(this._data[0]);n&&(this.tbody.textContent="",this.tbody.appendChild(n),this._rowHeight=n.offsetHeight||40,this.tbody.textContent="")}this._scrollContainer=u(this.dom);const t=this._scrollContainer||window;this._scrollHandler=function(){e._rafId||(e._rafId=requestAnimationFrame(function(){e._rafId=null,e._renderVirtual()}))},t.addEventListener("scroll",this._scrollHandler,{passive:!0}),window.addEventListener("resize",this._scrollHandler,{passive:!0})},a.prototype._disableVirtualScroll=function(){this._virtual&&(this._virtual=!1,this._scrollHandler&&((this._scrollContainer||window).removeEventListener("scroll",this._scrollHandler),window.removeEventListener("resize",this._scrollHandler),this._scrollHandler=null),this._scrollContainer=null,this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=null),this._vStart=-1,this._vEnd=-1)},a.prototype._renderVirtual=function(){const e=this._data,t=e.length,n=this._rowHeight;if(!n||!t)return;const l=this.thead?this.thead.offsetHeight:0,i=this._scrollContainer;let s,c;if(i){const h=this.table.getBoundingClientRect(),b=i.getBoundingClientRect(),k=h.top-b.top+i.scrollTop+l;s=i.scrollTop-k,c=i.clientHeight}else{const k=this.table.getBoundingClientRect().top+window.scrollY+l;s=window.scrollY-k,c=window.innerHeight}let d=Math.max(0,Math.floor(s/n)-15);d=Math.min(d,t);const f=Math.min(d+Math.ceil(c/n)+30,t);if(d===this._vStart&&f===this._vEnd)return;this._vStart=d,this._vEnd=f;const p=this.ths.length||1,A=d*n,v=(t-f)*n,w=document.createDocumentFragment();if(A>0){const h=document.createElement("tr");h.className="ln-data-table__spacer",h.setAttribute("aria-hidden","true");const b=document.createElement("td");b.setAttribute("colspan",p),b.style.height=A+"px",h.appendChild(b),w.appendChild(h)}for(let h=d;h<f;h++){const b=this._buildRow(e[h]);b&&w.appendChild(b)}if(v>0){const h=document.createElement("tr");h.className="ln-data-table__spacer",h.setAttribute("aria-hidden","true");const b=document.createElement("td");b.setAttribute("colspan",p),b.style.height=v+"px",h.appendChild(b),w.appendChild(h)}this.tbody.textContent="",this.tbody.appendChild(w),this._selectable&&this._updateSelectAll()},a.prototype._fillRow=function(e,t){T(e,t);const n=e.querySelectorAll("[data-ln-cell-attr]");for(let l=0;l<n.length;l++){const i=n[l],s=i.getAttribute("data-ln-cell-attr").split(",");for(let c=0;c<s.length;c++){const d=s[c].trim().split(":");if(d.length!==2)continue;const f=d[0].trim(),p=d[1].trim();t[f]!=null&&i.setAttribute(p,t[f])}}},a.prototype._showEmptyState=function(e){const t=E(this.dom,e,"ln-data-table");this.tbody.textContent="",t&&this.tbody.appendChild(t)},a.prototype._updateFooter=function(){const e=this._lastTotal,t=this._lastFiltered,n=t<e;if(this._totalSpan&&(this._totalSpan.textContent=S(e)),this._filteredSpan&&(this._filteredSpan.textContent=n?S(t):""),this._filteredWrap&&this._filteredWrap.classList.toggle("hidden",!n),this._selectedSpan){const l=this.selectedIds.size;this._selectedSpan.textContent=l>0?S(l):"",this._selectedWrap&&this._selectedWrap.classList.toggle("hidden",l===0)}},a.prototype.destroy=function(){this.dom[r]&&(this.dom.removeEventListener("ln-data-table:set-data",this._onSetData),this.dom.removeEventListener("ln-data-table:set-loading",this._onSetLoading),this.thead&&(this.thead.removeEventListener("click",this._onSortClick),this.thead.removeEventListener("click",this._onFilterClick)),document.removeEventListener("click",this._onDocClick),document.removeEventListener("keydown",this._onKeydown),this._searchInput&&this._searchInput.removeEventListener("input",this._onSearchInput),this.tbody&&(this.tbody.removeEventListener("click",this._onRowClick),this.tbody.removeEventListener("click",this._onRowAction)),this._onSelectionChange&&this.tbody&&this.tbody.removeEventListener("change",this._onSelectionChange),this._selectAllCheckbox&&this._onSelectAll&&this._selectAllCheckbox.removeEventListener("change",this._onSelectAll),this.dom.removeEventListener("click",this._onClearAll),this._closeFilterDropdown(),this._disableVirtualScroll(),this._data=[],delete this.dom[r])};function g(e,t){const n=e[r];if(n&&t==="data-ln-data-table-selectable"){const l=e.hasAttribute("data-ln-data-table-selectable");l!==n._selectable&&(n._selectable=l,l?n._enableSelection():n._disableSelection())}}O(o,r,a,"ln-data-table",{extraAttributes:["data-ln-data-table-selectable"],onAttributeChange:g})})()})();
|
|
1
|
+
(function(){"use strict";const E={};function q(o,r){E[o]||(E[o]=document.querySelector('[data-ln-template="'+o+'"]'));const p=E[o];return p?p.content.cloneNode(!0):(console.warn("["+r+'] Template "'+o+'" not found'),null)}function v(o,r,p){o.dispatchEvent(new CustomEvent(r,{bubbles:!0,detail:p||{}}))}function D(o,r){if(!o||!r)return o;const p=o.querySelectorAll("[data-ln-field]");for(let h=0;h<p.length;h++){const a=p[h],b=a.getAttribute("data-ln-field");r[b]!=null&&(a.textContent=r[b])}const m=o.querySelectorAll("[data-ln-attr]");for(let h=0;h<m.length;h++){const a=m[h],b=a.getAttribute("data-ln-attr").split(",");for(let e=0;e<b.length;e++){const t=b[e].trim().split(":");if(t.length!==2)continue;const n=t[0].trim(),l=t[1].trim();r[l]!=null&&a.setAttribute(n,r[l])}}const A=o.querySelectorAll("[data-ln-show]");for(let h=0;h<A.length;h++){const a=A[h],b=a.getAttribute("data-ln-show");b in r&&a.classList.toggle("hidden",!r[b])}const y=o.querySelectorAll("[data-ln-class]");for(let h=0;h<y.length;h++){const a=y[h],b=a.getAttribute("data-ln-class").split(",");for(let e=0;e<b.length;e++){const t=b[e].trim().split(":");if(t.length!==2)continue;const n=t[0].trim(),l=t[1].trim();l in r&&a.classList.toggle(n,!!r[l])}}return o}function F(o,r){if(!o||!r)return o;const p=document.createTreeWalker(o,NodeFilter.SHOW_TEXT);for(;p.nextNode();){const m=p.currentNode;m.textContent.indexOf("{{")!==-1&&(m.textContent=m.textContent.replace(/\{\{\s*(\w+)\s*\}\}/g,function(A,y){return r[y]!==void 0?r[y]:""}))}return o}function L(o,r){if(!document.body){document.addEventListener("DOMContentLoaded",function(){L(o,r)}),console.warn("["+r+'] Script loaded before <body> — add "defer" to your <script> tag');return}o()}function x(o,r,p){if(o){const m=o.querySelector('[data-ln-template="'+r+'"]');if(m)return m.content.cloneNode(!0)}return q(r,p)}function I(o,r,p,m){if(o.nodeType!==1)return;const y=r.indexOf("[")!==-1||r.indexOf(".")!==-1||r.indexOf("#")!==-1?r:"["+r+"]",h=Array.from(o.querySelectorAll(y));o.matches&&o.matches(y)&&h.push(o);for(const a of h)a[p]||(a[p]=new m(a))}function T(o,r,p,m,A={}){const y=A.extraAttributes||[],h=A.onAttributeChange||null,a=A.onInit||null;function b(e){const t=e||document.body;I(t,o,r,p),a&&a(t)}return L(function(){const e=new MutationObserver(function(n){for(let l=0;l<n.length;l++){const i=n[l];if(i.type==="childList"){for(let s=0;s<i.addedNodes.length;s++){const c=i.addedNodes[s];c.nodeType===1&&(I(c,o,r,p),a&&a(c))}for(let s=0;s<i.removedNodes.length;s++){const c=i.removedNodes[s];if(c.nodeType===1){const f=o.indexOf("[")!==-1||o.indexOf(".")!==-1||o.indexOf("#")!==-1?o:"["+o+"]",w=Array.from(c.querySelectorAll(f));c.matches&&c.matches(f)&&w.push(c);for(let S=0;S<w.length;S++){const C=w[S];if(!document.contains(C)){const _=C[r];_&&typeof _.destroy=="function"&&_.destroy()}}}}}else i.type==="attributes"&&(h&&i.target[r]?h(i.target,i.attributeName):(I(i.target,o,r,p),a&&a(i.target)))}});let t=[];if(o.indexOf("[")!==-1){const n=/\[([\w-]+)/g;let l;for(;(l=n.exec(o))!==null;)t.push(l[1])}else t.push(o);e.observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:t.concat(y)})},m),window[r]=b,document.readyState==="loading"?document.addEventListener("DOMContentLoaded",function(){b(document.body)}):b(document.body),b}const R={};function O(o,r){R[o]=r}function H(o){return R[o]||{ingress:r=>r,egress:r=>r}}typeof window<"u"&&(window.lnCore=window.lnCore||{},window.lnCore.registerDataMapper=O,window.lnCore.getDataMapper=H),(function(){const o="data-ln-data-table",r="lnDataTable";if(window[r]!==void 0)return;const A=typeof Intl<"u"?new Intl.NumberFormat(document.documentElement.lang||void 0):null;function y(e){return A?A.format(e):String(e)}function h(e){let t=e.parentElement;for(;t&&t!==document.body&&t!==document.documentElement;){const l=getComputedStyle(t).overflowY;if(l==="auto"||l==="scroll")return t;t=t.parentElement}return null}function a(e){this.dom=e,this.name=e.getAttribute(o)||"",this.table=e.querySelector("table"),this.tbody=e.querySelector("[data-ln-data-table-body]")||e.querySelector("tbody"),this.thead=e.querySelector("thead"),this.ths=this.thead?Array.from(this.thead.querySelectorAll("th")):[],this.isLoaded=!1,this.totalCount=0,this.visibleCount=0,this.currentSort=null,this.currentFilters={},this.currentSearch="",this.selectedIds=new Set,this._data=[],this._lastTotal=0,this._lastFiltered=0,this._filterOptions={},this._filterableFields=this.ths.filter(function(n){return n.getAttribute("data-ln-col")&&n.querySelector("[data-ln-col-filter]")}).map(function(n){return n.getAttribute("data-ln-col")}),this._virtual=!1,this._rowHeight=0,this._vStart=-1,this._vEnd=-1,this._rafId=null,this._scrollHandler=null,this._scrollContainer=null,this._totalSpan=e.querySelector("[data-ln-data-table-total]"),this._filteredSpan=e.querySelector("[data-ln-data-table-filtered]"),this._filteredSpan&&(this._filteredWrap=this._filteredSpan.parentElement!==e?this._filteredSpan.closest("[data-ln-data-table-filtered-wrap]")||this._filteredSpan.parentNode:null),this._selectedSpan=e.querySelector("[data-ln-data-table-selected]"),this._selectedSpan&&(this._selectedWrap=this._selectedSpan.parentElement!==e?this._selectedSpan.closest("[data-ln-data-table-selected-wrap]")||this._selectedSpan.parentNode:null);const t=this;return this._onSetData=function(n){const l=n.detail||{};t._data=l.data||[],t._lastTotal=l.total!=null?l.total:t._data.length,t._lastFiltered=l.filtered!=null?l.filtered:t._data.length,t.totalCount=t._lastTotal,t.visibleCount=t._lastFiltered,t.isLoaded=!0,t._updateFilterOptions(l.filterOptions),t._vStart=-1,t._vEnd=-1,t._renderRows(),t._updateFooter(),v(e,"ln-data-table:rendered",{table:t.name,total:t.totalCount,visible:t.visibleCount})},e.addEventListener("ln-data-table:set-data",this._onSetData),this._onSetLoading=function(n){const l=n.detail&&n.detail.loading;e.classList.toggle("ln-data-table--loading",!!l),l&&(t.isLoaded=!1)},e.addEventListener("ln-data-table:set-loading",this._onSetLoading),this._sortButtons=Array.from(e.querySelectorAll("[data-ln-col-sort]")),this._onSortClick=function(n){const l=n.target.closest("[data-ln-col-sort]");if(!l)return;const i=l.closest("th");if(!i)return;const s=i.getAttribute("data-ln-col");s&&t._handleSort(s,i)},this.thead&&this.thead.addEventListener("click",this._onSortClick),this._activeDropdown=null,this._onFilterClick=function(n){const l=n.target.closest("[data-ln-col-filter]");if(!l)return;n.stopPropagation();const i=l.closest("th");if(!i)return;const s=i.getAttribute("data-ln-col");if(s){if(t._activeDropdown&&t._activeDropdown.field===s){t._closeFilterDropdown();return}t._openFilterDropdown(s,i,l)}},this.thead&&this.thead.addEventListener("click",this._onFilterClick),this._onDocClick=function(){t._activeDropdown&&t._closeFilterDropdown()},document.addEventListener("click",this._onDocClick),this._onClearAll=function(n){n.target.closest("[data-ln-data-table-clear-all]")&&(t.currentFilters={},t._updateFilterIndicators(),v(e,"ln-data-table:clear-filters",{table:t.name}),t._requestData())},e.addEventListener("click",this._onClearAll),this._selectable=e.hasAttribute("data-ln-data-table-selectable"),this._selectableActive=!1,this._selectable&&this._enableSelection(),this._onRowClick=function(n){if(n.target.closest("[data-ln-row-select]")||n.target.closest("[data-ln-row-action]")||n.target.closest("a")||n.target.closest("button")||n.ctrlKey||n.metaKey||n.button===1)return;const l=n.target.closest("[data-ln-row]");if(!l)return;const i=l.getAttribute("data-ln-row-id"),s=l._lnRecord||{};v(e,"ln-data-table:row-click",{table:t.name,id:i,record:s})},this.tbody&&this.tbody.addEventListener("click",this._onRowClick),this._onRowAction=function(n){const l=n.target.closest("[data-ln-row-action]");if(!l)return;n.stopPropagation();const i=l.closest("[data-ln-row]");if(!i)return;const s=l.getAttribute("data-ln-row-action"),c=i.getAttribute("data-ln-row-id"),d=i._lnRecord||{};v(e,"ln-data-table:row-action",{table:t.name,id:c,action:s,record:d})},this.tbody&&this.tbody.addEventListener("click",this._onRowAction),this._searchInput=e.querySelector("[data-ln-data-table-search]"),this._searchInput&&(this._onSearchInput=function(){t.currentSearch=t._searchInput.value,v(e,"ln-data-table:search",{table:t.name,query:t.currentSearch}),t._requestData()},this._searchInput.addEventListener("input",this._onSearchInput)),this._focusedRowIndex=-1,this._onKeydown=function(n){if(!e.contains(document.activeElement)&&document.activeElement!==document.body||document.activeElement&&(document.activeElement.tagName==="INPUT"||document.activeElement.tagName==="TEXTAREA"))return;if(n.key==="/"){t._searchInput&&(n.preventDefault(),t._searchInput.focus());return}const l=t.tbody?Array.from(t.tbody.querySelectorAll("[data-ln-row]")):[];if(l.length)switch(n.key){case"ArrowDown":n.preventDefault(),t._focusedRowIndex=Math.min(t._focusedRowIndex+1,l.length-1),t._focusRow(l);break;case"ArrowUp":n.preventDefault(),t._focusedRowIndex=Math.max(t._focusedRowIndex-1,0),t._focusRow(l);break;case"Home":n.preventDefault(),t._focusedRowIndex=0,t._focusRow(l);break;case"End":n.preventDefault(),t._focusedRowIndex=l.length-1,t._focusRow(l);break;case"Enter":if(t._focusedRowIndex>=0&&t._focusedRowIndex<l.length){n.preventDefault();const i=l[t._focusedRowIndex];v(e,"ln-data-table:row-click",{table:t.name,id:i.getAttribute("data-ln-row-id"),record:i._lnRecord||{}})}break;case" ":if(t._selectable&&t._focusedRowIndex>=0&&t._focusedRowIndex<l.length){n.preventDefault();const i=l[t._focusedRowIndex].querySelector("[data-ln-row-select]");i&&(i.checked=!i.checked,i.dispatchEvent(new Event("change",{bubbles:!0})))}break;case"Escape":t._activeDropdown&&t._closeFilterDropdown();break}},document.addEventListener("keydown",this._onKeydown),v(e,"ln-data-table:request-data",{table:this.name,sort:this.currentSort,filters:this.currentFilters,search:this.currentSearch}),this}a.prototype._handleSort=function(e,t){let n;!this.currentSort||this.currentSort.field!==e?n="asc":this.currentSort.direction==="asc"?n="desc":n=null;for(let l=0;l<this.ths.length;l++)this.ths[l].classList.remove("ln-sort-asc","ln-sort-desc");n?(this.currentSort={field:e,direction:n},t.classList.add(n==="asc"?"ln-sort-asc":"ln-sort-desc")):this.currentSort=null,v(this.dom,"ln-data-table:sort",{table:this.name,field:e,direction:n}),this._requestData()},a.prototype._requestData=function(){v(this.dom,"ln-data-table:request-data",{table:this.name,sort:this.currentSort,filters:this.currentFilters,search:this.currentSearch})},a.prototype._updateSelectAll=function(){if(!this._selectAllCheckbox||!this.tbody)return;const e=this.tbody.querySelectorAll("[data-ln-row]");let t=e.length>0;for(let n=0;n<e.length;n++){const l=e[n].getAttribute("data-ln-row-id");if(l!=null&&!this.selectedIds.has(l)){t=!1;break}}this._selectAllCheckbox.checked=t},Object.defineProperty(a.prototype,"selectedCount",{get:function(){return this.selectedIds.size},set:function(){}}),a.prototype._enableSelection=function(){if(this._selectableActive)return;this._selectableActive=!0;const e=this;if(this._onSelectionChange=function(t){const n=t.target.closest("[data-ln-row-select]");if(!n)return;const l=n.closest("[data-ln-row]");if(!l)return;const i=l.getAttribute("data-ln-row-id");i!=null&&(n.checked?(e.selectedIds.add(i),l.classList.add("ln-row-selected")):(e.selectedIds.delete(i),l.classList.remove("ln-row-selected")),e.selectedCount=e.selectedIds.size,e._updateSelectAll(),e._updateFooter(),v(e.dom,"ln-data-table:select",{table:e.name,selectedIds:e.selectedIds,count:e.selectedCount}))},this.tbody&&this.tbody.addEventListener("change",this._onSelectionChange),this._selectAllCheckbox=this.dom.querySelector('[data-ln-col-select] input[type="checkbox"]')||this.dom.querySelector("[data-ln-col-select]"),this._selectAllCheckbox&&this._selectAllCheckbox.tagName==="TH"){const t=document.createElement("input");t.type="checkbox",t.setAttribute("aria-label","Select all"),this._selectAllCheckbox.appendChild(t),this._selectAllCheckbox=t}if(this._selectAllCheckbox&&(this._onSelectAll=function(){const t=e._selectAllCheckbox.checked,n=e.tbody?e.tbody.querySelectorAll("[data-ln-row]"):[];for(let l=0;l<n.length;l++){const i=n[l].getAttribute("data-ln-row-id"),s=n[l].querySelector("[data-ln-row-select]");i!=null&&(t?(e.selectedIds.add(i),n[l].classList.add("ln-row-selected")):(e.selectedIds.delete(i),n[l].classList.remove("ln-row-selected")),s&&(s.checked=t))}e.selectedCount=e.selectedIds.size,v(e.dom,"ln-data-table:select-all",{table:e.name,selected:t}),v(e.dom,"ln-data-table:select",{table:e.name,selectedIds:e.selectedIds,count:e.selectedCount}),e._updateFooter()},this._selectAllCheckbox.addEventListener("change",this._onSelectAll)),this.tbody){const t=this.tbody.querySelectorAll("[data-ln-row]");for(let n=0;n<t.length;n++){const l=t[n].querySelector("[data-ln-row-select]"),i=t[n].getAttribute("data-ln-row-id");l&&l.checked&&i!=null&&(this.selectedIds.add(i),t[n].classList.add("ln-row-selected"))}this.selectedCount=this.selectedIds.size,this.selectedCount>0&&this._updateSelectAll()}},a.prototype._disableSelection=function(){if(!this._selectableActive)return;this._selectableActive=!1,this.tbody&&this._onSelectionChange&&this.tbody.removeEventListener("change",this._onSelectionChange),this._selectAllCheckbox&&this._onSelectAll&&this._selectAllCheckbox.removeEventListener("change",this._onSelectAll);const e=this.dom.querySelector("[data-ln-col-select]");if(e){const t=e.querySelector('input[type="checkbox"]');t&&t.remove()}if(this._selectAllCheckbox=null,this.selectedIds.clear(),this.selectedCount=0,this.tbody){const t=this.tbody.querySelectorAll("[data-ln-row]");for(let n=0;n<t.length;n++){t[n].classList.remove("ln-row-selected");const l=t[n].querySelector("[data-ln-row-select]");l&&(l.checked=!1)}}this._updateFooter()},a.prototype._focusRow=function(e){for(let t=0;t<e.length;t++)e[t].classList.remove("ln-row-focused"),e[t].removeAttribute("tabindex");if(this._focusedRowIndex>=0&&this._focusedRowIndex<e.length){const t=e[this._focusedRowIndex];t.classList.add("ln-row-focused"),t.setAttribute("tabindex","0"),t.focus(),t.scrollIntoView({block:"nearest"})}},a.prototype._openFilterDropdown=function(e,t,n){this._closeFilterDropdown();const l=x(this.dom,this.name+"-column-filter","ln-data-table")||x(this.dom,"column-filter","ln-data-table");if(!l)return;const i=l.firstElementChild;if(!i)return;const s=this._getUniqueValues(e),c=i.querySelector("[data-ln-filter-options]"),d=i.querySelector("[data-ln-filter-search]"),f=this.currentFilters[e]||[],w=this;if(d&&s.length<=8&&d.classList.add("hidden"),c){const S=c.querySelector("[data-ln-filter-reset]");S&&(S.checked=f.length===0);const C=x(i,this.name+"-column-filter-item","ln-data-table")||x(i,"column-filter-item","ln-data-table");if(C)for(let _=0;_<s.length;_++){const u=s[_],g=C.cloneNode(!0);D(g,{value:u});const k=g.querySelector('input[type="checkbox"]');k&&(k.value=u,k.checked=f.length>0&&f.indexOf(u)!==-1),c.appendChild(g)}c.addEventListener("change",function(_){_.target.type==="checkbox"&&(w._applyFilterMutualExclusion(_.target,c),w._onFilterChange(e,c))})}d&&d.addEventListener("input",function(){const S=d.value.toLowerCase(),C=c.querySelectorAll("li");for(let _=0;_<C.length;_++){const u=C[_].textContent.toLowerCase();C[_].classList.toggle("hidden",S&&u.indexOf(S)===-1)}}),t.appendChild(i),this._activeDropdown={field:e,th:t,el:i},i.addEventListener("click",function(S){S.stopPropagation()})},a.prototype._closeFilterDropdown=function(){this._activeDropdown&&(this._activeDropdown.el&&this._activeDropdown.el.parentNode&&this._activeDropdown.el.parentNode.removeChild(this._activeDropdown.el),this._activeDropdown=null)},a.prototype._applyFilterMutualExclusion=function(e,t){const n=e.hasAttribute("data-ln-filter-reset"),l=t.querySelector("[data-ln-filter-reset]"),i=t.querySelectorAll('input[type="checkbox"]:not([data-ln-filter-reset])');if(n){e.checked=!0;for(let s=0;s<i.length;s++)i[s].checked=!1}else if(e.checked)l&&(l.checked=!1);else{let s=!1;for(let c=0;c<i.length;c++)if(i[c].checked){s=!0;break}!s&&l&&(l.checked=!0)}},a.prototype._onFilterChange=function(e,t){const n=t.querySelector("[data-ln-filter-reset]"),l=t.querySelectorAll('input[type="checkbox"]:not([data-ln-filter-reset])'),i=[];for(let c=0;c<l.length;c++)l[c].checked&&i.push(l[c].value);const s=n&&n.checked||i.length===0;s?delete this.currentFilters[e]:this.currentFilters[e]=i,this._updateFilterIndicators(),v(this.dom,"ln-data-table:filter",{table:this.name,field:e,values:s?[]:i}),this._requestData()},a.prototype._updateFilterOptions=function(e){if(e!==null&&typeof e=="object"&&!Array.isArray(e)){const t=Object.keys(e);for(let n=0;n<t.length;n++){const l=t[n],i=e[l];if(!Array.isArray(i))continue;const s={},c=[];for(let d=0;d<i.length;d++){const f=String(i[d]);s[f]||(s[f]=!0,c.push(f))}this._filterOptions[l]=c.sort()}}else{const t=this._filterableFields,n=this._data;for(let l=0;l<t.length;l++){const i=t[l];this._filterOptions[i]||(this._filterOptions[i]=[]);const s=this._filterOptions[i],c={};for(let d=0;d<s.length;d++)c[s[d]]=!0;for(let d=0;d<n.length;d++){const f=n[d][i];if(f!=null){const w=String(f);c[w]||(c[w]=!0,s.push(w))}}s.sort()}}},a.prototype._getUniqueValues=function(e){return(this._filterOptions[e]||[]).slice().sort()},a.prototype._updateFilterIndicators=function(){const e=this.ths;for(let t=0;t<e.length;t++){const n=e[t],l=n.getAttribute("data-ln-col");if(!l)continue;const i=n.querySelector("[data-ln-col-filter]");if(!i)continue;const s=this.currentFilters[l]&&this.currentFilters[l].length>0;i.classList.toggle("ln-filter-active",!!s)}},a.prototype._renderRows=function(){if(!this.tbody)return;const e=this._data,t=this._lastTotal,n=this._lastFiltered;if(t===0){this._disableVirtualScroll(),this._showEmptyState(this.name+"-empty");return}if(e.length===0||n===0){this._disableVirtualScroll(),this._showEmptyState(this.name+"-empty-filtered");return}e.length>200?(this._enableVirtualScroll(),this._renderVirtual()):(this._disableVirtualScroll(),this._renderAll())},a.prototype._renderAll=function(){const e=this._data,t=document.createDocumentFragment();for(let n=0;n<e.length;n++){const l=this._buildRow(e[n]);if(!l)break;t.appendChild(l)}this.tbody.textContent="",this.tbody.appendChild(t),this._selectable&&this._updateSelectAll()},a.prototype._buildRow=function(e){const t=x(this.dom,this.name+"-row","ln-data-table");if(!t)return null;const n=t.querySelector("[data-ln-row]")||t.firstElementChild;if(!n)return null;if(this._fillRow(n,e),n._lnRecord=e,e.id!=null&&n.setAttribute("data-ln-row-id",e.id),this._selectable&&e.id!=null&&this.selectedIds.has(String(e.id))){n.classList.add("ln-row-selected");const l=n.querySelector("[data-ln-row-select]");l&&(l.checked=!0)}return n},a.prototype._enableVirtualScroll=function(){if(this._virtual)return;this._virtual=!0,this._vStart=-1,this._vEnd=-1;const e=this;if(!this._rowHeight){const n=this._buildRow(this._data[0]);n&&(this.tbody.textContent="",this.tbody.appendChild(n),this._rowHeight=n.offsetHeight||40,this.tbody.textContent="")}this._scrollContainer=h(this.dom);const t=this._scrollContainer||window;this._scrollHandler=function(){e._rafId||(e._rafId=requestAnimationFrame(function(){e._rafId=null,e._renderVirtual()}))},t.addEventListener("scroll",this._scrollHandler,{passive:!0}),window.addEventListener("resize",this._scrollHandler,{passive:!0})},a.prototype._disableVirtualScroll=function(){this._virtual&&(this._virtual=!1,this._scrollHandler&&((this._scrollContainer||window).removeEventListener("scroll",this._scrollHandler),window.removeEventListener("resize",this._scrollHandler),this._scrollHandler=null),this._scrollContainer=null,this._rafId&&(cancelAnimationFrame(this._rafId),this._rafId=null),this._vStart=-1,this._vEnd=-1)},a.prototype._renderVirtual=function(){const e=this._data,t=e.length,n=this._rowHeight;if(!n||!t)return;const l=this.thead?this.thead.offsetHeight:0,i=this._scrollContainer;let s,c;if(i){const u=this.table.getBoundingClientRect(),g=i.getBoundingClientRect(),k=u.top-g.top+i.scrollTop+l;s=i.scrollTop-k,c=i.clientHeight}else{const k=this.table.getBoundingClientRect().top+window.scrollY+l;s=window.scrollY-k,c=window.innerHeight}let d=Math.max(0,Math.floor(s/n)-15);d=Math.min(d,t);const f=Math.min(d+Math.ceil(c/n)+30,t);if(d===this._vStart&&f===this._vEnd)return;this._vStart=d,this._vEnd=f;const w=this.ths.length||1,S=d*n,C=(t-f)*n,_=document.createDocumentFragment();if(S>0){const u=document.createElement("tr");u.className="ln-data-table__spacer",u.setAttribute("aria-hidden","true");const g=document.createElement("td");g.setAttribute("colspan",w),g.style.height=S+"px",u.appendChild(g),_.appendChild(u)}for(let u=d;u<f;u++){const g=this._buildRow(e[u]);g&&_.appendChild(g)}if(C>0){const u=document.createElement("tr");u.className="ln-data-table__spacer",u.setAttribute("aria-hidden","true");const g=document.createElement("td");g.setAttribute("colspan",w),g.style.height=C+"px",u.appendChild(g),_.appendChild(u)}this.tbody.textContent="",this.tbody.appendChild(_),this._selectable&&this._updateSelectAll()},a.prototype._fillRow=function(e,t){F(e,t);const n=e.querySelectorAll("[data-ln-cell-attr]");for(let l=0;l<n.length;l++){const i=n[l],s=i.getAttribute("data-ln-cell-attr").split(",");for(let c=0;c<s.length;c++){const d=s[c].trim().split(":");if(d.length!==2)continue;const f=d[0].trim(),w=d[1].trim();t[f]!=null&&i.setAttribute(w,t[f])}}},a.prototype._showEmptyState=function(e){const t=x(this.dom,e,"ln-data-table");this.tbody.textContent="",t&&this.tbody.appendChild(t)},a.prototype._updateFooter=function(){const e=this._lastTotal,t=this._lastFiltered,n=t<e;if(this._totalSpan&&(this._totalSpan.textContent=y(e)),this._filteredSpan&&(this._filteredSpan.textContent=n?y(t):""),this._filteredWrap&&this._filteredWrap.classList.toggle("hidden",!n),this._selectedSpan){const l=this.selectedIds.size;this._selectedSpan.textContent=l>0?y(l):"",this._selectedWrap&&this._selectedWrap.classList.toggle("hidden",l===0)}},a.prototype.destroy=function(){this.dom[r]&&(this.dom.removeEventListener("ln-data-table:set-data",this._onSetData),this.dom.removeEventListener("ln-data-table:set-loading",this._onSetLoading),this.thead&&(this.thead.removeEventListener("click",this._onSortClick),this.thead.removeEventListener("click",this._onFilterClick)),document.removeEventListener("click",this._onDocClick),document.removeEventListener("keydown",this._onKeydown),this._searchInput&&this._searchInput.removeEventListener("input",this._onSearchInput),this.tbody&&(this.tbody.removeEventListener("click",this._onRowClick),this.tbody.removeEventListener("click",this._onRowAction)),this._onSelectionChange&&this.tbody&&this.tbody.removeEventListener("change",this._onSelectionChange),this._selectAllCheckbox&&this._onSelectAll&&this._selectAllCheckbox.removeEventListener("change",this._onSelectAll),this.dom.removeEventListener("click",this._onClearAll),this._closeFilterDropdown(),this._disableVirtualScroll(),this._data=[],delete this.dom[r])};function b(e,t){const n=e[r];if(n&&t==="data-ln-data-table-selectable"){const l=e.hasAttribute("data-ln-data-table-selectable");l!==n._selectable&&(n._selectable=l,l?n._enableSelection():n._disableSelection())}}T(o,r,a,"ln-data-table",{extraAttributes:["data-ln-data-table-selectable"],onAttributeChange:b})})()})();
|
|
@@ -635,22 +635,6 @@ import { cloneTemplateScoped, dispatch, fill, fillTemplate, registerComponent }
|
|
|
635
635
|
});
|
|
636
636
|
}
|
|
637
637
|
|
|
638
|
-
// Clear filter button
|
|
639
|
-
const clearBtn = dropdown.querySelector('[data-ln-filter-clear]');
|
|
640
|
-
if (clearBtn) {
|
|
641
|
-
clearBtn.addEventListener('click', function () {
|
|
642
|
-
delete self.currentFilters[field];
|
|
643
|
-
self._closeFilterDropdown();
|
|
644
|
-
self._updateFilterIndicators();
|
|
645
|
-
dispatch(self.dom, 'ln-data-table:filter', {
|
|
646
|
-
table: self.name,
|
|
647
|
-
field: field,
|
|
648
|
-
values: []
|
|
649
|
-
});
|
|
650
|
-
self._requestData();
|
|
651
|
-
});
|
|
652
|
-
}
|
|
653
|
-
|
|
654
638
|
// Append to th — CSS handles positioning (th is relative, dropdown is absolute)
|
|
655
639
|
th.appendChild(dropdown);
|
|
656
640
|
|
package/js/ln-filter/README.md
CHANGED
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
# ln-filter
|
|
2
|
-
|
|
3
|
-
A zero-dependency, event-driven **Generic List & Table Filter Primitive** that manages item visibility states through declarative checkbox controls.
|
|
4
|
-
|
|
5
|
-
It filters target elements either by comparing child dataset attributes (for custom cards/lists) or scanning table column cell contents (for plain HTML tables). It operates independently of and in harmony with `ln-search`, combining multiple filter criteria seamlessly.
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## 🧭 Philosophy & Architecture
|
|
10
|
-
|
|
11
|
-
1. **Declarative State Model:** The component has no custom imperative state-change methods. Filter state is driven entirely by native checkboxes. External scripts update selections by writing `input.checked = true` and dispatching a standard bubbled `change` event.
|
|
12
|
-
2. **Sentinel Mutual Exclusion:** The `data-ln-filter-reset` ("All") checkbox is kept in sync automatically: checking any value checkbox unchecks the reset sentinel; checking the sentinel unchecks all value inputs; unchecking all value inputs re-checks the sentinel.
|
|
13
|
-
3. **Table Column & Auto-Population Mode:** By defining `data-ln-filter-col="N"`, the component filters plain HTML `<table>` rows by column cell text. When a `<template>` tag is nested inside, the component automatically populates value checkboxes from the column's unique values on page load.
|
|
14
|
-
4. **Local State Persistence:** Adding the `data-ln-persist` attribute saves active filter selections to `localStorage` under `lnf:{id}`, ensuring filter states survive page reloads and browser transitions.
|
|
15
|
-
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
## 📦 Minimal Blueprint
|
|
19
|
-
|
|
20
|
-
### Generic List Attribute Filter (Zero-JS)
|
|
21
|
-
Bind the filter to a container `id`. Target items declare attributes matching the filter key.
|
|
22
|
-
```html
|
|
23
|
-
<nav data-ln-filter="employees-list">
|
|
24
|
-
<!-- Reset Sentinel -->
|
|
25
|
-
<label><input type="checkbox" data-ln-filter-key="category" data-ln-filter-reset checked> All</label>
|
|
26
|
-
<!-- Values -->
|
|
27
|
-
<label><input type="checkbox" data-ln-filter-key="category" data-ln-filter-value="design"> Design</label>
|
|
28
|
-
<label><input type="checkbox" data-ln-filter-key="category" data-ln-filter-value="dev"> Development</label>
|
|
29
|
-
</nav>
|
|
30
|
-
|
|
31
|
-
<ul id="employees-list">
|
|
32
|
-
<li data-category="design">Ana Petrova — UI Designer</li>
|
|
33
|
-
<li data-category="dev">Marko Nikolov — Developer</li>
|
|
34
|
-
</ul>
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
### Table Column Filter with Auto-Population & Persistence
|
|
38
|
-
Auto-populates filter checkboxes from Column Index `2` (Department) and saves state to storage.
|
|
39
|
-
```html
|
|
40
|
-
<nav id="dept-filter" data-ln-filter="users-table" data-ln-filter-col="2" data-ln-persist>
|
|
41
|
-
<label><input type="checkbox" data-ln-filter-key="dept" data-ln-filter-reset checked> All Departments</label>
|
|
42
|
-
<!-- Checklist generated dynamically here -->
|
|
43
|
-
<template>
|
|
44
|
-
<label><input type="checkbox"> {{ text }}</label>
|
|
45
|
-
</template>
|
|
46
|
-
</nav>
|
|
47
|
-
|
|
48
|
-
<table id="users-table">
|
|
49
|
-
<thead>
|
|
50
|
-
<tr><th>ID</th><th>Name</th><th>Department</th></tr>
|
|
51
|
-
</thead>
|
|
52
|
-
<tbody>
|
|
53
|
-
<tr><td>1</td><td>Ana Petrova</td><td>Engineering</td></tr>
|
|
54
|
-
<tr><td>2</td><td>Marko Nikolov</td><td>Design</td></tr>
|
|
55
|
-
</tbody>
|
|
56
|
-
</table>
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
---
|
|
60
|
-
|
|
61
|
-
## 🛠️ Declarative API Contract
|
|
62
|
-
|
|
63
|
-
### HTML Attributes
|
|
64
|
-
|
|
65
|
-
| Attribute | Elements | Description |
|
|
66
|
-
| :--- | :--- | :--- |
|
|
67
|
-
| `data-ln-filter` | Container root | Component root. Value is the `id` of the target container whose items are filtered. |
|
|
68
|
-
| `data-ln-filter-key` | `<input type="checkbox">` | The field name representing the target dataset attribute (e.g. `category` matches `data-category`). |
|
|
69
|
-
| `data-ln-filter-value` | `<input type="checkbox">` | The value to match. Active checkboxes show matching items; others are hidden. |
|
|
70
|
-
| `data-ln-filter-reset` | `<input type="checkbox">` | Marks the reset ("All") sentinel. |
|
|
71
|
-
| `data-ln-filter-col` | Container root | Opt-in. 0-based column index to filter plain `<table>` rows by column cell text. |
|
|
72
|
-
| `data-ln-persist` | Container root | Opt-in. Persists active checkbox selections in `localStorage` under `lnf:{id}`. |
|
|
73
|
-
| `data-ln-filter-hide` | Children of target | *State*. Automatically toggled on non-matching elements (`display: none !important`). |
|
|
74
|
-
|
|
75
|
-
---
|
|
76
|
-
|
|
77
|
-
## ⚡ DOM Events
|
|
78
|
-
|
|
79
|
-
Events are dispatched on **both** the filter navigation container and the target element (dual dispatch).
|
|
80
|
-
|
|
81
|
-
### `ln-filter:changed`
|
|
82
|
-
Fired when any filter selection is modified.
|
|
83
|
-
- **Payload (`detail`)**: `{ key: string, values: string[] }` (where `values` lists active filter options).
|
|
84
|
-
|
|
85
|
-
### `ln-filter:reset`
|
|
86
|
-
Fired when the reset sentinel is activated.
|
|
87
|
-
- **Payload (`detail`)**: `{}`
|
|
88
|
-
|
|
89
|
-
---
|
|
90
|
-
|
|
91
|
-
## ⚠️ Common Pitfalls
|
|
92
|
-
|
|
93
|
-
- **Driving State Programmatically Without Events:** Changing `input.checked = true` using JavaScript does not trigger browser `change` listeners. You must explicitly dispatch the event:
|
|
94
|
-
```javascript
|
|
95
|
-
input.checked = true;
|
|
96
|
-
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
97
|
-
```
|
|
98
|
-
- **Missing `id` on Persisted Filters:** The `data-ln-persist` storage key relies on the filter element's ID (e.g. `<nav id="my-filter" data-ln-persist>`). If the ID is missing, the component will fail to initialize persistence.
|
|
99
|
-
- **Filtering Coordinated Tables:** `ln-filter` is designed for static lists or plain native tables. Do not target virtualised components like `ln-table` or `ln-data-table`, which manage their own column filters internally.
|
|
1
|
+
# ln-filter
|
|
2
|
+
|
|
3
|
+
A zero-dependency, event-driven **Generic List & Table Filter Primitive** that manages item visibility states through declarative checkbox controls.
|
|
4
|
+
|
|
5
|
+
It filters target elements either by comparing child dataset attributes (for custom cards/lists) or scanning table column cell contents (for plain HTML tables). It operates independently of and in harmony with `ln-search`, combining multiple filter criteria seamlessly.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🧭 Philosophy & Architecture
|
|
10
|
+
|
|
11
|
+
1. **Declarative State Model:** The component has no custom imperative state-change methods. Filter state is driven entirely by native checkboxes. External scripts update selections by writing `input.checked = true` and dispatching a standard bubbled `change` event.
|
|
12
|
+
2. **Sentinel Mutual Exclusion:** The `data-ln-filter-reset` ("All") checkbox is kept in sync automatically: checking any value checkbox unchecks the reset sentinel; checking the sentinel unchecks all value inputs; unchecking all value inputs re-checks the sentinel.
|
|
13
|
+
3. **Table Column & Auto-Population Mode:** By defining `data-ln-filter-col="N"`, the component filters plain HTML `<table>` rows by column cell text. When a `<template>` tag is nested inside, the component automatically populates value checkboxes from the column's unique values on page load.
|
|
14
|
+
4. **Local State Persistence:** Adding the `data-ln-persist` attribute saves active filter selections to `localStorage` under `lnf:{id}`, ensuring filter states survive page reloads and browser transitions.
|
|
15
|
+
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
## 📦 Minimal Blueprint
|
|
19
|
+
|
|
20
|
+
### Generic List Attribute Filter (Zero-JS)
|
|
21
|
+
Bind the filter to a container `id`. Target items declare attributes matching the filter key.
|
|
22
|
+
```html
|
|
23
|
+
<nav data-ln-filter="employees-list">
|
|
24
|
+
<!-- Reset Sentinel -->
|
|
25
|
+
<label><input type="checkbox" data-ln-filter-key="category" data-ln-filter-reset checked> All</label>
|
|
26
|
+
<!-- Values -->
|
|
27
|
+
<label><input type="checkbox" data-ln-filter-key="category" data-ln-filter-value="design"> Design</label>
|
|
28
|
+
<label><input type="checkbox" data-ln-filter-key="category" data-ln-filter-value="dev"> Development</label>
|
|
29
|
+
</nav>
|
|
30
|
+
|
|
31
|
+
<ul id="employees-list">
|
|
32
|
+
<li data-category="design">Ana Petrova — UI Designer</li>
|
|
33
|
+
<li data-category="dev">Marko Nikolov — Developer</li>
|
|
34
|
+
</ul>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Table Column Filter with Auto-Population & Persistence
|
|
38
|
+
Auto-populates filter checkboxes from Column Index `2` (Department) and saves state to storage.
|
|
39
|
+
```html
|
|
40
|
+
<nav id="dept-filter" data-ln-filter="users-table" data-ln-filter-col="2" data-ln-persist>
|
|
41
|
+
<label><input type="checkbox" data-ln-filter-key="dept" data-ln-filter-reset checked> All Departments</label>
|
|
42
|
+
<!-- Checklist generated dynamically here -->
|
|
43
|
+
<template>
|
|
44
|
+
<label><input type="checkbox"> {{ text }}</label>
|
|
45
|
+
</template>
|
|
46
|
+
</nav>
|
|
47
|
+
|
|
48
|
+
<table id="users-table">
|
|
49
|
+
<thead>
|
|
50
|
+
<tr><th>ID</th><th>Name</th><th>Department</th></tr>
|
|
51
|
+
</thead>
|
|
52
|
+
<tbody>
|
|
53
|
+
<tr><td>1</td><td>Ana Petrova</td><td>Engineering</td></tr>
|
|
54
|
+
<tr><td>2</td><td>Marko Nikolov</td><td>Design</td></tr>
|
|
55
|
+
</tbody>
|
|
56
|
+
</table>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
---
|
|
60
|
+
|
|
61
|
+
## 🛠️ Declarative API Contract
|
|
62
|
+
|
|
63
|
+
### HTML Attributes
|
|
64
|
+
|
|
65
|
+
| Attribute | Elements | Description |
|
|
66
|
+
| :--- | :--- | :--- |
|
|
67
|
+
| `data-ln-filter` | Container root | Component root. Value is the `id` of the target container whose items are filtered. |
|
|
68
|
+
| `data-ln-filter-key` | `<input type="checkbox">` | The field name representing the target dataset attribute (e.g. `category` matches `data-category`). |
|
|
69
|
+
| `data-ln-filter-value` | `<input type="checkbox">` | The value to match. Active checkboxes show matching items; others are hidden. |
|
|
70
|
+
| `data-ln-filter-reset` | `<input type="checkbox">` | Marks the reset ("All") sentinel. |
|
|
71
|
+
| `data-ln-filter-col` | Container root | Opt-in. 0-based column index to filter plain `<table>` rows by column cell text. |
|
|
72
|
+
| `data-ln-persist` | Container root | Opt-in. Persists active checkbox selections in `localStorage` under `lnf:{id}`. |
|
|
73
|
+
| `data-ln-filter-hide` | Children of target | *State*. Automatically toggled on non-matching elements (`display: none !important`). |
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## ⚡ DOM Events
|
|
78
|
+
|
|
79
|
+
Events are dispatched on **both** the filter navigation container and the target element (dual dispatch).
|
|
80
|
+
|
|
81
|
+
### `ln-filter:changed`
|
|
82
|
+
Fired when any filter selection is modified.
|
|
83
|
+
- **Payload (`detail`)**: `{ key: string, values: string[] }` (where `values` lists active filter options).
|
|
84
|
+
|
|
85
|
+
### `ln-filter:reset`
|
|
86
|
+
Fired when the reset sentinel is activated.
|
|
87
|
+
- **Payload (`detail`)**: `{}`
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## ⚠️ Common Pitfalls
|
|
92
|
+
|
|
93
|
+
- **Driving State Programmatically Without Events:** Changing `input.checked = true` using JavaScript does not trigger browser `change` listeners. You must explicitly dispatch the event:
|
|
94
|
+
```javascript
|
|
95
|
+
input.checked = true;
|
|
96
|
+
input.dispatchEvent(new Event('change', { bubbles: true }));
|
|
97
|
+
```
|
|
98
|
+
- **Missing `id` on Persisted Filters:** The `data-ln-persist` storage key relies on the filter element's ID (e.g. `<nav id="my-filter" data-ln-persist>`). If the ID is missing, the component will fail to initialize persistence.
|
|
99
|
+
- **Filtering Coordinated Tables:** `ln-filter` is designed for static lists or plain native tables. Do not target virtualised components like `ln-table` or `ln-data-table`, which manage their own column filters internally.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(){"use strict";function
|
|
1
|
+
(function(){"use strict";function y(t,e,s){t.dispatchEvent(new CustomEvent(e,{bubbles:!0,detail:s||{}}))}function f(t,e){if(!document.body){document.addEventListener("DOMContentLoaded",function(){f(t,e)}),console.warn("["+e+'] Script loaded before <body> — add "defer" to your <script> tag');return}t()}const h={};function _(t,e){h[t]=e}function w(t){return h[t]||{ingress:e=>e,egress:e=>e}}typeof window<"u"&&(window.lnCore=window.lnCore||{},window.lnCore.registerDataMapper=_,window.lnCore.getDataMapper=w);const g="ln:";function S(){return location.pathname.replace(/\/+$/,"").toLowerCase()||"/"}function p(t,e){const s=e.getAttribute("data-ln-persist"),l=s!==null&&s!==""?s:e.id;return l?g+t+":"+S()+":"+l:(console.warn('[ln-persist] Element requires id or data-ln-persist="key"',e),null)}function m(t,e){const s=p(t,e);if(!s)return null;try{const l=localStorage.getItem(s);return l!==null?JSON.parse(l):null}catch{return null}}function b(t,e,s){const l=p(t,e);if(l)try{localStorage.setItem(l,JSON.stringify(s))}catch{}}(function(){const t="lnTableSort",e="data-ln-sort",s="data-ln-table-sort";if(window[t]!==void 0)return;function l(o){a(o)}function a(o){const r=Array.from(o.querySelectorAll("table"));o.tagName==="TABLE"&&r.push(o),r.forEach(function(n){if(n[t])return;const c=Array.from(n.querySelectorAll("th["+e+"]"));c.length&&(n[t]=new u(n,c))})}function u(o,r){this.table=o,this.ths=r,this._col=-1,this._dir=null;const n=this;r.forEach(function(i,E){if(i[t+"Bound"])return;i[t+"Bound"]=!0;const d=i.querySelector("["+s+"]");d&&(d._lnSortClick=function(){n._handleClick(E,i)},d.addEventListener("click",d._lnSortClick))});const c=o.closest("[data-ln-table][data-ln-persist]");if(c){const i=m("table-sort",c);i&&i.dir&&i.col>=0&&i.col<r.length&&(this._handleClick(i.col,r[i.col]),i.dir==="desc"&&this._handleClick(i.col,r[i.col]))}return this}u.prototype._handleClick=function(o,r){let n;this._col!==o?n="asc":this._dir==="asc"?n="desc":this._dir==="desc"?n=null:n="asc",this.ths.forEach(function(i){i.classList.remove("ln-sort-asc","ln-sort-desc")}),n===null?(this._col=-1,this._dir=null):(this._col=o,this._dir=n,r.classList.add(n==="asc"?"ln-sort-asc":"ln-sort-desc")),y(this.table,"ln-table:sort",{column:o,sortType:r.getAttribute(e),direction:n});const c=this.table.closest("[data-ln-table][data-ln-persist]");c&&(n===null?b("table-sort",c,null):b("table-sort",c,{col:o,dir:n}))},u.prototype.destroy=function(){this.table[t]&&(this.ths.forEach(function(o){const r=o.querySelector("["+s+"]");r&&r._lnSortClick&&(r.removeEventListener("click",r._lnSortClick),delete r._lnSortClick),delete o[t+"Bound"]}),delete this.table[t])};function C(){f(function(){new MutationObserver(function(r){r.forEach(function(n){n.type==="childList"?n.addedNodes.forEach(function(c){c.nodeType===1&&a(c)}):n.type==="attributes"&&a(n.target)})}).observe(document.body,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[e]})},"ln-table-sort")}window[t]=l,C(),document.readyState==="loading"?document.addEventListener("DOMContentLoaded",function(){l(document.body)}):l(document.body)})()})();
|