UNPKG

@metamask/snaps-sdk

Version:

A library containing the core functionality for building MetaMask Snaps

1 lines 4.12 kB
{"version":3,"file":"panel.cjs","sourceRoot":"","sources":["../../../src/ui/components/panel.ts"],"names":[],"mappings":";;;AACA,uDAAoE;AAEpE,2CAA0C;AAC1C,yCAAwC;AACxC,6CAA4C;AAC5C,2CAA0C;AAC1C,qCAAoC;AACpC,2CAA0C;AAC1C,uCAAsC;AACtC,uCAAsC;AACtC,mCAAkC;AAClC,2CAA0C;AAC1C,qCAAoC;AACpC,yDAAsD;AACtD,4CAA2C;AAC3C,wCAAgD;AAEhD;;GAEG;AACU,QAAA,YAAY,GAAG,IAAA,oBAAM,EAChC,kBAAU,EACV,IAAA,oBAAM,EAAC;IACL,sEAAsE;IACtE,mEAAmE;IACnE,QAAQ,EAAE,IAAA,mBAAK,EAAC,IAAA,kBAAI,EAAC,GAAG,EAAE,CAAC,uBAAe,CAAC,CAAC;CAC7C,CAAC,CACH,CAAC;AAYF;;GAEG;AACU,QAAA,WAAW,GAAkB,IAAA,oBAAM,EAC9C,oBAAY,EACZ,IAAA,oBAAM,EAAC;IACL,IAAI,EAAE,IAAA,mBAAO,EAAC,gBAAQ,CAAC,KAAK,CAAC;CAC9B,CAAC,CACH,CAAC;AAeF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACU,QAAA,KAAK,GAAG,IAAA,uBAAa,EAAC,gBAAQ,CAAC,KAAK,EAAE,mBAAW,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;AAE9E,8EAA8E;AACjE,QAAA,eAAe,GAAG,IAAA,sBAAU,EAAC;IACxC,yBAAc;IACd,uBAAa;IACb,uBAAa;IACb,mBAAW;IACX,mBAAW;IACX,uBAAa;IACb,iBAAU;IACV,eAAS;IACT,uBAAa;IACb,mBAAW;IACX,iBAAU;IACV,qBAAY;CACb,CAAC,CAAC","sourcesContent":["import type { Infer, Struct } from '@metamask/superstruct';\nimport { array, assign, lazy, object } from '@metamask/superstruct';\n\nimport { AddressStruct } from './address';\nimport { ButtonStruct } from './button';\nimport { CopyableStruct } from './copyable';\nimport { DividerStruct } from './divider';\nimport { FormStruct } from './form';\nimport { HeadingStruct } from './heading';\nimport { ImageStruct } from './image';\nimport { InputStruct } from './input';\nimport { RowStruct } from './row';\nimport { SpinnerStruct } from './spinner';\nimport { TextStruct } from './text';\nimport { typedUnion, literal } from '../../internals';\nimport { createBuilder } from '../builder';\nimport { NodeStruct, NodeType } from '../nodes';\n\n/**\n * @internal\n */\nexport const ParentStruct = assign(\n NodeStruct,\n object({\n // This node references itself indirectly, so we need to use `lazy()`.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n children: array(lazy(() => ComponentStruct)),\n }),\n);\n\n/**\n * A node which supports child nodes. This is used for nodes that render their\n * children, such as {@link Panel}.\n *\n * @property type - The type of the node.\n * @property children - The children of the node\n * @internal\n */\nexport type Parent = Infer<typeof ParentStruct>;\n\n/**\n * @internal\n */\nexport const PanelStruct: Struct<Panel> = assign(\n ParentStruct,\n object({\n type: literal(NodeType.Panel),\n }),\n);\n\n/**\n * A panel node, which renders its children.\n *\n * @property type - The type of the node, must be the string 'text'.\n * @property value - The text content of the node, either as plain text, or as a\n * markdown string.\n */\n// This node references itself indirectly, so it cannot be inferred.\nexport type Panel = {\n type: NodeType.Panel;\n children: Component[];\n};\n\n/**\n * Create a {@link Panel} node.\n *\n * @param args - The node arguments. This can be either an array of children, or\n * an object with a `children` property.\n * @param args.children - The child nodes of the panel. This can be any valid\n * {@link Component}.\n * @returns The panel node as object.\n * @deprecated Snaps component functions are deprecated, in favor of the new JSX\n * components. This function will be removed in a future release.\n * @example\n * const node = panel({\n * children: [\n * heading({ text: 'Hello, world!' }),\n * text({ text: 'This is a panel.' }),\n * ],\n * });\n *\n * const node = panel([\n * heading('Hello, world!'),\n * text('This is a panel.'),\n * ]);\n */\nexport const panel = createBuilder(NodeType.Panel, PanelStruct, ['children']);\n\n// This is defined separately from `Component` to avoid circular dependencies.\nexport const ComponentStruct = typedUnion([\n CopyableStruct,\n DividerStruct,\n HeadingStruct,\n ImageStruct,\n PanelStruct,\n SpinnerStruct,\n TextStruct,\n RowStruct,\n AddressStruct,\n InputStruct,\n FormStruct,\n ButtonStruct,\n]);\n\n/**\n * All supported component types.\n */\nexport type Component = Infer<typeof ComponentStruct>;\n"]}