@embeddable.com/sdk-react 2.2.10 → 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 +33 -7
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +33 -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 +151 -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(),
|
|
@@ -451,6 +453,7 @@ const componentMetaSchema = z
|
|
|
451
453
|
.object({
|
|
452
454
|
name: z.string(),
|
|
453
455
|
type: embeddableTypeSchema,
|
|
456
|
+
array: z.boolean().optional(),
|
|
454
457
|
label: z.string().optional(),
|
|
455
458
|
})
|
|
456
459
|
.array()
|
|
@@ -463,6 +466,7 @@ const componentMetaSchema = z
|
|
|
463
466
|
.object({
|
|
464
467
|
name: z.string(),
|
|
465
468
|
type: embeddableTypeSchema,
|
|
469
|
+
array: z.boolean().optional(),
|
|
466
470
|
defaultValue: z.any().optional(),
|
|
467
471
|
inputs: z.array(z.string()).optional(),
|
|
468
472
|
events: z
|
|
@@ -476,13 +480,35 @@ const componentMetaSchema = z
|
|
|
476
480
|
.array()
|
|
477
481
|
.optional(),
|
|
478
482
|
})
|
|
479
|
-
.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
|
+
});
|
|
480
494
|
|
|
481
|
-
const componentMetaValidator = (
|
|
482
|
-
const result = componentMetaSchema.safeParse(meta);
|
|
495
|
+
const componentMetaValidator = (metaInfo) => {
|
|
496
|
+
const result = componentMetaSchema.safeParse(metaInfo.meta);
|
|
483
497
|
if (!result.success)
|
|
484
498
|
return errorFormatter(result.error.issues);
|
|
485
|
-
|
|
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 [];
|
|
486
512
|
};
|
|
487
513
|
const validateVariables = (meta) => {
|
|
488
514
|
const variables = meta.variables;
|
|
@@ -600,7 +626,7 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
|
|
|
600
626
|
const errors = [];
|
|
601
627
|
for (const metaConfig of metaConfigs) {
|
|
602
628
|
const validator = validators[metaConfig.moduleType];
|
|
603
|
-
const validationResult = validator(metaConfig
|
|
629
|
+
const validationResult = validator(metaConfig);
|
|
604
630
|
if (validationResult && validationResult.length) {
|
|
605
631
|
errors.push(`\nComponent meta is not valid ${metaConfig.moduleId}:\n${validationResult.join("\n")}`);
|
|
606
632
|
}
|