dumi 2.1.6 → 2.1.8

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.
@@ -4,7 +4,7 @@ declare class AtomAssetsParser {
4
4
  private resolveDir;
5
5
  private unresolvedFiles;
6
6
  private parser;
7
- private resolver;
7
+ private isParsing;
8
8
  private parseDeferrer;
9
9
  private watcher;
10
10
  private cbs;
@@ -22,6 +22,6 @@ declare class AtomAssetsParser {
22
22
  }>;
23
23
  watch(cb: AtomAssetsParser['cbs'][number]): void;
24
24
  unwatch(cb: AtomAssetsParser['cbs'][number]): void;
25
- destroy(): void;
25
+ destroyWorker(): void;
26
26
  }
27
27
  export default AtomAssetsParser;
@@ -33,6 +33,7 @@ var MAX_PARSE_SIZE = 1024 * 512;
33
33
  var AtomAssetsParser = class {
34
34
  constructor(opts) {
35
35
  this.unresolvedFiles = [];
36
+ this.isParsing = false;
36
37
  this.watcher = null;
37
38
  this.cbs = [];
38
39
  const absEntryFile = import_path.default.resolve(opts.resolveDir, opts.entryFile);
@@ -47,13 +48,13 @@ var AtomAssetsParser = class {
47
48
  });
48
49
  }
