@lobehub/ui 1.164.16 → 1.165.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,10 +8,12 @@ import { type ImageProps } from "../mdx/mdxComponents/Image";
8
8
  import { type PreProps } from "../mdx/mdxComponents/Pre";
9
9
  import { type VideoProps } from "../mdx/mdxComponents/Video";
10
10
  import type { AProps } from "../types";
11
+ import { CitationItem } from "../types/citation";
11
12
  import type { TypographyProps } from './Typography';
12
13
  export interface MarkdownProps extends TypographyProps {
13
14
  allowHtml?: boolean;
14
15
  children: string;
16
+ citations?: CitationItem[];
15
17
  className?: string;
16
18
  componentProps?: {
17
19
  a?: Partial<AProps & AnchorProps>;
@@ -33,6 +35,7 @@ export interface MarkdownProps extends TypographyProps {
33
35
  rehypePlugins?: Pluggable[];
34
36
  remarkPlugins?: Pluggable[];
35
37
  remarkPluginsAhead?: Pluggable[];
38
+ showFootnotes?: boolean;
36
39
  style?: CSSProperties;
37
40
  variant?: 'normal' | 'chat';
38
41
  }
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
 
3
3
  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); }
4
- var _excluded = ["children", "className", "style", "fullFeaturedCodeBlock", "onDoubleClick", "enableLatex", "enableMermaid", "enableImageGallery", "componentProps", "allowHtml", "fontSize", "headerMultiple", "marginMultiple", "variant", "lineHeight", "rehypePlugins", "remarkPlugins", "remarkPluginsAhead", "components", "customRender"];
4
+ var _excluded = ["children", "className", "style", "fullFeaturedCodeBlock", "onDoubleClick", "enableLatex", "enableMermaid", "enableImageGallery", "componentProps", "allowHtml", "fontSize", "headerMultiple", "marginMultiple", "showFootnotes", "variant", "lineHeight", "rehypePlugins", "remarkPlugins", "remarkPluginsAhead", "components", "customRender", "citations"];
5
5
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
6
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
7
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -25,12 +25,14 @@ import remarkMath from 'remark-math';
25
25
  import ImageGallery from "../Image/ImageGallery";
26
26
  import Image from "../mdx/mdxComponents/Image";
27
27
  import Link from "../mdx/mdxComponents/Link";
28
+ import Section from "../mdx/mdxComponents/Section";
28
29
  import Video from "../mdx/mdxComponents/Video";
29
30
  import { CodeFullFeatured, CodeLite } from "./CodeBlock";
30
31
  import { useStyles as useMarkdownStyles } from "./markdown.style";
31
- import { rehypeKatexDir } from "./rehypePlugin";
32
+ import { rehypeFootnoteLinks, remarkCustomFootnotes } from "./plugins/footnote";
33
+ import { rehypeKatexDir } from "./plugins/katexDir";
32
34
  import { useStyles } from "./style";
33
- import { escapeBrackets, escapeMhchem, fixMarkdownBold } from "./utils";
35
+ import { escapeBrackets, escapeMhchem, fixMarkdownBold, transformCitations } from "./utils";
34
36
  import { jsx as _jsx } from "react/jsx-runtime";
