@embeddable.com/sdk-react 3.2.0-next.9 → 3.2.1
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/extractComponentsConfigPlugin.d.ts +3 -2
- package/lib/index.esm.js +79 -34
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +80 -34
- package/lib/index.js.map +1 -1
- package/lib/validate/schema/componentMetaSchema.d.ts +60 -170
- package/lib/validate/schema/editorMetaSchema.d.ts +4 -14
- package/package.json +5 -4
package/lib/index.js
CHANGED
|
@@ -7,7 +7,9 @@ var vite = require('vite');
|
|
|
7
7
|
var viteReactPlugin = require('@vitejs/plugin-react');
|
|
8
8
|
var fs = require('node:fs/promises');
|
|
9
9
|
var url = require('node:url');
|
|
10
|
+
var globalRegistrator = require('@happy-dom/global-registrator');
|
|
10
11
|
require('node:child_process');
|
|
12
|
+
var crypto = require('node:crypto');
|
|
11
13
|
var zod = require('zod');
|
|
12
14
|
var parser = require('@babel/parser');
|
|
13
15
|
var traverse = require('@babel/traverse');
|
|
@@ -36,6 +38,7 @@ var path__namespace = /*#__PURE__*/_interopNamespaceDefault(path$1);
|
|
|
36
38
|
var vite__namespace = /*#__PURE__*/_interopNamespaceDefault(vite);
|
|
37
39
|
var fs__namespace = /*#__PURE__*/_interopNamespaceDefault(fs);
|
|
38
40
|
var url__namespace = /*#__PURE__*/_interopNamespaceDefault(url);
|
|
41
|
+
var crypto__namespace = /*#__PURE__*/_interopNamespaceDefault(crypto);
|
|
39
42
|
var fs__namespace$1 = /*#__PURE__*/_interopNamespaceDefault(fs$1);
|
|
40
43
|
|
|
41
44
|
var createContext = (pluginRoot, coreCtx) => {
|
|
@@ -50,45 +53,16 @@ var createContext = (pluginRoot, coreCtx) => {
|
|
|
50
53
|
};
|
|
51
54
|
};
|
|
52
55
|
|
|
56
|
+
globalRegistrator.GlobalRegistrator.register({
|
|
57
|
+
url: "http://localhost:3000",
|
|
58
|
+
width: 1920,
|
|
59
|
+
height: 1080,
|
|
60
|
+
});
|
|
53
61
|
const loadComponentMeta = async (moduleId) => {
|
|
54
62
|
const module = await import(url__namespace.pathToFileURL(moduleId).href);
|
|
55
63
|
return module.meta;
|
|
56
64
|
};
|
|
57
65
|
|
|
58
|
-
/**
|
|
59
|
-
* TODO: for some reason code from @embeddable.com/extract-components-config
|
|
60
|
-
* is being cached. Thus we use this code duplication in place. Please investigate and fix.
|
|
61
|
-
*/
|
|
62
|
-
var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, componentFileRegex, searchEntry = "", }) => {
|
|
63
|
-
let configs = [];
|
|
64
|
-
return {
|
|
65
|
-
name: "extract-components-config",
|
|
66
|
-
moduleParsed: async (moduleInfo) => {
|
|
67
|
-
var _a;
|
|
68
|
-
if (componentFileRegex.test(moduleInfo.id) &&
|
|
69
|
-
((_a = moduleInfo.code) === null || _a === void 0 ? void 0 : _a.includes(searchEntry))) {
|
|
70
|
-
const meta = await loadComponentMeta(moduleInfo.id);
|
|
71
|
-
const configJSON = JSON.stringify(meta, (_key, value) => typeof value === "object" &&
|
|
72
|
-
value !== null &&
|
|
73
|
-
"__embeddableType" in value
|
|
74
|
-
? value.toString()
|
|
75
|
-
: value);
|
|
76
|
-
configs.push(configJSON);
|
|
77
|
-
}
|
|
78
|
-
},
|
|
79
|
-
buildEnd: async () => {
|
|
80
|
-
const template = `
|
|
81
|
-
globalThis.__EMBEDDABLE__ = globalThis.__EMBEDDABLE__ || {};
|
|
82
|
-
globalThis.__EMBEDDABLE__.${globalKey} = globalThis.__EMBEDDABLE__.${globalKey} || [
|
|
83
|
-
__PLACEHOLDER__
|
|
84
|
-
];
|
|
85
|
-
`;
|
|
86
|
-
await fs__namespace.writeFile(`${outputDir}/${fileName}`, template.replace("__PLACEHOLDER__", configs.filter(Boolean).join(",\n")));
|
|
87
|
-
configs = [];
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
|
|
92
66
|
var findFiles = async (initialSrcDir, regex) => {
|
|
93
67
|
const filesList = [];
|
|
94
68
|
async function findFilesRec(srcDir) {
|
|
@@ -295,6 +269,11 @@ class ZodError extends Error {
|
|
|
295
269
|
processError(this);
|
|
296
270
|
return fieldErrors;
|
|
297
271
|
}
|
|
272
|
+
static assert(value) {
|
|
273
|
+
if (!(value instanceof ZodError)) {
|
|
274
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
298
277
|
toString() {
|
|
299
278
|
return this.message;
|
|
300
279
|
}
|
|
@@ -326,6 +305,11 @@ ZodError.create = (issues) => {
|
|
|
326
305
|
const error = new ZodError(issues);
|
|
327
306
|
return error;
|
|
328
307
|
};
|
|
308
|
+
|
|
309
|
+
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
310
|
+
var e = new Error(message);
|
|
311
|
+
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
312
|
+
};
|
|
329
313
|
|
|
330
314
|
var errorUtil;
|
|
331
315
|
(function (errorUtil) {
|
|
@@ -401,6 +385,63 @@ const formatErrorPath = (path) => {
|
|
|
401
385
|
return formatted;
|
|
402
386
|
};
|
|
403
387
|
|
|
388
|
+
/**
|
|
389
|
+
* Get the hash of the content string. It returns the first 5 characters of the hash
|
|
390
|
+
* Example: getContentHash("Hello World")
|
|
391
|
+
* @param contentString The content string to hash
|
|
392
|
+
* @returns
|
|
393
|
+
*/
|
|
394
|
+
const getContentHash = (contentString) => {
|
|
395
|
+
return crypto__namespace
|
|
396
|
+
.createHash("md5")
|
|
397
|
+
.update(contentString)
|
|
398
|
+
.digest("hex")
|
|
399
|
+
.substring(0, 5);
|
|
400
|
+
};
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* TODO: for some reason code from @embeddable.com/extract-components-config
|
|
404
|
+
* is being cached. Thus we use this code duplication in place. Please investigate and fix.
|
|
405
|
+
*/
|
|
406
|
+
var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, componentFileRegex, isDev = false, searchEntry = "", }) => {
|
|
407
|
+
let configs = [];
|
|
408
|
+
return {
|
|
409
|
+
name: "extract-components-config",
|
|
410
|
+
moduleParsed: async (moduleInfo) => {
|
|
411
|
+
var _a;
|
|
412
|
+
if (componentFileRegex.test(moduleInfo.id) &&
|
|
413
|
+
((_a = moduleInfo.code) === null || _a === void 0 ? void 0 : _a.includes(searchEntry))) {
|
|
414
|
+
const meta = await loadComponentMeta(moduleInfo.id);
|
|
415
|
+
const configJSON = JSON.stringify(meta, (_key, value) => typeof value === "object" &&
|
|
416
|
+
value !== null &&
|
|
417
|
+
"__embeddableType" in value
|
|
418
|
+
? value.toString()
|
|
419
|
+
: value);
|
|
420
|
+
configs.push(configJSON);
|
|
421
|
+
}
|
|
422
|
+
},
|
|
423
|
+
buildEnd: async () => {
|
|
424
|
+
const template = `
|
|
425
|
+
globalThis.__EMBEDDABLE__ = globalThis.__EMBEDDABLE__ || {};
|
|
426
|
+
globalThis.__EMBEDDABLE__.${globalKey} = globalThis.__EMBEDDABLE__.${globalKey} || [
|
|
427
|
+
__PLACEHOLDER__
|
|
428
|
+
];
|
|
429
|
+
`;
|
|
430
|
+
// sort to make sure the hash is consistent
|
|
431
|
+
configs.sort((a, b) => a.localeCompare(b));
|
|
432
|
+
const contentString = configs.filter(Boolean).join(",\n");
|
|
433
|
+
let newFileName = fileName;
|
|
434
|
+
if (!isDev) {
|
|
435
|
+
const fileHash = getContentHash(contentString);
|
|
436
|
+
const fileHashExtention = `-${fileHash}.js`;
|
|
437
|
+
newFileName = `${fileName.replace(".js", fileHashExtention)}`;
|
|
438
|
+
}
|
|
439
|
+
await fs__namespace.writeFile(`${outputDir}/${newFileName}`, template.replace("__PLACEHOLDER__", contentString));
|
|
440
|
+
configs = [];
|
|
441
|
+
},
|
|
442
|
+
};
|
|
443
|
+
};
|
|
444
|
+
|
|
404
445
|
/******************************************************************************
|
|
405
446
|
Copyright (c) Microsoft Corporation.
|
|
406
447
|
|
|
@@ -510,6 +551,9 @@ createBuiltInType("time", {
|
|
|
510
551
|
});
|
|
511
552
|
createBuiltInType("timeRange", {
|
|
512
553
|
transform: function (value) {
|
|
554
|
+
// Return undefined instead of a null populated object
|
|
555
|
+
if (!value)
|
|
556
|
+
return undefined;
|
|
513
557
|
var _a = [value === null || value === void 0 ? void 0 : value.from, value === null || value === void 0 ? void 0 : value.to], from = _a[0], to = _a[1];
|
|
514
558
|
var fromDate = new Date(from);
|
|
515
559
|
var toDate = new Date(to);
|
|
@@ -1062,6 +1106,7 @@ async function runViteBuild(ctx, watch = null) {
|
|
|
1062
1106
|
plugins: [
|
|
1063
1107
|
viteReactPlugin(),
|
|
1064
1108
|
extractComponentsConfigPlugin({
|
|
1109
|
+
isDev: !!watch,
|
|
1065
1110
|
globalKey: "componentsMeta",
|
|
1066
1111
|
fileName: "embeddable-components-meta.js",
|
|
1067
1112
|
outputDir: ctx.client.buildDir,
|
|
@@ -1069,6 +1114,7 @@ async function runViteBuild(ctx, watch = null) {
|
|
|
1069
1114
|
searchEntry: "defineComponent",
|
|
1070
1115
|
}),
|
|
1071
1116
|
extractComponentsConfigPlugin({
|
|
1117
|
+
isDev: !!watch,
|
|
1072
1118
|
globalKey: "editorsMeta",
|
|
1073
1119
|
fileName: "embeddable-editors-meta.js",
|
|
1074
1120
|
outputDir: ctx.client.buildDir,
|