@lemonriver/core 0.6.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 (62) hide show
  1. package/dist/{build-RlcGG-Ve.js → build-Bdagm0FU.js} +1 -1
  2. package/dist/cli/bin.js +4 -4
  3. package/dist/{config-BJT87wE9.js → config-Begts3gq.js} +6353 -2822
  4. package/dist/{dev-DR-j_xda.js → dev-DjjzmT28.js} +2 -2
  5. package/dist/{preview-BTAhTb5B.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/chrome/app-chrome.tsx +12 -1
  19. package/src/app/lemonriver/features.test.ts +10 -0
  20. package/src/app/lemonriver/features.ts +12 -1
  21. package/src/app/lemonriver/feedback/pending-toast.ts +7 -2
  22. package/src/app/lemonriver/help/help-page.tsx +262 -0
  23. package/src/app/lemonriver/help/model.test.ts +107 -0
  24. package/src/app/lemonriver/help/model.ts +96 -0
  25. package/src/app/lemonriver/home/deck-card.tsx +10 -1
  26. package/src/app/lemonriver/home/home-page.tsx +52 -1
  27. package/src/app/lemonriver/routes.test.tsx +4 -2
  28. package/src/app/lemonriver/routes.tsx +2 -0
  29. package/src/app/lemonriver/settings/backup-restore-dialog.tsx +525 -0
  30. package/src/app/lemonriver/settings/backup-section.tsx +489 -0
  31. package/src/app/lemonriver/settings/settings-page.tsx +22 -0
  32. package/src/app/lemonriver/share/capture.ts +76 -0
  33. package/src/app/lemonriver/share/client.ts +168 -0
  34. package/src/app/lemonriver/share/codes.test.ts +49 -0
  35. package/src/app/lemonriver/share/codes.ts +30 -0
  36. package/src/app/lemonriver/share/compare.test.ts +199 -0
  37. package/src/app/lemonriver/share/compare.ts +367 -0
  38. package/src/app/lemonriver/share/drop.ts +84 -0
  39. package/src/app/lemonriver/share/folder.test.ts +42 -0
  40. package/src/app/lemonriver/share/folder.ts +29 -0
  41. package/src/app/lemonriver/share/freeze.ts +51 -0
  42. package/src/app/lemonriver/share/guide.test.ts +78 -0
  43. package/src/app/lemonriver/share/guide.ts +222 -0
  44. package/src/app/lemonriver/share/import-dialog.tsx +405 -0
  45. package/src/app/lemonriver/share/import-entry.tsx +106 -0
  46. package/src/app/lemonriver/share/model.ts +150 -0
  47. package/src/app/lemonriver/share/naming.test.ts +59 -0
  48. package/src/app/lemonriver/share/naming.ts +71 -0
  49. package/src/app/lemonriver/share/paths.test.ts +116 -0
  50. package/src/app/lemonriver/share/paths.ts +215 -0
  51. package/src/app/lemonriver/share/pdf.test.ts +79 -0
  52. package/src/app/lemonriver/share/pdf.ts +169 -0
  53. package/src/app/lemonriver/share/share-dialog.tsx +339 -0
  54. package/src/app/lemonriver/share/summary.ts +47 -0
  55. package/src/app/lemonriver/slide-extensions.tsx +69 -23
  56. package/src/app/lemonriver/templates/library-page.tsx +5 -2
  57. package/src/app/lemonriver/text/en.ts +588 -0
  58. package/src/app/lemonriver/text/es.ts +146 -0
  59. package/src/app/lemonriver/text/ja.ts +143 -0
  60. package/src/app/lemonriver/text/types.ts +168 -0
  61. package/src/app/lemonriver/text/zh-cn.ts +559 -0
  62. package/src/app/lemonriver/text/zh-tw.ts +559 -0
@@ -5,7 +5,11 @@ const KEY = 'lemonriver:pending-toast';
5
5
  * reloads every client, and the dev server's own reload can land before the
6
6
  * request's response does, so the toast is saved before the request is sent.
7
7
  */
8
- export type PendingToast = { kind: 'trashed' | 'restored'; slideId: string; name: string };
8
+ export type PendingToast = {
9
+ kind: 'trashed' | 'restored' | 'imported';
10
+ slideId: string;
11
+ name: string;
12
+ };
9
13
 
10
14
  export function savePendingToast(toast: PendingToast, storage: Storage = sessionStorage): void {
11
15
  try {
@@ -30,7 +34,8 @@ export function takePendingToast(storage: Storage = sessionStorage): PendingToas
30
34
  if (!raw) return null;
31
35
  try {
32
36
  const value = JSON.parse(raw) as Record<string, unknown>;
33
- if (value.kind !== 'trashed' && value.kind !== 'restored') return null;
37
+ if (value.kind !== 'trashed' && value.kind !== 'restored' && value.kind !== 'imported')
38
+ return null;
34
39
  if (typeof value.slideId !== 'string' || typeof value.name !== 'string') return null;
35
40
  return { kind: value.kind, slideId: value.slideId, name: value.name };
36
41
  } catch {
@@ -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
+ }
@@ -1,4 +1,4 @@
1
- import { Copy, FolderInput, MoreHorizontal, Palette, Pencil, Trash2 } from 'lucide-react';
1
+ import { Copy, FolderInput, MoreHorizontal, Palette, Pencil, Share2, Trash2 } from 'lucide-react';
2
2
  import { useEffect, useState } from 'react';
3
3
  import { Link } from 'react-router-dom';
4
4
  import {
@@ -16,11 +16,13 @@ import { SlidePageProvider } from '../../lib/page-context';
16
16
  import type { SlideModule } from '../../lib/sdk';
17
17
  import { loadSlide } from '../../lib/slides';
18
18
  import { Mascot } from '../brand/mascot';
19
+ import { isFeatureEnabled } from '../features';
19
20
  import { useLrText } from '../text';
20
21
  import { relativeTime } from './time';
21
22
  import { useDelayed } from './use-delayed';
22
23
 
23
24
  export type DeckCardActions = {
25
+ onShare: () => void;
24
26
  onRename: () => void;
25
27
  onDuplicate: () => void;
26
28
  onMove: () => void;
@@ -156,6 +158,7 @@ export function DeckCard({
156
158
  function DeckMenu({ actions }: { actions: DeckCardActions }) {
157
159
  const t = useLocale();
158
160
  const lr = useLrText();
161
+ const shareOn = isFeatureEnabled('share');
159
162
  return (
160
163
  <DropdownMenu>
161
164
  <DropdownMenuTrigger
@@ -170,6 +173,12 @@ function DeckMenu({ actions }: { actions: DeckCardActions }) {
170
173
  }
171
174
  />
172
175
  <DropdownMenuContent align="end" className="min-w-[168px]">
176
+ {shareOn && (
177
+ <DropdownMenuItem onClick={actions.onShare}>
178
+ <Share2 />
179
+ {lr.share.menuItem}
180
+ </DropdownMenuItem>
181
+ )}
173
182
  <DropdownMenuItem onClick={actions.onRename}>
174
183
  <Pencil />
175
184
  {t.common.rename}
@@ -19,6 +19,11 @@ import type { HomeOutletContext } from '../../routes/home-shell';
19
19
  import { FilterPill } from '../chrome/filter-pill';
20
20
  import { isFeatureEnabled } from '../features';
21
21
  import { LemonEmpty } from '../feedback/lemon-empty';
22
+ import { type InspectOk, inspectPackage } from '../share/client';
23
+ import { shareErrorText } from '../share/codes';
24
+ import { ImportDialog } from '../share/import-dialog';
25
+ import { ImportButton, useShareDrop } from '../share/import-entry';
26
+ import { ShareDialog } from '../share/share-dialog';
22
27
  import { OCCASIONS } from '../templates/model';
23
28
  import { useTemplateLibrary } from '../templates/use-library';
24
29
  import { useLrText } from '../text';
@@ -66,6 +71,9 @@ export function LemonRiverHome() {
66
71
  const [occasion, setOccasion] = useState<string | null>(null);
67
72
  const [sortKey, setSortKey] = useSortPref();
68
73
  const [dialog, setDialog] = useState<Dialog>(null);
74
+ const [sharing, setSharing] = useState<{ slideId: string; title: string } | null>(null);
75
+ const [inspection, setInspection] = useState<InspectOk | null>(null);
76
+ const [inspecting, setInspecting] = useState(false);
69
77
 
70
78
  const isAll = selectedId === ALL_SLIDES_ID;
71
79
  const isDraft = selectedId === DRAFT_ID;
@@ -118,11 +126,35 @@ export function LemonRiverHome() {
118
126
  }
119
127
  };
120
128
 
129
+ const inspectBytes = async (bytes: Uint8Array) => {
130
+ if (inspecting) return;
131
+ setInspecting(true);
132
+ try {
133
+ const result = await inspectPackage(bytes);
134
+ if (result.ok) setInspection(result);
135
+ else
136
+ toast.error(
137
+ shareErrorText(lr.share.errors, result.code, result.appVersion, lr.share.unknownVersion),
138
+ );
139
+ } catch {
140
+ toast.error(lr.share.errors.notAPackage);
141
+ } finally {
142
+ setInspecting(false);
143
+ }
144
+ };
145
+
146
+ const { handlers: dropHandlers, hint: dropHint } = useShareDrop({
147
+ onBytes: (bytes) => void inspectBytes(bytes),
148
+ onUnknown: () => toast.error(lr.share.notAPackage),
149
+ });
150
+
121
151
  const current = dialog ? dialog.id : null;
122
152
  const trashOn = isFeatureEnabled('trash');
153
+ const shareOn = isFeatureEnabled('share');
123
154
 
124
155
  return (
125
- <div data-lr-home>
156
+ <div data-lr-home {...(shareOn ? dropHandlers : {})}>
157
+ {shareOn && dropHint}
126
158
  {import.meta.env.DEV && isAll && (
127
159
  <>
128
160
  <header className="mb-6">
@@ -154,6 +186,9 @@ export function LemonRiverHome() {
154
186
  </span>
155
187
  )}
156
188
  <div className="ml-auto flex w-full items-center gap-2 md:w-auto">
189
+ {shareOn && (
190
+ <ImportButton onBytes={(bytes) => void inspectBytes(bytes)} disabled={inspecting} />
191
+ )}
157
192
  <SortControl value={sortKey} onChange={setSortKey} />
158
193
  <SearchInput value={query} onChange={setQuery} />
159
194
  </div>
@@ -225,6 +260,7 @@ export function LemonRiverHome() {
225
260
  templateName={templateNameOf(id)}
226
261
  onTitleResolved={ctx.reportTitle}
227
262
  actions={{
263
+ onShare: () => setSharing({ slideId: id, title: titleOf(id) }),
228
264
  onRename: () => setDialog({ kind: 'rename', id }),
229
265
  onDuplicate: () => void duplicate(id),
230
266
  onMove: () => setDialog({ kind: 'move', id }),
@@ -269,6 +305,21 @@ export function LemonRiverHome() {
269
305
  setDialog(null);
270
306
  }}
271
307
  />
308
+ {shareOn && (
309
+ <>
310
+ <ShareDialog
311
+ open={sharing !== null}
312
+ slideId={sharing?.slideId ?? ''}
313
+ title={sharing?.title ?? ''}
314
+ onOpenChange={(open) => {
315
+ if (!open) setSharing(null);
316
+ }}
317
+ />
318
+ {inspection && (
319
+ <ImportDialog inspection={inspection} onClose={() => setInspection(null)} />
320
+ )}
321
+ </>
322
+ )}
272
323
  </div>
273
324
  );
274
325
  }
@@ -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"