@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
package/src/types.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
export type NonEmptyArray<T> = [T, ...Array<T>]
|
|
2
|
+
import type { ModalPropsIOS } from 'react-native'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* If you've requested long-term access to a directory or file, this object will be returned in the response.
|
|
6
|
+
* In order to access the same directory or file in the future, you must store the `bookmark` opaque string,
|
|
7
|
+
* and then pass it to the document viewer if you want to preview the file.
|
|
8
|
+
*
|
|
9
|
+
* See the Document viewer source on how to retrieve the file from the bookmark, if you need to do that (advanced use case).
|
|
10
|
+
* */
|
|
11
|
+
export type BookmarkingResponse =
|
|
12
|
+
| {
|
|
13
|
+
bookmarkStatus: 'success'
|
|
14
|
+
bookmark: string
|
|
15
|
+
}
|
|
16
|
+
| {
|
|
17
|
+
bookmarkStatus: 'error'
|
|
18
|
+
bookmarkError: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @group pick() types
|
|
23
|
+
*/
|
|
24
|
+
export type VirtualFileMeta = {
|
|
25
|
+
/**
|
|
26
|
+
* The registered extension for the given MIME type. Note that some MIME types map to multiple extensions.
|
|
27
|
+
*
|
|
28
|
+
* This call will return the most common extension for the given MIME type.
|
|
29
|
+
*
|
|
30
|
+
* Example: `pdf`
|
|
31
|
+
*/
|
|
32
|
+
extension: string | null
|
|
33
|
+
/**
|
|
34
|
+
* The MIME type of the file. This is necessary to export the virtual file to a local file.
|
|
35
|
+
*
|
|
36
|
+
* Example: `application/pdf`
|
|
37
|
+
*/
|
|
38
|
+
mimeType: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* @group pick() types
|
|
43
|
+
*/
|
|
44
|
+
export type DocumentPickerResponse = {
|
|
45
|
+
/**
|
|
46
|
+
* The URI of the picked file. This is a percent-encoded `content://` uri (Android), or a `file://` uri (iOS).
|
|
47
|
+
* */
|
|
48
|
+
uri: string
|
|
49
|
+
/**
|
|
50
|
+
* The name of the picked file, including the extension. It's very unlikely that it'd be `null` but in theory, it can happen.
|
|
51
|
+
* */
|
|
52
|
+
name: string | null
|
|
53
|
+
/**
|
|
54
|
+
* Error in case the file metadata could not be obtained.
|
|
55
|
+
* */
|
|
56
|
+
error: string | null
|
|
57
|
+
/**
|
|
58
|
+
* The MIME type of the picked file.
|
|
59
|
+
* */
|
|
60
|
+
type: string | null
|
|
61
|
+
/**
|
|
62
|
+
* The "native" type of the picked file: on Android, this is the MIME type. On iOS, it is the UTType identifier.
|
|
63
|
+
* */
|
|
64
|
+
nativeType: string | null
|
|
65
|
+
/**
|
|
66
|
+
* The size of the picked file in bytes.
|
|
67
|
+
* */
|
|
68
|
+
size: number | null
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Android: whether the file is a virtual file (such as Google docs or sheets). Will be `null` on pre-Android 7.0 devices. On iOS, it's always `false`.
|
|
72
|
+
* */
|
|
73
|
+
isVirtual: boolean | null
|
|
74
|
+
/**
|
|
75
|
+
* Android: The target types the virtual file can be converted to. Useful for {@link keepLocalCopy}.
|
|
76
|
+
* This field is only present if `isVirtual` is true, and only on Android 7.0+. Always `null` on iOS.
|
|
77
|
+
* */
|
|
78
|
+
convertibleToMimeTypes: VirtualFileMeta[] | null
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Android: Some document providers on Android (especially those popular in Asia, it seems)
|
|
82
|
+
* do not respect the request for limiting selectable file types.
|
|
83
|
+
* `hasRequestedType` will be false if the user picked a file that does not have one of the requested types.
|
|
84
|
+
*
|
|
85
|
+
* You need to do your own post-processing and display an error to the user if this is important to your app.
|
|
86
|
+
*
|
|
87
|
+
* Always `true` on iOS.
|
|
88
|
+
* */
|
|
89
|
+
hasRequestedType: boolean
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* iOS only. Configure the transition style of the picker.
|
|
94
|
+
* */
|
|
95
|
+
export type TransitionStyle =
|
|
96
|
+
| 'coverVertical'
|
|
97
|
+
| 'flipHorizontal'
|
|
98
|
+
| 'crossDissolve'
|
|
99
|
+
| 'partialCurl'
|
|
100
|
+
| undefined
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* iOS only. Configure the presentation style of the picker.
|
|
104
|
+
* */
|
|
105
|
+
export type PresentationStyle =
|
|
106
|
+
| 'fullScreen'
|
|
107
|
+
| 'pageSheet'
|
|
108
|
+
| 'formSheet'
|
|
109
|
+
| 'overFullScreen'
|
|
110
|
+
| undefined
|
|
111
|
+
/*
|
|
112
|
+
* really, PresentationStyle shouldn't be here and we should just use ModalPropsIOS['presentationStyle']>
|
|
113
|
+
* but I'm not sure how to get that working with TypeDoc producing a nice output so we duplicate it here
|
|
114
|
+
* */
|
|
115
|
+
|
|
116
|
+
type AreUnionsEqual<T, U> = [T] extends [U] ? ([U] extends [T] ? true : false) : false
|
|
117
|
+
|
|
118
|
+
export const typesAreEqual: AreUnionsEqual<PresentationStyle, ModalPropsIOS['presentationStyle']> =
|
|
119
|
+
true
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { DocumentPickerResponse } from './types'
|
|
2
|
+
|
|
3
|
+
export const safeValidate = (
|
|
4
|
+
requestedTypes: string[],
|
|
5
|
+
singlePickResult: Pick<DocumentPickerResponse, 'nativeType'>,
|
|
6
|
+
) => {
|
|
7
|
+
const { nativeType } = singlePickResult
|
|
8
|
+
return requestedTypes.some((it) => nativeTypeMatches(it, nativeType))
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const nativeTypeMatches = (requiredType: string, actualType: string | null) => {
|
|
12
|
+
if (requiredType === actualType || requiredType === '*/*') {
|
|
13
|
+
return true
|
|
14
|
+
}
|
|
15
|
+
if (actualType === null) {
|
|
16
|
+
return false
|
|
17
|
+
}
|
|
18
|
+
if (requiredType.endsWith('/*')) {
|
|
19
|
+
const requiredTypeWithoutStar = requiredType.slice(0, -2)
|
|
20
|
+
if (actualType.startsWith(requiredTypeWithoutStar)) {
|
|
21
|
+
return true
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return false
|
|
26
|
+
}
|