@lemonriver/core 0.2.0 → 0.3.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 (120) hide show
  1. package/dist/{build-Df_xwIpg.js → build-Bqo69DWP.js} +1 -1
  2. package/dist/cli/bin.js +4 -4
  3. package/dist/{config-BjWCLoMQ.js → config-DJ5rkMMg.js} +1594 -974
  4. package/dist/{config-rMGCkz6i.d.ts → config-teo3kWz7.d.ts} +1 -1
  5. package/dist/{dev-Ctsx9IeO.js → dev-B2FJD5bJ.js} +2 -2
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.js +1 -1
  8. package/dist/locale/index.d.ts +1 -1
  9. package/dist/locale/index.js +1 -1
  10. package/dist/{preview-CJgcqsPk.js → preview-C93BOZL1.js} +1 -1
  11. package/dist/{types-8VUyA2bu.d.ts → types-DFK02XVv.d.ts} +0 -35
  12. package/dist/{update-BKOA3Z6o.js → update-DsxZBtwv.js} +2 -70
  13. package/dist/vite/index.d.ts +1 -1
  14. package/dist/vite/index.js +1 -1
  15. package/dist/{zh-tw-CeLrYwRE.js → zh-tw-DwTAZKa6.js} +6 -172
  16. package/package.json +1 -1
  17. package/src/app/app.tsx +5 -18
  18. package/src/app/components/agent/agent-panel.tsx +3 -0
  19. package/src/app/components/agent/agent-presence.tsx +2 -2
  20. package/src/app/components/agent/history-view.tsx +3 -2
  21. package/src/app/components/agent/transcript.tsx +15 -4
  22. package/src/app/components/asset-view.tsx +6 -6
  23. package/src/app/components/command/command-menu.tsx +2 -1
  24. package/src/app/components/inspector/asset-picker-dialog.tsx +7 -5
  25. package/src/app/components/inspector/comment-layer.tsx +2 -1
  26. package/src/app/components/inspector/inspector-panel.tsx +2 -2
  27. package/src/app/components/sidebar/sidebar-footer.tsx +1 -1
  28. package/src/app/components/sidebar/sidebar.tsx +3 -2
  29. package/src/app/components/themes/theme-detail.tsx +4 -2
  30. package/src/app/components/thumbnail-rail.tsx +1 -28
  31. package/src/app/index.html +2 -2
  32. package/src/app/lemonriver/agent/lemon.tsx +64 -0
  33. package/src/app/{components → lemonriver}/board/board-canvas.tsx +17 -17
  34. package/src/app/{routes/board.tsx → lemonriver/board/board-page.tsx} +16 -15
  35. package/src/app/{components → lemonriver}/board/layout.ts +1 -1
  36. package/src/app/lemonriver/board/model/cards.test.ts +239 -0
  37. package/src/app/lemonriver/board/model/cards.ts +234 -0
  38. package/src/app/lemonriver/board/model/structure.test.ts +101 -0
  39. package/src/app/lemonriver/board/model/structure.ts +82 -0
  40. package/src/app/{components → lemonriver}/board/page-node.tsx +34 -31
  41. package/src/app/{components → lemonriver}/board/use-board-cards.ts +6 -6
  42. package/src/app/{components → lemonriver}/board/use-board-columns.ts +7 -7
  43. package/src/app/{components → lemonriver}/board/use-page-order.ts +10 -6
  44. package/src/app/lemonriver/brand/app-icon.svg +44 -0
  45. package/src/app/lemonriver/brand/apple-touch-icon.png +0 -0
  46. package/src/app/lemonriver/brand/favicon-32.png +0 -0
  47. package/src/app/lemonriver/brand/mascot.tsx +59 -0
  48. package/src/app/lemonriver/brand/mascots/lemon-done.png +0 -0
  49. package/src/app/lemonriver/brand/mascots/lemon-idle.png +0 -0
  50. package/src/app/lemonriver/brand/mascots/lemon-needs-you.png +0 -0
  51. package/src/app/lemonriver/brand/mascots/lemon-thinking.png +0 -0
  52. package/src/app/lemonriver/brand/mascots/lemon-working.png +0 -0
  53. package/src/app/lemonriver/chrome/app-chrome.tsx +99 -0
  54. package/src/app/lemonriver/chrome/nav-row.tsx +34 -0
  55. package/src/app/lemonriver/chrome/not-found.tsx +34 -0
  56. package/src/app/lemonriver/chrome/sidebar-extras.tsx +57 -0
  57. package/src/app/lemonriver/chrome/use-slot.ts +23 -0
  58. package/src/app/lemonriver/features.test.ts +29 -0
  59. package/src/app/lemonriver/features.ts +26 -0
  60. package/src/app/lemonriver/feedback/export.ts +7 -0
  61. package/src/app/lemonriver/feedback/lemon-empty.tsx +54 -0
  62. package/src/app/lemonriver/feedback/offline-banner.tsx +41 -0
  63. package/src/app/lemonriver/feedback/pending-toast.test.ts +44 -0
  64. package/src/app/lemonriver/feedback/pending-toast.ts +39 -0
  65. package/src/app/lemonriver/feedback/toaster.tsx +34 -0
  66. package/src/app/lemonriver/feedback/upload.test.ts +26 -0
  67. package/src/app/lemonriver/feedback/upload.ts +19 -0
  68. package/src/app/lemonriver/home/brief-card.tsx +63 -0
  69. package/src/app/lemonriver/home/brief.test.ts +38 -0
  70. package/src/app/lemonriver/home/brief.ts +34 -0
  71. package/src/app/lemonriver/home/controls.tsx +93 -0
  72. package/src/app/lemonriver/home/deck-card.tsx +183 -0
  73. package/src/app/lemonriver/home/dialogs.tsx +292 -0
  74. package/src/app/lemonriver/home/home-page.tsx +335 -0
  75. package/src/app/lemonriver/home/sorting.test.ts +24 -0
  76. package/src/app/lemonriver/home/sorting.ts +59 -0
  77. package/src/app/lemonriver/home/time.test.ts +33 -0
  78. package/src/app/lemonriver/home/time.ts +33 -0
  79. package/src/app/lemonriver/home/use-deck-times.ts +27 -0
  80. package/src/app/lemonriver/home/use-delayed.ts +15 -0
  81. package/src/app/lemonriver/routes.test.tsx +37 -0
  82. package/src/app/lemonriver/routes.tsx +38 -0
  83. package/src/app/lemonriver/settings/settings-page.tsx +103 -0
  84. package/src/app/lemonriver/slide-extensions.tsx +73 -0
  85. package/src/app/lemonriver/text/all.ts +19 -0
  86. package/src/app/lemonriver/text/en.ts +106 -0
  87. package/src/app/lemonriver/text/es.ts +108 -0
  88. package/src/app/lemonriver/text/index.ts +9 -0
  89. package/src/app/lemonriver/text/ja.ts +106 -0
  90. package/src/app/lemonriver/text/text.test.ts +57 -0
  91. package/src/app/lemonriver/text/types.ts +111 -0
  92. package/src/app/lemonriver/text/zh-cn.ts +101 -0
  93. package/src/app/lemonriver/text/zh-tw.ts +101 -0
  94. package/src/app/lemonriver/theme/app.css +288 -0
  95. package/src/app/lemonriver/theme/controls.css +463 -0
  96. package/src/app/lemonriver/theme/index.css +3 -0
  97. package/src/app/lemonriver/theme/motion.ts +52 -0
  98. package/src/app/lemonriver/theme/pages.test.ts +66 -0
  99. package/src/app/lemonriver/theme/pages.ts +56 -0
  100. package/src/app/lemonriver/theme/theme-menu.tsx +64 -0
  101. package/src/app/lemonriver/theme/themes.test.ts +18 -0
  102. package/src/app/lemonriver/theme/themes.ts +16 -0
  103. package/src/app/lemonriver/theme/tokens.css +226 -0
  104. package/src/app/lemonriver/theme/use-theme.tsx +49 -0
  105. package/src/app/lemonriver/trash/api.test.ts +19 -0
  106. package/src/app/lemonriver/trash/api.ts +77 -0
  107. package/src/app/lemonriver/trash/trash-page.tsx +131 -0
  108. package/src/app/lib/pptx/raster.ts +1 -1
  109. package/src/app/main.tsx +8 -1
  110. package/src/app/routes/home-shell.tsx +4 -2
  111. package/src/app/routes/slide.tsx +12 -16
  112. package/src/app/styles.css +1 -0
  113. package/src/locale/en.ts +0 -35
  114. package/src/locale/es.ts +0 -34
  115. package/src/locale/ja.ts +0 -34
  116. package/src/locale/types.ts +0 -36
  117. package/src/locale/zh-cn.ts +3 -37
  118. package/src/locale/zh-tw.ts +3 -37
  119. /package/src/app/{components → lemonriver}/board/board.css +0 -0
  120. /package/src/app/{components → lemonriver}/board/layout.test.ts +0 -0
