@lemonriver/core 0.4.0 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -4
- package/dist/{build-Nl7EeJ6x.js → build-RlcGG-Ve.js} +1 -1
- package/dist/cli/bin.js +4 -4
- package/dist/{config-CpC0nM3r.js → config-BJT87wE9.js} +4756 -2012
- package/dist/{dev-BB3THd5I.js → dev-DR-j_xda.js} +2 -2
- package/dist/{preview-BGjgTg7H.js → preview-BTAhTb5B.js} +1 -1
- package/dist/{update-DsxZBtwv.js → update-CMRxtTc9.js} +18 -8
- package/dist/vite/index.js +1 -1
- package/package.json +2 -2
- package/src/agent/types.ts +14 -2
- package/src/app/components/agent/agent-panel.tsx +17 -5
- package/src/app/components/agent/connect-view.tsx +1 -1
- package/src/app/components/agent/provider-logo.tsx +10 -1
- package/src/app/lemonriver/agent/provider-marks.tsx +53 -0
- package/src/app/lemonriver/agent-providers/section.tsx +75 -0
- package/src/app/lemonriver/agent-providers/use-providers.ts +61 -0
- package/src/app/lemonriver/board/blocks/block-panel.tsx +666 -0
- package/src/app/lemonriver/board/blocks/cache.ts +28 -0
- package/src/app/lemonriver/board/blocks/change-list.tsx +189 -0
- package/src/app/lemonriver/board/blocks/classify.test.ts +209 -0
- package/src/app/lemonriver/board/blocks/classify.ts +152 -0
- package/src/app/lemonriver/board/blocks/snapshot.ts +116 -0
- package/src/app/lemonriver/board/board-canvas.tsx +627 -104
- package/src/app/lemonriver/board/board-page.tsx +1702 -91
- package/src/app/lemonriver/board/board.css +58 -7
- package/src/app/lemonriver/board/layout.test.ts +84 -0
- package/src/app/lemonriver/board/layout.ts +112 -11
- package/src/app/lemonriver/board/model/agent-tasks.test.ts +200 -0
- package/src/app/lemonriver/board/model/agent-tasks.ts +223 -0
- package/src/app/lemonriver/board/model/apply-prompt.test.ts +121 -0
- package/src/app/lemonriver/board/model/apply-prompt.ts +115 -0
- package/src/app/lemonriver/board/model/apply.ts +71 -0
- package/src/app/lemonriver/board/model/cards.test.ts +95 -2
- package/src/app/lemonriver/board/model/cards.ts +88 -20
- package/src/app/lemonriver/board/model/changes.test.ts +244 -0
- package/src/app/lemonriver/board/model/changes.ts +268 -0
- package/src/app/lemonriver/board/model/filter.test.ts +50 -0
- package/src/app/lemonriver/board/model/filter.ts +42 -0
- package/src/app/lemonriver/board/model/history.test.ts +71 -0
- package/src/app/lemonriver/board/model/history.ts +51 -0
- package/src/app/lemonriver/board/model/restructure.test.ts +205 -0
- package/src/app/lemonriver/board/model/restructure.ts +169 -0
- 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/model/structure.test.ts +249 -0
- package/src/app/lemonriver/board/model/structure.ts +209 -0
- package/src/app/lemonriver/board/model/timing.test.ts +113 -0
- package/src/app/lemonriver/board/model/timing.ts +117 -0
- package/src/app/lemonriver/board/page-node.tsx +258 -55
- 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/status-style.ts +25 -0
- package/src/app/lemonriver/board/use-board-apply.ts +206 -0
- package/src/app/lemonriver/board/use-board-cards.ts +108 -5
- package/src/app/lemonriver/board/use-board-changes.ts +108 -0
- package/src/app/lemonriver/board/use-board-columns.ts +37 -56
- package/src/app/lemonriver/board/use-board-comments.ts +36 -0
- package/src/app/lemonriver/board/use-board-restructures.ts +107 -0
- package/src/app/lemonriver/board/use-history.ts +86 -0
- package/src/app/lemonriver/board/use-page-order.ts +65 -38
- package/src/app/lemonriver/board/use-self-check.ts +117 -0
- package/src/app/lemonriver/board/use-target-minutes.ts +47 -0
- package/src/app/lemonriver/board/views/block-readings.tsx +46 -0
- package/src/app/lemonriver/board/views/list-view.tsx +356 -0
- package/src/app/lemonriver/board/views/progress.tsx +32 -0
- package/src/app/lemonriver/board/views/timeline-view.tsx +341 -0
- 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 +5 -0
- package/src/app/lemonriver/features.ts +2 -1
- package/src/app/lemonriver/home/deck-card.tsx +10 -0
- package/src/app/lemonriver/home/home-page.tsx +55 -6
- 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 +118 -0
- package/src/app/lemonriver/outline/model.ts +92 -7
- package/src/app/lemonriver/outline/outline-page.tsx +90 -7
- 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/settings/settings-page.tsx +3 -0
- package/src/app/lemonriver/slide-extensions.tsx +14 -2
- 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 +292 -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 +228 -0
- package/src/app/lemonriver/text/es.ts +220 -0
- package/src/app/lemonriver/text/ja.ts +220 -0
- package/src/app/lemonriver/text/types.ts +243 -0
- package/src/app/lemonriver/text/zh-cn.ts +218 -0
- package/src/app/lemonriver/text/zh-tw.ts +218 -0
- package/src/app/lemonriver/theme/lemon-icon.tsx +6 -0
- package/src/app/lemonriver/theme/pages.test.ts +4 -0
- package/src/app/lemonriver/theme/pages.ts +6 -1
- package/src/app/lemonriver/theme/theme-menu.tsx +3 -2
- package/src/app/lemonriver/theme/use-theme.tsx +2 -2
- package/src/app/lemonriver/update/prompt.ts +1 -1
- package/src/app/lib/agent/use-agent.ts +4 -3
- package/src/app/routes/slide.tsx +1 -1
- package/src/app/assets/open-slide.svg +0 -39
- package/src/app/favicon.ico +0 -0
- package/src/app/favicon.svg +0 -39
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { useParams, useSearchParams } from 'react-router-dom';
|
|
3
|
+
import { SlideCanvas } from '@/components/slide-canvas';
|
|
4
|
+
import { SlidePageProvider } from '@/lib/page-context';
|
|
5
|
+
import { loadTemplateDemo, type TemplateDemoModule, templates } from './client';
|
|
6
|
+
import { applyKnobs, type TemplateKnobValues } from './model';
|
|
7
|
+
|
|
8
|
+
const knobValue = (raw: string | null): number | undefined => {
|
|
9
|
+
if (raw === null || raw.trim() === '') return undefined;
|
|
10
|
+
const value = Number(raw);
|
|
11
|
+
return Number.isFinite(value) ? Math.min(1, Math.max(0, value)) : undefined;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/** Dev-only: renders one page of a template's sample deck so a style can be seen before it is used. */
|
|
15
|
+
export function TemplateDemoPage() {
|
|
16
|
+
const { templateId = '' } = useParams();
|
|
17
|
+
const [params] = useSearchParams();
|
|
18
|
+
const [demo, setDemo] = useState<TemplateDemoModule | null>(null);
|
|
19
|
+
const [failed, setFailed] = useState(false);
|
|
20
|
+
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
let cancelled = false;
|
|
23
|
+
setDemo(null);
|
|
24
|
+
setFailed(false);
|
|
25
|
+
loadTemplateDemo(templateId)
|
|
26
|
+
.then((mod) => {
|
|
27
|
+
if (!cancelled) setDemo(mod);
|
|
28
|
+
})
|
|
29
|
+
.catch(() => {
|
|
30
|
+
if (!cancelled) setFailed(true);
|
|
31
|
+
});
|
|
32
|
+
return () => {
|
|
33
|
+
cancelled = true;
|
|
34
|
+
};
|
|
35
|
+
}, [templateId]);
|
|
36
|
+
|
|
37
|
+
const pages = demo?.default ?? [];
|
|
38
|
+
const requested = Number(params.get('p') ?? '1');
|
|
39
|
+
const pageNumber =
|
|
40
|
+
Number.isInteger(requested) && requested >= 1 && pages.length > 0
|
|
41
|
+
? Math.min(pages.length, requested)
|
|
42
|
+
: 1;
|
|
43
|
+
const Page = pages[pageNumber - 1];
|
|
44
|
+
|
|
45
|
+
// Preview-only: `?formal=0.1&bright=0.9` shows a template's knob ends.
|
|
46
|
+
const values: TemplateKnobValues = {
|
|
47
|
+
formal: knobValue(params.get('formal')),
|
|
48
|
+
bright: knobValue(params.get('bright')),
|
|
49
|
+
motion: knobValue(params.get('motion')),
|
|
50
|
+
};
|
|
51
|
+
const meta = templates.find((template) => template.id === templateId);
|
|
52
|
+
const baseDesign = demo?.design ?? meta?.design;
|
|
53
|
+
const design = baseDesign && meta ? applyKnobs(baseDesign, meta.knobs, values) : baseDesign;
|
|
54
|
+
|
|
55
|
+
if (failed) {
|
|
56
|
+
return (
|
|
57
|
+
<div className="grid h-screen place-items-center bg-black px-6 text-center font-mono text-[14px] text-muted-foreground">
|
|
58
|
+
Template demo not found: {templateId}
|
|
59
|
+
</div>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return (
|
|
64
|
+
<div
|
|
65
|
+
data-template-demo={templateId}
|
|
66
|
+
data-template-demo-page={Page ? pageNumber : undefined}
|
|
67
|
+
data-template-demo-total={pages.length || undefined}
|
|
68
|
+
className="h-screen w-screen overflow-hidden bg-black"
|
|
69
|
+
>
|
|
70
|
+
{demo && Page ? (
|
|
71
|
+
<SlideCanvas flat freezeMotion design={design}>
|
|
72
|
+
<SlidePageProvider index={pageNumber - 1} total={pages.length}>
|
|
73
|
+
<Page />
|
|
74
|
+
</SlidePageProvider>
|
|
75
|
+
</SlideCanvas>
|
|
76
|
+
) : null}
|
|
77
|
+
</div>
|
|
78
|
+
);
|
|
79
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import type { DesignSystem } from '../../lib/design';
|
|
3
|
+
import { applyKnobs, knobFlags } from './knobs';
|
|
4
|
+
import type { TemplateKnobs } from './model';
|
|
5
|
+
|
|
6
|
+
const design: DesignSystem = {
|
|
7
|
+
palette: { bg: '#FFFFFF', text: '#111111', accent: '#AA0000' },
|
|
8
|
+
fonts: { display: 'Display Sans', body: 'Body Sans' },
|
|
9
|
+
typeScale: { hero: 400, body: 30 },
|
|
10
|
+
radius: 0,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const knobs: TemplateKnobs = {
|
|
14
|
+
formal: {
|
|
15
|
+
left: { label: '正式', design: { fonts: { display: 'Songti SC' }, radius: 0 } },
|
|
16
|
+
right: { label: '活泼', design: { fonts: { display: 'PingFang SC' }, radius: 12 } },
|
|
17
|
+
},
|
|
18
|
+
bright: {
|
|
19
|
+
left: { label: '素', design: { palette: { accent: '#333333' } } },
|
|
20
|
+
right: { label: '亮', design: { palette: { accent: '#FF6600' } } },
|
|
21
|
+
},
|
|
22
|
+
motion: {
|
|
23
|
+
left: { label: '安静', flags: { motion: 'still' } },
|
|
24
|
+
right: { label: '活跃', flags: { motion: 'lively' } },
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
describe('applyKnobs', () => {
|
|
29
|
+
it('uses the left and right formal ends and keeps the template design in the middle', () => {
|
|
30
|
+
expect(applyKnobs(design, knobs, { formal: 0.2 })).toMatchObject({
|
|
31
|
+
fonts: { display: 'Songti SC' },
|
|
32
|
+
radius: 0,
|
|
33
|
+
});
|
|
34
|
+
expect(applyKnobs(design, knobs, { formal: 0.5 })).toEqual(design);
|
|
35
|
+
expect(applyKnobs(design, knobs, { formal: 0.8 })).toMatchObject({
|
|
36
|
+
fonts: { display: 'PingFang SC' },
|
|
37
|
+
radius: 12,
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('uses the left and right bright ends and keeps the template design in the middle', () => {
|
|
42
|
+
expect(applyKnobs(design, knobs, { bright: 0.2 }).palette.accent).toBe('#333333');
|
|
43
|
+
expect(applyKnobs(design, knobs, { bright: 0.5 })).toEqual(design);
|
|
44
|
+
expect(applyKnobs(design, knobs, { bright: 0.8 }).palette.accent).toBe('#FF6600');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('uses the left and right motion ends through the flags', () => {
|
|
48
|
+
expect(knobFlags(knobs, { motion: 0.2 })).toEqual({ motion: 'still' });
|
|
49
|
+
expect(knobFlags(knobs, { motion: 0.5 })).toEqual({});
|
|
50
|
+
expect(knobFlags(knobs, { motion: 0.8 })).toEqual({ motion: 'lively' });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('leaves a group the template does not define alone', () => {
|
|
54
|
+
const partial: Partial<TemplateKnobs> = { formal: knobs.formal, motion: knobs.motion };
|
|
55
|
+
expect(applyKnobs(design, partial, { bright: 0.9 })).toEqual(design);
|
|
56
|
+
expect(knobFlags(partial, { bright: 0.9 })).toEqual({});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('treats a missing value as the middle', () => {
|
|
60
|
+
expect(applyKnobs(design, knobs)).toEqual(design);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { DesignSystem } from '../../lib/design.ts';
|
|
2
|
+
import type {
|
|
3
|
+
DesignOverrides,
|
|
4
|
+
TemplateKnob,
|
|
5
|
+
TemplateKnobEnd,
|
|
6
|
+
TemplateKnobs,
|
|
7
|
+
TemplateKnobValues,
|
|
8
|
+
} from './model.ts';
|
|
9
|
+
|
|
10
|
+
const KNOB_KEYS = ['formal', 'bright', 'motion'] as const;
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Values under a third lean left, over two thirds lean right; the middle keeps
|
|
14
|
+
* the template's own design. Discrete ends keep a deck's colours reproducible.
|
|
15
|
+
*/
|
|
16
|
+
const LEFT_UNTIL = 0.34;
|
|
17
|
+
const RIGHT_FROM = 0.66;
|
|
18
|
+
|
|
19
|
+
function knobEnd(
|
|
20
|
+
knob: TemplateKnob | undefined,
|
|
21
|
+
value: number | undefined,
|
|
22
|
+
): TemplateKnobEnd | null {
|
|
23
|
+
if (!knob || value === undefined) return null;
|
|
24
|
+
if (value <= LEFT_UNTIL) return knob.left;
|
|
25
|
+
if (value >= RIGHT_FROM) return knob.right;
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function mergeOverrides(design: DesignSystem, overrides: DesignOverrides): DesignSystem {
|
|
30
|
+
return {
|
|
31
|
+
palette: { ...design.palette, ...overrides.palette },
|
|
32
|
+
fonts: { ...design.fonts, ...overrides.fonts },
|
|
33
|
+
typeScale: { ...design.typeScale, ...overrides.typeScale },
|
|
34
|
+
radius: overrides.radius ?? design.radius,
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A template that does not define a group keeps its own design for that group. */
|
|
39
|
+
export function applyKnobs(
|
|
40
|
+
design: DesignSystem,
|
|
41
|
+
knobs: Partial<TemplateKnobs>,
|
|
42
|
+
values: TemplateKnobValues = {},
|
|
43
|
+
): DesignSystem {
|
|
44
|
+
let out = design;
|
|
45
|
+
for (const key of KNOB_KEYS) {
|
|
46
|
+
const end = knobEnd(knobs[key], values[key]);
|
|
47
|
+
if (end?.design) out = mergeOverrides(out, end.design);
|
|
48
|
+
}
|
|
49
|
+
return out;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function knobFlags(
|
|
53
|
+
knobs: Partial<TemplateKnobs>,
|
|
54
|
+
values: TemplateKnobValues = {},
|
|
55
|
+
): Record<string, string | number | boolean> {
|
|
56
|
+
const flags: Record<string, string | number | boolean> = {};
|
|
57
|
+
for (const key of KNOB_KEYS) {
|
|
58
|
+
const end = knobEnd(knobs[key], values[key]);
|
|
59
|
+
if (end?.flags) Object.assign(flags, end.flags);
|
|
60
|
+
}
|
|
61
|
+
return flags;
|
|
62
|
+
}
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import { useNavigate } from 'react-router-dom';
|
|
3
|
+
import { Button } from '@/components/ui/button';
|
|
4
|
+
import {
|
|
5
|
+
Dialog,
|
|
6
|
+
DialogContent,
|
|
7
|
+
DialogDescription,
|
|
8
|
+
DialogFooter,
|
|
9
|
+
DialogHeader,
|
|
10
|
+
DialogTitle,
|
|
11
|
+
} from '@/components/ui/dialog';
|
|
12
|
+
import { format, useLocale } from '@/lib/use-locale';
|
|
13
|
+
import { cn } from '@/lib/utils';
|
|
14
|
+
import { SlideCanvas } from '../../components/slide-canvas';
|
|
15
|
+
import { SlidePageProvider } from '../../lib/page-context';
|
|
16
|
+
import { FilterPill } from '../chrome/filter-pill';
|
|
17
|
+
import { LemonEmpty } from '../feedback/lemon-empty';
|
|
18
|
+
import { useLrText } from '../text';
|
|
19
|
+
import {
|
|
20
|
+
loadTemplateDemo,
|
|
21
|
+
loadTemplatePreview,
|
|
22
|
+
type TemplateDemoModule,
|
|
23
|
+
type TemplateMeta,
|
|
24
|
+
type TemplatePreviewModule,
|
|
25
|
+
} from './client';
|
|
26
|
+
import type { OccasionId } from './model';
|
|
27
|
+
import { useTemplateLibrary } from './use-library';
|
|
28
|
+
|
|
29
|
+
export function TemplatesPage() {
|
|
30
|
+
const lr = useLrText();
|
|
31
|
+
const library = useTemplateLibrary();
|
|
32
|
+
const [occasion, setOccasion] = useState<OccasionId | null>(null);
|
|
33
|
+
const [open, setOpen] = useState<TemplateMeta | null>(null);
|
|
34
|
+
|
|
35
|
+
if (library && !library.available) {
|
|
36
|
+
return <LemonEmpty title={lr.templates.emptyTitle}>{lr.templates.emptyHint}</LemonEmpty>;
|
|
37
|
+
}
|
|
38
|
+
if (!library) return null;
|
|
39
|
+
|
|
40
|
+
const used = library.occasions.filter((entry) =>
|
|
41
|
+
library.templates.some((template) => template.occasions.includes(entry.id)),
|
|
42
|
+
);
|
|
43
|
+
const visible = occasion
|
|
44
|
+
? library.templates.filter((template) => template.occasions.includes(occasion))
|
|
45
|
+
: library.templates;
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<div data-lr-templates>
|
|
49
|
+
<header className="mb-5">
|
|
50
|
+
<h1 className="font-heading text-[28px] font-bold leading-[34px] tracking-[-0.01em]">
|
|
51
|
+
{lr.templates.title}
|
|
52
|
+
</h1>
|
|
53
|
+
<p className="lr-on-lime mt-0.5 text-[14px] text-muted-foreground">
|
|
54
|
+
{lr.templates.subtitle}
|
|
55
|
+
</p>
|
|
56
|
+
</header>
|
|
57
|
+
|
|
58
|
+
<div
|
|
59
|
+
role="radiogroup"
|
|
60
|
+
aria-label={lr.templates.occasions}
|
|
61
|
+
className="mb-5 flex flex-wrap items-center gap-2"
|
|
62
|
+
>
|
|
63
|
+
<FilterPill
|
|
64
|
+
label={lr.templates.all}
|
|
65
|
+
active={occasion === null}
|
|
66
|
+
onSelect={() => setOccasion(null)}
|
|
67
|
+
/>
|
|
68
|
+
{used.map((entry) => (
|
|
69
|
+
<FilterPill
|
|
70
|
+
key={entry.id}
|
|
71
|
+
label={entry.name}
|
|
72
|
+
active={occasion === entry.id}
|
|
73
|
+
onSelect={() => setOccasion(entry.id)}
|
|
74
|
+
/>
|
|
75
|
+
))}
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
<ul className="grid grid-cols-[repeat(auto-fill,minmax(240px,1fr))] gap-5">
|
|
79
|
+
{visible.map((template) => (
|
|
80
|
+
<li key={template.id}>
|
|
81
|
+
<TemplateCard template={template} onOpen={() => setOpen(template)} />
|
|
82
|
+
</li>
|
|
83
|
+
))}
|
|
84
|
+
</ul>
|
|
85
|
+
|
|
86
|
+
{open && (
|
|
87
|
+
<TemplateDialog
|
|
88
|
+
template={open}
|
|
89
|
+
occasions={library.occasions}
|
|
90
|
+
onClose={() => setOpen(null)}
|
|
91
|
+
/>
|
|
92
|
+
)}
|
|
93
|
+
</div>
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function TemplateCard({ template, onOpen }: { template: TemplateMeta; onOpen: () => void }) {
|
|
98
|
+
const lr = useLrText();
|
|
99
|
+
return (
|
|
100
|
+
<button
|
|
101
|
+
type="button"
|
|
102
|
+
onClick={onOpen}
|
|
103
|
+
data-lr-template={template.id}
|
|
104
|
+
className={cn(
|
|
105
|
+
'group block w-full overflow-hidden rounded-[16px] border border-border bg-card text-left shadow-[var(--lr-shadow-1)]',
|
|
106
|
+
'motion-safe:transition-[translate,box-shadow] motion-safe:duration-[160ms] hover:-translate-y-0.5 hover:shadow-[var(--lr-shadow-2)]',
|
|
107
|
+
'outline-none focus-visible:ring-2 focus-visible:ring-ring/40',
|
|
108
|
+
)}
|
|
109
|
+
>
|
|
110
|
+
<div className="aspect-video overflow-hidden border-b border-border bg-white">
|
|
111
|
+
<CoverCanvas template={template} />
|
|
112
|
+
</div>
|
|
113
|
+
<div className="px-4 py-3">
|
|
114
|
+
<h3 className="truncate text-[14px] font-semibold leading-5 text-foreground">
|
|
115
|
+
{template.name}
|
|
116
|
+
</h3>
|
|
117
|
+
<p className="mt-0.5 truncate text-[12px] leading-4 text-muted-foreground">
|
|
118
|
+
{format(lr.templates.pages, { n: template.pages })} · {template.reason}
|
|
119
|
+
</p>
|
|
120
|
+
</div>
|
|
121
|
+
</button>
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function CoverCanvas({ template }: { template: TemplateMeta }) {
|
|
126
|
+
const [preview, setPreview] = useState<TemplatePreviewModule | null>(null);
|
|
127
|
+
|
|
128
|
+
useEffect(() => {
|
|
129
|
+
let cancelled = false;
|
|
130
|
+
loadTemplatePreview(template.id)
|
|
131
|
+
.then((module) => {
|
|
132
|
+
if (!cancelled) setPreview(module);
|
|
133
|
+
})
|
|
134
|
+
.catch(() => {});
|
|
135
|
+
return () => {
|
|
136
|
+
cancelled = true;
|
|
137
|
+
};
|
|
138
|
+
}, [template.id]);
|
|
139
|
+
|
|
140
|
+
const Cover = preview?.CoverPreview;
|
|
141
|
+
if (!Cover) return <span className="lr-skeleton block h-full w-full" />;
|
|
142
|
+
return (
|
|
143
|
+
<SlideCanvas flat freezeMotion design={template.design}>
|
|
144
|
+
<SlidePageProvider index={0} total={1}>
|
|
145
|
+
<Cover title={template.name} subtitle={template.object} meta={template.audience} />
|
|
146
|
+
</SlidePageProvider>
|
|
147
|
+
</SlideCanvas>
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** The four sample pages the dialog offers; 1, 2, the middle and the second to last. */
|
|
152
|
+
function previewIndexes(template: TemplateMeta): number[] {
|
|
153
|
+
const total = Math.max(template.pages, 1);
|
|
154
|
+
const clamp = (n: number) => Math.min(total - 1, Math.max(0, n));
|
|
155
|
+
if (template.previewPages && template.previewPages.length > 0) {
|
|
156
|
+
return template.previewPages.slice(0, 4).map((n) => clamp(n - 1));
|
|
157
|
+
}
|
|
158
|
+
return [0, 1, Math.floor((total - 1) / 2), total - 2].map(clamp);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
function DemoCanvas({
|
|
162
|
+
template,
|
|
163
|
+
demo,
|
|
164
|
+
page,
|
|
165
|
+
}: {
|
|
166
|
+
template: TemplateMeta;
|
|
167
|
+
demo: TemplateDemoModule;
|
|
168
|
+
page: number;
|
|
169
|
+
}) {
|
|
170
|
+
const Page = demo.default[page];
|
|
171
|
+
if (!Page) return null;
|
|
172
|
+
return (
|
|
173
|
+
<SlideCanvas flat freezeMotion design={demo.design ?? template.design}>
|
|
174
|
+
<SlidePageProvider index={page} total={demo.default.length}>
|
|
175
|
+
<Page />
|
|
176
|
+
</SlidePageProvider>
|
|
177
|
+
</SlideCanvas>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function TemplateDialog({
|
|
182
|
+
template,
|
|
183
|
+
occasions,
|
|
184
|
+
onClose,
|
|
185
|
+
}: {
|
|
186
|
+
template: TemplateMeta;
|
|
187
|
+
occasions: { id: string; name: string }[];
|
|
188
|
+
onClose: () => void;
|
|
189
|
+
}) {
|
|
190
|
+
const lr = useLrText();
|
|
191
|
+
const locale = useLocale();
|
|
192
|
+
const navigate = useNavigate();
|
|
193
|
+
const [demo, setDemo] = useState<TemplateDemoModule | null>(null);
|
|
194
|
+
const [active, setActive] = useState(0);
|
|
195
|
+
const indexes = useMemo(() => previewIndexes(template), [template]);
|
|
196
|
+
|
|
197
|
+
useEffect(() => {
|
|
198
|
+
let cancelled = false;
|
|
199
|
+
loadTemplateDemo(template.id)
|
|
200
|
+
.then((module) => {
|
|
201
|
+
if (!cancelled) setDemo(module);
|
|
202
|
+
})
|
|
203
|
+
.catch(() => {});
|
|
204
|
+
return () => {
|
|
205
|
+
cancelled = true;
|
|
206
|
+
};
|
|
207
|
+
}, [template.id]);
|
|
208
|
+
|
|
209
|
+
const nameOf = (id: string) => occasions.find((entry) => entry.id === id)?.name ?? id;
|
|
210
|
+
|
|
211
|
+
return (
|
|
212
|
+
<Dialog open onOpenChange={(next) => !next && onClose()}>
|
|
213
|
+
<DialogContent className="sm:max-w-[960px]">
|
|
214
|
+
<DialogHeader>
|
|
215
|
+
<DialogTitle>{template.name}</DialogTitle>
|
|
216
|
+
<DialogDescription>
|
|
217
|
+
{format(lr.templates.pages, { n: template.pages })} · {template.reason}
|
|
218
|
+
</DialogDescription>
|
|
219
|
+
</DialogHeader>
|
|
220
|
+
|
|
221
|
+
<div className="grid gap-5 md:grid-cols-[minmax(0,3fr)_minmax(0,2fr)]">
|
|
222
|
+
<div className="min-w-0">
|
|
223
|
+
<div
|
|
224
|
+
data-lr-preview-main={indexes[active] + 1}
|
|
225
|
+
className="aspect-video overflow-hidden rounded-[10px] border border-border bg-white"
|
|
226
|
+
>
|
|
227
|
+
{demo ? (
|
|
228
|
+
<DemoCanvas template={template} demo={demo} page={indexes[active] ?? 0} />
|
|
229
|
+
) : (
|
|
230
|
+
<span className="lr-skeleton block h-full w-full" />
|
|
231
|
+
)}
|
|
232
|
+
</div>
|
|
233
|
+
<div className="mt-2 grid grid-cols-4 gap-2">
|
|
234
|
+
{indexes.map((page, i) => (
|
|
235
|
+
<button
|
|
236
|
+
key={page}
|
|
237
|
+
type="button"
|
|
238
|
+
aria-label={`${lr.templates.previews} ${i + 1}`}
|
|
239
|
+
aria-pressed={i === active}
|
|
240
|
+
data-lr-preview-thumb={page + 1}
|
|
241
|
+
onClick={() => setActive(i)}
|
|
242
|
+
className={cn(
|
|
243
|
+
'aspect-video overflow-hidden rounded-[6px] border bg-white outline-none transition-colors',
|
|
244
|
+
i === active
|
|
245
|
+
? 'border-[var(--lr-focus)]'
|
|
246
|
+
: 'border-border hover:border-[var(--lr-text-3)]',
|
|
247
|
+
)}
|
|
248
|
+
>
|
|
249
|
+
{demo ? <DemoCanvas template={template} demo={demo} page={page} /> : null}
|
|
250
|
+
</button>
|
|
251
|
+
))}
|
|
252
|
+
</div>
|
|
253
|
+
</div>
|
|
254
|
+
|
|
255
|
+
<dl className="space-y-4 text-[13px] leading-snug">
|
|
256
|
+
<div>
|
|
257
|
+
<dt className="text-muted-foreground">{lr.templates.occasions}</dt>
|
|
258
|
+
<dd className="mt-1 font-medium">
|
|
259
|
+
{template.occasions.map(nameOf).join(locale.id.startsWith('zh') ? '、' : ', ')}
|
|
260
|
+
</dd>
|
|
261
|
+
</div>
|
|
262
|
+
<div>
|
|
263
|
+
<dt className="text-muted-foreground">{lr.templates.audience}</dt>
|
|
264
|
+
<dd className="mt-1 font-medium">{template.audience}</dd>
|
|
265
|
+
</div>
|
|
266
|
+
<div>
|
|
267
|
+
<dt className="text-muted-foreground">{lr.templates.object}</dt>
|
|
268
|
+
<dd className="mt-1 font-medium">{template.object}</dd>
|
|
269
|
+
</div>
|
|
270
|
+
<div>
|
|
271
|
+
<dt className="text-muted-foreground">{lr.templates.accent}</dt>
|
|
272
|
+
<dd className="mt-1 flex items-start gap-2 font-medium">
|
|
273
|
+
<span
|
|
274
|
+
aria-hidden
|
|
275
|
+
className="mt-0.5 size-3.5 shrink-0 rounded-[3px] border border-border"
|
|
276
|
+
style={{ background: template.design.palette.accent }}
|
|
277
|
+
/>
|
|
278
|
+
<span>{template.accent}</span>
|
|
279
|
+
</dd>
|
|
280
|
+
</div>
|
|
281
|
+
</dl>
|
|
282
|
+
</div>
|
|
283
|
+
|
|
284
|
+
<DialogFooter>
|
|
285
|
+
<Button type="button" onClick={() => navigate(`/new?template=${template.id}`)}>
|
|
286
|
+
{lr.templates.create}
|
|
287
|
+
</Button>
|
|
288
|
+
</DialogFooter>
|
|
289
|
+
</DialogContent>
|
|
290
|
+
</Dialog>
|
|
291
|
+
);
|
|
292
|
+
}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
applyKnobs,
|
|
4
|
+
designSnippet,
|
|
5
|
+
knobFlags,
|
|
6
|
+
sanitizeAppliedTemplate,
|
|
7
|
+
sanitizeKnobValues,
|
|
8
|
+
sanitizeTemplate,
|
|
9
|
+
} from './model.ts';
|
|
10
|
+
|
|
11
|
+
const design = {
|
|
12
|
+
palette: { bg: '#f4f1ea', text: '#1a1a1a', accent: '#d9480f' },
|
|
13
|
+
fonts: { display: '"Songti SC", serif', body: '"PingFang SC", sans-serif' },
|
|
14
|
+
typeScale: { hero: 420, body: 30 },
|
|
15
|
+
radius: 0,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const knob = (label: string) => ({
|
|
19
|
+
left: { label: `${label}左`, design: { palette: { accent: '#2244aa' } } },
|
|
20
|
+
right: { label: `${label}右`, flags: { motion: 'lively' } },
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const raw = () => ({
|
|
24
|
+
id: 'board-report',
|
|
25
|
+
name: '董事会报告',
|
|
26
|
+
occasions: ['report', 'review'],
|
|
27
|
+
audience: '董事会成员与高管',
|
|
28
|
+
object: '正式董事会报告',
|
|
29
|
+
reason: '数字和审批一目了然',
|
|
30
|
+
accent: '最新值与计划的差额',
|
|
31
|
+
design,
|
|
32
|
+
knobs: { formal: knob('正式'), bright: knob('亮'), motion: knob('动效') },
|
|
33
|
+
skeletons: ['cover', 'overview', 'ask', 'end'],
|
|
34
|
+
fonts: [],
|
|
35
|
+
source: 'northfold',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('sanitizeTemplate', () => {
|
|
39
|
+
it('accepts a complete template and trims its text', () => {
|
|
40
|
+
const input = raw();
|
|
41
|
+
input.name = ' 董事会报告 ';
|
|
42
|
+
const read = sanitizeTemplate(input, 'board-report');
|
|
43
|
+
expect(read.ok).toBe(true);
|
|
44
|
+
if (!read.ok) return;
|
|
45
|
+
expect(read.template.name).toBe('董事会报告');
|
|
46
|
+
expect(read.template.occasions).toEqual(['report', 'review']);
|
|
47
|
+
expect(read.template.source).toBe('northfold');
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('drops a template without occasions', () => {
|
|
51
|
+
const input: Record<string, unknown> = raw();
|
|
52
|
+
delete input.occasions;
|
|
53
|
+
const read = sanitizeTemplate(input, 'board-report');
|
|
54
|
+
expect(read).toEqual({ ok: false, reason: 'missing occasions' });
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('drops an empty occasions list', () => {
|
|
58
|
+
const read = sanitizeTemplate({ ...raw(), occasions: [] }, 'board-report');
|
|
59
|
+
expect(read.ok).toBe(false);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('drops an occasion outside the seven', () => {
|
|
63
|
+
const read = sanitizeTemplate({ ...raw(), occasions: ['pitch', 'wedding'] }, 'board-report');
|
|
64
|
+
expect(read).toEqual({ ok: false, reason: 'unknown occasion "wedding"' });
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('drops an unknown skeleton', () => {
|
|
68
|
+
const read = sanitizeTemplate({ ...raw(), skeletons: ['cover', 'carousel'] }, 'board-report');
|
|
69
|
+
expect(read).toEqual({ ok: false, reason: 'unknown skeleton "carousel"' });
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('drops an id that disagrees with its folder', () => {
|
|
73
|
+
const read = sanitizeTemplate(raw(), 'other-folder');
|
|
74
|
+
expect(read.ok).toBe(false);
|
|
75
|
+
if (read.ok) return;
|
|
76
|
+
expect(read.reason).toContain('does not match the folder');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('drops an id with path characters', () => {
|
|
80
|
+
const read = sanitizeTemplate({ ...raw(), id: '../escape' }, '../escape');
|
|
81
|
+
expect(read.ok).toBe(false);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('drops a design missing an accent colour', () => {
|
|
85
|
+
const read = sanitizeTemplate(
|
|
86
|
+
{ ...raw(), design: { ...design, palette: { bg: '#fff', text: '#000' } } },
|
|
87
|
+
'board-report',
|
|
88
|
+
);
|
|
89
|
+
expect(read).toEqual({ ok: false, reason: 'missing or malformed design' });
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('drops knobs missing one of the three', () => {
|
|
93
|
+
const knobs = raw().knobs as Record<string, unknown>;
|
|
94
|
+
const read = sanitizeTemplate(
|
|
95
|
+
{ ...raw(), knobs: { formal: knobs.formal, bright: knobs.bright } },
|
|
96
|
+
'board-report',
|
|
97
|
+
);
|
|
98
|
+
expect(read).toEqual({ ok: false, reason: 'missing or malformed knobs' });
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it('treats an absent source as null', () => {
|
|
102
|
+
const input: Record<string, unknown> = raw();
|
|
103
|
+
delete input.source;
|
|
104
|
+
const read = sanitizeTemplate(input, 'board-report');
|
|
105
|
+
expect(read.ok).toBe(true);
|
|
106
|
+
if (read.ok) expect(read.template.source).toBeNull();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('reads font licence pairs', () => {
|
|
110
|
+
const read = sanitizeTemplate(
|
|
111
|
+
{
|
|
112
|
+
...raw(),
|
|
113
|
+
fonts: [{ file: 'fonts/Pixel.ttf', license: 'fonts/OFL.txt' }],
|
|
114
|
+
},
|
|
115
|
+
'board-report',
|
|
116
|
+
);
|
|
117
|
+
expect(read.ok).toBe(true);
|
|
118
|
+
if (read.ok) expect(read.template.fonts).toHaveLength(1);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('rejects a font entry without a licence', () => {
|
|
122
|
+
const read = sanitizeTemplate(
|
|
123
|
+
{ ...raw(), fonts: [{ file: 'fonts/Pixel.ttf' }] },
|
|
124
|
+
'board-report',
|
|
125
|
+
);
|
|
126
|
+
expect(read.ok).toBe(false);
|
|
127
|
+
});
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
describe('knobs', () => {
|
|
131
|
+
const read = sanitizeTemplate(raw(), 'board-report');
|
|
132
|
+
if (!read.ok) throw new Error('fixture template is invalid');
|
|
133
|
+
|
|
134
|
+
it('keeps the base design in the middle', () => {
|
|
135
|
+
expect(applyKnobs(read.template.design, read.template.knobs, { formal: 0.5 })).toEqual(design);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it('leans left below a third', () => {
|
|
139
|
+
const out = applyKnobs(read.template.design, read.template.knobs, { formal: 0.1 });
|
|
140
|
+
expect(out.palette.accent).toBe('#2244aa');
|
|
141
|
+
expect(out.palette.bg).toBe(design.palette.bg);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('leans right above two thirds and reports its flags', () => {
|
|
145
|
+
const out = applyKnobs(read.template.design, read.template.knobs, { motion: 0.9 });
|
|
146
|
+
expect(out.palette.accent).toBe(design.palette.accent);
|
|
147
|
+
expect(knobFlags(read.template.knobs, { motion: 0.9 })).toEqual({ motion: 'lively' });
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('keeps knob values inside [0, 1]', () => {
|
|
151
|
+
expect(sanitizeKnobValues({ formal: 2, bright: -0.2, motion: 0.4 })).toEqual({
|
|
152
|
+
motion: 0.4,
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
describe('applied record', () => {
|
|
158
|
+
it('reads back what the board stores', () => {
|
|
159
|
+
expect(
|
|
160
|
+
sanitizeAppliedTemplate({ id: 'board-report', knobs: { formal: 0.8 }, appliedAt: 12 }),
|
|
161
|
+
).toEqual({ id: 'board-report', knobs: { formal: 0.8 }, appliedAt: 12 });
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it('drops a record without a template id', () => {
|
|
165
|
+
expect(sanitizeAppliedTemplate({ knobs: {}, appliedAt: 12 })).toBeNull();
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
describe('designSnippet', () => {
|
|
170
|
+
it('writes a design constant the deck can paste', () => {
|
|
171
|
+
const snippet = designSnippet(design);
|
|
172
|
+
expect(snippet.startsWith('export const design: DesignSystem = {')).toBe(true);
|
|
173
|
+
expect(snippet).toContain('"accent": "#d9480f"');
|
|
174
|
+
});
|
|
175
|
+
});
|