@evotecit/officeimo 0.1.4 → 0.1.9
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/README.md +18 -4
- package/bundles/officeimo-canopyx-adapter.js +1444 -0
- package/bundles/officeimo-canopyx-adapter.min.js +2 -0
- package/bundles/officeimo-canopyx-adapter.min.mjs +2 -0
- package/bundles/officeimo-canopyx-adapter.mjs +1426 -0
- package/bundles/officeimo-canopyx.js +108 -50
- package/bundles/officeimo-canopyx.min.js +2 -0
- package/bundles/officeimo-canopyx.min.mjs +2 -0
- package/bundles/officeimo-canopyx.mjs +96 -38
- package/bundles/officeimo-csv.min.js +2 -0
- package/bundles/officeimo-csv.min.mjs +2 -0
- package/bundles/officeimo-datatables-adapter.js +626 -0
- package/bundles/officeimo-datatables-adapter.min.js +2 -0
- package/bundles/officeimo-datatables-adapter.min.mjs +2 -0
- package/bundles/officeimo-datatables-adapter.mjs +617 -0
- package/bundles/officeimo-datatables.js +55 -10
- package/bundles/officeimo-datatables.min.js +2 -0
- package/bundles/officeimo-datatables.min.mjs +2 -0
- package/bundles/officeimo-datatables.mjs +51 -6
- package/bundles/officeimo-execution.min.js +2 -0
- package/bundles/officeimo-execution.min.mjs +2 -0
- package/bundles/officeimo-pdf.min.js +2 -0
- package/bundles/officeimo-pdf.min.mjs +2 -0
- package/bundles/officeimo-xlsx.min.js +2 -0
- package/bundles/officeimo-xlsx.min.mjs +2 -0
- package/bundles/officeimo.min.js +2 -0
- package/bundles/officeimo.min.mjs +2 -0
- package/bundles/officeimo.mjs +2 -1
- package/dist/integrations/canopyx/pdf-number.d.ts +1 -1
- package/dist/integrations/canopyx/pdf-number.js +89 -35
- package/dist/integrations/canopyx/pivot.d.ts +1 -1
- package/dist/integrations/canopyx/pivot.js +4 -0
- package/dist/integrations/canopyx/source.js +2 -2
- package/dist/integrations/canopyx/types.d.ts +1 -0
- package/dist/integrations/datatables/snapshot.js +51 -6
- package/package.json +6 -2
package/bundles/officeimo.mjs
CHANGED
|
@@ -11536,5 +11536,6 @@ const _m0 = (() => {
|
|
|
11536
11536
|
const _exports = Object.freeze({ core: _m1, zip: _m14, xml: _m17, opc: _m18, xlsx: _m21, csv: _m50, pdf: _m54, Workbook: _m21.Workbook, Worksheet: _m21.Worksheet, Cell: _m21.Cell, FormulaCell: _m21.FormulaCell, StyleRegistry: _m21.StyleRegistry, NumberFormats: _m21.NumberFormats, writeXlsx: _m21.writeXlsx, writeXlsxTo: _m21.writeXlsxTo, writeCsv: _m50.writeCsv, writeCsvTo: _m50.writeCsvTo, createGroupedReport: _m8.createGroupedReport, writeGroupedXlsx: _m48.writeGroupedXlsx, writeGroupedXlsxTo: _m48.writeGroupedXlsxTo, addGroupedXlsx: _m48.addGroupedXlsx, writeGroupedPdf: _m83.writeGroupedPdf, writeGroupedPdfTo: _m83.writeGroupedPdfTo, pdfGroupedTable: _m83.pdfGroupedTable, writePdf: _m54.writePdf, writePdfTo: _m54.writePdfTo, writePdfDocument: _m54.writePdfDocument, writePdfDocumentTo: _m54.writePdfDocumentTo, pdfTable: _m54.pdfTable, PdfFont: _m54.PdfFont, preflightPdfText: _m54.preflightPdfText, OfficeIMOError: _m1.OfficeIMOError, NotSupportedError: _m1.NotSupportedError, detectFeatures: _m1.detectFeatures, saveBlob: _m1.saveBlob, ExportCell: _m1.ExportCell });
|
|
11537
11537
|
return _exports;
|
|
11538
11538
|
})();
|
|
11539
|
+
const __officeimoModules = Object.freeze({ "81b3d47c02b7d8443b79e02b3cfb52032d6b73d9a3fb592b777ebe028ad0ef00": _m1, "6cfd3e806439f6301003a2d1699a74fdfa574d935550ab62b97b528728eaee1f": _m23, "b48bcab805d4c75294dd8d8e8dc57f96d9db3f5af31a8f0ddc6562f010f566e4": _m50, "d6587a933b36ccfdba9a2a252389924ac8461f672b3a500082cceb5e53c8b0b6": _m21, "027aafa08408056b10d7d717d63d1f7c0ee20ecfc68213aa66feacc75ec525fe": _m54, "a10003e971cd5ec2cee127bc9b029a0aa06fe3d50112838929d7a04a55e177c0": _m47, "732224f6995c2478cf33a6ed01f3e3d3dcccb159a731d6db9280104bd5040fc5": _m5, "d56b24243cff6f3552a2f7b45521af4491494375ec76117e9ac1ebb047ce02da": _m30, "87c24efeaa0f1579c19afeeb4918caeb4f8f65a88d24a246e2cfd712b37dbac3": _m4, "42faf379960e5674a6fdfa8c8fca0bb68bbd74587231248d2524d7004def3671": _m9, "50b3c10b690ceff693c8c5f809195ba6845b20e60f408e791a750d2ecbd5c669": _m10, "0391fe35ea7d02b25804ab4d0e7543136d6bb615f368f268c74aa135f23aa6bc": _m11, "f0627ba89e5c8fcb376ebe3ce72dcc8d68c34952981f8703e36b8bb1a9894208": _m53, "4a089607f7cbe50e13d4382d1cc4e5f6ce32c5773bbec2df84178710f54d9a38": _m56, "477ff98f49343b8ec4213008254b57a60dd42d07cb9843b3791d5e5f8e295865": _m43, "d9c1509dff0538488752433e47cd0927ece5f93c559ad0e32dc56602dfd44596": _m63, "e88a83ca79cd099fc2de29689554c913c7d04b17018098f81c43044064fcdfb8": _m27, "046b305cdccf817d847addb75a778131622de23f2840830bbe1c0c26053a68c0": _m8, "c9fde2c438e186da56f740105fcd41c265fdfdd855a4f1b811d556a02387479b": _m12, "227236fd7adc9472e188831b8f16fdc69338c4d779f2b69a8abbd8dbfa95b585": _m17, "5337d1e3bd5ae0c1d10a476fcd31540d20337ccf7aa93c7e9e26c2b1a7dab92b": _m3, "59911f0fe023545e9e97521b268551078bdc4c5f303e446a13b7d52f905e8070": _m67 });
|
|
11539
11540
|
const { core, zip, xml, opc, xlsx, csv, pdf, Workbook, Worksheet, Cell, FormulaCell, StyleRegistry, NumberFormats, writeXlsx, writeXlsxTo, writeCsv, writeCsvTo, createGroupedReport, writeGroupedXlsx, writeGroupedXlsxTo, addGroupedXlsx, writeGroupedPdf, writeGroupedPdfTo, pdfGroupedTable, writePdf, writePdfTo, writePdfDocument, writePdfDocumentTo, pdfTable, PdfFont, preflightPdfText, OfficeIMOError, NotSupportedError, detectFeatures, saveBlob, ExportCell } = _m0;
|
|
11540
|
-
export { core, zip, xml, opc, xlsx, csv, pdf, Workbook, Worksheet, Cell, FormulaCell, StyleRegistry, NumberFormats, writeXlsx, writeXlsxTo, writeCsv, writeCsvTo, createGroupedReport, writeGroupedXlsx, writeGroupedXlsxTo, addGroupedXlsx, writeGroupedPdf, writeGroupedPdfTo, pdfGroupedTable, writePdf, writePdfTo, writePdfDocument, writePdfDocumentTo, pdfTable, PdfFont, preflightPdfText, OfficeIMOError, NotSupportedError, detectFeatures, saveBlob, ExportCell };
|
|
11541
|
+
export { core, zip, xml, opc, xlsx, csv, pdf, Workbook, Worksheet, Cell, FormulaCell, StyleRegistry, NumberFormats, writeXlsx, writeXlsxTo, writeCsv, writeCsvTo, createGroupedReport, writeGroupedXlsx, writeGroupedXlsxTo, addGroupedXlsx, writeGroupedPdf, writeGroupedPdfTo, pdfGroupedTable, writePdf, writePdfTo, writePdfDocument, writePdfDocumentTo, pdfTable, PdfFont, preflightPdfText, OfficeIMOError, NotSupportedError, detectFeatures, saveBlob, ExportCell, __officeimoModules };
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ExportValue, ColumnSettings } from "../../core/index.js";
|
|
2
|
-
/**
|
|
2
|
+
/** Apply one captured numeric convention to every supported numeric cell, including later streamed rows. */
|
|
3
3
|
export declare function canopyPdfNumbers(sample: readonly (readonly ExportValue[])[], columns: readonly ColumnSettings[]): (row: readonly ExportValue[]) => readonly ExportValue[];
|
|
@@ -1,64 +1,118 @@
|
|
|
1
1
|
import { ExportCell } from "../../core/index.js";
|
|
2
2
|
/** Fixed numeric formats affect PDF text, not the frozen numeric value used by other writers. */
|
|
3
3
|
function numericProfile(format) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
// No declared precision: whole values (including counts) stay whole.
|
|
5
|
+
if (format === undefined || format === "General")
|
|
6
|
+
return { minimumFractionDigits: 0, maximumFractionDigits: 20,
|
|
7
|
+
percent: false, grouping: false, prefix: "", suffix: "" };
|
|
8
|
+
const match = /^((?:"[^"]*"|\\["%])*)(#,##)?0(?:\.([0#]+))?(%)?((?:"[^"]*"|\\["%])*)$/.exec(format);
|
|
7
9
|
if (!match || (match[3]?.length ?? 0) > 10)
|
|
8
10
|
return undefined;
|
|
11
|
+
const literal = (text) => text.replace(/"([^"]*)"|\\(["%])/g, (_, quoted, escaped) => quoted ?? escaped);
|
|
9
12
|
return { minimumFractionDigits: (match[3]?.match(/0/g) ?? []).length, maximumFractionDigits: match[3]?.length ?? 0,
|
|
10
|
-
percent: !!match[4], grouping: !!match[2], prefix: match[1]
|
|
13
|
+
percent: !!match[4], grouping: !!match[2], prefix: literal(match[1]), suffix: literal(match[5]) };
|
|
11
14
|
}
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
15
|
+
/** Separate declared literal units before recognizing the captured numeric token. U+2212 MINUS SIGN counts as a
|
|
16
|
+
* sign like "-": the number is re-rendered with Intl's sign, so it never becomes a literal prefix. */
|
|
17
|
+
function capturedNumber(text, profile) {
|
|
18
|
+
let body = text, signBeforePrefix = false;
|
|
19
|
+
if (profile.prefix && body.startsWith(profile.prefix))
|
|
20
|
+
body = body.slice(profile.prefix.length);
|
|
21
|
+
else if (profile.prefix && /^[+\-\u2212]/.test(body) && body.slice(1).startsWith(profile.prefix)) {
|
|
22
|
+
signBeforePrefix = true;
|
|
23
|
+
body = body[0] + body.slice(1 + profile.prefix.length);
|
|
24
|
+
}
|
|
25
|
+
if (profile.suffix && body.endsWith(profile.suffix))
|
|
26
|
+
body = body.slice(0, -profile.suffix.length);
|
|
27
|
+
const match = /^([^0-9+\-\u2212]*)([+\-\u2212]?\d[\d., \u00a0\u202f]*?)([^0-9]*)$/.exec(body);
|
|
28
|
+
return match ? { prefix: profile.prefix || match[1], number: match[2], suffix: profile.suffix || match[3], signBeforePrefix } : undefined;
|
|
29
|
+
}
|
|
30
|
+
/** Distinguish a captured thousands mark from a decimal, using the raw value. */
|
|
31
|
+
function groupedInteger(numeric, value) {
|
|
32
|
+
if (!/^[+\-\u2212]?\d{1,3}(?:,\d{3})+$/.test(numeric) && !/^[+\-\u2212]?\d{1,3}(?:\.\d{3})+$/.test(numeric))
|
|
33
|
+
return false;
|
|
34
|
+
const grouped = Number(numeric.replace(/[.,]/g, "").replace("\u2212", "-"));
|
|
35
|
+
return grouped !== 0 && Math.abs(grouped - value) <= .5;
|
|
36
|
+
}
|
|
37
|
+
/** Choose once for the document; percent text is the strongest captured culture signal. */
|
|
38
|
+
function documentDecimal(sample, columns) {
|
|
39
|
+
let fallback;
|
|
40
|
+
for (const percent of [true, false]) {
|
|
41
|
+
for (const row of sample)
|
|
42
|
+
for (let index = 0; index < columns.length; index++) {
|
|
43
|
+
const cell = row[index], column = columns[index];
|
|
44
|
+
if (!(cell instanceof ExportCell) || typeof cell.value !== "number")
|
|
45
|
+
continue;
|
|
46
|
+
const profile = numericProfile(cell.presentation?.numberFormat ?? column.format);
|
|
47
|
+
if (!profile)
|
|
48
|
+
continue;
|
|
49
|
+
const captured = capturedNumber(cell.text ?? "", profile);
|
|
50
|
+
if (!captured)
|
|
51
|
+
continue;
|
|
52
|
+
// A literal percent label is a culture signal without requesting numeric scaling.
|
|
53
|
+
const percentageSignal = profile.percent || profile.prefix.includes("%") || profile.suffix.includes("%") || (cell.text ?? "").includes("%");
|
|
54
|
+
if (percentageSignal !== percent)
|
|
55
|
+
continue;
|
|
56
|
+
const match = /([.,])(\d+)$/.exec(captured.number.trimEnd());
|
|
57
|
+
if (match) {
|
|
58
|
+
const numeric = captured.number;
|
|
59
|
+
// An override changes output scaling/precision, not the captured label.
|
|
60
|
+
if (groupedInteger(numeric, cell.value) || (percentageSignal && groupedInteger(numeric, cell.value * 100))) {
|
|
30
61
|
fallback = match[1] === "," ? "." : ",";
|
|
31
62
|
continue;
|
|
32
63
|
}
|
|
64
|
+
return match[1];
|
|
33
65
|
}
|
|
34
|
-
return match[1];
|
|
35
66
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
67
|
+
if (fallback !== undefined)
|
|
68
|
+
return fallback;
|
|
69
|
+
}
|
|
70
|
+
return ".";
|
|
71
|
+
}
|
|
72
|
+
/** Apply one captured numeric convention to every supported numeric cell, including later streamed rows. */
|
|
73
|
+
export function canopyPdfNumbers(sample, columns) {
|
|
74
|
+
const formatters = new Map(), decimal = documentDecimal(sample, columns);
|
|
39
75
|
return row => row.map((value, index) => {
|
|
40
76
|
if (!(value instanceof ExportCell) || typeof value.value !== "number")
|
|
41
77
|
return value;
|
|
42
|
-
const
|
|
43
|
-
|
|
78
|
+
const format = value.presentation?.numberFormat ?? columns[index].format;
|
|
79
|
+
let profile = numericProfile(format);
|
|
80
|
+
if (!profile || value.text === "")
|
|
44
81
|
return value;
|
|
45
|
-
const captured =
|
|
82
|
+
const captured = capturedNumber(value.text ?? "", profile);
|
|
46
83
|
if (value.text && !captured)
|
|
47
84
|
return value;
|
|
48
|
-
|
|
85
|
+
// Undeclared formats normalize only plain numeric labels; a decoration
|
|
86
|
+
// alone does not declare how the raw value was transformed for display.
|
|
87
|
+
if ((format === undefined || format === "General") && captured && (captured.prefix.trim() || captured.suffix.trim()))
|
|
88
|
+
return value;
|
|
89
|
+
if (format === undefined || format === "General") {
|
|
90
|
+
const digits = Number.isInteger(value.value) || (captured && groupedInteger(captured.number, value.value)) ? 0 :
|
|
91
|
+
captured ? /[.,](\d+)$/.exec(captured.number.trimEnd())?.[1]?.length ?? 0 : undefined;
|
|
92
|
+
// Retain a fractional value's captured precision, without padding an
|
|
93
|
+
// undeclared whole aggregate merely because its display text was padded.
|
|
94
|
+
if (digits !== undefined && digits <= 20)
|
|
95
|
+
profile = { ...profile, minimumFractionDigits: digits, maximumFractionDigits: digits };
|
|
96
|
+
}
|
|
97
|
+
const key = [profile.minimumFractionDigits, profile.maximumFractionDigits, profile.grouping].join(":");
|
|
49
98
|
let formatter = formatters.get(key);
|
|
50
99
|
if (!formatter) {
|
|
51
|
-
formatter = new Intl.NumberFormat(decimal
|
|
100
|
+
formatter = new Intl.NumberFormat(decimal === "," ? "de-DE" : "en-US", {
|
|
52
101
|
minimumFractionDigits: profile.minimumFractionDigits, maximumFractionDigits: profile.maximumFractionDigits, useGrouping: profile.grouping
|
|
53
102
|
});
|
|
54
103
|
formatters.set(key, formatter);
|
|
55
104
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
105
|
+
let formatted = formatter.format(value.value * (profile.percent ? 100 : 1));
|
|
106
|
+
if (captured?.number.startsWith("+") && !formatted.startsWith("-"))
|
|
107
|
+
formatted = "+" + formatted;
|
|
108
|
+
const leadingSign = captured?.signBeforePrefix ? /^[+-]/.exec(formatted)?.[0] ?? "" : "";
|
|
109
|
+
if (leadingSign)
|
|
110
|
+
formatted = formatted.slice(1);
|
|
111
|
+
const prefix = captured?.prefix || profile.prefix;
|
|
112
|
+
let suffix = captured?.suffix || profile.suffix;
|
|
59
113
|
if (profile.percent && !profile.suffix)
|
|
60
114
|
suffix = suffix.replace(/%/g, "");
|
|
61
|
-
return new ExportCell(value.value, { text: prefix + formatted + (profile.percent ? "%" : "") + suffix,
|
|
115
|
+
return new ExportCell(value.value, { text: leadingSign + prefix + formatted + (profile.percent ? "%" : "") + suffix,
|
|
62
116
|
...(value.presentation ? { presentation: value.presentation } : {}), ...(value.link ? { link: value.link } : {}) });
|
|
63
117
|
});
|
|
64
118
|
}
|
|
@@ -60,6 +60,10 @@ export function canopyPivot(request) {
|
|
|
60
60
|
}
|
|
61
61
|
/** Per-cell formats preserve already-computed fractional percentages, ranks and differences. */
|
|
62
62
|
export function pivotNumberFormat(cell) {
|
|
63
|
+
// Raw-value aggregates need no decimal declaration. Transformed values still
|
|
64
|
+
// require the producer's frozen format (especially percent scaling).
|
|
65
|
+
if (cell.mode === "value" && cell.numberFormat === undefined)
|
|
66
|
+
return undefined;
|
|
63
67
|
if (!["value", "percentGrandTotal", "percentParent", "percentColumn", "percentRow", "runningTotal", "rank", "difference", "percentChange"].includes(cell.mode ?? "") ||
|
|
64
68
|
typeof cell.numberFormat !== "string" || !cell.numberFormat.length)
|
|
65
69
|
throw new TypeError("Numeric pivot cells require a frozen mode and native numberFormat.");
|
|
@@ -131,11 +131,11 @@ export function prepareCanopyExport(capture, format, options = {}) {
|
|
|
131
131
|
if (format === "xlsx" && values === "raw" && spec.kind === "datetime" && typeof value === "string")
|
|
132
132
|
value = datetime(value, dateMode, clock);
|
|
133
133
|
const capturedFormat = pivot && spec.kind === "number" && cell.value !== null ? pivotNumberFormat(cell) : undefined;
|
|
134
|
-
const nativeFormat =
|
|
134
|
+
const nativeFormat = spec.nativeFormatOverride === "" ? "General" : spec.nativeFormatOverride ?? capturedFormat;
|
|
135
135
|
const summary = format === "pdf" && pivot && (row.summary || row.grandTotal);
|
|
136
136
|
const cellStyle = tone(cell.tone, row.id, spec.id), presentation = rowStyle || cellStyle || nativeFormat || summary ? {
|
|
137
137
|
...rowStyle, ...(summary ? { bold: true } : {}), ...cellStyle,
|
|
138
|
-
...((format === "
|
|
138
|
+
...((format === "pdf" || (format === "xlsx" && pivot)) && values === "raw" && nativeFormat !== undefined ? { numberFormat: nativeFormat } : {})
|
|
139
139
|
} : undefined;
|
|
140
140
|
// CSV has no presentation or link metadata: emit its selected scalar directly.
|
|
141
141
|
// This also avoids a frozen wrapper for every cell in large CSV captures.
|
|
@@ -9,6 +9,7 @@ export interface CanopyExportCell {
|
|
|
9
9
|
readonly text: string;
|
|
10
10
|
/** Frozen pivot display semantics; values are already computed by CanopyX. */
|
|
11
11
|
readonly mode?: "value" | "percentGrandTotal" | "percentParent" | "percentColumn" | "percentRow" | "runningTotal" | "rank" | "difference" | "percentChange";
|
|
12
|
+
/** Native format; optional for mode=value, whose unformatted integer values stay whole in PDF. */
|
|
12
13
|
readonly numberFormat?: string;
|
|
13
14
|
readonly tone?: string;
|
|
14
15
|
readonly link?: ExportLink;
|
|
@@ -18,6 +18,31 @@ function safeOptions(options) {
|
|
|
18
18
|
value(result);
|
|
19
19
|
} } : {}) };
|
|
20
20
|
}
|
|
21
|
+
/** Buttons builds the heading structures before customizeData runs; carry changed leaf labels into their bottom row. */
|
|
22
|
+
function customizedStructure(structure, before, after, kind) {
|
|
23
|
+
if (!before || !Array.isArray(structure) || !structure.length)
|
|
24
|
+
return structure;
|
|
25
|
+
const changed = after.map((label, index) => !Object.is(label, before[index]));
|
|
26
|
+
if (!changed.some(Boolean))
|
|
27
|
+
return structure;
|
|
28
|
+
return structure.map((row, level) => !Array.isArray(row) ? row : row.map((cell, index) => {
|
|
29
|
+
if (cell == null || level + (Number(member(cell, "rowspan")) || 1) !== structure.length)
|
|
30
|
+
return cell;
|
|
31
|
+
const span = Number(member(cell, "colspan")) || 1;
|
|
32
|
+
if (!changed.slice(index, index + span).some(Boolean))
|
|
33
|
+
return cell;
|
|
34
|
+
if (span !== 1)
|
|
35
|
+
throw new TypeError("customizeData cannot change one column of a spanning " + kind + " cell.");
|
|
36
|
+
return { ...cell, title: after[index] };
|
|
37
|
+
}));
|
|
38
|
+
}
|
|
39
|
+
/** A customizeData reorder is visible as a permutation of distinct leaf labels; map each output column to its source. */
|
|
40
|
+
function reorderedSources(before, after) {
|
|
41
|
+
if (!before || before.length !== after.length || new Set(before).size !== before.length)
|
|
42
|
+
return undefined;
|
|
43
|
+
const sources = after.map(label => before.indexOf(label));
|
|
44
|
+
return sources.every(source => source >= 0) && new Set(sources).size === sources.length && sources.some((source, index) => source !== index) ? sources : undefined;
|
|
45
|
+
}
|
|
21
46
|
/** Capture export scope and headings, then produce values in bounded batches using public DataTables APIs. */
|
|
22
47
|
export function createDataTablesExport(host, table, options = {}) {
|
|
23
48
|
return captureDataTablesExport(host, table, options);
|
|
@@ -69,16 +94,35 @@ export function captureDataTablesExport(host, table, options = {}, omitted) {
|
|
|
69
94
|
throw new RangeError("A selected row exceeds maxBatchCells.");
|
|
70
95
|
if (new Set(rowIndexes).size !== rowIndexes.length || new Set(columnIndexes).size !== columnIndexes.length)
|
|
71
96
|
throw new TypeError("DataTables export indexes must be unique.");
|
|
72
|
-
|
|
97
|
+
let before;
|
|
98
|
+
const customize = config.customizeData;
|
|
99
|
+
const data = call(table.buttons, "exportData", { ...config, modifier, ...(mode === "batched" ? { rows: [] } : {}),
|
|
100
|
+
...(customize ? { customizeData: (input) => {
|
|
101
|
+
const footer = member(input, "footer");
|
|
102
|
+
before = { header: [...array(member(input, "header"))], footer: footer == null ? undefined : [...array(footer)] };
|
|
103
|
+
customize(input);
|
|
104
|
+
} } : {}) });
|
|
73
105
|
const leaf = array(member(data, "header"));
|
|
74
106
|
if (leaf.length !== columnIndexes.length)
|
|
75
107
|
throw new TypeError("Export header must match the selected columns.");
|
|
76
|
-
|
|
108
|
+
// Only structured output reaches the source structures' bottom row; leaf and grouped headings take the leaf labels.
|
|
109
|
+
const structured = headingMode === "structured" && !omitted?.header;
|
|
110
|
+
const sourceStructure = omitted?.header ? undefined : member(data, "headerStructure");
|
|
111
|
+
const heading = headings(structured ? customizedStructure(sourceStructure, before?.header, leaf, "header") : sourceStructure, leaf, omitted?.header ? "leaf" : headingMode);
|
|
112
|
+
const reordered = reorderedSources(before?.header, leaf);
|
|
113
|
+
if (reordered && heading.rows.length > 1)
|
|
114
|
+
throw new TypeError("customizeData cannot reorder columns under grouped headings; select headings: 'leaf' or reorder the table's columns.");
|
|
115
|
+
// Column options and keys follow each column to its new position after a customizeData reorder. Any other heading
|
|
116
|
+
// change (a rename, or a reorder with a rename) leaves no reliable source mapping for column options.
|
|
117
|
+
if (before && !reordered && before.header.some((label, index) => !Object.is(label, leaf[index])) &&
|
|
118
|
+
columnIndexes.some(index => options.columnOptions?.[index] !== undefined))
|
|
119
|
+
throw new TypeError("customizeData changed column headings, so columnOptions cannot be matched to columns; rename columns with columnOptions header instead.");
|
|
120
|
+
const sourceColumns = reordered ? reordered.map(source => columnIndexes[source]) : columnIndexes;
|
|
77
121
|
for (const index of columnIndexes)
|
|
78
122
|
if (member(options.columnOptions?.[index], "value") !== undefined)
|
|
79
123
|
throw new TypeError("DataTables columnOptions describes columns; resolve values with project.");
|
|
80
124
|
const columns = Object.freeze(copyColumns(leaf.map((label, index) => ({
|
|
81
|
-
header: text(label), key: "dt:" +
|
|
125
|
+
header: text(label), key: "dt:" + sourceColumns[index], ...options.columnOptions?.[sourceColumns[index]],
|
|
82
126
|
...(heading.groups[index].length ? { groups: Object.freeze(heading.groups[index]) } : {})
|
|
83
127
|
}))).map(column => Object.freeze(column)));
|
|
84
128
|
// Explicit heading overrides also apply to CSV's leaf heading.
|
|
@@ -87,8 +131,8 @@ export function captureDataTablesExport(host, table, options = {}, omitted) {
|
|
|
87
131
|
const headerStructure = heading.structure?.map((row, level) => Object.freeze(row.map((cell, index) => {
|
|
88
132
|
if (!cell || level + (cell.rowSpan ?? 1) !== heading.structure.length)
|
|
89
133
|
return cell;
|
|
90
|
-
const override = options.columnOptions?.[
|
|
91
|
-
if ((cell.columnSpan ?? 1) > 1 &&
|
|
134
|
+
const override = options.columnOptions?.[sourceColumns[index]]?.header;
|
|
135
|
+
if ((cell.columnSpan ?? 1) > 1 && sourceColumns.slice(index, index + (cell.columnSpan ?? 1)).some(c => options.columnOptions?.[c]?.header !== undefined))
|
|
92
136
|
throw new TypeError("A spanning leaf heading cannot have per-column header overrides.");
|
|
93
137
|
return override === undefined ? cell : Object.freeze({ ...cell, value: override });
|
|
94
138
|
})));
|
|
@@ -100,7 +144,8 @@ export function captureDataTablesExport(host, table, options = {}, omitted) {
|
|
|
100
144
|
const footer = rawFooter == null ? undefined : array(rawFooter).map(value);
|
|
101
145
|
if (footer && footer.length !== columns.length)
|
|
102
146
|
throw new TypeError("Export footer must match the selected columns.");
|
|
103
|
-
const footerHeading = footer && Array.isArray(footerStructure) && footerStructure.length
|
|
147
|
+
const footerHeading = footer && Array.isArray(footerStructure) && footerStructure.length
|
|
148
|
+
? headings(headingMode === "structured" ? customizedStructure(footerStructure, before?.footer, array(rawFooter), "footer") : footerStructure, footer, headingMode === "structured" ? "structured" : "grouped") : undefined;
|
|
104
149
|
const body = mode === "compatibility" ? array(member(data, "body")) : undefined;
|
|
105
150
|
const count = columns.length ? body?.length ?? rowIndexes.length : 0;
|
|
106
151
|
budget.check("maxRows", count);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@evotecit/officeimo",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.9",
|
|
4
4
|
"description": "Dependency-free OfficeIMO document libraries for browsers, workers and Node.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -62,7 +62,10 @@
|
|
|
62
62
|
"./xlsx.js": "./bundles/officeimo-xlsx.js",
|
|
63
63
|
"./csv.js": "./bundles/officeimo-csv.js",
|
|
64
64
|
"./pdf.js": "./bundles/officeimo-pdf.js",
|
|
65
|
-
"./execution.js": "./bundles/officeimo-execution.js"
|
|
65
|
+
"./execution.js": "./bundles/officeimo-execution.js",
|
|
66
|
+
"./canopyx-adapter.js": "./bundles/officeimo-canopyx-adapter.js",
|
|
67
|
+
"./datatables-adapter.js": "./bundles/officeimo-datatables-adapter.js",
|
|
68
|
+
"./bundles/*": "./bundles/*"
|
|
66
69
|
},
|
|
67
70
|
"files": [
|
|
68
71
|
"dist",
|
|
@@ -83,6 +86,7 @@
|
|
|
83
86
|
"prepack": "npm run check"
|
|
84
87
|
},
|
|
85
88
|
"devDependencies": {
|
|
89
|
+
"esbuild": "0.28.2",
|
|
86
90
|
"typescript": "7.0.2"
|
|
87
91
|
},
|
|
88
92
|
"engines": {
|