@topgrid/grid-export 0.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.
@@ -0,0 +1,231 @@
1
+ /** Excel export 범위 지정 */
2
+ type ExportScope = 'all' | 'filtered' | 'selected';
3
+ /** export 시 데이터 행 0건 동작 — 5개 Options 공유 single source-of-truth (G-005 D2) */
4
+ type EmptyBehavior = 'skip' | 'empty';
5
+ /**
6
+ * Excel export 옵션
7
+ *
8
+ * G-005 (emptyBehavior) 와 동일 타입 공유 — types.ts single source-of-truth (D7)
9
+ */
10
+ interface ExcelExportOptions {
11
+ /**
12
+ * 다운로드 파일명 (확장자 포함 권장, 없으면 .xlsx 자동 추가)
13
+ * @default 'export.xlsx'
14
+ */
15
+ fileName?: string;
16
+ /**
17
+ * Excel 시트명
18
+ * @default 'Sheet1'
19
+ */
20
+ sheetName?: string;
21
+ /**
22
+ * export 대상 행 범위
23
+ * - 'all': getCoreRowModel (필터 무시, 전체)
24
+ * - 'filtered': getFilteredRowModel (현재 정렬/필터 반영) ← default
25
+ * - 'selected': table.getSelectedRowModel (선택 행만)
26
+ * @default 'filtered'
27
+ */
28
+ scope?: ExportScope;
29
+ /**
30
+ * 데이터 행 0건 시 동작
31
+ * - 'skip': 파일 생성 안 함 (기본)
32
+ * - 'empty': 헤더만 있는 빈 파일 생성
33
+ * @default 'skip'
34
+ */
35
+ emptyBehavior?: EmptyBehavior;
36
+ }
37
+ /**
38
+ * DataTable buttonInfo 호환 alias 옵션 (legacy)
39
+ *
40
+ * @deprecated downloadExcel() 과 함께 사용. 신규 코드는 ExcelExportOptions + exportToExcel() 사용 권장.
41
+ */
42
+ interface DownloadExcelOptions extends Omit<ExcelExportOptions, 'scope'> {
43
+ scope?: ExportScope;
44
+ }
45
+ /**
46
+ * CSV export 옵션
47
+ *
48
+ * @example
49
+ * exportToCSV(table, { fileName: '데이터.csv', delimiter: ',' });
50
+ * exportToCSV(table, { fileName: '데이터.tsv', delimiter: '\t', scope: 'selected' });
51
+ */
52
+ interface CSVExportOptions {
53
+ /**
54
+ * 다운로드 파일명 (확장자 포함 권장, 없으면 .csv 자동 추가)
55
+ * @default 'export.csv'
56
+ */
57
+ fileName?: string;
58
+ /**
59
+ * export 대상 행 범위
60
+ * - 'all': getCoreRowModel (필터 무시, 전체)
61
+ * - 'filtered': getFilteredRowModel (현재 정렬/필터 반영) ← default
62
+ * - 'selected': table.getSelectedRowModel (선택 행만)
63
+ * @default 'filtered'
64
+ */
65
+ scope?: ExportScope;
66
+ /**
67
+ * CSV 구분자 — ',' (기본, RFC 4180) 또는 '\t' (TSV 옵션)
68
+ * @default ','
69
+ */
70
+ delimiter?: ',' | '\t';
71
+ /**
72
+ * 데이터 행 0건 시 동작
73
+ * - 'skip': 파일 생성 안 함 (기본)
74
+ * - 'empty': 헤더만 있는 빈 파일 생성
75
+ * @default 'skip'
76
+ */
77
+ emptyBehavior?: EmptyBehavior;
78
+ }
79
+ /**
80
+ * PDF export 옵션
81
+ *
82
+ * @remarks
83
+ * `fontFamily: 'korean'` 옵션은 stub 상태입니다 (spec Section 11 W1).
84
+ * 실 사용 전 loadKoreanFont.ts V1 구현 완료 필요.
85
+ *
86
+ * @example
87
+ * exportToPdf(table, { fileName: '보고서.pdf', orientation: 'l' });
88
+ * exportToPdf(table, { scope: 'selected', fontFamily: 'korean', title: '선택 데이터' });
89
+ */
90
+ interface PDFExportOptions {
91
+ /**
92
+ * 다운로드 파일명 (확장자 포함 권장, 없으면 .pdf 자동 추가)
93
+ * @default 'export.pdf'
94
+ */
95
+ fileName?: string;
96
+ /**
97
+ * PDF 최상단에 표시할 문서 제목 행 (없으면 생략)
98
+ * @default undefined
99
+ */
100
+ title?: string;
101
+ /**
102
+ * export 대상 행 범위
103
+ * - 'all': getCoreRowModel (필터 무시, 전체)
104
+ * - 'filtered': getFilteredRowModel (현재 정렬/필터 반영) ← default
105
+ * - 'selected': table.getSelectedRowModel (선택 행만)
106
+ * @default 'filtered'
107
+ */
108
+ scope?: ExportScope;
109
+ /**
110
+ * 데이터 행 0건 시 동작
111
+ * - 'skip': 파일 생성 안 함 (기본)
112
+ * - 'empty': 헤더만 있는 빈 파일 생성
113
+ * @default 'skip'
114
+ */
115
+ emptyBehavior?: EmptyBehavior;
116
+ /**
117
+ * PDF 페이지 방향
118
+ * - 'p': portrait (세로, 기본)
119
+ * - 'l': landscape (가로)
120
+ * @default 'p'
121
+ */
122
+ orientation?: 'p' | 'l';
123
+ /**
124
+ * 폰트 패밀리
125
+ * - 'default': jspdf 내장 Helvetica (라틴 문자 지원)
126
+ * - 'korean': NotoSansKR dynamic import (loadKoreanFont.ts — W1 참조)
127
+ * @default 'default'
128
+ */
129
+ fontFamily?: 'default' | 'korean';
130
+ }
131
+ /**
132
+ * 클립보드 복사 옵션
133
+ *
134
+ * @example
135
+ * copyToClipboard(table, { scope: 'selected' });
136
+ * copyToClipboard(table, { scope: 'all', emptyBehavior: 'empty' });
137
+ */
138
+ interface ClipboardOptions {
139
+ /**
140
+ * export 대상 행 범위
141
+ * - 'all': getCoreRowModel (필터 무시, 전체)
142
+ * - 'filtered': getFilteredRowModel (현재 정렬/필터 반영) ← default
143
+ * - 'selected': table.getSelectedRowModel (선택 행만)
144
+ * @default 'filtered'
145
+ */
146
+ scope?: ExportScope;
147
+ /**
148
+ * 데이터 행 0건 시 동작
149
+ * - 'skip': 복사 안 함 (기본)
150
+ * - 'empty': 헤더만 있는 TSV 클립보드 복사
151
+ * @default 'skip'
152
+ */
153
+ emptyBehavior?: EmptyBehavior;
154
+ }
155
+ /**
156
+ * 행 배열 기반 Excel export 의 컬럼 정의
157
+ *
158
+ * @see exportRowsToExcel
159
+ */
160
+ interface ExcelColumn {
161
+ /** 행 객체의 키 */
162
+ key: string;
163
+ /** 헤더 셀에 표시할 텍스트 */
164
+ header: string;
165
+ /** 컬럼 너비 (wch 단위). 기본값 15 */
166
+ width?: number;
167
+ /** 셀 값 포맷 */
168
+ format?: 'date' | 'datetime' | 'number' | 'currency';
169
+ }
170
+ /**
171
+ * `exportRowsToExcel` 옵션
172
+ *
173
+ * `scope` 는 행 배열 입력에서 무의미하므로 의도적으로 제외.
174
+ */
175
+ interface ExportRowsOptions {
176
+ /**
177
+ * 다운로드 파일명 (확장자 포함 권장, 없으면 .xlsx 자동 추가)
178
+ * @default 'export.xlsx'
179
+ */
180
+ fileName?: string;
181
+ /**
182
+ * Excel 시트명
183
+ * @default 'Sheet1'
184
+ */
185
+ sheetName?: string;
186
+ /**
187
+ * 데이터 행 0건 시 동작
188
+ * - 'skip': 파일 생성 안 함 (기본)
189
+ * - 'empty': 헤더만 있는 빈 파일 생성
190
+ * @default 'skip'
191
+ */
192
+ emptyBehavior?: EmptyBehavior;
193
+ }
194
+ /**
195
+ * 인쇄 옵션
196
+ *
197
+ * @example
198
+ * printGrid(table, { title: '월간 보고서', orientation: 'l' });
199
+ * printGrid(table, { scope: 'selected', title: '선택 데이터' });
200
+ */
201
+ interface PrintOptions {
202
+ /**
203
+ * 인쇄 페이지 최상단에 표시할 제목 (없으면 생략)
204
+ * @default undefined
205
+ */
206
+ title?: string;
207
+ /**
208
+ * export 대상 행 범위
209
+ * - 'all': getCoreRowModel (필터 무시, 전체)
210
+ * - 'filtered': getFilteredRowModel (현재 정렬/필터 반영) ← default
211
+ * - 'selected': table.getSelectedRowModel (선택 행만)
212
+ * @default 'filtered'
213
+ */
214
+ scope?: ExportScope;
215
+ /**
216
+ * 페이지 방향 (CSS @page 규칙으로 팝업 HTML에 삽입)
217
+ * - 'p': portrait (세로, 기본)
218
+ * - 'l': landscape (가로)
219
+ * @default 'p'
220
+ */
221
+ orientation?: 'p' | 'l';
222
+ /**
223
+ * 데이터 행 0건 시 동작
224
+ * - 'skip': 인쇄 창 열지 않음 (기본)
225
+ * - 'empty': 헤더만 있는 표 인쇄
226
+ * @default 'skip'
227
+ */
228
+ emptyBehavior?: EmptyBehavior;
229
+ }
230
+
231
+ export type { CSVExportOptions as C, DownloadExcelOptions as D, ExcelExportOptions as E, PDFExportOptions as P, ClipboardOptions as a, PrintOptions as b, ExcelColumn as c, ExportRowsOptions as d, EmptyBehavior as e, ExportScope as f };
@@ -0,0 +1,231 @@
1
+ /** Excel export 범위 지정 */
2
+ type ExportScope = 'all' | 'filtered' | 'selected';
3
+ /** export 시 데이터 행 0건 동작 — 5개 Options 공유 single source-of-truth (G-005 D2) */
4
+ type EmptyBehavior = 'skip' | 'empty';
5
+ /**
6
+ * Excel export 옵션
7
+ *
8
+ * G-005 (emptyBehavior) 와 동일 타입 공유 — types.ts single source-of-truth (D7)
9
+ */
10
+ interface ExcelExportOptions {
11
+ /**
12
+ * 다운로드 파일명 (확장자 포함 권장, 없으면 .xlsx 자동 추가)
13
+ * @default 'export.xlsx'
14
+ */
15
+ fileName?: string;
16
+ /**
17
+ * Excel 시트명
18
+ * @default 'Sheet1'
19
+ */
20
+ sheetName?: string;
21
+ /**
22
+ * export 대상 행 범위
23
+ * - 'all': getCoreRowModel (필터 무시, 전체)
24
+ * - 'filtered': getFilteredRowModel (현재 정렬/필터 반영) ← default
25
+ * - 'selected': table.getSelectedRowModel (선택 행만)
26
+ * @default 'filtered'
27
+ */
28
+ scope?: ExportScope;
29
+ /**
30
+ * 데이터 행 0건 시 동작
31
+ * - 'skip': 파일 생성 안 함 (기본)
32
+ * - 'empty': 헤더만 있는 빈 파일 생성
33
+ * @default 'skip'
34
+ */
35
+ emptyBehavior?: EmptyBehavior;
36
+ }
37
+ /**
38
+ * DataTable buttonInfo 호환 alias 옵션 (legacy)
39
+ *
40
+ * @deprecated downloadExcel() 과 함께 사용. 신규 코드는 ExcelExportOptions + exportToExcel() 사용 권장.
41
+ */
42
+ interface DownloadExcelOptions extends Omit<ExcelExportOptions, 'scope'> {
43
+ scope?: ExportScope;
44
+ }
45
+ /**
46
+ * CSV export 옵션
47
+ *
48
+ * @example
49
+ * exportToCSV(table, { fileName: '데이터.csv', delimiter: ',' });
50
+ * exportToCSV(table, { fileName: '데이터.tsv', delimiter: '\t', scope: 'selected' });
51
+ */
52
+ interface CSVExportOptions {
53
+ /**
54
+ * 다운로드 파일명 (확장자 포함 권장, 없으면 .csv 자동 추가)
55
+ * @default 'export.csv'
56
+ */
57
+ fileName?: string;
58
+ /**
59
+ * export 대상 행 범위
60
+ * - 'all': getCoreRowModel (필터 무시, 전체)
61
+ * - 'filtered': getFilteredRowModel (현재 정렬/필터 반영) ← default
62
+ * - 'selected': table.getSelectedRowModel (선택 행만)
63
+ * @default 'filtered'
64
+ */
65
+ scope?: ExportScope;
66
+ /**
67
+ * CSV 구분자 — ',' (기본, RFC 4180) 또는 '\t' (TSV 옵션)
68
+ * @default ','
69
+ */
70
+ delimiter?: ',' | '\t';
71
+ /**
72
+ * 데이터 행 0건 시 동작
73
+ * - 'skip': 파일 생성 안 함 (기본)
74
+ * - 'empty': 헤더만 있는 빈 파일 생성
75
+ * @default 'skip'
76
+ */
77
+ emptyBehavior?: EmptyBehavior;
78
+ }
79
+ /**
80
+ * PDF export 옵션
81
+ *
82
+ * @remarks
83
+ * `fontFamily: 'korean'` 옵션은 stub 상태입니다 (spec Section 11 W1).
84
+ * 실 사용 전 loadKoreanFont.ts V1 구현 완료 필요.
85
+ *
86
+ * @example
87
+ * exportToPdf(table, { fileName: '보고서.pdf', orientation: 'l' });
88
+ * exportToPdf(table, { scope: 'selected', fontFamily: 'korean', title: '선택 데이터' });
89
+ */
90
+ interface PDFExportOptions {
91
+ /**
92
+ * 다운로드 파일명 (확장자 포함 권장, 없으면 .pdf 자동 추가)
93
+ * @default 'export.pdf'
94
+ */
95
+ fileName?: string;
96
+ /**
97
+ * PDF 최상단에 표시할 문서 제목 행 (없으면 생략)
98
+ * @default undefined
99
+ */
100
+ title?: string;
101
+ /**
102
+ * export 대상 행 범위
103
+ * - 'all': getCoreRowModel (필터 무시, 전체)
104
+ * - 'filtered': getFilteredRowModel (현재 정렬/필터 반영) ← default
105
+ * - 'selected': table.getSelectedRowModel (선택 행만)
106
+ * @default 'filtered'
107
+ */
108
+ scope?: ExportScope;
109
+ /**
110
+ * 데이터 행 0건 시 동작
111
+ * - 'skip': 파일 생성 안 함 (기본)
112
+ * - 'empty': 헤더만 있는 빈 파일 생성
113
+ * @default 'skip'
114
+ */
115
+ emptyBehavior?: EmptyBehavior;
116
+ /**
117
+ * PDF 페이지 방향
118
+ * - 'p': portrait (세로, 기본)
119
+ * - 'l': landscape (가로)
120
+ * @default 'p'
121
+ */
122
+ orientation?: 'p' | 'l';
123
+ /**
124
+ * 폰트 패밀리
125
+ * - 'default': jspdf 내장 Helvetica (라틴 문자 지원)
126
+ * - 'korean': NotoSansKR dynamic import (loadKoreanFont.ts — W1 참조)
127
+ * @default 'default'
128
+ */
129
+ fontFamily?: 'default' | 'korean';
130
+ }
131
+ /**
132
+ * 클립보드 복사 옵션
133
+ *
134
+ * @example
135
+ * copyToClipboard(table, { scope: 'selected' });
136
+ * copyToClipboard(table, { scope: 'all', emptyBehavior: 'empty' });
137
+ */
138
+ interface ClipboardOptions {
139
+ /**
140
+ * export 대상 행 범위
141
+ * - 'all': getCoreRowModel (필터 무시, 전체)
142
+ * - 'filtered': getFilteredRowModel (현재 정렬/필터 반영) ← default
143
+ * - 'selected': table.getSelectedRowModel (선택 행만)
144
+ * @default 'filtered'
145
+ */
146
+ scope?: ExportScope;
147
+ /**
148
+ * 데이터 행 0건 시 동작
149
+ * - 'skip': 복사 안 함 (기본)
150
+ * - 'empty': 헤더만 있는 TSV 클립보드 복사
151
+ * @default 'skip'
152
+ */
153
+ emptyBehavior?: EmptyBehavior;
154
+ }
155
+ /**
156
+ * 행 배열 기반 Excel export 의 컬럼 정의
157
+ *
158
+ * @see exportRowsToExcel
159
+ */
160
+ interface ExcelColumn {
161
+ /** 행 객체의 키 */
162
+ key: string;
163
+ /** 헤더 셀에 표시할 텍스트 */
164
+ header: string;
165
+ /** 컬럼 너비 (wch 단위). 기본값 15 */
166
+ width?: number;
167
+ /** 셀 값 포맷 */
168
+ format?: 'date' | 'datetime' | 'number' | 'currency';
169
+ }
170
+ /**
171
+ * `exportRowsToExcel` 옵션
172
+ *
173
+ * `scope` 는 행 배열 입력에서 무의미하므로 의도적으로 제외.
174
+ */
175
+ interface ExportRowsOptions {
176
+ /**
177
+ * 다운로드 파일명 (확장자 포함 권장, 없으면 .xlsx 자동 추가)
178
+ * @default 'export.xlsx'
179
+ */
180
+ fileName?: string;
181
+ /**
182
+ * Excel 시트명
183
+ * @default 'Sheet1'
184
+ */
185
+ sheetName?: string;
186
+ /**
187
+ * 데이터 행 0건 시 동작
188
+ * - 'skip': 파일 생성 안 함 (기본)
189
+ * - 'empty': 헤더만 있는 빈 파일 생성
190
+ * @default 'skip'
191
+ */
192
+ emptyBehavior?: EmptyBehavior;
193
+ }
194
+ /**
195
+ * 인쇄 옵션
196
+ *
197
+ * @example
198
+ * printGrid(table, { title: '월간 보고서', orientation: 'l' });
199
+ * printGrid(table, { scope: 'selected', title: '선택 데이터' });
200
+ */
201
+ interface PrintOptions {
202
+ /**
203
+ * 인쇄 페이지 최상단에 표시할 제목 (없으면 생략)
204
+ * @default undefined
205
+ */
206
+ title?: string;
207
+ /**
208
+ * export 대상 행 범위
209
+ * - 'all': getCoreRowModel (필터 무시, 전체)
210
+ * - 'filtered': getFilteredRowModel (현재 정렬/필터 반영) ← default
211
+ * - 'selected': table.getSelectedRowModel (선택 행만)
212
+ * @default 'filtered'
213
+ */
214
+ scope?: ExportScope;
215
+ /**
216
+ * 페이지 방향 (CSS @page 규칙으로 팝업 HTML에 삽입)
217
+ * - 'p': portrait (세로, 기본)
218
+ * - 'l': landscape (가로)
219
+ * @default 'p'
220
+ */
221
+ orientation?: 'p' | 'l';
222
+ /**
223
+ * 데이터 행 0건 시 동작
224
+ * - 'skip': 인쇄 창 열지 않음 (기본)
225
+ * - 'empty': 헤더만 있는 표 인쇄
226
+ * @default 'skip'
227
+ */
228
+ emptyBehavior?: EmptyBehavior;
229
+ }
230
+
231
+ export type { CSVExportOptions as C, DownloadExcelOptions as D, ExcelExportOptions as E, PDFExportOptions as P, ClipboardOptions as a, PrintOptions as b, ExcelColumn as c, ExportRowsOptions as d, EmptyBehavior as e, ExportScope as f };
package/package.json ADDED
@@ -0,0 +1,70 @@
1
+ {
2
+ "name": "@topgrid/grid-export",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "license": "MIT",
6
+ "description": "Excel, PDF, CSV export for grid data",
7
+ "main": "./dist/index.cjs",
8
+ "module": "./dist/index.mjs",
9
+ "types": "./dist/index.d.ts",
10
+ "exports": {
11
+ ".": {
12
+ "types": "./dist/index.d.ts",
13
+ "import": "./dist/index.mjs",
14
+ "require": "./dist/index.cjs"
15
+ },
16
+ "./legacy": {
17
+ "types": "./dist/legacy/downloadExcel.d.ts",
18
+ "import": "./dist/legacy/downloadExcel.mjs",
19
+ "require": "./dist/legacy/downloadExcel.cjs"
20
+ }
21
+ },
22
+ "files": [
23
+ "dist",
24
+ "README.md"
25
+ ],
26
+ "peerDependencies": {
27
+ "@tanstack/react-table": "^8.0.0",
28
+ "jspdf": "^2.5.0",
29
+ "jspdf-autotable": "^3.5.0",
30
+ "react": "^18.0.0 || ^19.0.0",
31
+ "react-dom": "^18.0.0 || ^19.0.0",
32
+ "xlsx": "^0.18.5"
33
+ },
34
+ "peerDependenciesMeta": {
35
+ "jspdf": {
36
+ "optional": true
37
+ },
38
+ "jspdf-autotable": {
39
+ "optional": true
40
+ },
41
+ "xlsx": {
42
+ "optional": false
43
+ }
44
+ },
45
+ "devDependencies": {
46
+ "@tanstack/react-table": "^8.21.3",
47
+ "@types/react": "^19.0.0",
48
+ "react": "^19.1.0",
49
+ "tsup": "^8.0.0",
50
+ "typescript": "~5.8.3",
51
+ "xlsx": "^0.18.5"
52
+ },
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "git+https://github.com/alladins/topgrid.git",
56
+ "directory": "packages/grid-export"
57
+ },
58
+ "bugs": {
59
+ "url": "https://github.com/alladins/topgrid/issues"
60
+ },
61
+ "homepage": "https://github.com/alladins/topgrid#readme",
62
+ "publishConfig": {
63
+ "access": "public"
64
+ },
65
+ "scripts": {
66
+ "build": "tsup",
67
+ "typecheck": "tsc --noEmit",
68
+ "test": "echo TODO"
69
+ }
70
+ }