@embeddable.com/sdk-react 4.0.3 → 4.0.4
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/dynamicImportHandler.js +14 -0
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +26 -29
- package/lib/index.js.map +1 -1
- package/lib/plugin.d.ts +21 -0
- package/lib/proxyHandler.d.ts +4 -0
- package/lib/utils/modules.d.ts +13 -0
- package/lib/validate/errorFormatter.d.ts +3 -0
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -4,6 +4,7 @@ var path = require('node:path');
|
|
|
4
4
|
var fs$2 = require('fs/promises');
|
|
5
5
|
var path$1 = require('path');
|
|
6
6
|
var vite = require('vite');
|
|
7
|
+
var ora = require('ora');
|
|
7
8
|
var viteReactPlugin = require('@vitejs/plugin-react');
|
|
8
9
|
var fs = require('node:fs/promises');
|
|
9
10
|
var url = require('node:url');
|
|
@@ -314,7 +315,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
314
315
|
var errorUtil;
|
|
315
316
|
(function (errorUtil) {
|
|
316
317
|
errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
317
|
-
errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message ===
|
|
318
|
+
errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === undefined ? undefined : message.message;
|
|
318
319
|
})(errorUtil || (errorUtil = {}));
|
|
319
320
|
var ZodFirstPartyTypeKind;
|
|
320
321
|
(function (ZodFirstPartyTypeKind) {
|
|
@@ -410,7 +411,7 @@ var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, component
|
|
|
410
411
|
moduleParsed: async (moduleInfo) => {
|
|
411
412
|
var _a;
|
|
412
413
|
if (componentFileRegex.test(moduleInfo.id) &&
|
|
413
|
-
((_a = moduleInfo.code) === null || _a ===
|
|
414
|
+
((_a = moduleInfo.code) === null || _a === undefined ? undefined : _a.includes(searchEntry))) {
|
|
414
415
|
try {
|
|
415
416
|
const meta = await loadComponentMeta(moduleInfo.id);
|
|
416
417
|
const configJSON = JSON.stringify(meta, (_key, value) => typeof value === "object" &&
|
|
@@ -483,7 +484,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
483
484
|
|
|
484
485
|
var DEFAULT_LOCALE = "en-US";
|
|
485
486
|
var createBuiltInType = function (name, typeConfig) {
|
|
486
|
-
if (typeConfig ===
|
|
487
|
+
if (typeConfig === undefined) { typeConfig = {}; }
|
|
487
488
|
return ({
|
|
488
489
|
__embeddableType: "built-in",
|
|
489
490
|
toString: function () { return name; },
|
|
@@ -529,7 +530,7 @@ createBuiltInType("number", {
|
|
|
529
530
|
var _a;
|
|
530
531
|
return Array.isArray(value)
|
|
531
532
|
? "[".concat(value.join(","), "]")
|
|
532
|
-
: (_a = value === null || value ===
|
|
533
|
+
: ((_a = value === null || value === undefined ? undefined : value.toLocaleString(DEFAULT_LOCALE)) !== null && _a !== undefined ? _a : "");
|
|
533
534
|
},
|
|
534
535
|
});
|
|
535
536
|
createBuiltInType("boolean", {
|
|
@@ -538,19 +539,19 @@ createBuiltInType("boolean", {
|
|
|
538
539
|
});
|
|
539
540
|
createBuiltInType("time", {
|
|
540
541
|
transform: function (value) {
|
|
541
|
-
var date = (value === null || value ===
|
|
542
|
+
var date = (value === null || value === undefined ? undefined : value.date) ? new Date(value.date) : undefined;
|
|
542
543
|
var isValid = date && date.toString() !== "Invalid Date";
|
|
543
544
|
return {
|
|
544
545
|
date: isValid ? date : undefined,
|
|
545
|
-
relativeTimeString: value === null || value ===
|
|
546
|
+
relativeTimeString: value === null || value === undefined ? undefined : value.relativeTimeString,
|
|
546
547
|
};
|
|
547
548
|
},
|
|
548
549
|
optionLabel: function (value) {
|
|
549
550
|
var _a, _b;
|
|
550
551
|
if (!value)
|
|
551
552
|
return "";
|
|
552
|
-
if (value === null || value ===
|
|
553
|
-
return ((_b = (_a = value.date) === null || _a ===
|
|
553
|
+
if (value === null || value === undefined ? undefined : value.date) {
|
|
554
|
+
return ((_b = (_a = value.date) === null || _a === undefined ? undefined : _a.toLocaleDateString(DEFAULT_LOCALE)) !== null && _b !== undefined ? _b : value.date.toLocaleString());
|
|
554
555
|
}
|
|
555
556
|
return value.relativeTimeString;
|
|
556
557
|
},
|
|
@@ -560,23 +561,23 @@ createBuiltInType("timeRange", {
|
|
|
560
561
|
// Return undefined instead of a null populated object
|
|
561
562
|
if (!value)
|
|
562
563
|
return undefined;
|
|
563
|
-
var _a = [value === null || value ===
|
|
564
|
+
var _a = [value === null || value === undefined ? undefined : value.from, value === null || value === undefined ? undefined : value.to], from = _a[0], to = _a[1];
|
|
564
565
|
var fromDate = new Date(from);
|
|
565
566
|
var toDate = new Date(to);
|
|
566
567
|
return {
|
|
567
568
|
from: fromDate.toString() !== "Invalid Date" ? fromDate : undefined,
|
|
568
569
|
to: toDate.toString() !== "Invalid Date" ? toDate : undefined,
|
|
569
|
-
relativeTimeString: value === null || value ===
|
|
570
|
+
relativeTimeString: value === null || value === undefined ? undefined : value.relativeTimeString,
|
|
570
571
|
};
|
|
571
572
|
},
|
|
572
573
|
optionLabel: function (value) {
|
|
573
574
|
var _a, _b, _c, _d, _e, _f;
|
|
574
575
|
if (!value)
|
|
575
576
|
return "";
|
|
576
|
-
if ((value === null || value ===
|
|
577
|
-
return "".concat((_b = (_a = value.from) === null || _a ===
|
|
577
|
+
if ((value === null || value === undefined ? undefined : value.from) && (value === null || value === undefined ? undefined : value.to)) {
|
|
578
|
+
return "".concat((_b = (_a = value.from) === null || _a === undefined ? undefined : _a.toLocaleDateString(DEFAULT_LOCALE)) !== null && _b !== undefined ? _b : (_c = value.from) === null || _c === undefined ? undefined : _c.toLocaleString(), ",").concat((_e = (_d = value.to) === null || _d === undefined ? undefined : _d.toLocaleDateString(DEFAULT_LOCALE)) !== null && _e !== undefined ? _e : (_f = value.to) === null || _f === undefined ? undefined : _f.toLocaleString());
|
|
578
579
|
}
|
|
579
|
-
return value === null || value ===
|
|
580
|
+
return value === null || value === undefined ? undefined : value.relativeTimeString;
|
|
580
581
|
},
|
|
581
582
|
});
|
|
582
583
|
createBuiltInType("granularity", {
|
|
@@ -723,7 +724,7 @@ const validateComponentProps = (metaInfo) => {
|
|
|
723
724
|
var _a;
|
|
724
725
|
const componentConfig = path.node.declaration
|
|
725
726
|
.arguments[2];
|
|
726
|
-
const propsNode = (_a = componentConfig.properties) === null || _a ===
|
|
727
|
+
const propsNode = (_a = componentConfig.properties) === null || _a === undefined ? undefined : _a.find((x) => { var _a; return ((_a = x.key) === null || _a === undefined ? undefined : _a.name) === "props"; });
|
|
727
728
|
// There is no props defined
|
|
728
729
|
if (!propsNode)
|
|
729
730
|
return;
|
|
@@ -752,7 +753,7 @@ const validateComponentProps = (metaInfo) => {
|
|
|
752
753
|
};
|
|
753
754
|
const validateComponentEvents = (metaInfo) => {
|
|
754
755
|
var _a, _b;
|
|
755
|
-
const definedEvents = (_b = (_a = metaInfo.meta.events) === null || _a ===
|
|
756
|
+
const definedEvents = (_b = (_a = metaInfo.meta.events) === null || _a === undefined ? undefined : _a.map((e) => e.name)) !== null && _b !== undefined ? _b : [];
|
|
756
757
|
let implementedEvents = [];
|
|
757
758
|
const errors = [];
|
|
758
759
|
parseAndTraverse(metaInfo.moduleInfo.code, {
|
|
@@ -760,9 +761,9 @@ const validateComponentEvents = (metaInfo) => {
|
|
|
760
761
|
var _a, _b, _c, _d;
|
|
761
762
|
const componentConfig = path.node.declaration
|
|
762
763
|
.arguments[2];
|
|
763
|
-
const eventsNode = (_a = componentConfig.properties) === null || _a ===
|
|
764
|
+
const eventsNode = (_a = componentConfig.properties) === null || _a === undefined ? undefined : _a.find((p) => { var _a; return ((_a = p.key) === null || _a === undefined ? undefined : _a.name) === "events"; });
|
|
764
765
|
implementedEvents =
|
|
765
|
-
(_d = (_c = (_b = eventsNode === null || eventsNode ===
|
|
766
|
+
(_d = (_c = (_b = eventsNode === null || eventsNode === undefined ? undefined : eventsNode.value) === null || _b === undefined ? undefined : _b.properties) === null || _c === undefined ? undefined : _c.map((p) => p.key.name)) !== null && _d !== undefined ? _d : [];
|
|
766
767
|
},
|
|
767
768
|
});
|
|
768
769
|
const definedEventsSet = new Set(definedEvents);
|
|
@@ -809,7 +810,7 @@ const validateVariableInputs = (meta) => {
|
|
|
809
810
|
const inputs = variableConfig.inputs;
|
|
810
811
|
if (inputs) {
|
|
811
812
|
inputs.forEach((input, inputIdx) => {
|
|
812
|
-
const definedInput = definedInputs === null || definedInputs ===
|
|
813
|
+
const definedInput = definedInputs === null || definedInputs === undefined ? undefined : definedInputs.find((d) => d.name === input);
|
|
813
814
|
if (!definedInput) {
|
|
814
815
|
const path = formatErrorPath(["variables", idx, "inputs", inputIdx]);
|
|
815
816
|
errors.push(`${path}: input "${input}" is not defined`);
|
|
@@ -829,7 +830,7 @@ const validateVariableEvents = (meta) => {
|
|
|
829
830
|
const events = variableConfig.events;
|
|
830
831
|
if (events) {
|
|
831
832
|
events.forEach((event, eventIdx) => {
|
|
832
|
-
const definedEvent = definedEvents === null || definedEvents ===
|
|
833
|
+
const definedEvent = definedEvents === null || definedEvents === undefined ? undefined : definedEvents.find((d) => d.name === event.name);
|
|
833
834
|
if (!definedEvent) {
|
|
834
835
|
const path = formatErrorPath([
|
|
835
836
|
"variables",
|
|
@@ -842,7 +843,7 @@ const validateVariableEvents = (meta) => {
|
|
|
842
843
|
return;
|
|
843
844
|
}
|
|
844
845
|
const definedProperties = definedEvent.properties;
|
|
845
|
-
const definedProperty = definedProperties === null || definedProperties ===
|
|
846
|
+
const definedProperty = definedProperties === null || definedProperties === undefined ? undefined : definedProperties.find((p) => p.name === event.property);
|
|
846
847
|
if (!definedProperty) {
|
|
847
848
|
const path = formatErrorPath([
|
|
848
849
|
"variables",
|
|
@@ -875,10 +876,10 @@ const validators = {
|
|
|
875
876
|
};
|
|
876
877
|
const getModuleType = (moduleInfo) => {
|
|
877
878
|
var _a, _b;
|
|
878
|
-
if ((_a = moduleInfo.code) === null || _a ===
|
|
879
|
+
if ((_a = moduleInfo.code) === null || _a === undefined ? undefined : _a.includes("defineComponent")) {
|
|
879
880
|
return COMPONENT;
|
|
880
881
|
}
|
|
881
|
-
else if ((_b = moduleInfo.code) === null || _b ===
|
|
882
|
+
else if ((_b = moduleInfo.code) === null || _b === undefined ? undefined : _b.includes("defineEditor")) {
|
|
882
883
|
return EDITOR;
|
|
883
884
|
}
|
|
884
885
|
else {
|
|
@@ -941,7 +942,7 @@ const styledComponentsEntrypointModifier = {
|
|
|
941
942
|
var _a;
|
|
942
943
|
const packageJsonFilePath = path__namespace.resolve(ctx.client.rootDir, "package.json");
|
|
943
944
|
const packageJson = require(packageJsonFilePath);
|
|
944
|
-
return !!((_a = packageJson.dependencies) === null || _a ===
|
|
945
|
+
return !!((_a = packageJson.dependencies) === null || _a === undefined ? undefined : _a["styled-components"]);
|
|
945
946
|
},
|
|
946
947
|
};
|
|
947
948
|
|
|
@@ -949,7 +950,6 @@ const entrypointModifiers = [
|
|
|
949
950
|
styledComponentsEntrypointModifier,
|
|
950
951
|
];
|
|
951
952
|
|
|
952
|
-
const oraP$1 = import('ora');
|
|
953
953
|
function findFilesWithWrongUsage(directory, pattern, mustEndWith = []) {
|
|
954
954
|
const files = fs__namespace$1.readdirSync(directory);
|
|
955
955
|
const result = [];
|
|
@@ -996,7 +996,6 @@ const regexCubeFunction = /cube\(/;
|
|
|
996
996
|
const regexCubes = /cubes:/;
|
|
997
997
|
const usageValidator = async (directory) => {
|
|
998
998
|
let isValid = true;
|
|
999
|
-
const ora = (await oraP$1).default;
|
|
1000
999
|
const progress = ora("React: function usage validating...").start();
|
|
1001
1000
|
// defineComponent function
|
|
1002
1001
|
const filesWithWrongDefineComponentFunctionUsage = findFilesWithWrongUsage(directory, regexDefineComponentFunction, [".emb.js", ".emb.ts"]);
|
|
@@ -1064,16 +1063,14 @@ const usageValidator = async (directory) => {
|
|
|
1064
1063
|
: process.exit(1);
|
|
1065
1064
|
};
|
|
1066
1065
|
|
|
1067
|
-
const oraP = import('ora');
|
|
1068
1066
|
const EMB_FILE_REGEX = /^(.*)(?<!\.type|\.options)\.emb\.[jt]s$/;
|
|
1069
1067
|
var generate = async (ctx) => {
|
|
1070
1068
|
var _a;
|
|
1071
|
-
const ora = (await oraP).default;
|
|
1072
1069
|
await usageValidator(ctx.client.srcDir);
|
|
1073
1070
|
const filesList = await findFiles(ctx.client.srcDir, EMB_FILE_REGEX);
|
|
1074
1071
|
await prepareEntrypoint(ctx, filesList);
|
|
1075
1072
|
let result;
|
|
1076
|
-
if ((_a = ctx.dev) === null || _a ===
|
|
1073
|
+
if ((_a = ctx.dev) === null || _a === undefined ? undefined : _a.watch) {
|
|
1077
1074
|
result = await runViteWatch(ctx);
|
|
1078
1075
|
}
|
|
1079
1076
|
else {
|
|
@@ -1089,7 +1086,7 @@ async function runViteBuild(ctx, watch = null) {
|
|
|
1089
1086
|
logLevel: !!watch ? "info" : "error",
|
|
1090
1087
|
resolve: {
|
|
1091
1088
|
extensions: [".ts", ".tsx", ".js", ".jsx", ".json"],
|
|
1092
|
-
...(_a = ctx.client.viteConfig) === null || _a ===
|
|
1089
|
+
...(_a = ctx.client.viteConfig) === null || _a === undefined ? undefined : _a.resolve,
|
|
1093
1090
|
},
|
|
1094
1091
|
plugins: [
|
|
1095
1092
|
viteReactPlugin(),
|