@open-document/core 0.9.1 → 0.10.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-B0GJXy8I.js → build-DJMLK50m.js} +1 -1
- package/dist/{check-CuDIWsPT.js → check-CUKuufBm.js} +3 -3
- package/dist/cli/bin.js +10 -6
- package/dist/{config-CAZ7Z_va.js → config-CvzpyAUA.js} +558 -546
- package/dist/{context-PWAh9qbf.js → context-B4ip7SoI.js} +1 -1
- package/dist/{dev-CYqppXDI.js → dev-dnH7DTlD.js} +1 -1
- package/dist/{diagram-CCaUUnRe.js → diagram-BK4jTZr4.js} +146 -146
- package/dist/diff-QTo0A5Rx.js +44 -0
- package/dist/{export-1JtO2OMC.js → export-BrRFrexj.js} +3 -3
- package/dist/{import-CsrdBOZ8.js → import-C14Vn9ER.js} +2 -2
- package/dist/index.d.ts +53 -2
- package/dist/index.js +457 -18
- package/dist/ops/index.d.ts +72 -17
- package/dist/ops/index.js +3 -3
- package/dist/{ops-B2y9BMpk.js → ops-DKidjLXP.js} +642 -124
- package/dist/{preview-DW3PM-JV.js → preview-wKM4C6Uk.js} +1 -1
- package/dist/{sdk-BqU6mwD_.d.ts → sdk-CpDEGRIo.d.ts} +2 -0
- package/dist/vite/index.js +1 -1
- package/package.json +2 -2
- package/skills/doc-authoring/SKILL.md +9 -4
- package/skills/doc-authoring/references/pagination.md +1 -1
- package/skills/doc-authoring/references/tables-and-charts.md +18 -1
- package/src/app/components/browser/browser-ui.tsx +105 -0
- package/src/app/components/chart.tsx +239 -0
- package/src/app/components/command-palette.tsx +284 -0
- package/src/app/components/design-panel/design-panel.tsx +22 -20
- package/src/app/components/design-panel/design-provider.tsx +4 -2
- package/src/app/components/diagram.tsx +11 -1
- package/src/app/components/doc-assets.tsx +6 -5
- package/src/app/components/doc-search.tsx +12 -10
- package/src/app/components/doc-sidebar.tsx +24 -18
- package/src/app/components/flow-page.tsx +2 -0
- package/src/app/components/inspector/inspector.tsx +75 -48
- package/src/app/components/language-toggle.tsx +38 -0
- package/src/app/components/palette-items.ts +128 -0
- package/src/app/components/panel/edit-save-card.tsx +4 -2
- package/src/app/components/panel/fields.tsx +5 -2
- package/src/app/components/panel/save-card.tsx +18 -10
- package/src/app/components/sidebar/folder-item.tsx +10 -8
- package/src/app/components/sidebar/icon-picker.tsx +3 -1
- package/src/app/components/sidebar/sidebar.tsx +44 -13
- package/src/app/components/theme-toggle.tsx +5 -3
- package/src/app/components/ui/menu.tsx +5 -0
- package/src/app/lib/agent-bridge.ts +8 -2
- package/src/app/lib/chart.test.ts +108 -0
- package/src/app/lib/chart.ts +343 -0
- package/src/app/lib/doc-preview.tsx +0 -10
- package/src/app/lib/docs.ts +3 -0
- package/src/app/lib/docx/from-dom.ts +11 -11
- package/src/app/lib/docx/ooxml.test.ts +25 -9
- package/src/app/lib/docx/ooxml.ts +58 -37
- package/src/app/lib/export-docx.ts +13 -8
- package/src/app/lib/flow.ts +1 -1
- package/src/app/lib/i18n-ja/browser.ts +88 -0
- package/src/app/lib/i18n-ja/doc.ts +65 -0
- package/src/app/lib/i18n-ja/index.ts +5 -0
- package/src/app/lib/i18n-ja/panels.ts +104 -0
- package/src/app/lib/i18n-ko/browser.ts +87 -0
- package/src/app/lib/i18n-ko/doc.ts +65 -0
- package/src/app/lib/i18n-ko/index.ts +5 -0
- package/src/app/lib/i18n-ko/panels.ts +102 -0
- package/src/app/lib/i18n-zh-cn/browser.ts +84 -0
- package/src/app/lib/i18n-zh-cn/doc.ts +64 -0
- package/src/app/lib/i18n-zh-cn/index.ts +5 -0
- package/src/app/lib/i18n-zh-cn/panels.ts +98 -0
- package/src/app/lib/i18n-zh-tw/browser.ts +84 -0
- package/src/app/lib/i18n-zh-tw/doc.ts +64 -0
- package/src/app/lib/i18n-zh-tw/index.ts +5 -0
- package/src/app/lib/i18n-zh-tw/panels.ts +99 -0
- package/src/app/lib/i18n.test.ts +24 -0
- package/src/app/lib/i18n.tsx +109 -0
- package/src/app/lib/outline.ts +23 -0
- package/src/app/lib/page-range.test.ts +10 -1
- package/src/app/lib/page-range.ts +26 -0
- package/src/app/lib/sdk.ts +2 -0
- package/src/app/main.tsx +4 -1
- package/src/app/routes/assets.tsx +193 -132
- package/src/app/routes/doc.tsx +666 -310
- package/src/app/routes/home-shell.tsx +115 -88
- package/src/app/routes/home.tsx +200 -67
- package/src/app/routes/themes.tsx +42 -35
- package/src/app/styles.css +84 -5
- package/src/app/virtual.d.ts +1 -0
package/src/app/routes/doc.tsx
CHANGED
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import appConfig from 'virtual:open-doc/config';
|
|
2
2
|
import {
|
|
3
|
+
ArrowDownToLine,
|
|
3
4
|
ArrowLeft,
|
|
4
5
|
BookOpen,
|
|
5
6
|
Check,
|
|
7
|
+
ChevronDown,
|
|
6
8
|
Download,
|
|
7
9
|
Eye,
|
|
8
10
|
FileCode2,
|
|
9
11
|
FileImage,
|
|
10
12
|
FileText,
|
|
11
13
|
FileType2,
|
|
14
|
+
Hash,
|
|
12
15
|
Image,
|
|
13
16
|
LayoutGrid,
|
|
17
|
+
Link2,
|
|
14
18
|
Loader2,
|
|
15
19
|
Maximize,
|
|
16
20
|
Minimize,
|
|
@@ -19,12 +23,13 @@ import {
|
|
|
19
23
|
MoveVertical,
|
|
20
24
|
Palette,
|
|
21
25
|
Pencil,
|
|
22
|
-
Percent,
|
|
23
26
|
Plus,
|
|
24
27
|
Rows3,
|
|
25
28
|
} from 'lucide-react';
|
|
29
|
+
import { useTheme } from 'next-themes';
|
|
26
30
|
import { useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
27
|
-
import { Link, useParams } from 'react-router-dom';
|
|
31
|
+
import { Link, useNavigate, useParams } from 'react-router-dom';
|
|
32
|
+
import { CommandPaletteProvider, type PaletteItem } from '../components/command-palette';
|
|
28
33
|
import { DesignPanel } from '../components/design-panel/design-panel';
|
|
29
34
|
import { DesignProvider } from '../components/design-panel/design-provider';
|
|
30
35
|
import { DocSearch } from '../components/doc-search';
|
|
@@ -32,6 +37,7 @@ import { DocSidebar } from '../components/doc-sidebar';
|
|
|
32
37
|
import { HistoryProvider } from '../components/history-provider';
|
|
33
38
|
import { Inspector, type InspectorControls } from '../components/inspector/inspector';
|
|
34
39
|
import { PageFrame } from '../components/page-frame';
|
|
40
|
+
import { browserItems } from '../components/palette-items';
|
|
35
41
|
import { EditSaveCard } from '../components/panel/edit-save-card';
|
|
36
42
|
import { ThemeToggle } from '../components/theme-toggle';
|
|
37
43
|
import { Menu, MenuItem } from '../components/ui/menu';
|
|
@@ -40,8 +46,14 @@ import { exportDocAsDocx } from '../lib/export-docx';
|
|
|
40
46
|
import { exportDocAsHtml } from '../lib/export-html';
|
|
41
47
|
import { exportDocAsImages } from '../lib/export-image';
|
|
42
48
|
import { exportDocAsPdf } from '../lib/export-pdf';
|
|
49
|
+
import { useLocale, useT } from '../lib/i18n';
|
|
43
50
|
import { type OutlineEntry, useDocOutline } from '../lib/outline';
|
|
44
|
-
import {
|
|
51
|
+
import {
|
|
52
|
+
describeSelection,
|
|
53
|
+
formatPages,
|
|
54
|
+
type PageSelection,
|
|
55
|
+
resolveSelection,
|
|
56
|
+
} from '../lib/page-range';
|
|
45
57
|
import { nextFrame, waitForFonts } from '../lib/print-ready';
|
|
46
58
|
import { scanDocument } from '../lib/scan';
|
|
47
59
|
import { resolvePageGeometry } from '../lib/sdk';
|
|
@@ -66,16 +78,61 @@ const DOWNLOAD_LABEL: Record<DownloadFormat, string> = {
|
|
|
66
78
|
docx: 'Word',
|
|
67
79
|
};
|
|
68
80
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
81
|
+
/**
|
|
82
|
+
* Grouped by what the file is for rather than listed by type: the reader is
|
|
83
|
+
* choosing between "send it", "edit it" and "drop it in a slide", and the
|
|
84
|
+
* extension on the right says what lands in their downloads folder.
|
|
85
|
+
*/
|
|
86
|
+
const DOWNLOAD_GROUPS = [
|
|
87
|
+
{
|
|
88
|
+
label: 'Print & share',
|
|
89
|
+
formats: [
|
|
90
|
+
{
|
|
91
|
+
format: 'pdf' as const,
|
|
92
|
+
label: 'PDF',
|
|
93
|
+
hint: 'True page size, print-ready',
|
|
94
|
+
ext: '.pdf',
|
|
95
|
+
icon: FileText,
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
format: 'html' as const,
|
|
99
|
+
label: 'HTML',
|
|
100
|
+
hint: 'One self-contained file',
|
|
101
|
+
ext: '.html',
|
|
102
|
+
icon: FileCode2,
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
label: 'Edit',
|
|
108
|
+
formats: [
|
|
109
|
+
{
|
|
110
|
+
format: 'docx' as const,
|
|
111
|
+
label: 'Word',
|
|
112
|
+
hint: 'Editable; Word lays out the pages',
|
|
113
|
+
ext: '.docx',
|
|
114
|
+
icon: FileType2,
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
},
|
|
74
118
|
{
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
119
|
+
label: 'Images',
|
|
120
|
+
formats: [
|
|
121
|
+
{
|
|
122
|
+
format: 'png' as const,
|
|
123
|
+
label: 'PNG',
|
|
124
|
+
hint: 'Pixels at 2×, for slides and chat',
|
|
125
|
+
ext: '.png',
|
|
126
|
+
icon: Image,
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
format: 'svg' as const,
|
|
130
|
+
label: 'SVG',
|
|
131
|
+
hint: 'Vector, text stays text',
|
|
132
|
+
ext: '.svg',
|
|
133
|
+
icon: FileImage,
|
|
134
|
+
},
|
|
135
|
+
],
|
|
79
136
|
},
|
|
80
137
|
];
|
|
81
138
|
|
|
@@ -99,16 +156,17 @@ const BACK_CLASS =
|
|
|
99
156
|
* host that mounts the viewer this way is providing its own way back.
|
|
100
157
|
*/
|
|
101
158
|
const HeaderBackLink = () => {
|
|
159
|
+
const t = useT();
|
|
102
160
|
if (appConfig.home !== undefined) {
|
|
103
161
|
return (
|
|
104
|
-
<a href={appConfig.home} className={BACK_CLASS} aria-label=
|
|
162
|
+
<a href={appConfig.home} className={BACK_CLASS} aria-label={t('Back to workspace')}>
|
|
105
163
|
<ArrowLeft className="size-4" />
|
|
106
164
|
</a>
|
|
107
165
|
);
|
|
108
166
|
}
|
|
109
167
|
if (!appConfig.build.showDocBrowser) return null;
|
|
110
168
|
return (
|
|
111
|
-
<Link to="/" className={BACK_CLASS} aria-label=
|
|
169
|
+
<Link to="/" className={BACK_CLASS} aria-label={t('Back to documents')}>
|
|
112
170
|
<ArrowLeft className="size-4" />
|
|
113
171
|
</Link>
|
|
114
172
|
);
|
|
@@ -129,6 +187,8 @@ export function Doc() {
|
|
|
129
187
|
const { docId } = useParams<{ docId: string }>();
|
|
130
188
|
const state = useDocModule(docId);
|
|
131
189
|
const doc = state.doc;
|
|
190
|
+
const t = useT();
|
|
191
|
+
const { setLocale } = useLocale();
|
|
132
192
|
|
|
133
193
|
const rootRef = useRef<HTMLDivElement>(null);
|
|
134
194
|
const scrollRef = useRef<HTMLDivElement>(null);
|
|
@@ -366,9 +426,9 @@ export function Doc() {
|
|
|
366
426
|
setZoomMode(mode);
|
|
367
427
|
};
|
|
368
428
|
|
|
369
|
-
const
|
|
429
|
+
const setZoom = (value: number) => {
|
|
370
430
|
setZoomMode('auto');
|
|
371
|
-
setManualScale(
|
|
431
|
+
setManualScale(Math.min(MAX_SCALE, Math.max(MIN_SCALE, Number(value.toFixed(2)))));
|
|
372
432
|
};
|
|
373
433
|
|
|
374
434
|
const toggleFullscreen = useCallback(() => {
|
|
@@ -379,6 +439,114 @@ export function Doc() {
|
|
|
379
439
|
void rootRef.current?.requestFullscreen?.().catch(() => {});
|
|
380
440
|
}, []);
|
|
381
441
|
|
|
442
|
+
const navigate = useNavigate();
|
|
443
|
+
const { setTheme } = useTheme();
|
|
444
|
+
const paletteItems = (query: string): PaletteItem[] => {
|
|
445
|
+
const items: PaletteItem[] = [];
|
|
446
|
+
const wanted = Number(query.replace(/^(p|page)\.?\s*/i, ''));
|
|
447
|
+
if (Number.isInteger(wanted) && wanted >= 1 && wanted <= pages.length) {
|
|
448
|
+
items.push({
|
|
449
|
+
id: 'page',
|
|
450
|
+
group: t('This document'),
|
|
451
|
+
label: t('Go to page {page}', { page: wanted }),
|
|
452
|
+
keywords: query,
|
|
453
|
+
pinned: true,
|
|
454
|
+
icon: ArrowDownToLine,
|
|
455
|
+
run: () => scrollToPage(wanted),
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
for (const entry of outline) {
|
|
459
|
+
items.push({
|
|
460
|
+
id: `section:${entry.id}`,
|
|
461
|
+
group: t('Sections'),
|
|
462
|
+
label: entry.text,
|
|
463
|
+
hint: t('p. {page}', { page: entry.page }),
|
|
464
|
+
icon: Hash,
|
|
465
|
+
run: () => scrollToEntry(entry),
|
|
466
|
+
});
|
|
467
|
+
}
|
|
468
|
+
for (const group of DOWNLOAD_GROUPS) {
|
|
469
|
+
for (const { format, label, icon } of group.formats) {
|
|
470
|
+
items.push({
|
|
471
|
+
id: `download:${format}`,
|
|
472
|
+
group: t('Actions'),
|
|
473
|
+
label: t('Download as {format}', { format: t(label) }),
|
|
474
|
+
keywords: `export ${format}`,
|
|
475
|
+
icon,
|
|
476
|
+
run: () => void runDownload(format),
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
items.push(
|
|
481
|
+
{
|
|
482
|
+
id: 'layout:continuous',
|
|
483
|
+
group: t('Actions'),
|
|
484
|
+
label: t('Continuous layout'),
|
|
485
|
+
keywords: 'view pages',
|
|
486
|
+
icon: Rows3,
|
|
487
|
+
run: () => setViewMode('continuous'),
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
id: 'layout:spread',
|
|
491
|
+
group: t('Actions'),
|
|
492
|
+
label: t('Two-up layout'),
|
|
493
|
+
keywords: 'view spread pages',
|
|
494
|
+
icon: BookOpen,
|
|
495
|
+
run: () => setViewMode('spread'),
|
|
496
|
+
},
|
|
497
|
+
{
|
|
498
|
+
id: 'layout:grid',
|
|
499
|
+
group: t('Actions'),
|
|
500
|
+
label: t('Grid layout'),
|
|
501
|
+
keywords: 'view overview pages',
|
|
502
|
+
icon: LayoutGrid,
|
|
503
|
+
run: () => setViewMode('grid'),
|
|
504
|
+
},
|
|
505
|
+
{
|
|
506
|
+
id: 'fullscreen',
|
|
507
|
+
group: t('Actions'),
|
|
508
|
+
label: t('Fullscreen'),
|
|
509
|
+
hint: 'F',
|
|
510
|
+
icon: Maximize,
|
|
511
|
+
run: toggleFullscreen,
|
|
512
|
+
},
|
|
513
|
+
);
|
|
514
|
+
if (import.meta.env.DEV) {
|
|
515
|
+
items.push(
|
|
516
|
+
editing
|
|
517
|
+
? {
|
|
518
|
+
id: 'mode:preview',
|
|
519
|
+
group: t('Actions'),
|
|
520
|
+
label: t('Leave edit mode'),
|
|
521
|
+
keywords: 'preview read',
|
|
522
|
+
icon: Eye,
|
|
523
|
+
run: () => (leaveEditRef.current ? leaveEditRef.current() : setEditing(false)),
|
|
524
|
+
}
|
|
525
|
+
: {
|
|
526
|
+
id: 'mode:edit',
|
|
527
|
+
group: t('Actions'),
|
|
528
|
+
label: t('Edit on the page'),
|
|
529
|
+
keywords: 'edit mode text',
|
|
530
|
+
icon: Pencil,
|
|
531
|
+
run: () => setEditing(true),
|
|
532
|
+
},
|
|
533
|
+
{
|
|
534
|
+
id: 'design',
|
|
535
|
+
group: t('Actions'),
|
|
536
|
+
label: designOpen ? t('Close the design panel') : t('Open the design panel'),
|
|
537
|
+
hint: 'D',
|
|
538
|
+
keywords: 'design colours fonts',
|
|
539
|
+
icon: Palette,
|
|
540
|
+
run: () => setDesignOpen((open) => !open),
|
|
541
|
+
},
|
|
542
|
+
);
|
|
543
|
+
}
|
|
544
|
+
return [
|
|
545
|
+
...items,
|
|
546
|
+
...browserItems({ navigate, manifest: null, setTheme, setLocale, exclude: docId, t }),
|
|
547
|
+
];
|
|
548
|
+
};
|
|
549
|
+
|
|
382
550
|
useEffect(() => {
|
|
383
551
|
const onChange = () => setIsFullscreen(Boolean(document.fullscreenElement));
|
|
384
552
|
document.addEventListener('fullscreenchange', onChange);
|
|
@@ -418,7 +586,7 @@ export function Doc() {
|
|
|
418
586
|
if (state.status === 'error') {
|
|
419
587
|
return (
|
|
420
588
|
<Centered>
|
|
421
|
-
<p className="font-medium text-sm">Could not load “{docId}
|
|
589
|
+
<p className="font-medium text-sm">{t('Could not load “{id}”.', { id: docId ?? '' })}</p>
|
|
422
590
|
<p className="mt-1 text-muted-foreground text-xs">{state.error.message}</p>
|
|
423
591
|
<BackLink />
|
|
424
592
|
</Centered>
|
|
@@ -434,278 +602,273 @@ export function Doc() {
|
|
|
434
602
|
}
|
|
435
603
|
|
|
436
604
|
const view = (
|
|
437
|
-
<
|
|
438
|
-
{
|
|
605
|
+
<CommandPaletteProvider
|
|
606
|
+
items={paletteItems}
|
|
607
|
+
placeholder={t('Search sections, pages, actions and documents')}
|
|
608
|
+
>
|
|
609
|
+
<div ref={rootRef} className="flex h-screen flex-col bg-background text-foreground">
|
|
610
|
+
{/* Equal `1fr` rails put the title at the true centre of the bar rather
|
|
439
611
|
than the centre of what is left over, which is where a flex row would
|
|
440
612
|
drop it — the control cluster is many times wider than the back link.
|
|
441
613
|
The control rail keeps its automatic minimum — no `min-w-0` — so when
|
|
442
614
|
it outgrows its share the title truncates and slides instead of being
|
|
443
615
|
overlapped by it. */}
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
<
|
|
616
|
+
{/* Three rails by job: where you are (back, title), how you are looking
|
|
617
|
+
(page, zoom, layout, fullscreen), and what you do to the document
|
|
618
|
+
(search, edit, design, download). The middle rail is `auto` between
|
|
619
|
+
two equal `1fr` rails, so it sits at the true centre of the bar while
|
|
620
|
+
the title truncates before anything is overlapped. */}
|
|
621
|
+
<header className="grid h-12 flex-none grid-cols-[1fr_auto_1fr] items-center gap-3 border-b border-border px-3">
|
|
622
|
+
<div className="flex min-w-0 items-center gap-1">
|
|
623
|
+
<HeaderBackLink />
|
|
624
|
+
<h1 className="truncate font-medium text-sm">{doc.meta?.title ?? docId}</h1>
|
|
625
|
+
</div>
|
|
450
626
|
|
|
451
|
-
|
|
452
|
-
<span className="hidden items-center gap-1.5 sm:flex">
|
|
627
|
+
<div className="hidden items-center gap-2 sm:flex">
|
|
453
628
|
<PageJump page={currentPage} total={pages.length} onJump={scrollToPage} />
|
|
454
|
-
<
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
629
|
+
<Divider />
|
|
630
|
+
<ZoomControl
|
|
631
|
+
scale={scale}
|
|
632
|
+
fit={manualScale === null ? zoomMode : null}
|
|
633
|
+
onStep={zoom}
|
|
634
|
+
onSet={setZoom}
|
|
635
|
+
onFit={fitTo}
|
|
636
|
+
/>
|
|
637
|
+
<Divider />
|
|
638
|
+
<fieldset className="flex items-center gap-0.5">
|
|
639
|
+
<legend className="sr-only">{t('Page layout')}</legend>
|
|
640
|
+
<IconButton
|
|
641
|
+
label={t('Continuous')}
|
|
642
|
+
active={viewMode === 'continuous'}
|
|
643
|
+
onClick={() => setViewMode('continuous')}
|
|
644
|
+
>
|
|
645
|
+
<Rows3 className="size-3.5" />
|
|
646
|
+
</IconButton>
|
|
647
|
+
<IconButton
|
|
648
|
+
label={t('Two-up')}
|
|
649
|
+
active={viewMode === 'spread'}
|
|
650
|
+
onClick={() => setViewMode('spread')}
|
|
651
|
+
>
|
|
652
|
+
<BookOpen className="size-3.5" />
|
|
653
|
+
</IconButton>
|
|
654
|
+
<IconButton
|
|
655
|
+
label={t('Grid')}
|
|
656
|
+
active={viewMode === 'grid'}
|
|
657
|
+
onClick={() => setViewMode('grid')}
|
|
658
|
+
>
|
|
659
|
+
<LayoutGrid className="size-3.5" />
|
|
660
|
+
</IconButton>
|
|
661
|
+
</fieldset>
|
|
483
662
|
<IconButton
|
|
484
|
-
label=
|
|
485
|
-
onClick={
|
|
486
|
-
active={manualScale === null && zoomMode === 'fit-page'}
|
|
663
|
+
label={isFullscreen ? t('Exit fullscreen (F)') : t('Fullscreen (F)')}
|
|
664
|
+
onClick={toggleFullscreen}
|
|
487
665
|
>
|
|
488
|
-
<
|
|
489
|
-
</IconButton>
|
|
490
|
-
<IconButton label="Actual size (100%)" onClick={actualSize}>
|
|
491
|
-
<Percent className="size-3.5" />
|
|
666
|
+
{isFullscreen ? <Minimize className="size-3.5" /> : <Maximize className="size-3.5" />}
|
|
492
667
|
</IconButton>
|
|
493
668
|
</div>
|
|
494
669
|
|
|
495
|
-
<
|
|
496
|
-
<
|
|
497
|
-
<IconButton
|
|
498
|
-
label="Continuous"
|
|
499
|
-
active={viewMode === 'continuous'}
|
|
500
|
-
onClick={() => setViewMode('continuous')}
|
|
501
|
-
>
|
|
502
|
-
<Rows3 className="size-3.5" />
|
|
503
|
-
</IconButton>
|
|
504
|
-
<IconButton
|
|
505
|
-
label="Two-up"
|
|
506
|
-
active={viewMode === 'spread'}
|
|
507
|
-
onClick={() => setViewMode('spread')}
|
|
508
|
-
>
|
|
509
|
-
<BookOpen className="size-3.5" />
|
|
510
|
-
</IconButton>
|
|
511
|
-
<IconButton
|
|
512
|
-
label="Grid"
|
|
513
|
-
active={viewMode === 'grid'}
|
|
514
|
-
onClick={() => setViewMode('grid')}
|
|
515
|
-
>
|
|
516
|
-
<LayoutGrid className="size-3.5" />
|
|
517
|
-
</IconButton>
|
|
518
|
-
</fieldset>
|
|
670
|
+
<div className="flex items-center justify-end gap-2">
|
|
671
|
+
<DocSearch scrollRef={scrollRef} pagesRef={pagesRef} onFoundPage={setCurrentPage} />
|
|
519
672
|
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
673
|
+
{import.meta.env.DEV && (
|
|
674
|
+
// Same two modes as open-slide: reading the document, or editing it
|
|
675
|
+
// where it is printed. Leaving edit mode saves unsaved text first.
|
|
676
|
+
<fieldset className="flex items-center gap-0.5 rounded-md border border-border px-1 py-0.5">
|
|
677
|
+
<legend className="sr-only">{t('Mode')}</legend>
|
|
678
|
+
<IconButton
|
|
679
|
+
label={t('Preview')}
|
|
680
|
+
active={!editing}
|
|
681
|
+
onClick={() =>
|
|
682
|
+
leaveEditRef.current ? leaveEditRef.current() : setEditing(false)
|
|
683
|
+
}
|
|
684
|
+
>
|
|
685
|
+
<Eye className="size-3.5" />
|
|
686
|
+
</IconButton>
|
|
687
|
+
<IconButton label={t('Edit')} active={editing} onClick={() => setEditing(true)}>
|
|
688
|
+
<Pencil className="size-3.5" />
|
|
689
|
+
</IconButton>
|
|
690
|
+
</fieldset>
|
|
691
|
+
)}
|
|
692
|
+
{import.meta.env.DEV && (
|
|
693
|
+
<button
|
|
694
|
+
type="button"
|
|
695
|
+
aria-pressed={designOpen}
|
|
696
|
+
aria-label={t('Design')}
|
|
697
|
+
aria-keyshortcuts="D"
|
|
698
|
+
title={t('Design tokens (D)')}
|
|
699
|
+
onClick={() => setDesignOpen((open) => !open)}
|
|
700
|
+
className={cn(
|
|
701
|
+
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
702
|
+
designOpen && 'bg-accent',
|
|
703
|
+
)}
|
|
704
|
+
>
|
|
705
|
+
<Palette className="size-3.5" />
|
|
706
|
+
{t('Design')}
|
|
707
|
+
<kbd
|
|
708
|
+
aria-hidden
|
|
709
|
+
className="hidden rounded-sm bg-foreground/10 px-1 font-mono text-[9.5px] text-muted-foreground md:inline"
|
|
710
|
+
>
|
|
711
|
+
D
|
|
712
|
+
</kbd>
|
|
713
|
+
</button>
|
|
714
|
+
)}
|
|
526
715
|
|
|
527
|
-
|
|
716
|
+
<CopyLink />
|
|
717
|
+
|
|
718
|
+
{/* The document browser normally carries this. A viewer mounted with
|
|
528
719
|
`showDocBrowser: false` never shows that shell, and without it a
|
|
529
720
|
reader has no way to change the theme at all. */}
|
|
530
|
-
|
|
721
|
+
{!appConfig.build.showDocBrowser && <ThemeToggle />}
|
|
531
722
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
aria-pressed={designOpen}
|
|
553
|
-
aria-label="Design"
|
|
554
|
-
aria-keyshortcuts="D"
|
|
555
|
-
title="Design tokens (D)"
|
|
556
|
-
onClick={() => setDesignOpen((open) => !open)}
|
|
557
|
-
className={cn(
|
|
558
|
-
'flex items-center gap-1.5 rounded-md border border-border px-2.5 py-1.5 text-xs transition-colors hover:bg-accent',
|
|
559
|
-
designOpen && 'bg-accent',
|
|
723
|
+
<Menu
|
|
724
|
+
className="w-[300px] p-1.5"
|
|
725
|
+
trigger={(props) => (
|
|
726
|
+
<button
|
|
727
|
+
type="button"
|
|
728
|
+
disabled={download !== null}
|
|
729
|
+
className="flex items-center gap-1.5 rounded-md bg-primary px-2.5 py-1.5 text-primary-foreground text-xs transition-opacity hover:opacity-90 disabled:opacity-70 aria-expanded:opacity-90"
|
|
730
|
+
{...props}
|
|
731
|
+
>
|
|
732
|
+
{download ? (
|
|
733
|
+
<Loader2 className="size-3.5 animate-spin" />
|
|
734
|
+
) : downloaded ? (
|
|
735
|
+
<Check className="size-3.5" />
|
|
736
|
+
) : (
|
|
737
|
+
<Download className="size-3.5" />
|
|
738
|
+
)}
|
|
739
|
+
{download
|
|
740
|
+
? `${t(DOWNLOAD_LABEL[download.format])} ${Math.round(download.percent)}%`
|
|
741
|
+
: t('Download')}
|
|
742
|
+
</button>
|
|
560
743
|
)}
|
|
561
744
|
>
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
aria-hidden
|
|
566
|
-
className="hidden rounded-sm bg-foreground/10 px-1 font-mono text-[9.5px] text-muted-foreground md:inline"
|
|
567
|
-
>
|
|
568
|
-
D
|
|
569
|
-
</kbd>
|
|
570
|
-
</button>
|
|
571
|
-
)}
|
|
572
|
-
<Menu
|
|
573
|
-
trigger={(props) => (
|
|
574
|
-
<button
|
|
575
|
-
type="button"
|
|
576
|
-
disabled={download !== null}
|
|
577
|
-
className="flex items-center gap-1.5 rounded-md bg-primary px-2.5 py-1.5 text-primary-foreground text-xs transition-opacity hover:opacity-90 disabled:opacity-70 aria-expanded:opacity-90"
|
|
578
|
-
{...props}
|
|
579
|
-
>
|
|
580
|
-
{download ? (
|
|
581
|
-
<Loader2 className="size-3.5 animate-spin" />
|
|
582
|
-
) : downloaded ? (
|
|
583
|
-
<Check className="size-3.5" />
|
|
584
|
-
) : (
|
|
585
|
-
<Download className="size-3.5" />
|
|
586
|
-
)}
|
|
587
|
-
{download
|
|
588
|
-
? `${DOWNLOAD_LABEL[download.format]} ${Math.round(download.percent)}%`
|
|
589
|
-
: 'Download'}
|
|
590
|
-
</button>
|
|
591
|
-
)}
|
|
592
|
-
>
|
|
593
|
-
{(close) => (
|
|
594
|
-
<>
|
|
595
|
-
{/* Which pages, before which format. A reader who picks PDF and
|
|
745
|
+
{(close) => (
|
|
746
|
+
<>
|
|
747
|
+
{/* Which pages, before which format. A reader who picks PDF and
|
|
596
748
|
then discovers they exported forty pages has already waited
|
|
597
749
|
for all forty. */}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
design={doc.design}
|
|
634
|
-
currentPage={currentPage}
|
|
635
|
-
entries={outline}
|
|
636
|
-
activeId={activeOutlineId}
|
|
637
|
-
onSelectPage={scrollToPage}
|
|
638
|
-
onSelectEntry={scrollToEntry}
|
|
639
|
-
/>
|
|
640
|
-
<div className="relative flex min-w-0 flex-1">
|
|
641
|
-
<div
|
|
642
|
-
ref={scrollRef}
|
|
643
|
-
data-od-viewer
|
|
644
|
-
className="relative min-w-0 flex-1 overflow-auto bg-canvas"
|
|
645
|
-
>
|
|
646
|
-
<div
|
|
647
|
-
ref={pagesRef}
|
|
648
|
-
data-od-view={viewMode}
|
|
649
|
-
className={cn(
|
|
650
|
-
viewMode === 'continuous' && 'flex flex-col items-center',
|
|
651
|
-
// Facing pages as a bound document is read: page 1 alone on
|
|
652
|
-
// the right, then 2–3, 4–5.
|
|
653
|
-
viewMode === 'spread' && 'grid justify-center [&>:first-child]:col-start-2',
|
|
654
|
-
// A contact sheet: columns that line up, the last row starting
|
|
655
|
-
// under the first sheet rather than centred in the gap.
|
|
656
|
-
viewMode === 'grid' && 'grid content-start justify-center',
|
|
750
|
+
<PageChoice
|
|
751
|
+
selection={selection}
|
|
752
|
+
custom={customRange}
|
|
753
|
+
currentPage={currentPage}
|
|
754
|
+
total={pages.length}
|
|
755
|
+
onSelection={setSelection}
|
|
756
|
+
onCustom={setCustomRange}
|
|
757
|
+
/>
|
|
758
|
+
{DOWNLOAD_GROUPS.map((group) => (
|
|
759
|
+
<fieldset key={group.label}>
|
|
760
|
+
<legend className={MENU_LABEL}>{t(group.label)}</legend>
|
|
761
|
+
{group.formats.map(({ format, label, hint, ext, icon: Icon }) => (
|
|
762
|
+
<MenuItem
|
|
763
|
+
key={format}
|
|
764
|
+
disabled={!chosenPages.valid}
|
|
765
|
+
onClick={() => {
|
|
766
|
+
close();
|
|
767
|
+
void runDownload(format);
|
|
768
|
+
}}
|
|
769
|
+
>
|
|
770
|
+
<Icon className="size-4 flex-none text-muted-foreground" />
|
|
771
|
+
<span className="min-w-0 flex-1">
|
|
772
|
+
<span className="block font-medium">{t(label)}</span>
|
|
773
|
+
<span className="block truncate text-[10.5px] text-muted-foreground">
|
|
774
|
+
{t(hint)}
|
|
775
|
+
</span>
|
|
776
|
+
</span>
|
|
777
|
+
<span className="flex-none font-mono text-[10px] text-muted-foreground">
|
|
778
|
+
{ext}
|
|
779
|
+
</span>
|
|
780
|
+
</MenuItem>
|
|
781
|
+
))}
|
|
782
|
+
</fieldset>
|
|
783
|
+
))}
|
|
784
|
+
</>
|
|
657
785
|
)}
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
786
|
+
</Menu>
|
|
787
|
+
</div>
|
|
788
|
+
</header>
|
|
789
|
+
|
|
790
|
+
<div className="flex min-h-0 flex-1">
|
|
791
|
+
<DocSidebar
|
|
792
|
+
docId={docId ?? ''}
|
|
793
|
+
pages={pages}
|
|
794
|
+
geometry={geometry}
|
|
795
|
+
design={doc.design}
|
|
796
|
+
currentPage={currentPage}
|
|
797
|
+
entries={outline}
|
|
798
|
+
activeId={activeOutlineId}
|
|
799
|
+
onSelectPage={scrollToPage}
|
|
800
|
+
onSelectEntry={scrollToEntry}
|
|
801
|
+
/>
|
|
802
|
+
<div className="relative flex min-w-0 flex-1">
|
|
803
|
+
<div
|
|
804
|
+
ref={scrollRef}
|
|
805
|
+
data-od-viewer
|
|
806
|
+
className="relative min-w-0 flex-1 overflow-auto bg-canvas md:my-2 md:mr-2 md:rounded-xl md:border md:border-border"
|
|
667
807
|
>
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
808
|
+
<div
|
|
809
|
+
ref={pagesRef}
|
|
810
|
+
data-od-view={viewMode}
|
|
811
|
+
className={cn(
|
|
812
|
+
viewMode === 'continuous' && 'flex flex-col items-center',
|
|
813
|
+
// Facing pages as a bound document is read: page 1 alone on
|
|
814
|
+
// the right, then 2–3, 4–5.
|
|
815
|
+
viewMode === 'spread' && 'grid justify-center [&>:first-child]:col-start-2',
|
|
816
|
+
// A contact sheet: columns that line up, the last row starting
|
|
817
|
+
// under the first sheet rather than centred in the gap.
|
|
818
|
+
viewMode === 'grid' && 'grid content-start justify-center',
|
|
819
|
+
)}
|
|
820
|
+
style={{
|
|
821
|
+
gap: PAGE_GAP,
|
|
822
|
+
padding: `${GUTTER}px ${GUTTER}px ${GUTTER * 1.5}px`,
|
|
823
|
+
...(viewMode === 'spread'
|
|
824
|
+
? { gridTemplateColumns: `repeat(2, ${geometry.width * scale}px)` }
|
|
825
|
+
: viewMode === 'grid'
|
|
826
|
+
? { gridTemplateColumns: `repeat(auto-fill, ${geometry.width * scale}px)` }
|
|
827
|
+
: {}),
|
|
828
|
+
}}
|
|
829
|
+
>
|
|
830
|
+
{pages.map((page, index) => (
|
|
831
|
+
<PageFrame
|
|
832
|
+
key={page.key}
|
|
833
|
+
index={index}
|
|
834
|
+
total={pages.length}
|
|
835
|
+
geometry={geometry}
|
|
836
|
+
scale={scale}
|
|
837
|
+
design={doc.design}
|
|
838
|
+
>
|
|
839
|
+
{page.content}
|
|
840
|
+
</PageFrame>
|
|
841
|
+
))}
|
|
842
|
+
</div>
|
|
680
843
|
</div>
|
|
844
|
+
{import.meta.env.DEV && docId && (
|
|
845
|
+
<EditSaveCard
|
|
846
|
+
textCount={textPending}
|
|
847
|
+
controlsRef={editControlsRef}
|
|
848
|
+
onShownChange={setCardShown}
|
|
849
|
+
/>
|
|
850
|
+
)}
|
|
681
851
|
</div>
|
|
682
|
-
{
|
|
683
|
-
|
|
684
|
-
|
|
852
|
+
{editing && docId && (
|
|
853
|
+
// Keyed by document: a selection, or an editor carried across a
|
|
854
|
+
// reload by source location, must never follow into another
|
|
855
|
+
// document where the same line:column is something else entirely.
|
|
856
|
+
<Inspector
|
|
857
|
+
key={docId}
|
|
858
|
+
docId={docId}
|
|
859
|
+
containerRef={scrollRef}
|
|
860
|
+
panelHidden={designOpen}
|
|
861
|
+
quiet={cardShown}
|
|
862
|
+
onExit={() => setEditing(false)}
|
|
863
|
+
exitRef={leaveEditRef}
|
|
685
864
|
controlsRef={editControlsRef}
|
|
686
|
-
|
|
865
|
+
onPendingChange={setTextPending}
|
|
687
866
|
/>
|
|
688
867
|
)}
|
|
868
|
+
{designOpen && <DesignPanel onClose={() => setDesignOpen(false)} />}
|
|
689
869
|
</div>
|
|
690
|
-
{editing && docId && (
|
|
691
|
-
// Keyed by document: a selection, or an editor carried across a
|
|
692
|
-
// reload by source location, must never follow into another
|
|
693
|
-
// document where the same line:column is something else entirely.
|
|
694
|
-
<Inspector
|
|
695
|
-
key={docId}
|
|
696
|
-
docId={docId}
|
|
697
|
-
containerRef={scrollRef}
|
|
698
|
-
panelHidden={designOpen}
|
|
699
|
-
quiet={cardShown}
|
|
700
|
-
onExit={() => setEditing(false)}
|
|
701
|
-
exitRef={leaveEditRef}
|
|
702
|
-
controlsRef={editControlsRef}
|
|
703
|
-
onPendingChange={setTextPending}
|
|
704
|
-
/>
|
|
705
|
-
)}
|
|
706
|
-
{designOpen && <DesignPanel onClose={() => setDesignOpen(false)} />}
|
|
707
870
|
</div>
|
|
708
|
-
</
|
|
871
|
+
</CommandPaletteProvider>
|
|
709
872
|
);
|
|
710
873
|
|
|
711
874
|
// The design panel writes back to source through the dev server, so it only
|
|
@@ -725,6 +888,8 @@ export function Doc() {
|
|
|
725
888
|
* 自訂欄位只在被選中時出現。三個選項配一個永遠佔著位置的空欄位,會讓人以為那是
|
|
726
889
|
* 必填的。
|
|
727
890
|
*/
|
|
891
|
+
const MENU_LABEL = 'px-2 pt-2 pb-1 text-[10px] text-muted-foreground uppercase tracking-wide';
|
|
892
|
+
|
|
728
893
|
function PageChoice({
|
|
729
894
|
selection,
|
|
730
895
|
custom,
|
|
@@ -740,65 +905,100 @@ function PageChoice({
|
|
|
740
905
|
onSelection: (selection: PageSelection) => void;
|
|
741
906
|
onCustom: (text: string) => void;
|
|
742
907
|
}) {
|
|
908
|
+
const t = useT();
|
|
909
|
+
const rangeRef = useRef<HTMLInputElement>(null);
|
|
743
910
|
const options = [
|
|
744
|
-
{ kind: 'all' as const, label: 'All',
|
|
745
|
-
{ kind: 'current' as const, label: 'This page',
|
|
746
|
-
{ kind: 'custom' as const, label: '
|
|
911
|
+
{ kind: 'all' as const, label: t('All'), count: total },
|
|
912
|
+
{ kind: 'current' as const, label: t('This page'), count: currentPage },
|
|
913
|
+
{ kind: 'custom' as const, label: t('Range'), count: null },
|
|
747
914
|
];
|
|
748
|
-
const
|
|
749
|
-
selection.kind === 'custom' ? { kind: 'custom', text: custom } : selection
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
915
|
+
const current =
|
|
916
|
+
selection.kind === 'custom' ? { kind: 'custom' as const, text: custom } : selection;
|
|
917
|
+
const pages = resolveSelection(current, total, currentPage);
|
|
918
|
+
|
|
919
|
+
// Choosing a range is choosing to type one.
|
|
920
|
+
useEffect(() => {
|
|
921
|
+
if (selection.kind === 'custom') rangeRef.current?.focus();
|
|
922
|
+
}, [selection.kind]);
|
|
923
|
+
|
|
924
|
+
const summary =
|
|
925
|
+
pages === null
|
|
926
|
+
? selection.kind === 'custom' && custom.trim() !== ''
|
|
927
|
+
? t('No such pages — this document has {total}', { total })
|
|
928
|
+
: t('Type pages, like 1-3, 6')
|
|
929
|
+
: selection.kind === 'all'
|
|
930
|
+
? total === 1
|
|
931
|
+
? t('All 1 page')
|
|
932
|
+
: t('All {count} pages', { count: total })
|
|
933
|
+
: pages.length === 1
|
|
934
|
+
? t('Page {pages} · 1 page', { pages: formatPages(pages) })
|
|
935
|
+
: t('Pages {pages} · {count} pages', {
|
|
936
|
+
pages: formatPages(pages),
|
|
937
|
+
count: pages.length,
|
|
938
|
+
});
|
|
753
939
|
|
|
754
940
|
return (
|
|
755
|
-
<
|
|
756
|
-
<
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
941
|
+
<fieldset className="border-border border-b pb-2">
|
|
942
|
+
<legend className={MENU_LABEL}>{t('Pages')}</legend>
|
|
943
|
+
{/* One row of equal segments; labels never wrap, so a two-word option
|
|
944
|
+
doesn't stand taller than its neighbours. */}
|
|
945
|
+
<div
|
|
946
|
+
role="radiogroup"
|
|
947
|
+
aria-label={t('Pages to download')}
|
|
948
|
+
className="mx-1 grid grid-cols-3 gap-0.5 rounded-md bg-muted p-0.5"
|
|
949
|
+
>
|
|
950
|
+
{options.map((option) => {
|
|
951
|
+
const active = selection.kind === option.kind;
|
|
952
|
+
return (
|
|
953
|
+
<button
|
|
954
|
+
key={option.kind}
|
|
955
|
+
type="button"
|
|
956
|
+
aria-pressed={active}
|
|
957
|
+
onClick={(event) => {
|
|
958
|
+
event.stopPropagation();
|
|
959
|
+
onSelection(
|
|
960
|
+
option.kind === 'custom'
|
|
961
|
+
? { kind: 'custom', text: custom }
|
|
962
|
+
: { kind: option.kind },
|
|
963
|
+
);
|
|
964
|
+
}}
|
|
965
|
+
className={cn(
|
|
966
|
+
'flex h-7 items-center justify-center gap-1 whitespace-nowrap rounded px-1.5 text-[11px] text-muted-foreground transition-colors hover:text-foreground',
|
|
967
|
+
active && 'bg-background text-foreground shadow-sm',
|
|
968
|
+
)}
|
|
969
|
+
>
|
|
970
|
+
{option.label}
|
|
971
|
+
{option.count !== null && (
|
|
972
|
+
<span className="font-mono text-[10px] text-muted-foreground tabular-nums">
|
|
973
|
+
{option.count}
|
|
974
|
+
</span>
|
|
975
|
+
)}
|
|
976
|
+
</button>
|
|
977
|
+
);
|
|
978
|
+
})}
|
|
781
979
|
</div>
|
|
782
980
|
{selection.kind === 'custom' && (
|
|
783
981
|
<input
|
|
982
|
+
ref={rangeRef}
|
|
784
983
|
value={custom}
|
|
785
984
|
onChange={(event) => onCustom(event.target.value)}
|
|
786
985
|
onClick={(event) => event.stopPropagation()}
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
aria-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
)}
|
|
986
|
+
onKeyDown={(event) => event.stopPropagation()}
|
|
987
|
+
placeholder="1-3, 6"
|
|
988
|
+
aria-label={t('Page range')}
|
|
989
|
+
aria-invalid={pages === null && custom.trim() !== ''}
|
|
990
|
+
aria-describedby="od-download-pages"
|
|
991
|
+
className="mx-1 mt-1.5 h-7 w-[calc(100%-0.5rem)] rounded border border-border bg-background px-2 font-mono text-[11px] outline-none placeholder:text-muted-foreground focus-visible:border-foreground focus-visible:ring-2 focus-visible:ring-primary/30 aria-invalid:border-foreground/60"
|
|
794
992
|
/>
|
|
795
993
|
)}
|
|
796
|
-
<p
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
994
|
+
<p
|
|
995
|
+
id="od-download-pages"
|
|
996
|
+
aria-live="polite"
|
|
997
|
+
className="px-2 pt-1.5 text-[10.5px] text-muted-foreground"
|
|
998
|
+
>
|
|
999
|
+
{summary}
|
|
800
1000
|
</p>
|
|
801
|
-
</
|
|
1001
|
+
</fieldset>
|
|
802
1002
|
);
|
|
803
1003
|
}
|
|
804
1004
|
|
|
@@ -817,6 +1017,7 @@ function PageJump({
|
|
|
817
1017
|
total: number;
|
|
818
1018
|
onJump: (page: number) => void;
|
|
819
1019
|
}) {
|
|
1020
|
+
const t = useT();
|
|
820
1021
|
const [draft, setDraft] = useState<string | null>(null);
|
|
821
1022
|
|
|
822
1023
|
const commit = (raw: string) => {
|
|
@@ -828,6 +1029,8 @@ function PageJump({
|
|
|
828
1029
|
|
|
829
1030
|
return (
|
|
830
1031
|
<span className="flex items-center whitespace-nowrap font-mono text-muted-foreground text-xs tabular-nums">
|
|
1032
|
+
{/* A bordered field, not bare digits: a number that looks like a label
|
|
1033
|
+
reads as one, and nobody thinks to type into it. */}
|
|
831
1034
|
<input
|
|
832
1035
|
value={draft ?? String(page)}
|
|
833
1036
|
onChange={(event) => setDraft(event.target.value)}
|
|
@@ -846,10 +1049,11 @@ function PageJump({
|
|
|
846
1049
|
event.currentTarget.blur();
|
|
847
1050
|
}
|
|
848
1051
|
}}
|
|
849
|
-
aria-label={
|
|
850
|
-
title=
|
|
1052
|
+
aria-label={t('Page number, {total} pages', { total })}
|
|
1053
|
+
title={t('Go to page')}
|
|
851
1054
|
inputMode="numeric"
|
|
852
|
-
className=
|
|
1055
|
+
className={FIELD_CLASS}
|
|
1056
|
+
style={{ width: `${Math.max(2, String(total).length) + 2}ch` }}
|
|
853
1057
|
/>
|
|
854
1058
|
<span className="px-1">/</span>
|
|
855
1059
|
<span>{total}</span>
|
|
@@ -857,6 +1061,157 @@ function PageJump({
|
|
|
857
1061
|
);
|
|
858
1062
|
}
|
|
859
1063
|
|
|
1064
|
+
const FIELD_CLASS =
|
|
1065
|
+
'h-6 rounded border border-border bg-background px-1 text-center text-foreground outline-none transition-colors hover:border-muted-foreground/50 focus-visible:border-foreground focus-visible:ring-2 focus-visible:ring-primary/30';
|
|
1066
|
+
|
|
1067
|
+
function Divider() {
|
|
1068
|
+
return <span aria-hidden className="mx-0.5 h-4 w-px bg-border" />;
|
|
1069
|
+
}
|
|
1070
|
+
|
|
1071
|
+
const ZOOM_PRESETS = [50, 75, 100, 125, 150, 200];
|
|
1072
|
+
|
|
1073
|
+
/**
|
|
1074
|
+
* The zoom as a field you can type into, with the fits and common sizes one
|
|
1075
|
+
* menu away. It replaces a read-only percentage beside three icon buttons —
|
|
1076
|
+
* fit width, fit page, and actual size — the last of which did exactly what
|
|
1077
|
+
* clicking the percentage already did.
|
|
1078
|
+
*/
|
|
1079
|
+
function ZoomControl({
|
|
1080
|
+
scale,
|
|
1081
|
+
fit,
|
|
1082
|
+
onStep,
|
|
1083
|
+
onSet,
|
|
1084
|
+
onFit,
|
|
1085
|
+
}: {
|
|
1086
|
+
scale: number;
|
|
1087
|
+
/** The fit in force, or null once the reader has set a size by hand. */
|
|
1088
|
+
fit: 'auto' | 'fit-width' | 'fit-page' | null;
|
|
1089
|
+
onStep: (delta: number) => void;
|
|
1090
|
+
onSet: (scale: number) => void;
|
|
1091
|
+
onFit: (mode: 'fit-width' | 'fit-page') => void;
|
|
1092
|
+
}) {
|
|
1093
|
+
const t = useT();
|
|
1094
|
+
const [draft, setDraft] = useState<string | null>(null);
|
|
1095
|
+
const percent = Math.round(scale * 100);
|
|
1096
|
+
|
|
1097
|
+
const commit = (raw: string) => {
|
|
1098
|
+
setDraft(null);
|
|
1099
|
+
const digits = raw.replace(/[0-9]/g, (d) => String(d.charCodeAt(0) - 0xff10));
|
|
1100
|
+
const wanted = Number.parseFloat(digits.replace(/[%\s]/g, ''));
|
|
1101
|
+
if (Number.isFinite(wanted) && wanted > 0) onSet(wanted / 100);
|
|
1102
|
+
};
|
|
1103
|
+
|
|
1104
|
+
return (
|
|
1105
|
+
<div className="flex items-center gap-0.5">
|
|
1106
|
+
<IconButton label={t('Zoom out')} onClick={() => onStep(-0.1)}>
|
|
1107
|
+
<Minus className="size-3.5" />
|
|
1108
|
+
</IconButton>
|
|
1109
|
+
<input
|
|
1110
|
+
value={draft ?? `${percent}%`}
|
|
1111
|
+
onChange={(event) => setDraft(event.target.value)}
|
|
1112
|
+
onFocus={(event) => {
|
|
1113
|
+
setDraft(String(percent));
|
|
1114
|
+
requestAnimationFrame(() => event.target.select());
|
|
1115
|
+
}}
|
|
1116
|
+
onBlur={(event) => commit(event.target.value)}
|
|
1117
|
+
onKeyDown={(event) => {
|
|
1118
|
+
if (event.key === 'Enter') {
|
|
1119
|
+
event.preventDefault();
|
|
1120
|
+
event.currentTarget.blur();
|
|
1121
|
+
}
|
|
1122
|
+
if (event.key === 'Escape') {
|
|
1123
|
+
setDraft(null);
|
|
1124
|
+
event.currentTarget.blur();
|
|
1125
|
+
}
|
|
1126
|
+
}}
|
|
1127
|
+
aria-label={t('Zoom level, percent')}
|
|
1128
|
+
title={t('Type a zoom level')}
|
|
1129
|
+
inputMode="decimal"
|
|
1130
|
+
className={cn(FIELD_CLASS, 'w-[6ch] font-mono text-xs tabular-nums')}
|
|
1131
|
+
/>
|
|
1132
|
+
<IconButton label={t('Zoom in')} onClick={() => onStep(0.1)}>
|
|
1133
|
+
<Plus className="size-3.5" />
|
|
1134
|
+
</IconButton>
|
|
1135
|
+
<Menu
|
|
1136
|
+
placement="bottom-start"
|
|
1137
|
+
trigger={(props) => (
|
|
1138
|
+
<button
|
|
1139
|
+
type="button"
|
|
1140
|
+
aria-label={t('Zoom options')}
|
|
1141
|
+
title={t('Zoom options')}
|
|
1142
|
+
className="flex h-6 w-5 items-center justify-center rounded text-muted-foreground transition-colors hover:bg-accent hover:text-foreground aria-expanded:bg-accent aria-expanded:text-foreground"
|
|
1143
|
+
{...props}
|
|
1144
|
+
>
|
|
1145
|
+
<ChevronDown className="size-3.5" />
|
|
1146
|
+
</button>
|
|
1147
|
+
)}
|
|
1148
|
+
>
|
|
1149
|
+
{(close) => (
|
|
1150
|
+
<>
|
|
1151
|
+
<MenuItem
|
|
1152
|
+
active={fit === 'fit-width'}
|
|
1153
|
+
onClick={() => {
|
|
1154
|
+
onFit('fit-width');
|
|
1155
|
+
close();
|
|
1156
|
+
}}
|
|
1157
|
+
>
|
|
1158
|
+
<MoveHorizontal className="size-3.5" />
|
|
1159
|
+
{t('Fit width')}
|
|
1160
|
+
</MenuItem>
|
|
1161
|
+
<MenuItem
|
|
1162
|
+
active={fit === 'fit-page'}
|
|
1163
|
+
onClick={() => {
|
|
1164
|
+
onFit('fit-page');
|
|
1165
|
+
close();
|
|
1166
|
+
}}
|
|
1167
|
+
>
|
|
1168
|
+
<MoveVertical className="size-3.5" />
|
|
1169
|
+
{t('Fit page')}
|
|
1170
|
+
</MenuItem>
|
|
1171
|
+
<div aria-hidden className="my-1 h-px bg-border" />
|
|
1172
|
+
{ZOOM_PRESETS.map((value) => (
|
|
1173
|
+
<MenuItem
|
|
1174
|
+
key={value}
|
|
1175
|
+
active={fit === null && percent === value}
|
|
1176
|
+
onClick={() => {
|
|
1177
|
+
onSet(value / 100);
|
|
1178
|
+
close();
|
|
1179
|
+
}}
|
|
1180
|
+
>
|
|
1181
|
+
<span className="w-3.5" />
|
|
1182
|
+
{value === 100 ? t('Actual size (100%)') : `${value}%`}
|
|
1183
|
+
</MenuItem>
|
|
1184
|
+
))}
|
|
1185
|
+
</>
|
|
1186
|
+
)}
|
|
1187
|
+
</Menu>
|
|
1188
|
+
</div>
|
|
1189
|
+
);
|
|
1190
|
+
}
|
|
1191
|
+
|
|
1192
|
+
/** The page as it is — document, and the reader's place in it — on the clipboard. */
|
|
1193
|
+
function CopyLink() {
|
|
1194
|
+
const t = useT();
|
|
1195
|
+
const [copied, setCopied] = useState(false);
|
|
1196
|
+
return (
|
|
1197
|
+
<button
|
|
1198
|
+
type="button"
|
|
1199
|
+
aria-label={copied ? t('Link copied') : t('Copy link')}
|
|
1200
|
+
title={t('Copy link')}
|
|
1201
|
+
onClick={async () => {
|
|
1202
|
+
try {
|
|
1203
|
+
await navigator.clipboard.writeText(window.location.href);
|
|
1204
|
+
setCopied(true);
|
|
1205
|
+
setTimeout(() => setCopied(false), 1500);
|
|
1206
|
+
} catch {}
|
|
1207
|
+
}}
|
|
1208
|
+
className="flex size-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
|
|
1209
|
+
>
|
|
1210
|
+
{copied ? <Check className="size-4" /> : <Link2 className="size-4" />}
|
|
1211
|
+
</button>
|
|
1212
|
+
);
|
|
1213
|
+
}
|
|
1214
|
+
|
|
860
1215
|
function IconButton({
|
|
861
1216
|
label,
|
|
862
1217
|
onClick,
|
|
@@ -894,14 +1249,15 @@ function Centered({ children }: { children: React.ReactNode }) {
|
|
|
894
1249
|
}
|
|
895
1250
|
|
|
896
1251
|
function BackLink() {
|
|
1252
|
+
const t = useT();
|
|
897
1253
|
const className = 'mt-4 inline-block text-muted-foreground text-xs underline';
|
|
898
1254
|
return appConfig.home === undefined ? (
|
|
899
1255
|
<Link to="/" className={className}>
|
|
900
|
-
Back to documents
|
|
1256
|
+
{t('Back to documents')}
|
|
901
1257
|
</Link>
|
|
902
1258
|
) : (
|
|
903
1259
|
<a href={appConfig.home} className={className}>
|
|
904
|
-
Back to workspace
|
|
1260
|
+
{t('Back to workspace')}
|
|
905
1261
|
</a>
|
|
906
1262
|
);
|
|
907
1263
|
}
|