@syware/jlib 0.7.0 → 0.9.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/README.md +2 -1
- package/dist/all.js +3 -3
- package/dist/atoms/jl-chip.d.ts +1 -0
- package/dist/atoms/jl-chip.js +4 -2
- package/dist/atoms/jl-input.d.ts +2 -0
- package/dist/atoms/jl-input.js +9 -3
- package/dist/atoms/jl-rating.d.ts +2 -0
- package/dist/atoms/jl-rating.js +13 -5
- package/dist/atoms/jl-select.d.ts +8 -7
- package/dist/atoms/jl-select.js +11 -6
- package/dist/atoms/jl-spinner.d.ts +2 -0
- package/dist/atoms/jl-spinner.js +6 -2
- package/dist/base/jl-element.d.ts +6 -0
- package/dist/base/jl-element.js +5 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -3
- 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-de.d.ts +108 -0
- package/dist/lib/texts-de.js +111 -0
- package/dist/lib/texts-fr.d.ts +108 -0
- package/dist/lib/texts-fr.js +111 -0
- package/dist/lib/texts.d.ts +177 -89
- package/dist/lib/texts.js +176 -9
- package/dist/molecules/jl-alert.d.ts +1 -0
- package/dist/molecules/jl-alert.js +4 -2
- package/dist/molecules/jl-breadcrumb.d.ts +2 -0
- package/dist/molecules/jl-breadcrumb.js +12 -6
- package/dist/molecules/jl-calendar.d.ts +1 -0
- package/dist/molecules/jl-calendar.js +7 -4
- package/dist/molecules/jl-chip-group.d.ts +8 -6
- package/dist/molecules/jl-chip-group.js +10 -5
- package/dist/molecules/jl-code-block.js +1 -1
- package/dist/molecules/jl-combobox.d.ts +3 -1
- package/dist/molecules/jl-combobox.js +12 -7
- package/dist/molecules/jl-copy-button.d.ts +1 -0
- package/dist/molecules/jl-copy-button.js +7 -5
- package/dist/molecules/jl-date-picker.d.ts +1 -0
- package/dist/molecules/jl-date-picker.js +10 -7
- package/dist/molecules/jl-file-drop.d.ts +1 -0
- package/dist/molecules/jl-file-drop.js +15 -6
- package/dist/molecules/jl-input-list.d.ts +3 -2
- package/dist/molecules/jl-input-list.js +10 -7
- package/dist/molecules/jl-load-more.d.ts +4 -2
- package/dist/molecules/jl-load-more.js +15 -8
- package/dist/molecules/jl-load-state.d.ts +4 -0
- package/dist/molecules/jl-load-state.js +13 -9
- package/dist/molecules/jl-menu.d.ts +8 -4
- package/dist/molecules/jl-menu.js +8 -1
- package/dist/molecules/jl-number-input.d.ts +1 -0
- package/dist/molecules/jl-number-input.js +6 -3
- package/dist/molecules/jl-pagination.d.ts +2 -0
- package/dist/molecules/jl-pagination.js +17 -9
- package/dist/molecules/jl-radio-group.d.ts +9 -7
- package/dist/molecules/jl-radio-group.js +14 -7
- package/dist/molecules/jl-search-button.d.ts +2 -1
- package/dist/molecules/jl-search-button.js +6 -4
- package/dist/molecules/jl-search.d.ts +2 -0
- package/dist/molecules/jl-search.js +9 -3
- package/dist/molecules/jl-segmented.d.ts +8 -7
- package/dist/molecules/jl-segmented.js +10 -5
- package/dist/molecules/jl-steps.d.ts +2 -0
- package/dist/molecules/jl-steps.js +9 -4
- package/dist/molecules/jl-tag-input.d.ts +1 -0
- package/dist/molecules/jl-tag-input.js +8 -4
- package/dist/molecules/jl-toast.d.ts +1 -0
- package/dist/molecules/jl-toast.js +4 -2
- package/dist/organisms/jl-command-palette.d.ts +9 -5
- package/dist/organisms/jl-command-palette.js +15 -11
- package/dist/organisms/jl-confirm.d.ts +3 -0
- package/dist/organisms/jl-confirm.js +12 -11
- package/dist/organisms/jl-dialog.d.ts +1 -0
- package/dist/organisms/jl-dialog.js +4 -2
- package/dist/organisms/jl-drawer.d.ts +1 -0
- package/dist/organisms/jl-drawer.js +4 -2
- package/dist/organisms/jl-flow.d.ts +2 -0
- package/dist/organisms/jl-flow.js +25 -16
- package/dist/organisms/jl-navbar.d.ts +3 -0
- package/dist/organisms/jl-navbar.js +16 -7
- package/dist/organisms/jl-side-nav.d.ts +12 -9
- package/dist/organisms/jl-side-nav.js +26 -15
- package/dist/organisms/jl-tab-bar.d.ts +9 -7
- package/dist/organisms/jl-tab-bar.js +15 -6
- package/dist/organisms/jl-table.css_raw.js +1 -1
- package/dist/organisms/jl-table.d.ts +56 -17
- package/dist/organisms/jl-table.js +227 -43
- package/dist/organisms/jl-toaster.d.ts +2 -1
- package/dist/organisms/jl-toaster.js +12 -9
- package/dist/organisms/jl-tree.d.ts +6 -4
- package/dist/organisms/jl-tree.js +21 -15
- package/dist/templates/jl-app-shell.d.ts +1 -0
- package/dist/templates/jl-app-shell.js +4 -2
- package/dist/templates/jl-auth-layout.d.ts +4 -3
- package/dist/templates/jl-auth-layout.js +13 -11
- package/dist/templates/jl-page.d.ts +1 -0
- package/dist/templates/jl-page.js +4 -1
- package/dist/templates/jl-split-view.d.ts +1 -0
- package/dist/templates/jl-split-view.js +5 -4
- 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/dist/types/texts.types.d.ts +29 -4
- package/package.json +3 -3
|
@@ -1,20 +1,22 @@
|
|
|
1
|
+
import { jlText } from "../lib/texts.js";
|
|
1
2
|
import { BASE_STYLES } from "../styles/shared.js";
|
|
2
3
|
import { JlElement } from "../base/jl-element.js";
|
|
3
|
-
import { jsonOf, oneOf } from "../lib/attributes.js";
|
|
4
|
+
import { jsonOf, oneOf, textOf } from "../lib/attributes.js";
|
|
4
5
|
import { registerIcons } from "../lib/icons.js";
|
|
5
|
-
import { columnAlign, columnWidth, formatCell, nextSortDirection, rowKeyOf, selectionState, sortRows, toggleAll, toggleKey } from "../lib/table.js";
|
|
6
|
-
import { jlText } from "../lib/texts.js";
|
|
6
|
+
import { columnAlign, columnWidth, fieldOf, formatCell, nextSortDirection, openRows, rowKeyOf, rowToggles, selectionState, sortRows, toggleAll, toggleKey, withRowOpen } from "../lib/table.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",
|
|
@@ -112,8 +156,8 @@ var JlTable = class extends JlElement {
|
|
|
112
156
|
striped = this.useChange(false, (value) => this.reflect("striped", value), { attribute: "striped" });
|
|
113
157
|
/** A CSS height past which the rows scroll under the header: `320px`, `50vh`; a number is pixels. */
|
|
114
158
|
maxHeight = this.useChange("", (value) => this.renderMaxHeight(value), { attribute: "max-height" });
|
|
115
|
-
/** What the table says when it has no rows. */
|
|
116
|
-
emptyText = this.useChange(
|
|
159
|
+
/** What the table says when it has no rows; jlib's own text when empty. */
|
|
160
|
+
emptyText = this.useChange("", () => this.schedule("body"), { attribute: "empty-text" });
|
|
117
161
|
/** Shows placeholder rows while the data loads. */
|
|
118
162
|
loading = this.useChange(false, (value) => {
|
|
119
163
|
this.reflect("loading", value);
|
|
@@ -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,11 +217,14 @@ 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. */
|
|
225
|
+
drawTexts() {
|
|
226
|
+
this.schedule("head", "body");
|
|
227
|
+
}
|
|
160
228
|
schedule(...parts) {
|
|
161
229
|
for (const part of parts) this._pending[part] = true;
|
|
162
230
|
if (this._pending.queued) return;
|
|
@@ -172,8 +240,11 @@ var JlTable = class extends JlElement {
|
|
|
172
240
|
this.renderSortState();
|
|
173
241
|
if (body) this.renderBody();
|
|
174
242
|
this.renderSelection();
|
|
243
|
+
this.renderExpansion();
|
|
175
244
|
}
|
|
176
|
-
sortBy(
|
|
245
|
+
sortBy(name) {
|
|
246
|
+
const key = this.columns.get().find((column) => column.key === name)?.key;
|
|
247
|
+
if (key === void 0) return;
|
|
177
248
|
const current = key === this.sortKey.get() ? this.sortDirection.get() : NO_SORT;
|
|
178
249
|
const direction = nextSortDirection(current);
|
|
179
250
|
this.sortKey.set(key);
|
|
@@ -190,18 +261,57 @@ var JlTable = class extends JlElement {
|
|
|
190
261
|
this.selected.set(keys);
|
|
191
262
|
this.events.emit("selection", keys);
|
|
192
263
|
}
|
|
264
|
+
/** A press on a row's chevron, or on the row anywhere but its controls and its checkbox, opens or closes it. */
|
|
265
|
+
pressRow(event) {
|
|
266
|
+
const row = this.dataRowOf(event);
|
|
267
|
+
const key = row === void 0 ? void 0 : this.keyOf(row);
|
|
268
|
+
if (row === void 0 || key === void 0 || !this.opensOnPress(event, row)) return;
|
|
269
|
+
this.toggle(key, !row.hasAttribute(EXPANDED_ATTRIBUTE));
|
|
270
|
+
}
|
|
271
|
+
/** The row of data a press is on: one of the table's, not a row in the content of a detail. */
|
|
272
|
+
dataRowOf(event) {
|
|
273
|
+
const body = this._refs.body;
|
|
274
|
+
return event.composedPath().find((target) => target instanceof HTMLTableRowElement && target.parentElement === body && target.dataset.index !== void 0);
|
|
275
|
+
}
|
|
276
|
+
opensOnPress(event, row) {
|
|
277
|
+
const path = event.composedPath();
|
|
278
|
+
const chevron = row.querySelector("button.expand");
|
|
279
|
+
if (chevron === null) return false;
|
|
280
|
+
const select = row.querySelector(".select-cell");
|
|
281
|
+
const elsewhere = startedOnControl(event, row) || select !== null && path.includes(select) || isSelectingText();
|
|
282
|
+
return path.includes(chevron) || !elsewhere;
|
|
283
|
+
}
|
|
193
284
|
renderMaxHeight(value) {
|
|
194
285
|
const height = /^\d+(\.\d+)?$/.test(value.trim()) ? `${value.trim()}px` : value;
|
|
195
286
|
this.style.setProperty("--max-height", height === "" ? "none" : height);
|
|
196
287
|
this.reflect("scrolls", height !== "");
|
|
197
288
|
}
|
|
289
|
+
isExpandable() {
|
|
290
|
+
return this.expandable.get() !== NO_EXPANSION;
|
|
291
|
+
}
|
|
292
|
+
/** The number of cells in a row: the columns, after the checkbox and the chevron when there are. */
|
|
293
|
+
span(columns) {
|
|
294
|
+
return columns.length + Number(this.selectable.get()) + Number(this.isExpandable());
|
|
295
|
+
}
|
|
198
296
|
renderHead() {
|
|
199
297
|
const selectAll = this.selectable.get() ? /* @__PURE__ */ jsx("th", {
|
|
200
298
|
class: "select-cell",
|
|
201
299
|
scope: "col",
|
|
202
|
-
children: checkbox("
|
|
300
|
+
children: checkbox(jlText("selectAllRows"), null)
|
|
203
301
|
}) : null;
|
|
204
|
-
this.
|
|
302
|
+
const details = this.isExpandable() ? /* @__PURE__ */ jsx("th", {
|
|
303
|
+
class: "expand-cell",
|
|
304
|
+
scope: "col",
|
|
305
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
306
|
+
class: "sr-only",
|
|
307
|
+
children: jlText("details")
|
|
308
|
+
})
|
|
309
|
+
}) : null;
|
|
310
|
+
this._refs.head.replaceChildren(/* @__PURE__ */ jsxs("tr", { children: [
|
|
311
|
+
selectAll,
|
|
312
|
+
details,
|
|
313
|
+
this.columns.get().map((column) => this.headerCell(column))
|
|
314
|
+
] }));
|
|
205
315
|
}
|
|
206
316
|
headerCell(column) {
|
|
207
317
|
const content = column.sortable ? /* @__PURE__ */ jsxs("button", {
|
|
@@ -240,41 +350,65 @@ var JlTable = class extends JlElement {
|
|
|
240
350
|
}
|
|
241
351
|
renderBody() {
|
|
242
352
|
const columns = this.columns.get();
|
|
243
|
-
const span = columns.length + Number(this.selectable.get());
|
|
244
353
|
if (this.loading.get()) {
|
|
245
|
-
this.
|
|
354
|
+
this.setView([], []);
|
|
246
355
|
this._refs.body.replaceChildren(...this.skeletonRows(columns));
|
|
247
356
|
return;
|
|
248
357
|
}
|
|
249
358
|
const rows = this.rows.get();
|
|
250
359
|
if (rows.length === 0) {
|
|
251
|
-
this.
|
|
252
|
-
this._refs.body.replaceChildren(this.emptyRow(span));
|
|
360
|
+
this.setView([], []);
|
|
361
|
+
this._refs.body.replaceChildren(this.emptyRow(this.span(columns)));
|
|
253
362
|
return;
|
|
254
363
|
}
|
|
255
364
|
const keyField = this.rowKey.get();
|
|
256
365
|
const keys = new Map(rows.map((row, index) => [row, rowKeyOf(row, keyField, index)]));
|
|
257
366
|
const sorted = this.sortedRows();
|
|
258
|
-
this.
|
|
367
|
+
this.setView(sorted, sorted.map((row, index) => keys.get(row) ?? index));
|
|
259
368
|
this._refs.body.replaceChildren(...sorted.map((row, index) => this.bodyRow(row, index, columns)));
|
|
260
369
|
this.renderMarks();
|
|
261
370
|
}
|
|
371
|
+
setView(rows, keys) {
|
|
372
|
+
this._view.rows = rows;
|
|
373
|
+
this._view.keys = keys;
|
|
374
|
+
}
|
|
262
375
|
bodyRow(row, index, columns) {
|
|
263
376
|
const first = columns[0];
|
|
264
|
-
const name = first === void 0 ? String(index + 1) : formatCell(row
|
|
377
|
+
const name = first === void 0 ? String(index + 1) : formatCell(fieldOf(row, first.key), first.format);
|
|
265
378
|
const select = this.selectable.get() ? /* @__PURE__ */ jsx("td", {
|
|
266
379
|
class: "select-cell",
|
|
267
|
-
children: checkbox(
|
|
380
|
+
children: checkbox(jlText("selectNamed", { name }), index)
|
|
268
381
|
}) : null;
|
|
269
|
-
|
|
270
|
-
class:
|
|
271
|
-
children:
|
|
272
|
-
|
|
382
|
+
const chevron = this.isExpandable() ? /* @__PURE__ */ jsx("td", {
|
|
383
|
+
class: "expand-cell",
|
|
384
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
385
|
+
type: "button",
|
|
386
|
+
class: "expand",
|
|
387
|
+
"aria-expanded": "false",
|
|
388
|
+
"aria-label": jlText("detailsOf", { name }),
|
|
389
|
+
children: /* @__PURE__ */ jsx(JlIcon, {
|
|
390
|
+
class: "chevron",
|
|
391
|
+
name: "chevron-right",
|
|
392
|
+
size: CHEVRON_SIZE
|
|
393
|
+
})
|
|
394
|
+
})
|
|
395
|
+
}) : null;
|
|
396
|
+
return /* @__PURE__ */ jsxs("tr", {
|
|
397
|
+
"data-index": index,
|
|
398
|
+
children: [
|
|
399
|
+
select,
|
|
400
|
+
chevron,
|
|
401
|
+
columns.map((column) => /* @__PURE__ */ jsx("td", {
|
|
402
|
+
class: `align-${columnAlign(column)} format-${column.format ?? "text"}${column.wrap ? " wrap" : ""}`,
|
|
403
|
+
children: this.cell(row, column)
|
|
404
|
+
}))
|
|
405
|
+
]
|
|
406
|
+
});
|
|
273
407
|
}
|
|
274
408
|
/** A cell's value, drawn by its renderer or in its format, with the row's description under it when it has one. */
|
|
275
409
|
cell(row, column) {
|
|
276
410
|
const value = this.cellValue(row, column);
|
|
277
|
-
const description = column.description === void 0 ? "" : formatCell(row
|
|
411
|
+
const description = column.description === void 0 ? "" : formatCell(fieldOf(row, column.description));
|
|
278
412
|
if (description === "") return value;
|
|
279
413
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("div", {
|
|
280
414
|
class: "cell-value",
|
|
@@ -288,19 +422,24 @@ var JlTable = class extends JlElement {
|
|
|
288
422
|
const renderer = this.renderers.get()[column.key];
|
|
289
423
|
if (renderer !== void 0) return renderer(row);
|
|
290
424
|
const format = column.format ?? "text";
|
|
291
|
-
return CELL_MAKERS[format](formatCell(row
|
|
425
|
+
return CELL_MAKERS[format](formatCell(fieldOf(row, column.key), format), column);
|
|
292
426
|
}
|
|
293
427
|
skeletonRows(columns) {
|
|
294
428
|
const select = this.selectable.get();
|
|
429
|
+
const expand = this.isExpandable();
|
|
295
430
|
return Array.from({ length: SKELETON_ROWS }, () => /* @__PURE__ */ jsxs("tr", {
|
|
296
431
|
class: "skeleton",
|
|
297
|
-
children: [
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
432
|
+
children: [
|
|
433
|
+
select ? /* @__PURE__ */ jsx("td", {
|
|
434
|
+
class: "select-cell",
|
|
435
|
+
children: /* @__PURE__ */ jsx("span", { class: "bone box" })
|
|
436
|
+
}) : null,
|
|
437
|
+
expand ? /* @__PURE__ */ jsx("td", { class: "expand-cell" }) : null,
|
|
438
|
+
columns.map((column) => /* @__PURE__ */ jsx("td", {
|
|
439
|
+
class: `align-${columnAlign(column)}`,
|
|
440
|
+
children: /* @__PURE__ */ jsx("span", { class: "bone" })
|
|
441
|
+
}))
|
|
442
|
+
]
|
|
304
443
|
}));
|
|
305
444
|
}
|
|
306
445
|
emptyRow(span) {
|
|
@@ -313,24 +452,69 @@ var JlTable = class extends JlElement {
|
|
|
313
452
|
children: [/* @__PURE__ */ jsx(JlIcon, {
|
|
314
453
|
name: "inbox",
|
|
315
454
|
size: EMPTY_ICON_SIZE
|
|
316
|
-
}), /* @__PURE__ */ jsx("span", { children: this.emptyText.get() })]
|
|
455
|
+
}), /* @__PURE__ */ jsx("span", { children: this.emptyText.get() || jlText("noData") })]
|
|
317
456
|
})
|
|
318
457
|
})
|
|
319
458
|
});
|
|
320
459
|
}
|
|
321
|
-
/** The
|
|
460
|
+
/** The rows of data, without the details under the open ones. */
|
|
461
|
+
dataRows() {
|
|
462
|
+
return [...this._refs.body.querySelectorAll(":scope > tr[data-index]")];
|
|
463
|
+
}
|
|
464
|
+
keyOf(row) {
|
|
465
|
+
return this._view.keys[Number(row.dataset.index)];
|
|
466
|
+
}
|
|
467
|
+
/** The bar and the shade of marked rows, changed in place. */
|
|
322
468
|
renderMarks() {
|
|
323
469
|
const marked = new Set(this.marked.get());
|
|
324
|
-
const
|
|
325
|
-
|
|
326
|
-
const key = this._view.keys[index];
|
|
470
|
+
for (const row of this.dataRows()) {
|
|
471
|
+
const key = this.keyOf(row);
|
|
327
472
|
row.toggleAttribute(MARKED_ATTRIBUTE, key !== void 0 && marked.has(key));
|
|
328
473
|
}
|
|
329
474
|
}
|
|
475
|
+
/** The details of the open rows, added under them and taken away in place: one that stays open keeps its content. */
|
|
476
|
+
renderExpansion() {
|
|
477
|
+
const open = new Set(openRows(this.expanded.get(), this.expandable.get()));
|
|
478
|
+
for (const row of this.dataRows()) {
|
|
479
|
+
const key = this.keyOf(row);
|
|
480
|
+
this.renderRowOpen(row, key !== void 0 && open.has(key));
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
renderRowOpen(row, open) {
|
|
484
|
+
const chevron = row.querySelector("button.expand");
|
|
485
|
+
if (chevron === null) return;
|
|
486
|
+
row.toggleAttribute(EXPANDED_ATTRIBUTE, open);
|
|
487
|
+
chevron.setAttribute("aria-expanded", String(open));
|
|
488
|
+
const detail = detailOf(row);
|
|
489
|
+
if (!open) {
|
|
490
|
+
detail?.remove();
|
|
491
|
+
chevron.removeAttribute("aria-controls");
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
if (detail !== null) return;
|
|
495
|
+
const id = `${DETAIL_ID_PREFIX}${row.dataset.index}`;
|
|
496
|
+
row.after(this.detailRow(row, id));
|
|
497
|
+
chevron.setAttribute("aria-controls", id);
|
|
498
|
+
}
|
|
499
|
+
detailRow(row, id) {
|
|
500
|
+
const data = this._view.rows[Number(row.dataset.index)];
|
|
501
|
+
const draw = this._source.detail;
|
|
502
|
+
return /* @__PURE__ */ jsx("tr", {
|
|
503
|
+
class: "detail",
|
|
504
|
+
id,
|
|
505
|
+
children: /* @__PURE__ */ jsx("td", {
|
|
506
|
+
colSpan: this.span(this.columns.get()),
|
|
507
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
508
|
+
class: "detail-body",
|
|
509
|
+
children: data === void 0 || draw === null ? "" : draw(data)
|
|
510
|
+
})
|
|
511
|
+
})
|
|
512
|
+
});
|
|
513
|
+
}
|
|
330
514
|
/** The checkboxes and the shading of selected rows, changed in place. */
|
|
331
515
|
renderSelection() {
|
|
332
516
|
const selected = new Set(this.selected.get());
|
|
333
|
-
for (const input of this._refs.body.querySelectorAll("
|
|
517
|
+
for (const input of this._refs.body.querySelectorAll(":scope > tr > .select-cell .checkbox")) {
|
|
334
518
|
const key = this._view.keys[Number(input.dataset.index)];
|
|
335
519
|
const on = key !== void 0 && selected.has(key);
|
|
336
520
|
input.checked = on;
|
|
@@ -345,4 +529,4 @@ var JlTable = class extends JlElement {
|
|
|
345
529
|
}
|
|
346
530
|
};
|
|
347
531
|
JlTable.register();
|
|
348
|
-
export { JlTable, TABLE_SORT_DIRECTIONS };
|
|
532
|
+
export { JlTable, TABLE_EXPANSIONS, TABLE_SORT_DIRECTIONS };
|
|
@@ -31,6 +31,7 @@ export declare class JlToaster extends JlElement {
|
|
|
31
31
|
notify(options: ToastOptions): ToastHandle;
|
|
32
32
|
templateHtml(): Node;
|
|
33
33
|
templateCss(): string;
|
|
34
|
+
protected drawTexts(): void;
|
|
34
35
|
onConnect(): void;
|
|
35
36
|
onDisconnect(): void;
|
|
36
37
|
private toasts;
|
|
@@ -49,7 +50,7 @@ export declare class JlToaster extends JlElement {
|
|
|
49
50
|
* Returns a handle to close it early.
|
|
50
51
|
*/
|
|
51
52
|
export declare function toast(options: ToastOptions): ToastHandle;
|
|
52
|
-
/** A download's texts, in
|
|
53
|
+
/** A download's texts, in jlib's language, their placeholders left to fill: what `download()` says unless told otherwise. */
|
|
53
54
|
export declare const downloadTexts: () => DownloadTexts;
|
|
54
55
|
/**
|
|
55
56
|
* Downloads a file with its progress in a toast of the page's toaster: the time the server takes to prepare it,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { fillText } from "../lib/text.js";
|
|
2
|
+
import { jlTemplate, jlText } from "../lib/texts.js";
|
|
1
3
|
import { BASE_STYLES } from "../styles/shared.js";
|
|
2
4
|
import { JlElement } from "../base/jl-element.js";
|
|
3
5
|
import { clampedNumber, oneOf } from "../lib/attributes.js";
|
|
4
6
|
import { registerIcons } from "../lib/icons.js";
|
|
5
7
|
import { formatDuration } from "../lib/time.js";
|
|
6
|
-
import { fillText } from "../lib/text.js";
|
|
7
|
-
import { jlText } from "../lib/texts.js";
|
|
8
8
|
import { formatFileSize } from "../lib/files.js";
|
|
9
9
|
import { JlToast } from "../molecules/jl-toast.js";
|
|
10
10
|
import { answerError, dispositionFileName, readWithProgress, saveBlob, urlFileName } from "../lib/download.js";
|
|
@@ -63,7 +63,7 @@ var JlToaster = class extends JlElement {
|
|
|
63
63
|
parse: clampedNumber(DEFAULT_MAX, 1, MAX_LIMIT)
|
|
64
64
|
});
|
|
65
65
|
/** The region's name for screen readers. */
|
|
66
|
-
label = this.useChange(
|
|
66
|
+
label = this.useChange("", () => this.drawTexts(), { attribute: "label" });
|
|
67
67
|
_watched = /* @__PURE__ */ new WeakSet();
|
|
68
68
|
_refs = this.useRefs((ref) => ({
|
|
69
69
|
region: ref(".region"),
|
|
@@ -110,6 +110,9 @@ var JlToaster = class extends JlElement {
|
|
|
110
110
|
templateCss() {
|
|
111
111
|
return css`${BASE_STYLES}${jl_toaster_default}`;
|
|
112
112
|
}
|
|
113
|
+
drawTexts() {
|
|
114
|
+
this._refs.region.setAttribute("aria-label", this.label.get() || jlText("notifications"));
|
|
115
|
+
}
|
|
113
116
|
onConnect() {
|
|
114
117
|
this.renderStack();
|
|
115
118
|
this.on(this._refs.slot, "slotchange", () => this.renderStack());
|
|
@@ -185,14 +188,14 @@ var PERCENT = 100;
|
|
|
185
188
|
var FALLBACK_NAME = "download";
|
|
186
189
|
var CONTENT_LENGTH = "content-length";
|
|
187
190
|
var CONTENT_DISPOSITION = "content-disposition";
|
|
188
|
-
/** A download's texts, in
|
|
191
|
+
/** A download's texts, in jlib's language, their placeholders left to fill: what `download()` says unless told otherwise. */
|
|
189
192
|
var downloadTexts = () => ({
|
|
190
193
|
cancel: jlText("downloadCancel"),
|
|
191
|
-
failed:
|
|
192
|
-
preparing:
|
|
193
|
-
received:
|
|
194
|
-
receivedOf:
|
|
195
|
-
saved:
|
|
194
|
+
failed: jlTemplate("downloadFailed"),
|
|
195
|
+
preparing: jlTemplate("downloadPreparing"),
|
|
196
|
+
received: jlTemplate("downloadReceived"),
|
|
197
|
+
receivedOf: jlTemplate("downloadReceivedOf"),
|
|
198
|
+
saved: jlTemplate("downloadSaved")
|
|
196
199
|
});
|
|
197
200
|
/** The toast's text and bar for the bytes received: a share of the size when the server said it. */
|
|
198
201
|
function receiving(received, total, texts) {
|
|
@@ -41,22 +41,22 @@ export declare class JlTree extends JlElement {
|
|
|
41
41
|
get(): string;
|
|
42
42
|
set(setter: string | ((prevState: string) => string)): void;
|
|
43
43
|
}>>;
|
|
44
|
-
/** Said while a page loads. */
|
|
44
|
+
/** Said while a page loads; jlib's own text when empty. */
|
|
45
45
|
readonly loadingText: Readonly<Readonly<{
|
|
46
46
|
get(): string;
|
|
47
47
|
set(setter: string | ((prevState: string) => string)): void;
|
|
48
48
|
}>>;
|
|
49
|
-
/** The button that loads a level's next page
|
|
49
|
+
/** The button that loads a level's next page, `{count}` being how many items are left; jlib's own when empty. */
|
|
50
50
|
readonly moreText: Readonly<Readonly<{
|
|
51
51
|
get(): string;
|
|
52
52
|
set(setter: string | ((prevState: string) => string)): void;
|
|
53
53
|
}>>;
|
|
54
|
-
/** Said where a page could not be loaded. */
|
|
54
|
+
/** Said where a page could not be loaded; jlib's own text when empty. */
|
|
55
55
|
readonly errorText: Readonly<Readonly<{
|
|
56
56
|
get(): string;
|
|
57
57
|
set(setter: string | ((prevState: string) => string)): void;
|
|
58
58
|
}>>;
|
|
59
|
-
/** The action that loads it again. */
|
|
59
|
+
/** The action that loads it again; jlib's own text when empty. */
|
|
60
60
|
readonly retryLabel: Readonly<Readonly<{
|
|
61
61
|
get(): string;
|
|
62
62
|
set(setter: string | ((prevState: string) => string)): void;
|
|
@@ -109,6 +109,8 @@ export declare class JlTree extends JlElement {
|
|
|
109
109
|
private openFolder;
|
|
110
110
|
private levelEnd;
|
|
111
111
|
private hasLevelEndRow;
|
|
112
|
+
protected drawTexts(): void;
|
|
113
|
+
private errorLabel;
|
|
112
114
|
private renderItems;
|
|
113
115
|
private itemNode;
|
|
114
116
|
/** The row that ends a level, if it has one. */
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
+
import { pageLocale } from "../lib/locale.js";
|
|
2
|
+
import { jlTemplate, jlText } from "../lib/texts.js";
|
|
1
3
|
import { BASE_STYLES } from "../styles/shared.js";
|
|
2
4
|
import { JlElement } from "../base/jl-element.js";
|
|
3
5
|
import { jsonOf } from "../lib/attributes.js";
|
|
4
6
|
import { registerIcons } from "../lib/icons.js";
|
|
5
|
-
import { jlText } from "../lib/texts.js";
|
|
6
7
|
import { JlIcon } from "../atoms/jl-icon.js";
|
|
7
8
|
import { isModifiedClick, setOrRemove, uniqueId } from "../lib/dom.js";
|
|
8
9
|
import { JlSpinner } from "../atoms/jl-spinner.js";
|
|
9
|
-
import { pageLocale } from "../lib/locale.js";
|
|
10
10
|
import { allItems, childrenOf, isFolder, treeKeyAction, withExpanded, withExtraRows, withPage } from "../lib/tree.js";
|
|
11
11
|
import jl_tree_default from "./jl-tree.css_raw.js";
|
|
12
12
|
import { css } from "@jadis/core";
|
|
@@ -61,14 +61,14 @@ var JlTree = class extends JlElement {
|
|
|
61
61
|
label = this.useChange("", (value) => setOrRemove(this._refs.tree, "aria-label", value), { attribute: "label" });
|
|
62
62
|
/** What an empty tree says, such as "No object yet"; none by default. */
|
|
63
63
|
emptyText = this.useChange("", () => this.renderItems(), { attribute: "empty-text" });
|
|
64
|
-
/** Said while a page loads. */
|
|
65
|
-
loadingText = this.useChange(
|
|
66
|
-
/** The button that loads a level's next page
|
|
67
|
-
moreText = this.useChange(
|
|
68
|
-
/** Said where a page could not be loaded. */
|
|
69
|
-
errorText = this.useChange(
|
|
70
|
-
/** The action that loads it again. */
|
|
71
|
-
retryLabel = this.useChange(
|
|
64
|
+
/** Said while a page loads; jlib's own text when empty. */
|
|
65
|
+
loadingText = this.useChange("", () => this.renderItems(), { attribute: "loading-text" });
|
|
66
|
+
/** The button that loads a level's next page, `{count}` being how many items are left; jlib's own when empty. */
|
|
67
|
+
moreText = this.useChange("", () => this.renderItems(), { attribute: "more-text" });
|
|
68
|
+
/** Said where a page could not be loaded; jlib's own text when empty. */
|
|
69
|
+
errorText = this.useChange("", () => this.renderItems(), { attribute: "error-text" });
|
|
70
|
+
/** The action that loads it again; jlib's own text when empty. */
|
|
71
|
+
retryLabel = this.useChange("", () => this.renderItems(), { attribute: "retry-label" });
|
|
72
72
|
_source = { loader: null };
|
|
73
73
|
_rows = /* @__PURE__ */ new Map();
|
|
74
74
|
_focus = { id: "" };
|
|
@@ -245,7 +245,7 @@ var JlTree = class extends JlElement {
|
|
|
245
245
|
if (generation !== this._loading.generation) return;
|
|
246
246
|
const total = this._loading.levels.get(parent)?.total ?? 0;
|
|
247
247
|
this._loading.levels.set(parent, {
|
|
248
|
-
error: messageOf(error) || this.
|
|
248
|
+
error: messageOf(error) || this.errorLabel(),
|
|
249
249
|
pending: null,
|
|
250
250
|
total
|
|
251
251
|
});
|
|
@@ -277,6 +277,12 @@ var JlTree = class extends JlElement {
|
|
|
277
277
|
const end = this.levelEnd(parent);
|
|
278
278
|
return end !== "none" && end !== "empty";
|
|
279
279
|
}
|
|
280
|
+
drawTexts() {
|
|
281
|
+
this.renderItems();
|
|
282
|
+
}
|
|
283
|
+
errorLabel() {
|
|
284
|
+
return this.errorText.get() || jlText("loadError");
|
|
285
|
+
}
|
|
280
286
|
renderItems() {
|
|
281
287
|
const hadFocus = this.hasFocusInside();
|
|
282
288
|
this._rows.clear();
|
|
@@ -379,7 +385,7 @@ var JlTree = class extends JlElement {
|
|
|
379
385
|
return node;
|
|
380
386
|
}
|
|
381
387
|
loadingNode(parent, level) {
|
|
382
|
-
const text = this.loadingText.get();
|
|
388
|
+
const text = this.loadingText.get() || jlText("loadingMore");
|
|
383
389
|
return this.levelEndRow(parent, level, [/* @__PURE__ */ jsx(JlSpinner, {
|
|
384
390
|
class: "spinner",
|
|
385
391
|
size: ICON_SIZE,
|
|
@@ -392,7 +398,7 @@ var JlTree = class extends JlElement {
|
|
|
392
398
|
}
|
|
393
399
|
moreNode(parent, level) {
|
|
394
400
|
const left = (this._loading.levels.get(parent)?.total ?? 0) - childrenOf(this.items.get(), parent).length;
|
|
395
|
-
const text = this.moreText.get().replace(COUNT_PLACEHOLDER, left.toLocaleString(pageLocale()));
|
|
401
|
+
const text = (this.moreText.get() || jlTemplate("showMoreCount")).replace(COUNT_PLACEHOLDER, left.toLocaleString(pageLocale()));
|
|
396
402
|
return this.levelEndRow(parent, level, [/* @__PURE__ */ jsx("span", {
|
|
397
403
|
class: "label more",
|
|
398
404
|
children: text
|
|
@@ -407,11 +413,11 @@ var JlTree = class extends JlElement {
|
|
|
407
413
|
}),
|
|
408
414
|
/* @__PURE__ */ jsx("span", {
|
|
409
415
|
class: "label",
|
|
410
|
-
children: this.
|
|
416
|
+
children: this.errorLabel()
|
|
411
417
|
}),
|
|
412
418
|
/* @__PURE__ */ jsx("span", {
|
|
413
419
|
class: "retry",
|
|
414
|
-
children: this.retryLabel.get()
|
|
420
|
+
children: this.retryLabel.get() || jlText("retry")
|
|
415
421
|
})
|
|
416
422
|
], false);
|
|
417
423
|
setOrRemove(node, "title", this._loading.levels.get(parent)?.error ?? "");
|
|
@@ -33,6 +33,7 @@ export declare class JlAppShell extends JlElement {
|
|
|
33
33
|
toggleNav(force?: boolean): void;
|
|
34
34
|
templateHtml(): Node;
|
|
35
35
|
templateCss(): string;
|
|
36
|
+
protected drawTexts(): void;
|
|
36
37
|
onConnect(): void;
|
|
37
38
|
onDisconnect(): void;
|
|
38
39
|
/** Tells the page how much the tab bar covers at the bottom of the window, while it shows. */
|