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.
Files changed (77) hide show
  1. package/esm/actions/app.d.ts +3 -1
  2. package/esm/actions/app.js +18 -0
  3. package/esm/actions/app.js.map +1 -1
  4. package/esm/components/ErrorBoundary.d.ts +12 -33
  5. package/esm/components/ErrorBoundary.js +12 -14
  6. package/esm/components/ErrorBoundary.js.map +1 -1
  7. package/esm/createInstance.js +5 -1
  8. package/esm/createInstance.js.map +1 -1
  9. package/{debug-piral.d.ts → esm/debugger.d.ts} +1 -1
  10. package/esm/debugger.js +52 -0
  11. package/esm/debugger.js.map +1 -0
  12. package/{debug-pilet.d.ts → esm/emulator.d.ts} +1 -1
  13. package/esm/emulator.js +8 -0
  14. package/esm/emulator.js.map +1 -0
  15. package/esm/helpers.d.ts +3 -2
  16. package/esm/helpers.js +4 -3
  17. package/esm/helpers.js.map +1 -1
  18. package/esm/modules/core.js +8 -6
  19. package/esm/modules/core.js.map +1 -1
  20. package/esm/modules/dependencies.d.ts +2 -2
  21. package/esm/modules/dependencies.js.map +1 -1
  22. package/esm/state/withApi.d.ts +1 -1
  23. package/esm/state/withApi.js +31 -33
  24. package/esm/state/withApi.js.map +1 -1
  25. package/esm/types/api.d.ts +12 -8
  26. package/esm/types/state.d.ts +13 -3
  27. package/esm/types/utils.d.ts +1 -1
  28. package/esm/utils/index.d.ts +1 -0
  29. package/esm/utils/index.js +1 -0
  30. package/esm/utils/index.js.map +1 -1
  31. package/lib/actions/app.d.ts +3 -1
  32. package/lib/actions/app.js +21 -1
  33. package/lib/actions/app.js.map +1 -1
  34. package/lib/components/ErrorBoundary.d.ts +12 -33
  35. package/lib/components/ErrorBoundary.js +12 -14
  36. package/lib/components/ErrorBoundary.js.map +1 -1
  37. package/lib/createInstance.js +5 -1
  38. package/lib/createInstance.js.map +1 -1
  39. package/lib/debugger.d.ts +4 -0
  40. package/lib/debugger.js +56 -0
  41. package/lib/debugger.js.map +1 -0
  42. package/lib/emulator.d.ts +3 -0
  43. package/lib/emulator.js +12 -0
  44. package/lib/emulator.js.map +1 -0
  45. package/lib/helpers.d.ts +3 -2
  46. package/lib/helpers.js +4 -3
  47. package/lib/helpers.js.map +1 -1
  48. package/lib/modules/core.js +8 -6
  49. package/lib/modules/core.js.map +1 -1
  50. package/lib/modules/dependencies.d.ts +2 -2
  51. package/lib/modules/dependencies.js.map +1 -1
  52. package/lib/state/withApi.d.ts +1 -1
  53. package/lib/state/withApi.js +30 -32
  54. package/lib/state/withApi.js.map +1 -1
  55. package/lib/types/api.d.ts +12 -8
  56. package/lib/types/state.d.ts +13 -3
  57. package/lib/types/utils.d.ts +1 -1
  58. package/lib/utils/index.d.ts +1 -0
  59. package/lib/utils/index.js +4 -0
  60. package/lib/utils/index.js.map +1 -1
  61. package/package.json +9 -11
  62. package/src/actions/app.ts +25 -0
  63. package/src/components/ErrorBoundary.tsx +19 -51
  64. package/src/createInstance.tsx +5 -1
  65. package/src/debugger.ts +82 -0
  66. package/src/emulator.ts +10 -0
  67. package/src/helpers.tsx +6 -2
  68. package/src/modules/core.ts +10 -8
  69. package/src/modules/dependencies.ts +3 -2
  70. package/src/state/withApi.test.tsx +20 -4
  71. package/src/state/withApi.tsx +51 -42
  72. package/src/types/api.ts +23 -9
  73. package/src/types/state.ts +13 -3
  74. package/src/types/utils.ts +1 -1
  75. package/src/utils/index.ts +2 -0
  76. package/debug-pilet.js +0 -12
  77. package/debug-piral.js +0 -59
@@ -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 { PiletMetadata, EventEmitter, Pilet, BaseComponentProps, PageComponentProps, ExtensionComponentProps, PiletsBag, PiralPageMeta } from './api';
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<PiletMetadata>;
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 a pilet at runtime - removes the pilet from registry first if available.
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.
@@ -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
  }
