dumi 2.0.13 → 2.0.14

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.
@@ -25,6 +25,7 @@ __export(atom_exports, {
25
25
  default: () => atom_default
26
26
  });
27
27
  module.exports = __toCommonJS(atom_exports);
28
+ var import_utils = require("../utils");
28
29
  var import_parser = require("dumi-afx-deps/compiled/parser");
29
30
  var import_path = __toESM(require("path"));
30
31
  var import_plugin_utils = require("umi/plugin-utils");
@@ -34,12 +35,13 @@ var AtomAssetsParser = class {
34
35
  this.unresolvedFiles = [];
35
36
  this.watcher = null;
36
37
  this.cbs = [];
38
+ const absEntryFile = import_path.default.resolve(opts.resolveDir, opts.entryFile);
37
39
  this.resolveDir = opts.resolveDir;
38
40
  this.resolveFilter = opts.resolveFilter || (() => true);
39
- this.entryDir = import_path.default.relative(opts.resolveDir, import_path.default.dirname(opts.entryFile));
41
+ this.entryDir = import_path.default.relative(opts.resolveDir, import_path.default.dirname(absEntryFile));
40
42
  this.parser = new import_parser.SchemaParser({
41
- entryPath: opts.entryFile,
42
- basePath: opts.resolveDir,
43
+ entryPath: absEntryFile,
44
+ basePath: (0, import_utils.getProjectRoot)(opts.resolveDir),
43
45
  unPkgHost: opts.unpkgHost ?? "https://unpkg.com"
44
46
  });
45
47
  }
@@ -3,6 +3,4 @@
3
3
  */
4
4
  export declare const useNavData: () => (import("./types").INavItem & {
5
5
  children?: import("./types").INavItem[] | undefined;
6
- })[] | Record<string, (import("./types").INavItem & {
7
- children?: import("./types").INavItem[] | undefined;
8
- })[]>;
6
+ })[];
@@ -13,10 +13,10 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
13
13
  import { useFullSidebarData, useLocale, useSiteData } from 'dumi';
14
14
  import { useState } from 'react';
15
15
  import { pickRouteSortMeta, useLocaleDocRoutes, useRouteDataComparer } from "./utils";
16
+
16
17
  /**
17
18
  * hook for get nav data
18
19
  */
19
-
20
20
  export var useNavData = function useNavData() {
21
21
  var locale = useLocale();
22
22
  var routes = useLocaleDocRoutes();
@@ -27,7 +27,6 @@ __export(derivative_exports, {
27
27
  });
28
28
  module.exports = __toCommonJS(derivative_exports);
29
29
  var import_constants = require("../constants");
30
- var import_bundler_utils = require("@umijs/bundler-utils");
31
30
  var import_assert = __toESM(require("assert"));
32
31
  var import_fs = __toESM(require("fs"));
33
32
  var import_path = __toESM(require("path"));
@@ -45,30 +44,7 @@ function safeExcludeInMFSU(api, excludes) {
45
44
  });
46
45
  }
47
46
  }
