@crossbind/extension-page-files 0.0.0-stage → 2.0.0-beta.69
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 +21 -0
- package/README.md +18 -2
- package/crossbind.extension.js +11 -0
- package/native/android/dev/crossbind/extension/pagefiles/PageFilesExtension.java +47 -0
- package/native/darwin.mm +33 -0
- package/package.json +26 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Buğra Sarı and crossbind contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @crossbind/extension-page-files
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The system's picker for a page's file input, on macOS and Android.
|
|
4
|
+
|
|
5
|
+
An app has it by having `@crossbind/core-app-host`, which lists it as a dependency: there is nothing to install or list.
|
|
6
|
+
|
|
7
|
+
## What it does
|
|
8
|
+
|
|
9
|
+
A page's file input opens the system's picker, with the types and the multiple choice the input asks for.
|
|
10
|
+
|
|
11
|
+
## Platforms
|
|
12
|
+
|
|
13
|
+
macOS and Android; the other webviews show their own picker.
|
|
14
|
+
|
|
15
|
+
## Replace or leave out
|
|
16
|
+
|
|
17
|
+
It holds the role `page-files`. An extension that gives `replaces: 'page-files'` takes it; `app: { without: ['page-files'] }` in `crossbind.config.js` leaves it out. [The guide](https://crossbind.dev/guide/extensions/#replace) shows how, and [extensions.md](https://github.com/crossbind/crossbind/blob/main/docs/api/extensions.md#the-hosts-own-extensions) what a replacement answers.
|
|
18
|
+
|
|
19
|
+
[extensions.md](https://github.com/crossbind/crossbind/blob/main/docs/api/extensions.md#the-pages-requests) has the hooks a replacement answers.
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default function pageFiles() {
|
|
2
|
+
return {
|
|
3
|
+
name: 'page-files',
|
|
4
|
+
contract: 1,
|
|
5
|
+
root: import.meta.dirname,
|
|
6
|
+
app: {
|
|
7
|
+
macos: { sources: ['native/darwin.mm'] },
|
|
8
|
+
android: { java: 'native/android', class: 'dev.crossbind.extension.pagefiles.PageFilesExtension' },
|
|
9
|
+
},
|
|
10
|
+
};
|
|
11
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
package dev.crossbind.extension.pagefiles;
|
|
2
|
+
|
|
3
|
+
import android.app.Activity;
|
|
4
|
+
import android.content.ActivityNotFoundException;
|
|
5
|
+
import android.content.ClipData;
|
|
6
|
+
import android.content.Intent;
|
|
7
|
+
import android.net.Uri;
|
|
8
|
+
import android.util.Log;
|
|
9
|
+
|
|
10
|
+
import java.util.ArrayList;
|
|
11
|
+
import java.util.List;
|
|
12
|
+
|
|
13
|
+
import org.json.JSONObject;
|
|
14
|
+
|
|
15
|
+
import dev.crossbind.app.Extension;
|
|
16
|
+
import dev.crossbind.app.ExtensionHost;
|
|
17
|
+
|
|
18
|
+
// The host's page-files on Android: a file input opens the system's picker for its accept types, with several files
|
|
19
|
+
// where the input takes them.
|
|
20
|
+
public final class PageFilesExtension implements Extension {
|
|
21
|
+
@Override
|
|
22
|
+
public void call(ExtensionHost host, String function, JSONObject options, Call call) {
|
|
23
|
+
call.reject("crossbind: page-files has no function " + function);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
@Override
|
|
27
|
+
public void onFileInput(ExtensionHost host, FileInput input) {
|
|
28
|
+
Intent intent = input.params().createIntent();
|
|
29
|
+
if (input.allowsMultiple()) intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
|
|
30
|
+
try {
|
|
31
|
+
host.startForResult(intent, (result, data) -> input.pick(picked(result, data)));
|
|
32
|
+
} catch (ActivityNotFoundException none) {
|
|
33
|
+
Log.w("crossbind", "nothing on this device picks a file");
|
|
34
|
+
input.useDefault();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// What the picker chose, several files as clip data.
|
|
39
|
+
private static Uri[] picked(int result, Intent data) {
|
|
40
|
+
if (result != Activity.RESULT_OK || data == null) return null;
|
|
41
|
+
List<Uri> picked = new ArrayList<>();
|
|
42
|
+
ClipData clip = data.getClipData();
|
|
43
|
+
if (clip == null) picked.add(data.getData());
|
|
44
|
+
else for (int i = 0; i < clip.getItemCount(); i += 1) picked.add(clip.getItemAt(i).getUri());
|
|
45
|
+
return picked.toArray(new Uri[0]);
|
|
46
|
+
}
|
|
47
|
+
}
|
package/native/darwin.mm
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
#import <Cocoa/Cocoa.h>
|
|
2
|
+
|
|
3
|
+
#include "crossbind/extension.h"
|
|
4
|
+
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
// The host's page-files on macOS: a file input's picker, as a sheet on the page's window, which takes folders where the
|
|
9
|
+
// input does. WKWebView tells none of the input's accept types.
|
|
10
|
+
void crossbind_extension_page_files(crossbind::Registry ®istry) {
|
|
11
|
+
registry.onFileInput([](crossbind::FileInput input) {
|
|
12
|
+
NSOpenPanel *panel = [NSOpenPanel openPanel];
|
|
13
|
+
panel.canChooseFiles = YES;
|
|
14
|
+
panel.canChooseDirectories = input.allowsFolders();
|
|
15
|
+
panel.allowsMultipleSelection = input.allowsMultiple();
|
|
16
|
+
void (^done)(NSModalResponse) = ^(NSModalResponse response) {
|
|
17
|
+
if (response != NSModalResponseOK) {
|
|
18
|
+
input.cancel();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
std::vector<std::string> paths;
|
|
22
|
+
for (NSURL *url in panel.URLs) paths.emplace_back(url.path.UTF8String ?: "");
|
|
23
|
+
input.pick(paths);
|
|
24
|
+
};
|
|
25
|
+
const std::optional<crossbind::Window> open = crossbind::windowOf(input.page().windowId());
|
|
26
|
+
NSWindow *window = (__bridge NSWindow *)(open ? open->native() : crossbind::appWindow());
|
|
27
|
+
if (window) {
|
|
28
|
+
[panel beginSheetModalForWindow:window completionHandler:done];
|
|
29
|
+
} else {
|
|
30
|
+
done([panel runModal]);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crossbind/extension-page-files",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "2.0.0-beta.69",
|
|
4
|
+
"description": "crossbind app extension: the system's picker for a page's file input, on macOS and Android.",
|
|
5
|
+
"homepage": "https://github.com/crossbind/crossbind/tree/main/extensions/page-files#readme",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/crossbind/crossbind.git"
|
|
9
|
+
},
|
|
10
|
+
"license": "MIT",
|
|
11
|
+
"type": "module",
|
|
12
|
+
"exports": {
|
|
13
|
+
"./crossbind.extension.js": "./crossbind.extension.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"crossbind.extension.js",
|
|
17
|
+
"native"
|
|
18
|
+
],
|
|
19
|
+
"crossbind": {
|
|
20
|
+
"extension": "./crossbind.extension.js"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"crossbind-extension",
|
|
24
|
+
"crossbind",
|
|
25
|
+
"page",
|
|
26
|
+
"files",
|
|
27
|
+
"app"
|
|
28
|
+
]
|
|
6
29
|
}
|