@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useClientStatus.d.ts","sourceRoot":"","sources":["../../../../src/client/useClientStatus.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,MAAM,EAAE,KAAK,YAAY,EAAE,MAAM,cAAc,CAAC;AAE9D,eAAO,MAAM,eAAe,WAAY,MAAM,oCAY7C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDevtools.d.ts","sourceRoot":"","sources":["../../../../src/devtools/useDevtools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useDevtools.d.ts","sourceRoot":"","sources":["../../../../src/devtools/useDevtools.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAK1D,eAAO,MAAM,WAAW,QAAO,YAG9B,CAAC"}
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import React, { type FC } from 'react';
|
|
2
|
-
import { Client } from '@dxos/client';
|
|
2
|
+
import { Client, type PublicKey } from '@dxos/client';
|
|
3
3
|
import { type Space } from '@dxos/client/echo';
|
|
4
4
|
import { type S } from '@dxos/echo-schema';
|
|
5
5
|
import { type MaybePromise } from '@dxos/util';
|
|
6
|
-
export type
|
|
6
|
+
export type ClientRepeatedComponentProps = {
|
|
7
7
|
id: number;
|
|
8
8
|
count: number;
|
|
9
|
+
spaceKey?: PublicKey;
|
|
9
10
|
};
|
|
10
|
-
export type ClientRepeaterProps<P extends
|
|
11
|
-
component: FC<any>;
|
|
11
|
+
export type ClientRepeaterProps<P extends ClientRepeatedComponentProps> = {
|
|
12
12
|
className?: string;
|
|
13
|
+
component: FC<ClientRepeatedComponentProps>;
|
|
13
14
|
controls?: FC<{
|
|
14
15
|
clients: Client[];
|
|
15
16
|
}>;
|
|
@@ -26,5 +27,5 @@ export type ClientRepeaterProps<P extends RepeatedComponentProps> = {
|
|
|
26
27
|
* Utility component for Storybook stories which sets up clients for n peers.
|
|
27
28
|
* The `Component` property is rendered n times, once for each peer.
|
|
28
29
|
*/
|
|
29
|
-
export declare const ClientRepeater: <P extends
|
|
30
|
+
export declare const ClientRepeater: <P extends ClientRepeatedComponentProps>(props: ClientRepeaterProps<P>) => React.JSX.Element | null;
|
|
30
31
|
//# sourceMappingURL=ClientRepeater.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientRepeater.d.ts","sourceRoot":"","sources":["../../../../src/testing/ClientRepeater.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAY,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"ClientRepeater.d.ts","sourceRoot":"","sources":["../../../../src/testing/ClientRepeater.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAY,KAAK,EAAE,EAAqB,MAAM,OAAO,CAAC;AAEpE,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,mBAAmB,CAAC;AAG3C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAI/C,MAAM,MAAM,4BAA4B,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAE/F,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,4BAA4B,IAAI;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,EAAE,CAAC,4BAA4B,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,EAAE,CAAC;QAAE,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,CAAC;IACrC,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,KAAK,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;IACxB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;IACrD,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAAC,CAAC;CAChC,CAAC;AAEF;;;GAGG;AAMH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,4BAA4B,SAAS,mBAAmB,CAAC,CAAC,CAAC,6BA2DnG,CAAC"}
|
|
@@ -5,10 +5,10 @@ declare const _default: {
|
|
|
5
5
|
decorators: import("@storybook/react/*").Decorator[];
|
|
6
6
|
};
|
|
7
7
|
export default _default;
|
|
8
|
-
export declare const
|
|
8
|
+
export declare const Default: {
|
|
9
9
|
render: () => React.JSX.Element;
|
|
10
10
|
};
|
|
11
|
-
export declare const
|
|
11
|
+
export declare const Space: {
|
|
12
12
|
render: () => React.JSX.Element;
|
|
13
13
|
};
|
|
14
|
-
//# sourceMappingURL=
|
|
14
|
+
//# sourceMappingURL=ClientRepeater.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientRepeater.stories.d.ts","sourceRoot":"","sources":["../../../../src/testing/ClientRepeater.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,KAAK,MAAM,OAAO,CAAC;;;;;AAU1B,wBAGE;AAgCF,eAAO,MAAM,OAAO;;CAEnB,CAAC;AAEF,eAAO,MAAM,KAAK;;CAEjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,sBAAsB,CAAC;AAErC,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,sBAAsB,CAAC;AAErC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Client } from '@dxos/client';
|
|
3
|
+
import { type Space } from '@dxos/client/echo';
|
|
4
|
+
export declare const createClient: ({ createIdentity, createSpace, }?: {
|
|
5
|
+
createIdentity?: boolean;
|
|
6
|
+
createSpace?: boolean;
|
|
7
|
+
}) => Promise<{
|
|
8
|
+
client: Client;
|
|
9
|
+
space: Space | undefined;
|
|
10
|
+
}>;
|
|
11
|
+
export declare const createContextProvider: (client: Client) => Promise<({ children }: any) => React.JSX.Element>;
|
|
12
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../../../src/testing/util.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,MAAM,EAAY,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAI/C,eAAO,MAAM,YAAY,sCAGtB;IAAE,cAAc,CAAC,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE;;;EAcrD,CAAC;AAGF,eAAO,MAAM,qBAAqB,WAAkB,MAAM,4BAClC,GAAG,uBAC1B,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { type Decorator } from '@storybook/react';
|
|
2
|
+
import { type Client } from '@dxos/client';
|
|
3
|
+
import { type Space } from '@dxos/client/echo';
|
|
4
|
+
import { type MaybePromise } from '@dxos/util';
|
|
5
|
+
import { type ClientProviderProps } from '../client';
|
|
6
|
+
type InitializeProps = {
|
|
7
|
+
createIdentity?: boolean;
|
|
8
|
+
createSpace?: boolean;
|
|
9
|
+
onSpaceCreated?: (client: Client, space: Space) => MaybePromise<void>;
|
|
10
|
+
};
|
|
11
|
+
export type WithClientProviderProps = InitializeProps & ClientProviderProps;
|
|
12
|
+
/**
|
|
13
|
+
* Decorator that provides the client context.
|
|
14
|
+
*/
|
|
15
|
+
export declare const withClientProvider: ({ createIdentity, createSpace, onSpaceCreated, onInitialized, ...props }?: WithClientProviderProps) => Decorator;
|
|
16
|
+
export type WithMultiClientProviderProps = InitializeProps & ClientProviderProps & {
|
|
17
|
+
numClients?: number;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Decorator that creates a scaffold for multiple clients.
|
|
21
|
+
* Orchestrates invitations between a randomly selected host and the remaining clients.
|
|
22
|
+
* NOTE: Should come before withLayout.
|
|
23
|
+
*/
|
|
24
|
+
export declare const withMultiClientProvider: ({ numClients, createIdentity, createSpace, onSpaceCreated, onInitialized, ...props }: WithMultiClientProviderProps) => Decorator;
|
|
25
|
+
export {};
|
|
26
|
+
//# sourceMappingURL=withClientProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withClientProvider.d.ts","sourceRoot":"","sources":["../../../../src/testing/withClientProvider.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAKlD,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,OAAO,EAAkB,KAAK,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAErE,KAAK,eAAe,GAAG;IACrB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;CACvE,CAAC;AA4BF,MAAM,MAAM,uBAAuB,GAAG,eAAe,GAAG,mBAAmB,CAAC;AAE5E;;GAEG;AACH,eAAO,MAAM,kBAAkB,8EAM5B,uBAAuB,KAAQ,SAYjC,CAAC;AAKF,MAAM,MAAM,4BAA4B,GAAG,eAAe,GAAG,mBAAmB,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAE3G;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,yFAOjC,4BAA4B,KAAG,SAuCjC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import '@dxos-theme';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
declare const _default: {
|
|
4
|
+
title: string;
|
|
5
|
+
component: () => React.JSX.Element | null;
|
|
6
|
+
decorators: import("@storybook/react/*").Decorator[];
|
|
7
|
+
};
|
|
8
|
+
export default _default;
|
|
9
|
+
export declare const Default: {};
|
|
10
|
+
export declare const Multiple: {
|
|
11
|
+
decorators: import("@storybook/react/*").Decorator[];
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=withClientProvider.stories.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"withClientProvider.stories.d.ts","sourceRoot":"","sources":["../../../../src/testing/withClientProvider.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,KAAK,MAAM,OAAO,CAAC;;;;;;AA+B1B,wBAIE;AAEF,eAAO,MAAM,OAAO,IAAK,CAAC;AAE1B,eAAO,MAAM,QAAQ;;CAUpB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-client",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.11-staging.66fb9aa",
|
|
4
4
|
"description": "React client API",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -91,18 +91,20 @@
|
|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
93
|
"dependencies": {
|
|
94
|
-
"
|
|
95
|
-
"@dxos/
|
|
96
|
-
"@dxos/codec-protobuf": "0.6.
|
|
97
|
-
"@dxos/
|
|
98
|
-
"@dxos/
|
|
99
|
-
"@dxos/echo-
|
|
100
|
-
"@dxos/
|
|
101
|
-
"@dxos/echo-
|
|
102
|
-
"@dxos/
|
|
103
|
-
"@dxos/
|
|
104
|
-
"@dxos/
|
|
105
|
-
"@dxos/
|
|
94
|
+
"react-error-boundary": "^4.0.13",
|
|
95
|
+
"@dxos/async": "0.6.11-staging.66fb9aa",
|
|
96
|
+
"@dxos/codec-protobuf": "0.6.11-staging.66fb9aa",
|
|
97
|
+
"@dxos/client": "0.6.11-staging.66fb9aa",
|
|
98
|
+
"@dxos/config": "0.6.11-staging.66fb9aa",
|
|
99
|
+
"@dxos/echo-schema": "0.6.11-staging.66fb9aa",
|
|
100
|
+
"@dxos/debug": "0.6.11-staging.66fb9aa",
|
|
101
|
+
"@dxos/echo-signals": "0.6.11-staging.66fb9aa",
|
|
102
|
+
"@dxos/invariant": "0.6.11-staging.66fb9aa",
|
|
103
|
+
"@dxos/log": "0.6.11-staging.66fb9aa",
|
|
104
|
+
"@dxos/node-std": "0.6.11-staging.66fb9aa",
|
|
105
|
+
"@dxos/react-hooks": "0.6.11-staging.66fb9aa",
|
|
106
|
+
"@dxos/protocols": "0.6.11-staging.66fb9aa",
|
|
107
|
+
"@dxos/util": "0.6.11-staging.66fb9aa"
|
|
106
108
|
},
|
|
107
109
|
"devDependencies": {
|
|
108
110
|
"@testing-library/dom": "^8.17.1",
|
|
@@ -112,19 +114,20 @@
|
|
|
112
114
|
"@types/react-dom": "~18.2.0",
|
|
113
115
|
"react": "~18.2.0",
|
|
114
116
|
"react-dom": "~18.2.0",
|
|
115
|
-
"@dxos/random": "0.6.
|
|
116
|
-
"@dxos/react-ui": "0.6.
|
|
117
|
-
"@dxos/
|
|
118
|
-
"@dxos/react-ui-theme": "0.6.
|
|
117
|
+
"@dxos/random": "0.6.11-staging.66fb9aa",
|
|
118
|
+
"@dxos/react-ui": "0.6.11-staging.66fb9aa",
|
|
119
|
+
"@dxos/react-ui-syntax-highlighter": "0.6.11-staging.66fb9aa",
|
|
120
|
+
"@dxos/react-ui-theme": "0.6.11-staging.66fb9aa",
|
|
121
|
+
"@dxos/storybook-utils": "0.6.11-staging.66fb9aa"
|
|
119
122
|
},
|
|
120
123
|
"peerDependencies": {
|
|
121
124
|
"react": "^18.0.0",
|
|
122
125
|
"react-dom": "^18.0.0",
|
|
123
|
-
"@dxos/react-ui
|
|
124
|
-
"@dxos/react-ui": "0.6.
|
|
126
|
+
"@dxos/react-ui": "0.6.11-staging.66fb9aa",
|
|
127
|
+
"@dxos/react-ui-theme": "0.6.11-staging.66fb9aa"
|
|
125
128
|
},
|
|
126
129
|
"optionalDependencies": {
|
|
127
|
-
"@dxos/random": "0.6.
|
|
130
|
+
"@dxos/random": "0.6.11-staging.66fb9aa"
|
|
128
131
|
},
|
|
129
132
|
"publishConfig": {
|
|
130
133
|
"access": "public"
|
|
@@ -11,15 +11,16 @@ import { log } from '@dxos/log';
|
|
|
11
11
|
|
|
12
12
|
import { useClient } from '../client';
|
|
13
13
|
|
|
14
|
-
/*
|
|
15
|
-
* Interface for invoking the agent hosting provider client.
|
|
16
|
-
* @experimental
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
14
|
export type AgentHostingProviderProps = { config: Config; halo: Halo };
|
|
20
15
|
|
|
21
16
|
export const AgentHostingContext = createContext<AgentHostingProviderClient | null>(null);
|
|
22
17
|
|
|
18
|
+
/**
|
|
19
|
+
* Experimental agent hosting provider.
|
|
20
|
+
* @param props
|
|
21
|
+
* @constructor
|
|
22
|
+
* @deprecated
|
|
23
|
+
*/
|
|
23
24
|
export const AgentHostingProvider = (props: PropsWithChildren<{}>) => {
|
|
24
25
|
const client = useClient();
|
|
25
26
|
const [agentHostingProviderClient] = useState(makeClient(client));
|
|
@@ -52,7 +53,7 @@ const makeClient = ({ config, halo }: AgentHostingProviderProps) => {
|
|
|
52
53
|
if (agentHostingProviderClient.init()) {
|
|
53
54
|
return agentHostingProviderClient;
|
|
54
55
|
} else {
|
|
55
|
-
// Not authorized or error initializing
|
|
56
|
+
// Not authorized or error initializing.
|
|
56
57
|
return null;
|
|
57
58
|
}
|
|
58
59
|
}
|
|
@@ -11,7 +11,8 @@ import { Client, Config, SystemStatus, fromHost } from '@dxos/client';
|
|
|
11
11
|
import { log } from '@dxos/log';
|
|
12
12
|
import { describe, test } from '@dxos/test';
|
|
13
13
|
|
|
14
|
-
import { ClientProvider
|
|
14
|
+
import { ClientProvider } from './ClientProvider';
|
|
15
|
+
import { useClient } from './useClient';
|
|
15
16
|
import { useIdentity } from '../halo';
|
|
16
17
|
|
|
17
18
|
log.config({ filter: 'ClientContext:debug,warn' });
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2020 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import React, { type FunctionComponent, type ReactNode, useEffect, useRef, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { Client, type ClientOptions, type ClientServicesProvider, SystemStatus } from '@dxos/client';
|
|
8
|
+
import { type Config } from '@dxos/config';
|
|
9
|
+
import { type S } from '@dxos/echo-schema';
|
|
10
|
+
import { registerSignalFactory } from '@dxos/echo-signals/react';
|
|
11
|
+
import { log } from '@dxos/log';
|
|
12
|
+
import { useControlledValue } from '@dxos/react-hooks';
|
|
13
|
+
import { getAsyncProviderValue, type MaybePromise, type Provider } from '@dxos/util';
|
|
14
|
+
|
|
15
|
+
import { ClientContext, type ClientContextProps } from './context';
|
|
16
|
+
import { printBanner } from '../banner';
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Properties for the ClientProvider.
|
|
20
|
+
*/
|
|
21
|
+
export type ClientProviderProps = Pick<ClientContextProps, 'status'> &
|
|
22
|
+
Omit<ClientOptions, 'config' | 'services'> & {
|
|
23
|
+
children?: ReactNode;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Config object or async provider.
|
|
27
|
+
*/
|
|
28
|
+
config?: Config | Provider<Promise<Config>>;
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Client object or async provider to enable to caller to do custom initialization.
|
|
32
|
+
*
|
|
33
|
+
* Most apps won't need this.
|
|
34
|
+
*/
|
|
35
|
+
// TODO(wittjosiah): Remove async and just use to keep reference to client?
|
|
36
|
+
// (Preferring `onInitialized` for custom initialization.)
|
|
37
|
+
// TODO(burdon): Use useImperativeHandle to expose client.
|
|
38
|
+
client?: Client | Provider<Promise<Client>>;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Callback to enable the caller to create a custom ClientServicesProvider.
|
|
42
|
+
*
|
|
43
|
+
* Most apps won't need this.
|
|
44
|
+
*/
|
|
45
|
+
services?: ClientServicesProvider | ((config?: Config) => MaybePromise<ClientServicesProvider>);
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* List of schema to register.
|
|
49
|
+
*/
|
|
50
|
+
types?: S.Schema<any>[];
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* ReactNode to display until the client is available.
|
|
54
|
+
*/
|
|
55
|
+
fallback?: FunctionComponent<Partial<ClientContextProps>>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Set to false to stop default signal factory from being registered.
|
|
59
|
+
*/
|
|
60
|
+
// TODO(burdon): Move to options.
|
|
61
|
+
registerSignalFactory?: boolean;
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Post initialization hook to enable to caller to do custom initialization.
|
|
65
|
+
*
|
|
66
|
+
* @param Client
|
|
67
|
+
*/
|
|
68
|
+
onInitialized?: (client: Client) => MaybePromise<void>;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Root component that provides the DXOS client instance to child components.
|
|
73
|
+
* To be used with the `useClient` hook.
|
|
74
|
+
*/
|
|
75
|
+
export const ClientProvider = ({
|
|
76
|
+
children,
|
|
77
|
+
config: configProvider,
|
|
78
|
+
client: clientProvider,
|
|
79
|
+
services: servicesProvider,
|
|
80
|
+
types,
|
|
81
|
+
status: controlledStatus,
|
|
82
|
+
fallback: Fallback = () => null,
|
|
83
|
+
registerSignalFactory: _registerSignalFactory = true,
|
|
84
|
+
onInitialized,
|
|
85
|
+
...options
|
|
86
|
+
}: ClientProviderProps) => {
|
|
87
|
+
useRef(() => {
|
|
88
|
+
// TODO(wittjosiah): Ideally this should be imported asynchronously because it is optional.
|
|
89
|
+
// Unfortunately, async import seemed to break signals React instrumentation.
|
|
90
|
+
_registerSignalFactory && registerSignalFactory();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
const [client, setClient] = useState(clientProvider instanceof Client ? clientProvider : undefined);
|
|
94
|
+
|
|
95
|
+
const [error, setError] = useState();
|
|
96
|
+
if (error) {
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Status subscription.
|
|
101
|
+
const [status, setStatus] = useControlledValue(controlledStatus);
|
|
102
|
+
useEffect(() => {
|
|
103
|
+
if (!client) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const subscription = client.status.subscribe((status) => setStatus(status));
|
|
108
|
+
return () => subscription.unsubscribe();
|
|
109
|
+
}, [client, setStatus]);
|
|
110
|
+
|
|
111
|
+
// Initialize client.
|
|
112
|
+
useEffect(() => {
|
|
113
|
+
const done = async (client: Client) => {
|
|
114
|
+
await client.initialize().catch(setError);
|
|
115
|
+
log('client ready');
|
|
116
|
+
await onInitialized?.(client);
|
|
117
|
+
log('initialization complete');
|
|
118
|
+
if (types) {
|
|
119
|
+
client.addTypes(types);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
setClient(client);
|
|
123
|
+
setStatus(client.status.get() ?? SystemStatus.ACTIVE);
|
|
124
|
+
printBanner(client);
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
const t = setTimeout(async () => {
|
|
128
|
+
if (clientProvider) {
|
|
129
|
+
// Asynchronously request client.
|
|
130
|
+
const client = await getAsyncProviderValue(clientProvider);
|
|
131
|
+
await done(client);
|
|
132
|
+
} else {
|
|
133
|
+
// Asynchronously construct client (config may be undefined).
|
|
134
|
+
const config = await getAsyncProviderValue(configProvider);
|
|
135
|
+
log('resolved config', { config });
|
|
136
|
+
const services = await getAsyncProviderValue(servicesProvider, config);
|
|
137
|
+
log('created services', { services });
|
|
138
|
+
const client = new Client({ config, services, ...options });
|
|
139
|
+
log('created client');
|
|
140
|
+
await done(client);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return () => {
|
|
145
|
+
log('clean up');
|
|
146
|
+
clearTimeout(t);
|
|
147
|
+
void client?.destroy().catch((err) => log.catch(err));
|
|
148
|
+
};
|
|
149
|
+
}, [clientProvider, configProvider, servicesProvider]);
|
|
150
|
+
|
|
151
|
+
if (!client || status !== SystemStatus.ACTIVE) {
|
|
152
|
+
return <Fallback client={client} status={status} />;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
return <ClientContext.Provider value={{ client, status }}>{children}</ClientContext.Provider>;
|
|
156
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2020 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Context, createContext } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type Client, type ClientServices, type SystemStatus } from '@dxos/client';
|
|
8
|
+
|
|
9
|
+
export type ClientContextProps = {
|
|
10
|
+
client: Client;
|
|
11
|
+
|
|
12
|
+
// Optionally expose services (e.g., for devtools).
|
|
13
|
+
services?: ClientServices;
|
|
14
|
+
|
|
15
|
+
status?: SystemStatus | null;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export const ClientContext: Context<ClientContextProps | undefined> = createContext<ClientContextProps | undefined>(
|
|
19
|
+
undefined,
|
|
20
|
+
);
|
package/src/client/index.ts
CHANGED
|
@@ -3,8 +3,14 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
export * from './AgentHostingProvider';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './ClientProvider';
|
|
7
|
+
|
|
8
|
+
// TODO(burdon): Remove.
|
|
9
|
+
export * from './context';
|
|
10
|
+
|
|
11
|
+
export * from './useClient';
|
|
7
12
|
export * from './useClientServices';
|
|
13
|
+
export * from './useClientStatus';
|
|
8
14
|
export * from './useConfig';
|
|
9
15
|
export * from './useShell';
|
|
10
16
|
export * from './useStatus';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useContext } from 'react';
|
|
6
|
+
|
|
7
|
+
import { raise } from '@dxos/debug';
|
|
8
|
+
|
|
9
|
+
import { ClientContext } from '../client/context';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Hook returning instance of DXOS client.
|
|
13
|
+
* Requires ClientContext to be set via ClientProvider.
|
|
14
|
+
*/
|
|
15
|
+
export const useClient = () => {
|
|
16
|
+
const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));
|
|
17
|
+
return client;
|
|
18
|
+
};
|
|
@@ -4,10 +4,10 @@
|
|
|
4
4
|
|
|
5
5
|
import { useContext } from 'react';
|
|
6
6
|
|
|
7
|
-
import type
|
|
7
|
+
import { type ClientServices } from '@dxos/client';
|
|
8
8
|
import { raise } from '@dxos/debug';
|
|
9
9
|
|
|
10
|
-
import { ClientContext } from './
|
|
10
|
+
import { ClientContext } from './context';
|
|
11
11
|
|
|
12
12
|
export const useClientServices = (): ClientServices | undefined => {
|
|
13
13
|
const { services } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
|
|
7
|
+
import { type Client, type SystemStatus } from '@dxos/client';
|
|
8
|
+
|
|
9
|
+
export const useClientStatus = (client: Client) => {
|
|
10
|
+
const [status, setStatus] = useState<SystemStatus | null>();
|
|
11
|
+
useEffect(() => {
|
|
12
|
+
if (!client) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const subscription = client.status.subscribe((status) => setStatus(status));
|
|
17
|
+
return () => subscription.unsubscribe();
|
|
18
|
+
}, [client, setStatus]);
|
|
19
|
+
|
|
20
|
+
return status;
|
|
21
|
+
};
|
|
@@ -10,7 +10,7 @@ import { waitForCondition } from '@dxos/async';
|
|
|
10
10
|
import { Client, Config, SystemStatus, fromHost } from '@dxos/client';
|
|
11
11
|
import { describe, test } from '@dxos/test';
|
|
12
12
|
|
|
13
|
-
import { ClientProvider } from './
|
|
13
|
+
import { ClientProvider } from './ClientProvider';
|
|
14
14
|
import { useConfig } from './useConfig';
|
|
15
15
|
|
|
16
16
|
describe('Config hook', () => {
|
package/src/client/useConfig.ts
CHANGED
package/src/client/useShell.ts
CHANGED
package/src/client/useStatus.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { useContext } from 'react';
|
|
|
7
7
|
import { type SystemStatus } from '@dxos/client';
|
|
8
8
|
import { raise } from '@dxos/debug';
|
|
9
9
|
|
|
10
|
-
import { ClientContext } from './
|
|
10
|
+
import { ClientContext } from './context';
|
|
11
11
|
|
|
12
12
|
export const useStatus = (): SystemStatus | null | undefined => {
|
|
13
13
|
const { status } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));
|
|
@@ -2,16 +2,12 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { useContext } from 'react';
|
|
6
|
-
|
|
7
5
|
import { type DevtoolsHost } from '@dxos/client/devtools';
|
|
8
6
|
import { raise } from '@dxos/debug';
|
|
9
|
-
import { invariant } from '@dxos/invariant';
|
|
10
7
|
|
|
11
|
-
import {
|
|
8
|
+
import { useClient } from '../client';
|
|
12
9
|
|
|
13
10
|
export const useDevtools = (): DevtoolsHost => {
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
return services.DevtoolsHost;
|
|
11
|
+
const client = useClient();
|
|
12
|
+
return client.services.services.DevtoolsHost ?? raise(new Error('DevtoolsHost not available.'));
|
|
17
13
|
};
|
package/src/echo/useMembers.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { MulticastObservable } from '@dxos/async';
|
|
6
6
|
import { type PublicKey } from '@dxos/client';
|
|
7
7
|
import { HaloSpaceMember, type SpaceMember } from '@dxos/client/echo';
|
|
8
|
-
import { useMulticastObservable } from '@dxos/react-
|
|
8
|
+
import { useMulticastObservable } from '@dxos/react-hooks';
|
|
9
9
|
|
|
10
10
|
import { useSpaces } from './useSpaces';
|
|
11
11
|
|
|
@@ -6,7 +6,7 @@ import { useMemo } from 'react';
|
|
|
6
6
|
|
|
7
7
|
import { MulticastObservable } from '@dxos/async';
|
|
8
8
|
import { type PublicKey } from '@dxos/client';
|
|
9
|
-
import { useMulticastObservable } from '@dxos/react-
|
|
9
|
+
import { useMulticastObservable } from '@dxos/react-hooks';
|
|
10
10
|
|
|
11
11
|
import { useSpace } from './useSpaces';
|
|
12
12
|
import { type CancellableInvitationObservable, useInvitationStatus } from '../invitations';
|