@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
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { ScanSearch } from 'lucide-react';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { useNavigate, useSearchParams } from 'react-router-dom';
|
|
4
|
+
import { Button } from '@/components/ui/button';
|
|
5
|
+
import { format } from '@/lib/use-locale';
|
|
6
|
+
import { cn } from '@/lib/utils';
|
|
7
|
+
import { useLrText } from '../text';
|
|
8
|
+
import type { LrText } from '../text/types';
|
|
9
|
+
import { CANVAS, type Finding, hintsOf, problemsOf, type SelfCheck } from './model/self-check';
|
|
10
|
+
import { dropHighlight, requestHighlight, takeHighlight } from './self-check-jump';
|
|
11
|
+
|
|
12
|
+
/** The card badge reads what the board last published, without prop drilling. */
|
|
13
|
+
let published: { slideId: string; findings: Finding[]; unread: number[] } = {
|
|
14
|
+
slideId: '',
|
|
15
|
+
findings: [],
|
|
16
|
+
unread: [],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export function publishFindings(slideId: string, findings: Finding[], unread: number[]): void {
|
|
20
|
+
published = { slideId, findings, unread };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function findingsForPage(index: number): Finding[] {
|
|
24
|
+
return problemsOf(published.findings).filter((finding) => finding.page === index + 1);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function isPageUnread(index: number): boolean {
|
|
28
|
+
return published.unread.includes(index + 1);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The one sentence both the panel and the button show when pages were unread. */
|
|
32
|
+
export function unreadLabel(board: LrText['board'], unread: readonly number[]): string {
|
|
33
|
+
return unread.length > 5
|
|
34
|
+
? format(board.selfCheckUnreadMany, { n: unread.length })
|
|
35
|
+
: format(board.selfCheckUnread, { pages: unread.join(', ') });
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function findingText(board: LrText['board'], finding: Finding): string {
|
|
39
|
+
switch (finding.kind) {
|
|
40
|
+
case 'tiny':
|
|
41
|
+
return format(board.findingTiny, { size: finding.size ?? 0 });
|
|
42
|
+
case 'small-body':
|
|
43
|
+
return board.findingSmallBody;
|
|
44
|
+
case 'overflow':
|
|
45
|
+
return board.findingOverflow;
|
|
46
|
+
case 'overlap':
|
|
47
|
+
return board.findingOverlap;
|
|
48
|
+
case 'no-notes':
|
|
49
|
+
return board.findingNoNotes;
|
|
50
|
+
case 'long-title':
|
|
51
|
+
return format(board.findingLongTitle, { n: finding.measure ?? 0 });
|
|
52
|
+
default:
|
|
53
|
+
return format(board.findingAccent, { n: finding.measure ?? 0 });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The board's own button: runs the check again and shows how many it found. */
|
|
58
|
+
export function SelfCheckButton({
|
|
59
|
+
record,
|
|
60
|
+
running,
|
|
61
|
+
onRun,
|
|
62
|
+
}: {
|
|
63
|
+
record: SelfCheck | null | undefined;
|
|
64
|
+
running: boolean;
|
|
65
|
+
onRun: () => void;
|
|
66
|
+
}) {
|
|
67
|
+
const lr = useLrText();
|
|
68
|
+
const count = problemsOf(record?.findings ?? []).length;
|
|
69
|
+
const unread = record?.unread ?? [];
|
|
70
|
+
return (
|
|
71
|
+
<button
|
|
72
|
+
type="button"
|
|
73
|
+
data-lr-self-check-button
|
|
74
|
+
disabled={running}
|
|
75
|
+
onClick={onRun}
|
|
76
|
+
className={cn(
|
|
77
|
+
'inline-flex h-8 items-center gap-1.5 rounded-[8px] border border-border bg-card px-2.5 text-[12.5px] font-medium text-muted-foreground outline-none',
|
|
78
|
+
'hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40 disabled:opacity-50',
|
|
79
|
+
)}
|
|
80
|
+
>
|
|
81
|
+
<ScanSearch className="size-[15px]" aria-hidden />
|
|
82
|
+
{lr.board.selfCheck}
|
|
83
|
+
{record &&
|
|
84
|
+
(unread.length > 0 ? (
|
|
85
|
+
<span
|
|
86
|
+
data-lr-self-check-unread={unread.length}
|
|
87
|
+
title={unreadLabel(lr.board, unread)}
|
|
88
|
+
className="font-semibold text-foreground tabular-nums"
|
|
89
|
+
>
|
|
90
|
+
{format(lr.board.selfCheckUnreadBadge, { n: unread.length })}
|
|
91
|
+
</span>
|
|
92
|
+
) : (
|
|
93
|
+
<span
|
|
94
|
+
data-lr-self-check-count
|
|
95
|
+
className={cn('tabular-nums', count > 0 && 'font-semibold text-foreground')}
|
|
96
|
+
>
|
|
97
|
+
{count}
|
|
98
|
+
</span>
|
|
99
|
+
))}
|
|
100
|
+
</button>
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export function SelfCheckFindings({
|
|
105
|
+
record,
|
|
106
|
+
running,
|
|
107
|
+
onFix,
|
|
108
|
+
fixing,
|
|
109
|
+
onJump,
|
|
110
|
+
onRun,
|
|
111
|
+
}: {
|
|
112
|
+
record: SelfCheck | null | undefined;
|
|
113
|
+
running: boolean;
|
|
114
|
+
onFix: () => void;
|
|
115
|
+
fixing: boolean;
|
|
116
|
+
onJump: (finding: Finding) => void;
|
|
117
|
+
onRun: () => void;
|
|
118
|
+
}) {
|
|
119
|
+
const lr = useLrText().board;
|
|
120
|
+
if (record === undefined) return null;
|
|
121
|
+
const findings = record?.findings ?? [];
|
|
122
|
+
const problems = problemsOf(findings);
|
|
123
|
+
const hints = hintsOf(findings);
|
|
124
|
+
const unread = record?.unread ?? [];
|
|
125
|
+
|
|
126
|
+
return (
|
|
127
|
+
<section data-lr-self-check className="mt-3 rounded-[12px] border border-border bg-card p-3">
|
|
128
|
+
<div className="flex items-center justify-between gap-2">
|
|
129
|
+
<p data-lr-self-check-summary className="text-[12.5px] font-semibold">
|
|
130
|
+
{running
|
|
131
|
+
? lr.selfCheck
|
|
132
|
+
: unread.length > 0
|
|
133
|
+
? unreadLabel(lr, unread)
|
|
134
|
+
: problems.length === 0
|
|
135
|
+
? lr.selfCheckPassed
|
|
136
|
+
: format(lr.selfCheckFindings, { n: problems.length })}
|
|
137
|
+
</p>
|
|
138
|
+
<span className="flex shrink-0 items-center gap-1.5">
|
|
139
|
+
{unread.length > 0 && (
|
|
140
|
+
<Button type="button" size="xs" variant="outline" disabled={running} onClick={onRun}>
|
|
141
|
+
{lr.selfCheckAgain}
|
|
142
|
+
</Button>
|
|
143
|
+
)}
|
|
144
|
+
{problems.length > 0 && (
|
|
145
|
+
<Button
|
|
146
|
+
type="button"
|
|
147
|
+
size="xs"
|
|
148
|
+
variant="outline"
|
|
149
|
+
disabled={fixing || running}
|
|
150
|
+
onClick={onFix}
|
|
151
|
+
>
|
|
152
|
+
{lr.selfCheckFix}
|
|
153
|
+
</Button>
|
|
154
|
+
)}
|
|
155
|
+
</span>
|
|
156
|
+
</div>
|
|
157
|
+
{problems.length > 0 && (
|
|
158
|
+
<ul data-lr-self-check-problems className="mt-2 space-y-1">
|
|
159
|
+
{problems.map((finding) => (
|
|
160
|
+
<FindingRow key={`${finding.page}-${finding.kind}`} finding={finding} onJump={onJump} />
|
|
161
|
+
))}
|
|
162
|
+
</ul>
|
|
163
|
+
)}
|
|
164
|
+
{hints.length > 0 && (
|
|
165
|
+
<details data-lr-self-check-hints className="mt-2">
|
|
166
|
+
<summary className="cursor-pointer text-[12px] font-medium text-muted-foreground">
|
|
167
|
+
{lr.selfCheckHints}
|
|
168
|
+
</summary>
|
|
169
|
+
<ul className="mt-1 space-y-1">
|
|
170
|
+
{hints.map((finding) => (
|
|
171
|
+
<FindingRow
|
|
172
|
+
key={`${finding.page}-${finding.kind}`}
|
|
173
|
+
finding={finding}
|
|
174
|
+
onJump={onJump}
|
|
175
|
+
/>
|
|
176
|
+
))}
|
|
177
|
+
</ul>
|
|
178
|
+
</details>
|
|
179
|
+
)}
|
|
180
|
+
</section>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function FindingRow({ finding, onJump }: { finding: Finding; onJump: (finding: Finding) => void }) {
|
|
185
|
+
const lr = useLrText().board;
|
|
186
|
+
return (
|
|
187
|
+
<li>
|
|
188
|
+
<button
|
|
189
|
+
type="button"
|
|
190
|
+
data-lr-self-check-row={finding.page}
|
|
191
|
+
onClick={() => onJump(finding)}
|
|
192
|
+
className="w-full rounded-[6px] px-1.5 py-1 text-left text-[12px] leading-snug text-muted-foreground outline-none hover:bg-muted/60 hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40"
|
|
193
|
+
>
|
|
194
|
+
<span className="font-medium">{format(lr.selfCheckPage, { n: finding.page })}</span>
|
|
195
|
+
{' · '}
|
|
196
|
+
{finding.count > 1 && `${format(lr.selfCheckTimes, { n: finding.count })} · `}
|
|
197
|
+
{findingText(lr, finding)}
|
|
198
|
+
</button>
|
|
199
|
+
</li>
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** Draws the box of the finding the list jumped to, then fades out. */
|
|
204
|
+
export function SelfCheckHighlight() {
|
|
205
|
+
const [params] = useSearchParams();
|
|
206
|
+
const page = Number(params.get('p') ?? 1);
|
|
207
|
+
const [boxes, setBoxes] = useState<
|
|
208
|
+
{
|
|
209
|
+
left: number;
|
|
210
|
+
top: number;
|
|
211
|
+
width: number;
|
|
212
|
+
height: number;
|
|
213
|
+
}[]
|
|
214
|
+
>([]);
|
|
215
|
+
|
|
216
|
+
useEffect(() => {
|
|
217
|
+
const request = takeHighlight(page);
|
|
218
|
+
if (!request?.boxes || request.boxes.length === 0) return;
|
|
219
|
+
const targets = request.boxes;
|
|
220
|
+
let retry = 0;
|
|
221
|
+
const draw = (): boolean => {
|
|
222
|
+
const host = document.querySelector('main[data-inspector-root]');
|
|
223
|
+
const canvas = host?.querySelector<HTMLElement>('[data-osd-canvas]');
|
|
224
|
+
if (!canvas) return false;
|
|
225
|
+
const rect = canvas.getBoundingClientRect();
|
|
226
|
+
if (rect.width === 0) return false;
|
|
227
|
+
const scale = rect.width / CANVAS.width;
|
|
228
|
+
setBoxes(
|
|
229
|
+
targets.map((target) => ({
|
|
230
|
+
left: rect.left + target.x * scale,
|
|
231
|
+
top: rect.top + target.y * scale,
|
|
232
|
+
width: target.w * scale,
|
|
233
|
+
height: target.h * scale,
|
|
234
|
+
})),
|
|
235
|
+
);
|
|
236
|
+
return true;
|
|
237
|
+
};
|
|
238
|
+
if (!draw()) retry = window.setTimeout(() => void draw(), 240);
|
|
239
|
+
const clear = window.setTimeout(() => {
|
|
240
|
+
setBoxes([]);
|
|
241
|
+
dropHighlight();
|
|
242
|
+
}, 2000);
|
|
243
|
+
return () => {
|
|
244
|
+
window.clearTimeout(retry);
|
|
245
|
+
window.clearTimeout(clear);
|
|
246
|
+
};
|
|
247
|
+
}, [page]);
|
|
248
|
+
|
|
249
|
+
if (boxes.length === 0) return null;
|
|
250
|
+
return (
|
|
251
|
+
<>
|
|
252
|
+
{boxes.map((box) => (
|
|
253
|
+
<div
|
|
254
|
+
key={`${box.left}-${box.top}-${box.width}-${box.height}`}
|
|
255
|
+
data-lr-self-check-highlight
|
|
256
|
+
aria-hidden
|
|
257
|
+
className="pointer-events-none fixed z-50 rounded-[4px] bg-[var(--lr-focus)]/10 ring-2 ring-[var(--lr-focus)]"
|
|
258
|
+
style={box}
|
|
259
|
+
/>
|
|
260
|
+
))}
|
|
261
|
+
</>
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
/** The list's rows send the editor to that page; the box follows in the editor. */
|
|
266
|
+
export function useJumpToFinding(slideId: string) {
|
|
267
|
+
const navigate = useNavigate();
|
|
268
|
+
return (finding: Finding) => {
|
|
269
|
+
requestHighlight({ page: finding.page, boxes: finding.boxes });
|
|
270
|
+
navigate(`/s/${encodeURIComponent(slideId)}?p=${finding.page}`);
|
|
271
|
+
};
|
|
272
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { Component, type ReactNode, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { SlideCanvas } from '../../components/slide-canvas';
|
|
3
|
+
import type { DesignSystem } from '../../lib/design';
|
|
4
|
+
import { SlidePageProvider } from '../../lib/page-context';
|
|
5
|
+
import type { Page } from '../../lib/sdk';
|
|
6
|
+
import type { SnapNode } from './blocks/classify';
|
|
7
|
+
import { snapshotPage } from './blocks/snapshot';
|
|
8
|
+
import { CARD_H, CARD_W } from './layout';
|
|
9
|
+
import { type CheckedPage, type CheckResult, checkDeck } from './model/self-check';
|
|
10
|
+
|
|
11
|
+
/** Pages drawn off screen at a time; the next batch follows the one before it. */
|
|
12
|
+
const PER_PASS = 6;
|
|
13
|
+
const SCALE = 0.25;
|
|
14
|
+
/** A page that has not painted by then is reported as unread, never as clean. */
|
|
15
|
+
export const READY_TIMEOUT_MS = 5000;
|
|
16
|
+
|
|
17
|
+
export type SelfCheckInput = {
|
|
18
|
+
pages: Page[];
|
|
19
|
+
design?: DesignSystem;
|
|
20
|
+
notes?: (string | undefined)[];
|
|
21
|
+
titles?: string[];
|
|
22
|
+
minType?: number;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const wait = (ms: number) => new Promise((resolve) => window.setTimeout(resolve, ms));
|
|
26
|
+
|
|
27
|
+
const frames = (count: number) =>
|
|
28
|
+
new Promise<void>((resolve) => {
|
|
29
|
+
const step = (left: number) => {
|
|
30
|
+
if (left <= 0) resolve();
|
|
31
|
+
else window.requestAnimationFrame(() => step(left - 1));
|
|
32
|
+
};
|
|
33
|
+
step(count);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** A page that throws while drawn is a page this check could not read. */
|
|
37
|
+
class PageBoundary extends Component<{ children: ReactNode }, { failed: boolean }> {
|
|
38
|
+
state = { failed: false };
|
|
39
|
+
|
|
40
|
+
static getDerivedStateFromError(): { failed: boolean } {
|
|
41
|
+
return { failed: true };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
render() {
|
|
45
|
+
return this.state.failed ? null : this.props.children;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Draws every page off screen, waits for each to paint, copies its DOM and runs
|
|
51
|
+
* the rules. Nothing here is shown: the deck is already on screen elsewhere,
|
|
52
|
+
* and the check needs the pages laid out, not visible.
|
|
53
|
+
*/
|
|
54
|
+
export function SelfCheckRunner({
|
|
55
|
+
input,
|
|
56
|
+
onDone,
|
|
57
|
+
}: {
|
|
58
|
+
input: SelfCheckInput;
|
|
59
|
+
onDone: (result: CheckResult) => void;
|
|
60
|
+
}) {
|
|
61
|
+
const host = useRef<HTMLDivElement | null>(null);
|
|
62
|
+
const [pass, setPass] = useState(0);
|
|
63
|
+
const collected = useRef<CheckedPage[]>([]);
|
|
64
|
+
const done = useRef(onDone);
|
|
65
|
+
done.current = onDone;
|
|
66
|
+
|
|
67
|
+
const start = pass * PER_PASS;
|
|
68
|
+
const total = input.pages.length;
|
|
69
|
+
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
if (start >= total) {
|
|
72
|
+
done.current(
|
|
73
|
+
checkDeck(collected.current, {
|
|
74
|
+
accent: input.design?.palette.accent,
|
|
75
|
+
minType: input.minType,
|
|
76
|
+
}),
|
|
77
|
+
);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
let cancelled = false;
|
|
81
|
+
|
|
82
|
+
const readTree = (index: number): SnapNode | null => {
|
|
83
|
+
const box = host.current?.querySelector<HTMLElement>(`[data-lr-self-check-page="${index}"]`);
|
|
84
|
+
const canvas = box?.querySelector<HTMLElement>('[data-osd-canvas]');
|
|
85
|
+
if (!canvas) return null;
|
|
86
|
+
try {
|
|
87
|
+
return snapshotPage(canvas, SCALE);
|
|
88
|
+
} catch {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const run = async () => {
|
|
94
|
+
await Promise.race([document.fonts.ready, wait(READY_TIMEOUT_MS)]);
|
|
95
|
+
await frames(2);
|
|
96
|
+
if (cancelled) return;
|
|
97
|
+
const trees = new Map<number, SnapNode | null>();
|
|
98
|
+
for (let index = start; index < Math.min(start + PER_PASS, total); index += 1) {
|
|
99
|
+
trees.set(index, readTree(index));
|
|
100
|
+
}
|
|
101
|
+
const deadline = Date.now() + READY_TIMEOUT_MS;
|
|
102
|
+
while ([...trees.values()].some((tree) => tree === null) && Date.now() < deadline) {
|
|
103
|
+
await frames(1);
|
|
104
|
+
if (cancelled) return;
|
|
105
|
+
for (const [index, tree] of trees) {
|
|
106
|
+
if (!tree) trees.set(index, readTree(index));
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
for (let index = start; index < Math.min(start + PER_PASS, total); index += 1) {
|
|
110
|
+
collected.current.push({
|
|
111
|
+
n: index + 1,
|
|
112
|
+
tree: trees.get(index) ?? null,
|
|
113
|
+
notes: input.notes?.[index] ?? '',
|
|
114
|
+
title: input.titles?.[index] ?? '',
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
setPass((value) => value + 1);
|
|
118
|
+
};
|
|
119
|
+
void run();
|
|
120
|
+
|
|
121
|
+
return () => {
|
|
122
|
+
cancelled = true;
|
|
123
|
+
};
|
|
124
|
+
}, [start, total, input.design?.palette.accent, input.notes, input.titles, input.minType]);
|
|
125
|
+
|
|
126
|
+
if (start >= total) return null;
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<div ref={host} aria-hidden className="pointer-events-none fixed top-0 left-[-20000px]">
|
|
130
|
+
{input.pages.slice(start, start + PER_PASS).map((PageComp, offset) => {
|
|
131
|
+
const index = start + offset;
|
|
132
|
+
return (
|
|
133
|
+
<div
|
|
134
|
+
key={index}
|
|
135
|
+
data-lr-self-check-page={index}
|
|
136
|
+
style={{ width: CARD_W, height: CARD_H }}
|
|
137
|
+
>
|
|
138
|
+
<PageBoundary>
|
|
139
|
+
<SlideCanvas scale={SCALE} center={false} flat freezeMotion design={input.design}>
|
|
140
|
+
<SlidePageProvider index={index} total={total}>
|
|
141
|
+
<PageComp />
|
|
142
|
+
</SlidePageProvider>
|
|
143
|
+
</SlideCanvas>
|
|
144
|
+
</PageBoundary>
|
|
145
|
+
</div>
|
|
146
|
+
);
|
|
147
|
+
})}
|
|
148
|
+
</div>
|
|
149
|
+
);
|
|
150
|
+
}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import type { SlideModule } from '../../lib/sdk';
|
|
3
|
+
import { loadSlide } from '../../lib/slides';
|
|
4
|
+
import { templates } from '../templates/client';
|
|
5
|
+
import type { CheckResult, SelfCheck } from './model/self-check';
|
|
6
|
+
import type { SelfCheckInput } from './self-check-runner';
|
|
7
|
+
|
|
8
|
+
/** The floor for small type the deck's template asks for, if it has one. */
|
|
9
|
+
async function templateFloor(slideId: string): Promise<number | undefined> {
|
|
10
|
+
const id = (await outlineTemplate(slideId)) ?? (await appliedTemplate(slideId));
|
|
11
|
+
if (!id) return undefined;
|
|
12
|
+
return templates.find((template) => template.id === id)?.minType;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** The template the outline was written for, when there is one. */
|
|
16
|
+
async function outlineTemplate(slideId: string): Promise<string | undefined> {
|
|
17
|
+
try {
|
|
18
|
+
const res = await fetch(`/__lr/outline?slideId=${encodeURIComponent(slideId)}`);
|
|
19
|
+
if (!res.ok) return undefined;
|
|
20
|
+
const body = (await res.json()) as { outline?: { templateId?: unknown } | null };
|
|
21
|
+
const id = body.outline?.templateId;
|
|
22
|
+
return typeof id === 'string' ? id : undefined;
|
|
23
|
+
} catch {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** A template applied straight from the library records itself on the board, not the outline. */
|
|
29
|
+
async function appliedTemplate(slideId: string): Promise<string | undefined> {
|
|
30
|
+
try {
|
|
31
|
+
const res = await fetch(`/__board/?slideId=${encodeURIComponent(slideId)}`);
|
|
32
|
+
if (!res.ok) return undefined;
|
|
33
|
+
const body = (await res.json()) as { template?: { id?: unknown } | null };
|
|
34
|
+
const id = body.template?.id;
|
|
35
|
+
return typeof id === 'string' ? id : undefined;
|
|
36
|
+
} catch {
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The stored result and the one way to run the check again. The pages are
|
|
43
|
+
* loaded only while a check runs: the board and the team panel both keep this
|
|
44
|
+
* hook for the record, and only one of them draws the pages.
|
|
45
|
+
*/
|
|
46
|
+
export function useSelfCheck(slideId: string, titles?: string[]) {
|
|
47
|
+
const [record, setRecord] = useState<SelfCheck | null | undefined>(undefined);
|
|
48
|
+
const [running, setRunning] = useState(false);
|
|
49
|
+
const [deck, setDeck] = useState<SlideModule | null>(null);
|
|
50
|
+
const [minType, setMinType] = useState<number | undefined>(undefined);
|
|
51
|
+
const starting = useRef(false);
|
|
52
|
+
|
|
53
|
+
const refresh = useCallback(async () => {
|
|
54
|
+
try {
|
|
55
|
+
const res = await fetch(`/__board/self-check?slideId=${encodeURIComponent(slideId)}`);
|
|
56
|
+
if (!res.ok) return;
|
|
57
|
+
const body = (await res.json()) as { selfCheck: SelfCheck | null };
|
|
58
|
+
setRecord(body.selfCheck);
|
|
59
|
+
} catch {}
|
|
60
|
+
}, [slideId]);
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
void refresh();
|
|
64
|
+
}, [refresh]);
|
|
65
|
+
|
|
66
|
+
const run = useCallback(async () => {
|
|
67
|
+
if (starting.current || running) return;
|
|
68
|
+
starting.current = true;
|
|
69
|
+
try {
|
|
70
|
+
const module = await loadSlide(slideId);
|
|
71
|
+
const floor = await templateFloor(slideId);
|
|
72
|
+
setMinType(floor);
|
|
73
|
+
setDeck(module);
|
|
74
|
+
setRunning(true);
|
|
75
|
+
} catch {
|
|
76
|
+
starting.current = false;
|
|
77
|
+
}
|
|
78
|
+
}, [slideId, running]);
|
|
79
|
+
|
|
80
|
+
const finish = useCallback(
|
|
81
|
+
async (result: CheckResult) => {
|
|
82
|
+
const selfCheck: SelfCheck = {
|
|
83
|
+
at: Date.now(),
|
|
84
|
+
findings: result.findings,
|
|
85
|
+
unread: result.unread,
|
|
86
|
+
};
|
|
87
|
+
setRecord(selfCheck);
|
|
88
|
+
setRunning(false);
|
|
89
|
+
setDeck(null);
|
|
90
|
+
starting.current = false;
|
|
91
|
+
try {
|
|
92
|
+
await fetch('/__board/self-check', {
|
|
93
|
+
method: 'PUT',
|
|
94
|
+
headers: { 'content-type': 'application/json' },
|
|
95
|
+
body: JSON.stringify({ slideId, selfCheck }),
|
|
96
|
+
});
|
|
97
|
+
} catch {}
|
|
98
|
+
},
|
|
99
|
+
[slideId],
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const runner: { input: SelfCheckInput; onDone: (result: CheckResult) => void } | null =
|
|
103
|
+
running && deck
|
|
104
|
+
? {
|
|
105
|
+
input: {
|
|
106
|
+
pages: deck.default,
|
|
107
|
+
design: deck.design,
|
|
108
|
+
notes: deck.notes,
|
|
109
|
+
titles,
|
|
110
|
+
minType,
|
|
111
|
+
},
|
|
112
|
+
onDone: (result) => void finish(result),
|
|
113
|
+
}
|
|
114
|
+
: null;
|
|
115
|
+
|
|
116
|
+
return { record, running, run, runner, refresh };
|
|
117
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
|
-
import { useLocation } from 'react-router-dom';
|
|
2
|
+
import { useLocation, useNavigate } from 'react-router-dom';
|
|
3
3
|
import { toast } from 'sonner';
|
|
4
4
|
import { format } from '@/lib/use-locale';
|
|
5
5
|
import { OfflineBanner } from '../feedback/offline-banner';
|
|
@@ -52,10 +52,21 @@ function useDecksChangedReload() {
|
|
|
52
52
|
|
|
53
53
|
function usePendingToast() {
|
|
54
54
|
const lr = useLrText();
|
|
55
|
+
const navigate = useNavigate();
|
|
55
56
|
// biome-ignore lint/correctness/useExhaustiveDependencies: shows once per page load
|
|
56
57
|
useEffect(() => {
|
|
57
58
|
const pending = takePendingToast();
|
|
58
59
|
if (!pending) return;
|
|
60
|
+
if (pending.kind === 'imported') {
|
|
61
|
+
toast.success(format(lr.share.importedToast, { title: pending.name }), {
|
|
62
|
+
duration: 8000,
|
|
63
|
+
action: {
|
|
64
|
+
label: lr.share.openAction,
|
|
65
|
+
onClick: () => navigate(`/s/${encodeURIComponent(pending.slideId)}`),
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
59
70
|
if (pending.kind === 'restored') {
|
|
60
71
|
toast.success(format(lr.home.toastRestored, { name: pending.name }));
|
|
61
72
|
return;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { cn } from '@/lib/utils';
|
|
2
|
+
|
|
3
|
+
/** The single-choice occasion chips shared by the home list and the template library. */
|
|
4
|
+
export function FilterPill({
|
|
5
|
+
label,
|
|
6
|
+
active,
|
|
7
|
+
onSelect,
|
|
8
|
+
}: {
|
|
9
|
+
label: string;
|
|
10
|
+
active: boolean;
|
|
11
|
+
onSelect: () => void;
|
|
12
|
+
}) {
|
|
13
|
+
return (
|
|
14
|
+
// biome-ignore lint/a11y/useSemanticElements: a row of pills, as elsewhere in the app
|
|
15
|
+
<button
|
|
16
|
+
type="button"
|
|
17
|
+
role="radio"
|
|
18
|
+
aria-checked={active}
|
|
19
|
+
onClick={onSelect}
|
|
20
|
+
className={cn(
|
|
21
|
+
'h-8 rounded-full border px-3.5 text-[13px] font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring/40',
|
|
22
|
+
active
|
|
23
|
+
? 'border-[var(--lr-focus)] bg-[var(--lr-accent-soft)] text-foreground'
|
|
24
|
+
: 'border-border bg-card text-muted-foreground hover:border-[var(--lr-text-3)] hover:text-foreground',
|
|
25
|
+
)}
|
|
26
|
+
>
|
|
27
|
+
{label}
|
|
28
|
+
</button>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { Plus, Settings, Trash2 } from 'lucide-react';
|
|
1
|
+
import { LayoutTemplate, Plus, Settings, Trash2 } from 'lucide-react';
|
|
2
2
|
import { createPortal } from 'react-dom';
|
|
3
3
|
import { useLocation, useNavigate } from 'react-router-dom';
|
|
4
4
|
import { Button } from '@/components/ui/button';
|
|
5
5
|
import { useCreateDeck } from '@/lib/agent/use-agent';
|
|
6
6
|
import { isFeatureEnabled } from '../features';
|
|
7
|
+
import { useTemplateLibrary } from '../templates/use-library';
|
|
7
8
|
import { useLrText } from '../text';
|
|
8
9
|
import { pageForPath } from '../theme/pages';
|
|
9
10
|
import { NavRow } from './nav-row';
|
|
@@ -18,6 +19,8 @@ export function SidebarExtras() {
|
|
|
18
19
|
const createDeck = useCreateDeck();
|
|
19
20
|
const lr = useLrText();
|
|
20
21
|
const page = pageForPath(pathname);
|
|
22
|
+
const library = useTemplateLibrary();
|
|
23
|
+
const templatesOn = isFeatureEnabled('templates') && library?.available === true;
|
|
21
24
|
|
|
22
25
|
return (
|
|
23
26
|
<>
|
|
@@ -33,6 +36,14 @@ export function SidebarExtras() {
|
|
|
33
36
|
{nav &&
|
|
34
37
|
createPortal(
|
|
35
38
|
<>
|
|
39
|
+
{templatesOn && (
|
|
40
|
+
<NavRow
|
|
41
|
+
icon={<LayoutTemplate className="size-4" strokeWidth={1.75} />}
|
|
42
|
+
label={lr.templates.title}
|
|
43
|
+
current={page === 'templates'}
|
|
44
|
+
onSelect={() => navigate('/templates', { replace: true })}
|
|
45
|
+
/>
|
|
46
|
+
)}
|
|
36
47
|
{isFeatureEnabled('trash') && (
|
|
37
48
|
<NavRow
|
|
38
49
|
icon={<Trash2 className="size-4" strokeWidth={1.75} />}
|
|
@@ -31,4 +31,14 @@ describe('isFeatureEnabled', () => {
|
|
|
31
31
|
expect(isFeatureEnabled('outline', { dev: true })).toBe(true);
|
|
32
32
|
expect(isFeatureEnabled('outline', { dev: false })).toBe(false);
|
|
33
33
|
});
|
|
34
|
+
|
|
35
|
+
it('keeps the template library to dev, where its files sit', () => {
|
|
36
|
+
expect(isFeatureEnabled('templates', { dev: true })).toBe(true);
|
|
37
|
+
expect(isFeatureEnabled('templates', { dev: false })).toBe(false);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('keeps sharing to dev, where the pack and import endpoints run', () => {
|
|
41
|
+
expect(isFeatureEnabled('share', { dev: true })).toBe(true);
|
|
42
|
+
expect(isFeatureEnabled('share', { dev: false })).toBe(false);
|
|
43
|
+
});
|
|
34
44
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type Tier = 'free' | 'pro';
|
|
2
|
-
export type FeatureId = 'board' | 'trash' | 'settings' | 'outline';
|
|
2
|
+
export type FeatureId = 'board' | 'trash' | 'settings' | 'outline' | 'templates' | 'share';
|
|
3
3
|
|
|
4
4
|
export type Feature = { id: FeatureId; tier: Tier; devOnly: boolean };
|
|
5
5
|
|
|
@@ -8,6 +8,8 @@ export const FEATURES: readonly Feature[] = [
|
|
|
8
8
|
{ id: 'trash', tier: 'free', devOnly: true },
|
|
9
9
|
{ id: 'settings', tier: 'free', devOnly: false },
|
|
10
10
|
{ id: 'outline', tier: 'free', devOnly: true },
|
|
11
|
+
{ id: 'templates', tier: 'free', devOnly: true },
|
|
12
|
+
{ id: 'share', tier: 'free', devOnly: true },
|
|
11
13
|
];
|
|
12
14
|
|
|
13
15
|
/** The single place a paid tier will hook into later; today every tier is unlocked. */
|
|
@@ -5,7 +5,11 @@ const KEY = 'lemonriver:pending-toast';
|
|
|
5
5
|
* reloads every client, and the dev server's own reload can land before the
|
|
6
6
|
* request's response does, so the toast is saved before the request is sent.
|
|
7
7
|
*/
|
|
8
|
-
export type PendingToast = {
|
|
8
|
+
export type PendingToast = {
|
|
9
|
+
kind: 'trashed' | 'restored' | 'imported';
|
|
10
|
+
slideId: string;
|
|
11
|
+
name: string;
|
|
12
|
+
};
|
|
9
13
|
|
|
10
14
|
export function savePendingToast(toast: PendingToast, storage: Storage = sessionStorage): void {
|
|
11
15
|
try {
|
|
@@ -30,7 +34,8 @@ export function takePendingToast(storage: Storage = sessionStorage): PendingToas
|
|
|
30
34
|
if (!raw) return null;
|
|
31
35
|
try {
|
|
32
36
|
const value = JSON.parse(raw) as Record<string, unknown>;
|
|
33
|
-
if (value.kind !== 'trashed' && value.kind !== 'restored'
|
|
37
|
+
if (value.kind !== 'trashed' && value.kind !== 'restored' && value.kind !== 'imported')
|
|
38
|
+
return null;
|
|
34
39
|
if (typeof value.slideId !== 'string' || typeof value.name !== 'string') return null;
|
|
35
40
|
return { kind: value.kind, slideId: value.slideId, name: value.name };
|
|
36
41
|
} catch {
|