scb-wc 0.1.160 → 0.1.162
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 as v,p as g,v as p,y as m}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(r,s,a){try{customElements.get(r)||e(r,s,a)}catch(o){var i=String(o||"");if(i.indexOf("already been used")===-1&&i.indexOf("NotSupportedError")===-1)throw o}}}}catch{}})();var y,h=(y=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=r=>{const s=r.detail;s&&typeof s.page=="number"&&this._changePage(s.page)}}disconnectedCallback(){super.disconnectedCallback(),this._disconnectTbodyObserver()}attributeChangedCallback(e,r,s){if(super.attributeChangedCallback(e,r,s),r!==s){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`
|
|
1
|
+
import{h as _,m as v,p as g,v as p,y as m}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(r,s,a){try{customElements.get(r)||e(r,s,a)}catch(o){var i=String(o||"");if(i.indexOf("already been used")===-1&&i.indexOf("NotSupportedError")===-1)throw o}}}}catch{}})();var y,h=(y=class extends _{constructor(...e){super(...e),this.searchTerm="",this.pagination=!1,this.filteringSearch=!1,this.noScroll=!1,this.pageSize=10,this.disableSorting=[],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=r=>{const s=r.detail;s&&typeof s.page=="number"&&this._changePage(s.page)}}disconnectedCallback(){super.disconnectedCallback(),this._disconnectTbodyObserver()}attributeChangedCallback(e,r,s){if(super.attributeChangedCallback(e,r,s),r!==s){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 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("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)),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}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._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"}`}_sortTable(e,r){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: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="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);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "scb-wc",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.162",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"module": "index.js",
|
|
@@ -474,5 +474,5 @@
|
|
|
474
474
|
},
|
|
475
475
|
"./mvc/*": "./mvc/*"
|
|
476
476
|
},
|
|
477
|
-
"buildHash": "
|
|
477
|
+
"buildHash": "36EBA1AA25D45BEB9B1D7188412D2F4E4315048F80C7D794AD94BC241E641C42"
|
|
478
478
|
}
|
|
@@ -5,6 +5,7 @@ export declare class ScbTableAdvanced extends LitElement {
|
|
|
5
5
|
filteringSearch: boolean;
|
|
6
6
|
noScroll: boolean;
|
|
7
7
|
pageSize: number;
|
|
8
|
+
disableSorting: number[];
|
|
8
9
|
currentPage: number;
|
|
9
10
|
totalRows: number;
|
|
10
11
|
private _sortedColumn;
|
|
@@ -38,6 +39,7 @@ export declare class ScbTableAdvanced extends LitElement {
|
|
|
38
39
|
private _onThClick;
|
|
39
40
|
private _getHeaderAriaSort;
|
|
40
41
|
private _getSortButtonLabel;
|
|
42
|
+
private _isColumnSortable;
|
|
41
43
|
private _sortTable;
|
|
42
44
|
private _getRowSearchText;
|
|
43
45
|
private _getCellSortableValue;
|
|
@@ -7,7 +7,7 @@ import { customElement as i, property as a } from "lit/decorators.js";
|
|
|
7
7
|
//#region src/scb-components/scb-table-advanced/scb-table-advanced.ts
|
|
8
8
|
var o = class extends t {
|
|
9
9
|
constructor(...e) {
|
|
10
|
-
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 = () => {
|
|
10
|
+
super(...e), this.searchTerm = "", this.pagination = !1, this.filteringSearch = !1, this.noScroll = !1, this.pageSize = 10, this.disableSorting = [], 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 = () => {
|
|
11
11
|
this._attachTbodyObserver(), this._refreshFromTableContent();
|
|
12
12
|
}, this._onPaginationChange = (e) => {
|
|
13
13
|
let t = e.detail;
|
|
@@ -168,7 +168,7 @@ var o = class extends t {
|
|
|
168
168
|
e && (e.addEventListener("slotchange", () => this._attachThListeners()), this._attachThListeners(), this._attachTbodyObserver(), this._refreshFromTableContent());
|
|
169
169
|
}
|
|
170
170
|
updated(e) {
|
|
171
|
-
super.updated(e), (e.has("searchTerm") || e.has("currentPage") || e.has("pageSize") || e.has("filteringSearch") || e.has("pagination")) && this.updateComplete.then(() => {
|
|
171
|
+
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(() => {
|
|
172
172
|
this.isConnected && this._refreshFromTableContent();
|
|
173
173
|
});
|
|
174
174
|
}
|
|
@@ -238,6 +238,10 @@ var o = class extends t {
|
|
|
238
238
|
e.removeAttribute("aria-sort");
|
|
239
239
|
return;
|
|
240
240
|
}
|
|
241
|
+
if (!this._isColumnSortable(t)) {
|
|
242
|
+
e.removeAttribute("aria-sort");
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
241
245
|
e.setAttribute("aria-sort", this._getHeaderAriaSort(t));
|
|
242
246
|
let a = this._getNormalizedText(i.textContent) || `kolumn ${Math.max(t, 0) + 1}`, o = document.createElement("scb-icon-button");
|
|
243
247
|
o.className = "scb-sort-icon", o.onclick = () => this._onThClick(t), o.setAttribute("variant", "standard"), o.setAttribute("size", "small"), o.setAttribute("aria-label", this._getSortButtonLabel(a, t)), this._sortedColumn === t ? (o.setAttribute("variant", "filled-tonal"), o.setAttribute("icon", this._sortDirection === "asc" ? "arrow_downward" : "arrow_upward")) : (o.setAttribute("icon", "swap_horiz"), o.style.transform += " rotate(90deg)", o.style.alignSelf = "end"), this._wrapHeaderWithSortControl(e, i, o);
|
|
@@ -289,7 +293,7 @@ var o = class extends t {
|
|
|
289
293
|
return (e ?? "").replace(/\s+/g, " ").trim();
|
|
290
294
|
}
|
|
291
295
|
_onThClick(e) {
|
|
292
|
-
this._sortedColumn === e ? this._sortDirection = this._sortDirection === "asc" ? "desc" : "asc" : (this._sortedColumn = e, this._sortDirection = "asc"), this._sortTable(e, this._sortDirection), this._attachThListeners();
|
|
296
|
+
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());
|
|
293
297
|
}
|
|
294
298
|
_getHeaderAriaSort(e) {
|
|
295
299
|
return this._sortedColumn === e ? this._sortDirection === "asc" ? "ascending" : "descending" : "none";
|
|
@@ -297,7 +301,11 @@ var o = class extends t {
|
|
|
297
301
|
_getSortButtonLabel(e, t) {
|
|
298
302
|
return `Sortera ${e || `kolumn ${t + 1}`} ${this._sortedColumn === t && this._sortDirection === "asc" ? "fallande" : "stigande"}`;
|
|
299
303
|
}
|
|
304
|
+
_isColumnSortable(e) {
|
|
305
|
+
return !(Array.isArray(this.disableSorting) ? this.disableSorting : []).some((t) => Number(t) === e);
|
|
306
|
+
}
|
|
300
307
|
_sortTable(e, t) {
|
|
308
|
+
if (!this._isColumnSortable(e)) return;
|
|
301
309
|
let n = this.shadowRoot.querySelector("slot");
|
|
302
310
|
if (!n) return;
|
|
303
311
|
let r = n.assignedNodes({ flatten: !0 }), i = null;
|
|
@@ -401,6 +409,9 @@ e([a({ type: String })], o.prototype, "searchTerm", void 0), e([a({
|
|
|
401
409
|
})], o.prototype, "noScroll", void 0), e([a({
|
|
402
410
|
type: Number,
|
|
403
411
|
attribute: "page-size"
|
|
404
|
-
})], o.prototype, "pageSize", void 0), e([a({
|
|
412
|
+
})], o.prototype, "pageSize", void 0), e([a({
|
|
413
|
+
type: Array,
|
|
414
|
+
attribute: "disable-sorting"
|
|
415
|
+
})], o.prototype, "disableSorting", void 0), e([a({ type: Number })], o.prototype, "currentPage", void 0), e([a({ type: Number })], o.prototype, "totalRows", void 0), o = e([i("scb-table-advanced")], o);
|
|
405
416
|
//#endregion
|
|
406
417
|
export { o as ScbTableAdvanced };
|
package/scb-wc.bundle.js
CHANGED
|
@@ -16511,7 +16511,7 @@
|
|
|
16511
16511
|
<div class="scb-table-scroll-wrapper">
|
|
16512
16512
|
<slot @slotchange=${this._onSlotChange}></slot>
|
|
16513
16513
|
</div>
|
|
16514
|
-
`}firstUpdated(){let e=this.shadowRoot?.querySelector(`slot`);e&&(e.addEventListener(`slotchange`,()=>this._attachThListeners()),this._attachThListeners())}updated(e){e.has(`dataSorting`)&&(this.dataSorting||(this._sortedColumn=null,this._sortDirection=`asc`),this._attachThListeners()),e.has(`columnWidthMode`)&&this._queueColumnWidthUpdate()}disconnectedCallback(){super.disconnectedCallback(),this._columnWidthFrame!==null&&(cancelAnimationFrame(this._columnWidthFrame),this._columnWidthFrame=null)}_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,n=t.tagName.toLowerCase()===`tbody`?t:t.querySelector(`tbody`);if(n)return n}return null}_getTables(){let e=this.shadowRoot?.querySelector(`slot`);if(!e)return[];let t=e.assignedNodes({flatten:!0}),n=[];return t.forEach(e=>{if(e.nodeType===Node.ELEMENT_NODE){let t=e;t.tagName.toLowerCase()===`table`&&n.push(t),n.push(...Array.from(t.querySelectorAll(`table`)))}}),n}_attachThListeners(){let e=this.shadowRoot?.querySelector(`slot`);if(!e)return;let t=e.assignedNodes({flatten:!0}),n=[],r=[],i=[],a=[],o=[];t.forEach(e=>{if(e.nodeType===Node.ELEMENT_NODE){let t=Array.from(e.querySelectorAll(`thead`));n.push(...t),t.forEach(e=>{r.push(...Array.from(e.querySelectorAll(`th`)))}),i.push(...e.querySelectorAll(`th`)),a.push(...e.querySelectorAll(`td`)),o.push(...e.querySelectorAll(`tr`))}}),n.forEach(e=>{e.style.borderTop=`1px solid var(--md-sys-color-on-surface)`}),i.forEach(e=>{let t=r.indexOf(e),n=t!==-1;e.style.textAlign=`left`,e.style.padding=`var(--scb-table-cell-padding-block) var(--scb-table-cell-padding-inline)`,e.style.position=`relative`,e.style.backgroundColor=`var(--md-sys-color-surface)`,e.style.fontFamily=`var(--scb-table-header-font)`,e.style.fontSize=`var(--scb-table-header-font-size)`,e.style.lineHeight=`var(--scb-table-header-line-height)`,e.style.fontWeight=`var(--scb-table-header-font-weight)`,e.style.letterSpacing=`var(--scb-table-header-letter-spacing)`,e.style.verticalAlign=`bottom`,e.style.borderRight=`1px solid var(--md-sys-color-on-surface)`,e.style.borderBottom=`1px solid var(--md-sys-color-on-surface)`,e.style.overflowWrap=`normal`,e.style.wordBreak=`normal`,e.style.hyphens=`manual`,this._removeGeneratedSortMarkup(e),e.hasAttribute(`scope`)||(n?e.setAttribute(`scope`,`col`):e.closest(`tbody`)&&e.setAttribute(`scope`,`row`));let i=this._getOrCreateHeaderLabel(e,t),a=this._getHeaderLabelText(e,i,t);if((i instanceof HTMLParagraphElement||i.getAttribute(`data-scb-generated-label`)===`true`)&&this._applyGeneratedCellTextReset(i),this.dataSorting&&n){e.setAttribute(`aria-sort`,this._getHeaderAriaSort(t));let n=document.createElement(`scb-icon-button`);n.className=`scb-sort-icon`,n.onclick=()=>this._onThClick(t),n.setAttribute(`variant`,`standard`),n.setAttribute(`size`,`small`),n.setAttribute(`aria-label`,this._getSortButtonLabel(a,t)),n.style.alignSelf=`end`,this._sortedColumn===t?(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(e,i,n)}else e.removeAttribute(`aria-sort`)}),a.forEach(e=>{e.style.padding=`var(--scb-table-cell-padding-block) var(--scb-table-cell-padding-inline)`,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(--scb-table-cell-font)`,e.style.fontSize=`var(--scb-table-cell-font-size)`,e.style.lineHeight=`var(--scb-table-cell-line-height)`,e.style.fontWeight=`var(--scb-table-cell-font-weight)`,e.style.letterSpacing=`var(--scb-table-cell-letter-spacing)`,e.style.borderRight=`1px solid var(--md-sys-color-on-surface)`,e.style.borderBottom=`1px solid var(--md-sys-color-on-surface)`,e.style.overflowWrap=`normal`,e.style.wordBreak=`normal`,e.style.hyphens=`manual`}),o.forEach(e=>{let t=Array.from(e.cells);t.forEach((e,n)=>{e.style.borderRight=n===t.length-1?`none`:`1px solid var(--md-sys-color-on-surface)`})});let s=this._getTbody();s&&Array.from(s.querySelectorAll(`tr`)).forEach((e,t)=>{let n=t%2==0?`var(--md-sys-color-surface-container)`:`var(--md-sys-color-surface)`;Array.from(e.cells).forEach(e=>{e.style.backgroundColor=n})}),this._queueColumnWidthUpdate()}_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(e=>e.remove());let t=e.querySelector(`:scope > [data-scb-sort-header="true"]`);if(!(t instanceof HTMLElement))return;let n=t.querySelector(`:scope > [data-scb-sort-label="true"]`);if(n instanceof HTMLElement){t.replaceWith(n);return}t.remove()}_getOrCreateHeaderLabel(e,t){let n=e.querySelector(`:scope > [data-scb-sort-label="true"]`);if(n instanceof HTMLElement)return n;let r=e.querySelector(`:scope > p`);if(r instanceof HTMLParagraphElement)return r.setAttribute(`data-scb-sort-label`,`true`),r;let i=Array.from(e.children).find(e=>e instanceof HTMLElement&&!e.matches(`scb-icon-button.scb-sort-icon`));if(i)return i.setAttribute(`data-scb-sort-label`,`true`),i;let a=this._getNormalizedText(e.textContent),o=a||this._getNormalizedText(e.getAttribute(`aria-label`))||this._getFallbackColumnLabel(t),s=document.createElement(`p`);return s.setAttribute(`data-scb-sort-label`,`true`),s.setAttribute(`data-scb-generated-label`,`true`),s.textContent=o,a||(s.setAttribute(`data-scb-visually-hidden-label`,`true`),this._applyVisuallyHiddenStyles(s)),e.textContent=``,e.appendChild(s),s}_getHeaderLabelText(e,t,n){return this._getNormalizedText(t.textContent)||this._getNormalizedText(e.getAttribute(`aria-label`))||this._getFallbackColumnLabel(n)}_getFallbackColumnLabel(e){return`kolumn ${Math.max(e,0)+1}`}_applyVisuallyHiddenStyles(e){e.style.position=`absolute`,e.style.width=`1px`,e.style.height=`1px`,e.style.padding=`0`,e.style.margin=`-1px`,e.style.overflow=`hidden`,e.style.whiteSpace=`nowrap`,e.style.clip=`rect(0, 0, 0, 0)`,e.style.clipPath=`inset(50%)`,e.style.border=`0`}_wrapHeaderWithSortControl(e,t,n){let r=document.createElement(`div`);r.setAttribute(`data-scb-sort-header`,`true`),r.style.display=`flex`,r.style.gap=`8px`,r.style.flexWrap=`nowrap`,r.style.alignItems=`center`,r.appendChild(t),r.appendChild(n),e.appendChild(r)}_getNormalizedText(e){return(e??``).replace(/\s+/g,` `).trim()}_queueColumnWidthUpdate(){this._columnWidthFrame!==null&&cancelAnimationFrame(this._columnWidthFrame),this._columnWidthFrame=requestAnimationFrame(()=>{this._columnWidthFrame=null,this._applyColumnWidthMode()})}_applyColumnWidthMode(){this._getTables().forEach(e=>{if(this._removeGeneratedColGroup(e),e.style.tableLayout=``,e.style.width=``,e.style.minWidth=``,e.style.maxWidth=``,this.columnWidthMode!==`header`)return;let t=Array.from(e.querySelectorAll(`thead tr`)),n=t[t.length-1];if(!n)return;let r=Array.from(n.cells).map((t,n)=>{let r=this._measureCellContentWidth(t),i=this._measureColumnReadableBodyWidth(e,n),a=Math.max(r,i);return`${Math.ceil(a>0?Math.max(a,zf):0)}px`}),i=r.reduce((e,t)=>e+parseFloat(t),0);this._applyGeneratedColGroup(e,r),e.style.tableLayout=`fixed`,e.style.width=`${Math.ceil(i)}px`,e.style.minWidth=`${Math.ceil(i)}px`,e.style.maxWidth=`none`})}_applyGeneratedColGroup(e,t){let n=document.createElement(`colgroup`);n.setAttribute(`data-scb-generated-column-widths`,`true`),t.forEach(e=>{let t=document.createElement(`col`);t.style.width=e,t.style.minWidth=e,n.appendChild(t)}),e.insertBefore(n,e.firstChild)}_removeGeneratedColGroup(e){e.querySelector(`colgroup[data-scb-generated-column-widths="true"]`)?.remove()}_measureCellContentWidth(e){let t=e.firstElementChild?.cloneNode(!0)??document.createElement(`span`);e.firstElementChild||(t.textContent=e.textContent??``);let n=window.getComputedStyle(e),r=document.createElement(`div`);r.style.position=`absolute`,r.style.left=`-99999px`,r.style.top=`0`,r.style.visibility=`hidden`,r.style.pointerEvents=`none`,r.style.width=`max-content`,r.style.maxWidth=`none`,r.style.whiteSpace=`nowrap`,r.style.fontFamily=n.fontFamily,r.style.fontSize=n.fontSize,r.style.fontWeight=n.fontWeight,r.style.lineHeight=n.lineHeight,r.style.letterSpacing=n.letterSpacing,t instanceof HTMLElement&&(t.style.width=`max-content`,t.style.maxWidth=`none`,t.style.whiteSpace=`nowrap`),r.appendChild(t),document.body.appendChild(r);let i=parseFloat(n.paddingLeft||`0`),a=parseFloat(n.paddingRight||`0`),o=parseFloat(n.borderLeftWidth||`0`),s=parseFloat(n.borderRightWidth||`0`),c=r.getBoundingClientRect().width+i+a+o+s;return document.body.removeChild(r),c}_measureColumnReadableBodyWidth(e,t){return Array.from(e.querySelectorAll(`tbody tr`)).reduce((e,n)=>{let r=n.cells[t];if(!r)return e;let i=(r.textContent??``).replace(/\s+/g,` `).trim().split(` `).filter(Boolean).reduce((e,t)=>Math.max(e,this._measureCellTextWidth(r,t)),0),a=i>0?i+Bf:0;return Math.max(e,a)},0)}_measureCellTextWidth(e,t){let n=window.getComputedStyle(e),r=document.createElement(`span`);r.textContent=t,r.style.position=`absolute`,r.style.left=`-99999px`,r.style.top=`0`,r.style.visibility=`hidden`,r.style.pointerEvents=`none`,r.style.whiteSpace=`nowrap`,r.style.fontFamily=n.fontFamily,r.style.fontSize=n.fontSize,r.style.fontWeight=n.fontWeight,r.style.lineHeight=n.lineHeight,r.style.letterSpacing=n.letterSpacing,document.body.appendChild(r);let i=parseFloat(n.paddingLeft||`0`),a=parseFloat(n.paddingRight||`0`),o=parseFloat(n.borderLeftWidth||`0`),s=parseFloat(n.borderRightWidth||`0`),c=r.getBoundingClientRect().width+i+a+o+s;return document.body.removeChild(r),c}_onThClick(e){this.dataSorting&&(this._sortedColumn===e?this._sortDirection=this._sortDirection===`asc`?`desc`:`asc`:(this._sortedColumn=e,this._sortDirection=`asc`),this._sortTable(e,this._sortDirection),this._attachThListeners(),this.dispatchEvent(new CustomEvent(`tablesortchange`,{detail:{sortedColumn:this._sortedColumn,sortDirection:this._sortDirection},bubbles:!0,composed:!0})))}_getHeaderAriaSort(e){return this._sortedColumn===e?this._sortDirection===`asc`?`ascending`:`descending`:`none`}_getSortButtonLabel(e,t){return`Sortera ${e||`kolumn ${t+1}`} ${this._sortedColumn===t&&this._sortDirection===`asc`?`fallande`:`stigande`}`}_sortTable(e,t){let n=this._getTbody();if(!n)return;let r=Array.from(n.querySelectorAll(`tr`));r.sort((n,r)=>{let i=this._getCellSortableValue(n.children[e]),a=this._getCellSortableValue(r.children[e]);return this._compareCellValues(i,a,t)}),r.forEach(e=>n.appendChild(e))}_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}};P([_({type:Boolean,attribute:`data-sorting`})],Vf.prototype,`dataSorting`,void 0),P([_({type:String,attribute:`column-width-mode`})],Vf.prototype,`columnWidthMode`,void 0),Vf=P([a(`scb-table`)],Vf),w(),b(),rl(),du(),F();var Hf=class extends C{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=e=>{let t=e.detail;t&&typeof t.page==`number`&&this._changePage(t.page)}}static{this.styles=p`
|
|
16514
|
+
`}firstUpdated(){let e=this.shadowRoot?.querySelector(`slot`);e&&(e.addEventListener(`slotchange`,()=>this._attachThListeners()),this._attachThListeners())}updated(e){e.has(`dataSorting`)&&(this.dataSorting||(this._sortedColumn=null,this._sortDirection=`asc`),this._attachThListeners()),e.has(`columnWidthMode`)&&this._queueColumnWidthUpdate()}disconnectedCallback(){super.disconnectedCallback(),this._columnWidthFrame!==null&&(cancelAnimationFrame(this._columnWidthFrame),this._columnWidthFrame=null)}_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,n=t.tagName.toLowerCase()===`tbody`?t:t.querySelector(`tbody`);if(n)return n}return null}_getTables(){let e=this.shadowRoot?.querySelector(`slot`);if(!e)return[];let t=e.assignedNodes({flatten:!0}),n=[];return t.forEach(e=>{if(e.nodeType===Node.ELEMENT_NODE){let t=e;t.tagName.toLowerCase()===`table`&&n.push(t),n.push(...Array.from(t.querySelectorAll(`table`)))}}),n}_attachThListeners(){let e=this.shadowRoot?.querySelector(`slot`);if(!e)return;let t=e.assignedNodes({flatten:!0}),n=[],r=[],i=[],a=[],o=[];t.forEach(e=>{if(e.nodeType===Node.ELEMENT_NODE){let t=Array.from(e.querySelectorAll(`thead`));n.push(...t),t.forEach(e=>{r.push(...Array.from(e.querySelectorAll(`th`)))}),i.push(...e.querySelectorAll(`th`)),a.push(...e.querySelectorAll(`td`)),o.push(...e.querySelectorAll(`tr`))}}),n.forEach(e=>{e.style.borderTop=`1px solid var(--md-sys-color-on-surface)`}),i.forEach(e=>{let t=r.indexOf(e),n=t!==-1;e.style.textAlign=`left`,e.style.padding=`var(--scb-table-cell-padding-block) var(--scb-table-cell-padding-inline)`,e.style.position=`relative`,e.style.backgroundColor=`var(--md-sys-color-surface)`,e.style.fontFamily=`var(--scb-table-header-font)`,e.style.fontSize=`var(--scb-table-header-font-size)`,e.style.lineHeight=`var(--scb-table-header-line-height)`,e.style.fontWeight=`var(--scb-table-header-font-weight)`,e.style.letterSpacing=`var(--scb-table-header-letter-spacing)`,e.style.verticalAlign=`bottom`,e.style.borderRight=`1px solid var(--md-sys-color-on-surface)`,e.style.borderBottom=`1px solid var(--md-sys-color-on-surface)`,e.style.overflowWrap=`normal`,e.style.wordBreak=`normal`,e.style.hyphens=`manual`,this._removeGeneratedSortMarkup(e),e.hasAttribute(`scope`)||(n?e.setAttribute(`scope`,`col`):e.closest(`tbody`)&&e.setAttribute(`scope`,`row`));let i=this._getOrCreateHeaderLabel(e,t),a=this._getHeaderLabelText(e,i,t);if((i instanceof HTMLParagraphElement||i.getAttribute(`data-scb-generated-label`)===`true`)&&this._applyGeneratedCellTextReset(i),this.dataSorting&&n){e.setAttribute(`aria-sort`,this._getHeaderAriaSort(t));let n=document.createElement(`scb-icon-button`);n.className=`scb-sort-icon`,n.onclick=()=>this._onThClick(t),n.setAttribute(`variant`,`standard`),n.setAttribute(`size`,`small`),n.setAttribute(`aria-label`,this._getSortButtonLabel(a,t)),n.style.alignSelf=`end`,this._sortedColumn===t?(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(e,i,n)}else e.removeAttribute(`aria-sort`)}),a.forEach(e=>{e.style.padding=`var(--scb-table-cell-padding-block) var(--scb-table-cell-padding-inline)`,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(--scb-table-cell-font)`,e.style.fontSize=`var(--scb-table-cell-font-size)`,e.style.lineHeight=`var(--scb-table-cell-line-height)`,e.style.fontWeight=`var(--scb-table-cell-font-weight)`,e.style.letterSpacing=`var(--scb-table-cell-letter-spacing)`,e.style.borderRight=`1px solid var(--md-sys-color-on-surface)`,e.style.borderBottom=`1px solid var(--md-sys-color-on-surface)`,e.style.overflowWrap=`normal`,e.style.wordBreak=`normal`,e.style.hyphens=`manual`}),o.forEach(e=>{let t=Array.from(e.cells);t.forEach((e,n)=>{e.style.borderRight=n===t.length-1?`none`:`1px solid var(--md-sys-color-on-surface)`})});let s=this._getTbody();s&&Array.from(s.querySelectorAll(`tr`)).forEach((e,t)=>{let n=t%2==0?`var(--md-sys-color-surface-container)`:`var(--md-sys-color-surface)`;Array.from(e.cells).forEach(e=>{e.style.backgroundColor=n})}),this._queueColumnWidthUpdate()}_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(e=>e.remove());let t=e.querySelector(`:scope > [data-scb-sort-header="true"]`);if(!(t instanceof HTMLElement))return;let n=t.querySelector(`:scope > [data-scb-sort-label="true"]`);if(n instanceof HTMLElement){t.replaceWith(n);return}t.remove()}_getOrCreateHeaderLabel(e,t){let n=e.querySelector(`:scope > [data-scb-sort-label="true"]`);if(n instanceof HTMLElement)return n;let r=e.querySelector(`:scope > p`);if(r instanceof HTMLParagraphElement)return r.setAttribute(`data-scb-sort-label`,`true`),r;let i=Array.from(e.children).find(e=>e instanceof HTMLElement&&!e.matches(`scb-icon-button.scb-sort-icon`));if(i)return i.setAttribute(`data-scb-sort-label`,`true`),i;let a=this._getNormalizedText(e.textContent),o=a||this._getNormalizedText(e.getAttribute(`aria-label`))||this._getFallbackColumnLabel(t),s=document.createElement(`p`);return s.setAttribute(`data-scb-sort-label`,`true`),s.setAttribute(`data-scb-generated-label`,`true`),s.textContent=o,a||(s.setAttribute(`data-scb-visually-hidden-label`,`true`),this._applyVisuallyHiddenStyles(s)),e.textContent=``,e.appendChild(s),s}_getHeaderLabelText(e,t,n){return this._getNormalizedText(t.textContent)||this._getNormalizedText(e.getAttribute(`aria-label`))||this._getFallbackColumnLabel(n)}_getFallbackColumnLabel(e){return`kolumn ${Math.max(e,0)+1}`}_applyVisuallyHiddenStyles(e){e.style.position=`absolute`,e.style.width=`1px`,e.style.height=`1px`,e.style.padding=`0`,e.style.margin=`-1px`,e.style.overflow=`hidden`,e.style.whiteSpace=`nowrap`,e.style.clip=`rect(0, 0, 0, 0)`,e.style.clipPath=`inset(50%)`,e.style.border=`0`}_wrapHeaderWithSortControl(e,t,n){let r=document.createElement(`div`);r.setAttribute(`data-scb-sort-header`,`true`),r.style.display=`flex`,r.style.gap=`8px`,r.style.flexWrap=`nowrap`,r.style.alignItems=`center`,r.appendChild(t),r.appendChild(n),e.appendChild(r)}_getNormalizedText(e){return(e??``).replace(/\s+/g,` `).trim()}_queueColumnWidthUpdate(){this._columnWidthFrame!==null&&cancelAnimationFrame(this._columnWidthFrame),this._columnWidthFrame=requestAnimationFrame(()=>{this._columnWidthFrame=null,this._applyColumnWidthMode()})}_applyColumnWidthMode(){this._getTables().forEach(e=>{if(this._removeGeneratedColGroup(e),e.style.tableLayout=``,e.style.width=``,e.style.minWidth=``,e.style.maxWidth=``,this.columnWidthMode!==`header`)return;let t=Array.from(e.querySelectorAll(`thead tr`)),n=t[t.length-1];if(!n)return;let r=Array.from(n.cells).map((t,n)=>{let r=this._measureCellContentWidth(t),i=this._measureColumnReadableBodyWidth(e,n),a=Math.max(r,i);return`${Math.ceil(a>0?Math.max(a,zf):0)}px`}),i=r.reduce((e,t)=>e+parseFloat(t),0);this._applyGeneratedColGroup(e,r),e.style.tableLayout=`fixed`,e.style.width=`${Math.ceil(i)}px`,e.style.minWidth=`${Math.ceil(i)}px`,e.style.maxWidth=`none`})}_applyGeneratedColGroup(e,t){let n=document.createElement(`colgroup`);n.setAttribute(`data-scb-generated-column-widths`,`true`),t.forEach(e=>{let t=document.createElement(`col`);t.style.width=e,t.style.minWidth=e,n.appendChild(t)}),e.insertBefore(n,e.firstChild)}_removeGeneratedColGroup(e){e.querySelector(`colgroup[data-scb-generated-column-widths="true"]`)?.remove()}_measureCellContentWidth(e){let t=e.firstElementChild?.cloneNode(!0)??document.createElement(`span`);e.firstElementChild||(t.textContent=e.textContent??``);let n=window.getComputedStyle(e),r=document.createElement(`div`);r.style.position=`absolute`,r.style.left=`-99999px`,r.style.top=`0`,r.style.visibility=`hidden`,r.style.pointerEvents=`none`,r.style.width=`max-content`,r.style.maxWidth=`none`,r.style.whiteSpace=`nowrap`,r.style.fontFamily=n.fontFamily,r.style.fontSize=n.fontSize,r.style.fontWeight=n.fontWeight,r.style.lineHeight=n.lineHeight,r.style.letterSpacing=n.letterSpacing,t instanceof HTMLElement&&(t.style.width=`max-content`,t.style.maxWidth=`none`,t.style.whiteSpace=`nowrap`),r.appendChild(t),document.body.appendChild(r);let i=parseFloat(n.paddingLeft||`0`),a=parseFloat(n.paddingRight||`0`),o=parseFloat(n.borderLeftWidth||`0`),s=parseFloat(n.borderRightWidth||`0`),c=r.getBoundingClientRect().width+i+a+o+s;return document.body.removeChild(r),c}_measureColumnReadableBodyWidth(e,t){return Array.from(e.querySelectorAll(`tbody tr`)).reduce((e,n)=>{let r=n.cells[t];if(!r)return e;let i=(r.textContent??``).replace(/\s+/g,` `).trim().split(` `).filter(Boolean).reduce((e,t)=>Math.max(e,this._measureCellTextWidth(r,t)),0),a=i>0?i+Bf:0;return Math.max(e,a)},0)}_measureCellTextWidth(e,t){let n=window.getComputedStyle(e),r=document.createElement(`span`);r.textContent=t,r.style.position=`absolute`,r.style.left=`-99999px`,r.style.top=`0`,r.style.visibility=`hidden`,r.style.pointerEvents=`none`,r.style.whiteSpace=`nowrap`,r.style.fontFamily=n.fontFamily,r.style.fontSize=n.fontSize,r.style.fontWeight=n.fontWeight,r.style.lineHeight=n.lineHeight,r.style.letterSpacing=n.letterSpacing,document.body.appendChild(r);let i=parseFloat(n.paddingLeft||`0`),a=parseFloat(n.paddingRight||`0`),o=parseFloat(n.borderLeftWidth||`0`),s=parseFloat(n.borderRightWidth||`0`),c=r.getBoundingClientRect().width+i+a+o+s;return document.body.removeChild(r),c}_onThClick(e){this.dataSorting&&(this._sortedColumn===e?this._sortDirection=this._sortDirection===`asc`?`desc`:`asc`:(this._sortedColumn=e,this._sortDirection=`asc`),this._sortTable(e,this._sortDirection),this._attachThListeners(),this.dispatchEvent(new CustomEvent(`tablesortchange`,{detail:{sortedColumn:this._sortedColumn,sortDirection:this._sortDirection},bubbles:!0,composed:!0})))}_getHeaderAriaSort(e){return this._sortedColumn===e?this._sortDirection===`asc`?`ascending`:`descending`:`none`}_getSortButtonLabel(e,t){return`Sortera ${e||`kolumn ${t+1}`} ${this._sortedColumn===t&&this._sortDirection===`asc`?`fallande`:`stigande`}`}_sortTable(e,t){let n=this._getTbody();if(!n)return;let r=Array.from(n.querySelectorAll(`tr`));r.sort((n,r)=>{let i=this._getCellSortableValue(n.children[e]),a=this._getCellSortableValue(r.children[e]);return this._compareCellValues(i,a,t)}),r.forEach(e=>n.appendChild(e))}_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}};P([_({type:Boolean,attribute:`data-sorting`})],Vf.prototype,`dataSorting`,void 0),P([_({type:String,attribute:`column-width-mode`})],Vf.prototype,`columnWidthMode`,void 0),Vf=P([a(`scb-table`)],Vf),w(),b(),rl(),du(),F();var Hf=class extends C{constructor(...e){super(...e),this.searchTerm=``,this.pagination=!1,this.filteringSearch=!1,this.noScroll=!1,this.pageSize=10,this.disableSorting=[],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=e=>{let t=e.detail;t&&typeof t.page==`number`&&this._changePage(t.page)}}static{this.styles=p`
|
|
16515
16515
|
:host {
|
|
16516
16516
|
display: block;
|
|
16517
16517
|
color: var(--md-sys-color-on-surface);
|
|
@@ -16601,7 +16601,7 @@
|
|
|
16601
16601
|
></scb-pagination>
|
|
16602
16602
|
`:``}
|
|
16603
16603
|
</div>
|
|
16604
|
-
`}_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=[],a=[];t.forEach(e=>{e.nodeType===Node.ELEMENT_NODE&&(Array.from(e.querySelectorAll(`thead`)).forEach(e=>{n.push(...Array.from(e.querySelectorAll(`th`)))}),r.push(...e.querySelectorAll(`th`)),i.push(...e.querySelectorAll(`td`)),a.push(...e.querySelectorAll(`tr`)))}),r.forEach(e=>{let t=n.indexOf(e),r=t!==-1;e.style.textAlign=`left`,e.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)`,e.style.position=`relative`,e.style.backgroundColor=`var(--md-sys-color-surface)`,e.style.fontFamily=`var(--scb-table-header-font)`,e.style.fontSize=`var(--scb-table-header-font-size)`,e.style.lineHeight=`var(--scb-table-header-line-height)`,e.style.fontWeight=`var(--scb-table-header-font-weight)`,e.style.letterSpacing=`var(--scb-table-header-letter-spacing)`,e.style.verticalAlign=`bottom`,this._removeGeneratedSortMarkup(e),e.hasAttribute(`scope`)||(r?e.setAttribute(`scope`,`col`):e.closest(`tbody`)&&e.setAttribute(`scope`,`row`));let i=this._getOrCreateHeaderLabel(e,t);if((i instanceof HTMLParagraphElement||i.getAttribute(`data-scb-generated-label`)===`true`)&&this._applyGeneratedCellTextReset(i),!r){e.removeAttribute(`aria-sort`);return}e.setAttribute(`aria-sort`,this._getHeaderAriaSort(t));let a=this._getNormalizedText(i.textContent)||`kolumn ${Math.max(t,0)+1}`,o=document.createElement(`scb-icon-button`);o.className=`scb-sort-icon`,o.onclick=()=>this._onThClick(t),o.setAttribute(`variant`,`standard`),o.setAttribute(`size`,`small`),o.setAttribute(`aria-label`,this._getSortButtonLabel(a,t)),this._sortedColumn===t?(o.setAttribute(`variant`,`filled-tonal`),o.setAttribute(`icon`,this._sortDirection===`asc`?`arrow_downward`:`arrow_upward`)):(o.setAttribute(`icon`,`swap_horiz`),o.style.transform+=` rotate(90deg)`,o.style.alignSelf=`end`),this._wrapHeaderWithSortControl(e,i,o)}),i.forEach(e=>{e.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)`,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(--scb-table-cell-font)`,e.style.fontSize=`var(--scb-table-cell-font-size)`,e.style.lineHeight=`var(--scb-table-cell-line-height)`,e.style.fontWeight=`var(--scb-table-cell-font-weight)`,e.style.letterSpacing=`var(--scb-table-cell-letter-spacing)`}),a.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=`var(--scb-table-cell-edge-padding-inline)`),t===n.length-1?e.style.paddingRight=`var(--scb-table-cell-edge-padding-inline)`:e.style.paddingRight=``});let r=e.querySelectorAll(`td`);r.length>0&&r.forEach((e,t)=>{t===0&&(e.style.paddingLeft=`var(--scb-table-cell-edge-padding-inline)`),t===r.length-1?e.style.paddingRight=`var(--scb-table-cell-edge-padding-inline)`:e.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(e=>e.remove());let t=e.querySelector(`:scope > [data-scb-sort-header="true"]`);if(!(t instanceof HTMLElement))return;let n=t.querySelector(`:scope > [data-scb-sort-label="true"]`);if(n instanceof HTMLElement){t.replaceWith(n);return}t.remove()}_getOrCreateHeaderLabel(e,t){let n=e.querySelector(`:scope > [data-scb-sort-label="true"]`);if(n instanceof HTMLElement)return n;let r=e.querySelector(`:scope > p`);if(r instanceof HTMLParagraphElement)return r.setAttribute(`data-scb-sort-label`,`true`),r;let i=Array.from(e.children).find(e=>e instanceof HTMLElement&&!e.matches(`scb-icon-button.scb-sort-icon`));if(i)return i.setAttribute(`data-scb-sort-label`,`true`),i;let a=document.createElement(`p`);return a.setAttribute(`data-scb-sort-label`,`true`),a.setAttribute(`data-scb-generated-label`,`true`),a.textContent=this._getNormalizedText(e.textContent)||`kolumn ${Math.max(t,0)+1}`,e.textContent=``,e.appendChild(a),a}_wrapHeaderWithSortControl(e,t,n){let r=document.createElement(`div`);r.setAttribute(`data-scb-sort-header`,`true`),r.style.display=`flex`,r.style.gap=`8px`,r.style.flexWrap=`nowrap`,r.style.alignItems=`center`,r.appendChild(t),r.appendChild(n),e.appendChild(r)}_getNormalizedText(e){return(e??``).replace(/\s+/g,` `).trim()}_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()}_getHeaderAriaSort(e){return this._sortedColumn===e?this._sortDirection===`asc`?`ascending`:`descending`:`none`}_getSortButtonLabel(e,t){return`Sortera ${e||`kolumn ${t+1}`} ${this._sortedColumn===t&&this._sortDirection===`asc`?`fallande`:`stigande`}`}_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})],Hf.prototype,`searchTerm`,void 0),P([_({type:Boolean,attribute:`with-pagination`})],Hf.prototype,`pagination`,void 0),P([_({type:Boolean,attribute:`with-filtering-search`})],Hf.prototype,`filteringSearch`,void 0),P([_({type:Boolean,attribute:`no-scroll`})],Hf.prototype,`noScroll`,void 0),P([_({type:Number,attribute:`page-size`})],Hf.prototype,`pageSize`,void 0),P([_({type:Number})],Hf.prototype,`currentPage`,void 0),P([_({type:Number})],Hf.prototype,`totalRows`,void 0),Hf=P([a(`scb-table-advanced`)],Hf),b(),w(),D(),F();var Uf=class extends Ms{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=[...Ms.styles,p`
|
|
16604
|
+
`}_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(`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(),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=[],a=[];t.forEach(e=>{e.nodeType===Node.ELEMENT_NODE&&(Array.from(e.querySelectorAll(`thead`)).forEach(e=>{n.push(...Array.from(e.querySelectorAll(`th`)))}),r.push(...e.querySelectorAll(`th`)),i.push(...e.querySelectorAll(`td`)),a.push(...e.querySelectorAll(`tr`)))}),r.forEach(e=>{let t=n.indexOf(e),r=t!==-1;e.style.textAlign=`left`,e.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)`,e.style.position=`relative`,e.style.backgroundColor=`var(--md-sys-color-surface)`,e.style.fontFamily=`var(--scb-table-header-font)`,e.style.fontSize=`var(--scb-table-header-font-size)`,e.style.lineHeight=`var(--scb-table-header-line-height)`,e.style.fontWeight=`var(--scb-table-header-font-weight)`,e.style.letterSpacing=`var(--scb-table-header-letter-spacing)`,e.style.verticalAlign=`bottom`,this._removeGeneratedSortMarkup(e),e.hasAttribute(`scope`)||(r?e.setAttribute(`scope`,`col`):e.closest(`tbody`)&&e.setAttribute(`scope`,`row`));let i=this._getOrCreateHeaderLabel(e,t);if((i instanceof HTMLParagraphElement||i.getAttribute(`data-scb-generated-label`)===`true`)&&this._applyGeneratedCellTextReset(i),!r){e.removeAttribute(`aria-sort`);return}if(!this._isColumnSortable(t)){e.removeAttribute(`aria-sort`);return}e.setAttribute(`aria-sort`,this._getHeaderAriaSort(t));let a=this._getNormalizedText(i.textContent)||`kolumn ${Math.max(t,0)+1}`,o=document.createElement(`scb-icon-button`);o.className=`scb-sort-icon`,o.onclick=()=>this._onThClick(t),o.setAttribute(`variant`,`standard`),o.setAttribute(`size`,`small`),o.setAttribute(`aria-label`,this._getSortButtonLabel(a,t)),this._sortedColumn===t?(o.setAttribute(`variant`,`filled-tonal`),o.setAttribute(`icon`,this._sortDirection===`asc`?`arrow_downward`:`arrow_upward`)):(o.setAttribute(`icon`,`swap_horiz`),o.style.transform+=` rotate(90deg)`,o.style.alignSelf=`end`),this._wrapHeaderWithSortControl(e,i,o)}),i.forEach(e=>{e.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)`,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(--scb-table-cell-font)`,e.style.fontSize=`var(--scb-table-cell-font-size)`,e.style.lineHeight=`var(--scb-table-cell-line-height)`,e.style.fontWeight=`var(--scb-table-cell-font-weight)`,e.style.letterSpacing=`var(--scb-table-cell-letter-spacing)`}),a.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=`var(--scb-table-cell-edge-padding-inline)`),t===n.length-1?e.style.paddingRight=`var(--scb-table-cell-edge-padding-inline)`:e.style.paddingRight=``});let r=e.querySelectorAll(`td`);r.length>0&&r.forEach((e,t)=>{t===0&&(e.style.paddingLeft=`var(--scb-table-cell-edge-padding-inline)`),t===r.length-1?e.style.paddingRight=`var(--scb-table-cell-edge-padding-inline)`:e.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(e=>e.remove());let t=e.querySelector(`:scope > [data-scb-sort-header="true"]`);if(!(t instanceof HTMLElement))return;let n=t.querySelector(`:scope > [data-scb-sort-label="true"]`);if(n instanceof HTMLElement){t.replaceWith(n);return}t.remove()}_getOrCreateHeaderLabel(e,t){let n=e.querySelector(`:scope > [data-scb-sort-label="true"]`);if(n instanceof HTMLElement)return n;let r=e.querySelector(`:scope > p`);if(r instanceof HTMLParagraphElement)return r.setAttribute(`data-scb-sort-label`,`true`),r;let i=Array.from(e.children).find(e=>e instanceof HTMLElement&&!e.matches(`scb-icon-button.scb-sort-icon`));if(i)return i.setAttribute(`data-scb-sort-label`,`true`),i;let a=document.createElement(`p`);return a.setAttribute(`data-scb-sort-label`,`true`),a.setAttribute(`data-scb-generated-label`,`true`),a.textContent=this._getNormalizedText(e.textContent)||`kolumn ${Math.max(t,0)+1}`,e.textContent=``,e.appendChild(a),a}_wrapHeaderWithSortControl(e,t,n){let r=document.createElement(`div`);r.setAttribute(`data-scb-sort-header`,`true`),r.style.display=`flex`,r.style.gap=`8px`,r.style.flexWrap=`nowrap`,r.style.alignItems=`center`,r.appendChild(t),r.appendChild(n),e.appendChild(r)}_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?this._sortDirection===`asc`?`ascending`:`descending`:`none`}_getSortButtonLabel(e,t){return`Sortera ${e||`kolumn ${t+1}`} ${this._sortedColumn===t&&this._sortDirection===`asc`?`fallande`:`stigande`}`}_isColumnSortable(e){return!(Array.isArray(this.disableSorting)?this.disableSorting:[]).some(t=>Number(t)===e)}_sortTable(e,t){if(!this._isColumnSortable(e))return;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})],Hf.prototype,`searchTerm`,void 0),P([_({type:Boolean,attribute:`with-pagination`})],Hf.prototype,`pagination`,void 0),P([_({type:Boolean,attribute:`with-filtering-search`})],Hf.prototype,`filteringSearch`,void 0),P([_({type:Boolean,attribute:`no-scroll`})],Hf.prototype,`noScroll`,void 0),P([_({type:Number,attribute:`page-size`})],Hf.prototype,`pageSize`,void 0),P([_({type:Array,attribute:`disable-sorting`})],Hf.prototype,`disableSorting`,void 0),P([_({type:Number})],Hf.prototype,`currentPage`,void 0),P([_({type:Number})],Hf.prototype,`totalRows`,void 0),Hf=P([a(`scb-table-advanced`)],Hf),b(),w(),D(),F();var Uf=class extends Ms{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=[...Ms.styles,p`
|
|
16605
16605
|
:host {
|
|
16606
16606
|
/* Storlek och text styrs via tabs i src/tokens/source/component-size-model.json. */
|
|
16607
16607
|
--md-primary-tab-container-height: var(--scb-tabs-height, var(--scale-11, 48px));
|