@apps-in-toss/framework 0.0.5 → 0.0.7

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/dist/index.js CHANGED
@@ -1,14 +1,26 @@
1
- // src/native-event-emitter/nativeEventEmitter.ts
2
- import { NativeEventEmitter } from "react-native";
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ // src/native-event-emitter/index.ts
8
+ var native_event_emitter_exports = {};
9
+ __export(native_event_emitter_exports, {
10
+ startUpdateLocation: () => startUpdateLocation
11
+ });
12
+
13
+ // src/native-event-emitter/bedrock-event.ts
14
+ import { BedrockEvent } from "react-native-bedrock";
15
+
16
+ // src/native-event-emitter/event-plugins/UpdateLocationEvent.ts
17
+ import { BedrockEventDefinition } from "react-native-bedrock";
3
18
 
4
19
  // src/native-modules/AppsInTossModule.ts
5
20
  import { NativeModules } from "react-native";
6
21
  var AppsInTossModuleInstance = NativeModules.AppsInTossModule;
7
22
  var AppsInTossModule = AppsInTossModuleInstance;
8
23
 
9
- // src/native-event-emitter/nativeEventEmitter.ts
10
- var nativeEventEmitter = new NativeEventEmitter(AppsInTossModuleInstance);
11
-
12
24
  // src/native-modules/getPermission.ts
13
25
  function getPermission(permission) {
14
26
  return AppsInTossModule.getPermission(permission);
@@ -31,32 +43,56 @@ async function requestPermission(permission) {
31
43
  }
32
44
  }
33
45
 
