@monster-orange/den-ui 0.7.6 → 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/README.md +207 -0
- package/package.json +13 -1
- package/src/bulk-bar.css +96 -0
- package/src/bulk-bar.d.ts +45 -0
- package/src/bulk-bar.js +147 -0
- package/src/button.css +59 -0
- package/src/button.d.ts +27 -0
- package/src/button.js +81 -0
- package/src/filter-bar.css +184 -0
- package/src/filter-bar.d.ts +67 -0
- package/src/filter-bar.js +307 -0
- package/src/icons.js +10 -4
- package/src/kit.d.ts +42 -0
- package/src/kit.js +60 -0
- package/src/panel-fold.css +150 -0
- package/src/panel-fold.d.ts +67 -0
- package/src/panel-fold.js +152 -0
- package/src/setting-row.css +56 -0
- package/src/setting-row.d.ts +75 -0
- package/src/setting-row.js +260 -0
- package/src/shell-client.d.ts +13 -0
- package/src/shell-client.js +49 -2
- package/src/shell-html.d.ts +52 -0
- package/src/shell-html.js +104 -5
- package/src/shell.css +37 -0
- package/src/strings.js +73 -0
- package/src/switch.css +88 -0
- package/src/switch.d.ts +32 -0
- package/src/switch.js +85 -0
package/src/kit.d.ts
CHANGED
|
@@ -25,6 +25,7 @@ import type {
|
|
|
25
25
|
hydrateBell,
|
|
26
26
|
hydrateScope,
|
|
27
27
|
hydrateSearch,
|
|
28
|
+
PageMenuHydrateOptions,
|
|
28
29
|
} from "./shell-client.js";
|
|
29
30
|
import type {
|
|
30
31
|
ShellModel,
|
|
@@ -48,12 +49,24 @@ import type {
|
|
|
48
49
|
appearanceButtonHtml,
|
|
49
50
|
appearanceMenuHtml,
|
|
50
51
|
waitingHtml,
|
|
52
|
+
menuRowHtml,
|
|
53
|
+
pageMenuButtonHtml,
|
|
54
|
+
pageMenuHtml,
|
|
51
55
|
icon,
|
|
52
56
|
esc,
|
|
53
57
|
} from "./shell-html.js";
|
|
58
|
+
import type { buttonHtml } from "./button.js";
|
|
59
|
+
import type {
|
|
60
|
+
SettingRow,
|
|
61
|
+
SettingRowHydrateOptions,
|
|
62
|
+
SettingRowOptions,
|
|
63
|
+
settingRowHtml,
|
|
64
|
+
} from "./setting-row.js";
|
|
54
65
|
import type { syncPinToggles } from "./shell-client.js";
|
|
55
66
|
import type { UpdatePill } from "./update-pill.js";
|
|
56
67
|
import type { SaveState, SaveStateOptions } from "./savestate.js";
|
|
68
|
+
import type { FilterBar, FilterBarOptions } from "./filter-bar.js";
|
|
69
|
+
import type { BulkBar, BulkBarOptions } from "./bulk-bar.js";
|
|
57
70
|
|
|
58
71
|
/** Every call to the product goes through it; the kit names no URL. */
|
|
59
72
|
export interface Adapter extends ReportAdapter {
|
|
@@ -164,6 +177,26 @@ export declare function saveState(
|
|
|
164
177
|
el: HTMLElement,
|
|
165
178
|
opts: SaveStateOptions,
|
|
166
179
|
): SaveState;
|
|
180
|
+
/** A list's filter bar, in the kit's language. */
|
|
181
|
+
export declare function filterBar(
|
|
182
|
+
el: HTMLElement,
|
|
183
|
+
opts: FilterBarOptions,
|
|
184
|
+
): FilterBar;
|
|
185
|
+
/** A list's bulk bar, in the kit's language. */
|
|
186
|
+
export declare function bulkBar(el: HTMLElement, opts: BulkBarOptions): BulkBar;
|
|
187
|
+
/** The page action menu on a drawn More ▾ button, in the kit's language. */
|
|
188
|
+
export declare function pageMenu(
|
|
189
|
+
btn: HTMLElement,
|
|
190
|
+
opts: PageMenuHydrateOptions,
|
|
191
|
+
): AppearanceHandle;
|
|
192
|
+
/**
|
|
193
|
+
* The settings on/off row, in the kit's language: with a row's data (a
|
|
194
|
+
* label), drawn into el first; else the row el holds is wired.
|
|
195
|
+
*/
|
|
196
|
+
export declare function settingRow(
|
|
197
|
+
el: HTMLElement,
|
|
198
|
+
opts: SettingRowHydrateOptions & Partial<SettingRowOptions>,
|
|
199
|
+
): SettingRow;
|
|
167
200
|
export declare function hydrate(
|
|
168
201
|
root: ParentNode,
|
|
169
202
|
opts?: KitHydrateOptions,
|
|
@@ -215,6 +248,15 @@ export interface DenUIKit {
|
|
|
215
248
|
report: typeof report;
|
|
216
249
|
busy: typeof busy;
|
|
217
250
|
saveState: typeof saveState;
|
|
251
|
+
filterBar: typeof filterBar;
|
|
252
|
+
bulkBar: typeof bulkBar;
|
|
253
|
+
buttonHtml: typeof buttonHtml;
|
|
254
|
+
menuRowHtml: typeof menuRowHtml;
|
|
255
|
+
pageMenuButtonHtml: typeof pageMenuButtonHtml;
|
|
256
|
+
pageMenuHtml: typeof pageMenuHtml;
|
|
257
|
+
pageMenu: typeof pageMenu;
|
|
258
|
+
settingRowHtml: typeof settingRowHtml;
|
|
259
|
+
settingRow: typeof settingRow;
|
|
218
260
|
}
|
|
219
261
|
declare const DenUI: DenUIKit;
|
|
220
262
|
export default DenUI;
|
package/src/kit.js
CHANGED
|
@@ -45,6 +45,17 @@
|
|
|
45
45
|
* DenUI.saveState(el, { save, copyText, watch }) an autosaving
|
|
46
46
|
* editor's save-state line (savestate.js),
|
|
47
47
|
* in the kit's language
|
|
48
|
+
* DenUI.filterBar(el, { facets, selected, onChange, start, end })
|
|
49
|
+
* a list's Filters button, chosen chips
|
|
50
|
+
* and facet panel (filter-bar.js)
|
|
51
|
+
* DenUI.bulkBar(el, { count, actions, onAction, onClear })
|
|
52
|
+
* a list's bar while rows are selected
|
|
53
|
+
* (bulk-bar.js)
|
|
54
|
+
* DenUI.buttonHtml(o) the general button (button.js, issue 556)
|
|
55
|
+
* DenUI.pageMenu(btn, { items, onSelect }) the page action menu on a
|
|
56
|
+
* pageMenuButtonHtml button (issue 555)
|
|
57
|
+
* DenUI.settingRow(el, { onSave, ...row }) the settings on/off row
|
|
58
|
+
* (setting-row.js, issue 554)
|
|
48
59
|
* DenUI.strings(lang, table) the product's own words, or its versions
|
|
49
60
|
* of the kit's; DenUI.t(key, vars)
|
|
50
61
|
*/
|
|
@@ -70,6 +81,9 @@ import {
|
|
|
70
81
|
shellHtml,
|
|
71
82
|
topBarHtml,
|
|
72
83
|
markHtml,
|
|
84
|
+
menuRowHtml,
|
|
85
|
+
pageMenuButtonHtml,
|
|
86
|
+
pageMenuHtml,
|
|
73
87
|
versionChipHtml,
|
|
74
88
|
waitingHtml,
|
|
75
89
|
} from "./shell-html.js";
|
|
@@ -78,6 +92,7 @@ import {
|
|
|
78
92
|
attachMenuFilter,
|
|
79
93
|
hydrateAppearance,
|
|
80
94
|
hydrateBell,
|
|
95
|
+
hydratePageMenu,
|
|
81
96
|
hydrateScope,
|
|
82
97
|
hydrateSearch,
|
|
83
98
|
hydrateShell,
|
|
@@ -96,6 +111,14 @@ import { configureReport, openReport } from "./report.js";
|
|
|
96
111
|
import { showUpdate } from "./update-pill.js";
|
|
97
112
|
import { busyAction, configureBusy } from "./busy.js";
|
|
98
113
|
import { createSaveState } from "./savestate.js";
|
|
114
|
+
import { mountFilterBar } from "./filter-bar.js";
|
|
115
|
+
import { mountBulkBar } from "./bulk-bar.js";
|
|
116
|
+
import { buttonHtml } from "./button.js";
|
|
117
|
+
import {
|
|
118
|
+
hydrateSettingRow,
|
|
119
|
+
mountSettingRow,
|
|
120
|
+
settingRowHtml,
|
|
121
|
+
} from "./setting-row.js";
|
|
99
122
|
|
|
100
123
|
const state = {
|
|
101
124
|
lang: "en",
|
|
@@ -192,6 +215,34 @@ export function saveState(el, opts = {}) {
|
|
|
192
215
|
return createSaveState(el, { lang, ...opts });
|
|
193
216
|
}
|
|
194
217
|
|
|
218
|
+
/** A list's filter bar, in the kit's language. */
|
|
219
|
+
export function filterBar(el, opts = {}) {
|
|
220
|
+
return mountFilterBar(el, { lang, ...opts });
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** A list's bulk bar, in the kit's language. */
|
|
224
|
+
export function bulkBar(el, opts = {}) {
|
|
225
|
+
return mountBulkBar(el, { lang, ...opts });
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* The page action menu (issue 555) on a drawn More ▾ button, in the
|
|
230
|
+
* kit's language (hydratePageMenu).
|
|
231
|
+
*/
|
|
232
|
+
export function pageMenu(btn, opts = {}) {
|
|
233
|
+
return hydratePageMenu(btn, { lang, ...opts });
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* The settings on/off row (issue 554), in the kit's language. With
|
|
238
|
+
* opts.label (a row's data), it draws the row into el first; else it wires
|
|
239
|
+
* the row el already holds.
|
|
240
|
+
*/
|
|
241
|
+
export function settingRow(el, opts = {}) {
|
|
242
|
+
const o = { lang: lang(), ...opts };
|
|
243
|
+
return opts.label != null ? mountSettingRow(el, o) : hydrateSettingRow(el, o);
|
|
244
|
+
}
|
|
245
|
+
|
|
195
246
|
/**
|
|
196
247
|
* Binds the drawn shell, the chip and Report (see the top), and the 0.7.0
|
|
197
248
|
* pieces it finds: the scope crumbs (opts.scope), the search
|
|
@@ -304,6 +355,15 @@ const DenUI = {
|
|
|
304
355
|
report,
|
|
305
356
|
busy,
|
|
306
357
|
saveState,
|
|
358
|
+
filterBar,
|
|
359
|
+
bulkBar,
|
|
360
|
+
buttonHtml,
|
|
361
|
+
menuRowHtml,
|
|
362
|
+
pageMenuButtonHtml,
|
|
363
|
+
pageMenuHtml,
|
|
364
|
+
pageMenu,
|
|
365
|
+
settingRowHtml,
|
|
366
|
+
settingRow,
|
|
307
367
|
};
|
|
308
368
|
|
|
309
369
|
if (typeof window !== "undefined") window.DenUI = DenUI;
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/* den-ui: the panel fold toggle (issue 548) and the folded panel's edge
|
|
2
|
+
strip (issue 549), panel-fold.js. Tokens only: no colour of its own.
|
|
3
|
+
Linked, never injected: clean under style-src 'self'. The host shows or
|
|
4
|
+
hides each with the hidden attribute and lays its page out itself. */
|
|
5
|
+
|
|
6
|
+
/* The fold toggle: an icon and a word; pressed (the panel shows) is the
|
|
7
|
+
sunken fill and the strong border. */
|
|
8
|
+
.den-fold {
|
|
9
|
+
display: inline-flex;
|
|
10
|
+
align-items: center;
|
|
11
|
+
gap: 6px;
|
|
12
|
+
min-height: 32px;
|
|
13
|
+
margin: 0;
|
|
14
|
+
padding: 0 10px;
|
|
15
|
+
border: 1px solid var(--border);
|
|
16
|
+
border-radius: var(--r-btn);
|
|
17
|
+
background: transparent;
|
|
18
|
+
color: var(--text);
|
|
19
|
+
font-family: var(--sans);
|
|
20
|
+
font-size: var(--fs-s);
|
|
21
|
+
font-weight: 400;
|
|
22
|
+
line-height: 1;
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
transition:
|
|
25
|
+
background-color var(--dur-fast) ease,
|
|
26
|
+
border-color var(--dur-fast) ease;
|
|
27
|
+
}
|
|
28
|
+
.den-fold[hidden] {
|
|
29
|
+
display: none;
|
|
30
|
+
}
|
|
31
|
+
.den-fold:hover {
|
|
32
|
+
border-color: var(--border-strong);
|
|
33
|
+
}
|
|
34
|
+
.den-fold[aria-pressed="true"] {
|
|
35
|
+
background: var(--sunken);
|
|
36
|
+
border-color: var(--border-strong);
|
|
37
|
+
font-weight: 500;
|
|
38
|
+
}
|
|
39
|
+
.den-fold svg,
|
|
40
|
+
.den-strip-show svg {
|
|
41
|
+
flex: none;
|
|
42
|
+
fill: none;
|
|
43
|
+
stroke: currentColor;
|
|
44
|
+
stroke-width: 1.8;
|
|
45
|
+
stroke-linecap: round;
|
|
46
|
+
stroke-linejoin: round;
|
|
47
|
+
}
|
|
48
|
+
.den-fold svg {
|
|
49
|
+
width: 14px;
|
|
50
|
+
height: 14px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* The edge strip: 40px wide where the folded panel was; Show panel, then
|
|
54
|
+
the count under it. */
|
|
55
|
+
.den-strip {
|
|
56
|
+
display: flex;
|
|
57
|
+
flex-direction: column;
|
|
58
|
+
align-items: center;
|
|
59
|
+
gap: 6px;
|
|
60
|
+
box-sizing: border-box;
|
|
61
|
+
width: 40px;
|
|
62
|
+
min-height: 120px;
|
|
63
|
+
padding: var(--space-2) 0;
|
|
64
|
+
align-self: start;
|
|
65
|
+
background: var(--surface);
|
|
66
|
+
border: 1px solid var(--border);
|
|
67
|
+
border-radius: var(--r);
|
|
68
|
+
}
|
|
69
|
+
.den-strip[hidden] {
|
|
70
|
+
display: none;
|
|
71
|
+
}
|
|
72
|
+
.den-strip-show {
|
|
73
|
+
position: relative;
|
|
74
|
+
display: inline-flex;
|
|
75
|
+
align-items: center;
|
|
76
|
+
justify-content: center;
|
|
77
|
+
flex: none;
|
|
78
|
+
box-sizing: border-box;
|
|
79
|
+
width: 32px;
|
|
80
|
+
height: 32px;
|
|
81
|
+
margin: 0;
|
|
82
|
+
padding: 0;
|
|
83
|
+
border: 1px solid var(--border);
|
|
84
|
+
border-radius: var(--r-btn);
|
|
85
|
+
background: var(--surface);
|
|
86
|
+
color: var(--text);
|
|
87
|
+
cursor: pointer;
|
|
88
|
+
}
|
|
89
|
+
.den-strip-show:hover {
|
|
90
|
+
border-color: var(--border-strong);
|
|
91
|
+
background: var(--sunken);
|
|
92
|
+
}
|
|
93
|
+
.den-strip-show svg {
|
|
94
|
+
width: 16px;
|
|
95
|
+
height: 16px;
|
|
96
|
+
}
|
|
97
|
+
.den-strip-n {
|
|
98
|
+
min-width: 24px;
|
|
99
|
+
font-family: var(--mono);
|
|
100
|
+
font-size: var(--fs-xs);
|
|
101
|
+
font-weight: 500;
|
|
102
|
+
line-height: 16px;
|
|
103
|
+
text-align: center;
|
|
104
|
+
color: var(--accent-text);
|
|
105
|
+
}
|
|
106
|
+
/* The count's words: heard, never seen. */
|
|
107
|
+
.den-strip-sr {
|
|
108
|
+
position: absolute;
|
|
109
|
+
width: 1px;
|
|
110
|
+
height: 1px;
|
|
111
|
+
padding: 0;
|
|
112
|
+
margin: -1px;
|
|
113
|
+
overflow: hidden;
|
|
114
|
+
clip: rect(0 0 0 0);
|
|
115
|
+
white-space: nowrap;
|
|
116
|
+
border: 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.den-fold:focus-visible,
|
|
120
|
+
.den-strip-show:focus-visible {
|
|
121
|
+
outline: 2px solid var(--accent);
|
|
122
|
+
outline-offset: 2px;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/* A phone or a touch screen: the toggle is a 44px row; Show panel keeps
|
|
126
|
+
its 32px look inside the 40px strip, with a 44×44px tap centred on it
|
|
127
|
+
(as .den-hit). */
|
|
128
|
+
@media (pointer: coarse), (max-width: 720px) {
|
|
129
|
+
.den-fold {
|
|
130
|
+
min-height: var(--tap);
|
|
131
|
+
}
|
|
132
|
+
.den-strip-show::after {
|
|
133
|
+
content: "";
|
|
134
|
+
position: absolute;
|
|
135
|
+
left: 50%;
|
|
136
|
+
top: 50%;
|
|
137
|
+
width: 100%;
|
|
138
|
+
height: 100%;
|
|
139
|
+
min-width: var(--tap);
|
|
140
|
+
min-height: var(--tap);
|
|
141
|
+
transform: translate(-50%, -50%);
|
|
142
|
+
background: transparent;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
@media (prefers-reduced-motion: reduce) {
|
|
147
|
+
.den-fold {
|
|
148
|
+
transition: none;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/** What a strip's count counts, worded as the kit's badges are. */
|
|
2
|
+
export type EdgeStripCountKind = "open" | "waiting" | "down" | "running";
|
|
3
|
+
|
|
4
|
+
export interface FoldToggleModel {
|
|
5
|
+
/** The panel shows (default true): aria-pressed. */
|
|
6
|
+
pressed?: boolean;
|
|
7
|
+
/** The panel's id: aria-controls. */
|
|
8
|
+
controls?: string;
|
|
9
|
+
/** The kit's words' language: en, es or ja (default en). */
|
|
10
|
+
lang?: string;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface EdgeStripModel {
|
|
14
|
+
/** The count under Show panel; 0 or none draws none; 99+ past 99. */
|
|
15
|
+
count?: number;
|
|
16
|
+
/** What it counts (default "open"); any other is "open". */
|
|
17
|
+
what?: EdgeStripCountKind;
|
|
18
|
+
/** The folded panel's id: Show panel's aria-controls. */
|
|
19
|
+
controls?: string;
|
|
20
|
+
lang?: string;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface FoldToggleOptions {
|
|
24
|
+
/** A press: next is true when the panel should show. */
|
|
25
|
+
onToggle?: (next: boolean) => void;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface FoldToggle {
|
|
29
|
+
/** Moves aria-pressed with no call (the host's own change). */
|
|
30
|
+
set(pressed: boolean): void;
|
|
31
|
+
pressed(): boolean;
|
|
32
|
+
destroy(): void;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface EdgeStripOptions {
|
|
36
|
+
/** Show panel: the host shows the panel and hides the strip. */
|
|
37
|
+
onShow?: () => void;
|
|
38
|
+
/** The count's words' language (default: the nearest [lang], else en). */
|
|
39
|
+
lang?: string;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface EdgeStrip {
|
|
43
|
+
setCount(n: number, what?: EdgeStripCountKind): void;
|
|
44
|
+
destroy(): void;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** <button class="den-fold" aria-pressed>: an icon, then "Panel". */
|
|
48
|
+
export declare function foldToggleHtml(model?: FoldToggleModel): string;
|
|
49
|
+
|
|
50
|
+
/** <div class="den-strip" role="complementary">, 40px: Show panel, the count. */
|
|
51
|
+
export declare function edgeStripHtml(model?: EdgeStripModel): string;
|
|
52
|
+
|
|
53
|
+
/** A press moves aria-pressed and calls onToggle(next). */
|
|
54
|
+
export declare function hydrateFoldToggle(
|
|
55
|
+
button: HTMLElement | null,
|
|
56
|
+
opts?: FoldToggleOptions,
|
|
57
|
+
): FoldToggle;
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Show panel calls onShow(); then, when focus is still in the strip (now
|
|
61
|
+
* hidden) or on the body, it goes to the fold toggle for the same panel,
|
|
62
|
+
* else to the panel when it takes focus.
|
|
63
|
+
*/
|
|
64
|
+
export declare function hydrateEdgeStrip(
|
|
65
|
+
strip: HTMLElement | null,
|
|
66
|
+
opts?: EdgeStripOptions,
|
|
67
|
+
): EdgeStrip;
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The panel fold toggle (issue 548) and the folded panel's edge strip
|
|
3
|
+
* (issue 549). A page with a side panel (comments, details, a list) lets a
|
|
4
|
+
* person fold it away to read the main column clean, and bring it back.
|
|
5
|
+
* The host keeps the state (shown or folded, remembered or not) and lays
|
|
6
|
+
* the page out; the kit draws the two controls, owns their words (en, es,
|
|
7
|
+
* ja) and their keys and focus. Pure builders run in Node too:
|
|
8
|
+
*
|
|
9
|
+
* foldToggleHtml({ pressed, controls, lang })
|
|
10
|
+
* <button class="den-fold" aria-pressed>: an icon, then "Panel".
|
|
11
|
+
* pressed (default true) = the panel shows. controls: the panel's id.
|
|
12
|
+
* edgeStripHtml({ count, what, controls, lang })
|
|
13
|
+
* <div class="den-strip" role="complementary" aria-label="Panel,
|
|
14
|
+
* hidden">, 40px wide, for where the folded panel was: a "Show panel"
|
|
15
|
+
* icon button, then the count under it (none at 0; 99+ past 99). The
|
|
16
|
+
* count is seen as a number and heard as the kit's badge words:
|
|
17
|
+
* what is "open" (default), "waiting", "down" or "running".
|
|
18
|
+
*
|
|
19
|
+
* In the page, the same elements come alive:
|
|
20
|
+
*
|
|
21
|
+
* const fold = hydrateFoldToggle(button, { onToggle: (next) => … });
|
|
22
|
+
* A press (click, Enter, Space) moves aria-pressed and calls
|
|
23
|
+
* onToggle(next): true = show the panel. fold.set(pressed) moves it
|
|
24
|
+
* with no call (the host's own change, a kept layout); fold.pressed();
|
|
25
|
+
* fold.destroy().
|
|
26
|
+
* const strip = hydrateEdgeStrip(div, { onShow: () => …, lang });
|
|
27
|
+
* Show panel calls onShow(). The host shows the panel and hides the
|
|
28
|
+
* strip. When focus is still in the strip after that (or fell to the
|
|
29
|
+
* body), it goes to the fold toggle for the same panel, else to the
|
|
30
|
+
* panel when it can take focus. A focus the host moved itself is
|
|
31
|
+
* kept. strip.setCount(n, what?); strip.destroy().
|
|
32
|
+
*
|
|
33
|
+
* Host words are never used: a label, title or aria-label passed to a
|
|
34
|
+
* builder is ignored. The look is panel-fold.css: link it after
|
|
35
|
+
* tokens.css. The host shows or hides each with the `hidden` attribute.
|
|
36
|
+
*/
|
|
37
|
+
import { icon } from "./icons.js";
|
|
38
|
+
import { esc, kitT } from "./strings.js";
|
|
39
|
+
|
|
40
|
+
/** The counts a strip may say, worded as the kit's badges are. */
|
|
41
|
+
const WHAT = ["open", "waiting", "down", "running"];
|
|
42
|
+
|
|
43
|
+
const langOf = (lang) => lang || "en";
|
|
44
|
+
|
|
45
|
+
/** The fold toggle's markup (see the top of this file). */
|
|
46
|
+
export function foldToggleHtml(o = {}) {
|
|
47
|
+
const lang = langOf(o.lang);
|
|
48
|
+
const pressed = o.pressed !== false;
|
|
49
|
+
const controls = o.controls ? ` aria-controls="${esc(o.controls)}"` : "";
|
|
50
|
+
return (
|
|
51
|
+
`<button type="button" class="den-fold" aria-pressed="${pressed}"` +
|
|
52
|
+
`${controls} data-den-fold>${icon("panel")}` +
|
|
53
|
+
`<span class="den-fold-word">${esc(kitT(lang, "kit.fold.panel"))}</span>` +
|
|
54
|
+
"</button>"
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** The count under Show panel: the number seen, the words heard. */
|
|
59
|
+
function countHtml(n, what, lang) {
|
|
60
|
+
const count = Math.max(0, Math.floor(Number(n) || 0));
|
|
61
|
+
if (!count) return "";
|
|
62
|
+
const kind = WHAT.includes(what) ? what : "open";
|
|
63
|
+
const seen = count > 99 ? "99+" : String(count);
|
|
64
|
+
const heard = kitT(lang, `kit.badge.${kind}`, { n: count });
|
|
65
|
+
return (
|
|
66
|
+
`<span class="den-strip-n" data-den-strip-n>` +
|
|
67
|
+
`<span aria-hidden="true">${esc(seen)}</span>` +
|
|
68
|
+
`<span class="den-strip-sr">${esc(heard)}</span></span>`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The edge strip's markup (see the top of this file). */
|
|
73
|
+
export function edgeStripHtml(o = {}) {
|
|
74
|
+
const lang = langOf(o.lang);
|
|
75
|
+
const show = esc(kitT(lang, "kit.fold.show"));
|
|
76
|
+
const controls = o.controls ? ` aria-controls="${esc(o.controls)}"` : "";
|
|
77
|
+
return (
|
|
78
|
+
`<div class="den-strip" role="complementary"` +
|
|
79
|
+
` aria-label="${esc(kitT(lang, "kit.fold.hidden"))}" data-den-strip>` +
|
|
80
|
+
`<button type="button" class="den-strip-show" aria-label="${show}"` +
|
|
81
|
+
` title="${show}"${controls} data-den-strip-show>${icon("panelShow")}` +
|
|
82
|
+
`</button>${countHtml(o.count, o.what, lang)}</div>`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The fold toggle in the page (see the top of this file). */
|
|
87
|
+
export function hydrateFoldToggle(btn, opts = {}) {
|
|
88
|
+
const read = () => btn?.getAttribute("aria-pressed") === "true";
|
|
89
|
+
const set = (on) => btn?.setAttribute("aria-pressed", String(Boolean(on)));
|
|
90
|
+
// A <button>: Enter and Space are clicks.
|
|
91
|
+
const onClick = () => {
|
|
92
|
+
const next = !read();
|
|
93
|
+
set(next);
|
|
94
|
+
opts.onToggle?.(next);
|
|
95
|
+
};
|
|
96
|
+
btn?.addEventListener("click", onClick);
|
|
97
|
+
return {
|
|
98
|
+
set,
|
|
99
|
+
pressed: read,
|
|
100
|
+
destroy() {
|
|
101
|
+
btn?.removeEventListener("click", onClick);
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Can a person see it (laid out, not hidden by an ancestor)? */
|
|
107
|
+
const shown = (el) =>
|
|
108
|
+
Boolean(el && el.isConnected && el.getClientRects().length > 0);
|
|
109
|
+
|
|
110
|
+
/** The edge strip in the page (see the top of this file). */
|
|
111
|
+
export function hydrateEdgeStrip(strip, opts = {}) {
|
|
112
|
+
const btn = strip?.querySelector("[data-den-strip-show]");
|
|
113
|
+
const lang = () =>
|
|
114
|
+
opts.lang ||
|
|
115
|
+
strip?.closest("[lang]")?.getAttribute("lang")?.slice(0, 2) ||
|
|
116
|
+
"en";
|
|
117
|
+
|
|
118
|
+
/** Where focus goes when the host left it in a strip now out of sight. */
|
|
119
|
+
function returnFocus() {
|
|
120
|
+
const a = document.activeElement;
|
|
121
|
+
const lost = !a || a === document.body || (strip.contains(a) && !shown(a));
|
|
122
|
+
if (!lost) return;
|
|
123
|
+
const id = btn?.getAttribute("aria-controls");
|
|
124
|
+
const toggle = id
|
|
125
|
+
? document.querySelector(
|
|
126
|
+
`[data-den-fold][aria-controls="${CSS.escape(id)}"]`,
|
|
127
|
+
)
|
|
128
|
+
: null;
|
|
129
|
+
if (shown(toggle)) return toggle.focus({ preventScroll: true });
|
|
130
|
+
const panel = id ? document.getElementById(id) : null;
|
|
131
|
+
if (shown(panel) && panel.tabIndex >= 0)
|
|
132
|
+
panel.focus({ preventScroll: true });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const onClick = () => {
|
|
136
|
+
opts.onShow?.();
|
|
137
|
+
returnFocus();
|
|
138
|
+
};
|
|
139
|
+
btn?.addEventListener("click", onClick);
|
|
140
|
+
|
|
141
|
+
return {
|
|
142
|
+
setCount(n, what) {
|
|
143
|
+
if (!strip) return;
|
|
144
|
+
strip.querySelector("[data-den-strip-n]")?.remove();
|
|
145
|
+
const html = countHtml(n, what, lang());
|
|
146
|
+
if (html) strip.insertAdjacentHTML("beforeend", html);
|
|
147
|
+
},
|
|
148
|
+
destroy() {
|
|
149
|
+
btn?.removeEventListener("click", onClick);
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/* den-ui: the settings on/off row (setting-row.js, issue 554). Tokens
|
|
2
|
+
only. Save is the kit's button (button.css); the state line is
|
|
3
|
+
savestate.css's. Linked, never injected. */
|
|
4
|
+
.den-setrow {
|
|
5
|
+
display: flex;
|
|
6
|
+
flex-direction: column;
|
|
7
|
+
align-items: flex-start;
|
|
8
|
+
gap: 6px;
|
|
9
|
+
max-width: 32rem;
|
|
10
|
+
margin: 0;
|
|
11
|
+
}
|
|
12
|
+
.den-setrow-l {
|
|
13
|
+
display: flex;
|
|
14
|
+
gap: 10px;
|
|
15
|
+
align-items: flex-start;
|
|
16
|
+
font-weight: 600;
|
|
17
|
+
color: var(--text);
|
|
18
|
+
}
|
|
19
|
+
.den-setrow-l input {
|
|
20
|
+
margin: 3px 0 0;
|
|
21
|
+
flex: none;
|
|
22
|
+
accent-color: var(--accent-fill);
|
|
23
|
+
}
|
|
24
|
+
.den-setrow-help {
|
|
25
|
+
margin: 0;
|
|
26
|
+
color: var(--muted);
|
|
27
|
+
}
|
|
28
|
+
.den-setrow-act {
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
gap: var(--space-2);
|
|
32
|
+
margin-top: 4px;
|
|
33
|
+
}
|
|
34
|
+
.den-setrow-act .den-btn[aria-disabled="true"] {
|
|
35
|
+
cursor: progress;
|
|
36
|
+
}
|
|
37
|
+
.den-setrow-meta {
|
|
38
|
+
margin: 2px 0 0;
|
|
39
|
+
font-size: 12px;
|
|
40
|
+
color: var(--faint);
|
|
41
|
+
}
|
|
42
|
+
/* A phone: the label and Save are 44px targets; the box is 22px. */
|
|
43
|
+
@media (max-width: 720px), (pointer: coarse) {
|
|
44
|
+
.den-setrow-l {
|
|
45
|
+
min-height: var(--tap);
|
|
46
|
+
align-items: center;
|
|
47
|
+
}
|
|
48
|
+
.den-setrow-l input {
|
|
49
|
+
width: 22px;
|
|
50
|
+
height: 22px;
|
|
51
|
+
margin: 0;
|
|
52
|
+
}
|
|
53
|
+
.den-setrow-act .den-btn {
|
|
54
|
+
min-height: var(--tap);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/** The row's save state. */
|
|
2
|
+
export type SettingRowState = "idle" | "saving" | "saved" | "error";
|
|
3
|
+
|
|
4
|
+
/** The settings on/off row's data. */
|
|
5
|
+
export interface SettingRowOptions {
|
|
6
|
+
/** The row's id (safe characters); its parts' ids start with it. */
|
|
7
|
+
id: string;
|
|
8
|
+
/** The checkbox's form name (default: id). */
|
|
9
|
+
name?: string;
|
|
10
|
+
/** The host's words. */
|
|
11
|
+
label: string;
|
|
12
|
+
/** A help line under the label (the host's words); "" for none. */
|
|
13
|
+
help?: string;
|
|
14
|
+
checked?: boolean;
|
|
15
|
+
/** Who can change it, the host's words; [] is nobody. */
|
|
16
|
+
who?: string[];
|
|
17
|
+
/** The last change: who (the host's words) and an ISO time; null: none yet. */
|
|
18
|
+
last?: { by: string; at: string } | null;
|
|
19
|
+
/** This person can't change it: the box and Save are disabled. */
|
|
20
|
+
readOnly?: boolean;
|
|
21
|
+
state?: SettingRowState;
|
|
22
|
+
/** A form that posts with no script (csrf in a hidden field named `field`). */
|
|
23
|
+
form?: {
|
|
24
|
+
action: string;
|
|
25
|
+
method?: string;
|
|
26
|
+
csrf?: string;
|
|
27
|
+
field?: string;
|
|
28
|
+
} | null;
|
|
29
|
+
lang?: string;
|
|
30
|
+
/** The time's clock and zone (default: now, the person's zone). */
|
|
31
|
+
now?: string | Date;
|
|
32
|
+
zone?: string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface SettingRowHydrateOptions {
|
|
36
|
+
/** Save: the box's state; it rejects when it did not save. */
|
|
37
|
+
onSave?: (checked: boolean) => Promise<unknown> | unknown;
|
|
38
|
+
lang?: string | (() => string);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface SettingRow {
|
|
42
|
+
/** Draws a state the host decides. */
|
|
43
|
+
set(state: SettingRowState): void;
|
|
44
|
+
/** The box's state. */
|
|
45
|
+
checked(): boolean;
|
|
46
|
+
/** Save now, as a press of Save would. */
|
|
47
|
+
save(): Promise<void> | undefined;
|
|
48
|
+
destroy(): void;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The state line's words for a state ("" for idle). */
|
|
52
|
+
export declare function settingStateText(
|
|
53
|
+
state: SettingRowState,
|
|
54
|
+
lang?: string,
|
|
55
|
+
): string;
|
|
56
|
+
/** The line under the row: who can change it · its last change (HTML). */
|
|
57
|
+
export declare function settingMetaHtml(o: {
|
|
58
|
+
who?: string[];
|
|
59
|
+
last?: { by: string; at: string } | null;
|
|
60
|
+
lang?: string;
|
|
61
|
+
now?: string | Date;
|
|
62
|
+
zone?: string;
|
|
63
|
+
}): string;
|
|
64
|
+
/** The row's markup. */
|
|
65
|
+
export declare function settingRowHtml(o: SettingRowOptions): string;
|
|
66
|
+
/** Wires a drawn row. */
|
|
67
|
+
export declare function hydrateSettingRow(
|
|
68
|
+
el: Element,
|
|
69
|
+
opts?: SettingRowHydrateOptions,
|
|
70
|
+
): SettingRow;
|
|
71
|
+
/** Draws the row into el (its contents), then wires it. */
|
|
72
|
+
export declare function mountSettingRow(
|
|
73
|
+
el: Element,
|
|
74
|
+
opts: SettingRowOptions & SettingRowHydrateOptions,
|
|
75
|
+
): SettingRow;
|