UNPKG

@mui/internal-docs-infra

Version:

MUI Infra - internal documentation creation tools.

78 lines 2.63 kB
import * as React from 'react'; import { CodeExternalsContext } from "../CodeExternalsContext/index.mjs"; import { jsx as _jsx } from "react/jsx-runtime"; /** * Abstract factory function for creating demo client providers. * This creates a provider component that supplies externals to child components. * * @param options Configuration options for the demo client factory * @returns A function that creates demo client providers */ export function abstractCreateDemoClient(options, url, meta) { // When the loader bails out (e.g. server-only modules) and there are no // controller props, return a passthrough so the generated `client.ts` still // has a valid default export — `React.lazy` consumers would otherwise throw // at render time on `default: undefined`. const precomputedExternals = meta?.precompute?.externals; const controllerProps = meta?.controllerProps; if (!precomputedExternals && controllerProps == null) { function PassthroughClientProvider({ children }) { return /*#__PURE__*/_jsx(React.Fragment, { children: children }); } if (process.env.NODE_ENV !== 'production') { PassthroughClientProvider.displayName = `PassthroughClientProvider(${meta?.name || 'Demo'})`; } return PassthroughClientProvider; } const externals = precomputedExternals || {}; const context = { externals }; const { DemoController } = options; function ClientProvider({ children }) { if (controllerProps != null) { return /*#__PURE__*/_jsx(CodeExternalsContext.Provider, { value: context, children: /*#__PURE__*/React.createElement(DemoController, Object.assign({}, controllerProps, { children })) }); } return /*#__PURE__*/_jsx(CodeExternalsContext.Provider, { value: context, children: /*#__PURE__*/React.createElement(DemoController, Object.assign({}, { children })) }); } if (process.env.NODE_ENV !== 'production') { ClientProvider.displayName = `ClientProvider(${meta?.name || 'Demo'})`; } return Object.assign(ClientProvider, { clientMeta: { url, options, meta, externals } }); } export function createDemoClientFactory(options) { /** * Creates a demo client provider with precomputed externals. * @param url Depends on `import.meta.url` to determine the source file location. * @param meta Additional meta and configuration for the demo client. */ const createDemoClient = (url, meta) => { return abstractCreateDemoClient(options, url, meta); }; return createDemoClient; }