wovvmap-webview-bridge 1.0.3 → 1.0.5

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.
@@ -0,0 +1,18 @@
1
+ import type { WebViewMessageEvent } from "react-native-webview";
2
+ import { NodePoint } from "../types/types";
3
+ export type EventHandlerMap = {
4
+ isSceneClick?: (sceneClick: {
5
+ type: "event";
6
+ key: "isSceneClick";
7
+ file: string;
8
+ }) => void;
9
+ isShapClick?: (shapClick: {
10
+ type: "event";
11
+ key: "isShapClick";
12
+ value: NodePoint;
13
+ file: string;
14
+ }) => void;
15
+ };
16
+ export declare const eventHandlers: Partial<EventHandlerMap>;
17
+ export declare const registerBridgeHandler: <K extends keyof EventHandlerMap>(type: K, handler: EventHandlerMap[K]) => void;
18
+ export declare const handleBridgeMessage: (event: WebViewMessageEvent) => void;
@@ -0,0 +1,35 @@
1
+ import { bridgeStorage } from "../webviewBridge/BridgeStorage";
2
+ // ✅ 2. Global handler storage
3
+ export var eventHandlers = {};
4
+ // ✅ 4. Register handler function
5
+ export var registerBridgeHandler = function (type, handler) {
6
+ eventHandlers[type] = handler;
7
+ };
8
+ // ✅ 5. Main bridge handler
9
+ export var handleBridgeMessage = function (event) {
10
+ var _a, _b;
11
+ try {
12
+ var message = JSON.parse(event.nativeEvent.data);
13
+ if (message.key === "mapLoaded")
14
+ bridgeStorage.set("isMapLoaded", message.value);
15
+ if (message.key === "isConnection")
16
+ bridgeStorage.set("isBridgeLoaded", message.value);
17
+ if (message.key === "_searchablePoints")
18
+ bridgeStorage.set("searchablePoints", message.value);
19
+ if (message.key === "_activeFloor")
20
+ bridgeStorage.set("activeFloor", message.value);
21
+ if (message.key === "FloorImg")
22
+ bridgeStorage.set("floorImages", message.value);
23
+ if (message.key === "isSceneClick")
24
+ (_a = eventHandlers[message.key]) === null || _a === void 0 ? void 0 : _a.call(eventHandlers, message);
25
+ if (message.key === "isShapClick")
26
+ (_b = eventHandlers[message.key]) === null || _b === void 0 ? void 0 : _b.call(eventHandlers, message);
27
+ if (message.key === "stapByStapList")
28
+ bridgeStorage.set("stapByStapList", message.value);
29
+ if (message.key === "pathNextPreState")
30
+ bridgeStorage.set("nextPreState", message.value);
31
+ }
32
+ catch (e) {
33
+ console.error("WebView message error:", e);
34
+ }
35
+ };
@@ -0,0 +1,4 @@
1
+ export { WebViewScreen } from './webviewBridge/WebViewScreen';
2
+ export { eventHandlers, registerBridgeHandler } from './handlers/WebBridgeHandlers';
3
+ export { bridgeStorage } from './webviewBridge/BridgeStorage';
4
+ export { sendActiveFloorToBridge, sendEndPointToBridge, sendPathFinishBtnClick, sendPathNextBtnClick, sendPathPreBtnClick, sendStartPointToBridge } from './webviewBridge/BridgeService';
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { WebViewScreen } from './webviewBridge/WebViewScreen';
2
- export { sendToWeb, webviewRef } from './webviewBridge/WebViewBridgeRef';
3
- export { bridgeMessageStore, eventHandlers, handleBridgeMessage, registerBridgeHandler } from './handlers/WebBridgeHandlers';
2
+ export { eventHandlers, registerBridgeHandler } from './handlers/WebBridgeHandlers';
3
+ export { bridgeStorage } from './webviewBridge/BridgeStorage';
4
+ export { sendActiveFloorToBridge, sendEndPointToBridge, sendPathFinishBtnClick, sendPathNextBtnClick, sendPathPreBtnClick, sendStartPointToBridge } from './webviewBridge/BridgeService';
@@ -0,0 +1,178 @@
1
+ export interface LocationArea {
2
+ x: number;
3
+ y: number;
4
+ }
5
+ export interface LocationName {
6
+ text: string;
7
+ area: LocationArea;
8
+ rotate: number;
9
+ textColor: string;
10
+ textSize: string;
11
+ textStyle: string;
12
+ width: string;
13
+ height: string;
14
+ }
15
+ export interface Logo {
16
+ show: boolean;
17
+ url: string;
18
+ size: number;
19
+ x: number;
20
+ y: number;
21
+ rotate: number;
22
+ }
23
+ export interface ShapePoint {
24
+ x: number;
25
+ y: number;
26
+ }
27
+ export interface BrandId {
28
+ sit: string;
29
+ }
30
+ export interface NodePoint {
31
+ x: number;
32
+ y: number;
33
+ z: number;
34
+ targetDist: number;
35
+ previousNode: any;
36
+ close: boolean;
37
+ colleague: any[];
38
+ elementTag: string;
39
+ LocationName: LocationName;
40
+ Category: string;
41
+ type: string;
42
+ LeaseType: string;
43
+ logo: Logo;
44
+ color: string;
45
+ Description: string;
46
+ shape: ShapePoint[];
47
+ up: boolean;
48
+ down: boolean;
49
+ depth: number;
50
+ brand_Id: BrandId;
51
+ floorBash: boolean;
52
+ extra: Record<string, any>;
53
+ key: string;
54
+ myAngle: number;
55
+ NavigationInstruction: any;
56
+ distanceToNextPoint: number;
57
+ stepsToNextPoint: number;
58
+ }
59
+ export interface Category {
60
+ name: string;
61
+ Description: string;
62
+ color: string;
63
+ }
64
+ export interface FloorImage {
65
+ FloorName: string;
66
+ FloorUrl: string;
67
+ ShortName: string;
68
+ FloorNumber: number;
69
+ SubFloor?: boolean;
70
+ index: number;
71
+ }
72
+ export interface StepInstruction {
73
+ instruction: string;
74
+ distance: string;
75
+ steps?: number;
76
+ icon: "left" | "right" | "startPoint" | "endPoint" | "Take Elevator" | "Take Escalator" | "Exit Elevator" | "Exit Escalator" | null;
77
+ }
78
+ export type NavState = {
79
+ currentFloorIndex: number;
80
+ currentPointIndex: number;
81
+ totalFloors: number;
82
+ floorLengths: number[];
83
+ canPrev: boolean;
84
+ canNext: boolean;
85
+ isLastStep: boolean;
86
+ hasPath: boolean;
87
+ };
88
+ export type IncomingMessage = {
89
+ type: "event";
90
+ key: "pong";
91
+ file: string;
92
+ } | {
93
+ type: "event";
94
+ key: "isConnection";
95
+ value: boolean;
96
+ file: string;
97
+ } | {
98
+ type: "event";
99
+ key: "mapLoaded";
100
+ value: boolean;
101
+ file: string;
102
+ } | {
103
+ type: "event";
104
+ key: "_searchablePoints";
105
+ value: NodePoint[];
106
+ file: string;
107
+ } | {
108
+ type: "event";
109
+ key: "Category";
110
+ value: Category[];
111
+ file: string;
112
+ } | {
113
+ type: "event";
114
+ key: "_activeFloor";
115
+ value: number;
116
+ file: string;
117
+ } | {
118
+ type: "event";
119
+ key: "FloorImg";
120
+ value: FloorImage[];
121
+ file: string;
122
+ } | {
123
+ type: "event";
124
+ key: "isSceneClick";
125
+ file: string;
126
+ } | {
127
+ type: "event";
128
+ key: "isShapClick";
129
+ value: NodePoint;
130
+ file: string;
131
+ } | {
132
+ type: "event";
133
+ key: "stapByStapList";
134
+ value: StepInstruction[];
135
+ file: string;
136
+ } | {
137
+ type: "event";
138
+ key: "pathNextPreState";
139
+ value: NavState;
140
+ file: string;
141
+ };
142
+ export type OutgoingMessage = {
143
+ type: "applyCSS";
144
+ selector: string;
145
+ style: Partial<Record<string, string | number>>;
146
+ } | {
147
+ type: "event";
148
+ key: "ping";
149
+ value: boolean;
150
+ file: string;
151
+ } | {
152
+ type: "event";
153
+ key: "setEndPoint";
154
+ value: string;
155
+ file: string;
156
+ } | {
157
+ type: "event";
158
+ key: "setStartPoint";
159
+ value: string;
160
+ file: string;
161
+ } | {
162
+ type: "event";
163
+ key: "setActiveFloor";
164
+ value: number;
165
+ file: string;
166
+ } | {
167
+ type: "event";
168
+ key: "pathNextBtnClick";
169
+ file: string;
170
+ } | {
171
+ type: "event";
172
+ key: "pathPreBtnClick";
173
+ file: string;
174
+ } | {
175
+ type: "event";
176
+ key: "pathFinishBtnClick";
177
+ file: string;
178
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare const sendEndPointToBridge: (endPointId: string) => void;
2
+ export declare const sendStartPointToBridge: (startPointId: string) => void;
3
+ export declare const sendActiveFloorToBridge: (floorId: number) => void;
4
+ export declare const sendPathNextBtnClick: () => void;
5
+ export declare const sendPathPreBtnClick: () => void;
6
+ export declare const sendPathFinishBtnClick: () => void;
@@ -0,0 +1,19 @@
1
+ import { sendToWeb } from "./WebViewBridgeRef";
2
+ export var sendEndPointToBridge = function (endPointId) {
3
+ sendToWeb({ type: "event", key: "setEndPoint", value: endPointId, file: "BridgeService.ts" });
4
+ };
5
+ export var sendStartPointToBridge = function (startPointId) {
6
+ sendToWeb({ type: "event", key: "setStartPoint", value: startPointId, file: "BridgeService.ts" });
7
+ };
8
+ export var sendActiveFloorToBridge = function (floorId) {
9
+ sendToWeb({ type: "event", key: "setActiveFloor", value: floorId, file: "BridgeService.ts" });
10
+ };
11
+ export var sendPathNextBtnClick = function () {
12
+ sendToWeb({ type: "event", key: "pathNextBtnClick", file: "BridgeService.ts" });
13
+ };
14
+ export var sendPathPreBtnClick = function () {
15
+ sendToWeb({ type: "event", key: "pathPreBtnClick", file: "BridgeService.ts" });
16
+ };
17
+ export var sendPathFinishBtnClick = function () {
18
+ sendToWeb({ type: "event", key: "pathFinishBtnClick", file: "BridgeService.ts" });
19
+ };
@@ -0,0 +1,18 @@
1
+ import type { FloorImage, NavState, NodePoint, StepInstruction } from "../types/types";
2
+ type BridgeStorage = {
3
+ isBridgeLoaded: boolean;
4
+ isMapLoaded: boolean;
5
+ searchablePoints: NodePoint[];
6
+ activeFloor: number;
7
+ elevator: "true" | "false";
8
+ escalator: "true" | "false";
9
+ floorImages: FloorImage[];
10
+ stapByStapList: StepInstruction[];
11
+ nextPreState: NavState | null;
12
+ };
13
+ export declare let bridgeStorage: BridgeStorage & {
14
+ set<K extends keyof BridgeStorage>(key: K, value: BridgeStorage[K]): void;
15
+ onChange(callback: <K extends keyof BridgeStorage>(key: K, newValue: BridgeStorage[K], oldValue: BridgeStorage[K]) => void): () => void;
16
+ signal<K extends keyof BridgeStorage>(key: K): [BridgeStorage[K], (value: BridgeStorage[K]) => void];
17
+ };
18
+ export {};
@@ -0,0 +1,12 @@
1
+ import { createStore } from "koshin";
2
+ export var bridgeStorage = createStore({
3
+ isBridgeLoaded: false,
4
+ isMapLoaded: false,
5
+ searchablePoints: [],
6
+ activeFloor: -1,
7
+ elevator: "false",
8
+ escalator: "false",
9
+ floorImages: [],
10
+ stapByStapList: [],
11
+ nextPreState: null
12
+ });
@@ -0,0 +1,4 @@
1
+ import type { WebView } from "react-native-webview";
2
+ import { OutgoingMessage } from "../types/types";
3
+ export declare const webviewRef: import("react").RefObject<WebView<{}> | null>;
4
+ export declare const sendToWeb: (data: OutgoingMessage) => void;
@@ -0,0 +1,14 @@
1
+ import { createRef } from "react";
2
+ // Shared WebView ref
3
+ export var webviewRef = createRef();
4
+ // Exported send function
5
+ export var sendToWeb = function (data) {
6
+ console.log("webviweRef", webviewRef);
7
+ if (webviewRef.current) {
8
+ console.log("enter current");
9
+ webviewRef.current.postMessage(JSON.stringify(data));
10
+ }
11
+ else {
12
+ console.warn("WebView not ready yet");
13
+ }
14
+ };
@@ -0,0 +1,6 @@
1
+ import React from "react";
2
+ type Props = {
3
+ url: string;
4
+ };
5
+ export declare const WebViewScreen: ({ url }: Props) => React.JSX.Element;
6
+ export {};
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+ import { handleBridgeMessage } from "../handlers/WebBridgeHandlers";
3
+ import { webviewRef } from "./WebViewBridgeRef";
4
+ import { WebView } from 'react-native-webview';
5
+ export var WebViewScreen = function (_a) {
6
+ var url = _a.url;
7
+ var onMessage = function (event) {
8
+ console.log("on message event", event);
9
+ handleBridgeMessage(event);
10
+ };
11
+ return (React.createElement(WebView, { ref: webviewRef, source: { uri: url }, onMessage: onMessage, onLoadStart: function () { return console.log("WebView: load start", url); }, onLoadEnd: function () { return console.log("WebView: load end"); }, onLoadProgress: function (_a) {
12
+ var nativeEvent = _a.nativeEvent;
13
+ return console.log("WebView: progress", nativeEvent.progress);
14
+ }, onError: function (e) { return console.warn("WebView error:", e.nativeEvent); }, style: { flex: 1, width: "100%" } }));
15
+ };
package/package.json CHANGED
@@ -1,11 +1,10 @@
1
1
  {
2
2
  "name": "wovvmap-webview-bridge",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
7
- "src",
8
- "index.ts"
7
+ "dist"
9
8
  ],
10
9
  "scripts": {
11
10
  "build": "tsc "
@@ -13,9 +12,11 @@
13
12
  "peerDependencies": {
14
13
  "react": "^19.1.0",
15
14
  "react-native": "^0.80.1",
16
- "react-native-webview": "^13.15.0"
15
+ "react-native-webview": "^13.15.0",
16
+ "koshin": "^1.0.5"
17
17
  },
18
18
  "devDependencies": {
19
19
  "@types/react": "^19.1.8"
20
20
  }
21
+
21
22
  }
@@ -1,69 +0,0 @@
1
- import type { WebViewMessageEvent } from "react-native-webview";
2
- import type { BridgeMessage, NodeLineOuterFiled, NodePointOuterFiled } from "../types/BridgeMessage";
3
- import { SerializableNodePoint } from "../types/NodePoint";
4
- import { PathFindingResult } from "../types/PathFindingResult";
5
- import { SerializableNodePoint as NodePoint, SerializablePoint2D as Point2D } from "../types/NodePoint";
6
-
7
- // ✅ 1. Event handler map
8
- export type EventHandlerMap = {
9
- floor?: (floor: number) => void;
10
- pathData?: (val: NodePoint[]) => void;
11
- PathFindingResult?: (val: PathFindingResult) => void;
12
- searchTextResult?: (val: NodePoint[]) => void;
13
- shapeZoomAndSelect?: (val: NodePoint | undefined) => void;
14
- searchablePoints?: (val: NodePoint[]) => void;
15
- nodePoint?: (val: { [key: string]: NodePointOuterFiled }) => void;
16
- nodeline?: (val: { [key: string]: NodeLineOuterFiled }) => void;
17
- categoryList?: (val: { [key: string]: NodePoint }) => void;
18
- floorInfo?: (val: {
19
- floors: {
20
- index: number;
21
- shortName: string;
22
- fullName: string;
23
- floorNumber: number;
24
- }[];
25
- defaultFloorIndex: number;
26
- }) => void;
27
- to?: (val: string) => void;
28
- from?: (val: string) => void;
29
- elevator?: (val: "true" | "false") => void;
30
- escalator?: (val: "true" | "false") => void;
31
- };
32
-
33
- // ✅ 2. Global handler storage
34
- export const eventHandlers: Partial<EventHandlerMap> = {};
35
-
36
- // ✅ 3. Runtime key-value store for all event data
37
- export const bridgeMessageStore: Partial<Record<keyof EventHandlerMap, any>> = {};
38
-
39
- // ✅ 4. Register handler function
40
- export const registerBridgeHandler = <K extends keyof EventHandlerMap>(
41
- type: K,
42
- handler: EventHandlerMap[K]
43
- ) => {
44
- eventHandlers[type] = handler;
45
- };
46
-
47
- // ✅ 5. Main bridge handler
48
- export const handleBridgeMessage = (
49
- event: WebViewMessageEvent,
50
- ) => {
51
- try {
52
- const data: BridgeMessage = JSON.parse(event.nativeEvent.data);
53
-
54
- if (data.type === "event") {
55
- const key = data.key as keyof EventHandlerMap;
56
- const fn = eventHandlers[key];
57
-
58
- // ✅ Store latest data in bridgeMessageStore
59
- bridgeMessageStore[key] = data.value;
60
- // ✅ Call handler if available
61
- // @ts-expect-error safe
62
- fn?.(data.value);
63
-
64
- }
65
-
66
- } catch (e) {
67
- console.error("WebView message error:", e);
68
- }
69
- };
package/src/index.ts DELETED
@@ -1,8 +0,0 @@
1
- export { WebViewScreen } from './webviewBridge/WebViewScreen';
2
- export { sendToWeb, webviewRef } from './webviewBridge/WebViewBridgeRef';
3
- export { PathFindingResult } from './types/PathFindingResult';
4
- export { NavigationInstruction, SerializablePoint2D, SerializableNodePoint } from './types/NodePoint';
5
- export { NodePointOuterFiled, Point3D, NodeLineOuterFiled, SendToWebMessage } from './types/BridgeMessage';
6
- export { bridgeMessageStore, eventHandlers, handleBridgeMessage, registerBridgeHandler } from './handlers/WebBridgeHandlers';
7
- export { EventHandlerMap } from './handlers/WebBridgeHandlers';
8
-
@@ -1,68 +0,0 @@
1
- // Shared types
2
-
3
- import { SerializableNodePoint as NodePoint, SerializablePoint2D as Point2D } from "./NodePoint";
4
- import { PathFindingResult } from "./PathFindingResult";
5
-
6
- export interface NodePointOuterFiled {
7
- point: NodePoint, name: string, x: number, y: number, z: number
8
- }
9
-
10
-
11
- export interface Point3D extends Point2D {
12
- z: number;
13
- }
14
-
15
-
16
- export interface NodeLineOuterFiled {
17
- a: Point3D; b: Point3D;
18
- distance: number;
19
- pointA: NodePoint;
20
- pointB: NodePoint;
21
- }
22
-
23
-
24
-
25
- export type BridgeMessage =
26
- | { type: "event"; key: "floor"; value: number }
27
- | { type: "event"; key: "pathData"; value: NodePoint[] }
28
- | { type: "event"; key: "PathFindingResult"; value: PathFindingResult }
29
- | { type: "event"; key: "searchTextResult"; value: NodePoint[] }
30
- | { type: "event"; key: "shapeZoomAndSelect"; value: NodePoint | undefined }
31
- | { type: "event"; key: "searchablePoints"; value: NodePoint[] }
32
- | { type: "event"; key: "nodePoint"; value: {[key:string]: NodePointOuterFiled} }
33
- | { type: "event"; key: "nodeline"; value: {[key:string]: NodeLineOuterFiled} }
34
- | { type: "event"; key: "categoryList"; value: { [key: string]: NodePoint } }
35
- | {
36
- type: "event"; key: "floorInfo"; value: {
37
- floors: {
38
- index: number;
39
- shortName: string;
40
- fullName: string;
41
- floorNumber: number;
42
- }[],
43
- defaultFloorIndex: number
44
- }
45
- }
46
- | { type: "event"; key: "to"; value:string}
47
- | { type: "event"; key: "from"; value:string}
48
- | { type: "event"; key: "elevator"; value:"true" | "false"}
49
- | { type: "event"; key: "escalator"; value:"true" | "false"}
50
-
51
-
52
-
53
-
54
-
55
- export type SendToWebMessage =
56
- | {
57
- type: "setNavigationData";
58
- payload: {
59
- from?: string;
60
- to?: string;
61
- elevator?: boolean;
62
- escalator?: boolean;
63
- floor?: number;
64
- };
65
- }
66
- | {
67
- type: "condtiotion"; // 👈 you had this as example
68
- };
@@ -1,53 +0,0 @@
1
- // src/types/NodePoint.ts
2
-
3
- export type NavigationInstruction =
4
- | "left"
5
- | "right"
6
- | "startPoint"
7
- | "endPoint"
8
- | "Take Elevator"
9
- | "Take Escalator"
10
- | "Exit Elevator"
11
- | "Exit Escalator"
12
- | null;
13
-
14
- export type SerializablePoint2D = {
15
- x: number;
16
- y: number;
17
- };
18
-
19
- export type SerializableNodePoint = {
20
- x?: number;
21
- y?: number;
22
- z?: number;
23
- targetDist?: number;
24
- close?: boolean;
25
- elementTag?: string;
26
- type?: string;
27
- LeaseType?: string;
28
- Category?: string;
29
- color?: string;
30
- Description?: string;
31
- shape?: SerializablePoint2D[];
32
- key?: string;
33
- myAngle?: number;
34
- NavigationInstruction?: NavigationInstruction;
35
- distanceToNextPoint: number;
36
- stepsToNextPoint: number;
37
- floorBash?: boolean;
38
- brand_Id?: string | null;
39
-
40
- LocationName?: {
41
- text?: string;
42
- textColor?: string;
43
- textSize?: string;
44
- rotate?: number;
45
- };
46
-
47
- colleague?: {
48
- name: string;
49
- role?: string;
50
- }[];
51
-
52
- // NOTE: shapeMesh, texture, THREE.Vector3 are removed
53
- };
@@ -1,10 +0,0 @@
1
- // src/types/PathFindingResult.ts
2
-
3
- import { SerializableNodePoint } from "./NodePoint";
4
-
5
-
6
- export type PathFindingResult = {
7
- path: SerializableNodePoint[];
8
- totalCost: number;
9
- floor: number;
10
- };
@@ -1,15 +0,0 @@
1
- import { createRef } from "react";
2
- import type { WebView } from "react-native-webview";
3
- import type { SendToWebMessage } from "../types/BridgeMessage";
4
-
5
- // Shared WebView ref
6
- export const webviewRef = createRef<WebView>();
7
-
8
- // Exported send function
9
- export const sendToWeb = (data: SendToWebMessage) => {
10
- if (webviewRef.current) {
11
- webviewRef.current.postMessage(JSON.stringify(data));
12
- } else {
13
- console.warn("WebView not ready yet");
14
- }
15
- };
@@ -1,31 +0,0 @@
1
- import React, { useEffect, useRef } from "react";
2
- import { WebView } from "react-native-webview";
3
- import { handleBridgeMessage, registerBridgeHandler } from "../handlers/WebBridgeHandlers";
4
- import type { BridgeMessage } from "../types/BridgeMessage";
5
- import { webviewRef } from "./WebViewBridgeRef";
6
-
7
-
8
- type Props = {
9
- url: string;
10
- };
11
-
12
-
13
- export const WebViewScreen = ({ url }: Props) => {
14
-
15
-
16
- const onMessage = (event: any) => {
17
- console.log("on message event",event);
18
- handleBridgeMessage(event);
19
- };
20
-
21
-
22
-
23
- return (
24
- <WebView
25
- ref={webviewRef} // ✅ bind shared ref
26
- source={{ uri: url }}
27
- onMessage={onMessage}
28
- style={{ flex: 1 }}
29
- />
30
- );
31
- };