35
37
  var Markdown = /*#__PURE__*/memo(function (_ref) {
36
38
  var children = _ref.children,
@@ -49,6 +51,7 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
49
51
  fontSize = _ref.fontSize,
50
52
  headerMultiple = _ref.headerMultiple,
51
53
  marginMultiple = _ref.marginMultiple,
54
+ showFootnotes = _ref.showFootnotes,
52
55
  _ref$variant = _ref.variant,
53
56
  variant = _ref$variant === void 0 ? 'normal' : _ref$variant,
54
57
  lineHeight = _ref.lineHeight,
@@ -58,6 +61,7 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
58
61
  _ref$components = _ref.components,
59
62
  components = _ref$components === void 0 ? {} : _ref$components,
60
63
  customRender = _ref.customRender,
64
+ citations = _ref.citations,
61
65
  rest = _objectWithoutProperties(_ref, _excluded);
62
66
  var _useStyles = useStyles({
63
67
  fontSize: fontSize,
@@ -76,12 +80,14 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
76
80
  var isChatMode = variant === 'chat';
77
81
  var escapedContent = useMemo(function () {
78
82
  if (!enableLatex) return fixMarkdownBold(children);
79
- return fixMarkdownBold(escapeMhchem(escapeBrackets(children)));
83
+ return transformCitations(fixMarkdownBold(escapeMhchem(escapeBrackets(children))), citations === null || citations === void 0 ? void 0 : citations.length);
80
84
  }, [children, enableLatex]);
81
85
  var memoComponents = useMemo(function () {
82
86
  return _objectSpread({
83
87
  a: function a(props) {
84
- return /*#__PURE__*/_jsx(Link, _objectSpread(_objectSpread({}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.a));
88
+ return /*#__PURE__*/_jsx(Link, _objectSpread(_objectSpread({
89
+ citations: citations
90
+ }, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.a));
85
91
  },
86
92
  img: enableImageGallery ? function (props) {
87
93
  var _componentProps$img, _componentProps$img2;
@@ -103,19 +109,24 @@ var Markdown = /*#__PURE__*/memo(function (_ref) {
103
109
  mermaid: componentProps === null || componentProps === void 0 ? void 0 : componentProps.mermaid
104
110
  }, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.pre));
105
111
  },
112
+ section: function section(props) {
113
+ return /*#__PURE__*/_jsx(Section, _objectSpread({
114
+ showCitations: showFootnotes
115
+ }, props));
116
+ },
106
117
  video: function video(props) {
107
118
  return /*#__PURE__*/_jsx(Video, _objectSpread(_objectSpread({}, props), componentProps === null || componentProps === void 0 ? void 0 : componentProps.video));
108
119
  }
109
120
  }, components);
110
- }, [].concat(_toConsumableArray(Object.values(components || {})), _toConsumableArray(Object.values(componentProps || {})), [enableImageGallery, enableMermaid, fullFeaturedCodeBlock]));
121
+ }, [].concat(_toConsumableArray(Object.values(components || {})), _toConsumableArray(Object.values(componentProps || {})), [enableImageGallery, enableMermaid, fullFeaturedCodeBlock], _toConsumableArray(citations || []), [showFootnotes]));
111
122
  var innerRehypePlugins = Array.isArray(rehypePlugins) ? rehypePlugins : [rehypePlugins];
112
123
  var memoRehypePlugins = useMemo(function () {
113
- return [allowHtml && rehypeRaw, enableLatex && rehypeKatex, enableLatex && rehypeKatexDir].concat(_toConsumableArray(innerRehypePlugins)).filter(Boolean);
124
+ return [allowHtml && rehypeRaw, enableLatex && rehypeKatex, enableLatex && rehypeKatexDir, rehypeFootnoteLinks].concat(_toConsumableArray(innerRehypePlugins)).filter(Boolean);
114
125
  }, [allowHtml, enableLatex].concat(_toConsumableArray(innerRehypePlugins)));
115
126
  var innerRemarkPlugins = Array.isArray(remarkPlugins) ? remarkPlugins : [remarkPlugins];
116
127
  var innerRemarkPluginsAhead = Array.isArray(remarkPluginsAhead) ? remarkPluginsAhead : [remarkPluginsAhead];
117
128
  var memoRemarkPlugins = useMemo(function () {
118
- return [].concat(_toConsumableArray(innerRemarkPluginsAhead), [remarkGfm, enableLatex && remarkMath, isChatMode && remarkBreaks], _toConsumableArray(innerRemarkPlugins)).filter(Boolean);
129
+ return [].concat(_toConsumableArray(innerRemarkPluginsAhead), [remarkGfm, remarkCustomFootnotes, enableLatex && remarkMath, isChatMode && remarkBreaks], _toConsumableArray(innerRemarkPlugins)).filter(Boolean);
119
130
  }, [isChatMode, enableLatex].concat(_toConsumableArray(innerRemarkPluginsAhead), _toConsumableArray(innerRemarkPlugins)));
120
131
  var defaultDOM = /*#__PURE__*/_jsx(ImageGallery, {
121
132
  enable: enableImageGallery,
@@ -0,0 +1,2 @@
1
+ export declare const remarkCustomFootnotes: () => (tree: any, file: any) => void;
2
+ export declare const rehypeFootnoteLinks: () => (tree: any, file: any) => void;
@@ -0,0 +1,89 @@
1
+ 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); }
2
+ 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ 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); }
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
9
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
10
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
11
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
12
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
+ import { SKIP, visit } from 'unist-util-visit';
14
+ // eslint-disable-next-line unicorn/consistent-function-scoping
15
+ export var remarkCustomFootnotes = function remarkCustomFootnotes() {
16
+ return function (tree, file) {
17
+ var footnoteLinks = new Map();
18
+ visit(tree, 'footnoteDefinition', function (node) {
19
+ var linkData = null;
20
+
21
+ // 查找第一个link类型的子节点
22
+ visit(node, 'link', function (linkNode) {
23
+ if (linkData) return SKIP; // 只取第一个链接
24
+
25
+ // 提取链接文本
26
+ var textNode = linkNode.children.find(function (n) {
27
+ return n.type === 'text';
28
+ });
29
+ linkData = {
30
+ alt: (textNode === null || textNode === void 0 ? void 0 : textNode.value) || '',
31
+ title: (textNode === null || textNode === void 0 ? void 0 : textNode.value) || '',
32
+ url: linkNode.url // 或者根据需求处理
33
+ };
34
+ return SKIP; // 找到后停止遍历
35
+ });
36
+ if (linkData) {
37
+ footnoteLinks.set(node.identifier, linkData);
38
+ }
39
+ });
40
+
41
+ // 将数据存入文件上下文
42
+ file.data.footnoteLinks = Object.fromEntries(footnoteLinks);
43
+ };
44
+ };
45
+
46
+ // eslint-disable-next-line unicorn/consistent-function-scoping
47
+ export var rehypeFootnoteLinks = function rehypeFootnoteLinks() {
48
+ return function (tree, file) {
49
+ var linksData = file.data.footnoteLinks || {};
50
+ visit(tree, 'element', function (node) {
51
+ var _node$properties$clas;
52
+ if (node.tagName === 'section' && (_node$properties$clas = node.properties.className) !== null && _node$properties$clas !== void 0 && _node$properties$clas.includes('footnotes')) {
53
+ // 转换数据格式为数组(按identifier排序)
54
+ var sortedLinks = Object.entries(linksData).sort(function (_ref, _ref2) {
55
+ var _ref3 = _slicedToArray(_ref, 1),
56
+ a = _ref3[0];
57
+ var _ref4 = _slicedToArray(_ref2, 1),
58
+ b = _ref4[0];
59
+ return a.localeCompare(b);
60
+ }).map(function (_ref5) {
61
+ var _ref6 = _slicedToArray(_ref5, 2),
62
+ id = _ref6[0],
63
+ data = _ref6[1];
64
+ return _objectSpread({
65
+ id: id
66
+ }, data);
67
+ });
68
+ // 注入数据属性
69
+ node.properties['data-footnote-links'] = JSON.stringify(sortedLinks);
70
+ }
71
+ if (node.tagName === 'sup') {
72
+ var link = node.children.find(function (n) {
73
+ return n.tagName === 'a';
74
+ });
75
+ if (link) {
76
+ var _link$properties;
77
+ // a node example
78
+ // {
79
+ // "href": "#user-content-fn-3",
80
+ // "id": "user-content-fnref-3-2",
81
+ // "dataFootnoteRef": true,
82
+ // }
83
+ var linkRefIndex = (_link$properties = link.properties) === null || _link$properties === void 0 || (_link$properties = _link$properties.id) === null || _link$properties === void 0 ? void 0 : _link$properties.replace(/^user-content-fnref-/, '')[0];
84
+ if (linkRefIndex !== undefined) link.properties['data-link'] = JSON.stringify(linksData[linkRefIndex]);
85
+ }
86
+ }
87
+ });
88
+ };
89
+ };
@@ -1,8 +1,7 @@
1
- // katex-directive
2
- // 给 class="katex" 的节点加上 dir="ltr" 属性
3
-
4
1
  import { visit } from 'unist-util-visit';
5
2
 
3
+ // katex-directive
4
+ // 给 class="katex" 的节点加上 dir="ltr" 属性
6
5
  // eslint-disable-next-line unicorn/consistent-function-scoping
7
6
  export var rehypeKatexDir = function rehypeKatexDir() {
8
7
  return function (tree) {
@@ -17,6 +17,6 @@ export var useStyles = createStyles(function (_ref, _ref2) {
17
17
  return {
18
18
  chat: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n --lobe-markdown-font-size: ", "px;\n --lobe-markdown-header-multiple: ", ";\n --lobe-markdown-margin-multiple: ", ";\n --lobe-markdown-line-height: ", ";\n --lobe-markdown-border-radius: ", ";\n\n ol,\n ul {\n li {\n &::marker {\n color: ", " !important;\n }\n\n li {\n &::marker {\n color: ", " !important;\n }\n }\n }\n }\n\n ul {\n list-style: unset;\n\n li {\n &::before {\n content: unset;\n display: unset;\n }\n }\n }\n "])), fontSize, headerMultiple, marginMultiple, lineHeight, token.borderRadius, cyanColor, token.colorTextSecondary),
19
19
  latex: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n .katex-html {\n overflow: auto hidden;\n padding: 3px;\n\n .base {\n margin-block: 0;\n margin-inline: auto;\n }\n }\n\n .katex-html:has(span.tag) {\n display: flex !important;\n }\n\n .katex-html > .tag {\n position: relative !important;\n float: right;\n margin-inline-start: 0.25rem;\n }\n "]))),
20
- root: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n max-width: 100%;\n\n #footnote-label {\n display: none;\n }\n\n sup:has(a[aria-describedby='footnote-label']) {\n margin-inline: 0.2em;\n padding-block: 0.05em;\n padding-inline: 0.4em;\n border: 1px solid ", ";\n border-radius: 0.25em;\n\n font-size: 0.75em;\n vertical-align: super !important;\n\n background: ", ";\n }\n\n section.footnotes {\n padding-block: 1em;\n font-size: 0.875em;\n color: ", ";\n\n ol {\n display: flex;\n flex-wrap: wrap;\n gap: 0.5em;\n\n margin: 0;\n padding: 0;\n\n list-style-type: none;\n }\n\n ol li {\n position: relative;\n\n overflow: hidden;\n display: flex;\n flex-direction: row;\n\n margin: 0 !important;\n padding-block: 0 !important;\n padding-inline: 0 0.4em !important;\n border: 1px solid ", ";\n border-radius: 0.25em;\n\n text-overflow: ellipsis;\n white-space: nowrap;\n\n &::before {\n content: counter(list-item);\n counter-increment: list-item;\n\n display: block;\n\n margin-inline-end: 0.4em;\n padding-inline: 0.6em;\n\n background: ", ";\n }\n\n p,\n a {\n overflow: hidden;\n\n margin: 0 !important;\n padding: 0 !important;\n\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n }\n }\n "])), token.colorBorderSecondary, token.colorFillTertiary, token.colorTextSecondary, token.colorBorderSecondary, token.colorFillSecondary)
20
+ root: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n max-width: 100%;\n\n #footnote-label {\n display: none;\n }\n\n sup:has(a[aria-describedby='footnote-label']) {\n vertical-align: super !important;\n }\n "])))
21
21
  };
22
22
  });
@@ -1,3 +1,4 @@
1
1
  export declare function escapeBrackets(text: string): string;
2
2
  export declare function escapeMhchem(text: string): string;
3
3
  export declare function fixMarkdownBold(text: string): string;
4
+ export declare const transformCitations: (rawContent: string, length?: number) => string;
@@ -55,4 +55,17 @@ export function fixMarkdownBold(text) {
55
55
  }
56
56
  }
57
57
  return result;
58
- }
58
+ }
59
+ export var transformCitations = function transformCitations(rawContent) {
60
+ var length = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 40;
61
+ // 生成动态正则表达式模式
62
+ var idx = Array.from({
63
+ length: length
64
+ }).fill('').map(function (_, index) {
65
+ return index + 1;
66
+ });
67
+ var pattern = new RegExp("\\[(".concat(idx.join('|'), ")\\]"), 'g');
68
+ return rawContent.replaceAll(pattern, function (match, id) {
69
+ return "[#citation-".concat(id, "](citation-").concat(id, ")");
70
+ }).replaceAll('][', '] [');
71
+ };
@@ -0,0 +1,8 @@
1
+ /// <reference types="react" />
2
+ interface SearchResultCardProps {
3
+ alt?: string;
4
+ title?: string;
5
+ url: string;
6
+ }
7
+ declare const SearchResultCard: import("react").NamedExoticComponent<SearchResultCardProps>;
8
+ export default SearchResultCard;
@@ -0,0 +1,77 @@
1
+ var _templateObject, _templateObject2, _templateObject3;
2
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
6
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
9
+ import { Typography } from 'antd';
10
+ import { createStyles } from 'antd-style';
11
+ import { memo, useMemo } from 'react';
12
+ import { Flexbox } from 'react-layout-kit';
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ import { jsxs as _jsxs } from "react/jsx-runtime";
15
+ var useStyles = createStyles(function (_ref) {
16
+ var css = _ref.css,
17
+ token = _ref.token;
18
+ return {
19
+ container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n\n min-width: 160px;\n max-width: 160px;\n height: 100%;\n padding: 8px;\n border-radius: 8px;\n\n font-size: 12px;\n color: initial;\n\n background: ", ";\n\n &:hover {\n background: ", ";\n }\n "])), token.colorFillQuaternary, token.colorFillTertiary),
20
+ title: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n overflow: hidden;\n display: -webkit-box;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: 2;\n\n text-overflow: ellipsis;\n "]))),
21
+ url: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n overflow: hidden;\n display: -webkit-box;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: 1;\n\n text-overflow: ellipsis;\n "])))
22
+ };
23
+ });
24
+ var SearchResultCard = /*#__PURE__*/memo(function (_ref2) {
25
+ var url = _ref2.url,
26
+ title = _ref2.title,
27
+ alt = _ref2.alt;
28
+ var _useStyles = useStyles(),
29
+ styles = _useStyles.styles;
30
+ var _useMemo = useMemo(function () {
31
+ try {
32
+ var urlObj = new URL(url);
33
+ var _domain = urlObj.hostname.replace('www.', '');
34
+ var hostForUrl = urlObj.host;
35
+ var _displayTitle = title;
36
+ if (title === url) {
37
+ _displayTitle = hostForUrl + urlObj.pathname;
38
+ }
39
+ return [_displayTitle, _domain, hostForUrl];
40
+ } catch (_unused) {
41
+ return [title, url, url];
42
+ }
43
+ }, [url, title]),
44
+ _useMemo2 = _slicedToArray(_useMemo, 3),
45
+ displayTitle = _useMemo2[0],
46
+ domain = _useMemo2[1],
47
+ host = _useMemo2[2];
48
+ return /*#__PURE__*/_jsx("a", {
49
+ href: url,
50
+ rel: "noreferrer",
51
+ target: '_blank',
52
+ children: /*#__PURE__*/_jsxs(Flexbox, {
53
+ className: styles.container,
54
+ gap: 2,
55
+ justify: 'space-between',
56
+ children: [/*#__PURE__*/_jsx("div", {
57
+ className: styles.title,
58
+ children: displayTitle
59
+ }), /*#__PURE__*/_jsxs(Flexbox, {
60
+ align: 'center',
61
+ gap: 4,
62
+ horizontal: true,
63
+ children: [/*#__PURE__*/_jsx("img", {
64
+ alt: alt || title || url,
65
+ height: 14,
66
+ src: "https://icons.duckduckgo.com/ip3/".concat(host, ".ico"),
67
+ width: 14
68
+ }), /*#__PURE__*/_jsx(Typography.Text, {
69
+ className: styles.url,
70
+ type: 'secondary',
71
+ children: domain
72
+ })]
73
+ })]
74
+ }, url)
75
+ });
76
+ });
77
+ export default SearchResultCard;
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ export interface SearchResultItem {
3
+ alt?: string;
4
+ summary?: string;
5
+ title?: string;
6
+ url: string;
7
+ }
8
+ export interface SearchResultCardsProps {
9
+ dataSource: string[] | SearchResultItem[];
10
+ }
11
+ declare const SearchResultCards: import("react").NamedExoticComponent<SearchResultCardsProps>;
12
+ export default SearchResultCards;
@@ -0,0 +1,28 @@
1
+ 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); }
2
+ 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ 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); }
7
+ import { memo } from 'react';
8
+ import { Flexbox } from 'react-layout-kit';
9
+ import SearchResultCard from "../SearchResultCard";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ var SearchResultCards = /*#__PURE__*/memo(function (_ref) {
12
+ var dataSource = _ref.dataSource;
13
+ return /*#__PURE__*/_jsx(Flexbox, {
14
+ gap: 12,
15
+ horizontal: true,
16
+ style: {
17
+ minHeight: 80,
18
+ overflowX: 'scroll',
19
+ width: '100%'
20
+ },
21
+ children: dataSource.map(function (link) {
22
+ return typeof link === 'string' ? /*#__PURE__*/_jsx(SearchResultCard, {
23
+ url: link
24
+ }, link) : /*#__PURE__*/_jsx(SearchResultCard, _objectSpread({}, link), link.url);
25
+ })
26
+ });
27
+ });
28
+ export default SearchResultCards;
@@ -44,6 +44,7 @@ export { default as MaterialFileTypeIcon, type MaterialFileTypeIconProps, } from
44
44
  export { default as Mermaid, type MermaidProps } from './Mermaid';
