@dxos/react-client 0.8.4-main.3eb6e50203 → 0.8.4-main.3fbcb4aa9b

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 (93) hide show
  1. package/.storybook/main.mts +1 -3
  2. package/dist/lib/browser/{chunk-PFF63FPR.mjs → chunk-3LVU7RNK.mjs} +2 -2
  3. package/dist/lib/browser/{chunk-TSF6Y5VB.mjs → chunk-CZMIVAGI.mjs} +1 -1
  4. package/dist/lib/browser/{chunk-TSF6Y5VB.mjs.map → chunk-CZMIVAGI.mjs.map} +2 -2
  5. package/dist/lib/browser/{chunk-5UKA2BMA.mjs → chunk-XT352YI6.mjs} +11 -56
  6. package/dist/lib/browser/chunk-XT352YI6.mjs.map +7 -0
  7. package/dist/lib/browser/{chunk-LO3TU5CK.mjs → chunk-YHE6WD44.mjs} +3 -13
  8. package/dist/lib/browser/{chunk-LO3TU5CK.mjs.map → chunk-YHE6WD44.mjs.map} +2 -2
  9. package/dist/lib/browser/devtools/index.mjs +3 -8
  10. package/dist/lib/browser/devtools/index.mjs.map +2 -2
  11. package/dist/lib/browser/echo/index.mjs +19 -38
  12. package/dist/lib/browser/echo/index.mjs.map +3 -3
  13. package/dist/lib/browser/halo/index.mjs +3 -3
  14. package/dist/lib/browser/halo/index.mjs.map +2 -2
  15. package/dist/lib/browser/index.mjs +6 -21
  16. package/dist/lib/browser/index.mjs.map +2 -2
  17. package/dist/lib/browser/invitations/index.mjs +1 -1
  18. package/dist/lib/browser/mesh/index.mjs +2 -2
  19. package/dist/lib/browser/meta.json +1 -1
  20. package/dist/lib/browser/testing/index.mjs +15 -64
  21. package/dist/lib/browser/testing/index.mjs.map +3 -3
  22. package/dist/lib/node-esm/{chunk-NETTSER2.mjs → chunk-CUDKNAMV.mjs} +2 -2
  23. package/dist/lib/node-esm/{chunk-AQJH2UNZ.mjs → chunk-RQJPEHDY.mjs} +3 -13
  24. package/dist/lib/node-esm/{chunk-AQJH2UNZ.mjs.map → chunk-RQJPEHDY.mjs.map} +2 -2
  25. package/dist/lib/node-esm/{chunk-T3QTQHBD.mjs → chunk-WL3Z5HOH.mjs} +11 -56
  26. package/dist/lib/node-esm/chunk-WL3Z5HOH.mjs.map +7 -0
  27. package/dist/lib/node-esm/{chunk-373DPHEQ.mjs → chunk-WUTK2IJF.mjs} +1 -1
  28. package/dist/lib/node-esm/{chunk-373DPHEQ.mjs.map → chunk-WUTK2IJF.mjs.map} +2 -2
  29. package/dist/lib/node-esm/devtools/index.mjs +3 -8
  30. package/dist/lib/node-esm/devtools/index.mjs.map +2 -2
  31. package/dist/lib/node-esm/echo/index.mjs +19 -38
  32. package/dist/lib/node-esm/echo/index.mjs.map +3 -3
  33. package/dist/lib/node-esm/halo/index.mjs +3 -3
  34. package/dist/lib/node-esm/halo/index.mjs.map +2 -2
  35. package/dist/lib/node-esm/index.mjs +6 -21
  36. package/dist/lib/node-esm/index.mjs.map +2 -2
  37. package/dist/lib/node-esm/invitations/index.mjs +1 -1
  38. package/dist/lib/node-esm/mesh/index.mjs +2 -2
  39. package/dist/lib/node-esm/meta.json +1 -1
  40. package/dist/lib/node-esm/testing/index.mjs +15 -64
  41. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  42. package/dist/types/src/banner.d.ts.map +1 -1
  43. package/dist/types/src/client/AgentHostingProvider.d.ts.map +1 -1
  44. package/dist/types/src/client/ClientProvider.d.ts +1 -1
  45. package/dist/types/src/client/ClientProvider.d.ts.map +1 -1
  46. package/dist/types/src/client/useClientStatus.d.ts.map +1 -1
  47. package/dist/types/src/devtools/useStream.d.ts.map +1 -1
  48. package/dist/types/src/echo/useMembers.d.ts.map +1 -1
  49. package/dist/types/src/echo/useQueue.d.ts +1 -0
  50. package/dist/types/src/echo/useQueue.d.ts.map +1 -1
  51. package/dist/types/src/echo/useSpaceInvitations.d.ts.map +1 -1
  52. package/dist/types/src/echo/useSpaceProperties.d.ts.map +1 -1
  53. package/dist/types/src/echo/useSpaces.d.ts +7 -6
  54. package/dist/types/src/echo/useSpaces.d.ts.map +1 -1
  55. package/dist/types/src/echo/useSubscription.d.ts.map +1 -1
  56. package/dist/types/src/echo/useSyncState.d.ts.map +1 -1
  57. package/dist/types/src/halo/Passkey.stories.d.ts.map +1 -1
  58. package/dist/types/src/halo/useHaloInvitations.d.ts.map +1 -1
  59. package/dist/types/src/halo/useKeyStore.d.ts.map +1 -1
  60. package/dist/types/src/invitations/useInvitationStatus.d.ts.map +1 -1
  61. package/dist/types/src/testing/ClientRepeater.d.ts +1 -1
  62. package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
  63. package/dist/types/src/testing/ClientRepeater.stories.d.ts.map +1 -1
  64. package/dist/types/src/testing/util.d.ts.map +1 -1
  65. package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
  66. package/dist/types/src/testing/withClientProvider.stories.d.ts +1 -1
  67. package/dist/types/src/testing/withClientProvider.stories.d.ts.map +1 -1
  68. package/dist/types/tsconfig.tsbuildinfo +1 -1
  69. package/docs/README.md +38 -38
  70. package/moon.yml +1 -4
  71. package/package.json +24 -50
  72. package/src/client/ClientProvider.test.tsx +0 -1
  73. package/src/client/ClientProvider.tsx +0 -1
  74. package/src/client/useConfig.test.tsx +0 -1
  75. package/src/echo/useQueue.ts +1 -2
  76. package/src/echo/useSpaceInvitations.ts +0 -1
  77. package/src/echo/useSpaces.test.tsx +6 -13
  78. package/src/echo/useSpaces.ts +15 -30
  79. package/src/echo/useSyncState.ts +2 -1
  80. package/src/halo/Passkey.stories.tsx +4 -7
  81. package/src/halo/useDevices.test.tsx +0 -1
  82. package/src/testing/ClientRepeater.stories.tsx +4 -7
  83. package/src/testing/ClientRepeater.tsx +3 -4
  84. package/src/testing/util.tsx +0 -1
  85. package/src/testing/withClientProvider.stories.tsx +6 -8
  86. package/src/testing/withClientProvider.tsx +4 -38
  87. package/typedoc.json +1 -1
  88. package/vitest.config.ts +0 -2
  89. package/.swc/plugins/linux_x86_64_19.0.0/727453fb3a62f7f1d952a41e051ca8a6f88cadc45cee43c6a4d1aa45f9b75665.wasmer-v7 +0 -0
  90. package/dist/lib/browser/chunk-5UKA2BMA.mjs.map +0 -7
  91. package/dist/lib/node-esm/chunk-T3QTQHBD.mjs.map +0 -7
  92. /package/dist/lib/browser/{chunk-PFF63FPR.mjs.map → chunk-3LVU7RNK.mjs.map} +0 -0
  93. /package/dist/lib/node-esm/{chunk-NETTSER2.mjs.map → chunk-CUDKNAMV.mjs.map} +0 -0
