@lemonriver/core 1.3.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.
Files changed (119) hide show
  1. package/dist/{build-CSkdswfd.js → build-Cv0nNc4G.js} +1 -1
  2. package/dist/cli/bin.js +5 -5
  3. package/dist/{config-C5-myPY6.js → config-Di9kipre.js} +2773 -714
  4. package/dist/{config-CYNOR93W.d.ts → config-f1SqAhtR.d.ts} +1 -1
  5. package/dist/{dev-DHtYH8sw.js → dev-Az1UzCQp.js} +11 -11
  6. package/dist/index.d.ts +2 -2
  7. package/dist/index.js +21 -2
  8. package/dist/locale/index.d.ts +1 -1
  9. package/dist/locale/index.js +1 -1
  10. package/dist/{mcp-B2UeO1un.js → mcp-CW7H6oUg.js} +1 -1
  11. package/dist/{preview-C1B6-umF.js → preview-DtSq5uN1.js} +1 -1
  12. package/dist/{types-tdaXSyah.d.ts → types-C4VfD89E.d.ts} +12 -0
  13. package/dist/{update-DzL8fpcI.js → update-DVe2kQA7.js} +86 -13
  14. package/dist/vite/index.d.ts +1 -1
  15. package/dist/vite/index.js +1 -1
  16. package/dist/{zh-tw-BhYyMx0-.js → zh-tw-BX3oQAc2.js} +110 -0
  17. package/package.json +5 -6
  18. package/release-notes.json +20 -0
  19. package/src/agent/types.ts +9 -2
  20. package/src/app/app.tsx +2 -0
  21. package/src/app/components/agent/agent-panel.tsx +12 -3
  22. package/src/app/components/agent/agent-presence.tsx +1 -1
  23. package/src/app/components/command/home-command-menu.tsx +4 -1
  24. package/src/app/components/command/slide-command-menu.tsx +4 -1
  25. package/src/app/components/export-progress-toast.tsx +3 -1
  26. package/src/app/components/inspector/asset-picker-dialog.tsx +1 -1
  27. package/src/app/components/inspector/comment-layer.tsx +3 -3
  28. package/src/app/components/inspector/inline-text-editor.tsx +1 -12
  29. package/src/app/components/inspector/inspect-overlay.tsx +9 -1
  30. package/src/app/components/inspector/inspector-panel.tsx +7 -23
  31. package/src/app/components/inspector/inspector-provider.tsx +177 -36
  32. package/src/app/components/inspector/page-panel.tsx +270 -0
  33. package/src/app/components/language-toggle.tsx +13 -11
  34. package/src/app/components/overview-grid.tsx +3 -3
  35. package/src/app/components/panel/editor-sidebar.tsx +43 -8
  36. package/src/app/components/panel/panel-shell.tsx +9 -5
  37. package/src/app/components/panel/save-card.tsx +1 -1
  38. package/src/app/components/sidebar/folder-item.tsx +4 -1
  39. package/src/app/components/sidebar/sidebar.tsx +11 -8
  40. package/src/app/components/slide-canvas.tsx +1 -1
  41. package/src/app/components/style-panel/design-provider.tsx +48 -11
  42. package/src/app/components/style-panel/use-design.ts +6 -1
  43. package/src/app/components/theme-toggle.tsx +16 -22
  44. package/src/app/components/thumbnail-rail.tsx +69 -50
  45. package/src/app/components/ui/context-menu.tsx +9 -10
  46. package/src/app/components/ui/dialog.tsx +2 -4
  47. package/src/app/components/ui/dropdown-menu.tsx +9 -10
  48. package/src/app/components/ui/popover.tsx +1 -1
  49. package/src/app/components/ui/select.tsx +2 -2
  50. package/src/app/components/ui/sonner.tsx +2 -2
  51. package/src/app/index.html +7 -0
  52. package/src/app/lemonriver/agent-cli/model.ts +22 -0
  53. package/src/app/lemonriver/agent-install/model.ts +46 -0
  54. package/src/app/lemonriver/agent-install/section.tsx +178 -0
  55. package/src/app/lemonriver/agent-install/use-install.ts +51 -0
  56. package/src/app/lemonriver/agent-providers/section.tsx +385 -44
  57. package/src/app/lemonriver/agent-providers/use-providers.ts +50 -3
  58. package/src/app/lemonriver/backup/places.ts +22 -12
  59. package/src/app/lemonriver/chrome/sidebar-extras.tsx +1 -1
  60. package/src/app/lemonriver/feedback/dialog.tsx +1 -2
  61. package/src/app/lemonriver/feedback/model.ts +0 -5
  62. package/src/app/lemonriver/guide/clipboard.ts +19 -0
  63. package/src/app/lemonriver/guide/create-board.tsx +150 -0
  64. package/src/app/lemonriver/guide/install-board.tsx +208 -0
  65. package/src/app/lemonriver/guide/more-agents-page.tsx +89 -0
  66. package/src/app/lemonriver/guide/more-agents.ts +137 -0
  67. package/src/app/lemonriver/guide/quick-board.tsx +57 -0
  68. package/src/app/lemonriver/guide/start-board.tsx +38 -0
  69. package/src/app/lemonriver/guide/start-card.tsx +105 -0
  70. package/src/app/lemonriver/guide/start.ts +174 -0
  71. package/src/app/lemonriver/guide/state.ts +5 -21
  72. package/src/app/lemonriver/help/help-page.tsx +24 -6
  73. package/src/app/lemonriver/help/model.ts +1 -0
  74. package/src/app/lemonriver/home/home-page.tsx +12 -6
  75. package/src/app/lemonriver/home/sorting.ts +45 -0
  76. package/src/app/lemonriver/home/use-deck-times.ts +1 -2
  77. package/src/app/lemonriver/i18n/system-locale.ts +39 -0
  78. package/src/app/lemonriver/routes.tsx +2 -0
  79. package/src/app/lemonriver/settings/backup-section.tsx +3 -2
  80. package/src/app/lemonriver/settings/settings-page.tsx +5 -6
  81. package/src/app/lemonriver/settings/workspace-card.tsx +2 -1
  82. package/src/app/lemonriver/share/share-dialog.tsx +2 -1
  83. package/src/app/lemonriver/text/en.ts +592 -453
  84. package/src/app/lemonriver/text/es.ts +402 -271
  85. package/src/app/lemonriver/text/ja.ts +403 -274
  86. package/src/app/lemonriver/text/platform.ts +7 -0
  87. package/src/app/lemonriver/text/types.ts +118 -1
  88. package/src/app/lemonriver/text/zh-cn.ts +643 -508
  89. package/src/app/lemonriver/text/zh-tw.ts +679 -545
  90. package/src/app/lemonriver/theme/app.css +9 -0
  91. package/src/app/lemonriver/theme/controls.css +5 -2
  92. package/src/app/lemonriver/theme/index.css +9 -0
  93. package/src/app/lemonriver/theme/pages.ts +2 -0
  94. package/src/app/lemonriver/theme/theme-menu.tsx +10 -11
  95. package/src/app/lemonriver/update/restart-wait.ts +45 -0
  96. package/src/app/lemonriver/update/update-prompt.tsx +9 -0
  97. package/src/app/lib/agent/use-agent.ts +117 -30
  98. package/src/app/lib/desktop-host.ts +31 -0
  99. package/src/app/lib/desktop-routes.ts +22 -0
  100. package/src/app/lib/desktop.ts +106 -0
  101. package/src/app/lib/export-pdf.ts +15 -7
  102. package/src/app/lib/inspector/color.ts +51 -0
  103. package/src/app/lib/inspector/fiber.ts +6 -0
  104. package/src/app/lib/inspector/use-editor.ts +2 -1
  105. package/src/app/lib/inspector/use-notes.ts +331 -57
  106. package/src/app/lib/inspector/use-visual-editor.ts +9 -1
  107. package/src/app/lib/locale-store.ts +6 -1
  108. package/src/app/lib/transition.ts +43 -0
  109. package/src/app/lib/unsaved.ts +155 -0
  110. package/src/app/routes/home.tsx +1 -1
  111. package/src/app/routes/slide.tsx +116 -73
  112. package/src/app/styles.css +39 -1
  113. package/src/locale/en.ts +19 -0
  114. package/src/locale/es.ts +19 -0
  115. package/src/locale/ja.ts +19 -0
  116. package/src/locale/types.ts +12 -0
  117. package/src/locale/zh-cn.ts +19 -0
  118. package/src/locale/zh-tw.ts +19 -0
  119. package/src/app/lemonriver/guide/guide-prompt.tsx +0 -89
