@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,265 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
// @ts-nocheck
|
|
4
|
+
/* eslint-disable */
|
|
5
|
+
import { useCallback, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
export type DataExportFormat = 'csv' | 'json' | 'markdown' | 'xlsx';
|
|
8
|
+
|
|
9
|
+
export interface DataExportColumn<TData> {
|
|
10
|
+
/** Stable column id (also used as the JSON object key when format = 'json'). */
|
|
11
|
+
id: string;
|
|
12
|
+
/** Header label rendered in CSV / Markdown / Excel. */
|
|
13
|
+
header: string;
|
|
14
|
+
/**
|
|
15
|
+
* Pull the raw cell value for this column from a row. Defaults to
|
|
16
|
+
* `row[id]` when omitted.
|
|
17
|
+
*/
|
|
18
|
+
accessor?: (row: TData) => unknown;
|
|
19
|
+
/**
|
|
20
|
+
* Optional formatter run after `accessor` to coerce the raw value into the
|
|
21
|
+
* string written to the file. The default formatter renders primitives
|
|
22
|
+
* verbatim and `JSON.stringify`s objects/arrays.
|
|
23
|
+
*/
|
|
24
|
+
formatter?: (value: unknown, row: TData) => string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface UseDataExportOptions<TData> {
|
|
28
|
+
/**
|
|
29
|
+
* Column projection. Order is preserved in the output. Can be left out when
|
|
30
|
+
* every `exportData` call passes its own columns.
|
|
31
|
+
*/
|
|
32
|
+
columns?: Array<DataExportColumn<TData>>;
|
|
33
|
+
/** File name without extension. Default `'export'`. */
|
|
34
|
+
fileName?: string;
|
|
35
|
+
/** Sheet name for xlsx. Default `'Sheet1'`. */
|
|
36
|
+
sheetName?: string;
|
|
37
|
+
/** Prepend a UTF-8 BOM to CSV output (helps Excel detect encoding). Default `true`. */
|
|
38
|
+
csvBom?: boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface DataExportResult {
|
|
42
|
+
/** MIME type written to the Blob. */
|
|
43
|
+
mimeType: string;
|
|
44
|
+
/** File extension including leading dot. */
|
|
45
|
+
extension: string;
|
|
46
|
+
/** Final file name (`<fileName><extension>`). */
|
|
47
|
+
fileName: string;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface UseDataExportResult<TData> {
|
|
51
|
+
/**
|
|
52
|
+
* Project `rows` through `columns` (this call's, else the hook's) and
|
|
53
|
+
* trigger a browser download in the requested `format`. Returns the
|
|
54
|
+
* resolved file name + MIME type. No-ops on the server (returns `null`).
|
|
55
|
+
*/
|
|
56
|
+
exportData: (
|
|
57
|
+
rows: Array<TData>,
|
|
58
|
+
format: DataExportFormat,
|
|
59
|
+
columns?: Array<DataExportColumn<TData>>
|
|
60
|
+
) => Promise<DataExportResult | null>;
|
|
61
|
+
isExporting: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const FORMAT_META: Record<DataExportFormat, { extension: string; mimeType: string }> = {
|
|
65
|
+
csv: { extension: '.csv', mimeType: 'text/csv;charset=utf-8' },
|
|
66
|
+
json: { extension: '.json', mimeType: 'application/json;charset=utf-8' },
|
|
67
|
+
markdown: { extension: '.md', mimeType: 'text/markdown;charset=utf-8' },
|
|
68
|
+
xlsx: {
|
|
69
|
+
extension: '.xlsx',
|
|
70
|
+
mimeType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const NO_COLUMNS: Array<DataExportColumn<unknown>> = [];
|
|
75
|
+
|
|
76
|
+
export function useDataExport<TData>(
|
|
77
|
+
options: UseDataExportOptions<TData>
|
|
78
|
+
): UseDataExportResult<TData> {
|
|
79
|
+
const {
|
|
80
|
+
columns: defaultColumns = NO_COLUMNS,
|
|
81
|
+
fileName = 'export',
|
|
82
|
+
sheetName = 'Sheet1',
|
|
83
|
+
csvBom = true
|
|
84
|
+
} = options;
|
|
85
|
+
|
|
86
|
+
const [isExporting, setIsExporting] = useState(false);
|
|
87
|
+
|
|
88
|
+
const exportData = useCallback(
|
|
89
|
+
async (rows: Array<TData>, format: DataExportFormat, columns: Array<DataExportColumn<TData>> = defaultColumns) => {
|
|
90
|
+
if (typeof window === 'undefined') return null;
|
|
91
|
+
|
|
92
|
+
setIsExporting(true);
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
const meta = FORMAT_META[format];
|
|
96
|
+
const resolvedFileName = `${fileName}${meta.extension}`;
|
|
97
|
+
|
|
98
|
+
const projected = rows.map(row => projectRow(row, columns));
|
|
99
|
+
|
|
100
|
+
let blob: Blob;
|
|
101
|
+
|
|
102
|
+
if (format === 'csv') {
|
|
103
|
+
const body = buildCsv(columns, projected, csvBom);
|
|
104
|
+
|
|
105
|
+
blob = new Blob([body], { type: meta.mimeType });
|
|
106
|
+
} else if (format === 'json') {
|
|
107
|
+
const body = JSON.stringify(projected, null, 2);
|
|
108
|
+
|
|
109
|
+
blob = new Blob([body], { type: meta.mimeType });
|
|
110
|
+
} else if (format === 'markdown') {
|
|
111
|
+
const body = buildMarkdown(columns, projected);
|
|
112
|
+
|
|
113
|
+
blob = new Blob([body], { type: meta.mimeType });
|
|
114
|
+
} else {
|
|
115
|
+
blob = await buildXlsxBlob(columns, projected, sheetName);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
triggerDownload(blob, resolvedFileName);
|
|
119
|
+
|
|
120
|
+
return {
|
|
121
|
+
mimeType: meta.mimeType,
|
|
122
|
+
extension: meta.extension,
|
|
123
|
+
fileName: resolvedFileName
|
|
124
|
+
};
|
|
125
|
+
} finally {
|
|
126
|
+
setIsExporting(false);
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
[
|
|
130
|
+
defaultColumns,
|
|
131
|
+
fileName,
|
|
132
|
+
sheetName,
|
|
133
|
+
csvBom
|
|
134
|
+
]
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
return { exportData, isExporting };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function projectRow<TData>(
|
|
141
|
+
row: TData,
|
|
142
|
+
columns: Array<DataExportColumn<TData>>
|
|
143
|
+
): Record<string, unknown> {
|
|
144
|
+
const result: Record<string, unknown> = {};
|
|
145
|
+
|
|
146
|
+
for (const column of columns) {
|
|
147
|
+
const raw = column.accessor ? column.accessor(row) : (row as Record<string, unknown>)[column.id];
|
|
148
|
+
|
|
149
|
+
result[column.id] = column.formatter ? column.formatter(raw, row) : raw;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function defaultStringify(value: unknown): string {
|
|
156
|
+
if (value === null || value === undefined) return '';
|
|
157
|
+
if (typeof value === 'string') return value;
|
|
158
|
+
if (typeof value === 'number' || typeof value === 'boolean') return String(value);
|
|
159
|
+
if (value instanceof Date) return value.toISOString();
|
|
160
|
+
|
|
161
|
+
try {
|
|
162
|
+
return JSON.stringify(value);
|
|
163
|
+
} catch {
|
|
164
|
+
return String(value);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
function escapeCsvCell(value: unknown): string {
|
|
169
|
+
const str = defaultStringify(value);
|
|
170
|
+
|
|
171
|
+
if (/[",\r\n]/.test(str)) {
|
|
172
|
+
return `"${str.replace(/"/g, '""')}"`;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
return str;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function buildCsv<TData>(
|
|
179
|
+
columns: Array<DataExportColumn<TData>>,
|
|
180
|
+
rows: Array<Record<string, unknown>>,
|
|
181
|
+
withBom: boolean
|
|
182
|
+
): string {
|
|
183
|
+
const header = columns.map(column => escapeCsvCell(column.header)).join(',');
|
|
184
|
+
const lines = rows.map(row => columns.map(column => escapeCsvCell(row[column.id])).join(','));
|
|
185
|
+
const body = [header, ...lines].join('\r\n');
|
|
186
|
+
|
|
187
|
+
return withBom ? `${body}` : body;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
function escapeMarkdownCell(value: unknown): string {
|
|
191
|
+
return defaultStringify(value)
|
|
192
|
+
.replace(/\\/g, '\\\\')
|
|
193
|
+
.replace(/\|/g, '\\|')
|
|
194
|
+
.replace(/\r?\n/g, '<br />');
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function buildMarkdown<TData>(
|
|
198
|
+
columns: Array<DataExportColumn<TData>>,
|
|
199
|
+
rows: Array<Record<string, unknown>>
|
|
200
|
+
): string {
|
|
201
|
+
const header = `| ${columns.map(column => escapeMarkdownCell(column.header)).join(' | ')} |`;
|
|
202
|
+
const divider = `| ${columns.map(() => '---').join(' | ')} |`;
|
|
203
|
+
const body = rows.map(
|
|
204
|
+
row => `| ${columns.map(column => escapeMarkdownCell(row[column.id])).join(' | ')} |`
|
|
205
|
+
);
|
|
206
|
+
|
|
207
|
+
return [header, divider, ...body].join('\n');
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async function buildXlsxBlob<TData>(
|
|
211
|
+
columns: Array<DataExportColumn<TData>>,
|
|
212
|
+
rows: Array<Record<string, unknown>>,
|
|
213
|
+
sheetName: string
|
|
214
|
+
): Promise<Blob> {
|
|
215
|
+
/*
|
|
216
|
+
* Use `exceljs` instead of `xlsx` (SheetJS) — the upstream package has
|
|
217
|
+
* unpatched advisories (GHSA-4r6h-8v6p-xvw6 Prototype Pollution,
|
|
218
|
+
* GHSA-5pgg-2g8v-p4x9 ReDoS) and hasn't shipped a release in years.
|
|
219
|
+
* `exceljs` is actively maintained and already drives the pivot-grid
|
|
220
|
+
* exporter, so consolidating on it keeps the user's bundle leaner.
|
|
221
|
+
*/
|
|
222
|
+
const { Workbook } = await import('exceljs');
|
|
223
|
+
const headerRow = columns.map(column => column.header);
|
|
224
|
+
const bodyRows = rows.map(row => columns.map(column => normalizeXlsxValue(row[column.id])));
|
|
225
|
+
|
|
226
|
+
const workbook = new Workbook();
|
|
227
|
+
const sheet = workbook.addWorksheet(sheetName);
|
|
228
|
+
|
|
229
|
+
sheet.addRow(headerRow);
|
|
230
|
+
for (const row of bodyRows) {
|
|
231
|
+
sheet.addRow(row);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const buffer = await workbook.xlsx.writeBuffer();
|
|
235
|
+
|
|
236
|
+
return new Blob([buffer], {
|
|
237
|
+
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function normalizeXlsxValue(value: unknown): string | number | boolean | Date | null {
|
|
242
|
+
if (value === null || value === undefined) return null;
|
|
243
|
+
if (typeof value === 'string') return value;
|
|
244
|
+
if (typeof value === 'number' || typeof value === 'boolean') return value;
|
|
245
|
+
if (value instanceof Date) return value;
|
|
246
|
+
|
|
247
|
+
try {
|
|
248
|
+
return JSON.stringify(value);
|
|
249
|
+
} catch {
|
|
250
|
+
return String(value);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function triggerDownload(blob: Blob, fileName: string): void {
|
|
255
|
+
const url = URL.createObjectURL(blob);
|
|
256
|
+
const anchor = document.createElement('a');
|
|
257
|
+
|
|
258
|
+
anchor.href = url;
|
|
259
|
+
anchor.download = fileName;
|
|
260
|
+
anchor.style.display = 'none';
|
|
261
|
+
document.body.appendChild(anchor);
|
|
262
|
+
anchor.click();
|
|
263
|
+
document.body.removeChild(anchor);
|
|
264
|
+
URL.revokeObjectURL(url);
|
|
265
|
+
}
|