@lemonriver/core 0.2.0 → 0.4.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-Df_xwIpg.js → build-Nl7EeJ6x.js} +1 -1
- package/dist/cli/bin.js +4 -4
- package/dist/{config-rMGCkz6i.d.ts → config-CYNOR93W.d.ts} +1 -1
- package/dist/{config-BjWCLoMQ.js → config-CpC0nM3r.js} +3152 -1837
- package/dist/{dev-Ctsx9IeO.js → dev-BB3THd5I.js} +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/locale/index.d.ts +1 -1
- package/dist/locale/index.js +1 -1
- package/dist/{preview-CJgcqsPk.js → preview-BGjgTg7H.js} +1 -1
- package/dist/{types-8VUyA2bu.d.ts → types-tdaXSyah.d.ts} +1 -35
- package/dist/{update-BKOA3Z6o.js → update-DsxZBtwv.js} +2 -70
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +1 -1
- package/dist/{zh-tw-CeLrYwRE.js → zh-tw-DcrDeKxr.js} +11 -172
- package/package.json +1 -1
- package/src/agent/prompt.ts +2 -0
- package/src/app/app.tsx +5 -18
- package/src/app/components/agent/agent-panel.tsx +5 -0
- package/src/app/components/agent/agent-presence.tsx +2 -2
- package/src/app/components/agent/history-view.tsx +3 -2
- package/src/app/components/agent/transcript.tsx +15 -4
- package/src/app/components/asset-view.tsx +6 -6
- package/src/app/components/command/command-menu.tsx +2 -1
- package/src/app/components/inspector/asset-picker-dialog.tsx +7 -5
- package/src/app/components/inspector/comment-layer.tsx +2 -1
- package/src/app/components/inspector/inspector-panel.tsx +2 -2
- package/src/app/components/player.tsx +105 -23
- package/src/app/components/present/curtain.tsx +52 -0
- package/src/app/components/present/last-slide-hint.tsx +36 -0
- package/src/app/components/sidebar/sidebar-footer.tsx +7 -2
- package/src/app/components/sidebar/sidebar.tsx +3 -2
- package/src/app/components/themes/theme-detail.tsx +4 -2
- package/src/app/components/thumbnail-rail.tsx +2 -28
- package/src/app/index.html +2 -2
- package/src/app/lemonriver/agent/lemon.tsx +79 -0
- package/src/app/lemonriver/agent-prefs/prefs.test.ts +173 -0
- package/src/app/lemonriver/agent-prefs/prefs.ts +137 -0
- package/src/app/lemonriver/agent-prefs/use-prefs.ts +36 -0
- package/src/app/{components → lemonriver}/board/board-canvas.tsx +17 -17
- package/src/app/{routes/board.tsx → lemonriver/board/board-page.tsx} +16 -15
- package/src/app/{components → lemonriver}/board/layout.ts +1 -1
- package/src/app/lemonriver/board/model/cards.test.ts +239 -0
- package/src/app/lemonriver/board/model/cards.ts +234 -0
- package/src/app/lemonriver/board/model/structure.test.ts +101 -0
- package/src/app/lemonriver/board/model/structure.ts +82 -0
- package/src/app/{components → lemonriver}/board/page-node.tsx +34 -31
- package/src/app/{components → lemonriver}/board/use-board-cards.ts +6 -6
- package/src/app/{components → lemonriver}/board/use-board-columns.ts +7 -7
- package/src/app/{components → lemonriver}/board/use-page-order.ts +10 -6
- package/src/app/lemonriver/brand/app-icon.svg +44 -0
- package/src/app/lemonriver/brand/apple-touch-icon.png +0 -0
- package/src/app/lemonriver/brand/favicon-32.png +0 -0
- package/src/app/lemonriver/brand/mascot.tsx +145 -0
- package/src/app/lemonriver/brand/mascots/design-done.png +0 -0
- package/src/app/lemonriver/brand/mascots/design-idle.png +0 -0
- package/src/app/lemonriver/brand/mascots/design-needs-you.png +0 -0
- package/src/app/lemonriver/brand/mascots/design-working.png +0 -0
- package/src/app/lemonriver/brand/mascots/lemon-done.png +0 -0
- package/src/app/lemonriver/brand/mascots/lemon-idle.png +0 -0
- package/src/app/lemonriver/brand/mascots/lemon-needs-you.png +0 -0
- package/src/app/lemonriver/brand/mascots/lemon-thinking.png +0 -0
- package/src/app/lemonriver/brand/mascots/lemon-working.png +0 -0
- package/src/app/lemonriver/brand/mascots/outline-done.png +0 -0
- package/src/app/lemonriver/brand/mascots/outline-idle.png +0 -0
- package/src/app/lemonriver/brand/mascots/outline-needs-you.png +0 -0
- package/src/app/lemonriver/brand/mascots/outline-working.png +0 -0
- package/src/app/lemonriver/brand/mascots/research-done.png +0 -0
- package/src/app/lemonriver/brand/mascots/research-idle.png +0 -0
- package/src/app/lemonriver/brand/mascots/research-needs-you.png +0 -0
- package/src/app/lemonriver/brand/mascots/research-working.png +0 -0
- package/src/app/lemonriver/brand/mascots/review-done.png +0 -0
- package/src/app/lemonriver/brand/mascots/review-idle.png +0 -0
- package/src/app/lemonriver/brand/mascots/review-needs-you.png +0 -0
- package/src/app/lemonriver/brand/mascots/review-working.png +0 -0
- package/src/app/lemonriver/chrome/app-chrome.tsx +101 -0
- package/src/app/lemonriver/chrome/nav-row.tsx +34 -0
- package/src/app/lemonriver/chrome/not-found.tsx +34 -0
- package/src/app/lemonriver/chrome/sidebar-extras.tsx +57 -0
- package/src/app/lemonriver/chrome/use-slot.ts +23 -0
- package/src/app/lemonriver/features.test.ts +34 -0
- package/src/app/lemonriver/features.ts +27 -0
- package/src/app/lemonriver/feedback/export.ts +7 -0
- package/src/app/lemonriver/feedback/lemon-empty.tsx +54 -0
- package/src/app/lemonriver/feedback/offline-banner.tsx +41 -0
- package/src/app/lemonriver/feedback/pending-toast.test.ts +44 -0
- package/src/app/lemonriver/feedback/pending-toast.ts +39 -0
- package/src/app/lemonriver/feedback/toaster.tsx +34 -0
- package/src/app/lemonriver/feedback/upload.test.ts +26 -0
- package/src/app/lemonriver/feedback/upload.ts +19 -0
- package/src/app/lemonriver/home/brief-card.tsx +70 -0
- package/src/app/lemonriver/home/brief.test.ts +38 -0
- package/src/app/lemonriver/home/brief.ts +34 -0
- package/src/app/lemonriver/home/controls.tsx +93 -0
- package/src/app/lemonriver/home/deck-card.tsx +183 -0
- package/src/app/lemonriver/home/dialogs.tsx +292 -0
- package/src/app/lemonriver/home/home-page.tsx +339 -0
- package/src/app/lemonriver/home/sorting.test.ts +24 -0
- package/src/app/lemonriver/home/sorting.ts +59 -0
- package/src/app/lemonriver/home/time.test.ts +33 -0
- package/src/app/lemonriver/home/time.ts +33 -0
- package/src/app/lemonriver/home/use-deck-times.ts +27 -0
- package/src/app/lemonriver/home/use-delayed.ts +15 -0
- package/src/app/lemonriver/onboarding/onboarding.tsx +182 -0
- package/src/app/lemonriver/outline/build-team.tsx +278 -0
- package/src/app/lemonriver/outline/describe-page.tsx +380 -0
- package/src/app/lemonriver/outline/files.test.ts +90 -0
- package/src/app/lemonriver/outline/files.ts +69 -0
- package/src/app/lemonriver/outline/model.test.ts +633 -0
- package/src/app/lemonriver/outline/model.ts +443 -0
- package/src/app/lemonriver/outline/outline-page.tsx +504 -0
- package/src/app/lemonriver/outline/pending-pages.tsx +39 -0
- package/src/app/lemonriver/outline/rule.ts +3 -0
- package/src/app/lemonriver/outline/steps.tsx +43 -0
- package/src/app/lemonriver/outline/use-build-driver.ts +258 -0
- package/src/app/lemonriver/routes.test.tsx +37 -0
- package/src/app/lemonriver/routes.tsx +66 -0
- package/src/app/lemonriver/settings/settings-page.tsx +314 -0
- package/src/app/lemonriver/slide-extensions.tsx +80 -0
- package/src/app/lemonriver/text/all.ts +19 -0
- package/src/app/lemonriver/text/en.ts +255 -0
- package/src/app/lemonriver/text/es.ts +256 -0
- package/src/app/lemonriver/text/index.ts +9 -0
- package/src/app/lemonriver/text/ja.ts +256 -0
- package/src/app/lemonriver/text/text.test.ts +90 -0
- package/src/app/lemonriver/text/types.ts +280 -0
- package/src/app/lemonriver/text/zh-cn.ts +247 -0
- package/src/app/lemonriver/text/zh-tw.ts +247 -0
- package/src/app/lemonriver/theme/app.css +299 -0
- package/src/app/lemonriver/theme/controls.css +463 -0
- package/src/app/lemonriver/theme/index.css +3 -0
- package/src/app/lemonriver/theme/motion.ts +52 -0
- package/src/app/lemonriver/theme/pages.test.ts +70 -0
- package/src/app/lemonriver/theme/pages.ts +65 -0
- package/src/app/lemonriver/theme/theme-menu.tsx +64 -0
- package/src/app/lemonriver/theme/themes.test.ts +18 -0
- package/src/app/lemonriver/theme/themes.ts +16 -0
- package/src/app/lemonriver/theme/tokens.css +226 -0
- package/src/app/lemonriver/theme/use-theme.tsx +49 -0
- package/src/app/lemonriver/trash/api.test.ts +19 -0
- package/src/app/lemonriver/trash/api.ts +77 -0
- package/src/app/lemonriver/trash/trash-page.tsx +131 -0
- package/src/app/lemonriver/update/beta-badge.tsx +26 -0
- package/src/app/lemonriver/update/prompt.test.ts +84 -0
- package/src/app/lemonriver/update/prompt.ts +48 -0
- package/src/app/lemonriver/update/update-prompt.tsx +113 -0
- package/src/app/lib/pptx/raster.ts +1 -1
- package/src/app/main.tsx +8 -1
- package/src/app/routes/home-shell.tsx +4 -2
- package/src/app/routes/home.tsx +13 -5
- package/src/app/routes/slide.tsx +81 -28
- package/src/app/styles.css +1 -0
- package/src/locale/en.ts +1 -35
- package/src/locale/es.ts +1 -34
- package/src/locale/ja.ts +1 -34
- package/src/locale/types.ts +1 -36
- package/src/locale/zh-cn.ts +4 -37
- package/src/locale/zh-tw.ts +4 -37
- /package/src/app/{components → lemonriver}/board/board.css +0 -0
- /package/src/app/{components → lemonriver}/board/layout.test.ts +0 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export type SortKey = 'created-desc' | 'created-asc' | 'title-asc' | 'title-desc';
|
|
4
|
+
|
|
5
|
+
export const SORT_KEYS: readonly SortKey[] = [
|
|
6
|
+
'created-desc',
|
|
7
|
+
'created-asc',
|
|
8
|
+
'title-asc',
|
|
9
|
+
'title-desc',
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
// The official home's key, so the order someone picked there carries over.
|
|
13
|
+
const SORT_STORAGE_KEY = 'open-slide:home-sort';
|
|
14
|
+
|
|
15
|
+
function readSortPref(): SortKey {
|
|
16
|
+
try {
|
|
17
|
+
const raw = window.localStorage.getItem(SORT_STORAGE_KEY);
|
|
18
|
+
if (raw && (SORT_KEYS as readonly string[]).includes(raw)) return raw as SortKey;
|
|
19
|
+
} catch {}
|
|
20
|
+
return 'created-desc';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function useSortPref(): [SortKey, (next: SortKey) => void] {
|
|
24
|
+
const [value, setValue] = useState<SortKey>(readSortPref);
|
|
25
|
+
const set = (next: SortKey) => {
|
|
26
|
+
setValue(next);
|
|
27
|
+
try {
|
|
28
|
+
window.localStorage.setItem(SORT_STORAGE_KEY, next);
|
|
29
|
+
} catch {}
|
|
30
|
+
};
|
|
31
|
+
return [value, set];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const TITLE_COLLATOR = new Intl.Collator(undefined, { sensitivity: 'base', numeric: true });
|
|
35
|
+
|
|
36
|
+
export function sortDecks(
|
|
37
|
+
ids: string[],
|
|
38
|
+
key: SortKey,
|
|
39
|
+
titleOf: (id: string) => string,
|
|
40
|
+
createdAt: Record<string, number>,
|
|
41
|
+
): string[] {
|
|
42
|
+
const list = ids.slice();
|
|
43
|
+
if (key === 'title-asc') list.sort((a, b) => TITLE_COLLATOR.compare(titleOf(a), titleOf(b)));
|
|
44
|
+
else if (key === 'title-desc')
|
|
45
|
+
list.sort((a, b) => TITLE_COLLATOR.compare(titleOf(b), titleOf(a)));
|
|
46
|
+
else if (key === 'created-asc') list.sort((a, b) => (createdAt[a] ?? 0) - (createdAt[b] ?? 0));
|
|
47
|
+
else list.sort((a, b) => (createdAt[b] ?? 0) - (createdAt[a] ?? 0));
|
|
48
|
+
return list;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function filterDecks(
|
|
52
|
+
ids: string[],
|
|
53
|
+
query: string,
|
|
54
|
+
titles: Record<string, string>,
|
|
55
|
+
): string[] {
|
|
56
|
+
const q = query.trim().toLowerCase();
|
|
57
|
+
if (!q) return ids;
|
|
58
|
+
return ids.filter((id) => id.toLowerCase().includes(q) || titles[id]?.toLowerCase().includes(q));
|
|
59
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { daysLeft, greetingFor, relativeTime } from './time';
|
|
3
|
+
|
|
4
|
+
const NOW = Date.parse('2026-10-29T12:00:00Z');
|
|
5
|
+
|
|
6
|
+
describe('relativeTime', () => {
|
|
7
|
+
it('picks the largest unit that fits', () => {
|
|
8
|
+
expect(relativeTime(NOW - 3 * 24 * 3600 * 1000, NOW, 'en')).toBe('3 days ago');
|
|
9
|
+
expect(relativeTime(NOW - 24 * 3600 * 1000, NOW, 'en')).toBe('yesterday');
|
|
10
|
+
expect(relativeTime(NOW - 2 * 3600 * 1000, NOW, 'en')).toBe('2 hours ago');
|
|
11
|
+
expect(relativeTime(NOW - 10 * 1000, NOW, 'en')).toBe('now');
|
|
12
|
+
expect(relativeTime(NOW - 3 * 24 * 3600 * 1000, NOW, 'zh-CN')).toBe('3天前');
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('greetingFor', () => {
|
|
17
|
+
it('splits the day at noon and six', () => {
|
|
18
|
+
expect(greetingFor(9)).toBe('morning');
|
|
19
|
+
expect(greetingFor(12)).toBe('afternoon');
|
|
20
|
+
expect(greetingFor(17)).toBe('afternoon');
|
|
21
|
+
expect(greetingFor(18)).toBe('evening');
|
|
22
|
+
expect(greetingFor(2)).toBe('evening');
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe('daysLeft', () => {
|
|
27
|
+
it('rounds up and never shows zero', () => {
|
|
28
|
+
const day = 24 * 3600 * 1000;
|
|
29
|
+
expect(daysLeft(NOW + 29.2 * day, NOW)).toBe(30);
|
|
30
|
+
expect(daysLeft(NOW + day, NOW)).toBe(1);
|
|
31
|
+
expect(daysLeft(NOW + 1000, NOW)).toBe(1);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
const UNITS: [Intl.RelativeTimeFormatUnit, number][] = [
|
|
2
|
+
['year', 365 * 24 * 3600],
|
|
3
|
+
['month', 30 * 24 * 3600],
|
|
4
|
+
['week', 7 * 24 * 3600],
|
|
5
|
+
['day', 24 * 3600],
|
|
6
|
+
['hour', 3600],
|
|
7
|
+
['minute', 60],
|
|
8
|
+
];
|
|
9
|
+
|
|
10
|
+
/** "3 days ago", "yesterday", "now" — in the reader's language. */
|
|
11
|
+
export function relativeTime(ms: number, now: number, locale: string): string {
|
|
12
|
+
const seconds = (ms - now) / 1000;
|
|
13
|
+
const rtf = new Intl.RelativeTimeFormat(locale, { numeric: 'auto' });
|
|
14
|
+
for (const [unit, size] of UNITS) {
|
|
15
|
+
if (Math.abs(seconds) >= size) return rtf.format(Math.round(seconds / size), unit);
|
|
16
|
+
}
|
|
17
|
+
return rtf.format(0, 'second');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type Greeting = 'morning' | 'afternoon' | 'evening';
|
|
21
|
+
|
|
22
|
+
export function greetingFor(hour: number): Greeting {
|
|
23
|
+
if (hour >= 5 && hour < 12) return 'morning';
|
|
24
|
+
if (hour >= 12 && hour < 18) return 'afternoon';
|
|
25
|
+
return 'evening';
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const DAY_MS = 24 * 3600 * 1000;
|
|
29
|
+
|
|
30
|
+
/** Whole days until `expiresAt`, never below 1 while the entry still exists. */
|
|
31
|
+
export function daysLeft(expiresAt: number, now: number): number {
|
|
32
|
+
return Math.max(1, Math.ceil((expiresAt - now) / DAY_MS));
|
|
33
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
export type DeckTimes = Record<string, { modifiedAt: number }>;
|
|
4
|
+
|
|
5
|
+
/** When each deck was last saved. Only the dev server knows; a built site gets nothing. */
|
|
6
|
+
export function useDeckTimes(): DeckTimes {
|
|
7
|
+
const [times, setTimes] = useState<DeckTimes>({});
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
if (!import.meta.env.DEV) return;
|
|
10
|
+
let cancelled = false;
|
|
11
|
+
const load = () =>
|
|
12
|
+
fetch('/__lr/decks')
|
|
13
|
+
.then((res) => (res.ok ? (res.json() as Promise<{ decks: DeckTimes }>) : null))
|
|
14
|
+
.then((data) => {
|
|
15
|
+
if (!cancelled && data) setTimes(data.decks);
|
|
16
|
+
})
|
|
17
|
+
.catch(() => {});
|
|
18
|
+
void load();
|
|
19
|
+
const hot = import.meta.hot;
|
|
20
|
+
hot?.on('open-slide:slide-changed', load);
|
|
21
|
+
return () => {
|
|
22
|
+
cancelled = true;
|
|
23
|
+
hot?.off('open-slide:slide-changed', load);
|
|
24
|
+
};
|
|
25
|
+
}, []);
|
|
26
|
+
return times;
|
|
27
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
/** True once `active` has stayed true for `ms`, so quick loads never flash a skeleton. */
|
|
4
|
+
export function useDelayed(active: boolean, ms = 300): boolean {
|
|
5
|
+
const [shown, setShown] = useState(false);
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
if (!active) {
|
|
8
|
+
setShown(false);
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const timer = setTimeout(() => setShown(true), ms);
|
|
12
|
+
return () => clearTimeout(timer);
|
|
13
|
+
}, [active, ms]);
|
|
14
|
+
return shown;
|
|
15
|
+
}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { Button } from '@/components/ui/button';
|
|
3
|
+
import { Dialog, DialogContent, DialogDescription, DialogTitle } from '@/components/ui/dialog';
|
|
4
|
+
import { format } from '@/lib/use-locale';
|
|
5
|
+
import { cn } from '@/lib/utils';
|
|
6
|
+
import { toneForUses, type UseId } from '../agent-prefs/prefs';
|
|
7
|
+
import { updateAgentPrefs } from '../agent-prefs/use-prefs';
|
|
8
|
+
import { HelperMascot, type HelperRole, Mascot } from '../brand/mascot';
|
|
9
|
+
import { useLrText } from '../text';
|
|
10
|
+
|
|
11
|
+
export const ONBOARDED_KEY = 'lemonriver:onboarded';
|
|
12
|
+
|
|
13
|
+
const STEPS = 3;
|
|
14
|
+
|
|
15
|
+
function isOnboarded(): boolean {
|
|
16
|
+
try {
|
|
17
|
+
return localStorage.getItem(ONBOARDED_KEY) === '1';
|
|
18
|
+
} catch {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function markOnboarded(): void {
|
|
24
|
+
try {
|
|
25
|
+
localStorage.setItem(ONBOARDED_KEY, '1');
|
|
26
|
+
} catch {}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function Onboarding() {
|
|
30
|
+
const lr = useLrText();
|
|
31
|
+
const [open, setOpen] = useState(() => !isOnboarded());
|
|
32
|
+
const [step, setStep] = useState(0);
|
|
33
|
+
const [picked, setPicked] = useState<string[]>([]);
|
|
34
|
+
|
|
35
|
+
function close(withTone: boolean) {
|
|
36
|
+
if (withTone) {
|
|
37
|
+
const tone = toneForUses(picked);
|
|
38
|
+
if (tone) updateAgentPrefs({ tone });
|
|
39
|
+
}
|
|
40
|
+
markOnboarded();
|
|
41
|
+
setOpen(false);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const helpers: { role: HelperRole; name: string; line: string }[] = [
|
|
45
|
+
{ role: 'research', name: lr.build.research, line: lr.onboarding.researchLine },
|
|
46
|
+
{ role: 'outline', name: lr.build.outline, line: lr.onboarding.outlineLine },
|
|
47
|
+
{ role: 'design', name: lr.build.design, line: lr.onboarding.designLine },
|
|
48
|
+
{ role: 'review', name: lr.build.review, line: lr.onboarding.reviewLine },
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const uses: { id: UseId; label: string }[] = [
|
|
52
|
+
{ id: 'report', label: lr.onboarding.useReport },
|
|
53
|
+
{ id: 'pitch', label: lr.onboarding.usePitch },
|
|
54
|
+
{ id: 'lecture', label: lr.onboarding.useLecture },
|
|
55
|
+
{ id: 'launch', label: lr.onboarding.useLaunch },
|
|
56
|
+
{ id: 'training', label: lr.onboarding.useTraining },
|
|
57
|
+
{ id: 'other', label: lr.onboarding.useOther },
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
return (
|
|
61
|
+
<Dialog
|
|
62
|
+
open={open}
|
|
63
|
+
onOpenChange={(next) => {
|
|
64
|
+
if (!next) close(false);
|
|
65
|
+
}}
|
|
66
|
+
>
|
|
67
|
+
<DialogContent data-lr-onboarding="" showCloseButton={false} className="sm:max-w-[520px]">
|
|
68
|
+
{step === 0 && (
|
|
69
|
+
<div
|
|
70
|
+
data-lr-onboarding-step="1"
|
|
71
|
+
className="flex flex-col items-center gap-3 py-2 text-center"
|
|
72
|
+
>
|
|
73
|
+
<Mascot state="idle" size={88} float />
|
|
74
|
+
<DialogTitle className="text-[20px] leading-snug">
|
|
75
|
+
{lr.onboarding.step1Title}
|
|
76
|
+
</DialogTitle>
|
|
77
|
+
<DialogDescription className="max-w-[380px] text-[13.5px] leading-relaxed">
|
|
78
|
+
{lr.onboarding.step1Body}
|
|
79
|
+
</DialogDescription>
|
|
80
|
+
</div>
|
|
81
|
+
)}
|
|
82
|
+
|
|
83
|
+
{step === 1 && (
|
|
84
|
+
<div data-lr-onboarding-step="2">
|
|
85
|
+
<DialogTitle className="text-[18px] leading-snug">
|
|
86
|
+
{lr.onboarding.step2Title}
|
|
87
|
+
</DialogTitle>
|
|
88
|
+
<div className="mt-4 grid grid-cols-2 gap-3">
|
|
89
|
+
{helpers.map((helper) => (
|
|
90
|
+
<div key={helper.role} className="flex items-start gap-2 text-left">
|
|
91
|
+
<HelperMascot role={helper.role} state="idle" size={36} />
|
|
92
|
+
<div className="min-w-0">
|
|
93
|
+
<p className="text-[13px] font-semibold">{helper.name}</p>
|
|
94
|
+
<p className="text-[12px] leading-snug text-muted-foreground">{helper.line}</p>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
))}
|
|
98
|
+
</div>
|
|
99
|
+
</div>
|
|
100
|
+
)}
|
|
101
|
+
|
|
102
|
+
{step === 2 && (
|
|
103
|
+
<div data-lr-onboarding-step="3">
|
|
104
|
+
<DialogTitle className="text-[18px] leading-snug">
|
|
105
|
+
{lr.onboarding.step3Title}
|
|
106
|
+
</DialogTitle>
|
|
107
|
+
<DialogDescription className="mt-1 text-[13px]">
|
|
108
|
+
{lr.onboarding.step3Body}
|
|
109
|
+
</DialogDescription>
|
|
110
|
+
<div className="mt-3 flex flex-wrap gap-1.5">
|
|
111
|
+
{uses.map((use) => {
|
|
112
|
+
const on = picked.includes(use.id);
|
|
113
|
+
return (
|
|
114
|
+
<button
|
|
115
|
+
key={use.id}
|
|
116
|
+
type="button"
|
|
117
|
+
aria-pressed={on}
|
|
118
|
+
onClick={() =>
|
|
119
|
+
setPicked((prev) =>
|
|
120
|
+
on ? prev.filter((id) => id !== use.id) : [...prev, use.id],
|
|
121
|
+
)
|
|
122
|
+
}
|
|
123
|
+
className={cn(
|
|
124
|
+
'h-8 rounded-full border px-3 text-[12.5px] font-medium outline-none transition-colors focus-visible:ring-2 focus-visible:ring-ring/40',
|
|
125
|
+
on
|
|
126
|
+
? 'border-[var(--lr-accent)] bg-[var(--lr-accent-soft)] text-foreground'
|
|
127
|
+
: 'border-border bg-card text-muted-foreground hover:border-[var(--lr-text-3)]',
|
|
128
|
+
)}
|
|
129
|
+
>
|
|
130
|
+
{use.label}
|
|
131
|
+
</button>
|
|
132
|
+
);
|
|
133
|
+
})}
|
|
134
|
+
</div>
|
|
135
|
+
</div>
|
|
136
|
+
)}
|
|
137
|
+
|
|
138
|
+
<div className="mt-1 flex items-center justify-between gap-3">
|
|
139
|
+
{step === 0 ? (
|
|
140
|
+
<Button type="button" variant="ghost" size="sm" onClick={() => close(false)}>
|
|
141
|
+
{lr.onboarding.skip}
|
|
142
|
+
</Button>
|
|
143
|
+
) : (
|
|
144
|
+
<Button
|
|
145
|
+
type="button"
|
|
146
|
+
variant="ghost"
|
|
147
|
+
size="sm"
|
|
148
|
+
onClick={() => setStep((current) => Math.max(0, current - 1))}
|
|
149
|
+
>
|
|
150
|
+
{lr.onboarding.back}
|
|
151
|
+
</Button>
|
|
152
|
+
)}
|
|
153
|
+
|
|
154
|
+
<div className="flex items-center gap-3">
|
|
155
|
+
<div className="flex items-center gap-1.5">
|
|
156
|
+
<span className="sr-only">{format(lr.onboarding.progress, { k: step + 1 })}</span>
|
|
157
|
+
{[0, 1, 2].map((dot) => (
|
|
158
|
+
<span
|
|
159
|
+
key={dot}
|
|
160
|
+
aria-hidden
|
|
161
|
+
className={cn(
|
|
162
|
+
'size-1.5 rounded-full transition-colors',
|
|
163
|
+
dot === step ? 'bg-[var(--lr-focus)]' : 'bg-border',
|
|
164
|
+
)}
|
|
165
|
+
/>
|
|
166
|
+
))}
|
|
167
|
+
</div>
|
|
168
|
+
{step < STEPS - 1 ? (
|
|
169
|
+
<Button type="button" size="sm" onClick={() => setStep((current) => current + 1)}>
|
|
170
|
+
{lr.onboarding.next}
|
|
171
|
+
</Button>
|
|
172
|
+
) : (
|
|
173
|
+
<Button type="button" size="sm" onClick={() => close(true)}>
|
|
174
|
+
{lr.onboarding.start}
|
|
175
|
+
</Button>
|
|
176
|
+
)}
|
|
177
|
+
</div>
|
|
178
|
+
</div>
|
|
179
|
+
</DialogContent>
|
|
180
|
+
</Dialog>
|
|
181
|
+
);
|
|
182
|
+
}
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { toast } from 'sonner';
|
|
3
|
+
import { Button } from '@/components/ui/button';
|
|
4
|
+
import { format, plural } from '@/lib/use-locale';
|
|
5
|
+
import { cn } from '@/lib/utils';
|
|
6
|
+
import {
|
|
7
|
+
HelperMascot,
|
|
8
|
+
type HelperRole,
|
|
9
|
+
type HelperState,
|
|
10
|
+
Mascot,
|
|
11
|
+
type MascotState,
|
|
12
|
+
} from '../brand/mascot';
|
|
13
|
+
import { useLrText } from '../text';
|
|
14
|
+
import { pageAwaitingCheck, teamState } from './model';
|
|
15
|
+
import { useBuildDriver } from './use-build-driver';
|
|
16
|
+
|
|
17
|
+
function basePath(): string {
|
|
18
|
+
return import.meta.env.BASE_URL.replace(/\/$/, '');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function leadMascot(state: ReturnType<typeof teamState>['lead']): MascotState {
|
|
22
|
+
if (state === 'working') return 'working';
|
|
23
|
+
if (state === 'done') return 'done';
|
|
24
|
+
if (state === 'needs-you') return 'needs-you';
|
|
25
|
+
if (state === 'idle') return 'idle';
|
|
26
|
+
return 'thinking';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function helperMascot(state: ReturnType<typeof teamState>['design']): HelperState {
|
|
30
|
+
return state === 'none' ? 'idle' : state;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type Event = { id: number; text: string };
|
|
34
|
+
|
|
35
|
+
function nextEventId(seq: { current: number }): number {
|
|
36
|
+
seq.current += 1;
|
|
37
|
+
return seq.current;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function BuildTeam({ slideId }: { slideId: string }) {
|
|
41
|
+
const lr = useLrText().build;
|
|
42
|
+
const prefsLr = useLrText().prefs;
|
|
43
|
+
const { outline, action, running, waitingForAnswer, connected, pause, resume, undo } =
|
|
44
|
+
useBuildDriver(slideId);
|
|
45
|
+
const [events, setEvents] = useState<Event[]>([]);
|
|
46
|
+
const [hidden, setHidden] = useState(false);
|
|
47
|
+
const previous = useRef<typeof outline>(undefined);
|
|
48
|
+
const eventSeq = useRef(0);
|
|
49
|
+
const toasted = useRef(false);
|
|
50
|
+
|
|
51
|
+
const built = outline?.built ?? 0;
|
|
52
|
+
const total = outline?.items.length ?? 0;
|
|
53
|
+
const state = outline?.state;
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
if (!outline) return;
|
|
57
|
+
const prev = previous.current;
|
|
58
|
+
previous.current = outline;
|
|
59
|
+
if (!prev) return;
|
|
60
|
+
const add: Event[] = [];
|
|
61
|
+
if (outline.built > prev.built) {
|
|
62
|
+
add.push({ id: nextEventId(eventSeq), text: format(lr.eventPage, { k: outline.built }) });
|
|
63
|
+
add.push({ id: nextEventId(eventSeq), text: lr.eventSaved });
|
|
64
|
+
}
|
|
65
|
+
if (prev.stage !== 'review' && outline.stage === 'review') {
|
|
66
|
+
add.push({ id: nextEventId(eventSeq), text: lr.eventReview });
|
|
67
|
+
}
|
|
68
|
+
if (prev.state !== 'built' && outline.state === 'built') {
|
|
69
|
+
add.push({ id: nextEventId(eventSeq), text: lr.eventReviewed });
|
|
70
|
+
}
|
|
71
|
+
if (outline.decisions.length > prev.decisions.length) {
|
|
72
|
+
for (const decision of outline.decisions.slice(prev.decisions.length)) {
|
|
73
|
+
add.push({
|
|
74
|
+
id: nextEventId(eventSeq),
|
|
75
|
+
text: format(prefsLr.decisionEvent, {
|
|
76
|
+
question: decision.question,
|
|
77
|
+
answer: decision.answer,
|
|
78
|
+
}),
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (add.length > 0) setEvents((list) => [...add.reverse(), ...list].slice(0, 6));
|
|
83
|
+
}, [outline, lr, prefsLr]);
|
|
84
|
+
|
|
85
|
+
useEffect(() => {
|
|
86
|
+
if (state !== 'built') {
|
|
87
|
+
setHidden(false);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const left = (outline?.lastTurn?.at ?? 0) + 60_000 - Date.now();
|
|
91
|
+
if (left <= 0) {
|
|
92
|
+
setHidden(true);
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const timer = window.setTimeout(() => setHidden(true), left);
|
|
96
|
+
return () => window.clearTimeout(timer);
|
|
97
|
+
}, [state, outline?.lastTurn?.at]);
|
|
98
|
+
|
|
99
|
+
const runUndo = useCallback(async () => {
|
|
100
|
+
const ok = await undo();
|
|
101
|
+
if (ok) {
|
|
102
|
+
window.location.assign(`${basePath()}/s/${encodeURIComponent(slideId)}/outline`);
|
|
103
|
+
} else {
|
|
104
|
+
toast.error(lr.undoFailed);
|
|
105
|
+
}
|
|
106
|
+
}, [undo, slideId, lr.undoFailed]);
|
|
107
|
+
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
if (state !== 'built' || toasted.current) return;
|
|
110
|
+
toasted.current = true;
|
|
111
|
+
const key = `lr-build-toast:${slideId}`;
|
|
112
|
+
try {
|
|
113
|
+
if (sessionStorage.getItem(key)) return;
|
|
114
|
+
sessionStorage.setItem(key, '1');
|
|
115
|
+
} catch {}
|
|
116
|
+
toast.success(format(lr.done, { n: total }), {
|
|
117
|
+
duration: 10_000,
|
|
118
|
+
action: {
|
|
119
|
+
label: lr.undo,
|
|
120
|
+
onClick: () => void runUndo(),
|
|
121
|
+
},
|
|
122
|
+
});
|
|
123
|
+
}, [state, total, slideId, lr, runUndo]);
|
|
124
|
+
|
|
125
|
+
if (!outline || (state !== 'building' && state !== 'built')) return null;
|
|
126
|
+
if (state === 'built' && hidden) return null;
|
|
127
|
+
|
|
128
|
+
const team = teamState(outline, { running, waitingForAnswer, action });
|
|
129
|
+
const pct = total > 0 ? Math.min(100, Math.round((built / total) * 100)) : 0;
|
|
130
|
+
const check = pageAwaitingCheck(outline);
|
|
131
|
+
const status =
|
|
132
|
+
state === 'built'
|
|
133
|
+
? format(lr.statusDone, { n: total })
|
|
134
|
+
: waitingForAnswer
|
|
135
|
+
? lr.statusWaiting
|
|
136
|
+
: action === 'paused'
|
|
137
|
+
? check !== null
|
|
138
|
+
? format(prefsLr.confirmPage, { k: check })
|
|
139
|
+
: lr.statusPaused
|
|
140
|
+
: action === 'interrupted'
|
|
141
|
+
? lr.statusStopped
|
|
142
|
+
: outline.stage === 'review'
|
|
143
|
+
? lr.statusReview
|
|
144
|
+
: format(lr.statusWorking, { k: Math.min(built + 1, total) });
|
|
145
|
+
|
|
146
|
+
const helpers: {
|
|
147
|
+
role: HelperRole;
|
|
148
|
+
label: string;
|
|
149
|
+
state: ReturnType<typeof teamState>['design'];
|
|
150
|
+
sub: string | null;
|
|
151
|
+
subMuted: boolean;
|
|
152
|
+
}[] = [
|
|
153
|
+
{
|
|
154
|
+
role: 'research',
|
|
155
|
+
label: lr.research,
|
|
156
|
+
state: team.research,
|
|
157
|
+
sub:
|
|
158
|
+
outline.files.length > 0
|
|
159
|
+
? format(plural(outline.files.length, lr.readFiles), { n: outline.files.length })
|
|
160
|
+
: lr.noFiles,
|
|
161
|
+
subMuted: outline.files.length === 0,
|
|
162
|
+
},
|
|
163
|
+
{ role: 'outline', label: lr.outline, state: team.outline, sub: null, subMuted: false },
|
|
164
|
+
{ role: 'design', label: lr.design, state: team.design, sub: null, subMuted: false },
|
|
165
|
+
{ role: 'review', label: lr.review, state: team.review, sub: null, subMuted: false },
|
|
166
|
+
];
|
|
167
|
+
|
|
168
|
+
return (
|
|
169
|
+
<div data-lr-build-team className="border-b border-border/60 px-4 py-3">
|
|
170
|
+
{state === 'building' && action === 'interrupted' && (
|
|
171
|
+
<div
|
|
172
|
+
data-lr-build-interrupted
|
|
173
|
+
className="mb-3 flex items-start gap-2.5 rounded-[10px] border border-border bg-card px-3 py-2.5"
|
|
174
|
+
>
|
|
175
|
+
<Mascot state="needs-you" size={28} />
|
|
176
|
+
<div className="min-w-0 flex-1">
|
|
177
|
+
<p className="text-[12.5px] font-semibold">
|
|
178
|
+
{format(lr.interruptedTitle, { k: Math.min(built + 1, total) })}
|
|
179
|
+
</p>
|
|
180
|
+
<p className="mt-0.5 text-[11.5px] text-muted-foreground">
|
|
181
|
+
{connected
|
|
182
|
+
? built > 0
|
|
183
|
+
? format(lr.interruptedHint, { n: built })
|
|
184
|
+
: null
|
|
185
|
+
: lr.interruptedNoAgent}
|
|
186
|
+
</p>
|
|
187
|
+
<Button
|
|
188
|
+
type="button"
|
|
189
|
+
variant="outline"
|
|
190
|
+
size="xs"
|
|
191
|
+
className="mt-2"
|
|
192
|
+
onClick={() => void resume()}
|
|
193
|
+
>
|
|
194
|
+
{lr.continue}
|
|
195
|
+
</Button>
|
|
196
|
+
</div>
|
|
197
|
+
</div>
|
|
198
|
+
)}
|
|
199
|
+
|
|
200
|
+
<div className="flex items-center gap-2.5">
|
|
201
|
+
<Mascot
|
|
202
|
+
state={leadMascot(team.lead)}
|
|
203
|
+
size={36}
|
|
204
|
+
float={state === 'building' && !running && action !== 'interrupted'}
|
|
205
|
+
/>
|
|
206
|
+
<div className="min-w-0 flex-1">
|
|
207
|
+
<div className="flex items-start justify-between gap-3">
|
|
208
|
+
<p className="min-w-0 text-[13px] leading-snug font-semibold">{status}</p>
|
|
209
|
+
<span className="shrink-0 text-[11.5px] text-muted-foreground tabular-nums">
|
|
210
|
+
{format(lr.progress, { k: built, n: total })}
|
|
211
|
+
</span>
|
|
212
|
+
</div>
|
|
213
|
+
<div className="mt-1.5 h-1 overflow-hidden rounded-full bg-muted">
|
|
214
|
+
<div
|
|
215
|
+
className="h-full rounded-full bg-[var(--lr-focus)] motion-safe:transition-[width] motion-safe:duration-500"
|
|
216
|
+
style={{ width: `${pct}%` }}
|
|
217
|
+
/>
|
|
218
|
+
</div>
|
|
219
|
+
</div>
|
|
220
|
+
{state === 'building' &&
|
|
221
|
+
!waitingForAnswer &&
|
|
222
|
+
action !== 'interrupted' &&
|
|
223
|
+
(outline.paused ? (
|
|
224
|
+
<Button type="button" variant="outline" size="xs" onClick={() => void resume()}>
|
|
225
|
+
{lr.resume}
|
|
226
|
+
</Button>
|
|
227
|
+
) : (
|
|
228
|
+
<Button type="button" variant="ghost" size="xs" onClick={() => void pause()}>
|
|
229
|
+
{lr.pause}
|
|
230
|
+
</Button>
|
|
231
|
+
))}
|
|
232
|
+
</div>
|
|
233
|
+
|
|
234
|
+
<div className="mt-3 grid grid-cols-4 gap-1.5">
|
|
235
|
+
{helpers.map((helper) => (
|
|
236
|
+
<div
|
|
237
|
+
key={helper.role}
|
|
238
|
+
data-lr-helper-tile={helper.role}
|
|
239
|
+
className="flex flex-col items-center gap-0.5 text-center"
|
|
240
|
+
>
|
|
241
|
+
<HelperMascot role={helper.role} state={helperMascot(helper.state)} size={28} />
|
|
242
|
+
<span
|
|
243
|
+
className={cn(
|
|
244
|
+
'text-[11px] leading-tight',
|
|
245
|
+
helper.state === 'idle' || helper.state === 'none'
|
|
246
|
+
? 'text-muted-foreground'
|
|
247
|
+
: 'text-foreground',
|
|
248
|
+
helper.state === 'working' && 'font-semibold',
|
|
249
|
+
)}
|
|
250
|
+
>
|
|
251
|
+
{helper.label}
|
|
252
|
+
</span>
|
|
253
|
+
{helper.sub && (
|
|
254
|
+
<span
|
|
255
|
+
className={cn(
|
|
256
|
+
'text-[10.5px] leading-tight text-muted-foreground',
|
|
257
|
+
helper.subMuted && 'opacity-70',
|
|
258
|
+
)}
|
|
259
|
+
>
|
|
260
|
+
{helper.sub}
|
|
261
|
+
</span>
|
|
262
|
+
)}
|
|
263
|
+
</div>
|
|
264
|
+
))}
|
|
265
|
+
</div>
|
|
266
|
+
|
|
267
|
+
{events.length > 0 && (
|
|
268
|
+
<ul data-lr-build-events className="mt-3 space-y-0.5">
|
|
269
|
+
{events.map((event) => (
|
|
270
|
+
<li key={event.id} className="truncate text-[11px] text-muted-foreground">
|
|
271
|
+
{event.text}
|
|
272
|
+
</li>
|
|
273
|
+
))}
|
|
274
|
+
</ul>
|
|
275
|
+
)}
|
|
276
|
+
</div>
|
|
277
|
+
);
|
|
278
|
+
}
|