/* * Copyright (c) Facebook, Inc. and its affiliates. */ import {Children, useContext, useMemo} from 'react'; import * as React from 'react'; import cn from 'classnames'; import CodeBlock from './CodeBlock'; import {CodeDiagram} from './CodeDiagram'; import ConsoleBlock from './ConsoleBlock'; import Convention from './Convention'; import ExpandableCallout from './ExpandableCallout'; import ExpandableExample from './ExpandableExample'; import {H1, H2, H3, H4} from './Heading'; import HomepageHero from './HomepageHero'; import InlineCode from './InlineCode'; import Intro from './Intro'; import Link from './Link'; import {PackageImport} from './PackageImport'; import Recap from './Recap'; import Sandpack from './Sandpack'; import Diagram from './Diagram'; import DiagramGroup from './DiagramGroup'; import SimpleCallout from './SimpleCallout'; import TerminalBlock from './TerminalBlock'; import YouWillLearnCard from './YouWillLearnCard'; import {Challenges, Hint, Solution} from './Challenges'; import {IconNavArrow} from '../Icon/IconNavArrow'; import ButtonLink from 'components/ButtonLink'; import {TocContext} from './TocContext'; import type {Toc, TocItem} from './TocContext'; function CodeStep({children, step}: {children: any; step: number}) { return ( {children} ); } const P = (p: JSX.IntrinsicElements['p']) => (

); const Strong = (strong: JSX.IntrinsicElements['strong']) => ( ); const OL = (p: JSX.IntrinsicElements['ol']) => (

    ); const LI = (p: JSX.IntrinsicElements['li']) => (
  1. ); const UL = (p: JSX.IntrinsicElements['ul']) => (
      ); const Divider = () => (
      ); const Wip = ({children}: {children: React.ReactNode}) => ( {children} ); const Gotcha = ({children}: {children: React.ReactNode}) => ( {children} ); const Note = ({children}: {children: React.ReactNode}) => ( {children} ); const Blockquote = ({ children, ...props }: JSX.IntrinsicElements['blockquote']) => { return (
      {children}
      ); }; function LearnMore({ children, path, }: { title: string; path?: string; children: any; }) { return ( <>

      Ready to learn this topic?

      {children} {path ? ( Read More ) : null}

      ); } function Math({children}: {children: any}) { return ( {children} ); } function MathI({children}: {children: any}) { return ( {children} ); } function YouWillLearn({ children, isChapter, }: { children: any; isChapter?: boolean; }) { let title = isChapter ? 'In this chapter' : 'You will learn'; return {children}; } // TODO: typing. function Recipes(props: any) { return ; } function AuthorCredit({ author, authorLink, }: { author: string; authorLink: string; }) { return (

      Illustrated by{' '} {authorLink ? ( {author} ) : ( author )}

      ); } function Illustration({ caption, src, alt, author, authorLink, }: { caption: string; src: string; alt: string; author: string; authorLink: string; }) { return (
      {alt} {caption ? (
      {caption}
      ) : null}
      {author ? : null}
      ); } function IllustrationBlock({ title, sequential, author, authorLink, children, }: { title: string; author: string; authorLink: string; sequential: boolean; children: any; }) { const imageInfos = Children.toArray(children).map( (child: any) => child.props ); const images = imageInfos.map((info, index) => (
      {info.alt}
      {info.caption ? (
      {info.caption}
      ) : null}
      )); return (
      {title ? (

      {title}

      ) : null} {sequential ? (
        {images.map((x: any, i: number) => (
      1. {x}
      2. ))}
      ) : (
      {images}
      )} {author ? : null}
      ); } type NestedTocRoot = { item: null; children: Array; }; type NestedTocNode = { item: TocItem; children: Array; }; function calculateNestedToc(toc: Toc): NestedTocRoot { const currentAncestors = new Map(); const root: NestedTocRoot = { item: null, children: [], }; const startIndex = 1; // Skip "Overview" for (let i = startIndex; i < toc.length; i++) { const item = toc[i]; const currentParent: NestedTocNode | NestedTocRoot = currentAncestors.get(item.depth - 1) || root; const node: NestedTocNode = { item, children: [], }; currentParent.children.push(node); currentAncestors.set(item.depth, node); } return root; } function InlineToc() { const toc = useContext(TocContext); const root = useMemo(() => calculateNestedToc(toc), [toc]); return ; } function InlineTocItem({items}: {items: Array}) { return (
        {items.map((node) => (
      • {node.item.text} {node.children.length > 0 && }
      • ))}
      ); } function LinkWithTodo({href, children, ...props}: JSX.IntrinsicElements['a']) { if (href?.startsWith('TODO')) { return children; } return ( {children} ); } export const MDXComponents = { p: P, strong: Strong, blockquote: Blockquote, ol: OL, ul: UL, li: LI, h1: H1, h2: H2, h3: H3, h4: H4, hr: Divider, a: LinkWithTodo, code: InlineCode, pre: CodeBlock, CodeDiagram, ConsoleBlock, Convention, DeepDive: (props: { children: React.ReactNode; title: string; excerpt: string; }) => , Diagram, DiagramGroup, FullWidth({children}: {children: any}) { return children; }, MaxWidth({children}: {children: any}) { return
      {children}
      ; }, Gotcha, Wip, HomepageHero, Illustration, IllustrationBlock, Intro, InlineToc, LearnMore, Math, MathI, Note, PackageImport, Recap, Recipes, Sandpack, TerminalBlock, YouWillLearn, YouWillLearnCard, Challenges, Hint, Solution, CodeStep, }; for (let key in MDXComponents) { if (MDXComponents.hasOwnProperty(key)) { const MDXComponent: any = (MDXComponents as any)[key]; MDXComponent.mdxName = key; } }