@pushwoosh/single-spa 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Parcel.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import React, { useMemo } from 'react';
2
- import singleSpa from 'single-spa';
2
+ import { mountRootParcel } from 'single-spa';
3
3
  import SingleSpaParcel from 'single-spa-react/parcel';
4
4
  export const Parcel = ({
5
5
  className,
@@ -12,6 +12,7 @@ export const Parcel = ({
12
12
  return {
13
13
  bootstrap(props) {
14
14
  return System.import(module).then(imported => {
15
+ // eslint-disable-next-line react/prop-types
15
16
  parcel = imported[parcelFunctionName](props.domElement);
16
17
  });
17
18
  },
@@ -33,7 +34,7 @@ export const Parcel = ({
33
34
  ...transferProps,
34
35
  config: parcelConfig,
35
36
  wrapClassName: className,
36
- mountParcel: singleSpa.mountRootParcel,
37
+ mountParcel: mountRootParcel,
37
38
  key: `${module}-${parcelFunctionName}`
38
39
  });
39
40
  };
@@ -0,0 +1,6 @@
1
+ import { type ReactElement } from 'react';
2
+ import { type ReactAppOrParcel } from 'single-spa-react';
3
+ import { type SPAContextType } from '@pushwoosh/spa-context';
4
+ export declare function createApplicationFunctions<T extends {
5
+ spaContext: SPAContextType;
6
+ }>(renderFn: (props: T) => ReactElement): ReactAppOrParcel<T>;
@@ -0,0 +1,37 @@
1
+ import React, { Component } from 'react';
2
+ import ReactDOMClient from 'react-dom/client';
3
+ import singleSpaReact from 'single-spa-react';
4
+ import { SPAContextProvider } from '@pushwoosh/spa-context';
5
+ class AppWrapper extends Component {
6
+ constructor(props) {
7
+ super(props);
8
+ this.state = {
9
+ hasError: false
10
+ };
11
+ }
12
+ static getDerivedStateFromError() {
13
+ return {
14
+ hasError: true
15
+ };
16
+ }
17
+ componentDidCatch(error, errorInfo) {
18
+ console.error('AppWrapper caught an error', error, errorInfo);
19
+ }
20
+ render() {
21
+ if (this.state.hasError) {
22
+ return React.createElement("div", null, "Application has been crashed! Please try again later!");
23
+ }
24
+ return React.createElement(SPAContextProvider, {
25
+ value: this.props.spaContext
26
+ }, this.props.children);
27
+ }
28
+ }
29
+ export function createApplicationFunctions(renderFn) {
30
+ return singleSpaReact({
31
+ React,
32
+ ReactDOMClient,
33
+ rootComponent: props => React.createElement(AppWrapper, {
34
+ spaContext: props.spaContext
35
+ }, renderFn(props))
36
+ });
37
+ }
@@ -0,0 +1,7 @@
1
+ import { type ReactElement } from 'react';
2
+ type ParcelResult<T> = {
3
+ render: (props: T) => void;
4
+ unmount: () => void;
5
+ };
6
+ export declare function createParcelFunction<T>(render: (props: T) => ReactElement): (container: HTMLElement) => ParcelResult<T>;
7
+ export {};
@@ -0,0 +1,14 @@
1
+ import { createRoot } from 'react-dom/client';
2
+ export function createParcelFunction(render) {
3
+ return container => {
4
+ const root = createRoot(container);
5
+ return {
6
+ render(props) {
7
+ root.render(render(props));
8
+ },
9
+ unmount() {
10
+ root.unmount();
11
+ }
12
+ };
13
+ };
14
+ }
package/index.d.ts CHANGED
@@ -1 +1,3 @@
1
1
  export * from './Parcel';
2
+ export { createParcelFunction } from './createParcelFunction';
3
+ export { createApplicationFunctions } from './createApplicationFunctions';
package/index.js CHANGED
@@ -1 +1,3 @@
1
- export * from './Parcel';
1
+ export * from './Parcel';
2
+ export { createParcelFunction } from './createParcelFunction';
3
+ export { createApplicationFunctions } from './createApplicationFunctions';
package/package.json CHANGED
@@ -1,47 +1,38 @@
1
1
  {
2
2
  "name": "@pushwoosh/single-spa",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "React component for build Pushwoosh products",
5
5
  "main": "index.js",
6
6
  "module": "index.js",
7
7
  "types": "index.d.ts",
8
8
  "sideEffects": false,
9
9
  "scripts": {
10
- "start": "npm run playground",
11
10
  "build": "pushwoosh-engine lib:build",
12
- "playground": "`pushwoosh-engine lib:command:playground`",
13
11
  "check": "npm run check:lint && npm run check:types",
14
- "check:lint": "echo \"Run check:lint\" && eslint .",
12
+ "check:lint": "echo \"Run check:lint\" && NODE_ENV=production eslint src",
13
+ "check:lint-fix": "echo \"Run check:lint\" && NODE_ENV=production eslint src --fix",
15
14
  "check:types": "echo \"Run check:types\" && pushwoosh-engine lib:check-types"
16
15
  },
17
16
  "pre-commit": "check",
18
17
  "devDependencies": {
19
- "@pushwoosh/frontend-builder-engine": "^0.3.1",
18
+ "@pushwoosh/frontend-builder-engine": "^1.0.21",
20
19
  "@pushwoosh/kit-constants": "^1.6.0",
21
- "@types/react": "^16.14.20",
22
- "@types/react-dom": "^16.9.14",
23
- "@typescript-eslint/eslint-plugin": "^7.3.1",
24
- "@typescript-eslint/parser": "^7.3.1",
25
- "eslint": "^8.31.0",
26
- "eslint-config-airbnb": "^19.0.4",
27
- "eslint-config-airbnb-typescript": "^18.0.0",
28
- "eslint-import-resolver-alias": "^1.1.2",
29
- "eslint-plugin-import": "^2.25.2",
30
- "eslint-plugin-jsx-a11y": "^6.4.1",
31
- "eslint-plugin-react": "^7.26.1",
32
- "eslint-plugin-react-hooks": "^4.2.0",
20
+ "@types/react": "^18.3.28",
21
+ "@types/react-dom": "^18.3.7",
33
22
  "pre-commit": "^1.2.2",
34
- "react": "^16.14.0",
35
- "react-dom": "^16.14.0"
23
+ "react": "^18.3.1",
24
+ "react-dom": "^18.3.1"
36
25
  },
37
26
  "peerDependencies": {
38
- "react": ">= 16.14.0"
27
+ "react": ">= 18",
28
+ "react-dom": ">= 18"
39
29
  },
40
30
  "engines": {
41
31
  "node": ">= 18"
42
32
  },
43
33
  "dependencies": {
34
+ "@pushwoosh/spa-context": "^1.0.0",
44
35
  "single-spa": "^5.9.5",
45
- "single-spa-react": "^4.6.1"
36
+ "single-spa-react": "^6.0.2"
46
37
  }
47
38
  }