@monster-orange/den-ui 0.0.0-stage → 0.6.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/LICENSE +21 -0
- package/README.md +408 -2
- package/bin/den-ui-parity.mjs +365 -0
- package/inventory/nav-inventory.d.ts +89 -0
- package/inventory/nav-inventory.js +590 -0
- package/inventory/reference/den-chromium-1280.json +5137 -0
- package/inventory/reference/den-chromium-390.json +3653 -0
- package/inventory/reference/den-webkit-1280.json +5137 -0
- package/inventory/reference/den-webkit-390.json +3653 -0
- package/package.json +51 -4
- package/src/base.css +80 -0
- package/src/busy-words.d.ts +2 -0
- package/src/busy-words.js +71 -0
- package/src/busy.css +155 -0
- package/src/busy.d.ts +80 -0
- package/src/busy.js +662 -0
- package/src/dialog.css +103 -0
- package/src/dialog.d.ts +44 -0
- package/src/dialog.js +282 -0
- package/src/fonts/OFL.txt +97 -0
- package/src/fonts/rubik-latin-400-normal.woff2 +0 -0
- package/src/fonts/rubik-latin-500-normal.woff2 +0 -0
- package/src/fonts/rubik-latin-ext-400-normal.woff2 +0 -0
- package/src/fonts/rubik-latin-ext-500-normal.woff2 +0 -0
- package/src/fonts/space-mono-latin-400-normal.woff2 +0 -0
- package/src/fonts/space-mono-latin-ext-400-normal.woff2 +0 -0
- package/src/fonts.css +71 -0
- package/src/icons.d.ts +4 -0
- package/src/icons.js +43 -0
- package/src/kit.d.ts +146 -0
- package/src/kit.js +224 -0
- package/src/report-shot.d.ts +47 -0
- package/src/report-shot.js +255 -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 +31 -0
- package/src/shell-client.js +240 -0
- package/src/shell-html.d.ts +91 -0
- package/src/shell-html.js +289 -0
- package/src/shell.css +558 -0
- package/src/strings.d.ts +18 -0
- package/src/strings.js +514 -0
- package/src/time.d.ts +18 -0
- package/src/time.js +254 -0
- package/src/tokens.css +158 -0
- package/src/update-pill.css +32 -0
- package/src/update-pill.d.ts +17 -0
- package/src/update-pill.js +95 -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/src/whatsnew.css
ADDED
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* den-ui What's new: the release notes pop-up (whatsnew.js). Tokens only.
|
|
3
|
+
* <link rel="stylesheet" href="/kit/whatsnew.css">
|
|
4
|
+
*/
|
|
5
|
+
.cl-overlay {
|
|
6
|
+
position: fixed;
|
|
7
|
+
inset: 0;
|
|
8
|
+
z-index: 1000;
|
|
9
|
+
background: var(--kit-veil);
|
|
10
|
+
display: none;
|
|
11
|
+
align-items: center;
|
|
12
|
+
justify-content: center;
|
|
13
|
+
}
|
|
14
|
+
.cl-overlay.open {
|
|
15
|
+
display: flex;
|
|
16
|
+
}
|
|
17
|
+
.cl-box {
|
|
18
|
+
background: var(--surface);
|
|
19
|
+
border: 1px solid var(--border);
|
|
20
|
+
border-radius: 10px;
|
|
21
|
+
width: min(580px, 92vw);
|
|
22
|
+
max-height: 78vh;
|
|
23
|
+
display: flex;
|
|
24
|
+
flex-direction: column;
|
|
25
|
+
overflow: hidden;
|
|
26
|
+
box-shadow: var(--shadow);
|
|
27
|
+
}
|
|
28
|
+
.cl-hdr {
|
|
29
|
+
display: flex;
|
|
30
|
+
align-items: center;
|
|
31
|
+
gap: 10px;
|
|
32
|
+
padding: 13px 18px;
|
|
33
|
+
border-bottom: 1px solid var(--border);
|
|
34
|
+
flex-shrink: 0;
|
|
35
|
+
}
|
|
36
|
+
.cl-hdr h3 {
|
|
37
|
+
font-family: var(--mono);
|
|
38
|
+
font-size: 13px;
|
|
39
|
+
font-weight: 600;
|
|
40
|
+
color: var(--text);
|
|
41
|
+
flex: 1;
|
|
42
|
+
margin: 0;
|
|
43
|
+
}
|
|
44
|
+
.cl-close {
|
|
45
|
+
background: none;
|
|
46
|
+
border: none;
|
|
47
|
+
color: var(--muted);
|
|
48
|
+
font-size: 18px;
|
|
49
|
+
cursor: pointer;
|
|
50
|
+
line-height: 1;
|
|
51
|
+
padding: 2px 5px;
|
|
52
|
+
border-radius: 3px;
|
|
53
|
+
transition:
|
|
54
|
+
color 0.1s,
|
|
55
|
+
background 0.1s;
|
|
56
|
+
}
|
|
57
|
+
.cl-close:hover {
|
|
58
|
+
color: var(--text);
|
|
59
|
+
background: var(--border);
|
|
60
|
+
}
|
|
61
|
+
.cl-body {
|
|
62
|
+
overflow-y: auto;
|
|
63
|
+
padding: 16px 18px;
|
|
64
|
+
flex: 1;
|
|
65
|
+
}
|
|
66
|
+
.cl-entry {
|
|
67
|
+
margin-bottom: 18px;
|
|
68
|
+
}
|
|
69
|
+
.cl-ver-row {
|
|
70
|
+
display: flex;
|
|
71
|
+
align-items: baseline;
|
|
72
|
+
gap: 8px;
|
|
73
|
+
margin-bottom: 8px;
|
|
74
|
+
}
|
|
75
|
+
.cl-ver {
|
|
76
|
+
margin: 0;
|
|
77
|
+
font-family: var(--mono);
|
|
78
|
+
font-size: 13px;
|
|
79
|
+
font-weight: 700;
|
|
80
|
+
color: var(--accent-text);
|
|
81
|
+
}
|
|
82
|
+
.cl-date {
|
|
83
|
+
font-size: 11px;
|
|
84
|
+
color: var(--muted);
|
|
85
|
+
}
|
|
86
|
+
.cl-note {
|
|
87
|
+
font-size: 12px;
|
|
88
|
+
color: var(--muted);
|
|
89
|
+
margin: 0 0 8px;
|
|
90
|
+
font-style: italic;
|
|
91
|
+
}
|
|
92
|
+
.cl-sec {
|
|
93
|
+
font-size: 10px;
|
|
94
|
+
font-weight: 600;
|
|
95
|
+
text-transform: uppercase;
|
|
96
|
+
letter-spacing: 0.07em;
|
|
97
|
+
color: var(--muted);
|
|
98
|
+
margin: 8px 0 4px;
|
|
99
|
+
}
|
|
100
|
+
.cl-items {
|
|
101
|
+
list-style: none;
|
|
102
|
+
padding: 0;
|
|
103
|
+
margin: 0;
|
|
104
|
+
}
|
|
105
|
+
.cl-items li {
|
|
106
|
+
font-size: 12px;
|
|
107
|
+
color: var(--text);
|
|
108
|
+
padding: 2px 0 2px 14px;
|
|
109
|
+
position: relative;
|
|
110
|
+
line-height: 1.5;
|
|
111
|
+
}
|
|
112
|
+
.cl-items li::before {
|
|
113
|
+
content: "·";
|
|
114
|
+
position: absolute;
|
|
115
|
+
left: 2px;
|
|
116
|
+
color: var(--muted);
|
|
117
|
+
}
|
|
118
|
+
.cl-subitems {
|
|
119
|
+
list-style: none;
|
|
120
|
+
padding: 0;
|
|
121
|
+
margin: 2px 0 0 0;
|
|
122
|
+
}
|
|
123
|
+
.cl-subitems li {
|
|
124
|
+
font-size: 11.5px;
|
|
125
|
+
padding: 1px 0 1px 14px;
|
|
126
|
+
color: var(--muted);
|
|
127
|
+
}
|
|
128
|
+
.cl-subitems li::before {
|
|
129
|
+
content: "–";
|
|
130
|
+
position: absolute;
|
|
131
|
+
left: 2px;
|
|
132
|
+
}
|
|
133
|
+
.cl-items code {
|
|
134
|
+
font-family: var(--mono);
|
|
135
|
+
font-size: 10.5px;
|
|
136
|
+
color: var(--accent-text);
|
|
137
|
+
background: color-mix(in srgb, var(--accent) 10%, transparent);
|
|
138
|
+
padding: 1px 4px;
|
|
139
|
+
border-radius: 3px;
|
|
140
|
+
}
|
|
141
|
+
.cl-divider {
|
|
142
|
+
border: none;
|
|
143
|
+
border-top: 1px solid var(--border);
|
|
144
|
+
margin: 14px 0;
|
|
145
|
+
}
|
|
146
|
+
.cl-copy-group {
|
|
147
|
+
display: flex;
|
|
148
|
+
gap: 4px;
|
|
149
|
+
margin-left: auto;
|
|
150
|
+
flex-shrink: 0;
|
|
151
|
+
}
|
|
152
|
+
.cl-copy-btn,
|
|
153
|
+
.cl-slack-btn {
|
|
154
|
+
background: none;
|
|
155
|
+
border: 1px solid var(--border);
|
|
156
|
+
color: var(--muted);
|
|
157
|
+
padding: 3px 6px;
|
|
158
|
+
border-radius: 4px;
|
|
159
|
+
line-height: 0;
|
|
160
|
+
cursor: pointer;
|
|
161
|
+
flex-shrink: 0;
|
|
162
|
+
display: inline-flex;
|
|
163
|
+
align-items: center;
|
|
164
|
+
justify-content: center;
|
|
165
|
+
transition:
|
|
166
|
+
color 0.1s,
|
|
167
|
+
border-color 0.1s;
|
|
168
|
+
}
|
|
169
|
+
.cl-more-btn {
|
|
170
|
+
padding: 4px 12px;
|
|
171
|
+
font: inherit;
|
|
172
|
+
font-size: 11px;
|
|
173
|
+
color: var(--muted);
|
|
174
|
+
background: none;
|
|
175
|
+
border: 1px solid var(--border);
|
|
176
|
+
border-radius: 6px;
|
|
177
|
+
cursor: pointer;
|
|
178
|
+
}
|
|
179
|
+
.cl-more-btn:hover {
|
|
180
|
+
color: var(--accent-text);
|
|
181
|
+
border-color: var(--accent);
|
|
182
|
+
}
|
|
183
|
+
.cl-copy-btn:hover {
|
|
184
|
+
color: var(--accent-text);
|
|
185
|
+
border-color: var(--accent);
|
|
186
|
+
}
|
|
187
|
+
.cl-copy-btn.copied {
|
|
188
|
+
color: var(--ok);
|
|
189
|
+
border-color: var(--ok);
|
|
190
|
+
}
|
|
191
|
+
.cl-slack-btn:hover {
|
|
192
|
+
color: var(--accent-text);
|
|
193
|
+
border-color: var(--accent);
|
|
194
|
+
}
|
|
195
|
+
.cl-slack-btn.copied {
|
|
196
|
+
color: var(--ok);
|
|
197
|
+
border-color: var(--ok);
|
|
198
|
+
}
|
|
199
|
+
.cl-footer .den-rb {
|
|
200
|
+
margin-right: auto;
|
|
201
|
+
}
|
|
202
|
+
.cl-footer {
|
|
203
|
+
padding: 10px 18px;
|
|
204
|
+
border-top: 1px solid var(--border);
|
|
205
|
+
display: flex;
|
|
206
|
+
justify-content: flex-end;
|
|
207
|
+
flex-shrink: 0;
|
|
208
|
+
gap: 8px;
|
|
209
|
+
background: var(--surface);
|
|
210
|
+
}
|
|
211
|
+
.cl-got-it {
|
|
212
|
+
background: var(--accent-fill);
|
|
213
|
+
border: none;
|
|
214
|
+
color: var(--on-accent);
|
|
215
|
+
padding: 5px 16px;
|
|
216
|
+
border-radius: 5px;
|
|
217
|
+
font-size: 12px;
|
|
218
|
+
font-weight: 600;
|
|
219
|
+
cursor: pointer;
|
|
220
|
+
}
|
|
221
|
+
.cl-got-it:hover {
|
|
222
|
+
filter: brightness(0.92);
|
|
223
|
+
}
|
|
224
|
+
.cl-none {
|
|
225
|
+
color: var(--muted);
|
|
226
|
+
font-size: 12px;
|
|
227
|
+
}
|
|
228
|
+
/* A copy's helper element: on the page for the copy, never seen. */
|
|
229
|
+
.kit-offscreen {
|
|
230
|
+
position: fixed;
|
|
231
|
+
opacity: 0;
|
|
232
|
+
top: 0;
|
|
233
|
+
left: 0;
|
|
234
|
+
pointer-events: none;
|
|
235
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface ChangelogItem {
|
|
2
|
+
text: string;
|
|
3
|
+
items?: ChangelogItem[];
|
|
4
|
+
}
|
|
5
|
+
export interface ChangelogEntry {
|
|
6
|
+
version: string;
|
|
7
|
+
date?: string;
|
|
8
|
+
sections?: Record<string, ChangelogItem[]>;
|
|
9
|
+
}
|
|
10
|
+
export interface WhatsNewOptions {
|
|
11
|
+
lang?: string | (() => string);
|
|
12
|
+
/** The adapter's changelog(): newest first. */
|
|
13
|
+
changelog?: (() => Promise<ChangelogEntry[]>) | null;
|
|
14
|
+
/** The Report button's HTML for the footer ("" for none). */
|
|
15
|
+
reportButton?: () => string;
|
|
16
|
+
/** After a close, with the newest version shown. */
|
|
17
|
+
onClose?: (latest: string | null) => void;
|
|
18
|
+
}
|
|
19
|
+
export declare function configureWhatsNew(o?: WhatsNewOptions): void;
|
|
20
|
+
export declare function changelogView(
|
|
21
|
+
list: ChangelogEntry[],
|
|
22
|
+
all: boolean,
|
|
23
|
+
): {
|
|
24
|
+
shown: ChangelogEntry[];
|
|
25
|
+
toggle: { label: string; expanded: boolean } | null;
|
|
26
|
+
};
|
|
27
|
+
export declare function setEntries(list: ChangelogEntry[]): void;
|
|
28
|
+
export declare function getEntries(): ChangelogEntry[];
|
|
29
|
+
export declare function loadWhatsNew(): Promise<ChangelogEntry[]>;
|
|
30
|
+
export declare function ensureWhatsNew(): void;
|
|
31
|
+
export declare function renderBody(): void;
|
|
32
|
+
export declare function copyText(text: string): Promise<void>;
|
|
33
|
+
export declare function buildRichHtml(entry: ChangelogEntry): string;
|
|
34
|
+
export declare function buildMarkdown(entry: ChangelogEntry): string;
|
|
35
|
+
export declare function openWhatsNew(): void;
|
|
36
|
+
export declare function closeWhatsNew(): void;
|
package/src/whatsnew.js
ADDED
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* den-ui What's new: the release notes pop-up, opened from the version
|
|
3
|
+
* chip (or on a new version's first visit). Its look is whatsnew.css.
|
|
4
|
+
*
|
|
5
|
+
* configureWhatsNew({ lang, changelog, reportButton, onClose })
|
|
6
|
+
* lang the kit's words' language (a string or a function)
|
|
7
|
+
* changelog() the product's adapter: Promise of the entries, newest
|
|
8
|
+
* first: [{ version, date, note?, raw?, sections:
|
|
9
|
+
* { "Added": [{ text, sub? }] } }]
|
|
10
|
+
* reportButton() the footer's Report button HTML ("" when reports
|
|
11
|
+
* are off); default the kit's
|
|
12
|
+
* onClose(latest) after a close: the newest version, to remember it
|
|
13
|
+
* as seen (the chip's dot goes)
|
|
14
|
+
* loadWhatsNew() asks changelog() and keeps the entries
|
|
15
|
+
* setEntries(list) or gives them directly
|
|
16
|
+
* openWhatsNew() opens it at the newest release; focus on its heading
|
|
17
|
+
* closeWhatsNew() closes it; focus back where it was (else the chip)
|
|
18
|
+
* changelogView(entries, showAll) what it shows (pure)
|
|
19
|
+
*
|
|
20
|
+
* It is an aria-modal dialog: Tab stays in it, Escape and a click on the
|
|
21
|
+
* veil close it. Markdown and Slack copy buttons on each version.
|
|
22
|
+
*/
|
|
23
|
+
import { esc, kitT } from "./strings.js";
|
|
24
|
+
import { reportButtonHtml } from "./shell-html.js";
|
|
25
|
+
import { focusBack, openerOf } from "./dialog.js";
|
|
26
|
+
|
|
27
|
+
const cfg = {
|
|
28
|
+
lang: "en",
|
|
29
|
+
changelog: null,
|
|
30
|
+
reportButton: null,
|
|
31
|
+
onClose: null,
|
|
32
|
+
};
|
|
33
|
+
let entries = [];
|
|
34
|
+
let showAll = false;
|
|
35
|
+
let returnFocus = null;
|
|
36
|
+
let made = false;
|
|
37
|
+
|
|
38
|
+
const lang = () => (typeof cfg.lang === "function" ? cfg.lang() : cfg.lang);
|
|
39
|
+
const t = (key, vars) => kitT(lang(), key, vars);
|
|
40
|
+
const escT = (key, vars) => esc(t(key, vars));
|
|
41
|
+
|
|
42
|
+
export function configureWhatsNew(o = {}) {
|
|
43
|
+
Object.assign(cfg, o);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* What the pop-up shows: the newest release only, or every version once
|
|
48
|
+
* the reader asks for them, plus the one button that toggles between the
|
|
49
|
+
* two (null when there is nothing earlier to show).
|
|
50
|
+
*/
|
|
51
|
+
export function changelogView(list, all) {
|
|
52
|
+
const l = Array.isArray(list) ? list : [];
|
|
53
|
+
const earlier = l.length - 1;
|
|
54
|
+
if (earlier < 1) return { shown: l.slice(0, 1), toggle: null };
|
|
55
|
+
return {
|
|
56
|
+
shown: all ? l : l.slice(0, 1),
|
|
57
|
+
toggle: all
|
|
58
|
+
? { label: "Show latest only", expanded: true }
|
|
59
|
+
: { label: `Show all versions (${earlier} earlier)`, expanded: false },
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function setEntries(list) {
|
|
64
|
+
entries = Array.isArray(list) ? list : [];
|
|
65
|
+
}
|
|
66
|
+
export function getEntries() {
|
|
67
|
+
return entries;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function loadWhatsNew() {
|
|
71
|
+
try {
|
|
72
|
+
setEntries(cfg.changelog ? await cfg.changelog() : []);
|
|
73
|
+
} catch {
|
|
74
|
+
setEntries([]);
|
|
75
|
+
}
|
|
76
|
+
return entries;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The overlay, made once (hidden until opened). */
|
|
80
|
+
export function ensureWhatsNew() {
|
|
81
|
+
if (made && document.getElementById("cl-overlay")) return;
|
|
82
|
+
made = true;
|
|
83
|
+
const report = cfg.reportButton
|
|
84
|
+
? cfg.reportButton()
|
|
85
|
+
: reportButtonHtml({ inFoot: false, lang: lang() });
|
|
86
|
+
const overlay = document.createElement("div");
|
|
87
|
+
overlay.id = "cl-overlay";
|
|
88
|
+
overlay.className = "cl-overlay";
|
|
89
|
+
overlay.innerHTML =
|
|
90
|
+
'<div class="cl-box" role="dialog" aria-modal="true" aria-labelledby="cl-title">' +
|
|
91
|
+
`<div class="cl-hdr"><h3 id="cl-title" tabindex="-1">${escT("kit.whatsnew.title")}</h3><button type="button" class="cl-close" id="cl-close-btn" title="${escT("kit.whatsnew.close")}" aria-label="${escT("kit.whatsnew.close")}">×</button></div>` +
|
|
92
|
+
'<div class="cl-body" id="cl-body"></div>' +
|
|
93
|
+
'<div class="cl-footer">' +
|
|
94
|
+
// Report, as in every pop-up.
|
|
95
|
+
(report || "") +
|
|
96
|
+
'<button type="button" class="cl-more-btn" id="cl-more" aria-controls="cl-body" aria-expanded="false" hidden></button><button class="cl-got-it" id="cl-got-it-btn">' +
|
|
97
|
+
escT("kit.whatsnew.gotIt") +
|
|
98
|
+
"</button></div>" +
|
|
99
|
+
"</div>";
|
|
100
|
+
document.body.appendChild(overlay);
|
|
101
|
+
document.getElementById("cl-more")?.addEventListener("click", () => {
|
|
102
|
+
showAll = !showAll;
|
|
103
|
+
renderBody();
|
|
104
|
+
const body = document.getElementById("cl-body");
|
|
105
|
+
if (body) body.scrollTop = 0;
|
|
106
|
+
});
|
|
107
|
+
overlay.addEventListener("click", (e) => {
|
|
108
|
+
if (e.target === overlay) closeWhatsNew();
|
|
109
|
+
});
|
|
110
|
+
document
|
|
111
|
+
.getElementById("cl-close-btn")
|
|
112
|
+
?.addEventListener("click", () => closeWhatsNew());
|
|
113
|
+
document
|
|
114
|
+
.getElementById("cl-got-it-btn")
|
|
115
|
+
?.addEventListener("click", () => closeWhatsNew());
|
|
116
|
+
document.addEventListener("keydown", (e) => {
|
|
117
|
+
if (!overlay.classList.contains("open")) return;
|
|
118
|
+
if (e.key === "Escape") {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
closeWhatsNew();
|
|
121
|
+
} else if (e.key === "Tab") trapTab(e, overlay);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Tab and Shift+Tab stay inside the open dialog (aria-modal). */
|
|
126
|
+
function trapTab(e, overlay) {
|
|
127
|
+
const box = overlay.querySelector(".cl-box");
|
|
128
|
+
const stops = [
|
|
129
|
+
...box.querySelectorAll("button, a[href], [tabindex]:not([tabindex='-1'])"),
|
|
130
|
+
].filter((el) => !el.hidden && !el.disabled && el.getClientRects().length);
|
|
131
|
+
if (!stops.length) return;
|
|
132
|
+
const first = stops[0];
|
|
133
|
+
const last = stops[stops.length - 1];
|
|
134
|
+
const at = document.activeElement;
|
|
135
|
+
// Anything not one of the stops (the focused heading, or outside) counts
|
|
136
|
+
// as outside: Shift+Tab from the heading must not leave the dialog.
|
|
137
|
+
const inside = stops.includes(at);
|
|
138
|
+
if (e.shiftKey ? at === first || !inside : at === last) {
|
|
139
|
+
e.preventDefault();
|
|
140
|
+
(e.shiftKey ? last : first).focus();
|
|
141
|
+
} else if (!inside) {
|
|
142
|
+
e.preventDefault();
|
|
143
|
+
first.focus();
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const COPY_ICON =
|
|
148
|
+
'<svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' +
|
|
149
|
+
'<rect x="4" y="0.5" width="8.5" height="8.5" rx="1.5"/>' +
|
|
150
|
+
'<path d="M8.5 9v2.5a1 1 0 0 1-1 1H1a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h2.5"/>' +
|
|
151
|
+
"</svg>";
|
|
152
|
+
const SLACK_ICON =
|
|
153
|
+
'<svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' +
|
|
154
|
+
'<path d="M1 2a1 1 0 0 1 1-1h9a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H7.5L5 12v-3H2a1 1 0 0 1-1-1V2z"/>' +
|
|
155
|
+
"</svg>";
|
|
156
|
+
const CHECK_ICON =
|
|
157
|
+
'<svg width="13" height="13" viewBox="0 0 13 13" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">' +
|
|
158
|
+
'<polyline points="2,7 5,10 11,3"/>' +
|
|
159
|
+
"</svg>";
|
|
160
|
+
|
|
161
|
+
const escHtml = (s) =>
|
|
162
|
+
String(s).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
163
|
+
const renderItem = (s) =>
|
|
164
|
+
escHtml(s)
|
|
165
|
+
.replace(/\*\*([^*]+)\*\*/g, "<strong>$1</strong>")
|
|
166
|
+
.replace(/`([^`]+)`/g, "<code>$1</code>");
|
|
167
|
+
|
|
168
|
+
/** The body: the release(s) shown, and the footer's toggle. */
|
|
169
|
+
export function renderBody() {
|
|
170
|
+
const body = document.getElementById("cl-body");
|
|
171
|
+
if (!body) return;
|
|
172
|
+
if (!entries.length) {
|
|
173
|
+
body.innerHTML = `<p class="cl-none">${escT("kit.whatsnew.none")}</p>`;
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const view = changelogView(entries, showAll);
|
|
177
|
+
body.innerHTML = view.shown
|
|
178
|
+
.map(
|
|
179
|
+
(entry, i) =>
|
|
180
|
+
(i > 0 ? '<hr class="cl-divider">' : "") +
|
|
181
|
+
'<div class="cl-entry">' +
|
|
182
|
+
'<div class="cl-ver-row">' +
|
|
183
|
+
'<h4 class="cl-ver">v' +
|
|
184
|
+
escHtml(entry.version) +
|
|
185
|
+
"</h4>" +
|
|
186
|
+
'<span class="cl-date">' +
|
|
187
|
+
escHtml(entry.date) +
|
|
188
|
+
"</span>" +
|
|
189
|
+
'<div class="cl-copy-group">' +
|
|
190
|
+
'<button class="cl-copy-btn" data-cl-version="' +
|
|
191
|
+
escHtml(entry.version) +
|
|
192
|
+
'" title="' +
|
|
193
|
+
escT("kit.whatsnew.copyMd") +
|
|
194
|
+
'" aria-label="' +
|
|
195
|
+
escT("kit.whatsnew.copyMdX", { v: entry.version }) +
|
|
196
|
+
'">' +
|
|
197
|
+
COPY_ICON +
|
|
198
|
+
"</button>" +
|
|
199
|
+
'<button class="cl-slack-btn" data-cl-version="' +
|
|
200
|
+
escHtml(entry.version) +
|
|
201
|
+
'" title="' +
|
|
202
|
+
escT("kit.whatsnew.copySlack") +
|
|
203
|
+
'" aria-label="' +
|
|
204
|
+
escT("kit.whatsnew.copySlackX", { v: entry.version }) +
|
|
205
|
+
'">' +
|
|
206
|
+
SLACK_ICON +
|
|
207
|
+
"</button>" +
|
|
208
|
+
"</div>" +
|
|
209
|
+
"</div>" +
|
|
210
|
+
(entry.note
|
|
211
|
+
? '<p class="cl-note">' + renderItem(entry.note) + "</p>"
|
|
212
|
+
: "") +
|
|
213
|
+
Object.entries(entry.sections ?? {})
|
|
214
|
+
.map(
|
|
215
|
+
([sec, items]) =>
|
|
216
|
+
'<div class="cl-sec">' +
|
|
217
|
+
escHtml(sec) +
|
|
218
|
+
"</div>" +
|
|
219
|
+
'<ul class="cl-items">' +
|
|
220
|
+
items
|
|
221
|
+
.map(
|
|
222
|
+
(it) =>
|
|
223
|
+
"<li>" +
|
|
224
|
+
renderItem(it.text) +
|
|
225
|
+
(it.sub?.length
|
|
226
|
+
? '<ul class="cl-subitems">' +
|
|
227
|
+
it.sub
|
|
228
|
+
.map((s) => "<li>" + renderItem(s) + "</li>")
|
|
229
|
+
.join("") +
|
|
230
|
+
"</ul>"
|
|
231
|
+
: "") +
|
|
232
|
+
"</li>",
|
|
233
|
+
)
|
|
234
|
+
.join("") +
|
|
235
|
+
"</ul>",
|
|
236
|
+
)
|
|
237
|
+
.join("") +
|
|
238
|
+
"</div>",
|
|
239
|
+
)
|
|
240
|
+
.join("");
|
|
241
|
+
|
|
242
|
+
// The toggle lives in the footer, so it is in view however long the
|
|
243
|
+
// newest entry is.
|
|
244
|
+
const more = document.getElementById("cl-more");
|
|
245
|
+
if (more) {
|
|
246
|
+
more.hidden = !view.toggle;
|
|
247
|
+
if (view.toggle) {
|
|
248
|
+
more.textContent = view.toggle.expanded
|
|
249
|
+
? t("kit.whatsnew.latest")
|
|
250
|
+
: t("kit.whatsnew.all", { n: entries.length - 1 });
|
|
251
|
+
more.setAttribute("aria-expanded", String(view.toggle.expanded));
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
const copyBtn = (sel, icon, title, make, write) =>
|
|
256
|
+
body.querySelectorAll(sel).forEach((btn) => {
|
|
257
|
+
btn.addEventListener("click", async () => {
|
|
258
|
+
const entry = entries.find((e) => e.version === btn.dataset.clVersion);
|
|
259
|
+
if (!entry) return;
|
|
260
|
+
try {
|
|
261
|
+
await write(make(entry));
|
|
262
|
+
btn.innerHTML = CHECK_ICON;
|
|
263
|
+
btn.classList.add("copied");
|
|
264
|
+
setTimeout(() => {
|
|
265
|
+
btn.innerHTML = icon;
|
|
266
|
+
btn.classList.remove("copied");
|
|
267
|
+
}, 2000);
|
|
268
|
+
} catch {
|
|
269
|
+
btn.title = t("kit.whatsnew.copyFailed");
|
|
270
|
+
setTimeout(() => (btn.title = t(title)), 2000);
|
|
271
|
+
}
|
|
272
|
+
});
|
|
273
|
+
});
|
|
274
|
+
// Markdown copy: plain text for GitHub, MD editors, etc.
|
|
275
|
+
copyBtn(
|
|
276
|
+
".cl-copy-btn",
|
|
277
|
+
COPY_ICON,
|
|
278
|
+
"kit.whatsnew.copyMd",
|
|
279
|
+
(e) => e.raw || buildMarkdown(e),
|
|
280
|
+
copyText,
|
|
281
|
+
);
|
|
282
|
+
// Rich copy: a DOM selection's HTML, which Slack (and Notion, Docs)
|
|
283
|
+
// trusts and renders as formatted text.
|
|
284
|
+
copyBtn(
|
|
285
|
+
".cl-slack-btn",
|
|
286
|
+
SLACK_ICON,
|
|
287
|
+
"kit.whatsnew.copySlack",
|
|
288
|
+
buildRichHtml,
|
|
289
|
+
writeRich,
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Plain text to the clipboard: navigator.clipboard where it can (secure
|
|
295
|
+
* contexts), else execCommand('copy') (an http:// origin).
|
|
296
|
+
*/
|
|
297
|
+
export function copyText(text) {
|
|
298
|
+
if (navigator.clipboard?.writeText)
|
|
299
|
+
return navigator.clipboard.writeText(text);
|
|
300
|
+
return new Promise((resolve, reject) => {
|
|
301
|
+
const ta = document.createElement("textarea");
|
|
302
|
+
ta.value = text;
|
|
303
|
+
ta.className = "kit-offscreen";
|
|
304
|
+
document.body.appendChild(ta);
|
|
305
|
+
ta.focus();
|
|
306
|
+
ta.select();
|
|
307
|
+
try {
|
|
308
|
+
document.execCommand("copy")
|
|
309
|
+
? resolve()
|
|
310
|
+
: reject(new Error("execCommand failed"));
|
|
311
|
+
} catch (e) {
|
|
312
|
+
reject(e);
|
|
313
|
+
} finally {
|
|
314
|
+
document.body.removeChild(ta);
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Rich HTML to the clipboard through a hidden contenteditable: the "copy
|
|
321
|
+
* from a web page" path, whose HTML Slack's paste trusts (a ClipboardItem's
|
|
322
|
+
* it ignores).
|
|
323
|
+
*/
|
|
324
|
+
function writeRich(html) {
|
|
325
|
+
return new Promise((resolve, reject) => {
|
|
326
|
+
const el = document.createElement("div");
|
|
327
|
+
el.contentEditable = "true";
|
|
328
|
+
el.className = "kit-offscreen";
|
|
329
|
+
el.innerHTML = html;
|
|
330
|
+
document.body.appendChild(el);
|
|
331
|
+
const range = document.createRange();
|
|
332
|
+
range.selectNodeContents(el);
|
|
333
|
+
const sel = window.getSelection();
|
|
334
|
+
sel.removeAllRanges();
|
|
335
|
+
sel.addRange(range);
|
|
336
|
+
try {
|
|
337
|
+
document.execCommand("copy")
|
|
338
|
+
? resolve()
|
|
339
|
+
: reject(new Error("execCommand failed"));
|
|
340
|
+
} catch (e) {
|
|
341
|
+
reject(e);
|
|
342
|
+
} finally {
|
|
343
|
+
sel.removeAllRanges();
|
|
344
|
+
document.body.removeChild(el);
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
/** Slack's HTML: bold paragraphs for headings, <code>, bullets. */
|
|
350
|
+
export function buildRichHtml(entry) {
|
|
351
|
+
const sections = Object.entries(entry.sections ?? {})
|
|
352
|
+
.map(([sec, items]) => {
|
|
353
|
+
const li = items.flatMap((it) => [
|
|
354
|
+
`<li>${renderItem(it.text)}</li>`,
|
|
355
|
+
...(it.sub ?? []).map((s) => `<li>${renderItem(s)}</li>`),
|
|
356
|
+
]);
|
|
357
|
+
return `<p><strong>${escHtml(sec)}</strong></p><ul>${li.join("")}</ul>`;
|
|
358
|
+
})
|
|
359
|
+
.join("");
|
|
360
|
+
return `<p><strong>v${escHtml(entry.version)} — ${escHtml(entry.date)}</strong></p>${sections}`;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/** Markdown rebuilt from an entry (when it has no `raw`). */
|
|
364
|
+
export function buildMarkdown(entry) {
|
|
365
|
+
const lines = [`## [${entry.version}] — ${entry.date}`];
|
|
366
|
+
for (const [sec, items] of Object.entries(entry.sections ?? {})) {
|
|
367
|
+
lines.push("", `### ${sec}`, "");
|
|
368
|
+
for (const item of items) {
|
|
369
|
+
lines.push(`- ${item.text}`);
|
|
370
|
+
for (const s of item.sub ?? []) lines.push(` - ${s}`);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
return lines.join("\n");
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
export function openWhatsNew() {
|
|
377
|
+
showAll = false;
|
|
378
|
+
ensureWhatsNew();
|
|
379
|
+
renderBody();
|
|
380
|
+
const overlay = document.getElementById("cl-overlay");
|
|
381
|
+
if (!overlay) return;
|
|
382
|
+
if (!overlay.classList.contains("open")) {
|
|
383
|
+
const at = openerOf();
|
|
384
|
+
// Nothing focused (a first-visit open): the version chip.
|
|
385
|
+
returnFocus =
|
|
386
|
+
at && !overlay.contains(at)
|
|
387
|
+
? at
|
|
388
|
+
: document.getElementById("version-pill");
|
|
389
|
+
}
|
|
390
|
+
overlay.classList.add("open");
|
|
391
|
+
// Always at the newest release. After `.open`: while the overlay is
|
|
392
|
+
// display:none the body has no scroll box, so a reset there doesn't stick.
|
|
393
|
+
const body = document.getElementById("cl-body");
|
|
394
|
+
if (body) body.scrollTop = 0;
|
|
395
|
+
// The heading first, so a screen reader starts at the latest notes.
|
|
396
|
+
document.getElementById("cl-title")?.focus();
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
export function closeWhatsNew() {
|
|
400
|
+
const overlay = document.getElementById("cl-overlay");
|
|
401
|
+
const wasOpen = !!overlay?.classList.contains("open");
|
|
402
|
+
if (overlay) overlay.classList.remove("open");
|
|
403
|
+
if (wasOpen) {
|
|
404
|
+
const back = returnFocus;
|
|
405
|
+
returnFocus = null;
|
|
406
|
+
if (!focusBack(back)) focusBack(document.getElementById("version-pill"));
|
|
407
|
+
}
|
|
408
|
+
if (cfg.onClose) cfg.onClose(entries[0]?.version ?? null);
|
|
409
|
+
const pip = document.getElementById("v-pip");
|
|
410
|
+
if (pip) pip.style.display = "none";
|
|
411
|
+
}
|