34
- // src/native-event-emitter/startUpdateLocation.ts
35
- async function startUpdateLocation(options) {
36
- const { callback, ...nativeOptions } = options;
37
- const permissionStatus = await requestPermission({ name: "geolocation", access: "access" });
38
- if (permissionStatus === "denied") {
39
- throw new Error("\uC704\uCE58 \uAD8C\uD55C\uC774 \uAC70\uBD80\uB418\uC5C8\uC5B4\uC694.");
46
+ // src/native-event-emitter/nativeEventEmitter.ts
47
+ import { NativeEventEmitter } from "react-native";
48
+ var nativeEventEmitter = new NativeEventEmitter(AppsInTossModuleInstance);
49
+
50
+ // src/native-event-emitter/event-plugins/UpdateLocationEvent.ts
51
+ var UpdateLocationEvent = class extends BedrockEventDefinition {
52
+ name = "updateLocationEvent";
53
+ subscriptionCount = 0;
54
+ ref = {
55
+ remove: () => {
56
+ }
57
+ };
58
+ remove() {
59
+ --this.subscriptionCount === 0 && AppsInTossModuleInstance.stopUpdateLocation({});
60
+ this.ref.remove();
40
61
  }
41
- await AppsInTossModuleInstance.startUpdateLocation(nativeOptions);
42
- const subscription = nativeEventEmitter.addListener("updateLocation", callback);
43
- subscriptionCount++;
44
- const subscriptionProxy = new Proxy(subscription, {
45
- get: (target, key, receiver) => {
46
- const result = Reflect.get(target, key, receiver);
47
- if (key === "remove") {
48
- return async () => {
49
- await (--subscriptionCount === 0 && AppsInTossModuleInstance.stopUpdateLocation({}));
50
- const remove = result;
51
- remove();
52
- };
62
+ listener(options, onEvent, onError) {
63
+ requestPermission({ name: "geolocation", access: "access" }).then((permissionStatus) => {
64
+ if (permissionStatus === "denied") {
65
+ onError(new Error("\uC704\uCE58 \uAD8C\uD55C\uC774 \uAC70\uBD80\uB418\uC5C8\uC5B4\uC694."));
66
+ return;
53
67
  }
54
- return result;
55
- }
56
- });
57
- return subscriptionProxy;
68
+ void AppsInTossModuleInstance.startUpdateLocation(options).catch(onError);
69
+ const subscription = nativeEventEmitter.addListener("updateLocation", onEvent);
70
+ this.ref = {
71
+ remove: () => subscription?.remove()
72
+ };
73
+ this.subscriptionCount++;
74
+ }).catch(onError);
75
+ }
76
+ };
77
+
78
+ // src/native-event-emitter/bedrock-event.ts
79
+ var appsInTossEvent = new BedrockEvent([new UpdateLocationEvent()]);
80
+
81
+ // src/native-event-emitter/startUpdateLocation.ts
82
+ function startUpdateLocation(eventParams) {
83
+ return appsInTossEvent.addEventListener("updateLocationEvent", eventParams);
58
84
  }
59
- var subscriptionCount = 0;
85
+
86
+ // src/native-modules/index.ts
87
+ var native_modules_exports = {};
88
+ __export(native_modules_exports, {
89
+ fetchAlbumPhotos: () => fetchAlbumPhotos,
90
+ fetchContacts: () => fetchContacts,
91
+ getClipboardText: () => getClipboardText,
92
+ getCurrentLocation: () => getCurrentLocation,
93
+ openCamera: () => openCamera,
94
+ setClipboardText: () => setClipboardText
95
+ });
60
96
 
61
97
  // src/native-modules/setClipboardText.ts
62
98
  async function setClipboardText(text) {
@@ -139,88 +175,88 @@ import {
139
175
  WebView as OriginalWebView
140
176
  } from "@react-native-bedrock/native/react-native-webview";
141
177
  import { useMemo } from "react";
142
- import { Bedrock } from "react-native-bedrock";
143
-
144
- // src/components/getAppsInTossWebViewUrl.tsx
145
- function getAppsInTossWebViewUrl({
146
- appName,
147
- groupId,
148
- localhostPort,
149
- env
150
- }) {
151
- if (env === "local") {
152
- return `http://localhost:${localhostPort}`;
153
- }
154
- const subdomain = env === "alpha" ? "alpha-apps" : "apps";
155
- return `https://${appName}--${groupId}.${subdomain}.tossmini.com`;
156
- }
157
-
158
- // src/components/WebView.tsx
178
+ import { useBridgeHandler } from "react-native-bedrock";
179
+ import * as bridges from "react-native-bedrock/bridges";
180
+ import * as constantBridges from "react-native-bedrock/constants";
159
181
  import { jsx } from "react/jsx-runtime";
160
- function WebView({ env, localhostPort = 5173, ...props }) {
182
+ function WebView({ localhostPort = 5173, onMessage, ...props }) {
161
183
  const uri = useMemo(() => {
162
- const $env = env ?? (__DEV__ ? "local" : AppsInTossModule.operationalEnvironment === "sandbox" ? "alpha" : "production");
163
- return getAppsInTossWebViewUrl({
164
- appName: Bedrock.appName,
165
- groupId: AppsInTossModule.groupId,
166
- localhostPort,
167
- env: $env
168
- });
169
- }, [env, localhostPort]);
170
- return /* @__PURE__ */ jsx(OriginalWebView, { source: { uri }, ...props });
184
+ if (__DEV__) {
185
+ return `http://localhost:${localhostPort}`;
186
+ }
187
+ return AppsInTossModule.getWebBundleURL({}).url;
188
+ }, [localhostPort]);
189
+ const handler = useBridgeHandler({
190
+ onMessage,
191
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
192
+ eventListenerMap: native_event_emitter_exports,
193
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
194
+ // @ts-expect-error
195
+ constantHandlerMap: constantBridges,
196
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
197
+ // @ts-expect-error
198
+ handlerMap: {
199
+ ...bridges,
200
+ ...native_modules_exports
201
+ }
202
+ });
203
+ return /* @__PURE__ */ jsx(
204
+ OriginalWebView,
205
+ {
206
+ ref: handler.ref,
207
+ ...props,
208
+ source: { uri },
209
+ sharedCookiesEnabled: true,
210
+ thirdPartyCookiesEnabled: true,
211
+ onMessage: handler.onMessage,
212
+ injectedJavaScript: handler.injectedJavaScript,
213
+ injectedJavaScriptBeforeContentLoaded: handler.injectedJavaScript
214
+ }
215
+ );
171
216
  }
172
217
 
173
218
  // src/hooks/useGeolocation.ts
174
- import { useState, useCallback, useEffect, useRef } from "react";
219
+ import { useState, useEffect } from "react";
175
220
  import { useVisibility } from "react-native-bedrock";
176
221
  function useGeolocation({ accuracy, distanceInterval, timeInterval }) {
177
222
  const isVisible = useVisibility();
178
- const subscriptionRef = useRef();
179
223
  const [location, setLocation] = useState(null);
180
- const subscribe = useCallback(async () => {
181
- try {
182
- const subscription = await startUpdateLocation({
183
- accuracy,
184
- distanceInterval,
185
- timeInterval,
186
- callback: setLocation
187
- });
188
- subscriptionRef.current = subscription;
189
- } catch (error) {
190
- console.error("failed to subscribe location", error);
191
- }
192
- }, [accuracy, distanceInterval, timeInterval]);
193
- const cleanup = useCallback(async () => {
194
- try {
195
- const prevSubscription = subscriptionRef.current;
196
- subscriptionRef.current = void 0;
197
- await prevSubscription?.remove();
198
- } catch (error) {
199
- console.error("failed to cleanup location subscription", error);
200
- }
201
- }, []);
202
224
  useEffect(() => {
203
- if (subscriptionRef.current == null && isVisible) {
204
- subscribe();
225
+ if (!isVisible) {
226
+ return;
205
227
  }
206
- return () => void cleanup();
207
- }, [subscribe, cleanup, isVisible]);
228
+ return startUpdateLocation({
229
+ options: {
230
+ accuracy,
231
+ distanceInterval,
232
+ timeInterval
233
+ },
234
+ onEvent: setLocation,
235
+ onError: console.error
236
+ });
237
+ }, [accuracy, distanceInterval, timeInterval, isVisible]);
208
238
  return location;
209
239
  }
210
240
 
241
+ // src/env.ts
242
+ var env = {
243
+ getDeploymentId: () => __DEV__ ? "local" : global.__appsInToss?.deploymentId
244
+ };
245
+
211
246
  // src/types.ts
212
- var Accuracy = /* @__PURE__ */ ((Accuracy2) => {
213
- Accuracy2[Accuracy2["Lowest"] = 1] = "Lowest";
214
- Accuracy2[Accuracy2["Low"] = 2] = "Low";
215
- Accuracy2[Accuracy2["Balanced"] = 3] = "Balanced";
216
- Accuracy2[Accuracy2["High"] = 4] = "High";
217
- Accuracy2[Accuracy2["Highest"] = 5] = "Highest";
218
- Accuracy2[Accuracy2["BestForNavigation"] = 6] = "BestForNavigation";
219
- return Accuracy2;
220
- })(Accuracy || {});
247
+ var Accuracy2 = /* @__PURE__ */ ((Accuracy3) => {
248
+ Accuracy3[Accuracy3["Lowest"] = 1] = "Lowest";
249
+ Accuracy3[Accuracy3["Low"] = 2] = "Low";
250
+ Accuracy3[Accuracy3["Balanced"] = 3] = "Balanced";
251
+ Accuracy3[Accuracy3["High"] = 4] = "High";
252
+ Accuracy3[Accuracy3["Highest"] = 5] = "Highest";
253
+ Accuracy3[Accuracy3["BestForNavigation"] = 6] = "BestForNavigation";
254
+ return Accuracy3;
255
+ })(Accuracy2 || {});
221
256
  export {
222
- Accuracy,
257
+ Accuracy2 as Accuracy,
223
258
  WebView,
259
+ env,
224
260
  fetchAlbumPhotos,
225
261
  fetchContacts,
226
262
  getClipboardText,
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+
17
+ // src/jest/index.ts
18
+ var jest_exports = {};
19
+ module.exports = __toCommonJS(jest_exports);
20
+ __reExport(jest_exports, require("react-native-bedrock/jest"), module.exports);
21
+ // Annotate the CommonJS export names for ESM import in node:
22
+ 0 && (module.exports = {
23
+ ...require("react-native-bedrock/jest")
24
+ });
@@ -0,0 +1 @@
1
+ export * from 'react-native-bedrock/jest';
@@ -0,0 +1 @@
1
+ export * from 'react-native-bedrock/jest';
@@ -0,0 +1,4 @@
1
+ import { createRequire } from 'module'; const require = createRequire(import.meta.url);
2
+
3
+ // src/jest/index.ts
4
+ export * from "react-native-bedrock/jest";