@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
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
import { Workflow } from 'lucide-react';
|
|
2
|
-
import { useEffect } from 'react';
|
|
1
|
+
import { Share2, Workflow } from 'lucide-react';
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
4
|
import { useNavigate } from 'react-router-dom';
|
|
5
5
|
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip';
|
|
6
6
|
import { hasModifier, isTypingTarget } from '@/lib/keys';
|
|
7
7
|
import { cn } from '@/lib/utils';
|
|
8
|
+
import { loadSlide } from '../lib/slides';
|
|
8
9
|
import { useSlot } from './chrome/use-slot';
|
|
9
10
|
import { isFeatureEnabled } from './features';
|
|
10
11
|
import { useNewDeckBrief } from './home/brief';
|
|
11
12
|
import { PendingPages } from './outline/pending-pages';
|
|
13
|
+
import { ShareDialog } from './share/share-dialog';
|
|
12
14
|
import { useLrText } from './text';
|
|
13
15
|
|
|
14
16
|
type Props = {
|
|
@@ -30,10 +32,25 @@ function isInsideOverlay(target: EventTarget | null): boolean {
|
|
|
30
32
|
|
|
31
33
|
export function SlideExtensions({ slideId, overviewOpen }: Props) {
|
|
32
34
|
const enabled = isFeatureEnabled('board');
|
|
35
|
+
const shareOn = isFeatureEnabled('share');
|
|
33
36
|
const navigate = useNavigate();
|
|
34
37
|
const slot = useSlot('data-lr-rail-actions', enabled);
|
|
35
38
|
useNewDeckBrief(slideId);
|
|
36
39
|
const lr = useLrText();
|
|
40
|
+
const [sharing, setSharing] = useState(false);
|
|
41
|
+
const [title, setTitle] = useState(slideId);
|
|
42
|
+
|
|
43
|
+
useEffect(() => {
|
|
44
|
+
let cancelled = false;
|
|
45
|
+
loadSlide(slideId)
|
|
46
|
+
.then((slide) => {
|
|
47
|
+
if (!cancelled && slide.meta?.title) setTitle(slide.meta.title);
|
|
48
|
+
})
|
|
49
|
+
.catch(() => {});
|
|
50
|
+
return () => {
|
|
51
|
+
cancelled = true;
|
|
52
|
+
};
|
|
53
|
+
}, [slideId]);
|
|
37
54
|
|
|
38
55
|
useEffect(() => {
|
|
39
56
|
if (!enabled) return;
|
|
@@ -63,29 +80,58 @@ export function SlideExtensions({ slideId, overviewOpen }: Props) {
|
|
|
63
80
|
<>
|
|
64
81
|
{slot &&
|
|
65
82
|
createPortal(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
<
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
83
|
+
<>
|
|
84
|
+
{shareOn && (
|
|
85
|
+
<Tooltip>
|
|
86
|
+
<TooltipTrigger
|
|
87
|
+
render={
|
|
88
|
+
<button
|
|
89
|
+
type="button"
|
|
90
|
+
onClick={() => setSharing(true)}
|
|
91
|
+
aria-label={lr.share.open}
|
|
92
|
+
data-lr-share-open
|
|
93
|
+
className={cn(
|
|
94
|
+
'flex size-5 items-center justify-center rounded-[3px] text-muted-foreground/70 outline-none',
|
|
95
|
+
'motion-safe:transition-colors hover:bg-muted hover:text-foreground',
|
|
96
|
+
'focus-visible:ring-1 focus-visible:ring-brand',
|
|
97
|
+
)}
|
|
98
|
+
>
|
|
99
|
+
<Share2 className="size-3.5" strokeWidth={1.75} />
|
|
100
|
+
</button>
|
|
101
|
+
}
|
|
102
|
+
/>
|
|
103
|
+
<TooltipContent side="bottom" sideOffset={6}>
|
|
104
|
+
{lr.share.open}
|
|
105
|
+
</TooltipContent>
|
|
106
|
+
</Tooltip>
|
|
107
|
+
)}
|
|
108
|
+
<Tooltip>
|
|
109
|
+
<TooltipTrigger
|
|
110
|
+
render={
|
|
111
|
+
<button
|
|
112
|
+
type="button"
|
|
113
|
+
onClick={() => navigate(`/s/${encodeURIComponent(slideId)}/board`)}
|
|
114
|
+
aria-label={lr.board.openBoard}
|
|
115
|
+
className={cn(
|
|
116
|
+
'flex size-5 items-center justify-center rounded-[3px] text-muted-foreground/70 outline-none',
|
|
117
|
+
'motion-safe:transition-colors hover:bg-muted hover:text-foreground',
|
|
118
|
+
'focus-visible:ring-1 focus-visible:ring-brand',
|
|
119
|
+
)}
|
|
120
|
+
>
|
|
121
|
+
<Workflow className="size-3.5" strokeWidth={1.75} />
|
|
122
|
+
</button>
|
|
123
|
+
}
|
|
124
|
+
/>
|
|
125
|
+
<TooltipContent side="bottom" sideOffset={6}>
|
|
126
|
+
{lr.board.openBoard}
|
|
127
|
+
</TooltipContent>
|
|
128
|
+
</Tooltip>
|
|
129
|
+
</>,
|
|
87
130
|
slot,
|
|
88
131
|
)}
|
|
132
|
+
{shareOn && (
|
|
133
|
+
<ShareDialog open={sharing} slideId={slideId} title={title} onOpenChange={setSharing} />
|
|
134
|
+
)}
|
|
89
135
|
<PendingPages slideId={slideId} />
|
|
90
136
|
</>
|
|
91
137
|
);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
loadTemplateDemo as load,
|
|
3
|
+
loadTemplatePreview as loadPreview,
|
|
4
|
+
templates as raw,
|
|
5
|
+
} from 'virtual:open-slide/templates';
|
|
6
|
+
import type { ReactNode } from 'react';
|
|
7
|
+
import type { DesignSystem } from '../../lib/design';
|
|
8
|
+
import type { Page } from '../../lib/sdk';
|
|
9
|
+
import type { OccasionId, TemplateKnobs } from './model';
|
|
10
|
+
|
|
11
|
+
export type TemplateMeta = {
|
|
12
|
+
id: string;
|
|
13
|
+
name: string;
|
|
14
|
+
occasions: OccasionId[];
|
|
15
|
+
audience: string;
|
|
16
|
+
object: string;
|
|
17
|
+
reason: string;
|
|
18
|
+
accent: string;
|
|
19
|
+
design: DesignSystem;
|
|
20
|
+
knobs: TemplateKnobs;
|
|
21
|
+
skeletons: string[];
|
|
22
|
+
hasDemo: boolean;
|
|
23
|
+
pages: number;
|
|
24
|
+
previewPages: number[] | null;
|
|
25
|
+
minType?: number;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export type TemplateDemoModule = {
|
|
29
|
+
default: Page[];
|
|
30
|
+
design?: DesignSystem;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const templates: TemplateMeta[] = raw;
|
|
34
|
+
|
|
35
|
+
export async function loadTemplateDemo(id: string): Promise<TemplateDemoModule> {
|
|
36
|
+
return load(id);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export type TemplatePreviewModule = {
|
|
40
|
+
/** An empty `brand` or `mark` is left undrawn rather than filled with sample content. */
|
|
41
|
+
CoverPreview: (props: {
|
|
42
|
+
title: string;
|
|
43
|
+
subtitle: string;
|
|
44
|
+
meta: string;
|
|
45
|
+
brand?: string;
|
|
46
|
+
mark?: string;
|
|
47
|
+
}) => ReactNode;
|
|
48
|
+
/** Leaving `value` out makes the template draw its own sample number. */
|
|
49
|
+
DataPreview: (props: {
|
|
50
|
+
title: string;
|
|
51
|
+
value?: string;
|
|
52
|
+
unit?: string;
|
|
53
|
+
caption: string;
|
|
54
|
+
context: string;
|
|
55
|
+
}) => ReactNode;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export async function loadTemplatePreview(id: string): Promise<TemplatePreviewModule> {
|
|
59
|
+
return loadPreview(id) as Promise<TemplatePreviewModule>;
|
|
60
|
+
}
|
|
@@ -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,295 @@
|
|
|
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
|
|
214
|
+
className="sm:max-w-[960px]"
|
|
215
|
+
style={{ maxHeight: '92dvh', gridTemplateRows: 'auto minmax(0, 1fr) auto' }}
|
|
216
|
+
>
|
|
217
|
+
<DialogHeader>
|
|
218
|
+
<DialogTitle>{template.name}</DialogTitle>
|
|
219
|
+
<DialogDescription>
|
|
220
|
+
{format(lr.templates.pages, { n: template.pages })} · {template.reason}
|
|
221
|
+
</DialogDescription>
|
|
222
|
+
</DialogHeader>
|
|
223
|
+
|
|
224
|
+
<div className="grid min-h-0 gap-5 overflow-y-auto md:grid-cols-[minmax(0,3fr)_minmax(0,2fr)]">
|
|
225
|
+
<div className="min-w-0">
|
|
226
|
+
<div
|
|
227
|
+
data-lr-preview-main={indexes[active] + 1}
|
|
228
|
+
className="aspect-video overflow-hidden rounded-[10px] border border-border bg-white"
|
|
229
|
+
>
|
|
230
|
+
{demo ? (
|
|
231
|
+
<DemoCanvas template={template} demo={demo} page={indexes[active] ?? 0} />
|
|
232
|
+
) : (
|
|
233
|
+
<span className="lr-skeleton block h-full w-full" />
|
|
234
|
+
)}
|
|
235
|
+
</div>
|
|
236
|
+
<div className="mt-2 grid grid-cols-4 gap-2">
|
|
237
|
+
{indexes.map((page, i) => (
|
|
238
|
+
<button
|
|
239
|
+
key={page}
|
|
240
|
+
type="button"
|
|
241
|
+
aria-label={`${lr.templates.previews} ${i + 1}`}
|
|
242
|
+
aria-pressed={i === active}
|
|
243
|
+
data-lr-preview-thumb={page + 1}
|
|
244
|
+
onClick={() => setActive(i)}
|
|
245
|
+
className={cn(
|
|
246
|
+
'aspect-video overflow-hidden rounded-[6px] border bg-white outline-none transition-colors',
|
|
247
|
+
i === active
|
|
248
|
+
? 'border-[var(--lr-focus)]'
|
|
249
|
+
: 'border-border hover:border-[var(--lr-text-3)]',
|
|
250
|
+
)}
|
|
251
|
+
>
|
|
252
|
+
{demo ? <DemoCanvas template={template} demo={demo} page={page} /> : null}
|
|
253
|
+
</button>
|
|
254
|
+
))}
|
|
255
|
+
</div>
|
|
256
|
+
</div>
|
|
257
|
+
|
|
258
|
+
<dl className="space-y-4 text-[13px] leading-snug">
|
|
259
|
+
<div>
|
|
260
|
+
<dt className="text-muted-foreground">{lr.templates.occasions}</dt>
|
|
261
|
+
<dd className="mt-1 font-medium">
|
|
262
|
+
{template.occasions.map(nameOf).join(locale.id.startsWith('zh') ? '、' : ', ')}
|
|
263
|
+
</dd>
|
|
264
|
+
</div>
|
|
265
|
+
<div>
|
|
266
|
+
<dt className="text-muted-foreground">{lr.templates.audience}</dt>
|
|
267
|
+
<dd className="mt-1 font-medium">{template.audience}</dd>
|
|
268
|
+
</div>
|
|
269
|
+
<div>
|
|
270
|
+
<dt className="text-muted-foreground">{lr.templates.object}</dt>
|
|
271
|
+
<dd className="mt-1 font-medium">{template.object}</dd>
|
|
272
|
+
</div>
|
|
273
|
+
<div>
|
|
274
|
+
<dt className="text-muted-foreground">{lr.templates.accent}</dt>
|
|
275
|
+
<dd className="mt-1 flex items-start gap-2 font-medium">
|
|
276
|
+
<span
|
|
277
|
+
aria-hidden
|
|
278
|
+
className="mt-0.5 size-3.5 shrink-0 rounded-[3px] border border-border"
|
|
279
|
+
style={{ background: template.design.palette.accent }}
|
|
280
|
+
/>
|
|
281
|
+
<span>{template.accent}</span>
|
|
282
|
+
</dd>
|
|
283
|
+
</div>
|
|
284
|
+
</dl>
|
|
285
|
+
</div>
|
|
286
|
+
|
|
287
|
+
<DialogFooter>
|
|
288
|
+
<Button type="button" onClick={() => navigate(`/new?template=${template.id}`)}>
|
|
289
|
+
{lr.templates.create}
|
|
290
|
+
</Button>
|
|
291
|
+
</DialogFooter>
|
|
292
|
+
</DialogContent>
|
|
293
|
+
</Dialog>
|
|
294
|
+
);
|
|
295
|
+
}
|