@monster-orange/den-ui 0.6.6 → 0.7.1
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 +271 -7
- package/bin/den-ui-parity.mjs +80 -3
- package/inventory/fonts-dir.cjs +8 -0
- package/inventory/fonts-dir.mjs +10 -0
- package/inventory/nav-inventory.d.ts +81 -0
- package/inventory/nav-inventory.js +496 -16
- package/inventory/reference/den-chromium-1280.json +577 -98
- package/inventory/reference/den-chromium-390.json +457 -44
- package/inventory/reference/den-webkit-1280.json +577 -98
- package/inventory/reference/den-webkit-390.json +457 -44
- package/package.json +8 -1
- package/src/kit.d.ts +76 -3
- package/src/kit.js +79 -2
- package/src/marks/den.svg +6 -0
- package/src/report-shot.js +194 -12
- package/src/shell-client.d.ts +118 -0
- package/src/shell-client.js +621 -0
- package/src/shell-html.d.ts +240 -3
- package/src/shell-html.js +724 -12
- package/src/shell.css +721 -5
- package/src/strings.js +54 -0
- package/src/tokens.css +69 -63
- package/src/version.js +5 -1
package/src/shell-html.js
CHANGED
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
* No inline style attributes, no inline handlers: the markup is clean
|
|
9
9
|
* under `script-src 'self'; style-src 'self'`. Its look is shell.css.
|
|
10
10
|
*
|
|
11
|
-
* shellHtml({ product, nav, groups, foot,
|
|
11
|
+
* shellHtml({ product, nav, groups, foot, settings, account, lang, slots,
|
|
12
|
+
* collapsed, report })
|
|
12
13
|
* product { name, title?, version?, href?, mark? } the brand: `name` is the
|
|
13
14
|
* word beside the mark, `title` its tooltip (default name),
|
|
14
15
|
* `version` the chip's text ("v" + version; "v…" when unknown),
|
|
@@ -21,6 +22,10 @@
|
|
|
21
22
|
* entry is left out
|
|
22
23
|
* foot entries under the rail's spacer (Settings, say), then the
|
|
23
24
|
* kit's collapse toggle
|
|
25
|
+
* settings (0.7.0) the Settings entry, after foot: { href, label?,
|
|
26
|
+
* current?, id? } (settingsHtml)
|
|
27
|
+
* account (0.7.0) the account entry, last in the foot: { label,
|
|
28
|
+
* detail?, href? | action? } (accountHtml)
|
|
24
29
|
* lang "en", "es" or "ja" (the kit's words; else en)
|
|
25
30
|
* slots { start, end, bell, account }: the product's own HTML in
|
|
26
31
|
* the top bar. start: after the brand; end: the right group's
|
|
@@ -34,6 +39,10 @@
|
|
|
34
39
|
* attributes { name: value } (escaped); `cls` more classes; `pin` the
|
|
35
40
|
* pinned id (the row is a pin row: Delete unpins it); `after` HTML after
|
|
36
41
|
* the link inside the pin row (a Visit link).
|
|
42
|
+
*
|
|
43
|
+
* 0.7.0, for the slots: scopeHtml (the scope crumbs), searchHtml (the
|
|
44
|
+
* search field with ⌘K inside), bellButtonHtml and bellPanelHtml (the
|
|
45
|
+
* bell and its panel); and accountHtml (the rail's account entry).
|
|
37
46
|
*/
|
|
38
47
|
import { esc, kitT } from "./strings.js";
|
|
39
48
|
import { icon } from "./icons.js";
|
|
@@ -52,8 +61,13 @@ function attrs(o) {
|
|
|
52
61
|
return s;
|
|
53
62
|
}
|
|
54
63
|
|
|
55
|
-
/**
|
|
56
|
-
|
|
64
|
+
/**
|
|
65
|
+
* One rail entry (a link, .den-ni). `navRole`: the data-nav-role the nav
|
|
66
|
+
* inventory reads ("page" for a rail group's entries: host content).
|
|
67
|
+
*/
|
|
68
|
+
export function navItemHtml(n, navRole) {
|
|
69
|
+
const role =
|
|
70
|
+
typeof navRole === "string" ? ' data-nav-role="' + esc(navRole) + '"' : "";
|
|
57
71
|
const b = n.badge || null;
|
|
58
72
|
const extra = b
|
|
59
73
|
? '<span class="den-bdg' +
|
|
@@ -73,6 +87,7 @@ export function navItemHtml(n) {
|
|
|
73
87
|
'" data-nav="' +
|
|
74
88
|
esc(n.id) +
|
|
75
89
|
'"' +
|
|
90
|
+
(n.pin != null ? "" : role) +
|
|
76
91
|
(n.current ? ' aria-current="page"' : "") +
|
|
77
92
|
attrs(more) +
|
|
78
93
|
' title="' +
|
|
@@ -87,7 +102,12 @@ export function navItemHtml(n) {
|
|
|
87
102
|
extra +
|
|
88
103
|
"</a>";
|
|
89
104
|
return n.pin != null
|
|
90
|
-
? '<div class="den-pin-row"
|
|
105
|
+
? '<div class="den-pin-row"' +
|
|
106
|
+
role +
|
|
107
|
+
">" +
|
|
108
|
+
link +
|
|
109
|
+
(n.after || "") +
|
|
110
|
+
"</div>"
|
|
91
111
|
: link;
|
|
92
112
|
}
|
|
93
113
|
|
|
@@ -96,11 +116,11 @@ export function railGroupHtml(g, body, lang) {
|
|
|
96
116
|
const id = esc(g.id);
|
|
97
117
|
const from = g.from;
|
|
98
118
|
return (
|
|
99
|
-
'<div class="den-rail-group" role="group" aria-labelledby="den-gh-' +
|
|
119
|
+
'<div class="den-rail-group" data-nav-role="rail-group" role="group" aria-labelledby="den-gh-' +
|
|
100
120
|
id +
|
|
101
121
|
'"' +
|
|
102
122
|
(from ? ' aria-describedby="den-gd-' + id + '"' : "") +
|
|
103
|
-
'><div class="den-gh"><span id="den-gh-' +
|
|
123
|
+
'><div class="den-gh" data-nav-role="group"><span id="den-gh-' +
|
|
104
124
|
id +
|
|
105
125
|
'">' +
|
|
106
126
|
esc(g.label) +
|
|
@@ -146,6 +166,8 @@ export function railHtml({
|
|
|
146
166
|
nav = [],
|
|
147
167
|
groups = [],
|
|
148
168
|
foot = [],
|
|
169
|
+
settings,
|
|
170
|
+
account,
|
|
149
171
|
lang,
|
|
150
172
|
collapsed,
|
|
151
173
|
} = {}) {
|
|
@@ -153,12 +175,18 @@ export function railHtml({
|
|
|
153
175
|
for (const g of groups) {
|
|
154
176
|
const items = nav.filter((n) => n.group === g.id);
|
|
155
177
|
if (!items.length) continue;
|
|
156
|
-
html += railGroupHtml(
|
|
178
|
+
html += railGroupHtml(
|
|
179
|
+
g,
|
|
180
|
+
items.map((n) => navItemHtml(n, "page")).join(""),
|
|
181
|
+
lang,
|
|
182
|
+
);
|
|
157
183
|
}
|
|
158
184
|
html += '<div class="den-rail-grow"></div>';
|
|
159
185
|
html += foot
|
|
160
186
|
.map((n) => (typeof n === "string" ? n : navItemHtml(n)))
|
|
161
187
|
.join("");
|
|
188
|
+
html += settingsHtml(settings, lang);
|
|
189
|
+
html += accountHtml(account);
|
|
162
190
|
html += collapseHtml(!!collapsed, lang);
|
|
163
191
|
return html;
|
|
164
192
|
}
|
|
@@ -168,7 +196,11 @@ export function versionChipHtml({ version, lang } = {}) {
|
|
|
168
196
|
return (
|
|
169
197
|
'<button class="den-ib v-pill" id="version-pill" title="' +
|
|
170
198
|
esc(kitT(lang, "kit.version.title")) +
|
|
171
|
-
'"><span class="v-txt"
|
|
199
|
+
'"><span class="v-txt"' +
|
|
200
|
+
(version
|
|
201
|
+
? ' title="v' + esc(String(version).replace(/^v/, "")) + '"'
|
|
202
|
+
: "") +
|
|
203
|
+
">" +
|
|
172
204
|
esc(version ? "v" + String(version).replace(/^v/, "") : "v…") +
|
|
173
205
|
'</span><span class="v-pip" id="v-pip"></span></button>'
|
|
174
206
|
);
|
|
@@ -220,7 +252,24 @@ export function reportPrefillOf(el) {
|
|
|
220
252
|
* `text`, escaped; or `svg`, the product's own markup (the same trust as
|
|
221
253
|
* the icons). `label` names it.
|
|
222
254
|
*/
|
|
223
|
-
|
|
255
|
+
/**
|
|
256
|
+
* The brand's mark (#den-mark).
|
|
257
|
+
* { src, label }: an image file (the default: the kit's marks/den.svg),
|
|
258
|
+
* drawn as Den's theme draws its own: span.den-mark.den-mark-svg,
|
|
259
|
+
* titled by label, holding an 18px <img alt="">. An image runs no
|
|
260
|
+
* script, so no markup of the host's is trusted.
|
|
261
|
+
* { text, label }: escaped text. { svg, label }: the host's own markup.
|
|
262
|
+
* none: the empty slot.
|
|
263
|
+
*/
|
|
264
|
+
export function markHtml(mark) {
|
|
265
|
+
if (mark && mark.src != null)
|
|
266
|
+
return (
|
|
267
|
+
'<span class="den-mark den-mark-svg" id="den-mark" aria-hidden="true" title="' +
|
|
268
|
+
esc(mark.label ?? "") +
|
|
269
|
+
'"><img src="' +
|
|
270
|
+
esc(mark.src) +
|
|
271
|
+
'" alt="" width="18" height="18"></span>'
|
|
272
|
+
);
|
|
224
273
|
if (!mark || (mark.text == null && mark.svg == null))
|
|
225
274
|
return '<span class="den-mark" id="den-mark" aria-hidden="true"></span>';
|
|
226
275
|
return (
|
|
@@ -232,7 +281,15 @@ function markHtml(mark) {
|
|
|
232
281
|
);
|
|
233
282
|
}
|
|
234
283
|
|
|
235
|
-
/**
|
|
284
|
+
/** Where the kit's search starts in a `start` slot (searchHtml's markup). */
|
|
285
|
+
const SEARCH_AT = '<button type="button" class="den-search"';
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* The top bar (header.den-top), in three parts (issue 303): the left part
|
|
289
|
+
* (☰, the brand, and what `start` holds before the search: the crumbs),
|
|
290
|
+
* the search in a fixed slot, and the chips (the host's `end`, then
|
|
291
|
+
* Report, the bell, the version and ◐ ▾, pinned to the right edge).
|
|
292
|
+
*/
|
|
236
293
|
export function topBarHtml({
|
|
237
294
|
product = {},
|
|
238
295
|
lang,
|
|
@@ -240,8 +297,13 @@ export function topBarHtml({
|
|
|
240
297
|
report = true,
|
|
241
298
|
} = {}) {
|
|
242
299
|
const name = product.name ?? "";
|
|
300
|
+
const start = slots.start || "";
|
|
301
|
+
const at = start.indexOf(SEARCH_AT);
|
|
302
|
+
const before = at < 0 ? start : start.slice(0, at);
|
|
303
|
+
const search = at < 0 ? "" : start.slice(at);
|
|
243
304
|
return (
|
|
244
305
|
'<header class="den-top">' +
|
|
306
|
+
'<div class="den-left">' +
|
|
245
307
|
'<button class="den-ib den-menu-btn" id="den-menu-btn" aria-label="' +
|
|
246
308
|
esc(kitT(lang, "kit.menu")) +
|
|
247
309
|
'" aria-expanded="false" aria-controls="den-rail">☰</button>' +
|
|
@@ -252,12 +314,18 @@ export function topBarHtml({
|
|
|
252
314
|
'">' +
|
|
253
315
|
markHtml(product.mark) +
|
|
254
316
|
// The brand is a name, not a heading: the page's own h1 is its one.
|
|
255
|
-
'<span class="den-title">' +
|
|
317
|
+
'<span class="den-title" data-nav-role="brand-title">' +
|
|
256
318
|
esc(name) +
|
|
257
319
|
"</span></a>" +
|
|
258
|
-
|
|
320
|
+
before +
|
|
321
|
+
"</div>" +
|
|
322
|
+
search +
|
|
259
323
|
'<div class="den-chips">' +
|
|
324
|
+
// The host's chips' group, always drawn (empty without chips): the
|
|
325
|
+
// bar's structure is the same in any host.
|
|
326
|
+
'<div class="den-end">' +
|
|
260
327
|
(slots.end || "") +
|
|
328
|
+
"</div>" +
|
|
261
329
|
(report === false ? "" : reportButtonHtml({ inTop: true, lang })) +
|
|
262
330
|
(slots.bell || "") +
|
|
263
331
|
versionChipHtml({ version: product.version, lang }) +
|
|
@@ -287,3 +355,647 @@ export function shellHtml(o = {}) {
|
|
|
287
355
|
"</nav></div>"
|
|
288
356
|
);
|
|
289
357
|
}
|
|
358
|
+
|
|
359
|
+
// ── 0.7.0: the scope crumbs, the search field, the bell, the account ────
|
|
360
|
+
// Pieces of the top bar and the rail a host gave as its own HTML before.
|
|
361
|
+
// The host gives the words and the values; the kit draws them, and
|
|
362
|
+
// shell-client.js wires them (hydrateScope, hydrateSearch, hydrateBell,
|
|
363
|
+
// hydrateAccount). A piece left out draws nothing.
|
|
364
|
+
|
|
365
|
+
/** Crumb ids: "den-scope-<key>" unless the host names its own. */
|
|
366
|
+
const crumbId = (c) => c.id || "den-scope-" + (c.key || "x");
|
|
367
|
+
|
|
368
|
+
/**
|
|
369
|
+
* Whether a menu of `n` entries gets the filter field: `filter` false
|
|
370
|
+
* never, a number past that many, true always, else past 6.
|
|
371
|
+
*/
|
|
372
|
+
export function menuHasFilter(filter, n) {
|
|
373
|
+
if (filter === false) return false;
|
|
374
|
+
if (filter === true) return true;
|
|
375
|
+
return n > (typeof filter === "number" ? filter : 6);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* A menu's type-to-filter field (first in it) and its "No match" line
|
|
380
|
+
* (last): [field, none]. `label`: the menu's name ("Filter <label>").
|
|
381
|
+
*/
|
|
382
|
+
export function menuFilterParts(menuId, label, lang) {
|
|
383
|
+
return [
|
|
384
|
+
'<input type="search" class="den-mfilter" id="' +
|
|
385
|
+
esc(menuId) +
|
|
386
|
+
'-filter" aria-controls="' +
|
|
387
|
+
esc(menuId) +
|
|
388
|
+
'-list" aria-label="' +
|
|
389
|
+
esc(kitT(lang, "kit.menu.filter", { label: label ?? "" })) +
|
|
390
|
+
'" placeholder="' +
|
|
391
|
+
esc(kitT(lang, "kit.menu.filter.ph")) +
|
|
392
|
+
'" autocomplete="off" spellcheck="false">',
|
|
393
|
+
'<p class="den-mnote den-mnone" role="status" hidden>' +
|
|
394
|
+
esc(kitT(lang, "kit.menu.none")) +
|
|
395
|
+
"</p>",
|
|
396
|
+
];
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
/** A crumb's menu, drawn by the kit: links ({ label, href, current }) or HTML. */
|
|
400
|
+
function crumbMenuHtml(c, lang) {
|
|
401
|
+
const m = c.menu;
|
|
402
|
+
if (!m || m === true) return "";
|
|
403
|
+
const menuId = crumbId(c) + "-menu";
|
|
404
|
+
// A long list: a type-to-filter field first, "No match" last.
|
|
405
|
+
const filter =
|
|
406
|
+
Array.isArray(m) && menuHasFilter(c.filter, m.length)
|
|
407
|
+
? menuFilterParts(menuId, c.label, lang)
|
|
408
|
+
: ["", ""];
|
|
409
|
+
const body = Array.isArray(m)
|
|
410
|
+
? m
|
|
411
|
+
.map(
|
|
412
|
+
(l) =>
|
|
413
|
+
'<a class="den-mi" role="menuitem" href="' +
|
|
414
|
+
esc(l.href) +
|
|
415
|
+
'"' +
|
|
416
|
+
(l.current ? ' aria-current="true"' : "") +
|
|
417
|
+
'><span class="den-mi-l">' +
|
|
418
|
+
esc(l.label) +
|
|
419
|
+
"</span></a>",
|
|
420
|
+
)
|
|
421
|
+
.join("")
|
|
422
|
+
: String(m);
|
|
423
|
+
// With a filter, the pop-up holds the field, then the role="menu" list
|
|
424
|
+
// (a menu owns only its items), then "No match".
|
|
425
|
+
if (filter[0])
|
|
426
|
+
return (
|
|
427
|
+
'<div class="den-pop den-scope-menu" id="' +
|
|
428
|
+
esc(menuId) +
|
|
429
|
+
'" hidden>' +
|
|
430
|
+
filter[0] +
|
|
431
|
+
'<div class="den-mlist" role="menu" id="' +
|
|
432
|
+
esc(menuId) +
|
|
433
|
+
'-list" aria-label="' +
|
|
434
|
+
esc(c.label) +
|
|
435
|
+
'">' +
|
|
436
|
+
body +
|
|
437
|
+
"</div>" +
|
|
438
|
+
filter[1] +
|
|
439
|
+
"</div>"
|
|
440
|
+
);
|
|
441
|
+
return (
|
|
442
|
+
'<div class="den-pop den-scope-menu" id="' +
|
|
443
|
+
esc(menuId) +
|
|
444
|
+
'" role="menu" aria-label="' +
|
|
445
|
+
esc(c.label) +
|
|
446
|
+
'" hidden>' +
|
|
447
|
+
body +
|
|
448
|
+
"</div>"
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/**
|
|
453
|
+
* One scope crumb: its small-caps key and its value. With a menu, a
|
|
454
|
+
* button with ▾ (aria-haspopup="menu"); without, a plain label.
|
|
455
|
+
* { key, label, value, menu?, id?, title?, hidden?, optional?, cls?,
|
|
456
|
+
* valueCls? }
|
|
457
|
+
* `menu`: links [{ label, href, current? }] or HTML (the kit draws and
|
|
458
|
+
* opens it), or true (the host opens its own: hydrateScope's onOpen).
|
|
459
|
+
* `filter`: a type-to-filter field at the top of a list of links: by
|
|
460
|
+
* default past 6 of them; a number sets that threshold; false, never.
|
|
461
|
+
* `optional`: the first to give way on a narrow bar. `cls`: more classes;
|
|
462
|
+
* `valueCls`: more classes on the value.
|
|
463
|
+
*/
|
|
464
|
+
export function scopeCrumbHtml(c, lang) {
|
|
465
|
+
if (!c) return "";
|
|
466
|
+
const id = crumbId(c);
|
|
467
|
+
const title = c.title != null ? ' title="' + esc(c.title) + '"' : "";
|
|
468
|
+
const hidden = c.hidden ? " hidden" : "";
|
|
469
|
+
const more = (c.cls ? " " + esc(c.cls) : "") + (c.optional ? " den-opt" : "");
|
|
470
|
+
const key = '<span class="den-k">' + esc(c.label) + "</span> ";
|
|
471
|
+
if (!c.menu)
|
|
472
|
+
return (
|
|
473
|
+
'<span id="' +
|
|
474
|
+
esc(id) +
|
|
475
|
+
'" class="den-ib' +
|
|
476
|
+
more +
|
|
477
|
+
'" data-nav-role="crumb"' +
|
|
478
|
+
hidden +
|
|
479
|
+
title +
|
|
480
|
+
">" +
|
|
481
|
+
key +
|
|
482
|
+
'<span class="' +
|
|
483
|
+
esc(c.valueCls || "den-vn") +
|
|
484
|
+
'">' +
|
|
485
|
+
esc(c.value ?? "") +
|
|
486
|
+
"</span></span>"
|
|
487
|
+
);
|
|
488
|
+
const own = c.menu !== true;
|
|
489
|
+
return (
|
|
490
|
+
'<button type="button" id="' +
|
|
491
|
+
esc(id) +
|
|
492
|
+
'" class="den-ib den-scope-btn' +
|
|
493
|
+
more +
|
|
494
|
+
'" data-scope="' +
|
|
495
|
+
esc(c.key || "") +
|
|
496
|
+
'" data-nav-role="crumb" aria-haspopup="menu" aria-expanded="false"' +
|
|
497
|
+
(own ? ' aria-controls="' + esc(id) + '-menu"' : "") +
|
|
498
|
+
hidden +
|
|
499
|
+
title +
|
|
500
|
+
">" +
|
|
501
|
+
key +
|
|
502
|
+
'<span class="den-v"><span class="den-vn' +
|
|
503
|
+
(c.valueCls ? " " + esc(c.valueCls) : "") +
|
|
504
|
+
'">' +
|
|
505
|
+
esc(c.value ?? "") +
|
|
506
|
+
'</span> <span aria-hidden="true">▾</span></span></button>' +
|
|
507
|
+
crumbMenuHtml(c, lang)
|
|
508
|
+
);
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* The scope crumbs: / KEY value ▾ / KEY value ▾ …, a group named "Scope".
|
|
513
|
+
* scopeHtml({ crumbs, label?, lang, after? })
|
|
514
|
+
* A crumb left out (null, or not in the list) draws nothing, and no
|
|
515
|
+
* separator. Each separator after a crumb is "den-sep den-<key>-sep",
|
|
516
|
+
* hidden with it. `after`: the host's HTML at the group's end (a hidden
|
|
517
|
+
* <select> its pages read, say). No crumbs: nothing at all.
|
|
518
|
+
*/
|
|
519
|
+
export function scopeHtml({ crumbs, label, lang, after } = {}) {
|
|
520
|
+
const list = (crumbs || []).filter(Boolean);
|
|
521
|
+
if (!list.length) return "";
|
|
522
|
+
let html =
|
|
523
|
+
'<div class="den-scope" role="group" aria-label="' +
|
|
524
|
+
esc(label ?? kitT(lang, "kit.scope")) +
|
|
525
|
+
'"><span class="den-sep" aria-hidden="true">/</span>';
|
|
526
|
+
// Each separator after a crumb comes and goes with it: host content.
|
|
527
|
+
list.forEach((c, i) => {
|
|
528
|
+
// The last crumb is kept whole when the crumbs give way (issue 303).
|
|
529
|
+
const last = i === list.length - 1;
|
|
530
|
+
html += scopeCrumbHtml(
|
|
531
|
+
last ? { ...c, cls: (c.cls ? c.cls + " " : "") + "den-last" } : c,
|
|
532
|
+
lang,
|
|
533
|
+
);
|
|
534
|
+
if (i < list.length - 1)
|
|
535
|
+
html +=
|
|
536
|
+
'<span class="den-sep den-' +
|
|
537
|
+
esc(c.key || "x") +
|
|
538
|
+
'-sep" data-nav-role="crumb-sep" aria-hidden="true"' +
|
|
539
|
+
(c.hidden ? " hidden" : "") +
|
|
540
|
+
">/</span>";
|
|
541
|
+
});
|
|
542
|
+
return html + (after || "") + "</div>";
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
/**
|
|
546
|
+
* The search field: the kit's placeholder ("Search…"), then ⌘K inside it,
|
|
547
|
+
* as a button (the host's palette or page opens on it: hydrateSearch).
|
|
548
|
+
* searchHtml({ id?, shortcut?, lang })
|
|
549
|
+
* Its placeholder and its name ("Search") are the kit's words, in the
|
|
550
|
+
* page's language: one search in every product, so a host can't set them.
|
|
551
|
+
* `shortcut: false`: no ⌘K.
|
|
552
|
+
*/
|
|
553
|
+
export function searchHtml({ id, shortcut, lang } = {}) {
|
|
554
|
+
const keys = shortcut !== false;
|
|
555
|
+
return (
|
|
556
|
+
'<button type="button" class="den-search" id="' +
|
|
557
|
+
esc(id || "den-search") +
|
|
558
|
+
'" aria-haspopup="dialog" data-nav-kit="search"' +
|
|
559
|
+
(keys ? ' aria-keyshortcuts="Meta+K Control+K"' : "") +
|
|
560
|
+
' aria-label="' +
|
|
561
|
+
esc(kitT(lang, "kit.search.label")) +
|
|
562
|
+
'"><span class="den-search-ph">' +
|
|
563
|
+
esc(kitT(lang, "kit.search.ph")) +
|
|
564
|
+
"</span>" +
|
|
565
|
+
(keys ? '<kbd aria-hidden="true">⌘K</kbd>' : "") +
|
|
566
|
+
'<span class="den-search-ic" aria-hidden="true">⌕</span></button>'
|
|
567
|
+
);
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
/** The bell's count on its badge: "" for none, 99+ past 99. */
|
|
571
|
+
export function bellCount(n) {
|
|
572
|
+
const c = Number(n) || 0;
|
|
573
|
+
return c <= 0 ? "" : c > 99 ? "99+" : String(c);
|
|
574
|
+
}
|
|
575
|
+
|
|
576
|
+
/**
|
|
577
|
+
* The bell: a button that opens the notifications panel, with its count.
|
|
578
|
+
* bellButtonHtml({ count?, label?, id?, lang })
|
|
579
|
+
* Its name says the count ("Notifications: 3 unread").
|
|
580
|
+
*/
|
|
581
|
+
export function bellButtonHtml({ count, label, id, lang } = {}) {
|
|
582
|
+
const n = Number(count) || 0;
|
|
583
|
+
const word = label ?? kitT(lang, "kit.bell");
|
|
584
|
+
const name = n > 0 ? kitT(lang, "kit.bell.n", { n }) : word;
|
|
585
|
+
return (
|
|
586
|
+
'<button type="button" class="den-ib den-bell" id="' +
|
|
587
|
+
esc(id || "den-bell") +
|
|
588
|
+
'" aria-haspopup="dialog" aria-expanded="false" aria-label="' +
|
|
589
|
+
esc(name) +
|
|
590
|
+
'" title="' +
|
|
591
|
+
esc(word) +
|
|
592
|
+
'"><svg viewBox="0 0 24 24" width="16" height="16" aria-hidden="true" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9"/><path d="M10.3 21a1.94 1.94 0 0 0 3.4 0"/></svg>' +
|
|
593
|
+
'<span class="den-bell-n"' +
|
|
594
|
+
(n > 0 ? "" : " hidden") +
|
|
595
|
+
">" +
|
|
596
|
+
esc(bellCount(n)) +
|
|
597
|
+
"</span></button>"
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/** One row of the bell's panel. */
|
|
602
|
+
function bellRowHtml(it) {
|
|
603
|
+
const text = esc(it.text ?? "");
|
|
604
|
+
return (
|
|
605
|
+
'<div class="den-bell-row' +
|
|
606
|
+
(it.read ? " read" : "") +
|
|
607
|
+
'"' +
|
|
608
|
+
(it.id != null ? ' data-id="' + esc(it.id) + '"' : "") +
|
|
609
|
+
">" +
|
|
610
|
+
(it.href != null
|
|
611
|
+
? '<a href="' + esc(it.href) + '">' + text + "</a>"
|
|
612
|
+
: '<span class="den-bell-t">' + text + "</span>") +
|
|
613
|
+
(it.time
|
|
614
|
+
? "<time" +
|
|
615
|
+
(it.datetime ? ' datetime="' + esc(it.datetime) + '"' : "") +
|
|
616
|
+
">" +
|
|
617
|
+
esc(it.time) +
|
|
618
|
+
"</time>"
|
|
619
|
+
: "") +
|
|
620
|
+
"</div>"
|
|
621
|
+
);
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
/**
|
|
625
|
+
* The bell's panel content: its heading, then rows or the empty state.
|
|
626
|
+
* bellPanelHtml({ title?, titleId?, actions?, lead?, items?, body?,
|
|
627
|
+
* empty?, after?, foot?, lang })
|
|
628
|
+
* `items`: [{ text, href?, time?, datetime?, read?, id? }], drawn as rows;
|
|
629
|
+
* or `body`, the host's own HTML for them. Neither (or no items): the
|
|
630
|
+
* empty state, `empty` { text?, more? } (more: HTML under the words).
|
|
631
|
+
* `actions`: buttons beside the heading (Mark all read); `lead`: HTML
|
|
632
|
+
* under the heading; `after`: HTML after the rows; `foot`: the footer (a
|
|
633
|
+
* Report button). Every HTML part is the host's own.
|
|
634
|
+
*/
|
|
635
|
+
export function bellPanelHtml({
|
|
636
|
+
title,
|
|
637
|
+
titleId,
|
|
638
|
+
actions,
|
|
639
|
+
lead,
|
|
640
|
+
items,
|
|
641
|
+
body,
|
|
642
|
+
empty,
|
|
643
|
+
after,
|
|
644
|
+
foot,
|
|
645
|
+
lang,
|
|
646
|
+
} = {}) {
|
|
647
|
+
const list = Array.isArray(items) ? items : [];
|
|
648
|
+
const e = empty || {};
|
|
649
|
+
const rows =
|
|
650
|
+
body != null && body !== ""
|
|
651
|
+
? body
|
|
652
|
+
: list.length
|
|
653
|
+
? list.map(bellRowHtml).join("")
|
|
654
|
+
: '<div class="den-bell-empty"><p>' +
|
|
655
|
+
esc(e.text ?? kitT(lang, "kit.bell.empty")) +
|
|
656
|
+
"</p>" +
|
|
657
|
+
(e.more || "") +
|
|
658
|
+
"</div>";
|
|
659
|
+
return (
|
|
660
|
+
'<div class="den-bell-hd"><h2 id="' +
|
|
661
|
+
esc(titleId || "den-bell-h") +
|
|
662
|
+
'">' +
|
|
663
|
+
esc(title ?? kitT(lang, "kit.bell")) +
|
|
664
|
+
"</h2>" +
|
|
665
|
+
(actions || "") +
|
|
666
|
+
"</div>" +
|
|
667
|
+
(lead || "") +
|
|
668
|
+
rows +
|
|
669
|
+
(after || "") +
|
|
670
|
+
(foot || "")
|
|
671
|
+
);
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* The account entry, in the rail's foot: who is signed in, here.
|
|
676
|
+
* accountHtml({ label, detail?, href?, action?, icon?, id?, navId?,
|
|
677
|
+
* attrs?, current? })
|
|
678
|
+
* `href`: a link; else `menu` true: a button opening the account menu
|
|
679
|
+
* (accountMenuHtml, hydrateAccount's menu; id "den-account" unless
|
|
680
|
+
* given); else `action` true: a button (hydrateAccount's onAction). The
|
|
681
|
+
* name and tooltip read "label · detail". It is a rail entry (.den-ni)
|
|
682
|
+
* marked data-den-account. No label: nothing.
|
|
683
|
+
*/
|
|
684
|
+
/**
|
|
685
|
+
* Who is signed in, as the kit draws it (0.7.1): the name on the first
|
|
686
|
+
* line, @login on the second; @login alone when no name is known. The
|
|
687
|
+
* role is shown in the account menu's header only ({ menu: true }), on
|
|
688
|
+
* its own line. From data: { name?, login?, role? }; with no
|
|
689
|
+
* identity, { local: true } draws the kit's word for this computer. The old
|
|
690
|
+
* { label, detail } (or the menu's { name, detail }) still work for one
|
|
691
|
+
* release, as they were given, marked data-nav-legacy for the nav
|
|
692
|
+
* inventory. Returns { lines: [first, second?], shape, legacy, full }.
|
|
693
|
+
*/
|
|
694
|
+
export function accountWho(a, { menu = false } = {}) {
|
|
695
|
+
if (!a) return null;
|
|
696
|
+
const legacy = a.label != null || a.detail != null;
|
|
697
|
+
const name = a.name ?? a.label ?? "";
|
|
698
|
+
const login = a.login
|
|
699
|
+
? String(a.login).startsWith("@")
|
|
700
|
+
? String(a.login)
|
|
701
|
+
: "@" + a.login
|
|
702
|
+
: (a.detail ?? "");
|
|
703
|
+
// The role is shown in the account menu's header only, never in the
|
|
704
|
+
// rail's entry (it isn't part of the entry's shape).
|
|
705
|
+
const role = menu ? a.role || "" : "";
|
|
706
|
+
let first = name || login;
|
|
707
|
+
// No identity known at all: the kit's own word for this computer.
|
|
708
|
+
const local = !first && !!a.local;
|
|
709
|
+
if (local) first = kitT(a.lang, "kit.account.local");
|
|
710
|
+
if (!first) return null;
|
|
711
|
+
const second = name ? login : "";
|
|
712
|
+
const shape = [
|
|
713
|
+
name ? "name" : "",
|
|
714
|
+
a.login || a.detail ? "login" : "",
|
|
715
|
+
local ? "local" : "",
|
|
716
|
+
]
|
|
717
|
+
.filter(Boolean)
|
|
718
|
+
.join(",");
|
|
719
|
+
const lines = [first, second].filter(Boolean);
|
|
720
|
+
return {
|
|
721
|
+
lines,
|
|
722
|
+
role,
|
|
723
|
+
shape,
|
|
724
|
+
legacy,
|
|
725
|
+
full: lines.join(" · "),
|
|
726
|
+
};
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
function whoLinesHtml(who) {
|
|
730
|
+
return (
|
|
731
|
+
'<span class="den-acct-n">' +
|
|
732
|
+
esc(who.lines[0]) +
|
|
733
|
+
"</span>" +
|
|
734
|
+
(who.lines[1]
|
|
735
|
+
? '<span class="den-acct-l">' + esc(who.lines[1]) + "</span>"
|
|
736
|
+
: "") +
|
|
737
|
+
(who.role ? '<span class="den-acct-r">' + esc(who.role) + "</span>" : "")
|
|
738
|
+
);
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
export function accountHtml(a) {
|
|
742
|
+
const who = accountWho(a);
|
|
743
|
+
if (!who) return "";
|
|
744
|
+
const full = who.full;
|
|
745
|
+
const more = { ...(a.attrs || {}) };
|
|
746
|
+
if (a.id) more.id = a.id;
|
|
747
|
+
more["data-nav-shape"] = who.shape;
|
|
748
|
+
if (who.legacy) more["data-nav-legacy"] = "account";
|
|
749
|
+
// Who is signed in: the host's data (host content for the nav
|
|
750
|
+
// inventory, which compares its shape: which fields, how many lines).
|
|
751
|
+
const words =
|
|
752
|
+
'<span class="den-lbl den-acct" data-nav-role="account-name">' +
|
|
753
|
+
whoLinesHtml(who) +
|
|
754
|
+
"</span>";
|
|
755
|
+
if (a.href == null && a.menu && !a.id) more.id = "den-account";
|
|
756
|
+
const open =
|
|
757
|
+
a.href != null
|
|
758
|
+
? '<a class="den-ni" data-den-account href="' + esc(a.href) + '"'
|
|
759
|
+
: a.menu
|
|
760
|
+
? '<button type="button" class="den-ni" data-den-account aria-haspopup="menu" aria-expanded="false"'
|
|
761
|
+
: '<button type="button" class="den-ni" data-den-account data-act="account"';
|
|
762
|
+
return (
|
|
763
|
+
open +
|
|
764
|
+
' data-nav="' +
|
|
765
|
+
esc(a.navId || "account") +
|
|
766
|
+
'"' +
|
|
767
|
+
(a.current ? ' aria-current="page"' : "") +
|
|
768
|
+
attrs(more) +
|
|
769
|
+
' title="' +
|
|
770
|
+
esc(full) +
|
|
771
|
+
'">' +
|
|
772
|
+
icon(a.icon || "person") +
|
|
773
|
+
words +
|
|
774
|
+
(a.href != null ? "</a>" : "</button>")
|
|
775
|
+
);
|
|
776
|
+
}
|
|
777
|
+
|
|
778
|
+
/**
|
|
779
|
+
* The Settings entry, in the rail's foot after the host's entries.
|
|
780
|
+
* settingsHtml({ href, label?, current?, id? }, lang)
|
|
781
|
+
* No href: nothing.
|
|
782
|
+
*/
|
|
783
|
+
export function settingsHtml(o, lang) {
|
|
784
|
+
if (!o || !o.href) return "";
|
|
785
|
+
return navItemHtml({
|
|
786
|
+
id: o.id || "settings",
|
|
787
|
+
href: o.href,
|
|
788
|
+
label: o.label ?? kitT(lang, "kit.settings"),
|
|
789
|
+
icon: "settings",
|
|
790
|
+
current: !!o.current,
|
|
791
|
+
});
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
/**
|
|
795
|
+
* The appearance button, ◐ ▾, last in the bar (the `account` slot): its
|
|
796
|
+
* menu (hydrateAppearance) holds the mode, the theme and the language.
|
|
797
|
+
* appearanceButtonHtml({ id?, label?, title?, lang })
|
|
798
|
+
*/
|
|
799
|
+
export function appearanceButtonHtml({ id, label, title, lang } = {}) {
|
|
800
|
+
return (
|
|
801
|
+
'<button id="' +
|
|
802
|
+
esc(id || "appearance-btn") +
|
|
803
|
+
'" type="button" class="den-ib appearance-btn" title="' +
|
|
804
|
+
esc(title ?? kitT(lang, "kit.appearance.title")) +
|
|
805
|
+
'" aria-label="' +
|
|
806
|
+
esc(label ?? kitT(lang, "kit.appearance")) +
|
|
807
|
+
'" aria-haspopup="menu" aria-expanded="false"><span aria-hidden="true">◐ ▾</span></button>'
|
|
808
|
+
);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
/** One row of a kit menu: a radio (checked set), a link or a button. */
|
|
812
|
+
function menuRowHtml(r) {
|
|
813
|
+
const radio = r.checked != null;
|
|
814
|
+
const tag = r.href != null ? "a" : "button";
|
|
815
|
+
return (
|
|
816
|
+
"<" +
|
|
817
|
+
tag +
|
|
818
|
+
' class="den-mi" tabindex="-1" role="' +
|
|
819
|
+
(radio ? "menuitemradio" : "menuitem") +
|
|
820
|
+
'"' +
|
|
821
|
+
(radio ? ' aria-checked="' + (r.checked ? "true" : "false") + '"' : "") +
|
|
822
|
+
(r.href != null ? ' href="' + esc(r.href) + '"' : ' type="button"') +
|
|
823
|
+
(r.kind ? ' data-kind="' + esc(r.kind) + '"' : "") +
|
|
824
|
+
(r.value != null ? ' data-value="' + esc(r.value) + '"' : "") +
|
|
825
|
+
'><span class="den-mi-l">' +
|
|
826
|
+
esc(r.label) +
|
|
827
|
+
"</span></" +
|
|
828
|
+
tag +
|
|
829
|
+
">"
|
|
830
|
+
);
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
/**
|
|
834
|
+
* The appearance menu's content.
|
|
835
|
+
* appearanceMenuHtml({ mode, modes?, themes?, notice?, languages?,
|
|
836
|
+
* items?, lang })
|
|
837
|
+
* mode: "system", "dark" or "light" (checked); modes: [{ value, label }]
|
|
838
|
+
* (default the kit's System, Dark, Light); themes: [{ value, label,
|
|
839
|
+
* selected? }]; notice: a line under the themes; languages: [{ id, name,
|
|
840
|
+
* current? }], each named in itself; items: [{ label, href? | id }] after
|
|
841
|
+
* a rule (Settings, say). A part with nothing in it draws nothing.
|
|
842
|
+
*/
|
|
843
|
+
export function appearanceMenuHtml({
|
|
844
|
+
mode,
|
|
845
|
+
modes,
|
|
846
|
+
themes,
|
|
847
|
+
notice,
|
|
848
|
+
languages,
|
|
849
|
+
items,
|
|
850
|
+
lang,
|
|
851
|
+
} = {}) {
|
|
852
|
+
const head = (w) =>
|
|
853
|
+
'<div class="den-ml" aria-hidden="true">' + esc(w) + "</div>";
|
|
854
|
+
const hr = '<div class="den-hr" role="separator"></div>';
|
|
855
|
+
const ms = modes || [
|
|
856
|
+
{ value: "system", label: kitT(lang, "kit.mode.system") },
|
|
857
|
+
{ value: "dark", label: kitT(lang, "kit.mode.dark") },
|
|
858
|
+
{ value: "light", label: kitT(lang, "kit.mode.light") },
|
|
859
|
+
];
|
|
860
|
+
const parts = [];
|
|
861
|
+
parts.push(
|
|
862
|
+
head(kitT(lang, "kit.appearance")) +
|
|
863
|
+
ms
|
|
864
|
+
.map((m) =>
|
|
865
|
+
menuRowHtml({
|
|
866
|
+
label: m.label,
|
|
867
|
+
checked: m.value === mode,
|
|
868
|
+
kind: "mode",
|
|
869
|
+
value: m.value,
|
|
870
|
+
}),
|
|
871
|
+
)
|
|
872
|
+
.join(""),
|
|
873
|
+
);
|
|
874
|
+
if ((themes && themes.length) || notice)
|
|
875
|
+
parts.push(
|
|
876
|
+
head(kitT(lang, "kit.theme")) +
|
|
877
|
+
(themes || [])
|
|
878
|
+
.map((t) =>
|
|
879
|
+
menuRowHtml({
|
|
880
|
+
label: t.label,
|
|
881
|
+
checked: !!t.selected,
|
|
882
|
+
kind: "theme",
|
|
883
|
+
value: t.value ?? "",
|
|
884
|
+
}),
|
|
885
|
+
)
|
|
886
|
+
.join("") +
|
|
887
|
+
(notice
|
|
888
|
+
? '<p class="den-mnote" role="status">' + esc(notice) + "</p>"
|
|
889
|
+
: ""),
|
|
890
|
+
);
|
|
891
|
+
if (languages && languages.length)
|
|
892
|
+
parts.push(
|
|
893
|
+
head(kitT(lang, "kit.language")) +
|
|
894
|
+
languages
|
|
895
|
+
.map((l) =>
|
|
896
|
+
menuRowHtml({
|
|
897
|
+
label: l.name,
|
|
898
|
+
checked: !!l.current,
|
|
899
|
+
kind: "language",
|
|
900
|
+
value: l.id,
|
|
901
|
+
}),
|
|
902
|
+
)
|
|
903
|
+
.join(""),
|
|
904
|
+
);
|
|
905
|
+
if (items && items.length)
|
|
906
|
+
parts.push(
|
|
907
|
+
items
|
|
908
|
+
.map((it) =>
|
|
909
|
+
menuRowHtml({
|
|
910
|
+
label: it.label,
|
|
911
|
+
href: it.href,
|
|
912
|
+
kind: "item",
|
|
913
|
+
value: it.id,
|
|
914
|
+
}),
|
|
915
|
+
)
|
|
916
|
+
.join(""),
|
|
917
|
+
);
|
|
918
|
+
return parts.join(hr);
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* The account entry's menu: who is signed in (accountWho: the name, then
|
|
923
|
+
* @login), a rule, then the entries.
|
|
924
|
+
* accountMenuHtml({ name?, login?, role?, items, lang })
|
|
925
|
+
* ({ name, detail } is the old path, for one release.)
|
|
926
|
+
* items: [{ label, href }] links, [{ label, id }] buttons (onPick "item"),
|
|
927
|
+
* or [{ label, action: { method?, url, csrf?, field? } }]: a form that
|
|
928
|
+
* posts to url on its own, with no script (csrf, if any, in a hidden
|
|
929
|
+
* field named `field`, "csrf" by default).
|
|
930
|
+
*/
|
|
931
|
+
export function accountMenuHtml({ name, login, role, detail, items } = {}) {
|
|
932
|
+
const parts = [];
|
|
933
|
+
// The menu's { name, detail } were free text: the old path maps them
|
|
934
|
+
// as the entry's label and detail.
|
|
935
|
+
const w = accountWho(
|
|
936
|
+
detail != null ? { label: name, detail } : { name, login, role },
|
|
937
|
+
{ menu: true },
|
|
938
|
+
);
|
|
939
|
+
if (w)
|
|
940
|
+
parts.push(
|
|
941
|
+
'<div class="den-ml den-acct" data-nav-shape="' +
|
|
942
|
+
esc(w.shape) +
|
|
943
|
+
'"' +
|
|
944
|
+
(w.legacy ? ' data-nav-legacy="account"' : "") +
|
|
945
|
+
">" +
|
|
946
|
+
whoLinesHtml(w) +
|
|
947
|
+
"</div>",
|
|
948
|
+
);
|
|
949
|
+
const rows = (items || [])
|
|
950
|
+
.map((it) => {
|
|
951
|
+
if (!it || !it.label) return "";
|
|
952
|
+
const a = it.action;
|
|
953
|
+
if (a && a.url)
|
|
954
|
+
return (
|
|
955
|
+
'<form class="den-mform" method="' +
|
|
956
|
+
esc(a.method || "post") +
|
|
957
|
+
'" action="' +
|
|
958
|
+
esc(a.url) +
|
|
959
|
+
'">' +
|
|
960
|
+
(a.csrf != null
|
|
961
|
+
? '<input type="hidden" name="' +
|
|
962
|
+
esc(a.field || "csrf") +
|
|
963
|
+
'" value="' +
|
|
964
|
+
esc(a.csrf) +
|
|
965
|
+
'">'
|
|
966
|
+
: "") +
|
|
967
|
+
'<button type="submit" class="den-mi" tabindex="-1" role="menuitem"><span class="den-mi-l">' +
|
|
968
|
+
esc(it.label) +
|
|
969
|
+
"</span></button></form>"
|
|
970
|
+
);
|
|
971
|
+
return menuRowHtml({
|
|
972
|
+
label: it.label,
|
|
973
|
+
href: it.href,
|
|
974
|
+
kind: "item",
|
|
975
|
+
value: it.id,
|
|
976
|
+
});
|
|
977
|
+
})
|
|
978
|
+
.join("");
|
|
979
|
+
if (rows) parts.push(rows);
|
|
980
|
+
return parts.join('<div class="den-hr" role="separator"></div>');
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* The update-waiting pill beside the version chip: ⚠ and its words, a
|
|
985
|
+
* button (setWaiting in version.js shows and wires it).
|
|
986
|
+
* waitingHtml({ label, action, title?, name?, id? })
|
|
987
|
+
* Reads "⚠ label · action"; below 720px only ⚠.
|
|
988
|
+
*/
|
|
989
|
+
export function waitingHtml({ label, action, title, name, id } = {}) {
|
|
990
|
+
return (
|
|
991
|
+
'<button id="' +
|
|
992
|
+
esc(id || "stale-pill") +
|
|
993
|
+
'" class="stale-pill"' +
|
|
994
|
+
(title != null ? ' title="' + esc(title) + '"' : "") +
|
|
995
|
+
(name != null ? ' aria-label="' + esc(name) + '"' : "") +
|
|
996
|
+
'><span aria-hidden="true">⚠</span><span class="stale-lbl"> ' +
|
|
997
|
+
esc(label ?? "") +
|
|
998
|
+
(action != null ? " · <b>" + esc(action) + "</b>" : "") +
|
|
999
|
+
"</span></button>"
|
|
1000
|
+
);
|
|
1001
|
+
}
|