@react-native-documents/picker 9.3.1
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/LICENSE.md +21 -0
- package/android/.gradle/8.9/checksums/checksums.lock +0 -0
- package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.9/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/build.gradle +80 -0
- package/android/src/main/AndroidManifest.xml +3 -0
- package/android/src/main/java/com/reactnativedocumentpicker/CopyDestination.kt +12 -0
- package/android/src/main/java/com/reactnativedocumentpicker/DocumentMetadataBuilder.kt +79 -0
- package/android/src/main/java/com/reactnativedocumentpicker/FileOperations.kt +203 -0
- package/android/src/main/java/com/reactnativedocumentpicker/IntentFactory.kt +36 -0
- package/android/src/main/java/com/reactnativedocumentpicker/IsKnownTypeImpl.kt +40 -0
- package/android/src/main/java/com/reactnativedocumentpicker/MetadataGetter.kt +150 -0
- package/android/src/main/java/com/reactnativedocumentpicker/PickOptions.kt +63 -0
- package/android/src/main/java/com/reactnativedocumentpicker/PromiseWrapper.java +105 -0
- package/android/src/main/java/com/reactnativedocumentpicker/RNDocumentPickerModule.kt +352 -0
- package/android/src/main/java/com/reactnativedocumentpicker/RNDocumentPickerPackage.java +49 -0
- package/android/src/paper/java/com/reactnativedocumentpicker/NativeDocumentPickerSpec.java +69 -0
- package/ios/RCTConvert+RNDocumentPicker.h +8 -0
- package/ios/RCTConvert+RNDocumentPicker.mm +16 -0
- package/ios/RNDocumentPicker.h +19 -0
- package/ios/RNDocumentPicker.mm +128 -0
- package/ios/swift/DocPicker.swift +84 -0
- package/ios/swift/DocSaver.swift +41 -0
- package/ios/swift/DocumentMetadataBuilder.swift +69 -0
- package/ios/swift/FileOperations.swift +68 -0
- package/ios/swift/IsKnownTypeImpl.swift +42 -0
- package/ios/swift/LocalCopyResponse.swift +27 -0
- package/ios/swift/PickerBase.swift +78 -0
- package/ios/swift/PickerOptions.swift +44 -0
- package/ios/swift/PromiseSupport.swift +2 -0
- package/ios/swift/PromiseWrapper.swift +92 -0
- package/ios/swift/SaverOptions.swift +30 -0
- package/jest/build/jest/setup.js +70 -0
- package/jest/build/src/errors.js +47 -0
- package/jest/build/src/fileTypes.js +53 -0
- package/jest/build/src/index.js +22 -0
- package/jest/build/src/isKnownType.js +16 -0
- package/jest/build/src/keepLocalCopy.js +17 -0
- package/jest/build/src/pick.js +50 -0
- package/jest/build/src/pickDirectory.js +31 -0
- package/jest/build/src/release.js +22 -0
- package/jest/build/src/saveDocuments.js +40 -0
- package/jest/build/src/spec/NativeDocumentPicker.js +5 -0
- package/jest/build/src/types.js +4 -0
- package/jest/build/src/validateTypes.js +23 -0
- package/jest/build/tsconfig.tsbuildinfo +1 -0
- package/lib/commonjs/errors.js +53 -0
- package/lib/commonjs/errors.js.map +1 -0
- package/lib/commonjs/fileTypes.js +84 -0
- package/lib/commonjs/fileTypes.js.map +1 -0
- package/lib/commonjs/index.js +74 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/isKnownType.js +27 -0
- package/lib/commonjs/isKnownType.js.map +1 -0
- package/lib/commonjs/keepLocalCopy.js +34 -0
- package/lib/commonjs/keepLocalCopy.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/pick.js +93 -0
- package/lib/commonjs/pick.js.map +1 -0
- package/lib/commonjs/pickDirectory.js +71 -0
- package/lib/commonjs/pickDirectory.js.map +1 -0
- package/lib/commonjs/release.js +31 -0
- package/lib/commonjs/release.js.map +1 -0
- package/lib/commonjs/saveDocuments.js +55 -0
- package/lib/commonjs/saveDocuments.js.map +1 -0
- package/lib/commonjs/spec/NativeDocumentPicker.js +16 -0
- package/lib/commonjs/spec/NativeDocumentPicker.js.map +1 -0
- package/lib/commonjs/types.js +37 -0
- package/lib/commonjs/types.js.map +1 -0
- package/lib/commonjs/validateTypes.js +29 -0
- package/lib/commonjs/validateTypes.js.map +1 -0
- package/lib/module/errors.js +48 -0
- package/lib/module/errors.js.map +1 -0
- package/lib/module/fileTypes.js +81 -0
- package/lib/module/fileTypes.js.map +1 -0
- package/lib/module/index.js +13 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/isKnownType.js +24 -0
- package/lib/module/isKnownType.js.map +1 -0
- package/lib/module/keepLocalCopy.js +31 -0
- package/lib/module/keepLocalCopy.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/pick.js +90 -0
- package/lib/module/pick.js.map +1 -0
- package/lib/module/pickDirectory.js +68 -0
- package/lib/module/pickDirectory.js.map +1 -0
- package/lib/module/release.js +26 -0
- package/lib/module/release.js.map +1 -0
- package/lib/module/saveDocuments.js +52 -0
- package/lib/module/saveDocuments.js.map +1 -0
- package/lib/module/spec/NativeDocumentPicker.js +13 -0
- package/lib/module/spec/NativeDocumentPicker.js.map +1 -0
- package/lib/module/types.js +33 -0
- package/lib/module/types.js.map +1 -0
- package/lib/module/validateTypes.js +24 -0
- package/lib/module/validateTypes.js.map +1 -0
- package/lib/typescript/errors.d.ts +40 -0
- package/lib/typescript/errors.d.ts.map +1 -0
- package/lib/typescript/fileTypes.d.ts +94 -0
- package/lib/typescript/fileTypes.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +13 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/isKnownType.d.ts +41 -0
- package/lib/typescript/isKnownType.d.ts.map +1 -0
- package/lib/typescript/keepLocalCopy.d.ts +46 -0
- package/lib/typescript/keepLocalCopy.d.ts.map +1 -0
- package/lib/typescript/pick.d.ts +84 -0
- package/lib/typescript/pick.d.ts.map +1 -0
- package/lib/typescript/pickDirectory.d.ts +62 -0
- package/lib/typescript/pickDirectory.d.ts.map +1 -0
- package/lib/typescript/release.d.ts +24 -0
- package/lib/typescript/release.d.ts.map +1 -0
- package/lib/typescript/saveDocuments.d.ts +55 -0
- package/lib/typescript/saveDocuments.d.ts.map +1 -0
- package/lib/typescript/spec/NativeDocumentPicker.d.ts +29 -0
- package/lib/typescript/spec/NativeDocumentPicker.d.ts.map +1 -0
- package/lib/typescript/types.d.ts +95 -0
- package/lib/typescript/types.d.ts.map +1 -0
- package/lib/typescript/validateTypes.d.ts +3 -0
- package/lib/typescript/validateTypes.d.ts.map +1 -0
- package/package.json +92 -0
- package/react-native-document-picker.podspec +30 -0
- package/src/errors.ts +49 -0
- package/src/fileTypes.ts +92 -0
- package/src/index.ts +47 -0
- package/src/isKnownType.ts +48 -0
- package/src/keepLocalCopy.ts +51 -0
- package/src/pick.ts +151 -0
- package/src/pickDirectory.ts +93 -0
- package/src/release.ts +36 -0
- package/src/saveDocuments.ts +99 -0
- package/src/spec/NativeDocumentPicker.ts +31 -0
- package/src/types.ts +119 -0
- package/src/validateTypes.ts +26 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// LICENSE: see License.md in the package root
|
|
2
|
+
|
|
3
|
+
import Foundation
|
|
4
|
+
import UIKit
|
|
5
|
+
import UniformTypeIdentifiers
|
|
6
|
+
|
|
7
|
+
@objc public class SaverOptions: NSObject {
|
|
8
|
+
let transitionStyle: UIModalTransitionStyle
|
|
9
|
+
let presentationStyle: UIModalPresentationStyle
|
|
10
|
+
let initialDirectoryUrl: URL?
|
|
11
|
+
let sourceUrls: [URL]
|
|
12
|
+
let shouldShowFileExtensions: Bool
|
|
13
|
+
let asCopy: Bool
|
|
14
|
+
|
|
15
|
+
@objc public init(sourceUrlStrings: [String], asCopy: Bool, initialDirectoryUrl: String? = nil, shouldShowFileExtensions: Bool, transitionStyle: UIModalTransitionStyle = .coverVertical, presentationStyle: UIModalPresentationStyle = .fullScreen) {
|
|
16
|
+
self.sourceUrls = sourceUrlStrings.map({ it in
|
|
17
|
+
URL(string: it)!
|
|
18
|
+
})
|
|
19
|
+
self.asCopy = asCopy
|
|
20
|
+
self.transitionStyle = transitionStyle
|
|
21
|
+
self.presentationStyle = presentationStyle
|
|
22
|
+
if let unwrappedUrl = initialDirectoryUrl, let url = URL(string: unwrappedUrl) {
|
|
23
|
+
self.initialDirectoryUrl = url
|
|
24
|
+
} else {
|
|
25
|
+
self.initialDirectoryUrl = nil
|
|
26
|
+
}
|
|
27
|
+
self.shouldShowFileExtensions = shouldShowFileExtensions
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mockDocPickerResponse = void 0;
|
|
4
|
+
exports.mockDocPickerResponse = {
|
|
5
|
+
uri: 'file:///mock/uri/mockName.pdf',
|
|
6
|
+
name: 'mockName.pdf',
|
|
7
|
+
type: 'application/pdf',
|
|
8
|
+
nativeType: 'com.adobe.pdf',
|
|
9
|
+
size: 1234,
|
|
10
|
+
error: null,
|
|
11
|
+
isVirtual: false,
|
|
12
|
+
convertibleToMimeTypes: null,
|
|
13
|
+
hasRequestedType: true,
|
|
14
|
+
};
|
|
15
|
+
function mockFactory() {
|
|
16
|
+
const mockNativeModule = Object.freeze({
|
|
17
|
+
isKnownType: jest.fn().mockReturnValue({
|
|
18
|
+
isKnown: false,
|
|
19
|
+
UTType: null,
|
|
20
|
+
preferredFilenameExtension: null,
|
|
21
|
+
mimeType: null,
|
|
22
|
+
}),
|
|
23
|
+
keepLocalCopy: jest.fn().mockImplementation(async (options) => {
|
|
24
|
+
const mockCopyResults = options.files.map(({ uri, fileName }) => ({
|
|
25
|
+
sourceUri: uri,
|
|
26
|
+
localUri: `file:///mock/uri/${fileName}`,
|
|
27
|
+
status: 'success',
|
|
28
|
+
}));
|
|
29
|
+
return mockCopyResults;
|
|
30
|
+
}),
|
|
31
|
+
pick: jest.fn().mockResolvedValue([exports.mockDocPickerResponse]),
|
|
32
|
+
pickDirectory: jest.fn().mockResolvedValue({
|
|
33
|
+
uri: 'file:///mock/uri/mockDirectory',
|
|
34
|
+
}),
|
|
35
|
+
saveDocument: jest
|
|
36
|
+
.fn()
|
|
37
|
+
.mockResolvedValue([exports.mockDocPickerResponse]),
|
|
38
|
+
writeDocuments: jest
|
|
39
|
+
.fn()
|
|
40
|
+
.mockResolvedValue([exports.mockDocPickerResponse]),
|
|
41
|
+
releaseSecureAccess: jest.fn().mockResolvedValue(null),
|
|
42
|
+
releaseLongTermAccess: jest.fn().mockResolvedValue([]),
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
NativeDocumentPicker: mockNativeModule,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
jest.mock('../src/spec/NativeDocumentPicker', () => mockFactory());
|
|
49
|
+
// the following are for jest testing outside of the library, where the paths are different
|
|
50
|
+
// alternative is to use moduleNameMapper in user space
|
|
51
|
+
const mockModulePaths = [
|
|
52
|
+
'../../../lib/commonjs/spec/NativeDocumentPicker',
|
|
53
|
+
'../../../lib/module/spec/NativeDocumentPicker',
|
|
54
|
+
];
|
|
55
|
+
mockModulePaths.forEach((path) => {
|
|
56
|
+
try {
|
|
57
|
+
require.resolve(path);
|
|
58
|
+
jest.mock(path, () => mockFactory());
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
if ('code' in error && error.code === 'MODULE_NOT_FOUND') {
|
|
62
|
+
if (!process.env.SILENCE_MOCK_NOT_FOUND) {
|
|
63
|
+
console.warn(`Unable to resolve ${path}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isErrorWithCode = exports.errorCodes = void 0;
|
|
4
|
+
const OPERATION_CANCELED = 'OPERATION_CANCELED';
|
|
5
|
+
const IN_PROGRESS = 'ASYNC_OP_IN_PROGRESS';
|
|
6
|
+
const UNABLE_TO_OPEN_FILE_TYPE = 'UNABLE_TO_OPEN_FILE_TYPE';
|
|
7
|
+
/**
|
|
8
|
+
* Error codes that can be returned by the module, and are available on the `code` property of the error.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* const handleError = (err: unknown) => {
|
|
13
|
+
* if (isErrorWithCode(err)) {
|
|
14
|
+
* switch (err.code) {
|
|
15
|
+
* case errorCodes.IN_PROGRESS:
|
|
16
|
+
* ...
|
|
17
|
+
* break
|
|
18
|
+
* case errorCodes.UNABLE_TO_OPEN_FILE_TYPE:
|
|
19
|
+
* ...
|
|
20
|
+
* break
|
|
21
|
+
* case errorCodes.OPERATION_CANCELED:
|
|
22
|
+
* // ignore
|
|
23
|
+
* break
|
|
24
|
+
* default:
|
|
25
|
+
* console.error(err)
|
|
26
|
+
* }
|
|
27
|
+
* } else {
|
|
28
|
+
* console.error(err)
|
|
29
|
+
* }
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
* */
|
|
33
|
+
exports.errorCodes = Object.freeze({
|
|
34
|
+
OPERATION_CANCELED,
|
|
35
|
+
IN_PROGRESS,
|
|
36
|
+
UNABLE_TO_OPEN_FILE_TYPE,
|
|
37
|
+
});
|
|
38
|
+
/**
|
|
39
|
+
* TypeScript helper to check if an object has the `code` property.
|
|
40
|
+
* This is used to avoid `as` casting when you access the `code` property on errors returned by the module.
|
|
41
|
+
*/
|
|
42
|
+
const isErrorWithCode = (error) => {
|
|
43
|
+
// to account for https://github.com/facebook/react-native/issues/41950
|
|
44
|
+
const isNewArchErrorIOS = typeof error === 'object' && error != null;
|
|
45
|
+
return (error instanceof Error || isNewArchErrorIOS) && 'code' in error;
|
|
46
|
+
};
|
|
47
|
+
exports.isErrorWithCode = isErrorWithCode;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.typesAreEqual = exports.types = void 0;
|
|
4
|
+
const react_native_1 = require("react-native");
|
|
5
|
+
// TODO split this into platform-specific files, and / or topic-specific files
|
|
6
|
+
const mimeTypes = Object.freeze({
|
|
7
|
+
allFiles: '*/*',
|
|
8
|
+
audio: 'audio/*',
|
|
9
|
+
csv: ['text/csv', 'text/comma-separated-values'],
|
|
10
|
+
doc: 'application/msword',
|
|
11
|
+
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
12
|
+
images: 'image/*',
|
|
13
|
+
pdf: 'application/pdf',
|
|
14
|
+
plainText: 'text/plain',
|
|
15
|
+
json: 'application/json',
|
|
16
|
+
ppt: 'application/vnd.ms-powerpoint',
|
|
17
|
+
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
18
|
+
video: 'video/*',
|
|
19
|
+
xls: 'application/vnd.ms-excel',
|
|
20
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
21
|
+
zip: 'application/zip',
|
|
22
|
+
}); //satisfies TypeOfFileTypes
|
|
23
|
+
const utis = Object.freeze({
|
|
24
|
+
allFiles: 'public.item',
|
|
25
|
+
audio: 'public.audio',
|
|
26
|
+
csv: 'public.comma-separated-values-text',
|
|
27
|
+
doc: 'com.microsoft.word.doc',
|
|
28
|
+
docx: 'org.openxmlformats.wordprocessingml.document',
|
|
29
|
+
images: 'public.image',
|
|
30
|
+
pdf: 'com.adobe.pdf',
|
|
31
|
+
plainText: 'public.plain-text',
|
|
32
|
+
json: 'public.json',
|
|
33
|
+
ppt: 'com.microsoft.powerpoint.ppt',
|
|
34
|
+
pptx: 'org.openxmlformats.presentationml.presentation',
|
|
35
|
+
video: 'public.movie',
|
|
36
|
+
xls: 'com.microsoft.excel.xls',
|
|
37
|
+
xlsx: 'org.openxmlformats.spreadsheetml.sheet',
|
|
38
|
+
zip: 'public.zip-archive',
|
|
39
|
+
}); // satisfies TypeOfFileTypes
|
|
40
|
+
const perPlatformTypes = {
|
|
41
|
+
android: mimeTypes,
|
|
42
|
+
ios: utis,
|
|
43
|
+
// unsupported, but added to make TS happy
|
|
44
|
+
macos: utis,
|
|
45
|
+
windows: mimeTypes,
|
|
46
|
+
web: mimeTypes,
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* @hidden
|
|
50
|
+
* */
|
|
51
|
+
exports.types = perPlatformTypes[react_native_1.Platform.OS];
|
|
52
|
+
const mimesAndUtisAreEqual = true;
|
|
53
|
+
exports.typesAreEqual = mimesAndUtisAreEqual;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.releaseSecureAccess = exports.releaseLongTermAccess = exports.saveDocuments = exports.pick = exports.pickDirectory = exports.isErrorWithCode = exports.errorCodes = exports.types = exports.keepLocalCopy = exports.isKnownType = void 0;
|
|
4
|
+
var isKnownType_1 = require("./isKnownType");
|
|
5
|
+
Object.defineProperty(exports, "isKnownType", { enumerable: true, get: function () { return isKnownType_1.isKnownType; } });
|
|
6
|
+
var keepLocalCopy_1 = require("./keepLocalCopy");
|
|
7
|
+
Object.defineProperty(exports, "keepLocalCopy", { enumerable: true, get: function () { return keepLocalCopy_1.keepLocalCopy; } });
|
|
8
|
+
// TODO expose from /fileTypes?
|
|
9
|
+
var fileTypes_1 = require("./fileTypes");
|
|
10
|
+
Object.defineProperty(exports, "types", { enumerable: true, get: function () { return fileTypes_1.types; } });
|
|
11
|
+
var errors_1 = require("./errors");
|
|
12
|
+
Object.defineProperty(exports, "errorCodes", { enumerable: true, get: function () { return errors_1.errorCodes; } });
|
|
13
|
+
Object.defineProperty(exports, "isErrorWithCode", { enumerable: true, get: function () { return errors_1.isErrorWithCode; } });
|
|
14
|
+
var pickDirectory_1 = require("./pickDirectory");
|
|
15
|
+
Object.defineProperty(exports, "pickDirectory", { enumerable: true, get: function () { return pickDirectory_1.pickDirectory; } });
|
|
16
|
+
var pick_1 = require("./pick");
|
|
17
|
+
Object.defineProperty(exports, "pick", { enumerable: true, get: function () { return pick_1.pick; } });
|
|
18
|
+
var saveDocuments_1 = require("./saveDocuments");
|
|
19
|
+
Object.defineProperty(exports, "saveDocuments", { enumerable: true, get: function () { return saveDocuments_1.saveDocuments; } });
|
|
20
|
+
var release_1 = require("./release");
|
|
21
|
+
Object.defineProperty(exports, "releaseLongTermAccess", { enumerable: true, get: function () { return release_1.releaseLongTermAccess; } });
|
|
22
|
+
Object.defineProperty(exports, "releaseSecureAccess", { enumerable: true, get: function () { return release_1.releaseSecureAccess; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isKnownType = isKnownType;
|
|
4
|
+
const NativeDocumentPicker_1 = require("./spec/NativeDocumentPicker");
|
|
5
|
+
/**
|
|
6
|
+
*
|
|
7
|
+
* Checks if the given value (which can be a file extension, UTType identifier or mime) is known to the system.
|
|
8
|
+
* Also returns the mime type which you can use to filter files on Android.
|
|
9
|
+
*
|
|
10
|
+
* @group DocumentPicker
|
|
11
|
+
* */
|
|
12
|
+
function isKnownType(options) {
|
|
13
|
+
const { kind, value } = options;
|
|
14
|
+
const result = NativeDocumentPicker_1.NativeDocumentPicker.isKnownType(kind, value);
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.keepLocalCopy = keepLocalCopy;
|
|
4
|
+
const NativeDocumentPicker_1 = require("./spec/NativeDocumentPicker");
|
|
5
|
+
/**
|
|
6
|
+
* Makes the file available in the app's storage. The behavior is different on iOS and Android, and for simple use cases (such as uploading file to remote server), you may not need to call this method at all.
|
|
7
|
+
*
|
|
8
|
+
* On Android, it can be used to "convert" a `content://` Uri into a local file. It also "exports" virtual files (such as Google docs or sheets) into local files.
|
|
9
|
+
*
|
|
10
|
+
* However, note that for some use cases, such as uploading the picked file to a server, you may not need to call `keepLocalCopy` at all. React Native's `fetch` can handle `content://` uris.
|
|
11
|
+
*
|
|
12
|
+
* @group DocumentPicker
|
|
13
|
+
* */
|
|
14
|
+
function keepLocalCopy(options) {
|
|
15
|
+
const response = NativeDocumentPicker_1.NativeDocumentPicker.keepLocalCopy(options);
|
|
16
|
+
return response;
|
|
17
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pick = pick;
|
|
4
|
+
const NativeDocumentPicker_1 = require("./spec/NativeDocumentPicker");
|
|
5
|
+
const fileTypes_1 = require("./fileTypes");
|
|
6
|
+
const react_native_1 = require("react-native");
|
|
7
|
+
const validateTypes_1 = require("./validateTypes");
|
|
8
|
+
/**
|
|
9
|
+
* The method for picking a file, both for `import` and `open` modes.
|
|
10
|
+
*
|
|
11
|
+
* For result types, see {@link DocumentPickerResponse} or {@link DocumentPickerResponseOpenLongTerm}.
|
|
12
|
+
*
|
|
13
|
+
* For options, see {@link DocumentPickerOptionsImport}, {@link DocumentPickerOptionsOpenOnce} or {@link DocumentPickerOptionsOpenLongTerm}.
|
|
14
|
+
*
|
|
15
|
+
* @group DocumentPicker
|
|
16
|
+
* */
|
|
17
|
+
async function pick(options) {
|
|
18
|
+
const type = (() => {
|
|
19
|
+
if (!options?.type) {
|
|
20
|
+
return [fileTypes_1.types.allFiles];
|
|
21
|
+
}
|
|
22
|
+
const newType = Array.isArray(options.type) ? options.type : [options.type];
|
|
23
|
+
return newType.flat().map((it) => it.trim());
|
|
24
|
+
})();
|
|
25
|
+
const newOpts = {
|
|
26
|
+
mode: 'import',
|
|
27
|
+
// allowMultiSelection must be false to maintain old (v5) behavior
|
|
28
|
+
allowMultiSelection: false,
|
|
29
|
+
allowVirtualFiles: false,
|
|
30
|
+
...options,
|
|
31
|
+
type,
|
|
32
|
+
};
|
|
33
|
+
if (!newOpts.type.every((it) => typeof it === 'string')) {
|
|
34
|
+
throw new TypeError(`Unexpected type option in ${newOpts.type}, did you try using a DocumentPicker.types.* that does not exist?`);
|
|
35
|
+
}
|
|
36
|
+
if ('mode' in newOpts && !['import', 'open'].includes(newOpts.mode)) {
|
|
37
|
+
throw new TypeError('Invalid mode option: ' + newOpts.mode);
|
|
38
|
+
}
|
|
39
|
+
const response = NativeDocumentPicker_1.NativeDocumentPicker.pick(newOpts);
|
|
40
|
+
const awaitedResult = await response;
|
|
41
|
+
for (const res of awaitedResult) {
|
|
42
|
+
if (react_native_1.Platform.OS === 'android') {
|
|
43
|
+
res.hasRequestedType = (0, validateTypes_1.safeValidate)(newOpts.type, res);
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
res.hasRequestedType = true;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return awaitedResult;
|
|
50
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.pickDirectory = pickDirectory;
|
|
4
|
+
const react_native_1 = require("react-native");
|
|
5
|
+
const NativeDocumentPicker_1 = require("./spec/NativeDocumentPicker");
|
|
6
|
+
/**
|
|
7
|
+
* Opens a directory picker.
|
|
8
|
+
*
|
|
9
|
+
* @group DocumentPicker
|
|
10
|
+
* */
|
|
11
|
+
async function pickDirectory(options) {
|
|
12
|
+
const optionsOverride = (() => {
|
|
13
|
+
if (react_native_1.Platform.OS === 'ios') {
|
|
14
|
+
return {
|
|
15
|
+
...options,
|
|
16
|
+
mode: 'open',
|
|
17
|
+
allowMultiSelection: false,
|
|
18
|
+
type: ['public.folder'],
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
else {
|
|
22
|
+
return {
|
|
23
|
+
// technically, "mode" is ignored here, and we shouldn't need to specify anything but the PickOptions data class
|
|
24
|
+
// requires mode to be set
|
|
25
|
+
mode: 'open',
|
|
26
|
+
...options,
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
})();
|
|
30
|
+
return NativeDocumentPicker_1.NativeDocumentPicker.pickDirectory(optionsOverride);
|
|
31
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.releaseSecureAccess = exports.releaseLongTermAccess = void 0;
|
|
4
|
+
const NativeDocumentPicker_1 = require("./spec/NativeDocumentPicker");
|
|
5
|
+
/**
|
|
6
|
+
* Android only - Releases long-term access to the given URIs. There's no need to call this method on iOS - there's no iOS equivalent.
|
|
7
|
+
*
|
|
8
|
+
* See [Android documentation](https://developer.android.com/reference/android/content/ContentResolver#releasePersistableUriPermission(android.net.Uri,%20int)) for more information.
|
|
9
|
+
*/
|
|
10
|
+
const releaseLongTermAccess = async (uris) => {
|
|
11
|
+
return NativeDocumentPicker_1.NativeDocumentPicker.releaseLongTermAccess(uris);
|
|
12
|
+
};
|
|
13
|
+
exports.releaseLongTermAccess = releaseLongTermAccess;
|
|
14
|
+
/**
|
|
15
|
+
* iOS only - Releases (stops) secure access to the given URIs. Use with URIs obtained with Open mode or with the Directory Picker.
|
|
16
|
+
* See [iOS documentation](https://developer.apple.com/documentation/foundation/nsurl/1413736-stopaccessingsecurityscopedresou) for more information.
|
|
17
|
+
* There's no need to call this method on Android - there's no equivalent method on Android.
|
|
18
|
+
* */
|
|
19
|
+
const releaseSecureAccess = async (uris) => {
|
|
20
|
+
return NativeDocumentPicker_1.NativeDocumentPicker.releaseSecureAccess(uris);
|
|
21
|
+
};
|
|
22
|
+
exports.releaseSecureAccess = releaseSecureAccess;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.saveDocuments = saveDocuments;
|
|
4
|
+
const NativeDocumentPicker_1 = require("./spec/NativeDocumentPicker");
|
|
5
|
+
const react_native_1 = require("react-native");
|
|
6
|
+
/**
|
|
7
|
+
* The method for opening a "save as" dialog and saving source file(s) to a new location.
|
|
8
|
+
*
|
|
9
|
+
* On Android, only one file can be saved at a time.
|
|
10
|
+
*
|
|
11
|
+
* @group DocumentPicker
|
|
12
|
+
* */
|
|
13
|
+
async function saveDocuments(options) {
|
|
14
|
+
const writeDocumentResponse = await (async () => {
|
|
15
|
+
if (react_native_1.Platform.OS === 'android') {
|
|
16
|
+
const length = options.sourceUris.length;
|
|
17
|
+
if (length > 1) {
|
|
18
|
+
console.warn(`DocumentPicker.saveDocuments: Android only allows to save one file at a time.\n
|
|
19
|
+
You provided an array with ${length} entries.`);
|
|
20
|
+
}
|
|
21
|
+
// making this division into 2 calls might be an overkill... but who knows
|
|
22
|
+
const objectWithSingleUri = await NativeDocumentPicker_1.NativeDocumentPicker.saveDocument(options);
|
|
23
|
+
const response = await NativeDocumentPicker_1.NativeDocumentPicker.writeDocuments(objectWithSingleUri);
|
|
24
|
+
return response;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
return NativeDocumentPicker_1.NativeDocumentPicker.writeDocuments(options);
|
|
28
|
+
}
|
|
29
|
+
})();
|
|
30
|
+
return writeDocumentResponse.map(keepOnlySpecifiedFields);
|
|
31
|
+
}
|
|
32
|
+
function keepOnlySpecifiedFields(source) {
|
|
33
|
+
return {
|
|
34
|
+
uri: source.uri,
|
|
35
|
+
name: source.name,
|
|
36
|
+
error: source.error,
|
|
37
|
+
// type: source.type,
|
|
38
|
+
// nativeType: source.nativeType,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.safeValidate = void 0;
|
|
4
|
+
const safeValidate = (requestedTypes, singlePickResult) => {
|
|
5
|
+
const { nativeType } = singlePickResult;
|
|
6
|
+
return requestedTypes.some((it) => nativeTypeMatches(it, nativeType));
|
|
7
|
+
};
|
|
8
|
+
exports.safeValidate = safeValidate;
|
|
9
|
+
const nativeTypeMatches = (requiredType, actualType) => {
|
|
10
|
+
if (requiredType === actualType || requiredType === '*/*') {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
if (actualType === null) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
if (requiredType.endsWith('/*')) {
|
|
17
|
+
const requiredTypeWithoutStar = requiredType.slice(0, -2);
|
|
18
|
+
if (actualType.startsWith(requiredTypeWithoutStar)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"root":["../setup.ts"],"version":"5.6.3"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isErrorWithCode = exports.errorCodes = void 0;
|
|
7
|
+
const OPERATION_CANCELED = 'OPERATION_CANCELED';
|
|
8
|
+
const IN_PROGRESS = 'ASYNC_OP_IN_PROGRESS';
|
|
9
|
+
const UNABLE_TO_OPEN_FILE_TYPE = 'UNABLE_TO_OPEN_FILE_TYPE';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Error codes that can be returned by the module, and are available on the `code` property of the error.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const handleError = (err: unknown) => {
|
|
17
|
+
* if (isErrorWithCode(err)) {
|
|
18
|
+
* switch (err.code) {
|
|
19
|
+
* case errorCodes.IN_PROGRESS:
|
|
20
|
+
* ...
|
|
21
|
+
* break
|
|
22
|
+
* case errorCodes.UNABLE_TO_OPEN_FILE_TYPE:
|
|
23
|
+
* ...
|
|
24
|
+
* break
|
|
25
|
+
* case errorCodes.OPERATION_CANCELED:
|
|
26
|
+
* // ignore
|
|
27
|
+
* break
|
|
28
|
+
* default:
|
|
29
|
+
* console.error(err)
|
|
30
|
+
* }
|
|
31
|
+
* } else {
|
|
32
|
+
* console.error(err)
|
|
33
|
+
* }
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
36
|
+
* */
|
|
37
|
+
const errorCodes = exports.errorCodes = Object.freeze({
|
|
38
|
+
OPERATION_CANCELED,
|
|
39
|
+
IN_PROGRESS,
|
|
40
|
+
UNABLE_TO_OPEN_FILE_TYPE
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* TypeScript helper to check if an object has the `code` property.
|
|
45
|
+
* This is used to avoid `as` casting when you access the `code` property on errors returned by the module.
|
|
46
|
+
*/
|
|
47
|
+
const isErrorWithCode = error => {
|
|
48
|
+
// to account for https://github.com/facebook/react-native/issues/41950
|
|
49
|
+
const isNewArchErrorIOS = typeof error === 'object' && error != null;
|
|
50
|
+
return (error instanceof Error || isNewArchErrorIOS) && 'code' in error;
|
|
51
|
+
};
|
|
52
|
+
exports.isErrorWithCode = isErrorWithCode;
|
|
53
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["OPERATION_CANCELED","IN_PROGRESS","UNABLE_TO_OPEN_FILE_TYPE","errorCodes","exports","Object","freeze","isErrorWithCode","error","isNewArchErrorIOS","Error"],"sourceRoot":"../../src","sources":["errors.ts"],"mappings":";;;;;;AAIA,MAAMA,kBAAkB,GAAG,oBAAoB;AAC/C,MAAMC,WAAW,GAAG,sBAAsB;AAC1C,MAAMC,wBAAwB,GAAG,0BAA0B;;AAE3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,UAAU,GAAAC,OAAA,CAAAD,UAAA,GAAGE,MAAM,CAACC,MAAM,CAAC;EACtCN,kBAAkB;EAClBC,WAAW;EACXC;AACF,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACO,MAAMK,eAAe,GAAIC,KAAU,IAAiC;EACzE;EACA,MAAMC,iBAAiB,GAAG,OAAOD,KAAK,KAAK,QAAQ,IAAIA,KAAK,IAAI,IAAI;EACpE,OAAO,CAACA,KAAK,YAAYE,KAAK,IAAID,iBAAiB,KAAK,MAAM,IAAID,KAAK;AACzE,CAAC;AAAAJ,OAAA,CAAAG,eAAA,GAAAA,eAAA","ignoreList":[]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.typesAreEqual = exports.types = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
// TODO split this into platform-specific files, and / or topic-specific files
|
|
9
|
+
|
|
10
|
+
const mimeTypes = Object.freeze({
|
|
11
|
+
allFiles: '*/*',
|
|
12
|
+
audio: 'audio/*',
|
|
13
|
+
csv: ['text/csv', 'text/comma-separated-values'],
|
|
14
|
+
doc: 'application/msword',
|
|
15
|
+
docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
16
|
+
images: 'image/*',
|
|
17
|
+
pdf: 'application/pdf',
|
|
18
|
+
plainText: 'text/plain',
|
|
19
|
+
json: 'application/json',
|
|
20
|
+
ppt: 'application/vnd.ms-powerpoint',
|
|
21
|
+
pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
22
|
+
video: 'video/*',
|
|
23
|
+
xls: 'application/vnd.ms-excel',
|
|
24
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
25
|
+
zip: 'application/zip'
|
|
26
|
+
}); //satisfies TypeOfFileTypes
|
|
27
|
+
|
|
28
|
+
const utis = Object.freeze({
|
|
29
|
+
allFiles: 'public.item',
|
|
30
|
+
audio: 'public.audio',
|
|
31
|
+
csv: 'public.comma-separated-values-text',
|
|
32
|
+
doc: 'com.microsoft.word.doc',
|
|
33
|
+
docx: 'org.openxmlformats.wordprocessingml.document',
|
|
34
|
+
images: 'public.image',
|
|
35
|
+
pdf: 'com.adobe.pdf',
|
|
36
|
+
plainText: 'public.plain-text',
|
|
37
|
+
json: 'public.json',
|
|
38
|
+
ppt: 'com.microsoft.powerpoint.ppt',
|
|
39
|
+
pptx: 'org.openxmlformats.presentationml.presentation',
|
|
40
|
+
video: 'public.movie',
|
|
41
|
+
xls: 'com.microsoft.excel.xls',
|
|
42
|
+
xlsx: 'org.openxmlformats.spreadsheetml.sheet',
|
|
43
|
+
zip: 'public.zip-archive'
|
|
44
|
+
}); // satisfies TypeOfFileTypes
|
|
45
|
+
|
|
46
|
+
const perPlatformTypes = {
|
|
47
|
+
android: mimeTypes,
|
|
48
|
+
ios: utis,
|
|
49
|
+
// unsupported, but added to make TS happy
|
|
50
|
+
macos: utis,
|
|
51
|
+
windows: mimeTypes,
|
|
52
|
+
web: mimeTypes
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @hidden
|
|
57
|
+
* */
|
|
58
|
+
const types = exports.types = perPlatformTypes[_reactNative.Platform.OS];
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* You'd rarely use this type directly.
|
|
62
|
+
* It represents the predefined file types which are exported as `types` and can be used to limit the kinds of files that can be picked.
|
|
63
|
+
*
|
|
64
|
+
* @example
|
|
65
|
+
* ```ts
|
|
66
|
+
* import {
|
|
67
|
+
* pick,
|
|
68
|
+
* types,
|
|
69
|
+
* } from '@react-native-documents/picker'
|
|
70
|
+
* // ...
|
|
71
|
+
* const result = await pick({
|
|
72
|
+
* type: [types.pdf, types.docx],
|
|
73
|
+
* })
|
|
74
|
+
* ```
|
|
75
|
+
* */
|
|
76
|
+
|
|
77
|
+
// export type PlatformTypes = typeof perPlatformTypes
|
|
78
|
+
|
|
79
|
+
// ensure shapes of platformTypes are the same: https://stackoverflow.com/a/67027347/2070942
|
|
80
|
+
// let me know if there's a nicer way
|
|
81
|
+
|
|
82
|
+
const mimesAndUtisAreEqual = true;
|
|
83
|
+
const typesAreEqual = exports.typesAreEqual = mimesAndUtisAreEqual;
|
|
84
|
+
//# sourceMappingURL=fileTypes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","mimeTypes","Object","freeze","allFiles","audio","csv","doc","docx","images","pdf","plainText","json","ppt","pptx","video","xls","xlsx","zip","utis","perPlatformTypes","android","ios","macos","windows","web","types","exports","Platform","OS","mimesAndUtisAreEqual","typesAreEqual"],"sourceRoot":"../../src","sources":["fileTypes.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAEA;;AAEA,MAAMC,SAAS,GAAGC,MAAM,CAACC,MAAM,CAAC;EAC9BC,QAAQ,EAAE,KAAK;EACfC,KAAK,EAAE,SAAS;EAChBC,GAAG,EAAE,CAAC,UAAU,EAAE,6BAA6B,CAAC;EAChDC,GAAG,EAAE,oBAAoB;EACzBC,IAAI,EAAE,yEAAyE;EAC/EC,MAAM,EAAE,SAAS;EACjBC,GAAG,EAAE,iBAAiB;EACtBC,SAAS,EAAE,YAAY;EACvBC,IAAI,EAAE,kBAAkB;EACxBC,GAAG,EAAE,+BAA+B;EACpCC,IAAI,EAAE,2EAA2E;EACjFC,KAAK,EAAE,SAAS;EAChBC,GAAG,EAAE,0BAA0B;EAC/BC,IAAI,EAAE,mEAAmE;EACzEC,GAAG,EAAE;AACP,CAAU,CAAC,EAAC;;AAEZ,MAAMC,IAAI,GAAGjB,MAAM,CAACC,MAAM,CAAC;EACzBC,QAAQ,EAAE,aAAa;EACvBC,KAAK,EAAE,cAAc;EACrBC,GAAG,EAAE,oCAAoC;EACzCC,GAAG,EAAE,wBAAwB;EAC7BC,IAAI,EAAE,8CAA8C;EACpDC,MAAM,EAAE,cAAc;EACtBC,GAAG,EAAE,eAAe;EACpBC,SAAS,EAAE,mBAAmB;EAC9BC,IAAI,EAAE,aAAa;EACnBC,GAAG,EAAE,8BAA8B;EACnCC,IAAI,EAAE,gDAAgD;EACtDC,KAAK,EAAE,cAAc;EACrBC,GAAG,EAAE,yBAAyB;EAC9BC,IAAI,EAAE,wCAAwC;EAC9CC,GAAG,EAAE;AACP,CAAU,CAAC,EAAC;;AAEZ,MAAME,gBAAgB,GAAG;EACvBC,OAAO,EAAEpB,SAAS;EAClBqB,GAAG,EAAEH,IAAI;EACT;EACAI,KAAK,EAAEJ,IAAI;EACXK,OAAO,EAAEvB,SAAS;EAClBwB,GAAG,EAAExB;AACP,CAAC;;AAED;AACA;AACA;AACO,MAAMyB,KAAK,GAAAC,OAAA,CAAAD,KAAA,GAAGN,gBAAgB,CAACQ,qBAAQ,CAACC,EAAE,CAAC;;AAQlD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;;AAEA;AACA;;AASA,MAAMC,oBAAoE,GAAG,IAAI;AAC1E,MAAMC,aAAa,GAAAJ,OAAA,CAAAI,aAAA,GAAGD,oBAAoB","ignoreList":[]}
|