piral-core 0.15.0-alpha.3555 → 0.15.0-alpha.3640

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 (105) hide show
  1. package/debug.codegen +24 -0
  2. package/debug.codegen.d.ts +11 -0
  3. package/dependencies.codegen +6 -4
  4. package/dependencies.codegen.d.ts +1 -0
  5. package/dependencies.codegen.native.js +1 -1
  6. package/esm/RootListener.js +1 -1
  7. package/esm/RootListener.js.map +1 -1
  8. package/esm/components/ErrorBoundary.d.ts +12 -33
  9. package/esm/components/ErrorBoundary.js +12 -14
  10. package/esm/components/ErrorBoundary.js.map +1 -1
  11. package/esm/components/ExtensionSlot.js +20 -2
  12. package/esm/components/ExtensionSlot.js.map +1 -1
  13. package/esm/components/ForeignComponentContainer.d.ts +19 -0
  14. package/esm/components/ForeignComponentContainer.js +52 -0
  15. package/esm/components/ForeignComponentContainer.js.map +1 -0
  16. package/esm/components/index.d.ts +1 -0
  17. package/esm/components/index.js +1 -0
  18. package/esm/components/index.js.map +1 -1
  19. package/esm/components/wrapComponent.d.ts +7 -0
  20. package/esm/components/wrapComponent.js +42 -0
  21. package/esm/components/wrapComponent.js.map +1 -0
  22. package/esm/createInstance.js +1 -1
  23. package/esm/createInstance.js.map +1 -1
  24. package/esm/debugger.d.ts +4 -0
  25. package/esm/debugger.js +52 -0
  26. package/esm/debugger.js.map +1 -0
  27. package/esm/emulator.d.ts +3 -0
  28. package/esm/emulator.js +8 -0
  29. package/esm/emulator.js.map +1 -0
  30. package/esm/helpers.d.ts +1 -1
  31. package/esm/helpers.js +3 -10
  32. package/esm/helpers.js.map +1 -1
  33. package/esm/modules/core.js +8 -6
  34. package/esm/modules/core.js.map +1 -1
  35. package/esm/modules/dependencies.js +3 -23
  36. package/esm/modules/dependencies.js.map +1 -1
  37. package/esm/state/withApi.d.ts +1 -1
  38. package/esm/state/withApi.js +17 -103
  39. package/esm/state/withApi.js.map +1 -1
  40. package/esm/types/api.d.ts +14 -10
  41. package/esm/types/extension.d.ts +5 -1
  42. package/esm/utils/index.d.ts +1 -0
  43. package/esm/utils/index.js +1 -0
  44. package/esm/utils/index.js.map +1 -1
  45. package/lib/RootListener.js +2 -2
  46. package/lib/RootListener.js.map +1 -1
  47. package/lib/components/ErrorBoundary.d.ts +12 -33
  48. package/lib/components/ErrorBoundary.js +12 -14
  49. package/lib/components/ErrorBoundary.js.map +1 -1
  50. package/lib/components/ExtensionSlot.js +19 -1
  51. package/lib/components/ExtensionSlot.js.map +1 -1
  52. package/lib/components/ForeignComponentContainer.d.ts +19 -0
  53. package/lib/components/ForeignComponentContainer.js +56 -0
  54. package/lib/components/ForeignComponentContainer.js.map +1 -0
  55. package/lib/components/index.d.ts +1 -0
  56. package/lib/components/index.js +1 -0
  57. package/lib/components/index.js.map +1 -1
  58. package/lib/components/wrapComponent.d.ts +7 -0
  59. package/lib/components/wrapComponent.js +46 -0
  60. package/lib/components/wrapComponent.js.map +1 -0
  61. package/lib/createInstance.js +1 -1
  62. package/lib/createInstance.js.map +1 -1
  63. package/lib/debugger.d.ts +4 -0
  64. package/lib/debugger.js +56 -0
  65. package/lib/debugger.js.map +1 -0
  66. package/lib/emulator.d.ts +3 -0
  67. package/lib/emulator.js +12 -0
  68. package/lib/emulator.js.map +1 -0
  69. package/lib/helpers.d.ts +1 -1
  70. package/lib/helpers.js +3 -10
  71. package/lib/helpers.js.map +1 -1
  72. package/lib/modules/core.js +8 -6
  73. package/lib/modules/core.js.map +1 -1
  74. package/lib/modules/dependencies.js +3 -23
  75. package/lib/modules/dependencies.js.map +1 -1
  76. package/lib/state/withApi.d.ts +1 -1
  77. package/lib/state/withApi.js +15 -101
  78. package/lib/state/withApi.js.map +1 -1
  79. package/lib/types/api.d.ts +14 -10
  80. package/lib/types/extension.d.ts +5 -1
  81. package/lib/utils/index.d.ts +1 -0
  82. package/lib/utils/index.js +4 -0
  83. package/lib/utils/index.js.map +1 -1
  84. package/package.json +12 -12
  85. package/src/RootListener.tsx +1 -1
  86. package/src/components/ErrorBoundary.tsx +19 -51
  87. package/src/components/ExtensionSlot.tsx +25 -3
  88. package/src/components/ForeignComponentContainer.tsx +69 -0
  89. package/src/components/index.ts +1 -0
  90. package/src/components/wrapComponent.tsx +74 -0
  91. package/src/createInstance.tsx +1 -1
  92. package/src/debugger.ts +82 -0
  93. package/src/emulator.ts +10 -0
  94. package/src/helpers.tsx +4 -12
  95. package/src/modules/core.ts +10 -8
  96. package/src/modules/dependencies.ts +3 -22
  97. package/src/state/withApi.test.tsx +20 -4
  98. package/src/state/withApi.tsx +31 -157
  99. package/src/types/api.ts +25 -11
  100. package/src/types/extension.ts +12 -3
  101. package/src/utils/index.ts +2 -0
  102. package/debug-pilet.d.ts +0 -3
  103. package/debug-pilet.js +0 -11
  104. package/debug-piral.d.ts +0 -4
  105. package/debug-piral.js +0 -72
