@kivacore/ui-pro-shared 0.0.9 → 0.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +167 -1
- package/src/.kiva/config.json +27 -0
- package/src/components/avatar-group.tsx +222 -0
- package/src/components/kiva/bulk-update-dialog/bulk-update-dialog.tsx +240 -0
- package/src/components/kiva/bulk-update-dialog/index.tsx +6 -0
- package/src/components/kiva/bulk-update-dialog/types.ts +33 -0
- package/src/components/kiva/calendar/animations.ts +40 -0
- package/src/components/kiva/calendar/calendar-body.tsx +106 -0
- package/src/components/kiva/calendar/calendar-sidebar.tsx +103 -0
- package/src/components/kiva/calendar/calendar.tsx +243 -0
- package/src/components/kiva/calendar/constants.ts +12 -0
- package/src/components/kiva/calendar/contexts/calendar-context.tsx +696 -0
- package/src/components/kiva/calendar/contexts/dnd-context.tsx +173 -0
- package/src/components/kiva/calendar/dialogs/add-edit-event-dialog.tsx +287 -0
- package/src/components/kiva/calendar/dialogs/delete-event-dialog.tsx +73 -0
- package/src/components/kiva/calendar/dialogs/event-details-dialog.tsx +163 -0
- package/src/components/kiva/calendar/dialogs/events-list-dialog.tsx +122 -0
- package/src/components/kiva/calendar/dnd/draggable-event.tsx +66 -0
- package/src/components/kiva/calendar/dnd/droppable-area.tsx +53 -0
- package/src/components/kiva/calendar/dnd/resizable-event.tsx +190 -0
- package/src/components/kiva/calendar/header/calendar-header.tsx +84 -0
- package/src/components/kiva/calendar/header/date-navigator.tsx +188 -0
- package/src/components/kiva/calendar/header/filter.tsx +80 -0
- package/src/components/kiva/calendar/header/today-button.tsx +49 -0
- package/src/components/kiva/calendar/header/user-select.tsx +111 -0
- package/src/components/kiva/calendar/header/view-tabs.tsx +144 -0
- package/src/components/kiva/calendar/helpers.ts +617 -0
- package/src/components/kiva/calendar/hooks/use-disclosure.ts +19 -0
- package/src/components/kiva/calendar/hooks/use-local-storage.ts +40 -0
- package/src/components/kiva/calendar/hooks/use-media-query.ts +25 -0
- package/src/components/kiva/calendar/hooks.ts +5 -0
- package/src/components/kiva/calendar/index.tsx +27 -0
- package/src/components/kiva/calendar/interfaces.ts +35 -0
- package/src/components/kiva/calendar/schemas.ts +20 -0
- package/src/components/kiva/calendar/settings/settings.tsx +116 -0
- package/src/components/kiva/calendar/skeletons/calendar-header-skeleton.tsx +27 -0
- package/src/components/kiva/calendar/skeletons/calendar-skeleton.tsx +19 -0
- package/src/components/kiva/calendar/skeletons/day-view-skeleton.tsx +40 -0
- package/src/components/kiva/calendar/skeletons/month-view-skeleton.tsx +36 -0
- package/src/components/kiva/calendar/skeletons/week-view-skeleton.tsx +48 -0
- package/src/components/kiva/calendar/skeletons/year-view-skeleton.tsx +42 -0
- package/src/components/kiva/calendar/types.ts +25 -0
- package/src/components/kiva/calendar/views/agenda-view/agenda-events.tsx +150 -0
- package/src/components/kiva/calendar/views/month-view/calendar-month-view.tsx +82 -0
- package/src/components/kiva/calendar/views/month-view/day-cell.tsx +218 -0
- package/src/components/kiva/calendar/views/month-view/event-bullet.tsx +46 -0
- package/src/components/kiva/calendar/views/month-view/month-event-badge.tsx +154 -0
- package/src/components/kiva/calendar/views/timeline/calendar-timeline-view.tsx +100 -0
- package/src/components/kiva/calendar/views/timeline/lib/timeline-layout.ts +130 -0
- package/src/components/kiva/calendar/views/timeline/lib/timeline-model.ts +504 -0
- package/src/components/kiva/calendar/views/timeline/timeline-event-bar.tsx +68 -0
- package/src/components/kiva/calendar/views/timeline/timeline-grid-header.tsx +125 -0
- package/src/components/kiva/calendar/views/timeline/timeline-row.tsx +159 -0
- package/src/components/kiva/calendar/views/timeline/timeline-section.tsx +61 -0
- package/src/components/kiva/calendar/views/timeline/use-timeline-sections.ts +278 -0
- package/src/components/kiva/calendar/views/week-and-day-view/calendar-day-view.tsx +277 -0
- package/src/components/kiva/calendar/views/week-and-day-view/calendar-time-line.tsx +47 -0
- package/src/components/kiva/calendar/views/week-and-day-view/calendar-week-view.tsx +229 -0
- package/src/components/kiva/calendar/views/week-and-day-view/day-view-multi-day-events-row.tsx +79 -0
- package/src/components/kiva/calendar/views/week-and-day-view/event-block.tsx +116 -0
- package/src/components/kiva/calendar/views/week-and-day-view/render-grouped-events.tsx +54 -0
- package/src/components/kiva/calendar/views/week-and-day-view/week-view-multi-day-events-row.tsx +159 -0
- package/src/components/kiva/calendar/views/year-view/calendar-year-view.tsx +159 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-active-chips.tsx +137 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-clear.tsx +34 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-search.tsx +67 -0
- package/src/components/kiva/data-table-side-filters/components/side-filter-section.tsx +77 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-async-options.tsx +354 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-boolean.tsx +66 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-checkbox-list.tsx +137 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-date-range.tsx +204 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-numeric-range.tsx +162 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-options-dropdown.tsx +191 -0
- package/src/components/kiva/data-table-side-filters/controllers/side-filter-text.tsx +53 -0
- package/src/components/kiva/data-table-side-filters/core/query-translator.ts +367 -0
- package/src/components/kiva/data-table-side-filters/core/types.ts +81 -0
- package/src/components/kiva/data-table-side-filters/data-table-side-filters.tsx +483 -0
- package/src/components/kiva/data-table-side-filters/hooks/use-data-table-side-filters.tsx +160 -0
- package/src/components/kiva/data-table-side-filters/hooks/use-show-more.tsx +62 -0
- package/src/components/kiva/data-table-side-filters/index.tsx +44 -0
- package/src/components/kiva/data-table-side-filters/lib/render-mode.ts +62 -0
- package/src/components/kiva/date-time-picker.tsx +163 -0
- package/src/components/kiva/editable-record-detail.tsx +809 -0
- package/src/components/kiva/enum-option-editor/enum-option-editor.tsx +891 -0
- package/src/components/kiva/enum-option-editor/index.tsx +26 -0
- package/src/components/kiva/enum-option-editor/kiva-enum-option-editor.tsx +320 -0
- package/src/components/kiva/enum-option-editor/types.ts +90 -0
- package/src/components/kiva/kanban.tsx +1376 -0
- package/src/components/kiva/kiva-data-export-menu.tsx +543 -0
- package/src/components/kiva/map.tsx +1631 -0
- package/src/components/kiva/pivot-calendar/components/group-sidebar.tsx +95 -0
- package/src/components/kiva/pivot-calendar/components/pivot-calendar-toolbar.tsx +113 -0
- package/src/components/kiva/pivot-calendar/components/stats-cell.tsx +126 -0
- package/src/components/kiva/pivot-calendar/helpers.ts +374 -0
- package/src/components/kiva/pivot-calendar/hooks/use-pivot-calendar.ts +222 -0
- package/src/components/kiva/pivot-calendar/index.tsx +32 -0
- package/src/components/kiva/pivot-calendar/pivot-calendar.tsx +107 -0
- package/src/components/kiva/pivot-calendar/types.ts +154 -0
- package/src/components/kiva/pivot-calendar/views/days-of-month-view.tsx +37 -0
- package/src/components/kiva/pivot-calendar/views/days-of-week-view.tsx +37 -0
- package/src/components/kiva/pivot-calendar/views/month-calendar-view.tsx +154 -0
- package/src/components/kiva/pivot-calendar/views/months-of-year-view.tsx +40 -0
- package/src/components/kiva/pivot-calendar/views/pivot-grid-view.tsx +251 -0
- package/src/components/kiva/pivot-filter/index.tsx +9 -0
- package/src/components/kiva/pivot-filter/pivot-filter-item.tsx +159 -0
- package/src/components/kiva/pivot-filter/pivot-filter-settings.tsx +161 -0
- package/src/components/kiva/pivot-filter/pivot-filter.tsx +187 -0
- package/src/components/kiva/pivot-filter/types.ts +82 -0
- package/src/components/kiva/pivot-grid/hooks/use-pivot-grid.ts +683 -0
- package/src/components/kiva/pivot-grid/index.tsx +23 -0
- package/src/components/kiva/pivot-grid/lib/pivot-grid-color-rules.ts +98 -0
- package/src/components/kiva/pivot-grid/lib/pivot-grid-export.ts +265 -0
- package/src/components/kiva/pivot-grid/lib/pivot-grid-model.ts +1110 -0
- package/src/components/kiva/pivot-grid/pivot-grid-demo-data.ts +200 -0
- package/src/components/kiva/pivot-grid/pivot-grid-export-menu.tsx +66 -0
- package/src/components/kiva/pivot-grid/pivot-grid-toolbar.tsx +85 -0
- package/src/components/kiva/pivot-grid/pivot-grid.tsx +601 -0
- package/src/components/kiva/pivot-grid/types.ts +195 -0
- package/src/components/kiva/place-autocomplete.tsx +484 -0
- package/src/components/kiva/record-delete-confirm-dialog/index.tsx +10 -0
- package/src/components/kiva/record-delete-confirm-dialog/record-delete-confirm-dialog.tsx +266 -0
- package/src/components/kiva/record-delete-confirm-dialog/types.ts +25 -0
- package/src/hooks/kiva/_internal/autonumber-setting.ts +112 -0
- package/src/hooks/kiva/_internal/form-layout-to-view.ts +665 -0
- package/src/hooks/kiva/_internal/kiva-hook-utils.ts +143 -0
- package/src/hooks/kiva/_internal/use-computed-field-evaluator.tsx +310 -0
- package/src/hooks/kiva/_internal/use-field-actions-evaluator.tsx +398 -0
- package/src/hooks/kiva/_internal/use-form-actions-evaluator.tsx +363 -0
- package/src/hooks/kiva/_internal/use-form-view-engine.tsx +2200 -0
- package/src/hooks/kiva/_internal/use-kiva-form-view-fields.tsx +190 -0
- package/src/hooks/kiva/_internal/use-kiva-kanban-cards.tsx +311 -0
- package/src/hooks/kiva/use-data-export.tsx +265 -0
- package/src/hooks/kiva/use-kiva-calendar.tsx +992 -0
- package/src/hooks/kiva/use-kiva-data-export.tsx +173 -0
- package/src/hooks/kiva/use-kiva-data-grid.tsx +4750 -0
- package/src/hooks/kiva/use-kiva-data-view-select.tsx +1273 -0
- package/src/hooks/kiva/use-kiva-form-view.tsx +1581 -0
- package/src/hooks/kiva/use-kiva-inventory.tsx +184 -0
- package/src/hooks/kiva/use-kiva-kanban.tsx +1750 -0
- package/src/hooks/kiva/use-kiva-map-view.tsx +2255 -0
- package/src/hooks/kiva/use-kiva-pivot-calendar.tsx +759 -0
- package/src/hooks/kiva/use-kiva-pivot-filter.tsx +1523 -0
- package/src/hooks/kiva/use-kiva-pivot-grid.tsx +543 -0
- package/src/hooks/kiva/use-kiva-tenant.tsx +313 -0
- package/src/hooks/kiva/use-parameter-persistence.ts +191 -0
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
import jsonata from 'jsonata';
|
|
4
|
+
|
|
5
|
+
import { resolveColorHex } from '@kivacore/ui-pro-shared/lib/kiva/tailwind-colors';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
type PivotGridCellColorRule,
|
|
9
|
+
type PivotGridColorScope,
|
|
10
|
+
type PivotGridRenderedCell
|
|
11
|
+
} from '../types';
|
|
12
|
+
|
|
13
|
+
interface CompiledRule {
|
|
14
|
+
scope?: PivotGridColorScope;
|
|
15
|
+
expression: jsonata.Expression;
|
|
16
|
+
color: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function getCellScope<TData>(
|
|
20
|
+
cell: PivotGridRenderedCell<TData>
|
|
21
|
+
): PivotGridColorScope {
|
|
22
|
+
if (cell.isGrandTotal) {
|
|
23
|
+
return 'grand-total';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (cell.isTotal) {
|
|
27
|
+
return 'total';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (cell.isSubtotal) {
|
|
31
|
+
return 'subtotal';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return 'leaf';
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function compilePivotGridCellColorRules(
|
|
38
|
+
rules: Array<PivotGridCellColorRule>
|
|
39
|
+
): Array<CompiledRule> {
|
|
40
|
+
const compiledRules: Array<CompiledRule> = [];
|
|
41
|
+
|
|
42
|
+
for (const rule of rules) {
|
|
43
|
+
try {
|
|
44
|
+
compiledRules.push({
|
|
45
|
+
scope: rule.scope,
|
|
46
|
+
expression: jsonata(rule.formula),
|
|
47
|
+
color: resolveColorHex(rule.color)
|
|
48
|
+
});
|
|
49
|
+
} catch {
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return compiledRules;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function evaluatePivotGridCellColorRules<TData>(
|
|
57
|
+
compiledRules: Array<CompiledRule>,
|
|
58
|
+
cells: Array<PivotGridRenderedCell<TData>>
|
|
59
|
+
): Promise<Map<string, string>> {
|
|
60
|
+
const colorMap = new Map<string, string>();
|
|
61
|
+
|
|
62
|
+
if (compiledRules.length === 0) {
|
|
63
|
+
return colorMap;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
for (const cell of cells) {
|
|
67
|
+
const cellScope = getCellScope(cell);
|
|
68
|
+
|
|
69
|
+
for (const rule of compiledRules) {
|
|
70
|
+
if (rule.scope && rule.scope !== cellScope) {
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
try {
|
|
75
|
+
const result = await rule.expression.evaluate({
|
|
76
|
+
value: cell.value,
|
|
77
|
+
measureId: cell.measureId,
|
|
78
|
+
rowPath: cell.rowPath,
|
|
79
|
+
columnPath: cell.columnPath,
|
|
80
|
+
rowDepth: cell.rowPath.length,
|
|
81
|
+
columnDepth: cell.columnPath.length,
|
|
82
|
+
isSubtotal: cell.isSubtotal,
|
|
83
|
+
isTotal: cell.isTotal,
|
|
84
|
+
isGrandTotal: cell.isGrandTotal,
|
|
85
|
+
rawRowCount: cell.rawRowCount
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
if (result) {
|
|
89
|
+
colorMap.set(cell.id, rule.color);
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return colorMap;
|
|
98
|
+
}
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
import { type PivotGridRenderedColumnKind, type PivotGridRenderedRow } from '../types';
|
|
4
|
+
|
|
5
|
+
export interface PivotGridExportColumn {
|
|
6
|
+
id: string;
|
|
7
|
+
headerPath: Array<string>;
|
|
8
|
+
width: number;
|
|
9
|
+
kind: PivotGridRenderedColumnKind;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface PivotGridExportSnapshot<TData> {
|
|
13
|
+
fileName: string;
|
|
14
|
+
headerDepth: number;
|
|
15
|
+
rowHeaderLabels: Array<string>;
|
|
16
|
+
rowHeaderWidths: Array<number>;
|
|
17
|
+
valueColumns: Array<PivotGridExportColumn>;
|
|
18
|
+
rows: Array<PivotGridRenderedRow<TData>>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function escapeCsvValue(value: string): string {
|
|
22
|
+
if (/[",\n]/.test(value)) {
|
|
23
|
+
return `"${value.replaceAll('"', '""')}"`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function downloadBlob(blob: Blob, fileName: string): void {
|
|
30
|
+
const url = URL.createObjectURL(blob);
|
|
31
|
+
const link = document.createElement('a');
|
|
32
|
+
|
|
33
|
+
link.href = url;
|
|
34
|
+
link.download = fileName;
|
|
35
|
+
link.rel = 'noopener';
|
|
36
|
+
link.style.display = 'none';
|
|
37
|
+
document.body.append(link);
|
|
38
|
+
link.click();
|
|
39
|
+
|
|
40
|
+
window.setTimeout(() => {
|
|
41
|
+
link.remove();
|
|
42
|
+
URL.revokeObjectURL(url);
|
|
43
|
+
}, 1000);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function downloadTextFile(content: string, fileName: string): void {
|
|
47
|
+
downloadBlob(new Blob([content], { type: 'text/csv;charset=utf-8' }), fileName);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export function buildPivotGridCsv(snapshot: PivotGridExportSnapshot<unknown>): string {
|
|
51
|
+
const headerRow = [
|
|
52
|
+
...snapshot.rowHeaderLabels,
|
|
53
|
+
...snapshot.valueColumns.map((column) => {
|
|
54
|
+
const labels = column.headerPath.filter(Boolean);
|
|
55
|
+
|
|
56
|
+
return labels.length > 0 ? labels.join(' / ') : 'Value';
|
|
57
|
+
})
|
|
58
|
+
];
|
|
59
|
+
|
|
60
|
+
const bodyRows = snapshot.rows.map((row) => {
|
|
61
|
+
const rowHeaders = row.headerCells.map(cell => cell.label);
|
|
62
|
+
const values = snapshot.valueColumns.map(
|
|
63
|
+
column => row.cellMap.get(column.id)?.formattedValue ?? ''
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
return [...rowHeaders, ...values];
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
return [headerRow, ...bodyRows]
|
|
70
|
+
.map(row => row.map(value => escapeCsvValue(value ?? '')).join(','))
|
|
71
|
+
.join('\n');
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function buildHeaderMatrix(snapshot: PivotGridExportSnapshot<unknown>): Array<Array<string>> {
|
|
75
|
+
const headerMatrix = Array.from(
|
|
76
|
+
{ length: snapshot.headerDepth },
|
|
77
|
+
() => Array.from(
|
|
78
|
+
{ length: snapshot.rowHeaderLabels.length + snapshot.valueColumns.length },
|
|
79
|
+
() => ''
|
|
80
|
+
)
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
snapshot.rowHeaderLabels.forEach((label, columnIndex) => {
|
|
84
|
+
(headerMatrix[0] as string[])[columnIndex] = label;
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
snapshot.valueColumns.forEach((column, columnIndex) => {
|
|
88
|
+
column.headerPath.forEach((label, level) => {
|
|
89
|
+
(headerMatrix[level] as string[])[snapshot.rowHeaderLabels.length + columnIndex] = label;
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
return headerMatrix;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
export async function exportPivotGridExcel(
|
|
97
|
+
snapshot: PivotGridExportSnapshot<unknown>
|
|
98
|
+
): Promise<void> {
|
|
99
|
+
const { Workbook } = await import('exceljs');
|
|
100
|
+
|
|
101
|
+
const workbook = new Workbook();
|
|
102
|
+
const worksheet = workbook.addWorksheet('Pivot Grid', {
|
|
103
|
+
views: [
|
|
104
|
+
{
|
|
105
|
+
state: 'frozen',
|
|
106
|
+
xSplit: snapshot.rowHeaderLabels.length,
|
|
107
|
+
ySplit: snapshot.headerDepth
|
|
108
|
+
}
|
|
109
|
+
]
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const headerMatrix = buildHeaderMatrix(snapshot);
|
|
113
|
+
const valueColumnOffset = snapshot.rowHeaderLabels.length;
|
|
114
|
+
|
|
115
|
+
headerMatrix.forEach((row) => {
|
|
116
|
+
worksheet.addRow(row);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
for (let columnIndex = 0; columnIndex < snapshot.rowHeaderLabels.length; columnIndex += 1) {
|
|
120
|
+
if (snapshot.headerDepth > 1) {
|
|
121
|
+
worksheet.mergeCells(1, columnIndex + 1, snapshot.headerDepth, columnIndex + 1);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
for (let level = 0; level < snapshot.headerDepth; level += 1) {
|
|
126
|
+
let startIndex = valueColumnOffset;
|
|
127
|
+
const levelRow = headerMatrix[level] as string[];
|
|
128
|
+
let previousValue = levelRow[valueColumnOffset] ?? '';
|
|
129
|
+
|
|
130
|
+
for (let columnIndex = valueColumnOffset + 1; columnIndex <= levelRow.length; columnIndex += 1) {
|
|
131
|
+
const nextValue = levelRow[columnIndex] ?? '';
|
|
132
|
+
|
|
133
|
+
if (
|
|
134
|
+
previousValue
|
|
135
|
+
&& previousValue === nextValue
|
|
136
|
+
) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (previousValue && columnIndex - startIndex > 1) {
|
|
141
|
+
worksheet.mergeCells(level + 1, startIndex + 1, level + 1, columnIndex);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
startIndex = columnIndex;
|
|
145
|
+
previousValue = nextValue;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
snapshot.rows.forEach((row) => {
|
|
150
|
+
worksheet.addRow([
|
|
151
|
+
...row.headerCells.map(cell => cell.label),
|
|
152
|
+
...snapshot.valueColumns.map(
|
|
153
|
+
column => row.cellMap.get(column.id)?.formattedValue ?? ''
|
|
154
|
+
)
|
|
155
|
+
]);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
worksheet.columns = [...snapshot.rowHeaderWidths.map(width => ({ width: Math.max(12, width / 8) })), ...snapshot.valueColumns.map(column => ({ width: Math.max(12, column.width / 8) }))];
|
|
159
|
+
|
|
160
|
+
worksheet.eachRow((row, rowNumber) => {
|
|
161
|
+
row.eachCell((cell, columnNumber) => {
|
|
162
|
+
cell.alignment = { horizontal: 'center', vertical: 'middle' };
|
|
163
|
+
cell.border = {
|
|
164
|
+
top: { style: 'thin', color: { argb: 'FFE5E7EB' } },
|
|
165
|
+
left: { style: 'thin', color: { argb: 'FFE5E7EB' } },
|
|
166
|
+
bottom: { style: 'thin', color: { argb: 'FFE5E7EB' } },
|
|
167
|
+
right: { style: 'thin', color: { argb: 'FFE5E7EB' } }
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
if (rowNumber <= snapshot.headerDepth) {
|
|
171
|
+
cell.font = { bold: true };
|
|
172
|
+
cell.fill = {
|
|
173
|
+
type: 'pattern',
|
|
174
|
+
pattern: 'solid',
|
|
175
|
+
fgColor: { argb: 'FFF3F4F6' }
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
return;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const dataRow = snapshot.rows[rowNumber - snapshot.headerDepth - 1];
|
|
182
|
+
|
|
183
|
+
if (!dataRow) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const isValueColumn = columnNumber > snapshot.rowHeaderLabels.length;
|
|
188
|
+
const valueColumn = isValueColumn ? snapshot.valueColumns[columnNumber - snapshot.rowHeaderLabels.length - 1] : null;
|
|
189
|
+
|
|
190
|
+
if (dataRow.kind === 'grand-total') {
|
|
191
|
+
cell.font = { bold: true };
|
|
192
|
+
cell.fill = {
|
|
193
|
+
type: 'pattern',
|
|
194
|
+
pattern: 'solid',
|
|
195
|
+
fgColor: { argb: 'FFE5E7EB' }
|
|
196
|
+
};
|
|
197
|
+
} else if (dataRow.kind === 'subtotal') {
|
|
198
|
+
cell.font = { bold: true };
|
|
199
|
+
cell.fill = {
|
|
200
|
+
type: 'pattern',
|
|
201
|
+
pattern: 'solid',
|
|
202
|
+
fgColor: { argb: 'FFF9FAFB' }
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
if (valueColumn?.kind === 'grand-total' && dataRow.kind !== 'grand-total') {
|
|
207
|
+
cell.fill = {
|
|
208
|
+
type: 'pattern',
|
|
209
|
+
pattern: 'solid',
|
|
210
|
+
fgColor: { argb: 'FFE5E7EB' }
|
|
211
|
+
};
|
|
212
|
+
} else if (valueColumn?.kind === 'subtotal' && dataRow.kind === 'leaf') {
|
|
213
|
+
cell.fill = {
|
|
214
|
+
type: 'pattern',
|
|
215
|
+
pattern: 'solid',
|
|
216
|
+
fgColor: { argb: 'FFF9FAFB' }
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
const buffer = await workbook.xlsx.writeBuffer();
|
|
223
|
+
|
|
224
|
+
downloadBlob(
|
|
225
|
+
new Blob([buffer], {
|
|
226
|
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
227
|
+
}),
|
|
228
|
+
`${snapshot.fileName}.xlsx`
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export async function exportPivotGridPdf(params: {
|
|
233
|
+
element: HTMLElement;
|
|
234
|
+
fileName: string;
|
|
235
|
+
}): Promise<void> {
|
|
236
|
+
const { element, fileName } = params;
|
|
237
|
+
const [{ default: html2canvas }, PDFLib] = await Promise.all([import('html2canvas-pro'), import('pdf-lib')]);
|
|
238
|
+
|
|
239
|
+
const canvas = await html2canvas(element, {
|
|
240
|
+
backgroundColor: '#ffffff',
|
|
241
|
+
width: element.scrollWidth,
|
|
242
|
+
height: element.scrollHeight,
|
|
243
|
+
windowWidth: element.scrollWidth,
|
|
244
|
+
windowHeight: element.scrollHeight
|
|
245
|
+
});
|
|
246
|
+
|
|
247
|
+
const pdfDocument = await PDFLib.PDFDocument.create();
|
|
248
|
+
const page = pdfDocument.addPage([canvas.width, canvas.height]);
|
|
249
|
+
const image = await pdfDocument.embedPng(canvas.toDataURL('image/png'));
|
|
250
|
+
|
|
251
|
+
page.drawImage(image, {
|
|
252
|
+
x: 0,
|
|
253
|
+
y: 0,
|
|
254
|
+
width: canvas.width,
|
|
255
|
+
height: canvas.height
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const pdfBytes = await pdfDocument.save();
|
|
259
|
+
const pdfArray = Uint8Array.from(pdfBytes);
|
|
260
|
+
|
|
261
|
+
downloadBlob(
|
|
262
|
+
new Blob([pdfArray.buffer], { type: 'application/pdf' }),
|
|
263
|
+
`${fileName}.pdf`
|
|
264
|
+
);
|
|
265
|
+
}
|