dumi 2.0.0-beta.8 → 2.0.0-rc.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.
Files changed (94) hide show
  1. package/bin/forkedDev.js +3 -0
  2. package/dist/assetParsers/block.d.ts +2 -0
  3. package/dist/assetParsers/block.js +4 -1
  4. package/dist/cli.js +2 -2
  5. package/dist/client/theme-api/DumiDemoGrid.js +2 -1
  6. package/dist/client/theme-api/DumiPage.js +9 -3
  7. package/dist/client/theme-api/index.d.ts +1 -0
  8. package/dist/client/theme-api/index.js +1 -0
  9. package/dist/client/theme-api/openCodeSandbox.d.ts +9 -0
  10. package/dist/client/theme-api/openCodeSandbox.js +110 -0
  11. package/dist/client/theme-api/types.d.ts +11 -7
  12. package/dist/client/theme-api/useLocale.d.ts +2 -1
  13. package/dist/client/theme-api/useSiteSearch.js +47 -31
  14. package/dist/client/theme-api/utils.d.ts +6 -0
  15. package/dist/client/theme-api/utils.js +15 -0
  16. package/dist/constants.d.ts +4 -1
  17. package/dist/constants.js +22 -1
  18. package/dist/features/assets.d.ts +5 -1
  19. package/dist/features/assets.js +7 -1
  20. package/dist/features/autoAlias.d.ts +3 -0
  21. package/dist/features/autoAlias.js +65 -0
  22. package/dist/features/compile.js +4 -6
  23. package/dist/features/configPlugins/index.js +3 -1
  24. package/dist/features/configPlugins/schema.js +3 -2
  25. package/dist/features/derivative.d.ts +11 -0
  26. package/dist/features/derivative.js +110 -0
  27. package/dist/features/exports.d.ts +0 -5
  28. package/dist/features/exports.js +3 -24
  29. package/dist/features/locales.js +15 -8
  30. package/dist/features/meta.js +1 -1
  31. package/dist/features/routes.js +10 -11
  32. package/dist/features/tabs.js +2 -1
  33. package/dist/features/theme/index.js +23 -8
  34. package/dist/features/theme/loader.d.ts +4 -0
  35. package/dist/features/theme/loader.js +5 -1
  36. package/dist/loaders/markdown/index.d.ts +2 -1
  37. package/dist/loaders/markdown/index.js +24 -10
  38. package/dist/loaders/markdown/transformer/index.d.ts +2 -1
  39. package/dist/loaders/markdown/transformer/index.js +14 -3
  40. package/dist/loaders/markdown/transformer/rehypeDemo.d.ts +4 -1
  41. package/dist/loaders/markdown/transformer/rehypeDemo.js +10 -8
  42. package/dist/loaders/markdown/transformer/rehypeEnhancedTag.js +3 -0
  43. package/dist/loaders/markdown/transformer/rehypeImg.js +1 -1
  44. package/dist/loaders/markdown/transformer/rehypeText.js +1 -1
  45. package/dist/loaders/markdown/transformer/remarkEmbed.d.ts +1 -1
  46. package/dist/loaders/markdown/transformer/remarkEmbed.js +6 -2
  47. package/dist/loaders/markdown/transformer/remarkMeta.d.ts +4 -3
  48. package/dist/loaders/markdown/transformer/remarkMeta.js +20 -2
  49. package/dist/preset.js +15 -0
  50. package/dist/service/cli.d.ts +5 -0
  51. package/dist/service/cli.js +69 -0
  52. package/dist/service/constants.d.ts +4 -0
  53. package/dist/service/constants.js +38 -0
  54. package/dist/service/dev.d.ts +1 -0
  55. package/dist/service/dev.js +45 -0
  56. package/dist/service/forkedDev.d.ts +1 -0
  57. package/dist/service/forkedDev.js +37 -0
  58. package/dist/service/printHelp.d.ts +1 -0
  59. package/dist/service/printHelp.js +37 -0
  60. package/dist/service/service.d.ts +13 -0
  61. package/dist/service/service.js +63 -0
  62. package/dist/techStacks/react.js +1 -0
  63. package/dist/types.d.ts +1 -0
  64. package/dist/utils.d.ts +4 -0
  65. package/dist/utils.js +26 -2
  66. package/package.json +11 -7
  67. package/theme-default/builtins/API/index.js +2 -1
  68. package/theme-default/builtins/Previewer/index.js +4 -122
  69. package/theme-default/builtins/Previewer/index.less +0 -165
  70. package/theme-default/builtins/Table/index.d.ts +6 -0
  71. package/theme-default/builtins/Table/index.js +59 -0
  72. package/theme-default/builtins/Table/index.less +61 -0
  73. package/theme-default/layouts/DocLayout/index.js +5 -1
  74. package/theme-default/layouts/DocLayout/index.less +18 -0
  75. package/theme-default/locales/en-US.json +1 -1
  76. package/theme-default/locales/zh-CN.json +1 -1
  77. package/theme-default/slots/Content/index.less +7 -1
  78. package/theme-default/slots/Features/index.js +6 -2
  79. package/theme-default/slots/Features/index.less +9 -1
  80. package/theme-default/slots/Footer/index.d.ts +4 -0
  81. package/theme-default/slots/Footer/index.js +18 -0
  82. package/theme-default/slots/Footer/index.less +19 -0
  83. package/theme-default/slots/Hero/index.js +8 -8
  84. package/theme-default/slots/Hero/index.less +10 -6
  85. package/theme-default/slots/LangSwitch/index.js +33 -16
  86. package/theme-default/slots/LangSwitch/index.less +23 -0
  87. package/theme-default/slots/PreviewerActions/index.d.ts +11 -0
  88. package/theme-default/slots/PreviewerActions/index.js +125 -0
  89. package/theme-default/slots/PreviewerActions/index.less +168 -0
  90. package/theme-default/slots/PreviewerActionsExtra/index.d.ts +4 -0
  91. package/theme-default/slots/PreviewerActionsExtra/index.js +7 -0
  92. package/theme-default/slots/Sidebar/index.js +3 -2
  93. package/theme-default/slots/Toc/index.less +4 -0
  94. package/theme.d.ts +0 -1
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+
3
+ require('../dist/service/forkedDev');
@@ -1,5 +1,6 @@
1
1
  import { parseCodeFrontmatter } from "../utils";
