@embeddable.com/sdk-react 3.11.2-next.1 → 3.11.2-next.3

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
@@ -501,18 +501,61 @@ const DATASET = "dataset";
501
501
  const MEASURE = "measure";
502
502
  const DIMENSION = "dimension";
503
503
  const DIMENSION_OR_MEASURE = "dimensionOrMeasure";
504
- const ALL_NATIVE_TYPES = [
504
+ const DEFAULT_NATIVE_TYPES = [
505
505
  STRING,
506
506
  NUMBER,
507
507
  BOOLEAN,
508
508
  TIME,
509
509
  TIME_RANGE,
510
510
  GRANULARITY,
511
+ ];
512
+ const ALL_NATIVE_TYPES = [
513
+ ...DEFAULT_NATIVE_TYPES,
511
514
  DATASET,
512
515
  MEASURE,
513
516
  DIMENSION,
514
517
  DIMENSION_OR_MEASURE,
515
518
  ];
519
+ const MEASURE_TYPE_STRING = "string";
520
+ const MEASURE_TYPE_TIME = "time";
521
+ const MEASURE_TYPE_BOOLEAN = "boolean";
522
+ const MEASURE_TYPE_NUMBER = "number";
523
+ const MEASURE_TYPE_COUNT = "count";
524
+ const MEASURE_TYPE_COUNT_DISTINCT = "count_distinct";
525
+ const MEASURE_TYPE_COUNT_DISTINCT_APPROX = "count_distinct_approx";
526
+ const MEASURE_TYPE_SUM = "sum";
527
+ const MEASURE_TYPE_AVG = "avg";
528
+ const MEASURE_TYPE_MIN = "min";
529
+ const MEASURE_TYPE_MAX = "max";
530
+ const MEASURE_TYPES = [
531
+ MEASURE_TYPE_STRING,
532
+ MEASURE_TYPE_TIME,
533
+ MEASURE_TYPE_BOOLEAN,
534
+ MEASURE_TYPE_NUMBER,
535
+ MEASURE_TYPE_COUNT,
536
+ MEASURE_TYPE_COUNT_DISTINCT,
537
+ MEASURE_TYPE_COUNT_DISTINCT_APPROX,
538
+ MEASURE_TYPE_SUM,
539
+ MEASURE_TYPE_AVG,
540
+ MEASURE_TYPE_MIN,
541
+ MEASURE_TYPE_MAX,
542
+ ];
543
+ const DIMENSION_TYPE_STRING = "string";
544
+ const DIMENSION_TYPE_NUMBER = "number";
545
+ const DIMENSION_TYPE_BOOLEAN = "boolean";
546
+ const DIMENSION_TYPE_GEO = "geo";
547
+ const DIMENSION_TYPE_TIME = "time";
548
+ const DIMENSION_TYPES = [
549
+ DIMENSION_TYPE_STRING,
550
+ DIMENSION_TYPE_NUMBER,
551
+ DIMENSION_TYPE_BOOLEAN,
552
+ DIMENSION_TYPE_GEO,
553
+ DIMENSION_TYPE_TIME,
554
+ ];
555
+ [
556
+ ...DIMENSION_TYPES,
557
+ ...MEASURE_TYPES,
558
+ ];
516
559
 
517
560
  createBuiltInType("string", {
518
561
  transform: (value) => value,
@@ -608,6 +651,30 @@ const editorMetaValidator = (metaInfo) => {
608
651
  return errorFormatter(result.error.issues);
609
652
  };
610
653
 
654
+ const embeddableInputTypeSchema = z
655
+ .object({
656
+ typeConfig: z.object({
657
+ label: z.string(),
658
+ toString: z.function(),
659
+ }),
660
+ })
661
+ .or(z.enum(DEFAULT_NATIVE_TYPES));
662
+
663
+ const embeddableInputSupportedTypesSchema = z
664
+ .union([z.enum(DIMENSION_TYPES), z.enum(MEASURE_TYPES)])
665
+ .array()
666
+ .optional();
667
+
668
+ const uniqueNameRefinement = (items, refinementContext, message) => {
669
+ const names = items.map((item) => item.name);
670
+ if (new Set(names).size !== names.length) {
671
+ const duplicateNames = names.filter((name, index) => names.indexOf(name) !== index);
672
+ refinementContext.addIssue({
673
+ code: z.ZodIssueCode.custom,
674
+ message: `${message} Duplicate names: ${duplicateNames.join(", ")}`,
675
+ });
676
+ }
677
+ };
611
678
  const componentMetaSchema = z
612
679
  .object({
613
680
  name: z.string(),
@@ -627,19 +694,24 @@ const componentMetaSchema = z
627
694
  array: z.boolean().optional(),
628
695
  category: z.string().optional(),
629
696
  required: z.boolean().optional(),
697
+ inputs: z
698
+ .object({
699
+ name: z.string(),
700
+ label: z.string(),
701
+ description: z.string().optional(),
702
+ defaultValue: z.any().optional(),
703
+ config: z.record(z.string(), z.any()).optional(),
704
+ type: embeddableInputTypeSchema,
705
+ required: z.boolean().optional(),
706
+ supportedTypes: embeddableInputSupportedTypesSchema,
707
+ })
708
+ .array()
709
+ .superRefine((inputs, ctx) => uniqueNameRefinement(inputs, ctx, "SubInput names must be unique."))
710
+ .optional(),
630
711
  })
631
712
  .strict()
632
713
  .array()
633
- .superRefine((inputs, refinementContext) => {
634
- const inputNames = inputs.map((input) => input.name);
635
- if (new Set(inputNames).size !== inputNames.length) {
636
- const duplicateInputNames = inputNames.filter((name, index) => inputNames.indexOf(name) !== index);
637
- return refinementContext.addIssue({
638
- code: z.ZodIssueCode.custom,
639
- message: `Input names must be unique. Duplicate names: ${duplicateInputNames.join(", ")}`,
640
- });
641
- }
642
- })
714
+ .superRefine((inputs, ctx) => uniqueNameRefinement(inputs, ctx, "Input names must be unique."))
643
715
  .optional(),
644
716
  events: z
645
717
  .object({
@@ -680,7 +752,7 @@ const componentMetaSchema = z
680
752
  .superRefine(({ defaultWidth, defaultHeight }, refinementContext) => {
681
753
  const widthAndHeight = [defaultHeight, defaultWidth].filter(Boolean);
682
754
  if (widthAndHeight.length === 1) {
683
- return refinementContext.addIssue({
755
+ refinementContext.addIssue({
684
756
  code: z.ZodIssueCode.custom,
685
757
  message: "both defaultWidth and defaultHeight must be set",
686
758
  path: ["defaultWidth | defaultHeight"],