@dxos/react-client 0.6.11-staging.e6894a4 → 0.6.12-main.5cc132e

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 (131) hide show
  1. package/dist/lib/browser/{chunk-NLQLAARM.mjs → chunk-ESSNDYBJ.mjs} +116 -79
  2. package/dist/lib/browser/chunk-ESSNDYBJ.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 -4
  10. package/dist/lib/browser/index.mjs.map +1 -1
  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-N474KOAU.cjs} +102 -69
  17. package/dist/lib/node/chunk-N474KOAU.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 +15 -15
  25. package/dist/lib/node/index.cjs.map +1 -1
  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/lib/node-esm/chunk-AL2CUQ46.mjs +163 -0
  32. package/dist/lib/node-esm/chunk-AL2CUQ46.mjs.map +7 -0
  33. package/dist/lib/node-esm/chunk-ESSNDYBJ.mjs +300 -0
  34. package/dist/lib/node-esm/chunk-ESSNDYBJ.mjs.map +7 -0
  35. package/dist/lib/node-esm/devtools/index.mjs +43 -0
  36. package/dist/lib/node-esm/devtools/index.mjs.map +7 -0
  37. package/dist/lib/node-esm/echo/index.mjs +131 -0
  38. package/dist/lib/node-esm/echo/index.mjs.map +7 -0
  39. package/dist/lib/node-esm/halo/index.mjs +99 -0
  40. package/dist/lib/node-esm/halo/index.mjs.map +7 -0
  41. package/dist/lib/node-esm/index.mjs +32 -0
  42. package/dist/lib/node-esm/index.mjs.map +7 -0
  43. package/dist/lib/node-esm/invitations/index.mjs +17 -0
  44. package/dist/lib/node-esm/invitations/index.mjs.map +7 -0
  45. package/dist/lib/node-esm/mesh/index.mjs +17 -0
  46. package/dist/lib/node-esm/mesh/index.mjs.map +7 -0
  47. package/dist/lib/node-esm/meta.json +1 -0
  48. package/dist/lib/node-esm/testing/index.mjs +165 -0
  49. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  50. package/dist/lib/node-esm/worker.mjs +3 -0
  51. package/dist/lib/node-esm/worker.mjs.map +7 -0
  52. package/dist/types/src/client/AgentHostingProvider.d.ts +6 -0
  53. package/dist/types/src/client/AgentHostingProvider.d.ts.map +1 -1
  54. package/dist/types/src/client/ClientProvider.d.ts +108 -0
  55. package/dist/types/src/client/ClientProvider.d.ts.map +1 -0
  56. package/dist/types/src/client/ClientProvider.test.d.ts +2 -0
  57. package/dist/types/src/client/ClientProvider.test.d.ts.map +1 -0
  58. package/dist/types/src/client/context.d.ts +6 -0
  59. package/dist/types/src/client/context.d.ts.map +1 -0
  60. package/dist/types/src/client/index.d.ts +4 -2
  61. package/dist/types/src/client/index.d.ts.map +1 -1
  62. package/dist/types/src/client/useClient.d.ts +6 -0
  63. package/dist/types/src/client/useClient.d.ts.map +1 -0
  64. package/dist/types/src/client/useClientStatus.d.ts +3 -0
  65. package/dist/types/src/client/useClientStatus.d.ts.map +1 -0
  66. package/dist/types/src/devtools/useDevtools.d.ts.map +1 -1
  67. package/dist/types/src/index.d.ts +1 -1
  68. package/dist/types/src/playwright/playwright.config.d.ts +2 -2
  69. package/dist/types/src/playwright/playwright.config.d.ts.map +1 -1
  70. package/dist/types/src/testing/ClientRepeater.d.ts +6 -5
  71. package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
  72. package/dist/types/src/testing/{decorators.stories.d.ts → ClientRepeater.stories.d.ts} +3 -3
  73. package/dist/types/src/testing/ClientRepeater.stories.d.ts.map +1 -0
  74. package/dist/types/src/testing/index.d.ts +1 -0
  75. package/dist/types/src/testing/index.d.ts.map +1 -1
  76. package/dist/types/src/testing/util.d.ts +14 -0
  77. package/dist/types/src/testing/util.d.ts.map +1 -0
  78. package/dist/types/src/testing/withClientProvider.d.ts +26 -0
  79. package/dist/types/src/testing/withClientProvider.d.ts.map +1 -0
  80. package/dist/types/src/testing/withClientProvider.stories.d.ts +13 -0
  81. package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -0
  82. package/package.json +46 -34
  83. package/project.json +3 -23
  84. package/src/client/AgentHostingProvider.tsx +7 -6
  85. package/src/client/{ClientContext.test.tsx → ClientProvider.test.tsx} +9 -5
  86. package/src/client/ClientProvider.tsx +196 -0
  87. package/src/client/context.ts +20 -0
  88. package/src/client/index.ts +5 -2
  89. package/src/client/useClient.ts +18 -0
  90. package/src/client/useClientStatus.ts +21 -0
  91. package/src/client/useConfig.test.tsx +7 -11
  92. package/src/client/useConfig.ts +1 -1
  93. package/src/client/useShell.ts +1 -1
  94. package/src/client/useStatus.ts +1 -1
  95. package/src/devtools/useDevtools.ts +3 -7
  96. package/src/echo/useMembers.ts +1 -1
  97. package/src/echo/useSpaceInvitations.ts +1 -1
  98. package/src/echo/useSpaces.test.tsx +11 -37
  99. package/src/echo/useSpaces.ts +1 -1
  100. package/src/halo/useContacts.ts +1 -1
  101. package/src/halo/useDevices.test.tsx +4 -13
  102. package/src/halo/useDevices.ts +1 -1
  103. package/src/halo/useHaloInvitations.ts +1 -1
  104. package/src/halo/useIdentity.ts +1 -1
  105. package/src/index.ts +1 -1
  106. package/src/mesh/useNetworkStatus.ts +1 -1
  107. package/src/playwright/playwright.config.ts +13 -2
  108. package/src/playwright/smoke.spec.ts +5 -10
  109. package/src/testing/ClientRepeater.stories.tsx +58 -0
  110. package/src/testing/ClientRepeater.tsx +14 -13
  111. package/src/testing/index.ts +1 -0
  112. package/src/testing/util.tsx +39 -0
  113. package/src/testing/withClientProvider.stories.tsx +56 -0
  114. package/src/testing/withClientProvider.tsx +143 -0
  115. package/tsconfig.json +11 -3
  116. package/vitest.config.ts +22 -0
  117. package/dist/lib/browser/chunk-NLQLAARM.mjs.map +0 -7
  118. package/dist/lib/node/chunk-E3S6YHNJ.cjs.map +0 -7
  119. package/dist/types/src/client/ClientContext.d.ts +0 -57
  120. package/dist/types/src/client/ClientContext.d.ts.map +0 -1
  121. package/dist/types/src/client/ClientContext.stories.d.ts +0 -15
  122. package/dist/types/src/client/ClientContext.stories.d.ts.map +0 -1
  123. package/dist/types/src/client/ClientContext.test.d.ts +0 -2
  124. package/dist/types/src/client/ClientContext.test.d.ts.map +0 -1
  125. package/dist/types/src/client/useClientServices.d.ts +0 -3
  126. package/dist/types/src/client/useClientServices.d.ts.map +0 -1
  127. package/dist/types/src/testing/decorators.stories.d.ts.map +0 -1
  128. package/src/client/ClientContext.stories.tsx +0 -94
  129. package/src/client/ClientContext.tsx +0 -182
  130. package/src/client/useClientServices.ts +0 -15
  131. package/src/testing/decorators.stories.tsx +0 -63
