dumi 2.1.22 → 2.1.23

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.
@@ -59,10 +59,11 @@ export var DumiDemoGrid = function DumiDemoGrid(props) {
59
59
  };
60
60
 
61
61
  window.addEventListener('resize', handler);
62
+ handler();
62
63
  return function () {
63
64
  return window.removeEventListener('resize', handler);
64
65
  };
65
- }, []);
66
+ }, [props.items, fm.demo]);
66
67
  return /*#__PURE__*/React.createElement("div", {
67
68
  style: {
68
69
  display: 'flex',
@@ -12,6 +12,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
 
13
13
  import { useRouteMeta, useSiteData } from 'dumi';
14
14
  import ContentTabs from 'dumi/theme/slots/ContentTabs';
15
+ import nprogress from 'nprogress';
15
16
  import React, { useEffect, useState } from 'react';
16
17
  import { useTabQueryState } from "./useTabMeta";
17
18
  export var DumiPage = function DumiPage(props) {
@@ -39,6 +40,7 @@ export var DumiPage = function DumiPage(props) {
39
40
 
40
41
  useEffect(function () {
41
42
  setLoading(false);
43
+ nprogress.done();
42
44
  }, []);
43
45
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ContentTabs, {
44
46
  tabs: tabs,
@@ -196,6 +196,7 @@ export interface IThemeConfig {
196
196
  default: 'light' | 'dark' | 'auto';
197
197
  switch: boolean;
198
198
  };
199
+ nprogress?: boolean;
199
200
  socialLinks: {
200
201
  [key in SocialTypes]: string;
201
202
  };
@@ -33,7 +33,8 @@ var configPlugins_default = (api) => {
33
33
  },
34
34
  themeConfig: {
35
35
  footer: `Copyright \xA9 ${new Date().getFullYear()} | Powered by <a href="https://d.umijs.org" target="_blank" rel="noreferrer">dumi</a>`,
36
- prefersColor: { default: "light", switch: true }
36
+ prefersColor: { default: "light", switch: true },
37
+ nprogress: true
37
38
  }
38
39
  };
39
40
  const schemas = (0, import_schema.getSchemas)();
@@ -137,7 +137,7 @@ var theme_default = (api) => {
137
137
  return memo;
138
138
  });
139
139
  api.onGenerateFiles(() => {
140
- var _a;
140
+ var _a, _b, _c, _d;
141
141
  themeMapKeys.forEach((key) => {
142
142
  Object.values(originalThemeData[key] || {}).forEach((item) => {
143
143
  if (item.source === "dumi")
@@ -161,11 +161,16 @@ var theme_default = (api) => {
161
161
  const entryExports = entryFile ? getModuleExports(entryFile) : [];
162
162
  const hasDefaultExport = entryExports.includes("default");
163
163
  const hasNamedExport = entryExports.some((exp) => exp !== "default");
164
+ const enableNProgress = !!api.config.themeConfig.nprogress;
164
165
  api.writeTmpFile({
165
166
  noPluginDir: true,
166
167
  path: "dumi/theme/ContextWrapper.tsx",
167
168
  content: `import React, { useState, useEffect, useRef } from 'react';
168
169
  import { useOutlet, history } from 'dumi';
170
+ ${enableNProgress ? `
171
+ import nprogress from 'nprogress';
172
+ import './nprogress.css';
173
+ ` : ""}
169
174
  import { SiteContext } from '${(0, import_plugin_utils.winPath)(require.resolve("../../client/theme-api/context"))}';
170
175
  import { demos, components } from '../meta';
171
176
  import { locales } from '../locales/config';${hasDefaultExport ? `
@@ -190,6 +195,9 @@ export default function DumiContextWrapper() {
190
195
  // mark loading when route change, page component will set false when loaded
191
196
  setLoading(true);
192
197
 
198
+ // start nprogress
199
+ ${enableNProgress ? `nprogress.start();` : ""}
200
+
193
201
  // scroll to top when route changed
194
202
  document.documentElement.scrollTo(0, 0);
195
203
  }
@@ -213,6 +221,72 @@ export default function DumiContextWrapper() {
213
221
  );
214
222
  }`
215
223
  });
224
+ const primaryColor = typeof ((_b = api.config) == null ? void 0 : _b.theme) === "object" ? (_d = (_c = api.config) == null ? void 0 : _c.theme) == null ? void 0 : _d["@c-primary"] : "#1677ff";
225
+ api.writeTmpFile({
226
+ noPluginDir: true,
227
+ path: "dumi/theme/nprogress.css",
228
+ content: `
229
+ /* https://unpkg.com/browse/nprogress@0.2.0/nprogress.css */
230
+ #nprogress {
231
+ pointer-events: none;
232
+ }
233
+
234
+ #nprogress .bar {
235
+ background: var;
236
+ position: fixed;
237
+ z-index: 1031;
238
+ top: 0;
239
+ left: 0;
240
+ width: 100%;
241
+ height: 2px;
242
+ }
243
+
244
+ #nprogress .peg {
245
+ display: block;
246
+ position: absolute;
247
+ right: 0px;
248
+ width: 100px;
249
+ height: 100%;
250
+ box-shadow: 0 0 10px ${primaryColor}, 0 0 5px ${primaryColor};
251
+ opacity: 1.0;
252
+ transform: rotate(3deg) translate(0px, -4px);
253
+ }
254
+
255
+ #nprogress .spinner {
256
+ display: block;
257
+ position: fixed;
258
+ z-index: 1031;
259
+ top: 15px;
260
+ right: 15px;
261
+ }
262
+
263
+ #nprogress .spinner-icon {
264
+ width: 18px;
265
+ height: 18px;
266
+ box-sizing: border-box;
267
+ border: solid 2px transparent;
268
+ border-top-color: ${primaryColor};
269
+ border-left-color: ${primaryColor};
270
+ border-radius: 50%;
271
+ animation: nprogress-spinner 400ms linear infinite;
272
+ }
273
+
274
+ .nprogress-custom-parent {
275
+ overflow: hidden;
276
+ position: relative;
277
+ }
278
+
279
+ .nprogress-custom-parent #nprogress .spinner,
280
+ .nprogress-custom-parent #nprogress .bar {
281
+ position: absolute;
282
+ }
283
+
284
+ @keyframes nprogress-spinner {
285
+ 0% { transform: rotate(0deg); }
286
+ 100% { transform: rotate(360deg); }
287
+ }
288
+ `
289
+ });
216
290
  });
217
291
  api.addEntryCodeAhead(() => {
218
292
  const { prefersColor } = api.config.themeConfig;
@@ -107,6 +107,7 @@ var depsMapping = {};
107
107
  function mdLoader(content) {
108
108
  const opts = this.getOptions();
109
109
  const cb = this.async();
110
+ this.cacheable(false);
110
111
  const cache = (0, import_utils.getCache)("md-loader");
111
112
  const baseCacheKey = [
112
113
  this.resourcePath,
package/dist/types.d.ts CHANGED
@@ -9,7 +9,7 @@ import type { AssetsPackage, ExampleBlockAsset } from 'dumi-assets-types';
9
9
  import type { Element } from 'hast';
10
10
  import type { defineConfig as defineUmiConfig, IApi as IUmiApi } from 'umi';
11
11
  declare type Subset<K> = {
12
- [attr in keyof K]?: K[attr] extends Array<any> ? K[attr] : K[attr] extends object ? Subset<K[attr]> : K[attr] extends object | null ? Subset<K[attr]> | null : K[attr] extends object | null | undefined ? Subset<K[attr]> | null | undefined : K[attr];
12
+ [attr in keyof K]?: K[attr] extends Array<any> ? K[attr] : K[attr] extends Function | undefined ? K[attr] : K[attr] extends object ? Subset<K[attr]> : K[attr] extends object | null ? Subset<K[attr]> | null : K[attr] extends object | null | undefined ? Subset<K[attr]> | null | undefined : K[attr];
13
13
  };
14
14
  declare type NoStringIndex<T> = {
15
15
  [K in keyof T as string extends K ? never : K]: T[K];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.1.22",
3
+ "version": "2.1.23",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",
@@ -79,9 +79,10 @@
79
79
  "@ant-design/icons-svg": "^4.2.1",
80
80
  "@makotot/ghostui": "^2.0.0",
81
81
  "@stackblitz/sdk": "^1.8.1",
82
- "@swc/core": "1.3.44",
82
+ "@swc/core": "1.3.57",
83
83
  "@types/hast": "^2.3.4",
84
84
  "@types/mdast": "^3.0.10",
85
+ "@types/nprogress": "^0.2.0",
85
86
  "@umijs/bundler-utils": "^4.0.64",
86
87
  "@umijs/core": "^4.0.64",
87
88
  "animated-scroll-to": "^2.3.0",
@@ -104,6 +105,7 @@
104
105
  "js-yaml": "^4.1.0",
105
106
  "lodash.throttle": "^4.1.1",
106
107
  "mdast-util-to-string": "^3.1.0",
108
+ "nprogress": "^0.2.0",
107
109
  "pluralize": "^8.0.0",
108
110
  "prism-react-renderer": "^1.3.5",
109
111
  "prism-themes": "^1.9.0",
@@ -165,7 +167,7 @@
165
167
  "react": ">=16.8",
166
168
  "react-dom": ">=16.8"
167
169
  },
168
- "packageManager": "pnpm@7.3.0",
170
+ "packageManager": "pnpm@8.4.0",
169
171
  "publishConfig": {
170
172
  "access": "public"
171
173
  },
@@ -25,7 +25,7 @@ var HANDLERS = {
25
25
  return this.getValidClassName(prop) || prop.type;
26
26
  } else if ('const' in prop) {
27
27
  // const value
28
- return prop.const;
28
+ return "".concat(prop.const);
29
29
  } else if ('oneOf' in prop) {
30
30
  // oneOf value
31
31
  return this.oneOf(prop);
@@ -13,14 +13,15 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
13
13
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
14
14
 
15
15
  import { Scrollspy as ScrollSpy } from '@makotot/ghostui/src/Scrollspy';
16
- import { Link, useLocation, useRouteMeta, useSiteData, useTabMeta } from 'dumi';
16
+ import { history, Link, useLocation, useRouteMeta, useSiteData, useTabMeta } from 'dumi';
17
17
  import React, { useEffect, useRef, useState } from 'react';
18
18
  import "./index.less";
19
19
 
20
20
  var Toc = function Toc() {
21
21
  var _useLocation = useLocation(),
22
22
  pathname = _useLocation.pathname,
23
- search = _useLocation.search;
23
+ search = _useLocation.search,
24
+ hash = _useLocation.hash;
24
25
 
25
26
  var meta = useRouteMeta();
26
27
  var tabMeta = useTabMeta();
@@ -80,6 +81,11 @@ var Toc = function Toc() {
80
81
  "data-depth": item.depth
81
82
  }, /*#__PURE__*/React.createElement(Link, _extends({
82
83
  to: link,
84
+ onClickCapture: function onClickCapture() {
85
+ if (decodeURIComponent(hash).slice(1) === item.id) {
86
+ history.replace(search);
87
+ }
88
+ },
83
89
  title: item.title
84
90
  }, activeIndex === i ? {
85
91
  className: 'active'