@@ -3,18 +3,17 @@
3
3
  //
4
4
 
5
5
  import { type Decorator, type StoryContext } from '@storybook/react';
6
- import React, { type PropsWithChildren, useCallback, useEffect, useMemo, useRef, useState } from 'react';
7
- import { type FallbackProps, ErrorBoundary as NaturalErrorBoundary } from 'react-error-boundary';
6
+ import React, { useCallback, useMemo, useRef, useState } from 'react';
8
7
 
9
8
  import { Trigger } from '@dxos/async';
10
9
  import { type Client } from '@dxos/client';
11
10
  import { type Space, type SpaceId } from '@dxos/client/echo';
12
11
  import { TestBuilder, performInvitation } from '@dxos/client/testing';
13
12
  import { log } from '@dxos/log';
13
+ import { ErrorBoundary } from '@dxos/react-ui';
14
14
  import { type MaybePromise } from '@dxos/util';
15
15
 
16
16
  import { ClientProvider, type ClientProviderProps } from '../client';
17
-
18
17
  import { ClientStory } from './context';
19
18
 
20
19
  type InitializeProps = {
@@ -39,8 +38,6 @@ const initializeClient = async (
39
38
  if (createIdentity || createSpace) {
40
39
  if (!client.halo.identity.get()) {
41
40
  await client.halo.createIdentity();
42
- await client.spaces.waitUntilReady();
43
- await client.spaces.default.waitUntilReady();
44
41
  await onCreateIdentity?.({ client }, context);
45
42
  }
46
43
  }
@@ -87,7 +84,7 @@ export const withClientProvider = ({
87
84
  };
88
85
 
89
86
  return (
90
- <ErrorBoundary>
87
+ <ErrorBoundary name='client-provider'>
91
88
  <ClientProvider onInitialized={handleInitialized} {...props}>
92
89
  <ClientStory.Provider value={data}>
93
90
  <Story />
@@ -178,7 +175,7 @@ export const withMultiClientProvider = ({
178
175
  {...props}
179
176
  >
180
177
  <ClientStory.Provider value={{ index, spaceId }}>
181
- <ErrorBoundary>
178
+ <ErrorBoundary name='client-provider'>
182
179
  <Story />
183
180
  </ErrorBoundary>
184
181
  </ClientStory.Provider>
@@ -188,34 +185,3 @@ export const withMultiClientProvider = ({
188
185
  );
189
186
  };
190
187
  };
191
-
192
- const ErrorBoundary = ({ children }: PropsWithChildren) => {
193
- const [error, setError] = useState<Error>();
194
- useEffect(() => {
195
- const handleError = (event: PromiseRejectionEvent) => {
196
- setError(event.reason);
197
- };
198
-
199
- window.addEventListener('unhandledrejection', handleError);
200
- return () => window.removeEventListener('unhandledrejection', handleError);
201
- }, []);
202
-
203
- if (error) {
204
- return <ErrorFallback error={error} resetErrorBoundary={() => setError(undefined)} />;
205
- }
206
-
207
- return <NaturalErrorBoundary FallbackComponent={ErrorFallback}>{children}</NaturalErrorBoundary>;
208
- };
209
-
210
- const ErrorFallback = ({ error }: FallbackProps) => {
211
- const { name, message, stack } =
212
- error instanceof Error ? error : { name: 'Error', message: String(error), stack: undefined };
213
-
214
- return (
215
- <div role='alert' className='flex flex-col p-4 gap-4 overflow-auto'>
216
- <h1 className='text-xl text-red-500'>{name}</h1>
217
- <div className='text-lg'>{message}</div>
218
- {stack && <pre className='whitespace-pre-wrap text-sm text-subdued'>{stack}</pre>}
219
- </div>
220
- );
221
- };
package/typedoc.json CHANGED
@@ -9,4 +9,4 @@
9
9
  "src/mesh/index.ts",
10
10
  "src/worker.ts"
11
11
  ]
12
- }
12
+ }
package/vitest.config.ts CHANGED
@@ -11,8 +11,6 @@ export default createConfig({
11
11
  dirname: typeof __dirname !== 'undefined' ? __dirname : path.dirname(fileURLToPath(import.meta.url)),
12
12
  node: {
13
13
  environment: 'happy-dom',
14
- // TODO(dmaretskyi): Enabled because client tests were flaky. Remove when that's not the case.
15
- retry: 2,
16
14
  },
17
15
  storybook: true,
18
16
  });
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/client/ClientProvider.tsx", "../../../src/banner.ts"],
4
- "sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport React, {\n type FunctionComponent,\n type PropsWithChildren,\n forwardRef,\n useEffect,\n useImperativeHandle,\n useState,\n} from 'react';\n\nimport { Client, type ClientOptions, type ClientServicesProvider, SystemStatus } from '@dxos/client';\nimport { type Config } from '@dxos/config';\nimport { log } from '@dxos/log';\nimport { useAsyncEffect, useControlledState } from '@dxos/react-hooks';\nimport { type MaybePromise, type Provider, getAsyncProviderValue } from '@dxos/util';\n\nimport { printBanner } from '../banner';\n\nimport { ClientContext, type ClientContextProps } from './context';\n\n/**\n * Properties for the ClientProvider.\n */\nexport type ClientProviderProps = Omit<ClientOptions, 'config' | 'services'> &\n Pick<ClientContextProps, 'status'> &\n PropsWithChildren<{\n /**\n * Client object or async provider to enable to caller to do custom initialization.\n *\n * NOTE: For advanced use cases only.\n */\n client?: Client | Provider<Promise<Client>>;\n\n /**\n * Config object or async provider.\n *\n * NOTE: If a `client` is provided then `config` is ignored.\n */\n // TODO(burdon): Reconcile with ClientOptions.\n config?: Config | Provider<Promise<Config>>;\n\n /**\n * Callback to enable the caller to create a custom ClientServicesProvider.\n *\n * NOTE: If a `client` is provided then `services` is ignored.\n */\n // TODO(burdon): Reconcile with ClientOptions.\n services?: ClientServicesProvider | ((config?: Config) => MaybePromise<ClientServicesProvider>);\n\n /**\n * ReactNode to display until the client is available.\n */\n fallback?: FunctionComponent<Partial<ClientContextProps>>;\n\n /**\n * Skip the DXOS banner.\n */\n noBanner?: boolean;\n\n /**\n * Post initialization hook to enable to caller to do custom initialization.\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 = forwardRef<Client | undefined, ClientProviderProps>(\n (\n {\n children,\n config: configProp,\n client: clientProp,\n services: servicesProp,\n status: statusProp,\n fallback: Fallback = () => null,\n noBanner,\n onInitialized,\n ...options\n },\n forwardedRef,\n ) => {\n // The client is initialized asynchronously.\n // If an error occurs during initialization, it is caught and the state is set.\n // This allows the error to be thrown in the render method.\n // The assumption is that a client initialization error is fatal to the app.\n // This error will be caught by the nearest error boundary.\n const [error, setError] = useState();\n if (error) {\n throw error;\n }\n\n const [client, setClient] = useState(clientProp instanceof Client ? clientProp : undefined);\n\n // Provide external access.\n useImperativeHandle(forwardedRef, () => client, [client]);\n\n // Client status subscription.\n const [status, setStatus] = useControlledState(statusProp);\n useEffect(() => {\n if (!client) {\n return;\n }\n\n const subscription = client.status.subscribe((status) => setStatus(status));\n return () => subscription.unsubscribe();\n }, [client]);\n\n // Create and/or initialize client.\n useAsyncEffect(async () => {\n let disposed = false;\n const initialize = async (client: Client) => {\n if (!client.initialized) {\n await client.initialize().catch((err) => {\n if (!disposed) {\n setError(err);\n }\n });\n log('client ready');\n await onInitialized?.(client);\n log('initialization complete');\n }\n\n setClient(client);\n if (!noBanner) {\n printBanner(client);\n }\n };\n\n let client: Client;\n try {\n if (clientProp) {\n // Asynchronously request client.\n client = await getAsyncProviderValue(clientProp);\n await initialize(client);\n } else {\n // Asynchronously construct client (config may be undefined).\n const config = await getAsyncProviderValue(configProp);\n log('resolved config', { config });\n const services = await getAsyncProviderValue(servicesProp, config);\n log('created services', { services });\n client = new Client({ config, services, ...options });\n log('created client');\n await initialize(client);\n }\n } catch (err) {\n if (!disposed) {\n log.catch(err);\n }\n }\n\n return () => {\n log('clean up');\n disposed = true;\n // Only destroy if the client is not provided by the parent.\n if (!clientProp) {\n void client\n ?.destroy()\n .then(() => {\n log('destroyed');\n })\n .catch((err) => log.catch(err));\n }\n };\n }, [configProp, clientProp, servicesProp, noBanner]);\n\n if (!client?.initialized || 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", "//\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 || window.location.hostname === 'localhost') {\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"],
5
- "mappings": ";;;;;AAIA,OAAOA,SAGLC,YACAC,WACAC,qBACAC,gBACK;AAEP,SAASC,QAAyDC,oBAAoB;AAEtF,SAASC,WAAW;AACpB,SAASC,gBAAgBC,0BAA0B;AACnD,SAA2CC,6BAA6B;;;ACVxE,IAAMC,SAAS,CAACC,WAAAA;AACd,QAAMC,aAAaD,OAAOE,OAAOC,IAAI,8BAAA;AACrC,QAAMC,OAAOH,aAAa,eAAeA,UAAAA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", "log", "useAsyncEffect", "useControlledState", "getAsyncProviderValue", "BANNER", "client", "commitHash", "config", "get", "hash", "version", "bannerPrinted", "printBanner", "window", "location", "hostname", "console", "log", "ClientProvider", "forwardRef", "children", "config", "configProp", "client", "clientProp", "services", "servicesProp", "status", "statusProp", "fallback", "Fallback", "noBanner", "onInitialized", "options", "forwardedRef", "error", "setError", "useState", "setClient", "Client", "undefined", "useImperativeHandle", "setStatus", "useControlledState", "useEffect", "subscription", "subscribe", "unsubscribe", "useAsyncEffect", "disposed", "initialize", "initialized", "catch", "err", "log", "printBanner", "getAsyncProviderValue", "destroy", "then", "SystemStatus", "ACTIVE", "ClientContext", "Provider", "value"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/client/ClientProvider.tsx", "../../../src/banner.ts"],
4
- "sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport React, {\n type FunctionComponent,\n type PropsWithChildren,\n forwardRef,\n useEffect,\n useImperativeHandle,\n useState,\n} from 'react';\n\nimport { Client, type ClientOptions, type ClientServicesProvider, SystemStatus } from '@dxos/client';\nimport { type Config } from '@dxos/config';\nimport { log } from '@dxos/log';\nimport { useAsyncEffect, useControlledState } from '@dxos/react-hooks';\nimport { type MaybePromise, type Provider, getAsyncProviderValue } from '@dxos/util';\n\nimport { printBanner } from '../banner';\n\nimport { ClientContext, type ClientContextProps } from './context';\n\n/**\n * Properties for the ClientProvider.\n */\nexport type ClientProviderProps = Omit<ClientOptions, 'config' | 'services'> &\n Pick<ClientContextProps, 'status'> &\n PropsWithChildren<{\n /**\n * Client object or async provider to enable to caller to do custom initialization.\n *\n * NOTE: For advanced use cases only.\n */\n client?: Client | Provider<Promise<Client>>;\n\n /**\n * Config object or async provider.\n *\n * NOTE: If a `client` is provided then `config` is ignored.\n */\n // TODO(burdon): Reconcile with ClientOptions.\n config?: Config | Provider<Promise<Config>>;\n\n /**\n * Callback to enable the caller to create a custom ClientServicesProvider.\n *\n * NOTE: If a `client` is provided then `services` is ignored.\n */\n // TODO(burdon): Reconcile with ClientOptions.\n services?: ClientServicesProvider | ((config?: Config) => MaybePromise<ClientServicesProvider>);\n\n /**\n * ReactNode to display until the client is available.\n */\n fallback?: FunctionComponent<Partial<ClientContextProps>>;\n\n /**\n * Skip the DXOS banner.\n */\n noBanner?: boolean;\n\n /**\n * Post initialization hook to enable to caller to do custom initialization.\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 = forwardRef<Client | undefined, ClientProviderProps>(\n (\n {\n children,\n config: configProp,\n client: clientProp,\n services: servicesProp,\n status: statusProp,\n fallback: Fallback = () => null,\n noBanner,\n onInitialized,\n ...options\n },\n forwardedRef,\n ) => {\n // The client is initialized asynchronously.\n // If an error occurs during initialization, it is caught and the state is set.\n // This allows the error to be thrown in the render method.\n // The assumption is that a client initialization error is fatal to the app.\n // This error will be caught by the nearest error boundary.\n const [error, setError] = useState();\n if (error) {\n throw error;\n }\n\n const [client, setClient] = useState(clientProp instanceof Client ? clientProp : undefined);\n\n // Provide external access.\n useImperativeHandle(forwardedRef, () => client, [client]);\n\n // Client status subscription.\n const [status, setStatus] = useControlledState(statusProp);\n useEffect(() => {\n if (!client) {\n return;\n }\n\n const subscription = client.status.subscribe((status) => setStatus(status));\n return () => subscription.unsubscribe();\n }, [client]);\n\n // Create and/or initialize client.\n useAsyncEffect(async () => {\n let disposed = false;\n const initialize = async (client: Client) => {\n if (!client.initialized) {\n await client.initialize().catch((err) => {\n if (!disposed) {\n setError(err);\n }\n });\n log('client ready');\n await onInitialized?.(client);\n log('initialization complete');\n }\n\n setClient(client);\n if (!noBanner) {\n printBanner(client);\n }\n };\n\n let client: Client;\n try {\n if (clientProp) {\n // Asynchronously request client.\n client = await getAsyncProviderValue(clientProp);\n await initialize(client);\n } else {\n // Asynchronously construct client (config may be undefined).\n const config = await getAsyncProviderValue(configProp);\n log('resolved config', { config });\n const services = await getAsyncProviderValue(servicesProp, config);\n log('created services', { services });\n client = new Client({ config, services, ...options });\n log('created client');\n await initialize(client);\n }\n } catch (err) {\n if (!disposed) {\n log.catch(err);\n }\n }\n\n return () => {\n log('clean up');\n disposed = true;\n // Only destroy if the client is not provided by the parent.\n if (!clientProp) {\n void client\n ?.destroy()\n .then(() => {\n log('destroyed');\n })\n .catch((err) => log.catch(err));\n }\n };\n }, [configProp, clientProp, servicesProp, noBanner]);\n\n if (!client?.initialized || 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", "//\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 || window.location.hostname === 'localhost') {\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"],
5
- "mappings": ";;;;;;AAIA,OAAOA,SAGLC,YACAC,WACAC,qBACAC,gBACK;AAEP,SAASC,QAAyDC,oBAAoB;AAEtF,SAASC,WAAW;AACpB,SAASC,gBAAgBC,0BAA0B;AACnD,SAA2CC,6BAA6B;;;ACVxE,IAAMC,SAAS,CAACC,WAAAA;AACd,QAAMC,aAAaD,OAAOE,OAAOC,IAAI,8BAAA;AACrC,QAAMC,OAAOH,aAAa,eAAeA,UAAAA;IAAkB;AAE3D,SACE;;;;;;;eAMkBD,OAAOK,OAAO;EAAMD,IAAAA;AAE1C;AAEA,IAAIE,gBAAgB;AAEb,IAAMC,cAAc,CAACP,WAAAA;AAC1B,MAAIM,iBAAiBE,OAAOC,SAASC,aAAa,aAAa;AAC7D;EACF;AAEAJ,kBAAgB;AAEhBK,UAAQC,IAAI,KAAKb,OAAOC,MAAAA,CAAAA,IAAW,yBAAA;AACrC;;;;ADwCO,IAAMa,iBAAiBC,2BAC5B,CACE,EACEC,UACAC,QAAQC,YACRC,QAAQC,YACRC,UAAUC,cACVC,QAAQC,YACRC,UAAUC,WAAW,MAAM,MAC3BC,UACAC,eACA,GAAGC,QAAAA,GAELC,iBAAAA;AAOA,QAAM,CAACC,OAAOC,QAAAA,IAAYC,SAAAA;AAC1B,MAAIF,OAAO;AACT,UAAMA;EACR;AAEA,QAAM,CAACZ,QAAQe,SAAAA,IAAaD,SAASb,sBAAsBe,SAASf,aAAagB,MAAAA;AAGjFC,sBAAoBP,cAAc,MAAMX,QAAQ;IAACA;GAAO;AAGxD,QAAM,CAACI,QAAQe,SAAAA,IAAaC,mBAAmBf,UAAAA;AAC/CgB,YAAU,MAAA;AACR,QAAI,CAACrB,QAAQ;AACX;IACF;AA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EACDC,KAAK,MAAA;AACJJ,cAAI,aAAA,QAAA;;;;;;QACN,CAAA,EACCF,MAAM,CAACC,QAAQC,IAAIF,MAAMC,KAAAA,QAAAA;;;;;;MAC9B;IACF;EACF,GAAG;IAAC/B;IAAYE;IAAYE;IAAcK;GAAS;AAEnD,MAAI,CAACR,QAAQ4B,eAAexB,WAAWgC,aAAaC,QAAQ;AAC1D,WAAO,sBAAA,cAAC9B,UAAAA;MAASP;MAAgBI;;EACnC;AAEA,SAAO,sBAAA,cAACkC,cAAcC,UAAQ;IAACC,OAAO;MAAExC;MAAQI;IAAO;KAAIP,QAAAA;AAC7D,CAAA;",
6
- "names": ["React", "forwardRef", "useEffect", "useImperativeHandle", "useState", "Client", "SystemStatus", "log", "useAsyncEffect", "useControlledState", "getAsyncProviderValue", "BANNER", "client", "commitHash", "config", "get", "hash", "version", "bannerPrinted", "printBanner", "window", "location", "hostname", "console", "log", "ClientProvider", "forwardRef", "children", "config", "configProp", "client", "clientProp", "services", "servicesProp", "status", "statusProp", "fallback", "Fallback", "noBanner", "onInitialized", "options", "forwardedRef", "error", "setError", "useState", "setClient", "Client", "undefined", "useImperativeHandle", "setStatus", "useControlledState", "useEffect", "subscription", "subscribe", "unsubscribe", "useAsyncEffect", "disposed", "initialize", "initialized", "catch", "err", "log", "printBanner", "getAsyncProviderValue", "destroy", "then", "SystemStatus", "ACTIVE", "ClientContext", "Provider", "value"]
7
- }