UNPKG

@mui/internal-docs-infra

Version:

MUI Infra - internal documentation creation tools.

73 lines 2.87 kB
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; import _typeof from "@babel/runtime/helpers/esm/typeof"; import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray"; import { stringOrHastToJsx } from "../pipeline/hastUtils/index.js"; function toExtraSource(variantCode, fileName) { return Object.entries(variantCode.extraFiles || {}).reduce(function (acc, _ref) { var _ref2 = _slicedToArray(_ref, 2), name = _ref2[0], file = _ref2[1]; if (name !== fileName && _typeof(file) === 'object' && file != null && file.source) { acc[name] = stringOrHastToJsx(file.source); } return acc; }, {}); } export function codeToFallbackProps(variant, code, fileName) { var needsAllFiles = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; var needsAllVariants = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; var variantCode = code == null ? void 0 : code[variant]; if (!variantCode || typeof variantCode === 'string') { return {}; } var fileNames = [variantCode.fileName].concat(_toConsumableArray(Object.keys(variantCode.extraFiles || {}))).filter(function (name) { return Boolean(name); }); var source; if (fileName) { var _variantCode$extraFil; var fileData = (_variantCode$extraFil = variantCode.extraFiles) == null ? void 0 : _variantCode$extraFil[fileName]; if (fileData && _typeof(fileData) === 'object' && 'source' in fileData && fileData.source) { source = stringOrHastToJsx(fileData.source); } } else if (variantCode.source) { source = stringOrHastToJsx(variantCode.source); } if (needsAllVariants || needsAllFiles) { var extraSource = toExtraSource(variantCode, fileName); if (needsAllVariants) { var extraVariants = Object.entries(code || {}).reduce(function (acc, _ref3) { var _ref4 = _slicedToArray(_ref3, 2), name = _ref4[0], vCode = _ref4[1]; if (name !== variant && vCode && typeof vCode !== 'string') { var extraVariantExtraSource = toExtraSource(vCode, vCode.fileName); acc[name] = { fileNames: [vCode.fileName].concat(_toConsumableArray(Object.keys(vCode.extraFiles || {}))).filter(function (fn) { return Boolean(fn); }), // TODO: use filesOrder if provided source: vCode.source && stringOrHastToJsx(vCode.source), extraSource: extraVariantExtraSource }; } return acc; }, {}); return { fileNames: fileNames, source: source, extraSource: extraSource, extraVariants: extraVariants }; } return { fileNames: fileNames, source: source, extraSource: extraSource }; } return { fileNames: fileNames, source: source }; }