49
50
  async parse() {
50
- if (!this.parseDeferrer) {
51
+ if (!this.parseDeferrer || this.unresolvedFiles.length && !this.isParsing) {
52
+ this.isParsing = true;
51
53
  this.parseDeferrer = (async () => {
52
54
  await this.parser.patch(this.unresolvedFiles.splice(0));
53
55
  const resolver = new import_parser.SchemaResolver(await this.parser.parse(), {
54
56
  mode: "worker"
55
57
  });
56
- this.resolver = resolver;
57
58
  const result = {
58
59
  components: {},
59
60
  functions: {}
@@ -100,14 +101,10 @@ var AtomAssetsParser = class {
100
101
  signature
101
102
  };
102
103
  }
104
+ resolver.$$destroyWorker();
105
+ this.isParsing = false;
103
106
  return result;
104
107
  })();
105
- this.parseDeferrer.finally(() => {
106
- var _a;
107
- (_a = this.resolver) == null ? void 0 : _a.$$destroyWorker();
108
- this.resolver = void 0;
109
- this.parseDeferrer = void 0;
110
- });
111
108
  }
112
109
  return this.parseDeferrer;
113
110
  }
@@ -139,10 +136,12 @@ var AtomAssetsParser = class {
139
136
  unwatch(cb) {
140
137
  this.cbs.splice(this.cbs.indexOf(cb), 1);
141
138
  }
142
- destroy() {
143
- var _a;
144
- (_a = this.resolver) == null ? void 0 : _a.$$destroyWorker();
145
- this.parser.$$destroyWorker();
139
+ destroyWorker() {
140
+ if (this.parseDeferrer) {
141
+ this.parseDeferrer.finally(() => this.parser.$$destroyWorker());
142
+ } else {
143
+ this.parser.$$destroyWorker();
144
+ }
146
145
  }
147
146
  };
148
147
  var atom_default = AtomAssetsParser;
@@ -159,6 +159,7 @@ export interface ISidebarGroup {
159
159
  children: ISidebarItem[];
160
160
  [key: string]: any;
161
161
  }
162
+ export declare type SocialTypes = 'github' | 'weibo' | 'twitter' | 'gitlab' | 'facebook' | 'zhihu' | 'yuque' | 'linkedin';
162
163
  export interface IThemeConfig {
163
164
  name?: string;
164
165
  logo?: string | false;
@@ -173,6 +174,9 @@ export interface IThemeConfig {
173
174
  default: 'light' | 'dark' | 'auto';
174
175
  switch: boolean;
175
176
  };
177
+ socialLinks: {
178
+ [key in SocialTypes]: string;
179
+ };
176
180
  [key: string]: any;
177
181
  }
178
182
  export declare type IRoutesById = Record<string, {
@@ -225,6 +225,8 @@ export var useSidebarData = function useSidebarData() {
225
225
  // /en-US/a/b => /en-US/a
226
226
  // /en-US/a/b/ => /en-US/a (also strip trailing /)
227
227
 
228
- var parentPath = clearPath ? pathname.replace(/(\/[^/]+)(\/[^/]+\/?)$/, '$1') : pathname;
228
+ var parentPath = clearPath ? pathname.replace(clearPath, function (s) {
229
+ return s.replace(/([^/]+)(\/[^/]+\/?)$/, '$1');
230
+ }) : pathname;
229
231
  return parentPath ? sidebar[parentPath] : [];
230
232
  };
@@ -50,6 +50,7 @@ var derivative_default = (api) => {
50
50
  var _a, _b, _c, _d;
51
51
  (0, import_assert.default)(!api.config.mpa, "MPA mode is not supported in dumi!");
52
52
  (0, import_assert.default)(!api.config.vite, "Vite mode is not supported yet!");
53
+ (0, import_assert.default)(!api.config.phantomDependency, "PhantomDependency is not supported yet!");
53
54
  if (typeof api.config.mfsu === "object") {
54
55
  (0, import_assert.default)(api.config.mfsu.strategy !== "eager", "MFSU eager mode is not supported yet!");
55
56
  (0, import_assert.default)(api.config.mfsu.esbuild !== true, "MFSU esbuild bundler is not supported yet!");
@@ -135,6 +136,8 @@ var derivative_default = (api) => {
135
136
  }
136
137
  });
137
138
  api.registerPlugins([require.resolve("../../compiled/@umijs/plugins")]);
139
+ if (api.isPluginEnable("prepare"))
140
+ api.skipPlugins(["prepare"]);
138
141
  };
139
142
  // Annotate the CommonJS export names for ESM import in node:
140
143
  0 && (module.exports = {
@@ -23,6 +23,7 @@ __export(exportStatic_exports, {
23
23
  });
24
24
  module.exports = __toCommonJS(exportStatic_exports);
25
25
  var import_constants = require("../constants");
26
+ var import_plugin_utils = require("umi/plugin-utils");
26
27
  var import_assets = require("./assets");
27
28
  var exportStatic_default = (api) => {
28
29
  const prevExtraRoutePaths = [];
@@ -49,10 +50,14 @@ var exportStatic_default = (api) => {
49
50
  memo.exportStatic.extraRoutePaths = async () => {
50
51
  const examples = (0, import_assets.getExampleAssets)();
51
52
  const userExtraPaths = [];
53
+ const isSupportDisablePrerender = import_plugin_utils.semver.gte(api.appData.umi.version, "4.0.48");
52
54
  for (const prev of prevExtraRoutePaths) {
53
55
  userExtraPaths.push(...typeof prev === "function" ? await prev() : prev);
54
56
  }
55
- return userExtraPaths.concat(examples.map(({ id }) => `/${import_constants.SP_ROUTE_PREFIX}demos/${id}`));
57
+ return userExtraPaths.concat(examples.map(({ id }) => {
58
+ const demoPath = `/${import_constants.SP_ROUTE_PREFIX}demos/${id}`;
59
+ return isSupportDisablePrerender ? { path: demoPath, prerender: false } : demoPath;
60
+ }));
56
61
  };
57
62
  }
58
63
  return memo;
@@ -51,7 +51,7 @@ var parser_default = (api) => {
51
51
  (0, import_assert.default)((_a = api.userConfig.resolve) == null ? void 0 : _a.entryFile, "`resolve.entryFile` must be configured when `apiParser` enable");
52
52
  return memo;
53
53
  });
54
- api.onStart(async () => {
54
+ api.onCheckPkgJSON(async () => {
55
55
  const {
56
56
  default: AtomAssetsParser
57
57
  } = require("../assetParsers/atom");
@@ -73,11 +73,16 @@ var parser_default = (api) => {
73
73
  api.onGenerateFiles(async () => {
74
74
  if (api.env === "production") {
75
75
  writeAtomsMetaFile(await api.service.atomParser.parse());
76
- api.service.atomParser.destroy();
77
76
  } else if (prevData) {
78
77
  writeAtomsMetaFile(prevData);
79
78
  }
80
79
  });
80
+ api.onBuildComplete({
81
+ stage: Infinity,
82
+ fn() {
83
+ api.service.atomParser.destroyWorker();
84
+ }
85
+ });
81
86
  };
82
87
  // Annotate the CommonJS export names for ESM import in node:
83
88
  0 && (module.exports = {});
@@ -192,7 +192,8 @@ var routes_default = (api) => {
192
192
  path: `${import_constants.SP_ROUTE_PREFIX}demos/:id`,
193
193
  absPath: `/${import_constants.SP_ROUTE_PREFIX}demos/:id`,
194
194
  parentId: demoLayoutId,
195
- file: getClientPageFile("client/pages/Demo", api.cwd)
195
+ file: getClientPageFile("client/pages/Demo", api.cwd),
196
+ prerender: false
196
197
  };
197
198
  return routes;
198
199
  });
@@ -31,7 +31,7 @@ var visit;
31
31
  ({ visit } = await import("unist-util-visit"));
32
32
  })();
33
33
  function isRelativeUrl(url) {
34
- return !/^((blob:)?\w+:)?\/\//.test(url) && !import_path.default.isAbsolute(url);
34
+ return !url.startsWith("data:image") && !/^((blob:)?\w+:)?\/\//.test(url) && !import_path.default.isAbsolute(url);
35
35
  }
36
36
  function rehypeImg() {
37
37
  return (tree) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.1.6",
3
+ "version": "2.1.8",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",
@@ -80,8 +80,8 @@
80
80
  "@swc/core": "^1.2.224",
81
81
  "@types/hast": "^2.3.4",
82
82
  "@types/mdast": "^3.0.10",
83
- "@umijs/bundler-utils": "^4.0.33",
84
- "@umijs/core": "^4.0.33",
83
+ "@umijs/bundler-utils": "^4.0.48",
84
+ "@umijs/core": "^4.0.48",
85
85
  "animated-scroll-to": "^2.3.0",
86
86
  "classnames": "2.3.2",
87
87
  "codesandbox": "^2.2.3",
@@ -122,7 +122,7 @@
122
122
  "remark-rehype": "^10.1.0",
123
123
  "sass": "^1.55.0",
124
124
  "sitemap": "^7.1.1",
125
- "umi": "^4.0.33",
125
+ "umi": "^4.0.48",
126
126
  "unified": "^10.1.2",
127
127
  "unist-util-visit": "^4.1.0",
128
128
  "unist-util-visit-parents": "^5.1.1",
@@ -141,7 +141,7 @@
141
141
  "@types/pluralize": "^0.0.29",
142
142
  "@types/react": "^18.0.16",
143
143
  "@types/react-copy-to-clipboard": "^5.0.4",
144
- "@umijs/lint": "^4.0.33",
144
+ "@umijs/lint": "^4.0.48",
145
145
  "@umijs/plugins": "4.0.32",
146
146
  "dumi-theme-mobile": "workspace:*",
147
147
  "eslint": "^8.20.0",
@@ -3,6 +3,14 @@
3
3
  "header.color.mode.light": "Light Mode",
4
4
  "header.color.mode.dark": "Dark Mode",
5
5
  "header.color.mode.auto": "Follow System",
6
+ "header.social.github": "GitHub",
7
+ "header.social.weibo": "Weibo",
8
+ "header.social.twitter": "Twitter",
9
+ "header.social.gitlab": "GitLab",
10
+ "header.social.facebook": "Facebook",
11
+ "header.social.zhihu": "Zhihu",
12
+ "header.social.yuque": "Yuque",
13
+ "header.social.linkedin": "Linkedin",
6
14
  "previewer.actions.code.expand": "Show Code",
7
15
  "previewer.actions.code.shrink": "Hide Code",
8
16
  "previewer.actions.codesandbox": "Open in CodeSandbox",
@@ -3,6 +3,14 @@
3
3
  "header.color.mode.light": "亮色模式",
4
4
  "header.color.mode.dark": "暗色模式",
5
5
  "header.color.mode.auto": "跟随系统",
6
+ "header.social.github": "GitHub",
7
+ "header.social.weibo": "微博",
8
+ "header.social.twitter": "Twitter",
9
+ "header.social.gitlab": "GitLab",
10
+ "header.social.facebook": "Facebook",
11
+ "header.social.zhihu": "知乎",
12
+ "header.social.yuque": "语雀",
13
+ "header.social.linkedin": "Linkedin",
6
14
  "previewer.actions.code.expand": "展开代码",
7
15
  "previewer.actions.code.shrink": "收起代码",
8
16
  "previewer.actions.codesandbox": "在 CodeSandbox 中打开",
@@ -20,7 +20,8 @@ import Logo from "dumi/theme/slots/Logo";
20
20
  import Navbar from "dumi/theme/slots/Navbar";
21
21
  import RtlSwitch from "dumi/theme/slots/RtlSwitch";
22
22
  import SearchBar from "dumi/theme/slots/SearchBar";
23
- import React, { useState } from 'react';
23
+ import React, { useMemo, useState } from 'react';
24
+ import SocialIcon from "../SocialIcon";
24
25
  import "./index.less";
25
26
 
26
27
  var Header = function Header() {
@@ -35,6 +36,14 @@ var Header = function Header() {
35
36
  var _useSiteData = useSiteData(),
36
37
  themeConfig = _useSiteData.themeConfig;
37
38
 
39
+ var socialIcons = useMemo(function () {
40
+ return themeConfig.socialLinks ? Object.keys(themeConfig.socialLinks).slice(0, 5).map(function (key) {
41
+ return {
42
+ icon: key,
43
+ link: themeConfig.socialLinks[key]
44
+ };
45
+ }) : [];
46
+ }, [themeConfig.socialLinks]);
38
47
  return /*#__PURE__*/React.createElement("div", {
39
48
  className: "dumi-default-header",
40
49
  "data-static": Boolean(frontmatter.hero) || undefined,
@@ -50,7 +59,13 @@ var Header = function Header() {
50
59
  className: "dumi-default-header-right"
51
60
  }, /*#__PURE__*/React.createElement(Navbar, null), /*#__PURE__*/React.createElement("div", {
52
61
  className: "dumi-default-header-right-aside"
53
- }, /*#__PURE__*/React.createElement(SearchBar, null), /*#__PURE__*/React.createElement(LangSwitch, null), /*#__PURE__*/React.createElement(RtlSwitch, null), themeConfig.prefersColor.switch && /*#__PURE__*/React.createElement(ColorSwitch, null), /*#__PURE__*/React.createElement(HeaderExtra, null))), /*#__PURE__*/React.createElement("button", {
62
+ }, /*#__PURE__*/React.createElement(SearchBar, null), /*#__PURE__*/React.createElement(LangSwitch, null), /*#__PURE__*/React.createElement(RtlSwitch, null), themeConfig.prefersColor.switch && /*#__PURE__*/React.createElement(ColorSwitch, null), socialIcons.map(function (item) {
63
+ return /*#__PURE__*/React.createElement(SocialIcon, {
64
+ icon: item.icon,
65
+ link: item.link,
66
+ key: item.link
67
+ });
68
+ }), /*#__PURE__*/React.createElement(HeaderExtra, null))), /*#__PURE__*/React.createElement("button", {
54
69
  type: "button",
55
70
  className: "dumi-default-header-menu-btn",
56
71
  onClick: function onClick(ev) {
@@ -19,7 +19,8 @@ function getTargetLocalePath(_ref) {
19
19
  var pathname = _ref.pathname,
20
20
  current = _ref.current,
21
21
  target = _ref.target;
22
- var clearPath = 'base' in current ? pathname.replace(current.base.replace(/\/$/, ''), '') : pathname.replace(new RegExp("".concat(current.suffix, "$")), '');
22
+ var clearPath = 'base' in current ? // handle '/en-US/a' => '/a' or '/en-US' => '' => '/'
23
+ pathname.replace(current.base.replace(/\/$/, ''), '') || '/' : pathname.replace(new RegExp("".concat(current.suffix, "$")), '');
23
24
  return 'base' in target ? "".concat( // for `/` base, strip duplicated leading slash
24
25
  target.base.replace(/\/$/, '')).concat(clearPath) // for `/` clearPath, strip duplicated ending slash
25
26
  .replace(/([^/])\/$/, '$1') : "".concat(clearPath).concat(target.suffix);
@@ -0,0 +1,13 @@
1
+ import { SocialTypes } from "../../../theme-api/types";
2
+ import { FunctionComponent, type FC } from 'react';
3
+ import './index.less';
4
+ export declare type SocialIconProps = {
5
+ icon: SocialTypes;
6
+ link: string;
7
+ };
8
+ export declare type PresetSocialIcon = {
9
+ Icon: FunctionComponent;
10
+ titleIntlId: string;
11
+ };
12
+ declare const SocialIcon: FC<SocialIconProps>;
13
+ export default SocialIcon;
@@ -0,0 +1,45 @@
1
+ import { ReactComponent as IconFacebook } from '@ant-design/icons-svg/inline-svg/outlined/facebook.svg';
2
+ import { ReactComponent as IconGitHub } from '@ant-design/icons-svg/inline-svg/outlined/github.svg';
3
+ import { ReactComponent as IconGitlab } from '@ant-design/icons-svg/inline-svg/outlined/gitlab.svg';
4
+ import { ReactComponent as IconLinkedin } from '@ant-design/icons-svg/inline-svg/outlined/linkedin.svg';
5
+ import { ReactComponent as IconTwitter } from '@ant-design/icons-svg/inline-svg/outlined/twitter.svg';
6
+ import { ReactComponent as IconWeiBo } from '@ant-design/icons-svg/inline-svg/outlined/weibo.svg';
7
+ import { ReactComponent as IconYuque } from '@ant-design/icons-svg/inline-svg/outlined/yuque.svg';
8
+ import { ReactComponent as IconZhihu } from '@ant-design/icons-svg/inline-svg/outlined/zhihu.svg';
9
+ import React, { useMemo } from 'react';
10
+ import { useIntl } from 'react-intl';
11
+ import "./index.less";
12
+ var presetIconMap = {
13
+ github: IconGitHub,
14
+ weibo: IconWeiBo,
15
+ twitter: IconTwitter,
16
+ gitlab: IconGitlab,
17
+ facebook: IconFacebook,
18
+ zhihu: IconZhihu,
19
+ yuque: IconYuque,
20
+ linkedin: IconLinkedin
21
+ };
22
+
23
+ var SocialIcon = function SocialIcon(props) {
24
+ var icon = props.icon,
25
+ link = props.link;
26
+ var intl = useIntl();
27
+ var preset = useMemo(function () {
28
+ return {
29
+ Icon: presetIconMap[icon],
30
+ link: link
31
+ };
32
+ }, [icon, link]);
33
+ return /*#__PURE__*/React.createElement("a", {
34
+ className: "dumi-default-icon",
35
+ "data-dumi-tooltip": intl.formatMessage({
36
+ id: "header.social.".concat(icon)
37
+ }),
38
+ "data-dumi-tooltip-bottom": true,
39
+ target: "_blank",
40
+ href: preset.link,
41
+ rel: "noreferrer"
42
+ }, /*#__PURE__*/React.createElement(preset.Icon, null));
43
+ };
44
+
45
+ export default SocialIcon;
@@ -0,0 +1,38 @@
1
+ @import (reference) '../../styles/variables.less';
2
+
3
+ .@{prefix}-icon {
4
+ font-size: 0;
5
+ line-height: 0;
6
+
7
+ [class*='-switch'] + & {
8
+ margin-inline-start: 15px;
9
+ margin-inline-end: -15px;
10
+ padding-inline: 15px;
11
+ border-inline-start: 1px solid @c-border;
12
+
13
+ @{dark-selector} & {
14
+ border-inline-start-color: @c-border-dark;
15
+ }
16
+ }
17
+
18
+ & + & {
19
+ margin-inline-start: 18px;
20
+ }
21
+
22
+ > svg {
23
+ height: 16px;
24
+ fill: @c-text-secondary;
25
+
26
+ @{dark-selector} & {
27
+ fill: @c-text-secondary-dark;
28
+ }
29
+ }
30
+
31
+ &:hover svg {
32
+ fill: @c-primary;
33
+
34
+ @{dark-selector} & {
35
+ fill: @c-primary-dark;
36
+ }
37
+ }
38
+ }
@@ -22,7 +22,7 @@
22
22
  // @dark-selector be injected by less-loader in feature/theme/index.ts
23
23
  @dark-solid-amount: 15%;
24
24
  @dark-light-amount: 22%;
25
- @dark-border-amount: 73%;
25
+ @dark-border-amount: 71%;
26
26
  @c-primary-dark: darken(@c-primary, @dark-solid-amount);
27
27
  @c-warning-dark: darken(@c-warning, @dark-solid-amount);
28
28
  @c-success-dark: darken(@c-success, @dark-solid-amount);