@open-slide/core 2.3.2 → 2.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-8lRsgsO4.js → build-D7GwYl8d.js} +1 -1
- package/dist/cli/bin.js +4 -4
- package/dist/{config-DJ8ZOe7C.d.ts → config-CfhtJxQH.d.ts} +1 -1
- package/dist/{config-D2Mq1vSW.js → config-D4uPk_tM.js} +383 -138
- package/dist/{dev-BvefEp1Q.js → dev-DyCDMbHB.js} +10 -10
- package/dist/index.d.ts +2 -2
- package/dist/index.js +9 -1
- package/dist/locale/index.d.ts +1 -1
- package/dist/locale/index.js +1 -1
- package/dist/{preview-D8ognobz.js → preview-DjIFvt0K.js} +1 -1
- package/dist/{types-tdaXSyah.d.ts → types-ZfArJF0d.d.ts} +20 -13
- package/dist/{update-BivdNgL3.js → update-BKhRM7o4.js} +30 -3
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +1 -1
- package/dist/{zh-tw-DXcqQTrA.js → zh-tw-D7LfGVmA.js} +215 -65
- package/package.json +4 -5
- package/src/agent/provider.ts +8 -1
- package/src/agent/types.ts +17 -2
- package/src/app/app.tsx +2 -0
- package/src/app/components/agent/agent-markdown.tsx +3 -6
- package/src/app/components/agent/agent-panel.tsx +36 -258
- package/src/app/components/agent/agent-presence.tsx +1 -1
- package/src/app/components/agent/composer.tsx +52 -24
- package/src/app/components/agent/effort-slider.tsx +172 -0
- package/src/app/components/agent/model-menu.tsx +170 -0
- package/src/app/components/agent/permission-menu.tsx +88 -0
- package/src/app/components/agent/transcript.tsx +23 -31
- 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 +8 -35
- 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/note-markdown.test.tsx +12 -6
- package/src/app/components/note-markdown.tsx +16 -21
- 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/sidebar/folder-item.tsx +4 -1
- package/src/app/components/sidebar/sidebar.tsx +11 -8
- 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 +68 -49
- 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/lib/agent/use-agent.ts +131 -37
- package/src/app/lib/desktop-host.ts +31 -0
- package/src/app/lib/desktop-routes.test.ts +54 -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.test.ts +209 -0
- 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 +14 -2
- package/src/app/lib/note-markdown.test.ts +69 -5
- package/src/app/lib/note-markdown.ts +97 -22
- package/src/app/lib/transition.test.ts +84 -1
- package/src/app/lib/transition.ts +43 -0
- package/src/app/lib/unsaved.test.ts +253 -0
- package/src/app/lib/unsaved.ts +155 -0
- package/src/app/routes/home.tsx +1 -1
- package/src/app/routes/slide.tsx +114 -117
- package/src/app/styles.css +421 -1
- package/src/locale/en.ts +40 -15
- package/src/locale/es.ts +40 -17
- package/src/locale/ja.ts +40 -15
- package/src/locale/types.ts +19 -14
- package/src/locale/zh-cn.ts +40 -14
- package/src/locale/zh-tw.ts +40 -14
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import type { UnsavedAction, UnsavedOutcome, UnsavedStatus } from './desktop-host';
|
|
3
|
+
|
|
4
|
+
export type UnsavedSource = {
|
|
5
|
+
// A draft waits for the user to save it; autosaved work is unsaved only until its write lands.
|
|
6
|
+
kind: 'draft' | 'autosave';
|
|
7
|
+
dirty: () => boolean;
|
|
8
|
+
save: () => Promise<void>;
|
|
9
|
+
discard: () => void;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type Write = () => Promise<unknown>;
|
|
13
|
+
|
|
14
|
+
const sources = new Set<UnsavedSource>();
|
|
15
|
+
const writes = new Map<unknown, Promise<unknown>>();
|
|
16
|
+
const failed = new Map<unknown, Write>();
|
|
17
|
+
const abandonListeners = new Set<() => void>();
|
|
18
|
+
|
|
19
|
+
export function registerUnsaved(source: UnsavedSource): () => void {
|
|
20
|
+
sources.add(source);
|
|
21
|
+
return () => {
|
|
22
|
+
sources.delete(source);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// For a write that outlives the component that started it, such as a flush on
|
|
27
|
+
// unmount. A failed one is retried on the next save until it lands or the work
|
|
28
|
+
// is abandoned; a newer write under the same key replaces it.
|
|
29
|
+
export function trackWrite(key: unknown, write: Write): void {
|
|
30
|
+
const attempt = write();
|
|
31
|
+
writes.set(key, attempt);
|
|
32
|
+
failed.delete(key);
|
|
33
|
+
const finish = (retry?: Write) => {
|
|
34
|
+
if (writes.get(key) !== attempt) return;
|
|
35
|
+
writes.delete(key);
|
|
36
|
+
if (retry) failed.set(key, retry);
|
|
37
|
+
};
|
|
38
|
+
attempt.then(
|
|
39
|
+
() => finish(),
|
|
40
|
+
() => finish(write),
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function onAbandon(listener: () => void): () => void {
|
|
45
|
+
abandonListeners.add(listener);
|
|
46
|
+
return () => {
|
|
47
|
+
abandonListeners.delete(listener);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// For work that reached disk some other way after its tracked write failed.
|
|
52
|
+
export function forgetWrite(key: unknown): void {
|
|
53
|
+
failed.delete(key);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export function unsavedStatus(): UnsavedStatus {
|
|
57
|
+
let drafts = false;
|
|
58
|
+
let pending = writes.size > 0 || failed.size > 0;
|
|
59
|
+
for (const source of sources) {
|
|
60
|
+
if (!source.dirty()) continue;
|
|
61
|
+
if (source.kind === 'draft') drafts = true;
|
|
62
|
+
else pending = true;
|
|
63
|
+
}
|
|
64
|
+
return { drafts, pending };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function hasUnsaved(): boolean {
|
|
68
|
+
const { drafts, pending } = unsavedStatus();
|
|
69
|
+
return drafts || pending;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function describe(error: unknown): string {
|
|
73
|
+
return error instanceof Error ? error.message : String(error);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export async function settleUnsaved(action: UnsavedAction): Promise<UnsavedOutcome> {
|
|
77
|
+
const errors: string[] = [];
|
|
78
|
+
for (const source of [...sources]) {
|
|
79
|
+
if (!source.dirty()) continue;
|
|
80
|
+
if (action === 'abandon' || (action === 'discard' && source.kind === 'draft')) {
|
|
81
|
+
source.discard();
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
await source.save();
|
|
86
|
+
} catch (err) {
|
|
87
|
+
errors.push(describe(err));
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (action === 'abandon') {
|
|
91
|
+
// In-flight writes too, so one that fails later is not kept for a retry.
|
|
92
|
+
writes.clear();
|
|
93
|
+
failed.clear();
|
|
94
|
+
for (const listener of abandonListeners) listener();
|
|
95
|
+
return { ok: true };
|
|
96
|
+
}
|
|
97
|
+
for (const [key, write] of [...failed]) trackWrite(key, write);
|
|
98
|
+
for (const result of await Promise.allSettled([...writes.values()])) {
|
|
99
|
+
if (result.status === 'rejected') errors.push(describe(result.reason));
|
|
100
|
+
}
|
|
101
|
+
if (errors.length > 0) return { ok: false, error: errors.join(' ') };
|
|
102
|
+
if (hasUnsaved()) {
|
|
103
|
+
return { ok: false, error: 'More changes were made while saving.' };
|
|
104
|
+
}
|
|
105
|
+
return { ok: true };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function useUnsavedSource(source: UnsavedSource) {
|
|
109
|
+
const latest = useRef(source);
|
|
110
|
+
latest.current = source;
|
|
111
|
+
const { kind } = source;
|
|
112
|
+
useEffect(
|
|
113
|
+
() =>
|
|
114
|
+
registerUnsaved({
|
|
115
|
+
kind,
|
|
116
|
+
dirty: () => latest.current.dirty(),
|
|
117
|
+
save: () => latest.current.save(),
|
|
118
|
+
discard: () => latest.current.discard(),
|
|
119
|
+
}),
|
|
120
|
+
[kind],
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// For writes that carry no base revision: a retried one would otherwise replace
|
|
125
|
+
// a value that a newer write has saved since.
|
|
126
|
+
export function createWriteLedger() {
|
|
127
|
+
let seq = 0;
|
|
128
|
+
const saved = new Map<string, number>();
|
|
129
|
+
const superseded = (key: string, writeSeq: number) =>
|
|
130
|
+
(saved.get(key) ?? Number.NEGATIVE_INFINITY) > writeSeq;
|
|
131
|
+
return {
|
|
132
|
+
next: () => ++seq,
|
|
133
|
+
superseded,
|
|
134
|
+
record(key: string, writeSeq: number) {
|
|
135
|
+
if (!superseded(key, writeSeq)) saved.set(key, writeSeq);
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Runs saves one after another, each starting once the previous one settles.
|
|
141
|
+
export function createSaveQueue() {
|
|
142
|
+
let tail: Promise<unknown> = Promise.resolve();
|
|
143
|
+
let size = 0;
|
|
144
|
+
return {
|
|
145
|
+
run<T>(task: () => Promise<T>, onIdle?: () => void): Promise<T> {
|
|
146
|
+
size++;
|
|
147
|
+
const result = tail.then(task).finally(() => {
|
|
148
|
+
if (--size === 0) onIdle?.();
|
|
149
|
+
});
|
|
150
|
+
tail = result.catch(() => {});
|
|
151
|
+
return result;
|
|
152
|
+
},
|
|
153
|
+
busy: () => size > 0,
|
|
154
|
+
};
|
|
155
|
+
}
|
package/src/app/routes/home.tsx
CHANGED
|
@@ -592,7 +592,7 @@ function SlideCard({
|
|
|
592
592
|
<button
|
|
593
593
|
type="button"
|
|
594
594
|
onClick={(e) => e.stopPropagation()}
|
|
595
|
-
className="flex size-7 items-center justify-center rounded-[5px] bg-
|
|
595
|
+
className="flex size-7 items-center justify-center rounded-[5px] bg-material text-foreground shadow-edge ring-1 ring-border opacity-0 outline-none backdrop-blur-xl backdrop-saturate-150 hover:bg-card group-hover:opacity-100 focus-visible:opacity-100 focus-visible:ring-ring/40 aria-expanded:opacity-100 motion-safe:transition-opacity motion-safe:duration-150"
|
|
596
596
|
aria-label={tCard.home.slideActions}
|
|
597
597
|
>
|
|
598
598
|
<MoreHorizontal className="size-3.5" />
|
package/src/app/routes/slide.tsx
CHANGED
|
@@ -62,8 +62,13 @@ import {
|
|
|
62
62
|
DropdownMenuTrigger,
|
|
63
63
|
} from '@/components/ui/dropdown-menu';
|
|
64
64
|
import { Tabs, TabsList, TabsTrigger } from '@/components/ui/tabs';
|
|
65
|
-
import {
|
|
66
|
-
|
|
65
|
+
import {
|
|
66
|
+
setDockOpen,
|
|
67
|
+
useAgentActivity,
|
|
68
|
+
useAgentDock,
|
|
69
|
+
useSessionHandoff,
|
|
70
|
+
} from '@/lib/agent/use-agent';
|
|
71
|
+
import { openHomeInHost } from '@/lib/desktop';
|
|
67
72
|
import { useFolders } from '@/lib/folders';
|
|
68
73
|
import {
|
|
69
74
|
hasModifier,
|
|
@@ -73,7 +78,6 @@ import {
|
|
|
73
78
|
isTypingTarget,
|
|
74
79
|
} from '@/lib/keys';
|
|
75
80
|
import { readLastHomeLocation } from '@/lib/last-home-location';
|
|
76
|
-
import { useAgentSocketConnected } from '@/lib/use-agent-socket';
|
|
77
81
|
import { useClickPageNavigation } from '@/lib/use-click-page-navigation';
|
|
78
82
|
import { useDocumentTitle } from '@/lib/use-document-title';
|
|
79
83
|
import { useIsMobile } from '@/lib/use-is-mobile';
|
|
@@ -104,7 +108,7 @@ import {
|
|
|
104
108
|
exportSlideAsPptx,
|
|
105
109
|
type PptxExportProgress,
|
|
106
110
|
} from '../lib/export-pptx';
|
|
107
|
-
import {
|
|
111
|
+
import { changeNotesPages } from '../lib/inspector/use-notes';
|
|
108
112
|
import type { SlideModule } from '../lib/sdk';
|
|
109
113
|
import { usePrefersReducedMotion } from '../lib/use-prefers-reduced-motion';
|
|
110
114
|
import { useSlideModule } from '../lib/use-slide-module';
|
|
@@ -113,6 +117,12 @@ const { showSlideUi, showSlideBrowser, allowHtmlDownload } = config.build;
|
|
|
113
117
|
|
|
114
118
|
const noop = () => {};
|
|
115
119
|
|
|
120
|
+
type PagePlan = {
|
|
121
|
+
order: number[];
|
|
122
|
+
request: string;
|
|
123
|
+
init: RequestInit;
|
|
124
|
+
};
|
|
125
|
+
|
|
116
126
|
export function Slide() {
|
|
117
127
|
const { slideId = '' } = useParams();
|
|
118
128
|
const [searchParams, setSearchParams] = useSearchParams();
|
|
@@ -120,6 +130,7 @@ export function Slide() {
|
|
|
120
130
|
// react-router records its entry index in history.state; going back is only
|
|
121
131
|
// safe when we actually pushed an entry, otherwise land on the last home view.
|
|
122
132
|
const goBack = useCallback(() => {
|
|
133
|
+
if (openHomeInHost()) return;
|
|
123
134
|
const idx = (window.history.state as { idx?: number } | null)?.idx ?? 0;
|
|
124
135
|
if (idx > 0) {
|
|
125
136
|
navigate(-1);
|
|
@@ -147,6 +158,7 @@ export function Slide() {
|
|
|
147
158
|
const [overviewOpen, setOverviewOpen] = useState(false);
|
|
148
159
|
const [commandOpen, setCommandOpen] = useState(false);
|
|
149
160
|
const { open: agentOpen, toggle: toggleAgent } = useAgentDock();
|
|
161
|
+
useSessionHandoff(slideId);
|
|
150
162
|
useLayoutEffect(() => {
|
|
151
163
|
if (agentOpen) setDesignOpen(false);
|
|
152
164
|
}, [agentOpen]);
|
|
@@ -221,11 +233,16 @@ export function Slide() {
|
|
|
221
233
|
};
|
|
222
234
|
}, [curtain, playMode]);
|
|
223
235
|
|
|
236
|
+
const routedRef = useRef(slideId);
|
|
237
|
+
routedRef.current = slideId;
|
|
224
238
|
const modulePages = useMemo(() => slide?.default ?? [], [slide]);
|
|
225
|
-
|
|
239
|
+
// Tagged with its deck: right after a route change the old deck's module is
|
|
240
|
+
// still loaded under the new slideId.
|
|
241
|
+
const [deck, setDeck] = useState({ slideId, pages: modulePages });
|
|
226
242
|
useEffect(() => {
|
|
227
|
-
|
|
243
|
+
setDeck({ slideId: routedRef.current, pages: modulePages });
|
|
228
244
|
}, [modulePages]);
|
|
245
|
+
const pages = deck.pages;
|
|
229
246
|
const pageCount = pages.length;
|
|
230
247
|
const rawIndex = Number(searchParams.get('p') ?? '1') - 1;
|
|
231
248
|
const index = Number.isFinite(rawIndex) ? Math.max(0, Math.min(pageCount - 1, rawIndex)) : 0;
|
|
@@ -250,19 +267,23 @@ export function Slide() {
|
|
|
250
267
|
[navigate],
|
|
251
268
|
);
|
|
252
269
|
|
|
253
|
-
const
|
|
270
|
+
const showPage = useCallback(
|
|
254
271
|
(i: number) => {
|
|
255
|
-
const clamped = Math.max(0, Math.min(pageCount - 1, i));
|
|
256
272
|
setSearchParams(
|
|
257
273
|
(prev) => {
|
|
258
274
|
const next = new URLSearchParams(prev);
|
|
259
|
-
next.set('p', String(
|
|
275
|
+
next.set('p', String(i + 1));
|
|
260
276
|
return next;
|
|
261
277
|
},
|
|
262
278
|
{ replace: true },
|
|
263
279
|
);
|
|
264
280
|
},
|
|
265
|
-
[
|
|
281
|
+
[setSearchParams],
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
const goTo = useCallback(
|
|
285
|
+
(i: number) => showPage(Math.max(0, Math.min(pageCount - 1, i))),
|
|
286
|
+
[pageCount, showPage],
|
|
266
287
|
);
|
|
267
288
|
|
|
268
289
|
// While an agent writes this deck page by page, jump to each page as it
|
|
@@ -275,104 +296,114 @@ export function Slide() {
|
|
|
275
296
|
seenPageCount.current = pageCount;
|
|
276
297
|
}, [agentWriting, pageCount, goTo]);
|
|
277
298
|
|
|
299
|
+
const deckRef = useRef(deck);
|
|
300
|
+
deckRef.current = deck;
|
|
301
|
+
const indexRef = useRef(index);
|
|
302
|
+
indexRef.current = index;
|
|
303
|
+
|
|
304
|
+
// Notes can be mid-save when a page op is asked for, so the op is planned from
|
|
305
|
+
// the pages and position current once those writes settle, and dropped if the
|
|
306
|
+
// route has moved to another deck by then.
|
|
307
|
+
const changePages = useCallback(
|
|
308
|
+
(plan: (order: number[]) => PagePlan | null) =>
|
|
309
|
+
changeNotesPages(slideId, () => {
|
|
310
|
+
const { slideId: owner, pages: before } = deckRef.current;
|
|
311
|
+
if (routedRef.current !== slideId || owner !== slideId) return null;
|
|
312
|
+
const at = indexRef.current;
|
|
313
|
+
const next = plan(before.map((_, i) => i));
|
|
314
|
+
if (!next) return null;
|
|
315
|
+
const moved = next.order.map((i) => before[i]);
|
|
316
|
+
const position = next.order.indexOf(at);
|
|
317
|
+
const nextIndex = position < 0 ? Math.min(at, next.order.length - 1) : position;
|
|
318
|
+
return {
|
|
319
|
+
order: next.order,
|
|
320
|
+
apply: async () => {
|
|
321
|
+
setDeck({ slideId, pages: moved });
|
|
322
|
+
if (nextIndex !== at) showPage(nextIndex);
|
|
323
|
+
const res = await fetch(next.request, next.init);
|
|
324
|
+
const body = (await res.json().catch(() => ({ error: res.statusText }))) as {
|
|
325
|
+
error?: string;
|
|
326
|
+
layout?: string;
|
|
327
|
+
};
|
|
328
|
+
if (!res.ok) throw new Error(body.error ?? `HTTP ${res.status}`);
|
|
329
|
+
return body.layout;
|
|
330
|
+
},
|
|
331
|
+
revert: () => {
|
|
332
|
+
setDeck((current) => (current.pages === moved ? { slideId, pages: before } : current));
|
|
333
|
+
if (nextIndex !== at && routedRef.current === slideId) showPage(at);
|
|
334
|
+
},
|
|
335
|
+
};
|
|
336
|
+
}),
|
|
337
|
+
[slideId, showPage],
|
|
338
|
+
);
|
|
339
|
+
|
|
278
340
|
const reorderPage = useCallback(
|
|
279
341
|
async (from: number, to: number) => {
|
|
280
342
|
if (from === to) return;
|
|
281
|
-
const before = pages;
|
|
282
|
-
const nextPages = [...before];
|
|
283
|
-
const [moved] = nextPages.splice(from, 1);
|
|
284
|
-
nextPages.splice(to, 0, moved);
|
|
285
|
-
setPages(nextPages);
|
|
286
|
-
|
|
287
|
-
const order = before.map((_, i) => i);
|
|
288
|
-
const [movedIdx] = order.splice(from, 1);
|
|
289
|
-
order.splice(to, 0, movedIdx);
|
|
290
|
-
|
|
291
|
-
remapNotesSessionCacheAfterReorder(slideId, order);
|
|
292
|
-
|
|
293
|
-
// Keep the user looking at the same page they were on before the drag.
|
|
294
|
-
let nextIndex = index;
|
|
295
|
-
if (index === from) nextIndex = to;
|
|
296
|
-
else if (from < index && to >= index) nextIndex = index - 1;
|
|
297
|
-
else if (from > index && to <= index) nextIndex = index + 1;
|
|
298
|
-
if (nextIndex !== index) goTo(nextIndex);
|
|
299
|
-
|
|
300
343
|
try {
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
344
|
+
await changePages((order) => {
|
|
345
|
+
if (from < 0 || to < 0 || from >= order.length || to >= order.length) return null;
|
|
346
|
+
const [moved] = order.splice(from, 1);
|
|
347
|
+
order.splice(to, 0, moved);
|
|
348
|
+
return {
|
|
349
|
+
order,
|
|
350
|
+
request: `/__slides/${encodeURIComponent(slideId)}/reorder`,
|
|
351
|
+
init: {
|
|
352
|
+
method: 'PUT',
|
|
353
|
+
headers: { 'content-type': 'application/json' },
|
|
354
|
+
body: JSON.stringify({ order }),
|
|
355
|
+
},
|
|
356
|
+
};
|
|
305
357
|
});
|
|
306
|
-
if (!res.ok) {
|
|
307
|
-
const detail = await res.json().catch(() => ({ error: res.statusText }));
|
|
308
|
-
throw new Error(detail.error ?? `HTTP ${res.status}`);
|
|
309
|
-
}
|
|
310
358
|
} catch (err) {
|
|
311
|
-
setPages(before);
|
|
312
|
-
const inverse = order.map((_, i) => order.indexOf(i));
|
|
313
|
-
remapNotesSessionCacheAfterReorder(slideId, inverse);
|
|
314
359
|
toast.error(`Reorder failed: ${String((err as Error).message ?? err)}`);
|
|
315
360
|
}
|
|
316
361
|
},
|
|
317
|
-
[
|
|
362
|
+
[slideId, changePages],
|
|
318
363
|
);
|
|
319
364
|
|
|
320
365
|
const duplicatePage = useCallback(
|
|
321
366
|
async (i: number) => {
|
|
322
|
-
const before = pages;
|
|
323
|
-
if (i < 0 || i >= before.length) return;
|
|
324
|
-
const nextPages = [...before];
|
|
325
|
-
nextPages.splice(i + 1, 0, before[i]);
|
|
326
|
-
setPages(nextPages);
|
|
327
|
-
if (index > i) goTo(index + 1);
|
|
328
|
-
|
|
329
367
|
try {
|
|
330
|
-
const
|
|
331
|
-
|
|
368
|
+
const changed = await changePages((order) => {
|
|
369
|
+
if (i < 0 || i >= order.length) return null;
|
|
370
|
+
order.splice(i + 1, 0, i);
|
|
371
|
+
return {
|
|
372
|
+
order,
|
|
373
|
+
request: `/__slides/${encodeURIComponent(slideId)}/pages/${i}/duplicate`,
|
|
374
|
+
init: { method: 'POST' },
|
|
375
|
+
};
|
|
332
376
|
});
|
|
333
|
-
if (
|
|
334
|
-
const detail = await res.json().catch(() => ({ error: res.statusText }));
|
|
335
|
-
throw new Error(detail.error ?? `HTTP ${res.status}`);
|
|
336
|
-
}
|
|
337
|
-
toast.success(format(t.thumbnailRail.toastDuplicated, { n: i + 1 }));
|
|
377
|
+
if (changed) toast.success(format(t.thumbnailRail.toastDuplicated, { n: i + 1 }));
|
|
338
378
|
} catch (err) {
|
|
339
|
-
setPages(before);
|
|
340
379
|
toast.error(
|
|
341
380
|
`${t.thumbnailRail.toastDuplicateFailed}: ${String((err as Error).message ?? err)}`,
|
|
342
381
|
);
|
|
343
382
|
}
|
|
344
383
|
},
|
|
345
|
-
[
|
|
384
|
+
[slideId, changePages, t.thumbnailRail],
|
|
346
385
|
);
|
|
347
386
|
|
|
348
387
|
const deletePage = useCallback(
|
|
349
388
|
async (i: number) => {
|
|
350
|
-
const before = pages;
|
|
351
|
-
if (i < 0 || i >= before.length || before.length <= 1) return;
|
|
352
|
-
const nextPages = before.slice(0, i).concat(before.slice(i + 1));
|
|
353
|
-
setPages(nextPages);
|
|
354
|
-
if (index >= i && index > 0) {
|
|
355
|
-
const target = index === i ? Math.min(index, nextPages.length - 1) : index - 1;
|
|
356
|
-
goTo(target);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
389
|
try {
|
|
360
|
-
const
|
|
361
|
-
|
|
390
|
+
const changed = await changePages((order) => {
|
|
391
|
+
if (i < 0 || i >= order.length || order.length <= 1) return null;
|
|
392
|
+
order.splice(i, 1);
|
|
393
|
+
return {
|
|
394
|
+
order,
|
|
395
|
+
request: `/__slides/${encodeURIComponent(slideId)}/pages/${i}`,
|
|
396
|
+
init: { method: 'DELETE' },
|
|
397
|
+
};
|
|
362
398
|
});
|
|
363
|
-
if (
|
|
364
|
-
const detail = await res.json().catch(() => ({ error: res.statusText }));
|
|
365
|
-
throw new Error(detail.error ?? `HTTP ${res.status}`);
|
|
366
|
-
}
|
|
367
|
-
toast.success(format(t.thumbnailRail.toastDeleted, { n: i + 1 }));
|
|
399
|
+
if (changed) toast.success(format(t.thumbnailRail.toastDeleted, { n: i + 1 }));
|
|
368
400
|
} catch (err) {
|
|
369
|
-
setPages(before);
|
|
370
401
|
toast.error(
|
|
371
402
|
`${t.thumbnailRail.toastDeleteFailed}: ${String((err as Error).message ?? err)}`,
|
|
372
403
|
);
|
|
373
404
|
}
|
|
374
405
|
},
|
|
375
|
-
[
|
|
406
|
+
[slideId, changePages, t.thumbnailRail],
|
|
376
407
|
);
|
|
377
408
|
|
|
378
409
|
const thumbnailActions = useMemo<ThumbnailActions | undefined>(
|
|
@@ -745,7 +776,6 @@ export function Slide() {
|
|
|
745
776
|
</TabsList>
|
|
746
777
|
</Tabs>
|
|
747
778
|
)}
|
|
748
|
-
{import.meta.env.DEV && <AgentConnectedBadge />}
|
|
749
779
|
</div>
|
|
750
780
|
|
|
751
781
|
<div className="col-span-3 row-start-2 flex min-w-0 justify-center sm:col-span-1 sm:col-start-2 sm:row-start-1">
|
|
@@ -971,6 +1001,14 @@ export function Slide() {
|
|
|
971
1001
|
designOpen={designOpen}
|
|
972
1002
|
onCloseDesign={() => setDesignOpen(false)}
|
|
973
1003
|
agentOpen={agentOpen}
|
|
1004
|
+
page={{
|
|
1005
|
+
index,
|
|
1006
|
+
total: pageCount,
|
|
1007
|
+
component: pages[index],
|
|
1008
|
+
transition: pages[index]?.transition ?? slide.transition,
|
|
1009
|
+
inheritedTransition: !pages[index]?.transition && Boolean(slide.transition),
|
|
1010
|
+
themed: Boolean(slide.design),
|
|
1011
|
+
}}
|
|
974
1012
|
agent={
|
|
975
1013
|
import.meta.env.DEV && (
|
|
976
1014
|
<SlideAgentDock
|
|
@@ -1152,47 +1190,6 @@ function SlideAgentDock({
|
|
|
1152
1190
|
return <AgentPanel context={context} onClose={() => setDockOpen(false)} />;
|
|
1153
1191
|
}
|
|
1154
1192
|
|
|
1155
|
-
function AgentConnectedBadge() {
|
|
1156
|
-
const t = useLocale();
|
|
1157
|
-
const connected = useAgentSocketConnected();
|
|
1158
|
-
return (
|
|
1159
|
-
<TooltipProvider delay={200}>
|
|
1160
|
-
<Tooltip>
|
|
1161
|
-
<TooltipTrigger
|
|
1162
|
-
render={
|
|
1163
|
-
<button
|
|
1164
|
-
type="button"
|
|
1165
|
-
aria-label={connected ? t.slide.agentConnected : t.slide.agentDisconnected}
|
|
1166
|
-
className="ml-1 flex shrink-0 cursor-help items-center gap-1.5 rounded-[3px] border border-hairline bg-card px-1.5 py-0.5 text-[10.5px] text-foreground/85 outline-none transition-colors duration-150 hover:bg-muted/50 focus-visible:ring-2 focus-visible:ring-ring/30"
|
|
1167
|
-
>
|
|
1168
|
-
<span aria-hidden className="relative flex size-1.5 items-center justify-center">
|
|
1169
|
-
{connected ? (
|
|
1170
|
-
<>
|
|
1171
|
-
<span className="absolute inline-flex size-full rounded-full bg-emerald-500 opacity-60 motion-safe:animate-ping" />
|
|
1172
|
-
<span className="relative inline-flex size-1.5 rounded-full bg-emerald-500" />
|
|
1173
|
-
</>
|
|
1174
|
-
) : (
|
|
1175
|
-
<span className="relative inline-flex size-1.5 rounded-full bg-rose-500" />
|
|
1176
|
-
)}
|
|
1177
|
-
</span>
|
|
1178
|
-
<span className="hidden xl:inline">
|
|
1179
|
-
{connected ? t.slide.agentConnected : t.slide.agentDisconnected}
|
|
1180
|
-
</span>
|
|
1181
|
-
</button>
|
|
1182
|
-
}
|
|
1183
|
-
/>
|
|
1184
|
-
<TooltipContent
|
|
1185
|
-
side="bottom"
|
|
1186
|
-
align="start"
|
|
1187
|
-
className="w-max max-w-[min(520px,calc(100vw-2rem))] text-center leading-relaxed"
|
|
1188
|
-
>
|
|
1189
|
-
{connected ? t.slide.agentConnectedTooltip : t.slide.agentDisconnectedTooltip}
|
|
1190
|
-
</TooltipContent>
|
|
1191
|
-
</Tooltip>
|
|
1192
|
-
</TooltipProvider>
|
|
1193
|
-
);
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
1193
|
function SelectionReporter() {
|
|
1197
1194
|
const { selected } = useInspector();
|
|
1198
1195
|
useEffect(() => {
|