{"version":3,"file":"RichText.components.mjs","sources":["../../src/RichText.components.tsx"],"sourcesContent":["import {createElement, type ReactNode} from 'react';\n\nexport type CustomComponents = {\n  /** The root node of the rich text. Defaults to `<div>` */\n  root?: typeof Root;\n  /** Customize the headings. Each heading has a `level` property from 1-6. Defaults to `<h1>` to `<h6>` */\n  heading?: typeof Heading;\n  /** Customize paragraphs. Defaults to `<p>` */\n  paragraph?: typeof Paragraph;\n  /** Customize how text nodes. They can either be bold or italic. Defaults to `<em>`, `<strong>` or text. */\n  text?: typeof Text;\n  /** Customize links. Defaults to a React Router `<Link>` component in Hydrogen and a `<a>` in Hydrogen React. */\n  link?: typeof RichTextLink;\n  /** Customize lists. They can be either ordered or unordered. Defaults to `<ol>` or `<ul>` */\n  list?: typeof List;\n  /** Customize list items. Defaults to `<li>`. */\n  listItem?: typeof ListItem;\n};\n\nexport const RichTextComponents = {\n  root: Root,\n  heading: Heading,\n  paragraph: Paragraph,\n  text: Text,\n  link: RichTextLink,\n  list: List,\n  'list-item': ListItem,\n};\n\nfunction Root({\n  node,\n}: {\n  node: {\n    type: 'root';\n    children?: ReactNode[];\n  };\n}): ReactNode {\n  return <div>{node.children}</div>;\n}\n\nfunction Heading({\n  node,\n}: {\n  node: {\n    type: 'heading';\n    level: number;\n    children?: ReactNode[];\n  };\n}): ReactNode {\n  return createElement(`h${node.level ?? '1'}`, null, node.children);\n}\n\nfunction Paragraph({\n  node,\n}: {\n  node: {\n    type: 'paragraph';\n    children?: ReactNode[];\n  };\n}): ReactNode {\n  return <p>{node.children}</p>;\n}\n\nfunction Text({\n  node,\n}: {\n  node: {\n    type: 'text';\n    italic?: boolean;\n    bold?: boolean;\n    value?: string;\n  };\n}): ReactNode {\n  if (node.bold && node.italic)\n    return (\n      <em>\n        <strong>{node.value}</strong>\n      </em>\n    );\n\n  if (node.bold) return <strong>{node.value}</strong>;\n  if (node.italic) return <em>{node.value}</em>;\n\n  return node.value;\n}\n\nfunction RichTextLink({\n  node,\n}: {\n  node: {\n    type: 'link';\n    url: string;\n    title?: string;\n    target?: string;\n    children?: ReactNode[];\n  };\n}): ReactNode {\n  return (\n    <a href={node.url} title={node.title} target={node.target}>\n      {node.children}\n    </a>\n  );\n}\n\nfunction List({\n  node,\n}: {\n  node: {\n    type: 'list';\n    listType: 'unordered' | 'ordered';\n    children?: ReactNode[];\n  };\n}): ReactNode {\n  const List = node.listType === 'unordered' ? 'ul' : 'ol';\n  return <List>{node.children}</List>;\n}\n\nfunction ListItem({\n  node,\n}: {\n  node: {\n    type: 'list-item';\n    children?: ReactNode[];\n  };\n}): ReactNode {\n  return <li>{node.children}</li>;\n}\n"],"names":["List"],"mappings":";;AAmBO,MAAM,qBAAqB;AAAA,EAChC,MAAM;AAAA,EACN,SAAS;AAAA,EACT,WAAW;AAAA,EACX,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AAAA,EACN,aAAa;AACf;AAEA,SAAS,KAAK;AAAA,EACZ;AACF,GAKc;AACZ,SAAO,oBAAC,OAAA,EAAK,UAAA,KAAK,SAAA,CAAS;AAC7B;AAEA,SAAS,QAAQ;AAAA,EACf;AACF,GAMc;AACZ,SAAO,cAAc,IAAI,KAAK,SAAS,GAAG,IAAI,MAAM,KAAK,QAAQ;AACnE;AAEA,SAAS,UAAU;AAAA,EACjB;AACF,GAKc;AACZ,SAAO,oBAAC,KAAA,EAAG,UAAA,KAAK,SAAA,CAAS;AAC3B;AAEA,SAAS,KAAK;AAAA,EACZ;AACF,GAOc;AACZ,MAAI,KAAK,QAAQ,KAAK;AACpB,+BACG,MAAA,EACC,UAAA,oBAAC,UAAA,EAAQ,UAAA,KAAK,OAAM,EAAA,CACtB;AAGJ,MAAI,KAAK,KAAM,QAAO,oBAAC,UAAA,EAAQ,eAAK,OAAM;AAC1C,MAAI,KAAK,OAAQ,QAAO,oBAAC,MAAA,EAAI,eAAK,OAAM;AAExC,SAAO,KAAK;AACd;AAEA,SAAS,aAAa;AAAA,EACpB;AACF,GAQc;AACZ,SACE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