@idealyst/files 1.2.138 → 1.2.139

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.138",
3
+ "version": "1.2.139",
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,12 +37,12 @@
37
37
  "publish:npm": "npm publish"
38
38
  },
39
39
  "peerDependencies": {
40
- "@idealyst/components": "^1.2.138",
41
- "@idealyst/theme": "^1.2.138",
40
+ "@idealyst/components": "^1.2.139",
41
+ "@idealyst/theme": "^1.2.139",
42
+ "@react-native-documents/picker": ">=1.0.0",
42
43
  "react": ">=16.8.0",
43
44
  "react-native": ">=0.60.0",
44
45
  "react-native-blob-util": ">=0.19.0",
45
- "react-native-document-picker": ">=9.0.0",
46
46
  "react-native-image-picker": ">=7.0.0"
47
47
  },
48
48
  "peerDependenciesMeta": {
@@ -52,13 +52,13 @@
52
52
  "@idealyst/theme": {
53
53
  "optional": true
54
54
  },
55
- "react-native": {
55
+ "@react-native-documents/picker": {
56
56
  "optional": true
57
57
  },
58
- "react-native-blob-util": {
58
+ "react-native": {
59
59
  "optional": true
60
60
  },
61
- "react-native-document-picker": {
61
+ "react-native-blob-util": {
62
62
  "optional": true
63
63
  },
64
64
  "react-native-image-picker": {
@@ -66,8 +66,8 @@
66
66
  }
67
67
  },
68
68
  "devDependencies": {
69
- "@idealyst/components": "^1.2.138",
70
- "@idealyst/theme": "^1.2.138",
69
+ "@idealyst/components": "^1.2.139",
70
+ "@idealyst/theme": "^1.2.139",
71
71
  "@types/react": "^19.1.0",
72
72
  "@types/react-native": "^0.73.0",
73
73
  "react": "^19.1.0",
package/src/constants.ts CHANGED
@@ -82,7 +82,7 @@ export const FILE_TYPE_EXTENSIONS: Record<FileType, string[]> = {
82
82
  };
83
83
 
84
84
  /**
85
- * Document picker type mappings for react-native-document-picker.
85
+ * Document picker type mappings for @react-native-documents/picker.
86
86
  */
87
87
  export const DOCUMENT_PICKER_TYPES: Record<FileType, string[]> = {
88
88
  image: ['public.image'],
@@ -23,7 +23,7 @@ import {
23
23
  getFileExtension,
24
24
  } from '../utils';
25
25
  import { checkPermissions, requestPermissions } from '../permissions/permissions.native';
26
- import DocumentPicker, { type DocumentPickerResponse } from 'react-native-document-picker';
26
+ import { pick as pickDocuments, keepLocalCopy, isErrorWithCode, errorCodes } from '@react-native-documents/picker';
27
27
  import { launchCamera, launchImageLibrary, type ImagePickerResponse } from 'react-native-image-picker';
28
28
  import ReactNativeBlobUtil from 'react-native-blob-util';
29
29
 
@@ -32,7 +32,7 @@ type FilePickerEvents = {
32
32
  };
33
33
 
34
34
  /**
35
- * Native implementation of IFilePicker using react-native-document-picker and react-native-image-picker.
35
+ * Native implementation of IFilePicker using @react-native-documents/picker and react-native-image-picker.
36
36
  */
37
37
  export class NativeFilePicker implements IFilePicker {
38
38
  private _status: FilePickerStatus = { ...INITIAL_FILE_PICKER_STATUS };
@@ -223,14 +223,24 @@ export class NativeFilePicker implements IFilePicker {
223
223
  const types = this._buildDocumentPickerTypes(config);
224
224
 
225
225
  try {
226
- const results = await DocumentPicker.pick({
226
+ const results = await pickDocuments({
227
227
  type: types,
228
228
  allowMultiSelection: config.multiple,
229
- copyTo: 'cachesDirectory',
229
+ mode: 'import',
230
230
  });
231
231
 
232
232
  this._updateState('processing');
233
- const files = await this._transformDocumentPickerResponse(results, config);
233
+
234
+ // Copy picked files to cache directory for reliable access
235
+ const localCopies = await keepLocalCopy({
236
+ files: results.map(doc => ({
237
+ uri: doc.uri,
238
+ fileName: doc.name || `file_${Date.now()}`,
239
+ })),
240
+ destination: 'cachesDirectory',
241
+ });
242
+
243
+ const files = await this._transformDocumentPickerResponse(results, localCopies, config);
234
244
  const { accepted, rejected } = validateFilesUtil(files, config);
235
245
 
236
246
  this._updateState('idle');
@@ -240,7 +250,7 @@ export class NativeFilePicker implements IFilePicker {
240
250
  rejected,
241
251
  };
242
252
  } catch (error) {
243
- if (DocumentPicker.isCancel(error)) {
253
+ if (isErrorWithCode(error) && error.code === errorCodes.OPERATION_CANCELED) {
244
254
  this._updateState('idle');
245
255
  return { cancelled: true, files: [], rejected: [] };
246
256
  }
@@ -312,21 +322,31 @@ export class NativeFilePicker implements IFilePicker {
312
322
  }
313
323
 
314
324
  private async _transformDocumentPickerResponse(
315
- results: DocumentPickerResponse[],
325
+ results: { uri: string; name: string | null; type: string | null; size: number | null }[],
326
+ localCopies: { sourceUri: string; status: string; localUri?: string; copyError?: string }[],
316
327
  config?: FilePickerConfig
317
328
  ): Promise<PickedFile[]> {
318
329
  const files: PickedFile[] = [];
319
330
 
331
+ // Build a map from source URI to local copy URI for quick lookup
332
+ const localUriMap = new Map<string, string>();
333
+ for (const copy of localCopies) {
334
+ if (copy.status === 'success' && copy.localUri) {
335
+ localUriMap.set(copy.sourceUri, copy.localUri);
336
+ }
337
+ }
338
+
320
339
  for (const doc of results) {
340
+ const resolvedUri = localUriMap.get(doc.uri) || doc.uri;
321
341
  const file: PickedFile = {
322
342
  id: generateId(),
323
343
  name: doc.name || `file_${Date.now()}`,
324
344
  size: doc.size || 0,
325
345
  type: doc.type || 'application/octet-stream',
326
- uri: doc.fileCopyUri || doc.uri,
346
+ uri: resolvedUri,
327
347
  extension: getFileExtension(doc.name || ''),
328
- getArrayBuffer: () => this._readFileAsArrayBuffer(doc.fileCopyUri || doc.uri),
329
- getData: () => this._readFileAsBase64(doc.fileCopyUri || doc.uri),
348
+ getArrayBuffer: () => this._readFileAsArrayBuffer(resolvedUri),
349
+ getData: () => this._readFileAsBase64(resolvedUri),
330
350
  };
331
351
 
332
352
  files.push(file);