@@ -4,10 +4,11 @@ import { buttonVariants } from '@/components/ui/button';
4
4
  import {
5
5
  DropdownMenu,
6
6
  DropdownMenuContent,
7
- DropdownMenuItem,
7
+ DropdownMenuRadioGroup,
8
+ DropdownMenuRadioItem,
8
9
  DropdownMenuTrigger,
9
10
  } from '@/components/ui/dropdown-menu';
10
- import { LOCALE_OPTIONS, setLocale } from '@/lib/locale-store';
11
+ import { LOCALE_OPTIONS, type LocaleId, setLocale } from '@/lib/locale-store';
11
12
  import { useLocale } from '@/lib/use-locale';
12
13
  import { cn } from '@/lib/utils';
13
14
 
@@ -30,15 +31,16 @@ export function LanguageToggle() {
30
31
  </DropdownMenuTrigger>
31
32
  </IconTooltip>
32
33
  <DropdownMenuContent align="end" className="min-w-[140px]">
33
- {LOCALE_OPTIONS.map((option) => (
34
- <DropdownMenuItem
35
- key={option.id}
36
- onClick={() => setLocale(option.id)}
37
- data-active={t.id === option.id}
38
- >
39
- {option.label}
40
- </DropdownMenuItem>
41
- ))}
34
+ <DropdownMenuRadioGroup
35
+ value={t.id}
36
+ onValueChange={(value) => setLocale(value as LocaleId)}
37
+ >
38
+ {LOCALE_OPTIONS.map((option) => (
39
+ <DropdownMenuRadioItem key={option.id} value={option.id} closeOnClick>
40
+ {option.label}
41
+ </DropdownMenuRadioItem>
42
+ ))}
43
+ </DropdownMenuRadioGroup>
42
44
  </DropdownMenuContent>
43
45
  </DropdownMenu>
44
46
  );
