universe-code 0.0.87 → 0.0.89
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.
- package/dist/uiux/index.js +2 -1
- package/dist/uiux/tables/index.js +359 -0
- package/package.json +15 -2
package/dist/uiux/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { UniverseToaster, toaster } from "./toaster";
|
|
1
|
+
export { UniverseToaster, toaster } from "./toaster";
|
|
2
|
+
export { UniverseDataTable } from "./tables";
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
// Inject plain CSS for UniverseDataTable
|
|
2
|
+
const style = document.createElement("style");
|
|
3
|
+
style.textContent = `
|
|
4
|
+
/* Container & Table */
|
|
5
|
+
.udt-container {
|
|
6
|
+
background-color: #fff;
|
|
7
|
+
border-radius: 0 0 0.75rem 0.75rem;
|
|
8
|
+
padding: 20px;
|
|
9
|
+
overflow-x: auto;
|
|
10
|
+
font-size: 14px;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.table-wrapper {
|
|
14
|
+
overflow-x: auto;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.udt-table {
|
|
18
|
+
width: 100%;
|
|
19
|
+
border-collapse: collapse;
|
|
20
|
+
border: 1px solid #d1d5db;
|
|
21
|
+
border-radius: 0.375rem;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
.udt-th {
|
|
25
|
+
text-align: center;
|
|
26
|
+
font-weight: 600;
|
|
27
|
+
padding: 0.5rem 0.75rem;
|
|
28
|
+
min-width: 136px;
|
|
29
|
+
border: var(--tableHeaderBorder, 1px solid #d1d5db);
|
|
30
|
+
background-color: var(--tableHeaderBg, #f3f4f6);
|
|
31
|
+
color: #000;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.udt-td {
|
|
35
|
+
text-align: center;
|
|
36
|
+
padding: 0.5rem 0.75rem;
|
|
37
|
+
border-right: 1px solid #d1d5db;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.udt-table tbody tr {
|
|
41
|
+
border-bottom: 1px solid #d1d5db;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/* Pagination */
|
|
45
|
+
.udt-pagination {
|
|
46
|
+
display: flex;
|
|
47
|
+
flex-wrap: wrap;
|
|
48
|
+
justify-content: space-between;
|
|
49
|
+
align-items: center;
|
|
50
|
+
margin-top: 0.75rem;
|
|
51
|
+
font-size: 14px;
|
|
52
|
+
gap: 0.5rem;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.page-jump {
|
|
56
|
+
display: flex;
|
|
57
|
+
align-items: center;
|
|
58
|
+
gap: 0.3rem;
|
|
59
|
+
font-size: 10px;
|
|
60
|
+
color: #757272;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.jumpto {
|
|
64
|
+
width: 56.67px;
|
|
65
|
+
height: 2rem;
|
|
66
|
+
border: 1px solid #adadad;
|
|
67
|
+
border-radius: 0.3125rem;
|
|
68
|
+
background-color: #f1f1f1;
|
|
69
|
+
color: #6d6d6d;
|
|
70
|
+
text-align: center;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.jumpto:disabled {
|
|
74
|
+
cursor: not-allowed;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.go-btn {
|
|
78
|
+
height: 1.75rem;
|
|
79
|
+
padding: 0 0.75rem;
|
|
80
|
+
background: var(--goButtonBackground, linear-gradient(180deg,#2e4b5e 0%,#243a48 82%));
|
|
81
|
+
color: var(--goButtonColor, #fff);
|
|
82
|
+
font-weight: 600;
|
|
83
|
+
border-radius: var(--goButtonBorderRadius,0.125rem);
|
|
84
|
+
border: none;
|
|
85
|
+
cursor: pointer;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.go-btn:disabled {
|
|
89
|
+
opacity: 0.5;
|
|
90
|
+
cursor: not-allowed;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/* Entries text */
|
|
94
|
+
.entries-text {
|
|
95
|
+
white-space: nowrap;
|
|
96
|
+
text-align: left;
|
|
97
|
+
color: #4b5563;
|
|
98
|
+
font-size: var(--entriesTextFontSize, 10px);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/* Pagination buttons */
|
|
102
|
+
.pagination-buttons {
|
|
103
|
+
display: flex;
|
|
104
|
+
gap: 0.25rem;
|
|
105
|
+
align-items: center;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.pg-btn {
|
|
109
|
+
padding: 0.25rem 0.75rem;
|
|
110
|
+
border-radius: 0.25rem;
|
|
111
|
+
border: var(--paginationButtonBorder, 1px solid #d1d5db);
|
|
112
|
+
background-color: var(--paginationButtonBackground, #fff);
|
|
113
|
+
color: var(--paginationButtonColor, #4b5563);
|
|
114
|
+
cursor: pointer;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.pg-btn:hover:not(:disabled) {
|
|
118
|
+
background-color: #f9fafb;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.pg-btn:disabled {
|
|
122
|
+
background-color: var(--paginationButtonDissableBg,#e5e7eb);
|
|
123
|
+
color: var(--paginationButtonDissableColor, #9ca3af);
|
|
124
|
+
cursor: not-allowed;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.pg-number.active {
|
|
128
|
+
padding: 0.25rem 0.75rem;
|
|
129
|
+
border-radius: var(--paginationNumberBorderRadius, 0.25rem);
|
|
130
|
+
border: var(--paginationNumberBorder, 1px solid #d1d5db);
|
|
131
|
+
background: var(--paginationNumberBackground, linear-gradient(180deg,#2e4b5e 0%,#243a48 82%));
|
|
132
|
+
color: var(--paginationNumberColor, #fff);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.pagination-left{
|
|
136
|
+
display: flex;
|
|
137
|
+
justify-content: space-between;
|
|
138
|
+
align-items: center;
|
|
139
|
+
gap: 1rem;
|
|
140
|
+
width:auto;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.mbl-jump-btn{
|
|
144
|
+
display:none;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* Responsive for mobile pagination */
|
|
148
|
+
@media (max-width: 768px) {
|
|
149
|
+
.page-jump {
|
|
150
|
+
width: auto;
|
|
151
|
+
justify-content: center;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.pagination-left{
|
|
155
|
+
width:100%;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.pagination-buttons {
|
|
159
|
+
width: 100%;
|
|
160
|
+
justify-content: space-between;
|
|
161
|
+
flex-wrap: wrap;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.pg-btn {
|
|
165
|
+
flex: 1;
|
|
166
|
+
margin-bottom: 0.25rem;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
.mbl-jump-btn{
|
|
170
|
+
display:flex;
|
|
171
|
+
}
|
|
172
|
+
.desk-jump-btn{
|
|
173
|
+
display:none;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
@media (max-width: 1024px) {
|
|
177
|
+
.udt-container{
|
|
178
|
+
padding: 10px;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
`;
|
|
182
|
+
document.head.appendChild(style);
|
|
183
|
+
|
|
184
|
+
// UniverseDataTable Class
|
|
185
|
+
class UniverseDataTable {
|
|
186
|
+
constructor({
|
|
187
|
+
container,
|
|
188
|
+
apiData = [],
|
|
189
|
+
columns = [],
|
|
190
|
+
pagination = {},
|
|
191
|
+
jumpToPage = "",
|
|
192
|
+
shouldEnableJumpToPage = false,
|
|
193
|
+
handleJumpToPage = () => { },
|
|
194
|
+
handleKeyPress = () => { },
|
|
195
|
+
handlePageChange = () => { },
|
|
196
|
+
shouldShowPagination = true,
|
|
197
|
+
}) {
|
|
198
|
+
if (!container) throw new Error("UniverseDataTable: container is required");
|
|
199
|
+
|
|
200
|
+
this.container = container;
|
|
201
|
+
this.apiData = apiData;
|
|
202
|
+
this.columns = columns;
|
|
203
|
+
this.pagination = pagination;
|
|
204
|
+
|
|
205
|
+
this.jumpToPage = jumpToPage;
|
|
206
|
+
this.shouldEnableJumpToPage = shouldEnableJumpToPage;
|
|
207
|
+
this.handleJumpToPage = handleJumpToPage;
|
|
208
|
+
this.handleKeyPress = handleKeyPress;
|
|
209
|
+
this.handlePageChange = handlePageChange;
|
|
210
|
+
|
|
211
|
+
this.shouldShowPagination = shouldShowPagination;
|
|
212
|
+
|
|
213
|
+
this.render();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
th(label) {
|
|
217
|
+
return `<th class="udt-th">${label}</th>`;
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
renderRows() {
|
|
221
|
+
if (!this.apiData || this.apiData.length === 0) {
|
|
222
|
+
return `<tr>
|
|
223
|
+
<td colspan="${this.columns.length}" style="text-align:center; padding:1rem; color:#9ca3af;">
|
|
224
|
+
No data available
|
|
225
|
+
</td>
|
|
226
|
+
</tr>`;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
return this.apiData
|
|
230
|
+
.map((s) => `<tr>
|
|
231
|
+
${this.columns
|
|
232
|
+
.map((col) => {
|
|
233
|
+
const val = this.getNestedValue(s, col.key);
|
|
234
|
+
let formatted = val;
|
|
235
|
+
|
|
236
|
+
if (col.format && typeof col.format === "function") {
|
|
237
|
+
if (col.format.length === 1) formatted = col.format(val);
|
|
238
|
+
else if (col.format.length === 2) formatted = col.format(val, s);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
if (formatted instanceof HTMLElement) formatted = formatted.outerHTML;
|
|
242
|
+
|
|
243
|
+
const className = col.class || "";
|
|
244
|
+
return `<td class="udt-td ${className}">${formatted || "-"}</td>`;
|
|
245
|
+
})
|
|
246
|
+
.join("")}
|
|
247
|
+
</tr>`).join("");
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
pageBtn(label, page, disabled) {
|
|
251
|
+
return `<button data-page="${page}" ${disabled ? "disabled" : ""} class="pg-btn">${label}</button>`;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
render() {
|
|
255
|
+
if (!this.columns || this.columns.length === 0) {
|
|
256
|
+
this.container.innerHTML = "";
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const {
|
|
261
|
+
currentPage = 1,
|
|
262
|
+
totalPages = 1,
|
|
263
|
+
startEntry = 0,
|
|
264
|
+
endEntry = 0,
|
|
265
|
+
totalRecords = 0,
|
|
266
|
+
} = this.pagination;
|
|
267
|
+
|
|
268
|
+
const isFirstPage = currentPage === 1;
|
|
269
|
+
const isLastPage = currentPage === totalPages;
|
|
270
|
+
const hasMultiplePages = totalPages > 1;
|
|
271
|
+
|
|
272
|
+
const paginationHTML = this.shouldShowPagination
|
|
273
|
+
? `<div class="udt-pagination">
|
|
274
|
+
<div class="pagination-left">
|
|
275
|
+
<div class="entries-text">
|
|
276
|
+
Showing ${startEntry} to ${endEntry} of ${totalRecords} entries
|
|
277
|
+
</div>
|
|
278
|
+
|
|
279
|
+
<div class="page-jump mbl-jump-btn">
|
|
280
|
+
<span>Jump to page</span>
|
|
281
|
+
<input
|
|
282
|
+
type="number"
|
|
283
|
+
value="${this.jumpToPage}"
|
|
284
|
+
min="1"
|
|
285
|
+
max="${totalPages}"
|
|
286
|
+
${!this.shouldEnableJumpToPage ? "disabled" : ""}
|
|
287
|
+
class="jumpto"
|
|
288
|
+
/>
|
|
289
|
+
<button ${!this.shouldEnableJumpToPage ? "disabled" : ""} class="go-btn">Go</button>
|
|
290
|
+
</div>
|
|
291
|
+
</div>
|
|
292
|
+
|
|
293
|
+
<div class="pagination-buttons">
|
|
294
|
+
${this.pageBtn("First", 1, isFirstPage || !hasMultiplePages)}
|
|
295
|
+
${this.pageBtn("Previous", currentPage - 1, isFirstPage || !hasMultiplePages)}
|
|
296
|
+
<span class="pg-number active">${currentPage}</span>
|
|
297
|
+
${this.pageBtn("Next", currentPage + 1, isLastPage || !hasMultiplePages)}
|
|
298
|
+
${this.pageBtn("Last", totalPages, isLastPage || !hasMultiplePages)}
|
|
299
|
+
</div>
|
|
300
|
+
|
|
301
|
+
<div class="page-jump desk-jump-btn">
|
|
302
|
+
<span>Jump to page</span>
|
|
303
|
+
<input
|
|
304
|
+
type="number"
|
|
305
|
+
value="${this.jumpToPage}"
|
|
306
|
+
min="1"
|
|
307
|
+
max="${totalPages}"
|
|
308
|
+
${!this.shouldEnableJumpToPage ? "disabled" : ""}
|
|
309
|
+
class="jumpto"
|
|
310
|
+
/>
|
|
311
|
+
<button ${!this.shouldEnableJumpToPage ? "disabled" : ""} class="go-btn">Go</button>
|
|
312
|
+
</div>
|
|
313
|
+
</div>`
|
|
314
|
+
: "";
|
|
315
|
+
|
|
316
|
+
this.container.innerHTML = `<div class="udt-container">
|
|
317
|
+
<div>
|
|
318
|
+
<div class="table-wrapper">
|
|
319
|
+
<table class="udt-table">
|
|
320
|
+
<thead>
|
|
321
|
+
<tr>${this.columns.map((col) => this.th(col.label)).join("")}</tr>
|
|
322
|
+
</thead>
|
|
323
|
+
<tbody>
|
|
324
|
+
${this.renderRows()}
|
|
325
|
+
</tbody>
|
|
326
|
+
</table>
|
|
327
|
+
</div>
|
|
328
|
+
${paginationHTML}
|
|
329
|
+
</div>
|
|
330
|
+
</div>`;
|
|
331
|
+
|
|
332
|
+
if (this.shouldShowPagination) {
|
|
333
|
+
const jumpInputs = this.container.querySelectorAll("input.jumpto");
|
|
334
|
+
jumpInputs.forEach((input) =>
|
|
335
|
+
input.addEventListener("keypress", (e) => this.handleKeyPress(e))
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
const goButtons = this.container.querySelectorAll(".go-btn");
|
|
339
|
+
goButtons.forEach((btn) => {
|
|
340
|
+
if (!btn.disabled) btn.addEventListener("click", () => this.handleJumpToPage());
|
|
341
|
+
});
|
|
342
|
+
|
|
343
|
+
const pgButtons = this.container.querySelectorAll(".pg-btn");
|
|
344
|
+
pgButtons.forEach((btn) => {
|
|
345
|
+
const page = parseInt(btn.getAttribute("data-page"), 10) || 1;
|
|
346
|
+
btn.addEventListener("click", () => this.handlePageChange(page));
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
getNestedValue(obj, path) {
|
|
352
|
+
return path.split('.').reduce((acc, part) => {
|
|
353
|
+
if (acc && acc[part] !== undefined) return acc[part];
|
|
354
|
+
return undefined;
|
|
355
|
+
}, obj);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
export { UniverseDataTable };
|
package/package.json
CHANGED
|
@@ -1,12 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "universe-code",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.89",
|
|
4
4
|
"description": "Universal utility functions for all JS frameworks",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"main": "./dist/index.js",
|
|
8
8
|
"module": "./dist/index.js",
|
|
9
9
|
"types": "./dist/index.d.ts",
|
|
10
|
+
"typesVersions": {
|
|
11
|
+
"*": {
|
|
12
|
+
"angular": [
|
|
13
|
+
"dist/angular/index.d.ts"
|
|
14
|
+
],
|
|
15
|
+
"uiux": [
|
|
16
|
+
"dist/uiux/index.d.ts"
|
|
17
|
+
],
|
|
18
|
+
"core": [
|
|
19
|
+
"dist/core/index.d.ts"
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
},
|
|
10
23
|
"exports": {
|
|
11
24
|
".": {
|
|
12
25
|
"import": "./dist/indexdb/index.js",
|
|
@@ -62,4 +75,4 @@
|
|
|
62
75
|
"angular-indexdb",
|
|
63
76
|
"react-indexdb"
|
|
64
77
|
]
|
|
65
|
-
}
|
|
78
|
+
}
|