@dxos/react-client 0.6.13-main.ed424a1 → 0.6.13
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/lib/browser/{chunk-RJRDB4LF.mjs → chunk-CL7JDETM.mjs} +60 -62
- package/dist/lib/browser/chunk-CL7JDETM.mjs.map +7 -0
- package/dist/lib/browser/devtools/index.mjs +1 -1
- package/dist/lib/browser/echo/index.mjs +4 -6
- package/dist/lib/browser/echo/index.mjs.map +3 -3
- package/dist/lib/browser/halo/index.mjs +1 -1
- package/dist/lib/browser/index.mjs +3 -1
- package/dist/lib/browser/index.mjs.map +1 -1
- package/dist/lib/browser/mesh/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +32 -43
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-YNTACPMY.cjs → chunk-C4EWAKPZ.cjs} +60 -63
- package/dist/lib/node/chunk-C4EWAKPZ.cjs.map +7 -0
- package/dist/lib/node/devtools/index.cjs +2 -2
- package/dist/lib/node/echo/index.cjs +5 -7
- package/dist/lib/node/echo/index.cjs.map +3 -3
- package/dist/lib/node/halo/index.cjs +5 -5
- package/dist/lib/node/index.cjs +14 -12
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/mesh/index.cjs +2 -2
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +33 -44
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/client/ClientProvider.d.ts +18 -59
- package/dist/types/src/client/ClientProvider.d.ts.map +1 -1
- package/dist/types/src/client/context.d.ts +4 -1
- package/dist/types/src/client/context.d.ts.map +1 -1
- package/dist/types/src/client/index.d.ts +1 -0
- package/dist/types/src/client/index.d.ts.map +1 -1
- package/dist/types/src/client/useClientServices.d.ts +3 -0
- package/dist/types/src/client/useClientServices.d.ts.map +1 -0
- package/dist/types/src/echo/useQuery.d.ts.map +1 -1
- package/dist/types/src/playwright/playwright.config.d.ts +2 -2
- package/dist/types/src/playwright/playwright.config.d.ts.map +1 -1
- package/dist/types/src/testing/ClientRepeater.d.ts +12 -9
- package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts +3 -5
- package/dist/types/src/testing/util.d.ts.map +1 -1
- package/dist/types/src/testing/withClientProvider.d.ts +1 -4
- package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
- package/dist/types/src/testing/withClientProvider.stories.d.ts +3 -4
- package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -1
- package/package.json +38 -47
- package/project.json +22 -3
- package/src/client/ClientProvider.test.tsx +4 -7
- package/src/client/ClientProvider.tsx +100 -126
- package/src/client/context.ts +5 -4
- package/src/client/index.ts +3 -0
- package/src/client/useClientServices.ts +15 -0
- package/src/client/useConfig.test.tsx +12 -9
- package/src/echo/useQuery.ts +6 -3
- package/src/echo/useSpaces.test.tsx +8 -6
- package/src/halo/useDevices.test.tsx +5 -3
- package/src/playwright/playwright.config.ts +2 -13
- package/src/playwright/smoke.spec.ts +10 -5
- package/src/testing/ClientRepeater.tsx +20 -19
- package/src/testing/util.tsx +6 -11
- package/src/testing/withClientProvider.stories.tsx +10 -19
- package/src/testing/withClientProvider.tsx +18 -22
- package/tsconfig.json +58 -2
- package/dist/lib/browser/chunk-RJRDB4LF.mjs.map +0 -7
- package/dist/lib/node/chunk-YNTACPMY.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-UYJUBYMU.mjs +0 -165
- package/dist/lib/node-esm/chunk-UYJUBYMU.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-V65AVUQO.mjs +0 -295
- package/dist/lib/node-esm/chunk-V65AVUQO.mjs.map +0 -7
- package/dist/lib/node-esm/devtools/index.mjs +0 -44
- package/dist/lib/node-esm/devtools/index.mjs.map +0 -7
- package/dist/lib/node-esm/echo/index.mjs +0 -134
- package/dist/lib/node-esm/echo/index.mjs.map +0 -7
- package/dist/lib/node-esm/halo/index.mjs +0 -100
- package/dist/lib/node-esm/halo/index.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -33
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/invitations/index.mjs +0 -18
- package/dist/lib/node-esm/invitations/index.mjs.map +0 -7
- package/dist/lib/node-esm/mesh/index.mjs +0 -18
- package/dist/lib/node-esm/mesh/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -177
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/lib/node-esm/worker.mjs +0 -5
- package/dist/lib/node-esm/worker.mjs.map +0 -7
- package/vitest.config.ts +0 -22
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
// packages/sdk/react-client/src/client/AgentHostingProvider.tsx
|
|
2
|
-
import React2, { createContext as createContext2, useContext as
|
|
2
|
+
import React2, { createContext as createContext2, useContext as useContext5, useState as useState4 } from "react";
|
|
3
3
|
import { AgentManagerClient, FakeAgentHostingProvider } from "@dxos/client";
|
|
4
4
|
import { log as log2 } from "@dxos/log";
|
|
5
5
|
|
|
6
6
|
// packages/sdk/react-client/src/client/ClientProvider.tsx
|
|
7
|
-
import React, {
|
|
7
|
+
import React, { useEffect, useMemo, useState } from "react";
|
|
8
8
|
import { Client, SystemStatus } from "@dxos/client";
|
|
9
|
-
import {
|
|
9
|
+
import { registerSignalFactory } from "@dxos/echo-signals/react";
|
|
10
10
|
import { log } from "@dxos/log";
|
|
11
11
|
import { useControlledValue } from "@dxos/react-hooks";
|
|
12
12
|
import { getAsyncProviderValue } from "@dxos/util";
|
|
@@ -41,18 +41,15 @@ var printBanner = (client) => {
|
|
|
41
41
|
|
|
42
42
|
// packages/sdk/react-client/src/client/ClientProvider.tsx
|
|
43
43
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/react-client/src/client/ClientProvider.tsx";
|
|
44
|
-
var ClientProvider =
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
var ClientProvider = ({ children, config: configProvider, client: clientProvider, services: servicesProvider, types, status: controlledStatus, fallback: Fallback = () => null, registerSignalFactory: _registerSignalFactory = true, onInitialized, ...options }) => {
|
|
45
|
+
useMemo(() => {
|
|
46
|
+
_registerSignalFactory && registerSignalFactory();
|
|
47
47
|
}, []);
|
|
48
|
+
const [client, setClient] = useState(clientProvider instanceof Client ? clientProvider : void 0);
|
|
48
49
|
const [error, setError] = useState();
|
|
49
50
|
if (error) {
|
|
50
51
|
throw error;
|
|
51
52
|
}
|
|
52
|
-
const [client, setClient] = useState(clientProvider instanceof Client ? clientProvider : void 0);
|
|
53
|
-
useImperativeHandle(forwardedRef, () => client, [
|
|
54
|
-
client
|
|
55
|
-
]);
|
|
56
53
|
const [status, setStatus] = useControlledValue(controlledStatus);
|
|
57
54
|
useEffect(() => {
|
|
58
55
|
if (!client) {
|
|
@@ -61,43 +58,43 @@ var ClientProvider = /* @__PURE__ */ forwardRef(({ children, config: configProvi
|
|
|
61
58
|
const subscription = client.status.subscribe((status2) => setStatus(status2));
|
|
62
59
|
return () => subscription.unsubscribe();
|
|
63
60
|
}, [
|
|
64
|
-
client
|
|
61
|
+
client,
|
|
62
|
+
setStatus
|
|
65
63
|
]);
|
|
66
64
|
useEffect(() => {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
setClient(client3);
|
|
85
|
-
if (!noBanner) {
|
|
86
|
-
printBanner(client3);
|
|
65
|
+
const done = async (client2) => {
|
|
66
|
+
await client2.initialize().catch(setError);
|
|
67
|
+
log("client ready", void 0, {
|
|
68
|
+
F: __dxlog_file,
|
|
69
|
+
L: 115,
|
|
70
|
+
S: void 0,
|
|
71
|
+
C: (f, a) => f(...a)
|
|
72
|
+
});
|
|
73
|
+
await onInitialized?.(client2);
|
|
74
|
+
log("initialization complete", void 0, {
|
|
75
|
+
F: __dxlog_file,
|
|
76
|
+
L: 117,
|
|
77
|
+
S: void 0,
|
|
78
|
+
C: (f, a) => f(...a)
|
|
79
|
+
});
|
|
80
|
+
if (types) {
|
|
81
|
+
client2.addTypes(types);
|
|
87
82
|
}
|
|
83
|
+
setClient(client2);
|
|
84
|
+
setStatus(client2.status.get() ?? SystemStatus.ACTIVE);
|
|
85
|
+
printBanner(client2);
|
|
88
86
|
};
|
|
89
|
-
let client2;
|
|
90
87
|
const t = setTimeout(async () => {
|
|
91
88
|
if (clientProvider) {
|
|
92
|
-
client2 = await getAsyncProviderValue(clientProvider);
|
|
93
|
-
await
|
|
89
|
+
const client2 = await getAsyncProviderValue(clientProvider);
|
|
90
|
+
await done(client2);
|
|
94
91
|
} else {
|
|
95
92
|
const config = await getAsyncProviderValue(configProvider);
|
|
96
93
|
log("resolved config", {
|
|
97
94
|
config
|
|
98
95
|
}, {
|
|
99
96
|
F: __dxlog_file,
|
|
100
|
-
L:
|
|
97
|
+
L: 135,
|
|
101
98
|
S: void 0,
|
|
102
99
|
C: (f, a) => f(...a)
|
|
103
100
|
});
|
|
@@ -106,53 +103,45 @@ var ClientProvider = /* @__PURE__ */ forwardRef(({ children, config: configProvi
|
|
|
106
103
|
services
|
|
107
104
|
}, {
|
|
108
105
|
F: __dxlog_file,
|
|
109
|
-
L:
|
|
106
|
+
L: 137,
|
|
110
107
|
S: void 0,
|
|
111
108
|
C: (f, a) => f(...a)
|
|
112
109
|
});
|
|
113
|
-
client2 = new Client({
|
|
110
|
+
const client2 = new Client({
|
|
114
111
|
config,
|
|
115
112
|
services,
|
|
116
113
|
...options
|
|
117
114
|
});
|
|
118
115
|
log("created client", void 0, {
|
|
119
116
|
F: __dxlog_file,
|
|
120
|
-
L:
|
|
117
|
+
L: 139,
|
|
121
118
|
S: void 0,
|
|
122
119
|
C: (f, a) => f(...a)
|
|
123
120
|
});
|
|
124
|
-
await
|
|
121
|
+
await done(client2);
|
|
125
122
|
}
|
|
126
123
|
});
|
|
127
124
|
return () => {
|
|
128
125
|
log("clean up", void 0, {
|
|
129
126
|
F: __dxlog_file,
|
|
130
|
-
L:
|
|
127
|
+
L: 145,
|
|
131
128
|
S: void 0,
|
|
132
129
|
C: (f, a) => f(...a)
|
|
133
130
|
});
|
|
134
131
|
clearTimeout(t);
|
|
135
|
-
void
|
|
136
|
-
log("destroyed", void 0, {
|
|
137
|
-
F: __dxlog_file,
|
|
138
|
-
L: 170,
|
|
139
|
-
S: void 0,
|
|
140
|
-
C: (f, a) => f(...a)
|
|
141
|
-
});
|
|
142
|
-
}).catch((err) => log.catch(err, void 0, {
|
|
132
|
+
void client?.destroy().catch((err) => log.catch(err, void 0, {
|
|
143
133
|
F: __dxlog_file,
|
|
144
|
-
L:
|
|
134
|
+
L: 147,
|
|
145
135
|
S: void 0,
|
|
146
136
|
C: (f, a) => f(...a)
|
|
147
137
|
}));
|
|
148
138
|
};
|
|
149
139
|
}, [
|
|
150
|
-
configProvider,
|
|
151
140
|
clientProvider,
|
|
152
|
-
|
|
153
|
-
|
|
141
|
+
configProvider,
|
|
142
|
+
servicesProvider
|
|
154
143
|
]);
|
|
155
|
-
if (!client
|
|
144
|
+
if (!client || status !== SystemStatus.ACTIVE) {
|
|
156
145
|
return /* @__PURE__ */ React.createElement(Fallback, {
|
|
157
146
|
client,
|
|
158
147
|
status
|
|
@@ -164,7 +153,7 @@ var ClientProvider = /* @__PURE__ */ forwardRef(({ children, config: configProvi
|
|
|
164
153
|
status
|
|
165
154
|
}
|
|
166
155
|
}, children);
|
|
167
|
-
}
|
|
156
|
+
};
|
|
168
157
|
|
|
169
158
|
// packages/sdk/react-client/src/client/useClient.ts
|
|
170
159
|
import { useContext } from "react";
|
|
@@ -174,6 +163,14 @@ var useClient = () => {
|
|
|
174
163
|
return client;
|
|
175
164
|
};
|
|
176
165
|
|
|
166
|
+
// packages/sdk/react-client/src/client/useClientServices.ts
|
|
167
|
+
import { useContext as useContext2 } from "react";
|
|
168
|
+
import { raise as raise2 } from "@dxos/debug";
|
|
169
|
+
var useClientServices = () => {
|
|
170
|
+
const { services } = useContext2(ClientContext) ?? raise2(new Error("Missing ClientContext."));
|
|
171
|
+
return services;
|
|
172
|
+
};
|
|
173
|
+
|
|
177
174
|
// packages/sdk/react-client/src/client/useClientStatus.ts
|
|
178
175
|
import { useEffect as useEffect2, useState as useState2 } from "react";
|
|
179
176
|
var useClientStatus = (client) => {
|
|
@@ -192,10 +189,10 @@ var useClientStatus = (client) => {
|
|
|
192
189
|
};
|
|
193
190
|
|
|
194
191
|
// packages/sdk/react-client/src/client/useConfig.ts
|
|
195
|
-
import { useContext as
|
|
196
|
-
import { raise as
|
|
192
|
+
import { useContext as useContext3 } from "react";
|
|
193
|
+
import { raise as raise3 } from "@dxos/debug";
|
|
197
194
|
var useConfig = () => {
|
|
198
|
-
const { client } =
|
|
195
|
+
const { client } = useContext3(ClientContext) ?? raise3(new Error("Missing ClientContext."));
|
|
199
196
|
return client.config;
|
|
200
197
|
};
|
|
201
198
|
|
|
@@ -215,10 +212,10 @@ var useShellDisplay = () => {
|
|
|
215
212
|
};
|
|
216
213
|
|
|
217
214
|
// packages/sdk/react-client/src/client/useStatus.ts
|
|
218
|
-
import { useContext as
|
|
219
|
-
import { raise as
|
|
215
|
+
import { useContext as useContext4 } from "react";
|
|
216
|
+
import { raise as raise4 } from "@dxos/debug";
|
|
220
217
|
var useStatus = () => {
|
|
221
|
-
const { status } =
|
|
218
|
+
const { status } = useContext4(ClientContext) ?? raise4(new Error("Missing ClientContext."));
|
|
222
219
|
return status;
|
|
223
220
|
};
|
|
224
221
|
|
|
@@ -233,7 +230,7 @@ var AgentHostingProvider = (props) => {
|
|
|
233
230
|
}, " ", props.children);
|
|
234
231
|
};
|
|
235
232
|
var useAgentHostingClient = () => {
|
|
236
|
-
return
|
|
233
|
+
return useContext5(AgentHostingContext);
|
|
237
234
|
};
|
|
238
235
|
var makeClient = ({ config, halo }) => {
|
|
239
236
|
const agentHostingConfig = config.get("runtime.services.agentHosting");
|
|
@@ -284,10 +281,11 @@ export {
|
|
|
284
281
|
ClientContext,
|
|
285
282
|
ClientProvider,
|
|
286
283
|
useClient,
|
|
284
|
+
useClientServices,
|
|
287
285
|
useClientStatus,
|
|
288
286
|
useConfig,
|
|
289
287
|
useShell,
|
|
290
288
|
useShellDisplay,
|
|
291
289
|
useStatus
|
|
292
290
|
};
|
|
293
|
-
//# sourceMappingURL=chunk-
|
|
291
|
+
//# sourceMappingURL=chunk-CL7JDETM.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/client/AgentHostingProvider.tsx", "../../../src/client/ClientProvider.tsx", "../../../src/client/context.ts", "../../../src/banner.ts", "../../../src/client/useClient.ts", "../../../src/client/useClientServices.ts", "../../../src/client/useClientStatus.ts", "../../../src/client/useConfig.ts", "../../../src/client/useShell.ts", "../../../src/client/useStatus.ts"],
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nimport React, { createContext, type PropsWithChildren, useContext, useState } from 'react';\n\nimport { type AgentHostingProviderClient, AgentManagerClient, FakeAgentHostingProvider } from '@dxos/client';\nimport { type Halo } from '@dxos/client/halo';\nimport { type Config } from '@dxos/config';\nimport { log } from '@dxos/log';\n\nimport { useClient } from '../client';\n\nexport type AgentHostingProviderProps = { config: Config; halo: Halo };\n\nexport const AgentHostingContext = createContext<AgentHostingProviderClient | null>(null);\n\n/**\n * Experimental agent hosting provider.\n * @param props\n * @constructor\n * @deprecated\n */\nexport const AgentHostingProvider = (props: PropsWithChildren<{}>) => {\n const client = useClient();\n const [agentHostingProviderClient] = useState(makeClient(client));\n return (\n <AgentHostingContext.Provider value={agentHostingProviderClient}> {props.children}</AgentHostingContext.Provider>\n );\n};\n\nexport const useAgentHostingClient = () => {\n return useContext(AgentHostingContext);\n};\n\nconst makeClient = ({ config, halo }: AgentHostingProviderProps) => {\n const agentHostingConfig = config.get('runtime.services.agentHosting');\n if (!agentHostingConfig) {\n log('no agent hosting configured');\n return null;\n }\n\n // TODO(nf): Dynamically discover based on runtime config.\n let agentHostingProviderClient: AgentHostingProviderClient | null = null;\n switch (agentHostingConfig.type) {\n case 'LOCAL_TESTING': {\n log('using FakeAgentHostingProvider');\n return new FakeAgentHostingProvider();\n }\n\n case 'AGENTHOSTING_API': {\n agentHostingProviderClient = new AgentManagerClient(config, halo);\n if (agentHostingProviderClient.init()) {\n return agentHostingProviderClient;\n } else {\n // Not authorized or error initializing.\n return null;\n }\n }\n\n default: {\n log.error('Unknown agent hosting provider type: ' + agentHostingConfig.type);\n return null;\n }\n }\n};\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport React, { type FunctionComponent, type ReactNode, useEffect, useMemo, useState } from 'react';\n\nimport { Client, type ClientOptions, type ClientServicesProvider, SystemStatus } from '@dxos/client';\nimport { type Config } from '@dxos/config';\nimport { type S } from '@dxos/echo-schema';\nimport { registerSignalFactory } from '@dxos/echo-signals/react';\nimport { log } from '@dxos/log';\nimport { useControlledValue } from '@dxos/react-hooks';\nimport { getAsyncProviderValue, type MaybePromise, type Provider } from '@dxos/util';\n\nimport { ClientContext, type ClientContextProps } from './context';\nimport { printBanner } from '../banner';\n\n/**\n * Properties for the ClientProvider.\n */\nexport type ClientProviderProps = Pick<ClientContextProps, 'status'> &\n Omit<ClientOptions, 'config' | 'services'> & {\n children?: ReactNode;\n\n /**\n * Config object or async provider.\n */\n config?: Config | Provider<Promise<Config>>;\n\n /**\n * Client object or async provider to enable to caller to do custom initialization.\n *\n * Most apps won't need this.\n */\n // TODO(wittjosiah): Remove async and just use to keep reference to client?\n // (Preferring `onInitialized` for custom initialization.)\n // TODO(burdon): Use useImperativeHandle to expose client.\n client?: Client | Provider<Promise<Client>>;\n\n /**\n * Callback to enable the caller to create a custom ClientServicesProvider.\n *\n * Most apps won't need this.\n */\n services?: ClientServicesProvider | ((config?: Config) => MaybePromise<ClientServicesProvider>);\n\n /**\n * List of schema to register.\n */\n types?: S.Schema<any>[];\n\n /**\n * ReactNode to display until the client is available.\n */\n fallback?: FunctionComponent<Partial<ClientContextProps>>;\n\n /**\n * Set to false to stop default signal factory from being registered.\n */\n // TODO(burdon): Move to options.\n registerSignalFactory?: boolean;\n\n /**\n * Post initialization hook to enable to caller to do custom initialization.\n *\n * @param Client\n */\n onInitialized?: (client: Client) => MaybePromise<void>;\n };\n\n/**\n * Root component that provides the DXOS client instance to child components.\n * To be used with the `useClient` hook.\n */\nexport const ClientProvider = ({\n children,\n config: configProvider,\n client: clientProvider,\n services: servicesProvider,\n types,\n status: controlledStatus,\n fallback: Fallback = () => null,\n registerSignalFactory: _registerSignalFactory = true,\n onInitialized,\n ...options\n}: ClientProviderProps) => {\n useMemo(() => {\n // TODO(wittjosiah): Ideally this should be imported asynchronously because it is optional.\n // Unfortunately, async import seemed to break signals React instrumentation.\n _registerSignalFactory && registerSignalFactory();\n }, []);\n\n const [client, setClient] = useState(clientProvider instanceof Client ? clientProvider : undefined);\n\n const [error, setError] = useState();\n if (error) {\n throw error;\n }\n\n // Status subscription.\n const [status, setStatus] = useControlledValue(controlledStatus);\n useEffect(() => {\n if (!client) {\n return;\n }\n\n const subscription = client.status.subscribe((status) => setStatus(status));\n return () => subscription.unsubscribe();\n }, [client, setStatus]);\n\n // Initialize client.\n useEffect(() => {\n const done = async (client: Client) => {\n await client.initialize().catch(setError);\n log('client ready');\n await onInitialized?.(client);\n log('initialization complete');\n if (types) {\n client.addTypes(types);\n }\n\n setClient(client);\n setStatus(client.status.get() ?? SystemStatus.ACTIVE);\n printBanner(client);\n };\n\n const t = setTimeout(async () => {\n if (clientProvider) {\n // Asynchronously request client.\n const client = await getAsyncProviderValue(clientProvider);\n await done(client);\n } else {\n // Asynchronously construct client (config may be undefined).\n const config = await getAsyncProviderValue(configProvider);\n log('resolved config', { config });\n const services = await getAsyncProviderValue(servicesProvider, config);\n log('created services', { services });\n const client = new Client({ config, services, ...options });\n log('created client');\n await done(client);\n }\n });\n\n return () => {\n log('clean up');\n clearTimeout(t);\n void client?.destroy().catch((err) => log.catch(err));\n };\n }, [clientProvider, configProvider, servicesProvider]);\n\n if (!client || status !== SystemStatus.ACTIVE) {\n return <Fallback client={client} status={status} />;\n }\n\n return <ClientContext.Provider value={{ client, status }}>{children}</ClientContext.Provider>;\n};\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport { type Context, createContext } from 'react';\n\nimport { type Client, type ClientServices, type SystemStatus } from '@dxos/client';\n\nexport type ClientContextProps = {\n client: Client;\n\n // Optionally expose services (e.g., for devtools).\n services?: ClientServices;\n\n status?: SystemStatus | null;\n};\n\nexport const ClientContext: Context<ClientContextProps | undefined> = createContext<ClientContextProps | undefined>(\n undefined,\n);\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { type Client } from '@dxos/client';\n\n// http://patorjk.com/software/taag/#p=testall&f=Patorjk-HeX&t=DXOS\nconst BANNER = (client: Client) => {\n const commitHash = client.config.get('runtime.app.build.commitHash');\n const hash = commitHash ? ` App Commit ${commitHash} \\n` : '';\n\n return (\n '\\n' +\n '_/\\\\/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\______/\\\\/\\\\/\\\\/\\\\/\\\\_\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\__/\\\\/\\\\_________\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\______/\\\\/\\\\______/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\___\\n' +\n '_/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\__________/\\\\/\\\\_\\n' +\n '_/\\\\/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\____/\\\\/\\\\/\\\\/\\\\/\\\\___\\n' +\n `\\n DXOS Client ${client.version} \\n${hash}`\n );\n};\n\nlet bannerPrinted = false;\n\nexport const printBanner = (client: Client) => {\n if (bannerPrinted) {\n return;\n }\n\n bannerPrinted = true;\n // eslint-disable-next-line no-console\n console.log(`%c${BANNER(client)}`, 'font-family: monospace;');\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from '../client/context';\n\n/**\n * Hook returning instance of DXOS client.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useClient = () => {\n const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n return client;\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { type ClientServices } from '@dxos/client';\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from './context';\n\nexport const useClientServices = (): ClientServices | undefined => {\n const { services } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n return services;\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type Client, type SystemStatus } from '@dxos/client';\n\nexport const useClientStatus = (client: Client) => {\n const [status, setStatus] = useState<SystemStatus | null>();\n useEffect(() => {\n if (!client) {\n return;\n }\n\n const subscription = client.status.subscribe((status) => setStatus(status));\n return () => subscription.unsubscribe();\n }, [client, setStatus]);\n\n return status;\n};\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from './context';\n\n/**\n * Hook returning config object used to initialize the DXOS client instance.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useConfig = () => {\n const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n return client.config;\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type Shell, type ShellDisplay } from '@dxos/client';\n\nimport { useClient } from './useClient';\n\n/**\n * Helper hook to access the shell.\n */\nexport const useShell = (): Shell => {\n const client = useClient();\n return client.shell;\n};\n\n/**\n * Hook to access the shell’s display state.\n */\nexport const useShellDisplay = (): ShellDisplay => {\n const client = useClient();\n const [display, setDisplay] = useState(client.shell.display);\n useEffect(() => client.shell.onDisplayChange(setDisplay), [client]);\n return display;\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { type SystemStatus } from '@dxos/client';\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from './context';\n\nexport const useStatus = (): SystemStatus | null | undefined => {\n const { status } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n return status;\n};\n"],
|
|
5
|
+
"mappings": ";AAIA,OAAOA,UAASC,iBAAAA,gBAAuCC,cAAAA,aAAYC,YAAAA,iBAAgB;AAEnF,SAA0CC,oBAAoBC,gCAAgC;AAG9F,SAASC,OAAAA,YAAW;;;ACLpB,OAAOC,SAAiDC,WAAWC,SAASC,gBAAgB;AAE5F,SAASC,QAAyDC,oBAAoB;AAGtF,SAASC,6BAA6B;AACtC,SAASC,WAAW;AACpB,SAASC,0BAA0B;AACnC,SAASC,6BAA+D;;;ACRxE,SAAuBC,qBAAqB;AAarC,IAAMC,gBAAyDC,cACpEC,MAAAA;;;ACXF,IAAMC,SAAS,CAACC,WAAAA;AACd,QAAMC,aAAaD,OAAOE,OAAOC,IAAI,8BAAA;AACrC,QAAMC,OAAOH,aAAa,eAAeA,UAAAA;IAAkB;AAE3D,SACE;;;;;;;eAMkBD,OAAOK,OAAO;EAAMD,IAAAA;AAE1C;AAEA,IAAIE,gBAAgB;AAEb,IAAMC,cAAc,CAACP,WAAAA;AAC1B,MAAIM,eAAe;AACjB;EACF;AAEAA,kBAAgB;AAEhBE,UAAQC,IAAI,KAAKV,OAAOC,MAAAA,CAA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,QAAQ;AAErF;AAEO,IAAMC,wBAAwB,MAAA;AACnC,SAAOC,YAAWd,mBAAAA;AACpB;AAEA,IAAMQ,aAAa,CAAC,EAAEO,QAAQC,KAAI,MAA6B;AAC7D,QAAMC,qBAAqBF,OAAOG,IAAI,+BAAA;AACtC,MAAI,CAACD,oBAAoB;AACvBE,IAAAA,KAAI,+BAAA,QAAA;;;;;;AACJ,WAAO;EACT;AAGA,MAAIb,6BAAgE;AACpE,UAAQW,mBAAmBG,MAAI;IAC7B,KAAK,iBAAiB;AACpBD,MAAAA,KAAI,kCAAA,QAAA;;;;;;AACJ,aAAO,IAAIE,yBAAAA;IACb;IAEA,KAAK,oBAAoB;AACvBf,mCAA6B,IAAIgB,mBAAmBP,QAAQC,IAAAA;AAC5D,UAAIV,2BAA2BiB,KAAI,GAAI;AACrC,eAAOjB;MACT,OAAO;AAEL,eAAO;MACT;IACF;IAEA,SAAS;AACPa,MAAAA,KAAIK,MAAM,0CAA0CP,mBAAmBG,MAAI,QAAA;;;;;;AAC3E,aAAO;IACT;EACF;AACF;",
|
|
6
|
+
"names": ["React", "createContext", "useContext", "useState", "AgentManagerClient", "FakeAgentHostingProvider", "log", "React", "useEffect", "useMemo", "useState", "Client", "SystemStatus", "registerSignalFactory", "log", "useControlledValue", "getAsyncProviderValue", "createContext", "ClientContext", "createContext", "undefined", "BANNER", "client", "commitHash", "config", "get", "hash", "version", "bannerPrinted", "printBanner", "console", "log", "ClientProvider", "children", "config", "configProvider", "client", "clientProvider", "services", "servicesProvider", "types", "status", "controlledStatus", "fallback", "Fallback", "registerSignalFactory", "_registerSignalFactory", "onInitialized", "options", "useMemo", "setClient", "useState", "Client", "undefined", "error", "setError", "setStatus", "useControlledValue", "useEffect", "subscription", "subscribe", "unsubscribe", "done", "initialize", "catch", "log", "addTypes", "get", "SystemStatus", "ACTIVE", "printBanner", "t", "setTimeout", "getAsyncProviderValue", "clearTimeout", "destroy", "err", "ClientContext", "Provider", "value", "useContext", "raise", "useClient", "client", "useContext", "ClientContext", "raise", "Error", "useContext", "raise", "useClientServices", "services", "useContext", "ClientContext", "raise", "Error", "useEffect", "useState", "useClientStatus", "client", "status", "setStatus", "useState", "useEffect", "subscription", "subscribe", "unsubscribe", "useContext", "raise", "useConfig", "client", "useContext", "ClientContext", "raise", "Error", "config", "useEffect", "useState", "useShell", "client", "useClient", "shell", "useShellDisplay", "display", "setDisplay", "useState", "useEffect", "onDisplayChange", "useContext", "raise", "useStatus", "status", "useContext", "ClientContext", "raise", "Error", "AgentHostingContext", "createContext", "AgentHostingProvider", "props", "client", "useClient", "agentHostingProviderClient", "useState", "makeClient", "React", "Provider", "value", "children", "useAgentHostingClient", "useContext", "config", "halo", "agentHostingConfig", "get", "log", "type", "FakeAgentHostingProvider", "AgentManagerClient", "init", "error"]
|
|
7
|
+
}
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
} from "../chunk-AL2CUQ46.mjs";
|
|
4
4
|
import {
|
|
5
5
|
useClient
|
|
6
|
-
} from "../chunk-
|
|
6
|
+
} from "../chunk-CL7JDETM.mjs";
|
|
7
7
|
|
|
8
8
|
// packages/sdk/react-client/src/echo/index.ts
|
|
9
9
|
export * from "@dxos/client/echo";
|
|
@@ -59,7 +59,7 @@ var useMembers = (spaceKey) => {
|
|
|
59
59
|
|
|
60
60
|
// packages/sdk/react-client/src/echo/useQuery.ts
|
|
61
61
|
import { useMemo, useSyncExternalStore } from "react";
|
|
62
|
-
import {
|
|
62
|
+
import { isSpace } from "@dxos/client/echo";
|
|
63
63
|
var useQuery = (spaceOrEcho, filter, options, deps) => {
|
|
64
64
|
const { subscribe, getObjects } = useMemo(() => {
|
|
65
65
|
const query = isSpace(spaceOrEcho) ? spaceOrEcho.db.query(filter, options) : spaceOrEcho?.query(filter, options);
|
|
@@ -77,14 +77,12 @@ var useQuery = (spaceOrEcho, filter, options, deps) => {
|
|
|
77
77
|
};
|
|
78
78
|
}, [
|
|
79
79
|
spaceOrEcho,
|
|
80
|
-
...filterToDepsArray(filter),
|
|
80
|
+
...typeof filter === "function" ? [] : filterToDepsArray(filter),
|
|
81
81
|
...deps ?? []
|
|
82
82
|
]);
|
|
83
83
|
return useSyncExternalStore(subscribe, getObjects) ?? [];
|
|
84
84
|
};
|
|
85
|
-
var filterToDepsArray = (filter) =>
|
|
86
|
-
JSON.stringify(Filter.from(filter).toProto())
|
|
87
|
-
];
|
|
85
|
+
var filterToDepsArray = (filter) => Object.entries(filter ?? {}).flat(10).map((x) => typeof x === "function" || typeof x === "object" ? null : x);
|
|
88
86
|
var noop = () => {
|
|
89
87
|
};
|
|
90
88
|
var EMPTY_ARRAY = [];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/echo/index.ts", "../../../../src/echo/useMembers.ts", "../../../../src/echo/useSpaces.ts", "../../../../src/echo/useQuery.ts", "../../../../src/echo/useSpaceInvitations.ts", "../../../../src/echo/useSubscription.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nexport * from '@dxos/client/echo';\n\nexport * from './useMembers';\nexport * from './useQuery';\nexport * from './useSpaces';\nexport * from './useSpaceInvitations';\nexport * from './useSubscription';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { MulticastObservable } from '@dxos/async';\nimport { type PublicKey } from '@dxos/client';\nimport { HaloSpaceMember, type SpaceMember } from '@dxos/client/echo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useSpaces } from './useSpaces';\n\nexport const useMembers = (spaceKey: PublicKey | undefined): SpaceMember[] => {\n // TODO(dmaretskyi): useSpace hook for spaces that are not ready.\n const spaces = useSpaces({ all: true });\n const space = spaceKey ? spaces.find((space) => space.key.equals(spaceKey)) : undefined;\n\n // EMPTY_OBSERVABLE needs to be a stable reference to avoid re-subscribing on every render.\n const members = useMulticastObservable(space?.members ?? MulticastObservable.empty()) ?? [];\n return members.filter((member) => member.role !== HaloSpaceMember.Role.REMOVED);\n};\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type PublicKeyLike } from '@dxos/client';\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\n/**\n * Get a specific Space using its key.\n * The space is not guaranteed to be in the ready state.\n * Returns the default space if no key is provided.\n * Requires a ClientProvider somewhere in the parent tree.\n *\n * @param spaceKeyLike the key of the space to look for\n */\nexport const useSpace = (spaceKeyLike?: PublicKeyLike): Space | undefined => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n const [ready, setReady] = useState(false);\n\n useEffect(() => {\n // Only wait for ready if looking for the default space.\n if (spaceKeyLike) {\n return;\n }\n\n const timeout = setTimeout(async () => {\n await client.spaces.isReady.wait();\n setReady(true);\n });\n\n return () => clearTimeout(timeout);\n }, [client, spaceKeyLike]);\n\n if (spaceKeyLike) {\n return spaces.find((space) => space.key.equals(spaceKeyLike) || space.id === spaceKeyLike);\n }\n\n if (ready && client.halo.identity.get()) {\n return client.spaces.default;\n }\n};\n\nexport type UseSpacesParams = {\n /**\n * Return uninitialized spaces as well.\n */\n all?: boolean;\n};\n\n/**\n * Get all Spaces available to current user.\n * Requires a ClientProvider somewhere in the parent tree.\n * By default, only ready spaces are returned.\n * @returns an array of Spaces\n */\nexport const useSpaces = ({ all = false }: UseSpacesParams = {}): Space[] => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n\n // TODO(dmaretskyi): Array reference equality.\n return spaces.filter((space) => all || space.state.get() === SpaceState.SPACE_READY);\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport {\n
|
|
5
|
-
"mappings": ";;;;;;;;AAIA,cAAc;;;ACAd,SAASA,2BAA2B;AAEpC,SAASC,uBAAyC;AAClD,SAASC,0BAAAA,+BAA8B;;;ACHvC,SAASC,WAA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;;;AEfA,SAASC,SAASC,4BAA4B;AAE9C,SACEC,
|
|
6
|
-
"names": ["MulticastObservable", "HaloSpaceMember", "useMulticastObservable", "useEffect", "useState", "SpaceState", "useMulticastObservable", "useSpace", "spaceKeyLike", "client", "useClient", "spaces", "useMulticastObservable", "ready", "setReady", "useState", "useEffect", "timeout", "setTimeout", "isReady", "wait", "clearTimeout", "find", "space", "key", "equals", "id", "halo", "identity", "get", "default", "useSpaces", "all", "filter", "state", "SpaceState", "SPACE_READY", "useMembers", "spaceKey", "spaces", "useSpaces", "all", "space", "find", "key", "equals", "undefined", "members", "useMulticastObservable", "MulticastObservable", "empty", "filter", "member", "role", "HaloSpaceMember", "Role", "REMOVED", "useMemo", "useSyncExternalStore", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nexport * from '@dxos/client/echo';\n\nexport * from './useMembers';\nexport * from './useQuery';\nexport * from './useSpaces';\nexport * from './useSpaceInvitations';\nexport * from './useSubscription';\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { MulticastObservable } from '@dxos/async';\nimport { type PublicKey } from '@dxos/client';\nimport { HaloSpaceMember, type SpaceMember } from '@dxos/client/echo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useSpaces } from './useSpaces';\n\nexport const useMembers = (spaceKey: PublicKey | undefined): SpaceMember[] => {\n // TODO(dmaretskyi): useSpace hook for spaces that are not ready.\n const spaces = useSpaces({ all: true });\n const space = spaceKey ? spaces.find((space) => space.key.equals(spaceKey)) : undefined;\n\n // EMPTY_OBSERVABLE needs to be a stable reference to avoid re-subscribing on every render.\n const members = useMulticastObservable(space?.members ?? MulticastObservable.empty()) ?? [];\n return members.filter((member) => member.role !== HaloSpaceMember.Role.REMOVED);\n};\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport { useEffect, useState } from 'react';\n\nimport { type PublicKeyLike } from '@dxos/client';\nimport { type Space, SpaceState } from '@dxos/client/echo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\n/**\n * Get a specific Space using its key.\n * The space is not guaranteed to be in the ready state.\n * Returns the default space if no key is provided.\n * Requires a ClientProvider somewhere in the parent tree.\n *\n * @param spaceKeyLike the key of the space to look for\n */\nexport const useSpace = (spaceKeyLike?: PublicKeyLike): Space | undefined => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n const [ready, setReady] = useState(false);\n\n useEffect(() => {\n // Only wait for ready if looking for the default space.\n if (spaceKeyLike) {\n return;\n }\n\n const timeout = setTimeout(async () => {\n await client.spaces.isReady.wait();\n setReady(true);\n });\n\n return () => clearTimeout(timeout);\n }, [client, spaceKeyLike]);\n\n if (spaceKeyLike) {\n return spaces.find((space) => space.key.equals(spaceKeyLike) || space.id === spaceKeyLike);\n }\n\n if (ready && client.halo.identity.get()) {\n return client.spaces.default;\n }\n};\n\nexport type UseSpacesParams = {\n /**\n * Return uninitialized spaces as well.\n */\n all?: boolean;\n};\n\n/**\n * Get all Spaces available to current user.\n * Requires a ClientProvider somewhere in the parent tree.\n * By default, only ready spaces are returned.\n * @returns an array of Spaces\n */\nexport const useSpaces = ({ all = false }: UseSpacesParams = {}): Space[] => {\n const client = useClient();\n const spaces = useMulticastObservable<Space[]>(client.spaces);\n\n // TODO(dmaretskyi): Array reference equality.\n return spaces.filter((space) => all || space.state.get() === SpaceState.SPACE_READY);\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo, useSyncExternalStore } from 'react';\n\nimport {\n isSpace,\n type Echo,\n type EchoReactiveObject,\n type FilterSource,\n type Query,\n type QueryOptions,\n type Space,\n} from '@dxos/client/echo';\n\n/**\n * Create subscription.\n */\n// TODO(burdon): Support typed operator filters (e.g., Note.filter(note => ...)).\nexport const useQuery = <T extends EchoReactiveObject<any>>(\n spaceOrEcho?: Space | Echo,\n filter?: FilterSource<T>,\n options?: QueryOptions,\n deps?: any[],\n): T[] => {\n const { subscribe, getObjects } = useMemo(() => {\n const query = isSpace(spaceOrEcho)\n ? spaceOrEcho.db.query(filter, options)\n : (spaceOrEcho?.query(filter, options) as Query<T> | undefined);\n let subscribed = false;\n\n return {\n subscribe: (cb: () => void) => {\n subscribed = true;\n const unsubscribe = query?.subscribe(cb) ?? noop;\n return () => {\n unsubscribe?.();\n subscribed = false;\n };\n },\n getObjects: () => (subscribed && query ? query.objects : EMPTY_ARRAY),\n };\n }, [spaceOrEcho, ...(typeof filter === 'function' ? [] : filterToDepsArray(filter)), ...(deps ?? [])]);\n\n // https://beta.reactjs.org/reference/react/useSyncExternalStore\n // NOTE: This hook will resubscribe whenever the callback passed to the first argument changes -- make sure it is stable.\n return useSyncExternalStore<T[] | undefined>(subscribe, getObjects) ?? [];\n};\n\n// TODO(dmaretskyi): Serialize the filter here instead.\nconst filterToDepsArray = (filter?: FilterSource<any>) =>\n Object.entries(filter ?? {})\n .flat(10)\n .map((x) => (typeof x === 'function' || typeof x === 'object' ? null : x));\n\nconst noop = () => {};\n\nconst EMPTY_ARRAY: never[] = [];\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { MulticastObservable } from '@dxos/async';\nimport { type PublicKey } from '@dxos/client';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useSpace } from './useSpaces';\nimport { type CancellableInvitationObservable, useInvitationStatus } from '../invitations';\n\nexport const useSpaceInvitations = (spaceKey?: PublicKey): CancellableInvitationObservable[] => {\n const space = useSpace(spaceKey);\n return useMulticastObservable(space?.invitations ?? MulticastObservable.empty()) ?? [];\n};\n\nexport const useSpaceInvitation = (spaceKey?: PublicKey, invitationId?: string) => {\n const invitations = useSpaceInvitations(spaceKey);\n const invitation = useMemo(\n () => invitations.find((invitation) => invitation.get().invitationId === invitationId),\n [invitations],\n );\n return useInvitationStatus(invitation);\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { useEffect, useRef } from 'react';\n\nimport { type Selection, type SubscriptionHandle, createSubscription } from '@dxos/client/echo';\n\n/**\n * Create reactive selection.\n * Calls the callback when the selection changes and during the first render.\n */\n// TODO(wittjosiah): Is this still needed with signals reactivity? If not, remove or update jsdoc with usage info.\nexport const useSubscription = (cb: () => void, selection: Selection) => {\n // Make sure that the callback is always the one from the latest render.\n // Without this, we would always call the callback from the initial render,\n // which might contain stale data.\n const callbackRef = useRef(cb);\n callbackRef.current = cb;\n\n const subscriptionRef = useRef<SubscriptionHandle>();\n\n useEffect(() => {\n subscriptionRef.current = createSubscription(() => {\n callbackRef.current();\n });\n\n return () => subscriptionRef.current?.unsubscribe();\n }, []);\n\n subscriptionRef.current?.update(selection);\n return subscriptionRef.current;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;AAIA,cAAc;;;ACAd,SAASA,2BAA2B;AAEpC,SAASC,uBAAyC;AAClD,SAASC,0BAAAA,+BAA8B;;;ACHvC,SAASC,WAAWC,gBAAgB;AAGpC,SAAqBC,kBAAkB;AACvC,SAASC,8BAA8B;AAYhC,IAAMC,WAAW,CAACC,iBAAAA;AACvB,QAAMC,SAASC,UAAAA;AACf,QAAMC,SAASC,uBAAgCH,OAAOE,MAAM;AAC5D,QAAM,CAACE,OAAOC,QAAAA,IAAYC,SAAS,KAAA;AAEnCC,YAAU,MAAA;AAER,QAAIR,cAAc;AAChB;IACF;AAEA,UAAMS,UAAUC,WAAW,YAAA;AACzB,YAAMT,OAAOE,OAAOQ,QAAQC,KAAI;AAChCN,eAAS,IAAA;IACX,CAAA;AAEA,WAAO,MAAMO,aAAaJ,OAAAA;EAC5B,GAAG;IAACR;IAAQD;GAAa;AAEzB,MAAIA,cAAc;AAChB,WAAOG,OAAOW,KAAK,CAACC,UAAUA,MAAMC,IAAIC,OAAOjB,YAAAA,KAAiBe,MAAMG,OAAOlB,YAAAA;EAC/E;AAEA,MAAIK,SAASJ,OAAOkB,KAAKC,SAASC,IAAG,GAAI;AACvC,WAAOpB,OAAOE,OAAOmB;EACvB;AACF;AAeO,IAAMC,YAAY,CAAC,EAAE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zBiB,OAAOC,QAAQlB,UAAU,CAAC,CAAA,EACvBmB,KAAK,EAAA,EACLC,IAAI,CAACC,MAAO,OAAOA,MAAM,cAAc,OAAOA,MAAM,WAAW,OAAOA,CAAAA;AAE3E,IAAMT,OAAO,MAAA;AAAO;AAEpB,IAAME,cAAuB,CAAA;;;ACtD7B,SAASQ,WAAAA,gBAAe;AAExB,SAASC,uBAAAA,4BAA2B;AAEpC,SAASC,0BAAAA,+BAA8B;AAKhC,IAAMC,sBAAsB,CAACC,aAAAA;AAClC,QAAMC,QAAQC,SAASF,QAAAA;AACvB,SAAOG,wBAAuBF,OAAOG,eAAeC,qBAAoBC,MAAK,CAAA,KAAO,CAAA;AACtF;AAEO,IAAMC,qBAAqB,CAACP,UAAsBQ,iBAAAA;AACvD,QAAMJ,cAAcL,oBAAoBC,QAAAA;AACxC,QAAMS,aAAaC,SACjB,MAAMN,YAAYO,KAAK,CAACF,gBAAeA,YAAWG,IAAG,EAAGJ,iBAAiBA,YAAAA,GACzE;IAACJ;GAAY;AAEf,SAAOS,oBAAoBJ,UAAAA;AAC7B;;;ACrBA,SAASK,aAAAA,YAAWC,cAAc;AAElC,SAAkDC,0BAA0B;AAOrE,IAAMC,kBAAkB,CAACC,IAAgBC,cAAAA;AAI9C,QAAMC,cAAcC,OAAOH,EAAAA;AAC3BE,cAAYE,UAAUJ;AAEtB,QAAMK,kBAAkBF,OAAAA;AAExBG,EAAAA,WAAU,MAAA;AACRD,oBAAgBD,UAAUG,mBAAmB,MAAA;AAC3CL,kBAAYE,QAAO;IACrB,CAAA;AAEA,WAAO,MAAMC,gBAAgBD,SAASI,YAAAA;EACxC,GAAG,CAAA,CAAE;AAELH,kBAAgBD,SAASK,OAAOR,SAAAA;AAChC,SAAOI,gBAAgBD;AACzB;",
|
|
6
|
+
"names": ["MulticastObservable", "HaloSpaceMember", "useMulticastObservable", "useEffect", "useState", "SpaceState", "useMulticastObservable", "useSpace", "spaceKeyLike", "client", "useClient", "spaces", "useMulticastObservable", "ready", "setReady", "useState", "useEffect", "timeout", "setTimeout", "isReady", "wait", "clearTimeout", "find", "space", "key", "equals", "id", "halo", "identity", "get", "default", "useSpaces", "all", "filter", "state", "SpaceState", "SPACE_READY", "useMembers", "spaceKey", "spaces", "useSpaces", "all", "space", "find", "key", "equals", "undefined", "members", "useMulticastObservable", "MulticastObservable", "empty", "filter", "member", "role", "HaloSpaceMember", "Role", "REMOVED", "useMemo", "useSyncExternalStore", "isSpace", "useQuery", "spaceOrEcho", "filter", "options", "deps", "subscribe", "getObjects", "useMemo", "query", "isSpace", "db", "subscribed", "cb", "unsubscribe", "noop", "objects", "EMPTY_ARRAY", "filterToDepsArray", "useSyncExternalStore", "Object", "entries", "flat", "map", "x", "useMemo", "MulticastObservable", "useMulticastObservable", "useSpaceInvitations", "spaceKey", "space", "useSpace", "useMulticastObservable", "invitations", "MulticastObservable", "empty", "useSpaceInvitation", "invitationId", "invitation", "useMemo", "find", "get", "useInvitationStatus", "useEffect", "useRef", "createSubscription", "useSubscription", "cb", "selection", "callbackRef", "useRef", "current", "subscriptionRef", "useEffect", "createSubscription", "unsubscribe", "update"]
|
|
7
7
|
}
|
|
@@ -5,12 +5,13 @@ import {
|
|
|
5
5
|
ClientProvider,
|
|
6
6
|
useAgentHostingClient,
|
|
7
7
|
useClient,
|
|
8
|
+
useClientServices,
|
|
8
9
|
useClientStatus,
|
|
9
10
|
useConfig,
|
|
10
11
|
useShell,
|
|
11
12
|
useShellDisplay,
|
|
12
13
|
useStatus
|
|
13
|
-
} from "./chunk-
|
|
14
|
+
} from "./chunk-CL7JDETM.mjs";
|
|
14
15
|
|
|
15
16
|
// packages/sdk/react-client/src/index.ts
|
|
16
17
|
export * from "@dxos/client";
|
|
@@ -22,6 +23,7 @@ export {
|
|
|
22
23
|
ClientProvider,
|
|
23
24
|
useAgentHostingClient,
|
|
24
25
|
useClient,
|
|
26
|
+
useClientServices,
|
|
25
27
|
useClientStatus,
|
|
26
28
|
useConfig,
|
|
27
29
|
useMulticastObservable,
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/index.ts"],
|
|
4
4
|
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nexport * from '@dxos/client';\nexport { useMulticastObservable } from '@dxos/react-hooks';\n\nexport * from './client';\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;AAIA,cAAc;AACd,SAASA,8BAA8B;",
|
|
6
6
|
"names": ["useMulticastObservable"]
|
|
7
7
|
}
|