/* eslint-disable react-native/no-inline-styles */
import React, {
Children,
Fragment,
PropsWithChildren,
ReactElement,
useCallback
} from 'react';
import { ToolkitProvider, UIToolkitConfig, RefAPIProps } from '@doc/pages';
import BodyChapterMolecule from '../components/BodyChapterMolecule';
import BodySectionMolecule from '../components/BodySectionMolecule';
import BodyListAtom from '../components/BodyListAtom';
import BodyListItemAtom from '../components/BodyListItemAtom';
import BodyParagraphAtom from '../components/BodyParagraphAtom';
import RenderHtmlCardOrganism from '../components/RenderHtmlCardOrganism';
import UISourceDisplayMolecule from '../components/UISourceDisplayMolecule';
import { ScrollView } from 'react-native-gesture-handler';
import BodyAdmonitionAtom from '../components/BodyAdmonitionAtom';
import ArticleContainerAtom from '../components/ArticleContainerAtom';
import UIHyperlinkAtom from '../components/UIHyperlinkAtom';
import { useNavigation } from '@react-navigation/core';
import TextRoleNucleon from '../components/nucleons/TextRoleNucleon';
import svgAssetsIndex from '../svgAssetsIndex';
import { useColorPrimitives, useColorRoles } from '../theme/colorSystem';
import { Stack, useSpacing } from '@mobily/stacks';
import CardColorRolesProvider from '../components/croles/CardColorRolesProvider';
import { Linking, StyleSheet } from 'react-native';
import BoxNucleon from '../components/nucleons/BoxNucleon';
import { WEBSITE_URL } from '@doc/constants';
import URI from 'urijs';
import TNodeTransformDisplayOrganism from '../components/TNodeTransformDisplayOrganism';
import UICardContainer from '../components/UICardContainer';
import { BODY_PARAGRAPH_SPACING } from '../constants';
import MaxWidthContainerAtom from '../components/MaxWidthContainerAtom';
const genericOnLinkPress = (uri: string) => Linking.openURL(uri);
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
//@ts-ignore
function useOnLinkPress(uri: string): () => void;
function useOnLinkPress(): (uri: string) => void;
function useOnLinkPress(uri?: string) {
if (uri) {
// eslint-disable-next-line react-hooks/rules-of-hooks
return useCallback(() => genericOnLinkPress(uri), [uri]);
}
return genericOnLinkPress;
}
const styles = StyleSheet.create({
underline: {
textDecorationLine: 'underline'
}
});
const RefBuilder: UIToolkitConfig['RefBuilder'] = ({ name, url, type }) => {
const onLinkPress = useOnLinkPress(url);
return (
{name}
);
};
function Header({ children, ...other }: PropsWithChildren<{}>) {
return (
{children}
);
}
function RefAPI({
name,
url,
member,
full,
plural /* ,library */
}: RefAPIProps) {
const { apiRef } = useColorPrimitives();
const pluralMark = plural ? 's' : '';
const fullName =
(member && full ? `${name}.${member}` : member ? member : name) +
pluralMark;
const fullUrl = new URI(WEBSITE_URL + url).normalizePath().href();
return (
{fullName}
);
}
const SourceDisplayInner: UIToolkitConfig['SourceDisplay'] =
function SourceDisplayInner({ content, lang, showLineNumbers }) {
return (
);
};
const SourceDisplay: UIToolkitConfig['SourceDisplay'] = ({
title,
...other
}) => (
);
const RefDoc: UIToolkitConfig['RefDoc'] = ({ target, children, fragment }) => {
const navigation = useNavigation();
const onPress = useCallback(() => {
navigation.navigate(`${target.group}-${target.id}`, { fragment });
}, [navigation, target.group, target.id, fragment]);
return (
{children || target.title}
);
};
const Acronym: UIToolkitConfig['Acronym'] = ({ fullName }) => {
return ;
};
const Bold: UIToolkitConfig['Bold'] = ({ children }) => (
);
const SvgFigure: UIToolkitConfig['SvgFigure'] = ({
asset,
description,
title
}) => {
const Component = svgAssetsIndex[asset];
const { surface, codeBackground } = useColorRoles();
const padding = useSpacing(2);
return (
);
};
const toolkitConfig: UIToolkitConfig = {
Container: ArticleContainerAtom,
Chapter: BodyChapterMolecule,
Section: BodySectionMolecule,
List: BodyListAtom,
ListItem: BodyListItemAtom,
Paragraph: BodyParagraphAtom,
Bold,
Header,
RenderHtmlCard: RenderHtmlCardOrganism,
TNodeTransformDisplay: TNodeTransformDisplayOrganism,
SourceDisplay,
Admonition: BodyAdmonitionAtom,
RefBuilder,
RefAPI,
RefDoc,
Acronym,
SvgFigure: (props) => (
),
Hyperlink: ({ url, children }) => (
{children}
),
InlineCode: (props) => ,
DList: ({ children }) => (
{Children.map(children as ReactElement[], (c: ReactElement, i) =>
React.cloneElement(c, { ...c.props, index: Math.floor(i / 2) })
)}
),
DListItem: ({ children, index }: any) => (
{children}
),
DListTitle: ({ children, index }: any) => (
{children}
),
Conditional: ({ platform, children }) => {
return platform === 'mobile' ? {children} : null;
}
};
export default function PageToolkitProvider({
children
}: PropsWithChildren<{}>) {
return {children};
}