@lemonriver/core 1.0.2 → 1.1.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 (39) hide show
  1. package/dist/{build-DYN-H65n.js → build-Dm7gVRhb.js} +1 -1
  2. package/dist/cli/bin.js +3 -3
  3. package/dist/{config-DW1wSoxa.js → config-CubOIzrs.js} +1950 -1429
  4. package/dist/{dev-_VDoRfAK.js → dev-DgLeXPqp.js} +1 -1
  5. package/dist/{preview-CYIGh3Z8.js → preview-CxXQpPk5.js} +1 -1
  6. package/dist/vite/index.js +1 -1
  7. package/package.json +1 -1
  8. package/src/app/components/command/slide-command-menu.tsx +0 -9
  9. package/src/app/lemonriver/backup/client.ts +25 -1
  10. package/src/app/lemonriver/backup/model.test.ts +19 -7
  11. package/src/app/lemonriver/backup/model.ts +63 -18
  12. package/src/app/lemonriver/board/board-page.tsx +2 -2
  13. package/src/app/lemonriver/help/model.test.ts +1 -1
  14. package/src/app/lemonriver/help/model.ts +1 -1
  15. package/src/app/lemonriver/home/drafts.test.ts +23 -0
  16. package/src/app/lemonriver/home/drafts.ts +57 -0
  17. package/src/app/lemonriver/home/home-page.tsx +94 -10
  18. package/src/app/lemonriver/home/organize-drafts.tsx +192 -0
  19. package/src/app/lemonriver/outline/outline-page.tsx +8 -1
  20. package/src/app/lemonriver/settings/backup-restore-dialog.tsx +15 -1
  21. package/src/app/lemonriver/settings/backup-section.tsx +146 -28
  22. package/src/app/lemonriver/settings/settings-page.tsx +3 -0
  23. package/src/app/lemonriver/settings/workspace-card.tsx +53 -0
  24. package/src/app/lemonriver/settings/workspace.ts +37 -0
  25. package/src/app/lemonriver/share/editor-share.tsx +55 -0
  26. package/src/app/lemonriver/share/import-dialog.tsx +14 -0
  27. package/src/app/lemonriver/share/naming.test.ts +11 -0
  28. package/src/app/lemonriver/share/naming.ts +6 -1
  29. package/src/app/lemonriver/slide-extensions.tsx +37 -53
  30. package/src/app/lemonriver/text/en.ts +46 -11
  31. package/src/app/lemonriver/text/es.ts +39 -6
  32. package/src/app/lemonriver/text/ja.ts +39 -6
  33. package/src/app/lemonriver/text/types.ts +45 -6
  34. package/src/app/lemonriver/text/zh-cn.ts +47 -11
  35. package/src/app/lemonriver/text/zh-tw.ts +47 -11
  36. package/src/app/lemonriver/update/beta-badge.tsx +69 -0
  37. package/src/app/lib/export-html.ts +5 -3
  38. package/src/app/lib/export-pptx.ts +5 -4
  39. package/src/app/routes/slide.tsx +6 -57
