@open-document/core 0.17.1 → 0.17.3

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.
Files changed (37) hide show
  1. package/dist/{build-C7nHUUXO.js → build-CryLx-8O.js} +1 -1
  2. package/dist/{check--Cbkdqw3.js → check-BU86QFnH.js} +3 -3
  3. package/dist/cli/bin.js +11 -11
  4. package/dist/{context-DRXgt6Je.js → context-DHCqEAue.js} +1 -1
  5. package/dist/{dev-D_j2ykSa.js → dev-Dmi2PnqI.js} +1 -1
  6. package/dist/{diff-C1RDK_I5.js → diff-HVSJapV4.js} +2 -2
  7. package/dist/{export-BFxKPa0W.js → export-CDobz0UO.js} +3 -3
  8. package/dist/{import-TLuMXkou.js → import-BUHNpf-a.js} +3 -3
  9. package/dist/ops/index.js +2 -2
  10. package/dist/{ops-BG9hfBwQ.js → ops-DKEhE_su.js} +1 -1
  11. package/dist/{preview-rlMPuRZV.js → preview-Do-31RB6.js} +1 -1
  12. package/dist/{proofread-Dtj9OlWX.js → proofread-C0crhm3C.js} +3 -3
  13. package/dist/{session-CPFLe6BT.js → session-CcIBEiIB.js} +168 -110
  14. package/dist/{templates-BmSuBmj3.js → templates-hcl2pb6n.js} +3 -3
  15. package/dist/{translations-BmTXOhx9.js → translations-x2NwYrcj.js} +2 -2
  16. package/dist/vite/index.js +1 -1
  17. package/package.json +1 -1
  18. package/skills/doc-authoring/SKILL.md +10 -12
  19. package/src/app/components/agent/transcript.tsx +2 -4
  20. package/src/app/components/comments/comments-panel.tsx +9 -5
  21. package/src/app/components/doc-assets.tsx +9 -5
  22. package/src/app/lib/ask.ts +113 -0
  23. package/src/app/lib/clipboard.ts +26 -0
  24. package/src/app/lib/export-pdf.ts +18 -0
  25. package/src/app/lib/host.ts +4 -1
  26. package/src/app/lib/i18n-ja/browser.ts +1 -0
  27. package/src/app/lib/i18n-ja/doc.ts +11 -0
  28. package/src/app/lib/i18n-ko/browser.ts +1 -0
  29. package/src/app/lib/i18n-ko/doc.ts +9 -0
  30. package/src/app/lib/i18n-zh-cn/browser.ts +1 -0
  31. package/src/app/lib/i18n-zh-cn/doc.ts +9 -0
  32. package/src/app/lib/i18n-zh-tw/browser.ts +1 -0
  33. package/src/app/lib/i18n-zh-tw/doc.ts +9 -0
  34. package/src/app/lib/toast.ts +16 -2
  35. package/src/app/routes/assets.tsx +19 -12
  36. package/src/app/routes/doc.tsx +78 -20
  37. package/src/app/routes/home.tsx +16 -12
@@ -8,7 +8,9 @@ import {
8
8
  isPreviewable,
9
9
  listAssets,
10
10
  } from '../lib/assets';
11
+ import { copyText } from '../lib/clipboard';
11
12
  import { useT } from '../lib/i18n';
13
+ import { toast } from '../lib/toast';
12
14
  import { cn } from '../lib/utils';
13
15
 
14
16
  type Group = { scope: string; label: string; assets: Asset[] };
@@ -44,11 +46,13 @@ export function DocAssets({ docId }: { docId: string }) {
44
46
  }, [load]);
45
47
 
46
48
  const copyImport = async (asset: Asset) => {
47
- try {
48
- await navigator.clipboard.writeText(importSnippet(asset));
49
- setCopied(true);
50
- setTimeout(() => setCopied(false), 1200);
51
- } catch {}
49
+ const snippet = importSnippet(asset);
50
+ if (!(await copyText(snippet))) {
51
+ toast.error(t('Copying is blocked here'), { description: snippet });
52
+ return;
53
+ }
54
+ setCopied(true);
55
+ setTimeout(() => setCopied(false), 1200);
52
56
  };
