jazz-tools 0.15.3 → 0.15.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.
- package/.turbo/turbo-build.log +40 -40
- package/CHANGELOG.md +22 -0
- package/dist/react/index.js +1 -2
- package/dist/react/index.js.map +1 -1
- package/dist/react/provider.d.ts.map +1 -1
- package/dist/react/testing.js +0 -2
- package/dist/react/testing.js.map +1 -1
- package/dist/react-native-core/index.d.ts +1 -1
- package/dist/react-native-core/index.d.ts.map +1 -1
- package/dist/react-native-core/index.js +369 -369
- package/dist/react-native-core/index.js.map +1 -1
- package/dist/react-native-core/platform.d.ts +3 -3
- package/dist/react-native-core/platform.d.ts.map +1 -1
- package/dist/react-native-core/provider.d.ts +2 -2
- package/dist/react-native-core/provider.d.ts.map +1 -1
- package/package.json +30 -12
- package/src/react/provider.tsx +1 -0
- package/src/react-native-core/index.ts +1 -1
- package/src/react-native-core/platform.ts +1 -4
- package/src/react-native-core/provider.tsx +8 -7
@@ -1,21 +1,3 @@
|
|
1
|
-
// src/react-native-core/provider.tsx
|
2
|
-
import { JazzContext, JazzContextManagerContext } from "jazz-tools/react-core";
|
3
|
-
import React, { useEffect, useRef } from "react";
|
4
|
-
|
5
|
-
// src/react-native-core/ReactNativeContextManager.ts
|
6
|
-
import {
|
7
|
-
JazzContextManager
|
8
|
-
} from "jazz-tools";
|
9
|
-
|
10
|
-
// src/react-native-core/platform.ts
|
11
|
-
import NetInfo from "@react-native-community/netinfo";
|
12
|
-
import { PureJSCrypto } from "cojson/dist/crypto/PureJSCrypto";
|
13
|
-
import {
|
14
|
-
createInviteLink as baseCreateInviteLink,
|
15
|
-
createAnonymousJazzContext,
|
16
|
-
createJazzContext
|
17
|
-
} from "jazz-tools";
|
18
|
-
|
19
1
|
// src/react-native-core/storage/kv-store-context.ts
|
20
2
|
var KvStoreContext = class _KvStoreContext {
|
21
3
|
constructor() {
|
@@ -43,33 +25,366 @@ var KvStoreContext = class _KvStoreContext {
|
|
43
25
|
}
|
44
26
|
};
|
45
27
|
|
46
|
-
// src/react-native-core/
|
47
|
-
import {
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
28
|
+
// src/react-native-core/auth/DemoAuthUI.tsx
|
29
|
+
import { useState } from "react";
|
30
|
+
import {
|
31
|
+
StyleSheet,
|
32
|
+
Text,
|
33
|
+
TextInput,
|
34
|
+
TouchableOpacity,
|
35
|
+
View,
|
36
|
+
useColorScheme
|
37
|
+
} from "react-native";
|
38
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
39
|
+
var DemoAuthBasicUI = ({
|
40
|
+
appName,
|
41
|
+
auth,
|
42
|
+
children
|
43
|
+
}) => {
|
44
|
+
const colorScheme = useColorScheme();
|
45
|
+
const darkMode = colorScheme === "dark";
|
46
|
+
const [username, setUsername] = useState("");
|
47
|
+
const [errorMessage, setErrorMessage] = useState(null);
|
48
|
+
const handleSignUp = () => {
|
49
|
+
setErrorMessage(null);
|
50
|
+
auth.signUp(username).catch((error) => {
|
51
|
+
setErrorMessage(error.message);
|
52
|
+
});
|
53
|
+
};
|
54
|
+
const handleLogIn = (username2) => {
|
55
|
+
setErrorMessage(null);
|
56
|
+
auth.logIn(username2).catch((error) => {
|
57
|
+
setErrorMessage(error.message);
|
56
58
|
});
|
59
|
+
};
|
60
|
+
if (auth.state === "signedIn") {
|
61
|
+
return children;
|
57
62
|
}
|
63
|
+
return /* @__PURE__ */ jsx(
|
64
|
+
View,
|
65
|
+
{
|
66
|
+
style: [
|
67
|
+
styles.container,
|
68
|
+
darkMode ? styles.darkBackground : styles.lightBackground
|
69
|
+
],
|
70
|
+
children: /* @__PURE__ */ jsxs(View, { style: styles.formContainer, children: [
|
71
|
+
/* @__PURE__ */ jsx(
|
72
|
+
Text,
|
73
|
+
{
|
74
|
+
style: [
|
75
|
+
styles.headerText,
|
76
|
+
darkMode ? styles.darkText : styles.lightText
|
77
|
+
],
|
78
|
+
children: appName
|
79
|
+
}
|
80
|
+
),
|
81
|
+
errorMessage && /* @__PURE__ */ jsx(Text, { style: styles.errorText, children: errorMessage }),
|
82
|
+
/* @__PURE__ */ jsx(
|
83
|
+
TextInput,
|
84
|
+
{
|
85
|
+
placeholder: "Display name",
|
86
|
+
value: username,
|
87
|
+
onChangeText: setUsername,
|
88
|
+
placeholderTextColor: darkMode ? "#fff" : "#000",
|
89
|
+
style: [
|
90
|
+
styles.textInput,
|
91
|
+
darkMode ? styles.darkInput : styles.lightInput
|
92
|
+
]
|
93
|
+
}
|
94
|
+
),
|
95
|
+
/* @__PURE__ */ jsx(
|
96
|
+
TouchableOpacity,
|
97
|
+
{
|
98
|
+
onPress: handleSignUp,
|
99
|
+
style: [
|
100
|
+
styles.button,
|
101
|
+
darkMode ? styles.darkButton : styles.lightButton
|
102
|
+
],
|
103
|
+
children: /* @__PURE__ */ jsx(
|
104
|
+
Text,
|
105
|
+
{
|
106
|
+
style: darkMode ? styles.darkButtonText : styles.lightButtonText,
|
107
|
+
children: "Sign Up as new account"
|
108
|
+
}
|
109
|
+
)
|
110
|
+
}
|
111
|
+
),
|
112
|
+
/* @__PURE__ */ jsx(View, { style: styles.existingUsersContainer, children: auth.existingUsers.map((user) => /* @__PURE__ */ jsx(
|
113
|
+
TouchableOpacity,
|
114
|
+
{
|
115
|
+
onPress: () => handleLogIn(user),
|
116
|
+
style: [
|
117
|
+
styles.existingUserButton,
|
118
|
+
darkMode ? styles.darkUserButton : styles.lightUserButton
|
119
|
+
],
|
120
|
+
children: /* @__PURE__ */ jsxs(Text, { style: darkMode ? styles.darkText : styles.lightText, children: [
|
121
|
+
'Log In as "',
|
122
|
+
user,
|
123
|
+
'"'
|
124
|
+
] })
|
125
|
+
},
|
126
|
+
user
|
127
|
+
)) })
|
128
|
+
] })
|
129
|
+
}
|
130
|
+
);
|
58
131
|
};
|
132
|
+
var styles = StyleSheet.create({
|
133
|
+
container: {
|
134
|
+
flex: 1,
|
135
|
+
justifyContent: "center",
|
136
|
+
alignItems: "center",
|
137
|
+
padding: 20
|
138
|
+
},
|
139
|
+
formContainer: {
|
140
|
+
width: "80%",
|
141
|
+
alignItems: "center",
|
142
|
+
justifyContent: "center"
|
143
|
+
},
|
144
|
+
headerText: {
|
145
|
+
fontSize: 24,
|
146
|
+
marginBottom: 20
|
147
|
+
},
|
148
|
+
errorText: {
|
149
|
+
color: "red",
|
150
|
+
marginVertical: 5,
|
151
|
+
textAlign: "center"
|
152
|
+
},
|
153
|
+
textInput: {
|
154
|
+
borderWidth: 1,
|
155
|
+
padding: 10,
|
156
|
+
marginVertical: 10,
|
157
|
+
width: "100%",
|
158
|
+
borderRadius: 6
|
159
|
+
},
|
160
|
+
darkInput: {
|
161
|
+
borderColor: "#444",
|
162
|
+
backgroundColor: "#000",
|
163
|
+
color: "#fff"
|
164
|
+
},
|
165
|
+
lightInput: {
|
166
|
+
borderColor: "#ddd",
|
167
|
+
backgroundColor: "#fff",
|
168
|
+
color: "#000"
|
169
|
+
},
|
170
|
+
button: {
|
171
|
+
paddingVertical: 15,
|
172
|
+
paddingHorizontal: 10,
|
173
|
+
borderRadius: 6,
|
174
|
+
width: "100%",
|
175
|
+
marginVertical: 10
|
176
|
+
},
|
177
|
+
darkButton: {
|
178
|
+
backgroundColor: "#444"
|
179
|
+
},
|
180
|
+
lightButton: {
|
181
|
+
backgroundColor: "#ddd"
|
182
|
+
},
|
183
|
+
darkButtonText: {
|
184
|
+
color: "#fff",
|
185
|
+
textAlign: "center"
|
186
|
+
},
|
187
|
+
lightButtonText: {
|
188
|
+
color: "#000",
|
189
|
+
textAlign: "center"
|
190
|
+
},
|
191
|
+
existingUsersContainer: {
|
192
|
+
width: "100%",
|
193
|
+
marginTop: 20
|
194
|
+
},
|
195
|
+
existingUserButton: {
|
196
|
+
paddingVertical: 15,
|
197
|
+
paddingHorizontal: 10,
|
198
|
+
borderRadius: 6,
|
199
|
+
marginVertical: 5
|
200
|
+
},
|
201
|
+
darkUserButton: {
|
202
|
+
backgroundColor: "#222"
|
203
|
+
},
|
204
|
+
lightUserButton: {
|
205
|
+
backgroundColor: "#eee"
|
206
|
+
},
|
207
|
+
loadingText: {
|
208
|
+
fontSize: 18,
|
209
|
+
color: "#888"
|
210
|
+
},
|
211
|
+
darkText: {
|
212
|
+
color: "#fff"
|
213
|
+
},
|
214
|
+
lightText: {
|
215
|
+
color: "#000"
|
216
|
+
},
|
217
|
+
darkBackground: {
|
218
|
+
backgroundColor: "#000"
|
219
|
+
},
|
220
|
+
lightBackground: {
|
221
|
+
backgroundColor: "#fff"
|
222
|
+
}
|
223
|
+
});
|
59
224
|
|
60
|
-
// src/react-native-core/
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
225
|
+
// src/react-native-core/auth/auth.ts
|
226
|
+
function clearUserCredentials() {
|
227
|
+
const kvStore = KvStoreContext.getInstance().getStorage();
|
228
|
+
return Promise.all([
|
229
|
+
kvStore.delete("demo-auth-logged-in-secret"),
|
230
|
+
kvStore.delete("jazz-clerk-auth"),
|
231
|
+
kvStore.delete("jazz-logged-in-secret")
|
232
|
+
]);
|
233
|
+
}
|
234
|
+
|
235
|
+
// src/react-native-core/hooks.tsx
|
236
|
+
import { useEffect } from "react";
|
237
|
+
import { parseInviteLink } from "jazz-tools";
|
238
|
+
import { useJazzContext } from "jazz-tools/react-core";
|
239
|
+
import { Linking } from "react-native";
|
240
|
+
import {
|
241
|
+
useCoState,
|
242
|
+
experimental_useInboxSender,
|
243
|
+
useDemoAuth,
|
244
|
+
usePassphraseAuth,
|
245
|
+
useJazzContext as useJazzContext2,
|
246
|
+
useAuthSecretStorage,
|
247
|
+
useIsAuthenticated,
|
248
|
+
useAccount
|
249
|
+
} from "jazz-tools/react-core";
|
250
|
+
function useAcceptInviteNative({
|
251
|
+
invitedObjectSchema,
|
252
|
+
onAccept,
|
253
|
+
forValueHint
|
254
|
+
}) {
|
255
|
+
const context = useJazzContext();
|
256
|
+
if (!("me" in context)) {
|
257
|
+
throw new Error(
|
258
|
+
"useAcceptInviteNative can't be used in a JazzProvider with auth === 'guest'."
|
66
259
|
);
|
67
260
|
}
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
261
|
+
useEffect(() => {
|
262
|
+
const handleDeepLink = ({ url }) => {
|
263
|
+
const result = parseInviteLink(url);
|
264
|
+
if (result && result.valueHint === forValueHint) {
|
265
|
+
context.me.acceptInvite(
|
266
|
+
result.valueID,
|
267
|
+
result.inviteSecret,
|
268
|
+
invitedObjectSchema
|
269
|
+
).then(() => {
|
270
|
+
onAccept(result.valueID);
|
271
|
+
}).catch((e) => {
|
272
|
+
console.error("Failed to accept invite", e);
|
273
|
+
});
|
274
|
+
}
|
275
|
+
};
|
276
|
+
const linkingListener = Linking.addEventListener("url", handleDeepLink);
|
277
|
+
void Linking.getInitialURL().then((url) => {
|
278
|
+
if (url) handleDeepLink({ url });
|
279
|
+
});
|
280
|
+
return () => {
|
281
|
+
linkingListener.remove();
|
282
|
+
};
|
283
|
+
}, [context, onAccept, invitedObjectSchema, forValueHint]);
|
284
|
+
}
|
285
|
+
|
286
|
+
// src/react-native-core/media.tsx
|
287
|
+
import { ImageDefinition } from "jazz-tools";
|
288
|
+
import { useEffect as useEffect2, useState as useState2 } from "react";
|
289
|
+
function useProgressiveImgNative({
|
290
|
+
image,
|
291
|
+
maxWidth,
|
292
|
+
targetWidth
|
293
|
+
}) {
|
294
|
+
const [current, setCurrent] = useState2(void 0);
|
295
|
+
useEffect2(() => {
|
296
|
+
let lastHighestRes;
|
297
|
+
if (!image) return;
|
298
|
+
const unsub = image.subscribe({}, (update) => {
|
299
|
+
const highestRes = ImageDefinition.highestResAvailable(update, {
|
300
|
+
maxWidth,
|
301
|
+
targetWidth
|
302
|
+
});
|
303
|
+
if (highestRes && highestRes.res !== lastHighestRes) {
|
304
|
+
lastHighestRes = highestRes.res;
|
305
|
+
const dataUrl = highestRes.stream.asBase64({ dataURL: true });
|
306
|
+
if (dataUrl) {
|
307
|
+
setCurrent({
|
308
|
+
src: dataUrl,
|
309
|
+
res: highestRes.res
|
310
|
+
});
|
311
|
+
} else {
|
312
|
+
console.warn("No chunks available for image", image.id);
|
313
|
+
setCurrent({
|
314
|
+
src: update?.placeholderDataURL,
|
315
|
+
res: "placeholder"
|
316
|
+
});
|
317
|
+
}
|
318
|
+
} else if (!highestRes) {
|
319
|
+
setCurrent({
|
320
|
+
src: update?.placeholderDataURL,
|
321
|
+
res: "placeholder"
|
322
|
+
});
|
323
|
+
}
|
324
|
+
});
|
325
|
+
return unsub;
|
326
|
+
}, [image?.id, maxWidth]);
|
327
|
+
return {
|
328
|
+
src: current?.src,
|
329
|
+
res: current?.res,
|
330
|
+
originalSize: image?.originalSize
|
331
|
+
};
|
332
|
+
}
|
333
|
+
function ProgressiveImgNative({
|
334
|
+
children,
|
335
|
+
image,
|
336
|
+
maxWidth,
|
337
|
+
targetWidth
|
338
|
+
}) {
|
339
|
+
const result = useProgressiveImgNative({ image, maxWidth, targetWidth });
|
340
|
+
return result && children(result);
|
341
|
+
}
|
342
|
+
|
343
|
+
// src/react-native-core/provider.tsx
|
344
|
+
import { JazzContext, JazzContextManagerContext } from "jazz-tools/react-core";
|
345
|
+
import React3, { useEffect as useEffect3, useRef } from "react";
|
346
|
+
|
347
|
+
// src/react-native-core/ReactNativeContextManager.ts
|
348
|
+
import {
|
349
|
+
JazzContextManager
|
350
|
+
} from "jazz-tools";
|
351
|
+
|
352
|
+
// src/react-native-core/platform.ts
|
353
|
+
import NetInfo from "@react-native-community/netinfo";
|
354
|
+
import { PureJSCrypto } from "cojson/dist/crypto/PureJSCrypto";
|
355
|
+
import {
|
356
|
+
createInviteLink as baseCreateInviteLink,
|
357
|
+
createAnonymousJazzContext,
|
358
|
+
createJazzContext
|
359
|
+
} from "jazz-tools";
|
360
|
+
|
361
|
+
// src/react-native-core/storage/sqlite-react-native.ts
|
362
|
+
import { SQLiteNodeBaseAsync } from "cojson-storage";
|
363
|
+
var SQLiteReactNative = class extends SQLiteNodeBaseAsync {
|
364
|
+
static async asPeer(config) {
|
365
|
+
if (!config.adapter) {
|
366
|
+
throw new Error("SQLite adapter is required");
|
367
|
+
}
|
368
|
+
return SQLiteNodeBaseAsync.create({
|
369
|
+
db: config.adapter,
|
370
|
+
localNodeName: "localNode"
|
371
|
+
});
|
372
|
+
}
|
373
|
+
};
|
374
|
+
|
375
|
+
// src/react-native-core/platform.ts
|
376
|
+
import { WebSocketPeerWithReconnection } from "cojson-transport-ws";
|
377
|
+
var ReactNativeWebSocketPeerWithReconnection = class extends WebSocketPeerWithReconnection {
|
378
|
+
onNetworkChange(callback) {
|
379
|
+
return NetInfo.addEventListener(
|
380
|
+
(state) => callback(state.isConnected ?? false)
|
381
|
+
);
|
382
|
+
}
|
383
|
+
};
|
384
|
+
async function setupPeers(options) {
|
385
|
+
const CryptoProvider2 = options.CryptoProvider || PureJSCrypto;
|
386
|
+
const crypto = await CryptoProvider2.create();
|
387
|
+
let node = void 0;
|
73
388
|
const peersToLoadFrom = [];
|
74
389
|
if (options.storage && options.storage !== "disabled") {
|
75
390
|
const storage = await SQLiteReactNative.asPeer({
|
@@ -243,36 +558,36 @@ var ReactNativeContextManager = class extends JazzContextManager {
|
|
243
558
|
};
|
244
559
|
|
245
560
|
// src/react-native-core/provider.tsx
|
246
|
-
import { jsx } from "react/jsx-runtime";
|
561
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
247
562
|
function JazzProviderCore({
|
248
563
|
children,
|
249
564
|
guestMode,
|
250
565
|
sync,
|
251
566
|
storage,
|
252
|
-
AccountSchema
|
567
|
+
AccountSchema,
|
253
568
|
defaultProfileName,
|
254
569
|
onLogOut,
|
255
|
-
|
570
|
+
logOutReplacement,
|
256
571
|
onAnonymousAccountDiscarded,
|
257
|
-
|
258
|
-
|
572
|
+
kvStore,
|
573
|
+
CryptoProvider: CryptoProvider2
|
259
574
|
}) {
|
260
575
|
setupKvStore(kvStore);
|
261
|
-
const [contextManager] =
|
576
|
+
const [contextManager] = React3.useState(
|
262
577
|
() => new ReactNativeContextManager()
|
263
578
|
);
|
579
|
+
const onLogOutRefCallback = useRefCallback(onLogOut);
|
580
|
+
const logOutReplacementRefCallback = useRefCallback(logOutReplacement);
|
264
581
|
const onAnonymousAccountDiscardedRefCallback = useRefCallback(
|
265
582
|
onAnonymousAccountDiscarded
|
266
583
|
);
|
267
|
-
const onLogOutRefCallback = useRefCallback(onLogOut);
|
268
|
-
const logOutReplacementRefCallback = useRefCallback(logOutReplacement);
|
269
584
|
const logoutReplacementActiveRef = useRef(false);
|
270
585
|
logoutReplacementActiveRef.current = Boolean(logOutReplacement);
|
271
|
-
const value =
|
272
|
-
|
586
|
+
const value = React3.useSyncExternalStore(
|
587
|
+
React3.useCallback(
|
273
588
|
(callback) => {
|
274
589
|
const props = {
|
275
|
-
AccountSchema
|
590
|
+
AccountSchema,
|
276
591
|
guestMode,
|
277
592
|
sync,
|
278
593
|
storage,
|
@@ -285,7 +600,7 @@ function JazzProviderCore({
|
|
285
600
|
if (contextManager.propsChanged(props)) {
|
286
601
|
contextManager.createContext(props).catch((error) => {
|
287
602
|
console.log(error.stack);
|
288
|
-
console.error("Error creating Jazz context:", error);
|
603
|
+
console.error("Error creating Jazz React Native context:", error);
|
289
604
|
});
|
290
605
|
}
|
291
606
|
return contextManager.subscribe(callback);
|
@@ -295,337 +610,22 @@ function JazzProviderCore({
|
|
295
610
|
() => contextManager.getCurrentValue(),
|
296
611
|
() => contextManager.getCurrentValue()
|
297
612
|
);
|
298
|
-
|
613
|
+
useEffect3(() => {
|
299
614
|
if (process.env.NODE_ENV === "development") return;
|
300
615
|
return () => {
|
301
616
|
contextManager.done();
|
302
617
|
};
|
303
618
|
}, []);
|
304
|
-
return /* @__PURE__ */
|
619
|
+
return /* @__PURE__ */ jsx2(JazzContext.Provider, { value, children: /* @__PURE__ */ jsx2(JazzContextManagerContext.Provider, { value: contextManager, children: value && children }) });
|
305
620
|
}
|
306
621
|
function useRefCallback(callback) {
|
307
|
-
const callbackRef =
|
622
|
+
const callbackRef = React3.useRef(callback);
|
308
623
|
callbackRef.current = callback;
|
309
624
|
return useRef(
|
310
625
|
(...args) => callbackRef.current?.(...args)
|
311
626
|
).current;
|
312
627
|
}
|
313
628
|
|
314
|
-
// src/react-native-core/auth/DemoAuthUI.tsx
|
315
|
-
import { useState } from "react";
|
316
|
-
import {
|
317
|
-
StyleSheet,
|
318
|
-
Text,
|
319
|
-
TextInput,
|
320
|
-
TouchableOpacity,
|
321
|
-
View,
|
322
|
-
useColorScheme
|
323
|
-
} from "react-native";
|
324
|
-
import { jsx as jsx2, jsxs } from "react/jsx-runtime";
|
325
|
-
var DemoAuthBasicUI = ({
|
326
|
-
appName,
|
327
|
-
auth,
|
328
|
-
children
|
329
|
-
}) => {
|
330
|
-
const colorScheme = useColorScheme();
|
331
|
-
const darkMode = colorScheme === "dark";
|
332
|
-
const [username, setUsername] = useState("");
|
333
|
-
const [errorMessage, setErrorMessage] = useState(null);
|
334
|
-
const handleSignUp = () => {
|
335
|
-
setErrorMessage(null);
|
336
|
-
auth.signUp(username).catch((error) => {
|
337
|
-
setErrorMessage(error.message);
|
338
|
-
});
|
339
|
-
};
|
340
|
-
const handleLogIn = (username2) => {
|
341
|
-
setErrorMessage(null);
|
342
|
-
auth.logIn(username2).catch((error) => {
|
343
|
-
setErrorMessage(error.message);
|
344
|
-
});
|
345
|
-
};
|
346
|
-
if (auth.state === "signedIn") {
|
347
|
-
return children;
|
348
|
-
}
|
349
|
-
return /* @__PURE__ */ jsx2(
|
350
|
-
View,
|
351
|
-
{
|
352
|
-
style: [
|
353
|
-
styles.container,
|
354
|
-
darkMode ? styles.darkBackground : styles.lightBackground
|
355
|
-
],
|
356
|
-
children: /* @__PURE__ */ jsxs(View, { style: styles.formContainer, children: [
|
357
|
-
/* @__PURE__ */ jsx2(
|
358
|
-
Text,
|
359
|
-
{
|
360
|
-
style: [
|
361
|
-
styles.headerText,
|
362
|
-
darkMode ? styles.darkText : styles.lightText
|
363
|
-
],
|
364
|
-
children: appName
|
365
|
-
}
|
366
|
-
),
|
367
|
-
errorMessage && /* @__PURE__ */ jsx2(Text, { style: styles.errorText, children: errorMessage }),
|
368
|
-
/* @__PURE__ */ jsx2(
|
369
|
-
TextInput,
|
370
|
-
{
|
371
|
-
placeholder: "Display name",
|
372
|
-
value: username,
|
373
|
-
onChangeText: setUsername,
|
374
|
-
placeholderTextColor: darkMode ? "#fff" : "#000",
|
375
|
-
style: [
|
376
|
-
styles.textInput,
|
377
|
-
darkMode ? styles.darkInput : styles.lightInput
|
378
|
-
]
|
379
|
-
}
|
380
|
-
),
|
381
|
-
/* @__PURE__ */ jsx2(
|
382
|
-
TouchableOpacity,
|
383
|
-
{
|
384
|
-
onPress: handleSignUp,
|
385
|
-
style: [
|
386
|
-
styles.button,
|
387
|
-
darkMode ? styles.darkButton : styles.lightButton
|
388
|
-
],
|
389
|
-
children: /* @__PURE__ */ jsx2(
|
390
|
-
Text,
|
391
|
-
{
|
392
|
-
style: darkMode ? styles.darkButtonText : styles.lightButtonText,
|
393
|
-
children: "Sign Up as new account"
|
394
|
-
}
|
395
|
-
)
|
396
|
-
}
|
397
|
-
),
|
398
|
-
/* @__PURE__ */ jsx2(View, { style: styles.existingUsersContainer, children: auth.existingUsers.map((user) => /* @__PURE__ */ jsx2(
|
399
|
-
TouchableOpacity,
|
400
|
-
{
|
401
|
-
onPress: () => handleLogIn(user),
|
402
|
-
style: [
|
403
|
-
styles.existingUserButton,
|
404
|
-
darkMode ? styles.darkUserButton : styles.lightUserButton
|
405
|
-
],
|
406
|
-
children: /* @__PURE__ */ jsxs(Text, { style: darkMode ? styles.darkText : styles.lightText, children: [
|
407
|
-
'Log In as "',
|
408
|
-
user,
|
409
|
-
'"'
|
410
|
-
] })
|
411
|
-
},
|
412
|
-
user
|
413
|
-
)) })
|
414
|
-
] })
|
415
|
-
}
|
416
|
-
);
|
417
|
-
};
|
418
|
-
var styles = StyleSheet.create({
|
419
|
-
container: {
|
420
|
-
flex: 1,
|
421
|
-
justifyContent: "center",
|
422
|
-
alignItems: "center",
|
423
|
-
padding: 20
|
424
|
-
},
|
425
|
-
formContainer: {
|
426
|
-
width: "80%",
|
427
|
-
alignItems: "center",
|
428
|
-
justifyContent: "center"
|
429
|
-
},
|
430
|
-
headerText: {
|
431
|
-
fontSize: 24,
|
432
|
-
marginBottom: 20
|
433
|
-
},
|
434
|
-
errorText: {
|
435
|
-
color: "red",
|
436
|
-
marginVertical: 5,
|
437
|
-
textAlign: "center"
|
438
|
-
},
|
439
|
-
textInput: {
|
440
|
-
borderWidth: 1,
|
441
|
-
padding: 10,
|
442
|
-
marginVertical: 10,
|
443
|
-
width: "100%",
|
444
|
-
borderRadius: 6
|
445
|
-
},
|
446
|
-
darkInput: {
|
447
|
-
borderColor: "#444",
|
448
|
-
backgroundColor: "#000",
|
449
|
-
color: "#fff"
|
450
|
-
},
|
451
|
-
lightInput: {
|
452
|
-
borderColor: "#ddd",
|
453
|
-
backgroundColor: "#fff",
|
454
|
-
color: "#000"
|
455
|
-
},
|
456
|
-
button: {
|
457
|
-
paddingVertical: 15,
|
458
|
-
paddingHorizontal: 10,
|
459
|
-
borderRadius: 6,
|
460
|
-
width: "100%",
|
461
|
-
marginVertical: 10
|
462
|
-
},
|
463
|
-
darkButton: {
|
464
|
-
backgroundColor: "#444"
|
465
|
-
},
|
466
|
-
lightButton: {
|
467
|
-
backgroundColor: "#ddd"
|
468
|
-
},
|
469
|
-
darkButtonText: {
|
470
|
-
color: "#fff",
|
471
|
-
textAlign: "center"
|
472
|
-
},
|
473
|
-
lightButtonText: {
|
474
|
-
color: "#000",
|
475
|
-
textAlign: "center"
|
476
|
-
},
|
477
|
-
existingUsersContainer: {
|
478
|
-
width: "100%",
|
479
|
-
marginTop: 20
|
480
|
-
},
|
481
|
-
existingUserButton: {
|
482
|
-
paddingVertical: 15,
|
483
|
-
paddingHorizontal: 10,
|
484
|
-
borderRadius: 6,
|
485
|
-
marginVertical: 5
|
486
|
-
},
|
487
|
-
darkUserButton: {
|
488
|
-
backgroundColor: "#222"
|
489
|
-
},
|
490
|
-
lightUserButton: {
|
491
|
-
backgroundColor: "#eee"
|
492
|
-
},
|
493
|
-
loadingText: {
|
494
|
-
fontSize: 18,
|
495
|
-
color: "#888"
|
496
|
-
},
|
497
|
-
darkText: {
|
498
|
-
color: "#fff"
|
499
|
-
},
|
500
|
-
lightText: {
|
501
|
-
color: "#000"
|
502
|
-
},
|
503
|
-
darkBackground: {
|
504
|
-
backgroundColor: "#000"
|
505
|
-
},
|
506
|
-
lightBackground: {
|
507
|
-
backgroundColor: "#fff"
|
508
|
-
}
|
509
|
-
});
|
510
|
-
|
511
|
-
// src/react-native-core/auth/auth.ts
|
512
|
-
function clearUserCredentials() {
|
513
|
-
const kvStore = KvStoreContext.getInstance().getStorage();
|
514
|
-
return Promise.all([
|
515
|
-
kvStore.delete("demo-auth-logged-in-secret"),
|
516
|
-
kvStore.delete("jazz-clerk-auth"),
|
517
|
-
kvStore.delete("jazz-logged-in-secret")
|
518
|
-
]);
|
519
|
-
}
|
520
|
-
|
521
|
-
// src/react-native-core/hooks.tsx
|
522
|
-
import { useEffect as useEffect2 } from "react";
|
523
|
-
import { parseInviteLink } from "jazz-tools";
|
524
|
-
import { useJazzContext } from "jazz-tools/react-core";
|
525
|
-
import { Linking } from "react-native";
|
526
|
-
import {
|
527
|
-
useCoState,
|
528
|
-
experimental_useInboxSender,
|
529
|
-
useDemoAuth,
|
530
|
-
usePassphraseAuth,
|
531
|
-
useJazzContext as useJazzContext2,
|
532
|
-
useAuthSecretStorage,
|
533
|
-
useIsAuthenticated,
|
534
|
-
useAccount
|
535
|
-
} from "jazz-tools/react-core";
|
536
|
-
function useAcceptInviteNative({
|
537
|
-
invitedObjectSchema,
|
538
|
-
onAccept,
|
539
|
-
forValueHint
|
540
|
-
}) {
|
541
|
-
const context = useJazzContext();
|
542
|
-
if (!("me" in context)) {
|
543
|
-
throw new Error(
|
544
|
-
"useAcceptInviteNative can't be used in a JazzProvider with auth === 'guest'."
|
545
|
-
);
|
546
|
-
}
|
547
|
-
useEffect2(() => {
|
548
|
-
const handleDeepLink = ({ url }) => {
|
549
|
-
const result = parseInviteLink(url);
|
550
|
-
if (result && result.valueHint === forValueHint) {
|
551
|
-
context.me.acceptInvite(
|
552
|
-
result.valueID,
|
553
|
-
result.inviteSecret,
|
554
|
-
invitedObjectSchema
|
555
|
-
).then(() => {
|
556
|
-
onAccept(result.valueID);
|
557
|
-
}).catch((e) => {
|
558
|
-
console.error("Failed to accept invite", e);
|
559
|
-
});
|
560
|
-
}
|
561
|
-
};
|
562
|
-
const linkingListener = Linking.addEventListener("url", handleDeepLink);
|
563
|
-
void Linking.getInitialURL().then((url) => {
|
564
|
-
if (url) handleDeepLink({ url });
|
565
|
-
});
|
566
|
-
return () => {
|
567
|
-
linkingListener.remove();
|
568
|
-
};
|
569
|
-
}, [context, onAccept, invitedObjectSchema, forValueHint]);
|
570
|
-
}
|
571
|
-
|
572
|
-
// src/react-native-core/media.tsx
|
573
|
-
import { ImageDefinition } from "jazz-tools";
|
574
|
-
import { useEffect as useEffect3, useState as useState2 } from "react";
|
575
|
-
function useProgressiveImgNative({
|
576
|
-
image,
|
577
|
-
maxWidth,
|
578
|
-
targetWidth
|
579
|
-
}) {
|
580
|
-
const [current, setCurrent] = useState2(void 0);
|
581
|
-
useEffect3(() => {
|
582
|
-
let lastHighestRes;
|
583
|
-
if (!image) return;
|
584
|
-
const unsub = image.subscribe({}, (update) => {
|
585
|
-
const highestRes = ImageDefinition.highestResAvailable(update, {
|
586
|
-
maxWidth,
|
587
|
-
targetWidth
|
588
|
-
});
|
589
|
-
if (highestRes && highestRes.res !== lastHighestRes) {
|
590
|
-
lastHighestRes = highestRes.res;
|
591
|
-
const dataUrl = highestRes.stream.asBase64({ dataURL: true });
|
592
|
-
if (dataUrl) {
|
593
|
-
setCurrent({
|
594
|
-
src: dataUrl,
|
595
|
-
res: highestRes.res
|
596
|
-
});
|
597
|
-
} else {
|
598
|
-
console.warn("No chunks available for image", image.id);
|
599
|
-
setCurrent({
|
600
|
-
src: update?.placeholderDataURL,
|
601
|
-
res: "placeholder"
|
602
|
-
});
|
603
|
-
}
|
604
|
-
} else if (!highestRes) {
|
605
|
-
setCurrent({
|
606
|
-
src: update?.placeholderDataURL,
|
607
|
-
res: "placeholder"
|
608
|
-
});
|
609
|
-
}
|
610
|
-
});
|
611
|
-
return unsub;
|
612
|
-
}, [image?.id, maxWidth]);
|
613
|
-
return {
|
614
|
-
src: current?.src,
|
615
|
-
res: current?.res,
|
616
|
-
originalSize: image?.originalSize
|
617
|
-
};
|
618
|
-
}
|
619
|
-
function ProgressiveImgNative({
|
620
|
-
children,
|
621
|
-
image,
|
622
|
-
maxWidth,
|
623
|
-
targetWidth
|
624
|
-
}) {
|
625
|
-
const result = useProgressiveImgNative({ image, maxWidth, targetWidth });
|
626
|
-
return result && children(result);
|
627
|
-
}
|
628
|
-
|
629
629
|
// src/react-native-core/index.ts
|
630
630
|
import { SQLiteDatabaseDriverAsync as SQLiteDatabaseDriverAsync2 } from "cojson-storage";
|
631
631
|
import { parseInviteLink as parseInviteLink2 } from "jazz-tools";
|