@harbortouch/skytab-analytics-report-utils 0.41.2 → 0.41.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/exporters/exportBuilder.cjs +52 -2
- package/dist/exporters/exportBuilder.d.cts +4 -2
- package/dist/exporters/exportBuilder.d.ts +4 -2
- package/dist/exporters/exportBuilder.js +50 -1
- package/dist/exporters/pdf/index.cjs +16 -8
- package/dist/exporters/pdf/index.js +16 -8
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -20,7 +20,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/exporters/exportBuilder.ts
|
|
21
21
|
var exportBuilder_exports = {};
|
|
22
22
|
__export(exportBuilder_exports, {
|
|
23
|
-
ExportBuilder: () => ExportBuilder
|
|
23
|
+
ExportBuilder: () => ExportBuilder,
|
|
24
|
+
resolveRawFiltersToExportFilters: () => resolveRawFiltersToExportFilters
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(exportBuilder_exports);
|
|
26
27
|
|
|
@@ -3950,6 +3951,54 @@ var calculateReportTotals = (data, fieldConfig) => {
|
|
|
3950
3951
|
return result;
|
|
3951
3952
|
};
|
|
3952
3953
|
|
|
3954
|
+
// src/utils/filter-resolver.ts
|
|
3955
|
+
var ANALYTICS_FIELDS = /* @__PURE__ */ new Set([
|
|
3956
|
+
"location_id",
|
|
3957
|
+
"order_type_id",
|
|
3958
|
+
"revenue_center_id",
|
|
3959
|
+
"hour_id",
|
|
3960
|
+
"timeslot_id",
|
|
3961
|
+
"employee_id",
|
|
3962
|
+
"employee_name",
|
|
3963
|
+
"payroll_id",
|
|
3964
|
+
"daypart_id",
|
|
3965
|
+
"item_id",
|
|
3966
|
+
"department_id",
|
|
3967
|
+
"revenue_class_id",
|
|
3968
|
+
"modifier_id"
|
|
3969
|
+
]);
|
|
3970
|
+
function isAnalyticsField(key) {
|
|
3971
|
+
return ANALYTICS_FIELDS.has(key);
|
|
3972
|
+
}
|
|
3973
|
+
function isReportColumnKey(key) {
|
|
3974
|
+
return getColumnMetadata(key) !== void 0;
|
|
3975
|
+
}
|
|
3976
|
+
function resolveFilterLabel(key, locale) {
|
|
3977
|
+
if (isAnalyticsField(key)) {
|
|
3978
|
+
return resolveTranslate(`analytics.field.${key}`, locale);
|
|
3979
|
+
}
|
|
3980
|
+
if (isReportColumnKey(key)) {
|
|
3981
|
+
return resolveTranslate(getColumnMetadata(key).titleKey, locale);
|
|
3982
|
+
}
|
|
3983
|
+
return key.replace(/(?:_id|Id)$/, "").replace(/_/g, " ").replace(/([A-Z])/g, " $1").trim().replace(/\b\w/g, (c) => c.toUpperCase());
|
|
3984
|
+
}
|
|
3985
|
+
function resolveRawFiltersToExportFilters(rawFilters, locale) {
|
|
3986
|
+
if (!rawFilters || typeof rawFilters !== "object" || Array.isArray(rawFilters)) {
|
|
3987
|
+
return [];
|
|
3988
|
+
}
|
|
3989
|
+
return Object.entries(rawFilters).flatMap(([key, values]) => {
|
|
3990
|
+
if (key === "location_id" || !Array.isArray(values) || values.length === 0) {
|
|
3991
|
+
return [];
|
|
3992
|
+
}
|
|
3993
|
+
const label = resolveFilterLabel(key, locale);
|
|
3994
|
+
const value = values.filter((v) => v !== null && v !== void 0).map(String).join(", ");
|
|
3995
|
+
if (!value) {
|
|
3996
|
+
return [];
|
|
3997
|
+
}
|
|
3998
|
+
return [{ label, value }];
|
|
3999
|
+
});
|
|
4000
|
+
}
|
|
4001
|
+
|
|
3953
4002
|
// src/exporters/exportBuilder.ts
|
|
3954
4003
|
var import_date_fns = require("date-fns");
|
|
3955
4004
|
var ExportBuilder = class {
|
|
@@ -4174,5 +4223,6 @@ var ExportBuilder = class {
|
|
|
4174
4223
|
};
|
|
4175
4224
|
// Annotate the CommonJS export names for ESM import in node:
|
|
4176
4225
|
0 && (module.exports = {
|
|
4177
|
-
ExportBuilder
|
|
4226
|
+
ExportBuilder,
|
|
4227
|
+
resolveRawFiltersToExportFilters
|
|
4178
4228
|
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { R as ReportType, A as AnalyticsField } from '../report-pbGeYM8Q.cjs';
|
|
2
|
-
import {
|
|
2
|
+
import { E as ExportFilter, R as ReportMetadata, a as ExportSection } from '../types-MalWTEdo.cjs';
|
|
3
|
+
|
|
4
|
+
declare function resolveRawFiltersToExportFilters(rawFilters: Record<string, (string | number)[] | undefined>, locale: string): ExportFilter[];
|
|
3
5
|
|
|
4
6
|
type ReportDocumentSection = ExportSection;
|
|
5
7
|
interface ReportLocation {
|
|
@@ -49,4 +51,4 @@ declare class ExportBuilder {
|
|
|
49
51
|
getContent(reportData: ReportData, parameters: ReportParameters, name: string | undefined, metadata: ReportMetadata, appliedFilters?: ExportFilter[]): ExportSection[];
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
export { ExportBuilder, ExportFilter, type ReportData, type ReportDocumentSection, type ReportLocation, ReportMetadata, type ReportParameters, ReportType, type SingleReportData };
|
|
54
|
+
export { ExportBuilder, ExportFilter, type ReportData, type ReportDocumentSection, type ReportLocation, ReportMetadata, type ReportParameters, ReportType, type SingleReportData, resolveRawFiltersToExportFilters };
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { R as ReportType, A as AnalyticsField } from '../report-pbGeYM8Q.js';
|
|
2
|
-
import {
|
|
2
|
+
import { E as ExportFilter, R as ReportMetadata, a as ExportSection } from '../types-MalWTEdo.js';
|
|
3
|
+
|
|
4
|
+
declare function resolveRawFiltersToExportFilters(rawFilters: Record<string, (string | number)[] | undefined>, locale: string): ExportFilter[];
|
|
3
5
|
|
|
4
6
|
type ReportDocumentSection = ExportSection;
|
|
5
7
|
interface ReportLocation {
|
|
@@ -49,4 +51,4 @@ declare class ExportBuilder {
|
|
|
49
51
|
getContent(reportData: ReportData, parameters: ReportParameters, name: string | undefined, metadata: ReportMetadata, appliedFilters?: ExportFilter[]): ExportSection[];
|
|
50
52
|
}
|
|
51
53
|
|
|
52
|
-
export { ExportBuilder, ExportFilter, type ReportData, type ReportDocumentSection, type ReportLocation, ReportMetadata, type ReportParameters, ReportType, type SingleReportData };
|
|
54
|
+
export { ExportBuilder, ExportFilter, type ReportData, type ReportDocumentSection, type ReportLocation, ReportMetadata, type ReportParameters, ReportType, type SingleReportData, resolveRawFiltersToExportFilters };
|
|
@@ -10,6 +10,54 @@ import {
|
|
|
10
10
|
resolveTranslate
|
|
11
11
|
} from "../chunk-DDHOYPIA.js";
|
|
12
12
|
|
|
13
|
+
// src/utils/filter-resolver.ts
|
|
14
|
+
var ANALYTICS_FIELDS = /* @__PURE__ */ new Set([
|
|
15
|
+
"location_id",
|
|
16
|
+
"order_type_id",
|
|
17
|
+
"revenue_center_id",
|
|
18
|
+
"hour_id",
|
|
19
|
+
"timeslot_id",
|
|
20
|
+
"employee_id",
|
|
21
|
+
"employee_name",
|
|
22
|
+
"payroll_id",
|
|
23
|
+
"daypart_id",
|
|
24
|
+
"item_id",
|
|
25
|
+
"department_id",
|
|
26
|
+
"revenue_class_id",
|
|
27
|
+
"modifier_id"
|
|
28
|
+
]);
|
|
29
|
+
function isAnalyticsField(key) {
|
|
30
|
+
return ANALYTICS_FIELDS.has(key);
|
|
31
|
+
}
|
|
32
|
+
function isReportColumnKey(key) {
|
|
33
|
+
return getColumnMetadata(key) !== void 0;
|
|
34
|
+
}
|
|
35
|
+
function resolveFilterLabel(key, locale) {
|
|
36
|
+
if (isAnalyticsField(key)) {
|
|
37
|
+
return resolveTranslate(`analytics.field.${key}`, locale);
|
|
38
|
+
}
|
|
39
|
+
if (isReportColumnKey(key)) {
|
|
40
|
+
return resolveTranslate(getColumnMetadata(key).titleKey, locale);
|
|
41
|
+
}
|
|
42
|
+
return key.replace(/(?:_id|Id)$/, "").replace(/_/g, " ").replace(/([A-Z])/g, " $1").trim().replace(/\b\w/g, (c) => c.toUpperCase());
|
|
43
|
+
}
|
|
44
|
+
function resolveRawFiltersToExportFilters(rawFilters, locale) {
|
|
45
|
+
if (!rawFilters || typeof rawFilters !== "object" || Array.isArray(rawFilters)) {
|
|
46
|
+
return [];
|
|
47
|
+
}
|
|
48
|
+
return Object.entries(rawFilters).flatMap(([key, values]) => {
|
|
49
|
+
if (key === "location_id" || !Array.isArray(values) || values.length === 0) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
const label = resolveFilterLabel(key, locale);
|
|
53
|
+
const value = values.filter((v) => v !== null && v !== void 0).map(String).join(", ");
|
|
54
|
+
if (!value) {
|
|
55
|
+
return [];
|
|
56
|
+
}
|
|
57
|
+
return [{ label, value }];
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
|
|
13
61
|
// src/exporters/exportBuilder.ts
|
|
14
62
|
import { format, isValid, parseISO } from "date-fns";
|
|
15
63
|
var ExportBuilder = class {
|
|
@@ -233,5 +281,6 @@ var ExportBuilder = class {
|
|
|
233
281
|
}
|
|
234
282
|
};
|
|
235
283
|
export {
|
|
236
|
-
ExportBuilder
|
|
284
|
+
ExportBuilder,
|
|
285
|
+
resolveRawFiltersToExportFilters
|
|
237
286
|
};
|
|
@@ -49,23 +49,21 @@ var sanitizePdfText = (text) => {
|
|
|
49
49
|
return "";
|
|
50
50
|
}
|
|
51
51
|
const leadingSpaces = /^ */.exec(text)?.[0] ?? "";
|
|
52
|
-
return leadingSpaces + text.trimStart().replace(
|
|
52
|
+
return leadingSpaces + text.trimStart().replace(
|
|
53
53
|
/[\u{1F300}-\u{1F9FF}]|[\u{2600}-\u{26FF}]|[\u{2700}-\u{27BF}]|[\u{1F1E0}-\u{1F1FF}]|[\u{1F600}-\u{1F64F}]|[\u{1F680}-\u{1F6FF}]|[\u{1F900}-\u{1F9FF}]|[\u{1FA00}-\u{1FA6F}]|[\u{1FA70}-\u{1FAFF}]|[\u{FE00}-\u{FE0F}]|[\u{1F004}]|[\u{1F0CF}]|[\u{1F18E}]|[\u{1F191}-\u{1F19A}]|[\u{1F1E6}-\u{1F1FF}]|[\u{1F201}-\u{1F251}]/gu,
|
|
54
54
|
""
|
|
55
|
-
).replace(/[\x00-\x1F\x7F-\x9F]/g, " ").replace(/ /g, " ").replace(/[^\x20-\x7E\xA1-\xFF]/g, "").replace(/\s+/g, " ").trim();
|
|
55
|
+
).replace(/[\x00-\x1F\x7F-\x9F]/g, " ").replace(/ /g, " ").replace(/[^\x20-\x7E\xA1-\xFF€₹₩₪₽]/g, "").replace(/\s+/g, " ").trim();
|
|
56
56
|
};
|
|
57
57
|
|
|
58
58
|
// src/exporters/pdf/constants.ts
|
|
59
|
-
var ZOOM_FACTOR = 1.44;
|
|
60
59
|
var FONT_REGULAR = "Lato";
|
|
61
60
|
var FONT_BOLD = "Lato-Bold";
|
|
62
61
|
var DEFAULT_TEXT_COLOR = "#000000";
|
|
63
62
|
var HEADER_BACKGROUND_COLOR = "#f9fafb";
|
|
64
63
|
var ZEBRA_BACKGROUND_COLOR = "#fafbfc";
|
|
65
64
|
var SEPARATOR_COLOR = "#E4E5E5";
|
|
66
|
-
var SECTION_TITLE_FONT_SIZE =
|
|
67
|
-
var
|
|
68
|
-
var BODY_FONT_SIZE = 6 * ZOOM_FACTOR;
|
|
65
|
+
var SECTION_TITLE_FONT_SIZE = 9;
|
|
66
|
+
var BODY_FONT_SIZE = 9;
|
|
69
67
|
var TABLE_CELL_PADDING = 4;
|
|
70
68
|
var DEFAULT_ROW_HEIGHT = 25;
|
|
71
69
|
var MIN_COLUMN_WIDTH = 35;
|
|
@@ -200,8 +198,8 @@ var PdfExporter = class {
|
|
|
200
198
|
const columns = table.columns.length > 0 ? table.columns.map((c) => ({ ...c })) : [{ header: "No data", key: "no_data", width: 100 }];
|
|
201
199
|
const rows = table.rows ?? [];
|
|
202
200
|
const columnCount = columns.length;
|
|
203
|
-
const headerFontSize = columnCount > 13 ?
|
|
204
|
-
const dataFontSize = columnCount > 13 ?
|
|
201
|
+
const headerFontSize = columnCount > 13 ? 6 : columnCount > 10 ? 7 : columnCount > 7 ? 8 : 9;
|
|
202
|
+
const dataFontSize = columnCount > 13 ? 5 : columnCount > 10 ? 6 : columnCount > 7 ? 7 : 8;
|
|
205
203
|
const headerWidthSlack = 2;
|
|
206
204
|
const headerMinWidths = /* @__PURE__ */ new Map();
|
|
207
205
|
columns.forEach((col) => {
|
|
@@ -230,6 +228,16 @@ var PdfExporter = class {
|
|
|
230
228
|
const headerMin = headerMinWidths.get(c) ?? MIN_COLUMN_WIDTH;
|
|
231
229
|
c.width = Math.max(Math.floor((c.width ?? MIN_COLUMN_WIDTH) * scale), headerMin, MIN_COLUMN_WIDTH);
|
|
232
230
|
});
|
|
231
|
+
let excess = columns.reduce((sum, c) => sum + (c.width ?? MIN_COLUMN_WIDTH), 0) - usableWidth;
|
|
232
|
+
for (let i = columns.length - 1; i >= 0 && excess > 0; i--) {
|
|
233
|
+
const col = columns[i];
|
|
234
|
+
const available = (col.width ?? MIN_COLUMN_WIDTH) - MIN_COLUMN_WIDTH;
|
|
235
|
+
const trim = Math.min(excess, available);
|
|
236
|
+
if (trim > 0) {
|
|
237
|
+
col.width = (col.width ?? MIN_COLUMN_WIDTH) - trim;
|
|
238
|
+
excess -= trim;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
233
241
|
} else if (totalColumnWidth < usableWidth) {
|
|
234
242
|
const scale = usableWidth / totalColumnWidth;
|
|
235
243
|
columns.forEach((c) => {
|
|
@@ -9,23 +9,21 @@ var sanitizePdfText = (text) => {
|
|
|
9
9
|
return "";
|
|
10
10
|
}
|
|
11
11
|
const leadingSpaces = /^ */.exec(text)?.[0] ?? "";
|
|
12
|
-
return leadingSpaces + text.trimStart().replace(
|
|
12
|
+
return leadingSpaces + text.trimStart().replace(
|
|
13
13
|
/[\u{1F300}-\u{1F9FF}]|[\u{2600}-\u{26FF}]|[\u{2700}-\u{27BF}]|[\u{1F1E0}-\u{1F1FF}]|[\u{1F600}-\u{1F64F}]|[\u{1F680}-\u{1F6FF}]|[\u{1F900}-\u{1F9FF}]|[\u{1FA00}-\u{1FA6F}]|[\u{1FA70}-\u{1FAFF}]|[\u{FE00}-\u{FE0F}]|[\u{1F004}]|[\u{1F0CF}]|[\u{1F18E}]|[\u{1F191}-\u{1F19A}]|[\u{1F1E6}-\u{1F1FF}]|[\u{1F201}-\u{1F251}]/gu,
|
|
14
14
|
""
|
|
15
|
-
).replace(/[\x00-\x1F\x7F-\x9F]/g, " ").replace(/ /g, " ").replace(/[^\x20-\x7E\xA1-\xFF]/g, "").replace(/\s+/g, " ").trim();
|
|
15
|
+
).replace(/[\x00-\x1F\x7F-\x9F]/g, " ").replace(/ /g, " ").replace(/[^\x20-\x7E\xA1-\xFF€₹₩₪₽]/g, "").replace(/\s+/g, " ").trim();
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
// src/exporters/pdf/constants.ts
|
|
19
|
-
var ZOOM_FACTOR = 1.44;
|
|
20
19
|
var FONT_REGULAR = "Lato";
|
|
21
20
|
var FONT_BOLD = "Lato-Bold";
|
|
22
21
|
var DEFAULT_TEXT_COLOR = "#000000";
|
|
23
22
|
var HEADER_BACKGROUND_COLOR = "#f9fafb";
|
|
24
23
|
var ZEBRA_BACKGROUND_COLOR = "#fafbfc";
|
|
25
24
|
var SEPARATOR_COLOR = "#E4E5E5";
|
|
26
|
-
var SECTION_TITLE_FONT_SIZE =
|
|
27
|
-
var
|
|
28
|
-
var BODY_FONT_SIZE = 6 * ZOOM_FACTOR;
|
|
25
|
+
var SECTION_TITLE_FONT_SIZE = 9;
|
|
26
|
+
var BODY_FONT_SIZE = 9;
|
|
29
27
|
var TABLE_CELL_PADDING = 4;
|
|
30
28
|
var DEFAULT_ROW_HEIGHT = 25;
|
|
31
29
|
var MIN_COLUMN_WIDTH = 35;
|
|
@@ -160,8 +158,8 @@ var PdfExporter = class {
|
|
|
160
158
|
const columns = table.columns.length > 0 ? table.columns.map((c) => ({ ...c })) : [{ header: "No data", key: "no_data", width: 100 }];
|
|
161
159
|
const rows = table.rows ?? [];
|
|
162
160
|
const columnCount = columns.length;
|
|
163
|
-
const headerFontSize = columnCount > 13 ?
|
|
164
|
-
const dataFontSize = columnCount > 13 ?
|
|
161
|
+
const headerFontSize = columnCount > 13 ? 6 : columnCount > 10 ? 7 : columnCount > 7 ? 8 : 9;
|
|
162
|
+
const dataFontSize = columnCount > 13 ? 5 : columnCount > 10 ? 6 : columnCount > 7 ? 7 : 8;
|
|
165
163
|
const headerWidthSlack = 2;
|
|
166
164
|
const headerMinWidths = /* @__PURE__ */ new Map();
|
|
167
165
|
columns.forEach((col) => {
|
|
@@ -190,6 +188,16 @@ var PdfExporter = class {
|
|
|
190
188
|
const headerMin = headerMinWidths.get(c) ?? MIN_COLUMN_WIDTH;
|
|
191
189
|
c.width = Math.max(Math.floor((c.width ?? MIN_COLUMN_WIDTH) * scale), headerMin, MIN_COLUMN_WIDTH);
|
|
192
190
|
});
|
|
191
|
+
let excess = columns.reduce((sum, c) => sum + (c.width ?? MIN_COLUMN_WIDTH), 0) - usableWidth;
|
|
192
|
+
for (let i = columns.length - 1; i >= 0 && excess > 0; i--) {
|
|
193
|
+
const col = columns[i];
|
|
194
|
+
const available = (col.width ?? MIN_COLUMN_WIDTH) - MIN_COLUMN_WIDTH;
|
|
195
|
+
const trim = Math.min(excess, available);
|
|
196
|
+
if (trim > 0) {
|
|
197
|
+
col.width = (col.width ?? MIN_COLUMN_WIDTH) - trim;
|
|
198
|
+
excess -= trim;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
193
201
|
} else if (totalColumnWidth < usableWidth) {
|
|
194
202
|
const scale = usableWidth / totalColumnWidth;
|
|
195
203
|
columns.forEach((c) => {
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { M as MessageKey, F as FieldType, C as ColumnAlignment, a as ColumnPresentationConfig, b as ColumnGroupConfig, R as ReportType, c as ReportConfig, d as ReportColumnKey } from './report-pbGeYM8Q.cjs';
|
|
2
|
-
export { e as COLUMN_REGISTRY, f as ColumnMessageKey, g as ColumnMetadata, h as FooterCalculation, i as FooterCalculationType, j as Report, k as getColumnExportHeaderLabel, l as getColumnMetadata, m as getFixedColumns, n as getReportConfig, o as getReportExportFileName } from './report-pbGeYM8Q.cjs';
|
|
2
|
+
export { A as AnalyticsField, e as COLUMN_REGISTRY, f as ColumnMessageKey, g as ColumnMetadata, h as FooterCalculation, i as FooterCalculationType, j as Report, k as getColumnExportHeaderLabel, l as getColumnMetadata, m as getFixedColumns, n as getReportConfig, o as getReportExportFileName } from './report-pbGeYM8Q.cjs';
|
|
3
3
|
import { LocaleCode } from '@harbortouch/locale-registry';
|
|
4
4
|
export { R as RenderedReport, a as ReportDocument, b as ReportFormat, c as ReportSection, d as ResolvedColumn, S as SummaryRow } from './ir-CUi0Z9hv.cjs';
|
|
5
5
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { M as MessageKey, F as FieldType, C as ColumnAlignment, a as ColumnPresentationConfig, b as ColumnGroupConfig, R as ReportType, c as ReportConfig, d as ReportColumnKey } from './report-pbGeYM8Q.js';
|
|
2
|
-
export { e as COLUMN_REGISTRY, f as ColumnMessageKey, g as ColumnMetadata, h as FooterCalculation, i as FooterCalculationType, j as Report, k as getColumnExportHeaderLabel, l as getColumnMetadata, m as getFixedColumns, n as getReportConfig, o as getReportExportFileName } from './report-pbGeYM8Q.js';
|
|
2
|
+
export { A as AnalyticsField, e as COLUMN_REGISTRY, f as ColumnMessageKey, g as ColumnMetadata, h as FooterCalculation, i as FooterCalculationType, j as Report, k as getColumnExportHeaderLabel, l as getColumnMetadata, m as getFixedColumns, n as getReportConfig, o as getReportExportFileName } from './report-pbGeYM8Q.js';
|
|
3
3
|
import { LocaleCode } from '@harbortouch/locale-registry';
|
|
4
4
|
export { R as RenderedReport, a as ReportDocument, b as ReportFormat, c as ReportSection, d as ResolvedColumn, S as SummaryRow } from './ir-CUi0Z9hv.js';
|
|
5
5
|
|