mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-08 17:22:26 +03:00
feat: react, vue3 and vanilla examples (#242)
* feat: react, vue3 and vanilla examples * fix: vue3 example * Create rare-worms-tease.md * fix: vue3 types * fix: vue3 ts checks * fix: vue3 render types * fix: vue3 component types
This commit is contained in:
@@ -5,14 +5,19 @@ import { render } from './render';
|
||||
|
||||
const content = (children: ReactNode, plugins?: BBobPlugins, options?: BBobCoreOptions) =>
|
||||
React.Children.map(children,
|
||||
(child) =>
|
||||
(typeof child === 'string' ? render(child, plugins, options) : child)
|
||||
(child) => {
|
||||
if (typeof child === 'string') {
|
||||
return render(child, plugins, options)
|
||||
}
|
||||
|
||||
return child
|
||||
}
|
||||
);
|
||||
|
||||
export type BBobReactComponentProps = {
|
||||
children: ReactNode
|
||||
container: string
|
||||
componentProps: Record<string, unknown>
|
||||
container?: string
|
||||
componentProps?: Record<string, unknown>
|
||||
plugins?: BBobPlugins
|
||||
options?: BBobCoreOptions
|
||||
}
|
||||
@@ -23,7 +28,7 @@ const Component = ({
|
||||
children,
|
||||
plugins = [],
|
||||
options = {},
|
||||
}: BBobReactComponentProps) => React.createElement(
|
||||
}: BBobReactComponentProps): React.JSX.Element => React.createElement(
|
||||
container,
|
||||
componentProps,
|
||||
content(children, plugins, options),
|
||||
|
||||
@@ -24,7 +24,9 @@ const toAST = (
|
||||
) =>
|
||||
core(plugins).process(source, {
|
||||
...options,
|
||||
render: (input) => htmlrender(input, { stripTags: true }),
|
||||
render: (input) => {
|
||||
return htmlrender(input, { stripTags: true })
|
||||
},
|
||||
}).tree;
|
||||
|
||||
const isContentEmpty = (content: TagNodeTree) => {
|
||||
@@ -65,7 +67,7 @@ function renderToReactNodes(nodes?: BBobCoreTagNodeTree | TagNodeTree) {
|
||||
const prevArr = arr; // stupid eslint
|
||||
const prevNode = lastIdx >= 0 ? prevArr[lastIdx] : null;
|
||||
|
||||
if (prevArr[lastIdx] && prevNode !== null && !isEOL(String(prevNode))) {
|
||||
if (prevArr[lastIdx] && isStringNode(prevArr[lastIdx]) && prevNode !== null && !isEOL(String(prevNode))) {
|
||||
prevArr[lastIdx] += String(node);
|
||||
|
||||
return prevArr;
|
||||
|
||||
Reference in New Issue
Block a user