@octane-xplat/share 0.0.1 → 0.9.0
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 +27 -2
- package/dist/native/index.js +2 -0
- package/dist/native/index2.js +14 -0
- package/dist/native/octane-client-build.json +8 -0
- package/dist/web/index.js +2 -0
- package/dist/web/index2.js +18 -0
- package/dist/web/index3.js +73 -0
- package/dist/web/index4.js +71 -0
- package/dist/web/index5.js +46 -0
- package/dist/web/octane-client-build.json +8 -0
- package/package.json +83 -10
- package/src/index.macos.ts +2 -0
- package/src/index.ts +2 -0
- package/src/index.web.ts +2 -0
- package/src/share.macos.ts +15 -0
- package/src/share.ts +13 -0
- package/src/share.web.ts +44 -0
- package/src/types.ts +10 -0
- package/types/index.d.ts +1 -0
- package/types/index.macos.d.ts +5 -0
- package/types/types.d.ts +8 -0
- package/index.d.ts +0 -1
- package/index.js +0 -2
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Alec Larson
|
|
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
|
|
13
|
+
all 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
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# `@octane-xplat/share`
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The platform share sheet for Octane xplat apps. iOS and Android run
|
|
4
|
+
`@nativescript/social-share`; web calls `navigator.share` where it exists
|
|
5
|
+
(mobile browsers, some desktop) and degrades to a clipboard copy elsewhere
|
|
6
|
+
so the call still does something useful; macOS forwards the payload to the
|
|
7
|
+
AppKit host, which presents `NSSharingServicePicker`.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
pnpm add @octane-xplat/share
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { share } from '@octane-xplat/share'
|
|
15
|
+
|
|
16
|
+
const result = await share.text('Day 3 in Kyoto — 12km walked', 'Trip update')
|
|
17
|
+
const link = await share.url('https://example.com/trips/42', 'My itinerary')
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Both methods resolve a `ShareResult`: `'shared'` when the platform sheet
|
|
21
|
+
completed, `'copied'` when the web fallback put it on the clipboard, and
|
|
22
|
+
`'unavailable'` when no share path exists — branch on the result rather
|
|
23
|
+
than catching.
|
|
24
|
+
|
|
25
|
+
Guide: [Using device features](../../docs/platform-services.md);
|
|
26
|
+
per-target availability: [platform notes](../../docs/platform-notes.md).
|
|
27
|
+
Exercised by the harness `Services` screen
|
|
28
|
+
([`packages/app/src/Services.tsrx`](../app/src/Services.tsrx)).
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { shareText, shareUrl } from "@nativescript/social-share";
|
|
2
|
+
//#region src/share.ts
|
|
3
|
+
var share = {
|
|
4
|
+
async text(text, subject) {
|
|
5
|
+
shareText(text, subject);
|
|
6
|
+
return "shared";
|
|
7
|
+
},
|
|
8
|
+
async url(url, title) {
|
|
9
|
+
shareUrl(url, title ?? url);
|
|
10
|
+
return "shared";
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { share };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//#region ../platform/src/host-bridge.web.ts
|
|
2
|
+
/** Return the native message channel when this page is hosted by a desktop app. */
|
|
3
|
+
function createWebKitTransport() {
|
|
4
|
+
if (typeof window === "undefined") return null;
|
|
5
|
+
const handler = window.webkit?.messageHandlers?.xplat;
|
|
6
|
+
const host = window.__xplatHostTransport;
|
|
7
|
+
if (!handler || !host) return null;
|
|
8
|
+
return {
|
|
9
|
+
postMessage(message) {
|
|
10
|
+
handler.postMessage(message);
|
|
11
|
+
},
|
|
12
|
+
listen(listener) {
|
|
13
|
+
return host.listen(listener);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { createWebKitTransport };
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
//#region ../platform/src/host-protocol.ts
|
|
2
|
+
/**
|
|
3
|
+
* Create the webview-side client. Host methods are typed at compile time; this
|
|
4
|
+
* deliberately does not add runtime schema validation.
|
|
5
|
+
*/
|
|
6
|
+
function createHostClient(transport) {
|
|
7
|
+
const pending = /* @__PURE__ */ new Map();
|
|
8
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
9
|
+
let nextId = 0;
|
|
10
|
+
let disposed = false;
|
|
11
|
+
const removeListener = transport.listen((message) => {
|
|
12
|
+
const packet = JSON.parse(message);
|
|
13
|
+
if (packet.type === "reply") {
|
|
14
|
+
const task = pending.get(packet.id);
|
|
15
|
+
if (!task) return;
|
|
16
|
+
pending.delete(packet.id);
|
|
17
|
+
if (packet.ok) task.resolve(packet.value);
|
|
18
|
+
else task.reject(new Error(packet.error));
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
for (const listener of listeners.get(packet.name) ?? []) listener(packet.payload);
|
|
22
|
+
});
|
|
23
|
+
const request = (value) => {
|
|
24
|
+
if (disposed) return Promise.reject(/* @__PURE__ */ new Error("desktop host client is disposed"));
|
|
25
|
+
const id = ++nextId;
|
|
26
|
+
const promise = new Promise((resolve, reject) => pending.set(id, {
|
|
27
|
+
resolve,
|
|
28
|
+
reject
|
|
29
|
+
}));
|
|
30
|
+
try {
|
|
31
|
+
transport.postMessage(JSON.stringify({
|
|
32
|
+
...value,
|
|
33
|
+
id
|
|
34
|
+
}));
|
|
35
|
+
} catch (error) {
|
|
36
|
+
const task = pending.get(id);
|
|
37
|
+
pending.delete(id);
|
|
38
|
+
task?.reject(error instanceof Error ? error : new Error(String(error)));
|
|
39
|
+
}
|
|
40
|
+
return promise;
|
|
41
|
+
};
|
|
42
|
+
return {
|
|
43
|
+
call: ((service, method, ...args) => request({
|
|
44
|
+
type: "call",
|
|
45
|
+
service,
|
|
46
|
+
method,
|
|
47
|
+
args
|
|
48
|
+
})),
|
|
49
|
+
capabilities() {
|
|
50
|
+
return request({ type: "capabilities" });
|
|
51
|
+
},
|
|
52
|
+
on(name, listener) {
|
|
53
|
+
const eventListeners = listeners.get(name) ?? /* @__PURE__ */ new Set();
|
|
54
|
+
const receive = listener;
|
|
55
|
+
eventListeners.add(receive);
|
|
56
|
+
listeners.set(name, eventListeners);
|
|
57
|
+
return () => {
|
|
58
|
+
eventListeners.delete(receive);
|
|
59
|
+
if (!eventListeners.size) listeners.delete(name);
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
dispose() {
|
|
63
|
+
if (disposed) return;
|
|
64
|
+
disposed = true;
|
|
65
|
+
removeListener();
|
|
66
|
+
listeners.clear();
|
|
67
|
+
for (const task of pending.values()) task.reject(/* @__PURE__ */ new Error("desktop host client is disposed"));
|
|
68
|
+
pending.clear();
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
//#endregion
|
|
73
|
+
export { createHostClient };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createWebKitTransport } from "./index2.js";
|
|
2
|
+
import { createHostClient } from "./index3.js";
|
|
3
|
+
//#region ../platform/src/host-runtime.web.ts
|
|
4
|
+
var client;
|
|
5
|
+
var capabilityTable;
|
|
6
|
+
/** Return the native service client when this page is inside a desktop webview. */
|
|
7
|
+
function desktopHostClient() {
|
|
8
|
+
if (client !== void 0) return client;
|
|
9
|
+
const transport = createWebKitTransport();
|
|
10
|
+
client = transport ? createHostClient(transport) : null;
|
|
11
|
+
return client;
|
|
12
|
+
}
|
|
13
|
+
function desktopHostSupports(service, method) {
|
|
14
|
+
const host = desktopHostClient();
|
|
15
|
+
if (!host) return Promise.resolve(false);
|
|
16
|
+
capabilityTable ??= host.capabilities().catch(() => ({}));
|
|
17
|
+
return capabilityTable.then((capabilities) => capabilities[service]?.includes(method) ?? false);
|
|
18
|
+
}
|
|
19
|
+
/** Typed desktop service facade; null outside a supported native webview. */
|
|
20
|
+
function desktopHost() {
|
|
21
|
+
const host = desktopHostClient();
|
|
22
|
+
if (!host) return null;
|
|
23
|
+
return {
|
|
24
|
+
app: {
|
|
25
|
+
getInfo: () => host.call("app", "getInfo"),
|
|
26
|
+
getState: () => host.call("app", "getState"),
|
|
27
|
+
getWindowSize: () => host.call("app", "getWindowSize"),
|
|
28
|
+
consumeInitialUrl: () => host.call("app", "consumeInitialUrl")
|
|
29
|
+
},
|
|
30
|
+
clipboard: {
|
|
31
|
+
read: () => host.call("clipboard", "read"),
|
|
32
|
+
write: (value) => host.call("clipboard", "write", value)
|
|
33
|
+
},
|
|
34
|
+
files: {
|
|
35
|
+
pick: (accept, options) => host.call("files", "pick", accept, options),
|
|
36
|
+
readText: (uri) => host.call("files", "readText", uri),
|
|
37
|
+
writeText: (name, text) => host.call("files", "writeText", name, text)
|
|
38
|
+
},
|
|
39
|
+
notifications: {
|
|
40
|
+
ensure: () => host.call("notifications", "ensure"),
|
|
41
|
+
notify: (title, body) => host.call("notifications", "notify", title, body)
|
|
42
|
+
},
|
|
43
|
+
secureStorage: {
|
|
44
|
+
get: (key) => host.call("secureStorage", "get", key),
|
|
45
|
+
set: (key, value) => host.call("secureStorage", "set", key, value),
|
|
46
|
+
remove: (key) => host.call("secureStorage", "remove", key)
|
|
47
|
+
},
|
|
48
|
+
appearance: { get: () => host.call("appearance", "get") },
|
|
49
|
+
windows: {
|
|
50
|
+
open: (options) => host.call("windows", "open", options),
|
|
51
|
+
close: (id) => host.call("windows", "close", id),
|
|
52
|
+
setTitle: (id, title) => host.call("windows", "setTitle", id, title)
|
|
53
|
+
},
|
|
54
|
+
system: {
|
|
55
|
+
openUrl: (url) => host.call("system", "openUrl", url),
|
|
56
|
+
openPath: (path) => host.call("system", "openPath", path),
|
|
57
|
+
shareContent: (input) => host.call("system", "shareContent", input)
|
|
58
|
+
},
|
|
59
|
+
storage: {
|
|
60
|
+
get: (key) => host.call("storage", "get", key),
|
|
61
|
+
set: (key, value) => host.call("storage", "set", key, value),
|
|
62
|
+
remove: (key) => host.call("storage", "remove", key)
|
|
63
|
+
},
|
|
64
|
+
capabilities: () => host.capabilities(),
|
|
65
|
+
supports: desktopHostSupports,
|
|
66
|
+
on: (name, listener) => host.on(name, listener),
|
|
67
|
+
dispose: () => host.dispose()
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { desktopHost, desktopHostClient, desktopHostSupports };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { desktopHost, desktopHostSupports } from "./index4.js";
|
|
2
|
+
//#region src/share.web.ts
|
|
3
|
+
var share = {
|
|
4
|
+
async text(text, subject) {
|
|
5
|
+
const host = desktopHost();
|
|
6
|
+
if (host && await desktopHostSupports("system", "shareContent")) return host.system.shareContent({
|
|
7
|
+
text,
|
|
8
|
+
title: subject
|
|
9
|
+
});
|
|
10
|
+
const nav = navigator;
|
|
11
|
+
if (nav.share) {
|
|
12
|
+
await nav.share({
|
|
13
|
+
text,
|
|
14
|
+
title: subject
|
|
15
|
+
});
|
|
16
|
+
return "shared";
|
|
17
|
+
}
|
|
18
|
+
if (nav.clipboard) {
|
|
19
|
+
await nav.clipboard.writeText(text);
|
|
20
|
+
return "copied";
|
|
21
|
+
}
|
|
22
|
+
return "unavailable";
|
|
23
|
+
},
|
|
24
|
+
async url(url, title) {
|
|
25
|
+
const host = desktopHost();
|
|
26
|
+
if (host && await desktopHostSupports("system", "shareContent")) return host.system.shareContent({
|
|
27
|
+
url,
|
|
28
|
+
title
|
|
29
|
+
});
|
|
30
|
+
const nav = navigator;
|
|
31
|
+
if (nav.share) {
|
|
32
|
+
await nav.share({
|
|
33
|
+
url,
|
|
34
|
+
title
|
|
35
|
+
});
|
|
36
|
+
return "shared";
|
|
37
|
+
}
|
|
38
|
+
if (nav.clipboard) {
|
|
39
|
+
await nav.clipboard.writeText(url);
|
|
40
|
+
return "copied";
|
|
41
|
+
}
|
|
42
|
+
return "unavailable";
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
//#endregion
|
|
46
|
+
export { share };
|
package/package.json
CHANGED
|
@@ -1,19 +1,92 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@octane-xplat/share",
|
|
3
|
-
"version": "0.0
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"description": "Native share sheet for Octane xplat — matching web + NativeScript + AppKit implementations",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"android",
|
|
7
|
+
"cross-platform",
|
|
8
|
+
"ios",
|
|
9
|
+
"macos",
|
|
10
|
+
"nativescript",
|
|
11
|
+
"octane",
|
|
12
|
+
"share",
|
|
13
|
+
"share-sheet",
|
|
14
|
+
"social-share",
|
|
15
|
+
"web",
|
|
16
|
+
"xplat"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/share",
|
|
5
19
|
"license": "MIT",
|
|
6
20
|
"repository": {
|
|
7
21
|
"type": "git",
|
|
8
|
-
"url": "https://github.com/octane-xplat/octane-xplat
|
|
22
|
+
"url": "https://github.com/octane-xplat/octane-xplat",
|
|
9
23
|
"directory": "packages/share"
|
|
10
24
|
},
|
|
11
|
-
"homepage": "https://github.com/octane-xplat/octane-xplat/tree/main/packages/share",
|
|
12
|
-
"main": "./index.js",
|
|
13
|
-
"types": "./index.d.ts",
|
|
14
25
|
"files": [
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
]
|
|
19
|
-
|
|
26
|
+
"dist",
|
|
27
|
+
"types",
|
|
28
|
+
"src"
|
|
29
|
+
],
|
|
30
|
+
"type": "module",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"macos": {
|
|
34
|
+
"types": "./types/index.macos.d.ts",
|
|
35
|
+
"default": "./src/index.macos.ts"
|
|
36
|
+
},
|
|
37
|
+
"web": {
|
|
38
|
+
"types": "./types/index.d.ts",
|
|
39
|
+
"default": "./dist/web/index.js"
|
|
40
|
+
},
|
|
41
|
+
"native": {
|
|
42
|
+
"types": "./types/index.d.ts",
|
|
43
|
+
"default": "./dist/native/index.js"
|
|
44
|
+
},
|
|
45
|
+
"types": "./types/index.d.ts",
|
|
46
|
+
"default": "./dist/native/index.js"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
"publishConfig": {
|
|
50
|
+
"access": "public"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"@nativescript/social-share": "2.3.0",
|
|
54
|
+
"@octane-xplat/platform": "0.9.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@nativescript-community/octane": "0.2.4",
|
|
58
|
+
"@nativescript/core": "9.1.2",
|
|
59
|
+
"@octanejs/vite-plugin": "0.1.61",
|
|
60
|
+
"octane": "0.6.3",
|
|
61
|
+
"tsrx-typegen": "0.2.1",
|
|
62
|
+
"typescript": "5.9.3",
|
|
63
|
+
"vite": "8.3.0"
|
|
64
|
+
},
|
|
65
|
+
"peerDependencies": {
|
|
66
|
+
"@nativescript-community/octane": ">=0.2.1 <1",
|
|
67
|
+
"@nativescript/core": ">=9.1.0 <10",
|
|
68
|
+
"octane": ">=0.6.3 <1"
|
|
69
|
+
},
|
|
70
|
+
"peerDependenciesMeta": {
|
|
71
|
+
"@nativescript-community/octane": {
|
|
72
|
+
"optional": true
|
|
73
|
+
},
|
|
74
|
+
"@nativescript/core": {
|
|
75
|
+
"optional": true
|
|
76
|
+
},
|
|
77
|
+
"octane": {
|
|
78
|
+
"optional": true
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
"nativescript": {
|
|
82
|
+
"platforms": {
|
|
83
|
+
"android": "9.1.0",
|
|
84
|
+
"ios": "9.1.0"
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
"scripts": {
|
|
88
|
+
"build": "vite build && vite build --mode native && tsc -p tsconfig.types.json && node ../../scripts/check-native-dist.mjs",
|
|
89
|
+
"test:packed": "node tests/packed-consumer.mjs",
|
|
90
|
+
"pack:check": "tsrx-typegen --pack-check"
|
|
91
|
+
}
|
|
92
|
+
}
|
package/src/index.ts
ADDED
package/src/index.web.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Share — AppKit host leaf. The macOS host owns the window and presents
|
|
2
|
+
// NSSharingServicePicker itself; this leaf only forwards the payload through
|
|
3
|
+
// the __xplatAppKit seam.
|
|
4
|
+
import type { ShareResult } from './types'
|
|
5
|
+
|
|
6
|
+
const host = () => (globalThis as any).__xplatAppKit ?? {}
|
|
7
|
+
|
|
8
|
+
export const share = {
|
|
9
|
+
async text(text: string): Promise<ShareResult> {
|
|
10
|
+
return host().shareContent?.({ text }) ?? 'unavailable'
|
|
11
|
+
},
|
|
12
|
+
async url(url: string, title?: string): Promise<ShareResult> {
|
|
13
|
+
return host().shareContent?.({ url, title }) ?? 'unavailable'
|
|
14
|
+
},
|
|
15
|
+
}
|
package/src/share.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Share — native share sheet via @nativescript/social-share.
|
|
2
|
+
import { shareText, shareUrl } from '@nativescript/social-share'
|
|
3
|
+
|
|
4
|
+
export const share = {
|
|
5
|
+
async text(text: string, subject?: string): Promise<'shared'> {
|
|
6
|
+
shareText(text, subject)
|
|
7
|
+
return 'shared'
|
|
8
|
+
},
|
|
9
|
+
async url(url: string, title?: string): Promise<'shared'> {
|
|
10
|
+
shareUrl(url, title ?? url)
|
|
11
|
+
return 'shared'
|
|
12
|
+
},
|
|
13
|
+
}
|
package/src/share.web.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
// Share — web leaf. navigator.share where present (mobile Safari/Chrome);
|
|
2
|
+
// desktop degrades to clipboard copy so the call still does something useful.
|
|
3
|
+
import { desktopHost, desktopHostSupports } from '@octane-xplat/platform/host/web'
|
|
4
|
+
|
|
5
|
+
export const share = {
|
|
6
|
+
async text(text: string, subject?: string): Promise<'shared' | 'copied' | 'unavailable'> {
|
|
7
|
+
const host = desktopHost()
|
|
8
|
+
if (host && (await desktopHostSupports('system', 'shareContent'))) {
|
|
9
|
+
return host.system.shareContent({ text, title: subject })
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const nav = navigator as any
|
|
13
|
+
if (nav.share) {
|
|
14
|
+
await nav.share({ text, title: subject })
|
|
15
|
+
return 'shared'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (nav.clipboard) {
|
|
19
|
+
await nav.clipboard.writeText(text)
|
|
20
|
+
return 'copied'
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return 'unavailable'
|
|
24
|
+
},
|
|
25
|
+
async url(url: string, title?: string): Promise<'shared' | 'copied' | 'unavailable'> {
|
|
26
|
+
const host = desktopHost()
|
|
27
|
+
if (host && (await desktopHostSupports('system', 'shareContent'))) {
|
|
28
|
+
return host.system.shareContent({ url, title })
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const nav = navigator as any
|
|
32
|
+
if (nav.share) {
|
|
33
|
+
await nav.share({ url, title })
|
|
34
|
+
return 'shared'
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (nav.clipboard) {
|
|
38
|
+
await nav.clipboard.writeText(url)
|
|
39
|
+
return 'copied'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return 'unavailable'
|
|
43
|
+
},
|
|
44
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ShareResult = 'shared' | 'copied' | 'unavailable'
|
|
2
|
+
|
|
3
|
+
export interface Share {
|
|
4
|
+
/** Present the platform share sheet with text. */
|
|
5
|
+
text(text: string, subject?: string): Promise<ShareResult>
|
|
6
|
+
/** Present the platform share sheet with a URL. */
|
|
7
|
+
url(url: string, title?: string): Promise<ShareResult>
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export declare const share: Share
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './types.js'
|
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export type ShareResult = 'shared' | 'copied' | 'unavailable';
|
|
2
|
+
export interface Share {
|
|
3
|
+
/** Present the platform share sheet with text. */
|
|
4
|
+
text(text: string, subject?: string): Promise<ShareResult>;
|
|
5
|
+
/** Present the platform share sheet with a URL. */
|
|
6
|
+
url(url: string, title?: string): Promise<ShareResult>;
|
|
7
|
+
}
|
|
8
|
+
export declare const share: Share;
|
package/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {}
|
package/index.js
DELETED