@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,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
|
+
}
|
|
@@ -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;
|