@lemonriver/core 0.7.0 → 1.0.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/README.md +3 -1
- package/dist/{build-CKwrex8y.js → build-CiT4CNey.js} +1 -1
- package/dist/cli/bin.js +12 -5
- package/dist/client-DpO_eR9X.js +57 -0
- package/dist/{config-B1_gk0sy.js → config-BI3VRI2n.js} +7186 -5275
- package/dist/{dev-DZ2Yzl2p.js → dev-DpzBn_sf.js} +3 -3
- package/dist/index.js +1 -1
- package/dist/locale/index.js +1 -1
- package/dist/mcp-CjYDzcJa.js +262 -0
- package/dist/{preview-hMDcuHfP.js → preview-Dro8hl5_.js} +2 -2
- package/dist/{update-CMRxtTc9.js → update-b1dSg_FW.js} +17 -17
- package/dist/vite/index.js +1 -1
- package/dist/{zh-tw-DcrDeKxr.js → zh-tw-BhYyMx0-.js} +40 -40
- package/package.json +1 -1
- package/skills/slide-authoring/SKILL.md +2 -0
- package/src/app/lemonriver/agent-providers/section.tsx +13 -4
- package/src/app/lemonriver/backup/client.ts +177 -0
- package/src/app/lemonriver/backup/guide.test.ts +45 -0
- package/src/app/lemonriver/backup/guide.ts +138 -0
- package/src/app/lemonriver/backup/model.test.ts +96 -0
- package/src/app/lemonriver/backup/model.ts +255 -0
- package/src/app/lemonriver/backup/places.test.ts +154 -0
- package/src/app/lemonriver/backup/places.ts +74 -0
- package/src/app/lemonriver/board/blocks/snapshot.ts +10 -2
- package/src/app/lemonriver/board/self-check-runner.tsx +60 -15
- package/src/app/lemonriver/board/use-self-check.ts +1 -1
- package/src/app/lemonriver/chrome/app-chrome.tsx +6 -0
- package/src/app/lemonriver/chrome/sidebar-extras.tsx +9 -1
- package/src/app/lemonriver/features.test.ts +5 -0
- package/src/app/lemonriver/features.ts +11 -1
- package/src/app/lemonriver/guide/guide-prompt.tsx +89 -0
- package/src/app/lemonriver/guide/state.ts +29 -0
- package/src/app/lemonriver/guide/use-guide.ts +17 -0
- package/src/app/lemonriver/help/help-page.tsx +267 -0
- package/src/app/lemonriver/help/model.test.ts +179 -0
- package/src/app/lemonriver/help/model.ts +105 -0
- package/src/app/lemonriver/home/home-page.tsx +25 -7
- package/src/app/lemonriver/mcp/respond.ts +47 -0
- package/src/app/lemonriver/mcp/screenshot.tsx +155 -0
- package/src/app/lemonriver/mcp/self-check.tsx +65 -0
- package/src/app/lemonriver/outline/describe-page.tsx +3 -1
- package/src/app/lemonriver/routes.test.tsx +4 -2
- package/src/app/lemonriver/routes.tsx +2 -0
- package/src/app/lemonriver/settings/backup-restore-dialog.tsx +525 -0
- package/src/app/lemonriver/settings/backup-section.tsx +489 -0
- package/src/app/lemonriver/settings/settings-page.tsx +25 -3
- package/src/app/lemonriver/share/client.ts +6 -0
- package/src/app/lemonriver/share/freeze.ts +13 -5
- package/src/app/lemonriver/share/import-dialog.tsx +14 -0
- package/src/app/lemonriver/share/paths.test.ts +41 -0
- package/src/app/lemonriver/share/paths.ts +45 -11
- package/src/app/lemonriver/share/share-dialog.tsx +54 -1
- package/src/app/lemonriver/text/en.ts +742 -4
- package/src/app/lemonriver/text/es.ts +97 -4
- package/src/app/lemonriver/text/ja.ts +94 -4
- package/src/app/lemonriver/text/types.ts +103 -1
- package/src/app/lemonriver/text/zh-cn.ts +711 -3
- package/src/app/lemonriver/text/zh-tw.ts +711 -3
- package/src/app/lemonriver/update/beta-badge.tsx +3 -0
- package/src/app/lemonriver/update/version.test.ts +14 -0
- package/src/app/lemonriver/update/version.ts +5 -0
- package/src/locale/en.ts +8 -8
- package/src/locale/es.ts +10 -8
- package/src/locale/ja.ts +9 -8
- package/src/locale/zh-cn.ts +9 -8
- package/src/locale/zh-tw.ts +9 -8
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type { BackupPlaceKind } from '../backup/model';
|
|
2
|
+
|
|
3
|
+
export type HelpItem = { text: string; strong?: string; children?: string[] };
|
|
4
|
+
|
|
5
|
+
export type HelpBlock =
|
|
6
|
+
| { kind: 'p'; text: string; strong?: string }
|
|
7
|
+
| { kind: 'steps'; items: HelpItem[] }
|
|
8
|
+
| { kind: 'list'; items: HelpItem[] }
|
|
9
|
+
| { kind: 'note'; text: string; strong: string };
|
|
10
|
+
|
|
11
|
+
export type HelpSection = {
|
|
12
|
+
id: string;
|
|
13
|
+
title: string;
|
|
14
|
+
blocks: HelpBlock[];
|
|
15
|
+
/** The icon the backup location list uses for this drive. */
|
|
16
|
+
icon?: 'cloud' | 'folder' | 'drive';
|
|
17
|
+
/** Set on the cloud drive sections, so they hang under "cloud" in the index. */
|
|
18
|
+
parent?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type HelpButtonKey =
|
|
22
|
+
| 'settings'
|
|
23
|
+
| 'backupSection'
|
|
24
|
+
| 'share'
|
|
25
|
+
| 'generate'
|
|
26
|
+
| 'import'
|
|
27
|
+
| 'backupNow'
|
|
28
|
+
| 'autoBackup'
|
|
29
|
+
| 'keep'
|
|
30
|
+
| 'restore'
|
|
31
|
+
| 'restoreGo'
|
|
32
|
+
| 'chooseOtherFile'
|
|
33
|
+
| 'change'
|
|
34
|
+
| 'chooseOther'
|
|
35
|
+
| 'reveal'
|
|
36
|
+
| 'format'
|
|
37
|
+
| 'replaceImage'
|
|
38
|
+
| 'assets'
|
|
39
|
+
| 'board'
|
|
40
|
+
| 'notes'
|
|
41
|
+
| 'comments'
|
|
42
|
+
| 'selfCheck'
|
|
43
|
+
| 'present'
|
|
44
|
+
| 'duplicate';
|
|
45
|
+
|
|
46
|
+
export type HelpContent = {
|
|
47
|
+
title: string;
|
|
48
|
+
intro: string;
|
|
49
|
+
searchPlaceholder: string;
|
|
50
|
+
noResults: string;
|
|
51
|
+
buttons: Record<HelpButtonKey, string>;
|
|
52
|
+
sections: HelpSection[];
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
function itemText(item: HelpItem): string {
|
|
56
|
+
return [item.strong ?? '', item.text, ...(item.children ?? [])].join(' ');
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The text a search looks at: the title and everything under it. */
|
|
60
|
+
export function helpSectionText(section: HelpSection): string {
|
|
61
|
+
const parts = [section.title];
|
|
62
|
+
for (const block of section.blocks) {
|
|
63
|
+
if (block.kind === 'p' || block.kind === 'note') {
|
|
64
|
+
parts.push(block.strong ?? '', block.text);
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
for (const item of block.items) parts.push(itemText(item));
|
|
68
|
+
}
|
|
69
|
+
return parts.join(' ');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export function filterHelpSections(sections: HelpSection[], query: string): HelpSection[] {
|
|
73
|
+
const needle = query.trim().toLowerCase();
|
|
74
|
+
if (needle === '') return sections;
|
|
75
|
+
return sections.filter((section) => helpSectionText(section).toLowerCase().includes(needle));
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** `/help#cloud-<kind>` where the drive has its own section; the rest share one. */
|
|
79
|
+
export function helpAnchorForPlace(kind: BackupPlaceKind): string {
|
|
80
|
+
if (kind === 'local') return 'backup';
|
|
81
|
+
if (kind === 'google') return 'cloud-other';
|
|
82
|
+
return `cloud-${kind}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** `{name}` placeholders a help string fills from the button list. */
|
|
86
|
+
export function placeholdersIn(text: string): string[] {
|
|
87
|
+
return [...text.matchAll(/\{([a-zA-Z]+)\}/g)].map((match) => match[1] ?? '');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function helpStrings(content: HelpContent): string[] {
|
|
91
|
+
const out = [content.title, content.intro, content.searchPlaceholder, content.noResults];
|
|
92
|
+
for (const section of content.sections) {
|
|
93
|
+
out.push(section.title);
|
|
94
|
+
for (const block of section.blocks) {
|
|
95
|
+
if (block.kind === 'p') out.push(block.text, block.strong ?? '');
|
|
96
|
+
else if (block.kind === 'note') out.push(block.strong, block.text);
|
|
97
|
+
else {
|
|
98
|
+
for (const item of block.items) {
|
|
99
|
+
out.push(item.text, item.strong ?? '', ...(item.children ?? []));
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return out.filter((text) => text !== '');
|
|
105
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChevronDown, Plus } from 'lucide-react';
|
|
2
2
|
import { type ReactNode, useEffect, useMemo, useState } from 'react';
|
|
3
|
-
import { useNavigate, useOutletContext } from 'react-router-dom';
|
|
3
|
+
import { Link, useNavigate, useOutletContext } from 'react-router-dom';
|
|
4
4
|
import { toast } from 'sonner';
|
|
5
5
|
import { Button } from '@/components/ui/button';
|
|
6
6
|
import {
|
|
@@ -19,6 +19,8 @@ import type { HomeOutletContext } from '../../routes/home-shell';
|
|
|
19
19
|
import { FilterPill } from '../chrome/filter-pill';
|
|
20
20
|
import { isFeatureEnabled } from '../features';
|
|
21
21
|
import { LemonEmpty } from '../feedback/lemon-empty';
|
|
22
|
+
import { GuidePrompt } from '../guide/guide-prompt';
|
|
23
|
+
import { useGuideFlags } from '../guide/use-guide';
|
|
22
24
|
import { type InspectOk, inspectPackage } from '../share/client';
|
|
23
25
|
import { shareErrorText } from '../share/codes';
|
|
24
26
|
import { ImportDialog } from '../share/import-dialog';
|
|
@@ -67,6 +69,7 @@ export function LemonRiverHome() {
|
|
|
67
69
|
const times = useDeckTimes();
|
|
68
70
|
const library = useTemplateLibrary();
|
|
69
71
|
const editing = useEditingDecks();
|
|
72
|
+
const guide = useGuideFlags();
|
|
70
73
|
const [query, setQuery] = useState('');
|
|
71
74
|
const [occasion, setOccasion] = useState<string | null>(null);
|
|
72
75
|
const [sortKey, setSortKey] = useSortPref();
|
|
@@ -155,17 +158,20 @@ export function LemonRiverHome() {
|
|
|
155
158
|
return (
|
|
156
159
|
<div data-lr-home {...(shareOn ? dropHandlers : {})}>
|
|
157
160
|
{shareOn && dropHint}
|
|
161
|
+
{isFeatureEnabled('help') && <GuidePrompt />}
|
|
158
162
|
{import.meta.env.DEV && isAll && (
|
|
159
163
|
<>
|
|
160
164
|
<header className="mb-6">
|
|
161
165
|
<h1 className="font-heading text-[28px] font-bold leading-[34px] tracking-[-0.01em]">
|
|
162
166
|
{greeting}
|
|
163
167
|
</h1>
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
168
|
+
{guide?.guided === true && (
|
|
169
|
+
<p className="lr-on-lime mt-0.5 text-[14px] text-muted-foreground">
|
|
170
|
+
{lr.home.subtitle}
|
|
171
|
+
</p>
|
|
172
|
+
)}
|
|
167
173
|
</header>
|
|
168
|
-
<BriefCard />
|
|
174
|
+
{guide?.guided === true && <BriefCard />}
|
|
169
175
|
</>
|
|
170
176
|
)}
|
|
171
177
|
|
|
@@ -328,7 +334,8 @@ function NewDeckCard() {
|
|
|
328
334
|
const lr = useLrText();
|
|
329
335
|
const navigate = useNavigate();
|
|
330
336
|
const createDeck = useCreateDeck();
|
|
331
|
-
const
|
|
337
|
+
const guide = useGuideFlags();
|
|
338
|
+
const guided = guide?.guided === true && isFeatureEnabled('outline');
|
|
332
339
|
return (
|
|
333
340
|
<li>
|
|
334
341
|
<button
|
|
@@ -363,8 +370,10 @@ function GridSkeleton() {
|
|
|
363
370
|
|
|
364
371
|
function EmptyHome({ isDraft, folderName }: { isDraft: boolean; folderName?: string }) {
|
|
365
372
|
const t = useLocale();
|
|
373
|
+
const lr = useLrText();
|
|
366
374
|
const { enabled, provider } = useAgentStatus();
|
|
367
375
|
const createDeck = useCreateDeck();
|
|
376
|
+
const guide = useGuideFlags();
|
|
368
377
|
if (!isDraft) {
|
|
369
378
|
return (
|
|
370
379
|
<LemonEmpty title={t.home.folderEmptyTitle.replace('{name}', folderName ?? '')}>
|
|
@@ -372,11 +381,13 @@ function EmptyHome({ isDraft, folderName }: { isDraft: boolean; folderName?: str
|
|
|
372
381
|
</LemonEmpty>
|
|
373
382
|
);
|
|
374
383
|
}
|
|
384
|
+
const guided = guide?.guided === true;
|
|
375
385
|
return (
|
|
376
386
|
<LemonEmpty
|
|
377
387
|
title={t.home.noSlidesYet}
|
|
378
388
|
actions={
|
|
379
389
|
import.meta.env.DEV &&
|
|
390
|
+
guided &&
|
|
380
391
|
enabled && (
|
|
381
392
|
<Button onClick={() => void createDeck()}>
|
|
382
393
|
{provider
|
|
@@ -386,13 +397,20 @@ function EmptyHome({ isDraft, folderName }: { isDraft: boolean; folderName?: str
|
|
|
386
397
|
)
|
|
387
398
|
}
|
|
388
399
|
>
|
|
389
|
-
{!enabled && (
|
|
400
|
+
{(!enabled || !guided) && (
|
|
390
401
|
<>
|
|
391
402
|
{t.home.createSlideHintPrefix}
|
|
392
403
|
<code className="rounded-[4px] bg-muted px-1.5 py-0.5 font-mono text-[12.5px] text-foreground">
|
|
393
404
|
/create-slide
|
|
394
405
|
</code>
|
|
395
406
|
{t.home.createSlideHintSuffix}
|
|
407
|
+
<Link
|
|
408
|
+
to="/help#guide-agent"
|
|
409
|
+
data-lr-guide-start
|
|
410
|
+
className="mt-2 inline-block text-[13px] text-foreground underline underline-offset-2 outline-none hover:no-underline focus-visible:ring-2 focus-visible:ring-ring/40"
|
|
411
|
+
>
|
|
412
|
+
{lr.guide.startHint}
|
|
413
|
+
</Link>
|
|
396
414
|
</>
|
|
397
415
|
)}
|
|
398
416
|
</LemonEmpty>
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { screenshotPage } from './screenshot';
|
|
2
|
+
import { runSelfCheck } from './self-check';
|
|
3
|
+
|
|
4
|
+
export const MCP_REQUEST_EVENT = 'lemonriver:mcp-request';
|
|
5
|
+
|
|
6
|
+
type Request = { id: string; tool: string; args: Record<string, unknown> };
|
|
7
|
+
|
|
8
|
+
async function answer(request: Request): Promise<unknown> {
|
|
9
|
+
// A background tab stops painting, so the work below would never finish.
|
|
10
|
+
if (document.hidden) return { ok: false, hidden: true };
|
|
11
|
+
const args = request.args ?? {};
|
|
12
|
+
const slideId = typeof args.slideId === 'string' ? args.slideId : '';
|
|
13
|
+
try {
|
|
14
|
+
if (request.tool === 'screenshot') {
|
|
15
|
+
const page = typeof args.page === 'number' ? args.page : 0;
|
|
16
|
+
const step = typeof args.step === 'number' ? args.step : undefined;
|
|
17
|
+
return { ok: true, result: await screenshotPage(slideId, page, step) };
|
|
18
|
+
}
|
|
19
|
+
if (request.tool === 'self-check') {
|
|
20
|
+
return { ok: true, result: await runSelfCheck(slideId) };
|
|
21
|
+
}
|
|
22
|
+
return { ok: false, error: `unknown request: ${request.tool}` };
|
|
23
|
+
} catch (err) {
|
|
24
|
+
return { ok: false, error: (err as Error).message ?? String(err) };
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Answers the dev server's screenshot and self-check requests from whichever
|
|
30
|
+
* LemonRiver page is open. Every open page listens; the server keeps the first
|
|
31
|
+
* reply and drops the rest.
|
|
32
|
+
*/
|
|
33
|
+
export function installMcpResponder(): () => void {
|
|
34
|
+
const hot = import.meta.hot;
|
|
35
|
+
if (!hot) return () => {};
|
|
36
|
+
const onRequest = (data: Request) => {
|
|
37
|
+
void answer(data).then((reply) => {
|
|
38
|
+
void fetch(`/__lr/mcp/reply/${encodeURIComponent(data.id)}`, {
|
|
39
|
+
method: 'POST',
|
|
40
|
+
headers: { 'content-type': 'application/json' },
|
|
41
|
+
body: JSON.stringify(reply),
|
|
42
|
+
}).catch(() => {});
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
hot.on(MCP_REQUEST_EVENT, onRequest);
|
|
46
|
+
return () => hot.off(MCP_REQUEST_EVENT, onRequest);
|
|
47
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { flushSync } from 'react-dom';
|
|
3
|
+
import { createRoot, type Root } from 'react-dom/client';
|
|
4
|
+
import { PreviewStepHost } from '../../components/preview-step-host';
|
|
5
|
+
import { designToCssVars } from '../../lib/design';
|
|
6
|
+
import { nextPaint, sleep } from '../../lib/dom';
|
|
7
|
+
import { SlidePageProvider } from '../../lib/page-context';
|
|
8
|
+
import { isFrameAnimationSettled, waitForDataWaitfor, waitForFonts } from '../../lib/print-ready';
|
|
9
|
+
import { CANVAS_HEIGHT, CANVAS_WIDTH, type SlideModule } from '../../lib/sdk';
|
|
10
|
+
import { loadSlide } from '../../lib/slides';
|
|
11
|
+
import { toBase64 } from '../share/capture';
|
|
12
|
+
import { canvasJpeg, canvasScaled, freezeForCapture } from '../share/freeze';
|
|
13
|
+
|
|
14
|
+
const CAPTURE_CLASS = 'lr-mcp-capture';
|
|
15
|
+
const WIDTH = 1280;
|
|
16
|
+
const HEIGHT = 720;
|
|
17
|
+
const QUALITY = 0.85;
|
|
18
|
+
// Past this the encoded page is bigger than a reply should carry; a second,
|
|
19
|
+
// lower-quality pass keeps the screenshot instead of failing it.
|
|
20
|
+
const FALLBACK_QUALITY = 0.7;
|
|
21
|
+
const MAX_BASE64 = 2 * 1024 * 1024;
|
|
22
|
+
const ANIMATION_TIMEOUT_MS = 15_000;
|
|
23
|
+
const POLL_INTERVAL_MS = 100;
|
|
24
|
+
|
|
25
|
+
export type Screenshot = { image: string; mimeType: 'image/jpeg'; width: number; height: number };
|
|
26
|
+
|
|
27
|
+
// Same fast-forward trick the share capture uses: the rasterised clone must not
|
|
28
|
+
// replay an animation from its invisible first frame.
|
|
29
|
+
function captureStyleText(): string {
|
|
30
|
+
return `.${CAPTURE_CLASS} *, .${CAPTURE_CLASS} *::before, .${CAPTURE_CLASS} *::after {
|
|
31
|
+
animation-delay: -1s !important;
|
|
32
|
+
animation-duration: 1ms !important;
|
|
33
|
+
animation-iteration-count: 1 !important;
|
|
34
|
+
animation-fill-mode: forwards !important;
|
|
35
|
+
transition: none !important;
|
|
36
|
+
}`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
async function settle(frame: HTMLElement): Promise<void> {
|
|
40
|
+
await nextPaint();
|
|
41
|
+
await waitForFonts();
|
|
42
|
+
const deadline = performance.now() + ANIMATION_TIMEOUT_MS;
|
|
43
|
+
while (performance.now() < deadline) {
|
|
44
|
+
if (isFrameAnimationSettled(frame)) break;
|
|
45
|
+
await sleep(POLL_INTERVAL_MS);
|
|
46
|
+
}
|
|
47
|
+
await waitForDataWaitfor(frame);
|
|
48
|
+
await waitForFonts();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** One page, off screen, at 1920x1080, then down to the 1280x720 the tool returns. */
|
|
52
|
+
async function mountPage(
|
|
53
|
+
slide: SlideModule,
|
|
54
|
+
index: number,
|
|
55
|
+
step: number | undefined,
|
|
56
|
+
): Promise<{ frame: HTMLElement; dispose: () => void }> {
|
|
57
|
+
const pages = slide.default ?? [];
|
|
58
|
+
const Page = pages[index];
|
|
59
|
+
if (!Page) throw new Error(`this deck has no page ${index + 1}`);
|
|
60
|
+
|
|
61
|
+
const container = document.createElement('div');
|
|
62
|
+
container.className = CAPTURE_CLASS;
|
|
63
|
+
container.setAttribute('aria-hidden', 'true');
|
|
64
|
+
Object.assign(container.style, {
|
|
65
|
+
position: 'fixed',
|
|
66
|
+
left: '-99999px',
|
|
67
|
+
top: '0',
|
|
68
|
+
pointerEvents: 'none',
|
|
69
|
+
});
|
|
70
|
+
document.body.appendChild(container);
|
|
71
|
+
|
|
72
|
+
const style = document.createElement('style');
|
|
73
|
+
style.textContent = captureStyleText();
|
|
74
|
+
document.head.appendChild(style);
|
|
75
|
+
|
|
76
|
+
const frame = document.createElement('div');
|
|
77
|
+
frame.setAttribute('data-osd-canvas', '');
|
|
78
|
+
frame.style.width = `${CANVAS_WIDTH}px`;
|
|
79
|
+
frame.style.height = `${CANVAS_HEIGHT}px`;
|
|
80
|
+
frame.style.overflow = 'hidden';
|
|
81
|
+
const designVars = slide.design ? designToCssVars(slide.design) : null;
|
|
82
|
+
frame.style.background = designVars?.['--osd-bg'] ?? '#fff';
|
|
83
|
+
if (designVars) {
|
|
84
|
+
for (const [key, value] of Object.entries(designVars)) frame.style.setProperty(key, value);
|
|
85
|
+
}
|
|
86
|
+
container.appendChild(frame);
|
|
87
|
+
|
|
88
|
+
const root: Root = createRoot(frame);
|
|
89
|
+
const dispose = () => {
|
|
90
|
+
root.unmount();
|
|
91
|
+
container.remove();
|
|
92
|
+
style.remove();
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
const page = createElement(
|
|
96
|
+
SlidePageProvider,
|
|
97
|
+
{ index, total: pages.length },
|
|
98
|
+
createElement(Page),
|
|
99
|
+
);
|
|
100
|
+
try {
|
|
101
|
+
flushSync(() => {
|
|
102
|
+
root.render(
|
|
103
|
+
step === undefined ? page : <PreviewStepHost revealed={step}>{page}</PreviewStepHost>,
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
await settle(frame);
|
|
107
|
+
} catch (err) {
|
|
108
|
+
dispose();
|
|
109
|
+
throw err;
|
|
110
|
+
}
|
|
111
|
+
return { frame, dispose };
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export async function screenshotPage(
|
|
115
|
+
slideId: string,
|
|
116
|
+
page: number,
|
|
117
|
+
step: number | undefined,
|
|
118
|
+
): Promise<Screenshot> {
|
|
119
|
+
const slide = await loadSlide(slideId);
|
|
120
|
+
const total = slide.default?.length ?? 0;
|
|
121
|
+
if (total === 0) throw new Error('this deck has no pages');
|
|
122
|
+
if (page > total) {
|
|
123
|
+
throw new Error(
|
|
124
|
+
`this deck has ${total} page${total === 1 ? '' : 's'}, so page ${page} does not exist`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const mounted = await mountPage(slide, page - 1, step);
|
|
129
|
+
try {
|
|
130
|
+
freezeForCapture(mounted.frame);
|
|
131
|
+
const { toCanvas } = await import('html-to-image');
|
|
132
|
+
// html-to-image crops the page to width/height rather than scaling it, so
|
|
133
|
+
// the full canvas is captured and scaled down afterwards.
|
|
134
|
+
const full = await toCanvas(mounted.frame, {
|
|
135
|
+
width: CANVAS_WIDTH,
|
|
136
|
+
height: CANVAS_HEIGHT,
|
|
137
|
+
pixelRatio: 1,
|
|
138
|
+
backgroundColor: '#ffffff',
|
|
139
|
+
cacheBust: true,
|
|
140
|
+
});
|
|
141
|
+
const canvas = canvasScaled(full, WIDTH, HEIGHT);
|
|
142
|
+
let image = toBase64(await canvasJpeg(canvas, QUALITY));
|
|
143
|
+
if (image.length > MAX_BASE64) {
|
|
144
|
+
image = toBase64(await canvasJpeg(canvas, FALLBACK_QUALITY));
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
image,
|
|
148
|
+
mimeType: 'image/jpeg',
|
|
149
|
+
width: WIDTH,
|
|
150
|
+
height: HEIGHT,
|
|
151
|
+
};
|
|
152
|
+
} finally {
|
|
153
|
+
mounted.dispose();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { createElement } from 'react';
|
|
2
|
+
import { flushSync } from 'react-dom';
|
|
3
|
+
import { createRoot } from 'react-dom/client';
|
|
4
|
+
import { loadSlide } from '../../lib/slides';
|
|
5
|
+
import type { CheckResult } from '../board/model/self-check';
|
|
6
|
+
import { SelfCheckRunner } from '../board/self-check-runner';
|
|
7
|
+
import { templateFloor } from '../board/use-self-check';
|
|
8
|
+
|
|
9
|
+
export type SelfCheckSummary = {
|
|
10
|
+
findings: { page: number; kind: string; detail: string }[];
|
|
11
|
+
unread: number[];
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The board's own check, run on a hidden copy of the deck. The record is written
|
|
16
|
+
* back the same way the Self-check button writes it, so the board shows this run
|
|
17
|
+
* next time it is opened.
|
|
18
|
+
*/
|
|
19
|
+
export async function runSelfCheck(slideId: string): Promise<SelfCheckSummary> {
|
|
20
|
+
const deck = await loadSlide(slideId);
|
|
21
|
+
if (!deck.default || deck.default.length === 0) throw new Error('this deck has no pages');
|
|
22
|
+
const minType = await templateFloor(slideId);
|
|
23
|
+
|
|
24
|
+
const host = document.createElement('div');
|
|
25
|
+
host.setAttribute('aria-hidden', 'true');
|
|
26
|
+
document.body.appendChild(host);
|
|
27
|
+
const root = createRoot(host);
|
|
28
|
+
|
|
29
|
+
try {
|
|
30
|
+
const result = await new Promise<CheckResult>((resolve) => {
|
|
31
|
+
flushSync(() => {
|
|
32
|
+
root.render(
|
|
33
|
+
createElement(SelfCheckRunner, {
|
|
34
|
+
input: {
|
|
35
|
+
pages: deck.default,
|
|
36
|
+
design: deck.design,
|
|
37
|
+
notes: deck.notes,
|
|
38
|
+
minType,
|
|
39
|
+
},
|
|
40
|
+
onDone: resolve,
|
|
41
|
+
}),
|
|
42
|
+
);
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const selfCheck = { at: Date.now(), findings: result.findings, unread: result.unread };
|
|
47
|
+
await fetch('/__board/self-check', {
|
|
48
|
+
method: 'PUT',
|
|
49
|
+
headers: { 'content-type': 'application/json' },
|
|
50
|
+
body: JSON.stringify({ slideId, selfCheck }),
|
|
51
|
+
}).catch(() => {});
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
findings: result.findings.map((finding) => ({
|
|
55
|
+
page: finding.page,
|
|
56
|
+
kind: finding.kind,
|
|
57
|
+
detail: finding.detail,
|
|
58
|
+
})),
|
|
59
|
+
unread: result.unread,
|
|
60
|
+
};
|
|
61
|
+
} finally {
|
|
62
|
+
root.unmount();
|
|
63
|
+
host.remove();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -16,6 +16,7 @@ import { cn } from '@/lib/utils';
|
|
|
16
16
|
import { readPrefs } from '../agent-prefs/prefs';
|
|
17
17
|
import { useAgentPrefs } from '../agent-prefs/use-prefs';
|
|
18
18
|
import { Mascot } from '../brand/mascot';
|
|
19
|
+
import { useGuideFlags } from '../guide/use-guide';
|
|
19
20
|
import { Onboarding } from '../onboarding/onboarding';
|
|
20
21
|
import { OCCASIONS, type OccasionId } from '../templates/model';
|
|
21
22
|
import { useTemplateLibrary } from '../templates/use-library';
|
|
@@ -38,6 +39,7 @@ function fileKey(file: File): string {
|
|
|
38
39
|
export function DescribePage() {
|
|
39
40
|
const lr = useLrText();
|
|
40
41
|
const locale = useLocale();
|
|
42
|
+
const guide = useGuideFlags();
|
|
41
43
|
const location = useLocation();
|
|
42
44
|
const prefs = useAgentPrefs();
|
|
43
45
|
const { connected, loading, provider } = useAgentStatus();
|
|
@@ -410,7 +412,7 @@ export function DescribePage() {
|
|
|
410
412
|
</p>
|
|
411
413
|
)}
|
|
412
414
|
|
|
413
|
-
<Onboarding />
|
|
415
|
+
{guide?.guided === true && <Onboarding />}
|
|
414
416
|
</div>
|
|
415
417
|
);
|
|
416
418
|
}
|
|
@@ -4,6 +4,7 @@ import { describe, expect, it, vi } from 'vitest';
|
|
|
4
4
|
vi.mock('./features', () => ({ isFeatureEnabled: vi.fn(() => true) }));
|
|
5
5
|
vi.mock('./chrome/not-found', () => ({ NotFound: () => null }));
|
|
6
6
|
vi.mock('./home/home-page', () => ({ LemonRiverHome: () => null }));
|
|
7
|
+
vi.mock('./help/help-page', () => ({ HelpPage: () => null }));
|
|
7
8
|
vi.mock('./settings/settings-page', () => ({ SettingsPage: () => null }));
|
|
8
9
|
vi.mock('./trash/trash-page', () => ({ TrashPage: () => null }));
|
|
9
10
|
|
|
@@ -31,11 +32,12 @@ describe('lemonRiverRoutes', () => {
|
|
|
31
32
|
});
|
|
32
33
|
|
|
33
34
|
describe('lemonRiverShellRoutes', () => {
|
|
34
|
-
it('puts our home and the guided flow first, then settings, templates and trash', () => {
|
|
35
|
+
it('puts our home and the guided flow first, then settings, help, templates and trash', () => {
|
|
35
36
|
expect(paths(lemonRiverShellRoutes())).toEqual([
|
|
36
37
|
'/',
|
|
37
38
|
'/new',
|
|
38
39
|
'/settings',
|
|
40
|
+
'/help',
|
|
39
41
|
'/templates',
|
|
40
42
|
'/trash',
|
|
41
43
|
]);
|
|
@@ -43,7 +45,7 @@ describe('lemonRiverShellRoutes', () => {
|
|
|
43
45
|
|
|
44
46
|
it('leaves out the pages whose feature is off', () => {
|
|
45
47
|
vi.mocked(isFeatureEnabled).mockImplementation((id) => id !== 'trash' && id !== 'templates');
|
|
46
|
-
expect(paths(lemonRiverShellRoutes())).toEqual(['/', '/new', '/settings']);
|
|
48
|
+
expect(paths(lemonRiverShellRoutes())).toEqual(['/', '/new', '/settings', '/help']);
|
|
47
49
|
vi.mocked(isFeatureEnabled).mockReturnValue(true);
|
|
48
50
|
});
|
|
49
51
|
});
|
|
@@ -2,6 +2,7 @@ import { lazy, Suspense } from 'react';
|
|
|
2
2
|
import { Route } from 'react-router-dom';
|
|
3
3
|
import { NotFound } from './chrome/not-found';
|
|
4
4
|
import { isFeatureEnabled } from './features';
|
|
5
|
+
import { HelpPage } from './help/help-page';
|
|
5
6
|
import { LemonRiverHome } from './home/home-page';
|
|
6
7
|
import { SettingsPage } from './settings/settings-page';
|
|
7
8
|
import { TrashPage } from './trash/trash-page';
|
|
@@ -78,6 +79,7 @@ export function lemonRiverShellRoutes() {
|
|
|
78
79
|
isFeatureEnabled('settings') && (
|
|
79
80
|
<Route key="settings" path="/settings" element={<SettingsPage />} />
|
|
80
81
|
),
|
|
82
|
+
isFeatureEnabled('help') && <Route key="help" path="/help" element={<HelpPage />} />,
|
|
81
83
|
isFeatureEnabled('templates') && (
|
|
82
84
|
<Route
|
|
83
85
|
key="templates"
|