@lemonriver/core 0.1.1 → 0.3.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 (161) hide show
  1. package/dist/{build-f-fM2ZY4.js → build-Bqo69DWP.js} +1 -1
  2. package/dist/cli/bin.js +4 -4
  3. package/dist/{config-DO45GU3e.js → config-DJ5rkMMg.js} +3123 -523
  4. package/dist/{config-B6JaKJM4.d.ts → config-teo3kWz7.d.ts} +6 -2
  5. package/dist/{dev-CqS2xpgE.js → dev-B2FJD5bJ.js} +2 -2
  6. package/dist/index.d.ts +3 -3
  7. package/dist/index.js +4 -3
  8. package/dist/locale/index.d.ts +5 -2
  9. package/dist/locale/index.js +2 -2
  10. package/dist/{preview-BihgMlEl.js → preview-C93BOZL1.js} +1 -1
  11. package/dist/{types-BjW4glip.d.ts → types-DFK02XVv.d.ts} +120 -27
  12. package/dist/{update-C_R0ycVC.js → update-DsxZBtwv.js} +154 -90
  13. package/dist/vite/index.d.ts +1 -1
  14. package/dist/vite/index.js +1 -1
  15. package/dist/{zh-tw-Ci0jK8eg.js → zh-tw-DwTAZKa6.js} +1091 -104
  16. package/package.json +13 -6
  17. package/skills/apply-comments/SKILL.md +10 -6
  18. package/skills/create-slide/SKILL.md +2 -0
  19. package/skills/current-slide/SKILL.md +1 -0
  20. package/skills/slide-authoring/SKILL.md +31 -1
  21. package/src/agent/prompt.ts +141 -0
  22. package/src/agent/provider.ts +123 -0
  23. package/src/agent/types.ts +151 -0
  24. package/src/app/app.tsx +7 -18
  25. package/src/app/assets/open-slide.svg +39 -0
  26. package/src/app/components/agent/agent-dock.tsx +35 -0
  27. package/src/app/components/agent/agent-markdown.tsx +45 -0
  28. package/src/app/components/agent/agent-panel.tsx +695 -0
  29. package/src/app/components/agent/agent-presence.tsx +74 -0
  30. package/src/app/components/agent/composer.tsx +120 -0
  31. package/src/app/components/agent/connect-view.tsx +184 -0
  32. package/src/app/components/agent/history-view.tsx +136 -0
  33. package/src/app/components/agent/provider-logo.tsx +34 -0
  34. package/src/app/components/agent/transcript.tsx +620 -0
  35. package/src/app/components/asset-view.tsx +6 -6
  36. package/src/app/components/command/command-menu.tsx +2 -1
  37. package/src/app/components/command/slide-command-menu.tsx +10 -0
  38. package/src/app/components/icon-switcher-indicator.tsx +1 -1
  39. package/src/app/components/inspector/asset-picker-dialog.tsx +7 -5
  40. package/src/app/components/inspector/comment-layer.tsx +1012 -0
  41. package/src/app/components/inspector/image-crop-dialog.tsx +1 -5
  42. package/src/app/components/inspector/inspect-overlay.tsx +2 -39
  43. package/src/app/components/inspector/inspector-panel.tsx +12 -95
  44. package/src/app/components/inspector/inspector-provider.tsx +121 -47
  45. package/src/app/components/panel/editor-sidebar.tsx +85 -16
  46. package/src/app/components/panel/panel-shell.tsx +2 -2
  47. package/src/app/components/panel/resize-handle.tsx +129 -0
  48. package/src/app/components/player.tsx +0 -1
  49. package/src/app/components/preview-step-host.tsx +16 -0
  50. package/src/app/components/sidebar/sidebar-footer.tsx +1 -1
  51. package/src/app/components/sidebar/sidebar.tsx +4 -3
  52. package/src/app/components/style-panel/style-panel.tsx +3 -2
  53. package/src/app/components/themes/theme-detail.tsx +4 -2
  54. package/src/app/components/thumbnail-rail.tsx +77 -29
  55. package/src/app/favicon.ico +0 -0
  56. package/src/app/favicon.svg +39 -0
  57. package/src/app/index.html +2 -1
  58. package/src/app/lemonriver/agent/lemon.tsx +64 -0
  59. package/src/app/{components → lemonriver}/board/board-canvas.tsx +154 -23
  60. package/src/app/{routes/board.tsx → lemonriver/board/board-page.tsx} +63 -25
  61. package/src/app/{components → lemonriver}/board/board.css +51 -0
  62. package/src/app/{components → lemonriver}/board/layout.test.ts +53 -1
  63. package/src/app/{components → lemonriver}/board/layout.ts +51 -3
  64. package/src/app/lemonriver/board/model/cards.test.ts +239 -0
  65. package/src/app/lemonriver/board/model/cards.ts +234 -0
  66. package/src/app/lemonriver/board/model/structure.test.ts +101 -0
  67. package/src/app/lemonriver/board/model/structure.ts +82 -0
  68. package/src/app/lemonriver/board/page-node.tsx +481 -0
  69. package/src/app/lemonriver/board/use-board-cards.ts +210 -0
  70. package/src/app/{components → lemonriver}/board/use-board-columns.ts +7 -7
  71. package/src/app/{components → lemonriver}/board/use-page-order.ts +27 -15
  72. package/src/app/lemonriver/brand/app-icon.svg +44 -0
  73. package/src/app/lemonriver/brand/apple-touch-icon.png +0 -0
  74. package/src/app/lemonriver/brand/favicon-32.png +0 -0
  75. package/src/app/lemonriver/brand/mascot.tsx +59 -0
  76. package/src/app/lemonriver/brand/mascots/lemon-done.png +0 -0
  77. package/src/app/lemonriver/brand/mascots/lemon-idle.png +0 -0
  78. package/src/app/lemonriver/brand/mascots/lemon-needs-you.png +0 -0
  79. package/src/app/lemonriver/brand/mascots/lemon-thinking.png +0 -0
  80. package/src/app/lemonriver/brand/mascots/lemon-working.png +0 -0
  81. package/src/app/lemonriver/chrome/app-chrome.tsx +99 -0
  82. package/src/app/lemonriver/chrome/nav-row.tsx +34 -0
  83. package/src/app/lemonriver/chrome/not-found.tsx +34 -0
  84. package/src/app/lemonriver/chrome/sidebar-extras.tsx +57 -0
  85. package/src/app/lemonriver/chrome/use-slot.ts +23 -0
  86. package/src/app/lemonriver/features.test.ts +29 -0
  87. package/src/app/lemonriver/features.ts +26 -0
  88. package/src/app/lemonriver/feedback/export.ts +7 -0
  89. package/src/app/lemonriver/feedback/lemon-empty.tsx +54 -0
  90. package/src/app/lemonriver/feedback/offline-banner.tsx +41 -0
  91. package/src/app/lemonriver/feedback/pending-toast.test.ts +44 -0
  92. package/src/app/lemonriver/feedback/pending-toast.ts +39 -0
  93. package/src/app/lemonriver/feedback/toaster.tsx +34 -0
  94. package/src/app/lemonriver/feedback/upload.test.ts +26 -0
  95. package/src/app/lemonriver/feedback/upload.ts +19 -0
  96. package/src/app/lemonriver/home/brief-card.tsx +63 -0
  97. package/src/app/lemonriver/home/brief.test.ts +38 -0
  98. package/src/app/lemonriver/home/brief.ts +34 -0
  99. package/src/app/lemonriver/home/controls.tsx +93 -0
  100. package/src/app/lemonriver/home/deck-card.tsx +183 -0
  101. package/src/app/lemonriver/home/dialogs.tsx +292 -0
  102. package/src/app/lemonriver/home/home-page.tsx +335 -0
  103. package/src/app/lemonriver/home/sorting.test.ts +24 -0
  104. package/src/app/lemonriver/home/sorting.ts +59 -0
  105. package/src/app/lemonriver/home/time.test.ts +33 -0
  106. package/src/app/lemonriver/home/time.ts +33 -0
  107. package/src/app/lemonriver/home/use-deck-times.ts +27 -0
  108. package/src/app/lemonriver/home/use-delayed.ts +15 -0
  109. package/src/app/lemonriver/routes.test.tsx +37 -0
  110. package/src/app/lemonriver/routes.tsx +38 -0
  111. package/src/app/lemonriver/settings/settings-page.tsx +103 -0
  112. package/src/app/lemonriver/slide-extensions.tsx +73 -0
  113. package/src/app/lemonriver/text/all.ts +19 -0
  114. package/src/app/lemonriver/text/en.ts +106 -0
  115. package/src/app/lemonriver/text/es.ts +108 -0
  116. package/src/app/lemonriver/text/index.ts +9 -0
  117. package/src/app/lemonriver/text/ja.ts +106 -0
  118. package/src/app/lemonriver/text/text.test.ts +57 -0
  119. package/src/app/lemonriver/text/types.ts +111 -0
  120. package/src/app/lemonriver/text/zh-cn.ts +101 -0
  121. package/src/app/lemonriver/text/zh-tw.ts +101 -0
  122. package/src/app/lemonriver/theme/app.css +288 -0
  123. package/src/app/lemonriver/theme/controls.css +463 -0
  124. package/src/app/lemonriver/theme/index.css +3 -0
  125. package/src/app/lemonriver/theme/motion.ts +52 -0
  126. package/src/app/lemonriver/theme/pages.test.ts +66 -0
  127. package/src/app/lemonriver/theme/pages.ts +56 -0
  128. package/src/app/lemonriver/theme/theme-menu.tsx +64 -0
  129. package/src/app/lemonriver/theme/themes.test.ts +18 -0
  130. package/src/app/lemonriver/theme/themes.ts +16 -0
  131. package/src/app/lemonriver/theme/tokens.css +226 -0
  132. package/src/app/lemonriver/theme/use-theme.tsx +49 -0
  133. package/src/app/lemonriver/trash/api.test.ts +19 -0
  134. package/src/app/lemonriver/trash/api.ts +77 -0
  135. package/src/app/lemonriver/trash/trash-page.tsx +131 -0
  136. package/src/app/lib/agent/use-agent.ts +543 -0
  137. package/src/app/lib/inspector/freeze-motion.ts +61 -0
  138. package/src/app/lib/inspector/use-comments.ts +32 -3
  139. package/src/app/lib/locale-store.ts +6 -1
  140. package/src/app/lib/pptx/raster.ts +1 -1
  141. package/src/app/lib/print-ready.ts +9 -6
  142. package/src/app/lib/use-auto-grow.ts +15 -0
  143. package/src/app/lib/utils.ts +4 -0
  144. package/src/app/main.tsx +8 -1
  145. package/src/app/routes/home-shell.tsx +4 -2
  146. package/src/app/routes/home.tsx +43 -7
  147. package/src/app/routes/presenter.tsx +1 -16
  148. package/src/app/routes/preview.tsx +169 -0
  149. package/src/app/routes/slide.tsx +232 -188
  150. package/src/app/styles.css +235 -80
  151. package/src/editing/placeholder-id.ts +1 -0
  152. package/src/locale/en.ts +113 -26
  153. package/src/locale/es.ts +658 -0
  154. package/src/locale/index.ts +1 -0
  155. package/src/locale/ja.ts +106 -26
  156. package/src/locale/types.ts +119 -28
  157. package/src/locale/zh-cn.ts +106 -28
  158. package/src/locale/zh-tw.ts +106 -28
  159. package/src/app/assets/open-slide.png +0 -0
  160. package/src/app/components/board/page-node.tsx +0 -204
  161. package/src/app/components/inspector/comment-widget.tsx +0 -119