@@ -1 +0,0 @@
1
- {"version":3,"file":"ClientContext.test.d.ts","sourceRoot":"","sources":["../../../../src/client/ClientContext.test.tsx"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- import type { ClientServices } from '@dxos/client';
2
- export declare const useClientServices: () => ClientServices | undefined;
3
- //# sourceMappingURL=useClientServices.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useClientServices.d.ts","sourceRoot":"","sources":["../../../../src/client/useClientServices.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAKnD,eAAO,MAAM,iBAAiB,QAAO,cAAc,GAAG,SAGrD,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"decorators.stories.d.ts","sourceRoot":"","sources":["../../../../src/testing/decorators.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,KAAK,MAAM,OAAO,CAAC;;;;;AAS1B,wBAGE;AAsBF,eAAO,MAAM,UAAU;;CAEtB,CAAC;AAkBF,eAAO,MAAM,eAAe;;CAE3B,CAAC"}
@@ -1,94 +0,0 @@
1
- //
2
- // Copyright 2021 DXOS.org
3
- //
4
-
5
- import '@dxos-theme';
6
-
7
- import React, { Component, type PropsWithChildren } from 'react';
8
-
9
- import { fromHost } from '@dxos/client';
10
- import { Config } from '@dxos/config';
11
- import { withTheme } from '@dxos/storybook-utils';
12
-
13
- import { ClientProvider, useClient } from './ClientContext';
14
-
15
- export default {
16
- title: 'react-client/ClientContext',
17
- component: ClientProvider,
18
- decorators: [withTheme],
19
- };
20
-
21
- const JsonPanel = ({ value }: { value: any }) => (
22
- <pre
23
- style={{
24
- margin: 0,
25
- // code whiteSpace: 'pre-wrap',
26
- // code wordBreak: 'break-all',
27
- overflow: 'hidden',
28
- textOverflow: 'ellipsis',
29
- }}
30
- >
31
- {JSON.stringify(value, undefined, 2)}
32
- </pre>
33
- );
34
-
35
- const TestApp = () => {
36
- const client = useClient();
37
-
38
- return (
39
- <div>
40
- <div style={{ padding: 1 }}>
41
- <JsonPanel value={client.config} />
42
- </div>
43
- <div style={{ padding: 1 }}>
44
- <JsonPanel value={client.toJSON()} />
45
- </div>
46
- <div style={{ padding: 1 }}>
47
- <JsonPanel value={client.halo.identity} />
48
- </div>
49
- </div>
50
- );
51
- };
52
-
53
- const servicesProvider = (config?: Config) => fromHost(config);
54
-
55
- export const Default = {
56
- render: () => (
57
- <ClientProvider services={servicesProvider}>
58
- <TestApp />
59
- </ClientProvider>
60
- ),
61
- };
62
-
63
- class ErrorBoundary extends Component<PropsWithChildren<{}>, { hasError: boolean }> {
64
- constructor(props: any) {
65
- super(props);
66
- this.state = { hasError: false };
67
- }
68
-
69
- static getDerivedStateFromError() {
70
- // Update state so the next render will show the fallback UI.
71
- return { hasError: true };
72
- }
73
-
74
- override render() {
75
- if (this.state.hasError) {
76
- // You can render any custom fallback UI
77
- return <div>Runtime Error</div>;
78
- }
79
-
80
- return this.props.children;
81
- }
82
- }
83
-
84
- const config = new Config({ runtime: { client: { remoteSource: 'bad-value' } } });
85
-
86
- export const Error = {
87
- render: () => (
88
- <ErrorBoundary>
89
- <ClientProvider config={config}>
90
- <TestApp />
91
- </ClientProvider>
92
- </ErrorBoundary>
93
- ),
94
- };
@@ -1,182 +0,0 @@
1
- //
2
- // Copyright 2020 DXOS.org
3
- //
4
-
5
- import React, {
6
- type ReactNode,
7
- useState,
8
- type Context,
9
- createContext,
10
- useContext,
11
- useEffect,
12
- type FunctionComponent,
13
- useMemo,
14
- } from 'react';
15
-
16
- import {
17
- Client,
18
- SystemStatus,
19
- type ClientOptions,
20
- type ClientServices,
21
- type ClientServicesProvider,
22
- } from '@dxos/client';
23
- import { type Config } from '@dxos/config';
24
- import { raise } from '@dxos/debug';
25
- import { registerSignalFactory } from '@dxos/echo-signals/react';
26
- import { log } from '@dxos/log';
27
- import { getAsyncValue, type MaybePromise, type Provider } from '@dxos/util'; // TODO(burdon): Deprecate "util"?
28
-
29
- import { printBanner } from '../banner';
30
-
31
- // TODO(burdon): Reconcile with ClientOptions.
32
- export type ClientContextProps = {
33
- client: Client;
34
-
35
- // Optionally expose services (e.g., for devtools).
36
- // TODO(burdon): Can't this just be accessed via `client.services`?
37
- services?: ClientServices;
38
-
39
- status?: SystemStatus | null;
40
- };
41
-
42
- export const ClientContext: Context<ClientContextProps | undefined> = createContext<ClientContextProps | undefined>(
43
- undefined,
44
- );
45
-
46
- /**
47
- * Hook returning instance of DXOS client.
48
- * Requires ClientContext to be set via ClientProvider.
49
- */
50
- export const useClient = () => {
51
- const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));
52
- return client;
53
- };
54
-
55
- /**
56
- * Properties for the ClientProvider.
57
- */
58
- export type ClientProviderProps = Omit<ClientOptions, 'config' | 'services'> & {
59
- children?: ReactNode;
60
-
61
- /**
62
- * Config object or async provider.
63
- */
64
- config?: Config | Provider<Promise<Config>>;
65
-
66
- /**
67
- * Callback to enable the caller to create a custom ClientServicesProvider.
68
- *
69
- * Most apps won't need this.
70
- */
71
- services?: (config?: Config) => MaybePromise<ClientServicesProvider>;
72
-
73
- /**
74
- * Client object or async provider to enable to caller to do custom initialization.
75
- *
76
- * Most apps won't need this.
77
- */
78
- // TODO(wittjosiah): Remove async and just use to keeping reference to client?
79
- // (Prefering `onInitialized` for custom initialization.)
80
- client?: Client | Provider<Promise<Client>>;
81
-
82
- /**
83
- * ReactNode to display until the client is available.
84
- */
85
- // TODO(wittjosiah): Rename to `placeholder`.
86
- fallback?: FunctionComponent<Partial<ClientContextProps>>;
87
-
88
- /**
89
- * Set to false to stop default signal factory from being registered.
90
- */
91
- registerSignalFactory?: boolean;
92
-
93
- /**
94
- * Post initialization hook to enable to caller to do custom initialization.
95
- *
96
- * @param Client
97
- */
98
- onInitialized?: (client: Client) => MaybePromise<void>;
99
- };
100
-
101
- /**
102
- * Root component that provides the DXOS client instance to child components.
103
- * To be used with the `useClient` hook.
104
- */
105
- export const ClientProvider = ({
106
- children,
107
- config: configProvider,
108
- services: createServices,
109
- client: clientProvider,
110
- fallback: Fallback = () => null,
111
- registerSignalFactory: register = true,
112
- onInitialized,
113
- ...options
114
- }: ClientProviderProps) => {
115
- useMemo(() => {
116
- // TODO(wittjosiah): Ideally this should be imported asynchronosly because it is optional.
117
- // Unfortunately, async import seemed to break signals React instrumentation.
118
- register && registerSignalFactory();
119
- }, []);
120
-
121
- const [client, setClient] = useState(clientProvider instanceof Client ? clientProvider : undefined);
122
- const [status, setStatus] = useState<SystemStatus | null>(null);
123
- const [error, setError] = useState();
124
- if (error) {
125
- throw error;
126
- }
127
-
128
- useEffect(() => {
129
- if (!client) {
130
- return;
131
- }
132
-
133
- const subscription = client.status.subscribe((status) => setStatus(status));
134
- return () => subscription.unsubscribe();
135
- }, [client, setStatus]);
136
-
137
- useEffect(() => {
138
- const done = async (client: Client) => {
139
- await client.initialize().catch(setError);
140
- log('client ready');
141
- await onInitialized?.(client);
142
- log('initialization complete');
143
- setClient(client);
144
- setStatus(client.status.get() ?? SystemStatus.ACTIVE);
145
- printBanner(client);
146
- };
147
-
148
- const timeout = setTimeout(async () => {
149
- if (clientProvider) {
150
- // Asynchronously request client.
151
- const client = await getAsyncValue(clientProvider);
152
- await done(client);
153
- } else {
154
- // Asynchronously construct client (config may be undefined).
155
- const config = await getAsyncValue(configProvider);
156
- log('resolved config', { config });
157
- const services = await createServices?.(config);
158
- log('created services', { services });
159
- const client = new Client({ config, services, ...options });
160
- log('created client');
161
- await done(client);
162
- }
163
- });
164
-
165
- return () => {
166
- log('clean up');
167
- clearTimeout(timeout);
168
- void client?.destroy().catch((err) => log.catch(err));
169
- };
170
- }, [clientProvider, configProvider, createServices]);
171
-
172
- if (!client || status !== SystemStatus.ACTIVE) {
173
- return <Fallback client={client} status={status} />;
174
- }
175
-
176
- // prettier-ignore
177
- return (
178
- <ClientContext.Provider value={{ client, status }}>
179
- {children}
180
- </ClientContext.Provider>
181
- );
182
- };
@@ -1,15 +0,0 @@
1
- //
2
- // Copyright 2022 DXOS.org
3
- //
4
-
5
- import { useContext } from 'react';
6
-
7
- import type { ClientServices } from '@dxos/client';
8
- import { raise } from '@dxos/debug';
9
-
10
- import { ClientContext } from './ClientContext';
11
-
12
- export const useClientServices = (): ClientServices | undefined => {
13
- const { services } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));
14
- return services;
15
- };
@@ -1,63 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import '@dxos-theme';
6
-
7
- import React from 'react';
8
-
9
- import { type PublicKey } from '@dxos/client';
10
- import { withTheme } from '@dxos/storybook-utils';
11
-
12
- import { ClientRepeater } from './ClientRepeater';
13
- import { useClient } from '../client';
14
- import { useSpace } from '../echo';
15
-
16
- export default {
17
- title: 'testing/decorators',
18
- decorators: [withTheme],
19
- };
20
-
21
- const JsonPanel = ({ value }: { value: any }) => (
22
- <pre
23
- style={{
24
- margin: 0,
25
- // code whiteSpace: 'pre-wrap',
26
- // code wordBreak: 'break-all',
27
- overflow: 'hidden',
28
- textOverflow: 'ellipsis',
29
- }}
30
- >
31
- {JSON.stringify(value, undefined, 2)}
32
- </pre>
33
- );
34
-
35
- const ClientStory = () => {
36
- const client = useClient();
37
-
38
- return <JsonPanel value={client.toJSON()} />;
39
- };
40
-
41
- export const WithClient = {
42
- render: () => <ClientRepeater component={ClientStory} count={2} />,
43
- };
44
-
45
- const ClientSpace = ({ spaceKey }: { spaceKey: PublicKey }) => {
46
- const space = useSpace(spaceKey);
47
-
48
- if (!space) {
49
- return <>null</>;
50
- }
51
-
52
- return (
53
- <div className='flex-1 min-w-0 p-4'>
54
- <label>
55
- Name <input value={space.properties.name} onChange={(event) => (space.properties.name = event.target.value)} />
56
- </label>
57
- </div>
58
- );
59
- };
60
-
61
- export const WithClientSpace = {
62
- render: () => <ClientRepeater component={ClientSpace} count={2} createSpace />,
63
- };