2
2
  import type { ExampleBlockAsset } from 'dumi-assets-types';
3
+ import type { sync } from 'enhanced-resolve';
3
4
  export interface IParsedBlockAsset {
4
5
  asset: ExampleBlockAsset;
5
6
  sources: Record<string, string>;
@@ -10,5 +11,6 @@ declare function parseBlockAsset(opts: {
10
11
  id: string;
11
12
  refAtomIds: string[];
12
13
  entryPointCode?: string;
14
+ resolver: typeof sync;
13
15
  }): Promise<IParsedBlockAsset>;
14
16
  export default parseBlockAsset;
@@ -27,6 +27,7 @@ __export(block_exports, {
27
27
  module.exports = __toCommonJS(block_exports);
28
28
  var import_utils = require("../utils");
29
29
  var import_esbuild = require("@umijs/bundler-utils/compiled/esbuild");
30
+ var import_assert = __toESM(require("assert"));
30
31
  var import_fs = __toESM(require("fs"));
31
32
  var import_path = __toESM(require("path"));
32
33
  var import_plugin_utils = require("umi/plugin-utils");
@@ -56,8 +57,10 @@ async function parseBlockAsset(opts) {
56
57
  setup: (builder) => {
57
58
  builder.onResolve({ filter: /.*/ }, (args) => {
58
59
  if (args.kind !== "entry-point" && !args.path.startsWith(".")) {
60
+ const resolved = opts.resolver(args.resolveDir, args.path);
61
+ (0, import_assert.default)(resolved, `Can't resolve ${args.path} from ${args.resolveDir}`);
59
62
  const pkgJsonPath = import_plugin_utils.pkgUp.pkgUpSync({
60
- cwd: require.resolve(args.path, { paths: [args.resolveDir] })
63
+ cwd: resolved
61
64
  });
62
65
  if (pkgJsonPath) {
63
66
  asset.dependencies[args.path] = {
package/dist/cli.js CHANGED
@@ -15,12 +15,12 @@ var __copyProps = (to, from, except, desc) => {
15
15
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod));
16
16
 
17
17
  // src/cli.ts
18
- var import_umi = require("umi");
19
18
  var import_plugin_utils = require("umi/plugin-utils");
19
+ var import_cli = require("./service/cli");
20
20
  (async () => {
21
21
  try {
22
22
  import_plugin_utils.logger.info(import_plugin_utils.chalk.cyan.bold(`dumi v${require("../package").version}`));
23
- await (0, import_umi.run)({
23
+ await (0, import_cli.run)({
24
24
  presets: [require.resolve("./preset")]
25
25
  });
26
26
  } catch (e) {
@@ -53,7 +53,8 @@ export var DumiDemoGrid = function DumiDemoGrid(props) {
53
53
  return /*#__PURE__*/React.createElement("section", {
54
54
  style: {
55
55
  flex: 1,
56
- padding: 8
56
+ padding: 8,
57
+ width: 0
57
58
  },
58
59
  key: String(i)
59
60
  }, col.map(function (item) {
@@ -16,7 +16,8 @@ import React, { useEffect, useState } from 'react';
16
16
  import { useTabQueryState } from "./useTabMeta";
17
17
  export var DumiPage = function DumiPage(props) {
18
18
  var _useLocation = useLocation(),
19
- hash = _useLocation.hash;
19
+ hash = _useLocation.hash,
20
+ pathname = _useLocation.pathname;
20
21
 
21
22
  var _useRouteMeta = useRouteMeta(),
22
23
  tabs = _useRouteMeta.tabs;
@@ -45,9 +46,14 @@ export var DumiPage = function DumiPage(props) {
45
46
  }, []); // handle hash change
46
47
 
47
48
  useEffect(function () {
48
- var elm = document.getElementById(hash.replace('#', ''));
49
+ var id = hash.replace('#', '');
50
+ var elm = id && document.getElementById(id);
49
51
  if (elm) elm.scrollIntoView();
50
- }, [hash]);
52
+ }, [hash]); // handle pathname change
53
+
54
+ useEffect(function () {
55
+ document.documentElement.scrollTo(0, 0);
56
+ }, [pathname]);
51
57
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ContentTabs, {
52
58
  tabs: tabs,
53
59
  tabKey: tabKey,
@@ -3,6 +3,7 @@ export { useSiteData } from './context';
3
3
  export { DumiDemo } from './DumiDemo';
4
4
  export { DumiDemoGrid } from './DumiDemoGrid';
5
5
  export { DumiPage } from './DumiPage';
6
+ export { openCodeSandbox } from './openCodeSandbox';
6
7
  export type { IPreviewerProps } from './types';
7
8
  export { useAtomAssets } from './useAtomAssets';
8
9
  export { useLocale } from './useLocale';
@@ -3,6 +3,7 @@ export { useSiteData } from "./context";
3
3
  export { DumiDemo } from "./DumiDemo";
4
4
  export { DumiDemoGrid } from "./DumiDemoGrid";
5
5
  export { DumiPage } from "./DumiPage";
6
+ export { openCodeSandbox } from "./openCodeSandbox";
6
7
  export { useAtomAssets } from "./useAtomAssets";
7
8
  export { useLocale } from "./useLocale";
8
9
  export { useNavData } from "./useNavData";
@@ -0,0 +1,9 @@
1
+ /**
2
+ * use CodeSandbox.io
3
+ * @param data previewer opts
4
+ * @param opts the api that CodeSandbox calls when creating the demo
5
+ * @note return a open function for open demo on codesandbox.io
6
+ */
7
+ export declare const openCodeSandbox: (data: IPreviewerProps, opts?: {
8
+ api?: string;
9
+ }) => void;
@@ -0,0 +1,110 @@
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 { getParameters } from 'codesandbox/lib/api/define';
14
+ import { genReactRenderCode } from "./utils";
15
+ var CSB_API_ENDPOINT = 'https://codesandbox.io/api/v1/sandboxes/define';
16
+ /**
17
+ * get serialized data that use to submit to codesandbox.io
18
+ * @param opts previewer props
19
+ */
20
+
21
+ function getCSBData(opts) {
22
+ var _opts$asset$dependenc, _react, _deps$_react, _reactDom, _deps$_reactDom;
23
+
24
+ var isTSX = Boolean((_opts$asset$dependenc = opts.asset.dependencies) === null || _opts$asset$dependenc === void 0 ? void 0 : _opts$asset$dependenc['index.tsx']);
25
+ var ext = isTSX ? '.tsx' : '.jsx';
26
+ var files = {};
27
+ var deps = {};
28
+ var entryFileName = "index".concat(ext);
29
+ Object.entries(opts.asset.dependencies).forEach(function (_ref) {
30
+ var _ref2 = _slicedToArray(_ref, 2),
31
+ name = _ref2[0],
32
+ _ref2$ = _ref2[1],
33
+ type = _ref2$.type,
34
+ value = _ref2$.value;
35
+
36
+ if (type === 'NPM') {
37
+ // generate dependencies
38
+ deps[name] = value;
39
+ } else {
40
+ // append other imported local files
41
+ files[name === entryFileName ? "App".concat(ext) : name] = {
42
+ content: value,
43
+ isBinary: false
44
+ };
45
+ }
46
+ }); // add react、react-dom dependency
47
+
48
+ (_deps$_react = deps[_react = 'react']) !== null && _deps$_react !== void 0 ? _deps$_react : deps[_react] = 'latest';
49
+ (_deps$_reactDom = deps[_reactDom = 'react-dom']) !== null && _deps$_reactDom !== void 0 ? _deps$_reactDom : deps[_reactDom] = deps.react; // append sandbox.config.json
50
+
51
+ files['sandbox.config.json'] = {
52
+ content: JSON.stringify({
53
+ template: isTSX ? 'create-react-app-typescript' : 'create-react-app'
54
+ }, null, 2),
55
+ isBinary: false
56
+ }; // append package.json
57
+
58
+ files['package.json'] = {
59
+ content: JSON.stringify({
60
+ name: opts.title,
61
+ description: opts.description || 'An auto-generated demo by dumi',
62
+ main: entryFileName,
63
+ dependencies: deps,
64
+ // add TypeScript dependency if required, must in devDeps to avoid csb compile error
65
+ devDependencies: isTSX ? {
66
+ typescript: '^4'
67
+ } : {}
68
+ }, null, 2),
69
+ isBinary: false
70
+ }; // append index.html
71
+
72
+ files['index.html'] = {
73
+ content: '<div style="margin: 16px;" id="root"></div>',
74
+ isBinary: false
75
+ }; // append entry file
76
+
77
+ files[entryFileName] = {
78
+ content: genReactRenderCode(deps.react),
79
+ isBinary: false
80
+ };
81
+ return getParameters({
82
+ files: files
83
+ });
84
+ }
85
+ /**
86
+ * use CodeSandbox.io
87
+ * @param data previewer opts
88
+ * @param opts the api that CodeSandbox calls when creating the demo
89
+ * @note return a open function for open demo on codesandbox.io
90
+ */
91
+
92
+
93
+ export var openCodeSandbox = function openCodeSandbox(data, opts) {
94
+ var _data$assets;
95
+
96
+ var form = document.createElement('form');
97
+ var input = document.createElement('input');
98
+ var CSBData = getCSBData(data);
99
+ form.method = 'POST';
100
+ form.target = '_blank';
101
+ form.style.display = 'none';
102
+ form.action = (opts === null || opts === void 0 ? void 0 : opts.api) || CSB_API_ENDPOINT;
103
+ form.appendChild(input);
104
+ form.setAttribute('data-demo', ((_data$assets = data.assets) === null || _data$assets === void 0 ? void 0 : _data$assets.id) || '');
105
+ input.name = 'parameters';
106
+ input.value = CSBData;
107
+ document.body.appendChild(form);
108
+ form.submit();
109
+ form.remove();
110
+ };
@@ -10,9 +10,9 @@ export interface IPreviewerProps {
10
10
  */
11
11
  description?: string;
12
12
  /**
13
- * file path of current demo
13
+ * filename of current demo
14
14
  */
15
- filePath?: string;
15
+ filename?: string;
16
16
  /**
17
17
  * use iframe to render demo
18
18
  */
@@ -61,8 +61,8 @@ export interface IRouteMeta {
61
61
  title?: string;
62
62
  description?: string;
63
63
  background?: string;
64
- links?: {
65
- title: string;
64
+ actions?: {
65
+ text: string;
66
66
  link: string;
67
67
  }[];
68
68
  [key: string]: any;
@@ -78,6 +78,9 @@ export interface IRouteMeta {
78
78
  cols?: number;
79
79
  tocDepth?: number;
80
80
  };
81
+ atomId?: string;
82
+ filename?: string;
83
+ [key: string]: any;
81
84
  };
82
85
  toc: {
83
86
  id: string;
@@ -110,17 +113,17 @@ export interface IRouteMeta {
110
113
  [key: string]: any;
111
114
  };
112
115
  }[];
113
- [key: string]: any;
114
116
  }
115
117
  declare type IBasicLocale = {
116
118
  id: string;
117
119
  name: string;
118
120
  };
119
- export declare type ILocalesConfig = ((IBasicLocale & {
121
+ export declare type ILocale = (IBasicLocale & {
120
122
  base: string;
121
123
  }) | (IBasicLocale & {
122
124
  suffix: string;
123
- }))[];
125
+ });
126
+ export declare type ILocalesConfig = ILocale[];
124
127
  export interface INavItem {
125
128
  title: string;
126
129
  link: string;
@@ -146,6 +149,7 @@ export interface IThemeConfig {
146
149
  children?: INavItem[];
147
150
  })[];
148
151
  sidebar?: Record<string, ISidebarGroup[]>;
152
+ footer?: string;
149
153
  [key: string]: any;
150
154
  }
151
155
  export declare type IRoutesById = Record<string, {
@@ -1 +1,2 @@
1
- export declare const useLocale: () => any;
1
+ import type { ILocale } from './types';
2
+ export declare const useLocale: () => ILocale;
@@ -1,3 +1,9 @@
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
+
1
7
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
8
 
3
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."); }
@@ -71,7 +77,7 @@ function generateSearchMetadata(routes, demos, nav) {
71
77
  var _demosMapping$route$i;
72
78
 
73
79
  var routeMeta = route.meta;
74
- var routeAbsPath = route.path.replace(/^([^/])/, '/$1');
80
+ var routeAbsPath = route.path.replace(/^([^/])/, '/$1') || '/';
75
81
  var routeNav = nav.find(function (item) {
76
82
  return routeAbsPath === item.link || routeAbsPath.startsWith("".concat(item.activePath, "/"));
77
83
  });
@@ -81,17 +87,17 @@ function generateSearchMetadata(routes, demos, nav) {
81
87
  return (_demo$asset = demo.asset) === null || _demo$asset === void 0 ? void 0 : _demo$asset.id;
82
88
  });
83
89
  var orphanSection = createMetadataSection('', routeMeta.frontmatter.title, routeAbsPath, routeMeta.texts);
84
- var tocSections = routeMeta.toc // exclude demo id, to avoid duplicate
85
- .filter(function (_ref) {
86
- var id = _ref.id,
87
- depth = _ref.depth;
88
- return !demoIds.includes(id) && depth > 1;
89
- }).map(function (toc, i) {
90
- return createMetadataSection(toc.title, "".concat(routeMeta.frontmatter.title, " - ").concat(toc.title), "".concat(routeAbsPath, "#").concat(toc.id), routeMeta.texts, i);
91
- });
92
- var tabSections = (routeMeta.tabs || []).reduce(function (acc, _ref2) {
93
- var key = _ref2.key,
94
- meta = _ref2.meta;
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;
95
101
  // collect orphan section that not in toc
96
102
  var tabOrphanSection = createMetadataSection('', "".concat(routeMeta.frontmatter.title, " - ").concat(meta.frontmatter.title), "".concat(routeAbsPath, "?").concat(TAB_QUERY_KEY, "=").concat(key), meta.texts);
97
103
  if (tabOrphanSection) acc.push(tabOrphanSection); // collect sections by toc
@@ -129,11 +135,13 @@ function generateHighlightTexts() {
129
135
  textToHighlight: str,
130
136
  searchWords: keywords,
131
137
  autoEscape: true
132
- });
133
- return [chunks.map(function (_ref3, i) {
134
- var start = _ref3.start,
135
- end = _ref3.end,
136
- highlight = _ref3.highlight;
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;
137
145
  var highlightText = {
138
146
  text: str.slice(start, end)
139
147
  }; // omit long str before the first highlighted text
@@ -145,10 +153,13 @@ function generateHighlightTexts() {
145
153
 
146
154
  if (highlight) {
147
155
  highlightText.highlighted = true;
156
+ matchedMapping[keywords.find(function (k) {
157
+ return highlightText.text.includes(k);
158
+ })] = true;
148
159
  }
149
160
 
150
161
  return highlightText;
151
- }), chunks.length];
162
+ }), matchedMapping];
152
163
  }
153
164
 
154
165
  function generateSearchResult(metadata, keywordsStr) {
@@ -172,17 +183,17 @@ function generateSearchResult(metadata, keywordsStr) {
172
183
  var _generateHighlightTex3 = generateHighlightTexts(sec.title, keywords),
173
184
  _generateHighlightTex4 = _slicedToArray(_generateHighlightTex3, 2),
174
185
  _highlightTitleTexts = _generateHighlightTex4[0],
175
- _titleMatchCount = _generateHighlightTex4[1];
186
+ _titleMatchMapping = _generateHighlightTex4[1];
176
187
 
177
188
  var _generateHighlightTex5 = generateHighlightTexts(p, keywords),
178
189
  _generateHighlightTex6 = _slicedToArray(_generateHighlightTex5, 2),
179
190
  highlightTexts = _generateHighlightTex6[0],
180
- matchCount = _generateHighlightTex6[1];
191
+ matchMapping = _generateHighlightTex6[1];
181
192
 
182
193
  hints.push({
183
194
  type: 'content',
184
195
  link: sec.link,
185
- priority: _titleMatchCount + matchCount,
196
+ priority: Object.keys(_objectSpread(_objectSpread({}, _titleMatchMapping), matchMapping)).length,
186
197
  highlightTitleTexts: _highlightTitleTexts,
187
198
  highlightTexts: highlightTexts
188
199
  }); // match at most once in the same section
@@ -201,12 +212,12 @@ function generateSearchResult(metadata, keywordsStr) {
201
212
  var _generateHighlightTex = generateHighlightTexts(sec.title, keywords),
202
213
  _generateHighlightTex2 = _slicedToArray(_generateHighlightTex, 2),
203
214
  highlightTitleTexts = _generateHighlightTex2[0],
204
- titleMatchCount = _generateHighlightTex2[1];
215
+ titleMatchMapping = _generateHighlightTex2[1];
205
216
 
206
217
  hints.push({
207
218
  type: 'title',
208
219
  link: sec.link,
209
- priority: titleMatchCount,
220
+ priority: Object.keys(titleMatchMapping).length,
210
221
  highlightTitleTexts: highlightTitleTexts,
211
222
  highlightTexts: generateHighlightTexts(sec.paragraphs[0] || '', keywords)[0]
212
223
  });
@@ -218,17 +229,17 @@ function generateSearchResult(metadata, keywordsStr) {
218
229
  var _generateHighlightTex7 = generateHighlightTexts(demo.title, keywords),
219
230
  _generateHighlightTex8 = _slicedToArray(_generateHighlightTex7, 2),
220
231
  highlightTitleTexts = _generateHighlightTex8[0],
221
- titleMatchCount = _generateHighlightTex8[1];
232
+ titleMatchMapping = _generateHighlightTex8[1];
222
233
 
223
234
  var _generateHighlightTex9 = generateHighlightTexts(demo.description, keywords),
224
235
  _generateHighlightTex10 = _slicedToArray(_generateHighlightTex9, 2),
225
236
  highlightTexts = _generateHighlightTex10[0],
226
- matchCount = _generateHighlightTex10[1];
237
+ matchMapping = _generateHighlightTex10[1];
227
238
 
228
239
  hints.push({
229
240
  type: 'demo',
230
241
  link: demo.link,
231
- priority: titleMatchCount + matchCount,
242
+ priority: Object.keys(_objectSpread(_objectSpread({}, titleMatchMapping), matchMapping)).length,
232
243
  highlightTitleTexts: highlightTitleTexts,
233
244
  highlightTexts: highlightTexts
234
245
  });
@@ -241,12 +252,12 @@ function generateSearchResult(metadata, keywordsStr) {
241
252
  var _generateHighlightTex11 = generateHighlightTexts(data.title, keywords),
242
253
  _generateHighlightTex12 = _slicedToArray(_generateHighlightTex11, 2),
243
254
  highlightTitleTexts = _generateHighlightTex12[0],
244
- titleMatchCount = _generateHighlightTex12[1];
255
+ titleMatchMapping = _generateHighlightTex12[1];
245
256
 
246
257
  hints.push({
247
258
  type: 'page',
248
259
  link: data.link,
249
- priority: titleMatchCount,
260
+ priority: Object.keys(titleMatchMapping).length,
250
261
  highlightTitleTexts: highlightTitleTexts,
251
262
  highlightTexts: generateHighlightTexts(((_data$sections$ = data.sections[0]) === null || _data$sections$ === void 0 ? void 0 : _data$sections$.paragraphs[0]) || '', keywords)[0]
252
263
  });
@@ -263,10 +274,15 @@ function generateSearchResult(metadata, keywordsStr) {
263
274
  hints: []
264
275
  };
265
276
 
266
- (_resultMapping$key$hi = resultMapping[key].hints).push.apply(_resultMapping$key$hi, _toConsumableArray(hints.sort(function (prev, next) {
267
- return next.priority - prev.priority;
268
- })));
277
+ (_resultMapping$key$hi = resultMapping[key].hints).push.apply(_resultMapping$key$hi, hints);
269
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
+ });
270
286
  });
271
287
  return Object.values(resultMapping).sort(function (prev, next) {
272
288
  return next.priority - prev.priority;
@@ -1,2 +1,8 @@
1
1
  import type { IRoutesById } from './types';
2
2
  export declare const useLocaleDocRoutes: () => IRoutesById;
3
+ /**
4
+ * 在 react 18 中需要新的 render 方式,这个函数用来处理不同的 jsx 模式。
5
+ * @param version react version
6
+ * @returns code string
7
+ */
8
+ export declare const genReactRenderCode: (version: string) => string;
@@ -41,4 +41,19 @@ export var useLocaleDocRoutes = function useLocaleDocRoutes() {
41
41
  localeDocRoutes = _useState2[0];
42
42
 
43
43
  return localeDocRoutes;
44
+ };
45
+ /**
46
+ * 在 react 18 中需要新的 render 方式,这个函数用来处理不同的 jsx 模式。
47
+ * @param version react version
48
+ * @returns code string
49
+ */
50
+
51
+ export var genReactRenderCode = function genReactRenderCode(version) {
52
+ var annotation = "/**\n * This is an auto-generated demo by dumi\n * if you think it is not working as expected,\n * please report the issue at\n * https://github.com/umijs/dumi/issues\n */";
53
+
54
+ if (version.startsWith('18.') || version === 'latest') {
55
+ return "".concat(annotation, "\n\nimport React from 'react';\nimport { createRoot } from \"react-dom/client\";\nimport App from \"./App\";\n\nconst rootElement = document.getElementById(\"root\");\nconst root = createRoot(rootElement);\n\nroot.render(<App />);");
56
+ }
57
+
58
+ return "".concat(annotation, "\n \nimport React from 'react';\nimport ReactDOM from 'react-dom';\nimport App from './App';\n \nReactDOM.render(\n <App />,\n document.getElementById('root'),\n);");
44
59
  };
@@ -1,4 +1,6 @@
1
- export declare const LOCAL_THEME_DIR = ".dumi/theme";
1
+ export declare const LOCAL_DUMI_DIR = ".dumi";
2
+ export declare const LOCAL_THEME_DIR: string;
3
+ export declare const LOCAL_PAGES_DIR: string;
2
4
  export declare const THEME_PREFIX = "dumi-theme-";
3
5
  export declare const SP_ROUTE_PREFIX = "~";
4
6
  export declare const PICKED_PKG_FIELDS: {
@@ -10,3 +12,4 @@ export declare const PICKED_PKG_FIELDS: {
10
12
  author: string;
11
13
  authors: string;
12
14
  };
15
+ export declare const CLIENT_DEPS: string[];
package/dist/constants.js CHANGED
@@ -19,13 +19,18 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
19
19
  // src/constants.ts
20
20
  var constants_exports = {};
21
21
  __export(constants_exports, {
22
+ CLIENT_DEPS: () => CLIENT_DEPS,
23
+ LOCAL_DUMI_DIR: () => LOCAL_DUMI_DIR,
24
+ LOCAL_PAGES_DIR: () => LOCAL_PAGES_DIR,
22
25
  LOCAL_THEME_DIR: () => LOCAL_THEME_DIR,
23
26
  PICKED_PKG_FIELDS: () => PICKED_PKG_FIELDS,
24
27
  SP_ROUTE_PREFIX: () => SP_ROUTE_PREFIX,
25
28
  THEME_PREFIX: () => THEME_PREFIX
26
29
  });
27
30
  module.exports = __toCommonJS(constants_exports);
28
- var LOCAL_THEME_DIR = ".dumi/theme";
31
+ var LOCAL_DUMI_DIR = ".dumi";
32
+ var LOCAL_THEME_DIR = `${LOCAL_DUMI_DIR}/theme`;
33
+ var LOCAL_PAGES_DIR = `${LOCAL_DUMI_DIR}/pages`;
29
34
  var THEME_PREFIX = "dumi-theme-";
30
35
  var SP_ROUTE_PREFIX = "~";
31
36
  var PICKED_PKG_FIELDS = {
@@ -37,8 +42,24 @@ var PICKED_PKG_FIELDS = {
37
42
  author: "",
38
43
  authors: ""
39
44
  };
45
+ var CLIENT_DEPS = [
46
+ "@ant-design/icons-svg",
47
+ "@makotot/ghostui",
48
+ "deepmerge",
49
+ "highlight-words-core",
50
+ "lodash.throttle",
51
+ "prism-react-renderer",
52
+ "prismjs",
53
+ "rc-tabs",
54
+ "react-copy-to-clipboard",
55
+ "react-helmet",
56
+ "react-intl"
57
+ ];
40
58
  // Annotate the CommonJS export names for ESM import in node:
41
59
  0 && (module.exports = {
60
+ CLIENT_DEPS,
61
+ LOCAL_DUMI_DIR,
62
+ LOCAL_PAGES_DIR,
42
63
  LOCAL_THEME_DIR,
43
64
  PICKED_PKG_FIELDS,
44
65
  SP_ROUTE_PREFIX,
@@ -1,10 +1,14 @@
1
1
  import type { IApi } from "../types";
2
- import type { ExampleAsset } from 'dumi-assets-types';
2
+ import type { AtomAsset, ExampleAsset } from 'dumi-assets-types';
3
3
  declare const examples: ExampleAsset[];
4
4
  /**
5
5
  * internal function to add example assets
6
6
  */
7
7
  export declare function addExampleAssets(data: typeof examples): void;
8
+ /**
9
+ * internal function to add meta for atom
10
+ */
11
+ export declare function addAtomMeta(atomId: string, data: Partial<AtomAsset>): void;
8
12
  /**
9
13
  * plugin for generate assets.json
10
14
  */
@@ -22,6 +22,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
22
22
  // src/features/assets.ts
23
23
  var assets_exports = {};
24
24
  __export(assets_exports, {
25
+ addAtomMeta: () => addAtomMeta,
25
26
  addExampleAssets: () => addExampleAssets,
26
27
  default: () => assets_default
27
28
  });
@@ -30,9 +31,13 @@ var import_fs = __toESM(require("fs"));
30
31
  var import_path = __toESM(require("path"));
31
32
  var import_plugin_utils = require("umi/plugin-utils");
32
33
  var examples = [];
34
+ var atomsMeta = {};
33
35
  function addExampleAssets(data) {
34
36
  examples.push(...data);
35
37
  }
38
+ function addAtomMeta(atomId, data) {
39
+ atomsMeta[atomId] = import_plugin_utils.lodash.pick(data, ["title", "keywords", "deprecated"]);
40
+ }
36
41
  var assets_default = (api) => {
37
42
  api.describe({
38
43
  config: {
@@ -53,7 +58,7 @@ var assets_default = (api) => {
53
58
  homepage: api.pkg.homepage,
54
59
  repository: api.pkg.repository,
55
60
  assets: {
56
- atoms: Object.values(components),
61
+ atoms: Object.values(components).map((atom) => Object.assign(atom, atomsMeta[atom.id] || {})),
57
62
  examples: import_plugin_utils.lodash.uniqBy(examples, "id")
58
63
  }
59
64
  }
@@ -63,5 +68,6 @@ var assets_default = (api) => {
63
68
  };
64
69
  // Annotate the CommonJS export names for ESM import in node:
65
70
  0 && (module.exports = {
71
+ addAtomMeta,
66
72
  addExampleAssets
67
73
  });
@@ -0,0 +1,3 @@
1
+ import type { IApi } from "../types";
2
+ declare const _default: (api: IApi) => void;
3
+ export default _default;