@nativescript-community/ui-document-picker 1.1.5 → 1.1.9
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/CHANGELOG.md +50 -0
- package/LICENSE +201 -19
- package/README.md +118 -7
- package/index.android.d.ts +22 -0
- package/index.android.js +190 -0
- package/index.android.js.map +1 -0
- package/index.common.d.ts +16 -0
- package/index.common.js +2 -0
- package/index.common.js.map +1 -0
- package/index.d.ts +5 -0
- package/index.ios.d.ts +7 -0
- package/{filepicker.ios.js → index.ios.js} +11 -5
- package/index.ios.js.map +1 -0
- package/package.json +40 -33
- package/platforms/android/AndroidManifest.xml +3 -0
- package/platforms/android/include.gradle +5 -0
- package/platforms/android/java/com/nativescript/documentpicker/FilePath.java +65 -41
- package/references.d.ts +1 -0
- package/typings/android.d.ts +1521 -0
- package/filepicker.android.d.ts +0 -9
- package/filepicker.android.js +0 -63
- package/filepicker.android.js.map +0 -1
- package/filepicker.common.d.ts +0 -5
- package/filepicker.common.js +0 -1
- package/filepicker.common.js.map +0 -1
- package/filepicker.d.ts +0 -4
- package/filepicker.ios.d.ts +0 -3
- package/filepicker.ios.js.map +0 -1
- package/platforms/android/ui_document_picker.aar +0 -0
- package/pnpm-lock.yaml +0 -10
package/index.d.ts
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
import { FilePickerOptions, FolderPickerOptions } from './index.common';
|
2
|
+
|
3
|
+
export { FilePickerOptions, FolderPickerOptions };
|
4
|
+
export function openFilePicker(params?: FilePickerOptions): Promise<{ files: string[]; ios?; android? }>;
|
5
|
+
export function pickFolder(params?: FolderPickerOptions): Promise<{ folders: string[]; ios?; android? }>;
|
package/index.ios.d.ts
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
import { FolderPickerOptions } from '.';
|
2
|
+
import { FilePickerOptions } from './index.common';
|
3
|
+
export { FilePickerOptions };
|
4
|
+
export declare function openFilePicker(params: FilePickerOptions): Promise<unknown>;
|
5
|
+
export declare function pickFolder(params?: FolderPickerOptions): Promise<{
|
6
|
+
folders: any[];
|
7
|
+
}>;
|
@@ -14,11 +14,12 @@ var DocumentPickerDelegate = /** @class */ (function (_super) {
|
|
14
14
|
this._resolve = null;
|
15
15
|
this._reject = null;
|
16
16
|
controller.delegate = null;
|
17
|
+
delegate = null;
|
17
18
|
};
|
18
19
|
DocumentPickerDelegate.prototype.documentPickerDidPickDocumentAtURL = function (controller, url) {
|
19
20
|
this._resolve({
|
20
21
|
files: [url.absoluteString],
|
21
|
-
ios: url
|
22
|
+
ios: url
|
22
23
|
});
|
23
24
|
this.cleanup(controller);
|
24
25
|
};
|
@@ -29,25 +30,25 @@ var DocumentPickerDelegate = /** @class */ (function (_super) {
|
|
29
30
|
}
|
30
31
|
this._resolve({
|
31
32
|
files: output,
|
32
|
-
ios: urls
|
33
|
+
ios: urls
|
33
34
|
});
|
34
35
|
this.cleanup(controller);
|
35
36
|
};
|
36
37
|
DocumentPickerDelegate.prototype.documentPickerWasCancelled = function (controller) {
|
37
38
|
this._resolve({
|
38
|
-
files: []
|
39
|
+
files: []
|
39
40
|
});
|
40
41
|
this.cleanup(controller);
|
41
42
|
};
|
42
43
|
DocumentPickerDelegate.ObjCProtocols = [UIDocumentPickerDelegate];
|
43
44
|
return DocumentPickerDelegate;
|
44
45
|
}(NSObject));
|
46
|
+
let delegate;
|
45
47
|
export function openFilePicker(params) {
|
46
48
|
let documentTypes;
|
47
49
|
if (params.extensions && params.extensions.length > 0) {
|
48
50
|
documentTypes = Utils.ios.collections.jsArrayToNSArray(params.extensions);
|
49
51
|
}
|
50
|
-
let delegate;
|
51
52
|
return new Promise((resolve, reject) => {
|
52
53
|
const controller = UIDocumentPickerViewController.alloc().initWithDocumentTypesInMode(documentTypes, params.pickerMode !== undefined ? params.pickerMode : 0);
|
53
54
|
delegate = DocumentPickerDelegate.initWithResolveReject(resolve, reject);
|
@@ -59,4 +60,9 @@ export function openFilePicker(params) {
|
|
59
60
|
visibleVC.presentViewControllerAnimatedCompletion(controller, true, null);
|
60
61
|
});
|
61
62
|
}
|
62
|
-
|
63
|
+
export async function pickFolder(params = {}) {
|
64
|
+
return {
|
65
|
+
folders: []
|
66
|
+
};
|
67
|
+
}
|
68
|
+
//# sourceMappingURL=index.ios.js.map
|
package/index.ios.js.map
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.ios.js","sourceRoot":"../src/","sources":["index.ios.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuD3C,IAAI,QAAQ,CAAC;AACb,MAAM,UAAU,cAAc,CAAC,MAAyB;IAEpD,IAAI,aAAa,CAAC;IAElB,IAAI,MAAM,CAAC,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,EAAE;QACnD,aAAa,GAAG,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,gBAAgB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;KAC7E;IAED,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACnC,MAAM,UAAU,GAAG,8BAA8B,CAAC,KAAK,EAAE,CAAC,2BAA2B,CACjF,aAAa,EACb,MAAM,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,EAA4B,CACpF,CAAC;QACF,QAAQ,GAAG,sBAAsB,CAAC,qBAAqB,CAAC,OAAO,EAAE,MAAM,CAAQ,CAAC;QAChF,UAAU,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAG/B,UAAU,CAAC,uBAAuB,GAAG,CAAC,CAAC,MAAM,CAAC,iBAAiB,CAAC;QAIhE,MAAM,GAAG,GAAG,aAAa,CAAC,iBAAiB,CAAC;QAC5C,MAAM,MAAM,GAAG,GAAG,CAAC,SAAS,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,KAAK,GAAG,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1E,MAAM,SAAS,GAAG,KAAK,CAAC,GAAG,CAAC,wBAAwB,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAChF,SAAS,CAAC,uCAAuC,CAAC,UAAU,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;AACP,CAAC;AACD,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,SAA8B,EAAE;IAC7D,OAAO;QACH,OAAO,EAAE,EAAE;KACd,CAAC;AACN,CAAC"}
|
package/package.json
CHANGED
@@ -1,35 +1,42 @@
|
|
1
1
|
{
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
"
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
"
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
"
|
33
|
-
|
34
|
-
|
2
|
+
"name": "@nativescript-community/ui-document-picker",
|
3
|
+
"version": "1.1.9",
|
4
|
+
"description": "A NativeScript plugin that allows you to select files from the device.",
|
5
|
+
"main": "index",
|
6
|
+
"typings": "index.d.ts",
|
7
|
+
"sideEffects": false,
|
8
|
+
"scripts": {
|
9
|
+
"build": "npm run tsc && npm run readme",
|
10
|
+
"readme": "../../node_modules/.bin/readme generate -c ../../tools/readme/blueprint.json",
|
11
|
+
"tsc": "../../node_modules/.bin/cpy '**/*.d.ts' '../../packages/ui-document-picker' --parents --cwd=../../src/ui-document-picker && ../../node_modules/.bin/tsc -skipLibCheck -d",
|
12
|
+
"clean": "../../node_modules/.bin/rimraf ./*.d.ts ./*.js ./*.js.map"
|
13
|
+
},
|
14
|
+
"nativescript": {
|
15
|
+
"platforms": {
|
16
|
+
"android": "6.0.0",
|
17
|
+
"ios": "6.0.0"
|
18
|
+
}
|
19
|
+
},
|
20
|
+
"keywords": [
|
21
|
+
"NativeScript",
|
22
|
+
"JavaScript",
|
23
|
+
"Android",
|
24
|
+
"iOS",
|
25
|
+
"vue",
|
26
|
+
"vue.js"
|
27
|
+
],
|
28
|
+
"author": {
|
29
|
+
"name": "Martin Guillon",
|
30
|
+
"email": "martin@akylas.fr"
|
31
|
+
},
|
32
|
+
"bugs": {
|
33
|
+
"url": "https://github.com/nativescript-community/ui-document-picker/issues"
|
34
|
+
},
|
35
|
+
"repository": {
|
36
|
+
"type": "git",
|
37
|
+
"url": "https://github.com/nativescript-community/ui-document-picker"
|
38
|
+
},
|
39
|
+
"license": "Apache-2.0",
|
40
|
+
"readmeFilename": "README.md",
|
41
|
+
"gitHead": "1fce752aa083808c2949ae602a81122724fddd0a"
|
35
42
|
}
|
@@ -4,7 +4,6 @@ import android.text.TextUtils;
|
|
4
4
|
import android.Manifest;
|
5
5
|
import android.content.ContentUris;
|
6
6
|
import android.content.Context;
|
7
|
-
import android.content.pm.PackageManager;
|
8
7
|
import android.net.Uri;
|
9
8
|
import android.provider.OpenableColumns;
|
10
9
|
import android.util.Log;
|
@@ -14,10 +13,6 @@ import android.os.Environment;
|
|
14
13
|
import android.provider.DocumentsContract;
|
15
14
|
import android.provider.MediaStore;
|
16
15
|
|
17
|
-
import org.json.JSONArray;
|
18
|
-
import org.json.JSONObject;
|
19
|
-
import org.json.JSONException;
|
20
|
-
|
21
16
|
import java.io.FileOutputStream;
|
22
17
|
import java.io.InputStream;
|
23
18
|
import java.util.List;
|
@@ -39,32 +34,6 @@ public class FilePath {
|
|
39
34
|
public static final String READ = Manifest.permission.READ_EXTERNAL_STORAGE;
|
40
35
|
|
41
36
|
|
42
|
-
|
43
|
-
// public static String resolveNativePath() throws JSONException {
|
44
|
-
// /* content:///... */
|
45
|
-
// Uri pvUrl = Uri.parse(this.uriStr);
|
46
|
-
|
47
|
-
// Log.d(TAG, "URI: " + this.uriStr);
|
48
|
-
|
49
|
-
// Context appContext = this.cordova.getActivity().getApplicationContext();
|
50
|
-
// String filePath = getPath(appContext, pvUrl);
|
51
|
-
|
52
|
-
// //check result; send error/success callback
|
53
|
-
// if (filePath == GET_PATH_ERROR_ID) {
|
54
|
-
|
55
|
-
// throw new java.lang.Exception("Unable to resolve filesystem path");
|
56
|
-
// }
|
57
|
-
// else if (filePath.equals(GET_CLOUD_PATH_ERROR_ID)) {
|
58
|
-
|
59
|
-
// throw new java.lang.Exception("Files from cloud cannot be resolved to filesystem, download is required");
|
60
|
-
// }
|
61
|
-
// else {
|
62
|
-
// Log.d(TAG, "Filepath: " + filePath);
|
63
|
-
|
64
|
-
// return "file://" + filePath;
|
65
|
-
// }
|
66
|
-
// }
|
67
|
-
|
68
37
|
/**
|
69
38
|
* @param uri The Uri to check.
|
70
39
|
* @return Whether the Uri authority is ExternalStorageProvider.
|
@@ -131,6 +100,39 @@ public class FilePath {
|
|
131
100
|
if (cursor != null && cursor.moveToFirst()) {
|
132
101
|
final int column_index = cursor.getColumnIndexOrThrow(column);
|
133
102
|
return cursor.getString(column_index);
|
103
|
+
} else if (!cursor.moveToFirst()){
|
104
|
+
return getMediaStore(context, uri, null, null);
|
105
|
+
}
|
106
|
+
} finally {
|
107
|
+
if (cursor != null)
|
108
|
+
cursor.close();
|
109
|
+
}
|
110
|
+
return null;
|
111
|
+
}
|
112
|
+
|
113
|
+
/**
|
114
|
+
* Get the value of the data column for this Uri. This is useful for
|
115
|
+
* MediaStore Uris, and other file-based ContentProviders.
|
116
|
+
*
|
117
|
+
* @param context The context.
|
118
|
+
* @param uri The Uri to query.
|
119
|
+
* @param selection (Optional) Filter used in the query.
|
120
|
+
* @param selectionArgs (Optional) Selection arguments used in the query.
|
121
|
+
* @return The value of the _data column, which is typically a file path.
|
122
|
+
*/
|
123
|
+
private static String getMediaStore(Context context, Uri uri, String selection,
|
124
|
+
String[] selectionArgs) {
|
125
|
+
|
126
|
+
Cursor cursor = null;
|
127
|
+
final String[] projection = {
|
128
|
+
android.provider.MediaStore.Files.FileColumns.DISPLAY_NAME
|
129
|
+
};
|
130
|
+
try {
|
131
|
+
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
|
132
|
+
null);
|
133
|
+
if (cursor != null && cursor.moveToFirst()) {
|
134
|
+
final int column_index = cursor.getColumnIndexOrThrow(android.provider.MediaStore.Files.FileColumns.DISPLAY_NAME);
|
135
|
+
return cursor.getString(column_index);
|
134
136
|
}
|
135
137
|
} finally {
|
136
138
|
if (cursor != null)
|
@@ -207,6 +209,11 @@ public class FilePath {
|
|
207
209
|
return fullPath;
|
208
210
|
}
|
209
211
|
|
212
|
+
fullPath = "/storage/" + type + relativePath;
|
213
|
+
if (fileExists(fullPath)) {
|
214
|
+
return fullPath;
|
215
|
+
}
|
216
|
+
|
210
217
|
return fullPath;
|
211
218
|
}
|
212
219
|
|
@@ -225,6 +232,7 @@ public class FilePath {
|
|
225
232
|
|
226
233
|
Log.d(TAG, "File - " +
|
227
234
|
"Authority: " + uri.getAuthority() +
|
235
|
+
", Path: " + uri.getPath() +
|
228
236
|
", Fragment: " + uri.getFragment() +
|
229
237
|
", Port: " + uri.getPort() +
|
230
238
|
", Query: " + uri.getQuery() +
|
@@ -237,6 +245,7 @@ public class FilePath {
|
|
237
245
|
|
238
246
|
// DocumentProvider
|
239
247
|
if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) {
|
248
|
+
|
240
249
|
// ExternalStorageProvider
|
241
250
|
if (isExternalStorageDocument(uri)) {
|
242
251
|
final String docId = DocumentsContract.getDocumentId(uri);
|
@@ -259,20 +268,23 @@ public class FilePath {
|
|
259
268
|
cursor = context.getContentResolver().query(uri, new String[]{MediaStore.MediaColumns.DISPLAY_NAME}, null, null, null);
|
260
269
|
if (cursor != null && cursor.moveToFirst()) {
|
261
270
|
String fileName = cursor.getString(0);
|
262
|
-
String
|
271
|
+
String folders = android.os.Environment.getExternalStoragePublicDirectory(
|
272
|
+
android.os.Environment.DIRECTORY_DOWNLOADS
|
273
|
+
).getAbsolutePath();
|
274
|
+
String path = folders + "/" + fileName;
|
263
275
|
if (!TextUtils.isEmpty(path)) {
|
264
276
|
return path;
|
265
277
|
}
|
266
278
|
}
|
267
279
|
} finally {
|
268
280
|
if (cursor != null)
|
269
|
-
|
281
|
+
cursor.close();
|
270
282
|
}
|
271
283
|
//
|
272
284
|
final String id = DocumentsContract.getDocumentId(uri);
|
273
285
|
try {
|
274
286
|
final Uri contentUri = ContentUris.withAppendedId(
|
275
|
-
|
287
|
+
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
|
276
288
|
|
277
289
|
return getDataColumn(context, contentUri, null, null);
|
278
290
|
} catch(NumberFormatException e) {
|
@@ -282,10 +294,12 @@ public class FilePath {
|
|
282
294
|
}
|
283
295
|
// MediaProvider
|
284
296
|
else if (isMediaDocument(uri)) {
|
297
|
+
|
285
298
|
final String docId = DocumentsContract.getDocumentId(uri);
|
286
299
|
final String[] split = docId.split(":");
|
287
300
|
final String type = split[0];
|
288
301
|
|
302
|
+
Log.i(TAG, type);
|
289
303
|
Uri contentUri = null;
|
290
304
|
if ("image".equals(type)) {
|
291
305
|
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
@@ -293,6 +307,8 @@ public class FilePath {
|
|
293
307
|
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
294
308
|
} else if ("audio".equals(type)) {
|
295
309
|
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
310
|
+
} else {
|
311
|
+
contentUri = MediaStore.Files.getContentUri("external");
|
296
312
|
}
|
297
313
|
|
298
314
|
final String selection = "_id=?";
|
@@ -300,7 +316,11 @@ public class FilePath {
|
|
300
316
|
split[1]
|
301
317
|
};
|
302
318
|
|
303
|
-
|
319
|
+
try {
|
320
|
+
return getDataColumn(context, contentUri, selection, selectionArgs);
|
321
|
+
} catch (Exception e) {
|
322
|
+
return getMediaStore(context, contentUri, null, null);
|
323
|
+
}
|
304
324
|
}
|
305
325
|
else if(isGoogleDriveUri(uri)){
|
306
326
|
return getDriveFilePath(uri,context);
|
@@ -308,7 +328,6 @@ public class FilePath {
|
|
308
328
|
}
|
309
329
|
// MediaStore (and general)
|
310
330
|
else if ("content".equalsIgnoreCase(uri.getScheme())) {
|
311
|
-
|
312
331
|
// Return the remote address
|
313
332
|
if (isGooglePhotosUri(uri)) {
|
314
333
|
String contentPath = getContentFromSegments(uri.getPathSegments());
|
@@ -321,10 +340,15 @@ public class FilePath {
|
|
321
340
|
}
|
322
341
|
|
323
342
|
if(isGoogleDriveUri(uri)){
|
343
|
+
Log.i(TAG, "4");
|
324
344
|
return getDriveFilePath(uri,context);
|
325
345
|
}
|
326
346
|
|
327
|
-
|
347
|
+
try {
|
348
|
+
return getDataColumn(context, uri, null, null);
|
349
|
+
} catch (Exception ex) {
|
350
|
+
return getMediaStore(context, uri, null, null);
|
351
|
+
}
|
328
352
|
}
|
329
353
|
// File
|
330
354
|
else if ("file".equalsIgnoreCase(uri.getScheme())) {
|
@@ -338,10 +362,10 @@ public class FilePath {
|
|
338
362
|
Uri returnUri =uri;
|
339
363
|
Cursor returnCursor = context.getContentResolver().query(returnUri, null, null, null, null);
|
340
364
|
/*
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
365
|
+
* Get the column indexes of the data in the Cursor,
|
366
|
+
* * move to the first row in the Cursor, get the data,
|
367
|
+
* * and display it.
|
368
|
+
* */
|
345
369
|
int nameIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
346
370
|
int sizeIndex = returnCursor.getColumnIndex(OpenableColumns.SIZE);
|
347
371
|
returnCursor.moveToFirst();
|
package/references.d.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/// <reference path="./typings/android.d.ts" />
|