@lemonriver/core 0.4.0 → 0.6.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 (115) hide show
  1. package/README.md +14 -4
  2. package/dist/{build-Nl7EeJ6x.js → build-RlcGG-Ve.js} +1 -1
  3. package/dist/cli/bin.js +4 -4
  4. package/dist/{config-CpC0nM3r.js → config-BJT87wE9.js} +4756 -2012
  5. package/dist/{dev-BB3THd5I.js → dev-DR-j_xda.js} +2 -2
  6. package/dist/{preview-BGjgTg7H.js → preview-BTAhTb5B.js} +1 -1
  7. package/dist/{update-DsxZBtwv.js → update-CMRxtTc9.js} +18 -8
  8. package/dist/vite/index.js +1 -1
  9. package/package.json +2 -2
  10. package/src/agent/types.ts +14 -2
  11. package/src/app/components/agent/agent-panel.tsx +17 -5
  12. package/src/app/components/agent/connect-view.tsx +1 -1
  13. package/src/app/components/agent/provider-logo.tsx +10 -1
  14. package/src/app/lemonriver/agent/provider-marks.tsx +53 -0
  15. package/src/app/lemonriver/agent-providers/section.tsx +75 -0
  16. package/src/app/lemonriver/agent-providers/use-providers.ts +61 -0
  17. package/src/app/lemonriver/board/blocks/block-panel.tsx +666 -0
  18. package/src/app/lemonriver/board/blocks/cache.ts +28 -0
  19. package/src/app/lemonriver/board/blocks/change-list.tsx +189 -0
  20. package/src/app/lemonriver/board/blocks/classify.test.ts +209 -0
  21. package/src/app/lemonriver/board/blocks/classify.ts +152 -0
  22. package/src/app/lemonriver/board/blocks/snapshot.ts +116 -0
  23. package/src/app/lemonriver/board/board-canvas.tsx +627 -104
  24. package/src/app/lemonriver/board/board-page.tsx +1702 -91
  25. package/src/app/lemonriver/board/board.css +58 -7
  26. package/src/app/lemonriver/board/layout.test.ts +84 -0
  27. package/src/app/lemonriver/board/layout.ts +112 -11
  28. package/src/app/lemonriver/board/model/agent-tasks.test.ts +200 -0
  29. package/src/app/lemonriver/board/model/agent-tasks.ts +223 -0
  30. package/src/app/lemonriver/board/model/apply-prompt.test.ts +121 -0
  31. package/src/app/lemonriver/board/model/apply-prompt.ts +115 -0
  32. package/src/app/lemonriver/board/model/apply.ts +71 -0
  33. package/src/app/lemonriver/board/model/cards.test.ts +95 -2
  34. package/src/app/lemonriver/board/model/cards.ts +88 -20
  35. package/src/app/lemonriver/board/model/changes.test.ts +244 -0
  36. package/src/app/lemonriver/board/model/changes.ts +268 -0
  37. package/src/app/lemonriver/board/model/filter.test.ts +50 -0
  38. package/src/app/lemonriver/board/model/filter.ts +42 -0
  39. package/src/app/lemonriver/board/model/history.test.ts +71 -0
  40. package/src/app/lemonriver/board/model/history.ts +51 -0
  41. package/src/app/lemonriver/board/model/restructure.test.ts +205 -0
  42. package/src/app/lemonriver/board/model/restructure.ts +169 -0
  43. package/src/app/lemonriver/board/model/self-check.test.ts +329 -0
  44. package/src/app/lemonriver/board/model/self-check.ts +489 -0
  45. package/src/app/lemonriver/board/model/structure.test.ts +249 -0
  46. package/src/app/lemonriver/board/model/structure.ts +209 -0
  47. package/src/app/lemonriver/board/model/timing.test.ts +113 -0
  48. package/src/app/lemonriver/board/model/timing.ts +117 -0
  49. package/src/app/lemonriver/board/page-node.tsx +258 -55
  50. package/src/app/lemonriver/board/self-check-jump.ts +23 -0
  51. package/src/app/lemonriver/board/self-check-panel.tsx +272 -0
  52. package/src/app/lemonriver/board/self-check-runner.tsx +150 -0
  53. package/src/app/lemonriver/board/status-style.ts +25 -0
  54. package/src/app/lemonriver/board/use-board-apply.ts +206 -0
  55. package/src/app/lemonriver/board/use-board-cards.ts +108 -5
  56. package/src/app/lemonriver/board/use-board-changes.ts +108 -0
  57. package/src/app/lemonriver/board/use-board-columns.ts +37 -56
  58. package/src/app/lemonriver/board/use-board-comments.ts +36 -0
  59. package/src/app/lemonriver/board/use-board-restructures.ts +107 -0
  60. package/src/app/lemonriver/board/use-history.ts +86 -0
  61. package/src/app/lemonriver/board/use-page-order.ts +65 -38
  62. package/src/app/lemonriver/board/use-self-check.ts +117 -0
  63. package/src/app/lemonriver/board/use-target-minutes.ts +47 -0
  64. package/src/app/lemonriver/board/views/block-readings.tsx +46 -0
  65. package/src/app/lemonriver/board/views/list-view.tsx +356 -0
  66. package/src/app/lemonriver/board/views/progress.tsx +32 -0
  67. package/src/app/lemonriver/board/views/timeline-view.tsx +341 -0
  68. package/src/app/lemonriver/chrome/filter-pill.tsx +30 -0
  69. package/src/app/lemonriver/chrome/sidebar-extras.tsx +12 -1
  70. package/src/app/lemonriver/features.test.ts +5 -0
  71. package/src/app/lemonriver/features.ts +2 -1
  72. package/src/app/lemonriver/home/deck-card.tsx +10 -0
  73. package/src/app/lemonriver/home/home-page.tsx +55 -6
  74. package/src/app/lemonriver/home/use-deck-times.ts +4 -1
  75. package/src/app/lemonriver/outline/build-team.tsx +42 -0
  76. package/src/app/lemonriver/outline/describe-page.tsx +128 -27
  77. package/src/app/lemonriver/outline/draft.ts +38 -0
  78. package/src/app/lemonriver/outline/model.test.ts +118 -0
  79. package/src/app/lemonriver/outline/model.ts +92 -7
  80. package/src/app/lemonriver/outline/outline-page.tsx +90 -7
  81. package/src/app/lemonriver/outline/pick-style.tsx +282 -0
  82. package/src/app/lemonriver/routes.test.tsx +17 -5
  83. package/src/app/lemonriver/routes.tsx +28 -0
  84. package/src/app/lemonriver/settings/settings-page.tsx +3 -0
  85. package/src/app/lemonriver/slide-extensions.tsx +14 -2
  86. package/src/app/lemonriver/templates/client.ts +60 -0
  87. package/src/app/lemonriver/templates/demo-page.tsx +79 -0
  88. package/src/app/lemonriver/templates/knobs.test.ts +62 -0
  89. package/src/app/lemonriver/templates/knobs.ts +62 -0
  90. package/src/app/lemonriver/templates/library-page.tsx +292 -0
  91. package/src/app/lemonriver/templates/model.test.ts +175 -0
  92. package/src/app/lemonriver/templates/model.ts +339 -0
  93. package/src/app/lemonriver/templates/preview-content.test.ts +117 -0
  94. package/src/app/lemonriver/templates/preview-content.ts +149 -0
  95. package/src/app/lemonriver/templates/recommend.test.ts +71 -0
  96. package/src/app/lemonriver/templates/recommend.ts +72 -0
  97. package/src/app/lemonriver/templates/use-library.ts +58 -0
  98. package/src/app/lemonriver/templates/virtual.d.ts +28 -0
  99. package/src/app/lemonriver/text/en.ts +228 -0
  100. package/src/app/lemonriver/text/es.ts +220 -0
  101. package/src/app/lemonriver/text/ja.ts +220 -0
  102. package/src/app/lemonriver/text/types.ts +243 -0
  103. package/src/app/lemonriver/text/zh-cn.ts +218 -0
  104. package/src/app/lemonriver/text/zh-tw.ts +218 -0
  105. package/src/app/lemonriver/theme/lemon-icon.tsx +6 -0
  106. package/src/app/lemonriver/theme/pages.test.ts +4 -0
  107. package/src/app/lemonriver/theme/pages.ts +6 -1
  108. package/src/app/lemonriver/theme/theme-menu.tsx +3 -2
  109. package/src/app/lemonriver/theme/use-theme.tsx +2 -2
  110. package/src/app/lemonriver/update/prompt.ts +1 -1
  111. package/src/app/lib/agent/use-agent.ts +4 -3
  112. package/src/app/routes/slide.tsx +1 -1
  113. package/src/app/assets/open-slide.svg +0 -39
  114. package/src/app/favicon.ico +0 -0
  115. package/src/app/favicon.svg +0 -39
