@embeddable.com/sdk-react 0.0.15 → 0.0.17

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.
@@ -2,6 +2,7 @@ import * as React from 'react';
2
2
  export type Config<T> = {
3
3
  inputs: any;
4
4
  events: Record<string, EmbeddableEventHandler<T>>;
5
+ mapProps?: (_: any) => any;
5
6
  };
6
7
  export type EmbeddableEventHandler<T> = (value: T, setter: Setter<T>) => void;
7
8
  export type EmbeddableEvent<T> = {
@@ -9,11 +10,8 @@ export type EmbeddableEvent<T> = {
9
10
  value: T;
10
11
  };
11
12
  type Setter<T> = (value: T) => void;
12
- export declare function embedEditor<T>(InnerComponent: React.ComponentType, config: Config<T>): {
13
- ({ editorId, initialValue }: {
14
- editorId: any;
15
- initialValue: any;
16
- }): React.JSX.Element;
13
+ export declare function embedControl<T>(InnerComponent: React.ComponentType, config: Config<T>): {
14
+ (props: any): React.JSX.Element;
17
15
  displayName: string;
18
16
  };
19
17
  export {};
package/lib/index.cjs.js CHANGED
@@ -88,11 +88,12 @@ function embedComponent(InnerComponent, config) {
88
88
  }
89
89
 
90
90
  var EVENT_NAME = "embeddable:editor:changed";
91
- function embedEditor(InnerComponent, config) {
91
+ function embedControl(InnerComponent, config) {
92
92
  var _a;
93
- function EmbeddableWrapper(_a) {
94
- var editorId = _a.editorId, initialValue = _a.initialValue;
95
- var _b = React__namespace.useState(initialValue), componentState = _b[0], setComponentState = _b[1];
93
+ function EmbeddableWrapper(props) {
94
+ var _a, _b;
95
+ var editorId = props.editorId, initialValue = props.initialValue;
96
+ var _c = React__namespace.useState(initialValue), componentState = _c[0], setComponentState = _c[1];
96
97
  var createEvent = function (value) {
97
98
  var event = new CustomEvent(EVENT_NAME, {
98
99
  bubbles: false,
@@ -117,11 +118,11 @@ function embedEditor(InnerComponent, config) {
117
118
  for (var event_1 in events) {
118
119
  _loop_1(event_1);
119
120
  }
120
- return React__namespace.createElement(InnerComponent, __assign({}, eventProps, config.inputs(componentState)));
121
+ return React__namespace.createElement(InnerComponent, __assign({}, eventProps, config.inputs(componentState), ((_b = (_a = config.mapProps) === null || _a === void 0 ? void 0 : _a.call(config, props)) !== null && _b !== void 0 ? _b : {})));
121
122
  }
122
123
  EmbeddableWrapper.displayName = "embedded(".concat((_a = InnerComponent.displayName) !== null && _a !== void 0 ? _a : 'Editor', ")");
123
124
  return EmbeddableWrapper;
124
125
  }
125
126
 
126
127
  exports.embedComponent = embedComponent;
127
- exports.embedEditor = embedEditor;
128
+ exports.embedControl = embedControl;
package/lib/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  export { embedComponent } from './embedComponent';
2
- export { embedEditor } from './embedEditor';
2
+ export { embedControl } from './embedControl';
package/lib/index.esm.js CHANGED
@@ -67,11 +67,12 @@ function embedComponent(InnerComponent, config) {
67
67
  }
68
68
 
69
69
  var EVENT_NAME = "embeddable:editor:changed";
70
- function embedEditor(InnerComponent, config) {
70
+ function embedControl(InnerComponent, config) {
71
71
  var _a;
72
- function EmbeddableWrapper(_a) {
73
- var editorId = _a.editorId, initialValue = _a.initialValue;
74
- var _b = React.useState(initialValue), componentState = _b[0], setComponentState = _b[1];
72
+ function EmbeddableWrapper(props) {
73
+ var _a, _b;
74
+ var editorId = props.editorId, initialValue = props.initialValue;
75
+ var _c = React.useState(initialValue), componentState = _c[0], setComponentState = _c[1];
75
76
  var createEvent = function (value) {
76
77
  var event = new CustomEvent(EVENT_NAME, {
77
78
  bubbles: false,
@@ -96,10 +97,10 @@ function embedEditor(InnerComponent, config) {
96
97
  for (var event_1 in events) {
97
98
  _loop_1(event_1);
98
99
  }
99
- return React.createElement(InnerComponent, __assign({}, eventProps, config.inputs(componentState)));
100
+ return React.createElement(InnerComponent, __assign({}, eventProps, config.inputs(componentState), ((_b = (_a = config.mapProps) === null || _a === void 0 ? void 0 : _a.call(config, props)) !== null && _b !== void 0 ? _b : {})));
100
101
  }
101
102
  EmbeddableWrapper.displayName = "embedded(".concat((_a = InnerComponent.displayName) !== null && _a !== void 0 ? _a : 'Editor', ")");
102
103
  return EmbeddableWrapper;
103
104
  }
104
105
 
105
- export { embedComponent, embedEditor };
106
+ export { embedComponent, embedControl };
package/lib/index.umd.js CHANGED
@@ -108,11 +108,12 @@
108
108
  }
109
109
 
110
110
  var EVENT_NAME = "embeddable:editor:changed";
111
- function embedEditor(InnerComponent, config) {
111
+ function embedControl(InnerComponent, config) {
112
112
  var _a;
113
- function EmbeddableWrapper(_a) {
114
- var editorId = _a.editorId, initialValue = _a.initialValue;
115
- var _b = reactExports.useState(initialValue), componentState = _b[0], setComponentState = _b[1];
113
+ function EmbeddableWrapper(props) {
114
+ var _a, _b;
115
+ var editorId = props.editorId, initialValue = props.initialValue;
116
+ var _c = reactExports.useState(initialValue), componentState = _c[0], setComponentState = _c[1];
116
117
  var createEvent = function (value) {
117
118
  var event = new CustomEvent(EVENT_NAME, {
118
119
  bubbles: false,
@@ -137,13 +138,13 @@
137
138
  for (var event_1 in events) {
138
139
  _loop_1(event_1);
139
140
  }
140
- return reactExports.createElement(InnerComponent, __assign({}, eventProps, config.inputs(componentState)));
141
+ return reactExports.createElement(InnerComponent, __assign({}, eventProps, config.inputs(componentState), ((_b = (_a = config.mapProps) === null || _a === void 0 ? void 0 : _a.call(config, props)) !== null && _b !== void 0 ? _b : {})));
141
142
  }
142
143
  EmbeddableWrapper.displayName = "embedded(".concat((_a = InnerComponent.displayName) !== null && _a !== void 0 ? _a : 'Editor', ")");
143
144
  return EmbeddableWrapper;
144
145
  }
145
146
 
146
147
  exports.embedComponent = embedComponent;
147
- exports.embedEditor = embedEditor;
148
+ exports.embedControl = embedControl;
148
149
 
149
150
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@embeddable.com/sdk-react",
3
- "version": "0.0.15",
3
+ "version": "0.0.17",
4
4
  "description": "Embeddable SDK React plugin/module responsible for React components bundling.",
5
5
  "keywords": [
6
6
  "embeddable",
@@ -2,7 +2,7 @@ const fs = require("fs/promises");
2
2
  const path = require("path");
3
3
  const vite = require("vite");
4
4
  const viteReactPlugin = require('@vitejs/plugin-react');
5
- const core = require("@embeddable.com/sdk-core/scripts/build");
5
+ const core = require("@embeddable.com/sdk-core/scripts");
6
6
 
7
7
  process.on('message', async ({ ctx }) => {
8
8
  await generate(ctx);
@@ -10,8 +10,10 @@ process.on('message', async ({ ctx }) => {
10
10
  process.exit();
11
11
  });
12
12
 
13
+ const EMB_FILE_REGEX = /^(.*)\.emb\.[jt]s$/;
14
+
13
15
  async function generate(ctx) {
14
- const filesList = await findEmbFiles(ctx.client.srcDir);
16
+ const filesList = await core.findEmbFiles(ctx.client.srcDir, EMB_FILE_REGEX);
15
17
 
16
18
  await injectImports(ctx, filesList);
17
19
 
@@ -65,35 +67,3 @@ async function injectImports(ctx, filesList) {
65
67
  content.replace(REPLACE_TOKEN, imports)
66
68
  );
67
69
  }
68
-
69
-
70
- const EMB_FILE_REGEX = /^(.*)\.emb\.(j|t)s$/;
71
-
72
- async function findEmbFiles (initialSrcDir) {
73
- const filesList = [];
74
-
75
- async function findEmbFilesRec(srcDir) {
76
- const allFiles = await fs.readdir(srcDir);
77
-
78
- for (const file of allFiles) {
79
- const filePath = path.join(srcDir, file)
80
-
81
- const status = await fs.lstat(filePath);
82
-
83
- if (status.isDirectory()) {
84
- await findEmbFilesRec(filePath)
85
- }
86
-
87
- const fileName = file.match(EMB_FILE_REGEX);
88
-
89
- if (fileName) {
90
- filesList.push([fileName[1], filePath]);
91
- }
92
- }
93
- }
94
-
95
- await findEmbFilesRec(initialSrcDir);
96
-
97
-
98
- return filesList;
99
- }