@open-slide/core 2.3.1 → 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-CDrYgaEj.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-DFK02XVv.d.ts → types-ZfArJF0d.d.ts} +21 -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-B1pkKQsc.js → zh-tw-D7LfGVmA.js} +220 -65
- package/package.json +5 -6
- 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/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/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/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 +14 -6
- package/src/app/routes/slide.tsx +184 -130
- package/src/app/styles.css +421 -1
- package/src/locale/en.ts +41 -15
- package/src/locale/es.ts +41 -17
- package/src/locale/ja.ts +41 -15
- package/src/locale/types.ts +20 -14
- package/src/locale/zh-cn.ts +41 -14
- package/src/locale/zh-tw.ts +41 -14
|
@@ -12,9 +12,16 @@ import { usePrefersReducedMotion } from '../lib/use-prefers-reduced-motion';
|
|
|
12
12
|
import { OverviewGrid } from './overview-grid';
|
|
13
13
|
import { PresentBlackoutOverlay } from './present/blackout-overlay';
|
|
14
14
|
import { PresentControlBar } from './present/control-bar';
|
|
15
|
+
import {
|
|
16
|
+
afterPaint,
|
|
17
|
+
CURTAIN_FADE_MS,
|
|
18
|
+
PresentCurtain,
|
|
19
|
+
whenFullscreenSettled,
|
|
20
|
+
} from './present/curtain';
|
|
15
21
|
import { PresentHelpOverlay } from './present/help-overlay';
|
|
16
22
|
import { PresentJumpInput } from './present/jump-input';
|
|
17
23
|
import { PresentLaserPointer } from './present/laser-pointer';
|
|
24
|
+
import { PresentLastSlideHint } from './present/last-slide-hint';
|
|
18
25
|
import { PresentProgressBar } from './present/progress-bar';
|
|
19
26
|
import { useIdle } from './present/use-idle';
|
|
20
27
|
import { usePointerNearBottom } from './present/use-pointer-near-bottom';
|
|
@@ -48,6 +55,8 @@ type Props = {
|
|
|
48
55
|
* without entering fullscreen. Defaults to true for back-compat.
|
|
49
56
|
*/
|
|
50
57
|
fullscreen?: boolean;
|
|
58
|
+
/** Fade in from black on mount and fade to black before calling `onExit`. */
|
|
59
|
+
curtain?: boolean;
|
|
51
60
|
};
|
|
52
61
|
|
|
53
62
|
export function Player({
|
|
@@ -62,9 +71,13 @@ export function Player({
|
|
|
62
71
|
slideId,
|
|
63
72
|
onSwitchSlide,
|
|
64
73
|
fullscreen = true,
|
|
74
|
+
curtain = false,
|
|
65
75
|
}: Props) {
|
|
66
76
|
const isMobile = useIsMobile();
|
|
67
77
|
const prefersReducedMotion = usePrefersReducedMotion();
|
|
78
|
+
const fade = curtain && !prefersReducedMotion;
|
|
79
|
+
const [curtainOpaque, setCurtainOpaque] = useState(fade);
|
|
80
|
+
const exitingRef = useRef(false);
|
|
68
81
|
const rootRef = useRef<HTMLDivElement | null>(null);
|
|
69
82
|
// Mirrored as state so descendants portaling *into* the player subtree
|
|
70
83
|
// (tooltips, popovers — the body is outside the fullscreen tree) re-render
|
|
@@ -93,6 +106,28 @@ export function Player({
|
|
|
93
106
|
const canPrev = index > 0;
|
|
94
107
|
const canNext = index < pages.length - 1;
|
|
95
108
|
|
|
109
|
+
// Stepping past either end nudges the slide like a rubber band so the
|
|
110
|
+
// press visibly registered; past the last slide a hint says how to leave.
|
|
111
|
+
const nudgeRef = useRef<HTMLDivElement | null>(null);
|
|
112
|
+
const [lastSlideHintAt, setLastSlideHintAt] = useState(0);
|
|
113
|
+
const bumpEdge = useCallback(
|
|
114
|
+
(direction: 'start' | 'end') => {
|
|
115
|
+
if (!controls) return;
|
|
116
|
+
if (direction === 'end') setLastSlideHintAt(Date.now());
|
|
117
|
+
if (prefersReducedMotion) return;
|
|
118
|
+
const offset = direction === 'end' ? -14 : 14;
|
|
119
|
+
nudgeRef.current?.animate(
|
|
120
|
+
[
|
|
121
|
+
{ transform: 'translateX(0)' },
|
|
122
|
+
{ transform: `translateX(${offset}px)`, offset: 0.3 },
|
|
123
|
+
{ transform: 'translateX(0)' },
|
|
124
|
+
],
|
|
125
|
+
{ duration: 360, easing: 'cubic-bezier(0.2, 0.8, 0.3, 1)' },
|
|
126
|
+
);
|
|
127
|
+
},
|
|
128
|
+
[controls, prefersReducedMotion],
|
|
129
|
+
);
|
|
130
|
+
|
|
96
131
|
const stepControllerRef = useRef<StepController | null>(null);
|
|
97
132
|
const [entryDirection, setEntryDirection] = useState<EntryDirection>('jump');
|
|
98
133
|
const [stepAggregate, setStepAggregate] = useState<StepAggregate>({
|
|
@@ -116,14 +151,34 @@ export function Player({
|
|
|
116
151
|
[index, onIndexChange],
|
|
117
152
|
);
|
|
118
153
|
|
|
154
|
+
const exitTimerRef = useRef<number | null>(null);
|
|
155
|
+
useEffect(
|
|
156
|
+
() => () => {
|
|
157
|
+
if (exitTimerRef.current !== null) window.clearTimeout(exitTimerRef.current);
|
|
158
|
+
},
|
|
159
|
+
[],
|
|
160
|
+
);
|
|
161
|
+
const requestExit = useCallback(() => {
|
|
162
|
+
if (!fade) {
|
|
163
|
+
onExit();
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (exitingRef.current) return;
|
|
167
|
+
exitingRef.current = true;
|
|
168
|
+
setCurtainOpaque(true);
|
|
169
|
+
exitTimerRef.current = window.setTimeout(onExit, CURTAIN_FADE_MS);
|
|
170
|
+
}, [fade, onExit]);
|
|
171
|
+
|
|
119
172
|
const goPrev = useCallback(() => {
|
|
120
173
|
if (stepControllerRef.current?.retreat()) return;
|
|
121
174
|
if (index > 0) handleIndexChange(index - 1);
|
|
122
|
-
|
|
175
|
+
else bumpEdge('start');
|
|
176
|
+
}, [index, handleIndexChange, bumpEdge]);
|
|
123
177
|
const goNext = useCallback(() => {
|
|
124
178
|
if (stepControllerRef.current?.advance()) return;
|
|
125
179
|
if (index < pages.length - 1) handleIndexChange(index + 1);
|
|
126
|
-
|
|
180
|
+
else bumpEdge('end');
|
|
181
|
+
}, [index, pages.length, handleIndexChange, bumpEdge]);
|
|
127
182
|
|
|
128
183
|
const overlayActive = controls && (overviewOpen || helpOpen);
|
|
129
184
|
const overlayActiveRef = useRef(overlayActive);
|
|
@@ -178,8 +233,8 @@ export function Player({
|
|
|
178
233
|
useClickPageNavigation({
|
|
179
234
|
ref: rootRef,
|
|
180
235
|
enabled: !overlayActive,
|
|
181
|
-
canPrev,
|
|
182
|
-
canNext,
|
|
236
|
+
canPrev: canPrev || controls,
|
|
237
|
+
canNext: canNext || controls,
|
|
183
238
|
onPrev: goPrev,
|
|
184
239
|
onNext: goNext,
|
|
185
240
|
onViewportClick: controls && isMobile ? handleMobileViewportClick : undefined,
|
|
@@ -216,11 +271,33 @@ export function Player({
|
|
|
216
271
|
useEffect(() => {
|
|
217
272
|
if (!allowExit) return;
|
|
218
273
|
const onFsChange = () => {
|
|
219
|
-
if (!document.fullscreenElement && !windowedRef.current)
|
|
274
|
+
if (!document.fullscreenElement && !windowedRef.current) requestExit();
|
|
220
275
|
};
|
|
221
276
|
document.addEventListener('fullscreenchange', onFsChange);
|
|
222
277
|
return () => document.removeEventListener('fullscreenchange', onFsChange);
|
|
223
|
-
}, [
|
|
278
|
+
}, [requestExit, allowExit]);
|
|
279
|
+
|
|
280
|
+
// Wait out the browser's own fullscreen animation before revealing the
|
|
281
|
+
// first slide, otherwise the fade plays while the screen is still resizing.
|
|
282
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: runs once on mount
|
|
283
|
+
useEffect(() => {
|
|
284
|
+
if (!fade) return;
|
|
285
|
+
let cancelPaint = () => {};
|
|
286
|
+
const reveal = () => {
|
|
287
|
+
cancelPaint = afterPaint(() => {
|
|
288
|
+
if (!exitingRef.current) setCurtainOpaque(false);
|
|
289
|
+
});
|
|
290
|
+
};
|
|
291
|
+
if (!fullscreen || document.fullscreenElement) {
|
|
292
|
+
reveal();
|
|
293
|
+
return () => cancelPaint();
|
|
294
|
+
}
|
|
295
|
+
const cancelWait = whenFullscreenSettled(reveal);
|
|
296
|
+
return () => {
|
|
297
|
+
cancelWait();
|
|
298
|
+
cancelPaint();
|
|
299
|
+
};
|
|
300
|
+
}, []);
|
|
224
301
|
|
|
225
302
|
const toggleFullscreen = useCallback(() => {
|
|
226
303
|
setWindowed((w) => !w);
|
|
@@ -296,7 +373,7 @@ export function Player({
|
|
|
296
373
|
setBlackout(null);
|
|
297
374
|
return;
|
|
298
375
|
}
|
|
299
|
-
if (allowExit)
|
|
376
|
+
if (allowExit) requestExit();
|
|
300
377
|
return;
|
|
301
378
|
}
|
|
302
379
|
|
|
@@ -364,7 +441,7 @@ export function Player({
|
|
|
364
441
|
helpOpen,
|
|
365
442
|
blackout,
|
|
366
443
|
allowExit,
|
|
367
|
-
|
|
444
|
+
requestExit,
|
|
368
445
|
goNext,
|
|
369
446
|
goPrev,
|
|
370
447
|
handleIndexChange,
|
|
@@ -403,26 +480,29 @@ export function Player({
|
|
|
403
480
|
controls && (hideCursor ? 'cursor-none' : 'cursor-default'),
|
|
404
481
|
)}
|
|
405
482
|
>
|
|
406
|
-
<
|
|
407
|
-
|
|
483
|
+
<div ref={nudgeRef} className="h-full w-full">
|
|
484
|
+
<SlideCanvas flat design={design}>
|
|
485
|
+
{/* Keyed per deck so a presenter-driven deck switch cuts instead of
|
|
408
486
|
animating a transition between two unrelated decks. */}
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
487
|
+
<SlideTransitionLayer
|
|
488
|
+
key={slideId}
|
|
489
|
+
pages={pages}
|
|
490
|
+
index={index}
|
|
491
|
+
total={pages.length}
|
|
492
|
+
moduleTransition={transition}
|
|
493
|
+
disabled={prefersReducedMotion}
|
|
494
|
+
stepControllerRef={stepControllerRef}
|
|
495
|
+
entryDirection={entryDirection}
|
|
496
|
+
onStepAggregateChange={handleAggregateChange}
|
|
497
|
+
/>
|
|
498
|
+
</SlideCanvas>
|
|
499
|
+
</div>
|
|
421
500
|
|
|
422
501
|
{controls && (
|
|
423
502
|
<div data-osd-chrome style={{ display: 'contents' }}>
|
|
424
503
|
<PresentProgressBar index={index} total={pages.length} visible={chromeVisible} />
|
|
425
504
|
<PresentBlackoutOverlay mode={blackout} />
|
|
505
|
+
<PresentLastSlideHint shownAt={lastSlideHintAt} />
|
|
426
506
|
<PresentJumpInput pageCount={pages.length} onJump={handleIndexChange} />
|
|
427
507
|
<PresentLaserPointer enabled={laser} />
|
|
428
508
|
<PresentControlBar
|
|
@@ -444,7 +524,7 @@ export function Player({
|
|
|
444
524
|
onPresenter={() => slideId && openPresenterWindow(slideId)}
|
|
445
525
|
onToggleFullscreen={toggleFullscreen}
|
|
446
526
|
onHelp={() => setHelpOpen(true)}
|
|
447
|
-
onExit={
|
|
527
|
+
onExit={requestExit}
|
|
448
528
|
/>
|
|
449
529
|
<OverviewGrid
|
|
450
530
|
pages={pages}
|
|
@@ -460,6 +540,8 @@ export function Player({
|
|
|
460
540
|
<PresentHelpOverlay open={helpOpen} onOpenChange={setHelpOpen} container={rootEl} />
|
|
461
541
|
</div>
|
|
462
542
|
)}
|
|
543
|
+
|
|
544
|
+
{fade && <PresentCurtain opaque={curtainOpaque} className="absolute z-[100]" />}
|
|
463
545
|
</div>
|
|
464
546
|
);
|
|
465
547
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { cn } from '@/lib/utils';
|
|
2
|
+
|
|
3
|
+
export const CURTAIN_FADE_MS = 400;
|
|
4
|
+
|
|
5
|
+
type Props = {
|
|
6
|
+
opaque: boolean;
|
|
7
|
+
className?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export function PresentCurtain({ opaque, className }: Props) {
|
|
11
|
+
return (
|
|
12
|
+
<div
|
|
13
|
+
aria-hidden
|
|
14
|
+
className={cn(
|
|
15
|
+
'pointer-events-none inset-0 bg-black transition-opacity ease-in-out',
|
|
16
|
+
opaque ? 'opacity-100' : 'opacity-0',
|
|
17
|
+
className,
|
|
18
|
+
)}
|
|
19
|
+
style={{ transitionDuration: `${CURTAIN_FADE_MS}ms` }}
|
|
20
|
+
/>
|
|
21
|
+
);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Two frames so the opaque state is painted before the fade starts;
|
|
25
|
+
// a single rAF can land in the same style recalc and skip the transition.
|
|
26
|
+
export function afterPaint(cb: () => void): () => void {
|
|
27
|
+
let inner = 0;
|
|
28
|
+
const outer = requestAnimationFrame(() => {
|
|
29
|
+
inner = requestAnimationFrame(cb);
|
|
30
|
+
});
|
|
31
|
+
return () => {
|
|
32
|
+
cancelAnimationFrame(outer);
|
|
33
|
+
cancelAnimationFrame(inner);
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function whenFullscreenSettled(cb: () => void, maxWaitMs = 800): () => void {
|
|
38
|
+
let fired = false;
|
|
39
|
+
const timer = window.setTimeout(done, maxWaitMs);
|
|
40
|
+
document.addEventListener('fullscreenchange', done);
|
|
41
|
+
function done() {
|
|
42
|
+
if (fired) return;
|
|
43
|
+
fired = true;
|
|
44
|
+
cleanup();
|
|
45
|
+
cb();
|
|
46
|
+
}
|
|
47
|
+
function cleanup() {
|
|
48
|
+
window.clearTimeout(timer);
|
|
49
|
+
document.removeEventListener('fullscreenchange', done);
|
|
50
|
+
}
|
|
51
|
+
return cleanup;
|
|
52
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { usePanelMount } from '@/components/panel/panel-shell';
|
|
3
|
+
import { useLocale } from '@/lib/use-locale';
|
|
4
|
+
import { cn } from '@/lib/utils';
|
|
5
|
+
|
|
6
|
+
const VISIBLE_MS = 1800;
|
|
7
|
+
|
|
8
|
+
type Props = {
|
|
9
|
+
shownAt: number;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function PresentLastSlideHint({ shownAt }: Props) {
|
|
13
|
+
const t = useLocale();
|
|
14
|
+
const [open, setOpen] = useState(false);
|
|
15
|
+
useEffect(() => {
|
|
16
|
+
if (!shownAt) return;
|
|
17
|
+
setOpen(true);
|
|
18
|
+
const id = window.setTimeout(() => setOpen(false), VISIBLE_MS);
|
|
19
|
+
return () => window.clearTimeout(id);
|
|
20
|
+
}, [shownAt]);
|
|
21
|
+
const { mounted, animVisible } = usePanelMount(open);
|
|
22
|
+
if (!mounted) return null;
|
|
23
|
+
return (
|
|
24
|
+
<div
|
|
25
|
+
role="status"
|
|
26
|
+
className={cn(
|
|
27
|
+
'pointer-events-none absolute bottom-10 left-1/2 z-30 -translate-x-1/2 rounded-full bg-black/70 px-3.5 py-1.5 text-[12px] text-white/85 shadow-lg backdrop-blur-md motion-safe:transition-[opacity,translate]',
|
|
28
|
+
animVisible
|
|
29
|
+
? 'opacity-100 motion-safe:duration-200'
|
|
30
|
+
: 'translate-y-1 opacity-0 motion-safe:duration-200',
|
|
31
|
+
)}
|
|
32
|
+
>
|
|
33
|
+
{t.present.lastSlideHint}
|
|
34
|
+
</div>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
DropdownMenuTrigger,
|
|
17
17
|
} from '@/components/ui/dropdown-menu';
|
|
18
18
|
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
|
19
|
+
import { haptic } from '@/lib/desktop';
|
|
19
20
|
import type { Folder, FolderIcon } from '@/lib/sdk';
|
|
20
21
|
import { useLocale } from '@/lib/use-locale';
|
|
21
22
|
import { cn, pad2 } from '@/lib/utils';
|
|
@@ -131,7 +132,9 @@ export function FolderItem({
|
|
|
131
132
|
const handleDragEnter = (e: React.DragEvent) => {
|
|
132
133
|
if (!isSlideDrag(e)) return;
|
|
133
134
|
dragDepth.current += 1;
|
|
134
|
-
if (dragDepth.current
|
|
135
|
+
if (dragDepth.current !== 1) return;
|
|
136
|
+
setDragOver(true);
|
|
137
|
+
haptic('generic');
|
|
135
138
|
};
|
|
136
139
|
const handleDragOver = (e: React.DragEvent) => {
|
|
137
140
|
if (!isSlideDrag(e)) return;
|
|
@@ -3,6 +3,7 @@ import { useEffect, useRef, useState } from 'react';
|
|
|
3
3
|
import { toast } from 'sonner';
|
|
4
4
|
import logo from '@/assets/open-slide.svg';
|
|
5
5
|
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
|
|
6
|
+
import { haptic } from '@/lib/desktop';
|
|
6
7
|
import type { Folder, FolderIcon } from '@/lib/sdk';
|
|
7
8
|
import { format, useLocale } from '@/lib/use-locale';
|
|
8
9
|
import { cn } from '@/lib/utils';
|
|
@@ -53,6 +54,8 @@ export function Sidebar({
|
|
|
53
54
|
}) {
|
|
54
55
|
const [dragId, setDragId] = useState<string | null>(null);
|
|
55
56
|
const [dropTarget, setDropTarget] = useState<{ id: string; before: boolean } | null>(null);
|
|
57
|
+
// Survives the dragleave that clears dropTarget between rows, so each new slot ticks once.
|
|
58
|
+
const lastDropSlot = useRef<string | null>(null);
|
|
56
59
|
|
|
57
60
|
const finishReorder = (toId: string, before: boolean) => {
|
|
58
61
|
const fromId = dragId;
|
|
@@ -129,14 +132,8 @@ export function Sidebar({
|
|
|
129
132
|
|
|
130
133
|
return (
|
|
131
134
|
<aside className="group/side relative flex h-full w-[16.5rem] shrink-0 flex-col bg-sidebar text-sidebar-foreground">
|
|
132
|
-
<div className="flex items-center gap-2.5 px-4 pt-4 pb-3">
|
|
133
|
-
<img
|
|
134
|
-
src={logo}
|
|
135
|
-
alt=""
|
|
136
|
-
aria-hidden
|
|
137
|
-
draggable={false}
|
|
138
|
-
className="size-6 shrink-0 select-none"
|
|
139
|
-
/>
|
|
135
|
+
<div className="flex select-none items-center gap-2.5 px-4 pt-4 pb-3">
|
|
136
|
+
<img src={logo} alt="" aria-hidden draggable={false} className="size-6 shrink-0" />
|
|
140
137
|
<h1 className="font-heading text-[13.5px] font-semibold tracking-tight">
|
|
141
138
|
{t.home.appTitle}
|
|
142
139
|
</h1>
|
|
@@ -239,6 +236,7 @@ export function Sidebar({
|
|
|
239
236
|
e.dataTransfer.setData(FOLDER_DND_MIME, folder.id);
|
|
240
237
|
e.dataTransfer.effectAllowed = 'move';
|
|
241
238
|
setDragId(folder.id);
|
|
239
|
+
lastDropSlot.current = null;
|
|
242
240
|
}}
|
|
243
241
|
onDragEnd={() => {
|
|
244
242
|
setDragId(null);
|
|
@@ -250,6 +248,11 @@ export function Sidebar({
|
|
|
250
248
|
e.dataTransfer.dropEffect = 'move';
|
|
251
249
|
const rect = e.currentTarget.getBoundingClientRect();
|
|
252
250
|
const isBefore = e.clientY < rect.top + rect.height / 2;
|
|
251
|
+
const slot = `${folder.id}:${isBefore}`;
|
|
252
|
+
if (lastDropSlot.current !== null && lastDropSlot.current !== slot) {
|
|
253
|
+
haptic('levelChange');
|
|
254
|
+
}
|
|
255
|
+
lastDropSlot.current = slot;
|
|
253
256
|
if (!dropTarget || dropTarget.id !== folder.id || dropTarget.before !== isBefore) {
|
|
254
257
|
setDropTarget({ id: folder.id, before: isBefore });
|
|
255
258
|
}
|
|
@@ -51,7 +51,7 @@ export function SlideCanvas({
|
|
|
51
51
|
<div ref={containerRef} className={cn('relative h-full w-full', flat && 'overflow-hidden')}>
|
|
52
52
|
<div
|
|
53
53
|
className={cn(
|
|
54
|
-
'overflow-hidden bg-white text-black',
|
|
54
|
+
'overflow-hidden bg-white text-start text-black',
|
|
55
55
|
!flat && 'rounded-[6px] shadow-floating',
|
|
56
56
|
)}
|
|
57
57
|
style={
|
|
@@ -12,6 +12,7 @@ import { toast } from 'sonner';
|
|
|
12
12
|
import { useHistory } from '@/components/history-provider';
|
|
13
13
|
import { type DesignSystem, designToCssVars } from '../../lib/design';
|
|
14
14
|
import { shuffleDesign } from '../../lib/design-presets';
|
|
15
|
+
import { createSaveQueue, useUnsavedSource } from '../../lib/unsaved';
|
|
15
16
|
import { useDesign as useDesignFetch } from './use-design';
|
|
16
17
|
|
|
17
18
|
type DesignCtx = {
|
|
@@ -42,16 +43,20 @@ function clone<T>(d: T): T {
|
|
|
42
43
|
}
|
|
43
44
|
|
|
44
45
|
export function DesignProvider({ slideId, children }: { slideId: string; children: ReactNode }) {
|
|
45
|
-
const { design, exists, warning, loaded, save } = useDesignFetch(slideId);
|
|
46
|
+
const { design, savedFrom, exists, warning, loaded, save } = useDesignFetch(slideId);
|
|
46
47
|
const [draft, setDraft] = useState<DesignSystem | null>(null);
|
|
47
48
|
const [committing, setCommitting] = useState(false);
|
|
48
49
|
const history = useHistory();
|
|
49
50
|
const draftRef = useRef<DesignSystem | null>(null);
|
|
50
51
|
draftRef.current = draft;
|
|
51
|
-
|
|
52
|
+
// A save or discard only reaches `dirty` on the next render; this answers in between.
|
|
53
|
+
const settledDraftRef = useRef<DesignSystem | null>(null);
|
|
54
|
+
const [saveQueue] = useState(createSaveQueue);
|
|
55
|
+
// When a save's response arrives as the new design, edits made since it was sent stay.
|
|
52
56
|
useEffect(() => {
|
|
53
|
-
if (design
|
|
54
|
-
|
|
57
|
+
if (!design || (savedFrom && draftRef.current !== savedFrom)) return;
|
|
58
|
+
setDraft(clone(design));
|
|
59
|
+
}, [design, savedFrom]);
|
|
55
60
|
|
|
56
61
|
const dirty = useMemo(() => {
|
|
57
62
|
if (!draft || !design) return false;
|
|
@@ -74,20 +79,52 @@ export function DesignProvider({ slideId, children }: { slideId: string; childre
|
|
|
74
79
|
[history],
|
|
75
80
|
);
|
|
76
81
|
|
|
77
|
-
|
|
78
|
-
|
|
82
|
+
// Each save sends the draft as it stands when its turn comes: two in flight
|
|
83
|
+
// could answer out of order and put an older design back over the draft.
|
|
84
|
+
const write = useCallback((): Promise<string | null> => {
|
|
85
|
+
if (!draftRef.current) return Promise.resolve(null);
|
|
79
86
|
setCommitting(true);
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
87
|
+
return saveQueue.run(
|
|
88
|
+
async () => {
|
|
89
|
+
const saving = draftRef.current;
|
|
90
|
+
if (!saving || saving === settledDraftRef.current) return null;
|
|
91
|
+
const r = await save(saving);
|
|
92
|
+
if (r.ok) {
|
|
93
|
+
if (draftRef.current === saving) history.clear();
|
|
94
|
+
settledDraftRef.current = saving;
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
const error = r.error ?? 'Failed to save';
|
|
98
|
+
toast.error(error);
|
|
99
|
+
return error;
|
|
100
|
+
},
|
|
101
|
+
() => setCommitting(false),
|
|
102
|
+
);
|
|
103
|
+
}, [saveQueue, save, history]);
|
|
104
|
+
|
|
105
|
+
const commit = useCallback(async () => {
|
|
106
|
+
await write();
|
|
107
|
+
}, [write]);
|
|
85
108
|
|
|
86
109
|
const discard = useCallback(() => {
|
|
110
|
+
settledDraftRef.current = draftRef.current;
|
|
87
111
|
if (design) setDraft(clone(design));
|
|
88
112
|
history.clear();
|
|
89
113
|
}, [design, history]);
|
|
90
114
|
|
|
115
|
+
const dirtyRef = useRef(dirty);
|
|
116
|
+
dirtyRef.current = dirty;
|
|
117
|
+
useUnsavedSource({
|
|
118
|
+
kind: 'draft',
|
|
119
|
+
dirty: () =>
|
|
120
|
+
saveQueue.busy() || (dirtyRef.current && draftRef.current !== settledDraftRef.current),
|
|
121
|
+
save: async () => {
|
|
122
|
+
const error = await write();
|
|
123
|
+
if (error) throw new Error(error);
|
|
124
|
+
},
|
|
125
|
+
discard,
|
|
126
|
+
});
|
|
127
|
+
|
|
91
128
|
const shuffle = useCallback(() => {
|
|
92
129
|
const prev = draftRef.current;
|
|
93
130
|
const next = clone(shuffleDesign(prev));
|
|
@@ -3,6 +3,8 @@ import type { DesignSystem } from '../../lib/design';
|
|
|
3
3
|
|
|
4
4
|
type FetchedState = {
|
|
5
5
|
design: DesignSystem | null;
|
|
6
|
+
// The draft whose save returned `design`, or null when it was fetched.
|
|
7
|
+
savedFrom: Partial<DesignSystem> | null;
|
|
6
8
|
exists: boolean;
|
|
7
9
|
warning: string | null;
|
|
8
10
|
loaded: boolean;
|
|
@@ -15,6 +17,7 @@ export type UseDesignReturn = FetchedState & {
|
|
|
15
17
|
export function useDesign(slideId: string): UseDesignReturn {
|
|
16
18
|
const [state, setState] = useState<FetchedState>({
|
|
17
19
|
design: null,
|
|
20
|
+
savedFrom: null,
|
|
18
21
|
exists: false,
|
|
19
22
|
warning: null,
|
|
20
23
|
loaded: false,
|
|
@@ -35,6 +38,7 @@ export function useDesign(slideId: string): UseDesignReturn {
|
|
|
35
38
|
};
|
|
36
39
|
setState({
|
|
37
40
|
design: body.design,
|
|
41
|
+
savedFrom: null,
|
|
38
42
|
exists: body.exists,
|
|
39
43
|
warning: body.warning,
|
|
40
44
|
loaded: true,
|
|
@@ -45,7 +49,7 @@ export function useDesign(slideId: string): UseDesignReturn {
|
|
|
45
49
|
}, []);
|
|
46
50
|
|
|
47
51
|
useEffect(() => {
|
|
48
|
-
setState({ design: null, exists: false, warning: null, loaded: false });
|
|
52
|
+
setState({ design: null, savedFrom: null, exists: false, warning: null, loaded: false });
|
|
49
53
|
void refresh();
|
|
50
54
|
}, [refresh]);
|
|
51
55
|
|
|
@@ -71,6 +75,7 @@ export function useDesign(slideId: string): UseDesignReturn {
|
|
|
71
75
|
setState((s) => ({
|
|
72
76
|
...s,
|
|
73
77
|
design: body.design ?? s.design,
|
|
78
|
+
savedFrom: patch,
|
|
74
79
|
exists: true,
|
|
75
80
|
warning: null,
|
|
76
81
|
}));
|
|
@@ -6,7 +6,8 @@ import { buttonVariants } from '@/components/ui/button';
|
|
|
6
6
|
import {
|
|
7
7
|
DropdownMenu,
|
|
8
8
|
DropdownMenuContent,
|
|
9
|
-
|
|
9
|
+
DropdownMenuRadioGroup,
|
|
10
|
+
DropdownMenuRadioItem,
|
|
10
11
|
DropdownMenuTrigger,
|
|
11
12
|
} from '@/components/ui/dropdown-menu';
|
|
12
13
|
import { useLocale } from '@/lib/use-locale';
|
|
@@ -38,27 +39,20 @@ export function ThemeToggle() {
|
|
|
38
39
|
</DropdownMenuTrigger>
|
|
39
40
|
</IconTooltip>
|
|
40
41
|
<DropdownMenuContent align="end" className="min-w-[140px]">
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
</
|
|
55
|
-
<DropdownMenuItem
|
|
56
|
-
onClick={() => setTheme('system')}
|
|
57
|
-
data-active={mounted && theme === 'system'}
|
|
58
|
-
>
|
|
59
|
-
<Monitor />
|
|
60
|
-
{t.themeToggle.system}
|
|
61
|
-
</DropdownMenuItem>
|
|
42
|
+
<DropdownMenuRadioGroup value={mounted ? theme : undefined} onValueChange={setTheme}>
|
|
43
|
+
<DropdownMenuRadioItem value="light" closeOnClick>
|
|
44
|
+
<Sun />
|
|
45
|
+
{t.themeToggle.light}
|
|
46
|
+
</DropdownMenuRadioItem>
|
|
47
|
+
<DropdownMenuRadioItem value="dark" closeOnClick>
|
|
48
|
+
<Moon />
|
|
49
|
+
{t.themeToggle.dark}
|
|
50
|
+
</DropdownMenuRadioItem>
|
|
51
|
+
<DropdownMenuRadioItem value="system" closeOnClick>
|
|
52
|
+
<Monitor />
|
|
53
|
+
{t.themeToggle.system}
|
|
54
|
+
</DropdownMenuRadioItem>
|
|
55
|
+
</DropdownMenuRadioGroup>
|
|
62
56
|
</DropdownMenuContent>
|
|
63
57
|
</DropdownMenu>
|
|
64
58
|
);
|