@lemonriver/core 0.5.0 → 0.7.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.
- package/dist/{build-CS1goZxt.js → build-CKwrex8y.js} +1 -1
- package/dist/cli/bin.js +3 -3
- package/dist/{config-BpbcCbUv.js → config-B1_gk0sy.js} +2983 -266
- package/dist/{dev-BpYnfgLL.js → dev-DZ2Yzl2p.js} +1 -1
- package/dist/{preview-HSzPPkSs.js → preview-hMDcuHfP.js} +1 -1
- package/dist/vite/index.js +1 -1
- package/package.json +1 -1
- package/src/app/lemonriver/board/blocks/classify.test.ts +5 -0
- package/src/app/lemonriver/board/blocks/classify.ts +29 -2
- package/src/app/lemonriver/board/blocks/snapshot.ts +34 -4
- package/src/app/lemonriver/board/board-page.tsx +15 -0
- package/src/app/lemonriver/board/model/agent-tasks.ts +33 -1
- package/src/app/lemonriver/board/model/self-check.test.ts +329 -0
- package/src/app/lemonriver/board/model/self-check.ts +489 -0
- package/src/app/lemonriver/board/page-node.tsx +23 -1
- package/src/app/lemonriver/board/self-check-jump.ts +23 -0
- package/src/app/lemonriver/board/self-check-panel.tsx +272 -0
- package/src/app/lemonriver/board/self-check-runner.tsx +150 -0
- package/src/app/lemonriver/board/use-self-check.ts +117 -0
- package/src/app/lemonriver/chrome/app-chrome.tsx +12 -1
- package/src/app/lemonriver/chrome/filter-pill.tsx +30 -0
- package/src/app/lemonriver/chrome/sidebar-extras.tsx +12 -1
- package/src/app/lemonriver/features.test.ts +10 -0
- package/src/app/lemonriver/features.ts +3 -1
- package/src/app/lemonriver/feedback/pending-toast.ts +7 -2
- package/src/app/lemonriver/home/deck-card.tsx +20 -1
- package/src/app/lemonriver/home/home-page.tsx +107 -7
- package/src/app/lemonriver/home/use-deck-times.ts +4 -1
- package/src/app/lemonriver/outline/build-team.tsx +42 -0
- package/src/app/lemonriver/outline/describe-page.tsx +128 -27
- package/src/app/lemonriver/outline/draft.ts +38 -0
- package/src/app/lemonriver/outline/model.test.ts +79 -0
- package/src/app/lemonriver/outline/model.ts +80 -7
- package/src/app/lemonriver/outline/outline-page.tsx +56 -6
- package/src/app/lemonriver/outline/pick-style.tsx +282 -0
- package/src/app/lemonriver/routes.test.tsx +17 -5
- package/src/app/lemonriver/routes.tsx +28 -0
- package/src/app/lemonriver/share/capture.ts +76 -0
- package/src/app/lemonriver/share/client.ts +162 -0
- package/src/app/lemonriver/share/codes.test.ts +49 -0
- package/src/app/lemonriver/share/codes.ts +30 -0
- package/src/app/lemonriver/share/compare.test.ts +199 -0
- package/src/app/lemonriver/share/compare.ts +367 -0
- package/src/app/lemonriver/share/drop.ts +84 -0
- package/src/app/lemonriver/share/folder.test.ts +42 -0
- package/src/app/lemonriver/share/folder.ts +29 -0
- package/src/app/lemonriver/share/freeze.ts +51 -0
- package/src/app/lemonriver/share/guide.test.ts +78 -0
- package/src/app/lemonriver/share/guide.ts +222 -0
- package/src/app/lemonriver/share/import-dialog.tsx +391 -0
- package/src/app/lemonriver/share/import-entry.tsx +106 -0
- package/src/app/lemonriver/share/model.ts +150 -0
- package/src/app/lemonriver/share/naming.test.ts +59 -0
- package/src/app/lemonriver/share/naming.ts +71 -0
- package/src/app/lemonriver/share/paths.test.ts +75 -0
- package/src/app/lemonriver/share/paths.ts +181 -0
- package/src/app/lemonriver/share/pdf.test.ts +79 -0
- package/src/app/lemonriver/share/pdf.ts +169 -0
- package/src/app/lemonriver/share/share-dialog.tsx +286 -0
- package/src/app/lemonriver/share/summary.ts +47 -0
- package/src/app/lemonriver/slide-extensions.tsx +69 -23
- package/src/app/lemonriver/templates/client.ts +60 -0
- package/src/app/lemonriver/templates/demo-page.tsx +79 -0
- package/src/app/lemonriver/templates/knobs.test.ts +62 -0
- package/src/app/lemonriver/templates/knobs.ts +62 -0
- package/src/app/lemonriver/templates/library-page.tsx +295 -0
- package/src/app/lemonriver/templates/model.test.ts +175 -0
- package/src/app/lemonriver/templates/model.ts +339 -0
- package/src/app/lemonriver/templates/preview-content.test.ts +117 -0
- package/src/app/lemonriver/templates/preview-content.ts +149 -0
- package/src/app/lemonriver/templates/recommend.test.ts +71 -0
- package/src/app/lemonriver/templates/recommend.ts +72 -0
- package/src/app/lemonriver/templates/use-library.ts +58 -0
- package/src/app/lemonriver/templates/virtual.d.ts +28 -0
- package/src/app/lemonriver/text/en.ts +124 -0
- package/src/app/lemonriver/text/es.ts +124 -0
- package/src/app/lemonriver/text/ja.ts +124 -0
- package/src/app/lemonriver/text/types.ts +151 -0
- package/src/app/lemonriver/text/zh-cn.ts +119 -0
- package/src/app/lemonriver/text/zh-tw.ts +119 -0
- package/src/app/lemonriver/theme/pages.test.ts +4 -0
- package/src/app/lemonriver/theme/pages.ts +6 -1
- package/src/app/lemonriver/update/prompt.ts +1 -1
|
@@ -51,6 +51,11 @@ const outline: Outline = {
|
|
|
51
51
|
lastTurn: null,
|
|
52
52
|
prefs: DEFAULT_PREFS,
|
|
53
53
|
decisions: [],
|
|
54
|
+
occasion: 'report',
|
|
55
|
+
audience: '董事会成员',
|
|
56
|
+
templatePrompt: '',
|
|
57
|
+
templateSkeletons: [],
|
|
58
|
+
templateId: null,
|
|
54
59
|
};
|
|
55
60
|
|
|
56
61
|
describe('sanitizeOutline', () => {
|
|
@@ -58,6 +63,23 @@ describe('sanitizeOutline', () => {
|
|
|
58
63
|
expect(sanitizeOutline(outline)).toEqual(outline);
|
|
59
64
|
});
|
|
60
65
|
|
|
66
|
+
it('keeps the occasion and audience, and drops ones it cannot use', () => {
|
|
67
|
+
expect(sanitizeOutline(outline)).toMatchObject({ occasion: 'report', audience: '董事会成员' });
|
|
68
|
+
expect(sanitizeOutline({ ...outline, occasion: 'nope', audience: 7 })).toMatchObject({
|
|
69
|
+
occasion: null,
|
|
70
|
+
audience: '',
|
|
71
|
+
});
|
|
72
|
+
expect(sanitizeOutline({ ...outline, audience: ` ${'字'.repeat(80)} ` })?.audience).toBe(
|
|
73
|
+
'字'.repeat(40),
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('reads a record written before the occasion fields existed', () => {
|
|
78
|
+
expect(sanitizeOutline({ ...outline, occasion: undefined, audience: undefined })).toMatchObject(
|
|
79
|
+
{ occasion: null, audience: '' },
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
|
|
61
83
|
it('fills the build fields on a record written before they existed', () => {
|
|
62
84
|
const old = {
|
|
63
85
|
state: 'building',
|
|
@@ -313,6 +335,63 @@ describe('prompts', () => {
|
|
|
313
335
|
});
|
|
314
336
|
});
|
|
315
337
|
|
|
338
|
+
describe('template prompts', () => {
|
|
339
|
+
const applied: Outline = {
|
|
340
|
+
...outline,
|
|
341
|
+
templatePrompt: 'This deck uses the "Board" template.',
|
|
342
|
+
templateSkeletons: ['cover', 'overview', 'figure', 'cards', 'compare', 'ask', 'end'],
|
|
343
|
+
};
|
|
344
|
+
|
|
345
|
+
it('puts the template instructions first on page one', () => {
|
|
346
|
+
const text = pagePrompt(applied, 'deck-1', 1);
|
|
347
|
+
expect(text.startsWith('This deck uses the "Board" template.')).toBe(true);
|
|
348
|
+
expect(text).toContain('Build slides/deck-1/index.tsx');
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
it('suggests a skeleton per page from the ones the template has', () => {
|
|
352
|
+
const text = pagePrompt(applied, 'deck-1', 1);
|
|
353
|
+
expect(text).toContain('1. [cover] Cover → cover');
|
|
354
|
+
expect(text).toContain('2. [list] Why now → cards');
|
|
355
|
+
expect(text).toContain('3. [kpi] Numbers → overview');
|
|
356
|
+
expect(text).toContain('4. [end] End → end');
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
it('leaves a page kind alone when the template has no skeleton for it', () => {
|
|
360
|
+
const partial: Outline = { ...outline, templateSkeletons: ['cover', 'end'] };
|
|
361
|
+
const text = pagePrompt(partial, 'deck-1', 1);
|
|
362
|
+
expect(text).toContain('2. [list] Why now\n');
|
|
363
|
+
expect(text).toContain('3. [kpi] Numbers\n');
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it('tells later pages to keep the template and its guide', () => {
|
|
367
|
+
const text = pagePrompt(applied, 'deck-1', 3);
|
|
368
|
+
expect(text.split('\n')[0]).toBe(
|
|
369
|
+
'Page 3 of 4: [kpi] Numbers → overview. Write only this page; leave the others as they are.',
|
|
370
|
+
);
|
|
371
|
+
expect(text).toContain('Keep using the template in ./kit/');
|
|
372
|
+
expect(text).toContain('kit/docs/GUIDE.md');
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it('adds the quality checklist to the review pass', () => {
|
|
376
|
+
const withTemplate = reviewPrompt(applied, 'deck-1');
|
|
377
|
+
expect(withTemplate).toContain('kit/docs/质量清单.md');
|
|
378
|
+
expect(withTemplate).toContain('take a screenshot of every page');
|
|
379
|
+
const plain = reviewPrompt(outline, 'deck-1');
|
|
380
|
+
expect(plain).not.toContain('质量清单');
|
|
381
|
+
expect(plain).toContain('pre-delivery checklist at the end of the slide-authoring skill');
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it('reads only the skeletons the model knows', () => {
|
|
385
|
+
const read = sanitizeOutline({
|
|
386
|
+
...outline,
|
|
387
|
+
templatePrompt: 'x',
|
|
388
|
+
templateSkeletons: ['cover', 'nope', 3, 'cover', 'end'],
|
|
389
|
+
});
|
|
390
|
+
expect(read?.templateSkeletons).toEqual(['cover', 'end']);
|
|
391
|
+
expect(read?.templatePrompt).toBe('x');
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
|
|
316
395
|
const building = (patch: Partial<Outline> = {}): Outline => ({
|
|
317
396
|
...outline,
|
|
318
397
|
state: 'building',
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AgentItem } from '../../../agent/types';
|
|
2
2
|
import { type AgentPrefs, prefsLines, sanitizePrefs } from '../agent-prefs/prefs';
|
|
3
|
+
import { OCCASIONS, type OccasionId, SKELETONS, type SkeletonId } from '../templates/model';
|
|
3
4
|
|
|
4
5
|
export const PAGE_KINDS = ['cover', 'kpi', 'chart', 'list', 'page', 'end'] as const;
|
|
5
6
|
export type PageKind = (typeof PAGE_KINDS)[number];
|
|
@@ -31,6 +32,14 @@ export type Outline = {
|
|
|
31
32
|
lastTurn: BuildTurn | null;
|
|
32
33
|
prefs: AgentPrefs;
|
|
33
34
|
decisions: Decision[];
|
|
35
|
+
occasion: OccasionId | null;
|
|
36
|
+
audience: string;
|
|
37
|
+
/** The template's opening instructions, written when the build copied its kit in. */
|
|
38
|
+
templatePrompt: string;
|
|
39
|
+
/** The skeletons that travelled with that template, for the per-page suggestions. */
|
|
40
|
+
templateSkeletons: SkeletonId[];
|
|
41
|
+
/** The template picked when describing the deck; a direct build applies it. */
|
|
42
|
+
templateId: string | null;
|
|
34
43
|
};
|
|
35
44
|
|
|
36
45
|
export const OUTLINE_PAGE_SIZES = [5, 8, 12] as const;
|
|
@@ -38,8 +47,22 @@ export const MAX_ITEMS = 30;
|
|
|
38
47
|
export const MIN_ITEMS = 2;
|
|
39
48
|
export const MAX_TITLE = 120;
|
|
40
49
|
export const MAX_BRIEF = 2000;
|
|
50
|
+
export const MAX_AUDIENCE = 40;
|
|
41
51
|
export const MAX_DECISIONS = 20;
|
|
42
52
|
export const MAX_DECISION_TEXT = 120;
|
|
53
|
+
export const MAX_TEMPLATE_PROMPT = 8000;
|
|
54
|
+
|
|
55
|
+
const SKELETON_IDS = new Set<string>(SKELETONS.map((skeleton) => skeleton.id));
|
|
56
|
+
|
|
57
|
+
function sanitizeSkeletons(raw: unknown): SkeletonId[] {
|
|
58
|
+
if (!Array.isArray(raw)) return [];
|
|
59
|
+
const out: SkeletonId[] = [];
|
|
60
|
+
for (const entry of raw) {
|
|
61
|
+
if (typeof entry !== 'string' || !SKELETON_IDS.has(entry)) continue;
|
|
62
|
+
if (!out.includes(entry as SkeletonId)) out.push(entry as SkeletonId);
|
|
63
|
+
}
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
43
66
|
|
|
44
67
|
const ID_RE = /^[a-z0-9-]{1,40}$/;
|
|
45
68
|
const BLOCK_RE = /<lemonriver-outline>([\s\S]*?)<\/lemonriver-outline>/gi;
|
|
@@ -59,6 +82,14 @@ export function isOutlineState(value: unknown): value is OutlineState {
|
|
|
59
82
|
return typeof value === 'string' && (OUTLINE_STATES as readonly string[]).includes(value);
|
|
60
83
|
}
|
|
61
84
|
|
|
85
|
+
export function isOccasionId(value: unknown): value is OccasionId {
|
|
86
|
+
return typeof value === 'string' && OCCASIONS.some((occasion) => occasion.id === value);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function cleanAudience(value: unknown): string {
|
|
90
|
+
return typeof value === 'string' ? value.trim().slice(0, MAX_AUDIENCE) : '';
|
|
91
|
+
}
|
|
92
|
+
|
|
62
93
|
function cleanTitle(value: unknown): string {
|
|
63
94
|
return typeof value === 'string' ? value.trim().slice(0, MAX_TITLE) : '';
|
|
64
95
|
}
|
|
@@ -178,6 +209,15 @@ export function sanitizeOutline(raw: unknown): Outline | null {
|
|
|
178
209
|
lastTurn: cleanTurn(r.lastTurn, items.length),
|
|
179
210
|
prefs: sanitizePrefs(r.prefs),
|
|
180
211
|
decisions: sanitizeDecisions(r.decisions),
|
|
212
|
+
occasion: isOccasionId(r.occasion) ? r.occasion : null,
|
|
213
|
+
audience: cleanAudience(r.audience),
|
|
214
|
+
templatePrompt:
|
|
215
|
+
typeof r.templatePrompt === 'string' ? r.templatePrompt.slice(0, MAX_TEMPLATE_PROMPT) : '',
|
|
216
|
+
templateSkeletons: sanitizeSkeletons(r.templateSkeletons),
|
|
217
|
+
templateId:
|
|
218
|
+
typeof r.templateId === 'string' && /^[a-z0-9][a-z0-9-]*$/.test(r.templateId)
|
|
219
|
+
? r.templateId
|
|
220
|
+
: null,
|
|
181
221
|
};
|
|
182
222
|
}
|
|
183
223
|
|
|
@@ -260,6 +300,29 @@ const KIND_GUIDE: Record<PageKind, string> = {
|
|
|
260
300
|
end: 'closing — the last page and what should happen next',
|
|
261
301
|
};
|
|
262
302
|
|
|
303
|
+
const TEMPLATE_PAGE_LINE =
|
|
304
|
+
'Keep using the template in ./kit/ — follow kit/docs/GUIDE.md and pick one skeleton per page.';
|
|
305
|
+
|
|
306
|
+
const TEMPLATE_REVIEW_LINE =
|
|
307
|
+
"Before you finish, take a screenshot of every page (see the slide-authoring skill's preview section) and go through kit/docs/质量清单.md item by item; fix what fails. Reply with the items you could not satisfy, if any.";
|
|
308
|
+
|
|
309
|
+
const FRAMEWORK_REVIEW_LINE =
|
|
310
|
+
"Before you finish, take a screenshot of every page (see the slide-authoring skill's preview section) and go through the pre-delivery checklist at the end of the slide-authoring skill item by item; fix what fails. Reply with the items you could not satisfy, if any.";
|
|
311
|
+
|
|
312
|
+
const SKELETON_FOR_KIND: Record<PageKind, SkeletonId[]> = {
|
|
313
|
+
cover: ['cover'],
|
|
314
|
+
kpi: ['overview', 'bignum'],
|
|
315
|
+
chart: ['figure'],
|
|
316
|
+
list: ['cards'],
|
|
317
|
+
page: ['compare', 'process'],
|
|
318
|
+
end: ['end'],
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
/** The skeleton the template offers for a page of this kind, if it has one. */
|
|
322
|
+
export function skeletonFor(kind: PageKind, available: readonly SkeletonId[]): SkeletonId | null {
|
|
323
|
+
return SKELETON_FOR_KIND[kind].find((id) => available.includes(id)) ?? null;
|
|
324
|
+
}
|
|
325
|
+
|
|
263
326
|
export function outlinePrompt(outline: Outline, slideId: string, lang: string): string {
|
|
264
327
|
const fileList =
|
|
265
328
|
outline.files.length > 0
|
|
@@ -286,22 +349,31 @@ export function pagePrompt(outline: Outline, slideId: string, k: number): string
|
|
|
286
349
|
const page = outline.items[k - 1];
|
|
287
350
|
if (k >= 2 && page) {
|
|
288
351
|
const title = page.title || '(untitled)';
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
]
|
|
352
|
+
const skeleton = skeletonFor(page.kind, outline.templateSkeletons);
|
|
353
|
+
const lines = [
|
|
354
|
+
`Page ${k} of ${outline.items.length}: [${page.kind}] ${title}${skeleton ? ` → ${skeleton}` : ''}. Write only this page; leave the others as they are.`,
|
|
355
|
+
];
|
|
356
|
+
if (outline.templatePrompt) lines.push(TEMPLATE_PAGE_LINE);
|
|
357
|
+
lines.push(...prefsLines(outline.prefs, 'page'));
|
|
358
|
+
return lines.join('\n');
|
|
293
359
|
}
|
|
294
360
|
const list = outline.items
|
|
295
|
-
.map((item, i) =>
|
|
361
|
+
.map((item, i) => {
|
|
362
|
+
const base = `${i + 1}. [${item.kind}] ${item.title || '(untitled)'}`;
|
|
363
|
+
const skeleton = skeletonFor(item.kind, outline.templateSkeletons);
|
|
364
|
+
return skeleton ? `${base} → ${skeleton}` : base;
|
|
365
|
+
})
|
|
296
366
|
.join('\n');
|
|
297
|
-
|
|
367
|
+
const lines = [
|
|
298
368
|
`Build ${file} from this outline, one page per turn. This turn: write page 1 only, replacing the placeholder page, and set meta.title to the deck title. Pages:`,
|
|
299
369
|
list,
|
|
300
370
|
'Page kinds and how to write them:',
|
|
301
371
|
...PAGE_KINDS.map((kind) => `- ${KIND_GUIDE[kind]}`),
|
|
302
372
|
'Numbers from the reference files stay exactly as written there.',
|
|
303
373
|
...prefsLines(outline.prefs, 'page'),
|
|
304
|
-
]
|
|
374
|
+
];
|
|
375
|
+
if (outline.templatePrompt) return `${outline.templatePrompt}\n\n${lines.join('\n')}`;
|
|
376
|
+
return lines.join('\n');
|
|
305
377
|
}
|
|
306
378
|
|
|
307
379
|
export function reviewPrompt(outline: Outline, slideId: string): string {
|
|
@@ -310,6 +382,7 @@ export function reviewPrompt(outline: Outline, slideId: string): string {
|
|
|
310
382
|
`Check each page of slides/${slideId}/index.tsx against the outline and the reference files in slides/${slideId}/assets/:`,
|
|
311
383
|
'fix typos and any number that differs from the files.',
|
|
312
384
|
];
|
|
385
|
+
lines.push(outline.templatePrompt ? TEMPLATE_REVIEW_LINE : FRAMEWORK_REVIEW_LINE);
|
|
313
386
|
if (outline.prefs.askOnMismatch) {
|
|
314
387
|
lines.push(
|
|
315
388
|
'If two files give different numbers for the same thing, ask the user which to use before changing it.',
|
|
@@ -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';
|
|
@@ -41,8 +41,11 @@ import { format, useLocale } from '@/lib/use-locale';
|
|
|
41
41
|
import { cn } from '@/lib/utils';
|
|
42
42
|
import { readPrefs } from '../agent-prefs/prefs';
|
|
43
43
|
import { Mascot } from '../brand/mascot';
|
|
44
|
+
import { previewContent } from '../templates/preview-content';
|
|
45
|
+
import { useTemplateLibrary } from '../templates/use-library';
|
|
44
46
|
import { useLrText } from '../text';
|
|
45
47
|
import type { LrText } from '../text/types';
|
|
48
|
+
import { draftTemplateId } from './draft';
|
|
46
49
|
import {
|
|
47
50
|
insertPage,
|
|
48
51
|
lastErrorText,
|
|
@@ -56,6 +59,7 @@ import {
|
|
|
56
59
|
renamePage,
|
|
57
60
|
setKind,
|
|
58
61
|
} from './model';
|
|
62
|
+
import { PickStyle, type TemplateChoice } from './pick-style';
|
|
59
63
|
import { Steps } from './steps';
|
|
60
64
|
|
|
61
65
|
const SAVE_DELAY_MS = 400;
|
|
@@ -99,6 +103,10 @@ export function OutlineView() {
|
|
|
99
103
|
const [outline, setOutline] = useState<Outline | null | undefined>(undefined);
|
|
100
104
|
const [items, setItems] = useState<OutlinePage[]>([]);
|
|
101
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;
|
|
102
110
|
const dirty = useRef(false);
|
|
103
111
|
const saveTimer = useRef<number | null>(null);
|
|
104
112
|
const redirected = useRef(false);
|
|
@@ -182,14 +190,18 @@ export function OutlineView() {
|
|
|
182
190
|
return session.id;
|
|
183
191
|
}
|
|
184
192
|
|
|
185
|
-
async function build() {
|
|
193
|
+
async function build(choice: TemplateChoice | null = null) {
|
|
186
194
|
if (!outline || building) return;
|
|
187
195
|
setBuilding(true);
|
|
188
196
|
try {
|
|
189
197
|
const res = await fetch('/__lr/outline/build', {
|
|
190
198
|
method: 'POST',
|
|
191
199
|
headers: { 'content-type': 'application/json' },
|
|
192
|
-
body: JSON.stringify({
|
|
200
|
+
body: JSON.stringify({
|
|
201
|
+
slideId,
|
|
202
|
+
prefs: readPrefs(localStorage),
|
|
203
|
+
...(choice ? { template: choice } : {}),
|
|
204
|
+
}),
|
|
193
205
|
});
|
|
194
206
|
if (!res.ok) throw new Error('build failed');
|
|
195
207
|
setDockOpen(true);
|
|
@@ -200,6 +212,14 @@ export function OutlineView() {
|
|
|
200
212
|
}
|
|
201
213
|
}
|
|
202
214
|
|
|
215
|
+
function startBuild() {
|
|
216
|
+
if (library?.available && library.templates.length > 0) {
|
|
217
|
+
setPicking(true);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
void build();
|
|
221
|
+
}
|
|
222
|
+
|
|
203
223
|
async function retry() {
|
|
204
224
|
if (!outline) return;
|
|
205
225
|
try {
|
|
@@ -243,6 +263,19 @@ export function OutlineView() {
|
|
|
243
263
|
(session) => session.slideId === slideId && session.status === 'running',
|
|
244
264
|
);
|
|
245
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
|
+
|
|
246
279
|
return (
|
|
247
280
|
<div data-lr-outline className="min-h-dvh bg-background text-foreground">
|
|
248
281
|
<div className="mx-auto w-full max-w-[820px] px-6 py-8">
|
|
@@ -344,7 +377,24 @@ export function OutlineView() {
|
|
|
344
377
|
{outline &&
|
|
345
378
|
outline.state !== 'drafting' &&
|
|
346
379
|
outline.state !== 'failed' &&
|
|
347
|
-
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 && (
|
|
348
398
|
<>
|
|
349
399
|
<ul className="mt-8 flex flex-col gap-2">
|
|
350
400
|
<DndContext
|
|
@@ -395,8 +445,8 @@ export function OutlineView() {
|
|
|
395
445
|
<div className="mt-6 flex justify-end">
|
|
396
446
|
<Button
|
|
397
447
|
type="button"
|
|
398
|
-
disabled={outline.state !== 'ready' || running || building}
|
|
399
|
-
onClick={
|
|
448
|
+
disabled={outline.state !== 'ready' || running || building || !library}
|
|
449
|
+
onClick={startBuild}
|
|
400
450
|
>
|
|
401
451
|
{lr.build}
|
|
402
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
|
+
}
|