@triptease/tt-table-wrapper 1.0.2

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.
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.TtTableWrapper = void 0;
10
+ const lit_1 = require("lit");
11
+ const decorators_js_1 = require("lit/decorators.js");
12
+ const styles_js_1 = require("./styles.js");
13
+ require("@triptease/tt-paginator");
14
+ const ARIA_SORT_MAP = {
15
+ asc: 'ascending',
16
+ desc: 'descending',
17
+ none: '',
18
+ };
19
+ const NEXT_DIRECTION = {
20
+ none: 'asc',
21
+ asc: 'desc',
22
+ desc: 'none',
23
+ };
24
+ class TtTableWrapper extends lit_1.LitElement {
25
+ constructor() {
26
+ super(...arguments);
27
+ this.totalRows = 0;
28
+ this.pageSize = 10;
29
+ this.sortState = { key: '', direction: 'none' };
30
+ this.headerClickHandlers = new Map();
31
+ }
32
+ render() {
33
+ return (0, lit_1.html) `
34
+ <slot @slotchange=${this.handleSlotChange}></slot>
35
+ <div class="pagination-row">
36
+ <tt-paginator total-rows=${this.totalRows} page-size=${this.pageSize}></tt-paginator>
37
+ </div>
38
+ `;
39
+ }
40
+ disconnectedCallback() {
41
+ super.disconnectedCallback();
42
+ this.cleanupHandlers();
43
+ }
44
+ handleSlotChange() {
45
+ this.cleanupHandlers();
46
+ this.sortState = { key: '', direction: 'none' };
47
+ const headers = this.querySelectorAll('th[data-sort-key]');
48
+ for (const header of headers) {
49
+ const handler = () => this.handleSortClick(header);
50
+ this.headerClickHandlers.set(header, handler);
51
+ header.addEventListener('click', handler);
52
+ }
53
+ }
54
+ handleSortClick(header) {
55
+ const key = header.dataset.sortKey;
56
+ const isSameColumn = key === this.sortState.key;
57
+ const direction = isSameColumn ? NEXT_DIRECTION[this.sortState.direction] : 'asc';
58
+ this.clearAriaSortFromAll();
59
+ if (direction !== 'none') {
60
+ header.setAttribute('aria-sort', ARIA_SORT_MAP[direction]);
61
+ }
62
+ this.sortState = { key, direction };
63
+ this.dispatchEvent(new CustomEvent('sort-change', {
64
+ detail: { key, direction },
65
+ bubbles: true,
66
+ composed: true,
67
+ }));
68
+ }
69
+ clearAriaSortFromAll() {
70
+ const headers = this.querySelectorAll('th[aria-sort]');
71
+ for (const header of headers) {
72
+ header.removeAttribute('aria-sort');
73
+ }
74
+ }
75
+ cleanupHandlers() {
76
+ for (const [header, handler] of this.headerClickHandlers) {
77
+ header.removeEventListener('click', handler);
78
+ }
79
+ this.headerClickHandlers.clear();
80
+ }
81
+ }
82
+ exports.TtTableWrapper = TtTableWrapper;
83
+ TtTableWrapper.styles = styles_js_1.styles;
84
+ __decorate([
85
+ (0, decorators_js_1.property)({ type: Number, attribute: 'total-rows' })
86
+ ], TtTableWrapper.prototype, "totalRows", void 0);
87
+ __decorate([
88
+ (0, decorators_js_1.property)({ type: Number, attribute: 'page-size' })
89
+ ], TtTableWrapper.prototype, "pageSize", void 0);
90
+ //# sourceMappingURL=TtTableWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TtTableWrapper.js","sourceRoot":"","sources":["../../../src/TtTableWrapper.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6BAAuC;AACvC,qDAA6C;AAC7C,2CAAqC;AAErC,mCAAiC;AAEjC,MAAM,aAAa,GAAkC;IACnD,GAAG,EAAE,WA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Y,EAAE,CAAC;iDACtC;AAGd;IADC,IAAA,wBAAQ,EAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;gDACrC","sourcesContent":["import { html, LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { styles } from './styles.js';\nimport type { SortDirection, SortState } from './types.js';\nimport '@triptease/tt-paginator';\n\nconst ARIA_SORT_MAP: Record<SortDirection, string> = {\n asc: 'ascending',\n desc: 'descending',\n none: '',\n};\n\nconst NEXT_DIRECTION: Record<SortDirection, SortDirection> = {\n none: 'asc',\n asc: 'desc',\n desc: 'none',\n};\n\nexport class TtTableWrapper extends LitElement {\n static styles = styles;\n\n @property({ type: Number, attribute: 'total-rows' })\n totalRows = 0;\n\n @property({ type: Number, attribute: 'page-size' })\n pageSize = 10;\n\n private sortState: SortState = { key: '', direction: 'none' };\n private headerClickHandlers = new Map<HTMLElement, () => void>();\n\n render() {\n return html`\n <slot @slotchange=${this.handleSlotChange}></slot>\n <div class=\"pagination-row\">\n <tt-paginator total-rows=${this.totalRows} page-size=${this.pageSize}></tt-paginator>\n </div>\n `;\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n this.cleanupHandlers();\n }\n\n private handleSlotChange() {\n this.cleanupHandlers();\n this.sortState = { key: '', direction: 'none' };\n\n const headers = this.querySelectorAll<HTMLElement>('th[data-sort-key]');\n for (const header of headers) {\n const handler = () => this.handleSortClick(header);\n this.headerClickHandlers.set(header, handler);\n header.addEventListener('click', handler);\n }\n }\n\n private handleSortClick(header: HTMLElement) {\n const key = header.dataset.sortKey!;\n const isSameColumn = key === this.sortState.key;\n\n const direction = isSameColumn ? NEXT_DIRECTION[this.sortState.direction] : 'asc';\n\n this.clearAriaSortFromAll();\n\n if (direction !== 'none') {\n header.setAttribute('aria-sort', ARIA_SORT_MAP[direction]);\n }\n\n this.sortState = { key, direction };\n\n this.dispatchEvent(\n new CustomEvent('sort-change', {\n detail: { key, direction },\n bubbles: true,\n composed: true,\n })\n );\n }\n\n private clearAriaSortFromAll() {\n const headers = this.querySelectorAll('th[aria-sort]');\n for (const header of headers) {\n header.removeAttribute('aria-sort');\n }\n }\n\n private cleanupHandlers() {\n for (const [header, handler] of this.headerClickHandlers) {\n header.removeEventListener('click', handler);\n }\n this.headerClickHandlers.clear();\n }\n}\n"]}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.TtTableWrapper = void 0;
18
+ var tt_table_wrapper_js_1 = require("./tt-table-wrapper.js");
19
+ Object.defineProperty(exports, "TtTableWrapper", { enumerable: true, get: function () { return tt_table_wrapper_js_1.TtTableWrapper; } });
20
+ __exportStar(require("./types.js"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,6DAAuD;AAA9C,qHAAA,cAAc,OAAA;AACvB,6CAA2B","sourcesContent":["export { TtTableWrapper } from './tt-table-wrapper.js';\nexport * from './types.js';\n"]}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.styles = void 0;
4
+ const lit_1 = require("lit");
5
+ const lit_2 = require("@triptease/stylesheet/lit");
6
+ exports.styles = [
7
+ lit_2.styles,
8
+ (0, lit_1.css) `
9
+ :host {
10
+ display: block;
11
+ }
12
+
13
+ .pagination-row {
14
+ display: flex;
15
+ justify-content: flex-end;
16
+ padding-top: var(--space-scale-1);
17
+ }
18
+ `,
19
+ ];
20
+ //# sourceMappingURL=styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../src/styles.ts"],"names":[],"mappings":";;;AAAA,6BAA0B;AAC1B,mDAAiE;AAEpD,QAAA,MAAM,GAAG;IACpB,YAAU;IACV,IAAA,SAAG,EAAA;;;;;;;;;;GAUF;CACF,CAAC","sourcesContent":["import { css } from 'lit';\nimport { styles as baseStyles } from '@triptease/stylesheet/lit';\n\nexport const styles = [\n baseStyles,\n css`\n :host {\n display: block;\n }\n\n .pagination-row {\n display: flex;\n justify-content: flex-end;\n padding-top: var(--space-scale-1);\n }\n `,\n];\n"]}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TtTableWrapper = void 0;
4
+ const TtTableWrapper_js_1 = require("./TtTableWrapper.js");
5
+ Object.defineProperty(exports, "TtTableWrapper", { enumerable: true, get: function () { return TtTableWrapper_js_1.TtTableWrapper; } });
6
+ if (typeof window !== 'undefined') {
7
+ if (!window.customElements.get('tt-table-wrapper')) {
8
+ window.customElements.define('tt-table-wrapper', TtTableWrapper_js_1.TtTableWrapper);
9
+ }
10
+ }
11
+ //# sourceMappingURL=tt-table-wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tt-table-wrapper.js","sourceRoot":"","sources":["../../../src/tt-table-wrapper.ts"],"names":[],"mappings":";;;AAAA,2DAAqD;AAQ5C,+FARA,kCAAc,OAQA;AANvB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACnD,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,kBAAkB,EAAE,kCAAc,CAAC,CAAC;IACnE,CAAC;AACH,CAAC","sourcesContent":["import { TtTableWrapper } from './TtTableWrapper.js';\n\nif (typeof window !== 'undefined') {\n if (!window.customElements.get('tt-table-wrapper')) {\n window.customElements.define('tt-table-wrapper', TtTableWrapper);\n }\n}\n\nexport { TtTableWrapper };\n"]}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { TtTableWrapper } from './TtTableWrapper.js';\n\nexport type SortDirection = 'asc' | 'desc' | 'none';\n\nexport interface SortState {\n key: string;\n direction: SortDirection;\n}\n\ninterface TtTableWrapperExternalAttributes {\n 'total-rows'?: number;\n 'page-size'?: number;\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'tt-table-wrapper': TtTableWrapper;\n }\n namespace JSX {\n interface IntrinsicElements {\n 'tt-table-wrapper': TtTableWrapperExternalAttributes & { children: Element; style?: string };\n }\n }\n\n namespace React {\n namespace JSX {\n interface IntrinsicElements {\n 'tt-table-wrapper': TtTableWrapperExternalAttributes & {\n children: React.ReactNode;\n key?: string;\n ref?: React.Ref<unknown>;\n style?: React.CSSProperties;\n };\n }\n }\n }\n}\n"]}
@@ -0,0 +1,15 @@
1
+ import { LitElement } from 'lit';
2
+ import '@triptease/tt-paginator';
3
+ export declare class TtTableWrapper extends LitElement {
4
+ static styles: import("lit").CSSResult[];
5
+ totalRows: number;
6
+ pageSize: number;
7
+ private sortState;
8
+ private headerClickHandlers;
9
+ render(): import("lit-html").TemplateResult<1>;
10
+ disconnectedCallback(): void;
11
+ private handleSlotChange;
12
+ private handleSortClick;
13
+ private clearAriaSortFromAll;
14
+ private cleanupHandlers;
15
+ }
@@ -0,0 +1,86 @@
1
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
6
+ };
7
+ import { html, LitElement } from 'lit';
8
+ import { property } from 'lit/decorators.js';
9
+ import { styles } from './styles.js';
10
+ import '@triptease/tt-paginator';
11
+ const ARIA_SORT_MAP = {
12
+ asc: 'ascending',
13
+ desc: 'descending',
14
+ none: '',
15
+ };
16
+ const NEXT_DIRECTION = {
17
+ none: 'asc',
18
+ asc: 'desc',
19
+ desc: 'none',
20
+ };
21
+ export class TtTableWrapper extends LitElement {
22
+ constructor() {
23
+ super(...arguments);
24
+ this.totalRows = 0;
25
+ this.pageSize = 10;
26
+ this.sortState = { key: '', direction: 'none' };
27
+ this.headerClickHandlers = new Map();
28
+ }
29
+ render() {
30
+ return html `
31
+ <slot @slotchange=${this.handleSlotChange}></slot>
32
+ <div class="pagination-row">
33
+ <tt-paginator total-rows=${this.totalRows} page-size=${this.pageSize}></tt-paginator>
34
+ </div>
35
+ `;
36
+ }
37
+ disconnectedCallback() {
38
+ super.disconnectedCallback();
39
+ this.cleanupHandlers();
40
+ }
41
+ handleSlotChange() {
42
+ this.cleanupHandlers();
43
+ this.sortState = { key: '', direction: 'none' };
44
+ const headers = this.querySelectorAll('th[data-sort-key]');
45
+ for (const header of headers) {
46
+ const handler = () => this.handleSortClick(header);
47
+ this.headerClickHandlers.set(header, handler);
48
+ header.addEventListener('click', handler);
49
+ }
50
+ }
51
+ handleSortClick(header) {
52
+ const key = header.dataset.sortKey;
53
+ const isSameColumn = key === this.sortState.key;
54
+ const direction = isSameColumn ? NEXT_DIRECTION[this.sortState.direction] : 'asc';
55
+ this.clearAriaSortFromAll();
56
+ if (direction !== 'none') {
57
+ header.setAttribute('aria-sort', ARIA_SORT_MAP[direction]);
58
+ }
59
+ this.sortState = { key, direction };
60
+ this.dispatchEvent(new CustomEvent('sort-change', {
61
+ detail: { key, direction },
62
+ bubbles: true,
63
+ composed: true,
64
+ }));
65
+ }
66
+ clearAriaSortFromAll() {
67
+ const headers = this.querySelectorAll('th[aria-sort]');
68
+ for (const header of headers) {
69
+ header.removeAttribute('aria-sort');
70
+ }
71
+ }
72
+ cleanupHandlers() {
73
+ for (const [header, handler] of this.headerClickHandlers) {
74
+ header.removeEventListener('click', handler);
75
+ }
76
+ this.headerClickHandlers.clear();
77
+ }
78
+ }
79
+ TtTableWrapper.styles = styles;
80
+ __decorate([
81
+ property({ type: Number, attribute: 'total-rows' })
82
+ ], TtTableWrapper.prototype, "totalRows", void 0);
83
+ __decorate([
84
+ property({ type: Number, attribute: 'page-size' })
85
+ ], TtTableWrapper.prototype, "pageSize", void 0);
86
+ //# sourceMappingURL=TtTableWrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TtTableWrapper.js","sourceRoot":"","sources":["../../../src/TtTableWrapper.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,KAAK,CAAC;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAErC,OAAO,yBAAyB,CAAC;AAEjC,MAAM,aAAa,GAAkC;IACnD,GAAG,EAAE,WAAW;IAChB,IAAI,EAAE,YAAY;IAClB,IAAI,EAAE,EAAE;CACT,CAAC;AAEF,MAAM,cAAc,GAAyC;IAC3D,IAAI,EAAE,KAAK;IACX,GAAG,EAAE,MAAM;IACX,IAAI,EAAE,MAAM;CACb,CAAC;AAEF,MAAM,OAAO,cAAe,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AAC,CAAC,CAAC,KAAK,CAAC;QAElF,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAE5B,IAAI,SAAS,KAAK,MAAM,EAAE,CAAC;YACzB,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,aAAa,CAAC,SAAS,CAAC,CAAC,CAAC;QAC7D,CAAC;QAED,IAAI,CAAC,SAAS,GAAG,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;QAEpC,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,aAAa,EAAE;YAC7B,MAAM,EAAE,EAAE,GAAG,EAAE,SAAS,EAAE;YAC1B,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,IAAI;SACf,CAAC,CACH,CAAC;IACJ,CAAC;IAEO,oBAAoB;QAC1B,MAAM,OAAO,GAAG,IAAI,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAC;QACvD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;YAC7B,MAAM,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAEO,eAAe;QACrB,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACzD,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC;QACD,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,CAAC;IACnC,CAAC;;AAxEM,qBAAM,GAAG,MAAM,AAAT,CAAU;AAGvB;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,YAAY,EAAE,CAAC;iDACtC;AAGd;IADC,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;gDACrC","sourcesContent":["import { html, LitElement } from 'lit';\nimport { property } from 'lit/decorators.js';\nimport { styles } from './styles.js';\nimport type { SortDirection, SortState } from './types.js';\nimport '@triptease/tt-paginator';\n\nconst ARIA_SORT_MAP: Record<SortDirection, string> = {\n asc: 'ascending',\n desc: 'descending',\n none: '',\n};\n\nconst NEXT_DIRECTION: Record<SortDirection, SortDirection> = {\n none: 'asc',\n asc: 'desc',\n desc: 'none',\n};\n\nexport class TtTableWrapper extends LitElement {\n static styles = styles;\n\n @property({ type: Number, attribute: 'total-rows' })\n totalRows = 0;\n\n @property({ type: Number, attribute: 'page-size' })\n pageSize = 10;\n\n private sortState: SortState = { key: '', direction: 'none' };\n private headerClickHandlers = new Map<HTMLElement, () => void>();\n\n render() {\n return html`\n <slot @slotchange=${this.handleSlotChange}></slot>\n <div class=\"pagination-row\">\n <tt-paginator total-rows=${this.totalRows} page-size=${this.pageSize}></tt-paginator>\n </div>\n `;\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n this.cleanupHandlers();\n }\n\n private handleSlotChange() {\n this.cleanupHandlers();\n this.sortState = { key: '', direction: 'none' };\n\n const headers = this.querySelectorAll<HTMLElement>('th[data-sort-key]');\n for (const header of headers) {\n const handler = () => this.handleSortClick(header);\n this.headerClickHandlers.set(header, handler);\n header.addEventListener('click', handler);\n }\n }\n\n private handleSortClick(header: HTMLElement) {\n const key = header.dataset.sortKey!;\n const isSameColumn = key === this.sortState.key;\n\n const direction = isSameColumn ? NEXT_DIRECTION[this.sortState.direction] : 'asc';\n\n this.clearAriaSortFromAll();\n\n if (direction !== 'none') {\n header.setAttribute('aria-sort', ARIA_SORT_MAP[direction]);\n }\n\n this.sortState = { key, direction };\n\n this.dispatchEvent(\n new CustomEvent('sort-change', {\n detail: { key, direction },\n bubbles: true,\n composed: true,\n })\n );\n }\n\n private clearAriaSortFromAll() {\n const headers = this.querySelectorAll('th[aria-sort]');\n for (const header of headers) {\n header.removeAttribute('aria-sort');\n }\n }\n\n private cleanupHandlers() {\n for (const [header, handler] of this.headerClickHandlers) {\n header.removeEventListener('click', handler);\n }\n this.headerClickHandlers.clear();\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export { TtTableWrapper } from './tt-table-wrapper.js';
2
+ export * from './types.js';
@@ -0,0 +1,3 @@
1
+ export { TtTableWrapper } from './tt-table-wrapper.js';
2
+ export * from './types.js';
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,cAAc,YAAY,CAAC","sourcesContent":["export { TtTableWrapper } from './tt-table-wrapper.js';\nexport * from './types.js';\n"]}
@@ -0,0 +1 @@
1
+ export declare const styles: import("lit").CSSResult[];
@@ -0,0 +1,17 @@
1
+ import { css } from 'lit';
2
+ import { styles as baseStyles } from '@triptease/stylesheet/lit';
3
+ export const styles = [
4
+ baseStyles,
5
+ css `
6
+ :host {
7
+ display: block;
8
+ }
9
+
10
+ .pagination-row {
11
+ display: flex;
12
+ justify-content: flex-end;
13
+ padding-top: var(--space-scale-1);
14
+ }
15
+ `,
16
+ ];
17
+ //# sourceMappingURL=styles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styles.js","sourceRoot":"","sources":["../../../src/styles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAC1B,OAAO,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEjE,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,UAAU;IACV,GAAG,CAAA;;;;;;;;;;GAUF;CACF,CAAC","sourcesContent":["import { css } from 'lit';\nimport { styles as baseStyles } from '@triptease/stylesheet/lit';\n\nexport const styles = [\n baseStyles,\n css`\n :host {\n display: block;\n }\n\n .pagination-row {\n display: flex;\n justify-content: flex-end;\n padding-top: var(--space-scale-1);\n }\n `,\n];\n"]}
@@ -0,0 +1,2 @@
1
+ import { TtTableWrapper } from './TtTableWrapper.js';
2
+ export { TtTableWrapper };
@@ -0,0 +1,8 @@
1
+ import { TtTableWrapper } from './TtTableWrapper.js';
2
+ if (typeof window !== 'undefined') {
3
+ if (!window.customElements.get('tt-table-wrapper')) {
4
+ window.customElements.define('tt-table-wrapper', TtTableWrapper);
5
+ }
6
+ }
7
+ export { TtTableWrapper };
8
+ //# sourceMappingURL=tt-table-wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tt-table-wrapper.js","sourceRoot":"","sources":["../../../src/tt-table-wrapper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;IAClC,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACnD,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,kBAAkB,EAAE,cAAc,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AAED,OAAO,EAAE,cAAc,EAAE,CAAC","sourcesContent":["import { TtTableWrapper } from './TtTableWrapper.js';\n\nif (typeof window !== 'undefined') {\n if (!window.customElements.get('tt-table-wrapper')) {\n window.customElements.define('tt-table-wrapper', TtTableWrapper);\n }\n}\n\nexport { TtTableWrapper };\n"]}
@@ -0,0 +1,36 @@
1
+ import { TtTableWrapper } from './TtTableWrapper.js';
2
+ export type SortDirection = 'asc' | 'desc' | 'none';
3
+ export interface SortState {
4
+ key: string;
5
+ direction: SortDirection;
6
+ }
7
+ interface TtTableWrapperExternalAttributes {
8
+ 'total-rows'?: number;
9
+ 'page-size'?: number;
10
+ }
11
+ declare global {
12
+ interface HTMLElementTagNameMap {
13
+ 'tt-table-wrapper': TtTableWrapper;
14
+ }
15
+ namespace JSX {
16
+ interface IntrinsicElements {
17
+ 'tt-table-wrapper': TtTableWrapperExternalAttributes & {
18
+ children: Element;
19
+ style?: string;
20
+ };
21
+ }
22
+ }
23
+ namespace React {
24
+ namespace JSX {
25
+ interface IntrinsicElements {
26
+ 'tt-table-wrapper': TtTableWrapperExternalAttributes & {
27
+ children: React.ReactNode;
28
+ key?: string;
29
+ ref?: React.Ref<unknown>;
30
+ style?: React.CSSProperties;
31
+ };
32
+ }
33
+ }
34
+ }
35
+ }
36
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import { TtTableWrapper } from './TtTableWrapper.js';\n\nexport type SortDirection = 'asc' | 'desc' | 'none';\n\nexport interface SortState {\n key: string;\n direction: SortDirection;\n}\n\ninterface TtTableWrapperExternalAttributes {\n 'total-rows'?: number;\n 'page-size'?: number;\n}\n\ndeclare global {\n interface HTMLElementTagNameMap {\n 'tt-table-wrapper': TtTableWrapper;\n }\n namespace JSX {\n interface IntrinsicElements {\n 'tt-table-wrapper': TtTableWrapperExternalAttributes & { children: Element; style?: string };\n }\n }\n\n namespace React {\n namespace JSX {\n interface IntrinsicElements {\n 'tt-table-wrapper': TtTableWrapperExternalAttributes & {\n children: React.ReactNode;\n key?: string;\n ref?: React.Ref<unknown>;\n style?: React.CSSProperties;\n };\n }\n }\n }\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@triptease/tt-table-wrapper",
3
+ "description": "Table wrapper web component with sorting and pagination",
4
+ "license": "MIT",
5
+ "author": "@triptease",
6
+ "version": "1.0.2",
7
+ "type": "module",
8
+ "main": "dist/esm/src/index.js",
9
+ "module": "dist/esm/src/index.js",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/esm/src/index.d.ts",
13
+ "import": "./dist/esm/src/index.js",
14
+ "require": "./dist/cjs/src/index.js"
15
+ },
16
+ "./types": {
17
+ "types": "./dist/esm/src/types.d.ts",
18
+ "import": "./dist/esm/src/types.js",
19
+ "require": "./dist/cjs/src/types.js"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist/esm",
24
+ "dist/cjs"
25
+ ],
26
+ "scripts": {
27
+ "analyze": "cem analyze --litelement",
28
+ "build": "yarn build:node && yarn build:web && yarn analyze --exclude dist",
29
+ "build:esm": "tsc",
30
+ "build:cjs": "tsc -p tsconfig.cjs.json && node ../../scripts/create-cjs-package.mjs",
31
+ "build:node": "yarn build:esm && yarn build:cjs",
32
+ "build:node:watch": "tsc --watch",
33
+ "build:web": "node ../../scripts/esbuild.mjs",
34
+ "prepublish": "tsc && yarn analyze --exclude dist",
35
+ "test": "yarn playwright install && vitest run --config=./vitest.browser.config.mjs",
36
+ "test:watch": "vitest --config=./vitest.browser.config.mjs"
37
+ },
38
+ "dependencies": {
39
+ "@triptease/stylesheet": "2.1.1",
40
+ "@triptease/tt-paginator": "1.0.3",
41
+ "lit": "^3.1.4"
42
+ },
43
+ "devDependencies": {
44
+ "@custom-elements-manifest/analyzer": "^0.10.3",
45
+ "concurrently": "^8.2.2",
46
+ "playwright": "^1.57.0",
47
+ "tslib": "^2.6.3",
48
+ "typescript": "^5.5.3"
49
+ },
50
+ "customElements": "custom-elements.json",
51
+ "publishConfig": {
52
+ "access": "public"
53
+ }
54
+ }