@embeddable.com/sdk-react 0.1.3 → 2.0.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/lib/index.cjs.js +89 -153
- package/lib/index.esm.js +86 -151
- package/lib/plugin/build.d.ts +2 -0
- package/lib/plugin/cleanup.d.ts +2 -0
- package/lib/plugin/createContext.d.ts +2 -0
- package/lib/plugin/generate.d.ts +2 -0
- package/lib/plugin/index.d.ts +7 -0
- package/package.json +11 -17
- package/templates/embeddable-entry-point.jsx.template +9 -3
- package/bin/embeddable-react +0 -10
- package/lib/embedComponent.d.ts +0 -22
- package/lib/embedControl.d.ts +0 -13
- package/lib/index.d.ts +0 -2
- package/lib/index.umd.js +0 -219
- package/scripts/build.js +0 -47
- package/scripts/cleanup.js +0 -8
- package/scripts/createContext.js +0 -22
- package/scripts/generate.js +0 -69
- package/scripts/prepare.js +0 -13
package/lib/index.cjs.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var path = require('node:path');
|
|
4
|
+
var fs = require('fs/promises');
|
|
5
|
+
var path$1 = require('path');
|
|
6
|
+
var vite = require('vite');
|
|
7
|
+
var viteReactPlugin = require('@vitejs/plugin-react');
|
|
8
|
+
var extractComponentsConfigPlugin = require('@embeddable.com/extract-components-config');
|
|
9
|
+
var sdkUtils = require('@embeddable.com/sdk-utils');
|
|
10
|
+
var promises = require('node:fs/promises');
|
|
5
11
|
|
|
6
12
|
function _interopNamespaceDefault(e) {
|
|
7
13
|
var n = Object.create(null);
|
|
@@ -20,161 +26,91 @@ function _interopNamespaceDefault(e) {
|
|
|
20
26
|
return Object.freeze(n);
|
|
21
27
|
}
|
|
22
28
|
|
|
23
|
-
var
|
|
29
|
+
var path__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(path);
|
|
30
|
+
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
31
|
+
var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
|
|
32
|
+
var vite__namespace = /*#__PURE__*/_interopNamespaceDefault(vite);
|
|
24
33
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
36
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
37
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
38
|
-
***************************************************************************** */
|
|
39
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
var __assign = function() {
|
|
43
|
-
__assign = Object.assign || function __assign(t) {
|
|
44
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
45
|
-
s = arguments[i];
|
|
46
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
47
|
-
}
|
|
48
|
-
return t;
|
|
49
|
-
};
|
|
50
|
-
return __assign.apply(this, arguments);
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
function __rest(s, e) {
|
|
54
|
-
var t = {};
|
|
55
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
56
|
-
t[p] = s[p];
|
|
57
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
58
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
59
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
60
|
-
t[p[i]] = s[p[i]];
|
|
61
|
-
}
|
|
62
|
-
return t;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
66
|
-
var e = new Error(message);
|
|
67
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
34
|
+
var createContext = (pluginRoot, coreCtx) => {
|
|
35
|
+
coreCtx["sdk-react"] = {
|
|
36
|
+
rootDir: pluginRoot,
|
|
37
|
+
templatesDir: path.resolve(pluginRoot, "templates"),
|
|
38
|
+
outputOptions: {
|
|
39
|
+
fileName: "embeddable-prepared",
|
|
40
|
+
buildName: "embeddable-prepared-build",
|
|
41
|
+
componentsEntryPointFilename: "embeddable-entry-point.jsx",
|
|
42
|
+
},
|
|
43
|
+
};
|
|
68
44
|
};
|
|
69
45
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
46
|
+
const oraP = import('ora');
|
|
47
|
+
const EMB_FILE_REGEX = /^(.*)(?<!\.type|\.options)\.emb\.[jt]s$/;
|
|
48
|
+
const EMB_TYPE_FILE_REGEX = /^(.*)\.type\.emb\.[jt]s$/;
|
|
49
|
+
var generate = async (ctx) => {
|
|
50
|
+
const ora = (await oraP).default;
|
|
51
|
+
const progress = ora("React: building components...").start();
|
|
52
|
+
const filesList = await sdkUtils.findFiles(ctx.client.srcDir, EMB_FILE_REGEX);
|
|
53
|
+
await injectImports(ctx, filesList);
|
|
54
|
+
await runViteBuild(ctx);
|
|
55
|
+
progress.succeed("React: components built completed");
|
|
76
56
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}, []);
|
|
111
|
-
var extendedProps = React__namespace.useMemo(function () { var _a; return (_a = config === null || config === void 0 ? void 0 : config.extendedProps) === null || _a === void 0 ? void 0 : _a.call(config, propsProxy); }, [propsProxy, config === null || config === void 0 ? void 0 : config.extendedProps]);
|
|
112
|
-
var dataLoaders = React__namespace.useMemo(function () { var _a, _b; return (_b = (_a = config === null || config === void 0 ? void 0 : config.dataLoaders) === null || _a === void 0 ? void 0 : _a.call(config, propsProxy)) !== null && _b !== void 0 ? _b : {}; }, [propsProxy, config === null || config === void 0 ? void 0 : config.dataLoaders]);
|
|
113
|
-
var _c = React__namespace.useReducer(reducer, dataLoaders, createInitialLoadersState), loadersState = _c[0], dispatch = _c[1];
|
|
114
|
-
var handleDataLoaded = function (inputName) { return function (res) { return dispatch({ type: ReducerActionTypes.data, inputName: inputName, payload: res.data }); }; };
|
|
115
|
-
var handleError = function (inputName) { return function (error) { return dispatch({ type: ReducerActionTypes.error, inputName: inputName, payload: error }); }; };
|
|
116
|
-
var reloadDataset = function (inputName, params) {
|
|
117
|
-
dispatch({ type: ReducerActionTypes.loading, inputName: inputName });
|
|
118
|
-
params.dataLoader(params.requestParams, latestVariables)
|
|
119
|
-
.then(handleDataLoaded(inputName))
|
|
120
|
-
.catch(handleError(inputName));
|
|
121
|
-
};
|
|
122
|
-
var variableChangedEventHandler = function (_a) {
|
|
123
|
-
var detail = _a.detail;
|
|
124
|
-
latestVariables = detail.variableValues;
|
|
125
|
-
Object.entries(dataLoaders)
|
|
126
|
-
.filter(function (_a) {
|
|
127
|
-
_a[0]; var params = _a[1];
|
|
128
|
-
return params.requestParams.from.datasetId === detail.datasetId;
|
|
129
|
-
})
|
|
130
|
-
.forEach(function (_a) {
|
|
131
|
-
var inputName = _a[0], params = _a[1];
|
|
132
|
-
return reloadDataset(inputName, params);
|
|
133
|
-
});
|
|
134
|
-
};
|
|
135
|
-
React__namespace.useEffect(function () {
|
|
136
|
-
Object.entries(dataLoaders).forEach(function (_a) {
|
|
137
|
-
var inputName = _a[0], params = _a[1];
|
|
138
|
-
return reloadDataset(inputName, params);
|
|
139
|
-
});
|
|
140
|
-
window.addEventListener(RELOAD_DATASET_EVENT_NAME, variableChangedEventHandler);
|
|
141
|
-
return function () { return window.removeEventListener(RELOAD_DATASET_EVENT_NAME, variableChangedEventHandler); };
|
|
142
|
-
}, [JSON.stringify(Object.values(dataLoaders).map(function (loader) { return loader.requestParams; }))]);
|
|
143
|
-
var createEvent = function (value, eventName) { return sdkCore.setValue(value, componentId, eventName); };
|
|
144
|
-
var events = config === null || config === void 0 ? void 0 : config.events;
|
|
145
|
-
var eventProps = {};
|
|
146
|
-
if (events) {
|
|
147
|
-
var _loop_1 = function (event_1) {
|
|
148
|
-
if (events.hasOwnProperty(event_1)) {
|
|
149
|
-
var eventFunction_1 = events[event_1];
|
|
150
|
-
eventProps[event_1] = function (value) { return createEvent(eventFunction_1(value), event_1); };
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
for (var event_1 in events) {
|
|
154
|
-
_loop_1(event_1);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
return React__namespace.createElement(InnerComponent, __assign({}, propsProxy, extendedProps, eventProps, loadersState));
|
|
158
|
-
}
|
|
159
|
-
EmbeddableWrapper.displayName = "embedded(".concat((_a = InnerComponent.displayName) !== null && _a !== void 0 ? _a : 'Component', ")");
|
|
160
|
-
return EmbeddableWrapper;
|
|
57
|
+
async function runViteBuild(ctx) {
|
|
58
|
+
process.chdir(ctx.client.rootDir);
|
|
59
|
+
await vite__namespace.build({
|
|
60
|
+
logLevel: "error",
|
|
61
|
+
plugins: [
|
|
62
|
+
viteReactPlugin(),
|
|
63
|
+
extractComponentsConfigPlugin({
|
|
64
|
+
globalKey: "componentsMeta",
|
|
65
|
+
fileName: "embeddable-components-meta.js",
|
|
66
|
+
outputDir: ".embeddable-build",
|
|
67
|
+
componentFileRegex: EMB_FILE_REGEX,
|
|
68
|
+
typeFileRegex: EMB_TYPE_FILE_REGEX,
|
|
69
|
+
searchEntry: "embedComponent",
|
|
70
|
+
}),
|
|
71
|
+
extractComponentsConfigPlugin({
|
|
72
|
+
globalKey: "editorsMeta",
|
|
73
|
+
fileName: "embeddable-editors-meta.js",
|
|
74
|
+
outputDir: ".embeddable-build",
|
|
75
|
+
componentFileRegex: EMB_FILE_REGEX,
|
|
76
|
+
typeFileRegex: EMB_TYPE_FILE_REGEX,
|
|
77
|
+
searchEntry: "embedControl",
|
|
78
|
+
}),
|
|
79
|
+
],
|
|
80
|
+
build: {
|
|
81
|
+
lib: {
|
|
82
|
+
entry: `./${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}`,
|
|
83
|
+
formats: ["es"],
|
|
84
|
+
fileName: ctx["sdk-react"].outputOptions.fileName,
|
|
85
|
+
},
|
|
86
|
+
outDir: `.embeddable-build/${ctx["sdk-react"].outputOptions.buildName}`,
|
|
87
|
+
},
|
|
88
|
+
define: { "process.env.NODE_ENV": '"production"' },
|
|
89
|
+
});
|
|
161
90
|
}
|
|
162
|
-
|
|
163
|
-
function
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
var setter = function (value) {
|
|
170
|
-
setComponentState(value);
|
|
171
|
-
sdkCore.setValue(value, componentId);
|
|
172
|
-
};
|
|
173
|
-
return React__namespace.createElement(InnerComponent, __assign({}, config.inputs(componentState, setter), ((_b = (_a = config.mapProps) === null || _a === void 0 ? void 0 : _a.call(config, props)) !== null && _b !== void 0 ? _b : {})));
|
|
174
|
-
}
|
|
175
|
-
EmbeddableWrapper.displayName = "embedded(".concat((_a = InnerComponent.displayName) !== null && _a !== void 0 ? _a : 'Editor', ")");
|
|
176
|
-
return EmbeddableWrapper;
|
|
91
|
+
const REPLACE_TOKEN = "{{LAZY_IMPORTS}}";
|
|
92
|
+
async function injectImports(ctx, filesList) {
|
|
93
|
+
const imports = filesList
|
|
94
|
+
.map(([fileName, filePath]) => `\t${fileName}: React.lazy(() => import('./${path__namespace.relative(ctx.client.rootDir, filePath)}'))`)
|
|
95
|
+
.join(",\n");
|
|
96
|
+
const content = await fs__namespace.readFile(path__namespace.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
|
|
97
|
+
await fs__namespace.writeFile(path__namespace.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content.replace(REPLACE_TOKEN, imports));
|
|
177
98
|
}
|
|
178
99
|
|
|
179
|
-
|
|
180
|
-
|
|
100
|
+
var build = async (ctx) => {
|
|
101
|
+
createContext(path__namespace$1.resolve(__dirname, ".."), ctx);
|
|
102
|
+
await generate(ctx);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
var cleanup = async (ctx) => await promises.rm(path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename));
|
|
106
|
+
|
|
107
|
+
var index = (coreCtx) => {
|
|
108
|
+
return {
|
|
109
|
+
pluginName: "sdk-react",
|
|
110
|
+
validate: async () => { },
|
|
111
|
+
build,
|
|
112
|
+
cleanup,
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
module.exports = index;
|
package/lib/index.esm.js
CHANGED
|
@@ -1,158 +1,93 @@
|
|
|
1
|
-
import * as
|
|
2
|
-
import {
|
|
1
|
+
import * as path$1 from 'node:path';
|
|
2
|
+
import { resolve } from 'node:path';
|
|
3
|
+
import * as fs from 'fs/promises';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
import * as vite from 'vite';
|
|
6
|
+
import viteReactPlugin from '@vitejs/plugin-react';
|
|
7
|
+
import extractComponentsConfigPlugin from '@embeddable.com/extract-components-config';
|
|
8
|
+
import { findFiles } from '@embeddable.com/sdk-utils';
|
|
9
|
+
import { rm } from 'node:fs/promises';
|
|
3
10
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
15
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
16
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
17
|
-
***************************************************************************** */
|
|
18
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var __assign = function() {
|
|
22
|
-
__assign = Object.assign || function __assign(t) {
|
|
23
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
24
|
-
s = arguments[i];
|
|
25
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
26
|
-
}
|
|
27
|
-
return t;
|
|
28
|
-
};
|
|
29
|
-
return __assign.apply(this, arguments);
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
function __rest(s, e) {
|
|
33
|
-
var t = {};
|
|
34
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
35
|
-
t[p] = s[p];
|
|
36
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
37
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
38
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
39
|
-
t[p[i]] = s[p[i]];
|
|
40
|
-
}
|
|
41
|
-
return t;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
45
|
-
var e = new Error(message);
|
|
46
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
11
|
+
var createContext = (pluginRoot, coreCtx) => {
|
|
12
|
+
coreCtx["sdk-react"] = {
|
|
13
|
+
rootDir: pluginRoot,
|
|
14
|
+
templatesDir: resolve(pluginRoot, "templates"),
|
|
15
|
+
outputOptions: {
|
|
16
|
+
fileName: "embeddable-prepared",
|
|
17
|
+
buildName: "embeddable-prepared-build",
|
|
18
|
+
componentsEntryPointFilename: "embeddable-entry-point.jsx",
|
|
19
|
+
},
|
|
20
|
+
};
|
|
47
21
|
};
|
|
48
22
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
23
|
+
const oraP = import('ora');
|
|
24
|
+
const EMB_FILE_REGEX = /^(.*)(?<!\.type|\.options)\.emb\.[jt]s$/;
|
|
25
|
+
const EMB_TYPE_FILE_REGEX = /^(.*)\.type\.emb\.[jt]s$/;
|
|
26
|
+
var generate = async (ctx) => {
|
|
27
|
+
const ora = (await oraP).default;
|
|
28
|
+
const progress = ora("React: building components...").start();
|
|
29
|
+
const filesList = await findFiles(ctx.client.srcDir, EMB_FILE_REGEX);
|
|
30
|
+
await injectImports(ctx, filesList);
|
|
31
|
+
await runViteBuild(ctx);
|
|
32
|
+
progress.succeed("React: components built completed");
|
|
55
33
|
};
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
}, []);
|
|
90
|
-
var extendedProps = React.useMemo(function () { var _a; return (_a = config === null || config === void 0 ? void 0 : config.extendedProps) === null || _a === void 0 ? void 0 : _a.call(config, propsProxy); }, [propsProxy, config === null || config === void 0 ? void 0 : config.extendedProps]);
|
|
91
|
-
var dataLoaders = React.useMemo(function () { var _a, _b; return (_b = (_a = config === null || config === void 0 ? void 0 : config.dataLoaders) === null || _a === void 0 ? void 0 : _a.call(config, propsProxy)) !== null && _b !== void 0 ? _b : {}; }, [propsProxy, config === null || config === void 0 ? void 0 : config.dataLoaders]);
|
|
92
|
-
var _c = React.useReducer(reducer, dataLoaders, createInitialLoadersState), loadersState = _c[0], dispatch = _c[1];
|
|
93
|
-
var handleDataLoaded = function (inputName) { return function (res) { return dispatch({ type: ReducerActionTypes.data, inputName: inputName, payload: res.data }); }; };
|
|
94
|
-
var handleError = function (inputName) { return function (error) { return dispatch({ type: ReducerActionTypes.error, inputName: inputName, payload: error }); }; };
|
|
95
|
-
var reloadDataset = function (inputName, params) {
|
|
96
|
-
dispatch({ type: ReducerActionTypes.loading, inputName: inputName });
|
|
97
|
-
params.dataLoader(params.requestParams, latestVariables)
|
|
98
|
-
.then(handleDataLoaded(inputName))
|
|
99
|
-
.catch(handleError(inputName));
|
|
100
|
-
};
|
|
101
|
-
var variableChangedEventHandler = function (_a) {
|
|
102
|
-
var detail = _a.detail;
|
|
103
|
-
latestVariables = detail.variableValues;
|
|
104
|
-
Object.entries(dataLoaders)
|
|
105
|
-
.filter(function (_a) {
|
|
106
|
-
_a[0]; var params = _a[1];
|
|
107
|
-
return params.requestParams.from.datasetId === detail.datasetId;
|
|
108
|
-
})
|
|
109
|
-
.forEach(function (_a) {
|
|
110
|
-
var inputName = _a[0], params = _a[1];
|
|
111
|
-
return reloadDataset(inputName, params);
|
|
112
|
-
});
|
|
113
|
-
};
|
|
114
|
-
React.useEffect(function () {
|
|
115
|
-
Object.entries(dataLoaders).forEach(function (_a) {
|
|
116
|
-
var inputName = _a[0], params = _a[1];
|
|
117
|
-
return reloadDataset(inputName, params);
|
|
118
|
-
});
|
|
119
|
-
window.addEventListener(RELOAD_DATASET_EVENT_NAME, variableChangedEventHandler);
|
|
120
|
-
return function () { return window.removeEventListener(RELOAD_DATASET_EVENT_NAME, variableChangedEventHandler); };
|
|
121
|
-
}, [JSON.stringify(Object.values(dataLoaders).map(function (loader) { return loader.requestParams; }))]);
|
|
122
|
-
var createEvent = function (value, eventName) { return setValue(value, componentId, eventName); };
|
|
123
|
-
var events = config === null || config === void 0 ? void 0 : config.events;
|
|
124
|
-
var eventProps = {};
|
|
125
|
-
if (events) {
|
|
126
|
-
var _loop_1 = function (event_1) {
|
|
127
|
-
if (events.hasOwnProperty(event_1)) {
|
|
128
|
-
var eventFunction_1 = events[event_1];
|
|
129
|
-
eventProps[event_1] = function (value) { return createEvent(eventFunction_1(value), event_1); };
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
for (var event_1 in events) {
|
|
133
|
-
_loop_1(event_1);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return React.createElement(InnerComponent, __assign({}, propsProxy, extendedProps, eventProps, loadersState));
|
|
137
|
-
}
|
|
138
|
-
EmbeddableWrapper.displayName = "embedded(".concat((_a = InnerComponent.displayName) !== null && _a !== void 0 ? _a : 'Component', ")");
|
|
139
|
-
return EmbeddableWrapper;
|
|
34
|
+
async function runViteBuild(ctx) {
|
|
35
|
+
process.chdir(ctx.client.rootDir);
|
|
36
|
+
await vite.build({
|
|
37
|
+
logLevel: "error",
|
|
38
|
+
plugins: [
|
|
39
|
+
viteReactPlugin(),
|
|
40
|
+
extractComponentsConfigPlugin({
|
|
41
|
+
globalKey: "componentsMeta",
|
|
42
|
+
fileName: "embeddable-components-meta.js",
|
|
43
|
+
outputDir: ".embeddable-build",
|
|
44
|
+
componentFileRegex: EMB_FILE_REGEX,
|
|
45
|
+
typeFileRegex: EMB_TYPE_FILE_REGEX,
|
|
46
|
+
searchEntry: "embedComponent",
|
|
47
|
+
}),
|
|
48
|
+
extractComponentsConfigPlugin({
|
|
49
|
+
globalKey: "editorsMeta",
|
|
50
|
+
fileName: "embeddable-editors-meta.js",
|
|
51
|
+
outputDir: ".embeddable-build",
|
|
52
|
+
componentFileRegex: EMB_FILE_REGEX,
|
|
53
|
+
typeFileRegex: EMB_TYPE_FILE_REGEX,
|
|
54
|
+
searchEntry: "embedControl",
|
|
55
|
+
}),
|
|
56
|
+
],
|
|
57
|
+
build: {
|
|
58
|
+
lib: {
|
|
59
|
+
entry: `./${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}`,
|
|
60
|
+
formats: ["es"],
|
|
61
|
+
fileName: ctx["sdk-react"].outputOptions.fileName,
|
|
62
|
+
},
|
|
63
|
+
outDir: `.embeddable-build/${ctx["sdk-react"].outputOptions.buildName}`,
|
|
64
|
+
},
|
|
65
|
+
define: { "process.env.NODE_ENV": '"production"' },
|
|
66
|
+
});
|
|
140
67
|
}
|
|
141
|
-
|
|
142
|
-
function
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
var setter = function (value) {
|
|
149
|
-
setComponentState(value);
|
|
150
|
-
setValue(value, componentId);
|
|
151
|
-
};
|
|
152
|
-
return React.createElement(InnerComponent, __assign({}, config.inputs(componentState, setter), ((_b = (_a = config.mapProps) === null || _a === void 0 ? void 0 : _a.call(config, props)) !== null && _b !== void 0 ? _b : {})));
|
|
153
|
-
}
|
|
154
|
-
EmbeddableWrapper.displayName = "embedded(".concat((_a = InnerComponent.displayName) !== null && _a !== void 0 ? _a : 'Editor', ")");
|
|
155
|
-
return EmbeddableWrapper;
|
|
68
|
+
const REPLACE_TOKEN = "{{LAZY_IMPORTS}}";
|
|
69
|
+
async function injectImports(ctx, filesList) {
|
|
70
|
+
const imports = filesList
|
|
71
|
+
.map(([fileName, filePath]) => `\t${fileName}: React.lazy(() => import('./${path.relative(ctx.client.rootDir, filePath)}'))`)
|
|
72
|
+
.join(",\n");
|
|
73
|
+
const content = await fs.readFile(path.resolve(ctx["sdk-react"].templatesDir, `${ctx["sdk-react"].outputOptions.componentsEntryPointFilename}.template`), "utf8");
|
|
74
|
+
await fs.writeFile(path.resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename), content.replace(REPLACE_TOKEN, imports));
|
|
156
75
|
}
|
|
157
76
|
|
|
158
|
-
|
|
77
|
+
var build = async (ctx) => {
|
|
78
|
+
createContext(path$1.resolve(__dirname, ".."), ctx);
|
|
79
|
+
await generate(ctx);
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
var cleanup = async (ctx) => await rm(resolve(ctx.client.rootDir, ctx["sdk-react"].outputOptions.componentsEntryPointFilename));
|
|
83
|
+
|
|
84
|
+
var index = (coreCtx) => {
|
|
85
|
+
return {
|
|
86
|
+
pluginName: "sdk-react",
|
|
87
|
+
validate: async () => { },
|
|
88
|
+
build,
|
|
89
|
+
cleanup,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export { index as default };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@embeddable.com/sdk-react",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Embeddable SDK React plugin
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "Embeddable SDK React plugin responsible for React components bundling.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"embeddable",
|
|
7
7
|
"sdk",
|
|
@@ -9,19 +9,15 @@
|
|
|
9
9
|
],
|
|
10
10
|
"main": "lib/index.cjs.js",
|
|
11
11
|
"module": "lib/index.esm.js",
|
|
12
|
-
"browser": "lib/index.umd.js",
|
|
13
12
|
"types": "lib/index.d.ts",
|
|
14
13
|
"repository": {
|
|
15
14
|
"type": "git",
|
|
16
15
|
"url": "git+https://github.com/embeddable-hq/embeddable-sdk.git",
|
|
17
|
-
"directory": "packages/react"
|
|
16
|
+
"directory": "packages/react-plugin"
|
|
18
17
|
},
|
|
19
18
|
"scripts": {
|
|
20
19
|
"build": "rollup -c"
|
|
21
20
|
},
|
|
22
|
-
"bin": {
|
|
23
|
-
"embeddable-react": "bin/embeddable-react"
|
|
24
|
-
},
|
|
25
21
|
"author": "Oleg Kapustin <oleg@trevor.io>",
|
|
26
22
|
"files": [
|
|
27
23
|
"lib/",
|
|
@@ -29,17 +25,15 @@
|
|
|
29
25
|
"templates/"
|
|
30
26
|
],
|
|
31
27
|
"license": "MIT",
|
|
32
|
-
"peerDependencies": {
|
|
33
|
-
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"@types/react": "^18.2.14",
|
|
37
|
-
"react": "^18.2.0"
|
|
38
|
-
},
|
|
39
28
|
"dependencies": {
|
|
29
|
+
"@embeddable.com/extract-components-config": "*",
|
|
40
30
|
"@embeddable.com/sdk-core": "*",
|
|
41
|
-
"@
|
|
42
|
-
"
|
|
43
|
-
|
|
31
|
+
"@embeddable.com/sdk-utils": "*",
|
|
32
|
+
"@vitejs/plugin-react": "^4.0.2"
|
|
33
|
+
},
|
|
34
|
+
"lint-staged": {
|
|
35
|
+
"*.{js,ts,jsx,tsx,json}": [
|
|
36
|
+
"prettier --write"
|
|
37
|
+
]
|
|
44
38
|
}
|
|
45
39
|
}
|
|
@@ -8,10 +8,16 @@ const COMPONENT_MAP = {
|
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export default (rootEl, componentName, props) => {
|
|
11
|
-
const Component = COMPONENT_MAP[componentName]
|
|
12
|
-
ReactDOM.createRoot(rootEl)
|
|
11
|
+
const Component = COMPONENT_MAP[componentName];
|
|
12
|
+
const root = ReactDOM.createRoot(rootEl);
|
|
13
|
+
const unmountHandler = () => {
|
|
14
|
+
root.unmount();
|
|
15
|
+
rootEl.removeEventListener('EMBEDDABLE_COMPONENT:UNMOUNT', unmountHandler);
|
|
16
|
+
};
|
|
17
|
+
root.render(
|
|
13
18
|
<React.Suspense fallback={<div/>}>
|
|
14
19
|
<Component {...props} propsUpdateListener={rootEl} />
|
|
15
20
|
</React.Suspense>
|
|
16
|
-
)
|
|
21
|
+
);
|
|
22
|
+
rootEl.addEventListener('EMBEDDABLE_COMPONENT:UNMOUNT', unmountHandler);
|
|
17
23
|
}
|
package/bin/embeddable-react
DELETED
package/lib/embedComponent.d.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { LoadDataParams } from "@embeddable.com/sdk-core";
|
|
3
|
-
type WrapperProps = {
|
|
4
|
-
propsUpdateListener: HTMLElement;
|
|
5
|
-
componentId: string;
|
|
6
|
-
};
|
|
7
|
-
export type Config = {
|
|
8
|
-
extendedProps?: (props: any) => any;
|
|
9
|
-
events: Record<string, EmbeddableEventHandler>;
|
|
10
|
-
dataLoaders: (props: any) => Record<string, LoadDataParams>;
|
|
11
|
-
};
|
|
12
|
-
export type EmbeddableEventHandler = (value: any) => any;
|
|
13
|
-
export type DataResponse = {
|
|
14
|
-
isLoading: boolean;
|
|
15
|
-
data?: any;
|
|
16
|
-
error?: string;
|
|
17
|
-
};
|
|
18
|
-
export declare function embedComponent(InnerComponent: React.ComponentType, config: Config): {
|
|
19
|
-
({ propsUpdateListener, ...props }: WrapperProps): React.JSX.Element;
|
|
20
|
-
displayName: string;
|
|
21
|
-
};
|
|
22
|
-
export {};
|
package/lib/embedControl.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
export type Config<T> = {
|
|
3
|
-
inputs: (value: any, setter: Setter<T>) => any;
|
|
4
|
-
events: Record<string, EmbeddableEventHandler<T>>;
|
|
5
|
-
mapProps?: (_: any) => any;
|
|
6
|
-
};
|
|
7
|
-
export type EmbeddableEventHandler<T> = (value: T) => T;
|
|
8
|
-
type Setter<T> = (value: T) => void;
|
|
9
|
-
export declare function embedControl<T>(InnerComponent: React.ComponentType, config: Config<T>): {
|
|
10
|
-
(props: any): React.JSX.Element;
|
|
11
|
-
displayName: string;
|
|
12
|
-
};
|
|
13
|
-
export {};
|
package/lib/index.d.ts
DELETED
package/lib/index.umd.js
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
(function (global, factory) {
|
|
2
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
|
3
|
-
typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
|
4
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.embeddableSdkReact = {}));
|
|
5
|
-
})(this, (function (exports) { 'use strict';
|
|
6
|
-
|
|
7
|
-
/******************************************************************************
|
|
8
|
-
Copyright (c) Microsoft Corporation.
|
|
9
|
-
|
|
10
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
11
|
-
purpose with or without fee is hereby granted.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
14
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
15
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
16
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
17
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
18
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
19
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
20
|
-
***************************************************************************** */
|
|
21
|
-
/* global Reflect, Promise, SuppressedError, Symbol */
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
var __assign = function() {
|
|
25
|
-
__assign = Object.assign || function __assign(t) {
|
|
26
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
27
|
-
s = arguments[i];
|
|
28
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
29
|
-
}
|
|
30
|
-
return t;
|
|
31
|
-
};
|
|
32
|
-
return __assign.apply(this, arguments);
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
function __rest(s, e) {
|
|
36
|
-
var t = {};
|
|
37
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
38
|
-
t[p] = s[p];
|
|
39
|
-
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
40
|
-
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
41
|
-
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
42
|
-
t[p[i]] = s[p[i]];
|
|
43
|
-
}
|
|
44
|
-
return t;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
48
|
-
var e = new Error(message);
|
|
49
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
var react = {exports: {}};
|
|
53
|
-
|
|
54
|
-
var react_production_min = {};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* @license React
|
|
58
|
-
* react.production.min.js
|
|
59
|
-
*
|
|
60
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
61
|
-
*
|
|
62
|
-
* This source code is licensed under the MIT license found in the
|
|
63
|
-
* LICENSE file in the root directory of this source tree.
|
|
64
|
-
*/
|
|
65
|
-
var l=Symbol.for("react.element"),n=Symbol.for("react.portal"),p=Symbol.for("react.fragment"),q=Symbol.for("react.strict_mode"),r=Symbol.for("react.profiler"),t=Symbol.for("react.provider"),u=Symbol.for("react.context"),v=Symbol.for("react.forward_ref"),w=Symbol.for("react.suspense"),x=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),z=Symbol.iterator;function A(a){if(null===a||"object"!==typeof a)return null;a=z&&a[z]||a["@@iterator"];return "function"===typeof a?a:null}
|
|
66
|
-
var B={isMounted:function(){return !1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},C=Object.assign,D={};function E(a,b,e){this.props=a;this.context=b;this.refs=D;this.updater=e||B;}E.prototype.isReactComponent={};
|
|
67
|
-
E.prototype.setState=function(a,b){if("object"!==typeof a&&"function"!==typeof a&&null!=a)throw Error("setState(...): takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,a,b,"setState");};E.prototype.forceUpdate=function(a){this.updater.enqueueForceUpdate(this,a,"forceUpdate");};function F(){}F.prototype=E.prototype;function G(a,b,e){this.props=a;this.context=b;this.refs=D;this.updater=e||B;}var H=G.prototype=new F;
|
|
68
|
-
H.constructor=G;C(H,E.prototype);H.isPureReactComponent=!0;var I=Array.isArray,J=Object.prototype.hasOwnProperty,K={current:null},L={key:!0,ref:!0,__self:!0,__source:!0};
|
|
69
|
-
function M(a,b,e){var d,c={},k=null,h=null;if(null!=b)for(d in void 0!==b.ref&&(h=b.ref),void 0!==b.key&&(k=""+b.key),b)J.call(b,d)&&!L.hasOwnProperty(d)&&(c[d]=b[d]);var g=arguments.length-2;if(1===g)c.children=e;else if(1<g){for(var f=Array(g),m=0;m<g;m++)f[m]=arguments[m+2];c.children=f;}if(a&&a.defaultProps)for(d in g=a.defaultProps,g)void 0===c[d]&&(c[d]=g[d]);return {$$typeof:l,type:a,key:k,ref:h,props:c,_owner:K.current}}
|
|
70
|
-
function N(a,b){return {$$typeof:l,type:a.type,key:b,ref:a.ref,props:a.props,_owner:a._owner}}function O(a){return "object"===typeof a&&null!==a&&a.$$typeof===l}function escape(a){var b={"=":"=0",":":"=2"};return "$"+a.replace(/[=:]/g,function(a){return b[a]})}var P=/\/+/g;function Q(a,b){return "object"===typeof a&&null!==a&&null!=a.key?escape(""+a.key):b.toString(36)}
|
|
71
|
-
function R(a,b,e,d,c){var k=typeof a;if("undefined"===k||"boolean"===k)a=null;var h=!1;if(null===a)h=!0;else switch(k){case "string":case "number":h=!0;break;case "object":switch(a.$$typeof){case l:case n:h=!0;}}if(h)return h=a,c=c(h),a=""===d?"."+Q(h,0):d,I(c)?(e="",null!=a&&(e=a.replace(P,"$&/")+"/"),R(c,b,e,"",function(a){return a})):null!=c&&(O(c)&&(c=N(c,e+(!c.key||h&&h.key===c.key?"":(""+c.key).replace(P,"$&/")+"/")+a)),b.push(c)),1;h=0;d=""===d?".":d+":";if(I(a))for(var g=0;g<a.length;g++){k=
|
|
72
|
-
a[g];var f=d+Q(k,g);h+=R(k,b,e,f,c);}else if(f=A(a),"function"===typeof f)for(a=f.call(a),g=0;!(k=a.next()).done;)k=k.value,f=d+Q(k,g++),h+=R(k,b,e,f,c);else if("object"===k)throw b=String(a),Error("Objects are not valid as a React child (found: "+("[object Object]"===b?"object with keys {"+Object.keys(a).join(", ")+"}":b)+"). If you meant to render a collection of children, use an array instead.");return h}
|
|
73
|
-
function S(a,b,e){if(null==a)return a;var d=[],c=0;R(a,d,"","",function(a){return b.call(e,a,c++)});return d}function T(a){if(-1===a._status){var b=a._result;b=b();b.then(function(b){if(0===a._status||-1===a._status)a._status=1,a._result=b;},function(b){if(0===a._status||-1===a._status)a._status=2,a._result=b;});-1===a._status&&(a._status=0,a._result=b);}if(1===a._status)return a._result.default;throw a._result;}
|
|
74
|
-
var U={current:null},V={transition:null},W={ReactCurrentDispatcher:U,ReactCurrentBatchConfig:V,ReactCurrentOwner:K};react_production_min.Children={map:S,forEach:function(a,b,e){S(a,function(){b.apply(this,arguments);},e);},count:function(a){var b=0;S(a,function(){b++;});return b},toArray:function(a){return S(a,function(a){return a})||[]},only:function(a){if(!O(a))throw Error("React.Children.only expected to receive a single React element child.");return a}};react_production_min.Component=E;react_production_min.Fragment=p;
|
|
75
|
-
react_production_min.Profiler=r;react_production_min.PureComponent=G;react_production_min.StrictMode=q;react_production_min.Suspense=w;react_production_min.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=W;
|
|
76
|
-
react_production_min.cloneElement=function(a,b,e){if(null===a||void 0===a)throw Error("React.cloneElement(...): The argument must be a React element, but you passed "+a+".");var d=C({},a.props),c=a.key,k=a.ref,h=a._owner;if(null!=b){void 0!==b.ref&&(k=b.ref,h=K.current);void 0!==b.key&&(c=""+b.key);if(a.type&&a.type.defaultProps)var g=a.type.defaultProps;for(f in b)J.call(b,f)&&!L.hasOwnProperty(f)&&(d[f]=void 0===b[f]&&void 0!==g?g[f]:b[f]);}var f=arguments.length-2;if(1===f)d.children=e;else if(1<f){g=Array(f);
|
|
77
|
-
for(var m=0;m<f;m++)g[m]=arguments[m+2];d.children=g;}return {$$typeof:l,type:a.type,key:c,ref:k,props:d,_owner:h}};react_production_min.createContext=function(a){a={$$typeof:u,_currentValue:a,_currentValue2:a,_threadCount:0,Provider:null,Consumer:null,_defaultValue:null,_globalName:null};a.Provider={$$typeof:t,_context:a};return a.Consumer=a};react_production_min.createElement=M;react_production_min.createFactory=function(a){var b=M.bind(null,a);b.type=a;return b};react_production_min.createRef=function(){return {current:null}};
|
|
78
|
-
react_production_min.forwardRef=function(a){return {$$typeof:v,render:a}};react_production_min.isValidElement=O;react_production_min.lazy=function(a){return {$$typeof:y,_payload:{_status:-1,_result:a},_init:T}};react_production_min.memo=function(a,b){return {$$typeof:x,type:a,compare:void 0===b?null:b}};react_production_min.startTransition=function(a){var b=V.transition;V.transition={};try{a();}finally{V.transition=b;}};react_production_min.unstable_act=function(){throw Error("act(...) is not supported in production builds of React.");};
|
|
79
|
-
react_production_min.useCallback=function(a,b){return U.current.useCallback(a,b)};react_production_min.useContext=function(a){return U.current.useContext(a)};react_production_min.useDebugValue=function(){};react_production_min.useDeferredValue=function(a){return U.current.useDeferredValue(a)};react_production_min.useEffect=function(a,b){return U.current.useEffect(a,b)};react_production_min.useId=function(){return U.current.useId()};react_production_min.useImperativeHandle=function(a,b,e){return U.current.useImperativeHandle(a,b,e)};
|
|
80
|
-
react_production_min.useInsertionEffect=function(a,b){return U.current.useInsertionEffect(a,b)};react_production_min.useLayoutEffect=function(a,b){return U.current.useLayoutEffect(a,b)};react_production_min.useMemo=function(a,b){return U.current.useMemo(a,b)};react_production_min.useReducer=function(a,b,e){return U.current.useReducer(a,b,e)};react_production_min.useRef=function(a){return U.current.useRef(a)};react_production_min.useState=function(a){return U.current.useState(a)};react_production_min.useSyncExternalStore=function(a,b,e){return U.current.useSyncExternalStore(a,b,e)};
|
|
81
|
-
react_production_min.useTransition=function(){return U.current.useTransition()};react_production_min.version="18.2.0";
|
|
82
|
-
|
|
83
|
-
{
|
|
84
|
-
react.exports = react_production_min;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
var reactExports = react.exports;
|
|
88
|
-
|
|
89
|
-
var UPDATE_VALUE_EVENT = "embeddable:value:changed";
|
|
90
|
-
var setValue = function (value, componentId, eventName) {
|
|
91
|
-
var event = new CustomEvent(UPDATE_VALUE_EVENT, {
|
|
92
|
-
bubbles: false,
|
|
93
|
-
detail: {
|
|
94
|
-
componentId: componentId,
|
|
95
|
-
value: value,
|
|
96
|
-
eventName: eventName
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
window.dispatchEvent(event);
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
103
|
-
var e = new Error(message);
|
|
104
|
-
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
var UPDATE_PROPS_EVENT_NAME = 'embeddable-event:update-props';
|
|
108
|
-
var RELOAD_DATASET_EVENT_NAME = 'embeddable-event:reload-dataset';
|
|
109
|
-
var ReducerActionTypes = {
|
|
110
|
-
loading: 'loading',
|
|
111
|
-
error: 'error',
|
|
112
|
-
data: 'data',
|
|
113
|
-
};
|
|
114
|
-
var reducer = function (state, action) {
|
|
115
|
-
var _a, _b, _c;
|
|
116
|
-
switch (action.type) {
|
|
117
|
-
case (ReducerActionTypes.loading): {
|
|
118
|
-
return __assign(__assign({}, state), (_a = {}, _a[action.inputName] = { isLoading: true }, _a));
|
|
119
|
-
}
|
|
120
|
-
case (ReducerActionTypes.data): {
|
|
121
|
-
return __assign(__assign({}, state), (_b = {}, _b[action.inputName] = { isLoading: false, data: action.payload.data }, _b));
|
|
122
|
-
}
|
|
123
|
-
case (ReducerActionTypes.error): {
|
|
124
|
-
return __assign(__assign({}, state), (_c = {}, _c[action.inputName] = { isLoading: false, error: action.payload.message || action.payload }, _c));
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return state;
|
|
128
|
-
};
|
|
129
|
-
var createInitialLoadersState = function (dataLoaders) { return Object.keys(dataLoaders).reduce(function (loaderState, loaderKey) {
|
|
130
|
-
var _a;
|
|
131
|
-
return (__assign(__assign({}, loaderState), (_a = {}, _a[loaderKey] = { isLoading: false }, _a)));
|
|
132
|
-
}, {}); };
|
|
133
|
-
var latestVariables = {};
|
|
134
|
-
function embedComponent(InnerComponent, config) {
|
|
135
|
-
var _a;
|
|
136
|
-
function EmbeddableWrapper(_a) {
|
|
137
|
-
var propsUpdateListener = _a.propsUpdateListener, props = __rest(_a, ["propsUpdateListener"]);
|
|
138
|
-
var _b = reactExports.useState(props), propsProxy = _b[0], setProps = _b[1];
|
|
139
|
-
var componentId = props.componentId;
|
|
140
|
-
var propsUpdateEventHandler = function (_a) {
|
|
141
|
-
var detail = _a.detail;
|
|
142
|
-
return setProps(detail);
|
|
143
|
-
};
|
|
144
|
-
reactExports.useEffect(function () {
|
|
145
|
-
propsUpdateListener.addEventListener(UPDATE_PROPS_EVENT_NAME, propsUpdateEventHandler);
|
|
146
|
-
return function () { return propsUpdateListener.removeEventListener(UPDATE_PROPS_EVENT_NAME, propsUpdateEventHandler); };
|
|
147
|
-
}, []);
|
|
148
|
-
var extendedProps = reactExports.useMemo(function () { var _a; return (_a = config === null || config === void 0 ? void 0 : config.extendedProps) === null || _a === void 0 ? void 0 : _a.call(config, propsProxy); }, [propsProxy, config === null || config === void 0 ? void 0 : config.extendedProps]);
|
|
149
|
-
var dataLoaders = reactExports.useMemo(function () { var _a, _b; return (_b = (_a = config === null || config === void 0 ? void 0 : config.dataLoaders) === null || _a === void 0 ? void 0 : _a.call(config, propsProxy)) !== null && _b !== void 0 ? _b : {}; }, [propsProxy, config === null || config === void 0 ? void 0 : config.dataLoaders]);
|
|
150
|
-
var _c = reactExports.useReducer(reducer, dataLoaders, createInitialLoadersState), loadersState = _c[0], dispatch = _c[1];
|
|
151
|
-
var handleDataLoaded = function (inputName) { return function (res) { return dispatch({ type: ReducerActionTypes.data, inputName: inputName, payload: res.data }); }; };
|
|
152
|
-
var handleError = function (inputName) { return function (error) { return dispatch({ type: ReducerActionTypes.error, inputName: inputName, payload: error }); }; };
|
|
153
|
-
var reloadDataset = function (inputName, params) {
|
|
154
|
-
dispatch({ type: ReducerActionTypes.loading, inputName: inputName });
|
|
155
|
-
params.dataLoader(params.requestParams, latestVariables)
|
|
156
|
-
.then(handleDataLoaded(inputName))
|
|
157
|
-
.catch(handleError(inputName));
|
|
158
|
-
};
|
|
159
|
-
var variableChangedEventHandler = function (_a) {
|
|
160
|
-
var detail = _a.detail;
|
|
161
|
-
latestVariables = detail.variableValues;
|
|
162
|
-
Object.entries(dataLoaders)
|
|
163
|
-
.filter(function (_a) {
|
|
164
|
-
_a[0]; var params = _a[1];
|
|
165
|
-
return params.requestParams.from.datasetId === detail.datasetId;
|
|
166
|
-
})
|
|
167
|
-
.forEach(function (_a) {
|
|
168
|
-
var inputName = _a[0], params = _a[1];
|
|
169
|
-
return reloadDataset(inputName, params);
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
reactExports.useEffect(function () {
|
|
173
|
-
Object.entries(dataLoaders).forEach(function (_a) {
|
|
174
|
-
var inputName = _a[0], params = _a[1];
|
|
175
|
-
return reloadDataset(inputName, params);
|
|
176
|
-
});
|
|
177
|
-
window.addEventListener(RELOAD_DATASET_EVENT_NAME, variableChangedEventHandler);
|
|
178
|
-
return function () { return window.removeEventListener(RELOAD_DATASET_EVENT_NAME, variableChangedEventHandler); };
|
|
179
|
-
}, [JSON.stringify(Object.values(dataLoaders).map(function (loader) { return loader.requestParams; }))]);
|
|
180
|
-
var createEvent = function (value, eventName) { return setValue(value, componentId, eventName); };
|
|
181
|
-
var events = config === null || config === void 0 ? void 0 : config.events;
|
|
182
|
-
var eventProps = {};
|
|
183
|
-
if (events) {
|
|
184
|
-
var _loop_1 = function (event_1) {
|
|
185
|
-
if (events.hasOwnProperty(event_1)) {
|
|
186
|
-
var eventFunction_1 = events[event_1];
|
|
187
|
-
eventProps[event_1] = function (value) { return createEvent(eventFunction_1(value), event_1); };
|
|
188
|
-
}
|
|
189
|
-
};
|
|
190
|
-
for (var event_1 in events) {
|
|
191
|
-
_loop_1(event_1);
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
return reactExports.createElement(InnerComponent, __assign({}, propsProxy, extendedProps, eventProps, loadersState));
|
|
195
|
-
}
|
|
196
|
-
EmbeddableWrapper.displayName = "embedded(".concat((_a = InnerComponent.displayName) !== null && _a !== void 0 ? _a : 'Component', ")");
|
|
197
|
-
return EmbeddableWrapper;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function embedControl(InnerComponent, config) {
|
|
201
|
-
var _a;
|
|
202
|
-
function EmbeddableWrapper(props) {
|
|
203
|
-
var _a, _b;
|
|
204
|
-
var componentId = props.componentId, initialValue = props.initialValue;
|
|
205
|
-
var _c = reactExports.useState(initialValue), componentState = _c[0], setComponentState = _c[1];
|
|
206
|
-
var setter = function (value) {
|
|
207
|
-
setComponentState(value);
|
|
208
|
-
setValue(value, componentId);
|
|
209
|
-
};
|
|
210
|
-
return reactExports.createElement(InnerComponent, __assign({}, config.inputs(componentState, setter), ((_b = (_a = config.mapProps) === null || _a === void 0 ? void 0 : _a.call(config, props)) !== null && _b !== void 0 ? _b : {})));
|
|
211
|
-
}
|
|
212
|
-
EmbeddableWrapper.displayName = "embedded(".concat((_a = InnerComponent.displayName) !== null && _a !== void 0 ? _a : 'Editor', ")");
|
|
213
|
-
return EmbeddableWrapper;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
exports.embedComponent = embedComponent;
|
|
217
|
-
exports.embedControl = embedControl;
|
|
218
|
-
|
|
219
|
-
}));
|
package/scripts/build.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
const path = require("path");
|
|
2
|
-
const { fork } = require('child_process');
|
|
3
|
-
const oraP = import('ora');
|
|
4
|
-
const core = require("@embeddable.com/sdk-core/scripts");
|
|
5
|
-
|
|
6
|
-
const {createContext} = require("./createContext");
|
|
7
|
-
const {prepare} = require("./prepare");
|
|
8
|
-
const {cleanup} = require("./cleanup");
|
|
9
|
-
|
|
10
|
-
const generateFork = fork(
|
|
11
|
-
path.resolve(__dirname, 'generate.js'),
|
|
12
|
-
[],
|
|
13
|
-
process.env.NODE_ENV === 'dev' ? undefined : { silent: true }
|
|
14
|
-
);
|
|
15
|
-
|
|
16
|
-
async function build() {
|
|
17
|
-
const ora = (await oraP).default;
|
|
18
|
-
|
|
19
|
-
const spinnerPrepare = ora("preparing...").start();
|
|
20
|
-
|
|
21
|
-
const ctx = createContext(path.resolve(__dirname, '..'), process.cwd());
|
|
22
|
-
|
|
23
|
-
await validationEmulation();
|
|
24
|
-
await prepare(ctx);
|
|
25
|
-
spinnerPrepare.succeed("preparation competed");
|
|
26
|
-
|
|
27
|
-
const spinnerBuild = ora("building...").start();
|
|
28
|
-
|
|
29
|
-
generateFork.send({ ctx });
|
|
30
|
-
|
|
31
|
-
generateFork.on('exit', async () => {
|
|
32
|
-
await cleanup(ctx);
|
|
33
|
-
spinnerBuild.succeed("build completed");
|
|
34
|
-
|
|
35
|
-
await core.buildTypes(ctx);
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
module.exports = { build };
|
|
41
|
-
|
|
42
|
-
// TODO: later we will validate configs e.g. yaml files with this function.
|
|
43
|
-
function validationEmulation() {
|
|
44
|
-
return new Promise((res, _rej) => {
|
|
45
|
-
setTimeout(res, 4000);
|
|
46
|
-
})
|
|
47
|
-
}
|
package/scripts/cleanup.js
DELETED
package/scripts/createContext.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
|
|
3
|
-
function createContext (pluginRoot, clientRoot) {
|
|
4
|
-
return {
|
|
5
|
-
plugin: {
|
|
6
|
-
rootDir: pluginRoot,
|
|
7
|
-
templatesDir: path.resolve(pluginRoot, 'templates'),
|
|
8
|
-
},
|
|
9
|
-
client: {
|
|
10
|
-
rootDir: clientRoot,
|
|
11
|
-
srcDir: path.resolve(clientRoot, 'src'), // TODO: should be specified via command parameters or from rc file.
|
|
12
|
-
buildDir: path.resolve(clientRoot, '.embeddable-build'),
|
|
13
|
-
},
|
|
14
|
-
outputOptions: { // TODO: should be specified via command parameters or from rc file.
|
|
15
|
-
fileName: 'embeddable-prepared',
|
|
16
|
-
buildName: 'embeddable-prepared-build',
|
|
17
|
-
typesEntryPointFilename: 'embeddable-types-entry-point.js',
|
|
18
|
-
},
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
module.exports = { createContext };
|
package/scripts/generate.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
const fs = require("fs/promises");
|
|
2
|
-
const path = require("path");
|
|
3
|
-
const vite = require("vite");
|
|
4
|
-
const viteReactPlugin = require('@vitejs/plugin-react');
|
|
5
|
-
const core = require("@embeddable.com/sdk-core/scripts");
|
|
6
|
-
|
|
7
|
-
process.on('message', async ({ ctx }) => {
|
|
8
|
-
await generate(ctx);
|
|
9
|
-
|
|
10
|
-
process.exit();
|
|
11
|
-
});
|
|
12
|
-
|
|
13
|
-
const EMB_FILE_REGEX = /^(.*)(?<!\.type|\.options)\.emb\.[jt]s$/;
|
|
14
|
-
|
|
15
|
-
async function generate(ctx) {
|
|
16
|
-
const filesList = await core.findEmbFiles(ctx.client.srcDir, EMB_FILE_REGEX);
|
|
17
|
-
|
|
18
|
-
await injectImports(ctx, filesList);
|
|
19
|
-
|
|
20
|
-
await runViteBuild(ctx);
|
|
21
|
-
|
|
22
|
-
await runCoreBuild(ctx);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
module.exports = { generate };
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
async function runCoreBuild(ctx) {
|
|
29
|
-
await core.build({
|
|
30
|
-
outDir: ctx.outputOptions.buildName,
|
|
31
|
-
renderFunctionFileName: ctx.outputOptions.fileName
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
async function runViteBuild(ctx) {
|
|
36
|
-
process.chdir(ctx.client.rootDir);
|
|
37
|
-
|
|
38
|
-
await vite.build({
|
|
39
|
-
plugins: [viteReactPlugin()],
|
|
40
|
-
build: {
|
|
41
|
-
lib: {
|
|
42
|
-
entry: './embeddable-entry-point.jsx',
|
|
43
|
-
formats: ['es'],
|
|
44
|
-
fileName: ctx.outputOptions.fileName
|
|
45
|
-
},
|
|
46
|
-
outDir: `.embeddable-build/${ctx.outputOptions.buildName}`
|
|
47
|
-
},
|
|
48
|
-
define: { 'process.env.NODE_ENV': '"production"' }
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
const REPLACE_TOKEN = '{{LAZY_IMPORTS}}';
|
|
54
|
-
|
|
55
|
-
async function injectImports(ctx, filesList) {
|
|
56
|
-
const imports = filesList.map(([fileName, filePath]) =>
|
|
57
|
-
`\t${fileName}: React.lazy(() => import('./${path.relative(ctx.client.rootDir, filePath)}'))`
|
|
58
|
-
).join(',\n');
|
|
59
|
-
|
|
60
|
-
const content = await fs.readFile(
|
|
61
|
-
path.resolve(ctx.plugin.templatesDir, 'embeddable-entry-point.jsx.template'),
|
|
62
|
-
'utf8'
|
|
63
|
-
);
|
|
64
|
-
|
|
65
|
-
await fs.writeFile(
|
|
66
|
-
path.resolve(ctx.client.rootDir, 'embeddable-entry-point.jsx'),
|
|
67
|
-
content.replace(REPLACE_TOKEN, imports)
|
|
68
|
-
);
|
|
69
|
-
}
|
package/scripts/prepare.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
const fsSync = require("fs");
|
|
2
|
-
const fs = require("fs/promises");
|
|
3
|
-
|
|
4
|
-
async function prepare (ctx) {
|
|
5
|
-
await removeIfExists(ctx.client.buildDir);
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
module.exports = { prepare }
|
|
9
|
-
|
|
10
|
-
async function removeIfExists(buildDir) {
|
|
11
|
-
if (fsSync.existsSync(buildDir)) await fs.rm(buildDir, { recursive: true });
|
|
12
|
-
}
|
|
13
|
-
|