@qhr123/sa2kit 0.1.1 â 0.3.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/README.md +159 -7
- package/dist/analytics/index.d.mts +702 -0
- package/dist/analytics/index.d.ts +702 -0
- package/dist/analytics/index.js +1185 -0
- package/dist/analytics/index.js.map +1 -0
- package/dist/analytics/index.mjs +1140 -0
- package/dist/analytics/index.mjs.map +1 -0
- package/dist/i18n/index.d.mts +306 -0
- package/dist/i18n/index.d.ts +306 -0
- package/dist/i18n/index.js +369 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/i18n/index.mjs +360 -0
- package/dist/i18n/index.mjs.map +1 -0
- package/dist/universalExport/index.d.mts +517 -0
- package/dist/universalExport/index.d.ts +517 -0
- package/dist/universalExport/index.js +619 -0
- package/dist/universalExport/index.js.map +1 -0
- package/dist/universalExport/index.mjs +578 -0
- package/dist/universalExport/index.mjs.map +1 -0
- package/dist/universalFile/index.d.mts +519 -0
- package/dist/universalFile/index.d.ts +519 -0
- package/dist/universalFile/index.js +827 -0
- package/dist/universalFile/index.js.map +1 -0
- package/dist/universalFile/index.mjs +767 -0
- package/dist/universalFile/index.mjs.map +1 -0
- package/package.json +25 -1
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
#
|
|
1
|
+
# SA2Kit
|
|
2
2
|
|
|
3
3
|
A modern, type-safe React utility library with cross-platform support for building scalable applications.
|
|
4
4
|
|
|
@@ -12,15 +12,19 @@ A modern, type-safe React utility library with cross-platform support for buildi
|
|
|
12
12
|
- ðŊ **React Hooks** - Custom hooks for common patterns
|
|
13
13
|
- ð **Logger System** - Unified logging with multiple adapters
|
|
14
14
|
- ðū **Storage Adapters** - Universal storage abstraction
|
|
15
|
+
- ð **File Upload** - Complete file management with progress tracking
|
|
16
|
+
- ð **Data Export** - Flexible export to CSV, Excel, JSON formats
|
|
17
|
+
- ð **i18n** - Complete internationalization solution
|
|
18
|
+
- ð **Analytics** - Comprehensive event tracking and analytics
|
|
15
19
|
|
|
16
20
|
## Installation
|
|
17
21
|
|
|
18
22
|
```bash
|
|
19
|
-
npm install @
|
|
23
|
+
npm install @qhr123/sa2kit
|
|
20
24
|
# or
|
|
21
|
-
yarn add @
|
|
25
|
+
yarn add @qhr123/sa2kit
|
|
22
26
|
# or
|
|
23
|
-
pnpm add @
|
|
27
|
+
pnpm add @qhr123/sa2kit
|
|
24
28
|
```
|
|
25
29
|
|
|
26
30
|
## Quick Start
|
|
@@ -28,7 +32,7 @@ pnpm add @react-utils-kit/core
|
|
|
28
32
|
### Logger
|
|
29
33
|
|
|
30
34
|
```typescript
|
|
31
|
-
import { logger, createLogger, LogLevel } from '@
|
|
35
|
+
import { logger, createLogger, LogLevel } from '@qhr123/sa2kit/logger';
|
|
32
36
|
|
|
33
37
|
// Use default logger
|
|
34
38
|
logger.info('Application started');
|
|
@@ -47,7 +51,7 @@ apiLogger.info('API request completed');
|
|
|
47
51
|
### Utility Functions
|
|
48
52
|
|
|
49
53
|
```typescript
|
|
50
|
-
import { stringUtils, arrayUtils, fileUtils } from '@
|
|
54
|
+
import { stringUtils, arrayUtils, fileUtils } from '@qhr123/sa2kit/utils';
|
|
51
55
|
|
|
52
56
|
// String utilities
|
|
53
57
|
const capitalized = stringUtils.capitalize('hello world');
|
|
@@ -65,7 +69,7 @@ const isValid = fileUtils.isValidFilename('document.pdf');
|
|
|
65
69
|
### React Hooks
|
|
66
70
|
|
|
67
71
|
```typescript
|
|
68
|
-
import { useLocalStorage, useAsyncStorage } from '@
|
|
72
|
+
import { useLocalStorage, useAsyncStorage } from '@qhr123/sa2kit/hooks';
|
|
69
73
|
|
|
70
74
|
function MyComponent() {
|
|
71
75
|
// Persistent state with localStorage
|
|
@@ -78,12 +82,160 @@ function MyComponent() {
|
|
|
78
82
|
}
|
|
79
83
|
```
|
|
80
84
|
|
|
85
|
+
### File Upload
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
import { universalFileClient } from '@qhr123/sa2kit/universalFile';
|
|
89
|
+
|
|
90
|
+
// Upload a file with progress tracking
|
|
91
|
+
const uploadFile = async (file: File) => {
|
|
92
|
+
const fileMetadata = await universalFileClient.uploadFile(
|
|
93
|
+
{
|
|
94
|
+
file,
|
|
95
|
+
moduleId: 'user-avatars',
|
|
96
|
+
businessId: 'user-123',
|
|
97
|
+
permission: 'public',
|
|
98
|
+
},
|
|
99
|
+
(progress) => {
|
|
100
|
+
console.log(`Upload progress: ${progress.progress}%`);
|
|
101
|
+
console.log(`Speed: ${progress.speed} bytes/sec`);
|
|
102
|
+
}
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
console.log('File uploaded:', fileMetadata.id);
|
|
106
|
+
return fileMetadata;
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// Query files
|
|
110
|
+
const files = await universalFileClient.queryFiles({
|
|
111
|
+
moduleId: 'user-avatars',
|
|
112
|
+
pageSize: 20,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Get file URL
|
|
116
|
+
const fileUrl = await universalFileClient.getFileUrl(fileId);
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
### Data Export
|
|
120
|
+
|
|
121
|
+
```typescript
|
|
122
|
+
import { universalExportClient } from '@qhr123/sa2kit/universalExport';
|
|
123
|
+
|
|
124
|
+
// Export data to CSV
|
|
125
|
+
const exportData = async () => {
|
|
126
|
+
const result = await universalExportClient.exportData({
|
|
127
|
+
configId: 'my-export-config',
|
|
128
|
+
dataSource: async () => [
|
|
129
|
+
{ id: 1, name: 'John', email: 'john@example.com' },
|
|
130
|
+
{ id: 2, name: 'Jane', email: 'jane@example.com' },
|
|
131
|
+
],
|
|
132
|
+
format: 'csv',
|
|
133
|
+
callbacks: {
|
|
134
|
+
onProgress: (progress) => {
|
|
135
|
+
console.log(`Export progress: ${progress.progress}%`);
|
|
136
|
+
},
|
|
137
|
+
onSuccess: (result) => {
|
|
138
|
+
console.log('Export completed:', result.fileName);
|
|
139
|
+
// Download the file
|
|
140
|
+
const url = URL.createObjectURL(result.fileBlob!);
|
|
141
|
+
const a = document.createElement('a');
|
|
142
|
+
a.href = url;
|
|
143
|
+
a.download = result.fileName;
|
|
144
|
+
a.click();
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Internationalization (i18n)
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
import { createI18n, useTranslation } from '@qhr123/sa2kit/i18n';
|
|
155
|
+
import { zhCN, enUS } from '@qhr123/sa2kit/i18n';
|
|
156
|
+
|
|
157
|
+
// Create i18n instance
|
|
158
|
+
const i18n = createI18n({
|
|
159
|
+
locale: 'zh-CN',
|
|
160
|
+
fallbackLocale: 'en-US',
|
|
161
|
+
resources: {
|
|
162
|
+
'zh-CN': zhCN,
|
|
163
|
+
'en-US': enUS,
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
// In React component
|
|
168
|
+
function MyComponent() {
|
|
169
|
+
const { t, locale, setLocale } = useTranslation();
|
|
170
|
+
|
|
171
|
+
return (
|
|
172
|
+
<div>
|
|
173
|
+
<p>{t('common.welcome')}</p>
|
|
174
|
+
<button onClick={() => setLocale('en-US')}>
|
|
175
|
+
Switch to English
|
|
176
|
+
</button>
|
|
177
|
+
</div>
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
### Analytics
|
|
183
|
+
|
|
184
|
+
```typescript
|
|
185
|
+
import { Analytics, createAnalytics } from '@qhr123/sa2kit/analytics';
|
|
186
|
+
|
|
187
|
+
// Create analytics instance (éčĶæäūéé
åĻ)
|
|
188
|
+
const analytics = createAnalytics('my-app', {
|
|
189
|
+
appId: 'my-app',
|
|
190
|
+
appVersion: '1.0.0',
|
|
191
|
+
endpoint: '/api/analytics/events',
|
|
192
|
+
platform: 'web',
|
|
193
|
+
adapter: yourPlatformAdapter, // éčĶčŠčĄåŪį°
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Track events
|
|
197
|
+
analytics.trackEvent('button_click', {
|
|
198
|
+
button_id: 'submit',
|
|
199
|
+
page: 'home',
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
// Use decorators (TypeScript)
|
|
203
|
+
class MyService {
|
|
204
|
+
@Track('user_login')
|
|
205
|
+
async login(username: string) {
|
|
206
|
+
// Login logic
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
@CatchError()
|
|
210
|
+
async fetchData() {
|
|
211
|
+
// Fetch logic
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Use React Hooks
|
|
216
|
+
function MyComponent() {
|
|
217
|
+
const trackEvent = useAnalyticsEvent(analytics);
|
|
218
|
+
|
|
219
|
+
usePageView(analytics); // Auto track page views
|
|
220
|
+
|
|
221
|
+
const handleClick = () => {
|
|
222
|
+
trackEvent('button_click', { action: 'submit' });
|
|
223
|
+
};
|
|
224
|
+
|
|
225
|
+
return <button onClick={handleClick}>Submit</button>;
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
|
|
81
229
|
## Documentation
|
|
82
230
|
|
|
83
231
|
- [Logger Documentation](./docs/logger.md)
|
|
84
232
|
- [Utility Functions](./docs/utils.md)
|
|
85
233
|
- [React Hooks](./docs/hooks.md)
|
|
86
234
|
- [Storage Adapters](./docs/storage.md)
|
|
235
|
+
- [File Upload Service](./docs/universalFile.md)
|
|
236
|
+
- [Data Export Service](./docs/universalExport.md)
|
|
237
|
+
- [i18n Internationalization](./docs/i18n.md)
|
|
238
|
+
- [Analytics Tracking](./docs/analytics.md)
|
|
87
239
|
|
|
88
240
|
## Examples
|
|
89
241
|
|