@embeddable.com/sdk-react 2.2.11 → 2.2.13

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.js CHANGED
@@ -441,8 +441,8 @@ const editorMetaSchema = zod.z
441
441
  })
442
442
  .strict();
443
443
 
444
- const editorMetaValidator = (meta) => {
445
- const result = editorMetaSchema.safeParse(meta);
444
+ const editorMetaValidator = (metaInfo) => {
445
+ const result = editorMetaSchema.safeParse(metaInfo.meta);
446
446
  if (result.success)
447
447
  return [];
448
448
  return errorFormatter(result.error.issues);
@@ -453,6 +453,8 @@ const componentMetaSchema = zod.z
453
453
  name: zod.z.string(),
454
454
  label: zod.z.string(),
455
455
  classNames: zod.z.string().array().min(1).optional(),
456
+ defaultWidth: zod.z.number().optional(),
457
+ defaultHeight: zod.z.number().optional(),
456
458
  inputs: zod.z
457
459
  .object({
458
460
  name: zod.z.string(),
@@ -501,13 +503,35 @@ const componentMetaSchema = zod.z
501
503
  .array()
502
504
  .optional(),
503
505
  })
504
- .strict();
506
+ .strict()
507
+ .superRefine(({ defaultWidth, defaultHeight }, refinementContext) => {
508
+ const widthAndHeight = [defaultHeight, defaultWidth].filter(Boolean);
509
+ if (widthAndHeight.length === 1) {
510
+ return refinementContext.addIssue({
511
+ code: zod.z.ZodIssueCode.custom,
512
+ message: "both defaultWidth and defaultHeight must be set",
513
+ path: ["defaultWidth | defaultHeight"],
514
+ });
515
+ }
516
+ });
505
517
 
506
- const componentMetaValidator = (meta) => {
507
- const result = componentMetaSchema.safeParse(meta);
518
+ const componentMetaValidator = (metaInfo) => {
519
+ const result = componentMetaSchema.safeParse(metaInfo.meta);
508
520
  if (!result.success)
509
521
  return errorFormatter(result.error.issues);
510
- return validateVariables(meta);
522
+ let errors = validateModuleName(metaInfo);
523
+ errors = errors.concat(validateVariables(metaInfo.meta));
524
+ return errors;
525
+ };
526
+ const validateModuleName = (metaInfo) => {
527
+ const basename = path__namespace.basename(metaInfo.moduleId);
528
+ const fileName = basename.split(".");
529
+ if (!basename.includes(metaInfo.meta.name)) {
530
+ return [
531
+ `meta.name: The name of the .emb.* file and [meta.name]'s value must match. In this case, [meta.name] must be ${fileName[0]}`,
532
+ ];
533
+ }
534
+ return [];
511
535
  };
512
536
  const validateVariables = (meta) => {
513
537
  const variables = meta.variables;
@@ -576,10 +600,13 @@ const validateVariableEvents = (meta) => {
576
600
  errors.push(`${path}: property "${event.property}" is not defined`);
577
601
  return;
578
602
  }
603
+ const path = formatErrorPath(["variables", idx]);
579
604
  if (definedProperty.type !== variableConfig.type) {
580
- const path = formatErrorPath(["variables", idx]);
581
605
  errors.push(`${path}: the type of the variable "${variableConfig.name}" and the type of the property "${event.property}" do not match`);
582
606
  }
607
+ if (Boolean(definedProperty.array) !== Boolean(variableConfig.array)) {
608
+ errors.push(`${path}: the array of the variable "${variableConfig.name}" and the array of the property "${event.property}" do not match`);
609
+ }
583
610
  });
584
611
  }
585
612
  });
@@ -625,7 +652,7 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
625
652
  const errors = [];
626
653
  for (const metaConfig of metaConfigs) {
627
654
  const validator = validators[metaConfig.moduleType];
628
- const validationResult = validator(metaConfig.meta);
655
+ const validationResult = validator(metaConfig);
629
656
  if (validationResult && validationResult.length) {
630
657
  errors.push(`\nComponent meta is not valid ${metaConfig.moduleId}:\n${validationResult.join("\n")}`);
631
658
  }