piral-core 0.15.0-alpha.3589 → 0.15.0-alpha.3711

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 (87) 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.js +2 -1
  9. package/esm/components/ErrorBoundary.js.map +1 -1
  10. package/esm/components/ExtensionSlot.js +20 -2
  11. package/esm/components/ExtensionSlot.js.map +1 -1
  12. package/esm/components/ForeignComponentContainer.d.ts +19 -0
  13. package/esm/components/ForeignComponentContainer.js +52 -0
  14. package/esm/components/ForeignComponentContainer.js.map +1 -0
  15. package/esm/components/index.d.ts +1 -0
  16. package/esm/components/index.js +1 -0
  17. package/esm/components/index.js.map +1 -1
  18. package/esm/components/wrapComponent.d.ts +7 -0
  19. package/esm/components/wrapComponent.js +42 -0
  20. package/esm/components/wrapComponent.js.map +1 -0
  21. package/esm/createInstance.js +1 -1
  22. package/esm/createInstance.js.map +1 -1
  23. package/esm/debugger.d.ts +1 -1
  24. package/esm/debugger.js +1 -1
  25. package/esm/debugger.js.map +1 -1
  26. package/esm/emulator.d.ts +1 -1
  27. package/esm/emulator.js +1 -1
  28. package/esm/emulator.js.map +1 -1
  29. package/esm/helpers.d.ts +1 -1
  30. package/esm/helpers.js +3 -10
  31. package/esm/helpers.js.map +1 -1
  32. package/esm/modules/dependencies.js +3 -23
  33. package/esm/modules/dependencies.js.map +1 -1
  34. package/esm/state/withApi.js +8 -92
  35. package/esm/state/withApi.js.map +1 -1
  36. package/esm/types/api.d.ts +2 -2
  37. package/esm/types/components.d.ts +12 -0
  38. package/esm/types/extension.d.ts +5 -1
  39. package/lib/RootListener.js +2 -2
  40. package/lib/RootListener.js.map +1 -1
  41. package/lib/components/ErrorBoundary.js +2 -1
  42. package/lib/components/ErrorBoundary.js.map +1 -1
  43. package/lib/components/ExtensionSlot.js +19 -1
  44. package/lib/components/ExtensionSlot.js.map +1 -1
  45. package/lib/components/ForeignComponentContainer.d.ts +19 -0
  46. package/lib/components/ForeignComponentContainer.js +56 -0
  47. package/lib/components/ForeignComponentContainer.js.map +1 -0
  48. package/lib/components/index.d.ts +1 -0
  49. package/lib/components/index.js +1 -0
  50. package/lib/components/index.js.map +1 -1
  51. package/lib/components/wrapComponent.d.ts +7 -0
  52. package/lib/components/wrapComponent.js +46 -0
  53. package/lib/components/wrapComponent.js.map +1 -0
  54. package/lib/createInstance.js +1 -1
  55. package/lib/createInstance.js.map +1 -1
  56. package/lib/debugger.d.ts +1 -1
  57. package/lib/debugger.js +3 -3
  58. package/lib/debugger.js.map +1 -1
  59. package/lib/emulator.d.ts +1 -1
  60. package/lib/emulator.js +3 -3
  61. package/lib/emulator.js.map +1 -1
  62. package/lib/helpers.d.ts +1 -1
  63. package/lib/helpers.js +3 -10
  64. package/lib/helpers.js.map +1 -1
  65. package/lib/modules/dependencies.js +3 -23
  66. package/lib/modules/dependencies.js.map +1 -1
  67. package/lib/state/withApi.js +7 -91
  68. package/lib/state/withApi.js.map +1 -1
  69. package/lib/types/api.d.ts +2 -2
  70. package/lib/types/components.d.ts +12 -0
  71. package/lib/types/extension.d.ts +5 -1
  72. package/package.json +8 -5
  73. package/src/RootListener.tsx +1 -1
  74. package/src/components/ErrorBoundary.tsx +2 -1
  75. package/src/components/ExtensionSlot.tsx +25 -3
  76. package/src/components/ForeignComponentContainer.tsx +69 -0
  77. package/src/components/index.ts +1 -0
  78. package/src/components/wrapComponent.tsx +74 -0
  79. package/src/createInstance.tsx +1 -1
  80. package/src/debugger.ts +1 -1
  81. package/src/emulator.ts +1 -1
  82. package/src/helpers.tsx +4 -12
  83. package/src/modules/dependencies.ts +3 -22
  84. package/src/state/withApi.tsx +21 -156
  85. package/src/types/api.ts +2 -2
  86. package/src/types/components.ts +12 -0
  87. package/src/types/extension.ts +12 -3
