import React, { createContext, useContext, useEffect, useMemo, useRef, useState } from 'react' import { HighlightedCode } from 'codehike/code'; import { Settings } from "@xyd-js/core" import { Anchor, Badge, Blockquote, Callout, Code, CodeTutorialSteps, Details, GuideCard, Heading, Hr, Table, Tabs, Steps, List, ListOl, Text, Button, Icon, Image, Update, Card, ColorSchemeButton, Breadcrumbs } from '../../writer' import { PageHome, PageFirstSlide, PageBlogHome } from '../../pages' import { CodeSample } from "../../coder"; import { GridDecorator } from './GridDecorator'; import { useUXEvents } from '../uxsdk'; interface ReactContentOptions { Link?: React.ElementType components?: { [component: string]: (props: any) => React.JSX.Element | null } useLocation?: () => { search: string } // TODO: !!!! BETTER API !!!!! useNavigate?: (to: any) => void // TODO: !!!! BETTER API !!!!! useNavigation?: () => any, // TODO: !!!! BETTER API !!!!! } export class ReactContent { constructor( protected settings?: Settings, protected options?: ReactContentOptions ) { } public components(): { [component: string]: (props: any) => React.JSX.Element | null } { const builtInComponents = [ stdContent, writerContent, pageComponents, iconContent, coderContent, directiveContent, contentDecorators, ] .map(fn => fn.bind(this)) .reduce((acc, fn) => ({ ...acc, ...fn() }), {}); return { ...builtInComponents, ...this.options?.components || {} } } public noop() { const components = this.components() const noopBuiltInFlatComponents = [ ...Object.keys(components), ...Object.keys(this.options?.components || {}) ].reduce((acc, key) => { acc[key] = () => null return acc }, {}) const noopNestedComponents = { Steps: NoopComponent, Tabs: NoopComponent, GuideCard: NoopComponent, Table: NoopComponent, CodeTutorialSteps: NoopComponent, } return { ...noopBuiltInFlatComponents, ...noopNestedComponents, React: NoopReactComponent, } } } function NoopComponent() { return null } NoopComponent.Item = () => null NoopComponent.Content = () => null NoopComponent.List = () => null NoopComponent.Head = () => null NoopComponent.Td = () => null NoopComponent.Tr = () => null NoopComponent.Th = () => null NoopComponent.Cell = () => null NoopComponent.Step = () => null NoopComponent.Title = () => null NoopComponent.Body = () => null NoopComponent.Aside = () => null function NoopReactComponent() { // TODO: !!!! in the future refactor but `html-to-jsx-transform` creates !!! return null } NoopReactComponent.Fragment = React.Fragment export function stdContent( this: ReactContent, ) { const $$Pre = $Pre.bind(this) const $$Heading = $Heading.bind(this) const stdComponents = { h1: (props) => { return <$$Heading depth={1} {...props} noanchor /> }, h2: props => { const appearance = this.settings?.theme?.appearance return <> {appearance?.content?.sectionSeparator ?
: null} <$$Heading depth={2} {...props} /> }, h3: props => { return <$$Heading depth={3} {...props} /> }, h4: props => { return <$$Heading depth={4} {...props} /> }, h5: props => { return <$$Heading depth={5} {...props} /> }, p: props => { return }, ul: props => { return {props.children} }, ol: props => { return {props.children} }, li: props => { return {props.children} }, table: (props) => { const kind = this.settings?.theme?.appearance?.tables?.kind return }, tr: (props) => { return }, th: (props) => { return }, td: (props) => { return {props.children} }, code: (props) => { return }, pre: $$Pre, details: (props) => { return
}, blockquote: (props) => { return
}, hr: ({ children, ...props }) => { return
}, a: (props) => { return <$Link {...props} as={this?.options?.Link} /> }, br: ({ children, ...props }) => { return
}, img: ({ children, src, alt, ...props }) => { return }, picture: (props) => { const { children, ...rest } = props return {children} }, source: (props) => { const { children, ...rest } = props return }, input: ({ children, ...props }) => { return }, textarea: ({ children, ...props }) => { return