import React, { PropsWithChildren, useMemo } from 'react';
import acronymsIndex from '../acronymsIndex';
import figuresIndex from '../figuresIndex';
import pagesSpecs from '../pagesSpecs';
import {
UIToolkit,
UIToolkitConfig,
UIToolkitRefs,
ImportStmt,
RendererCardConfig
} from './toolkit-types';
import toolkitContext from './toolkitContext';
import makeSnippet from './makeSnippet';
import defaultImports from './defaultImports';
import { TRenderEngine } from '@native-html/transient-render-engine';
import { HTMLSourceInline } from 'react-native-render-html';
function buildRefs(Builder: UIToolkitConfig['RefBuilder']): UIToolkitRefs {
return {
RefCssProperty: ({ name }) => (
),
RefESSymbol: ({ name }) => (
),
// TODO enhance this by parsing this page and generating a linkmap in a
// buildstep: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes
RefHtmlAttr: ({ name }) => (
),
RefHtmlElement: ({ name }) => (
`}
url={`https://mdn.io/${name}`}
/>
),
RefLibrary: ({ name, url }) => (
),
RefRNSymbol: ({ name }) => (
)
};
}
export default function ToolkitProvider({
children,
config
}: PropsWithChildren<{ config: UIToolkitConfig }>) {
const {
RefBuilder,
RenderHtmlCard,
RefDoc,
Acronym,
SvgFigure,
RefAPI,
...other
} = config;
const uitoolkit = useMemo(
() => ({
...other,
...buildRefs(RefBuilder),
RenderHtmlCard({
title,
caption,
props,
config: renderConfig,
preferHtmlSrc = false
}) {
const conf: Required = {
exprSrcMap: {},
fnSrcMap: {},
importStatements: [] as ImportStmt[],
wrapperComponent: null,
...renderConfig
};
return (
v.package)
.filter((pck) => !(pck in defaultImports))}
/>
);
},
RefDoc({ target, children, fragment }) {
if (!(target in pagesSpecs)) {
throw new Error(`Target "${target}" is not a registered page.`);
}
return (
);
},
Acronym({ name }) {
const acronym = acronymsIndex[name];
return ;
},
SvgFigure({ asset }) {
const assetSpecs = figuresIndex[asset];
return (
);
},
RefRenderHtmlProp({ name }) {
return (
);
},
RefCSSProcessor({ name, member, plural, full }) {
return (
);
},
RefDOM({ name, member, plural, full }) {
return (
);
},
RefRenderHTMLExport({ name, member, plural, full }) {
return (
);
},
RefTRE({ name, member, plural, full }) {
return (
);
}
}),
// eslint-disable-next-line react-hooks/exhaustive-deps
[...Object.values(other), RefBuilder]
);
return (
{children}
);
}