45
45
  export { default as Modal, type ModalProps } from './Modal';
46
46
  export { default as SearchBar, type SearchBarProps } from './SearchBar';
47
+ export { default as SearchResultCards, type SearchResultCardsProps } from './SearchResultCards';
47
48
  export { default as SelectWithImg, type SelectWithImgOptionItem, type SelectWithImgProps, } from './SelectWithImg';
48
49
  export { default as SideNav, type SideNavProps } from './SideNav';
49
50
  export { default as SliderWithInput, type SliderWithInputProps } from './SliderWithInput';
package/es/components.js CHANGED
@@ -44,6 +44,7 @@ export { default as MaterialFileTypeIcon } from "./MaterialFileTypeIcon";
44
44
  export { default as Mermaid } from "./Mermaid";
45
45
  export { default as Modal } from "./Modal";
46
46
  export { default as SearchBar } from "./SearchBar";
47
+ export { default as SearchResultCards } from "./SearchResultCards";
47
48
  export { default as SelectWithImg } from "./SelectWithImg";
48
49
  export { default as SideNav } from "./SideNav";
49
50
  export { default as SliderWithInput } from "./SliderWithInput";
@@ -0,0 +1,10 @@
1
+ import { ReactNode } from 'react';
2
+ interface PopoverPanelProps {
3
+ alt?: string;
4
+ children?: ReactNode;
5
+ title?: string;
6
+ url?: string;
7
+ usePopover?: boolean;
8
+ }
9
+ declare const PopoverPanel: import("react").MemoExoticComponent<({ children, usePopover, title, alt, url }: PopoverPanelProps) => string | number | bigint | boolean | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react/jsx-runtime").JSX.Element | null | undefined>;
10
+ export default PopoverPanel;
@@ -0,0 +1,91 @@
1
+ 'use client';
2
+
3
+ var _templateObject, _templateObject2;
4
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
5
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
7
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
8
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
9
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
10
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
11
+ import { Popover } from 'antd';
12
+ import { createStyles } from 'antd-style';
13
+ import { ArrowRightIcon } from 'lucide-react';
14
+ import { memo, useMemo } from 'react';
15
+ import { Flexbox } from 'react-layout-kit';
16
+ import Icon from "../../../Icon";
17
+ import { jsx as _jsx } from "react/jsx-runtime";
18
+ import { jsxs as _jsxs } from "react/jsx-runtime";
19
+ var useStyles = createStyles(function (_ref) {
20
+ var css = _ref.css,
21
+ token = _ref.token;
22
+ return {
23
+ link: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n color: ", ";\n\n :hover {\n color: ", ";\n }\n "])), token.colorTextSecondary, token.colorText),
24
+ url: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n overflow: hidden;\n display: -webkit-box;\n -webkit-box-orient: vertical;\n -webkit-line-clamp: 1;\n\n text-overflow: ellipsis;\n "])))
25
+ };
26
+ });
27
+ var PopoverPanel = /*#__PURE__*/memo(function (_ref2) {
28
+ var children = _ref2.children,
29
+ usePopover = _ref2.usePopover,
30
+ title = _ref2.title,
31
+ alt = _ref2.alt,
32
+ url = _ref2.url;
33
+ var _useStyles = useStyles(),
34
+ styles = _useStyles.styles;
35
+ var _useMemo = useMemo(function () {
36
+ try {
37
+ var urlObj = new URL(url);
38
+ var hostForUrl = urlObj.host;
39
+ var _displayTitle = title;
40
+ if (title === url) {
41
+ _displayTitle = '';
42
+ }
43
+ var _domain = urlObj.hostname.replace('www.', '');
44
+ if (!_displayTitle) _domain = url;
45
+ return [_displayTitle, _domain, hostForUrl];
46
+ } catch (_unused) {
47
+ return [title, url, url];
48
+ }
49
+ }, [url, title]),
50
+ _useMemo2 = _slicedToArray(_useMemo, 3),
51
+ displayTitle = _useMemo2[0],
52
+ domain = _useMemo2[1],
53
+ host = _useMemo2[2];
54
+ return usePopover && url ? /*#__PURE__*/_jsx(Popover, {
55
+ arrow: false,
56
+ content: /*#__PURE__*/_jsxs(Flexbox, {
57
+ gap: 8,
58
+ children: [/*#__PURE__*/_jsxs(Flexbox, {
59
+ className: styles.link,
60
+ gap: 12,
61
+ horizontal: true,
62
+ justify: 'space-between',
63
+ onClick: function onClick() {
64
+ window.open(url, '_blank');
65
+ },
66
+ children: [/*#__PURE__*/_jsxs(Flexbox, {
67
+ align: 'center',
68
+ gap: 4,
69
+ horizontal: true,
70
+ children: [/*#__PURE__*/_jsx("img", {
71
+ alt: alt || title || url,
72
+ height: 14,
73
+ src: "https://icons.duckduckgo.com/ip3/".concat(host, ".ico"),
74
+ style: {
75
+ borderRadius: 4
76
+ },
77
+ width: 14
78
+ }), /*#__PURE__*/_jsx("span", {
79
+ className: styles.url,
80
+ children: domain
81
+ })]
82
+ }), /*#__PURE__*/_jsx(Icon, {
83
+ icon: ArrowRightIcon
84
+ })]
85
+ }), displayTitle]
86
+ }),
87
+ trigger: 'hover',
88
+ children: children
89
+ }) : children;
90
+ });
91
+ export default PopoverPanel;
@@ -0,0 +1,12 @@
1
+ import { ReactNode } from 'react';
2
+ import { CitationItem } from "../../../types/citation";
3
+ interface CitationProps {
4
+ children?: ReactNode;
5
+ citationDetail?: CitationItem;
6
+ citations?: string[];
7
+ href?: string;
8
+ id: string;
9
+ inSup?: boolean;
10
+ }
11
+ declare const Citation: import("react").MemoExoticComponent<({ children, href, inSup, id, citationDetail }: CitationProps) => import("react/jsx-runtime").JSX.Element>;
12
+ export default Citation;
@@ -0,0 +1,74 @@
1
+ 'use client';
2
+
3
+ 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); }
4
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4;
5
+ 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; }
6
+ 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; }
7
+ 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; }
8
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
9
+ 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); }
10
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
11
+ import { createStyles } from 'antd-style';
12
+ import { isEmpty } from 'lodash-es';
13
+ import { memo } from 'react';
14
+ import PopoverPanel from "./PopoverPanel";
15
+ import { jsx as _jsx } from "react/jsx-runtime";
16
+ var useStyles = createStyles(function (_ref) {
17
+ var css = _ref.css,
18
+ token = _ref.token;
19
+ return {
20
+ container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: inline-flex;\n line-height: var(--lobe-markdown-line-height);\n vertical-align: baseline;\n\n a {\n color: inherit;\n }\n "]))),
21
+ content: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n width: 16px;\n height: 16px;\n margin-inline: 2px;\n border-radius: 4px;\n\n font-family: ", ";\n font-size: 10px;\n color: ", " !important;\n text-align: center;\n vertical-align: top;\n\n background: ", ";\n\n transition: all 100ms ", ";\n "])), token.fontFamilyCode, token.colorTextSecondary, token.colorFillSecondary, token.motionEaseOut),
22
+ hover: css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n cursor: pointer;\n\n :hover {\n color: ", " !important;\n background: ", ";\n }\n "])), token.colorBgSpotlight, token.colorPrimary),
23
+ supContainer: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n vertical-align: super;\n "])))
24
+ };
25
+ });
26
+ var Citation = /*#__PURE__*/memo(function (_ref2) {
27
+ var children = _ref2.children,
28
+ href = _ref2.href,
29
+ inSup = _ref2.inSup,
30
+ id = _ref2.id,
31
+ citationDetail = _ref2.citationDetail;
32
+ var _useStyles = useStyles(),
33
+ styles = _useStyles.styles,
34
+ cx = _useStyles.cx;
35
+ var usePopover = !isEmpty(citationDetail);
36
+ var url = (citationDetail === null || citationDetail === void 0 ? void 0 : citationDetail.url) || href;
37
+
38
+ // [^1] 格式类型
39
+ if (inSup) {
40
+ return /*#__PURE__*/_jsx(PopoverPanel, _objectSpread(_objectSpread({}, citationDetail), {}, {
41
+ usePopover: usePopover,
42
+ children: /*#__PURE__*/_jsx("span", {
43
+ className: styles.container,
44
+ children: /*#__PURE__*/_jsx("a", {
45
+ "aria-describedby": "footnote-label",
46
+ className: cx(styles.content, styles.hover),
47
+ "data-footnote-ref": "true",
48
+ href: url,
49
+ id: id,
50
+ rel: "noreferrer",
51
+ target: citationDetail !== null && citationDetail !== void 0 && citationDetail.url ? '_blank' : undefined,
52
+ children: children
53
+ })
54
+ })
55
+ }));
56
+ }
57
+ return /*#__PURE__*/_jsx(PopoverPanel, _objectSpread(_objectSpread({}, citationDetail), {}, {
58
+ usePopover: usePopover,
59
+ children: /*#__PURE__*/_jsx("sup", {
60
+ className: cx(styles.container, styles.supContainer),
61
+ children: url ? /*#__PURE__*/_jsx("a", {
62
+ className: cx(styles.content, styles.hover),
63
+ href: url,
64
+ rel: "noreferrer",
65
+ target: '_blank',
66
+ children: children
67
+ }) : /*#__PURE__*/_jsx("span", {
68
+ className: cx(styles.content, styles.hover),
69
+ children: children
70
+ })
71
+ })
72
+ }));
73
+ });
74
+ export default Citation;
@@ -0,0 +1,8 @@
1
+ import { ReactNode } from 'react';
2
+ interface FootnotesProps {
3
+ 'children': ReactNode;
4
+ 'data-footnote-links'?: string;
5
+ 'data-footnotes'?: boolean;
6
+ }
7
+ declare const Footnotes: ({ children, ...res }: FootnotesProps) => import("react/jsx-runtime").JSX.Element;
8
+ export default Footnotes;
@@ -0,0 +1,41 @@
1
+ var _excluded = ["children"];
2
+ var _templateObject;
3
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
4
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
5
+ function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
6
+ import { createStyles } from 'antd-style';
7
+ import { useMemo } from 'react';
8
+ import SearchResultCards from "../../SearchResultCards";
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ var useStyles = createStyles(function (_ref) {
11
+ var css = _ref.css,
12
+ token = _ref.token;
13
+ return {
14
+ fallback: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n padding-block: 1em;\n font-size: 0.875em;\n color: ", ";\n\n ol {\n display: flex;\n flex-wrap: wrap;\n gap: 0.5em;\n\n margin: 0;\n padding: 0;\n\n list-style-type: none;\n }\n\n ol li {\n position: relative;\n\n overflow: hidden;\n display: flex;\n flex-direction: row;\n\n margin: 0 !important;\n padding-block: 0 !important;\n padding-inline: 0 0.4em !important;\n border: 1px solid ", ";\n border-radius: 0.25em;\n\n text-overflow: ellipsis;\n white-space: nowrap;\n\n &::before {\n content: counter(list-item);\n counter-increment: list-item;\n\n display: block;\n\n margin-inline-end: 0.4em;\n padding-inline: 0.6em;\n\n background: ", ";\n }\n\n p,\n a {\n overflow: hidden;\n\n margin: 0 !important;\n padding: 0 !important;\n\n text-overflow: ellipsis;\n white-space: nowrap;\n }\n }\n "])), token.colorTextSecondary, token.colorBorderSecondary, token.colorFillSecondary)
15
+ };
16
+ });
17
+ var Footnotes = function Footnotes(_ref2) {
18
+ var children = _ref2.children,
19
+ res = _objectWithoutProperties(_ref2, _excluded);
20
+ var _useStyles = useStyles(),
21
+ styles = _useStyles.styles,
22
+ cx = _useStyles.cx;
23
+ var links = useMemo(function () {
24
+ try {
25
+ return JSON.parse(res['data-footnote-links'] || '');
26
+ } catch (error) {
27
+ console.error(error);
28
+ console.log(res);
29
+ return [];
30
+ }
31
+ }, [res['data-footnote-links']]);
32
+ var isError = links.length === 0;
33
+ return /*#__PURE__*/_jsx("section", {
34
+ className: cx('footnotes', isError && styles.fallback),
35
+ "data-footnotes": "true",
36
+ children: isError ? children : /*#__PURE__*/_jsx(SearchResultCards, {
37
+ dataSource: links
38
+ })
39
+ });
40
+ };
41
+ export default Footnotes;
@@ -1,5 +1,13 @@
1
1
  import { FC } from 'react';
