@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
124 lines (123 loc) • 6.9 kB
JavaScript
'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); }
var _excluded = ["node", "href"],
_excluded2 = ["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; }
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); }
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; }
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; }
import { memo, useMemo } from 'react';
import { Flexbox } from 'react-layout-kit';
import A from "../../A";
import Block from "../../Block";
import Text from "../../Text";
import SearchResultCards from "./SearchResultCards";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
import { createElement as _createElement } from "react";
var DefaultFootnotes = /*#__PURE__*/memo(function (_ref) {
var dataSource = _ref.dataSource;
var items = useMemo(function () {
var _dataSource$find;
return (_dataSource$find = dataSource.find(function (child) {
return (child === null || child === void 0 ? void 0 : child.type) === 'ol';
})) === null || _dataSource$find === void 0 || (_dataSource$find = _dataSource$find.props) === null || _dataSource$find === void 0 || (_dataSource$find = _dataSource$find.children) === null || _dataSource$find === void 0 ? void 0 : _dataSource$find.map(function (item) {
var _item$props, _data$;
if (typeof item === 'string' || (item === null || item === void 0 ? void 0 : item.type) !== 'li') return false;
var data = item === null || item === void 0 || (_item$props = item.props) === null || _item$props === void 0 || (_item$props = _item$props.children) === null || _item$props === void 0 || (_item$props = _item$props.find(function (note) {
var _note$props;
return note === null || note === void 0 || (_note$props = note.props) === null || _note$props === void 0 ? void 0 : _note$props.children;
})) === null || _item$props === void 0 || (_item$props = _item$props.props) === null || _item$props === void 0 ? void 0 : _item$props.children;
if (!data || !Array.isArray(data)) return false;
return {
children: data[0],
props: ((_data$ = data[1]) === null || _data$ === void 0 ? void 0 : _data$.props) || {}
};
}).filter(Boolean);
}, [dataSource]);
if (!Array.isArray(items)) return null;
return /*#__PURE__*/_jsx(Flexbox, {
align: 'flex-start',
as: 'section',
className: 'footnotes',
"data-footnotes": "true",
gap: '0.5em',
horizontal: true,
justify: 'flex-start',
wrap: 'wrap',
children: items.map(function (_ref2, index) {
var children = _ref2.children,
props = _ref2.props;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
var node = props.node,
href = props.href,
rest = _objectWithoutProperties(props, _excluded);
var Container = href ? A : 'div';
return /*#__PURE__*/_createElement(Container, _objectSpread(_objectSpread({}, href ? _objectSpread({
href: href
}, rest) : rest), {}, {
key: index
}), /*#__PURE__*/_jsxs(Block, {
align: 'stretch',
horizontal: true,
style: {
overflow: 'hidden',
position: 'relative'
},
variant: 'outlined',
children: [/*#__PURE__*/_jsx(Block, {
paddingInline: '0.66em',
style: {
borderRadius: 0
},
variant: 'filled',
children: /*#__PURE__*/_jsx(Text, {
as: "span",
code: true,
type: 'secondary',
children: index + 1
})
}), /*#__PURE__*/_jsx(Text, {
as: "span",
style: {
paddingInline: '0.66em'
},
type: 'secondary',
children: children
})]
}));
})
});
});
var Footnotes = /*#__PURE__*/memo(function (_ref3) {
var children = _ref3.children,
rest = _objectWithoutProperties(_ref3, _excluded2);
var links = useMemo(function () {
try {
return JSON.parse(rest['data-footnote-links'] || '[]');
} catch (error) {
console.error('Failed to parse footnote links:', error);
return [];
}
}, [rest['data-footnote-links']]);
var isError = links.length === 0;
if (!children) return;
if (isError) {
if (!Array.isArray(children)) return children;
return /*#__PURE__*/_jsx(DefaultFootnotes, {
dataSource: children
});
}
return /*#__PURE__*/_jsx("section", {
className: 'footnotes',
"data-footnotes": "true",
children: /*#__PURE__*/_jsx(SearchResultCards, {
dataSource: links
})
});
});
Footnotes.displayName = 'Footnotes';
export default Footnotes;