@@ -2,36 +2,47 @@ import {
2
2
  applyNodeChanges,
3
3
  Background,
4
4
  BackgroundVariant,
5
+ BaseEdge,
5
6
  type Edge,
7
+ EdgeLabelRenderer,
8
+ type EdgeProps,
9
+ type EdgeTypes,
10
+ type InternalNode,
6
11
  MarkerType,
7
12
  MiniMap,
8
13
  type Node,
9
14
  type NodeChange,
10
15
  type NodeProps,
11
16
  type NodeTypes,
17
+ type OnConnectEnd,
12
18
  type OnNodeDrag,
13
19
  Panel,
14
20
  ReactFlow,
15
21
  ReactFlowProvider,
22
+ useInternalNode,
16
23
  useReactFlow,
17
24
  } from '@xyflow/react';
18
- import { Maximize2, Minus, Plus } from 'lucide-react';
25
+ import { Link2, Link2Off, Maximize2, Minus, Plus, X } from 'lucide-react';
19
26
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
20
27
  import { Button } from '@/components/ui/button';
21
- import { useLocale } from '@/lib/use-locale';
22
28
  import { cn, pad2 } from '@/lib/utils';
23
- import { type BoardColumn, columnsAfterMove } from '../../../files/board-structure';
24
29
  import type { DesignSystem } from '../../lib/design';