48
- function getFilesByGlob(globExp, dir) {
49
- return import_plugin_utils.glob.sync(globExp, { cwd: dir }).map((file) => (0, import_plugin_utils.winPath)(import_path.default.join(dir, file)));
50
- }
51
47
  var derivative_default = (api) => {
52
- const dumiAbsDir = import_path.default.join(api.cwd, import_constants.LOCAL_DUMI_DIR);
53
- const strategies = {
54
- async appJS() {
55
- const [appJS] = getFilesByGlob("app.{js,jsx,ts,tsx}", dumiAbsDir);
56
- if (appJS) {
57
- const [, exports] = await (0, import_bundler_utils.parseModule)({
58
- path: appJS,
59
- content: import_fs.default.readFileSync(appJS, "utf-8")
60
- });
61
- return {
62
- path: appJS,
63
- exports
64
- };
65
- }
66
- return null;
67
- },
68
- globalCSS: getFilesByGlob.bind(null, "global.{css,less,scss,sass}", dumiAbsDir),
69
- globalJS: getFilesByGlob.bind(null, "global.{js,jsx,ts,tsx}", dumiAbsDir),
70
- overridesCSS: getFilesByGlob.bind(null, "overrides.{css,less,scss,sass}", dumiAbsDir)
71
- };
72
48
  api.describe({ key: "dumi:derivative" });
73
49
  api.onCheck(() => {
74
50
  var _a, _b;
@@ -113,21 +89,15 @@ var derivative_default = (api) => {
113
89
  memo.exportStatic || (memo.exportStatic = {});
114
90
  return memo;
115
91
  });
116
- api.modifyAppData(async (memo) => {
117
- for (const [key, strategy] of Object.entries(strategies)) {
118
- memo[key] = await strategy();
92
+ api.modifyConfig((memo) => {
93
+ var _a;
94
+ if ((_a = api.userConfig.alias) == null ? void 0 : _a["@"]) {
95
+ memo["@"] = api.userConfig.alias["@"];
96
+ } else {
97
+ memo["@"] = (0, import_plugin_utils.winPath)([import_path.default.join(api.cwd, "src"), api.cwd].find(import_fs.default.existsSync));
119
98
  }
120
99
  return memo;
121
100
  });
122
- api.register({
123
- key: "onGenerateFiles",
124
- stage: -Infinity,
125
- async fn() {
126
- for (const [key, strategy] of Object.entries(strategies)) {
127
- api.appData[key] = await strategy();
128
- }
129
- }
130
- });
131
101
  api.register({
132
102
  key: "onGenerateFiles",
133
103
  stage: Infinity,
@@ -3,7 +3,7 @@ export declare class DumiService extends Service {
3
3
  constructor();
4
4
  getPaths(): Promise<{
5
5
  cwd: string;
6
- absSrcPath: any;
6
+ absSrcPath: string;
7
7
  absPagesPath: string;
8
8
  absApiRoutesPath: string;
9
9
  absTmpPath: string;
@@ -38,13 +38,13 @@ var DumiService = class extends import_umi.Service {
38
38
  });
39
39
  }
40
40
  async getPaths() {
41
- var _a;
42
- const cwd = this.cwd;
43
- const absSrcPath = ((_a = this.userConfig.alias) == null ? void 0 : _a["@"]) ?? cwd;
44
- const absPagesPath = winJoin(cwd, `.${import_constants.FRAMEWORK_NAME}`, "pages");
45
- const absApiRoutesPath = winJoin(absSrcPath, "api");
41
+ const { cwd } = this;
46
42
  const tmp = this.env === import_core.Env.development ? `tmp` : `tmp-${this.env}`;
47
- const absTmpPath = winJoin(cwd, `.${import_constants.FRAMEWORK_NAME}`, tmp);
43
+ const absFWPath = winJoin(cwd, `.${import_constants.FRAMEWORK_NAME}`);
44
+ const absSrcPath = absFWPath;
45
+ const absPagesPath = winJoin(absSrcPath, "pages");
46
+ const absApiRoutesPath = winJoin(absSrcPath, "api");
47
+ const absTmpPath = winJoin(absSrcPath, tmp);
48
48
  const absNodeModulesPath = winJoin(cwd, "node_modules");
49
49
  const absOutputPath = winJoin(cwd, "dist");
50
50
  return {
package/dist/utils.d.ts CHANGED
@@ -30,4 +30,8 @@ export declare function getCache(ns: string): typeof caches['0'];
30
30
  * try to get father config
31
31
  */
32
32
  export declare function tryFatherBuildConfigs(cwd: string): Promise<any[]>;
33
+ /**
34
+ * get root dir for monorepo project
35
+ */
36
+ export declare function getProjectRoot(cwd: string): string;
33
37
  export {};
package/dist/utils.js CHANGED
@@ -25,12 +25,14 @@ __export(utils_exports, {
25
25
  getCache: () => getCache,
26
26
  getFileContentByRegExp: () => getFileContentByRegExp,
27
27
  getFileRangeLines: () => getFileRangeLines,
28
+ getProjectRoot: () => getProjectRoot,
28
29
  getRoutePathFromFsPath: () => getRoutePathFromFsPath,
29
30
  parseCodeFrontmatter: () => parseCodeFrontmatter,
30
31
  tryFatherBuildConfigs: () => tryFatherBuildConfigs
31
32
  });
32
33
  module.exports = __toCommonJS(utils_exports);
33
34
  var import_file_system_cache = __toESM(require("file-system-cache"));
35
+ var import_fs = __toESM(require("fs"));
34
36
  var import_js_yaml = __toESM(require("js-yaml"));
35
37
  var import_path = __toESM(require("path"));
36
38
  var import_plugin_utils = require("umi/plugin-utils");
@@ -102,11 +104,25 @@ async function tryFatherBuildConfigs(cwd) {
102
104
  process.env.APP_ROOT = APP_ROOT;
103
105
  return configs;
104
106
  }
107
+ function getProjectRoot(cwd) {
108
+ const splittedCwd = (0, import_plugin_utils.winPath)(cwd).split("/");
109
+ for (let level = -1; level >= -3; level -= 1) {
110
+ const rootCwd = splittedCwd.slice(0, level).join("/");
111
+ if (!rootCwd)
112
+ break;
113
+ const pkgPath = import_path.default.join(rootCwd, "package.json");
114
+ if (import_fs.default.existsSync(pkgPath) && (["pnpm-workspace.yaml", "lerna.json"].some((f) => import_fs.default.existsSync(import_path.default.join(rootCwd, f))) || require(pkgPath).workspace)) {
115
+ return (0, import_plugin_utils.winPath)(rootCwd);
116
+ }
117
+ }
118
+ return (0, import_plugin_utils.winPath)(cwd);
119
+ }
105
120
  // Annotate the CommonJS export names for ESM import in node:
106
121
  0 && (module.exports = {
107
122
  getCache,
108
123
  getFileContentByRegExp,
109
124
  getFileRangeLines,
125
+ getProjectRoot,
110
126
  getRoutePathFromFsPath,
111
127
  parseCodeFrontmatter,
112
128
  tryFatherBuildConfigs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.0.13",
3
+ "version": "2.0.14",
4
4
  "description": "📖 Documentation Generator of React Component",
5
5
  "keywords": [
6
6
  "generator",
@@ -37,6 +37,7 @@
37
37
  "scripts": {
38
38
  "build": "father build",
39
39
  "build:deps": "node scripts/pre-bundle-worker.js && father prebundle",
40
+ "build:suites": "pnpm run --filter=\"./suites/**\" build",
40
41
  "custom-install": "pnpm i",
41
42
  "dev": "father dev",
42
43
  "docs:build": "node ./bin/dumi.js build",
@@ -46,7 +47,7 @@
46
47
  "lint": "npm run lint:es && npm run lint:css",
47
48
  "lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
48
49
  "lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
49
- "prepare": "husky install && npm run build && node ./bin/dumi.js setup && npm run docs:sync",
50
+ "prepare": "husky install && npm run build && npm run build:suites && node ./bin/dumi.js setup && npm run docs:sync",
50
51
  "prepublishOnly": "npm run build",
51
52
  "test": "vitest"
52
53
  },
@@ -82,6 +83,7 @@
82
83
  "@umijs/bundler-utils": "^4.0.33",
83
84
  "@umijs/core": "^4.0.33",
84
85
  "animated-scroll-to": "^2.3.0",
86
+ "classnames": "2.3.2",
85
87
  "codesandbox": "^2.2.3",
86
88
  "deepmerge": "^4.2.2",
87
89
  "dumi-afx-deps": "^1.0.0-alpha.6",
@@ -141,6 +143,7 @@
141
143
  "@types/react-copy-to-clipboard": "^5.0.4",
142
144
  "@umijs/lint": "^4.0.33",
143
145
  "@umijs/plugins": "4.0.32",
146
+ "dumi-theme-mobile": "workspace:*",
144
147
  "eslint": "^8.20.0",
145
148
  "father": "^4.1.0",
146
149
  "highlight-words-core": "^1.2.2",
@@ -1,5 +1,6 @@
1
1
  function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
2
 
3
+ import classnames from 'classnames';
3
4
  import { useLocation } from 'dumi';
4
5
  import PreviewerActions from "dumi/theme/slots/PreviewerActions";
5
6
  import React from 'react';
@@ -12,7 +13,8 @@ var Previewer = function Previewer(props) {
12
13
  var link = "#".concat(props.asset.id);
13
14
  return /*#__PURE__*/React.createElement("div", {
14
15
  id: props.asset.id,
15
- className: "dumi-default-previewer",
16
+ className: classnames('dumi-default-previewer', props.className),
17
+ style: props.style,
16
18
  "data-debug": props.debug,
17
19
  "data-active": hash === link || undefined
18
20
  }, /*#__PURE__*/React.createElement("div", {
@@ -108,9 +108,11 @@
108
108
  }
109
109
 
110
110
  > strong {
111
+ float: inline-start;
111
112
  padding-inline-end: 8px;
112
113
  color: @c-warning;
113
114
  font-size: 12px;
115
+ line-height: 15px;
114
116
  }
115
117
  }
116
118
  }
@@ -0,0 +1,3 @@
1
+ import { type FC } from 'react';
2
+ declare const NavbarExtra: FC;
3
+ export default NavbarExtra;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+
3
+ var NavbarExtra = function NavbarExtra() {
4
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
5
+ };
6
+
7
+ export default NavbarExtra;
@@ -10,6 +10,7 @@ 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 HeaderExtra from "../HeadeExtra";
13
14
  import { ReactComponent as IconClose } from '@ant-design/icons-svg/inline-svg/outlined/close.svg';
14
15
  import { ReactComponent as IconMenu } from '@ant-design/icons-svg/inline-svg/outlined/menu.svg';
15
16
  import { useRouteMeta } from 'dumi';
@@ -45,7 +46,7 @@ var Header = function Header() {
45
46
  className: "dumi-default-header-right"
46
47
  }, /*#__PURE__*/React.createElement(Navbar, null), /*#__PURE__*/React.createElement("div", {
47
48
  className: "dumi-default-header-right-aside"
48
- }, /*#__PURE__*/React.createElement(SearchBar, null), /*#__PURE__*/React.createElement(LangSwitch, null), /*#__PURE__*/React.createElement(RtlSwitch, null))), /*#__PURE__*/React.createElement("button", {
49
+ }, /*#__PURE__*/React.createElement(SearchBar, null), /*#__PURE__*/React.createElement(LangSwitch, null), /*#__PURE__*/React.createElement(RtlSwitch, null), /*#__PURE__*/React.createElement(HeaderExtra, null))), /*#__PURE__*/React.createElement("button", {
49
50
  type: "button",
50
51
  className: "dumi-default-header-menu-btn",
51
52
  onClick: function onClick(ev) {
@@ -1,6 +1,7 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
2
 
3
3
  import { Link, useLocation, useNavData } from 'dumi';
4
+ import NavbarExtra from "dumi/theme/slots/NavbarExtra";
4
5
  import React from 'react';
5
6
  import "./index.less";
6
7
 
@@ -24,7 +25,7 @@ var Navbar = function Navbar() {
24
25
  }, pathname.startsWith(item.activePath || item.link) ? {
25
26
  className: 'active'
26
27
  } : {}), item.title));
27
- }));
28
+ }), /*#__PURE__*/React.createElement(NavbarExtra, null));
28
29
  };
29
30
 
30
31
  export default Navbar;
@@ -0,0 +1,3 @@
1
+ import { type FC } from 'react';
2
+ declare const NavbarExtra: FC;
3
+ export default NavbarExtra;
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+
3
+ var NavbarExtra = function NavbarExtra() {
4
+ return /*#__PURE__*/React.createElement(React.Fragment, null);
5
+ };
6
+
7
+ export default NavbarExtra;
@@ -6,6 +6,7 @@ export interface IPreviewerActionsProps extends IPreviewerProps {
6
6
  * disabled actions
7
7
  */
8
8
  disabledActions?: ('CSB' | 'CODEPEN' | 'STACKBLITZ' | 'EXTERNAL')[];
9
+ forceShowCode?: boolean;
9
10
  }
10
11
  declare const PreviewerActions: FC<IPreviewerActionsProps>;
11
12
  export default PreviewerActions;
@@ -62,7 +62,7 @@ var PreviewerActions = function PreviewerActions(props) {
62
62
  activeKey = _useState2[0],
63
63
  setActiveKey = _useState2[1];
64
64
 
65
- var _useState3 = useState(false),
65
+ var _useState3 = useState(!(props !== null && props !== void 0 && props.forceShowCode)),
66
66
  _useState4 = _slicedToArray(_useState3, 2),
67
67
  showCode = _useState4[0],
68
68
  setShowCode = _useState4[1];
@@ -97,7 +97,7 @@ var PreviewerActions = function PreviewerActions(props) {
97
97
  "data-dumi-tooltip": intl.formatMessage({
98
98
  id: 'previewer.actions.separate'
99
99
  })
100
- }, /*#__PURE__*/React.createElement(IconExternalLink, null)), /*#__PURE__*/React.createElement(PreviewerActionsExtra, props), /*#__PURE__*/React.createElement("button", {
100
+ }, /*#__PURE__*/React.createElement(IconExternalLink, null)), /*#__PURE__*/React.createElement(PreviewerActionsExtra, props), (props === null || props === void 0 ? void 0 : props.forceShowCode) && /*#__PURE__*/React.createElement("button", {
101
101
  className: "dumi-default-previewer-action-btn",
102
102
  type: "button",
103
103
  onClick: function onClick() {
@@ -19,3 +19,4 @@
19
19
 
20
20
  @mobile: ~'only screen and (max-width: 767px)';
21
21
  @tablet: ~'only screen and (min-width: 768px) and (max-width: 1024px)';
22
+ @desktop: ~'only screen and (min-width: 1025px)';