jazz-svelte 0.8.50 → 0.9.0
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/Provider.svelte +3 -3
- package/dist/Provider.svelte.d.ts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/jazz.svelte.d.ts +41 -35
- package/dist/jazz.svelte.js +116 -137
- package/dist/testing.d.ts +8 -0
- package/dist/testing.js +19 -0
- package/dist/tests/components/ProviderTestComponent.svelte +13 -0
- package/dist/tests/components/useAcceptInvite.svelte +17 -0
- package/dist/tests/components/useAcceptInvite.svelte.d.ts +22 -0
- package/dist/tests/components/useAccount.svelte +27 -0
- package/dist/tests/components/useAccount.svelte.d.ts +9 -0
- package/dist/tests/components/useAccountOrGuest.svelte +27 -0
- package/dist/tests/components/useAccountOrGuest.svelte.d.ts +9 -0
- package/dist/tests/components/useCoState.svelte +21 -0
- package/dist/tests/components/useCoState.svelte.d.ts +24 -0
- package/package.json +8 -3
- package/dist/tests/ProviderTestComponent.svelte +0 -14
- package/dist/tests/TestComponent.svelte +0 -17
- package/dist/tests/TestComponent.svelte.d.ts +0 -9
- /package/dist/tests/{ProviderTestComponent.svelte.d.ts → components/ProviderTestComponent.svelte.d.ts} +0 -0
package/dist/Provider.svelte
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
auth: AuthMethod | 'guest';
|
5
5
|
peer: `wss://${string}` | `ws://${string}`;
|
6
6
|
storage?: 'indexedDB' | 'singleTabOPFS';
|
7
|
-
|
7
|
+
AccountSchema?: AccountClass<Acc>;
|
8
8
|
};
|
9
9
|
</script>
|
10
10
|
|
@@ -15,7 +15,7 @@
|
|
15
15
|
import { type Snippet, setContext, untrack } from 'svelte';
|
16
16
|
import { JAZZ_CTX, type JazzContext } from './jazz.svelte.js';
|
17
17
|
|
18
|
-
let { children, auth, peer, storage,
|
18
|
+
let { children, auth, peer, storage, AccountSchema }: Props<Acc> = $props();
|
19
19
|
|
20
20
|
const ctx = $state<JazzContext<Acc>>({ current: undefined });
|
21
21
|
setContext<JazzContext<Acc>>(JAZZ_CTX, ctx);
|
@@ -36,7 +36,7 @@
|
|
36
36
|
storage
|
37
37
|
}
|
38
38
|
: {
|
39
|
-
AccountSchema:
|
39
|
+
AccountSchema: AccountSchema ?? Account as unknown as AccountClass<Acc>,
|
40
40
|
auth,
|
41
41
|
peer,
|
42
42
|
storage
|
@@ -3,7 +3,7 @@ export type Props<Acc extends Account = Account> = {
|
|
3
3
|
auth: AuthMethod | 'guest';
|
4
4
|
peer: `wss://${string}` | `ws://${string}`;
|
5
5
|
storage?: 'indexedDB' | 'singleTabOPFS';
|
6
|
-
|
6
|
+
AccountSchema?: AccountClass<Acc>;
|
7
7
|
};
|
8
8
|
import type { AccountClass, AuthMethod } from 'jazz-tools';
|
9
9
|
import { Account } from 'jazz-tools';
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/jazz.svelte.d.ts
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
import { type BrowserContext, type BrowserGuestContext } from 'jazz-browser';
|
2
|
-
import type {
|
2
|
+
import type { AnonymousJazzAgent, CoValue, CoValueClass, DeeplyLoaded, DepthsIn, ID } from 'jazz-tools';
|
3
3
|
import { Account } from 'jazz-tools';
|
4
|
-
import
|
5
|
-
|
4
|
+
import Provider from './Provider.svelte';
|
5
|
+
export { Provider as JazzProvider };
|
6
6
|
/**
|
7
7
|
* The key for the Jazz context.
|
8
8
|
*/
|
@@ -18,38 +18,44 @@ export type JazzContext<Acc extends Account> = {
|
|
18
18
|
* @returns The current Jazz context.
|
19
19
|
*/
|
20
20
|
export declare function getJazzContext<Acc extends Account>(): JazzContext<Acc>;
|
21
|
+
export interface Register {
|
22
|
+
}
|
23
|
+
export type RegisteredAccount = Register extends {
|
24
|
+
Account: infer Acc;
|
25
|
+
} ? Acc : Account;
|
26
|
+
export declare function useAccount(): {
|
27
|
+
me: RegisteredAccount;
|
28
|
+
logOut: () => void;
|
29
|
+
};
|
30
|
+
export declare function useAccount<D extends DepthsIn<RegisteredAccount>>(depth: D): {
|
31
|
+
me: DeeplyLoaded<RegisteredAccount, D> | undefined;
|
32
|
+
logOut: () => void;
|
33
|
+
};
|
34
|
+
export declare function useAccountOrGuest(): {
|
35
|
+
me: RegisteredAccount | AnonymousJazzAgent;
|
36
|
+
};
|
37
|
+
export declare function useAccountOrGuest<D extends DepthsIn<RegisteredAccount>>(depth: D): {
|
38
|
+
me: DeeplyLoaded<RegisteredAccount, D> | undefined | AnonymousJazzAgent;
|
39
|
+
};
|
21
40
|
/**
|
22
|
-
*
|
23
|
-
* @
|
41
|
+
* Use a CoValue with a optional depth.
|
42
|
+
* @param Schema - The CoValue schema.
|
43
|
+
* @param id - The CoValue id.
|
44
|
+
* @param depth - The depth.
|
45
|
+
* @returns The CoValue.
|
24
46
|
*/
|
25
|
-
export declare function
|
26
|
-
|
27
|
-
}): {
|
28
|
-
Provider: Component<Omit<Props<Acc>, "schema">, {}, string>;
|
29
|
-
useAccount: {
|
30
|
-
(): {
|
31
|
-
me: Acc | undefined;
|
32
|
-
logOut: () => void;
|
33
|
-
};
|
34
|
-
<D extends DepthsIn<Acc>>(depth: D): {
|
35
|
-
me: DeeplyLoaded<Acc, D> | undefined;
|
36
|
-
logOut: () => void;
|
37
|
-
};
|
38
|
-
};
|
39
|
-
useAccountOrGuest: {
|
40
|
-
(): {
|
41
|
-
me: Acc | AnonymousJazzAgent;
|
42
|
-
};
|
43
|
-
<D extends DepthsIn<Acc>>(depth: D): {
|
44
|
-
me: DeeplyLoaded<Acc, D> | undefined | AnonymousJazzAgent;
|
45
|
-
};
|
46
|
-
};
|
47
|
-
useCoState: <V extends CoValue, D extends DepthsIn<V> = []>(Schema: CoValueClass<V>, id: ID<V> | undefined, depth?: D) => {
|
48
|
-
current?: DeeplyLoaded<V, D>;
|
49
|
-
};
|
50
|
-
useAcceptInvite: <V extends CoValue>({ invitedObjectSchema, onAccept, forValueHint }: {
|
51
|
-
invitedObjectSchema: CoValueClass<V>;
|
52
|
-
onAccept: (projectID: ID<V>) => void;
|
53
|
-
forValueHint?: string;
|
54
|
-
}) => void;
|
47
|
+
export declare function useCoState<V extends CoValue, D extends DepthsIn<V> = []>(Schema: CoValueClass<V>, id: ID<V> | undefined, depth?: D): {
|
48
|
+
current?: DeeplyLoaded<V, D>;
|
55
49
|
};
|
50
|
+
/**
|
51
|
+
* Use the accept invite hook.
|
52
|
+
* @param invitedObjectSchema - The invited object schema.
|
53
|
+
* @param onAccept - Function to call when the invite is accepted.
|
54
|
+
* @param forValueHint - Hint for the value.
|
55
|
+
* @returns The accept invite hook.
|
56
|
+
*/
|
57
|
+
export declare function useAcceptInvite<V extends CoValue>({ invitedObjectSchema, onAccept, forValueHint }: {
|
58
|
+
invitedObjectSchema: CoValueClass<V>;
|
59
|
+
onAccept: (projectID: ID<V>) => void;
|
60
|
+
forValueHint?: string;
|
61
|
+
}): void;
|
package/dist/jazz.svelte.js
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
import { consumeInviteLinkFromWindowLocation } from 'jazz-browser';
|
2
|
-
import { Account, createCoValueObservable } from 'jazz-tools';
|
2
|
+
import { Account, createCoValueObservable, subscribeToCoValue } from 'jazz-tools';
|
3
3
|
import { getContext, untrack } from 'svelte';
|
4
4
|
import Provider from './Provider.svelte';
|
5
|
+
export { Provider as JazzProvider };
|
5
6
|
/**
|
6
7
|
* The key for the Jazz context.
|
7
8
|
*/
|
@@ -14,159 +15,137 @@ export function getJazzContext() {
|
|
14
15
|
return getContext(JAZZ_CTX);
|
15
16
|
}
|
16
17
|
/**
|
17
|
-
*
|
18
|
-
* @
|
18
|
+
* Use the current account with a optional depth.
|
19
|
+
* @param depth - The depth.
|
20
|
+
* @returns The current account.
|
19
21
|
*/
|
20
|
-
export function
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
}
|
28
|
-
|
29
|
-
|
30
|
-
* @param depth - The depth.
|
31
|
-
* @returns The current account.
|
32
|
-
*/
|
33
|
-
function useAccount(depth) {
|
34
|
-
const ctx = getJazzContext();
|
35
|
-
if (!ctx?.current) {
|
36
|
-
throw new Error('useAccount must be used within a JazzProvider');
|
37
|
-
}
|
38
|
-
if (!('me' in ctx.current)) {
|
39
|
-
throw new Error("useAccount can't be used in a JazzProvider with auth === 'guest' - consider using useAccountOrGuest()");
|
40
|
-
}
|
41
|
-
// If no depth is specified, return the context's me directly
|
42
|
-
if (depth === undefined) {
|
43
|
-
return {
|
44
|
-
get me() {
|
45
|
-
return ctx.current.me;
|
46
|
-
},
|
47
|
-
logOut() {
|
48
|
-
return ctx.current?.logOut();
|
49
|
-
}
|
50
|
-
};
|
51
|
-
}
|
52
|
-
// If depth is specified, use useCoState to get the deeply loaded version
|
53
|
-
const me = useCoState(ctx.current.me.constructor, ctx.current.me.id, depth);
|
22
|
+
export function useAccount(depth) {
|
23
|
+
const ctx = getJazzContext();
|
24
|
+
if (!ctx?.current) {
|
25
|
+
throw new Error('useAccount must be used within a JazzProvider');
|
26
|
+
}
|
27
|
+
if (!('me' in ctx.current)) {
|
28
|
+
throw new Error("useAccount can't be used in a JazzProvider with auth === 'guest' - consider using useAccountOrGuest()");
|
29
|
+
}
|
30
|
+
// If no depth is specified, return the context's me directly
|
31
|
+
if (depth === undefined) {
|
54
32
|
return {
|
55
33
|
get me() {
|
56
|
-
return
|
34
|
+
return ctx.current.me;
|
57
35
|
},
|
58
36
|
logOut() {
|
59
37
|
return ctx.current?.logOut();
|
60
38
|
}
|
61
39
|
};
|
62
40
|
}
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
throw new Error('useAccountOrGuest must be used within a JazzProvider');
|
72
|
-
}
|
73
|
-
const contextMe = 'me' in ctx.current ? ctx.current.me : undefined;
|
74
|
-
const me = useCoState(contextMe?.constructor, contextMe?.id, depth);
|
75
|
-
// If the context has a me, return the account.
|
76
|
-
if ('me' in ctx.current) {
|
77
|
-
return {
|
78
|
-
get me() {
|
79
|
-
return depth === undefined
|
80
|
-
? me.current || ctx.current?.me
|
81
|
-
: me.current;
|
82
|
-
}
|
83
|
-
};
|
84
|
-
}
|
85
|
-
// If the context has no me, return the guest.
|
86
|
-
else {
|
87
|
-
return {
|
88
|
-
get me() {
|
89
|
-
return ctx.current?.guest;
|
90
|
-
}
|
91
|
-
};
|
41
|
+
// If depth is specified, use useCoState to get the deeply loaded version
|
42
|
+
const me = useCoState(ctx.current.me.constructor, ctx.current.me.id, depth);
|
43
|
+
return {
|
44
|
+
get me() {
|
45
|
+
return me.current;
|
46
|
+
},
|
47
|
+
logOut() {
|
48
|
+
return ctx.current?.logOut();
|
92
49
|
}
|
50
|
+
};
|
51
|
+
}
|
52
|
+
/**
|
53
|
+
* Use the current account or guest with a optional depth.
|
54
|
+
* @param depth - The depth.
|
55
|
+
* @returns The current account or guest.
|
56
|
+
*/
|
57
|
+
export function useAccountOrGuest(depth) {
|
58
|
+
const ctx = getJazzContext();
|
59
|
+
if (!ctx?.current) {
|
60
|
+
throw new Error('useAccountOrGuest must be used within a JazzProvider');
|
93
61
|
}
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
* @param depth - The depth.
|
99
|
-
* @returns The CoValue.
|
100
|
-
*/
|
101
|
-
function useCoState(Schema, id, depth = []) {
|
102
|
-
const ctx = getJazzContext();
|
103
|
-
// Create state and a stable observable
|
104
|
-
let state = $state.raw(undefined);
|
105
|
-
const observable = $state.raw(createCoValueObservable());
|
106
|
-
// Effect to handle subscription
|
107
|
-
// TODO: Possibly memoise this, to avoid re-subscribing
|
108
|
-
$effect(() => {
|
109
|
-
// Reset state when dependencies change
|
110
|
-
state = undefined;
|
111
|
-
// Return early if no context or id, effectively cleaning up any previous subscription
|
112
|
-
if (!ctx?.current || !id)
|
113
|
-
return;
|
114
|
-
// Setup subscription with current values
|
115
|
-
return observable.subscribe(Schema, id, 'me' in ctx.current ? ctx.current.me : ctx.current.guest, depth, () => {
|
116
|
-
// Get current value from our stable observable
|
117
|
-
state = observable.getCurrentValue();
|
118
|
-
});
|
119
|
-
});
|
62
|
+
const contextMe = 'me' in ctx.current ? ctx.current.me : undefined;
|
63
|
+
const me = useCoState(contextMe?.constructor, contextMe?.id, depth);
|
64
|
+
// If the context has a me, return the account.
|
65
|
+
if ('me' in ctx.current) {
|
120
66
|
return {
|
121
|
-
get
|
122
|
-
return
|
67
|
+
get me() {
|
68
|
+
return depth === undefined
|
69
|
+
? me.current || ctx.current?.me
|
70
|
+
: me.current;
|
123
71
|
}
|
124
72
|
};
|
125
73
|
}
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
74
|
+
// If the context has no me, return the guest.
|
75
|
+
else {
|
76
|
+
return {
|
77
|
+
get me() {
|
78
|
+
return ctx.current?.guest;
|
79
|
+
}
|
80
|
+
};
|
81
|
+
}
|
82
|
+
}
|
83
|
+
/**
|
84
|
+
* Use a CoValue with a optional depth.
|
85
|
+
* @param Schema - The CoValue schema.
|
86
|
+
* @param id - The CoValue id.
|
87
|
+
* @param depth - The depth.
|
88
|
+
* @returns The CoValue.
|
89
|
+
*/
|
90
|
+
export function useCoState(Schema, id, depth = []) {
|
91
|
+
const ctx = getJazzContext();
|
92
|
+
// Create state and a stable observable
|
93
|
+
let state = $state.raw(undefined);
|
94
|
+
// Effect to handle subscription
|
95
|
+
$effect(() => {
|
96
|
+
// Reset state when dependencies change
|
97
|
+
state = undefined;
|
98
|
+
// Return early if no context or id, effectively cleaning up any previous subscription
|
99
|
+
if (!ctx?.current || !id)
|
100
|
+
return;
|
101
|
+
// Setup subscription with current values
|
102
|
+
return subscribeToCoValue(Schema, id, 'me' in ctx.current ? ctx.current.me : ctx.current.guest, depth, (value) => {
|
103
|
+
// Get current value from our stable observable
|
104
|
+
state = value;
|
105
|
+
}, undefined, true);
|
106
|
+
});
|
107
|
+
return {
|
108
|
+
get current() {
|
109
|
+
return state;
|
141
110
|
}
|
111
|
+
};
|
112
|
+
}
|
113
|
+
/**
|
114
|
+
* Use the accept invite hook.
|
115
|
+
* @param invitedObjectSchema - The invited object schema.
|
116
|
+
* @param onAccept - Function to call when the invite is accepted.
|
117
|
+
* @param forValueHint - Hint for the value.
|
118
|
+
* @returns The accept invite hook.
|
119
|
+
*/
|
120
|
+
export function useAcceptInvite({ invitedObjectSchema, onAccept, forValueHint }) {
|
121
|
+
const ctx = getJazzContext();
|
122
|
+
const _onAccept = onAccept;
|
123
|
+
if (!ctx.current) {
|
124
|
+
throw new Error('useAcceptInvite must be used within a JazzProvider');
|
125
|
+
}
|
126
|
+
if (!('me' in ctx.current)) {
|
127
|
+
throw new Error("useAcceptInvite can't be used in a JazzProvider with auth === 'guest'.");
|
128
|
+
}
|
129
|
+
// Subscribe to the onAccept function.
|
130
|
+
$effect(() => {
|
131
|
+
_onAccept;
|
142
132
|
// Subscribe to the onAccept function.
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
.then((result) => result && _onAccept(result?.valueID))
|
159
|
-
.catch((e) => {
|
160
|
-
console.error('Failed to accept invite', e);
|
161
|
-
});
|
133
|
+
untrack(() => {
|
134
|
+
// If there is no context, return.
|
135
|
+
if (!ctx.current)
|
136
|
+
return;
|
137
|
+
// Consume the invite link from the window location.
|
138
|
+
const result = consumeInviteLinkFromWindowLocation({
|
139
|
+
as: ctx.current.me,
|
140
|
+
invitedObjectSchema,
|
141
|
+
forValueHint
|
142
|
+
});
|
143
|
+
// If the result is valid, call the onAccept function.
|
144
|
+
result
|
145
|
+
.then((result) => result && _onAccept(result?.valueID))
|
146
|
+
.catch((e) => {
|
147
|
+
console.error('Failed to accept invite', e);
|
162
148
|
});
|
163
149
|
});
|
164
|
-
}
|
165
|
-
return {
|
166
|
-
Provider: ProviderWithSchema,
|
167
|
-
useAccount,
|
168
|
-
useAccountOrGuest,
|
169
|
-
useCoState,
|
170
|
-
useAcceptInvite
|
171
|
-
};
|
150
|
+
});
|
172
151
|
}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { Account, AnonymousJazzAgent } from "jazz-tools";
|
2
|
+
import { type JazzContext } from './jazz.svelte.js';
|
3
|
+
export declare function createJazzTestContext<Acc extends Account>({ account }: {
|
4
|
+
account: Acc | {
|
5
|
+
guest: AnonymousJazzAgent;
|
6
|
+
};
|
7
|
+
}): Map<{}, JazzContext<Acc>>;
|
8
|
+
export { createJazzTestAccount, createJazzTestGuest, linkAccounts } from "jazz-tools/testing";
|
package/dist/testing.js
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
import { Account, AnonymousJazzAgent } from "jazz-tools";
|
2
|
+
import { JAZZ_CTX } from './jazz.svelte.js';
|
3
|
+
import { getJazzContextShape } from "jazz-tools/testing";
|
4
|
+
export function createJazzTestContext({ account }) {
|
5
|
+
const ctx = new Map();
|
6
|
+
const value = getJazzContextShape(account);
|
7
|
+
if ('guest' in account) {
|
8
|
+
ctx.set(JAZZ_CTX, {
|
9
|
+
current: value
|
10
|
+
});
|
11
|
+
}
|
12
|
+
else {
|
13
|
+
ctx.set(JAZZ_CTX, {
|
14
|
+
current: value
|
15
|
+
});
|
16
|
+
}
|
17
|
+
return ctx;
|
18
|
+
}
|
19
|
+
export { createJazzTestAccount, createJazzTestGuest, linkAccounts } from "jazz-tools/testing";
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<script lang="ts">
|
2
|
+
import { JazzProvider } from "../../jazz.svelte.js";
|
3
|
+
|
4
|
+
const { auth } = $props();
|
5
|
+
</script>
|
6
|
+
|
7
|
+
<div data-testid="provider-test">
|
8
|
+
<JazzProvider {auth} peer="wss://cloud.jazz.tools/?key=jazz-svelte-test">
|
9
|
+
{#if auth}
|
10
|
+
<span data-testid="provider-auth-test">{JSON.stringify(auth)}</span>
|
11
|
+
{/if}
|
12
|
+
</JazzProvider>
|
13
|
+
</div>
|
@@ -0,0 +1,17 @@
|
|
1
|
+
<script lang="ts" module>
|
2
|
+
export type Props<R extends CoValue> = {
|
3
|
+
invitedObjectSchema: CoValueClass<R>;
|
4
|
+
onAccept: (id: ID<R>) => void;
|
5
|
+
};
|
6
|
+
</script>
|
7
|
+
|
8
|
+
<script lang="ts" generics="R extends CoValue">
|
9
|
+
import { useAcceptInvite } from '../../jazz.svelte.js';
|
10
|
+
import type { CoValue, CoValueClass, ID } from 'jazz-tools';
|
11
|
+
|
12
|
+
let { invitedObjectSchema, onAccept }: Props<R> = $props();
|
13
|
+
|
14
|
+
useAcceptInvite({
|
15
|
+
invitedObjectSchema, onAccept
|
16
|
+
});
|
17
|
+
</script>
|
@@ -0,0 +1,22 @@
|
|
1
|
+
export type Props<R extends CoValue> = {
|
2
|
+
invitedObjectSchema: CoValueClass<R>;
|
3
|
+
onAccept: (id: ID<R>) => void;
|
4
|
+
};
|
5
|
+
import type { CoValue, CoValueClass, ID } from 'jazz-tools';
|
6
|
+
declare class __sveltets_Render<R extends CoValue> {
|
7
|
+
props(): Props<R>;
|
8
|
+
events(): {};
|
9
|
+
slots(): {};
|
10
|
+
bindings(): "";
|
11
|
+
exports(): {};
|
12
|
+
}
|
13
|
+
interface $$IsomorphicComponent {
|
14
|
+
new <R extends CoValue>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<R>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<R>['props']>, ReturnType<__sveltets_Render<R>['events']>, ReturnType<__sveltets_Render<R>['slots']>> & {
|
15
|
+
$$bindings?: ReturnType<__sveltets_Render<R>['bindings']>;
|
16
|
+
} & ReturnType<__sveltets_Render<R>['exports']>;
|
17
|
+
<R extends CoValue>(internal: unknown, props: ReturnType<__sveltets_Render<R>['props']> & {}): ReturnType<__sveltets_Render<R>['exports']>;
|
18
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
19
|
+
}
|
20
|
+
declare const UseAcceptInvite: $$IsomorphicComponent;
|
21
|
+
type UseAcceptInvite<R extends CoValue> = InstanceType<typeof UseAcceptInvite<R>>;
|
22
|
+
export default UseAcceptInvite;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<script lang="ts" module>
|
2
|
+
export type Props = {
|
3
|
+
depth?: DepthsIn<RegisteredAccount>;
|
4
|
+
setResult: (result: ReturnType<typeof useAccount> | undefined) => void;
|
5
|
+
};
|
6
|
+
</script>
|
7
|
+
|
8
|
+
<script lang="ts">
|
9
|
+
import { useAccount, type RegisteredAccount } from '../../jazz.svelte.js';
|
10
|
+
import type { DepthsIn } from 'jazz-tools';
|
11
|
+
|
12
|
+
let { depth, setResult }: Props = $props();
|
13
|
+
|
14
|
+
if (depth) {
|
15
|
+
const result = $derived(useAccount(depth));
|
16
|
+
|
17
|
+
$effect(() => {
|
18
|
+
setResult(result);
|
19
|
+
});
|
20
|
+
} else {
|
21
|
+
const result = $derived(useAccount());
|
22
|
+
|
23
|
+
$effect(() => {
|
24
|
+
setResult(result);
|
25
|
+
});
|
26
|
+
}
|
27
|
+
</script>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export type Props = {
|
2
|
+
depth?: DepthsIn<RegisteredAccount>;
|
3
|
+
setResult: (result: ReturnType<typeof useAccount> | undefined) => void;
|
4
|
+
};
|
5
|
+
import { useAccount, type RegisteredAccount } from '../../jazz.svelte.js';
|
6
|
+
import type { DepthsIn } from 'jazz-tools';
|
7
|
+
declare const UseAccount: import("svelte").Component<Props, {}, "">;
|
8
|
+
type UseAccount = ReturnType<typeof UseAccount>;
|
9
|
+
export default UseAccount;
|
@@ -0,0 +1,27 @@
|
|
1
|
+
<script lang="ts" module>
|
2
|
+
export type Props = {
|
3
|
+
depth?: DepthsIn<RegisteredAccount>;
|
4
|
+
setResult: (result: ReturnType<typeof useAccountOrGuest> | undefined) => void;
|
5
|
+
};
|
6
|
+
</script>
|
7
|
+
|
8
|
+
<script lang="ts">
|
9
|
+
import { useAccountOrGuest, type RegisteredAccount } from '../../jazz.svelte.js';
|
10
|
+
import type { DepthsIn } from 'jazz-tools';
|
11
|
+
|
12
|
+
let { depth, setResult }: Props = $props();
|
13
|
+
|
14
|
+
if (depth) {
|
15
|
+
const result = $derived(useAccountOrGuest(depth));
|
16
|
+
|
17
|
+
$effect(() => {
|
18
|
+
setResult(result);
|
19
|
+
});
|
20
|
+
} else {
|
21
|
+
const result = $derived(useAccountOrGuest());
|
22
|
+
|
23
|
+
$effect(() => {
|
24
|
+
setResult(result);
|
25
|
+
});
|
26
|
+
}
|
27
|
+
</script>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
export type Props = {
|
2
|
+
depth?: DepthsIn<RegisteredAccount>;
|
3
|
+
setResult: (result: ReturnType<typeof useAccountOrGuest> | undefined) => void;
|
4
|
+
};
|
5
|
+
import { useAccountOrGuest, type RegisteredAccount } from '../../jazz.svelte.js';
|
6
|
+
import type { DepthsIn } from 'jazz-tools';
|
7
|
+
declare const UseAccountOrGuest: import("svelte").Component<Props, {}, "">;
|
8
|
+
type UseAccountOrGuest = ReturnType<typeof UseAccountOrGuest>;
|
9
|
+
export default UseAccountOrGuest;
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<script lang="ts" module>
|
2
|
+
export type Props<R extends CoValue> = {
|
3
|
+
Schema: CoValueClass<R>;
|
4
|
+
id: ID<R>;
|
5
|
+
depth: DepthsIn<R>;
|
6
|
+
setResult: (result: R | undefined) => void;
|
7
|
+
};
|
8
|
+
</script>
|
9
|
+
|
10
|
+
<script lang="ts" generics="R extends CoValue">
|
11
|
+
import { useCoState } from '../../jazz.svelte.js';
|
12
|
+
import type { CoValue, CoValueClass, DepthsIn, ID } from 'jazz-tools';
|
13
|
+
|
14
|
+
let { Schema, id, depth, setResult }: Props<R> = $props();
|
15
|
+
|
16
|
+
const result = $derived(useCoState(Schema, id, depth));
|
17
|
+
|
18
|
+
$effect(() => {
|
19
|
+
setResult(result.current);
|
20
|
+
});
|
21
|
+
</script>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
export type Props<R extends CoValue> = {
|
2
|
+
Schema: CoValueClass<R>;
|
3
|
+
id: ID<R>;
|
4
|
+
depth: DepthsIn<R>;
|
5
|
+
setResult: (result: R | undefined) => void;
|
6
|
+
};
|
7
|
+
import type { CoValue, CoValueClass, DepthsIn, ID } from 'jazz-tools';
|
8
|
+
declare class __sveltets_Render<R extends CoValue> {
|
9
|
+
props(): Props<R>;
|
10
|
+
events(): {};
|
11
|
+
slots(): {};
|
12
|
+
bindings(): "";
|
13
|
+
exports(): {};
|
14
|
+
}
|
15
|
+
interface $$IsomorphicComponent {
|
16
|
+
new <R extends CoValue>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<R>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<R>['props']>, ReturnType<__sveltets_Render<R>['events']>, ReturnType<__sveltets_Render<R>['slots']>> & {
|
17
|
+
$$bindings?: ReturnType<__sveltets_Render<R>['bindings']>;
|
18
|
+
} & ReturnType<__sveltets_Render<R>['exports']>;
|
19
|
+
<R extends CoValue>(internal: unknown, props: ReturnType<__sveltets_Render<R>['props']> & {}): ReturnType<__sveltets_Render<R>['exports']>;
|
20
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
21
|
+
}
|
22
|
+
declare const UseCoState: $$IsomorphicComponent;
|
23
|
+
type UseCoState<R extends CoValue> = InstanceType<typeof UseCoState<R>>;
|
24
|
+
export default UseCoState;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "jazz-svelte",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.9.0",
|
4
4
|
"files": [
|
5
5
|
"dist",
|
6
6
|
"!dist/**/*.test.*",
|
@@ -16,6 +16,10 @@
|
|
16
16
|
".": {
|
17
17
|
"types": "./dist/index.d.ts",
|
18
18
|
"svelte": "./dist/index.js"
|
19
|
+
},
|
20
|
+
"./testing": {
|
21
|
+
"types": "./dist/testing.d.ts",
|
22
|
+
"svelte": "./dist/testing.js"
|
19
23
|
}
|
20
24
|
},
|
21
25
|
"peerDependencies": {
|
@@ -46,8 +50,9 @@
|
|
46
50
|
"vitest": "1.5.3"
|
47
51
|
},
|
48
52
|
"dependencies": {
|
49
|
-
"
|
50
|
-
"jazz-
|
53
|
+
"cojson": "0.9.0",
|
54
|
+
"jazz-browser": "0.9.0",
|
55
|
+
"jazz-tools": "0.9.0"
|
51
56
|
},
|
52
57
|
"scripts": {
|
53
58
|
"dev": "vite dev",
|
@@ -1,14 +0,0 @@
|
|
1
|
-
<script lang="ts">
|
2
|
-
import { createJazzApp } from '../jazz.svelte';
|
3
|
-
|
4
|
-
const { Provider } = createJazzApp();
|
5
|
-
const {auth} = $props();
|
6
|
-
</script>
|
7
|
-
|
8
|
-
<div data-testid="provider-test">
|
9
|
-
<Provider {auth} peer="wss://cloud.jazz.tools/?key=jazz-svelte-test">
|
10
|
-
{#if auth}
|
11
|
-
<span data-testid="provider-auth-test">{JSON.stringify(auth)}</span>
|
12
|
-
{/if}
|
13
|
-
</Provider>
|
14
|
-
</div>
|
@@ -1,17 +0,0 @@
|
|
1
|
-
<script lang="ts">
|
2
|
-
import { createJazzApp } from '../jazz.svelte';
|
3
|
-
import type { Account, CoValueClass, DepthsIn, ID } from 'jazz-tools';
|
4
|
-
|
5
|
-
const { schema, id = undefined, depth = {} } = $props<{
|
6
|
-
schema: CoValueClass<any>;
|
7
|
-
id?: ID<Account>;
|
8
|
-
depth?: DepthsIn<Account>;
|
9
|
-
}>();
|
10
|
-
|
11
|
-
const app = createJazzApp();
|
12
|
-
const result = $derived(app.useCoState(schema, id, depth));
|
13
|
-
</script>
|
14
|
-
|
15
|
-
<div data-testid="test-component">
|
16
|
-
<div data-testid="current-value">{JSON.stringify(result.current)}</div>
|
17
|
-
</div>
|
@@ -1,9 +0,0 @@
|
|
1
|
-
import type { Account, CoValueClass, DepthsIn, ID } from 'jazz-tools';
|
2
|
-
type $$ComponentProps = {
|
3
|
-
schema: CoValueClass<any>;
|
4
|
-
id?: ID<Account>;
|
5
|
-
depth?: DepthsIn<Account>;
|
6
|
-
};
|
7
|
-
declare const TestComponent: import("svelte").Component<$$ComponentProps, {}, "">;
|
8
|
-
type TestComponent = ReturnType<typeof TestComponent>;
|
9
|
-
export default TestComponent;
|
File without changes
|