@apps-in-toss/framework 0.0.4 → 0.0.6
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/bin.js +4 -0
- package/dist/index.cjs +146 -69
- package/dist/index.d.cts +32 -17
- package/dist/index.d.ts +32 -17
- package/dist/index.js +139 -66
- package/dist/plugins/index.cjs +33154 -0
- package/dist/plugins/index.d.cts +36 -0
- package/dist/plugins/index.d.ts +36 -0
- package/dist/plugins/index.js +33159 -0
- package/package.json +29 -18
- package/plugins.d.ts +1 -0
- package/dist/cli-presets.cjs +0 -24
- package/dist/cli-presets.d.cts +0 -1
- package/dist/cli-presets.d.ts +0 -1
- package/dist/cli-presets.js +0 -2
package/dist/index.js
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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/
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
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) {
|
|
@@ -134,56 +170,93 @@ async function openCamera(options) {
|
|
|
134
170
|
return photo;
|
|
135
171
|
}
|
|
136
172
|
|
|
173
|
+
// src/components/WebView.tsx
|
|
174
|
+
import {
|
|
175
|
+
WebView as OriginalWebView
|
|
176
|
+
} from "@react-native-bedrock/native/react-native-webview";
|
|
177
|
+
import { useMemo } from "react";
|
|
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";
|
|
181
|
+
import { jsx } from "react/jsx-runtime";
|
|
182
|
+
function WebView({ localhostPort = 5173, onMessage, ...props }) {
|
|
183
|
+
const uri = useMemo(() => {
|
|
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
|
+
);
|
|
216
|
+
}
|
|
217
|
+
|
|
137
218
|
// src/hooks/useGeolocation.ts
|
|
138
|
-
import { useState,
|
|
219
|
+
import { useState, useEffect } from "react";
|
|
139
220
|
import { useVisibility } from "react-native-bedrock";
|
|
140
221
|
function useGeolocation({ accuracy, distanceInterval, timeInterval }) {
|
|
141
222
|
const isVisible = useVisibility();
|
|
142
|
-
const subscriptionRef = useRef();
|
|
143
223
|
const [location, setLocation] = useState(null);
|
|
144
|
-
const subscribe = useCallback(async () => {
|
|
145
|
-
try {
|
|
146
|
-
const subscription = await startUpdateLocation({
|
|
147
|
-
accuracy,
|
|
148
|
-
distanceInterval,
|
|
149
|
-
timeInterval,
|
|
150
|
-
callback: setLocation
|
|
151
|
-
});
|
|
152
|
-
subscriptionRef.current = subscription;
|
|
153
|
-
} catch (error) {
|
|
154
|
-
console.error("failed to subscribe location", error);
|
|
155
|
-
}
|
|
156
|
-
}, [accuracy, distanceInterval, timeInterval]);
|
|
157
|
-
const cleanup = useCallback(async () => {
|
|
158
|
-
try {
|
|
159
|
-
const prevSubscription = subscriptionRef.current;
|
|
160
|
-
subscriptionRef.current = void 0;
|
|
161
|
-
await prevSubscription?.remove();
|
|
162
|
-
} catch (error) {
|
|
163
|
-
console.error("failed to cleanup location subscription", error);
|
|
164
|
-
}
|
|
165
|
-
}, []);
|
|
166
224
|
useEffect(() => {
|
|
167
|
-
if (
|
|
168
|
-
|
|
225
|
+
if (!isVisible) {
|
|
226
|
+
return;
|
|
169
227
|
}
|
|
170
|
-
return (
|
|
171
|
-
|
|
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]);
|
|
172
238
|
return location;
|
|
173
239
|
}
|
|
174
240
|
|
|
241
|
+
// src/env.ts
|
|
242
|
+
var env = {
|
|
243
|
+
getDeploymentId: () => __DEV__ ? "local" : global.__appsInToss?.deploymentId
|
|
244
|
+
};
|
|
245
|
+
|
|
175
246
|
// src/types.ts
|
|
176
|
-
var
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
return
|
|
184
|
-
})(
|
|
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 || {});
|
|
185
256
|
export {
|
|
186
|
-
Accuracy,
|
|
257
|
+
Accuracy2 as Accuracy,
|
|
258
|
+
WebView,
|
|
259
|
+
env,
|
|
187
260
|
fetchAlbumPhotos,
|
|
188
261
|
fetchContacts,
|
|
189
262
|
getClipboardText,
|