@vvedantb/ui 0.84.1 → 0.86.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/app/src/index.ts +5 -0
- package/app/src/update/releaseNotes.ts +74 -0
- package/app/src/update/updateWatcher.ts +53 -21
- package/dist/app/src/index.js +1 -0
- package/dist/app/src/update/releaseNotes.js +65 -0
- package/dist/app/src/update/updateWatcher.js +53 -16
- package/dist/src/client.js +1 -0
- package/dist/src/markdown/Markdown.js +43 -28
- package/dist/src/markdown/codeHighlight.js +70 -37
- package/dist/src/markdown/lazyMath.js +36 -0
- package/dist/src/markdown/mathPlugin.js +2 -0
- package/dist/src/ui/sonner.js +21 -3
- package/dist/src/ui/whats-new-dialog.js +142 -0
- package/package.json +2 -1
- package/src/client.ts +5 -0
- package/src/markdown/Markdown.tsx +12 -6
- package/src/markdown/codeHighlight.ts +46 -10
- package/src/markdown/lazyMath.ts +36 -0
- package/src/markdown/mathPlugin.ts +3 -0
- package/src/ui/sonner.tsx +4 -0
- package/src/ui/whats-new-dialog.tsx +60 -0
package/app/src/index.ts
CHANGED
|
@@ -16,6 +16,11 @@ export {
|
|
|
16
16
|
fetchDeployFingerprint,
|
|
17
17
|
fingerprintFromHtml,
|
|
18
18
|
} from "./update/deployFingerprint.js";
|
|
19
|
+
export {
|
|
20
|
+
fetchReleaseNotes,
|
|
21
|
+
newReleaseNotes,
|
|
22
|
+
type ReleaseNote,
|
|
23
|
+
} from "./update/releaseNotes.js";
|
|
19
24
|
export {
|
|
20
25
|
showUpdateAvailableToast,
|
|
21
26
|
startUpdateAvailableWatcher,
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** One changelog entry of a deploy, from its `/release-notes.json`. */
|
|
2
|
+
export type ReleaseNote = { id: string; date: string; title: string };
|
|
3
|
+
|
|
4
|
+
export type WhatsNewState = {
|
|
5
|
+
notes: ReleaseNote[];
|
|
6
|
+
refresh: () => void;
|
|
7
|
+
onClose: () => void;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
function isReleaseNote(value: unknown): value is ReleaseNote {
|
|
11
|
+
if (typeof value !== "object" || value === null) return false;
|
|
12
|
+
const note = value as Record<string, unknown>;
|
|
13
|
+
return typeof note.id === "string" && typeof note.date === "string" && typeof note.title === "string";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The live deploy's `/release-notes.json` entries. Null when the deploy has
|
|
18
|
+
* no such file (an SPA fallback answers HTML) or the request fails.
|
|
19
|
+
*/
|
|
20
|
+
export async function fetchReleaseNotes(origin: string): Promise<ReleaseNote[] | null> {
|
|
21
|
+
try {
|
|
22
|
+
const response = await fetch(`${origin}/release-notes.json?_vb=${Date.now()}`, {
|
|
23
|
+
cache: "no-store",
|
|
24
|
+
headers: { Accept: "application/json" },
|
|
25
|
+
});
|
|
26
|
+
if (!response.ok) return null;
|
|
27
|
+
const body: unknown = await response.json();
|
|
28
|
+
const notes = (body as { notes?: unknown } | null)?.notes;
|
|
29
|
+
return Array.isArray(notes) ? notes.filter(isReleaseNote) : null;
|
|
30
|
+
} catch {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The entries of `next` that `current` does not have, in `next`'s order.
|
|
37
|
+
* Empty when either deploy has no release notes.
|
|
38
|
+
*/
|
|
39
|
+
export function newReleaseNotes(current: ReleaseNote[] | null, next: ReleaseNote[] | null): ReleaseNote[] {
|
|
40
|
+
if (!current || !next) return [];
|
|
41
|
+
const seen = new Set(current.map((note) => note.id));
|
|
42
|
+
return next.filter((note) => !seen.has(note.id));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
let whatsNew: WhatsNewState | null = null;
|
|
46
|
+
const listeners = new Set<() => void>();
|
|
47
|
+
|
|
48
|
+
function emit(): void {
|
|
49
|
+
for (const listener of listeners) listener();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Open the "What's new" dialog that `SonnerToaster` renders. */
|
|
53
|
+
export function openWhatsNew(state: WhatsNewState): void {
|
|
54
|
+
whatsNew = state;
|
|
55
|
+
emit();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Close the "What's new" dialog. */
|
|
59
|
+
export function closeWhatsNew(): void {
|
|
60
|
+
if (whatsNew === null) return;
|
|
61
|
+
whatsNew = null;
|
|
62
|
+
emit();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export function subscribeWhatsNew(listener: () => void): () => void {
|
|
66
|
+
listeners.add(listener);
|
|
67
|
+
return () => {
|
|
68
|
+
listeners.delete(listener);
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function getWhatsNew(): WhatsNewState | null {
|
|
73
|
+
return whatsNew;
|
|
74
|
+
}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { fetchDeployFingerprint } from "./deployFingerprint.js";
|
|
2
|
+
import {
|
|
3
|
+
fetchReleaseNotes,
|
|
4
|
+
newReleaseNotes,
|
|
5
|
+
openWhatsNew,
|
|
6
|
+
type ReleaseNote,
|
|
7
|
+
} from "./releaseNotes.js";
|
|
2
8
|
|
|
3
9
|
export type UpdateToastOptions = {
|
|
4
10
|
id: string;
|
|
5
11
|
description: string;
|
|
6
12
|
duration: number;
|
|
7
13
|
action: { label: string; onClick: () => void };
|
|
14
|
+
cancel?: { label: string; onClick: () => void };
|
|
8
15
|
};
|
|
9
16
|
|
|
10
17
|
export type UpdateAvailableWatcherOptions = {
|
|
@@ -15,12 +22,15 @@ export type UpdateAvailableWatcherOptions = {
|
|
|
15
22
|
toastId?: string;
|
|
16
23
|
enabled?: boolean;
|
|
17
24
|
reload?: () => void;
|
|
25
|
+
onWhatsNew?: (notes: ReleaseNote[], refresh: () => void) => void;
|
|
18
26
|
};
|
|
19
27
|
|
|
20
28
|
export type ShowUpdateAvailableToastOptions = Pick<
|
|
21
29
|
UpdateAvailableWatcherOptions,
|
|
22
|
-
"toast" | "closeConvex" | "toastId" | "reload"
|
|
23
|
-
|
|
30
|
+
"toast" | "closeConvex" | "toastId" | "reload" | "onWhatsNew"
|
|
31
|
+
> & {
|
|
32
|
+
notes?: ReleaseNote[];
|
|
33
|
+
};
|
|
24
34
|
|
|
25
35
|
const DEFAULT_POLL_MS = 60_000;
|
|
26
36
|
const DEFAULT_TOAST_ID = "app-update-available";
|
|
@@ -29,27 +39,40 @@ const DEFAULT_TOAST_ID = "app-update-available";
|
|
|
29
39
|
* Show the sticky "Update available" toast with a Refresh action. Refresh
|
|
30
40
|
* calls `closeConvex` (errors ignored), then reloads. The same `toastId`
|
|
31
41
|
* replaces an open toast instead of stacking a second one.
|
|
42
|
+
*
|
|
43
|
+
* With `notes`, the toast also has a "What's new" button. It calls
|
|
44
|
+
* `onWhatsNew`, else opens the dialog that `SonnerToaster` renders; closing
|
|
45
|
+
* that dialog shows the toast again.
|
|
32
46
|
*/
|
|
33
|
-
export function showUpdateAvailableToast({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
47
|
+
export function showUpdateAvailableToast(options: ShowUpdateAvailableToastOptions): void {
|
|
48
|
+
const {
|
|
49
|
+
toast,
|
|
50
|
+
closeConvex,
|
|
51
|
+
toastId = DEFAULT_TOAST_ID,
|
|
52
|
+
reload = () => window.location.reload(),
|
|
53
|
+
onWhatsNew,
|
|
54
|
+
notes = [],
|
|
55
|
+
} = options;
|
|
56
|
+
const refresh = (): void => {
|
|
57
|
+
try {
|
|
58
|
+
closeConvex?.();
|
|
59
|
+
} catch {
|
|
60
|
+
}
|
|
61
|
+
reload();
|
|
62
|
+
};
|
|
63
|
+
const showWhatsNew = (): void => {
|
|
64
|
+
if (onWhatsNew) {
|
|
65
|
+
onWhatsNew(notes, refresh);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
openWhatsNew({ notes, refresh, onClose: () => showUpdateAvailableToast(options) });
|
|
69
|
+
};
|
|
39
70
|
toast.message("Update available", {
|
|
40
71
|
id: toastId,
|
|
41
72
|
description: "Refresh to load the latest version.",
|
|
42
73
|
duration: Number.POSITIVE_INFINITY,
|
|
43
|
-
action: {
|
|
44
|
-
|
|
45
|
-
onClick: () => {
|
|
46
|
-
try {
|
|
47
|
-
closeConvex?.();
|
|
48
|
-
} catch {
|
|
49
|
-
}
|
|
50
|
-
reload();
|
|
51
|
-
},
|
|
52
|
-
},
|
|
74
|
+
action: { label: "Refresh", onClick: refresh },
|
|
75
|
+
...(notes.length > 0 ? { cancel: { label: "What's new", onClick: showWhatsNew } } : {}),
|
|
53
76
|
});
|
|
54
77
|
}
|
|
55
78
|
|
|
@@ -57,6 +80,10 @@ export function showUpdateAvailableToast({
|
|
|
57
80
|
* Poll the live index HTML for a new Vite asset fingerprint (and re-check when
|
|
58
81
|
* the tab becomes visible). Calls `showUpdateAvailableToast` once when a newer
|
|
59
82
|
* deploy is serving. Returns a stop function.
|
|
83
|
+
*
|
|
84
|
+
* It also reads `/release-notes.json` (written by `@vvedantb/config`'s
|
|
85
|
+
* `releaseNotes`) at the start and again when the new deploy shows. The
|
|
86
|
+
* toast offers "What's new" only for entries the running deploy lacks.
|
|
60
87
|
*/
|
|
61
88
|
export function startUpdateAvailableWatcher(
|
|
62
89
|
options: UpdateAvailableWatcherOptions,
|
|
@@ -69,17 +96,21 @@ export function startUpdateAvailableWatcher(
|
|
|
69
96
|
toastId,
|
|
70
97
|
enabled = true,
|
|
71
98
|
reload,
|
|
99
|
+
onWhatsNew,
|
|
72
100
|
} = options;
|
|
73
101
|
if (!enabled) return () => {};
|
|
74
102
|
|
|
75
103
|
let cancelled = false;
|
|
76
104
|
let shown = false;
|
|
77
105
|
let baseline: string | null = null;
|
|
106
|
+
let baselineNotes: ReleaseNote[] | null = null;
|
|
78
107
|
|
|
79
|
-
const showToast = (): void => {
|
|
108
|
+
const showToast = async (): Promise<void> => {
|
|
80
109
|
if (shown) return;
|
|
81
110
|
shown = true;
|
|
82
|
-
|
|
111
|
+
const notes = newReleaseNotes(baselineNotes, await fetchReleaseNotes(origin));
|
|
112
|
+
if (cancelled) return;
|
|
113
|
+
showUpdateAvailableToast({ toast, closeConvex, toastId, reload, onWhatsNew, notes });
|
|
83
114
|
};
|
|
84
115
|
|
|
85
116
|
const check = async (): Promise<void> => {
|
|
@@ -88,9 +119,10 @@ export function startUpdateAvailableWatcher(
|
|
|
88
119
|
if (cancelled || next === null) return;
|
|
89
120
|
if (baseline === null) {
|
|
90
121
|
baseline = next;
|
|
122
|
+
baselineNotes = await fetchReleaseNotes(origin);
|
|
91
123
|
return;
|
|
92
124
|
}
|
|
93
|
-
if (next !== baseline) showToast();
|
|
125
|
+
if (next !== baseline) await showToast();
|
|
94
126
|
};
|
|
95
127
|
|
|
96
128
|
void check();
|
package/dist/app/src/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { requestConfirm, shouldSkipConfirm } from "./confirm/confirmSkip.js";
|
|
|
3
3
|
export { useRequestConfirm } from "./confirm/useRequestConfirm.js";
|
|
4
4
|
export { ConfirmSkipHint, skipConfirmTitle } from "./confirm/ConfirmSkipHint.js";
|
|
5
5
|
export { fetchDeployFingerprint, fingerprintFromHtml } from "./update/deployFingerprint.js";
|
|
6
|
+
export { fetchReleaseNotes, newReleaseNotes } from "./update/releaseNotes.js";
|
|
6
7
|
export { showUpdateAvailableToast, startUpdateAvailableWatcher } from "./update/updateWatcher.js";
|
|
7
8
|
export { isChunkLoadError, claimStaleDeployReload, reloadForStaleDeploy, stripStaleDeployReloadParam, installStaleDeployReload, STALE_DEPLOY_RELOAD_KEY, STALE_DEPLOY_RELOAD_PARAM } from "./update/staleDeployReload.js";
|
|
8
9
|
export { SettingsSection } from "./settings/SettingsSection.js";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** One changelog entry of a deploy, from its `/release-notes.json`. */
|
|
2
|
+
|
|
3
|
+
function isReleaseNote(value) {
|
|
4
|
+
if (typeof value !== "object" || value === null) return false;
|
|
5
|
+
const note = value;
|
|
6
|
+
return typeof note.id === "string" && typeof note.date === "string" && typeof note.title === "string";
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The live deploy's `/release-notes.json` entries. Null when the deploy has
|
|
11
|
+
* no such file (an SPA fallback answers HTML) or the request fails.
|
|
12
|
+
*/
|
|
13
|
+
export async function fetchReleaseNotes(origin) {
|
|
14
|
+
try {
|
|
15
|
+
const response = await fetch(`${origin}/release-notes.json?_vb=${Date.now()}`, {
|
|
16
|
+
cache: "no-store",
|
|
17
|
+
headers: {
|
|
18
|
+
Accept: "application/json"
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
if (!response.ok) return null;
|
|
22
|
+
const body = await response.json();
|
|
23
|
+
const notes = body?.notes;
|
|
24
|
+
return Array.isArray(notes) ? notes.filter(isReleaseNote) : null;
|
|
25
|
+
} catch {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The entries of `next` that `current` does not have, in `next`'s order.
|
|
32
|
+
* Empty when either deploy has no release notes.
|
|
33
|
+
*/
|
|
34
|
+
export function newReleaseNotes(current, next) {
|
|
35
|
+
if (!current || !next) return [];
|
|
36
|
+
const seen = new Set(current.map(note => note.id));
|
|
37
|
+
return next.filter(note => !seen.has(note.id));
|
|
38
|
+
}
|
|
39
|
+
let whatsNew = null;
|
|
40
|
+
const listeners = new Set();
|
|
41
|
+
function emit() {
|
|
42
|
+
for (const listener of listeners) listener();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Open the "What's new" dialog that `SonnerToaster` renders. */
|
|
46
|
+
export function openWhatsNew(state) {
|
|
47
|
+
whatsNew = state;
|
|
48
|
+
emit();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Close the "What's new" dialog. */
|
|
52
|
+
export function closeWhatsNew() {
|
|
53
|
+
if (whatsNew === null) return;
|
|
54
|
+
whatsNew = null;
|
|
55
|
+
emit();
|
|
56
|
+
}
|
|
57
|
+
export function subscribeWhatsNew(listener) {
|
|
58
|
+
listeners.add(listener);
|
|
59
|
+
return () => {
|
|
60
|
+
listeners.delete(listener);
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
export function getWhatsNew() {
|
|
64
|
+
return whatsNew;
|
|
65
|
+
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { fetchDeployFingerprint } from "./deployFingerprint.js";
|
|
2
|
+
import { fetchReleaseNotes, newReleaseNotes, openWhatsNew } from "./releaseNotes.js";
|
|
2
3
|
const DEFAULT_POLL_MS = 60_000;
|
|
3
4
|
const DEFAULT_TOAST_ID = "app-update-available";
|
|
4
5
|
|
|
@@ -6,26 +7,51 @@ const DEFAULT_TOAST_ID = "app-update-available";
|
|
|
6
7
|
* Show the sticky "Update available" toast with a Refresh action. Refresh
|
|
7
8
|
* calls `closeConvex` (errors ignored), then reloads. The same `toastId`
|
|
8
9
|
* replaces an open toast instead of stacking a second one.
|
|
10
|
+
*
|
|
11
|
+
* With `notes`, the toast also has a "What's new" button. It calls
|
|
12
|
+
* `onWhatsNew`, else opens the dialog that `SonnerToaster` renders; closing
|
|
13
|
+
* that dialog shows the toast again.
|
|
9
14
|
*/
|
|
10
|
-
export function showUpdateAvailableToast({
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
export function showUpdateAvailableToast(options) {
|
|
16
|
+
const {
|
|
17
|
+
toast,
|
|
18
|
+
closeConvex,
|
|
19
|
+
toastId = DEFAULT_TOAST_ID,
|
|
20
|
+
reload = () => window.location.reload(),
|
|
21
|
+
onWhatsNew,
|
|
22
|
+
notes = []
|
|
23
|
+
} = options;
|
|
24
|
+
const refresh = () => {
|
|
25
|
+
try {
|
|
26
|
+
closeConvex?.();
|
|
27
|
+
} catch {}
|
|
28
|
+
reload();
|
|
29
|
+
};
|
|
30
|
+
const showWhatsNew = () => {
|
|
31
|
+
if (onWhatsNew) {
|
|
32
|
+
onWhatsNew(notes, refresh);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
openWhatsNew({
|
|
36
|
+
notes,
|
|
37
|
+
refresh,
|
|
38
|
+
onClose: () => showUpdateAvailableToast(options)
|
|
39
|
+
});
|
|
40
|
+
};
|
|
16
41
|
toast.message("Update available", {
|
|
17
42
|
id: toastId,
|
|
18
43
|
description: "Refresh to load the latest version.",
|
|
19
44
|
duration: Number.POSITIVE_INFINITY,
|
|
20
45
|
action: {
|
|
21
46
|
label: "Refresh",
|
|
22
|
-
onClick:
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
47
|
+
onClick: refresh
|
|
48
|
+
},
|
|
49
|
+
...(notes.length > 0 ? {
|
|
50
|
+
cancel: {
|
|
51
|
+
label: "What's new",
|
|
52
|
+
onClick: showWhatsNew
|
|
27
53
|
}
|
|
28
|
-
}
|
|
54
|
+
} : {})
|
|
29
55
|
});
|
|
30
56
|
}
|
|
31
57
|
|
|
@@ -33,6 +59,10 @@ export function showUpdateAvailableToast({
|
|
|
33
59
|
* Poll the live index HTML for a new Vite asset fingerprint (and re-check when
|
|
34
60
|
* the tab becomes visible). Calls `showUpdateAvailableToast` once when a newer
|
|
35
61
|
* deploy is serving. Returns a stop function.
|
|
62
|
+
*
|
|
63
|
+
* It also reads `/release-notes.json` (written by `@vvedantb/config`'s
|
|
64
|
+
* `releaseNotes`) at the start and again when the new deploy shows. The
|
|
65
|
+
* toast offers "What's new" only for entries the running deploy lacks.
|
|
36
66
|
*/
|
|
37
67
|
export function startUpdateAvailableWatcher(options) {
|
|
38
68
|
const {
|
|
@@ -42,20 +72,26 @@ export function startUpdateAvailableWatcher(options) {
|
|
|
42
72
|
pollMs = DEFAULT_POLL_MS,
|
|
43
73
|
toastId,
|
|
44
74
|
enabled = true,
|
|
45
|
-
reload
|
|
75
|
+
reload,
|
|
76
|
+
onWhatsNew
|
|
46
77
|
} = options;
|
|
47
78
|
if (!enabled) return () => {};
|
|
48
79
|
let cancelled = false;
|
|
49
80
|
let shown = false;
|
|
50
81
|
let baseline = null;
|
|
51
|
-
|
|
82
|
+
let baselineNotes = null;
|
|
83
|
+
const showToast = async () => {
|
|
52
84
|
if (shown) return;
|
|
53
85
|
shown = true;
|
|
86
|
+
const notes = newReleaseNotes(baselineNotes, await fetchReleaseNotes(origin));
|
|
87
|
+
if (cancelled) return;
|
|
54
88
|
showUpdateAvailableToast({
|
|
55
89
|
toast,
|
|
56
90
|
closeConvex,
|
|
57
91
|
toastId,
|
|
58
|
-
reload
|
|
92
|
+
reload,
|
|
93
|
+
onWhatsNew,
|
|
94
|
+
notes
|
|
59
95
|
});
|
|
60
96
|
};
|
|
61
97
|
const check = async () => {
|
|
@@ -64,9 +100,10 @@ export function startUpdateAvailableWatcher(options) {
|
|
|
64
100
|
if (cancelled || next === null) return;
|
|
65
101
|
if (baseline === null) {
|
|
66
102
|
baseline = next;
|
|
103
|
+
baselineNotes = await fetchReleaseNotes(origin);
|
|
67
104
|
return;
|
|
68
105
|
}
|
|
69
|
-
if (next !== baseline) showToast();
|
|
106
|
+
if (next !== baseline) await showToast();
|
|
70
107
|
};
|
|
71
108
|
void check();
|
|
72
109
|
const intervalId = setInterval(() => {
|
package/dist/src/client.js
CHANGED
|
@@ -175,6 +175,7 @@ export { requestConfirm, shouldSkipConfirm } from "../app/src/confirm/confirmSki
|
|
|
175
175
|
export { useRequestConfirm } from "../app/src/confirm/useRequestConfirm.js";
|
|
176
176
|
export { ConfirmSkipHint, skipConfirmTitle } from "../app/src/confirm/ConfirmSkipHint.js";
|
|
177
177
|
export { fetchDeployFingerprint, fingerprintFromHtml } from "../app/src/update/deployFingerprint.js";
|
|
178
|
+
export { fetchReleaseNotes, newReleaseNotes } from "../app/src/update/releaseNotes.js";
|
|
178
179
|
export { showUpdateAvailableToast, startUpdateAvailableWatcher } from "../app/src/update/updateWatcher.js";
|
|
179
180
|
export { isChunkLoadError, claimStaleDeployReload, reloadForStaleDeploy, stripStaleDeployReloadParam, installStaleDeployReload, STALE_DEPLOY_RELOAD_KEY, STALE_DEPLOY_RELOAD_PARAM } from "../app/src/update/staleDeployReload.js";
|
|
180
181
|
export { SettingsSection } from "../app/src/settings/SettingsSection.js";
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
2
|
import { memo } from "react";
|
|
3
3
|
import { cjk } from "@streamdown/cjk";
|
|
4
|
-
import { code } from "@streamdown/code";
|
|
5
|
-
import { math } from "@streamdown/math";
|
|
6
4
|
import { Streamdown, defaultRehypePlugins, defaultRemarkPlugins } from "streamdown";
|
|
7
5
|
import { useCn } from "../ui/ui-config.js";
|
|
8
6
|
import { parseMarkdownIntoBlocksIncremental } from "./incrementalBlocks.js";
|
|
@@ -10,18 +8,25 @@ import { MarkdownBlockquote } from "./MarkdownBlockquote.js";
|
|
|
10
8
|
import { MarkdownPre } from "./MarkdownCodeBlock.js";
|
|
11
9
|
import { MarkdownInlineCode } from "./MarkdownInlineCode.js";
|
|
12
10
|
import { MarkdownLink } from "./MarkdownLink.js";
|
|
11
|
+
import { useMathPlugin } from "./lazyMath.js";
|
|
13
12
|
import { mermaidPlugin } from "./mermaid.js";
|
|
14
13
|
import { copyMarkdownSelection } from "./markdownClipboard.js";
|
|
15
14
|
import { rehypeGithubAlerts } from "./rehypeGithubAlerts.js";
|
|
16
|
-
import "katex/dist/katex.min.css";
|
|
17
15
|
import { useSmoothText } from "./useSmoothText.js";
|
|
18
16
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
19
17
|
const PLUGINS = {
|
|
20
18
|
cjk,
|
|
21
|
-
code,
|
|
22
|
-
math,
|
|
23
19
|
mermaid: mermaidPlugin
|
|
24
20
|
};
|
|
21
|
+
let pluginsWithMath = null;
|
|
22
|
+
function pluginsFor(math) {
|
|
23
|
+
if (math === null) return PLUGINS;
|
|
24
|
+
pluginsWithMath ??= {
|
|
25
|
+
...PLUGINS,
|
|
26
|
+
math
|
|
27
|
+
};
|
|
28
|
+
return pluginsWithMath;
|
|
29
|
+
}
|
|
25
30
|
const REMARK_PLUGINS = Object.values(defaultRemarkPlugins);
|
|
26
31
|
const REHYPE_PLUGINS = [...Object.values(defaultRehypePlugins), rehypeGithubAlerts];
|
|
27
32
|
const MARKDOWN_COMPONENTS = {
|
|
@@ -55,7 +60,7 @@ const MARKDOWN_COMPONENTS = {
|
|
|
55
60
|
* (mention chips, line breaks).
|
|
56
61
|
*/
|
|
57
62
|
export const Markdown = /*#__PURE__*/memo(function Markdown(t0) {
|
|
58
|
-
const $ = _c(
|
|
63
|
+
const $ = _c(23);
|
|
59
64
|
let children;
|
|
60
65
|
let className;
|
|
61
66
|
let components;
|
|
@@ -89,6 +94,7 @@ export const Markdown = /*#__PURE__*/memo(function Markdown(t0) {
|
|
|
89
94
|
const smooth = t1 === undefined ? true : t1;
|
|
90
95
|
const merge = useCn();
|
|
91
96
|
const text = useSmoothText(children, smooth && props.mode === "streaming");
|
|
97
|
+
const math = useMathPlugin(text);
|
|
92
98
|
let t2;
|
|
93
99
|
if ($[7] !== className || $[8] !== merge) {
|
|
94
100
|
t2 = merge("markdown", className);
|
|
@@ -99,48 +105,57 @@ export const Markdown = /*#__PURE__*/memo(function Markdown(t0) {
|
|
|
99
105
|
t2 = $[9];
|
|
100
106
|
}
|
|
101
107
|
let t3;
|
|
102
|
-
if ($[10] !==
|
|
103
|
-
t3 =
|
|
104
|
-
|
|
105
|
-
...components
|
|
106
|
-
} : MARKDOWN_COMPONENTS;
|
|
107
|
-
$[10] = components;
|
|
108
|
+
if ($[10] !== math) {
|
|
109
|
+
t3 = pluginsFor(math);
|
|
110
|
+
$[10] = math;
|
|
108
111
|
$[11] = t3;
|
|
109
112
|
} else {
|
|
110
113
|
t3 = $[11];
|
|
111
114
|
}
|
|
112
115
|
let t4;
|
|
113
|
-
if ($[12] !==
|
|
114
|
-
t4 =
|
|
115
|
-
|
|
116
|
+
if ($[12] !== components) {
|
|
117
|
+
t4 = components ? {
|
|
118
|
+
...MARKDOWN_COMPONENTS,
|
|
119
|
+
...components
|
|
120
|
+
} : MARKDOWN_COMPONENTS;
|
|
121
|
+
$[12] = components;
|
|
116
122
|
$[13] = t4;
|
|
117
123
|
} else {
|
|
118
124
|
t4 = $[13];
|
|
119
125
|
}
|
|
120
126
|
let t5;
|
|
121
|
-
if ($[14] !==
|
|
122
|
-
t5 =
|
|
127
|
+
if ($[14] !== remarkPlugins) {
|
|
128
|
+
t5 = remarkPlugins ? [...REMARK_PLUGINS, ...remarkPlugins] : REMARK_PLUGINS;
|
|
129
|
+
$[14] = remarkPlugins;
|
|
130
|
+
$[15] = t5;
|
|
131
|
+
} else {
|
|
132
|
+
t5 = $[15];
|
|
133
|
+
}
|
|
134
|
+
let t6;
|
|
135
|
+
if ($[16] !== props || $[17] !== t2 || $[18] !== t3 || $[19] !== t4 || $[20] !== t5 || $[21] !== text) {
|
|
136
|
+
t6 = /*#__PURE__*/_jsx("div", {
|
|
123
137
|
className: "contents",
|
|
124
138
|
onCopy: copyMarkdownSelection,
|
|
125
139
|
children: /*#__PURE__*/_jsx(Streamdown, {
|
|
126
140
|
className: t2,
|
|
127
|
-
plugins:
|
|
128
|
-
components:
|
|
129
|
-
remarkPlugins:
|
|
141
|
+
plugins: t3,
|
|
142
|
+
components: t4,
|
|
143
|
+
remarkPlugins: t5,
|
|
130
144
|
rehypePlugins: REHYPE_PLUGINS,
|
|
131
145
|
parseMarkdownIntoBlocksFn: parseMarkdownIntoBlocksIncremental,
|
|
132
146
|
...props,
|
|
133
147
|
children: text
|
|
134
148
|
})
|
|
135
149
|
});
|
|
136
|
-
$[
|
|
137
|
-
$[
|
|
138
|
-
$[
|
|
139
|
-
$[
|
|
140
|
-
$[
|
|
141
|
-
$[
|
|
150
|
+
$[16] = props;
|
|
151
|
+
$[17] = t2;
|
|
152
|
+
$[18] = t3;
|
|
153
|
+
$[19] = t4;
|
|
154
|
+
$[20] = t5;
|
|
155
|
+
$[21] = text;
|
|
156
|
+
$[22] = t6;
|
|
142
157
|
} else {
|
|
143
|
-
|
|
158
|
+
t6 = $[22];
|
|
144
159
|
}
|
|
145
|
-
return
|
|
160
|
+
return t6;
|
|
146
161
|
});
|
|
@@ -1,8 +1,26 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
|
-
import { code as shiki } from "@streamdown/code";
|
|
3
2
|
import { useState, useSyncExternalStore } from "react";
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
let engine = null;
|
|
4
|
+
let loading = null;
|
|
5
|
+
const engineListeners = new Set();
|
|
6
|
+
function subscribeEngine(notify) {
|
|
7
|
+
engineListeners.add(notify);
|
|
8
|
+
return () => engineListeners.delete(notify);
|
|
9
|
+
}
|
|
10
|
+
function loadEngine() {
|
|
11
|
+
loading ??= import("@streamdown/code").then(({
|
|
12
|
+
code: shiki
|
|
13
|
+
}) => {
|
|
14
|
+
engine = {
|
|
15
|
+
shiki,
|
|
16
|
+
themes: shiki.getThemes(),
|
|
17
|
+
languages: new Map(shiki.getSupportedLanguages().map(id => [id, id]))
|
|
18
|
+
};
|
|
19
|
+
for (const notify of engineListeners) notify();
|
|
20
|
+
}, () => {
|
|
21
|
+
loading = null;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
6
24
|
const CACHE_LIMIT = 200;
|
|
7
25
|
const cache = new Map();
|
|
8
26
|
const listeners = new Map();
|
|
@@ -16,7 +34,10 @@ function store(key, entry) {
|
|
|
16
34
|
const oldest = cache.keys().next().value;
|
|
17
35
|
if (oldest !== undefined && !listeners.has(oldest)) cache.delete(oldest);
|
|
18
36
|
}
|
|
19
|
-
function request(
|
|
37
|
+
function request({
|
|
38
|
+
shiki,
|
|
39
|
+
themes
|
|
40
|
+
}, language, source) {
|
|
20
41
|
const key = cacheKey(language, source);
|
|
21
42
|
const hit = cache.get(key);
|
|
22
43
|
if (hit !== undefined) return hit.status === "done" ? hit.result : null;
|
|
@@ -26,7 +47,7 @@ function request(language, source) {
|
|
|
26
47
|
const sync = shiki.highlight({
|
|
27
48
|
code: source,
|
|
28
49
|
language,
|
|
29
|
-
themes
|
|
50
|
+
themes
|
|
30
51
|
}, result => {
|
|
31
52
|
store(key, {
|
|
32
53
|
status: "done",
|
|
@@ -82,42 +103,48 @@ export function buildCodeLines(code, highlighted) {
|
|
|
82
103
|
* for), so streaming never flashes back to plain text.
|
|
83
104
|
*/
|
|
84
105
|
export function useHighlightedLines(code, language, isIncomplete) {
|
|
85
|
-
const $ = _c(
|
|
106
|
+
const $ = _c(20);
|
|
107
|
+
const loaded = useSyncExternalStore(subscribeEngine, _temp, _temp2);
|
|
108
|
+
if (loaded === null && language !== "") {
|
|
109
|
+
loadEngine();
|
|
110
|
+
}
|
|
86
111
|
let bundled;
|
|
87
112
|
let source;
|
|
88
113
|
let t0;
|
|
89
|
-
if ($[0] !== code || $[1] !== isIncomplete || $[2] !== language) {
|
|
90
|
-
bundled =
|
|
114
|
+
if ($[0] !== code || $[1] !== isIncomplete || $[2] !== language || $[3] !== loaded?.languages) {
|
|
115
|
+
bundled = loaded?.languages.get(language.toLowerCase()) ?? null;
|
|
91
116
|
source = bundled === null ? "" : highlightSource(code, isIncomplete);
|
|
92
117
|
t0 = bundled === null ? "" : cacheKey(bundled, source);
|
|
93
118
|
$[0] = code;
|
|
94
119
|
$[1] = isIncomplete;
|
|
95
120
|
$[2] = language;
|
|
96
|
-
$[3] =
|
|
97
|
-
$[4] =
|
|
98
|
-
$[5] =
|
|
121
|
+
$[3] = loaded?.languages;
|
|
122
|
+
$[4] = bundled;
|
|
123
|
+
$[5] = source;
|
|
124
|
+
$[6] = t0;
|
|
99
125
|
} else {
|
|
100
|
-
bundled = $[
|
|
101
|
-
source = $[
|
|
102
|
-
t0 = $[
|
|
126
|
+
bundled = $[4];
|
|
127
|
+
source = $[5];
|
|
128
|
+
t0 = $[6];
|
|
103
129
|
}
|
|
104
130
|
const key = t0;
|
|
105
131
|
let t1;
|
|
106
|
-
if ($[
|
|
107
|
-
t1 = notify => key === "" ?
|
|
108
|
-
$[
|
|
109
|
-
$[
|
|
132
|
+
if ($[7] !== key) {
|
|
133
|
+
t1 = notify => key === "" ? _temp3 : subscribe(key, notify);
|
|
134
|
+
$[7] = key;
|
|
135
|
+
$[8] = t1;
|
|
110
136
|
} else {
|
|
111
|
-
t1 = $[
|
|
137
|
+
t1 = $[8];
|
|
112
138
|
}
|
|
113
139
|
let t2;
|
|
114
|
-
if ($[
|
|
115
|
-
t2 = () => bundled === null || source === "" ? null : request(bundled, source);
|
|
116
|
-
$[
|
|
117
|
-
$[
|
|
118
|
-
$[
|
|
140
|
+
if ($[9] !== bundled || $[10] !== loaded || $[11] !== source) {
|
|
141
|
+
t2 = () => loaded === null || bundled === null || source === "" ? null : request(loaded, bundled, source);
|
|
142
|
+
$[9] = bundled;
|
|
143
|
+
$[10] = loaded;
|
|
144
|
+
$[11] = source;
|
|
145
|
+
$[12] = t2;
|
|
119
146
|
} else {
|
|
120
|
-
t2 = $[
|
|
147
|
+
t2 = $[12];
|
|
121
148
|
}
|
|
122
149
|
const result = useSyncExternalStore(t1, t2);
|
|
123
150
|
const [shown, setShown] = useState(null);
|
|
@@ -128,27 +155,33 @@ export function useHighlightedLines(code, language, isIncomplete) {
|
|
|
128
155
|
});
|
|
129
156
|
}
|
|
130
157
|
let t3;
|
|
131
|
-
if ($[
|
|
158
|
+
if ($[13] !== result || $[14] !== shown || $[15] !== source) {
|
|
132
159
|
t3 = result !== null ? {
|
|
133
160
|
source,
|
|
134
161
|
result
|
|
135
162
|
} : shown;
|
|
136
|
-
$[
|
|
137
|
-
$[
|
|
138
|
-
$[
|
|
139
|
-
$[
|
|
163
|
+
$[13] = result;
|
|
164
|
+
$[14] = shown;
|
|
165
|
+
$[15] = source;
|
|
166
|
+
$[16] = t3;
|
|
140
167
|
} else {
|
|
141
|
-
t3 = $[
|
|
168
|
+
t3 = $[16];
|
|
142
169
|
}
|
|
143
170
|
let t4;
|
|
144
|
-
if ($[
|
|
171
|
+
if ($[17] !== code || $[18] !== t3) {
|
|
145
172
|
t4 = buildCodeLines(code, t3);
|
|
146
|
-
$[
|
|
147
|
-
$[
|
|
148
|
-
$[
|
|
173
|
+
$[17] = code;
|
|
174
|
+
$[18] = t3;
|
|
175
|
+
$[19] = t4;
|
|
149
176
|
} else {
|
|
150
|
-
t4 = $[
|
|
177
|
+
t4 = $[19];
|
|
151
178
|
}
|
|
152
179
|
return t4;
|
|
153
180
|
}
|
|
154
|
-
function
|
|
181
|
+
function _temp3() {}
|
|
182
|
+
function _temp2() {
|
|
183
|
+
return engine;
|
|
184
|
+
}
|
|
185
|
+
function _temp() {
|
|
186
|
+
return engine;
|
|
187
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
const MATH_HINT = /\$\$|```math/;
|
|
3
|
+
let math = null;
|
|
4
|
+
let loading = null;
|
|
5
|
+
const listeners = new Set();
|
|
6
|
+
function subscribe(notify) {
|
|
7
|
+
listeners.add(notify);
|
|
8
|
+
return () => listeners.delete(notify);
|
|
9
|
+
}
|
|
10
|
+
function load() {
|
|
11
|
+
loading ??= import("./mathPlugin.js").then(module => {
|
|
12
|
+
math = module.math;
|
|
13
|
+
for (const notify of listeners) notify();
|
|
14
|
+
}, () => {
|
|
15
|
+
loading = null;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* KaTeX and its CSS load on the first text that holds `$$` or a `math`
|
|
21
|
+
* fence (single `$` is off), so pages without maths never fetch them.
|
|
22
|
+
*/
|
|
23
|
+
export function useMathPlugin(text) {
|
|
24
|
+
const loaded = useSyncExternalStore(subscribe, _temp, _temp2);
|
|
25
|
+
const needed = MATH_HINT.test(text);
|
|
26
|
+
if (needed && loaded === null) {
|
|
27
|
+
load();
|
|
28
|
+
}
|
|
29
|
+
return needed ? loaded : null;
|
|
30
|
+
}
|
|
31
|
+
function _temp2() {
|
|
32
|
+
return math;
|
|
33
|
+
}
|
|
34
|
+
function _temp() {
|
|
35
|
+
return math;
|
|
36
|
+
}
|
package/dist/src/ui/sonner.js
CHANGED
|
@@ -3,7 +3,8 @@ import { Toaster as SonnerPrimitive } from "sonner";
|
|
|
3
3
|
import { filledToastIcons } from "./sonner-icons.js";
|
|
4
4
|
import { useUiConfig } from "./ui-config.js";
|
|
5
5
|
import "./sonner.css";
|
|
6
|
-
import {
|
|
6
|
+
import { WhatsNewDialog } from "./whats-new-dialog.js";
|
|
7
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
8
|
const defaultToasterClassName = "toaster group !font-sans";
|
|
8
9
|
const hideStackedContentClassName = "[&[data-expanded=false][data-front=false]>*]:opacity-0";
|
|
9
10
|
const hoverChipCloseButtonClassName = "pointer-events-none absolute -right-2 -top-2 z-10 flex h-6 w-6 items-center justify-center rounded-full border border-border bg-card/95 text-muted-foreground opacity-0 transition-opacity hover:border-border! hover:text-foreground focus-visible:pointer-events-auto focus-visible:opacity-100 focus-visible:outline-hidden focus-visible:ring-2 focus-visible:ring-ring group-hover:pointer-events-auto group-hover:opacity-100 max-sm:pointer-events-auto max-sm:opacity-100 max-sm:hit-target";
|
|
@@ -97,7 +98,7 @@ function withConfigDefaults(defaults, props) {
|
|
|
97
98
|
return merged;
|
|
98
99
|
}
|
|
99
100
|
function SonnerToaster(props) {
|
|
100
|
-
const $ = _c(
|
|
101
|
+
const $ = _c(13);
|
|
101
102
|
const {
|
|
102
103
|
classes,
|
|
103
104
|
position: t0,
|
|
@@ -188,7 +189,24 @@ function SonnerToaster(props) {
|
|
|
188
189
|
} else {
|
|
189
190
|
t13 = $[9];
|
|
190
191
|
}
|
|
191
|
-
|
|
192
|
+
let t14;
|
|
193
|
+
if ($[10] === Symbol.for("react.memo_cache_sentinel")) {
|
|
194
|
+
t14 = /*#__PURE__*/_jsx(WhatsNewDialog, {});
|
|
195
|
+
$[10] = t14;
|
|
196
|
+
} else {
|
|
197
|
+
t14 = $[10];
|
|
198
|
+
}
|
|
199
|
+
let t15;
|
|
200
|
+
if ($[11] !== t13) {
|
|
201
|
+
t15 = /*#__PURE__*/_jsxs(_Fragment, {
|
|
202
|
+
children: [t13, t14]
|
|
203
|
+
});
|
|
204
|
+
$[11] = t13;
|
|
205
|
+
$[12] = t15;
|
|
206
|
+
} else {
|
|
207
|
+
t15 = $[12];
|
|
208
|
+
}
|
|
209
|
+
return t15;
|
|
192
210
|
}
|
|
193
211
|
export { SonnerToaster, createToasterClassNames, hoverChipCloseButtonClassName, mergeToastClassNames, mergeToastOptions, mergeToasterStyle, sonnerVarsStyle };
|
|
194
212
|
export { filledToastIcons } from "./sonner-icons.js";
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { c as _c } from "react/compiler-runtime";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
import { closeWhatsNew, getWhatsNew, subscribeWhatsNew } from "../../app/src/update/releaseNotes.js";
|
|
4
|
+
import { Button } from "./button.js";
|
|
5
|
+
import { Dialog, DialogBody, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "./dialog.js";
|
|
6
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
7
|
+
const getServerSnapshot = () => null;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The "What's new" dialog of the update toast: the changelog titles that the
|
|
11
|
+
* new deploy adds, with Refresh. `SonnerToaster` renders it.
|
|
12
|
+
*/
|
|
13
|
+
export function WhatsNewDialog() {
|
|
14
|
+
const $ = _c(23);
|
|
15
|
+
const state = useSyncExternalStore(subscribeWhatsNew, getWhatsNew, getServerSnapshot);
|
|
16
|
+
let t0;
|
|
17
|
+
if ($[0] !== state) {
|
|
18
|
+
t0 = () => {
|
|
19
|
+
if (!state) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
closeWhatsNew();
|
|
23
|
+
state.onClose();
|
|
24
|
+
};
|
|
25
|
+
$[0] = state;
|
|
26
|
+
$[1] = t0;
|
|
27
|
+
} else {
|
|
28
|
+
t0 = $[1];
|
|
29
|
+
}
|
|
30
|
+
const close = t0;
|
|
31
|
+
const t1 = state !== null;
|
|
32
|
+
let t2;
|
|
33
|
+
if ($[2] !== close) {
|
|
34
|
+
t2 = open => open ? undefined : close();
|
|
35
|
+
$[2] = close;
|
|
36
|
+
$[3] = t2;
|
|
37
|
+
} else {
|
|
38
|
+
t2 = $[3];
|
|
39
|
+
}
|
|
40
|
+
let t3;
|
|
41
|
+
if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
|
|
42
|
+
t3 = /*#__PURE__*/_jsxs(DialogHeader, {
|
|
43
|
+
children: [/*#__PURE__*/_jsx(DialogTitle, {
|
|
44
|
+
children: "What's new"
|
|
45
|
+
}), /*#__PURE__*/_jsx(DialogDescription, {
|
|
46
|
+
children: "Refresh to load the latest version."
|
|
47
|
+
})]
|
|
48
|
+
});
|
|
49
|
+
$[4] = t3;
|
|
50
|
+
} else {
|
|
51
|
+
t3 = $[4];
|
|
52
|
+
}
|
|
53
|
+
let t4;
|
|
54
|
+
if ($[5] !== state?.notes) {
|
|
55
|
+
t4 = state?.notes.map(_temp);
|
|
56
|
+
$[5] = state?.notes;
|
|
57
|
+
$[6] = t4;
|
|
58
|
+
} else {
|
|
59
|
+
t4 = $[6];
|
|
60
|
+
}
|
|
61
|
+
let t5;
|
|
62
|
+
if ($[7] !== t4) {
|
|
63
|
+
t5 = /*#__PURE__*/_jsx(DialogBody, {
|
|
64
|
+
children: /*#__PURE__*/_jsx("ul", {
|
|
65
|
+
className: "list-disc space-y-1.5 pl-5 text-sm",
|
|
66
|
+
children: t4
|
|
67
|
+
})
|
|
68
|
+
});
|
|
69
|
+
$[7] = t4;
|
|
70
|
+
$[8] = t5;
|
|
71
|
+
} else {
|
|
72
|
+
t5 = $[8];
|
|
73
|
+
}
|
|
74
|
+
let t6;
|
|
75
|
+
if ($[9] !== close) {
|
|
76
|
+
t6 = /*#__PURE__*/_jsx(Button, {
|
|
77
|
+
variant: "outline",
|
|
78
|
+
onClick: close,
|
|
79
|
+
children: "Later"
|
|
80
|
+
});
|
|
81
|
+
$[9] = close;
|
|
82
|
+
$[10] = t6;
|
|
83
|
+
} else {
|
|
84
|
+
t6 = $[10];
|
|
85
|
+
}
|
|
86
|
+
let t7;
|
|
87
|
+
if ($[11] !== state) {
|
|
88
|
+
t7 = /*#__PURE__*/_jsx(Button, {
|
|
89
|
+
onClick: () => {
|
|
90
|
+
closeWhatsNew();
|
|
91
|
+
state?.refresh();
|
|
92
|
+
},
|
|
93
|
+
children: "Refresh"
|
|
94
|
+
});
|
|
95
|
+
$[11] = state;
|
|
96
|
+
$[12] = t7;
|
|
97
|
+
} else {
|
|
98
|
+
t7 = $[12];
|
|
99
|
+
}
|
|
100
|
+
let t8;
|
|
101
|
+
if ($[13] !== t6 || $[14] !== t7) {
|
|
102
|
+
t8 = /*#__PURE__*/_jsxs(DialogFooter, {
|
|
103
|
+
children: [t6, t7]
|
|
104
|
+
});
|
|
105
|
+
$[13] = t6;
|
|
106
|
+
$[14] = t7;
|
|
107
|
+
$[15] = t8;
|
|
108
|
+
} else {
|
|
109
|
+
t8 = $[15];
|
|
110
|
+
}
|
|
111
|
+
let t9;
|
|
112
|
+
if ($[16] !== t5 || $[17] !== t8) {
|
|
113
|
+
t9 = /*#__PURE__*/_jsxs(DialogContent, {
|
|
114
|
+
children: [t3, t5, t8]
|
|
115
|
+
});
|
|
116
|
+
$[16] = t5;
|
|
117
|
+
$[17] = t8;
|
|
118
|
+
$[18] = t9;
|
|
119
|
+
} else {
|
|
120
|
+
t9 = $[18];
|
|
121
|
+
}
|
|
122
|
+
let t10;
|
|
123
|
+
if ($[19] !== t1 || $[20] !== t2 || $[21] !== t9) {
|
|
124
|
+
t10 = /*#__PURE__*/_jsx(Dialog, {
|
|
125
|
+
open: t1,
|
|
126
|
+
onOpenChange: t2,
|
|
127
|
+
children: t9
|
|
128
|
+
});
|
|
129
|
+
$[19] = t1;
|
|
130
|
+
$[20] = t2;
|
|
131
|
+
$[21] = t9;
|
|
132
|
+
$[22] = t10;
|
|
133
|
+
} else {
|
|
134
|
+
t10 = $[22];
|
|
135
|
+
}
|
|
136
|
+
return t10;
|
|
137
|
+
}
|
|
138
|
+
function _temp(note) {
|
|
139
|
+
return /*#__PURE__*/_jsx("li", {
|
|
140
|
+
children: note.title
|
|
141
|
+
}, note.id);
|
|
142
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.86.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared React 19 UI for web apps: one main JavaScript entry (primitives, shell pieces, app helpers including the Convex and Clerk provider, VITE env parsing and ensure-user, artifact viewers over the @vvedantb/server artifacts core, native tokens), third-party brand logos (also @vvedantb/ui/logos), motion-driven animated SVG icons (@vvedantb/ui/icons/animated), a client entry without @vvedantb/server, convex or Clerk for Chrome extensions, design-token CSS, shared Tailwind v4 CSS, a Tailwind preset and packaged Instrument Sans fonts.",
|
|
6
6
|
"type": "module",
|
|
@@ -246,6 +246,7 @@
|
|
|
246
246
|
"check:tokens": "node tokens/scripts/check-component-tokens.mjs",
|
|
247
247
|
"build": "node scripts/build-dist.mjs && node tokens/scripts/check-exports.mjs && node tokens/scripts/check-component-tokens.mjs && tsrs -p tsconfig.json",
|
|
248
248
|
"typecheck": "tsrs --noEmit --fast -p tsconfig.json && tsrs --noEmit --fast -p tsconfig.consumer.json && tsrs --noEmit --fast -p tsconfig.consumer-speech.json && tsrs --noEmit --fast -p tokens/tsconfig.json",
|
|
249
|
+
"lint": "oxlint -c .oxlintrc.json shell src app",
|
|
249
250
|
"test": "node tokens/scripts/check-component-tokens.mjs && vitest run && node --test tokens/test/*.test.mjs app/tests-node/*.test.mjs",
|
|
250
251
|
"verify": "node tokens/scripts/check-component-tokens.mjs && node tokens/verify/run.mjs",
|
|
251
252
|
"analyze": "node tokens/verify/analyze.mjs",
|
package/src/client.ts
CHANGED
|
@@ -373,6 +373,11 @@ export { requestConfirm, shouldSkipConfirm } from "../app/src/confirm/confirmSki
|
|
|
373
373
|
export { useRequestConfirm } from "../app/src/confirm/useRequestConfirm";
|
|
374
374
|
export { ConfirmSkipHint, skipConfirmTitle } from "../app/src/confirm/ConfirmSkipHint";
|
|
375
375
|
export { fetchDeployFingerprint, fingerprintFromHtml } from "../app/src/update/deployFingerprint";
|
|
376
|
+
export {
|
|
377
|
+
fetchReleaseNotes,
|
|
378
|
+
newReleaseNotes,
|
|
379
|
+
type ReleaseNote,
|
|
380
|
+
} from "../app/src/update/releaseNotes";
|
|
376
381
|
export {
|
|
377
382
|
showUpdateAvailableToast,
|
|
378
383
|
startUpdateAvailableWatcher,
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import type { ComponentProps } from "react";
|
|
2
2
|
import { memo } from "react";
|
|
3
3
|
import { cjk } from "@streamdown/cjk";
|
|
4
|
-
import {
|
|
5
|
-
import { math } from "@streamdown/math";
|
|
6
|
-
import type { Components } from "streamdown";
|
|
4
|
+
import type { Components, MathPlugin } from "streamdown";
|
|
7
5
|
import {
|
|
8
6
|
Streamdown,
|
|
9
7
|
defaultRehypePlugins,
|
|
@@ -16,13 +14,20 @@ import { MarkdownBlockquote } from "./MarkdownBlockquote";
|
|
|
16
14
|
import { MarkdownPre } from "./MarkdownCodeBlock";
|
|
17
15
|
import { MarkdownInlineCode } from "./MarkdownInlineCode";
|
|
18
16
|
import { MarkdownLink } from "./MarkdownLink";
|
|
17
|
+
import { useMathPlugin } from "./lazyMath";
|
|
19
18
|
import { mermaidPlugin } from "./mermaid";
|
|
20
19
|
import { copyMarkdownSelection } from "./markdownClipboard";
|
|
21
20
|
import { rehypeGithubAlerts } from "./rehypeGithubAlerts";
|
|
22
|
-
import "katex/dist/katex.min.css";
|
|
23
21
|
import { useSmoothText } from "./useSmoothText";
|
|
24
22
|
|
|
25
|
-
const PLUGINS = { cjk,
|
|
23
|
+
const PLUGINS = { cjk, mermaid: mermaidPlugin };
|
|
24
|
+
let pluginsWithMath: typeof PLUGINS & { math: MathPlugin } | null = null;
|
|
25
|
+
|
|
26
|
+
function pluginsFor(math: MathPlugin | null) {
|
|
27
|
+
if (math === null) return PLUGINS;
|
|
28
|
+
pluginsWithMath ??= { ...PLUGINS, math };
|
|
29
|
+
return pluginsWithMath;
|
|
30
|
+
}
|
|
26
31
|
|
|
27
32
|
const REMARK_PLUGINS = Object.values(defaultRemarkPlugins);
|
|
28
33
|
const REHYPE_PLUGINS = [...Object.values(defaultRehypePlugins), rehypeGithubAlerts];
|
|
@@ -76,11 +81,12 @@ export const Markdown = memo(function Markdown({
|
|
|
76
81
|
}: MarkdownProps) {
|
|
77
82
|
const merge = useCn();
|
|
78
83
|
const text = useSmoothText(children, smooth && props.mode === "streaming");
|
|
84
|
+
const math = useMathPlugin(text);
|
|
79
85
|
return (
|
|
80
86
|
<div className="contents" onCopy={copyMarkdownSelection}>
|
|
81
87
|
<Streamdown
|
|
82
88
|
className={merge("markdown", className)}
|
|
83
|
-
plugins={
|
|
89
|
+
plugins={pluginsFor(math)}
|
|
84
90
|
components={
|
|
85
91
|
components ? { ...MARKDOWN_COMPONENTS, ...components } : MARKDOWN_COMPONENTS
|
|
86
92
|
}
|
|
@@ -1,15 +1,42 @@
|
|
|
1
|
-
import { code as shiki } from "@streamdown/code";
|
|
2
1
|
import { useState, useSyncExternalStore } from "react";
|
|
3
2
|
import type { CodeHighlighterPlugin } from "streamdown";
|
|
4
3
|
|
|
5
|
-
type
|
|
4
|
+
type Shiki = (typeof import("@streamdown/code"))["code"];
|
|
5
|
+
type BundledLanguage = ReturnType<Shiki["getSupportedLanguages"]>[number];
|
|
6
6
|
type HighlightResult = NonNullable<ReturnType<CodeHighlighterPlugin["highlight"]>>;
|
|
7
7
|
export type HighlightToken = HighlightResult["tokens"][number][number];
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
type Engine = {
|
|
10
|
+
shiki: Shiki;
|
|
11
|
+
themes: ReturnType<Shiki["getThemes"]>;
|
|
12
|
+
languages: Map<string, BundledLanguage>;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
let engine: Engine | null = null;
|
|
16
|
+
let loading: Promise<void> | null = null;
|
|
17
|
+
const engineListeners = new Set<() => void>();
|
|
18
|
+
|
|
19
|
+
function subscribeEngine(notify: () => void): () => void {
|
|
20
|
+
engineListeners.add(notify);
|
|
21
|
+
return () => engineListeners.delete(notify);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function loadEngine(): void {
|
|
25
|
+
loading ??= import("@streamdown/code").then(
|
|
26
|
+
({ code: shiki }) => {
|
|
27
|
+
engine = {
|
|
28
|
+
shiki,
|
|
29
|
+
themes: shiki.getThemes(),
|
|
30
|
+
languages: new Map(shiki.getSupportedLanguages().map((id) => [id, id])),
|
|
31
|
+
};
|
|
32
|
+
for (const notify of engineListeners) notify();
|
|
33
|
+
},
|
|
34
|
+
() => {
|
|
35
|
+
loading = null;
|
|
36
|
+
},
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
13
40
|
const CACHE_LIMIT = 200;
|
|
14
41
|
|
|
15
42
|
type Entry = { status: "pending" } | { status: "done"; result: HighlightResult };
|
|
@@ -29,14 +56,18 @@ function store(key: string, entry: Entry): void {
|
|
|
29
56
|
if (oldest !== undefined && !listeners.has(oldest)) cache.delete(oldest);
|
|
30
57
|
}
|
|
31
58
|
|
|
32
|
-
function request(
|
|
59
|
+
function request(
|
|
60
|
+
{ shiki, themes }: Engine,
|
|
61
|
+
language: BundledLanguage,
|
|
62
|
+
source: string,
|
|
63
|
+
): HighlightResult | null {
|
|
33
64
|
const key = cacheKey(language, source);
|
|
34
65
|
const hit = cache.get(key);
|
|
35
66
|
if (hit !== undefined) return hit.status === "done" ? hit.result : null;
|
|
36
67
|
|
|
37
68
|
store(key, { status: "pending" });
|
|
38
69
|
const sync = shiki.highlight(
|
|
39
|
-
{ code: source, language, themes
|
|
70
|
+
{ code: source, language, themes },
|
|
40
71
|
(result) => {
|
|
41
72
|
store(key, { status: "done", result });
|
|
42
73
|
for (const notify of listeners.get(key) ?? []) notify();
|
|
@@ -101,13 +132,18 @@ export function useHighlightedLines(
|
|
|
101
132
|
language: string,
|
|
102
133
|
isIncomplete: boolean,
|
|
103
134
|
): CodeLine[] {
|
|
104
|
-
const
|
|
135
|
+
const loaded = useSyncExternalStore(subscribeEngine, () => engine, () => engine);
|
|
136
|
+
if (loaded === null && language !== "") loadEngine();
|
|
137
|
+
const bundled = loaded?.languages.get(language.toLowerCase()) ?? null;
|
|
105
138
|
const source = bundled === null ? "" : highlightSource(code, isIncomplete);
|
|
106
139
|
const key = bundled === null ? "" : cacheKey(bundled, source);
|
|
107
140
|
|
|
108
141
|
const result = useSyncExternalStore(
|
|
109
142
|
(notify) => (key === "" ? () => {} : subscribe(key, notify)),
|
|
110
|
-
() =>
|
|
143
|
+
() =>
|
|
144
|
+
loaded === null || bundled === null || source === ""
|
|
145
|
+
? null
|
|
146
|
+
: request(loaded, bundled, source),
|
|
111
147
|
);
|
|
112
148
|
|
|
113
149
|
const [shown, setShown] = useState<{
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
import type { MathPlugin } from "streamdown";
|
|
3
|
+
|
|
4
|
+
const MATH_HINT = /\$\$|```math/;
|
|
5
|
+
|
|
6
|
+
let math: MathPlugin | null = null;
|
|
7
|
+
let loading: Promise<void> | null = null;
|
|
8
|
+
const listeners = new Set<() => void>();
|
|
9
|
+
|
|
10
|
+
function subscribe(notify: () => void): () => void {
|
|
11
|
+
listeners.add(notify);
|
|
12
|
+
return () => listeners.delete(notify);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function load(): void {
|
|
16
|
+
loading ??= import("./mathPlugin").then(
|
|
17
|
+
(module) => {
|
|
18
|
+
math = module.math;
|
|
19
|
+
for (const notify of listeners) notify();
|
|
20
|
+
},
|
|
21
|
+
() => {
|
|
22
|
+
loading = null;
|
|
23
|
+
},
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* KaTeX and its CSS load on the first text that holds `$$` or a `math`
|
|
29
|
+
* fence (single `$` is off), so pages without maths never fetch them.
|
|
30
|
+
*/
|
|
31
|
+
export function useMathPlugin(text: string): MathPlugin | null {
|
|
32
|
+
const loaded = useSyncExternalStore(subscribe, () => math, () => math);
|
|
33
|
+
const needed = MATH_HINT.test(text);
|
|
34
|
+
if (needed && loaded === null) load();
|
|
35
|
+
return needed ? loaded : null;
|
|
36
|
+
}
|
package/src/ui/sonner.tsx
CHANGED
|
@@ -3,6 +3,7 @@ import { Toaster as SonnerPrimitive, type ToasterProps } from "sonner";
|
|
|
3
3
|
import { filledToastIcons } from "./sonner-icons";
|
|
4
4
|
import { useUiConfig } from "./ui-config";
|
|
5
5
|
import "./sonner.css";
|
|
6
|
+
import { WhatsNewDialog } from "./whats-new-dialog";
|
|
6
7
|
|
|
7
8
|
type ToastClassNames = NonNullable<
|
|
8
9
|
NonNullable<ToasterProps["toastOptions"]>["classNames"]
|
|
@@ -178,6 +179,7 @@ function SonnerToaster(props: ToasterProps & SonnerToasterOptions) {
|
|
|
178
179
|
? { ...loadingOverride, ...icons }
|
|
179
180
|
: icons;
|
|
180
181
|
return (
|
|
182
|
+
<>
|
|
181
183
|
<SonnerPrimitive
|
|
182
184
|
expand={false}
|
|
183
185
|
visibleToasts={4}
|
|
@@ -211,6 +213,8 @@ function SonnerToaster(props: ToasterProps & SonnerToasterOptions) {
|
|
|
211
213
|
toastOptions,
|
|
212
214
|
)}
|
|
213
215
|
/>
|
|
216
|
+
<WhatsNewDialog />
|
|
217
|
+
</>
|
|
214
218
|
);
|
|
215
219
|
}
|
|
216
220
|
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
import {
|
|
3
|
+
closeWhatsNew,
|
|
4
|
+
getWhatsNew,
|
|
5
|
+
subscribeWhatsNew,
|
|
6
|
+
type WhatsNewState,
|
|
7
|
+
} from "../../app/src/update/releaseNotes";
|
|
8
|
+
import { Button } from "./button";
|
|
9
|
+
import {
|
|
10
|
+
Dialog,
|
|
11
|
+
DialogBody,
|
|
12
|
+
DialogContent,
|
|
13
|
+
DialogDescription,
|
|
14
|
+
DialogFooter,
|
|
15
|
+
DialogHeader,
|
|
16
|
+
DialogTitle,
|
|
17
|
+
} from "./dialog";
|
|
18
|
+
|
|
19
|
+
const getServerSnapshot = (): WhatsNewState | null => null;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The "What's new" dialog of the update toast: the changelog titles that the
|
|
23
|
+
* new deploy adds, with Refresh. `SonnerToaster` renders it.
|
|
24
|
+
*/
|
|
25
|
+
export function WhatsNewDialog() {
|
|
26
|
+
const state = useSyncExternalStore(subscribeWhatsNew, getWhatsNew, getServerSnapshot);
|
|
27
|
+
const close = (): void => {
|
|
28
|
+
if (!state) return;
|
|
29
|
+
closeWhatsNew();
|
|
30
|
+
state.onClose();
|
|
31
|
+
};
|
|
32
|
+
return (
|
|
33
|
+
<Dialog open={state !== null} onOpenChange={(open) => (open ? undefined : close())}>
|
|
34
|
+
<DialogContent>
|
|
35
|
+
<DialogHeader>
|
|
36
|
+
<DialogTitle>What's new</DialogTitle>
|
|
37
|
+
<DialogDescription>Refresh to load the latest version.</DialogDescription>
|
|
38
|
+
</DialogHeader>
|
|
39
|
+
<DialogBody>
|
|
40
|
+
<ul className="list-disc space-y-1.5 pl-5 text-sm">
|
|
41
|
+
{state?.notes.map((note) => <li key={note.id}>{note.title}</li>)}
|
|
42
|
+
</ul>
|
|
43
|
+
</DialogBody>
|
|
44
|
+
<DialogFooter>
|
|
45
|
+
<Button variant="outline" onClick={close}>
|
|
46
|
+
Later
|
|
47
|
+
</Button>
|
|
48
|
+
<Button
|
|
49
|
+
onClick={() => {
|
|
50
|
+
closeWhatsNew();
|
|
51
|
+
state?.refresh();
|
|
52
|
+
}}
|
|
53
|
+
>
|
|
54
|
+
Refresh
|
|
55
|
+
</Button>
|
|
56
|
+
</DialogFooter>
|
|
57
|
+
</DialogContent>
|
|
58
|
+
</Dialog>
|
|
59
|
+
);
|
|
60
|
+
}
|