@embeddable.com/sdk-react 2.2.11 → 2.2.12
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 +31 -7
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +31 -7
- package/lib/index.js.map +1 -1
- package/lib/validate/componentMetaValidator.d.ts +2 -1
- package/lib/validate/editorMetaValidator.d.ts +3 -1
- package/lib/validate/schema/componentMetaSchema.d.ts +139 -1
- package/lib/validate/validateComponentMetaPlugin.d.ts +7 -0
- package/package.json +1 -1
package/lib/index.esm.js
CHANGED
|
@@ -418,8 +418,8 @@ const editorMetaSchema = z
|
|
|
418
418
|
})
|
|
419
419
|
.strict();
|
|
420
420
|
|
|
421
|
-
const editorMetaValidator = (
|
|
422
|
-
const result = editorMetaSchema.safeParse(meta);
|
|
421
|
+
const editorMetaValidator = (metaInfo) => {
|
|
422
|
+
const result = editorMetaSchema.safeParse(metaInfo.meta);
|
|
423
423
|
if (result.success)
|
|
424
424
|
return [];
|
|
425
425
|
return errorFormatter(result.error.issues);
|
|
@@ -430,6 +430,8 @@ const componentMetaSchema = z
|
|
|
430
430
|
name: z.string(),
|
|
431
431
|
label: z.string(),
|
|
432
432
|
classNames: z.string().array().min(1).optional(),
|
|
433
|
+
defaultWidth: z.number().optional(),
|
|
434
|
+
defaultHeight: z.number().optional(),
|
|
433
435
|
inputs: z
|
|
434
436
|
.object({
|
|
435
437
|
name: z.string(),
|
|
@@ -478,13 +480,35 @@ const componentMetaSchema = z
|
|
|
478
480
|
.array()
|
|
479
481
|
.optional(),
|
|
480
482
|
})
|
|
481
|
-
.strict()
|
|
483
|
+
.strict()
|
|
484
|
+
.superRefine(({ defaultWidth, defaultHeight }, refinementContext) => {
|
|
485
|
+
const widthAndHeight = [defaultHeight, defaultWidth].filter(Boolean);
|
|
486
|
+
if (widthAndHeight.length === 1) {
|
|
487
|
+
return refinementContext.addIssue({
|
|
488
|
+
code: z.ZodIssueCode.custom,
|
|
489
|
+
message: "both defaultWidth and defaultHeight must be set",
|
|
490
|
+
path: ["defaultWidth | defaultHeight"],
|
|
491
|
+
});
|
|
492
|
+
}
|
|
493
|
+
});
|
|
482
494
|
|
|
483
|
-
const componentMetaValidator = (
|
|
484
|
-
const result = componentMetaSchema.safeParse(meta);
|
|
495
|
+
const componentMetaValidator = (metaInfo) => {
|
|
496
|
+
const result = componentMetaSchema.safeParse(metaInfo.meta);
|
|
485
497
|
if (!result.success)
|
|
486
498
|
return errorFormatter(result.error.issues);
|
|
487
|
-
|
|
499
|
+
let errors = validateModuleName(metaInfo);
|
|
500
|
+
errors = errors.concat(validateVariables(metaInfo.meta));
|
|
501
|
+
return errors;
|
|
502
|
+
};
|
|
503
|
+
const validateModuleName = (metaInfo) => {
|
|
504
|
+
const basename = path.basename(metaInfo.moduleId);
|
|
505
|
+
const fileName = basename.split(".");
|
|
506
|
+
if (!basename.includes(metaInfo.meta.name)) {
|
|
507
|
+
return [
|
|
508
|
+
`meta.name: The name of the .emb.* file and [meta.name]'s value must match. In this case, [meta.name] must be ${fileName[0]}`,
|
|
509
|
+
];
|
|
510
|
+
}
|
|
511
|
+
return [];
|
|
488
512
|
};
|
|
489
513
|
const validateVariables = (meta) => {
|
|
490
514
|
const variables = meta.variables;
|
|
@@ -602,7 +626,7 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
|
|
|
602
626
|
const errors = [];
|
|
603
627
|
for (const metaConfig of metaConfigs) {
|
|
604
628
|
const validator = validators[metaConfig.moduleType];
|
|
605
|
-
const validationResult = validator(metaConfig
|
|
629
|
+
const validationResult = validator(metaConfig);
|
|
606
630
|
if (validationResult && validationResult.length) {
|
|
607
631
|
errors.push(`\nComponent meta is not valid ${metaConfig.moduleId}:\n${validationResult.join("\n")}`);
|
|
608
632
|
}
|