scb-wc 0.1.162 → 0.1.164
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/mvc/components/scb-table-advanced/scb-table-advanced.js +1 -1
- package/mvc/scb-wc-core.css +1 -1
- package/mvc/scb-wc-selfhost.css +1 -1
- package/mvc/scb-wc.css +1 -1
- package/package.json +2 -2
- package/scb-table-advanced/scb-table-advanced.js +2 -2
- package/scb-wc-core.css +1 -1
- package/scb-wc-selfhost.css +1 -1
- package/scb-wc.bundle.js +1 -1
- package/scb-wc.css +1 -1
|
@@ -22,4 +22,4 @@ import{h as _,m as v,p as g,v as p,y as m}from"../../vendor/vendor.js";import"..
|
|
|
22
22
|
></scb-pagination>
|
|
23
23
|
`:""}
|
|
24
24
|
</div>
|
|
25
|
-
`}_onSearchInput(e){const r=e.target.value;this.searchTerm=r,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 r=e.assignedNodes({flatten:!0});let s=null;if(r.forEach(t=>{if(t.nodeType===Node.ELEMENT_NODE){const l=t.querySelector("tbody");l&&(s=l)}}),!s)return;const a=s,i=this._getTopLevelRows(a),o=this.searchTerm.trim().toLowerCase();if(!o)this._filteredRows=null,i.forEach(t=>t.style.display=""),this._updateTotalRows(),this._ensureCurrentPageWithinBounds(),this.pagination&&this._paginateTable(),this._sortedColumn!==null&&this._sortTable(this._sortedColumn,this._sortDirection);else{this._filteredRows=i.filter(l=>this._getRowSearchText(l).toLowerCase().includes(o)),i.forEach(l=>l.style.display="none");let t=this._filteredRows;this._sortedColumn!==null&&(t=[...t],t.sort((l,d)=>{const b=this._getCellSortableValue(l.children[this._sortedColumn]),c=this._getCellSortableValue(d.children[this._sortedColumn]);return this._compareCellValues(b,c,this._sortDirection)}),this._filteredRows=t),this.totalRows=this._filteredRows.length,this._ensureCurrentPageWithinBounds(),this.pagination?this._paginateTable():this._filteredRows.forEach(l=>l.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("disableSorting")&&this._sortedColumn!==null&&!this._isColumnSortable(this._sortedColumn)&&(this._sortedColumn=null,this._sortDirection="asc"),(e.has("searchTerm")||e.has("currentPage")||e.has("pageSize")||e.has("filteringSearch")||e.has("pagination")||e.has("disableSorting"))&&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)),r=Math.min(Math.max(1,this.currentPage),e);r!==this.currentPage&&(this.currentPage=r)}_getTbody(){const e=this.shadowRoot.querySelector("slot");if(!e)return null;const r=e.assignedNodes({flatten:!0});for(const s of r)if(s.nodeType===Node.ELEMENT_NODE){const a=s.querySelector("tbody");if(a)return a}return null}_getTopLevelRows(e){return Array.from(e.children).filter(r=>r instanceof HTMLTableRowElement)}_attachThListeners(){const e=this.shadowRoot.querySelector("slot");if(!e)return;const r=e.assignedNodes({flatten:!0}),s=[],a=[],i=[],o=[];r.forEach(t=>{t.nodeType===Node.ELEMENT_NODE&&(Array.from(t.querySelectorAll("thead")).forEach(l=>{s.push(...Array.from(l.querySelectorAll("th")))}),a.push(...t.querySelectorAll("th")),i.push(...t.querySelectorAll("td")),o.push(...t.querySelectorAll("tr")))}),a.forEach(t=>{const l=s.indexOf(t),d=l!==-1;t.style.textAlign="left",t.style.padding="var(--scb-table-cell-padding-block) var(--scb-table-cell-padding-inline-end) var(--scb-table-cell-padding-block) var(--scb-table-cell-padding-inline)",t.style.position="relative",t.style.backgroundColor="var(--md-sys-color-surface)",t.style.fontFamily="var(--scb-table-header-font)",t.style.fontSize="var(--scb-table-header-font-size)",t.style.lineHeight="var(--scb-table-header-line-height)",t.style.fontWeight="var(--scb-table-header-font-weight)",t.style.letterSpacing="var(--scb-table-header-letter-spacing)",t.style.verticalAlign="bottom",this._removeGeneratedSortMarkup(t),t.hasAttribute("scope")||(d?t.setAttribute("scope","col"):t.closest("tbody")&&t.setAttribute("scope","row"));const b=this._getOrCreateHeaderLabel(t,l);if((b instanceof HTMLParagraphElement||b.getAttribute("data-scb-generated-label")==="true")&&this._applyGeneratedCellTextReset(b),!d){t.removeAttribute("aria-sort");return}if(!this._isColumnSortable(l)){t.removeAttribute("aria-sort");return}t.setAttribute("aria-sort",this._getHeaderAriaSort(l));const c=this._getNormalizedText(b.textContent)||`kolumn ${Math.max(l,0)+1}`,n=document.createElement("scb-icon-button");n.className="scb-sort-icon",n.onclick=()=>this._onThClick(l),n.setAttribute("variant","standard"),n.setAttribute("size","small"),n.setAttribute("aria-label",this._getSortButtonLabel(c,l)),this._sortedColumn===l?(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"),this._wrapHeaderWithSortControl(t,b,n)}),i.forEach(t=>{t.style.padding="var(--scb-table-cell-padding-block) var(--scb-table-cell-padding-inline-end) var(--scb-table-cell-padding-block) var(--scb-table-cell-padding-inline)",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(--scb-table-cell-font)",t.style.fontSize="var(--scb-table-cell-font-size)",t.style.lineHeight="var(--scb-table-cell-line-height)",t.style.fontWeight="var(--scb-table-cell-font-weight)",t.style.letterSpacing="var(--scb-table-cell-letter-spacing)"}),o.forEach((t,l)=>{l%2===1&&t.querySelectorAll("td").forEach(c=>{c.style.backgroundColor="var(--scb-background-row)"});const d=t.querySelectorAll("th");d.length>0&&d.forEach((c,n)=>{n===0&&(c.style.paddingLeft="var(--scb-table-cell-edge-padding-inline)"),n===d.length-1?c.style.paddingRight="var(--scb-table-cell-edge-padding-inline)":c.style.paddingRight=""});const b=t.querySelectorAll("td");b.length>0&&b.forEach((c,n)=>{n===0&&(c.style.paddingLeft="var(--scb-table-cell-edge-padding-inline)"),n===b.length-1?c.style.paddingRight="var(--scb-table-cell-edge-padding-inline)":c.style.paddingRight=""})}),this.pagination&&this._paginateTable()}_applyGeneratedCellTextReset(e){e.style.margin="0",e.style.color="inherit",e.style.fontFamily="inherit",e.style.fontSize="inherit",e.style.lineHeight="inherit",e.style.fontWeight="inherit",e.style.letterSpacing="inherit"}_removeGeneratedSortMarkup(e){e.querySelectorAll("scb-icon-button.scb-sort-icon").forEach(a=>a.remove());const r=e.querySelector(':scope > [data-scb-sort-header="true"]');if(!(r instanceof HTMLElement))return;const s=r.querySelector(':scope > [data-scb-sort-label="true"]');if(s instanceof HTMLElement){r.replaceWith(s);return}r.remove()}_getOrCreateHeaderLabel(e,r){const s=e.querySelector(':scope > [data-scb-sort-label="true"]');if(s instanceof HTMLElement)return s;const a=e.querySelector(":scope > p");if(a instanceof HTMLParagraphElement)return a.setAttribute("data-scb-sort-label","true"),a;const i=Array.from(e.children).find(t=>t instanceof HTMLElement&&!t.matches("scb-icon-button.scb-sort-icon"));if(i)return i.setAttribute("data-scb-sort-label","true"),i;const o=document.createElement("p");return o.setAttribute("data-scb-sort-label","true"),o.setAttribute("data-scb-generated-label","true"),o.textContent=this._getNormalizedText(e.textContent)||`kolumn ${Math.max(r,0)+1}`,e.textContent="",e.appendChild(o),o}_wrapHeaderWithSortControl(e,r,s){const a=document.createElement("div");a.setAttribute("data-scb-sort-header","true"),a.style.display="flex",a.style.gap="8px",a.style.flexWrap="nowrap",a.style.alignItems="center",a.appendChild(r),a.appendChild(s),e.appendChild(a)}_getNormalizedText(e){return(e??"").replace(/\s+/g," ").trim()}_onThClick(e){this._isColumnSortable(e)&&(this._sortedColumn===e?this._sortDirection=this._sortDirection==="asc"?"desc":"asc":(this._sortedColumn=e,this._sortDirection="asc"),this._sortTable(e,this._sortDirection),this._attachThListeners())}_getHeaderAriaSort(e){return this._sortedColumn!==e?"none":this._sortDirection==="asc"?"ascending":"descending"}_getSortButtonLabel(e,r){return`Sortera ${e||`kolumn ${r+1}`} ${this._sortedColumn===r&&this._sortDirection==="asc"?"fallande":"stigande"}`}_isColumnSortable(e){return!(Array.isArray(this.disableSorting)?this.disableSorting:[]).some(r=>Number(r)===e)}_sortTable(e,r){if(!this._isColumnSortable(e))return;const s=this.shadowRoot.querySelector("slot");if(!s)return;const a=s.assignedNodes({flatten:!0});let i=null;if(a.forEach(l=>{if(l.nodeType===Node.ELEMENT_NODE){const d=l.querySelector("tbody");d&&(i=d)}}),!i)return;let o;this._filteredRows?o=[...this._filteredRows]:o=this._getTopLevelRows(i),o.sort((l,d)=>{const b=this._getCellSortableValue(l.children[e]),c=this._getCellSortableValue(d.children[e]);return this._compareCellValues(b,c,r)});const t=this._tbodyObserver!==null;t&&this._disconnectTbodyObserver();try{o.forEach(l=>i.appendChild(l))}finally{t&&this._attachTbodyObserver()}this._filteredRows&&(this._filteredRows=o,this.totalRows=this._filteredRows.length),this.pagination&&this._paginateTable()}_getRowSearchText(e){return Array.from(e.cells).map(r=>this._getCellSortableValue(r)).join(" ")}_getCellSortableValue(e){if(!e)return"";const r=e,s=this._getSortableAttributeValue(r);if(s)return s;const a=[],i=r.textContent?.replace(/\s+/g," ").trim();return i&&a.push(i),r.querySelectorAll("[data-sort-value], [data-sort], [aria-label], [label], [value], [title]").forEach(o=>{const t=this._getSortableAttributeValue(o);t&&!a.includes(t)&&a.push(t)}),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,r,s){const a=this._parseSortableNumber(e),i=this._parseSortableNumber(r);if(a!==null&&i!==null)return s==="asc"?a-i:i-a;const o=Date.parse(e.replace(/\s+/g," ")),t=Date.parse(r.replace(/\s+/g," "));if(!isNaN(o)&&!isNaN(t))return s==="asc"?o-t:t-o;const l=e.localeCompare(r,"sv");return s==="asc"?l:-l}_parseSortableNumber(e){const r=e.trim();if(!/^[+-]?(?:\d+|\d{1,3}(?:[\s\u00a0\u202f]\d{3})+)(?:[,.]\d+)?$/.test(r))return null;const s=Number(r.replace(/[\s\u00a0\u202f]/g,"").replace(",","."));return Number.isNaN(s)?null:s}_updateTotalRows(){const e=this.shadowRoot.querySelector("slot");if(!e)return;const r=e.assignedNodes({flatten:!0});let s=null;r.forEach(a=>{if(a.nodeType===Node.ELEMENT_NODE){const i=a.querySelector("tbody");i&&(s=i)}}),s&&(this.totalRows=this._getTopLevelRows(s).length,this._ensureCurrentPageWithinBounds())}_paginateTable(){const e=this.shadowRoot.querySelector("slot");if(!e)return;const r=e.assignedNodes({flatten:!0});let s=null;if(r.forEach(t=>{if(t.nodeType===Node.ELEMENT_NODE){const l=t.querySelector("tbody");l&&(s=l)}}),!s)return;let a;this._filteredRows?a=this._filteredRows:a=this._getTopLevelRows(s),this._getTopLevelRows(s).forEach(t=>t.style.display="none");const i=(this.currentPage-1)*this.pageSize,o=i+this.pageSize;a.slice(i,o).forEach(t=>t.style.display="")}_changePage(e){const r=Math.ceil(this.totalRows/this.pageSize);e<1||e>r||(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=m`:host{display:block;color:var(--md-sys-color-on-surface);font-family:var(--scb-table-cell-font, var(--scb-typography-body-large-font, var(--md-sys-typescale-body-large-font, var(--brand-font, Inter, Arial, sans-serif))));--scb-background-row:var(--md-sys-color-surface);--scb-table-cell-font:var(--scb-tables-cell-font, var(--scb-typography-body-large-font, var(--md-sys-typescale-body-large-font, var(--brand-font, Inter, Arial, sans-serif))));--scb-table-cell-font-size:var(--scb-tables-cell-size, var(--scb-typography-body-large-size, var(--md-sys-typescale-body-large-size)));--scb-table-cell-line-height:var(--scb-tables-cell-line-height, var(--scb-typography-body-large-line-height, var(--md-sys-typescale-body-large-line-height)));--scb-table-cell-font-weight:var(--scb-tables-cell-weight, var(--scb-typography-body-large-weight, var(--md-sys-typescale-body-large-weight)));--scb-table-cell-letter-spacing:var(--scb-tables-cell-tracking, var(--scb-typography-body-large-tracking, var(--md-sys-typescale-body-large-tracking)));--scb-table-header-font:var(--scb-tables-header-font, var(--scb-typography-label-large-font, var(--md-sys-typescale-label-large-font, var(--brand-font, Inter, Arial, sans-serif))));--scb-table-header-font-size:var(--scb-tables-header-size, var(--scb-typography-label-large-size, var(--md-sys-typescale-label-large-size)));--scb-table-header-line-height:var(--scb-tables-header-line-height, var(--scb-typography-label-large-line-height, var(--md-sys-typescale-label-large-line-height)));--scb-table-header-font-weight:var(--scb-tables-header-weight, var(--scb-typography-label-large-weight, var(--md-sys-typescale-label-large-weight)));--scb-table-header-letter-spacing:var(--scb-tables-header-tracking, var(--scb-typography-label-large-tracking, var(--md-sys-typescale-label-large-tracking)));--scb-table-cell-padding-block:var(--scb-table-advanced-cell-padding-block, var(--scb-tables-cell-padding-block, var(--spacing-5, 16px)));--scb-table-cell-padding-inline:var(--scb-table-advanced-cell-padding-inline, var(--scb-tables-cell-padding-inline, var(--spacing-9, 32px)));--scb-table-cell-padding-inline-end:var(--spacing-0, 0px);--scb-table-cell-edge-padding-inline:var(--spacing-8, 24px)}scb-search{max-width:400px}.scb-table-scroll-wrapper{width:100%;overflow-x:auto;overflow-y:auto;max-width:100%;padding-bottom:var(--spacing-8, 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:var(--radius-extra-large, 24px);font-family:var(--scb-table-cell-font, var(--scb-typography-body-large-font, var(--md-sys-typescale-body-large-font, var(--brand-font, Inter, Arial, sans-serif))));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([g({type:String})],h.prototype,"searchTerm",void 0);u([g({type:Boolean,attribute:"with-pagination"})],h.prototype,"pagination",void 0);u([g({type:Boolean,attribute:"with-filtering-search"})],h.prototype,"filteringSearch",void 0);u([g({type:Boolean,attribute:"no-scroll"})],h.prototype,"noScroll",void 0);u([g({type:Number,attribute:"page-size"})],h.prototype,"pageSize",void 0);u([g({type:Array,attribute:"disable-sorting"})],h.prototype,"disableSorting",void 0);u([g({type:Number})],h.prototype,"currentPage",void 0);u([g({type:Number})],h.prototype,"totalRows",void 0);h=u([v("scb-table-advanced")],h);
|
|
25
|
+
`}_onSearchInput(e){const r=e.target.value;this.searchTerm=r,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 r=e.assignedNodes({flatten:!0});let s=null;if(r.forEach(t=>{if(t.nodeType===Node.ELEMENT_NODE){const l=t.querySelector("tbody");l&&(s=l)}}),!s)return;const a=s,i=this._getTopLevelRows(a),o=this.searchTerm.trim().toLowerCase();if(!o)this._filteredRows=null,i.forEach(t=>t.style.display=""),this._updateTotalRows(),this._ensureCurrentPageWithinBounds(),this.pagination&&this._paginateTable(),this._sortedColumn!==null&&this._sortTable(this._sortedColumn,this._sortDirection);else{this._filteredRows=i.filter(l=>this._getRowSearchText(l).toLowerCase().includes(o)),i.forEach(l=>l.style.display="none");let t=this._filteredRows;this._sortedColumn!==null&&(t=[...t],t.sort((l,d)=>{const b=this._getCellSortableValue(l.children[this._sortedColumn]),c=this._getCellSortableValue(d.children[this._sortedColumn]);return this._compareCellValues(b,c,this._sortDirection)}),this._filteredRows=t),this.totalRows=this._filteredRows.length,this._ensureCurrentPageWithinBounds(),this.pagination?this._paginateTable():this._filteredRows.forEach(l=>l.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("disableSorting")&&this._sortedColumn!==null&&!this._isColumnSortable(this._sortedColumn)&&(this._sortedColumn=null,this._sortDirection="asc"),(e.has("searchTerm")||e.has("currentPage")||e.has("pageSize")||e.has("filteringSearch")||e.has("pagination")||e.has("disableSorting"))&&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)),r=Math.min(Math.max(1,this.currentPage),e);r!==this.currentPage&&(this.currentPage=r)}_getTbody(){const e=this.shadowRoot.querySelector("slot");if(!e)return null;const r=e.assignedNodes({flatten:!0});for(const s of r)if(s.nodeType===Node.ELEMENT_NODE){const a=s.querySelector("tbody");if(a)return a}return null}_getTopLevelRows(e){return Array.from(e.children).filter(r=>r instanceof HTMLTableRowElement)}_attachThListeners(){const e=this.shadowRoot.querySelector("slot");if(!e)return;const r=e.assignedNodes({flatten:!0}),s=[],a=[],i=[],o=[];r.forEach(t=>{t.nodeType===Node.ELEMENT_NODE&&(Array.from(t.querySelectorAll("thead")).forEach(l=>{s.push(...Array.from(l.querySelectorAll("th")))}),a.push(...t.querySelectorAll("th")),i.push(...t.querySelectorAll("td")),o.push(...t.querySelectorAll("tr")))}),a.forEach(t=>{const l=s.indexOf(t),d=l!==-1;t.style.textAlign="left",t.style.padding="var(--scb-table-cell-padding-block) var(--scb-table-cell-padding-inline-end) var(--scb-table-cell-padding-block) var(--scb-table-cell-padding-inline)",t.style.position="relative",t.style.backgroundColor="var(--md-sys-color-surface)",t.style.fontFamily="var(--scb-table-header-font)",t.style.fontSize="var(--scb-table-header-font-size)",t.style.lineHeight="var(--scb-table-header-line-height)",t.style.fontWeight="var(--scb-table-header-font-weight)",t.style.letterSpacing="var(--scb-table-header-letter-spacing)",t.style.verticalAlign="middle",this._removeGeneratedSortMarkup(t),t.hasAttribute("scope")||(d?t.setAttribute("scope","col"):t.closest("tbody")&&t.setAttribute("scope","row"));const b=this._getOrCreateHeaderLabel(t,l);if((b instanceof HTMLParagraphElement||b.getAttribute("data-scb-generated-label")==="true")&&this._applyGeneratedCellTextReset(b),!d){t.removeAttribute("aria-sort");return}if(!this._isColumnSortable(l)){t.removeAttribute("aria-sort");return}t.setAttribute("aria-sort",this._getHeaderAriaSort(l));const c=this._getNormalizedText(b.textContent)||`kolumn ${Math.max(l,0)+1}`,n=document.createElement("scb-icon-button");n.className="scb-sort-icon",n.onclick=()=>this._onThClick(l),n.setAttribute("variant","standard"),n.setAttribute("size","small"),n.setAttribute("aria-label",this._getSortButtonLabel(c,l)),n.style.alignSelf="center",this._sortedColumn===l?(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)"),this._wrapHeaderWithSortControl(t,b,n)}),i.forEach(t=>{t.style.padding="var(--scb-table-cell-padding-block) var(--scb-table-cell-padding-inline-end) var(--scb-table-cell-padding-block) var(--scb-table-cell-padding-inline)",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(--scb-table-cell-font)",t.style.fontSize="var(--scb-table-cell-font-size)",t.style.lineHeight="var(--scb-table-cell-line-height)",t.style.fontWeight="var(--scb-table-cell-font-weight)",t.style.letterSpacing="var(--scb-table-cell-letter-spacing)"}),o.forEach((t,l)=>{l%2===1&&t.querySelectorAll("td").forEach(c=>{c.style.backgroundColor="var(--scb-background-row)"});const d=t.querySelectorAll("th");d.length>0&&d.forEach((c,n)=>{n===0&&(c.style.paddingLeft="var(--scb-table-cell-edge-padding-inline)"),n===d.length-1?c.style.paddingRight="var(--scb-table-cell-edge-padding-inline)":c.style.paddingRight=""});const b=t.querySelectorAll("td");b.length>0&&b.forEach((c,n)=>{n===0&&(c.style.paddingLeft="var(--scb-table-cell-edge-padding-inline)"),n===b.length-1?c.style.paddingRight="var(--scb-table-cell-edge-padding-inline)":c.style.paddingRight=""})}),this.pagination&&this._paginateTable()}_applyGeneratedCellTextReset(e){e.style.margin="0",e.style.color="inherit",e.style.fontFamily="inherit",e.style.fontSize="inherit",e.style.lineHeight="inherit",e.style.fontWeight="inherit",e.style.letterSpacing="inherit"}_removeGeneratedSortMarkup(e){e.querySelectorAll("scb-icon-button.scb-sort-icon").forEach(a=>a.remove());const r=e.querySelector(':scope > [data-scb-sort-header="true"]');if(!(r instanceof HTMLElement))return;const s=r.querySelector(':scope > [data-scb-sort-label="true"]');if(s instanceof HTMLElement){r.replaceWith(s);return}r.remove()}_getOrCreateHeaderLabel(e,r){const s=e.querySelector(':scope > [data-scb-sort-label="true"]');if(s instanceof HTMLElement)return s;const a=e.querySelector(":scope > p");if(a instanceof HTMLParagraphElement)return a.setAttribute("data-scb-sort-label","true"),a;const i=Array.from(e.children).find(t=>t instanceof HTMLElement&&!t.matches("scb-icon-button.scb-sort-icon"));if(i)return i.setAttribute("data-scb-sort-label","true"),i;const o=document.createElement("p");return o.setAttribute("data-scb-sort-label","true"),o.setAttribute("data-scb-generated-label","true"),o.textContent=this._getNormalizedText(e.textContent)||`kolumn ${Math.max(r,0)+1}`,e.textContent="",e.appendChild(o),o}_wrapHeaderWithSortControl(e,r,s){const a=document.createElement("div");a.setAttribute("data-scb-sort-header","true"),a.style.display="flex",a.style.gap="8px",a.style.flexWrap="nowrap",a.style.alignItems="center",a.appendChild(r),a.appendChild(s),e.appendChild(a)}_getNormalizedText(e){return(e??"").replace(/\s+/g," ").trim()}_onThClick(e){this._isColumnSortable(e)&&(this._sortedColumn===e?this._sortDirection=this._sortDirection==="asc"?"desc":"asc":(this._sortedColumn=e,this._sortDirection="asc"),this._sortTable(e,this._sortDirection),this._attachThListeners())}_getHeaderAriaSort(e){return this._sortedColumn!==e?"none":this._sortDirection==="asc"?"ascending":"descending"}_getSortButtonLabel(e,r){return`Sortera ${e||`kolumn ${r+1}`} ${this._sortedColumn===r&&this._sortDirection==="asc"?"fallande":"stigande"}`}_isColumnSortable(e){return!(Array.isArray(this.disableSorting)?this.disableSorting:[]).some(r=>Number(r)===e)}_sortTable(e,r){if(!this._isColumnSortable(e))return;const s=this.shadowRoot.querySelector("slot");if(!s)return;const a=s.assignedNodes({flatten:!0});let i=null;if(a.forEach(l=>{if(l.nodeType===Node.ELEMENT_NODE){const d=l.querySelector("tbody");d&&(i=d)}}),!i)return;let o;this._filteredRows?o=[...this._filteredRows]:o=this._getTopLevelRows(i),o.sort((l,d)=>{const b=this._getCellSortableValue(l.children[e]),c=this._getCellSortableValue(d.children[e]);return this._compareCellValues(b,c,r)});const t=this._tbodyObserver!==null;t&&this._disconnectTbodyObserver();try{o.forEach(l=>i.appendChild(l))}finally{t&&this._attachTbodyObserver()}this._filteredRows&&(this._filteredRows=o,this.totalRows=this._filteredRows.length),this.pagination&&this._paginateTable()}_getRowSearchText(e){return Array.from(e.cells).map(r=>this._getCellSortableValue(r)).join(" ")}_getCellSortableValue(e){if(!e)return"";const r=e,s=this._getSortableAttributeValue(r);if(s)return s;const a=[],i=r.textContent?.replace(/\s+/g," ").trim();return i&&a.push(i),r.querySelectorAll("[data-sort-value], [data-sort], [aria-label], [label], [value], [title]").forEach(o=>{const t=this._getSortableAttributeValue(o);t&&!a.includes(t)&&a.push(t)}),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,r,s){const a=this._parseSortableNumber(e),i=this._parseSortableNumber(r);if(a!==null&&i!==null)return s==="asc"?a-i:i-a;const o=Date.parse(e.replace(/\s+/g," ")),t=Date.parse(r.replace(/\s+/g," "));if(!isNaN(o)&&!isNaN(t))return s==="asc"?o-t:t-o;const l=e.localeCompare(r,"sv");return s==="asc"?l:-l}_parseSortableNumber(e){const r=e.trim();if(!/^[+-]?(?:\d+|\d{1,3}(?:[\s\u00a0\u202f]\d{3})+)(?:[,.]\d+)?$/.test(r))return null;const s=Number(r.replace(/[\s\u00a0\u202f]/g,"").replace(",","."));return Number.isNaN(s)?null:s}_updateTotalRows(){const e=this.shadowRoot.querySelector("slot");if(!e)return;const r=e.assignedNodes({flatten:!0});let s=null;r.forEach(a=>{if(a.nodeType===Node.ELEMENT_NODE){const i=a.querySelector("tbody");i&&(s=i)}}),s&&(this.totalRows=this._getTopLevelRows(s).length,this._ensureCurrentPageWithinBounds())}_paginateTable(){const e=this.shadowRoot.querySelector("slot");if(!e)return;const r=e.assignedNodes({flatten:!0});let s=null;if(r.forEach(t=>{if(t.nodeType===Node.ELEMENT_NODE){const l=t.querySelector("tbody");l&&(s=l)}}),!s)return;let a;this._filteredRows?a=this._filteredRows:a=this._getTopLevelRows(s),this._getTopLevelRows(s).forEach(t=>t.style.display="none");const i=(this.currentPage-1)*this.pageSize,o=i+this.pageSize;a.slice(i,o).forEach(t=>t.style.display="")}_changePage(e){const r=Math.ceil(this.totalRows/this.pageSize);e<1||e>r||(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=m`:host{display:block;color:var(--md-sys-color-on-surface);font-family:var(--scb-table-cell-font, var(--scb-typography-body-large-font, var(--md-sys-typescale-body-large-font, var(--brand-font, Inter, Arial, sans-serif))));--scb-background-row:var(--md-sys-color-surface);--scb-table-cell-font:var(--scb-tables-cell-font, var(--scb-typography-body-large-font, var(--md-sys-typescale-body-large-font, var(--brand-font, Inter, Arial, sans-serif))));--scb-table-cell-font-size:var(--scb-tables-cell-size, var(--scb-typography-body-large-size, var(--md-sys-typescale-body-large-size)));--scb-table-cell-line-height:var(--scb-tables-cell-line-height, var(--scb-typography-body-large-line-height, var(--md-sys-typescale-body-large-line-height)));--scb-table-cell-font-weight:var(--scb-tables-cell-weight, var(--scb-typography-body-large-weight, var(--md-sys-typescale-body-large-weight)));--scb-table-cell-letter-spacing:var(--scb-tables-cell-tracking, var(--scb-typography-body-large-tracking, var(--md-sys-typescale-body-large-tracking)));--scb-table-header-font:var(--scb-tables-header-font, var(--scb-typography-label-large-font, var(--md-sys-typescale-label-large-font, var(--brand-font, Inter, Arial, sans-serif))));--scb-table-header-font-size:var(--scb-tables-header-size, var(--scb-typography-label-large-size, var(--md-sys-typescale-label-large-size)));--scb-table-header-line-height:var(--scb-tables-header-line-height, var(--scb-typography-label-large-line-height, var(--md-sys-typescale-label-large-line-height)));--scb-table-header-font-weight:var(--scb-tables-header-weight, var(--scb-typography-label-large-weight, var(--md-sys-typescale-label-large-weight)));--scb-table-header-letter-spacing:var(--scb-tables-header-tracking, var(--scb-typography-label-large-tracking, var(--md-sys-typescale-label-large-tracking)));--scb-table-cell-padding-block:var(--scb-table-advanced-cell-padding-block, var(--scb-tables-cell-padding-block, var(--spacing-5, 16px)));--scb-table-cell-padding-inline:var(--scb-table-advanced-cell-padding-inline, var(--scb-tables-cell-padding-inline, var(--spacing-9, 32px)));--scb-table-cell-padding-inline-end:var(--spacing-0, 0px);--scb-table-cell-edge-padding-inline:var(--spacing-8, 24px)}scb-search{max-width:400px}.scb-table-scroll-wrapper{width:100%;overflow-x:auto;overflow-y:auto;max-width:100%;padding-bottom:var(--spacing-8, 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:var(--radius-extra-large, 24px);font-family:var(--scb-table-cell-font, var(--scb-typography-body-large-font, var(--md-sys-typescale-body-large-font, var(--brand-font, Inter, Arial, sans-serif))));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([g({type:String})],h.prototype,"searchTerm",void 0);u([g({type:Boolean,attribute:"with-pagination"})],h.prototype,"pagination",void 0);u([g({type:Boolean,attribute:"with-filtering-search"})],h.prototype,"filteringSearch",void 0);u([g({type:Boolean,attribute:"no-scroll"})],h.prototype,"noScroll",void 0);u([g({type:Number,attribute:"page-size"})],h.prototype,"pageSize",void 0);u([g({type:Array,attribute:"disable-sorting"})],h.prototype,"disableSorting",void 0);u([g({type:Number})],h.prototype,"currentPage",void 0);u([g({type:Number})],h.prototype,"totalRows",void 0);h=u([v("scb-table-advanced")],h);
|