@lemonriver/core 0.3.0 → 0.5.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/README.md +14 -4
- package/dist/{build-Bqo69DWP.js → build-CS1goZxt.js} +1 -1
- package/dist/cli/bin.js +4 -4
- package/dist/{config-DJ5rkMMg.js → config-BpbcCbUv.js} +3835 -1532
- package/dist/{config-teo3kWz7.d.ts → config-CYNOR93W.d.ts} +1 -1
- package/dist/{dev-B2FJD5bJ.js → dev-BpYnfgLL.js} +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/locale/index.d.ts +1 -1
- package/dist/locale/index.js +1 -1
- package/dist/{preview-C93BOZL1.js → preview-HSzPPkSs.js} +1 -1
- package/dist/{types-DFK02XVv.d.ts → types-tdaXSyah.d.ts} +1 -0
- package/dist/{update-DsxZBtwv.js → update-CMRxtTc9.js} +18 -8
- package/dist/vite/index.d.ts +1 -1
- package/dist/vite/index.js +1 -1
- package/dist/{zh-tw-DwTAZKa6.js → zh-tw-DcrDeKxr.js} +5 -0
- package/package.json +2 -2
- package/src/agent/prompt.ts +2 -0
- package/src/agent/types.ts +14 -2
- package/src/app/components/agent/agent-panel.tsx +19 -5
- package/src/app/components/agent/connect-view.tsx +1 -1
- package/src/app/components/agent/provider-logo.tsx +10 -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/sidebar-footer.tsx +6 -1
- package/src/app/components/thumbnail-rail.tsx +1 -0
- package/src/app/lemonriver/agent/lemon.tsx +16 -1
- package/src/app/lemonriver/agent/provider-marks.tsx +53 -0
- package/src/app/lemonriver/agent-prefs/prefs.test.ts +173 -0
- package/src/app/lemonriver/agent-prefs/prefs.ts +137 -0
- package/src/app/lemonriver/agent-prefs/use-prefs.ts +36 -0
- package/src/app/lemonriver/agent-providers/section.tsx +75 -0
- package/src/app/lemonriver/agent-providers/use-providers.ts +61 -0
- package/src/app/lemonriver/board/blocks/block-panel.tsx +666 -0
- package/src/app/lemonriver/board/blocks/cache.ts +28 -0
- package/src/app/lemonriver/board/blocks/change-list.tsx +189 -0
- package/src/app/lemonriver/board/blocks/classify.test.ts +204 -0
- package/src/app/lemonriver/board/blocks/classify.ts +125 -0
- package/src/app/lemonriver/board/blocks/snapshot.ts +86 -0
- package/src/app/lemonriver/board/board-canvas.tsx +627 -104
- package/src/app/lemonriver/board/board-page.tsx +1687 -91
- package/src/app/lemonriver/board/board.css +58 -7
- package/src/app/lemonriver/board/layout.test.ts +84 -0
- package/src/app/lemonriver/board/layout.ts +112 -11
- package/src/app/lemonriver/board/model/agent-tasks.test.ts +200 -0
- package/src/app/lemonriver/board/model/agent-tasks.ts +191 -0
- package/src/app/lemonriver/board/model/apply-prompt.test.ts +121 -0
- package/src/app/lemonriver/board/model/apply-prompt.ts +115 -0
- package/src/app/lemonriver/board/model/apply.ts +71 -0
- package/src/app/lemonriver/board/model/cards.test.ts +95 -2
- package/src/app/lemonriver/board/model/cards.ts +88 -20
- package/src/app/lemonriver/board/model/changes.test.ts +244 -0
- package/src/app/lemonriver/board/model/changes.ts +268 -0
- package/src/app/lemonriver/board/model/filter.test.ts +50 -0
- package/src/app/lemonriver/board/model/filter.ts +42 -0
- package/src/app/lemonriver/board/model/history.test.ts +71 -0
- package/src/app/lemonriver/board/model/history.ts +51 -0
- package/src/app/lemonriver/board/model/restructure.test.ts +205 -0
- package/src/app/lemonriver/board/model/restructure.ts +169 -0
- package/src/app/lemonriver/board/model/structure.test.ts +249 -0
- package/src/app/lemonriver/board/model/structure.ts +209 -0
- package/src/app/lemonriver/board/model/timing.test.ts +113 -0
- package/src/app/lemonriver/board/model/timing.ts +117 -0
- package/src/app/lemonriver/board/page-node.tsx +236 -55
- package/src/app/lemonriver/board/status-style.ts +25 -0
- package/src/app/lemonriver/board/use-board-apply.ts +206 -0
- package/src/app/lemonriver/board/use-board-cards.ts +108 -5
- package/src/app/lemonriver/board/use-board-changes.ts +108 -0
- package/src/app/lemonriver/board/use-board-columns.ts +37 -56
- package/src/app/lemonriver/board/use-board-comments.ts +36 -0
- package/src/app/lemonriver/board/use-board-restructures.ts +107 -0
- package/src/app/lemonriver/board/use-history.ts +86 -0
- package/src/app/lemonriver/board/use-page-order.ts +65 -38
- package/src/app/lemonriver/board/use-target-minutes.ts +47 -0
- package/src/app/lemonriver/board/views/block-readings.tsx +46 -0
- package/src/app/lemonriver/board/views/list-view.tsx +356 -0
- package/src/app/lemonriver/board/views/progress.tsx +32 -0
- package/src/app/lemonriver/board/views/timeline-view.tsx +341 -0
- package/src/app/lemonriver/brand/mascot.tsx +86 -0
- package/src/app/lemonriver/brand/mascots/design-done.png +0 -0
- package/src/app/lemonriver/brand/mascots/design-idle.png +0 -0
- package/src/app/lemonriver/brand/mascots/design-needs-you.png +0 -0
- package/src/app/lemonriver/brand/mascots/design-working.png +0 -0
- package/src/app/lemonriver/brand/mascots/outline-done.png +0 -0
- package/src/app/lemonriver/brand/mascots/outline-idle.png +0 -0
- package/src/app/lemonriver/brand/mascots/outline-needs-you.png +0 -0
- package/src/app/lemonriver/brand/mascots/outline-working.png +0 -0
- package/src/app/lemonriver/brand/mascots/research-done.png +0 -0
- package/src/app/lemonriver/brand/mascots/research-idle.png +0 -0
- package/src/app/lemonriver/brand/mascots/research-needs-you.png +0 -0
- package/src/app/lemonriver/brand/mascots/research-working.png +0 -0
- package/src/app/lemonriver/brand/mascots/review-done.png +0 -0
- package/src/app/lemonriver/brand/mascots/review-idle.png +0 -0
- package/src/app/lemonriver/brand/mascots/review-needs-you.png +0 -0
- package/src/app/lemonriver/brand/mascots/review-working.png +0 -0
- package/src/app/lemonriver/chrome/app-chrome.tsx +2 -0
- package/src/app/lemonriver/features.test.ts +5 -0
- package/src/app/lemonriver/features.ts +2 -1
- package/src/app/lemonriver/home/brief-card.tsx +8 -1
- package/src/app/lemonriver/home/home-page.tsx +11 -7
- package/src/app/lemonriver/onboarding/onboarding.tsx +182 -0
- package/src/app/lemonriver/outline/build-team.tsx +278 -0
- package/src/app/lemonriver/outline/describe-page.tsx +380 -0
- package/src/app/lemonriver/outline/files.test.ts +90 -0
- package/src/app/lemonriver/outline/files.ts +69 -0
- package/src/app/lemonriver/outline/model.test.ts +672 -0
- package/src/app/lemonriver/outline/model.ts +455 -0
- package/src/app/lemonriver/outline/outline-page.tsx +537 -0
- package/src/app/lemonriver/outline/pending-pages.tsx +39 -0
- package/src/app/lemonriver/outline/rule.ts +3 -0
- package/src/app/lemonriver/outline/steps.tsx +43 -0
- package/src/app/lemonriver/outline/use-build-driver.ts +258 -0
- package/src/app/lemonriver/routes.test.tsx +6 -6
- package/src/app/lemonriver/routes.tsx +28 -0
- package/src/app/lemonriver/settings/settings-page.tsx +214 -0
- package/src/app/lemonriver/slide-extensions.tsx +45 -26
- package/src/app/lemonriver/text/en.ts +320 -0
- package/src/app/lemonriver/text/es.ts +311 -0
- package/src/app/lemonriver/text/ja.ts +313 -0
- package/src/app/lemonriver/text/text.test.ts +33 -0
- package/src/app/lemonriver/text/types.ts +339 -0
- package/src/app/lemonriver/text/zh-cn.ts +307 -0
- package/src/app/lemonriver/text/zh-tw.ts +307 -0
- package/src/app/lemonriver/theme/app.css +12 -1
- package/src/app/lemonriver/theme/lemon-icon.tsx +6 -0
- package/src/app/lemonriver/theme/pages.test.ts +4 -0
- package/src/app/lemonriver/theme/pages.ts +11 -2
- package/src/app/lemonriver/theme/theme-menu.tsx +3 -2
- package/src/app/lemonriver/theme/use-theme.tsx +2 -2
- package/src/app/lemonriver/update/beta-badge.tsx +26 -0
- package/src/app/lemonriver/update/prompt.test.ts +84 -0
- package/src/app/lemonriver/update/prompt.ts +48 -0
- package/src/app/lemonriver/update/update-prompt.tsx +113 -0
- package/src/app/lib/agent/use-agent.ts +4 -3
- package/src/app/routes/home.tsx +13 -5
- package/src/app/routes/slide.tsx +71 -14
- package/src/locale/en.ts +1 -0
- package/src/locale/es.ts +1 -0
- package/src/locale/ja.ts +1 -0
- package/src/locale/types.ts +1 -0
- package/src/locale/zh-cn.ts +1 -0
- package/src/locale/zh-tw.ts +1 -0
- package/src/app/assets/open-slide.svg +0 -39
- package/src/app/favicon.ico +0 -0
- package/src/app/favicon.svg +0 -39
|
@@ -0,0 +1,666 @@
|
|
|
1
|
+
import {
|
|
2
|
+
closestCenter,
|
|
3
|
+
DndContext,
|
|
4
|
+
type DragEndEvent,
|
|
5
|
+
KeyboardSensor,
|
|
6
|
+
PointerSensor,
|
|
7
|
+
useSensor,
|
|
8
|
+
useSensors,
|
|
9
|
+
} from '@dnd-kit/core';
|
|
10
|
+
import {
|
|
11
|
+
arrayMove,
|
|
12
|
+
SortableContext,
|
|
13
|
+
sortableKeyboardCoordinates,
|
|
14
|
+
useSortable,
|
|
15
|
+
verticalListSortingStrategy,
|
|
16
|
+
} from '@dnd-kit/sortable';
|
|
17
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
18
|
+
import {
|
|
19
|
+
AlignLeft,
|
|
20
|
+
BarChart3,
|
|
21
|
+
GripVertical,
|
|
22
|
+
Hash,
|
|
23
|
+
Image as ImageIcon,
|
|
24
|
+
ListChecks,
|
|
25
|
+
Maximize2,
|
|
26
|
+
MoreHorizontal,
|
|
27
|
+
PenLine,
|
|
28
|
+
Quote,
|
|
29
|
+
Scissors,
|
|
30
|
+
Sparkles,
|
|
31
|
+
StickyNote,
|
|
32
|
+
Type,
|
|
33
|
+
} from 'lucide-react';
|
|
34
|
+
import { type ReactNode, useCallback, useEffect, useMemo, useState } from 'react';
|
|
35
|
+
import { toast } from 'sonner';
|
|
36
|
+
import { Button, buttonVariants } from '@/components/ui/button';
|
|
37
|
+
import {
|
|
38
|
+
DropdownMenu,
|
|
39
|
+
DropdownMenuContent,
|
|
40
|
+
DropdownMenuItem,
|
|
41
|
+
DropdownMenuSub,
|
|
42
|
+
DropdownMenuSubContent,
|
|
43
|
+
DropdownMenuSubTrigger,
|
|
44
|
+
DropdownMenuTrigger,
|
|
45
|
+
} from '@/components/ui/dropdown-menu';
|
|
46
|
+
import { format } from '@/lib/use-locale';
|
|
47
|
+
import { cn } from '@/lib/utils';
|
|
48
|
+
import type { DesignSystem } from '../../../lib/design';
|
|
49
|
+
import { CANVAS_WIDTH, type Page } from '../../../lib/sdk';
|
|
50
|
+
import { useLrText } from '../../text';
|
|
51
|
+
import { PAGE_ACTIONS, type PageAction } from '../model/agent-tasks';
|
|
52
|
+
import {
|
|
53
|
+
type EffectiveBlock,
|
|
54
|
+
effectiveBlocks,
|
|
55
|
+
type Placement,
|
|
56
|
+
parkedBlocks,
|
|
57
|
+
placeBlock,
|
|
58
|
+
type Spot,
|
|
59
|
+
unparkBlock,
|
|
60
|
+
} from '../model/changes';
|
|
61
|
+
import type { SplitBlock } from '../model/restructure';
|
|
62
|
+
import { PagePreview } from '../page-node';
|
|
63
|
+
import type { PageRead } from './cache';
|
|
64
|
+
import type { BlockKind } from './classify';
|
|
65
|
+
|
|
66
|
+
const PANEL_WIDTH = 320;
|
|
67
|
+
const PREVIEW_WIDTH = 288;
|
|
68
|
+
const PREVIEW_SCALE = PREVIEW_WIDTH / CANVAS_WIDTH;
|
|
69
|
+
|
|
70
|
+
const KIND_ICON: Record<BlockKind, typeof Type> = {
|
|
71
|
+
title: Type,
|
|
72
|
+
point: ListChecks,
|
|
73
|
+
text: AlignLeft,
|
|
74
|
+
image: ImageIcon,
|
|
75
|
+
chart: BarChart3,
|
|
76
|
+
quote: Quote,
|
|
77
|
+
number: Hash,
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const blockInfo = (block: EffectiveBlock) => ({
|
|
81
|
+
kind: block.kind,
|
|
82
|
+
text: block.text,
|
|
83
|
+
loc: block.loc,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const ASK_ICON: Record<PageAction, typeof Type> = {
|
|
87
|
+
rewrite: PenLine,
|
|
88
|
+
chart: BarChart3,
|
|
89
|
+
memo: StickyNote,
|
|
90
|
+
expand: Maximize2,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const DRAG_KEYS = new Set([
|
|
94
|
+
'ArrowUp',
|
|
95
|
+
'ArrowDown',
|
|
96
|
+
'ArrowLeft',
|
|
97
|
+
'ArrowRight',
|
|
98
|
+
' ',
|
|
99
|
+
'Spacebar',
|
|
100
|
+
'Enter',
|
|
101
|
+
'Escape',
|
|
102
|
+
'Tab',
|
|
103
|
+
]);
|
|
104
|
+
|
|
105
|
+
const listId = (block: string) => `block:${block}`;
|
|
106
|
+
const parkedId = (item: Placement) => `parked:${item.origin.page}:${item.origin.block}`;
|
|
107
|
+
|
|
108
|
+
export type BlockPanelProps = {
|
|
109
|
+
slideId: string;
|
|
110
|
+
pages: Page[];
|
|
111
|
+
pageKeys: string[];
|
|
112
|
+
design?: DesignSystem;
|
|
113
|
+
/** The card last clicked, or null. */
|
|
114
|
+
selected: number | null;
|
|
115
|
+
changes: Placement[];
|
|
116
|
+
onChanges: (next: Placement[]) => void;
|
|
117
|
+
cardTitle: (index: number) => string;
|
|
118
|
+
cardMemo: (index: number) => string;
|
|
119
|
+
/** The four one-page actions, for the page in the panel. */
|
|
120
|
+
agent: { hint: string | null; onTask: (action: PageAction) => void };
|
|
121
|
+
/** The agent is applying the list: nothing here may be touched. */
|
|
122
|
+
readOnly?: boolean;
|
|
123
|
+
onSplit: (page: string, blocks: SplitBlock[]) => void;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The blocks of one page, and the holding area. Nothing here reaches the deck:
|
|
128
|
+
* every move is written down and handed over later.
|
|
129
|
+
*/
|
|
130
|
+
export function BlockPanel({
|
|
131
|
+
slideId,
|
|
132
|
+
pages,
|
|
133
|
+
pageKeys,
|
|
134
|
+
design,
|
|
135
|
+
selected,
|
|
136
|
+
changes,
|
|
137
|
+
onChanges,
|
|
138
|
+
cardTitle,
|
|
139
|
+
cardMemo,
|
|
140
|
+
agent,
|
|
141
|
+
readOnly = false,
|
|
142
|
+
onSplit,
|
|
143
|
+
}: BlockPanelProps) {
|
|
144
|
+
const lr = useLrText();
|
|
145
|
+
const askLabels: Record<PageAction, string> = {
|
|
146
|
+
rewrite: lr.board.askRewrite,
|
|
147
|
+
chart: lr.board.askChart,
|
|
148
|
+
memo: lr.board.askMemo,
|
|
149
|
+
expand: lr.board.askExpand,
|
|
150
|
+
};
|
|
151
|
+
const page = selected !== null ? pages[selected] : undefined;
|
|
152
|
+
const pageKey = selected !== null ? (pageKeys[selected] ?? null) : null;
|
|
153
|
+
const [readFor, setReadFor] = useState<{ page: Page; read: PageRead } | null>(null);
|
|
154
|
+
const [hovered, setHovered] = useState<string | null>(null);
|
|
155
|
+
const [checked, setChecked] = useState<ReadonlySet<string>>(() => new Set());
|
|
156
|
+
|
|
157
|
+
const sensors = useSensors(
|
|
158
|
+
useSensor(PointerSensor, { activationConstraint: { distance: 5 } }),
|
|
159
|
+
useSensor(KeyboardSensor, { coordinateGetter: sortableKeyboardCoordinates }),
|
|
160
|
+
);
|
|
161
|
+
|
|
162
|
+
useEffect(() => {
|
|
163
|
+
if (page) setHovered(null);
|
|
164
|
+
}, [page]);
|
|
165
|
+
|
|
166
|
+
useEffect(() => {
|
|
167
|
+
if (page) setChecked(new Set());
|
|
168
|
+
}, [page]);
|
|
169
|
+
|
|
170
|
+
const onRead = useCallback(
|
|
171
|
+
(next: PageRead) => {
|
|
172
|
+
if (page) setReadFor({ page, read: next });
|
|
173
|
+
},
|
|
174
|
+
[page],
|
|
175
|
+
);
|
|
176
|
+
// A read belongs to the page it was taken from; one still arriving from the
|
|
177
|
+
// page clicked a moment ago must not be drawn as this page's blocks.
|
|
178
|
+
const read = readFor && readFor.page === page ? readFor.read : undefined;
|
|
179
|
+
|
|
180
|
+
const original = read && 'blocks' in read ? read.blocks : [];
|
|
181
|
+
const whole = read && 'whole' in read ? read.whole : null;
|
|
182
|
+
const effective = pageKey ? effectiveBlocks(pageKey, original, changes) : [];
|
|
183
|
+
const parked = parkedBlocks(changes);
|
|
184
|
+
|
|
185
|
+
const originOf = useCallback(
|
|
186
|
+
(block: EffectiveBlock): (Spot & { block: string }) | null => {
|
|
187
|
+
if (block.pending && block.from) {
|
|
188
|
+
const found = changes.find(
|
|
189
|
+
(item) => item.origin.page === block.from && item.origin.block === block.id,
|
|
190
|
+
);
|
|
191
|
+
return found ? found.origin : null;
|
|
192
|
+
}
|
|
193
|
+
if (!pageKey) return null;
|
|
194
|
+
const at = original.findIndex((candidate) => candidate.id === block.id);
|
|
195
|
+
if (at < 0) return null;
|
|
196
|
+
return { page: pageKey, before: original[at + 1]?.id ?? null, block: block.id };
|
|
197
|
+
},
|
|
198
|
+
[changes, original, pageKey],
|
|
199
|
+
);
|
|
200
|
+
|
|
201
|
+
const moveTo = useCallback(
|
|
202
|
+
(block: EffectiveBlock, target: Spot) => {
|
|
203
|
+
const origin = originOf(block);
|
|
204
|
+
if (!origin) return;
|
|
205
|
+
const existing = changes.find(
|
|
206
|
+
(item) => item.origin.page === origin.page && item.origin.block === origin.block,
|
|
207
|
+
);
|
|
208
|
+
onChanges(placeBlock(changes, origin, blockInfo(block), target, existing?.code));
|
|
209
|
+
},
|
|
210
|
+
[changes, onChanges, originOf],
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
const park = useCallback(
|
|
214
|
+
async (block: EffectiveBlock) => {
|
|
215
|
+
const origin = originOf(block);
|
|
216
|
+
if (!origin) return;
|
|
217
|
+
if (!block.loc) {
|
|
218
|
+
toast.error(lr.board.parkNeedsSource);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
let code: string | null = null;
|
|
222
|
+
try {
|
|
223
|
+
const res = await fetch('/__board/blocks/source', {
|
|
224
|
+
method: 'POST',
|
|
225
|
+
headers: { 'content-type': 'application/json' },
|
|
226
|
+
body: JSON.stringify({ slideId, loc: block.loc, text: block.text }),
|
|
227
|
+
});
|
|
228
|
+
if (res.ok) code = ((await res.json()) as { code?: string }).code ?? null;
|
|
229
|
+
} catch {
|
|
230
|
+
code = null;
|
|
231
|
+
}
|
|
232
|
+
if (!code) {
|
|
233
|
+
toast.error(lr.board.parkNeedsSource);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
onChanges(placeBlock(changes, origin, blockInfo(block), 'parked', code));
|
|
237
|
+
},
|
|
238
|
+
[changes, lr.board.parkNeedsSource, onChanges, originOf, slideId],
|
|
239
|
+
);
|
|
240
|
+
|
|
241
|
+
const unpark = useCallback(
|
|
242
|
+
(item: Placement, target: Spot) => {
|
|
243
|
+
onChanges(unparkBlock(changes, item, target));
|
|
244
|
+
},
|
|
245
|
+
[changes, onChanges],
|
|
246
|
+
);
|
|
247
|
+
|
|
248
|
+
const toggleChecked = useCallback((id: string) => {
|
|
249
|
+
setChecked((current) => {
|
|
250
|
+
const next = new Set(current);
|
|
251
|
+
if (next.has(id)) next.delete(id);
|
|
252
|
+
else next.add(id);
|
|
253
|
+
return next;
|
|
254
|
+
});
|
|
255
|
+
}, []);
|
|
256
|
+
|
|
257
|
+
// Every block on the page is already a page of its own, and none of them is
|
|
258
|
+
// the page: the split is a part of it.
|
|
259
|
+
const canSplit =
|
|
260
|
+
!readOnly && pageKey !== null && !whole && checked.size > 0 && checked.size < effective.length;
|
|
261
|
+
|
|
262
|
+
const split = useCallback(() => {
|
|
263
|
+
if (!pageKey) return;
|
|
264
|
+
const picked = effective.filter((block) => checked.has(block.id));
|
|
265
|
+
if (picked.length === 0) return;
|
|
266
|
+
onSplit(
|
|
267
|
+
pageKey,
|
|
268
|
+
picked.map((block) => ({ id: block.id, kind: block.kind, text: block.text })),
|
|
269
|
+
);
|
|
270
|
+
setChecked(new Set());
|
|
271
|
+
}, [checked, effective, onSplit, pageKey]);
|
|
272
|
+
|
|
273
|
+
const onDragEnd = useCallback(
|
|
274
|
+
(event: DragEndEvent) => {
|
|
275
|
+
const activeId = String(event.active.id);
|
|
276
|
+
const overId = event.over ? String(event.over.id) : null;
|
|
277
|
+
if (!overId || activeId === overId) return;
|
|
278
|
+
|
|
279
|
+
const fromParking = activeId.startsWith('parked:');
|
|
280
|
+
const toParking = overId.startsWith('parked:');
|
|
281
|
+
if (fromParking && toParking) return;
|
|
282
|
+
|
|
283
|
+
if (!fromParking && toParking) {
|
|
284
|
+
const moving = effective.find((block) => listId(block.id) === activeId);
|
|
285
|
+
if (moving) void park(moving);
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
const overIndex = effective.findIndex((block) => listId(block.id) === overId);
|
|
290
|
+
|
|
291
|
+
if (fromParking) {
|
|
292
|
+
const item = parked.find((placement) => parkedId(placement) === activeId);
|
|
293
|
+
if (!item || !pageKey) return;
|
|
294
|
+
unpark(item, { page: pageKey, before: overIndex >= 0 ? effective[overIndex].id : null });
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
const fromIndex = effective.findIndex((block) => listId(block.id) === activeId);
|
|
299
|
+
const moving = effective[fromIndex];
|
|
300
|
+
if (!moving || overIndex < 0) return;
|
|
301
|
+
const order = arrayMove(effective, fromIndex, overIndex);
|
|
302
|
+
const at = order.findIndex((block) => block.id === moving.id);
|
|
303
|
+
moveTo(moving, { page: pageKey ?? '', before: order[at + 1]?.id ?? null });
|
|
304
|
+
},
|
|
305
|
+
[effective, moveTo, pageKey, park, parked, unpark],
|
|
306
|
+
);
|
|
307
|
+
|
|
308
|
+
const pageOptions = useMemo(
|
|
309
|
+
() =>
|
|
310
|
+
pages.map((_, index) => ({
|
|
311
|
+
key: pageKeys[index] ?? '',
|
|
312
|
+
number: format(lr.board.blockPageOption, { n: index + 1 }),
|
|
313
|
+
title: cardTitle(index),
|
|
314
|
+
})),
|
|
315
|
+
[pages, pageKeys, cardTitle, lr.board.blockPageOption],
|
|
316
|
+
);
|
|
317
|
+
|
|
318
|
+
const hoveredBox = useMemo(() => {
|
|
319
|
+
const block = effective.find((candidate) => candidate.id === hovered);
|
|
320
|
+
return block?.box ?? null;
|
|
321
|
+
}, [effective, hovered]);
|
|
322
|
+
|
|
323
|
+
// A picture or a chart has no words, so its row is named by what it is and
|
|
324
|
+
// which one of them it is on this page.
|
|
325
|
+
const labels = useMemo(() => {
|
|
326
|
+
const counts = new Map<BlockKind, number>();
|
|
327
|
+
const named = new Map<string, string>();
|
|
328
|
+
for (const block of effective) {
|
|
329
|
+
if (block.text) {
|
|
330
|
+
named.set(block.id, block.text);
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
const n = (counts.get(block.kind) ?? 0) + 1;
|
|
334
|
+
counts.set(block.kind, n);
|
|
335
|
+
named.set(
|
|
336
|
+
block.id,
|
|
337
|
+
format(lr.board.blockKindN, { kind: lr.board.blockKinds[block.kind], n }),
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
return named;
|
|
341
|
+
}, [effective, lr.board]);
|
|
342
|
+
|
|
343
|
+
const labelOf = useCallback(
|
|
344
|
+
(block: EffectiveBlock) =>
|
|
345
|
+
labels.get(block.id) ?? block.text ?? lr.board.blockKinds[block.kind],
|
|
346
|
+
[labels, lr.board],
|
|
347
|
+
);
|
|
348
|
+
|
|
349
|
+
const menuFor = (block: EffectiveBlock): ReactNode => (
|
|
350
|
+
<>
|
|
351
|
+
<DropdownMenuSub>
|
|
352
|
+
<DropdownMenuSubTrigger>
|
|
353
|
+
<span className="truncate">{lr.board.moveBlockTo}</span>
|
|
354
|
+
</DropdownMenuSubTrigger>
|
|
355
|
+
<DropdownMenuSubContent className="max-h-[320px] min-w-[190px] overflow-y-auto">
|
|
356
|
+
{pageOptions.map((option) => (
|
|
357
|
+
<DropdownMenuItem
|
|
358
|
+
key={option.key}
|
|
359
|
+
onClick={() => moveTo(block, { page: option.key, before: null })}
|
|
360
|
+
>
|
|
361
|
+
<span className="shrink-0 tabular-nums">{option.number}</span>
|
|
362
|
+
<span className="min-w-0 truncate text-muted-foreground">{option.title}</span>
|
|
363
|
+
</DropdownMenuItem>
|
|
364
|
+
))}
|
|
365
|
+
</DropdownMenuSubContent>
|
|
366
|
+
</DropdownMenuSub>
|
|
367
|
+
<DropdownMenuItem onClick={() => void park(block)}>{lr.board.parkBlock}</DropdownMenuItem>
|
|
368
|
+
</>
|
|
369
|
+
);
|
|
370
|
+
|
|
371
|
+
const parkingMenuFor = (item: Placement): ReactNode => (
|
|
372
|
+
<DropdownMenuSub>
|
|
373
|
+
<DropdownMenuSubTrigger>
|
|
374
|
+
<span className="truncate">{lr.board.unparkBlockTo}</span>
|
|
375
|
+
</DropdownMenuSubTrigger>
|
|
376
|
+
<DropdownMenuSubContent className="max-h-[320px] min-w-[190px] overflow-y-auto">
|
|
377
|
+
{pageOptions.map((option) => (
|
|
378
|
+
<DropdownMenuItem
|
|
379
|
+
key={option.key}
|
|
380
|
+
onClick={() => unpark(item, { page: option.key, before: null })}
|
|
381
|
+
>
|
|
382
|
+
<span className="shrink-0 tabular-nums">{option.number}</span>
|
|
383
|
+
<span className="min-w-0 truncate text-muted-foreground">{option.title}</span>
|
|
384
|
+
</DropdownMenuItem>
|
|
385
|
+
))}
|
|
386
|
+
</DropdownMenuSubContent>
|
|
387
|
+
</DropdownMenuSub>
|
|
388
|
+
);
|
|
389
|
+
|
|
390
|
+
return (
|
|
391
|
+
// Board shortcuts (delete, escape) and React Flow's own delete key stop at
|
|
392
|
+
// the panel: inside it those keys belong to the blocks.
|
|
393
|
+
<aside
|
|
394
|
+
data-lr-block-panel
|
|
395
|
+
style={{ width: PANEL_WIDTH }}
|
|
396
|
+
onKeyDown={(event) => {
|
|
397
|
+
const mod = event.metaKey || event.ctrlKey;
|
|
398
|
+
if (mod && (event.key === 'z' || event.key === 'Z')) return;
|
|
399
|
+
// Arrow and pickup keys have to reach the drag sensor on the document;
|
|
400
|
+
// every other board shortcut ends here.
|
|
401
|
+
if (DRAG_KEYS.has(event.key)) return;
|
|
402
|
+
event.stopPropagation();
|
|
403
|
+
}}
|
|
404
|
+
className="flex shrink-0 flex-col overflow-hidden border-l border-hairline bg-background"
|
|
405
|
+
>
|
|
406
|
+
<div className="shrink-0 border-b border-hairline p-4">
|
|
407
|
+
{page ? (
|
|
408
|
+
<div
|
|
409
|
+
className="relative overflow-hidden rounded-[4px] bg-white ring-1 ring-hairline"
|
|
410
|
+
style={{ width: PREVIEW_WIDTH, height: (PREVIEW_WIDTH * 9) / 16 }}
|
|
411
|
+
>
|
|
412
|
+
<PagePreview
|
|
413
|
+
page={page}
|
|
414
|
+
index={selected ?? 0}
|
|
415
|
+
total={pages.length}
|
|
416
|
+
design={design}
|
|
417
|
+
scale={PREVIEW_SCALE}
|
|
418
|
+
onRead={onRead}
|
|
419
|
+
/>
|
|
420
|
+
{hoveredBox && (
|
|
421
|
+
<div
|
|
422
|
+
className="pointer-events-none absolute rounded-[2px] ring-2 ring-[var(--lr-accent)]"
|
|
423
|
+
style={{
|
|
424
|
+
left: hoveredBox.x * PREVIEW_SCALE,
|
|
425
|
+
top: hoveredBox.y * PREVIEW_SCALE,
|
|
426
|
+
width: hoveredBox.w * PREVIEW_SCALE,
|
|
427
|
+
height: hoveredBox.h * PREVIEW_SCALE,
|
|
428
|
+
}}
|
|
429
|
+
/>
|
|
430
|
+
)}
|
|
431
|
+
</div>
|
|
432
|
+
) : (
|
|
433
|
+
<p className="grid h-[162px] place-items-center px-4 text-center text-[12.5px] text-muted-foreground">
|
|
434
|
+
{lr.board.blockPanelEmpty}
|
|
435
|
+
</p>
|
|
436
|
+
)}
|
|
437
|
+
</div>
|
|
438
|
+
|
|
439
|
+
{page && (
|
|
440
|
+
<div className="shrink-0 border-b border-hairline px-4 py-2">
|
|
441
|
+
<DropdownMenu>
|
|
442
|
+
<DropdownMenuTrigger
|
|
443
|
+
type="button"
|
|
444
|
+
data-lr-ask-agent
|
|
445
|
+
disabled={readOnly}
|
|
446
|
+
className={cn(buttonVariants({ variant: 'outline', size: 'sm' }), 'w-full')}
|
|
447
|
+
>
|
|
448
|
+
<Sparkles />
|
|
449
|
+
{lr.board.askAgent}
|
|
450
|
+
</DropdownMenuTrigger>
|
|
451
|
+
<DropdownMenuContent align="start" className="min-w-[210px]">
|
|
452
|
+
{PAGE_ACTIONS.map((action) => {
|
|
453
|
+
const needsMemo = action === 'memo' && !cardMemo(selected ?? 0).trim();
|
|
454
|
+
const hint = agent.hint ?? (needsMemo ? lr.board.askNeedsMemo : null);
|
|
455
|
+
const Icon = ASK_ICON[action];
|
|
456
|
+
return (
|
|
457
|
+
<DropdownMenuItem
|
|
458
|
+
key={action}
|
|
459
|
+
disabled={readOnly || hint !== null}
|
|
460
|
+
title={hint ?? undefined}
|
|
461
|
+
onClick={() => agent.onTask(action)}
|
|
462
|
+
>
|
|
463
|
+
<Icon />
|
|
464
|
+
{askLabels[action]}
|
|
465
|
+
</DropdownMenuItem>
|
|
466
|
+
);
|
|
467
|
+
})}
|
|
468
|
+
</DropdownMenuContent>
|
|
469
|
+
</DropdownMenu>
|
|
470
|
+
</div>
|
|
471
|
+
)}
|
|
472
|
+
|
|
473
|
+
{canSplit && (
|
|
474
|
+
<div className="shrink-0 border-b border-hairline px-4 py-2">
|
|
475
|
+
<Button
|
|
476
|
+
type="button"
|
|
477
|
+
variant="outline"
|
|
478
|
+
size="sm"
|
|
479
|
+
className="w-full"
|
|
480
|
+
data-lr-split-page
|
|
481
|
+
onClick={split}
|
|
482
|
+
>
|
|
483
|
+
<Scissors />
|
|
484
|
+
{lr.board.splitPage}
|
|
485
|
+
</Button>
|
|
486
|
+
</div>
|
|
487
|
+
)}
|
|
488
|
+
|
|
489
|
+
<DndContext sensors={sensors} collisionDetection={closestCenter} onDragEnd={onDragEnd}>
|
|
490
|
+
<div className="min-h-0 flex-1 overflow-y-auto px-2 py-2">
|
|
491
|
+
{!page ? null : whole ? (
|
|
492
|
+
<p className="px-2 py-3 text-[12.5px] text-muted-foreground">{lr.board.whole[whole]}</p>
|
|
493
|
+
) : !read ? (
|
|
494
|
+
<p className="px-2 py-3 text-[12.5px] text-muted-foreground">{lr.board.loading}</p>
|
|
495
|
+
) : effective.length === 0 ? (
|
|
496
|
+
<p className="px-2 py-3 text-[12.5px] text-muted-foreground">
|
|
497
|
+
{lr.board.blockPanelEmpty}
|
|
498
|
+
</p>
|
|
499
|
+
) : (
|
|
500
|
+
<SortableContext
|
|
501
|
+
items={effective.map((block) => listId(block.id))}
|
|
502
|
+
strategy={verticalListSortingStrategy}
|
|
503
|
+
>
|
|
504
|
+
<ul data-lr-block-list className="flex flex-col gap-0.5">
|
|
505
|
+
{effective.map((block) => (
|
|
506
|
+
<BlockRow
|
|
507
|
+
key={listId(block.id)}
|
|
508
|
+
id={listId(block.id)}
|
|
509
|
+
kind={block.kind}
|
|
510
|
+
label={labelOf(block)}
|
|
511
|
+
readOnly={readOnly}
|
|
512
|
+
checked={checked.has(block.id)}
|
|
513
|
+
onToggle={() => toggleChecked(block.id)}
|
|
514
|
+
pending={block.pending === true && block.from !== pageKey}
|
|
515
|
+
from={
|
|
516
|
+
block.pending && block.from && block.from !== pageKey
|
|
517
|
+
? format(lr.board.blockFrom, {
|
|
518
|
+
n: pageKeys.indexOf(block.from) + 1,
|
|
519
|
+
})
|
|
520
|
+
: undefined
|
|
521
|
+
}
|
|
522
|
+
onHover={() => setHovered(block.id)}
|
|
523
|
+
onHoverEnd={() => setHovered(null)}
|
|
524
|
+
>
|
|
525
|
+
{menuFor(block)}
|
|
526
|
+
</BlockRow>
|
|
527
|
+
))}
|
|
528
|
+
</ul>
|
|
529
|
+
</SortableContext>
|
|
530
|
+
)}
|
|
531
|
+
</div>
|
|
532
|
+
|
|
533
|
+
<div className="shrink-0 border-t border-hairline bg-muted/25 px-2 py-2">
|
|
534
|
+
<p className="px-2 pb-1.5 pt-1 text-[11.5px] font-medium text-muted-foreground">
|
|
535
|
+
{format(lr.board.parking, { n: parked.length })}
|
|
536
|
+
</p>
|
|
537
|
+
{parked.length === 0 ? (
|
|
538
|
+
<p className="px-2 pb-2 text-[12px] text-muted-foreground/70">
|
|
539
|
+
{lr.board.parkingEmpty}
|
|
540
|
+
</p>
|
|
541
|
+
) : (
|
|
542
|
+
<SortableContext
|
|
543
|
+
items={parked.map((item) => parkedId(item))}
|
|
544
|
+
strategy={verticalListSortingStrategy}
|
|
545
|
+
>
|
|
546
|
+
<ul
|
|
547
|
+
data-lr-parking-list
|
|
548
|
+
className="flex max-h-[280px] flex-col gap-0.5 overflow-y-auto"
|
|
549
|
+
>
|
|
550
|
+
{parked.map((item) => (
|
|
551
|
+
<BlockRow
|
|
552
|
+
key={parkedId(item)}
|
|
553
|
+
id={parkedId(item)}
|
|
554
|
+
kind={item.block.kind}
|
|
555
|
+
label={item.block.text || lr.board.blockKinds[item.block.kind]}
|
|
556
|
+
readOnly={readOnly}
|
|
557
|
+
onHover={() => {}}
|
|
558
|
+
onHoverEnd={() => {}}
|
|
559
|
+
>
|
|
560
|
+
{parkingMenuFor(item)}
|
|
561
|
+
</BlockRow>
|
|
562
|
+
))}
|
|
563
|
+
</ul>
|
|
564
|
+
</SortableContext>
|
|
565
|
+
)}
|
|
566
|
+
</div>
|
|
567
|
+
</DndContext>
|
|
568
|
+
</aside>
|
|
569
|
+
);
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
function BlockRow({
|
|
573
|
+
id,
|
|
574
|
+
kind,
|
|
575
|
+
label,
|
|
576
|
+
readOnly,
|
|
577
|
+
checked,
|
|
578
|
+
onToggle,
|
|
579
|
+
pending,
|
|
580
|
+
from,
|
|
581
|
+
onHover,
|
|
582
|
+
onHoverEnd,
|
|
583
|
+
children,
|
|
584
|
+
}: {
|
|
585
|
+
id: string;
|
|
586
|
+
kind: BlockKind;
|
|
587
|
+
label: string;
|
|
588
|
+
readOnly: boolean;
|
|
589
|
+
checked?: boolean;
|
|
590
|
+
/** Present on the blocks of a page: they can be picked to leave it. */
|
|
591
|
+
onToggle?: () => void;
|
|
592
|
+
pending?: boolean;
|
|
593
|
+
from?: string;
|
|
594
|
+
onHover: () => void;
|
|
595
|
+
onHoverEnd: () => void;
|
|
596
|
+
children: ReactNode;
|
|
597
|
+
}) {
|
|
598
|
+
const lr = useLrText();
|
|
599
|
+
const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
|
|
600
|
+
id,
|
|
601
|
+
disabled: readOnly,
|
|
602
|
+
});
|
|
603
|
+
const Icon = KIND_ICON[kind];
|
|
604
|
+
const style = { transform: CSS.Transform.toString(transform), transition };
|
|
605
|
+
|
|
606
|
+
return (
|
|
607
|
+
<li
|
|
608
|
+
ref={setNodeRef}
|
|
609
|
+
style={style}
|
|
610
|
+
data-lr-block-row
|
|
611
|
+
data-lr-block-kind={kind}
|
|
612
|
+
onMouseEnter={onHover}
|
|
613
|
+
onMouseLeave={onHoverEnd}
|
|
614
|
+
className={cn(
|
|
615
|
+
'group/row flex items-center gap-1 rounded-[6px] px-1 py-1 text-[12.5px]',
|
|
616
|
+
'hover:bg-muted/60',
|
|
617
|
+
isDragging && 'bg-card opacity-80 shadow-edge',
|
|
618
|
+
)}
|
|
619
|
+
>
|
|
620
|
+
{onToggle && !readOnly && (
|
|
621
|
+
<input
|
|
622
|
+
type="checkbox"
|
|
623
|
+
checked={checked === true}
|
|
624
|
+
onChange={onToggle}
|
|
625
|
+
aria-label={label}
|
|
626
|
+
className="size-3.5 shrink-0 cursor-pointer accent-[var(--lr-accent)]"
|
|
627
|
+
/>
|
|
628
|
+
)}
|
|
629
|
+
<button
|
|
630
|
+
type="button"
|
|
631
|
+
aria-label={lr.board.blockDrag}
|
|
632
|
+
disabled={readOnly}
|
|
633
|
+
className="cursor-grab rounded p-1 text-muted-foreground/60 outline-none hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40 disabled:pointer-events-none disabled:opacity-40"
|
|
634
|
+
{...attributes}
|
|
635
|
+
{...listeners}
|
|
636
|
+
>
|
|
637
|
+
<GripVertical className="size-3.5" />
|
|
638
|
+
</button>
|
|
639
|
+
<Icon className="size-3.5 shrink-0 text-muted-foreground" strokeWidth={1.8} />
|
|
640
|
+
<span className="min-w-0 flex-1 truncate">{label}</span>
|
|
641
|
+
{pending && (
|
|
642
|
+
<span
|
|
643
|
+
title={from}
|
|
644
|
+
className="flex shrink-0 items-center gap-1 text-[10.5px] text-[var(--lr-accent)]"
|
|
645
|
+
>
|
|
646
|
+
<span className="size-1.5 rounded-full bg-[var(--lr-accent)]" />
|
|
647
|
+
{lr.board.blockPending}
|
|
648
|
+
</span>
|
|
649
|
+
)}
|
|
650
|
+
{!readOnly && (
|
|
651
|
+
<DropdownMenu>
|
|
652
|
+
<DropdownMenuTrigger
|
|
653
|
+
type="button"
|
|
654
|
+
aria-label={lr.board.blockMenu}
|
|
655
|
+
className="rounded p-1 text-muted-foreground/60 opacity-0 outline-none hover:text-foreground focus-visible:opacity-100 focus-visible:ring-2 focus-visible:ring-ring/40 group-hover/row:opacity-100"
|
|
656
|
+
>
|
|
657
|
+
<MoreHorizontal className="size-3.5" />
|
|
658
|
+
</DropdownMenuTrigger>
|
|
659
|
+
<DropdownMenuContent align="end" className="min-w-[190px]">
|
|
660
|
+
{children}
|
|
661
|
+
</DropdownMenuContent>
|
|
662
|
+
</DropdownMenu>
|
|
663
|
+
)}
|
|
664
|
+
</li>
|
|
665
|
+
);
|
|
666
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Block, WholeReason } from './classify.ts';
|
|
2
|
+
|
|
3
|
+
export type PageRead = { blocks: Block[] } | { whole: WholeReason };
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What each page was read to contain. Keyed by the page component itself, so a
|
|
7
|
+
* reloaded deck module starts empty without anything having to clear it.
|
|
8
|
+
*/
|
|
9
|
+
const reads = new WeakMap<object, PageRead>();
|
|
10
|
+
|
|
11
|
+
export function rememberPageRead(page: object, read: PageRead): void {
|
|
12
|
+
reads.set(page, read);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function pageReadOf(page: object): PageRead | undefined {
|
|
16
|
+
return reads.get(page);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Whether two reads describe the same blocks, regardless of their boxes. */
|
|
20
|
+
export function sameRead(a: PageRead | undefined, b: PageRead): boolean {
|
|
21
|
+
if (!a) return false;
|
|
22
|
+
if ('whole' in a || 'whole' in b) return 'whole' in a && 'whole' in b && a.whole === b.whole;
|
|
23
|
+
if (a.blocks.length !== b.blocks.length) return false;
|
|
24
|
+
return a.blocks.every((block, index) => {
|
|
25
|
+
const other = b.blocks[index];
|
|
26
|
+
return block.id === other.id && block.kind === other.kind && block.text === other.text;
|
|
27
|
+
});
|
|
28
|
+
}
|