@metamask/snaps-sdk
Version:
A library containing the core functionality for building MetaMask Snaps
1 lines • 3.21 kB
Source Map (JSON)
{"version":3,"file":"jsx-runtime.mjs","sourceRoot":"","sources":["../../src/jsx/jsx-runtime.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,GAAG,CACjB,SAA+B,EAC/B,KAAY,EACZ,GAAe;IAEf,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;QAClC,uEAAuE;QACvE,4CAA4C;QAC5C,MAAM,IAAI,KAAK,CACb,qBAAqB,MAAM,CACzB,SAAS,CACV,uHAAuH,CACzH,CAAC;IACJ,CAAC;IAED,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,0EAA0E;QAC1E,0BAA0B;QAC1B,MAAM,IAAI,KAAK,CACb,mIAAmI,CACpI,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC,EAAE,GAAG,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,IAAI,CAClB,SAA+B,EAC/B,KAAY,EACZ,GAAe;IAEf,OAAO,GAAG,CAAC,SAAS,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AACpC,CAAC","sourcesContent":["import type { JsonObject, Key, SnapComponent } from './component';\n\n/**\n * The JSX runtime for Snaps SDK components. This function is used to render\n * Snap components into a format that can be used by the Snaps.\n *\n * This is the \"production\" version of the runtime, which does not include\n * additional validation, as it is handled by MetaMask. To use this runtime,\n * specify `@metamask/snaps-sdk` as import source for JSX, and use `react-jsx`\n * as the pragma.\n *\n * @param component - The component to render.\n * @param props - The props to pass to the component.\n * @param key - The key of the component.\n * @returns The rendered component.\n * @see https://www.typescriptlang.org/tsconfig/#jsx\n */\nexport function jsx<Props extends JsonObject>(\n component: SnapComponent<Props>,\n props: Props,\n key: Key | null,\n): unknown | null {\n if (typeof component === 'string') {\n // If component is a string, it is a built-in HTML element. This is not\n // supported in Snaps, so we throw an error.\n throw new Error(\n `An HTML element (\"${String(\n component,\n )}\") was used in a Snap component, which is not supported by Snaps UI. Please use one of the supported Snap components.`,\n );\n }\n\n if (!component) {\n // If component is undefined, a JSX fragment `<>...</>` was used, which is\n // not supported in Snaps.\n throw new Error(\n 'A JSX fragment was used in a Snap component, which is not supported by Snaps UI. Please use one of the supported Snap components.',\n );\n }\n\n return component({ ...props, key });\n}\n\n/**\n * The JSX runtime for Snaps SDK components. This function is used to render\n * Snap components into a format that can be used by the Snaps.\n *\n * The `jsxs` function is used for rendering nested components.\n *\n * This is the \"production\" version of the runtime, which does not include\n * additional validation, as it is handled by MetaMask. To use this runtime,\n * specify `@metamask/snaps-sdk` as import source for JSX, and use `react-jsx`\n * as the pragma.\n *\n * @param component - The component to render.\n * @param props - The props to pass to the component.\n * @param key - The key of the component.\n * @returns The rendered component.\n * @see https://www.typescriptlang.org/tsconfig/#jsx\n */\nexport function jsxs<Props extends JsonObject>(\n component: SnapComponent<Props>,\n props: Props,\n key: Key | null,\n): unknown | null {\n return jsx(component, props, key);\n}\n"]}