@lemonriver/core 0.7.0 → 0.8.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.
Files changed (38) hide show
  1. package/dist/{build-CKwrex8y.js → build-Bdagm0FU.js} +1 -1
  2. package/dist/cli/bin.js +4 -4
  3. package/dist/{config-B1_gk0sy.js → config-Begts3gq.js} +5921 -3971
  4. package/dist/{dev-DZ2Yzl2p.js → dev-DjjzmT28.js} +2 -2
  5. package/dist/{preview-hMDcuHfP.js → preview-C9y9MTY1.js} +1 -1
  6. package/dist/{update-CMRxtTc9.js → update-b1dSg_FW.js} +17 -17
  7. package/dist/vite/index.js +1 -1
  8. package/package.json +1 -1
  9. package/src/app/lemonriver/backup/client.ts +177 -0
  10. package/src/app/lemonriver/backup/guide.test.ts +45 -0
  11. package/src/app/lemonriver/backup/guide.ts +138 -0
  12. package/src/app/lemonriver/backup/model.test.ts +96 -0
  13. package/src/app/lemonriver/backup/model.ts +255 -0
  14. package/src/app/lemonriver/backup/places.test.ts +154 -0
  15. package/src/app/lemonriver/backup/places.ts +74 -0
  16. package/src/app/lemonriver/board/blocks/snapshot.ts +10 -2
  17. package/src/app/lemonriver/board/self-check-runner.tsx +60 -15
  18. package/src/app/lemonriver/features.test.ts +5 -0
  19. package/src/app/lemonriver/features.ts +11 -1
  20. package/src/app/lemonriver/help/help-page.tsx +262 -0
  21. package/src/app/lemonriver/help/model.test.ts +107 -0
  22. package/src/app/lemonriver/help/model.ts +96 -0
  23. package/src/app/lemonriver/routes.test.tsx +4 -2
  24. package/src/app/lemonriver/routes.tsx +2 -0
  25. package/src/app/lemonriver/settings/backup-restore-dialog.tsx +525 -0
  26. package/src/app/lemonriver/settings/backup-section.tsx +489 -0
  27. package/src/app/lemonriver/settings/settings-page.tsx +22 -0
  28. package/src/app/lemonriver/share/client.ts +6 -0
  29. package/src/app/lemonriver/share/import-dialog.tsx +14 -0
  30. package/src/app/lemonriver/share/paths.test.ts +41 -0
  31. package/src/app/lemonriver/share/paths.ts +45 -11
  32. package/src/app/lemonriver/share/share-dialog.tsx +54 -1
  33. package/src/app/lemonriver/text/en.ts +521 -0
  34. package/src/app/lemonriver/text/es.ts +79 -0
  35. package/src/app/lemonriver/text/ja.ts +76 -0
  36. package/src/app/lemonriver/text/types.ts +90 -0
  37. package/src/app/lemonriver/text/zh-cn.ts +497 -0
  38. package/src/app/lemonriver/text/zh-tw.ts +497 -0
