piral-core 0.15.0-alpha.3555 → 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 (51) hide show
  1. package/esm/components/ErrorBoundary.d.ts +12 -33
  2. package/esm/components/ErrorBoundary.js +12 -14
  3. package/esm/components/ErrorBoundary.js.map +1 -1
  4. package/{debug-piral.d.ts → esm/debugger.d.ts} +1 -1
  5. package/esm/debugger.js +52 -0
  6. package/esm/debugger.js.map +1 -0
  7. package/{debug-pilet.d.ts → esm/emulator.d.ts} +1 -1
  8. package/esm/emulator.js +8 -0
  9. package/esm/emulator.js.map +1 -0
  10. package/esm/helpers.js +2 -2
  11. package/esm/helpers.js.map +1 -1
  12. package/esm/modules/core.js +8 -6
  13. package/esm/modules/core.js.map +1 -1
  14. package/esm/state/withApi.d.ts +1 -1
  15. package/esm/state/withApi.js +31 -33
  16. package/esm/state/withApi.js.map +1 -1
  17. package/esm/types/api.d.ts +12 -8
  18. package/esm/utils/index.d.ts +1 -0
  19. package/esm/utils/index.js +1 -0
  20. package/esm/utils/index.js.map +1 -1
  21. package/lib/components/ErrorBoundary.d.ts +12 -33
  22. package/lib/components/ErrorBoundary.js +12 -14
  23. package/lib/components/ErrorBoundary.js.map +1 -1
  24. package/lib/debugger.d.ts +4 -0
  25. package/lib/debugger.js +56 -0
  26. package/lib/debugger.js.map +1 -0
  27. package/lib/emulator.d.ts +3 -0
  28. package/{debug-pilet.js → lib/emulator.js} +4 -3
  29. package/lib/emulator.js.map +1 -0
  30. package/lib/helpers.js +2 -2
  31. package/lib/helpers.js.map +1 -1
  32. package/lib/modules/core.js +8 -6
  33. package/lib/modules/core.js.map +1 -1
  34. package/lib/state/withApi.d.ts +1 -1
  35. package/lib/state/withApi.js +30 -32
  36. package/lib/state/withApi.js.map +1 -1
  37. package/lib/types/api.d.ts +12 -8
  38. package/lib/utils/index.d.ts +1 -0
  39. package/lib/utils/index.js +4 -0
  40. package/lib/utils/index.js.map +1 -1
  41. package/package.json +9 -11
  42. package/src/components/ErrorBoundary.tsx +19 -51
  43. package/src/debugger.ts +82 -0
  44. package/src/emulator.ts +10 -0
  45. package/src/helpers.tsx +2 -2
  46. package/src/modules/core.ts +10 -8
  47. package/src/state/withApi.test.tsx +20 -4
  48. package/src/state/withApi.tsx +51 -42
  49. package/src/types/api.ts +23 -9
  50. package/src/utils/index.ts +2 -0
  51. package/debug-piral.js +0 -72
@@ -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,EAC1B,QAAkC,EAAE;IAEpC,IAAA,qCAAiB,kCACZ,KAAK,KACR,QAAQ,EAAE,OAAO,CAAC,QAAQ,EAC1B,WAAW,EAAE,OAAO,CAAC,WAAW,EAChC,WAAW,CAAC,KAAK;YACf,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE;gBACnB,MAAM,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;gBAC9B,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,CAAC;gBAEhC,IAAI;oBACF,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;oBAC3B,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;iBACrB;gBAAC,OAAO,KAAK,EAAE;oBACd,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;iBACtB;aACF;iBAAM;gBACL,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;aAC5B;QACH,CAAC,EACD,SAAS,EAAE,OAAO,CAAC,IAAI,EACvB,eAAe;YACb,OAAO,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;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E,EAAE;gBACrE,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,KAAK,QAAQ,CAAC,OAAO,CAAC;gBACpD,MAAM,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC,KAAK,KAAK,QAAQ,CAAC,QAAQ,CAAC,KAAK,IAAI,OAAO,CAAC,MAAM,KAAK,QAAQ,CAAC,MAAM,CAAC;gBACvG,MAAM,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,UAAU,KAAK,QAAQ,CAAC,QAAQ,CAAC,UAAU,CAAC;gBAChF,MAAM,KAAK,GAAG,OAAO,KAAK,QAAQ,CAAC;gBACnC,GAAG,CAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,EAAE;oBAC9B,MAAM;oBACN,KAAK;oBACL,UAAU;oBACV,KAAK;iBACN,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;QACL,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;
@@ -1,11 +1,12 @@
1
1
  "use strict";
2
- exports.__esModule = true;
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.integrate = void 0;
4
- var piral_debug_utils_1 = require("piral-debug-utils");
4
+ const piral_debug_utils_1 = require("piral-debug-utils");
5
5
  function integrate(context, options) {
6
6
  options.fetchPilets = (0, piral_debug_utils_1.withEmulatorPilets)(options.fetchPilets, {
7
7
  addPilet: context.addPilet,
8
- removePilet: context.removePilet
8
+ removePilet: context.removePilet,
9
9
  });
10
10
  }
