@metamask/snaps-sdk 1.1.0 → 1.2.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.
Files changed (42) hide show
  1. package/CHANGELOG.md +10 -1
  2. package/dist/cjs/index.js +9 -0
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/internals/index.js +1 -0
  5. package/dist/cjs/internals/index.js.map +1 -1
  6. package/dist/cjs/internals/structs.js +43 -0
  7. package/dist/cjs/internals/structs.js.map +1 -0
  8. package/dist/cjs/ui/components/address.js +30 -0
  9. package/dist/cjs/ui/components/address.js.map +1 -0
  10. package/dist/cjs/ui/components/index.js +2 -0
  11. package/dist/cjs/ui/components/index.js.map +1 -1
  12. package/dist/cjs/ui/components/panel.js +5 -1
  13. package/dist/cjs/ui/components/panel.js.map +1 -1
  14. package/dist/cjs/ui/components/row.js +57 -0
  15. package/dist/cjs/ui/components/row.js.map +1 -0
  16. package/dist/cjs/ui/nodes.js +2 -0
  17. package/dist/cjs/ui/nodes.js.map +1 -1
  18. package/dist/esm/index.js +1 -1
  19. package/dist/esm/index.js.map +1 -1
  20. package/dist/esm/internals/index.js +1 -0
  21. package/dist/esm/internals/index.js.map +1 -1
  22. package/dist/esm/internals/structs.js +59 -0
  23. package/dist/esm/internals/structs.js.map +1 -0
  24. package/dist/esm/ui/components/address.js +22 -0
  25. package/dist/esm/ui/components/address.js.map +1 -0
  26. package/dist/esm/ui/components/index.js +2 -0
  27. package/dist/esm/ui/components/index.js.map +1 -1
  28. package/dist/esm/ui/components/panel.js +5 -1
  29. package/dist/esm/ui/components/panel.js.map +1 -1
  30. package/dist/esm/ui/components/row.js +50 -0
  31. package/dist/esm/ui/components/row.js.map +1 -0
  32. package/dist/esm/ui/nodes.js +2 -0
  33. package/dist/esm/ui/nodes.js.map +1 -1
  34. package/dist/types/index.d.ts +1 -1
  35. package/dist/types/internals/index.d.ts +1 -0
  36. package/dist/types/internals/structs.d.ts +50 -0
  37. package/dist/types/ui/components/address.d.ts +34 -0
  38. package/dist/types/ui/components/index.d.ts +2 -0
  39. package/dist/types/ui/components/panel.d.ts +90 -0
  40. package/dist/types/ui/components/row.d.ts +104 -0
  41. package/dist/types/ui/nodes.d.ts +3 -1
  42. package/package.json +5 -4
