dumi 2.0.0-beta.7 → 2.0.0-beta.9

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.
Files changed (63) hide show
  1. package/dist/client/theme-api/DumiPage.js +24 -4
  2. package/dist/client/theme-api/context.d.ts +1 -0
  3. package/dist/client/theme-api/index.d.ts +2 -0
  4. package/dist/client/theme-api/index.js +3 -1
  5. package/dist/client/theme-api/types.d.ts +34 -3
  6. package/dist/client/theme-api/useRouteMeta.js +4 -3
  7. package/dist/client/theme-api/useSiteSearch.d.ts +23 -0
  8. package/dist/client/theme-api/useSiteSearch.js +347 -0
  9. package/dist/client/theme-api/useTabMeta.d.ts +4 -0
  10. package/dist/client/theme-api/useTabMeta.js +47 -0
  11. package/dist/features/configPlugins/index.js +1 -1
  12. package/dist/features/configPlugins/schema.js +4 -2
  13. package/dist/features/exports.d.ts +5 -0
  14. package/dist/features/exports.js +23 -2
  15. package/dist/features/meta.js +43 -22
  16. package/dist/features/routes.js +8 -7
  17. package/dist/features/tabs.js +1 -1
  18. package/dist/features/theme/index.js +8 -3
  19. package/dist/loaders/markdown/index.d.ts +1 -1
  20. package/dist/loaders/markdown/index.js +69 -48
  21. package/dist/loaders/markdown/transformer/index.d.ts +4 -3
  22. package/dist/loaders/markdown/transformer/index.js +6 -6
  23. package/dist/loaders/markdown/transformer/rehypeDemo.js +2 -2
  24. package/dist/loaders/markdown/transformer/rehypeEnhancedTag.js +6 -1
  25. package/dist/loaders/markdown/transformer/rehypeImg.d.ts +6 -0
  26. package/dist/loaders/markdown/transformer/rehypeImg.js +57 -0
  27. package/dist/loaders/markdown/transformer/rehypeJsxify.js +17 -1
  28. package/dist/loaders/markdown/transformer/rehypeSlug.d.ts +2 -2
  29. package/dist/loaders/markdown/transformer/rehypeSlug.js +21 -57
  30. package/dist/loaders/markdown/transformer/rehypeText.d.ts +4 -0
  31. package/dist/loaders/markdown/transformer/rehypeText.js +110 -0
  32. package/dist/loaders/markdown/transformer/remarkEmbed.d.ts +4 -0
  33. package/dist/loaders/markdown/transformer/remarkEmbed.js +89 -0
  34. package/dist/loaders/page/index.js +1 -0
  35. package/dist/types.d.ts +8 -1
  36. package/dist/utils.d.ts +7 -0
  37. package/dist/utils.js +16 -0
  38. package/package.json +12 -11
  39. package/theme-default/builtins/Previewer/index.js +1 -0
  40. package/theme-default/layouts/DocLayout/index.js +3 -1
  41. package/theme-default/layouts/DocLayout/index.less +9 -4
  42. package/theme-default/locales/en-US.json +2 -1
  43. package/theme-default/locales/zh-CN.json +2 -1
  44. package/theme-default/slots/ContentTabs/index.d.ts +1 -1
  45. package/theme-default/slots/ContentTabs/index.js +1 -1
  46. package/theme-default/slots/Features/index.d.ts +4 -0
  47. package/theme-default/slots/Features/index.js +28 -0
  48. package/theme-default/slots/Features/index.less +49 -0
  49. package/theme-default/slots/Header/index.js +9 -2
  50. package/theme-default/slots/Header/index.less +18 -10
  51. package/theme-default/slots/Hero/index.d.ts +4 -0
  52. package/theme-default/slots/Hero/index.js +35 -0
  53. package/theme-default/slots/Hero/index.less +65 -0
  54. package/theme-default/slots/HeroTitle/index.d.ts +6 -0
  55. package/theme-default/slots/HeroTitle/index.js +10 -0
  56. package/theme-default/slots/HeroTitle/index.less +23 -0
  57. package/theme-default/slots/SearchBar/index.js +69 -9
  58. package/theme-default/slots/SearchBar/index.less +37 -4
  59. package/theme-default/slots/SearchResult/index.d.ts +9 -0
  60. package/theme-default/slots/SearchResult/index.js +168 -0
  61. package/theme-default/slots/SearchResult/index.less +119 -0
  62. package/dist/loaders/markdown/transformer/rehypeEmbed.d.ts +0 -12
  63. package/dist/loaders/markdown/transformer/rehypeEmbed.js +0 -88
