@papernote/ui 1.0.0 → 1.2.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 -21
- package/README.md +455 -445
- package/dist/components/CurrencyInput.d.ts +52 -0
- package/dist/components/CurrencyInput.d.ts.map +1 -0
- package/dist/components/DataTable.d.ts +3 -1
- package/dist/components/DataTable.d.ts.map +1 -1
- package/dist/components/Modal.d.ts.map +1 -1
- package/dist/components/Page.d.ts +2 -0
- package/dist/components/Page.d.ts.map +1 -1
- package/dist/components/PageLayout.d.ts +5 -1
- package/dist/components/PageLayout.d.ts.map +1 -1
- package/dist/components/Spreadsheet.d.ts +129 -0
- package/dist/components/Spreadsheet.d.ts.map +1 -0
- package/dist/components/Tabs.d.ts +5 -1
- package/dist/components/Tabs.d.ts.map +1 -1
- package/dist/components/index.d.ts +6 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/index.d.ts +336 -5
- package/dist/index.esm.js +51152 -174
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +51145 -143
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1187 -11
- package/dist/utils/excelExport.d.ts +143 -0
- package/dist/utils/excelExport.d.ts.map +1 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +13 -3
- package/src/components/AdminModal.css +49 -49
- package/src/components/CurrencyInput.stories.tsx +290 -0
- package/src/components/CurrencyInput.tsx +193 -0
- package/src/components/DataTable.stories.tsx +87 -0
- package/src/components/DataTable.tsx +149 -37
- package/src/components/Modal.stories.tsx +64 -0
- package/src/components/Modal.tsx +15 -2
- package/src/components/Page.stories.tsx +76 -0
- package/src/components/Page.tsx +35 -3
- package/src/components/PageLayout.stories.tsx +75 -0
- package/src/components/PageLayout.tsx +28 -9
- package/src/components/RoleManager.css +10 -10
- package/src/components/Spreadsheet.css +216 -0
- package/src/components/Spreadsheet.stories.tsx +362 -0
- package/src/components/Spreadsheet.tsx +351 -0
- package/src/components/SpreadsheetSimple.stories.tsx +27 -0
- package/src/components/Tabs.stories.tsx +31 -0
- package/src/components/Tabs.tsx +28 -4
- package/src/components/TimePicker.tsx +1 -1
- package/src/components/Toast.tsx +9 -9
- package/src/components/__tests__/Input.test.tsx +22 -26
- package/src/components/index.ts +11 -2
- package/src/styles/index.css +44 -6
- package/src/utils/excelExport.stories.tsx +535 -0
- package/src/utils/excelExport.ts +225 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/sqlToNaturalLanguage.ts +1 -1
- package/tailwind.config.js +253 -253
- package/dist/components/Button.stories.d.ts +0 -51
- package/dist/components/Button.stories.d.ts.map +0 -1
- package/dist/components/ChartVisualizationUI.d.ts +0 -21
- package/dist/components/ChartVisualizationUI.d.ts.map +0 -1
- package/dist/components/ChatUI.d.ts +0 -23
- package/dist/components/ChatUI.d.ts.map +0 -1
- package/dist/components/CommissionDashboardUI.d.ts +0 -25
- package/dist/components/CommissionDashboardUI.d.ts.map +0 -1
- package/dist/components/DataTable.stories.d.ts +0 -23
- package/dist/components/DataTable.stories.d.ts.map +0 -1
- package/dist/components/FormField.d.ts +0 -35
- package/dist/components/FormField.d.ts.map +0 -1
- package/dist/components/Input.stories.d.ts +0 -366
- package/dist/components/Input.stories.d.ts.map +0 -1
- package/dist/components/InsightsPanelUI.d.ts +0 -21
- package/dist/components/InsightsPanelUI.d.ts.map +0 -1
- package/dist/components/PaymentHistoryTimeline.d.ts +0 -34
- package/dist/components/PaymentHistoryTimeline.d.ts.map +0 -1
- package/dist/components/RelationshipManagerUI.d.ts +0 -60
- package/dist/components/RelationshipManagerUI.d.ts.map +0 -1
- package/dist/components/RoleManager.d.ts +0 -19
- package/dist/components/RoleManager.d.ts.map +0 -1
- package/dist/components/SplitCommissionBadge.d.ts +0 -18
- package/dist/components/SplitCommissionBadge.d.ts.map +0 -1
- package/dist/components/__tests__/Button.test.d.ts +0 -2
- package/dist/components/__tests__/Button.test.d.ts.map +0 -1
- package/dist/components/__tests__/Input.test.d.ts +0 -2
- package/dist/components/__tests__/Input.test.d.ts.map +0 -1
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { utils, writeFile, WorkBook } from 'xlsx';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Column definition for Excel export
|
|
5
|
+
*/
|
|
6
|
+
export interface ExcelColumn {
|
|
7
|
+
/** Key in the data object */
|
|
8
|
+
key: string;
|
|
9
|
+
/** Column header label */
|
|
10
|
+
label: string;
|
|
11
|
+
/** Optional formatter function */
|
|
12
|
+
format?: (value: any) => string | number | boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Options for exporting data to Excel
|
|
17
|
+
*/
|
|
18
|
+
export interface ExportToExcelOptions {
|
|
19
|
+
/** Array of data objects to export */
|
|
20
|
+
data: any[];
|
|
21
|
+
/** Output filename (default: 'export.xlsx') */
|
|
22
|
+
filename?: string;
|
|
23
|
+
/** Sheet name (default: 'Sheet1') */
|
|
24
|
+
sheetName?: string;
|
|
25
|
+
/** Column definitions for custom headers and ordering */
|
|
26
|
+
columns?: ExcelColumn[];
|
|
27
|
+
/** Include headers row (default: true) */
|
|
28
|
+
includeHeaders?: boolean;
|
|
29
|
+
/** Custom workbook for multi-sheet exports */
|
|
30
|
+
workbook?: WorkBook;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Export data to Excel file
|
|
35
|
+
*
|
|
36
|
+
* A standalone utility for exporting any data array to Excel format.
|
|
37
|
+
* Works independently of the Spreadsheet component.
|
|
38
|
+
*
|
|
39
|
+
* **Features:**
|
|
40
|
+
* - Export arrays of objects to Excel
|
|
41
|
+
* - Custom column headers and ordering
|
|
42
|
+
* - Value formatting with custom functions
|
|
43
|
+
* - Multi-sheet support
|
|
44
|
+
* - Automatic type handling
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```typescript
|
|
48
|
+
* // Simple export - uses object keys as headers
|
|
49
|
+
* const data = [
|
|
50
|
+
* { id: 1, name: 'Product A', price: 29.99 },
|
|
51
|
+
* { id: 2, name: 'Product B', price: 49.99 },
|
|
52
|
+
* ];
|
|
53
|
+
* exportToExcel({ data, filename: 'products.xlsx' });
|
|
54
|
+
*
|
|
55
|
+
* // Custom columns with formatting
|
|
56
|
+
* exportToExcel({
|
|
57
|
+
* data: users,
|
|
58
|
+
* filename: 'users.xlsx',
|
|
59
|
+
* columns: [
|
|
60
|
+
* { key: 'id', label: 'ID' },
|
|
61
|
+
* { key: 'name', label: 'Full Name' },
|
|
62
|
+
* { key: 'email', label: 'Email Address' },
|
|
63
|
+
* { key: 'createdAt', label: 'Joined', format: (date) => new Date(date).toLocaleDateString() },
|
|
64
|
+
* { key: 'isActive', label: 'Status', format: (active) => active ? 'Active' : 'Inactive' },
|
|
65
|
+
* ],
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* // Multi-sheet export
|
|
69
|
+
* const wb = utils.book_new();
|
|
70
|
+
* exportToExcel({ data: products, sheetName: 'Products', workbook: wb });
|
|
71
|
+
* exportToExcel({ data: orders, sheetName: 'Orders', workbook: wb });
|
|
72
|
+
* writeFile(wb, 'multi-sheet.xlsx');
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @param options - Export configuration options
|
|
76
|
+
* @returns WorkBook if workbook option provided, otherwise void (auto-downloads)
|
|
77
|
+
*/
|
|
78
|
+
export function exportToExcel({
|
|
79
|
+
data,
|
|
80
|
+
filename = 'export.xlsx',
|
|
81
|
+
sheetName = 'Sheet1',
|
|
82
|
+
columns,
|
|
83
|
+
includeHeaders = true,
|
|
84
|
+
workbook,
|
|
85
|
+
}: ExportToExcelOptions): WorkBook | void {
|
|
86
|
+
if (!data || data.length === 0) {
|
|
87
|
+
throw new Error('No data provided for export');
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
let worksheetData: any[][];
|
|
91
|
+
|
|
92
|
+
if (columns) {
|
|
93
|
+
// Use custom columns with specific ordering and formatting
|
|
94
|
+
const headers = columns.map((col) => col.label);
|
|
95
|
+
const rows = data.map((row) =>
|
|
96
|
+
columns.map((col) => {
|
|
97
|
+
const value = row[col.key];
|
|
98
|
+
return col.format ? col.format(value) : value ?? '';
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
worksheetData = includeHeaders ? [headers, ...rows] : rows;
|
|
103
|
+
} else {
|
|
104
|
+
// Auto-generate from object keys
|
|
105
|
+
if (includeHeaders) {
|
|
106
|
+
const headers = Object.keys(data[0]);
|
|
107
|
+
const rows = data.map((row) => headers.map((key) => row[key] ?? ''));
|
|
108
|
+
worksheetData = [headers, ...rows];
|
|
109
|
+
} else {
|
|
110
|
+
const headers = Object.keys(data[0]);
|
|
111
|
+
worksheetData = data.map((row) => headers.map((key) => row[key] ?? ''));
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const worksheet = utils.aoa_to_sheet(worksheetData);
|
|
116
|
+
|
|
117
|
+
// If workbook provided, add sheet and return (for multi-sheet exports)
|
|
118
|
+
if (workbook) {
|
|
119
|
+
utils.book_append_sheet(workbook, worksheet, sheetName);
|
|
120
|
+
return workbook;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Otherwise, create workbook and download
|
|
124
|
+
const newWorkbook = utils.book_new();
|
|
125
|
+
utils.book_append_sheet(newWorkbook, worksheet, sheetName);
|
|
126
|
+
writeFile(newWorkbook, filename);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Export DataTable-compatible data to Excel
|
|
131
|
+
*
|
|
132
|
+
* Helper function specifically designed for exporting DataTable data.
|
|
133
|
+
* Automatically handles common DataTable column configurations.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* import { exportDataTableToExcel } from 'notebook-ui';
|
|
138
|
+
*
|
|
139
|
+
* const columns = [
|
|
140
|
+
* { key: 'id', header: 'ID' },
|
|
141
|
+
* { key: 'name', header: 'Name' },
|
|
142
|
+
* { key: 'price', header: 'Price' },
|
|
143
|
+
* ];
|
|
144
|
+
*
|
|
145
|
+
* exportDataTableToExcel({
|
|
146
|
+
* data: products,
|
|
147
|
+
* columns: columns,
|
|
148
|
+
* filename: 'products.xlsx',
|
|
149
|
+
* });
|
|
150
|
+
* ```
|
|
151
|
+
*/
|
|
152
|
+
export interface DataTableExportOptions {
|
|
153
|
+
/** Array of data objects */
|
|
154
|
+
data: any[];
|
|
155
|
+
/** DataTable column definitions */
|
|
156
|
+
columns: Array<{ key: string; header: string }>;
|
|
157
|
+
/** Output filename */
|
|
158
|
+
filename?: string;
|
|
159
|
+
/** Sheet name */
|
|
160
|
+
sheetName?: string;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export function exportDataTableToExcel({
|
|
164
|
+
data,
|
|
165
|
+
columns,
|
|
166
|
+
filename = 'export.xlsx',
|
|
167
|
+
sheetName = 'Sheet1',
|
|
168
|
+
}: DataTableExportOptions): void {
|
|
169
|
+
const excelColumns: ExcelColumn[] = columns.map((col) => ({
|
|
170
|
+
key: col.key,
|
|
171
|
+
label: col.header,
|
|
172
|
+
}));
|
|
173
|
+
|
|
174
|
+
exportToExcel({
|
|
175
|
+
data,
|
|
176
|
+
columns: excelColumns,
|
|
177
|
+
filename,
|
|
178
|
+
sheetName,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Create a multi-sheet Excel workbook
|
|
184
|
+
*
|
|
185
|
+
* Utility for creating Excel files with multiple sheets.
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* import { createMultiSheetExcel } from 'notebook-ui';
|
|
190
|
+
*
|
|
191
|
+
* createMultiSheetExcel({
|
|
192
|
+
* filename: 'report.xlsx',
|
|
193
|
+
* sheets: [
|
|
194
|
+
* { name: 'Products', data: products },
|
|
195
|
+
* { name: 'Orders', data: orders },
|
|
196
|
+
* { name: 'Customers', data: customers, columns: customerColumns },
|
|
197
|
+
* ],
|
|
198
|
+
* });
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
export interface MultiSheetExcelOptions {
|
|
202
|
+
/** Output filename */
|
|
203
|
+
filename: string;
|
|
204
|
+
/** Array of sheet configurations */
|
|
205
|
+
sheets: Array<{
|
|
206
|
+
name: string;
|
|
207
|
+
data: any[];
|
|
208
|
+
columns?: ExcelColumn[];
|
|
209
|
+
}>;
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
export function createMultiSheetExcel({ filename, sheets }: MultiSheetExcelOptions): void {
|
|
213
|
+
const workbook = utils.book_new();
|
|
214
|
+
|
|
215
|
+
sheets.forEach((sheet) => {
|
|
216
|
+
exportToExcel({
|
|
217
|
+
data: sheet.data,
|
|
218
|
+
sheetName: sheet.name,
|
|
219
|
+
columns: sheet.columns,
|
|
220
|
+
workbook,
|
|
221
|
+
});
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
writeFile(workbook, filename);
|
|
225
|
+
}
|
package/src/utils/index.ts
CHANGED
|
@@ -4,3 +4,6 @@ export type { QueryDescription, FriendlyNameConfig } from './sqlToNaturalLanguag
|
|
|
4
4
|
|
|
5
5
|
export { formatStatisticValue, formatStatistics } from './statisticsFormatter';
|
|
6
6
|
export type { StatisticFormat, StatisticConfig, FormattedStatistic } from './statisticsFormatter';
|
|
7
|
+
|
|
8
|
+
export { exportToExcel, exportDataTableToExcel, createMultiSheetExcel } from './excelExport';
|
|
9
|
+
export type { ExcelColumn, ExportToExcelOptions, DataTableExportOptions, MultiSheetExcelOptions } from './excelExport';
|
|
@@ -415,7 +415,7 @@ function parseCondition(condition: string, friendlyNames: FriendlyNameConfig): s
|
|
|
415
415
|
function extractFieldName(condition: string, friendlyNames: FriendlyNameConfig): string {
|
|
416
416
|
condition = condition.trim();
|
|
417
417
|
|
|
418
|
-
|
|
418
|
+
const match = condition.match(/^(?:["']?\w+["']?\.)?["']?(\w+)["']?/);
|
|
419
419
|
|
|
420
420
|
if (match && match[1]) {
|
|
421
421
|
const fieldName = match[1];
|