oc-template-preact-compiler 0.3.2 → 0.3.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 preactOCProviderTemplate({ viewPath }: {
1
+ export default function preactOCProviderTemplate({ viewPath, providerFunctions }: {
2
2
  viewPath: string;
3
+ providerFunctions: string;
3
4
  }): string;
@@ -1,47 +1,24 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const removeExtension = (path) => path.replace(/\.(t|j)sx?$/, '');
4
- function preactOCProviderTemplate({ viewPath }) {
4
+ function preactOCProviderTemplate({ viewPath, providerFunctions }) {
5
5
  return `
6
6
  import { render } from 'preact';
7
7
  import { useEffect } from 'preact/hooks';
8
8
  import View from '${removeExtension(viewPath)}';
9
9
  import { DataProvider } from 'oc-template-preact-compiler/dist/utils/useData'
10
10
 
11
- function OCProvider(props: any): any {
11
+ function OCProvider(props) {
12
12
  const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = props;
13
13
 
14
14
  useEffect(() => {
15
- (window as any).oc.events.fire('oc:componentDidMount', rest);
15
+ window.oc.events.fire('oc:componentDidMount', rest);
16
16
  }, []);
17
17
 
18
- function getData(providerProps: any, parameters: any, cb: (error: any, parameters?: any, props?: any) => void) {
19
- return (window as any).oc.getData({
20
- name: providerProps._componentName,
21
- version: providerProps._componentVersion,
22
- baseUrl: providerProps._baseUrl,
23
- parameters
24
- }, (err: any, data: any) => {
25
- if (err) {
26
- return cb(err);
27
- }
28
- const { _staticPath, _baseUrl, _componentName, _componentVersion, ...rest } = data.component.props;
29
- cb(null, rest, data.component.props);
30
- });
31
- }
32
-
33
- function getSetting(providerProps: any, setting: string) {
34
- const settingHash = {
35
- name: providerProps._componentName,
36
- version: providerProps._componentVersion,
37
- baseUrl: providerProps._baseUrl,
38
- staticPath: providerProps._staticPath
39
- };
40
- return (settingHash as any)[setting];
41
- }
18
+ ${providerFunctions}
42
19
 
43
- (rest as any).getData = (parameters: any, cb: (error: any, parameters?: any, props?: any) => void) => getData(props, parameters, cb);
44
- (rest as any).getSetting = (setting: string) => getSetting(props, setting);
20
+ rest.getData = getData;
21
+ rest.getSetting = getSetting;
45
22
 
46
23
  return (
47
24
  <DataProvider value={{...rest}}>
@@ -50,11 +27,9 @@ function preactOCProviderTemplate({ viewPath }) {
50
27
  );
51
28
  }
52
29
 
53
- function renderer(props, element) {
30
+ export default function renderer(props, element, ssr) {
54
31
  render(<OCProvider {...props} />, element);
55
32
  }
56
-
57
- export default renderer;
58
33
  `;
59
34
  }
60
35
  exports.default = preactOCProviderTemplate;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oc-template-preact-compiler",
3
- "version": "0.3.2",
3
+ "version": "0.3.3",
4
4
  "description": "Compiler for the Preact OC template",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  "dependencies": {
32
32
  "@preact/preset-vite": "^2.5.0",
33
33
  "oc-template-preact": "^0.1.0",
34
- "oc-vite-compiler": "^3.2.0",
34
+ "oc-vite-compiler": "^3.3.0",
35
35
  "preact": "^10"
36
36
  },
37
37
  "peerDependencies": {