oc-template-react-compiler 6.0.2 → 6.0.3

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.
@@ -1,3 +1,4 @@
1
- export default function reactOCProviderTemplate({ viewPath }: {
1
+ export default function reactOCProviderTemplate({ viewPath, providerFunctions }: {
2
2
  viewPath: string;
3
+ providerFunctions: string;
3
4
  }): string;
@@ -1,56 +1,32 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const removeExtension = (path) => path.replace(/\.(t|j)sx?$/, '');
4
- function reactOCProviderTemplate({ viewPath }) {
4
+ function reactOCProviderTemplate({ viewPath, providerFunctions }) {
5
5
  return `
6
6
  import React from 'react';
7
7
  import View from '${removeExtension(viewPath)}';
8
8
  import { DataProvider } from 'oc-template-react-compiler/dist/utils/useData'
9
9
 
10
- class OCProvider extends React.Component {
11
- componentDidMount(){
12
- const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = (this.props as any);
13
- (window as any).oc.events.fire('oc:componentDidMount', rest);
14
- }
10
+ function OCProvider(props) {
11
+ const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = props;
15
12
 
16
- getData(providerProps: any, parameters: any, cb: (error: any, parameters?: any, props?: any) => void) {
17
- return (window as any).oc.getData({
18
- name: providerProps._componentName,
19
- version: providerProps._componentVersion,
20
- baseUrl: providerProps._baseUrl,
21
- parameters
22
- }, (err: any, data: any) => {
23
- if (err) {
24
- return cb(err);
25
- }
26
- const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = (data.component.props as any);
27
- cb(null, rest, data.component.props);
28
- });
29
- }
13
+ React.useEffect(() => {
14
+ window.oc.events.fire('oc:componentDidMount', rest);
15
+ }, []);
30
16
 
31
- getSetting(providerProps: any, setting: string) {
32
- const settingHash = {
33
- name: providerProps._componentName,
34
- version: providerProps._componentVersion,
35
- baseUrl: providerProps._baseUrl,
36
- staticPath: providerProps._staticPath
37
- };
38
- return (settingHash as any)[setting];
39
- }
17
+ ${providerFunctions}
18
+
19
+ rest.getData = getData;
20
+ rest.getSetting = getSetting;
40
21
 
41
- render() {
42
- const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = (this.props as any);
43
- (rest as any).getData = (parameters: any, cb: (error: any, parameters?: any, props?: any) => void) => this.getData(this.props, parameters, cb);
44
- (rest as any).getSetting = (setting: string) => this.getSetting(this.props, setting);
45
- return (
46
- <DataProvider value={{...rest}}>
47
- <View { ...rest } />
48
- </DataProvider>
49
- );
50
- }
22
+ return (
23
+ <DataProvider value={{...rest}}>
24
+ <View { ...rest } />
25
+ </DataProvider>
26
+ );
51
27
  }
52
28
 
53
- function renderer(props, element, ssr) {
29
+ export default function renderer(props, element, ssr) {
54
30
  if (window.ReactDOM.createRoot) {
55
31
  if (ssr) {
56
32
  window.ReactDOM.hydrateRoot(element, <OCProvider {...props} />);
@@ -65,8 +41,6 @@ function reactOCProviderTemplate({ viewPath }) {
65
41
  }
66
42
  }
67
43
  }
68
-
69
- export default renderer;
70
44
  `;
71
45
  }
72
46
  exports.default = reactOCProviderTemplate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oc-template-react-compiler",
3
- "version": "6.0.2",
3
+ "version": "6.0.3",
4
4
  "description": "Compiler for the React OC template",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  "dependencies": {
32
32
  "@vitejs/plugin-react": "^4.0.0",
33
33
  "oc-template-react": "^4.0.0",
34
- "oc-vite-compiler": "^3.2.0",
34
+ "oc-vite-compiler": "^3.3.0",
35
35
  "react": "18.2.0",
36
36
  "react-dom": "18.2.0"
37
37
  },
@@ -35,7 +35,7 @@
35
35
  "@types/react": "^18.0.28",
36
36
  "jsdom": "^21.1.1",
37
37
  "oc-server": "*",
38
- "oc-template-react-compiler": "6.0.0",
38
+ "oc-template-react-compiler": "^6.0.0",
39
39
  "react": "18.2.0",
40
40
  "react-dom": "18.2.0",
41
41
  "typescript": "5.1.3",