@monster-orange/den-ui 0.7.5 → 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 +240 -0
- package/package.json +15 -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 +49 -0
- package/src/kit.js +70 -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/savestate.css +75 -0
- package/src/savestate.d.ts +73 -0
- package/src/savestate.js +294 -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 +89 -0
- package/src/switch.css +88 -0
- package/src/switch.d.ts +32 -0
- package/src/switch.js +85 -0
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The settings on/off row (issue 554): a checkbox and its label, a help
|
|
3
|
+
* line, Save, the save state, and a line "who can change this · last
|
|
4
|
+
* changed". The host passes data and a callback; the kit draws the row and
|
|
5
|
+
* owns its own words (en, es, ja).
|
|
6
|
+
*
|
|
7
|
+
* settingRowHtml({
|
|
8
|
+
* id, the row's id (safe characters; its parts' ids
|
|
9
|
+
* start with it)
|
|
10
|
+
* name, the checkbox's form name (default: id)
|
|
11
|
+
* label, help, the host's words (help may be "")
|
|
12
|
+
* checked, on or off
|
|
13
|
+
* who: ["Admins"], who can change it, the host's words ([]: nobody)
|
|
14
|
+
* last: { by, at }, the last change: who (the host's words) and an
|
|
15
|
+
* ISO time; null: no changes yet
|
|
16
|
+
* readOnly, this person can't change it: the box and Save
|
|
17
|
+
* are disabled
|
|
18
|
+
* state, "idle" | "saving" | "saved" | "error"
|
|
19
|
+
* form: { action, method?, csrf?, field? }, a form that posts with
|
|
20
|
+
* no script (csrf in a hidden field named `field`,
|
|
21
|
+
* "csrf" by default); without it, Save is a plain
|
|
22
|
+
* button the client wires
|
|
23
|
+
* lang, now?, zone? the words' language; the time's clock and zone
|
|
24
|
+
* })
|
|
25
|
+
*
|
|
26
|
+
* const row = hydrateSettingRow(el, { onSave(checked) → Promise, lang })
|
|
27
|
+
* const row = mountSettingRow(el, opts) draws it into el, then hydrates
|
|
28
|
+
* row.set(state) draws a state the host decides
|
|
29
|
+
* row.checked() the box's state
|
|
30
|
+
* row.destroy()
|
|
31
|
+
*
|
|
32
|
+
* Save calls onSave with the box's state: "Saving…" when it takes more
|
|
33
|
+
* than SAVING_AFTER_MS (savestate.js), then "Saved", or "Not saved. Try
|
|
34
|
+
* again." (a reject). Save says it is busy (aria-disabled) while it saves,
|
|
35
|
+
* and keeps focus. A change to the box clears "Saved". The state line
|
|
36
|
+
* wears savestate.css's look (link it) and is a polite status. A form row
|
|
37
|
+
* hydrated with onSave saves through it instead of posting.
|
|
38
|
+
*
|
|
39
|
+
* Its look is setting-row.css, with button.css and savestate.css.
|
|
40
|
+
*/
|
|
41
|
+
import { buttonHtml } from "./button.js";
|
|
42
|
+
import { SAVING_AFTER_MS } from "./savestate.js";
|
|
43
|
+
import { esc, kitT } from "./strings.js";
|
|
44
|
+
import { timeHtml, upgradeTimes } from "./time.js";
|
|
45
|
+
|
|
46
|
+
const STATES = ["idle", "saving", "saved", "error"];
|
|
47
|
+
|
|
48
|
+
/** An id made of safe characters: letters, digits, - and _. */
|
|
49
|
+
const safeId = (s) => String(s).replace(/[^A-Za-z0-9_-]/g, "-");
|
|
50
|
+
|
|
51
|
+
/** "Admins and Owners", in the row's language. */
|
|
52
|
+
function joinWho(lang, who) {
|
|
53
|
+
try {
|
|
54
|
+
return new Intl.ListFormat(lang || "en", {
|
|
55
|
+
style: "long",
|
|
56
|
+
type: "conjunction",
|
|
57
|
+
}).format(who);
|
|
58
|
+
} catch {
|
|
59
|
+
return who.join(", ");
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* A kit sentence with {time} as markup: the words escaped, the <time>
|
|
65
|
+
* dropped in whole.
|
|
66
|
+
*/
|
|
67
|
+
function sentenceHtml(lang, key, vars, time) {
|
|
68
|
+
const mark = "\u0000t\u0000";
|
|
69
|
+
return esc(kitT(lang, key, { ...vars, time: mark })).replace(
|
|
70
|
+
mark,
|
|
71
|
+
() => time,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/** The state line's words for a state ("" for idle). */
|
|
76
|
+
export function settingStateText(state, lang) {
|
|
77
|
+
return state === "saving"
|
|
78
|
+
? kitT(lang, "kit.savestate.saving")
|
|
79
|
+
: state === "saved"
|
|
80
|
+
? kitT(lang, "kit.savestate.saved")
|
|
81
|
+
: state === "error"
|
|
82
|
+
? kitT(lang, "kit.setrow.error")
|
|
83
|
+
: "";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** The line under the row: who can change it · its last change. */
|
|
87
|
+
export function settingMetaHtml({ who, last, lang, now, zone } = {}) {
|
|
88
|
+
const names = (who || []).filter((w) => w != null && w !== "").map(String);
|
|
89
|
+
const can = names.length
|
|
90
|
+
? esc(kitT(lang, "kit.setrow.who", { who: joinWho(lang, names) }))
|
|
91
|
+
: esc(kitT(lang, "kit.setrow.nobody"));
|
|
92
|
+
const t =
|
|
93
|
+
last && last.at
|
|
94
|
+
? timeHtml(last.at, { style: "relative", locale: lang, now, zone })
|
|
95
|
+
: "";
|
|
96
|
+
const changed = t
|
|
97
|
+
? sentenceHtml(lang, "kit.setrow.last", { who: last.by ?? "" }, t)
|
|
98
|
+
: esc(kitT(lang, "kit.setrow.never"));
|
|
99
|
+
return can + " · " + changed;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/** The row's markup (see the top). */
|
|
103
|
+
export function settingRowHtml(o = {}) {
|
|
104
|
+
const id = safeId(o.id || "den-setrow");
|
|
105
|
+
const lang = o.lang;
|
|
106
|
+
const state = STATES.includes(o.state) ? o.state : "idle";
|
|
107
|
+
const f = o.form && o.form.action ? o.form : null;
|
|
108
|
+
const tag = f ? "form" : "div";
|
|
109
|
+
const help = o.help ? String(o.help) : "";
|
|
110
|
+
const describedBy = (help ? id + "-help " : "") + id + "-meta";
|
|
111
|
+
return (
|
|
112
|
+
"<" +
|
|
113
|
+
tag +
|
|
114
|
+
' class="den-setrow" id="' +
|
|
115
|
+
id +
|
|
116
|
+
'" data-den-setrow' +
|
|
117
|
+
(f
|
|
118
|
+
? ' method="' +
|
|
119
|
+
esc(f.method || "post") +
|
|
120
|
+
'" action="' +
|
|
121
|
+
esc(f.action) +
|
|
122
|
+
'">' +
|
|
123
|
+
(f.csrf != null
|
|
124
|
+
? '<input type="hidden" name="' +
|
|
125
|
+
esc(f.field || "csrf") +
|
|
126
|
+
'" value="' +
|
|
127
|
+
esc(f.csrf) +
|
|
128
|
+
'">'
|
|
129
|
+
: "")
|
|
130
|
+
: ">") +
|
|
131
|
+
'<label class="den-setrow-l"><input type="checkbox" id="' +
|
|
132
|
+
id +
|
|
133
|
+
'-cb" name="' +
|
|
134
|
+
esc(o.name || id) +
|
|
135
|
+
'" value="on" aria-describedby="' +
|
|
136
|
+
describedBy +
|
|
137
|
+
'"' +
|
|
138
|
+
(o.checked ? " checked" : "") +
|
|
139
|
+
(o.readOnly ? " disabled" : "") +
|
|
140
|
+
"> <span>" +
|
|
141
|
+
esc(o.label) +
|
|
142
|
+
"</span></label>" +
|
|
143
|
+
(help
|
|
144
|
+
? '<p class="den-setrow-help" id="' + id + '-help">' + esc(help) + "</p>"
|
|
145
|
+
: "") +
|
|
146
|
+
'<div class="den-setrow-act">' +
|
|
147
|
+
buttonHtml({
|
|
148
|
+
label: kitT(lang, "kit.setrow.save"),
|
|
149
|
+
type: f ? "submit" : "button",
|
|
150
|
+
disabled: !!o.readOnly,
|
|
151
|
+
attrs: { "data-den-setrow-save": "" },
|
|
152
|
+
}).replace(' data-den-setrow-save=""', " data-den-setrow-save") +
|
|
153
|
+
'<p class="den-savestate den-setrow-state" id="' +
|
|
154
|
+
id +
|
|
155
|
+
'-state" data-state="' +
|
|
156
|
+
state +
|
|
157
|
+
'" role="status">' +
|
|
158
|
+
esc(settingStateText(state, lang)) +
|
|
159
|
+
"</p></div>" +
|
|
160
|
+
'<p class="den-setrow-meta" id="' +
|
|
161
|
+
id +
|
|
162
|
+
'-meta">' +
|
|
163
|
+
settingMetaHtml({
|
|
164
|
+
who: o.who,
|
|
165
|
+
last: o.last,
|
|
166
|
+
lang,
|
|
167
|
+
now: o.now,
|
|
168
|
+
zone: o.zone,
|
|
169
|
+
}) +
|
|
170
|
+
"</p></" +
|
|
171
|
+
tag +
|
|
172
|
+
">"
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** Wires a drawn row (see the top). */
|
|
177
|
+
export function hydrateSettingRow(el, opts = {}) {
|
|
178
|
+
const lang = () =>
|
|
179
|
+
typeof opts.lang === "function"
|
|
180
|
+
? opts.lang()
|
|
181
|
+
: opts.lang ||
|
|
182
|
+
(el.closest && el.closest("[lang]")
|
|
183
|
+
? el.closest("[lang]").getAttribute("lang")
|
|
184
|
+
: undefined);
|
|
185
|
+
const box = el.querySelector('input[type="checkbox"]');
|
|
186
|
+
const save = el.querySelector("[data-den-setrow-save]");
|
|
187
|
+
const line = el.querySelector(".den-setrow-state");
|
|
188
|
+
let busy = false;
|
|
189
|
+
let slow = 0;
|
|
190
|
+
let dead = false;
|
|
191
|
+
|
|
192
|
+
function set(state) {
|
|
193
|
+
if (!line || dead) return;
|
|
194
|
+
const s = STATES.includes(state) ? state : "idle";
|
|
195
|
+
line.setAttribute("data-state", s);
|
|
196
|
+
line.textContent = settingStateText(s, lang());
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function run(e) {
|
|
200
|
+
if (e) e.preventDefault();
|
|
201
|
+
if (busy || dead || !opts.onSave || (box && box.disabled)) return;
|
|
202
|
+
busy = true;
|
|
203
|
+
save.setAttribute("aria-disabled", "true");
|
|
204
|
+
clearTimeout(slow);
|
|
205
|
+
slow = setTimeout(() => busy && set("saving"), SAVING_AFTER_MS);
|
|
206
|
+
let p;
|
|
207
|
+
try {
|
|
208
|
+
p = Promise.resolve(opts.onSave(box ? box.checked : false));
|
|
209
|
+
} catch (err) {
|
|
210
|
+
p = Promise.reject(err);
|
|
211
|
+
}
|
|
212
|
+
return p.then(
|
|
213
|
+
() => done("saved"),
|
|
214
|
+
() => done("error"),
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
function done(state) {
|
|
219
|
+
clearTimeout(slow);
|
|
220
|
+
busy = false;
|
|
221
|
+
if (dead) return;
|
|
222
|
+
save.removeAttribute("aria-disabled");
|
|
223
|
+
set(state);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const onChange = () => {
|
|
227
|
+
if (!busy) set("idle");
|
|
228
|
+
};
|
|
229
|
+
const onClick = (e) => {
|
|
230
|
+
// A form with no onSave posts on its own.
|
|
231
|
+
if (!opts.onSave) return;
|
|
232
|
+
run(e);
|
|
233
|
+
};
|
|
234
|
+
const onSubmit = (e) => {
|
|
235
|
+
if (opts.onSave) run(e);
|
|
236
|
+
};
|
|
237
|
+
if (box) box.addEventListener("change", onChange);
|
|
238
|
+
if (save) save.addEventListener("click", onClick);
|
|
239
|
+
if (el.tagName === "FORM") el.addEventListener("submit", onSubmit);
|
|
240
|
+
upgradeTimes(el);
|
|
241
|
+
|
|
242
|
+
return {
|
|
243
|
+
set,
|
|
244
|
+
checked: () => !!(box && box.checked),
|
|
245
|
+
save: () => run(null),
|
|
246
|
+
destroy() {
|
|
247
|
+
dead = true;
|
|
248
|
+
clearTimeout(slow);
|
|
249
|
+
if (box) box.removeEventListener("change", onChange);
|
|
250
|
+
if (save) save.removeEventListener("click", onClick);
|
|
251
|
+
if (el.tagName === "FORM") el.removeEventListener("submit", onSubmit);
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** Draws the row into `el` (its contents), then wires it. */
|
|
257
|
+
export function mountSettingRow(el, opts = {}) {
|
|
258
|
+
el.innerHTML = settingRowHtml(opts);
|
|
259
|
+
return hydrateSettingRow(el.firstElementChild, opts);
|
|
260
|
+
}
|
package/src/shell-client.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type {
|
|
|
3
3
|
AppearanceMenu,
|
|
4
4
|
BellItem,
|
|
5
5
|
BellPanelOptions,
|
|
6
|
+
PageMenuItem,
|
|
6
7
|
WaitingOptions,
|
|
7
8
|
} from "./shell-html.js";
|
|
8
9
|
|
|
@@ -142,6 +143,18 @@ export declare function hydrateAppearance(
|
|
|
142
143
|
button: HTMLElement,
|
|
143
144
|
opts?: AppearanceHydrateOptions,
|
|
144
145
|
): AppearanceHandle;
|
|
146
|
+
export interface PageMenuHydrateOptions {
|
|
147
|
+
/** The items, or a function giving them each time the menu opens. */
|
|
148
|
+
items: PageMenuItem[] | (() => PageMenuItem[]);
|
|
149
|
+
/** A pick of an item with no onSelect of its own. */
|
|
150
|
+
onSelect?: (id: string, item: PageMenuItem) => void;
|
|
151
|
+
lang?: string | (() => string);
|
|
152
|
+
}
|
|
153
|
+
/** The page action menu on the button pageMenuButtonHtml drew. */
|
|
154
|
+
export declare function hydratePageMenu(
|
|
155
|
+
button: HTMLElement,
|
|
156
|
+
opts: PageMenuHydrateOptions,
|
|
157
|
+
): AppearanceHandle;
|
|
145
158
|
/** The update-waiting pill after the version chip; null hides it. */
|
|
146
159
|
export declare function setWaiting(
|
|
147
160
|
o: (WaitingOptions & { onClick?: (e: Event) => void }) | null,
|
package/src/shell-client.js
CHANGED
|
@@ -75,6 +75,11 @@
|
|
|
75
75
|
* the checked entry (else the first); ↑ ↓ Home End move; Esc or Tab
|
|
76
76
|
* closes it and focus goes back to ◐ ▾; a press outside closes it.
|
|
77
77
|
* → { open(), close(refocus), isOpen() }
|
|
78
|
+
* hydratePageMenu(button, { items, onSelect(id, item), lang })
|
|
79
|
+
* the page action menu (issue 555) on pageMenuButtonHtml's More ▾,
|
|
80
|
+
* as ◐ ▾'s. A disabled item does nothing and keeps it open; its note
|
|
81
|
+
* (with an href) is a row to follow. → { open(), close(refocus),
|
|
82
|
+
* isOpen() }
|
|
78
83
|
* setWaiting(o | null, root?) the update-waiting pill after the
|
|
79
84
|
* version chip: { label, action, title?, name?, onClick } shows it
|
|
80
85
|
* (waitingHtml), null hides it.
|
|
@@ -87,6 +92,7 @@ import {
|
|
|
87
92
|
bellPanelHtml,
|
|
88
93
|
menuFilterParts,
|
|
89
94
|
menuHasFilter,
|
|
95
|
+
pageMenuHtml,
|
|
90
96
|
waitingHtml,
|
|
91
97
|
} from "./shell-html.js";
|
|
92
98
|
import { focusBack } from "./dialog.js";
|
|
@@ -702,10 +708,46 @@ export function hydrateAppearance(btn, opts = {}) {
|
|
|
702
708
|
});
|
|
703
709
|
}
|
|
704
710
|
|
|
711
|
+
/**
|
|
712
|
+
* The page action menu (issue 555): the button pageMenuButtonHtml drew,
|
|
713
|
+
* and its menu on <body>, as ◐ ▾'s.
|
|
714
|
+
* hydratePageMenu(button, { items, onSelect(id, item), lang })
|
|
715
|
+
* items: pageMenuHtml's items (a list, or a function giving one each time
|
|
716
|
+
* it opens); an item may carry its own onSelect(item). A pick calls the
|
|
717
|
+
* item's onSelect, else opts.onSelect(id, item), and closes the menu; a
|
|
718
|
+
* link is followed. A disabled item does nothing. Its note, when it has an
|
|
719
|
+
* href, is a row to follow.
|
|
720
|
+
* → { open(), close(refocus), isOpen() }
|
|
721
|
+
*/
|
|
722
|
+
export function hydratePageMenu(btn, opts = {}) {
|
|
723
|
+
const lang = () =>
|
|
724
|
+
typeof opts.lang === "function" ? opts.lang() : opts.lang;
|
|
725
|
+
const list = () =>
|
|
726
|
+
(typeof opts.items === "function" ? opts.items() : opts.items) || [];
|
|
727
|
+
let shown = [];
|
|
728
|
+
return popMenu(btn, {
|
|
729
|
+
id: "den-pmenu",
|
|
730
|
+
cls: "den-pmenu",
|
|
731
|
+
label: () => kitT(lang(), "kit.pmenu.more"),
|
|
732
|
+
html: () => {
|
|
733
|
+
shown = list();
|
|
734
|
+
return pageMenuHtml({ id: btn.id, items: shown, lang: lang() });
|
|
735
|
+
},
|
|
736
|
+
onPick: (kind, value) => {
|
|
737
|
+
if (kind !== "page") return;
|
|
738
|
+
const item = shown.find((it) => it && !it.hr && String(it.id) === value);
|
|
739
|
+
if (!item || item.disabled) return;
|
|
740
|
+
if (typeof item.onSelect === "function") item.onSelect(item);
|
|
741
|
+
else if (opts.onSelect) opts.onSelect(item.id, item);
|
|
742
|
+
},
|
|
743
|
+
});
|
|
744
|
+
}
|
|
745
|
+
|
|
705
746
|
/**
|
|
706
747
|
* A kit menu on <body> for a button (◐ ▾, the account entry): placed by
|
|
707
748
|
* it, kept in the window. o: { id (the button's, if it has none), label(),
|
|
708
|
-
* html(), onPick(kind, value, row), onSubmit(event, form)
|
|
749
|
+
* html(), onPick(kind, value, row), onSubmit(event, form), cls (a class
|
|
750
|
+
* of its own on the menu) }. Opens on
|
|
709
751
|
* the checked entry, else the first; ↑ ↓ Home End move; Esc or Tab
|
|
710
752
|
* closes it and focus goes back to the button; a press outside closes
|
|
711
753
|
* it. A form's submit button submits it (onSubmit first: preventDefault
|
|
@@ -750,7 +792,7 @@ function popMenu(el, o) {
|
|
|
750
792
|
if (pop) return;
|
|
751
793
|
if (from) btn = from;
|
|
752
794
|
pop = document.createElement("div");
|
|
753
|
-
pop.className = "den-pop den-um";
|
|
795
|
+
pop.className = "den-pop den-um" + (o.cls ? " " + o.cls : "");
|
|
754
796
|
pop.tabIndex = -1;
|
|
755
797
|
pop.id = (btn.id || o.id) + "-menu";
|
|
756
798
|
pop.setAttribute("role", "menu");
|
|
@@ -765,6 +807,11 @@ function popMenu(el, o) {
|
|
|
765
807
|
e.target && e.target.closest ? e.target.closest(".den-mi") : null;
|
|
766
808
|
// A form's own button: the form posts (see submit below).
|
|
767
809
|
if (!row || row.type === "submit") return;
|
|
810
|
+
// A disabled row does nothing, and the menu stays open.
|
|
811
|
+
if (row.getAttribute("aria-disabled") === "true") {
|
|
812
|
+
e.preventDefault();
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
768
815
|
const kind = row.dataset.kind;
|
|
769
816
|
const value = row.dataset.value;
|
|
770
817
|
if (row.tagName !== "A") e.preventDefault();
|
package/src/shell-html.d.ts
CHANGED
|
@@ -370,6 +370,58 @@ export interface AppearanceMenu {
|
|
|
370
370
|
lang?: string;
|
|
371
371
|
}
|
|
372
372
|
export declare function appearanceMenuHtml(o?: AppearanceMenu): string;
|
|
373
|
+
/** One row of a kit menu (◐ ▾, the account menu and the page menu draw theirs with it). */
|
|
374
|
+
export interface MenuRow {
|
|
375
|
+
label: string;
|
|
376
|
+
/** A link (a disabled one is drawn as a button: nothing to follow). */
|
|
377
|
+
href?: string | null;
|
|
378
|
+
/** A radio: aria-checked. */
|
|
379
|
+
checked?: boolean | null;
|
|
380
|
+
/** data-kind and data-value: what a pick reports. */
|
|
381
|
+
kind?: string | null;
|
|
382
|
+
value?: string | number | null;
|
|
383
|
+
id?: string | null;
|
|
384
|
+
/** A class of its own, after den-mi. */
|
|
385
|
+
cls?: string | null;
|
|
386
|
+
/** aria-disabled="true". */
|
|
387
|
+
disabled?: boolean;
|
|
388
|
+
/** The id of the line that says why. */
|
|
389
|
+
describedBy?: string | null;
|
|
390
|
+
}
|
|
391
|
+
export declare function menuRowHtml(r: MenuRow): string;
|
|
392
|
+
/** A host's words: text, or a key in the kit's tables (addStrings) and its vars. */
|
|
393
|
+
export type HostWords =
|
|
394
|
+
| string
|
|
395
|
+
| { key: string; vars?: Record<string, unknown> };
|
|
396
|
+
/** An item of the page action menu, or a rule. */
|
|
397
|
+
export type PageMenuItem =
|
|
398
|
+
| {
|
|
399
|
+
id: string;
|
|
400
|
+
label: HostWords;
|
|
401
|
+
/** A link to follow; else a button (onSelect). */
|
|
402
|
+
href?: string;
|
|
403
|
+
disabled?: boolean;
|
|
404
|
+
/** Why it is disabled: drawn under it, and its description. */
|
|
405
|
+
note?: HostWords;
|
|
406
|
+
/** Where to turn it on: the note becomes a row to follow. */
|
|
407
|
+
noteHref?: string;
|
|
408
|
+
/** Its own pick (hydratePageMenu), before opts.onSelect. */
|
|
409
|
+
onSelect?: (item: PageMenuItem) => void;
|
|
410
|
+
}
|
|
411
|
+
| { hr: true };
|
|
412
|
+
/** More ▾: the kit's button, a menu button. */
|
|
413
|
+
export declare function pageMenuButtonHtml(o?: {
|
|
414
|
+
id?: string;
|
|
415
|
+
size?: "sm";
|
|
416
|
+
lang?: string;
|
|
417
|
+
}): string;
|
|
418
|
+
/** The page action menu's rows, from data. */
|
|
419
|
+
export declare function pageMenuHtml(o: {
|
|
420
|
+
/** The menu button's id: each row's id is "<id>-<item id>". */
|
|
421
|
+
id?: string;
|
|
422
|
+
items: PageMenuItem[];
|
|
423
|
+
lang?: string;
|
|
424
|
+
}): string;
|
|
373
425
|
export interface WaitingOptions {
|
|
374
426
|
/** The words before the dot ("stale server"). */
|
|
375
427
|
label?: string;
|
package/src/shell-html.js
CHANGED
|
@@ -1002,20 +1002,34 @@ export function appearanceButtonHtml({ id, label, title, lang } = {}) {
|
|
|
1002
1002
|
);
|
|
1003
1003
|
}
|
|
1004
1004
|
|
|
1005
|
-
/**
|
|
1006
|
-
|
|
1005
|
+
/**
|
|
1006
|
+
* One row of a kit menu: a radio (checked set), a link or a button. The
|
|
1007
|
+
* kit's own menus (◐ ▾, the account menu) and the page action menu draw
|
|
1008
|
+
* their rows with it.
|
|
1009
|
+
* menuRowHtml({ label, href?, checked?, kind?, value?, id?, cls?,
|
|
1010
|
+
* disabled?, describedBy? })
|
|
1011
|
+
* disabled: aria-disabled="true", and a link becomes a button (nothing to
|
|
1012
|
+
* follow); describedBy: the id of the line that says why.
|
|
1013
|
+
*/
|
|
1014
|
+
export function menuRowHtml(r) {
|
|
1007
1015
|
const radio = r.checked != null;
|
|
1008
|
-
const
|
|
1016
|
+
const link = r.href != null && !r.disabled;
|
|
1017
|
+
const tag = link ? "a" : "button";
|
|
1009
1018
|
return (
|
|
1010
1019
|
"<" +
|
|
1011
1020
|
tag +
|
|
1012
|
-
' class="den-mi
|
|
1021
|
+
' class="den-mi' +
|
|
1022
|
+
(r.cls ? " " + esc(r.cls) : "") +
|
|
1023
|
+
'" tabindex="-1" role="' +
|
|
1013
1024
|
(radio ? "menuitemradio" : "menuitem") +
|
|
1014
1025
|
'"' +
|
|
1015
1026
|
(radio ? ' aria-checked="' + (r.checked ? "true" : "false") + '"' : "") +
|
|
1016
|
-
(
|
|
1027
|
+
(link ? ' href="' + esc(r.href) + '"' : ' type="button"') +
|
|
1017
1028
|
(r.kind ? ' data-kind="' + esc(r.kind) + '"' : "") +
|
|
1018
1029
|
(r.value != null ? ' data-value="' + esc(r.value) + '"' : "") +
|
|
1030
|
+
(r.id ? ' id="' + esc(r.id) + '"' : "") +
|
|
1031
|
+
(r.disabled ? ' aria-disabled="true"' : "") +
|
|
1032
|
+
(r.describedBy ? ' aria-describedby="' + esc(r.describedBy) + '"' : "") +
|
|
1019
1033
|
'><span class="den-mi-l">' +
|
|
1020
1034
|
esc(r.label) +
|
|
1021
1035
|
"</span></" +
|
|
@@ -1024,6 +1038,91 @@ function menuRowHtml(r) {
|
|
|
1024
1038
|
);
|
|
1025
1039
|
}
|
|
1026
1040
|
|
|
1041
|
+
/** An id made of safe characters: letters, digits, - and _. */
|
|
1042
|
+
const safeId = (s) => String(s).replace(/[^A-Za-z0-9_-]/g, "-");
|
|
1043
|
+
|
|
1044
|
+
/** A host's words: text, or { key, vars } in the kit's tables (addStrings). */
|
|
1045
|
+
const words = (w, lang) =>
|
|
1046
|
+
w == null
|
|
1047
|
+
? ""
|
|
1048
|
+
: typeof w === "object"
|
|
1049
|
+
? w.key
|
|
1050
|
+
? kitT(lang, w.key, w.vars)
|
|
1051
|
+
: ""
|
|
1052
|
+
: String(w);
|
|
1053
|
+
|
|
1054
|
+
/**
|
|
1055
|
+
* The page action menu's button (issue 555): "More ▾", the kit's button
|
|
1056
|
+
* (button.css), a menu button. hydratePageMenu (shell-client.js) opens
|
|
1057
|
+
* its menu.
|
|
1058
|
+
* pageMenuButtonHtml({ id?, size?: "sm", lang })
|
|
1059
|
+
*/
|
|
1060
|
+
export function pageMenuButtonHtml({ id, size, lang } = {}) {
|
|
1061
|
+
return (
|
|
1062
|
+
'<button type="button" class="den-btn' +
|
|
1063
|
+
(size === "sm" ? " sm" : "") +
|
|
1064
|
+
' den-pmenu-btn" id="' +
|
|
1065
|
+
esc(safeId(id || "den-pmenu")) +
|
|
1066
|
+
'" aria-haspopup="menu" aria-expanded="false">' +
|
|
1067
|
+
esc(kitT(lang, "kit.pmenu.more")) +
|
|
1068
|
+
' <span aria-hidden="true">▾</span></button>'
|
|
1069
|
+
);
|
|
1070
|
+
}
|
|
1071
|
+
|
|
1072
|
+
/**
|
|
1073
|
+
* The page action menu's rows (issue 555), from data.
|
|
1074
|
+
* pageMenuHtml({ id, items, lang })
|
|
1075
|
+
* id: the menu button's (each row's id is "<id>-<item id>"). Each item:
|
|
1076
|
+
* { id, label, href?, disabled?, note?, noteHref? } or { hr: true }
|
|
1077
|
+
* label and note: the host's words, or { key, vars } in the kit's tables
|
|
1078
|
+
* (a host adds its keys with addStrings). A disabled item has
|
|
1079
|
+
* aria-disabled and is described by its note, drawn right under it: a row
|
|
1080
|
+
* to follow when the note has an href (where to turn it on), else a line.
|
|
1081
|
+
* An item with no id or no label draws nothing.
|
|
1082
|
+
*/
|
|
1083
|
+
export function pageMenuHtml({ id, items, lang } = {}) {
|
|
1084
|
+
const base = safeId(id || "den-pmenu");
|
|
1085
|
+
return (items || [])
|
|
1086
|
+
.map((it) => {
|
|
1087
|
+
if (!it) return "";
|
|
1088
|
+
if (it.hr) return '<div class="den-hr" role="separator"></div>';
|
|
1089
|
+
const label = words(it.label, lang);
|
|
1090
|
+
if (it.id == null || it.id === "" || !label) return "";
|
|
1091
|
+
const rowId = base + "-" + safeId(it.id);
|
|
1092
|
+
const note = it.disabled ? words(it.note, lang) : "";
|
|
1093
|
+
const noteId = rowId + "-note";
|
|
1094
|
+
return (
|
|
1095
|
+
menuRowHtml({
|
|
1096
|
+
label,
|
|
1097
|
+
href: it.href,
|
|
1098
|
+
kind: "page",
|
|
1099
|
+
value: it.id,
|
|
1100
|
+
id: rowId,
|
|
1101
|
+
cls: "den-pmi",
|
|
1102
|
+
disabled: !!it.disabled,
|
|
1103
|
+
describedBy: note ? noteId : null,
|
|
1104
|
+
}) +
|
|
1105
|
+
(!note
|
|
1106
|
+
? ""
|
|
1107
|
+
: it.noteHref != null
|
|
1108
|
+
? menuRowHtml({
|
|
1109
|
+
label: note,
|
|
1110
|
+
href: it.noteHref,
|
|
1111
|
+
kind: "note",
|
|
1112
|
+
value: it.id,
|
|
1113
|
+
id: noteId,
|
|
1114
|
+
cls: "den-mwhy",
|
|
1115
|
+
})
|
|
1116
|
+
: '<p class="den-mnote den-mwhy" id="' +
|
|
1117
|
+
esc(noteId) +
|
|
1118
|
+
'">' +
|
|
1119
|
+
esc(note) +
|
|
1120
|
+
"</p>")
|
|
1121
|
+
);
|
|
1122
|
+
})
|
|
1123
|
+
.join("");
|
|
1124
|
+
}
|
|
1125
|
+
|
|
1027
1126
|
/**
|
|
1028
1127
|
* The appearance menu's content.
|
|
1029
1128
|
* appearanceMenuHtml({ mode, modes?, themes?, notice?, languages?,
|
package/src/shell.css
CHANGED
|
@@ -1233,6 +1233,43 @@ body.den-has-shell .den-upd {
|
|
|
1233
1233
|
padding: 0;
|
|
1234
1234
|
box-sizing: border-box;
|
|
1235
1235
|
}
|
|
1236
|
+
/* The page action menu (issue 555). A disabled item is faint and
|
|
1237
|
+
doesn't light up; its note sits right under it, wraps, and is a row to
|
|
1238
|
+
follow when it links to where to turn it on. */
|
|
1239
|
+
.den-pop .den-mi[aria-disabled="true"] {
|
|
1240
|
+
color: var(--faint);
|
|
1241
|
+
cursor: not-allowed;
|
|
1242
|
+
}
|
|
1243
|
+
.den-pop .den-mi[aria-disabled="true"]:hover {
|
|
1244
|
+
background: none;
|
|
1245
|
+
}
|
|
1246
|
+
.den-pop .den-mwhy {
|
|
1247
|
+
display: block;
|
|
1248
|
+
max-width: 260px;
|
|
1249
|
+
padding: 0 8px 6px;
|
|
1250
|
+
font-size: 12px;
|
|
1251
|
+
line-height: 1.4;
|
|
1252
|
+
color: var(--muted);
|
|
1253
|
+
}
|
|
1254
|
+
.den-pop .den-mwhy .den-mi-l {
|
|
1255
|
+
white-space: normal;
|
|
1256
|
+
}
|
|
1257
|
+
.den-pop a.den-mwhy .den-mi-l {
|
|
1258
|
+
text-decoration: underline;
|
|
1259
|
+
text-underline-offset: 2px;
|
|
1260
|
+
}
|
|
1261
|
+
/* A phone: More and every row a 44px target. */
|
|
1262
|
+
@media (max-width: 720px), (pointer: coarse) {
|
|
1263
|
+
.den-pmenu-btn,
|
|
1264
|
+
.den-pmenu .den-mi {
|
|
1265
|
+
min-height: var(--tap);
|
|
1266
|
+
}
|
|
1267
|
+
.den-pmenu .den-mwhy {
|
|
1268
|
+
display: flex;
|
|
1269
|
+
padding: 4px 8px 8px;
|
|
1270
|
+
font-size: 13px;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1236
1273
|
/* ◐ ▾'s menu, on <body> above everything, placed under the button. */
|
|
1237
1274
|
.den-um {
|
|
1238
1275
|
margin: 0;
|