@webstudio-is/sdk 0.195.0 → 0.197.0

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
@@ -470,6 +470,311 @@ var WebstudioFragment = z12.object({
470
470
  styles: z12.array(StyleDecl)
471
471
  });
472
472
 
473
+ // src/schema/prop-meta.ts
474
+ import { z as z13 } from "zod";
475
+ var common = {
476
+ label: z13.string().optional(),
477
+ description: z13.string().optional(),
478
+ required: z13.boolean()
479
+ };
480
+ var Number = z13.object({
481
+ ...common,
482
+ control: z13.literal("number"),
483
+ type: z13.literal("number"),
484
+ defaultValue: z13.number().optional()
485
+ });
486
+ var Range = z13.object({
487
+ ...common,
488
+ control: z13.literal("range"),
489
+ type: z13.literal("number"),
490
+ defaultValue: z13.number().optional()
491
+ });
492
+ var Text = z13.object({
493
+ ...common,
494
+ control: z13.literal("text"),
495
+ type: z13.literal("string"),
496
+ defaultValue: z13.string().optional(),
497
+ /**
498
+ * The number of rows in <textarea>. If set to 0 an <input> will be used instead.
499
+ * In line with Storybook team's plan: https://github.com/storybookjs/storybook/issues/21100
500
+ */
501
+ rows: z13.number().optional()
502
+ });
503
+ var Code = z13.object({
504
+ ...common,
505
+ control: z13.literal("code"),
506
+ type: z13.literal("string"),
507
+ language: z13.union([z13.literal("html"), z13.literal("markdown")]),
508
+ defaultValue: z13.string().optional()
509
+ });
510
+ var CodeText = z13.object({
511
+ ...common,
512
+ control: z13.literal("codetext"),
513
+ type: z13.literal("string"),
514
+ defaultValue: z13.string().optional()
515
+ });
516
+ var Color = z13.object({
517
+ ...common,
518
+ control: z13.literal("color"),
519
+ type: z13.literal("string"),
520
+ defaultValue: z13.string().optional()
521
+ });
522
+ var Boolean = z13.object({
523
+ ...common,
524
+ control: z13.literal("boolean"),
525
+ type: z13.literal("boolean"),
526
+ defaultValue: z13.boolean().optional()
527
+ });
528
+ var Radio = z13.object({
529
+ ...common,
530
+ control: z13.literal("radio"),
531
+ type: z13.literal("string"),
532
+ defaultValue: z13.string().optional(),
533
+ options: z13.array(z13.string())
534
+ });
535
+ var InlineRadio = z13.object({
536
+ ...common,
537
+ control: z13.literal("inline-radio"),
538
+ type: z13.literal("string"),
539
+ defaultValue: z13.string().optional(),
540
+ options: z13.array(z13.string())
541
+ });
542
+ var Select = z13.object({
543
+ ...common,
544
+ control: z13.literal("select"),
545
+ type: z13.literal("string"),
546
+ defaultValue: z13.string().optional(),
547
+ options: z13.array(z13.string())
548
+ });
549
+ var Check = z13.object({
550
+ ...common,
551
+ control: z13.literal("check"),
552
+ type: z13.literal("string[]"),
553
+ defaultValue: z13.array(z13.string()).optional(),
554
+ options: z13.array(z13.string())
555
+ });
556
+ var InlineCheck = z13.object({
557
+ ...common,
558
+ control: z13.literal("inline-check"),
559
+ type: z13.literal("string[]"),
560
+ defaultValue: z13.array(z13.string()).optional(),
561
+ options: z13.array(z13.string())
562
+ });
563
+ var MultiSelect = z13.object({
564
+ ...common,
565
+ control: z13.literal("multi-select"),
566
+ type: z13.literal("string[]"),
567
+ defaultValue: z13.array(z13.string()).optional(),
568
+ options: z13.array(z13.string())
569
+ });
570
+ var File = z13.object({
571
+ ...common,
572
+ control: z13.literal("file"),
573
+ type: z13.literal("string"),
574
+ defaultValue: z13.string().optional(),
575
+ /** https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/file#accept */
576
+ accept: z13.string().optional()
577
+ });
578
+ var Url = z13.object({
579
+ ...common,
580
+ control: z13.literal("url"),
581
+ type: z13.literal("string"),
582
+ defaultValue: z13.string().optional()
583
+ });
584
+ var Json = z13.object({
585
+ ...common,
586
+ control: z13.literal("json"),
587
+ type: z13.literal("json"),
588
+ defaultValue: z13.unknown().optional()
589
+ });
590
+ var Date = z13.object({
591
+ ...common,
592
+ control: z13.literal("date"),
593
+ // @todo not sure what type should be here
594
+ // (we don't support Date yet, added for completeness)
595
+ type: z13.literal("string"),
596
+ defaultValue: z13.string().optional()
597
+ });
598
+ var Action = z13.object({
599
+ ...common,
600
+ control: z13.literal("action"),
601
+ type: z13.literal("action"),
602
+ defaultValue: z13.undefined().optional()
603
+ });
604
+ var TextContent = z13.object({
605
+ ...common,
606
+ control: z13.literal("textContent"),
607
+ type: z13.literal("string"),
608
+ defaultValue: z13.string().optional()
609
+ });
610
+ var PropMeta = z13.union([
611
+ Number,
612
+ Range,
613
+ Text,
614
+ Code,
615
+ CodeText,
616
+ Color,
617
+ Boolean,
618
+ Radio,
619
+ InlineRadio,
620
+ Select,
621
+ MultiSelect,
622
+ Check,
623
+ InlineCheck,
624
+ File,
625
+ Url,
626
+ Json,
627
+ Date,
628
+ Action,
629
+ TextContent
630
+ ]);
631
+
632
+ // src/schema/embed-template.ts
633
+ import { z as z14 } from "zod";
634
+ import { StyleValue as StyleValue2 } from "@webstudio-is/css-engine";
635
+ var EmbedTemplateText = z14.object({
636
+ type: z14.literal("text"),
637
+ value: z14.string(),
638
+ placeholder: z14.boolean().optional()
639
+ });
640
+ var EmbedTemplateExpression = z14.object({
641
+ type: z14.literal("expression"),
642
+ value: z14.string()
643
+ });
644
+ var EmbedTemplateVariable = z14.object({
645
+ alias: z14.optional(z14.string()),
646
+ initialValue: z14.unknown()
647
+ });
648
+ var EmbedTemplateProp = z14.union([
649
+ z14.object({
650
+ type: z14.literal("number"),
651
+ name: z14.string(),
652
+ value: z14.number()
653
+ }),
654
+ z14.object({
655
+ type: z14.literal("string"),
656
+ name: z14.string(),
657
+ value: z14.string()
658
+ }),
659
+ z14.object({
660
+ type: z14.literal("boolean"),
661
+ name: z14.string(),
662
+ value: z14.boolean()
663
+ }),
664
+ z14.object({
665
+ type: z14.literal("string[]"),
666
+ name: z14.string(),
667
+ value: z14.array(z14.string())
668
+ }),
669
+ z14.object({
670
+ type: z14.literal("json"),
671
+ name: z14.string(),
672
+ value: z14.unknown()
673
+ }),
674
+ z14.object({
675
+ type: z14.literal("expression"),
676
+ name: z14.string(),
677
+ code: z14.string()
678
+ }),
679
+ z14.object({
680
+ type: z14.literal("parameter"),
681
+ name: z14.string(),
682
+ variableName: z14.string(),
683
+ variableAlias: z14.optional(z14.string())
684
+ }),
685
+ z14.object({
686
+ type: z14.literal("action"),
687
+ name: z14.string(),
688
+ value: z14.array(
689
+ z14.object({
690
+ type: z14.literal("execute"),
691
+ args: z14.optional(z14.array(z14.string())),
692
+ code: z14.string()
693
+ })
694
+ )
695
+ })
696
+ ]);
697
+ var EmbedTemplateStyleDeclRaw = z14.object({
698
+ // State selector, e.g. :hover
699
+ state: z14.optional(z14.string()),
700
+ property: z14.string(),
701
+ value: StyleValue2
702
+ });
703
+ var EmbedTemplateStyleDecl = EmbedTemplateStyleDeclRaw;
704
+ var EmbedTemplateInstance = z14.lazy(
705
+ () => z14.object({
706
+ type: z14.literal("instance"),
707
+ component: z14.string(),
708
+ label: z14.optional(z14.string()),
709
+ variables: z14.optional(z14.record(z14.string(), EmbedTemplateVariable)),
710
+ props: z14.optional(z14.array(EmbedTemplateProp)),
711
+ styles: z14.optional(z14.array(EmbedTemplateStyleDecl)),
712
+ children: WsEmbedTemplate
713
+ })
714
+ );
715
+ var WsEmbedTemplate = z14.lazy(
716
+ () => z14.array(
717
+ z14.union([EmbedTemplateInstance, EmbedTemplateText, EmbedTemplateExpression])
718
+ )
719
+ );
720
+
721
+ // src/schema/component-meta.ts
722
+ import { z as z15 } from "zod";
723
+ var WsComponentPropsMeta = z15.object({
724
+ props: z15.record(PropMeta),
725
+ // Props that will be always visible in properties panel.
726
+ initialProps: z15.array(z15.string()).optional()
727
+ });
728
+ var componentCategories = [
729
+ "general",
730
+ "typography",
731
+ "media",
732
+ "data",
733
+ "forms",
734
+ "localization",
735
+ "radix",
736
+ "xml",
737
+ "hidden",
738
+ "internal"
739
+ ];
740
+ var stateCategories = ["states", "component-states"];
741
+ var ComponentState = z15.object({
742
+ category: z15.enum(stateCategories).optional(),
743
+ selector: z15.string(),
744
+ label: z15.string()
745
+ });
746
+ var defaultStates = [
747
+ { selector: ":hover", label: "Hover" },
748
+ { selector: ":active", label: "Active" },
749
+ { selector: ":focus", label: "Focus" },
750
+ { selector: ":focus-visible", label: "Focus Visible" },
751
+ { selector: ":focus-within", label: "Focus Within" }
752
+ ];
753
+ var WsComponentMeta = z15.object({
754
+ category: z15.enum(componentCategories).optional(),
755
+ // container - can accept other components with dnd or be edited as text
756
+ // control - usually form controls like inputs, without children
757
+ // embed - images, videos or other embeddable components, without children
758
+ // rich-text-child - formatted text fragment, not listed in components list
759
+ type: z15.enum(["container", "control", "embed", "rich-text-child"]),
760
+ constraints: Matchers.optional(),
761
+ // when this field is specified component receives
762
+ // prop with index of same components withiin specified ancestor
763
+ // important to automatically enumerate collections without
764
+ // naming every item manually
765
+ indexWithinAncestor: z15.optional(z15.string()),
766
+ stylable: z15.optional(z15.boolean()),
767
+ label: z15.optional(z15.string()),
768
+ description: z15.string().optional(),
769
+ icon: z15.string(),
770
+ presetStyle: z15.optional(
771
+ z15.record(z15.string(), z15.array(EmbedTemplateStyleDecl))
772
+ ),
773
+ states: z15.optional(z15.array(ComponentState)),
774
+ template: z15.optional(WsEmbedTemplate),
775
+ order: z15.number().optional()
776
+ });
777
+
473
778
  // src/instances-utils.ts