11
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.js CHANGED
@@ -16,12 +16,12 @@ function createPiletOptions({ hooks, context, loaders, loaderConfig, availablePi
16
16
  };
17
17
  // if we build the debug version of piral (debug and emulator build)
18
18
  if (process.env.DEBUG_PIRAL) {
19
- const { integrate } = require('../debug-piral');
19
+ const { integrate } = require('./debugger');
20
20
  integrate(context, options, debug);
21
21
  }
22
22
  // if we build the emulator version of piral (shipped to pilets)
23
23
  if (process.env.DEBUG_PILET) {
24
- const { integrate } = require('../debug-pilet');
24
+ const { integrate } = require('./emulator');
25
25
  integrate(context, options);
26
26
  }
27
27
  return options;
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.tsx"],"names":[],"mappings":";;;AAAA,2CASoB;AAEpB,uCAA+C;AAiB/C,SAAgB,kBAAkB,CAAC,EACjC,KAAK,EACL,OAAO,EACP,OAAO,EACP,YAAY,EACZ,eAAe,EACf,QAAQ,EACR,SAAS,EACT,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,KAAK,GACc;IACnB,MAAM,OAAO,GAAsB;QACjC,MAAM,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,S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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,I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AAC,KAAK,CAAC,CAAC;YACzC,CAAC;YACD,cAAc,CAAC,KAAK;gBAClB,OAAO,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC;YAChC,CAAC;YACD,iBAAiB,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ;gBACzC,MAAM,SAAS,GAAG,IAAA,eAAO,EAAC,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,WAAW,CAAC,CAAC;gBAChE,OAAO,CAAC,iBAAiB,CAAC,IAAI,EAAE;oBAC9B,KAAK;oBACL,SAAS;oBACT,SAAS;oBACT,QAAQ;iBACT,CAAC,CAAC;gBACH,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,mBAAmB,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YACxD,CAAC;YACD,mBAAmB,CAAC,IAAI,EAAE,GAAG;gBAC3B,OAAO,CAAC,mBAAmB,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;YACzC,CAAC;YACD,mBAAmB,CAAC,OAAO,EAAE,KAAK;gBAChC,MAAM,CAAC,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,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
@@ -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,8CAAuH;AACvH,oCAAiD;AACjD,oCAAiE;AAYjE,qDAAqD;AACrD,IAAI,YAAY,GAAG,MAAM,CAAC;AAE1B,MAAM,cAAc,GAAa,CAAC,KAAK,EAAE,EAAE,CAAC,IAAA,qBAAa,EAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAS1E,MAAM,yBAA6B,SAAQ,KAAK,CAAC,SAA4C;IAA7F;;QAGU,YAAO,GAAG,CAAC,EAAe,EAAE,EAAE;YACpC,MAAM,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;YAClC,EAAE,CAAC,eAAe,EAAE,CAAC;YACrB,UAAU,CAAC,KAAK,CAAC,mBAAmB,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAC1E,CAAC,CAAC;QAEM,YAAO,GAAG,CAAC,IAAoB,EAAE,EAAE;YACzC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACtB,CAAC,CAAC;IA6CJ,CAAC;IA3CC,iBAAiB;QACf,MAAM,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC;QAC1B,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QACxD,MAAM,EAAE,KAAK,EAAE,GAAG,UAAU,CAAC;QAE7B,IAAI,IAAI,IAAI,IAAA,m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2
2
  import type { RouteComponentProps } from 'react-router';
3
- import type { PiletApi, Pilet, PiletEntry, PiletEntries, PiletMetadata, EventEmitter } from 'piral-base';
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, PiletEntry, PiletEntries };
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
- * The meta data registered for a page.
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
  }
@@ -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,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);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":";;;AAAA,yDAA0B;AAC1B,sDAAuB;AACvB,2DAA4B;AAC5B,yDAA0B;AAC1B,sDAAuB;AACvB,yDAA0B;AAC1B,uDAAwB;AACxB,uDAAwB;AACxB,uDAAwB;AACxB,yDAA0B"}
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.3555",
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 && yarn build:convert",
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.3555",
54
- "piral-debug-utils": "0.15.0-alpha.3555"
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": "0727a5c782dd1bbc7ccaa11a036a9f16e616bf10"
79
+ "gitHead": "e5af009799d073993a1c415c4ee63029f9b3d547"
82
80
  }
@@ -1,42 +1,18 @@
1
1
  import * as React from 'react';
2
- import { isfunc } from 'piral-base';
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
- * Callback to be used when an error should be rendered.
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
- renderError?(error: Error, props: T): React.ReactNode;
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 render props for the specific ErrorBoundary.
11
+ * The associated pilet api for the metadata.
33
12
  */
34
- renderProps: T;
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 React component for catching errors and displaying error information.
24
+ * The component for catching errors and displaying error information.
49
25
  */
50
- export class ErrorBoundary<T> extends React.Component<ErrorBoundaryProps<T>, ErrorBoundaryState> {
51
- constructor(props: ErrorBoundaryProps<T>) {
52
- super(props);
53
- this.state = {
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 { onError } = this.props;
60
-
61
- if (isfunc(onError)) {
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, renderError, renderChild, renderProps } = this.props;
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
- if (isfunc(renderError)) {
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 isfunc(renderChild) ? renderChild(children, renderProps) : children;
50
+ return <React.Suspense fallback={<PiralLoadingIndicator />}>{children}</React.Suspense>;
83
51
  }
84
52
  }
@@ -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
+ }
@@ -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
@@ -52,13 +52,13 @@ export function createPiletOptions({
52
52
 
53
53
  // if we build the debug version of piral (debug and emulator build)
54
54
  if (process.env.DEBUG_PIRAL) {
55
- const { integrate } = require('../debug-piral');
55
+ const { integrate } = require('./debugger');
56
56
  integrate(context, options, debug);
57
57
  }
58
58
 
59
59
  // if we build the emulator version of piral (shipped to pilets)
60
60
  if (process.env.DEBUG_PILET) {
61
- const { integrate } = require('../debug-pilet');
61
+ const { integrate } = require('./emulator');
62
62
  integrate(context, options);
63
63
  }
64
64