@open-document/core 0.1.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/LICENSE +21 -0
- package/README.md +50 -0
- package/README.zh-TW.md +50 -0
- package/bin.js +2 -0
- package/dist/build-BWZJ1gvL.js +18 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +86 -0
- package/dist/config-DBp4mOOf.js +1121 -0
- package/dist/config-EBFfKtWH.d.ts +17 -0
- package/dist/design-BJLvOcCO.js +53 -0
- package/dist/dev-CZtw1oqs.js +24 -0
- package/dist/edit-ops-DSdUroVO.js +1225 -0
- package/dist/index.d.ts +206 -0
- package/dist/index.js +240 -0
- package/dist/ops/index.d.ts +160 -0
- package/dist/ops/index.js +202 -0
- package/dist/preview-DUfQl7Ij.js +23 -0
- package/dist/sync-6GTPAt2t.js +86 -0
- package/dist/sync-C6CsPmyK.js +3 -0
- package/dist/vite/index.d.ts +22 -0
- package/dist/vite/index.js +5 -0
- package/env.d.ts +51 -0
- package/package.json +91 -0
- package/skills/apply-comments/SKILL.md +74 -0
- package/skills/create-doc/SKILL.md +102 -0
- package/skills/create-theme/SKILL.md +184 -0
- package/skills/doc-authoring/SKILL.md +354 -0
- package/skills/doc-authoring/references/assets.md +47 -0
- package/skills/doc-authoring/references/design-system.md +81 -0
- package/skills/doc-authoring/references/pagination.md +117 -0
- package/skills/doc-authoring/references/tables-and-charts.md +161 -0
- package/src/app/app.tsx +42 -0
- package/src/app/components/design-panel/design-panel.tsx +318 -0
- package/src/app/components/design-panel/design-provider.tsx +121 -0
- package/src/app/components/design-panel/use-design.ts +85 -0
- package/src/app/components/doc-assets.tsx +129 -0
- package/src/app/components/doc-sidebar.tsx +162 -0
- package/src/app/components/flow-page.tsx +50 -0
- package/src/app/components/image-placeholder.tsx +50 -0
- package/src/app/components/inspector/inspector.tsx +426 -0
- package/src/app/components/page-frame.tsx +70 -0
- package/src/app/components/sidebar/folder-item.tsx +212 -0
- package/src/app/components/sidebar/icon-picker.tsx +99 -0
- package/src/app/components/sidebar/sidebar.tsx +252 -0
- package/src/app/components/table-of-contents.tsx +81 -0
- package/src/app/components/theme-toggle.tsx +50 -0
- package/src/app/components/themes/markdown.tsx +249 -0
- package/src/app/components/themes/theme-preview.tsx +74 -0
- package/src/app/components/ui/menu.tsx +139 -0
- package/src/app/index.html +12 -0
- package/src/app/lib/assets.ts +151 -0
- package/src/app/lib/design-presets.ts +109 -0
- package/src/app/lib/design.ts +88 -0
- package/src/app/lib/doc-preview.tsx +29 -0
- package/src/app/lib/docs.ts +26 -0
- package/src/app/lib/export-html.ts +309 -0
- package/src/app/lib/export-pdf.ts +166 -0
- package/src/app/lib/flow-measure.ts +109 -0
- package/src/app/lib/flow.test.ts +64 -0
- package/src/app/lib/flow.ts +111 -0
- package/src/app/lib/folders.ts +192 -0
- package/src/app/lib/inspector/fiber.ts +99 -0
- package/src/app/lib/outline.ts +109 -0
- package/src/app/lib/page-context.tsx +38 -0
- package/src/app/lib/print-ready.ts +69 -0
- package/src/app/lib/sdk.test.ts +24 -0
- package/src/app/lib/sdk.ts +86 -0
- package/src/app/lib/themes.ts +31 -0
- package/src/app/lib/use-doc-module.ts +53 -0
- package/src/app/lib/use-doc-pages.ts +99 -0
- package/src/app/lib/utils.ts +6 -0
- package/src/app/main.tsx +14 -0
- package/src/app/routes/assets.tsx +257 -0
- package/src/app/routes/doc.tsx +480 -0
- package/src/app/routes/home-shell.tsx +203 -0
- package/src/app/routes/home.tsx +269 -0
- package/src/app/routes/themes.tsx +121 -0
- package/src/app/styles.css +72 -0
- package/src/app/virtual.d.ts +30 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createContext,
|
|
3
|
+
type ReactNode,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useMemo,
|
|
8
|
+
useRef,
|
|
9
|
+
useState,
|
|
10
|
+
} from 'react';
|
|
11
|
+
import { type DesignSystem, defaultDesign, designToCssVars } from '../../lib/design';
|
|
12
|
+
import { shuffleDesign } from '../../lib/design-presets';
|
|
13
|
+
import { useDesign as useDesignFetch } from './use-design';
|
|
14
|
+
|
|
15
|
+
type DesignCtx = {
|
|
16
|
+
docId: string;
|
|
17
|
+
loaded: boolean;
|
|
18
|
+
exists: boolean;
|
|
19
|
+
warning: string | null;
|
|
20
|
+
design: DesignSystem | null;
|
|
21
|
+
draft: DesignSystem | null;
|
|
22
|
+
dirty: boolean;
|
|
23
|
+
committing: boolean;
|
|
24
|
+
error: string | null;
|
|
25
|
+
update: (mut: (next: DesignSystem) => void) => void;
|
|
26
|
+
commit: () => Promise<void>;
|
|
27
|
+
discard: () => void;
|
|
28
|
+
resetToDefaults: () => void;
|
|
29
|
+
shuffle: () => void;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const Ctx = createContext<DesignCtx | null>(null);
|
|
33
|
+
|
|
34
|
+
export function useDesignPanelState(): DesignCtx {
|
|
35
|
+
const value = useContext(Ctx);
|
|
36
|
+
if (!value) throw new Error('useDesignPanelState must be used inside <DesignProvider>');
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function clone<T>(value: T): T {
|
|
41
|
+
return JSON.parse(JSON.stringify(value)) as T;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function DesignProvider({ docId, children }: { docId: string; children: ReactNode }) {
|
|
45
|
+
const { design, exists, warning, loaded, save } = useDesignFetch(docId);
|
|
46
|
+
const [draft, setDraft] = useState<DesignSystem | null>(null);
|
|
47
|
+
const [committing, setCommitting] = useState(false);
|
|
48
|
+
const [error, setError] = useState<string | null>(null);
|
|
49
|
+
const draftRef = useRef<DesignSystem | null>(null);
|
|
50
|
+
draftRef.current = draft;
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (design) setDraft(clone(design));
|
|
54
|
+
}, [design]);
|
|
55
|
+
|
|
56
|
+
const dirty = useMemo(() => {
|
|
57
|
+
if (!draft || !design) return false;
|
|
58
|
+
return JSON.stringify(draft) !== JSON.stringify(design);
|
|
59
|
+
}, [draft, design]);
|
|
60
|
+
|
|
61
|
+
const update = useCallback((mut: (next: DesignSystem) => void) => {
|
|
62
|
+
const prev = draftRef.current;
|
|
63
|
+
if (!prev) return;
|
|
64
|
+
const next = clone(prev);
|
|
65
|
+
mut(next);
|
|
66
|
+
setDraft(next);
|
|
67
|
+
}, []);
|
|
68
|
+
|
|
69
|
+
const commit = useCallback(async () => {
|
|
70
|
+
if (!draft) return;
|
|
71
|
+
setCommitting(true);
|
|
72
|
+
const result = await save(draft);
|
|
73
|
+
setCommitting(false);
|
|
74
|
+
setError(result.ok ? null : (result.error ?? 'Failed to save'));
|
|
75
|
+
}, [draft, save]);
|
|
76
|
+
|
|
77
|
+
const discard = useCallback(() => {
|
|
78
|
+
if (design) setDraft(clone(design));
|
|
79
|
+
setError(null);
|
|
80
|
+
}, [design]);
|
|
81
|
+
|
|
82
|
+
const resetToDefaults = useCallback(() => setDraft(clone(defaultDesign)), []);
|
|
83
|
+
const shuffle = useCallback(() => setDraft(clone(shuffleDesign(draftRef.current))), []);
|
|
84
|
+
|
|
85
|
+
// PageFrame writes its design vars inline on each page root, so the draft
|
|
86
|
+
// overlay has to outrank inline styles — hence `!important`.
|
|
87
|
+
const previewCss = useMemo(() => {
|
|
88
|
+
if (!dirty || !draft) return '';
|
|
89
|
+
const lines = Object.entries(designToCssVars(draft))
|
|
90
|
+
.map(([k, v]) => ` ${k}: ${v} !important;`)
|
|
91
|
+
.join('\n');
|
|
92
|
+
return `[data-od-page] {\n${lines}\n}`;
|
|
93
|
+
}, [dirty, draft]);
|
|
94
|
+
|
|
95
|
+
const value: DesignCtx = {
|
|
96
|
+
docId,
|
|
97
|
+
loaded,
|
|
98
|
+
exists,
|
|
99
|
+
warning,
|
|
100
|
+
design,
|
|
101
|
+
draft,
|
|
102
|
+
dirty,
|
|
103
|
+
committing,
|
|
104
|
+
error,
|
|
105
|
+
update,
|
|
106
|
+
commit,
|
|
107
|
+
discard,
|
|
108
|
+
resetToDefaults,
|
|
109
|
+
shuffle,
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return (
|
|
113
|
+
<Ctx.Provider value={value}>
|
|
114
|
+
{previewCss && (
|
|
115
|
+
// biome-ignore lint/security/noDangerouslySetInnerHtml: trusted local css built from draft state
|
|
116
|
+
<style dangerouslySetInnerHTML={{ __html: previewCss }} />
|
|
117
|
+
)}
|
|
118
|
+
{children}
|
|
119
|
+
</Ctx.Provider>
|
|
120
|
+
);
|
|
121
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import type { DesignSystem } from '../../lib/design';
|
|
3
|
+
|
|
4
|
+
type FetchedState = {
|
|
5
|
+
design: DesignSystem | null;
|
|
6
|
+
exists: boolean;
|
|
7
|
+
warning: string | null;
|
|
8
|
+
loaded: boolean;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type UseDesignReturn = FetchedState & {
|
|
12
|
+
refresh: () => Promise<void>;
|
|
13
|
+
save: (patch: Partial<DesignSystem>) => Promise<{ ok: boolean; error?: string }>;
|
|
14
|
+
reset: () => Promise<{ ok: boolean; error?: string }>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const INITIAL: FetchedState = { design: null, exists: false, warning: null, loaded: false };
|
|
18
|
+
|
|
19
|
+
export function useDesign(docId: string): UseDesignReturn {
|
|
20
|
+
const [state, setState] = useState<FetchedState>(INITIAL);
|
|
21
|
+
const docIdRef = useRef(docId);
|
|
22
|
+
docIdRef.current = docId;
|
|
23
|
+
|
|
24
|
+
const refresh = useCallback(async () => {
|
|
25
|
+
const id = docIdRef.current;
|
|
26
|
+
if (!id) return;
|
|
27
|
+
try {
|
|
28
|
+
const res = await fetch(`/__design?docId=${encodeURIComponent(id)}`);
|
|
29
|
+
if (!res.ok) throw new Error(`HTTP ${res.status}`);
|
|
30
|
+
const body = (await res.json()) as {
|
|
31
|
+
design: DesignSystem;
|
|
32
|
+
exists: boolean;
|
|
33
|
+
warning: string | null;
|
|
34
|
+
};
|
|
35
|
+
setState({ design: body.design, exists: body.exists, warning: body.warning, loaded: true });
|
|
36
|
+
} catch (err) {
|
|
37
|
+
setState((s) => ({ ...s, warning: String((err as Error).message), loaded: true }));
|
|
38
|
+
}
|
|
39
|
+
}, []);
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
setState(INITIAL);
|
|
43
|
+
void refresh();
|
|
44
|
+
}, [refresh]);
|
|
45
|
+
|
|
46
|
+
const save = useCallback(async (patch: Partial<DesignSystem>) => {
|
|
47
|
+
const id = docIdRef.current;
|
|
48
|
+
if (!id) return { ok: false, error: 'no document id' };
|
|
49
|
+
try {
|
|
50
|
+
const res = await fetch(`/__design?docId=${encodeURIComponent(id)}`, {
|
|
51
|
+
method: 'PUT',
|
|
52
|
+
headers: { 'content-type': 'application/json' },
|
|
53
|
+
body: JSON.stringify({ patch }),
|
|
54
|
+
});
|
|
55
|
+
const body = (await res.json()) as { ok?: boolean; error?: string; design?: DesignSystem };
|
|
56
|
+
if (!res.ok || !body.ok) return { ok: false, error: body.error ?? `HTTP ${res.status}` };
|
|
57
|
+
if (body.design) {
|
|
58
|
+
setState((s) => ({ ...s, design: body.design ?? s.design, exists: true, warning: null }));
|
|
59
|
+
}
|
|
60
|
+
return { ok: true };
|
|
61
|
+
} catch (err) {
|
|
62
|
+
return { ok: false, error: String((err as Error).message) };
|
|
63
|
+
}
|
|
64
|
+
}, []);
|
|
65
|
+
|
|
66
|
+
const reset = useCallback(async () => {
|
|
67
|
+
const id = docIdRef.current;
|
|
68
|
+
if (!id) return { ok: false, error: 'no document id' };
|
|
69
|
+
try {
|
|
70
|
+
const res = await fetch(`/__design/reset?docId=${encodeURIComponent(id)}`, {
|
|
71
|
+
method: 'POST',
|
|
72
|
+
});
|
|
73
|
+
const body = (await res.json()) as { ok?: boolean; error?: string; design?: DesignSystem };
|
|
74
|
+
if (!res.ok || !body.ok) return { ok: false, error: body.error ?? `HTTP ${res.status}` };
|
|
75
|
+
if (body.design) {
|
|
76
|
+
setState((s) => ({ ...s, design: body.design ?? s.design, exists: true, warning: null }));
|
|
77
|
+
}
|
|
78
|
+
return { ok: true };
|
|
79
|
+
} catch (err) {
|
|
80
|
+
return { ok: false, error: String((err as Error).message) };
|
|
81
|
+
}
|
|
82
|
+
}, []);
|
|
83
|
+
|
|
84
|
+
return { ...state, refresh, save, reset };
|
|
85
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Check, Copy, FileIcon, Loader2 } from 'lucide-react';
|
|
2
|
+
import { useCallback, useEffect, useState } from 'react';
|
|
3
|
+
import {
|
|
4
|
+
type Asset,
|
|
5
|
+
formatBytes,
|
|
6
|
+
GLOBAL_SCOPE,
|
|
7
|
+
importSnippet,
|
|
8
|
+
isPreviewable,
|
|
9
|
+
listAssets,
|
|
10
|
+
} from '../lib/assets';
|
|
11
|
+
import { cn } from '../lib/utils';
|
|
12
|
+
|
|
13
|
+
type Group = { scope: string; label: string; assets: Asset[] };
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The images this document can reach, without leaving it: its own `assets/`
|
|
17
|
+
* folder plus the shared project folder. Clicking one gives the import line to
|
|
18
|
+
* paste into the source.
|
|
19
|
+
*/
|
|
20
|
+
export function DocAssets({ docId }: { docId: string }) {
|
|
21
|
+
const [groups, setGroups] = useState<Group[] | null>(null);
|
|
22
|
+
const [selected, setSelected] = useState<Asset | null>(null);
|
|
23
|
+
const [copied, setCopied] = useState(false);
|
|
24
|
+
|
|
25
|
+
const load = useCallback(async () => {
|
|
26
|
+
const [own, global] = await Promise.all([listAssets(docId), listAssets(GLOBAL_SCOPE)]);
|
|
27
|
+
setGroups([
|
|
28
|
+
{ scope: docId, label: 'This document', assets: own.ok ? own.value : [] },
|
|
29
|
+
{ scope: GLOBAL_SCOPE, label: 'Project', assets: global.ok ? global.value : [] },
|
|
30
|
+
]);
|
|
31
|
+
}, [docId]);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
setGroups(null);
|
|
35
|
+
void load();
|
|
36
|
+
if (!import.meta.hot) return;
|
|
37
|
+
const handler = () => void load();
|
|
38
|
+
import.meta.hot.on('open-doc:files-changed', handler);
|
|
39
|
+
return () => {
|
|
40
|
+
import.meta.hot?.off('open-doc:files-changed', handler);
|
|
41
|
+
};
|
|
42
|
+
}, [load]);
|
|
43
|
+
|
|
44
|
+
const copyImport = async (asset: Asset) => {
|
|
45
|
+
try {
|
|
46
|
+
await navigator.clipboard.writeText(importSnippet(asset));
|
|
47
|
+
setCopied(true);
|
|
48
|
+
setTimeout(() => setCopied(false), 1200);
|
|
49
|
+
} catch {}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
if (groups === null) {
|
|
53
|
+
return (
|
|
54
|
+
<div className="grid flex-1 place-items-center">
|
|
55
|
+
<Loader2 className="size-4 animate-spin text-muted-foreground" />
|
|
56
|
+
</div>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const empty = groups.every((group) => group.assets.length === 0);
|
|
61
|
+
|
|
62
|
+
return (
|
|
63
|
+
<div className="flex-1 overflow-y-auto px-3 pb-6">
|
|
64
|
+
{empty && (
|
|
65
|
+
<p className="px-1 py-2 text-muted-foreground text-xs leading-relaxed">
|
|
66
|
+
No assets yet. Drop files into <code className="font-mono">docs/{docId}/assets/</code> or
|
|
67
|
+
upload them from the Assets page.
|
|
68
|
+
</p>
|
|
69
|
+
)}
|
|
70
|
+
|
|
71
|
+
{groups.map((group) =>
|
|
72
|
+
group.assets.length === 0 ? null : (
|
|
73
|
+
<section key={group.scope} className="mb-4">
|
|
74
|
+
<h3 className="mb-1.5 px-1 text-[10px] text-muted-foreground uppercase tracking-wider">
|
|
75
|
+
{group.label}
|
|
76
|
+
</h3>
|
|
77
|
+
<div className="grid grid-cols-2 gap-1.5">
|
|
78
|
+
{group.assets.map((asset) => (
|
|
79
|
+
<button
|
|
80
|
+
key={`${group.scope}/${asset.name}`}
|
|
81
|
+
type="button"
|
|
82
|
+
title={asset.name}
|
|
83
|
+
onClick={() => setSelected(asset)}
|
|
84
|
+
className={cn(
|
|
85
|
+
'grid h-16 place-items-center overflow-hidden rounded border bg-muted p-1 transition-colors',
|
|
86
|
+
selected?.url === asset.url
|
|
87
|
+
? 'border-foreground'
|
|
88
|
+
: 'border-border hover:border-foreground/40',
|
|
89
|
+
)}
|
|
90
|
+
>
|
|
91
|
+
{isPreviewable(asset.mime) ? (
|
|
92
|
+
<img
|
|
93
|
+
src={asset.url}
|
|
94
|
+
alt={asset.name}
|
|
95
|
+
className="max-h-full max-w-full object-contain"
|
|
96
|
+
/>
|
|
97
|
+
) : (
|
|
98
|
+
<FileIcon className="size-4 text-muted-foreground" />
|
|
99
|
+
)}
|
|
100
|
+
</button>
|
|
101
|
+
))}
|
|
102
|
+
</div>
|
|
103
|
+
</section>
|
|
104
|
+
),
|
|
105
|
+
)}
|
|
106
|
+
|
|
107
|
+
{selected && (
|
|
108
|
+
<div className="sticky bottom-0 rounded-md border border-border bg-background p-2">
|
|
109
|
+
<p className="truncate font-medium text-[11px]">{selected.name}</p>
|
|
110
|
+
<p className="mt-0.5 text-[10px] text-muted-foreground">
|
|
111
|
+
{formatBytes(selected.size)}
|
|
112
|
+
{selected.unused ? ' · unused' : ''}
|
|
113
|
+
</p>
|
|
114
|
+
<code className="mt-1.5 block truncate rounded bg-muted px-1.5 py-1 font-mono text-[10px]">
|
|
115
|
+
{selected.importPath}
|
|
116
|
+
</code>
|
|
117
|
+
<button
|
|
118
|
+
type="button"
|
|
119
|
+
onClick={() => copyImport(selected)}
|
|
120
|
+
className="mt-1.5 flex w-full items-center justify-center gap-1 rounded border border-border px-2 py-1 text-[11px] transition-colors hover:bg-accent"
|
|
121
|
+
>
|
|
122
|
+
{copied ? <Check className="size-3" /> : <Copy className="size-3" />}
|
|
123
|
+
{copied ? 'Copied' : 'Copy import'}
|
|
124
|
+
</button>
|
|
125
|
+
</div>
|
|
126
|
+
)}
|
|
127
|
+
</div>
|
|
128
|
+
);
|
|
129
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import type { DesignSystem } from '../lib/design';
|
|
3
|
+
import type { OutlineEntry } from '../lib/outline';
|
|
4
|
+
import type { PageGeometry } from '../lib/sdk';
|
|
5
|
+
import type { ExpandedPage } from '../lib/use-doc-pages';
|
|
6
|
+
import { cn } from '../lib/utils';
|
|
7
|
+
import { DocAssets } from './doc-assets';
|
|
8
|
+
import { PageFrame } from './page-frame';
|
|
9
|
+
|
|
10
|
+
const THUMB_WIDTH = 116;
|
|
11
|
+
|
|
12
|
+
type Tab = 'pages' | 'outline' | 'assets';
|
|
13
|
+
|
|
14
|
+
type Props = {
|
|
15
|
+
docId: string;
|
|
16
|
+
pages: ExpandedPage[];
|
|
17
|
+
geometry: PageGeometry;
|
|
18
|
+
design?: DesignSystem;
|
|
19
|
+
currentPage: number;
|
|
20
|
+
entries: OutlineEntry[];
|
|
21
|
+
activeId: string | null;
|
|
22
|
+
onSelectPage: (page: number) => void;
|
|
23
|
+
onSelectEntry: (entry: OutlineEntry) => void;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export function DocSidebar({
|
|
27
|
+
docId,
|
|
28
|
+
pages,
|
|
29
|
+
geometry,
|
|
30
|
+
design,
|
|
31
|
+
currentPage,
|
|
32
|
+
entries,
|
|
33
|
+
activeId,
|
|
34
|
+
onSelectPage,
|
|
35
|
+
onSelectEntry,
|
|
36
|
+
}: Props) {
|
|
37
|
+
const [tab, setTab] = useState<Tab>('pages');
|
|
38
|
+
const railRef = useRef<HTMLDivElement>(null);
|
|
39
|
+
// The assets panel talks to the dev API, so it has nothing to show in a
|
|
40
|
+
// static build.
|
|
41
|
+
const tabs = useMemo<Tab[]>(
|
|
42
|
+
() => (import.meta.env.DEV ? ['pages', 'outline', 'assets'] : ['pages', 'outline']),
|
|
43
|
+
[],
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
// Follow the reader: keep the active thumbnail in view as the main pane scrolls.
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (tab !== 'pages') return;
|
|
49
|
+
const rail = railRef.current;
|
|
50
|
+
const active = rail?.querySelector<HTMLElement>(`[data-thumb-page="${currentPage}"]`);
|
|
51
|
+
if (!rail || !active) return;
|
|
52
|
+
const top = active.offsetTop;
|
|
53
|
+
const bottom = top + active.offsetHeight;
|
|
54
|
+
if (top < rail.scrollTop || bottom > rail.scrollTop + rail.clientHeight) {
|
|
55
|
+
rail.scrollTo({ top: top - rail.clientHeight / 3, behavior: 'smooth' });
|
|
56
|
+
}
|
|
57
|
+
}, [currentPage, tab]);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<aside className="hidden w-56 flex-none flex-col border-border border-r bg-background md:flex">
|
|
61
|
+
<div className="flex flex-none gap-1 p-2">
|
|
62
|
+
{tabs.map((value) => (
|
|
63
|
+
<button
|
|
64
|
+
key={value}
|
|
65
|
+
type="button"
|
|
66
|
+
onClick={() => setTab(value)}
|
|
67
|
+
className={cn(
|
|
68
|
+
'flex-1 rounded-md px-2 py-1 text-[11px] capitalize transition-colors',
|
|
69
|
+
tab === value
|
|
70
|
+
? 'bg-accent font-medium text-foreground'
|
|
71
|
+
: 'text-muted-foreground hover:bg-accent/60',
|
|
72
|
+
)}
|
|
73
|
+
>
|
|
74
|
+
{value}
|
|
75
|
+
</button>
|
|
76
|
+
))}
|
|
77
|
+
</div>
|
|
78
|
+
|
|
79
|
+
{tab === 'assets' ? (
|
|
80
|
+
<DocAssets docId={docId} />
|
|
81
|
+
) : tab === 'pages' ? (
|
|
82
|
+
<div ref={railRef} className="flex-1 overflow-y-auto px-3 pb-6">
|
|
83
|
+
<div className="flex flex-col items-center gap-3">
|
|
84
|
+
{pages.map((entry, index) => {
|
|
85
|
+
const page = index + 1;
|
|
86
|
+
return (
|
|
87
|
+
<button
|
|
88
|
+
key={entry.key}
|
|
89
|
+
type="button"
|
|
90
|
+
data-thumb-page={page}
|
|
91
|
+
onClick={() => onSelectPage(page)}
|
|
92
|
+
className="flex flex-col items-center gap-1"
|
|
93
|
+
>
|
|
94
|
+
<div
|
|
95
|
+
className={cn(
|
|
96
|
+
'overflow-hidden rounded-sm ring-1 transition-shadow',
|
|
97
|
+
page === currentPage
|
|
98
|
+
? 'ring-2 ring-foreground'
|
|
99
|
+
: 'ring-border hover:ring-foreground/40',
|
|
100
|
+
)}
|
|
101
|
+
style={{
|
|
102
|
+
width: THUMB_WIDTH,
|
|
103
|
+
height: geometry.height * (THUMB_WIDTH / geometry.width),
|
|
104
|
+
}}
|
|
105
|
+
>
|
|
106
|
+
<PageFrame
|
|
107
|
+
index={index}
|
|
108
|
+
total={pages.length}
|
|
109
|
+
geometry={geometry}
|
|
110
|
+
scale={THUMB_WIDTH / geometry.width}
|
|
111
|
+
design={design}
|
|
112
|
+
flat
|
|
113
|
+
>
|
|
114
|
+
{entry.content}
|
|
115
|
+
</PageFrame>
|
|
116
|
+
</div>
|
|
117
|
+
<span
|
|
118
|
+
className={cn(
|
|
119
|
+
'font-mono text-[10px] tabular-nums',
|
|
120
|
+
page === currentPage ? 'text-foreground' : 'text-muted-foreground',
|
|
121
|
+
)}
|
|
122
|
+
>
|
|
123
|
+
{page}
|
|
124
|
+
</span>
|
|
125
|
+
</button>
|
|
126
|
+
);
|
|
127
|
+
})}
|
|
128
|
+
</div>
|
|
129
|
+
</div>
|
|
130
|
+
) : (
|
|
131
|
+
<nav className="flex-1 overflow-y-auto px-2 pb-6">
|
|
132
|
+
{entries.length === 0 ? (
|
|
133
|
+
<p className="px-2 py-1 text-muted-foreground text-xs leading-relaxed">
|
|
134
|
+
No headings yet. Add an <code className="font-mono">h1</code>/
|
|
135
|
+
<code className="font-mono">h2</code> to a page and it shows up here.
|
|
136
|
+
</p>
|
|
137
|
+
) : (
|
|
138
|
+
entries.map((entry) => (
|
|
139
|
+
<button
|
|
140
|
+
key={entry.id}
|
|
141
|
+
type="button"
|
|
142
|
+
onClick={() => onSelectEntry(entry)}
|
|
143
|
+
className={cn(
|
|
144
|
+
'flex w-full items-baseline gap-2 rounded-md px-2 py-1.5 text-left text-[13px] transition-colors hover:bg-accent',
|
|
145
|
+
entry.id === activeId
|
|
146
|
+
? 'bg-accent font-medium text-foreground'
|
|
147
|
+
: 'text-muted-foreground',
|
|
148
|
+
)}
|
|
149
|
+
style={{ paddingLeft: 8 + (entry.level - 1) * 12 }}
|
|
150
|
+
>
|
|
151
|
+
<span className="line-clamp-2 flex-1">{entry.text}</span>
|
|
152
|
+
<span className="font-mono text-[10px] text-muted-foreground tabular-nums">
|
|
153
|
+
{entry.page}
|
|
154
|
+
</span>
|
|
155
|
+
</button>
|
|
156
|
+
))
|
|
157
|
+
)}
|
|
158
|
+
</nav>
|
|
159
|
+
)}
|
|
160
|
+
</aside>
|
|
161
|
+
);
|
|
162
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { CSSProperties, ReactNode } from 'react';
|
|
2
|
+
import type { DesignSystem } from '../lib/design';
|
|
3
|
+
import type { FlowSection } from '../lib/flow';
|
|
4
|
+
|
|
5
|
+
export const FLOW_BLOCK_ATTR = 'data-od-flow-block';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The page shell a flow section renders into. The framework owns the margin and
|
|
9
|
+
* base typography here — that is the trade for not hand-splitting pages — while
|
|
10
|
+
* the blocks keep their own styles.
|
|
11
|
+
*/
|
|
12
|
+
export function flowShellStyle(design: DesignSystem | undefined, padding?: number): CSSProperties {
|
|
13
|
+
return {
|
|
14
|
+
width: '100%',
|
|
15
|
+
height: '100%',
|
|
16
|
+
boxSizing: 'border-box',
|
|
17
|
+
padding: padding ?? design?.margin ?? 76,
|
|
18
|
+
background: 'var(--od-bg)',
|
|
19
|
+
color: 'var(--od-text)',
|
|
20
|
+
fontFamily: 'var(--od-font-body)',
|
|
21
|
+
fontSize: 'var(--od-size-body)',
|
|
22
|
+
lineHeight: 'var(--od-leading)',
|
|
23
|
+
position: 'relative',
|
|
24
|
+
overflow: 'hidden',
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function FlowBlock({ children }: { children?: ReactNode }) {
|
|
29
|
+
return <div {...{ [FLOW_BLOCK_ATTR]: '' }}>{children}</div>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function FlowPage({
|
|
33
|
+
section,
|
|
34
|
+
design,
|
|
35
|
+
blockIndices,
|
|
36
|
+
}: {
|
|
37
|
+
section: FlowSection;
|
|
38
|
+
design: DesignSystem | undefined;
|
|
39
|
+
blockIndices: number[];
|
|
40
|
+
}) {
|
|
41
|
+
const Footer = section.footer;
|
|
42
|
+
return (
|
|
43
|
+
<div style={flowShellStyle(design, section.padding)}>
|
|
44
|
+
{blockIndices.map((index) => (
|
|
45
|
+
<FlowBlock key={index}>{section.blocks[index]}</FlowBlock>
|
|
46
|
+
))}
|
|
47
|
+
{Footer && <Footer />}
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { CSSProperties } from 'react';
|
|
2
|
+
|
|
3
|
+
export type ImagePlaceholderProps = {
|
|
4
|
+
/** What the final image should show — the user reads this when replacing it. */
|
|
5
|
+
hint: string;
|
|
6
|
+
width?: number | string;
|
|
7
|
+
height?: number | string;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
className?: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Stands in for an image the user has to supply (a chart from their data, a
|
|
14
|
+
* product screenshot). Use it instead of inventing filler — never for
|
|
15
|
+
* decoration.
|
|
16
|
+
*/
|
|
17
|
+
export function ImagePlaceholder({
|
|
18
|
+
hint,
|
|
19
|
+
width = '100%',
|
|
20
|
+
height = 200,
|
|
21
|
+
style,
|
|
22
|
+
className,
|
|
23
|
+
}: ImagePlaceholderProps) {
|
|
24
|
+
return (
|
|
25
|
+
<div
|
|
26
|
+
data-od-image-placeholder=""
|
|
27
|
+
className={className}
|
|
28
|
+
style={{
|
|
29
|
+
width,
|
|
30
|
+
height,
|
|
31
|
+
display: 'flex',
|
|
32
|
+
alignItems: 'center',
|
|
33
|
+
justifyContent: 'center',
|
|
34
|
+
textAlign: 'center',
|
|
35
|
+
padding: 16,
|
|
36
|
+
boxSizing: 'border-box',
|
|
37
|
+
border: '1px dashed var(--od-rule, #d4d4d8)',
|
|
38
|
+
borderRadius: 'var(--od-radius, 6px)',
|
|
39
|
+
background: 'repeating-linear-gradient(45deg, rgba(0,0,0,.02) 0 8px, transparent 8px 16px)',
|
|
40
|
+
color: 'var(--od-muted, #6b7280)',
|
|
41
|
+
fontFamily: 'var(--od-font-body, system-ui, sans-serif)',
|
|
42
|
+
fontSize: 'var(--od-size-caption, 10px)',
|
|
43
|
+
lineHeight: 1.4,
|
|
44
|
+
...style,
|
|
45
|
+
}}
|
|
46
|
+
>
|
|
47
|
+
{hint}
|
|
48
|
+
</div>
|
|
49
|
+
);
|
|
50
|
+
}
|