@openworkbook/react 0.0.0-stage → 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 +46 -2
- package/THIRD-PARTY-NOTICES.md +23 -0
- package/dist/chunk-6JJNRZAC.js +8524 -0
- package/dist/client.cjs +36015 -0
- package/dist/client.js +26448 -0
- package/dist/dictionaries/en-GB.cjs +197 -0
- package/dist/dictionaries/en-GB.d.cts +20 -0
- package/dist/dictionaries/en-GB.d.ts +20 -0
- package/dist/dictionaries/en-GB.js +170 -0
- package/dist/dictionaries/en.cjs +67 -0
- package/dist/dictionaries/en.d.cts +30 -0
- package/dist/dictionaries/en.d.ts +30 -0
- package/dist/dictionaries/en.js +38 -0
- package/dist/index.cjs +11112 -0
- package/dist/index.d.cts +7431 -0
- package/dist/index.d.ts +7431 -0
- package/dist/index.js +11068 -0
- package/dist/printSettingsUi-O3255F6Z.js +1268 -0
- package/dist/skeleton.cjs +73 -0
- package/dist/skeleton.d.cts +21 -0
- package/dist/skeleton.d.ts +21 -0
- package/dist/skeleton.js +47 -0
- package/package.json +70 -3
|
@@ -0,0 +1,1268 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
Icon,
|
|
4
|
+
download,
|
|
5
|
+
errorText,
|
|
6
|
+
printPreviewDocument,
|
|
7
|
+
printSheets,
|
|
8
|
+
sheetPrintPages,
|
|
9
|
+
useLocale
|
|
10
|
+
} from "./chunk-6JJNRZAC.js";
|
|
11
|
+
|
|
12
|
+
// src/printSettingsUi.tsx
|
|
13
|
+
import {
|
|
14
|
+
PAPER_SIZES as PAPER_SIZES2,
|
|
15
|
+
frozenPrintTitles,
|
|
16
|
+
headerFooterFields,
|
|
17
|
+
marginPresetOf,
|
|
18
|
+
marginUnit,
|
|
19
|
+
movePageBreak,
|
|
20
|
+
parsePrintTitles,
|
|
21
|
+
printScaleMode,
|
|
22
|
+
rangeName as rangeName2,
|
|
23
|
+
repeatsFrozenPanes,
|
|
24
|
+
scaleModePatch,
|
|
25
|
+
setHeaderFooterField,
|
|
26
|
+
setPageBreak,
|
|
27
|
+
sheetPrintRange
|
|
28
|
+
} from "@openworkbook/core";
|
|
29
|
+
import { Fragment, useEffect, useMemo, useRef, useState } from "react";
|
|
30
|
+
|
|
31
|
+
// src/printSettings.ts
|
|
32
|
+
import {
|
|
33
|
+
DEFAULT_PAGE_SETUP,
|
|
34
|
+
PAPER_SIZES,
|
|
35
|
+
formatPrintTitles,
|
|
36
|
+
joinHeaderFooterPieces,
|
|
37
|
+
loadPageBreaks,
|
|
38
|
+
loadPageSetup,
|
|
39
|
+
rangeName,
|
|
40
|
+
samePageSetup,
|
|
41
|
+
scanHeaderFooter,
|
|
42
|
+
headerFooterTokenOf,
|
|
43
|
+
HEADER_FOOTER_TOKENS
|
|
44
|
+
} from "@openworkbook/core";
|
|
45
|
+
function initPrintSettings(wb, o = {}) {
|
|
46
|
+
const visible = wb.sheets.filter((s) => !s.hidden);
|
|
47
|
+
const active = wb.activeSheet && !wb.activeSheet.hidden ? wb.activeSheet : visible[0] ?? wb.sheets[0];
|
|
48
|
+
const setups = {}, pageBreaks = {};
|
|
49
|
+
for (const s of wb.sheets) {
|
|
50
|
+
setups[s.name] = s.pageSetup;
|
|
51
|
+
pageBreaks[s.name] = s.pageBreaks;
|
|
52
|
+
}
|
|
53
|
+
const sel = o.selection ? { ...o.selection } : null;
|
|
54
|
+
const sheets = (o.sheets?.length ? wb.sheets.filter((s) => o.sheets.includes(s.name)) : visible).map((s) => s.name);
|
|
55
|
+
return {
|
|
56
|
+
what: o.what === "selection" && !sel ? "sheet" : o.what ?? "sheet",
|
|
57
|
+
sheet: active.name,
|
|
58
|
+
sheets,
|
|
59
|
+
selection: sel,
|
|
60
|
+
setups,
|
|
61
|
+
pageBreaks,
|
|
62
|
+
applyTo: "all",
|
|
63
|
+
notes: o.notes ? "atEnd" : "none"
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
var currentSetup = (s) => s.setups[s.sheet] ?? DEFAULT_PAGE_SETUP;
|
|
67
|
+
function editedSheets(s) {
|
|
68
|
+
return s.what === "workbook" && s.applyTo === "all" ? [.../* @__PURE__ */ new Set([s.sheet, ...s.sheets])] : [s.sheet];
|
|
69
|
+
}
|
|
70
|
+
function applySetupPatch(s, patch) {
|
|
71
|
+
return applySetupChange(s, () => patch);
|
|
72
|
+
}
|
|
73
|
+
function applySetupChange(s, change) {
|
|
74
|
+
const setups = { ...s.setups };
|
|
75
|
+
for (const name of editedSheets(s)) {
|
|
76
|
+
const cur = setups[name] ?? DEFAULT_PAGE_SETUP;
|
|
77
|
+
setups[name] = loadPageSetup(change(cur, name), cur);
|
|
78
|
+
}
|
|
79
|
+
return { ...s, setups };
|
|
80
|
+
}
|
|
81
|
+
function setWorkingPageBreaks(s, sheet, pb) {
|
|
82
|
+
return { ...s, pageBreaks: { ...s.pageBreaks, [sheet]: loadPageBreaks(pb) } };
|
|
83
|
+
}
|
|
84
|
+
function printTargets(s, wb) {
|
|
85
|
+
if (s.what !== "workbook") return wb.sheets.filter((x) => x.name === s.sheet);
|
|
86
|
+
return wb.sheets.filter((x) => s.sheets.includes(x.name));
|
|
87
|
+
}
|
|
88
|
+
function printExportOptions(s, wb, o = {}) {
|
|
89
|
+
const targets = printTargets(s, wb);
|
|
90
|
+
const pageSetup = {}, pageBreaks = {};
|
|
91
|
+
for (const sh of targets) {
|
|
92
|
+
pageSetup[sh.name] = s.setups[sh.name] ?? sh.pageSetup;
|
|
93
|
+
pageBreaks[sh.name] = s.pageBreaks[sh.name] ?? sh.pageBreaks;
|
|
94
|
+
}
|
|
95
|
+
const out = { sheets: targets.map((x) => x.name), pageSetup, pageBreaks, includeComments: s.notes };
|
|
96
|
+
if (s.what === "selection" && s.selection) out.range = rangeName(s.selection);
|
|
97
|
+
if (o.title !== void 0) {
|
|
98
|
+
out.title = o.title;
|
|
99
|
+
out.fileName = o.title;
|
|
100
|
+
out.filePath = o.filePath ?? `${o.title}.xlsx`;
|
|
101
|
+
} else if (o.filePath !== void 0) out.filePath = o.filePath;
|
|
102
|
+
if (o.date) out.date = o.date;
|
|
103
|
+
return out;
|
|
104
|
+
}
|
|
105
|
+
function browserPrintSetup(s, sheet) {
|
|
106
|
+
const st = s.setups[sheet.name] ?? sheet.pageSetup;
|
|
107
|
+
return s.what === "selection" && s.selection && sheet.name === s.sheet ? { ...st, printArea: [{ ...s.selection }] } : st;
|
|
108
|
+
}
|
|
109
|
+
function printSettingsChanges(s, wb) {
|
|
110
|
+
const out = [];
|
|
111
|
+
for (const sheet of printTargets(s, wb)) {
|
|
112
|
+
const setup = s.setups[sheet.name], pb = s.pageBreaks[sheet.name];
|
|
113
|
+
const ch = { sheet };
|
|
114
|
+
if (setup && !samePageSetup(setup, sheet.pageSetup)) ch.setup = setup;
|
|
115
|
+
if (pb && JSON.stringify(loadPageBreaks(pb)) !== JSON.stringify(loadPageBreaks(sheet.pageBreaks))) ch.pageBreaks = pb;
|
|
116
|
+
if (ch.setup || ch.pageBreaks) out.push(ch);
|
|
117
|
+
}
|
|
118
|
+
return out;
|
|
119
|
+
}
|
|
120
|
+
function persistPrintSettings(s, wb, readOnly = false) {
|
|
121
|
+
if (readOnly) return false;
|
|
122
|
+
const changes = printSettingsChanges(s, wb);
|
|
123
|
+
if (!changes.length) return false;
|
|
124
|
+
wb.transact(() => {
|
|
125
|
+
for (const c of changes) {
|
|
126
|
+
if (c.setup) c.sheet.setPageSetup(c.setup);
|
|
127
|
+
if (c.pageBreaks) c.sheet.setPageBreaks(c.pageBreaks);
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return true;
|
|
131
|
+
}
|
|
132
|
+
var trim = (n, locale) => locale ? new Intl.NumberFormat(locale, { maximumFractionDigits: 2 }).format(n) : String(Math.round(n * 100) / 100);
|
|
133
|
+
function formatLength(mm, unit, locale) {
|
|
134
|
+
return unit === "in" ? `${trim(mm / 25.4, locale)}"` : `${trim(mm / 10, locale)} cm`;
|
|
135
|
+
}
|
|
136
|
+
function paperLabel(size, unit, locale) {
|
|
137
|
+
const p = PAPER_SIZES[size];
|
|
138
|
+
return `${size} (${formatLength(p.w, unit, locale)} x ${formatLength(p.h, unit, locale)})`;
|
|
139
|
+
}
|
|
140
|
+
var titlesText = (p, axis) => formatPrintTitles(axis === "row" ? p.printTitleRows : p.printTitleCols, axis);
|
|
141
|
+
function headerFooterToDisplay(text, names) {
|
|
142
|
+
return scanHeaderFooter(text).map((p) => {
|
|
143
|
+
if ("text" in p) return p.text.replace(/&/g, "&&");
|
|
144
|
+
const tok = headerFooterTokenOf(p.code);
|
|
145
|
+
return tok ? `{${names[tok]}}` : p.code;
|
|
146
|
+
}).join("");
|
|
147
|
+
}
|
|
148
|
+
function headerFooterFromDisplay(display, names) {
|
|
149
|
+
const byName = /* @__PURE__ */ new Map();
|
|
150
|
+
for (const k of Object.keys(HEADER_FOOTER_TOKENS)) {
|
|
151
|
+
byName.set(k.toLowerCase(), k);
|
|
152
|
+
byName.set(names[k].toLowerCase(), k);
|
|
153
|
+
}
|
|
154
|
+
const out = display.replace(/\{([^{}]+)\}/g, (all, name) => {
|
|
155
|
+
const k = byName.get(name.trim().toLowerCase());
|
|
156
|
+
return k ? HEADER_FOOTER_TOKENS[k] : all;
|
|
157
|
+
});
|
|
158
|
+
return joinHeaderFooterPieces(scanHeaderFooter(out));
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// src/printSettingsUi.tsx
|
|
162
|
+
import { Fragment as Fragment2, jsx, jsxs } from "react/jsx-runtime";
|
|
163
|
+
var PAPERS = Object.keys(PAPER_SIZES2);
|
|
164
|
+
var ZOOM_MIN = 0.1;
|
|
165
|
+
var ZOOM_MAX = 4;
|
|
166
|
+
var GAP = 24;
|
|
167
|
+
var PAD = 24;
|
|
168
|
+
var HF_FIELDS = [["pageNumbers", "psx.hf.pageNumbers"], ["title", "psx.hf.title"], ["sheetName", "psx.hf.sheetName"], ["date", "psx.hf.date"], ["time", "psx.hf.time"]];
|
|
169
|
+
var TOKENS = [["page", "psx.token.page"], ["pages", "psx.token.pages"], ["date", "psx.token.date"], ["time", "psx.token.time"], ["title", "psx.token.title"], ["sheet", "psx.token.sheet"], ["file", "psx.token.file"]];
|
|
170
|
+
var MARGIN_KEYS = [["top", "psx.top"], ["bottom", "psx.bottom"], ["left", "psx.left"], ["right", "psx.right"], ["header", "psx.header"], ["footer", "psx.footer"]];
|
|
171
|
+
var PRINT_SETTINGS_CSS = `
|
|
172
|
+
.ox-psx{position:fixed;inset:0;z-index:1300;display:flex;flex-direction:column;background:var(--ox-chrome,#f5f5f5);color:var(--ox-fg,#242424);font:var(--ox-font-size,14px) var(--ox-font,"Segoe UI",-apple-system,BlinkMacSystemFont,Helvetica,Arial,sans-serif);outline:none;box-sizing:border-box}
|
|
173
|
+
.ox-psx *{box-sizing:border-box}
|
|
174
|
+
.ox-psx button,.ox-psx input,.ox-psx select,.ox-psx textarea{font:inherit;color:inherit}
|
|
175
|
+
.ox-psx.ox-psx-dark{color-scheme:dark;--ox-bg:#292929;--ox-chrome:#1f1f1f;--ox-surface:#292929;--ox-fg:#f0f0f0;--ox-muted:#adadad;--ox-border:#3d3d3d;--ox-strong:#525252;--ox-hover:#383838;--ox-accent:#4caf7a;--ox-accent-fg:#10231a}
|
|
176
|
+
.ox-psx-bar{display:flex;align-items:center;gap:10px;flex:none;min-height:56px;padding:8px 16px;background:#202124;color:#fff;flex-wrap:wrap}
|
|
177
|
+
.ox-psx-bar h2{margin:0;font-size:18px;font-weight:500;white-space:nowrap}
|
|
178
|
+
.ox-psx-total{color:#c4c7c5;font-size:14px;white-space:nowrap;font-variant-numeric:tabular-nums}
|
|
179
|
+
.ox-psx-grow{flex:1}
|
|
180
|
+
.ox-psx-bar button{display:inline-flex;align-items:center;gap:6px;height:36px;padding:0 16px;border:1px solid transparent;border-radius:var(--ox-radius,4px);background:none;color:#fff;cursor:pointer;font-weight:600;letter-spacing:.02em;text-transform:uppercase;font-size:13px;white-space:nowrap}
|
|
181
|
+
.ox-psx-bar button:hover:not(:disabled){background:rgba(255,255,255,.1)}
|
|
182
|
+
.ox-psx-bar button:disabled{opacity:.5;cursor:default}
|
|
183
|
+
.ox-psx-bar button.ox-psx-outline{border-color:rgba(255,255,255,.35)}
|
|
184
|
+
.ox-psx-bar button.ox-psx-primary{background:var(--ox-accent,#107c41);border-color:var(--ox-accent,#107c41);color:var(--ox-accent-fg,#fff)}
|
|
185
|
+
.ox-psx-bar button.ox-psx-primary:hover:not(:disabled){filter:brightness(1.1);background:var(--ox-accent,#107c41)}
|
|
186
|
+
.ox-psx-bar button:focus-visible{outline:2px solid #8ab4f8;outline-offset:2px}
|
|
187
|
+
.ox-psx-drawer-btn{display:none!important}
|
|
188
|
+
.ox-psx-body{flex:1;min-height:0;display:flex;position:relative}
|
|
189
|
+
.ox-psx-stage{position:relative;flex:1;min-width:0;background:#e6e6e6;overflow:hidden;display:flex;flex-direction:column}
|
|
190
|
+
.ox-dark .ox-psx-stage,.ox-psx-dark .ox-psx-stage{background:#121212}
|
|
191
|
+
.ox-psx-scroll{flex:1;min-height:0;overflow:auto;position:relative;outline:none;touch-action:pan-x pan-y}
|
|
192
|
+
.ox-psx-inner{position:relative}
|
|
193
|
+
.ox-psx-page{position:absolute;background:#fff;box-shadow:0 1px 3px rgba(0,0,0,.18),0 4px 14px rgba(0,0,0,.14);overflow:hidden}
|
|
194
|
+
.ox-psx-page canvas{display:block;width:100%;height:100%}
|
|
195
|
+
.ox-psx-page iframe{position:absolute;left:0;top:0;border:0;transform-origin:0 0;background:#fff;pointer-events:none}
|
|
196
|
+
.ox-psx-badge{position:absolute;transform:translateX(-50%);font-size:12px;color:#5f6368;white-space:nowrap;font-variant-numeric:tabular-nums}
|
|
197
|
+
.ox-dark .ox-psx-badge,.ox-psx-dark .ox-psx-badge{color:#9aa0a6}
|
|
198
|
+
.ox-psx-skel{position:absolute;inset:0;background:linear-gradient(100deg,#fff 30%,#f1f1f1 50%,#fff 70%);background-size:300% 100%;animation:ox-psx-shimmer 1.4s ease-in-out infinite}
|
|
199
|
+
.ox-psx-skel i{position:absolute;left:10%;right:10%;height:6px;border-radius:3px;background:#ececec}
|
|
200
|
+
@keyframes ox-psx-shimmer{0%{background-position:100% 0}100%{background-position:0 0}}
|
|
201
|
+
@media (prefers-reduced-motion:reduce){.ox-psx-skel{animation:none}}
|
|
202
|
+
.ox-psx-busy{position:absolute;inset-inline-start:50%;top:12px;transform:translateX(-50%);z-index:3;padding:5px 12px;border-radius:14px;background:rgba(32,33,36,.86);color:#fff;font-size:12.5px;pointer-events:none}
|
|
203
|
+
.ox-psx-note{position:absolute;inset-inline-start:12px;bottom:12px;z-index:3;max-width:60%;padding:5px 10px;border-radius:6px;background:rgba(255,255,255,.92);color:#3c4043;font-size:12px}
|
|
204
|
+
.ox-psx-zoom{position:absolute;inset-inline-end:16px;bottom:16px;z-index:4;display:flex;flex-direction:column;gap:8px}
|
|
205
|
+
.ox-psx-zoom button{width:40px;height:40px;border-radius:50%;border:0;background:#fff;color:#3c4043;box-shadow:0 1px 3px rgba(0,0,0,.3);cursor:pointer;font-size:22px;line-height:1;display:flex;align-items:center;justify-content:center}
|
|
206
|
+
.ox-psx-zoom button:hover:not(:disabled){background:#f1f3f4}
|
|
207
|
+
.ox-psx-zoom button:disabled{opacity:.5;cursor:default}
|
|
208
|
+
.ox-psx-zoom button:focus-visible{outline:2px solid var(--ox-accent,#107c41);outline-offset:2px}
|
|
209
|
+
.ox-psx-empty{position:absolute;inset:0;display:flex;align-items:center;justify-content:center;color:var(--ox-muted,#616161)}
|
|
210
|
+
.ox-psx-panel{width:340px;flex:none;overflow:auto;background:var(--ox-surface,var(--ox-bg,#fff));border-inline-start:1px solid var(--ox-border,#e0e0e0);padding:4px 0 24px}
|
|
211
|
+
.ox-psx-sec{padding:14px 20px;border-bottom:1px solid var(--ox-border,#e0e0e0)}
|
|
212
|
+
.ox-psx-sec:last-child{border-bottom:0}
|
|
213
|
+
.ox-psx-sec>h3,.ox-psx-sum{margin:0 0 10px;font-size:13px;font-weight:600;color:var(--ox-fg,#242424)}
|
|
214
|
+
.ox-psx-sum{display:flex;align-items:center;justify-content:space-between;width:100%;margin:0;padding:0;border:0;background:none;cursor:pointer;text-align:start}
|
|
215
|
+
.ox-psx-sum svg{transition:transform .15s}
|
|
216
|
+
.ox-psx-sum[aria-expanded=true]{margin-bottom:10px}
|
|
217
|
+
.ox-psx-sum[aria-expanded=true] svg{transform:rotate(180deg)}
|
|
218
|
+
.ox-psx-row{display:flex;align-items:center;gap:8px;flex-wrap:wrap;margin:0 0 8px}
|
|
219
|
+
.ox-psx-row:last-child{margin-bottom:0}
|
|
220
|
+
.ox-psx label{display:inline-flex;align-items:center;gap:8px;cursor:pointer;min-height:24px}
|
|
221
|
+
.ox-psx-col{display:flex;flex-direction:column;gap:6px}
|
|
222
|
+
.ox-psx-sub{margin:4px 0 4px 26px;margin-inline-start:26px;margin-left:0;display:flex;flex-direction:column;gap:4px;max-height:170px;overflow:auto}
|
|
223
|
+
.ox-psx select,.ox-psx input[type=text]{height:32px;padding:0 8px;border:1px solid var(--ox-strong,#c7c7c7);border-radius:var(--ox-radius,4px);background:var(--ox-bg,#fff);min-width:0}
|
|
224
|
+
.ox-psx select{width:100%}
|
|
225
|
+
.ox-psx input[type=text].ox-psx-n{width:76px}
|
|
226
|
+
.ox-psx input[type=checkbox],.ox-psx input[type=radio]{accent-color:var(--ox-accent,#107c41);margin:0;width:16px;height:16px}
|
|
227
|
+
.ox-psx input:focus-visible,.ox-psx select:focus-visible,.ox-psx-panel button:focus-visible{outline:2px solid var(--ox-accent,#107c41);outline-offset:1px}
|
|
228
|
+
.ox-psx-bad{border-color:#c4314b!important}
|
|
229
|
+
.ox-psx-hint{margin:6px 0 0;color:var(--ox-muted,#616161);font-size:12px;line-height:1.35}
|
|
230
|
+
.ox-psx-grid{display:grid;grid-template-columns:auto 1fr auto 1fr;gap:8px 10px;align-items:center}
|
|
231
|
+
.ox-psx-grid input[type=text]{width:100%}
|
|
232
|
+
.ox-psx-link{border:1px solid var(--ox-strong,#c7c7c7);background:var(--ox-bg,#fff);color:var(--ox-accent,#107c41);font-weight:600;letter-spacing:.02em;text-transform:uppercase;font-size:12.5px;height:34px;padding:0 14px;border-radius:var(--ox-radius,4px);cursor:pointer;width:100%}
|
|
233
|
+
.ox-psx-link:hover{background:var(--ox-hover,#ebebeb)}
|
|
234
|
+
.ox-psx-tbtn{border:0;background:none;color:var(--ox-accent,#107c41);font-weight:600;cursor:pointer;padding:4px 0;text-transform:uppercase;font-size:12.5px;letter-spacing:.02em}
|
|
235
|
+
.ox-psx-err{margin:0;padding:8px 16px;background:#fde7e9;color:#a4262c;font-size:13px}
|
|
236
|
+
.ox-psx-ro{margin:0;padding:8px 20px;color:var(--ox-muted,#616161);font-size:12.5px;border-bottom:1px solid var(--ox-border,#e0e0e0)}
|
|
237
|
+
.ox-psx-brk{position:absolute;z-index:2}
|
|
238
|
+
.ox-psx-brk.ox-row{height:11px;margin-top:-5px;cursor:row-resize}
|
|
239
|
+
.ox-psx-brk.ox-col{width:11px;margin-left:-5px;cursor:col-resize}
|
|
240
|
+
.ox-psx-brk::after{content:"";position:absolute;background:#1a73e8}
|
|
241
|
+
.ox-psx-brk.ox-row::after{left:0;right:0;top:4px;height:3px}
|
|
242
|
+
.ox-psx-brk.ox-col::after{top:0;bottom:0;left:4px;width:3px}
|
|
243
|
+
.ox-psx-brk.ox-auto::after{background:repeating-linear-gradient(90deg,#1a73e8 0 8px,transparent 8px 13px)}
|
|
244
|
+
.ox-psx-brk.ox-col.ox-auto::after{background:repeating-linear-gradient(180deg,#1a73e8 0 8px,transparent 8px 13px)}
|
|
245
|
+
.ox-psx-brk.ox-drag::after{background:#174ea6}
|
|
246
|
+
.ox-psx-brk:focus-visible{outline:2px solid #1a73e8}
|
|
247
|
+
.ox-psx-modal{position:absolute;inset:0;z-index:20;display:flex;align-items:center;justify-content:center;background:rgba(0,0,0,.35)}
|
|
248
|
+
.ox-psx-dlg{width:min(640px,94vw);max-height:90vh;overflow:auto;background:var(--ox-surface,var(--ox-bg,#fff));color:var(--ox-fg,#242424);border-radius:8px;box-shadow:0 12px 40px rgba(0,0,0,.35);padding:18px 20px}
|
|
249
|
+
.ox-psx-dlg h3{margin:0 0 12px;font-size:16px;font-weight:600}
|
|
250
|
+
.ox-psx-dlg fieldset{border:0;margin:0 0 12px;padding:0;display:grid;grid-template-columns:repeat(3,1fr);gap:8px}
|
|
251
|
+
.ox-psx-dlg legend{font-weight:600;font-size:13px;margin-bottom:6px}
|
|
252
|
+
.ox-psx-dlg fieldset label{display:flex;flex-direction:column;align-items:stretch;gap:3px;font-size:12px;color:var(--ox-muted,#616161)}
|
|
253
|
+
.ox-psx-dlg fieldset input{width:100%;color:var(--ox-fg,#242424)}
|
|
254
|
+
.ox-psx-chips{display:flex;flex-wrap:wrap;gap:6px;margin:0 0 12px}
|
|
255
|
+
.ox-psx-chips button{height:28px;padding:0 10px;border:1px solid var(--ox-strong,#c7c7c7);border-radius:14px;background:var(--ox-bg,#fff);cursor:pointer;font-size:12.5px}
|
|
256
|
+
.ox-psx-chips button:hover{background:var(--ox-hover,#ebebeb)}
|
|
257
|
+
.ox-psx-dlgfoot{display:flex;justify-content:flex-end;gap:8px;margin-top:8px}
|
|
258
|
+
.ox-psx-dlgfoot button{min-width:84px;height:34px;padding:0 14px;border:1px solid var(--ox-strong,#c7c7c7);border-radius:var(--ox-radius,4px);background:var(--ox-bg,#fff);cursor:pointer}
|
|
259
|
+
.ox-psx-dlgfoot button.ox-psx-primary{background:var(--ox-accent,#107c41);border-color:var(--ox-accent,#107c41);color:var(--ox-accent-fg,#fff)}
|
|
260
|
+
.ox-psx.ox-psx-narrow .ox-psx-body{flex-direction:column}
|
|
261
|
+
.ox-psx.ox-psx-narrow .ox-psx-panel{width:auto;max-height:50%;border-inline-start:0;border-top:1px solid var(--ox-border,#e0e0e0);box-shadow:0 -4px 14px rgba(0,0,0,.12)}
|
|
262
|
+
.ox-psx.ox-psx-narrow .ox-psx-panel[data-open=false]{display:none}
|
|
263
|
+
.ox-psx.ox-psx-narrow .ox-psx-drawer-btn{display:inline-flex!important}
|
|
264
|
+
.ox-psx.ox-psx-narrow .ox-psx-bar{padding:6px 10px;gap:6px}
|
|
265
|
+
.ox-psx.ox-psx-narrow .ox-psx-bar button{padding:0 10px}
|
|
266
|
+
`;
|
|
267
|
+
var message = (e) => errorText(e);
|
|
268
|
+
var safeName = (s) => s.replace(/[\\/:*?"<>|\r\n]+/g, "_").trim() || "workbook";
|
|
269
|
+
var hasLayout = (pdf) => !!pdf && (typeof pdf.layoutPdfAsync === "function" || typeof pdf.layoutPdf === "function");
|
|
270
|
+
var canExport = (pdf) => !!pdf && (typeof pdf.exportPdfAsync === "function" || typeof pdf.exportPdf === "function");
|
|
271
|
+
function usePreview(wb, s, pdf, title, date, delay = 220) {
|
|
272
|
+
const [preview, setPreview] = useState(null);
|
|
273
|
+
const [busy, setBusy] = useState(true);
|
|
274
|
+
const seq = useRef(0);
|
|
275
|
+
const key = JSON.stringify([s.what, s.sheet, s.sheets, s.selection, s.notes, printTargets(s, wb).map((x) => [s.setups[x.name], s.pageBreaks[x.name]])]);
|
|
276
|
+
useEffect(() => {
|
|
277
|
+
const id = ++seq.current;
|
|
278
|
+
setBusy(true);
|
|
279
|
+
const timer = setTimeout(() => {
|
|
280
|
+
const done = (p) => {
|
|
281
|
+
if (seq.current === id) {
|
|
282
|
+
setPreview(p);
|
|
283
|
+
setBusy(false);
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
const targets = printTargets(s, wb);
|
|
287
|
+
if (!targets.length) {
|
|
288
|
+
done({ pages: [], mode: hasLayout(pdf) ? "pdf" : "html" });
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
if (hasLayout(pdf)) {
|
|
292
|
+
const opts = printExportOptions(s, wb, { title, date });
|
|
293
|
+
const run = async () => {
|
|
294
|
+
const lay = pdf.layoutPdfAsync ? await pdf.layoutPdfAsync(wb, opts) : pdf.layoutPdf(wb, opts);
|
|
295
|
+
return lay.pages.map((p, i) => ({ key: `${id}:${i}`, sheet: p.sheet, kind: p.kind, area: p.area, widthPx: p.widthPx, heightPx: p.heightPx, draw: (ctx, o) => p.draw(ctx, o) }));
|
|
296
|
+
};
|
|
297
|
+
run().then((pages) => done({ pages, mode: "pdf" }), (e) => done({ pages: [], mode: "pdf", error: message(e) }));
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
try {
|
|
301
|
+
const pages = [];
|
|
302
|
+
for (const sheet of targets) {
|
|
303
|
+
const out = sheetPrintPages(sheet, browserPrintSetup(s, sheet), { fileName: title, date, pageBreaks: s.pageBreaks[sheet.name] });
|
|
304
|
+
const p = out.layout.paper;
|
|
305
|
+
out.pages.forEach((_html, i) => pages.push({
|
|
306
|
+
key: `${id}:${pages.length}`,
|
|
307
|
+
sheet: sheet.name,
|
|
308
|
+
kind: "cells",
|
|
309
|
+
area: out.layout.pages[i]?.area,
|
|
310
|
+
widthPx: p.width,
|
|
311
|
+
heightPx: p.height,
|
|
312
|
+
html: printPreviewDocument(out, i)
|
|
313
|
+
// [security] sanitised page HTML in a sandboxed frame
|
|
314
|
+
}));
|
|
315
|
+
}
|
|
316
|
+
done({ pages, mode: "html" });
|
|
317
|
+
} catch (e) {
|
|
318
|
+
done({ pages: [], mode: "html", error: message(e) });
|
|
319
|
+
}
|
|
320
|
+
}, preview ? delay : 30);
|
|
321
|
+
return () => clearTimeout(timer);
|
|
322
|
+
}, [key, pdf, title]);
|
|
323
|
+
return { preview, busy };
|
|
324
|
+
}
|
|
325
|
+
function PageCanvas({ page, zoom }) {
|
|
326
|
+
const ref = useRef(null);
|
|
327
|
+
const [drawn, setDrawn] = useState(false);
|
|
328
|
+
useEffect(() => {
|
|
329
|
+
let live = true;
|
|
330
|
+
const id = requestAnimationFrame(() => {
|
|
331
|
+
const cv = ref.current;
|
|
332
|
+
if (!cv || !live || !page.draw) return;
|
|
333
|
+
const dpr = typeof window !== "undefined" && window.devicePixelRatio || 1, area = page.widthPx * page.heightPx;
|
|
334
|
+
let k = zoom * dpr;
|
|
335
|
+
if (area * k * k > 16e6) k = Math.sqrt(16e6 / area);
|
|
336
|
+
cv.width = Math.max(1, Math.round(page.widthPx * k));
|
|
337
|
+
cv.height = Math.max(1, Math.round(page.heightPx * k));
|
|
338
|
+
const ctx = cv.getContext("2d");
|
|
339
|
+
if (!ctx) return;
|
|
340
|
+
const paint = () => {
|
|
341
|
+
if (!live) return;
|
|
342
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
343
|
+
try {
|
|
344
|
+
page.draw(ctx, { scale: k, onImageReady: () => requestAnimationFrame(paint) });
|
|
345
|
+
} catch (e) {
|
|
346
|
+
console.error(e);
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
paint();
|
|
350
|
+
setDrawn(true);
|
|
351
|
+
});
|
|
352
|
+
return () => {
|
|
353
|
+
live = false;
|
|
354
|
+
cancelAnimationFrame(id);
|
|
355
|
+
};
|
|
356
|
+
}, [page, zoom]);
|
|
357
|
+
return /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
358
|
+
/* @__PURE__ */ jsx("canvas", { ref, "aria-hidden": "true" }),
|
|
359
|
+
!drawn && /* @__PURE__ */ jsx(Skeleton, {})
|
|
360
|
+
] });
|
|
361
|
+
}
|
|
362
|
+
function Skeleton() {
|
|
363
|
+
return /* @__PURE__ */ jsx("div", { className: "ox-psx-skel", "aria-hidden": "true", children: [8, 13, 18, 23, 28, 33].map((t) => /* @__PURE__ */ jsx("i", { style: { top: `${t}%`, right: `${10 + t % 3 * 12}%` } }, t)) });
|
|
364
|
+
}
|
|
365
|
+
function PreviewPane({ t, preview, busy, zoom, setZoom }) {
|
|
366
|
+
const scroll = useRef(null);
|
|
367
|
+
const [measured, setView0] = useState(null);
|
|
368
|
+
const view = measured ?? { w: 800, h: 600, top: 0 };
|
|
369
|
+
const setView = setView0;
|
|
370
|
+
const pages = measured ? preview?.pages ?? [] : [];
|
|
371
|
+
const maxW = pages.reduce((m, p) => Math.max(m, p.widthPx), 0) || 794;
|
|
372
|
+
const fit = Math.max(ZOOM_MIN, Math.min(2, (view.w - PAD * 2) / maxW));
|
|
373
|
+
const z = zoom ?? fit;
|
|
374
|
+
const [drawZoom, setDrawZoom] = useState(z);
|
|
375
|
+
const settled = useRef(false);
|
|
376
|
+
useEffect(() => {
|
|
377
|
+
if (!measured) return;
|
|
378
|
+
if (!settled.current) {
|
|
379
|
+
settled.current = true;
|
|
380
|
+
setDrawZoom(z);
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
const id = setTimeout(() => setDrawZoom(z), 140);
|
|
384
|
+
return () => clearTimeout(id);
|
|
385
|
+
}, [z, !!measured]);
|
|
386
|
+
useEffect(() => {
|
|
387
|
+
const el = scroll.current;
|
|
388
|
+
if (!el) return;
|
|
389
|
+
const measure = () => setView({ w: el.clientWidth, h: el.clientHeight, top: el.scrollTop });
|
|
390
|
+
measure();
|
|
391
|
+
const onScroll = () => setView((v) => ({ ...v ?? { w: el.clientWidth, h: el.clientHeight }, top: el.scrollTop }));
|
|
392
|
+
el.addEventListener("scroll", onScroll, { passive: true });
|
|
393
|
+
let ro;
|
|
394
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
395
|
+
ro = new ResizeObserver(measure);
|
|
396
|
+
ro.observe(el);
|
|
397
|
+
} else window.addEventListener("resize", measure);
|
|
398
|
+
return () => {
|
|
399
|
+
el.removeEventListener("scroll", onScroll);
|
|
400
|
+
ro?.disconnect();
|
|
401
|
+
window.removeEventListener("resize", measure);
|
|
402
|
+
};
|
|
403
|
+
}, []);
|
|
404
|
+
const zoomRef = useRef(z);
|
|
405
|
+
zoomRef.current = z;
|
|
406
|
+
useEffect(() => {
|
|
407
|
+
const el = scroll.current;
|
|
408
|
+
if (!el) return;
|
|
409
|
+
const zoomAt = (next, cx, cy) => {
|
|
410
|
+
const cur = zoomRef.current, nz = Math.max(ZOOM_MIN, Math.min(ZOOM_MAX, next));
|
|
411
|
+
if (nz === cur) return;
|
|
412
|
+
const r = el.getBoundingClientRect(), px = cx - r.left + el.scrollLeft, py = cy - r.top + el.scrollTop;
|
|
413
|
+
setZoom(nz);
|
|
414
|
+
requestAnimationFrame(() => {
|
|
415
|
+
el.scrollLeft = px * (nz / cur) - (cx - r.left);
|
|
416
|
+
el.scrollTop = py * (nz / cur) - (cy - r.top);
|
|
417
|
+
});
|
|
418
|
+
};
|
|
419
|
+
const onWheel = (e) => {
|
|
420
|
+
if (!e.ctrlKey && !e.metaKey) return;
|
|
421
|
+
e.preventDefault();
|
|
422
|
+
zoomAt(zoomRef.current * Math.exp(-e.deltaY * 25e-4), e.clientX, e.clientY);
|
|
423
|
+
};
|
|
424
|
+
let pinch = null;
|
|
425
|
+
const dist = (e) => Math.hypot(e.touches[0].clientX - e.touches[1].clientX, e.touches[0].clientY - e.touches[1].clientY);
|
|
426
|
+
const onStart = (e) => {
|
|
427
|
+
if (e.touches.length === 2) pinch = { d: dist(e), z: zoomRef.current };
|
|
428
|
+
};
|
|
429
|
+
const onMove = (e) => {
|
|
430
|
+
if (!pinch || e.touches.length !== 2) return;
|
|
431
|
+
e.preventDefault();
|
|
432
|
+
zoomAt(pinch.z * (dist(e) / pinch.d), (e.touches[0].clientX + e.touches[1].clientX) / 2, (e.touches[0].clientY + e.touches[1].clientY) / 2);
|
|
433
|
+
};
|
|
434
|
+
const onEnd = () => {
|
|
435
|
+
pinch = null;
|
|
436
|
+
};
|
|
437
|
+
el.addEventListener("wheel", onWheel, { passive: false });
|
|
438
|
+
el.addEventListener("touchstart", onStart, { passive: true });
|
|
439
|
+
el.addEventListener("touchmove", onMove, { passive: false });
|
|
440
|
+
el.addEventListener("touchend", onEnd);
|
|
441
|
+
return () => {
|
|
442
|
+
el.removeEventListener("wheel", onWheel);
|
|
443
|
+
el.removeEventListener("touchstart", onStart);
|
|
444
|
+
el.removeEventListener("touchmove", onMove);
|
|
445
|
+
el.removeEventListener("touchend", onEnd);
|
|
446
|
+
};
|
|
447
|
+
}, [setZoom]);
|
|
448
|
+
const badgeH = 22;
|
|
449
|
+
const tops = [];
|
|
450
|
+
let y = PAD;
|
|
451
|
+
for (const p of pages) {
|
|
452
|
+
tops.push(y);
|
|
453
|
+
y += p.heightPx * z + badgeH + GAP;
|
|
454
|
+
}
|
|
455
|
+
const innerH = Math.max(view.h, y + PAD), innerW = Math.max(view.w, maxW * z + PAD * 2);
|
|
456
|
+
let first = 0, last = -1;
|
|
457
|
+
if (pages.length) {
|
|
458
|
+
let lo = 0, hi = pages.length - 1;
|
|
459
|
+
while (lo < hi) {
|
|
460
|
+
const m = lo + hi >> 1;
|
|
461
|
+
if (tops[m] + pages[m].heightPx * z < view.top) lo = m + 1;
|
|
462
|
+
else hi = m;
|
|
463
|
+
}
|
|
464
|
+
first = Math.max(0, lo - 1);
|
|
465
|
+
last = first;
|
|
466
|
+
while (last + 1 < pages.length && tops[last + 1] < view.top + view.h) last++;
|
|
467
|
+
last = Math.min(pages.length - 1, last + 1);
|
|
468
|
+
}
|
|
469
|
+
const step = (dir) => setZoom(Math.max(ZOOM_MIN, Math.min(ZOOM_MAX, Math.round(z * (dir > 0 ? 1.25 : 0.8) * 100) / 100)));
|
|
470
|
+
const shown = [];
|
|
471
|
+
for (let i = first; i <= last && i < pages.length; i++) {
|
|
472
|
+
const p = pages[i], w = p.widthPx * z, h = p.heightPx * z, left = Math.max(PAD, (innerW - w) / 2);
|
|
473
|
+
shown.push(
|
|
474
|
+
/* @__PURE__ */ jsx(
|
|
475
|
+
"div",
|
|
476
|
+
{
|
|
477
|
+
className: "ox-psx-page",
|
|
478
|
+
role: "img",
|
|
479
|
+
"aria-label": t("psx.pageOf", { n: i + 1, total: pages.length }),
|
|
480
|
+
"data-page": i + 1,
|
|
481
|
+
"data-sheet": p.sheet,
|
|
482
|
+
style: { left, top: tops[i], width: w, height: h },
|
|
483
|
+
children: p.draw ? /* @__PURE__ */ jsx(PageCanvas, { page: p, zoom: drawZoom }) : /* @__PURE__ */ jsx("iframe", { title: t("ui2.labelItem", [t("psx.preview"), i + 1]), sandbox: "", srcDoc: p.html, style: { width: p.widthPx, height: p.heightPx, transform: `scale(${z})` } })
|
|
484
|
+
},
|
|
485
|
+
p.key
|
|
486
|
+
),
|
|
487
|
+
/* @__PURE__ */ jsx("span", { className: "ox-psx-badge", style: { left: left + w / 2, top: tops[i] + h + 4 }, children: `${i + 1} / ${pages.length}${p.sheet && preview && new Set(pages.map((x) => x.sheet)).size > 1 ? ` \xB7 ${p.sheet}` : ""}` }, p.key + "b")
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
return /* @__PURE__ */ jsxs("div", { className: "ox-psx-stage", children: [
|
|
491
|
+
/* @__PURE__ */ jsx("div", { className: "ox-psx-scroll", ref: scroll, tabIndex: 0, "aria-label": t("psx.preview"), role: "region", children: /* @__PURE__ */ jsx("div", { className: "ox-psx-inner", style: { width: innerW, height: innerH }, children: preview && measured ? shown : [0, 1].map((i) => /* @__PURE__ */ jsx("div", { className: "ox-psx-page", style: { left: Math.max(PAD, (innerW - 794 * z) / 2), top: PAD + i * (1123 * z + badgeH + GAP), width: 794 * z, height: 1123 * z }, children: /* @__PURE__ */ jsx(Skeleton, {}) }, i)) }) }),
|
|
492
|
+
preview && !pages.length && !busy && /* @__PURE__ */ jsx("div", { className: "ox-psx-empty", children: preview.error ?? t("psx.empty") }),
|
|
493
|
+
busy && preview && /* @__PURE__ */ jsx("div", { className: "ox-psx-busy", role: "status", children: t("psx.loading") }),
|
|
494
|
+
preview?.mode === "html" && /* @__PURE__ */ jsx("div", { className: "ox-psx-note", children: t("psx.htmlPreview") }),
|
|
495
|
+
/* @__PURE__ */ jsxs("div", { className: "ox-psx-zoom", children: [
|
|
496
|
+
/* @__PURE__ */ jsx("button", { type: "button", title: t("psx.zoomIn"), "aria-label": t("psx.zoomIn"), disabled: z >= ZOOM_MAX, onClick: () => step(1), children: "+" }),
|
|
497
|
+
/* @__PURE__ */ jsx("button", { type: "button", title: t("psx.zoomOut"), "aria-label": t("psx.zoomOut"), disabled: z <= ZOOM_MIN, onClick: () => step(-1), children: "\u2212" })
|
|
498
|
+
] })
|
|
499
|
+
] });
|
|
500
|
+
}
|
|
501
|
+
function BreakEditor({ t, sheet, pages, breaks, setBreaks, fitIgnored, zoom, setZoom }) {
|
|
502
|
+
const scroll = useRef(null), canvas = useRef(null);
|
|
503
|
+
const [view, setView] = useState({ w: 800, h: 600, left: 0, top: 0 });
|
|
504
|
+
const [drag, setDrag] = useState(null);
|
|
505
|
+
const mine = pages.filter((p) => p.sheet === sheet.name && p.kind === "cells" && p.area);
|
|
506
|
+
const range = mine.length ? { r1: Math.min(...mine.map((p) => p.area.r1)), c1: Math.min(...mine.map((p) => p.area.c1)), r2: Math.max(...mine.map((p) => p.area.r2)), c2: Math.max(...mine.map((p) => p.area.c2)) } : sheetPrintRange(sheet);
|
|
507
|
+
const R = sheet.rows, C = sheet.cols, HW = 46, HH = 24;
|
|
508
|
+
const z = zoom ?? 1;
|
|
509
|
+
const x0 = C.offset(range.c1), y0 = R.offset(range.r1), W = C.offset(range.c2 + 1) - x0, H = R.offset(range.r2 + 1) - y0;
|
|
510
|
+
const colX = (c) => HW + (C.offset(c) - x0) * z, rowY = (r) => HH + (R.offset(r) - y0) * z;
|
|
511
|
+
const rowStarts = [...new Set(mine.map((p) => p.area.r1))].filter((r) => r > range.r1).sort((a, b) => a - b);
|
|
512
|
+
const colStarts = [...new Set(mine.map((p) => p.area.c1))].filter((c) => c > range.c1).sort((a, b) => a - b);
|
|
513
|
+
useEffect(() => {
|
|
514
|
+
const el = scroll.current;
|
|
515
|
+
if (!el) return;
|
|
516
|
+
const measure = () => setView({ w: el.clientWidth, h: el.clientHeight, left: el.scrollLeft, top: el.scrollTop });
|
|
517
|
+
measure();
|
|
518
|
+
el.addEventListener("scroll", measure, { passive: true });
|
|
519
|
+
let ro;
|
|
520
|
+
if (typeof ResizeObserver !== "undefined") {
|
|
521
|
+
ro = new ResizeObserver(measure);
|
|
522
|
+
ro.observe(el);
|
|
523
|
+
}
|
|
524
|
+
return () => {
|
|
525
|
+
el.removeEventListener("scroll", measure);
|
|
526
|
+
ro?.disconnect();
|
|
527
|
+
};
|
|
528
|
+
}, []);
|
|
529
|
+
useEffect(() => {
|
|
530
|
+
const cv = canvas.current;
|
|
531
|
+
if (!cv) return;
|
|
532
|
+
const dpr = window.devicePixelRatio || 1;
|
|
533
|
+
cv.width = Math.max(1, Math.round(view.w * dpr));
|
|
534
|
+
cv.height = Math.max(1, Math.round(view.h * dpr));
|
|
535
|
+
const ctx = cv.getContext("2d");
|
|
536
|
+
if (!ctx) return;
|
|
537
|
+
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
538
|
+
ctx.fillStyle = "#ffffff";
|
|
539
|
+
ctx.fillRect(0, 0, view.w, view.h);
|
|
540
|
+
ctx.save();
|
|
541
|
+
ctx.translate(-view.left, -view.top);
|
|
542
|
+
const rA = Math.max(range.r1, R.indexAt(y0 + Math.max(0, view.top - HH) / z)), rB = Math.min(range.r2, R.indexAt(y0 + (view.top + view.h) / z) + 1);
|
|
543
|
+
const cA = Math.max(range.c1, C.indexAt(x0 + Math.max(0, view.left - HW) / z)), cB = Math.min(range.c2, C.indexAt(x0 + (view.left + view.w) / z) + 1);
|
|
544
|
+
ctx.font = `${Math.max(6, 11 * z * 4 / 3)}px Calibri, Carlito, Arial, sans-serif`;
|
|
545
|
+
ctx.textBaseline = "middle";
|
|
546
|
+
for (let r = rA; r <= rB; r++) {
|
|
547
|
+
const h = R.size(r) * z;
|
|
548
|
+
if (!h) continue;
|
|
549
|
+
const y = rowY(r);
|
|
550
|
+
for (let c = cA; c <= cB; c++) {
|
|
551
|
+
const w = C.size(c) * z;
|
|
552
|
+
if (!w) continue;
|
|
553
|
+
const x = colX(c), st = sheet.getStyle(r, c);
|
|
554
|
+
if (st.fill) {
|
|
555
|
+
ctx.fillStyle = st.fill;
|
|
556
|
+
ctx.fillRect(x, y, w, h);
|
|
557
|
+
}
|
|
558
|
+
const text = sheet.getText(r, c);
|
|
559
|
+
if (text) {
|
|
560
|
+
ctx.save();
|
|
561
|
+
ctx.beginPath();
|
|
562
|
+
ctx.rect(x, y, w, h);
|
|
563
|
+
ctx.clip();
|
|
564
|
+
ctx.fillStyle = st.color || "#202124";
|
|
565
|
+
const num = typeof sheet.getValue(r, c) === "number";
|
|
566
|
+
ctx.textAlign = st.align === "center" ? "center" : st.align === "right" || !st.align && num ? "right" : "left";
|
|
567
|
+
ctx.fillText(text.replace(/\n/g, " "), ctx.textAlign === "center" ? x + w / 2 : ctx.textAlign === "right" ? x + w - 3 : x + 3, y + h / 2);
|
|
568
|
+
ctx.restore();
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
ctx.strokeStyle = "#e1e3e1";
|
|
573
|
+
ctx.lineWidth = 1;
|
|
574
|
+
ctx.beginPath();
|
|
575
|
+
for (let r = rA; r <= rB + 1; r++) {
|
|
576
|
+
const y = Math.round(rowY(r)) + 0.5;
|
|
577
|
+
ctx.moveTo(colX(cA), y);
|
|
578
|
+
ctx.lineTo(colX(cB + 1), y);
|
|
579
|
+
}
|
|
580
|
+
for (let c = cA; c <= cB + 1; c++) {
|
|
581
|
+
const x = Math.round(colX(c)) + 0.5;
|
|
582
|
+
ctx.moveTo(x, rowY(rA));
|
|
583
|
+
ctx.lineTo(x, rowY(rB + 1));
|
|
584
|
+
}
|
|
585
|
+
ctx.stroke();
|
|
586
|
+
ctx.restore();
|
|
587
|
+
ctx.fillStyle = "#f1f3f4";
|
|
588
|
+
ctx.fillRect(0, 0, view.w, HH);
|
|
589
|
+
ctx.fillRect(0, 0, HW, view.h);
|
|
590
|
+
ctx.fillStyle = "#5f6368";
|
|
591
|
+
ctx.font = "11px system-ui, sans-serif";
|
|
592
|
+
ctx.textAlign = "center";
|
|
593
|
+
for (let c = cA; c <= cB; c++) {
|
|
594
|
+
const w = C.size(c) * z;
|
|
595
|
+
if (w < 8) continue;
|
|
596
|
+
ctx.fillText(sheet.getColumnHeaderText(c), colX(c) - view.left + w / 2, HH / 2);
|
|
597
|
+
}
|
|
598
|
+
for (let r = rA; r <= rB; r++) {
|
|
599
|
+
const h = R.size(r) * z;
|
|
600
|
+
if (h < 8) continue;
|
|
601
|
+
ctx.fillText(sheet.getRowHeaderText(r), HW / 2, rowY(r) - view.top + h / 2);
|
|
602
|
+
}
|
|
603
|
+
ctx.strokeStyle = "#c4c7c5";
|
|
604
|
+
ctx.beginPath();
|
|
605
|
+
ctx.moveTo(0, HH - 0.5);
|
|
606
|
+
ctx.lineTo(view.w, HH - 0.5);
|
|
607
|
+
ctx.moveTo(HW - 0.5, 0);
|
|
608
|
+
ctx.lineTo(HW - 0.5, view.h);
|
|
609
|
+
ctx.stroke();
|
|
610
|
+
});
|
|
611
|
+
const boundary = (axis, px) => {
|
|
612
|
+
const ax = axis === "row" ? R : C, a = axis === "row" ? range.r1 : range.c1, b = axis === "row" ? range.r2 : range.c2, o = axis === "row" ? y0 : x0, head = axis === "row" ? HH : HW;
|
|
613
|
+
const pos = o + (px - head) / z;
|
|
614
|
+
const i = Math.max(a, Math.min(b, ax.indexAt(Math.max(0, pos))));
|
|
615
|
+
return pos - ax.offset(i) > ax.size(i) / 2 ? Math.min(b + 1, i + 1) : i;
|
|
616
|
+
};
|
|
617
|
+
const startDrag = (e, axis, at) => {
|
|
618
|
+
e.preventDefault();
|
|
619
|
+
e.stopPropagation();
|
|
620
|
+
try {
|
|
621
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
622
|
+
} catch {
|
|
623
|
+
}
|
|
624
|
+
setDrag({ axis, from: at, to: at });
|
|
625
|
+
};
|
|
626
|
+
const local = (e) => {
|
|
627
|
+
const r = scroll.current.getBoundingClientRect();
|
|
628
|
+
return { x: e.clientX - r.left + scroll.current.scrollLeft, y: e.clientY - r.top + scroll.current.scrollTop };
|
|
629
|
+
};
|
|
630
|
+
const move = (e) => {
|
|
631
|
+
if (!drag) return;
|
|
632
|
+
const p = local(e);
|
|
633
|
+
setDrag({ ...drag, to: boundary(drag.axis, drag.axis === "row" ? p.y : p.x) });
|
|
634
|
+
};
|
|
635
|
+
const drop = () => {
|
|
636
|
+
if (!drag) return;
|
|
637
|
+
const first = drag.axis === "row" ? range.r1 : range.c1, end = drag.axis === "row" ? range.r2 + 1 : range.c2 + 1;
|
|
638
|
+
if (drag.to !== drag.from) setBreaks(drag.to <= first || drag.to >= end ? setPageBreak(breaks, drag.axis, drag.from, false) : movePageBreak(breaks, drag.axis, drag.from, drag.to));
|
|
639
|
+
setDrag(null);
|
|
640
|
+
};
|
|
641
|
+
const onCanvasClick = (e) => {
|
|
642
|
+
const r = scroll.current.getBoundingClientRect(), vx = e.clientX - r.left, vy = e.clientY - r.top;
|
|
643
|
+
if (vy < HH && vx > HW) {
|
|
644
|
+
const c = C.indexAt(x0 + (vx + view.left - HW) / z);
|
|
645
|
+
if (c > range.c1 && c <= range.c2) setBreaks(setPageBreak(breaks, "col", c, true));
|
|
646
|
+
} else if (vx < HW && vy > HH) {
|
|
647
|
+
const rr = R.indexAt(y0 + (vy + view.top - HH) / z);
|
|
648
|
+
if (rr > range.r1 && rr <= range.r2) setBreaks(setPageBreak(breaks, "row", rr, true));
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
const line = (axis, at) => {
|
|
652
|
+
const manual = (axis === "row" ? breaks.rows : breaks.cols).includes(at), dragging = drag && drag.axis === axis && drag.from === at;
|
|
653
|
+
const pos = axis === "row" ? rowY(dragging ? drag.to : at) : colX(dragging ? drag.to : at);
|
|
654
|
+
const label = t("printUi.breakAt", [t(manual ? "psx.breaks.manual" : "psx.breaks.auto"), axis === "row" ? sheet.getRowHeaderText(at) : sheet.getColumnHeaderText(at)]);
|
|
655
|
+
return /* @__PURE__ */ jsx(
|
|
656
|
+
"div",
|
|
657
|
+
{
|
|
658
|
+
className: `ox-psx-brk ${axis === "row" ? "ox-row" : "ox-col"}${manual ? "" : " ox-auto"}${dragging ? " ox-drag" : ""}`,
|
|
659
|
+
role: "separator",
|
|
660
|
+
tabIndex: 0,
|
|
661
|
+
"aria-orientation": axis === "row" ? "horizontal" : "vertical",
|
|
662
|
+
"aria-label": label,
|
|
663
|
+
title: label,
|
|
664
|
+
"data-break": `${axis}:${at}`,
|
|
665
|
+
style: axis === "row" ? { top: pos, left: HW, width: W * z } : { left: pos, top: HH, height: H * z },
|
|
666
|
+
onPointerDown: (e) => startDrag(e, axis, at),
|
|
667
|
+
onPointerMove: move,
|
|
668
|
+
onPointerUp: drop,
|
|
669
|
+
onPointerCancel: () => setDrag(null),
|
|
670
|
+
onDoubleClick: () => {
|
|
671
|
+
if (manual) setBreaks(setPageBreak(breaks, axis, at, false));
|
|
672
|
+
},
|
|
673
|
+
onKeyDown: (e) => {
|
|
674
|
+
const d = axis === "row" ? e.key === "ArrowUp" ? -1 : e.key === "ArrowDown" ? 1 : 0 : e.key === "ArrowLeft" ? -1 : e.key === "ArrowRight" ? 1 : 0;
|
|
675
|
+
if (d) {
|
|
676
|
+
e.preventDefault();
|
|
677
|
+
const lim = axis === "row" ? range.r2 : range.c2;
|
|
678
|
+
const to = Math.max((axis === "row" ? range.r1 : range.c1) + 1, Math.min(lim, at + d));
|
|
679
|
+
setBreaks(movePageBreak(breaks, axis, at, to));
|
|
680
|
+
} else if ((e.key === "Delete" || e.key === "Backspace") && manual) {
|
|
681
|
+
e.preventDefault();
|
|
682
|
+
setBreaks(setPageBreak(breaks, axis, at, false));
|
|
683
|
+
}
|
|
684
|
+
}
|
|
685
|
+
},
|
|
686
|
+
axis + at
|
|
687
|
+
);
|
|
688
|
+
};
|
|
689
|
+
return /* @__PURE__ */ jsxs("div", { className: "ox-psx-stage", children: [
|
|
690
|
+
/* @__PURE__ */ jsxs("div", { className: "ox-psx-note", style: { position: "relative", insetInlineStart: 0, bottom: "auto", maxWidth: "none", borderRadius: 0, background: "var(--ox-surface,#fff)", color: "var(--ox-fg,#242424)", borderBottom: "1px solid var(--ox-border,#e0e0e0)", padding: "8px 16px" }, children: [
|
|
691
|
+
t("psx.breaks.hint"),
|
|
692
|
+
fitIgnored && /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
693
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
694
|
+
/* @__PURE__ */ jsx("b", { children: t("psx.breaks.fitIgnored") })
|
|
695
|
+
] })
|
|
696
|
+
] }),
|
|
697
|
+
/* @__PURE__ */ jsx("div", { className: "ox-psx-scroll", ref: scroll, role: "region", "aria-label": t("psx.breaks.title"), children: /* @__PURE__ */ jsxs("div", { className: "ox-psx-inner", style: { width: HW + W * z + PAD, height: HH + H * z + PAD }, children: [
|
|
698
|
+
/* @__PURE__ */ jsx("canvas", { ref: canvas, onClick: onCanvasClick, style: { position: "sticky", left: 0, top: 0, width: view.w, height: view.h, display: "block", cursor: "default" } }),
|
|
699
|
+
/* @__PURE__ */ jsx("div", { style: { position: "absolute", inset: 0, pointerEvents: "none" }, children: /* @__PURE__ */ jsxs("div", { style: { pointerEvents: "auto" }, children: [
|
|
700
|
+
rowStarts.map((r) => line("row", r)),
|
|
701
|
+
colStarts.map((c) => line("col", c))
|
|
702
|
+
] }) })
|
|
703
|
+
] }) }),
|
|
704
|
+
/* @__PURE__ */ jsxs("div", { className: "ox-psx-zoom", children: [
|
|
705
|
+
/* @__PURE__ */ jsx("button", { type: "button", title: t("psx.zoomIn"), "aria-label": t("psx.zoomIn"), onClick: () => setZoom(Math.min(ZOOM_MAX, z * 1.25)), children: "+" }),
|
|
706
|
+
/* @__PURE__ */ jsx("button", { type: "button", title: t("psx.zoomOut"), "aria-label": t("psx.zoomOut"), onClick: () => setZoom(Math.max(0.25, z * 0.8)), children: "\u2212" })
|
|
707
|
+
] })
|
|
708
|
+
] });
|
|
709
|
+
}
|
|
710
|
+
function FieldsDialog({ t, setup, close, apply }) {
|
|
711
|
+
const names = Object.fromEntries(TOKENS.map(([k, l]) => [k, t(l)]));
|
|
712
|
+
const [v, setV] = useState(() => ({
|
|
713
|
+
header: { left: headerFooterToDisplay(setup.header.left, names), center: headerFooterToDisplay(setup.header.center, names), right: headerFooterToDisplay(setup.header.right, names) },
|
|
714
|
+
footer: { left: headerFooterToDisplay(setup.footer.left, names), center: headerFooterToDisplay(setup.footer.center, names), right: headerFooterToDisplay(setup.footer.right, names) }
|
|
715
|
+
}));
|
|
716
|
+
const focus = useRef(null);
|
|
717
|
+
const first = useRef(null);
|
|
718
|
+
useEffect(() => {
|
|
719
|
+
first.current?.focus();
|
|
720
|
+
}, []);
|
|
721
|
+
const insert = (k) => {
|
|
722
|
+
const f = focus.current ?? { part: "header", sec: "left", el: first.current };
|
|
723
|
+
const cur = v[f.part][f.sec], a = f.el?.selectionStart ?? cur.length, b = f.el?.selectionEnd ?? a, tok = `{${names[k]}}`;
|
|
724
|
+
setV((o) => ({ ...o, [f.part]: { ...o[f.part], [f.sec]: cur.slice(0, a) + tok + cur.slice(b) } }));
|
|
725
|
+
requestAnimationFrame(() => {
|
|
726
|
+
f.el?.focus();
|
|
727
|
+
f.el?.setSelectionRange(a + tok.length, a + tok.length);
|
|
728
|
+
});
|
|
729
|
+
};
|
|
730
|
+
const ok = () => {
|
|
731
|
+
const conv = (hf) => ({ left: headerFooterFromDisplay(hf.left, names), center: headerFooterFromDisplay(hf.center, names), right: headerFooterFromDisplay(hf.right, names) });
|
|
732
|
+
apply({ header: conv(v.header), footer: conv(v.footer) });
|
|
733
|
+
};
|
|
734
|
+
return /* @__PURE__ */ jsx("div", { className: "ox-psx-modal", onMouseDown: (e) => {
|
|
735
|
+
if (e.target === e.currentTarget) close();
|
|
736
|
+
}, children: /* @__PURE__ */ jsxs(
|
|
737
|
+
"div",
|
|
738
|
+
{
|
|
739
|
+
className: "ox-psx-dlg",
|
|
740
|
+
role: "dialog",
|
|
741
|
+
"aria-modal": "true",
|
|
742
|
+
"aria-label": t("psx.fields.title"),
|
|
743
|
+
onKeyDown: (e) => {
|
|
744
|
+
if (e.key === "Escape") {
|
|
745
|
+
e.stopPropagation();
|
|
746
|
+
close();
|
|
747
|
+
} else if (e.key === "Enter" && e.target.tagName === "INPUT") {
|
|
748
|
+
e.preventDefault();
|
|
749
|
+
ok();
|
|
750
|
+
}
|
|
751
|
+
},
|
|
752
|
+
children: [
|
|
753
|
+
/* @__PURE__ */ jsx("h3", { children: t("psx.fields.title") }),
|
|
754
|
+
/* @__PURE__ */ jsx("div", { className: "ox-psx-chips", role: "group", "aria-label": t("psx.fields.insert"), children: TOKENS.map(([k, l]) => /* @__PURE__ */ jsx("button", { type: "button", onMouseDown: (e) => e.preventDefault(), onClick: () => insert(k), children: t(l) }, k)) }),
|
|
755
|
+
["header", "footer"].map((part) => /* @__PURE__ */ jsxs("fieldset", { children: [
|
|
756
|
+
/* @__PURE__ */ jsx("legend", { children: t(part === "header" ? "psx.header" : "psx.footer") }),
|
|
757
|
+
["left", "center", "right"].map((sec) => /* @__PURE__ */ jsxs("label", { children: [
|
|
758
|
+
t(sec === "left" ? "psx.left" : sec === "center" ? "psx.center" : "psx.right"),
|
|
759
|
+
/* @__PURE__ */ jsx(
|
|
760
|
+
"input",
|
|
761
|
+
{
|
|
762
|
+
ref: part === "header" && sec === "left" ? first : void 0,
|
|
763
|
+
type: "text",
|
|
764
|
+
value: v[part][sec],
|
|
765
|
+
spellCheck: false,
|
|
766
|
+
autoComplete: "off",
|
|
767
|
+
"data-hf": `${part}.${sec}`,
|
|
768
|
+
"aria-label": t("printUi.hfSection", [t(part === "header" ? "psx.header" : "psx.footer"), t(sec === "left" ? "psx.left" : sec === "center" ? "psx.center" : "psx.right")]),
|
|
769
|
+
onFocus: (e) => {
|
|
770
|
+
focus.current = { part, sec, el: e.currentTarget };
|
|
771
|
+
},
|
|
772
|
+
onChange: (e) => setV((o) => ({ ...o, [part]: { ...o[part], [sec]: e.target.value } }))
|
|
773
|
+
}
|
|
774
|
+
)
|
|
775
|
+
] }, sec))
|
|
776
|
+
] }, part)),
|
|
777
|
+
/* @__PURE__ */ jsx("p", { className: "ox-psx-hint", children: t("psx.fields.hint") }),
|
|
778
|
+
/* @__PURE__ */ jsxs("div", { className: "ox-psx-dlgfoot", children: [
|
|
779
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: close, children: t("psx.cancel") }),
|
|
780
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "ox-psx-primary", onClick: ok, children: t("ui.ok") })
|
|
781
|
+
] })
|
|
782
|
+
]
|
|
783
|
+
}
|
|
784
|
+
) });
|
|
785
|
+
}
|
|
786
|
+
function NumBox({ value, onCommit, label, min, max, className = "ox-psx-n", disabled }) {
|
|
787
|
+
const [text, setText] = useState(String(value));
|
|
788
|
+
const [bad, setBad] = useState(false);
|
|
789
|
+
const shown = useRef(value);
|
|
790
|
+
useEffect(() => {
|
|
791
|
+
if (value !== shown.current) {
|
|
792
|
+
shown.current = value;
|
|
793
|
+
setText(String(value));
|
|
794
|
+
setBad(false);
|
|
795
|
+
}
|
|
796
|
+
}, [value]);
|
|
797
|
+
return /* @__PURE__ */ jsx(
|
|
798
|
+
"input",
|
|
799
|
+
{
|
|
800
|
+
type: "text",
|
|
801
|
+
inputMode: "decimal",
|
|
802
|
+
className: `${className}${bad ? " ox-psx-bad" : ""}`,
|
|
803
|
+
"aria-label": label,
|
|
804
|
+
"aria-invalid": bad || void 0,
|
|
805
|
+
value: text,
|
|
806
|
+
disabled,
|
|
807
|
+
autoComplete: "off",
|
|
808
|
+
onChange: (e) => {
|
|
809
|
+
const s = e.target.value;
|
|
810
|
+
setText(s);
|
|
811
|
+
const n = Number(s.replace(",", "."));
|
|
812
|
+
const ok = s.trim() !== "" && isFinite(n) && n >= min && n <= max;
|
|
813
|
+
setBad(!ok);
|
|
814
|
+
if (ok) {
|
|
815
|
+
shown.current = n;
|
|
816
|
+
onCommit(n);
|
|
817
|
+
}
|
|
818
|
+
},
|
|
819
|
+
onBlur: () => {
|
|
820
|
+
if (bad) {
|
|
821
|
+
setText(String(value));
|
|
822
|
+
setBad(false);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
);
|
|
827
|
+
}
|
|
828
|
+
var round2 = (n) => Math.round(n * 100) / 100;
|
|
829
|
+
var fromUnit = (v, u) => u === "in" ? v * 25.4 : u === "cm" ? v * 10 : v;
|
|
830
|
+
var toUnit = (mm, u) => round2(u === "in" ? mm / 25.4 : u === "cm" ? mm / 10 : mm);
|
|
831
|
+
function PrintSettings(props) {
|
|
832
|
+
const { workbook: wb, pdf, readOnly = false } = props;
|
|
833
|
+
const i18n = useLocale(props.locale ?? null, props.labels);
|
|
834
|
+
const t = i18n.t;
|
|
835
|
+
const title = props.title ?? "Book1";
|
|
836
|
+
const [s, setS] = useState(() => initPrintSettings(wb, props.initial));
|
|
837
|
+
const [date] = useState(() => /* @__PURE__ */ new Date());
|
|
838
|
+
const [zoom, setZoom] = useState(null);
|
|
839
|
+
const [breakZoom, setBreakZoom] = useState(null);
|
|
840
|
+
const [mode, setMode] = useState("settings");
|
|
841
|
+
const breaksBefore = useRef(null);
|
|
842
|
+
const [fields, setFields] = useState(false);
|
|
843
|
+
const [open, setOpen] = useState({ formatting: true, hf: true });
|
|
844
|
+
const [narrow, setNarrow] = useState(false);
|
|
845
|
+
const [drawer, setDrawer] = useState(true);
|
|
846
|
+
const [busy, setBusy] = useState(false);
|
|
847
|
+
const [error, setError] = useState(null);
|
|
848
|
+
const [customMargins, setCustomMargins] = useState(false);
|
|
849
|
+
const [paperUnit, setPaperUnit] = useState(() => marginUnit(wb.culture));
|
|
850
|
+
const unit = marginUnit(wb.culture);
|
|
851
|
+
const root = useRef(null), primary = useRef(null);
|
|
852
|
+
const { preview, busy: laying } = usePreview(wb, s, pdf, title, date);
|
|
853
|
+
const pages = preview?.pages ?? [];
|
|
854
|
+
const st = currentSetup(s);
|
|
855
|
+
const sheet = wb.sheets.find((x) => x.name === s.sheet) ?? wb.activeSheet;
|
|
856
|
+
const targets = printTargets(s, wb);
|
|
857
|
+
const exportable = canExport(pdf);
|
|
858
|
+
const update = (fn) => {
|
|
859
|
+
setS(fn);
|
|
860
|
+
setError(null);
|
|
861
|
+
};
|
|
862
|
+
const patch = (p) => update((o) => applySetupPatch(o, p));
|
|
863
|
+
const change = (fn) => update((o) => applySetupChange(o, fn));
|
|
864
|
+
useEffect(() => {
|
|
865
|
+
const el = root.current;
|
|
866
|
+
if (!el) return;
|
|
867
|
+
const measure = () => setNarrow(el.clientWidth < 760);
|
|
868
|
+
measure();
|
|
869
|
+
if (typeof ResizeObserver === "undefined") {
|
|
870
|
+
window.addEventListener("resize", measure);
|
|
871
|
+
return () => window.removeEventListener("resize", measure);
|
|
872
|
+
}
|
|
873
|
+
const ro = new ResizeObserver(measure);
|
|
874
|
+
ro.observe(el);
|
|
875
|
+
return () => ro.disconnect();
|
|
876
|
+
}, []);
|
|
877
|
+
useEffect(() => {
|
|
878
|
+
primary.current?.focus();
|
|
879
|
+
}, []);
|
|
880
|
+
const close = (reason) => props.onClose(reason);
|
|
881
|
+
const doExport = async () => {
|
|
882
|
+
if (!pdf || !exportable || !targets.length || busy) return;
|
|
883
|
+
let req = { options: printExportOptions(s, wb, { title, date }), filename: `${safeName(title)}.pdf` };
|
|
884
|
+
const r = props.onBeforeExportPdf?.(req);
|
|
885
|
+
if (r === false) return;
|
|
886
|
+
if (r) req = r;
|
|
887
|
+
setBusy(true);
|
|
888
|
+
setError(null);
|
|
889
|
+
try {
|
|
890
|
+
const bytes = pdf.exportPdfAsync ? await pdf.exportPdfAsync(wb, req.options) : pdf.exportPdf(wb, req.options);
|
|
891
|
+
persistPrintSettings(s, wb, readOnly);
|
|
892
|
+
if (props.onExportPdf) await props.onExportPdf(bytes, req.filename);
|
|
893
|
+
else download(req.filename, bytes, "application/pdf");
|
|
894
|
+
close("export");
|
|
895
|
+
} catch (e) {
|
|
896
|
+
setError(message(e));
|
|
897
|
+
} finally {
|
|
898
|
+
setBusy(false);
|
|
899
|
+
}
|
|
900
|
+
};
|
|
901
|
+
const doPrint = () => {
|
|
902
|
+
if (!targets.length) return;
|
|
903
|
+
const items = targets.map((sh) => ({ sheet: sh, setup: browserPrintSetup(s, sh), pageBreaks: s.pageBreaks[sh.name] }));
|
|
904
|
+
persistPrintSettings(s, wb, readOnly);
|
|
905
|
+
close("print");
|
|
906
|
+
setTimeout(() => printSheets(items, { fileName: title, date }), 0);
|
|
907
|
+
};
|
|
908
|
+
const enterBreaks = () => {
|
|
909
|
+
breaksBefore.current = s.pageBreaks[s.sheet] ?? sheet.pageBreaks;
|
|
910
|
+
setMode("breaks");
|
|
911
|
+
};
|
|
912
|
+
const leaveBreaks = (keep) => {
|
|
913
|
+
if (!keep && breaksBefore.current) {
|
|
914
|
+
const pb = breaksBefore.current;
|
|
915
|
+
update((o) => setWorkingPageBreaks(o, o.sheet, pb));
|
|
916
|
+
}
|
|
917
|
+
setMode("settings");
|
|
918
|
+
};
|
|
919
|
+
const onKeyDown = (e) => {
|
|
920
|
+
e.stopPropagation();
|
|
921
|
+
if (e.key === "Escape") {
|
|
922
|
+
e.preventDefault();
|
|
923
|
+
if (fields) setFields(false);
|
|
924
|
+
else if (mode === "breaks") leaveBreaks(false);
|
|
925
|
+
else close("cancel");
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
if ((e.ctrlKey || e.metaKey) && (e.key === "p" || e.key === "P")) {
|
|
929
|
+
e.preventDefault();
|
|
930
|
+
return;
|
|
931
|
+
}
|
|
932
|
+
if (e.key === "Tab") {
|
|
933
|
+
const el = root.current;
|
|
934
|
+
if (!el) return;
|
|
935
|
+
const list = [...el.querySelectorAll('button:not(:disabled),input:not(:disabled),select:not(:disabled),textarea,[tabindex]:not([tabindex="-1"])')].filter((x) => x.offsetParent !== null || x === document.activeElement);
|
|
936
|
+
if (!list.length) return;
|
|
937
|
+
const i = list.indexOf(document.activeElement);
|
|
938
|
+
if (e.shiftKey && i <= 0) {
|
|
939
|
+
e.preventDefault();
|
|
940
|
+
list[list.length - 1].focus();
|
|
941
|
+
} else if (!e.shiftKey && i === list.length - 1) {
|
|
942
|
+
e.preventDefault();
|
|
943
|
+
list[0].focus();
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
};
|
|
947
|
+
const scaleMode = printScaleMode(st);
|
|
948
|
+
const preset = marginPresetOf(st.margins);
|
|
949
|
+
const marginSel = customMargins || preset === "custom" ? "custom" : preset;
|
|
950
|
+
const hfOn = headerFooterFields(st);
|
|
951
|
+
const frozen = frozenPrintTitles(sheet);
|
|
952
|
+
const total = laying && !preview ? null : pages.length;
|
|
953
|
+
const radio = (name, checked, onChange, label, extra) => /* @__PURE__ */ jsxs("label", { children: [
|
|
954
|
+
/* @__PURE__ */ jsx("input", { type: "radio", name, checked, disabled: extra?.disabled, onChange }),
|
|
955
|
+
label
|
|
956
|
+
] });
|
|
957
|
+
const check = (checked, onChange, label, extra) => /* @__PURE__ */ jsxs("label", { title: extra?.title, children: [
|
|
958
|
+
/* @__PURE__ */ jsx("input", { type: "checkbox", checked, disabled: extra?.disabled, onChange: (e) => onChange(e.target.checked) }),
|
|
959
|
+
label
|
|
960
|
+
] });
|
|
961
|
+
const section = (key, label, body) => /* @__PURE__ */ jsxs("div", { className: "ox-psx-sec", children: [
|
|
962
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: "ox-psx-sum", "aria-expanded": open[key], onClick: () => setOpen((o) => ({ ...o, [key]: !o[key] })), children: [
|
|
963
|
+
label,
|
|
964
|
+
/* @__PURE__ */ jsx(Icon.caret, {})
|
|
965
|
+
] }),
|
|
966
|
+
open[key] && body
|
|
967
|
+
] });
|
|
968
|
+
const what = (w) => update((o) => ({ ...o, what: w }));
|
|
969
|
+
const visibleSheets = wb.sheets.filter((x) => !x.hidden);
|
|
970
|
+
const cp = st.customPaper ?? { width: PAPER_SIZES2[st.paperSize].w, height: PAPER_SIZES2[st.paperSize].h };
|
|
971
|
+
const uid = useMemo(() => `psx${Math.random().toString(36).slice(2, 8)}`, []);
|
|
972
|
+
const panel = /* @__PURE__ */ jsxs("div", { className: "ox-psx-panel", "data-open": drawer, role: "form", "aria-label": t("psx.settings"), children: [
|
|
973
|
+
readOnly && /* @__PURE__ */ jsx("p", { className: "ox-psx-ro", children: t("psx.readOnly") }),
|
|
974
|
+
/* @__PURE__ */ jsxs("div", { className: "ox-psx-sec", children: [
|
|
975
|
+
/* @__PURE__ */ jsx("h3", { id: `${uid}-what`, children: t("psx.what") }),
|
|
976
|
+
/* @__PURE__ */ jsxs("div", { className: "ox-psx-col", role: "radiogroup", "aria-labelledby": `${uid}-what`, children: [
|
|
977
|
+
radio(`${uid}-what`, s.what === "sheet", () => what("sheet"), /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
978
|
+
t("psx.currentSheet"),
|
|
979
|
+
" ",
|
|
980
|
+
/* @__PURE__ */ jsxs("span", { style: { color: "var(--ox-muted,#616161)" }, children: [
|
|
981
|
+
"(",
|
|
982
|
+
s.sheet,
|
|
983
|
+
")"
|
|
984
|
+
] })
|
|
985
|
+
] })),
|
|
986
|
+
radio(`${uid}-what`, s.what === "workbook", () => what("workbook"), t("psx.workbook")),
|
|
987
|
+
s.what === "workbook" && /* @__PURE__ */ jsxs("div", { className: "ox-psx-sub", style: { marginInlineStart: 26 }, children: [
|
|
988
|
+
visibleSheets.map((x) => /* @__PURE__ */ jsx(Fragment, { children: check(s.sheets.includes(x.name), (on) => update((o) => ({ ...o, sheets: on ? wb.sheets.filter((y) => y.name === x.name || o.sheets.includes(y.name)).map((y) => y.name) : o.sheets.filter((n) => n !== x.name) })), x.name) }, x.name)),
|
|
989
|
+
!s.sheets.length && /* @__PURE__ */ jsx("p", { className: "ox-psx-hint", role: "alert", children: t("psx.noSheets") })
|
|
990
|
+
] }),
|
|
991
|
+
radio(`${uid}-what`, s.what === "selection", () => what("selection"), /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
992
|
+
t("psx.selection"),
|
|
993
|
+
s.selection && /* @__PURE__ */ jsxs("span", { style: { color: "var(--ox-muted,#616161)" }, children: [
|
|
994
|
+
" (",
|
|
995
|
+
rangeName2(s.selection),
|
|
996
|
+
")"
|
|
997
|
+
] })
|
|
998
|
+
] }), { disabled: !s.selection })
|
|
999
|
+
] }),
|
|
1000
|
+
s.what === "workbook" && /* @__PURE__ */ jsxs("div", { className: "ox-psx-col", style: { marginTop: 10 }, children: [
|
|
1001
|
+
/* @__PURE__ */ jsxs("label", { style: { display: "flex", flexDirection: "column", alignItems: "stretch", gap: 4 }, children: [
|
|
1002
|
+
t("psx.applyTo"),
|
|
1003
|
+
/* @__PURE__ */ jsxs("select", { "aria-label": t("psx.applyTo"), value: s.applyTo, onChange: (e) => update((o) => ({ ...o, applyTo: e.target.value })), children: [
|
|
1004
|
+
/* @__PURE__ */ jsx("option", { value: "all", children: t("psx.applyAll") }),
|
|
1005
|
+
/* @__PURE__ */ jsx("option", { value: "sheet", children: t("psx.applySheet") })
|
|
1006
|
+
] })
|
|
1007
|
+
] }),
|
|
1008
|
+
/* @__PURE__ */ jsxs("label", { style: { display: "flex", flexDirection: "column", alignItems: "stretch", gap: 4 }, children: [
|
|
1009
|
+
t("psx.settingsOf"),
|
|
1010
|
+
/* @__PURE__ */ jsx("select", { "aria-label": t("psx.settingsOf"), value: s.sheet, onChange: (e) => update((o) => ({ ...o, sheet: e.target.value })), children: visibleSheets.map((x) => /* @__PURE__ */ jsx("option", { value: x.name, children: x.name }, x.name)) })
|
|
1011
|
+
] })
|
|
1012
|
+
] })
|
|
1013
|
+
] }),
|
|
1014
|
+
/* @__PURE__ */ jsxs("div", { className: "ox-psx-sec", children: [
|
|
1015
|
+
/* @__PURE__ */ jsx("h3", { children: /* @__PURE__ */ jsx("label", { htmlFor: `${uid}-paper`, children: t("psx.paperSize") }) }),
|
|
1016
|
+
/* @__PURE__ */ jsxs(
|
|
1017
|
+
"select",
|
|
1018
|
+
{
|
|
1019
|
+
id: `${uid}-paper`,
|
|
1020
|
+
value: st.customPaper ? "custom" : st.paperSize,
|
|
1021
|
+
onChange: (e) => {
|
|
1022
|
+
const v = e.target.value;
|
|
1023
|
+
if (v === "custom") patch({ customPaper: { width: cp.width, height: cp.height } });
|
|
1024
|
+
else patch({ paperSize: v, customPaper: null });
|
|
1025
|
+
},
|
|
1026
|
+
children: [
|
|
1027
|
+
PAPERS.map((p) => /* @__PURE__ */ jsx("option", { value: p, children: paperLabel(p, unit, i18n.locale) }, p)),
|
|
1028
|
+
/* @__PURE__ */ jsx("option", { value: "custom", children: t("psx.customSize") })
|
|
1029
|
+
]
|
|
1030
|
+
}
|
|
1031
|
+
),
|
|
1032
|
+
st.customPaper && /* @__PURE__ */ jsxs("div", { className: "ox-psx-row", style: { marginTop: 8 }, children: [
|
|
1033
|
+
/* @__PURE__ */ jsx(NumBox, { label: t("psx.width"), value: toUnit(st.customPaper.width, paperUnit), min: toUnit(10, paperUnit), max: toUnit(5e3, paperUnit), onCommit: (n) => change((p) => ({ customPaper: { width: fromUnit(n, paperUnit), height: p.customPaper?.height ?? cp.height } })) }),
|
|
1034
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: "\xD7" }),
|
|
1035
|
+
/* @__PURE__ */ jsx(NumBox, { label: t("psx.height"), value: toUnit(st.customPaper.height, paperUnit), min: toUnit(10, paperUnit), max: toUnit(5e3, paperUnit), onCommit: (n) => change((p) => ({ customPaper: { width: p.customPaper?.width ?? cp.width, height: fromUnit(n, paperUnit) } })) }),
|
|
1036
|
+
/* @__PURE__ */ jsxs("select", { "aria-label": t("psx.unit"), style: { width: "auto" }, value: paperUnit, onChange: (e) => setPaperUnit(e.target.value), children: [
|
|
1037
|
+
/* @__PURE__ */ jsx("option", { value: "in", children: t("psx.inches") }),
|
|
1038
|
+
/* @__PURE__ */ jsx("option", { value: "cm", children: t("psx.cm") }),
|
|
1039
|
+
/* @__PURE__ */ jsx("option", { value: "mm", children: t("psx.mm") })
|
|
1040
|
+
] })
|
|
1041
|
+
] })
|
|
1042
|
+
] }),
|
|
1043
|
+
/* @__PURE__ */ jsxs("div", { className: "ox-psx-sec", children: [
|
|
1044
|
+
/* @__PURE__ */ jsx("h3", { id: `${uid}-or`, children: t("psx.orientation") }),
|
|
1045
|
+
/* @__PURE__ */ jsxs("div", { className: "ox-psx-row", role: "radiogroup", "aria-labelledby": `${uid}-or`, style: { gap: 20 }, children: [
|
|
1046
|
+
radio(`${uid}-or`, st.orientation === "landscape", () => patch({ orientation: "landscape" }), t("psx.landscape")),
|
|
1047
|
+
radio(`${uid}-or`, st.orientation === "portrait", () => patch({ orientation: "portrait" }), t("psx.portrait"))
|
|
1048
|
+
] })
|
|
1049
|
+
] }),
|
|
1050
|
+
/* @__PURE__ */ jsxs("div", { className: "ox-psx-sec", children: [
|
|
1051
|
+
/* @__PURE__ */ jsx("h3", { children: /* @__PURE__ */ jsx("label", { htmlFor: `${uid}-scale`, children: t("psx.scale") }) }),
|
|
1052
|
+
/* @__PURE__ */ jsxs("select", { id: `${uid}-scale`, value: scaleMode, onChange: (e) => {
|
|
1053
|
+
const m = e.target.value;
|
|
1054
|
+
patch(scaleModePatch(m, m === "custom" ? st.fitToPage ? 100 : st.scale === 100 ? 90 : st.scale : void 0));
|
|
1055
|
+
}, children: [
|
|
1056
|
+
/* @__PURE__ */ jsx("option", { value: "normal", children: t("psx.scale.normal") }),
|
|
1057
|
+
/* @__PURE__ */ jsx("option", { value: "fitWidth", children: t("psx.scale.fitWidth") }),
|
|
1058
|
+
/* @__PURE__ */ jsx("option", { value: "fitHeight", children: t("psx.scale.fitHeight") }),
|
|
1059
|
+
/* @__PURE__ */ jsx("option", { value: "fitPage", children: t("psx.scale.fitPage") }),
|
|
1060
|
+
scaleMode === "fitCustom" && /* @__PURE__ */ jsx("option", { value: "fitCustom", children: t("psx.scale.fitCustom", { w: st.fitToWidth || "\u221E", h: st.fitToHeight || "\u221E" }) }),
|
|
1061
|
+
/* @__PURE__ */ jsx("option", { value: "custom", children: t("psx.scale.custom") })
|
|
1062
|
+
] }),
|
|
1063
|
+
scaleMode === "custom" && /* @__PURE__ */ jsxs("div", { className: "ox-psx-row", style: { marginTop: 8 }, children: [
|
|
1064
|
+
/* @__PURE__ */ jsx(NumBox, { label: t("psx.percent"), value: st.scale, min: 10, max: 400, onCommit: (n) => patch(scaleModePatch("custom", n)) }),
|
|
1065
|
+
/* @__PURE__ */ jsx("span", { children: "%" })
|
|
1066
|
+
] })
|
|
1067
|
+
] }),
|
|
1068
|
+
/* @__PURE__ */ jsxs("div", { className: "ox-psx-sec", children: [
|
|
1069
|
+
/* @__PURE__ */ jsx("h3", { children: /* @__PURE__ */ jsx("label", { htmlFor: `${uid}-mg`, children: t("psx.margins") }) }),
|
|
1070
|
+
/* @__PURE__ */ jsxs("select", { id: `${uid}-mg`, value: marginSel, onChange: (e) => {
|
|
1071
|
+
const v = e.target.value;
|
|
1072
|
+
if (v === "custom") setCustomMargins(true);
|
|
1073
|
+
else {
|
|
1074
|
+
setCustomMargins(false);
|
|
1075
|
+
patch({ margins: v });
|
|
1076
|
+
}
|
|
1077
|
+
}, children: [
|
|
1078
|
+
/* @__PURE__ */ jsx("option", { value: "normal", children: t("psx.margins.normal") }),
|
|
1079
|
+
/* @__PURE__ */ jsx("option", { value: "narrow", children: t("psx.margins.narrow") }),
|
|
1080
|
+
/* @__PURE__ */ jsx("option", { value: "wide", children: t("psx.margins.wide") }),
|
|
1081
|
+
/* @__PURE__ */ jsx("option", { value: "custom", children: t("psx.margins.custom") })
|
|
1082
|
+
] }),
|
|
1083
|
+
marginSel === "custom" && /* @__PURE__ */ jsxs("div", { className: "ox-psx-grid", style: { marginTop: 10 }, children: [
|
|
1084
|
+
MARGIN_KEYS.map(([k, l]) => /* @__PURE__ */ jsxs("label", { style: { display: "contents" }, children: [
|
|
1085
|
+
/* @__PURE__ */ jsx("span", { children: t(l) }),
|
|
1086
|
+
/* @__PURE__ */ jsx(
|
|
1087
|
+
NumBox,
|
|
1088
|
+
{
|
|
1089
|
+
className: "",
|
|
1090
|
+
label: t("printUi.marginLabel", [t("psx.margins"), t(l), unit === "in" ? t("psx.inches") : t("psx.cm")]),
|
|
1091
|
+
value: toUnit(st.margins[k] * 25.4, unit),
|
|
1092
|
+
min: 0,
|
|
1093
|
+
max: toUnit(20 * 25.4, unit),
|
|
1094
|
+
onCommit: (n) => patch({ margins: { [k]: Math.round(fromUnit(n, unit) / 25.4 * 1e4) / 1e4 } })
|
|
1095
|
+
}
|
|
1096
|
+
)
|
|
1097
|
+
] }, k)),
|
|
1098
|
+
/* @__PURE__ */ jsx("span", { className: "ox-psx-hint", style: { gridColumn: "1 / -1", margin: 0 }, children: unit === "in" ? t("psx.inches") : t("psx.cm") })
|
|
1099
|
+
] })
|
|
1100
|
+
] }),
|
|
1101
|
+
/* @__PURE__ */ jsx("div", { className: "ox-psx-sec", children: /* @__PURE__ */ jsx("button", { type: "button", className: "ox-psx-link", onClick: enterBreaks, disabled: !targets.length, children: t("psx.breaks") }) }),
|
|
1102
|
+
section("formatting", t("psx.formatting"), /* @__PURE__ */ jsxs("div", { className: "ox-psx-col", children: [
|
|
1103
|
+
check(st.gridlines, (v) => patch({ gridlines: v }), t("psx.gridlines")),
|
|
1104
|
+
check(s.notes === "atEnd", (v) => update((o) => ({ ...o, notes: v ? "atEnd" : "none" })), t("psx.notes"), { disabled: !hasLayout(pdf) && !exportable }),
|
|
1105
|
+
check(st.headings, (v) => patch({ headings: v }), t("psx.headings")),
|
|
1106
|
+
check(st.blackAndWhite, (v) => patch({ blackAndWhite: v }), t("psx.bw")),
|
|
1107
|
+
/* @__PURE__ */ jsxs("div", { style: { marginTop: 8 }, children: [
|
|
1108
|
+
/* @__PURE__ */ jsx("div", { id: `${uid}-order`, style: { fontWeight: 600, fontSize: 13, marginBottom: 6 }, children: t("psx.pageOrder") }),
|
|
1109
|
+
/* @__PURE__ */ jsxs("div", { className: "ox-psx-col", role: "radiogroup", "aria-labelledby": `${uid}-order`, children: [
|
|
1110
|
+
radio(`${uid}-order`, st.pageOrder === "overThenDown", () => patch({ pageOrder: "overThenDown" }), t("psx.overThenDown")),
|
|
1111
|
+
radio(`${uid}-order`, st.pageOrder === "downThenOver", () => patch({ pageOrder: "downThenOver" }), t("psx.downThenOver"))
|
|
1112
|
+
] })
|
|
1113
|
+
] }),
|
|
1114
|
+
/* @__PURE__ */ jsxs("div", { style: { marginTop: 8 }, children: [
|
|
1115
|
+
/* @__PURE__ */ jsx("div", { style: { fontWeight: 600, fontSize: 13, marginBottom: 6 }, children: t("psx.alignment") }),
|
|
1116
|
+
/* @__PURE__ */ jsxs("div", { className: "ox-psx-grid", style: { gridTemplateColumns: "auto 1fr" }, children: [
|
|
1117
|
+
/* @__PURE__ */ jsx("label", { htmlFor: `${uid}-ha`, children: t("psx.horizontal") }),
|
|
1118
|
+
/* @__PURE__ */ jsxs("select", { id: `${uid}-ha`, value: st.centerHorizontally ? "center" : "left", onChange: (e) => patch({ centerHorizontally: e.target.value === "center" }), children: [
|
|
1119
|
+
/* @__PURE__ */ jsx("option", { value: "left", children: t("psx.left") }),
|
|
1120
|
+
/* @__PURE__ */ jsx("option", { value: "center", children: t("psx.center") })
|
|
1121
|
+
] }),
|
|
1122
|
+
/* @__PURE__ */ jsx("label", { htmlFor: `${uid}-va`, children: t("psx.vertical") }),
|
|
1123
|
+
/* @__PURE__ */ jsxs("select", { id: `${uid}-va`, value: st.centerVertically ? "middle" : "top", onChange: (e) => patch({ centerVertically: e.target.value === "middle" }), children: [
|
|
1124
|
+
/* @__PURE__ */ jsx("option", { value: "top", children: t("psx.top") }),
|
|
1125
|
+
/* @__PURE__ */ jsx("option", { value: "middle", children: t("psx.middle") })
|
|
1126
|
+
] })
|
|
1127
|
+
] })
|
|
1128
|
+
] })
|
|
1129
|
+
] })),
|
|
1130
|
+
section("hf", t("psx.hf"), /* @__PURE__ */ jsxs("div", { className: "ox-psx-col", children: [
|
|
1131
|
+
HF_FIELDS.map(([f, l]) => /* @__PURE__ */ jsx(Fragment, { children: check(hfOn[f], (v) => change((p) => setHeaderFooterField(p, f, v)), t(l)) }, f)),
|
|
1132
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "ox-psx-tbtn", style: { alignSelf: "flex-start" }, onClick: () => setFields(true), children: t("psx.hf.edit") }),
|
|
1133
|
+
/* @__PURE__ */ jsx("div", { style: { marginTop: 10, fontWeight: 600, fontSize: 13 }, children: t("psx.titles") }),
|
|
1134
|
+
check(
|
|
1135
|
+
repeatsFrozenPanes(st, sheet, "row"),
|
|
1136
|
+
(v) => change((p, name) => {
|
|
1137
|
+
const f = frozenPrintTitles(wb.sheets.find((x) => x.name === name) ?? sheet);
|
|
1138
|
+
return { printTitleRows: v ? f.rows : null };
|
|
1139
|
+
}),
|
|
1140
|
+
/* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
1141
|
+
t("psx.repeatRows"),
|
|
1142
|
+
!frozen.rows && /* @__PURE__ */ jsxs("span", { style: { color: "var(--ox-muted,#616161)" }, children: [
|
|
1143
|
+
" (",
|
|
1144
|
+
t("psx.nothingFrozen"),
|
|
1145
|
+
")"
|
|
1146
|
+
] })
|
|
1147
|
+
] }),
|
|
1148
|
+
{ disabled: !frozen.rows }
|
|
1149
|
+
),
|
|
1150
|
+
check(
|
|
1151
|
+
repeatsFrozenPanes(st, sheet, "col"),
|
|
1152
|
+
(v) => change((p, name) => {
|
|
1153
|
+
const f = frozenPrintTitles(wb.sheets.find((x) => x.name === name) ?? sheet);
|
|
1154
|
+
return { printTitleCols: v ? f.cols : null };
|
|
1155
|
+
}),
|
|
1156
|
+
/* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
1157
|
+
t("psx.repeatCols"),
|
|
1158
|
+
!frozen.cols && /* @__PURE__ */ jsxs("span", { style: { color: "var(--ox-muted,#616161)" }, children: [
|
|
1159
|
+
" (",
|
|
1160
|
+
t("psx.nothingFrozen"),
|
|
1161
|
+
")"
|
|
1162
|
+
] })
|
|
1163
|
+
] }),
|
|
1164
|
+
{ disabled: !frozen.cols }
|
|
1165
|
+
),
|
|
1166
|
+
/* @__PURE__ */ jsxs("div", { className: "ox-psx-grid", style: { gridTemplateColumns: "auto 1fr", marginTop: 6 }, children: [
|
|
1167
|
+
/* @__PURE__ */ jsx(TitlesBox, { t, axis: "row", setup: st, onCommit: (v) => patch({ printTitleRows: v }) }),
|
|
1168
|
+
/* @__PURE__ */ jsx(TitlesBox, { t, axis: "col", setup: st, onCommit: (v) => patch({ printTitleCols: v }) })
|
|
1169
|
+
] })
|
|
1170
|
+
] }))
|
|
1171
|
+
] });
|
|
1172
|
+
const totalText = total === null ? t("psx.counting") : t("psx.total", { n: total });
|
|
1173
|
+
const rootClass = `ox-psx${narrow ? " ox-psx-narrow" : ""}${props.colorScheme === "dark" ? " ox-psx-dark" : ""}${props.className ? " " + props.className : ""}`;
|
|
1174
|
+
return /* @__PURE__ */ jsxs("div", { className: rootClass, ref: root, role: "dialog", "aria-modal": "true", "aria-label": t("psx.title"), dir: props.dir ?? (props.locale ? i18n.dir : void 0), lang: props.locale ? i18n.locale : void 0, onKeyDown, tabIndex: -1, children: [
|
|
1175
|
+
/* @__PURE__ */ jsx("style", { children: PRINT_SETTINGS_CSS }),
|
|
1176
|
+
/* @__PURE__ */ jsx("div", { className: "ox-psx-bar", children: mode === "breaks" ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
1177
|
+
/* @__PURE__ */ jsx("h2", { children: t("psx.breaks.title") }),
|
|
1178
|
+
/* @__PURE__ */ jsx("span", { className: "ox-psx-total", "aria-live": "polite", children: totalText }),
|
|
1179
|
+
/* @__PURE__ */ jsx("span", { className: "ox-psx-grow" }),
|
|
1180
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => update((o) => setWorkingPageBreaks(o, o.sheet, { rows: [], cols: [] })), children: t("psx.breaks.reset") }),
|
|
1181
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "ox-psx-outline", onClick: () => leaveBreaks(false), children: t("psx.cancel") }),
|
|
1182
|
+
/* @__PURE__ */ jsx("button", { type: "button", className: "ox-psx-primary", ref: primary, onClick: () => leaveBreaks(true), children: t("psx.breaks.confirm") })
|
|
1183
|
+
] }) : /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
1184
|
+
/* @__PURE__ */ jsx("h2", { children: t("psx.title") }),
|
|
1185
|
+
/* @__PURE__ */ jsx("span", { className: "ox-psx-total", "aria-live": "polite", "data-total": total ?? "", children: totalText }),
|
|
1186
|
+
/* @__PURE__ */ jsx("span", { className: "ox-psx-grow" }),
|
|
1187
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: "ox-psx-drawer-btn", "aria-expanded": drawer, onClick: () => setDrawer((d) => !d), children: [
|
|
1188
|
+
/* @__PURE__ */ jsx(Icon.gear, {}),
|
|
1189
|
+
t("psx.settings")
|
|
1190
|
+
] }),
|
|
1191
|
+
/* @__PURE__ */ jsx("button", { type: "button", onClick: () => close("cancel"), children: t("psx.cancel") }),
|
|
1192
|
+
exportable ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
1193
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: "ox-psx-outline", onClick: doPrint, disabled: !targets.length || busy, children: [
|
|
1194
|
+
/* @__PURE__ */ jsx(Icon.print, {}),
|
|
1195
|
+
t("psx.print")
|
|
1196
|
+
] }),
|
|
1197
|
+
/* @__PURE__ */ jsxs("button", { type: "button", className: "ox-psx-primary", ref: primary, onClick: () => {
|
|
1198
|
+
void doExport();
|
|
1199
|
+
}, disabled: !targets.length || busy, children: [
|
|
1200
|
+
/* @__PURE__ */ jsx(Icon.download, {}),
|
|
1201
|
+
busy ? t("psx.exporting") : t("psx.exportPdf")
|
|
1202
|
+
] })
|
|
1203
|
+
] }) : /* @__PURE__ */ jsxs("button", { type: "button", className: "ox-psx-primary", ref: primary, onClick: doPrint, disabled: !targets.length, children: [
|
|
1204
|
+
/* @__PURE__ */ jsx(Icon.print, {}),
|
|
1205
|
+
t("psx.print")
|
|
1206
|
+
] })
|
|
1207
|
+
] }) }),
|
|
1208
|
+
error && /* @__PURE__ */ jsx("p", { className: "ox-psx-err", role: "alert", children: error }),
|
|
1209
|
+
/* @__PURE__ */ jsxs("div", { className: "ox-psx-body", children: [
|
|
1210
|
+
mode === "breaks" ? /* @__PURE__ */ jsx(BreakEditor, { t, sheet, pages, breaks: s.pageBreaks[s.sheet] ?? sheet.pageBreaks, setBreaks: (pb) => update((o) => setWorkingPageBreaks(o, o.sheet, pb)), fitIgnored: st.fitToPage, zoom: breakZoom, setZoom: setBreakZoom }) : /* @__PURE__ */ jsx(PreviewPane, { t, preview, busy: laying, total: pages.length, zoom, setZoom }),
|
|
1211
|
+
mode === "settings" && panel
|
|
1212
|
+
] }),
|
|
1213
|
+
fields && /* @__PURE__ */ jsx(FieldsDialog, { t, setup: st, close: () => setFields(false), apply: (hf) => {
|
|
1214
|
+
change(() => ({ header: hf.header, footer: hf.footer }));
|
|
1215
|
+
setFields(false);
|
|
1216
|
+
} })
|
|
1217
|
+
] });
|
|
1218
|
+
}
|
|
1219
|
+
function TitlesBox({ t, axis, setup, onCommit }) {
|
|
1220
|
+
const value = titlesText(setup, axis);
|
|
1221
|
+
const [text, setText] = useState(value);
|
|
1222
|
+
const [bad, setBad] = useState(false);
|
|
1223
|
+
const last = useRef(value);
|
|
1224
|
+
useEffect(() => {
|
|
1225
|
+
if (value !== last.current) {
|
|
1226
|
+
last.current = value;
|
|
1227
|
+
setText(value);
|
|
1228
|
+
setBad(false);
|
|
1229
|
+
}
|
|
1230
|
+
}, [value]);
|
|
1231
|
+
const label = t(axis === "row" ? "psx.rowsToRepeat" : "psx.colsToRepeat");
|
|
1232
|
+
return /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
1233
|
+
/* @__PURE__ */ jsx("span", { children: label }),
|
|
1234
|
+
/* @__PURE__ */ jsx(
|
|
1235
|
+
"input",
|
|
1236
|
+
{
|
|
1237
|
+
type: "text",
|
|
1238
|
+
className: bad ? "ox-psx-bad" : void 0,
|
|
1239
|
+
"aria-label": label,
|
|
1240
|
+
"aria-invalid": bad || void 0,
|
|
1241
|
+
title: bad ? t("psx.badTitles") : void 0,
|
|
1242
|
+
placeholder: axis === "row" ? "$1:$2" : "$A:$B",
|
|
1243
|
+
value: text,
|
|
1244
|
+
spellCheck: false,
|
|
1245
|
+
autoComplete: "off",
|
|
1246
|
+
onChange: (e) => {
|
|
1247
|
+
setText(e.target.value);
|
|
1248
|
+
const v = parsePrintTitles(e.target.value, axis);
|
|
1249
|
+
setBad(v === void 0);
|
|
1250
|
+
if (v !== void 0) {
|
|
1251
|
+
last.current = e.target.value.trim() === "" ? "" : titlesText({ ...setup, printTitleRows: axis === "row" ? v : setup.printTitleRows, printTitleCols: axis === "col" ? v : setup.printTitleCols }, axis);
|
|
1252
|
+
onCommit(v);
|
|
1253
|
+
}
|
|
1254
|
+
},
|
|
1255
|
+
onBlur: () => {
|
|
1256
|
+
if (bad) {
|
|
1257
|
+
setText(value);
|
|
1258
|
+
setBad(false);
|
|
1259
|
+
}
|
|
1260
|
+
}
|
|
1261
|
+
}
|
|
1262
|
+
)
|
|
1263
|
+
] });
|
|
1264
|
+
}
|
|
1265
|
+
export {
|
|
1266
|
+
PRINT_SETTINGS_CSS,
|
|
1267
|
+
PrintSettings
|
|
1268
|
+
};
|