@@ -112,7 +112,7 @@ export function OverviewGrid({
112
112
  aria-modal="true"
113
113
  aria-label={t.present.overviewDialogAria}
114
114
  className={cn(
115
- 'absolute inset-0 z-50 flex flex-col backdrop-blur-sm',
115
+ 'absolute inset-0 z-50 flex flex-col backdrop-blur-2xl backdrop-saturate-150',
116
116
  'motion-safe:animate-in motion-safe:fade-in-0 motion-safe:duration-150',
117
117
  styles.surface,
118
118
  )}
@@ -335,7 +335,7 @@ type OverviewStyles = {
335
335
  };
336
336
 
337
337
  const presentStyles = {
338
- surface: 'bg-black/95',
338
+ surface: 'bg-black/80',
339
339
  eyebrow: 'text-white/55',
340
340
  thumbFocused: 'bg-white/10',
341
341
  thumbHover: 'hover:bg-white/5',
@@ -349,7 +349,7 @@ const presentStyles = {
349
349
  } as const;
350
350
 
351
351
  const editorStyles = {
352
- surface: 'bg-background/95',
352
+ surface: 'bg-background/80',
353
353
  eyebrow: 'text-muted-foreground',
354
354
  thumbFocused: 'bg-muted',
355
355
  thumbHover: 'hover:bg-muted/60',
@@ -1,10 +1,12 @@
1
- import { type ReactNode, useState } from 'react';
1
+ import { type CSSProperties, type ReactNode, useEffect, useState } from 'react';
2
2
  import { AGENT_DOCK_W } from '@/components/agent/agent-dock';
3
3
  import { InspectorPanel } from '@/components/inspector/inspector-panel';
4
4
  import { useInspector } from '@/components/inspector/inspector-provider';
5
+ import type { PageInfo } from '@/components/inspector/page-panel';
5
6
  import { useDesignPanelState } from '@/components/style-panel/design-provider';
6
7
  import { DesignPanel } from '@/components/style-panel/style-panel';
7
8
  import { useLocale } from '@/lib/use-locale';
9
+ import { cn } from '@/lib/utils';
8
10
  import { PANEL_TRANSITION_MS, PANEL_W, usePanelMount } from './panel-shell';
9
11
  import { ResizeHandle, useStoredWidth } from './resize-handle';
10
12
 
@@ -22,11 +24,13 @@ export function EditorSidebar({
22
24
  onCloseDesign,
23
25
  agentOpen = false,
24
26
  agent,
27
+ page,
25
28
  }: {
26
29
  designOpen: boolean;
27
30
  onCloseDesign: () => void;
28
31
  agentOpen?: boolean;
29
32
  agent?: ReactNode;
33
+ page?: PageInfo;
30
34
  }) {
31
35
  const t = useLocale();
32
36
  const { active, panelOpen } = useInspector();
@@ -64,7 +68,9 @@ export function EditorSidebar({
64
68
  const [agentMounted, setAgentMounted] = useState(false);
65
69
  if (isAgent && !agentMounted) setAgentMounted(true);
66
70
  const open = mode !== null;
67
- const { mounted, animVisible } = usePanelMount(open);
71
+ const { mounted, animVisible } = usePanelMount(open, { animateInitial: false });
72
+ const [firstRender, setFirstRender] = useState(true);
73
+ useEffect(() => setFirstRender(false), []);
68
74
 
69
75
  if (!mounted) return null;
70
76
 
@@ -97,23 +103,52 @@ export function EditorSidebar({
97
103
  />
98
104
  )}
99
105
  {agentMounted && (
100
- <div
101
- className="sidebar-swap h-full shrink-0"
106
+ <SwapPane
107
+ animate={!firstRender}
108
+ className="h-full shrink-0"
102
109
  style={{ width: agentWidth }}
103
110
  hidden={!isAgent}
104
111
  >
105
112
  {agent}
106
- </div>
113
+ </SwapPane>
107
114
  )}
108
115
  {!isAgent && (
109
- <div className="sidebar-swap flex h-full shrink-0" style={{ width: editorWidth }}>
116
+ <SwapPane
117
+ animate={!firstRender}
118
+ className="flex h-full shrink-0"
119
+ style={{ width: editorWidth }}
120
+ >
110
121
  {lastEditor === 'design' ? (
111
122
  <DesignPanel onClose={onCloseDesign} />
112
123
  ) : (
113
- <InspectorPanel preferredTab={preferredTab} onTabChange={setPreferredTab} />
124
+ <InspectorPanel preferredTab={preferredTab} onTabChange={setPreferredTab} page={page} />
114
125
  )}
115
- </div>
126
+ </SwapPane>
116
127
  )}
117
128
  </div>
118
129
  );
119
130
  }
131
+
132
+ // Fixed at mount, since toggling the fade on a showing pane would replay it; a
133
+ // hidden pane can pick it up, as it only plays once shown again.
134
+ function SwapPane({
135
+ animate,
136
+ hidden = false,
137
+ className,
138
+ style,
139
+ children,
140
+ }: {
141
+ animate: boolean;
142
+ hidden?: boolean;
143
+ className?: string;
144
+ style?: CSSProperties;
145
+ children: ReactNode;
146
+ }) {
147
+ const [fade, setFade] = useState(animate);
148
+ if (hidden && !fade) setFade(true);
149
+ return (
150
+ <div className={cn(fade && 'sidebar-swap', className)} style={style} hidden={hidden}>
151
+ {children}
152
+ </div>
153
+ );
154
+ }
@@ -6,8 +6,8 @@ export const PANEL_TRANSITION_MS = 240;
6
6
 
7
7
  // Defer the width expansion to the next frame so the browser paints once
8
8
  // at width=0 first; otherwise the transition has no starting frame.
9
- export function useAnimatedOpen(open: boolean): boolean {
10
- const [animVisible, setAnimVisible] = useState(false);
9
+ export function useAnimatedOpen(open: boolean, initial = false): boolean {
10
+ const [animVisible, setAnimVisible] = useState(initial);
11
11
  useEffect(() => {
12
12
  if (open) {
13
13
  const id = requestAnimationFrame(() => setAnimVisible(true));
@@ -20,8 +20,12 @@ export function useAnimatedOpen(open: boolean): boolean {
20
20
 
21
21
  // Stay mounted through the close-out width transition so the panel
22
22
  // visibly collapses instead of vanishing.
23
- export function usePanelMount(open: boolean): { mounted: boolean; animVisible: boolean } {
24
- const [mounted, setMounted] = useState(false);
23
+ export function usePanelMount(
24
+ open: boolean,
25
+ { animateInitial = true }: { animateInitial?: boolean } = {},
26
+ ): { mounted: boolean; animVisible: boolean } {
27
+ const [startOpen] = useState(() => open && !animateInitial);
28
+ const [mounted, setMounted] = useState(startOpen);
25
29
  useEffect(() => {
26
30
  if (open) {
27
31
  setMounted(true);
@@ -30,7 +34,7 @@ export function usePanelMount(open: boolean): { mounted: boolean; animVisible: b
30
34
  const t = setTimeout(() => setMounted(false), PANEL_TRANSITION_MS);
31
35
  return () => clearTimeout(t);
32
36
  }, [open]);
33
- const animVisible = useAnimatedOpen(open && mounted);
37
+ const animVisible = useAnimatedOpen(open && mounted, startOpen);
34
38
  return { mounted, animVisible };
35
39
  }
36
40
 
@@ -73,7 +73,7 @@ export function SaveCard({
73
73
  : 'translate-y-2 scale-[0.98] opacity-0',
74
74
  )}
75
75
  >
76
- <div className="pointer-events-auto flex h-9 items-center gap-1 rounded-[8px] border border-border bg-popover/95 py-0.5 pr-0.5 pl-1 shadow-overlay backdrop-blur-md">
76
+ <div className="pointer-events-auto flex h-9 items-center gap-1 rounded-[8px] border border-border bg-material py-0.5 pr-0.5 pl-1 shadow-overlay backdrop-blur-xl backdrop-saturate-150">
77
77
  {showHistory && (
78
78
  <div className="flex items-center">
79
79
  <Button
@@ -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 === 1) setDragOver(true);
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;
@@ -2,6 +2,7 @@ import { Plus, Search } from 'lucide-react';
2
2
  import { useEffect, useRef, useState } from 'react';
3
3
  import { toast } from 'sonner';
4
4
  import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover';
5
+ import { haptic } from '@/lib/desktop';
5
6
  import type { Folder, FolderIcon } from '@/lib/sdk';
6
7
  import { format, useLocale } from '@/lib/use-locale';
7
8
  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>
@@ -240,6 +237,7 @@ export function Sidebar({
240
237
  e.dataTransfer.setData(FOLDER_DND_MIME, folder.id);
241
238
  e.dataTransfer.effectAllowed = 'move';
242
239
  setDragId(folder.id);
240
+ lastDropSlot.current = null;
243
241
  }}
244
242
  onDragEnd={() => {
245
243
  setDragId(null);
@@ -251,6 +249,11 @@ export function Sidebar({
251
249
  e.dataTransfer.dropEffect = 'move';
252
250
  const rect = e.currentTarget.getBoundingClientRect();
253
251
  const isBefore = e.clientY < rect.top + rect.height / 2;
252
+ const slot = `${folder.id}:${isBefore}`;
253
+ if (lastDropSlot.current !== null && lastDropSlot.current !== slot) {
254
+ haptic('levelChange');
255
+ }
256
+ lastDropSlot.current = slot;
254
257
  if (!dropTarget || dropTarget.id !== folder.id || dropTarget.before !== isBefore) {
255
258
  setDropTarget({ id: folder.id, before: isBefore });
256
259
  }
@@ -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) setDraft(clone(design));
54
- }, [design]);
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
- const commit = useCallback(async () => {
78
- if (!draft) return;
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
- const r = await save(draft);
81
- setCommitting(false);
82
- if (!r.ok) toast.error(r.error ?? 'Failed to save');
83
- history.clear();
84
- }, [draft, save, history]);
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
- DropdownMenuItem,
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
- <DropdownMenuItem
42
- onClick={() => setTheme('light')}
43
- data-active={mounted && theme === 'light'}
44
- >
45
- <Sun />
46
- {t.themeToggle.light}
47
- </DropdownMenuItem>
48
- <DropdownMenuItem
49
- onClick={() => setTheme('dark')}
50
- data-active={mounted && theme === 'dark'}
51
- >
52
- <Moon />
53
- {t.themeToggle.dark}
54
- </DropdownMenuItem>
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
  );
@@ -2,9 +2,11 @@ import {
2
2
  closestCenter,
3
3
  DndContext,
4
4
  type DragEndEvent,
5
+ type DragOverEvent,
5
6
  type DragStartEvent,
6
7
  KeyboardSensor,
7
8
  PointerSensor,
9
+ type UniqueIdentifier,
8
10
  useSensor,
9
11
  useSensors,
10
12
  } from '@dnd-kit/core';
@@ -37,6 +39,7 @@ import {
37
39
  } from '@/components/ui/context-menu';
38
40
  import { ScrollArea } from '@/components/ui/scroll-area';
39
41
  import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
42
+ import { haptic } from '@/lib/desktop';
40
43
  import { format, plural, useLocale } from '@/lib/use-locale';
41
44
  import { cn, pad2 } from '@/lib/utils';
42
45
  import type { DesignSystem } from '../lib/design';
@@ -326,39 +329,42 @@ export function ThumbnailRail({
326
329
  );
327
330
  }
328
331
 
329
- const list = (
330
- <aside className="flex flex-col gap-2 px-3 pb-3">
331
- <div className="-mx-3 sticky top-0 z-10 bg-sidebar px-4 pt-3 pb-1">
332
- <div className="flex items-center justify-between gap-2">
333
- <span className="eyebrow">{t.thumbnailRail.pages}</span>
334
- <div className="flex items-center gap-1.5" data-lr-rail-actions="">
335
- <span className="folio">{pad2(pages.length)}</span>
336
- {onOverview && (
337
- <Tooltip>
338
- <TooltipTrigger
339
- render={
340
- <button
341
- type="button"
342
- onClick={onOverview}
343
- aria-label={t.thumbnailRail.overviewAria}
344
- className={cn(
345
- 'flex size-5 items-center justify-center rounded-[3px] text-muted-foreground/70 outline-none',
346
- 'motion-safe:transition-colors hover:bg-muted hover:text-foreground',
347
- 'focus-visible:ring-1 focus-visible:ring-brand',
348
- )}
349
- >
350
- <Grid2x2 className="size-3.5" strokeWidth={1.75} />
351
- </button>
352
- }
353
- />
354
- <TooltipContent side="bottom" sideOffset={6}>
355
- {t.thumbnailRail.overviewAria}
356
- </TooltipContent>
357
- </Tooltip>
358
- )}
359
- </div>
332
+ const header = (
333
+ <div className="shrink-0 px-4 pt-3 pb-3">
334
+ <div className="flex items-center justify-between gap-2">
335
+ <span className="eyebrow">{t.thumbnailRail.pages}</span>
336
+ <div className="flex items-center gap-1.5" data-lr-rail-actions="">
337
+ <span className="folio">{pad2(pages.length)}</span>
338
+ {onOverview && (
339
+ <Tooltip>
340
+ <TooltipTrigger
341
+ render={
342
+ <button
343
+ type="button"
344
+ onClick={onOverview}
345
+ aria-label={t.thumbnailRail.overviewAria}
346
+ className={cn(
347
+ 'flex size-5 items-center justify-center rounded-[3px] text-muted-foreground/70 outline-none',
348
+ 'motion-safe:transition-colors hover:bg-muted hover:text-foreground',
349
+ 'focus-visible:ring-1 focus-visible:ring-brand',
350
+ )}
351
+ >
352
+ <Grid2x2 className="size-3.5" strokeWidth={1.75} />
353
+ </button>
354
+ }
355
+ />
356
+ <TooltipContent side="bottom" sideOffset={6}>
357
+ {t.thumbnailRail.overviewAria}
358
+ </TooltipContent>
359
+ </Tooltip>
360
+ )}
360
361
  </div>
361
362
  </div>
363
+ </div>
364
+ );
365
+
366
+ const list = (
367
+ <aside className="px-3 pb-3">
362
368
  <VirtualThumbList
363
369
  pages={pages}
364
370
  current={current}
@@ -383,22 +389,25 @@ export function ThumbnailRail({
383
389
 
384
390
  return (
385
391
  <TooltipProvider delay={200}>
386
- <div className="relative h-full">
387
- <ScrollArea className="h-full bg-sidebar [&_[data-slot=scroll-area-scrollbar]]:z-20">
388
- {scrollAreaContents}
389
- </ScrollArea>
390
- {currentPosition && (
391
- <CurrentThumbnailButton
392
- direction={currentPosition}
393
- label={format(
394
- currentPosition === 'above'
395
- ? t.thumbnailRail.scrollUpToCurrentPage
396
- : t.thumbnailRail.scrollDownToCurrentPage,
397
- { n: current + 1 },
398
- )}
399
- onActivate={scrollToCurrent}
400
- />
401
- )}
392
+ <div className="flex h-full flex-col bg-sidebar">
393
+ {header}
394
+ <div className="relative min-h-0 flex-1">
395
+ <ScrollArea className="h-full [&_[data-slot=scroll-area-scrollbar]]:z-20">
396
+ {scrollAreaContents}
397
+ </ScrollArea>
398
+ {currentPosition && (
399
+ <CurrentThumbnailButton
400
+ direction={currentPosition}
401
+ label={format(
402
+ currentPosition === 'above'
403
+ ? t.thumbnailRail.scrollUpToCurrentPage
404
+ : t.thumbnailRail.scrollDownToCurrentPage,
405
+ { n: current + 1 },
406
+ )}
407
+ onActivate={scrollToCurrent}
408
+ />
409
+ )}
410
+ </div>
402
411
  </div>
403
412
  </TooltipProvider>
404
413
  );
@@ -442,9 +451,9 @@ function CurrentThumbnailButton({
442
451
  onActivate(true);
443
452
  }}
444
453
  className={cn(
445
- 'pointer-events-auto absolute left-1/2 z-30 -translate-x-1/2 bg-card/95 shadow-floating backdrop-blur-sm',
454
+ 'pointer-events-auto absolute left-1/2 z-30 -translate-x-1/2 bg-material shadow-floating backdrop-blur-xl backdrop-saturate-150',
446
455
  'motion-safe:animate-in motion-safe:fade-in-0 motion-safe:zoom-in-95 motion-safe:duration-150',
447
- direction === 'above' ? 'top-10' : 'bottom-3',
456
+ direction === 'above' ? 'top-3' : 'bottom-3',
448
457
  )}
449
458
  >
450
459
  <Icon className="size-3.5" strokeWidth={1.75} aria-hidden />
@@ -569,7 +578,7 @@ function HorizontalVirtualThumbList({
569
578
  aria-label={format(t.thumbnailRail.goToPageAria, { n: i + 1 })}
570
579
  aria-current={active ? 'page' : undefined}
571
580
  className={cn(
572
- 'group/thumb relative flex shrink-0 flex-col items-center gap-1.5 rounded-[6px] outline-none motion-safe:transition-[scale] motion-safe:duration-100 active:scale-[0.985]',
581
+ 'group/thumb relative flex shrink-0 flex-col items-center gap-1.5 rounded-[6px] text-left outline-none motion-safe:transition-[scale] motion-safe:duration-100 active:scale-[0.985]',
573
582
  'focus-visible:ring-1 focus-visible:ring-brand focus-visible:ring-offset-1 focus-visible:ring-offset-sidebar',
574
583
  )}
575
584
  >
@@ -961,11 +970,20 @@ function SortableRail({
961
970
 
962
971
  const items = pages.map((_, i) => i + 1);
963
972
 
973
+ const overId = useRef<UniqueIdentifier | null>(null);
974
+
964
975
  const handleDragStart = (event: DragStartEvent) => {
976
+ overId.current = event.active.id;
965
977
  const i = (event.active.id as number) - 1;
966
978
  if (i >= 0) onSelect(i);
967
979
  };
968
980
 
981
+ const handleDragOver = ({ over }: DragOverEvent) => {
982
+ if (!over || over.id === overId.current) return;
983
+ overId.current = over.id;
984
+ haptic('levelChange');
985
+ };
986
+
969
987
  const handleDragEnd = (event: DragEndEvent) => {
970
988
  const { active, over } = event;
971
989
  if (!over || active.id === over.id) return;
@@ -980,6 +998,7 @@ function SortableRail({
980
998
  sensors={sensors}
981
999
  collisionDetection={closestCenter}
982
1000
  onDragStart={handleDragStart}
1001
+ onDragOver={handleDragOver}
983
1002
  onDragEnd={handleDragEnd}
984
1003
  >
985
1004
  <SortableContext items={items} strategy={verticalListSortingStrategy}>