@@ -0,0 +1,335 @@
1
+ import { ChevronDown, Plus } from 'lucide-react';
2
+ import { type ReactNode, useEffect, useMemo, useState } from 'react';
3
+ import { useOutletContext } from 'react-router-dom';
4
+ import { toast } from 'sonner';
5
+ import { Button } from '@/components/ui/button';
6
+ import {
7
+ DropdownMenu,
8
+ DropdownMenuContent,
9
+ DropdownMenuItem,
10
+ DropdownMenuTrigger,
11
+ } from '@/components/ui/dropdown-menu';
12
+ import { useAgentSessions, useAgentStatus, useCreateDeck } from '@/lib/agent/use-agent';
13
+ import { format, useLocale } from '@/lib/use-locale';
14
+ import { cn, pad2 } from '@/lib/utils';
15
+ import { FolderIconChip, SystemViewIcon } from '../../components/sidebar/folder-item';
16
+ import { ALL_SLIDES_ID, DRAFT_ID } from '../../components/sidebar/sidebar';
17
+ import { slideCreatedAt, slideIds } from '../../lib/slides';
18
+ import type { HomeOutletContext } from '../../routes/home-shell';
19
+ import { isFeatureEnabled } from '../features';
20
+ import { LemonEmpty } from '../feedback/lemon-empty';
21
+ import { useLrText } from '../text';
22
+ import { moveToTrash } from '../trash/api';
23
+ import { BriefCard } from './brief-card';
24
+ import { SearchInput, SortControl } from './controls';
25
+ import { DeckCard } from './deck-card';
26
+ import { MoveDialog, RenameDialog, TypedConfirmDialog } from './dialogs';
27
+ import { filterDecks, sortDecks, useSortPref } from './sorting';
28
+ import { greetingFor } from './time';
29
+ import { useDeckTimes } from './use-deck-times';
30
+ import { useDelayed } from './use-delayed';
31
+
32
+ type Dialog = { kind: 'rename' | 'move' | 'delete'; id: string } | null;
33
+
34
+ function useNow(): number {
35
+ const [now, setNow] = useState(() => Date.now());
36
+ useEffect(() => {
37
+ const timer = setInterval(() => setNow(Date.now()), 60_000);
38
+ return () => clearInterval(timer);
39
+ }, []);
40
+ return now;
41
+ }
42
+
43
+ /** Decks the agent is working on right now. */
44
+ function useEditingDecks(): Set<string> {
45
+ const { sessions } = useAgentSessions();
46
+ return useMemo(
47
+ () =>
48
+ new Set(sessions.flatMap((s) => (s.status === 'running' && s.slideId ? [s.slideId] : []))),
49
+ [sessions],
50
+ );
51
+ }
52
+
53
+ export function LemonRiverHome() {
54
+ const ctx = useOutletContext<HomeOutletContext>();
55
+ const { manifest, loading, draftSlides, slidesByFolder, selectedId, titleMap } = ctx;
56
+ const t = useLocale();
57
+ const lr = useLrText();
58
+ const now = useNow();
59
+ const times = useDeckTimes();
60
+ const editing = useEditingDecks();
61
+ const [query, setQuery] = useState('');
62
+ const [sortKey, setSortKey] = useSortPref();
63
+ const [dialog, setDialog] = useState<Dialog>(null);
64
+
65
+ const isAll = selectedId === ALL_SLIDES_ID;
66
+ const isDraft = selectedId === DRAFT_ID;
67
+ const folder =
68
+ isAll || isDraft ? null : (manifest.folders.find((f) => f.id === selectedId) ?? null);
69
+ const visible = isAll ? slideIds : isDraft ? draftSlides : (slidesByFolder[selectedId] ?? []);
70
+ const filtered = useMemo(() => filterDecks(visible, query, titleMap), [visible, query, titleMap]);
71
+ const sorted = useMemo(
72
+ () => sortDecks(filtered, sortKey, (id) => titleMap[id] ?? id, slideCreatedAt),
73
+ [filtered, sortKey, titleMap],
74
+ );
75
+ const searching = query.trim().length > 0;
76
+ const showLoading = useDelayed(loading);
77
+ const titleOf = (id: string) => titleMap[id] ?? id;
78
+
79
+ const greeting = {
80
+ morning: lr.home.greetingMorning,
81
+ afternoon: lr.home.greetingAfternoon,
82
+ evening: lr.home.greetingEvening,
83
+ }[greetingFor(new Date(now).getHours())];
84
+
85
+ const duplicate = async (id: string) => {
86
+ try {
87
+ const copy = await ctx.duplicateSlide(id);
88
+ toast.success(format(t.home.toastSlideDuplicated, { slide: titleOf(id), newSlide: copy }));
89
+ } catch {
90
+ toast.error(t.home.toastSlideDuplicateFailed);
91
+ }
92
+ };
93
+
94
+ const trash = async (id: string) => {
95
+ try {
96
+ await moveToTrash(id, titleOf(id));
97
+ } catch {
98
+ toast.error(lr.home.toastTrashFailed);
99
+ }
100
+ };
101
+
102
+ const current = dialog ? dialog.id : null;
103
+ const trashOn = isFeatureEnabled('trash');
104
+
105
+ return (
106
+ <div data-lr-home>
107
+ {import.meta.env.DEV && isAll && (
108
+ <>
109
+ <header className="mb-6">
110
+ <h1 className="font-heading text-[28px] font-bold leading-[34px] tracking-[-0.01em]">
111
+ {greeting}
112
+ </h1>
113
+ <p className="lr-on-lime mt-0.5 text-[14px] text-muted-foreground">
114
+ {lr.home.subtitle}
115
+ </p>
116
+ </header>
117
+ <BriefCard />
118
+ </>
119
+ )}
120
+
121
+ <div className="mb-4 flex flex-wrap items-center gap-2.5">
122
+ {folder ? (
123
+ <FolderIconChip icon={folder.icon} className="size-5 text-[16px]" />
124
+ ) : (
125
+ <SystemViewIcon kind={isAll ? 'all' : 'draft'} className="text-muted-foreground" />
126
+ )}
127
+ <h2 className="font-heading text-[20px] font-semibold leading-7">
128
+ {folder?.name ?? (isAll ? t.home.slides : t.home.draft)}
129
+ </h2>
130
+ <FolderSwitcher ctx={ctx} />
131
+ {!loading && (
132
+ <span className="folio ml-0.5">
133
+ {pad2(searching ? filtered.length : visible.length)}
134
+ {searching && <span className="opacity-40">/{pad2(visible.length)}</span>}
135
+ </span>
136
+ )}
137
+ <div className="ml-auto flex w-full items-center gap-2 md:w-auto">
138
+ <SortControl value={sortKey} onChange={setSortKey} />
139
+ <SearchInput value={query} onChange={setQuery} />
140
+ </div>
141
+ </div>
142
+
143
+ {loading ? (
144
+ showLoading ? (
145
+ <GridSkeleton />
146
+ ) : null
147
+ ) : visible.length === 0 ? (
148
+ <EmptyHome isDraft={isAll || isDraft} folderName={folder?.name} />
149
+ ) : filtered.length === 0 ? (
150
+ <LemonEmpty
151
+ state="thinking"
152
+ title={t.home.noMatches}
153
+ actions={
154
+ <Button variant="outline" onClick={() => setQuery('')}>
155
+ {t.home.clearSearch}
156
+ </Button>
157
+ }
158
+ >
159
+ {t.home.nothingMatchesPrefix}
160
+ <span className="font-medium text-foreground">&ldquo;{query}&rdquo;</span>
161
+ {t.home.nothingMatchesSuffix} {lr.home.noMatchesHint}
162
+ </LemonEmpty>
163
+ ) : (
164
+ <ul className="grid grid-cols-[repeat(auto-fill,minmax(230px,1fr))] gap-5">
165
+ {import.meta.env.DEV && isAll && !searching && <NewDeckCard />}
166
+ {sorted.map((id, i) => (
167
+ <li
168
+ key={id}
169
+ className="lr-rise"
170
+ style={{ animationDelay: `${Math.min(i, 11) * 40}ms` }}
171
+ >
172
+ <DeckCard
173
+ id={id}
174
+ now={now}
175
+ modifiedAt={times[id]?.modifiedAt}
176
+ editing={editing.has(id)}
177
+ onTitleResolved={ctx.reportTitle}
178
+ actions={{
179
+ onRename: () => setDialog({ kind: 'rename', id }),
180
+ onDuplicate: () => void duplicate(id),
181
+ onMove: () => setDialog({ kind: 'move', id }),
182
+ onDelete: () => (trashOn ? void trash(id) : setDialog({ kind: 'delete', id })),
183
+ }}
184
+ />
185
+ </li>
186
+ ))}
187
+ </ul>
188
+ )}
189
+
190
+ <RenameDialog
191
+ open={dialog?.kind === 'rename'}
192
+ initialName={current ? titleOf(current) : ''}
193
+ onOpenChange={(open) => !open && setDialog(null)}
194
+ onSubmit={async (name) => {
195
+ if (current) await ctx.renameSlide(current, name);
196
+ setDialog(null);
197
+ }}
198
+ />
199
+ <MoveDialog
200
+ open={dialog?.kind === 'move'}
201
+ slideName={current ? titleOf(current) : ''}
202
+ folders={manifest.folders}
203
+ currentFolderId={current ? (manifest.assignments[current] ?? null) : null}
204
+ onOpenChange={(open) => !open && setDialog(null)}
205
+ onSubmit={async (folderId) => {
206
+ if (current) await ctx.assign(current, folderId);
207
+ setDialog(null);
208
+ }}
209
+ />
210
+ <TypedConfirmDialog
211
+ open={dialog?.kind === 'delete'}
212
+ name={current ? titleOf(current) : ''}
213
+ title={t.home.deleteDialogTitle}
214
+ hint={format(lr.trash.confirmHint, { name: current ? titleOf(current) : '' })}
215
+ label={lr.trash.confirmLabel}
216
+ action={t.common.delete}
217
+ onOpenChange={(open) => !open && setDialog(null)}
218
+ onConfirm={async () => {
219
+ if (current) await ctx.deleteSlide(current);
220
+ setDialog(null);
221
+ }}
222
+ />
223
+ </div>
224
+ );
225
+ }
226
+
227
+ function NewDeckCard() {
228
+ const lr = useLrText();
229
+ const createDeck = useCreateDeck();
230
+ return (
231
+ <li>
232
+ <button
233
+ type="button"
234
+ onClick={() => void createDeck()}
235
+ className={cn(
236
+ 'flex h-full min-h-[190px] w-full flex-col items-center justify-center gap-2 rounded-[16px]',
237
+ 'border-[1.5px] border-dashed border-border text-[14px] font-semibold text-muted-foreground outline-none',
238
+ 'transition-colors duration-150 hover:border-[var(--lr-focus)] hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40',
239
+ )}
240
+ >
241
+ <Plus className="size-7" />
242
+ {lr.shell.newDeckCard}
243
+ </button>
244
+ </li>
245
+ );
246
+ }
247
+
248
+ function GridSkeleton() {
249
+ return (
250
+ <ul aria-hidden className="grid grid-cols-[repeat(auto-fill,minmax(230px,1fr))] gap-5">
251
+ {[0, 1, 2, 3].map((i) => (
252
+ <li key={i} className="rounded-[16px] border border-border bg-card p-3">
253
+ <span className="lr-skeleton block aspect-video rounded-[12px]" />
254
+ <span className="lr-skeleton mt-3 block h-3.5 w-[70%] rounded-full" />
255
+ <span className="lr-skeleton mt-2 block h-3.5 w-[45%] rounded-full" />
256
+ </li>
257
+ ))}
258
+ </ul>
259
+ );
260
+ }
261
+
262
+ function EmptyHome({ isDraft, folderName }: { isDraft: boolean; folderName?: string }) {
263
+ const t = useLocale();
264
+ const { provider } = useAgentStatus();
265
+ const createDeck = useCreateDeck();
266
+ if (!isDraft) {
267
+ return (
268
+ <LemonEmpty title={t.home.folderEmptyTitle.replace('{name}', folderName ?? '')}>
269
+ {t.home.folderEmptyHint}
270
+ </LemonEmpty>
271
+ );
272
+ }
273
+ return (
274
+ <LemonEmpty
275
+ title={t.home.noSlidesYet}
276
+ actions={
277
+ import.meta.env.DEV &&
278
+ provider && (
279
+ <Button onClick={() => void createDeck()}>
280
+ {format(t.agent.createDeckWith, { provider: provider.name })}
281
+ </Button>
282
+ )
283
+ }
284
+ >
285
+ {!provider && (
286
+ <>
287
+ {t.home.createSlideHintPrefix}
288
+ <code className="rounded-[4px] bg-muted px-1.5 py-0.5 font-mono text-[12.5px] text-foreground">
289
+ /create-slide
290
+ </code>
291
+ {t.home.createSlideHintSuffix}
292
+ </>
293
+ )}
294
+ </LemonEmpty>
295
+ );
296
+ }
297
+
298
+ /** On narrow screens the sidebar is hidden; this picks a folder instead. */
299
+ function FolderSwitcher({ ctx }: { ctx: HomeOutletContext }) {
300
+ const t = useLocale();
301
+ const { manifest, draftSlides, slidesByFolder, selectedId, selectFolder } = ctx;
302
+ const item = (id: string, label: string, count: number, chip: ReactNode) => (
303
+ <DropdownMenuItem
304
+ key={id}
305
+ onClick={() => selectFolder(id)}
306
+ className={cn(selectedId === id && 'bg-muted text-foreground')}
307
+ >
308
+ {chip}
309
+ <span className="flex-1 truncate">{label}</span>
310
+ <span className="folio">{pad2(count)}</span>
311
+ </DropdownMenuItem>
312
+ );
313
+ return (
314
+ <DropdownMenu>
315
+ <DropdownMenuTrigger
316
+ render={
317
+ <button
318
+ type="button"
319
+ aria-label={t.home.folders}
320
+ className="flex size-8 items-center justify-center rounded-[8px] border border-border bg-card text-muted-foreground outline-none hover:bg-muted md:hidden"
321
+ >
322
+ <ChevronDown className="size-4" />
323
+ </button>
324
+ }
325
+ />
326
+ <DropdownMenuContent align="start" className="min-w-[200px]">
327
+ {item(ALL_SLIDES_ID, t.home.slides, slideIds.length, <SystemViewIcon kind="all" />)}
328
+ {item(DRAFT_ID, t.home.draft, draftSlides.length, <SystemViewIcon kind="draft" />)}
329
+ {manifest.folders.map((f) =>
330
+ item(f.id, f.name, slidesByFolder[f.id]?.length ?? 0, <FolderIconChip icon={f.icon} />),
331
+ )}
332
+ </DropdownMenuContent>
333
+ </DropdownMenu>
334
+ );
335
+ }
@@ -0,0 +1,24 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { filterDecks, sortDecks } from './sorting';
3
+
4
+ const created = { a: 3, b: 1, c: 2 };
5
+ const titles: Record<string, string> = { a: 'Zeta', b: 'alpha 10', c: 'Alpha 9' };
6
+
7
+ describe('sortDecks', () => {
8
+ it('orders by creation time and by title', () => {
9
+ const ids = ['a', 'b', 'c'];
10
+ expect(sortDecks(ids, 'created-desc', (id) => titles[id], created)).toEqual(['a', 'c', 'b']);
11
+ expect(sortDecks(ids, 'created-asc', (id) => titles[id], created)).toEqual(['b', 'c', 'a']);
12
+ expect(sortDecks(ids, 'title-asc', (id) => titles[id], created)).toEqual(['c', 'b', 'a']);
13
+ expect(sortDecks(ids, 'title-desc', (id) => titles[id], created)).toEqual(['a', 'b', 'c']);
14
+ expect(ids).toEqual(['a', 'b', 'c']);
15
+ });
16
+ });
17
+
18
+ describe('filterDecks', () => {
19
+ it('matches the id or the title, ignoring case', () => {
20
+ expect(filterDecks(['a', 'b', 'c'], ' ALPHA ', titles)).toEqual(['b', 'c']);
21
+ expect(filterDecks(['a', 'b', 'c'], 'b', titles)).toEqual(['b']);
22
+ expect(filterDecks(['a', 'b'], '', titles)).toEqual(['a', 'b']);
23
+ });
24
+ });
@@ -0,0 +1,59 @@
1
+ import { useState } from 'react';
2
+
3
+ export type SortKey = 'created-desc' | 'created-asc' | 'title-asc' | 'title-desc';
4
+
5
+ export const SORT_KEYS: readonly SortKey[] = [
6
+ 'created-desc',
7
+ 'created-asc',
8
+ 'title-asc',
9
+ 'title-desc',
10
+ ];
11
+
12
+ // The official home's key, so the order someone picked there carries over.
13
+ const SORT_STORAGE_KEY = 'open-slide:home-sort';
14
+
15
+ function readSortPref(): SortKey {
16
+ try {
17
+ const raw = window.localStorage.getItem(SORT_STORAGE_KEY);
18
+ if (raw && (SORT_KEYS as readonly string[]).includes(raw)) return raw as SortKey;
19
+ } catch {}
20
+ return 'created-desc';
21
+ }
22
+
23
+ export function useSortPref(): [SortKey, (next: SortKey) => void] {
24
+ const [value, setValue] = useState<SortKey>(readSortPref);
25
+ const set = (next: SortKey) => {
26
+ setValue(next);
27
+ try {
28
+ window.localStorage.setItem(SORT_STORAGE_KEY, next);
29
+ } catch {}
30
+ };
31
+ return [value, set];
32
+ }
33
+
34
+ const TITLE_COLLATOR = new Intl.Collator(undefined, { sensitivity: 'base', numeric: true });
35
+
36
+ export function sortDecks(
37
+ ids: string[],
38
+ key: SortKey,
39
+ titleOf: (id: string) => string,
40
+ createdAt: Record<string, number>,
41
+ ): string[] {
42
+ const list = ids.slice();
43
+ if (key === 'title-asc') list.sort((a, b) => TITLE_COLLATOR.compare(titleOf(a), titleOf(b)));
44
+ else if (key === 'title-desc')
45
+ list.sort((a, b) => TITLE_COLLATOR.compare(titleOf(b), titleOf(a)));
46
+ else if (key === 'created-asc') list.sort((a, b) => (createdAt[a] ?? 0) - (createdAt[b] ?? 0));
47
+ else list.sort((a, b) => (createdAt[b] ?? 0) - (createdAt[a] ?? 0));
48
+ return list;
49
+ }
50
+
51
+ export function filterDecks(
52
+ ids: string[],
53
+ query: string,
54
+ titles: Record<string, string>,
55
+ ): string[] {
56
+ const q = query.trim().toLowerCase();
57
+ if (!q) return ids;
58
+ return ids.filter((id) => id.toLowerCase().includes(q) || titles[id]?.toLowerCase().includes(q));
59
+ }
@@ -0,0 +1,33 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { daysLeft, greetingFor, relativeTime } from './time';
3
+
4
+ const NOW = Date.parse('2026-10-29T12:00:00Z');
5
+
6
+ describe('relativeTime', () => {
7
+ it('picks the largest unit that fits', () => {
8
+ expect(relativeTime(NOW - 3 * 24 * 3600 * 1000, NOW, 'en')).toBe('3 days ago');
9
+ expect(relativeTime(NOW - 24 * 3600 * 1000, NOW, 'en')).toBe('yesterday');
10
+ expect(relativeTime(NOW - 2 * 3600 * 1000, NOW, 'en')).toBe('2 hours ago');
11
+ expect(relativeTime(NOW - 10 * 1000, NOW, 'en')).toBe('now');
12
+ expect(relativeTime(NOW - 3 * 24 * 3600 * 1000, NOW, 'zh-CN')).toBe('3天前');
13
+ });
14
+ });
15
+
16
+ describe('greetingFor', () => {
17
+ it('splits the day at noon and six', () => {
18
+ expect(greetingFor(9)).toBe('morning');
19
+ expect(greetingFor(12)).toBe('afternoon');
20
+ expect(greetingFor(17)).toBe('afternoon');
21
+ expect(greetingFor(18)).toBe('evening');
22
+ expect(greetingFor(2)).toBe('evening');
23
+ });
24
+ });
25
+
26
+ describe('daysLeft', () => {
27
+ it('rounds up and never shows zero', () => {
28
+ const day = 24 * 3600 * 1000;
29
+ expect(daysLeft(NOW + 29.2 * day, NOW)).toBe(30);
30
+ expect(daysLeft(NOW + day, NOW)).toBe(1);
31
+ expect(daysLeft(NOW + 1000, NOW)).toBe(1);
32
+ });
33
+ });
@@ -0,0 +1,33 @@
1
+ const UNITS: [Intl.RelativeTimeFormatUnit, number][] = [
2
+ ['year', 365 * 24 * 3600],
3
+ ['month', 30 * 24 * 3600],
4
+ ['week', 7 * 24 * 3600],
5
+ ['day', 24 * 3600],
6
+ ['hour', 3600],
7
+ ['minute', 60],
8
+ ];
9
+
10
+ /** "3 days ago", "yesterday", "now" — in the reader's language. */
11
+ export function relativeTime(ms: number, now: number, locale: string): string {
12
+ const seconds = (ms - now) / 1000;
13
+ const rtf = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' });
14
+ for (const [unit, size] of UNITS) {
15
+ if (Math.abs(seconds) >= size) return rtf.format(Math.round(seconds / size), unit);
16
+ }
17
+ return rtf.format(0, 'second');
18
+ }
19
+
20
+ export type Greeting = 'morning' | 'afternoon' | 'evening';
21
+
22
+ export function greetingFor(hour: number): Greeting {
23
+ if (hour >= 5 && hour < 12) return 'morning';
24
+ if (hour >= 12 && hour < 18) return 'afternoon';
25
+ return 'evening';
26
+ }
27
+
28
+ const DAY_MS = 24 * 3600 * 1000;
29
+
30
+ /** Whole days until `expiresAt`, never below 1 while the entry still exists. */
31
+ export function daysLeft(expiresAt: number, now: number): number {
32
+ return Math.max(1, Math.ceil((expiresAt - now) / DAY_MS));
33
+ }
@@ -0,0 +1,27 @@
1
+ import { useEffect, useState } from 'react';
2
+
3
+ export type DeckTimes = Record<string, { modifiedAt: number }>;
4
+
5
+ /** When each deck was last saved. Only the dev server knows; a built site gets nothing. */
6
+ export function useDeckTimes(): DeckTimes {
7
+ const [times, setTimes] = useState<DeckTimes>({});
8
+ useEffect(() => {
9
+ if (!import.meta.env.DEV) return;
10
+ let cancelled = false;
11
+ const load = () =>
12
+ fetch('/__lr/decks')
13
+ .then((res) => (res.ok ? (res.json() as Promise<{ decks: DeckTimes }>) : null))
14
+ .then((data) => {
15
+ if (!cancelled && data) setTimes(data.decks);
16
+ })
17
+ .catch(() => {});
18
+ void load();
19
+ const hot = import.meta.hot;
20
+ hot?.on('open-slide:slide-changed', load);
21
+ return () => {
22
+ cancelled = true;
23
+ hot?.off('open-slide:slide-changed', load);
24
+ };
25
+ }, []);
26
+ return times;
27
+ }
@@ -0,0 +1,15 @@
1
+ import { useEffect, useState } from 'react';
2
+
3
+ /** True once `active` has stayed true for `ms`, so quick loads never flash a skeleton. */
4
+ export function useDelayed(active: boolean, ms = 300): boolean {
5
+ const [shown, setShown] = useState(false);
6
+ useEffect(() => {
7
+ if (!active) {
8
+ setShown(false);
9
+ return;
10
+ }
11
+ const timer = setTimeout(() => setShown(true), ms);
12
+ return () => clearTimeout(timer);
13
+ }, [active, ms]);
14
+ return shown;
15
+ }
@@ -0,0 +1,37 @@
1
+ import type { ReactElement } from 'react';
2
+ import { describe, expect, it, vi } from 'vitest';
3
+
4
+ vi.mock('./features', () => ({ isFeatureEnabled: vi.fn(() => true) }));
5
+ vi.mock('./chrome/not-found', () => ({ NotFound: () => null }));
6
+ vi.mock('./home/home-page', () => ({ LemonRiverHome: () => null }));
7
+ vi.mock('./settings/settings-page', () => ({ SettingsPage: () => null }));
8
+ vi.mock('./trash/trash-page', () => ({ TrashPage: () => null }));
9
+
10
+ import { isFeatureEnabled } from './features';
11
+ import { lemonRiverRoutes, lemonRiverShellRoutes } from './routes';
12
+
13
+ const paths = (routes: unknown[]) =>
14
+ routes.filter(Boolean).map((r) => (r as ReactElement<{ path: string }>).props.path);
15
+
16
+ describe('lemonRiverRoutes', () => {
17
+ it('adds the board and the not-found page', () => {
18
+ expect(paths(lemonRiverRoutes())).toEqual(['/s/:slideId/board', '*']);
19
+ });
20
+
21
+ it('drops the board when the feature is off', () => {
22
+ vi.mocked(isFeatureEnabled).mockReturnValue(false);
23
+ expect(paths(lemonRiverRoutes())).toEqual(['*']);
24
+ vi.mocked(isFeatureEnabled).mockReturnValue(true);
25
+ });
26
+ });
27
+
28
+ describe('lemonRiverShellRoutes', () => {
29
+ it('puts our home first, then settings and trash', () => {
30
+ expect(paths(lemonRiverShellRoutes())).toEqual(['/', '/settings', '/trash']);
31
+ });
32
+
33
+ it('leaves out the pages whose feature is off', () => {
34
+ vi.mocked(isFeatureEnabled).mockImplementation((id) => id !== 'trash');
35
+ expect(paths(lemonRiverShellRoutes())).toEqual(['/', '/settings']);
36
+ });
37
+ });
@@ -0,0 +1,38 @@
1
+ import { lazy, Suspense } from 'react';
2
+ import { Route } from 'react-router-dom';
3
+ import { NotFound } from './chrome/not-found';
4
+ import { isFeatureEnabled } from './features';
5
+ import { LemonRiverHome } from './home/home-page';
6
+ import { SettingsPage } from './settings/settings-page';
7
+ import { TrashPage } from './trash/trash-page';
8
+
9
+ const BoardPage = lazy(() => import('./board/board-page').then((m) => ({ default: m.Board })));
10
+
11
+ /** Routes of our own, outside the home shell. Placed before the official catch-all. */
12
+ export function lemonRiverRoutes() {
13
+ return [
14
+ isFeatureEnabled('board') && (
15
+ <Route
16
+ key="board"
17
+ path="/s/:slideId/board"
18
+ element={
19
+ <Suspense fallback={null}>
20
+ <BoardPage />
21
+ </Suspense>
22
+ }
23
+ />
24
+ ),
25
+ <Route key="not-found" path="*" element={<NotFound />} />,
26
+ ];
27
+ }
28
+
29
+ /** Pages inside the home shell. Placed before the official home route, which they replace. */
30
+ export function lemonRiverShellRoutes() {
31
+ return [
32
+ <Route key="home" path="/" element={<LemonRiverHome />} />,
33
+ isFeatureEnabled('settings') && (
34
+ <Route key="settings" path="/settings" element={<SettingsPage />} />
35
+ ),
36
+ isFeatureEnabled('trash') && <Route key="trash" path="/trash" element={<TrashPage />} />,
37
+ ];
38
+ }