@@ -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,8CAA8D;AAC9D,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;AAa1E,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,mBAAM,EAAC,KAAK,CAAC,EAAE;YACzB,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,CAAC,CAAC;YAClC,IAAI,CAAC,gBAAgB,CAAC,aAAa,EAAE,IAAI,CAAC,OAAO,EAAE,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EACnB,SAAuB;IAEvB,MAAM,YAAY,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC,CAAC;IAE5F,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAChB,oBAAC,YAAY,oBAAK,UAAU,EAAM,KAAK;QACrC,oBAAC,0BAAa,oBAAK,UAAU,EAAM,KAAK,IAAE,SAAS,EAAE,SAAS,KAC3D,KAAK,CAAC,QAAQ,CACD,CACH,CAChB,CAAC;AACJ,CAAC;AAED,SAAgB,OAAO,CACrB,OAA2B,EAC3B,SAAoD,EACpD,KAAe,EACf,SAAuB,EACvB,cAAsB,SAAS,EAC/B,QAAQ,GAAG,EAAE;IAEb,MAAM,UAAU,mCAAQ,QAAQ,KAAE,KAAK,GAAE,CAAC;IAC1C,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC;IACtC,MAAM,OAAO,GAAG,WAAW,CAAS,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,CAAC,CAAC;IACjF,OAAO,IAAA,0BAAa,EAAC,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;AACnE,CAAC;AAZD,0BAYC"}
@@ -3,7 +3,7 @@ import type { RouteComponentProps } from 'react-router';
3
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
9
  export { PiletApi, Pilet, PiletMetadata, EventEmitter, PiletEntry, PiletEntries, PiletLoader, PiletLoadingStrategy };
@@ -93,7 +93,7 @@ export interface PiletCoreApi {
93
93
  * @param Component The component to be rendered.
94
94
  * @param defaults Optionally, sets the default values for the expected data.
95
95
  */
96
- 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;
97
97
  /**
98
98
  * Unregisters a global extension component.
99
99
  * Only previously registered extension components can be unregistered.
@@ -81,6 +81,10 @@ export interface PageErrorInfoProps extends RouteComponentProps {
81
81
  * The provided error details.
82
82
  */
83
83
  error: any;
84
+ /**
85
+ * The name of the pilet emitting the error.
86
+ */
87
+ pilet?: string;
84
88
  }
85
89
  /**
86
90
  * The error used when the app could not be loaded.
@@ -107,6 +111,10 @@ export interface ExtensionErrorInfoProps {
107
111
  * The provided error details.
108
112
  */
109
113
  error: any;
114
+ /**
115
+ * The name of the pilet emitting the error.
116
+ */
117
+ pilet?: string;
110
118
  }
111
119
  /**
112
120
  * The error used when the exact type is unknown.
@@ -120,6 +128,10 @@ export interface UnknownErrorInfoProps {
120
128
  * The provided error details.
121
129
  */
122
130
  error: any;
131
+ /**
132
+ * The name of the pilet emitting the error.
133
+ */
134
+ pilet?: string;
123
135
  }