53
57
 
54
58
  if (groups === null) {
@@ -0,0 +1,113 @@
1
+ /**
2
+ * Confirm and prompt drawn in the page instead of `window.confirm` / `window.prompt`.
3
+ * A sandboxed frame without `allow-modals` (VS Code's webviews, editor panels that
4
+ * frame the viewer) never shows the browser's own boxes: `confirm` answers false and
5
+ * `prompt` null at once, so Delete and Rename silently did nothing there. A `<dialog>`
6
+ * in the DOM works in any frame. Built straight into the DOM, like `toast`, so a
7
+ * caller in an event handler needs no React state; the answer comes back as a promise.
8
+ */
9
+
10
+ type Labels = { ok: string; cancel: string; destructive?: boolean };
11
+
12
+ function open(
13
+ build: (dialog: HTMLDialogElement, done: (value: string | null) => void) => void,
14
+ ): Promise<string | null> {
15
+ if (typeof document === 'undefined') return Promise.resolve(null);
16
+ return new Promise((resolve) => {
17
+ const dialog = document.createElement('dialog');
18
+ dialog.className =
19
+ 'm-auto w-[min(400px,calc(100vw-32px))] rounded-xl border border-border bg-background p-4 text-foreground text-sm shadow-2xl backdrop:bg-black/40';
20
+ let settled = false;
21
+ const done = (value: string | null) => {
22
+ if (settled) return;
23
+ settled = true;
24
+ if (dialog.open) dialog.close();
25
+ dialog.remove();
26
+ resolve(value);
27
+ };
28
+ // Escape, or the browser closing it: the same as Cancel.
29
+ dialog.addEventListener('cancel', (event) => {
30
+ event.preventDefault();
31
+ done(null);
32
+ });
33
+ dialog.addEventListener('close', () => done(null));
34
+ build(dialog, done);
35
+ document.body.append(dialog);
36
+ if (typeof dialog.showModal === 'function') dialog.showModal();
37
+ else dialog.setAttribute('open', '');
38
+ (
39
+ dialog.querySelector('input') ?? dialog.querySelector<HTMLButtonElement>('[data-ok]')
40
+ )?.focus();
41
+ });
42
+ }
43
+
44
+ function buttons(labels: Labels, onOk: () => void, onCancel: () => void): HTMLElement {
45
+ const row = document.createElement('div');
46
+ row.className = 'mt-4 flex justify-end gap-2';
47
+ const cancel = document.createElement('button');
48
+ cancel.type = 'button';
49
+ cancel.className =
50
+ 'h-9 rounded-md px-4 text-sm transition-colors hover:bg-accent focus-visible:outline-2 focus-visible:outline-foreground/60';
51
+ cancel.textContent = labels.cancel;
52
+ cancel.addEventListener('click', onCancel);
53
+ const ok = document.createElement('button');
54
+ ok.type = 'submit';
55
+ ok.dataset.ok = '';
56
+ ok.className = `h-9 rounded-md px-4 text-sm transition-opacity hover:opacity-90 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-foreground/60 ${
57
+ labels.destructive ? 'bg-destructive text-white' : 'bg-primary text-primary-foreground'
58
+ }`;
59
+ ok.textContent = labels.ok;
60
+ ok.addEventListener('click', onOk);
61
+ row.append(cancel, ok);
62
+ return row;
63
+ }
64
+
65
+ /** Asks a yes/no question; true only when the OK button is pressed. */
66
+ export async function askConfirm(message: string, labels: Labels): Promise<boolean> {
67
+ const answer = await open((dialog, done) => {
68
+ dialog.setAttribute('role', 'alertdialog');
69
+ const text = document.createElement('p');
70
+ text.className = 'whitespace-pre-wrap leading-relaxed';
71
+ text.textContent = message;
72
+ dialog.append(
73
+ text,
74
+ buttons(
75
+ labels,
76
+ () => done('ok'),
77
+ () => done(null),
78
+ ),
79
+ );
80
+ });
81
+ return answer === 'ok';
82
+ }
83
+
84
+ /** Asks for a line of text, starting from `value`; null when cancelled. */
85
+ export function askText(label: string, value: string, labels: Labels): Promise<string | null> {
86
+ return open((dialog, done) => {
87
+ const form = document.createElement('form');
88
+ form.method = 'dialog';
89
+ const caption = document.createElement('label');
90
+ caption.className = 'block font-medium';
91
+ caption.textContent = label;
92
+ const input = document.createElement('input');
93
+ input.type = 'text';
94
+ input.value = value;
95
+ input.className =
96
+ 'mt-2 h-9 w-full rounded-md border border-border bg-transparent px-3 text-sm outline-none focus:border-foreground/40';
97
+ caption.append(input);
98
+ form.append(
99
+ caption,
100
+ buttons(
101
+ labels,
102
+ () => {},
103
+ () => done(null),
104
+ ),
105
+ );
106
+ form.addEventListener('submit', (event) => {
107
+ event.preventDefault();
108
+ done(input.value);
109
+ });
110
+ dialog.append(form);
111
+ queueMicrotask(() => input.select());
112
+ });
113
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Puts text on the clipboard, or says it could not. A frame without the
3
+ * `clipboard-write` permission (VS Code's webviews, editor panels that frame the
4
+ * viewer) refuses `navigator.clipboard`; the older selection copy still works
5
+ * there in most hosts, so it is the fallback before giving up.
6
+ */
7
+ export async function copyText(text: string): Promise<boolean> {
8
+ try {
9
+ await navigator.clipboard.writeText(text);
10
+ return true;
11
+ } catch {}
12
+ const area = document.createElement('textarea');
13
+ area.value = text;
14
+ area.setAttribute('readonly', '');
15
+ area.style.cssText = 'position:fixed;top:0;left:0;width:1px;height:1px;opacity:0;';
16
+ const focused = document.activeElement as HTMLElement | null;
17
+ document.body.append(area);
18
+ area.select();
19
+ let copied = false;
20
+ try {
21
+ copied = document.execCommand('copy');
22
+ } catch {}
23
+ area.remove();
24
+ focused?.focus?.();
25
+ return copied;
26
+ }
@@ -193,6 +193,14 @@ export async function mountPrintCopy(
193
193
  return { root, dispose };
194
194
  }
195
195
 
196
+ /** The page is in a frame that may not print; the caller can make the PDF another way. */
197
+ export class PrintBlockedError extends Error {
198
+ constructor() {
199
+ super('printing is blocked in this frame');
200
+ this.name = 'PrintBlockedError';
201
+ }
202
+ }
203
+
196
204
  export async function exportDocAsPdf(
197
205
  doc: DocModule,
198
206
  docId: string,
@@ -206,8 +214,18 @@ export async function exportDocAsPdf(
206
214
 
207
215
  try {
208
216
  onProgress?.({ phase: 'printing', current: total, total, percent: 99 });
217
+ // A frame without `allow-modals` ignores print() without a word: no beforeprint, no
218
+ // afterprint, and the export would wait for a dialog that never opens.
219
+ let started = false;
220
+ const onBefore = () => {
221
+ started = true;
222
+ };
223
+ window.addEventListener('beforeprint', onBefore, { once: true });
209
224
  const printDone = waitForAfterPrint();
210
225
  window.print();
226
+ await new Promise((resolve) => setTimeout(resolve, 50));
227
+ window.removeEventListener('beforeprint', onBefore);
228
+ if (!started) throw new PrintBlockedError();
211
229
  await printDone;
212
230
  } finally {
213
231
  onProgress?.({ phase: 'done', current: total, total, percent: 100 });
@@ -9,7 +9,8 @@ export type HostCapability =
9
9
  | 'openHome'
10
10
  | 'guardUnsaved'
11
11
  | 'printToPdf'
12
- | 'translucent';
12
+ | 'translucent'
13
+ | 'openInBrowser';
13
14
 
14
15
  export interface HostTheme {
15
16
  mode: 'light' | 'dark';
@@ -37,6 +38,8 @@ export interface OpenxHost {
37
38
  openHome?(path?: string): boolean;
38
39
  guardUnsaved?(guard: UnsavedGuard): () => void;
39
40
  printToPdf?(filename: string): Promise<boolean>;
41
+ /** Opens this server's page in the person's own browser, where the viewer can do all it does. */
42
+ openInBrowser?(url: string): boolean;
40
43
  translucent?: boolean;
41
44
  }
42
45
 
@@ -14,6 +14,7 @@ export const BROWSER: Record<string, string> = {
14
14
  Rename: '名前を変更',
15
15
  Duplicate: '複製',
16
16
  'Move to': '移動',
17
+ Replace: '置き換え',
17
18
  Delete: '削除',
18
19
  'Delete folder': 'フォルダを削除',
19
20
  'Delete document': 'ドキュメントを削除',
@@ -67,4 +67,15 @@ export const DOC: Record<string, string> = {
67
67
  'Previous record': '前のレコード',
68
68
  'Next record': '次のレコード',
69
69
  Certificate: '修了証',
70
+ 'Copying is blocked here': 'ここではコピーできません',
71
+ 'This window cannot print': 'このウィンドウでは印刷できません',
72
+ 'Open the document in a browser to save a PDF.':
73
+ 'PDF を保存するには、ブラウザでドキュメントを開いてください。',
74
+ 'Could not make the PDF': 'PDF を作成できませんでした',
75
+ 'Saved the whole document': 'ドキュメント全体を保存しました',
76
+ 'This window cannot print a page range.':
77
+ 'このウィンドウではページ範囲を指定して印刷できません。',
78
+ 'Open in browser': 'ブラウザで開く',
79
+ 'Open the document in your browser and save the PDF there.':
80
+ 'ブラウザでドキュメントを開き、そこから PDF を保存してください。',
70
81
  };
@@ -14,6 +14,7 @@ export const BROWSER: Record<string, string> = {
14
14
  Rename: '이름 변경',
15
15
  Duplicate: '복제',
16
16
  'Move to': '이동',
17
+ Replace: '바꾸기',
17
18
  Delete: '삭제',
18
19
  'Delete folder': '폴더 삭제',
19
20
  'Delete document': '문서 삭제',
@@ -67,4 +67,13 @@ export const DOC: Record<string, string> = {
67
67
  'Previous record': '이전 레코드',
68
68
  'Next record': '다음 레코드',
69
69
  Certificate: '수료증',
70
+ 'Copying is blocked here': '여기서는 복사할 수 없습니다',
71
+ 'This window cannot print': '이 창에서는 인쇄할 수 없습니다',
72
+ 'Open the document in a browser to save a PDF.': 'PDF로 저장하려면 브라우저에서 문서를 여세요.',
73
+ 'Could not make the PDF': 'PDF를 만들 수 없습니다',
74
+ 'Saved the whole document': '문서 전체를 저장했습니다',
75
+ 'This window cannot print a page range.': '이 창에서는 일부 페이지만 인쇄할 수 없습니다.',
76
+ 'Open in browser': '브라우저에서 열기',
77
+ 'Open the document in your browser and save the PDF there.':
78
+ '브라우저에서 문서를 열고 거기서 PDF로 저장하세요.',
70
79
  };
@@ -14,6 +14,7 @@ export const BROWSER: Record<string, string> = {
14
14
  Rename: '重命名',
15
15
  Duplicate: '创建副本',
16
16
  'Move to': '移动到',
17
+ Replace: '替换',
17
18
  Delete: '删除',
18
19
  'Delete folder': '删除文件夹',
19
20
  'Delete document': '删除文档',
@@ -66,4 +66,13 @@ export const DOC: Record<string, string> = {
66
66
  'Previous record': '上一条数据',
67
67
  'Next record': '下一条数据',
68
68
  Certificate: '证书',
69
+ 'Copying is blocked here': '此处无法复制',
70
+ 'This window cannot print': '此窗口无法打印',
71
+ 'Open the document in a browser to save a PDF.': '请在浏览器中打开文档以保存 PDF。',
72
+ 'Could not make the PDF': '无法生成 PDF',
73
+ 'Saved the whole document': '已保存整份文档',
74
+ 'This window cannot print a page range.': '此窗口无法只打印部分页面。',
75
+ 'Open in browser': '在浏览器中打开',
76
+ 'Open the document in your browser and save the PDF there.':
77
+ '请在浏览器中打开文档,并从那里保存 PDF。',
69
78
  };
@@ -14,6 +14,7 @@ export const BROWSER: Record<string, string> = {
14
14
  Rename: '重新命名',
15
15
  Duplicate: '複製',
16
16
  'Move to': '移到',
17
+ Replace: '取代',
17
18
  Delete: '刪除',
18
19
  'Delete folder': '刪除資料夾',
19
20
  'Delete document': '刪除文件',
@@ -66,4 +66,13 @@ export const DOC: Record<string, string> = {
66
66
  'Previous record': '上一筆資料',
67
67
  'Next record': '下一筆資料',
68
68
  Certificate: '證書',
69
+ 'Copying is blocked here': '這裡無法複製',
70
+ 'This window cannot print': '這個視窗無法列印',
71
+ 'Open the document in a browser to save a PDF.': '請在瀏覽器打開文件來儲存 PDF。',
72
+ 'Could not make the PDF': '無法產生 PDF',
73
+ 'Saved the whole document': '已儲存整份文件',
74
+ 'This window cannot print a page range.': '這個視窗無法只列印部分頁面。',
75
+ 'Open in browser': '在瀏覽器開啟',
76
+ 'Open the document in your browser and save the PDF there.':
77
+ '請在瀏覽器打開文件,從那裡儲存 PDF。',
69
78
  };
@@ -6,7 +6,7 @@
6
6
  */
7
7
 
8
8
  type Kind = 'error' | 'success';
9
- type Options = { description?: string };
9
+ type Options = { description?: string; action?: { label: string; onClick: () => void } };
10
10
 
11
11
  const SHOWN_MS = 5000;
12
12
 
@@ -40,8 +40,22 @@ function show(kind: Kind, message: string, options?: Options): void {
40
40
  body.textContent = options.description;
41
41
  card.append(body);
42
42
  }
43
+ if (options?.action) {
44
+ const { label, onClick } = options.action;
45
+ const button = document.createElement('button');
46
+ button.type = 'button';
47
+ button.className =
48
+ 'mt-2 h-7 rounded-md border border-border px-2.5 font-medium text-[12px] hover:bg-accent';
49
+ button.textContent = label;
50
+ button.addEventListener('click', () => {
51
+ card.remove();
52
+ onClick();
53
+ });
54
+ card.append(button);
55
+ }
43
56
  host().append(card);
44
- setTimeout(() => card.remove(), SHOWN_MS);
57
+ // A card with a button stays long enough to be pressed.
58
+ setTimeout(() => card.remove(), options?.action ? SHOWN_MS * 3 : SHOWN_MS);
45
59
  }
46
60
 
47
61
  export const toast = {
@@ -12,6 +12,7 @@ import {
12
12
  import { type DragEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react';
13
13
  import { CARD_GRID, EmptyState, PageHeader } from '../components/browser/browser-ui';
14
14
  import { Menu, MenuItem, MenuSeparator } from '../components/ui/menu';
15
+ import { askConfirm, askText } from '../lib/ask';
15
16
  import {
16
17
  type Asset,
17
18
  deleteAsset,
@@ -23,6 +24,7 @@ import {
23
24
  renameAsset,
24
25
  uploadAsset,
25
26
  } from '../lib/assets';
27
+ import { copyText } from '../lib/clipboard';
26
28
  import { docIds } from '../lib/docs';
27
29
  import { useT } from '../lib/i18n';
28
30
  import { cn } from '../lib/utils';
@@ -60,8 +62,9 @@ export function AssetsPage() {
60
62
  for (const file of Array.from(files)) {
61
63
  let result = await uploadAsset(scope, file);
62
64
  if (!result.ok && result.error === 'asset exists') {
63
- const replace = window.confirm(
65
+ const replace = await askConfirm(
64
66
  t('"{name}" already exists in {scope}. Replace it?', { name: file.name, scope }),
67
+ { ok: t('Replace'), cancel: t('Cancel') },
65
68
  );
66
69
  if (!replace) continue;
67
70
  result = await uploadAsset(scope, file, { overwrite: true });
@@ -199,17 +202,20 @@ function AssetCard({
199
202
  const [copied, setCopied] = useState(false);
200
203
 
201
204
  const copyImport = async () => {
202
- try {
203
- await navigator.clipboard.writeText(importSnippet(asset));
204
- setCopied(true);
205
- setTimeout(() => setCopied(false), 1200);
206
- } catch (err) {
207
- onError(String((err as Error).message));
205
+ const snippet = importSnippet(asset);
206
+ if (!(await copyText(snippet))) {
207
+ onError(`${t('Copying is blocked here')}: ${snippet}`);
208
+ return;
208
209
  }
210
+ setCopied(true);
211
+ setTimeout(() => setCopied(false), 1200);
209
212
  };
210
213
 
211
214
  const rename = async () => {
212
- const next = window.prompt(t('New file name'), asset.name);
215
+ const next = await askText(t('New file name'), asset.name, {
216
+ ok: t('Rename'),
217
+ cancel: t('Cancel'),
218
+ });
213
219
  if (!next || next === asset.name) return;
214
220
  const result = await renameAsset(scope, asset.name, next);
215
221
  if (!result.ok) onError(`${asset.name}: ${result.error}`);
@@ -217,10 +223,11 @@ function AssetCard({
217
223
  };
218
224
 
219
225
  const remove = async () => {
220
- if (
221
- !window.confirm(t('Delete "{name}"? This removes the file from disk.', { name: asset.name }))
222
- )
223
- return;
226
+ const yes = await askConfirm(
227
+ t('Delete "{name}"? This removes the file from disk.', { name: asset.name }),
228
+ { ok: t('Delete'), cancel: t('Cancel'), destructive: true },
229
+ );
230
+ if (!yes) return;
224
231
  const result = await deleteAsset(scope, asset.name);
225
232
  if (!result.ok) onError(`${asset.name}: ${result.error}`);
226
233
  onChanged();
@@ -66,10 +66,13 @@ import {
66
66
  useAgentStatus,
67
67
  } from '../lib/agent/use-agent';
68
68
  import { useAgentBridge } from '../lib/agent-bridge';
69
+ import { copyText } from '../lib/clipboard';
69
70
  import { exportDocAsDocx } from '../lib/export-docx';
71
+ import { downloadBlob, downloadName } from '../lib/export-dom';
70
72
  import { exportDocAsHtml } from '../lib/export-html';
71
73
  import { exportDocAsImages } from '../lib/export-image';
72
- import { exportDocAsPdf } from '../lib/export-pdf';
74
+ import { exportDocAsPdf, PrintBlockedError } from '../lib/export-pdf';
75
+ import { getHost, hostCan } from '../lib/host';
73
76
  import { useLocale, useT } from '../lib/i18n';
74
77
  import { type OutlineEntry, useDocOutline } from '../lib/outline';
75
78
  import {
@@ -83,6 +86,7 @@ import { markDocOpened } from '../lib/recent-docs';
83
86
  import { getRecordState, setRecords, useRecordIndex } from '../lib/records';
84
87
  import { scanDocument } from '../lib/scan';
85
88
  import { pageLang, resolvePageGeometry } from '../lib/sdk';
89
+ import { toast } from '../lib/toast';
86
90
  import { useDocModule } from '../lib/use-doc-module';
87
91
  import { useDocPages } from '../lib/use-doc-pages';
88
92
  import { cn } from '../lib/utils';
@@ -555,6 +559,48 @@ export function Doc() {
555
559
  return onPage[0]?.id ?? null;
556
560
  }, [outline, currentPage]);
557
561
 
562
+ /*
563
+ * A frame that may not print (VS Code's webviews) gets the PDF the CLI makes, from the
564
+ * dev server. It renders the whole document: the server has no page range to obey.
565
+ */
566
+ const pdfFromServer = async (partial: boolean): Promise<boolean> => {
567
+ if (!doc || !docId) return false;
568
+ // A host that can open the page in the person's browser turns the failure into one click.
569
+ const host = getHost();
570
+ const inBrowser =
571
+ host?.openInBrowser && hostCan(host, 'openInBrowser')
572
+ ? {
573
+ label: t('Open in browser'),
574
+ onClick: () => host.openInBrowser?.(window.location.href),
575
+ }
576
+ : undefined;
577
+ if (!import.meta.env.DEV) {
578
+ toast.error(t('This window cannot print'), {
579
+ description: t('Open the document in a browser to save a PDF.'),
580
+ ...(inBrowser ? { action: inBrowser } : {}),
581
+ });
582
+ return false;
583
+ }
584
+ const res = await fetch(`/__docs/${encodeURIComponent(docId)}/pdf`, { method: 'POST' });
585
+ if (!res.ok) {
586
+ const body = (await res.json().catch(() => ({}))) as { error?: string };
587
+ toast.error(t('Could not make the PDF'), {
588
+ description: inBrowser
589
+ ? t('Open the document in your browser and save the PDF there.')
590
+ : (body.error ?? res.statusText),
591
+ ...(inBrowser ? { action: inBrowser } : {}),
592
+ });
593
+ return false;
594
+ }
595
+ downloadBlob(await res.blob(), `${downloadName(doc, docId)}.pdf`);
596
+ if (partial) {
597
+ toast.success(t('Saved the whole document'), {
598
+ description: t('This window cannot print a page range.'),
599
+ });
600
+ }
601
+ return true;
602
+ };
603
+
558
604
  const runDownload = async (format: DownloadFormat) => {
559
605
  if (!doc || !docId || download) return;
560
606
 
@@ -575,9 +621,14 @@ export function Doc() {
575
621
  setDownload({ format, percent: 0 });
576
622
  try {
577
623
  if (format === 'pdf') {
578
- await exportDocAsPdf(doc, docId, chosen, (progress) =>
579
- setDownload({ format, percent: progress.percent }),
580
- );
624
+ try {
625
+ await exportDocAsPdf(doc, docId, chosen, (progress) =>
626
+ setDownload({ format, percent: progress.percent }),
627
+ );
628
+ } catch (err) {
629
+ if (!(err instanceof PrintBlockedError)) throw err;
630
+ if (!(await pdfFromServer(chosen.length < pages.length))) return;
631
+ }
581
632
  } else if (format === 'html') {
582
633
  await exportDocAsHtml(doc, docId, chosen);
583
634
  } else if (format === 'docx') {
@@ -897,16 +948,18 @@ export function Doc() {
897
948
  <LayoutGrid className="size-3.5" />
898
949
  </IconButton>
899
950
  </fieldset>
900
- <IconButton
901
- label={isFullscreen ? t('Exit fullscreen (F)') : t('Fullscreen (F)')}
902
- onClick={toggleFullscreen}
903
- >
904
- {isFullscreen ? (
905
- <Minimize className="size-3.5" />
906
- ) : (
907
- <Maximize className="size-3.5" />
908
- )}
909
- </IconButton>
951
+ {document.fullscreenEnabled && (
952
+ <IconButton
953
+ label={isFullscreen ? t('Exit fullscreen (F)') : t('Fullscreen (F)')}
954
+ onClick={toggleFullscreen}
955
+ >
956
+ {isFullscreen ? (
957
+ <Minimize className="size-3.5" />
958
+ ) : (
959
+ <Maximize className="size-3.5" />
960
+ )}
961
+ </IconButton>
962
+ )}
910
963
  </div>
911
964
  </div>
912
965
 
@@ -1684,7 +1737,10 @@ function MoreMenu({ changes, comments }: { changes: DockToggle; comments: DockTo
1684
1737
  <MenuItem
1685
1738
  onClick={() => {
1686
1739
  close();
1687
- navigator.clipboard.writeText(window.location.href).catch(() => {});
1740
+ const href = window.location.href;
1741
+ void copyText(href).then(
1742
+ (ok) => ok || toast.error(t('Copying is blocked here'), { description: href }),
1743
+ );
1688
1744
  }}
1689
1745
  >
1690
1746
  <Link2 className={item} />
@@ -1706,11 +1762,13 @@ function CopyLink() {
1706
1762
  aria-label={copied ? t('Link copied') : t('Copy link')}
1707
1763
  title={t('Copy link')}
1708
1764
  onClick={async () => {
1709
- try {
1710
- await navigator.clipboard.writeText(window.location.href);
1711
- setCopied(true);
1712
- setTimeout(() => setCopied(false), 1500);
1713
- } catch {}
1765
+ const href = window.location.href;
1766
+ if (!(await copyText(href))) {
1767
+ toast.error(t('Copying is blocked here'), { description: href });
1768
+ return;
1769
+ }
1770
+ setCopied(true);
1771
+ setTimeout(() => setCopied(false), 1500);
1714
1772
  }}
1715
1773
  className="flex size-8 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground"
1716
1774
  >
@@ -34,6 +34,7 @@ import { DOC_DND_MIME } from '../components/sidebar/folder-item';
34
34
  import { ALL_DOCS_ID, DRAFT_ID } from '../components/sidebar/sidebar';
35
35
  import { Menu, MenuItem, MenuSeparator } from '../components/ui/menu';
36
36
  import { useAgentStatus, useCreateDoc } from '../lib/agent/use-agent';
37
+ import { askConfirm, askText } from '../lib/ask';
37
38
  import { coverContent } from '../lib/doc-preview';
38
39
  import { docCreatedAt, docIds, docThemes, docTitles } from '../lib/docs';
39
40
  import { type Translate, useLocale, useT } from '../lib/i18n';
@@ -393,8 +394,12 @@ function DocCard({
393
394
  <MenuItem
394
395
  onClick={() => {
395
396
  close();
396
- const next = window.prompt(t('Document title'), title);
397
- if (next && next !== title) void run(() => ctx.renameDoc(docId, next));
397
+ void askText(t('Document title'), title, {
398
+ ok: t('Rename'),
399
+ cancel: t('Cancel'),
400
+ }).then((next) => {
401
+ if (next && next !== title) void run(() => ctx.renameDoc(docId, next));
402
+ });
398
403
  }}
399
404
  >
400
405
  <PencilLine className="size-3.5" />
@@ -446,16 +451,15 @@ function DocCard({
446
451
  destructive
447
452
  onClick={() => {
448
453
  close();
449
- if (
450
- !window.confirm(
451
- t('Delete "{title}"? This removes docs/{id}/ from disk.', {
452
- title,
453
- id: docId,
454
- }),
455
- )
456
- )
457
- return;
458
- void run(() => ctx.deleteDoc(docId));
454
+ void askConfirm(
455
+ t('Delete "{title}"? This removes docs/{id}/ from disk.', {
456
+ title,
457
+ id: docId,
458
+ }),
459
+ { ok: t('Delete'), cancel: t('Cancel'), destructive: true },
460
+ ).then((yes) => {
461
+ if (yes) void run(() => ctx.deleteDoc(docId));
462
+ });
459
463
  }}
460
464
  >
461
465
  <Trash2 className="size-3.5" />