474
779
  var ROOT_INSTANCE_ID = ":root";
475
780
  var traverseInstances = (instances, instanceId, callback) => {
@@ -1229,10 +1534,15 @@ export {
1229
1534
  Breakpoint,
1230
1535
  Breakpoints,
1231
1536
  CompilerSettings,
1537
+ ComponentState,
1232
1538
  DataSource,
1233
1539
  DataSourceVariableValue,
1234
1540
  DataSources,
1235
1541
  Deployment,
1542
+ EmbedTemplateInstance,
1543
+ EmbedTemplateProp,
1544
+ EmbedTemplateStyleDecl,
1545
+ EmbedTemplateVariable,
1236
1546
  ExpressionChild,
1237
1547
  Folder,
1238
1548
  FolderName,
@@ -1255,6 +1565,7 @@ export {
1255
1565
  Pages,
1256
1566
  ProjectNewRedirectPath,
1257
1567
  Prop,
1568
+ PropMeta,
1258
1569
  Props,
1259
1570
  ROOT_FOLDER_ID,
1260
1571
  ROOT_INSTANCE_ID,
@@ -1270,8 +1581,12 @@ export {
1270
1581
  Templates,
1271
1582
  TextChild,
1272
1583
  WebstudioFragment,
1584
+ WsComponentMeta,
1585
+ WsEmbedTemplate,
1586
+ componentCategories,
1273
1587
  createScope,
1274
1588
  decodeDataSourceVariable,
1589
+ defaultStates,
1275
1590
  documentTypes,
1276
1591
  encodeDataSourceVariable,
1277
1592
  executeExpression,
@@ -1296,5 +1611,6 @@ export {
1296
1611
  parseComponentName,
1297
1612
  parseObjectExpression,
1298
1613
  replaceFormActionsWithResources,
1614
+ stateCategories,
1299
1615
  transpileExpression
1300
1616
  };
@@ -10,6 +10,9 @@ export * from "./schema/style-source-selections";
10
10
  export * from "./schema/styles";
11
11
  export * from "./schema/deployment";
12
12
  export * from "./schema/webstudio";
13
+ export * from "./schema/prop-meta";
14
+ export * from "./schema/embed-template";
15
+ export * from "./schema/component-meta";
13
16
  export * from "./instances-utils";
14
17
  export * from "./page-utils";
15
18
  export * from "./scope";