@dxos/react-client 0.6.10 → 0.6.11-staging.66fb9aa
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-NLQLAARM.mjs → chunk-BLQHBTRS.mjs} +67 -39
- package/dist/lib/browser/chunk-BLQHBTRS.mjs.map +7 -0
- package/dist/lib/browser/devtools/index.mjs +6 -18
- package/dist/lib/browser/devtools/index.mjs.map +3 -3
- package/dist/lib/browser/echo/index.mjs +4 -4
- package/dist/lib/browser/echo/index.mjs.map +1 -1
- package/dist/lib/browser/halo/index.mjs +5 -5
- package/dist/lib/browser/halo/index.mjs.map +1 -1
- package/dist/lib/browser/index.mjs +4 -2
- package/dist/lib/browser/index.mjs.map +2 -2
- package/dist/lib/browser/mesh/index.mjs +2 -2
- package/dist/lib/browser/mesh/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +108 -12
- package/dist/lib/browser/testing/index.mjs.map +4 -4
- package/dist/lib/node/{chunk-E3S6YHNJ.cjs → chunk-D7WQQFA3.cjs} +62 -39
- package/dist/lib/node/chunk-D7WQQFA3.cjs.map +7 -0
- package/dist/lib/node/devtools/index.cjs +8 -20
- package/dist/lib/node/devtools/index.cjs.map +3 -3
- package/dist/lib/node/echo/index.cjs +10 -10
- package/dist/lib/node/echo/index.cjs.map +2 -2
- package/dist/lib/node/halo/index.cjs +13 -13
- package/dist/lib/node/halo/index.cjs.map +2 -2
- package/dist/lib/node/index.cjs +16 -14
- package/dist/lib/node/index.cjs.map +2 -2
- package/dist/lib/node/mesh/index.cjs +4 -4
- package/dist/lib/node/mesh/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +106 -10
- package/dist/lib/node/testing/index.cjs.map +4 -4
- package/dist/types/src/client/AgentHostingProvider.d.ts +6 -0
- package/dist/types/src/client/AgentHostingProvider.d.ts.map +1 -1
- package/dist/types/src/client/{ClientContext.d.ts → ClientProvider.d.ts} +15 -20
- package/dist/types/src/client/ClientProvider.d.ts.map +1 -0
- package/dist/types/src/client/ClientProvider.test.d.ts +2 -0
- package/dist/types/src/client/ClientProvider.test.d.ts.map +1 -0
- package/dist/types/src/client/context.d.ts +9 -0
- package/dist/types/src/client/context.d.ts.map +1 -0
- package/dist/types/src/client/index.d.ts +4 -1
- package/dist/types/src/client/index.d.ts.map +1 -1
- package/dist/types/src/client/useClient.d.ts +6 -0
- package/dist/types/src/client/useClient.d.ts.map +1 -0
- package/dist/types/src/client/useClientServices.d.ts +1 -1
- package/dist/types/src/client/useClientServices.d.ts.map +1 -1
- package/dist/types/src/client/useClientStatus.d.ts +3 -0
- package/dist/types/src/client/useClientStatus.d.ts.map +1 -0
- package/dist/types/src/devtools/useDevtools.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/testing/ClientRepeater.d.ts +6 -5
- package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
- package/dist/types/src/testing/{decorators.stories.d.ts → ClientRepeater.stories.d.ts} +3 -3
- package/dist/types/src/testing/ClientRepeater.stories.d.ts.map +1 -0
- package/dist/types/src/testing/index.d.ts +1 -0
- package/dist/types/src/testing/index.d.ts.map +1 -1
- package/dist/types/src/testing/util.d.ts +12 -0
- package/dist/types/src/testing/util.d.ts.map +1 -0
- package/dist/types/src/testing/withClientProvider.d.ts +26 -0
- package/dist/types/src/testing/withClientProvider.d.ts.map +1 -0
- package/dist/types/src/testing/withClientProvider.stories.d.ts +13 -0
- package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -0
- package/package.json +23 -20
- package/src/client/AgentHostingProvider.tsx +7 -6
- package/src/client/{ClientContext.test.tsx → ClientProvider.test.tsx} +2 -1
- package/src/client/ClientProvider.tsx +156 -0
- package/src/client/context.ts +20 -0
- package/src/client/index.ts +7 -1
- package/src/client/useClient.ts +18 -0
- package/src/client/useClientServices.ts +2 -2
- package/src/client/useClientStatus.ts +21 -0
- package/src/client/useConfig.test.tsx +1 -1
- package/src/client/useConfig.ts +1 -1
- package/src/client/useShell.ts +1 -1
- package/src/client/useStatus.ts +1 -1
- package/src/devtools/useDevtools.ts +3 -7
- package/src/echo/useMembers.ts +1 -1
- package/src/echo/useSpaceInvitations.ts +1 -1
- package/src/echo/useSpaces.test.tsx +10 -34
- package/src/echo/useSpaces.ts +1 -1
- package/src/halo/useContacts.ts +1 -1
- package/src/halo/useDevices.test.tsx +3 -10
- package/src/halo/useDevices.ts +1 -1
- package/src/halo/useHaloInvitations.ts +1 -1
- package/src/halo/useIdentity.ts +1 -1
- package/src/index.ts +1 -1
- package/src/mesh/useNetworkStatus.ts +1 -1
- package/src/testing/ClientRepeater.stories.tsx +58 -0
- package/src/testing/ClientRepeater.tsx +14 -13
- package/src/testing/index.ts +1 -0
- package/src/testing/util.tsx +34 -0
- package/src/testing/withClientProvider.stories.tsx +56 -0
- package/src/testing/withClientProvider.tsx +142 -0
- package/tsconfig.json +9 -3
- package/dist/lib/browser/chunk-NLQLAARM.mjs.map +0 -7
- package/dist/lib/node/chunk-E3S6YHNJ.cjs.map +0 -7
- package/dist/types/src/client/ClientContext.d.ts.map +0 -1
- package/dist/types/src/client/ClientContext.stories.d.ts +0 -15
- package/dist/types/src/client/ClientContext.stories.d.ts.map +0 -1
- package/dist/types/src/client/ClientContext.test.d.ts +0 -2
- package/dist/types/src/client/ClientContext.test.d.ts.map +0 -1
- package/dist/types/src/testing/decorators.stories.d.ts.map +0 -1
- package/src/client/ClientContext.stories.tsx +0 -94
- package/src/client/ClientContext.tsx +0 -182
- package/src/testing/decorators.stories.tsx +0 -63
|
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
26
26
|
mod
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var
|
|
30
|
-
__export(
|
|
29
|
+
var chunk_D7WQQFA3_exports = {};
|
|
30
|
+
__export(chunk_D7WQQFA3_exports, {
|
|
31
31
|
AgentHostingContext: () => AgentHostingContext,
|
|
32
32
|
AgentHostingProvider: () => AgentHostingProvider,
|
|
33
33
|
ClientContext: () => ClientContext,
|
|
@@ -35,28 +35,34 @@ __export(chunk_E3S6YHNJ_exports, {
|
|
|
35
35
|
useAgentHostingClient: () => useAgentHostingClient,
|
|
36
36
|
useClient: () => useClient,
|
|
37
37
|
useClientServices: () => useClientServices,
|
|
38
|
+
useClientStatus: () => useClientStatus,
|
|
38
39
|
useConfig: () => useConfig,
|
|
39
40
|
useShell: () => useShell,
|
|
40
41
|
useShellDisplay: () => useShellDisplay,
|
|
41
42
|
useStatus: () => useStatus
|
|
42
43
|
});
|
|
43
|
-
module.exports = __toCommonJS(
|
|
44
|
+
module.exports = __toCommonJS(chunk_D7WQQFA3_exports);
|
|
44
45
|
var import_react = __toESM(require("react"));
|
|
45
46
|
var import_client = require("@dxos/client");
|
|
46
47
|
var import_log = require("@dxos/log");
|
|
47
48
|
var import_react2 = __toESM(require("react"));
|
|
48
49
|
var import_client2 = require("@dxos/client");
|
|
49
|
-
var import_debug = require("@dxos/debug");
|
|
50
50
|
var import_react3 = require("@dxos/echo-signals/react");
|
|
51
51
|
var import_log2 = require("@dxos/log");
|
|
52
|
+
var import_react_hooks = require("@dxos/react-hooks");
|
|
52
53
|
var import_util = require("@dxos/util");
|
|
53
54
|
var import_react4 = require("react");
|
|
54
|
-
var import_debug2 = require("@dxos/debug");
|
|
55
55
|
var import_react5 = require("react");
|
|
56
|
-
var
|
|
56
|
+
var import_debug = require("@dxos/debug");
|
|
57
57
|
var import_react6 = require("react");
|
|
58
|
+
var import_debug2 = require("@dxos/debug");
|
|
58
59
|
var import_react7 = require("react");
|
|
60
|
+
var import_react8 = require("react");
|
|
61
|
+
var import_debug3 = require("@dxos/debug");
|
|
62
|
+
var import_react9 = require("react");
|
|
63
|
+
var import_react10 = require("react");
|
|
59
64
|
var import_debug4 = require("@dxos/debug");
|
|
65
|
+
var ClientContext = (0, import_react4.createContext)(void 0);
|
|
60
66
|
var BANNER = (client) => {
|
|
61
67
|
const commitHash = client.config.get("runtime.app.build.commitHash");
|
|
62
68
|
const hash = commitHash ? ` App Commit ${commitHash}
|
|
@@ -79,22 +85,17 @@ var printBanner = (client) => {
|
|
|
79
85
|
bannerPrinted = true;
|
|
80
86
|
console.log(`%c${BANNER(client)}`, "font-family: monospace;");
|
|
81
87
|
};
|
|
82
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/react-client/src/client/
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
};
|
|
88
|
-
var ClientProvider = ({ children, config: configProvider, services: createServices, client: clientProvider, fallback: Fallback = () => null, registerSignalFactory: register = true, onInitialized, ...options }) => {
|
|
89
|
-
(0, import_react2.useMemo)(() => {
|
|
90
|
-
register && (0, import_react3.registerSignalFactory)();
|
|
91
|
-
}, []);
|
|
88
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/react-client/src/client/ClientProvider.tsx";
|
|
89
|
+
var ClientProvider = ({ children, config: configProvider, client: clientProvider, services: servicesProvider, types, status: controlledStatus, fallback: Fallback = () => null, registerSignalFactory: _registerSignalFactory = true, onInitialized, ...options }) => {
|
|
90
|
+
(0, import_react2.useRef)(() => {
|
|
91
|
+
_registerSignalFactory && (0, import_react3.registerSignalFactory)();
|
|
92
|
+
});
|
|
92
93
|
const [client, setClient] = (0, import_react2.useState)(clientProvider instanceof import_client2.Client ? clientProvider : void 0);
|
|
93
|
-
const [status, setStatus] = (0, import_react2.useState)(null);
|
|
94
94
|
const [error, setError] = (0, import_react2.useState)();
|
|
95
95
|
if (error) {
|
|
96
96
|
throw error;
|
|
97
97
|
}
|
|
98
|
+
const [status, setStatus] = (0, import_react_hooks.useControlledValue)(controlledStatus);
|
|
98
99
|
(0, import_react2.useEffect)(() => {
|
|
99
100
|
if (!client) {
|
|
100
101
|
return;
|
|
@@ -110,41 +111,44 @@ var ClientProvider = ({ children, config: configProvider, services: createServic
|
|
|
110
111
|
await client2.initialize().catch(setError);
|
|
111
112
|
(0, import_log2.log)("client ready", void 0, {
|
|
112
113
|
F: __dxlog_file,
|
|
113
|
-
L:
|
|
114
|
+
L: 115,
|
|
114
115
|
S: void 0,
|
|
115
116
|
C: (f, a) => f(...a)
|
|
116
117
|
});
|
|
117
118
|
await onInitialized?.(client2);
|
|
118
119
|
(0, import_log2.log)("initialization complete", void 0, {
|
|
119
120
|
F: __dxlog_file,
|
|
120
|
-
L:
|
|
121
|
+
L: 117,
|
|
121
122
|
S: void 0,
|
|
122
123
|
C: (f, a) => f(...a)
|
|
123
124
|
});
|
|
125
|
+
if (types) {
|
|
126
|
+
client2.addTypes(types);
|
|
127
|
+
}
|
|
124
128
|
setClient(client2);
|
|
125
129
|
setStatus(client2.status.get() ?? import_client2.SystemStatus.ACTIVE);
|
|
126
130
|
printBanner(client2);
|
|
127
131
|
};
|
|
128
|
-
const
|
|
132
|
+
const t = setTimeout(async () => {
|
|
129
133
|
if (clientProvider) {
|
|
130
|
-
const client2 = await (0, import_util.
|
|
134
|
+
const client2 = await (0, import_util.getAsyncProviderValue)(clientProvider);
|
|
131
135
|
await done(client2);
|
|
132
136
|
} else {
|
|
133
|
-
const config = await (0, import_util.
|
|
137
|
+
const config = await (0, import_util.getAsyncProviderValue)(configProvider);
|
|
134
138
|
(0, import_log2.log)("resolved config", {
|
|
135
139
|
config
|
|
136
140
|
}, {
|
|
137
141
|
F: __dxlog_file,
|
|
138
|
-
L:
|
|
142
|
+
L: 135,
|
|
139
143
|
S: void 0,
|
|
140
144
|
C: (f, a) => f(...a)
|
|
141
145
|
});
|
|
142
|
-
const services = await
|
|
146
|
+
const services = await (0, import_util.getAsyncProviderValue)(servicesProvider, config);
|
|
143
147
|
(0, import_log2.log)("created services", {
|
|
144
148
|
services
|
|
145
149
|
}, {
|
|
146
150
|
F: __dxlog_file,
|
|
147
|
-
L:
|
|
151
|
+
L: 137,
|
|
148
152
|
S: void 0,
|
|
149
153
|
C: (f, a) => f(...a)
|
|
150
154
|
});
|
|
@@ -155,7 +159,7 @@ var ClientProvider = ({ children, config: configProvider, services: createServic
|
|
|
155
159
|
});
|
|
156
160
|
(0, import_log2.log)("created client", void 0, {
|
|
157
161
|
F: __dxlog_file,
|
|
158
|
-
L:
|
|
162
|
+
L: 139,
|
|
159
163
|
S: void 0,
|
|
160
164
|
C: (f, a) => f(...a)
|
|
161
165
|
});
|
|
@@ -165,14 +169,14 @@ var ClientProvider = ({ children, config: configProvider, services: createServic
|
|
|
165
169
|
return () => {
|
|
166
170
|
(0, import_log2.log)("clean up", void 0, {
|
|
167
171
|
F: __dxlog_file,
|
|
168
|
-
L:
|
|
172
|
+
L: 145,
|
|
169
173
|
S: void 0,
|
|
170
174
|
C: (f, a) => f(...a)
|
|
171
175
|
});
|
|
172
|
-
clearTimeout(
|
|
176
|
+
clearTimeout(t);
|
|
173
177
|
void client?.destroy().catch((err) => import_log2.log.catch(err, void 0, {
|
|
174
178
|
F: __dxlog_file,
|
|
175
|
-
L:
|
|
179
|
+
L: 147,
|
|
176
180
|
S: void 0,
|
|
177
181
|
C: (f, a) => f(...a)
|
|
178
182
|
}));
|
|
@@ -180,7 +184,7 @@ var ClientProvider = ({ children, config: configProvider, services: createServic
|
|
|
180
184
|
}, [
|
|
181
185
|
clientProvider,
|
|
182
186
|
configProvider,
|
|
183
|
-
|
|
187
|
+
servicesProvider
|
|
184
188
|
]);
|
|
185
189
|
if (!client || status !== import_client2.SystemStatus.ACTIVE) {
|
|
186
190
|
return /* @__PURE__ */ import_react2.default.createElement(Fallback, {
|
|
@@ -195,12 +199,30 @@ var ClientProvider = ({ children, config: configProvider, services: createServic
|
|
|
195
199
|
}
|
|
196
200
|
}, children);
|
|
197
201
|
};
|
|
202
|
+
var useClient = () => {
|
|
203
|
+
const { client } = (0, import_react5.useContext)(ClientContext) ?? (0, import_debug.raise)(new Error("Missing ClientContext."));
|
|
204
|
+
return client;
|
|
205
|
+
};
|
|
198
206
|
var useClientServices = () => {
|
|
199
|
-
const { services } = (0,
|
|
207
|
+
const { services } = (0, import_react6.useContext)(ClientContext) ?? (0, import_debug2.raise)(new Error("Missing ClientContext."));
|
|
200
208
|
return services;
|
|
201
209
|
};
|
|
210
|
+
var useClientStatus = (client) => {
|
|
211
|
+
const [status, setStatus] = (0, import_react7.useState)();
|
|
212
|
+
(0, import_react7.useEffect)(() => {
|
|
213
|
+
if (!client) {
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
const subscription = client.status.subscribe((status2) => setStatus(status2));
|
|
217
|
+
return () => subscription.unsubscribe();
|
|
218
|
+
}, [
|
|
219
|
+
client,
|
|
220
|
+
setStatus
|
|
221
|
+
]);
|
|
222
|
+
return status;
|
|
223
|
+
};
|
|
202
224
|
var useConfig = () => {
|
|
203
|
-
const { client } = (0,
|
|
225
|
+
const { client } = (0, import_react8.useContext)(ClientContext) ?? (0, import_debug3.raise)(new Error("Missing ClientContext."));
|
|
204
226
|
return client.config;
|
|
205
227
|
};
|
|
206
228
|
var useShell = () => {
|
|
@@ -209,14 +231,14 @@ var useShell = () => {
|
|
|
209
231
|
};
|
|
210
232
|
var useShellDisplay = () => {
|
|
211
233
|
const client = useClient();
|
|
212
|
-
const [display, setDisplay] = (0,
|
|
213
|
-
(0,
|
|
234
|
+
const [display, setDisplay] = (0, import_react9.useState)(client.shell.display);
|
|
235
|
+
(0, import_react9.useEffect)(() => client.shell.onDisplayChange(setDisplay), [
|
|
214
236
|
client
|
|
215
237
|
]);
|
|
216
238
|
return display;
|
|
217
239
|
};
|
|
218
240
|
var useStatus = () => {
|
|
219
|
-
const { status } = (0,
|
|
241
|
+
const { status } = (0, import_react10.useContext)(ClientContext) ?? (0, import_debug4.raise)(new Error("Missing ClientContext."));
|
|
220
242
|
return status;
|
|
221
243
|
};
|
|
222
244
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/sdk/react-client/src/client/AgentHostingProvider.tsx";
|
|
@@ -236,7 +258,7 @@ var makeClient = ({ config, halo }) => {
|
|
|
236
258
|
if (!agentHostingConfig) {
|
|
237
259
|
(0, import_log.log)("no agent hosting configured", void 0, {
|
|
238
260
|
F: __dxlog_file2,
|
|
239
|
-
L:
|
|
261
|
+
L: 39,
|
|
240
262
|
S: void 0,
|
|
241
263
|
C: (f, a) => f(...a)
|
|
242
264
|
});
|
|
@@ -247,7 +269,7 @@ var makeClient = ({ config, halo }) => {
|
|
|
247
269
|
case "LOCAL_TESTING": {
|
|
248
270
|
(0, import_log.log)("using FakeAgentHostingProvider", void 0, {
|
|
249
271
|
F: __dxlog_file2,
|
|
250
|
-
L:
|
|
272
|
+
L: 47,
|
|
251
273
|
S: void 0,
|
|
252
274
|
C: (f, a) => f(...a)
|
|
253
275
|
});
|
|
@@ -264,7 +286,7 @@ var makeClient = ({ config, halo }) => {
|
|
|
264
286
|
default: {
|
|
265
287
|
import_log.log.error("Unknown agent hosting provider type: " + agentHostingConfig.type, void 0, {
|
|
266
288
|
F: __dxlog_file2,
|
|
267
|
-
L:
|
|
289
|
+
L: 62,
|
|
268
290
|
S: void 0,
|
|
269
291
|
C: (f, a) => f(...a)
|
|
270
292
|
});
|
|
@@ -281,9 +303,10 @@ var makeClient = ({ config, halo }) => {
|
|
|
281
303
|
useAgentHostingClient,
|
|
282
304
|
useClient,
|
|
283
305
|
useClientServices,
|
|
306
|
+
useClientStatus,
|
|
284
307
|
useConfig,
|
|
285
308
|
useShell,
|
|
286
309
|
useShellDisplay,
|
|
287
310
|
useStatus
|
|
288
311
|
});
|
|
289
|
-
//# sourceMappingURL=chunk-
|
|
312
|
+
//# sourceMappingURL=chunk-D7WQQFA3.cjs.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, useRef, 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 useRef(() => {\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": ";;;;;;;;;;;;;;;;;;;;;;;;;;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;MACT;IACF;IAEA,SAAS;AACP5D,iBAAAA,IAAIoB,MAAM,0CAA0C4C,mBAAmBC,MAAI,QAAA;;;;;;AAC3E,aAAO;IACT;EACF;AACF;",
|
|
6
|
+
"names": ["import_react", "import_client", "import_log", "import_debug", "ClientContext", "createContext", "undefined", "BANNER", "client", "commitHash", "config", "get", "hash", "version", "bannerPrinted", "printBanner", "console", "log", "ClientProvider", "children", "configProvider", "clientProvider", "services", "servicesProvider", "types", "status", "controlledStatus", "fallback", "Fallback", "registerSignalFactory", "_registerSignalFactory", "onInitialized", "options", "useRef", "setClient", "useState", "Client", "error", "setError", "setStatus", "useControlledValue", "useEffect", "subscription", "subscribe", "unsubscribe", "done", "initialize", "catch", "addTypes", "SystemStatus", "ACTIVE", "t", "setTimeout", "getAsyncProviderValue", "clearTimeout", "destroy", "err", "React", "Provider", "value", "useClient", "useContext", "raise", "Error", "useClientServices", "useClientStatus", "useConfig", "useShell", "shell", "useShellDisplay", "display", "setDisplay", "onDisplayChange", "useStatus", "AgentHostingContext", "AgentHostingProvider", "props", "agentHostingProviderClient", "makeClient", "useAgentHostingClient", "halo", "agentHostingConfig", "type", "FakeAgentHostingProvider", "AgentManagerClient", "init"]
|
|
7
|
+
}
|
|
@@ -23,36 +23,24 @@ __export(devtools_exports, {
|
|
|
23
23
|
useStream: () => useStream
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(devtools_exports);
|
|
26
|
-
var
|
|
26
|
+
var import_chunk_D7WQQFA3 = require("../chunk-D7WQQFA3.cjs");
|
|
27
27
|
__reExport(devtools_exports, require("@dxos/client/devtools"), module.exports);
|
|
28
|
-
var import_react = require("react");
|
|
29
28
|
var import_debug = require("@dxos/debug");
|
|
30
|
-
var
|
|
31
|
-
var import_react2 = require("react");
|
|
29
|
+
var import_react = require("react");
|
|
32
30
|
var import_log = require("@dxos/log");
|
|
33
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/react-client/src/devtools/useDevtools.ts";
|
|
34
31
|
var useDevtools = () => {
|
|
35
|
-
const
|
|
36
|
-
(0,
|
|
37
|
-
F: __dxlog_file,
|
|
38
|
-
L: 15,
|
|
39
|
-
S: void 0,
|
|
40
|
-
A: [
|
|
41
|
-
"services",
|
|
42
|
-
""
|
|
43
|
-
]
|
|
44
|
-
});
|
|
45
|
-
return services.DevtoolsHost;
|
|
32
|
+
const client = (0, import_chunk_D7WQQFA3.useClient)();
|
|
33
|
+
return client.services.services.DevtoolsHost ?? (0, import_debug.raise)(new Error("DevtoolsHost not available."));
|
|
46
34
|
};
|
|
47
|
-
var
|
|
35
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/react-client/src/devtools/useStream.ts";
|
|
48
36
|
var useStream = (streamFactory, defaultValue, deps = []) => {
|
|
49
|
-
const [value, setValue] = (0,
|
|
50
|
-
(0,
|
|
37
|
+
const [value, setValue] = (0, import_react.useState)(defaultValue);
|
|
38
|
+
(0, import_react.useEffect)(() => {
|
|
51
39
|
const stream = streamFactory();
|
|
52
40
|
stream.subscribe((response) => setValue(response), (err) => {
|
|
53
41
|
if (err) {
|
|
54
42
|
import_log.log.catch(err, void 0, {
|
|
55
|
-
F:
|
|
43
|
+
F: __dxlog_file,
|
|
56
44
|
L: 21,
|
|
57
45
|
S: void 0,
|
|
58
46
|
C: (f, a) => f(...a)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/devtools/index.ts", "../../../../src/devtools/useDevtools.ts", "../../../../src/devtools/useStream.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport * from '@dxos/client/devtools';\n\nexport * from './useDevtools';\nexport * from './useStream';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,6BAAc;
|
|
6
|
-
"names": ["
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2023 DXOS.org\n//\n\nexport * from '@dxos/client/devtools';\n\nexport * from './useDevtools';\nexport * from './useStream';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type DevtoolsHost } from '@dxos/client/devtools';\nimport { raise } from '@dxos/debug';\n\nimport { useClient } from '../client';\n\nexport const useDevtools = (): DevtoolsHost => {\n const client = useClient();\n return client.services.services.DevtoolsHost ?? raise(new Error('DevtoolsHost not available.'));\n};\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { type DependencyList, useState, useEffect } from 'react';\n\nimport { type Stream } from '@dxos/codec-protobuf';\nimport { log } from '@dxos/log';\n\n/**\n * Subscribe to service API streams.\n */\nexport const useStream = <T>(streamFactory: () => Stream<T>, defaultValue: T, deps: DependencyList = []): T => {\n const [value, setValue] = useState<T | undefined>(defaultValue);\n useEffect(() => {\n const stream = streamFactory();\n stream.subscribe(\n (response: T) => setValue(response),\n (err) => {\n if (err) {\n log.catch(err);\n }\n },\n );\n\n return () => {\n void stream.close();\n };\n }, deps);\n\n return value ?? defaultValue;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,6BAAc;ACCd,mBAAsB;ACDtB,mBAAyD;AAGzD,iBAAoB;ADEb,IAAMA,cAAc,MAAA;AACzB,QAAMC,aAASC,iCAAAA;AACf,SAAOD,OAAOE,SAASA,SAASC,oBAAgBC,oBAAM,IAAIC,MAAM,6BAAA,CAAA;AAClE;;ACAO,IAAMC,YAAY,CAAIC,eAAgCC,cAAiBC,OAAuB,CAAA,MAAE;AACrG,QAAM,CAACC,OAAOC,QAAAA,QAAYC,uBAAwBJ,YAAAA;AAClDK,8BAAU,MAAA;AACR,UAAMC,SAASP,cAAAA;AACfO,WAAOC,UACL,CAACC,aAAgBL,SAASK,QAAAA,GAC1B,CAACC,QAAAA;AACC,UAAIA,KAAK;AACPC,uBAAIC,MAAMF,KAAAA,QAAAA;;;;;;MACZ;IACF,CAAA;AAGF,WAAO,MAAA;AACL,WAAKH,OAAOM,MAAK;IACnB;EACF,GAAGX,IAAAA;AAEH,SAAOC,SAASF;AAClB;",
|
|
6
|
+
"names": ["useDevtools", "client", "useClient", "services", "DevtoolsHost", "raise", "Error", "useStream", "streamFactory", "defaultValue", "deps", "value", "setValue", "useState", "useEffect", "stream", "subscribe", "response", "err", "log", "catch", "close"]
|
|
7
7
|
}
|
|
@@ -29,24 +29,24 @@ __export(echo_exports, {
|
|
|
29
29
|
});
|
|
30
30
|
module.exports = __toCommonJS(echo_exports);
|
|
31
31
|
var import_chunk_FYOAVV65 = require("../chunk-FYOAVV65.cjs");
|
|
32
|
-
var
|
|
32
|
+
var import_chunk_D7WQQFA3 = require("../chunk-D7WQQFA3.cjs");
|
|
33
33
|
__reExport(echo_exports, require("@dxos/client/echo"), module.exports);
|
|
34
34
|
var import_async = require("@dxos/async");
|
|
35
35
|
var import_echo = require("@dxos/client/echo");
|
|
36
|
-
var
|
|
36
|
+
var import_react_hooks = require("@dxos/react-hooks");
|
|
37
37
|
var import_react = require("react");
|
|
38
38
|
var import_echo2 = require("@dxos/client/echo");
|
|
39
|
-
var
|
|
39
|
+
var import_react_hooks2 = require("@dxos/react-hooks");
|
|
40
40
|
var import_react2 = require("react");
|
|
41
41
|
var import_echo3 = require("@dxos/client/echo");
|
|
42
42
|
var import_react3 = require("react");
|
|
43
43
|
var import_async2 = require("@dxos/async");
|
|
44
|
-
var
|
|
44
|
+
var import_react_hooks3 = require("@dxos/react-hooks");
|
|
45
45
|
var import_react4 = require("react");
|
|
46
46
|
var import_echo4 = require("@dxos/client/echo");
|
|
47
47
|
var useSpace = (spaceKeyLike) => {
|
|
48
|
-
const client = (0,
|
|
49
|
-
const spaces = (0,
|
|
48
|
+
const client = (0, import_chunk_D7WQQFA3.useClient)();
|
|
49
|
+
const spaces = (0, import_react_hooks2.useMulticastObservable)(client.spaces);
|
|
50
50
|
const [ready, setReady] = (0, import_react.useState)(false);
|
|
51
51
|
(0, import_react.useEffect)(() => {
|
|
52
52
|
if (spaceKeyLike) {
|
|
@@ -69,8 +69,8 @@ var useSpace = (spaceKeyLike) => {
|
|
|
69
69
|
}
|
|
70
70
|
};
|
|
71
71
|
var useSpaces = ({ all = false } = {}) => {
|
|
72
|
-
const client = (0,
|
|
73
|
-
const spaces = (0,
|
|
72
|
+
const client = (0, import_chunk_D7WQQFA3.useClient)();
|
|
73
|
+
const spaces = (0, import_react_hooks2.useMulticastObservable)(client.spaces);
|
|
74
74
|
return spaces.filter((space) => all || space.state.get() === import_echo2.SpaceState.SPACE_READY);
|
|
75
75
|
};
|
|
76
76
|
var useMembers = (spaceKey) => {
|
|
@@ -78,7 +78,7 @@ var useMembers = (spaceKey) => {
|
|
|
78
78
|
all: true
|
|
79
79
|
});
|
|
80
80
|
const space = spaceKey ? spaces.find((space2) => space2.key.equals(spaceKey)) : void 0;
|
|
81
|
-
const members = (0,
|
|
81
|
+
const members = (0, import_react_hooks.useMulticastObservable)(space?.members ?? import_async.MulticastObservable.empty()) ?? [];
|
|
82
82
|
return members.filter((member) => member.role !== import_echo.HaloSpaceMember.Role.REMOVED);
|
|
83
83
|
};
|
|
84
84
|
var useQuery = (spaceOrEcho, filter, options, deps) => {
|
|
@@ -109,7 +109,7 @@ var noop = () => {
|
|
|
109
109
|
var EMPTY_ARRAY = [];
|
|
110
110
|
var useSpaceInvitations = (spaceKey) => {
|
|
111
111
|
const space = useSpace(spaceKey);
|
|
112
|
-
return (0,
|
|
112
|
+
return (0, import_react_hooks3.useMulticastObservable)(space?.invitations ?? import_async2.MulticastObservable.empty()) ?? [];
|
|
113
113
|
};
|
|
114
114
|
var useSpaceInvitation = (spaceKey, invitationId) => {
|
|
115
115
|
const invitations = useSpaceInvitations(spaceKey);
|
|
@@ -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-
|
|
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
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,yBAAc;ACAd,mBAAoC;AAEpC,kBAAkD;AAClD,yBAAuC;ACHvC,mBAAoC;AAGpC,IAAAA,eAAuC;AACvC,IAAAC,sBAAuC;ACJvC,IAAAC,gBAA8C;AAE9C,IAAAF,eAQO;ACVP,IAAAE,gBAAwB;AAExB,IAAAC,gBAAoC;AAEpC,IAAAF,sBAAuC;ACJvC,IAAAC,gBAAkC;AAElC,IAAAF,eAA4E;AHcrE,IAAMI,WAAW,CAACC,iBAAAA;AACvB,QAAMC,aAASC,iCAAAA;AACf,QAAMC,aAASC,4CAAgCH,OAAOE,MAAM;AAC5D,QAAM,CAACE,OAAOC,QAAAA,QAAYC,uBAAS,KAAA;AAEnCC,8BAAU,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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AGA,IAAMW,oBAAoB,CAAC/B,WACzBiC,OAAOC,QAAQlC,UAAU,CAAC,CAAA,EACvBmC,KAAK,EAAA,EACLC,IAAI,CAACC,MAAO,OAAOA,MAAM,cAAc,OAAOA,MAAM,WAAW,OAAOA,CAAAA;AAE3E,IAAMT,OAAO,MAAA;AAAO;AAEpB,IAAME,cAAuB,CAAA;AC7CtB,IAAMQ,sBAAsB,CAACjC,aAAAA;AAClC,QAAMf,QAAQhB,SAAS+B,QAAAA;AACvB,aAAO1B,oBAAAA,wBAAuBW,OAAOiD,eAAe/B,cAAAA,oBAAoBC,MAAK,CAAA,KAAO,CAAA;AACtF;AAEO,IAAM+B,qBAAqB,CAACnC,UAAsBoC,iBAAAA;AACvD,QAAMF,cAAcD,oBAAoBjC,QAAAA;AACxC,QAAMqC,iBAAarB,cAAAA,SACjB,MAAMkB,YAAYlD,KAAK,CAACqD,gBAAeA,YAAW9C,IAAG,EAAG6C,iBAAiBA,YAAAA,GACzE;IAACF;GAAY;AAEf,aAAOI,2CAAoBD,UAAAA;AAC7B;ACZO,IAAME,kBAAkB,CAAClB,IAAgBmB,cAAAA;AAI9C,QAAMC,kBAAcC,sBAAOrB,EAAAA;AAC3BoB,cAAYE,UAAUtB;AAEtB,QAAMuB,sBAAkBF,sBAAAA;AAExBhE,oBAAAA,WAAU,MAAA;AACRkE,oBAAgBD,cAAUE,iCAAmB,MAAA;AAC3CJ,kBAAYE,QAAO;IACrB,CAAA;AAEA,WAAO,MAAMC,gBAAgBD,SAASrB,YAAAA;EACxC,GAAG,CAAA,CAAE;AAELsB,kBAAgBD,SAASG,OAAON,SAAAA;AAChC,SAAOI,gBAAgBD;AACzB;",
|
|
6
|
-
"names": ["import_echo", "
|
|
6
|
+
"names": ["import_echo", "import_react_hooks", "import_react", "import_async", "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", "undefined", "members", "MulticastObservable", "empty", "member", "role", "HaloSpaceMember", "Role", "REMOVED", "useQuery", "spaceOrEcho", "options", "deps", "subscribe", "getObjects", "useMemo", "query", "isSpace", "db", "subscribed", "cb", "unsubscribe", "noop", "objects", "EMPTY_ARRAY", "filterToDepsArray", "useSyncExternalStore", "Object", "entries", "flat", "map", "x", "useSpaceInvitations", "invitations", "useSpaceInvitation", "invitationId", "invitation", "useInvitationStatus", "useSubscription", "selection", "callbackRef", "useRef", "current", "subscriptionRef", "createSubscription", "update"]
|
|
7
7
|
}
|
|
@@ -31,25 +31,25 @@ __export(halo_exports, {
|
|
|
31
31
|
});
|
|
32
32
|
module.exports = __toCommonJS(halo_exports);
|
|
33
33
|
var import_chunk_FYOAVV65 = require("../chunk-FYOAVV65.cjs");
|
|
34
|
-
var
|
|
34
|
+
var import_chunk_D7WQQFA3 = require("../chunk-D7WQQFA3.cjs");
|
|
35
35
|
var import_halo = require("@dxos/client/halo");
|
|
36
|
-
var
|
|
37
|
-
var
|
|
36
|
+
var import_react_hooks = require("@dxos/react-hooks");
|
|
37
|
+
var import_react_hooks2 = require("@dxos/react-hooks");
|
|
38
38
|
var import_react = require("react");
|
|
39
|
-
var
|
|
40
|
-
var
|
|
39
|
+
var import_react_hooks3 = require("@dxos/react-hooks");
|
|
40
|
+
var import_react_hooks4 = require("@dxos/react-hooks");
|
|
41
41
|
var import_react2 = require("react");
|
|
42
42
|
var useContacts = () => {
|
|
43
|
-
const client = (0,
|
|
44
|
-
return (0,
|
|
43
|
+
const client = (0, import_chunk_D7WQQFA3.useClient)();
|
|
44
|
+
return (0, import_react_hooks.useMulticastObservable)(client.halo.contacts);
|
|
45
45
|
};
|
|
46
46
|
var useDevices = () => {
|
|
47
|
-
const client = (0,
|
|
48
|
-
return (0,
|
|
47
|
+
const client = (0, import_chunk_D7WQQFA3.useClient)();
|
|
48
|
+
return (0, import_react_hooks2.useMulticastObservable)(client.halo.devices);
|
|
49
49
|
};
|
|
50
50
|
var useHaloInvitations = () => {
|
|
51
|
-
const client = (0,
|
|
52
|
-
return (0,
|
|
51
|
+
const client = (0, import_chunk_D7WQQFA3.useClient)();
|
|
52
|
+
return (0, import_react_hooks3.useMulticastObservable)(client.halo.invitations);
|
|
53
53
|
};
|
|
54
54
|
var useHaloInvitation = (invitationId) => {
|
|
55
55
|
const invitations = useHaloInvitations();
|
|
@@ -59,8 +59,8 @@ var useHaloInvitation = (invitationId) => {
|
|
|
59
59
|
return (0, import_chunk_FYOAVV65.useInvitationStatus)(invitation);
|
|
60
60
|
};
|
|
61
61
|
var useIdentity = () => {
|
|
62
|
-
const client = (0,
|
|
63
|
-
return (0,
|
|
62
|
+
const client = (0, import_chunk_D7WQQFA3.useClient)();
|
|
63
|
+
return (0, import_react_hooks4.useMulticastObservable)(client.halo.identity);
|
|
64
64
|
};
|
|
65
65
|
var KeyStore = class {
|
|
66
66
|
constructor(_defaultKeys = []) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/halo/index.ts", "../../../../src/halo/useContacts.ts", "../../../../src/halo/useDevices.ts", "../../../../src/halo/useHaloInvitations.ts", "../../../../src/halo/useIdentity.ts", "../../../../src/halo/useKeyStore.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\n// NOTE: Export * fails here.\nexport { type Contact, type Identity, type Halo, Device, DeviceKind, DeviceType } from '@dxos/client/halo';\n\nexport * from './useContacts';\nexport * from './useDevices';\nexport * from './useHaloInvitations';\nexport * from './useIdentity';\nexport * from './useKeyStore';\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport type { Contact } from '@dxos/client/halo';\nimport { useMulticastObservable } from '@dxos/react-
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2022 DXOS.org\n//\n\n// NOTE: Export * fails here.\nexport { type Contact, type Identity, type Halo, Device, DeviceKind, DeviceType } from '@dxos/client/halo';\n\nexport * from './useContacts';\nexport * from './useDevices';\nexport * from './useHaloInvitations';\nexport * from './useIdentity';\nexport * from './useKeyStore';\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport type { Contact } from '@dxos/client/halo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\n/**\n * Returns all known Contacts across all Spaces.\n * Contacts are known members of a common Space.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useContacts = (): Contact[] => {\n const client = useClient();\n return useMulticastObservable(client.halo.contacts);\n};\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport type { Device } from '@dxos/client/halo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\nexport const useDevices = (): Device[] => {\n const client = useClient();\n return useMulticastObservable(client.halo.devices);\n};\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useMemo } from 'react';\n\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\nimport { useInvitationStatus, type CancellableInvitationObservable } from '../invitations';\n\nexport const useHaloInvitations = (): CancellableInvitationObservable[] => {\n const client = useClient();\n return useMulticastObservable(client.halo.invitations);\n};\n\nexport const useHaloInvitation = (invitationId?: string) => {\n const invitations = useHaloInvitations();\n const invitation = useMemo(\n () => invitations.find((invitation) => invitation.get().invitationId === invitationId),\n [invitations],\n );\n return useInvitationStatus(invitation);\n};\n", "//\n// Copyright 2020 DXOS.org\n//\n\nimport { type Identity } from '@dxos/client/halo';\nimport { useMulticastObservable } from '@dxos/react-hooks';\n\nimport { useClient } from '../client';\n\n/**\n * Hook returning DXOS identity object.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useIdentity = (): Identity | null => {\n const client = useClient();\n return useMulticastObservable(client.halo.identity);\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { useMemo, useReducer } from 'react';\n\n// TODO(burdon): Move to settings plugin.\nexport class KeyStore {\n private _keyMap = new Map<string, string>();\n\n constructor(private readonly _defaultKeys: string[] = []) {}\n\n get map() {\n return this._keyMap;\n }\n\n // TODO(burdon): Create subkeys.\n initialize() {\n this._defaultKeys.forEach((key) => {\n const value = localStorage.getItem(key);\n this.setKey(key, value ?? '');\n });\n\n return this;\n }\n\n getKey(key: string) {\n localStorage.getItem(key);\n }\n\n setKey(key: string, value: string) {\n localStorage.setItem(key, '');\n this._keyMap.set(key, value);\n }\n}\n\n/**\n * Settings store.\n * @deprecated Replace with HALO key store when available.\n */\nexport const useKeyStore = (\n defaultKeys: string[] = [],\n): [Map<string, string>, (key: string, value: string) => void] => {\n const [, forceUpdate] = useReducer((x) => x + 1, 0);\n const store = useMemo(() => new KeyStore(defaultKeys).initialize(), [defaultKeys]);\n const setKey = (key: string, value: string) => {\n store.setKey(key, value);\n forceUpdate();\n };\n\n return [store.map, setKey];\n};\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,kBAAuF;ACAvF,yBAAuC;ACAvC,IAAAA,sBAAuC;ACDvC,mBAAwB;AAExB,IAAAA,sBAAuC;ACDvC,IAAAA,sBAAuC;ACDvC,IAAAC,gBAAoC;AJU7B,IAAMC,cAAc,MAAA;AACzB,QAAMC,aAASC,iCAAAA;AACf,aAAOC,2CAAuBF,OAAOG,KAAKC,QAAQ;AACpD;ACRO,IAAMC,aAAa,MAAA;AACxB,QAAML,aAASC,iCAAAA;AACf,aAAOC,oBAAAA,wBAAuBF,OAAOG,KAAKG,OAAO;AACnD;ACDO,IAAMC,qBAAqB,MAAA;AAChC,QAAMP,aAASC,iCAAAA;AACf,aAAOC,oBAAAA,wBAAuBF,OAAOG,KAAKK,WAAW;AACvD;AAEO,IAAMC,oBAAoB,CAACC,iBAAAA;AAChC,QAAMF,cAAcD,mBAAAA;AACpB,QAAMI,iBAAaC,sBACjB,MAAMJ,YAAYK,KAAK,CAACF,gBAAeA,YAAWG,IAAG,EAAGJ,iBAAiBA,YAAAA,GACzE;IAACF;GAAY;AAEf,aAAOO,2CAAoBJ,UAAAA;AAC7B;ACVO,IAAMK,cAAc,MAAA;AACzB,QAAMhB,aAASC,iCAAAA;AACf,aAAOC,oBAAAA,wBAAuBF,OAAOG,KAAKc,QAAQ;AACpD;ACTO,IAAMC,WAAN,MAAMA;EAGXC,YAA6BC,eAAyB,CAAA,GAAI;SAA7BA,eAAAA;SAFrBC,UAAU,oBAAIC,IAAAA;EAEqC;EAE3D,IAAIC,MAAM;AACR,WAAO,KAAKF;EACd;;EAGAG,aAAa;AACX,SAAKJ,aAAaK,QAAQ,CAACC,QAAAA;AACzB,YAAMC,QAAQC,aAAaC,QAAQH,GAAAA;AACnC,WAAKI,OAAOJ,KAAKC,SAAS,EAAA;IAC5B,CAAA;AAEA,WAAO;EACT;EAEAI,OAAOL,KAAa;AAClBE,iBAAaC,QAAQH,GAAAA;EACvB;EAEAI,OAAOJ,KAAaC,OAAe;AACjCC,iBAAaI,QAAQN,KAAK,EAAA;AAC1B,SAAKL,QAAQY,IAAIP,KAAKC,KAAAA;EACxB;AACF;AAMO,IAAMO,cAAc,CACzBC,cAAwB,CAAA,MAAE;AAE1B,QAAM,CAAA,EAAGC,WAAAA,QAAeC,0BAAW,CAACC,MAAMA,IAAI,GAAG,CAAA;AACjD,QAAMC,YAAQ3B,cAAAA,SAAQ,MAAM,IAAIM,SAASiB,WAAAA,EAAaX,WAAU,GAAI;IAACW;GAAY;AACjF,QAAML,SAAS,CAACJ,KAAaC,UAAAA;AAC3BY,UAAMT,OAAOJ,KAAKC,KAAAA;AAClBS,gBAAAA;EACF;AAEA,SAAO;IAACG,MAAMhB;IAAKO;;AACrB;",
|
|
6
|
-
"names": ["
|
|
6
|
+
"names": ["import_react_hooks", "import_react", "useContacts", "client", "useClient", "useMulticastObservable", "halo", "contacts", "useDevices", "devices", "useHaloInvitations", "invitations", "useHaloInvitation", "invitationId", "invitation", "useMemo", "find", "get", "useInvitationStatus", "useIdentity", "identity", "KeyStore", "constructor", "_defaultKeys", "_keyMap", "Map", "map", "initialize", "forEach", "key", "value", "localStorage", "getItem", "setKey", "getKey", "setItem", "set", "useKeyStore", "defaultKeys", "forceUpdate", "useReducer", "x", "store"]
|
|
7
7
|
}
|
package/dist/lib/node/index.cjs
CHANGED
|
@@ -19,23 +19,24 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
|
|
|
19
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
20
|
var node_exports = {};
|
|
21
21
|
__export(node_exports, {
|
|
22
|
-
AgentHostingContext: () =>
|
|
23
|
-
AgentHostingProvider: () =>
|
|
24
|
-
ClientContext: () =>
|
|
25
|
-
ClientProvider: () =>
|
|
26
|
-
useAgentHostingClient: () =>
|
|
27
|
-
useClient: () =>
|
|
28
|
-
useClientServices: () =>
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
22
|
+
AgentHostingContext: () => import_chunk_D7WQQFA3.AgentHostingContext,
|
|
23
|
+
AgentHostingProvider: () => import_chunk_D7WQQFA3.AgentHostingProvider,
|
|
24
|
+
ClientContext: () => import_chunk_D7WQQFA3.ClientContext,
|
|
25
|
+
ClientProvider: () => import_chunk_D7WQQFA3.ClientProvider,
|
|
26
|
+
useAgentHostingClient: () => import_chunk_D7WQQFA3.useAgentHostingClient,
|
|
27
|
+
useClient: () => import_chunk_D7WQQFA3.useClient,
|
|
28
|
+
useClientServices: () => import_chunk_D7WQQFA3.useClientServices,
|
|
29
|
+
useClientStatus: () => import_chunk_D7WQQFA3.useClientStatus,
|
|
30
|
+
useConfig: () => import_chunk_D7WQQFA3.useConfig,
|
|
31
|
+
useMulticastObservable: () => import_react_hooks.useMulticastObservable,
|
|
32
|
+
useShell: () => import_chunk_D7WQQFA3.useShell,
|
|
33
|
+
useShellDisplay: () => import_chunk_D7WQQFA3.useShellDisplay,
|
|
34
|
+
useStatus: () => import_chunk_D7WQQFA3.useStatus
|
|
34
35
|
});
|
|
35
36
|
module.exports = __toCommonJS(node_exports);
|
|
36
|
-
var
|
|
37
|
+
var import_chunk_D7WQQFA3 = require("./chunk-D7WQQFA3.cjs");
|
|
37
38
|
__reExport(node_exports, require("@dxos/client"), module.exports);
|
|
38
|
-
var
|
|
39
|
+
var import_react_hooks = require("@dxos/react-hooks");
|
|
39
40
|
// Annotate the CommonJS export names for ESM import in node:
|
|
40
41
|
0 && (module.exports = {
|
|
41
42
|
AgentHostingContext,
|
|
@@ -45,6 +46,7 @@ var import_react_async = require("@dxos/react-async");
|
|
|
45
46
|
useAgentHostingClient,
|
|
46
47
|
useClient,
|
|
47
48
|
useClientServices,
|
|
49
|
+
useClientStatus,
|
|
48
50
|
useConfig,
|
|
49
51
|
useMulticastObservable,
|
|
50
52
|
useShell,
|