dumi-theme-lobehub 1.9.0 → 1.9.2

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.
@@ -1,6 +1,5 @@
1
- import { useLocation } from "../../../example/.dumi/tmp/exports";
2
1
  import { ThemeProvider } from '@lobehub/ui';
3
- import { useLocale, useNavData, useOutlet, useRouteMeta, useSidebarData, useSiteData, useTabMeta } from 'dumi';
2
+ import { useLocale, useLocation, useNavData, useOutlet, useRouteMeta, useSidebarData, useSiteData, useTabMeta } from 'dumi';
4
3
  import isEqual from 'fast-deep-equal';
5
4
  import { memo, useMemo } from 'react';
6
5
  import Analytics from "../../components/Analytics";
@@ -6,8 +6,8 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import { SearchBar as Input } from '@lobehub/ui';
8
8
  import { useSiteSearch } from 'dumi';
9
- import SearchResult from 'dumi/theme-default/slots/SearchResult';
10
9
  import { memo, useState } from 'react';
10
+ import SearchResult from "dumi/theme/slots/SearchResult";
11
11
  import { useStyles } from "./style";
12
12
  import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { jsxs as _jsxs } from "react/jsx-runtime";
@@ -0,0 +1,9 @@
1
+ import { type useSiteSearch } from 'dumi';
2
+ import React from 'react';
3
+ type ISearchResult = ReturnType<typeof useSiteSearch>['result'];
4
+ declare const SearchResult: React.NamedExoticComponent<{
5
+ data: import("dumi/dist/client/theme-api/useSiteSearch").ISearchResult;
6
+ loading: boolean;
7
+ onItemSelect?: ((item: ISearchResult[0]['hints'][0]) => void) | undefined;
8
+ }>;
9
+ export default SearchResult;
@@ -0,0 +1,255 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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."); }
3
+ 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; } }
4
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
5
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
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
+ import { Icon } from '@lobehub/ui';
9
+ import animateScrollTo from 'animated-scroll-to';
10
+ import { Empty, Typography } from 'antd';
11
+ import { useTheme } from 'antd-style';
12
+ import { FormattedMessage, Link, history, useLocation } from 'dumi';
13
+ import { FileBox, FileIcon, HeadingIcon, LetterText } from 'lucide-react';
14
+ import React, { Fragment, memo, useCallback, useEffect, useState } from 'react';
15
+ import { Center, Flexbox } from 'react-layout-kit';
16
+ import { jsx as _jsx } from "react/jsx-runtime";
17
+ import { Fragment as _Fragment } from "react/jsx-runtime";
18
+ import { jsxs as _jsxs } from "react/jsx-runtime";
19
+ var ICONS_MAPPING = {
20
+ content: LetterText,
21
+ demo: FileBox,
22
+ page: FileIcon,
23
+ title: HeadingIcon
24
+ };
25
+ var Highlight = /*#__PURE__*/memo(function (props) {
26
+ return /*#__PURE__*/_jsx(_Fragment, {
27
+ children: props.texts.map(function (text, idx) {
28
+ return /*#__PURE__*/_jsx(Fragment, {
29
+ children: text.highlighted ? /*#__PURE__*/_jsx("mark", {
30
+ children: text.text
31
+ }) : text.text
32
+ }, idx);
33
+ })
34
+ });
35
+ });
36
+ var useFlatSearchData = function useFlatSearchData(data) {
37
+ var update = useCallback(function () {
38
+ var activeIndex = 0;
39
+ var ret = [];
40
+ var _iterator = _createForOfIteratorHelper(data),
41
+ _step;
42
+ try {
43
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
44
+ var _item = _step.value;
45
+ if (_item.title) {
46
+ ret.push({
47
+ type: 'title',
48
+ value: {
49
+ title: _item.title
50
+ }
51
+ });
52
+ }
53
+ var _iterator2 = _createForOfIteratorHelper(_item.hints),
54
+ _step2;
55
+ try {
56
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
57
+ var hint = _step2.value;
58
+ ret.push({
59
+ activeIndex: activeIndex++,
60
+ type: 'hint',
61
+ value: hint
62
+ });
63
+ }
64
+ } catch (err) {
65
+ _iterator2.e(err);
66
+ } finally {
67
+ _iterator2.f();
68
+ }
69
+ }
70
+ } catch (err) {
71
+ _iterator.e(err);
72
+ } finally {
73
+ _iterator.f();
74
+ }
75
+ return [ret, activeIndex];
76
+ }, [data]);
77
+ var _useState = useState(update),
78
+ _useState2 = _slicedToArray(_useState, 2),
79
+ flatData = _useState2[0],
80
+ setFlatData = _useState2[1];
81
+ useEffect(function () {
82
+ setFlatData(update);
83
+ }, [data]);
84
+ return flatData;
85
+ };
86
+ var SearchResult = /*#__PURE__*/memo(function (props) {
87
+ var theme = useTheme();
88
+ var _useFlatSearchData = useFlatSearchData(props.data),
89
+ _useFlatSearchData2 = _slicedToArray(_useFlatSearchData, 2),
90
+ data = _useFlatSearchData2[0],
91
+ histsCount = _useFlatSearchData2[1];
92
+ var _useState3 = useState(-1),
93
+ _useState4 = _slicedToArray(_useState3, 2),
94
+ activeIndex = _useState4[0],
95
+ setActiveIndex = _useState4[1];
96
+ var _useLocation = useLocation(),
97
+ pathname = _useLocation.pathname;
98
+ var onItemSelect = function onItemSelect(item) {
99
+ var _props$onItemSelect;
100
+ (_props$onItemSelect = props.onItemSelect) === null || _props$onItemSelect === void 0 || _props$onItemSelect.call(props, item);
101
+ var url = new URL(item === null || item === void 0 ? void 0 : item.link, location.origin);
102
+ if ((url === null || url === void 0 ? void 0 : url.pathname) === pathname && !url.hash) {
103
+ setTimeout(function () {
104
+ animateScrollTo(0, {
105
+ maxDuration: 300
106
+ });
107
+ }, 1);
108
+ }
109
+ };
110
+ useEffect(function () {
111
+ var handler = function handler(ev) {
112
+ // TODO: scroll into view for invisible items
113
+ if (ev.key === 'ArrowDown') {
114
+ setActiveIndex((activeIndex + 1) % histsCount);
115
+ } else if (ev.key === 'ArrowUp') {
116
+ setActiveIndex((activeIndex + histsCount - 1) % histsCount);
117
+ } else if (ev.key === 'Enter' && activeIndex >= 0) {
118
+ var _item2 = data.find(function (item) {
119
+ return item.type === 'hint' && item.activeIndex === activeIndex;
120
+ }).value;
121
+ history.push(_item2.link);
122
+ onItemSelect === null || onItemSelect === void 0 || onItemSelect(_item2);
123
+ document.activeElement.blur();
124
+ }
125
+ if (['Escape', 'Enter'].includes(ev.key)) {
126
+ setActiveIndex(-1);
127
+ }
128
+ };
129
+ document.addEventListener('keydown', handler);
130
+ return function () {
131
+ return document.removeEventListener('keydown', handler);
132
+ };
133
+ });
134
+ var returnNode = null;
135
+ if (props.loading) {
136
+ returnNode = /*#__PURE__*/_jsx(Empty, {
137
+ description: /*#__PURE__*/_jsx(FormattedMessage, {
138
+ id: "search.loading"
139
+ }),
140
+ image: Empty.PRESENTED_IMAGE_SIMPLE
141
+ });
142
+ } else if (props.data.length > 0) {
143
+ returnNode = /*#__PURE__*/_jsx(Flexbox, {
144
+ gap: 8,
145
+ paddingBlock: 8,
146
+ paddingInline: 8,
147
+ children: data.map(function (item, i) {
148
+ return item.type === 'title' ? /*#__PURE__*/_jsx(Flexbox, {
149
+ paddingBlock: 8,
150
+ paddingInline: 12,
151
+ style: {
152
+ background: theme.colorFillTertiary,
153
+ borderRadius: theme.borderRadius
154
+ },
155
+ children: /*#__PURE__*/_jsx(Typography.Title, {
156
+ ellipsis: {
157
+ rows: 1
158
+ },
159
+ level: 4,
160
+ style: {
161
+ fontSize: 14,
162
+ lineHeight: 1.4,
163
+ margin: 0
164
+ },
165
+ children: item.value.title
166
+ })
167
+ }, String(i)) : /*#__PURE__*/_jsx(Flexbox, {
168
+ children: /*#__PURE__*/_jsx(Link, {
169
+ "data-active": activeIndex === item.activeIndex || undefined,
170
+ onClick: function onClick() {
171
+ return onItemSelect === null || onItemSelect === void 0 ? void 0 : onItemSelect(item.value);
172
+ },
173
+ style: {
174
+ color: 'inherit'
175
+ },
176
+ to: item.value.link,
177
+ children: /*#__PURE__*/_jsxs(Flexbox, {
178
+ align: 'center',
179
+ gap: 16,
180
+ horizontal: true,
181
+ style: {
182
+ overflow: 'hidden',
183
+ position: 'relative'
184
+ },
185
+ children: [/*#__PURE__*/_jsx(Center, {
186
+ flex: 'none',
187
+ height: 48,
188
+ style: {
189
+ background: theme.colorFillTertiary,
190
+ borderRadius: theme.borderRadius
191
+ },
192
+ width: 48,
193
+ children: /*#__PURE__*/_jsx(Icon, {
194
+ color: theme.colorTextDescription,
195
+ icon: ICONS_MAPPING === null || ICONS_MAPPING === void 0 ? void 0 : ICONS_MAPPING[item.value.type],
196
+ size: {
197
+ fontSize: 32
198
+ }
199
+ })
200
+ }), /*#__PURE__*/_jsxs(Flexbox, {
201
+ children: [/*#__PURE__*/_jsx(Typography.Title, {
202
+ ellipsis: {
203
+ rows: 1
204
+ },
205
+ level: 4,
206
+ style: {
207
+ fontSize: 14,
208
+ lineHeight: 1.4,
209
+ margin: 0
210
+ },
211
+ children: /*#__PURE__*/_jsx(Highlight, {
212
+ texts: item.value.highlightTitleTexts
213
+ })
214
+ }), /*#__PURE__*/_jsx(Typography.Paragraph, {
215
+ ellipsis: {
216
+ rows: 2
217
+ },
218
+ style: {
219
+ color: theme.colorTextSecondary,
220
+ fontSize: 12,
221
+ lineHeight: 1.4,
222
+ margin: 0
223
+ },
224
+ children: /*#__PURE__*/_jsx(Highlight, {
225
+ texts: item.value.highlightTexts
226
+ })
227
+ })]
228
+ })]
229
+ })
230
+ })
231
+ }, String(i));
232
+ })
233
+ });
234
+ } else {
235
+ returnNode = /*#__PURE__*/_jsx(Empty, {
236
+ description: /*#__PURE__*/_jsx(FormattedMessage, {
237
+ id: "search.not.found"
238
+ }),
239
+ image: Empty.PRESENTED_IMAGE_SIMPLE
240
+ });
241
+ }
242
+ return /*#__PURE__*/_jsx(Flexbox, {
243
+ onMouseDownCapture: function onMouseDownCapture(ev) {
244
+ return ev.preventDefault();
245
+ },
246
+ onMouseEnter: function onMouseEnter() {
247
+ return setActiveIndex(-1);
248
+ },
249
+ onMouseUpCapture: function onMouseUpCapture() {
250
+ document.activeElement.blur();
251
+ },
252
+ children: returnNode
253
+ });
254
+ });
255
+ export default SearchResult;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi-theme-lobehub",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
4
4
  "description": "dumi-theme-lobehub is a documentation site theme package designed for dumi2. It provides a more beautiful and user-friendly development and reading experience based on @lobehub/ui",
5
5
  "keywords": [
6
6
  "lobehub",
@@ -27,6 +27,7 @@
27
27
  "dependencies": {
28
28
  "@floating-ui/react": "^0.26.28",
29
29
  "ahooks": "^3.8.1",
30
+ "animated-scroll-to": "^2.3.0",
30
31
  "chalk": "^4.1.2",
31
32
  "fast-deep-equal": "^3.1.3",
32
33
  "history": "^5.3.0",