@monster-orange/den-ui 0.5.1 → 0.7.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 +515 -1
- package/bin/den-ui-parity.mjs +440 -0
- package/inventory/fonts-dir.cjs +8 -0
- package/inventory/fonts-dir.mjs +10 -0
- package/inventory/nav-inventory.d.ts +133 -0
- package/inventory/nav-inventory.js +839 -0
- package/inventory/reference/den-chromium-1280.json +5388 -0
- package/inventory/reference/den-chromium-390.json +3834 -0
- package/inventory/reference/den-webkit-1280.json +5388 -0
- package/inventory/reference/den-webkit-390.json +3834 -0
- package/package.json +40 -3
- package/src/busy-words.d.ts +2 -0
- package/src/busy-words.js +6 -0
- package/src/busy.css +155 -0
- package/src/busy.d.ts +80 -0
- package/src/busy.js +105 -35
- package/src/dialog.css +103 -0
- package/src/dialog.d.ts +44 -0
- package/src/dialog.js +95 -30
- package/src/icons.d.ts +4 -0
- package/src/icons.js +43 -0
- package/src/kit.d.ts +217 -0
- package/src/kit.js +299 -0
- package/src/marks/den.svg +6 -0
- package/src/report-shot.d.ts +47 -0
- package/src/report-shot.js +437 -0
- package/src/report.css +387 -0
- package/src/report.d.ts +61 -0
- package/src/report.js +909 -0
- package/src/shell-client.d.ts +149 -0
- package/src/shell-client.js +820 -0
- package/src/shell-html.d.ts +305 -0
- package/src/shell-html.js +903 -0
- package/src/shell.css +1010 -0
- package/src/strings.d.ts +18 -0
- package/src/strings.js +565 -0
- package/src/time.d.ts +18 -0
- package/src/time.js +14 -2
- package/src/tokens.css +81 -67
- package/src/update-pill.d.ts +17 -0
- package/src/version.d.ts +7 -0
- package/src/version.js +31 -0
- package/src/whatsnew.css +235 -0
- package/src/whatsnew.d.ts +36 -0
- package/src/whatsnew.js +411 -0
package/package.json
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monster-orange/den-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Den's UI kit: tokens, fonts and shared components, framework-free",
|
|
5
5
|
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/Monster-Orange/den.git",
|
|
9
|
+
"directory": "packages/den-ui"
|
|
10
|
+
},
|
|
6
11
|
"type": "module",
|
|
12
|
+
"types": "./src/kit.d.ts",
|
|
7
13
|
"exports": {
|
|
8
14
|
"./tokens.css": "./src/tokens.css",
|
|
9
15
|
"./fonts.css": "./src/fonts.css",
|
|
@@ -13,11 +19,42 @@
|
|
|
13
19
|
"./update-pill.css": "./src/update-pill.css",
|
|
14
20
|
"./busy": "./src/busy.js",
|
|
15
21
|
"./busy-words": "./src/busy-words.js",
|
|
16
|
-
"./dialog": "./src/dialog.js"
|
|
22
|
+
"./dialog": "./src/dialog.js",
|
|
23
|
+
"./strings": "./src/strings.js",
|
|
24
|
+
"./icons": "./src/icons.js",
|
|
25
|
+
"./shell-html": "./src/shell-html.js",
|
|
26
|
+
"./shell-client": "./src/shell-client.js",
|
|
27
|
+
"./version": "./src/version.js",
|
|
28
|
+
"./whatsnew": "./src/whatsnew.js",
|
|
29
|
+
"./report": "./src/report.js",
|
|
30
|
+
"./report-shot": "./src/report-shot.js",
|
|
31
|
+
"./kit": "./src/kit.js",
|
|
32
|
+
"./shell.css": "./src/shell.css",
|
|
33
|
+
"./whatsnew.css": "./src/whatsnew.css",
|
|
34
|
+
"./report.css": "./src/report.css",
|
|
35
|
+
"./busy.css": "./src/busy.css",
|
|
36
|
+
"./dialog.css": "./src/dialog.css",
|
|
37
|
+
"./inventory": {
|
|
38
|
+
"types": "./inventory/nav-inventory.d.ts",
|
|
39
|
+
"default": "./inventory/nav-inventory.js"
|
|
40
|
+
},
|
|
41
|
+
"./inventory/reference/*": "./inventory/reference/*"
|
|
42
|
+
},
|
|
43
|
+
"imports": {
|
|
44
|
+
"#den-ui-fonts-dir": {
|
|
45
|
+
"import": "./inventory/fonts-dir.mjs",
|
|
46
|
+
"require": "./inventory/fonts-dir.cjs",
|
|
47
|
+
"default": "./inventory/fonts-dir.mjs"
|
|
48
|
+
}
|
|
17
49
|
},
|
|
18
50
|
"files": [
|
|
19
51
|
"src/",
|
|
52
|
+
"inventory/",
|
|
53
|
+
"bin/",
|
|
20
54
|
"LICENSE",
|
|
21
55
|
"README.md"
|
|
22
|
-
]
|
|
56
|
+
],
|
|
57
|
+
"bin": {
|
|
58
|
+
"den-ui-parity": "bin/den-ui-parity.mjs"
|
|
59
|
+
}
|
|
23
60
|
}
|
package/src/busy-words.js
CHANGED
|
@@ -22,6 +22,8 @@ export const BUSY_WORDS = {
|
|
|
22
22
|
"{who} has no record of this request any more. Check the page before you try again.",
|
|
23
23
|
err_code: "{who} answered with an error ({code}).",
|
|
24
24
|
network: "Couldn't reach {who}.",
|
|
25
|
+
next: "Trying again won't help. Do this first:",
|
|
26
|
+
progress: "Progress",
|
|
25
27
|
},
|
|
26
28
|
es: {
|
|
27
29
|
wait: "Esperando a {who}…",
|
|
@@ -41,6 +43,8 @@ export const BUSY_WORDS = {
|
|
|
41
43
|
"{who} ya no tiene registro de esta solicitud. Revisa la página antes de intentarlo de nuevo.",
|
|
42
44
|
err_code: "{who} respondió con un error ({code}).",
|
|
43
45
|
network: "No se pudo contactar con {who}.",
|
|
46
|
+
next: "Intentar de nuevo no servirá. Haz esto primero:",
|
|
47
|
+
progress: "Progreso",
|
|
44
48
|
},
|
|
45
49
|
ja: {
|
|
46
50
|
wait: "{who} の応答を待っています…",
|
|
@@ -61,5 +65,7 @@ export const BUSY_WORDS = {
|
|
|
61
65
|
"{who} にこのリクエストの記録がもうありません。もう一度試す前にページを確認してください。",
|
|
62
66
|
err_code: "{who} がエラーを返しました({code})。",
|
|
63
67
|
network: "{who} に接続できませんでした。",
|
|
68
|
+
next: "もう一度試しても解決しません。先にこちらを:",
|
|
69
|
+
progress: "進行状況",
|
|
64
70
|
},
|
|
65
71
|
};
|
package/src/busy.css
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/* den-ui: the working pop-up's look (busy.js). Tokens only (UK-1): no
|
|
2
|
+
colour of its own. Linked, never injected: clean under style-src 'self'. */
|
|
3
|
+
.bz-dlg {
|
|
4
|
+
font-family: var(--sans);
|
|
5
|
+
position: fixed;
|
|
6
|
+
inset-block: auto;
|
|
7
|
+
inset-inline: 0;
|
|
8
|
+
top: 50%;
|
|
9
|
+
transform: translateY(-50%);
|
|
10
|
+
margin: 0 auto;
|
|
11
|
+
height: auto;
|
|
12
|
+
max-height: calc(100vh - 32px);
|
|
13
|
+
max-height: calc(100dvh - 32px);
|
|
14
|
+
overflow: auto;
|
|
15
|
+
width: min(420px, calc(100vw - 32px));
|
|
16
|
+
max-width: 100%;
|
|
17
|
+
padding: 0;
|
|
18
|
+
border: 1px solid var(--border-strong);
|
|
19
|
+
border-radius: var(--radius);
|
|
20
|
+
background: var(--surface);
|
|
21
|
+
color: var(--text);
|
|
22
|
+
box-shadow: var(--shadow-dialog);
|
|
23
|
+
}
|
|
24
|
+
.bz-dlg::backdrop {
|
|
25
|
+
background: color-mix(in srgb, var(--sunken) 70%, transparent);
|
|
26
|
+
}
|
|
27
|
+
.bz-b {
|
|
28
|
+
padding: var(--space-4) calc(var(--space-4) + 2px);
|
|
29
|
+
display: grid;
|
|
30
|
+
gap: 10px;
|
|
31
|
+
}
|
|
32
|
+
.bz-b h2 {
|
|
33
|
+
font-size: var(--fs-l);
|
|
34
|
+
margin: 0;
|
|
35
|
+
outline: none;
|
|
36
|
+
display: flex;
|
|
37
|
+
gap: var(--space-2);
|
|
38
|
+
align-items: center;
|
|
39
|
+
}
|
|
40
|
+
.bz-b p {
|
|
41
|
+
margin: 0;
|
|
42
|
+
font-size: var(--fs-s);
|
|
43
|
+
line-height: 1.5;
|
|
44
|
+
}
|
|
45
|
+
.bz-ico {
|
|
46
|
+
width: 18px;
|
|
47
|
+
height: 18px;
|
|
48
|
+
flex: none;
|
|
49
|
+
}
|
|
50
|
+
.bz-ok {
|
|
51
|
+
color: var(--ok);
|
|
52
|
+
}
|
|
53
|
+
.bz-bad {
|
|
54
|
+
color: var(--bad);
|
|
55
|
+
}
|
|
56
|
+
.bz-dlg[data-state="noanswer"] .bz-clock {
|
|
57
|
+
color: var(--warn);
|
|
58
|
+
}
|
|
59
|
+
.bz-bar {
|
|
60
|
+
height: 2px;
|
|
61
|
+
background: color-mix(in srgb, var(--accent) 22%, transparent);
|
|
62
|
+
position: relative;
|
|
63
|
+
overflow: hidden;
|
|
64
|
+
border-radius: 2px;
|
|
65
|
+
}
|
|
66
|
+
.bz-bar i {
|
|
67
|
+
position: absolute;
|
|
68
|
+
inset: 0 auto 0 0;
|
|
69
|
+
width: 35%;
|
|
70
|
+
background: var(--accent);
|
|
71
|
+
animation: bz-ind 1.4s ease-in-out infinite;
|
|
72
|
+
}
|
|
73
|
+
@keyframes bz-ind {
|
|
74
|
+
0% {
|
|
75
|
+
transform: translateX(-100%);
|
|
76
|
+
}
|
|
77
|
+
100% {
|
|
78
|
+
transform: translateX(300%);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
@media (prefers-reduced-motion: reduce) {
|
|
82
|
+
.bz-bar i {
|
|
83
|
+
animation: none;
|
|
84
|
+
width: 100%;
|
|
85
|
+
opacity: 0.7;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
.bz-b details {
|
|
89
|
+
font-size: var(--fs-xs);
|
|
90
|
+
color: var(--muted);
|
|
91
|
+
}
|
|
92
|
+
.bz-b pre {
|
|
93
|
+
margin: 6px 0 0;
|
|
94
|
+
font: 11.5px/1.5 var(--mono);
|
|
95
|
+
background: var(--sunken);
|
|
96
|
+
padding: var(--space-2);
|
|
97
|
+
border-radius: var(--radius-button);
|
|
98
|
+
white-space: pre-wrap;
|
|
99
|
+
overflow-wrap: anywhere;
|
|
100
|
+
}
|
|
101
|
+
.bz-ft {
|
|
102
|
+
display: flex;
|
|
103
|
+
flex-wrap: wrap;
|
|
104
|
+
gap: var(--space-2);
|
|
105
|
+
justify-content: flex-end;
|
|
106
|
+
align-items: center;
|
|
107
|
+
}
|
|
108
|
+
.bz-btn {
|
|
109
|
+
font: inherit;
|
|
110
|
+
font-size: var(--fs-s);
|
|
111
|
+
min-height: var(--tap-min);
|
|
112
|
+
padding: 0 var(--space-3);
|
|
113
|
+
border-radius: var(--radius-button);
|
|
114
|
+
border: 1px solid var(--border-strong);
|
|
115
|
+
background: var(--surface);
|
|
116
|
+
color: var(--text);
|
|
117
|
+
cursor: pointer;
|
|
118
|
+
}
|
|
119
|
+
.bz-btn:focus-visible {
|
|
120
|
+
outline: 2px solid var(--accent);
|
|
121
|
+
outline-offset: 2px;
|
|
122
|
+
}
|
|
123
|
+
.bz-btn.bz-primary {
|
|
124
|
+
background: var(--accent-fill);
|
|
125
|
+
border-color: var(--accent-fill);
|
|
126
|
+
color: var(--on-accent);
|
|
127
|
+
}
|
|
128
|
+
@media (max-width: 480px) {
|
|
129
|
+
.bz-btn {
|
|
130
|
+
min-height: var(--tap);
|
|
131
|
+
}
|
|
132
|
+
.bz-ft .bz-primary {
|
|
133
|
+
flex-basis: 100%;
|
|
134
|
+
order: 9;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
.bz-prog {
|
|
138
|
+
margin: 0;
|
|
139
|
+
padding-inline-start: 1.25em;
|
|
140
|
+
font-size: var(--fs-s);
|
|
141
|
+
line-height: 1.5;
|
|
142
|
+
color: var(--muted);
|
|
143
|
+
}
|
|
144
|
+
.bz-prog li:last-child {
|
|
145
|
+
color: var(--text);
|
|
146
|
+
}
|
|
147
|
+
.bz-next {
|
|
148
|
+
font-weight: 500;
|
|
149
|
+
}
|
|
150
|
+
a.bz-btn {
|
|
151
|
+
display: inline-flex;
|
|
152
|
+
align-items: center;
|
|
153
|
+
text-decoration: none;
|
|
154
|
+
box-sizing: border-box;
|
|
155
|
+
}
|
package/src/busy.d.ts
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
export declare const OPEN_MS: number;
|
|
2
|
+
export declare const MIN_MS: number;
|
|
3
|
+
export declare const STILL_MS: number;
|
|
4
|
+
export declare const NO_ANSWER_MS: number;
|
|
5
|
+
export declare const SUCCESS_CLOSE_MS: number;
|
|
6
|
+
export declare const POLL_MS: number;
|
|
7
|
+
export declare const POLL_MAX_MS: number;
|
|
8
|
+
|
|
9
|
+
export type Words = Record<string, Record<string, string>>;
|
|
10
|
+
/** Check again's answer: how a request id ended. */
|
|
11
|
+
export interface RequestState {
|
|
12
|
+
state: "done" | "failed" | "running" | "unknown";
|
|
13
|
+
result?: unknown;
|
|
14
|
+
error?: { code?: number; message?: string };
|
|
15
|
+
}
|
|
16
|
+
export interface BusyHooks {
|
|
17
|
+
lang?: () => string;
|
|
18
|
+
words?: Words;
|
|
19
|
+
idHeader?: string;
|
|
20
|
+
statusUrl?: (id: string) => string;
|
|
21
|
+
/** Check again through the product's adapter (statusUrl is then unused). */
|
|
22
|
+
request?: (id: string) => Promise<RequestState | null>;
|
|
23
|
+
report?:
|
|
24
|
+
| ((info: { title: string; details: string; requestId: string }) => void)
|
|
25
|
+
| null;
|
|
26
|
+
toast?: ((text: string) => void) | null;
|
|
27
|
+
open?: (url: string) => void;
|
|
28
|
+
logUrl?: string | null;
|
|
29
|
+
reconnect?: {
|
|
30
|
+
url: string;
|
|
31
|
+
back: (now: unknown, before: unknown) => boolean;
|
|
32
|
+
waitMs?: (before: unknown) => number;
|
|
33
|
+
version?: (now: unknown) => string;
|
|
34
|
+
done?: (now: unknown) => void;
|
|
35
|
+
} | null;
|
|
36
|
+
}
|
|
37
|
+
export interface BusyActionDef {
|
|
38
|
+
who?: string;
|
|
39
|
+
autoClose?: boolean;
|
|
40
|
+
inline?: boolean;
|
|
41
|
+
mode?: "reconnect";
|
|
42
|
+
words: Words;
|
|
43
|
+
}
|
|
44
|
+
export interface BusyOptions<T = unknown> {
|
|
45
|
+
button?: HTMLElement | null;
|
|
46
|
+
vars?: Record<string, string | number>;
|
|
47
|
+
success?: (data: T) => string;
|
|
48
|
+
onDone?: (data: T) => void;
|
|
49
|
+
onFail?: (err: unknown) => void;
|
|
50
|
+
toastFast?: boolean;
|
|
51
|
+
quietFail?: boolean;
|
|
52
|
+
inlineError?: boolean;
|
|
53
|
+
skipDone?: (data: T) => boolean;
|
|
54
|
+
extra?: (data: T) => Node | null | undefined;
|
|
55
|
+
before?: unknown;
|
|
56
|
+
/**
|
|
57
|
+
* A failure trying again won't fix: its link (the primary) in place of
|
|
58
|
+
* Try again; or, from the failure, null for Try again as before.
|
|
59
|
+
*/
|
|
60
|
+
next?: NextStep | ((err: unknown) => NextStep | null | undefined) | null;
|
|
61
|
+
}
|
|
62
|
+
export interface NextStep {
|
|
63
|
+
label: string;
|
|
64
|
+
/** None: the words in place of Try again, and Close is the primary. */
|
|
65
|
+
href?: string;
|
|
66
|
+
}
|
|
67
|
+
/** run's second argument: a progress line under the working title. */
|
|
68
|
+
export type Progress = (text: string) => void;
|
|
69
|
+
export declare function configureBusy(h?: BusyHooks): void;
|
|
70
|
+
export declare function registerActions(
|
|
71
|
+
map: Record<string, BusyActionDef>,
|
|
72
|
+
): void;
|
|
73
|
+
export declare function busyActionOf(name: string): BusyActionDef | null;
|
|
74
|
+
/** The first message with words in an error or its answer, else "". */
|
|
75
|
+
export declare function messageOf(err: unknown): string;
|
|
76
|
+
export declare function busyAction<T = unknown>(
|
|
77
|
+
name: string,
|
|
78
|
+
run: (headers: Record<string, string>, progress: Progress) => Promise<T> | T,
|
|
79
|
+
opts?: BusyOptions<T>,
|
|
80
|
+
): Promise<T | null>;
|
package/src/busy.js
CHANGED
|
@@ -11,6 +11,9 @@
|
|
|
11
11
|
* words: { en: {...}, ... }, extra or replaced shared words
|
|
12
12
|
* idHeader: "X-Request-Id", the header the request id rides in
|
|
13
13
|
* statusUrl: (id) => url, Check again's GET (never resends)
|
|
14
|
+
* request: (id) => Promise<state> Check again through the product's
|
|
15
|
+
* adapter instead ({ state, result?,
|
|
16
|
+
* error? }); statusUrl is then unused
|
|
14
17
|
* report: (info) => void, Report: { title, details, requestId }
|
|
15
18
|
* toast: (text) => void, a fast success, said without a pop-up
|
|
16
19
|
* open: (url) => void, a held answer's page (default: go)
|
|
@@ -48,6 +51,18 @@
|
|
|
48
51
|
* opts.extra(res) a node under the success line; waits for Close.
|
|
49
52
|
* opts.before reconnect: the product's answer from before (else
|
|
50
53
|
* the kit asks reconnect.url first).
|
|
54
|
+
* opts.next a failure trying again won't fix: { label, href },
|
|
55
|
+
* or (err) => { label, href } | null. The Failure
|
|
56
|
+
* pop-up then offers that link (the primary) in
|
|
57
|
+
* place of Try again. With no href ({ label }: who
|
|
58
|
+
* to ask, say), it says the words instead and
|
|
59
|
+
* Close is the primary.
|
|
60
|
+
*
|
|
61
|
+
* run(headers, progress) progress(text) adds a line under the working
|
|
62
|
+
* title (in order; the newest is the brightest),
|
|
63
|
+
* shown when the pop-up opens and as it works.
|
|
64
|
+
*
|
|
65
|
+
* Its look is busy.css (linked from beside this file).
|
|
51
66
|
*
|
|
52
67
|
* Reconnect mode: the request may get no answer (the product stopped
|
|
53
68
|
* first); that counts as going down, and the pop-up waits for it to come
|
|
@@ -142,35 +157,23 @@ const ICONS = {
|
|
|
142
157
|
const icon = (k) =>
|
|
143
158
|
`<svg class="bz-ico bz-${k}" viewBox="0 0 24 24" aria-hidden="true">${ICONS[k]}</svg>`;
|
|
144
159
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
.
|
|
151
|
-
.bz-b p{margin:0;font-size:var(--fs-s);line-height:1.5}
|
|
152
|
-
.bz-ico{width:18px;height:18px;flex:none}
|
|
153
|
-
.bz-ok{color:var(--ok)}.bz-bad{color:var(--bad)}
|
|
154
|
-
.bz-dlg[data-state="noanswer"] .bz-clock{color:var(--warn)}
|
|
155
|
-
.bz-bar{height:2px;background:color-mix(in srgb,var(--accent) 22%,transparent);position:relative;overflow:hidden;border-radius:2px}
|
|
156
|
-
.bz-bar i{position:absolute;inset:0 auto 0 0;width:35%;background:var(--accent);animation:bz-ind 1.4s ease-in-out infinite}
|
|
157
|
-
@keyframes bz-ind{0%{transform:translateX(-100%)}100%{transform:translateX(300%)}}
|
|
158
|
-
@media (prefers-reduced-motion: reduce){.bz-bar i{animation:none;width:100%;opacity:.7}}
|
|
159
|
-
.bz-b details{font-size:var(--fs-xs);color:var(--muted)}
|
|
160
|
-
.bz-b pre{margin:6px 0 0;font:11.5px/1.5 var(--mono);background:var(--sunken);padding:var(--space-2);border-radius:var(--radius-button);white-space:pre-wrap;overflow-wrap:anywhere}
|
|
161
|
-
.bz-ft{display:flex;flex-wrap:wrap;gap:var(--space-2);justify-content:flex-end;align-items:center}
|
|
162
|
-
.bz-btn{font:inherit;font-size:var(--fs-s);min-height:var(--tap-min);padding:0 var(--space-3);border-radius:var(--radius-button);border:1px solid var(--border-strong);background:var(--surface);color:var(--text);cursor:pointer}
|
|
163
|
-
.bz-btn:focus-visible{outline:2px solid var(--accent);outline-offset:2px}
|
|
164
|
-
.bz-btn.bz-primary{background:var(--accent-fill);border-color:var(--accent-fill);color:var(--on-accent)}
|
|
165
|
-
@media (max-width:480px){.bz-btn{min-height:var(--tap)}.bz-ft .bz-primary{flex-basis:100%;order:9}}
|
|
166
|
-
`;
|
|
160
|
+
/**
|
|
161
|
+
* The look is busy.css, beside this file: linked once, never injected, so
|
|
162
|
+
* a page under style-src 'self' takes it. A page that links it itself (in
|
|
163
|
+
* its <head>, say) keeps its own link.
|
|
164
|
+
*/
|
|
165
|
+
const CSS_URL = new URL("./busy.css", import.meta.url).href;
|
|
167
166
|
|
|
168
167
|
function ensureCss() {
|
|
169
168
|
if (document.getElementById("bz-css")) return;
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
document.
|
|
169
|
+
for (const l of document.querySelectorAll('link[rel="stylesheet"]'))
|
|
170
|
+
if (/(^|\/)busy\.css(\?|$)/.test(new URL(l.href, location.href).pathname))
|
|
171
|
+
return;
|
|
172
|
+
const l = document.createElement("link");
|
|
173
|
+
l.id = "bz-css";
|
|
174
|
+
l.rel = "stylesheet";
|
|
175
|
+
l.href = CSS_URL;
|
|
176
|
+
document.head.append(l);
|
|
174
177
|
}
|
|
175
178
|
|
|
176
179
|
/** <den-busy>: the pop-up's element, defined on first use (a browser only). */
|
|
@@ -249,6 +252,8 @@ export function busyAction(name, run, opts = {}) {
|
|
|
249
252
|
let lastErr = null;
|
|
250
253
|
let okData = null;
|
|
251
254
|
let lastAt = new Date();
|
|
255
|
+
/** progress(text)'s lines, this attempt. */
|
|
256
|
+
let lines = [];
|
|
252
257
|
let finish;
|
|
253
258
|
let fail;
|
|
254
259
|
const result = new Promise((res, rej) => {
|
|
@@ -300,15 +305,36 @@ export function busyAction(name, run, opts = {}) {
|
|
|
300
305
|
const btn = (key, primary) =>
|
|
301
306
|
`<button type="button" class="bz-btn${primary ? " bz-primary" : ""}" data-bz="${key}">${esc(word(key))}</button>`;
|
|
302
307
|
|
|
303
|
-
/**
|
|
304
|
-
|
|
308
|
+
/**
|
|
309
|
+
* Report · Close · [Open the log] · the primary, last. `next`: the
|
|
310
|
+
* caller's link ({ label, href }) is the primary.
|
|
311
|
+
*/
|
|
312
|
+
const footer = (primary, withLog, next) =>
|
|
305
313
|
`<div class="bz-ft">` +
|
|
306
314
|
(hook.report ? btn("report") : "") +
|
|
307
|
-
|
|
315
|
+
// A next step with no link: its words are in the body; Close leads.
|
|
316
|
+
btn("close", !!next && !next.href) +
|
|
308
317
|
(withLog && hook.logUrl ? btn("log") : "") +
|
|
309
|
-
|
|
318
|
+
(next
|
|
319
|
+
? next.href
|
|
320
|
+
? `<a class="bz-btn bz-primary" href="${esc(next.href)}">${esc(next.label)}</a>`
|
|
321
|
+
: ""
|
|
322
|
+
: btn(primary, true)) +
|
|
310
323
|
`</div>`;
|
|
311
324
|
|
|
325
|
+
/** The caller's next step for this failure, or null (then Try again). */
|
|
326
|
+
function nextStep(err) {
|
|
327
|
+
let n = opts.next;
|
|
328
|
+
if (typeof n === "function") {
|
|
329
|
+
try {
|
|
330
|
+
n = n(err);
|
|
331
|
+
} catch {
|
|
332
|
+
n = null;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
return n && n.label ? n : null;
|
|
336
|
+
}
|
|
337
|
+
|
|
312
338
|
function paintWorking(secs, note) {
|
|
313
339
|
state = "working";
|
|
314
340
|
const line = note
|
|
@@ -321,10 +347,39 @@ export function busyAction(name, run, opts = {}) {
|
|
|
321
347
|
paint(
|
|
322
348
|
title("clock", actionWord(a, "working", vars)) +
|
|
323
349
|
`<p aria-live="polite" class="bz-live">${esc(line)}</p>` +
|
|
350
|
+
progressHtml() +
|
|
324
351
|
`<div class="bz-bar" role="progressbar" aria-label="${esc(word("wait", { who }))}"><i></i></div>`,
|
|
325
352
|
);
|
|
326
353
|
}
|
|
327
354
|
|
|
355
|
+
/** The progress lines so far ("" with none). */
|
|
356
|
+
function progressHtml() {
|
|
357
|
+
if (!lines.length) return "";
|
|
358
|
+
return (
|
|
359
|
+
`<ol class="bz-prog" aria-label="${esc(word("progress"))}" aria-live="polite">` +
|
|
360
|
+
lines.map((l) => `<li>${esc(l)}</li>`).join("") +
|
|
361
|
+
`</ol>`
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/** run's progress(text): a new line, in the open pop-up too. */
|
|
366
|
+
function progress(text) {
|
|
367
|
+
if (settled || text == null || text === "") return;
|
|
368
|
+
lines.push(String(text));
|
|
369
|
+
if (state !== "working" || !d?.open) return;
|
|
370
|
+
const ol = d.querySelector(".bz-prog");
|
|
371
|
+
if (ol) {
|
|
372
|
+
const li = document.createElement("li");
|
|
373
|
+
li.textContent = String(text);
|
|
374
|
+
ol.append(li);
|
|
375
|
+
} else {
|
|
376
|
+
d.querySelector(".bz-live")?.insertAdjacentHTML(
|
|
377
|
+
"afterend",
|
|
378
|
+
progressHtml(),
|
|
379
|
+
);
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
|
|
328
383
|
function tick(startedAt) {
|
|
329
384
|
clearInterval(ticker);
|
|
330
385
|
ticker = setInterval(() => {
|
|
@@ -372,13 +427,22 @@ export function busyAction(name, run, opts = {}) {
|
|
|
372
427
|
? word("err_code", { who, code: err.status })
|
|
373
428
|
: messageOf(err) || word("network", { who });
|
|
374
429
|
opts.onFail?.(err);
|
|
430
|
+
const next = nextStep(err);
|
|
375
431
|
paint(
|
|
376
432
|
title("bad", actionWord(a, "failure", vars)) +
|
|
377
433
|
`<p>${esc(why)}</p>` +
|
|
378
434
|
(said && said !== why ? `<p class="bz-said">${esc(said)}</p>` : "") +
|
|
435
|
+
(next ? `<p class="bz-next">${esc(word("next"))}</p>` : "") +
|
|
436
|
+
(next && !next.href
|
|
437
|
+
? `<p class="bz-step">${esc(next.label)}</p>`
|
|
438
|
+
: "") +
|
|
379
439
|
`<details><summary>${esc(word("details"))}</summary><pre>${esc(detailsText(err, id, lastAt))}</pre></details>` +
|
|
380
|
-
footer("retry"),
|
|
381
|
-
|
|
440
|
+
footer("retry", false, next),
|
|
441
|
+
next
|
|
442
|
+
? next.href
|
|
443
|
+
? ".bz-ft a.bz-primary"
|
|
444
|
+
: '[data-bz="close"]'
|
|
445
|
+
: '[data-bz="retry"]',
|
|
382
446
|
);
|
|
383
447
|
wire();
|
|
384
448
|
}
|
|
@@ -492,6 +556,7 @@ export function busyAction(name, run, opts = {}) {
|
|
|
492
556
|
// Try again: the same id only when no answer came back.
|
|
493
557
|
if (answeredWithError(lastErr)) id = newId();
|
|
494
558
|
lastErr = null;
|
|
559
|
+
lines = [];
|
|
495
560
|
const startedAt = Date.now();
|
|
496
561
|
state = "working";
|
|
497
562
|
hold(true);
|
|
@@ -506,7 +571,7 @@ export function busyAction(name, run, opts = {}) {
|
|
|
506
571
|
}
|
|
507
572
|
}, OPEN_MS);
|
|
508
573
|
Promise.resolve()
|
|
509
|
-
.then(() => run({ [hook.idHeader]: id }))
|
|
574
|
+
.then(() => run({ [hook.idHeader]: id }, progress))
|
|
510
575
|
.then(
|
|
511
576
|
(data) => {
|
|
512
577
|
clearTimeout(opener);
|
|
@@ -526,8 +591,13 @@ export function busyAction(name, run, opts = {}) {
|
|
|
526
591
|
async function checkAgain() {
|
|
527
592
|
let st = null;
|
|
528
593
|
try {
|
|
529
|
-
|
|
530
|
-
|
|
594
|
+
// The product's adapter when it has one (its request(id)), else
|
|
595
|
+
// a GET of statusUrl(id).
|
|
596
|
+
if (hook.request) st = (await hook.request(id)) ?? null;
|
|
597
|
+
else {
|
|
598
|
+
const r = await fetch(hook.statusUrl(id), { cache: "no-store" });
|
|
599
|
+
st = r.ok ? await r.json() : null;
|
|
600
|
+
}
|
|
531
601
|
} catch {
|
|
532
602
|
st = null;
|
|
533
603
|
}
|
package/src/dialog.css
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/* den-ui: the ask-and-tell dialogs' look (dialog.js). Tokens only (UK-1):
|
|
2
|
+
no colour of its own. Linked, never injected: clean under style-src 'self'. */
|
|
3
|
+
.dk-dlg {
|
|
4
|
+
font-family: var(--sans);
|
|
5
|
+
position: fixed;
|
|
6
|
+
inset-block: auto;
|
|
7
|
+
inset-inline: 0;
|
|
8
|
+
top: 50%;
|
|
9
|
+
transform: translateY(-50%);
|
|
10
|
+
margin: 0 auto;
|
|
11
|
+
height: auto;
|
|
12
|
+
max-height: calc(100vh - 32px);
|
|
13
|
+
max-height: calc(100dvh - 32px);
|
|
14
|
+
overflow: auto;
|
|
15
|
+
width: min(440px, calc(100vw - 32px));
|
|
16
|
+
max-width: 100%;
|
|
17
|
+
padding: 0;
|
|
18
|
+
border: 1px solid var(--border-strong);
|
|
19
|
+
border-radius: var(--radius);
|
|
20
|
+
background: var(--surface);
|
|
21
|
+
color: var(--text);
|
|
22
|
+
box-shadow: var(--shadow-dialog);
|
|
23
|
+
box-sizing: border-box;
|
|
24
|
+
}
|
|
25
|
+
.dk-dlg::backdrop {
|
|
26
|
+
background: color-mix(in srgb, var(--sunken) 70%, transparent);
|
|
27
|
+
}
|
|
28
|
+
.dk-b {
|
|
29
|
+
padding: var(--space-4) calc(var(--space-4) + 2px);
|
|
30
|
+
display: grid;
|
|
31
|
+
gap: 10px;
|
|
32
|
+
margin: 0;
|
|
33
|
+
}
|
|
34
|
+
.dk-b h2 {
|
|
35
|
+
font-size: var(--fs-l);
|
|
36
|
+
margin: 0;
|
|
37
|
+
overflow-wrap: anywhere;
|
|
38
|
+
}
|
|
39
|
+
.dk-msg {
|
|
40
|
+
margin: 0;
|
|
41
|
+
font-size: var(--fs-s);
|
|
42
|
+
line-height: 1.5;
|
|
43
|
+
white-space: pre-wrap;
|
|
44
|
+
overflow-wrap: anywhere;
|
|
45
|
+
max-height: 50dvh;
|
|
46
|
+
overflow: auto;
|
|
47
|
+
}
|
|
48
|
+
.dk-in {
|
|
49
|
+
font: inherit;
|
|
50
|
+
font-size: var(--fs-s);
|
|
51
|
+
min-height: var(--tap-min);
|
|
52
|
+
padding: 0 var(--space-2);
|
|
53
|
+
border: 1px solid var(--border-strong);
|
|
54
|
+
border-radius: var(--radius-button);
|
|
55
|
+
background: var(--bg);
|
|
56
|
+
color: var(--text);
|
|
57
|
+
width: 100%;
|
|
58
|
+
box-sizing: border-box;
|
|
59
|
+
}
|
|
60
|
+
.dk-in:focus-visible {
|
|
61
|
+
outline: 2px solid var(--accent);
|
|
62
|
+
outline-offset: 1px;
|
|
63
|
+
}
|
|
64
|
+
.dk-ft {
|
|
65
|
+
display: flex;
|
|
66
|
+
flex-wrap: wrap;
|
|
67
|
+
gap: var(--space-2);
|
|
68
|
+
justify-content: flex-end;
|
|
69
|
+
align-items: center;
|
|
70
|
+
}
|
|
71
|
+
.dk-ft > :first-child:not(.dk-btn) {
|
|
72
|
+
margin-right: auto;
|
|
73
|
+
}
|
|
74
|
+
.dk-btn {
|
|
75
|
+
font: inherit;
|
|
76
|
+
font-size: var(--fs-s);
|
|
77
|
+
min-height: var(--tap-min);
|
|
78
|
+
padding: 0 var(--space-3);
|
|
79
|
+
border-radius: var(--radius-button);
|
|
80
|
+
border: 1px solid var(--border-strong);
|
|
81
|
+
background: var(--surface);
|
|
82
|
+
color: var(--text);
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
}
|
|
85
|
+
.dk-btn:focus-visible {
|
|
86
|
+
outline: 2px solid var(--accent);
|
|
87
|
+
outline-offset: 2px;
|
|
88
|
+
}
|
|
89
|
+
.dk-btn.dk-primary {
|
|
90
|
+
background: var(--accent-fill);
|
|
91
|
+
border-color: var(--accent-fill);
|
|
92
|
+
color: var(--on-accent);
|
|
93
|
+
}
|
|
94
|
+
.dk-btn.dk-danger {
|
|
95
|
+
background: var(--bad);
|
|
96
|
+
border-color: var(--bad);
|
|
97
|
+
color: var(--on-accent);
|
|
98
|
+
}
|
|
99
|
+
@media (max-width: 480px) {
|
|
100
|
+
.dk-btn {
|
|
101
|
+
min-height: var(--tap);
|
|
102
|
+
}
|
|
103
|
+
}
|