@@ -0,0 +1,262 @@
1
+ import { Cloud, Folder, HardDrive } from 'lucide-react';
2
+ import { useEffect, useMemo, useState } from 'react';
3
+ import { Link, useLocation } from 'react-router-dom';
4
+ import { format } from '@/lib/use-locale';
5
+ import { cn } from '@/lib/utils';
6
+ import { useLrText } from '../text';
7
+ import { useReduceMotionSetting } from '../theme/motion';
8
+ import {
9
+ filterHelpSections,
10
+ type HelpBlock,
11
+ type HelpContent,
12
+ type HelpItem,
13
+ type HelpSection,
14
+ } from './model';
15
+
16
+ const HIGHLIGHT_MS = 1500;
17
+
18
+ function Inline({ text, values }: { text: string; values: Record<string, string> }) {
19
+ const filled = format(text, values);
20
+ let at = 0;
21
+ const parts = filled.split(/(https?:\/\/[^\s)]+)/g).map((part) => {
22
+ const key = `${at}`;
23
+ at += part.length;
24
+ return { key, part };
25
+ });
26
+ return (
27
+ <>
28
+ {parts.map(({ key, part }) =>
29
+ /^https?:\/\//.test(part) ? (
30
+ <a
31
+ key={key}
32
+ href={part}
33
+ target="_blank"
34
+ rel="noreferrer"
35
+ className="break-all text-foreground underline underline-offset-2"
36
+ >
37
+ {part}
38
+ </a>
39
+ ) : (
40
+ <span key={key}>{part}</span>
41
+ ),
42
+ )}
43
+ </>
44
+ );
45
+ }
46
+
47
+ function Item({ item, values }: { item: HelpItem; values: Record<string, string> }) {
48
+ return (
49
+ <li className="leading-relaxed">
50
+ {item.strong !== undefined && (
51
+ <strong className="font-semibold">
52
+ <Inline text={item.strong} values={values} />
53
+ </strong>
54
+ )}
55
+ <Inline text={item.text} values={values} />
56
+ {item.children !== undefined && item.children.length > 0 && (
57
+ <ul className="mt-1 list-disc space-y-0.5 pl-5 text-[13.5px] text-muted-foreground">
58
+ {item.children.map((child) => (
59
+ <li key={child} className="leading-relaxed">
60
+ <Inline text={child} values={values} />
61
+ </li>
62
+ ))}
63
+ </ul>
64
+ )}
65
+ </li>
66
+ );
67
+ }
68
+
69
+ function Block({ block, values }: { block: HelpBlock; values: Record<string, string> }) {
70
+ if (block.kind === 'p') {
71
+ return (
72
+ <p className="text-[14px] leading-relaxed">
73
+ {block.strong !== undefined && (
74
+ <strong className="font-semibold">
75
+ <Inline text={block.strong} values={values} />
76
+ </strong>
77
+ )}
78
+ <Inline text={block.text} values={values} />
79
+ </p>
80
+ );
81
+ }
82
+ if (block.kind === 'note') {
83
+ return (
84
+ <div className="flex items-start gap-2.5 rounded-[10px] border border-[var(--lr-warn-border,var(--lr-accent))] bg-[var(--lr-accent-soft)] px-3 py-2.5 text-[13.5px] leading-relaxed">
85
+ <strong className="shrink-0 font-semibold">
86
+ <Inline text={block.strong} values={values} />
87
+ </strong>
88
+ <span>
89
+ <Inline text={block.text} values={values} />
90
+ </span>
91
+ </div>
92
+ );
93
+ }
94
+ if (block.kind === 'steps') {
95
+ return (
96
+ <ol className="list-decimal space-y-1.5 pl-5 text-[14px]">
97
+ {block.items.map((item) => (
98
+ <Item key={item.text} item={item} values={values} />
99
+ ))}
100
+ </ol>
101
+ );
102
+ }
103
+ return (
104
+ <ul className="list-disc space-y-1.5 pl-5 text-[14px]">
105
+ {block.items.map((item) => (
106
+ <Item key={item.text} item={item} values={values} />
107
+ ))}
108
+ </ul>
109
+ );
110
+ }
111
+
112
+ function SectionIcon({ section }: { section: HelpSection }) {
113
+ if (section.icon === undefined) return null;
114
+ const className = 'size-4 shrink-0 text-muted-foreground';
115
+ if (section.icon === 'folder') return <Folder className={className} aria-hidden />;
116
+ if (section.icon === 'drive') return <HardDrive className={className} aria-hidden />;
117
+ return <Cloud className={className} aria-hidden />;
118
+ }
119
+
120
+ function Section({
121
+ section,
122
+ values,
123
+ highlighted,
124
+ }: {
125
+ section: HelpSection;
126
+ values: Record<string, string>;
127
+ highlighted: boolean;
128
+ }) {
129
+ let at = 0;
130
+ return (
131
+ <section
132
+ id={`help-${section.id}`}
133
+ data-lr-help-section={section.id}
134
+ className="scroll-mt-6 border-t border-border pt-6 first:border-t-0 first:pt-0"
135
+ >
136
+ <h2
137
+ className={cn(
138
+ '-mx-1 rounded-[8px] px-1 font-heading text-[20px] font-bold leading-[27px] tracking-[-0.01em] transition-colors',
139
+ highlighted && 'bg-[var(--lr-accent-soft)]',
140
+ )}
141
+ >
142
+ <span className="inline-flex items-center gap-2">
143
+ <SectionIcon section={section} />
144
+ <Inline text={section.title} values={values} />
145
+ </span>
146
+ </h2>
147
+ <div className="mt-3 flex flex-col gap-3">
148
+ {section.blocks.map((block) => {
149
+ const key = `${section.id}-${at}`;
150
+ at += JSON.stringify(block).length;
151
+ return <Block key={key} block={block} values={values} />;
152
+ })}
153
+ </div>
154
+ </section>
155
+ );
156
+ }
157
+
158
+ function Index({ help }: { help: HelpContent }) {
159
+ const top = help.sections.filter((section) => section.parent === undefined);
160
+ return (
161
+ <nav className="flex flex-col gap-1 text-[13.5px]">
162
+ {top.map((section) => {
163
+ const children = help.sections.filter((child) => child.parent === section.id);
164
+ return (
165
+ <div key={section.id} className="flex flex-col gap-0.5">
166
+ <Link
167
+ to={`/help#${section.id}`}
168
+ data-lr-help-nav={section.id}
169
+ className="rounded-[6px] px-2 py-1 font-medium outline-none hover:bg-muted/50 focus-visible:ring-2 focus-visible:ring-ring/40"
170
+ >
171
+ {section.title}
172
+ </Link>
173
+ {children.length > 0 && (
174
+ <div className="ml-2 flex flex-col gap-0.5 border-l border-border pl-2">
175
+ {children.map((child) => (
176
+ <Link
177
+ key={child.id}
178
+ to={`/help#${child.id}`}
179
+ data-lr-help-nav={child.id}
180
+ className="rounded-[6px] px-2 py-1 text-[13px] text-muted-foreground outline-none hover:bg-muted/50 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40"
181
+ >
182
+ {child.title}
183
+ </Link>
184
+ ))}
185
+ </div>
186
+ )}
187
+ </div>
188
+ );
189
+ })}
190
+ </nav>
191
+ );
192
+ }
193
+
194
+ export function HelpPage() {
195
+ const lr = useLrText();
196
+ const help = lr.help;
197
+ const location = useLocation();
198
+ const reduceMotion = useReduceMotionSetting();
199
+ const [query, setQuery] = useState('');
200
+ const [highlight, setHighlight] = useState<string | null>(null);
201
+
202
+ const sections = useMemo(() => filterHelpSections(help.sections, query), [help.sections, query]);
203
+ const searching = query.trim() !== '';
204
+
205
+ const anchor = location.hash.replace(/^#/, '');
206
+
207
+ useEffect(() => {
208
+ if (anchor === '') return;
209
+ const target = document.getElementById(`help-${anchor}`);
210
+ if (!target) return;
211
+ target.scrollIntoView({ behavior: reduceMotion ? 'auto' : 'smooth', block: 'start' });
212
+ setHighlight(anchor);
213
+ const timer = setTimeout(() => setHighlight(null), HIGHLIGHT_MS);
214
+ return () => clearTimeout(timer);
215
+ }, [anchor, reduceMotion]);
216
+
217
+ return (
218
+ <div data-lr-help className="flex max-w-[1020px] gap-10">
219
+ {!searching && (
220
+ <aside className="sticky top-6 hidden w-[210px] shrink-0 self-start md:block">
221
+ <Index help={help} />
222
+ </aside>
223
+ )}
224
+
225
+ <div className="min-w-0 max-w-[720px] flex-1">
226
+ <header className="mb-5">
227
+ <h1 className="font-heading text-[28px] font-bold leading-[34px] tracking-[-0.01em]">
228
+ {help.title}
229
+ </h1>
230
+ <p className="mt-0.5 text-[14px] text-muted-foreground">{help.intro}</p>
231
+ </header>
232
+
233
+ <input
234
+ type="search"
235
+ data-lr-help-search
236
+ value={query}
237
+ onChange={(event) => setQuery(event.target.value)}
238
+ placeholder={help.searchPlaceholder}
239
+ aria-label={help.searchPlaceholder}
240
+ className="mb-6 w-full rounded-[10px] border border-border bg-card px-3 py-2 text-[14px] outline-none focus-visible:ring-2 focus-visible:ring-ring/40"
241
+ />
242
+
243
+ {sections.length === 0 ? (
244
+ <p data-lr-help-empty className="text-[14px] text-muted-foreground">
245
+ {help.noResults}
246
+ </p>
247
+ ) : (
248
+ <div className="flex flex-col gap-6">
249
+ {sections.map((section) => (
250
+ <Section
251
+ key={section.id}
252
+ section={section}
253
+ values={help.buttons}
254
+ highlighted={highlight === section.id}
255
+ />
256
+ ))}
257
+ </div>
258
+ )}
259
+ </div>
260
+ </div>
261
+ );
262
+ }
@@ -0,0 +1,107 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import type { Locale } from '../../../locale/types.ts';
3
+ import { lrTextFor } from '../text/all';
4
+ import { filterHelpSections, helpAnchorForPlace, helpStrings, placeholdersIn } from './model.ts';
5
+
6
+ const ANCHORS = [
7
+ 'share',
8
+ 'import',
9
+ 'backup',
10
+ 'restore',
11
+ 'cloud',
12
+ 'cloud-icloud',
13
+ 'cloud-baidu',
14
+ 'cloud-weiyun',
15
+ 'cloud-dropbox',
16
+ 'cloud-onedrive',
17
+ 'cloud-nutstore',
18
+ 'cloud-other',
19
+ 'cloud-faq',
20
+ ];
21
+
22
+ const PLACES = [
23
+ 'icloud',
24
+ 'dropbox',
25
+ 'onedrive',
26
+ 'baidu',
27
+ 'nutstore',
28
+ 'other',
29
+ 'local',
30
+ 'google',
31
+ ] as const;
32
+
33
+ const LOCALES: Locale['id'][] = ['en', 'es', 'ja', 'zh-CN', 'zh-TW'];
34
+
35
+ describe('the help page', () => {
36
+ const zh = lrTextFor('zh-CN');
37
+
38
+ it('has one section for every anchor the app links to', () => {
39
+ expect(zh.help.sections.map((section) => section.id)).toEqual(ANCHORS);
40
+ for (const place of PLACES) {
41
+ expect(ANCHORS, place).toContain(helpAnchorForPlace(place));
42
+ }
43
+ const ids = new Set(zh.help.sections.map((section) => section.id));
44
+ for (const section of zh.help.sections) {
45
+ if (section.parent !== undefined) expect(ids, section.id).toContain(section.parent);
46
+ }
47
+ });
48
+
49
+ it('names every app button the way the interface does', () => {
50
+ // Japanese and Spanish show the English help, so they keep the English names.
51
+ for (const id of ['en', 'zh-CN', 'zh-TW'] as const) {
52
+ const text = lrTextFor(id);
53
+ const buttons = text.help.buttons;
54
+ const expected = {
55
+ settings: text.settings.title,
56
+ backupSection: text.backup.title,
57
+ share: text.share.open,
58
+ generate: text.share.generate,
59
+ import: text.share.importAction,
60
+ backupNow: text.backup.runNow,
61
+ autoBackup: text.backup.auto,
62
+ keep: text.backup.keep,
63
+ restore: text.backup.restore,
64
+ restoreGo: text.backup.restoreGo,
65
+ chooseOtherFile: text.backup.chooseOtherFile,
66
+ change: text.backup.change,
67
+ chooseOther: text.backup.chooseOther,
68
+ reveal: text.backup.reveal,
69
+ };
70
+ for (const [key, value] of Object.entries(expected)) {
71
+ expect(buttons[key as keyof typeof buttons], `${id}: ${key}`).toBe(value);
72
+ }
73
+ }
74
+ });
75
+
76
+ it('fills every placeholder from the button list', () => {
77
+ for (const id of LOCALES) {
78
+ const help = lrTextFor(id).help;
79
+ const keys = new Set(Object.keys(help.buttons));
80
+ for (const text of helpStrings(help)) {
81
+ for (const name of placeholdersIn(text)) {
82
+ expect(keys, `${id}: ${text}`).toContain(name);
83
+ }
84
+ }
85
+ }
86
+ });
87
+
88
+ it('searches the body, not only the titles', () => {
89
+ const ids = (query: string) => filterHelpSections(zh.help.sections, query).map((s) => s.id);
90
+ // Only this section's body says 冲突副本; its title does not.
91
+ expect(ids('冲突副本')).toEqual(['cloud-faq']);
92
+ expect(ids('iCloud')).toEqual(['cloud-icloud']);
93
+ expect(ids('Dropbox')).toEqual(['cloud-dropbox']);
94
+ expect(ids('没有这个词')).toEqual([]);
95
+ });
96
+
97
+ it('has the same sections in every language', () => {
98
+ const counts = LOCALES.map((id) => lrTextFor(id).help.sections.length);
99
+ expect(counts).toEqual(LOCALES.map(() => ANCHORS.length));
100
+ for (const id of LOCALES) {
101
+ expect(
102
+ lrTextFor(id).help.sections.map((section) => section.id),
103
+ id,
104
+ ).toEqual(ANCHORS);
105
+ }
106
+ });
107
+ });
@@ -0,0 +1,96 @@
1
+ import type { BackupPlaceKind } from '../backup/model';
2
+
3
+ export type HelpItem = { text: string; strong?: string; children?: string[] };
4
+
5
+ export type HelpBlock =
6
+ | { kind: 'p'; text: string; strong?: string }
7
+ | { kind: 'steps'; items: HelpItem[] }
8
+ | { kind: 'list'; items: HelpItem[] }
9
+ | { kind: 'note'; text: string; strong: string };
10
+
11
+ export type HelpSection = {
12
+ id: string;
13
+ title: string;
14
+ blocks: HelpBlock[];
15
+ /** The icon the backup location list uses for this drive. */
16
+ icon?: 'cloud' | 'folder' | 'drive';
17
+ /** Set on the cloud drive sections, so they hang under "cloud" in the index. */
18
+ parent?: string;
19
+ };
20
+
21
+ export type HelpButtonKey =
22
+ | 'settings'
23
+ | 'backupSection'
24
+ | 'share'
25
+ | 'generate'
26
+ | 'import'
27
+ | 'backupNow'
28
+ | 'autoBackup'
29
+ | 'keep'
30
+ | 'restore'
31
+ | 'restoreGo'
32
+ | 'chooseOtherFile'
33
+ | 'change'
34
+ | 'chooseOther'
35
+ | 'reveal';
36
+
37
+ export type HelpContent = {
38
+ title: string;
39
+ intro: string;
40
+ searchPlaceholder: string;
41
+ noResults: string;
42
+ buttons: Record<HelpButtonKey, string>;
43
+ sections: HelpSection[];
44
+ };
45
+
46
+ function itemText(item: HelpItem): string {
47
+ return [item.strong ?? '', item.text, ...(item.children ?? [])].join(' ');
48
+ }
49
+
50
+ /** The text a search looks at: the title and everything under it. */
51
+ export function helpSectionText(section: HelpSection): string {
52
+ const parts = [section.title];
53
+ for (const block of section.blocks) {
54
+ if (block.kind === 'p' || block.kind === 'note') {
55
+ parts.push(block.strong ?? '', block.text);
56
+ continue;
57
+ }
58
+ for (const item of block.items) parts.push(itemText(item));
59
+ }
60
+ return parts.join(' ');
61
+ }
62
+
63
+ export function filterHelpSections(sections: HelpSection[], query: string): HelpSection[] {
64
+ const needle = query.trim().toLowerCase();
65
+ if (needle === '') return sections;
66
+ return sections.filter((section) => helpSectionText(section).toLowerCase().includes(needle));
67
+ }
68
+
69
+ /** `/help#cloud-<kind>` where the drive has its own section; the rest share one. */
70
+ export function helpAnchorForPlace(kind: BackupPlaceKind): string {
71
+ if (kind === 'local') return 'backup';
72
+ if (kind === 'google') return 'cloud-other';
73
+ return `cloud-${kind}`;
74
+ }
75
+
76
+ /** `{name}` placeholders a help string fills from the button list. */
77
+ export function placeholdersIn(text: string): string[] {
78
+ return [...text.matchAll(/\{([a-zA-Z]+)\}/g)].map((match) => match[1] ?? '');
79
+ }
80
+
81
+ export function helpStrings(content: HelpContent): string[] {
82
+ const out = [content.title, content.intro, content.searchPlaceholder, content.noResults];
83
+ for (const section of content.sections) {
84
+ out.push(section.title);
85
+ for (const block of section.blocks) {
86
+ if (block.kind === 'p') out.push(block.text, block.strong ?? '');
87
+ else if (block.kind === 'note') out.push(block.strong, block.text);
88
+ else {
89
+ for (const item of block.items) {
90
+ out.push(item.text, item.strong ?? '', ...(item.children ?? []));
91
+ }
92
+ }
93
+ }
94
+ }
95
+ return out.filter((text) => text !== '');
96
+ }
@@ -4,6 +4,7 @@ import { describe, expect, it, vi } from 'vitest';
4
4
  vi.mock('./features', () => ({ isFeatureEnabled: vi.fn(() => true) }));
5
5
  vi.mock('./chrome/not-found', () => ({ NotFound: () => null }));
6
6
  vi.mock('./home/home-page', () => ({ LemonRiverHome: () => null }));
7
+ vi.mock('./help/help-page', () => ({ HelpPage: () => null }));
7
8
  vi.mock('./settings/settings-page', () => ({ SettingsPage: () => null }));
8
9
  vi.mock('./trash/trash-page', () => ({ TrashPage: () => null }));
9
10
 
@@ -31,11 +32,12 @@ describe('lemonRiverRoutes', () => {
31
32
  });
32
33
 
33
34
  describe('lemonRiverShellRoutes', () => {
34
- it('puts our home and the guided flow first, then settings, templates and trash', () => {
35
+ it('puts our home and the guided flow first, then settings, help, templates and trash', () => {
35
36
  expect(paths(lemonRiverShellRoutes())).toEqual([
36
37
  '/',
37
38
  '/new',
38
39
  '/settings',
40
+ '/help',
39
41
  '/templates',
40
42
  '/trash',
41
43
  ]);
@@ -43,7 +45,7 @@ describe('lemonRiverShellRoutes', () => {
43
45
 
44
46
  it('leaves out the pages whose feature is off', () => {
45
47
  vi.mocked(isFeatureEnabled).mockImplementation((id) => id !== 'trash' && id !== 'templates');
46
- expect(paths(lemonRiverShellRoutes())).toEqual(['/', '/new', '/settings']);
48
+ expect(paths(lemonRiverShellRoutes())).toEqual(['/', '/new', '/settings', '/help']);
47
49
  vi.mocked(isFeatureEnabled).mockReturnValue(true);
48
50
  });
49
51
  });
@@ -2,6 +2,7 @@ import { lazy, Suspense } from 'react';
2
2
  import { Route } from 'react-router-dom';
3
3
  import { NotFound } from './chrome/not-found';
4
4
  import { isFeatureEnabled } from './features';
5
+ import { HelpPage } from './help/help-page';
5
6
  import { LemonRiverHome } from './home/home-page';
6
7
  import { SettingsPage } from './settings/settings-page';
7
8
  import { TrashPage } from './trash/trash-page';
@@ -78,6 +79,7 @@ export function lemonRiverShellRoutes() {
78
79
  isFeatureEnabled('settings') && (
79
80
  <Route key="settings" path="/settings" element={<SettingsPage />} />
80
81
  ),
82
+ isFeatureEnabled('help') && <Route key="help" path="/help" element={<HelpPage />} />,
81
83
  isFeatureEnabled('templates') && (
82
84
  <Route
83
85
  key="templates"