@open-document/core 0.17.2 → 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.
- package/package.json +1 -1
- package/src/app/lib/host.ts +4 -1
- package/src/app/lib/i18n-ja/doc.ts +3 -0
- package/src/app/lib/i18n-ko/doc.ts +3 -0
- package/src/app/lib/i18n-zh-cn/doc.ts +3 -0
- package/src/app/lib/i18n-zh-tw/doc.ts +3 -0
- package/src/app/lib/toast.ts +16 -2
- package/src/app/routes/doc.tsx +17 -1
package/package.json
CHANGED
package/src/app/lib/host.ts
CHANGED
|
@@ -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
|
|
|
@@ -75,4 +75,7 @@ export const DOC: Record<string, string> = {
|
|
|
75
75
|
'Saved the whole document': 'ドキュメント全体を保存しました',
|
|
76
76
|
'This window cannot print a page range.':
|
|
77
77
|
'このウィンドウではページ範囲を指定して印刷できません。',
|
|
78
|
+
'Open in browser': 'ブラウザで開く',
|
|
79
|
+
'Open the document in your browser and save the PDF there.':
|
|
80
|
+
'ブラウザでドキュメントを開き、そこから PDF を保存してください。',
|
|
78
81
|
};
|
|
@@ -73,4 +73,7 @@ export const DOC: Record<string, string> = {
|
|
|
73
73
|
'Could not make the PDF': 'PDF를 만들 수 없습니다',
|
|
74
74
|
'Saved the whole document': '문서 전체를 저장했습니다',
|
|
75
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로 저장하세요.',
|
|
76
79
|
};
|
|
@@ -72,4 +72,7 @@ export const DOC: Record<string, string> = {
|
|
|
72
72
|
'Could not make the PDF': '无法生成 PDF',
|
|
73
73
|
'Saved the whole document': '已保存整份文档',
|
|
74
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。',
|
|
75
78
|
};
|
|
@@ -72,4 +72,7 @@ export const DOC: Record<string, string> = {
|
|
|
72
72
|
'Could not make the PDF': '無法產生 PDF',
|
|
73
73
|
'Saved the whole document': '已儲存整份文件',
|
|
74
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。',
|
|
75
78
|
};
|
package/src/app/lib/toast.ts
CHANGED
|
@@ -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
|
-
|
|
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 = {
|
package/src/app/routes/doc.tsx
CHANGED
|
@@ -72,6 +72,7 @@ import { downloadBlob, downloadName } from '../lib/export-dom';
|
|
|
72
72
|
import { exportDocAsHtml } from '../lib/export-html';
|
|
73
73
|
import { exportDocAsImages } from '../lib/export-image';
|
|
74
74
|
import { exportDocAsPdf, PrintBlockedError } from '../lib/export-pdf';
|
|
75
|
+
import { getHost, hostCan } from '../lib/host';
|
|
75
76
|
import { useLocale, useT } from '../lib/i18n';
|
|
76
77
|
import { type OutlineEntry, useDocOutline } from '../lib/outline';
|
|
77
78
|
import {
|
|
@@ -564,16 +565,31 @@ export function Doc() {
|
|
|
564
565
|
*/
|
|
565
566
|
const pdfFromServer = async (partial: boolean): Promise<boolean> => {
|
|
566
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;
|
|
567
577
|
if (!import.meta.env.DEV) {
|
|
568
578
|
toast.error(t('This window cannot print'), {
|
|
569
579
|
description: t('Open the document in a browser to save a PDF.'),
|
|
580
|
+
...(inBrowser ? { action: inBrowser } : {}),
|
|
570
581
|
});
|
|
571
582
|
return false;
|
|
572
583
|
}
|
|
573
584
|
const res = await fetch(`/__docs/${encodeURIComponent(docId)}/pdf`, { method: 'POST' });
|
|
574
585
|
if (!res.ok) {
|
|
575
586
|
const body = (await res.json().catch(() => ({}))) as { error?: string };
|
|
576
|
-
toast.error(t('Could not make the PDF'), {
|
|
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
|
+
});
|
|
577
593
|
return false;
|
|
578
594
|
}
|
|
579
595
|
downloadBlob(await res.blob(), `${downloadName(doc, docId)}.pdf`);
|