@lemonriver/core 1.2.0 → 1.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-CSkdswfd.js → build-Cv0nNc4G.js} +1 -1
- package/dist/cli/bin.js +5 -5
- package/dist/{config-C5-myPY6.js → config-Di9kipre.js} +2773 -714
- package/dist/{config-CYNOR93W.d.ts → config-f1SqAhtR.d.ts} +1 -1
- package/dist/{dev-DHtYH8sw.js → dev-Az1UzCQp.js} +11 -11
- package/dist/index.d.ts +2 -2
- package/dist/index.js +21 -2
- package/dist/locale/index.d.ts +1 -1
- package/dist/locale/index.js +1 -1
- package/dist/{mcp-B2UeO1un.js → mcp-CW7H6oUg.js} +1 -1
- package/dist/{preview-C1B6-umF.js → preview-DtSq5uN1.js} +1 -1
- package/dist/{types-tdaXSyah.d.ts → types-C4VfD89E.d.ts} +12 -0
- package/dist/{update-DzL8fpcI.js → update-DVe2kQA7.js} +86 -13
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +1 -1
- package/dist/{zh-tw-BhYyMx0-.js → zh-tw-BX3oQAc2.js} +110 -0
- package/package.json +5 -6
- package/release-notes.json +34 -0
- package/src/agent/types.ts +9 -2
- package/src/app/app.tsx +2 -0
- package/src/app/components/agent/agent-panel.tsx +12 -3
- package/src/app/components/agent/agent-presence.tsx +1 -1
- package/src/app/components/command/home-command-menu.tsx +4 -1
- package/src/app/components/command/slide-command-menu.tsx +4 -1
- package/src/app/components/export-progress-toast.tsx +3 -1
- package/src/app/components/inspector/asset-picker-dialog.tsx +1 -1
- package/src/app/components/inspector/comment-layer.tsx +3 -3
- package/src/app/components/inspector/inline-text-editor.tsx +1 -12
- package/src/app/components/inspector/inspect-overlay.tsx +9 -1
- package/src/app/components/inspector/inspector-panel.tsx +7 -23
- package/src/app/components/inspector/inspector-provider.tsx +177 -36
- package/src/app/components/inspector/page-panel.tsx +270 -0
- package/src/app/components/language-toggle.tsx +13 -11
- package/src/app/components/overview-grid.tsx +3 -3
- package/src/app/components/panel/editor-sidebar.tsx +43 -8
- package/src/app/components/panel/panel-shell.tsx +9 -5
- package/src/app/components/panel/save-card.tsx +1 -1
- package/src/app/components/player.tsx +6 -1
- package/src/app/components/sidebar/folder-item.tsx +4 -1
- package/src/app/components/sidebar/sidebar.tsx +11 -8
- package/src/app/components/slide-canvas.tsx +1 -1
- package/src/app/components/style-panel/design-provider.tsx +48 -11
- package/src/app/components/style-panel/use-design.ts +6 -1
- package/src/app/components/theme-toggle.tsx +16 -22
- package/src/app/components/thumbnail-rail.tsx +69 -50
- package/src/app/components/ui/context-menu.tsx +9 -10
- package/src/app/components/ui/dialog.tsx +2 -4
- package/src/app/components/ui/dropdown-menu.tsx +9 -10
- package/src/app/components/ui/popover.tsx +1 -1
- package/src/app/components/ui/select.tsx +2 -2
- package/src/app/components/ui/sonner.tsx +2 -2
- package/src/app/index.html +7 -0
- package/src/app/lemonriver/agent-cli/model.ts +22 -0
- package/src/app/lemonriver/agent-install/model.ts +46 -0
- package/src/app/lemonriver/agent-install/section.tsx +178 -0
- package/src/app/lemonriver/agent-install/use-install.ts +51 -0
- package/src/app/lemonriver/agent-providers/section.tsx +385 -44
- package/src/app/lemonriver/agent-providers/use-providers.ts +50 -3
- package/src/app/lemonriver/backup/places.ts +22 -12
- package/src/app/lemonriver/chrome/sidebar-extras.tsx +1 -1
- package/src/app/lemonriver/feedback/dialog.tsx +1 -2
- package/src/app/lemonriver/feedback/model.ts +0 -5
- package/src/app/lemonriver/guide/clipboard.ts +19 -0
- package/src/app/lemonriver/guide/create-board.tsx +150 -0
- package/src/app/lemonriver/guide/install-board.tsx +208 -0
- package/src/app/lemonriver/guide/more-agents-page.tsx +89 -0
- package/src/app/lemonriver/guide/more-agents.ts +137 -0
- package/src/app/lemonriver/guide/quick-board.tsx +57 -0
- package/src/app/lemonriver/guide/start-board.tsx +38 -0
- package/src/app/lemonriver/guide/start-card.tsx +105 -0
- package/src/app/lemonriver/guide/start.ts +174 -0
- package/src/app/lemonriver/guide/state.ts +5 -21
- package/src/app/lemonriver/help/help-page.tsx +24 -6
- package/src/app/lemonriver/help/model.ts +1 -0
- package/src/app/lemonriver/home/home-page.tsx +12 -6
- package/src/app/lemonriver/home/sorting.ts +45 -0
- package/src/app/lemonriver/home/use-deck-times.ts +1 -2
- package/src/app/lemonriver/i18n/system-locale.ts +39 -0
- package/src/app/lemonriver/present/dual-screen.ts +154 -0
- package/src/app/lemonriver/present/presenter-blocked-hint.tsx +28 -0
- package/src/app/lemonriver/present/wake-lock.ts +74 -0
- package/src/app/lemonriver/routes.tsx +2 -0
- package/src/app/lemonriver/settings/backup-section.tsx +3 -2
- package/src/app/lemonriver/settings/settings-page.tsx +5 -6
- package/src/app/lemonriver/settings/workspace-card.tsx +2 -1
- package/src/app/lemonriver/share/share-dialog.tsx +2 -1
- package/src/app/lemonriver/text/en.ts +594 -452
- package/src/app/lemonriver/text/es.ts +404 -270
- package/src/app/lemonriver/text/ja.ts +405 -273
- package/src/app/lemonriver/text/platform.ts +7 -0
- package/src/app/lemonriver/text/types.ts +122 -1
- package/src/app/lemonriver/text/zh-cn.ts +645 -507
- package/src/app/lemonriver/text/zh-tw.ts +681 -544
- package/src/app/lemonriver/theme/app.css +9 -0
- package/src/app/lemonriver/theme/controls.css +5 -2
- package/src/app/lemonriver/theme/index.css +9 -0
- package/src/app/lemonriver/theme/pages.ts +2 -0
- package/src/app/lemonriver/theme/theme-menu.tsx +10 -11
- package/src/app/lemonriver/update/restart-wait.ts +45 -0
- package/src/app/lemonriver/update/update-prompt.tsx +9 -0
- package/src/app/lib/agent/use-agent.ts +117 -30
- package/src/app/lib/desktop-host.ts +31 -0
- package/src/app/lib/desktop-routes.ts +22 -0
- package/src/app/lib/desktop.ts +106 -0
- package/src/app/lib/export-pdf.ts +15 -7
- package/src/app/lib/inspector/color.ts +51 -0
- package/src/app/lib/inspector/fiber.ts +6 -0
- package/src/app/lib/inspector/use-editor.ts +2 -1
- package/src/app/lib/inspector/use-notes.ts +331 -57
- package/src/app/lib/inspector/use-visual-editor.ts +9 -1
- package/src/app/lib/locale-store.ts +6 -1
- package/src/app/lib/transition.ts +43 -0
- package/src/app/lib/unsaved.ts +155 -0
- package/src/app/routes/home.tsx +1 -1
- package/src/app/routes/presenter.tsx +2 -0
- package/src/app/routes/slide.tsx +130 -74
- package/src/app/styles.css +39 -1
- package/src/locale/en.ts +19 -0
- package/src/locale/es.ts +19 -0
- package/src/locale/ja.ts +19 -0
- package/src/locale/types.ts +12 -0
- package/src/locale/zh-cn.ts +19 -0
- package/src/locale/zh-tw.ts +19 -0
- package/src/app/lemonriver/guide/guide-prompt.tsx +0 -89
|
@@ -297,3 +297,12 @@ html[data-lr-app] [data-lr-confirm] button[aria-pressed="true"] {
|
|
|
297
297
|
border-color: var(--lr-accent);
|
|
298
298
|
background: var(--lr-accent-soft);
|
|
299
299
|
}
|
|
300
|
+
|
|
301
|
+
/*
|
|
302
|
+
* Base UI portals a select above the page, but its positioner keeps z-index
|
|
303
|
+
* auto inside a stacking context that lands under the dialog portal; clicks on
|
|
304
|
+
* options then hit the dialog instead. Raise it whenever a dialog is open.
|
|
305
|
+
*/
|
|
306
|
+
body:has([data-slot="dialog-content"]) [role="presentation"]:has(> [data-slot="select-content"]) {
|
|
307
|
+
z-index: 60;
|
|
308
|
+
}
|
|
@@ -177,7 +177,7 @@ html[data-lr-app]
|
|
|
177
177
|
border-color: var(--lr-danger);
|
|
178
178
|
}
|
|
179
179
|
|
|
180
|
-
html[data-lr-app]
|
|
180
|
+
html[data-lr-app]:not([data-lr-material])
|
|
181
181
|
:is(
|
|
182
182
|
[data-slot="dropdown-menu-content"],
|
|
183
183
|
[data-slot="context-menu-content"],
|
|
@@ -302,13 +302,16 @@ html[data-lr-app] [data-slot="dialog-overlay"] {
|
|
|
302
302
|
html[data-lr-app] [data-slot="dialog-content"] {
|
|
303
303
|
border-radius: var(--lr-radius-xl);
|
|
304
304
|
border-color: transparent;
|
|
305
|
-
background-color: var(--lr-surface);
|
|
306
305
|
box-shadow: var(--lr-shadow-2);
|
|
307
306
|
padding: 24px;
|
|
308
307
|
transition-duration: var(--lr-dur-slow);
|
|
309
308
|
transition-timing-function: var(--lr-ease-out);
|
|
310
309
|
}
|
|
311
310
|
|
|
311
|
+
html[data-lr-app]:not([data-lr-material]) [data-slot="dialog-content"] {
|
|
312
|
+
background-color: var(--lr-surface);
|
|
313
|
+
}
|
|
314
|
+
|
|
312
315
|
html[data-lr-app] [data-slot="dialog-content"].p-0 {
|
|
313
316
|
padding: 0;
|
|
314
317
|
}
|
|
@@ -1,3 +1,12 @@
|
|
|
1
1
|
@import "./tokens.css";
|
|
2
2
|
@import "./controls.css";
|
|
3
3
|
@import "./app.css";
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* Upstream's frosted material reads lighter than the themes and the user's
|
|
7
|
+
* design package; keep floating surfaces opaque unless the page opts in
|
|
8
|
+
* with data-lr-material.
|
|
9
|
+
*/
|
|
10
|
+
html:not([data-lr-material]) {
|
|
11
|
+
--material: var(--popover);
|
|
12
|
+
}
|
|
@@ -63,6 +63,7 @@ export function isBrandPage(page: LrPage): boolean {
|
|
|
63
63
|
export const SETTINGS_VIEW_ID = '__lr_settings__';
|
|
64
64
|
export const TRASH_VIEW_ID = '__lr_trash__';
|
|
65
65
|
export const TEMPLATES_VIEW_ID = '__lr_templates__';
|
|
66
|
+
export const HELP_VIEW_ID = '__lr_help__';
|
|
66
67
|
|
|
67
68
|
/** The sidebar selection for our pages inside the home shell, or null for the official ones. */
|
|
68
69
|
export function lemonRiverViewFor(pathname: string): string | null {
|
|
@@ -70,5 +71,6 @@ export function lemonRiverViewFor(pathname: string): string | null {
|
|
|
70
71
|
if (page === 'settings') return SETTINGS_VIEW_ID;
|
|
71
72
|
if (page === 'trash') return TRASH_VIEW_ID;
|
|
72
73
|
if (page === 'templates') return TEMPLATES_VIEW_ID;
|
|
74
|
+
if (page === 'help') return HELP_VIEW_ID;
|
|
73
75
|
return null;
|
|
74
76
|
}
|
|
@@ -5,7 +5,8 @@ import { buttonVariants } from '@/components/ui/button';
|
|
|
5
5
|
import {
|
|
6
6
|
DropdownMenu,
|
|
7
7
|
DropdownMenuContent,
|
|
8
|
-
|
|
8
|
+
DropdownMenuRadioGroup,
|
|
9
|
+
DropdownMenuRadioItem,
|
|
9
10
|
DropdownMenuTrigger,
|
|
10
11
|
} from '@/components/ui/dropdown-menu';
|
|
11
12
|
import { useLocale } from '@/lib/use-locale';
|
|
@@ -49,16 +50,14 @@ export function ThemeToggle() {
|
|
|
49
50
|
</DropdownMenuTrigger>
|
|
50
51
|
</IconTooltip>
|
|
51
52
|
<DropdownMenuContent align="end" className="min-w-[160px]">
|
|
52
|
-
{
|
|
53
|
-
|
|
54
|
-
key={item.id}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
</DropdownMenuItem>
|
|
61
|
-
))}
|
|
53
|
+
<DropdownMenuRadioGroup value={mounted ? theme : undefined} onValueChange={setTheme}>
|
|
54
|
+
{items.map((item) => (
|
|
55
|
+
<DropdownMenuRadioItem key={item.id} value={item.id} closeOnClick>
|
|
56
|
+
{item.icon}
|
|
57
|
+
{item.label}
|
|
58
|
+
</DropdownMenuRadioItem>
|
|
59
|
+
))}
|
|
60
|
+
</DropdownMenuRadioGroup>
|
|
62
61
|
</DropdownMenuContent>
|
|
63
62
|
</DropdownMenu>
|
|
64
63
|
);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// The Windows launcher answers an update by stopping the dev server, replacing
|
|
2
|
+
// it and starting a fresh one; a changed executionId is the only signal that
|
|
3
|
+
// the replacement is really serving, so the page waits for one before it
|
|
4
|
+
// reloads.
|
|
5
|
+
|
|
6
|
+
export type ExecutionId = string | null;
|
|
7
|
+
|
|
8
|
+
export async function currentExecutionId(fetchImpl: typeof fetch = fetch): Promise<ExecutionId> {
|
|
9
|
+
try {
|
|
10
|
+
const res = await fetchImpl('/__server-status');
|
|
11
|
+
if (!res.ok) return null;
|
|
12
|
+
const body = (await res.json()) as { executionId?: unknown };
|
|
13
|
+
return typeof body.executionId === 'string' ? body.executionId : null;
|
|
14
|
+
} catch {
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export async function waitForReplacementServer({
|
|
20
|
+
before,
|
|
21
|
+
timeoutMs = 120_000,
|
|
22
|
+
intervalMs = 1000,
|
|
23
|
+
fetchImpl = fetch,
|
|
24
|
+
reload = () => window.location.reload(),
|
|
25
|
+
sleep = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms)),
|
|
26
|
+
}: {
|
|
27
|
+
before: ExecutionId;
|
|
28
|
+
timeoutMs?: number;
|
|
29
|
+
intervalMs?: number;
|
|
30
|
+
fetchImpl?: typeof fetch;
|
|
31
|
+
reload?: () => void;
|
|
32
|
+
sleep?: (ms: number) => Promise<void>;
|
|
33
|
+
}): Promise<boolean> {
|
|
34
|
+
const attempts = Math.max(1, Math.ceil(timeoutMs / intervalMs));
|
|
35
|
+
for (let attempt = 0; attempt < attempts; attempt += 1) {
|
|
36
|
+
await sleep(intervalMs);
|
|
37
|
+
const id = await currentExecutionId(fetchImpl);
|
|
38
|
+
if (id === null) continue;
|
|
39
|
+
if (before === null || id !== before) {
|
|
40
|
+
reload();
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
type UpdateCheck,
|
|
18
18
|
} from './prompt';
|
|
19
19
|
import { fetchReleaseNotes, releaseNotesLine } from './release-notes';
|
|
20
|
+
import { currentExecutionId, waitForReplacementServer } from './restart-wait';
|
|
20
21
|
import { markUpdated, rememberNoticeIcons, UPDATE_TOAST_ID } from './state';
|
|
21
22
|
|
|
22
23
|
const TOAST_ID = UPDATE_TOAST_ID;
|
|
@@ -72,13 +73,21 @@ export function UpdatePrompt() {
|
|
|
72
73
|
rememberNoticeIcons(icons);
|
|
73
74
|
|
|
74
75
|
let ok = false;
|
|
76
|
+
let restarting = false;
|
|
77
|
+
const before = await currentExecutionId();
|
|
75
78
|
try {
|
|
76
79
|
const res = await fetch('/__update-package', { method: 'POST' });
|
|
77
80
|
ok = res.ok;
|
|
81
|
+
if (ok) {
|
|
82
|
+
const body = (await res.json().catch(() => null)) as { restarting?: unknown } | null;
|
|
83
|
+
restarting = body?.restarting === true;
|
|
84
|
+
}
|
|
78
85
|
} catch {
|
|
79
86
|
ok = false;
|
|
80
87
|
}
|
|
81
88
|
|
|
89
|
+
if (restarting) void waitForReplacementServer({ before });
|
|
90
|
+
|
|
82
91
|
if (!ok) {
|
|
83
92
|
phase.current = 'idle';
|
|
84
93
|
if (cancelled) return;
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { useCallback, useEffect, useSyncExternalStore } from 'react';
|
|
2
2
|
import { toast } from 'sonner';
|
|
3
|
+
import { desktopHost, openDeckInHost } from '@/lib/desktop';
|
|
3
4
|
import { useLocale } from '@/lib/use-locale';
|
|
4
5
|
import {
|
|
6
|
+
AGENT_EVENT,
|
|
5
7
|
type AgentEffort,
|
|
6
8
|
type AgentItem,
|
|
7
9
|
type AgentModelOption,
|
|
8
10
|
type AgentProviderId,
|
|
9
11
|
type AgentSession,
|
|
10
12
|
type AgentSessionSummary,
|
|
13
|
+
type AgentSnapshot,
|
|
11
14
|
type AgentStatus,
|
|
12
15
|
type AgentStreamEvent,
|
|
13
16
|
type AgentTurnContext,
|
|
@@ -35,14 +38,21 @@ type State = {
|
|
|
35
38
|
installing: AgentProviderId | null;
|
|
36
39
|
connectErrors: Partial<Record<AgentProviderId, string>>;
|
|
37
40
|
newDeck: string | null;
|
|
41
|
+
handoff: Handoff | null;
|
|
42
|
+
// Bumped per handoff taken, so one naming the already active session still registers.
|
|
43
|
+
handoffs: number;
|
|
38
44
|
};
|
|
39
45
|
|
|
46
|
+
type Handoff = { slideId: string; sessionId: string };
|
|
47
|
+
|
|
40
48
|
const ACTIVE_KEY = 'open-slide:agent-session';
|
|
41
49
|
const PROVIDER_KEY = 'open-slide:agent-provider';
|
|
42
50
|
const MODEL_KEY = 'open-slide:agent-model';
|
|
43
51
|
const AUTO_APPROVE_KEY = 'open-slide:agent-auto-approve';
|
|
44
52
|
const DOCK_KEY = 'open-slide:agent-dock';
|
|
45
53
|
const NEW_DECK_KEY = 'open-slide:agent-new-deck';
|
|
54
|
+
const HANDOFF_KEY = 'open-slide:agent-handoff';
|
|
55
|
+
const HANDOFF_TTL_MS = 30_000;
|
|
46
56
|
|
|
47
57
|
function readStorage(key: string): string | null {
|
|
48
58
|
try {
|
|
@@ -77,6 +87,18 @@ function readModelChoices(): Partial<Record<AgentProviderId, ModelChoice>> {
|
|
|
77
87
|
return choices;
|
|
78
88
|
}
|
|
79
89
|
|
|
90
|
+
function parseHandoff(raw: string | null): Handoff | null {
|
|
91
|
+
if (!raw) return null;
|
|
92
|
+
try {
|
|
93
|
+
const { slideId, sessionId, at } = JSON.parse(raw) as Record<string, unknown>;
|
|
94
|
+
if (typeof slideId !== 'string' || typeof sessionId !== 'string') return null;
|
|
95
|
+
if (typeof at !== 'number' || Date.now() - at > HANDOFF_TTL_MS) return null;
|
|
96
|
+
return { slideId, sessionId };
|
|
97
|
+
} catch {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
80
102
|
const available = import.meta.env.DEV && typeof window !== 'undefined';
|
|
81
103
|
|
|
82
104
|
let state: State = {
|
|
@@ -97,6 +119,8 @@ let state: State = {
|
|
|
97
119
|
installing: null,
|
|
98
120
|
connectErrors: {},
|
|
99
121
|
newDeck: readStorage(NEW_DECK_KEY),
|
|
122
|
+
handoff: parseHandoff(readStorage(HANDOFF_KEY)),
|
|
123
|
+
handoffs: 0,
|
|
100
124
|
};
|
|
101
125
|
|
|
102
126
|
const listeners = new Set<() => void>();
|
|
@@ -122,28 +146,27 @@ export function useAgentState(): State {
|
|
|
122
146
|
return useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
|
|
123
147
|
}
|
|
124
148
|
|
|
125
|
-
let
|
|
126
|
-
|
|
149
|
+
let streaming = false;
|
|
150
|
+
|
|
151
|
+
// Anything streamed while the socket was down is gone, so reload what is on
|
|
152
|
+
// screen once it reconnects.
|
|
153
|
+
function resync() {
|
|
154
|
+
void refreshStatus();
|
|
155
|
+
if (state.sessionsLoaded) void loadSessions();
|
|
156
|
+
for (const id of Object.keys(state.full)) void loadSession(id);
|
|
157
|
+
}
|
|
127
158
|
|
|
128
159
|
function syncStream(enabled: boolean) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
160
|
+
const hot = import.meta.hot;
|
|
161
|
+
if (!hot || enabled === streaming) return;
|
|
162
|
+
streaming = enabled;
|
|
163
|
+
if (enabled) {
|
|
164
|
+
hot.on(AGENT_EVENT, applyEvent);
|
|
165
|
+
hot.on('vite:ws:connect', resync);
|
|
166
|
+
} else {
|
|
167
|
+
hot.off(AGENT_EVENT, applyEvent);
|
|
168
|
+
hot.off('vite:ws:connect', resync);
|
|
133
169
|
}
|
|
134
|
-
if (stream) return;
|
|
135
|
-
stream = new EventSource('/__agent/events');
|
|
136
|
-
stream.onmessage = (message) => applyEvent(JSON.parse(message.data) as AgentStreamEvent);
|
|
137
|
-
stream.onopen = () => {
|
|
138
|
-
// Anything streamed while disconnected is gone, so reload what is on screen.
|
|
139
|
-
if (!streamOpened) {
|
|
140
|
-
streamOpened = true;
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
void refreshStatus();
|
|
144
|
-
if (state.sessionsLoaded) void loadSessions();
|
|
145
|
-
for (const id of Object.keys(state.full)) void loadSession(id);
|
|
146
|
-
};
|
|
147
170
|
}
|
|
148
171
|
|
|
149
172
|
function upsertSummary(list: AgentSessionSummary[], summary: AgentSessionSummary) {
|
|
@@ -153,7 +176,36 @@ function upsertSummary(list: AgentSessionSummary[], summary: AgentSessionSummary
|
|
|
153
176
|
);
|
|
154
177
|
}
|
|
155
178
|
|
|
179
|
+
// Events that arrive while each snapshot request is in flight.
|
|
180
|
+
const recovering = new Set<AgentStreamEvent[]>();
|
|
181
|
+
|
|
156
182
|
function applyEvent(event: AgentStreamEvent) {
|
|
183
|
+
for (const missed of recovering) missed.push(event);
|
|
184
|
+
reduceEvent(event);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// A snapshot can land after newer events; replaying the ones it lacks keeps them.
|
|
188
|
+
async function loadSnapshot<T>(
|
|
189
|
+
path: string,
|
|
190
|
+
apply: (snapshot: T) => void,
|
|
191
|
+
affects: (event: AgentStreamEvent) => boolean,
|
|
192
|
+
): Promise<T> {
|
|
193
|
+
const missed: AgentStreamEvent[] = [];
|
|
194
|
+
recovering.add(missed);
|
|
195
|
+
try {
|
|
196
|
+
const { rev, ...rest } = await request<AgentSnapshot<T>>(path);
|
|
197
|
+
const snapshot = rest as unknown as T;
|
|
198
|
+
apply(snapshot);
|
|
199
|
+
for (const event of missed) {
|
|
200
|
+
if ((event.rev ?? 0) > rev && affects(event)) reduceEvent(event);
|
|
201
|
+
}
|
|
202
|
+
return snapshot;
|
|
203
|
+
} finally {
|
|
204
|
+
recovering.delete(missed);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function reduceEvent(event: AgentStreamEvent) {
|
|
157
209
|
switch (event.type) {
|
|
158
210
|
case 'session':
|
|
159
211
|
setState((prev) => {
|
|
@@ -262,13 +314,15 @@ export async function refreshStatus(): Promise<void> {
|
|
|
262
314
|
async function loadSessions(): Promise<void> {
|
|
263
315
|
if (!available) return;
|
|
264
316
|
try {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
sessions,
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
317
|
+
await loadSnapshot<{ sessions: AgentSessionSummary[] }>(
|
|
318
|
+
'/__agent/sessions',
|
|
319
|
+
({ sessions }) => setState({ sessions, sessionsLoaded: true }),
|
|
320
|
+
(event) => event.type === 'session' || event.type === 'session-removed',
|
|
321
|
+
);
|
|
322
|
+
// Only after the replay, which restores sessions created while the request was out.
|
|
323
|
+
setState((prev) =>
|
|
324
|
+
prev.activeId && !prev.sessions.some((s) => s.id === prev.activeId) ? { activeId: null } : {},
|
|
325
|
+
);
|
|
272
326
|
} catch {
|
|
273
327
|
setState({ sessionsLoaded: true });
|
|
274
328
|
}
|
|
@@ -277,9 +331,14 @@ async function loadSessions(): Promise<void> {
|
|
|
277
331
|
async function loadSession(id: string): Promise<AgentSession | null> {
|
|
278
332
|
if (!available) return null;
|
|
279
333
|
try {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
334
|
+
return await loadSnapshot<AgentSession>(
|
|
335
|
+
`/__agent/sessions/${encodeURIComponent(id)}`,
|
|
336
|
+
(session) => setState((prev) => ({ full: { ...prev.full, [id]: session } })),
|
|
337
|
+
(event) =>
|
|
338
|
+
event.type === 'session'
|
|
339
|
+
? event.session.id === id
|
|
340
|
+
: event.type !== 'slide-renamed' && event.sessionId === id,
|
|
341
|
+
);
|
|
283
342
|
} catch {
|
|
284
343
|
setState((prev) => {
|
|
285
344
|
const { [id]: _gone, ...full } = prev.full;
|
|
@@ -391,6 +450,32 @@ export function setActiveSession(id: string | null): void {
|
|
|
391
450
|
setState({ activeId: id });
|
|
392
451
|
}
|
|
393
452
|
|
|
453
|
+
if (available) {
|
|
454
|
+
window.addEventListener('storage', (e) => {
|
|
455
|
+
if (e.key === HANDOFF_KEY) setState({ handoff: parseHandoff(e.newValue) });
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
// Each desktop tab is a separate page on one origin, so a session picked for
|
|
460
|
+
// another deck goes through storage, reaching that deck's tab whether it is
|
|
461
|
+
// already open or yet to load.
|
|
462
|
+
export function openSessionInHost(slideId: string, sessionId: string): boolean {
|
|
463
|
+
if (!desktopHost) return false;
|
|
464
|
+
writeStorage(HANDOFF_KEY, JSON.stringify({ slideId, sessionId, at: Date.now() }));
|
|
465
|
+
return openDeckInHost(slideId);
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export function useSessionHandoff(slideId: string): void {
|
|
469
|
+
const { handoff } = useAgentState();
|
|
470
|
+
useEffect(() => {
|
|
471
|
+
if (handoff?.slideId !== slideId) return;
|
|
472
|
+
writeStorage(HANDOFF_KEY, null);
|
|
473
|
+
setState((prev) => ({ handoff: null, handoffs: prev.handoffs + 1 }));
|
|
474
|
+
setActiveSession(handoff.sessionId);
|
|
475
|
+
setDockOpen(true);
|
|
476
|
+
}, [handoff, slideId]);
|
|
477
|
+
}
|
|
478
|
+
|
|
394
479
|
export function setModelChoice(provider: AgentProviderId, choice: ModelChoice): void {
|
|
395
480
|
const modelChoices = { ...state.modelChoices, [provider]: choice };
|
|
396
481
|
writeStorage(MODEL_KEY, JSON.stringify(modelChoices));
|
|
@@ -433,7 +518,9 @@ function startBlankDeck(): Promise<void> {
|
|
|
433
518
|
writeStorage(NEW_DECK_KEY, slideId);
|
|
434
519
|
setActiveSession(null);
|
|
435
520
|
setDockOpen(true);
|
|
436
|
-
|
|
521
|
+
if (!openDeckInHost(slideId)) {
|
|
522
|
+
window.location.assign(`${basePath()}/s/${encodeURIComponent(slideId)}`);
|
|
523
|
+
}
|
|
437
524
|
})().finally(() => {
|
|
438
525
|
creatingDeck = null;
|
|
439
526
|
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type HapticPattern = 'alignment' | 'levelChange' | 'generic';
|
|
2
|
+
|
|
3
|
+
// Drafts wait for an explicit Save; pending work is already on its way to disk.
|
|
4
|
+
export type UnsavedStatus = { drafts: boolean; pending: boolean };
|
|
5
|
+
|
|
6
|
+
// `discard` drops drafts but lets autosaved work land; `abandon` drops everything.
|
|
7
|
+
export type UnsavedAction = 'save' | 'discard' | 'abandon';
|
|
8
|
+
|
|
9
|
+
export type UnsavedOutcome = { ok: true } | { ok: false; error: string };
|
|
10
|
+
|
|
11
|
+
export type UnsavedGuard = {
|
|
12
|
+
status: () => UnsavedStatus;
|
|
13
|
+
settle: (action: UnsavedAction) => Promise<UnsavedOutcome>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
// Injected by the desktop app's preload into every tab. This file imports
|
|
17
|
+
// nothing so the preload can type-check against it; optional members are
|
|
18
|
+
// missing in older desktop builds.
|
|
19
|
+
export type DesktopHost = {
|
|
20
|
+
translucent: boolean;
|
|
21
|
+
openDeck: (slideId: string) => void;
|
|
22
|
+
openHome: (path?: string) => void;
|
|
23
|
+
setTheme: (theme: string) => void;
|
|
24
|
+
haptic?: (pattern: HapticPattern) => void;
|
|
25
|
+
// Resolves false when the user cancels the save dialog.
|
|
26
|
+
printToPdf?: (filename: string) => Promise<boolean>;
|
|
27
|
+
onNavigate: (listener: (path: string) => void) => () => void;
|
|
28
|
+
// Destroying a page runs no React cleanup, so the host asks before it closes or reloads one.
|
|
29
|
+
guardUnsaved?: (guard: UnsavedGuard) => () => void;
|
|
30
|
+
onTranslucentChange?: (listener: (translucent: boolean) => void) => () => void;
|
|
31
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const DECK_PATH_RE = /^\/s\/([^/]+)\/?$/;
|
|
2
|
+
|
|
3
|
+
export function stripBase(pathname: string, base = ''): string {
|
|
4
|
+
if (!base || !pathname.startsWith(base)) return pathname;
|
|
5
|
+
const rest = pathname.slice(base.length);
|
|
6
|
+
if (rest === '') return '/';
|
|
7
|
+
return rest.startsWith('/') ? rest : pathname;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function deckIdFromPath(pathname: string, base = ''): string | null {
|
|
11
|
+
const m = DECK_PATH_RE.exec(stripBase(pathname, base));
|
|
12
|
+
if (!m) return null;
|
|
13
|
+
try {
|
|
14
|
+
return decodeURIComponent(m[1]);
|
|
15
|
+
} catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function isHomePath(pathname: string, base = ''): boolean {
|
|
21
|
+
return !stripBase(pathname, base).startsWith('/s/');
|
|
22
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { useTheme } from 'next-themes';
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { useNavigate } from 'react-router-dom';
|
|
4
|
+
import type { DesktopHost, HapticPattern } from './desktop-host';
|
|
5
|
+
import { deckIdFromPath, isHomePath, stripBase } from './desktop-routes';
|
|
6
|
+
import { slideIds } from './slides';
|
|
7
|
+
import { hasUnsaved, settleUnsaved, unsavedStatus } from './unsaved';
|
|
8
|
+
|
|
9
|
+
declare global {
|
|
10
|
+
interface Window {
|
|
11
|
+
openSlideDesktop?: DesktopHost;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export const desktopHost: DesktopHost | undefined =
|
|
16
|
+
typeof window === 'undefined' ? undefined : window.openSlideDesktop;
|
|
17
|
+
|
|
18
|
+
if (desktopHost) {
|
|
19
|
+
desktopHost.guardUnsaved?.({ status: unsavedStatus, settle: settleUnsaved });
|
|
20
|
+
// Covers unloads the host does not start itself, such as a dev-server reload.
|
|
21
|
+
window.addEventListener('beforeunload', (e) => {
|
|
22
|
+
if (hasUnsaved()) e.preventDefault();
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const BASE = import.meta.env.BASE_URL.replace(/\/$/, '');
|
|
27
|
+
|
|
28
|
+
// True when the host took over, so the caller skips its own navigation.
|
|
29
|
+
export function openDeckInHost(slideId: string): boolean {
|
|
30
|
+
if (!desktopHost) return false;
|
|
31
|
+
desktopHost.openDeck(slideId);
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function haptic(pattern: HapticPattern) {
|
|
36
|
+
desktopHost?.haptic?.(pattern);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function openHomeInHost(path?: string): boolean {
|
|
40
|
+
if (!desktopHost) return false;
|
|
41
|
+
desktopHost.openHome(path);
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function interceptLinkClick(host: DesktopHost, e: MouseEvent) {
|
|
46
|
+
if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const anchor = (e.target as Element | null)?.closest?.('a[href]');
|
|
50
|
+
if (!(anchor instanceof HTMLAnchorElement) || (anchor.target && anchor.target !== '_self')) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (anchor.hasAttribute('download')) return;
|
|
54
|
+
const url = new URL(anchor.href);
|
|
55
|
+
if (url.origin !== window.location.origin) return;
|
|
56
|
+
const currentDeck = deckIdFromPath(window.location.pathname, BASE);
|
|
57
|
+
const targetDeck = deckIdFromPath(url.pathname, BASE);
|
|
58
|
+
if (targetDeck && targetDeck !== currentDeck) {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
host.openDeck(targetDeck);
|
|
61
|
+
} else if (currentDeck && isHomePath(url.pathname, BASE)) {
|
|
62
|
+
e.preventDefault();
|
|
63
|
+
host.openHome(stripBase(url.pathname, BASE) + url.search);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function DesktopBridge() {
|
|
68
|
+
const navigate = useNavigate();
|
|
69
|
+
const { theme } = useTheme();
|
|
70
|
+
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (!desktopHost) return;
|
|
73
|
+
const host = desktopHost;
|
|
74
|
+
const onClick = (e: MouseEvent) => interceptLinkClick(host, e);
|
|
75
|
+
document.addEventListener('click', onClick, true);
|
|
76
|
+
return () => document.removeEventListener('click', onClick, true);
|
|
77
|
+
}, []);
|
|
78
|
+
|
|
79
|
+
useEffect(
|
|
80
|
+
() =>
|
|
81
|
+
desktopHost?.onNavigate((path) => {
|
|
82
|
+
// A pre-warmed page's slide list predates decks created after it booted.
|
|
83
|
+
const deck = deckIdFromPath(path, BASE);
|
|
84
|
+
if (deck && !slideIds.includes(deck)) {
|
|
85
|
+
window.location.replace(`${BASE}${path}`);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
navigate(path);
|
|
89
|
+
}),
|
|
90
|
+
[navigate],
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
if (theme) desktopHost?.setTheme(theme);
|
|
95
|
+
}, [theme]);
|
|
96
|
+
|
|
97
|
+
useEffect(
|
|
98
|
+
() =>
|
|
99
|
+
desktopHost?.onTranslucentChange?.((translucent) => {
|
|
100
|
+
document.documentElement.toggleAttribute('data-translucent', translucent);
|
|
101
|
+
}),
|
|
102
|
+
[],
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
return null;
|
|
106
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createElement } from 'react';
|
|
2
2
|
import { createRoot, type Root } from 'react-dom/client';
|
|
3
3
|
import { designToCssVars } from './design';
|
|
4
|
+
import { desktopHost } from './desktop';
|
|
4
5
|
import { nextPaint, sleep } from './dom';
|
|
5
6
|
import { SlidePageProvider } from './page-context';
|
|
6
7
|
import { isFrameAnimationSettled, waitForDataWaitfor, waitForFonts } from './print-ready';
|
|
@@ -88,11 +89,11 @@ export function isSafari(): boolean {
|
|
|
88
89
|
}
|
|
89
90
|
|
|
90
91
|
export type PdfExportProgress = {
|
|
91
|
-
phase: 'processing' | 'printing' | 'done';
|
|
92
|
+
phase: 'processing' | 'printing' | 'saving' | 'done';
|
|
92
93
|
/** Number of pages whose intro animations have finished (0..total). */
|
|
93
94
|
current: number;
|
|
94
95
|
total: number;
|
|
95
|
-
/** 0–99 while processing, 99 during printing, 100 when done. */
|
|
96
|
+
/** 0–99 while processing, 99 during printing or saving, 100 when done. */
|
|
96
97
|
percent: number;
|
|
97
98
|
};
|
|
98
99
|
|
|
@@ -155,6 +156,7 @@ export async function exportSlideAsPdf(
|
|
|
155
156
|
|
|
156
157
|
const previousTitle = document.title;
|
|
157
158
|
document.title = slide.meta?.title ?? slideId;
|
|
159
|
+
let finished = false;
|
|
158
160
|
|
|
159
161
|
try {
|
|
160
162
|
await waitForFonts();
|
|
@@ -178,12 +180,18 @@ export async function exportSlideAsPdf(
|
|
|
178
180
|
neutralizeGradientBackgrounds(root);
|
|
179
181
|
await sleep(100); // flush layout
|
|
180
182
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
183
|
+
if (desktopHost?.printToPdf) {
|
|
184
|
+
onProgress?.({ phase: 'saving', current: total, total, percent: 99 });
|
|
185
|
+
finished = await desktopHost.printToPdf(`${document.title}.pdf`);
|
|
186
|
+
} else {
|
|
187
|
+
onProgress?.({ phase: 'printing', current: total, total, percent: 99 });
|
|
188
|
+
const printDone = waitForAfterPrint();
|
|
189
|
+
window.print();
|
|
190
|
+
await printDone;
|
|
191
|
+
finished = true;
|
|
192
|
+
}
|
|
185
193
|
} finally {
|
|
186
|
-
onProgress?.({ phase: 'done', current: total, total, percent: 100 });
|
|
194
|
+
if (finished) onProgress?.({ phase: 'done', current: total, total, percent: 100 });
|
|
187
195
|
document.title = previousTitle;
|
|
188
196
|
for (const r of reactRoots) r.unmount();
|
|
189
197
|
root.remove();
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { parseColor, type Rgba, toHex } from '../pptx/css';
|
|
2
|
+
|
|
3
|
+
let painter: CanvasRenderingContext2D | null | undefined;
|
|
4
|
+
const painted = new Map<string, Rgba | null>();
|
|
5
|
+
|
|
6
|
+
// Computed styles keep oklch(), lab(), color() and the like as written, so
|
|
7
|
+
// anything that isn't rgb() is painted onto a pixel and read back as sRGB.
|
|
8
|
+
function paintRgb(value: string): Rgba | null {
|
|
9
|
+
if (painted.has(value)) return painted.get(value) ?? null;
|
|
10
|
+
if (painter === undefined) {
|
|
11
|
+
try {
|
|
12
|
+
const canvas = document.createElement('canvas');
|
|
13
|
+
canvas.width = 1;
|
|
14
|
+
canvas.height = 1;
|
|
15
|
+
painter = canvas.getContext('2d', { willReadFrequently: true });
|
|
16
|
+
} catch {
|
|
17
|
+
painter = null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
let result: Rgba | null = null;
|
|
21
|
+
if (painter && typeof CSS !== 'undefined' && CSS.supports('color', value)) {
|
|
22
|
+
painter.clearRect(0, 0, 1, 1);
|
|
23
|
+
painter.fillStyle = value;
|
|
24
|
+
painter.fillRect(0, 0, 1, 1);
|
|
25
|
+
const [r, g, b, a] = painter.getImageData(0, 0, 1, 1).data;
|
|
26
|
+
result = { r, g, b, a: a / 255 };
|
|
27
|
+
}
|
|
28
|
+
if (painted.size >= 256) painted.clear();
|
|
29
|
+
painted.set(value, result);
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function toRgba(value: string): Rgba | null {
|
|
34
|
+
if (!value) return null;
|
|
35
|
+
return parseColor(value) ?? paintRgb(value);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function rgbToHex(value: string): string | null {
|
|
39
|
+
const rgba = toRgba(value);
|
|
40
|
+
return rgba ? `#${toHex(rgba).toLowerCase()}` : null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function isTransparent(value: string): boolean {
|
|
44
|
+
if (!value) return true;
|
|
45
|
+
const rgba = toRgba(value);
|
|
46
|
+
return rgba ? rgba.a === 0 : false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function opaqueHex(value: string): string | null {
|
|
50
|
+
return isTransparent(value) ? null : rgbToHex(value);
|
|
51
|
+
}
|