@metamask/snaps-sdk 6.2.0 → 6.3.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/CHANGELOG.md CHANGED
@@ -6,10 +6,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [6.3.0]
10
+ ### Added
11
+ - Add `Selector` component ([#2645](https://github.com/MetaMask/snaps/pull/2645))
12
+ - Add `Icon` component ([#2638](https://github.com/MetaMask/snaps/pull/2638))
13
+ - Add `color` prop to `Text` component ([#2660](https://github.com/MetaMask/snaps/pull/2660))
14
+
15
+ ### Changed
16
+ - `Button` children are now allowed to be `Image` and `Icon` ([#2641](https://github.com/MetaMask/snaps/pull/2641))
17
+
18
+ ## [6.2.1]
19
+ ### Fixed
20
+ - Add structs to `typedUnion` schema ([#2623](https://github.com/MetaMask/snaps/pull/2623))
21
+
9
22
  ## [6.2.0]
10
23
  ### Added
11
24
  - Add `snap_getPreferences` ([#2607](https://github.com/MetaMask/snaps/pull/2607))
12
- - Add `RadioButton` component ([#2592](https://github.com/MetaMask/snaps/pull/2592))
25
+ - Add `RadioGroup` component ([#2592](https://github.com/MetaMask/snaps/pull/2592))
13
26
 
14
27
  ## [6.1.1]
15
28
  ### Changed
@@ -211,7 +224,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
211
224
  ### Added
212
225
  - Initial release of this package.
213
226
 
214
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@6.2.0...HEAD
227
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@6.3.0...HEAD
228
+ [6.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@6.2.1...@metamask/snaps-sdk@6.3.0
229
+ [6.2.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@6.2.0...@metamask/snaps-sdk@6.2.1
215
230
  [6.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@6.1.1...@metamask/snaps-sdk@6.2.0
216
231
  [6.1.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@6.1.0...@metamask/snaps-sdk@6.1.1
217
232
  [6.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@6.0.0...@metamask/snaps-sdk@6.1.0
package/dist/index.js CHANGED
@@ -311,7 +311,7 @@ function enumValue(constant) {
311
311
  function typedUnion(structs) {
312
312
  return new import_superstruct.Struct({
313
313
  type: "union",
314
- schema: null,
314
+ schema: structs,
315
315
  *entries(value, context) {
316
316
  if (!(0, import_utils2.isPlainObject)(value) || !(0, import_utils2.hasProperty)(value, "type")) {
317
317
  return;
@@ -846,6 +846,187 @@ var NotificationType = /* @__PURE__ */ ((NotificationType2) => {
846
846
  var import_superstruct19 = require("@metamask/superstruct");
847
847
  var import_utils8 = require("@metamask/utils");
848
848
 
849
+ // src/jsx/component.ts
850
+ function removeUndefinedProps(props) {
851
+ return Object.fromEntries(
852
+ Object.entries(props).filter(([, value]) => value !== void 0)
853
+ );
854
+ }
855
+ function createSnapComponent(type) {
856
+ return (props) => {
857
+ const { key = null, ...rest } = props;
858
+ return {
859
+ type,
860
+ props: removeUndefinedProps(rest),
861
+ key
862
+ };
863
+ };
864
+ }
865
+
866
+ // src/jsx/components/Icon.ts
867
+ var IconName = /* @__PURE__ */ ((IconName2) => {
868
+ IconName2["AddSquare"] = "add-square";
869
+ IconName2["Add"] = "add";
870
+ IconName2["Arrow2Down"] = "arrow-2-down";
871
+ IconName2["Arrow2Left"] = "arrow-2-left";
872
+ IconName2["Arrow2Right"] = "arrow-2-right";
873
+ IconName2["Arrow2Up"] = "arrow-2-up";
874
+ IconName2["Arrow2UpRight"] = "arrow-2-up-right";
875
+ IconName2["ArrowDoubleLeft"] = "arrow-double-left";
876
+ IconName2["ArrowDoubleRight"] = "arrow-double-right";
877
+ IconName2["ArrowDown"] = "arrow-down";
878
+ IconName2["ArrowLeft"] = "arrow-left";
879
+ IconName2["ArrowRight"] = "arrow-right";
880
+ IconName2["ArrowUp"] = "arrow-up";
881
+ IconName2["BankToken"] = "bank-token";
882
+ IconName2["Bank"] = "bank";
883
+ IconName2["Book"] = "book";
884
+ IconName2["Bookmark"] = "bookmark";
885
+ IconName2["Bridge"] = "bridge";
886
+ IconName2["Calculator"] = "calculator";
887
+ IconName2["CardPos"] = "card-pos";
888
+ IconName2["CardToken"] = "card-token";
889
+ IconName2["Card"] = "card";
890
+ IconName2["Category"] = "category";
891
+ IconName2["Chart"] = "chart";
892
+ IconName2["CheckBold"] = "check-bold";
893
+ IconName2["Check"] = "check";
894
+ IconName2["Clock"] = "clock";
895
+ IconName2["Close"] = "close";
896
+ IconName2["CodeCircle"] = "code-circle";
897
+ IconName2["Coin"] = "coin";
898
+ IconName2["Confirmation"] = "confirmation";
899
+ IconName2["Connect"] = "connect";
900
+ IconName2["CopySuccess"] = "copy-success";
901
+ IconName2["Copy"] = "copy";
902
+ IconName2["Customize"] = "customize";
903
+ IconName2["Danger"] = "danger";
904
+ IconName2["Dark"] = "dark";
905
+ IconName2["Data"] = "data";
906
+ IconName2["Diagram"] = "diagram";
907
+ IconName2["DocumentCode"] = "document-code";
908
+ IconName2["DragDrop"] = "drag-drop";
909
+ IconName2["DraggingAnimation"] = "dragging-animation";
910
+ IconName2["PinningAnimation"] = "pinning-animation";
911
+ IconName2["Edit"] = "edit";
912
+ IconName2["Eraser"] = "eraser";
913
+ IconName2["Ethereum"] = "ethereum";
914
+ IconName2["Expand"] = "expand";
915
+ IconName2["Explore"] = "explore";
916
+ IconName2["Export"] = "export";
917
+ IconName2["EyeSlash"] = "eye-slash";
918
+ IconName2["Eye"] = "eye";
919
+ IconName2["Filter"] = "filter";
920
+ IconName2["Flag"] = "flag";
921
+ IconName2["FlashSlash"] = "flash-slash";
922
+ IconName2["Flash"] = "flash";
923
+ IconName2["FullCircle"] = "full-circle";
924
+ IconName2["Gas"] = "gas";
925
+ IconName2["GlobalSearch"] = "global-search";
926
+ IconName2["Global"] = "global";
927
+ IconName2["Graph"] = "graph";
928
+ IconName2["Hardware"] = "hardware";
929
+ IconName2["Heart"] = "heart";
930
+ IconName2["Hierarchy"] = "hierarchy";
931
+ IconName2["Home"] = "home";
932
+ IconName2["Import"] = "import";
933
+ IconName2["Info"] = "info";
934
+ IconName2["Key"] = "key";
935
+ IconName2["Light"] = "light";
936
+ IconName2["Link"] = "link";
937
+ IconName2["Loading"] = "loading";
938
+ IconName2["LockCircle"] = "lock-circle";
939
+ IconName2["LockSlash"] = "lock-slash";
940
+ IconName2["Lock"] = "lock";
941
+ IconName2["Login"] = "login";
942
+ IconName2["Logout"] = "logout";
943
+ IconName2["Menu"] = "menu";
944
+ IconName2["MessageQuestion"] = "message-question";
945
+ IconName2["Messages"] = "messages";
946
+ IconName2["MinusBold"] = "minus-bold";
947
+ IconName2["MinusSquare"] = "minus-square";
948
+ IconName2["Minus"] = "minus";
949
+ IconName2["Mobile"] = "mobile";
950
+ IconName2["Money"] = "money";
951
+ IconName2["Monitor"] = "monitor";
952
+ IconName2["MoreHorizontal"] = "more-horizontal";
953
+ IconName2["MoreVertical"] = "more-vertical";
954
+ IconName2["NotificationCircle"] = "notification-circle";
955
+ IconName2["Notification"] = "notification";
956
+ IconName2["PasswordCheck"] = "password-check";
957
+ IconName2["People"] = "people";
958
+ IconName2["Pin"] = "pin";
959
+ IconName2["ProgrammingArrows"] = "programming-arrows";
960
+ IconName2["Custody"] = "custody";
961
+ IconName2["Question"] = "question";
962
+ IconName2["Received"] = "received";
963
+ IconName2["Refresh"] = "refresh";
964
+ IconName2["Save"] = "save";
965
+ IconName2["ScanBarcode"] = "scan-barcode";
966
+ IconName2["ScanFocus"] = "scan-focus";
967
+ IconName2["Scan"] = "scan";
968
+ IconName2["Scroll"] = "scroll";
969
+ IconName2["Search"] = "search";
970
+ IconName2["SecurityCard"] = "security-card";
971
+ IconName2["SecurityCross"] = "security-cross";
972
+ IconName2["SecurityKey"] = "security-key";
973
+ IconName2["SecuritySearch"] = "security-search";
974
+ IconName2["SecuritySlash"] = "security-slash";
975
+ IconName2["SecurityTick"] = "security-tick";
976
+ IconName2["SecurityTime"] = "security-time";
977
+ IconName2["SecurityUser"] = "security-user";
978
+ IconName2["Security"] = "security";
979
+ IconName2["Send1"] = "send-1";
980
+ IconName2["Send2"] = "send-2";
981
+ IconName2["Setting"] = "setting";
982
+ IconName2["Slash"] = "slash";
983
+ IconName2["SnapsMobile"] = "snaps-mobile";
984
+ IconName2["SnapsPlus"] = "snaps-plus";
985
+ IconName2["Snaps"] = "snaps";
986
+ IconName2["Speedometer"] = "speedometer";
987
+ IconName2["Star"] = "star";
988
+ IconName2["Stake"] = "stake";
989
+ IconName2["Student"] = "student";
990
+ IconName2["SwapHorizontal"] = "swap-horizontal";
991
+ IconName2["SwapVertical"] = "swap-vertical";
992
+ IconName2["Tag"] = "tag";
993
+ IconName2["Tilde"] = "tilde";
994
+ IconName2["Timer"] = "timer";
995
+ IconName2["Trash"] = "trash";
996
+ IconName2["TrendDown"] = "trend-down";
997
+ IconName2["TrendUp"] = "trend-up";
998
+ IconName2["UserCircleAdd"] = "user-circle-add";
999
+ IconName2["UserCircleLink"] = "user-circle-link";
1000
+ IconName2["UserCircleRemove"] = "user-circle-remove";
1001
+ IconName2["UserCircle"] = "user-circle";
1002
+ IconName2["User"] = "user";
1003
+ IconName2["WalletCard"] = "wallet-card";
1004
+ IconName2["WalletMoney"] = "wallet-money";
1005
+ IconName2["Wallet"] = "wallet";
1006
+ IconName2["Warning"] = "warning";
1007
+ IconName2["Twitter"] = "twitter";
1008
+ IconName2["QrCode"] = "qr-code";
1009
+ IconName2["UserCheck"] = "user-check";
1010
+ IconName2["Unpin"] = "unpin";
1011
+ IconName2["Ban"] = "ban";
1012
+ IconName2["Bold"] = "bold";
1013
+ IconName2["CircleX"] = "circle-x";
1014
+ IconName2["Download"] = "download";
1015
+ IconName2["FileIcon"] = "file";
1016
+ IconName2["Flask"] = "flask";
1017
+ IconName2["Plug"] = "plug";
1018
+ IconName2["Share"] = "share";
1019
+ IconName2["Square"] = "square";
1020
+ IconName2["Tint"] = "tint";
1021
+ IconName2["Upload"] = "upload";
1022
+ IconName2["Usb"] = "usb";
1023
+ IconName2["Wifi"] = "wifi";
1024
+ IconName2["PlusMinus"] = "plus-minus";
1025
+ return IconName2;
1026
+ })(IconName || {});
1027
+ var TYPE = "Icon";
1028
+ var Icon = createSnapComponent(TYPE);
1029
+
849
1030
  // src/jsx/validation.ts
850
1031
  var import_superstruct18 = require("@metamask/superstruct");
851
1032
  var import_utils7 = require("@metamask/utils");
@@ -875,8 +1056,22 @@ function element(name, props = {}) {
875
1056
  key: (0, import_superstruct18.nullable)(KeyStruct)
876
1057
  });
877
1058
  }
1059
+ var ImageStruct2 = element("Image", {
1060
+ src: svg(),
1061
+ alt: (0, import_superstruct18.optional)((0, import_superstruct18.string)())
1062
+ });
1063
+ var IconNameStruct = nullUnion(
1064
+ Object.values(IconName).map((name) => literal(name))
1065
+ );
1066
+ var IconStruct = element("Icon", {
1067
+ name: IconNameStruct,
1068
+ color: (0, import_superstruct18.optional)(
1069
+ nullUnion([literal("default"), literal("primary"), literal("muted")])
1070
+ ),
1071
+ size: (0, import_superstruct18.optional)(nullUnion([literal("md"), literal("inherit")]))
1072
+ });
878
1073
  var ButtonStruct2 = element("Button", {
879
- children: StringElementStruct,
1074
+ children: children([StringElementStruct, ImageStruct2, IconStruct]),
880
1075
  name: (0, import_superstruct18.optional)((0, import_superstruct18.string)()),
881
1076
  type: (0, import_superstruct18.optional)(nullUnion([literal("button"), literal("submit")])),
882
1077
  variant: (0, import_superstruct18.optional)(nullUnion([literal("primary"), literal("destructive")])),
@@ -898,13 +1093,33 @@ var InputStruct2 = element("Input", {
898
1093
  });
899
1094
  var OptionStruct = element("Option", {
900
1095
  value: (0, import_superstruct18.string)(),
901
- children: (0, import_superstruct18.string)()
1096
+ children: nullUnion([(0, import_superstruct18.string)()])
902
1097
  });
903
1098
  var DropdownStruct = element("Dropdown", {
904
1099
  name: (0, import_superstruct18.string)(),
905
1100
  value: (0, import_superstruct18.optional)((0, import_superstruct18.string)()),
906
1101
  children: children([OptionStruct])
907
1102
  });
1103
+ var CardStruct = element("Card", {
1104
+ image: (0, import_superstruct18.optional)((0, import_superstruct18.string)()),
1105
+ title: (0, import_superstruct18.string)(),
1106
+ description: (0, import_superstruct18.optional)((0, import_superstruct18.string)()),
1107
+ value: (0, import_superstruct18.string)(),
1108
+ extra: (0, import_superstruct18.optional)((0, import_superstruct18.string)())
1109
+ });
1110
+ var SelectorOptionStruct = element(
1111
+ "SelectorOption",
1112
+ {
1113
+ value: (0, import_superstruct18.string)(),
1114
+ children: CardStruct
1115
+ }
1116
+ );
1117
+ var SelectorStruct = element("Selector", {
1118
+ name: (0, import_superstruct18.string)(),
1119
+ title: (0, import_superstruct18.string)(),
1120
+ value: (0, import_superstruct18.optional)((0, import_superstruct18.string)()),
1121
+ children: children([SelectorOptionStruct])
1122
+ });
908
1123
  var RadioStruct = element("Radio", {
909
1124
  value: (0, import_superstruct18.string)(),
910
1125
  children: (0, import_superstruct18.string)()
@@ -931,7 +1146,8 @@ var FIELD_CHILDREN_ARRAY = [
931
1146
  DropdownStruct,
932
1147
  RadioGroupStruct,
933
1148
  FileInputStruct,
934
- CheckboxStruct
1149
+ CheckboxStruct,
1150
+ SelectorStruct
935
1151
  ];
936
1152
  var FieldChildUnionStruct = nullUnion([
937
1153
  ...FIELD_CHILDREN_ARRAY,
@@ -1018,28 +1234,33 @@ var ValueStruct = element("Value", {
1018
1234
  value: (0, import_superstruct18.string)(),
1019
1235
  extra: (0, import_superstruct18.string)()
1020
1236
  });
1021
- var CardStruct = element("Card", {
1022
- image: (0, import_superstruct18.optional)((0, import_superstruct18.string)()),
1023
- title: (0, import_superstruct18.string)(),
1024
- description: (0, import_superstruct18.optional)((0, import_superstruct18.string)()),
1025
- value: (0, import_superstruct18.string)(),
1026
- extra: (0, import_superstruct18.optional)((0, import_superstruct18.string)())
1027
- });
1028
1237
  var HeadingStruct2 = element("Heading", {
1029
1238
  children: StringElementStruct
1030
1239
  });
1031
- var ImageStruct2 = element("Image", {
1032
- src: svg(),
1033
- alt: (0, import_superstruct18.optional)((0, import_superstruct18.string)())
1034
- });
1035
1240
  var LinkStruct = element("Link", {
1036
1241
  href: (0, import_superstruct18.string)(),
1037
1242
  children: children([FormattingStruct, (0, import_superstruct18.string)()])
1038
1243
  });
1039
1244
  var TextStruct2 = element("Text", {
1040
- children: children([(0, import_superstruct18.string)(), BoldStruct, ItalicStruct, LinkStruct]),
1245
+ children: children([
1246
+ (0, import_superstruct18.string)(),
1247
+ BoldStruct,
1248
+ ItalicStruct,
1249
+ LinkStruct,
1250
+ IconStruct
1251
+ ]),
1041
1252
  alignment: (0, import_superstruct18.optional)(
1042
1253
  nullUnion([literal("start"), literal("center"), literal("end")])
1254
+ ),
1255
+ color: (0, import_superstruct18.optional)(
1256
+ nullUnion([
1257
+ literal("default"),
1258
+ literal("alternative"),
1259
+ literal("muted"),
1260
+ literal("error"),
1261
+ literal("success"),
1262
+ literal("warning")
1263
+ ])
1043
1264
  )
1044
1265
  });
1045
1266
  var TooltipChildStruct = nullUnion([
@@ -1048,6 +1269,7 @@ var TooltipChildStruct = nullUnion([
1048
1269
  ItalicStruct,
1049
1270
  LinkStruct,
1050
1271
  ImageStruct2,
1272
+ IconStruct,
1051
1273
  (0, import_superstruct18.boolean)()
1052
1274
  ]);
1053
1275
  var TooltipContentStruct = nullUnion([
@@ -1055,6 +1277,7 @@ var TooltipContentStruct = nullUnion([
1055
1277
  BoldStruct,
1056
1278
  ItalicStruct,
1057
1279
  LinkStruct,
1280
+ IconStruct,
1058
1281
  (0, import_superstruct18.string)()
1059
1282
  ]);
1060
1283
  var TooltipStruct = element("Tooltip", {
@@ -1091,7 +1314,9 @@ var BoxChildStruct = typedUnion([
1091
1314
  TextStruct2,
1092
1315
  TooltipStruct,
1093
1316
  CheckboxStruct,
1094
- CardStruct
1317
+ CardStruct,
1318
+ IconStruct,
1319
+ SelectorStruct
1095
1320
  ]);
1096
1321
  var RootJSXElementStruct = nullUnion([
1097
1322
  BoxChildStruct,
@@ -1124,7 +1349,10 @@ var JSXElementStruct = typedUnion([
1124
1349
  CheckboxStruct,
1125
1350
  FooterStruct,
1126
1351
  ContainerStruct,
1127
- CardStruct
1352
+ CardStruct,
1353
+ IconStruct,
1354
+ SelectorStruct,
1355
+ SelectorOptionStruct
1128
1356
  ]);
1129
1357
 
1130
1358
  // src/types/interface.ts