@dxos/react-client 0.6.14-main.2b6a0f3 → 0.6.14-main.f49f251
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-OFVJLJ3V.mjs → chunk-GSDDO2LE.mjs} +131 -5
- package/dist/lib/browser/chunk-GSDDO2LE.mjs.map +7 -0
- package/dist/lib/browser/devtools/index.mjs +1 -2
- package/dist/lib/browser/devtools/index.mjs.map +1 -1
- package/dist/lib/browser/echo/index.mjs +1 -2
- package/dist/lib/browser/echo/index.mjs.map +1 -1
- package/dist/lib/browser/halo/index.mjs +1 -2
- package/dist/lib/browser/halo/index.mjs.map +1 -1
- package/dist/lib/browser/index.mjs +12 -114
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/mesh/index.mjs +1 -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 +16 -8
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/chunk-WR4BVOQQ.cjs +315 -0
- package/dist/lib/node/chunk-WR4BVOQQ.cjs.map +7 -0
- package/dist/lib/node/devtools/index.cjs +2 -3
- package/dist/lib/node/devtools/index.cjs.map +1 -1
- package/dist/lib/node/echo/index.cjs +3 -4
- package/dist/lib/node/echo/index.cjs.map +1 -1
- package/dist/lib/node/halo/index.cjs +5 -6
- package/dist/lib/node/halo/index.cjs.map +1 -1
- package/dist/lib/node/index.cjs +12 -120
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/mesh/index.cjs +2 -3
- 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 +18 -9
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/{chunk-KVEEO6SV.mjs → chunk-LPOLSASZ.mjs} +132 -5
- package/dist/lib/node-esm/chunk-LPOLSASZ.mjs.map +7 -0
- package/dist/lib/node-esm/devtools/index.mjs +1 -2
- package/dist/lib/node-esm/devtools/index.mjs.map +1 -1
- package/dist/lib/node-esm/echo/index.mjs +1 -2
- package/dist/lib/node-esm/echo/index.mjs.map +1 -1
- package/dist/lib/node-esm/halo/index.mjs +1 -2
- package/dist/lib/node-esm/halo/index.mjs.map +1 -1
- package/dist/lib/node-esm/index.mjs +12 -114
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/mesh/index.mjs +1 -2
- package/dist/lib/node-esm/mesh/index.mjs.map +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +16 -8
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/testing/withClientProvider.d.ts +3 -0
- package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
- package/package.json +40 -64
- package/src/playwright/smoke.spec.ts +1 -1
- package/src/testing/withClientProvider.tsx +14 -9
- package/dist/lib/browser/chunk-DXE5O7SV.mjs +0 -8
- package/dist/lib/browser/chunk-DXE5O7SV.mjs.map +0 -7
- package/dist/lib/browser/chunk-KX3DKZQL.mjs +0 -16
- package/dist/lib/browser/chunk-KX3DKZQL.mjs.map +0 -7
- package/dist/lib/browser/chunk-OFVJLJ3V.mjs.map +0 -7
- package/dist/lib/node/chunk-DVAPCZTK.cjs +0 -35
- package/dist/lib/node/chunk-DVAPCZTK.cjs.map +0 -7
- package/dist/lib/node/chunk-VIZOXSRY.cjs +0 -30
- package/dist/lib/node/chunk-VIZOXSRY.cjs.map +0 -7
- package/dist/lib/node/chunk-ZUY26MIE.cjs +0 -192
- package/dist/lib/node/chunk-ZUY26MIE.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-KVEEO6SV.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-QNHFZM3T.mjs +0 -17
- package/dist/lib/node-esm/chunk-QNHFZM3T.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-UPS353EF.mjs +0 -10
- package/dist/lib/node-esm/chunk-UPS353EF.mjs.map +0 -7
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/client/context.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { type Context, createContext } from 'react';\n\nimport { type Client, type SystemStatus } from '@dxos/client';\n\nexport type ClientContextProps = {\n client: Client;\n status?: SystemStatus | null;\n};\n\n/**\n * @internal Use ClientProvider to create or initialize the Client.\n */\nexport const ClientContext: Context<ClientContextProps | undefined> = createContext<ClientContextProps | undefined>(\n undefined,\n);\n"],
|
|
5
|
-
"mappings": ";AAIA,SAAuBA,qBAAqB;AAYrC,IAAMC,gBAAyDC,cACpEC,MAAAA;",
|
|
6
|
-
"names": ["createContext", "ClientContext", "createContext", "undefined"]
|
|
7
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ClientContext
|
|
3
|
-
} from "./chunk-DXE5O7SV.mjs";
|
|
4
|
-
|
|
5
|
-
// packages/sdk/react-client/src/client/useClient.ts
|
|
6
|
-
import { useContext } from "react";
|
|
7
|
-
import { raise } from "@dxos/debug";
|
|
8
|
-
var useClient = () => {
|
|
9
|
-
const { client } = useContext(ClientContext) ?? raise(new Error("Missing ClientContext."));
|
|
10
|
-
return client;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
export {
|
|
14
|
-
useClient
|
|
15
|
-
};
|
|
16
|
-
//# sourceMappingURL=chunk-KX3DKZQL.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/client/useClient.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from '../client/context';\n\n/**\n * Hook returning instance of DXOS client.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useClient = () => {\n const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n return client;\n};\n"],
|
|
5
|
-
"mappings": ";;;;;AAIA,SAASA,kBAAkB;AAE3B,SAASC,aAAa;AAQf,IAAMC,YAAY,MAAA;AACvB,QAAM,EAAEC,OAAM,IAAKC,WAAWC,aAAAA,KAAkBC,MAAM,IAAIC,MAAM,wBAAA,CAAA;AAChE,SAAOJ;AACT;",
|
|
6
|
-
"names": ["useContext", "raise", "useClient", "client", "useContext", "ClientContext", "raise", "Error"]
|
|
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 { registerSignalsRuntime } from '@dxos/echo-signals/react';\nimport { log } from '@dxos/log';\nimport { useControlledValue } from '@dxos/react-hooks';\nimport { getAsyncProviderValue, type MaybePromise, type Provider } from '@dxos/util';\n\nimport { ClientContext, type ClientContextProps } from './context';\nimport { printBanner } from '../banner';\n\n/**\n * Properties for the ClientProvider.\n */\nexport type ClientProviderProps = 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 * Enable (by default) registration of Preact signals runtime for reactive ECHO objects.\n * @see https://www.npmjs.com/package/@preact/signals-react\n */\n signalsRuntime?: boolean;\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 * @param Client\n */\n onInitialized?: (client: Client) => MaybePromise<void>;\n }>;\n\n/**\n * Root component that provides the DXOS client instance to child components.\n * To be used with the `useClient` hook.\n */\nexport const ClientProvider = forwardRef<Client | undefined, ClientProviderProps>(\n (\n {\n children,\n config: configProvider,\n client: clientProvider,\n services: servicesProvider,\n status: controlledStatus,\n fallback: Fallback = () => null,\n signalsRuntime = true,\n noBanner,\n onInitialized,\n ...options\n },\n forwardedRef,\n ) => {\n useEffect(() => {\n // TODO(wittjosiah): Ideally this should be imported asynchronously because it is optional.\n // Unfortunately, async import seemed to break signals React instrumentation.\n signalsRuntime && registerSignalsRuntime();\n }, []);\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(clientProvider instanceof Client ? clientProvider : undefined);\n\n // Provide external access.\n useImperativeHandle(forwardedRef, () => client, [client]);\n\n // Client status subscription.\n const [status, setStatus] = useControlledValue(controlledStatus);\n useEffect(() => {\n if (!client) {\n return;\n }\n\n const subscription = client.status.subscribe((status) => setStatus(status));\n return () => subscription.unsubscribe();\n }, [client]);\n\n // Create and/or initialize client.\n useEffect(() => {\n const initialize = async (client: Client) => {\n if (!client.initialized) {\n await client.initialize().catch(setError);\n log('client ready');\n await onInitialized?.(client);\n log('initialization complete');\n }\n\n setClient(client);\n\n if (!noBanner) {\n printBanner(client);\n }\n };\n\n let client: Client;\n const t = setTimeout(async () => {\n if (clientProvider) {\n // Asynchronously request client.\n client = await getAsyncProviderValue(clientProvider);\n await initialize(client);\n } else {\n // Asynchronously construct client (config may be undefined).\n const config = await getAsyncProviderValue(configProvider);\n log('resolved config', { config });\n const services = await getAsyncProviderValue(servicesProvider, config);\n log('created services', { services });\n client = new Client({ config, services, ...options });\n log('created client');\n await initialize(client);\n }\n });\n\n return () => {\n log('clean up');\n clearTimeout(t);\n void client\n ?.destroy()\n .then(() => {\n log('destroyed');\n })\n .catch((err) => log.catch(err));\n };\n }, [configProvider, clientProvider, servicesProvider, 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) {\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,8BAA8B;AACvC,SAASC,WAAW;AACpB,SAASC,0BAA0B;AACnC,SAASC,6BAA+D;;;ACXxE,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,eAAe;AACjB;EACF;AAEAA,kBAAgB;AAEhBE,UAAQC,IAAI,KAAKV,OAAOC,MAAAA,CAAAA,IAAW,yBAAA;AACrC;;;;ADgDO,IAAMU,iBAAiBC,2BAC5B,CACE,EACEC,UACAC,QAAQC,gBACRC,QAAQC,gBACRC,UAAUC,kBACVC,QAAQC,kBACRC,UAAUC,WAAW,MAAM,MAC3BC,iBAAiB,MACjBC,UACAC,eACA,GAAGC,QAAAA,GAELC,iBAAAA;AAEAC,YAAU,MAAA;AAGRL,sBAAkBM,uBAAAA;EACpB,GAAG,CAAA,CAAE;AAOL,QAAM,CAACC,OAAOC,QAAAA,IAAYC,SAAAA;AAC1B,MAAIF,OAAO;AACT,UAAMA;EACR;AAEA,QAA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,MAAA;AACL8B,UAAI,YAAA,QAAA;;;;;;AACJK,mBAAaH,CAAAA;AACb,WAAKhC,SACDoC,QAAAA,EACDC,KAAK,MAAA;AACJP,YAAI,aAAA,QAAA;;;;;;MACN,CAAA,EACCD,MAAM,CAACS,QAAQR,IAAID,MAAMS,KAAAA,QAAAA;;;;;;IAC9B;EACF,GAAG;IAACvC;IAAgBE;IAAgBE;IAAkBM;GAAS;AAE/D,MAAI,CAACT,QAAQ4B,eAAexB,WAAWmC,aAAaC,QAAQ;AAC1D,WAAO,sBAAA,cAACjC,UAAAA;MAASP;MAAgBI;;EACnC;AAEA,SAAO,sBAAA,cAACqC,cAAcC,UAAQ;IAACC,OAAO;MAAE3C;MAAQI;IAAO;KAAIP,QAAAA;AAC7D,CAAA;",
|
|
6
|
-
"names": ["React", "forwardRef", "useEffect", "useImperativeHandle", "useState", "Client", "SystemStatus", "registerSignalsRuntime", "log", "useControlledValue", "getAsyncProviderValue", "BANNER", "client", "commitHash", "config", "get", "hash", "version", "bannerPrinted", "printBanner", "console", "log", "ClientProvider", "forwardRef", "children", "config", "configProvider", "client", "clientProvider", "services", "servicesProvider", "status", "controlledStatus", "fallback", "Fallback", "signalsRuntime", "noBanner", "onInitialized", "options", "forwardedRef", "useEffect", "registerSignalsRuntime", "error", "setError", "useState", "setClient", "Client", "undefined", "useImperativeHandle", "setStatus", "useControlledValue", "subscription", "subscribe", "unsubscribe", "initialize", "initialized", "catch", "log", "printBanner", "t", "setTimeout", "getAsyncProviderValue", "clearTimeout", "destroy", "then", "err", "SystemStatus", "ACTIVE", "ClientContext", "Provider", "value"]
|
|
7
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var chunk_DVAPCZTK_exports = {};
|
|
20
|
-
__export(chunk_DVAPCZTK_exports, {
|
|
21
|
-
useClient: () => useClient
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(chunk_DVAPCZTK_exports);
|
|
24
|
-
var import_chunk_VIZOXSRY = require("./chunk-VIZOXSRY.cjs");
|
|
25
|
-
var import_react = require("react");
|
|
26
|
-
var import_debug = require("@dxos/debug");
|
|
27
|
-
var useClient = () => {
|
|
28
|
-
const { client } = (0, import_react.useContext)(import_chunk_VIZOXSRY.ClientContext) ?? (0, import_debug.raise)(new Error("Missing ClientContext."));
|
|
29
|
-
return client;
|
|
30
|
-
};
|
|
31
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
32
|
-
0 && (module.exports = {
|
|
33
|
-
useClient
|
|
34
|
-
});
|
|
35
|
-
//# sourceMappingURL=chunk-DVAPCZTK.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/client/useClient.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from '../client/context';\n\n/**\n * Hook returning instance of DXOS client.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useClient = () => {\n const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n return client;\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAIA,mBAA2B;AAE3B,mBAAsB;AAQf,IAAMA,YAAY,MAAA;AACvB,QAAM,EAAEC,OAAM,QAAKC,yBAAWC,mCAAAA,SAAkBC,oBAAM,IAAIC,MAAM,wBAAA,CAAA;AAChE,SAAOJ;AACT;",
|
|
6
|
-
"names": ["useClient", "client", "useContext", "ClientContext", "raise", "Error"]
|
|
7
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var chunk_VIZOXSRY_exports = {};
|
|
20
|
-
__export(chunk_VIZOXSRY_exports, {
|
|
21
|
-
ClientContext: () => ClientContext
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(chunk_VIZOXSRY_exports);
|
|
24
|
-
var import_react = require("react");
|
|
25
|
-
var ClientContext = (0, import_react.createContext)(void 0);
|
|
26
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
27
|
-
0 && (module.exports = {
|
|
28
|
-
ClientContext
|
|
29
|
-
});
|
|
30
|
-
//# sourceMappingURL=chunk-VIZOXSRY.cjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/client/context.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { type Context, createContext } from 'react';\n\nimport { type Client, type SystemStatus } from '@dxos/client';\n\nexport type ClientContextProps = {\n client: Client;\n status?: SystemStatus | null;\n};\n\n/**\n * @internal Use ClientProvider to create or initialize the Client.\n */\nexport const ClientContext: Context<ClientContextProps | undefined> = createContext<ClientContextProps | undefined>(\n undefined,\n);\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;AAIA,mBAA4C;AAYrC,IAAMA,oBAAyDC,4BACpEC,MAAAA;",
|
|
6
|
-
"names": ["ClientContext", "createContext", "undefined"]
|
|
7
|
-
}
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var chunk_ZUY26MIE_exports = {};
|
|
30
|
-
__export(chunk_ZUY26MIE_exports, {
|
|
31
|
-
ClientProvider: () => ClientProvider
|
|
32
|
-
});
|
|
33
|
-
module.exports = __toCommonJS(chunk_ZUY26MIE_exports);
|
|
34
|
-
var import_chunk_VIZOXSRY = require("./chunk-VIZOXSRY.cjs");
|
|
35
|
-
var import_react = __toESM(require("react"));
|
|
36
|
-
var import_client = require("@dxos/client");
|
|
37
|
-
var import_react2 = require("@dxos/echo-signals/react");
|
|
38
|
-
var import_log = require("@dxos/log");
|
|
39
|
-
var import_react_hooks = require("@dxos/react-hooks");
|
|
40
|
-
var import_util = require("@dxos/util");
|
|
41
|
-
var BANNER = (client) => {
|
|
42
|
-
const commitHash = client.config.get("runtime.app.build.commitHash");
|
|
43
|
-
const hash = commitHash ? ` App Commit ${commitHash}
|
|
44
|
-
` : "";
|
|
45
|
-
return `
|
|
46
|
-
_/\\/\\/\\/\\/\\____/\\/\\____/\\/\\____/\\/\\/\\/\\______/\\/\\/\\/\\/\\_
|
|
47
|
-
_/\\/\\____/\\/\\____/\\/\\/\\/\\____/\\/\\____/\\/\\__/\\/\\_________
|
|
48
|
-
_/\\/\\____/\\/\\______/\\/\\______/\\/\\____/\\/\\____/\\/\\/\\/\\___
|
|
49
|
-
_/\\/\\____/\\/\\____/\\/\\/\\/\\____/\\/\\____/\\/\\__________/\\/\\_
|
|
50
|
-
_/\\/\\/\\/\\/\\____/\\/\\____/\\/\\____/\\/\\/\\/\\____/\\/\\/\\/\\/\\___
|
|
51
|
-
|
|
52
|
-
DXOS Client ${client.version}
|
|
53
|
-
${hash}`;
|
|
54
|
-
};
|
|
55
|
-
var bannerPrinted = false;
|
|
56
|
-
var printBanner = (client) => {
|
|
57
|
-
if (bannerPrinted) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
bannerPrinted = true;
|
|
61
|
-
console.log(`%c${BANNER(client)}`, "font-family: monospace;");
|
|
62
|
-
};
|
|
63
|
-
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/sdk/react-client/src/client/ClientProvider.tsx";
|
|
64
|
-
var ClientProvider = /* @__PURE__ */ (0, import_react.forwardRef)(({ children, config: configProvider, client: clientProvider, services: servicesProvider, status: controlledStatus, fallback: Fallback = () => null, signalsRuntime = true, noBanner, onInitialized, ...options }, forwardedRef) => {
|
|
65
|
-
(0, import_react.useEffect)(() => {
|
|
66
|
-
signalsRuntime && (0, import_react2.registerSignalsRuntime)();
|
|
67
|
-
}, []);
|
|
68
|
-
const [error, setError] = (0, import_react.useState)();
|
|
69
|
-
if (error) {
|
|
70
|
-
throw error;
|
|
71
|
-
}
|
|
72
|
-
const [client, setClient] = (0, import_react.useState)(clientProvider instanceof import_client.Client ? clientProvider : void 0);
|
|
73
|
-
(0, import_react.useImperativeHandle)(forwardedRef, () => client, [
|
|
74
|
-
client
|
|
75
|
-
]);
|
|
76
|
-
const [status, setStatus] = (0, import_react_hooks.useControlledValue)(controlledStatus);
|
|
77
|
-
(0, import_react.useEffect)(() => {
|
|
78
|
-
if (!client) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const subscription = client.status.subscribe((status2) => setStatus(status2));
|
|
82
|
-
return () => subscription.unsubscribe();
|
|
83
|
-
}, [
|
|
84
|
-
client
|
|
85
|
-
]);
|
|
86
|
-
(0, import_react.useEffect)(() => {
|
|
87
|
-
const initialize = async (client3) => {
|
|
88
|
-
if (!client3.initialized) {
|
|
89
|
-
await client3.initialize().catch(setError);
|
|
90
|
-
(0, import_log.log)("client ready", void 0, {
|
|
91
|
-
F: __dxlog_file,
|
|
92
|
-
L: 134,
|
|
93
|
-
S: void 0,
|
|
94
|
-
C: (f, a) => f(...a)
|
|
95
|
-
});
|
|
96
|
-
await onInitialized?.(client3);
|
|
97
|
-
(0, import_log.log)("initialization complete", void 0, {
|
|
98
|
-
F: __dxlog_file,
|
|
99
|
-
L: 136,
|
|
100
|
-
S: void 0,
|
|
101
|
-
C: (f, a) => f(...a)
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
setClient(client3);
|
|
105
|
-
if (!noBanner) {
|
|
106
|
-
printBanner(client3);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
let client2;
|
|
110
|
-
const t = setTimeout(async () => {
|
|
111
|
-
if (clientProvider) {
|
|
112
|
-
client2 = await (0, import_util.getAsyncProviderValue)(clientProvider);
|
|
113
|
-
await initialize(client2);
|
|
114
|
-
} else {
|
|
115
|
-
const config = await (0, import_util.getAsyncProviderValue)(configProvider);
|
|
116
|
-
(0, import_log.log)("resolved config", {
|
|
117
|
-
config
|
|
118
|
-
}, {
|
|
119
|
-
F: __dxlog_file,
|
|
120
|
-
L: 155,
|
|
121
|
-
S: void 0,
|
|
122
|
-
C: (f, a) => f(...a)
|
|
123
|
-
});
|
|
124
|
-
const services = await (0, import_util.getAsyncProviderValue)(servicesProvider, config);
|
|
125
|
-
(0, import_log.log)("created services", {
|
|
126
|
-
services
|
|
127
|
-
}, {
|
|
128
|
-
F: __dxlog_file,
|
|
129
|
-
L: 157,
|
|
130
|
-
S: void 0,
|
|
131
|
-
C: (f, a) => f(...a)
|
|
132
|
-
});
|
|
133
|
-
client2 = new import_client.Client({
|
|
134
|
-
config,
|
|
135
|
-
services,
|
|
136
|
-
...options
|
|
137
|
-
});
|
|
138
|
-
(0, import_log.log)("created client", void 0, {
|
|
139
|
-
F: __dxlog_file,
|
|
140
|
-
L: 159,
|
|
141
|
-
S: void 0,
|
|
142
|
-
C: (f, a) => f(...a)
|
|
143
|
-
});
|
|
144
|
-
await initialize(client2);
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
return () => {
|
|
148
|
-
(0, import_log.log)("clean up", void 0, {
|
|
149
|
-
F: __dxlog_file,
|
|
150
|
-
L: 165,
|
|
151
|
-
S: void 0,
|
|
152
|
-
C: (f, a) => f(...a)
|
|
153
|
-
});
|
|
154
|
-
clearTimeout(t);
|
|
155
|
-
void client2?.destroy().then(() => {
|
|
156
|
-
(0, import_log.log)("destroyed", void 0, {
|
|
157
|
-
F: __dxlog_file,
|
|
158
|
-
L: 170,
|
|
159
|
-
S: void 0,
|
|
160
|
-
C: (f, a) => f(...a)
|
|
161
|
-
});
|
|
162
|
-
}).catch((err) => import_log.log.catch(err, void 0, {
|
|
163
|
-
F: __dxlog_file,
|
|
164
|
-
L: 172,
|
|
165
|
-
S: void 0,
|
|
166
|
-
C: (f, a) => f(...a)
|
|
167
|
-
}));
|
|
168
|
-
};
|
|
169
|
-
}, [
|
|
170
|
-
configProvider,
|
|
171
|
-
clientProvider,
|
|
172
|
-
servicesProvider,
|
|
173
|
-
noBanner
|
|
174
|
-
]);
|
|
175
|
-
if (!client?.initialized || status !== import_client.SystemStatus.ACTIVE) {
|
|
176
|
-
return /* @__PURE__ */ import_react.default.createElement(Fallback, {
|
|
177
|
-
client,
|
|
178
|
-
status
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
return /* @__PURE__ */ import_react.default.createElement(import_chunk_VIZOXSRY.ClientContext.Provider, {
|
|
182
|
-
value: {
|
|
183
|
-
client,
|
|
184
|
-
status
|
|
185
|
-
}
|
|
186
|
-
}, children);
|
|
187
|
-
});
|
|
188
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
189
|
-
0 && (module.exports = {
|
|
190
|
-
ClientProvider
|
|
191
|
-
});
|
|
192
|
-
//# sourceMappingURL=chunk-ZUY26MIE.cjs.map
|
|
@@ -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 { registerSignalsRuntime } from '@dxos/echo-signals/react';\nimport { log } from '@dxos/log';\nimport { useControlledValue } from '@dxos/react-hooks';\nimport { getAsyncProviderValue, type MaybePromise, type Provider } from '@dxos/util';\n\nimport { ClientContext, type ClientContextProps } from './context';\nimport { printBanner } from '../banner';\n\n/**\n * Properties for the ClientProvider.\n */\nexport type ClientProviderProps = 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 * Enable (by default) registration of Preact signals runtime for reactive ECHO objects.\n * @see https://www.npmjs.com/package/@preact/signals-react\n */\n signalsRuntime?: boolean;\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 * @param Client\n */\n onInitialized?: (client: Client) => MaybePromise<void>;\n }>;\n\n/**\n * Root component that provides the DXOS client instance to child components.\n * To be used with the `useClient` hook.\n */\nexport const ClientProvider = forwardRef<Client | undefined, ClientProviderProps>(\n (\n {\n children,\n config: configProvider,\n client: clientProvider,\n services: servicesProvider,\n status: controlledStatus,\n fallback: Fallback = () => null,\n signalsRuntime = true,\n noBanner,\n onInitialized,\n ...options\n },\n forwardedRef,\n ) => {\n useEffect(() => {\n // TODO(wittjosiah): Ideally this should be imported asynchronously because it is optional.\n // Unfortunately, async import seemed to break signals React instrumentation.\n signalsRuntime && registerSignalsRuntime();\n }, []);\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(clientProvider instanceof Client ? clientProvider : undefined);\n\n // Provide external access.\n useImperativeHandle(forwardedRef, () => client, [client]);\n\n // Client status subscription.\n const [status, setStatus] = useControlledValue(controlledStatus);\n useEffect(() => {\n if (!client) {\n return;\n }\n\n const subscription = client.status.subscribe((status) => setStatus(status));\n return () => subscription.unsubscribe();\n }, [client]);\n\n // Create and/or initialize client.\n useEffect(() => {\n const initialize = async (client: Client) => {\n if (!client.initialized) {\n await client.initialize().catch(setError);\n log('client ready');\n await onInitialized?.(client);\n log('initialization complete');\n }\n\n setClient(client);\n\n if (!noBanner) {\n printBanner(client);\n }\n };\n\n let client: Client;\n const t = setTimeout(async () => {\n if (clientProvider) {\n // Asynchronously request client.\n client = await getAsyncProviderValue(clientProvider);\n await initialize(client);\n } else {\n // Asynchronously construct client (config may be undefined).\n const config = await getAsyncProviderValue(configProvider);\n log('resolved config', { config });\n const services = await getAsyncProviderValue(servicesProvider, config);\n log('created services', { services });\n client = new Client({ config, services, ...options });\n log('created client');\n await initialize(client);\n }\n });\n\n return () => {\n log('clean up');\n clearTimeout(t);\n void client\n ?.destroy()\n .then(() => {\n log('destroyed');\n })\n .catch((err) => log.catch(err));\n };\n }, [configProvider, clientProvider, servicesProvider, 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) {\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,mBAOO;AAEP,oBAAsF;AAEtF,IAAAA,gBAAuC;AACvC,iBAAoB;AACpB,yBAAmC;AACnC,kBAAwE;ACXxE,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,eAAe;AACjB;EACF;AAEAA,kBAAgB;AAEhBE,UAAQC,IAAI,KAAKV,OAAOC,MAAAA,CAAAA,IAAW,yBAAA;AACrC;;ADgDO,IAAMU,iBAAiBC,6CAC5B,CACE,EACEC,UACAV,QAAQW,gBACRb,QAAQc,gBACRC,UAAUC,kBACVC,QAAQC,kBACRC,UAAUC,WAAW,MAAM,MAC3BC,iBAAiB,MACjBC,UACAC,eACA,GAAGC,QAAAA,GAELC,iBAAAA;AAEAC,8BAAU,MAAA;AAGRL,0BAAkBM,sCAAAA;EACpB,GAAG,CAAA,CAAE;AAOL,QAAM,CAACC,OAAOC,QAAAA,QAAYC,uBAAAA;AAC1B,MAAIF,OAAO;AACT,UAAMA;EACR;AAEA,QAAM,CAAC5B,QAAQ+B,SAAAA,QAAaD,uBAAShB,0BAA0BkB,uBAASlB,iBAAiBmB,MAAAA;AAGzFC,wCAAoBT,cAAc,MAAMzB,QAAQ;IAACA;GAAO;AAGxD,QAAM,CAACiB,QAAQkB,SAAAA,QAAaC,uCAAmBlB,gBAAAA;A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O,KAAAA,QAAAA;;;;;;IAC9B;EACF,GAAG;IAACpC;IAAgBC;IAAgBE;IAAkBM;GAAS;AAE/D,MAAI,CAACtB,QAAQyC,eAAexB,WAAWiC,2BAAaC,QAAQ;AAC1D,WAAO,6BAAAC,QAAA,cAAChC,UAAAA;MAASpB;MAAgBiB;;EACnC;AAEA,SAAO,6BAAAmC,QAAA,cAACC,oCAAcC,UAAQ;IAACC,OAAO;MAAEvD;MAAQiB;IAAO;KAAIL,QAAAA;AAC7D,CAAA;",
|
|
6
|
-
"names": ["import_react", "BANNER", "client", "commitHash", "config", "get", "hash", "version", "bannerPrinted", "printBanner", "console", "log", "ClientProvider", "forwardRef", "children", "configProvider", "clientProvider", "services", "servicesProvider", "status", "controlledStatus", "fallback", "Fallback", "signalsRuntime", "noBanner", "onInitialized", "options", "forwardedRef", "useEffect", "registerSignalsRuntime", "error", "setError", "useState", "setClient", "Client", "undefined", "useImperativeHandle", "setStatus", "useControlledValue", "subscription", "subscribe", "unsubscribe", "initialize", "initialized", "catch", "t", "setTimeout", "getAsyncProviderValue", "clearTimeout", "destroy", "then", "err", "SystemStatus", "ACTIVE", "React", "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 { registerSignalsRuntime } from '@dxos/echo-signals/react';\nimport { log } from '@dxos/log';\nimport { useControlledValue } from '@dxos/react-hooks';\nimport { getAsyncProviderValue, type MaybePromise, type Provider } from '@dxos/util';\n\nimport { ClientContext, type ClientContextProps } from './context';\nimport { printBanner } from '../banner';\n\n/**\n * Properties for the ClientProvider.\n */\nexport type ClientProviderProps = 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 * Enable (by default) registration of Preact signals runtime for reactive ECHO objects.\n * @see https://www.npmjs.com/package/@preact/signals-react\n */\n signalsRuntime?: boolean;\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 * @param Client\n */\n onInitialized?: (client: Client) => MaybePromise<void>;\n }>;\n\n/**\n * Root component that provides the DXOS client instance to child components.\n * To be used with the `useClient` hook.\n */\nexport const ClientProvider = forwardRef<Client | undefined, ClientProviderProps>(\n (\n {\n children,\n config: configProvider,\n client: clientProvider,\n services: servicesProvider,\n status: controlledStatus,\n fallback: Fallback = () => null,\n signalsRuntime = true,\n noBanner,\n onInitialized,\n ...options\n },\n forwardedRef,\n ) => {\n useEffect(() => {\n // TODO(wittjosiah): Ideally this should be imported asynchronously because it is optional.\n // Unfortunately, async import seemed to break signals React instrumentation.\n signalsRuntime && registerSignalsRuntime();\n }, []);\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(clientProvider instanceof Client ? clientProvider : undefined);\n\n // Provide external access.\n useImperativeHandle(forwardedRef, () => client, [client]);\n\n // Client status subscription.\n const [status, setStatus] = useControlledValue(controlledStatus);\n useEffect(() => {\n if (!client) {\n return;\n }\n\n const subscription = client.status.subscribe((status) => setStatus(status));\n return () => subscription.unsubscribe();\n }, [client]);\n\n // Create and/or initialize client.\n useEffect(() => {\n const initialize = async (client: Client) => {\n if (!client.initialized) {\n await client.initialize().catch(setError);\n log('client ready');\n await onInitialized?.(client);\n log('initialization complete');\n }\n\n setClient(client);\n\n if (!noBanner) {\n printBanner(client);\n }\n };\n\n let client: Client;\n const t = setTimeout(async () => {\n if (clientProvider) {\n // Asynchronously request client.\n client = await getAsyncProviderValue(clientProvider);\n await initialize(client);\n } else {\n // Asynchronously construct client (config may be undefined).\n const config = await getAsyncProviderValue(configProvider);\n log('resolved config', { config });\n const services = await getAsyncProviderValue(servicesProvider, config);\n log('created services', { services });\n client = new Client({ config, services, ...options });\n log('created client');\n await initialize(client);\n }\n });\n\n return () => {\n log('clean up');\n clearTimeout(t);\n void client\n ?.destroy()\n .then(() => {\n log('destroyed');\n })\n .catch((err) => log.catch(err));\n };\n }, [configProvider, clientProvider, servicesProvider, 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) {\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,8BAA8B;AACvC,SAASC,WAAW;AACpB,SAASC,0BAA0B;AACnC,SAASC,6BAA+D;;;ACXxE,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,eAAe;AACjB;EACF;AAEAA,kBAAgB;AAEhBE,UAAQC,IAAI,KAAKV,OAAOC,MAAAA,CAAAA,IAAW,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O;AAEL,cAAMF,SAAS,MAAMoC,sBAAsBnC,cAAAA;AAC3C+B,YAAI,mBAAmB;UAAEhC;QAAO,GAAA;;;;;;AAChC,cAAMI,WAAW,MAAMgC,sBAAsB/B,kBAAkBL,MAAAA;AAC/DgC,YAAI,oBAAoB;UAAE5B;QAAS,GAAA;;;;;;AACnCF,QAAAA,UAAS,IAAImB,OAAO;UAAErB;UAAQI;UAAU,GAAGS;QAAQ,CAAA;AACnDmB,YAAI,kBAAA,QAAA;;;;;;AACJ,cAAMH,WAAW3B,OAAAA;MACnB;IACF,CAAA;AAEA,WAAO,MAAA;AACL8B,UAAI,YAAA,QAAA;;;;;;AACJK,mBAAaH,CAAAA;AACb,WAAKhC,SACDoC,QAAAA,EACDC,KAAK,MAAA;AACJP,YAAI,aAAA,QAAA;;;;;;MACN,CAAA,EACCD,MAAM,CAACS,QAAQR,IAAID,MAAMS,KAAAA,QAAAA;;;;;;IAC9B;EACF,GAAG;IAACvC;IAAgBE;IAAgBE;IAAkBM;GAAS;AAE/D,MAAI,CAACT,QAAQ4B,eAAexB,WAAWmC,aAAaC,QAAQ;AAC1D,WAAO,sBAAA,cAACjC,UAAAA;MAASP;MAAgBI;;EACnC;AAEA,SAAO,sBAAA,cAACqC,cAAcC,UAAQ;IAACC,OAAO;MAAE3C;MAAQI;IAAO;KAAIP,QAAAA;AAC7D,CAAA;",
|
|
6
|
-
"names": ["React", "forwardRef", "useEffect", "useImperativeHandle", "useState", "Client", "SystemStatus", "registerSignalsRuntime", "log", "useControlledValue", "getAsyncProviderValue", "BANNER", "client", "commitHash", "config", "get", "hash", "version", "bannerPrinted", "printBanner", "console", "log", "ClientProvider", "forwardRef", "children", "config", "configProvider", "client", "clientProvider", "services", "servicesProvider", "status", "controlledStatus", "fallback", "Fallback", "signalsRuntime", "noBanner", "onInitialized", "options", "forwardedRef", "useEffect", "registerSignalsRuntime", "error", "setError", "useState", "setClient", "Client", "undefined", "useImperativeHandle", "setStatus", "useControlledValue", "subscription", "subscribe", "unsubscribe", "initialize", "initialized", "catch", "log", "printBanner", "t", "setTimeout", "getAsyncProviderValue", "clearTimeout", "destroy", "then", "err", "SystemStatus", "ACTIVE", "ClientContext", "Provider", "value"]
|
|
7
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
import {
|
|
3
|
-
ClientContext
|
|
4
|
-
} from "./chunk-UPS353EF.mjs";
|
|
5
|
-
|
|
6
|
-
// packages/sdk/react-client/src/client/useClient.ts
|
|
7
|
-
import { useContext } from "react";
|
|
8
|
-
import { raise } from "@dxos/debug";
|
|
9
|
-
var useClient = () => {
|
|
10
|
-
const { client } = useContext(ClientContext) ?? raise(new Error("Missing ClientContext."));
|
|
11
|
-
return client;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
export {
|
|
15
|
-
useClient
|
|
16
|
-
};
|
|
17
|
-
//# sourceMappingURL=chunk-QNHFZM3T.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/client/useClient.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { useContext } from 'react';\n\nimport { raise } from '@dxos/debug';\n\nimport { ClientContext } from '../client/context';\n\n/**\n * Hook returning instance of DXOS client.\n * Requires ClientContext to be set via ClientProvider.\n */\nexport const useClient = () => {\n const { client } = useContext(ClientContext) ?? raise(new Error('Missing ClientContext.'));\n return client;\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;AAIA,SAASA,kBAAkB;AAE3B,SAASC,aAAa;AAQf,IAAMC,YAAY,MAAA;AACvB,QAAM,EAAEC,OAAM,IAAKC,WAAWC,aAAAA,KAAkBC,MAAM,IAAIC,MAAM,wBAAA,CAAA;AAChE,SAAOJ;AACT;",
|
|
6
|
-
"names": ["useContext", "raise", "useClient", "client", "useContext", "ClientContext", "raise", "Error"]
|
|
7
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
|
-
|
|
3
|
-
// packages/sdk/react-client/src/client/context.ts
|
|
4
|
-
import { createContext } from "react";
|
|
5
|
-
var ClientContext = createContext(void 0);
|
|
6
|
-
|
|
7
|
-
export {
|
|
8
|
-
ClientContext
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=chunk-UPS353EF.mjs.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/client/context.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nimport { type Context, createContext } from 'react';\n\nimport { type Client, type SystemStatus } from '@dxos/client';\n\nexport type ClientContextProps = {\n client: Client;\n status?: SystemStatus | null;\n};\n\n/**\n * @internal Use ClientProvider to create or initialize the Client.\n */\nexport const ClientContext: Context<ClientContextProps | undefined> = createContext<ClientContextProps | undefined>(\n undefined,\n);\n"],
|
|
5
|
-
"mappings": ";;;AAIA,SAAuBA,qBAAqB;AAYrC,IAAMC,gBAAyDC,cACpEC,MAAAA;",
|
|
6
|
-
"names": ["createContext", "ClientContext", "createContext", "undefined"]
|
|
7
|
-
}
|