@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.
Files changed (103) hide show
  1. package/dist/lib/browser/{chunk-NLQLAARM.mjs → chunk-BLQHBTRS.mjs} +67 -39
  2. package/dist/lib/browser/chunk-BLQHBTRS.mjs.map +7 -0
  3. package/dist/lib/browser/devtools/index.mjs +6 -18
  4. package/dist/lib/browser/devtools/index.mjs.map +3 -3
  5. package/dist/lib/browser/echo/index.mjs +4 -4
  6. package/dist/lib/browser/echo/index.mjs.map +1 -1
  7. package/dist/lib/browser/halo/index.mjs +5 -5
  8. package/dist/lib/browser/halo/index.mjs.map +1 -1
  9. package/dist/lib/browser/index.mjs +4 -2
  10. package/dist/lib/browser/index.mjs.map +2 -2
  11. package/dist/lib/browser/mesh/index.mjs +2 -2
  12. package/dist/lib/browser/mesh/index.mjs.map +1 -1
  13. package/dist/lib/browser/meta.json +1 -1
  14. package/dist/lib/browser/testing/index.mjs +108 -12
  15. package/dist/lib/browser/testing/index.mjs.map +4 -4
  16. package/dist/lib/node/{chunk-E3S6YHNJ.cjs → chunk-D7WQQFA3.cjs} +62 -39
  17. package/dist/lib/node/chunk-D7WQQFA3.cjs.map +7 -0
  18. package/dist/lib/node/devtools/index.cjs +8 -20
  19. package/dist/lib/node/devtools/index.cjs.map +3 -3
  20. package/dist/lib/node/echo/index.cjs +10 -10
  21. package/dist/lib/node/echo/index.cjs.map +2 -2
  22. package/dist/lib/node/halo/index.cjs +13 -13
  23. package/dist/lib/node/halo/index.cjs.map +2 -2
  24. package/dist/lib/node/index.cjs +16 -14
  25. package/dist/lib/node/index.cjs.map +2 -2
  26. package/dist/lib/node/mesh/index.cjs +4 -4
  27. package/dist/lib/node/mesh/index.cjs.map +1 -1
  28. package/dist/lib/node/meta.json +1 -1
  29. package/dist/lib/node/testing/index.cjs +106 -10
  30. package/dist/lib/node/testing/index.cjs.map +4 -4
  31. package/dist/types/src/client/AgentHostingProvider.d.ts +6 -0
  32. package/dist/types/src/client/AgentHostingProvider.d.ts.map +1 -1
  33. package/dist/types/src/client/{ClientContext.d.ts → ClientProvider.d.ts} +15 -20
  34. package/dist/types/src/client/ClientProvider.d.ts.map +1 -0
  35. package/dist/types/src/client/ClientProvider.test.d.ts +2 -0
  36. package/dist/types/src/client/ClientProvider.test.d.ts.map +1 -0
  37. package/dist/types/src/client/context.d.ts +9 -0
  38. package/dist/types/src/client/context.d.ts.map +1 -0
  39. package/dist/types/src/client/index.d.ts +4 -1
  40. package/dist/types/src/client/index.d.ts.map +1 -1
  41. package/dist/types/src/client/useClient.d.ts +6 -0
  42. package/dist/types/src/client/useClient.d.ts.map +1 -0
  43. package/dist/types/src/client/useClientServices.d.ts +1 -1
  44. package/dist/types/src/client/useClientServices.d.ts.map +1 -1
  45. package/dist/types/src/client/useClientStatus.d.ts +3 -0
  46. package/dist/types/src/client/useClientStatus.d.ts.map +1 -0
  47. package/dist/types/src/devtools/useDevtools.d.ts.map +1 -1
  48. package/dist/types/src/index.d.ts +1 -1
  49. package/dist/types/src/testing/ClientRepeater.d.ts +6 -5
  50. package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
  51. package/dist/types/src/testing/{decorators.stories.d.ts → ClientRepeater.stories.d.ts} +3 -3
  52. package/dist/types/src/testing/ClientRepeater.stories.d.ts.map +1 -0
  53. package/dist/types/src/testing/index.d.ts +1 -0
  54. package/dist/types/src/testing/index.d.ts.map +1 -1
  55. package/dist/types/src/testing/util.d.ts +12 -0
  56. package/dist/types/src/testing/util.d.ts.map +1 -0
  57. package/dist/types/src/testing/withClientProvider.d.ts +26 -0
  58. package/dist/types/src/testing/withClientProvider.d.ts.map +1 -0
  59. package/dist/types/src/testing/withClientProvider.stories.d.ts +13 -0
  60. package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -0
  61. package/package.json +23 -20
  62. package/src/client/AgentHostingProvider.tsx +7 -6
  63. package/src/client/{ClientContext.test.tsx → ClientProvider.test.tsx} +2 -1
  64. package/src/client/ClientProvider.tsx +156 -0
  65. package/src/client/context.ts +20 -0
  66. package/src/client/index.ts +7 -1
  67. package/src/client/useClient.ts +18 -0
  68. package/src/client/useClientServices.ts +2 -2
  69. package/src/client/useClientStatus.ts +21 -0
  70. package/src/client/useConfig.test.tsx +1 -1
  71. package/src/client/useConfig.ts +1 -1
  72. package/src/client/useShell.ts +1 -1
  73. package/src/client/useStatus.ts +1 -1
  74. package/src/devtools/useDevtools.ts +3 -7
  75. package/src/echo/useMembers.ts +1 -1
  76. package/src/echo/useSpaceInvitations.ts +1 -1
  77. package/src/echo/useSpaces.test.tsx +10 -34
  78. package/src/echo/useSpaces.ts +1 -1
  79. package/src/halo/useContacts.ts +1 -1
  80. package/src/halo/useDevices.test.tsx +3 -10
  81. package/src/halo/useDevices.ts +1 -1
  82. package/src/halo/useHaloInvitations.ts +1 -1
  83. package/src/halo/useIdentity.ts +1 -1
  84. package/src/index.ts +1 -1
  85. package/src/mesh/useNetworkStatus.ts +1 -1
  86. package/src/testing/ClientRepeater.stories.tsx +58 -0
  87. package/src/testing/ClientRepeater.tsx +14 -13
  88. package/src/testing/index.ts +1 -0
  89. package/src/testing/util.tsx +34 -0
  90. package/src/testing/withClientProvider.stories.tsx +56 -0
  91. package/src/testing/withClientProvider.tsx +142 -0
  92. package/tsconfig.json +9 -3
  93. package/dist/lib/browser/chunk-NLQLAARM.mjs.map +0 -7
  94. package/dist/lib/node/chunk-E3S6YHNJ.cjs.map +0 -7
  95. package/dist/types/src/client/ClientContext.d.ts.map +0 -1
  96. package/dist/types/src/client/ClientContext.stories.d.ts +0 -15
  97. package/dist/types/src/client/ClientContext.stories.d.ts.map +0 -1
  98. package/dist/types/src/client/ClientContext.test.d.ts +0 -2
  99. package/dist/types/src/client/ClientContext.test.d.ts.map +0 -1
  100. package/dist/types/src/testing/decorators.stories.d.ts.map +0 -1
  101. package/src/client/ClientContext.stories.tsx +0 -94
  102. package/src/client/ClientContext.tsx +0 -182
  103. 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":"AAMA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAM1D,eAAO,MAAM,WAAW,QAAO,YAI9B,CAAC"}
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,4 +1,4 @@
1
1
  export * from '@dxos/client';
