@lemonriver/core 1.0.0 → 1.0.1
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/package.json +1 -1
- package/src/app/lemonriver/brand/mascot.tsx +4 -1
- package/src/app/lemonriver/feedback/lemon-empty.tsx +3 -1
- package/src/app/lemonriver/routes.test.tsx +4 -1
- package/src/app/lemonriver/routes.tsx +12 -11
- package/src/app/lemonriver/text/en.ts +5 -2
- package/src/app/lemonriver/text/es.ts +5 -2
- package/src/app/lemonriver/text/ja.ts +5 -2
- package/src/app/lemonriver/text/types.ts +1 -0
- package/src/app/lemonriver/text/zh-cn.ts +3 -2
- package/src/app/lemonriver/text/zh-tw.ts +3 -2
- package/src/app/lemonriver/update/lazy-page.tsx +29 -0
- package/src/app/lemonriver/update/notice-mascot.tsx +18 -0
- package/src/app/lemonriver/update/restart-notice.tsx +47 -0
- package/src/app/lemonriver/update/state.ts +33 -0
- package/src/app/lemonriver/update/update-prompt.tsx +30 -1
package/package.json
CHANGED
|
@@ -38,11 +38,14 @@ export function Mascot({
|
|
|
38
38
|
size,
|
|
39
39
|
float = false,
|
|
40
40
|
className,
|
|
41
|
+
src,
|
|
41
42
|
}: {
|
|
42
43
|
state: MascotState;
|
|
43
44
|
size: number;
|
|
44
45
|
float?: boolean;
|
|
45
46
|
className?: string;
|
|
47
|
+
/** An already-loaded image, used when the file on disk may be gone. */
|
|
48
|
+
src?: string;
|
|
46
49
|
}) {
|
|
47
50
|
const first = useRef(true);
|
|
48
51
|
const [bounce, setBounce] = useState(0);
|
|
@@ -59,7 +62,7 @@ export function Mascot({
|
|
|
59
62
|
return (
|
|
60
63
|
<img
|
|
61
64
|
key={bounce}
|
|
62
|
-
src={MASCOT_SRC[state]}
|
|
65
|
+
src={src ?? MASCOT_SRC[state]}
|
|
63
66
|
alt=""
|
|
64
67
|
aria-hidden
|
|
65
68
|
draggable={false}
|
|
@@ -6,6 +6,7 @@ import { Mascot, type MascotState } from '../brand/mascot';
|
|
|
6
6
|
export function LemonEmpty({
|
|
7
7
|
state = 'idle',
|
|
8
8
|
size = 140,
|
|
9
|
+
mascotSrc,
|
|
9
10
|
title,
|
|
10
11
|
children,
|
|
11
12
|
actions,
|
|
@@ -14,6 +15,7 @@ export function LemonEmpty({
|
|
|
14
15
|
}: {
|
|
15
16
|
state?: MascotState;
|
|
16
17
|
size?: number;
|
|
18
|
+
mascotSrc?: string;
|
|
17
19
|
title: ReactNode;
|
|
18
20
|
children?: ReactNode;
|
|
19
21
|
actions?: ReactNode;
|
|
@@ -29,7 +31,7 @@ export function LemonEmpty({
|
|
|
29
31
|
className,
|
|
30
32
|
)}
|
|
31
33
|
>
|
|
32
|
-
<Mascot state={state} size={size} float={state === 'idle'} className="mb-2" />
|
|
34
|
+
<Mascot state={state} size={size} src={mascotSrc} float={state === 'idle'} className="mb-2" />
|
|
33
35
|
<h2
|
|
34
36
|
className={cn(
|
|
35
37
|
'font-heading font-semibold text-foreground',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ReactElement } from 'react';
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
2
|
import { describe, expect, it, vi } from 'vitest';
|
|
3
3
|
|
|
4
4
|
vi.mock('./features', () => ({ isFeatureEnabled: vi.fn(() => true) }));
|
|
@@ -7,6 +7,9 @@ vi.mock('./home/home-page', () => ({ LemonRiverHome: () => null }));
|
|
|
7
7
|
vi.mock('./help/help-page', () => ({ HelpPage: () => null }));
|
|
8
8
|
vi.mock('./settings/settings-page', () => ({ SettingsPage: () => null }));
|
|
9
9
|
vi.mock('./trash/trash-page', () => ({ TrashPage: () => null }));
|
|
10
|
+
vi.mock('./update/lazy-page', () => ({
|
|
11
|
+
LazyPage: ({ children }: { children: ReactNode }) => children,
|
|
12
|
+
}));
|
|
10
13
|
|
|
11
14
|
import { isFeatureEnabled } from './features';
|
|
12
15
|
import { lemonRiverRoutes, lemonRiverShellRoutes } from './routes';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { lazy
|
|
1
|
+
import { lazy } from 'react';
|
|
2
2
|
import { Route } from 'react-router-dom';
|
|
3
3
|
import { NotFound } from './chrome/not-found';
|
|
4
4
|
import { isFeatureEnabled } from './features';
|
|
@@ -6,6 +6,7 @@ import { HelpPage } from './help/help-page';
|
|
|
6
6
|
import { LemonRiverHome } from './home/home-page';
|
|
7
7
|
import { SettingsPage } from './settings/settings-page';
|
|
8
8
|
import { TrashPage } from './trash/trash-page';
|
|
9
|
+
import { LazyPage } from './update/lazy-page';
|
|
9
10
|
|
|
10
11
|
const BoardPage = lazy(() => import('./board/board-page').then((m) => ({ default: m.Board })));
|
|
11
12
|
const DescribePage = lazy(() =>
|
|
@@ -29,9 +30,9 @@ export function lemonRiverRoutes() {
|
|
|
29
30
|
key="board"
|
|
30
31
|
path="/s/:slideId/board"
|
|
31
32
|
element={
|
|
32
|
-
<
|
|
33
|
+
<LazyPage>
|
|
33
34
|
<BoardPage />
|
|
34
|
-
</
|
|
35
|
+
</LazyPage>
|
|
35
36
|
}
|
|
36
37
|
/>
|
|
37
38
|
),
|
|
@@ -40,9 +41,9 @@ export function lemonRiverRoutes() {
|
|
|
40
41
|
key="outline"
|
|
41
42
|
path="/s/:slideId/outline"
|
|
42
43
|
element={
|
|
43
|
-
<
|
|
44
|
+
<LazyPage>
|
|
44
45
|
<OutlinePage />
|
|
45
|
-
</
|
|
46
|
+
</LazyPage>
|
|
46
47
|
}
|
|
47
48
|
/>
|
|
48
49
|
),
|
|
@@ -51,9 +52,9 @@ export function lemonRiverRoutes() {
|
|
|
51
52
|
key="template-demo"
|
|
52
53
|
path="/template-demo/:templateId"
|
|
53
54
|
element={
|
|
54
|
-
<
|
|
55
|
+
<LazyPage>
|
|
55
56
|
<TemplateDemoPage />
|
|
56
|
-
</
|
|
57
|
+
</LazyPage>
|
|
57
58
|
}
|
|
58
59
|
/>
|
|
59
60
|
),
|
|
@@ -70,9 +71,9 @@ export function lemonRiverShellRoutes() {
|
|
|
70
71
|
key="new"
|
|
71
72
|
path="/new"
|
|
72
73
|
element={
|
|
73
|
-
<
|
|
74
|
+
<LazyPage>
|
|
74
75
|
<DescribePage />
|
|
75
|
-
</
|
|
76
|
+
</LazyPage>
|
|
76
77
|
}
|
|
77
78
|
/>
|
|
78
79
|
),
|
|
@@ -85,9 +86,9 @@ export function lemonRiverShellRoutes() {
|
|
|
85
86
|
key="templates"
|
|
86
87
|
path="/templates"
|
|
87
88
|
element={
|
|
88
|
-
<
|
|
89
|
+
<LazyPage>
|
|
89
90
|
<TemplatesPage />
|
|
90
|
-
</
|
|
91
|
+
</LazyPage>
|
|
91
92
|
}
|
|
92
93
|
/>
|
|
93
94
|
),
|
|
@@ -1017,8 +1017,11 @@ export const en: LrText = {
|
|
|
1017
1017
|
later: 'Later',
|
|
1018
1018
|
updating: 'Updating…',
|
|
1019
1019
|
updated: 'Updated to {version}',
|
|
1020
|
-
updatedHint:
|
|
1021
|
-
|
|
1020
|
+
updatedHint:
|
|
1021
|
+
'Restart the server now. Until you do, pages you have not opened yet may not open.',
|
|
1022
|
+
updatedManual:
|
|
1023
|
+
'Run the start command again. Until you do, pages you have not opened yet may not open.',
|
|
1024
|
+
restartNeeded: 'LemonRiver has updated. Restart the server to open this page.',
|
|
1022
1025
|
restart: 'Restart server',
|
|
1023
1026
|
failed: "The update didn't go through",
|
|
1024
1027
|
failedHint: 'The terminal running the start command has the details.',
|
|
@@ -365,8 +365,11 @@ export const es: LrText = {
|
|
|
365
365
|
later: 'Más tarde',
|
|
366
366
|
updating: 'Actualizando…',
|
|
367
367
|
updated: 'Actualizado a {version}',
|
|
368
|
-
updatedHint:
|
|
369
|
-
|
|
368
|
+
updatedHint:
|
|
369
|
+
'Reinicia el servidor ahora. Hasta entonces, puede que las páginas que aún no has abierto no se abran.',
|
|
370
|
+
updatedManual:
|
|
371
|
+
'Vuelve a ejecutar el comando de inicio. Hasta entonces, puede que las páginas que aún no has abierto no se abran.',
|
|
372
|
+
restartNeeded: 'LemonRiver se ha actualizado. Reinicia el servidor para abrir esta página.',
|
|
370
373
|
restart: 'Reiniciar servidor',
|
|
371
374
|
failed: 'La actualización no se completó',
|
|
372
375
|
failedHint: 'La terminal donde corre el comando de inicio tiene los detalles.',
|
|
@@ -362,8 +362,11 @@ export const ja: LrText = {
|
|
|
362
362
|
later: 'あとで',
|
|
363
363
|
updating: '更新中…',
|
|
364
364
|
updated: '{version} に更新しました',
|
|
365
|
-
updatedHint:
|
|
366
|
-
|
|
365
|
+
updatedHint:
|
|
366
|
+
'今すぐサーバーを再起動してください。再起動するまで、まだ開いていないページが開けないことがあります。',
|
|
367
|
+
updatedManual:
|
|
368
|
+
'起動コマンドをもう一度実行してください。それまでは、まだ開いていないページが開けないことがあります。',
|
|
369
|
+
restartNeeded: 'LemonRiver を更新しました。このページを開くにはサーバーを再起動してください。',
|
|
367
370
|
restart: 'サーバーを再起動',
|
|
368
371
|
failed: '更新できませんでした',
|
|
369
372
|
failedHint: '起動コマンドを実行しているターミナルに詳細が出ています。',
|
|
@@ -972,8 +972,9 @@ export const zhCN: LrText = {
|
|
|
972
972
|
later: '稍后',
|
|
973
973
|
updating: '正在更新…',
|
|
974
974
|
updated: '已更新到 {version}',
|
|
975
|
-
updatedHint: '
|
|
976
|
-
updatedManual: '
|
|
975
|
+
updatedHint: '现在重启服务。重启之前,还没打开过的页面可能打不开。',
|
|
976
|
+
updatedManual: '重新运行启动命令。在那之前,还没打开过的页面可能打不开。',
|
|
977
|
+
restartNeeded: 'LemonRiver 已更新,重启服务后才能打开这一页',
|
|
977
978
|
restart: '重启服务',
|
|
978
979
|
failed: '更新没成功',
|
|
979
980
|
failedHint: '启动命令所在的终端里有报错详情。',
|
|
@@ -972,8 +972,9 @@ export const zhTW: LrText = {
|
|
|
972
972
|
later: '稍後',
|
|
973
973
|
updating: '正在更新…',
|
|
974
974
|
updated: '已更新到 {version}',
|
|
975
|
-
updatedHint: '
|
|
976
|
-
updatedManual: '
|
|
975
|
+
updatedHint: '現在重啟服務。重啟之前,還沒打開過的頁面可能打不開。',
|
|
976
|
+
updatedManual: '重新執行啟動指令。在那之前,還沒打開過的頁面可能打不開。',
|
|
977
|
+
restartNeeded: 'LemonRiver 已更新,重啟服務後才能開啟這一頁',
|
|
977
978
|
restart: '重啟服務',
|
|
978
979
|
failed: '更新沒成功',
|
|
979
980
|
failedHint: '啟動指令所在的終端機裡有錯誤詳情。',
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Component, type ReactNode, Suspense } from 'react';
|
|
2
|
+
import { RestartNotice } from './restart-notice';
|
|
3
|
+
import { justUpdated, moduleFetchFailed } from './state';
|
|
4
|
+
|
|
5
|
+
/** A `lazy` route: while it loads nothing shows, and after an update a missing chunk gets a restart hint. */
|
|
6
|
+
export function LazyPage({ children }: { children: ReactNode }) {
|
|
7
|
+
return (
|
|
8
|
+
<Suspense fallback={null}>
|
|
9
|
+
<ModuleBoundary>{children}</ModuleBoundary>
|
|
10
|
+
</Suspense>
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
type BoundaryState = { error: Error | null };
|
|
15
|
+
|
|
16
|
+
class ModuleBoundary extends Component<{ children: ReactNode }, BoundaryState> {
|
|
17
|
+
state: BoundaryState = { error: null };
|
|
18
|
+
|
|
19
|
+
static getDerivedStateFromError(error: Error): BoundaryState {
|
|
20
|
+
return { error };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
render() {
|
|
24
|
+
const { error } = this.state;
|
|
25
|
+
if (!error) return this.props.children;
|
|
26
|
+
if (!moduleFetchFailed(error) || !justUpdated()) throw error;
|
|
27
|
+
return <RestartNotice />;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const SIZE = 36;
|
|
2
|
+
|
|
3
|
+
/** Lemon at the size the toaster draws it, from an already-loaded copy. */
|
|
4
|
+
export function NoticeMascot({ src }: { src: string | null }) {
|
|
5
|
+
if (!src) return null;
|
|
6
|
+
return (
|
|
7
|
+
<img
|
|
8
|
+
src={src}
|
|
9
|
+
alt=""
|
|
10
|
+
aria-hidden
|
|
11
|
+
draggable={false}
|
|
12
|
+
width={SIZE}
|
|
13
|
+
height={SIZE}
|
|
14
|
+
className="lr-mascot shrink-0"
|
|
15
|
+
style={{ width: SIZE, height: SIZE }}
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { toast } from 'sonner';
|
|
3
|
+
import { Button } from '@/components/ui/button';
|
|
4
|
+
import { format } from '@/lib/use-locale';
|
|
5
|
+
import { useRestartServer } from '@/lib/use-restart-server';
|
|
6
|
+
import { LemonEmpty } from '../feedback/lemon-empty';
|
|
7
|
+
import { useLrText } from '../text';
|
|
8
|
+
import { NoticeMascot } from './notice-mascot';
|
|
9
|
+
import { justUpdated, noticeIcons, UPDATE_TOAST_ID } from './state';
|
|
10
|
+
|
|
11
|
+
/** Shown instead of a blank page when the code for this route was deleted by the update. */
|
|
12
|
+
export function RestartNotice() {
|
|
13
|
+
const lr = useLrText();
|
|
14
|
+
const { canRestart, restarting, restartServer } = useRestartServer();
|
|
15
|
+
const version = justUpdated();
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
if (!version) return;
|
|
19
|
+
const { done } = noticeIcons();
|
|
20
|
+
toast.success(format(lr.update.updated, { version }), {
|
|
21
|
+
id: UPDATE_TOAST_ID,
|
|
22
|
+
duration: Infinity,
|
|
23
|
+
description: canRestart ? lr.update.updatedHint : lr.update.updatedManual,
|
|
24
|
+
icon: done ? <NoticeMascot src={done} /> : undefined,
|
|
25
|
+
action: canRestart
|
|
26
|
+
? { label: lr.update.restart, onClick: () => void restartServer() }
|
|
27
|
+
: undefined,
|
|
28
|
+
});
|
|
29
|
+
}, [canRestart, lr, restartServer, version]);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div className="grid min-h-dvh place-items-center bg-background px-6 text-foreground">
|
|
33
|
+
<LemonEmpty
|
|
34
|
+
state="needs-you"
|
|
35
|
+
mascotSrc={noticeIcons().needsYou ?? undefined}
|
|
36
|
+
title={lr.update.restartNeeded}
|
|
37
|
+
actions={
|
|
38
|
+
canRestart && (
|
|
39
|
+
<Button data-slot="button" disabled={restarting} onClick={() => void restartServer()}>
|
|
40
|
+
{lr.update.restart}
|
|
41
|
+
</Button>
|
|
42
|
+
)
|
|
43
|
+
}
|
|
44
|
+
/>
|
|
45
|
+
</div>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export const UPDATE_TOAST_ID = 'lemonriver-update';
|
|
2
|
+
|
|
3
|
+
let updatedVersion: string | null = null;
|
|
4
|
+
let icons: { done: string | null; needsYou: string | null } = { done: null, needsYou: null };
|
|
5
|
+
|
|
6
|
+
export function markUpdated(version: string): void {
|
|
7
|
+
updatedVersion = version;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function justUpdated(): string | null {
|
|
11
|
+
return updatedVersion;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function rememberNoticeIcons(next: typeof icons): void {
|
|
15
|
+
icons = next;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function noticeIcons(): typeof icons {
|
|
19
|
+
return icons;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// A dev-server update deletes the old files while the page still runs them, so
|
|
23
|
+
// the next page the user opens fails to fetch its chunk.
|
|
24
|
+
const MODULE_FETCH_ERRORS = [
|
|
25
|
+
'Failed to fetch dynamically imported module',
|
|
26
|
+
'error loading dynamically imported module',
|
|
27
|
+
'Importing a module script failed',
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
export function moduleFetchFailed(error: unknown): boolean {
|
|
31
|
+
const message = (error as Error | null)?.message ?? '';
|
|
32
|
+
return MODULE_FETCH_ERRORS.some((text) => message.includes(text));
|
|
33
|
+
}
|
|
@@ -3,7 +3,9 @@ import { useLocation } from 'react-router-dom';
|
|
|
3
3
|
import { toast } from 'sonner';
|
|
4
4
|
import { format } from '@/lib/use-locale';
|
|
5
5
|
import { useRestartServer } from '@/lib/use-restart-server';
|
|
6
|
+
import { MASCOT_SRC } from '../brand/mascot';
|
|
6
7
|
import { useLrText } from '../text';
|
|
8
|
+
import { NoticeMascot } from './notice-mascot';
|
|
7
9
|
import {
|
|
8
10
|
promptsOnPage,
|
|
9
11
|
readSnooze,
|
|
@@ -12,8 +14,26 @@ import {
|
|
|
12
14
|
UPDATE_CHECK_INTERVAL_MS,
|
|
13
15
|
type UpdateCheck,
|
|
14
16
|
} from './prompt';
|
|
17
|
+
import { markUpdated, rememberNoticeIcons, UPDATE_TOAST_ID } from './state';
|
|
15
18
|
|
|
16
|
-
const TOAST_ID =
|
|
19
|
+
const TOAST_ID = UPDATE_TOAST_ID;
|
|
20
|
+
|
|
21
|
+
/** Reads a mascot while its file still exists, so the notice can still draw it after the update. */
|
|
22
|
+
async function preloadMascot(src: string): Promise<string | null> {
|
|
23
|
+
try {
|
|
24
|
+
const res = await fetch(src);
|
|
25
|
+
if (!res.ok) return null;
|
|
26
|
+
const blob = await res.blob();
|
|
27
|
+
return await new Promise<string>((resolve, reject) => {
|
|
28
|
+
const reader = new FileReader();
|
|
29
|
+
reader.onload = () => resolve(String(reader.result));
|
|
30
|
+
reader.onerror = () => reject(reader.error);
|
|
31
|
+
reader.readAsDataURL(blob);
|
|
32
|
+
});
|
|
33
|
+
} catch {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
17
37
|
|
|
18
38
|
export function UpdatePrompt() {
|
|
19
39
|
const { pathname } = useLocation();
|
|
@@ -41,6 +61,12 @@ export function UpdatePrompt() {
|
|
|
41
61
|
phase.current = 'busy';
|
|
42
62
|
toast.loading(lr.update.updating, { id: TOAST_ID, duration: Infinity });
|
|
43
63
|
|
|
64
|
+
const icons = {
|
|
65
|
+
done: await preloadMascot(MASCOT_SRC.done),
|
|
66
|
+
needsYou: await preloadMascot(MASCOT_SRC['needs-you']),
|
|
67
|
+
};
|
|
68
|
+
rememberNoticeIcons(icons);
|
|
69
|
+
|
|
44
70
|
let ok = false;
|
|
45
71
|
try {
|
|
46
72
|
const res = await fetch('/__update-package', { method: 'POST' });
|
|
@@ -56,6 +82,7 @@ export function UpdatePrompt() {
|
|
|
56
82
|
id: TOAST_ID,
|
|
57
83
|
duration: Infinity,
|
|
58
84
|
description: lr.update.failedHint,
|
|
85
|
+
icon: icons.needsYou ? <NoticeMascot src={icons.needsYou} /> : undefined,
|
|
59
86
|
action: { label: lr.update.retry, onClick: () => void runUpdate(latest) },
|
|
60
87
|
cancel: { label: lr.update.later, onClick: () => snooze(latest) },
|
|
61
88
|
});
|
|
@@ -64,10 +91,12 @@ export function UpdatePrompt() {
|
|
|
64
91
|
|
|
65
92
|
phase.current = 'done';
|
|
66
93
|
settled.current = latest;
|
|
94
|
+
markUpdated(latest);
|
|
67
95
|
if (cancelled) return;
|
|
68
96
|
toast.success(format(lr.update.updated, { version: latest }), {
|
|
69
97
|
id: TOAST_ID,
|
|
70
98
|
duration: Infinity,
|
|
99
|
+
icon: icons.done ? <NoticeMascot src={icons.done} /> : undefined,
|
|
71
100
|
description: canRestart ? lr.update.updatedHint : lr.update.updatedManual,
|
|
72
101
|
action: canRestart
|
|
73
102
|
? { label: lr.update.restart, onClick: () => void restartServer() }
|