2023-09-29 16:01:27 +02:00
|
|
|
// __SDEFILE__ - This file is a dependency for the stand-alone environment
|
2023-10-06 09:15:07 +02:00
|
|
|
// Dependencies
|
|
|
|
import * as runtime from 'react/jsx-runtime'
|
2023-10-09 11:42:16 +02:00
|
|
|
import { run, runSync } from '@mdx-js/mdx'
|
2023-10-06 09:15:07 +02:00
|
|
|
import { useState, useEffect } from 'react'
|
2023-05-15 15:57:46 +02:00
|
|
|
// Components that are available in MDX content
|
|
|
|
import { components as baseComponents } from 'shared/components/mdx/index.mjs'
|
2023-10-06 09:15:07 +02:00
|
|
|
// Loading component when running async
|
|
|
|
import { Loading } from 'shared/components/spinner.mjs'
|
2021-12-18 09:54:53 +01:00
|
|
|
|
2023-10-06 09:15:07 +02:00
|
|
|
/*
|
|
|
|
* This runs MDX that is compiled as function-body
|
|
|
|
* By run, I mean it turns it into a React component
|
|
|
|
* This is the default async version
|
|
|
|
*/
|
|
|
|
const runMdx = async (mdx) => {
|
2023-10-09 11:42:16 +02:00
|
|
|
const { default: Content } = await run(mdx, runtime)
|
2023-06-17 16:57:17 -05:00
|
|
|
|
2023-10-06 09:15:07 +02:00
|
|
|
return Content
|
2023-06-17 16:57:17 -05:00
|
|
|
}
|
|
|
|
|
2023-10-06 09:15:07 +02:00
|
|
|
/*
|
|
|
|
* This runs MDX that is compiled as function-body
|
|
|
|
* By run, I mean it turns it into a React component
|
|
|
|
* This is the sync version because SSR does not run effects
|
|
|
|
*/
|
|
|
|
const runMdxSync = (mdx) => {
|
|
|
|
const { default: Content } = runSync(mdx, runtime)
|
|
|
|
|
|
|
|
return Content
|
|
|
|
}
|
|
|
|
|
|
|
|
export const PlainMdxWrapperAsync = ({ mdx = false, components = {}, site = 'org', slug = [] }) => {
|
|
|
|
/*
|
|
|
|
* Merge passed-in components with the base components
|
|
|
|
*/
|
|
|
|
const allComponents = { ...baseComponents(site, slug), ...components }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up state for MDX as running it is handled async in useEffect
|
|
|
|
*/
|
|
|
|
const [MDX, setMDX] = useState(false)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run the mdx compiled as function-body and turn it into a component
|
|
|
|
*/
|
|
|
|
useEffect(() => {
|
|
|
|
const run = async () => {
|
|
|
|
const Content = await runMdx(mdx, allComponents)
|
|
|
|
setMDX(<Content components={allComponents} />)
|
|
|
|
}
|
|
|
|
if (mdx) run()
|
|
|
|
}, [mdx])
|
|
|
|
|
|
|
|
return <div className="searchme">{MDX ? MDX : <Loading />}</div>
|
|
|
|
}
|
|
|
|
|
|
|
|
export const PlainMdxWrapperSync = ({ mdx = false, components = {}, site = 'org', slug = [] }) => {
|
|
|
|
/*
|
|
|
|
* Merge passed-in components with the base components
|
|
|
|
*/
|
|
|
|
const allComponents = { ...baseComponents(site, slug), ...components }
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run mdx sync
|
|
|
|
*/
|
|
|
|
const Content = runMdxSync(mdx, allComponents)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="searchme">
|
|
|
|
<Content components={allComponents} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const MdxWrapper = ({
|
|
|
|
mdx = false,
|
|
|
|
components = {},
|
|
|
|
site = 'org',
|
|
|
|
async = false,
|
|
|
|
slug = [],
|
|
|
|
}) => (
|
2023-07-13 21:15:25 +02:00
|
|
|
<div className="text-primary mdx max-w-prose text-base-content max-w-prose text-base">
|
2023-10-06 09:15:07 +02:00
|
|
|
{async ? (
|
|
|
|
<PlainMdxWrapperAsync {...{ mdx, components, site, slug }} />
|
|
|
|
) : (
|
|
|
|
<PlainMdxWrapperSync {...{ mdx, components, site, slug }} />
|
|
|
|
)}
|
2023-07-13 21:15:25 +02:00
|
|
|
</div>
|
|
|
|
)
|