@lemonriver/core 1.1.0 → 1.2.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/dist/{build-Dm7gVRhb.js → build-CSkdswfd.js} +1 -1
- package/dist/cli/bin.js +5 -5
- package/dist/{config-CubOIzrs.js → config-C5-myPY6.js} +129 -2
- package/dist/{dev-DgLeXPqp.js → dev-DHtYH8sw.js} +2 -2
- package/dist/{mcp-CjYDzcJa.js → mcp-B2UeO1un.js} +1 -1
- package/dist/{preview-CxXQpPk5.js → preview-C1B6-umF.js} +1 -1
- package/dist/{update-b1dSg_FW.js → update-DzL8fpcI.js} +1 -1
- package/dist/vite/index.js +1 -1
- package/package.json +5 -2
- package/release-notes.json +19 -0
- package/src/app/lemonriver/chrome/app-chrome.tsx +52 -0
- package/src/app/lemonriver/chrome/sidebar-extras.tsx +8 -1
- package/src/app/lemonriver/feedback/dialog.tsx +222 -0
- package/src/app/lemonriver/feedback/export.ts +21 -2
- package/src/app/lemonriver/feedback/first-success.ts +30 -0
- package/src/app/lemonriver/feedback/install.ts +18 -0
- package/src/app/lemonriver/feedback/model.ts +88 -0
- package/src/app/lemonriver/help/help-page.tsx +16 -1
- package/src/app/lemonriver/links.ts +16 -0
- package/src/app/lemonriver/settings/backup-section.tsx +13 -0
- package/src/app/lemonriver/settings/settings-page.tsx +20 -0
- package/src/app/lemonriver/share/editor-share.tsx +6 -3
- package/src/app/lemonriver/share/share-dialog.tsx +2 -0
- package/src/app/lemonriver/text/en.ts +45 -0
- package/src/app/lemonriver/text/es.ts +42 -0
- package/src/app/lemonriver/text/ja.ts +41 -0
- package/src/app/lemonriver/text/types.ts +44 -0
- package/src/app/lemonriver/text/zh-cn.ts +45 -0
- package/src/app/lemonriver/text/zh-tw.ts +45 -0
- package/src/app/lemonriver/theme/pages.ts +4 -0
- package/src/app/lemonriver/update/release-notes.ts +22 -0
- package/src/app/lemonriver/update/update-prompt.tsx +28 -4
- package/src/app/components/note-markdown.test.tsx +0 -42
- package/src/app/components/thumbnail-rail-scroll.test.ts +0 -60
- package/src/app/lemonriver/agent-prefs/prefs.test.ts +0 -173
- package/src/app/lemonriver/backup/guide.test.ts +0 -45
- package/src/app/lemonriver/backup/model.test.ts +0 -108
- package/src/app/lemonriver/backup/places.test.ts +0 -154
- package/src/app/lemonriver/board/blocks/classify.test.ts +0 -209
- package/src/app/lemonriver/board/layout.test.ts +0 -245
- package/src/app/lemonriver/board/model/agent-tasks.test.ts +0 -200
- package/src/app/lemonriver/board/model/apply-prompt.test.ts +0 -121
- package/src/app/lemonriver/board/model/cards.test.ts +0 -332
- package/src/app/lemonriver/board/model/changes.test.ts +0 -244
- package/src/app/lemonriver/board/model/filter.test.ts +0 -50
- package/src/app/lemonriver/board/model/history.test.ts +0 -71
- package/src/app/lemonriver/board/model/restructure.test.ts +0 -205
- package/src/app/lemonriver/board/model/self-check.test.ts +0 -329
- package/src/app/lemonriver/board/model/structure.test.ts +0 -350
- package/src/app/lemonriver/board/model/timing.test.ts +0 -113
- package/src/app/lemonriver/features.test.ts +0 -49
- package/src/app/lemonriver/feedback/pending-toast.test.ts +0 -44
- package/src/app/lemonriver/feedback/upload.test.ts +0 -26
- package/src/app/lemonriver/help/model.test.ts +0 -179
- package/src/app/lemonriver/home/brief.test.ts +0 -38
- package/src/app/lemonriver/home/drafts.test.ts +0 -23
- package/src/app/lemonriver/home/sorting.test.ts +0 -24
- package/src/app/lemonriver/home/time.test.ts +0 -33
- package/src/app/lemonriver/outline/files.test.ts +0 -90
- package/src/app/lemonriver/outline/model.test.ts +0 -751
- package/src/app/lemonriver/public-links.test.ts +0 -32
- package/src/app/lemonriver/routes.test.tsx +0 -54
- package/src/app/lemonriver/share/codes.test.ts +0 -49
- package/src/app/lemonriver/share/compare.test.ts +0 -199
- package/src/app/lemonriver/share/folder.test.ts +0 -42
- package/src/app/lemonriver/share/guide.test.ts +0 -78
- package/src/app/lemonriver/share/naming.test.ts +0 -70
- package/src/app/lemonriver/share/paths.test.ts +0 -116
- package/src/app/lemonriver/share/pdf.test.ts +0 -79
- package/src/app/lemonriver/templates/knobs.test.ts +0 -62
- package/src/app/lemonriver/templates/model.test.ts +0 -175
- package/src/app/lemonriver/templates/preview-content.test.ts +0 -117
- package/src/app/lemonriver/templates/recommend.test.ts +0 -71
- package/src/app/lemonriver/text/text.test.ts +0 -90
- package/src/app/lemonriver/theme/pages.test.ts +0 -74
- package/src/app/lemonriver/theme/themes.test.ts +0 -18
- package/src/app/lemonriver/trash/api.test.ts +0 -19
- package/src/app/lemonriver/update/prompt.test.ts +0 -84
- package/src/app/lemonriver/update/version.test.ts +0 -14
- package/src/app/lib/asset-filter.test.ts +0 -176
- package/src/app/lib/inspector/fiber.test.ts +0 -154
- package/src/app/lib/inspector/geometry.test.ts +0 -324
- package/src/app/lib/inspector/text-edit-timeline.test.ts +0 -121
- package/src/app/lib/note-markdown.test.ts +0 -147
- package/src/app/lib/pptx/css.test.ts +0 -205
- package/src/app/lib/pptx/ooxml.test.ts +0 -199
- package/src/app/lib/pptx/text-lines.test.ts +0 -82
- package/src/app/lib/print-ready.test.ts +0 -32
- package/src/app/lib/sdk.test.ts +0 -13
- package/src/app/lib/transition.test.ts +0 -31
- package/src/app/lib/use-document-title.test.ts +0 -14
- package/src/app/lib/utils.test.ts +0 -49
|
@@ -218,6 +218,10 @@ export const zhTW: LrText = {
|
|
|
218
218
|
strong: '留言沒生效',
|
|
219
219
|
text: ':留言只是記下來,要跟 Agent 說「應用留言」才會改。',
|
|
220
220
|
},
|
|
221
|
+
{
|
|
222
|
+
strong: '想提意見或遇到問題',
|
|
223
|
+
text: ':點側欄的「回饋」。',
|
|
224
|
+
},
|
|
221
225
|
],
|
|
222
226
|
},
|
|
223
227
|
],
|
|
@@ -914,6 +918,9 @@ export const zhTW: LrText = {
|
|
|
914
918
|
workspaceCopied: '已複製',
|
|
915
919
|
workspaceReveal: '在 Finder 中顯示',
|
|
916
920
|
workspaceCopiedToast: '已複製工作區資料夾位址',
|
|
921
|
+
supportTitle: '支持 LemonRiver',
|
|
922
|
+
supportText: 'LemonRiver 免費使用。覺得好用的話,可以請我們喝杯咖啡。',
|
|
923
|
+
supportButton: 'Buy Me a Coffee',
|
|
917
924
|
},
|
|
918
925
|
agents: {
|
|
919
926
|
title: 'Agent',
|
|
@@ -935,6 +942,42 @@ export const zhTW: LrText = {
|
|
|
935
942
|
uploadTooLargeHint: '壓縮圖片或換一個較小的檔案,再重新上傳。',
|
|
936
943
|
confirmWho: '檸檬需要你做決定',
|
|
937
944
|
confirmReview: '核對需要你做決定',
|
|
945
|
+
sidebar: '回饋',
|
|
946
|
+
title: '回饋',
|
|
947
|
+
intro: '會一起帶上下面這些資訊,不帶你的簡報內容和檔案位置。',
|
|
948
|
+
categoryIssue: '遇到問題',
|
|
949
|
+
categoryIdea: '想要的功能',
|
|
950
|
+
categoryOther: '其它',
|
|
951
|
+
fieldVersion: 'LemonRiver 版本',
|
|
952
|
+
fieldOs: '系統',
|
|
953
|
+
fieldInstall: '安裝方式',
|
|
954
|
+
fieldPage: '頁面',
|
|
955
|
+
fieldError: '出錯',
|
|
956
|
+
separator: ':',
|
|
957
|
+
unknown: '未知',
|
|
958
|
+
installApp: '安裝包',
|
|
959
|
+
installCli: '命令列',
|
|
960
|
+
pageHome: '首頁',
|
|
961
|
+
pageEditor: '編輯頁',
|
|
962
|
+
pageBoard: '故事看板',
|
|
963
|
+
pageOutline: '大綱',
|
|
964
|
+
pageSettings: '設定',
|
|
965
|
+
pageHelp: '說明',
|
|
966
|
+
pageOther: '其它頁面',
|
|
967
|
+
errorExport: '匯出失敗',
|
|
968
|
+
errorUpdate: '更新失敗',
|
|
969
|
+
errorBackup: '備份失敗',
|
|
970
|
+
openForm: '填線上表單',
|
|
971
|
+
sendEmail: '寄信',
|
|
972
|
+
copyInfo: '複製這些資訊',
|
|
973
|
+
copied: '資訊已複製,貼到表單裡就行',
|
|
974
|
+
noChannel: '回饋管道還沒開通',
|
|
975
|
+
mailSubject: 'LemonRiver 回饋:{category}',
|
|
976
|
+
mailBodyPlaceholder: '(在這裡寫你的回饋)',
|
|
977
|
+
feedbackThis: '回報這個問題',
|
|
978
|
+
firstSuccessTitle: '這次順利嗎?',
|
|
979
|
+
smooth: '順利',
|
|
980
|
+
notSmooth: '不順利',
|
|
938
981
|
},
|
|
939
982
|
prefs: {
|
|
940
983
|
title: 'Agent 偏好',
|
|
@@ -995,6 +1038,8 @@ export const zhTW: LrText = {
|
|
|
995
1038
|
updated: '已更新到 {version}',
|
|
996
1039
|
updatedHint: '現在重啟服務。重啟之前,還沒打開過的頁面可能打不開。',
|
|
997
1040
|
updatedManual: '重新執行啟動指令。在那之前,還沒打開過的頁面可能打不開。',
|
|
1041
|
+
releaseNotes: '這一版:{first}',
|
|
1042
|
+
releaseNotesMore: '這一版:{first} 等 {n} 項',
|
|
998
1043
|
restartNeeded: 'LemonRiver 已更新,重啟服務後才能開啟這一頁',
|
|
999
1044
|
restart: '重啟服務',
|
|
1000
1045
|
failed: '更新沒成功',
|
|
@@ -8,8 +8,10 @@ export type LrPage =
|
|
|
8
8
|
| 'templates'
|
|
9
9
|
| 'editor'
|
|
10
10
|
| 'board'
|
|
11
|
+
| 'outline'
|
|
11
12
|
| 'presenter'
|
|
12
13
|
| 'preview'
|
|
14
|
+
| 'help'
|
|
13
15
|
| 'other';
|
|
14
16
|
|
|
15
17
|
/** Pages that wear the lime theme when it is picked; the editor and present views stay fresh. */
|
|
@@ -45,7 +47,9 @@ export function pageForPath(pathname: string): LrPage {
|
|
|
45
47
|
if (path === '/trash') return 'trash';
|
|
46
48
|
if (path === '/new') return 'new';
|
|
47
49
|
if (path === '/templates') return 'templates';
|
|
50
|
+
if (path === '/help') return 'help';
|
|
48
51
|
if (/^\/s\/[^/]+\/board$/.test(path)) return 'board';
|
|
52
|
+
if (/^\/s\/[^/]+\/outline$/.test(path)) return 'outline';
|
|
49
53
|
if (/^\/s\/[^/]+\/presenter$/.test(path)) return 'presenter';
|
|
50
54
|
if (/^\/s\/[^/]+\/preview$/.test(path)) return 'preview';
|
|
51
55
|
if (/^\/s\/[^/]+$/.test(path)) return 'editor';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { format } from '../../../locale/format';
|
|
2
|
+
import type { LrText } from '../text/types';
|
|
3
|
+
|
|
4
|
+
export async function fetchReleaseNotes(locale: string): Promise<string[]> {
|
|
5
|
+
try {
|
|
6
|
+
const res = await fetch(`/__lr/release-notes?locale=${encodeURIComponent(locale)}`);
|
|
7
|
+
if (!res.ok) return [];
|
|
8
|
+
const body = (await res.json()) as { notes?: unknown };
|
|
9
|
+
return Array.isArray(body.notes)
|
|
10
|
+
? body.notes.filter((note): note is string => typeof note === 'string')
|
|
11
|
+
: [];
|
|
12
|
+
} catch {
|
|
13
|
+
return [];
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function releaseNotesLine(notes: string[], update: LrText['update']): string | null {
|
|
18
|
+
if (notes.length === 0) return null;
|
|
19
|
+
return notes.length === 1
|
|
20
|
+
? format(update.releaseNotes, { first: notes[0] })
|
|
21
|
+
: format(update.releaseNotesMore, { first: notes[0], n: notes.length - 1 });
|
|
22
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
import { useLocation } from 'react-router-dom';
|
|
3
3
|
import { toast } from 'sonner';
|
|
4
|
-
import {
|
|
4
|
+
import { Button } from '@/components/ui/button';
|
|
5
|
+
import { format, useLocale } from '@/lib/use-locale';
|
|
5
6
|
import { useRestartServer } from '@/lib/use-restart-server';
|
|
6
7
|
import { MASCOT_SRC } from '../brand/mascot';
|
|
8
|
+
import { openFeedback } from '../feedback/dialog';
|
|
7
9
|
import { useLrText } from '../text';
|
|
8
10
|
import { NoticeMascot } from './notice-mascot';
|
|
9
11
|
import {
|
|
@@ -14,6 +16,7 @@ import {
|
|
|
14
16
|
UPDATE_CHECK_INTERVAL_MS,
|
|
15
17
|
type UpdateCheck,
|
|
16
18
|
} from './prompt';
|
|
19
|
+
import { fetchReleaseNotes, releaseNotesLine } from './release-notes';
|
|
17
20
|
import { markUpdated, rememberNoticeIcons, UPDATE_TOAST_ID } from './state';
|
|
18
21
|
|
|
19
22
|
const TOAST_ID = UPDATE_TOAST_ID;
|
|
@@ -38,6 +41,7 @@ async function preloadMascot(src: string): Promise<string | null> {
|
|
|
38
41
|
export function UpdatePrompt() {
|
|
39
42
|
const { pathname } = useLocation();
|
|
40
43
|
const lr = useLrText();
|
|
44
|
+
const locale = useLocale();
|
|
41
45
|
const { canRestart, restartServer } = useRestartServer();
|
|
42
46
|
const phase = useRef<'idle' | 'busy' | 'done'>('idle');
|
|
43
47
|
const settled = useRef<string | null>(null);
|
|
@@ -81,7 +85,20 @@ export function UpdatePrompt() {
|
|
|
81
85
|
toast.error(lr.update.failed, {
|
|
82
86
|
id: TOAST_ID,
|
|
83
87
|
duration: Infinity,
|
|
84
|
-
description:
|
|
88
|
+
description: (
|
|
89
|
+
<span className="flex flex-col items-start gap-1.5">
|
|
90
|
+
<span>{lr.update.failedHint}</span>
|
|
91
|
+
<Button
|
|
92
|
+
type="button"
|
|
93
|
+
variant="outline"
|
|
94
|
+
size="sm"
|
|
95
|
+
data-lr-feedback-this
|
|
96
|
+
onClick={() => openFeedback({ category: 'issue', errorKind: 'update' })}
|
|
97
|
+
>
|
|
98
|
+
{lr.feedback.feedbackThis}
|
|
99
|
+
</Button>
|
|
100
|
+
</span>
|
|
101
|
+
),
|
|
85
102
|
icon: icons.needsYou ? <NoticeMascot src={icons.needsYou} /> : undefined,
|
|
86
103
|
action: { label: lr.update.retry, onClick: () => void runUpdate(latest) },
|
|
87
104
|
cancel: { label: lr.update.later, onClick: () => snooze(latest) },
|
|
@@ -93,11 +110,18 @@ export function UpdatePrompt() {
|
|
|
93
110
|
settled.current = latest;
|
|
94
111
|
markUpdated(latest);
|
|
95
112
|
if (cancelled) return;
|
|
113
|
+
const notesLine = releaseNotesLine(await fetchReleaseNotes(locale.id), lr.update);
|
|
114
|
+
if (cancelled) return;
|
|
96
115
|
toast.success(format(lr.update.updated, { version: latest }), {
|
|
97
116
|
id: TOAST_ID,
|
|
98
117
|
duration: Infinity,
|
|
99
118
|
icon: icons.done ? <NoticeMascot src={icons.done} /> : undefined,
|
|
100
|
-
description:
|
|
119
|
+
description: (
|
|
120
|
+
<span className="flex flex-col gap-1">
|
|
121
|
+
<span>{canRestart ? lr.update.updatedHint : lr.update.updatedManual}</span>
|
|
122
|
+
{notesLine !== null && <span data-lr-release-notes>{notesLine}</span>}
|
|
123
|
+
</span>
|
|
124
|
+
),
|
|
101
125
|
action: canRestart
|
|
102
126
|
? { label: lr.update.restart, onClick: () => void restartServer() }
|
|
103
127
|
: undefined,
|
|
@@ -136,7 +160,7 @@ export function UpdatePrompt() {
|
|
|
136
160
|
cancelled = true;
|
|
137
161
|
clearInterval(timer);
|
|
138
162
|
};
|
|
139
|
-
}, [pathname, lr, canRestart, restartServer]);
|
|
163
|
+
}, [pathname, lr, locale, canRestart, restartServer]);
|
|
140
164
|
|
|
141
165
|
return null;
|
|
142
166
|
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { renderToStaticMarkup } from 'react-dom/server';
|
|
2
|
-
import { describe, expect, it } from 'vitest';
|
|
3
|
-
import { NoteMarkdown } from './note-markdown';
|
|
4
|
-
|
|
5
|
-
const render = (text: string) => renderToStaticMarkup(<NoteMarkdown text={text} />);
|
|
6
|
-
|
|
7
|
-
describe('NoteMarkdown', () => {
|
|
8
|
-
it('renders inline markdown as semantic elements', () => {
|
|
9
|
-
const html = render('a **bold** and *soft* `cmd`');
|
|
10
|
-
expect(html).toContain('<strong class="font-semibold">bold</strong>');
|
|
11
|
-
expect(html).toContain('<em>soft</em>');
|
|
12
|
-
expect(html).toContain('>cmd</code>');
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
it('renders headings demoted to h4–h6', () => {
|
|
16
|
-
const html = render('# One\n## Two\n### Three');
|
|
17
|
-
expect(html).toContain('<h4');
|
|
18
|
-
expect(html).toContain('<h5');
|
|
19
|
-
expect(html).toContain('<h6');
|
|
20
|
-
expect(html).not.toContain('<h1');
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('renders lists with the right element', () => {
|
|
24
|
-
expect(render('- a\n- b')).toMatch(/<ul[^>]*>.*<li>a<\/li><li>b<\/li>.*<\/ul>/);
|
|
25
|
-
expect(render('1. a\n2. b')).toMatch(/<ol[^>]*>.*<li>a<\/li><li>b<\/li>.*<\/ol>/);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('joins paragraph lines with <br/> and splits paragraphs', () => {
|
|
29
|
-
const html = render('one\ntwo\n\nthree');
|
|
30
|
-
expect(html).toMatch(/<p>one<br\/>two<\/p><p>three<\/p>/);
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('keeps escaped delimiters literal in the output', () => {
|
|
34
|
-
const html = render('\\*keep\\* the stars');
|
|
35
|
-
expect(html).toContain('*keep* the stars');
|
|
36
|
-
expect(html).not.toContain('<em>');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('preserves whitespace via a pre-wrap wrapper', () => {
|
|
40
|
-
expect(render('x')).toContain('whitespace-pre-wrap');
|
|
41
|
-
});
|
|
42
|
-
});
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
getCenteredThumbnailScrollTop,
|
|
4
|
-
getThumbnailOffscreenDirection,
|
|
5
|
-
} from './thumbnail-rail-scroll';
|
|
6
|
-
|
|
7
|
-
describe('getThumbnailOffscreenDirection', () => {
|
|
8
|
-
const visibleBounds = { visibleTop: 40, visibleBottom: 540 };
|
|
9
|
-
|
|
10
|
-
it('reports a thumbnail fully above the visible area', () => {
|
|
11
|
-
expect(getThumbnailOffscreenDirection({ itemTop: -80, itemBottom: 40, ...visibleBounds })).toBe(
|
|
12
|
-
'above',
|
|
13
|
-
);
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it('reports a thumbnail fully below the visible area', () => {
|
|
17
|
-
expect(
|
|
18
|
-
getThumbnailOffscreenDirection({ itemTop: 540, itemBottom: 660, ...visibleBounds }),
|
|
19
|
-
).toBe('below');
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it('keeps the control hidden while a thumbnail is fully visible', () => {
|
|
23
|
-
expect(
|
|
24
|
-
getThumbnailOffscreenDirection({ itemTop: 120, itemBottom: 240, ...visibleBounds }),
|
|
25
|
-
).toBeNull();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('keeps the control hidden while either edge remains visible', () => {
|
|
29
|
-
expect(
|
|
30
|
-
getThumbnailOffscreenDirection({ itemTop: 20, itemBottom: 80, ...visibleBounds }),
|
|
31
|
-
).toBeNull();
|
|
32
|
-
expect(
|
|
33
|
-
getThumbnailOffscreenDirection({ itemTop: 500, itemBottom: 580, ...visibleBounds }),
|
|
34
|
-
).toBeNull();
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
describe('getCenteredThumbnailScrollTop', () => {
|
|
39
|
-
it('centers the thumbnail inside the unobscured viewport', () => {
|
|
40
|
-
expect(
|
|
41
|
-
getCenteredThumbnailScrollTop({
|
|
42
|
-
itemTop: 1040,
|
|
43
|
-
itemHeight: 120,
|
|
44
|
-
viewportHeight: 600,
|
|
45
|
-
topInset: 40,
|
|
46
|
-
}),
|
|
47
|
-
).toBe(780);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('does not scroll before the start of the list', () => {
|
|
51
|
-
expect(
|
|
52
|
-
getCenteredThumbnailScrollTop({
|
|
53
|
-
itemTop: 40,
|
|
54
|
-
itemHeight: 120,
|
|
55
|
-
viewportHeight: 600,
|
|
56
|
-
topInset: 40,
|
|
57
|
-
}),
|
|
58
|
-
).toBe(0);
|
|
59
|
-
});
|
|
60
|
-
});
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
type AgentPrefs,
|
|
4
|
-
DEFAULT_PREFS,
|
|
5
|
-
PREFS_KEY,
|
|
6
|
-
prefsLines,
|
|
7
|
-
readPrefs,
|
|
8
|
-
sanitizePrefs,
|
|
9
|
-
savePrefs,
|
|
10
|
-
toneForUses,
|
|
11
|
-
} from './prefs';
|
|
12
|
-
|
|
13
|
-
function memoryStorage(initial: Record<string, string> = {}): Storage {
|
|
14
|
-
const data = new Map(Object.entries(initial));
|
|
15
|
-
return {
|
|
16
|
-
get length() {
|
|
17
|
-
return data.size;
|
|
18
|
-
},
|
|
19
|
-
clear: () => data.clear(),
|
|
20
|
-
getItem: (key: string) => data.get(key) ?? null,
|
|
21
|
-
key: (index: number) => [...data.keys()][index] ?? null,
|
|
22
|
-
removeItem: (key: string) => {
|
|
23
|
-
data.delete(key);
|
|
24
|
-
},
|
|
25
|
-
setItem: (key: string, value: string) => {
|
|
26
|
-
data.set(key, value);
|
|
27
|
-
},
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
describe('sanitizePrefs', () => {
|
|
32
|
-
it('returns the defaults for anything that is not an object', () => {
|
|
33
|
-
expect(sanitizePrefs(null)).toEqual(DEFAULT_PREFS);
|
|
34
|
-
expect(sanitizePrefs('dense')).toEqual(DEFAULT_PREFS);
|
|
35
|
-
expect(sanitizePrefs(['dense'])).toEqual(DEFAULT_PREFS);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('keeps the values it knows', () => {
|
|
39
|
-
const prefs: AgentPrefs = {
|
|
40
|
-
confirmEachPage: true,
|
|
41
|
-
askOnMismatch: false,
|
|
42
|
-
autoImages: false,
|
|
43
|
-
tone: 'concise',
|
|
44
|
-
research: 'web',
|
|
45
|
-
outline: 'direct',
|
|
46
|
-
design: 'dense',
|
|
47
|
-
review: 'numbers',
|
|
48
|
-
};
|
|
49
|
-
expect(sanitizePrefs(prefs)).toEqual(prefs);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('replaces the values it does not know with the defaults', () => {
|
|
53
|
-
expect(
|
|
54
|
-
sanitizePrefs({
|
|
55
|
-
confirmEachPage: 'yes',
|
|
56
|
-
askOnMismatch: 0,
|
|
57
|
-
autoImages: null,
|
|
58
|
-
tone: 'shouty',
|
|
59
|
-
research: 'library',
|
|
60
|
-
outline: 'auto',
|
|
61
|
-
design: 'sparse',
|
|
62
|
-
review: 'loose',
|
|
63
|
-
}),
|
|
64
|
-
).toEqual(DEFAULT_PREFS);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('fills a partial record', () => {
|
|
68
|
-
expect(sanitizePrefs({ design: 'visual' })).toEqual({ ...DEFAULT_PREFS, design: 'visual' });
|
|
69
|
-
});
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
describe('readPrefs and savePrefs', () => {
|
|
73
|
-
it('round-trips through storage', () => {
|
|
74
|
-
const storage = memoryStorage();
|
|
75
|
-
const prefs: AgentPrefs = { ...DEFAULT_PREFS, tone: 'friendly', confirmEachPage: true };
|
|
76
|
-
savePrefs(storage, prefs);
|
|
77
|
-
expect(storage.getItem(PREFS_KEY)).toBe(JSON.stringify(prefs));
|
|
78
|
-
expect(readPrefs(storage)).toEqual(prefs);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('falls back to the defaults on junk or a missing key', () => {
|
|
82
|
-
expect(readPrefs(memoryStorage())).toEqual(DEFAULT_PREFS);
|
|
83
|
-
expect(readPrefs(memoryStorage({ [PREFS_KEY]: 'not json' }))).toEqual(DEFAULT_PREFS);
|
|
84
|
-
expect(readPrefs(memoryStorage({ [PREFS_KEY]: '{"tone":"loud"}' }))).toEqual(DEFAULT_PREFS);
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('swallows a storage that throws', () => {
|
|
88
|
-
const broken = {
|
|
89
|
-
getItem: () => {
|
|
90
|
-
throw new Error('blocked');
|
|
91
|
-
},
|
|
92
|
-
setItem: () => {
|
|
93
|
-
throw new Error('blocked');
|
|
94
|
-
},
|
|
95
|
-
} as unknown as Storage;
|
|
96
|
-
expect(readPrefs(broken)).toEqual(DEFAULT_PREFS);
|
|
97
|
-
expect(() => savePrefs(broken, DEFAULT_PREFS)).not.toThrow();
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe('prefsLines', () => {
|
|
102
|
-
const prefs = (patch: Partial<AgentPrefs> = {}): AgentPrefs => ({ ...DEFAULT_PREFS, ...patch });
|
|
103
|
-
|
|
104
|
-
it('gives every step the tone', () => {
|
|
105
|
-
for (const step of ['outline', 'page', 'review'] as const) {
|
|
106
|
-
expect(prefsLines(prefs(), step)[0]).toBe('Write in a steady, professional tone.');
|
|
107
|
-
}
|
|
108
|
-
expect(prefsLines(prefs({ tone: 'friendly' }), 'page')[0]).toBe(
|
|
109
|
-
'Write in a light, friendly tone.',
|
|
110
|
-
);
|
|
111
|
-
expect(prefsLines(prefs({ tone: 'concise' }), 'review')[0]).toBe(
|
|
112
|
-
'Keep the wording short and punchy.',
|
|
113
|
-
);
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
it('tells the outline step where facts may come from', () => {
|
|
117
|
-
expect(prefsLines(prefs(), 'outline')).toEqual([
|
|
118
|
-
'Write in a steady, professional tone.',
|
|
119
|
-
"Use only the user's reference files; do not look anything up on the web.",
|
|
120
|
-
]);
|
|
121
|
-
expect(prefsLines(prefs({ research: 'web' }), 'outline')).toContain(
|
|
122
|
-
'You may look up facts the files do not cover; say where each one came from.',
|
|
123
|
-
);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('tells the page step how dense to lay out and whether to use images', () => {
|
|
127
|
-
expect(prefsLines(prefs(), 'page')).toEqual([
|
|
128
|
-
'Write in a steady, professional tone.',
|
|
129
|
-
'Balance text and visuals.',
|
|
130
|
-
'Use icons and image placeholders where a picture helps; never invent photos the user did not provide.',
|
|
131
|
-
]);
|
|
132
|
-
expect(prefsLines(prefs({ design: 'dense' }), 'page')).toContain(
|
|
133
|
-
'A page may carry more text and data when the content needs it.',
|
|
134
|
-
);
|
|
135
|
-
expect(prefsLines(prefs({ autoImages: false }), 'page')).toContain(
|
|
136
|
-
'Do not add any image the user did not provide.',
|
|
137
|
-
);
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('tells the review step how far to check and what to do with a mismatch', () => {
|
|
141
|
-
expect(prefsLines(prefs(), 'review')).toEqual([
|
|
142
|
-
'Write in a steady, professional tone.',
|
|
143
|
-
'Check wording, typos and every number.',
|
|
144
|
-
]);
|
|
145
|
-
expect(prefsLines(prefs({ review: 'numbers' }), 'review')).toContain(
|
|
146
|
-
'Check only the numbers against the reference files.',
|
|
147
|
-
);
|
|
148
|
-
const lenient = prefsLines(prefs({ askOnMismatch: false }), 'review');
|
|
149
|
-
expect(lenient).toContain(
|
|
150
|
-
'When two files disagree on a number, use the one from the spreadsheet (.xlsx, .xls or .csv) and say which you used.',
|
|
151
|
-
);
|
|
152
|
-
});
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
describe('toneForUses', () => {
|
|
156
|
-
it('picks a tone from what the deck is for', () => {
|
|
157
|
-
expect(toneForUses(['report'])).toBe('steady');
|
|
158
|
-
expect(toneForUses(['pitch'])).toBe('steady');
|
|
159
|
-
expect(toneForUses(['lecture'])).toBe('friendly');
|
|
160
|
-
expect(toneForUses(['training'])).toBe('friendly');
|
|
161
|
-
expect(toneForUses(['launch'])).toBe('concise');
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('lets a launch win over anything else picked with it', () => {
|
|
165
|
-
expect(toneForUses(['lecture', 'launch'])).toBe('concise');
|
|
166
|
-
expect(toneForUses(['report', 'training'])).toBe('friendly');
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it('changes nothing for other or an empty pick', () => {
|
|
170
|
-
expect(toneForUses([])).toBeNull();
|
|
171
|
-
expect(toneForUses(['other'])).toBeNull();
|
|
172
|
-
});
|
|
173
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import { buildRestoreGuide, formatSize, restoreGuideFileName } from './guide.ts';
|
|
3
|
-
|
|
4
|
-
const AT = new Date(2026, 10, 1, 21, 30).getTime();
|
|
5
|
-
|
|
6
|
-
describe('the restore guide inside a backup', () => {
|
|
7
|
-
it('says how to restore, in the language of the interface', () => {
|
|
8
|
-
const zh = buildRestoreGuide({
|
|
9
|
-
createdAt: AT,
|
|
10
|
-
decks: 3,
|
|
11
|
-
sizeBytes: 620 * 1024 * 1024,
|
|
12
|
-
appVersion: '0.8.0',
|
|
13
|
-
locale: 'zh-CN',
|
|
14
|
-
});
|
|
15
|
-
expect(zh).toContain('LemonRiver 备份 · 2026-11-01 21:30');
|
|
16
|
-
expect(zh).toContain('3 份演示 · 620 MB · 用 LemonRiver 0.8.0 备份');
|
|
17
|
-
expect(zh).toContain('从备份恢复');
|
|
18
|
-
expect(zh).toContain('https://github.com/SegawaBeer/lemonriver-slide/releases/latest');
|
|
19
|
-
expect(zh).not.toContain('<script');
|
|
20
|
-
|
|
21
|
-
const en = buildRestoreGuide({
|
|
22
|
-
createdAt: AT,
|
|
23
|
-
decks: 1,
|
|
24
|
-
sizeBytes: 2048,
|
|
25
|
-
appVersion: '0.8.0',
|
|
26
|
-
locale: 'en',
|
|
27
|
-
});
|
|
28
|
-
expect(en).toContain('LemonRiver backup · 2026-11-01 21:30');
|
|
29
|
-
expect(en).toContain('1 decks · 2 KB · Made with LemonRiver 0.8.0');
|
|
30
|
-
expect(en).toContain('Settings → Backup');
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
it('names the file per language', () => {
|
|
34
|
-
expect(restoreGuideFileName('zh-CN')).toBe('怎么恢复.html');
|
|
35
|
-
expect(restoreGuideFileName('zh-TW')).toBe('怎麼還原.html');
|
|
36
|
-
expect(restoreGuideFileName('en')).toBe('How to restore.html');
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('formats sizes the way the backup line shows them', () => {
|
|
40
|
-
expect(formatSize(900)).toBe('900 B');
|
|
41
|
-
expect(formatSize(18 * 1024)).toBe('18 KB');
|
|
42
|
-
expect(formatSize(620 * 1024 * 1024)).toBe('620 MB');
|
|
43
|
-
expect(formatSize(1.5 * 1024 * 1024 * 1024)).toBe('1.5 GB');
|
|
44
|
-
});
|
|
45
|
-
});
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest';
|
|
2
|
-
import {
|
|
3
|
-
backupDue,
|
|
4
|
-
backupFileStem,
|
|
5
|
-
DAY_MS,
|
|
6
|
-
isCompressedFile,
|
|
7
|
-
isLargeVideo,
|
|
8
|
-
LARGE_VIDEO_BYTES,
|
|
9
|
-
looksLikeBackupName,
|
|
10
|
-
PREFS_KEYS,
|
|
11
|
-
sanitizePrefs,
|
|
12
|
-
sanitizeSettings,
|
|
13
|
-
} from './model.ts';
|
|
14
|
-
|
|
15
|
-
const SETTINGS = { folder: '/Users/me/Backups', auto: true, skipLargeVideos: false, last: null };
|
|
16
|
-
|
|
17
|
-
describe('backup settings', () => {
|
|
18
|
-
it('falls back to a usable default', () => {
|
|
19
|
-
expect(sanitizeSettings(null)).toEqual({
|
|
20
|
-
folder: null,
|
|
21
|
-
auto: false,
|
|
22
|
-
skipLargeVideos: false,
|
|
23
|
-
last: null,
|
|
24
|
-
});
|
|
25
|
-
expect(sanitizeSettings({ folder: 'relative/path' }).folder).toBeNull();
|
|
26
|
-
expect(sanitizeSettings({}).skipLargeVideos).toBe(false);
|
|
27
|
-
expect(sanitizeSettings({ skipLargeVideos: true }).skipLargeVideos).toBe(true);
|
|
28
|
-
expect(sanitizeSettings({ keep: 30, written: ['a.zip'] })).toEqual({
|
|
29
|
-
folder: null,
|
|
30
|
-
auto: false,
|
|
31
|
-
skipLargeVideos: false,
|
|
32
|
-
last: null,
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('knows when the daily backup is due', () => {
|
|
37
|
-
const now = 1_800_000_000_000;
|
|
38
|
-
expect(backupDue(sanitizeSettings({ ...SETTINGS, auto: false }), now)).toBe(false);
|
|
39
|
-
expect(backupDue(sanitizeSettings({ ...SETTINGS, folder: null }), now)).toBe(false);
|
|
40
|
-
expect(backupDue(sanitizeSettings(SETTINGS), now)).toBe(true);
|
|
41
|
-
expect(
|
|
42
|
-
backupDue(
|
|
43
|
-
sanitizeSettings({ ...SETTINGS, last: { at: now - 23 * 3600_000, ok: true } }),
|
|
44
|
-
now,
|
|
45
|
-
),
|
|
46
|
-
).toBe(false);
|
|
47
|
-
expect(
|
|
48
|
-
backupDue(sanitizeSettings({ ...SETTINGS, last: { at: now - DAY_MS - 1, ok: true } }), now),
|
|
49
|
-
).toBe(true);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('waits an hour before retrying a failed backup', () => {
|
|
53
|
-
const now = 1_800_000_000_000;
|
|
54
|
-
const failed = { at: now - 10 * 60_000, ok: false, path: '', size: 0, error: 'denied' };
|
|
55
|
-
expect(backupDue(sanitizeSettings({ ...SETTINGS, last: failed }), now)).toBe(false);
|
|
56
|
-
const older = { ...failed, at: now - 2 * 3600_000 };
|
|
57
|
-
expect(backupDue(sanitizeSettings({ ...SETTINGS, last: older }), now)).toBe(true);
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
it('names the file after the local date and time', () => {
|
|
61
|
-
const at = new Date(2026, 10, 1, 21, 30).getTime();
|
|
62
|
-
expect(backupFileStem(at)).toBe('LemonRiver 备份 2026-11-01 2130');
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
it('stores formats that are already compressed', () => {
|
|
66
|
-
expect(isCompressedFile('photo.JPG')).toBe(true);
|
|
67
|
-
expect(isCompressedFile('report.pdf')).toBe(true);
|
|
68
|
-
expect(isCompressedFile('deck.pptx')).toBe(true);
|
|
69
|
-
expect(isCompressedFile('index.tsx')).toBe(false);
|
|
70
|
-
expect(isCompressedFile('notes.md')).toBe(false);
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
it('counts only videos past the size limit as large videos', () => {
|
|
74
|
-
expect(isLargeVideo('assets/team/clip.MP4', LARGE_VIDEO_BYTES + 1)).toBe(true);
|
|
75
|
-
expect(isLargeVideo('assets/team/clip.mov', LARGE_VIDEO_BYTES)).toBe(false);
|
|
76
|
-
expect(isLargeVideo('assets/team/huge.zip', LARGE_VIDEO_BYTES + 1)).toBe(false);
|
|
77
|
-
expect(isLargeVideo('assets/team/photo.png', LARGE_VIDEO_BYTES + 1)).toBe(false);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('counts only its own file names as backups', () => {
|
|
81
|
-
expect(looksLikeBackupName('LemonRiver 备份 2026-11-01 2130.zip')).toBe(true);
|
|
82
|
-
expect(looksLikeBackupName('my stuff.zip')).toBe(false);
|
|
83
|
-
expect(looksLikeBackupName('LemonRiver 备份 notes.txt')).toBe(false);
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
describe('prefs that travel with a backup', () => {
|
|
88
|
-
it('keeps the whitelist and drops everything else', () => {
|
|
89
|
-
const kept = sanitizePrefs({
|
|
90
|
-
theme: 'dark',
|
|
91
|
-
'open-slide:locale': 'zh-CN',
|
|
92
|
-
'lemonriver:agent-prefs': '{"tone":"steady"}',
|
|
93
|
-
'open-slide:agent-auto-approve': 'true',
|
|
94
|
-
'lemonriver:session': 'secret',
|
|
95
|
-
'open-slide:home-sort': 3,
|
|
96
|
-
});
|
|
97
|
-
expect(kept).toEqual({
|
|
98
|
-
theme: 'dark',
|
|
99
|
-
'open-slide:locale': 'zh-CN',
|
|
100
|
-
'lemonriver:agent-prefs': '{"tone":"steady"}',
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
it('never carries agent auto-approve', () => {
|
|
105
|
-
expect(PREFS_KEYS as readonly string[]).not.toContain('open-slide:agent-auto-approve');
|
|
106
|
-
expect(sanitizePrefs({ 'open-slide:agent-auto-approve': 'true' })).toEqual({});
|
|
107
|
-
});
|
|
108
|
-
});
|