@metamask/snaps-sdk 6.0.0 → 6.1.1
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 +28 -1
- package/dist/index.js +138 -60
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +170 -57
- package/dist/index.mjs.map +1 -1
- package/dist/jsx/index.js +143 -47
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +149 -52
- package/dist/jsx/index.mjs.map +1 -1
- package/dist/jsx/jsx-dev-runtime.js +104 -25
- package/dist/jsx/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx/jsx-dev-runtime.mjs +110 -30
- package/dist/jsx/jsx-dev-runtime.mjs.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/internals/jsx.d.ts +1 -2
- package/dist/types/internals/structs.d.ts +12 -3
- package/dist/types/internals/svg.d.ts +1 -1
- package/dist/types/jsx/components/Card.d.ts +36 -0
- package/dist/types/jsx/components/Container.d.ts +34 -0
- package/dist/types/jsx/components/Footer.d.ts +28 -0
- package/dist/types/jsx/components/index.d.ts +7 -1
- package/dist/types/jsx/index.d.ts +1 -1
- package/dist/types/jsx/validation.d.ts +37 -5
- package/dist/types/types/handlers/user-input.d.ts +29 -29
- package/dist/types/types/interface.d.ts +7 -7
- package/dist/types/types/methods/dialog.d.ts +8 -2
- package/dist/types/types/methods/index.d.ts +1 -0
- package/dist/types/types/methods/methods.d.ts +2 -0
- package/dist/types/types/methods/resolve-interface.d.ts +15 -0
- package/dist/types/ui/builder.d.ts +1 -1
- package/dist/types/ui/components/address.d.ts +4 -4
- package/dist/types/ui/components/button.d.ts +7 -7
- package/dist/types/ui/components/copyable.d.ts +5 -5
- package/dist/types/ui/components/divider.d.ts +3 -3
- package/dist/types/ui/components/form.d.ts +7 -7
- package/dist/types/ui/components/heading.d.ts +4 -4
- package/dist/types/ui/components/image.d.ts +4 -4
- package/dist/types/ui/components/input.d.ts +9 -9
- package/dist/types/ui/components/panel.d.ts +1 -1
- package/dist/types/ui/components/row.d.ts +6 -6
- package/dist/types/ui/components/spinner.d.ts +3 -3
- package/dist/types/ui/components/text.d.ts +5 -5
- package/dist/types/ui/nodes.d.ts +6 -6
- package/package.json +6 -6
package/dist/jsx/index.mjs
CHANGED
|
@@ -63,45 +63,57 @@ var Address = createSnapComponent(TYPE11);
|
|
|
63
63
|
var TYPE12 = "Box";
|
|
64
64
|
var Box = createSnapComponent(TYPE12);
|
|
65
65
|
|
|
66
|
+
// src/jsx/components/Card.ts
|
|
67
|
+
var TYPE13 = "Card";
|
|
68
|
+
var Card = createSnapComponent(TYPE13);
|
|
69
|
+
|
|
66
70
|
// src/jsx/components/Copyable.ts
|
|
67
|
-
var
|
|
68
|
-
var Copyable = createSnapComponent(
|
|
71
|
+
var TYPE14 = "Copyable";
|
|
72
|
+
var Copyable = createSnapComponent(TYPE14);
|
|
69
73
|
|
|
70
74
|
// src/jsx/components/Divider.ts
|
|
71
|
-
var
|
|
72
|
-
var Divider = createSnapComponent(
|
|
75
|
+
var TYPE15 = "Divider";
|
|
76
|
+
var Divider = createSnapComponent(TYPE15);
|
|
73
77
|
|
|
74
78
|
// src/jsx/components/Value.ts
|
|
75
|
-
var
|
|
76
|
-
var Value = createSnapComponent(
|
|
79
|
+
var TYPE16 = "Value";
|
|
80
|
+
var Value = createSnapComponent(TYPE16);
|
|
77
81
|
|
|
78
82
|
// src/jsx/components/Heading.ts
|
|
79
|
-
var
|
|
80
|
-
var Heading = createSnapComponent(
|
|
83
|
+
var TYPE17 = "Heading";
|
|
84
|
+
var Heading = createSnapComponent(TYPE17);
|
|
81
85
|
|
|
82
86
|
// src/jsx/components/Image.ts
|
|
83
|
-
var
|
|
84
|
-
var Image = createSnapComponent(
|
|
87
|
+
var TYPE18 = "Image";
|
|
88
|
+
var Image = createSnapComponent(TYPE18);
|
|
85
89
|
|
|
86
90
|
// src/jsx/components/Link.ts
|
|
87
|
-
var
|
|
88
|
-
var Link = createSnapComponent(
|
|
91
|
+
var TYPE19 = "Link";
|
|
92
|
+
var Link = createSnapComponent(TYPE19);
|
|
89
93
|
|
|
90
94
|
// src/jsx/components/Row.ts
|
|
91
|
-
var
|
|
92
|
-
var Row = createSnapComponent(
|
|
95
|
+
var TYPE20 = "Row";
|
|
96
|
+
var Row = createSnapComponent(TYPE20);
|
|
93
97
|
|
|
94
98
|
// src/jsx/components/Spinner.ts
|
|
95
|
-
var
|
|
96
|
-
var Spinner = createSnapComponent(
|
|
99
|
+
var TYPE21 = "Spinner";
|
|
100
|
+
var Spinner = createSnapComponent(TYPE21);
|
|
97
101
|
|
|
98
102
|
// src/jsx/components/Text.ts
|
|
99
|
-
var
|
|
100
|
-
var Text = createSnapComponent(
|
|
103
|
+
var TYPE22 = "Text";
|
|
104
|
+
var Text = createSnapComponent(TYPE22);
|
|
101
105
|
|
|
102
106
|
// src/jsx/components/Tooltip.ts
|
|
103
|
-
var
|
|
104
|
-
var Tooltip = createSnapComponent(
|
|
107
|
+
var TYPE23 = "Tooltip";
|
|
108
|
+
var Tooltip = createSnapComponent(TYPE23);
|
|
109
|
+
|
|
110
|
+
// src/jsx/components/Footer.ts
|
|
111
|
+
var TYPE24 = "Footer";
|
|
112
|
+
var Footer = createSnapComponent(TYPE24);
|
|
113
|
+
|
|
114
|
+
// src/jsx/components/Container.ts
|
|
115
|
+
var TYPE25 = "Container";
|
|
116
|
+
var Container = createSnapComponent(TYPE25);
|
|
105
117
|
|
|
106
118
|
// src/jsx/jsx-runtime.ts
|
|
107
119
|
function jsx(component, props, key) {
|
|
@@ -125,13 +137,7 @@ function jsxs(component, props, key) {
|
|
|
125
137
|
|
|
126
138
|
// src/jsx/validation.ts
|
|
127
139
|
import {
|
|
128
|
-
|
|
129
|
-
HexChecksumAddressStruct,
|
|
130
|
-
isPlainObject,
|
|
131
|
-
JsonStruct
|
|
132
|
-
} from "@metamask/utils";
|
|
133
|
-
import {
|
|
134
|
-
is,
|
|
140
|
+
is as is2,
|
|
135
141
|
boolean,
|
|
136
142
|
optional,
|
|
137
143
|
array,
|
|
@@ -142,15 +148,23 @@ import {
|
|
|
142
148
|
record,
|
|
143
149
|
string as string2,
|
|
144
150
|
tuple
|
|
145
|
-
} from "superstruct";
|
|
151
|
+
} from "@metamask/superstruct";
|
|
152
|
+
import {
|
|
153
|
+
hasProperty as hasProperty2,
|
|
154
|
+
HexChecksumAddressStruct,
|
|
155
|
+
isPlainObject as isPlainObject2,
|
|
156
|
+
JsonStruct
|
|
157
|
+
} from "@metamask/utils";
|
|
146
158
|
|
|
147
159
|
// src/internals/structs.ts
|
|
148
160
|
import {
|
|
149
161
|
Struct,
|
|
150
162
|
define,
|
|
163
|
+
is,
|
|
151
164
|
literal as superstructLiteral,
|
|
152
165
|
union as superstructUnion
|
|
153
|
-
} from "superstruct";
|
|
166
|
+
} from "@metamask/superstruct";
|
|
167
|
+
import { hasProperty, isPlainObject } from "@metamask/utils";
|
|
154
168
|
function literal(value) {
|
|
155
169
|
return define(
|
|
156
170
|
JSON.stringify(value),
|
|
@@ -167,6 +181,41 @@ function union([
|
|
|
167
181
|
schema: [head, ...tail]
|
|
168
182
|
});
|
|
169
183
|
}
|
|
184
|
+
function typedUnion(structs) {
|
|
185
|
+
return new Struct({
|
|
186
|
+
type: "union",
|
|
187
|
+
schema: null,
|
|
188
|
+
*entries(value, context) {
|
|
189
|
+
if (!isPlainObject(value) || !hasProperty(value, "type")) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const { type } = value;
|
|
193
|
+
const struct = structs.find(({ schema }) => is(type, schema.type));
|
|
194
|
+
if (!struct) {
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
for (const entry of struct.entries(value, context)) {
|
|
198
|
+
yield entry;
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
validator(value, context) {
|
|
202
|
+
const types = structs.map(({ schema }) => schema.type.type);
|
|
203
|
+
if (!isPlainObject(value) || !hasProperty(value, "type") || typeof value.type !== "string") {
|
|
204
|
+
return `Expected type to be one of: ${types.join(
|
|
205
|
+
", "
|
|
206
|
+
)}, but received: undefined`;
|
|
207
|
+
}
|
|
208
|
+
const { type } = value;
|
|
209
|
+
const struct = structs.find(({ schema }) => is(type, schema.type));
|
|
210
|
+
if (struct) {
|
|
211
|
+
return struct.validator(value, context);
|
|
212
|
+
}
|
|
213
|
+
return `Expected type to be one of: ${types.join(
|
|
214
|
+
", "
|
|
215
|
+
)}, but received: "${type}"`;
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
170
219
|
|
|
171
220
|
// src/internals/jsx.ts
|
|
172
221
|
function nullUnion(structs) {
|
|
@@ -174,7 +223,7 @@ function nullUnion(structs) {
|
|
|
174
223
|
}
|
|
175
224
|
|
|
176
225
|
// src/internals/svg.ts
|
|
177
|
-
import { refine, string } from "superstruct";
|
|
226
|
+
import { refine, string } from "@metamask/superstruct";
|
|
178
227
|
function svg() {
|
|
179
228
|
return refine(string(), "SVG", (value) => {
|
|
180
229
|
if (!value.includes("<svg")) {
|
|
@@ -249,22 +298,32 @@ var FileInputStruct = element(
|
|
|
249
298
|
compact: optional(boolean())
|
|
250
299
|
}
|
|
251
300
|
);
|
|
301
|
+
var BUTTON_INPUT = [InputStruct, ButtonStruct];
|
|
302
|
+
var FIELD_CHILDREN_ARRAY = [
|
|
303
|
+
InputStruct,
|
|
304
|
+
DropdownStruct,
|
|
305
|
+
FileInputStruct,
|
|
306
|
+
CheckboxStruct
|
|
307
|
+
];
|
|
308
|
+
var FieldChildUnionStruct = nullUnion([
|
|
309
|
+
...FIELD_CHILDREN_ARRAY,
|
|
310
|
+
...BUTTON_INPUT
|
|
311
|
+
]);
|
|
312
|
+
var FieldChildStruct = nullUnion([
|
|
313
|
+
tuple(BUTTON_INPUT),
|
|
314
|
+
...FIELD_CHILDREN_ARRAY
|
|
315
|
+
]);
|
|
252
316
|
var FieldStruct = element("Field", {
|
|
253
317
|
label: optional(string2()),
|
|
254
318
|
error: optional(string2()),
|
|
255
|
-
children:
|
|
256
|
-
tuple([InputStruct, ButtonStruct]),
|
|
257
|
-
DropdownStruct,
|
|
258
|
-
FileInputStruct,
|
|
259
|
-
InputStruct,
|
|
260
|
-
CheckboxStruct
|
|
261
|
-
])
|
|
319
|
+
children: FieldChildStruct
|
|
262
320
|
});
|
|
321
|
+
var FormChildStruct = children(
|
|
322
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
323
|
+
[FieldStruct, lazy(() => BoxChildStruct)]
|
|
324
|
+
);
|
|
263
325
|
var FormStruct = element("Form", {
|
|
264
|
-
children:
|
|
265
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
266
|
-
[FieldStruct, lazy(() => BoxChildStruct)]
|
|
267
|
-
),
|
|
326
|
+
children: FormChildStruct,
|
|
268
327
|
name: string2()
|
|
269
328
|
});
|
|
270
329
|
var BoldStruct = element("Bold", {
|
|
@@ -288,11 +347,12 @@ var FormattingStruct = nullUnion([
|
|
|
288
347
|
var AddressStruct = element("Address", {
|
|
289
348
|
address: HexChecksumAddressStruct
|
|
290
349
|
});
|
|
350
|
+
var BoxChildrenStruct = children(
|
|
351
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
352
|
+
[lazy(() => BoxChildStruct)]
|
|
353
|
+
);
|
|
291
354
|
var BoxStruct = element("Box", {
|
|
292
|
-
children:
|
|
293
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
294
|
-
[lazy(() => BoxChildStruct)]
|
|
295
|
-
),
|
|
355
|
+
children: BoxChildrenStruct,
|
|
296
356
|
direction: optional(nullUnion([literal("horizontal"), literal("vertical")])),
|
|
297
357
|
alignment: optional(
|
|
298
358
|
nullUnion([
|
|
@@ -304,6 +364,23 @@ var BoxStruct = element("Box", {
|
|
|
304
364
|
])
|
|
305
365
|
)
|
|
306
366
|
});
|
|
367
|
+
var FooterChildStruct = nullUnion([
|
|
368
|
+
tuple([ButtonStruct, ButtonStruct]),
|
|
369
|
+
ButtonStruct
|
|
370
|
+
]);
|
|
371
|
+
var FooterStruct = element("Footer", {
|
|
372
|
+
children: FooterChildStruct
|
|
373
|
+
});
|
|
374
|
+
var ContainerChildStruct = nullUnion([
|
|
375
|
+
tuple([BoxStruct, FooterStruct]),
|
|
376
|
+
BoxStruct
|
|
377
|
+
]);
|
|
378
|
+
var ContainerStruct = element(
|
|
379
|
+
"Container",
|
|
380
|
+
{
|
|
381
|
+
children: ContainerChildStruct
|
|
382
|
+
}
|
|
383
|
+
);
|
|
307
384
|
var CopyableStruct = element("Copyable", {
|
|
308
385
|
value: string2(),
|
|
309
386
|
sensitive: optional(boolean())
|
|
@@ -313,6 +390,13 @@ var ValueStruct = element("Value", {
|
|
|
313
390
|
value: string2(),
|
|
314
391
|
extra: string2()
|
|
315
392
|
});
|
|
393
|
+
var CardStruct = element("Card", {
|
|
394
|
+
image: optional(string2()),
|
|
395
|
+
title: string2(),
|
|
396
|
+
description: optional(string2()),
|
|
397
|
+
value: string2(),
|
|
398
|
+
extra: optional(string2())
|
|
399
|
+
});
|
|
316
400
|
var HeadingStruct = element("Heading", {
|
|
317
401
|
children: StringElementStruct
|
|
318
402
|
});
|
|
@@ -358,7 +442,7 @@ var RowStruct = element("Row", {
|
|
|
358
442
|
tooltip: optional(string2())
|
|
359
443
|
});
|
|
360
444
|
var SpinnerStruct = element("Spinner");
|
|
361
|
-
var BoxChildStruct =
|
|
445
|
+
var BoxChildStruct = typedUnion([
|
|
362
446
|
AddressStruct,
|
|
363
447
|
BoldStruct,
|
|
364
448
|
BoxStruct,
|
|
@@ -377,10 +461,14 @@ var BoxChildStruct = nullUnion([
|
|
|
377
461
|
SpinnerStruct,
|
|
378
462
|
TextStruct,
|
|
379
463
|
TooltipStruct,
|
|
380
|
-
CheckboxStruct
|
|
464
|
+
CheckboxStruct,
|
|
465
|
+
CardStruct
|
|
381
466
|
]);
|
|
382
|
-
var RootJSXElementStruct =
|
|
383
|
-
|
|
467
|
+
var RootJSXElementStruct = nullUnion([
|
|
468
|
+
BoxChildStruct,
|
|
469
|
+
ContainerStruct
|
|
470
|
+
]);
|
|
471
|
+
var JSXElementStruct = typedUnion([
|
|
384
472
|
ButtonStruct,
|
|
385
473
|
InputStruct,
|
|
386
474
|
FileInputStruct,
|
|
@@ -402,13 +490,16 @@ var JSXElementStruct = nullUnion([
|
|
|
402
490
|
OptionStruct,
|
|
403
491
|
ValueStruct,
|
|
404
492
|
TooltipStruct,
|
|
405
|
-
CheckboxStruct
|
|
493
|
+
CheckboxStruct,
|
|
494
|
+
FooterStruct,
|
|
495
|
+
ContainerStruct,
|
|
496
|
+
CardStruct
|
|
406
497
|
]);
|
|
407
498
|
function isJSXElement(value) {
|
|
408
|
-
return
|
|
499
|
+
return is2(value, JSXElementStruct);
|
|
409
500
|
}
|
|
410
501
|
function isJSXElementUnsafe(value) {
|
|
411
|
-
return
|
|
502
|
+
return isPlainObject2(value) && hasProperty2(value, "type") && hasProperty2(value, "props") && hasProperty2(value, "key");
|
|
412
503
|
}
|
|
413
504
|
function assertJSXElement(value) {
|
|
414
505
|
if (!isJSXElement(value)) {
|
|
@@ -430,14 +521,20 @@ export {
|
|
|
430
521
|
Address,
|
|
431
522
|
Bold,
|
|
432
523
|
Box,
|
|
524
|
+
BoxChildStruct,
|
|
433
525
|
Button,
|
|
526
|
+
Card,
|
|
434
527
|
Checkbox,
|
|
528
|
+
Container,
|
|
435
529
|
Copyable,
|
|
436
530
|
Divider,
|
|
437
531
|
Dropdown,
|
|
438
532
|
Field,
|
|
533
|
+
FieldChildUnionStruct,
|
|
439
534
|
FileInput,
|
|
535
|
+
Footer,
|
|
440
536
|
Form,
|
|
537
|
+
FormChildStruct,
|
|
441
538
|
Heading,
|
|
442
539
|
Image,
|
|
443
540
|
Input,
|