@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.js
CHANGED
|
@@ -441,8 +441,8 @@ const editorMetaSchema = zod.z
|
|
|
441
441
|
})
|
|
442
442
|
.strict();
|
|
443
443
|
|
|
444
|
-
const editorMetaValidator = (
|
|
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(),
|
|
@@ -474,6 +476,7 @@ const componentMetaSchema = zod.z
|
|
|
474
476
|
.object({
|
|
475
477
|
name: zod.z.string(),
|
|
476
478
|
type: embeddableTypeSchema,
|
|
479
|
+
array: zod.z.boolean().optional(),
|
|
477
480
|
label: zod.z.string().optional(),
|
|
478
481
|
})
|
|
479
482
|
.array()
|
|
@@ -486,6 +489,7 @@ const componentMetaSchema = zod.z
|
|
|
486
489
|
.object({
|
|
487
490
|
name: zod.z.string(),
|
|
488
491
|
type: embeddableTypeSchema,
|
|
492
|
+
array: zod.z.boolean().optional(),
|
|
489
493
|
defaultValue: zod.z.any().optional(),
|
|
490
494
|
inputs: zod.z.array(zod.z.string()).optional(),
|
|
491
495
|
events: zod.z
|
|
@@ -499,13 +503,35 @@ const componentMetaSchema = zod.z
|
|
|
499
503
|
.array()
|
|
500
504
|
.optional(),
|
|
501
505
|
})
|
|
502
|
-
.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
|
+
});
|
|
503
517
|
|
|
504
|
-
const componentMetaValidator = (
|
|
505
|
-
const result = componentMetaSchema.safeParse(meta);
|
|
518
|
+
const componentMetaValidator = (metaInfo) => {
|
|
519
|
+
const result = componentMetaSchema.safeParse(metaInfo.meta);
|
|
506
520
|
if (!result.success)
|
|
507
521
|
return errorFormatter(result.error.issues);
|
|
508
|
-
|
|
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 [];
|
|
509
535
|
};
|
|
510
536
|
const validateVariables = (meta) => {
|
|
511
537
|
const variables = meta.variables;
|
|
@@ -623,7 +649,7 @@ var validateComponentMetaPlugin = (componentFileRegex) => {
|
|
|
623
649
|
const errors = [];
|
|
624
650
|
for (const metaConfig of metaConfigs) {
|
|
625
651
|
const validator = validators[metaConfig.moduleType];
|
|
626
|
-
const validationResult = validator(metaConfig
|
|
652
|
+
const validationResult = validator(metaConfig);
|
|
627
653
|
if (validationResult && validationResult.length) {
|
|
628
654
|
errors.push(`\nComponent meta is not valid ${metaConfig.moduleId}:\n${validationResult.join("\n")}`);
|
|
629
655
|
}
|