2
2
  import { AProps } from "../../types";
3
- export type LinkProps = AProps;
3
+ import { CitationItem } from "../../types/citation";
4
+ export interface LinkProps extends AProps {
5
+ 'aria-describedby'?: string;
6
+ 'citations'?: CitationItem[];
7
+ 'data-footnote-ref'?: boolean;
8
+ 'data-link'?: string;
9
+ 'id'?: string;
10
+ 'node': any;
11
+ }
4
12
  declare const Link: FC<LinkProps>;
5
13
  export default Link;
@@ -1,5 +1,5 @@
1
1
  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); }
2
- var _excluded = ["href", "target"];
2
+ var _excluded = ["href", "target", "citations"];
3
3
  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; }
4
4
  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; }
5
5
  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; }
@@ -8,11 +8,36 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
8
8
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
9
9
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
10
10
  import A from "../../A";
11
+ import { safeParseJSON } from "../../utils/safeParseJSON";
12
+ import Citation from "./Citation";
11
13
  import { jsx as _jsx } from "react/jsx-runtime";
12
14
  var Link = function Link(_ref) {
13
15
  var href = _ref.href,
14
16
  target = _ref.target,
17
+ citations = _ref.citations,
15
18
  rest = _objectWithoutProperties(_ref, _excluded);
19
+ // [^1] 格式类型
20
+ if (rest['data-footnote-ref']) {
21
+ return /*#__PURE__*/_jsx(Citation, {
22
+ citationDetail: safeParseJSON(rest['data-link']),
23
+ href: href,
24
+ id: rest.id,
25
+ inSup: true,
26
+ children: rest.children
27
+ });
28
+ }
29
+
30
+ // [1] 格式类型,搭配 citations 注入
31
+ var match = href === null || href === void 0 ? void 0 : href.match(/citation-(\d+)/);
32
+ if (match) {
33
+ var index = Number.parseInt(match[1]) - 1;
34
+ var detail = citations === null || citations === void 0 ? void 0 : citations[index];
35
+ return /*#__PURE__*/_jsx(Citation, {
36
+ citationDetail: detail,
37
+ id: match[1],
38
+ children: match[1]
39
+ });
40
+ }
16
41
  var isNewWindow = href === null || href === void 0 ? void 0 : href.startsWith('http');
17
42
  return /*#__PURE__*/_jsx(A, _objectSpread({
18
43
  href: href,
@@ -0,0 +1,8 @@
1
+ import { ReactNode } from 'react';
2
+ interface SectionProps {
3
+ 'children': ReactNode;
4
+ 'data-footnotes'?: boolean;
5
+ 'showFootnotes'?: boolean;
6
+ }
7
+ declare const Section: (props: SectionProps) => import("react/jsx-runtime").JSX.Element;
8
+ export default Section;
@@ -0,0 +1,16 @@
1
+ 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); }
2
+ 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; }
3
+ 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; }
4
+ 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; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ 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); }
7
+ import Footnotes from "./Footnotes";
8
+ import { jsx as _jsx } from "react/jsx-runtime";
9
+ var Section = function Section(props) {
10
+ // 说明是脚注
11
+ if (props['data-footnotes']) {
12
+ return /*#__PURE__*/_jsx(Footnotes, _objectSpread({}, props));
13
+ }
14
+ return /*#__PURE__*/_jsx("section", _objectSpread({}, props));
15
+ };
16
+ export default Section;
@@ -0,0 +1,6 @@
1
+ export interface CitationItem {
2
+ alt?: string;
3
+ summary?: string;
4
+ title?: string;
5
+ url: string;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ export declare const safeParseJSON: <T = Record<string, any>>(text?: string) => T | undefined;
@@ -0,0 +1,10 @@
1
+ export var safeParseJSON = function safeParseJSON(text) {
2
+ if (typeof text !== 'string') return;
3
+ var json;
4
+ try {
5
+ json = JSON.parse(text);
6
+ } catch (_unused) {
7
+ return;
8
+ }
9
+ return json;
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.164.16",
3
+ "version": "1.165.0",
4
4
  "description": "Lobe UI is an open-source UI component library for building AIGC web apps",
5
5
  "keywords": [
6
6
  "lobehub",