UNPKG

@yuntijs/ui

Version:

☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps

40 lines 2.68 kB
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray"; import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties"; var _excluded = ["components", "remarkPlugins", "customComponentProps", "children"]; 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; } import { Markdown } from '@lobehub/ui'; import React, { useMemo } from 'react'; import { markdownElements } from "./MarkdownElements"; import { normalizeThinkTags } from "./utils"; import { jsx as _jsx } from "react/jsx-runtime"; var defaultRemarkPlugins = markdownElements.map(function (element) { return element.remarkPlugins; }); export var ChatMarkdown = function ChatMarkdown(_ref) { var _ref$components = _ref.components, components = _ref$components === void 0 ? {} : _ref$components, _ref$remarkPlugins = _ref.remarkPlugins, remarkPlugins = _ref$remarkPlugins === void 0 ? [] : _ref$remarkPlugins, customComponentProps = _ref.customComponentProps, children = _ref.children, props = _objectWithoutProperties(_ref, _excluded); var allComponents = useMemo(function () { var defaultComponents = Object.fromEntries(markdownElements.map(function (element) { return [element.tag, function (aprops) { return /*#__PURE__*/_jsx(element.Component, _objectSpread(_objectSpread({}, aprops), customComponentProps === null || customComponentProps === void 0 ? void 0 : customComponentProps[element.tag])); }]; })); return _objectSpread(_objectSpread({}, defaultComponents), components); }, [components, customComponentProps]); var allRemarkPlugins = useMemo(function () { return [].concat(_toConsumableArray(defaultRemarkPlugins), _toConsumableArray(remarkPlugins)); }, [remarkPlugins]); return /*#__PURE__*/_jsx(Markdown, _objectSpread(_objectSpread({ components: allComponents, remarkPlugins: allRemarkPlugins }, props), {}, { children: normalizeThinkTags(children) })); };