@kodaris/krubble-components 1.0.8 → 1.0.10

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,253 @@
1
+ import { LitElement, TemplateResult } from 'lit';
2
+ import '../button/button.js';
3
+ export interface KRSolrSort {
4
+ sortBy: string;
5
+ sortDirection: 'asc' | 'desc';
6
+ }
7
+ export interface KRSolrFilter {
8
+ name: string;
9
+ compare?: string;
10
+ value?: string;
11
+ values?: string[];
12
+ boost?: number;
13
+ fuzzy?: number;
14
+ operation: 'EXPRESSION' | 'AND' | 'OR' | string;
15
+ not?: boolean;
16
+ tagged?: boolean;
17
+ and?: boolean;
18
+ }
19
+ export interface KRSolrFacet {
20
+ name: string;
21
+ limit?: number;
22
+ sort?: 'count' | 'index';
23
+ offset?: number;
24
+ minimumCount?: number;
25
+ start?: string;
26
+ end?: string;
27
+ gap?: string;
28
+ hardened?: string;
29
+ include?: string;
30
+ other?: string;
31
+ missing?: boolean;
32
+ type?: 'FIELD' | 'RANGE' | 'QUERY';
33
+ contains?: string;
34
+ }
35
+ export interface KRSolrRequest {
36
+ page: number;
37
+ size: number;
38
+ sorts?: KRSolrSort[];
39
+ filterFields?: KRSolrFilter[];
40
+ queryFields?: KRSolrFilter[];
41
+ facetFields?: KRSolrFacet[];
42
+ }
43
+ export interface KRSolrResponse {
44
+ success: boolean;
45
+ code: number;
46
+ messages?: string[];
47
+ errors?: string[];
48
+ data: {
49
+ size: number;
50
+ number: number;
51
+ totalElements: number;
52
+ totalPages: number;
53
+ isLast: boolean;
54
+ isFirst: boolean;
55
+ hasPrevious: boolean;
56
+ hasNext: boolean;
57
+ numberOfElements: number;
58
+ offset: number;
59
+ content: Record<string, any>[];
60
+ };
61
+ }
62
+ export type KRTableDataSourceMode = 'solr' | 'db' | 'opensearch';
63
+ /** Configuration for the table's data source. */
64
+ export interface KRTableDataSource {
65
+ /** Data source mode (solr, db, or opensearch) */
66
+ mode?: KRTableDataSourceMode;
67
+ /** Function to fetch data from the server */
68
+ fetch: (params: any) => Promise<any>;
69
+ /** Function to create a new row */
70
+ create?: (row: Record<string, any>) => Promise<Record<string, any>>;
71
+ /** Function to update an existing row */
72
+ update?: (row: Record<string, any>) => Promise<Record<string, any>>;
73
+ /** Function to delete a row */
74
+ delete?: (row: Record<string, any>) => Promise<void>;
75
+ }
76
+ /** Configuration for a table column. */
77
+ export interface KRTableColumn {
78
+ /** Unique column identifier */
79
+ id: string;
80
+ /** Column header text */
81
+ label?: string;
82
+ /** Column width (e.g., '150px', '20%') */
83
+ width?: string;
84
+ /** Minimum column width */
85
+ minWidth?: string;
86
+ /** Sticky position for horizontal scrolling */
87
+ sticky?: 'left' | 'right';
88
+ /** Whether the column is sortable */
89
+ sortable?: boolean;
90
+ /** Whether the column is included in search */
91
+ searchable?: boolean;
92
+ /** Cell content alignment */
93
+ align?: 'left' | 'center' | 'right';
94
+ /** Data type for automatic formatting */
95
+ type?: 'text' | 'number' | 'date' | 'currency' | 'boolean';
96
+ /** Custom render function for cell content */
97
+ render?: (row: any) => TemplateResult;
98
+ }
99
+ /** Configuration for a table action button. */
100
+ export interface KRTableAction {
101
+ /** Unique action identifier */
102
+ id: string;
103
+ /** Action button label */
104
+ label: string;
105
+ }
106
+ /** Main configuration object for the table component. */
107
+ export interface KRTableDef {
108
+ /** Table title displayed in the header */
109
+ title?: string;
110
+ /** Action buttons in the header dropdown */
111
+ actions?: KRTableAction[];
112
+ /** Column definitions (required) */
113
+ columns: KRTableColumn[];
114
+ /** Column IDs to display initially */
115
+ displayedColumns?: string[];
116
+ /** Static data array (alternative to dataSource) */
117
+ data?: Record<string, any>[];
118
+ /** Data source configuration for server-side data */
119
+ dataSource?: KRTableDataSource;
120
+ /** Auto-refresh interval in milliseconds */
121
+ refreshInterval?: number;
122
+ /** Number of rows per page */
123
+ pageSize?: number;
124
+ }
125
+ export declare class KRTable extends LitElement {
126
+ static styles: import("lit").CSSResult[];
127
+ /**
128
+ * Internal flag to switch between scroll edge modes:
129
+ * - 'overlay': Fixed padding with overlay elements that hide content at edges (scrollbar at viewport edge)
130
+ * - 'edge': Padding scrolls with content, allowing table to reach edges when scrolling
131
+ */
132
+ private _scrollStyle;
133
+ private _refreshTimer?;
134
+ private _data;
135
+ private _dataState;
136
+ private _page;
137
+ private _pageSize;
138
+ private _totalItems;
139
+ private _totalPages;
140
+ private _searchQuery;
141
+ private _canScrollLeft;
142
+ private _canScrollRight;
143
+ private _canScrollHorizontal;
144
+ private _columnPickerOpen;
145
+ private _displayedColumns;
146
+ private _columnWidths;
147
+ private _resizing;
148
+ private _resizeObserver;
149
+ private _searchPositionLocked;
150
+ def: KRTableDef;
151
+ connectedCallback(): void;
152
+ disconnectedCallback(): void;
153
+ updated(changedProperties: Map<string, unknown>): void;
154
+ refresh(): void;
155
+ goToPrevPage(): void;
156
+ goToNextPage(): void;
157
+ goToPage(page: number): void;
158
+ /**
159
+ * Fetches data from the API and updates the table.
160
+ * Shows a loading spinner while fetching, then displays rows on success
161
+ * or an error snackbar on failure.
162
+ * Request/response format depends on dataSource.mode (solr, opensearch, db).
163
+ */
164
+ private _fetch;
165
+ /**
166
+ * Sets up auto-refresh so the table automatically fetches fresh data
167
+ * at a regular interval (useful for dashboards, monitoring views).
168
+ * Configured via def.refreshInterval in milliseconds.
169
+ */
170
+ private _initRefresh;
171
+ private _handleSearch;
172
+ /**
173
+ * Updates search position to be centered with equal gaps from title and tools.
174
+ * On first call: resets to flex centering, measures position, then locks with fixed margin.
175
+ * Subsequent calls are ignored unless _searchPositionLocked is reset (e.g., on resize).
176
+ */
177
+ private _updateSearchPosition;
178
+ private _toggleColumnPicker;
179
+ private _toggleColumn;
180
+ private _handleClickOutsideColumnPicker;
181
+ getDisplayedColumns(): KRTableColumn[];
182
+ /**
183
+ * Scroll event handler that updates scroll flags in real-time as user scrolls.
184
+ * Updates shadow indicators to show if more content exists left/right.
185
+ */
186
+ private _handleScroll;
187
+ /**
188
+ * Updates scroll state flags for the table content container.
189
+ * - _canScrollLeft: true if scrolled right (can scroll back left)
190
+ * - _canScrollRight: true if more content exists to the right
191
+ * - _canScrollHorizontal: true if content is wider than container
192
+ * These flags control scroll shadow indicators and CSS classes.
193
+ */
194
+ private _updateScrollFlags;
195
+ private _handleResizeStart;
196
+ private _handleResizeMove;
197
+ private _handleResizeEnd;
198
+ private _handleAction;
199
+ private _renderCellContent;
200
+ /**
201
+ * Returns CSS classes for a header cell based on column config.
202
+ */
203
+ private _getHeaderCellClasses;
204
+ /**
205
+ * Returns CSS classes for a table cell based on column config:
206
+ * - Alignment (center, right)
207
+ * - Sticky positioning (left, right)
208
+ * - Border classes for the last left-sticky or first right-sticky column
209
+ */
210
+ private _getCellClasses;
211
+ /**
212
+ * Returns inline styles for a table cell:
213
+ * - Width (from column config or default 150px)
214
+ * - Min-width (if specified)
215
+ * - Left/right offset for sticky columns (calculated from widths of preceding sticky columns)
216
+ */
217
+ private _getCellStyle;
218
+ /**
219
+ * Renders the pagination controls:
220
+ * - Previous page arrow (disabled on first page)
221
+ * - Range text showing "1-50 of 150" format
222
+ * - Next page arrow (disabled on last page)
223
+ *
224
+ * Hidden when there's no data or all data fits on one page.
225
+ */
226
+ private _renderPagination;
227
+ /**
228
+ * Renders the header toolbar containing:
229
+ * - Title (left)
230
+ * - Search bar with view selector dropdown (center)
231
+ * - Tools (right): page navigation, refresh button, column visibility picker, actions dropdown
232
+ *
233
+ * Hidden when there's no title, no actions, and data fits on one page.
234
+ */
235
+ private _renderHeader;
236
+ /** Renders status message (loading, error, empty) */
237
+ private _renderStatus;
238
+ /** Renders the scrollable data grid with column headers and rows. */
239
+ private _renderTable;
240
+ /**
241
+ * Renders a data table with:
242
+ * - Header bar with title, search input with view selector, and tools (pagination, refresh, column visibility, actions dropdown)
243
+ * - Scrollable grid with sticky header row and optional sticky left/right columns
244
+ * - Loading, error message, or empty state when no data
245
+ */
246
+ render(): TemplateResult<1>;
247
+ }
248
+ declare global {
249
+ interface HTMLElementTagNameMap {
250
+ 'kr-table': KRTable;
251
+ }
252
+ }
253
+ //# sourceMappingURL=table.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../src/table/table.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAa,cAAc,EAAW,MAAM,KAAK,CAAC;AAKrE,OAAO,qBAAqB,CAAC;AAuB7B,MAAM,WAAW,UAAU;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,aAAa,EAAE,KAAK,GAAG,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,YAAY,GAAG,KAAK,GAAG,IAAI,GAAG,MAAM,CAAC;IAChD,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC;IACzB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,IAAI,CAA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