scb-wc 0.1.86 → 0.1.88
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{h as _,m,p as b,v as p,y as v}from"../../vendor/vendor.js";import"../../vendor/vendor-lit.js";import{t as u}from"../../vendor/decorate.js";import"../scb-icon-button/scb-icon-button.js";import"../scb-search/scb-search.js";import"../scb-pagination/scb-pagination.js";(function(){try{var f=typeof globalThis<"u"?globalThis:window;if(!f.__scb_ce_guard_installed__){f.__scb_ce_guard_installed__=!0;var e=customElements.define.bind(customElements);customElements.define=function(s,r,
|
|
1
|
+
import{h as _,m,p as b,v as p,y as v}from"../../vendor/vendor.js";import"../../vendor/vendor-lit.js";import{t as u}from"../../vendor/decorate.js";import"../scb-icon-button/scb-icon-button.js";import"../scb-search/scb-search.js";import"../scb-pagination/scb-pagination.js";(function(){try{var f=typeof globalThis<"u"?globalThis:window;if(!f.__scb_ce_guard_installed__){f.__scb_ce_guard_installed__=!0;var e=customElements.define.bind(customElements);customElements.define=function(s,r,a){try{customElements.get(s)||e(s,r,a)}catch(t){var l=String(t||"");if(l.indexOf("already been used")===-1&&l.indexOf("NotSupportedError")===-1)throw t}}}}catch{}})();var g,d=(g=class extends _{constructor(...e){super(...e),this.searchTerm="",this.pagination=!1,this.filteringSearch=!1,this.noScroll=!1,this.pageSize=10,this.currentPage=1,this.totalRows=0,this._sortedColumn=null,this._sortDirection="asc",this._filteredRows=null,this._tbodyObserver=null,this._observedTbody=null,this._pendingTableRefresh=!1,this._suppressTbodyObserver=!1,this._onSlotChange=()=>{this._attachTbodyObserver(),this._refreshFromTableContent()},this._onPaginationChange=s=>{const r=s.detail;r&&typeof r.page=="number"&&this._changePage(r.page)}}disconnectedCallback(){super.disconnectedCallback(),this._disconnectTbodyObserver()}attributeChangedCallback(e,s,r){if(super.attributeChangedCallback(e,s,r),s!==r){if(e==="searchterm"){queueMicrotask(()=>{this.isConnected&&this._filterTable()});return}if(e==="currentpage"){queueMicrotask(()=>{this.isConnected&&this._paginateTable()});return}(e==="page-size"||e==="with-filtering-search"||e==="with-pagination")&&this._scheduleTableRefresh()}}render(){const e=Math.ceil(this.totalRows/this.pageSize);return p`
|
|
2
2
|
${this.filteringSearch?p`
|
|
3
3
|
<div style="margin-bottom: 12px;">
|
|
4
4
|
<scb-search
|
|
@@ -22,4 +22,4 @@ import{h as _,m,p as b,v as p,y as v}from"../../vendor/vendor.js";import"../../v
|
|
|
22
22
|
></scb-pagination>
|
|
23
23
|
`:""}
|
|
24
24
|
</div>
|
|
25
|
-
`}_onSearchInput(e){const s=e.target.value;this.searchTerm=s,this._filterTable(),this.dispatchEvent(new CustomEvent("tableadvancedchange",{detail:{searchTerm:this.searchTerm,currentPage:this.currentPage},bubbles:!0,composed:!0}))}_filterTable(){const e=this.shadowRoot.querySelector("slot");if(!e)return;const s=e.assignedNodes({flatten:!0});let r=null;if(s.forEach(i=>{if(i.nodeType===Node.ELEMENT_NODE){const o=i.querySelector("tbody");o&&(r=o)}}),!r)return;const a=Array.from(r.querySelectorAll("tr")),t=this.searchTerm.trim().toLowerCase();if(!t)this._filteredRows=null,a.forEach(i=>i.style.display=""),this._updateTotalRows(),this._ensureCurrentPageWithinBounds(),this.pagination&&this._paginateTable(),this._sortedColumn!==null&&this._sortTable(this._sortedColumn,this._sortDirection);else{this._filteredRows=a.filter(o=>this._getRowSearchText(o).toLowerCase().includes(t)),a.forEach(o=>o.style.display="none");let i=this._filteredRows;this._sortedColumn!==null&&(i=[...i],i.sort((o,c)=>{const h=this._getCellSortableValue(o.children[this._sortedColumn]),n=this._getCellSortableValue(c.children[this._sortedColumn]);return this._compareCellValues(h,n,this._sortDirection)}),this._filteredRows=i),this.totalRows=this._filteredRows.length,this._ensureCurrentPageWithinBounds(),this.pagination?this._paginateTable():this._filteredRows.forEach(o=>o.style.display="")}}firstUpdated(){const e=this.shadowRoot.querySelector("slot");e&&(e.addEventListener("slotchange",()=>this._attachThListeners()),this._attachThListeners(),this._attachTbodyObserver(),this._refreshFromTableContent())}updated(e){super.updated(e),(e.has("searchTerm")||e.has("currentPage")||e.has("pageSize")||e.has("filteringSearch")||e.has("pagination"))&&this.updateComplete.then(()=>{this.isConnected&&this._refreshFromTableContent()})}_disconnectTbodyObserver(){this._tbodyObserver&&(this._tbodyObserver.disconnect(),this._tbodyObserver=null),this._observedTbody=null}_attachTbodyObserver(){const e=this._getTbody();if(!e){this._disconnectTbodyObserver();return}this._observedTbody!==e&&(this._disconnectTbodyObserver(),this._observedTbody=e,this._tbodyObserver=new MutationObserver(()=>{this._suppressTbodyObserver||this._scheduleTableRefresh()}),this._tbodyObserver.observe(e,{childList:!0,subtree:!0,characterData:!0}))}_scheduleTableRefresh(){this._pendingTableRefresh||(this._pendingTableRefresh=!0,queueMicrotask(()=>{this._pendingTableRefresh=!1,this._refreshFromTableContent()}))}_refreshFromTableContent(){if(this._attachTbodyObserver(),this.filteringSearch){this._filterTable();return}if(this._updateTotalRows(),this._ensureCurrentPageWithinBounds(),this._sortedColumn!==null){this._sortTable(this._sortedColumn,this._sortDirection);return}this.pagination&&this._paginateTable()}_ensureCurrentPageWithinBounds(){const e=Math.max(1,Math.ceil(this.totalRows/this.pageSize)),s=Math.min(Math.max(1,this.currentPage),e);s!==this.currentPage&&(this.currentPage=s)}_getTbody(){const e=this.shadowRoot.querySelector("slot");if(!e)return null;const s=e.assignedNodes({flatten:!0});for(const r of s)if(r.nodeType===Node.ELEMENT_NODE){const l=r.querySelector("tbody");if(l)return l}return null}_attachThListeners(){const e=this.shadowRoot.querySelector("slot");if(!e)return;const s=e.assignedNodes({flatten:!0}),r=[],l=[],a=[];s.forEach(t=>{t.nodeType===Node.ELEMENT_NODE&&(r.push(...t.querySelectorAll("th")),l.push(...t.querySelectorAll("td")),a.push(...t.querySelectorAll("tr")))}),r.forEach((t,i)=>{t.style.textAlign="left",t.style.padding="16px 0px 16px 32px",t.style.position="relative",t.style.backgroundColor="var(--md-sys-color-surface)",t.style.fontFamily="var(--md-sys-typescale-label-medium-font)",t.style.fontSize="var(--md-sys-typescale-label-medium-size)",t.style.lineHeight="var(--md-sys-typescale-label-medium-line-height)",t.style.fontWeight="var(--md-sys-typescale-label-medium-weight)",t.style.letterSpacing="var(--md-sys-typescale-label-medium-tracking)",t.style.verticalAlign="bottom";const o=t.firstChild;if(o&&o.nodeType===Node.TEXT_NODE&&o.textContent?.trim()||o&&o.nodeType===Node.ELEMENT_NODE&&o.tagName.toLowerCase()!=="p"){const h=document.createElement("p");h.textContent=o.textContent?o.textContent.trim():"",h.style.margin="0",t.replaceChild(h,o),t.querySelectorAll("scb-icon-button.scb-sort-icon").forEach(g=>g.remove());const n=document.createElement("scb-icon-button");n.className="scb-sort-icon",n.onclick=()=>this._onThClick(i),n.setAttribute("variant","standard"),n.setAttribute("size","small"),this._sortedColumn===i?(n.setAttribute("variant","filled-tonal"),n.setAttribute("icon",this._sortDirection==="asc"?"arrow_downward":"arrow_upward")):(n.setAttribute("icon","swap_horiz"),n.style.transform+=" rotate(90deg)",n.style.alignSelf="end");var c=document.createElement("div");c.style.display="flex",c.style.gap="8px",c.style.flexWrap="nowrap",c.style.alignItems="center",c.appendChild(h),c.appendChild(n),t.appendChild(c)}}),l.forEach(t=>{t.style.padding="16px 0px 16px 32px",t.style.textAlign="left",t.style.borderTop="1px solid var(--md-sys-color-outline-variant)",t.style.verticalAlign="text-top",t.style.backgroundColor="var(--md-sys-color-surface)",t.style.fontFamily="var(--md-sys-typescale-body-medium-font)",t.style.fontSize="var(--md-sys-typescale-body-medium-size)",t.style.lineHeight="var(--md-sys-typescale-body-medium-line-height)",t.style.fontWeight="var(--md-sys-typescale-body-medium-weight)",t.style.letterSpacing="var(--md-sys-typescale-body-medium-tracking)"}),a.forEach((t,i)=>{i%2===1&&t.querySelectorAll("td").forEach(h=>{h.style.backgroundColor="var(--scb-background-row)"});const o=t.querySelectorAll("th");o.length>0&&o.forEach((h,n)=>{n===0&&(h.style.paddingLeft="24px"),n===o.length-1?h.style.paddingRight="24px":h.style.paddingRight=""});const c=t.querySelectorAll("td");c.length>0&&c.forEach((h,n)=>{n===0&&(h.style.paddingLeft="24px"),n===c.length-1?h.style.paddingRight="24px":h.style.paddingRight=""})}),this.pagination&&this._paginateTable()}_onThClick(e){this._sortedColumn===e?this._sortDirection=this._sortDirection==="asc"?"desc":"asc":(this._sortedColumn=e,this._sortDirection="asc"),this._sortTable(e,this._sortDirection),this._attachThListeners()}_sortTable(e,s){const r=this.shadowRoot.querySelector("slot");if(!r)return;const l=r.assignedNodes({flatten:!0});let a=null;if(l.forEach(o=>{if(o.nodeType===Node.ELEMENT_NODE){const c=o.querySelector("tbody");c&&(a=c)}}),!a)return;let t;this._filteredRows?t=[...this._filteredRows]:t=Array.from(a.querySelectorAll("tr")),t.sort((o,c)=>{const h=this._getCellSortableValue(o.children[e]),n=this._getCellSortableValue(c.children[e]);return this._compareCellValues(h,n,s)});const i=this._tbodyObserver!==null;i&&this._disconnectTbodyObserver();try{t.forEach(o=>a.appendChild(o))}finally{i&&this._attachTbodyObserver()}this._filteredRows&&(this._filteredRows=t,this.totalRows=this._filteredRows.length),this.pagination&&this._paginateTable()}_getRowSearchText(e){return Array.from(e.cells).map(s=>this._getCellSortableValue(s)).join(" ")}_getCellSortableValue(e){if(!e)return"";const s=e,r=this._getSortableAttributeValue(s);if(r)return r;const l=[],a=s.textContent?.replace(/\s+/g," ").trim();return a&&l.push(a),s.querySelectorAll("[data-sort-value], [data-sort], [aria-label], [label], [value], [title]").forEach(t=>{const i=this._getSortableAttributeValue(t);i&&!l.includes(i)&&l.push(i)}),l.join(" ").trim()}_getSortableAttributeValue(e){return(e.getAttribute("data-sort-value")??e.getAttribute("data-sort")??e.getAttribute("aria-label")??e.getAttribute("label")??e.getAttribute("value")??e.getAttribute("title")??"").replace(/\s+/g," ").trim()}_compareCellValues(e,s,r){const l=this._parseSortableNumber(e),a=this._parseSortableNumber(s);if(l!==null&&a!==null)return r==="asc"?l-a:a-l;const t=Date.parse(e.replace(/\s+/g," ")),i=Date.parse(s.replace(/\s+/g," "));if(!isNaN(t)&&!isNaN(i))return r==="asc"?t-i:i-t;const o=e.localeCompare(s,"sv");return r==="asc"?o:-o}_parseSortableNumber(e){const s=e.trim();if(!/^[+-]?(?:\d+|\d{1,3}(?:[\s\u00a0\u202f]\d{3})+)(?:[,.]\d+)?$/.test(s))return null;const r=Number(s.replace(/[\s\u00a0\u202f]/g,"").replace(",","."));return Number.isNaN(r)?null:r}_updateTotalRows(){const e=this.shadowRoot.querySelector("slot");if(!e)return;const s=e.assignedNodes({flatten:!0});let r=null;s.forEach(l=>{if(l.nodeType===Node.ELEMENT_NODE){const a=l.querySelector("tbody");a&&(r=a)}}),r&&(this.totalRows=r.querySelectorAll("tr").length,this._ensureCurrentPageWithinBounds())}_paginateTable(){const e=this.shadowRoot.querySelector("slot");if(!e)return;const s=e.assignedNodes({flatten:!0});let r=null;if(s.forEach(i=>{if(i.nodeType===Node.ELEMENT_NODE){const o=i.querySelector("tbody");o&&(r=o)}}),!r)return;let l;this._filteredRows?l=this._filteredRows:l=Array.from(r.querySelectorAll("tr")),Array.from(r.querySelectorAll("tr")).forEach(i=>i.style.display="none");const a=(this.currentPage-1)*this.pageSize,t=a+this.pageSize;l.slice(a,t).forEach(i=>i.style.display="")}_changePage(e){const s=Math.ceil(this.totalRows/this.pageSize);e<1||e>s||(this.currentPage=e,this._paginateTable(),this.dispatchEvent(new CustomEvent("tableadvancedchange",{detail:{searchTerm:this.searchTerm,currentPage:this.currentPage},bubbles:!0,composed:!0})),this.requestUpdate())}},y.styles=v`:host{display:block;color:var(--md-sys-color-on-surface);font-family:var(--brand-font, Inter, Arial, sans-serif);--scb-background-row:var(--md-sys-color-surface)}scb-search{max-width:400px}.scb-table-scroll-wrapper{width:100%;overflow-x:auto;overflow-y:auto;max-width:100%;padding-bottom:24px}.scb-table-scroll-wrapper::-webkit-scrollbar{border-radius:var(--md-sys-shape-corner-large);height:8px;width:10px}.scb-table-scroll-wrapper::-webkit-scrollbar-thumb{background:var(--md-sys-color-on-surface);border-radius:var(--md-sys-shape-corner-large);cursor:pointer}.scb-table-scroll-wrapper::-webkit-scrollbar-track{background:var(--md-sys-color-secondary-container);border-radius:var(--md-sys-shape-corner-large)}::slotted(table){border-collapse:collapse;border-spacing:0;border-radius:24px;min-width:100%;overflow:hidden}.pagination{margin-top:16px;display:flex;justify-self:center}::slotted(th) .scb-sort-icon{pointer-events:none}::slotted(th:hover) .scb-sort-icon{pointer-events:auto}`,y);u([b({type:String})],d.prototype,"searchTerm",void 0);u([b({type:Boolean,attribute:"with-pagination"})],d.prototype,"pagination",void 0);u([b({type:Boolean,attribute:"with-filtering-search"})],d.prototype,"filteringSearch",void 0);u([b({type:Boolean,attribute:"no-scroll"})],d.prototype,"noScroll",void 0);u([b({type:Number,attribute:"page-size"})],d.prototype,"pageSize",void 0);u([b({type:Number})],d.prototype,"currentPage",void 0);u([b({type:Number})],d.prototype,"totalRows",void 0);d=u([m("scb-table-advanced")],d);
|
|
25
|
+
`}_onSearchInput(e){const s=e.target.value;this.searchTerm=s,this._filterTable(),this.dispatchEvent(new CustomEvent("tableadvancedchange",{detail:{searchTerm:this.searchTerm,currentPage:this.currentPage},bubbles:!0,composed:!0}))}_filterTable(){const e=this.shadowRoot.querySelector("slot");if(!e)return;const s=e.assignedNodes({flatten:!0});let r=null;if(s.forEach(i=>{if(i.nodeType===Node.ELEMENT_NODE){const o=i.querySelector("tbody");o&&(r=o)}}),!r)return;const a=r,l=this._getTopLevelRows(a),t=this.searchTerm.trim().toLowerCase();if(!t)this._filteredRows=null,l.forEach(i=>i.style.display=""),this._updateTotalRows(),this._ensureCurrentPageWithinBounds(),this.pagination&&this._paginateTable(),this._sortedColumn!==null&&this._sortTable(this._sortedColumn,this._sortDirection);else{this._filteredRows=l.filter(o=>this._getRowSearchText(o).toLowerCase().includes(t)),l.forEach(o=>o.style.display="none");let i=this._filteredRows;this._sortedColumn!==null&&(i=[...i],i.sort((o,c)=>{const h=this._getCellSortableValue(o.children[this._sortedColumn]),n=this._getCellSortableValue(c.children[this._sortedColumn]);return this._compareCellValues(h,n,this._sortDirection)}),this._filteredRows=i),this.totalRows=this._filteredRows.length,this._ensureCurrentPageWithinBounds(),this.pagination?this._paginateTable():this._filteredRows.forEach(o=>o.style.display="")}}firstUpdated(){const e=this.shadowRoot.querySelector("slot");e&&(e.addEventListener("slotchange",()=>this._attachThListeners()),this._attachThListeners(),this._attachTbodyObserver(),this._refreshFromTableContent())}updated(e){super.updated(e),(e.has("searchTerm")||e.has("currentPage")||e.has("pageSize")||e.has("filteringSearch")||e.has("pagination"))&&this.updateComplete.then(()=>{this.isConnected&&this._refreshFromTableContent()})}_disconnectTbodyObserver(){this._tbodyObserver&&(this._tbodyObserver.disconnect(),this._tbodyObserver=null),this._observedTbody=null}_attachTbodyObserver(){const e=this._getTbody();if(!e){this._disconnectTbodyObserver();return}this._observedTbody!==e&&(this._disconnectTbodyObserver(),this._observedTbody=e,this._tbodyObserver=new MutationObserver(()=>{this._suppressTbodyObserver||this._scheduleTableRefresh()}),this._tbodyObserver.observe(e,{childList:!0,subtree:!0,characterData:!0}))}_scheduleTableRefresh(){this._pendingTableRefresh||(this._pendingTableRefresh=!0,queueMicrotask(()=>{this._pendingTableRefresh=!1,this._refreshFromTableContent()}))}_refreshFromTableContent(){if(this._attachTbodyObserver(),this.filteringSearch){this._filterTable();return}if(this._updateTotalRows(),this._ensureCurrentPageWithinBounds(),this._sortedColumn!==null){this._sortTable(this._sortedColumn,this._sortDirection);return}this.pagination&&this._paginateTable()}_ensureCurrentPageWithinBounds(){const e=Math.max(1,Math.ceil(this.totalRows/this.pageSize)),s=Math.min(Math.max(1,this.currentPage),e);s!==this.currentPage&&(this.currentPage=s)}_getTbody(){const e=this.shadowRoot.querySelector("slot");if(!e)return null;const s=e.assignedNodes({flatten:!0});for(const r of s)if(r.nodeType===Node.ELEMENT_NODE){const a=r.querySelector("tbody");if(a)return a}return null}_getTopLevelRows(e){return Array.from(e.children).filter(s=>s instanceof HTMLTableRowElement)}_attachThListeners(){const e=this.shadowRoot.querySelector("slot");if(!e)return;const s=e.assignedNodes({flatten:!0}),r=[],a=[],l=[];s.forEach(t=>{t.nodeType===Node.ELEMENT_NODE&&(r.push(...t.querySelectorAll("th")),a.push(...t.querySelectorAll("td")),l.push(...t.querySelectorAll("tr")))}),r.forEach((t,i)=>{t.style.textAlign="left",t.style.padding="16px 0px 16px 32px",t.style.position="relative",t.style.backgroundColor="var(--md-sys-color-surface)",t.style.fontFamily="var(--md-sys-typescale-label-medium-font)",t.style.fontSize="var(--md-sys-typescale-label-medium-size)",t.style.lineHeight="var(--md-sys-typescale-label-medium-line-height)",t.style.fontWeight="var(--md-sys-typescale-label-medium-weight)",t.style.letterSpacing="var(--md-sys-typescale-label-medium-tracking)",t.style.verticalAlign="bottom";const o=t.firstChild;if(o&&o.nodeType===Node.TEXT_NODE&&o.textContent?.trim()||o&&o.nodeType===Node.ELEMENT_NODE&&o.tagName.toLowerCase()!=="p"){const h=document.createElement("p");h.textContent=o.textContent?o.textContent.trim():"",h.style.margin="0",t.replaceChild(h,o),t.querySelectorAll("scb-icon-button.scb-sort-icon").forEach(y=>y.remove());const n=document.createElement("scb-icon-button");n.className="scb-sort-icon",n.onclick=()=>this._onThClick(i),n.setAttribute("variant","standard"),n.setAttribute("size","small"),this._sortedColumn===i?(n.setAttribute("variant","filled-tonal"),n.setAttribute("icon",this._sortDirection==="asc"?"arrow_downward":"arrow_upward")):(n.setAttribute("icon","swap_horiz"),n.style.transform+=" rotate(90deg)",n.style.alignSelf="end");var c=document.createElement("div");c.style.display="flex",c.style.gap="8px",c.style.flexWrap="nowrap",c.style.alignItems="center",c.appendChild(h),c.appendChild(n),t.appendChild(c)}}),a.forEach(t=>{t.style.padding="16px 0px 16px 32px",t.style.textAlign="left",t.style.borderTop="1px solid var(--md-sys-color-outline-variant)",t.style.verticalAlign="text-top",t.style.backgroundColor="var(--md-sys-color-surface)",t.style.fontFamily="var(--md-sys-typescale-body-medium-font)",t.style.fontSize="var(--md-sys-typescale-body-medium-size)",t.style.lineHeight="var(--md-sys-typescale-body-medium-line-height)",t.style.fontWeight="var(--md-sys-typescale-body-medium-weight)",t.style.letterSpacing="var(--md-sys-typescale-body-medium-tracking)"}),l.forEach((t,i)=>{i%2===1&&t.querySelectorAll("td").forEach(h=>{h.style.backgroundColor="var(--scb-background-row)"});const o=t.querySelectorAll("th");o.length>0&&o.forEach((h,n)=>{n===0&&(h.style.paddingLeft="24px"),n===o.length-1?h.style.paddingRight="24px":h.style.paddingRight=""});const c=t.querySelectorAll("td");c.length>0&&c.forEach((h,n)=>{n===0&&(h.style.paddingLeft="24px"),n===c.length-1?h.style.paddingRight="24px":h.style.paddingRight=""})}),this.pagination&&this._paginateTable()}_onThClick(e){this._sortedColumn===e?this._sortDirection=this._sortDirection==="asc"?"desc":"asc":(this._sortedColumn=e,this._sortDirection="asc"),this._sortTable(e,this._sortDirection),this._attachThListeners()}_sortTable(e,s){const r=this.shadowRoot.querySelector("slot");if(!r)return;const a=r.assignedNodes({flatten:!0});let l=null;if(a.forEach(o=>{if(o.nodeType===Node.ELEMENT_NODE){const c=o.querySelector("tbody");c&&(l=c)}}),!l)return;let t;this._filteredRows?t=[...this._filteredRows]:t=this._getTopLevelRows(l),t.sort((o,c)=>{const h=this._getCellSortableValue(o.children[e]),n=this._getCellSortableValue(c.children[e]);return this._compareCellValues(h,n,s)});const i=this._tbodyObserver!==null;i&&this._disconnectTbodyObserver();try{t.forEach(o=>l.appendChild(o))}finally{i&&this._attachTbodyObserver()}this._filteredRows&&(this._filteredRows=t,this.totalRows=this._filteredRows.length),this.pagination&&this._paginateTable()}_getRowSearchText(e){return Array.from(e.cells).map(s=>this._getCellSortableValue(s)).join(" ")}_getCellSortableValue(e){if(!e)return"";const s=e,r=this._getSortableAttributeValue(s);if(r)return r;const a=[],l=s.textContent?.replace(/\s+/g," ").trim();return l&&a.push(l),s.querySelectorAll("[data-sort-value], [data-sort], [aria-label], [label], [value], [title]").forEach(t=>{const i=this._getSortableAttributeValue(t);i&&!a.includes(i)&&a.push(i)}),a.join(" ").trim()}_getSortableAttributeValue(e){return(e.getAttribute("data-sort-value")??e.getAttribute("data-sort")??e.getAttribute("aria-label")??e.getAttribute("label")??e.getAttribute("value")??e.getAttribute("title")??"").replace(/\s+/g," ").trim()}_compareCellValues(e,s,r){const a=this._parseSortableNumber(e),l=this._parseSortableNumber(s);if(a!==null&&l!==null)return r==="asc"?a-l:l-a;const t=Date.parse(e.replace(/\s+/g," ")),i=Date.parse(s.replace(/\s+/g," "));if(!isNaN(t)&&!isNaN(i))return r==="asc"?t-i:i-t;const o=e.localeCompare(s,"sv");return r==="asc"?o:-o}_parseSortableNumber(e){const s=e.trim();if(!/^[+-]?(?:\d+|\d{1,3}(?:[\s\u00a0\u202f]\d{3})+)(?:[,.]\d+)?$/.test(s))return null;const r=Number(s.replace(/[\s\u00a0\u202f]/g,"").replace(",","."));return Number.isNaN(r)?null:r}_updateTotalRows(){const e=this.shadowRoot.querySelector("slot");if(!e)return;const s=e.assignedNodes({flatten:!0});let r=null;s.forEach(a=>{if(a.nodeType===Node.ELEMENT_NODE){const l=a.querySelector("tbody");l&&(r=l)}}),r&&(this.totalRows=this._getTopLevelRows(r).length,this._ensureCurrentPageWithinBounds())}_paginateTable(){const e=this.shadowRoot.querySelector("slot");if(!e)return;const s=e.assignedNodes({flatten:!0});let r=null;if(s.forEach(i=>{if(i.nodeType===Node.ELEMENT_NODE){const o=i.querySelector("tbody");o&&(r=o)}}),!r)return;let a;this._filteredRows?a=this._filteredRows:a=this._getTopLevelRows(r),this._getTopLevelRows(r).forEach(i=>i.style.display="none");const l=(this.currentPage-1)*this.pageSize,t=l+this.pageSize;a.slice(l,t).forEach(i=>i.style.display="")}_changePage(e){const s=Math.ceil(this.totalRows/this.pageSize);e<1||e>s||(this.currentPage=e,this._paginateTable(),this.dispatchEvent(new CustomEvent("tableadvancedchange",{detail:{searchTerm:this.searchTerm,currentPage:this.currentPage},bubbles:!0,composed:!0})),this.requestUpdate())}},g.styles=v`:host{display:block;color:var(--md-sys-color-on-surface);font-family:var(--brand-font, Inter, Arial, sans-serif);--scb-background-row:var(--md-sys-color-surface)}scb-search{max-width:400px}.scb-table-scroll-wrapper{width:100%;overflow-x:auto;overflow-y:auto;max-width:100%;padding-bottom:24px}.scb-table-scroll-wrapper::-webkit-scrollbar{border-radius:var(--md-sys-shape-corner-large);height:8px;width:10px}.scb-table-scroll-wrapper::-webkit-scrollbar-thumb{background:var(--md-sys-color-on-surface);border-radius:var(--md-sys-shape-corner-large);cursor:pointer}.scb-table-scroll-wrapper::-webkit-scrollbar-track{background:var(--md-sys-color-secondary-container);border-radius:var(--md-sys-shape-corner-large)}::slotted(table){border-collapse:collapse;border-spacing:0;border-radius:24px;min-width:100%;overflow:hidden}.pagination{margin-top:16px;display:flex;justify-self:center}::slotted(th) .scb-sort-icon{pointer-events:none}::slotted(th:hover) .scb-sort-icon{pointer-events:auto}`,g);u([b({type:String})],d.prototype,"searchTerm",void 0);u([b({type:Boolean,attribute:"with-pagination"})],d.prototype,"pagination",void 0);u([b({type:Boolean,attribute:"with-filtering-search"})],d.prototype,"filteringSearch",void 0);u([b({type:Boolean,attribute:"no-scroll"})],d.prototype,"noScroll",void 0);u([b({type:Number,attribute:"page-size"})],d.prototype,"pageSize",void 0);u([b({type:Number})],d.prototype,"currentPage",void 0);u([b({type:Number})],d.prototype,"totalRows",void 0);d=u([m("scb-table-advanced")],d);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scb-wc",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.88",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -460,5 +460,5 @@
|
|
|
460
460
|
},
|
|
461
461
|
"./mvc/*": "./mvc/*"
|
|
462
462
|
},
|
|
463
|
-
"buildHash": "
|
|
463
|
+
"buildHash": "6058F176EC825A9E12E32FD3448ED12E141CFE214AB815F9049B49009C876D5D"
|
|
464
464
|
}
|
|
@@ -28,6 +28,7 @@ export declare class ScbTableAdvanced extends LitElement {
|
|
|
28
28
|
private _refreshFromTableContent;
|
|
29
29
|
private _ensureCurrentPageWithinBounds;
|
|
30
30
|
private _getTbody;
|
|
31
|
+
private _getTopLevelRows;
|
|
31
32
|
private _attachThListeners;
|
|
32
33
|
private _onThClick;
|
|
33
34
|
private _sortTable;
|
|
@@ -137,7 +137,7 @@ var o = class extends t {
|
|
|
137
137
|
t && (n = t);
|
|
138
138
|
}
|
|
139
139
|
}), !n) return;
|
|
140
|
-
let r = n, i =
|
|
140
|
+
let r = n, i = this._getTopLevelRows(r), a = this.searchTerm.trim().toLowerCase();
|
|
141
141
|
if (!a) this._filteredRows = null, i.forEach((e) => e.style.display = ""), this._updateTotalRows(), this._ensureCurrentPageWithinBounds(), this.pagination && this._paginateTable(), this._sortedColumn !== null && this._sortTable(this._sortedColumn, this._sortDirection);
|
|
142
142
|
else {
|
|
143
143
|
this._filteredRows = i.filter((e) => this._getRowSearchText(e).toLowerCase().includes(a)), i.forEach((e) => e.style.display = "none");
|
|
@@ -204,6 +204,9 @@ var o = class extends t {
|
|
|
204
204
|
}
|
|
205
205
|
return null;
|
|
206
206
|
}
|
|
207
|
+
_getTopLevelRows(e) {
|
|
208
|
+
return Array.from(e.children).filter((e) => e instanceof HTMLTableRowElement);
|
|
209
|
+
}
|
|
207
210
|
_attachThListeners() {
|
|
208
211
|
let e = this.shadowRoot.querySelector("slot");
|
|
209
212
|
if (!e) return;
|
|
@@ -251,7 +254,7 @@ var o = class extends t {
|
|
|
251
254
|
}
|
|
252
255
|
}), !i) return;
|
|
253
256
|
let a;
|
|
254
|
-
a = this._filteredRows ? [...this._filteredRows] :
|
|
257
|
+
a = this._filteredRows ? [...this._filteredRows] : this._getTopLevelRows(i), a.sort((n, r) => {
|
|
255
258
|
let i = this._getCellSortableValue(n.children[e]), a = this._getCellSortableValue(r.children[e]);
|
|
256
259
|
return this._compareCellValues(i, a, t);
|
|
257
260
|
});
|
|
@@ -303,7 +306,7 @@ var o = class extends t {
|
|
|
303
306
|
let t = e.querySelector("tbody");
|
|
304
307
|
t && (n = t);
|
|
305
308
|
}
|
|
306
|
-
}), n && (this.totalRows =
|
|
309
|
+
}), n && (this.totalRows = this._getTopLevelRows(n).length, this._ensureCurrentPageWithinBounds());
|
|
307
310
|
}
|
|
308
311
|
_paginateTable() {
|
|
309
312
|
let e = this.shadowRoot.querySelector("slot");
|
|
@@ -316,7 +319,7 @@ var o = class extends t {
|
|
|
316
319
|
}
|
|
317
320
|
}), !n) return;
|
|
318
321
|
let r;
|
|
319
|
-
r = this._filteredRows ? this._filteredRows :
|
|
322
|
+
r = this._filteredRows ? this._filteredRows : this._getTopLevelRows(n), this._getTopLevelRows(n).forEach((e) => e.style.display = "none");
|
|
320
323
|
let i = (this.currentPage - 1) * this.pageSize, a = i + this.pageSize;
|
|
321
324
|
r.slice(i, a).forEach((e) => e.style.display = "");
|
|
322
325
|
}
|
package/scb-wc.bundle.js
CHANGED
|
@@ -13333,7 +13333,7 @@ var ScbWc=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module
|
|
|
13333
13333
|
></scb-pagination>
|
|
13334
13334
|
`:``}
|
|
13335
13335
|
</div>
|
|
13336
|
-
`}_onSearchInput(e){let t=e.target.value;this.searchTerm=t,this._filterTable(),this.dispatchEvent(new CustomEvent(`tableadvancedchange`,{detail:{searchTerm:this.searchTerm,currentPage:this.currentPage},bubbles:!0,composed:!0}))}_filterTable(){let e=this.shadowRoot.querySelector(`slot`);if(!e)return;let t=e.assignedNodes({flatten:!0}),n=null;if(t.forEach(e=>{if(e.nodeType===Node.ELEMENT_NODE){let t=e.querySelector(`tbody`);t&&(n=t)}}),!n)return;let r=n,i=Array.from(r.querySelectorAll(`tr`)),a=this.searchTerm.trim().toLowerCase();if(!a)this._filteredRows=null,i.forEach(e=>e.style.display=``),this._updateTotalRows(),this._ensureCurrentPageWithinBounds(),this.pagination&&this._paginateTable(),this._sortedColumn!==null&&this._sortTable(this._sortedColumn,this._sortDirection);else{this._filteredRows=i.filter(e=>this._getRowSearchText(e).toLowerCase().includes(a)),i.forEach(e=>e.style.display=`none`);let e=this._filteredRows;this._sortedColumn!==null&&(e=[...e],e.sort((e,t)=>{let n=this._getCellSortableValue(e.children[this._sortedColumn]),r=this._getCellSortableValue(t.children[this._sortedColumn]);return this._compareCellValues(n,r,this._sortDirection)}),this._filteredRows=e),this.totalRows=this._filteredRows.length,this._ensureCurrentPageWithinBounds(),this.pagination?this._paginateTable():this._filteredRows.forEach(e=>e.style.display=``)}}firstUpdated(){let e=this.shadowRoot.querySelector(`slot`);e&&(e.addEventListener(`slotchange`,()=>this._attachThListeners()),this._attachThListeners(),this._attachTbodyObserver(),this._refreshFromTableContent())}updated(e){super.updated(e),(e.has(`searchTerm`)||e.has(`currentPage`)||e.has(`pageSize`)||e.has(`filteringSearch`)||e.has(`pagination`))&&this.updateComplete.then(()=>{this.isConnected&&this._refreshFromTableContent()})}_disconnectTbodyObserver(){this._tbodyObserver&&=(this._tbodyObserver.disconnect(),null),this._observedTbody=null}_attachTbodyObserver(){let e=this._getTbody();if(!e){this._disconnectTbodyObserver();return}this._observedTbody!==e&&(this._disconnectTbodyObserver(),this._observedTbody=e,this._tbodyObserver=new MutationObserver(()=>{this._suppressTbodyObserver||this._scheduleTableRefresh()}),this._tbodyObserver.observe(e,{childList:!0,subtree:!0,characterData:!0}))}_scheduleTableRefresh(){this._pendingTableRefresh||(this._pendingTableRefresh=!0,queueMicrotask(()=>{this._pendingTableRefresh=!1,this._refreshFromTableContent()}))}_refreshFromTableContent(){if(this._attachTbodyObserver(),this.filteringSearch){this._filterTable();return}if(this._updateTotalRows(),this._ensureCurrentPageWithinBounds(),this._sortedColumn!==null){this._sortTable(this._sortedColumn,this._sortDirection);return}this.pagination&&this._paginateTable()}_ensureCurrentPageWithinBounds(){let e=Math.max(1,Math.ceil(this.totalRows/this.pageSize)),t=Math.min(Math.max(1,this.currentPage),e);t!==this.currentPage&&(this.currentPage=t)}_getTbody(){let e=this.shadowRoot.querySelector(`slot`);if(!e)return null;let t=e.assignedNodes({flatten:!0});for(let e of t)if(e.nodeType===Node.ELEMENT_NODE){let t=e.querySelector(`tbody`);if(t)return t}return null}_attachThListeners(){let e=this.shadowRoot.querySelector(`slot`);if(!e)return;let t=e.assignedNodes({flatten:!0}),n=[],r=[],i=[];t.forEach(e=>{e.nodeType===Node.ELEMENT_NODE&&(n.push(...e.querySelectorAll(`th`)),r.push(...e.querySelectorAll(`td`)),i.push(...e.querySelectorAll(`tr`)))}),n.forEach((e,t)=>{e.style.textAlign=`left`,e.style.padding=`16px 0px 16px 32px`,e.style.position=`relative`,e.style.backgroundColor=`var(--md-sys-color-surface)`,e.style.fontFamily=`var(--md-sys-typescale-label-medium-font)`,e.style.fontSize=`var(--md-sys-typescale-label-medium-size)`,e.style.lineHeight=`var(--md-sys-typescale-label-medium-line-height)`,e.style.fontWeight=`var(--md-sys-typescale-label-medium-weight)`,e.style.letterSpacing=`var(--md-sys-typescale-label-medium-tracking)`,e.style.verticalAlign=`bottom`;let n=e.firstChild;if(n&&n.nodeType===Node.TEXT_NODE&&n.textContent?.trim()||n&&n.nodeType===Node.ELEMENT_NODE&&n.tagName.toLowerCase()!==`p`){let i=document.createElement(`p`);i.textContent=n.textContent?n.textContent.trim():``,i.style.margin=`0`,e.replaceChild(i,n),e.querySelectorAll(`scb-icon-button.scb-sort-icon`).forEach(e=>e.remove());let a=document.createElement(`scb-icon-button`);a.className=`scb-sort-icon`,a.onclick=()=>this._onThClick(t),a.setAttribute(`variant`,`standard`),a.setAttribute(`size`,`small`),this._sortedColumn===t?(a.setAttribute(`variant`,`filled-tonal`),a.setAttribute(`icon`,this._sortDirection===`asc`?`arrow_downward`:`arrow_upward`)):(a.setAttribute(`icon`,`swap_horiz`),a.style.transform+=` rotate(90deg)`,a.style.alignSelf=`end`);var r=document.createElement(`div`);r.style.display=`flex`,r.style.gap=`8px`,r.style.flexWrap=`nowrap`,r.style.alignItems=`center`,r.appendChild(i),r.appendChild(a),e.appendChild(r)}}),r.forEach(e=>{e.style.padding=`16px 0px 16px 32px`,e.style.textAlign=`left`,e.style.borderTop=`1px solid var(--md-sys-color-outline-variant)`,e.style.verticalAlign=`text-top`,e.style.backgroundColor=`var(--md-sys-color-surface)`,e.style.fontFamily=`var(--md-sys-typescale-body-medium-font)`,e.style.fontSize=`var(--md-sys-typescale-body-medium-size)`,e.style.lineHeight=`var(--md-sys-typescale-body-medium-line-height)`,e.style.fontWeight=`var(--md-sys-typescale-body-medium-weight)`,e.style.letterSpacing=`var(--md-sys-typescale-body-medium-tracking)`}),i.forEach((e,t)=>{t%2==1&&e.querySelectorAll(`td`).forEach(e=>{e.style.backgroundColor=`var(--scb-background-row)`});let n=e.querySelectorAll(`th`);n.length>0&&n.forEach((e,t)=>{t===0&&(e.style.paddingLeft=`24px`),t===n.length-1?e.style.paddingRight=`24px`:e.style.paddingRight=``});let r=e.querySelectorAll(`td`);r.length>0&&r.forEach((e,t)=>{t===0&&(e.style.paddingLeft=`24px`),t===r.length-1?e.style.paddingRight=`24px`:e.style.paddingRight=``})}),this.pagination&&this._paginateTable()}_onThClick(e){this._sortedColumn===e?this._sortDirection=this._sortDirection===`asc`?`desc`:`asc`:(this._sortedColumn=e,this._sortDirection=`asc`),this._sortTable(e,this._sortDirection),this._attachThListeners()}_sortTable(e,t){let n=this.shadowRoot.querySelector(`slot`);if(!n)return;let r=n.assignedNodes({flatten:!0}),i=null;if(r.forEach(e=>{if(e.nodeType===Node.ELEMENT_NODE){let t=e.querySelector(`tbody`);t&&(i=t)}}),!i)return;let a;a=this._filteredRows?[...this._filteredRows]:Array.from(i.querySelectorAll(`tr`)),a.sort((n,r)=>{let i=this._getCellSortableValue(n.children[e]),a=this._getCellSortableValue(r.children[e]);return this._compareCellValues(i,a,t)});let o=this._tbodyObserver!==null;o&&this._disconnectTbodyObserver();try{a.forEach(e=>i.appendChild(e))}finally{o&&this._attachTbodyObserver()}this._filteredRows&&(this._filteredRows=a,this.totalRows=this._filteredRows.length),this.pagination&&this._paginateTable()}_getRowSearchText(e){return Array.from(e.cells).map(e=>this._getCellSortableValue(e)).join(` `)}_getCellSortableValue(e){if(!e)return``;let t=e,n=this._getSortableAttributeValue(t);if(n)return n;let r=[],i=t.textContent?.replace(/\s+/g,` `).trim();return i&&r.push(i),t.querySelectorAll(`[data-sort-value], [data-sort], [aria-label], [label], [value], [title]`).forEach(e=>{let t=this._getSortableAttributeValue(e);t&&!r.includes(t)&&r.push(t)}),r.join(` `).trim()}_getSortableAttributeValue(e){return(e.getAttribute(`data-sort-value`)??e.getAttribute(`data-sort`)??e.getAttribute(`aria-label`)??e.getAttribute(`label`)??e.getAttribute(`value`)??e.getAttribute(`title`)??``).replace(/\s+/g,` `).trim()}_compareCellValues(e,t,n){let r=this._parseSortableNumber(e),i=this._parseSortableNumber(t);if(r!==null&&i!==null)return n===`asc`?r-i:i-r;let a=Date.parse(e.replace(/\s+/g,` `)),o=Date.parse(t.replace(/\s+/g,` `));if(!isNaN(a)&&!isNaN(o))return n===`asc`?a-o:o-a;let s=e.localeCompare(t,`sv`);return n===`asc`?s:-s}_parseSortableNumber(e){let t=e.trim();if(!/^[+-]?(?:\d+|\d{1,3}(?:[\s\u00a0\u202f]\d{3})+)(?:[,.]\d+)?$/.test(t))return null;let n=Number(t.replace(/[\s\u00a0\u202f]/g,``).replace(`,`,`.`));return Number.isNaN(n)?null:n}_updateTotalRows(){let e=this.shadowRoot.querySelector(`slot`);if(!e)return;let t=e.assignedNodes({flatten:!0}),n=null;t.forEach(e=>{if(e.nodeType===Node.ELEMENT_NODE){let t=e.querySelector(`tbody`);t&&(n=t)}}),n&&(this.totalRows=n.querySelectorAll(`tr`).length,this._ensureCurrentPageWithinBounds())}_paginateTable(){let e=this.shadowRoot.querySelector(`slot`);if(!e)return;let t=e.assignedNodes({flatten:!0}),n=null;if(t.forEach(e=>{if(e.nodeType===Node.ELEMENT_NODE){let t=e.querySelector(`tbody`);t&&(n=t)}}),!n)return;let r;r=this._filteredRows?this._filteredRows:Array.from(n.querySelectorAll(`tr`)),Array.from(n.querySelectorAll(`tr`)).forEach(e=>e.style.display=`none`);let i=(this.currentPage-1)*this.pageSize,a=i+this.pageSize;r.slice(i,a).forEach(e=>e.style.display=``)}_changePage(e){let t=Math.ceil(this.totalRows/this.pageSize);e<1||e>t||(this.currentPage=e,this._paginateTable(),this.dispatchEvent(new CustomEvent(`tableadvancedchange`,{detail:{searchTerm:this.searchTerm,currentPage:this.currentPage},bubbles:!0,composed:!0})),this.requestUpdate())}};P([_({type:String})],Ef.prototype,`searchTerm`,void 0),P([_({type:Boolean,attribute:`with-pagination`})],Ef.prototype,`pagination`,void 0),P([_({type:Boolean,attribute:`with-filtering-search`})],Ef.prototype,`filteringSearch`,void 0),P([_({type:Boolean,attribute:`no-scroll`})],Ef.prototype,`noScroll`,void 0),P([_({type:Number,attribute:`page-size`})],Ef.prototype,`pageSize`,void 0),P([_({type:Number})],Ef.prototype,`currentPage`,void 0),P([_({type:Number})],Ef.prototype,`totalRows`,void 0),Ef=P([o(`scb-table-advanced`)],Ef),b(),w(),k(),F();var Df=class extends js{constructor(...e){super(...e),this.iconOnly=!1,this.inlineIcon=!1,this._onActivate=()=>{let e=this.textContent?.trim()??``;this.dispatchEvent(new CustomEvent(`activate`,{detail:{label:e},bubbles:!0,composed:!0}))}}connectedCallback(){super.connectedCallback(),this.setAttribute(`role`,`tab`)}get icon(){return this._icon}set icon(e){let t=this._icon;t!==e&&(this._icon=e,this.requestUpdate(`icon`,t),this.updateIconSlot())}firstUpdated(e){super.firstUpdated(e),this.addEventListener(`click`,this._onActivate),this._icon&&this.updateIconSlot()}updated(){if(super.updated(),this.setAttribute(`aria-selected`,this.active?`true`:`false`),this.iconOnly&&!this.hasAttribute(`aria-label`)){let e=this.textContent?.trim()??``;e&&this.setAttribute(`aria-label`,e)}}static{this.styles=[...js.styles,m`
|
|
13336
|
+
`}_onSearchInput(e){let t=e.target.value;this.searchTerm=t,this._filterTable(),this.dispatchEvent(new CustomEvent(`tableadvancedchange`,{detail:{searchTerm:this.searchTerm,currentPage:this.currentPage},bubbles:!0,composed:!0}))}_filterTable(){let e=this.shadowRoot.querySelector(`slot`);if(!e)return;let t=e.assignedNodes({flatten:!0}),n=null;if(t.forEach(e=>{if(e.nodeType===Node.ELEMENT_NODE){let t=e.querySelector(`tbody`);t&&(n=t)}}),!n)return;let r=n,i=this._getTopLevelRows(r),a=this.searchTerm.trim().toLowerCase();if(!a)this._filteredRows=null,i.forEach(e=>e.style.display=``),this._updateTotalRows(),this._ensureCurrentPageWithinBounds(),this.pagination&&this._paginateTable(),this._sortedColumn!==null&&this._sortTable(this._sortedColumn,this._sortDirection);else{this._filteredRows=i.filter(e=>this._getRowSearchText(e).toLowerCase().includes(a)),i.forEach(e=>e.style.display=`none`);let e=this._filteredRows;this._sortedColumn!==null&&(e=[...e],e.sort((e,t)=>{let n=this._getCellSortableValue(e.children[this._sortedColumn]),r=this._getCellSortableValue(t.children[this._sortedColumn]);return this._compareCellValues(n,r,this._sortDirection)}),this._filteredRows=e),this.totalRows=this._filteredRows.length,this._ensureCurrentPageWithinBounds(),this.pagination?this._paginateTable():this._filteredRows.forEach(e=>e.style.display=``)}}firstUpdated(){let e=this.shadowRoot.querySelector(`slot`);e&&(e.addEventListener(`slotchange`,()=>this._attachThListeners()),this._attachThListeners(),this._attachTbodyObserver(),this._refreshFromTableContent())}updated(e){super.updated(e),(e.has(`searchTerm`)||e.has(`currentPage`)||e.has(`pageSize`)||e.has(`filteringSearch`)||e.has(`pagination`))&&this.updateComplete.then(()=>{this.isConnected&&this._refreshFromTableContent()})}_disconnectTbodyObserver(){this._tbodyObserver&&=(this._tbodyObserver.disconnect(),null),this._observedTbody=null}_attachTbodyObserver(){let e=this._getTbody();if(!e){this._disconnectTbodyObserver();return}this._observedTbody!==e&&(this._disconnectTbodyObserver(),this._observedTbody=e,this._tbodyObserver=new MutationObserver(()=>{this._suppressTbodyObserver||this._scheduleTableRefresh()}),this._tbodyObserver.observe(e,{childList:!0,subtree:!0,characterData:!0}))}_scheduleTableRefresh(){this._pendingTableRefresh||(this._pendingTableRefresh=!0,queueMicrotask(()=>{this._pendingTableRefresh=!1,this._refreshFromTableContent()}))}_refreshFromTableContent(){if(this._attachTbodyObserver(),this.filteringSearch){this._filterTable();return}if(this._updateTotalRows(),this._ensureCurrentPageWithinBounds(),this._sortedColumn!==null){this._sortTable(this._sortedColumn,this._sortDirection);return}this.pagination&&this._paginateTable()}_ensureCurrentPageWithinBounds(){let e=Math.max(1,Math.ceil(this.totalRows/this.pageSize)),t=Math.min(Math.max(1,this.currentPage),e);t!==this.currentPage&&(this.currentPage=t)}_getTbody(){let e=this.shadowRoot.querySelector(`slot`);if(!e)return null;let t=e.assignedNodes({flatten:!0});for(let e of t)if(e.nodeType===Node.ELEMENT_NODE){let t=e.querySelector(`tbody`);if(t)return t}return null}_getTopLevelRows(e){return Array.from(e.children).filter(e=>e instanceof HTMLTableRowElement)}_attachThListeners(){let e=this.shadowRoot.querySelector(`slot`);if(!e)return;let t=e.assignedNodes({flatten:!0}),n=[],r=[],i=[];t.forEach(e=>{e.nodeType===Node.ELEMENT_NODE&&(n.push(...e.querySelectorAll(`th`)),r.push(...e.querySelectorAll(`td`)),i.push(...e.querySelectorAll(`tr`)))}),n.forEach((e,t)=>{e.style.textAlign=`left`,e.style.padding=`16px 0px 16px 32px`,e.style.position=`relative`,e.style.backgroundColor=`var(--md-sys-color-surface)`,e.style.fontFamily=`var(--md-sys-typescale-label-medium-font)`,e.style.fontSize=`var(--md-sys-typescale-label-medium-size)`,e.style.lineHeight=`var(--md-sys-typescale-label-medium-line-height)`,e.style.fontWeight=`var(--md-sys-typescale-label-medium-weight)`,e.style.letterSpacing=`var(--md-sys-typescale-label-medium-tracking)`,e.style.verticalAlign=`bottom`;let n=e.firstChild;if(n&&n.nodeType===Node.TEXT_NODE&&n.textContent?.trim()||n&&n.nodeType===Node.ELEMENT_NODE&&n.tagName.toLowerCase()!==`p`){let i=document.createElement(`p`);i.textContent=n.textContent?n.textContent.trim():``,i.style.margin=`0`,e.replaceChild(i,n),e.querySelectorAll(`scb-icon-button.scb-sort-icon`).forEach(e=>e.remove());let a=document.createElement(`scb-icon-button`);a.className=`scb-sort-icon`,a.onclick=()=>this._onThClick(t),a.setAttribute(`variant`,`standard`),a.setAttribute(`size`,`small`),this._sortedColumn===t?(a.setAttribute(`variant`,`filled-tonal`),a.setAttribute(`icon`,this._sortDirection===`asc`?`arrow_downward`:`arrow_upward`)):(a.setAttribute(`icon`,`swap_horiz`),a.style.transform+=` rotate(90deg)`,a.style.alignSelf=`end`);var r=document.createElement(`div`);r.style.display=`flex`,r.style.gap=`8px`,r.style.flexWrap=`nowrap`,r.style.alignItems=`center`,r.appendChild(i),r.appendChild(a),e.appendChild(r)}}),r.forEach(e=>{e.style.padding=`16px 0px 16px 32px`,e.style.textAlign=`left`,e.style.borderTop=`1px solid var(--md-sys-color-outline-variant)`,e.style.verticalAlign=`text-top`,e.style.backgroundColor=`var(--md-sys-color-surface)`,e.style.fontFamily=`var(--md-sys-typescale-body-medium-font)`,e.style.fontSize=`var(--md-sys-typescale-body-medium-size)`,e.style.lineHeight=`var(--md-sys-typescale-body-medium-line-height)`,e.style.fontWeight=`var(--md-sys-typescale-body-medium-weight)`,e.style.letterSpacing=`var(--md-sys-typescale-body-medium-tracking)`}),i.forEach((e,t)=>{t%2==1&&e.querySelectorAll(`td`).forEach(e=>{e.style.backgroundColor=`var(--scb-background-row)`});let n=e.querySelectorAll(`th`);n.length>0&&n.forEach((e,t)=>{t===0&&(e.style.paddingLeft=`24px`),t===n.length-1?e.style.paddingRight=`24px`:e.style.paddingRight=``});let r=e.querySelectorAll(`td`);r.length>0&&r.forEach((e,t)=>{t===0&&(e.style.paddingLeft=`24px`),t===r.length-1?e.style.paddingRight=`24px`:e.style.paddingRight=``})}),this.pagination&&this._paginateTable()}_onThClick(e){this._sortedColumn===e?this._sortDirection=this._sortDirection===`asc`?`desc`:`asc`:(this._sortedColumn=e,this._sortDirection=`asc`),this._sortTable(e,this._sortDirection),this._attachThListeners()}_sortTable(e,t){let n=this.shadowRoot.querySelector(`slot`);if(!n)return;let r=n.assignedNodes({flatten:!0}),i=null;if(r.forEach(e=>{if(e.nodeType===Node.ELEMENT_NODE){let t=e.querySelector(`tbody`);t&&(i=t)}}),!i)return;let a;a=this._filteredRows?[...this._filteredRows]:this._getTopLevelRows(i),a.sort((n,r)=>{let i=this._getCellSortableValue(n.children[e]),a=this._getCellSortableValue(r.children[e]);return this._compareCellValues(i,a,t)});let o=this._tbodyObserver!==null;o&&this._disconnectTbodyObserver();try{a.forEach(e=>i.appendChild(e))}finally{o&&this._attachTbodyObserver()}this._filteredRows&&(this._filteredRows=a,this.totalRows=this._filteredRows.length),this.pagination&&this._paginateTable()}_getRowSearchText(e){return Array.from(e.cells).map(e=>this._getCellSortableValue(e)).join(` `)}_getCellSortableValue(e){if(!e)return``;let t=e,n=this._getSortableAttributeValue(t);if(n)return n;let r=[],i=t.textContent?.replace(/\s+/g,` `).trim();return i&&r.push(i),t.querySelectorAll(`[data-sort-value], [data-sort], [aria-label], [label], [value], [title]`).forEach(e=>{let t=this._getSortableAttributeValue(e);t&&!r.includes(t)&&r.push(t)}),r.join(` `).trim()}_getSortableAttributeValue(e){return(e.getAttribute(`data-sort-value`)??e.getAttribute(`data-sort`)??e.getAttribute(`aria-label`)??e.getAttribute(`label`)??e.getAttribute(`value`)??e.getAttribute(`title`)??``).replace(/\s+/g,` `).trim()}_compareCellValues(e,t,n){let r=this._parseSortableNumber(e),i=this._parseSortableNumber(t);if(r!==null&&i!==null)return n===`asc`?r-i:i-r;let a=Date.parse(e.replace(/\s+/g,` `)),o=Date.parse(t.replace(/\s+/g,` `));if(!isNaN(a)&&!isNaN(o))return n===`asc`?a-o:o-a;let s=e.localeCompare(t,`sv`);return n===`asc`?s:-s}_parseSortableNumber(e){let t=e.trim();if(!/^[+-]?(?:\d+|\d{1,3}(?:[\s\u00a0\u202f]\d{3})+)(?:[,.]\d+)?$/.test(t))return null;let n=Number(t.replace(/[\s\u00a0\u202f]/g,``).replace(`,`,`.`));return Number.isNaN(n)?null:n}_updateTotalRows(){let e=this.shadowRoot.querySelector(`slot`);if(!e)return;let t=e.assignedNodes({flatten:!0}),n=null;t.forEach(e=>{if(e.nodeType===Node.ELEMENT_NODE){let t=e.querySelector(`tbody`);t&&(n=t)}}),n&&(this.totalRows=this._getTopLevelRows(n).length,this._ensureCurrentPageWithinBounds())}_paginateTable(){let e=this.shadowRoot.querySelector(`slot`);if(!e)return;let t=e.assignedNodes({flatten:!0}),n=null;if(t.forEach(e=>{if(e.nodeType===Node.ELEMENT_NODE){let t=e.querySelector(`tbody`);t&&(n=t)}}),!n)return;let r;r=this._filteredRows?this._filteredRows:this._getTopLevelRows(n),this._getTopLevelRows(n).forEach(e=>e.style.display=`none`);let i=(this.currentPage-1)*this.pageSize,a=i+this.pageSize;r.slice(i,a).forEach(e=>e.style.display=``)}_changePage(e){let t=Math.ceil(this.totalRows/this.pageSize);e<1||e>t||(this.currentPage=e,this._paginateTable(),this.dispatchEvent(new CustomEvent(`tableadvancedchange`,{detail:{searchTerm:this.searchTerm,currentPage:this.currentPage},bubbles:!0,composed:!0})),this.requestUpdate())}};P([_({type:String})],Ef.prototype,`searchTerm`,void 0),P([_({type:Boolean,attribute:`with-pagination`})],Ef.prototype,`pagination`,void 0),P([_({type:Boolean,attribute:`with-filtering-search`})],Ef.prototype,`filteringSearch`,void 0),P([_({type:Boolean,attribute:`no-scroll`})],Ef.prototype,`noScroll`,void 0),P([_({type:Number,attribute:`page-size`})],Ef.prototype,`pageSize`,void 0),P([_({type:Number})],Ef.prototype,`currentPage`,void 0),P([_({type:Number})],Ef.prototype,`totalRows`,void 0),Ef=P([o(`scb-table-advanced`)],Ef),b(),w(),k(),F();var Df=class extends js{constructor(...e){super(...e),this.iconOnly=!1,this.inlineIcon=!1,this._onActivate=()=>{let e=this.textContent?.trim()??``;this.dispatchEvent(new CustomEvent(`activate`,{detail:{label:e},bubbles:!0,composed:!0}))}}connectedCallback(){super.connectedCallback(),this.setAttribute(`role`,`tab`)}get icon(){return this._icon}set icon(e){let t=this._icon;t!==e&&(this._icon=e,this.requestUpdate(`icon`,t),this.updateIconSlot())}firstUpdated(e){super.firstUpdated(e),this.addEventListener(`click`,this._onActivate),this._icon&&this.updateIconSlot()}updated(){if(super.updated(),this.setAttribute(`aria-selected`,this.active?`true`:`false`),this.iconOnly&&!this.hasAttribute(`aria-label`)){let e=this.textContent?.trim()??``;e&&this.setAttribute(`aria-label`,e)}}static{this.styles=[...js.styles,m`
|
|
13337
13337
|
/* Icon-only: dölj textslot */
|
|
13338
13338
|
:host([icon-only]) slot:not([name='icon']) {
|
|
13339
13339
|
display: none;
|