@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.
- package/lib/{embedEditor.d.ts → embedControl.d.ts} +3 -5
- package/lib/index.cjs.js +7 -6
- package/lib/index.d.ts +1 -1
- package/lib/index.esm.js +7 -6
- package/lib/index.umd.js +7 -6
- package/package.json +1 -1
- package/scripts/generate.js +4 -34
|
@@ -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
|
|
13
|
-
(
|
|
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
|
|
91
|
+
function embedControl(InnerComponent, config) {
|
|
92
92
|
var _a;
|
|
93
|
-
function EmbeddableWrapper(
|
|
94
|
-
var
|
|
95
|
-
var
|
|
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.
|
|
128
|
+
exports.embedControl = embedControl;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { embedComponent } from './embedComponent';
|
|
2
|
-
export {
|
|
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
|
|
70
|
+
function embedControl(InnerComponent, config) {
|
|
71
71
|
var _a;
|
|
72
|
-
function EmbeddableWrapper(
|
|
73
|
-
var
|
|
74
|
-
var
|
|
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,
|
|
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
|
|
111
|
+
function embedControl(InnerComponent, config) {
|
|
112
112
|
var _a;
|
|
113
|
-
function EmbeddableWrapper(
|
|
114
|
-
var
|
|
115
|
-
var
|
|
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.
|
|
148
|
+
exports.embedControl = embedControl;
|
|
148
149
|
|
|
149
150
|
}));
|
package/package.json
CHANGED
package/scripts/generate.js
CHANGED
|
@@ -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
|
|
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
|
-
}
|