@metamask/snaps-sdk 4.2.0 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -1
- package/dist/index.js +59 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +59 -6
- package/dist/index.mjs.map +1 -1
- package/dist/jsx/index.js +99 -34
- package/dist/jsx/index.js.map +1 -1
- package/dist/jsx/index.mjs +101 -35
- package/dist/jsx/index.mjs.map +1 -1
- package/dist/jsx/jsx-dev-runtime.js +52 -4
- package/dist/jsx/jsx-dev-runtime.js.map +1 -1
- package/dist/jsx/jsx-dev-runtime.mjs +54 -5
- package/dist/jsx/jsx-dev-runtime.mjs.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/jsx/components/Box.d.ts +4 -0
- package/dist/types/jsx/components/Row.d.ts +2 -1
- package/dist/types/jsx/components/Value.d.ts +31 -0
- package/dist/types/jsx/components/form/Dropdown.d.ts +40 -0
- package/dist/types/jsx/components/form/Field.d.ts +4 -1
- package/dist/types/jsx/components/form/Option.d.ts +35 -0
- package/dist/types/jsx/components/form/index.d.ts +5 -1
- package/dist/types/jsx/components/index.d.ts +3 -1
- package/dist/types/jsx/index.d.ts +1 -1
- package/dist/types/jsx/validation.d.ts +66 -2
- package/dist/types/types/handlers/user-input.d.ts +2 -0
- package/dist/types/types/interface.d.ts +23 -1
- package/dist/types/types/methods/create-interface.d.ts +2 -1
- package/package.json +2 -2
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { MaybeArray } from '../../component';
|
|
2
|
+
import type { OptionElement } from './Option';
|
|
3
|
+
/**
|
|
4
|
+
* The props of the {@link Dropdown} component.
|
|
5
|
+
*
|
|
6
|
+
* @property name - The name of the dropdown. This is used to identify the
|
|
7
|
+
* state in the form data.
|
|
8
|
+
* @property value - The selected value of the dropdown.
|
|
9
|
+
* @property children - The children of the dropdown.
|
|
10
|
+
*/
|
|
11
|
+
declare type DropdownProps = {
|
|
12
|
+
name: string;
|
|
13
|
+
value?: string;
|
|
14
|
+
children: MaybeArray<OptionElement>;
|
|
15
|
+
};
|
|
16
|
+
/**
|
|
17
|
+
* A dropdown component, which is used to create a dropdown. This component
|
|
18
|
+
* can only be used as a child of the {@link Field} component.
|
|
19
|
+
*
|
|
20
|
+
* @param props - The props of the component.
|
|
21
|
+
* @param props.name - The name of the dropdown field. This is used to identify the
|
|
22
|
+
* state in the form data.
|
|
23
|
+
* @param props.value - The selected value of the dropdown.
|
|
24
|
+
* @param props.children - The children of the dropdown.
|
|
25
|
+
* @returns A dropdown element.
|
|
26
|
+
* @example
|
|
27
|
+
* <Dropdown name="dropdown">
|
|
28
|
+
* <Option value="option1">Option 1</Option>
|
|
29
|
+
* <Option value="option2">Option 2</Option>
|
|
30
|
+
* <Option value="option3">Option 3</Option>
|
|
31
|
+
* </Dropdown>
|
|
32
|
+
*/
|
|
33
|
+
export declare const Dropdown: import("../../component").SnapComponent<DropdownProps, "Dropdown">;
|
|
34
|
+
/**
|
|
35
|
+
* A dropdown element.
|
|
36
|
+
*
|
|
37
|
+
* @see Dropdown
|
|
38
|
+
*/
|
|
39
|
+
export declare type DropdownElement = ReturnType<typeof Dropdown>;
|
|
40
|
+
export {};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ButtonElement } from './Button';
|
|
2
|
+
import type { DropdownElement } from './Dropdown';
|
|
1
3
|
import type { InputElement } from './Input';
|
|
2
4
|
/**
|
|
3
5
|
* The props of the {@link Field} component.
|
|
@@ -9,7 +11,7 @@ import type { InputElement } from './Input';
|
|
|
9
11
|
export declare type FieldProps = {
|
|
10
12
|
label?: string | undefined;
|
|
11
13
|
error?: string | undefined;
|
|
12
|
-
children: InputElement;
|
|
14
|
+
children: [InputElement, ButtonElement] | InputElement | DropdownElement;
|
|
13
15
|
};
|
|
14
16
|
/**
|
|
15
17
|
* A field component, which is used to create a form field. This component can
|
|
@@ -23,6 +25,7 @@ export declare type FieldProps = {
|
|
|
23
25
|
* @example
|
|
24
26
|
* <Field label="Username">
|
|
25
27
|
* <Input name="username" type="text" />
|
|
28
|
+
* <Button type="submit">Submit</Button>
|
|
26
29
|
* </Field>
|
|
27
30
|
*/
|
|
28
31
|
export declare const Field: import("../../component").SnapComponent<FieldProps, "Field">;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The props of the {@link Option} component.
|
|
3
|
+
*
|
|
4
|
+
* @property value - The value of the dropdown option. This is used to populate the
|
|
5
|
+
* state in the form data.
|
|
6
|
+
* @property children - The text to display.
|
|
7
|
+
*/
|
|
8
|
+
declare type OptionProps = {
|
|
9
|
+
value: string;
|
|
10
|
+
children: string;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* A dropdown option component, which is used to create a dropdown option. This component
|
|
14
|
+
* can only be used as a child of the {@link Dropdown} component.
|
|
15
|
+
*
|
|
16
|
+
* @param props - The props of the component.
|
|
17
|
+
* @param props.value - The value of the dropdown option. This is used to populate the
|
|
18
|
+
* state in the form data.
|
|
19
|
+
* @param props.children - The text to display.
|
|
20
|
+
* @returns A dropdown option element.
|
|
21
|
+
* @example
|
|
22
|
+
* <Dropdown name="dropdown">
|
|
23
|
+
* <Option value="option1">Option 1</Option>
|
|
24
|
+
* <Option value="option2">Option 2</Option>
|
|
25
|
+
* <Option value="option3">Option 3</Option>
|
|
26
|
+
* </Dropdown>
|
|
27
|
+
*/
|
|
28
|
+
export declare const Option: import("../../component").SnapComponent<OptionProps, "Option">;
|
|
29
|
+
/**
|
|
30
|
+
* A dropdown option element.
|
|
31
|
+
*
|
|
32
|
+
* @see Option
|
|
33
|
+
*/
|
|
34
|
+
export declare type OptionElement = ReturnType<typeof Option>;
|
|
35
|
+
export {};
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import type { ButtonElement } from './Button';
|
|
2
|
+
import type { DropdownElement } from './Dropdown';
|
|
2
3
|
import type { FieldElement } from './Field';
|
|
3
4
|
import type { FormElement } from './Form';
|
|
4
5
|
import type { InputElement } from './Input';
|
|
6
|
+
import type { OptionElement } from './Option';
|
|
5
7
|
export * from './Button';
|
|
8
|
+
export * from './Dropdown';
|
|
9
|
+
export * from './Option';
|
|
6
10
|
export * from './Field';
|
|
7
11
|
export * from './Form';
|
|
8
12
|
export * from './Input';
|
|
9
|
-
export declare type StandardFormElement = ButtonElement | FormElement | FieldElement | InputElement;
|
|
13
|
+
export declare type StandardFormElement = ButtonElement | FormElement | FieldElement | InputElement | DropdownElement | OptionElement;
|
|
@@ -10,12 +10,14 @@ import type { LinkElement } from './Link';
|
|
|
10
10
|
import type { RowElement } from './Row';
|
|
11
11
|
import type { SpinnerElement } from './Spinner';
|
|
12
12
|
import type { TextElement } from './Text';
|
|
13
|
+
import type { ValueElement } from './Value';
|
|
13
14
|
export * from './form';
|
|
14
15
|
export * from './formatting';
|
|
15
16
|
export * from './Address';
|
|
16
17
|
export * from './Box';
|
|
17
18
|
export * from './Copyable';
|
|
18
19
|
export * from './Divider';
|
|
20
|
+
export * from './Value';
|
|
19
21
|
export * from './Heading';
|
|
20
22
|
export * from './Image';
|
|
21
23
|
export * from './Link';
|
|
@@ -25,4 +27,4 @@ export * from './Text';
|
|
|
25
27
|
/**
|
|
26
28
|
* A built-in JSX element, which can be used in a Snap user interface.
|
|
27
29
|
*/
|
|
28
|
-
export declare type JSXElement = StandardFormElement | StandardFormattingElement | AddressElement | BoxElement | CopyableElement | DividerElement | HeadingElement | ImageElement | LinkElement | RowElement | SpinnerElement | TextElement;
|
|
30
|
+
export declare type JSXElement = StandardFormElement | StandardFormattingElement | AddressElement | BoxElement | CopyableElement | DividerElement | ValueElement | HeadingElement | ImageElement | LinkElement | RowElement | SpinnerElement | TextElement;
|
|
@@ -2,4 +2,4 @@ export * from './component';
|
|
|
2
2
|
export * from './components';
|
|
3
3
|
export * from './jsx-runtime';
|
|
4
4
|
export * from './jsx-dev-runtime';
|
|
5
|
-
export { JSXElementStruct, isJSXElement, isJSXElementUnsafe, assertJSXElement, } from './validation';
|
|
5
|
+
export { JSXElementStruct, RootJSXElementStruct, isJSXElement, isJSXElementUnsafe, assertJSXElement, } from './validation';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { Struct } from 'superstruct';
|
|
1
2
|
import type { Describe } from '../internals';
|
|
2
|
-
import type { GenericSnapElement, Key, StringElement } from './component';
|
|
3
|
-
import type { AddressElement, BoldElement, BoxElement, ButtonElement, CopyableElement, DividerElement, FieldElement, FormElement, HeadingElement, ImageElement, InputElement, ItalicElement, JSXElement, LinkElement, RowElement, SpinnerElement, StandardFormattingElement, TextElement } from './components';
|
|
3
|
+
import type { GenericSnapElement, Key, MaybeArray, SnapElement, StringElement } from './component';
|
|
4
|
+
import type { AddressElement, BoldElement, BoxElement, ButtonElement, CopyableElement, DividerElement, DropdownElement, OptionElement, FieldElement, FormElement, HeadingElement, ImageElement, InputElement, ItalicElement, JSXElement, LinkElement, RowElement, SpinnerElement, StandardFormattingElement, TextElement, ValueElement } from './components';
|
|
4
5
|
/**
|
|
5
6
|
* A struct for the {@link Key} type.
|
|
6
7
|
*/
|
|
@@ -21,6 +22,14 @@ export declare const ButtonStruct: Describe<ButtonElement>;
|
|
|
21
22
|
* A struct for the {@link InputElement} type.
|
|
22
23
|
*/
|
|
23
24
|
export declare const InputStruct: Describe<InputElement>;
|
|
25
|
+
/**
|
|
26
|
+
* A struct for the {@link OptionElement} type.
|
|
27
|
+
*/
|
|
28
|
+
export declare const OptionStruct: Describe<OptionElement>;
|
|
29
|
+
/**
|
|
30
|
+
* A struct for the {@link DropdownElement} type.
|
|
31
|
+
*/
|
|
32
|
+
export declare const DropdownStruct: Describe<DropdownElement>;
|
|
24
33
|
/**
|
|
25
34
|
* A struct for the {@link FieldElement} type.
|
|
26
35
|
*/
|
|
@@ -54,6 +63,10 @@ export declare const CopyableStruct: Describe<CopyableElement>;
|
|
|
54
63
|
* A struct for the {@link DividerElement} type.
|
|
55
64
|
*/
|
|
56
65
|
export declare const DividerStruct: Describe<DividerElement>;
|
|
66
|
+
/**
|
|
67
|
+
* A struct for the {@link ValueElement} type.
|
|
68
|
+
*/
|
|
69
|
+
export declare const ValueStruct: Describe<ValueElement>;
|
|
57
70
|
/**
|
|
58
71
|
* A struct for the {@link HeadingElement} type.
|
|
59
72
|
*/
|
|
@@ -78,6 +91,57 @@ export declare const RowStruct: Describe<RowElement>;
|
|
|
78
91
|
* A struct for the {@link SpinnerElement} type.
|
|
79
92
|
*/
|
|
80
93
|
export declare const SpinnerStruct: Describe<SpinnerElement>;
|
|
94
|
+
/**
|
|
95
|
+
* A subset of JSX elements that are allowed as children of the Box component.
|
|
96
|
+
* This set should include all components, except components that need to be nested
|
|
97
|
+
* in another component (e.g. Field must be contained in a Form).
|
|
98
|
+
*/
|
|
99
|
+
export declare const BoxChildStruct: Struct<SnapElement<import("./components").AddressProps, "Address"> | SnapElement<import("./components").BoxProps, "Box"> | SnapElement<import("./components").CopyableProps, "Copyable"> | SnapElement<Record<string, never>, "Divider"> | SnapElement<import("./components").ButtonProps, "Button"> | SnapElement<{
|
|
100
|
+
name: string;
|
|
101
|
+
value?: string | undefined;
|
|
102
|
+
children: MaybeArray<SnapElement<{
|
|
103
|
+
value: string;
|
|
104
|
+
children: string;
|
|
105
|
+
}, "Option">>;
|
|
106
|
+
}, "Dropdown"> | SnapElement<{
|
|
107
|
+
name: string;
|
|
108
|
+
type?: "number" | "text" | "password" | undefined;
|
|
109
|
+
value?: string | undefined;
|
|
110
|
+
placeholder?: string | undefined;
|
|
111
|
+
}, "Input"> | SnapElement<{
|
|
112
|
+
children: MaybeArray<SnapElement<import("./components").ButtonProps, "Button"> | SnapElement<import("./components").FieldProps, "Field">>;
|
|
113
|
+
name: string;
|
|
114
|
+
}, "Form"> | SnapElement<import("./components").BoldProps, "Bold"> | SnapElement<import("./components").ItalicProps, "Italic"> | SnapElement<import("./components").LinkProps, "Link"> | SnapElement<import("./components").TextProps, "Text"> | SnapElement<{
|
|
115
|
+
children: StringElement;
|
|
116
|
+
}, "Heading"> | SnapElement<{
|
|
117
|
+
src: string;
|
|
118
|
+
alt?: string | undefined;
|
|
119
|
+
}, "Image"> | SnapElement<import("./components").RowProps, "Row"> | SnapElement<Record<string, never>, "Spinner">, null>;
|
|
120
|
+
/**
|
|
121
|
+
* For now, the allowed JSX elements at the root are the same as the allowed
|
|
122
|
+
* children of the Box component.
|
|
123
|
+
*/
|
|
124
|
+
export declare const RootJSXElementStruct: Struct<SnapElement<import("./components").AddressProps, "Address"> | SnapElement<import("./components").BoxProps, "Box"> | SnapElement<import("./components").CopyableProps, "Copyable"> | SnapElement<Record<string, never>, "Divider"> | SnapElement<import("./components").ButtonProps, "Button"> | SnapElement<{
|
|
125
|
+
name: string;
|
|
126
|
+
value?: string | undefined;
|
|
127
|
+
children: MaybeArray<SnapElement<{
|
|
128
|
+
value: string;
|
|
129
|
+
children: string;
|
|
130
|
+
}, "Option">>;
|
|
131
|
+
}, "Dropdown"> | SnapElement<{
|
|
132
|
+
name: string;
|
|
133
|
+
type?: "number" | "text" | "password" | undefined;
|
|
134
|
+
value?: string | undefined;
|
|
135
|
+
placeholder?: string | undefined;
|
|
136
|
+
}, "Input"> | SnapElement<{
|
|
137
|
+
children: MaybeArray<SnapElement<import("./components").ButtonProps, "Button"> | SnapElement<import("./components").FieldProps, "Field">>;
|
|
138
|
+
name: string;
|
|
139
|
+
}, "Form"> | SnapElement<import("./components").BoldProps, "Bold"> | SnapElement<import("./components").ItalicProps, "Italic"> | SnapElement<import("./components").LinkProps, "Link"> | SnapElement<import("./components").TextProps, "Text"> | SnapElement<{
|
|
140
|
+
children: StringElement;
|
|
141
|
+
}, "Heading"> | SnapElement<{
|
|
142
|
+
src: string;
|
|
143
|
+
alt?: string | undefined;
|
|
144
|
+
}, "Image"> | SnapElement<import("./components").RowProps, "Row"> | SnapElement<Record<string, never>, "Spinner">, null>;
|
|
81
145
|
/**
|
|
82
146
|
* A struct for the {@link JSXElement} type.
|
|
83
147
|
*/
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Infer } from 'superstruct';
|
|
2
|
+
import type { InterfaceContext } from '../interface';
|
|
2
3
|
/**
|
|
3
4
|
* The type of user input event fired.
|
|
4
5
|
* Currently only three events are supported:
|
|
@@ -75,4 +76,5 @@ export declare type UserInputEvent = Infer<typeof UserInputEventStruct>;
|
|
|
75
76
|
export declare type OnUserInputHandler = (args: {
|
|
76
77
|
id: string;
|
|
77
78
|
event: UserInputEvent;
|
|
79
|
+
context: InterfaceContext | null;
|
|
78
80
|
}) => Promise<void>;
|
|
@@ -11,7 +11,27 @@ export declare const InterfaceStateStruct: import("superstruct").Struct<Record<s
|
|
|
11
11
|
export declare type FormState = Infer<typeof FormStateStruct>;
|
|
12
12
|
export declare type InterfaceState = Infer<typeof InterfaceStateStruct>;
|
|
13
13
|
export declare type ComponentOrElement = Component | JSXElement;
|
|
14
|
-
export declare const ComponentOrElementStruct: import("superstruct").Struct<
|
|
14
|
+
export declare const ComponentOrElementStruct: import("superstruct").Struct<import("@metamask/snaps-sdk/jsx-runtime").SnapElement<import("@metamask/snaps-sdk/jsx-runtime").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<import("@metamask/snaps-sdk/jsx-runtime").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<import("@metamask/snaps-sdk/jsx-runtime").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<import("@metamask/snaps-sdk/jsx-runtime").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<{
|
|
15
|
+
name: string;
|
|
16
|
+
value?: string | undefined;
|
|
17
|
+
children: import("@metamask/snaps-sdk/jsx-runtime").MaybeArray<import("@metamask/snaps-sdk/jsx-runtime").SnapElement<{
|
|
18
|
+
value: string;
|
|
19
|
+
children: string;
|
|
20
|
+
}, "Option">>;
|
|
21
|
+
}, "Dropdown"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<{
|
|
22
|
+
name: string;
|
|
23
|
+
type?: "number" | "text" | "password" | undefined;
|
|
24
|
+
value?: string | undefined;
|
|
25
|
+
placeholder?: string | undefined;
|
|
26
|
+
}, "Input"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<{
|
|
27
|
+
children: import("@metamask/snaps-sdk/jsx-runtime").MaybeArray<import("@metamask/snaps-sdk/jsx-runtime").SnapElement<import("@metamask/snaps-sdk/jsx-runtime").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<import("@metamask/snaps-sdk/jsx-runtime").FieldProps, "Field">>;
|
|
28
|
+
name: string;
|
|
29
|
+
}, "Form"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<import("@metamask/snaps-sdk/jsx-runtime").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<import("@metamask/snaps-sdk/jsx-runtime").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<import("@metamask/snaps-sdk/jsx-runtime").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<import("@metamask/snaps-sdk/jsx-runtime").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<{
|
|
30
|
+
children: import("@metamask/snaps-sdk/jsx-runtime").StringElement;
|
|
31
|
+
}, "Heading"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<{
|
|
32
|
+
src: string;
|
|
33
|
+
alt?: string | undefined;
|
|
34
|
+
}, "Image"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<import("@metamask/snaps-sdk/jsx-runtime").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx-runtime").SnapElement<Record<string, never>, "Spinner"> | {
|
|
15
35
|
value: string;
|
|
16
36
|
type: import("../ui").NodeType.Copyable;
|
|
17
37
|
sensitive?: boolean | undefined;
|
|
@@ -80,3 +100,5 @@ export declare const ComponentOrElementStruct: import("superstruct").Struct<JSXE
|
|
|
80
100
|
buttonType?: "button" | "submit" | undefined;
|
|
81
101
|
})[];
|
|
82
102
|
}, null>;
|
|
103
|
+
export declare const InterfaceContextStruct: import("superstruct").Struct<Record<string, import("@metamask/utils").Json>, null>;
|
|
104
|
+
export declare type InterfaceContext = Infer<typeof InterfaceContextStruct>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ComponentOrElement } from '..';
|
|
1
|
+
import type { ComponentOrElement, InterfaceContext } from '..';
|
|
2
2
|
/**
|
|
3
3
|
* The request parameters for the `snap_createInterface` method.
|
|
4
4
|
*
|
|
@@ -6,6 +6,7 @@ import type { ComponentOrElement } from '..';
|
|
|
6
6
|
*/
|
|
7
7
|
export declare type CreateInterfaceParams = {
|
|
8
8
|
ui: ComponentOrElement;
|
|
9
|
+
context?: InterfaceContext;
|
|
9
10
|
};
|
|
10
11
|
/**
|
|
11
12
|
* The result returned by the `snap_createInterface` method, which is the id of the created interface.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-sdk",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/MetaMask/snaps.git"
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"superstruct": "^1.0.3"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@lavamoat/allow-scripts": "^3.0.
|
|
70
|
+
"@lavamoat/allow-scripts": "^3.0.4",
|
|
71
71
|
"@metamask/auto-changelog": "^3.4.4",
|
|
72
72
|
"@metamask/eslint-config": "^12.1.0",
|
|
73
73
|
"@metamask/eslint-config-jest": "^12.1.0",
|