@memberjunction/ng-export-service 4.0.0 → 4.1.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.
Files changed (2) hide show
  1. package/README.md +229 -0
  2. package/package.json +2 -2
package/README.md ADDED
@@ -0,0 +1,229 @@
1
+ # @memberjunction/ng-export-service
2
+
3
+ Angular service and dialog component for exporting data to Excel, CSV, and JSON formats, with configurable sampling, column selection, and browser-side file download.
4
+
5
+ ## Overview
6
+
7
+ The `@memberjunction/ng-export-service` package wraps the [`@memberjunction/export-engine`](../../../ExportEngine/README.md) for Angular usage. It provides an injectable `ExportService` with format-specific convenience methods and an `ExportDialogComponent` that presents a progressive UI for format selection, row sampling, and one-click download.
8
+
9
+ ```mermaid
10
+ flowchart LR
11
+ subgraph Dialog["ExportDialogComponent"]
12
+ FMT[Format Selection] --> SAMP[Sampling Options]
13
+ SAMP --> PREV[Row Estimate Preview]
14
+ PREV --> DL[Export & Download]
15
+ end
16
+
17
+ subgraph Service["ExportService"]
18
+ EXP[export / toExcel / toCSV / toJSON]
19
+ DOWN[downloadResult]
20
+ BOTH[exportAndDownload]
21
+ end
22
+
23
+ subgraph Engine["@memberjunction/export-engine"]
24
+ EE[ExportEngine]
25
+ end
26
+
27
+ Dialog --> Service
28
+ Service --> Engine
29
+
30
+ style Dialog fill:#2d6a9f,stroke:#1a4971,color:#fff
31
+ style Service fill:#7c5295,stroke:#563a6b,color:#fff
32
+ style Engine fill:#2d8659,stroke:#1a5c3a,color:#fff
33
+ ```
34
+
35
+ ## Installation
36
+
37
+ ```bash
38
+ npm install @memberjunction/ng-export-service
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ### Import the Module
44
+
45
+ ```typescript
46
+ import { ExportServiceModule } from '@memberjunction/ng-export-service';
47
+
48
+ @NgModule({
49
+ imports: [ExportServiceModule]
50
+ })
51
+ export class YourModule { }
52
+ ```
53
+
54
+ ### Using the Export Dialog
55
+
56
+ ```html
57
+ @if (showExportDialog) {
58
+ <mj-export-dialog
59
+ [visible]="showExportDialog"
60
+ [config]="exportConfig"
61
+ (closed)="onExportDialogClosed($event)">
62
+ </mj-export-dialog>
63
+ }
64
+ ```
65
+
66
+ ```typescript
67
+ import { ExportDialogConfig, ExportDialogResult } from '@memberjunction/ng-export-service';
68
+
69
+ @Component({ ... })
70
+ export class MyComponent {
71
+ showExportDialog = false;
72
+ exportConfig: ExportDialogConfig | null = null;
73
+
74
+ openExport(data: Record<string, unknown>[]) {
75
+ this.exportConfig = {
76
+ data,
77
+ defaultFileName: 'contacts-export',
78
+ defaultFormat: 'excel',
79
+ showSamplingOptions: true,
80
+ dialogTitle: 'Export Contacts'
81
+ };
82
+ this.showExportDialog = true;
83
+ }
84
+
85
+ onExportDialogClosed(result: ExportDialogResult) {
86
+ this.showExportDialog = false;
87
+ if (result.exported) {
88
+ console.log('Exported successfully:', result.result?.fileName);
89
+ }
90
+ }
91
+ }
92
+ ```
93
+
94
+ ### Using the Service Directly
95
+
96
+ ```typescript
97
+ import { ExportService } from '@memberjunction/ng-export-service';
98
+ import { ExportData } from '@memberjunction/export-engine';
99
+
100
+ @Component({ ... })
101
+ export class MyComponent {
102
+ private exportService = inject(ExportService);
103
+
104
+ async exportToExcel(data: ExportData) {
105
+ // Export and immediately trigger browser download
106
+ const result = await this.exportService.exportAndDownload(data, {
107
+ format: 'excel',
108
+ fileName: 'my-data',
109
+ includeHeaders: true
110
+ });
111
+
112
+ if (!result.success) {
113
+ console.error('Export failed:', result.error);
114
+ }
115
+ }
116
+
117
+ async exportToCSV(data: ExportData) {
118
+ // Export with sampling -- only first 500 rows
119
+ const result = await this.exportService.toCSV(data, {
120
+ fileName: 'sample-data',
121
+ sampling: { mode: 'top', count: 500 }
122
+ });
123
+
124
+ if (result.success) {
125
+ this.exportService.downloadResult(result);
126
+ }
127
+ }
128
+ }
129
+ ```
130
+
131
+ ## API Reference
132
+
133
+ ### ExportService
134
+
135
+ Root-provided Angular service wrapping `ExportEngine`.
136
+
137
+ | Method | Returns | Description |
138
+ |--------|---------|-------------|
139
+ | `export(data, options?)` | `Promise<ExportResult>` | Export data with full options |
140
+ | `toExcel(data, options?)` | `Promise<ExportResult>` | Export to Excel format |
141
+ | `toCSV(data, options?)` | `Promise<ExportResult>` | Export to CSV format |
142
+ | `toJSON(data, options?)` | `Promise<ExportResult>` | Export to JSON format |
143
+ | `getSupportedFormats()` | `ExportFormat[]` | List supported formats |
144
+ | `downloadResult(result)` | `void` | Trigger browser file download |
145
+ | `exportAndDownload(data, options?)` | `Promise<ExportResult>` | Export then download in one call |
146
+ | `getSamplingModes()` | `SamplingModeInfo[]` | Get sampling modes with labels |
147
+ | `getFormatInfo(format)` | `FormatInfo` | Get format label, icon, description |
148
+ | `buildSamplingOptions(mode, count?, interval?)` | `SamplingOptions` | Build sampling config from user selections |
149
+
150
+ ### ExportDialogComponent (`mj-export-dialog`)
151
+
152
+ Standalone export dialog with progressive UX.
153
+
154
+ #### Inputs
155
+
156
+ | Input | Type | Default | Description |
157
+ |-------|------|---------|-------------|
158
+ | `visible` | `boolean` | `false` | Controls dialog visibility |
159
+ | `config` | `ExportDialogConfig \| null` | `null` | Dialog configuration |
160
+
161
+ #### Outputs
162
+
163
+ | Output | Type | Description |
164
+ |--------|------|-------------|
165
+ | `closed` | `EventEmitter<ExportDialogResult>` | Emitted when dialog closes |
166
+
167
+ ### ExportDialogConfig
168
+
169
+ ```typescript
170
+ interface ExportDialogConfig {
171
+ data: ExportData;
172
+ columns?: ExportColumn[];
173
+ defaultFileName?: string;
174
+ availableFormats?: ExportFormat[];
175
+ defaultFormat?: ExportFormat;
176
+ showSamplingOptions?: boolean;
177
+ defaultSamplingMode?: SamplingMode;
178
+ defaultSampleCount?: number;
179
+ dialogTitle?: string;
180
+ }
181
+ ```
182
+
183
+ ### ExportDialogResult
184
+
185
+ ```typescript
186
+ interface ExportDialogResult {
187
+ exported: boolean;
188
+ result?: ExportResult;
189
+ options?: ExportOptions;
190
+ }
191
+ ```
192
+
193
+ ### Sampling Modes
194
+
195
+ | Mode | Description |
196
+ |------|-------------|
197
+ | `all` | Export all data rows |
198
+ | `top` | Export the first N rows |
199
+ | `bottom` | Export the last N rows |
200
+ | `every-nth` | Export every Nth row |
201
+ | `random` | Export N random rows |
202
+
203
+ ## Dependencies
204
+
205
+ ### Runtime Dependencies
206
+
207
+ | Package | Description |
208
+ |---------|-------------|
209
+ | `@memberjunction/export-engine` | Core export engine with format support |
210
+
211
+ ### Peer Dependencies
212
+
213
+ - `@angular/common` ^21.x
214
+ - `@angular/core` ^21.x
215
+ - `@angular/forms` ^21.x
216
+ - `@angular/cdk` ^21.x
217
+
218
+ **Note:** For export types (`ExportFormat`, `ExportOptions`, `ExportResult`, etc.), import directly from `@memberjunction/export-engine`.
219
+
220
+ ## Build
221
+
222
+ ```bash
223
+ cd packages/Angular/Generic/export-service
224
+ npm run build
225
+ ```
226
+
227
+ ## License
228
+
229
+ ISC
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/ng-export-service",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "MemberJunction: Angular export service and dialog for exporting data to Excel, CSV, and JSON",
5
5
  "main": "./dist/public-api.js",
6
6
  "typings": "./dist/public-api.d.ts",
@@ -32,7 +32,7 @@
32
32
  "@angular/cdk": "21.1.3"
33
33
  },
34
34
  "dependencies": {
35
- "@memberjunction/export-engine": "4.0.0",
35
+ "@memberjunction/export-engine": "4.1.0",
36
36
  "tslib": "^2.8.1"
37
37
  },
38
38
  "sideEffects": false,