25
30
  import type { Page } from '../../lib/sdk';
31
+ import { useLrText } from '../text';
26
32
  import {
27
33
  type BoardLayout,
34
+ type Box,
28
35
  CARD_BOX_H,
29
36
  CARD_BOX_W,
37
+ cardAtPoint,
30
38
  identityOrder,
31
39
  layoutBoard,
40
+ linkCurve,
32
41
  orderAfterMove,
33
42
  slotAtPoint,
34
43
  } from './layout';
44
+ import type { BoardCard, CardPatch } from './model/cards';
45
+ import { type BoardColumn, columnsAfterMove } from './model/structure';
35
46
  import { PageNode, type PageNodeData } from './page-node';
36
47
  import '@xyflow/react/dist/base.css';
37
48
  import './board.css';
@@ -41,6 +52,11 @@ type Props = {
41
52
  pages: Page[];
42
53
  columns: BoardColumn[];
43
54
  notes?: (string | undefined)[];
55
+ cards: (BoardCard | undefined)[];
56
+ cardsReady: boolean;
57
+ /** Linked pages, as deck positions. */
58
+ links: [number, number][];
59
+ showLinks: boolean;
44
60
  design?: DesignSystem;
45
61
  onOpenPage: (index: number) => void;
46
62
  onMovePage: (from: number, to: number) => void;
@@ -49,6 +65,10 @@ type Props = {
49
65
  onDuplicate: (index: number) => void;
50
66
  onDelete: (index: number) => void;
51
67
  onMoveToEnd: (index: number) => void;
68
+ onPatchCard: (index: number, patch: CardPatch) => void;
69
+ onLink: (a: number, b: number) => void;
70
+ onUnlink: (a: number, b: number) => void;
71
+ onToggleLinks: () => void;
52
72
  };
53
73
 
54
74
  type ColumnLabelData = {
@@ -61,7 +81,7 @@ type ColumnLabelData = {
61
81
 
62
82
  function ColumnLabel({ data }: NodeProps) {
63
83
  const { title, count, index, onRename, onAddPage } = data as unknown as ColumnLabelData;
64
- const t = useLocale();
84
+ const lr = useLrText();
65
85
  const [editing, setEditing] = useState(false);
66
86
 
67
87
  return (
@@ -74,8 +94,8 @@ function ColumnLabel({ data }: NodeProps) {
74
94
  // biome-ignore lint/a11y/noAutofocus: the field only exists once the title is clicked
75
95
  autoFocus
76
96
  defaultValue={title}
77
- aria-label={t.board.renameColumn}
78
- placeholder={t.board.columnTitlePlaceholder}
97
+ aria-label={lr.board.renameColumn}
98
+ placeholder={lr.board.columnTitlePlaceholder}
79
99
  onKeyDown={(e) => {
80
100
  e.stopPropagation();
81
101
  if (e.key === 'Enter') e.currentTarget.blur();
@@ -95,7 +115,7 @@ function ColumnLabel({ data }: NodeProps) {
95
115
  <button
96
116
  type="button"
97
117
  onClick={() => setEditing(true)}
98
- aria-label={t.board.renameColumn}
118
+ aria-label={lr.board.renameColumn}
99
119
  className="eyebrow min-w-0 truncate rounded-[4px] px-1.5 py-1 text-left motion-safe:transition-colors hover:bg-muted/60"
100
120
  >
101
121
  {title}
@@ -105,7 +125,7 @@ function ColumnLabel({ data }: NodeProps) {
105
125
  <button
106
126
  type="button"
107
127
  onClick={() => onAddPage(index)}
108
- aria-label={t.board.addPage}
128
+ aria-label={lr.board.addPage}
109
129
  className={cn(
110
130
  'ml-auto flex size-6 items-center justify-center rounded-[4px] text-muted-foreground/60',
111
131
  'motion-safe:transition-colors hover:bg-muted hover:text-foreground',
@@ -129,6 +149,52 @@ function DropSlot() {
129
149
 
130
150
  const nodeTypes: NodeTypes = { page: PageNode, columnLabel: ColumnLabel, dropSlot: DropSlot };
131
151
 
152
+ type LinkEdgeData = { a: number; b: number; onUnlink: (a: number, b: number) => void };
153
+
154
+ function boxOf(node: InternalNode | undefined): Box | null {
155
+ if (!node) return null;
156
+ const { x, y } = node.internals.positionAbsolute;
157
+ return {
158
+ x,
159
+ y,
160
+ width: node.measured.width ?? CARD_BOX_W,
161
+ height: node.measured.height ?? CARD_BOX_H,
162
+ };
163
+ }
164
+
165
+ /**
166
+ * A loose association between two pages. It is drawn thin and dashed so it can
167
+ * never be read as the deck's order, and it follows the cards as they move.
168
+ */
169
+ function LinkEdge({ id, source, target, data }: EdgeProps) {
170
+ const lr = useLrText();
171
+ const { a, b, onUnlink } = data as unknown as LinkEdgeData;
172
+ const from = boxOf(useInternalNode(source));
173
+ const to = boxOf(useInternalNode(target));
174
+ if (!from || !to) return null;
175
+ const curve = linkCurve(from, to);
176
+
177
+ return (
178
+ <>
179
+ <BaseEdge id={id} path={curve.path} className="osd-board-link" interactionWidth={14} />
180
+ <EdgeLabelRenderer>
181
+ <button
182
+ type="button"
183
+ aria-label={lr.board.removeLink}
184
+ title={lr.board.removeLink}
185
+ onClick={() => onUnlink(a, b)}
186
+ className="osd-board-link-remove nodrag nopan"
187
+ style={{ transform: `translate(-50%, -50%) translate(${curve.x}px, ${curve.y}px)` }}
188
+ >
189
+ <X className="size-3" strokeWidth={2.2} />
190
+ </button>
191
+ </EdgeLabelRenderer>
192
+ </>
193
+ );
194
+ }
195
+
196
+ const edgeTypes: EdgeTypes = { link: LinkEdge };
197
+
132
198
  const edgeStyle = { stroke: 'var(--osd-board-line)', strokeWidth: 1.5 } as const;
133
199
  const marker = {
134
200
  type: MarkerType.ArrowClosed,
@@ -137,6 +203,12 @@ const marker = {
137
203
  color: 'var(--osd-board-line)',
138
204
  };
139
205
 
206
+ const linkDraftStyle = {
207
+ stroke: 'var(--osd-board-link)',
208
+ strokeWidth: 1.5,
209
+ strokeDasharray: '5 4',
210
+ } as const;
211
+
140
212
  const pageIndexOf = (id: string) => Number(id.replace('page-', ''));
141
213
 
142
214
  type BuildArgs = {
@@ -146,8 +218,10 @@ type BuildArgs = {
146
218
  slideId: string;
147
219
  pages: Page[];
148
220
  notes?: (string | undefined)[];
221
+ cards: (BoardCard | undefined)[];
222
+ cardsReady: boolean;
149
223
  design?: DesignSystem;
150
- actions: Pick<PageNodeData, 'onDuplicate' | 'onDelete' | 'onMoveToEnd'>;
224
+ actions: Pick<PageNodeData, 'onDuplicate' | 'onDelete' | 'onMoveToEnd' | 'onPatchCard'>;
151
225
  columnActions: {
152
226
  onRename: (index: number, title: string) => void;
153
227
  onAddPage: (index: number) => void;
@@ -164,6 +238,8 @@ function buildNodes({
164
238
  slideId,
165
239
  pages,
166
240
  notes,
241
+ cards,
242
+ cardsReady,
167
243
  design,
168
244
  actions,
169
245
  columnActions,
@@ -199,7 +275,7 @@ function buildNodes({
199
275
  hidden: true,
200
276
  data: {},
201
277
  };
202
- const cards: Node[] = layout.slots.map((slot) => {
278
+ const pageNodes: Node[] = layout.slots.map((slot) => {
203
279
  const pageIndex = order[slot.index] ?? slot.index;
204
280
  return {
205
281
  id: `page-${pageIndex}`,
@@ -211,6 +287,9 @@ function buildNodes({
211
287
  slideId,
212
288
  page: pages[pageIndex],
213
289
  note: notes?.[pageIndex],
290
+ card: cards[pageIndex],
291
+ cardsReady,
292
+ canLink: cardsReady && pages.length > 1,
214
293
  index: pageIndex,
215
294
  total: pages.length,
216
295
  design,
@@ -219,7 +298,7 @@ function buildNodes({
219
298
  } satisfies PageNodeData as unknown as Record<string, unknown>,
220
299
  };
221
300
  });
222
- return [...labels, drop, ...cards];
301
+ return [...labels, drop, ...pageNodes];
223
302
  }
224
303
 
225
304
  function BoardFlow({
@@ -227,6 +306,10 @@ function BoardFlow({
227
306
  pages,
228
307
  columns,
229
308
  notes,
309
+ cards,
310
+ cardsReady,
311
+ links,
312
+ showLinks,
230
313
  design,
231
314
  onOpenPage,
232
315
  onMovePage,
@@ -235,15 +318,19 @@ function BoardFlow({
235
318
  onDuplicate,
236
319
  onDelete,
237
320
  onMoveToEnd,
321
+ onPatchCard,
322
+ onLink,
323
+ onUnlink,
324
+ onToggleLinks,
238
325
  }: Props) {
239
- const t = useLocale();
240
- const { fitView, zoomIn, zoomOut } = useReactFlow();
326
+ const lr = useLrText();
327
+ const { fitView, zoomIn, zoomOut, screenToFlowPosition } = useReactFlow();
241
328
 
242
329
  const layout = useMemo(() => layoutBoard(columns), [columns]);
243
330
 
244
331
  const actions = useMemo(
245
- () => ({ onDuplicate, onDelete, onMoveToEnd }),
246
- [onDuplicate, onDelete, onMoveToEnd],
332
+ () => ({ onDuplicate, onDelete, onMoveToEnd, onPatchCard }),
333
+ [onDuplicate, onDelete, onMoveToEnd, onPatchCard],
247
334
  );
248
335
 
249
336
  const columnActions = useMemo(
@@ -259,11 +346,13 @@ function BoardFlow({
259
346
  slideId,
260
347
  pages,
261
348
  notes,
349
+ cards,
350
+ cardsReady,
262
351
  design,
263
352
  actions,
264
353
  columnActions,
265
354
  }),
266
- [layout, slideId, pages, notes, design, actions, columnActions],
355
+ [layout, slideId, pages, notes, cards, cardsReady, design, actions, columnActions],
267
356
  );
268
357
 
269
358
  const [nodes, setNodes] = useState<Node[]>(baseNodes);
@@ -299,6 +388,8 @@ function BoardFlow({
299
388
  slideId,
300
389
  pages,
301
390
  notes,
391
+ cards,
392
+ cardsReady,
302
393
  design,
303
394
  actions,
304
395
  columnActions,
@@ -319,7 +410,7 @@ function BoardFlow({
319
410
  });
320
411
  });
321
412
  },
322
- [layout, columns, slideId, pages, notes, design, actions, columnActions],
413
+ [layout, columns, slideId, pages, notes, cards, cardsReady, design, actions, columnActions],
323
414
  );
324
415
 
325
416
  const handleDragStop = useCallback<OnNodeDrag>(
@@ -358,7 +449,7 @@ function BoardFlow({
358
449
 
359
450
  const edges = useMemo<Edge[]>(() => {
360
451
  const byIndex = new Map(layout.slots.map((slot) => [slot.index, slot]));
361
- return pages.slice(0, -1).map((_, i) => {
452
+ const mainLine: Edge[] = pages.slice(0, -1).map((_, i) => {
362
453
  const sameColumn = byIndex.get(i)?.column === byIndex.get(i + 1)?.column;
363
454
  return {
364
455
  id: `line-${i}`,
@@ -373,20 +464,50 @@ function BoardFlow({
373
464
  focusable: false,
374
465
  };
375
466
  });
376
- }, [layout, pages]);
467
+ if (!showLinks) return mainLine;
468
+ const linkLines: Edge[] = links.map(([a, b]) => ({
469
+ id: `link-${Math.min(a, b)}-${Math.max(a, b)}`,
470
+ source: `page-${a}`,
471
+ target: `page-${b}`,
472
+ type: 'link',
473
+ data: { a, b, onUnlink } satisfies LinkEdgeData,
474
+ selectable: false,
475
+ focusable: false,
476
+ }));
477
+ return [...mainLine, ...linkLines];
478
+ }, [layout, pages, links, showLinks, onUnlink]);
479
+
480
+ // A link is drawn by dragging a card's dot onto another card. The whole card is
481
+ // the target rather than a handle on it, because a handle is too small to hit
482
+ // at the zoom a long deck is read at.
483
+ const handleConnectEnd = useCallback<OnConnectEnd>(
484
+ (event, state) => {
485
+ const from = state.fromNode;
486
+ if (from?.type !== 'page') return;
487
+ const point = 'changedTouches' in event ? event.changedTouches[0] : event;
488
+ if (!point) return;
489
+ const at = screenToFlowPosition({ x: point.clientX, y: point.clientY });
490
+ const target = cardAtPoint(layout, at.x, at.y);
491
+ const source = pageIndexOf(from.id);
492
+ if (target !== null && target !== source) onLink(source, target);
493
+ },
494
+ [layout, screenToFlowPosition, onLink],
495
+ );
377
496
 
378
497
  return (
379
498
  <ReactFlow
380
499
  nodes={nodes}
381
500
  edges={edges}
382
501
  nodeTypes={nodeTypes}
502
+ edgeTypes={edgeTypes}
383
503
  onNodesChange={onNodesChange}
384
504
  onNodeDrag={handleDrag}
385
505
  onNodeDragStop={handleDragStop}
386
506
  onNodeDoubleClick={(_, node) => {
387
507
  if (node.type === 'page') onOpenPage(pageIndexOf(node.id));
388
508
  }}
389
- nodesConnectable={false}
509
+ onConnectEnd={handleConnectEnd}
510
+ connectionLineStyle={linkDraftStyle}
390
511
  edgesFocusable={false}
391
512
  onlyRenderVisibleElements
392
513
  onInit={frameStart}
@@ -409,7 +530,7 @@ function BoardFlow({
409
530
  <Button
410
531
  variant="outline"
411
532
  size="icon-sm"
412
- aria-label={t.board.zoomOut}
533
+ aria-label={lr.board.zoomOut}
413
534
  onClick={() => zoomOut()}
414
535
  >
415
536
  <Minus />
@@ -417,14 +538,24 @@ function BoardFlow({
417
538
  <Button
418
539
  variant="outline"
419
540
  size="icon-sm"
420
- aria-label={t.board.zoomIn}
541
+ aria-label={lr.board.zoomIn}
421
542
  onClick={() => zoomIn()}
422
543
  >
423
544
  <Plus />
424
545
  </Button>
425
- <Button variant="outline" size="icon-sm" aria-label={t.board.fitView} onClick={fitAll}>
546
+ <Button variant="outline" size="icon-sm" aria-label={lr.board.fitView} onClick={fitAll}>
426
547
  <Maximize2 />
427
548
  </Button>
549
+ <Button
550
+ variant="outline"
551
+ size="icon-sm"
552
+ aria-label={showLinks ? lr.board.hideLinks : lr.board.showLinks}
553
+ aria-pressed={showLinks}
554
+ title={showLinks ? lr.board.hideLinks : lr.board.showLinks}
555
+ onClick={onToggleLinks}
556
+ >
557
+ {showLinks ? <Link2 /> : <Link2Off />}
558
+ </Button>
428
559
  </Panel>
429
560
  </ReactFlow>
430
561
  );
@@ -1,50 +1,75 @@
1
1
  import { ChevronLeft } from 'lucide-react';
2
- import { lazy, Suspense, useCallback } from 'react';
2
+ import { lazy, Suspense, useCallback, useEffect, useState } from 'react';
3
3
  import { useNavigate, useParams } from 'react-router-dom';
4
4
  import { Button } from '@/components/ui/button';
5
5
  import { useDocumentTitle } from '@/lib/use-document-title';
6
- import { format, useLocale } from '@/lib/use-locale';
6
+ import { format } from '@/lib/use-locale';
7
7
  import { pad2 } from '@/lib/utils';
8
- import { columnStarts } from '../../files/board-structure';
9
- import { useBoardColumns } from '../components/board/use-board-columns';
10
- import { usePageOrder } from '../components/board/use-page-order';
11
- import type { Page } from '../lib/sdk';
12
- import { useSlideModule } from '../lib/use-slide-module';
8
+ import type { Page } from '../../lib/sdk';
9
+ import { useSlideModule } from '../../lib/use-slide-module';
10
+ import { useLrText } from '../text';
11
+ import { columnStarts } from './model/structure';
12
+ import { useBoardCards } from './use-board-cards';
13
+ import { useBoardColumns } from './use-board-columns';
14
+ import { usePageOrder } from './use-page-order';
13
15
 
14
- const BoardCanvas = lazy(() => import('../components/board/board-canvas'));
16
+ const BoardCanvas = lazy(() => import('./board-canvas'));
15
17
 
16
18
  // A fresh [] on every render would restart the page-order state in a loop while
17
19
  // the deck module is still loading.
18
20
  const NO_PAGES: Page[] = [];
19
21
 
22
+ const LINKS_KEY = 'open-slide:board-links-visible';
23
+
24
+ function useLinksVisible() {
25
+ const [visible, setVisible] = useState(() => {
26
+ if (typeof window === 'undefined') return true;
27
+ return window.localStorage.getItem(LINKS_KEY) !== '0';
28
+ });
29
+ useEffect(() => {
30
+ window.localStorage.setItem(LINKS_KEY, visible ? '1' : '0');
31
+ }, [visible]);
32
+ const toggle = useCallback(() => setVisible((v) => !v), []);
33
+ return [visible, toggle] as const;
34
+ }
35
+
20
36
  export function Board() {
21
37
  const { slideId = '' } = useParams();
22
38
  const navigate = useNavigate();
23
39
  const { slide, error } = useSlideModule(slideId);
24
- const t = useLocale();
40
+ const lr = useLrText();
25
41
  useDocumentTitle(slide?.meta?.title);
26
42
 
27
43
  const modulePages = slide?.default ?? NO_PAGES;
28
44
  const { pages, reorder, duplicate, insert, remove } = usePageOrder(slideId, modulePages);
29
45
 
30
46
  const columnTitle = useCallback(
31
- (n: number) => format(t.board.columnFallback, { n }),
32
- [t.board.columnFallback],
47
+ (n: number) => format(lr.board.columnFallback, { n }),
48
+ [lr.board.columnFallback],
33
49
  );
34
50
  const { columns, moveBetweenColumns, resizeColumnAt, growColumn, renameColumn } = useBoardColumns(
35
51
  slideId,
36
52
  pages,
37
53
  columnTitle,
38
54
  );
55
+ const { ready, cards, pairs, patch, link, unlink, beginOp } = useBoardCards(
56
+ slideId,
57
+ modulePages,
58
+ pages.length,
59
+ );
60
+ const [showLinks, toggleLinks] = useLinksVisible();
39
61
 
40
- // Order and structure move together: every path that reorders a deck goes
41
- // through here, so the columns can never drift out of step with the pages.
62
+ // Order, structure and the board's own card data move together: every path
63
+ // that changes the deck's pages goes through here, so none of them can drift
64
+ // out of step with the pages.
42
65
  const movePage = useCallback(
43
66
  (from: number, to: number) => {
67
+ if (from === to) return;
68
+ const settle = beginOp({ kind: 'move', from, to });
44
69
  moveBetweenColumns(from, to);
45
- void reorder(from, to);
70
+ void reorder(from, to).then(settle);
46
71
  },
47
- [moveBetweenColumns, reorder],
72
+ [beginOp, moveBetweenColumns, reorder],
48
73
  );
49
74
 
50
75
  const openPage = useCallback(
@@ -56,10 +81,11 @@ export function Board() {
56
81
 
57
82
  const duplicatePage = useCallback(
58
83
  (index: number) => {
84
+ const settle = beginOp({ kind: 'duplicate', index });
59
85
  resizeColumnAt(index, 1);
60
- void duplicate(index);
86
+ void duplicate(index).then(settle);
61
87
  },
62
- [duplicate, resizeColumnAt],
88
+ [beginOp, duplicate, resizeColumnAt],
63
89
  );
64
90
 
65
91
  // A new page lands at the end of the column whose + was clicked.
@@ -69,10 +95,12 @@ export function Board() {
69
95
  const starts = columnStarts(columns);
70
96
  const start = starts[columnIndex];
71
97
  const size = columns[columnIndex].size;
98
+ const at = size > 0 ? start + size : start;
99
+ const settle = beginOp({ kind: 'insert', index: at });
72
100
  growColumn(columnIndex, 1);
73
- void insert(size > 0 ? start + size : start);
101
+ void insert(at).then(settle);
74
102
  },
75
- [columns, growColumn, insert],
103
+ [beginOp, columns, growColumn, insert],
76
104
  );
77
105
 
78
106
  const moveToEnd = useCallback(
@@ -82,10 +110,12 @@ export function Board() {
82
110
 
83
111
  const deletePage = useCallback(
84
112
  (index: number) => {
113
+ if (pages.length <= 1) return;
114
+ const settle = beginOp({ kind: 'delete', index });
85
115
  resizeColumnAt(index, -1);
86
- void remove(index);
116
+ void remove(index).then(settle);
87
117
  },
88
- [remove, resizeColumnAt],
118
+ [beginOp, pages.length, remove, resizeColumnAt],
89
119
  );
90
120
 
91
121
  return (
@@ -94,18 +124,18 @@ export function Board() {
94
124
  <Button
95
125
  variant="ghost"
96
126
  size="icon-sm"
97
- aria-label={t.board.backToDeck}
127
+ aria-label={lr.board.backToDeck}
98
128
  onClick={() => navigate(`/s/${encodeURIComponent(slideId)}`)}
99
129
  >
100
130
  <ChevronLeft />
101
131
  </Button>
102
- <span className="eyebrow">{t.board.title}</span>
132
+ <span className="eyebrow">{lr.board.title}</span>
103
133
  <span className="truncate text-[13px] text-muted-foreground">
104
134
  {slide?.meta?.title ?? slideId}
105
135
  </span>
106
136
  <span className="folio ml-auto">{pad2(pages.length)}</span>
107
137
  <span className="hidden text-[11.5px] text-muted-foreground/70 sm:inline">
108
- {t.board.hint}
138
+ {lr.board.hint}
109
139
  </span>
110
140
  </header>
111
141
  <div className="relative min-h-0 flex-1">
@@ -115,7 +145,7 @@ export function Board() {
115
145
  </p>
116
146
  ) : pages.length === 0 || !columns ? (
117
147
  <p className="grid h-full place-items-center text-[13px] text-muted-foreground">
118
- {t.board.loading}
148
+ {lr.board.loading}
119
149
  </p>
120
150
  ) : (
121
151
  <Suspense fallback={null}>
@@ -123,6 +153,10 @@ export function Board() {
123
153
  slideId={slideId}
124
154
  pages={pages}
125
155
  notes={slide?.notes}
156
+ cards={cards}
157
+ cardsReady={ready}
158
+ links={pairs}
159
+ showLinks={showLinks}
126
160
  columns={columns}
127
161
  design={slide?.design}
128
162
  onOpenPage={openPage}
@@ -132,6 +166,10 @@ export function Board() {
132
166
  onDuplicate={duplicatePage}
133
167
  onDelete={deletePage}
134
168
  onMoveToEnd={moveToEnd}
169
+ onPatchCard={patch}
170
+ onLink={link}
171
+ onUnlink={unlink}
172
+ onToggleLinks={toggleLinks}
135
173
  />
136
174
  </Suspense>
137
175
  )}
@@ -4,6 +4,7 @@
4
4
  --osd-board-line: color-mix(in oklab, var(--color-muted-foreground) 45%, transparent);
5
5
  --osd-board-mask: color-mix(in oklab, var(--color-background) 82%, transparent);
6
6
  --osd-board-minimap-node: color-mix(in oklab, var(--color-foreground) 28%, transparent);
7
+ --osd-board-link: color-mix(in oklab, var(--color-brand) 55%, transparent);
7
8
  background: var(--color-background);
8
9
  }
9
10
 
@@ -73,3 +74,53 @@
73
74
  .osd-board .react-flow__attribution a {
74
75
  color: color-mix(in oklab, var(--color-muted-foreground) 60%, transparent);
75
76
  }
77
+
78
+ /* Links are loose associations, so they stay thin, dashed and quiet next to the
79
+ solid main line that carries the deck's order. */
80
+ .osd-board .osd-board-link {
81
+ stroke: var(--osd-board-link);
82
+ stroke-width: 1.25;
83
+ stroke-dasharray: 5 4;
84
+ }
85
+
86
+ .osd-board-link-remove {
87
+ position: absolute;
88
+ display: flex;
89
+ align-items: center;
90
+ justify-content: center;
91
+ width: 20px;
92
+ height: 20px;
93
+ border-radius: 999px;
94
+ border: 1px solid var(--color-border);
95
+ background: var(--color-card);
96
+ color: var(--color-muted-foreground);
97
+ pointer-events: all;
98
+ opacity: 0.7;
99
+ transition:
100
+ opacity 120ms ease,
101
+ color 120ms ease;
102
+ }
103
+
104
+ .osd-board-link-remove:hover,
105
+ .osd-board-link-remove:focus-visible {
106
+ opacity: 1;
107
+ color: var(--color-destructive);
108
+ }
109
+
110
+ /* The dot a link is dragged from. It only shows on the card under the pointer,
111
+ so a board at rest carries no extra chrome. */
112
+ .osd-board .osd-board-link-handle {
113
+ width: 14px;
114
+ height: 14px;
115
+ border-radius: 999px;
116
+ border: 2px solid var(--color-card);
117
+ background: var(--color-brand);
118
+ cursor: crosshair;
119
+ opacity: 0;
120
+ transition: opacity 120ms ease;
121
+ }
122
+
123
+ .osd-board .react-flow__node-page:hover .osd-board-link-handle,
124
+ .osd-board .osd-board-link-handle.connectingfrom {
125
+ opacity: 1;
126
+ }
@@ -1,6 +1,17 @@
1
1
  import { describe, expect, it } from 'vitest';
2
2
  import type { Page } from '../../lib/sdk';
3
- import { CARD_H, CARD_W, layoutBoard, orderAfterMove, seedColumns, slotAtPoint } from './layout';
3
+ import {
4
+ CARD_BOX_H,
5
+ CARD_BOX_W,
6
+ CARD_H,
7
+ CARD_W,
8
+ cardAtPoint,
9
+ layoutBoard,
10
+ linkCurve,
11
+ orderAfterMove,
12
+ seedColumns,
13
+ slotAtPoint,
14
+ } from './layout';
4
15
 
5
16
  /** Pages are identified by their component name, so the fixtures need real names. */
6
17
  function named(name: string): Page {
@@ -107,3 +118,44 @@ describe('orderAfterMove', () => {
107
118
  expect(orderAfterMove(5, 2, 2)).toEqual([0, 1, 2, 3, 4]);
108
119
  });
109
120
  });
121
+
122
+ describe('cardAtPoint', () => {
123
+ const layout = layoutBoard([
124
+ { title: 'Cover', size: 2 },
125
+ { title: 'Chapter One', size: 2 },
126
+ ]);
127
+
128
+ it('finds the card under a point anywhere inside it', () => {
129
+ const slot = layout.slots[3];
130
+ expect(cardAtPoint(layout, slot.x + CARD_BOX_W - 1, slot.y + CARD_BOX_H - 1)).toBe(3);
131
+ });
132
+
133
+ it('reports empty canvas between cards as no card', () => {
134
+ const [a, b] = [layout.slots[0], layout.slots[1]];
135
+ expect(cardAtPoint(layout, a.x + 10, (a.y + CARD_BOX_H + b.y) / 2)).toBeNull();
136
+ expect(cardAtPoint(layout, a.x + CARD_BOX_W + 20, a.y + 10)).toBeNull();
137
+ });
138
+ });
139
+
140
+ describe('linkCurve', () => {
141
+ const box = (x: number, y: number) => ({ x, y, width: 100, height: 60 });
142
+
143
+ it('bows a link between cards in one column out to the right of the column', () => {
144
+ const curve = linkCurve(box(0, 0), box(0, 400));
145
+ expect(curve.x).toBeGreaterThan(100);
146
+ expect(curve.path.startsWith('M 100,18')).toBe(true);
147
+ });
148
+
149
+ it('never ends where the main line does, at the middle of a card side', () => {
150
+ const curve = linkCurve(box(0, 0), box(300, 0));
151
+ expect(curve.path).not.toContain(',30');
152
+ });
153
+
154
+ it('joins cards in different columns between their facing sides, whichever is first', () => {
155
+ const forward = linkCurve(box(0, 0), box(300, 200));
156
+ const backward = linkCurve(box(300, 200), box(0, 0));
157
+ expect(forward.path).toBe(backward.path);
158
+ expect(forward.path.startsWith('M 100,18')).toBe(true);
159
+ expect(forward.path.endsWith('300,218')).toBe(true);
160
+ });
161
+ });