@dxos/react-client 2.18.0 → 2.19.0
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/.rush/temp/package-deps_build:test.json +23 -25
- package/.rush/temp/shrinkwrap-deps.json +56 -2
- package/README.md +6 -6
- package/dist/src/containers/ClientProvider.d.ts +29 -5
- package/dist/src/containers/ClientProvider.d.ts.map +1 -1
- package/dist/src/containers/ClientProvider.js +45 -4
- package/dist/src/containers/ClientProvider.js.map +1 -1
- package/dist/src/containers/ClientProvider.test.js +0 -2
- package/dist/src/containers/ClientProvider.test.js.map +1 -1
- package/dist/src/containers/index.d.ts +0 -2
- package/dist/src/containers/index.d.ts.map +1 -1
- package/dist/src/containers/index.js +0 -2
- package/dist/src/containers/index.js.map +1 -1
- package/dist/src/hooks/client/context.d.ts +5 -1
- package/dist/src/hooks/client/context.d.ts.map +1 -1
- package/dist/src/hooks/client/context.js.map +1 -1
- package/dist/src/hooks/client/useClient.d.ts +1 -1
- package/dist/src/hooks/client/useClient.d.ts.map +1 -1
- package/dist/src/hooks/client/useClient.js +3 -2
- package/dist/src/hooks/client/useClient.js.map +1 -1
- package/dist/src/hooks/client/useConfig.d.ts +2 -2
- package/dist/src/hooks/client/useConfig.d.ts.map +1 -1
- package/dist/src/hooks/client/useConfig.js +3 -3
- package/dist/src/hooks/client/useConfig.js.map +1 -1
- package/dist/src/hooks/client/useProfile.d.ts +2 -2
- package/dist/src/hooks/client/useProfile.d.ts.map +1 -1
- package/dist/src/hooks/client/useProfile.js +1 -1
- package/dist/src/hooks/echo-queries/useContacts.d.ts +1 -1
- package/dist/src/hooks/echo-queries/useContacts.js +2 -2
- package/dist/src/hooks/echo-queries/useContacts.js.map +1 -1
- package/dist/src/hooks/echo-queries/useMembers.d.ts +3 -2
- package/dist/src/hooks/echo-queries/useMembers.d.ts.map +1 -1
- package/dist/src/hooks/echo-queries/useMembers.js.map +1 -1
- package/dist/src/hooks/echo-queries/useParties.d.ts +6 -6
- package/dist/src/hooks/echo-queries/useParties.d.ts.map +1 -1
- package/dist/src/hooks/echo-queries/useParties.js +2 -2
- package/dist/src/hooks/echo-queries/useParties.js.map +1 -1
- package/dist/src/hooks/echo-queries/useRemoteParties.d.ts +3 -4
- package/dist/src/hooks/echo-queries/useRemoteParties.d.ts.map +1 -1
- package/dist/src/hooks/echo-queries/useRemoteParties.js +1 -1
- package/dist/src/hooks/echo-queries/useRemoteParties.js.map +1 -1
- package/dist/src/index.d.ts +1 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -2
- package/dist/src/index.js.map +1 -1
- package/dist/src/{containers → testing}/ProfileInitializer.d.ts +0 -0
- package/dist/src/testing/ProfileInitializer.d.ts.map +1 -0
- package/dist/src/{containers → testing}/ProfileInitializer.js +4 -2
- package/dist/src/testing/ProfileInitializer.js.map +1 -0
- package/dist/src/testing/index.d.ts +2 -0
- package/dist/src/testing/index.d.ts.map +1 -0
- package/dist/src/{components → testing}/index.js +1 -1
- package/dist/src/testing/index.js.map +1 -0
- package/dist/stories/client.stories.d.ts +1 -0
- package/dist/stories/client.stories.d.ts.map +1 -1
- package/dist/stories/client.stories.js +9 -6
- package/dist/stories/client.stories.js.map +1 -1
- package/dist/stories/halo-invitations.stories.js +3 -3
- package/dist/stories/halo-invitations.stories.js.map +1 -1
- package/dist/stories/helpers/ClientPanel.d.ts +2 -3
- package/dist/stories/helpers/ClientPanel.d.ts.map +1 -1
- package/dist/stories/helpers/ClientPanel.js +1 -5
- package/dist/stories/helpers/ClientPanel.js.map +1 -1
- package/dist/stories/party-invitations.stories.js +3 -3
- package/dist/stories/party-invitations.stories.js.map +1 -1
- package/dist/tests/config.test.js +1 -1
- package/dist/tests/config.test.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/esbuild-server.config.js +21 -0
- package/package.json +14 -10
- package/react-client.build.log +6 -6
- package/src/containers/ClientProvider.test.tsx +0 -2
- package/src/containers/ClientProvider.tsx +86 -7
- package/src/containers/index.ts +0 -2
- package/src/hooks/client/context.ts +5 -1
- package/src/hooks/client/useClient.ts +3 -2
- package/src/hooks/client/useConfig.ts +3 -3
- package/src/hooks/client/useProfile.ts +1 -1
- package/src/hooks/echo-queries/useContacts.ts +2 -2
- package/src/hooks/echo-queries/useMembers.tsx +3 -2
- package/src/hooks/echo-queries/useParties.ts +6 -6
- package/src/hooks/echo-queries/useRemoteParties.ts +4 -2
- package/src/index.ts +1 -2
- package/src/{containers → testing}/ProfileInitializer.tsx +4 -2
- package/src/testing/index.ts +5 -0
- package/stories/client.stories.tsx +14 -10
- package/stories/halo-invitations.stories.tsx +6 -6
- package/stories/helpers/ClientPanel.tsx +3 -8
- package/stories/party-invitations.stories.tsx +5 -5
- package/tests/config.test.ts +1 -1
- package/dist/src/components/ErrorBoundary.d.ts +0 -52
- package/dist/src/components/ErrorBoundary.d.ts.map +0 -1
- package/dist/src/components/ErrorBoundary.js +0 -78
- package/dist/src/components/ErrorBoundary.js.map +0 -1
- package/dist/src/components/index.d.ts +0 -2
- package/dist/src/components/index.d.ts.map +0 -1
- package/dist/src/components/index.js.map +0 -1
- package/dist/src/config.d.ts +0 -8
- package/dist/src/config.d.ts.map +0 -1
- package/dist/src/config.js +0 -11
- package/dist/src/config.js.map +0 -1
- package/dist/src/containers/ClientInitializer.d.ts +0 -30
- package/dist/src/containers/ClientInitializer.d.ts.map +0 -1
- package/dist/src/containers/ClientInitializer.js +0 -82
- package/dist/src/containers/ClientInitializer.js.map +0 -1
- package/dist/src/containers/ProfileInitializer.d.ts.map +0 -1
- package/dist/src/containers/ProfileInitializer.js.map +0 -1
- package/src/components/ErrorBoundary.tsx +0 -96
- package/src/components/index.ts +0 -5
- package/src/config.ts +0 -15
- package/src/containers/ClientInitializer.tsx +0 -121
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// Copyright 2020 DXOS.org
|
|
4
|
-
//
|
|
5
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
8
|
-
}) : (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
o[k2] = m[k];
|
|
11
|
-
}));
|
|
12
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
-
}) : function(o, v) {
|
|
15
|
-
o["default"] = v;
|
|
16
|
-
});
|
|
17
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
-
if (mod && mod.__esModule) return mod;
|
|
19
|
-
var result = {};
|
|
20
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
-
__setModuleDefault(result, mod);
|
|
22
|
-
return result;
|
|
23
|
-
};
|
|
24
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
25
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
26
|
-
};
|
|
27
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
-
exports.ErrorBoundary = void 0;
|
|
29
|
-
const debug_1 = __importDefault(require("debug"));
|
|
30
|
-
const react_1 = __importStar(require("react"));
|
|
31
|
-
const log = (0, debug_1.default)('dxos:react-client:error');
|
|
32
|
-
/**
|
|
33
|
-
* Top-level error boundary.
|
|
34
|
-
* NOTE: Doesn't catch exceptions in event handlers, or asynchronous callbacks.
|
|
35
|
-
* A global error handler should be configured for such errors.
|
|
36
|
-
* https://reactjs.org/docs/error-boundaries.html#how-about-event-handlers
|
|
37
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror
|
|
38
|
-
* It DOES catch exceptions in hooks and any components that return malformed React compoennts.
|
|
39
|
-
*/
|
|
40
|
-
class ErrorBoundary extends react_1.Component {
|
|
41
|
-
constructor() {
|
|
42
|
-
super(...arguments);
|
|
43
|
-
this.state = {
|
|
44
|
-
error: null
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
static getDerivedStateFromError(error) {
|
|
48
|
-
return { error };
|
|
49
|
-
}
|
|
50
|
-
componentDidCatch(error, errorInfo) {
|
|
51
|
-
const { onError } = this.props;
|
|
52
|
-
onError(error, errorInfo);
|
|
53
|
-
}
|
|
54
|
-
render() {
|
|
55
|
-
const { children, onRestart, onReset, errorComponent: ErrorComponent } = this.props;
|
|
56
|
-
const { error } = this.state;
|
|
57
|
-
if (error) {
|
|
58
|
-
if (ErrorComponent) {
|
|
59
|
-
return (react_1.default.createElement(ErrorComponent, { onRestart: onRestart, onReset: onReset, error: error }));
|
|
60
|
-
}
|
|
61
|
-
log('ErrorComponent not set.');
|
|
62
|
-
return (react_1.default.createElement("div", { style: { border: '1px solid #CCC', padding: 16 } },
|
|
63
|
-
react_1.default.createElement("h1", null, "ErrorBoundary component not set."),
|
|
64
|
-
react_1.default.createElement("pre", { style: { whiteSpace: 'break-spaces' } }, String(error))));
|
|
65
|
-
}
|
|
66
|
-
return children;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
exports.ErrorBoundary = ErrorBoundary;
|
|
70
|
-
ErrorBoundary.defaultProps = {
|
|
71
|
-
onError: console.warn,
|
|
72
|
-
onRestart: () => {
|
|
73
|
-
window.location.href = '/';
|
|
74
|
-
},
|
|
75
|
-
onReset: undefined,
|
|
76
|
-
errorComponent: undefined
|
|
77
|
-
};
|
|
78
|
-
//# sourceMappingURL=ErrorBoundary.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ErrorBoundary.js","sourceRoot":"","sources":["../../../src/components/ErrorBoundary.tsx"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;AAEF,kDAA0B;A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Q,CAAC,IAAI,GAAG,GAAG,CAAC;IAC7B,CAAC;IACD,OAAO,EAAE,SAAS;IAClB,cAAc,EAAE,SAAS;CAC1B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAIA,cAAc,iBAAiB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;AAEF,kDAAgC"}
|
package/dist/src/config.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Config, defs } from '@dxos/config';
|
|
2
|
-
import { MaybeFunction, MaybePromise } from '@dxos/util';
|
|
3
|
-
/**
|
|
4
|
-
* Config that is passed to components can be wrapped in a promise or a callback.
|
|
5
|
-
*/
|
|
6
|
-
export declare type SuppliedConfig = MaybeFunction<MaybePromise<defs.Config | Config>>;
|
|
7
|
-
export declare function unwrapConfig(config: SuppliedConfig): Promise<defs.Config | Config>;
|
|
8
|
-
//# sourceMappingURL=config.d.ts.map
|
package/dist/src/config.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAEzD;;GAEG;AACH,oBAAY,cAAc,GAAG,aAAa,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAA;AAE9E,wBAAsB,YAAY,CAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,CAEzF"}
|
package/dist/src/config.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// Copyright 2021 DXOS.org
|
|
4
|
-
//
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.unwrapConfig = void 0;
|
|
7
|
-
async function unwrapConfig(config) {
|
|
8
|
-
return typeof config === 'function' ? config() : config;
|
|
9
|
-
}
|
|
10
|
-
exports.unwrapConfig = unwrapConfig;
|
|
11
|
-
//# sourceMappingURL=config.js.map
|
package/dist/src/config.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;AAUK,KAAK,UAAU,YAAY,CAAE,MAAsB;IACxD,OAAO,OAAO,MAAM,KAAK,UAAU,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;AAC1D,CAAC;AAFD,oCAEC"}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import React, { ReactNode } from 'react';
|
|
2
|
-
import { Client, ClientConstructorOpts } from '@dxos/client';
|
|
3
|
-
import { ErrorComponentProps, ErrorCallbackType } from '../components';
|
|
4
|
-
import { SuppliedConfig } from '../config';
|
|
5
|
-
interface ClientLoaderProps {
|
|
6
|
-
children?: ReactNode;
|
|
7
|
-
config?: SuppliedConfig;
|
|
8
|
-
clientOpts?: ClientConstructorOpts;
|
|
9
|
-
onInit?: (client: Client) => void;
|
|
10
|
-
loaderComponent?: React.ComponentType;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Async initializer for the client component the defers rendering of children until complete.
|
|
14
|
-
*/
|
|
15
|
-
export declare const ClientLoader: ({ children, config, clientOpts, onInit, loaderComponent: LoaderComponent }: ClientLoaderProps) => JSX.Element | null;
|
|
16
|
-
interface ClientInitializerProps {
|
|
17
|
-
children?: ReactNode;
|
|
18
|
-
config?: SuppliedConfig;
|
|
19
|
-
clientOpts?: ClientConstructorOpts;
|
|
20
|
-
onError?: ErrorCallbackType;
|
|
21
|
-
errorComponent?: React.ComponentType<ErrorComponentProps>;
|
|
22
|
-
loaderComponent?: React.ComponentType;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Async initializer for the client component the defers rendering of children until complete,
|
|
26
|
-
* incorporating a top-level ErrorBoundary.
|
|
27
|
-
*/
|
|
28
|
-
export declare const ClientInitializer: ({ children, config, clientOpts, onError, errorComponent: ErrorComponent, loaderComponent: LoaderComponent }: ClientInitializerProps) => JSX.Element;
|
|
29
|
-
export {};
|
|
30
|
-
//# sourceMappingURL=ClientInitializer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ClientInitializer.d.ts","sourceRoot":"","sources":["../../../src/containers/ClientInitializer.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAuB,SAAS,EAAa,MAAM,OAAO,CAAC;AAEzE,OAAO,EAAE,MAAM,EAAE,qBAAqB,EAAE,MAAM,cAAc,CAAC;AAE7D,OAAO,EAAE,mBAAmB,EAAiB,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACtF,OAAO,EAAE,cAAc,EAAgB,MAAM,WAAW,CAAC;AAGzD,UAAU,iBAAiB;IACzB,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB,UAAU,CAAC,EAAE,qBAAqB,CAAA;IAClC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IACjC,eAAe,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;CACtC;AAED;;GAEG;AAEH,eAAO,MAAM,YAAY,+EAMtB,iBAAiB,uBA2BnB,CAAC;AAEF,UAAU,sBAAsB;IAC9B,QAAQ,CAAC,EAAE,SAAS,CAAA;IACpB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,UAAU,CAAC,EAAE,qBAAqB,CAAA;IAClC,OAAO,CAAC,EAAE,iBAAiB,CAAA;IAC3B,cAAc,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAA;IACzD,eAAe,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;CACtC;AAED;;;GAGG;AAEH,eAAO,MAAM,iBAAiB,gHAO3B,sBAAsB,gBAwCxB,CAAC"}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
//
|
|
3
|
-
// Copyright 2020 DXOS.org
|
|
4
|
-
//
|
|
5
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
8
|
-
}) : (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
o[k2] = m[k];
|
|
11
|
-
}));
|
|
12
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
13
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
14
|
-
}) : function(o, v) {
|
|
15
|
-
o["default"] = v;
|
|
16
|
-
});
|
|
17
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
18
|
-
if (mod && mod.__esModule) return mod;
|
|
19
|
-
var result = {};
|
|
20
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
21
|
-
__setModuleDefault(result, mod);
|
|
22
|
-
return result;
|
|
23
|
-
};
|
|
24
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.ClientInitializer = exports.ClientLoader = void 0;
|
|
26
|
-
const react_1 = __importStar(require("react"));
|
|
27
|
-
const client_1 = require("@dxos/client");
|
|
28
|
-
const components_1 = require("../components");
|
|
29
|
-
const config_1 = require("../config");
|
|
30
|
-
const ClientProvider_1 = require("./ClientProvider");
|
|
31
|
-
/**
|
|
32
|
-
* Async initializer for the client component the defers rendering of children until complete.
|
|
33
|
-
*/
|
|
34
|
-
// TODO(burdon): Rename.
|
|
35
|
-
const ClientLoader = ({ children, config = {}, clientOpts, onInit, loaderComponent: LoaderComponent }) => {
|
|
36
|
-
const [client, setClient] = (0, react_1.useState)();
|
|
37
|
-
(0, react_1.useEffect)(() => {
|
|
38
|
-
setImmediate(async () => {
|
|
39
|
-
const client = new client_1.Client(await (0, config_1.unwrapConfig)(config), clientOpts);
|
|
40
|
-
await client.initialize();
|
|
41
|
-
setClient(client);
|
|
42
|
-
onInit && onInit(client);
|
|
43
|
-
});
|
|
44
|
-
}, []);
|
|
45
|
-
if (!client) {
|
|
46
|
-
if (LoaderComponent) {
|
|
47
|
-
return (react_1.default.createElement(LoaderComponent, null));
|
|
48
|
-
}
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
return (react_1.default.createElement(ClientProvider_1.ClientProvider, { client: client }, children));
|
|
52
|
-
};
|
|
53
|
-
exports.ClientLoader = ClientLoader;
|
|
54
|
-
/**
|
|
55
|
-
* Async initializer for the client component the defers rendering of children until complete,
|
|
56
|
-
* incorporating a top-level ErrorBoundary.
|
|
57
|
-
*/
|
|
58
|
-
// TODO(burdon): Rename.
|
|
59
|
-
const ClientInitializer = ({ children, config = {}, clientOpts, onError, errorComponent: ErrorComponent, loaderComponent: LoaderComponent }) => {
|
|
60
|
-
const [client, setClient] = (0, react_1.useState)();
|
|
61
|
-
// TODO(burdon): Global error handling?
|
|
62
|
-
// It's important to print the error to the console here so sentry can report it.
|
|
63
|
-
const handleError = (error, errorInfo) => {
|
|
64
|
-
console.error(error, errorInfo);
|
|
65
|
-
if (onError) {
|
|
66
|
-
onError(error, errorInfo);
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
const handleRestart = () => {
|
|
70
|
-
window.location.reload();
|
|
71
|
-
};
|
|
72
|
-
// TODO(burdon): Debug only? "Are you sure?" warning?
|
|
73
|
-
const handleReset = async () => {
|
|
74
|
-
if (client) {
|
|
75
|
-
await client.reset();
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
return (react_1.default.createElement(components_1.ErrorBoundary, { onError: handleError, onRestart: handleRestart, onReset: handleReset, errorComponent: ErrorComponent },
|
|
79
|
-
react_1.default.createElement(exports.ClientLoader, { config: config, clientOpts: clientOpts, loaderComponent: LoaderComponent, onInit: setClient }, children)));
|
|
80
|
-
};
|
|
81
|
-
exports.ClientInitializer = ClientInitializer;
|
|
82
|
-
//# sourceMappingURL=ClientInitializer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ClientInitializer.js","sourceRoot":"","sources":["../../../src/containers/ClientInitializer.tsx"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;;;;;;;AAEF,+CAAyE;AAEzE,yCAA6D;AAE7D,8CAAsF;AACtF,sCAAyD;AACzD,qDAAkD;AAUlD;;GAEG;AACH,wBAAwB;AACjB,MAAM,YAAY,GAAG,CAAC,EAC3B,QAAQ,EACR,MAAM,GAAG,EAAE,EACX,UAAU,EACV,MAAM,EACN,eAAe,EAAE,eAAe,EACd,EAAE,EAAE;IACtB,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,GAAsB,CAAC;IAE3D,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,YAAY,CAAC,KAAK,IAAI,EAAE;YACtB,MAAM,MAAM,GAAG,IAAI,eAAM,CAAC,MAAM,IAAA,qBAAY,EAAC,MAAM,CAAC,EAAE,UAAU,CAAC,CAAC;YAClE,MAAM,MAAM,CAAC,UAAU,EAAE,CAAC;YAC1B,SAAS,CAAC,MAAM,CAAC,CAAC;YAClB,MAAM,IAAI,MAAM,CAAC,MAAM,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC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EACd,UAAU,EAAE,UAAU,EACtB,eAAe,EAAE,eAAe,EAChC,MAAM,EAAE,SAAS,IAEhB,QAAQ,CACI,CACD,CACjB,CAAC;AACJ,CAAC,CAAC;AA/CW,QAAA,iBAAiB,qBA+C5B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileInitializer.d.ts","sourceRoot":"","sources":["../../../src/containers/ProfileInitializer.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAoB,MAAM,OAAO,CAAC;AAIzC;;;GAGG;AAEH,eAAO,MAAM,kBAAkB;cAA8B,MAAM,SAAS;wBAe3E,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProfileInitializer.js","sourceRoot":"","sources":["../../../src/containers/ProfileInitializer.tsx"],"names":[],"mappings":";AAAA,EAAE;AACF,0BAA0B;AAC1B,EAAE;;;;;;;;;;;;;;;;;;;;;;AAEF,+CAAyC;AAEzC,oCAAiD;AAEjD;;;GAGG;AACH,8BAA8B;AACvB,MAAM,kBAAkB,GAAG,CAAC,EAAE,QAAQ,EAAiC,EAAE,EAAE;IAChF,MAAM,MAAM,GAAG,IAAA,iBAAS,GAAE,CAAC;IAC3B,MAAM,OAAO,GAAG,IAAA,kBAAU,GAAE,CAAC;IAE7B,IAAA,iBAAS,EAAC,GAAG,EAAE;QACb,IAAI,CAAC,OAAO,EAAE;YACZ,KAAK,MAAM,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;SAClC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,IAAI,CAAC;KACb;IAED,OAAO,8DAAG,QAAQ,CAAI,CAAC;AACzB,CAAC,CAAC;AAfW,QAAA,kBAAkB,sBAe7B"}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2020 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import debug from 'debug';
|
|
6
|
-
import React, { Component, ErrorInfo } from 'react';
|
|
7
|
-
|
|
8
|
-
const log = debug('dxos:react-client:error');
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Root-level error boundary.
|
|
12
|
-
* https://reactjs.org/docs/error-boundaries.html
|
|
13
|
-
*
|
|
14
|
-
* NOTE: Must currently be a Component.
|
|
15
|
-
* https://reactjs.org/docs/hooks-faq.html#do-hooks-cover-all-use-cases-for-classes
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
export type ErrorCallbackType = (error: Error, errorInfo?: ErrorInfo) => void;
|
|
19
|
-
|
|
20
|
-
export interface ErrorComponentProps {
|
|
21
|
-
error: Error | null,
|
|
22
|
-
onRestart?: () => void,
|
|
23
|
-
onReset?: () => void,
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
interface ErrorBoundaryProps {
|
|
27
|
-
onError: ErrorCallbackType,
|
|
28
|
-
onRestart?: () => void,
|
|
29
|
-
onReset?: () => void,
|
|
30
|
-
errorComponent?: React.ComponentType<ErrorComponentProps>
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
interface State {
|
|
34
|
-
error: Error | null
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Top-level error boundary.
|
|
39
|
-
* NOTE: Doesn't catch exceptions in event handlers, or asynchronous callbacks.
|
|
40
|
-
* A global error handler should be configured for such errors.
|
|
41
|
-
* https://reactjs.org/docs/error-boundaries.html#how-about-event-handlers
|
|
42
|
-
* https://developer.mozilla.org/en-US/docs/Web/API/GlobalEventHandlers/onerror
|
|
43
|
-
* It DOES catch exceptions in hooks and any components that return malformed React compoennts.
|
|
44
|
-
*/
|
|
45
|
-
export class ErrorBoundary extends Component<ErrorBoundaryProps, State> {
|
|
46
|
-
override state = {
|
|
47
|
-
error: null
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
static defaultProps = {
|
|
51
|
-
onError: console.warn,
|
|
52
|
-
onRestart: () => {
|
|
53
|
-
window.location.href = '/';
|
|
54
|
-
},
|
|
55
|
-
onReset: undefined,
|
|
56
|
-
errorComponent: undefined
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
static getDerivedStateFromError (error: any) {
|
|
60
|
-
return { error };
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
override componentDidCatch (error: Error, errorInfo: ErrorInfo) {
|
|
64
|
-
const { onError } = this.props;
|
|
65
|
-
onError(error, errorInfo);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
override render () {
|
|
69
|
-
const { children, onRestart, onReset, errorComponent: ErrorComponent } = this.props;
|
|
70
|
-
const { error } = this.state;
|
|
71
|
-
|
|
72
|
-
if (error) {
|
|
73
|
-
if (ErrorComponent) {
|
|
74
|
-
return (
|
|
75
|
-
<ErrorComponent
|
|
76
|
-
onRestart={onRestart}
|
|
77
|
-
onReset={onReset}
|
|
78
|
-
error={error}
|
|
79
|
-
/>
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
log('ErrorComponent not set.');
|
|
84
|
-
return (
|
|
85
|
-
<div style={{ border: '1px solid #CCC', padding: 16 }}>
|
|
86
|
-
<h1>ErrorBoundary component not set.</h1>
|
|
87
|
-
<pre style={{ whiteSpace: 'break-spaces' }}>
|
|
88
|
-
{String(error)}
|
|
89
|
-
</pre>
|
|
90
|
-
</div>
|
|
91
|
-
);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return children;
|
|
95
|
-
}
|
|
96
|
-
}
|
package/src/components/index.ts
DELETED
package/src/config.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2021 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { Config, defs } from '@dxos/config';
|
|
6
|
-
import { MaybeFunction, MaybePromise } from '@dxos/util';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Config that is passed to components can be wrapped in a promise or a callback.
|
|
10
|
-
*/
|
|
11
|
-
export type SuppliedConfig = MaybeFunction<MaybePromise<defs.Config | Config>>
|
|
12
|
-
|
|
13
|
-
export async function unwrapConfig (config: SuppliedConfig): Promise<defs.Config | Config> {
|
|
14
|
-
return typeof config === 'function' ? config() : config;
|
|
15
|
-
}
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2020 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import React, { useState, useEffect, ReactNode, ErrorInfo } from 'react';
|
|
6
|
-
|
|
7
|
-
import { Client, ClientConstructorOpts } from '@dxos/client';
|
|
8
|
-
|
|
9
|
-
import { ErrorComponentProps, ErrorBoundary, ErrorCallbackType } from '../components';
|
|
10
|
-
import { SuppliedConfig, unwrapConfig } from '../config';
|
|
11
|
-
import { ClientProvider } from './ClientProvider';
|
|
12
|
-
|
|
13
|
-
interface ClientLoaderProps {
|
|
14
|
-
children?: ReactNode
|
|
15
|
-
config?: SuppliedConfig
|
|
16
|
-
clientOpts?: ClientConstructorOpts
|
|
17
|
-
onInit?: (client: Client) => void
|
|
18
|
-
loaderComponent?: React.ComponentType
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Async initializer for the client component the defers rendering of children until complete.
|
|
23
|
-
*/
|
|
24
|
-
// TODO(burdon): Rename.
|
|
25
|
-
export const ClientLoader = ({
|
|
26
|
-
children,
|
|
27
|
-
config = {},
|
|
28
|
-
clientOpts,
|
|
29
|
-
onInit,
|
|
30
|
-
loaderComponent: LoaderComponent
|
|
31
|
-
}: ClientLoaderProps) => {
|
|
32
|
-
const [client, setClient] = useState<Client | undefined>();
|
|
33
|
-
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
setImmediate(async () => {
|
|
36
|
-
const client = new Client(await unwrapConfig(config), clientOpts);
|
|
37
|
-
await client.initialize();
|
|
38
|
-
setClient(client);
|
|
39
|
-
onInit && onInit(client);
|
|
40
|
-
});
|
|
41
|
-
}, []);
|
|
42
|
-
|
|
43
|
-
if (!client) {
|
|
44
|
-
if (LoaderComponent) {
|
|
45
|
-
return (
|
|
46
|
-
<LoaderComponent />
|
|
47
|
-
);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return (
|
|
54
|
-
<ClientProvider client={client}>
|
|
55
|
-
{children}
|
|
56
|
-
</ClientProvider>
|
|
57
|
-
);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
interface ClientInitializerProps {
|
|
61
|
-
children?: ReactNode
|
|
62
|
-
config?: SuppliedConfig,
|
|
63
|
-
clientOpts?: ClientConstructorOpts
|
|
64
|
-
onError?: ErrorCallbackType
|
|
65
|
-
errorComponent?: React.ComponentType<ErrorComponentProps>
|
|
66
|
-
loaderComponent?: React.ComponentType
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Async initializer for the client component the defers rendering of children until complete,
|
|
71
|
-
* incorporating a top-level ErrorBoundary.
|
|
72
|
-
*/
|
|
73
|
-
// TODO(burdon): Rename.
|
|
74
|
-
export const ClientInitializer = ({
|
|
75
|
-
children,
|
|
76
|
-
config = {},
|
|
77
|
-
clientOpts,
|
|
78
|
-
onError,
|
|
79
|
-
errorComponent: ErrorComponent,
|
|
80
|
-
loaderComponent: LoaderComponent
|
|
81
|
-
}: ClientInitializerProps) => {
|
|
82
|
-
const [client, setClient] = useState<Client | undefined>();
|
|
83
|
-
|
|
84
|
-
// TODO(burdon): Global error handling?
|
|
85
|
-
// It's important to print the error to the console here so sentry can report it.
|
|
86
|
-
const handleError = (error: Error, errorInfo?: ErrorInfo) => {
|
|
87
|
-
console.error(error, errorInfo);
|
|
88
|
-
if (onError) {
|
|
89
|
-
onError(error, errorInfo);
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const handleRestart = () => {
|
|
94
|
-
window.location.reload();
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
// TODO(burdon): Debug only? "Are you sure?" warning?
|
|
98
|
-
const handleReset = async () => {
|
|
99
|
-
if (client) {
|
|
100
|
-
await client.reset();
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
return (
|
|
105
|
-
<ErrorBoundary
|
|
106
|
-
onError={handleError}
|
|
107
|
-
onRestart={handleRestart}
|
|
108
|
-
onReset={handleReset}
|
|
109
|
-
errorComponent={ErrorComponent}
|
|
110
|
-
>
|
|
111
|
-
<ClientLoader
|
|
112
|
-
config={config}
|
|
113
|
-
clientOpts={clientOpts}
|
|
114
|
-
loaderComponent={LoaderComponent}
|
|
115
|
-
onInit={setClient}
|
|
116
|
-
>
|
|
117
|
-
{children}
|
|
118
|
-
</ClientLoader>
|
|
119
|
-
</ErrorBoundary>
|
|
120
|
-
);
|
|
121
|
-
};
|