piral-core 0.15.0-alpha.3540 → 0.15.0-alpha.3564
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/esm/actions/app.d.ts +3 -1
- package/esm/actions/app.js +18 -0
- package/esm/actions/app.js.map +1 -1
- package/esm/components/ErrorBoundary.d.ts +12 -33
- package/esm/components/ErrorBoundary.js +12 -14
- package/esm/components/ErrorBoundary.js.map +1 -1
- package/esm/createInstance.js +5 -1
- package/esm/createInstance.js.map +1 -1
- package/{debug-piral.d.ts → esm/debugger.d.ts} +1 -1
- package/esm/debugger.js +52 -0
- package/esm/debugger.js.map +1 -0
- package/{debug-pilet.d.ts → esm/emulator.d.ts} +1 -1
- package/esm/emulator.js +8 -0
- package/esm/emulator.js.map +1 -0
- package/esm/helpers.d.ts +3 -2
- package/esm/helpers.js +4 -3
- package/esm/helpers.js.map +1 -1
- package/esm/modules/core.js +8 -6
- package/esm/modules/core.js.map +1 -1
- package/esm/modules/dependencies.d.ts +2 -2
- package/esm/modules/dependencies.js.map +1 -1
- package/esm/state/withApi.d.ts +1 -1
- package/esm/state/withApi.js +31 -33
- package/esm/state/withApi.js.map +1 -1
- package/esm/types/api.d.ts +12 -8
- package/esm/types/state.d.ts +13 -3
- package/esm/types/utils.d.ts +1 -1
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.js +1 -0
- package/esm/utils/index.js.map +1 -1
- package/lib/actions/app.d.ts +3 -1
- package/lib/actions/app.js +21 -1
- package/lib/actions/app.js.map +1 -1
- package/lib/components/ErrorBoundary.d.ts +12 -33
- package/lib/components/ErrorBoundary.js +12 -14
- package/lib/components/ErrorBoundary.js.map +1 -1
- package/lib/createInstance.js +5 -1
- package/lib/createInstance.js.map +1 -1
- package/lib/debugger.d.ts +4 -0
- package/lib/debugger.js +56 -0
- package/lib/debugger.js.map +1 -0
- package/lib/emulator.d.ts +3 -0
- package/lib/emulator.js +12 -0
- package/lib/emulator.js.map +1 -0
- package/lib/helpers.d.ts +3 -2
- package/lib/helpers.js +4 -3
- package/lib/helpers.js.map +1 -1
- package/lib/modules/core.js +8 -6
- package/lib/modules/core.js.map +1 -1
- package/lib/modules/dependencies.d.ts +2 -2
- package/lib/modules/dependencies.js.map +1 -1
- package/lib/state/withApi.d.ts +1 -1
- package/lib/state/withApi.js +30 -32
- package/lib/state/withApi.js.map +1 -1
- package/lib/types/api.d.ts +12 -8
- package/lib/types/state.d.ts +13 -3
- package/lib/types/utils.d.ts +1 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +4 -0
- package/lib/utils/index.js.map +1 -1
- package/package.json +9 -11
- package/src/actions/app.ts +25 -0
- package/src/components/ErrorBoundary.tsx +19 -51
- package/src/createInstance.tsx +5 -1
- package/src/debugger.ts +82 -0
- package/src/emulator.ts +10 -0
- package/src/helpers.tsx +6 -2
- package/src/modules/core.ts +10 -8
- package/src/modules/dependencies.ts +3 -2
- package/src/state/withApi.test.tsx +20 -4
- package/src/state/withApi.tsx +51 -42
- package/src/types/api.ts +23 -9
- package/src/types/state.ts +13 -3
- package/src/types/utils.ts +1 -1
- package/src/utils/index.ts +2 -0
- package/debug-pilet.js +0 -12
- package/debug-piral.js +0 -59
package/lib/state/withApi.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"withApi.js","sourceRoot":"","sources":["../../src/state/withApi.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AACpC,+CAA+C;AAC/C,
|
|
1
|
+
{"version":3,"file":"withApi.js","sourceRoot":"","sources":["../../src/state/withApi.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AACpC,+CAA+C;AAC/C,8CAA8D;AAC9D,oCAAiD;AACjD,oCAAiE;AAYjE,qDAAqD;AACrD,IAAI,YAAY,GAAG,MAAM,CAAC;AAE1B,MAAM,cAAc,GAAa,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,qBAAa,E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I,KAAK,6CAA6C,CAAC,CAAC;QACtE,2CAA2C;QAC3C,SAAS,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;KACxB;IAED,OAAO,aAAa,CAAS,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AAC3E,CAAC;AA5BD,0BA4BC"}
|
package/lib/types/api.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { ReactElement } from 'react';
|
|
2
2
|
import type { RouteComponentProps } from 'react-router';
|
|
3
|
-
import type { PiletApi, Pilet, PiletMetadata, EventEmitter,
|
|
3
|
+
import type { PiletApi, Pilet, PiletEntry, PiletEntries, PiletMetadata, EventEmitter, PiletLoader, PiletLoadingStrategy } from 'piral-base';
|
|
4
4
|
import type { PiletCustomApi, PiralCustomPageMeta } from './custom';
|
|
5
5
|
import type { AnyComponent } from './components';
|
|
6
6
|
import type { ExtensionSlotProps, PiralExtensionSlotMap } from './extension';
|
|
7
7
|
import type { SharedData, DataStoreOptions } from './data';
|
|
8
8
|
import type { Disposable } from './utils';
|
|
9
|
-
export { PiletApi, Pilet, PiletMetadata, EventEmitter,
|
|
9
|
+
export { PiletApi, Pilet, PiletMetadata, EventEmitter, PiletEntry, PiletEntries, PiletLoader, PiletLoadingStrategy };
|
|
10
10
|
/**
|
|
11
11
|
* The props that every registered component obtains.
|
|
12
12
|
*/
|
|
@@ -34,6 +34,11 @@ export interface ExtensionComponentProps<T> extends BaseComponentProps {
|
|
|
34
34
|
*/
|
|
35
35
|
params: T extends keyof PiralExtensionSlotMap ? PiralExtensionSlotMap[T] : T extends string ? any : T;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* The meta data registered for a page.
|
|
39
|
+
*/
|
|
40
|
+
export interface PiralPageMeta extends PiralCustomPageMeta {
|
|
41
|
+
}
|
|
37
42
|
/**
|
|
38
43
|
* The props that every registered page component obtains.
|
|
39
44
|
*/
|
|
@@ -43,11 +48,10 @@ export interface RouteBaseProps<UrlParams = any, UrlState = any> extends RouteCo
|
|
|
43
48
|
* The props used by a page component.
|
|
44
49
|
*/
|
|
45
50
|
export interface PageComponentProps<T = any, S = any> extends RouteBaseProps<T, S> {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
export interface PiralPageMeta extends PiralCustomPageMeta {
|
|
51
|
+
/**
|
|
52
|
+
* The meta data registered with the page.
|
|
53
|
+
*/
|
|
54
|
+
meta: PiralPageMeta;
|
|
51
55
|
}
|
|
52
56
|
/**
|
|
53
57
|
* Defines the Pilet API from piral-core.
|
|
@@ -111,7 +115,7 @@ export interface PiletCoreApi {
|
|
|
111
115
|
*/
|
|
112
116
|
renderHtmlExtension<TName>(element: HTMLElement | ShadowRoot, props: ExtensionSlotProps<TName>): Disposable;
|
|
113
117
|
}
|
|
114
|
-
declare module 'piral-base/lib/types' {
|
|
118
|
+
declare module 'piral-base/lib/types/runtime' {
|
|
115
119
|
interface PiletApi extends PiletCustomApi, PiletCoreApi {
|
|
116
120
|
}
|
|
117
121
|
}
|
package/lib/types/state.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import type { Dict, Without } from './common';
|
|
|
6
6
|
import type { LayoutType } from './layout';
|
|
7
7
|
import type { SharedDataItem, DataStoreTarget } from './data';
|
|
8
8
|
import type { PiralCustomActions, PiralCustomState, PiralCustomRegistryState, PiralCustomComponentsState } from './custom';
|
|
9
|
-
import type {
|
|
9
|
+
import type { EventEmitter, Pilet, BaseComponentProps, PageComponentProps, ExtensionComponentProps, PiletsBag, PiralPageMeta, PiletEntry } from './api';
|
|
10
10
|
import type { ComponentConverters, LoadingIndicatorProps, ErrorInfoProps, RouterProps, LayoutProps, Errors } from './components';
|
|
11
11
|
export interface StateDispatcher<TState> {
|
|
12
12
|
(state: TState): Partial<TState>;
|
|
@@ -130,7 +130,7 @@ export interface GlobalState extends PiralCustomState {
|
|
|
130
130
|
/**
|
|
131
131
|
* Gets the loaded modules.
|
|
132
132
|
*/
|
|
133
|
-
modules: Array<
|
|
133
|
+
modules: Array<Pilet>;
|
|
134
134
|
/**
|
|
135
135
|
* The foreign component portals to render.
|
|
136
136
|
*/
|
|
@@ -172,10 +172,20 @@ export interface PiralActions extends PiralCustomActions {
|
|
|
172
172
|
*/
|
|
173
173
|
initialize(loading: boolean, error: Error | undefined, modules: Array<Pilet>): void;
|
|
174
174
|
/**
|
|
175
|
-
* Injects
|
|
175
|
+
* Injects an evaluated pilet at runtime - removes the pilet from registry first if available.
|
|
176
176
|
* @param pilet The pilet to be injected.
|
|
177
177
|
*/
|
|
178
178
|
injectPilet(pilet: Pilet): void;
|
|
179
|
+
/**
|
|
180
|
+
* Adds a pilet at runtime by loading it, evaluating it, and then injecting it.
|
|
181
|
+
* @param pilet The pilet to be added.
|
|
182
|
+
*/
|
|
183
|
+
addPilet(pilet: PiletEntry): void;
|
|
184
|
+
/**
|
|
185
|
+
* Removes a pilet by unloading it and deleting all component registrations.
|
|
186
|
+
* @param name The name of the pilet to remove.
|
|
187
|
+
*/
|
|
188
|
+
removePilet(name: string): void;
|
|
179
189
|
/**
|
|
180
190
|
* Defines a single action for Piral.
|
|
181
191
|
* @param actionName The name of the action to define.
|
package/lib/types/utils.d.ts
CHANGED
|
@@ -55,7 +55,7 @@ export interface PiralStoreDataEvent<TValue = any> {
|
|
|
55
55
|
*/
|
|
56
56
|
expires: number;
|
|
57
57
|
}
|
|
58
|
-
declare module 'piral-base/lib/types' {
|
|
58
|
+
declare module 'piral-base/lib/types/api' {
|
|
59
59
|
interface PiralEventMap extends PiralCustomEventMap {
|
|
60
60
|
'store-data': PiralStoreDataEvent;
|
|
61
61
|
}
|
package/lib/utils/index.d.ts
CHANGED
package/lib/utils/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.requireModule = exports.isfunc = void 0;
|
|
3
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
var piral_base_1 = require("piral-base");
|
|
6
|
+
Object.defineProperty(exports, "isfunc", { enumerable: true, get: function () { return piral_base_1.isfunc; } });
|
|
7
|
+
Object.defineProperty(exports, "requireModule", { enumerable: true, get: function () { return piral_base_1.requireModule; } });
|
|
4
8
|
(0, tslib_1.__exportStar)(require("./compare"), exports);
|
|
5
9
|
(0, tslib_1.__exportStar)(require("./data"), exports);
|
|
6
10
|
(0, tslib_1.__exportStar)(require("./extension"), exports);
|
package/lib/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;;AAAA,yCAAmD;AAA1C,oGAAA,MAAM,OAAA;AAAE,2GAAA,aAAa,OAAA;AAE9B,yDAA0B;AAC1B,sDAAuB;AACvB,2DAA4B;AAC5B,yDAA0B;AAC1B,sDAAuB;AACvB,yDAA0B;AAC1B,uDAAwB;AACxB,uDAAwB;AACxB,uDAAwB;AACxB,yDAA0B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "piral-core",
|
|
3
|
-
"version": "0.15.0-alpha.
|
|
3
|
+
"version": "0.15.0-alpha.3564",
|
|
4
4
|
"description": "The core library for creating a Piral instance.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portal",
|
|
@@ -22,10 +22,6 @@
|
|
|
22
22
|
"esm",
|
|
23
23
|
"lib",
|
|
24
24
|
"src",
|
|
25
|
-
"debug-pilet.d.ts",
|
|
26
|
-
"debug-piral.d.ts",
|
|
27
|
-
"debug-pilet.js",
|
|
28
|
-
"debug-piral.js",
|
|
29
25
|
"dependencies.codegen",
|
|
30
26
|
"dependencies.codegen.native.js"
|
|
31
27
|
],
|
|
@@ -41,8 +37,7 @@
|
|
|
41
37
|
"url": "https://github.com/smapiot/piral/issues"
|
|
42
38
|
},
|
|
43
39
|
"scripts": {
|
|
44
|
-
"build": "yarn build:commonjs && yarn build:esnext
|
|
45
|
-
"build:convert": "tsc debug-pilet.ts debug-piral.ts --skipLibCheck --declaration",
|
|
40
|
+
"build": "yarn build:commonjs && yarn build:esnext",
|
|
46
41
|
"build:commonjs": "tsc --project tsconfig.json --outDir lib --module commonjs",
|
|
47
42
|
"build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
|
|
48
43
|
"typedoc": "typedoc --json ../../../docs/types/piral-core.json src --exclude \"src/**/*.test.*\"",
|
|
@@ -50,8 +45,8 @@
|
|
|
50
45
|
},
|
|
51
46
|
"dependencies": {
|
|
52
47
|
"@dbeining/react-atom": "^4.0.0",
|
|
53
|
-
"piral-base": "0.15.0-alpha.
|
|
54
|
-
"piral-debug-utils": "0.15.0-alpha.
|
|
48
|
+
"piral-base": "0.15.0-alpha.3564",
|
|
49
|
+
"piral-debug-utils": "0.15.0-alpha.3564"
|
|
55
50
|
},
|
|
56
51
|
"peerDependencies": {
|
|
57
52
|
"react": ">=16.8.0",
|
|
@@ -62,10 +57,13 @@
|
|
|
62
57
|
"devDependencies": {
|
|
63
58
|
"@types/history": "^4.7.8",
|
|
64
59
|
"@types/react": "^17.0.0",
|
|
60
|
+
"@types/react-dom": "^17.0.0",
|
|
65
61
|
"@types/react-router": "^5.1.8",
|
|
66
62
|
"@types/react-router-dom": "^5.1.6",
|
|
67
63
|
"react": "^17.0.1",
|
|
68
|
-
"react-dom": "^17.0.1"
|
|
64
|
+
"react-dom": "^17.0.1",
|
|
65
|
+
"react-router": "^5.2.0",
|
|
66
|
+
"react-router-dom": "^5.2.0"
|
|
69
67
|
},
|
|
70
68
|
"sharedDependencies": [
|
|
71
69
|
"react",
|
|
@@ -78,5 +76,5 @@
|
|
|
78
76
|
"@libre/atom",
|
|
79
77
|
"@dbeining/react-atom"
|
|
80
78
|
],
|
|
81
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "e5af009799d073993a1c415c4ee63029f9b3d547"
|
|
82
80
|
}
|
package/src/actions/app.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ComponentType } from 'react';
|
|
2
2
|
import { RouteComponentProps } from 'react-router';
|
|
3
|
+
import { runPilet } from 'piral-base';
|
|
3
4
|
import { withKey, replaceOrAddItem, removeNested, withProvider, withRoute } from '../utils';
|
|
4
5
|
import {
|
|
5
6
|
LayoutType,
|
|
@@ -9,6 +10,7 @@ import {
|
|
|
9
10
|
RegistryState,
|
|
10
11
|
GlobalStateContext,
|
|
11
12
|
Pilet,
|
|
13
|
+
PiletEntry,
|
|
12
14
|
} from '../types';
|
|
13
15
|
|
|
14
16
|
export function changeLayout(ctx: GlobalStateContext, current: LayoutType) {
|
|
@@ -30,6 +32,29 @@ export function initialize(ctx: GlobalStateContext, loading: boolean, error: Err
|
|
|
30
32
|
}));
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
export function addPilet(ctx: GlobalStateContext, meta: PiletEntry) {
|
|
36
|
+
ctx.options.loadPilet(meta).then((pilet) => {
|
|
37
|
+
try {
|
|
38
|
+
ctx.injectPilet(pilet);
|
|
39
|
+
runPilet(ctx.options.createApi, pilet, ctx.options.hooks);
|
|
40
|
+
} catch (error) {
|
|
41
|
+
console.error(error);
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function removePilet(ctx: GlobalStateContext, name: string) {
|
|
47
|
+
ctx.dispatch((state) => ({
|
|
48
|
+
...state,
|
|
49
|
+
modules: state.modules.filter((m) => m.name !== name),
|
|
50
|
+
registry: removeNested<RegistryState, BaseRegistration>(state.registry, (m) => m.pilet === name),
|
|
51
|
+
}));
|
|
52
|
+
|
|
53
|
+
ctx.emit('unload-pilet', {
|
|
54
|
+
name,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
33
58
|
export function injectPilet(ctx: GlobalStateContext, pilet: Pilet) {
|
|
34
59
|
ctx.dispatch((state) => ({
|
|
35
60
|
...state,
|
|
@@ -1,42 +1,18 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { PiralError, PiralLoadingIndicator } from './components';
|
|
3
|
+
import { Errors, PiletApi } from '../types';
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
* The options to be used for determining the boundary's behavior.
|
|
6
|
-
*/
|
|
7
|
-
export interface ErrorBoundaryOptions<T> {
|
|
8
|
-
/**
|
|
9
|
-
* Callback to be used in case of an emitted error.
|
|
10
|
-
* @param error The error caught by the boundary.
|
|
11
|
-
*/
|
|
12
|
-
onError(error: Error): void;
|
|
5
|
+
export interface ErrorBoundaryProps {
|
|
13
6
|
/**
|
|
14
|
-
*
|
|
15
|
-
* @param error The error caught by the boundary.
|
|
16
|
-
* @param props The props used by the boundary.
|
|
7
|
+
* The type of error to indicate when caught.
|
|
17
8
|
*/
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Callback to used when no error should be rendered.
|
|
21
|
-
* @param children The standard children to render.
|
|
22
|
-
* @param props The props used by the boundary.
|
|
23
|
-
*/
|
|
24
|
-
renderChild(children: React.ReactNode, props: T): React.ReactNode;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* The props of the ErrorBoundary component.
|
|
29
|
-
*/
|
|
30
|
-
export interface ErrorBoundaryProps<T> extends ErrorBoundaryOptions<T> {
|
|
9
|
+
errorType: keyof Errors;
|
|
31
10
|
/**
|
|
32
|
-
* The
|
|
11
|
+
* The associated pilet api for the metadata.
|
|
33
12
|
*/
|
|
34
|
-
|
|
13
|
+
piral: PiletApi;
|
|
35
14
|
}
|
|
36
15
|
|
|
37
|
-
/**
|
|
38
|
-
* The state of the ErrorBoundary component.
|
|
39
|
-
*/
|
|
40
16
|
export interface ErrorBoundaryState {
|
|
41
17
|
/**
|
|
42
18
|
* The current error (if any) caught by the boundary.
|
|
@@ -45,22 +21,17 @@ export interface ErrorBoundaryState {
|
|
|
45
21
|
}
|
|
46
22
|
|
|
47
23
|
/**
|
|
48
|
-
* The
|
|
24
|
+
* The component for catching errors and displaying error information.
|
|
49
25
|
*/
|
|
50
|
-
export class ErrorBoundary
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
error: undefined,
|
|
55
|
-
};
|
|
56
|
-
}
|
|
26
|
+
export class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
|
|
27
|
+
state = {
|
|
28
|
+
error: undefined,
|
|
29
|
+
};
|
|
57
30
|
|
|
58
31
|
componentDidCatch(error: Error) {
|
|
59
|
-
const {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
onError(error);
|
|
63
|
-
}
|
|
32
|
+
const { piral, errorType } = this.props;
|
|
33
|
+
const pilet = piral.meta.name;
|
|
34
|
+
console.error(`[${pilet}] Exception in component of type "${errorType}".`, error);
|
|
64
35
|
|
|
65
36
|
this.setState({
|
|
66
37
|
error,
|
|
@@ -68,17 +39,14 @@ export class ErrorBoundary<T> extends React.Component<ErrorBoundaryProps<T>, Err
|
|
|
68
39
|
}
|
|
69
40
|
|
|
70
41
|
render() {
|
|
71
|
-
const { children,
|
|
42
|
+
const { children, piral, errorType, ...renderProps } = this.props;
|
|
72
43
|
const { error } = this.state;
|
|
44
|
+
const rest: any = renderProps;
|
|
73
45
|
|
|
74
46
|
if (error) {
|
|
75
|
-
|
|
76
|
-
return renderError(error, renderProps);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return <div style={{ whiteSpace: 'pre-wrap' }}>{error && error.message}</div>;
|
|
47
|
+
return <PiralError type={errorType} error={error} {...rest} />;
|
|
80
48
|
}
|
|
81
49
|
|
|
82
|
-
return
|
|
50
|
+
return <React.Suspense fallback={<PiralLoadingIndicator />}>{children}</React.Suspense>;
|
|
83
51
|
}
|
|
84
52
|
}
|
package/src/createInstance.tsx
CHANGED
|
@@ -51,7 +51,11 @@ export function createInstance(config: PiralInstanceOptions = {}): PiralInstance
|
|
|
51
51
|
const root = createApi({
|
|
52
52
|
name: 'root',
|
|
53
53
|
version: process.env.BUILD_PCKG_VERSION || '1.0.0',
|
|
54
|
-
spec: '',
|
|
54
|
+
spec: 'v0',
|
|
55
|
+
basePath: '',
|
|
56
|
+
link: '',
|
|
57
|
+
config: {},
|
|
58
|
+
dependencies: {},
|
|
55
59
|
});
|
|
56
60
|
const options = createPiletOptions({
|
|
57
61
|
context,
|
package/src/debugger.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { addChangeHandler } from '@dbeining/react-atom';
|
|
2
|
+
import { LoadPiletsOptions } from 'piral-base';
|
|
3
|
+
import { installPiralDebug, DebuggerExtensionOptions } from 'piral-debug-utils';
|
|
4
|
+
import { GlobalStateContext } from './types';
|
|
5
|
+
|
|
6
|
+
export function integrate(
|
|
7
|
+
context: GlobalStateContext,
|
|
8
|
+
options: LoadPiletsOptions,
|
|
9
|
+
debug: DebuggerExtensionOptions = {},
|
|
10
|
+
) {
|
|
11
|
+
installPiralDebug({
|
|
12
|
+
...debug,
|
|
13
|
+
addPilet: context.addPilet,
|
|
14
|
+
removePilet: context.removePilet,
|
|
15
|
+
updatePilet(pilet) {
|
|
16
|
+
if (!pilet.disabled) {
|
|
17
|
+
const { createApi } = options;
|
|
18
|
+
const newApi = createApi(pilet);
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
context.injectPilet(pilet);
|
|
22
|
+
pilet.setup(newApi);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
console.error(error);
|
|
25
|
+
}
|
|
26
|
+
} else {
|
|
27
|
+
context.injectPilet(pilet);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
fireEvent: context.emit,
|
|
31
|
+
getDependencies() {
|
|
32
|
+
return Object.keys(options.dependencies);
|
|
33
|
+
},
|
|
34
|
+
getExtensions() {
|
|
35
|
+
return context.readState((s) => Object.keys(s.registry.extensions));
|
|
36
|
+
},
|
|
37
|
+
getRoutes() {
|
|
38
|
+
const registeredRoutes = context.readState((state) => Object.keys(state.registry.pages));
|
|
39
|
+
const componentRoutes = context.readState((state) => Object.keys(state.routes));
|
|
40
|
+
return [...componentRoutes, ...registeredRoutes];
|
|
41
|
+
},
|
|
42
|
+
getGlobalState() {
|
|
43
|
+
return context.readState((s) => s);
|
|
44
|
+
},
|
|
45
|
+
getPilets() {
|
|
46
|
+
return context.readState((s) => s.modules);
|
|
47
|
+
},
|
|
48
|
+
integrate(dbg) {
|
|
49
|
+
context.dispatch((s) => ({
|
|
50
|
+
...s,
|
|
51
|
+
components: {
|
|
52
|
+
...s.components,
|
|
53
|
+
...dbg.components,
|
|
54
|
+
},
|
|
55
|
+
routes: {
|
|
56
|
+
...s.routes,
|
|
57
|
+
...dbg.routes,
|
|
58
|
+
},
|
|
59
|
+
registry: {
|
|
60
|
+
...s.registry,
|
|
61
|
+
wrappers: {
|
|
62
|
+
...s.registry.wrappers,
|
|
63
|
+
...dbg.wrappers,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
}));
|
|
67
|
+
|
|
68
|
+
addChangeHandler(context.state, 'debugging', ({ previous, current }) => {
|
|
69
|
+
const pilets = current.modules !== previous.modules;
|
|
70
|
+
const pages = current.registry.pages !== previous.registry.pages || current.routes !== previous.routes;
|
|
71
|
+
const extensions = current.registry.extensions !== previous.registry.extensions;
|
|
72
|
+
const state = current !== previous;
|
|
73
|
+
dbg.onChange(previous, current, {
|
|
74
|
+
pilets,
|
|
75
|
+
pages,
|
|
76
|
+
extensions,
|
|
77
|
+
state,
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
package/src/emulator.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { LoadPiletsOptions } from 'piral-base';
|
|
2
|
+
import { withEmulatorPilets } from 'piral-debug-utils';
|
|
3
|
+
import { GlobalStateContext } from './types';
|
|
4
|
+
|
|
5
|
+
export function integrate(context: GlobalStateContext, options: LoadPiletsOptions) {
|
|
6
|
+
options.fetchPilets = withEmulatorPilets(options.fetchPilets, {
|
|
7
|
+
addPilet: context.addPilet,
|
|
8
|
+
removePilet: context.removePilet,
|
|
9
|
+
});
|
|
10
|
+
}
|
package/src/helpers.tsx
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
getDefaultLoader,
|
|
7
7
|
extendLoader,
|
|
8
8
|
PiletLoader,
|
|
9
|
+
PiletLifecycleHooks,
|
|
9
10
|
} from 'piral-base';
|
|
10
11
|
import { DebuggerExtensionOptions } from 'piral-debug-utils';
|
|
11
12
|
import { globalDependencies } from './modules';
|
|
@@ -13,6 +14,7 @@ import type { Pilet, PiletRequester, GlobalStateContext, PiletLoadingStrategy, D
|
|
|
13
14
|
|
|
14
15
|
export interface PiletOptionsConfig {
|
|
15
16
|
context: GlobalStateContext;
|
|
17
|
+
hooks?: PiletLifecycleHooks;
|
|
16
18
|
loaders?: CustomSpecLoaders;
|
|
17
19
|
loaderConfig?: DefaultLoaderConfig;
|
|
18
20
|
availablePilets: Array<Pilet>;
|
|
@@ -25,6 +27,7 @@ export interface PiletOptionsConfig {
|
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
export function createPiletOptions({
|
|
30
|
+
hooks,
|
|
28
31
|
context,
|
|
29
32
|
loaders,
|
|
30
33
|
loaderConfig,
|
|
@@ -43,18 +46,19 @@ export function createPiletOptions({
|
|
|
43
46
|
createApi,
|
|
44
47
|
pilets: availablePilets,
|
|
45
48
|
fetchPilets: requestPilets,
|
|
49
|
+
hooks,
|
|
46
50
|
dependencies: shareDependencies(globalDependencies),
|
|
47
51
|
};
|
|
48
52
|
|
|
49
53
|
// if we build the debug version of piral (debug and emulator build)
|
|
50
54
|
if (process.env.DEBUG_PIRAL) {
|
|
51
|
-
const { integrate } = require('
|
|
55
|
+
const { integrate } = require('./debugger');
|
|
52
56
|
integrate(context, options, debug);
|
|
53
57
|
}
|
|
54
58
|
|
|
55
59
|
// if we build the emulator version of piral (shipped to pilets)
|
|
56
60
|
if (process.env.DEBUG_PILET) {
|
|
57
|
-
const { integrate } = require('
|
|
61
|
+
const { integrate } = require('./emulator');
|
|
58
62
|
integrate(context, options);
|
|
59
63
|
}
|
|
60
64
|
|
package/src/modules/core.ts
CHANGED
|
@@ -17,28 +17,30 @@ export function createCoreApi(context: GlobalStateContext): PiletApiExtender<Pil
|
|
|
17
17
|
const expiration = getDataExpiration(expires);
|
|
18
18
|
return context.tryWriteDataItem(name, value, pilet, target, expiration);
|
|
19
19
|
},
|
|
20
|
-
registerPage(route, arg, meta) {
|
|
20
|
+
registerPage(route, arg, meta = {}) {
|
|
21
|
+
const component = withApi(context, arg, api, 'page', undefined, { meta });
|
|
21
22
|
context.registerPage(route, {
|
|
22
23
|
pilet,
|
|
23
24
|
meta,
|
|
24
|
-
component
|
|
25
|
+
component,
|
|
25
26
|
});
|
|
26
27
|
return () => api.unregisterPage(route);
|
|
27
28
|
},
|
|
28
29
|
unregisterPage(route) {
|
|
29
30
|
context.unregisterPage(route);
|
|
30
31
|
},
|
|
31
|
-
registerExtension(name,
|
|
32
|
-
context
|
|
32
|
+
registerExtension(name, reference, defaults) {
|
|
33
|
+
const component = withApi(context, reference, api, 'extension');
|
|
34
|
+
context.registerExtension(name, {
|
|
33
35
|
pilet,
|
|
34
|
-
component
|
|
35
|
-
reference
|
|
36
|
+
component,
|
|
37
|
+
reference,
|
|
36
38
|
defaults,
|
|
37
39
|
});
|
|
38
|
-
return () => api.unregisterExtension(name,
|
|
40
|
+
return () => api.unregisterExtension(name, reference);
|
|
39
41
|
},
|
|
40
42
|
unregisterExtension(name, arg) {
|
|
41
|
-
context.unregisterExtension(name
|
|
43
|
+
context.unregisterExtension(name, arg);
|
|
42
44
|
},
|
|
43
45
|
renderHtmlExtension(element, props) {
|
|
44
46
|
const [dispose] = renderElement(context, element, props);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isfunc } from 'piral-base';
|
|
2
2
|
import { __assign } from 'tslib';
|
|
3
|
+
import type { AvailableDependencies, PiletEntries } from '../types';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The global dependencies, which represent the dependencies
|
|
@@ -49,6 +50,6 @@ return fetch('https://feed.piral.cloud/api/v1/pilet/sample')
|
|
|
49
50
|
.then(res => res.items);
|
|
50
51
|
```
|
|
51
52
|
*/
|
|
52
|
-
export function defaultModuleRequester(): Promise<
|
|
53
|
+
export function defaultModuleRequester(): Promise<PiletEntries> {
|
|
53
54
|
return Promise.resolve([]);
|
|
54
55
|
}
|
|
@@ -58,7 +58,11 @@ StubComponent.displayName = 'StubComponent';
|
|
|
58
58
|
|
|
59
59
|
describe('withApi Module', () => {
|
|
60
60
|
it('wraps a component and forwards the API as piral', () => {
|
|
61
|
-
const api: any = {
|
|
61
|
+
const api: any = {
|
|
62
|
+
meta: {
|
|
63
|
+
name: 'foo',
|
|
64
|
+
},
|
|
65
|
+
};
|
|
62
66
|
const { context } = createMockContainer();
|
|
63
67
|
const Component = withApi(context, StubComponent, api, 'feed' as any);
|
|
64
68
|
const node = mount(<Component />);
|
|
@@ -67,7 +71,11 @@ describe('withApi Module', () => {
|
|
|
67
71
|
|
|
68
72
|
it('is protected against a component crash', () => {
|
|
69
73
|
console.error = jest.fn();
|
|
70
|
-
const api: any = {
|
|
74
|
+
const api: any = {
|
|
75
|
+
meta: {
|
|
76
|
+
name: 'foo',
|
|
77
|
+
},
|
|
78
|
+
};
|
|
71
79
|
const { context } = createMockContainer();
|
|
72
80
|
const Component = withApi(context, StubComponent, api, 'feed' as any);
|
|
73
81
|
const node = mount(<Component shouldCrash />);
|
|
@@ -88,7 +96,11 @@ describe('withApi Module', () => {
|
|
|
88
96
|
});
|
|
89
97
|
|
|
90
98
|
it('Wraps component of type object', () => {
|
|
91
|
-
const api: any = {
|
|
99
|
+
const api: any = {
|
|
100
|
+
meta: {
|
|
101
|
+
name: 'foo',
|
|
102
|
+
},
|
|
103
|
+
};
|
|
92
104
|
const { context } = createMockContainer();
|
|
93
105
|
context.converters = {
|
|
94
106
|
html: (component) => {
|
|
@@ -107,7 +119,11 @@ describe('withApi Module', () => {
|
|
|
107
119
|
});
|
|
108
120
|
|
|
109
121
|
it('Wraps component which is object == null.', () => {
|
|
110
|
-
const api: any = {
|
|
122
|
+
const api: any = {
|
|
123
|
+
meta: {
|
|
124
|
+
name: 'foo',
|
|
125
|
+
},
|
|
126
|
+
};
|
|
111
127
|
const { context } = createMockContainer();
|
|
112
128
|
context.converters = {
|
|
113
129
|
html: (component) => {
|