@public-ui/components
Version:
Contains all web components that belong to KoliBri - The accessible HTML-Standard.
5 lines • 33 kB
JavaScript
/*!
* KoliBri - The accessible HTML-Standard
*/
import{r as n,h as t,H as e,g as i}from"./index-BQlHOxik.js";import{g as o,k as l}from"./component-names-Dy77vq43.js";import{t as a}from"./i18n-Br16IAnY.js";import{e as s,b as r,s as c,P as h,o as d,p as f,j as b}from"./common-Cx_AGO_M.js";import{v as p,a as k}from"./aria-labelledby-CEzR68x-.js";import{v as u,a as m,b as _,c as g,d as y,e as v}from"./table-selection-DmmUo33G.js";import{v as x}from"./label-Fyi30H9j.js";import{C as w}from"./keyboard-DNd73LVa.js";import{K as z,d as S}from"./events-VVvk1win.js";import"./i18n-B2d_exHc.js";const j=(n,t,e={})=>{s(n,"_allowMultiSort",t,Object.assign({defaultValue:false},e))};const C=["top","bottom","both"];const O=(n,t)=>{r(n,`_paginationPosition`,(n=>typeof n==="string"&&C.includes(n)),new Set([`PaginationPositionPropType {${C.join(", ")}`]),t,{defaultValue:"bottom"})};const T='@charset "UTF-8";\n/*\n* This file defines the layer order for all CSS layers used in KoliBri.\n* The order is important as it determines the cascade priority.\n*\n* Layer order (lowest to highest priority):\n* 1. kol-a11y - Accessibility defaults and requirements\n* 2. kol-global - Global component styles and resets\n* 3. kol-component - Component-specific styles\n* 4. kol-theme-global - Theme-specific global styles\n* 5. kol-theme-component - Theme-specific component styles\n*/\n@layer kol-a11y, kol-global, kol-component, kol-theme-global, kol-theme-component;\n/* forward the rem function */\n/*\n * This file contains all rules for accessibility.\n */\n@layer kol-a11y {\n :host {\n /*\n * Minimum size of interactive elements.\n */\n --a11y-min-size: calc(44 * 1rem / var(--kolibri-root-font-size, 16));\n /*\n * No element should be used without verifying the contrast ratio of its background and font colors.\n * By initially setting the background color to white and the font color to black,\n * the contrast ratio is ensured and explicit adjustment is forced.\n */\n color: black;\n background-color: white;\n /*\n * Verdana is an accessible font that can be used without requiring additional loading time.\n */\n font-family: Verdana;\n /*\n * Letter spacing is required for all texts.\n */\n letter-spacing: inherit;\n /*\n * Word spacing is required for all texts.\n */\n word-spacing: inherit;\n /*\n * Text should be aligned left by default to provide a predictable starting point.\n */\n text-align: left;\n }\n * {\n /*\n * This rule enables the word dividing for all texts. That is important for high zoom levels.\n */\n hyphens: auto;\n /*\n * This rule enables the word dividing for all texts. That is important for high zoom levels.\n */\n word-break: break-word;\n }\n /*\n * All interactive elements should have a minimum size of to-rem(44).\n */\n /* input:not([type=\'checkbox\'], [type=\'radio\'], [type=\'range\']), */\n /* option, */\n /* select, */\n /* textarea, */\n button,\n .kol-input .input {\n min-width: var(--a11y-min-size);\n min-height: var(--a11y-min-size);\n }\n /*\n * Some interactive elements should not inherit the font-family and font-size.\n */\n a,\n button,\n h1,\n h2,\n h3,\n h4,\n h5,\n h6,\n input,\n option,\n select,\n textarea {\n /*\n * All elements should inherit the text color from his parent element.\n */\n color: inherit;\n /*\n * All elements should inherit the font family from his parent element.\n */\n font-family: inherit;\n /*\n * All elements should inherit the font size from his parent element.\n */\n font-size: inherit;\n /*\n * Letter spacing is required for all texts.\n */\n letter-spacing: inherit;\n /*\n * Word spacing is required for all texts.\n */\n word-spacing: inherit;\n }\n /**\n * Sometimes we need the semantic element for accessibility reasons,\n * but we don\'t want to show it.\n *\n * - https://www.a11yproject.com/posts/how-to-hide-content/\n */\n .visually-hidden {\n position: fixed;\n top: 0;\n left: 0;\n width: 1px;\n height: 1px;\n overflow: hidden;\n white-space: nowrap;\n clip-path: inset(50%);\n }\n}\n@layer kol-global {\n /*\n * Dieses CSS stellt sicher, dass der Standard-Style\n * von A und Button resettet werden.\n */\n :is(a, button) {\n background-color: transparent;\n width: 100%;\n margin: 0;\n padding: 0;\n border: none;\n /* 100% needed for custom width from outside */\n }\n /*\n * Ensure elements with hidden attribute to be actually not visible\n * @see https://meowni.ca/hidden.is.a.lie.html\n */\n [hidden] {\n display: none !important;\n }\n .badge-text-hint {\n color: black;\n background-color: white;\n }\n}\n@layer kol-global {\n :host {\n /*\n * The max-width is needed to prevent the table from overflowing the\n * parent node, if the table is wider than the parent node.\n */\n max-width: 100%;\n font-size: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n }\n * {\n /*\n * We prefer to box-sizing: border-box for all elements.\n */\n box-sizing: border-box;\n }\n .kol-span {\n /* KolSpan is a layout component with icons in all directions and a label text in the middle. */\n display: flex;\n flex-flow: column;\n align-items: center;\n justify-content: center;\n /* The sub span in KolSpan is the horizontal span with icon left and right and the label text in the middle. */\n }\n .kol-span__container {\n display: flex;\n align-items: center;\n }\n a,\n button {\n cursor: pointer;\n }\n .kol-span .kol-span__label--hide-label .kol-span__label {\n display: none;\n }\n /* Reset browser agent style. */\n button:disabled {\n color: unset;\n }\n .disabled label,\n .disabled:focus-within label,\n [aria-disabled=true],\n [aria-disabled=true]:focus,\n [disabled],\n [disabled]:focus {\n outline: none;\n cursor: not-allowed;\n }\n [aria-disabled=true]:focus .kol-span,\n [disabled]:focus .kol-span {\n outline: none !important;\n }\n .hastooltip {\n z-index: 900 !important;\n }\n}\n@layer kol-component {\n :host {\n display: block;\n }\n}\n@font-face {\n font-family: "kolicons";\n src: url("kolicons.eot?t=1780571516250"); /* IE9*/\n src: url("kolicons.eot?t=1780571516250#iefix") format("embedded-opentype"), url("kolicons.woff2?t=1780571516250") format("woff2"), url("kolicons.woff?t=1780571516250") format("woff"), url("kolicons.ttf?t=1780571516250") format("truetype"), url("kolicons.svg?t=1780571516250#kolicons") format("svg"); /* iOS 4.1- */\n}\n@layer kol-component {\n [class^=kolicon-], [class*=" kolicon-"] {\n font-family: "kolicons";\n font-style: normal;\n font-weight: 400;\n line-height: 1em;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n }\n .kolicon-alert-error::before {\n content: "\\ea01";\n }\n .kolicon-alert-info::before {\n content: "\\ea02";\n }\n .kolicon-alert-success::before {\n content: "\\ea03";\n }\n .kolicon-alert-warning::before {\n content: "\\ea04";\n }\n .kolicon-check::before {\n content: "\\ea05";\n }\n .kolicon-chevron-double-left::before {\n content: "\\ea06";\n }\n .kolicon-chevron-double-right::before {\n content: "\\ea07";\n }\n .kolicon-chevron-down::before {\n content: "\\ea08";\n }\n .kolicon-chevron-left::before {\n content: "\\ea09";\n }\n .kolicon-chevron-right::before {\n content: "\\ea0a";\n }\n .kolicon-chevron-up::before {\n content: "\\ea0b";\n }\n .kolicon-cogwheel::before {\n content: "\\ea0c";\n }\n .kolicon-cross::before {\n content: "\\ea0d";\n }\n .kolicon-eye-closed::before {\n content: "\\ea0e";\n }\n .kolicon-eye::before {\n content: "\\ea0f";\n }\n .kolicon-house::before {\n content: "\\ea10";\n }\n .kolicon-kolibri::before {\n content: "\\ea11";\n }\n .kolicon-link-external::before {\n content: "\\ea12";\n }\n .kolicon-link::before {\n content: "\\ea13";\n }\n .kolicon-minus::before {\n content: "\\ea14";\n }\n .kolicon-plus::before {\n content: "\\ea15";\n }\n .kolicon-settings::before {\n content: "\\ea16";\n }\n .kolicon-sort-asc::before {\n content: "\\ea17";\n }\n .kolicon-sort-desc::before {\n content: "\\ea18";\n }\n .kolicon-sort-neutral::before {\n content: "\\ea19";\n }\n .kolicon-up::before {\n content: "\\ea1a";\n }\n .kolicon-version::before {\n content: "\\ea1b";\n }\n}\n@layer kol-component {\n .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n .kol-tooltip {\n display: contents;\n }\n .kol-tooltip__floating {\n opacity: 0;\n display: none;\n position: fixed;\n /* Avoid layout interference - see https://floating-ui.com/docs/computePosition */\n top: 0;\n left: 0;\n /* Can be used to specify the tooltip-width from the outside. Unset by default. */\n width: var(--kol-tooltip-width, max-content);\n min-width: calc(8 * 1rem / var(--kolibri-root-font-size, 16));\n max-width: 90vw;\n max-height: 90vh;\n animation-direction: normal;\n /* Can be used to specify the animation duration from the outside. 250ms by default. */\n animation-duration: var(--kolibri-tooltip-animation-duration, 250ms);\n animation-fill-mode: forwards;\n animation-iteration-count: 1;\n animation-timing-function: ease-in;\n }\n .kol-tooltip__floating.hide {\n animation-name: hideTooltip;\n }\n .kol-tooltip__floating.show {\n animation-name: showTooltip;\n }\n .kol-tooltip__arrow {\n transform: rotate(45deg);\n color: black;\n background-color: white;\n position: absolute;\n z-index: 999;\n width: calc(10 * 1rem / var(--kolibri-root-font-size, 16));\n height: calc(10 * 1rem / var(--kolibri-root-font-size, 16));\n }\n .kol-tooltip__content {\n color: black;\n background-color: white;\n position: relative;\n z-index: 1000;\n }\n @keyframes hideTooltip {\n 0% {\n opacity: 1;\n }\n 100% {\n opacity: 0;\n display: none;\n }\n }\n @keyframes showTooltip {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n }\n}\n@layer kol-component {\n .kol-alert .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n .kol-alert :host {\n display: inline-block;\n }\n .kol-alert .kol-button {\n display: flex;\n min-height: var(--a11y-min-size);\n font-style: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n text-decoration-line: none;\n }\n .kol-alert .kol-button::before {\n /* Render zero-width character as first element to set the baseline correctly. */\n content: "";\n }\n .kol-alert .kol-button__text {\n flex: 1 0 100%;\n }\n .kol-alert {\n display: grid;\n }\n .kol-alert__container {\n display: flex;\n place-items: center;\n }\n .kol-alert__container-content {\n flex-grow: 1;\n }\n .kol-alert__closer {\n /* Visible with forced colors */\n outline: transparent solid calc(1 * 1rem / var(--kolibri-root-font-size, 16));\n }\n .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n :host {\n display: inline-block;\n }\n .kol-button {\n display: flex;\n min-height: var(--a11y-min-size);\n font-style: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n text-decoration-line: none;\n }\n .kol-button::before {\n /* Render zero-width character as first element to set the baseline correctly. */\n content: "";\n }\n .kol-button__text {\n flex: 1 0 100%;\n }\n .kol-popover-button__popover {\n margin: 0;\n padding: 0;\n border: 0;\n }\n .kol-popover-button--inline .kol-popover-button__button {\n display: inline;\n }\n .kol-popover {\n opacity: 0;\n transition: 0.2s ease-out opacity;\n }\n .kol-popover-button--open + .kol-popover {\n opacity: 1;\n }\n .kol-table-settings {\n position: absolute;\n top: 0;\n right: 0;\n z-index: 1;\n }\n .kol-table-settings .kol-popover-button__popover {\n background: white;\n box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);\n border-radius: calc(8 * 1rem / var(--kolibri-root-font-size, 16));\n border: 1px solid black;\n }\n .kol-table-settings__columns-container {\n max-height: calc(200 * 1rem / var(--kolibri-root-font-size, 16));\n overflow: auto;\n }\n .kol-table-settings__columns {\n display: grid;\n align-items: center;\n grid-auto-rows: min-content;\n grid-template-columns: min-content minmax(max-content, 1fr) calc(140 * 1rem / var(--kolibri-root-font-size, 16)) auto auto;\n }\n .kol-table-settings__column {\n display: contents;\n }\n .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n .kol-table {\n --kol-table-selection-col-width: var(--a11y-min-size);\n display: block;\n position: relative;\n max-width: 100%;\n }\n .kol-table:has(.kol-table__focus-element:focus) .kol-table__scroll-container {\n /* @see https://remysharp.com/til/css/focus-ring-default-styles */\n outline: 5px auto Highlight;\n outline: 5px auto -webkit-focus-ring-color;\n outline-offset: 2px;\n }\n .kol-table__scroll-container {\n overflow-x: auto;\n overflow-y: hidden;\n }\n .kol-table__table {\n table-layout: fixed;\n }\n .kol-table__caption {\n min-height: var(--a11y-min-size);\n text-align: start;\n }\n .kol-table__sort-button .kol-button {\n color: inherit;\n }\n .kol-table__sort {\n display: inline-flex;\n align-items: center;\n }\n .kol-table__sort-order {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n }\n .kol-table__body {\n text-align: left;\n }\n .kol-table__body .kol-button__text {\n justify-items: start;\n }\n .kol-table__cell--align-left {\n text-align: left;\n }\n .kol-table__cell--align-left .kol-button__text {\n align-items: start;\n }\n .kol-table__cell--align-center {\n text-align: center;\n }\n .kol-table__cell--align-center .kol-button__text {\n align-items: center;\n }\n .kol-table__cell--align-right {\n text-align: right;\n }\n .kol-table__cell--align-right .kol-button__text {\n align-items: end;\n }\n .kol-table__cell--selection {\n background-color: white;\n position: sticky !important;\n left: 0;\n z-index: 2;\n width: var(--kol-table-selection-col-width, auto);\n min-width: var(--a11y-min-size);\n min-height: var(--a11y-min-size);\n white-space: nowrap;\n }\n .kol-table__cell--actions {\n white-space: nowrap;\n }\n .kol-table__cell--actions .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n .kol-table__cell--actions :host {\n display: inline-block;\n }\n .kol-table__cell--actions .kol-button {\n display: flex;\n min-height: var(--a11y-min-size);\n font-style: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n text-decoration-line: none;\n }\n .kol-table__cell--actions .kol-button::before {\n /* Render zero-width character as first element to set the baseline correctly. */\n content: "";\n }\n .kol-table__cell--actions .kol-button__text {\n flex: 1 0 100%;\n }\n .kol-table__cell--actions .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n .kol-table__cell--actions :host {\n display: inline-block;\n }\n .kol-table__cell--actions .kol-link {\n display: inline-flex;\n max-width: fit-content;\n align-items: baseline;\n place-items: center;\n text-align: left;\n text-decoration-line: none;\n }\n .kol-table__cell--actions .kol-link--standalone {\n min-width: var(--a11y-min-size);\n min-height: var(--a11y-min-size);\n align-items: stretch;\n }\n .kol-table__cell--actions .kol-link--standalone .kol-link__text {\n display: inline-flex;\n flex: 1 1 100%;\n place-items: center;\n }\n .kol-table__cell--actions .kol-link .kol-span__label {\n text-decoration-line: underline;\n }\n .kol-table__cell--actions .kol-link:focus:not([aria-disabled], [disabled]) .kol-span__label, .kol-table__cell--actions .kol-link:hover:not([aria-disabled], [disabled]) .kol-span__label {\n text-decoration-thickness: 0.2em;\n }\n .kol-table__cell--actions .kol-link__icon {\n display: inline-flex;\n }\n .kol-table__cell--sticky-left, .kol-table__cell--sticky-right {\n background-color: white;\n position: sticky !important;\n z-index: 1;\n }\n .kol-table__cell--sticky-left:nth-last-child(1 of .kol-table__cell--sticky-left) {\n border-right: 2px solid black;\n }\n .kol-table__cell--sticky-right:nth-child(1 of .kol-table__cell--sticky-left) {\n border-left: 2px solid black;\n }\n .kol-table__cell-actions {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n justify-content: center;\n }\n .kol-table__spacer {\n display: none;\n }\n .kol-table__selection {\n position: relative;\n }\n .kol-table__selection-label {\n display: flex;\n position: relative;\n min-width: var(--a11y-min-size);\n min-height: var(--a11y-min-size);\n align-items: center;\n justify-content: center;\n cursor: pointer;\n }\n .kol-table__selection--disabled {\n cursor: not-allowed;\n }\n .kol-table__selection-icon {\n display: block;\n position: absolute;\n inset: auto;\n z-index: 1;\n }\n .kol-table__selection-input {\n border-style: solid;\n margin: 0;\n appearance: none;\n cursor: pointer;\n }\n .kol-table__selection-input:disabled {\n cursor: not-allowed;\n }\n .kol-table__selection-input:before {\n content: "";\n }\n .kol-table__selection-input--checkbox {\n background-color: white;\n display: flex;\n position: relative;\n min-width: calc(var(--a11y-min-size) / 2);\n min-height: calc(var(--a11y-min-size) / 2);\n border-width: 2px;\n align-items: center;\n justify-content: center;\n line-height: 1.5;\n }\n .kol-table__selection-input--radio {\n border-radius: 100%;\n display: flex;\n width: 1.5em;\n min-width: 1.5em;\n height: 1.5em;\n min-height: 1.5em;\n padding: 0;\n border-width: 2px;\n }\n .kol-table__selection-input--radio:before {\n border-radius: 100%;\n width: 0.75em;\n height: 0.75em;\n margin: auto;\n }\n .kol-table__selection-input--radio:checked:before {\n background-color: black;\n }\n @media (forced-colors: active) {\n .kol-table__selection-input--radio:checked:before {\n /* Give it a visible background in forced colors mode */\n background-color: selectedItem !important;\n }\n }\n .kol-alert .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n .kol-alert :host {\n display: inline-block;\n }\n .kol-alert .kol-button {\n display: flex;\n min-height: var(--a11y-min-size);\n font-style: calc(16 * 1rem / var(--kolibri-root-font-size, 16));\n text-decoration-line: none;\n }\n .kol-alert .kol-button::before {\n /* Render zero-width character as first element to set the baseline correctly. */\n content: "";\n }\n .kol-alert .kol-button__text {\n flex: 1 0 100%;\n }\n .kol-alert {\n display: grid;\n }\n .kol-alert__container {\n display: flex;\n place-items: center;\n }\n .kol-alert__container-content {\n flex-grow: 1;\n }\n .kol-alert__closer {\n /* Visible with forced colors */\n outline: transparent solid calc(1 * 1rem / var(--kolibri-root-font-size, 16));\n }\n .kol-form-field {\n display: grid;\n }\n .kol-form-field:not(.kol-form-field--disabled) .kol-form-field__label {\n cursor: pointer;\n }\n .kol-form-field__label-text {\n flex-flow: row;\n align-items: flex-start;\n justify-content: flex-start;\n }\n .kol-form-field--required .kol-form-field__label-text:has(.kol-span__slot[hidden])::after,\n .kol-form-field--required .kol-tooltip__content .kol-span__label::after {\n content: "*"/"";\n }\n .kol-input-container {\n background-color: transparent;\n display: grid;\n position: relative;\n width: 100%;\n min-width: var(--a11y-min-size);\n min-height: var(--a11y-min-size);\n align-items: center;\n grid-template-columns: 1fr;\n }\n .kol-input-container:has(> .kol-input-container__adornment--start) {\n grid-template-columns: auto 1fr auto;\n }\n .kol-input-container__container {\n position: relative;\n z-index: 1;\n }\n .kol-input-container__adornment {\n display: flex;\n align-items: center;\n }\n .kol-input-container__adornment .kol-icon {\n display: grid;\n min-height: var(--a11y-min-size);\n place-items: center;\n }\n .kol-select {\n background-color: transparent;\n width: 100%;\n padding: 0;\n }\n .kol-select:not(:disabled) {\n cursor: pointer;\n }\n .kol-select:not([multiple], [size]) {\n height: 2.75em;\n }\n .kol-select:focus {\n outline: none;\n }\n .kol-select__option:checked::before {\n content: "✓ ";\n }\n .kol-select[multiple] option {\n display: flex;\n min-height: var(--a11y-min-size);\n align-items: center;\n }\n .kol-icon {\n color: inherit;\n display: inline-block;\n font-size: inherit;\n font-weight: inherit;\n line-height: inherit;\n }\n .kol-pagination {\n display: flex;\n flex-wrap: wrap;\n align-items: center;\n justify-content: center;\n container: paging/inline-size;\n }\n .kol-pagination__navigation-list {\n display: inline-flex;\n margin: 0;\n padding: 0;\n flex-wrap: wrap;\n align-items: center;\n list-style: none;\n }\n .kol-pagination__separator:before {\n content: "•••";\n }\n .kol-pagination__page-size-select .kol-form-field-select {\n align-items: center;\n grid-template-columns: 1fr max-content;\n }\n @container paging (width < 600px) {\n .kol-pagination:has(.kol-pagination__button--first) li:has(.kol-pagination__button--numbers),\n .kol-pagination:has(.kol-pagination__button--first) li:has(.kol-pagination__separator) {\n display: none;\n }\n }\n}';const A=[10,20,50,100];const P=n=>n===true||n===""||typeof n==="object"&&n!==null;const D=class{constructor(t){n(this,t);this.resolvedElements=[];this.catchRef=n=>{this.tableWcRef=n};this.sortData=[];this.showPagination=false;this.pageStartSlice=0;this.pageEndSlice=10;this.disableSort=false;this._paginationPosition="bottom";this.state={_allowMultiSort:false,_fixedCols:[0,0],_data:[],_dataFoot:[],_headers:{horizontal:[],vertical:[]},_label:"",_pagination:{_page:1,_pageSize:10,_max:0},_sortedData:[],_paginationPosition:"bottom",_hasSettingsMenu:false};this.handlePagination={onClick:(n,t)=>{var e;if(typeof((e=this.state._pagination._on)===null||e===void 0?void 0:e.onClick)==="function"){this.state._pagination._on.onClick(n,t)}c(this,"_pagination",Object.assign(Object.assign({},this.state._pagination),{_page:t}))},onChangePage:(n,t)=>{var e;if(typeof((e=this.state._pagination._on)===null||e===void 0?void 0:e.onChangePage)==="function"){this.state._pagination._on.onChangePage(n,t)}c(this,"_pagination",Object.assign(Object.assign({},this.state._pagination),{_page:t}))},onChangePageSize:(n,t)=>{var e;if(typeof((e=this.state._pagination._on)===null||e===void 0?void 0:e.onChangePageSize)==="function"){this.state._pagination._on.onChangePageSize(n,t)}c(this,"_pagination",Object.assign(Object.assign({},this.state._pagination),{_pageSize:t}));c(this,"_pageSize",t)}};this.onSelectionChange=n=>{n.stopPropagation()};this.updateSortedData=()=>{if(this.disableSort){c(this,"_sortedData",this.state._data);return}const n=[...this.state._data];if(this.sortData.length>0){n.sort(((n,t)=>{for(let e=0;e<this.sortData.length;e++){const i=this.sortData[e];const o=i.compareFn(n,t,i.direction);if(o!==0){return i.direction==="ASC"?o:-o}}return 0}))}c(this,"_sortedData",n)}}validateAriaLabelledby(n){this.syncExternalLabel(n)}syncExternalLabel(n){this.resolvedElements=p(this,this.host,this.internals,n)}validateAllowMultiSort(n){j(this,n,{defaultValue:false})}validateData(n){u(this,n,{afterPatch:()=>{setTimeout(this.updateSortedData)}})}validateDataFoot(n){m(this,n,{afterPatch:()=>{setTimeout(this.updateSortedData)}})}validateFixedCols(n){_(this,n)}validatePaginationPosition(n){O(this,n)}validateHasSettingsMenu(n){g(this,n)}changeCellSort(n){var t;if(n.type===undefined||n.type==="default"){if(typeof n.compareFn!=="function"){return}if(!this.state._allowMultiSort&&n.key!==((t=this.sortData[0])===null||t===void 0?void 0:t.key)){this.sortData=[]}const e=this.sortData.findIndex((t=>t.key===n.key));if(e>=0){const n=this.sortData[e];switch(n.direction){case"ASC":n.direction="DESC";break;case"DESC":this.sortData.splice(e,1);break;default:n.direction="ASC";break}}else if(n.key){this.sortData.push({label:n.label,key:n.key,compareFn:n.compareFn,direction:"ASC"})}this.updateSortedData()}}initializeSortFromHeaders(n){var t,e;let i=false;const o=n=>{this.sortData=[];n.forEach((n=>{if(n.type!==undefined&&n.type!=="default"){return}if(typeof n.compareFn==="function"&&!n.key){b(`[KolTableStateful] A sortable column requires the 'key' property.`);return}const t=n.key;if(!t){return}const e=n.sortDirection;if(e==="ASC"||e==="DESC"){if(typeof n.compareFn==="function"){if(this.state._allowMultiSort||this.sortData.length===0){this.sortData.push({label:n.label,key:t,compareFn:n.compareFn,direction:e})}i=true}}}))};(t=n.horizontal)===null||t===void 0?void 0:t.forEach(o);(e=n.vertical)===null||e===void 0?void 0:e.forEach(o);return i}validateHeaders(n){h(n,(()=>{d(n,(()=>{try{n=f(n)}catch(n){}r(this,"_headers",(n=>typeof n==="object"&&n!==null),new Set(["KoliBriTableHeaders"]),n,{hooks:{beforePatch:n=>{var t,e;const i=n;const o=this.initializeSortFromHeaders(i);if(o){setTimeout((()=>this.updateSortedData()))}if(i.horizontal&&i.vertical&&((t=i.horizontal)===null||t===void 0?void 0:t.length)>0&&((e=i.vertical)===null||e===void 0?void 0:e.length)>0){this.disableSort=true;b(`Table: You can not sort the table data, if horizontal and vertical headers are defined at the same time. (https://github.com/public-ui/kolibri/issues/2372)`)}}}})}))}))}validateLabel(n){x(this,n,{required:true})}validateSelection(n){y(this,n)}validateOn(n){v(this,n)}validatePagination(n){try{n=f(n)}catch(n){}this.showPagination=P(n);r(this,"_pagination",P,new Set(["boolean","KoliBriTablePagination"]),n,{defaultValue:{_page:1,_pageSize:10,_max:0}})}componentDidLoad(){var n;(n=this.tableWcRef)===null||n===void 0?void 0:n.addEventListener(z.selectionChange,this.onSelectionChange);if(!this.resolvedElements.length){this.syncExternalLabel(this._ariaLabelledby)}}disconnectedCallback(){var n;(n=this.tableWcRef)===null||n===void 0?void 0:n.removeEventListener(z.selectionChange,this.onSelectionChange)}componentWillLoad(){this.internals=k(this.host);this.syncExternalLabel(this._ariaLabelledby);this.validateAllowMultiSort(this._allowMultiSort);this.validateData(this._data);this.validateDataFoot(this._dataFoot);this.validateFixedCols(this._fixedCols);this.validateHeaders(this._headers);this.validateLabel(this._label);this.validateOn(this._on);this.validatePagination(this._pagination);this.validatePaginationPosition(this._paginationPosition);this.validateSelection(this._selection);this.validateHasSettingsMenu(this._hasSettingsMenu)}selectDisplayedData(n,t,e){if(typeof t==="number"&&t>0&&typeof e==="number"&&e>0){this.pageStartSlice=t*(e-1);this.pageEndSlice=t*e>n.length?n.length:t*e;return n.slice(this.pageStartSlice,this.pageEndSlice)}else{this.pageStartSlice=0;this.pageEndSlice=n.length;return n}}renderPagination(n){const e=a("kol-table-pagination-label",{placeholders:{label:`${this.state._label} (${a(`kol-pagination-position-${n}`)})`}});return t("div",{class:`kol-table-stateful__pagination kol-table-stateful__pagination--${this.state._paginationPosition}`},t("div",{class:"kol-table-stateful__pagination-wrapper"},t(o,{_boundaryCount:this.state._pagination._boundaryCount,_customClass:this.state._pagination._customClass,_hasButtons:this.state._pagination._hasButtons,_on:this.handlePagination,_page:this.state._pagination._page,_pageSize:this.state._pagination._pageSize,_pageSizeOptions:this.state._pagination._pageSizeOptions||A,_siblingCount:this.state._pagination._siblingCount,_tooltipAlign:"bottom",_max:this.state._pagination._max||this.state._data.length,_label:e})))}getHeaderCellSortState(n){if(n.type!==undefined&&n.type!=="default"){return}if(!this.disableSort&&typeof n.compareFn==="function"){if(n.key){const t=this.sortData.find((t=>t.key===n.key));if(t===null||t===void 0?void 0:t.direction){return t.direction}}return"NOS"}}getHeaderCellSortOrder(n){if(n.type!==undefined&&n.type!=="default"){return}if(!this.disableSort&&this.state._allowMultiSort&&typeof n.compareFn==="function"&&n.key){const t=this.sortData.findIndex((t=>t.key===n.key));if(t>=0){return t+1}}}handleSort({key:n}){var t,e;const i=(t=this.state._headers.horizontal)!==null&&t!==void 0?t:[];const o=(e=this.state._headers.vertical)!==null&&e!==void 0?e:[];const l=[];for(const n of i){if(Array.isArray(n)){l.push(...n)}}for(const n of o){if(Array.isArray(n)){l.push(...n)}}const a=l.find((t=>t.key===n));if(a){this.changeCellSort(a)}}getSelectedData(n){var t;const e=this.state._selection;if(e){const i=(t=e.keyPropertyName)!==null&&t!==void 0?t:"id";const o=new Set(n.map(String));const l=this.state._sortedData.filter((n=>o.has(String(n[i]))));if(i)return l}return null}handleSelectionChange(n,t){var e;const i=this.state._selection;if(i)this.state=Object.assign(Object.assign({},this.state),{_selection:Object.assign(Object.assign({},i),{selectedKeys:t})});const o=this.getSelectedData(t);if(typeof((e=this.state._on)===null||e===void 0?void 0:e[w.onSelectionChange])==="function"){this.state._on[w.onSelectionChange](n,o)}if(this.host){S(this.host,z.selectionChange,o)}}async getSelection(){var n;const t=((n=this.state._selection)===null||n===void 0?void 0:n.selectedKeys)||[];return this.getSelectedData(t)}async resetSort(){this.initializeSortFromHeaders(this.state._headers);this.updateSortedData()}render(){var n,i,o,a,s,r;const c=this.selectDisplayedData(this.state._sortedData,this.showPagination?(i=(n=this.state._pagination)===null||n===void 0?void 0:n._pageSize)!==null&&i!==void 0?i:10:this.state._sortedData.length,this.state._pagination._page||1);const h=this._paginationPosition==="top"||this._paginationPosition==="both"?this.renderPagination("top"):null;const d=this._paginationPosition==="bottom"||this._paginationPosition==="both"?this.renderPagination("bottom"):null;const f={horizontal:(a=(o=this.state._headers.horizontal)===null||o===void 0?void 0:o.map((n=>n.map((n=>Object.assign(Object.assign({},n),{sortDirection:this.getHeaderCellSortState(n),sortOrder:this.getHeaderCellSortOrder(n)}))))))!==null&&a!==void 0?a:[],vertical:(r=(s=this.state._headers.vertical)===null||s===void 0?void 0:s.map((n=>n.map((n=>Object.assign(Object.assign({},n),{sortDirection:this.getHeaderCellSortState(n),sortOrder:this.getHeaderCellSortOrder(n)}))))))!==null&&r!==void 0?r:[]};return t(e,{key:"b0bcf91837e687037e9b5665e39f6fb73bba2552",class:"kol-table-stateful"},this.pageEndSlice>0&&this.showPagination&&h,t(l,{key:"e66a607e7596b367b452e08762f2205a335818f0",externalLabelElements:this.resolvedElements,ref:this.catchRef,_data:c,_fixedCols:this._fixedCols,_headerCells:f,_label:this.state._label,_dataFoot:this.state._dataFoot,_on:{onSort:(n,t)=>{this.handleSort(t)},onSelectionChange:(n,t)=>{this.handleSelectionChange(n,t)}},_selection:this.state._selection,_hasSettingsMenu:this.state._hasSettingsMenu,_variant:this._variant}),this.pageEndSlice>0&&this.showPagination&&d)}get host(){return i(this)}static get watchers(){return{_ariaLabelledby:["validateAriaLabelledby"],_allowMultiSort:["validateAllowMultiSort"],_data:["validateData"],_dataFoot:["validateDataFoot"],_fixedCols:["validateFixedCols"],_paginationPosition:["validatePaginationPosition"],_hasSettingsMenu:["validateHasSettingsMenu"],_headers:["validateHeaders"],_label:["validateLabel"],_selection:["validateSelection"],_on:["validateOn"],_pagination:["validatePagination"]}}};D.style={default:T};export{D as kol_table_stateful};
//# sourceMappingURL=kol-table-stateful.entry.js.map