@@ -10,14 +10,28 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
10
10
 
11
11
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
 
13
- import { useRouteMeta, useSiteData } from 'dumi';
13
+ import { useLocation, useRouteMeta, useSiteData } from 'dumi';
14
14
  import ContentTabs from 'dumi/theme/slots/ContentTabs';
15
15
  import React, { useEffect, useState } from 'react';
16
+ import { useTabQueryState } from "./useTabMeta";
16
17
  export var DumiPage = function DumiPage(props) {
18
+ var _useLocation = useLocation(),
19
+ hash = _useLocation.hash;
20
+
17
21
  var _useRouteMeta = useRouteMeta(),
18
22
  tabs = _useRouteMeta.tabs;
19
23
 
20
- var _useState = useState(),
24
+ var _useTabQueryState = useTabQueryState(),
25
+ _useTabQueryState2 = _slicedToArray(_useTabQueryState, 2),
26
+ tabKey = _useTabQueryState2[0],
27
+ setTabKey = _useTabQueryState2[1];
28
+
29
+ var _useState = useState(function () {
30
+ return tabs === null || tabs === void 0 ? void 0 : tabs.find(function (_ref) {
31
+ var key = _ref.key;
32
+ return key === tabKey;
33
+ });
34
+ }),
21
35
  _useState2 = _slicedToArray(_useState, 2),
22
36
  tab = _useState2[0],
23
37
  setTab = _useState2[1];
@@ -28,12 +42,18 @@ export var DumiPage = function DumiPage(props) {
28
42
 
29
43
  useEffect(function () {
30
44
  setLoading(false);
31
- }, []);
45
+ }, []); // handle hash change
46
+
47
+ useEffect(function () {
48
+ var elm = document.getElementById(hash.replace('#', ''));
49
+ if (elm) elm.scrollIntoView();
50
+ }, [hash]);
32
51
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ContentTabs, {
33
52
  tabs: tabs,
34
- tabKey: tab === null || tab === void 0 ? void 0 : tab.key,
53
+ tabKey: tabKey,
35
54
  onChange: function onChange(val) {
36
55
  setTab(val);
56
+ setTabKey(val === null || val === void 0 ? void 0 : val.key);
37
57
  }
38
58
  }), tab ? /*#__PURE__*/React.createElement(tab.components.default) : props.children);
39
59
  };
