@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.
Files changed (139) hide show
  1. package/LICENSE.md +21 -0
  2. package/android/.gradle/8.9/checksums/checksums.lock +0 -0
  3. package/android/.gradle/8.9/dependencies-accessors/gc.properties +0 -0
  4. package/android/.gradle/8.9/fileChanges/last-build.bin +0 -0
  5. package/android/.gradle/8.9/fileHashes/fileHashes.lock +0 -0
  6. package/android/.gradle/8.9/gc.properties +0 -0
  7. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  8. package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
  9. package/android/.gradle/vcs-1/gc.properties +0 -0
  10. package/android/build.gradle +80 -0
  11. package/android/src/main/AndroidManifest.xml +3 -0
  12. package/android/src/main/java/com/reactnativedocumentpicker/CopyDestination.kt +12 -0
  13. package/android/src/main/java/com/reactnativedocumentpicker/DocumentMetadataBuilder.kt +79 -0
  14. package/android/src/main/java/com/reactnativedocumentpicker/FileOperations.kt +203 -0
  15. package/android/src/main/java/com/reactnativedocumentpicker/IntentFactory.kt +36 -0
  16. package/android/src/main/java/com/reactnativedocumentpicker/IsKnownTypeImpl.kt +40 -0
  17. package/android/src/main/java/com/reactnativedocumentpicker/MetadataGetter.kt +150 -0
  18. package/android/src/main/java/com/reactnativedocumentpicker/PickOptions.kt +63 -0
  19. package/android/src/main/java/com/reactnativedocumentpicker/PromiseWrapper.java +105 -0
  20. package/android/src/main/java/com/reactnativedocumentpicker/RNDocumentPickerModule.kt +352 -0
  21. package/android/src/main/java/com/reactnativedocumentpicker/RNDocumentPickerPackage.java +49 -0
  22. package/android/src/paper/java/com/reactnativedocumentpicker/NativeDocumentPickerSpec.java +69 -0
  23. package/ios/RCTConvert+RNDocumentPicker.h +8 -0
  24. package/ios/RCTConvert+RNDocumentPicker.mm +16 -0
  25. package/ios/RNDocumentPicker.h +19 -0
  26. package/ios/RNDocumentPicker.mm +128 -0
  27. package/ios/swift/DocPicker.swift +84 -0
  28. package/ios/swift/DocSaver.swift +41 -0
  29. package/ios/swift/DocumentMetadataBuilder.swift +69 -0
  30. package/ios/swift/FileOperations.swift +68 -0
  31. package/ios/swift/IsKnownTypeImpl.swift +42 -0
  32. package/ios/swift/LocalCopyResponse.swift +27 -0
  33. package/ios/swift/PickerBase.swift +78 -0
  34. package/ios/swift/PickerOptions.swift +44 -0
  35. package/ios/swift/PromiseSupport.swift +2 -0
  36. package/ios/swift/PromiseWrapper.swift +92 -0
  37. package/ios/swift/SaverOptions.swift +30 -0
  38. package/jest/build/jest/setup.js +70 -0
  39. package/jest/build/src/errors.js +47 -0
  40. package/jest/build/src/fileTypes.js +53 -0
  41. package/jest/build/src/index.js +22 -0
  42. package/jest/build/src/isKnownType.js +16 -0
  43. package/jest/build/src/keepLocalCopy.js +17 -0
  44. package/jest/build/src/pick.js +50 -0
  45. package/jest/build/src/pickDirectory.js +31 -0
  46. package/jest/build/src/release.js +22 -0
  47. package/jest/build/src/saveDocuments.js +40 -0
  48. package/jest/build/src/spec/NativeDocumentPicker.js +5 -0
  49. package/jest/build/src/types.js +4 -0
  50. package/jest/build/src/validateTypes.js +23 -0
  51. package/jest/build/tsconfig.tsbuildinfo +1 -0
  52. package/lib/commonjs/errors.js +53 -0
  53. package/lib/commonjs/errors.js.map +1 -0
  54. package/lib/commonjs/fileTypes.js +84 -0
  55. package/lib/commonjs/fileTypes.js.map +1 -0
  56. package/lib/commonjs/index.js +74 -0
  57. package/lib/commonjs/index.js.map +1 -0
  58. package/lib/commonjs/isKnownType.js +27 -0
  59. package/lib/commonjs/isKnownType.js.map +1 -0
  60. package/lib/commonjs/keepLocalCopy.js +34 -0
  61. package/lib/commonjs/keepLocalCopy.js.map +1 -0
  62. package/lib/commonjs/package.json +1 -0
  63. package/lib/commonjs/pick.js +93 -0
  64. package/lib/commonjs/pick.js.map +1 -0
  65. package/lib/commonjs/pickDirectory.js +71 -0
  66. package/lib/commonjs/pickDirectory.js.map +1 -0
  67. package/lib/commonjs/release.js +31 -0
  68. package/lib/commonjs/release.js.map +1 -0
  69. package/lib/commonjs/saveDocuments.js +55 -0
  70. package/lib/commonjs/saveDocuments.js.map +1 -0
  71. package/lib/commonjs/spec/NativeDocumentPicker.js +16 -0
  72. package/lib/commonjs/spec/NativeDocumentPicker.js.map +1 -0
  73. package/lib/commonjs/types.js +37 -0
  74. package/lib/commonjs/types.js.map +1 -0
  75. package/lib/commonjs/validateTypes.js +29 -0
  76. package/lib/commonjs/validateTypes.js.map +1 -0
  77. package/lib/module/errors.js +48 -0
  78. package/lib/module/errors.js.map +1 -0
  79. package/lib/module/fileTypes.js +81 -0
  80. package/lib/module/fileTypes.js.map +1 -0
  81. package/lib/module/index.js +13 -0
  82. package/lib/module/index.js.map +1 -0
  83. package/lib/module/isKnownType.js +24 -0
  84. package/lib/module/isKnownType.js.map +1 -0
  85. package/lib/module/keepLocalCopy.js +31 -0
  86. package/lib/module/keepLocalCopy.js.map +1 -0
  87. package/lib/module/package.json +1 -0
  88. package/lib/module/pick.js +90 -0
  89. package/lib/module/pick.js.map +1 -0
  90. package/lib/module/pickDirectory.js +68 -0
  91. package/lib/module/pickDirectory.js.map +1 -0
  92. package/lib/module/release.js +26 -0
  93. package/lib/module/release.js.map +1 -0
  94. package/lib/module/saveDocuments.js +52 -0
  95. package/lib/module/saveDocuments.js.map +1 -0
  96. package/lib/module/spec/NativeDocumentPicker.js +13 -0
  97. package/lib/module/spec/NativeDocumentPicker.js.map +1 -0
  98. package/lib/module/types.js +33 -0
  99. package/lib/module/types.js.map +1 -0
  100. package/lib/module/validateTypes.js +24 -0
  101. package/lib/module/validateTypes.js.map +1 -0
  102. package/lib/typescript/errors.d.ts +40 -0
  103. package/lib/typescript/errors.d.ts.map +1 -0
  104. package/lib/typescript/fileTypes.d.ts +94 -0
  105. package/lib/typescript/fileTypes.d.ts.map +1 -0
  106. package/lib/typescript/index.d.ts +13 -0
  107. package/lib/typescript/index.d.ts.map +1 -0
  108. package/lib/typescript/isKnownType.d.ts +41 -0
  109. package/lib/typescript/isKnownType.d.ts.map +1 -0
  110. package/lib/typescript/keepLocalCopy.d.ts +46 -0
  111. package/lib/typescript/keepLocalCopy.d.ts.map +1 -0
  112. package/lib/typescript/pick.d.ts +84 -0
  113. package/lib/typescript/pick.d.ts.map +1 -0
  114. package/lib/typescript/pickDirectory.d.ts +62 -0
  115. package/lib/typescript/pickDirectory.d.ts.map +1 -0
  116. package/lib/typescript/release.d.ts +24 -0
  117. package/lib/typescript/release.d.ts.map +1 -0
  118. package/lib/typescript/saveDocuments.d.ts +55 -0
  119. package/lib/typescript/saveDocuments.d.ts.map +1 -0
  120. package/lib/typescript/spec/NativeDocumentPicker.d.ts +29 -0
  121. package/lib/typescript/spec/NativeDocumentPicker.d.ts.map +1 -0
  122. package/lib/typescript/types.d.ts +95 -0
  123. package/lib/typescript/types.d.ts.map +1 -0
  124. package/lib/typescript/validateTypes.d.ts +3 -0
  125. package/lib/typescript/validateTypes.d.ts.map +1 -0
  126. package/package.json +92 -0
  127. package/react-native-document-picker.podspec +30 -0
  128. package/src/errors.ts +49 -0
  129. package/src/fileTypes.ts +92 -0
  130. package/src/index.ts +47 -0
  131. package/src/isKnownType.ts +48 -0
  132. package/src/keepLocalCopy.ts +51 -0
  133. package/src/pick.ts +151 -0
  134. package/src/pickDirectory.ts +93 -0
  135. package/src/release.ts +36 -0
  136. package/src/saveDocuments.ts +99 -0
  137. package/src/spec/NativeDocumentPicker.ts +31 -0
  138. package/src/types.ts +119 -0
  139. 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
+ }