@metamask/snaps-sdk 4.4.2 → 5.0.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 +18 -1
- package/dist/index.js +191 -215
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +31 -56
- package/dist/index.mjs.map +1 -1
- package/dist/jsx/index.js +68 -52
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +48 -33
- package/dist/jsx/index.mjs.map +1 -1
- package/dist/jsx/jsx-dev-runtime.js +68 -52
- package/dist/jsx/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx/jsx-dev-runtime.mjs +48 -33
- package/dist/jsx/jsx-dev-runtime.mjs.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/internals/svg.d.ts +4 -11
- package/dist/types/jsx/component.d.ts +12 -2
- package/dist/types/jsx/components/Row.d.ts +5 -2
- package/dist/types/jsx/components/form/Dropdown.d.ts +1 -2
- package/dist/types/jsx/components/form/Input.d.ts +1 -2
- package/dist/types/types/handlers/name-lookup.d.ts +1 -0
- package/dist/types/ui/components/image.d.ts +0 -7
- package/package.json +1 -2
|
@@ -43,7 +43,7 @@ function jsx(component, props, key) {
|
|
|
43
43
|
|
|
44
44
|
// src/jsx/validation.ts
|
|
45
45
|
var import_utils = require("@metamask/utils");
|
|
46
|
-
var
|
|
46
|
+
var import_superstruct3 = require("superstruct");
|
|
47
47
|
|
|
48
48
|
// src/internals/structs.ts
|
|
49
49
|
var import_superstruct = require("superstruct");
|
|
@@ -69,84 +69,99 @@ function nullUnion(structs) {
|
|
|
69
69
|
return union(structs);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
// src/internals/svg.ts
|
|
73
|
+
var import_superstruct2 = require("superstruct");
|
|
74
|
+
function svg() {
|
|
75
|
+
return (0, import_superstruct2.refine)((0, import_superstruct2.string)(), "SVG", (value) => {
|
|
76
|
+
if (!value.includes("<svg")) {
|
|
77
|
+
return "Value is not a valid SVG.";
|
|
78
|
+
}
|
|
79
|
+
return true;
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
|
|
72
83
|
// src/jsx/validation.ts
|
|
73
|
-
var KeyStruct = nullUnion([(0,
|
|
84
|
+
var KeyStruct = nullUnion([(0, import_superstruct3.string)(), (0, import_superstruct3.number)()]);
|
|
74
85
|
var StringElementStruct = maybeArray(
|
|
75
|
-
(0,
|
|
86
|
+
(0, import_superstruct3.string)()
|
|
76
87
|
);
|
|
77
|
-
var ElementStruct = (0,
|
|
78
|
-
type: (0,
|
|
79
|
-
props: (0,
|
|
80
|
-
key: (0,
|
|
88
|
+
var ElementStruct = (0, import_superstruct3.object)({
|
|
89
|
+
type: (0, import_superstruct3.string)(),
|
|
90
|
+
props: (0, import_superstruct3.record)((0, import_superstruct3.string)(), import_utils.JsonStruct),
|
|
91
|
+
key: (0, import_superstruct3.nullable)(KeyStruct)
|
|
81
92
|
});
|
|
82
|
-
function
|
|
83
|
-
|
|
93
|
+
function nestable(struct) {
|
|
94
|
+
const nestableStruct = nullUnion([
|
|
95
|
+
struct,
|
|
96
|
+
(0, import_superstruct3.array)((0, import_superstruct3.lazy)(() => nestableStruct))
|
|
97
|
+
]);
|
|
98
|
+
return nestableStruct;
|
|
84
99
|
}
|
|
85
100
|
function maybeArray(struct) {
|
|
86
|
-
return
|
|
101
|
+
return nestable(struct);
|
|
87
102
|
}
|
|
88
103
|
function element(name, props = {}) {
|
|
89
|
-
return (0,
|
|
104
|
+
return (0, import_superstruct3.object)({
|
|
90
105
|
type: literal(name),
|
|
91
|
-
props: (0,
|
|
92
|
-
key: (0,
|
|
106
|
+
props: (0, import_superstruct3.object)(props),
|
|
107
|
+
key: (0, import_superstruct3.nullable)(KeyStruct)
|
|
93
108
|
});
|
|
94
109
|
}
|
|
95
110
|
var ButtonStruct = element("Button", {
|
|
96
111
|
children: StringElementStruct,
|
|
97
|
-
name: (0,
|
|
98
|
-
type: (0,
|
|
99
|
-
variant: (0,
|
|
100
|
-
disabled: (0,
|
|
112
|
+
name: (0, import_superstruct3.optional)((0, import_superstruct3.string)()),
|
|
113
|
+
type: (0, import_superstruct3.optional)(nullUnion([literal("button"), literal("submit")])),
|
|
114
|
+
variant: (0, import_superstruct3.optional)(nullUnion([literal("primary"), literal("destructive")])),
|
|
115
|
+
disabled: (0, import_superstruct3.optional)((0, import_superstruct3.boolean)())
|
|
101
116
|
});
|
|
102
117
|
var InputStruct = element("Input", {
|
|
103
|
-
name: (0,
|
|
104
|
-
type: (0,
|
|
118
|
+
name: (0, import_superstruct3.string)(),
|
|
119
|
+
type: (0, import_superstruct3.optional)(
|
|
105
120
|
nullUnion([literal("text"), literal("password"), literal("number")])
|
|
106
121
|
),
|
|
107
|
-
value: (0,
|
|
108
|
-
placeholder: (0,
|
|
122
|
+
value: (0, import_superstruct3.optional)((0, import_superstruct3.string)()),
|
|
123
|
+
placeholder: (0, import_superstruct3.optional)((0, import_superstruct3.string)())
|
|
109
124
|
});
|
|
110
125
|
var OptionStruct = element("Option", {
|
|
111
|
-
value: (0,
|
|
112
|
-
children: (0,
|
|
126
|
+
value: (0, import_superstruct3.string)(),
|
|
127
|
+
children: (0, import_superstruct3.string)()
|
|
113
128
|
});
|
|
114
129
|
var DropdownStruct = element("Dropdown", {
|
|
115
|
-
name: (0,
|
|
116
|
-
value: (0,
|
|
130
|
+
name: (0, import_superstruct3.string)(),
|
|
131
|
+
value: (0, import_superstruct3.optional)((0, import_superstruct3.string)()),
|
|
117
132
|
children: maybeArray(OptionStruct)
|
|
118
133
|
});
|
|
119
134
|
var FieldStruct = element("Field", {
|
|
120
|
-
label: (0,
|
|
121
|
-
error: (0,
|
|
135
|
+
label: (0, import_superstruct3.optional)((0, import_superstruct3.string)()),
|
|
136
|
+
error: (0, import_superstruct3.optional)((0, import_superstruct3.string)()),
|
|
122
137
|
children: nullUnion([
|
|
123
|
-
(0,
|
|
138
|
+
(0, import_superstruct3.tuple)([InputStruct, ButtonStruct]),
|
|
124
139
|
InputStruct,
|
|
125
140
|
DropdownStruct
|
|
126
141
|
])
|
|
127
142
|
});
|
|
128
143
|
var FormStruct = element("Form", {
|
|
129
144
|
children: maybeArray(nullUnion([FieldStruct, ButtonStruct])),
|
|
130
|
-
name: (0,
|
|
145
|
+
name: (0, import_superstruct3.string)()
|
|
131
146
|
});
|
|
132
147
|
var BoldStruct = element("Bold", {
|
|
133
148
|
children: maybeArray(
|
|
134
|
-
(0,
|
|
149
|
+
(0, import_superstruct3.nullable)(
|
|
135
150
|
nullUnion([
|
|
136
|
-
(0,
|
|
151
|
+
(0, import_superstruct3.string)(),
|
|
137
152
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
138
|
-
(0,
|
|
153
|
+
(0, import_superstruct3.lazy)(() => ItalicStruct)
|
|
139
154
|
])
|
|
140
155
|
)
|
|
141
156
|
)
|
|
142
157
|
});
|
|
143
158
|
var ItalicStruct = element("Italic", {
|
|
144
159
|
children: maybeArray(
|
|
145
|
-
(0,
|
|
160
|
+
(0, import_superstruct3.nullable)(
|
|
146
161
|
nullUnion([
|
|
147
|
-
(0,
|
|
162
|
+
(0, import_superstruct3.string)(),
|
|
148
163
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
149
|
-
(0,
|
|
164
|
+
(0, import_superstruct3.lazy)(() => BoldStruct)
|
|
150
165
|
])
|
|
151
166
|
)
|
|
152
167
|
)
|
|
@@ -161,10 +176,10 @@ var AddressStruct = element("Address", {
|
|
|
161
176
|
var BoxStruct = element("Box", {
|
|
162
177
|
children: maybeArray(
|
|
163
178
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
164
|
-
(0,
|
|
179
|
+
(0, import_superstruct3.nullable)((0, import_superstruct3.lazy)(() => BoxChildStruct))
|
|
165
180
|
),
|
|
166
|
-
direction: (0,
|
|
167
|
-
alignment: (0,
|
|
181
|
+
direction: (0, import_superstruct3.optional)(nullUnion([literal("horizontal"), literal("vertical")])),
|
|
182
|
+
alignment: (0, import_superstruct3.optional)(
|
|
168
183
|
nullUnion([
|
|
169
184
|
literal("start"),
|
|
170
185
|
literal("center"),
|
|
@@ -175,36 +190,37 @@ var BoxStruct = element("Box", {
|
|
|
175
190
|
)
|
|
176
191
|
});
|
|
177
192
|
var CopyableStruct = element("Copyable", {
|
|
178
|
-
value: (0,
|
|
179
|
-
sensitive: (0,
|
|
193
|
+
value: (0, import_superstruct3.string)(),
|
|
194
|
+
sensitive: (0, import_superstruct3.optional)((0, import_superstruct3.boolean)())
|
|
180
195
|
});
|
|
181
196
|
var DividerStruct = element("Divider");
|
|
182
197
|
var ValueStruct = element("Value", {
|
|
183
|
-
value: (0,
|
|
184
|
-
extra: (0,
|
|
198
|
+
value: (0, import_superstruct3.string)(),
|
|
199
|
+
extra: (0, import_superstruct3.string)()
|
|
185
200
|
});
|
|
186
201
|
var HeadingStruct = element("Heading", {
|
|
187
202
|
children: StringElementStruct
|
|
188
203
|
});
|
|
189
204
|
var ImageStruct = element("Image", {
|
|
190
|
-
src: (
|
|
191
|
-
alt: (0,
|
|
205
|
+
src: svg(),
|
|
206
|
+
alt: (0, import_superstruct3.optional)((0, import_superstruct3.string)())
|
|
192
207
|
});
|
|
193
208
|
var LinkStruct = element("Link", {
|
|
194
|
-
href: (0,
|
|
195
|
-
children: maybeArray((0,
|
|
209
|
+
href: (0, import_superstruct3.string)(),
|
|
210
|
+
children: maybeArray((0, import_superstruct3.nullable)(nullUnion([FormattingStruct, (0, import_superstruct3.string)()])))
|
|
196
211
|
});
|
|
197
212
|
var TextStruct = element("Text", {
|
|
198
213
|
children: maybeArray(
|
|
199
|
-
(0,
|
|
214
|
+
(0, import_superstruct3.nullable)(nullUnion([(0, import_superstruct3.string)(), BoldStruct, ItalicStruct, LinkStruct]))
|
|
200
215
|
)
|
|
201
216
|
});
|
|
202
217
|
var RowStruct = element("Row", {
|
|
203
|
-
label: (0,
|
|
218
|
+
label: (0, import_superstruct3.string)(),
|
|
204
219
|
children: nullUnion([AddressStruct, ImageStruct, TextStruct, ValueStruct]),
|
|
205
|
-
variant: (0,
|
|
206
|
-
nullUnion([literal("default"), literal("warning"), literal("
|
|
207
|
-
)
|
|
220
|
+
variant: (0, import_superstruct3.optional)(
|
|
221
|
+
nullUnion([literal("default"), literal("warning"), literal("critical")])
|
|
222
|
+
),
|
|
223
|
+
tooltip: (0, import_superstruct3.optional)((0, import_superstruct3.string)())
|
|
208
224
|
});
|
|
209
225
|
var SpinnerStruct = element("Spinner");
|
|
210
226
|
var BoxChildStruct = nullUnion([
|
|
@@ -247,7 +263,7 @@ var JSXElementStruct = nullUnion([
|
|
|
247
263
|
ValueStruct
|
|
248
264
|
]);
|
|
249
265
|
function isJSXElement(value) {
|
|
250
|
-
return (0,
|
|
266
|
+
return (0, import_superstruct3.is)(value, JSXElementStruct);
|
|
251
267
|
}
|
|
252
268
|
function assertJSXElement(value) {
|
|
253
269
|
if (!isJSXElement(value)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/jsx/jsx-dev-runtime.ts","../../src/jsx/jsx-runtime.ts","../../src/jsx/validation.ts","../../src/internals/structs.ts","../../src/internals/jsx.ts"],"sourcesContent":["import type { JsonObject, Key, SnapComponent } from './component';\nimport { jsx } from './jsx-runtime';\nimport { assertJSXElement } from './validation';\n\n/**\n * The JSX runtime for Snaps SDK components. This function is used to render\n * Snap components into a format that can be used by the Snaps.\n *\n * This is the \"development\" version of the runtime, which includes additional\n * validation, which is otherwise handled by MetaMask. To use this runtime,\n * specify `@metamask/snaps-sdk` as import source for JSX, and use\n * `react-jsxdev` as the pragma.\n *\n * @param component - The component to render.\n * @param props - The props to pass to the component.\n * @param key - The key of the component.\n * @returns The rendered component.\n * @see https://www.typescriptlang.org/tsconfig/#jsx\n */\nexport function jsxDEV<Props extends JsonObject>(\n component: SnapComponent<Props>,\n props: Props,\n key: Key | null,\n): unknown | null {\n const element = jsx(component, props, key);\n assertJSXElement(element);\n\n return element;\n}\n","import type { JsonObject, Key, SnapComponent } from './component';\n\n/**\n * The JSX runtime for Snaps SDK components. This function is used to render\n * Snap components into a format that can be used by the Snaps.\n *\n * This is the \"production\" version of the runtime, which does not include\n * additional validation, as it is handled by MetaMask. To use this runtime,\n * specify `@metamask/snaps-sdk` as import source for JSX, and use `react-jsx`\n * as the pragma.\n *\n * @param component - The component to render.\n * @param props - The props to pass to the component.\n * @param key - The key of the component.\n * @returns The rendered component.\n * @see https://www.typescriptlang.org/tsconfig/#jsx\n */\nexport function jsx<Props extends JsonObject>(\n component: SnapComponent<Props>,\n props: Props,\n key: Key | null,\n): unknown | null {\n if (typeof component === 'string') {\n // If component is a string, it is a built-in HTML element. This is not\n // supported in Snaps, so we throw an error.\n throw new Error(\n `An HTML element (\"${String(\n component,\n )}\") was used in a Snap component, which is not supported by Snaps UI. Please use one of the supported Snap components.`,\n );\n }\n\n if (!component) {\n // If component is undefined, a JSX fragment `<>...</>` was used, which is\n // not supported in Snaps.\n throw new Error(\n 'A JSX fragment was used in a Snap component, which is not supported by Snaps UI. Please use one of the supported Snap components.',\n );\n }\n\n return component({ ...props, key });\n}\n\n/**\n * The JSX runtime for Snaps SDK components. This function is used to render\n * Snap components into a format that can be used by the Snaps.\n *\n * The `jsxs` function is used for rendering nested components.\n *\n * This is the \"production\" version of the runtime, which does not include\n * additional validation, as it is handled by MetaMask. To use this runtime,\n * specify `@metamask/snaps-sdk` as import source for JSX, and use `react-jsx`\n * as the pragma.\n *\n * @param component - The component to render.\n * @param props - The props to pass to the component.\n * @param key - The key of the component.\n * @returns The rendered component.\n * @see https://www.typescriptlang.org/tsconfig/#jsx\n */\nexport function jsxs<Props extends JsonObject>(\n component: SnapComponent<Props>,\n props: Props,\n key: Key | null,\n): unknown | null {\n return jsx(component, props, key);\n}\n","import type { NonEmptyArray } from '@metamask/utils';\nimport {\n hasProperty,\n HexChecksumAddressStruct,\n isPlainObject,\n JsonStruct,\n} from '@metamask/utils';\nimport type { Struct } from 'superstruct';\nimport {\n nonempty,\n is,\n boolean,\n optional,\n array,\n lazy,\n nullable,\n number,\n object,\n record,\n string,\n tuple,\n} from 'superstruct';\nimport type { ObjectSchema } from 'superstruct/dist/utils';\n\nimport type { Describe } from '../internals';\nimport { literal, nullUnion } from '../internals';\nimport type { EmptyObject } from '../types';\nimport type {\n GenericSnapElement,\n JsonObject,\n Key,\n MaybeArray,\n SnapElement,\n StringElement,\n} from './component';\nimport type {\n AddressElement,\n BoldElement,\n BoxElement,\n ButtonElement,\n CopyableElement,\n DividerElement,\n DropdownElement,\n OptionElement,\n FieldElement,\n FormElement,\n HeadingElement,\n ImageElement,\n InputElement,\n ItalicElement,\n JSXElement,\n LinkElement,\n RowElement,\n SpinnerElement,\n StandardFormattingElement,\n TextElement,\n ValueElement,\n} from './components';\n\n/**\n * A struct for the {@link Key} type.\n */\nexport const KeyStruct: Describe<Key> = nullUnion([string(), number()]);\n\n/**\n * A struct for the {@link StringElement} type.\n */\nexport const StringElementStruct: Describe<StringElement> = maybeArray(\n string(),\n);\n\n/**\n * A struct for the {@link GenericSnapElement} type.\n */\nexport const ElementStruct: Describe<GenericSnapElement> = object({\n type: string(),\n props: record(string(), JsonStruct),\n key: nullable(KeyStruct),\n});\n\n/**\n * A struct for the {@link NonEmptyArray} type.\n *\n * @param struct - The struct for the non-empty array type.\n * @returns The struct for the non-empty array type.\n */\nfunction nonEmptyArray<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<NonEmptyArray<Type>, any> {\n return nonempty(array(struct)) as unknown as Struct<\n NonEmptyArray<Type>,\n Schema\n >;\n}\n\n/**\n * A helper function for creating a struct for a {@link MaybeArray} type.\n *\n * @param struct - The struct for the maybe array type.\n * @returns The struct for the maybe array type.\n */\nfunction maybeArray<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<MaybeArray<Type>, any> {\n return nullUnion([struct, nonEmptyArray(struct)]);\n}\n\n/**\n * A helper function for creating a struct for a JSX element.\n *\n * @param name - The name of the element.\n * @param props - The props of the element.\n * @returns The struct for the element.\n */\nfunction element<Name extends string, Props extends ObjectSchema = EmptyObject>(\n name: Name,\n props: Props = {} as Props,\n) {\n return object({\n type: literal(name) as unknown as Struct<Name, Name>,\n props: object(props),\n key: nullable(KeyStruct),\n });\n}\n\n/**\n * A struct for the {@link ButtonElement} type.\n */\nexport const ButtonStruct: Describe<ButtonElement> = element('Button', {\n children: StringElementStruct,\n name: optional(string()),\n type: optional(nullUnion([literal('button'), literal('submit')])),\n variant: optional(nullUnion([literal('primary'), literal('destructive')])),\n disabled: optional(boolean()),\n});\n\n/**\n * A struct for the {@link InputElement} type.\n */\nexport const InputStruct: Describe<InputElement> = element('Input', {\n name: string(),\n type: optional(\n nullUnion([literal('text'), literal('password'), literal('number')]),\n ),\n value: optional(string()),\n placeholder: optional(string()),\n});\n\n/**\n * A struct for the {@link OptionElement} type.\n */\nexport const OptionStruct: Describe<OptionElement> = element('Option', {\n value: string(),\n children: string(),\n});\n\n/**\n * A struct for the {@link DropdownElement} type.\n */\nexport const DropdownStruct: Describe<DropdownElement> = element('Dropdown', {\n name: string(),\n value: optional(string()),\n children: maybeArray(OptionStruct),\n});\n\n/**\n * A struct for the {@link FieldElement} type.\n */\nexport const FieldStruct: Describe<FieldElement> = element('Field', {\n label: optional(string()),\n error: optional(string()),\n children: nullUnion([\n tuple([InputStruct, ButtonStruct]),\n InputStruct,\n DropdownStruct,\n ]),\n});\n\n/**\n * A struct for the {@link FormElement} type.\n */\nexport const FormStruct: Describe<FormElement> = element('Form', {\n children: maybeArray(nullUnion([FieldStruct, ButtonStruct])),\n name: string(),\n});\n\n/**\n * A struct for the {@link BoldElement} type.\n */\nexport const BoldStruct: Describe<BoldElement> = element('Bold', {\n children: maybeArray(\n nullable(\n nullUnion([\n string(),\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n lazy(() => ItalicStruct) as unknown as Struct<\n SnapElement<JsonObject, 'Italic'>\n >,\n ]),\n ),\n ),\n});\n\n/**\n * A struct for the {@link ItalicElement} type.\n */\nexport const ItalicStruct: Describe<ItalicElement> = element('Italic', {\n children: maybeArray(\n nullable(\n nullUnion([\n string(),\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n lazy(() => BoldStruct) as unknown as Struct<\n SnapElement<JsonObject, 'Bold'>\n >,\n ]),\n ),\n ),\n});\n\nexport const FormattingStruct: Describe<StandardFormattingElement> = nullUnion([\n BoldStruct,\n ItalicStruct,\n]);\n\n/**\n * A struct for the {@link AddressElement} type.\n */\nexport const AddressStruct: Describe<AddressElement> = element('Address', {\n address: HexChecksumAddressStruct,\n});\n\n/**\n * A struct for the {@link BoxElement} type.\n */\nexport const BoxStruct: Describe<BoxElement> = element('Box', {\n children: maybeArray(\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n nullable(lazy(() => BoxChildStruct)),\n ) as unknown as Struct<MaybeArray<GenericSnapElement | null>, null>,\n direction: optional(nullUnion([literal('horizontal'), literal('vertical')])),\n alignment: optional(\n nullUnion([\n literal('start'),\n literal('center'),\n literal('end'),\n literal('space-between'),\n literal('space-around'),\n ]),\n ),\n});\n\n/**\n * A struct for the {@link CopyableElement} type.\n */\nexport const CopyableStruct: Describe<CopyableElement> = element('Copyable', {\n value: string(),\n sensitive: optional(boolean()),\n});\n\n/**\n * A struct for the {@link DividerElement} type.\n */\nexport const DividerStruct: Describe<DividerElement> = element('Divider');\n\n/**\n * A struct for the {@link ValueElement} type.\n */\nexport const ValueStruct: Describe<ValueElement> = element('Value', {\n value: string(),\n extra: string(),\n});\n\n/**\n * A struct for the {@link HeadingElement} type.\n */\nexport const HeadingStruct: Describe<HeadingElement> = element('Heading', {\n children: StringElementStruct,\n});\n\n/**\n * A struct for the {@link ImageElement} type.\n */\nexport const ImageStruct: Describe<ImageElement> = element('Image', {\n src: string(),\n alt: optional(string()),\n});\n\n/**\n * A struct for the {@link LinkElement} type.\n */\nexport const LinkStruct: Describe<LinkElement> = element('Link', {\n href: string(),\n children: maybeArray(nullable(nullUnion([FormattingStruct, string()]))),\n});\n\n/**\n * A struct for the {@link TextElement} type.\n */\nexport const TextStruct: Describe<TextElement> = element('Text', {\n children: maybeArray(\n nullable(nullUnion([string(), BoldStruct, ItalicStruct, LinkStruct])),\n ),\n});\n\n/**\n * A struct for the {@link RowElement} type.\n */\nexport const RowStruct: Describe<RowElement> = element('Row', {\n label: string(),\n children: nullUnion([AddressStruct, ImageStruct, TextStruct, ValueStruct]),\n variant: optional(\n nullUnion([literal('default'), literal('warning'), literal('error')]),\n ),\n});\n\n/**\n * A struct for the {@link SpinnerElement} type.\n */\nexport const SpinnerStruct: Describe<SpinnerElement> = element('Spinner');\n\n/**\n * A subset of JSX elements that are allowed as children of the Box component.\n * This set should include all components, except components that need to be nested\n * in another component (e.g. Field must be contained in a Form).\n */\nexport const BoxChildStruct = nullUnion([\n ButtonStruct,\n InputStruct,\n FormStruct,\n BoldStruct,\n ItalicStruct,\n AddressStruct,\n BoxStruct,\n CopyableStruct,\n DividerStruct,\n HeadingStruct,\n ImageStruct,\n LinkStruct,\n RowStruct,\n SpinnerStruct,\n TextStruct,\n DropdownStruct,\n]);\n\n/**\n * For now, the allowed JSX elements at the root are the same as the allowed\n * children of the Box component.\n */\nexport const RootJSXElementStruct = BoxChildStruct;\n\n/**\n * A struct for the {@link JSXElement} type.\n */\nexport const JSXElementStruct: Describe<JSXElement> = nullUnion([\n ButtonStruct,\n InputStruct,\n FieldStruct,\n FormStruct,\n BoldStruct,\n ItalicStruct,\n AddressStruct,\n BoxStruct,\n CopyableStruct,\n DividerStruct,\n HeadingStruct,\n ImageStruct,\n LinkStruct,\n RowStruct,\n SpinnerStruct,\n TextStruct,\n DropdownStruct,\n OptionStruct,\n ValueStruct,\n]);\n\n/**\n * Check if a value is a JSX element.\n *\n * @param value - The value to check.\n * @returns True if the value is a JSX element, false otherwise.\n */\nexport function isJSXElement(value: unknown): value is JSXElement {\n return is(value, JSXElementStruct);\n}\n\n/**\n * Check if a value is a JSX element, without validating all of its contents.\n * This is useful when you want to validate the structure of a value, but not\n * all the children.\n *\n * This should only be used when you are sure that the value is safe to use,\n * i.e., after using {@link isJSXElement}.\n *\n * @param value - The value to check.\n * @returns True if the value is a JSX element, false otherwise.\n */\nexport function isJSXElementUnsafe(value: unknown): value is JSXElement {\n return (\n isPlainObject(value) &&\n hasProperty(value, 'type') &&\n hasProperty(value, 'props') &&\n hasProperty(value, 'key')\n );\n}\n\n/**\n * Assert that a value is a JSX element.\n *\n * @param value - The value to check.\n * @throws If the value is not a JSX element.\n */\nexport function assertJSXElement(value: unknown): asserts value is JSXElement {\n // TODO: We should use the error parsing utils from `snaps-utils` to improve\n // the error messages. It currently includes colours and potentially other\n // formatting that we might not want to include in the SDK.\n if (!isJSXElement(value)) {\n throw new Error(\n `Expected a JSX element, but received ${JSON.stringify(\n value,\n )}. Please refer to the documentation for the supported JSX elements and their props.`,\n );\n }\n}\n","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","import type { Infer, Struct } from 'superstruct';\nimport type {\n AnyStruct,\n EnumSchema,\n InferStructTuple,\n IsExactMatch,\n IsMatch,\n IsRecord,\n IsTuple,\n UnionToIntersection,\n} from 'superstruct/dist/utils';\n\nimport type { EmptyObject } from '../types';\nimport { union } from './structs';\n\n/**\n * Check if a type is a union. Infers `true` if it is a union, otherwise\n * `false`.\n */\ntype IsUnion<Type> = [Type] extends [UnionToIntersection<Type>] ? false : true;\n\n/**\n * Get a struct schema for a type.\n *\n * This is copied from `superstruct` but fixes some issues with the original\n * implementation.\n */\ntype StructSchema<Type> = IsUnion<Type> extends true\n ? null\n : [Type] extends [EmptyObject]\n ? EmptyObject\n : [Type] extends [string | undefined | null]\n ? [Type] extends [`0x${string}`]\n ? null\n : [Type] extends [IsMatch<Type, string | undefined | null>]\n ? null\n : [Type] extends [IsUnion<Type>]\n ? EnumSchema<Type>\n : Type\n : [Type] extends [number | undefined | null]\n ? [Type] extends [IsMatch<Type, number | undefined | null>]\n ? null\n : [Type] extends [IsUnion<Type>]\n ? EnumSchema<Type>\n : Type\n : [Type] extends [boolean]\n ? [Type] extends [IsExactMatch<Type, boolean>]\n ? null\n : Type\n : Type extends\n | bigint\n | symbol\n | undefined\n | null\n // eslint-disable-next-line @typescript-eslint/ban-types\n | Function\n | Date\n | Error\n | RegExp\n | Map<any, any>\n | WeakMap<any, any>\n | Set<any>\n | WeakSet<any>\n | Promise<any>\n ? null\n : Type extends (infer E)[]\n ? Type extends IsTuple<Type>\n ? null\n : Struct<E>\n : Type extends object\n ? Type extends IsRecord<Type>\n ? null\n : {\n [InnerKey in keyof Type]: Describe<Type[InnerKey]>;\n }\n : null;\n\n/**\n * Describe a struct type.\n */\nexport type Describe<Type> = Struct<Type, StructSchema<Type>>;\n\n/**\n * Create a union struct that uses `null` for the schema type, for better\n * compatibility with `Describe`.\n *\n * @param structs - The structs to union.\n * @returns The `superstruct` struct, which validates that the value satisfies\n * one of the structs.\n */\nexport function nullUnion<Head extends AnyStruct, Tail extends AnyStruct[]>(\n structs: [head: Head, ...tail: Tail],\n) {\n return union(structs) as unknown as Struct<\n Infer<Head> | InferStructTuple<Tail>[number],\n null\n >;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACiBO,SAAS,IACd,WACA,OACA,KACgB;AAChB,MAAI,OAAO,cAAc,UAAU;AAGjC,UAAM,IAAI;AAAA,MACR,qBAAqB;AAAA,QACnB;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AAEA,MAAI,CAAC,WAAW;AAGd,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,UAAU,EAAE,GAAG,OAAO,IAAI,CAAC;AACpC;;;ACxCA,mBAKO;AAEP,IAAAA,sBAaO;;;ACpBP,yBAKO;AA0BA,SAAS,QAAgD,OAAa;AAC3E,aAAO;AAAA,IACL,KAAK,UAAU,KAAK;AAAA,QACpB,mBAAAC,SAAmB,KAAK,EAAE;AAAA,EAC5B;AACF;AAcO,SAAS,MAAwD;AAAA,EACtE;AAAA,EACA,GAAG;AACL,GAGE;AACA,QAAM,aAAS,mBAAAC,OAAiB,CAAC,MAAM,GAAG,IAAI,CA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C,QAAQ,SAAS,GAAG,QAAQ,SAAS,GAAG,QAAQ,OAAO,CAAC,CAAC;AAAA,EACtE;AACF,CAAC;AAKM,IAAM,gBAA0C,QAAQ,SAAS;AAOjE,IAAM,iBAAiB,UAAU;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAWM,IAAM,mBAAyC,UAAU;AAAA,EAC9D;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAQM,SAAS,aAAa,OAAqC;AAChE,aAAO,wBAAG,OAAO,gBAAgB;AACnC;AA4BO,SAAS,iBAAiB,OAA6C;AAI5E,MAAI,CAAC,aAAa,KAAK,GAAG;AACxB,UAAM,IAAI;AAAA,MACR,wCAAwC,KAAK;AAAA,QAC3C;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;;;AFpZO,SAAS,OACd,WACA,OACA,KACgB;AAChB,QAAMC,WAAU,IAAI,WAAW,OAAO,GAAG;AACzC,mBAAiBA,QAAO;AAExB,SAAOA;AACT;","names":["import_superstruct","superstructLiteral","superstructUnion","element"]}
|
|
1
|
+
{"version":3,"sources":["../../src/jsx/jsx-dev-runtime.ts","../../src/jsx/jsx-runtime.ts","../../src/jsx/validation.ts","../../src/internals/structs.ts","../../src/internals/jsx.ts","../../src/internals/svg.ts"],"sourcesContent":["import type { JsonObject, Key, SnapComponent } from './component';\nimport { jsx } from './jsx-runtime';\nimport { assertJSXElement } from './validation';\n\n/**\n * The JSX runtime for Snaps SDK components. This function is used to render\n * Snap components into a format that can be used by the Snaps.\n *\n * This is the \"development\" version of the runtime, which includes additional\n * validation, which is otherwise handled by MetaMask. To use this runtime,\n * specify `@metamask/snaps-sdk` as import source for JSX, and use\n * `react-jsxdev` as the pragma.\n *\n * @param component - The component to render.\n * @param props - The props to pass to the component.\n * @param key - The key of the component.\n * @returns The rendered component.\n * @see https://www.typescriptlang.org/tsconfig/#jsx\n */\nexport function jsxDEV<Props extends JsonObject>(\n component: SnapComponent<Props>,\n props: Props,\n key: Key | null,\n): unknown | null {\n const element = jsx(component, props, key);\n assertJSXElement(element);\n\n return element;\n}\n","import type { JsonObject, Key, SnapComponent } from './component';\n\n/**\n * The JSX runtime for Snaps SDK components. This function is used to render\n * Snap components into a format that can be used by the Snaps.\n *\n * This is the \"production\" version of the runtime, which does not include\n * additional validation, as it is handled by MetaMask. To use this runtime,\n * specify `@metamask/snaps-sdk` as import source for JSX, and use `react-jsx`\n * as the pragma.\n *\n * @param component - The component to render.\n * @param props - The props to pass to the component.\n * @param key - The key of the component.\n * @returns The rendered component.\n * @see https://www.typescriptlang.org/tsconfig/#jsx\n */\nexport function jsx<Props extends JsonObject>(\n component: SnapComponent<Props>,\n props: Props,\n key: Key | null,\n): unknown | null {\n if (typeof component === 'string') {\n // If component is a string, it is a built-in HTML element. This is not\n // supported in Snaps, so we throw an error.\n throw new Error(\n `An HTML element (\"${String(\n component,\n )}\") was used in a Snap component, which is not supported by Snaps UI. Please use one of the supported Snap components.`,\n );\n }\n\n if (!component) {\n // If component is undefined, a JSX fragment `<>...</>` was used, which is\n // not supported in Snaps.\n throw new Error(\n 'A JSX fragment was used in a Snap component, which is not supported by Snaps UI. Please use one of the supported Snap components.',\n );\n }\n\n return component({ ...props, key });\n}\n\n/**\n * The JSX runtime for Snaps SDK components. This function is used to render\n * Snap components into a format that can be used by the Snaps.\n *\n * The `jsxs` function is used for rendering nested components.\n *\n * This is the \"production\" version of the runtime, which does not include\n * additional validation, as it is handled by MetaMask. To use this runtime,\n * specify `@metamask/snaps-sdk` as import source for JSX, and use `react-jsx`\n * as the pragma.\n *\n * @param component - The component to render.\n * @param props - The props to pass to the component.\n * @param key - The key of the component.\n * @returns The rendered component.\n * @see https://www.typescriptlang.org/tsconfig/#jsx\n */\nexport function jsxs<Props extends JsonObject>(\n component: SnapComponent<Props>,\n props: Props,\n key: Key | null,\n): unknown | null {\n return jsx(component, props, key);\n}\n","import {\n hasProperty,\n HexChecksumAddressStruct,\n isPlainObject,\n JsonStruct,\n} from '@metamask/utils';\nimport type { Struct } from 'superstruct';\nimport {\n is,\n boolean,\n optional,\n array,\n lazy,\n nullable,\n number,\n object,\n record,\n string,\n tuple,\n} from 'superstruct';\nimport type { ObjectSchema } from 'superstruct/dist/utils';\n\nimport type { Describe } from '../internals';\nimport { literal, nullUnion, svg } from '../internals';\nimport type { EmptyObject } from '../types';\nimport type {\n GenericSnapElement,\n JsonObject,\n Key,\n MaybeArray,\n Nestable,\n SnapElement,\n StringElement,\n} from './component';\nimport type {\n AddressElement,\n BoldElement,\n BoxElement,\n ButtonElement,\n CopyableElement,\n DividerElement,\n DropdownElement,\n OptionElement,\n FieldElement,\n FormElement,\n HeadingElement,\n ImageElement,\n InputElement,\n ItalicElement,\n JSXElement,\n LinkElement,\n RowElement,\n SpinnerElement,\n StandardFormattingElement,\n TextElement,\n ValueElement,\n} from './components';\n\n/**\n * A struct for the {@link Key} type.\n */\nexport const KeyStruct: Describe<Key> = nullUnion([string(), number()]);\n\n/**\n * A struct for the {@link StringElement} type.\n */\nexport const StringElementStruct: Describe<StringElement> = maybeArray(\n string(),\n);\n\n/**\n * A struct for the {@link GenericSnapElement} type.\n */\nexport const ElementStruct: Describe<GenericSnapElement> = object({\n type: string(),\n props: record(string(), JsonStruct),\n key: nullable(KeyStruct),\n});\n\n/**\n * A helper function for creating a struct for a {@link Nestable} type.\n *\n * @param struct - The struct for the type to test.\n * @returns The struct for the nestable type.\n */\nfunction nestable<Type, Schema>(struct: Struct<Type, Schema>) {\n const nestableStruct: Struct<Nestable<Type>> = nullUnion([\n struct,\n array(lazy(() => nestableStruct)),\n ]);\n\n return nestableStruct;\n}\n\n/**\n * A helper function for creating a struct for a {@link MaybeArray} type.\n *\n * @param struct - The struct for the maybe array type.\n * @returns The struct for the maybe array type.\n */\nfunction maybeArray<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<MaybeArray<Type>, any> {\n return nestable(struct);\n}\n\n/**\n * A helper function for creating a struct for a JSX element.\n *\n * @param name - The name of the element.\n * @param props - The props of the element.\n * @returns The struct for the element.\n */\nfunction element<Name extends string, Props extends ObjectSchema = EmptyObject>(\n name: Name,\n props: Props = {} as Props,\n) {\n return object({\n type: literal(name) as unknown as Struct<Name, Name>,\n props: object(props),\n key: nullable(KeyStruct),\n });\n}\n\n/**\n * A struct for the {@link ButtonElement} type.\n */\nexport const ButtonStruct: Describe<ButtonElement> = element('Button', {\n children: StringElementStruct,\n name: optional(string()),\n type: optional(nullUnion([literal('button'), literal('submit')])),\n variant: optional(nullUnion([literal('primary'), literal('destructive')])),\n disabled: optional(boolean()),\n});\n\n/**\n * A struct for the {@link InputElement} type.\n */\nexport const InputStruct: Describe<InputElement> = element('Input', {\n name: string(),\n type: optional(\n nullUnion([literal('text'), literal('password'), literal('number')]),\n ),\n value: optional(string()),\n placeholder: optional(string()),\n});\n\n/**\n * A struct for the {@link OptionElement} type.\n */\nexport const OptionStruct: Describe<OptionElement> = element('Option', {\n value: string(),\n children: string(),\n});\n\n/**\n * A struct for the {@link DropdownElement} type.\n */\nexport const DropdownStruct: Describe<DropdownElement> = element('Dropdown', {\n name: string(),\n value: optional(string()),\n children: maybeArray(OptionStruct),\n});\n\n/**\n * A struct for the {@link FieldElement} type.\n */\nexport const FieldStruct: Describe<FieldElement> = element('Field', {\n label: optional(string()),\n error: optional(string()),\n children: nullUnion([\n tuple([InputStruct, ButtonStruct]),\n InputStruct,\n DropdownStruct,\n ]),\n});\n\n/**\n * A struct for the {@link FormElement} type.\n */\nexport const FormStruct: Describe<FormElement> = element('Form', {\n children: maybeArray(nullUnion([FieldStruct, ButtonStruct])),\n name: string(),\n});\n\n/**\n * A struct for the {@link BoldElement} type.\n */\nexport const BoldStruct: Describe<BoldElement> = element('Bold', {\n children: maybeArray(\n nullable(\n nullUnion([\n string(),\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n lazy(() => ItalicStruct) as unknown as Struct<\n SnapElement<JsonObject, 'Italic'>\n >,\n ]),\n ),\n ),\n});\n\n/**\n * A struct for the {@link ItalicElement} type.\n */\nexport const ItalicStruct: Describe<ItalicElement> = element('Italic', {\n children: maybeArray(\n nullable(\n nullUnion([\n string(),\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n lazy(() => BoldStruct) as unknown as Struct<\n SnapElement<JsonObject, 'Bold'>\n >,\n ]),\n ),\n ),\n});\n\nexport const FormattingStruct: Describe<StandardFormattingElement> = nullUnion([\n BoldStruct,\n ItalicStruct,\n]);\n\n/**\n * A struct for the {@link AddressElement} type.\n */\nexport const AddressStruct: Describe<AddressElement> = element('Address', {\n address: HexChecksumAddressStruct,\n});\n\n/**\n * A struct for the {@link BoxElement} type.\n */\nexport const BoxStruct: Describe<BoxElement> = element('Box', {\n children: maybeArray(\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n nullable(lazy(() => BoxChildStruct)),\n ) as unknown as Struct<MaybeArray<GenericSnapElement | null>, null>,\n direction: optional(nullUnion([literal('horizontal'), literal('vertical')])),\n alignment: optional(\n nullUnion([\n literal('start'),\n literal('center'),\n literal('end'),\n literal('space-between'),\n literal('space-around'),\n ]),\n ),\n});\n\n/**\n * A struct for the {@link CopyableElement} type.\n */\nexport const CopyableStruct: Describe<CopyableElement> = element('Copyable', {\n value: string(),\n sensitive: optional(boolean()),\n});\n\n/**\n * A struct for the {@link DividerElement} type.\n */\nexport const DividerStruct: Describe<DividerElement> = element('Divider');\n\n/**\n * A struct for the {@link ValueElement} type.\n */\nexport const ValueStruct: Describe<ValueElement> = element('Value', {\n value: string(),\n extra: string(),\n});\n\n/**\n * A struct for the {@link HeadingElement} type.\n */\nexport const HeadingStruct: Describe<HeadingElement> = element('Heading', {\n children: StringElementStruct,\n});\n\n/**\n * A struct for the {@link ImageElement} type.\n */\nexport const ImageStruct: Describe<ImageElement> = element('Image', {\n src: svg(),\n alt: optional(string()),\n});\n\n/**\n * A struct for the {@link LinkElement} type.\n */\nexport const LinkStruct: Describe<LinkElement> = element('Link', {\n href: string(),\n children: maybeArray(nullable(nullUnion([FormattingStruct, string()]))),\n});\n\n/**\n * A struct for the {@link TextElement} type.\n */\nexport const TextStruct: Describe<TextElement> = element('Text', {\n children: maybeArray(\n nullable(nullUnion([string(), BoldStruct, ItalicStruct, LinkStruct])),\n ),\n});\n\n/**\n * A struct for the {@link RowElement} type.\n */\nexport const RowStruct: Describe<RowElement> = element('Row', {\n label: string(),\n children: nullUnion([AddressStruct, ImageStruct, TextStruct, ValueStruct]),\n variant: optional(\n nullUnion([literal('default'), literal('warning'), literal('critical')]),\n ),\n tooltip: optional(string()),\n});\n\n/**\n * A struct for the {@link SpinnerElement} type.\n */\nexport const SpinnerStruct: Describe<SpinnerElement> = element('Spinner');\n\n/**\n * A subset of JSX elements that are allowed as children of the Box component.\n * This set should include all components, except components that need to be nested\n * in another component (e.g. Field must be contained in a Form).\n */\nexport const BoxChildStruct = nullUnion([\n ButtonStruct,\n InputStruct,\n FormStruct,\n BoldStruct,\n ItalicStruct,\n AddressStruct,\n BoxStruct,\n CopyableStruct,\n DividerStruct,\n HeadingStruct,\n ImageStruct,\n LinkStruct,\n RowStruct,\n SpinnerStruct,\n TextStruct,\n DropdownStruct,\n]);\n\n/**\n * For now, the allowed JSX elements at the root are the same as the allowed\n * children of the Box component.\n */\nexport const RootJSXElementStruct = BoxChildStruct;\n\n/**\n * A struct for the {@link JSXElement} type.\n */\nexport const JSXElementStruct: Describe<JSXElement> = nullUnion([\n ButtonStruct,\n InputStruct,\n FieldStruct,\n FormStruct,\n BoldStruct,\n ItalicStruct,\n AddressStruct,\n BoxStruct,\n CopyableStruct,\n DividerStruct,\n HeadingStruct,\n ImageStruct,\n LinkStruct,\n RowStruct,\n SpinnerStruct,\n TextStruct,\n DropdownStruct,\n OptionStruct,\n ValueStruct,\n]);\n\n/**\n * Check if a value is a JSX element.\n *\n * @param value - The value to check.\n * @returns True if the value is a JSX element, false otherwise.\n */\nexport function isJSXElement(value: unknown): value is JSXElement {\n return is(value, JSXElementStruct);\n}\n\n/**\n * Check if a value is a JSX element, without validating all of its contents.\n * This is useful when you want to validate the structure of a value, but not\n * all the children.\n *\n * This should only be used when you are sure that the value is safe to use,\n * i.e., after using {@link isJSXElement}.\n *\n * @param value - The value to check.\n * @returns True if the value is a JSX element, false otherwise.\n */\nexport function isJSXElementUnsafe(value: unknown): value is JSXElement {\n return (\n isPlainObject(value) &&\n hasProperty(value, 'type') &&\n hasProperty(value, 'props') &&\n hasProperty(value, 'key')\n );\n}\n\n/**\n * Assert that a value is a JSX element.\n *\n * @param value - The value to check.\n * @throws If the value is not a JSX element.\n */\nexport function assertJSXElement(value: unknown): asserts value is JSXElement {\n // TODO: We should use the error parsing utils from `snaps-utils` to improve\n // the error messages. It currently includes colours and potentially other\n // formatting that we might not want to include in the SDK.\n if (!isJSXElement(value)) {\n throw new Error(\n `Expected a JSX element, but received ${JSON.stringify(\n value,\n )}. Please refer to the documentation for the supported JSX elements and their props.`,\n );\n }\n}\n","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","import type { Infer, Struct } from 'superstruct';\nimport type {\n AnyStruct,\n EnumSchema,\n InferStructTuple,\n IsExactMatch,\n IsMatch,\n IsRecord,\n IsTuple,\n UnionToIntersection,\n} from 'superstruct/dist/utils';\n\nimport type { EmptyObject } from '../types';\nimport { union } from './structs';\n\n/**\n * Check if a type is a union. Infers `true` if it is a union, otherwise\n * `false`.\n */\ntype IsUnion<Type> = [Type] extends [UnionToIntersection<Type>] ? false : true;\n\n/**\n * Get a struct schema for a type.\n *\n * This is copied from `superstruct` but fixes some issues with the original\n * implementation.\n */\ntype StructSchema<Type> = IsUnion<Type> extends true\n ? null\n : [Type] extends [EmptyObject]\n ? EmptyObject\n : [Type] extends [string | undefined | null]\n ? [Type] extends [`0x${string}`]\n ? null\n : [Type] extends [IsMatch<Type, string | undefined | null>]\n ? null\n : [Type] extends [IsUnion<Type>]\n ? EnumSchema<Type>\n : Type\n : [Type] extends [number | undefined | null]\n ? [Type] extends [IsMatch<Type, number | undefined | null>]\n ? null\n : [Type] extends [IsUnion<Type>]\n ? EnumSchema<Type>\n : Type\n : [Type] extends [boolean]\n ? [Type] extends [IsExactMatch<Type, boolean>]\n ? null\n : Type\n : Type extends\n | bigint\n | symbol\n | undefined\n | null\n // eslint-disable-next-line @typescript-eslint/ban-types\n | Function\n | Date\n | Error\n | RegExp\n | Map<any, any>\n | WeakMap<any, any>\n | Set<any>\n | WeakSet<any>\n | Promise<any>\n ? null\n : Type extends (infer E)[]\n ? Type extends IsTuple<Type>\n ? null\n : Struct<E>\n : Type extends object\n ? Type extends IsRecord<Type>\n ? null\n : {\n [InnerKey in keyof Type]: Describe<Type[InnerKey]>;\n }\n : null;\n\n/**\n * Describe a struct type.\n */\nexport type Describe<Type> = Struct<Type, StructSchema<Type>>;\n\n/**\n * Create a union struct that uses `null` for the schema type, for better\n * compatibility with `Describe`.\n *\n * @param structs - The structs to union.\n * @returns The `superstruct` struct, which validates that the value satisfies\n * one of the structs.\n */\nexport function nullUnion<Head extends AnyStruct, Tail extends AnyStruct[]>(\n structs: [head: Head, ...tail: Tail],\n) {\n return union(structs) as unknown as Struct<\n Infer<Head> | InferStructTuple<Tail>[number],\n null\n >;\n}\n","import { refine, string } from 'superstruct';\n\n/**\n * Get a Struct that validates a string as a valid SVG.\n *\n * @returns A Struct that validates a string as a valid SVG.\n * @internal\n */\nexport function svg() {\n return refine(string(), 'SVG', (value) => {\n // This validation is intentionally very basic, we don't need to be that strict\n // and merely have this extra validation as a helpful error if devs aren't\n // passing in SVGs.\n if (!value.includes('<svg')) {\n return 'Value is not a valid SVG.';\n }\n\n return true;\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;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AA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAQM,SAAS,aAAa,OAAqC;AAChE,aAAO,wBAAG,OAAO,gBAAgB;AACnC;AA4BO,SAAS,iBAAiB,OAA6C;AAI5E,MAAI,CAAC,aAAa,KAAK,GAAG;AACxB,UAAM,IAAI;AAAA,MACR,wCAAwC,KAAK;AAAA,QAC3C;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF;AACF;;;AFpZO,SAAS,OACd,WACA,OACA,KACgB;AAChB,QAAMC,WAAU,IAAI,WAAW,OAAO,GAAG;AACzC,mBAAiBA,QAAO;AAExB,SAAOA;AACT;","names":["import_superstruct","superstructLiteral","superstructUnion","import_superstruct","element"]}
|
|
@@ -23,7 +23,6 @@ import {
|
|
|
23
23
|
JsonStruct
|
|
24
24
|
} from "@metamask/utils";
|
|
25
25
|
import {
|
|
26
|
-
nonempty,
|
|
27
26
|
is,
|
|
28
27
|
boolean,
|
|
29
28
|
optional,
|
|
@@ -33,7 +32,7 @@ import {
|
|
|
33
32
|
number,
|
|
34
33
|
object,
|
|
35
34
|
record,
|
|
36
|
-
string,
|
|
35
|
+
string as string2,
|
|
37
36
|
tuple
|
|
38
37
|
} from "superstruct";
|
|
39
38
|
|
|
@@ -66,21 +65,36 @@ function nullUnion(structs) {
|
|
|
66
65
|
return union(structs);
|
|
67
66
|
}
|
|
68
67
|
|
|
68
|
+
// src/internals/svg.ts
|
|
69
|
+
import { refine, string } from "superstruct";
|
|
70
|
+
function svg() {
|
|
71
|
+
return refine(string(), "SVG", (value) => {
|
|
72
|
+
if (!value.includes("<svg")) {
|
|
73
|
+
return "Value is not a valid SVG.";
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
69
79
|
// src/jsx/validation.ts
|
|
70
|
-
var KeyStruct = nullUnion([
|
|
80
|
+
var KeyStruct = nullUnion([string2(), number()]);
|
|
71
81
|
var StringElementStruct = maybeArray(
|
|
72
|
-
|
|
82
|
+
string2()
|
|
73
83
|
);
|
|
74
84
|
var ElementStruct = object({
|
|
75
|
-
type:
|
|
76
|
-
props: record(
|
|
85
|
+
type: string2(),
|
|
86
|
+
props: record(string2(), JsonStruct),
|
|
77
87
|
key: nullable(KeyStruct)
|
|
78
88
|
});
|
|
79
|
-
function
|
|
80
|
-
|
|
89
|
+
function nestable(struct) {
|
|
90
|
+
const nestableStruct = nullUnion([
|
|
91
|
+
struct,
|
|
92
|
+
array(lazy(() => nestableStruct))
|
|
93
|
+
]);
|
|
94
|
+
return nestableStruct;
|
|
81
95
|
}
|
|
82
96
|
function maybeArray(struct) {
|
|
83
|
-
return
|
|
97
|
+
return nestable(struct);
|
|
84
98
|
}
|
|
85
99
|
function element(name, props = {}) {
|
|
86
100
|
return object({
|
|
@@ -91,31 +105,31 @@ function element(name, props = {}) {
|
|
|
91
105
|
}
|
|
92
106
|
var ButtonStruct = element("Button", {
|
|
93
107
|
children: StringElementStruct,
|
|
94
|
-
name: optional(
|
|
108
|
+
name: optional(string2()),
|
|
95
109
|
type: optional(nullUnion([literal("button"), literal("submit")])),
|
|
96
110
|
variant: optional(nullUnion([literal("primary"), literal("destructive")])),
|
|
97
111
|
disabled: optional(boolean())
|
|
98
112
|
});
|
|
99
113
|
var InputStruct = element("Input", {
|
|
100
|
-
name:
|
|
114
|
+
name: string2(),
|
|
101
115
|
type: optional(
|
|
102
116
|
nullUnion([literal("text"), literal("password"), literal("number")])
|
|
103
117
|
),
|
|
104
|
-
value: optional(
|
|
105
|
-
placeholder: optional(
|
|
118
|
+
value: optional(string2()),
|
|
119
|
+
placeholder: optional(string2())
|
|
106
120
|
});
|
|
107
121
|
var OptionStruct = element("Option", {
|
|
108
|
-
value:
|
|
109
|
-
children:
|
|
122
|
+
value: string2(),
|
|
123
|
+
children: string2()
|
|
110
124
|
});
|
|
111
125
|
var DropdownStruct = element("Dropdown", {
|
|
112
|
-
name:
|
|
113
|
-
value: optional(
|
|
126
|
+
name: string2(),
|
|
127
|
+
value: optional(string2()),
|
|
114
128
|
children: maybeArray(OptionStruct)
|
|
115
129
|
});
|
|
116
130
|
var FieldStruct = element("Field", {
|
|
117
|
-
label: optional(
|
|
118
|
-
error: optional(
|
|
131
|
+
label: optional(string2()),
|
|
132
|
+
error: optional(string2()),
|
|
119
133
|
children: nullUnion([
|
|
120
134
|
tuple([InputStruct, ButtonStruct]),
|
|
121
135
|
InputStruct,
|
|
@@ -124,13 +138,13 @@ var FieldStruct = element("Field", {
|
|
|
124
138
|
});
|
|
125
139
|
var FormStruct = element("Form", {
|
|
126
140
|
children: maybeArray(nullUnion([FieldStruct, ButtonStruct])),
|
|
127
|
-
name:
|
|
141
|
+
name: string2()
|
|
128
142
|
});
|
|
129
143
|
var BoldStruct = element("Bold", {
|
|
130
144
|
children: maybeArray(
|
|
131
145
|
nullable(
|
|
132
146
|
nullUnion([
|
|
133
|
-
|
|
147
|
+
string2(),
|
|
134
148
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
135
149
|
lazy(() => ItalicStruct)
|
|
136
150
|
])
|
|
@@ -141,7 +155,7 @@ var ItalicStruct = element("Italic", {
|
|
|
141
155
|
children: maybeArray(
|
|
142
156
|
nullable(
|
|
143
157
|
nullUnion([
|
|
144
|
-
|
|
158
|
+
string2(),
|
|
145
159
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
146
160
|
lazy(() => BoldStruct)
|
|
147
161
|
])
|
|
@@ -172,36 +186,37 @@ var BoxStruct = element("Box", {
|
|
|
172
186
|
)
|
|
173
187
|
});
|
|
174
188
|
var CopyableStruct = element("Copyable", {
|
|
175
|
-
value:
|
|
189
|
+
value: string2(),
|
|
176
190
|
sensitive: optional(boolean())
|
|
177
191
|
});
|
|
178
192
|
var DividerStruct = element("Divider");
|
|
179
193
|
var ValueStruct = element("Value", {
|
|
180
|
-
value:
|
|
181
|
-
extra:
|
|
194
|
+
value: string2(),
|
|
195
|
+
extra: string2()
|
|
182
196
|
});
|
|
183
197
|
var HeadingStruct = element("Heading", {
|
|
184
198
|
children: StringElementStruct
|
|
185
199
|
});
|
|
186
200
|
var ImageStruct = element("Image", {
|
|
187
|
-
src:
|
|
188
|
-
alt: optional(
|
|
201
|
+
src: svg(),
|
|
202
|
+
alt: optional(string2())
|
|
189
203
|
});
|
|
190
204
|
var LinkStruct = element("Link", {
|
|
191
|
-
href:
|
|
192
|
-
children: maybeArray(nullable(nullUnion([FormattingStruct,
|
|
205
|
+
href: string2(),
|
|
206
|
+
children: maybeArray(nullable(nullUnion([FormattingStruct, string2()])))
|
|
193
207
|
});
|
|
194
208
|
var TextStruct = element("Text", {
|
|
195
209
|
children: maybeArray(
|
|
196
|
-
nullable(nullUnion([
|
|
210
|
+
nullable(nullUnion([string2(), BoldStruct, ItalicStruct, LinkStruct]))
|
|
197
211
|
)
|
|
198
212
|
});
|
|
199
213
|
var RowStruct = element("Row", {
|
|
200
|
-
label:
|
|
214
|
+
label: string2(),
|
|
201
215
|
children: nullUnion([AddressStruct, ImageStruct, TextStruct, ValueStruct]),
|
|
202
216
|
variant: optional(
|
|
203
|
-
nullUnion([literal("default"), literal("warning"), literal("
|
|
204
|
-
)
|
|
217
|
+
nullUnion([literal("default"), literal("warning"), literal("critical")])
|
|
218
|
+
),
|
|
219
|
+
tooltip: optional(string2())
|
|
205
220
|
});
|
|
206
221
|
var SpinnerStruct = element("Spinner");
|
|
207
222
|
var BoxChildStruct = nullUnion([
|