@symbiote-native/sharing 3.0.1 → 3.0.3
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/README.md +80 -52
- package/build/angular/index.d.ts +1 -0
- package/build/angular/index.js +1 -3
- package/build/angular/inject-incoming-share.d.ts +4 -0
- package/build/angular/inject-incoming-share.js +5 -0
- package/build/core/incoming-share-hook.d.ts +4 -0
- package/build/core/incoming-share-hook.js +13 -0
- package/build/core/incoming-share-result.d.ts +3 -0
- package/build/core/incoming-share-result.js +11 -0
- package/build/core/incoming-share-store.d.ts +9 -0
- package/build/core/incoming-share-store.js +100 -0
- package/build/core/index.d.ts +5 -2
- package/build/core/index.js +3 -1
- package/build/core/native-module.d.ts +4 -1
- package/build/core/sharing.d.ts +4 -1
- package/build/core/sharing.js +20 -0
- package/build/core/types.d.ts +41 -0
- package/build/react/index.d.ts +2 -0
- package/build/react/index.js +2 -0
- package/build/react/use-incoming-share.d.ts +3 -0
- package/build/react/use-incoming-share.js +10 -0
- package/build/solid/index.d.ts +2 -0
- package/build/solid/index.js +2 -0
- package/build/solid/use-incoming-share.d.ts +4 -0
- package/build/solid/use-incoming-share.js +5 -0
- package/build/svelte/index.d.ts +2 -0
- package/build/svelte/index.js +2 -0
- package/build/svelte/use-incoming-share.svelte.d.ts +7 -0
- package/build/svelte/use-incoming-share.svelte.js +8 -0
- package/build/vue/index.d.ts +2 -0
- package/build/vue/index.js +2 -0
- package/build/vue/use-incoming-share.d.ts +4 -0
- package/build/vue/use-incoming-share.js +5 -0
- package/build-ngc/angular/index.d.ts +1 -0
- package/build-ngc/angular/index.js +1 -3
- package/build-ngc/angular/index.js.map +1 -1
- package/build-ngc/angular/inject-incoming-share.d.ts +4 -0
- package/build-ngc/angular/inject-incoming-share.js +6 -0
- package/build-ngc/angular/inject-incoming-share.js.map +1 -0
- package/build-ngc/core/incoming-share-hook.d.ts +4 -0
- package/build-ngc/core/incoming-share-hook.js +14 -0
- package/build-ngc/core/incoming-share-hook.js.map +1 -0
- package/build-ngc/core/incoming-share-result.d.ts +3 -0
- package/build-ngc/core/incoming-share-result.js +12 -0
- package/build-ngc/core/incoming-share-result.js.map +1 -0
- package/build-ngc/core/incoming-share-store.d.ts +9 -0
- package/build-ngc/core/incoming-share-store.js +101 -0
- package/build-ngc/core/incoming-share-store.js.map +1 -0
- package/build-ngc/core/index.d.ts +5 -2
- package/build-ngc/core/index.js +3 -1
- package/build-ngc/core/index.js.map +1 -1
- package/build-ngc/core/native-module.d.ts +4 -1
- package/build-ngc/core/native-module.js.map +1 -1
- package/build-ngc/core/sharing.d.ts +4 -1
- package/build-ngc/core/sharing.js +20 -0
- package/build-ngc/core/sharing.js.map +1 -1
- package/build-ngc/core/types.d.ts +41 -0
- package/package.json +23 -23
- package/src/angular/index.ts +1 -3
- package/src/angular/inject-incoming-share.ts +13 -0
- package/src/core/incoming-share-hook.ts +28 -0
- package/src/core/incoming-share-result.ts +17 -0
- package/src/core/incoming-share-store.ts +118 -0
- package/src/core/index.ts +26 -2
- package/src/core/native-module.ts +10 -4
- package/src/core/sharing.ts +33 -1
- package/src/core/types.ts +52 -0
- package/src/react/index.ts +2 -0
- package/src/react/use-incoming-share.ts +24 -0
- package/src/solid/index.ts +2 -0
- package/src/solid/use-incoming-share.ts +13 -0
- package/src/svelte/index.ts +2 -0
- package/src/svelte/svelte-ambient.d.ts +3 -0
- package/src/svelte/svelte-compile.test-helper.ts +7 -0
- package/src/svelte/use-incoming-share.svelte.ts +22 -0
- package/src/vue/index.ts +2 -0
- package/src/vue/use-incoming-share.ts +13 -0
package/src/core/sharing.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { UnavailabilityError } from 'expo-modules-core';
|
|
2
2
|
|
|
3
3
|
import { expoSharing } from './native-module';
|
|
4
|
-
import type {
|
|
4
|
+
import type {
|
|
5
|
+
IResolvedSharePayload,
|
|
6
|
+
ISharePayload,
|
|
7
|
+
ISharingOptions,
|
|
8
|
+
} from './types';
|
|
5
9
|
|
|
6
10
|
const NATIVE_MODULE_NAME = 'expo-sharing';
|
|
7
11
|
|
|
@@ -38,6 +42,34 @@ export async function shareAsync(
|
|
|
38
42
|
await expoSharing.shareAsync(url, options);
|
|
39
43
|
}
|
|
40
44
|
|
|
45
|
+
// Empty until the host app carries the share target (iOS Share Extension, Android intent filters)
|
|
46
|
+
export function getSharedPayloads(): ISharePayload[] {
|
|
47
|
+
if (!expoSharing.getSharedPayloads) {
|
|
48
|
+
throw new UnavailabilityError(NATIVE_MODULE_NAME, 'getSharedPayloads');
|
|
49
|
+
}
|
|
50
|
+
return expoSharing.getSharedPayloads();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// Adds display details per payload, resolving a shared URL may need the network
|
|
54
|
+
export async function getResolvedSharedPayloadsAsync(): Promise<
|
|
55
|
+
IResolvedSharePayload[]
|
|
56
|
+
> {
|
|
57
|
+
if (!expoSharing.getResolvedSharedPayloadsAsync) {
|
|
58
|
+
throw new UnavailabilityError(
|
|
59
|
+
NATIVE_MODULE_NAME,
|
|
60
|
+
'getResolvedSharedPayloadsAsync',
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
return expoSharing.getResolvedSharedPayloadsAsync();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export function clearSharedPayloads(): void {
|
|
67
|
+
if (!expoSharing.clearSharedPayloads) {
|
|
68
|
+
throw new UnavailabilityError(NATIVE_MODULE_NAME, 'clearSharedPayloads');
|
|
69
|
+
}
|
|
70
|
+
expoSharing.clearSharedPayloads();
|
|
71
|
+
}
|
|
72
|
+
|
|
41
73
|
// Not in upstream, which hands anything straight to the native module. An empty or non-string
|
|
42
74
|
// url surfaces there as an argument-conversion failure on iOS and a generic "Failed to share the
|
|
43
75
|
// file" on Android — both far enough from the call site to be worth failing early with the
|
package/src/core/types.ts
CHANGED
|
@@ -37,3 +37,55 @@ export type ISharingOptions = {
|
|
|
37
37
|
*/
|
|
38
38
|
anchor?: ISharingAnchor;
|
|
39
39
|
};
|
|
40
|
+
|
|
41
|
+
export type IShareType = 'text' | 'url' | 'audio' | 'image' | 'video' | 'file';
|
|
42
|
+
|
|
43
|
+
export type IContentType =
|
|
44
|
+
'text' | 'audio' | 'image' | 'video' | 'file' | 'website';
|
|
45
|
+
|
|
46
|
+
/** Raw data shared with the app (android, ios) */
|
|
47
|
+
export type ISharePayload = {
|
|
48
|
+
/** Message body for `text`, the URL for `url`, otherwise typically the file URI */
|
|
49
|
+
value: string;
|
|
50
|
+
shareType: IShareType;
|
|
51
|
+
/** MIME type of `value` */
|
|
52
|
+
mimeType?: string;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export type IBaseResolvedSharePayload = ISharePayload & {
|
|
56
|
+
/** Where the content can be read from (the redirect target for a URL), null for text */
|
|
57
|
+
contentUri: string | null;
|
|
58
|
+
contentType: IContentType | null;
|
|
59
|
+
contentMimeType: string | null;
|
|
60
|
+
/** The `suggestedFilename` HTTP header if present, otherwise the last path component */
|
|
61
|
+
originalName: string | null;
|
|
62
|
+
contentSize: number | null;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export type IUriBasedResolvedSharePayload = IBaseResolvedSharePayload & {
|
|
66
|
+
contentType: 'audio' | 'file' | 'video' | 'image' | 'website';
|
|
67
|
+
contentUri: string;
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
export type ITextBasedResolvedSharePayload = IBaseResolvedSharePayload & {
|
|
71
|
+
contentType?: 'text';
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/** A payload plus the details needed to display it, resolving a URL may need the network */
|
|
75
|
+
export type IResolvedSharePayload =
|
|
76
|
+
IUriBasedResolvedSharePayload | ITextBasedResolvedSharePayload;
|
|
77
|
+
|
|
78
|
+
export type IIncomingShareSnapshot = {
|
|
79
|
+
/** Unresolved payloads, available synchronously from the first read */
|
|
80
|
+
sharedPayloads: ISharePayload[];
|
|
81
|
+
/** Empty while resolving or when resolving failed */
|
|
82
|
+
resolvedSharedPayloads: IResolvedSharePayload[];
|
|
83
|
+
isResolving: boolean;
|
|
84
|
+
/** The error hit while resolving, null on success */
|
|
85
|
+
error: Error | null;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
export type IUseIncomingShareResult = IIncomingShareSnapshot & {
|
|
89
|
+
clearSharedPayloads: () => void;
|
|
90
|
+
refreshSharePayloads: () => void;
|
|
91
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { createEventValueHook } from '@symbiote-native/react';
|
|
3
|
+
import {
|
|
4
|
+
createIncomingShareStore,
|
|
5
|
+
INCOMING_SHARE_CHANGE,
|
|
6
|
+
} from '../core/incoming-share-store';
|
|
7
|
+
import { withShareActions } from '../core/incoming-share-result';
|
|
8
|
+
import type { IIncomingShareStore } from '../core/incoming-share-store';
|
|
9
|
+
import type {
|
|
10
|
+
IIncomingShareSnapshot,
|
|
11
|
+
IUseIncomingShareResult,
|
|
12
|
+
} from '../core/types';
|
|
13
|
+
|
|
14
|
+
const useShareSnapshot = createEventValueHook<
|
|
15
|
+
IIncomingShareStore,
|
|
16
|
+
IIncomingShareSnapshot,
|
|
17
|
+
typeof INCOMING_SHARE_CHANGE
|
|
18
|
+
>(INCOMING_SHARE_CHANGE, store => store.getSnapshot());
|
|
19
|
+
|
|
20
|
+
/** React twin of `expo-sharing`'s `useIncomingShare` */
|
|
21
|
+
export function useIncomingShare(): IUseIncomingShareResult {
|
|
22
|
+
const [store] = useState(createIncomingShareStore);
|
|
23
|
+
return withShareActions(useShareSnapshot(store), store);
|
|
24
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createMemo, type Accessor } from 'solid-js';
|
|
2
|
+
import { createEventValueHook } from '@symbiote-native/solid';
|
|
3
|
+
import { createIncomingShareHook } from '../core/incoming-share-hook';
|
|
4
|
+
import type {
|
|
5
|
+
IIncomingShareSnapshot,
|
|
6
|
+
IUseIncomingShareResult,
|
|
7
|
+
} from '../core/types';
|
|
8
|
+
|
|
9
|
+
/** Solid twin of `expo-sharing`'s `useIncomingShare` */
|
|
10
|
+
export const useIncomingShare = createIncomingShareHook<
|
|
11
|
+
Accessor<IIncomingShareSnapshot>,
|
|
12
|
+
Accessor<IUseIncomingShareResult>
|
|
13
|
+
>(createEventValueHook, box => box(), createMemo);
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
// Re-exports the existing harness instead of a third copy (packages/sqlite and
|
|
2
|
+
// packages/navigation already carry one, not part of either package's public exports)
|
|
3
|
+
export {
|
|
4
|
+
createSvelteHarness,
|
|
5
|
+
loadComponent,
|
|
6
|
+
type ISvelteHarness,
|
|
7
|
+
} from '../../../sqlite/src/svelte/svelte-compile.test-helper';
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { createEventValueHook } from '@symbiote-native/svelte/runes/create-event-value-hook';
|
|
2
|
+
import { createIncomingShareHook } from '../core/incoming-share-hook';
|
|
3
|
+
import type {
|
|
4
|
+
IIncomingShareSnapshot,
|
|
5
|
+
IUseIncomingShareResult,
|
|
6
|
+
} from '../core/types';
|
|
7
|
+
|
|
8
|
+
type IBox<TValue> = { readonly current: TValue };
|
|
9
|
+
|
|
10
|
+
/** Svelte twin of `expo-sharing`'s `useIncomingShare` */
|
|
11
|
+
export const useIncomingShare = createIncomingShareHook<
|
|
12
|
+
IBox<IIncomingShareSnapshot>,
|
|
13
|
+
IBox<IUseIncomingShareResult>
|
|
14
|
+
>(
|
|
15
|
+
createEventValueHook,
|
|
16
|
+
box => box.current,
|
|
17
|
+
compute => ({
|
|
18
|
+
get current(): IUseIncomingShareResult {
|
|
19
|
+
return compute();
|
|
20
|
+
},
|
|
21
|
+
}),
|
|
22
|
+
);
|
package/src/vue/index.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { computed, type ComputedRef, type ShallowRef } from '@vue/runtime-core';
|
|
2
|
+
import { createEventValueHook } from '@symbiote-native/vue';
|
|
3
|
+
import { createIncomingShareHook } from '../core/incoming-share-hook';
|
|
4
|
+
import type {
|
|
5
|
+
IIncomingShareSnapshot,
|
|
6
|
+
IUseIncomingShareResult,
|
|
7
|
+
} from '../core/types';
|
|
8
|
+
|
|
9
|
+
/** Vue twin of `expo-sharing`'s `useIncomingShare` */
|
|
10
|
+
export const useIncomingShare = createIncomingShareHook<
|
|
11
|
+
ShallowRef<IIncomingShareSnapshot>,
|
|
12
|
+
ComputedRef<IUseIncomingShareResult>
|
|
13
|
+
>(createEventValueHook, box => box.value, computed);
|