@@ -1,3 +1,4 @@
1
+ export { isfunc, requireModule } from 'piral-base';
1
2
  export * from './compare';
2
3
  export * from './data';
3
4
  export * from './extension';
@@ -1,3 +1,4 @@
1
+ export { isfunc, requireModule } from 'piral-base';
1
2
  export * from './compare';
2
3
  export * from './data';
3
4
  export * from './extension';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEnD,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC"}
@@ -1,8 +1,10 @@
1
1
  import { ComponentType } from 'react';
2
2
  import { RouteComponentProps } from 'react-router';
3
- import { LayoutType, ComponentsState, ErrorComponentsState, GlobalStateContext, Pilet } from '../types';
3
+ import { LayoutType, ComponentsState, ErrorComponentsState, GlobalStateContext, Pilet, PiletEntry } from '../types';
4
4
  export declare function changeLayout(ctx: GlobalStateContext, current: LayoutType): void;
5
5
  export declare function initialize(ctx: GlobalStateContext, loading: boolean, error: Error | undefined, modules: Array<Pilet>): void;
6
+ export declare function addPilet(ctx: GlobalStateContext, meta: PiletEntry): void;
7
+ export declare function removePilet(ctx: GlobalStateContext, name: string): void;
6
8
  export declare function injectPilet(ctx: GlobalStateContext, pilet: Pilet): void;
7
9
  export declare function setComponent<TKey extends keyof ComponentsState>(ctx: GlobalStateContext, name: TKey, component: ComponentsState[TKey]): void;
8
10
  export declare function setErrorComponent<TKey extends keyof ErrorComponentsState>(ctx: GlobalStateContext, type: TKey, component: ErrorComponentsState[TKey]): void;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.includeProvider = exports.setRoute = exports.setErrorComponent = exports.setComponent = exports.injectPilet = exports.initialize = exports.changeLayout = void 0;
3
+ exports.includeProvider = exports.setRoute = exports.setErrorComponent = exports.setComponent = exports.injectPilet = exports.removePilet = exports.addPilet = exports.initialize = exports.changeLayout = void 0;
4
+ const piral_base_1 = require("piral-base");
4
5
  const utils_1 = require("../utils");
5
6
  function changeLayout(ctx, current) {
6
7
  ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { app: (0, utils_1.withKey)(state.app, 'layout', current) })));
@@ -11,6 +12,25 @@ function initialize(ctx, loading, error, modules) {
11
12
  loading }), modules })));
12
13
  }
13
14
  exports.initialize = initialize;
