@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
|
@@ -4,19 +4,21 @@ import type { PaletteCommand } from '../types/jl-command-palette.types';
|
|
|
4
4
|
* A search box over every command of an app, opened by ⌘K (Ctrl+K off Apple) or `show()`. Typing filters the
|
|
5
5
|
* commands by their letters in order, best matches first, under their groups; arrows move, Enter runs the command
|
|
6
6
|
* (`select` with its id) and Escape closes. It sits near the top of the window, on the browser's modal `<dialog>`.
|
|
7
|
+
* Typed by its ids, `JlCommandPalette<'theme' | 'logout'>` takes commands of those ids and gives `select` one of
|
|
8
|
+
* them.
|
|
7
9
|
*/
|
|
8
|
-
export declare class JlCommandPalette extends JlElement {
|
|
10
|
+
export declare class JlCommandPalette<Id extends string = string> extends JlElement {
|
|
9
11
|
static readonly selector = "jl-command-palette";
|
|
10
12
|
/** `search`: what was typed, once typing pauses (and empty when it opens), for a page that answers it. */
|
|
11
13
|
readonly events: Readonly<import("@jadis/core").UseEventsHandler<{
|
|
12
|
-
select:
|
|
14
|
+
select: Id;
|
|
13
15
|
open: undefined;
|
|
14
16
|
close: undefined;
|
|
15
17
|
search: string;
|
|
16
18
|
}>>;
|
|
17
19
|
readonly commands: Readonly<Readonly<{
|
|
18
|
-
get(): PaletteCommand[];
|
|
19
|
-
set(setter: PaletteCommand[] | ((prevState: PaletteCommand[]) => PaletteCommand[])): void;
|
|
20
|
+
get(): PaletteCommand<Id>[];
|
|
21
|
+
set(setter: PaletteCommand<Id>[] | ((prevState: PaletteCommand<Id>[]) => PaletteCommand<Id>[])): void;
|
|
20
22
|
}>>;
|
|
21
23
|
readonly open: Readonly<Readonly<{
|
|
22
24
|
get(): boolean;
|
|
@@ -34,6 +34,8 @@ function highlighted(label, positions) {
|
|
|
34
34
|
* A search box over every command of an app, opened by ⌘K (Ctrl+K off Apple) or `show()`. Typing filters the
|
|
35
35
|
* commands by their letters in order, best matches first, under their groups; arrows move, Enter runs the command
|
|
36
36
|
* (`select` with its id) and Escape closes. It sits near the top of the window, on the browser's modal `<dialog>`.
|
|
37
|
+
* Typed by its ids, `JlCommandPalette<'theme' | 'logout'>` takes commands of those ids and gives `select` one of
|
|
38
|
+
* them.
|
|
37
39
|
*/
|
|
38
40
|
var JlCommandPalette = class extends JlElement {
|
|
39
41
|
static selector = "jl-command-palette";
|
|
@@ -4,23 +4,24 @@ import type { SideNavSection } from '../types/jl-side-nav.types';
|
|
|
4
4
|
* The navigation of an app, down its side: sections of items with icons, badges and nested items that open with
|
|
5
5
|
* a chevron. `value` is the active item (its parents open to show it); `collapsed` makes it a rail of icons, with
|
|
6
6
|
* the labels as tooltips, and `collapsible` lets people fold and unfold it with a button at its bottom. Items with
|
|
7
|
-
* an `href` are links; the others fire `select`.
|
|
7
|
+
* an `href` are links; the others fire `select`. Typed by its ids, `JlSideNav<'jobs' | 'people'>` takes items of
|
|
8
|
+
* those ids and gives `select` one of them.
|
|
8
9
|
*/
|
|
9
|
-
export declare class JlSideNav extends JlElement {
|
|
10
|
+
export declare class JlSideNav<Id extends string = string> extends JlElement {
|
|
10
11
|
static readonly selector = "jl-side-nav";
|
|
11
12
|
/** `collapse`: people folded the side nav into its rail (true) or unfolded it (false), for the app to remember. */
|
|
12
13
|
readonly events: Readonly<import("@jadis/core").UseEventsHandler<{
|
|
13
|
-
select:
|
|
14
|
+
select: Id;
|
|
14
15
|
collapse: boolean;
|
|
15
16
|
}>>;
|
|
16
17
|
readonly sections: Readonly<Readonly<{
|
|
17
|
-
get(): SideNavSection[];
|
|
18
|
-
set(setter: SideNavSection[] | ((prevState: SideNavSection[]) => SideNavSection[])): void;
|
|
18
|
+
get(): SideNavSection<Id>[];
|
|
19
|
+
set(setter: SideNavSection<Id>[] | ((prevState: SideNavSection<Id>[]) => SideNavSection<Id>[])): void;
|
|
19
20
|
}>>;
|
|
20
21
|
/** The id of the active item. */
|
|
21
22
|
readonly value: Readonly<Readonly<{
|
|
22
|
-
get():
|
|
23
|
-
set(setter:
|
|
23
|
+
get(): "" | Id;
|
|
24
|
+
set(setter: "" | Id | ((prevState: "" | Id) => "" | Id)): void;
|
|
24
25
|
}>>;
|
|
25
26
|
/** Shows only the icons, in a narrow rail; the labels become tooltips. */
|
|
26
27
|
readonly collapsed: Readonly<Readonly<{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BASE_STYLES } from "../styles/shared.js";
|
|
2
2
|
import { JlElement } from "../base/jl-element.js";
|
|
3
|
-
import { jsonOf } from "../lib/attributes.js";
|
|
3
|
+
import { jsonOf, textOf } from "../lib/attributes.js";
|
|
4
4
|
import { registerIcons } from "../lib/icons.js";
|
|
5
5
|
import { jlText } from "../lib/texts.js";
|
|
6
6
|
import { JlIcon } from "../atoms/jl-icon.js";
|
|
@@ -24,6 +24,7 @@ var EXPAND_ICON = "panel-left-open";
|
|
|
24
24
|
var ROW_SELECTOR = ".item";
|
|
25
25
|
var NEW_TAB = "_blank";
|
|
26
26
|
var SAFE_REL = "noopener noreferrer";
|
|
27
|
+
var NO_ITEM = "";
|
|
27
28
|
/** A JSON attribute that should hold a list of sections; anything else gives none. */
|
|
28
29
|
var parseSections = (value) => {
|
|
29
30
|
const parsed = jsonOf([])(value);
|
|
@@ -36,7 +37,8 @@ var isReachable = (row) => row.closest("[hidden]") === null && row.offsetParent
|
|
|
36
37
|
* The navigation of an app, down its side: sections of items with icons, badges and nested items that open with
|
|
37
38
|
* a chevron. `value` is the active item (its parents open to show it); `collapsed` makes it a rail of icons, with
|
|
38
39
|
* the labels as tooltips, and `collapsible` lets people fold and unfold it with a button at its bottom. Items with
|
|
39
|
-
* an `href` are links; the others fire `select`.
|
|
40
|
+
* an `href` are links; the others fire `select`. Typed by its ids, `JlSideNav<'jobs' | 'people'>` takes items of
|
|
41
|
+
* those ids and gives `select` one of them.
|
|
40
42
|
*/
|
|
41
43
|
var JlSideNav = class extends JlElement {
|
|
42
44
|
static selector = "jl-side-nav";
|
|
@@ -47,7 +49,10 @@ var JlSideNav = class extends JlElement {
|
|
|
47
49
|
parse: parseSections
|
|
48
50
|
});
|
|
49
51
|
/** The id of the active item. */
|
|
50
|
-
value = this.useChange(
|
|
52
|
+
value = this.useChange(NO_ITEM, (value) => this.renderActive(value), {
|
|
53
|
+
attribute: "value",
|
|
54
|
+
parse: textOf(NO_ITEM)
|
|
55
|
+
});
|
|
51
56
|
/** Shows only the icons, in a narrow rail; the labels become tooltips. */
|
|
52
57
|
collapsed = this.useChange(false, (value) => {
|
|
53
58
|
this.reflect("collapsed", value);
|
|
@@ -122,7 +127,7 @@ var JlSideNav = class extends JlElement {
|
|
|
122
127
|
this.toggleItem(item.id);
|
|
123
128
|
return;
|
|
124
129
|
}
|
|
125
|
-
this.choose(row?.dataset.target ?? item.id);
|
|
130
|
+
this.choose(findItem(this.sections.get(), row?.dataset.target ?? "")?.id ?? item.id);
|
|
126
131
|
}
|
|
127
132
|
/** Whether it shows as the rail now: folded, and not in a drawer. */
|
|
128
133
|
isRail() {
|
|
@@ -4,22 +4,23 @@ import type { TabBarItem } from '../types/jl-tab-bar.types';
|
|
|
4
4
|
* The bar along the bottom of a phone, under the thumb: the three to five main places of an app, an icon over a
|
|
5
5
|
* label, one tap away. `value` is the current item. Items with an `href` are links; the others are buttons; both
|
|
6
6
|
* fire `select`. `more` adds a last button for everything else, which fires `more`: in a `jl-app-shell`, it opens
|
|
7
|
-
* the navigation drawer.
|
|
7
|
+
* the navigation drawer. Typed by its ids, `JlTabBar<'home' | 'jobs'>` takes items of those ids and gives `select`
|
|
8
|
+
* one of them.
|
|
8
9
|
*/
|
|
9
|
-
export declare class JlTabBar extends JlElement {
|
|
10
|
+
export declare class JlTabBar<Id extends string = string> extends JlElement {
|
|
10
11
|
static readonly selector = "jl-tab-bar";
|
|
11
12
|
readonly events: Readonly<import("@jadis/core").UseEventsHandler<{
|
|
12
|
-
select:
|
|
13
|
+
select: Id;
|
|
13
14
|
more: undefined;
|
|
14
15
|
}>>;
|
|
15
16
|
readonly items: Readonly<Readonly<{
|
|
16
|
-
get(): TabBarItem[];
|
|
17
|
-
set(setter: TabBarItem[] | ((prevState: TabBarItem[]) => TabBarItem[])): void;
|
|
17
|
+
get(): TabBarItem<Id>[];
|
|
18
|
+
set(setter: TabBarItem<Id>[] | ((prevState: TabBarItem<Id>[]) => TabBarItem<Id>[])): void;
|
|
18
19
|
}>>;
|
|
19
20
|
/** The id of the current item. */
|
|
20
21
|
readonly value: Readonly<Readonly<{
|
|
21
|
-
get():
|
|
22
|
-
set(setter:
|
|
22
|
+
get(): "" | Id;
|
|
23
|
+
set(setter: "" | Id | ((prevState: "" | Id) => "" | Id)): void;
|
|
23
24
|
}>>;
|
|
24
25
|
/** The label of a last button for the other places (`More`); empty shows none. */
|
|
25
26
|
readonly more: Readonly<Readonly<{
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BASE_STYLES } from "../styles/shared.js";
|
|
2
2
|
import { JlElement } from "../base/jl-element.js";
|
|
3
|
-
import { jsonOf } from "../lib/attributes.js";
|
|
3
|
+
import { jsonOf, textOf } from "../lib/attributes.js";
|
|
4
4
|
import { registerIcons } from "../lib/icons.js";
|
|
5
5
|
import { jlText } from "../lib/texts.js";
|
|
6
6
|
import { JlIcon } from "../atoms/jl-icon.js";
|
|
@@ -14,6 +14,7 @@ registerIcons({ ellipsis: Ellipsis });
|
|
|
14
14
|
var ICON_SIZE = 22;
|
|
15
15
|
var MAX_COUNT = 99;
|
|
16
16
|
var ITEM_SELECTOR = ".item";
|
|
17
|
+
var NO_ITEM = "";
|
|
17
18
|
/** A JSON attribute that should hold a list of items; anything else gives none. */
|
|
18
19
|
var parseItems = (value) => {
|
|
19
20
|
const parsed = jsonOf([])(value);
|
|
@@ -28,7 +29,8 @@ var badgeText = (badge) => {
|
|
|
28
29
|
* The bar along the bottom of a phone, under the thumb: the three to five main places of an app, an icon over a
|
|
29
30
|
* label, one tap away. `value` is the current item. Items with an `href` are links; the others are buttons; both
|
|
30
31
|
* fire `select`. `more` adds a last button for everything else, which fires `more`: in a `jl-app-shell`, it opens
|
|
31
|
-
* the navigation drawer.
|
|
32
|
+
* the navigation drawer. Typed by its ids, `JlTabBar<'home' | 'jobs'>` takes items of those ids and gives `select`
|
|
33
|
+
* one of them.
|
|
32
34
|
*/
|
|
33
35
|
var JlTabBar = class extends JlElement {
|
|
34
36
|
static selector = "jl-tab-bar";
|
|
@@ -38,7 +40,10 @@ var JlTabBar = class extends JlElement {
|
|
|
38
40
|
parse: parseItems
|
|
39
41
|
});
|
|
40
42
|
/** The id of the current item. */
|
|
41
|
-
value = this.useChange(
|
|
43
|
+
value = this.useChange(NO_ITEM, (value) => this.renderCurrent(value), {
|
|
44
|
+
attribute: "value",
|
|
45
|
+
parse: textOf(NO_ITEM)
|
|
46
|
+
});
|
|
42
47
|
/** The label of a last button for the other places (`More`); empty shows none. */
|
|
43
48
|
more = this.useChange("", (value) => {
|
|
44
49
|
this._refs.moreLabel.textContent = value;
|
|
@@ -77,7 +82,8 @@ var JlTabBar = class extends JlElement {
|
|
|
77
82
|
this.on(this._refs.more, "click", () => this.events.emit("more"));
|
|
78
83
|
}
|
|
79
84
|
onClick(event) {
|
|
80
|
-
const
|
|
85
|
+
const pressed = event.target.closest(ITEM_SELECTOR)?.dataset.id;
|
|
86
|
+
const id = this.items.get().find((item) => item.id === pressed)?.id;
|
|
81
87
|
if (id === void 0) return;
|
|
82
88
|
this.value.set(id);
|
|
83
89
|
this.events.emit("select", id);
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// src/organisms/jl-table.css?raw
|
|
2
|
-
var jl_table_default = ":host {\n display: block;\n /* The table scrolls sideways inside its frame: its width never pushes the page, or a grid around it, wider. */\n contain: inline-size;\n --max-height: none;\n --cell-y: 10px;\n --cell-x: 14px;\n}\n\n:host([dense]) {\n --cell-y: 6px;\n --cell-x: 12px;\n}\n\n.scroll {\n max-height: var(--max-height);\n overflow: auto;\n border: 1px solid var(--jl-line);\n border-radius: var(--jl-radius);\n background: var(--jl-surface);\n overscroll-behavior-x: contain;\n}\n\ntable {\n width: 100%;\n border-collapse: separate;\n border-spacing: 0;\n color: var(--jl-text);\n font-size: var(--jl-font-md);\n line-height: 20px;\n}\n\nth,\ntd {\n padding: var(--cell-y) var(--cell-x);\n white-space: nowrap;\n vertical-align: middle;\n}\n\nth {\n position: sticky;\n top: 0;\n z-index: 1;\n border-bottom: 1px solid var(--jl-line);\n background: var(--jl-surface-2);\n color: var(--jl-muted);\n font-size: var(--jl-font-xs);\n font-weight: 600;\n letter-spacing: 0.01em;\n text-align: left;\n}\n\ntd {\n border-top: 1px solid var(--jl-line-soft);\n}\n\ntbody tr:first-child td {\n border-top: none;\n}\n\ntbody tr.empty td {\n padding: 40px var(--cell-x);\n color: var(--jl-muted);\n text-align: center;\n}\n\n.align-left {\n text-align: left;\n}\n\n.align-center {\n text-align: center;\n}\n\n.align-right {\n text-align: right;\n}\n\n.sort {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n margin: -2px -4px;\n padding: 2px 4px;\n border: none;\n border-radius: var(--jl-radius-xs);\n background: none;\n color: inherit;\n font-weight: inherit;\n letter-spacing: inherit;\n cursor: pointer;\n}\n\n.sort:hover {\n color: var(--jl-text);\n}\n\n.sort-icon {\n color: var(--jl-faint);\n}\n\nth[data-sorted] {\n color: var(--jl-text);\n}\n\nth[data-sorted] .sort-icon {\n color: var(--jl-accent);\n}\n\n/* Selected rows keep their shade: the hover and the stripes leave them alone. */\ntbody tr[data-selected] td {\n background: var(--jl-accent-soft);\n}\n\n/* Marked rows (a search's matches) carry a bar at their start and a shade, which selection and hover take over. */\ntbody tr[data-marked] td {\n background: var(--jl-accent-soft);\n}\n\ntbody tr[data-marked] td:first-child {\n box-shadow: inset 3px 0 0 var(--jl-accent);\n}\n\ntbody tr:not(.empty, .skeleton, [data-selected]):hover td {\n background: var(--jl-surface-2);\n}\n\n:host([striped]) tbody tr:nth-child(even):not(.empty, [data-selected], [data-marked]) td {\n background: var(--jl-surface-2);\n}\n\n:host([striped]) tbody tr:not(.empty, .skeleton, [data-selected]):hover td {\n background: var(--jl-surface-3);\n}\n\n.format-number {\n font-variant-numeric: tabular-nums;\n}\n\n/* Broken anywhere, so a long address wraps too; never so narrow that a word stands alone on each line. */\ntd.wrap {\n min-width: 160px;\n white-space: normal;\n overflow-wrap: anywhere;\n}\n\n.format-date {\n color: var(--jl-text-2);\n font-variant-numeric: tabular-nums;\n}\n\ncode {\n padding: 2px 6px;\n border-radius: var(--jl-radius-xs);\n background: var(--jl-code-bg);\n font-size: var(--jl-font-xs);\n}\n\n.select-cell {\n width:
|
|
2
|
+
var jl_table_default = ":host {\n display: block;\n /* The table scrolls sideways inside its frame: its width never pushes the page, or a grid around it, wider. */\n contain: inline-size;\n --max-height: none;\n --cell-y: 10px;\n --cell-x: 14px;\n --select-width: 44px;\n --expand-width: 36px;\n /* The width of the checkbox and chevron cells, after which the details of open rows start. */\n --lead: 0px;\n}\n\n:host([expandable]) {\n --lead: var(--expand-width);\n}\n\n:host([expandable][selectable]) {\n --expand-width: 28px;\n --lead: calc(var(--select-width) + var(--expand-width));\n}\n\n:host([dense]) {\n --cell-y: 6px;\n --cell-x: 12px;\n}\n\n.scroll {\n max-height: var(--max-height);\n overflow: auto;\n border: 1px solid var(--jl-line);\n border-radius: var(--jl-radius);\n background: var(--jl-surface);\n overscroll-behavior-x: contain;\n}\n\n/* The details of open rows take the width of the frame, not of the table. */\n:host([expandable]) .scroll {\n container-type: inline-size;\n}\n\ntable {\n width: 100%;\n border-collapse: separate;\n border-spacing: 0;\n color: var(--jl-text);\n font-size: var(--jl-font-md);\n line-height: 20px;\n}\n\nth,\ntd {\n padding: var(--cell-y) var(--cell-x);\n white-space: nowrap;\n vertical-align: middle;\n}\n\nth {\n position: sticky;\n top: 0;\n z-index: 1;\n border-bottom: 1px solid var(--jl-line);\n background: var(--jl-surface-2);\n color: var(--jl-muted);\n font-size: var(--jl-font-xs);\n font-weight: 600;\n letter-spacing: 0.01em;\n text-align: left;\n}\n\ntd {\n border-top: 1px solid var(--jl-line-soft);\n}\n\ntbody tr:first-child td {\n border-top: none;\n}\n\ntbody tr.empty td {\n padding: 40px var(--cell-x);\n color: var(--jl-muted);\n text-align: center;\n}\n\n/* An open row's detail: joined to its row, no line between them, in line with its first column. */\ntbody tr.detail td {\n padding: 0 var(--cell-x) calc(var(--cell-y) + 6px) calc(var(--lead) + var(--cell-x));\n border-top: none;\n white-space: normal;\n cursor: auto;\n}\n\n/* It stays in the frame while the table scrolls sideways. */\n.detail-body {\n position: sticky;\n left: calc(var(--lead) + var(--cell-x));\n max-width: calc(100cqi - var(--lead) - 2 * var(--cell-x));\n}\n\n.align-left {\n text-align: left;\n}\n\n.align-center {\n text-align: center;\n}\n\n.align-right {\n text-align: right;\n}\n\n.sort {\n display: inline-flex;\n align-items: center;\n gap: 4px;\n margin: -2px -4px;\n padding: 2px 4px;\n border: none;\n border-radius: var(--jl-radius-xs);\n background: none;\n color: inherit;\n font-weight: inherit;\n letter-spacing: inherit;\n cursor: pointer;\n}\n\n.sort:hover {\n color: var(--jl-text);\n}\n\n.sort-icon {\n color: var(--jl-faint);\n}\n\nth[data-sorted] {\n color: var(--jl-text);\n}\n\nth[data-sorted] .sort-icon {\n color: var(--jl-accent);\n}\n\n/* Selected rows keep their shade: the hover and the stripes leave them alone. */\ntbody tr[data-selected] td {\n background: var(--jl-accent-soft);\n}\n\n/* Marked rows (a search's matches) carry a bar at their start and a shade, which selection and hover take over. */\ntbody tr[data-marked] td {\n background: var(--jl-accent-soft);\n}\n\ntbody tr[data-marked] td:first-child {\n box-shadow: inset 3px 0 0 var(--jl-accent);\n}\n\ntbody tr:not(.empty, .skeleton, .detail, [data-selected]):hover td {\n background: var(--jl-surface-2);\n}\n\n/* The stripes count the rows of data, not the details of open rows. */\n:host([striped]) tbody tr:nth-child(even of :where(:not(.detail))):not(.empty, [data-selected], [data-marked]) td {\n background: var(--jl-surface-2);\n}\n\n:host([striped]) tbody tr:not(.empty, .skeleton, .detail, [data-selected]):hover td {\n background: var(--jl-surface-3);\n}\n\n/* An open row's detail takes the shade of its row. */\n:host([striped])\n tbody\n tr:nth-child(even of :where(:not(.detail))):not([data-selected], [data-marked])\n + .detail\n td {\n background: var(--jl-surface-2);\n}\n\n.format-number {\n font-variant-numeric: tabular-nums;\n}\n\n/* Broken anywhere, so a long address wraps too; never so narrow that a word stands alone on each line. */\ntd.wrap {\n min-width: 160px;\n white-space: normal;\n overflow-wrap: anywhere;\n}\n\n.format-date {\n color: var(--jl-text-2);\n font-variant-numeric: tabular-nums;\n}\n\ncode {\n padding: 2px 6px;\n border-radius: var(--jl-radius-xs);\n background: var(--jl-code-bg);\n font-size: var(--jl-font-xs);\n}\n\n.select-cell {\n width: var(--select-width);\n padding-right: 0;\n line-height: 0;\n}\n\n/* The chevron's icon starts where the cells' text does, its button around it; after a checkbox, close to it. */\n.expand-cell {\n width: var(--expand-width);\n padding-right: 0;\n padding-left: calc(var(--cell-x) - 4px);\n line-height: 0;\n}\n\n.select-cell + .expand-cell {\n padding-left: 0;\n}\n\n:host([expandable]) tbody tr[data-index] {\n cursor: pointer;\n}\n\n/* Taller than a line of text, the button reaches into the cell's padding rather than heighten the row. */\n.expand {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 24px;\n height: 24px;\n margin: -2px 0;\n padding: 0;\n border: none;\n border-radius: var(--jl-radius-xs);\n background: none;\n color: var(--jl-muted);\n cursor: pointer;\n}\n\n.expand:hover {\n color: var(--jl-text);\n}\n\n.chevron {\n transition: rotate var(--jl-fast) var(--jl-ease);\n}\n\n.expand[aria-expanded=\"true\"] .chevron {\n rotate: 90deg;\n}\n\n/* The checkbox: the native input keeps the keyboard and the states, the mark beside it draws the tick. */\n.check {\n position: relative;\n display: inline-flex;\n}\n\n.checkbox {\n width: 16px;\n height: 16px;\n margin: 0;\n border: 1.5px solid var(--jl-line-strong);\n border-radius: 4px;\n background: var(--jl-surface);\n cursor: pointer;\n appearance: none;\n transition:\n background var(--jl-fast) var(--jl-ease),\n border-color var(--jl-fast) var(--jl-ease);\n}\n\n.checkbox:hover {\n border-color: var(--jl-muted);\n}\n\n.checkbox:checked,\n.checkbox:indeterminate {\n border-color: var(--jl-accent);\n background: var(--jl-accent);\n}\n\n.checkbox:disabled {\n cursor: not-allowed;\n opacity: 0.5;\n}\n\n.mark {\n position: absolute;\n inset: 0;\n pointer-events: none;\n}\n\n.checkbox:checked + .mark::after {\n position: absolute;\n top: 2.5px;\n left: 5.5px;\n width: 5px;\n height: 9px;\n border: solid var(--jl-on-accent);\n border-width: 0 2px 2px 0;\n rotate: 45deg;\n content: \"\";\n}\n\n.checkbox:indeterminate + .mark::after {\n position: absolute;\n top: 7px;\n right: 4px;\n left: 4px;\n height: 2px;\n border-radius: 1px;\n background: var(--jl-on-accent);\n content: \"\";\n}\n\n.empty-content {\n display: inline-flex;\n align-items: center;\n gap: 8px;\n}\n\n.empty jl-icon {\n color: var(--jl-faint);\n}\n\n.bone {\n display: inline-block;\n width: 70%;\n max-width: 160px;\n height: 10px;\n border-radius: var(--jl-radius-pill);\n background:\n linear-gradient(90deg, var(--jl-surface-3) 30%, var(--jl-surface-2) 50%, var(--jl-surface-3) 70%) 0 0 / 300%\n 100%;\n vertical-align: middle;\n animation: shimmer 1.4s linear infinite;\n}\n\n.bone.box {\n width: 16px;\n height: 16px;\n border-radius: 4px;\n}\n\ntbody tr.skeleton:nth-child(3n + 2) .bone:not(.box) {\n width: 50%;\n}\n\ntbody tr.skeleton:nth-child(3n) .bone:not(.box) {\n width: 85%;\n}\n\n/* Shortened to a millisecond by the base styles, an endless shimmer would flicker: it stands still instead. */\n@media (prefers-reduced-motion: reduce) {\n .bone {\n animation: none;\n }\n}\n\n@keyframes shimmer {\n from {\n background-position: 100% 0;\n }\n\n to {\n background-position: 0 0;\n }\n}\n\n/* A column's description: a quieter line under the cell's value. */\n.cell-description {\n margin-top: 2px;\n color: var(--jl-muted);\n font-size: var(--jl-font-xs);\n}\n";
|
|
3
3
|
export { jl_table_default as default };
|
|
@@ -1,36 +1,42 @@
|
|
|
1
1
|
import { JlElement } from '../base/jl-element';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TableColumn, TableColumnKey, TableDetailRenderer, TableExpansion, TableField, TableRenderers, TableRow, TableRowKey, TableSort, TableSortDirection, TableToggle } from '../types/jl-table.types';
|
|
3
3
|
export declare const TABLE_SORT_DIRECTIONS: readonly TableSortDirection[];
|
|
4
|
+
export declare const TABLE_EXPANSIONS: readonly TableExpansion[];
|
|
4
5
|
/**
|
|
5
6
|
* Rows of data under column headings. `columns` say what each column shows and how (`format`: text, number, date,
|
|
6
7
|
* badge, code); `rows` are plain objects. Sortable headings cycle ascending, descending and unsorted, and sort the
|
|
7
8
|
* rows in place; `selectable` adds a checkbox column. The header stays on top while the rows scroll within
|
|
8
9
|
* `max-height`, and the table scrolls sideways on narrow screens. Cells of a column can be drawn by code with
|
|
9
|
-
* `renderers`.
|
|
10
|
+
* `renderers`. `expandable` rows open on a press to show their `detail` under them, the row staying as it is: one at
|
|
11
|
+
* a time (`single`) or any number (`multiple`).
|
|
12
|
+
*
|
|
13
|
+
* Typed by its rows, `JlTable<Order>` checks and completes the fields its columns name, and hands its renderers and
|
|
14
|
+
* `detail` an order; `JlTable<Order, 'actions'>` adds a column that is not a field, which a renderer draws.
|
|
10
15
|
*/
|
|
11
|
-
export declare class JlTable extends JlElement {
|
|
16
|
+
export declare class JlTable<Row extends object = TableRow, Extra extends string = never> extends JlElement {
|
|
12
17
|
static readonly selector = "jl-table";
|
|
13
18
|
readonly events: Readonly<import("@jadis/core").UseEventsHandler<{
|
|
14
|
-
sort: TableSort
|
|
19
|
+
sort: TableSort<Row, Extra>;
|
|
15
20
|
selection: TableRowKey[];
|
|
21
|
+
toggle: TableToggle;
|
|
16
22
|
}>>;
|
|
17
23
|
readonly columns: Readonly<Readonly<{
|
|
18
|
-
get(): TableColumn[];
|
|
19
|
-
set(setter: TableColumn[] | ((prevState: TableColumn[]) => TableColumn[])): void;
|
|
24
|
+
get(): TableColumn<Row, Extra>[];
|
|
25
|
+
set(setter: TableColumn<Row, Extra>[] | ((prevState: TableColumn<Row, Extra>[]) => TableColumn<Row, Extra>[])): void;
|
|
20
26
|
}>>;
|
|
21
27
|
readonly rows: Readonly<Readonly<{
|
|
22
|
-
get():
|
|
23
|
-
set(setter:
|
|
28
|
+
get(): Row[];
|
|
29
|
+
set(setter: Row[] | ((prevState: Row[]) => Row[])): void;
|
|
24
30
|
}>>;
|
|
25
31
|
/** The field that tells rows apart, for the selection. */
|
|
26
32
|
readonly rowKey: Readonly<Readonly<{
|
|
27
|
-
get(): string
|
|
28
|
-
set(setter:
|
|
33
|
+
get(): "id" | Extract<keyof Row, string>;
|
|
34
|
+
set(setter: "id" | ((prevState: "id" | TableField<Row>) => "id" | Extract<keyof Row, string>) | TableField<Row>): void;
|
|
29
35
|
}>>;
|
|
30
36
|
/** The column the rows are sorted by. */
|
|
31
37
|
readonly sortKey: Readonly<Readonly<{
|
|
32
|
-
get():
|
|
33
|
-
set(setter:
|
|
38
|
+
get(): "" | TableColumnKey<Row, Extra>;
|
|
39
|
+
set(setter: "" | ((prevState: "" | TableColumnKey<Row, Extra>) => "" | TableColumnKey<Row, Extra>) | TableColumnKey<Row, Extra>): void;
|
|
34
40
|
}>>;
|
|
35
41
|
readonly sortDirection: Readonly<Readonly<{
|
|
36
42
|
get(): TableSortDirection;
|
|
@@ -46,6 +52,16 @@ export declare class JlTable extends JlElement {
|
|
|
46
52
|
get(): TableRowKey[];
|
|
47
53
|
set(setter: TableRowKey[] | ((prevState: TableRowKey[]) => TableRowKey[])): void;
|
|
48
54
|
}>>;
|
|
55
|
+
/** Rows open on a press to show their `detail` under them: one at a time (`single`), any number (`multiple`). */
|
|
56
|
+
readonly expandable: Readonly<Readonly<{
|
|
57
|
+
get(): TableExpansion;
|
|
58
|
+
set(setter: ((prevState: TableExpansion) => TableExpansion) | TableExpansion): void;
|
|
59
|
+
}>>;
|
|
60
|
+
/** The keys of the open rows. */
|
|
61
|
+
readonly expanded: Readonly<Readonly<{
|
|
62
|
+
get(): TableRowKey[];
|
|
63
|
+
set(setter: TableRowKey[] | ((prevState: TableRowKey[]) => TableRowKey[])): void;
|
|
64
|
+
}>>;
|
|
49
65
|
/** The keys of rows to draw attention to, such as a search's matches: a mark, not a selection. */
|
|
50
66
|
readonly marked: Readonly<Readonly<{
|
|
51
67
|
get(): TableRowKey[];
|
|
@@ -83,13 +99,19 @@ export declare class JlTable extends JlElement {
|
|
|
83
99
|
}>>;
|
|
84
100
|
/** Draws the cells of some columns by code, by column key: `{ name: (row) => <strong>{row.name}</strong> }`. */
|
|
85
101
|
readonly renderers: Readonly<Readonly<{
|
|
86
|
-
get():
|
|
87
|
-
set(setter:
|
|
102
|
+
get(): TableRenderers<Row, Extra>;
|
|
103
|
+
set(setter: TableRenderers<Row, Extra> | ((prevState: TableRenderers<Row, Extra>) => TableRenderers<Row, Extra>)): void;
|
|
88
104
|
}>>;
|
|
105
|
+
private readonly _source;
|
|
89
106
|
private readonly _pending;
|
|
90
|
-
/** The
|
|
107
|
+
/** The rows as drawn and their keys, by their place: the rows and their checkboxes carry the place. */
|
|
91
108
|
private readonly _view;
|
|
92
109
|
private readonly _refs;
|
|
110
|
+
/** Draws what an open row shows under it, from the row: `(row) => <JlFacts items={…} />`. */
|
|
111
|
+
get detail(): TableDetailRenderer<Row> | null;
|
|
112
|
+
set detail(draw: TableDetailRenderer<Row> | null);
|
|
113
|
+
/** Opens or closes a row, as a press on it would; one at a time, opening a row closes the one that was open. */
|
|
114
|
+
toggle(key: TableRowKey, open: boolean): void;
|
|
93
115
|
templateHtml(): Node;
|
|
94
116
|
templateCss(): string;
|
|
95
117
|
onConnect(): void;
|
|
@@ -98,21 +120,37 @@ export declare class JlTable extends JlElement {
|
|
|
98
120
|
private flush;
|
|
99
121
|
private sortBy;
|
|
100
122
|
private changeSelection;
|
|
123
|
+
/** A press on a row's chevron, or on the row anywhere but its controls and its checkbox, opens or closes it. */
|
|
124
|
+
private pressRow;
|
|
125
|
+
/** The row of data a press is on: one of the table's, not a row in the content of a detail. */
|
|
126
|
+
private dataRowOf;
|
|
127
|
+
private opensOnPress;
|
|
101
128
|
private renderMaxHeight;
|
|
129
|
+
private isExpandable;
|
|
130
|
+
/** The number of cells in a row: the columns, after the checkbox and the chevron when there are. */
|
|
131
|
+
private span;
|
|
102
132
|
private renderHead;
|
|
103
133
|
private headerCell;
|
|
104
134
|
/** The arrows and `aria-sort` of the headings, changed in place so a pressed heading keeps the focus. */
|
|
105
135
|
private renderSortState;
|
|
106
136
|
private sortedRows;
|
|
107
137
|
private renderBody;
|
|
138
|
+
private setView;
|
|
108
139
|
private bodyRow;
|
|
109
140
|
/** A cell's value, drawn by its renderer or in its format, with the row's description under it when it has one. */
|
|
110
141
|
private cell;
|
|
111
142
|
private cellValue;
|
|
112
143
|
private skeletonRows;
|
|
113
144
|
private emptyRow;
|
|
114
|
-
/** The
|
|
145
|
+
/** The rows of data, without the details under the open ones. */
|
|
146
|
+
private dataRows;
|
|
147
|
+
private keyOf;
|
|
148
|
+
/** The bar and the shade of marked rows, changed in place. */
|
|
115
149
|
private renderMarks;
|
|
150
|
+
/** The details of the open rows, added under them and taken away in place: one that stays open keeps its content. */
|
|
151
|
+
private renderExpansion;
|
|
152
|
+
private renderRowOpen;
|
|
153
|
+
private detailRow;
|
|
116
154
|
/** The checkboxes and the shading of selected rows, changed in place. */
|
|
117
155
|
private renderSelection;
|
|
118
156
|
}
|