@open-document/core 0.15.1 → 0.17.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-CBMroMqd.js → build-BzNZnIhF.js} +1 -1
- package/dist/{check-C2kIZr3f.js → check-C7kxlAFW.js} +11 -4
- package/dist/cli/bin.js +24 -11
- package/dist/{context-DGp1jwN5.js → context-CFPnmNCR.js} +1 -1
- package/dist/{dev-DmzGncKf.js → dev-BUo7OESU.js} +1 -1
- package/dist/{diff-CMI_PVzz.js → diff-B950T0O6.js} +2 -2
- package/dist/{export-BQMUBoBB.js → export-CHN1CiGv.js} +3 -3
- package/dist/{flow-CS5apebG.d.ts → flow-DlV3t5ML.d.ts} +24 -4
- package/dist/{import-CiSRqZyo.js → import-CLSnIxvN.js} +11 -7
- package/dist/index.d.ts +26 -2
- package/dist/index.js +55 -1
- package/dist/ops/index.d.ts +200 -4
- package/dist/ops/index.js +3 -3
- package/dist/{ops-DQbZmYRF.js → ops-BgbM5Irm.js} +364 -9
- package/dist/{preview-CERhZ_FX.js → preview-BVwVqS-I.js} +1 -1
- package/dist/proofread-BpR_3GZz.js +35 -0
- package/dist/{session-DdaKKd7_.js → session-DmbXf3u7.js} +5179 -106
- package/dist/{templates-CBeC-v7e.js → templates-BsWxs7oo.js} +3 -3
- package/dist/translations-CW5OVM0L.js +42 -0
- package/dist/vite/index.js +1 -1
- package/package.json +1 -1
- package/skills/doc-authoring/references/pagination.md +1 -1
- package/skills/fill-form/SKILL.md +42 -0
- package/skills/fit-pages/SKILL.md +48 -0
- package/skills/import-document/SKILL.md +58 -0
- package/skills/proofread/SKILL.md +44 -0
- package/skills/refresh-report/SKILL.md +48 -0
- package/skills/sync-translation/SKILL.md +55 -0
- package/src/agent/prompt.ts +1 -1
- package/src/agent/types.ts +9 -2
- package/src/app/components/agent/agent-panel.tsx +3 -2
- package/src/app/components/checkbox.tsx +68 -0
- package/src/app/components/doc-sidebar.tsx +5 -3
- package/src/app/components/flow-page.tsx +7 -2
- package/src/app/components/host-bridge.tsx +49 -0
- package/src/app/components/panel/edit-save-card.tsx +23 -1
- package/src/app/lib/agent-bridge.ts +37 -4
- package/src/app/lib/diagnostics.ts +46 -5
- package/src/app/lib/export-docx.ts +5 -2
- package/src/app/lib/export-dom.ts +13 -0
- package/src/app/lib/export-html.ts +6 -1
- package/src/app/lib/export-image.ts +9 -4
- package/src/app/lib/export-pdf.ts +17 -4
- package/src/app/lib/flow-measure.ts +9 -5
- package/src/app/lib/flow.ts +3 -2
- package/src/app/lib/host.ts +71 -0
- package/src/app/lib/i18n-ja/browser.ts +1 -0
- package/src/app/lib/i18n-ko/browser.ts +1 -0
- package/src/app/lib/i18n-zh-cn/browser.ts +1 -0
- package/src/app/lib/i18n-zh-tw/browser.ts +1 -0
- package/src/app/lib/page-budget.ts +81 -0
- package/src/app/lib/proofread-script.ts +61 -0
- package/src/app/lib/proofread.ts +399 -0
- package/src/app/lib/recent-docs.ts +27 -0
- package/src/app/lib/sdk.ts +44 -2
- package/src/app/lib/text-runs.ts +83 -0
- package/src/app/lib/use-doc-pages.ts +10 -3
- package/src/app/main.tsx +2 -0
- package/src/app/routes/doc-preview.tsx +1 -1
- package/src/app/routes/doc.tsx +26 -2
- package/src/app/routes/home.tsx +39 -5
|
@@ -11,11 +11,13 @@ import {
|
|
|
11
11
|
import { type MeasurableSection, measureFlowSections } from './flow-measure';
|
|
12
12
|
import { extractSectionFootnotes, notesForPage, type PreparedSection } from './footnotes';
|
|
13
13
|
import { useRecordIndex } from './records';
|
|
14
|
-
import { type DocModule, type PageGeometry, pageLang } from './sdk';
|
|
14
|
+
import { type DocModule, type PageGeometry, pageLang, sectionGeometry } from './sdk';
|
|
15
15
|
|
|
16
16
|
export type ExpandedPage = {
|
|
17
17
|
key: string;
|
|
18
18
|
content: ReactNode;
|
|
19
|
+
/** Set when this sheet is turned from the document's: a landscape section's page. */
|
|
20
|
+
geometry?: PageGeometry;
|
|
19
21
|
};
|
|
20
22
|
|
|
21
23
|
type Plan = {
|
|
@@ -65,10 +67,13 @@ export function useDocPages(
|
|
|
65
67
|
blocks: prepared[index].blocks,
|
|
66
68
|
notesByBlock: prepared[index].notesByBlock,
|
|
67
69
|
...(section.padding !== undefined ? { padding: section.padding } : {}),
|
|
70
|
+
...(sectionGeometry(geometry, section.orientation) !== geometry
|
|
71
|
+
? { geometry: sectionGeometry(geometry, section.orientation) }
|
|
72
|
+
: {}),
|
|
68
73
|
...(section.columns !== undefined ? { columns: section.columns } : {}),
|
|
69
74
|
...(section.columnGap !== undefined ? { columnGap: section.columnGap } : {}),
|
|
70
75
|
})),
|
|
71
|
-
[sections, prepared],
|
|
76
|
+
[sections, prepared, geometry],
|
|
72
77
|
);
|
|
73
78
|
|
|
74
79
|
const [state, setState] = useState<Measured>(NOT_MEASURED);
|
|
@@ -129,6 +134,7 @@ export function useDocPages(
|
|
|
129
134
|
const chunks: BlockSlice[][] = plan.bySection[sectionIndex] ?? [
|
|
130
135
|
blocks.map((_, index) => ({ index })),
|
|
131
136
|
];
|
|
137
|
+
const turned = sectionGeometry(geometry, section.orientation);
|
|
132
138
|
chunks.forEach((blockSlices, pageIndex) => {
|
|
133
139
|
const blockIndices = blockSlices.map((s) => s.index);
|
|
134
140
|
const noteIndices = blockSlices
|
|
@@ -136,6 +142,7 @@ export function useDocPages(
|
|
|
136
142
|
.map((s) => s.index);
|
|
137
143
|
out.push({
|
|
138
144
|
key: `f${entryIndex}-${pageIndex}`,
|
|
145
|
+
...(turned !== geometry ? { geometry: turned } : {}),
|
|
139
146
|
content: createElement(FlowPage, {
|
|
140
147
|
section,
|
|
141
148
|
design,
|
|
@@ -149,7 +156,7 @@ export function useDocPages(
|
|
|
149
156
|
});
|
|
150
157
|
|
|
151
158
|
return out;
|
|
152
|
-
}, [entries, plan, prepared, design]);
|
|
159
|
+
}, [entries, plan, prepared, design, geometry]);
|
|
153
160
|
|
|
154
161
|
return { pages, measuring, overflowing: plan.overflowing };
|
|
155
162
|
}
|
package/src/app/main.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import { ThemeProvider } from 'next-themes';
|
|
|
2
2
|
import { StrictMode } from 'react';
|
|
3
3
|
import { createRoot } from 'react-dom/client';
|
|
4
4
|
import { App } from './app';
|
|
5
|
+
import { HostBridge } from './components/host-bridge';
|
|
5
6
|
import { LocaleProvider } from './lib/i18n';
|
|
6
7
|
import './styles.css';
|
|
7
8
|
|
|
@@ -10,6 +11,7 @@ createRoot(document.getElementById('root')!).render(
|
|
|
10
11
|
<StrictMode>
|
|
11
12
|
<ThemeProvider attribute="class" defaultTheme="system" enableSystem disableTransitionOnChange>
|
|
12
13
|
<LocaleProvider>
|
|
14
|
+
<HostBridge />
|
|
13
15
|
<App />
|
|
14
16
|
</LocaleProvider>
|
|
15
17
|
</ThemeProvider>
|
package/src/app/routes/doc.tsx
CHANGED
|
@@ -78,6 +78,7 @@ import {
|
|
|
78
78
|
resolveSelection,
|
|
79
79
|
} from '../lib/page-range';
|
|
80
80
|
import { nextFrame, waitForFonts } from '../lib/print-ready';
|
|
81
|
+
import { markDocOpened } from '../lib/recent-docs';
|
|
81
82
|
import { getRecordState, setRecords, useRecordIndex } from '../lib/records';
|
|
82
83
|
import { scanDocument } from '../lib/scan';
|
|
83
84
|
import { pageLang, resolvePageGeometry } from '../lib/sdk';
|
|
@@ -214,7 +215,7 @@ export function Doc() {
|
|
|
214
215
|
const state = useDocModule(docId);
|
|
215
216
|
const doc = state.doc;
|
|
216
217
|
const t = useT();
|
|
217
|
-
const { setLocale } = useLocale();
|
|
218
|
+
const { locale, setLocale } = useLocale();
|
|
218
219
|
|
|
219
220
|
const rootRef = useRef<HTMLDivElement>(null);
|
|
220
221
|
const scrollRef = useRef<HTMLDivElement>(null);
|
|
@@ -262,6 +263,7 @@ export function Doc() {
|
|
|
262
263
|
const editControlsRef = useRef<InspectorControls | null>(null);
|
|
263
264
|
const [textPending, setTextPending] = useState(0);
|
|
264
265
|
const [cardShown, setCardShown] = useState(false);
|
|
266
|
+
const [unsaved, setUnsaved] = useState(false);
|
|
265
267
|
const [isFullscreen, setIsFullscreen] = useState(false);
|
|
266
268
|
const [viewMode, setViewModeState] = useState<ViewMode>(() => readViewMode(docId));
|
|
267
269
|
// The page the reader was on when the layout changed, to put back in view.
|
|
@@ -281,6 +283,27 @@ export function Doc() {
|
|
|
281
283
|
useEffect(() => () => setRecords(undefined), []);
|
|
282
284
|
|
|
283
285
|
const { pages, measuring, overflowing } = useDocPages(doc, geometry);
|
|
286
|
+
|
|
287
|
+
const loaded = Boolean(doc);
|
|
288
|
+
useEffect(() => {
|
|
289
|
+
if (loaded && docId) markDocOpened(docId);
|
|
290
|
+
}, [loaded, docId]);
|
|
291
|
+
|
|
292
|
+
const docTitle = doc ? (doc.meta?.title ?? docId) : undefined;
|
|
293
|
+
const showPage = pages.length > 1 && !measuring;
|
|
294
|
+
// biome-ignore lint/correctness/useExhaustiveDependencies: `t` keeps one identity across languages, so `locale` re-runs it
|
|
295
|
+
useEffect(() => {
|
|
296
|
+
if (!docTitle) return;
|
|
297
|
+
const page = showPage ? ` · ${t('p. {page}', { page: currentPage })}` : '';
|
|
298
|
+
document.title = `${unsaved ? '● ' : ''}${docTitle}${page}`;
|
|
299
|
+
}, [docTitle, showPage, currentPage, unsaved, t, locale]);
|
|
300
|
+
useEffect(
|
|
301
|
+
() => () => {
|
|
302
|
+
document.title = 'open-doc';
|
|
303
|
+
},
|
|
304
|
+
[],
|
|
305
|
+
);
|
|
306
|
+
|
|
284
307
|
const recordIndex = useRecordIndex();
|
|
285
308
|
|
|
286
309
|
// Read again on every reload of the document, so what an agent just wrote
|
|
@@ -1122,7 +1145,7 @@ export function Doc() {
|
|
|
1122
1145
|
key={page.key}
|
|
1123
1146
|
index={index}
|
|
1124
1147
|
total={pages.length}
|
|
1125
|
-
geometry={geometry}
|
|
1148
|
+
geometry={page.geometry ?? geometry}
|
|
1126
1149
|
scale={scale}
|
|
1127
1150
|
design={doc.design}
|
|
1128
1151
|
lang={pageLang(doc.meta)}
|
|
@@ -1152,6 +1175,7 @@ export function Doc() {
|
|
|
1152
1175
|
textCount={textPending}
|
|
1153
1176
|
controlsRef={editControlsRef}
|
|
1154
1177
|
onShownChange={setCardShown}
|
|
1178
|
+
onUnsavedChange={setUnsaved}
|
|
1155
1179
|
/>
|
|
1156
1180
|
)}
|
|
1157
1181
|
{agentActivity && (
|
package/src/app/routes/home.tsx
CHANGED
|
@@ -37,6 +37,7 @@ import { useAgentStatus, useCreateDoc } from '../lib/agent/use-agent';
|
|
|
37
37
|
import { coverContent } from '../lib/doc-preview';
|
|
38
38
|
import { docCreatedAt, docIds, docThemes, docTitles } from '../lib/docs';
|
|
39
39
|
import { type Translate, useLocale, useT } from '../lib/i18n';
|
|
40
|
+
import { readRecentDocs, recentAmong } from '../lib/recent-docs';
|
|
40
41
|
import { pageLang, resolvePageGeometry } from '../lib/sdk';
|
|
41
42
|
import { findTheme } from '../lib/themes';
|
|
42
43
|
import { useDocModule } from '../lib/use-doc-module';
|
|
@@ -80,6 +81,9 @@ function readSort(): SortKey {
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
|
|
84
|
+
const RECENT_COUNT = 4;
|
|
85
|
+
const SECTION_LABEL = 'mb-4 font-medium text-muted-foreground text-xs uppercase tracking-wider';
|
|
86
|
+
|
|
83
87
|
const titleOf = (id: string) => docTitles[id] ?? id;
|
|
84
88
|
|
|
85
89
|
function compare(sort: SortKey) {
|
|
@@ -139,6 +143,15 @@ export function Home() {
|
|
|
139
143
|
})
|
|
140
144
|
.sort(compare(sort));
|
|
141
145
|
}, [sourceIds, filter, sort]);
|
|
146
|
+
// Only where it saves a search: the whole library, not filtered, and big
|
|
147
|
+
// enough that the documents in it no longer fit on one screen.
|
|
148
|
+
const recentIds = useMemo(
|
|
149
|
+
() =>
|
|
150
|
+
ctx.selectedId === ALL_DOCS_ID && !filter.trim() && docIds.length > RECENT_COUNT * 2
|
|
151
|
+
? recentAmong(readRecentDocs(), docIds, RECENT_COUNT)
|
|
152
|
+
: [],
|
|
153
|
+
[ctx.selectedId, filter],
|
|
154
|
+
);
|
|
142
155
|
const currentSort = SORTS.find((entry) => entry.key === sort) ?? SORTS[0];
|
|
143
156
|
|
|
144
157
|
const heading =
|
|
@@ -231,11 +244,32 @@ export function Home() {
|
|
|
231
244
|
{newButton && <div className="mt-4 flex justify-center">{newButton}</div>}
|
|
232
245
|
</EmptyState>
|
|
233
246
|
) : (
|
|
234
|
-
|
|
235
|
-
{
|
|
236
|
-
<
|
|
237
|
-
|
|
238
|
-
|
|
247
|
+
<>
|
|
248
|
+
{recentIds.length > 0 && (
|
|
249
|
+
<section aria-labelledby="od-recent" className="mb-10">
|
|
250
|
+
<h2 id="od-recent" className={SECTION_LABEL}>
|
|
251
|
+
{t('Recently opened')}
|
|
252
|
+
</h2>
|
|
253
|
+
<div className={CARD_GRID}>
|
|
254
|
+
{recentIds.map((id) => (
|
|
255
|
+
<DocCard key={id} docId={id} ctx={ctx} onError={setError} />
|
|
256
|
+
))}
|
|
257
|
+
</div>
|
|
258
|
+
</section>
|
|
259
|
+
)}
|
|
260
|
+
<section aria-labelledby={recentIds.length > 0 ? 'od-all' : undefined}>
|
|
261
|
+
{recentIds.length > 0 && (
|
|
262
|
+
<h2 id="od-all" className={SECTION_LABEL}>
|
|
263
|
+
{t('All documents')}
|
|
264
|
+
</h2>
|
|
265
|
+
)}
|
|
266
|
+
<div className={CARD_GRID}>
|
|
267
|
+
{visibleIds.map((id) => (
|
|
268
|
+
<DocCard key={id} docId={id} ctx={ctx} onError={setError} />
|
|
269
|
+
))}
|
|
270
|
+
</div>
|
|
271
|
+
</section>
|
|
272
|
+
</>
|
|
239
273
|
)}
|
|
240
274
|
{import.meta.env.DEV && (
|
|
241
275
|
<NewDocumentDialog open={creating} folderId={inFolder} onClose={() => setCreating(false)} />
|