15
+ function addPilet(ctx, meta) {
16
+ ctx.options.loadPilet(meta).then((pilet) => {
17
+ try {
18
+ ctx.injectPilet(pilet);
19
+ (0, piral_base_1.runPilet)(ctx.options.createApi, pilet, ctx.options.hooks);
20
+ }
21
+ catch (error) {
22
+ console.error(error);
23
+ }
24
+ });
25
+ }
26
+ exports.addPilet = addPilet;
27
+ function removePilet(ctx, name) {
28
+ ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { modules: state.modules.filter((m) => m.name !== name), registry: (0, utils_1.removeNested)(state.registry, (m) => m.pilet === name) })));
29
+ ctx.emit('unload-pilet', {
30
+ name,
31
+ });
32
+ }
33
+ exports.removePilet = removePilet;
14
34
  function injectPilet(ctx, pilet) {
15
35
  ctx.dispatch((state) => (Object.assign(Object.assign({}, state), { modules: (0, utils_1.replaceOrAddItem)(state.modules, pilet, (m) => m.name === pilet.name), registry: (0, utils_1.removeNested)(state.registry, (m) => m.pilet === pilet.name) })));
16
36
  ctx.emit('unload-pilet', {
@@ -1 +1 @@
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/**
3
- * The options to be used for determining the boundary's behavior.
4
- */
5
- export interface ErrorBoundaryOptions<T> {
6
- /**
7
- * Callback to be used in case of an emitted error.
8
- * @param error The error caught by the boundary.
9
- */
10
- onError(error: Error): void;
2
+ import { Errors, PiletApi } from '../types';
3
+ export interface ErrorBoundaryProps {
11
4
  /**
12
- * Callback to be used when an error should be rendered.
13
- * @param error The error caught by the boundary.
14
- * @param props The props used by the boundary.
5
+ * The type of error to indicate when caught.
15
6
  */
16
- renderError?(error: Error, props: T): React.ReactNode;
7
+ errorType: keyof Errors;
17
8
  /**
18
- * Callback to used when no error should be rendered.
19
- * @param children The standard children to render.
20
- * @param props The props used by the boundary.
9
+ * The associated pilet api for the metadata.
21
10
  */
22
- renderChild(children: React.ReactNode, props: T): React.ReactNode;
11
+ piral: PiletApi;
23
12
  }
24
- /**
25
- * The props of the ErrorBoundary component.
26
- */
27
- export interface ErrorBoundaryProps<T> extends ErrorBoundaryOptions<T> {
28
- /**
29
- * The render props for the specific ErrorBoundary.
30
- */
31
- renderProps: T;
32
- }
33
- /**
34
- * The state of the ErrorBoundary component.
35
- */
36
13
  export interface ErrorBoundaryState {
37
14
  /**
38
15
  * The current error (if any) caught by the boundary.
@@ -40,10 +17,12 @@ export interface ErrorBoundaryState {
40
17
  error?: Error;
41
18
  }
42
19
  /**
43
- * The React component for catching errors and displaying error information.
20
+ * The component for catching errors and displaying error information.
44
21
  */
45
- export declare class ErrorBoundary<T> extends React.Component<ErrorBoundaryProps<T>, ErrorBoundaryState> {
46
- constructor(props: ErrorBoundaryProps<T>);
22
+ export declare class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoundaryState> {
23
+ state: {
24
+ error: any;
25
+ };
47
26
  componentDidCatch(error: Error): void;
48
- render(): React.ReactNode;
27
+ render(): JSX.Element;
49
28
  }
@@ -1,37 +1,35 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ErrorBoundary = void 0;
4
+ const tslib_1 = require("tslib");
4
5
  const React = require("react");
5
- const piral_base_1 = require("piral-base");
6
+ const components_1 = require("./components");
6
7
  /**
7
- * The React component for catching errors and displaying error information.
8
+ * The component for catching errors and displaying error information.
8
9
  */
9
10
  class ErrorBoundary extends React.Component {
10
- constructor(props) {
11
- super(props);
11
+ constructor() {
12
+ super(...arguments);
12
13
  this.state = {
13
14
  error: undefined,
14
15
  };
15
16
  }
16
17
  componentDidCatch(error) {
17
- const { onError } = this.props;
18
- if ((0, piral_base_1.isfunc)(onError)) {
19
- onError(error);
20
- }
18
+ const { piral, errorType } = this.props;
19
+ const pilet = piral.meta.name;
20
+ console.error(`[${pilet}] Exception in component of type "${errorType}".`, error);
21
21
  this.setState({
22
22
  error,
23
23
  });
24
24
  }
25
25
  render() {
26
- const { children, renderError, renderChild, renderProps } = this.props;
26
+ const _a = this.props, { children, piral, errorType } = _a, renderProps = (0, tslib_1.__rest)(_a, ["children", "piral", "errorType"]);
27
27
  const { error } = this.state;
28
+ const rest = renderProps;
28
29
  if (error) {
29
- if ((0, piral_base_1.isfunc)(renderError)) {
30
- return renderError(error, renderProps);
31
- }
32
- return React.createElement("div", { style: { whiteSpace: 'pre-wrap' } }, error && error.message);
30
+ return React.createElement(components_1.PiralError, Object.assign({ type: errorType, error: error }, rest));
33
31
  }
34
- return (0, piral_base_1.isfunc)(renderChild) ? renderChild(children, renderProps) : children;
32
+ return React.createElement(React.Suspense, { fallback: React.createElement(components_1.PiralLoadingIndicator, null) }, children);
35
33
  }
36
34
  }
37
35
  exports.ErrorBoundary = ErrorBoundary;
@@ -1 +1 @@
1
- {"version":3,"file":"ErrorBoundary.js","sourceRoot":"","sources":["../../src/components/ErrorBoundary.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AA6CpC;;GAEG;AACH,MAAa,aAAiB,SAAQ,KAAK,CAAC,SAAoD;IAC9F,YAAY,KAA4B;QACtC,KAAK,CAAC,KAAK,CAAC,CAAC;QACb,IAAI,CAAC,KA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,CAAC;QACxC,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC;QAC9B,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,qCAAqC,SAAS,IAAI,EAAE,KAAK,CAAC,CAAC;QAElF,IAAI,CAAC,QAAQ,CAAC;YACZ,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED,MAAM;QACJ,MAAM,KAAiD,IAAI,CAAC,KAAK,EAA3D,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,OAA+B,EAA1B,WAAW,2BAA5C,kCAA8C,CAAa,CAAC;QAClE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAC7B,MAAM,IAAI,GAAQ,WAAW,CAAC;QAE9B,IAAI,KAAK,EAAE;YACT,OAAO,oBAAC,uBAAU,kBAAC,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,IAAM,IAAI,EAAI,CAAC;SAChE;QAED,OAAO,oBAAC,KAAK,CAAC,QAAQ,IAAC,QAAQ,EAAE,oBAAC,kCAAqB,OAAG,IAAG,QAAQ,CAAkB,CAAC;IAC1F,CAAC;CACF;AA1BD,sCA0BC"}
@@ -38,7 +38,11 @@ function createInstance(config = {}) {
38
38
  const root = createApi({
39
39
  name: 'root',
40
40
  version: process.env.BUILD_PCKG_VERSION || '1.0.0',
41
- spec: '',
41
+ spec: 'v0',
42
+ basePath: '',
43
+ link: '',
44
+ config: {},
45
+ dependencies: {},
42
46
  });
43
47
  const options = (0, helpers_1.createPiletOptions)({
44
48
  context,
@@ -1 +1 @@
1
- {"version":3,"file":"createInstance.js","sourceRoot":"","sources":["../src/createInstance.tsx"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,2CAAuF;AACvF,uCAAiG;AACjG,mCAA2E;AAC3E,uCAA+C;AAC/C,mCAAqC;AAGrC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,SAAgB,cAAc,CAAC,SAA+B,EAAE;IAC9D,MAAM,E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AAE,MAAM;QACZ,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,OAAO;QAClD,IAAI,EAAE,IAAI;QACV,QAAQ,EAAE,EAAE;QACZ,IAAI,EAAE,EAAE;QACR,MAAM,EAAE,EAAE;QACV,YAAY,EAAE,EAAE;KACjB,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,IAAA,4BAAkB,EAAC;QACjC,OAAO;QACP,SAAS;QACT,OAAO;QACP,SAAS;QACT,eAAe;QACf,YAAY;QACZ,iBAAiB;QACjB,QAAQ,EAAE,IAAA,mBAAM,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,4BAAe,CAAC,CAAC,CAAC,6BAAgB;QAC5E,aAAa;QACb,KAAK;KACN,CAAC,CAAC;IAEH,IAAI,OAAO,EAAE;QACX,IAAA,sBAAc,EAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KAClC;IAED,OAAO,CAAC,OAAO,GAAG,OAAO,CAAC;IAE1B,OAAO,IAAA,gBAAQ,EAAC,MAAM,EAAE;QACtB,EAAE;QACF,SAAS;QACT,OAAO;QACP,IAAI;QACJ,OAAO;KACR,CAAC,CAAC;AACL,CAAC;AAzDD,wCAyDC"}
@@ -0,0 +1,4 @@
1
+ import { LoadPiletsOptions } from 'piral-base';
2
+ import { DebuggerExtensionOptions } from 'piral-debug-utils';
3
+ import { GlobalStateContext } from './types';
4
+ export declare function integrate(context: GlobalStateContext, options: LoadPiletsOptions, debug?: DebuggerExtensionOptions): void;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.integrate = void 0;
4
+ const react_atom_1 = require("@dbeining/react-atom");
5
+ const piral_debug_utils_1 = require("piral-debug-utils");
6
+ function integrate(context, options, debug = {}) {
7
+ (0, piral_debug_utils_1.installPiralDebug)(Object.assign(Object.assign({}, debug), { addPilet: context.addPilet, removePilet: context.removePilet, updatePilet(pilet) {
8
+ if (!pilet.disabled) {
9
+ const { createApi } = options;
10
+ const newApi = createApi(pilet);
11
+ try {
12
+ context.injectPilet(pilet);
13
+ pilet.setup(newApi);
14
+ }
15
+ catch (error) {
16
+ console.error(error);
17
+ }
18
+ }
19
+ else {
20
+ context.injectPilet(pilet);
21
+ }
22
+ }, fireEvent: context.emit, getDependencies() {
23
+ return Object.keys(options.dependencies);
24
+ },
25
+ getExtensions() {
26
+ return context.readState((s) => Object.keys(s.registry.extensions));
27
+ },
28
+ getRoutes() {
29
+ const registeredRoutes = context.readState((state) => Object.keys(state.registry.pages));
30
+ const componentRoutes = context.readState((state) => Object.keys(state.routes));
31
+ return [...componentRoutes, ...registeredRoutes];
32
+ },
33
+ getGlobalState() {
34
+ return context.readState((s) => s);
35
+ },
36
+ getPilets() {
37
+ return context.readState((s) => s.modules);
38
+ },
39
+ integrate(dbg) {
40
+ context.dispatch((s) => (Object.assign(Object.assign({}, s), { components: Object.assign(Object.assign({}, s.components), dbg.components), routes: Object.assign(Object.assign({}, s.routes), dbg.routes), registry: Object.assign(Object.assign({}, s.registry), { wrappers: Object.assign(Object.assign({}, s.registry.wrappers), dbg.wrappers) }) })));
41
+ (0, react_atom_1.addChangeHandler)(context.state, 'debugging', ({ previous, current }) => {
42
+ const pilets = current.modules !== previous.modules;
43
+ const pages = current.registry.pages !== previous.registry.pages || current.routes !== previous.routes;
44
+ const extensions = current.registry.extensions !== previous.registry.extensions;
45
+ const state = current !== previous;
46
+ dbg.onChange(previous, current, {
47
+ pilets,
48
+ pages,
49
+ extensions,
50
+ state,
51
+ });
52
+ });
53
+ } }));
54
+ }
55
+ exports.integrate = integrate;
56
+ //# sourceMappingURL=debugger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debugger.js","sourceRoot":"","sources":["../src/debugger.ts"],"names":[],"mappings":";;;AAAA,qDAAwD;AAExD,yDAAgF;AAGhF,SAAgB,SAAS,CACvB,OAA2B,EAC3B,OAA0B,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CAAC,IACD,CAAC;AACL,CAAC;AA5ED,8BA4EC"}
@@ -0,0 +1,3 @@
1
+ import { LoadPiletsOptions } from 'piral-base';
2
+ import { GlobalStateContext } from './types';
3
+ export declare function integrate(context: GlobalStateContext, options: LoadPiletsOptions): void;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.integrate = void 0;
4
+ const piral_debug_utils_1 = require("piral-debug-utils");
5
+ function integrate(context, options) {
6
+ options.fetchPilets = (0, piral_debug_utils_1.withEmulatorPilets)(options.fetchPilets, {
7
+ addPilet: context.addPilet,
8
+ removePilet: context.removePilet,
9
+ });
10
+ }
11
+ exports.integrate = integrate;
12
+ //# sourceMappingURL=emulator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"emulator.js","sourceRoot":"","sources":["../src/emulator.ts"],"names":[],"mappings":";;;AACA,yDAAuD;AAGvD,SAAgB,SAAS,CAAC,OAA2B,EAAE,OAA0B;IAC/E,OAAO,CAAC,WAAW,GAAG,IAAA,sCAAkB,EAAC,OAAO,CAAC,WAAW,EAAE;QAC5D,QAAQ,EAAE,OAAO,CAAC,QAAQ;QAC1B,WAAW,EAAE,OAAO,CAAC,WAAW;KACjC,CAAC,CAAC;AACL,CAAC;AALD,8BAKC"}
package/lib/helpers.d.ts CHANGED
@@ -1,8 +1,9 @@
1
- import { PiletApiCreator, LoadPiletsOptions, CustomSpecLoaders, DefaultLoaderConfig, PiletLoader } from 'piral-base';
1
+ import { PiletApiCreator, LoadPiletsOptions, CustomSpecLoaders, DefaultLoaderConfig, PiletLoader, PiletLifecycleHooks } from 'piral-base';
2
2
  import { DebuggerExtensionOptions } from 'piral-debug-utils';
3
3
  import type { Pilet, PiletRequester, GlobalStateContext, PiletLoadingStrategy, DependencySelector } from './types';
4
4
  export interface PiletOptionsConfig {
5
5
  context: GlobalStateContext;
6
+ hooks?: PiletLifecycleHooks;
6
7
  loaders?: CustomSpecLoaders;
7
8
  loaderConfig?: DefaultLoaderConfig;
8
9
  availablePilets: Array<Pilet>;
@@ -13,4 +14,4 @@ export interface PiletOptionsConfig {
13
14
  shareDependencies: DependencySelector;
14
15
  debug?: DebuggerExtensionOptions;
15
16
  }
16
- export declare function createPiletOptions({ context, loaders, loaderConfig, availablePilets, strategy, createApi, loadPilet, requestPilets, shareDependencies, debug, }: PiletOptionsConfig): LoadPiletsOptions;
17
+ export declare function createPiletOptions({ hooks, context, loaders, loaderConfig, availablePilets, strategy, createApi, loadPilet, requestPilets, shareDependencies, debug, }: PiletOptionsConfig): LoadPiletsOptions;
package/lib/helpers.js CHANGED
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createPiletOptions = void 0;
4
4
  const piral_base_1 = require("piral-base");
5
5
  const modules_1 = require("./modules");
6
- function createPiletOptions({ context, loaders, loaderConfig, availablePilets, strategy, createApi, loadPilet, requestPilets, shareDependencies, debug, }) {
6
+ function createPiletOptions({ hooks, context, loaders, loaderConfig, availablePilets, strategy, createApi, loadPilet, requestPilets, shareDependencies, debug, }) {
7
7
  const options = {
8
8
  config: loaderConfig,
9
9
  strategy,
@@ -11,16 +11,17 @@ function createPiletOptions({ context, loaders, loaderConfig, availablePilets, s
11
11
  createApi,
12
12
  pilets: availablePilets,
13
13
  fetchPilets: requestPilets,
14
+ hooks,
14
15
  dependencies: shareDependencies(modules_1.globalDependencies),
15
16
  };
16
17
  // if we build the debug version of piral (debug and emulator build)
17
18
  if (process.env.DEBUG_PIRAL) {
18
- const { integrate } = require('../debug-piral');
19
+ const { integrate } = require('./debugger');
19
20
  integrate(context, options, debug);
20
21
  }
21
22
  // if we build the emulator version of piral (shipped to pilets)
22
23
  if (process.env.DEBUG_PILET) {
23
- const { integrate } = require('../debug-pilet');
24
+ const { integrate } = require('./emulator');
24
25
  integrate(context, options);
25
26
  }
26
27
  return options;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.tsx"],"names":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,EAAE,YAAY;QACpB,QAAQ;QACR,SAAS,EAAE,IAAA,yBAAY,EAAC,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,IAAA,6BAAgB,EAAC,YAAY,CAAC,EAAE,OAAO,CAAC;QAC7E,SAAS;QACT,MAAM,EAAE,eAAe;QACvB,WAAW,EAAE,aAAa;QAC1B,KAAK;QACL,YAAY,EAAE,iBAAiB,CAAC,4BAAkB,CAAC;KACpD,CAAC;IAEF,oEAAoE;IACpE,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE;QAC3B,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;QAC5C,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;KACpC;IAED,gEAAgE;IAChE,IAAI,OAAO,CAAC,GAAG,CAAC,WAAW,EAAE;QAC3B,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;QAC5C,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;KAC7B;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AArCD,gDAqCC"}
@@ -17,25 +17,27 @@ function createCoreApi(context) {
17
17
  const expiration = (0, utils_1.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 = (0, state_1.withApi)(context, arg, api, 'page', undefined, { meta });
21
22
  context.registerPage(route, {
22
23
  pilet,
23
24
  meta,
24
- component: (0, state_1.withApi)(context, arg, api, 'page'),
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, arg, defaults) {
32
+ registerExtension(name, reference, defaults) {
33
+ const component = (0, state_1.withApi)(context, reference, api, 'extension');
32
34
  context.registerExtension(name, {
33
35
  pilet,
34
- component: (0, state_1.withApi)(context, arg, api, 'extension'),
35
- reference: arg,
36
+ component,
37
+ reference,
36
38
  defaults,
37
39
  });
38
- return () => api.unregisterExtension(name, arg);
40
+ return () => api.unregisterExtension(name, reference);
39
41
  },
40
42
  unregisterExtension(name, arg) {
41
43
  context.unregisterExtension(name, arg);
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","sourceRoot":"","sources":["../../src/modules/core.ts"],"names":[],"mappings":";;;AACA,uCAA0C;AAC1C,oCAAmC;AACnC,8CAA8C;AAC9C,oCAAgE;AAGhE,SAAgB,aAAa,CAAC,OAA2B;IACvD,OAAO,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC;QACxB,OAAO;YACL,OAAO,CAAC,IAAI;gBACV,OAAO,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;YACrC,CAAC;YACD,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO;gBAC1B,MAAM,EAAE,MAAM,GAAG,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAA,yBAAiB,EAAC,OAAO,CAAC,CAAC;gBAClE,MAAM,UAAU,GAAG,IAAA,yBAAiB,EAAC,OAAO,CAAC,CAAC;gBAC9C,OAAO,OAAO,CAAC,gBAAgB,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;YAC1E,CAAC;YACD,YAAY,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI;gBAC3B,OAAO,CAAC,YAAY,CAAC,KAAK,EAAE;oBAC1B,KAAK;oBACL,IAAI;oBACJ,SAAS,EAAE,IAAA,eAAO,EAAC,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC;iBAC9C,CAAC,CAAC;gBACH,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YACzC,CAAC;YACD,cAAc,CAAC,KAAK;gBA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C,OAAO,CAAC,GAAG,IAAA,uBAAa,EAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;gBACzD,OAAO,OAAO,CAAC;YACjB,CAAC;YACD,SAAS,EAAE,0BAAa;SACzB,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AA5CD,sCA4CC"}
@@ -1,4 +1,4 @@
1
- import { PiletMetadata, AvailableDependencies } from 'piral-base';
1
+ import type { AvailableDependencies, PiletEntries } from '../types';
2
2
  /**
3
3
  * The global dependencies, which represent the dependencies
4
4
  * shared from the app shell itself.
@@ -20,4 +20,4 @@ return fetch('https://feed.piral.cloud/api/v1/pilet/sample')
20
20
  .then(res => res.items);
21
21
  ```
22
22
  */
23
- export declare function defaultModuleRequester(): Promise<Array<PiletMetadata>>;
23
+ export declare function defaultModuleRequester(): Promise<PiletEntries>;
@@ -1 +1 @@
1
- {"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../../src/modules/dependencies.ts"],"names":[],"mappings":";;;AAAA,2CAA0E;AAC1E,iCAAiC;AAEjC;;;GAGG;AACU,QAAA,kBAAkB,GAA0B,EAAE,CAAC;AAE5D,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE;IACnC,MAAM,gBAAgB,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;IAE/D,IAAI,IAAA,mBAAM,EAAC,gBAAgB,CAAC,EAAE;QAC5B,gBAAgB,CAAC,0BAAkB,CAAC,CAAC;KACtC;SAAM;QACL,0EAA0E;QAC1E,IAAA,gBAAQ,EAAC,0BAAkB,EAAE;YAC3B,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC;YACvB,WAAW,EAAE,OAAO,CAAC,WAAW,CAAC;YACjC,cAAc,EAAE,OAAO,CAAC,cAAc,CAAC;YACvC,kBAAkB,EAAE,OAAO,CAAC,kBAAkB,CAAC;YAC/C,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC;YAC3B,KAAK,EAAE,OAAO,CAAC,OAAO,CAAC;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AAsB,CAAC;SACxD,CAAC,CAAC;KACJ;CACF;KAAM;IACL,kFAAkF;CACnF;AAED;;;GAGG;AACH,SAAgB,yBAAyB,CAAC,YAAmC;IAC3E,OAAO,YAAY,CAAC;AACtB,CAAC;AAFD,8DAEC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,sBAAsB;IACpC,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAC7B,CAAC;AAFD,wDAEC"}
@@ -1,3 +1,3 @@
1
1
  import * as React from 'react';
2
2
  import { AnyComponent, Errors, PiletApi, BaseComponentProps, GlobalStateContext } from '../types';
3
- export declare function withApi<TProps>(context: GlobalStateContext, component: AnyComponent<TProps & BaseComponentProps>, piral: PiletApi, errorType: keyof Errors, wrapperType?: string): React.MemoExoticComponent<(props: TProps) => JSX.Element> | React.ComponentType<TProps>;
3
+ export declare function withApi<TProps>(context: GlobalStateContext, component: AnyComponent<TProps & BaseComponentProps>, piral: PiletApi, errorType: keyof Errors, wrapperType?: string, captured?: {}): React.MemoExoticComponent<(props: TProps) => JSX.Element> | React.ComponentType<TProps>;
@@ -59,57 +59,55 @@ class ForeignComponentContainer extends React.Component {
59
59
  return React.createElement("div", { "data-portal-id": $portalId, ref: this.setNode });
60
60
  }
61
61
  }
62
- function wrapReactComponent(Component, stasisOptions, piral, Wrapper) {
63
- return (props) => (React.createElement(Wrapper, Object.assign({}, props, { piral: piral }),
64
- React.createElement(components_1.ErrorBoundary, Object.assign({}, stasisOptions, { renderProps: props }),
65
- React.createElement(Component, Object.assign({}, props, { piral: piral })))));
62
+ function wrapReactComponent(Component, captured, Wrapper) {
63
+ return (props) => (React.createElement(Wrapper, Object.assign({}, props),
64
+ React.createElement(Component, Object.assign({}, props, captured))));
66
65
  }
67
- function wrapForeignComponent(component, stasisOptions, piral, Wrapper) {
66
+ function wrapForeignComponent(component, captured, Wrapper) {
68
67
  return React.memo((props) => {
69
68
  const { state, readState, destroyPortal } = (0, hooks_1.useGlobalStateContext)();
70
69
  const router = React.useContext(react_router_1.__RouterContext);
71
70
  const id = React.useMemo(() => (portalIdBase++).toString(26), utils_1.none);
72
71
  const context = React.useMemo(() => ({ router, state, readState }), [router, state]);
73
- const innerProps = React.useMemo(() => (Object.assign(Object.assign({}, props), { piral })), [props]);
72
+ const innerProps = React.useMemo(() => (Object.assign(Object.assign({}, props), captured)), [props]);
74
73
  React.useEffect(() => () => destroyPortal(id), utils_1.none);
75
- return (React.createElement(Wrapper, Object.assign({}, innerProps),
76
- React.createElement(components_1.ErrorBoundary, Object.assign({}, stasisOptions, { renderProps: props }),
77
- React.createElement(components_1.PortalRenderer, { id: id }),
78
- React.createElement(ForeignComponentContainer, { innerProps: innerProps, "$portalId": id, "$component": component, "$context": context }))));
74
+ return (React.createElement(Wrapper, Object.assign({}, props),
75
+ React.createElement(components_1.PortalRenderer, { id: id }),
76
+ React.createElement(ForeignComponentContainer, { innerProps: innerProps, "$portalId": id, "$component": component, "$context": context })));
79
77
  });
80
78
  }
81
79
  function isNotExotic(component) {
82
80
  return !component.$$typeof;
83
81
  }
84
- function wrapComponent(converters, component, piral, Wrapper, stasisOptions) {
85
- if (!component) {
86
- console.error('The given value is not a valid component.');
87
- // tslint:disable-next-line:no-null-keyword
88
- component = () => null;
89
- }
82
+ function wrapComponent(converters, component, captured, Wrapper) {
90
83
  if (typeof component === 'object' && isNotExotic(component)) {
91
84
  const result = (0, utils_1.convertComponent)(converters[component.type], component);
92
- return wrapForeignComponent(result, stasisOptions, piral, Wrapper);
85
+ return wrapForeignComponent(result, captured, Wrapper);
93
86
  }
94
- return wrapReactComponent(component, stasisOptions, piral, Wrapper);
87
+ return wrapReactComponent(component, captured, Wrapper);
95
88
  }
96
89
  function getWrapper(wrappers, wrapperType) {
97
- return wrappers[wrapperType] || wrappers['*'] || DefaultWrapper;
90
+ const WrapAll = wrappers['*'];
91
+ const WrapType = wrappers[wrapperType];
92
+ if (WrapAll && WrapType) {
93
+ return (props) => (React.createElement(WrapAll, Object.assign({}, props),
94
+ React.createElement(WrapType, Object.assign({}, props))));
95
+ }
96
+ return WrapType || WrapAll || DefaultWrapper;
98
97
  }
99
- function withApi(context, component, piral, errorType, wrapperType = errorType) {
98
+ function withApi(context, component, piral, errorType, wrapperType = errorType, captured = {}) {
99
+ const outerProps = Object.assign(Object.assign({}, captured), { piral });
100
100
  const converters = context.converters;
101
- const Wrapper = context.readState((m) => getWrapper(m.registry.wrappers, wrapperType));
102
- return wrapComponent(converters, component, piral, Wrapper, {
103
- onError(error) {
104
- console.error(piral, error);
105
- },
106
- renderChild(child) {
107
- return React.createElement(React.Suspense, { fallback: React.createElement(components_1.PiralLoadingIndicator, null) }, child);
108
- },
109
- renderError(error, props) {
110
- return React.createElement(components_1.PiralError, Object.assign({ type: errorType, error: error }, props));
111
- },
112
- });
101
+ const OuterWrapper = context.readState((m) => getWrapper(m.registry.wrappers, wrapperType));
102
+ const Wrapper = (props) => (React.createElement(OuterWrapper, Object.assign({}, outerProps, props),
103
+ React.createElement(components_1.ErrorBoundary, Object.assign({}, outerProps, props, { errorType: errorType }), props.children)));
104
+ if (!component) {
105
+ const pilet = piral.meta.name;
106
+ console.error(`[${pilet}] The given value is not a valid component.`);
107
+ // tslint:disable-next-line:no-null-keyword
108
+ component = () => null;
109
+ }
110
+ return wrapComponent(converters, component, outerProps, Wrapper);
113
111
  }
114
112
  exports.withApi = withApi;
115
113
  //# sourceMappingURL=withApi.js.map