@metamask/snaps-sdk 1.4.0 → 2.1.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 +22 -1
- package/dist/cjs/errors.js +8 -3
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/internals/error-wrappers.js +15 -1
- package/dist/cjs/internals/error-wrappers.js.map +1 -1
- package/dist/cjs/internals/index.js +1 -0
- package/dist/cjs/internals/index.js.map +1 -1
- package/dist/cjs/internals/svg.js +49 -0
- package/dist/cjs/internals/svg.js.map +1 -0
- package/dist/cjs/types/handlers/index.js +1 -0
- package/dist/cjs/types/handlers/index.js.map +1 -1
- package/dist/cjs/types/handlers/transaction.js.map +1 -1
- package/dist/cjs/types/handlers/user-input.js +51 -0
- package/dist/cjs/types/handlers/user-input.js.map +1 -0
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/interface.js +26 -0
- package/dist/cjs/types/interface.js.map +1 -0
- package/dist/cjs/types/methods/create-interface.js +6 -0
- package/dist/cjs/types/methods/create-interface.js.map +1 -0
- package/dist/cjs/types/methods/dialog.js.map +1 -1
- package/dist/cjs/types/methods/get-interface-state.js +6 -0
- package/dist/cjs/types/methods/get-interface-state.js.map +1 -0
- package/dist/cjs/types/methods/index.js +3 -0
- package/dist/cjs/types/methods/index.js.map +1 -1
- package/dist/cjs/types/methods/update-interface.js +6 -0
- package/dist/cjs/types/methods/update-interface.js.map +1 -0
- package/dist/cjs/ui/components/button.js +59 -0
- package/dist/cjs/ui/components/button.js.map +1 -0
- package/dist/cjs/ui/components/form.js +41 -0
- package/dist/cjs/ui/components/form.js.map +1 -0
- package/dist/cjs/ui/components/image.js +2 -7
- package/dist/cjs/ui/components/image.js.map +1 -1
- package/dist/cjs/ui/components/index.js +3 -0
- package/dist/cjs/ui/components/index.js.map +1 -1
- package/dist/cjs/ui/components/input.js +52 -0
- package/dist/cjs/ui/components/input.js.map +1 -0
- package/dist/cjs/ui/components/panel.js +7 -1
- package/dist/cjs/ui/components/panel.js.map +1 -1
- package/dist/cjs/ui/nodes.js +3 -0
- package/dist/cjs/ui/nodes.js.map +1 -1
- package/dist/esm/errors.js +8 -3
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/internals/error-wrappers.js +15 -1
- package/dist/esm/internals/error-wrappers.js.map +1 -1
- package/dist/esm/internals/index.js +1 -0
- package/dist/esm/internals/index.js.map +1 -1
- package/dist/esm/internals/svg.js +41 -0
- package/dist/esm/internals/svg.js.map +1 -0
- package/dist/esm/types/handlers/home-page.js.map +1 -1
- package/dist/esm/types/handlers/index.js +1 -0
- package/dist/esm/types/handlers/index.js.map +1 -1
- package/dist/esm/types/handlers/name-lookup.js.map +1 -1
- package/dist/esm/types/handlers/signature.js.map +1 -1
- package/dist/esm/types/handlers/transaction.js.map +1 -1
- package/dist/esm/types/handlers/user-input.js +24 -0
- package/dist/esm/types/handlers/user-input.js.map +1 -0
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/types/index.js.map +1 -1
- package/dist/esm/types/interface.js +12 -0
- package/dist/esm/types/interface.js.map +1 -0
- package/dist/esm/types/methods/create-interface.js +3 -0
- package/dist/esm/types/methods/create-interface.js.map +1 -0
- package/dist/esm/types/methods/dialog.js.map +1 -1
- package/dist/esm/types/methods/get-interface-state.js +3 -0
- package/dist/esm/types/methods/get-interface-state.js.map +1 -0
- package/dist/esm/types/methods/index.js +3 -0
- package/dist/esm/types/methods/index.js.map +1 -1
- package/dist/esm/types/methods/methods.js.map +1 -1
- package/dist/esm/types/methods/update-interface.js +3 -0
- package/dist/esm/types/methods/update-interface.js.map +1 -0
- package/dist/esm/types/permissions.js.map +1 -1
- package/dist/esm/ui/components/button.js +50 -0
- package/dist/esm/ui/components/button.js.map +1 -0
- package/dist/esm/ui/components/form.js +39 -0
- package/dist/esm/ui/components/form.js.map +1 -0
- package/dist/esm/ui/components/image.js +1 -1
- package/dist/esm/ui/components/image.js.map +1 -1
- package/dist/esm/ui/components/index.js +3 -0
- package/dist/esm/ui/components/index.js.map +1 -1
- package/dist/esm/ui/components/input.js +47 -0
- package/dist/esm/ui/components/input.js.map +1 -0
- package/dist/esm/ui/components/panel.js +7 -1
- package/dist/esm/ui/components/panel.js.map +1 -1
- package/dist/esm/ui/nodes.js +3 -0
- package/dist/esm/ui/nodes.js.map +1 -1
- package/dist/types/error-wrappers.d.ts +464 -48
- package/dist/types/errors.d.ts +2 -4
- package/dist/types/index.d.ts +1 -1
- package/dist/types/internals/error-wrappers.d.ts +29 -3
- package/dist/types/internals/index.d.ts +1 -0
- package/dist/types/internals/svg.d.ts +14 -0
- package/dist/types/types/handlers/home-page.d.ts +3 -0
- package/dist/types/types/handlers/index.d.ts +1 -0
- package/dist/types/types/handlers/name-lookup.d.ts +31 -10
- package/dist/types/types/handlers/signature.d.ts +4 -0
- package/dist/types/types/handlers/transaction.d.ts +4 -0
- package/dist/types/types/handlers/user-input.d.ts +64 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/types/interface.d.ts +10 -0
- package/dist/types/types/methods/create-interface.d.ts +13 -0
- package/dist/types/types/methods/dialog.d.ts +14 -0
- package/dist/types/types/methods/get-interface-state.d.ts +13 -0
- package/dist/types/types/methods/index.d.ts +3 -0
- package/dist/types/types/methods/methods.d.ts +6 -0
- package/dist/types/types/methods/update-interface.d.ts +15 -0
- package/dist/types/types/permissions.d.ts +39 -20
- package/dist/types/ui/components/button.d.ts +62 -0
- package/dist/types/ui/components/form.d.ts +144 -0
- package/dist/types/ui/components/index.d.ts +3 -0
- package/dist/types/ui/components/input.d.ts +69 -0
- package/dist/types/ui/components/panel.d.ts +150 -0
- package/dist/types/ui/nodes.d.ts +4 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [2.1.0]
|
|
10
|
+
### Changed
|
|
11
|
+
- Improve support for Snap errors without a message ([#2176](https://github.com/MetaMask/snaps/pull/2176))
|
|
12
|
+
- You can now add data to an error without having to specify a message. For example:
|
|
13
|
+
```ts
|
|
14
|
+
throw new MethodNotFoundError({ method: 'some method name' });
|
|
15
|
+
```
|
|
16
|
+
- Strip empty `data` from Snap errors ([#2179](https://github.com/MetaMask/snaps/pull/2179))
|
|
17
|
+
|
|
18
|
+
## [2.0.0]
|
|
19
|
+
### Changed
|
|
20
|
+
- **BREAKING:** Update name lookup API types ([#2113](https://github.com/MetaMask/snaps/pull/2113))
|
|
21
|
+
- The return value and the permission format has changed, see [SIP-12](https://metamask.github.io/SIPs/SIPS/sip-12) for more details.
|
|
22
|
+
- Add support for dynamic user interfaces ([#1465](https://github.com/MetaMask/snaps/pull/1465), [#2126](https://github.com/MetaMask/snaps/pull/2126), [#2143](https://github.com/MetaMask/snaps/pull/2143))
|
|
23
|
+
- Add support for snap defined execution timeouts ([#2098](https://github.com/MetaMask/snaps/pull/2098))
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
- Fix initial permissions types ([#2111](https://github.com/MetaMask/snaps/pull/2111))
|
|
27
|
+
|
|
9
28
|
## [1.4.0]
|
|
10
29
|
### Added
|
|
11
30
|
- Add support for signature insights ([#2074](https://github.com/MetaMask/snaps/pull/2074), [#2079](https://github.com/MetaMask/snaps/pull/2079))
|
|
@@ -45,7 +64,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
45
64
|
### Added
|
|
46
65
|
- Initial release of this package.
|
|
47
66
|
|
|
48
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@1.
|
|
67
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@2.1.0...HEAD
|
|
68
|
+
[2.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@2.0.0...@metamask/snaps-sdk@2.1.0
|
|
69
|
+
[2.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@1.4.0...@metamask/snaps-sdk@2.0.0
|
|
49
70
|
[1.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@1.3.2...@metamask/snaps-sdk@1.4.0
|
|
50
71
|
[1.3.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@1.3.1...@metamask/snaps-sdk@1.3.2
|
|
51
72
|
[1.3.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-sdk@1.3.0...@metamask/snaps-sdk@1.3.1
|
package/dist/cjs/errors.js
CHANGED
|
@@ -101,7 +101,9 @@ class SnapError extends Error {
|
|
|
101
101
|
code: this.code,
|
|
102
102
|
message: this.message,
|
|
103
103
|
stack: this.stack,
|
|
104
|
-
|
|
104
|
+
...this.data ? {
|
|
105
|
+
data: this.data
|
|
106
|
+
} : {}
|
|
105
107
|
}
|
|
106
108
|
}
|
|
107
109
|
};
|
|
@@ -146,10 +148,13 @@ class SnapError extends Error {
|
|
|
146
148
|
});
|
|
147
149
|
_class_private_field_set(this, _message, message);
|
|
148
150
|
_class_private_field_set(this, _code, (0, _internals.getErrorCode)(error));
|
|
149
|
-
|
|
151
|
+
const mergedData = {
|
|
150
152
|
...(0, _internals.getErrorData)(error),
|
|
151
153
|
...data
|
|
152
|
-
}
|
|
154
|
+
};
|
|
155
|
+
if (Object.keys(mergedData).length > 0) {
|
|
156
|
+
_class_private_field_set(this, _data, mergedData);
|
|
157
|
+
}
|
|
153
158
|
_class_private_field_set(this, _stack, super.stack);
|
|
154
159
|
}
|
|
155
160
|
}
|
package/dist/cjs/errors.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/errors.ts"],"sourcesContent":["import type { Json, JsonRpcError } from '@metamask/utils';\n\nimport {\n getErrorCode,\n getErrorData,\n getErrorMessage,\n SNAP_ERROR_CODE,\n SNAP_ERROR_MESSAGE,\n} from './internals';\n\n/**\n * A generic error which can be thrown by a Snap, without it causing the Snap to\n * crash.\n */\nexport class SnapError extends Error {\n readonly #code: number;\n\n readonly #message: string;\n\n readonly #data
|
|
1
|
+
{"version":3,"sources":["../../src/errors.ts"],"sourcesContent":["import type { Json, JsonRpcError } from '@metamask/utils';\n\nimport {\n getErrorCode,\n getErrorData,\n getErrorMessage,\n SNAP_ERROR_CODE,\n SNAP_ERROR_MESSAGE,\n} from './internals';\n\n/**\n * A generic error which can be thrown by a Snap, without it causing the Snap to\n * crash.\n */\nexport class SnapError extends Error {\n readonly #code: number;\n\n readonly #message: string;\n\n readonly #data?: Record<string, Json>;\n\n readonly #stack?: string;\n\n /**\n * Create a new `SnapError`.\n *\n * @param error - The error to create the `SnapError` from. If this is a\n * `string`, it will be used as the error message. If this is an `Error`, its\n * `message` property will be used as the error message. If this is a\n * `JsonRpcError`, its `message` property will be used as the error message\n * and its `code` property will be used as the error code. Otherwise, the\n * error will be converted to a string and used as the error message.\n * @param data - Additional data to include in the error. This will be merged\n * with the error data, if any.\n */\n constructor(\n error: string | Error | JsonRpcError,\n data: Record<string, Json> = {},\n ) {\n const message = getErrorMessage(error);\n super(message);\n\n this.#message = message;\n this.#code = getErrorCode(error);\n\n const mergedData = { ...getErrorData(error), ...data };\n if (Object.keys(mergedData).length > 0) {\n this.#data = mergedData;\n }\n\n this.#stack = super.stack;\n }\n\n /**\n * The error name.\n *\n * @returns The error name.\n */\n get name() {\n return 'SnapError';\n }\n\n /**\n * The error code.\n *\n * @returns The error code.\n */\n get code() {\n return this.#code;\n }\n\n /**\n * The error message.\n *\n * @returns The error message.\n */\n // This line is covered, but Jest doesn't pick it up for some reason.\n /* istanbul ignore next */\n get message() {\n return this.#message;\n }\n\n /**\n * Additional data for the error.\n *\n * @returns Additional data for the error.\n */\n get data() {\n return this.#data;\n }\n\n /**\n * The error stack.\n *\n * @returns The error stack.\n */\n // This line is covered, but Jest doesn't pick it up for some reason.\n /* istanbul ignore next */\n get stack() {\n return this.#stack;\n }\n\n /**\n * Convert the error to a JSON object.\n *\n * @returns The JSON object.\n */\n toJSON(): SerializedSnapError {\n return {\n code: SNAP_ERROR_CODE,\n message: SNAP_ERROR_MESSAGE,\n data: {\n cause: {\n code: this.code,\n message: this.message,\n stack: this.stack,\n ...(this.data ? { data: this.data } : {}),\n },\n },\n };\n }\n\n /**\n * Serialize the error to a JSON object. This is called by\n * `@metamask/rpc-errors` when serializing the error.\n *\n * @returns The JSON object.\n */\n serialize() {\n return this.toJSON();\n }\n}\n\n/**\n * A serialized {@link SnapError}. It's JSON-serializable, so it can be sent\n * over the RPC. The original error is wrapped in the `cause` property.\n *\n * @property code - The error code. This is always `-31002`.\n * @property message - The error message. This is always `'Snap Error'`.\n * @property data - The error data.\n * @property data.cause - The cause of the error.\n * @property data.cause.code - The error code.\n * @property data.cause.message - The error message.\n * @property data.cause.stack - The error stack.\n * @property data.cause.data - Additional data for the error.\n * @see SnapError\n */\nexport type SerializedSnapError = {\n code: typeof SNAP_ERROR_CODE;\n message: typeof SNAP_ERROR_MESSAGE;\n data: {\n cause: JsonRpcError;\n };\n};\n"],"names":["SnapError","Error","name","code","message","data","stack","toJSON","SNAP_ERROR_CODE","SNAP_ERROR_MESSAGE","cause","serialize","constructor","error","getErrorMessage","getErrorCode","mergedData","getErrorData","Object","keys","length"],"mappings":";;;;+BAcaA;;;eAAAA;;;2BANN;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAOI,qCAEA,wCAEA,qCAEA;AAPJ,MAAMA,kBAAkBC;IAuC7B;;;;GAIC,GACD,IAAIC,OAAO;QACT,OAAO;IACT;IAEA;;;;GAIC,GACD,IAAIC,OAAO;QACT,gCAAO,IAAI,EAAEA;IACf;IAEA;;;;GAIC,GACD,qEAAqE;IACrE,wBAAwB,GACxB,IAAIC,UAAU;QACZ,gCAAO,IAAI,EAAEA;IACf;IAEA;;;;GAIC,GACD,IAAIC,OAAO;QACT,gCAAO,IAAI,EAAEA;IACf;IAEA;;;;GAIC,GACD,qEAAqE;IACrE,wBAAwB,GACxB,IAAIC,QAAQ;QACV,gCAAO,IAAI,EAAEA;IACf;IAEA;;;;GAIC,GACDC,SAA8B;QAC5B,OAAO;YACLJ,MAAMK,0BAAe;YACrBJ,SAASK,6BAAkB;YAC3BJ,MAAM;gBACJK,OAAO;oBACLP,MAAM,IAAI,CAACA,IAAI;oBACfC,SAAS,IAAI,CAACA,OAAO;oBACrBE,OAAO,IAAI,CAACA,KAAK;oBACjB,GAAI,IAAI,CAACD,IAAI,GAAG;wBAAEA,MAAM,IAAI,CAACA,IAAI;oBAAC,IAAI,CAAC,CAAC;gBAC1C;YACF;QACF;IACF;IAEA;;;;;GAKC,GACDM,YAAY;QACV,OAAO,IAAI,CAACJ,MAAM;IACpB;IA3GA;;;;;;;;;;;GAWC,GACDK,YACEC,KAAoC,EACpCR,OAA6B,CAAC,CAAC,CAC/B;QACA,MAAMD,UAAUU,IAAAA,0BAAe,EAACD;QAChC,KAAK,CAACT;QAzBR,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;uCAqBQA,UAAUA;uCACVD,OAAOY,IAAAA,uBAAY,EAACF;QAE1B,MAAMG,aAAa;YAAE,GAAGC,IAAAA,uBAAY,EAACJ,MAAM;YAAE,GAAGR,IAAI;QAAC;QACrD,IAAIa,OAAOC,IAAI,CAACH,YAAYI,MAAM,GAAG,GAAG;2CAChCf,OAAOW;QACf;uCAEMV,QAAQ,KAAK,CAACA;IACtB;AAgFF"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -34,6 +34,12 @@ _export(exports, {
|
|
|
34
34
|
enumValue: function() {
|
|
35
35
|
return _internals.enumValue;
|
|
36
36
|
},
|
|
37
|
+
parseSvg: function() {
|
|
38
|
+
return _internals.parseSvg;
|
|
39
|
+
},
|
|
40
|
+
isSvg: function() {
|
|
41
|
+
return _internals.isSvg;
|
|
42
|
+
},
|
|
37
43
|
assert: function() {
|
|
38
44
|
return _utils.assert;
|
|
39
45
|
}
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -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 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';\nexport { assert } from '@metamask/utils';\n\nexport * from './errors';\nexport * from './error-wrappers';\nexport * from './images';\nexport * from './types';\nexport * from './ui';\n"],"names":["getErrorData","getErrorMessage","getErrorStack","SNAP_ERROR_CODE","SNAP_ERROR_MESSAGE","literal","union","enumValue","assert"],"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;;
|
|
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 parseSvg,\n isSvg,\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';\nexport { assert } from '@metamask/utils';\n\nexport * from './errors';\nexport * from './error-wrappers';\nexport * from './images';\nexport * from './types';\nexport * from './ui';\n"],"names":["getErrorData","getErrorMessage","getErrorStack","SNAP_ERROR_CODE","SNAP_ERROR_MESSAGE","literal","union","enumValue","parseSvg","isSvg","assert"],"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;;IACTC,QAAQ;eAARA,mBAAQ;;IACRC,KAAK;eAALA,gBAAK;;IAUEC,MAAM;eAANA,aAAM;;;2BATR;uBASgB;qBAET;qBACA;qBACA;qBACA;qBACA"}
|
|
@@ -11,7 +11,21 @@ Object.defineProperty(exports, "createSnapError", {
|
|
|
11
11
|
const _errors = require("../errors");
|
|
12
12
|
function createSnapError(fn) {
|
|
13
13
|
return class SnapJsonRpcError extends _errors.SnapError {
|
|
14
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Create a new `SnapJsonRpcError` from a message and data.
|
|
16
|
+
*
|
|
17
|
+
* @param message - The message to create the error from.
|
|
18
|
+
* @param data - The data to create the error from.
|
|
19
|
+
*/ constructor(message, data){
|
|
20
|
+
if (typeof message === 'object') {
|
|
21
|
+
const error = fn();
|
|
22
|
+
super({
|
|
23
|
+
code: error.code,
|
|
24
|
+
message: error.message,
|
|
25
|
+
data: message
|
|
26
|
+
});
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
15
29
|
const error = fn(message);
|
|
16
30
|
super({
|
|
17
31
|
code: error.code,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/internals/error-wrappers.ts"],"sourcesContent":["import type { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json } from '@metamask/utils';\n\nimport { SnapError } from '../errors';\n\nexport type JsonRpcErrorFunction = typeof rpcErrors.parse;\n\n/**\n * Create a `SnapError` class from an error function from\n * `@metamask/rpc-errors`. This is useful for creating custom error classes\n * which can be thrown by a Snap.\n *\n * The created class will inherit the message, code, and data properties from\n * the error function.\n *\n * @param fn - The error function to create the class from.\n * @returns The created `SnapError` class.\n */\nexport function createSnapError(fn: JsonRpcErrorFunction) {\n return class SnapJsonRpcError extends SnapError {\n constructor(message?: string
|
|
1
|
+
{"version":3,"sources":["../../../src/internals/error-wrappers.ts"],"sourcesContent":["import type { rpcErrors } from '@metamask/rpc-errors';\nimport type { Json } from '@metamask/utils';\n\nimport { SnapError } from '../errors';\n\nexport type JsonRpcErrorFunction = typeof rpcErrors.parse;\n\n/**\n * Create a `SnapError` class from an error function from\n * `@metamask/rpc-errors`. This is useful for creating custom error classes\n * which can be thrown by a Snap.\n *\n * The created class will inherit the message, code, and data properties from\n * the error function.\n *\n * @param fn - The error function to create the class from.\n * @returns The created `SnapError` class.\n */\nexport function createSnapError(fn: JsonRpcErrorFunction) {\n return class SnapJsonRpcError extends SnapError {\n /**\n * Create a new `SnapJsonRpcError` from a message.\n *\n * @param message - The message to create the error from.\n */\n constructor(message?: string);\n\n /**\n * Create a new `SnapJsonRpcError` from data.\n *\n * @param data - The data to create the error from.\n */\n constructor(data?: Record<string, Json>);\n\n /**\n * Create a new `SnapJsonRpcError` from a message and data.\n *\n * @param message - The message to create the error from.\n * @param data - The data to create the error from.\n */\n constructor(\n message?: string | Record<string, Json>,\n data?: Record<string, Json>,\n );\n\n /**\n * Create a new `SnapJsonRpcError` from a message and data.\n *\n * @param message - The message to create the error from.\n * @param data - The data to create the error from.\n */\n constructor(\n message?: string | Record<string, Json>,\n data?: Record<string, Json>,\n ) {\n if (typeof message === 'object') {\n const error = fn();\n super({\n code: error.code,\n message: error.message,\n data: message,\n });\n\n return;\n }\n\n const error = fn(message);\n super({\n code: error.code,\n message: error.message,\n data,\n });\n }\n };\n}\n"],"names":["createSnapError","fn","SnapJsonRpcError","SnapError","constructor","message","data","error","code"],"mappings":";;;;+BAkBgBA;;;eAAAA;;;wBAfU;AAenB,SAASA,gBAAgBC,EAAwB;IACtD,OAAO,MAAMC,yBAAyBC,iBAAS;QA0B7C;;;;;KAKC,GACDC,YACEC,OAAuC,EACvCC,IAA2B,CAC3B;YACA,IAAI,OAAOD,YAAY,UAAU;gBAC/B,MAAME,QAAQN;gBACd,KAAK,CAAC;oBACJO,MAAMD,MAAMC,IAAI;oBAChBH,SAASE,MAAMF,OAAO;oBACtBC,MAAMD;gBACR;gBAEA;YACF;YAEA,MAAME,QAAQN,GAAGI;YACjB,KAAK,CAAC;gBACJG,MAAMD,MAAMC,IAAI;gBAChBH,SAASE,MAAMF,OAAO;gBACtBC;YACF;QACF;IACF;AACF"}
|
|
@@ -6,6 +6,7 @@ _export_star(require("./error-wrappers"), exports);
|
|
|
6
6
|
_export_star(require("./errors"), exports);
|
|
7
7
|
_export_star(require("./helpers"), exports);
|
|
8
8
|
_export_star(require("./structs"), exports);
|
|
9
|
+
_export_star(require("./svg"), exports);
|
|
9
10
|
function _export_star(from, to) {
|
|
10
11
|
Object.keys(from).forEach(function(k) {
|
|
11
12
|
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';\nexport * from './structs';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA"}
|
|
1
|
+
{"version":3,"sources":["../../../src/internals/index.ts"],"sourcesContent":["export * from './error-wrappers';\nexport * from './errors';\nexport * from './helpers';\nexport * from './structs';\nexport * from './svg';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA"}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
parseSvg: function() {
|
|
13
|
+
return parseSvg;
|
|
14
|
+
},
|
|
15
|
+
isSvg: function() {
|
|
16
|
+
return isSvg;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _utils = require("@metamask/utils");
|
|
20
|
+
const _fastxmlparser = require("fast-xml-parser");
|
|
21
|
+
function parseSvg(svg) {
|
|
22
|
+
try {
|
|
23
|
+
const trimmed = svg.trim();
|
|
24
|
+
(0, _utils.assert)(trimmed.length > 0);
|
|
25
|
+
const parser = new _fastxmlparser.XMLParser({
|
|
26
|
+
ignoreAttributes: false,
|
|
27
|
+
parseAttributeValue: true
|
|
28
|
+
});
|
|
29
|
+
const parsed = parser.parse(trimmed, true);
|
|
30
|
+
(0, _utils.assert)((0, _utils.hasProperty)(parsed, 'svg'));
|
|
31
|
+
// Empty SVGs are not returned as objects
|
|
32
|
+
if (!(0, _utils.isObject)(parsed.svg)) {
|
|
33
|
+
return {};
|
|
34
|
+
}
|
|
35
|
+
return parsed.svg;
|
|
36
|
+
} catch {
|
|
37
|
+
throw new Error('Snap icon must be a valid SVG.');
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function isSvg(svg) {
|
|
41
|
+
try {
|
|
42
|
+
parseSvg(svg);
|
|
43
|
+
return true;
|
|
44
|
+
} catch {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
//# sourceMappingURL=svg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/internals/svg.ts"],"sourcesContent":["import { assert, hasProperty, isObject } from '@metamask/utils';\nimport { XMLParser } from 'fast-xml-parser';\n\n/**\n * Parse and validate a string as an SVG.\n *\n * @param svg - An SVG string.\n * @returns The SVG, its attributes and children in an object format.\n */\nexport function parseSvg(svg: string) {\n try {\n const trimmed = svg.trim();\n\n assert(trimmed.length > 0);\n\n const parser = new XMLParser({\n ignoreAttributes: false,\n parseAttributeValue: true,\n });\n const parsed = parser.parse(trimmed, true);\n\n assert(hasProperty(parsed, 'svg'));\n\n // Empty SVGs are not returned as objects\n if (!isObject(parsed.svg)) {\n return {};\n }\n\n return parsed.svg;\n } catch {\n throw new Error('Snap icon must be a valid SVG.');\n }\n}\n\n/**\n * Validate that a string is a valid SVG.\n *\n * @param svg - An SVG string.\n * @returns True if the SVG is valid otherwise false.\n */\nexport function isSvg(svg: string) {\n try {\n parseSvg(svg);\n return true;\n } catch {\n return false;\n }\n}\n"],"names":["parseSvg","isSvg","svg","trimmed","trim","assert","length","parser","XMLParser","ignoreAttributes","parseAttributeValue","parsed","parse","hasProperty","isObject","Error"],"mappings":";;;;;;;;;;;IASgBA,QAAQ;eAARA;;IA+BAC,KAAK;eAALA;;;uBAxC8B;+BACpB;AAQnB,SAASD,SAASE,GAAW;IAClC,IAAI;QACF,MAAMC,UAAUD,IAAIE,IAAI;QAExBC,IAAAA,aAAM,EAACF,QAAQG,MAAM,GAAG;QAExB,MAAMC,SAAS,IAAIC,wBAAS,CAAC;YAC3BC,kBAAkB;YAClBC,qBAAqB;QACvB;QACA,MAAMC,SAASJ,OAAOK,KAAK,CAACT,SAAS;QAErCE,IAAAA,aAAM,EAACQ,IAAAA,kBAAW,EAACF,QAAQ;QAE3B,yCAAyC;QACzC,IAAI,CAACG,IAAAA,eAAQ,EAACH,OAAOT,GAAG,GAAG;YACzB,OAAO,CAAC;QACV;QAEA,OAAOS,OAAOT,GAAG;IACnB,EAAE,OAAM;QACN,MAAM,IAAIa,MAAM;IAClB;AACF;AAQO,SAASd,MAAMC,GAAW;IAC/B,IAAI;QACFF,SAASE;QACT,OAAO;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
|
|
@@ -10,6 +10,7 @@ _export_star(require("./name-lookup"), exports);
|
|
|
10
10
|
_export_star(require("./rpc-request"), exports);
|
|
11
11
|
_export_star(require("./transaction"), exports);
|
|
12
12
|
_export_star(require("./signature"), exports);
|
|
13
|
+
_export_star(require("./user-input"), exports);
|
|
13
14
|
function _export_star(from, to) {
|
|
14
15
|
Object.keys(from).forEach(function(k) {
|
|
15
16
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/types/handlers/index.ts"],"sourcesContent":["export * from './cronjob';\nexport * from './home-page';\nexport * from './keyring';\nexport * from './lifecycle';\nexport * from './name-lookup';\nexport * from './rpc-request';\nexport * from './transaction';\nexport * from './signature';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/types/handlers/index.ts"],"sourcesContent":["export * from './cronjob';\nexport * from './home-page';\nexport * from './keyring';\nexport * from './lifecycle';\nexport * from './name-lookup';\nexport * from './rpc-request';\nexport * from './transaction';\nexport * from './signature';\nexport * from './user-input';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/types/handlers/transaction.ts"],"sourcesContent":["import type { EnumToUnion } from '../../internals';\nimport type { Component } from '../../ui';\nimport type { ChainId } from '../caip';\n\n/**\n * The severity level of content being returned from a transaction insight.\n * Currently only one level is supported:\n *\n * - `critical` - The transaction is critical and should not be submitted by the\n * user.\n */\nexport enum SeverityLevel {\n Critical = 'critical',\n}\n\n/**\n * An EIP-1559 (type 2) transaction object.\n *\n * @property from - The address the transaction is being sent from.\n * @property to - The address the transaction is being sent to.\n * @property nonce - The nonce of the transaction.\n * @property value - The value of the transaction.\n * @property data - The data of the transaction.\n * @property gas - The gas limit of the transaction.\n * @property maxFeePerGas - The maximum fee per gas of the transaction.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas of the\n * transaction.\n * @property estimateSuggested - The suggested gas price for the transaction.\n * @property estimateUsed - The gas price used for the transaction.\n * @see https://eips.ethereum.org/EIPS/eip-1559\n */\nexport type EIP1559Transaction = {\n from: string;\n to: string;\n nonce: string;\n value: string;\n data: string;\n gas: string;\n maxFeePerGas: string;\n maxPriorityFeePerGas: string;\n estimateSuggested: string;\n estimateUsed: string;\n};\n\n/**\n * A legacy (type \"0\") transaction object.\n *\n * @property from - The address the transaction is being sent from.\n * @property to - The address the transaction is being sent to.\n * @property nonce - The nonce of the transaction.\n * @property value - The value of the transaction.\n * @property data - The data of the transaction.\n * @property gas - The gas limit of the transaction.\n * @property gasPrice - The gas price of the transaction.\n * @property estimateSuggested - The suggested gas price for the transaction.\n * @property estimateUsed - The gas price used for the transaction.\n */\nexport type LegacyTransaction = {\n from: string;\n to: string;\n nonce: string;\n value: string;\n data: string;\n gas: string;\n gasPrice: string;\n estimateSuggested: string;\n estimateUsed: string;\n};\n\n/**\n * A transaction object. This can be either an EIP-1559 transaction or a legacy\n * transaction.\n *\n * @see EIP1559Transaction\n * @see LegacyTransaction\n */\nexport type Transaction = EIP1559Transaction | LegacyTransaction;\n\n/**\n * The `onTransaction` handler. This is called whenever a transaction is\n * submitted to the snap. It can return insights about the transaction, which\n * will be displayed to the user.\n *\n * Note that using this handler requires the `endowment:transaction-insights`\n * permission.\n *\n * @param args - The request arguments.\n * @param args.transaction - The transaction object, containing the address,\n * value, data, and other properties of the transaction.\n * @param args.chainId - The CAIP-2 {@link ChainId} of the network the\n * transaction is being submitted to.\n * @param args.transactionOrigin - The origin of the transaction. This is the\n * URL of the website that submitted the transaction. This is only available if\n * the Snap has enabled the `allowTransactionOrigin` option in the\n * `endowment:transaction-insight` permission.\n * @returns An object containing insights about the transaction. See\n * {@link OnTransactionResponse}. Can also return `null` if no insights are\n * available.\n */\nexport type OnTransactionHandler = (args: {\n transaction: Transaction;\n chainId: ChainId;\n transactionOrigin?: string;\n}) => Promise<OnTransactionResponse | null>;\n\n/**\n * The response from a Snap's `onTransaction` handler.\n *\n * @property component - A custom UI component, that will be shown in MetaMask.\n * @property severity - The severity level of the content. Currently only one\n * level is supported: `critical`.\n */\nexport type OnTransactionResponse
|
|
1
|
+
{"version":3,"sources":["../../../../src/types/handlers/transaction.ts"],"sourcesContent":["import type { EnumToUnion } from '../../internals';\nimport type { Component } from '../../ui';\nimport type { ChainId } from '../caip';\n\n/**\n * The severity level of content being returned from a transaction insight.\n * Currently only one level is supported:\n *\n * - `critical` - The transaction is critical and should not be submitted by the\n * user.\n */\nexport enum SeverityLevel {\n Critical = 'critical',\n}\n\n/**\n * An EIP-1559 (type 2) transaction object.\n *\n * @property from - The address the transaction is being sent from.\n * @property to - The address the transaction is being sent to.\n * @property nonce - The nonce of the transaction.\n * @property value - The value of the transaction.\n * @property data - The data of the transaction.\n * @property gas - The gas limit of the transaction.\n * @property maxFeePerGas - The maximum fee per gas of the transaction.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas of the\n * transaction.\n * @property estimateSuggested - The suggested gas price for the transaction.\n * @property estimateUsed - The gas price used for the transaction.\n * @see https://eips.ethereum.org/EIPS/eip-1559\n */\nexport type EIP1559Transaction = {\n from: string;\n to: string;\n nonce: string;\n value: string;\n data: string;\n gas: string;\n maxFeePerGas: string;\n maxPriorityFeePerGas: string;\n estimateSuggested: string;\n estimateUsed: string;\n};\n\n/**\n * A legacy (type \"0\") transaction object.\n *\n * @property from - The address the transaction is being sent from.\n * @property to - The address the transaction is being sent to.\n * @property nonce - The nonce of the transaction.\n * @property value - The value of the transaction.\n * @property data - The data of the transaction.\n * @property gas - The gas limit of the transaction.\n * @property gasPrice - The gas price of the transaction.\n * @property estimateSuggested - The suggested gas price for the transaction.\n * @property estimateUsed - The gas price used for the transaction.\n */\nexport type LegacyTransaction = {\n from: string;\n to: string;\n nonce: string;\n value: string;\n data: string;\n gas: string;\n gasPrice: string;\n estimateSuggested: string;\n estimateUsed: string;\n};\n\n/**\n * A transaction object. This can be either an EIP-1559 transaction or a legacy\n * transaction.\n *\n * @see EIP1559Transaction\n * @see LegacyTransaction\n */\nexport type Transaction = EIP1559Transaction | LegacyTransaction;\n\n/**\n * The `onTransaction` handler. This is called whenever a transaction is\n * submitted to the snap. It can return insights about the transaction, which\n * will be displayed to the user.\n *\n * Note that using this handler requires the `endowment:transaction-insights`\n * permission.\n *\n * @param args - The request arguments.\n * @param args.transaction - The transaction object, containing the address,\n * value, data, and other properties of the transaction.\n * @param args.chainId - The CAIP-2 {@link ChainId} of the network the\n * transaction is being submitted to.\n * @param args.transactionOrigin - The origin of the transaction. This is the\n * URL of the website that submitted the transaction. This is only available if\n * the Snap has enabled the `allowTransactionOrigin` option in the\n * `endowment:transaction-insight` permission.\n * @returns An object containing insights about the transaction. See\n * {@link OnTransactionResponse}. Can also return `null` if no insights are\n * available.\n */\nexport type OnTransactionHandler = (args: {\n transaction: Transaction;\n chainId: ChainId;\n transactionOrigin?: string;\n}) => Promise<OnTransactionResponse | null>;\n\n/**\n * The response from a Snap's `onTransaction` handler.\n *\n * @property component - A custom UI component, that will be shown in MetaMask.\n * @property id - A Snap interface ID.\n * @property severity - The severity level of the content. Currently only one\n * level is supported: `critical`.\n */\nexport type OnTransactionResponse =\n | {\n content: Component;\n severity?: EnumToUnion<SeverityLevel>;\n }\n | {\n id: string;\n severity?: EnumToUnion<SeverityLevel>;\n };\n"],"names":["SeverityLevel","Critical"],"mappings":";;;;;;;;;;IAWO;UAAKA,aAAa;IAAbA,cACVC,cAAW;GADDD,kBAAAA"}
|
|
@@ -0,0 +1,51 @@
|
|
|
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
|
+
UserInputEventType: function() {
|
|
13
|
+
return UserInputEventType;
|
|
14
|
+
},
|
|
15
|
+
GenericEventStruct: function() {
|
|
16
|
+
return GenericEventStruct;
|
|
17
|
+
},
|
|
18
|
+
ButtonClickEventStruct: function() {
|
|
19
|
+
return ButtonClickEventStruct;
|
|
20
|
+
},
|
|
21
|
+
FormSubmitEventStruct: function() {
|
|
22
|
+
return FormSubmitEventStruct;
|
|
23
|
+
},
|
|
24
|
+
UserInputEventStruct: function() {
|
|
25
|
+
return UserInputEventStruct;
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const _superstruct = require("superstruct");
|
|
29
|
+
var UserInputEventType;
|
|
30
|
+
(function(UserInputEventType) {
|
|
31
|
+
UserInputEventType["ButtonClickEvent"] = "ButtonClickEvent";
|
|
32
|
+
UserInputEventType["FormSubmitEvent"] = "FormSubmitEvent";
|
|
33
|
+
})(UserInputEventType || (UserInputEventType = {}));
|
|
34
|
+
const GenericEventStruct = (0, _superstruct.object)({
|
|
35
|
+
type: (0, _superstruct.string)(),
|
|
36
|
+
name: (0, _superstruct.optional)((0, _superstruct.string)())
|
|
37
|
+
});
|
|
38
|
+
const ButtonClickEventStruct = (0, _superstruct.assign)(GenericEventStruct, (0, _superstruct.object)({
|
|
39
|
+
type: (0, _superstruct.literal)(UserInputEventType.ButtonClickEvent)
|
|
40
|
+
}));
|
|
41
|
+
const FormSubmitEventStruct = (0, _superstruct.assign)(GenericEventStruct, (0, _superstruct.object)({
|
|
42
|
+
type: (0, _superstruct.literal)(UserInputEventType.FormSubmitEvent),
|
|
43
|
+
value: (0, _superstruct.record)((0, _superstruct.string)(), (0, _superstruct.string)()),
|
|
44
|
+
name: (0, _superstruct.string)()
|
|
45
|
+
}));
|
|
46
|
+
const UserInputEventStruct = (0, _superstruct.union)([
|
|
47
|
+
ButtonClickEventStruct,
|
|
48
|
+
FormSubmitEventStruct
|
|
49
|
+
]);
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=user-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/types/handlers/user-input.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport {\n assign,\n literal,\n object,\n optional,\n record,\n string,\n union,\n} from 'superstruct';\n\n/**\n * The type of user input event fired.\n * Currently only two events are supported:\n *\n * - `ButtonClickEvent` - A button has been clicked in the UI.\n * - `FormSubmitEvent` - A Form has been submitted in the UI.\n */\nexport enum UserInputEventType {\n ButtonClickEvent = 'ButtonClickEvent',\n FormSubmitEvent = 'FormSubmitEvent',\n}\n\nexport const GenericEventStruct = object({\n type: string(),\n name: optional(string()),\n});\n\nexport const ButtonClickEventStruct = assign(\n GenericEventStruct,\n object({\n type: literal(UserInputEventType.ButtonClickEvent),\n }),\n);\n\nexport const FormSubmitEventStruct = assign(\n GenericEventStruct,\n object({\n type: literal(UserInputEventType.FormSubmitEvent),\n value: record(string(), string()),\n name: string(),\n }),\n);\n\nexport const UserInputEventStruct = union([\n ButtonClickEventStruct,\n FormSubmitEventStruct,\n]);\n\n/**\n * A user input event fired in the UI. This is passed to the params of the `onUserInput` handler.\n *\n * @property type - The type of event fired. See {@link UserInputEventType} for the different types.\n * @property name - The component name that fired the event. It is optional for an {@link UserInputEventType.ButtonClickEvent}.\n * @property value - The value associated with the event. Only available when an {@link UserInputEventType.FormSubmitEvent} is fired.\n * It contains the form values submitted.\n */\ntype UserInputEvent = Infer<typeof UserInputEventStruct>;\n\n/**\n * The `onUserInput` handler. This is called when an user input event is fired in the UI.\n *\n * @param args - The user input event.\n * @param args.id - The user interface id.\n * @param args.event - The {@link UserInputEvent} object, containing the data about the fired event.\n */\nexport type OnUserInputHandler = (args: {\n id: string;\n event: UserInputEvent;\n}) => Promise<void>;\n"],"names":["GenericEventStruct","ButtonClickEventStruct","FormSubmitEventStruct","UserInputEventStruct","UserInputEventType","ButtonClickEvent","FormSubmitEvent","object","type","string","name","optional","assign","literal","value","record","union"],"mappings":";;;;;;;;;;;;;;IAuBaA,kBAAkB;eAAlBA;;IAKAC,sBAAsB;eAAtBA;;IAOAC,qBAAqB;eAArBA;;IASAC,oBAAoB;eAApBA;;;6BAnCN;IASA;UAAKC,kBAAkB;IAAlBA,mBACVC,sBAAAA;IADUD,mBAEVE,qBAAAA;GAFUF,uBAAAA;AAKL,MAAMJ,qBAAqBO,IAAAA,mBAAM,EAAC;IACvCC,MAAMC,IAAAA,mBAAM;IACZC,MAAMC,IAAAA,qBAAQ,EAACF,IAAAA,mBAAM;AACvB;AAEO,MAAMR,yBAAyBW,IAAAA,mBAAM,EAC1CZ,oBACAO,IAAAA,mBAAM,EAAC;IACLC,MAAMK,IAAAA,oBAAO,EAACT,mBAAmBC,gBAAgB;AACnD;AAGK,MAAMH,wBAAwBU,IAAAA,mBAAM,EACzCZ,oBACAO,IAAAA,mBAAM,EAAC;IACLC,MAAMK,IAAAA,oBAAO,EAACT,mBAAmBE,eAAe;IAChDQ,OAAOC,IAAAA,mBAAM,EAACN,IAAAA,mBAAM,KAAIA,IAAAA,mBAAM;IAC9BC,MAAMD,IAAAA,mBAAM;AACd;AAGK,MAAMN,uBAAuBa,IAAAA,kBAAK,EAAC;IACxCf;IACAC;CACD"}
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -11,6 +11,7 @@ _export_star(require("./methods"), exports);
|
|
|
11
11
|
_export_star(require("./permissions"), exports);
|
|
12
12
|
_export_star(require("./provider"), exports);
|
|
13
13
|
_export_star(require("./snap"), exports);
|
|
14
|
+
_export_star(require("./interface"), exports);
|
|
14
15
|
function _export_star(from, to) {
|
|
15
16
|
Object.keys(from).forEach(function(k) {
|
|
16
17
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["// This is intentionally imported, rather than re-exported.\n// eslint-disable-next-line import/no-unassigned-import\nimport './global';\n\nexport * from './caip';\nexport * from './handlers';\nexport * from './methods';\nexport * from './permissions';\nexport * from './provider';\nexport * from './snap';\n"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,uDAAuD;;;;;QAChD;qBAEO;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
1
|
+
{"version":3,"sources":["../../../src/types/index.ts"],"sourcesContent":["// This is intentionally imported, rather than re-exported.\n// eslint-disable-next-line import/no-unassigned-import\nimport './global';\n\nexport * from './caip';\nexport * from './handlers';\nexport * from './methods';\nexport * from './permissions';\nexport * from './provider';\nexport * from './snap';\nexport * from './interface';\n"],"names":[],"mappings":"AAAA,2DAA2D;AAC3D,uDAAuD;;;;;QAChD;qBAEO;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
FormStateStruct: function() {
|
|
13
|
+
return FormStateStruct;
|
|
14
|
+
},
|
|
15
|
+
InterfaceStateStruct: function() {
|
|
16
|
+
return InterfaceStateStruct;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
const _superstruct = require("superstruct");
|
|
20
|
+
const FormStateStruct = (0, _superstruct.record)((0, _superstruct.string)(), (0, _superstruct.nullable)((0, _superstruct.string)()));
|
|
21
|
+
const InterfaceStateStruct = (0, _superstruct.record)((0, _superstruct.string)(), (0, _superstruct.union)([
|
|
22
|
+
FormStateStruct,
|
|
23
|
+
(0, _superstruct.nullable)((0, _superstruct.string)())
|
|
24
|
+
]));
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=interface.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/types/interface.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport { nullable, record, string, union } from 'superstruct';\n\n/**\n * To avoid typing problems with the interface state when manipulating it we have to differentiate the state of\n * a form (that will be contained inside the root state) and the root state since a key in the root stat can contain\n * either the value of an input or a sub-state of a form.\n */\n\nexport const FormStateStruct = record(string(), nullable(string()));\n\nexport const InterfaceStateStruct = record(\n string(),\n union([FormStateStruct, nullable(string())]),\n);\n\nexport type FormState = Infer<typeof FormStateStruct>;\nexport type InterfaceState = Infer<typeof InterfaceStateStruct>;\n"],"names":["FormStateStruct","InterfaceStateStruct","record","string","nullable","union"],"mappings":";;;;;;;;;;;IASaA,eAAe;eAAfA;;IAEAC,oBAAoB;eAApBA;;;6BAVmC;AAQzC,MAAMD,kBAAkBE,IAAAA,mBAAM,EAACC,IAAAA,mBAAM,KAAIC,IAAAA,qBAAQ,EAACD,IAAAA,mBAAM;AAExD,MAAMF,uBAAuBC,IAAAA,mBAAM,EACxCC,IAAAA,mBAAM,KACNE,IAAAA,kBAAK,EAAC;IAACL;IAAiBI,IAAAA,qBAAQ,EAACD,IAAAA,mBAAM;CAAI"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/types/methods/create-interface.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/types/methods/dialog.ts"],"sourcesContent":["import type { EnumToUnion } from '../../internals';\nimport type { Component } from '../../ui';\n\n/**\n * The type of dialog to display.\n *\n * - `alert` - A dialog with a single button.\n * - `confirmation` - A dialog with two buttons, one to confirm and one to\n * cancel.\n * - `prompt` - A dialog with two buttons and a text input.\n */\nexport enum DialogType {\n Alert = 'alert',\n Confirmation = 'confirmation',\n Prompt = 'prompt',\n}\n\n/**\n * An alert dialog.\n *\n * @property type - The type of dialog. Must be `alert`.\n * @property content - The content to display in the dialog.\n */\nexport type AlertDialog
|
|
1
|
+
{"version":3,"sources":["../../../../src/types/methods/dialog.ts"],"sourcesContent":["import type { EnumToUnion } from '../../internals';\nimport type { Component } from '../../ui';\n\n/**\n * The type of dialog to display.\n *\n * - `alert` - A dialog with a single button.\n * - `confirmation` - A dialog with two buttons, one to confirm and one to\n * cancel.\n * - `prompt` - A dialog with two buttons and a text input.\n */\nexport enum DialogType {\n Alert = 'alert',\n Confirmation = 'confirmation',\n Prompt = 'prompt',\n}\n\n/**\n * An alert dialog.\n *\n * @property type - The type of dialog. Must be `alert`.\n * @property content - The content to display in the dialog.\n * @property id - The Snap interface ID.\n */\nexport type AlertDialog =\n | {\n type: EnumToUnion<DialogType.Alert>;\n content: Component;\n }\n | {\n type: EnumToUnion<DialogType.Alert>;\n id: string;\n };\n\n/**\n * A confirmation dialog.\n *\n * @property type - The type of dialog. Must be `confirmation`.\n * @property content - The content to display in the dialog.\n * @property id - The Snap interface ID.\n */\nexport type ConfirmationDialog =\n | {\n type: EnumToUnion<DialogType.Confirmation>;\n content: Component;\n }\n | {\n type: EnumToUnion<DialogType.Confirmation>;\n id: string;\n };\n\n/**\n * A prompt dialog.\n *\n * @property type - The type of dialog. Must be `prompt`.\n * @property content - The content to display in the dialog.\n * @property id - The Snap interface ID.\n * @property placeholder - An optional placeholder text to display in the text\n * input.\n */\nexport type PromptDialog =\n | {\n type: EnumToUnion<DialogType.Prompt>;\n content: Component;\n placeholder?: string;\n }\n | {\n type: EnumToUnion<DialogType.Prompt>;\n id: string;\n placeholder?: string;\n };\n\n/**\n * The request parameters for the `snap_dialog` method.\n *\n * @property type - The type of dialog to display.\n * @property content - The content to display in the dialog.\n * @property id - The Snap interface ID.\n * @property placeholder - The placeholder text to display in the dialog. Only\n * applicable for the `prompt` dialog.\n */\nexport type DialogParams = AlertDialog | ConfirmationDialog | PromptDialog;\n\n/**\n * The result returned by the `snap_dialog` method.\n *\n * - If the dialog is an `alert`, the result is `null`.\n * - If the dialog is a `confirmation`, the result is a boolean indicating\n * whether the user confirmed the dialog.\n * - If the dialog is a `prompt`, the result is the value entered by\n * the user.\n */\nexport type DialogResult = null | boolean | string;\n"],"names":["DialogType","Alert","Confirmation","Prompt"],"mappings":";;;;;;;;;;IAWO;UAAKA,UAAU;IAAVA,WACVC,WAAQ;IADED,WAEVE,kBAAe;IAFLF,WAGVG,YAAS;GAHCH,eAAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/types/methods/get-interface-state.ts"],"names":[],"mappings":""}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", {
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
|
+
_export_star(require("./create-interface"), exports);
|
|
5
6
|
_export_star(require("./dialog"), exports);
|
|
6
7
|
_export_star(require("./get-bip32-entropy"), exports);
|
|
7
8
|
_export_star(require("./get-bip32-public-key"), exports);
|
|
@@ -9,6 +10,7 @@ _export_star(require("./get-bip44-entropy"), exports);
|
|
|
9
10
|
_export_star(require("./get-client-status"), exports);
|
|
10
11
|
_export_star(require("./get-entropy"), exports);
|
|
11
12
|
_export_star(require("./get-file"), exports);
|
|
13
|
+
_export_star(require("./get-interface-state"), exports);
|
|
12
14
|
_export_star(require("./get-locale"), exports);
|
|
13
15
|
_export_star(require("./get-snaps"), exports);
|
|
14
16
|
_export_star(require("./invoke-keyring"), exports);
|
|
@@ -18,6 +20,7 @@ _export_star(require("./manage-state"), exports);
|
|
|
18
20
|
_export_star(require("./methods"), exports);
|
|
19
21
|
_export_star(require("./notify"), exports);
|
|
20
22
|
_export_star(require("./request-snaps"), exports);
|
|
23
|
+
_export_star(require("./update-interface"), exports);
|
|
21
24
|
function _export_star(from, to) {
|
|
22
25
|
Object.keys(from).forEach(function(k) {
|
|
23
26
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/types/methods/index.ts"],"sourcesContent":["export * from './dialog';\nexport * from './get-bip32-entropy';\nexport * from './get-bip32-public-key';\nexport * from './get-bip44-entropy';\nexport * from './get-client-status';\nexport * from './get-entropy';\nexport * from './get-file';\nexport * from './get-locale';\nexport * from './get-snaps';\nexport * from './invoke-keyring';\nexport * from './invoke-snap';\nexport * from './manage-accounts';\nexport * from './manage-state';\nexport * from './methods';\nexport * from './notify';\nexport * from './request-snaps';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/types/methods/index.ts"],"sourcesContent":["export * from './create-interface';\nexport * from './dialog';\nexport * from './get-bip32-entropy';\nexport * from './get-bip32-public-key';\nexport * from './get-bip44-entropy';\nexport * from './get-client-status';\nexport * from './get-entropy';\nexport * from './get-file';\nexport * from './get-interface-state';\nexport * from './get-locale';\nexport * from './get-snaps';\nexport * from './invoke-keyring';\nexport * from './invoke-snap';\nexport * from './manage-accounts';\nexport * from './manage-state';\nexport * from './methods';\nexport * from './notify';\nexport * from './request-snaps';\nexport * from './update-interface';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/types/methods/update-interface.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,59 @@
|
|
|
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
|
+
ButtonVariant: function() {
|
|
13
|
+
return ButtonVariant;
|
|
14
|
+
},
|
|
15
|
+
ButtonType: function() {
|
|
16
|
+
return ButtonType;
|
|
17
|
+
},
|
|
18
|
+
ButtonStruct: function() {
|
|
19
|
+
return ButtonStruct;
|
|
20
|
+
},
|
|
21
|
+
button: function() {
|
|
22
|
+
return button;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
const _superstruct = require("superstruct");
|
|
26
|
+
const _internals = require("../../internals");
|
|
27
|
+
const _builder = require("../builder");
|
|
28
|
+
const _nodes = require("../nodes");
|
|
29
|
+
var ButtonVariant;
|
|
30
|
+
(function(ButtonVariant) {
|
|
31
|
+
ButtonVariant["Primary"] = 'primary';
|
|
32
|
+
ButtonVariant["Secondary"] = 'secondary';
|
|
33
|
+
})(ButtonVariant || (ButtonVariant = {}));
|
|
34
|
+
var ButtonType;
|
|
35
|
+
(function(ButtonType) {
|
|
36
|
+
ButtonType["Button"] = 'button';
|
|
37
|
+
ButtonType["Submit"] = 'submit';
|
|
38
|
+
})(ButtonType || (ButtonType = {}));
|
|
39
|
+
const ButtonStruct = (0, _superstruct.assign)(_nodes.LiteralStruct, (0, _superstruct.object)({
|
|
40
|
+
type: (0, _superstruct.literal)(_nodes.NodeType.Button),
|
|
41
|
+
value: (0, _superstruct.string)(),
|
|
42
|
+
variant: (0, _superstruct.optional)((0, _superstruct.union)([
|
|
43
|
+
(0, _internals.enumValue)(ButtonVariant.Primary),
|
|
44
|
+
(0, _internals.enumValue)(ButtonVariant.Secondary)
|
|
45
|
+
])),
|
|
46
|
+
buttonType: (0, _superstruct.optional)((0, _superstruct.union)([
|
|
47
|
+
(0, _internals.enumValue)(ButtonType.Button),
|
|
48
|
+
(0, _internals.enumValue)(ButtonType.Submit)
|
|
49
|
+
])),
|
|
50
|
+
name: (0, _superstruct.optional)((0, _superstruct.string)())
|
|
51
|
+
}));
|
|
52
|
+
const button = (0, _builder.createBuilder)(_nodes.NodeType.Button, ButtonStruct, [
|
|
53
|
+
'value',
|
|
54
|
+
'buttonType',
|
|
55
|
+
'name',
|
|
56
|
+
'variant'
|
|
57
|
+
]);
|
|
58
|
+
|
|
59
|
+
//# sourceMappingURL=button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/components/button.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport { assign, literal, object, optional, string, union } from 'superstruct';\n\nimport { enumValue } from '../../internals';\nimport { createBuilder } from '../builder';\nimport { LiteralStruct, NodeType } from '../nodes';\n\nexport enum ButtonVariant {\n Primary = 'primary',\n Secondary = 'secondary',\n}\n\nexport enum ButtonType {\n Button = 'button',\n Submit = 'submit',\n}\n\nexport const ButtonStruct = assign(\n LiteralStruct,\n object({\n type: literal(NodeType.Button),\n value: string(),\n variant: optional(\n union([\n enumValue(ButtonVariant.Primary),\n enumValue(ButtonVariant.Secondary),\n ]),\n ),\n buttonType: optional(\n union([enumValue(ButtonType.Button), enumValue(ButtonType.Submit)]),\n ),\n name: optional(string()),\n }),\n);\n\n/**\n * A button node, that renders either a primary or a secondary button.\n *\n * @property type - The type of the node, must be the string 'button'.\n * @property variant - The style variant of the node, must be either 'primary' or 'secondary'.\n * @property value - The text content of the node as plain text.\n * @property buttonType - The type of the button, must be either 'button' or 'submit'.\n * @property name - An optional name to identify the button.\n */\nexport type Button = Infer<typeof ButtonStruct>;\n\n/**\n * Create a {@link Button} node.\n *\n * @param args - The node arguments. This can be either a string, or an object\n * with a `value` property. A set of optional properties can be passed.\n * @param args.variant - The optional variant of the button.\n * @param args.value - The text content of the node.\n * @param args.name - The optional name of the button.\n * @returns The text node as object.\n * @example\n * ```typescript\n * const node = button({ variant: 'primary', text: 'Hello, world!', name: 'myButton' });\n * const node = button('Hello, world!', 'button', 'myButton', 'primary');\n * const node = button('Hello, world!');\n * ```\n */\nexport const button = createBuilder(NodeType.Button, ButtonStruct, [\n 'value',\n 'buttonType',\n 'name',\n 'variant',\n]);\n"],"names":["ButtonStruct","button","ButtonVariant","Primary","Secondary","ButtonType","Button","Submit","assign","LiteralStruct","object","type","literal","NodeType","value","string","variant","optional","union","enumValue","buttonType","name","createBuilder"],"mappings":";;;;;;;;;;;;;;;;;IAiBaA,YAAY;eAAZA;;IA6CAC,MAAM;eAANA;;;6BA7DoD;2BAEvC;yBACI;uBACU;IAEjC;UAAKC,aAAa;IAAbA,cACVC,aAAU;IADAD,cAEVE,eAAY;GAFFF,kBAAAA;IAKL;UAAKG,UAAU;IAAVA,WACVC,YAAS;IADCD,WAEVE,YAAS;GAFCF,eAAAA;AAKL,MAAML,eAAeQ,IAAAA,mBAAM,EAChCC,oBAAa,EACbC,IAAAA,mBAAM,EAAC;IACLC,MAAMC,IAAAA,oBAAO,EAACC,eAAQ,CAACP,MAAM;IAC7BQ,OAAOC,IAAAA,mBAAM;IACbC,SAASC,IAAAA,qBAAQ,EACfC,IAAAA,kBAAK,EAAC;QACJC,IAAAA,oBAAS,EAACjB,cAAcC,OAAO;QAC/BgB,IAAAA,oBAAS,EAACjB,cAAcE,SAAS;KAClC;IAEHgB,YAAYH,IAAAA,qBAAQ,EAClBC,IAAAA,kBAAK,EAAC;QAACC,IAAAA,oBAAS,EAACd,WAAWC,MAAM;QAAGa,IAAAA,oBAAS,EAACd,WAAWE,MAAM;KAAE;IAEpEc,MAAMJ,IAAAA,qBAAQ,EAACF,IAAAA,mBAAM;AACvB;AA8BK,MAAMd,SAASqB,IAAAA,sBAAa,EAACT,eAAQ,CAACP,MAAM,EAAEN,cAAc;IACjE;IACA;IACA;IACA;CACD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
FormComponentStruct: function() {
|
|
13
|
+
return FormComponentStruct;
|
|
14
|
+
},
|
|
15
|
+
FormStruct: function() {
|
|
16
|
+
return FormStruct;
|
|
17
|
+
},
|
|
18
|
+
form: function() {
|
|
19
|
+
return form;
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const _superstruct = require("superstruct");
|
|
23
|
+
const _builder = require("../builder");
|
|
24
|
+
const _nodes = require("../nodes");
|
|
25
|
+
const _button = require("./button");
|
|
26
|
+
const _input = require("./input");
|
|
27
|
+
const FormComponentStruct = (0, _superstruct.union)([
|
|
28
|
+
_input.InputStruct,
|
|
29
|
+
_button.ButtonStruct
|
|
30
|
+
]);
|
|
31
|
+
const FormStruct = (0, _superstruct.assign)(_nodes.NodeStruct, (0, _superstruct.object)({
|
|
32
|
+
type: (0, _superstruct.literal)(_nodes.NodeType.Form),
|
|
33
|
+
children: (0, _superstruct.array)(FormComponentStruct),
|
|
34
|
+
name: (0, _superstruct.string)()
|
|
35
|
+
}));
|
|
36
|
+
const form = (0, _builder.createBuilder)(_nodes.NodeType.Form, FormStruct, [
|
|
37
|
+
'name',
|
|
38
|
+
'children'
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
//# sourceMappingURL=form.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/components/form.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport { array, assign, literal, object, string, union } from 'superstruct';\n\nimport { createBuilder } from '../builder';\nimport { NodeStruct, NodeType } from '../nodes';\nimport { ButtonStruct } from './button';\nimport { InputStruct } from './input';\n\nexport const FormComponentStruct = union([InputStruct, ButtonStruct]);\n\n/**\n * The subset of nodes allowed as children in the {@link Form} node.\n */\nexport type FormComponent = Infer<typeof FormComponentStruct>;\n\nexport const FormStruct = assign(\n NodeStruct,\n object({\n type: literal(NodeType.Form),\n children: array(FormComponentStruct),\n name: string(),\n }),\n);\n\n/**\n * A form node that takes children {@link FormComponent} nodes and renders a form.\n *\n * @property type - The type of the node. Must be the string `form`.\n * @property children - The children of the node. Only {@link FormComponent} nodes are allowed.\n * @property name - The form name used to identify it.\n */\nexport type Form = Infer<typeof FormStruct>;\n\n/**\n * Create a {@link Form} node.\n *\n * @param args - The node arguments. This can be either an array of children and a string, or\n * an object with a `name` and `children` property.\n * @param args.name - The form name used to identify it.\n * @param args.children - The child nodes of the form. This can be any valid\n * {@link FormComponent}.\n * @returns The form node as object.\n * @example\n * const node = form({\n * name: 'myForm',\n * children: [\n * input({ name: 'myInput' }),\n * button({ value: 'Hello, world!' }),\n * ],\n * });\n *\n * const node = form('myForm', [input('myInput'), button('Hello, world!')]);\n */\nexport const form = createBuilder(NodeType.Form, FormStruct, [\n 'name',\n 'children',\n]);\n"],"names":["FormComponentStruct","FormStruct","form","union","InputStruct","ButtonStruct","assign","NodeStruct","object","type","literal","NodeType","Form","children","array","name","string","createBuilder"],"mappings":";;;;;;;;;;;IAQaA,mBAAmB;eAAnBA;;IAOAC,UAAU;eAAVA;;IAsCAC,IAAI;eAAJA;;;6BApDiD;yBAEhC;uBACO;wBACR;uBACD;AAErB,MAAMF,sBAAsBG,IAAAA,kBAAK,EAAC;IAACC,kBAAW;IAAEC,oBAAY;CAAC;AAO7D,MAAMJ,aAAaK,IAAAA,mBAAM,EAC9BC,iBAAU,EACVC,IAAAA,mBAAM,EAAC;IACLC,MAAMC,IAAAA,oBAAO,EAACC,eAAQ,CAACC,IAAI;IAC3BC,UAAUC,IAAAA,kBAAK,EAACd;IAChBe,MAAMC,IAAAA,mBAAM;AACd;AAgCK,MAAMd,OAAOe,IAAAA,sBAAa,EAACN,eAAQ,CAACC,IAAI,EAAEX,YAAY;IAC3D;IACA;CACD"}
|
|
@@ -19,18 +19,13 @@ _export(exports, {
|
|
|
19
19
|
return image;
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
|
-
const _issvg = /*#__PURE__*/ _interop_require_default(require("is-svg"));
|
|
23
22
|
const _superstruct = require("superstruct");
|
|
23
|
+
const _internals = require("../../internals");
|
|
24
24
|
const _builder = require("../builder");
|
|
25
25
|
const _nodes = require("../nodes");
|
|
26
|
-
function _interop_require_default(obj) {
|
|
27
|
-
return obj && obj.__esModule ? obj : {
|
|
28
|
-
default: obj
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
26
|
function svg() {
|
|
32
27
|
return (0, _superstruct.refine)((0, _superstruct.string)(), 'SVG', (value)=>{
|
|
33
|
-
if (!(0,
|
|
28
|
+
if (!(0, _internals.isSvg)(value)) {
|
|
34
29
|
return 'Value is not a valid SVG.';
|
|
35
30
|
}
|
|
36
31
|
return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/ui/components/image.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../../../src/ui/components/image.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport { assign, literal, object, refine, string } from 'superstruct';\n\nimport { isSvg } from '../../internals';\nimport { createBuilder } from '../builder';\nimport { NodeStruct, NodeType } from '../nodes';\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 if (!isSvg(value)) {\n return 'Value is not a valid SVG.';\n }\n\n return true;\n });\n}\n\nexport const ImageStruct = assign(\n NodeStruct,\n object({\n type: literal(NodeType.Image),\n value: svg(),\n }),\n);\n\n/**\n * An image node, that renders an SVG image.\n *\n * @property type - The type of the node. Must be the string `image`.\n * @property value - The SVG image to be rendered.\n */\nexport type Image = Infer<typeof ImageStruct>;\n\n/**\n * Create an {@link Image} 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 SVG image to be rendered. Must be a valid SVG string.\n * @returns The image node as object. Other image formats are supported by\n * embedding them as data URLs in the SVG.\n * @example\n * const node = image({ value: '<svg />' });\n * const node = image('<svg />');\n */\nexport const image = createBuilder(NodeType.Image, ImageStruct, ['value']);\n"],"names":["svg","ImageStruct","image","refine","string","value","isSvg","assign","NodeStruct","object","type","literal","NodeType","Image","createBuilder"],"mappings":";;;;;;;;;;;IAagBA,GAAG;eAAHA;;IAUHC,WAAW;eAAXA;;IA4BAC,KAAK;eAALA;;;6BAlD2C;2BAElC;yBACQ;uBACO;AAQ9B,SAASF;IACd,OAAOG,IAAAA,mBAAM,EAACC,IAAAA,mBAAM,KAAI,OAAO,CAACC;QAC9B,IAAI,CAACC,IAAAA,gBAAK,EAACD,QAAQ;YACjB,OAAO;QACT;QAEA,OAAO;IACT;AACF;AAEO,MAAMJ,cAAcM,IAAAA,mBAAM,EAC/BC,iBAAU,EACVC,IAAAA,mBAAM,EAAC;IACLC,MAAMC,IAAAA,oBAAO,EAACC,eAAQ,CAACC,KAAK;IAC5BR,OAAOL;AACT;AAuBK,MAAME,QAAQY,IAAAA,sBAAa,EAACF,eAAQ,CAACC,KAAK,EAAEZ,aAAa;IAAC;CAAQ"}
|