2
- export { useMulticastObservable } from '@dxos/react-async';
2
+ export { useMulticastObservable } from '@dxos/react-hooks';
3
3
  export * from './client';
4
4
  //# sourceMappingURL=index.d.ts.map
@@ -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 RepeatedComponentProps = {
6
+ export type ClientRepeatedComponentProps = {
7
7
  id: number;
8
8
  count: number;
9
+ spaceKey?: PublicKey;
9
10
  };
10
- export type ClientRepeaterProps<P extends RepeatedComponentProps> = {
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 RepeatedComponentProps>(props: ClientRepeaterProps<P>) => React.JSX.Element | null;
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,EAAa,MAAM,OAAO,CAAC;AAE5D,OAAO,EAAE,MAAM,EAAkB,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;AAM/C,MAAM,MAAM,sBAAsB,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnE,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,sBAAsB,IAAI;IAClE,SAAS,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,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,sBAAsB,SAAS,mBAAmB,CAAC,CAAC,CAAC,6BAwD7F,CAAC"}
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 WithClient: {
8
+ export declare const Default: {
9
9
  render: () => React.JSX.Element;
10
10
  };
11
- export declare const WithClientSpace: {
11
+ export declare const Space: {
12
12
  render: () => React.JSX.Element;
13
13
  };
14
- //# sourceMappingURL=decorators.stories.d.ts.map
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,3 +1,4 @@
1
1
  export * from '@dxos/client/testing';
2
2
  export * from './ClientRepeater';
3
+ export * from './withClientProvider';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -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.10",
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
- "@dxos/async": "0.6.10",
95
- "@dxos/client": "0.6.10",
96
- "@dxos/codec-protobuf": "0.6.10",
97
- "@dxos/config": "0.6.10",
98
- "@dxos/debug": "0.6.10",
99
- "@dxos/echo-signals": "0.6.10",
100
- "@dxos/invariant": "0.6.10",
101
- "@dxos/echo-schema": "0.6.10",
102
- "@dxos/log": "0.6.10",
103
- "@dxos/node-std": "0.6.10",
104
- "@dxos/react-async": "0.6.10",
105
- "@dxos/util": "0.6.10"
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.10",
116
- "@dxos/react-ui": "0.6.10",
117
- "@dxos/storybook-utils": "0.6.10",
118
- "@dxos/react-ui-theme": "0.6.10"
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-theme": "0.6.10",
124
- "@dxos/react-ui": "0.6.10"
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.10"
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, useClient } from './ClientContext';
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
+ );
@@ -3,8 +3,14 @@
3
3
  //
4
4
 
5
5
  export * from './AgentHostingProvider';
6
- export * from './ClientContext';
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 { ClientServices } from '@dxos/client';
7
+ import { type ClientServices } from '@dxos/client';
8
8
  import { raise } from '@dxos/debug';
9
9
 
10
- import { ClientContext } from './ClientContext';
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 './ClientContext';
13
+ import { ClientProvider } from './ClientProvider';
14
14
  import { useConfig } from './useConfig';
15
15
 
16
16
  describe('Config hook', () => {
@@ -6,7 +6,7 @@ import { useContext } from 'react';
6
6
 
7
7
  import { raise } from '@dxos/debug';
8
8
 
9
- import { ClientContext } from './ClientContext';
9
+ import { ClientContext } from './context';
10
10
 
11
11
  /**
12
12
  * Hook returning config object used to initialize the DXOS client instance.
@@ -6,7 +6,7 @@ import { useEffect, useState } from 'react';
6
6
 
7
7
  import { type Shell, type ShellDisplay } from '@dxos/client';
8
8
 
9
- import { useClient } from './ClientContext';
9
+ import { useClient } from './useClient';
10
10
 
11
11
  /**
12
12
  * Helper hook to access the shell.
@@ -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 './ClientContext';
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 { ClientContext } from '../client';
8
+ import { useClient } from '../client';
12
9
 
13
10
  export const useDevtools = (): DevtoolsHost => {
14
- const { services } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));
15
- invariant(services);
16
- return services.DevtoolsHost;
11
+ const client = useClient();
12
+ return client.services.services.DevtoolsHost ?? raise(new Error('DevtoolsHost not available.'));
17
13
  };
@@ -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-async';
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-async';
9
+ import { useMulticastObservable } from '@dxos/react-hooks';
10
10
 
11
11
  import { useSpace } from './useSpaces';
12
12
  import { type CancellableInvitationObservable, useInvitationStatus } from '../invitations';