package/CHANGELOG.md CHANGED
@@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.2.0]
10
+ ### Added
11
+ - Add `row` and `address` component ([#1968](https://github.com/MetaMask/snaps/pull/1968))
12
+ - Add `enumValue`, `literal` and `union` from `snaps-utils` ([#1968](https://github.com/MetaMask/snaps/pull/1968))
13
+
14
+ ### Changed
15
+ - Bump several MetaMask dependencies ([#1964](https://github.com/MetaMask/snaps/pull/1964))
16
+
9
17
  ## [1.1.0]
10
18
  ### Added
11
19
  - Add Snap error wrappers of JSON-RPC errors ([#1924](https://github.com/MetaMask/snaps/pull/1924))
@@ -14,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
14
22
  ### Added
15
23
  - Initial release of this package.
16
24
 
17
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@1.1.0...HEAD
25
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@1.2.0...HEAD
26
+ [1.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@1.1.0...@metamask/snaps-sdk@1.2.0
18
27
  [1.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@1.0.0...@metamask/snaps-sdk@1.1.0
19
28
  [1.0.0]: https://github.com/MetaMask/snaps/releases/tag/@metamask/snaps-sdk@1.0.0
package/dist/cjs/index.js CHANGED
@@ -24,6 +24,15 @@ _export(exports, {
24
24
  },
25
25
  SNAP_ERROR_MESSAGE: function() {
26
26
  return _internals.SNAP_ERROR_MESSAGE;
27
+ },
28
+ literal: function() {
29
+ return _internals.literal;
30
+ },
31
+ union: function() {
32
+ return _internals.union;
33
+ },
34
+ enumValue: function() {
35
+ return _internals.enumValue;
27
36
  }
28
37
  });
29
38
  const _internals = require("./internals");
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["// Only internals that are used by other Snaps packages should be exported here.\nexport type { EnumToUnion } from './internals';\nexport {\n getErrorData,\n getErrorMessage,\n getErrorStack,\n SNAP_ERROR_CODE,\n SNAP_ERROR_MESSAGE,\n} from './internals';\n\n// Re-exported from `@metamask/utils` for convenience.\nexport type {\n Json,\n JsonRpcError,\n JsonRpcRequest,\n JsonRpcParams,\n} from '@metamask/utils';\n\nexport * from './errors';\nexport * from './types';\nexport * from './ui';\n"],"names":["getErrorData","getErrorMessage","getErrorStack","SNAP_ERROR_CODE","SNAP_ERROR_MESSAGE"],"mappings":"AAAA,gFAAgF;;;;;;;;;;;;IAG9EA,YAAY;eAAZA,uBAAY;;IACZC,eAAe;eAAfA,0BAAe;;IACfC,aAAa;eAAbA,wBAAa;;IACbC,eAAe;eAAfA,0BAAe;;IACfC,kBAAkB;eAAlBA,6BAAkB;;;2BACb;qBAUO;qBACA;qBACA"}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["// Only internals that are used by other Snaps packages should be exported here.\nexport type { EnumToUnion } from './internals';\nexport {\n getErrorData,\n getErrorMessage,\n getErrorStack,\n SNAP_ERROR_CODE,\n SNAP_ERROR_MESSAGE,\n literal,\n union,\n enumValue,\n} from './internals';\n\n// Re-exported from `@metamask/utils` for convenience.\nexport type {\n Json,\n JsonRpcError,\n JsonRpcRequest,\n JsonRpcParams,\n} from '@metamask/utils';\n\nexport * from './errors';\nexport * from './types';\nexport * from './ui';\n"],"names":["getErrorData","getErrorMessage","getErrorStack","SNAP_ERROR_CODE","SNAP_ERROR_MESSAGE","literal","union","enumValue"],"mappings":"AAAA,gFAAgF;;;;;;;;;;;;IAG9EA,YAAY;eAAZA,uBAAY;;IACZC,eAAe;eAAfA,0BAAe;;IACfC,aAAa;eAAbA,wBAAa;;IACbC,eAAe;eAAfA,0BAAe;;IACfC,kBAAkB;eAAlBA,6BAAkB;;IAClBC,OAAO;eAAPA,kBAAO;;IACPC,KAAK;eAALA,gBAAK;;IACLC,SAAS;eAATA,oBAAS;;;2BACJ;qBAUO;qBACA;qBACA"}
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  _export_star(require("./error-wrappers"), exports);
6
6
  _export_star(require("./errors"), exports);
7
7
  _export_star(require("./helpers"), exports);
8
+ _export_star(require("./structs"), exports);
8
9
  function _export_star(from, to) {
9
10
  Object.keys(from).forEach(function(k) {
10
11
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/internals/index.ts"],"sourcesContent":["export * from './error-wrappers';\nexport * from './errors';\nexport * from './helpers';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA"}
1
+ {"version":3,"sources":["../../../src/internals/index.ts"],"sourcesContent":["export * from './error-wrappers';\nexport * from './errors';\nexport * from './helpers';\nexport * from './structs';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA"}
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ literal: function() {
13
+ return literal;
14
+ },
15
+ union: function() {
16
+ return union;
17
+ },
18
+ enumValue: function() {
19
+ return enumValue;
20
+ }
21
+ });
22
+ const _superstruct = require("superstruct");
23
+ function literal(value) {
24
+ return (0, _superstruct.define)(JSON.stringify(value), (0, _superstruct.literal)(value).validator);
25
+ }
26
+ function union([head, ...tail]) {
27
+ const struct = (0, _superstruct.union)([
28
+ head,
29
+ ...tail
30
+ ]);
31
+ return new _superstruct.Struct({
32
+ ...struct,
33
+ schema: [
34
+ head,
35
+ ...tail
36
+ ]
37
+ });
38
+ }
39
+ function enumValue(constant) {
40
+ return literal(constant);
41
+ }
42
+
43
+ //# sourceMappingURL=structs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/internals/structs.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport {\n Struct,\n define,\n literal as superstructLiteral,\n union as superstructUnion,\n} from 'superstruct';\nimport type { AnyStruct, InferStructTuple } from 'superstruct/dist/utils';\n\nimport type { EnumToUnion } from './helpers';\n\n/**\n * A wrapper of `superstruct`'s `literal` struct that also defines the name of\n * the struct as the literal value.\n *\n * This is useful for improving the error messages returned by `superstruct`.\n * For example, instead of returning an error like:\n *\n * ```\n * Expected the value to satisfy a union of `literal | literal`, but received: \\\"baz\\\"\n * ```\n *\n * This struct will return an error like:\n *\n * ```\n * Expected the value to satisfy a union of `\"foo\" | \"bar\"`, but received: \\\"baz\\\"\n * ```\n *\n * @param value - The literal value.\n * @returns The `superstruct` struct, which validates that the value is equal\n * to the literal value.\n */\nexport function literal<Type extends string | number | boolean>(value: Type) {\n return define<Type>(\n JSON.stringify(value),\n superstructLiteral(value).validator,\n );\n}\n\n/**\n * A wrapper of `superstruct`'s `union` struct that also defines the schema as\n * the union of the schemas of the structs.\n *\n * This is useful for improving the error messages returned by `superstruct`.\n *\n * @param structs - The structs to union.\n * @param structs.\"0\" - The first struct.\n * @param structs.\"1\" - The remaining structs.\n * @returns The `superstruct` struct, which validates that the value satisfies\n * one of the structs.\n */\nexport function union<Head extends AnyStruct, Tail extends AnyStruct[]>([\n head,\n ...tail\n]: [head: Head, ...tail: Tail]): Struct<\n Infer<Head> | InferStructTuple<Tail>[number],\n [head: Head, ...tail: Tail]\n> {\n const struct = superstructUnion([head, ...tail]);\n\n return new Struct({\n ...struct,\n schema: [head, ...tail],\n });\n}\n\n/**\n * Superstruct struct for validating an enum value. This allows using both the\n * enum string values and the enum itself as values.\n *\n * @param constant - The enum to validate against.\n * @returns The superstruct struct.\n */\nexport function enumValue<Type extends string>(\n constant: Type,\n): Struct<EnumToUnion<Type>, null> {\n return literal(constant as EnumToUnion<Type>);\n}\n"],"names":["literal","union","enumValue","value","define","JSON","stringify","superstructLiteral","validator","head","tail","struct","superstructUnion","Struct","schema","constant"],"mappings":";;;;;;;;;;;IAgCgBA,OAAO;eAAPA;;IAmBAC,KAAK;eAALA;;IAsBAC,SAAS;eAATA;;;6BAnET;AA0BA,SAASF,QAAgDG,KAAW;IACzE,OAAOC,IAAAA,mBAAM,EACXC,KAAKC,SAAS,CAACH,QACfI,IAAAA,oBAAkB,EAACJ,OAAOK,SAAS;AAEvC;AAcO,SAASP,MAAwD,CACtEQ,MACA,GAAGC,KACyB;IAI5B,MAAMC,SAASC,IAAAA,kBAAgB,EAAC;QAACH;WAASC;KAAK;IAE/C,OAAO,IAAIG,mBAAM,CAAC;QAChB,GAAGF,MAAM;QACTG,QAAQ;YAACL;eAASC;SAAK;IACzB;AACF;AASO,SAASR,UACda,QAAc;IAEd,OAAOf,QAAQe;AACjB"}
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ AddressStruct: function() {
13
+ return AddressStruct;
14
+ },
15
+ address: function() {
16
+ return address;
17
+ }
18
+ });
19
+ const _superstruct = require("superstruct");
20
+ const _builder = require("../builder");
21
+ const _nodes = require("../nodes");
22
+ const AddressStruct = (0, _superstruct.assign)(_nodes.LiteralStruct, (0, _superstruct.object)({
23
+ type: (0, _superstruct.literal)(_nodes.NodeType.Address),
24
+ value: (0, _superstruct.pattern)((0, _superstruct.string)(), /0x[a-fA-F0-9]{40}/u)
25
+ }));
26
+ const address = (0, _builder.createBuilder)(_nodes.NodeType.Address, AddressStruct, [
27
+ 'value'
28
+ ]);
29
+
30
+ //# sourceMappingURL=address.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/ui/components/address.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport { assign, literal, object, pattern, string } from 'superstruct';\n\nimport { createBuilder } from '../builder';\nimport { LiteralStruct, NodeType } from '../nodes';\n\nexport const AddressStruct = assign(\n LiteralStruct,\n object({\n type: literal(NodeType.Address),\n value: pattern(string(), /0x[a-fA-F0-9]{40}/u),\n }),\n);\n\n/**\n * A address node, that renders an EVM-like address and its icon.\n *\n * @property type - The type of the node. Must be the string `address`.\n * @property value - The address in hexadecimal, including 0x.\n */\nexport type Address = Infer<typeof AddressStruct>;\n\n/**\n * Create an {@link Address} node.\n *\n * @param args - The node arguments. This can either be a string, or an object\n * with the `value` property.\n * @param args.value - The address to be rendered.\n * @returns The address node as an object.\n * @example\n * const node = address({ value: '0x4bbeeb066ed09b7aed07bf39eee0460dfa261520' });\n * const node = address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520');\n */\nexport const address = createBuilder(NodeType.Address, AddressStruct, [\n 'value',\n]);\n"],"names":["AddressStruct","address","assign","LiteralStruct","object","type","literal","NodeType","Address","value","pattern","string","createBuilder"],"mappings":";;;;;;;;;;;IAMaA,aAAa;eAAbA;;IA2BAC,OAAO;eAAPA;;;6BAhC4C;yBAE3B;uBACU;AAEjC,MAAMD,gBAAgBE,IAAAA,mBAAM,EACjCC,oBAAa,EACbC,IAAAA,mBAAM,EAAC;IACLC,MAAMC,IAAAA,oBAAO,EAACC,eAAQ,CAACC,OAAO;IAC9BC,OAAOC,IAAAA,oBAAO,EAACC,IAAAA,mBAAM,KAAI;AAC3B;AAsBK,MAAMV,UAAUW,IAAAA,sBAAa,EAACL,eAAQ,CAACC,OAAO,EAAER,eAAe;IACpE;CACD"}
@@ -25,6 +25,7 @@ _export(exports, {
25
25
  return _panel.PanelStruct;
26
26
  }
27
27
  });
28
+ _export_star(require("./address"), exports);
28
29
  _export_star(require("./copyable"), exports);
29
30
  _export_star(require("./divider"), exports);
30
31
  _export_star(require("./heading"), exports);
@@ -32,6 +33,7 @@ const _image = require("./image");
32
33
  const _panel = require("./panel");
33
34
  _export_star(require("./spinner"), exports);
34
35
  _export_star(require("./text"), exports);
36
+ _export_star(require("./row"), exports);
35
37
  function _export_star(from, to) {
36
38
  Object.keys(from).forEach(function(k) {
37
39
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/ui/components/index.ts"],"sourcesContent":["export * from './copyable';\nexport * from './divider';\nexport * from './heading';\nexport type { Image } from './image';\nexport { image, ImageStruct } from './image';\nexport type { Component, Panel } from './panel';\nexport { ComponentStruct, panel, PanelStruct } from './panel';\nexport * from './spinner';\nexport * from './text';\n"],"names":["image","ImageStruct","ComponentStruct","panel","PanelStruct"],"mappings":";;;;;;;;;;;IAISA,KAAK;eAALA,YAAK;;IAAEC,WAAW;eAAXA,kBAAW;;IAElBC,eAAe;eAAfA,sBAAe;;IAAEC,KAAK;eAALA,YAAK;;IAAEC,WAAW;eAAXA,kBAAW;;;qBAN9B;qBACA;qBACA;uBAEqB;uBAEiB;qBACtC;qBACA"}
1
+ {"version":3,"sources":["../../../../src/ui/components/index.ts"],"sourcesContent":["export * from './address';\nexport * from './copyable';\nexport * from './divider';\nexport * from './heading';\nexport type { Image } from './image';\nexport { image, ImageStruct } from './image';\nexport type { Component, Panel } from './panel';\nexport { ComponentStruct, panel, PanelStruct } from './panel';\nexport * from './spinner';\nexport * from './text';\nexport * from './row';\n"],"names":["image","ImageStruct","ComponentStruct","panel","PanelStruct"],"mappings":";;;;;;;;;;;IAKSA,KAAK;eAALA,YAAK;;IAAEC,WAAW;eAAXA,kBAAW;;IAElBC,eAAe;eAAfA,sBAAe;;IAAEC,KAAK;eAALA,YAAK;;IAAEC,WAAW;eAAXA,kBAAW;;;qBAP9B;qBACA;qBACA;qBACA;uBAEqB;uBAEiB;qBACtC;qBACA;qBACA"}
@@ -25,10 +25,12 @@ _export(exports, {
25
25
  const _superstruct = require("superstruct");
26
26
  const _builder = require("../builder");
27
27
  const _nodes = require("../nodes");
28
+ const _address = require("./address");
28
29
  const _copyable = require("./copyable");
29
30
  const _divider = require("./divider");
30
31
  const _heading = require("./heading");
31
32
  const _image = require("./image");
33
+ const _row = require("./row");
32
34
  const _spinner = require("./spinner");
33
35
  const _text = require("./text");
34
36
  const ParentStruct = (0, _superstruct.assign)(_nodes.NodeStruct, (0, _superstruct.object)({
@@ -49,7 +51,9 @@ const ComponentStruct = (0, _superstruct.union)([
49
51
  _image.ImageStruct,
50
52
  PanelStruct,
51
53
  _spinner.SpinnerStruct,
52
- _text.TextStruct
54
+ _text.TextStruct,
55
+ _row.RowStruct,
56
+ _address.AddressStruct
53
57
  ]);
54
58
 
55
59
  //# sourceMappingURL=panel.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/ui/components/panel.ts"],"sourcesContent":["import type { Infer, Struct } from 'superstruct';\nimport { array, assign, lazy, literal, object, union } from 'superstruct';\n\nimport { createBuilder } from '../builder';\nimport { NodeStruct, NodeType } from '../nodes';\nimport { CopyableStruct } from './copyable';\nimport { DividerStruct } from './divider';\nimport { HeadingStruct } from './heading';\nimport { ImageStruct } from './image';\nimport { SpinnerStruct } from './spinner';\nimport { TextStruct } from './text';\n\n/**\n * @internal\n */\nexport const ParentStruct = assign(\n NodeStruct,\n object({\n // This node references itself indirectly, so we need to use `lazy()`.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n children: array(lazy(() => ComponentStruct)),\n }),\n);\n\n/**\n * A node which supports child nodes. This is used for nodes that render their\n * children, such as {@link Panel}.\n *\n * @property type - The type of the node.\n * @property children - The children of the node\n * @internal\n */\nexport type Parent = Infer<typeof ParentStruct>;\n\n/**\n * @internal\n */\nexport const PanelStruct: Struct<Panel> = assign(\n ParentStruct,\n object({\n type: literal(NodeType.Panel),\n }),\n);\n\n/**\n * A panel node, which renders its children.\n *\n * @property type - The type of the node, must be the string 'text'.\n * @property value - The text content of the node, either as plain text, or as a\n * markdown string.\n */\n// This node references itself indirectly, so it cannot be inferred.\nexport type Panel = {\n type: NodeType.Panel;\n children: Component[];\n};\n\n/**\n * Create a {@link Panel} node.\n *\n * @param args - The node arguments. This can be either an array of children, or\n * an object with a `children` property.\n * @param args.children - The child nodes of the panel. This can be any valid\n * {@link Component}.\n * @returns The panel node as object.\n * @example\n * const node = panel({\n * children: [\n * heading({ text: 'Hello, world!' }),\n * text({ text: 'This is a panel.' }),\n * ],\n * });\n *\n * const node = panel([\n * heading('Hello, world!'),\n * text('This is a panel.'),\n * ]);\n */\nexport const panel = createBuilder(NodeType.Panel, PanelStruct, ['children']);\n\n// This is defined separately from `Component` to avoid circular dependencies.\nexport const ComponentStruct = union([\n CopyableStruct,\n DividerStruct,\n HeadingStruct,\n ImageStruct,\n PanelStruct,\n SpinnerStruct,\n TextStruct,\n]);\n\n/**\n * All supported component types.\n */\nexport type Component = Infer<typeof ComponentStruct>;\n"],"names":["ParentStruct","PanelStruct","panel","ComponentStruct","assign","NodeStruct","object","children","array","lazy","type","literal","NodeType","Panel","createBuilder","union","CopyableStruct","DividerStruct","HeadingStruct","ImageStruct","SpinnerStruct","TextStruct"],"mappings":";;;;;;;;;;;IAeaA,YAAY;eAAZA;;IAsBAC,WAAW;eAAXA;;IAyCAC,KAAK;eAALA;;IAGAC,eAAe;eAAfA;;;6BAhF+C;yBAE9B;uBACO;0BACN;yBACD;yBACA;uBACF;yBACE;sBACH;AAKpB,MAAMH,eAAeI,IAAAA,mBAAM,EAChCC,iBAAU,EACVC,IAAAA,mBAAM,EAAC;IACL,sEAAsE;IACtE,mEAAmE;IACnEC,UAAUC,IAAAA,kBAAK,EAACC,IAAAA,iBAAI,EAAC,IAAMN;AAC7B;AAgBK,MAAMF,cAA6BG,IAAAA,mBAAM,EAC9CJ,cACAM,IAAAA,mBAAM,EAAC;IACLI,MAAMC,IAAAA,oBAAO,EAACC,eAAQ,CAACC,KAAK;AAC9B;AAqCK,MAAMX,QAAQY,IAAAA,sBAAa,EAACF,eAAQ,CAACC,KAAK,EAAEZ,aAAa;IAAC;CAAW;AAGrE,MAAME,kBAAkBY,IAAAA,kBAAK,EAAC;IACnCC,wBAAc;IACdC,sBAAa;IACbC,sBAAa;IACbC,kBAAW;IACXlB;IACAmB,sBAAa;IACbC,gBAAU;CACX"}
1
+ {"version":3,"sources":["../../../../src/ui/components/panel.ts"],"sourcesContent":["import type { Infer, Struct } from 'superstruct';\nimport { array, assign, lazy, literal, object, union } from 'superstruct';\n\nimport { createBuilder } from '../builder';\nimport { NodeStruct, NodeType } from '../nodes';\nimport { AddressStruct } from './address';\nimport { CopyableStruct } from './copyable';\nimport { DividerStruct } from './divider';\nimport { HeadingStruct } from './heading';\nimport { ImageStruct } from './image';\nimport { RowStruct } from './row';\nimport { SpinnerStruct } from './spinner';\nimport { TextStruct } from './text';\n\n/**\n * @internal\n */\nexport const ParentStruct = assign(\n NodeStruct,\n object({\n // This node references itself indirectly, so we need to use `lazy()`.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n children: array(lazy(() => ComponentStruct)),\n }),\n);\n\n/**\n * A node which supports child nodes. This is used for nodes that render their\n * children, such as {@link Panel}.\n *\n * @property type - The type of the node.\n * @property children - The children of the node\n * @internal\n */\nexport type Parent = Infer<typeof ParentStruct>;\n\n/**\n * @internal\n */\nexport const PanelStruct: Struct<Panel> = assign(\n ParentStruct,\n object({\n type: literal(NodeType.Panel),\n }),\n);\n\n/**\n * A panel node, which renders its children.\n *\n * @property type - The type of the node, must be the string 'text'.\n * @property value - The text content of the node, either as plain text, or as a\n * markdown string.\n */\n// This node references itself indirectly, so it cannot be inferred.\nexport type Panel = {\n type: NodeType.Panel;\n children: Component[];\n};\n\n/**\n * Create a {@link Panel} node.\n *\n * @param args - The node arguments. This can be either an array of children, or\n * an object with a `children` property.\n * @param args.children - The child nodes of the panel. This can be any valid\n * {@link Component}.\n * @returns The panel node as object.\n * @example\n * const node = panel({\n * children: [\n * heading({ text: 'Hello, world!' }),\n * text({ text: 'This is a panel.' }),\n * ],\n * });\n *\n * const node = panel([\n * heading('Hello, world!'),\n * text('This is a panel.'),\n * ]);\n */\nexport const panel = createBuilder(NodeType.Panel, PanelStruct, ['children']);\n\n// This is defined separately from `Component` to avoid circular dependencies.\nexport const ComponentStruct = union([\n CopyableStruct,\n DividerStruct,\n HeadingStruct,\n ImageStruct,\n PanelStruct,\n SpinnerStruct,\n TextStruct,\n RowStruct,\n AddressStruct,\n]);\n\n/**\n * All supported component types.\n */\nexport type Component = Infer<typeof ComponentStruct>;\n"],"names":["ParentStruct","PanelStruct","panel","ComponentStruct","assign","NodeStruct","object","children","array","lazy","type","literal","NodeType","Panel","createBuilder","union","CopyableStruct","DividerStruct","HeadingStruct","ImageStruct","SpinnerStruct","TextStruct","RowStruct","AddressStruct"],"mappings":";;;;;;;;;;;IAiBaA,YAAY;eAAZA;;IAsBAC,WAAW;eAAXA;;IAyCAC,KAAK;eAALA;;IAGAC,eAAe;eAAfA;;;6BAlF+C;yBAE9B;uBACO;yBACP;0BACC;yBACD;yBACA;uBACF;qBACF;yBACI;sBACH;AAKpB,MAAMH,eAAeI,IAAAA,mBAAM,EAChCC,iBAAU,EACVC,IAAAA,mBAAM,EAAC;IACL,sEAAsE;IACtE,mEAAmE;IACnEC,UAAUC,IAAAA,kBAAK,EAACC,IAAAA,iBAAI,EAAC,IAAMN;AAC7B;AAgBK,MAAMF,cAA6BG,IAAAA,mBAAM,EAC9CJ,cACAM,IAAAA,mBAAM,EAAC;IACLI,MAAMC,IAAAA,oBAAO,EAACC,eAAQ,CAACC,KAAK;AAC9B;AAqCK,MAAMX,QAAQY,IAAAA,sBAAa,EAACF,eAAQ,CAACC,KAAK,EAAEZ,aAAa;IAAC;CAAW;AAGrE,MAAME,kBAAkBY,IAAAA,kBAAK,EAAC;IACnCC,wBAAc;IACdC,sBAAa;IACbC,sBAAa;IACbC,kBAAW;IACXlB;IACAmB,sBAAa;IACbC,gBAAU;IACVC,cAAS;IACTC,sBAAa;CACd"}
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ RowVariant: function() {
13
+ return RowVariant;
14
+ },
15
+ RowStruct: function() {
16
+ return RowStruct;
17
+ },
18
+ row: function() {
19
+ return row;
20
+ }
21
+ });
22
+ const _superstruct = require("superstruct");
23
+ const _internals = require("../../internals");
24
+ const _builder = require("../builder");
25
+ const _nodes = require("../nodes");
26
+ const _address = require("./address");
27
+ const _image = require("./image");
28
+ const _text = require("./text");
29
+ var RowVariant;
30
+ (function(RowVariant) {
31
+ RowVariant["Default"] = 'default';
32
+ RowVariant["Critical"] = 'critical';
33
+ RowVariant["Warning"] = 'warning';
34
+ })(RowVariant || (RowVariant = {}));
35
+ // A subset of components made available to the row
36
+ const RowComponentStruct = (0, _superstruct.union)([
37
+ _image.ImageStruct,
38
+ _text.TextStruct,
39
+ _address.AddressStruct
40
+ ]);
41
+ const RowStruct = (0, _superstruct.assign)(_nodes.LiteralStruct, (0, _superstruct.object)({
42
+ type: (0, _superstruct.literal)(_nodes.NodeType.Row),
43
+ variant: (0, _superstruct.optional)((0, _superstruct.union)([
44
+ (0, _internals.enumValue)(RowVariant.Default),
45
+ (0, _internals.enumValue)(RowVariant.Critical),
46
+ (0, _internals.enumValue)(RowVariant.Warning)
47
+ ])),
48
+ label: (0, _superstruct.string)(),
49
+ value: RowComponentStruct
50
+ }));
51
+ const row = (0, _builder.createBuilder)(_nodes.NodeType.Row, RowStruct, [
52
+ 'label',
53
+ 'value',
54
+ 'variant'
55
+ ]);
56
+
57
+ //# sourceMappingURL=row.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/ui/components/row.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport { assign, literal, object, string, optional, union } from 'superstruct';\n\nimport { enumValue } from '../../internals';\nimport { createBuilder } from '../builder';\nimport { LiteralStruct, NodeType } from '../nodes';\nimport { AddressStruct } from './address';\nimport { ImageStruct } from './image';\nimport { TextStruct } from './text';\n\nexport enum RowVariant {\n Default = 'default',\n Critical = 'critical',\n Warning = 'warning',\n}\n\n// A subset of components made available to the row\nconst RowComponentStruct = union([ImageStruct, TextStruct, AddressStruct]);\n\nexport const RowStruct = assign(\n LiteralStruct,\n object({\n type: literal(NodeType.Row),\n variant: optional(\n union([\n enumValue(RowVariant.Default),\n enumValue(RowVariant.Critical),\n enumValue(RowVariant.Warning),\n ]),\n ),\n label: string(),\n value: RowComponentStruct,\n }),\n);\n\n/**\n * A row node, that renders a row with a label and a value.\n *\n * @property type - The type of the node. Must be the string `row`.\n * @property label - The label for the row.\n * @property value - A sub component to be rendered\n * on one side of the row.\n * @property variant - Optional variant for styling.\n */\nexport type Row = Infer<typeof RowStruct>;\n\n/**\n * Create a {@link Row} node.\n *\n * @param args - The node arguments. This can either be a string, a component and an optional variant or an object\n * with the properties: `label`, `value` and `variant`.\n * @param args.label - The label for the row.\n * @param args.value - Another component, is currently limited to `image`, `text` and `address`.\n * @param args.variant - An optional variant, either `default`, `warning` or `critical`.\n * @returns The row node as an object.\n * @example\n * const node = row({ label: 'Address', value: address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520') });\n * const node = row({ label: 'Address', value: address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520'), variant: RowVariant.Warning });\n * const node = row('Address', address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520'));\n * const node = row('Address', address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520'), RowVariant.Warning);\n */\nexport const row = createBuilder(NodeType.Row, RowStruct, [\n 'label',\n 'value',\n 'variant',\n]);\n"],"names":["RowStruct","row","RowVariant","Default","Critical","Warning","RowComponentStruct","union","ImageStruct","TextStruct","AddressStruct","assign","LiteralStruct","object","type","literal","NodeType","Row","variant","optional","enumValue","label","string","value","createBuilder"],"mappings":";;;;;;;;;;;;;;IAmBaA,SAAS;eAATA;;IA0CAC,GAAG;eAAHA;;;6BA5DoD;2BAEvC;yBACI;uBACU;yBACV;uBACF;sBACD;IAEpB;UAAKC,UAAU;IAAVA,WACVC,aAAU;IADAD,WAEVE,cAAW;IAFDF,WAGVG,aAAU;GAHAH,eAAAA;AAMZ,mDAAmD;AACnD,MAAMI,qBAAqBC,IAAAA,kBAAK,EAAC;IAACC,kBAAW;IAAEC,gBAAU;IAAEC,sBAAa;CAAC;AAElE,MAAMV,YAAYW,IAAAA,mBAAM,EAC7BC,oBAAa,EACbC,IAAAA,mBAAM,EAAC;IACLC,MAAMC,IAAAA,oBAAO,EAACC,eAAQ,CAACC,GAAG;IAC1BC,SAASC,IAAAA,qBAAQ,EACfZ,IAAAA,kBAAK,EAAC;QACJa,IAAAA,oBAAS,EAAClB,WAAWC,OAAO;QAC5BiB,IAAAA,oBAAS,EAAClB,WAAWE,QAAQ;QAC7BgB,IAAAA,oBAAS,EAAClB,WAAWG,OAAO;KAC7B;IAEHgB,OAAOC,IAAAA,mBAAM;IACbC,OAAOjB;AACT;AA6BK,MAAML,MAAMuB,IAAAA,sBAAa,EAACR,eAAQ,CAACC,GAAG,EAAEjB,WAAW;IACxD;IACA;IACA;CACD"}
@@ -30,6 +30,8 @@ var NodeType;
30
30
  NodeType[// eslint-disable-next-line @typescript-eslint/no-shadow
31
31
  "Text"] = 'text';
32
32
  NodeType["Image"] = 'image';
33
+ NodeType["Row"] = 'row';
34
+ NodeType["Address"] = 'address';
33
35
  })(NodeType || (NodeType = {}));
34
36
  const NodeStruct = (0, _superstruct.object)({
35
37
  type: (0, _superstruct.string)()
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/ui/nodes.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport { assign, object, string, unknown } from 'superstruct';\n\n/**\n * The supported node types. This is based on SIP-7.\n *\n * @see https://metamask.github.io/SIPs/SIPS/sip-7\n */\nexport enum NodeType {\n Copyable = 'copyable',\n Divider = 'divider',\n Heading = 'heading',\n Panel = 'panel',\n Spinner = 'spinner',\n // eslint-disable-next-line @typescript-eslint/no-shadow\n Text = 'text',\n Image = 'image',\n}\n\n/**\n * @internal\n */\nexport const NodeStruct = object({\n type: string(),\n});\n\n/**\n * The base node type. All nodes extend this type.\n *\n * @property type - The type of the node. See {@link NodeType} for the supported\n * node types.\n * @internal\n */\nexport type Node = Infer<typeof NodeStruct>;\n\n/**\n * @internal\n */\nexport const LiteralStruct = assign(\n NodeStruct,\n object({\n value: unknown(),\n }),\n);\n\n/**\n * A node with a value. This is used for nodes that render a value, such as\n * {@link Text}.\n *\n * @property type - The type of the node.\n * @property value - The value of the node. The type of the value depends on the\n * node type.\n * @internal\n */\nexport type Literal = Infer<typeof LiteralStruct>;\n"],"names":["NodeStruct","LiteralStruct","NodeType","Copyable","Divider","Heading","Panel","Spinner","Text","Image","object","type","string","assign","value","unknown"],"mappings":";;;;;;;;;;;;;;IAsBaA,UAAU;eAAVA;;IAgBAC,aAAa;eAAbA;;;6BArCmC;IAOzC;UAAKC,QAAQ;IAARA,SACVC,cAAW;IADDD,SAEVE,aAAU;IAFAF,SAGVG,aAAU;IAHAH,SAIVI,WAAQ;IAJEJ,SAKVK,aAAU;IALAL,SAMV,wDAAwD;IACxDM,UAAO;IAPGN,SAQVO,WAAQ;GAREP,aAAAA;AAcL,MAAMF,aAAaU,IAAAA,mBAAM,EAAC;IAC/BC,MAAMC,IAAAA,mBAAM;AACd;AAcO,MAAMX,gBAAgBY,IAAAA,mBAAM,EACjCb,YACAU,IAAAA,mBAAM,EAAC;IACLI,OAAOC,IAAAA,oBAAO;AAChB"}
1
+ {"version":3,"sources":["../../../src/ui/nodes.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport { assign, object, string, unknown } from 'superstruct';\n\n/**\n * The supported node types. This is based on SIP-7.\n *\n * @see https://metamask.github.io/SIPs/SIPS/sip-7\n */\nexport enum NodeType {\n Copyable = 'copyable',\n Divider = 'divider',\n Heading = 'heading',\n Panel = 'panel',\n Spinner = 'spinner',\n // eslint-disable-next-line @typescript-eslint/no-shadow\n Text = 'text',\n Image = 'image',\n Row = 'row',\n Address = 'address',\n}\n\n/**\n * @internal\n */\nexport const NodeStruct = object({\n type: string(),\n});\n\n/**\n * The base node type. All nodes extend this type.\n *\n * @property type - The type of the node. See {@link NodeType} for the supported\n * node types.\n * @internal\n */\nexport type Node = Infer<typeof NodeStruct>;\n\n/**\n * @internal\n */\nexport const LiteralStruct = assign(\n NodeStruct,\n object({\n value: unknown(),\n }),\n);\n\n/**\n * A node with a value. This is used for nodes that render a value, such as\n * {@link Text}.\n *\n * @property type - The type of the node.\n * @property value - The value of the node. The type of the value depends on the\n * node type.\n * @internal\n */\nexport type Literal = Infer<typeof LiteralStruct>;\n"],"names":["NodeStruct","LiteralStruct","NodeType","Copyable","Divider","Heading","Panel","Spinner","Text","Image","Row","Address","object","type","string","assign","value","unknown"],"mappings":";;;;;;;;;;;;;;IAwBaA,UAAU;eAAVA;;IAgBAC,aAAa;eAAbA;;;6BAvCmC;IAOzC;UAAKC,QAAQ;IAARA,SACVC,cAAW;IADDD,SAEVE,aAAU;IAFAF,SAGVG,aAAU;IAHAH,SAIVI,WAAQ;IAJEJ,SAKVK,aAAU;IALAL,SAMV,wDAAwD;IACxDM,UAAO;IAPGN,SAQVO,WAAQ;IAREP,SASVQ,SAAM;IATIR,SAUVS,aAAU;GAVAT,aAAAA;AAgBL,MAAMF,aAAaY,IAAAA,mBAAM,EAAC;IAC/BC,MAAMC,IAAAA,mBAAM;AACd;AAcO,MAAMb,gBAAgBc,IAAAA,mBAAM,EACjCf,YACAY,IAAAA,mBAAM,EAAC;IACLI,OAAOC,IAAAA,oBAAO;AAChB"}
package/dist/esm/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  // Only internals that are used by other Snaps packages should be exported here.
2
- export { getErrorData, getErrorMessage, getErrorStack, SNAP_ERROR_CODE, SNAP_ERROR_MESSAGE } from './internals';
2
+ export { getErrorData, getErrorMessage, getErrorStack, SNAP_ERROR_CODE, SNAP_ERROR_MESSAGE, literal, union, enumValue } from './internals';
3
3
  export * from './errors';
4
4
  export * from './types';
5
5
  export * from './ui';
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["// Only internals that are used by other Snaps packages should be exported here.\nexport type { EnumToUnion } from './internals';\nexport {\n getErrorData,\n getErrorMessage,\n getErrorStack,\n SNAP_ERROR_CODE,\n SNAP_ERROR_MESSAGE,\n} from './internals';\n\n// Re-exported from `@metamask/utils` for convenience.\nexport type {\n Json,\n JsonRpcError,\n JsonRpcRequest,\n JsonRpcParams,\n} from '@metamask/utils';\n\nexport * from './errors';\nexport * from './types';\nexport * from './ui';\n"],"names":["getErrorData","getErrorMessage","getErrorStack","SNAP_ERROR_CODE","SNAP_ERROR_MESSAGE"],"mappings":"AAAA,gFAAgF;AAEhF,SACEA,YAAY,EACZC,eAAe,EACfC,aAAa,EACbC,eAAe,EACfC,kBAAkB,QACb,cAAc;AAUrB,cAAc,WAAW;AACzB,cAAc,UAAU;AACxB,cAAc,OAAO"}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["// Only internals that are used by other Snaps packages should be exported here.\nexport type { EnumToUnion } from './internals';\nexport {\n getErrorData,\n getErrorMessage,\n getErrorStack,\n SNAP_ERROR_CODE,\n SNAP_ERROR_MESSAGE,\n literal,\n union,\n enumValue,\n} from './internals';\n\n// Re-exported from `@metamask/utils` for convenience.\nexport type {\n Json,\n JsonRpcError,\n JsonRpcRequest,\n JsonRpcParams,\n} from '@metamask/utils';\n\nexport * from './errors';\nexport * from './types';\nexport * from './ui';\n"],"names":["getErrorData","getErrorMessage","getErrorStack","SNAP_ERROR_CODE","SNAP_ERROR_MESSAGE","literal","union","enumValue"],"mappings":"AAAA,gFAAgF;AAEhF,SACEA,YAAY,EACZC,eAAe,EACfC,aAAa,EACbC,eAAe,EACfC,kBAAkB,EAClBC,OAAO,EACPC,KAAK,EACLC,SAAS,QACJ,cAAc;AAUrB,cAAc,WAAW;AACzB,cAAc,UAAU;AACxB,cAAc,OAAO"}
@@ -1,5 +1,6 @@
1
1
  export * from './error-wrappers';
2
2
  export * from './errors';
3
3
  export * from './helpers';
4
+ export * from './structs';
4
5
 
5
6
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/internals/index.ts"],"sourcesContent":["export * from './error-wrappers';\nexport * from './errors';\nexport * from './helpers';\n"],"names":[],"mappings":"AAAA,cAAc,mBAAmB;AACjC,cAAc,WAAW;AACzB,cAAc,YAAY"}
1
+ {"version":3,"sources":["../../../src/internals/index.ts"],"sourcesContent":["export * from './error-wrappers';\nexport * from './errors';\nexport * from './helpers';\nexport * from './structs';\n"],"names":[],"mappings":"AAAA,cAAc,mBAAmB;AACjC,cAAc,WAAW;AACzB,cAAc,YAAY;AAC1B,cAAc,YAAY"}
@@ -0,0 +1,59 @@
1
+ import { Struct, define, literal as superstructLiteral, union as superstructUnion } from 'superstruct';
2
+ /**
3
+ * A wrapper of `superstruct`'s `literal` struct that also defines the name of
4
+ * the struct as the literal value.
5
+ *
6
+ * This is useful for improving the error messages returned by `superstruct`.
7
+ * For example, instead of returning an error like:
8
+ *
9
+ * ```
10
+ * Expected the value to satisfy a union of `literal | literal`, but received: \"baz\"
11
+ * ```
12
+ *
13
+ * This struct will return an error like:
14
+ *
15
+ * ```
16
+ * Expected the value to satisfy a union of `"foo" | "bar"`, but received: \"baz\"
17
+ * ```
18
+ *
19
+ * @param value - The literal value.
20
+ * @returns The `superstruct` struct, which validates that the value is equal
21
+ * to the literal value.
22
+ */ export function literal(value) {
23
+ return define(JSON.stringify(value), superstructLiteral(value).validator);
24
+ }
25
+ /**
26
+ * A wrapper of `superstruct`'s `union` struct that also defines the schema as
27
+ * the union of the schemas of the structs.
28
+ *
29
+ * This is useful for improving the error messages returned by `superstruct`.
30
+ *
31
+ * @param structs - The structs to union.
32
+ * @param structs."0" - The first struct.
33
+ * @param structs."1" - The remaining structs.
34
+ * @returns The `superstruct` struct, which validates that the value satisfies
35
+ * one of the structs.
36
+ */ export function union([head, ...tail]) {
37
+ const struct = superstructUnion([
38
+ head,
39
+ ...tail
40
+ ]);
41
+ return new Struct({
42
+ ...struct,
43
+ schema: [
44
+ head,
45
+ ...tail
46
+ ]
47
+ });
48
+ }
49
+ /**
50
+ * Superstruct struct for validating an enum value. This allows using both the
51
+ * enum string values and the enum itself as values.
52
+ *
53
+ * @param constant - The enum to validate against.
54
+ * @returns The superstruct struct.
55
+ */ export function enumValue(constant) {
56
+ return literal(constant);
57
+ }
58
+
59
+ //# sourceMappingURL=structs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/internals/structs.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport {\n Struct,\n define,\n literal as superstructLiteral,\n union as superstructUnion,\n} from 'superstruct';\nimport type { AnyStruct, InferStructTuple } from 'superstruct/dist/utils';\n\nimport type { EnumToUnion } from './helpers';\n\n/**\n * A wrapper of `superstruct`'s `literal` struct that also defines the name of\n * the struct as the literal value.\n *\n * This is useful for improving the error messages returned by `superstruct`.\n * For example, instead of returning an error like:\n *\n * ```\n * Expected the value to satisfy a union of `literal | literal`, but received: \\\"baz\\\"\n * ```\n *\n * This struct will return an error like:\n *\n * ```\n * Expected the value to satisfy a union of `\"foo\" | \"bar\"`, but received: \\\"baz\\\"\n * ```\n *\n * @param value - The literal value.\n * @returns The `superstruct` struct, which validates that the value is equal\n * to the literal value.\n */\nexport function literal<Type extends string | number | boolean>(value: Type) {\n return define<Type>(\n JSON.stringify(value),\n superstructLiteral(value).validator,\n );\n}\n\n/**\n * A wrapper of `superstruct`'s `union` struct that also defines the schema as\n * the union of the schemas of the structs.\n *\n * This is useful for improving the error messages returned by `superstruct`.\n *\n * @param structs - The structs to union.\n * @param structs.\"0\" - The first struct.\n * @param structs.\"1\" - The remaining structs.\n * @returns The `superstruct` struct, which validates that the value satisfies\n * one of the structs.\n */\nexport function union<Head extends AnyStruct, Tail extends AnyStruct[]>([\n head,\n ...tail\n]: [head: Head, ...tail: Tail]): Struct<\n Infer<Head> | InferStructTuple<Tail>[number],\n [head: Head, ...tail: Tail]\n> {\n const struct = superstructUnion([head, ...tail]);\n\n return new Struct({\n ...struct,\n schema: [head, ...tail],\n });\n}\n\n/**\n * Superstruct struct for validating an enum value. This allows using both the\n * enum string values and the enum itself as values.\n *\n * @param constant - The enum to validate against.\n * @returns The superstruct struct.\n */\nexport function enumValue<Type extends string>(\n constant: Type,\n): Struct<EnumToUnion<Type>, null> {\n return literal(constant as EnumToUnion<Type>);\n}\n"],"names":["Struct","define","literal","superstructLiteral","union","superstructUnion","value","JSON","stringify","validator","head","tail","struct","schema","enumValue","constant"],"mappings":"AACA,SACEA,MAAM,EACNC,MAAM,EACNC,WAAWC,kBAAkB,EAC7BC,SAASC,gBAAgB,QACpB,cAAc;AAKrB;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,SAASH,QAAgDI,KAAW;IACzE,OAAOL,OACLM,KAAKC,SAAS,CAACF,QACfH,mBAAmBG,OAAOG,SAAS;AAEvC;AAEA;;;;;;;;;;;CAWC,GACD,OAAO,SAASL,MAAwD,CACtEM,MACA,GAAGC,KACyB;IAI5B,MAAMC,SAASP,iBAAiB;QAACK;WAASC;KAAK;IAE/C,OAAO,IAAIX,OAAO;QAChB,GAAGY,MAAM;QACTC,QAAQ;YAACH;eAASC;SAAK;IACzB;AACF;AAEA;;;;;;CAMC,GACD,OAAO,SAASG,UACdC,QAAc;IAEd,OAAOb,QAAQa;AACjB"}
@@ -0,0 +1,22 @@
1
+ import { assign, literal, object, pattern, string } from 'superstruct';
2
+ import { createBuilder } from '../builder';
3
+ import { LiteralStruct, NodeType } from '../nodes';
4
+ export const AddressStruct = assign(LiteralStruct, object({
5
+ type: literal(NodeType.Address),
6
+ value: pattern(string(), /0x[a-fA-F0-9]{40}/u)
7
+ }));
8
+ /**
9
+ * Create an {@link Address} node.
10
+ *
11
+ * @param args - The node arguments. This can either be a string, or an object
12
+ * with the `value` property.
13
+ * @param args.value - The address to be rendered.
14
+ * @returns The address node as an object.
15
+ * @example
16
+ * const node = address({ value: '0x4bbeeb066ed09b7aed07bf39eee0460dfa261520' });
17
+ * const node = address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520');
18
+ */ export const address = createBuilder(NodeType.Address, AddressStruct, [
19
+ 'value'
20
+ ]);
21
+
22
+ //# sourceMappingURL=address.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/ui/components/address.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport { assign, literal, object, pattern, string } from 'superstruct';\n\nimport { createBuilder } from '../builder';\nimport { LiteralStruct, NodeType } from '../nodes';\n\nexport const AddressStruct = assign(\n LiteralStruct,\n object({\n type: literal(NodeType.Address),\n value: pattern(string(), /0x[a-fA-F0-9]{40}/u),\n }),\n);\n\n/**\n * A address node, that renders an EVM-like address and its icon.\n *\n * @property type - The type of the node. Must be the string `address`.\n * @property value - The address in hexadecimal, including 0x.\n */\nexport type Address = Infer<typeof AddressStruct>;\n\n/**\n * Create an {@link Address} node.\n *\n * @param args - The node arguments. This can either be a string, or an object\n * with the `value` property.\n * @param args.value - The address to be rendered.\n * @returns The address node as an object.\n * @example\n * const node = address({ value: '0x4bbeeb066ed09b7aed07bf39eee0460dfa261520' });\n * const node = address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520');\n */\nexport const address = createBuilder(NodeType.Address, AddressStruct, [\n 'value',\n]);\n"],"names":["assign","literal","object","pattern","string","createBuilder","LiteralStruct","NodeType","AddressStruct","type","Address","value","address"],"mappings":"AACA,SAASA,MAAM,EAAEC,OAAO,EAAEC,MAAM,EAAEC,OAAO,EAAEC,MAAM,QAAQ,cAAc;AAEvE,SAASC,aAAa,QAAQ,aAAa;AAC3C,SAASC,aAAa,EAAEC,QAAQ,QAAQ,WAAW;AAEnD,OAAO,MAAMC,gBAAgBR,OAC3BM,eACAJ,OAAO;IACLO,MAAMR,QAAQM,SAASG,OAAO;IAC9BC,OAAOR,QAAQC,UAAU;AAC3B,IACA;AAUF;;;;;;;;;;CAUC,GACD,OAAO,MAAMQ,UAAUP,cAAcE,SAASG,OAAO,EAAEF,eAAe;IACpE;CACD,EAAE"}
@@ -1,3 +1,4 @@
1
+ export * from './address';
1
2
  export * from './copyable';
2
3
  export * from './divider';
3
4
  export * from './heading';
@@ -5,5 +6,6 @@ export { image, ImageStruct } from './image';
5
6
  export { ComponentStruct, panel, PanelStruct } from './panel';
6
7
  export * from './spinner';
7
8
  export * from './text';
9
+ export * from './row';
8
10
 
9
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/ui/components/index.ts"],"sourcesContent":["export * from './copyable';\nexport * from './divider';\nexport * from './heading';\nexport type { Image } from './image';\nexport { image, ImageStruct } from './image';\nexport type { Component, Panel } from './panel';\nexport { ComponentStruct, panel, PanelStruct } from './panel';\nexport * from './spinner';\nexport * from './text';\n"],"names":["image","ImageStruct","ComponentStruct","panel","PanelStruct"],"mappings":"AAAA,cAAc,aAAa;AAC3B,cAAc,YAAY;AAC1B,cAAc,YAAY;AAE1B,SAASA,KAAK,EAAEC,WAAW,QAAQ,UAAU;AAE7C,SAASC,eAAe,EAAEC,KAAK,EAAEC,WAAW,QAAQ,UAAU;AAC9D,cAAc,YAAY;AAC1B,cAAc,SAAS"}
1
+ {"version":3,"sources":["../../../../src/ui/components/index.ts"],"sourcesContent":["export * from './address';\nexport * from './copyable';\nexport * from './divider';\nexport * from './heading';\nexport type { Image } from './image';\nexport { image, ImageStruct } from './image';\nexport type { Component, Panel } from './panel';\nexport { ComponentStruct, panel, PanelStruct } from './panel';\nexport * from './spinner';\nexport * from './text';\nexport * from './row';\n"],"names":["image","ImageStruct","ComponentStruct","panel","PanelStruct"],"mappings":"AAAA,cAAc,YAAY;AAC1B,cAAc,aAAa;AAC3B,cAAc,YAAY;AAC1B,cAAc,YAAY;AAE1B,SAASA,KAAK,EAAEC,WAAW,QAAQ,UAAU;AAE7C,SAASC,eAAe,EAAEC,KAAK,EAAEC,WAAW,QAAQ,UAAU;AAC9D,cAAc,YAAY;AAC1B,cAAc,SAAS;AACvB,cAAc,QAAQ"}
@@ -1,10 +1,12 @@
1
1
  import { array, assign, lazy, literal, object, union } from 'superstruct';
2
2
  import { createBuilder } from '../builder';
3
3
  import { NodeStruct, NodeType } from '../nodes';
4
+ import { AddressStruct } from './address';
4
5
  import { CopyableStruct } from './copyable';
5
6
  import { DividerStruct } from './divider';
6
7
  import { HeadingStruct } from './heading';
7
8
  import { ImageStruct } from './image';
9
+ import { RowStruct } from './row';
8
10
  import { SpinnerStruct } from './spinner';
9
11
  import { TextStruct } from './text';
10
12
  /**
@@ -50,7 +52,9 @@ export const ComponentStruct = union([
50
52
  ImageStruct,
51
53
  PanelStruct,
52
54
  SpinnerStruct,
53
- TextStruct
55
+ TextStruct,
56
+ RowStruct,
57
+ AddressStruct
54
58
  ]);
55
59
 
56
60
  //# sourceMappingURL=panel.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/ui/components/panel.ts"],"sourcesContent":["import type { Infer, Struct } from 'superstruct';\nimport { array, assign, lazy, literal, object, union } from 'superstruct';\n\nimport { createBuilder } from '../builder';\nimport { NodeStruct, NodeType } from '../nodes';\nimport { CopyableStruct } from './copyable';\nimport { DividerStruct } from './divider';\nimport { HeadingStruct } from './heading';\nimport { ImageStruct } from './image';\nimport { SpinnerStruct } from './spinner';\nimport { TextStruct } from './text';\n\n/**\n * @internal\n */\nexport const ParentStruct = assign(\n NodeStruct,\n object({\n // This node references itself indirectly, so we need to use `lazy()`.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n children: array(lazy(() => ComponentStruct)),\n }),\n);\n\n/**\n * A node which supports child nodes. This is used for nodes that render their\n * children, such as {@link Panel}.\n *\n * @property type - The type of the node.\n * @property children - The children of the node\n * @internal\n */\nexport type Parent = Infer<typeof ParentStruct>;\n\n/**\n * @internal\n */\nexport const PanelStruct: Struct<Panel> = assign(\n ParentStruct,\n object({\n type: literal(NodeType.Panel),\n }),\n);\n\n/**\n * A panel node, which renders its children.\n *\n * @property type - The type of the node, must be the string 'text'.\n * @property value - The text content of the node, either as plain text, or as a\n * markdown string.\n */\n// This node references itself indirectly, so it cannot be inferred.\nexport type Panel = {\n type: NodeType.Panel;\n children: Component[];\n};\n\n/**\n * Create a {@link Panel} node.\n *\n * @param args - The node arguments. This can be either an array of children, or\n * an object with a `children` property.\n * @param args.children - The child nodes of the panel. This can be any valid\n * {@link Component}.\n * @returns The panel node as object.\n * @example\n * const node = panel({\n * children: [\n * heading({ text: 'Hello, world!' }),\n * text({ text: 'This is a panel.' }),\n * ],\n * });\n *\n * const node = panel([\n * heading('Hello, world!'),\n * text('This is a panel.'),\n * ]);\n */\nexport const panel = createBuilder(NodeType.Panel, PanelStruct, ['children']);\n\n// This is defined separately from `Component` to avoid circular dependencies.\nexport const ComponentStruct = union([\n CopyableStruct,\n DividerStruct,\n HeadingStruct,\n ImageStruct,\n PanelStruct,\n SpinnerStruct,\n TextStruct,\n]);\n\n/**\n * All supported component types.\n */\nexport type Component = Infer<typeof ComponentStruct>;\n"],"names":["array","assign","lazy","literal","object","union","createBuilder","NodeStruct","NodeType","CopyableStruct","DividerStruct","HeadingStruct","ImageStruct","SpinnerStruct","TextStruct","ParentStruct","children","ComponentStruct","PanelStruct","type","Panel","panel"],"mappings":"AACA,SAASA,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAEC,MAAM,EAAEC,KAAK,QAAQ,cAAc;AAE1E,SAASC,aAAa,QAAQ,aAAa;AAC3C,SAASC,UAAU,EAAEC,QAAQ,QAAQ,WAAW;AAChD,SAASC,cAAc,QAAQ,aAAa;AAC5C,SAASC,aAAa,QAAQ,YAAY;AAC1C,SAASC,aAAa,QAAQ,YAAY;AAC1C,SAASC,WAAW,QAAQ,UAAU;AACtC,SAASC,aAAa,QAAQ,YAAY;AAC1C,SAASC,UAAU,QAAQ,SAAS;AAEpC;;CAEC,GACD,OAAO,MAAMC,eAAed,OAC1BM,YACAH,OAAO;IACL,sEAAsE;IACtE,mEAAmE;IACnEY,UAAUhB,MAAME,KAAK,IAAMe;AAC7B,IACA;AAYF;;CAEC,GACD,OAAO,MAAMC,cAA6BjB,OACxCc,cACAX,OAAO;IACLe,MAAMhB,QAAQK,SAASY,KAAK;AAC9B,IACA;AAeF;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,MAAMC,QAAQf,cAAcE,SAASY,KAAK,EAAEF,aAAa;IAAC;CAAW,EAAE;AAE9E,8EAA8E;AAC9E,OAAO,MAAMD,kBAAkBZ,MAAM;IACnCI;IACAC;IACAC;IACAC;IACAM;IACAL;IACAC;CACD,EAAE"}
1
+ {"version":3,"sources":["../../../../src/ui/components/panel.ts"],"sourcesContent":["import type { Infer, Struct } from 'superstruct';\nimport { array, assign, lazy, literal, object, union } from 'superstruct';\n\nimport { createBuilder } from '../builder';\nimport { NodeStruct, NodeType } from '../nodes';\nimport { AddressStruct } from './address';\nimport { CopyableStruct } from './copyable';\nimport { DividerStruct } from './divider';\nimport { HeadingStruct } from './heading';\nimport { ImageStruct } from './image';\nimport { RowStruct } from './row';\nimport { SpinnerStruct } from './spinner';\nimport { TextStruct } from './text';\n\n/**\n * @internal\n */\nexport const ParentStruct = assign(\n NodeStruct,\n object({\n // This node references itself indirectly, so we need to use `lazy()`.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n children: array(lazy(() => ComponentStruct)),\n }),\n);\n\n/**\n * A node which supports child nodes. This is used for nodes that render their\n * children, such as {@link Panel}.\n *\n * @property type - The type of the node.\n * @property children - The children of the node\n * @internal\n */\nexport type Parent = Infer<typeof ParentStruct>;\n\n/**\n * @internal\n */\nexport const PanelStruct: Struct<Panel> = assign(\n ParentStruct,\n object({\n type: literal(NodeType.Panel),\n }),\n);\n\n/**\n * A panel node, which renders its children.\n *\n * @property type - The type of the node, must be the string 'text'.\n * @property value - The text content of the node, either as plain text, or as a\n * markdown string.\n */\n// This node references itself indirectly, so it cannot be inferred.\nexport type Panel = {\n type: NodeType.Panel;\n children: Component[];\n};\n\n/**\n * Create a {@link Panel} node.\n *\n * @param args - The node arguments. This can be either an array of children, or\n * an object with a `children` property.\n * @param args.children - The child nodes of the panel. This can be any valid\n * {@link Component}.\n * @returns The panel node as object.\n * @example\n * const node = panel({\n * children: [\n * heading({ text: 'Hello, world!' }),\n * text({ text: 'This is a panel.' }),\n * ],\n * });\n *\n * const node = panel([\n * heading('Hello, world!'),\n * text('This is a panel.'),\n * ]);\n */\nexport const panel = createBuilder(NodeType.Panel, PanelStruct, ['children']);\n\n// This is defined separately from `Component` to avoid circular dependencies.\nexport const ComponentStruct = union([\n CopyableStruct,\n DividerStruct,\n HeadingStruct,\n ImageStruct,\n PanelStruct,\n SpinnerStruct,\n TextStruct,\n RowStruct,\n AddressStruct,\n]);\n\n/**\n * All supported component types.\n */\nexport type Component = Infer<typeof ComponentStruct>;\n"],"names":["array","assign","lazy","literal","object","union","createBuilder","NodeStruct","NodeType","AddressStruct","CopyableStruct","DividerStruct","HeadingStruct","ImageStruct","RowStruct","SpinnerStruct","TextStruct","ParentStruct","children","ComponentStruct","PanelStruct","type","Panel","panel"],"mappings":"AACA,SAASA,KAAK,EAAEC,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAEC,MAAM,EAAEC,KAAK,QAAQ,cAAc;AAE1E,SAASC,aAAa,QAAQ,aAAa;AAC3C,SAASC,UAAU,EAAEC,QAAQ,QAAQ,WAAW;AAChD,SAASC,aAAa,QAAQ,YAAY;AAC1C,SAASC,cAAc,QAAQ,aAAa;AAC5C,SAASC,aAAa,QAAQ,YAAY;AAC1C,SAASC,aAAa,QAAQ,YAAY;AAC1C,SAASC,WAAW,QAAQ,UAAU;AACtC,SAASC,SAAS,QAAQ,QAAQ;AAClC,SAASC,aAAa,QAAQ,YAAY;AAC1C,SAASC,UAAU,QAAQ,SAAS;AAEpC;;CAEC,GACD,OAAO,MAAMC,eAAehB,OAC1BM,YACAH,OAAO;IACL,sEAAsE;IACtE,mEAAmE;IACnEc,UAAUlB,MAAME,KAAK,IAAMiB;AAC7B,IACA;AAYF;;CAEC,GACD,OAAO,MAAMC,cAA6BnB,OACxCgB,cACAb,OAAO;IACLiB,MAAMlB,QAAQK,SAASc,KAAK;AAC9B,IACA;AAeF;;;;;;;;;;;;;;;;;;;;CAoBC,GACD,OAAO,MAAMC,QAAQjB,cAAcE,SAASc,KAAK,EAAEF,aAAa;IAAC;CAAW,EAAE;AAE9E,8EAA8E;AAC9E,OAAO,MAAMD,kBAAkBd,MAAM;IACnCK;IACAC;IACAC;IACAC;IACAO;IACAL;IACAC;IACAF;IACAL;CACD,EAAE"}
@@ -0,0 +1,50 @@
1
+ import { assign, literal, object, string, optional, union } from 'superstruct';
2
+ import { enumValue } from '../../internals';
3
+ import { createBuilder } from '../builder';
4
+ import { LiteralStruct, NodeType } from '../nodes';
5
+ import { AddressStruct } from './address';
6
+ import { ImageStruct } from './image';
7
+ import { TextStruct } from './text';
8
+ export var RowVariant;
9
+ (function(RowVariant) {
10
+ RowVariant["Default"] = 'default';
11
+ RowVariant["Critical"] = 'critical';
12
+ RowVariant["Warning"] = 'warning';
13
+ })(RowVariant || (RowVariant = {}));
14
+ // A subset of components made available to the row
15
+ const RowComponentStruct = union([
16
+ ImageStruct,
17
+ TextStruct,
18
+ AddressStruct
19
+ ]);
20
+ export const RowStruct = assign(LiteralStruct, object({
21
+ type: literal(NodeType.Row),
22
+ variant: optional(union([
23
+ enumValue(RowVariant.Default),
24
+ enumValue(RowVariant.Critical),
25
+ enumValue(RowVariant.Warning)
26
+ ])),
27
+ label: string(),
28
+ value: RowComponentStruct
29
+ }));
30
+ /**
31
+ * Create a {@link Row} node.
32
+ *
33
+ * @param args - The node arguments. This can either be a string, a component and an optional variant or an object
34
+ * with the properties: `label`, `value` and `variant`.
35
+ * @param args.label - The label for the row.
36
+ * @param args.value - Another component, is currently limited to `image`, `text` and `address`.
37
+ * @param args.variant - An optional variant, either `default`, `warning` or `critical`.
38
+ * @returns The row node as an object.
39
+ * @example
40
+ * const node = row({ label: 'Address', value: address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520') });
41
+ * const node = row({ label: 'Address', value: address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520'), variant: RowVariant.Warning });
42
+ * const node = row('Address', address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520'));
43
+ * const node = row('Address', address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520'), RowVariant.Warning);
44
+ */ export const row = createBuilder(NodeType.Row, RowStruct, [
45
+ 'label',
46
+ 'value',
47
+ 'variant'
48
+ ]);
49
+
50
+ //# sourceMappingURL=row.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/ui/components/row.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport { assign, literal, object, string, optional, union } from 'superstruct';\n\nimport { enumValue } from '../../internals';\nimport { createBuilder } from '../builder';\nimport { LiteralStruct, NodeType } from '../nodes';\nimport { AddressStruct } from './address';\nimport { ImageStruct } from './image';\nimport { TextStruct } from './text';\n\nexport enum RowVariant {\n Default = 'default',\n Critical = 'critical',\n Warning = 'warning',\n}\n\n// A subset of components made available to the row\nconst RowComponentStruct = union([ImageStruct, TextStruct, AddressStruct]);\n\nexport const RowStruct = assign(\n LiteralStruct,\n object({\n type: literal(NodeType.Row),\n variant: optional(\n union([\n enumValue(RowVariant.Default),\n enumValue(RowVariant.Critical),\n enumValue(RowVariant.Warning),\n ]),\n ),\n label: string(),\n value: RowComponentStruct,\n }),\n);\n\n/**\n * A row node, that renders a row with a label and a value.\n *\n * @property type - The type of the node. Must be the string `row`.\n * @property label - The label for the row.\n * @property value - A sub component to be rendered\n * on one side of the row.\n * @property variant - Optional variant for styling.\n */\nexport type Row = Infer<typeof RowStruct>;\n\n/**\n * Create a {@link Row} node.\n *\n * @param args - The node arguments. This can either be a string, a component and an optional variant or an object\n * with the properties: `label`, `value` and `variant`.\n * @param args.label - The label for the row.\n * @param args.value - Another component, is currently limited to `image`, `text` and `address`.\n * @param args.variant - An optional variant, either `default`, `warning` or `critical`.\n * @returns The row node as an object.\n * @example\n * const node = row({ label: 'Address', value: address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520') });\n * const node = row({ label: 'Address', value: address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520'), variant: RowVariant.Warning });\n * const node = row('Address', address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520'));\n * const node = row('Address', address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520'), RowVariant.Warning);\n */\nexport const row = createBuilder(NodeType.Row, RowStruct, [\n 'label',\n 'value',\n 'variant',\n]);\n"],"names":["assign","literal","object","string","optional","union","enumValue","createBuilder","LiteralStruct","NodeType","AddressStruct","ImageStruct","TextStruct","RowVariant","Default","Critical","Warning","RowComponentStruct","RowStruct","type","Row","variant","label","value","row"],"mappings":"AACA,SAASA,MAAM,EAAEC,OAAO,EAAEC,MAAM,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,QAAQ,cAAc;AAE/E,SAASC,SAAS,QAAQ,kBAAkB;AAC5C,SAASC,aAAa,QAAQ,aAAa;AAC3C,SAASC,aAAa,EAAEC,QAAQ,QAAQ,WAAW;AACnD,SAASC,aAAa,QAAQ,YAAY;AAC1C,SAASC,WAAW,QAAQ,UAAU;AACtC,SAASC,UAAU,QAAQ,SAAS;WAE7B;UAAKC,UAAU;IAAVA,WACVC,aAAU;IADAD,WAEVE,cAAW;IAFDF,WAGVG,aAAU;GAHAH,eAAAA;AAMZ,mDAAmD;AACnD,MAAMI,qBAAqBZ,MAAM;IAACM;IAAaC;IAAYF;CAAc;AAEzE,OAAO,MAAMQ,YAAYlB,OACvBQ,eACAN,OAAO;IACLiB,MAAMlB,QAAQQ,SAASW,GAAG;IAC1BC,SAASjB,SACPC,MAAM;QACJC,UAAUO,WAAWC,OAAO;QAC5BR,UAAUO,WAAWE,QAAQ;QAC7BT,UAAUO,WAAWG,OAAO;KAC7B;IAEHM,OAAOnB;IACPoB,OAAON;AACT,IACA;AAaF;;;;;;;;;;;;;;CAcC,GACD,OAAO,MAAMO,MAAMjB,cAAcE,SAASW,GAAG,EAAEF,WAAW;IACxD;IACA;IACA;CACD,EAAE"}
@@ -9,6 +9,8 @@ export var NodeType;
9
9
  NodeType[// eslint-disable-next-line @typescript-eslint/no-shadow
10
10
  "Text"] = 'text';
11
11
  NodeType["Image"] = 'image';
12
+ NodeType["Row"] = 'row';
13
+ NodeType["Address"] = 'address';
12
14
  })(NodeType || (NodeType = {}));
13
15
  /**
14
16
  * @internal
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/ui/nodes.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport { assign, object, string, unknown } from 'superstruct';\n\n/**\n * The supported node types. This is based on SIP-7.\n *\n * @see https://metamask.github.io/SIPs/SIPS/sip-7\n */\nexport enum NodeType {\n Copyable = 'copyable',\n Divider = 'divider',\n Heading = 'heading',\n Panel = 'panel',\n Spinner = 'spinner',\n // eslint-disable-next-line @typescript-eslint/no-shadow\n Text = 'text',\n Image = 'image',\n}\n\n/**\n * @internal\n */\nexport const NodeStruct = object({\n type: string(),\n});\n\n/**\n * The base node type. All nodes extend this type.\n *\n * @property type - The type of the node. See {@link NodeType} for the supported\n * node types.\n * @internal\n */\nexport type Node = Infer<typeof NodeStruct>;\n\n/**\n * @internal\n */\nexport const LiteralStruct = assign(\n NodeStruct,\n object({\n value: unknown(),\n }),\n);\n\n/**\n * A node with a value. This is used for nodes that render a value, such as\n * {@link Text}.\n *\n * @property type - The type of the node.\n * @property value - The value of the node. The type of the value depends on the\n * node type.\n * @internal\n */\nexport type Literal = Infer<typeof LiteralStruct>;\n"],"names":["assign","object","string","unknown","NodeType","Copyable","Divider","Heading","Panel","Spinner","Text","Image","NodeStruct","type","LiteralStruct","value"],"mappings":"AACA,SAASA,MAAM,EAAEC,MAAM,EAAEC,MAAM,EAAEC,OAAO,QAAQ,cAAc;WAOvD;UAAKC,QAAQ;IAARA,SACVC,cAAW;IADDD,SAEVE,aAAU;IAFAF,SAGVG,aAAU;IAHAH,SAIVI,WAAQ;IAJEJ,SAKVK,aAAU;IALAL,SAMV,wDAAwD;IACxDM,UAAO;IAPGN,SAQVO,WAAQ;GAREP,aAAAA;AAWZ;;CAEC,GACD,OAAO,MAAMQ,aAAaX,OAAO;IAC/BY,MAAMX;AACR,GAAG;AAWH;;CAEC,GACD,OAAO,MAAMY,gBAAgBd,OAC3BY,YACAX,OAAO;IACLc,OAAOZ;AACT,IACA"}
1
+ {"version":3,"sources":["../../../src/ui/nodes.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport { assign, object, string, unknown } from 'superstruct';\n\n/**\n * The supported node types. This is based on SIP-7.\n *\n * @see https://metamask.github.io/SIPs/SIPS/sip-7\n */\nexport enum NodeType {\n Copyable = 'copyable',\n Divider = 'divider',\n Heading = 'heading',\n Panel = 'panel',\n Spinner = 'spinner',\n // eslint-disable-next-line @typescript-eslint/no-shadow\n Text = 'text',\n Image = 'image',\n Row = 'row',\n Address = 'address',\n}\n\n/**\n * @internal\n */\nexport const NodeStruct = object({\n type: string(),\n});\n\n/**\n * The base node type. All nodes extend this type.\n *\n * @property type - The type of the node. See {@link NodeType} for the supported\n * node types.\n * @internal\n */\nexport type Node = Infer<typeof NodeStruct>;\n\n/**\n * @internal\n */\nexport const LiteralStruct = assign(\n NodeStruct,\n object({\n value: unknown(),\n }),\n);\n\n/**\n * A node with a value. This is used for nodes that render a value, such as\n * {@link Text}.\n *\n * @property type - The type of the node.\n * @property value - The value of the node. The type of the value depends on the\n * node type.\n * @internal\n */\nexport type Literal = Infer<typeof LiteralStruct>;\n"],"names":["assign","object","string","unknown","NodeType","Copyable","Divider","Heading","Panel","Spinner","Text","Image","Row","Address","NodeStruct","type","LiteralStruct","value"],"mappings":"AACA,SAASA,MAAM,EAAEC,MAAM,EAAEC,MAAM,EAAEC,OAAO,QAAQ,cAAc;WAOvD;UAAKC,QAAQ;IAARA,SACVC,cAAW;IADDD,SAEVE,aAAU;IAFAF,SAGVG,aAAU;IAHAH,SAIVI,WAAQ;IAJEJ,SAKVK,aAAU;IALAL,SAMV,wDAAwD;IACxDM,UAAO;IAPGN,SAQVO,WAAQ;IAREP,SASVQ,SAAM;IATIR,SAUVS,aAAU;GAVAT,aAAAA;AAaZ;;CAEC,GACD,OAAO,MAAMU,aAAab,OAAO;IAC/Bc,MAAMb;AACR,GAAG;AAWH;;CAEC,GACD,OAAO,MAAMc,gBAAgBhB,OAC3Bc,YACAb,OAAO;IACLgB,OAAOd;AACT,IACA"}
@@ -1,5 +1,5 @@
1
1
  export type { EnumToUnion } from './internals';
2
- export { getErrorData, getErrorMessage, getErrorStack, SNAP_ERROR_CODE, SNAP_ERROR_MESSAGE, } from './internals';
2
+ export { getErrorData, getErrorMessage, getErrorStack, SNAP_ERROR_CODE, SNAP_ERROR_MESSAGE, literal, union, enumValue, } from './internals';
3
3
  export type { Json, JsonRpcError, JsonRpcRequest, JsonRpcParams, } from '@metamask/utils';
4
4
  export * from './errors';
5
5
  export * from './types';
@@ -1,3 +1,4 @@
1
1
  export * from './error-wrappers';
2
2
  export * from './errors';
3
3
  export * from './helpers';
4
+ export * from './structs';
@@ -0,0 +1,50 @@
1
+ import type { Infer } from 'superstruct';
2
+ import { Struct } from 'superstruct';
3
+ import type { AnyStruct, InferStructTuple } from 'superstruct/dist/utils';
4
+ import type { EnumToUnion } from './helpers';
5
+ /**
6
+ * A wrapper of `superstruct`'s `literal` struct that also defines the name of
7
+ * the struct as the literal value.
8
+ *
9
+ * This is useful for improving the error messages returned by `superstruct`.
10
+ * For example, instead of returning an error like:
11
+ *
12
+ * ```
13
+ * Expected the value to satisfy a union of `literal | literal`, but received: \"baz\"
14
+ * ```
15
+ *
16
+ * This struct will return an error like:
17
+ *
18
+ * ```
19
+ * Expected the value to satisfy a union of `"foo" | "bar"`, but received: \"baz\"
20
+ * ```
21
+ *
22
+ * @param value - The literal value.
23
+ * @returns The `superstruct` struct, which validates that the value is equal
24
+ * to the literal value.
25
+ */
26
+ export declare function literal<Type extends string | number | boolean>(value: Type): Struct<Type, null>;
27
+ /**
28
+ * A wrapper of `superstruct`'s `union` struct that also defines the schema as
29
+ * the union of the schemas of the structs.
30
+ *
31
+ * This is useful for improving the error messages returned by `superstruct`.
32
+ *
33
+ * @param structs - The structs to union.
34
+ * @param structs."0" - The first struct.
35
+ * @param structs."1" - The remaining structs.
36
+ * @returns The `superstruct` struct, which validates that the value satisfies
37
+ * one of the structs.
38
+ */
39
+ export declare function union<Head extends AnyStruct, Tail extends AnyStruct[]>([head, ...tail]: [head: Head, ...tail: Tail]): Struct<Infer<Head> | InferStructTuple<Tail>[number], [
40
+ head: Head,
41
+ ...tail: Tail
42
+ ]>;
43
+ /**
44
+ * Superstruct struct for validating an enum value. This allows using both the
45
+ * enum string values and the enum itself as values.
46
+ *
47
+ * @param constant - The enum to validate against.
48
+ * @returns The superstruct struct.
49
+ */
50
+ export declare function enumValue<Type extends string>(constant: Type): Struct<EnumToUnion<Type>, null>;
@@ -0,0 +1,34 @@
1
+ import type { Infer } from 'superstruct';
2
+ import { NodeType } from '../nodes';
3
+ export declare const AddressStruct: import("superstruct").Struct<{
4
+ value: string;
5
+ type: NodeType.Address;
6
+ }, {
7
+ type: import("superstruct").Struct<NodeType.Address, NodeType.Address>;
8
+ value: import("superstruct").Struct<string, null>;
9
+ }>;
10
+ /**
11
+ * A address node, that renders an EVM-like address and its icon.
12
+ *
13
+ * @property type - The type of the node. Must be the string `address`.
14
+ * @property value - The address in hexadecimal, including 0x.
15
+ */
16
+ export declare type Address = Infer<typeof AddressStruct>;
17
+ /**
18
+ * Create an {@link Address} node.
19
+ *
20
+ * @param args - The node arguments. This can either be a string, or an object
21
+ * with the `value` property.
22
+ * @param args.value - The address to be rendered.
23
+ * @returns The address node as an object.
24
+ * @example
25
+ * const node = address({ value: '0x4bbeeb066ed09b7aed07bf39eee0460dfa261520' });
26
+ * const node = address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520');
27
+ */
28
+ export declare const address: (...args: string[] | [Omit<{
29
+ value: string;
30
+ type: NodeType.Address;
31
+ }, "type">]) => {
32
+ value: string;
33
+ type: NodeType.Address;
34
+ };
@@ -1,3 +1,4 @@
1
+ export * from './address';
1
2
  export * from './copyable';
2
3
  export * from './divider';
3
4
  export * from './heading';
@@ -7,3 +8,4 @@ export type { Component, Panel } from './panel';
7
8
  export { ComponentStruct, panel, PanelStruct } from './panel';
8
9
  export * from './spinner';
9
10
  export * from './text';
11
+ export * from './row';
@@ -23,6 +23,24 @@ export declare const ParentStruct: Struct<{
23
23
  value: string;
24
24
  type: NodeType.Text;
25
25
  markdown?: boolean | undefined;
26
+ } | {
27
+ value: string;
28
+ type: NodeType.Address;
29
+ } | {
30
+ value: {
31
+ value: string;
32
+ type: NodeType.Image;
33
+ } | {
34
+ value: string;
35
+ type: NodeType.Text;
36
+ markdown?: boolean | undefined;
37
+ } | {
38
+ value: string;
39
+ type: NodeType.Address;
40
+ };
41
+ type: NodeType.Row;
42
+ label: string;
43
+ variant?: "default" | "warning" | "critical" | undefined;
26
44
  })[];
27
45
  }, {
28
46
  children: Struct<({
@@ -43,6 +61,24 @@ export declare const ParentStruct: Struct<{
43
61
  value: string;
44
62
  type: NodeType.Text;
45
63
  markdown?: boolean | undefined;
64
+ } | {
65
+ value: string;
66
+ type: NodeType.Address;
67
+ } | {
68
+ value: {
69
+ value: string;
70
+ type: NodeType.Image;
71
+ } | {
72
+ value: string;
73
+ type: NodeType.Text;
74
+ markdown?: boolean | undefined;
75
+ } | {
76
+ value: string;
77
+ type: NodeType.Address;
78
+ };
79
+ type: NodeType.Row;
80
+ label: string;
81
+ variant?: "default" | "warning" | "critical" | undefined;
46
82
  })[], Struct<{
47
83
  value: string;
48
84
  type: NodeType.Copyable;
@@ -61,6 +97,24 @@ export declare const ParentStruct: Struct<{
61
97
  value: string;
62
98
  type: NodeType.Text;
63
99
  markdown?: boolean | undefined;
100
+ } | {
101
+ value: string;
102
+ type: NodeType.Address;
103
+ } | {
104
+ value: {
105
+ value: string;
106
+ type: NodeType.Image;
107
+ } | {
108
+ value: string;
109
+ type: NodeType.Text;
110
+ markdown?: boolean | undefined;
111
+ } | {
112
+ value: string;
113
+ type: NodeType.Address;
114
+ };
115
+ type: NodeType.Row;
116
+ label: string;
117
+ variant?: "default" | "warning" | "critical" | undefined;
64
118
  }, null>>;
65
119
  type: Struct<string, null>;
66
120
  }>;
@@ -127,6 +181,24 @@ export declare const panel: (...args: [Omit<Panel, "type">] | ({
127
181
  value: string;
128
182
  type: NodeType.Text;
129
183
  markdown?: boolean | undefined;
184
+ } | {
185
+ value: string;
186
+ type: NodeType.Address;
187
+ } | {
188
+ value: {
189
+ value: string;
190
+ type: NodeType.Image;
191
+ } | {
192
+ value: string;
193
+ type: NodeType.Text;
194
+ markdown?: boolean | undefined;
195
+ } | {
196
+ value: string;
197
+ type: NodeType.Address;
198
+ };
199
+ type: NodeType.Row;
200
+ label: string;
201
+ variant?: "default" | "warning" | "critical" | undefined;
130
202
  })[][]) => Panel;
131
203
  export declare const ComponentStruct: Struct<{
132
204
  value: string;
@@ -146,6 +218,24 @@ export declare const ComponentStruct: Struct<{
146
218
  value: string;
147
219
  type: NodeType.Text;
148
220
  markdown?: boolean | undefined;
221
+ } | {
222
+ value: string;
223
+ type: NodeType.Address;
224
+ } | {
225
+ value: {
226
+ value: string;
227
+ type: NodeType.Image;
228
+ } | {
229
+ value: string;
230
+ type: NodeType.Text;
231
+ markdown?: boolean | undefined;
232
+ } | {
233
+ value: string;
234
+ type: NodeType.Address;
235
+ };
236
+ type: NodeType.Row;
237
+ label: string;
238
+ variant?: "default" | "warning" | "critical" | undefined;
149
239
  }, null>;
150
240
  /**
151
241
  * All supported component types.
@@ -0,0 +1,104 @@
1
+ import type { Infer } from 'superstruct';
2
+ import { NodeType } from '../nodes';
3
+ export declare enum RowVariant {
4
+ Default = "default",
5
+ Critical = "critical",
6
+ Warning = "warning"
7
+ }
8
+ export declare const RowStruct: import("superstruct").Struct<{
9
+ value: {
10
+ value: string;
11
+ type: NodeType.Image;
12
+ } | {
13
+ value: string;
14
+ type: NodeType.Text;
15
+ markdown?: boolean | undefined;
16
+ } | {
17
+ value: string;
18
+ type: NodeType.Address;
19
+ };
20
+ type: NodeType.Row;
21
+ label: string;
22
+ variant?: "default" | "warning" | "critical" | undefined;
23
+ }, {
24
+ type: import("superstruct").Struct<NodeType.Row, NodeType.Row>;
25
+ variant: import("superstruct").Struct<"default" | "warning" | "critical" | undefined, null>;
26
+ label: import("superstruct").Struct<string, null>;
27
+ value: import("superstruct").Struct<{
28
+ value: string;
29
+ type: NodeType.Image;
30
+ } | {
31
+ value: string;
32
+ type: NodeType.Text;
33
+ markdown?: boolean | undefined;
34
+ } | {
35
+ value: string;
36
+ type: NodeType.Address;
37
+ }, null>;
38
+ }>;
39
+ /**
40
+ * A row node, that renders a row with a label and a value.
41
+ *
42
+ * @property type - The type of the node. Must be the string `row`.
43
+ * @property label - The label for the row.
44
+ * @property value - A sub component to be rendered
45
+ * on one side of the row.
46
+ * @property variant - Optional variant for styling.
47
+ */
48
+ export declare type Row = Infer<typeof RowStruct>;
49
+ /**
50
+ * Create a {@link Row} node.
51
+ *
52
+ * @param args - The node arguments. This can either be a string, a component and an optional variant or an object
53
+ * with the properties: `label`, `value` and `variant`.
54
+ * @param args.label - The label for the row.
55
+ * @param args.value - Another component, is currently limited to `image`, `text` and `address`.
56
+ * @param args.variant - An optional variant, either `default`, `warning` or `critical`.
57
+ * @returns The row node as an object.
58
+ * @example
59
+ * const node = row({ label: 'Address', value: address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520') });
60
+ * const node = row({ label: 'Address', value: address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520'), variant: RowVariant.Warning });
61
+ * const node = row('Address', address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520'));
62
+ * const node = row('Address', address('0x4bbeeb066ed09b7aed07bf39eee0460dfa261520'), RowVariant.Warning);
63
+ */
64
+ export declare const row: (...args: [Omit<{
65
+ value: {
66
+ value: string;
67
+ type: NodeType.Image;
68
+ } | {
69
+ value: string;
70
+ type: NodeType.Text;
71
+ markdown?: boolean | undefined;
72
+ } | {
73
+ value: string;
74
+ type: NodeType.Address;
75
+ };
76
+ type: NodeType.Row;
77
+ label: string;
78
+ variant?: "default" | "warning" | "critical" | undefined;
79
+ }, "type">] | (string | {
80
+ value: string;
81
+ type: NodeType.Image;
82
+ } | {
83
+ value: string;
84
+ type: NodeType.Text;
85
+ markdown?: boolean | undefined;
86
+ } | {
87
+ value: string;
88
+ type: NodeType.Address;
89
+ } | undefined)[]) => {
90
+ value: {
91
+ value: string;
92
+ type: NodeType.Image;
93
+ } | {
94
+ value: string;
95
+ type: NodeType.Text;
96
+ markdown?: boolean | undefined;
97
+ } | {
98
+ value: string;
99
+ type: NodeType.Address;
100
+ };
101
+ type: NodeType.Row;
102
+ label: string;
103
+ variant?: "default" | "warning" | "critical" | undefined;
104
+ };
@@ -11,7 +11,9 @@ export declare enum NodeType {
11
11
  Panel = "panel",
12
12
  Spinner = "spinner",
13
13
  Text = "text",
14
- Image = "image"
14
+ Image = "image",
15
+ Row = "row",
16
+ Address = "address"
15
17
  }
16
18
  /**
17
19
  * @internal
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-sdk",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/MetaMask/snaps.git"
@@ -36,9 +36,9 @@
36
36
  },
37
37
  "dependencies": {
38
38
  "@metamask/key-tree": "^9.0.0",
39
- "@metamask/providers": "^13.0.0",
39
+ "@metamask/providers": "^14.0.1",
40
40
  "@metamask/rpc-errors": "^6.1.0",
41
- "@metamask/utils": "^8.1.0",
41
+ "@metamask/utils": "^8.2.1",
42
42
  "is-svg": "^4.4.0",
43
43
  "superstruct": "^1.0.3"
44
44
  },
@@ -51,7 +51,6 @@
51
51
  "@metamask/eslint-config-typescript": "^12.1.0",
52
52
  "@swc/cli": "^0.1.62",
53
53
  "@swc/core": "1.3.78",
54
- "@swc/jest": "^0.2.26",
55
54
  "@types/jest": "^27.5.1",
56
55
  "@typescript-eslint/eslint-plugin": "^5.42.1",
57
56
  "@typescript-eslint/parser": "^5.42.1",
@@ -65,11 +64,13 @@
65
64
  "eslint-plugin-n": "^15.7.0",
66
65
  "eslint-plugin-prettier": "^4.2.1",
67
66
  "eslint-plugin-promise": "^6.1.1",
67
+ "expect-type": "^0.17.3",
68
68
  "jest": "^29.0.2",
69
69
  "jest-it-up": "^2.0.0",
70
70
  "prettier": "^2.7.1",
71
71
  "prettier-plugin-packagejson": "^2.2.11",
72
72
  "rimraf": "^4.1.2",
73
+ "ts-jest": "^29.1.1",
73
74
  "typescript": "~4.8.4"
74
75
  },
75
76
  "engines": {