124
136
  /**
125
137
  * Map of all error types to their respective props.
@@ -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>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "piral-core",
3
- "version": "0.15.0-alpha.3589",
3
+ "version": "0.15.0-alpha.3711",
4
4
  "description": "The core library for creating a Piral instance.",
5
5
  "keywords": [
6
6
  "portal",
@@ -22,8 +22,10 @@
22
22
  "esm",
23
23
  "lib",
24
24
  "src",
25
+ "debug.codegen",
26
+ "debug.codegen.*",
25
27
  "dependencies.codegen",
26
- "dependencies.codegen.native.js"
28
+ "dependencies.codegen.*"
27
29
  ],
28
30
  "funding": {
29
31
  "type": "github",
@@ -37,6 +39,7 @@
37
39
  "url": "https://github.com/smapiot/piral/issues"
38
40
  },
39
41
  "scripts": {
42
+ "cleanup": "rimraf esm lib",
40
43
  "build": "yarn build:commonjs && yarn build:esnext",
41
44
  "build:commonjs": "tsc --project tsconfig.json --outDir lib --module commonjs",
42
45
  "build:esnext": "tsc --project tsconfig.json --outDir esm --module esnext",
@@ -45,8 +48,8 @@
45
48
  },
46
49
  "dependencies": {
47
50
  "@dbeining/react-atom": "^4.0.0",
48
- "piral-base": "0.15.0-alpha.3589",
49
- "piral-debug-utils": "0.15.0-alpha.3589"
51
+ "piral-base": "0.15.0-alpha.3711",
52
+ "piral-debug-utils": "0.15.0-alpha.3711"
50
53
  },
51
54
  "peerDependencies": {
52
55
  "react": ">=16.8.0",
@@ -76,5 +79,5 @@
76
79
  "@libre/atom",
77
80
  "@dbeining/react-atom"
78
81
  ],
79
- "gitHead": "3de80e7857d8f95c5f7c6944dfad56d4a5e21f8d"
82
+ "gitHead": "2ef676e46e2fb402edeceeb3b4f1a1aa04c99970"
80
83
  }
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { useGlobalStateContext } from '.';
2
+ import { useGlobalStateContext } from './hooks';
3
3
  import { renderElement } from './modules';
4
4
 
5
5
  export const RootListener: React.FC = () => {
@@ -44,7 +44,8 @@ export class ErrorBoundary extends React.Component<ErrorBoundaryProps, ErrorBoun
44
44
  const rest: any = renderProps;
45
45
 
46
46
  if (error) {
47
- return <PiralError type={errorType} error={error} {...rest} />;
47
+ const pilet = piral.meta.name;
48
+ return <PiralError type={errorType} error={error} pilet={pilet} {...rest} />;
48
49
  }
49
50
 
50
51
  return <React.Suspense fallback={<PiralLoadingIndicator />}>{children}</React.Suspense>;
@@ -1,8 +1,30 @@
1
1
  import * as React from 'react';
2
2
  import { isfunc } from 'piral-base';
3
- import { useGlobalState } from '../hooks';
3
+ import { wrapComponent } from './wrapComponent';
4
+ import { useGlobalState, useGlobalStateContext } from '../hooks';
4
5
  import { defaultRender, none } from '../utils';
5
- import { ExtensionSlotProps } from '../types';
6
+ import { ExtensionRegistration, ExtensionSlotProps } from '../types';
7
+
8
+ const renderExtensions: [ExtensionRegistration] = [
9
+ {
10
+ component: (props) => {
11
+ const context = useGlobalStateContext();
12
+ const converters = context.converters;
13
+ const piral = context.apis._;
14
+ const { component, props: args } = props.params;
15
+ const Component = React.useMemo(
16
+ () => wrapComponent(converters, component, { piral }, defaultRender),
17
+ [component],
18
+ );
19
+ return <Component {...args} />;
20
+ },
21
+ defaults: {},
22
+ pilet: '',
23
+ reference: {
24
+ displayName: 'RenderExtension',
25
+ },
26
+ },
27
+ ];
6
28
 
7
29
  /**
8
30
  * The extension slot component to be used when the available
@@ -11,7 +33,7 @@ import { ExtensionSlotProps } from '../types';
11
33
  */