@@ -7,6 +7,7 @@ interface ISiteContext {
7
7
  demos: Record<string, {
8
8
  component: ComponentType;
9
9
  asset: IPreviewerProps['asset'];
10
+ routeId: string;
10
11
  }>;
11
12
  components: Record<string, AtomComponentAsset>;
12
13
  locales: NonNullable<ILocalesConfig>;
@@ -9,3 +9,5 @@ export { useLocale } from './useLocale';
9
9
  export { useNavData } from './useNavData';
10
10
  export { useRouteMeta } from './useRouteMeta';
11
11
  export { useFullSidebarData, useSidebarData } from './useSidebarData';
12
+ export { useSiteSearch } from './useSiteSearch';
13
+ export { useTabMeta } from './useTabMeta';
@@ -7,4 +7,6 @@ export { useAtomAssets } from "./useAtomAssets";
7
7
  export { useLocale } from "./useLocale";
8
8
  export { useNavData } from "./useNavData";
9
9
  export { useRouteMeta } from "./useRouteMeta";
10
- export { useFullSidebarData, useSidebarData } from "./useSidebarData";
10
+ export { useFullSidebarData, useSidebarData } from "./useSidebarData";
11
+ export { useSiteSearch } from "./useSiteSearch";
12
+ export { useTabMeta } from "./useTabMeta";
@@ -57,6 +57,22 @@ export interface IRouteMeta {
57
57
  order?: number;
58
58
  };
59
59
  order?: number;
60
+ hero?: {
61
+ title?: string;
62
+ description?: string;
63
+ background?: string;
64
+ links?: {
65
+ title: string;
66
+ link: string;
67
+ }[];
68
+ [key: string]: any;
69
+ };
70
+ features?: {
71
+ emoji?: string;
72
+ title?: string;
73
+ description?: string;
74
+ [key: string]: any;
75
+ }[];
60
76
  toc?: boolean | 'content' | 'menu';
61
77
  demo?: {
62
78
  cols?: number;
@@ -68,6 +84,18 @@ export interface IRouteMeta {
68
84
  depth: number;
69
85
  title: string;
70
86
  }[];
87
+ texts: {
88
+ type?: 'content';
89
+ value: string;
90
+ /**
91
+ * paragraph index
92
+ */
93
+ paraId: number;
94
+ /**
95
+ * title index in toc
96
+ */
97
+ tocIndex?: number;
98
+ }[];
71
99
  tabs?: {
72
100
  key: string;
73
101
  components: {
@@ -75,9 +103,12 @@ export interface IRouteMeta {
75
103
  Extra: ComponentType;
76
104
  Action: ComponentType;
77
105
  };
78
- frontmatter: Omit<IRouteMeta['frontmatter'], 'description' | 'keywords' | 'nav' | 'group'>;
79
- toc: IRouteMeta['toc'];
80
- [key: string]: any;
106
+ meta: {
107
+ frontmatter: Omit<IRouteMeta['frontmatter'], 'description' | 'keywords' | 'nav' | 'group' | 'hero' | 'features'>;
108
+ toc: IRouteMeta['toc'];
109
+ texts: IRouteMeta['texts'];
110
+ [key: string]: any;
111
+ };
81
112
  }[];
82
113
  [key: string]: any;
83
114
  }
@@ -11,7 +11,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
11
11
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
 
13
13
  import { matchRoutes, useAppData, useLocation, useRouteData } from 'dumi';
14
- import { useCallback, useEffect, useState } from 'react';
14
+ import { useCallback, useLayoutEffect, useState } from 'react';
15
15
 
16
16
  /**
17
17
  * hook for get matched route meta
@@ -42,7 +42,8 @@ export var useRouteMeta = function useRouteMeta() {
42
42
 
43
43
  return ret || {
44
44
  frontmatter: {},
45
- toc: []
45
+ toc: [],
46
+ texts: []
46
47
  };
47
48
  }, [clientRoutes.length, pathname]);
48
49
 
@@ -51,7 +52,7 @@ export var useRouteMeta = function useRouteMeta() {
51
52
  meta = _useState2[0],
52
53
  setMeta = _useState2[1];
53
54
 
54
- useEffect(function () {
55
+ useLayoutEffect(function () {
55
56
  setMeta(getter);
56
57
  }, [clientRoutes.length, pathname]);
57
58
  return meta;
@@ -0,0 +1,23 @@
1
+ interface IHighlightText {
2
+ highlighted?: boolean;
3
+ text: string;
4
+ }
5
+ interface ISearchNavResult {
6
+ title?: string;
7
+ priority: number;
8
+ hints: {
9
+ type: 'page' | 'title' | 'demo' | 'content';
10
+ link: string;
11
+ priority: number;
12
+ highlightTitleTexts: IHighlightText[];
13
+ highlightTexts: IHighlightText[];
14
+ }[];
15
+ }
16
+ declare type ISearchResult = ISearchNavResult[];
17
+ export declare const useSiteSearch: () => {
18
+ keywords: string;
19
+ setKeywords: (val: string) => void;
20
+ result: ISearchResult;
21
+ loading: boolean;
22
+ };
23
+ export {};
@@ -0,0 +1,347 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+
5
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+
7
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
8
+
9
+ 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."); }
10
+
11
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
12
+
13
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
+
15
+ 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(_e2) { throw _e2; }, 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(_e3) { didErr = true; err = _e3; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
16
+
17
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
18
+
19
+ 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."); }
20
+
21
+ 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); }
22
+
23
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
24
+
25
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
26
+
27
+ 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; }
28
+
29
+ import { useNavData, useSiteData } from 'dumi';
30
+ import { findAll } from 'highlight-words-core';
31
+ import { useCallback, useEffect, useRef, useState } from 'react';
32
+ import { TAB_QUERY_KEY } from "./useTabMeta";
33
+ import { useLocaleDocRoutes } from "./utils";
34
+
35
+ function createMetadataSection(rawTitle, title, link, texts, tocIndex) {
36
+ var allowEmptyParas = tocIndex !== undefined;
37
+ var paragraphs = texts.reduce(function (acc, text) {
38
+ if (text.tocIndex === tocIndex) {
39
+ acc[text.paraId] = (acc[text.paraId] || '').concat(text.value);
40
+ }
41
+
42
+ return acc;
43
+ }, []).filter(Boolean);
44
+ return Boolean(paragraphs.length) || allowEmptyParas ? {
45
+ rawTitle: rawTitle,
46
+ title: title,
47
+ link: link,
48
+ paragraphs: texts.reduce(function (acc, text) {
49
+ if (text.tocIndex === tocIndex) {
50
+ var _text$paraId, _acc$_text$paraId;
51
+
52
+ (_acc$_text$paraId = acc[_text$paraId = text.paraId]) !== null && _acc$_text$paraId !== void 0 ? _acc$_text$paraId : acc[_text$paraId] = '';
53
+ acc[text.paraId] += text.value;
54
+ }
55
+
56
+ return acc;
57
+ }, []).filter(Boolean)
58
+ } : null;
59
+ }
60
+
61
+ function generateSearchMetadata(routes, demos, nav) {
62
+ var metadata = []; // generate demos mapping by route.id
63
+
64
+ var demosMapping = Object.values(demos).reduce(function (acc, demo) {
65
+ if (demo.asset) {
66
+ var _demo$routeId, _acc$_demo$routeId;
67
+
68
+ (_acc$_demo$routeId = acc[_demo$routeId = demo.routeId]) !== null && _acc$_demo$routeId !== void 0 ? _acc$_demo$routeId : acc[_demo$routeId] = [];
69
+ acc[demo.routeId].push(demo);
70
+ }
71
+
72
+ return acc;
73
+ }, {});
74
+ Object.values(routes).forEach(function (route) {
75
+ // only process content route
76
+ if ('meta' in route && !('isLayout' in route)) {
77
+ var _demosMapping$route$i;
78
+
79
+ var routeMeta = route.meta;
80
+ var routeAbsPath = route.path.replace(/^([^/])/, '/$1') || '/';
81
+ var routeNav = nav.find(function (item) {
82
+ return routeAbsPath === item.link || routeAbsPath.startsWith("".concat(item.activePath, "/"));
83
+ });
84
+ var demoIds = (demosMapping[route.id] || []).map(function (demo) {
85
+ var _demo$asset;
86
+
87
+ return (_demo$asset = demo.asset) === null || _demo$asset === void 0 ? void 0 : _demo$asset.id;
88
+ });
89
+ var orphanSection = createMetadataSection('', routeMeta.frontmatter.title, routeAbsPath, routeMeta.texts);
90
+ var tocSections = routeMeta.toc.reduce(function (acc, toc, i) {
91
+ // exclude demo id, to avoid duplicate
92
+ if (!demoIds.includes(toc.id) && toc.depth > 1) {
93
+ acc.push(createMetadataSection(toc.title, "".concat(routeMeta.frontmatter.title, " - ").concat(toc.title), "".concat(routeAbsPath, "#").concat(toc.id), routeMeta.texts, i));
94
+ }
95
+
96
+ return acc;
97
+ }, []);
98
+ var tabSections = (routeMeta.tabs || []).reduce(function (acc, _ref) {
99
+ var key = _ref.key,
100
+ meta = _ref.meta;
101
+ // collect orphan section that not in toc
102
+ var tabOrphanSection = createMetadataSection('', "".concat(routeMeta.frontmatter.title, " - ").concat(meta.frontmatter.title), "".concat(routeAbsPath, "?").concat(TAB_QUERY_KEY, "=").concat(key), meta.texts);
103
+ if (tabOrphanSection) acc.push(tabOrphanSection); // collect sections by toc
104
+
105
+ acc.push.apply(acc, _toConsumableArray(meta.toc.map(function (toc, i) {
106
+ return createMetadataSection(toc.title, "".concat(routeMeta.frontmatter.title, " - ").concat(meta.frontmatter.title, " - ").concat(toc.title), "".concat(routeAbsPath, "?").concat(TAB_QUERY_KEY, "=").concat(key, "#").concat(toc.id), meta.texts, i);
107
+ })));
108
+ return acc;
109
+ }, []);
110
+ metadata.push({
111
+ navTitle: routeNav === null || routeNav === void 0 ? void 0 : routeNav.title,
112
+ navOrder: routeNav ? nav.indexOf(routeNav) : Infinity,
113
+ title: routeMeta.frontmatter.title,
114
+ link: routeAbsPath,
115
+ sections: [].concat(_toConsumableArray(orphanSection ? [orphanSection] : []), _toConsumableArray(tocSections), _toConsumableArray(tabSections)),
116
+ demos: ((_demosMapping$route$i = demosMapping[route.id]) === null || _demosMapping$route$i === void 0 ? void 0 : _demosMapping$route$i.map(function (demo) {
117
+ return {
118
+ link: "".concat(routeAbsPath, "#").concat(demo.asset.id),
119
+ rawTitle: demo.asset.title || '',
120
+ title: demo.asset.title || routeMeta.frontmatter.title,
121
+ description: demo.asset.description || '',
122
+ keywords: demo.asset.keywords || []
123
+ };
124
+ })) || []
125
+ });
126
+ }
127
+ });
128
+ return metadata;
129
+ }
130
+
131
+ function generateHighlightTexts() {
132
+ var str = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
133
+ var keywords = arguments.length > 1 ? arguments[1] : undefined;
134
+ var chunks = findAll({
135
+ textToHighlight: str,
136
+ searchWords: keywords,
137
+ autoEscape: true
138
+ }); // save matched keywords
139
+
140
+ var matchedMapping = {};
141
+ return [chunks.map(function (_ref2, i) {
142
+ var start = _ref2.start,
143
+ end = _ref2.end,
144
+ highlight = _ref2.highlight;
145
+ var highlightText = {
146
+ text: str.slice(start, end)
147
+ }; // omit long str before the first highlighted text
148
+
149
+ if (i === 0 && !highlight && chunks.length > 1 && highlightText.text.length > 20) {
150
+ highlightText.text = "...".concat(highlightText.text.slice(-20));
151
+ } // mark highlight
152
+
153
+
154
+ if (highlight) {
155
+ highlightText.highlighted = true;
156
+ matchedMapping[keywords.find(function (k) {
157
+ return highlightText.text.includes(k);
158
+ })] = true;
159
+ }
160
+
161
+ return highlightText;
162
+ }), matchedMapping];
163
+ }
164
+
165
+ function generateSearchResult(metadata, keywordsStr) {
166
+ var keywords = keywordsStr.split(' ');
167
+ var matchReg = new RegExp(keywordsStr.replace(/[.*+?^${}()|[\]\\]/g, '\\$&').replace(' ', '|'), 'gi');
168
+ var resultMapping = {}; // traverse metadata from all routes
169
+
170
+ metadata.forEach(function (data) {
171
+ var hints = []; // find content & section hints
172
+
173
+ data.sections.forEach(function (sec) {
174
+ // find matched keywords in paragraph
175
+ var _iterator = _createForOfIteratorHelper(sec.paragraphs),
176
+ _step;
177
+
178
+ try {
179
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
180
+ var p = _step.value;
181
+
182
+ if (matchReg.test(p)) {
183
+ var _generateHighlightTex3 = generateHighlightTexts(sec.title, keywords),
184
+ _generateHighlightTex4 = _slicedToArray(_generateHighlightTex3, 2),
185
+ _highlightTitleTexts = _generateHighlightTex4[0],
186
+ _titleMatchMapping = _generateHighlightTex4[1];
187
+
188
+ var _generateHighlightTex5 = generateHighlightTexts(p, keywords),
189
+ _generateHighlightTex6 = _slicedToArray(_generateHighlightTex5, 2),
190
+ highlightTexts = _generateHighlightTex6[0],
191
+ matchMapping = _generateHighlightTex6[1];
192
+
193
+ hints.push({
194
+ type: 'content',
195
+ link: sec.link,
196
+ priority: Object.keys(_objectSpread(_objectSpread({}, _titleMatchMapping), matchMapping)).length,
197
+ highlightTitleTexts: _highlightTitleTexts,
198
+ highlightTexts: highlightTexts
199
+ }); // match at most once in the same section
200
+
201
+ return;
202
+ }
203
+ } // find matched keywords in section title
204
+
205
+ } catch (err) {
206
+ _iterator.e(err);
207
+ } finally {
208
+ _iterator.f();
209
+ }
210
+
211
+ if (matchReg.test(sec.rawTitle)) {
212
+ var _generateHighlightTex = generateHighlightTexts(sec.title, keywords),
213
+ _generateHighlightTex2 = _slicedToArray(_generateHighlightTex, 2),
214
+ highlightTitleTexts = _generateHighlightTex2[0],
215
+ titleMatchMapping = _generateHighlightTex2[1];
216
+
217
+ hints.push({
218
+ type: 'title',
219
+ link: sec.link,
220
+ priority: Object.keys(titleMatchMapping).length,
221
+ highlightTitleTexts: highlightTitleTexts,
222
+ highlightTexts: generateHighlightTexts(sec.paragraphs[0] || '', keywords)[0]
223
+ });
224
+ }
225
+ }); // find demo hints
226
+
227
+ data.demos.forEach(function (demo) {
228
+ if (matchReg.test(demo.rawTitle) || matchReg.test(demo.description)) {
229
+ var _generateHighlightTex7 = generateHighlightTexts(demo.title, keywords),
230
+ _generateHighlightTex8 = _slicedToArray(_generateHighlightTex7, 2),
231
+ highlightTitleTexts = _generateHighlightTex8[0],
232
+ titleMatchMapping = _generateHighlightTex8[1];
233
+
234
+ var _generateHighlightTex9 = generateHighlightTexts(demo.description, keywords),
235
+ _generateHighlightTex10 = _slicedToArray(_generateHighlightTex9, 2),
236
+ highlightTexts = _generateHighlightTex10[0],
237
+ matchMapping = _generateHighlightTex10[1];
238
+
239
+ hints.push({
240
+ type: 'demo',
241
+ link: demo.link,
242
+ priority: Object.keys(_objectSpread(_objectSpread({}, titleMatchMapping), matchMapping)).length,
243
+ highlightTitleTexts: highlightTitleTexts,
244
+ highlightTexts: highlightTexts
245
+ });
246
+ }
247
+ }); // find page hints
248
+
249
+ if (matchReg.test(data.title)) {
250
+ var _data$sections$;
251
+
252
+ var _generateHighlightTex11 = generateHighlightTexts(data.title, keywords),
253
+ _generateHighlightTex12 = _slicedToArray(_generateHighlightTex11, 2),
254
+ highlightTitleTexts = _generateHighlightTex12[0],
255
+ titleMatchMapping = _generateHighlightTex12[1];
256
+
257
+ hints.push({
258
+ type: 'page',
259
+ link: data.link,
260
+ priority: Object.keys(titleMatchMapping).length,
261
+ highlightTitleTexts: highlightTitleTexts,
262
+ highlightTexts: generateHighlightTexts(((_data$sections$ = data.sections[0]) === null || _data$sections$ === void 0 ? void 0 : _data$sections$.paragraphs[0]) || '', keywords)[0]
263
+ });
264
+ } // create nav result if there has any hint
265
+
266
+
267
+ if (hints.length) {
268
+ var _resultMapping$key, _resultMapping$key$hi;
269
+
270
+ var key = data.navTitle || '$ROOT';
271
+ (_resultMapping$key = resultMapping[key]) !== null && _resultMapping$key !== void 0 ? _resultMapping$key : resultMapping[key] = {
272
+ title: data.navTitle,
273
+ priority: data.navOrder,
274
+ hints: []
275
+ };
276
+
277
+ (_resultMapping$key$hi = resultMapping[key].hints).push.apply(_resultMapping$key$hi, hints);
278
+ }
279
+ }); // sort hints
280
+
281
+ Object.values(resultMapping).forEach(function (_ref3) {
282
+ var hints = _ref3.hints;
283
+ hints.sort(function (prev, next) {
284
+ return next.priority - prev.priority;
285
+ });
286
+ });
287
+ return Object.values(resultMapping).sort(function (prev, next) {
288
+ return next.priority - prev.priority;
289
+ });
290
+ }
291
+
292
+ export var useSiteSearch = function useSiteSearch() {
293
+ var debounceTimer = useRef();
294
+ var routes = useLocaleDocRoutes();
295
+
296
+ var _useSiteData = useSiteData(),
297
+ demos = _useSiteData.demos;
298
+
299
+ var _useState = useState(false),
300
+ _useState2 = _slicedToArray(_useState, 2),
301
+ loading = _useState2[0],
302
+ setLoading = _useState2[1];
303
+
304
+ var _useState3 = useState(''),
305
+ _useState4 = _slicedToArray(_useState3, 2),
306
+ keywords = _useState4[0],
307
+ setKeywords = _useState4[1];
308
+
309
+ var navData = useNavData();
310
+
311
+ var _useState5 = useState([]),
312
+ _useState6 = _slicedToArray(_useState5, 2),
313
+ metadata = _useState6[0],
314
+ setMetadata = _useState6[1];
315
+
316
+ var _useState7 = useState([]),
317
+ _useState8 = _slicedToArray(_useState7, 2),
318
+ result = _useState8[0],
319
+ setResult = _useState8[1];
320
+
321
+ var setter = useCallback(function (val) {
322
+ setLoading(true);
323
+ setKeywords(val);
324
+ }, []);
325
+ useEffect(function () {
326
+ setMetadata(generateSearchMetadata(routes, demos, navData));
327
+ }, [routes, demos, navData]);
328
+ useEffect(function () {
329
+ var str = keywords.trim();
330
+
331
+ if (str) {
332
+ clearTimeout(debounceTimer.current);
333
+ debounceTimer.current = window.setTimeout(function () {
334
+ setResult(generateSearchResult(metadata, str));
335
+ setLoading(false);
336
+ }, 100);
337
+ } else {
338
+ setResult([]);
339
+ }
340
+ }, [keywords, metadata]);
341
+ return {
342
+ keywords: keywords,
343
+ setKeywords: setter,
344
+ result: result,
345
+ loading: loading
346
+ };
347
+ };
@@ -0,0 +1,4 @@
1
+ import type { IRouteMeta } from './types';
2
+ export declare const TAB_QUERY_KEY = "tab";
3
+ export declare const useTabQueryState: () => [string | null, (val?: string) => void];
4
+ export declare const useTabMeta: () => NonNullable<IRouteMeta['tabs']>[0]['meta'] | undefined;
@@ -0,0 +1,47 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+
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
+
5
+ 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); }
6
+
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
+
9
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
10
+
11
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
+
13
+ import { history, useLocation, useRouteMeta, useSearchParams } from 'dumi';
14
+ import { useCallback } from 'react';
15
+ export var TAB_QUERY_KEY = 'tab';
16
+ export var useTabQueryState = function useTabQueryState() {
17
+ var _useLocation = useLocation(),
18
+ pathname = _useLocation.pathname;
19
+
20
+ var _useSearchParams = useSearchParams(),
21
+ _useSearchParams2 = _slicedToArray(_useSearchParams, 1),
22
+ params = _useSearchParams2[0];
23
+
24
+ var setTabQueryState = useCallback(function (val) {
25
+ if (val) params.set(TAB_QUERY_KEY, val);else params.delete(TAB_QUERY_KEY);
26
+ history.push({
27
+ pathname: pathname,
28
+ search: params.toString()
29
+ });
30
+ }, [params]);
31
+ return [params.get(TAB_QUERY_KEY), setTabQueryState];
32
+ };
33
+ export var useTabMeta = function useTabMeta() {
34
+ var _tabs$find;
35
+
36
+ var _useRouteMeta = useRouteMeta(),
37
+ tabs = _useRouteMeta.tabs;
38
+
39
+ var _useTabQueryState = useTabQueryState(),
40
+ _useTabQueryState2 = _slicedToArray(_useTabQueryState, 1),
41
+ tabKey = _useTabQueryState2[0];
42
+
43
+ return tabs === null || tabs === void 0 ? void 0 : (_tabs$find = tabs.find(function (_ref) {
44
+ var key = _ref.key;
45
+ return tabKey === key;
46
+ })) === null || _tabs$find === void 0 ? void 0 : _tabs$find.meta;
47
+ };
@@ -27,7 +27,7 @@ var configPlugins_default = (api) => {
27
27
  const configDefaults = {
28
28
  resolve: {
29
29
  docDirs: ["docs"],
30
- entityDirs: [{ type: "component", dir: "src" }],
30
+ atomDirs: [{ type: "component", dir: "src" }],
31
31
  codeBlockMode: "active"
32
32
  },
33
33
  themeConfig: {}
@@ -29,13 +29,15 @@ function getSchemas() {
29
29
  return {
30
30
  resolve: (Joi) => Joi.object({
31
31
  docDirs: Joi.array().items(Joi.alternatives(Joi.string(), Joi.object({ dir: Joi.string(), type: Joi.string().optional() }))).optional(),
32
- entityDirs: Joi.array().items(Joi.object({ type: Joi.string(), dir: Joi.string() })).optional(),
32
+ atomDirs: Joi.array().items(Joi.object({ type: Joi.string(), dir: Joi.string() })).optional(),
33
+ entityDirs: Joi.forbidden().error(new Error("`entityDirs` is already deprecated, please rename it to `atomDirs` in `.umirc.ts` or `config/config.ts`")),
33
34
  codeBlockMode: Joi.string().valid("active", "passive").optional(),
34
35
  entryFile: Joi.string().optional()
35
36
  }).optional(),
36
37
  extraRemarkPlugins: getUnifiedPluginSchema,
37
38
  extraRehypePlugins: getUnifiedPluginSchema,
38
- themeConfig: (Joi) => Joi.object().optional()
39
+ themeConfig: (Joi) => Joi.object().optional(),
40
+ logo: (Joi) => Joi.string()
39
41
  };
40
42
  }
41
43
  // Annotate the CommonJS export names for ESM import in node:
@@ -1,3 +1,8 @@
1
1
  import type { IApi } from "../types";
2
+ /**
3
+ * exclude pre-compiling modules in mfsu mode
4
+ * and make sure there has no multiple instances problem (such as react)
5
+ */
6
+ export declare function safeExcludeInMFSU(api: IApi, excludes: RegExp[]): void;
2
7
  declare const _default: (api: IApi) => void;
3
8
  export default _default;
@@ -22,12 +22,31 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  // src/features/exports.ts
23
23
  var exports_exports = {};
24
24
  __export(exports_exports, {
25
- default: () => exports_default
25
+ default: () => exports_default,
26
+ safeExcludeInMFSU: () => safeExcludeInMFSU
26
27
  });
27
28
  module.exports = __toCommonJS(exports_exports);
28
29
  var import_plugin_utils = require("umi/plugin-utils");
30
+ function safeExcludeInMFSU(api, excludes) {
31
+ if (api.userConfig.mfsu !== false) {
32
+ api.modifyDefaultConfig((memo) => {
33
+ memo.mfsu ?? (memo.mfsu = {});
34
+ memo.mfsu.exclude = (0, import_plugin_utils.deepmerge)(memo.mfsu.exclude || [], excludes);
35
+ memo.extraBabelIncludes ?? (memo.extraBabelIncludes = []);
36
+ memo.extraBabelIncludes.push(...excludes);
37
+ return memo;
38
+ });
39
+ }
40
+ }
29
41
  var exports_default = (api) => {
30
42
  api.describe({ key: void 0 });
43
+ safeExcludeInMFSU(api, [new RegExp("dumi/dist/client")]);
44
+ api.modifyDefaultConfig((memo) => {
45
+ if (api.userConfig.mfsu !== false) {
46
+ memo.mfsu = { strategy: "normal" };
47
+ }
48
+ return memo;
49
+ });
31
50
  api.modifyConfig((memo) => {
32
51
  memo.alias["dumi$"] = "@@/dumi/exports";
33
52
  return memo;
@@ -42,4 +61,6 @@ export * from '${(0, import_plugin_utils.winPath)(require.resolve("../client/the
42
61
  });
43
62
  };
44
63
  // Annotate the CommonJS export names for ESM import in node:
45
- 0 && (module.exports = {});
64
+ 0 && (module.exports = {
65
+ safeExcludeInMFSU
66
+ });