@embeddable.com/sdk-react 3.10.7-next.4 → 3.10.7

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.esm.js CHANGED
@@ -3,7 +3,6 @@ import { resolve, join } from 'node:path';
3
3
  import * as fs$2 from 'fs/promises';
4
4
  import * as path from 'path';
5
5
  import * as vite from 'vite';
6
- import ora from 'ora';
7
6
  import viteReactPlugin from '@vitejs/plugin-react';
8
7
  import * as fs from 'node:fs/promises';
9
8
  import { readdir, lstat, rm } from 'node:fs/promises';
@@ -289,7 +288,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
289
288
  var errorUtil;
290
289
  (function (errorUtil) {
291
290
  errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
292
- errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === undefined ? undefined : message.message;
291
+ errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
293
292
  })(errorUtil || (errorUtil = {}));
294
293
  var ZodFirstPartyTypeKind;
295
294
  (function (ZodFirstPartyTypeKind) {
@@ -385,7 +384,7 @@ var extractComponentsConfigPlugin = ({ globalKey, outputDir, fileName, component
385
384
  moduleParsed: async (moduleInfo) => {
386
385
  var _a;
387
386
  if (componentFileRegex.test(moduleInfo.id) &&
388
- ((_a = moduleInfo.code) === null || _a === undefined ? undefined : _a.includes(searchEntry))) {
387
+ ((_a = moduleInfo.code) === null || _a === void 0 ? void 0 : _a.includes(searchEntry))) {
389
388
  try {
390
389
  const meta = await loadComponentMeta(moduleInfo.id);
391
390
  const configJSON = JSON.stringify(meta, (_key, value) => typeof value === "object" &&
@@ -458,7 +457,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
458
457
 
459
458
  var DEFAULT_LOCALE = "en-US";
460
459
  var createBuiltInType = function (name, typeConfig) {
461
- if (typeConfig === undefined) { typeConfig = {}; }
460
+ if (typeConfig === void 0) { typeConfig = {}; }
462
461
  return ({
463
462
  __embeddableType: "built-in",
464
463
  toString: function () { return name; },
@@ -504,7 +503,7 @@ createBuiltInType("number", {
504
503
  var _a;
505
504
  return Array.isArray(value)
506
505
  ? "[".concat(value.join(","), "]")
507
- : ((_a = value === null || value === undefined ? undefined : value.toLocaleString(DEFAULT_LOCALE)) !== null && _a !== undefined ? _a : "");
506
+ : (_a = value === null || value === void 0 ? void 0 : value.toLocaleString(DEFAULT_LOCALE)) !== null && _a !== void 0 ? _a : "";
508
507
  },
509
508
  });
510
509
  createBuiltInType("boolean", {
@@ -513,19 +512,19 @@ createBuiltInType("boolean", {
513
512
  });
514
513
  createBuiltInType("time", {
515
514
  transform: function (value) {
516
- var date = (value === null || value === undefined ? undefined : value.date) ? new Date(value.date) : undefined;
515
+ var date = (value === null || value === void 0 ? void 0 : value.date) ? new Date(value.date) : undefined;
517
516
  var isValid = date && date.toString() !== "Invalid Date";
518
517
  return {
519
518
  date: isValid ? date : undefined,
520
- relativeTimeString: value === null || value === undefined ? undefined : value.relativeTimeString,
519
+ relativeTimeString: value === null || value === void 0 ? void 0 : value.relativeTimeString,
521
520
  };
522
521
  },
523
522
  optionLabel: function (value) {
524
523
  var _a, _b;
525
524
  if (!value)
526
525
  return "";
527
- if (value === null || value === undefined ? undefined : value.date) {
528
- return ((_b = (_a = value.date) === null || _a === undefined ? undefined : _a.toLocaleDateString(DEFAULT_LOCALE)) !== null && _b !== undefined ? _b : value.date.toLocaleString());
526
+ if (value === null || value === void 0 ? void 0 : value.date) {
527
+ return ((_b = (_a = value.date) === null || _a === void 0 ? void 0 : _a.toLocaleDateString(DEFAULT_LOCALE)) !== null && _b !== void 0 ? _b : value.date.toLocaleString());
529
528
  }
530
529
  return value.relativeTimeString;
531
530
  },
@@ -535,23 +534,23 @@ createBuiltInType("timeRange", {
535
534
  // Return undefined instead of a null populated object
536
535
  if (!value)
537
536
  return undefined;
538
- var _a = [value === null || value === undefined ? undefined : value.from, value === null || value === undefined ? undefined : value.to], from = _a[0], to = _a[1];
537
+ 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];
539
538
  var fromDate = new Date(from);
540
539
  var toDate = new Date(to);
541
540
  return {
542
541
  from: fromDate.toString() !== "Invalid Date" ? fromDate : undefined,
543
542
  to: toDate.toString() !== "Invalid Date" ? toDate : undefined,
544
- relativeTimeString: value === null || value === undefined ? undefined : value.relativeTimeString,
543
+ relativeTimeString: value === null || value === void 0 ? void 0 : value.relativeTimeString,
545
544
  };
546
545
  },
547
546
  optionLabel: function (value) {
548
547
  var _a, _b, _c, _d, _e, _f;
549
548
  if (!value)
550
549
  return "";
551
- if ((value === null || value === undefined ? undefined : value.from) && (value === null || value === undefined ? undefined : value.to)) {
552
- 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());
550
+ if ((value === null || value === void 0 ? void 0 : value.from) && (value === null || value === void 0 ? void 0 : value.to)) {
551
+ return "".concat((_b = (_a = value.from) === null || _a === void 0 ? void 0 : _a.toLocaleDateString(DEFAULT_LOCALE)) !== null && _b !== void 0 ? _b : (_c = value.from) === null || _c === void 0 ? void 0 : _c.toLocaleString(), ",").concat((_e = (_d = value.to) === null || _d === void 0 ? void 0 : _d.toLocaleDateString(DEFAULT_LOCALE)) !== null && _e !== void 0 ? _e : (_f = value.to) === null || _f === void 0 ? void 0 : _f.toLocaleString());
553
552
  }
554
- return value === null || value === undefined ? undefined : value.relativeTimeString;
553
+ return value === null || value === void 0 ? void 0 : value.relativeTimeString;
555
554
  },
556
555
  });
557
556
  createBuiltInType("granularity", {
@@ -698,7 +697,7 @@ const validateComponentProps = (metaInfo) => {
698
697
  var _a;
699
698
  const componentConfig = path.node.declaration
700
699
  .arguments[2];
701
- 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"; });
700
+ const propsNode = (_a = componentConfig.properties) === null || _a === void 0 ? void 0 : _a.find((x) => { var _a; return ((_a = x.key) === null || _a === void 0 ? void 0 : _a.name) === "props"; });
702
701
  // There is no props defined
703
702
  if (!propsNode)
704
703
  return;
@@ -727,7 +726,7 @@ const validateComponentProps = (metaInfo) => {
727
726
  };
728
727
  const validateComponentEvents = (metaInfo) => {
729
728
  var _a, _b;
730
- const definedEvents = (_b = (_a = metaInfo.meta.events) === null || _a === undefined ? undefined : _a.map((e) => e.name)) !== null && _b !== undefined ? _b : [];
729
+ const definedEvents = (_b = (_a = metaInfo.meta.events) === null || _a === void 0 ? void 0 : _a.map((e) => e.name)) !== null && _b !== void 0 ? _b : [];
731
730
  let implementedEvents = [];
732
731
  const errors = [];
733
732
  parseAndTraverse(metaInfo.moduleInfo.code, {
@@ -735,9 +734,9 @@ const validateComponentEvents = (metaInfo) => {
735
734
  var _a, _b, _c, _d;
736
735
  const componentConfig = path.node.declaration
737
736
  .arguments[2];
738
- 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"; });
737
+ const eventsNode = (_a = componentConfig.properties) === null || _a === void 0 ? void 0 : _a.find((p) => { var _a; return ((_a = p.key) === null || _a === void 0 ? void 0 : _a.name) === "events"; });
739
738
  implementedEvents =
740
- (_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 : [];
739
+ (_d = (_c = (_b = eventsNode === null || eventsNode === void 0 ? void 0 : eventsNode.value) === null || _b === void 0 ? void 0 : _b.properties) === null || _c === void 0 ? void 0 : _c.map((p) => p.key.name)) !== null && _d !== void 0 ? _d : [];
741
740
  },
742
741
  });
743
742
  const definedEventsSet = new Set(definedEvents);
@@ -784,7 +783,7 @@ const validateVariableInputs = (meta) => {
784
783
  const inputs = variableConfig.inputs;
785
784
  if (inputs) {
786
785
  inputs.forEach((input, inputIdx) => {
787
- const definedInput = definedInputs === null || definedInputs === undefined ? undefined : definedInputs.find((d) => d.name === input);
786
+ const definedInput = definedInputs === null || definedInputs === void 0 ? void 0 : definedInputs.find((d) => d.name === input);
788
787
  if (!definedInput) {
789
788
  const path = formatErrorPath(["variables", idx, "inputs", inputIdx]);
790
789
  errors.push(`${path}: input "${input}" is not defined`);
@@ -804,7 +803,7 @@ const validateVariableEvents = (meta) => {
804
803
  const events = variableConfig.events;
805
804
  if (events) {
806
805
  events.forEach((event, eventIdx) => {
807
- const definedEvent = definedEvents === null || definedEvents === undefined ? undefined : definedEvents.find((d) => d.name === event.name);
806
+ const definedEvent = definedEvents === null || definedEvents === void 0 ? void 0 : definedEvents.find((d) => d.name === event.name);
808
807
  if (!definedEvent) {
809
808
  const path = formatErrorPath([
810
809
  "variables",
@@ -817,7 +816,7 @@ const validateVariableEvents = (meta) => {
817
816
  return;
818
817
  }
819
818
  const definedProperties = definedEvent.properties;
820
- const definedProperty = definedProperties === null || definedProperties === undefined ? undefined : definedProperties.find((p) => p.name === event.property);
819
+ const definedProperty = definedProperties === null || definedProperties === void 0 ? void 0 : definedProperties.find((p) => p.name === event.property);
821
820
  if (!definedProperty) {
822
821
  const path = formatErrorPath([
823
822
  "variables",
@@ -850,10 +849,10 @@ const validators = {
850
849
  };
851
850
  const getModuleType = (moduleInfo) => {
852
851
  var _a, _b;
853
- if ((_a = moduleInfo.code) === null || _a === undefined ? undefined : _a.includes("defineComponent")) {
852
+ if ((_a = moduleInfo.code) === null || _a === void 0 ? void 0 : _a.includes("defineComponent")) {
854
853
  return COMPONENT;
855
854
  }
856
- else if ((_b = moduleInfo.code) === null || _b === undefined ? undefined : _b.includes("defineEditor")) {
855
+ else if ((_b = moduleInfo.code) === null || _b === void 0 ? void 0 : _b.includes("defineEditor")) {
857
856
  return EDITOR;
858
857
  }
859
858
  else {
@@ -912,11 +911,11 @@ const styledComponentsEntrypointModifier = {
912
911
  getImports() {
913
912
  return "import {StyleSheetManager} from 'styled-components'";
914
913
  },
915
- async needToModify(ctx) {
914
+ needToModify(ctx) {
916
915
  var _a;
917
916
  const packageJsonFilePath = path.resolve(ctx.client.rootDir, "package.json");
918
- const packageJson = await import(packageJsonFilePath);
919
- return !!((_a = packageJson.dependencies) === null || _a === undefined ? undefined : _a["styled-components"]);
917
+ const packageJson = require(packageJsonFilePath);
918
+ return !!((_a = packageJson.dependencies) === null || _a === void 0 ? void 0 : _a["styled-components"]);
920
919
  },
921
920
  };
922
921
 
@@ -924,6 +923,7 @@ const entrypointModifiers = [
924
923
  styledComponentsEntrypointModifier,
925
924
  ];
926
925
 
926
+ const oraP$1 = import('ora');
927
927
  function findFilesWithWrongUsage(directory, pattern, mustEndWith = []) {
928
928
  const files = fs$1.readdirSync(directory);
929
929
  const result = [];
@@ -970,6 +970,7 @@ const regexCubeFunction = /cube\(/;
970
970
  const regexCubes = /cubes:/;
971
971
  const usageValidator = async (directory) => {
972
972
  let isValid = true;
973
+ const ora = (await oraP$1).default;
973
974
  const progress = ora("React: function usage validating...").start();
974
975
  // defineComponent function
975
976
  const filesWithWrongDefineComponentFunctionUsage = findFilesWithWrongUsage(directory, regexDefineComponentFunction, [".emb.js", ".emb.ts"]);
@@ -1037,14 +1038,16 @@ const usageValidator = async (directory) => {
1037
1038
  : process.exit(1);
1038
1039
  };
1039
1040
 
1041
+ const oraP = import('ora');
1040
1042
  const EMB_FILE_REGEX = /^(.*)(?<!\.type|\.options)\.emb\.[jt]s$/;
1041
1043
  var generate = async (ctx) => {
1042
1044
  var _a;
1045
+ const ora = (await oraP).default;
1043
1046
  await usageValidator(ctx.client.srcDir);
1044
1047
  const filesList = await findFiles(ctx.client.srcDir, EMB_FILE_REGEX);
1045
1048
  await prepareEntrypoint(ctx, filesList);
1046
1049
  let result;
1047
- if ((_a = ctx.dev) === null || _a === undefined ? undefined : _a.watch) {
1050
+ if ((_a = ctx.dev) === null || _a === void 0 ? void 0 : _a.watch) {
1048
1051
  result = await runViteWatch(ctx);
1049
1052
  }
1050
1053
  else {
@@ -1060,7 +1063,7 @@ async function runViteBuild(ctx, watch = null) {
1060
1063
  logLevel: !!watch ? "info" : "error",
1061
1064
  resolve: {
1062
1065
  extensions: [".ts", ".tsx", ".js", ".jsx", ".json"],
1063
- ...(_a = ctx.client.viteConfig) === null || _a === undefined ? undefined : _a.resolve,
1066
+ ...(_a = ctx.client.viteConfig) === null || _a === void 0 ? void 0 : _a.resolve,
1064
1067
  },
1065
1068
  plugins: [
1066
1069
  viteReactPlugin(),
@@ -1151,7 +1154,7 @@ async function prepareEntrypoint(ctx, filesList) {
1151
1154
  let additionalContentBegin = [];
1152
1155
  let additionalContentEnd = [];
1153
1156
  for (const entrypointModifier of entrypointModifiers) {
1154
- if (await entrypointModifier.needToModify(ctx)) {
1157
+ if (entrypointModifier.needToModify(ctx)) {
1155
1158
  additionalContentImport.push(entrypointModifier.getImports(ctx));
1156
1159
  additionalContentBegin.push(entrypointModifier.getContentBegin(ctx));
1157
1160
  additionalContentEnd.unshift(entrypointModifier.getContentEnd(ctx));
@@ -1168,7 +1171,6 @@ async function prepareEntrypoint(ctx, filesList) {
1168
1171
  }
1169
1172
 
1170
1173
  var build = async (ctx) => {
1171
- const __dirname = import.meta.dirname;
1172
1174
  createContext(path$1.resolve(__dirname, ".."), ctx);
1173
1175
  return generate(ctx);
1174
1176
  };