@@ -1,32 +1,12 @@
1
1
  import { isfunc } from 'piral-base';
2
- import { __assign } from 'tslib';
2
+ import fillDependencies from '../../dependencies.codegen';
3
3
  /**
4
4
  * The global dependencies, which represent the dependencies
5
5
  * shared from the app shell itself.
6
6
  */
7
7
  export const globalDependencies = {};
8
- if (process.env.SHARED_DEPENDENCIES) {
9
- const fillDependencies = require('../../dependencies.codegen');
10
- if (isfunc(fillDependencies)) {
11
- fillDependencies(globalDependencies);
12
- }
13
- else {
14
- // fall back to the default list if the codegen is invalid / not supported
15
- __assign(globalDependencies, {
16
- react: require('react'),
17
- 'react-dom': require('react-dom'),
18
- 'react-router': require('react-router'),
19
- 'react-router-dom': require('react-router-dom'),
20
- history: require('history'),
21
- tslib: require('tslib'),
22
- 'path-to-regexp': require('path-to-regexp'),
23
- '@libre/atom': require('@libre/atom'),
24
- '@dbeining/react-atom': require('@dbeining/react-atom'),
25
- });
26
- }
27
- }
28
- else {
29
- // App shell is built with something else than the Piral CLI - just don't fill ...
8
+ if (isfunc(fillDependencies)) {
9
+ fillDependencies(globalDependencies);
30
10
  }
31
11
  /**
32
12
  * The default dependency selector, which just returns the provided
@@ -1 +1 @@
1
- {"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../../src/modules/dependencies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGjC;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA0B,EAAE,CAAC;AAE5D,IAAI,OAAO,CAAC,GAAG,CAAC,mBAAmB,EAAE;IACnC,MAAM,gBAAgB,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;IAE/D,IAAI,MAAM,CAAC,gBAAgB,CAAC,EAAE;QAC5B,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;KACtC;SAAM;QACL,0EAA0E;QAC1E,QAAQ,CAAC,kBAAkB,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;YACvB,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,CAAC;YAC3C,aAAa,EAAE,OAAO,CAAC,aAAa,CAAC;YACrC,sBAAsB,EAAE,OAAO,CAAC,sBAAsB,CAAC;SACxD,CAAC,CAAC;KACJ;CACF;KAAM;IACL,kFAAkF;CACnF;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,YAAmC;IAC3E,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAC7B,CAAC"}
1
+ {"version":3,"file":"dependencies.js","sourceRoot":"","sources":["../../src/modules/dependencies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEpC,OAAO,gBAAgB,MAAM,4BAA4B,CAAC;AAE1D;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAA0B,EAAE,CAAC;AAE5D,IAAI,MAAM,CAAC,gBAAgB,CAAC,EAAE;IAC5B,gBAAgB,CAAC,kBAAkB,CAAC,CAAC;CACtC;AAED;;;GAGG;AACH,MAAM,UAAU,yBAAyB,CAAC,YAAmC;IAC3E,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;AAC7B,CAAC"}
@@ -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>;
@@ -1,111 +1,25 @@
1
1
  import * as React from 'react';
2
- import { isfunc } from 'piral-base';
3
- import { __RouterContext } from 'react-router';
4
- import { PiralError, PiralLoadingIndicator, ErrorBoundary, PortalRenderer } from '../components';
5
- import { useGlobalStateContext } from '../hooks';
6
- import { defaultRender, convertComponent, none } from '../utils';
7
- // this is an arbitrary start number to have 6 digits
8
- let portalIdBase = 123456;
2
+ import { ErrorBoundary, wrapComponent } from '../components';
3
+ import { defaultRender } from '../utils';
9
4
  const DefaultWrapper = (props) => defaultRender(props.children);
10
- class ForeignComponentContainer extends React.Component {
11
- constructor() {
12
- super(...arguments);
13
- this.handler = (ev) => {
14
- const { innerProps } = this.props;
15
- ev.stopPropagation();
16
- innerProps.piral.renderHtmlExtension(ev.detail.target, ev.detail.props);
17
- };
18
- this.setNode = (node) => {
19
- this.current = node;
20
- };
21
- }
22
- componentDidMount() {
23
- const node = this.current;
24
- const { $component, $context, innerProps } = this.props;
25
- const { mount } = $component;
26
- if (node && isfunc(mount)) {
27
- mount(node, innerProps, $context);
28
- node.addEventListener('render-html', this.handler, false);
29
- }
30
- this.previous = node;
31
- }
32
- componentDidUpdate() {
33
- const { current, previous } = this;
34
- const { $component, $context, innerProps } = this.props;
35
- const { update } = $component;
36
- if (current !== previous) {
37
- previous && this.componentWillUnmount();
38
- current && this.componentDidMount();
39
- }
40
- else if (isfunc(update)) {
41
- update(current, innerProps, $context);
42
- }
43
- }
44
- componentWillUnmount() {
45
- const node = this.previous;
46
- const { $component } = this.props;
47
- const { unmount } = $component;
48
- if (node && isfunc(unmount)) {
49
- unmount(node);
50
- node.removeEventListener('render-html', this.handler, false);
51
- }
52
- this.previous = undefined;
53
- }
54
- render() {
55
- const { $portalId } = this.props;
56
- return React.createElement("div", { "data-portal-id": $portalId, ref: this.setNode });
57
- }
58
- }
59
- function wrapReactComponent(Component, stasisOptions, piral, Wrapper) {
60
- return (props) => (React.createElement(Wrapper, Object.assign({}, props, { piral: piral }),
61
- React.createElement(ErrorBoundary, Object.assign({}, stasisOptions, { renderProps: props }),
62
- React.createElement(Component, Object.assign({}, props, { piral: piral })))));
63
- }
64
- function wrapForeignComponent(component, stasisOptions, piral, Wrapper) {
65
- return React.memo((props) => {
66
- const { state, readState, destroyPortal } = useGlobalStateContext();
67
- const router = React.useContext(__RouterContext);
68
- const id = React.useMemo(() => (portalIdBase++).toString(26), none);
69
- const context = React.useMemo(() => ({ router, state, readState }), [router, state]);
70
- const innerProps = React.useMemo(() => (Object.assign(Object.assign({}, props), { piral })), [props]);
71
- React.useEffect(() => () => destroyPortal(id), none);
72
- return (React.createElement(Wrapper, Object.assign({}, innerProps),
73
- React.createElement(ErrorBoundary, Object.assign({}, stasisOptions, { renderProps: props }),
74
- React.createElement(PortalRenderer, { id: id }),
75
- React.createElement(ForeignComponentContainer, { innerProps: innerProps, "$portalId": id, "$component": component, "$context": context }))));
76
- });
77
- }
78
- function isNotExotic(component) {
79
- return !component.$$typeof;
80
- }
81
- function wrapComponent(converters, component, piral, Wrapper, stasisOptions) {
82
- if (!component) {
83
- console.error('The given value is not a valid component.');
84
- // tslint:disable-next-line:no-null-keyword
85
- component = () => null;
86
- }
87
- if (typeof component === 'object' && isNotExotic(component)) {
88
- const result = convertComponent(converters[component.type], component);
89
- return wrapForeignComponent(result, stasisOptions, piral, Wrapper);
5
+ function getWrapper(wrappers, wrapperType) {
6
+ const WrapAll = wrappers['*'];
7
+ const WrapType = wrappers[wrapperType];
8
+ if (WrapAll && WrapType) {
9
+ return (props) => (React.createElement(WrapAll, Object.assign({}, props),
10
+ React.createElement(WrapType, Object.assign({}, props))));
90
11
  }
91
- return wrapReactComponent(component, stasisOptions, piral, Wrapper);
12
+ return WrapType || WrapAll || DefaultWrapper;
92
13
  }
93
- function getWrapper(wrappers, wrapperType) {
94
- return wrappers[wrapperType] || wrappers['*'] || DefaultWrapper;
14
+ function makeWrapper(context, outerProps, wrapperType, errorType) {
15
+ const OuterWrapper = context.readState((m) => getWrapper(m.registry.wrappers, wrapperType));
16
+ return (props) => (React.createElement(OuterWrapper, Object.assign({}, outerProps, props),
17
+ React.createElement(ErrorBoundary, Object.assign({}, outerProps, props, { errorType: errorType }), props.children)));
95
18
  }
96
- export function withApi(context, component, piral, errorType, wrapperType = errorType) {
19
+ export function withApi(context, component, piral, errorType, wrapperType = errorType, captured = {}) {
20
+ const outerProps = Object.assign(Object.assign({}, captured), { piral });
97
21
  const converters = context.converters;
98
- const Wrapper = context.readState((m) => getWrapper(m.registry.wrappers, wrapperType));
99
- return wrapComponent(converters, component, piral, Wrapper, {
100
- onError(error) {
101
- console.error(piral, error);
102
- },
103
- renderChild(child) {
104
- return React.createElement(React.Suspense, { fallback: React.createElement(PiralLoadingIndicator, null) }, child);
105
- },
106
- renderError(error, props) {
107
- return React.createElement(PiralError, Object.assign({ type: errorType, error: error }, props));
108
- },
109
- });
22
+ const Wrapper = makeWrapper(context, outerProps, wrapperType, errorType);
23
+ return wrapComponent(converters, component, outerProps, Wrapper);
110
24
  }
111
25
  //# sourceMappingURL=withApi.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"withApi.js","sourceRoot":"","sources":["../../src/state/withApi.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,aAAa,EAAwB,cAAc,EAAE,MAAM,eAAe,CAAC;AACvH,OAAO,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAYjE,qDAAqD;AACrD,IAAI,YAAY,GAAG,MAAM,CAAC;AAE1B,MAAM,cAAc,GAAa,CAAC,KAAK,EAAE,EAAE,CAAC,aAAa,CAAC,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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AAC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AACnE,CAAC"}
@@ -1,12 +1,12 @@
1
1
  import type { ReactElement } from 'react';
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
- import type { ExtensionSlotProps, PiralExtensionSlotMap } from './extension';
6
+ import type { ExtensionParams, 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.
@@ -89,7 +93,7 @@ export interface PiletCoreApi {
89
93
  * @param Component The component to be rendered.
90
94
  * @param defaults Optionally, sets the default values for the expected data.
91
95
  */
92
- registerExtension<TName>(name: TName extends string ? TName : string, Component: AnyComponent<ExtensionComponentProps<TName>>, defaults?: TName): RegistrationDisposer;
96
+ registerExtension<TName>(name: TName extends string ? TName : string, Component: AnyComponent<ExtensionComponentProps<TName>>, defaults?: Partial<ExtensionParams<TName>>): RegistrationDisposer;
93
97
  /**
94
98
  * Unregisters a global extension component.
95
99
  * Only previously registered extension components can be unregistered.
@@ -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
  }
@@ -32,7 +32,11 @@ export interface BaseExtensionSlotProps<TName, TParams> {
32
32
  */
33
33
  name: TName;
34
34
  }
