UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

95 lines (92 loc) 6.43 kB
'use client'; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } import { useMemo } from 'react'; import { CodeBlock } from "../../Markdown/components/CodeBlock"; import { useMarkdownContext } from "../../Markdown/components/MarkdownProvider"; import Image from "../../mdx/mdxComponents/Image"; import Link from "../../mdx/mdxComponents/Link"; import Section from "../../mdx/mdxComponents/Section"; import Video from "../../mdx/mdxComponents/Video"; import { jsx as _jsx } from "react/jsx-runtime"; export var useMarkdownComponents = function useMarkdownComponents() { var _componentProps$highl2, _componentProps$merma2; var _useMarkdownContext = useMarkdownContext(), components = _useMarkdownContext.components, animated = _useMarkdownContext.animated, citations = _useMarkdownContext.citations, componentProps = _useMarkdownContext.componentProps, showFootnotes = _useMarkdownContext.showFootnotes, enableMermaid = _useMarkdownContext.enableMermaid, fullFeaturedCodeBlock = _useMarkdownContext.fullFeaturedCodeBlock; var memoA = useMemo(function () { return function (props) { return /*#__PURE__*/_jsx(Link, _objectSpread(_objectSpread({ citations: citations }, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.a)); }; }, [citations, componentProps === null || componentProps === void 0 ? void 0 : componentProps.a]); var memoImg = useMemo(function () { return function (props) { return /*#__PURE__*/_jsx(Image, _objectSpread(_objectSpread({}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.img)); }; }, [componentProps === null || componentProps === void 0 ? void 0 : componentProps.img]); var memoVideo = useMemo(function () { return function (props) { return /*#__PURE__*/_jsx(Video, _objectSpread(_objectSpread({}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.video)); }; }, [componentProps === null || componentProps === void 0 ? void 0 : componentProps.video]); var memoSection = useMemo(function () { return function (props) { return /*#__PURE__*/_jsx(Section, _objectSpread({ showFootnotes: showFootnotes }, props)); }; }, [showFootnotes]); // Stable references for theme objects to prevent unnecessary re-renders var highlightTheme = useMemo(function () { var _componentProps$highl; return componentProps === null || componentProps === void 0 || (_componentProps$highl = componentProps.highlight) === null || _componentProps$highl === void 0 ? void 0 : _componentProps$highl.theme; }, [JSON.stringify(componentProps === null || componentProps === void 0 || (_componentProps$highl2 = componentProps.highlight) === null || _componentProps$highl2 === void 0 ? void 0 : _componentProps$highl2.theme)]); var mermaidTheme = useMemo(function () { var _componentProps$merma; return componentProps === null || componentProps === void 0 || (_componentProps$merma = componentProps.mermaid) === null || _componentProps$merma === void 0 ? void 0 : _componentProps$merma.theme; }, [JSON.stringify(componentProps === null || componentProps === void 0 || (_componentProps$merma2 = componentProps.mermaid) === null || _componentProps$merma2 === void 0 ? void 0 : _componentProps$merma2.theme)]); // Create stable component props reference var stableComponentProps = useMemo(function () { if (!componentProps) return; return { highlight: componentProps.highlight ? _objectSpread(_objectSpread({}, componentProps.highlight), {}, { theme: highlightTheme }) : undefined, mermaid: componentProps.mermaid ? _objectSpread(_objectSpread({}, componentProps.mermaid), {}, { theme: mermaidTheme }) : undefined }; }, [highlightTheme, mermaidTheme]); var memoPre = useMemo(function () { return function (props) { return /*#__PURE__*/_jsx(CodeBlock, _objectSpread(_objectSpread(_objectSpread({ animated: animated, enableMermaid: enableMermaid, fullFeatured: fullFeaturedCodeBlock }, stableComponentProps), componentProps === null || componentProps === void 0 ? void 0 : componentProps.pre), props)); }; }, [animated, enableMermaid, fullFeaturedCodeBlock, stableComponentProps, componentProps === null || componentProps === void 0 ? void 0 : componentProps.pre]); var memoComponents = useMemo(function () { return { a: memoA, img: memoImg, pre: memoPre, section: memoSection, video: memoVideo }; }, [memoA, memoImg, memoVideo, memoPre, memoSection]); return useMemo(function () { return _objectSpread(_objectSpread({}, memoComponents), components); }, [memoComponents, components]); };