wovvmap-webview-bridge 1.0.4 → 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.
@@ -1,38 +1,18 @@
1
1
  import type { WebViewMessageEvent } from "react-native-webview";
2
- import type { NodeLineOuterFiled, NodePointOuterFiled } from "../types/BridgeMessage";
3
- import { PathFindingResult } from "../types/PathFindingResult";
4
- import { SerializableNodePoint as NodePoint } from "../types/NodePoint";
2
+ import { NodePoint } from "../types/types";
5
3
  export type EventHandlerMap = {
6
- floor?: (floor: number) => void;
7
- pathData?: (val: NodePoint[]) => void;
8
- PathFindingResult?: (val: PathFindingResult) => void;
9
- searchTextResult?: (val: NodePoint[]) => void;
10
- shapeZoomAndSelect?: (val: NodePoint | undefined) => void;
11
- searchablePoints?: (val: NodePoint[]) => void;
12
- nodePoint?: (val: {
13
- [key: string]: NodePointOuterFiled;
4
+ isSceneClick?: (sceneClick: {
5
+ type: "event";
6
+ key: "isSceneClick";
7
+ file: string;
14
8
  }) => void;
15
- nodeline?: (val: {
16
- [key: string]: NodeLineOuterFiled;
9
+ isShapClick?: (shapClick: {
10
+ type: "event";
11
+ key: "isShapClick";
12
+ value: NodePoint;
13
+ file: string;
17
14
  }) => void;
18
- categoryList?: (val: {
19
- [key: string]: NodePoint;
20
- }) => void;
21
- floorInfo?: (val: {
22
- floors: {
23
- index: number;
24
- shortName: string;
25
- fullName: string;
26
- floorNumber: number;
27
- }[];
28
- defaultFloorIndex: number;
29
- }) => void;
30
- to?: (val: string) => void;
31
- from?: (val: string) => void;
32
- elevator?: (val: "true" | "false") => void;
33
- escalator?: (val: "true" | "false") => void;
34
15
  };
35
16
  export declare const eventHandlers: Partial<EventHandlerMap>;
36
- export declare const bridgeMessageStore: Partial<Record<keyof EventHandlerMap, any>>;
37
17
  export declare const registerBridgeHandler: <K extends keyof EventHandlerMap>(type: K, handler: EventHandlerMap[K]) => void;
38
18
  export declare const handleBridgeMessage: (event: WebViewMessageEvent) => void;
@@ -1,24 +1,33 @@
1
+ import { bridgeStorage } from "../webviewBridge/BridgeStorage";
1
2
  // ✅ 2. Global handler storage
2
3
  export var eventHandlers = {};
3
- // ✅ 3. Runtime key-value store for all event data
4
- export var bridgeMessageStore = {};
5
4
  // ✅ 4. Register handler function
6
5
  export var registerBridgeHandler = function (type, handler) {
7
6
  eventHandlers[type] = handler;
8
7
  };
9
8
  // ✅ 5. Main bridge handler
10
9
  export var handleBridgeMessage = function (event) {
10
+ var _a, _b;
11
11
  try {
12
- var data = JSON.parse(event.nativeEvent.data);
13
- if (data.type === "event") {
14
- var key = data.key;
15
- var fn = eventHandlers[key];
16
- // ✅ Store latest data in bridgeMessageStore
17
- bridgeMessageStore[key] = data.value;
18
- // ✅ Call handler if available
19
- // @ts-expect-error safe
20
- fn === null || fn === void 0 ? void 0 : fn(data.value);
21
- }
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);
22
31
  }
23
32
  catch (e) {
24
33
  console.error("WebView message error:", e);
package/dist/index.d.ts CHANGED
@@ -1,7 +1,4 @@
1
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';
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
+ });
@@ -1,4 +1,4 @@
1
1
  import type { WebView } from "react-native-webview";
2
- import type { SendToWebMessage } from "../types/BridgeMessage";
2
+ import { OutgoingMessage } from "../types/types";
3
3
  export declare const webviewRef: import("react").RefObject<WebView<{}> | null>;
4
- export declare const sendToWeb: (data: SendToWebMessage) => void;
4
+ export declare const sendToWeb: (data: OutgoingMessage) => void;
@@ -3,7 +3,9 @@ import { createRef } from "react";
3
3
  export var webviewRef = createRef();
4
4
  // Exported send function
5
5
  export var sendToWeb = function (data) {
6
+ console.log("webviweRef", webviewRef);
6
7
  if (webviewRef.current) {
8
+ console.log("enter current");
7
9
  webviewRef.current.postMessage(JSON.stringify(data));
8
10
  }
9
11
  else {
@@ -1,12 +1,15 @@
1
1
  import React from "react";
2
- import { WebView } from "react-native-webview";
3
2
  import { handleBridgeMessage } from "../handlers/WebBridgeHandlers";
4
3
  import { webviewRef } from "./WebViewBridgeRef";
4
+ import { WebView } from 'react-native-webview';
5
5
  export var WebViewScreen = function (_a) {
6
6
  var url = _a.url;
7
7
  var onMessage = function (event) {
8
8
  console.log("on message event", event);
9
9
  handleBridgeMessage(event);
10
10
  };
11
- return (React.createElement(WebView, { ref: webviewRef, source: { uri: url }, onMessage: onMessage, style: { flex: 1 } }));
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%" } }));
12
15
  };
package/package.json CHANGED
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "name": "wovvmap-webview-bridge",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "files": [
7
- "dist"
7
+ "dist"
8
8
  ],
9
9
  "scripts": {
10
10
  "build": "tsc "
@@ -12,9 +12,11 @@
12
12
  "peerDependencies": {
13
13
  "react": "^19.1.0",
14
14
  "react-native": "^0.80.1",
15
- "react-native-webview": "^13.15.0"
15
+ "react-native-webview": "^13.15.0",
16
+ "koshin": "^1.0.5"
16
17
  },
17
18
  "devDependencies": {
18
19
  "@types/react": "^19.1.8"
19
20
  }
21
+
20
22
  }
@@ -1,102 +0,0 @@
1
- import { SerializableNodePoint as NodePoint, SerializablePoint2D as Point2D } from "./NodePoint";
2
- import { PathFindingResult } from "./PathFindingResult";
3
- export interface NodePointOuterFiled {
4
- point: NodePoint;
5
- name: string;
6
- x: number;
7
- y: number;
8
- z: number;
9
- }
10
- export interface Point3D extends Point2D {
11
- z: number;
12
- }
13
- export interface NodeLineOuterFiled {
14
- a: Point3D;
15
- b: Point3D;
16
- distance: number;
17
- pointA: NodePoint;
18
- pointB: NodePoint;
19
- }
20
- export type BridgeMessage = {
21
- type: "event";
22
- key: "floor";
23
- value: number;
24
- } | {
25
- type: "event";
26
- key: "pathData";
27
- value: NodePoint[];
28
- } | {
29
- type: "event";
30
- key: "PathFindingResult";
31
- value: PathFindingResult;
32
- } | {
33
- type: "event";
34
- key: "searchTextResult";
35
- value: NodePoint[];
36
- } | {
37
- type: "event";
38
- key: "shapeZoomAndSelect";
39
- value: NodePoint | undefined;
40
- } | {
41
- type: "event";
42
- key: "searchablePoints";
43
- value: NodePoint[];
44
- } | {
45
- type: "event";
46
- key: "nodePoint";
47
- value: {
48
- [key: string]: NodePointOuterFiled;
49
- };
50
- } | {
51
- type: "event";
52
- key: "nodeline";
53
- value: {
54
- [key: string]: NodeLineOuterFiled;
55
- };
56
- } | {
57
- type: "event";
58
- key: "categoryList";
59
- value: {
60
- [key: string]: NodePoint;
61
- };
62
- } | {
63
- type: "event";
64
- key: "floorInfo";
65
- value: {
66
- floors: {
67
- index: number;
68
- shortName: string;
69
- fullName: string;
70
- floorNumber: number;
71
- }[];
72
- defaultFloorIndex: number;
73
- };
74
- } | {
75
- type: "event";
76
- key: "to";
77
- value: string;
78
- } | {
79
- type: "event";
80
- key: "from";
81
- value: string;
82
- } | {
83
- type: "event";
84
- key: "elevator";
85
- value: "true" | "false";
86
- } | {
87
- type: "event";
88
- key: "escalator";
89
- value: "true" | "false";
90
- };
91
- export type SendToWebMessage = {
92
- type: "setNavigationData";
93
- payload: {
94
- from?: string;
95
- to?: string;
96
- elevator?: boolean;
97
- escalator?: boolean;
98
- floor?: number;
99
- };
100
- } | {
101
- type: "condtiotion";
102
- };
@@ -1,2 +0,0 @@
1
- // Shared types
2
- export {};
@@ -1,36 +0,0 @@
1
- export type NavigationInstruction = "left" | "right" | "startPoint" | "endPoint" | "Take Elevator" | "Take Escalator" | "Exit Elevator" | "Exit Escalator" | null;
2
- export type SerializablePoint2D = {
3
- x: number;
4
- y: number;
5
- };
6
- export type SerializableNodePoint = {
7
- x?: number;
8
- y?: number;
9
- z?: number;
10
- targetDist?: number;
11
- close?: boolean;
12
- elementTag?: string;
13
- type?: string;
14
- LeaseType?: string;
15
- Category?: string;
16
- color?: string;
17
- Description?: string;
18
- shape?: SerializablePoint2D[];
19
- key?: string;
20
- myAngle?: number;
21
- NavigationInstruction?: NavigationInstruction;
22
- distanceToNextPoint: number;
23
- stepsToNextPoint: number;
24
- floorBash?: boolean;
25
- brand_Id?: string | null;
26
- LocationName?: {
27
- text?: string;
28
- textColor?: string;
29
- textSize?: string;
30
- rotate?: number;
31
- };
32
- colleague?: {
33
- name: string;
34
- role?: string;
35
- }[];
36
- };
@@ -1,2 +0,0 @@
1
- // src/types/NodePoint.ts
2
- export {};
@@ -1,6 +0,0 @@
1
- import { SerializableNodePoint } from "./NodePoint";
2
- export type PathFindingResult = {
3
- path: SerializableNodePoint[];
4
- totalCost: number;
5
- floor: number;
6
- };
@@ -1,2 +0,0 @@
1
- // src/types/PathFindingResult.ts
2
- export {};