@idealyst/files 1.2.97 → 1.2.98

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@idealyst/files",
3
- "version": "1.2.97",
3
+ "version": "1.2.98",
4
4
  "description": "Cross-platform file picker, upload, and local file management for React and React Native",
5
5
  "documentation": "https://github.com/IdealystIO/idealyst-framework/tree/main/packages/files#readme",
6
6
  "readme": "README.md",
@@ -37,8 +37,8 @@
37
37
  "publish:npm": "npm publish"
38
38
  },
39
39
  "peerDependencies": {
40
- "@idealyst/components": "^1.2.97",
41
- "@idealyst/theme": "^1.2.97",
40
+ "@idealyst/components": "^1.2.98",
41
+ "@idealyst/theme": "^1.2.98",
42
42
  "react": ">=16.8.0",
43
43
  "react-native": ">=0.60.0",
44
44
  "react-native-document-picker": ">=9.0.0",
@@ -66,8 +66,8 @@
66
66
  }
67
67
  },
68
68
  "devDependencies": {
69
- "@idealyst/components": "^1.2.97",
70
- "@idealyst/theme": "^1.2.97",
69
+ "@idealyst/components": "^1.2.98",
70
+ "@idealyst/theme": "^1.2.98",
71
71
  "@types/react": "^19.1.0",
72
72
  "@types/react-native": "^0.73.0",
73
73
  "react": "^19.1.0",
@@ -1,14 +1,5 @@
1
1
  import type { PermissionStatus, PermissionResult } from '../types';
2
-
3
- // Lazy load react-native-image-picker for permission checks
4
- let ImagePicker: typeof import('react-native-image-picker') | null = null;
5
-
6
- async function getImagePicker() {
7
- if (!ImagePicker) {
8
- ImagePicker = await import('react-native-image-picker');
9
- }
10
- return ImagePicker;
11
- }
2
+ import { launchCamera, launchImageLibrary } from 'react-native-image-picker';
12
3
 
13
4
  /**
14
5
  * Map image picker permission to our PermissionStatus.
@@ -35,10 +26,8 @@ function mapPermissionStatus(status: string): PermissionStatus {
35
26
  */
36
27
  export async function checkPhotoLibraryPermission(): Promise<PermissionStatus> {
37
28
  try {
38
- const imagePicker = await getImagePicker();
39
-
40
29
  // Check if the library exists and has the right method
41
- if (typeof imagePicker.launchImageLibrary !== 'function') {
30
+ if (typeof launchImageLibrary !== 'function') {
42
31
  return 'unavailable';
43
32
  }
44
33
 
@@ -55,12 +44,10 @@ export async function checkPhotoLibraryPermission(): Promise<PermissionStatus> {
55
44
  */
56
45
  export async function requestPhotoLibraryPermission(): Promise<PermissionStatus> {
57
46
  try {
58
- const imagePicker = await getImagePicker();
59
-
60
47
  // Launch the image library to trigger permission request
61
48
  // This is a common pattern since react-native-image-picker doesn't expose
62
49
  // a direct permission request API
63
- const result = await imagePicker.launchImageLibrary({
50
+ const result = await launchImageLibrary({
64
51
  mediaType: 'mixed',
65
52
  selectionLimit: 0,
66
53
  });
@@ -91,9 +78,7 @@ export async function requestPhotoLibraryPermission(): Promise<PermissionStatus>
91
78
  */
92
79
  export async function checkCameraPermission(): Promise<PermissionStatus> {
93
80
  try {
94
- const imagePicker = await getImagePicker();
95
-
96
- if (typeof imagePicker.launchCamera !== 'function') {
81
+ if (typeof launchCamera !== 'function') {
97
82
  return 'unavailable';
98
83
  }
99
84
 
@@ -108,10 +93,8 @@ export async function checkCameraPermission(): Promise<PermissionStatus> {
108
93
  */
109
94
  export async function requestCameraPermission(): Promise<PermissionStatus> {
110
95
  try {
111
- const imagePicker = await getImagePicker();
112
-
113
96
  // Launch camera to trigger permission request
114
- const result = await imagePicker.launchCamera({
97
+ const result = await launchCamera({
115
98
  mediaType: 'photo',
116
99
  saveToPhotos: false,
117
100
  });
@@ -23,24 +23,9 @@ import {
23
23
  getFileExtension,
24
24
  } from '../utils';
25
25
  import { checkPermissions, requestPermissions } from '../permissions/permissions.native';
26
-
27
- // Lazy load native modules
28
- let DocumentPicker: typeof import('react-native-document-picker') | null = null;
29
- let ImagePicker: typeof import('react-native-image-picker') | null = null;
30
-
31
- async function getDocumentPicker() {
32
- if (!DocumentPicker) {
33
- DocumentPicker = await import('react-native-document-picker');
34
- }
35
- return DocumentPicker;
36
- }
37
-
38
- async function getImagePicker() {
39
- if (!ImagePicker) {
40
- ImagePicker = await import('react-native-image-picker');
41
- }
42
- return ImagePicker;
43
- }
26
+ import DocumentPicker, { type DocumentPickerResponse } from 'react-native-document-picker';
27
+ import { launchCamera, launchImageLibrary, type ImagePickerResponse } from 'react-native-image-picker';
28
+ import ReactNativeBlobUtil from 'react-native-blob-util';
44
29
 
45
30
  type FilePickerEvents = {
46
31
  stateChange: [FilePickerStatus];
@@ -119,9 +104,7 @@ export class NativeFilePicker implements IFilePicker {
119
104
  this._updateState('picking');
120
105
 
121
106
  try {
122
- const imagePicker = await getImagePicker();
123
-
124
- const result = await imagePicker.launchCamera({
107
+ const result = await launchCamera({
125
108
  mediaType: this._mapMediaType(options?.mediaType || 'photo'),
126
109
  quality: (options?.quality || 80) / 100,
127
110
  durationLimit: options?.maxDuration,
@@ -199,11 +182,9 @@ export class NativeFilePicker implements IFilePicker {
199
182
  }
200
183
 
201
184
  private async _pickMedia(config: FilePickerConfig): Promise<FilePickerResult> {
202
- const imagePicker = await getImagePicker();
203
-
204
185
  const mediaType = this._getMediaTypeFromConfig(config);
205
186
 
206
- const result = await imagePicker.launchImageLibrary({
187
+ const result = await launchImageLibrary({
207
188
  mediaType,
208
189
  selectionLimit: config.multiple ? (config.maxFiles || 0) : 1,
209
190
  quality: (config.imageQuality || 80) / 100,
@@ -239,12 +220,10 @@ export class NativeFilePicker implements IFilePicker {
239
220
  }
240
221
 
241
222
  private async _pickDocuments(config: FilePickerConfig): Promise<FilePickerResult> {
242
- const docPicker = await getDocumentPicker();
243
-
244
223
  const types = this._buildDocumentPickerTypes(config);
245
224
 
246
225
  try {
247
- const results = await docPicker.default.pick({
226
+ const results = await DocumentPicker.pick({
248
227
  type: types,
249
228
  allowMultiSelection: config.multiple,
250
229
  copyTo: 'cachesDirectory',
@@ -261,8 +240,7 @@ export class NativeFilePicker implements IFilePicker {
261
240
  rejected,
262
241
  };
263
242
  } catch (error) {
264
- const dp = await getDocumentPicker();
265
- if (dp.default.isCancel(error)) {
243
+ if (DocumentPicker.isCancel(error)) {
266
244
  this._updateState('idle');
267
245
  return { cancelled: true, files: [], rejected: [] };
268
246
  }
@@ -305,7 +283,7 @@ export class NativeFilePicker implements IFilePicker {
305
283
  }
306
284
 
307
285
  private async _transformImagePickerResponse(
308
- response: import('react-native-image-picker').ImagePickerResponse,
286
+ response: ImagePickerResponse,
309
287
  config?: FilePickerConfig
310
288
  ): Promise<PickedFile[]> {
311
289
  const files: PickedFile[] = [];
@@ -334,7 +312,7 @@ export class NativeFilePicker implements IFilePicker {
334
312
  }
335
313
 
336
314
  private async _transformDocumentPickerResponse(
337
- results: import('react-native-document-picker').DocumentPickerResponse[],
315
+ results: DocumentPickerResponse[],
338
316
  config?: FilePickerConfig
339
317
  ): Promise<PickedFile[]> {
340
318
  const files: PickedFile[] = [];
@@ -369,10 +347,8 @@ export class NativeFilePicker implements IFilePicker {
369
347
  }
370
348
 
371
349
  private async _readFileAsArrayBuffer(uri: string): Promise<ArrayBuffer> {
372
- // Use react-native-blob-util for file reading
373
350
  try {
374
- const BlobUtil = await import('react-native-blob-util');
375
- const base64 = await BlobUtil.default.fs.readFile(uri.replace('file://', ''), 'base64');
351
+ const base64 = await ReactNativeBlobUtil.fs.readFile(uri.replace('file://', ''), 'base64');
376
352
  return this._base64ToArrayBuffer(base64);
377
353
  } catch {
378
354
  // Fallback: return empty buffer if reading fails
@@ -382,8 +358,7 @@ export class NativeFilePicker implements IFilePicker {
382
358
 
383
359
  private async _readFileAsBase64(uri: string): Promise<string> {
384
360
  try {
385
- const BlobUtil = await import('react-native-blob-util');
386
- return await BlobUtil.default.fs.readFile(uri.replace('file://', ''), 'base64');
361
+ return await ReactNativeBlobUtil.fs.readFile(uri.replace('file://', ''), 'base64');
387
362
  } catch {
388
363
  return '';
389
364
  }
@@ -16,16 +16,7 @@ import {
16
16
  } from '../utils';
17
17
  import { UploadQueue } from './UploadQueue';
18
18
  import { ChunkedUploader } from './ChunkedUploader';
19
-
20
- // Lazy load react-native-blob-util
21
- let BlobUtil: typeof import('react-native-blob-util') | null = null;
22
-
23
- async function getBlobUtil() {
24
- if (!BlobUtil) {
25
- BlobUtil = await import('react-native-blob-util');
26
- }
27
- return BlobUtil.default;
28
- }
19
+ import ReactNativeBlobUtil from 'react-native-blob-util';
29
20
 
30
21
  interface UploadTask {
31
22
  cancel: () => void;
@@ -171,8 +162,6 @@ export class NativeFileUploader implements IFileUploader {
171
162
  const { id, file, config } = upload;
172
163
 
173
164
  try {
174
- const RNBlobUtil = await getBlobUtil();
175
-
176
165
  // Get file path
177
166
  const filePath = file.uri.replace('file://', '');
178
167
 
@@ -182,7 +171,7 @@ export class NativeFileUploader implements IFileUploader {
182
171
  name: config.fieldName,
183
172
  filename: file.name,
184
173
  type: file.type,
185
- data: RNBlobUtil.wrap(filePath),
174
+ data: ReactNativeBlobUtil.wrap(filePath),
186
175
  },
187
176
  ];
188
177
 
@@ -197,7 +186,7 @@ export class NativeFileUploader implements IFileUploader {
197
186
  }
198
187
 
199
188
  // Create upload task
200
- const task = RNBlobUtil.fetch(
189
+ const task = ReactNativeBlobUtil.fetch(
201
190
  config.method,
202
191
  config.url,
203
192
  {
@@ -266,13 +255,11 @@ export class NativeFileUploader implements IFileUploader {
266
255
  const { id, file, config } = upload;
267
256
 
268
257
  try {
269
- const RNBlobUtil = await getBlobUtil();
270
-
271
258
  // Get file path
272
259
  const filePath = file.uri.replace('file://', '');
273
260
 
274
261
  // Configure for background upload
275
- const sessionConfig = RNBlobUtil.config({
262
+ const sessionConfig = ReactNativeBlobUtil.config({
276
263
  IOSBackgroundTask: true,
277
264
  indicator: true,
278
265
  timeout: config.timeout,
@@ -284,7 +271,7 @@ export class NativeFileUploader implements IFileUploader {
284
271
  name: config.fieldName,
285
272
  filename: file.name,
286
273
  type: file.type,
287
- data: RNBlobUtil.wrap(filePath),
274
+ data: ReactNativeBlobUtil.wrap(filePath),
288
275
  },
289
276
  ];
290
277