12
34
  export function ExtensionSlot<T extends string>(props: ExtensionSlotProps<T>) {
13
35
  const { name, render = defaultRender, empty, params, children } = props;
14
- const extensions = useGlobalState((s) => s.registry.extensions[name] || none);
36
+ const extensions = useGlobalState((s) => (name ? s.registry.extensions[name] || none : renderExtensions));
15
37
  return render(
16
38
  extensions.length === 0 && isfunc(empty)
17
39
  ? [defaultRender(empty(), 'empty')]
@@ -0,0 +1,69 @@
1
+ import * as React from 'react';
2
+ import { isfunc } from 'piral-base';
3
+ import { __RouterContext } from 'react-router';
4
+ import { ForeignComponent, BaseComponentProps, ComponentContext } from '../types';
5
+
6
+ interface ForeignComponentContainerProps<T> {
7
+ $portalId: string;
8
+ $component: ForeignComponent<T>;
9
+ $context: ComponentContext;
10
+ innerProps: T & BaseComponentProps;
11
+ }
12
+
13
+ export class ForeignComponentContainer<T> extends React.Component<ForeignComponentContainerProps<T>> {
14
+ private current?: HTMLElement;
15
+ private previous?: HTMLElement;
16
+ private handler = (ev: CustomEvent) => {
17
+ const { innerProps } = this.props;
18
+ ev.stopPropagation();
19
+ innerProps.piral.renderHtmlExtension(ev.detail.target, ev.detail.props);
20
+ };
21
+
22
+ private setNode = (node: HTMLDivElement) => {
23
+ this.current = node;
24
+ };
25
+
26
+ componentDidMount() {
27
+ const node = this.current;
28
+ const { $component, $context, innerProps } = this.props;
29
+ const { mount } = $component;
30
+
31
+ if (node && isfunc(mount)) {
32
+ mount(node, innerProps, $context);
33
+ node.addEventListener('render-html', this.handler, false);
34
+ }
35
+
36
+ this.previous = node;
37
+ }
38
+
39
+ componentDidUpdate() {
40
+ const { current, previous } = this;
41
+ const { $component, $context, innerProps } = this.props;
42
+ const { update } = $component;
43
+
44
+ if (current !== previous) {
45
+ previous && this.componentWillUnmount();
46
+ current && this.componentDidMount();
47
+ } else if (isfunc(update)) {
48
+ update(current, innerProps, $context);
49
+ }
50
+ }
51
+
52
+ componentWillUnmount() {
53
+ const node = this.previous;
54
+ const { $component } = this.props;
55
+ const { unmount } = $component;
56
+
57
+ if (node && isfunc(unmount)) {
58
+ unmount(node);
59
+ node.removeEventListener('render-html', this.handler, false);
60
+ }
61
+
62
+ this.previous = undefined;
63
+ }
64
+
65
+ render() {
66
+ const { $portalId } = this.props;
67
+ return <div data-portal-id={$portalId} ref={this.setNode} />;
68
+ }
69
+ }
@@ -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';
@@ -0,0 +1,74 @@
1
+ import * as React from 'react';
2
+ import { __RouterContext } from 'react-router';
3
+ import { PortalRenderer } from './PortalRenderer';
4
+ import { ForeignComponentContainer } from './ForeignComponentContainer';
5
+ import { useGlobalStateContext } from '../hooks';
6
+ import { convertComponent, none } from '../utils';
7
+ import { AnyComponent, ComponentConverters, ForeignComponent, PiletApi, BaseComponentProps } from '../types';
8
+
9
+ // this is an arbitrary start number to have 6 digits
10
+ let portalIdBase = 123456;
11
+
12
+ interface CapturedProps {
13
+ piral: PiletApi;
14
+ }
15
+
16
+ function wrapReactComponent<T>(
17
+ Component: React.ComponentType<T & BaseComponentProps>,
18
+ captured: CapturedProps,
19
+ Wrapper: React.FC<T>,
20
+ ): React.ComponentType<T> {
21
+ return (props: T) => (
22
+ <Wrapper {...props}>
23
+ <Component {...props} {...captured} />
24
+ </Wrapper>
25
+ );
26
+ }
27
+
28
+ function wrapForeignComponent<T>(
29
+ component: ForeignComponent<T & BaseComponentProps>,
30
+ captured: CapturedProps,
31
+ Wrapper: React.FC<T>,
32
+ ) {
33
+ return React.memo((props: T) => {
34
+ const { state, readState, destroyPortal } = useGlobalStateContext();
35
+ const router = React.useContext(__RouterContext);
36
+ const id = React.useMemo(() => (portalIdBase++).toString(26), none);
37
+ const context = React.useMemo(() => ({ router, state, readState }), [router, state]);
38
+ const innerProps = React.useMemo(() => ({ ...props, ...captured }), [props]);
39
+
40
+ React.useEffect(() => () => destroyPortal(id), none);
41
+
42
+ return (
43
+ <Wrapper {...props}>
44
+ <PortalRenderer id={id} />
45
+ <ForeignComponentContainer innerProps={innerProps} $portalId={id} $component={component} $context={context} />
46
+ </Wrapper>
47
+ );
48
+ });
49
+ }
50
+
51
+ function isNotExotic(component: any): component is object {
52
+ return !(component as React.ExoticComponent).$$typeof;
53
+ }
54
+
55
+ export function wrapComponent<T>(
56
+ converters: ComponentConverters<T & BaseComponentProps>,
57
+ component: AnyComponent<T & BaseComponentProps>,
58
+ captured: CapturedProps,
59
+ Wrapper: React.FC<T>,
60
+ ) {
61
+ if (!component) {
62
+ const pilet = captured.piral.meta.name;
63
+ console.error(`[${pilet}] The given value is not a valid component.`);
64
+ // tslint:disable-next-line:no-null-keyword
65
+ component = () => null;
66
+ }
67
+
68
+ if (typeof component === 'object' && isNotExotic(component)) {
69
+ const result = convertComponent(converters[component.type], component);
70
+ return wrapForeignComponent<T>(result, captured, Wrapper);
71
+ }
72
+
73
+ return wrapReactComponent<T>(component, captured, Wrapper);
74
+ }
@@ -49,7 +49,7 @@ export function createInstance(config: PiralInstanceOptions = {}): PiralInstance
49
49
  const usedPlugins = Array.isArray(definedPlugins) ? definedPlugins : [definedPlugins];
50
50
  const createApi = apiFactory(context, usedPlugins);
51
51
  const root = createApi({
52
- name: 'root',
52
+ name: '_',
53
53
  version: process.env.BUILD_PCKG_VERSION || '1.0.0',
54
54
  spec: 'v0',
55
55
  basePath: '',
package/src/debugger.ts CHANGED
@@ -3,7 +3,7 @@ import { LoadPiletsOptions } from 'piral-base';
3
3
  import { installPiralDebug, DebuggerExtensionOptions } from 'piral-debug-utils';
4
4
  import { GlobalStateContext } from './types';
5
5
 
6
- export function integrate(
6
+ export function integrateDebugger(
7
7
  context: GlobalStateContext,
8
8
  options: LoadPiletsOptions,
9
9
  debug: DebuggerExtensionOptions = {},
package/src/emulator.ts CHANGED
@@ -2,7 +2,7 @@ import { LoadPiletsOptions } from 'piral-base';
2
2
  import { withEmulatorPilets } from 'piral-debug-utils';
3
3
  import { GlobalStateContext } from './types';
4
4
 
5
- export function integrate(context: GlobalStateContext, options: LoadPiletsOptions) {
5
+ export function integrateEmulator(context: GlobalStateContext, options: LoadPiletsOptions) {
6
6
  options.fetchPilets = withEmulatorPilets(options.fetchPilets, {
7
7
  addPilet: context.addPilet,
8
8
  removePilet: context.removePilet,
package/src/helpers.tsx CHANGED
@@ -8,9 +8,10 @@ import {
8
8
  PiletLoader,
9
9
  PiletLifecycleHooks,
10
10
  } from 'piral-base';
11
- import { DebuggerExtensionOptions } from 'piral-debug-utils';
11
+ import type { DebuggerExtensionOptions } from 'piral-debug-utils';
12
12
  import { globalDependencies } from './modules';
13
13
  import type { Pilet, PiletRequester, GlobalStateContext, PiletLoadingStrategy, DependencySelector } from './types';
14
+ import { integrateDebugger, integrateEmulator } from '../debug.codegen';
14
15
 
15
16
  export interface PiletOptionsConfig {
16
17
  context: GlobalStateContext;
@@ -50,17 +51,8 @@ export function createPiletOptions({
50
51
  dependencies: shareDependencies(globalDependencies),
51
52
  };
52
53
 
53
- // if we build the debug version of piral (debug and emulator build)
54
- if (process.env.DEBUG_PIRAL) {
55
- const { integrate } = require('./debugger');
56
- integrate(context, options, debug);
57
- }
58
-
59
- // if we build the emulator version of piral (shipped to pilets)
60
- if (process.env.DEBUG_PILET) {
61
- const { integrate } = require('./emulator');
62
- integrate(context, options);
63
- }
54
+ integrateDebugger(context, options, debug);
55
+ integrateEmulator(context, options, debug);
64
56
 
65
57
  return options;
66
58
  }
@@ -1,6 +1,6 @@
1
1
  import { isfunc } from 'piral-base';
2
- import { __assign } from 'tslib';
3
2
  import type { AvailableDependencies, PiletEntries } from '../types';
3
+ import fillDependencies from '../../dependencies.codegen';
4
4
 
5
5
  /**
6
6
  * The global dependencies, which represent the dependencies
@@ -8,27 +8,8 @@ import type { AvailableDependencies, PiletEntries } from '../types';
8
8
  */
9
9
  export const globalDependencies: AvailableDependencies = {};
10
10
 
11
- if (process.env.SHARED_DEPENDENCIES) {
12
- const fillDependencies = require('../../dependencies.codegen');
13
-
14
- if (isfunc(fillDependencies)) {
15
- fillDependencies(globalDependencies);
16
- } else {
17
- // fall back to the default list if the codegen is invalid / not supported
18
- __assign(globalDependencies, {
19
- react: require('react'),
20
- 'react-dom': require('react-dom'),
21
- 'react-router': require('react-router'),
22
- 'react-router-dom': require('react-router-dom'),
23
- history: require('history'),
24
- tslib: require('tslib'),
25
- 'path-to-regexp': require('path-to-regexp'),
26
- '@libre/atom': require('@libre/atom'),
27
- '@dbeining/react-atom': require('@dbeining/react-atom'),
28
- });
29
- }
30
- } else {
31
- // App shell is built with something else than the Piral CLI - just don't fill ...
11
+ if (isfunc(fillDependencies)) {
12
+ fillDependencies(globalDependencies);
32
13
  }
33
14
 
34
15
  /**
@@ -1,147 +1,11 @@
1
1
  import * as React from 'react';
2
- import { isfunc } from 'piral-base';
3
2
  import { __RouterContext } from 'react-router';
4
- import { ErrorBoundary, PortalRenderer } from '../components';
5
- import { useGlobalStateContext } from '../hooks';
6
- import { defaultRender, convertComponent, none } from '../utils';
7
- import {
8
- AnyComponent,
9
- Errors,
10
- ComponentConverters,
11
- ForeignComponent,
12
- PiletApi,
13
- BaseComponentProps,
14
- ComponentContext,
15
- GlobalStateContext,
16
- } from '../types';
17
-
18
- // this is an arbitrary start number to have 6 digits
19
- let portalIdBase = 123456;
3
+ import { ErrorBoundary, wrapComponent } from '../components';
4
+ import { defaultRender } from '../utils';
5
+ import { AnyComponent, Errors, PiletApi, BaseComponentProps, GlobalStateContext } from '../types';
20
6
 
21
7
  const DefaultWrapper: React.FC = (props) => defaultRender(props.children);
22
8
 
23
- interface CapturedProps {
24
- piral: PiletApi;
25
- }
26
-
27
- interface ForeignComponentContainerProps<T> {
28
- $portalId: string;
29
- $component: ForeignComponent<T>;
30
- $context: ComponentContext;
31
- innerProps: T & BaseComponentProps;
32
- }
33
-
34
- class ForeignComponentContainer<T> extends React.Component<ForeignComponentContainerProps<T>> {
35
- private current?: HTMLElement;
36
- private previous?: HTMLElement;
37
- private handler = (ev: CustomEvent) => {
38
- const { innerProps } = this.props;
39
- ev.stopPropagation();
40
- innerProps.piral.renderHtmlExtension(ev.detail.target, ev.detail.props);
41
- };
42
-
43
- private setNode = (node: HTMLDivElement) => {
44
- this.current = node;
45
- };
46
-
47
- componentDidMount() {
48
- const node = this.current;
49
- const { $component, $context, innerProps } = this.props;
50
- const { mount } = $component;
51
-
52
- if (node && isfunc(mount)) {
53
- mount(node, innerProps, $context);
54
- node.addEventListener('render-html', this.handler, false);
55
- }
56
-
57
- this.previous = node;
58
- }
59
-
60
- componentDidUpdate() {
61
- const { current, previous } = this;
62
- const { $component, $context, innerProps } = this.props;
63
- const { update } = $component;
64
-
65
- if (current !== previous) {
66
- previous && this.componentWillUnmount();
67
- current && this.componentDidMount();
68
- } else if (isfunc(update)) {
69
- update(current, innerProps, $context);
70
- }
71
- }
72
-
73
- componentWillUnmount() {
74
- const node = this.previous;
75
- const { $component } = this.props;
76
- const { unmount } = $component;
77
-
78
- if (node && isfunc(unmount)) {
79
- unmount(node);
80
- node.removeEventListener('render-html', this.handler, false);
81
- }
82
-
83
- this.previous = undefined;
84
- }
85
-
86
- render() {
87
- const { $portalId } = this.props;
88
- return <div data-portal-id={$portalId} ref={this.setNode} />;
89
- }
90
- }
91
-
92
- function wrapReactComponent<T>(
93
- Component: React.ComponentType<T & BaseComponentProps>,
94
- captured: CapturedProps,
95
- Wrapper: React.FC<T>,
96
- ): React.ComponentType<T> {
97
- return (props: T) => (
98
- <Wrapper {...props}>
99
- <Component {...props} {...captured} />
100
- </Wrapper>
101
- );
102
- }
103
-
104
- function wrapForeignComponent<T>(
105
- component: ForeignComponent<T & BaseComponentProps>,
106
- captured: CapturedProps,
107
- Wrapper: React.FC<T>,
108
- ) {
109
- return React.memo((props: T) => {
110
- const { state, readState, destroyPortal } = useGlobalStateContext();
111
- const router = React.useContext(__RouterContext);
112
- const id = React.useMemo(() => (portalIdBase++).toString(26), none);
113
- const context = React.useMemo(() => ({ router, state, readState }), [router, state]);
114
- const innerProps = React.useMemo(() => ({ ...props, ...captured }), [props]);
115
-
116
- React.useEffect(() => () => destroyPortal(id), none);
117
-
118
- return (
119
- <Wrapper {...props}>
120
- <PortalRenderer id={id} />
121
- <ForeignComponentContainer innerProps={innerProps} $portalId={id} $component={component} $context={context} />
122
- </Wrapper>
123
- );
124
- });
125
- }
126
-
127
- function isNotExotic(component: any): component is object {
128
- return !(component as React.ExoticComponent).$$typeof;
129
- }
130
-
131
- function wrapComponent<T>(
132
- converters: ComponentConverters<T & BaseComponentProps>,
133
- component: AnyComponent<T & BaseComponentProps>,
134
- captured: CapturedProps,
135
- Wrapper: React.FC<T>,
136
- ) {
137
- if (typeof component === 'object' && isNotExotic(component)) {
138
- const result = convertComponent(converters[component.type], component);
139
- return wrapForeignComponent<T>(result, captured, Wrapper);
140
- }
141
-
142
- return wrapReactComponent<T>(component, captured, Wrapper);
143
- }
144
-
145
9
  function getWrapper(wrappers: Record<string, React.ComponentType<any>>, wrapperType: string) {
146
10
  const WrapAll = wrappers['*'];
147
11
  const WrapType = wrappers[wrapperType];
@@ -157,32 +21,33 @@ function getWrapper(wrappers: Record<string, React.ComponentType<any>>, wrapperT
157
21
  return WrapType || WrapAll || DefaultWrapper;
158
22
  }
159
23
 
160
- export function withApi<TProps>(
24
+ function makeWrapper<TProps>(
161
25
  context: GlobalStateContext,
162
- component: AnyComponent<TProps & BaseComponentProps>,
163
- piral: PiletApi,
26
+ outerProps: any,
27
+ wrapperType: string,
164
28
  errorType: keyof Errors,
165
- wrapperType: string = errorType,
166
- captured = {},
167
- ) {
168
- const outerProps = { ...captured, piral };
169
- const converters = context.converters;
29
+ ): React.FC<TProps> {
170
30
  const OuterWrapper = context.readState((m) => getWrapper(m.registry.wrappers, wrapperType));
171
31
 
172
- const Wrapper: React.FC<TProps> = (props) => (
32
+ return (props) => (
173
33
  <OuterWrapper {...outerProps} {...props}>
174
34
  <ErrorBoundary {...outerProps} {...props} errorType={errorType}>
175
35
  {props.children}
176
36
  </ErrorBoundary>
177
37
  </OuterWrapper>
178
38
  );
39
+ }
179
40
 
180
- if (!component) {
181
- const pilet = piral.meta.name;
182
- console.error(`[${pilet}] The given value is not a valid component.`);
183
- // tslint:disable-next-line:no-null-keyword
184
- component = () => null;
185
- }
186
-
187
- return wrapComponent<TProps>(converters, component, outerProps, Wrapper);
41
+ export function withApi<TProps>(
42
+ context: GlobalStateContext,
43
+ component: AnyComponent<TProps & BaseComponentProps>,
44
+ piral: PiletApi,
45
+ errorType: keyof Errors,
46
+ wrapperType: string = errorType,
47
+ captured = {},
48
+ ) {
49
+ const outerProps = { ...captured, piral };
50
+ const converters = context.converters;
51
+ const Wrapper = makeWrapper<TProps>(context, outerProps, wrapperType, errorType);
52
+ return wrapComponent(converters, component, outerProps, Wrapper);
188
53
  }
package/src/types/api.ts CHANGED
@@ -12,7 +12,7 @@ import type {
12
12
  } from 'piral-base';
13
13
  import type { PiletCustomApi, PiralCustomPageMeta } from './custom';
14
14
  import type { AnyComponent } from './components';
15
- import type { ExtensionSlotProps, PiralExtensionSlotMap } from './extension';
15
+ import type { ExtensionParams, ExtensionSlotProps, PiralExtensionSlotMap } from './extension';
16
16
  import type { SharedData, DataStoreOptions } from './data';
17
17
  import type { Disposable } from './utils';
18
18
 
@@ -113,7 +113,7 @@ export interface PiletCoreApi {
113
113
  registerExtension<TName>(
114
114
  name: TName extends string ? TName : string,
115
115
  Component: AnyComponent<ExtensionComponentProps<TName>>,
116
- defaults?: TName,
116
+ defaults?: Partial<ExtensionParams<TName>>,
117
117
  ): RegistrationDisposer;
118
118
  /**
119
119
  * Unregisters a global extension component.