@@ -0,0 +1,192 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { toast } from 'sonner';
3
+ import { Button } from '@/components/ui/button';
4
+ import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog';
5
+ import { Input } from '@/components/ui/input';
6
+ import {
7
+ Select,
8
+ SelectContent,
9
+ SelectItem,
10
+ SelectTrigger,
11
+ SelectValue,
12
+ } from '@/components/ui/select';
13
+ import { format, plural } from '@/lib/use-locale';
14
+ import { useSlideModule } from '@/lib/use-slide-module';
15
+ import { useLrText } from '../text';
16
+ import { suggestedFolder } from './drafts';
17
+
18
+ const STAY = '__stay__';
19
+ const NEW_FOLDER = '__new__';
20
+
21
+ type Choice = string | null;
22
+
23
+ async function createFolder(name: string): Promise<{ id: string }> {
24
+ const res = await fetch('/__folders', {
25
+ method: 'POST',
26
+ headers: { 'content-type': 'application/json' },
27
+ body: JSON.stringify({ name, icon: { type: 'color', value: '#9bc929' } }),
28
+ });
29
+ if (!res.ok) throw new Error(`POST /__folders ${res.status}`);
30
+ const folder = (await res.json()) as { id?: unknown };
31
+ if (typeof folder.id !== 'string') throw new Error('no folder id');
32
+ return { id: folder.id };
33
+ }
34
+
35
+ function DraftRow({
36
+ slideId,
37
+ title,
38
+ folders,
39
+ choice,
40
+ newName,
41
+ onChoice,
42
+ onNewName,
43
+ }: {
44
+ slideId: string;
45
+ title: string;
46
+ folders: { id: string; name: string }[];
47
+ choice: Choice;
48
+ newName: string;
49
+ onChoice: (next: string | null) => void;
50
+ onNewName: (next: string) => void;
51
+ }) {
52
+ const lr = useLrText();
53
+ const { slide } = useSlideModule(slideId);
54
+ const pages = slide?.default.length ?? 0;
55
+
56
+ return (
57
+ <div
58
+ data-lr-organize-row
59
+ className="flex flex-wrap items-center gap-2 border-b border-hairline py-2.5 last:border-b-0"
60
+ >
61
+ <div className="min-w-0 flex-1">
62
+ <p className="truncate text-[13.5px] font-medium text-foreground">{title}</p>
63
+ <p className="text-[11.5px] text-muted-foreground">
64
+ {format(plural(pages, lr.home.pages), { n: pages })}
65
+ </p>
66
+ </div>
67
+ <Select
68
+ value={choice === null ? STAY : choice === NEW_FOLDER ? NEW_FOLDER : choice}
69
+ items={{
70
+ [STAY]: lr.home.organizeStay,
71
+ ...Object.fromEntries(folders.map((folder) => [folder.id, folder.name])),
72
+ [NEW_FOLDER]: lr.home.organizeNew,
73
+ }}
74
+ onValueChange={onChoice}
75
+ >
76
+ <SelectTrigger className="w-[190px]" aria-label={title}>
77
+ <SelectValue />
78
+ </SelectTrigger>
79
+ <SelectContent>
80
+ <SelectItem value={STAY}>{lr.home.organizeStay}</SelectItem>
81
+ {folders.map((folder) => (
82
+ <SelectItem key={folder.id} value={folder.id}>
83
+ {folder.name}
84
+ </SelectItem>
85
+ ))}
86
+ <SelectItem value={NEW_FOLDER}>{lr.home.organizeNew}</SelectItem>
87
+ </SelectContent>
88
+ </Select>
89
+ {choice === NEW_FOLDER && (
90
+ <Input
91
+ className="w-[190px]"
92
+ value={newName}
93
+ placeholder={lr.home.organizeNamePlaceholder}
94
+ aria-label={lr.home.organizeNamePlaceholder}
95
+ onChange={(event) => onNewName(event.target.value)}
96
+ />
97
+ )}
98
+ </div>
99
+ );
100
+ }
101
+
102
+ export function OrganizeDraftsDialog({
103
+ open,
104
+ drafts,
105
+ titleOf,
106
+ folders,
107
+ onClose,
108
+ onAssign,
109
+ }: {
110
+ open: boolean;
111
+ drafts: string[];
112
+ titleOf: (id: string) => string;
113
+ folders: { id: string; name: string }[];
114
+ onClose: () => void;
115
+ onAssign: (slideId: string, folderId: string | null) => Promise<void>;
116
+ }) {
117
+ const lr = useLrText();
118
+ const [choices, setChoices] = useState<Record<string, Choice>>({});
119
+ const [names, setNames] = useState<Record<string, string>>({});
120
+ const [busy, setBusy] = useState(false);
121
+
122
+ // Suggestions are a starting point for one visit, not something to keep
123
+ // refreshing while the user edits the rows.
124
+ // biome-ignore lint/correctness/useExhaustiveDependencies: reset on open
125
+ useEffect(() => {
126
+ if (!open) return;
127
+ setChoices(
128
+ Object.fromEntries(drafts.map((id) => [id, suggestedFolder(folders, titleOf(id))] as const)),
129
+ );
130
+ setNames({});
131
+ setBusy(false);
132
+ }, [open]);
133
+
134
+ const moving = drafts.filter((id) => choices[id] !== null && choices[id] !== undefined);
135
+
136
+ const move = async () => {
137
+ if (busy || moving.length === 0) return;
138
+ setBusy(true);
139
+ try {
140
+ const created = new Map<string, string>();
141
+ for (const id of moving) {
142
+ let target = choices[id] as string;
143
+ if (target === NEW_FOLDER) {
144
+ const name = (names[id] ?? '').trim() || titleOf(id);
145
+ const known = created.get(name) ?? folders.find((f) => f.name === name)?.id;
146
+ target = known ?? (await createFolder(name)).id;
147
+ created.set(name, target);
148
+ }
149
+ if (target !== STAY) await onAssign(id, target);
150
+ }
151
+ onClose();
152
+ } catch {
153
+ toast.error(lr.home.organizeFailed);
154
+ } finally {
155
+ setBusy(false);
156
+ }
157
+ };
158
+
159
+ return (
160
+ <Dialog open={open} onOpenChange={(next) => !next && onClose()}>
161
+ <DialogContent className="sm:max-w-[560px]" data-lr-organize-dialog>
162
+ <DialogHeader>
163
+ <DialogTitle>{lr.home.organizeTitle}</DialogTitle>
164
+ </DialogHeader>
165
+ <div className="max-h-[50vh] overflow-y-auto">
166
+ {drafts.map((id) => (
167
+ <DraftRow
168
+ key={id}
169
+ slideId={id}
170
+ title={titleOf(id)}
171
+ folders={folders}
172
+ choice={choices[id] ?? null}
173
+ newName={names[id] ?? ''}
174
+ onChoice={(next) =>
175
+ setChoices((prev) => ({
176
+ ...prev,
177
+ [id]: next === STAY ? null : next,
178
+ }))
179
+ }
180
+ onNewName={(next) => setNames((prev) => ({ ...prev, [id]: next }))}
181
+ />
182
+ ))}
183
+ </div>
184
+ <div className="flex justify-end">
185
+ <Button disabled={busy || moving.length === 0} onClick={() => void move()}>
186
+ {format(lr.home.organizeMove, { n: moving.length })}
187
+ </Button>
188
+ </div>
189
+ </DialogContent>
190
+ </Dialog>
191
+ );
192
+ }
@@ -38,6 +38,7 @@ import {
38
38
  useAgentStatus,
39
39
  } from '@/lib/agent/use-agent';
