@syware/jlib 0.7.0 → 0.8.0
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/all.js +2 -2
- package/dist/atoms/jl-select.d.ts +8 -7
- package/dist/atoms/jl-select.js +11 -6
- package/dist/index.js +2 -2
- package/dist/lib/attributes.d.ts +9 -0
- package/dist/lib/attributes.js +10 -1
- package/dist/lib/nav-tree.d.ts +2 -2
- package/dist/lib/palette.d.ts +2 -2
- package/dist/lib/table.d.ts +19 -6
- package/dist/lib/table.js +42 -7
- package/dist/lib/texts.d.ts +2 -0
- package/dist/lib/texts.js +2 -0
- package/dist/molecules/jl-chip-group.d.ts +7 -6
- package/dist/molecules/jl-chip-group.js +6 -4
- package/dist/molecules/jl-menu.d.ts +8 -4
- package/dist/molecules/jl-menu.js +8 -1
- package/dist/molecules/jl-radio-group.d.ts +8 -7
- package/dist/molecules/jl-radio-group.js +10 -6
- package/dist/molecules/jl-segmented.d.ts +8 -7
- package/dist/molecules/jl-segmented.js +10 -5
- package/dist/organisms/jl-command-palette.d.ts +6 -4
- package/dist/organisms/jl-command-palette.js +2 -0
- package/dist/organisms/jl-side-nav.d.ts +8 -7
- package/dist/organisms/jl-side-nav.js +9 -4
- package/dist/organisms/jl-tab-bar.d.ts +8 -7
- package/dist/organisms/jl-tab-bar.js +10 -4
- package/dist/organisms/jl-table.css_raw.js +1 -1
- package/dist/organisms/jl-table.d.ts +54 -16
- package/dist/organisms/jl-table.js +218 -37
- package/dist/types/jl-chip-group.types.d.ts +3 -3
- package/dist/types/jl-command-palette.types.d.ts +10 -6
- package/dist/types/jl-menu.types.d.ts +4 -4
- package/dist/types/jl-radio-group.types.d.ts +6 -3
- package/dist/types/jl-segmented.types.d.ts +6 -3
- package/dist/types/jl-select.types.d.ts +6 -3
- package/dist/types/jl-side-nav.types.d.ts +9 -6
- package/dist/types/jl-tab-bar.types.d.ts +6 -3
- package/dist/types/jl-table.types.d.ts +34 -8
- package/package.json +2 -2
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { BASE_STYLES } from "../styles/shared.js";
|
|
2
2
|
import { JlElement } from "../base/jl-element.js";
|
|
3
|
-
import { jsonOf, oneOf } from "../lib/attributes.js";
|
|
3
|
+
import { jsonOf, oneOf, textOf } from "../lib/attributes.js";
|
|
4
4
|
import { registerIcons } from "../lib/icons.js";
|
|
5
|
-
import { columnAlign, columnWidth, formatCell, nextSortDirection, rowKeyOf, selectionState, sortRows, toggleAll, toggleKey } from "../lib/table.js";
|
|
5
|
+
import { columnAlign, columnWidth, fieldOf, formatCell, nextSortDirection, openRows, rowKeyOf, rowToggles, selectionState, sortRows, toggleAll, toggleKey, withRowOpen } from "../lib/table.js";
|
|
6
6
|
import { jlText } from "../lib/texts.js";
|
|
7
7
|
import { JlIcon } from "../atoms/jl-icon.js";
|
|
8
8
|
import { setOrRemove } from "../lib/dom.js";
|
|
9
9
|
import { JlBadge } from "../atoms/jl-badge.js";
|
|
10
|
+
import { startedOnControl } from "../lib/surface.js";
|
|
10
11
|
import jl_table_default from "./jl-table.css_raw.js";
|
|
11
12
|
import { css } from "@jadis/core";
|
|
12
|
-
import { ArrowDown, ArrowUp, ChevronsUpDown, Inbox } from "lucide";
|
|
13
|
+
import { ArrowDown, ArrowUp, ChevronRight, ChevronsUpDown, Inbox } from "lucide";
|
|
13
14
|
import { Fragment, jsx, jsxs } from "@jadis/core/jsx-runtime";
|
|
14
15
|
// src/organisms/jl-table.tsx
|
|
15
16
|
registerIcons({
|
|
16
17
|
"arrow-down": ArrowDown,
|
|
17
18
|
"arrow-up": ArrowUp,
|
|
19
|
+
"chevron-right": ChevronRight,
|
|
18
20
|
"chevrons-up-down": ChevronsUpDown,
|
|
19
21
|
inbox: Inbox
|
|
20
22
|
});
|
|
@@ -23,12 +25,22 @@ var TABLE_SORT_DIRECTIONS = [
|
|
|
23
25
|
"asc",
|
|
24
26
|
"desc"
|
|
25
27
|
];
|
|
28
|
+
var TABLE_EXPANSIONS = [
|
|
29
|
+
"none",
|
|
30
|
+
"single",
|
|
31
|
+
"multiple"
|
|
32
|
+
];
|
|
26
33
|
var MARKED_ATTRIBUTE = "data-marked";
|
|
34
|
+
var EXPANDED_ATTRIBUTE = "data-expanded";
|
|
35
|
+
var DETAIL_ID_PREFIX = "detail-";
|
|
27
36
|
var DEFAULT_ROW_KEY = "id";
|
|
37
|
+
var NO_SORT_KEY = "";
|
|
28
38
|
var SKELETON_ROWS = 5;
|
|
29
39
|
var SORT_ICON_SIZE = 14;
|
|
30
40
|
var EMPTY_ICON_SIZE = 18;
|
|
41
|
+
var CHEVRON_SIZE = 16;
|
|
31
42
|
var NO_SORT = "none";
|
|
43
|
+
var NO_EXPANSION = "none";
|
|
32
44
|
var ARIA_SORT = {
|
|
33
45
|
asc: "ascending",
|
|
34
46
|
desc: "descending",
|
|
@@ -65,12 +77,25 @@ function checkbox(label, index) {
|
|
|
65
77
|
})]
|
|
66
78
|
});
|
|
67
79
|
}
|
|
80
|
+
/** One of the table's own checkboxes, not an input a renderer drew. */
|
|
81
|
+
var isTableCheckbox = (target) => target instanceof HTMLInputElement && target.matches(".select-cell > .check > .checkbox");
|
|
82
|
+
/** The detail drawn under a row while it is open. */
|
|
83
|
+
function detailOf(row) {
|
|
84
|
+
const next = row.nextElementSibling;
|
|
85
|
+
return next?.classList.contains("detail") ? next : null;
|
|
86
|
+
}
|
|
87
|
+
/** Whether a press ends a drag that selected text, which leaves the row as it was. */
|
|
88
|
+
var isSelectingText = () => (document.getSelection()?.toString() ?? "") !== "";
|
|
68
89
|
/**
|
|
69
90
|
* Rows of data under column headings. `columns` say what each column shows and how (`format`: text, number, date,
|
|
70
91
|
* badge, code); `rows` are plain objects. Sortable headings cycle ascending, descending and unsorted, and sort the
|
|
71
92
|
* rows in place; `selectable` adds a checkbox column. The header stays on top while the rows scroll within
|
|
72
93
|
* `max-height`, and the table scrolls sideways on narrow screens. Cells of a column can be drawn by code with
|
|
73
|
-
* `renderers`.
|
|
94
|
+
* `renderers`. `expandable` rows open on a press to show their `detail` under them, the row staying as it is: one at
|
|
95
|
+
* a time (`single`) or any number (`multiple`).
|
|
96
|
+
*
|
|
97
|
+
* Typed by its rows, `JlTable<Order>` checks and completes the fields its columns name, and hands its renderers and
|
|
98
|
+
* `detail` an order; `JlTable<Order, 'actions'>` adds a column that is not a field, which a renderer draws.
|
|
74
99
|
*/
|
|
75
100
|
var JlTable = class extends JlElement {
|
|
76
101
|
static selector = "jl-table";
|
|
@@ -84,9 +109,15 @@ var JlTable = class extends JlElement {
|
|
|
84
109
|
parse: jsonOf([])
|
|
85
110
|
});
|
|
86
111
|
/** The field that tells rows apart, for the selection. */
|
|
87
|
-
rowKey = this.useChange(DEFAULT_ROW_KEY, () => this.schedule("body"), {
|
|
112
|
+
rowKey = this.useChange(DEFAULT_ROW_KEY, () => this.schedule("body"), {
|
|
113
|
+
attribute: "row-key",
|
|
114
|
+
parse: textOf(DEFAULT_ROW_KEY)
|
|
115
|
+
});
|
|
88
116
|
/** The column the rows are sorted by. */
|
|
89
|
-
sortKey = this.useChange(
|
|
117
|
+
sortKey = this.useChange(NO_SORT_KEY, () => this.schedule("body"), {
|
|
118
|
+
attribute: "sort-key",
|
|
119
|
+
parse: textOf(NO_SORT_KEY)
|
|
120
|
+
});
|
|
90
121
|
sortDirection = this.useChange(NO_SORT, () => this.schedule("body"), {
|
|
91
122
|
attribute: "sort-direction",
|
|
92
123
|
parse: oneOf(TABLE_SORT_DIRECTIONS, NO_SORT)
|
|
@@ -101,6 +132,19 @@ var JlTable = class extends JlElement {
|
|
|
101
132
|
attribute: "selected",
|
|
102
133
|
parse: jsonOf([])
|
|
103
134
|
});
|
|
135
|
+
/** Rows open on a press to show their `detail` under them: one at a time (`single`), any number (`multiple`). */
|
|
136
|
+
expandable = this.useChange(NO_EXPANSION, (value) => {
|
|
137
|
+
this.reflect("expandable", value === NO_EXPANSION ? false : value);
|
|
138
|
+
this.schedule("head", "body");
|
|
139
|
+
}, {
|
|
140
|
+
attribute: "expandable",
|
|
141
|
+
parse: oneOf(TABLE_EXPANSIONS, NO_EXPANSION)
|
|
142
|
+
});
|
|
143
|
+
/** The keys of the open rows. */
|
|
144
|
+
expanded = this.useChange([], () => this.renderExpansion(), {
|
|
145
|
+
attribute: "expanded",
|
|
146
|
+
parse: jsonOf([])
|
|
147
|
+
});
|
|
104
148
|
/** The keys of rows to draw attention to, such as a search's matches: a mark, not a selection. */
|
|
105
149
|
marked = this.useChange([], () => this.renderMarks(), {
|
|
106
150
|
attribute: "marked",
|
|
@@ -124,18 +168,39 @@ var JlTable = class extends JlElement {
|
|
|
124
168
|
label = this.useChange("", (value) => setOrRemove(this._refs.table, "aria-label", value), { attribute: "label" });
|
|
125
169
|
/** Draws the cells of some columns by code, by column key: `{ name: (row) => <strong>{row.name}</strong> }`. */
|
|
126
170
|
renderers = this.useChange({}, () => this.schedule("body"));
|
|
171
|
+
_source = { detail: null };
|
|
127
172
|
_pending = {
|
|
128
173
|
body: false,
|
|
129
174
|
head: false,
|
|
130
175
|
queued: false
|
|
131
176
|
};
|
|
132
|
-
/** The
|
|
133
|
-
_view = {
|
|
177
|
+
/** The rows as drawn and their keys, by their place: the rows and their checkboxes carry the place. */
|
|
178
|
+
_view = {
|
|
179
|
+
keys: [],
|
|
180
|
+
rows: []
|
|
181
|
+
};
|
|
134
182
|
_refs = this.useRefs((ref) => ({
|
|
135
183
|
body: ref("tbody"),
|
|
136
184
|
head: ref("thead"),
|
|
137
185
|
table: ref("table")
|
|
138
186
|
}));
|
|
187
|
+
/** Draws what an open row shows under it, from the row: `(row) => <JlFacts items={…} />`. */
|
|
188
|
+
get detail() {
|
|
189
|
+
return this._source.detail;
|
|
190
|
+
}
|
|
191
|
+
set detail(draw) {
|
|
192
|
+
this._source.detail = draw;
|
|
193
|
+
this.whenRendered(() => this.schedule("body"));
|
|
194
|
+
}
|
|
195
|
+
/** Opens or closes a row, as a press on it would; one at a time, opening a row closes the one that was open. */
|
|
196
|
+
toggle(key, open) {
|
|
197
|
+
const expansion = this.expandable.get();
|
|
198
|
+
if (expansion === NO_EXPANSION) return;
|
|
199
|
+
const before = openRows(this.expanded.get(), expansion);
|
|
200
|
+
const expanded = withRowOpen(this.expanded.get(), key, open, expansion);
|
|
201
|
+
this.expanded.set(expanded);
|
|
202
|
+
for (const change of rowToggles(before, openRows(expanded, expansion))) this.events.emit("toggle", change);
|
|
203
|
+
}
|
|
139
204
|
templateHtml() {
|
|
140
205
|
return /* @__PURE__ */ jsx("div", {
|
|
141
206
|
class: "scroll",
|
|
@@ -152,9 +217,9 @@ var JlTable = class extends JlElement {
|
|
|
152
217
|
if (key !== void 0) this.sortBy(key);
|
|
153
218
|
});
|
|
154
219
|
this.on(this._refs.table, "change", (event) => {
|
|
155
|
-
|
|
156
|
-
if (input instanceof HTMLInputElement && input.classList.contains("checkbox")) this.changeSelection(input);
|
|
220
|
+
if (isTableCheckbox(event.target)) this.changeSelection(event.target);
|
|
157
221
|
});
|
|
222
|
+
this.on(this._refs.body, "click", (event) => this.pressRow(event));
|
|
158
223
|
}
|
|
159
224
|
/** Draws on the next microtask: the inputs set while connecting give one drawing, not one each. */
|
|
160
225
|
schedule(...parts) {
|
|
@@ -172,8 +237,11 @@ var JlTable = class extends JlElement {
|
|
|
172
237
|
this.renderSortState();
|
|
173
238
|
if (body) this.renderBody();
|
|
174
239
|
this.renderSelection();
|
|
240
|
+
this.renderExpansion();
|
|
175
241
|
}
|
|
176
|
-
sortBy(
|
|
242
|
+
sortBy(name) {
|
|
243
|
+
const key = this.columns.get().find((column) => column.key === name)?.key;
|
|
244
|
+
if (key === void 0) return;
|
|
177
245
|
const current = key === this.sortKey.get() ? this.sortDirection.get() : NO_SORT;
|
|
178
246
|
const direction = nextSortDirection(current);
|
|
179
247
|
this.sortKey.set(key);
|
|
@@ -190,18 +258,57 @@ var JlTable = class extends JlElement {
|
|
|
190
258
|
this.selected.set(keys);
|
|
191
259
|
this.events.emit("selection", keys);
|
|
192
260
|
}
|
|
261
|
+
/** A press on a row's chevron, or on the row anywhere but its controls and its checkbox, opens or closes it. */
|
|
262
|
+
pressRow(event) {
|
|
263
|
+
const row = this.dataRowOf(event);
|
|
264
|
+
const key = row === void 0 ? void 0 : this.keyOf(row);
|
|
265
|
+
if (row === void 0 || key === void 0 || !this.opensOnPress(event, row)) return;
|
|
266
|
+
this.toggle(key, !row.hasAttribute(EXPANDED_ATTRIBUTE));
|
|
267
|
+
}
|
|
268
|
+
/** The row of data a press is on: one of the table's, not a row in the content of a detail. */
|
|
269
|
+
dataRowOf(event) {
|
|
270
|
+
const body = this._refs.body;
|
|
271
|
+
return event.composedPath().find((target) => target instanceof HTMLTableRowElement && target.parentElement === body && target.dataset.index !== void 0);
|
|
272
|
+
}
|
|
273
|
+
opensOnPress(event, row) {
|
|
274
|
+
const path = event.composedPath();
|
|
275
|
+
const chevron = row.querySelector("button.expand");
|
|
276
|
+
if (chevron === null) return false;
|
|
277
|
+
const select = row.querySelector(".select-cell");
|
|
278
|
+
const elsewhere = startedOnControl(event, row) || select !== null && path.includes(select) || isSelectingText();
|
|
279
|
+
return path.includes(chevron) || !elsewhere;
|
|
280
|
+
}
|
|
193
281
|
renderMaxHeight(value) {
|
|
194
282
|
const height = /^\d+(\.\d+)?$/.test(value.trim()) ? `${value.trim()}px` : value;
|
|
195
283
|
this.style.setProperty("--max-height", height === "" ? "none" : height);
|
|
196
284
|
this.reflect("scrolls", height !== "");
|
|
197
285
|
}
|
|
286
|
+
isExpandable() {
|
|
287
|
+
return this.expandable.get() !== NO_EXPANSION;
|
|
288
|
+
}
|
|
289
|
+
/** The number of cells in a row: the columns, after the checkbox and the chevron when there are. */
|
|
290
|
+
span(columns) {
|
|
291
|
+
return columns.length + Number(this.selectable.get()) + Number(this.isExpandable());
|
|
292
|
+
}
|
|
198
293
|
renderHead() {
|
|
199
294
|
const selectAll = this.selectable.get() ? /* @__PURE__ */ jsx("th", {
|
|
200
295
|
class: "select-cell",
|
|
201
296
|
scope: "col",
|
|
202
297
|
children: checkbox("Select all rows", null)
|
|
203
298
|
}) : null;
|
|
204
|
-
this.
|
|
299
|
+
const details = this.isExpandable() ? /* @__PURE__ */ jsx("th", {
|
|
300
|
+
class: "expand-cell",
|
|
301
|
+
scope: "col",
|
|
302
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
303
|
+
class: "sr-only",
|
|
304
|
+
children: jlText("details")
|
|
305
|
+
})
|
|
306
|
+
}) : null;
|
|
307
|
+
this._refs.head.replaceChildren(/* @__PURE__ */ jsxs("tr", { children: [
|
|
308
|
+
selectAll,
|
|
309
|
+
details,
|
|
310
|
+
this.columns.get().map((column) => this.headerCell(column))
|
|
311
|
+
] }));
|
|
205
312
|
}
|
|
206
313
|
headerCell(column) {
|
|
207
314
|
const content = column.sortable ? /* @__PURE__ */ jsxs("button", {
|
|
@@ -240,41 +347,65 @@ var JlTable = class extends JlElement {
|
|
|
240
347
|
}
|
|
241
348
|
renderBody() {
|
|
242
349
|
const columns = this.columns.get();
|
|
243
|
-
const span = columns.length + Number(this.selectable.get());
|
|
244
350
|
if (this.loading.get()) {
|
|
245
|
-
this.
|
|
351
|
+
this.setView([], []);
|
|
246
352
|
this._refs.body.replaceChildren(...this.skeletonRows(columns));
|
|
247
353
|
return;
|
|
248
354
|
}
|
|
249
355
|
const rows = this.rows.get();
|
|
250
356
|
if (rows.length === 0) {
|
|
251
|
-
this.
|
|
252
|
-
this._refs.body.replaceChildren(this.emptyRow(span));
|
|
357
|
+
this.setView([], []);
|
|
358
|
+
this._refs.body.replaceChildren(this.emptyRow(this.span(columns)));
|
|
253
359
|
return;
|
|
254
360
|
}
|
|
255
361
|
const keyField = this.rowKey.get();
|
|
256
362
|
const keys = new Map(rows.map((row, index) => [row, rowKeyOf(row, keyField, index)]));
|
|
257
363
|
const sorted = this.sortedRows();
|
|
258
|
-
this.
|
|
364
|
+
this.setView(sorted, sorted.map((row, index) => keys.get(row) ?? index));
|
|
259
365
|
this._refs.body.replaceChildren(...sorted.map((row, index) => this.bodyRow(row, index, columns)));
|
|
260
366
|
this.renderMarks();
|
|
261
367
|
}
|
|
368
|
+
setView(rows, keys) {
|
|
369
|
+
this._view.rows = rows;
|
|
370
|
+
this._view.keys = keys;
|
|
371
|
+
}
|
|
262
372
|
bodyRow(row, index, columns) {
|
|
263
373
|
const first = columns[0];
|
|
264
|
-
const name = first === void 0 ? String(index + 1) : formatCell(row
|
|
374
|
+
const name = first === void 0 ? String(index + 1) : formatCell(fieldOf(row, first.key), first.format);
|
|
265
375
|
const select = this.selectable.get() ? /* @__PURE__ */ jsx("td", {
|
|
266
376
|
class: "select-cell",
|
|
267
377
|
children: checkbox(`Select ${name}`, index)
|
|
268
378
|
}) : null;
|
|
269
|
-
|
|
270
|
-
class:
|
|
271
|
-
children:
|
|
272
|
-
|
|
379
|
+
const chevron = this.isExpandable() ? /* @__PURE__ */ jsx("td", {
|
|
380
|
+
class: "expand-cell",
|
|
381
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
382
|
+
type: "button",
|
|
383
|
+
class: "expand",
|
|
384
|
+
"aria-expanded": "false",
|
|
385
|
+
"aria-label": jlText("detailsOf", { name }),
|
|
386
|
+
children: /* @__PURE__ */ jsx(JlIcon, {
|
|
387
|
+
class: "chevron",
|
|
388
|
+
name: "chevron-right",
|
|
389
|
+
size: CHEVRON_SIZE
|
|
390
|
+
})
|
|
391
|
+
})
|
|
392
|
+
}) : null;
|
|
393
|
+
return /* @__PURE__ */ jsxs("tr", {
|
|
394
|
+
"data-index": index,
|
|
395
|
+
children: [
|
|
396
|
+
select,
|
|
397
|
+
chevron,
|
|
398
|
+
columns.map((column) => /* @__PURE__ */ jsx("td", {
|
|
399
|
+
class: `align-${columnAlign(column)} format-${column.format ?? "text"}${column.wrap ? " wrap" : ""}`,
|
|
400
|
+
children: this.cell(row, column)
|
|
401
|
+
}))
|
|
402
|
+
]
|
|
403
|
+
});
|
|
273
404
|
}
|
|
274
405
|
/** A cell's value, drawn by its renderer or in its format, with the row's description under it when it has one. */
|
|
275
406
|
cell(row, column) {
|
|
276
407
|
const value = this.cellValue(row, column);
|
|
277
|
-
const description = column.description === void 0 ? "" : formatCell(row
|
|
408
|
+
const description = column.description === void 0 ? "" : formatCell(fieldOf(row, column.description));
|
|
278
409
|
if (description === "") return value;
|
|
279
410
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
280
411
|
class: "cell-value",
|
|
@@ -288,19 +419,24 @@ var JlTable = class extends JlElement {
|
|
|
288
419
|
const renderer = this.renderers.get()[column.key];
|
|
289
420
|
if (renderer !== void 0) return renderer(row);
|
|
290
421
|
const format = column.format ?? "text";
|
|
291
|
-
return CELL_MAKERS[format](formatCell(row
|
|
422
|
+
return CELL_MAKERS[format](formatCell(fieldOf(row, column.key), format), column);
|
|
292
423
|
}
|
|
293
424
|
skeletonRows(columns) {
|
|
294
425
|
const select = this.selectable.get();
|
|
426
|
+
const expand = this.isExpandable();
|
|
295
427
|
return Array.from({ length: SKELETON_ROWS }, () => /* @__PURE__ */ jsxs("tr", {
|
|
296
428
|
class: "skeleton",
|
|
297
|
-
children: [
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
429
|
+
children: [
|
|
430
|
+
select ? /* @__PURE__ */ jsx("td", {
|
|
431
|
+
class: "select-cell",
|
|
432
|
+
children: /* @__PURE__ */ jsx("span", { class: "bone box" })
|
|
433
|
+
}) : null,
|
|
434
|
+
expand ? /* @__PURE__ */ jsx("td", { class: "expand-cell" }) : null,
|
|
435
|
+
columns.map((column) => /* @__PURE__ */ jsx("td", {
|
|
436
|
+
class: `align-${columnAlign(column)}`,
|
|
437
|
+
children: /* @__PURE__ */ jsx("span", { class: "bone" })
|
|
438
|
+
}))
|
|
439
|
+
]
|
|
304
440
|
}));
|
|
305
441
|
}
|
|
306
442
|
emptyRow(span) {
|
|
@@ -318,19 +454,64 @@ var JlTable = class extends JlElement {
|
|
|
318
454
|
})
|
|
319
455
|
});
|
|
320
456
|
}
|
|
321
|
-
/** The
|
|
457
|
+
/** The rows of data, without the details under the open ones. */
|
|
458
|
+
dataRows() {
|
|
459
|
+
return [...this._refs.body.querySelectorAll(":scope > tr[data-index]")];
|
|
460
|
+
}
|
|
461
|
+
keyOf(row) {
|
|
462
|
+
return this._view.keys[Number(row.dataset.index)];
|
|
463
|
+
}
|
|
464
|
+
/** The bar and the shade of marked rows, changed in place. */
|
|
322
465
|
renderMarks() {
|
|
323
466
|
const marked = new Set(this.marked.get());
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
const key = this._view.keys[index];
|
|
467
|
+
for (const row of this.dataRows()) {
|
|
468
|
+
const key = this.keyOf(row);
|
|
327
469
|
row.toggleAttribute(MARKED_ATTRIBUTE, key !== void 0 && marked.has(key));
|
|
328
470
|
}
|
|
329
471
|
}
|
|
472
|
+
/** The details of the open rows, added under them and taken away in place: one that stays open keeps its content. */
|
|
473
|
+
renderExpansion() {
|
|
474
|
+
const open = new Set(openRows(this.expanded.get(), this.expandable.get()));
|
|
475
|
+
for (const row of this.dataRows()) {
|
|
476
|
+
const key = this.keyOf(row);
|
|
477
|
+
this.renderRowOpen(row, key !== void 0 && open.has(key));
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
renderRowOpen(row, open) {
|
|
481
|
+
const chevron = row.querySelector("button.expand");
|
|
482
|
+
if (chevron === null) return;
|
|
483
|
+
row.toggleAttribute(EXPANDED_ATTRIBUTE, open);
|
|
484
|
+
chevron.setAttribute("aria-expanded", String(open));
|
|
485
|
+
const detail = detailOf(row);
|
|
486
|
+
if (!open) {
|
|
487
|
+
detail?.remove();
|
|
488
|
+
chevron.removeAttribute("aria-controls");
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
if (detail !== null) return;
|
|
492
|
+
const id = `${DETAIL_ID_PREFIX}${row.dataset.index}`;
|
|
493
|
+
row.after(this.detailRow(row, id));
|
|
494
|
+
chevron.setAttribute("aria-controls", id);
|
|
495
|
+
}
|
|
496
|
+
detailRow(row, id) {
|
|
497
|
+
const data = this._view.rows[Number(row.dataset.index)];
|
|
498
|
+
const draw = this._source.detail;
|
|
499
|
+
return /* @__PURE__ */ jsx("tr", {
|
|
500
|
+
class: "detail",
|
|
501
|
+
id,
|
|
502
|
+
children: /* @__PURE__ */ jsx("td", {
|
|
503
|
+
colSpan: this.span(this.columns.get()),
|
|
504
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
505
|
+
class: "detail-body",
|
|
506
|
+
children: data === void 0 || draw === null ? "" : draw(data)
|
|
507
|
+
})
|
|
508
|
+
})
|
|
509
|
+
});
|
|
510
|
+
}
|
|
330
511
|
/** The checkboxes and the shading of selected rows, changed in place. */
|
|
331
512
|
renderSelection() {
|
|
332
513
|
const selected = new Set(this.selected.get());
|
|
333
|
-
for (const input of this._refs.body.querySelectorAll("
|
|
514
|
+
for (const input of this._refs.body.querySelectorAll(":scope > tr > .select-cell .checkbox")) {
|
|
334
515
|
const key = this._view.keys[Number(input.dataset.index)];
|
|
335
516
|
const on = key !== void 0 && selected.has(key);
|
|
336
517
|
input.checked = on;
|
|
@@ -345,4 +526,4 @@ var JlTable = class extends JlElement {
|
|
|
345
526
|
}
|
|
346
527
|
};
|
|
347
528
|
JlTable.register();
|
|
348
|
-
export { JlTable, TABLE_SORT_DIRECTIONS };
|
|
529
|
+
export { JlTable, TABLE_EXPANSIONS, TABLE_SORT_DIRECTIONS };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/** One choice of a chip group. */
|
|
2
|
-
export type ChipGroupOption = {
|
|
3
|
-
value:
|
|
1
|
+
/** One choice of a chip group. Typed by its values (`ChipGroupOption<'open' | 'done'>`), `value` is one of them. */
|
|
2
|
+
export type ChipGroupOption<Value extends string = string> = {
|
|
3
|
+
value: Value;
|
|
4
4
|
label: string;
|
|
5
5
|
/** An icon name before the label; a chosen chip without one shows a check. */
|
|
6
6
|
icon?: string;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A command of the palette: `select` fires with its id. Typed by its ids (`PaletteCommand<'theme' | 'logout'>`, or
|
|
3
|
+
* `` `open:${string}` `` for the records a search finds), `id` is one of them.
|
|
4
|
+
*/
|
|
5
|
+
export type PaletteCommand<Id extends string = string> = {
|
|
6
|
+
id: Id;
|
|
3
7
|
label: string;
|
|
4
8
|
/** The heading the command is listed under. */
|
|
5
9
|
group?: string;
|
|
@@ -17,13 +21,13 @@ export type PaletteCommand = {
|
|
|
17
21
|
result?: boolean;
|
|
18
22
|
};
|
|
19
23
|
/** A command that matches the search, with the places of the matched letters in its label. */
|
|
20
|
-
export type PaletteMatch = {
|
|
21
|
-
command: PaletteCommand
|
|
24
|
+
export type PaletteMatch<Id extends string = string> = {
|
|
25
|
+
command: PaletteCommand<Id>;
|
|
22
26
|
score: number;
|
|
23
27
|
positions: number[];
|
|
24
28
|
};
|
|
25
29
|
/** Commands under one heading, in the order they are listed. */
|
|
26
|
-
export type PaletteGroup = {
|
|
30
|
+
export type PaletteGroup<Id extends string = string> = {
|
|
27
31
|
label: string;
|
|
28
|
-
matches: PaletteMatch[];
|
|
32
|
+
matches: PaletteMatch<Id>[];
|
|
29
33
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/** A choice of a menu: `select` fires with its value. */
|
|
2
|
-
export type MenuAction = {
|
|
3
|
-
value:
|
|
1
|
+
/** A choice of a menu: `select` fires with its value. Typed (`MenuAction<'edit' | 'delete'>`), it is one of those. */
|
|
2
|
+
export type MenuAction<Value extends string = string> = {
|
|
3
|
+
value: Value;
|
|
4
4
|
label: string;
|
|
5
5
|
icon?: string;
|
|
6
6
|
/** The keys that do the same, shown at the end: "⌘D". */
|
|
@@ -19,4 +19,4 @@ export type MenuDivider = {
|
|
|
19
19
|
export type MenuHeading = {
|
|
20
20
|
heading: string;
|
|
21
21
|
};
|
|
22
|
-
export type MenuItem = MenuAction | MenuDivider | MenuHeading;
|
|
22
|
+
export type MenuItem<Value extends string = string> = MenuAction<Value> | MenuDivider | MenuHeading;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* One choice of a radio group, with an optional line that explains it. Typed by its values
|
|
3
|
+
* (`RadioOption<'card' | 'invoice'>`), `value` is one of them.
|
|
4
|
+
*/
|
|
5
|
+
export type RadioOption<Value extends string = string> = {
|
|
6
|
+
value: Value;
|
|
4
7
|
label: string;
|
|
5
8
|
description?: string;
|
|
6
9
|
disabled?: boolean;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* One choice of a segmented control; without a label it shows its icon, and its value names it. Typed by its values
|
|
3
|
+
* (`SegmentedOption<'list' | 'grid'>`), `value` is one of them.
|
|
4
|
+
*/
|
|
5
|
+
export type SegmentedOption<Value extends string = string> = {
|
|
6
|
+
value: Value;
|
|
4
7
|
label?: string;
|
|
5
8
|
icon?: string;
|
|
6
9
|
/** A count or a short word after the label: what waits behind the choice. */
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* One choice of a select: `group` gathers it with the others of the same group under that heading. Typed by its
|
|
3
|
+
* values (`SelectOption<'eur' | 'chf'>`), `value` is one of them.
|
|
4
|
+
*/
|
|
5
|
+
export type SelectOption<Value extends string = string> = {
|
|
6
|
+
value: Value;
|
|
4
7
|
label: string;
|
|
5
8
|
disabled?: boolean;
|
|
6
9
|
group?: string;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* One entry of a side navigation; with `children`, it opens and closes to show them. Typed by its ids
|
|
3
|
+
* (`SideNavItem<'jobs' | 'people'>`), `id` is one of them.
|
|
4
|
+
*/
|
|
5
|
+
export type SideNavItem<Id extends string = string> = {
|
|
6
|
+
id: Id;
|
|
4
7
|
label: string;
|
|
5
8
|
/** An icon name; the collapsed rail shows only the icons. */
|
|
6
9
|
icon?: string;
|
|
@@ -10,10 +13,10 @@ export type SideNavItem = {
|
|
|
10
13
|
target?: string;
|
|
11
14
|
/** A count or a short word beside the label: `3`, `New`. */
|
|
12
15
|
badge?: string | number;
|
|
13
|
-
children?: SideNavItem[];
|
|
16
|
+
children?: SideNavItem<Id>[];
|
|
14
17
|
};
|
|
15
18
|
/** A group of items under an optional heading. */
|
|
16
|
-
export type SideNavSection = {
|
|
19
|
+
export type SideNavSection<Id extends string = string> = {
|
|
17
20
|
label?: string;
|
|
18
|
-
items: SideNavItem[];
|
|
21
|
+
items: SideNavItem<Id>[];
|
|
19
22
|
};
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
/**
|
|
2
|
+
* One place in a bottom tab bar: an icon over a short label. Typed by its ids (`TabBarItem<'home' | 'jobs'>`), `id`
|
|
3
|
+
* is one of them.
|
|
4
|
+
*/
|
|
5
|
+
export type TabBarItem<Id extends string = string> = {
|
|
6
|
+
id: Id;
|
|
4
7
|
label: string;
|
|
5
8
|
/** An icon name: the tab bar draws one over every label. */
|
|
6
9
|
icon: string;
|
|
@@ -4,9 +4,23 @@ export type TableCellFormat = 'text' | 'number' | 'date' | 'datetime' | 'badge'
|
|
|
4
4
|
export type TableAlign = 'left' | 'center' | 'right';
|
|
5
5
|
/** The order of a sorted column; `none` keeps the rows as they came. */
|
|
6
6
|
export type TableSortDirection = 'asc' | 'desc' | 'none';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
/** A row of a table that does not say its type: any field, of any value. */
|
|
8
|
+
export type TableRow = Record<string, unknown>;
|
|
9
|
+
/** The names of a type of row's fields: what a column shows, sorts by, or shows under its value. */
|
|
10
|
+
export type TableField<Row> = Extract<keyof Row, string>;
|
|
11
|
+
/**
|
|
12
|
+
* What a column's `key` names: a field of the row, or one of the `Extra` columns a renderer draws from the whole
|
|
13
|
+
* row, such as a column of actions. The extra columns are named, never guessed from the keys: a misspelt field is
|
|
14
|
+
* an error, not a new column.
|
|
15
|
+
*/
|
|
16
|
+
export type TableColumnKey<Row, Extra extends string = never> = TableField<Row> | NoInfer<Extra>;
|
|
17
|
+
/**
|
|
18
|
+
* A column of a table. Typed by its rows (`TableColumn<Order>`), its `key` and `description` are fields of an
|
|
19
|
+
* order, checked and completed by the editor.
|
|
20
|
+
*/
|
|
21
|
+
export type TableColumn<Row extends object = TableRow, Extra extends string = never> = {
|
|
22
|
+
/** The row's field shown in this column, or one of the `Extra` columns a renderer draws. */
|
|
23
|
+
key: TableColumnKey<Row, Extra>;
|
|
10
24
|
label: string;
|
|
11
25
|
/** Numbers are right-aligned when absent; the rest left. */
|
|
12
26
|
align?: TableAlign;
|
|
@@ -17,21 +31,33 @@ export type TableColumn = {
|
|
|
17
31
|
/** For badges: the tone of each value (`{ "Active": "ok" }`); neutral otherwise. */
|
|
18
32
|
tones?: Record<string, Tone>;
|
|
19
33
|
/** The row's field shown as a quieter line under the value: a package's format under its name. */
|
|
20
|
-
description?:
|
|
34
|
+
description?: TableField<Row>;
|
|
21
35
|
/**
|
|
22
36
|
* Long text, a description or a note, breaks over lines instead of widening the table; cells stay on one line
|
|
23
37
|
* otherwise.
|
|
24
38
|
*/
|
|
25
39
|
wrap?: boolean;
|
|
26
40
|
};
|
|
27
|
-
export type TableRow = Record<string, unknown>;
|
|
28
41
|
/** A row's identity, the value of its `row-key` field. */
|
|
29
42
|
export type TableRowKey = string | number;
|
|
30
|
-
export type TableSort = {
|
|
31
|
-
key:
|
|
43
|
+
export type TableSort<Row extends object = TableRow, Extra extends string = never> = {
|
|
44
|
+
key: TableColumnKey<Row, Extra>;
|
|
32
45
|
direction: TableSortDirection;
|
|
33
46
|
};
|
|
34
47
|
/** Draws a cell of a column in place of its formatted value. */
|
|
35
|
-
export type TableCellRenderer = (row:
|
|
48
|
+
export type TableCellRenderer<Row extends object = TableRow> = (row: Row) => Node;
|
|
49
|
+
/** The renderers of a table, by the key of the column whose cells they draw. */
|
|
50
|
+
export type TableRenderers<Row extends object = TableRow, Extra extends string = never> = {
|
|
51
|
+
[Key in TableColumnKey<Row, Extra>]?: TableCellRenderer<Row>;
|
|
52
|
+
};
|
|
36
53
|
/** What the select-all box shows: no row selected, some, or all of them. */
|
|
37
54
|
export type TableSelectionState = 'none' | 'some' | 'all';
|
|
55
|
+
/** Whether rows open to show more under them: never, one at a time, or any number at once. */
|
|
56
|
+
export type TableExpansion = 'none' | 'single' | 'multiple';
|
|
57
|
+
/** Draws what an open row shows under it. */
|
|
58
|
+
export type TableDetailRenderer<Row extends object = TableRow> = (row: Row) => Node;
|
|
59
|
+
/** A row opened or closed: its key, and whether it is open now. */
|
|
60
|
+
export type TableToggle = {
|
|
61
|
+
key: TableRowKey;
|
|
62
|
+
open: boolean;
|
|
63
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@syware/jlib",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"description": "A tree-shakeable component library on Jadis and native Web Components, organised in atomic design",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"web-components",
|
|
@@ -94,7 +94,7 @@
|
|
|
94
94
|
"@biomejs/biome": "^2.6.3",
|
|
95
95
|
"@fontsource-variable/jetbrains-mono": "^5.3.0",
|
|
96
96
|
"@fontsource-variable/manrope": "^5.3.0",
|
|
97
|
-
"@jadis/core": "^1.4.
|
|
97
|
+
"@jadis/core": "^1.4.2",
|
|
98
98
|
"@types/node": "^24.13.3",
|
|
99
99
|
"playwright-core": "^1.64.1",
|
|
100
100
|
"typescript": "^7.0.2",
|