@@ -16,7 +16,7 @@ import {
16
16
  import { CSS } from '@dnd-kit/utilities';
17
17
  import { ArrowDown, ArrowLeft, ArrowUp, GripVertical, Trash2 } from 'lucide-react';
18
18
  import type { ReactNode } from 'react';
19
- import { useCallback, useEffect, useRef, useState } from 'react';
19
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
20
20
  import { useNavigate, useParams } from 'react-router-dom';
21
21
  import { toast } from 'sonner';
22
22
  import { Button } from '@/components/ui/button';
@@ -33,6 +33,7 @@ import {
33
33
  sendMessage,
34
34
  setActiveSession,
35
35
  setDockOpen,
36
+ useAgentSession,
36
37
  useAgentSessions,
37
38
  useAgentStatus,
38
39
  } from '@/lib/agent/use-agent';
@@ -40,10 +41,14 @@ import { format, useLocale } from '@/lib/use-locale';
40
41
  import { cn } from '@/lib/utils';
41
42
  import { readPrefs } from '../agent-prefs/prefs';
42
43
  import { Mascot } from '../brand/mascot';
44
+ import { previewContent } from '../templates/preview-content';
45
+ import { useTemplateLibrary } from '../templates/use-library';
43
46
  import { useLrText } from '../text';
44
47
  import type { LrText } from '../text/types';
48
+ import { draftTemplateId } from './draft';
45
49
  import {
46
50
  insertPage,
51
+ lastErrorText,
47
52
  movePage,
48
53
  type Outline,
49
54
  type OutlinePage,
@@ -54,6 +59,7 @@ import {
54
59
  renamePage,
55
60
  setKind,
56
61
  } from './model';
62
+ import { PickStyle, type TemplateChoice } from './pick-style';
57
63
  import { Steps } from './steps';
58
64
 
59
65
  const SAVE_DELAY_MS = 400;
@@ -84,9 +90,23 @@ export function OutlineView() {
84
90
  const navigate = useNavigate();
85
91
  const { sessions } = useAgentSessions();
86
92
  const { provider } = useAgentStatus();
93
+ const latestSession = sessions
94
+ .filter((session) => session.slideId === slideId)
95
+ .sort((a, b) => a.updatedAt.localeCompare(b.updatedAt))
96
+ .at(-1);
97
+ const session = useAgentSession(latestSession?.id ?? null);
98
+ const sessionItems = session?.items ?? [];
99
+ const failureReason = lastErrorText(
100
+ sessionItems,
101
+ [...sessionItems].reverse().find((item) => item.kind === 'user')?.id ?? null,
102
+ );
87
103
  const [outline, setOutline] = useState<Outline | null | undefined>(undefined);
88
104
  const [items, setItems] = useState<OutlinePage[]>([]);
89
105
  const [building, setBuilding] = useState(false);
106
+ const [picking, setPicking] = useState(false);
107
+ const library = useTemplateLibrary();
108
+ const draftTemplate = useMemo(() => draftTemplateId(), []);
109
+ const preferredTemplate = outline?.templateId ?? draftTemplate;
90
110
  const dirty = useRef(false);
91
111
  const saveTimer = useRef<number | null>(null);
92
112
  const redirected = useRef(false);
@@ -170,14 +190,18 @@ export function OutlineView() {
170
190
  return session.id;
171
191
  }
172
192
 
173
- async function build() {
193
+ async function build(choice: TemplateChoice | null = null) {
174
194
  if (!outline || building) return;
175
195
  setBuilding(true);
176
196
  try {
177
197
  const res = await fetch('/__lr/outline/build', {
178
198
  method: 'POST',
179
199
  headers: { 'content-type': 'application/json' },
180
- body: JSON.stringify({ slideId, prefs: readPrefs(localStorage) }),
200
+ body: JSON.stringify({
201
+ slideId,
202
+ prefs: readPrefs(localStorage),
203
+ ...(choice ? { template: choice } : {}),
204
+ }),
181
205
  });
182
206
  if (!res.ok) throw new Error('build failed');
183
207
  setDockOpen(true);
@@ -188,6 +212,14 @@ export function OutlineView() {
188
212
  }
189
213
  }
190
214
 
215
+ function startBuild() {
216
+ if (library?.available && library.templates.length > 0) {
217
+ setPicking(true);
218
+ return;
219
+ }
220
+ void build();
221
+ }
222
+
191
223
  async function retry() {
192
224
  if (!outline) return;
193
225
  try {
@@ -231,6 +263,19 @@ export function OutlineView() {
231
263
  (session) => session.slideId === slideId && session.status === 'running',
232
264
  );
233
265
 
266
+ const pickContent = useMemo(
267
+ () =>
268
+ previewContent(
269
+ {
270
+ brief: outline?.brief ?? '',
271
+ audience: outline?.audience ?? '',
272
+ items: items.map((item) => ({ title: item.title, kind: item.kind })),
273
+ },
274
+ { locale: locale.id },
275
+ ),
276
+ [outline?.brief, outline?.audience, items, locale.id],
277
+ );
278
+
234
279
  return (
235
280
  <div data-lr-outline className="min-h-dvh bg-background text-foreground">
236
281
  <div className="mx-auto w-full max-w-[820px] px-6 py-8">
@@ -270,7 +315,15 @@ export function OutlineView() {
270
315
  <div className="min-w-0 flex-1">
271
316
  <p className="text-[15px] font-semibold">{lr.failedTitle}</p>
272
317
  <p className="mt-1 text-[13px] text-muted-foreground">{lr.failedHint}</p>
273
- <div className="mt-3 flex gap-2">
318
+ {failureReason && (
319
+ <p
320
+ data-lr-outline-error
321
+ className="mt-1.5 select-text text-[12px] leading-relaxed text-muted-foreground"
322
+ >
323
+ {format(lr.failedReason, { reason: failureReason })}
324
+ </p>
325
+ )}
326
+ <div className="mt-3 flex flex-wrap items-center gap-2">
274
327
  <Button
275
328
  type="button"
276
329
  variant="outline"
@@ -283,6 +336,19 @@ export function OutlineView() {
283
336
  <Button type="button" variant="ghost" size="sm" onClick={editBrief}>
284
337
  {lr.editBrief}
285
338
  </Button>
339
+ {failureReason && (
340
+ <Button
341
+ type="button"
342
+ variant="ghost"
343
+ size="sm"
344
+ onClick={() => {
345
+ setDockOpen(true);
346
+ window.location.assign(`${basePath()}/s/${encodeURIComponent(slideId)}`);
347
+ }}
348
+ >
349
+ {lr.openAgent}
350
+ </Button>
351
+ )}
286
352
  </div>
287
353
  </div>
288
354
  </div>
@@ -311,7 +377,24 @@ export function OutlineView() {
311
377
  {outline &&
312
378
  outline.state !== 'drafting' &&
313
379
  outline.state !== 'failed' &&
314
- outline.state !== 'building' && (
380
+ outline.state !== 'building' &&
381
+ picking && (
382
+ <PickStyle
383
+ templates={library?.templates ?? []}
384
+ occasion={outline.occasion}
385
+ content={pickContent}
386
+ preferred={preferredTemplate}
387
+ building={building}
388
+ onBack={() => setPicking(false)}
389
+ onBuild={(choice) => void build(choice)}
390
+ />
391
+ )}
392
+
393
+ {outline &&
394
+ outline.state !== 'drafting' &&
395
+ outline.state !== 'failed' &&
396
+ outline.state !== 'building' &&
397
+ !picking && (
315
398
  <>
316
399
  <ul className="mt-8 flex flex-col gap-2">
317
400
  <DndContext
@@ -362,8 +445,8 @@ export function OutlineView() {
362
445
  <div className="mt-6 flex justify-end">
363
446
  <Button
364
447
  type="button"
365
- disabled={outline.state !== 'ready' || running || building}
366
- onClick={() => void build()}
448
+ disabled={outline.state !== 'ready' || running || building || !library}
449
+ onClick={startBuild}
367
450
  >
368
451
  {lr.build}
369
452
  </Button>
@@ -0,0 +1,282 @@
1
+ import { useEffect, useMemo, useState } from 'react';
2
+ import { toast } from 'sonner';
3
+ import { Button } from '@/components/ui/button';
4
+ import { format } from '@/lib/use-locale';
5
+ import { cn } from '@/lib/utils';
6
+ import { SlideCanvas } from '../../components/slide-canvas';
7
+ import { designToCssVars } from '../../lib/design';
8
+ import { SlidePageProvider } from '../../lib/page-context';
9
+ import {
10
+ loadTemplatePreview,
11
+ type TemplateMeta,
12
+ type TemplatePreviewModule,
13
+ } from '../templates/client';
14
+ import { applyKnobs, type OccasionId, type TemplateKnobValues } from '../templates/model';
15
+ import type { PreviewContent } from '../templates/preview-content';
16
+ import { recommendTemplates } from '../templates/recommend';
17
+ import { useLrText } from '../text';
18
+
19
+ const KNOB_KEYS = ['formal', 'bright', 'motion'] as const;
20
+ type KnobKey = (typeof KNOB_KEYS)[number];
21
+
22
+ const DEFAULT_KNOBS: TemplateKnobValues = { formal: 0.5, bright: 0.5, motion: 0.5 };
23
+
24
+ export type TemplateChoice = { id: string; knobs: TemplateKnobValues };
25
+
26
+ function initialPicks(
27
+ templates: TemplateMeta[],
28
+ occasion: OccasionId | null,
29
+ preferred: string | null,
30
+ ): TemplateMeta[] {
31
+ const base = recommendTemplates(templates, { occasion }).picks;
32
+ if (!preferred) return base;
33
+ const wanted = templates.find((template) => template.id === preferred);
34
+ if (!wanted) return base;
35
+ return [wanted, ...base.filter((template) => template.id !== preferred)].slice(0, 3);
36
+ }
37
+
38
+ function usePreview(id: string): TemplatePreviewModule | null {
39
+ const [preview, setPreview] = useState<TemplatePreviewModule | null>(null);
40
+ useEffect(() => {
41
+ let cancelled = false;
42
+ setPreview(null);
43
+ loadTemplatePreview(id)
44
+ .then((module) => {
45
+ if (!cancelled) setPreview(module);
46
+ })
47
+ .catch(() => {});
48
+ return () => {
49
+ cancelled = true;
50
+ };
51
+ }, [id]);
52
+ return preview;
53
+ }
54
+
55
+ export function PickStyle({
56
+ templates,
57
+ occasion,
58
+ content,
59
+ preferred,
60
+ building,
61
+ onBack,
62
+ onBuild,
63
+ }: {
64
+ templates: TemplateMeta[];
65
+ occasion: OccasionId | null;
66
+ content: PreviewContent;
67
+ preferred: string | null;
68
+ building: boolean;
69
+ onBack: () => void;
70
+ onBuild: (choice: TemplateChoice | null) => void;
71
+ }) {
72
+ const lr = useLrText().outline;
73
+ const [picks, setPicks] = useState<TemplateMeta[]>(() =>
74
+ initialPicks(templates, occasion, preferred),
75
+ );
76
+ const [excluded, setExcluded] = useState<string[]>([]);
77
+ const [selected, setSelected] = useState<string | null>(() =>
78
+ preferred && templates.some((template) => template.id === preferred) ? preferred : null,
79
+ );
80
+ const [knobs, setKnobs] = useState<TemplateKnobValues>(DEFAULT_KNOBS);
81
+
82
+ const chosen = useMemo(
83
+ () => picks.find((template) => template.id === selected) ?? null,
84
+ [picks, selected],
85
+ );
86
+
87
+ function anotherRound() {
88
+ const shown = [...excluded, ...picks.map((template) => template.id)];
89
+ const next = recommendTemplates(templates, { occasion, exclude: shown }).picks;
90
+ setPicks(next);
91
+ setExcluded(shown);
92
+ setSelected(null);
93
+ setKnobs(DEFAULT_KNOBS);
94
+ }
95
+
96
+ function pickForMe() {
97
+ const first = picks[0];
98
+ if (!first) return;
99
+ setSelected(first.id);
100
+ toast.success(format(lr.pickToast, { name: first.name, reason: first.reason }));
101
+ onBuild({ id: first.id, knobs: DEFAULT_KNOBS });
102
+ }
103
+
104
+ if (picks.length === 0) return null;
105
+
106
+ return (
107
+ <div data-lr-pick className="mt-8">
108
+ <div className="flex items-start justify-between gap-4">
109
+ <div>
110
+ <h2 className="font-heading text-[22px] font-bold leading-7">{lr.pickTitle}</h2>
111
+ <p className="mt-1 text-[13.5px] text-muted-foreground">{lr.pickHint}</p>
112
+ </div>
113
+ <Button type="button" variant="ghost" size="sm" onClick={onBack}>
114
+ {lr.pickBack}
115
+ </Button>
116
+ </div>
117
+
118
+ <div role="radiogroup" aria-label={lr.pickTitle} className="mt-5 grid gap-4 md:grid-cols-3">
119
+ {picks.map((template) => (
120
+ <PickColumn
121
+ key={template.id}
122
+ template={template}
123
+ content={content}
124
+ knobs={selected === template.id ? knobs : DEFAULT_KNOBS}
125
+ selected={selected === template.id}
126
+ onSelect={() => setSelected(template.id)}
127
+ />
128
+ ))}
129
+ </div>
130
+
131
+ {chosen && (
132
+ <div data-lr-knobs className="mt-5 rounded-[14px] border border-border bg-card px-5 py-4">
133
+ <p className="text-[13px] font-semibold">
134
+ {format(lr.pickKnobsFor, { name: chosen.name })}
135
+ </p>
136
+ <div className="mt-3 flex flex-col gap-3">
137
+ {KNOB_KEYS.map((key) => {
138
+ const knob = chosen.knobs[key];
139
+ if (!knob) return null;
140
+ return (
141
+ <div key={key} data-lr-knob={key}>
142
+ <label className="flex items-center gap-3 text-[12.5px] text-muted-foreground">
143
+ <span className="w-[104px] shrink-0">{lr[knobLabelKey(key)]}</span>
144
+ <input
145
+ type="range"
146
+ min={0}
147
+ max={1}
148
+ step={0.5}
149
+ value={knobs[key] ?? 0.5}
150
+ aria-label={lr[knobLabelKey(key)]}
151
+ onChange={(event) =>
152
+ setKnobs((prev) => ({ ...prev, [key]: Number(event.target.value) }))
153
+ }
154
+ className="h-1.5 flex-1 accent-[var(--lr-focus)]"
155
+ />
156
+ </label>
157
+ {key === 'motion' && (
158
+ <p className="mt-1 pl-[116px] text-[11.5px] text-muted-foreground">
159
+ {lr.motionHint}
160
+ </p>
161
+ )}
162
+ </div>
163
+ );
164
+ })}
165
+ </div>
166
+ </div>
167
+ )}
168
+
169
+ <div className="mt-5 flex flex-wrap items-center gap-2">
170
+ <Button type="button" variant="outline" size="sm" onClick={anotherRound}>
171
+ {lr.pickMore}
172
+ </Button>
173
+ <Button type="button" variant="ghost" size="sm" onClick={pickForMe} disabled={building}>
174
+ {lr.pickYou}
175
+ </Button>
176
+ <Button
177
+ type="button"
178
+ variant="ghost"
179
+ size="sm"
180
+ disabled={building}
181
+ onClick={() => onBuild(null)}
182
+ >
183
+ {lr.pickNone}
184
+ </Button>
185
+ <Button
186
+ type="button"
187
+ className="ml-auto"
188
+ disabled={!selected || building}
189
+ onClick={() => selected && onBuild({ id: selected, knobs })}
190
+ >
191
+ {lr.pickStart}
192
+ </Button>
193
+ </div>
194
+ </div>
195
+ );
196
+ }
197
+
198
+ function knobLabelKey(key: KnobKey): 'knobFormal' | 'knobBright' | 'knobMotion' {
199
+ if (key === 'formal') return 'knobFormal';
200
+ if (key === 'bright') return 'knobBright';
201
+ return 'knobMotion';
202
+ }
203
+
204
+ function PickColumn({
205
+ template,
206
+ content,
207
+ knobs,
208
+ selected,
209
+ onSelect,
210
+ }: {
211
+ template: TemplateMeta;
212
+ content: PreviewContent;
213
+ knobs: TemplateKnobValues;
214
+ selected: boolean;
215
+ onSelect: () => void;
216
+ }) {
217
+ const lr = useLrText().outline;
218
+ const preview = usePreview(template.id);
219
+ const design = useMemo(
220
+ () => applyKnobs(template.design, template.knobs, knobs),
221
+ [template, knobs],
222
+ );
223
+ const vars = designToCssVars(design);
224
+
225
+ return (
226
+ // biome-ignore lint/a11y/useSemanticElements: the column is a preview card, not a plain radio
227
+ <button
228
+ type="button"
229
+ role="radio"
230
+ aria-checked={selected}
231
+ data-lr-pick-column={template.id}
232
+ onClick={onSelect}
233
+ className={cn(
234
+ 'block w-full overflow-hidden rounded-[14px] border-2 bg-card p-2.5 text-left outline-none transition-colors',
235
+ 'focus-visible:ring-2 focus-visible:ring-ring/40',
236
+ selected
237
+ ? 'border-[var(--lr-focus)] shadow-[var(--lr-shadow-2)]'
238
+ : 'border-border hover:border-[var(--lr-text-3)]',
239
+ )}
240
+ >
241
+ <div
242
+ data-lr-pick-design
243
+ style={vars}
244
+ className="aspect-video overflow-hidden rounded-[8px] border border-border bg-white"
245
+ >
246
+ <SlideCanvas flat freezeMotion design={design}>
247
+ <SlidePageProvider index={0} total={2}>
248
+ {preview ? <preview.CoverPreview {...content.cover} /> : null}
249
+ </SlidePageProvider>
250
+ </SlideCanvas>
251
+ </div>
252
+ <div
253
+ data-lr-pick-design
254
+ style={vars}
255
+ className="mt-2 aspect-video overflow-hidden rounded-[8px] border border-border bg-white"
256
+ >
257
+ <SlideCanvas flat freezeMotion design={design}>
258
+ <SlidePageProvider index={1} total={2}>
259
+ {preview ? (
260
+ <preview.DataPreview
261
+ title={content.data.title}
262
+ value={content.data.sample ? undefined : content.data.value}
263
+ unit={content.data.sample ? undefined : content.data.unit}
264
+ caption={content.data.caption}
265
+ context={content.data.context}
266
+ />
267
+ ) : null}
268
+ </SlidePageProvider>
269
+ </SlideCanvas>
270
+ </div>
271
+ {content.data.sample && (
272
+ <p className="mt-1 text-right text-[11.5px] text-muted-foreground">{lr.pickSample}</p>
273
+ )}
274
+ <div className="mt-2 px-1 pb-1">
275
+ <p className="truncate text-[13.5px] font-semibold">{template.name}</p>
276
+ <p className="mt-0.5 line-clamp-2 text-[12px] leading-4 text-muted-foreground">
277
+ {template.reason}
278
+ </p>
279
+ </div>
280
+ </button>
281
+ );
282
+ }
@@ -14,8 +14,13 @@ const paths = (routes: unknown[]) =>
14
14
  routes.filter(Boolean).map((r) => (r as ReactElement<{ path: string }>).props.path);
15
15
 
16
16
  describe('lemonRiverRoutes', () => {
17
- it('adds the board, the outline and the not-found page', () => {
18
- expect(paths(lemonRiverRoutes())).toEqual(['/s/:slideId/board', '/s/:slideId/outline', '*']);
17
+ it('adds the board, the outline, the template demo and the not-found page', () => {
18
+ expect(paths(lemonRiverRoutes())).toEqual([
19
+ '/s/:slideId/board',
20
+ '/s/:slideId/outline',
21
+ '/template-demo/:templateId',
22
+ '*',
23
+ ]);
19
24
  });
20
25
 
21
26
  it('drops the pages whose feature is off', () => {
@@ -26,12 +31,19 @@ describe('lemonRiverRoutes', () => {
26
31
  });
27
32
 
28
33
  describe('lemonRiverShellRoutes', () => {
29
- it('puts our home and the guided flow first, then settings and trash', () => {
30
- expect(paths(lemonRiverShellRoutes())).toEqual(['/', '/new', '/settings', '/trash']);
34
+ it('puts our home and the guided flow first, then settings, templates and trash', () => {
35
+ expect(paths(lemonRiverShellRoutes())).toEqual([
36
+ '/',
37
+ '/new',
38
+ '/settings',
39
+ '/templates',
40
+ '/trash',
41
+ ]);
31
42
  });
32
43
 
33
44
  it('leaves out the pages whose feature is off', () => {
34
- vi.mocked(isFeatureEnabled).mockImplementation((id) => id !== 'trash');
45
+ vi.mocked(isFeatureEnabled).mockImplementation((id) => id !== 'trash' && id !== 'templates');
35
46
  expect(paths(lemonRiverShellRoutes())).toEqual(['/', '/new', '/settings']);
47
+ vi.mocked(isFeatureEnabled).mockReturnValue(true);
36
48
  });
37
49
  });
@@ -13,6 +13,12 @@ const DescribePage = lazy(() =>
13
13
  const OutlinePage = lazy(() =>
14
14
  import('./outline/outline-page').then((m) => ({ default: m.OutlineView })),
15
15
  );
16
+ const TemplateDemoPage = lazy(() =>
17
+ import('./templates/demo-page').then((m) => ({ default: m.TemplateDemoPage })),
18
+ );
19
+ const TemplatesPage = lazy(() =>
20
+ import('./templates/library-page').then((m) => ({ default: m.TemplatesPage })),
21
+ );
16
22
 
17
23
  /** Routes of our own, outside the home shell. Placed before the official catch-all. */
18
24
  export function lemonRiverRoutes() {
@@ -39,6 +45,17 @@ export function lemonRiverRoutes() {
39
45
  }
40
46
  />
41
47
  ),
48
+ isFeatureEnabled('templates') && (
49
+ <Route
50
+ key="template-demo"
51
+ path="/template-demo/:templateId"
52
+ element={
53
+ <Suspense fallback={null}>
54
+ <TemplateDemoPage />
55
+ </Suspense>
56
+ }
57
+ />
58
+ ),
42
59
  <Route key="not-found" path="*" element={<NotFound />} />,
43
60
  ];
44
61
  }
@@ -61,6 +78,17 @@ export function lemonRiverShellRoutes() {
61
78
  isFeatureEnabled('settings') && (
62
79
  <Route key="settings" path="/settings" element={<SettingsPage />} />
63
80
  ),
81
+ isFeatureEnabled('templates') && (
82
+ <Route
83
+ key="templates"
84
+ path="/templates"
85
+ element={
86
+ <Suspense fallback={null}>
87
+ <TemplatesPage />
88
+ </Suspense>
89
+ }
90
+ />
91
+ ),
64
92
  isFeatureEnabled('trash') && <Route key="trash" path="/trash" element={<TrashPage />} />,
65
93
  ];
66
94
  }
@@ -5,6 +5,7 @@ import { useLocale } from '@/lib/use-locale';
5
5
  import { cn } from '@/lib/utils';
6
6
  import type { AgentPrefs } from '../agent-prefs/prefs';
7
7
  import { updateAgentPrefs, useAgentPrefs } from '../agent-prefs/use-prefs';
8
+ import { AgentProvidersSection } from '../agent-providers/section';
8
9
  import { HelperMascot, type HelperRole } from '../brand/mascot';
9
10
  import { ONBOARDED_KEY } from '../onboarding/onboarding';
10
11
  import { useLrText } from '../text';
@@ -164,6 +165,8 @@ export function SettingsPage() {
164
165
  </div>
165
166
  </section>
166
167
 
168
+ {import.meta.env.DEV && <AgentProvidersSection />}
169
+
167
170
  {import.meta.env.DEV && (
168
171
  <section
169
172
  data-lr-agent-prefs
@@ -3,7 +3,7 @@ import { useEffect } from 'react';
3
3
  import { createPortal } from 'react-dom';
4
4
  import { useNavigate } from 'react-router-dom';
5
5
  import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
6
- import { hasModifier, isShortcutControlTarget, isTypingTarget } from '@/lib/keys';
6
+ import { hasModifier, isTypingTarget } from '@/lib/keys';
7
7
  import { cn } from '@/lib/utils';
8
8
  import { useSlot } from './chrome/use-slot';
9
9
  import { isFeatureEnabled } from './features';
@@ -16,6 +16,18 @@ type Props = {
16
16
  overviewOpen: boolean;
17
17
  };
18
18
 
19
+ /**
20
+ * A key pressed with focus inside a menu or dialog belongs to that overlay. A
21
+ * focused button does not: the shortcut has to reach the page from any view,
22
+ * including the asset grid, whose own controls sit under the pointer.
23
+ */
24
+ function isInsideOverlay(target: EventTarget | null): boolean {
25
+ return (
26
+ target instanceof Element &&
27
+ !!target.closest('[role="dialog"], [role="menu"], [role="listbox"]')
28
+ );
29
+ }
30
+
19
31
  export function SlideExtensions({ slideId, overviewOpen }: Props) {
20
32
  const enabled = isFeatureEnabled('board');
21
33
  const navigate = useNavigate();
@@ -28,7 +40,7 @@ export function SlideExtensions({ slideId, overviewOpen }: Props) {
28
40
  const onKey = (e: KeyboardEvent) => {
29
41
  if (
30
42
  isTypingTarget(e.target) ||
31
- isShortcutControlTarget(e.target) ||
43
+ isInsideOverlay(e.target) ||
32
44
  e.isComposing ||
33
45
  e.keyCode === 229 ||
34
46
  e.defaultPrevented
@@ -0,0 +1,60 @@
1
+ import {
2
+ loadTemplateDemo as load,
3
+ loadTemplatePreview as loadPreview,
4
+ templates as raw,
5
+ } from 'virtual:open-slide/templates';
6
+ import type { ReactNode } from 'react';
7
+ import type { DesignSystem } from '../../lib/design';
8
+ import type { Page } from '../../lib/sdk';
9
+ import type { OccasionId, TemplateKnobs } from './model';
10
+
11
+ export type TemplateMeta = {
12
+ id: string;
13
+ name: string;
14
+ occasions: OccasionId[];
15
+ audience: string;
16
+ object: string;
17
+ reason: string;
18
+ accent: string;
19
+ design: DesignSystem;
20
+ knobs: TemplateKnobs;
21
+ skeletons: string[];
22
+ hasDemo: boolean;
23
+ pages: number;
24
+ previewPages: number[] | null;
25
+ minType?: number;
26
+ };
27
+
28
+ export type TemplateDemoModule = {
29
+ default: Page[];
30
+ design?: DesignSystem;
31
+ };
32
+
33
+ export const templates: TemplateMeta[] = raw;
34
+
35
+ export async function loadTemplateDemo(id: string): Promise<TemplateDemoModule> {
36
+ return load(id);
37
+ }
38
+
39
+ export type TemplatePreviewModule = {
40
+ /** An empty `brand` or `mark` is left undrawn rather than filled with sample content. */
41
+ CoverPreview: (props: {
42
+ title: string;
43
+ subtitle: string;
44
+ meta: string;
45
+ brand?: string;
46
+ mark?: string;
47
+ }) => ReactNode;
48
+ /** Leaving `value` out makes the template draw its own sample number. */
49
+ DataPreview: (props: {
50
+ title: string;
51
+ value?: string;
52
+ unit?: string;
53
+ caption: string;
54
+ context: string;
55
+ }) => ReactNode;
56
+ };
57
+
58
+ export async function loadTemplatePreview(id: string): Promise<TemplatePreviewModule> {
59
+ return loadPreview(id) as Promise<TemplatePreviewModule>;
60
+ }