40
40
  import { format, useLocale } from '@/lib/use-locale';
41
+ import { useSlideModule } from '@/lib/use-slide-module';
41
42
  import { cn } from '@/lib/utils';
42
43
  import { readPrefs } from '../agent-prefs/prefs';
43
44
  import { Mascot } from '../brand/mascot';
@@ -88,6 +89,7 @@ export function OutlineView() {
88
89
  const prefsLr = useLrText().prefs;
89
90
  const locale = useLocale();
90
91
  const navigate = useNavigate();
92
+ const { slide: deck } = useSlideModule(slideId);
91
93
  const { sessions } = useAgentSessions();
92
94
  const { provider } = useAgentStatus();
93
95
  const latestSession = sessions
@@ -281,7 +283,12 @@ export function OutlineView() {
281
283
  <div className="mx-auto w-full max-w-[820px] px-6 py-8">
282
284
  <button
283
285
  type="button"
284
- onClick={() => navigate('/')}
286
+ onClick={() =>
287
+ navigate(
288
+ (deck?.default.length ?? 0) === 0 ? '/' : `/s/${encodeURIComponent(slideId)}`,
289
+ { replace: true },
290
+ )
291
+ }
285
292
  className="mb-6 inline-flex items-center gap-1.5 text-[13px] text-muted-foreground outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40"
286
293
  >
287
294
  <ArrowLeft className="size-3.5" />
@@ -306,7 +306,16 @@ export function BackupRestoreDialog({
306
306
  >
307
307
  <span className="w-full truncate text-[13.5px] font-medium">{item.name}</span>
308
308
  <span className="text-[12px] text-muted-foreground">
309
- {formatSize(item.size)} · {when(item.at, locale.id)}
309
+ {item.kind === 'snapshot'
310
+ ? format(b.snapshotLine, {
311
+ decks: item.decks ?? 0,
312
+ size: formatSize(item.size),
313
+ when: when(item.at, locale.id),
314
+ })
315
+ : format(b.zipLine, {
316
+ size: formatSize(item.size),
317
+ when: when(item.at, locale.id),
318
+ })}
310
319
  </span>
311
320
  </button>
312
321
  ))}
@@ -416,6 +425,11 @@ export function BackupRestoreDialog({
416
425
  {format(b.previewThemes, { n: chosen.preview.themes })}
417
426
  </p>
418
427
  )}
428
+ {(chosen.preview.skipped?.length ?? 0) > 0 && (
429
+ <p data-lr-backup-skipped className="text-[12.5px] text-muted-foreground">
430
+ {format(b.restoreSkipped, { n: chosen.preview.skipped?.length ?? 0 })}
431
+ </p>
432
+ )}
419
433
 
420
434
  <label className="flex items-center gap-2 text-[13px]">
421
435
  <input
@@ -7,8 +7,11 @@ import { Progress } from '@/components/ui/progress';
7
7
  import { format, useLocale } from '@/lib/use-locale';
8
8
  import { useAgentPrefs } from '../agent-prefs/use-prefs';
9
9
  import {
10
+ backupList,
10
11
  backupPlaces,
11
12
  backupSettings,
13
+ backupSummary,
14
+ exportBackup,
12
15
  pendingRestoreJob,
13
16
  pickBackupFolder,
14
17
  revealBackup,
@@ -21,9 +24,10 @@ import { formatSize } from '../backup/guide';
21
24
  import {
22
25
  BACKUP_TOO_LARGE,
23
26
  type BackupJob,
27
+ type BackupListItem,
24
28
  type BackupPlace,
25
29
  type BackupSettings,
26
- KEEP_CHOICES,
30
+ type BackupSummary,
27
31
  PREFS_KEYS,
28
32
  type PrefsSnapshot,
29
33
  } from '../backup/model';
@@ -117,6 +121,7 @@ export function BackupSection() {
117
121
 
118
122
  const [settings, setSettings] = useState<BackupSettings | null>(null);
119
123
  const [dir, setDir] = useState<string | null>(null);
124
+ const [summary, setSummary] = useState<BackupSummary | null>(null);
120
125
  const [places, setPlaces] = useState<BackupPlace[]>([]);
121
126
  const [pickerOpen, setPickerOpen] = useState(false);
122
127
  const [pasteMode, setPasteMode] = useState(false);
@@ -124,19 +129,25 @@ export function BackupSection() {
124
129
  const [notice, setNotice] = useState('');
125
130
  const [job, setJob] = useState<BackupJob | null>(null);
126
131
  const [restoreOpen, setRestoreOpen] = useState(false);
132
+ const [exportOpen, setExportOpen] = useState(false);
133
+ const [exportItems, setExportItems] = useState<BackupListItem[]>([]);
134
+ const [exportNotice, setExportNotice] = useState('');
135
+ const [exporting, setExporting] = useState(false);
127
136
 
128
137
  const running = job?.state === 'running';
129
138
 
130
139
  const load = useCallback(async () => {
131
- const [info, found] = await Promise.all([
140
+ const [info, found, totals] = await Promise.all([
132
141
  backupSettings().catch(() => null),
133
142
  backupPlaces().catch(() => [] as BackupPlace[]),
143
+ backupSummary().catch(() => null),
134
144
  ]);
135
145
  if (info) {
136
146
  setSettings(info.settings);
137
147
  setDir(info.dir);
138
148
  }
139
149
  setPlaces(found);
150
+ if (totals) setSummary(totals);
140
151
  }, []);
141
152
 
142
153
  useEffect(() => {
@@ -168,7 +179,11 @@ export function BackupSection() {
168
179
  return () => clearTimeout(timer);
169
180
  }, [theme.theme, reduceMotion, agentStamp, locale.id]);
170
181
 
171
- const patch = async (value: { folder?: string | null; auto?: boolean; keep?: number }) => {
182
+ const patch = async (value: {
183
+ folder?: string | null;
184
+ auto?: boolean;
185
+ skipLargeVideos?: boolean;
186
+ }) => {
172
187
  setNotice('');
173
188
  const saved = await saveBackupSettings(value);
174
189
  if (!saved.ok) {
@@ -225,8 +240,35 @@ export function BackupSection() {
225
240
  }
226
241
  };
227
242
 
243
+ const openExport = async () => {
244
+ setExportNotice('');
245
+ setExportItems([]);
246
+ setExportOpen(true);
247
+ const items = await backupList().catch(() => [] as BackupListItem[]);
248
+ setExportItems(items.filter((item) => item.kind === 'snapshot'));
249
+ };
250
+
251
+ const doExport = async (snapshot: string) => {
252
+ if (exporting) return;
253
+ setExporting(true);
254
+ setExportNotice('');
255
+ try {
256
+ const answer = await exportBackup(snapshot, locale.id);
257
+ if ('unsupported' in answer) {
258
+ setExportNotice(b.exportFailed);
259
+ return;
260
+ }
261
+ if ('cancelled' in answer) return;
262
+ const name = answer.path.split('/').pop() ?? answer.path;
263
+ setExportNotice(format(b.exportDone, { name, size: formatSize(answer.size) }));
264
+ } catch {
265
+ setExportNotice(b.exportFailed);
266
+ } finally {
267
+ setExporting(false);
268
+ }
269
+ };
270
+
228
271
  const last = settings?.last ?? null;
229
- const keep = settings?.keep ?? 7;
230
272
  const currentPlace = settings?.folder
231
273
  ? places.find((place) => place.path === settings.folder)
232
274
  : undefined;
@@ -278,31 +320,49 @@ export function BackupSection() {
278
320
  />
279
321
  </div>
280
322
 
323
+ <div className="mt-3 border-t border-border pt-3">
324
+ <p data-lr-backup-total className="text-[14px] font-semibold">
325
+ {format(b.totalSize, { size: formatSize(summary?.totalBytes ?? 0) })}
326
+ </p>
327
+ <p className="mt-0.5 text-[12px] text-muted-foreground">{b.retain}</p>
328
+ {summary !== null && summary.biggest.length > 0 && (
329
+ <div data-lr-backup-biggest className="mt-2">
330
+ <p className="text-[12px] font-semibold text-muted-foreground">{b.biggestTitle}</p>
331
+ <ul className="mt-1 list-disc break-all pl-4 text-[12px] text-muted-foreground">
332
+ {summary.biggest.map((file) => {
333
+ const name = file.rel.slice(file.rel.lastIndexOf('/') + 1);
334
+ return (
335
+ <li key={file.rel}>
336
+ {file.deck
337
+ ? format(b.biggestItemDeck, {
338
+ name,
339
+ size: formatSize(file.size),
340
+ deck: file.deck,
341
+ })
342
+ : format(b.biggestItem, { name, size: formatSize(file.size) })}
343
+ </li>
344
+ );
345
+ })}
346
+ </ul>
347
+ </div>
348
+ )}
349
+ </div>
350
+
281
351
  <div className="mt-3 flex items-center gap-4 border-t border-border pt-3">
282
352
  <div className="min-w-0 flex-1">
283
- <p className="text-[14px] font-semibold">{b.keep}</p>
284
- {last?.ok && last.size > 0 && (
285
- <p data-lr-backup-keep-size className="text-[12px] text-muted-foreground">
286
- {format(b.keepSize, {
287
- size: formatSize(last.size),
288
- n: keep,
289
- total: formatSize(last.size * keep),
290
- })}
291
- </p>
292
- )}
353
+ <p className="text-[14px] font-semibold">{b.skipVideos}</p>
354
+ <p className="text-[12px] text-muted-foreground">{b.skipVideosHint}</p>
293
355
  </div>
294
- <select
295
- data-lr-backup-keep
296
- value={keep}
297
- onChange={(event) => void patch({ keep: Number(event.target.value) })}
298
- className="rounded-[8px] border border-border bg-card px-2 py-1 text-[13px] outline-none focus-visible:ring-2 focus-visible:ring-ring/40"
299
- >
300
- {KEEP_CHOICES.map((value) => (
301
- <option key={value} value={value}>
302
- {format(b.keepOption, { n: value })}
303
- </option>
304
- ))}
305
- </select>
356
+ <button
357
+ type="button"
358
+ role="switch"
359
+ aria-checked={settings?.skipLargeVideos === true}
360
+ aria-label={b.skipVideos}
361
+ data-lr-backup-skip-videos
362
+ disabled={!settings?.folder}
363
+ onClick={() => void patch({ skipLargeVideos: !(settings?.skipLargeVideos === true) })}
364
+ className="lr-switch outline-none focus-visible:ring-2 focus-visible:ring-ring/40 disabled:opacity-40"
365
+ />
306
366
  </div>
307
367
 
308
368
  <div className="mt-3 border-t border-border pt-3">
@@ -334,7 +394,10 @@ export function BackupSection() {
334
394
  }
335
395
  >
336
396
  {last.ok
337
- ? format(b.lastOk, { when: when(last.at, locale.id), size: formatSize(last.size) })
397
+ ? format(b.lastOk, {
398
+ when: when(last.at, locale.id),
399
+ added: formatSize(last.addedBytes),
400
+ })
338
401
  : failureText(last.error)}
339
402
  </p>
340
403
  )}
@@ -362,6 +425,12 @@ export function BackupSection() {
362
425
  </p>
363
426
  )}
364
427
 
428
+ {!running && last?.ok && last.skipped.length > 0 && (
429
+ <p data-lr-backup-skipped className="mt-1 text-[12.5px] text-muted-foreground">
430
+ {format(b.skipped, { n: last.skipped.length })}
431
+ </p>
432
+ )}
433
+
365
434
  {!running && last && !last.ok && (
366
435
  <Link
367
436
  to="/help#cloud-faq"
@@ -393,7 +462,17 @@ export function BackupSection() {
393
462
  </div>
394
463
  )}
395
464
 
396
- <div className="mt-3 border-t border-border pt-3">
465
+ <div className="mt-3 flex flex-wrap items-center gap-2 border-t border-border pt-3">
466
+ <Button
467
+ type="button"
468
+ variant="outline"
469
+ size="sm"
470
+ data-lr-backup-export
471
+ disabled={!settings?.folder}
472
+ onClick={() => void openExport()}
473
+ >
474
+ {b.exportFull}
475
+ </Button>
397
476
  <Button
398
477
  type="button"
399
478
  variant="outline"
@@ -483,6 +562,45 @@ export function BackupSection() {
483
562
  </DialogContent>
484
563
  </Dialog>
485
564
 
565
+ <Dialog open={exportOpen} onOpenChange={setExportOpen}>
566
+ <DialogContent className="sm:max-w-[520px]" data-lr-backup-export-dialog>
567
+ <DialogHeader>
568
+ <DialogTitle>{b.exportTitle}</DialogTitle>
569
+ </DialogHeader>
570
+ <p className="text-[12.5px] text-muted-foreground">{b.exportHint}</p>
571
+ <div className="flex max-h-[46vh] flex-col gap-1 overflow-y-auto">
572
+ {exportItems.length === 0 ? (
573
+ <p className="text-[13px] text-muted-foreground">{b.noBackups}</p>
574
+ ) : (
575
+ exportItems.map((item) => (
576
+ <button
577
+ key={item.path}
578
+ type="button"
579
+ data-lr-backup-export-day={item.name}
580
+ disabled={exporting}
581
+ onClick={() => void doExport(item.path)}
582
+ className="flex flex-col items-start rounded-[10px] border border-border px-3 py-2 text-left outline-none hover:border-[var(--lr-text-3)] focus-visible:ring-2 focus-visible:ring-ring/40 disabled:opacity-50"
583
+ >
584
+ <span className="w-full truncate text-[13.5px] font-medium">{item.name}</span>
585
+ <span className="text-[12px] text-muted-foreground">
586
+ {format(b.snapshotLine, {
587
+ decks: item.decks ?? 0,
588
+ size: formatSize(item.size),
589
+ when: when(item.at, locale.id),
590
+ })}
591
+ </span>
592
+ </button>
593
+ ))
594
+ )}
595
+ </div>
596
+ {exportNotice !== '' && (
597
+ <p data-lr-backup-export-notice className="text-[12.5px] text-muted-foreground">
598
+ {exportNotice}
599
+ </p>
600
+ )}
601
+ </DialogContent>
602
+ </Dialog>
603
+
486
604
  <BackupRestoreDialog open={restoreOpen} onOpenChange={setRestoreOpen} />
487
605
  </section>
488
606
  );
@@ -14,6 +14,7 @@ import { setReduceMotionSetting, useReduceMotionSetting } from '../theme/motion'
14
14
  import { LR_THEME_CHOICES, type LrThemeChoice } from '../theme/themes';
15
15
  import { useTheme } from '../theme/use-theme';
16
16
  import { BackupSection } from './backup-section';
17
+ import { WorkspaceCard } from './workspace-card';
17
18
 
18
19
  const SWATCH: Record<LrThemeChoice, { bg: string; fg: string }> = {
19
20
  system: { bg: 'linear-gradient(90deg,#fafbf5 50%,#111412 50%)', fg: '#13240f' },
@@ -110,6 +111,8 @@ export function SettingsPage() {
110
111
  </p>
111
112
  </header>
112
113
 
114
+ <WorkspaceCard />
115
+
113
116
  <section className="rounded-[16px] border border-border bg-card px-6 py-5 shadow-[var(--lr-shadow-1)]">
114
117
  <h2 className="text-[16px] font-semibold">{lr.settings.appearance}</h2>
115
118
  <p className="mt-1 mb-4 text-[14px] text-muted-foreground">{lr.settings.appearanceHint}</p>
@@ -0,0 +1,53 @@
1
+ import { Check, Copy, Folder } from 'lucide-react';
2
+ import { useEffect, useState } from 'react';
3
+ import { Button } from '@/components/ui/button';
4
+ import { useLrText } from '../text';
5
+ import { copyWorkspacePath, revealWorkspace, workspacePath } from './workspace';
6
+
7
+ export function WorkspaceCard() {
8
+ const t = useLrText().settings;
9
+ const [path, setPath] = useState<string | null>(null);
10
+ const [copied, setCopied] = useState(false);
11
+
12
+ useEffect(() => {
13
+ let live = true;
14
+ void workspacePath().then((value) => {
15
+ if (live) setPath(value);
16
+ });
17
+ return () => {
18
+ live = false;
19
+ };
20
+ }, []);
21
+
22
+ if (!path) return null;
23
+
24
+ async function copy() {
25
+ if (await copyWorkspacePath()) setCopied(true);
26
+ }
27
+
28
+ return (
29
+ <section
30
+ data-lr-workspace
31
+ className="mb-4 rounded-[16px] border border-border bg-card px-6 py-5 shadow-[var(--lr-shadow-1)]"
32
+ >
33
+ <h2 className="text-[16px] font-semibold">{t.workspaceTitle}</h2>
34
+ <p
35
+ data-lr-workspace-path
36
+ className="mt-2 select-text break-all font-mono text-[12.5px] text-foreground/90"
37
+ >
38
+ {path}
39
+ </p>
40
+ <div className="mt-3 flex flex-wrap gap-2">
41
+ <Button variant="outline" size="sm" onClick={() => void copy()}>
42
+ {copied ? <Check /> : <Copy />}
43
+ {copied ? t.workspaceCopied : t.workspaceCopy}
44
+ </Button>
45
+ <Button variant="outline" size="sm" onClick={revealWorkspace}>
46
+ <Folder />
47
+ {t.workspaceReveal}
48
+ </Button>
49
+ </div>
50
+ <p className="mt-3 text-[12.5px] text-muted-foreground">{t.workspaceHint}</p>
51
+ </section>
52
+ );
53
+ }
@@ -0,0 +1,37 @@
1
+ let cached: string | null = null;
2
+ let pending: Promise<string | null> | null = null;
3
+
4
+ /** The folder the dev server runs in; null when it cannot say. */
5
+ export function workspacePath(): Promise<string | null> {
6
+ if (cached) return Promise.resolve(cached);
7
+ pending ??= (async () => {
8
+ try {
9
+ const res = await fetch('/__lr/workspace');
10
+ if (!res.ok) return null;
11
+ const body = (await res.json()) as { path?: unknown };
12
+ if (typeof body.path !== 'string' || !body.path) return null;
13
+ cached = body.path;
14
+ return cached;
15
+ } catch {
16
+ return null;
17
+ } finally {
18
+ pending = null;
19
+ }
20
+ })();
21
+ return pending;
22
+ }
23
+
24
+ export async function copyWorkspacePath(): Promise<boolean> {
25
+ const path = await workspacePath();
26
+ if (!path) return false;
27
+ try {
28
+ await navigator.clipboard.writeText(path);
29
+ return true;
30
+ } catch {
31
+ return false;
32
+ }
33
+ }
34
+
35
+ export function revealWorkspace(): void {
36
+ void fetch('/__lr/workspace/reveal', { method: 'POST' }).catch(() => {});
37
+ }
@@ -0,0 +1,55 @@
1
+ import { Share2 } from 'lucide-react';
2
+ import { useEffect } from 'react';
3
+ import { Button } from '@/components/ui/button';
4
+ import { DropdownMenuItem } from '@/components/ui/dropdown-menu';
5
+ import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
6
+ import { useLrText } from '../text';
7
+
8
+ const SHARE_OPEN_EVENT = 'lemonriver:share-open';
9
+
10
+ /** The editor's more-menu cannot reach the dialog's state, so it asks for it. */
11
+ export function requestShare(): void {
12
+ window.dispatchEvent(new Event(SHARE_OPEN_EVENT));
13
+ }
14
+
15
+ export function useShareRequests(open: () => void): void {
16
+ useEffect(() => {
17
+ window.addEventListener(SHARE_OPEN_EVENT, open);
18
+ return () => window.removeEventListener(SHARE_OPEN_EVENT, open);
19
+ }, [open]);
20
+ }
21
+
22
+ export function ShareMenuEntry() {
23
+ const lr = useLrText();
24
+ return (
25
+ <DropdownMenuItem onClick={requestShare}>
26
+ <Share2 />
27
+ {lr.share.menuItem}
28
+ </DropdownMenuItem>
29
+ );
30
+ }
31
+
32
+ export function ShareHeaderButton({ onOpen }: { onOpen: () => void }) {
33
+ const lr = useLrText();
34
+ return (
35
+ <Tooltip>
36
+ <TooltipTrigger
37
+ render={
38
+ <Button
39
+ size="sm"
40
+ variant="outline"
41
+ aria-keyshortcuts="S"
42
+ onClick={onOpen}
43
+ className="border-[var(--lr-accent)] bg-[var(--lr-accent-soft)] text-[var(--lr-on-secondary)] hover:border-[var(--lr-accent)] hover:bg-[var(--lr-accent-soft)]"
44
+ >
45
+ <Share2 className="size-3.5" />
46
+ {lr.share.open}
47
+ </Button>
48
+ }
49
+ />
50
+ <TooltipContent side="bottom" sideOffset={6}>
51
+ {lr.share.openHint}
52
+ </TooltipContent>
53
+ </Tooltip>
54
+ );
55
+ }