@open-document/core 0.6.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{build-BvIHtePO.js → build-CFL7nhz0.js} +1 -1
- package/dist/{check-BqEdVH7G.js → check-pEQh4jJE.js} +3 -3
- package/dist/cli/bin.js +6 -6
- package/dist/{config-B7vFf9qZ.js → config-4nz5NnxW.js} +593 -137
- package/dist/{context-BaUE_aqU.js → context-BH8C-dSW.js} +1 -1
- package/dist/{dev-DXG-Dg-y.js → dev-BCSUczXW.js} +1 -1
- package/dist/{export-CT1Axnjv.js → export-BQ-GvMsb.js} +3 -3
- package/dist/{import-C8ZC4R6T.js → import-Daat3L2J.js} +2 -2
- package/dist/index.d.ts +21 -3
- package/dist/index.js +40 -9
- package/dist/ops/index.d.ts +47 -3
- package/dist/ops/index.js +3 -3
- package/dist/{ops-ByclxTfk.js → ops-DQfckiyp.js} +2 -45
- package/dist/{preview-CdmWbaHy.js → preview-CwCrw-i3.js} +1 -1
- package/dist/vite/index.js +1 -1
- package/package.json +1 -1
- package/src/app/components/data-table.tsx +17 -2
- package/src/app/components/design-panel/design-panel.tsx +149 -274
- package/src/app/components/design-panel/design-provider.tsx +35 -15
- package/src/app/components/footnote.tsx +27 -10
- package/src/app/components/history-provider.tsx +125 -0
- package/src/app/components/inspector/inspector.tsx +1149 -208
- package/src/app/components/numbering.tsx +13 -1
- package/src/app/components/panel/edit-save-card.tsx +112 -0
- package/src/app/components/panel/fields.tsx +247 -0
- package/src/app/components/panel/panel-shell.tsx +71 -0
- package/src/app/components/panel/save-card.tsx +146 -0
- package/src/app/lib/footnotes.ts +6 -3
- package/src/app/lib/href.ts +14 -0
- package/src/app/lib/inspector/inline-edit.test.ts +244 -0
- package/src/app/lib/inspector/inline-edit.ts +770 -0
- package/src/app/lib/source-loc.ts +15 -0
- package/src/app/lib/view-mode.test.ts +46 -0
- package/src/app/lib/view-mode.ts +76 -0
- package/src/app/routes/doc.tsx +206 -48
- package/src/app/styles.css +41 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In dev, `loc-tags-plugin` stamps `data-od-loc` onto the call site of a
|
|
3
|
+
* framework component that forwards it. The component puts it back on the
|
|
4
|
+
* host that prints the call site's words, so the inspector can select what it
|
|
5
|
+
* rendered — a table, a caption, a footnote — and find the source behind it.
|
|
6
|
+
* `data-od-prop` says which attribute of the call site those words come from.
|
|
7
|
+
*/
|
|
8
|
+
export const LOC_PROP = 'data-od-loc';
|
|
9
|
+
export const PROP_ATTR = 'data-od-prop';
|
|
10
|
+
|
|
11
|
+
/** The attributes pointing a host back at its call site; nothing outside dev. */
|
|
12
|
+
export function sourceAttrs(loc: string | undefined, prop?: string): Record<string, string> {
|
|
13
|
+
if (!loc) return {};
|
|
14
|
+
return prop ? { [LOC_PROP]: loc, [PROP_ATTR]: prop } : { [LOC_PROP]: loc };
|
|
15
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { fitWidthScale, pageAtMarker, sheetsAcross } from './view-mode.ts';
|
|
3
|
+
|
|
4
|
+
describe('fitWidthScale', () => {
|
|
5
|
+
it('fits one sheet, a spread, or a row of three into the width', () => {
|
|
6
|
+
expect(sheetsAcross('continuous')).toBe(1);
|
|
7
|
+
for (const mode of ['continuous', 'spread', 'grid'] as const) {
|
|
8
|
+
const scale = fitWidthScale(mode, 960, 794, 24);
|
|
9
|
+
const across = sheetsAcross(mode);
|
|
10
|
+
// The row the viewer lays out — scaled sheets plus fixed gaps — fills it exactly.
|
|
11
|
+
expect(across * 794 * scale + (across - 1) * 24).toBeCloseTo(960);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
describe('pageAtMarker', () => {
|
|
17
|
+
it('follows a single column', () => {
|
|
18
|
+
expect(pageAtMarker([0, 1100, 2200], 1500)).toBe(2);
|
|
19
|
+
expect(pageAtMarker([0, 1100, 2200], 10)).toBe(1);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('reports the left page of the spread in view', () => {
|
|
23
|
+
// Page 1 alone on the right, then 2–3, 4–5.
|
|
24
|
+
const tops = [0, 1100, 1100, 2200, 2200];
|
|
25
|
+
expect(pageAtMarker(tops, 1500)).toBe(2);
|
|
26
|
+
expect(pageAtMarker(tops, 2300)).toBe(4);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('reports the first sheet of the grid row in view', () => {
|
|
30
|
+
const tops = [0, 0, 0, 300, 300, 300, 600];
|
|
31
|
+
expect(pageAtMarker(tops, 450)).toBe(4);
|
|
32
|
+
expect(pageAtMarker(tops, 650)).toBe(7);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('keeps a page just jumped to while its row is in view', () => {
|
|
36
|
+
const tops = [0, 1100, 1100, 2200, 2200];
|
|
37
|
+
expect(pageAtMarker(tops, 1500, 3)).toBe(3);
|
|
38
|
+
// Scrolled on to the next spread: the jump no longer describes the view.
|
|
39
|
+
expect(pageAtMarker(tops, 2300, 3)).toBe(4);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('falls back to the first page before anything has passed the marker', () => {
|
|
43
|
+
expect(pageAtMarker([200, 1300], 100)).toBe(1);
|
|
44
|
+
expect(pageAtMarker([], 100)).toBe(1);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the viewer lays the sheets out. Every mode keeps all pages in the one
|
|
3
|
+
* scroll container, so the page counter, page jump, the outline, find and the
|
|
4
|
+
* inspector overlay work the same in each — there is no single-sheet mode,
|
|
5
|
+
* which would need its own navigation path through all of them.
|
|
6
|
+
*/
|
|
7
|
+
export const VIEW_MODES = ['continuous', 'spread', 'grid'] as const;
|
|
8
|
+
export type ViewMode = (typeof VIEW_MODES)[number];
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* How many sheets side by side the zoom fits to. Fit width in two-up fits the
|
|
12
|
+
* spread, not one of its pages; in grid it fits a row of three, which is what
|
|
13
|
+
* keeps a chapter readable at a glance rather than a strip of postage stamps.
|
|
14
|
+
*/
|
|
15
|
+
export function sheetsAcross(mode: ViewMode): number {
|
|
16
|
+
return mode === 'continuous' ? 1 : mode === 'spread' ? 2 : 3;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The scale at which the mode's row of sheets exactly fills `width`. The gaps
|
|
21
|
+
* between sheets are fixed pixels, not scaled with the pages, so they come off
|
|
22
|
+
* the width before the sheets share what is left — counting them as page width
|
|
23
|
+
* would leave the row a little too wide, and a grid of three would wrap to two.
|
|
24
|
+
*/
|
|
25
|
+
export function fitWidthScale(
|
|
26
|
+
mode: ViewMode,
|
|
27
|
+
width: number,
|
|
28
|
+
pageWidth: number,
|
|
29
|
+
gap: number,
|
|
30
|
+
): number {
|
|
31
|
+
const across = sheetsAcross(mode);
|
|
32
|
+
return Math.max(0, width - (across - 1) * gap) / (across * pageWidth);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The page the reader is on: the first sheet of the lowest row whose top has
|
|
37
|
+
* passed the marker. In two-up that is the left page of the spread in view —
|
|
38
|
+
* the one a reader starts on — not the right one that shares its row.
|
|
39
|
+
*
|
|
40
|
+
* `prefer` is a page the reader just asked for. Jumping to page 3 in two-up
|
|
41
|
+
* brings the 2–3 spread into view, and reporting 2 would read as the jump
|
|
42
|
+
* having missed; while that page is in the row in view, it is the answer.
|
|
43
|
+
*/
|
|
44
|
+
export function pageAtMarker(tops: number[], marker: number, prefer?: number | null): number {
|
|
45
|
+
let rowTop = Number.NEGATIVE_INFINITY;
|
|
46
|
+
tops.forEach((top) => {
|
|
47
|
+
if (top <= marker && top > rowTop) rowTop = top;
|
|
48
|
+
});
|
|
49
|
+
const index = tops.indexOf(rowTop);
|
|
50
|
+
if (index < 0) return 1;
|
|
51
|
+
if (prefer && tops[prefer - 1] === rowTop) return prefer;
|
|
52
|
+
return index + 1;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const key = (docId: string) => `open-doc:view:${docId}`;
|
|
56
|
+
|
|
57
|
+
/** The mode last used for this document, so coming back resumes the same reading. */
|
|
58
|
+
export function readViewMode(docId: string | undefined): ViewMode {
|
|
59
|
+
if (!docId) return 'continuous';
|
|
60
|
+
try {
|
|
61
|
+
const stored = localStorage.getItem(key(docId));
|
|
62
|
+
return (VIEW_MODES as readonly string[]).includes(stored ?? '')
|
|
63
|
+
? (stored as ViewMode)
|
|
64
|
+
: 'continuous';
|
|
65
|
+
} catch {
|
|
66
|
+
return 'continuous';
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export function writeViewMode(docId: string | undefined, mode: ViewMode): void {
|
|
71
|
+
if (!docId) return;
|
|
72
|
+
try {
|
|
73
|
+
if (mode === 'continuous') localStorage.removeItem(key(docId));
|
|
74
|
+
else localStorage.setItem(key(docId), mode);
|
|
75
|
+
} catch {}
|
|
76
|
+
}
|
package/src/app/routes/doc.tsx
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
import appConfig from 'virtual:open-doc/config';
|
|
2
2
|
import {
|
|
3
3
|
ArrowLeft,
|
|
4
|
+
BookOpen,
|
|
4
5
|
Check,
|
|
5
6
|
Download,
|
|
7
|
+
Eye,
|
|
6
8
|
FileCode2,
|
|
7
9
|
FileImage,
|
|
8
10
|
FileText,
|
|
9
11
|
Image,
|
|
12
|
+
LayoutGrid,
|
|
10
13
|
Loader2,
|
|
11
14
|
Maximize,
|
|
12
15
|
Minimize,
|
|
13
16
|
Minus,
|
|
14
|
-
MousePointerClick,
|
|
15
17
|
MoveHorizontal,
|
|
16
18
|
MoveVertical,
|
|
17
19
|
Palette,
|
|
20
|
+
Pencil,
|
|
18
21
|
Percent,
|
|
19
22
|
Plus,
|
|
23
|
+
Rows3,
|
|
20
24
|
} from 'lucide-react';
|
|
21
25
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
22
26
|
import { Link, useParams } from 'react-router-dom';
|
|
@@ -24,8 +28,10 @@ import { DesignPanel } from '../components/design-panel/design-panel';
|
|
|
24
28
|
import { DesignProvider } from '../components/design-panel/design-provider';
|
|
25
29
|
import { DocSearch } from '../components/doc-search';
|
|
26
30
|
import { DocSidebar } from '../components/doc-sidebar';
|
|
27
|
-
import {
|
|
31
|
+
import { HistoryProvider } from '../components/history-provider';
|
|
32
|
+
import { Inspector, type InspectorControls } from '../components/inspector/inspector';
|
|
28
33
|
import { PageFrame } from '../components/page-frame';
|
|
34
|
+
import { EditSaveCard } from '../components/panel/edit-save-card';
|
|
29
35
|
import { ThemeToggle } from '../components/theme-toggle';
|
|
30
36
|
import { Menu, MenuItem } from '../components/ui/menu';
|
|
31
37
|
import { useAgentBridge } from '../lib/agent-bridge';
|
|
@@ -40,6 +46,13 @@ import { resolvePageGeometry } from '../lib/sdk';
|
|
|
40
46
|
import { useDocModule } from '../lib/use-doc-module';
|
|
41
47
|
import { useDocPages } from '../lib/use-doc-pages';
|
|
42
48
|
import { cn } from '../lib/utils';
|
|
49
|
+
import {
|
|
50
|
+
fitWidthScale as fitScale,
|
|
51
|
+
pageAtMarker,
|
|
52
|
+
readViewMode,
|
|
53
|
+
type ViewMode,
|
|
54
|
+
writeViewMode,
|
|
55
|
+
} from '../lib/view-mode';
|
|
43
56
|
|
|
44
57
|
type DownloadFormat = 'pdf' | 'html' | 'png' | 'svg';
|
|
45
58
|
|
|
@@ -92,6 +105,17 @@ const HeaderBackLink = () => {
|
|
|
92
105
|
);
|
|
93
106
|
};
|
|
94
107
|
|
|
108
|
+
const EDITING_KEY = 'open-doc:editing';
|
|
109
|
+
|
|
110
|
+
function readEditing(): boolean {
|
|
111
|
+
if (!import.meta.env.DEV) return false;
|
|
112
|
+
try {
|
|
113
|
+
return sessionStorage.getItem(EDITING_KEY) === '1';
|
|
114
|
+
} catch {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
95
119
|
export function Doc() {
|
|
96
120
|
const { docId } = useParams<{ docId: string }>();
|
|
97
121
|
const state = useDocModule(docId);
|
|
@@ -111,8 +135,26 @@ export function Doc() {
|
|
|
111
135
|
const [selection, setSelection] = useState<PageSelection>({ kind: 'all' });
|
|
112
136
|
const [customRange, setCustomRange] = useState('');
|
|
113
137
|
const [designOpen, setDesignOpen] = useState(false);
|
|
114
|
-
const [
|
|
138
|
+
const [editing, setEditingState] = useState(readEditing);
|
|
139
|
+
// The dev server reloads every open viewer when a document is added or
|
|
140
|
+
// removed anywhere in the workspace. Edit mode is per tab and survives that.
|
|
141
|
+
const setEditing = useCallback((next: boolean) => {
|
|
142
|
+
setEditingState(next);
|
|
143
|
+
try {
|
|
144
|
+
if (next) sessionStorage.setItem(EDITING_KEY, '1');
|
|
145
|
+
else sessionStorage.removeItem(EDITING_KEY);
|
|
146
|
+
} catch {}
|
|
147
|
+
}, []);
|
|
148
|
+
const leaveEditRef = useRef<(() => void) | null>(null);
|
|
149
|
+
const editControlsRef = useRef<InspectorControls | null>(null);
|
|
150
|
+
const [textPending, setTextPending] = useState(0);
|
|
151
|
+
const [cardShown, setCardShown] = useState(false);
|
|
115
152
|
const [isFullscreen, setIsFullscreen] = useState(false);
|
|
153
|
+
const [viewMode, setViewModeState] = useState<ViewMode>(() => readViewMode(docId));
|
|
154
|
+
// The page the reader was on when the layout changed, to put back in view.
|
|
155
|
+
const keepPageRef = useRef<number | null>(null);
|
|
156
|
+
// The page last jumped to, reported while it shares the row in view.
|
|
157
|
+
const jumpedRef = useRef<number | null>(null);
|
|
116
158
|
|
|
117
159
|
const geometry = useMemo(() => resolvePageGeometry(doc?.meta), [doc?.meta]);
|
|
118
160
|
const { pages, measuring, overflowing } = useDocPages(doc, geometry);
|
|
@@ -121,10 +163,13 @@ export function Doc() {
|
|
|
121
163
|
useAgentBridge({ docId: docId ?? '', doc, pages, geometry, measuring, oversized: overflowing });
|
|
122
164
|
|
|
123
165
|
const clamp = (value: number) => Math.max(MIN_SCALE, Math.min(MAX_SCALE, value));
|
|
124
|
-
|
|
125
|
-
//
|
|
166
|
+
// Every fit is of the unit the mode lays side by side — a sheet, a spread,
|
|
167
|
+
// a row of the grid — so zoom and view mode compose instead of fighting.
|
|
168
|
+
const widthFit = fitScale(viewMode, available.width, geometry.width, PAGE_GAP);
|
|
169
|
+
const fitWidthScale = available.width ? clamp(widthFit) : 1;
|
|
170
|
+
// Fit page is bounded by both axes so the whole unit lands inside the pane.
|
|
126
171
|
const fitPageScale = available.height
|
|
127
|
-
? clamp(Math.min(
|
|
172
|
+
? clamp(Math.min(widthFit, available.height / geometry.height))
|
|
128
173
|
: 1;
|
|
129
174
|
// Auto keeps a page at its true size unless the window is too narrow to hold
|
|
130
175
|
// it; the explicit fit modes may go past 100%.
|
|
@@ -184,11 +229,13 @@ export function Doc() {
|
|
|
184
229
|
frame = 0;
|
|
185
230
|
const marker = root.scrollTop + root.clientHeight / 3;
|
|
186
231
|
const frames = Array.from(container.children) as HTMLElement[];
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
232
|
+
setCurrentPage(
|
|
233
|
+
pageAtMarker(
|
|
234
|
+
frames.map((el) => el.offsetTop),
|
|
235
|
+
marker,
|
|
236
|
+
jumpedRef.current,
|
|
237
|
+
),
|
|
238
|
+
);
|
|
192
239
|
};
|
|
193
240
|
const onScroll = () => {
|
|
194
241
|
if (frame) return;
|
|
@@ -201,9 +248,35 @@ export function Doc() {
|
|
|
201
248
|
root.removeEventListener('scroll', onScroll);
|
|
202
249
|
if (frame) cancelAnimationFrame(frame);
|
|
203
250
|
};
|
|
204
|
-
}, [pages.length, scale]);
|
|
251
|
+
}, [pages.length, scale, viewMode]);
|
|
252
|
+
|
|
253
|
+
useEffect(() => setViewModeState(readViewMode(docId)), [docId]);
|
|
254
|
+
|
|
255
|
+
const setViewMode = (mode: ViewMode) => {
|
|
256
|
+
if (mode === viewMode) return;
|
|
257
|
+
keepPageRef.current = currentPage;
|
|
258
|
+
setViewModeState(mode);
|
|
259
|
+
writeViewMode(docId, mode);
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
// Changing the layout moves every sheet. Without this the reader lands on
|
|
263
|
+
// whatever page now sits where their scroll position happens to be.
|
|
264
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: runs once per layout change, after the sheets have moved.
|
|
265
|
+
useLayoutEffect(() => {
|
|
266
|
+
const page = keepPageRef.current;
|
|
267
|
+
keepPageRef.current = null;
|
|
268
|
+
const root = scrollRef.current;
|
|
269
|
+
const frame = pagesRef.current?.children[page === null ? -1 : page - 1] as
|
|
270
|
+
| HTMLElement
|
|
271
|
+
| undefined;
|
|
272
|
+
if (!root || !frame) return;
|
|
273
|
+
// Keep the gutter above the sheet, as a fresh document opens with, rather
|
|
274
|
+
// than butting its top edge against the toolbar.
|
|
275
|
+
root.scrollTop = Math.max(0, frame.offsetTop - GUTTER);
|
|
276
|
+
}, [viewMode]);
|
|
205
277
|
|
|
206
278
|
const scrollToPage = useCallback((page: number) => {
|
|
279
|
+
jumpedRef.current = page;
|
|
207
280
|
const frame = pagesRef.current?.children[page - 1];
|
|
208
281
|
frame?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
|
209
282
|
}, []);
|
|
@@ -322,6 +395,9 @@ export function Doc() {
|
|
|
322
395
|
if (e.key === 'f' || e.key === 'F') {
|
|
323
396
|
e.preventDefault();
|
|
324
397
|
toggleFullscreen();
|
|
398
|
+
} else if (import.meta.env.DEV && (e.key === 'd' || e.key === 'D')) {
|
|
399
|
+
e.preventDefault();
|
|
400
|
+
setDesignOpen((open) => !open);
|
|
325
401
|
}
|
|
326
402
|
};
|
|
327
403
|
window.addEventListener('keydown', onKeyDown);
|
|
@@ -405,6 +481,31 @@ export function Doc() {
|
|
|
405
481
|
</IconButton>
|
|
406
482
|
</div>
|
|
407
483
|
|
|
484
|
+
<fieldset className="flex items-center gap-0.5 rounded-md border border-border px-1 py-0.5">
|
|
485
|
+
<legend className="sr-only">Page layout</legend>
|
|
486
|
+
<IconButton
|
|
487
|
+
label="Continuous"
|
|
488
|
+
active={viewMode === 'continuous'}
|
|
489
|
+
onClick={() => setViewMode('continuous')}
|
|
490
|
+
>
|
|
491
|
+
<Rows3 className="size-3.5" />
|
|
492
|
+
</IconButton>
|
|
493
|
+
<IconButton
|
|
494
|
+
label="Two-up"
|
|
495
|
+
active={viewMode === 'spread'}
|
|
496
|
+
onClick={() => setViewMode('spread')}
|
|
497
|
+
>
|
|
498
|
+
<BookOpen className="size-3.5" />
|
|
499
|
+
</IconButton>
|
|
500
|
+
<IconButton
|
|
501
|
+
label="Grid"
|
|
502
|
+
active={viewMode === 'grid'}
|
|
503
|
+
onClick={() => setViewMode('grid')}
|
|
504
|
+
>
|
|
505
|
+
<LayoutGrid className="size-3.5" />
|
|
506
|
+
</IconButton>
|
|
507
|
+
</fieldset>
|
|
508
|
+
|
|
408
509
|
<IconButton
|
|
409
510
|
label={isFullscreen ? 'Exit fullscreen (F)' : 'Fullscreen (F)'}
|
|
410
511
|
onClick={toggleFullscreen}
|
|
@@ -418,22 +519,29 @@ export function Doc() {
|
|
|
418
519
|
{!appConfig.build.showDocBrowser && <ThemeToggle />}
|
|
419
520
|
|
|
420
521
|
{import.meta.env.DEV && (
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
522
|
+
// Same two modes as open-slide: reading the document, or editing it
|
|
523
|
+
// where it is printed. Leaving edit mode saves unsaved text first.
|
|
524
|
+
<fieldset className="flex items-center gap-0.5 rounded-md border border-border px-1 py-0.5">
|
|
525
|
+
<legend className="sr-only">Mode</legend>
|
|
526
|
+
<IconButton
|
|
527
|
+
label="Preview"
|
|
528
|
+
active={!editing}
|
|
529
|
+
onClick={() => (leaveEditRef.current ? leaveEditRef.current() : setEditing(false))}
|
|
530
|
+
>
|
|
531
|
+
<Eye className="size-3.5" />
|
|
532
|
+
</IconButton>
|
|
533
|
+
<IconButton label="Edit" active={editing} onClick={() => setEditing(true)}>
|
|
534
|
+
<Pencil className="size-3.5" />
|
|
535
|
+
</IconButton>
|
|
536
|
+
</fieldset>
|
|
433
537
|
)}
|
|
434
538
|
{import.meta.env.DEV && (
|
|
435
539
|
<button
|
|
436
540
|
type="button"
|
|
541
|
+
aria-pressed={designOpen}
|
|
542
|
+
aria-label="Design"
|
|
543
|
+
aria-keyshortcuts="D"
|
|
544
|
+
title="Design tokens (D)"
|
|
437
545
|
onClick={() => setDesignOpen((open) => !open)}
|
|
438
546
|
className={cn(
|
|
439
547
|
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
@@ -442,6 +550,12 @@ export function Doc() {
|
|
|
442
550
|
>
|
|
443
551
|
<Palette className="size-3.5" />
|
|
444
552
|
Design
|
|
553
|
+
<kbd
|
|
554
|
+
aria-hidden
|
|
555
|
+
className="hidden rounded-sm bg-foreground/10 px-1 font-mono text-[9.5px] text-muted-foreground md:inline"
|
|
556
|
+
>
|
|
557
|
+
D
|
|
558
|
+
</kbd>
|
|
445
559
|
</button>
|
|
446
560
|
)}
|
|
447
561
|
<Menu
|
|
@@ -512,32 +626,71 @@ export function Doc() {
|
|
|
512
626
|
onSelectPage={scrollToPage}
|
|
513
627
|
onSelectEntry={scrollToEntry}
|
|
514
628
|
/>
|
|
515
|
-
<div
|
|
516
|
-
ref={scrollRef}
|
|
517
|
-
data-od-viewer
|
|
518
|
-
className="relative min-w-0 flex-1 overflow-auto bg-canvas"
|
|
519
|
-
>
|
|
629
|
+
<div className="relative flex min-w-0 flex-1">
|
|
520
630
|
<div
|
|
521
|
-
ref={
|
|
522
|
-
|
|
523
|
-
|
|
631
|
+
ref={scrollRef}
|
|
632
|
+
data-od-viewer
|
|
633
|
+
className="relative min-w-0 flex-1 overflow-auto bg-canvas"
|
|
524
634
|
>
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
635
|
+
<div
|
|
636
|
+
ref={pagesRef}
|
|
637
|
+
data-od-view={viewMode}
|
|
638
|
+
className={cn(
|
|
639
|
+
viewMode === 'continuous' && 'flex flex-col items-center',
|
|
640
|
+
// Facing pages as a bound document is read: page 1 alone on
|
|
641
|
+
// the right, then 2–3, 4–5.
|
|
642
|
+
viewMode === 'spread' && 'grid justify-center [&>:first-child]:col-start-2',
|
|
643
|
+
// A contact sheet: columns that line up, the last row starting
|
|
644
|
+
// under the first sheet rather than centred in the gap.
|
|
645
|
+
viewMode === 'grid' && 'grid content-start justify-center',
|
|
646
|
+
)}
|
|
647
|
+
style={{
|
|
648
|
+
gap: PAGE_GAP,
|
|
649
|
+
padding: `${GUTTER}px ${GUTTER}px ${GUTTER * 1.5}px`,
|
|
650
|
+
...(viewMode === 'spread'
|
|
651
|
+
? { gridTemplateColumns: `repeat(2, ${geometry.width * scale}px)` }
|
|
652
|
+
: viewMode === 'grid'
|
|
653
|
+
? { gridTemplateColumns: `repeat(auto-fill, ${geometry.width * scale}px)` }
|
|
654
|
+
: {}),
|
|
655
|
+
}}
|
|
656
|
+
>
|
|
657
|
+
{pages.map((page, index) => (
|
|
658
|
+
<PageFrame
|
|
659
|
+
key={page.key}
|
|
660
|
+
index={index}
|
|
661
|
+
total={pages.length}
|
|
662
|
+
geometry={geometry}
|
|
663
|
+
scale={scale}
|
|
664
|
+
design={doc.design}
|
|
665
|
+
>
|
|
666
|
+
{page.content}
|
|
667
|
+
</PageFrame>
|
|
668
|
+
))}
|
|
669
|
+
</div>
|
|
537
670
|
</div>
|
|
671
|
+
{import.meta.env.DEV && docId && (
|
|
672
|
+
<EditSaveCard
|
|
673
|
+
textCount={textPending}
|
|
674
|
+
controlsRef={editControlsRef}
|
|
675
|
+
onShownChange={setCardShown}
|
|
676
|
+
/>
|
|
677
|
+
)}
|
|
538
678
|
</div>
|
|
539
|
-
{
|
|
540
|
-
|
|
679
|
+
{editing && docId && (
|
|
680
|
+
// Keyed by document: a selection, or an editor carried across a
|
|
681
|
+
// reload by source location, must never follow into another
|
|
682
|
+
// document where the same line:column is something else entirely.
|
|
683
|
+
<Inspector
|
|
684
|
+
key={docId}
|
|
685
|
+
docId={docId}
|
|
686
|
+
containerRef={scrollRef}
|
|
687
|
+
panelHidden={designOpen}
|
|
688
|
+
quiet={cardShown}
|
|
689
|
+
onExit={() => setEditing(false)}
|
|
690
|
+
exitRef={leaveEditRef}
|
|
691
|
+
controlsRef={editControlsRef}
|
|
692
|
+
onPendingChange={setTextPending}
|
|
693
|
+
/>
|
|
541
694
|
)}
|
|
542
695
|
{designOpen && <DesignPanel onClose={() => setDesignOpen(false)} />}
|
|
543
696
|
</div>
|
|
@@ -545,9 +698,14 @@ export function Doc() {
|
|
|
545
698
|
);
|
|
546
699
|
|
|
547
700
|
// The design panel writes back to source through the dev server, so it only
|
|
548
|
-
// exists while `open-doc dev` is running.
|
|
701
|
+
// exists while `open-doc dev` is running. The history is per document: an
|
|
702
|
+
// undo step from one must never replay onto another.
|
|
549
703
|
if (!import.meta.env.DEV || !docId) return view;
|
|
550
|
-
return
|
|
704
|
+
return (
|
|
705
|
+
<HistoryProvider key={docId}>
|
|
706
|
+
<DesignProvider docId={docId}>{view}</DesignProvider>
|
|
707
|
+
</HistoryProvider>
|
|
708
|
+
);
|
|
551
709
|
}
|
|
552
710
|
|
|
553
711
|
/**
|
package/src/app/styles.css
CHANGED
|
@@ -46,10 +46,51 @@
|
|
|
46
46
|
--border: oklch(0.28 0 0);
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
/* The dock's content arrives from the edge it docks against. Opacity only
|
|
50
|
+
when motion is reduced; never the width, which would reflow the pages. */
|
|
51
|
+
@keyframes od-panel-in {
|
|
52
|
+
from {
|
|
53
|
+
opacity: 0;
|
|
54
|
+
transform: translateX(8px);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
@keyframes od-fade-in {
|
|
58
|
+
from {
|
|
59
|
+
opacity: 0;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
@keyframes od-card-in {
|
|
63
|
+
from {
|
|
64
|
+
opacity: 0;
|
|
65
|
+
translate: 0 6px;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
.od-panel-in {
|
|
69
|
+
animation: od-panel-in 150ms ease-out;
|
|
70
|
+
}
|
|
71
|
+
/* The save card rises from the edge it sits on; `translate` rather than
|
|
72
|
+
`transform`, which already centres it. */
|
|
73
|
+
.od-card-in {
|
|
74
|
+
animation: od-card-in 150ms ease-out;
|
|
75
|
+
}
|
|
76
|
+
@media (prefers-reduced-motion: reduce) {
|
|
77
|
+
.od-panel-in,
|
|
78
|
+
.od-card-in {
|
|
79
|
+
animation-name: od-fade-in;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
49
83
|
@layer base {
|
|
50
84
|
* {
|
|
51
85
|
border-color: var(--border);
|
|
52
86
|
}
|
|
87
|
+
/* The sheet is paper in both themes. Left alone, a selection on it takes the
|
|
88
|
+
dark theme's highlight — a muddy slate on white — so it takes the
|
|
89
|
+
inspector's blue instead, the colour of the frame around the text. */
|
|
90
|
+
[data-od-page] ::selection {
|
|
91
|
+
background-color: rgb(59 130 246 / 0.3);
|
|
92
|
+
color: inherit;
|
|
93
|
+
}
|
|
53
94
|
/* A heading's space-above is what separates it from the section before it —
|
|
54
95
|
but at the top of a page that space is just a dent. Strip it there so the
|
|
55
96
|
first block of every flow page starts flush with the margin. */
|