@monster-orange/den-ui 0.7.4 → 0.7.6
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 +96 -0
- package/package.json +11 -1
- package/src/kit.d.ts +7 -0
- package/src/kit.js +10 -0
- package/src/markdown-editor.css +230 -0
- package/src/markdown-editor.d.ts +187 -0
- package/src/markdown-editor.js +1122 -0
- package/src/report.d.ts +7 -1
- package/src/report.js +32 -2
- package/src/savestate.css +75 -0
- package/src/savestate.d.ts +73 -0
- package/src/savestate.js +294 -0
- package/src/shell-html.d.ts +5 -0
- package/src/shell-html.js +43 -2
- package/src/shell.css +16 -0
- package/src/strings.js +74 -0
- package/src/whatsnew.js +13 -2
package/src/report.d.ts
CHANGED
|
@@ -20,7 +20,13 @@ export interface ReportAdapter {
|
|
|
20
20
|
},
|
|
21
21
|
) => Promise<{ number: number; url?: string } | { error: string }>;
|
|
22
22
|
info?: () => Promise<{
|
|
23
|
-
repos?: {
|
|
23
|
+
repos?: {
|
|
24
|
+
repo: string;
|
|
25
|
+
/** Who can see it; missing or anything else reads as "public". */
|
|
26
|
+
visibility?: "public" | "private" | "internal";
|
|
27
|
+
/** Who can see it, as words (shown after a private or internal pill). */
|
|
28
|
+
audience?: string;
|
|
29
|
+
}[];
|
|
24
30
|
maxPerHour?: number;
|
|
25
31
|
captureSeconds?: number;
|
|
26
32
|
}>;
|
package/src/report.js
CHANGED
|
@@ -13,6 +13,9 @@
|
|
|
13
13
|
* with the link. With no way to send, the form offers
|
|
14
14
|
* Copy report only.
|
|
15
15
|
* info() → { repos: [{ repo }], maxPerHour, captureSeconds }
|
|
16
|
+
* each repo may say its visibility ("public" | "private" |
|
|
17
|
+
* "internal"; missing or anything else reads as public)
|
|
18
|
+
* and an audience (who can see it, plain text)
|
|
16
19
|
* diagnostics() → { sections: { name: text } } shown on Include
|
|
17
20
|
* preview(form, headers) → { status, data: { title, body } }
|
|
18
21
|
* the text the product will post (its redactor's); else
|
|
@@ -294,6 +297,32 @@ export async function openReport(opts = {}) {
|
|
|
294
297
|
function allSections() {
|
|
295
298
|
return { ...st.diag, ...st.client };
|
|
296
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* Who can see the selected repo (issue 415): public unless the host says
|
|
302
|
+
* private or internal, with the host's audience words then.
|
|
303
|
+
*/
|
|
304
|
+
function vis(repos) {
|
|
305
|
+
const r = repos.find((x) => x.repo === st.repo) || {};
|
|
306
|
+
const v =
|
|
307
|
+
r.visibility === "private" || r.visibility === "internal"
|
|
308
|
+
? r.visibility
|
|
309
|
+
: "public";
|
|
310
|
+
const who = v === "public" ? "" : String(r.audience || "").trim();
|
|
311
|
+
return { v, who };
|
|
312
|
+
}
|
|
313
|
+
/** The pill after the destination, then the audience when not public. */
|
|
314
|
+
function visPill(repos) {
|
|
315
|
+
const { v, who } = vis(repos);
|
|
316
|
+
const key = { public: "pub", private: "priv", internal: "int" }[v];
|
|
317
|
+
return `<span class="fb-pill" data-vis="${v}">${esc(t(`kit.report.${key}`))}</span>${who ? `<span class="fb-fine">${esc(who)}</span>` : ""}`;
|
|
318
|
+
}
|
|
319
|
+
/** Above Send: the public warning, or a quiet line for a private repo. */
|
|
320
|
+
function visNote(repos) {
|
|
321
|
+
const { v, who } = vis(repos);
|
|
322
|
+
if (v === "public")
|
|
323
|
+
return `<div class="fb-warn" role="note"><b>${esc(t("kit.report.pub"))}.</b> ${esc(t("kit.report.pubW"))}</div>`;
|
|
324
|
+
return `<p class="fb-fine" role="note" data-vis-note>${esc(who ? t("kit.report.privW", { who }) : t("kit.report.privN"))}</p>`;
|
|
325
|
+
}
|
|
297
326
|
/** Whether a screenshot goes with the report. */
|
|
298
327
|
function shotOn() {
|
|
299
328
|
return !!st.shot && !st.noShot;
|
|
@@ -447,7 +476,7 @@ ${
|
|
|
447
476
|
)
|
|
448
477
|
.join("")}</select>`
|
|
449
478
|
: `<b>${esc(st.repo)}</b>`
|
|
450
|
-
}
|
|
479
|
+
}${visPill(repos)}</div>`
|
|
451
480
|
: ""
|
|
452
481
|
}
|
|
453
482
|
<pre data-preview>${esc(pv ? `${pv.title}\n\n${pv.body}` : "…")}</pre>${
|
|
@@ -455,7 +484,7 @@ ${
|
|
|
455
484
|
? `<div class="fb-h">${esc(t("kit.report.revShot", { n: st.masks.length }))}</div><div class="fb-shot"><img data-shot-review alt="${esc(t("kit.report.revShot", { n: st.masks.length }))}" src="${maskedShot().toDataURL("image/png")}"></div>`
|
|
456
485
|
: ""
|
|
457
486
|
}
|
|
458
|
-
${sends() ?
|
|
487
|
+
${sends() ? visNote(repos) : ""}${err}${st.copied ? `<p class="fb-fine" role="status">${esc(t(st.copied === "ok" ? "kit.report.copied" : "kit.report.copyFailed"))}</p>` : ""}
|
|
459
488
|
<div class="fb-btns">${sends() ? btn("send", t("kit.report.send"), true) : btn("copy", t("kit.report.copy"), true)}${laterBtn(t("kit.report.later"))}${btn("back-include", t("kit.report.back"))}</div>`;
|
|
460
489
|
} else if (st.step === "signin") {
|
|
461
490
|
label = t("kit.report.siH");
|
|
@@ -782,6 +811,7 @@ ${st.link ? `<p class="fb-fine">${esc(t("kit.report.siAlt"))} ${linkBtn(st.link,
|
|
|
782
811
|
}
|
|
783
812
|
if (f === "repo") {
|
|
784
813
|
st.repo = el.value;
|
|
814
|
+
render('[data-f="repo"]');
|
|
785
815
|
void preview();
|
|
786
816
|
}
|
|
787
817
|
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/* den-ui: the save-state line's look (savestate.js). Tokens only: no
|
|
2
|
+
colour of its own. Linked, never injected: clean under style-src 'self'.
|
|
3
|
+
The dot's colour is the only thing that moves (var(--dur-fast)). */
|
|
4
|
+
.den-savestate {
|
|
5
|
+
display: flex;
|
|
6
|
+
align-items: center;
|
|
7
|
+
gap: var(--space-1);
|
|
8
|
+
margin: 0;
|
|
9
|
+
min-height: 20px;
|
|
10
|
+
font-family: var(--sans);
|
|
11
|
+
font-size: var(--fs-s);
|
|
12
|
+
font-weight: 400;
|
|
13
|
+
line-height: 20px;
|
|
14
|
+
color: var(--muted);
|
|
15
|
+
}
|
|
16
|
+
.den-savestate::before {
|
|
17
|
+
content: "";
|
|
18
|
+
flex: none;
|
|
19
|
+
width: 6px;
|
|
20
|
+
height: 6px;
|
|
21
|
+
border-radius: 50%;
|
|
22
|
+
background-color: transparent;
|
|
23
|
+
transition: background-color var(--dur-fast) ease;
|
|
24
|
+
}
|
|
25
|
+
/* idle: no words and no dot; the line keeps its height. */
|
|
26
|
+
.den-savestate[data-state="idle"]::before {
|
|
27
|
+
visibility: hidden;
|
|
28
|
+
}
|
|
29
|
+
.den-savestate[data-state="saving"]::before {
|
|
30
|
+
background-color: var(--faint);
|
|
31
|
+
}
|
|
32
|
+
.den-savestate[data-state="saved"]::before {
|
|
33
|
+
background-color: var(--ok);
|
|
34
|
+
}
|
|
35
|
+
.den-savestate[data-state="error"] {
|
|
36
|
+
color: var(--bad);
|
|
37
|
+
}
|
|
38
|
+
.den-savestate[data-state="error"]::before {
|
|
39
|
+
background-color: var(--bad);
|
|
40
|
+
}
|
|
41
|
+
/* Copy text: a link-style button after the words. */
|
|
42
|
+
.den-savestate-copy {
|
|
43
|
+
font: inherit;
|
|
44
|
+
margin: 0;
|
|
45
|
+
margin-inline-start: var(--space-1);
|
|
46
|
+
padding: 0;
|
|
47
|
+
border: 0;
|
|
48
|
+
background: none;
|
|
49
|
+
color: var(--accent-text);
|
|
50
|
+
text-decoration: underline;
|
|
51
|
+
text-underline-offset: 2px;
|
|
52
|
+
cursor: pointer;
|
|
53
|
+
}
|
|
54
|
+
.den-savestate-copy:focus-visible {
|
|
55
|
+
outline: 2px solid var(--accent);
|
|
56
|
+
outline-offset: 2px;
|
|
57
|
+
border-radius: 2px;
|
|
58
|
+
}
|
|
59
|
+
/* The live region beside the line: heard, never seen. */
|
|
60
|
+
.den-savestate-sr {
|
|
61
|
+
position: absolute;
|
|
62
|
+
width: 1px;
|
|
63
|
+
height: 1px;
|
|
64
|
+
padding: 0;
|
|
65
|
+
margin: -1px;
|
|
66
|
+
overflow: hidden;
|
|
67
|
+
clip: rect(0 0 0 0);
|
|
68
|
+
white-space: nowrap;
|
|
69
|
+
border: 0;
|
|
70
|
+
}
|
|
71
|
+
@media (prefers-reduced-motion: reduce) {
|
|
72
|
+
.den-savestate::before {
|
|
73
|
+
transition: none;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/** Save 800 ms after the last change. */
|
|
2
|
+
export declare const SAVE_AFTER_MS: number;
|
|
3
|
+
/** "Saving…" only when a save takes longer than this (400 ms). */
|
|
4
|
+
export declare const SAVING_AFTER_MS: number;
|
|
5
|
+
/** The first retries after a failure: 2 s, 4 s, 8 s. */
|
|
6
|
+
export declare const RETRY_MS: readonly number[];
|
|
7
|
+
/** Then a retry every 30 s. */
|
|
8
|
+
export declare const RETRY_EVERY_MS: number;
|
|
9
|
+
|
|
10
|
+
export type SaveStateName = "idle" | "saving" | "saved" | "error";
|
|
11
|
+
|
|
12
|
+
/** One change of state. announce: what a screen reader is told, if anything. */
|
|
13
|
+
export interface SaveStateChange {
|
|
14
|
+
state: SaveStateName;
|
|
15
|
+
/** saved: when it saved. */
|
|
16
|
+
at?: Date;
|
|
17
|
+
/** "error" on the first failure, "recovered" on the success after it. */
|
|
18
|
+
announce: "error" | "recovered" | null;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The kit's words, replaced for this line only. {time} fills savedAt. */
|
|
22
|
+
export interface SaveStateWords {
|
|
23
|
+
saving?: string;
|
|
24
|
+
saved?: string;
|
|
25
|
+
error?: string;
|
|
26
|
+
copy?: string;
|
|
27
|
+
savedAt?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface SaveStateOptions {
|
|
31
|
+
/** The host's save; it rejects when the text did not save. */
|
|
32
|
+
save: () => Promise<unknown>;
|
|
33
|
+
/** What Copy text copies (the title and body, say). None: no Copy text. */
|
|
34
|
+
copyText?: (() => string) | null;
|
|
35
|
+
/** Its `input` is changed(), its `focusout` (blur) is flush(). */
|
|
36
|
+
watch?: EventTarget | null;
|
|
37
|
+
/** The words' language (default: <html lang>). */
|
|
38
|
+
lang?: string | (() => string);
|
|
39
|
+
words?: SaveStateWords;
|
|
40
|
+
/** Where savestate.css is, for a page that doesn't link it. */
|
|
41
|
+
css?: string | null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface SaveScheduler {
|
|
45
|
+
/** The text changed: a save SAVE_AFTER_MS after the last change. */
|
|
46
|
+
changed(): void;
|
|
47
|
+
/** Save now when anything changed; resolves when that save settles. */
|
|
48
|
+
flush(): Promise<void>;
|
|
49
|
+
/** After a failure, try again now (online); else nothing. */
|
|
50
|
+
retry(): Promise<void>;
|
|
51
|
+
state(): SaveStateName;
|
|
52
|
+
/** Every timer stops. */
|
|
53
|
+
destroy(): void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type SaveState = SaveScheduler;
|
|
57
|
+
|
|
58
|
+
/** The timing with no DOM: onChange on each change of state. */
|
|
59
|
+
export declare function saveScheduler(opts: {
|
|
60
|
+
save: () => Promise<unknown>;
|
|
61
|
+
onChange?: (change: SaveStateChange) => void;
|
|
62
|
+
}): SaveScheduler;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* The save-state line in `el`: <p class="den-savestate" data-state
|
|
66
|
+
* role="status" aria-live="off">, with a polite live region beside it for
|
|
67
|
+
* the error and its recovery. destroy() also removes its listeners and the
|
|
68
|
+
* live region.
|
|
69
|
+
*/
|
|
70
|
+
export declare function createSaveState(
|
|
71
|
+
el: HTMLElement,
|
|
72
|
+
opts: SaveStateOptions,
|
|
73
|
+
): SaveState;
|
package/src/savestate.js
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The save-state line: what an autosaving editor says about its text.
|
|
3
|
+
* Framework-free, and blind to the editor: any input, textarea or editor
|
|
4
|
+
* that tells it "changed" works. The host gives the save and what Copy
|
|
5
|
+
* text copies:
|
|
6
|
+
*
|
|
7
|
+
* const line = createSaveState(el, {
|
|
8
|
+
* save: () => Promise<void>, the host's save (rejects on failure)
|
|
9
|
+
* copyText: () => string, error's Copy text: the title and body,
|
|
10
|
+
* say (none: no Copy text)
|
|
11
|
+
* watch: field, optional: its `input` is changed(), its
|
|
12
|
+
* `focusout` (blur) is flush()
|
|
13
|
+
* lang: "en" | () => "en", default: <html lang>
|
|
14
|
+
* words: { saving, saved, error, copy, savedAt }, optional overrides
|
|
15
|
+
* of the kit's words (strings.js)
|
|
16
|
+
* css: "/kit/savestate.css", where savestate.css is, for a page that
|
|
17
|
+
* doesn't link it (default: beside another
|
|
18
|
+
* kit stylesheet on the page)
|
|
19
|
+
* })
|
|
20
|
+
* line.changed() the text changed: a save SAVE_AFTER_MS after the last
|
|
21
|
+
* line.flush() save now, when anything changed (→ Promise)
|
|
22
|
+
* line.retry() after a failure, try again now (→ Promise)
|
|
23
|
+
* line.state() "idle" | "saving" | "saved" | "error"
|
|
24
|
+
* line.destroy() timers and listeners off; the live region removed
|
|
25
|
+
*
|
|
26
|
+
* The element becomes <p class="den-savestate" data-state="…"
|
|
27
|
+
* role="status" aria-live="off">: a dot, then the words. aria-live="off"
|
|
28
|
+
* keeps the routine "Saved" quiet; a separate, visually hidden polite
|
|
29
|
+
* region beside it says only the error and its recovery.
|
|
30
|
+
*
|
|
31
|
+
* idle nothing (the line keeps its height)
|
|
32
|
+
* saving "Saving…", only when a save takes more than SAVING_AFTER_MS
|
|
33
|
+
* saved "Saved", title "Saved at {time}"; stays until the next save
|
|
34
|
+
* error "Not saved. Retrying…" and Copy text; retries at RETRY_MS,
|
|
35
|
+
* then every RETRY_EVERY_MS, and at once when the browser is
|
|
36
|
+
* back online; a success is "saved" again
|
|
37
|
+
*
|
|
38
|
+
* A page going hidden (visibilitychange) saves at once.
|
|
39
|
+
*
|
|
40
|
+
* saveScheduler({ save, onChange }) is the same timing with no DOM (a
|
|
41
|
+
* server, a test, a host's own view): onChange({ state, at?, announce? })
|
|
42
|
+
* on each change of state; announce is "error" or "recovered", else null.
|
|
43
|
+
*
|
|
44
|
+
* Its look is savestate.css (linked from beside this file).
|
|
45
|
+
*/
|
|
46
|
+
import { kitT } from "./strings.js";
|
|
47
|
+
import { formatTime } from "./time.js";
|
|
48
|
+
|
|
49
|
+
export const SAVE_AFTER_MS = 800;
|
|
50
|
+
export const SAVING_AFTER_MS = 400;
|
|
51
|
+
export const RETRY_MS = [2000, 4000, 8000];
|
|
52
|
+
export const RETRY_EVERY_MS = 30_000;
|
|
53
|
+
|
|
54
|
+
/** The timing of saves and their states, with no DOM. */
|
|
55
|
+
export function saveScheduler({ save, onChange }) {
|
|
56
|
+
let state = "idle";
|
|
57
|
+
let dirty = false;
|
|
58
|
+
let failing = false;
|
|
59
|
+
let again = false;
|
|
60
|
+
let step = 0;
|
|
61
|
+
let dead = false;
|
|
62
|
+
let debounce = 0;
|
|
63
|
+
let retryTimer = 0;
|
|
64
|
+
let running = null;
|
|
65
|
+
|
|
66
|
+
const set = (s, extra) => {
|
|
67
|
+
if (dead) return;
|
|
68
|
+
state = s;
|
|
69
|
+
onChange?.({ state: s, announce: null, ...extra });
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
function run() {
|
|
73
|
+
if (dead) return Promise.resolve();
|
|
74
|
+
// A save is out: save again as soon as it ends.
|
|
75
|
+
if (running) {
|
|
76
|
+
again = true;
|
|
77
|
+
return running;
|
|
78
|
+
}
|
|
79
|
+
clearTimeout(retryTimer);
|
|
80
|
+
retryTimer = 0;
|
|
81
|
+
dirty = false;
|
|
82
|
+
// While in error the line keeps saying "Retrying…".
|
|
83
|
+
const show = failing ? 0 : setTimeout(() => set("saving"), SAVING_AFTER_MS);
|
|
84
|
+
running = (async () => {
|
|
85
|
+
let ok = true;
|
|
86
|
+
try {
|
|
87
|
+
await save();
|
|
88
|
+
} catch {
|
|
89
|
+
ok = false;
|
|
90
|
+
}
|
|
91
|
+
clearTimeout(show);
|
|
92
|
+
running = null;
|
|
93
|
+
if (dead) return;
|
|
94
|
+
if (ok) {
|
|
95
|
+
const recovered = failing;
|
|
96
|
+
failing = false;
|
|
97
|
+
step = 0;
|
|
98
|
+
set("saved", {
|
|
99
|
+
at: new Date(),
|
|
100
|
+
announce: recovered ? "recovered" : null,
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
dirty = true;
|
|
104
|
+
if (!failing) {
|
|
105
|
+
failing = true;
|
|
106
|
+
set("error", { announce: "error" });
|
|
107
|
+
}
|
|
108
|
+
const wait = RETRY_MS[step] ?? RETRY_EVERY_MS;
|
|
109
|
+
step++;
|
|
110
|
+
retryTimer = setTimeout(() => {
|
|
111
|
+
retryTimer = 0;
|
|
112
|
+
void run();
|
|
113
|
+
}, wait);
|
|
114
|
+
}
|
|
115
|
+
if (again) {
|
|
116
|
+
again = false;
|
|
117
|
+
if (dirty && !failing) return run();
|
|
118
|
+
}
|
|
119
|
+
})();
|
|
120
|
+
return running;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
changed() {
|
|
125
|
+
if (dead) return;
|
|
126
|
+
dirty = true;
|
|
127
|
+
clearTimeout(debounce);
|
|
128
|
+
debounce = setTimeout(() => {
|
|
129
|
+
debounce = 0;
|
|
130
|
+
void run();
|
|
131
|
+
}, SAVE_AFTER_MS);
|
|
132
|
+
},
|
|
133
|
+
flush() {
|
|
134
|
+
clearTimeout(debounce);
|
|
135
|
+
debounce = 0;
|
|
136
|
+
if (dead || !dirty) return running ?? Promise.resolve();
|
|
137
|
+
return run();
|
|
138
|
+
},
|
|
139
|
+
retry() {
|
|
140
|
+
if (dead || !failing) return running ?? Promise.resolve();
|
|
141
|
+
return run();
|
|
142
|
+
},
|
|
143
|
+
state: () => state,
|
|
144
|
+
destroy() {
|
|
145
|
+
dead = true;
|
|
146
|
+
clearTimeout(debounce);
|
|
147
|
+
clearTimeout(retryTimer);
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* The look is savestate.css: linked, never injected, so a page under
|
|
154
|
+
* style-src 'self' takes it. A page that links it (in its <head>) keeps
|
|
155
|
+
* its own link. Else it is linked from opts.css, or from the folder of
|
|
156
|
+
* another kit stylesheet on the page (tokens.css, say), as dialog.js does.
|
|
157
|
+
*/
|
|
158
|
+
const KIT_SHEET =
|
|
159
|
+
/(^|\/)(tokens|base|fonts|busy|dialog|shell|update-pill)\.css$/;
|
|
160
|
+
function ensureCss(css) {
|
|
161
|
+
if (document.getElementById("ss-css")) return;
|
|
162
|
+
let near = null;
|
|
163
|
+
for (const l of document.querySelectorAll('link[rel="stylesheet"]')) {
|
|
164
|
+
const u = new URL(l.href, location.href);
|
|
165
|
+
if (/(^|\/)savestate\.css$/.test(u.pathname)) return;
|
|
166
|
+
if (!near && KIT_SHEET.test(u.pathname)) near = u;
|
|
167
|
+
}
|
|
168
|
+
const href =
|
|
169
|
+
css ||
|
|
170
|
+
(near ? new URL("savestate.css", near).href.replace(/\?.*$/, "") : null);
|
|
171
|
+
if (!href) return;
|
|
172
|
+
const l = document.createElement("link");
|
|
173
|
+
l.id = "ss-css";
|
|
174
|
+
l.rel = "stylesheet";
|
|
175
|
+
l.href = href;
|
|
176
|
+
document.head.append(l);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Plain text to the clipboard. Kept here rather than imported from
|
|
181
|
+
* whatsnew.js, which brings the shell's modules with it. The fallback
|
|
182
|
+
* never focuses its textarea: focus stays on Copy text.
|
|
183
|
+
*/
|
|
184
|
+
function copy(text) {
|
|
185
|
+
if (navigator.clipboard?.writeText)
|
|
186
|
+
return navigator.clipboard.writeText(text);
|
|
187
|
+
return new Promise((resolve, reject) => {
|
|
188
|
+
const ta = document.createElement("textarea");
|
|
189
|
+
ta.value = text;
|
|
190
|
+
ta.className = "den-savestate-sr";
|
|
191
|
+
ta.setAttribute("aria-hidden", "true");
|
|
192
|
+
document.body.append(ta);
|
|
193
|
+
ta.select();
|
|
194
|
+
try {
|
|
195
|
+
document.execCommand("copy") ? resolve() : reject(new Error("copy"));
|
|
196
|
+
} catch (e) {
|
|
197
|
+
reject(e);
|
|
198
|
+
} finally {
|
|
199
|
+
ta.remove();
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** The save-state line in `el` (see the top of this file). */
|
|
205
|
+
export function createSaveState(el, opts = {}) {
|
|
206
|
+
const { save, copyText, watch, words = {} } = opts;
|
|
207
|
+
const lang = () => {
|
|
208
|
+
const l = typeof opts.lang === "function" ? opts.lang() : opts.lang;
|
|
209
|
+
return l || document.documentElement.lang?.slice(0, 2) || "en";
|
|
210
|
+
};
|
|
211
|
+
const word = (key, vars) =>
|
|
212
|
+
words[key] != null
|
|
213
|
+
? String(words[key]).replace(/\{(\w+)\}/g, (m, k) => vars?.[k] ?? m)
|
|
214
|
+
: kitT(lang(), `kit.savestate.${key}`, vars);
|
|
215
|
+
|
|
216
|
+
ensureCss(opts.css);
|
|
217
|
+
el.classList.add("den-savestate");
|
|
218
|
+
el.setAttribute("role", "status");
|
|
219
|
+
el.setAttribute("aria-live", "off");
|
|
220
|
+
el.dataset.state = "idle";
|
|
221
|
+
const text = document.createElement("span");
|
|
222
|
+
text.className = "den-savestate-text";
|
|
223
|
+
el.replaceChildren(text);
|
|
224
|
+
const live = document.createElement("span");
|
|
225
|
+
live.className = "den-savestate-sr";
|
|
226
|
+
live.setAttribute("aria-live", "polite");
|
|
227
|
+
el.after(live);
|
|
228
|
+
let btn = null;
|
|
229
|
+
|
|
230
|
+
// The error and the recovery alternate, so each is new words to say.
|
|
231
|
+
const say = (s) => {
|
|
232
|
+
live.textContent = s;
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
function paint({ state, at, announce }) {
|
|
236
|
+
el.dataset.state = state;
|
|
237
|
+
text.textContent =
|
|
238
|
+
state === "saving"
|
|
239
|
+
? word("saving")
|
|
240
|
+
: state === "saved"
|
|
241
|
+
? word("saved")
|
|
242
|
+
: state === "error"
|
|
243
|
+
? word("error")
|
|
244
|
+
: "";
|
|
245
|
+
const savedAt =
|
|
246
|
+
state === "saved"
|
|
247
|
+
? word("savedAt", { time: formatTime(at, { style: "time" }) })
|
|
248
|
+
: "";
|
|
249
|
+
if (savedAt) el.title = savedAt;
|
|
250
|
+
else el.removeAttribute("title");
|
|
251
|
+
if (state === "error" && copyText && !btn) {
|
|
252
|
+
btn = document.createElement("button");
|
|
253
|
+
btn.type = "button";
|
|
254
|
+
btn.className = "den-savestate-copy";
|
|
255
|
+
btn.textContent = word("copy");
|
|
256
|
+
btn.addEventListener("click", () => {
|
|
257
|
+
void copy(String(copyText() ?? "")).catch(() => {});
|
|
258
|
+
});
|
|
259
|
+
el.append(btn);
|
|
260
|
+
} else if (state !== "error" && btn) {
|
|
261
|
+
btn.remove();
|
|
262
|
+
btn = null;
|
|
263
|
+
}
|
|
264
|
+
if (announce === "error") say(word("error"));
|
|
265
|
+
else if (announce === "recovered") say(savedAt);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const sch = saveScheduler({ save, onChange: paint });
|
|
269
|
+
const onInput = () => sch.changed();
|
|
270
|
+
const onBlur = () => void sch.flush();
|
|
271
|
+
const onHidden = () => {
|
|
272
|
+
if (document.visibilityState === "hidden") void sch.flush();
|
|
273
|
+
};
|
|
274
|
+
const onOnline = () => void sch.retry();
|
|
275
|
+
watch?.addEventListener("input", onInput);
|
|
276
|
+
watch?.addEventListener("focusout", onBlur);
|
|
277
|
+
document.addEventListener("visibilitychange", onHidden);
|
|
278
|
+
window.addEventListener("online", onOnline);
|
|
279
|
+
|
|
280
|
+
return {
|
|
281
|
+
changed: sch.changed,
|
|
282
|
+
flush: sch.flush,
|
|
283
|
+
retry: sch.retry,
|
|
284
|
+
state: sch.state,
|
|
285
|
+
destroy() {
|
|
286
|
+
sch.destroy();
|
|
287
|
+
watch?.removeEventListener("input", onInput);
|
|
288
|
+
watch?.removeEventListener("focusout", onBlur);
|
|
289
|
+
document.removeEventListener("visibilitychange", onHidden);
|
|
290
|
+
window.removeEventListener("online", onOnline);
|
|
291
|
+
live.remove();
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
}
|
package/src/shell-html.d.ts
CHANGED
|
@@ -231,6 +231,11 @@ export interface BellPanelOptions {
|
|
|
231
231
|
items?: BellItem[];
|
|
232
232
|
/** The host's own HTML in place of rows. */
|
|
233
233
|
body?: string | null;
|
|
234
|
+
/**
|
|
235
|
+
* Issue 101: the rows of the panel's two sections, in place of rows:
|
|
236
|
+
* the kit heads them "Needs you" (always first) and "Earlier".
|
|
237
|
+
*/
|
|
238
|
+
sections?: { needs: string; earlier?: string };
|
|
234
239
|
/** The empty state: its words, and HTML under them. */
|
|
235
240
|
empty?: { text?: string; more?: string };
|
|
236
241
|
after?: string;
|
package/src/shell-html.js
CHANGED
|
@@ -784,6 +784,10 @@ function bellRowHtml(it) {
|
|
|
784
784
|
* `actions`: buttons beside the heading (Mark all read); `lead`: HTML
|
|
785
785
|
* under the heading; `after`: HTML after the rows; `foot`: the footer (a
|
|
786
786
|
* Report button). Every HTML part is the host's own.
|
|
787
|
+
* Issue 101: `sections` { needs, earlier? } in place of rows: the kit
|
|
788
|
+
* heads them "Needs you" (first, always; its own line when `needs` is
|
|
789
|
+
* empty) and "Earlier" (when given), in its words; the host gives only
|
|
790
|
+
* each section's rows.
|
|
787
791
|
*/
|
|
788
792
|
export function bellPanelHtml({
|
|
789
793
|
title,
|
|
@@ -792,6 +796,7 @@ export function bellPanelHtml({
|
|
|
792
796
|
lead,
|
|
793
797
|
items,
|
|
794
798
|
body,
|
|
799
|
+
sections,
|
|
795
800
|
empty,
|
|
796
801
|
after,
|
|
797
802
|
foot,
|
|
@@ -799,8 +804,9 @@ export function bellPanelHtml({
|
|
|
799
804
|
} = {}) {
|
|
800
805
|
const list = Array.isArray(items) ? items : [];
|
|
801
806
|
const e = empty || {};
|
|
802
|
-
const rows =
|
|
803
|
-
|
|
807
|
+
const rows = sections
|
|
808
|
+
? bellSectionsHtml(sections, lang)
|
|
809
|
+
: body != null && body !== ""
|
|
804
810
|
? body
|
|
805
811
|
: list.length
|
|
806
812
|
? list.map(bellRowHtml).join("")
|
|
@@ -824,6 +830,41 @@ export function bellPanelHtml({
|
|
|
824
830
|
);
|
|
825
831
|
}
|
|
826
832
|
|
|
833
|
+
/** Issue 101: one titled section of the bell's panel. */
|
|
834
|
+
function bellSectionHtml(id, word, rows) {
|
|
835
|
+
return (
|
|
836
|
+
'<section class="den-bell-sec" data-sec="' +
|
|
837
|
+
id +
|
|
838
|
+
'" aria-labelledby="den-bell-' +
|
|
839
|
+
id +
|
|
840
|
+
'"><h3 class="den-bell-sech" id="den-bell-' +
|
|
841
|
+
id +
|
|
842
|
+
'">' +
|
|
843
|
+
esc(word) +
|
|
844
|
+
"</h3>" +
|
|
845
|
+
rows +
|
|
846
|
+
"</section>"
|
|
847
|
+
);
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
/** Issue 101: Needs you, then Earlier (the host's rows in each). */
|
|
851
|
+
function bellSectionsHtml(s, lang) {
|
|
852
|
+
const needs = s.needs || "";
|
|
853
|
+
return (
|
|
854
|
+
bellSectionHtml(
|
|
855
|
+
"needs",
|
|
856
|
+
kitT(lang, "kit.bell.needs"),
|
|
857
|
+
needs ||
|
|
858
|
+
'<p class="den-bell-none">' +
|
|
859
|
+
esc(kitT(lang, "kit.bell.needsNone")) +
|
|
860
|
+
"</p>",
|
|
861
|
+
) +
|
|
862
|
+
(s.earlier
|
|
863
|
+
? bellSectionHtml("earlier", kitT(lang, "kit.bell.earlier"), s.earlier)
|
|
864
|
+
: "")
|
|
865
|
+
);
|
|
866
|
+
}
|
|
867
|
+
|
|
827
868
|
/**
|
|
828
869
|
* The account entry, in the rail's foot: who is signed in, here.
|
|
829
870
|
* accountHtml({ label, detail?, href?, action?, icon?, id?, navId?,
|
package/src/shell.css
CHANGED
|
@@ -1009,6 +1009,22 @@ body.den-has-shell .den-upd {
|
|
|
1009
1009
|
font-size: 11px;
|
|
1010
1010
|
white-space: nowrap;
|
|
1011
1011
|
}
|
|
1012
|
+
/* Issue 101: Needs you, then Earlier, each under a quiet heading. */
|
|
1013
|
+
.den-bell-sec + .den-bell-sec {
|
|
1014
|
+
border-top: 1px solid var(--border);
|
|
1015
|
+
}
|
|
1016
|
+
.den-bell-sech {
|
|
1017
|
+
margin: 0;
|
|
1018
|
+
padding: 10px 12px 2px;
|
|
1019
|
+
font-size: 12px;
|
|
1020
|
+
font-weight: 600;
|
|
1021
|
+
color: var(--muted);
|
|
1022
|
+
}
|
|
1023
|
+
.den-bell-none {
|
|
1024
|
+
margin: 0;
|
|
1025
|
+
padding: 6px 12px 10px;
|
|
1026
|
+
color: var(--muted);
|
|
1027
|
+
}
|
|
1012
1028
|
.den-bell-empty {
|
|
1013
1029
|
padding: 16px 12px;
|
|
1014
1030
|
color: var(--muted);
|