@inglorious/web 2.5.0 → 2.6.1

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,232 @@
1
+ import type { TemplateResult } from "lit-html"
2
+ import type { Api } from "./mount"
3
+
4
+ /**
5
+ * Represents a column definition for the table.
6
+ */
7
+ export interface TableColumn {
8
+ /** The unique identifier for the column (usually matches a property in the data). */
9
+ id: string
10
+ /** The display label for the column header. */
11
+ title: string
12
+ /** The type of data in the column. */
13
+ type?: "string" | "number" | "boolean" | "date"
14
+ /** Whether the column is sortable. */
15
+ isSortable?: boolean
16
+ /** Whether the column is filterable. */
17
+ isFilterable?: boolean
18
+ /** Filter configuration. */
19
+ filter?: {
20
+ type: "text" | "number" | "range" | "select" | "date" | "time" | "datetime"
21
+ options?: any[]
22
+ [key: string]: any
23
+ }
24
+ /** The width of the column. */
25
+ width?: number
26
+ /** Optional formatter key or function. */
27
+ formatter?: string | ((value: any) => any)
28
+ /** Custom sort function. */
29
+ sortFn?: (a: any, b: any) => number
30
+ /** Custom filter function. */
31
+ filterFn?: (row: any, filterValue: any) => boolean
32
+ /** Custom format function. */
33
+ format?: (value: any) => string
34
+ /** Any other custom properties. */
35
+ [key: string]: any
36
+ }
37
+
38
+ /**
39
+ * Represents the state of a table entity.
40
+ */
41
+ export interface TableEntity<T = any> {
42
+ /** A unique identifier for the table entity. */
43
+ id: string | number
44
+ /** The entity type. */
45
+ type: string
46
+ /** The data array to display. */
47
+ data: T[]
48
+ /** The column definitions. */
49
+ columns: TableColumn[]
50
+ /** Sorting state. */
51
+ sorts: { column: string; direction: "asc" | "desc" }[]
52
+ /** Filtering state. */
53
+ filters: Record<string, any>
54
+ /** Search state. */
55
+ search: { value: string } | null
56
+ /** Selected row IDs. */
57
+ selection: (string | number)[]
58
+ /** Pagination state. */
59
+ pagination: { page: number; pageSize: number } | null
60
+ /** Whether multi-select is enabled. */
61
+ isMultiSelect: boolean
62
+ /** Any other custom properties. */
63
+ [key: string]: any
64
+ }
65
+
66
+ /**
67
+ * The table type implementation.
68
+ */
69
+ export declare const table: {
70
+ /**
71
+ * Initializes the table entity with default state.
72
+ * @param entity The table entity.
73
+ */
74
+ create(entity: TableEntity): void
75
+
76
+ /**
77
+ * Toggles sorting for a specific column.
78
+ * @param entity The table entity.
79
+ * @param columnId The ID of the column to sort by.
80
+ */
81
+ sortChange(entity: TableEntity, columnId: string): void
82
+
83
+ /**
84
+ * Clears all active sorts.
85
+ * @param entity The table entity.
86
+ */
87
+ sortsClear(entity: TableEntity): void
88
+
89
+ /**
90
+ * Updates the filter value for a specific column.
91
+ * @param entity The table entity.
92
+ * @param payload The filter change payload containing columnId and value.
93
+ */
94
+ filterChange(
95
+ entity: TableEntity,
96
+ payload: { columnId: string; value: any },
97
+ ): void
98
+
99
+ /**
100
+ * Clears all active filters.
101
+ * @param entity The table entity.
102
+ */
103
+ filtersClear(entity: TableEntity): void
104
+
105
+ /**
106
+ * Updates the global search term.
107
+ * @param entity The table entity.
108
+ * @param search The new search string.
109
+ */
110
+ searchChange(entity: TableEntity, search: string): void
111
+
112
+ /**
113
+ * Changes the current page index.
114
+ * @param entity The table entity.
115
+ * @param page The new page index (0-based).
116
+ */
117
+ pageChange(entity: TableEntity, page: number): void
118
+
119
+ /**
120
+ * Moves to the next page.
121
+ * @param entity The table entity.
122
+ */
123
+ pageNext(entity: TableEntity): void
124
+
125
+ /**
126
+ * Moves to the previous page.
127
+ * @param entity The table entity.
128
+ */
129
+ pagePrev(entity: TableEntity): void
130
+
131
+ /**
132
+ * Changes the page size (number of items per page).
133
+ * @param entity The table entity.
134
+ * @param pageSize The new page size.
135
+ */
136
+ pageSizeChange(entity: TableEntity, pageSize: number): void
137
+
138
+ /**
139
+ * Selects a specific row.
140
+ * @param entity The table entity.
141
+ * @param rowId The ID of the row to select.
142
+ */
143
+ rowSelect(entity: TableEntity, rowId: string | number): void
144
+
145
+ /**
146
+ * Deselects a specific row.
147
+ * @param entity The table entity.
148
+ * @param rowId The ID of the row to deselect.
149
+ */
150
+ rowDeselect(entity: TableEntity, rowId: string | number): void
151
+
152
+ /**
153
+ * Toggles selection for a specific row.
154
+ * @param entity The table entity.
155
+ * @param rowId The ID of the row to toggle.
156
+ */
157
+ rowToggle(entity: TableEntity, rowId: string | number): void
158
+
159
+ /**
160
+ * Toggles selection for all currently visible rows.
161
+ * @param entity The table entity.
162
+ */
163
+ rowsToggleAll(entity: TableEntity): void
164
+
165
+ /**
166
+ * Selects all currently visible rows.
167
+ * @param entity The table entity.
168
+ */
169
+ rowsSelectAll(entity: TableEntity): void
170
+
171
+ /**
172
+ * Clears the current row selection.
173
+ * @param entity The table entity.
174
+ */
175
+ selectionClear(entity: TableEntity): void
176
+
177
+ /**
178
+ * Renders the table component.
179
+ * @param entity The table entity.
180
+ * @param api The store API.
181
+ */
182
+ render(entity: TableEntity, api: Api): TemplateResult
183
+
184
+ /**
185
+ * Renders the table header.
186
+ * @param entity The table entity.
187
+ * @param api The store API.
188
+ */
189
+ renderHeader(entity: TableEntity, api: Api): TemplateResult
190
+
191
+ /**
192
+ * Renders the table body.
193
+ * @param entity The table entity.
194
+ * @param api The store API.
195
+ */
196
+ renderBody(entity: TableEntity, api: Api): TemplateResult
197
+
198
+ /**
199
+ * Renders a single row.
200
+ * @param entity The table entity.
201
+ * @param item The data item for the row.
202
+ * @param index The index of the row.
203
+ * @param api The store API.
204
+ */
205
+ renderRow(
206
+ entity: TableEntity,
207
+ item: any,
208
+ index: number,
209
+ api: Api,
210
+ ): TemplateResult
211
+
212
+ /**
213
+ * Renders a single cell.
214
+ * @param entity The table entity.
215
+ * @param item The data item for the row.
216
+ * @param column The column definition.
217
+ * @param api The store API.
218
+ */
219
+ renderCell(
220
+ entity: TableEntity,
221
+ item: any,
222
+ column: TableColumn,
223
+ api: Api,
224
+ ): TemplateResult
225
+
226
+ /**
227
+ * Renders the value of a cell.
228
+ * @param value The raw value from the data item.
229
+ * @param column The column definition.
230
+ */
231
+ renderValue(value: any, column: TableColumn): any
232
+ }