35
+ /**
36
+ * Gives the extension params shape for the given extension slot name.
37
+ */
38
+ export declare type ExtensionParams<TName> = TName extends keyof PiralExtensionSlotMap ? PiralExtensionSlotMap[TName] : TName extends string ? any : TName;
35
39
  /**
36
40
  * The props for defining an extension slot.
37
41
  */
38
- export declare type ExtensionSlotProps<K = string> = BaseExtensionSlotProps<K extends string ? K : string, K extends keyof PiralExtensionSlotMap ? PiralExtensionSlotMap[K] : K extends string ? any : K>;
42
+ export declare type ExtensionSlotProps<TName = string> = BaseExtensionSlotProps<TName extends string ? TName : string, ExtensionParams<TName>>;
@@ -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"}
@@ -2,10 +2,10 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RootListener = void 0;
4
4
  const React = require("react");
5
- const _1 = require(".");
5
+ const hooks_1 = require("./hooks");
6
6
  const modules_1 = require("./modules");
7
7
  const RootListener = () => {
8
- const context = (0, _1.useGlobalStateContext)();
8
+ const context = (0, hooks_1.useGlobalStateContext)();
9
9
  React.useLayoutEffect(() => {
10
10
  if (typeof document !== 'undefined') {
11
11
  const handler = (ev) => {
@@ -1 +1 @@
1
- {"version":3,"file":"RootListener.js","sourceRoot":"","sources":["../src/RootListener.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,wBAA0C;AAC1C,uCAA0C;AAEnC,MAAM,YAAY,GAAa,GAAG,EAAE;IACzC,MAAM,OAAO,GAAG,IAAA,wBAAqB,GAAE,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AAE,CAAC,MAAM,CAAC;gBACpC,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,GAAG,IAAA,uBAAa,EAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;gBAChE,MAAM,CAAC,OAAO,GAAG,OAAO,CAAC;gBACzB,MAAM,CAAC,MAAM,GAAG,MAAM,CAAC;YACzB,CAAC,CAAC;YACF,QAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;YAE9D,OAAO,GAAG,EAAE;gBACV,QAAQ,CAAC,IAAI,CAAC,mBAAmB,CAAC,aAAa,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;YACnE,CAAC,CAAC;SACH;IACH,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IAEd,OAAO,IAAI,CAAC;AACd,CAAC,CAAC;AArBW,QAAA,YAAY,gBAqBvB"}
@@ -1,38 +1,15 @@
1
1
  import * as React from 'react';
2
- /**
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,KAAK,GAAG;YACX,KAAK,EAAE,SAAS;SACjB,CAAC;IACJ,CAAC;IAED,iBAAiB,CAAC,KAAY;QAC5B,MAAM,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAE/B,IAAI,IAAA,mBAAM,EAAC,OAAO,CAAC,EAAE;YACnB,OAAO,CAAC,KAAK,CAAC,CAAC;SAChB;QAED,IAAI,CAAC,QAAQ,CAAC;YACZ,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED,MAAM;QACJ,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QACvE,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QAE7B,IAAI,KAAK,EAAE;YACT,IAAI,IAAA,mBAAM,EAAC,WAAW,CAAC,EAAE;gBACvB,OAAO,WAAW,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;aACxC;YAED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C,KAAK,CAAC,QAAQ,IAAC,QAAQ,EAAE,oBAAC,kCAAqB,OAAG,IAAG,QAAQ,CAAkB,CAAC;IAC1F,CAAC;CACF;AA1BD,sCA0BC"}
@@ -3,8 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ExtensionSlot = void 0;
4
4
  const React = require("react");
5
5
  const piral_base_1 = require("piral-base");
6
+ const wrapComponent_1 = require("./wrapComponent");
6
7
  const hooks_1 = require("../hooks");
7
8
  const utils_1 = require("../utils");
9
+ const renderExtensions = [
10
+ {
11
+ component: (props) => {
12
+ const context = (0, hooks_1.useGlobalStateContext)();
13
+ const converters = context.converters;
14
+ const piral = context.apis._;
15
+ const { component, props: args } = props.params;
16
+ const Component = React.useMemo(() => (0, wrapComponent_1.wrapComponent)(converters, component, { piral }, utils_1.defaultRender), [component]);
17
+ return React.createElement(Component, Object.assign({}, args));
18
+ },
19
+ defaults: {},
20
+ pilet: '',
21
+ reference: {
22
+ displayName: 'RenderExtension',
23
+ },
24
+ },
25
+ ];
8
26
  /**
9
27
  * The extension slot component to be used when the available
10
28
  * extensions of a given name should be rendered at a specific
@@ -12,7 +30,7 @@ const utils_1 = require("../utils");
12
30
  */
13
31
  function ExtensionSlot(props) {
14
32
  const { name, render = utils_1.defaultRender, empty, params, children } = props;
15
- const extensions = (0, hooks_1.useGlobalState)((s) => s.registry.extensions[name] || utils_1.none);
33
+ const extensions = (0, hooks_1.useGlobalState)((s) => (name ? s.registry.extensions[name] || utils_1.none : renderExtensions));
16
34
  return render(extensions.length === 0 && (0, piral_base_1.isfunc)(empty)
17
35
  ? [(0, utils_1.defaultRender)(empty(), 'empty')]
18
36
  : extensions.map(({ component: Component, reference, defaults = {} }, i) => (React.createElement(Component, { key: `${(reference === null || reference === void 0 ? void 0 : reference.displayName) || '_'}${i}`, children: children, params: Object.assign(Object.assign({}, defaults), (params || {})) }))));
@@ -1 +1 @@
1
- {"version":3,"file":"ExtensionSlot.js","sourceRoot":"","sources":["../../src/components/ExtensionSlot.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AACpC,oCAA0C;AAC1C,oCAA+C;AAG/C;;;;GAIG;AACH,SAAgB,aAAa,CAAmB,KAA4B;IAC1E,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,qBAAa,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,CAAC;IACxE,MAAM,UAAU,GAAG,IAAA,sBAAc,EAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,YAAI,CAAC,CAAC;IAC9E,OAAO,MAAM,CACX,UAAU,CAAC,MAAM,KAAK,CAAC,IAAI,IAAA,mBAAM,EAAC,KAAK,CAAC;QACtC,CAAC,CAAC,CAAC,IAAA,qBAAa,EAAC,KAAK,EAAE,EAAE,OAAO,CAAC,CAAC;QACnC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CACxE,oBAAC,SAAS,IACR,GAAG,EAAE,GAAG,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,WAAW,KAAI,GAAG,GAAG,CAAC,EAAE,EAC3C,QAAQ,EAAE,QAAQ,EAClB,MAAM,kCACD,QAAQ,GACR,CAAC,MAAM,IAAI,EAAE,CAAC,IAEnB,CACH,CAAC,CACP,CAAC;AACJ,CAAC;AAjBD,sCAiBC;AAED,aAAa,CAAC,WAAW,GAAG,eAAe,CAAC"}
1
+ {"version":3,"file":"ExtensionSlot.js","sourceRoot":"","sources":["../../src/components/ExtensionSlot.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AACpC,mDAAgD;AAChD,oCAAiE;AACjE,oCAA+C;AAG/C,MAAM,gBAAgB,GAA4B;IAChD;QACE,S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SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,GAAG,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CACxE,oBAAC,SAAS,IACR,GAAG,EAAE,GAAG,CAAA,SAAS,aAAT,SAAS,uBAAT,SAAS,CAAE,WAAW,KAAI,GAAG,GAAG,CAAC,EAAE,EAC3C,QAAQ,EAAE,QAAQ,EAClB,MAAM,kCACD,QAAQ,GACR,CAAC,MAAM,IAAI,EAAE,CAAC,IAEnB,CACH,CAAC,CACP,CAAC;AACJ,CAAC;AAjBD,sCAiBC;AAED,aAAa,CAAC,WAAW,GAAG,eAAe,CAAC"}
@@ -0,0 +1,19 @@
1
+ import * as React from 'react';
2
+ import { ForeignComponent, BaseComponentProps, ComponentContext } from '../types';
3
+ interface ForeignComponentContainerProps<T> {
4
+ $portalId: string;
5
+ $component: ForeignComponent<T>;
6
+ $context: ComponentContext;
7
+ innerProps: T & BaseComponentProps;
8
+ }
9
+ export declare class ForeignComponentContainer<T> extends React.Component<ForeignComponentContainerProps<T>> {
10
+ private current?;
11
+ private previous?;
12
+ private handler;
13
+ private setNode;
14
+ componentDidMount(): void;
15
+ componentDidUpdate(): void;
16
+ componentWillUnmount(): void;
17
+ render(): JSX.Element;
18
+ }
19
+ export {};
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ForeignComponentContainer = void 0;
4
+ const React = require("react");
5
+ const piral_base_1 = require("piral-base");
6
+ class ForeignComponentContainer extends React.Component {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.handler = (ev) => {
10
+ const { innerProps } = this.props;
11
+ ev.stopPropagation();
12
+ innerProps.piral.renderHtmlExtension(ev.detail.target, ev.detail.props);
13
+ };
14
+ this.setNode = (node) => {
15
+ this.current = node;
16
+ };
17
+ }
18
+ componentDidMount() {
19
+ const node = this.current;
20
+ const { $component, $context, innerProps } = this.props;
21
+ const { mount } = $component;
22
+ if (node && (0, piral_base_1.isfunc)(mount)) {
23
+ mount(node, innerProps, $context);
24
+ node.addEventListener('render-html', this.handler, false);
25
+ }
26
+ this.previous = node;
27
+ }
28
+ componentDidUpdate() {
29
+ const { current, previous } = this;
30
+ const { $component, $context, innerProps } = this.props;
31
+ const { update } = $component;
32
+ if (current !== previous) {
33
+ previous && this.componentWillUnmount();
34
+ current && this.componentDidMount();
35
+ }
36
+ else if ((0, piral_base_1.isfunc)(update)) {
37
+ update(current, innerProps, $context);
38
+ }
39
+ }
40
+ componentWillUnmount() {
41
+ const node = this.previous;
42
+ const { $component } = this.props;
43
+ const { unmount } = $component;
44
+ if (node && (0, piral_base_1.isfunc)(unmount)) {
45
+ unmount(node);
46
+ node.removeEventListener('render-html', this.handler, false);
47
+ }
48
+ this.previous = undefined;
49
+ }
50
+ render() {
51
+ const { $portalId } = this.props;
52
+ return React.createElement("div", { "data-portal-id": $portalId, ref: this.setNode });
53
+ }
54
+ }
55
+ exports.ForeignComponentContainer = ForeignComponentContainer;
56
+ //# sourceMappingURL=ForeignComponentContainer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ForeignComponentContainer.js","sourceRoot":"","sources":["../../src/components/ForeignComponentContainer.tsx"],"names":[],"mappings":";;;AAAA,+BAA+B;AAC/B,2CAAoC;AAWpC,MAAa,yBAA6B,SAAQ,KAAK,CAAC,SAA4C;IAApG;;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;IA6C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;YACd,IAAI,CAAC,mBAAmB,CAAC,aAAa,EAAE,IAAI,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;SAC9D;QAED,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;IAC5B,CAAC;IAED,MAAM;QACJ,MAAM,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC;QACjC,OAAO,+CAAqB,SAAS,EAAE,GAAG,EAAE,IAAI,CAAC,OAAO,GAAI,CAAC;IAC/D,CAAC;CACF;AAxDD,8DAwDC"}
@@ -18,3 +18,4 @@ export * from './SetProvider';
18
18
  export * from './SetRedirect';
19
19
  export * from './SetRoute';
20
20
  export * from './SwitchErrorInfo';
21
+ export * from './wrapComponent';
@@ -21,4 +21,5 @@ const tslib_1 = require("tslib");
21
21
  (0, tslib_1.__exportStar)(require("./SetRedirect"), exports);
22
22
  (0, tslib_1.__exportStar)(require("./SetRoute"), exports);
23
23
  (0, tslib_1.__exportStar)(require("./SwitchErrorInfo"), exports);
24
+ (0, tslib_1.__exportStar)(require("./wrapComponent"), exports);
24
25
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":";;;AAAA,4DAA6B;AAC7B,kEAAmC;AACnC,+DAAgC;AAChC,+DAAgC;AAChC,+DAAgC;AAChC,+DAAgC;AAChC,+DAAgC;AAChC,0DAA2B;AAC3B,6DAA8B;AAC9B,2DAA4B;AAC5B,gEAAiC;AACjC,kEAAmC;AACnC,8DAA+B;AAC/B,0DAA2B;AAC3B,2DAA4B;AAC5B,2DAA4B;AAC5B,6DAA8B;AAC9B,6DAA8B;AAC9B,0DAA2B;AAC3B,iEAAkC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/components/index.ts"],"names":[],"mappings":";;;AAAA,4DAA6B;AAC7B,kEAAmC;AACnC,+DAAgC;AAChC,+DAAgC;AAChC,+DAAgC;AAChC,+DAAgC;AAChC,+DAAgC;AAChC,0DAA2B;AAC3B,6DAA8B;AAC9B,2DAA4B;AAC5B,gEAAiC;AACjC,kEAAmC;AACnC,8DAA+B;AAC/B,0DAA2B;AAC3B,2DAA4B;AAC5B,2DAA4B;AAC5B,6DAA8B;AAC9B,6DAA8B;AAC9B,0DAA2B;AAC3B,iEAAkC;AAClC,+DAAgC"}
@@ -0,0 +1,7 @@
1
+ import * as React from 'react';
2
+ import { AnyComponent, ComponentConverters, PiletApi, BaseComponentProps } from '../types';
3
+ interface CapturedProps {
4
+ piral: PiletApi;
5
+ }
6
+ export declare function wrapComponent<T>(converters: ComponentConverters<T & BaseComponentProps>, component: AnyComponent<T & BaseComponentProps>, captured: CapturedProps, Wrapper: React.FC<T>): React.MemoExoticComponent<(props: T) => JSX.Element> | React.ComponentType<T>;
7
+ export {};