@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
|
@@ -14,8 +14,13 @@ const paths = (routes: unknown[]) =>
|
|
|
14
14
|
routes.filter(Boolean).map((r) => (r as ReactElement<{ path: string }>).props.path);
|
|
15
15
|
|
|
16
16
|
describe('lemonRiverRoutes', () => {
|
|
17
|
-
it('adds the board, the outline and the not-found page', () => {
|
|
18
|
-
expect(paths(lemonRiverRoutes())).toEqual([
|
|
17
|
+
it('adds the board, the outline, the template demo and the not-found page', () => {
|
|
18
|
+
expect(paths(lemonRiverRoutes())).toEqual([
|
|
19
|
+
'/s/:slideId/board',
|
|
20
|
+
'/s/:slideId/outline',
|
|
21
|
+
'/template-demo/:templateId',
|
|
22
|
+
'*',
|
|
23
|
+
]);
|
|
19
24
|
});
|
|
20
25
|
|
|
21
26
|
it('drops the pages whose feature is off', () => {
|
|
@@ -26,12 +31,19 @@ describe('lemonRiverRoutes', () => {
|
|
|
26
31
|
});
|
|
27
32
|
|
|
28
33
|
describe('lemonRiverShellRoutes', () => {
|
|
29
|
-
it('puts our home and the guided flow first, then settings and trash', () => {
|
|
30
|
-
expect(paths(lemonRiverShellRoutes())).toEqual([
|
|
34
|
+
it('puts our home and the guided flow first, then settings, templates and trash', () => {
|
|
35
|
+
expect(paths(lemonRiverShellRoutes())).toEqual([
|
|
36
|
+
'/',
|
|
37
|
+
'/new',
|
|
38
|
+
'/settings',
|
|
39
|
+
'/templates',
|
|
40
|
+
'/trash',
|
|
41
|
+
]);
|
|
31
42
|
});
|
|
32
43
|
|
|
33
44
|
it('leaves out the pages whose feature is off', () => {
|
|
34
|
-
vi.mocked(isFeatureEnabled).mockImplementation((id) => id !== 'trash');
|
|
45
|
+
vi.mocked(isFeatureEnabled).mockImplementation((id) => id !== 'trash' && id !== 'templates');
|
|
35
46
|
expect(paths(lemonRiverShellRoutes())).toEqual(['/', '/new', '/settings']);
|
|
47
|
+
vi.mocked(isFeatureEnabled).mockReturnValue(true);
|
|
36
48
|
});
|
|
37
49
|
});
|
|
@@ -13,6 +13,12 @@ const DescribePage = lazy(() =>
|
|
|
13
13
|
const OutlinePage = lazy(() =>
|
|
14
14
|
import('./outline/outline-page').then((m) => ({ default: m.OutlineView })),
|
|
15
15
|
);
|
|
16
|
+
const TemplateDemoPage = lazy(() =>
|
|
17
|
+
import('./templates/demo-page').then((m) => ({ default: m.TemplateDemoPage })),
|
|
18
|
+
);
|
|
19
|
+
const TemplatesPage = lazy(() =>
|
|
20
|
+
import('./templates/library-page').then((m) => ({ default: m.TemplatesPage })),
|
|
21
|
+
);
|
|
16
22
|
|
|
17
23
|
/** Routes of our own, outside the home shell. Placed before the official catch-all. */
|
|
18
24
|
export function lemonRiverRoutes() {
|
|
@@ -39,6 +45,17 @@ export function lemonRiverRoutes() {
|
|
|
39
45
|
}
|
|
40
46
|
/>
|
|
41
47
|
),
|
|
48
|
+
isFeatureEnabled('templates') && (
|
|
49
|
+
<Route
|
|
50
|
+
key="template-demo"
|
|
51
|
+
path="/template-demo/:templateId"
|
|
52
|
+
element={
|
|
53
|
+
<Suspense fallback={null}>
|
|
54
|
+
<TemplateDemoPage />
|
|
55
|
+
</Suspense>
|
|
56
|
+
}
|
|
57
|
+
/>
|
|
58
|
+
),
|
|
42
59
|
<Route key="not-found" path="*" element={<NotFound />} />,
|
|
43
60
|
];
|
|
44
61
|
}
|
|
@@ -61,6 +78,17 @@ export function lemonRiverShellRoutes() {
|
|
|
61
78
|
isFeatureEnabled('settings') && (
|
|
62
79
|
<Route key="settings" path="/settings" element={<SettingsPage />} />
|
|
63
80
|
),
|
|
81
|
+
isFeatureEnabled('templates') && (
|
|
82
|
+
<Route
|
|
83
|
+
key="templates"
|
|
84
|
+
path="/templates"
|
|
85
|
+
element={
|
|
86
|
+
<Suspense fallback={null}>
|
|
87
|
+
<TemplatesPage />
|
|
88
|
+
</Suspense>
|
|
89
|
+
}
|
|
90
|
+
/>
|
|
91
|
+
),
|
|
64
92
|
isFeatureEnabled('trash') && <Route key="trash" path="/trash" element={<TrashPage />} />,
|
|
65
93
|
];
|
|
66
94
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { CANVAS_HEIGHT, CANVAS_WIDTH, type SlideModule } from '../../lib/sdk';
|
|
2
|
+
import { canvasJpeg, canvasThumb, freezeForCapture } from './freeze';
|
|
3
|
+
|
|
4
|
+
const CAPTURE_CLASS = 'lr-share-capture';
|
|
5
|
+
const JPEG_QUALITY = 0.88;
|
|
6
|
+
const THUMB_WIDTH = 480;
|
|
7
|
+
const THUMB_HEIGHT = 270;
|
|
8
|
+
const THUMB_QUALITY = 0.8;
|
|
9
|
+
|
|
10
|
+
export type CapturedPage = { jpeg: Uint8Array; thumb: Uint8Array };
|
|
11
|
+
|
|
12
|
+
export class CaptureCancelled extends Error {
|
|
13
|
+
constructor() {
|
|
14
|
+
super('capture cancelled');
|
|
15
|
+
this.name = 'CaptureCancelled';
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function aborted(signal: AbortSignal): boolean {
|
|
20
|
+
return signal.aborted;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function toBase64(bytes: Uint8Array): string {
|
|
24
|
+
let binary = '';
|
|
25
|
+
const chunk = 0x8000;
|
|
26
|
+
for (let i = 0; i < bytes.length; i += chunk) {
|
|
27
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
|
|
28
|
+
}
|
|
29
|
+
return btoa(binary);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Draws every page off-screen and rasterises it twice: the full-size JPEG that
|
|
34
|
+
* becomes a PDF page, and a small one for the preview inside the package.
|
|
35
|
+
*/
|
|
36
|
+
export async function captureDeck(
|
|
37
|
+
slide: SlideModule,
|
|
38
|
+
opts: {
|
|
39
|
+
onPage: (current: number, total: number) => void;
|
|
40
|
+
signal: AbortSignal;
|
|
41
|
+
},
|
|
42
|
+
): Promise<CapturedPage[]> {
|
|
43
|
+
const pages = slide.default ?? [];
|
|
44
|
+
const total = pages.length;
|
|
45
|
+
if (total === 0) throw new Error('this deck has no pages');
|
|
46
|
+
const [{ mountDeckOffscreen }, { toCanvas }] = await Promise.all([
|
|
47
|
+
import('../../lib/pptx/render'),
|
|
48
|
+
import('html-to-image'),
|
|
49
|
+
]);
|
|
50
|
+
if (aborted(opts.signal)) throw new CaptureCancelled();
|
|
51
|
+
|
|
52
|
+
const mounted = await mountDeckOffscreen(slide, CAPTURE_CLASS);
|
|
53
|
+
const captured: CapturedPage[] = [];
|
|
54
|
+
try {
|
|
55
|
+
for (let i = 0; i < mounted.frames.length; i++) {
|
|
56
|
+
if (aborted(opts.signal)) throw new CaptureCancelled();
|
|
57
|
+
const frame = mounted.frames[i];
|
|
58
|
+
if (!frame) continue;
|
|
59
|
+
freezeForCapture(frame);
|
|
60
|
+
const canvas = await toCanvas(frame, {
|
|
61
|
+
width: CANVAS_WIDTH,
|
|
62
|
+
height: CANVAS_HEIGHT,
|
|
63
|
+
pixelRatio: 1,
|
|
64
|
+
backgroundColor: '#ffffff',
|
|
65
|
+
cacheBust: true,
|
|
66
|
+
});
|
|
67
|
+
const jpeg = await canvasJpeg(canvas, JPEG_QUALITY);
|
|
68
|
+
const thumb = await canvasThumb(canvas, THUMB_WIDTH, THUMB_HEIGHT, THUMB_QUALITY);
|
|
69
|
+
captured.push({ jpeg, thumb });
|
|
70
|
+
opts.onPage(i + 1, total);
|
|
71
|
+
}
|
|
72
|
+
} finally {
|
|
73
|
+
mounted.dispose();
|
|
74
|
+
}
|
|
75
|
+
return captured;
|
|
76
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import type { DeckChanges } from './compare';
|
|
2
|
+
|
|
3
|
+
/** The browser's side of the share endpoints. */
|
|
4
|
+
|
|
5
|
+
export type ShareExtra = { name: string; base64: string };
|
|
6
|
+
|
|
7
|
+
export type PackResponse = {
|
|
8
|
+
ok: true;
|
|
9
|
+
path: string;
|
|
10
|
+
name: string;
|
|
11
|
+
size: number;
|
|
12
|
+
warnings: string[];
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type PackFailure = { ok: false; error: string; paths?: string[] };
|
|
16
|
+
|
|
17
|
+
export type InspectDeck = {
|
|
18
|
+
slideId: string;
|
|
19
|
+
title: string;
|
|
20
|
+
pages: number | null;
|
|
21
|
+
thumbs: number;
|
|
22
|
+
theme: string | null;
|
|
23
|
+
existing: { slideId: string; title: string } | null;
|
|
24
|
+
idTaken: boolean;
|
|
25
|
+
changes: DeckChanges | null;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type InspectOk = {
|
|
29
|
+
ok: true;
|
|
30
|
+
token: string;
|
|
31
|
+
kind: 'share' | 'backup';
|
|
32
|
+
app: { name: string; version: string };
|
|
33
|
+
createdAt: number;
|
|
34
|
+
decks: InspectDeck[];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export type InspectFailure = {
|
|
38
|
+
ok: false;
|
|
39
|
+
code: string;
|
|
40
|
+
detail: string;
|
|
41
|
+
paths?: string[];
|
|
42
|
+
appVersion?: string;
|
|
43
|
+
status: number;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
async function readJson<T>(res: Response): Promise<T> {
|
|
47
|
+
return (await res.json().catch(() => ({}))) as T;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export async function appVersion(): Promise<string> {
|
|
51
|
+
const res = await fetch('/__lr/share/version', { headers: { accept: 'application/json' } });
|
|
52
|
+
const data = await readJson<{ version?: string }>(res);
|
|
53
|
+
return typeof data.version === 'string' ? data.version : '';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function packShare(input: {
|
|
57
|
+
slideIds: string[];
|
|
58
|
+
pages: Record<string, number>;
|
|
59
|
+
thumbs: Record<string, string[]>;
|
|
60
|
+
extras: ShareExtra[];
|
|
61
|
+
}): Promise<PackResponse | PackFailure> {
|
|
62
|
+
const res = await fetch('/__lr/share/pack', {
|
|
63
|
+
method: 'POST',
|
|
64
|
+
headers: { 'content-type': 'application/json' },
|
|
65
|
+
body: JSON.stringify({ ...input, kind: 'share' }),
|
|
66
|
+
});
|
|
67
|
+
const data = await readJson<{
|
|
68
|
+
ok?: boolean;
|
|
69
|
+
path?: string;
|
|
70
|
+
name?: string;
|
|
71
|
+
size?: number;
|
|
72
|
+
warnings?: string[];
|
|
73
|
+
error?: string;
|
|
74
|
+
paths?: string[];
|
|
75
|
+
}>(res);
|
|
76
|
+
if (!res.ok || data.ok !== true || typeof data.path !== 'string') {
|
|
77
|
+
return { ok: false, error: data.error ?? `HTTP ${res.status}`, paths: data.paths ?? [] };
|
|
78
|
+
}
|
|
79
|
+
return {
|
|
80
|
+
ok: true,
|
|
81
|
+
path: data.path,
|
|
82
|
+
name: typeof data.name === 'string' ? data.name : '',
|
|
83
|
+
size: typeof data.size === 'number' ? data.size : 0,
|
|
84
|
+
warnings: Array.isArray(data.warnings) ? data.warnings : [],
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export async function revealShared(path: string): Promise<boolean> {
|
|
89
|
+
const res = await fetch('/__lr/share/reveal', {
|
|
90
|
+
method: 'POST',
|
|
91
|
+
headers: { 'content-type': 'application/json' },
|
|
92
|
+
body: JSON.stringify({ path }),
|
|
93
|
+
});
|
|
94
|
+
return res.ok;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export async function inspectPackage(bytes: Uint8Array): Promise<InspectOk | InspectFailure> {
|
|
98
|
+
const res = await fetch('/__lr/share/inspect', {
|
|
99
|
+
method: 'POST',
|
|
100
|
+
headers: { 'content-type': 'application/zip' },
|
|
101
|
+
body: new Blob([bytes as BlobPart], { type: 'application/zip' }),
|
|
102
|
+
});
|
|
103
|
+
const data = await readJson<{
|
|
104
|
+
ok?: boolean;
|
|
105
|
+
token?: string;
|
|
106
|
+
kind?: 'share' | 'backup';
|
|
107
|
+
app?: { name: string; version: string };
|
|
108
|
+
createdAt?: number;
|
|
109
|
+
decks?: InspectDeck[];
|
|
110
|
+
code?: string;
|
|
111
|
+
detail?: string;
|
|
112
|
+
paths?: string[];
|
|
113
|
+
appVersion?: string;
|
|
114
|
+
}>(res);
|
|
115
|
+
if (!res.ok || data.ok !== true || typeof data.token !== 'string') {
|
|
116
|
+
return {
|
|
117
|
+
ok: false,
|
|
118
|
+
status: res.status,
|
|
119
|
+
code: typeof data.code === 'string' ? data.code : 'bad-manifest',
|
|
120
|
+
detail: typeof data.detail === 'string' ? data.detail : `HTTP ${res.status}`,
|
|
121
|
+
paths: Array.isArray(data.paths) ? data.paths : [],
|
|
122
|
+
appVersion: typeof data.appVersion === 'string' ? data.appVersion : '',
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
return {
|
|
126
|
+
ok: true,
|
|
127
|
+
token: data.token,
|
|
128
|
+
kind: data.kind === 'backup' ? 'backup' : 'share',
|
|
129
|
+
app: data.app ?? { name: 'LemonRiver', version: '' },
|
|
130
|
+
createdAt: typeof data.createdAt === 'number' ? data.createdAt : 0,
|
|
131
|
+
decks: (Array.isArray(data.decks) ? data.decks : []).map((deck) => ({
|
|
132
|
+
...deck,
|
|
133
|
+
changes: deck.changes ?? null,
|
|
134
|
+
})),
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
export type ImportedDeck = { from: string; slideId: string };
|
|
139
|
+
|
|
140
|
+
export async function importPackages(
|
|
141
|
+
token: string,
|
|
142
|
+
decks: { slideId: string; mode: 'copy' | 'replace' }[],
|
|
143
|
+
): Promise<{ imported: ImportedDeck[]; warnings: string[] }> {
|
|
144
|
+
const res = await fetch('/__lr/share/import', {
|
|
145
|
+
method: 'POST',
|
|
146
|
+
headers: { 'content-type': 'application/json' },
|
|
147
|
+
body: JSON.stringify({ token, decks }),
|
|
148
|
+
});
|
|
149
|
+
const data = await readJson<{
|
|
150
|
+
ok?: boolean;
|
|
151
|
+
imported?: ImportedDeck[];
|
|
152
|
+
warnings?: string[];
|
|
153
|
+
error?: string;
|
|
154
|
+
}>(res);
|
|
155
|
+
if (!res.ok || data.ok !== true) throw new Error(data.error ?? `HTTP ${res.status}`);
|
|
156
|
+
return { imported: data.imported ?? [], warnings: data.warnings ?? [] };
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function thumbUrl(token: string, slideId: string, page: number): string {
|
|
160
|
+
const name = String(page).padStart(2, '0');
|
|
161
|
+
return `/__lr/share/inbox/${encodeURIComponent(token)}/thumbs/${encodeURIComponent(slideId)}/${name}.jpg`;
|
|
162
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { en } from '../text/en';
|
|
3
|
+
import { es } from '../text/es';
|
|
4
|
+
import { ja } from '../text/ja';
|
|
5
|
+
import { zhCN } from '../text/zh-cn';
|
|
6
|
+
import { zhTW } from '../text/zh-tw';
|
|
7
|
+
import { shareErrorText } from './codes';
|
|
8
|
+
import type { ShareCode } from './model';
|
|
9
|
+
|
|
10
|
+
const CODES: ShareCode[] = [
|
|
11
|
+
'not-a-package',
|
|
12
|
+
'bad-manifest',
|
|
13
|
+
'newer-version',
|
|
14
|
+
'bad-path',
|
|
15
|
+
'blocked-file',
|
|
16
|
+
'checksum',
|
|
17
|
+
'missing-file',
|
|
18
|
+
'extra-file',
|
|
19
|
+
'too-large',
|
|
20
|
+
'too-many-files',
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
describe('shareErrorText', () => {
|
|
24
|
+
it('has a sentence for every code in every language', () => {
|
|
25
|
+
for (const text of [zhCN, zhTW, en, ja, es]) {
|
|
26
|
+
for (const code of CODES) {
|
|
27
|
+
const message = shareErrorText(text.share.errors, code, '', text.share.unknownVersion);
|
|
28
|
+
expect(message, code).not.toContain('{');
|
|
29
|
+
expect(message.length, code).toBeGreaterThan(4);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('names the version that made a package we cannot read yet', () => {
|
|
35
|
+
expect(shareErrorText(en.share.errors, 'newer-version', '9.9.9')).toBe(
|
|
36
|
+
'This package was made by a newer LemonRiver (9.9.9). Update first, then import.',
|
|
37
|
+
);
|
|
38
|
+
expect(shareErrorText(zhCN.share.errors, 'newer-version', '9.9.9')).toBe(
|
|
39
|
+
'这个包是用更新的 LemonRiver(9.9.9)做的,先更新再导入。',
|
|
40
|
+
);
|
|
41
|
+
expect(
|
|
42
|
+
shareErrorText(zhCN.share.errors, 'newer-version', '', zhCN.share.unknownVersion),
|
|
43
|
+
).toContain('未知版本');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('treats a code it has never heard of as a broken package', () => {
|
|
47
|
+
expect(shareErrorText(en.share.errors, 'something-new')).toBe(en.share.errors.badManifest);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { format } from '../../../locale/format';
|
|
2
|
+
import type { LrText } from '../text/types';
|
|
3
|
+
import type { ShareCode } from './model';
|
|
4
|
+
|
|
5
|
+
type Errors = LrText['share']['errors'];
|
|
6
|
+
|
|
7
|
+
const KEYS: Record<ShareCode, keyof Errors> = {
|
|
8
|
+
'not-a-package': 'notAPackage',
|
|
9
|
+
'bad-manifest': 'badManifest',
|
|
10
|
+
'newer-version': 'newerVersion',
|
|
11
|
+
'bad-path': 'badPath',
|
|
12
|
+
'blocked-file': 'blockedFile',
|
|
13
|
+
checksum: 'checksum',
|
|
14
|
+
'missing-file': 'missingFile',
|
|
15
|
+
'extra-file': 'extraFile',
|
|
16
|
+
'too-large': 'tooLarge',
|
|
17
|
+
'too-many-files': 'tooManyFiles',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export function shareErrorText(
|
|
21
|
+
errors: Errors,
|
|
22
|
+
code: string,
|
|
23
|
+
appVersion = '',
|
|
24
|
+
unknownVersion = '',
|
|
25
|
+
): string {
|
|
26
|
+
const key = KEYS[code as ShareCode] ?? 'badManifest';
|
|
27
|
+
return format(errors[key], {
|
|
28
|
+
version: appVersion !== '' ? appVersion : unknownVersion,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { compareDeck } from './compare';
|
|
3
|
+
|
|
4
|
+
const encoder = new TextEncoder();
|
|
5
|
+
const bytes = (text: string) => encoder.encode(text);
|
|
6
|
+
|
|
7
|
+
const BASE = `import type { Page } from '@lemonriver/core';
|
|
8
|
+
|
|
9
|
+
export const meta = { title: 'Q3' };
|
|
10
|
+
|
|
11
|
+
const Cover: Page = () => <div>Cover</div>;
|
|
12
|
+
const Body: Page = () => <div>Body</div>;
|
|
13
|
+
|
|
14
|
+
export const notes = ['first', 'second'];
|
|
15
|
+
|
|
16
|
+
export default [Cover, Body] satisfies Page[];
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
function deck(source: string, extra: Record<string, string | Uint8Array> = {}) {
|
|
20
|
+
const files: Record<string, Uint8Array> = { 'index.tsx': bytes(source) };
|
|
21
|
+
for (const [path, data] of Object.entries(extra)) {
|
|
22
|
+
files[path] = typeof data === 'string' ? bytes(data) : data;
|
|
23
|
+
}
|
|
24
|
+
return files;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const statuses = (changes: ReturnType<typeof compareDeck>) =>
|
|
28
|
+
changes.pages.map((page) => [page.n, page.status]);
|
|
29
|
+
|
|
30
|
+
describe('compareDeck', () => {
|
|
31
|
+
it('reports nothing when the two copies are identical, reformatting included', () => {
|
|
32
|
+
const reformatted = BASE.replace(/\n\n/g, '\n\n\n')
|
|
33
|
+
.replace('<div>Cover</div>', '<div> Cover </div>')
|
|
34
|
+
.replace("title: 'Q3'", "title: 'Q3'");
|
|
35
|
+
const changes = compareDeck(deck(BASE), deck(reformatted));
|
|
36
|
+
expect(changes.readable).toBe(true);
|
|
37
|
+
expect(statuses(changes)).toEqual([
|
|
38
|
+
[1, 'same'],
|
|
39
|
+
[2, 'same'],
|
|
40
|
+
]);
|
|
41
|
+
expect(changes.shared).toBe(false);
|
|
42
|
+
expect(changes.assets).toEqual({ added: [], changed: [], removed: [] });
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('marks a page whose code changed', () => {
|
|
46
|
+
const changes = compareDeck(deck(BASE), deck(BASE.replace('Body</div>', 'Body, v2</div>')));
|
|
47
|
+
expect(statuses(changes)).toEqual([
|
|
48
|
+
[1, 'same'],
|
|
49
|
+
[2, 'changed'],
|
|
50
|
+
]);
|
|
51
|
+
expect(changes.pages[1]?.name).toBe('Body');
|
|
52
|
+
expect(changes.shared).toBe(false);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('marks a page that only moved', () => {
|
|
56
|
+
const moved = BASE.replace('export default [Cover, Body]', 'export default [Body, Cover]');
|
|
57
|
+
const changes = compareDeck(deck(BASE), deck(moved));
|
|
58
|
+
expect(statuses(changes)).toEqual([
|
|
59
|
+
[1, 'moved'],
|
|
60
|
+
[2, 'moved'],
|
|
61
|
+
]);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('marks an added page with its place in the package', () => {
|
|
65
|
+
const extra = BASE.replace(
|
|
66
|
+
'const Body: Page = () => <div>Body</div>;',
|
|
67
|
+
'const Body: Page = () => <div>Body</div>;\nconst More: Page = () => <div>More</div>;',
|
|
68
|
+
).replace('[Cover, Body]', '[Cover, Body, More]');
|
|
69
|
+
const changes = compareDeck(deck(BASE), deck(extra));
|
|
70
|
+
expect(statuses(changes)).toEqual([
|
|
71
|
+
[1, 'same'],
|
|
72
|
+
[2, 'same'],
|
|
73
|
+
[3, 'added'],
|
|
74
|
+
]);
|
|
75
|
+
expect(changes.pages[2]?.name).toBe('More');
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('marks a page this machine has and the package does not', () => {
|
|
79
|
+
const fewer = BASE.replace('const Body: Page = () => <div>Body</div>;\n', '').replace(
|
|
80
|
+
'[Cover, Body]',
|
|
81
|
+
'[Cover]',
|
|
82
|
+
);
|
|
83
|
+
const changes = compareDeck(deck(BASE), deck(fewer));
|
|
84
|
+
expect(statuses(changes)).toEqual([
|
|
85
|
+
[1, 'same'],
|
|
86
|
+
[2, 'removed'],
|
|
87
|
+
]);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('counts a page whose only change is its speaker note', () => {
|
|
91
|
+
const changes = compareDeck(
|
|
92
|
+
deck(BASE),
|
|
93
|
+
deck(BASE.replace("['first', 'second']", "['first', 'second, rewritten']")),
|
|
94
|
+
);
|
|
95
|
+
expect(statuses(changes)).toEqual([
|
|
96
|
+
[1, 'same'],
|
|
97
|
+
[2, 'changed'],
|
|
98
|
+
]);
|
|
99
|
+
expect(changes.pages[1]?.notes).toBe(true);
|
|
100
|
+
expect(changes.pages[0]?.notes).toBe(false);
|
|
101
|
+
expect(changes.shared).toBe(false);
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it('does not treat a title change as shared code', () => {
|
|
105
|
+
const changes = compareDeck(deck(BASE), deck(BASE.replace("title: 'Q3'", "title: 'Q3 FY26'")));
|
|
106
|
+
expect(changes.shared).toBe(false);
|
|
107
|
+
expect(statuses(changes)).toEqual([
|
|
108
|
+
[1, 'same'],
|
|
109
|
+
[2, 'same'],
|
|
110
|
+
]);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('keeps exported pages out of the shared check', () => {
|
|
114
|
+
const exported = BASE.replace('const Cover: Page', 'export const Cover: Page').replace(
|
|
115
|
+
'const Body: Page',
|
|
116
|
+
'export const Body: Page',
|
|
117
|
+
);
|
|
118
|
+
const changes = compareDeck(
|
|
119
|
+
deck(exported),
|
|
120
|
+
deck(exported.replace('Body</div>', 'Body v2</div>')),
|
|
121
|
+
);
|
|
122
|
+
expect(statuses(changes)).toEqual([
|
|
123
|
+
[1, 'same'],
|
|
124
|
+
[2, 'changed'],
|
|
125
|
+
]);
|
|
126
|
+
expect(changes.shared).toBe(false);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('flags a component both pages use as shared', () => {
|
|
130
|
+
const source = `import type { Page } from '@lemonriver/core';
|
|
131
|
+
|
|
132
|
+
export const meta = { title: 'Q3' };
|
|
133
|
+
|
|
134
|
+
const Card = () => <p>card</p>;
|
|
135
|
+
|
|
136
|
+
const Cover: Page = () => <div><Card />Cover</div>;
|
|
137
|
+
const Body: Page = () => <div><Card />Body</div>;
|
|
138
|
+
|
|
139
|
+
export const notes = ['first', 'second'];
|
|
140
|
+
|
|
141
|
+
export default [Cover, Body] satisfies Page[];
|
|
142
|
+
`;
|
|
143
|
+
const changes = compareDeck(deck(source), deck(source.replace('card</p>', 'card v2</p>')));
|
|
144
|
+
expect(changes.shared).toBe(true);
|
|
145
|
+
expect(statuses(changes)).toEqual([
|
|
146
|
+
[1, 'same'],
|
|
147
|
+
[2, 'same'],
|
|
148
|
+
]);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('ignores how packing rewrote an asset reference', () => {
|
|
152
|
+
const local = deck(
|
|
153
|
+
BASE.replace('Cover</div>', 'Cover<Logo /></div>').replace(
|
|
154
|
+
'const Cover',
|
|
155
|
+
"import logo from '@assets/logo.png';\n\nconst Cover",
|
|
156
|
+
),
|
|
157
|
+
);
|
|
158
|
+
const packaged = deck(
|
|
159
|
+
BASE.replace('Cover</div>', 'Cover<Logo /></div>').replace(
|
|
160
|
+
'const Cover',
|
|
161
|
+
"import logo from './assets/logo.png';\n\nconst Cover",
|
|
162
|
+
),
|
|
163
|
+
{ 'assets/logo.png': bytes('PNG') },
|
|
164
|
+
);
|
|
165
|
+
const changes = compareDeck(local, packaged);
|
|
166
|
+
expect(statuses(changes)).toEqual([
|
|
167
|
+
[1, 'same'],
|
|
168
|
+
[2, 'same'],
|
|
169
|
+
]);
|
|
170
|
+
expect(changes.shared).toBe(false);
|
|
171
|
+
expect(changes.assets.added).toEqual(['logo.png']);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
it('lists assets that were added, changed and removed', () => {
|
|
175
|
+
const local = deck(BASE, { 'assets/a.png': 'old', 'assets/gone.png': 'x' });
|
|
176
|
+
const packaged = deck(BASE, { 'assets/a.png': 'new', 'assets/b.png': 'y' });
|
|
177
|
+
const changes = compareDeck(local, packaged);
|
|
178
|
+
expect(changes.assets).toEqual({ added: ['b.png'], changed: ['a.png'], removed: ['gone.png'] });
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('pairs inline pages by position', () => {
|
|
182
|
+
const inline = (b: string) =>
|
|
183
|
+
`import type { Page } from '@lemonriver/core';\n\nexport default [() => <div>${b}</div>, () => <div>Y</div>] satisfies Page[];\n`;
|
|
184
|
+
const changes = compareDeck(deck(inline('X')), deck(inline('X2')));
|
|
185
|
+
expect(statuses(changes)).toEqual([
|
|
186
|
+
[1, 'changed'],
|
|
187
|
+
[2, 'same'],
|
|
188
|
+
]);
|
|
189
|
+
expect(changes.pages[0]?.name).toBeNull();
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it('says when the file cannot be read page by page', () => {
|
|
193
|
+
const spread = `import type { Page } from '@lemonriver/core';\nconst rest: Page[] = [];\nexport default [() => <div>X</div>, ...rest];\n`;
|
|
194
|
+
const changes = compareDeck(deck(BASE), deck(spread));
|
|
195
|
+
expect(changes.readable).toBe(false);
|
|
196
|
+
expect(changes.pages).toEqual([]);
|
|
197
|
+
expect(changes.shared).toBe(true);
|
|
198
|
+
});
|
|
199
|
+
});
|