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