@mappedin/react-native-sdk 6.0.0-alpha.9 → 6.0.0-beta.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.txt +104 -0
- package/README.md +162 -164
- package/lib/components/label.d.ts +45 -0
- package/lib/components/label.d.ts.map +1 -0
- package/lib/components/marker.d.ts +54 -0
- package/lib/components/marker.d.ts.map +1 -0
- package/lib/components/model.d.ts +45 -0
- package/lib/components/model.d.ts.map +1 -0
- package/lib/components/path.d.ts +42 -0
- package/lib/components/path.d.ts.map +1 -0
- package/lib/components/shape.d.ts +54 -0
- package/lib/components/shape.d.ts.map +1 -0
- package/lib/controls/event-control.d.ts +89 -0
- package/lib/controls/event-control.d.ts.map +1 -0
- package/lib/controls/map-view-control.d.ts +360 -0
- package/lib/controls/map-view-control.d.ts.map +1 -0
- package/lib/errors.d.ts +4 -0
- package/lib/errors.d.ts.map +1 -0
- package/lib/hooks/use-bridge.d.ts +81 -0
- package/lib/hooks/use-bridge.d.ts.map +1 -0
- package/lib/hooks/use-map-view-event.d.ts +27 -0
- package/lib/hooks/use-map-view-event.d.ts.map +1 -0
- package/lib/hooks/use-map.d.ts +58 -0
- package/lib/hooks/use-map.d.ts.map +1 -0
- package/lib/index.d.ts +21 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +61507 -0
- package/lib/index.js.map +7 -0
- package/lib/map-view.d.ts +51 -0
- package/lib/map-view.d.ts.map +1 -0
- package/lib/types.d.ts +3 -0
- package/lib/types.d.ts.map +1 -0
- package/lib/utils.d.ts +28 -0
- package/lib/utils.d.ts.map +1 -0
- package/package.json +52 -29
- package/dist/commonjs/index.js +0 -3628
- package/dist/esm/index.js +0 -3628
- package/dist/index.d.ts +0 -6863
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { WebView, WebViewMessageEvent } from 'react-native-webview';
|
|
2
|
+
/**
|
|
3
|
+
* React hook for communicating with a WebView using a bridge pattern.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* import { useRef, useState } from 'react';
|
|
8
|
+
* import { WebView } from 'react-native-webview';
|
|
9
|
+
* import { useBridge } from './hooks/use-bridge';
|
|
10
|
+
*
|
|
11
|
+
* function MyComponent() {
|
|
12
|
+
* const [webView, setWebView] = useState<WebView | null>(null);
|
|
13
|
+
* const { instruct, handleMessage, cleanup } = useBridge(webView);
|
|
14
|
+
*
|
|
15
|
+
* const handlePress = async () => {
|
|
16
|
+
* try {
|
|
17
|
+
* const result = await instruct({
|
|
18
|
+
* type: 'function',
|
|
19
|
+
* payload: {
|
|
20
|
+
* name: 'getMapData',
|
|
21
|
+
* options: [{ venueId: '123' }]
|
|
22
|
+
* }
|
|
23
|
+
* });
|
|
24
|
+
* console.log('Map data:', result);
|
|
25
|
+
* } catch (error) {
|
|
26
|
+
* console.error('Failed to get map data:', error);
|
|
27
|
+
* }
|
|
28
|
+
* };
|
|
29
|
+
*
|
|
30
|
+
* // Clean up on unmount
|
|
31
|
+
* useEffect(() => {
|
|
32
|
+
* return () => {
|
|
33
|
+
* cleanup();
|
|
34
|
+
* };
|
|
35
|
+
* }, [cleanup]);
|
|
36
|
+
*
|
|
37
|
+
* return (
|
|
38
|
+
* <WebView
|
|
39
|
+
* ref={setWebView}
|
|
40
|
+
* source={{ uri: 'https://example.com' }}
|
|
41
|
+
* onMessage={handleMessage}
|
|
42
|
+
* />
|
|
43
|
+
* );
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
46
|
+
*
|
|
47
|
+
* @param webView - The WebView instance (can be null)
|
|
48
|
+
* @returns Object containing the instruct function, handleMessage callback, and cleanup function
|
|
49
|
+
*/
|
|
50
|
+
type FunctionInstruction = {
|
|
51
|
+
type: 'function';
|
|
52
|
+
payload: {
|
|
53
|
+
name: string;
|
|
54
|
+
options?: any[];
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
type MethodInstruction = {
|
|
58
|
+
type: 'method';
|
|
59
|
+
payload: {
|
|
60
|
+
target: string;
|
|
61
|
+
method: string;
|
|
62
|
+
args?: any[];
|
|
63
|
+
};
|
|
64
|
+
};
|
|
65
|
+
export type Instruction = FunctionInstruction | MethodInstruction;
|
|
66
|
+
/**
|
|
67
|
+
* React hook for communicating with a WebView or iframe using a bridge pattern.
|
|
68
|
+
* Automatically detects platform and uses appropriate communication method.
|
|
69
|
+
*
|
|
70
|
+
* @param container - The WebView instance (React Native) or HTMLIFrameElement (web) - can be null
|
|
71
|
+
* @returns An object containing the instruct function, handleMessage callback, cleanup function, and isReady state
|
|
72
|
+
*/
|
|
73
|
+
export declare function useBridge(container: WebView | HTMLIFrameElement | null): {
|
|
74
|
+
instruct: <T = any>(instruction: Instruction) => Promise<T>;
|
|
75
|
+
handleMessage: (event: WebViewMessageEvent | MessageEvent) => void;
|
|
76
|
+
destroy: () => void;
|
|
77
|
+
isReady: boolean;
|
|
78
|
+
};
|
|
79
|
+
export type UseBridgeHook = ReturnType<typeof useBridge>;
|
|
80
|
+
export {};
|
|
81
|
+
//# sourceMappingURL=use-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-bridge.d.ts","sourceRoot":"","sources":["../../src/hooks/use-bridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAIzE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAGH,KAAK,mBAAmB,GAAG;IAC1B,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC;KAChB,CAAC;CACF,CAAC;AACF,KAAK,iBAAiB,GAAG;IACxB,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE;QACR,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;KACb,CAAC;CACF,CAAC;AACF,MAAM,MAAM,WAAW,GAAG,mBAAmB,GAAG,iBAAiB,CAAC;AAqBlE;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,SAAS,EAAE,OAAO,GAAG,iBAAiB,GAAG,IAAI;eAyCpE,CAAC,qBAAqB,WAAW,KAAG,OAAO,CAAC,CAAC,CAAC;2BA7BN,mBAAmB,GAAG,YAAY;;;EA8F5E;AAED,MAAM,MAAM,aAAa,GAAG,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TEvents } from '@mappedin/mappedin-js';
|
|
2
|
+
type TEventPayload<EventName extends keyof TEvents> = TEvents[EventName] extends {
|
|
3
|
+
data: null;
|
|
4
|
+
} ? TEvents[EventName]['data'] : TEvents[EventName];
|
|
5
|
+
/**
|
|
6
|
+
* Hook to subscribe to an event on the MapView in React Native.
|
|
7
|
+
*
|
|
8
|
+
* This hook uses the MapView's .on() and .off() methods to subscribe to events
|
|
9
|
+
* on the MapView instance running in the WebView.
|
|
10
|
+
*
|
|
11
|
+
* @param event - The event to listen for.
|
|
12
|
+
* @param callback - The callback to call when the event is triggered.
|
|
13
|
+
*
|
|
14
|
+
* @category Hooks
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```tsx
|
|
18
|
+
* useMapViewEvent('click', event => {
|
|
19
|
+
* const { coordinate } = event;
|
|
20
|
+
* const { latitude, longitude } = coordinate;
|
|
21
|
+
* console.log(`Map was clicked at ${latitude}, ${longitude}`);
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
export declare function useMapViewEvent<T extends keyof TEvents>(event: T, callback: (payload: TEventPayload<T>) => void): void;
|
|
26
|
+
export {};
|
|
27
|
+
//# sourceMappingURL=use-map-view-event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-map-view-event.d.ts","sourceRoot":"","sources":["../../src/hooks/use-map-view-event.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,KAAK,aAAa,CAAC,SAAS,SAAS,MAAM,OAAO,IAAI,OAAO,CAAC,SAAS,CAAC,SAAS;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,GAC5F,OAAO,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,GAC1B,OAAO,CAAC,SAAS,CAAC,CAAC;AAEtB;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,MAAM,OAAO,EAAE,KAAK,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,IAAI,QAwC/G"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { WebView, WebViewMessageEvent } from 'react-native-webview';
|
|
2
|
+
import type { Mappedin } from '../types';
|
|
3
|
+
import type { MapViewControl } from '../controls/map-view-control';
|
|
4
|
+
import type { EventControl } from '../controls/event-control';
|
|
5
|
+
import type { PubSub } from '@mappedin/mappedin-js';
|
|
6
|
+
interface WebViewMessageEventPayload {
|
|
7
|
+
'webview-message-received': WebViewMessageEvent;
|
|
8
|
+
}
|
|
9
|
+
export declare const MappedinContext: import("react").Context<{
|
|
10
|
+
mapData?: Mappedin.MapData;
|
|
11
|
+
mapView?: MapViewControl;
|
|
12
|
+
/**
|
|
13
|
+
* Event control system for managing event callbacks.
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
_events?: EventControl;
|
|
17
|
+
/**
|
|
18
|
+
* Container instance for bridge communication (WebView on native, HTMLIFrameElement on web).
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
_webView?: WebView | HTMLIFrameElement | null;
|
|
22
|
+
/**
|
|
23
|
+
* PubSub instance for WebView message events.
|
|
24
|
+
* @internal
|
|
25
|
+
*/
|
|
26
|
+
_webViewMessagePubSub?: PubSub<WebViewMessageEventPayload>;
|
|
27
|
+
}>;
|
|
28
|
+
/**
|
|
29
|
+
* Hook to get the MapData and MapView instances from the MapView context.
|
|
30
|
+
*
|
|
31
|
+
* This hook provides access to the mapData and mapView instances that are
|
|
32
|
+
* created and managed by the MapView component. It ensures that the hook
|
|
33
|
+
* is used within a MapView component context.
|
|
34
|
+
*
|
|
35
|
+
* @throws {MapViewNullError} When used outside of a MapView component or when mapData/mapView are not yet initialized
|
|
36
|
+
*
|
|
37
|
+
* @returns Object containing mapData and mapView instances
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* function MyMapComponent() {
|
|
42
|
+
* const { mapData, mapView } = useMap();
|
|
43
|
+
*
|
|
44
|
+
* useEffect(() => {
|
|
45
|
+
* // Use mapView to interact with the map
|
|
46
|
+
* mapView.Camera.animateTo({ center: mapData.getByType('space')[0] });
|
|
47
|
+
* }, [mapData, mapView]);
|
|
48
|
+
*
|
|
49
|
+
* return <Text>Map is ready!</Text>;
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
export declare function useMap(): {
|
|
54
|
+
mapData: Mappedin.MapData;
|
|
55
|
+
mapView: MapViewControl;
|
|
56
|
+
};
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=use-map.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-map.d.ts","sourceRoot":"","sources":["../../src/hooks/use-map.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAEzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAGpD,UAAU,0BAA0B;IACnC,0BAA0B,EAAE,mBAAmB,CAAC;CAChD;AAGD,eAAO,MAAM,eAAe;cACjB,QAAQ,CAAC,OAAO;cAChB,cAAc;IACxB;;;OAGG;cACO,YAAY;IACtB;;;OAGG;eACQ,OAAO,GAAG,iBAAiB,GAAG,IAAI;IAC7C;;;OAGG;4BACqB,MAAM,CAAC,0BAA0B,CAAC;EAOzD,CAAC;AAEH;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,MAAM,IAAI;IACzB,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC;IAC1B,OAAO,EAAE,cAAc,CAAC;CACxB,CAQA"}
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { MapView } from './map-view';
|
|
2
|
+
export type { MapViewProps } from './map-view';
|
|
3
|
+
export { useMap, MappedinContext } from './hooks/use-map';
|
|
4
|
+
export type { MapViewControl, Promisify, PromisifiedUpdateState } from './controls/map-view-control';
|
|
5
|
+
export { useMapViewEvent } from './hooks/use-map-view-event';
|
|
6
|
+
export { Marker } from './components/marker';
|
|
7
|
+
export type { MarkerProps } from './components/marker';
|
|
8
|
+
export { Label } from './components/label';
|
|
9
|
+
export type { LabelProps } from './components/label';
|
|
10
|
+
export { Path } from './components/path';
|
|
11
|
+
export type { PathProps } from './components/path';
|
|
12
|
+
export { Shape } from './components/shape';
|
|
13
|
+
export type { ShapeProps } from './components/shape';
|
|
14
|
+
export type { Navigation } from './controls/map-view-control';
|
|
15
|
+
export { Model } from './components/model';
|
|
16
|
+
export type { ModelProps } from './components/model';
|
|
17
|
+
export { setLoggerLevel } from './utils';
|
|
18
|
+
import type { hydrateMapData as HydrateMapData, unzipAndParseMVFv2 as UnzipAndParseMVFv2 } from '@mappedin/mappedin-js';
|
|
19
|
+
export declare const hydrateMapData: typeof HydrateMapData;
|
|
20
|
+
export declare const unzipAndParseMVFv2: typeof UnzipAndParseMVFv2;
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AACrC,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC1D,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrG,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,YAAY,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,YAAY,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,YAAY,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAMzC,OAAO,KAAK,EAAE,cAAc,IAAI,cAAc,EAAE,kBAAkB,IAAI,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAExH,eAAO,MAAM,cAAc,EAAE,OAAO,cAAgC,CAAC;AACrE,eAAO,MAAM,kBAAkB,EAAE,OAAO,kBAAwC,CAAC"}
|