@open-document/core 0.11.0 → 0.12.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-BHFGY8eF.js → build-DfUfpeTR.js} +1 -1
- package/dist/{check-UEBmDfT_.js → check-CHxiOkQG.js} +3 -3
- package/dist/cli/bin.js +20 -33
- package/dist/{config-B_pdNbYg.js → config-9IdbhVuT.js} +1402 -675
- package/dist/{context-BM9_-u9P.js → context-BLI1-64_.js} +2 -2
- package/dist/{dev-DX3QMIRi.js → dev-yNYKv5mm.js} +1 -1
- package/dist/{diff-DayvbXfX.js → diff-Bs205mOx.js} +2 -2
- package/dist/{export-BPsXj1i6.js → export-tkquS5O5.js} +11 -4
- package/dist/{import-71wlAsrd.js → import-D1hIKIr3.js} +3 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +63 -28
- package/dist/ops/index.d.ts +111 -2
- package/dist/ops/index.js +3 -3
- package/dist/{ops-BUo67DaP.js → ops-Dgqujq5a.js} +85 -164
- package/dist/package-version-C89gtYSk.js +36 -0
- package/dist/{preview-D3m1-gUL.js → preview-BImdTH6K.js} +1 -1
- package/dist/{sdk-CpDEGRIo.d.ts → sdk-CHEGeINh.d.ts} +46 -1
- package/dist/templates-DT5zzqHq.js +34 -0
- package/dist/vite/index.js +1 -1
- package/package.json +2 -1
- package/skills/apply-comments/SKILL.md +3 -1
- package/skills/create-doc/SKILL.md +2 -0
- package/skills/doc-authoring/SKILL.md +2 -0
- package/src/app/components/browser/browser-ui.tsx +21 -0
- package/src/app/components/browser/new-document-dialog.tsx +208 -0
- package/src/app/components/changes/changes-overlay.tsx +68 -0
- package/src/app/components/changes/changes-panel.tsx +341 -0
- package/src/app/components/changes/use-changes.ts +85 -0
- package/src/app/components/comments/comments-overlay.tsx +50 -0
- package/src/app/components/comments/comments-panel.tsx +272 -0
- package/src/app/components/comments/use-comments.ts +61 -0
- package/src/app/components/doc-sidebar.tsx +32 -2
- package/src/app/components/inspector/field-source.tsx +41 -0
- package/src/app/components/inspector/inspector.tsx +64 -65
- package/src/app/components/overlay-frame.tsx +79 -0
- package/src/app/components/page-frame.tsx +4 -0
- package/src/app/components/page-placement.ts +68 -0
- package/src/app/components/record-picker.tsx +79 -0
- package/src/app/components/themes/theme-preview.tsx +5 -4
- package/src/app/lib/agent-bridge.ts +29 -1
- package/src/app/lib/docx/ooxml.test.ts +24 -1
- package/src/app/lib/docx/ooxml.ts +27 -1
- package/src/app/lib/export-docx.ts +3 -1
- package/src/app/lib/export-dom.ts +2 -1
- package/src/app/lib/export-html.ts +4 -2
- package/src/app/lib/export-image.ts +2 -1
- package/src/app/lib/flow-measure.test.ts +30 -0
- package/src/app/lib/flow-measure.ts +35 -10
- package/src/app/lib/i18n-ja/browser.ts +10 -0
- package/src/app/lib/i18n-ja/doc.ts +4 -0
- package/src/app/lib/i18n-ja/panels.ts +40 -0
- package/src/app/lib/i18n-ko/browser.ts +10 -0
- package/src/app/lib/i18n-ko/doc.ts +4 -0
- package/src/app/lib/i18n-ko/panels.ts +39 -0
- package/src/app/lib/i18n-zh-cn/browser.ts +10 -0
- package/src/app/lib/i18n-zh-cn/doc.ts +4 -0
- package/src/app/lib/i18n-zh-cn/panels.ts +38 -0
- package/src/app/lib/i18n-zh-tw/browser.ts +10 -0
- package/src/app/lib/i18n-zh-tw/doc.ts +4 -0
- package/src/app/lib/i18n-zh-tw/panels.ts +38 -0
- package/src/app/lib/records.test.ts +38 -0
- package/src/app/lib/records.ts +127 -0
- package/src/app/lib/sdk.ts +29 -0
- package/src/app/lib/use-doc-module.ts +7 -0
- package/src/app/lib/use-doc-pages.ts +15 -9
- package/src/app/routes/doc.tsx +274 -13
- package/src/app/routes/home.tsx +30 -5
- package/src/app/styles.css +23 -0
- package/templates/blank/index.tsx +63 -0
- package/templates/blank/template.json +6 -0
- package/templates/certificate/data/recipients.csv +4 -0
- package/templates/certificate/index.tsx +128 -0
- package/templates/certificate/template.json +6 -0
- package/templates/letter/index.tsx +106 -0
- package/templates/letter/template.json +5 -0
- package/templates/meeting-notes/index.tsx +194 -0
- package/templates/meeting-notes/template.json +6 -0
- package/templates/proposal/index.tsx +264 -0
- package/templates/proposal/template.json +6 -0
- package/templates/report/data/metrics.csv +5 -0
- package/templates/report/index.tsx +224 -0
- package/templates/report/template.json +6 -0
|
@@ -11,7 +11,7 @@ import { PAGE_ATTR, PAGE_INDEX_ATTR } from './outline';
|
|
|
11
11
|
import { DocPageProvider } from './page-context';
|
|
12
12
|
import { nextFrame, waitForFonts, waitForImages } from './print-ready';
|
|
13
13
|
import { captureScan, restoreScan, scanDocument } from './scan';
|
|
14
|
-
import type
|
|
14
|
+
import { type DocModule, type PageGeometry, pageLang } from './sdk';
|
|
15
15
|
import { scopeSvgIds } from './svg-ids';
|
|
16
16
|
import type { ExpandedPage } from './use-doc-pages';
|
|
17
17
|
|
|
@@ -52,6 +52,7 @@ export async function withRenderedPages<T>(
|
|
|
52
52
|
const host = document.createElement('div');
|
|
53
53
|
host.setAttribute(PAGE_ATTR, '');
|
|
54
54
|
host.setAttribute(PAGE_INDEX_ATTR, String(i));
|
|
55
|
+
host.setAttribute('lang', pageLang(doc.meta));
|
|
55
56
|
host.style.width = `${geometry.width}px`;
|
|
56
57
|
host.style.height = `${geometry.height}px`;
|
|
57
58
|
if (designVars) {
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
uniqueAssetName,
|
|
13
13
|
} from './export-dom';
|
|
14
14
|
import { PAGE_ATTR, PAGE_INDEX_ATTR } from './outline';
|
|
15
|
-
import { type DocModule, type PageGeometry, resolvePageGeometry } from './sdk';
|
|
15
|
+
import { type DocModule, type PageGeometry, pageLang, resolvePageGeometry } from './sdk';
|
|
16
16
|
import type { ExpandedPage } from './use-doc-pages';
|
|
17
17
|
|
|
18
18
|
type AssetEntry = { name: string; bytes: Uint8Array };
|
|
@@ -61,6 +61,7 @@ export async function buildDocHtmlBundle(
|
|
|
61
61
|
|
|
62
62
|
const html = buildHtml({
|
|
63
63
|
title,
|
|
64
|
+
lang: pageLang(doc.meta),
|
|
64
65
|
geometry,
|
|
65
66
|
design: doc.design,
|
|
66
67
|
pagesHtml: pagesHtml.map((page) => rewriteUrls(page, assets, 'html')),
|
|
@@ -112,6 +113,7 @@ function rewriteUrls(
|
|
|
112
113
|
|
|
113
114
|
function buildHtml(opts: {
|
|
114
115
|
title: string;
|
|
116
|
+
lang: string;
|
|
115
117
|
geometry: PageGeometry;
|
|
116
118
|
design: DocModule['design'];
|
|
117
119
|
pagesHtml: string[];
|
|
@@ -133,7 +135,7 @@ function buildHtml(opts: {
|
|
|
133
135
|
.join('\n');
|
|
134
136
|
|
|
135
137
|
return `<!doctype html>
|
|
136
|
-
<html lang="
|
|
138
|
+
<html lang="${escapeAttr(opts.lang)}">
|
|
137
139
|
<head>
|
|
138
140
|
<meta charset="utf-8">
|
|
139
141
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
toAbsolute,
|
|
21
21
|
} from './export-dom';
|
|
22
22
|
import { PAGE_ATTR } from './outline';
|
|
23
|
-
import { type DocModule, type PageGeometry, resolvePageGeometry } from './sdk';
|
|
23
|
+
import { type DocModule, type PageGeometry, pageLang, resolvePageGeometry } from './sdk';
|
|
24
24
|
import type { ExpandedPage } from './use-doc-pages';
|
|
25
25
|
|
|
26
26
|
export type ImageFormat = 'png' | 'svg';
|
|
@@ -186,6 +186,7 @@ function buildSvg(pageHtml: string, css: string, geometry: Box, doc: DocModule):
|
|
|
186
186
|
const content = document.createElementNS(XHTML_NS, 'div');
|
|
187
187
|
content.setAttribute('style', 'width:100%;height:100%');
|
|
188
188
|
content.setAttribute(PAGE_ATTR, '');
|
|
189
|
+
content.setAttribute('lang', pageLang(doc.meta));
|
|
189
190
|
content.innerHTML = pageHtml;
|
|
190
191
|
wrapper.appendChild(content);
|
|
191
192
|
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { metricsFor } from './flow-measure';
|
|
3
|
+
|
|
4
|
+
/** Just what `metricsFor` reads of a block's wrapper. */
|
|
5
|
+
function block(inner: { tagName: string; attrs?: Record<string, string> } | null): HTMLElement {
|
|
6
|
+
return {
|
|
7
|
+
firstElementChild: inner && {
|
|
8
|
+
tagName: inner.tagName,
|
|
9
|
+
getAttribute: (name: string) => inner.attrs?.[name] ?? null,
|
|
10
|
+
},
|
|
11
|
+
} as unknown as HTMLElement;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
describe('metricsFor', () => {
|
|
15
|
+
it('treats a block that renders nothing as plain, not as a page break', () => {
|
|
16
|
+
expect(metricsFor(block(null), 0, 0)).toMatchObject({
|
|
17
|
+
breakBefore: false,
|
|
18
|
+
keepWithNext: false,
|
|
19
|
+
keepWithPrevious: false,
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('glues a heading to what follows, and reads declared breaks', () => {
|
|
24
|
+
expect(metricsFor(block({ tagName: 'H2' }), 20, 0).keepWithNext).toBe(true);
|
|
25
|
+
expect(
|
|
26
|
+
metricsFor(block({ tagName: 'DIV', attrs: { 'data-od-break-before': '' } }), 20, 0)
|
|
27
|
+
.breakBefore,
|
|
28
|
+
).toBe(true);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createElement, type ReactNode } from 'react';
|
|
2
|
+
import { flushSync } from 'react-dom';
|
|
2
3
|
import { createRoot } from 'react-dom/client';
|
|
3
4
|
import { FLOW_BLOCK_ATTR, FlowBlock } from '../components/flow-page';
|
|
4
5
|
import { FOOTNOTE_AREA_MARGIN_TOP, FOOTNOTE_ROW_ATTR, Footnotes } from '../components/footnote';
|
|
@@ -18,12 +19,15 @@ export type MeasurableSection = {
|
|
|
18
19
|
padding?: number;
|
|
19
20
|
};
|
|
20
21
|
|
|
21
|
-
function metricsFor(el: HTMLElement, height: number, footnoteHeight: number): BlockMetrics {
|
|
22
|
+
export function metricsFor(el: HTMLElement, height: number, footnoteHeight: number): BlockMetrics {
|
|
22
23
|
const inner = el.firstElementChild;
|
|
23
24
|
const tag = inner?.tagName ?? '';
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
// `?? null`: a block that renders nothing has no child, and `undefined`
|
|
26
|
+
// would pass every `!== null` below — an empty block then broke the page
|
|
27
|
+
// before it and glued itself to the next.
|
|
28
|
+
const declaredKeepNext = inner?.getAttribute('data-od-keep-with-next') ?? null;
|
|
29
|
+
const declaredKeepPrev = inner?.getAttribute('data-od-keep-with-previous') ?? null;
|
|
30
|
+
const declaredBreak = inner?.getAttribute('data-od-break-before') ?? null;
|
|
27
31
|
|
|
28
32
|
return {
|
|
29
33
|
height,
|
|
@@ -73,7 +77,7 @@ function stackedHeights(container: HTMLElement, selector: string): number[] {
|
|
|
73
77
|
*/
|
|
74
78
|
export async function measureFlowSections(
|
|
75
79
|
sections: MeasurableSection[],
|
|
76
|
-
opts: { geometry: PageGeometry; design?: DesignSystem },
|
|
80
|
+
opts: { geometry: PageGeometry; design?: DesignSystem; lang?: string },
|
|
77
81
|
): Promise<FlowMeasurement[]> {
|
|
78
82
|
if (sections.length === 0) return [];
|
|
79
83
|
|
|
@@ -82,6 +86,9 @@ export async function measureFlowSections(
|
|
|
82
86
|
// The sheet's own element styles (styles.css) apply here too, so a block
|
|
83
87
|
// measures as it will print.
|
|
84
88
|
host.setAttribute('data-od-measure', '');
|
|
89
|
+
// Where a line breaks depends on the language, so it is measured in the one
|
|
90
|
+
// it prints in.
|
|
91
|
+
host.setAttribute('lang', opts.lang ?? 'en');
|
|
85
92
|
Object.assign(host.style, {
|
|
86
93
|
position: 'fixed',
|
|
87
94
|
left: '-99999px',
|
|
@@ -112,16 +119,23 @@ export async function measureFlowSections(
|
|
|
112
119
|
};
|
|
113
120
|
|
|
114
121
|
try {
|
|
122
|
+
// Out of the effect that called us, so `flushSync` below may commit.
|
|
123
|
+
await Promise.resolve();
|
|
115
124
|
for (const section of sections) {
|
|
116
125
|
const width = opts.geometry.width - paddingOf(section) * 2;
|
|
117
126
|
|
|
118
127
|
const blocks = makeContainer(width);
|
|
119
128
|
blockContainers.push(blocks);
|
|
120
129
|
const blockRoot = createRoot(blocks);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
130
|
+
// Committed now, not on React's schedule: on a slow machine a render
|
|
131
|
+
// left to finish on its own was still empty when the frames below had
|
|
132
|
+
// passed, the section measured as no blocks, and it printed as no pages.
|
|
133
|
+
flushSync(() =>
|
|
134
|
+
blockRoot.render(
|
|
135
|
+
section.blocks.map((block, index) =>
|
|
136
|
+
createElement(FlowBlock, { key: index }, block),
|
|
137
|
+
) as unknown as Parameters<typeof blockRoot.render>[0],
|
|
138
|
+
),
|
|
125
139
|
);
|
|
126
140
|
roots.push(blockRoot);
|
|
127
141
|
|
|
@@ -133,13 +147,24 @@ export async function measureFlowSections(
|
|
|
133
147
|
const notes = makeContainer(width);
|
|
134
148
|
noteContainers.push(notes);
|
|
135
149
|
const noteRoot = createRoot(notes);
|
|
136
|
-
noteRoot.render(createElement(Footnotes, { notes: allNotes }));
|
|
150
|
+
flushSync(() => noteRoot.render(createElement(Footnotes, { notes: allNotes })));
|
|
137
151
|
roots.push(noteRoot);
|
|
138
152
|
}
|
|
139
153
|
|
|
140
154
|
await nextFrame();
|
|
141
155
|
await waitForFonts();
|
|
142
156
|
await nextFrame();
|
|
157
|
+
// Every block has its wrapper before anything is read: a short count would
|
|
158
|
+
// be packed as a short section.
|
|
159
|
+
for (let frame = 0; frame < 60; frame++) {
|
|
160
|
+
const complete = sections.every(
|
|
161
|
+
(section, index) =>
|
|
162
|
+
(blockContainers[index]?.querySelectorAll(`:scope > [${FLOW_BLOCK_ATTR}]`).length ?? 0) >=
|
|
163
|
+
section.blocks.length,
|
|
164
|
+
);
|
|
165
|
+
if (complete) break;
|
|
166
|
+
await nextFrame();
|
|
167
|
+
}
|
|
143
168
|
|
|
144
169
|
return sections.map((section, sectionIndex) => {
|
|
145
170
|
const padding = paddingOf(section);
|
|
@@ -85,4 +85,14 @@ export const BROWSER: Record<string, string> = {
|
|
|
85
85
|
'Light theme': 'ライトテーマ',
|
|
86
86
|
'Dark theme': 'ダークテーマ',
|
|
87
87
|
'System theme': 'システムテーマ',
|
|
88
|
+
'New document': '新しいドキュメント',
|
|
89
|
+
Template: 'テンプレート',
|
|
90
|
+
'This workspace': 'このワークスペース',
|
|
91
|
+
Create: '作成',
|
|
92
|
+
'Could not create the document': 'ドキュメントを作成できませんでした',
|
|
93
|
+
Blank: '白紙',
|
|
94
|
+
Report: 'レポート',
|
|
95
|
+
Proposal: '提案書',
|
|
96
|
+
'Meeting notes': '議事録',
|
|
97
|
+
Letter: 'レター',
|
|
88
98
|
};
|
|
@@ -148,4 +148,44 @@ export const PANELS: Record<string, string> = {
|
|
|
148
148
|
Done: '完了',
|
|
149
149
|
'{count} elements print from this line of source':
|
|
150
150
|
'このソース行から {count} 個の要素が出力されます',
|
|
151
|
+
Changes: '変更',
|
|
152
|
+
'Changes ({count})': '変更({count})',
|
|
153
|
+
'Changes since the last commit': '前回のコミット以降の変更',
|
|
154
|
+
'Close the changes panel': '変更パネルを閉じる',
|
|
155
|
+
'Show changes since the last commit': '前回のコミット以降の変更を表示',
|
|
156
|
+
'Previous change': '前の変更',
|
|
157
|
+
'Next change': '次の変更',
|
|
158
|
+
Since: '比較',
|
|
159
|
+
'Compare with': '比較対象',
|
|
160
|
+
'Last commit': '前回のコミット',
|
|
161
|
+
'git is not installed': 'git がインストールされていません',
|
|
162
|
+
'Not a git repository': 'git リポジトリではありません',
|
|
163
|
+
'No changes': '変更はありません',
|
|
164
|
+
'Page {page}, changed': '{page} ページ(変更あり)',
|
|
165
|
+
Files: 'ファイル',
|
|
166
|
+
'Revert this change': 'この変更を元に戻す',
|
|
167
|
+
'that change is no longer there — reload the changes':
|
|
168
|
+
'この変更はもうありません。変更を再読み込みしてください',
|
|
169
|
+
'the file changed since the diff was read': '差分を読んだ後にファイルが変更されました',
|
|
170
|
+
'reverting this change alone would break the source — revert the changes around it too':
|
|
171
|
+
'この変更だけを戻すとソースが壊れます。周辺の変更も一緒に戻してください',
|
|
172
|
+
'a binary file cannot be reverted here': 'バイナリファイルはここでは元に戻せません',
|
|
173
|
+
'this workspace is not under git': 'このワークスペースは git で管理されていません',
|
|
174
|
+
Comments: 'コメント',
|
|
175
|
+
'Comments ({count})': 'コメント({count})',
|
|
176
|
+
'Close the comments panel': 'コメントパネルを閉じる',
|
|
177
|
+
'Show comments': 'コメントを表示',
|
|
178
|
+
'New comment': '新しいコメント',
|
|
179
|
+
Resolve: '解決済みにする',
|
|
180
|
+
'Copy request for the agent': 'エージェントへの依頼をコピー',
|
|
181
|
+
'No comments': 'コメントはありません',
|
|
182
|
+
'p.{page}': '{page} ページ',
|
|
183
|
+
'Page {page}, with comments': '{page} ページ(コメントあり)',
|
|
184
|
+
'Could not resolve the comment': '解決済みにできませんでした',
|
|
185
|
+
'Pick an element on the page': 'ページ上の要素を選択',
|
|
186
|
+
'Click the element to comment on · Esc to cancel':
|
|
187
|
+
'コメントする要素をクリック · Esc でキャンセル',
|
|
188
|
+
Records: 'レコード',
|
|
189
|
+
'Row {row} of {count}': '{count} 行中 {row} 行目',
|
|
190
|
+
'Esc to deselect': 'Esc で選択解除',
|
|
151
191
|
};
|
|
@@ -84,4 +84,14 @@ export const BROWSER: Record<string, string> = {
|
|
|
84
84
|
'Light theme': '라이트 테마',
|
|
85
85
|
'Dark theme': '다크 테마',
|
|
86
86
|
'System theme': '시스템 테마',
|
|
87
|
+
'New document': '새 문서',
|
|
88
|
+
Template: '템플릿',
|
|
89
|
+
'This workspace': '이 작업 공간',
|
|
90
|
+
Create: '만들기',
|
|
91
|
+
'Could not create the document': '문서를 만들 수 없습니다',
|
|
92
|
+
Blank: '빈 문서',
|
|
93
|
+
Report: '보고서',
|
|
94
|
+
Proposal: '제안서',
|
|
95
|
+
'Meeting notes': '회의록',
|
|
96
|
+
Letter: '서신',
|
|
87
97
|
};
|
|
@@ -145,4 +145,43 @@ export const PANELS: Record<string, string> = {
|
|
|
145
145
|
'Custom font': '사용자 지정 글꼴',
|
|
146
146
|
Done: '완료',
|
|
147
147
|
'{count} elements print from this line of source': '이 소스 줄에서 {count}개의 요소가 출력됩니다',
|
|
148
|
+
Changes: '변경 사항',
|
|
149
|
+
'Changes ({count})': '변경 사항({count})',
|
|
150
|
+
'Changes since the last commit': '마지막 커밋 이후 변경 사항',
|
|
151
|
+
'Close the changes panel': '변경 사항 패널 닫기',
|
|
152
|
+
'Show changes since the last commit': '마지막 커밋 이후 변경 사항 표시',
|
|
153
|
+
'Previous change': '이전 변경',
|
|
154
|
+
'Next change': '다음 변경',
|
|
155
|
+
Since: '비교',
|
|
156
|
+
'Compare with': '비교 대상',
|
|
157
|
+
'Last commit': '마지막 커밋',
|
|
158
|
+
'git is not installed': 'git이 설치되어 있지 않습니다',
|
|
159
|
+
'Not a git repository': 'git 저장소가 아닙니다',
|
|
160
|
+
'No changes': '변경 사항 없음',
|
|
161
|
+
'Page {page}, changed': '{page}페이지, 변경됨',
|
|
162
|
+
Files: '파일',
|
|
163
|
+
'Revert this change': '이 변경 되돌리기',
|
|
164
|
+
'that change is no longer there — reload the changes':
|
|
165
|
+
'이 변경은 더 이상 없습니다. 변경 사항을 다시 불러오세요',
|
|
166
|
+
'the file changed since the diff was read': '차이를 읽은 뒤 파일이 변경되었습니다',
|
|
167
|
+
'reverting this change alone would break the source — revert the changes around it too':
|
|
168
|
+
'이 변경만 되돌리면 소스가 깨집니다. 주변 변경도 함께 되돌리세요',
|
|
169
|
+
'a binary file cannot be reverted here': '바이너리 파일은 여기서 되돌릴 수 없습니다',
|
|
170
|
+
'this workspace is not under git': '이 작업 공간은 git으로 관리되지 않습니다',
|
|
171
|
+
Comments: '댓글',
|
|
172
|
+
'Comments ({count})': '댓글({count})',
|
|
173
|
+
'Close the comments panel': '댓글 패널 닫기',
|
|
174
|
+
'Show comments': '댓글 표시',
|
|
175
|
+
'New comment': '새 댓글',
|
|
176
|
+
Resolve: '해결됨으로 표시',
|
|
177
|
+
'Copy request for the agent': '에이전트 요청 복사',
|
|
178
|
+
'No comments': '댓글 없음',
|
|
179
|
+
'p.{page}': '{page}쪽',
|
|
180
|
+
'Page {page}, with comments': '{page}페이지, 댓글 있음',
|
|
181
|
+
'Could not resolve the comment': '해결됨으로 표시할 수 없습니다',
|
|
182
|
+
'Pick an element on the page': '페이지에서 요소 선택',
|
|
183
|
+
'Click the element to comment on · Esc to cancel': '댓글을 남길 요소를 클릭 · Esc로 취소',
|
|
184
|
+
Records: '레코드',
|
|
185
|
+
'Row {row} of {count}': '{count}행 중 {row}행',
|
|
186
|
+
'Esc to deselect': 'Esc로 선택 해제',
|
|
148
187
|
};
|
|
@@ -81,4 +81,14 @@ export const BROWSER: Record<string, string> = {
|
|
|
81
81
|
'Light theme': '浅色主题',
|
|
82
82
|
'Dark theme': '深色主题',
|
|
83
83
|
'System theme': '跟随系统主题',
|
|
84
|
+
'New document': '新建文档',
|
|
85
|
+
Template: '模板',
|
|
86
|
+
'This workspace': '这个工作区',
|
|
87
|
+
Create: '创建',
|
|
88
|
+
'Could not create the document': '无法创建文档',
|
|
89
|
+
Blank: '空白',
|
|
90
|
+
Report: '报告',
|
|
91
|
+
Proposal: '提案',
|
|
92
|
+
'Meeting notes': '会议记录',
|
|
93
|
+
Letter: '信函',
|
|
84
94
|
};
|
|
@@ -140,4 +140,42 @@ export const PANELS: Record<string, string> = {
|
|
|
140
140
|
'Custom font': '自定义字体',
|
|
141
141
|
Done: '完成',
|
|
142
142
|
'{count} elements print from this line of source': '这一行源码输出 {count} 个元素',
|
|
143
|
+
Changes: '变更',
|
|
144
|
+
'Changes ({count})': '变更({count})',
|
|
145
|
+
'Changes since the last commit': '上次 commit 之后的变更',
|
|
146
|
+
'Close the changes panel': '关闭变更面板',
|
|
147
|
+
'Show changes since the last commit': '显示上次 commit 之后的变更',
|
|
148
|
+
'Previous change': '上一个变更',
|
|
149
|
+
'Next change': '下一个变更',
|
|
150
|
+
Since: '比较',
|
|
151
|
+
'Compare with': '比较对象',
|
|
152
|
+
'Last commit': '上次 commit',
|
|
153
|
+
'git is not installed': '没有安装 git',
|
|
154
|
+
'Not a git repository': '不是 git 仓库',
|
|
155
|
+
'No changes': '没有变更',
|
|
156
|
+
'Page {page}, changed': '第 {page} 页,有变更',
|
|
157
|
+
Files: '文件',
|
|
158
|
+
'Revert this change': '还原这个变更',
|
|
159
|
+
'that change is no longer there — reload the changes': '这个变更已经不在了,请重新加载变更',
|
|
160
|
+
'the file changed since the diff was read': '读取差异之后文件又被改过了',
|
|
161
|
+
'reverting this change alone would break the source — revert the changes around it too':
|
|
162
|
+
'单独还原这个变更会让源码出错,请连同周围的变更一起还原',
|
|
163
|
+
'a binary file cannot be reverted here': '二进制文件无法在这里还原',
|
|
164
|
+
'this workspace is not under git': '这个工作区没有使用 git',
|
|
165
|
+
Comments: '评论',
|
|
166
|
+
'Comments ({count})': '评论({count})',
|
|
167
|
+
'Close the comments panel': '关闭评论面板',
|
|
168
|
+
'Show comments': '显示评论',
|
|
169
|
+
'New comment': '新建评论',
|
|
170
|
+
Resolve: '标为已解决',
|
|
171
|
+
'Copy request for the agent': '复制给 Agent 的指令',
|
|
172
|
+
'No comments': '没有评论',
|
|
173
|
+
'p.{page}': '第 {page} 页',
|
|
174
|
+
'Page {page}, with comments': '第 {page} 页,有评论',
|
|
175
|
+
'Could not resolve the comment': '无法标为已解决',
|
|
176
|
+
'Pick an element on the page': '在页面上点选元素',
|
|
177
|
+
'Click the element to comment on · Esc to cancel': '点选要评论的元素 · Esc 取消',
|
|
178
|
+
Records: '数据',
|
|
179
|
+
'Row {row} of {count}': '第 {row} 行,共 {count} 行',
|
|
180
|
+
'Esc to deselect': 'Esc 取消选取',
|
|
143
181
|
};
|
|
@@ -81,4 +81,14 @@ export const BROWSER: Record<string, string> = {
|
|
|
81
81
|
'Light theme': '淺色主題',
|
|
82
82
|
'Dark theme': '深色主題',
|
|
83
83
|
'System theme': '系統主題',
|
|
84
|
+
'New document': '新增文件',
|
|
85
|
+
Template: '範本',
|
|
86
|
+
'This workspace': '這個工作區',
|
|
87
|
+
Create: '建立',
|
|
88
|
+
'Could not create the document': '無法建立文件',
|
|
89
|
+
Blank: '空白',
|
|
90
|
+
Report: '報告',
|
|
91
|
+
Proposal: '提案',
|
|
92
|
+
'Meeting notes': '會議紀錄',
|
|
93
|
+
Letter: '信函',
|
|
84
94
|
};
|
|
@@ -141,4 +141,42 @@ export const PANELS: Record<string, string> = {
|
|
|
141
141
|
'Custom font': '自訂字型',
|
|
142
142
|
Done: '完成',
|
|
143
143
|
'{count} elements print from this line of source': '這一行原始碼印出 {count} 個元素',
|
|
144
|
+
Changes: '變更',
|
|
145
|
+
'Changes ({count})': '變更({count})',
|
|
146
|
+
'Changes since the last commit': '上次 commit 之後的變更',
|
|
147
|
+
'Close the changes panel': '關閉變更面板',
|
|
148
|
+
'Show changes since the last commit': '顯示上次 commit 之後的變更',
|
|
149
|
+
'Previous change': '上一個變更',
|
|
150
|
+
'Next change': '下一個變更',
|
|
151
|
+
Since: '比較',
|
|
152
|
+
'Compare with': '比較對象',
|
|
153
|
+
'Last commit': '上次 commit',
|
|
154
|
+
'git is not installed': '沒有安裝 git',
|
|
155
|
+
'Not a git repository': '不是 git 儲存庫',
|
|
156
|
+
'No changes': '沒有變更',
|
|
157
|
+
'Page {page}, changed': '第 {page} 頁,有變更',
|
|
158
|
+
Files: '檔案',
|
|
159
|
+
'Revert this change': '還原這個變更',
|
|
160
|
+
'that change is no longer there — reload the changes': '這個變更已經不在了,請重新載入變更',
|
|
161
|
+
'the file changed since the diff was read': '讀取差異之後檔案又被改過了',
|
|
162
|
+
'reverting this change alone would break the source — revert the changes around it too':
|
|
163
|
+
'單獨還原這個變更會讓原始碼出錯,請連同周圍的變更一起還原',
|
|
164
|
+
'a binary file cannot be reverted here': '二進位檔無法在這裡還原',
|
|
165
|
+
'this workspace is not under git': '這個工作區沒有使用 git',
|
|
166
|
+
Comments: '留言',
|
|
167
|
+
'Comments ({count})': '留言({count})',
|
|
168
|
+
'Close the comments panel': '關閉留言面板',
|
|
169
|
+
'Show comments': '顯示留言',
|
|
170
|
+
'New comment': '新增留言',
|
|
171
|
+
Resolve: '標為已解決',
|
|
172
|
+
'Copy request for the agent': '複製給 Agent 的指令',
|
|
173
|
+
'No comments': '沒有留言',
|
|
174
|
+
'p.{page}': '第 {page} 頁',
|
|
175
|
+
'Page {page}, with comments': '第 {page} 頁,有留言',
|
|
176
|
+
'Could not resolve the comment': '無法標為已解決',
|
|
177
|
+
'Pick an element on the page': '在頁面上點選元素',
|
|
178
|
+
'Click the element to comment on · Esc to cancel': '點選要留言的元素 · Esc 取消',
|
|
179
|
+
Records: '資料',
|
|
180
|
+
'Row {row} of {count}': '第 {row} 列,共 {count} 列',
|
|
181
|
+
'Esc to deselect': 'Esc 取消選取',
|
|
144
182
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import { getRecordState, recordFileName, recordLabel, setRecordIndex, setRecords } from './records';
|
|
3
|
+
|
|
4
|
+
describe('recordFileName', () => {
|
|
5
|
+
const row = { name: 'Lin Mei', company: 'Acme / Asia', score: 92 };
|
|
6
|
+
|
|
7
|
+
it('fills columns and the row number', () => {
|
|
8
|
+
expect(recordFileName('certificate-{name}', row, 2, 120)).toBe('certificate-Lin Mei');
|
|
9
|
+
expect(recordFileName('{#}-{company}', row, 2, 120)).toBe('003-Acme - Asia');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('numbers a pattern without placeholders, so each row gets its own file', () => {
|
|
13
|
+
expect(recordFileName('awards', row, 0, 9)).toBe('awards-1');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('falls back to the number when the pattern fills to nothing', () => {
|
|
17
|
+
expect(recordFileName('{missing}', row, 4, 12)).toBe('05');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
describe('recordLabel', () => {
|
|
22
|
+
it('uses the named column, else the first value', () => {
|
|
23
|
+
expect(recordLabel({ id: '', name: 'Ada' }, 0)).toBe('Ada');
|
|
24
|
+
expect(recordLabel({ id: 'x7', name: 'Ada' }, 0, 'name')).toBe('Ada');
|
|
25
|
+
expect(recordLabel(undefined, 3)).toBe('4');
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
describe('the record store', () => {
|
|
30
|
+
it('keeps the index inside the rows', () => {
|
|
31
|
+
setRecords([{ a: 1 }, { a: 2 }], 5);
|
|
32
|
+
expect(getRecordState().index).toBe(1);
|
|
33
|
+
setRecordIndex(-3);
|
|
34
|
+
expect(getRecordState().index).toBe(0);
|
|
35
|
+
setRecords(undefined);
|
|
36
|
+
expect(getRecordState()).toEqual({ records: [], index: 0 });
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { createElement, type ReactNode, useSyncExternalStore } from 'react';
|
|
2
|
+
|
|
3
|
+
/** One row of a document's `records` — usually a line of an imported `.csv`. */
|
|
4
|
+
export type DataRecord = Record<string, unknown>;
|
|
5
|
+
|
|
6
|
+
// Shared through globalThis for the same reason as the outline store: the
|
|
7
|
+
// viewer and the exporters set the record from the source copy of this module,
|
|
8
|
+
// while a document's `useRecord()` and `<Field>` read it from the published
|
|
9
|
+
// bundle. Two stores would mean pages that never change record.
|
|
10
|
+
const GLOBAL_KEY = '__open_doc_record_store__';
|
|
11
|
+
type RecordStore = {
|
|
12
|
+
records: DataRecord[];
|
|
13
|
+
index: number;
|
|
14
|
+
listeners: Set<() => void>;
|
|
15
|
+
};
|
|
16
|
+
type GlobalWithStore = typeof globalThis & { [GLOBAL_KEY]?: RecordStore };
|
|
17
|
+
const g = globalThis as GlobalWithStore;
|
|
18
|
+
if (!g[GLOBAL_KEY]) g[GLOBAL_KEY] = { records: [], index: 0, listeners: new Set() };
|
|
19
|
+
const store = g[GLOBAL_KEY];
|
|
20
|
+
|
|
21
|
+
const notify = () => {
|
|
22
|
+
for (const listener of store.listeners) listener();
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** The rows the open document prints from, or none — the viewer sets this as a document loads. */
|
|
26
|
+
export function setRecords(records: DataRecord[] | undefined, index = 0): void {
|
|
27
|
+
const next = Array.isArray(records) ? records : [];
|
|
28
|
+
const at = Math.min(Math.max(0, index), Math.max(0, next.length - 1));
|
|
29
|
+
if (store.records === next && store.index === at) return;
|
|
30
|
+
store.records = next;
|
|
31
|
+
store.index = at;
|
|
32
|
+
notify();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function setRecordIndex(index: number): void {
|
|
36
|
+
const at = Math.min(Math.max(0, index), Math.max(0, store.records.length - 1));
|
|
37
|
+
if (store.index === at) return;
|
|
38
|
+
store.index = at;
|
|
39
|
+
notify();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function getRecordState(): { records: DataRecord[]; index: number } {
|
|
43
|
+
return { records: store.records, index: store.index };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function subscribe(listener: () => void): () => void {
|
|
47
|
+
store.listeners.add(listener);
|
|
48
|
+
return () => store.listeners.delete(listener);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const getIndex = () => store.index;
|
|
52
|
+
const getCount = () => store.records.length;
|
|
53
|
+
const getCurrent = (): DataRecord | undefined => store.records[store.index];
|
|
54
|
+
|
|
55
|
+
export function useRecordIndex(): number {
|
|
56
|
+
return useSyncExternalStore(subscribe, getIndex, getIndex);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function useRecordCount(): number {
|
|
60
|
+
return useSyncExternalStore(subscribe, getCount, getCount);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* The row this copy of the document is printed for. A document that exports
|
|
65
|
+
* `records` is laid out once per row; every page reads the same one. Outside a
|
|
66
|
+
* document with records — a card in the document list — it is `undefined`.
|
|
67
|
+
*/
|
|
68
|
+
export function useRecord<T extends DataRecord = DataRecord>(): T | undefined {
|
|
69
|
+
return useSyncExternalStore(subscribe, getCurrent, getCurrent) as T | undefined;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export type FieldProps = {
|
|
73
|
+
/** The column to print. */
|
|
74
|
+
name: string;
|
|
75
|
+
/** Printed when the row has no value for it. */
|
|
76
|
+
fallback?: ReactNode;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* One value of the current row, as text. Where no row is set — a document
|
|
81
|
+
* card, a theme preview — it prints the column's name in guillemets, so the
|
|
82
|
+
* layout still shows what goes where.
|
|
83
|
+
*/
|
|
84
|
+
export function Field({ name, fallback }: FieldProps) {
|
|
85
|
+
const record = useRecord();
|
|
86
|
+
if (!record) return createElement('span', { style: { opacity: 0.55 } }, `‹${name}›`);
|
|
87
|
+
const value = record[name];
|
|
88
|
+
if (value === null || value === undefined || value === '') {
|
|
89
|
+
return fallback === undefined ? null : createElement('span', null, fallback);
|
|
90
|
+
}
|
|
91
|
+
return createElement('span', null, String(value));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** How a row is named in the viewer's picker: the chosen column, else the first non-empty one. */
|
|
95
|
+
export function recordLabel(record: DataRecord | undefined, index: number, key?: string): string {
|
|
96
|
+
if (!record) return String(index + 1);
|
|
97
|
+
const value = key ? record[key] : Object.values(record).find((v) => v !== '' && v != null);
|
|
98
|
+
return value === undefined || value === null || value === '' ? String(index + 1) : String(value);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// Characters no file system takes in a name, and the separators.
|
|
102
|
+
const UNSAFE = /[\\/:*?"<>|\p{Cc}]+/gu;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* A file name for one row: `{column}` takes the row's value and `{#}` its
|
|
106
|
+
* 1-based number, padded to the width of the count. A pattern-free name gets
|
|
107
|
+
* the number appended, so every row still lands in its own file.
|
|
108
|
+
*/
|
|
109
|
+
export function recordFileName(
|
|
110
|
+
pattern: string,
|
|
111
|
+
record: DataRecord | undefined,
|
|
112
|
+
index: number,
|
|
113
|
+
count: number,
|
|
114
|
+
): string {
|
|
115
|
+
const number = String(index + 1).padStart(String(count).length, '0');
|
|
116
|
+
const filled = pattern.replace(/\{([^{}]+)\}/g, (_, key: string) =>
|
|
117
|
+
key === '#' ? number : String(record?.[key.trim()] ?? ''),
|
|
118
|
+
);
|
|
119
|
+
const named = /\{[^{}]+\}/.test(pattern) ? filled : `${filled}-${number}`;
|
|
120
|
+
return (
|
|
121
|
+
named
|
|
122
|
+
.replace(UNSAFE, '-')
|
|
123
|
+
.replace(/\s+/g, ' ')
|
|
124
|
+
.replace(/^[\s.-]+|[\s.-]+$/g, '')
|
|
125
|
+
.slice(0, 120) || number
|
|
126
|
+
);
|
|
127
|
+
}
|