dumi 2.0.0-rc.4 → 2.0.0-rc.5

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.
@@ -1,3 +1,4 @@
1
1
  import { type FC } from 'react';
2
+ import './index.less';
2
3
  declare const DemoRenderPage: FC;
3
4
  export default DemoRenderPage;
@@ -1,5 +1,6 @@
1
1
  import { useParams, useSiteData } from 'dumi';
2
2
  import { createElement } from 'react';
3
+ import "./index.less";
3
4
 
4
5
  var DemoRenderPage = function DemoRenderPage() {
5
6
  var _useParams = useParams(),
@@ -0,0 +1,4 @@
1
+ body {
2
+ margin: 0;
3
+ padding: 0;
4
+ }
@@ -16,8 +16,7 @@ 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,
20
- pathname = _useLocation.pathname;
19
+ hash = _useLocation.hash;
21
20
 
22
21
  var _useRouteMeta = useRouteMeta(),
23
22
  tabs = _useRouteMeta.tabs;
@@ -47,13 +46,11 @@ export var DumiPage = function DumiPage(props) {
47
46
 
48
47
  useEffect(function () {
49
48
  var id = hash.replace('#', '');
50
- var elm = id && document.getElementById(id);
51
- if (elm) elm.scrollIntoView();
52
- }, [hash]); // handle pathname change
53
-
54
- useEffect(function () {
55
- document.documentElement.scrollTo(0, 0);
56
- }, [pathname]);
49
+ setTimeout(function () {
50
+ var elm = id && document.getElementById(decodeURIComponent(id));
51
+ if (elm) document.documentElement.scrollTo(0, elm.offsetTop - 80);
52
+ }, 1);
53
+ }, [hash]);
57
54
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ContentTabs, {
58
55
  tabs: tabs,
59
56
  tabKey: tabKey,
@@ -50,6 +50,16 @@ function flatRoute(route) {
50
50
  route.path = route.path === "*" ? route.path : route.absPath.slice(1);
51
51
  }
52
52
  }
53
+ function getClientPageFile(file, cwd) {
54
+ try {
55
+ return import_plugin_utils.resolve.sync(`dumi/dist/${file}`, {
56
+ basedir: cwd,
57
+ preserveSymlinks: false
58
+ });
59
+ } catch {
60
+ return require.resolve(`../${file}`);
61
+ }
62
+ }
53
63
  var routes_default = (api) => {
54
64
  var _a, _b, _c;
55
65
  const extraWatchPaths = [
@@ -112,6 +122,7 @@ var routes_default = (api) => {
112
122
  Object.entries(pages).forEach(([, route]) => {
113
123
  route.file = (0, import_plugin_utils.winPath)(import_path.default.resolve(api.config.conventionRoutes.base, route.file));
114
124
  flatRoute(route);
125
+ localizeUmiRoute(route, api.config.locales);
115
126
  routes[route.id] = route;
116
127
  });
117
128
  docDirs.map(normalizeDocDir).forEach(({ type, dir }) => {
@@ -155,7 +166,7 @@ var routes_default = (api) => {
155
166
  path: "*",
156
167
  absPath: "/*",
157
168
  parentId: docLayoutId,
158
- file: require.resolve("../client/pages/404")
169
+ file: getClientPageFile("client/pages/404", api.cwd)
159
170
  };
160
171
  }
161
172
  routes["demo-render"] = {
@@ -163,7 +174,7 @@ var routes_default = (api) => {
163
174
  path: `${import_constants.SP_ROUTE_PREFIX}demos/:id`,
164
175
  absPath: `/${import_constants.SP_ROUTE_PREFIX}demos/:id`,
165
176
  parentId: demoLayoutId,
166
- file: require.resolve("../client/pages/Demo")
177
+ file: getClientPageFile("client/pages/Demo", api.cwd)
167
178
  };
168
179
  return routes;
169
180
  });
@@ -26,6 +26,7 @@ __export(theme_exports, {
26
26
  });
27
27
  module.exports = __toCommonJS(theme_exports);
28
28
  var import_constants = require("../../constants");
29
+ var import_bundler_utils = require("@umijs/bundler-utils");
29
30
  var import_fs = __toESM(require("fs"));
30
31
  var import_path = __toESM(require("path"));
31
32
  var import_plugin_utils = require("umi/plugin-utils");
@@ -109,18 +110,28 @@ var theme_default = (api) => {
109
110
  api.onGenerateFiles(() => {
110
111
  themeMapKeys.forEach((key) => {
111
112
  Object.values(originalThemeData[key] || {}).forEach((item) => {
113
+ let contents = [];
114
+ const [, exports] = (0, import_bundler_utils.parseModuleSync)({
115
+ path: item.source,
116
+ content: import_fs.default.readFileSync(item.source, "utf-8")
117
+ });
118
+ if (exports.includes("default")) {
119
+ contents.push(`export { default } from '${item.source}';`);
120
+ }
121
+ if (exports.some((exp) => exp !== "default")) {
122
+ contents.push(`export * from '${item.source}';`);
123
+ }
112
124
  api.writeTmpFile({
113
125
  noPluginDir: true,
114
126
  path: `dumi/theme/${key}/${item.specifier}.ts`,
115
- content: `export * from '${item.source}';
116
- export { default } from '${item.source}';`
127
+ content: contents.join("\n")
117
128
  });
118
129
  });
119
130
  });
120
131
  api.writeTmpFile({
121
132
  noPluginDir: true,
122
133
  path: "dumi/theme/ContextWrapper.tsx",
123
- content: `import React, { useState, useEffect } from 'react';
134
+ content: `import React, { useState, useEffect, useRef } from 'react';
124
135
  import { useOutlet, history } from 'dumi';
125
136
  import { SiteContext } from '${(0, import_plugin_utils.winPath)(require.resolve("../../client/theme-api/context"))}';
126
137
  import { demos, components } from '../meta';
@@ -129,10 +140,19 @@ import { locales } from '../locales/config';
129
140
  export default function DumiContextWrapper() {
130
141
  const outlet = useOutlet();
131
142
  const [loading, setLoading] = useState(true);
143
+ const prev = useRef(history.location.pathname);
132
144
 
133
- // mark loading when route change, page component will set false when loaded
134
145
  useEffect(() => {
135
- return history.listen(() => setLoading(true));
146
+ return history.listen((next) => {
147
+ // mark loading when route change, page component will set false when loaded
148
+ setLoading(true);
149
+
150
+ // scroll to top when route changed
151
+ if (next.location.pathname !== prev.current) {
152
+ prev.current = next.location.pathname;
153
+ document.documentElement.scrollTo(0, 0);
154
+ }
155
+ });
136
156
  }, []);
137
157
 
138
158
  return (
@@ -44,6 +44,9 @@ var visit;
44
44
  })();
45
45
  function remarkRawAST() {
46
46
  this.Compiler = function Compiler(ast) {
47
+ visit(ast, "yaml", (_node, i, parent) => {
48
+ parent.children.splice(i, 1);
49
+ });
47
50
  return ast;
48
51
  };
49
52
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dumi",
3
- "version": "2.0.0-rc.4",
3
+ "version": "2.0.0-rc.5",
4
4
  "description": "Framework for developing UI components",
5
5
  "keywords": [],
6
6
  "license": "MIT",
@@ -1,3 +1,5 @@
1
+ var _excluded = ["children"];
2
+
1
3
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
4
 
3
5
  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,12 +12,18 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
10
12
 
11
13
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
14
 
15
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
16
+
17
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
18
+
13
19
  import throttle from 'lodash.throttle';
14
20
  import React, { useEffect, useRef, useState } from 'react';
15
21
  import "./index.less";
16
22
 
17
23
  var Table = function Table(_ref) {
18
- var children = _ref.children;
24
+ var children = _ref.children,
25
+ props = _objectWithoutProperties(_ref, _excluded);
26
+
19
27
  var container = useRef(null);
20
28
 
21
29
  var _useState = useState(false),
@@ -53,7 +61,7 @@ var Table = function Table(_ref) {
53
61
  ref: container,
54
62
  "data-left-folded": leftFolded || undefined,
55
63
  "data-right-folded": rightFolded || undefined
56
- }, /*#__PURE__*/React.createElement("table", null, children)));
64
+ }, /*#__PURE__*/React.createElement("table", props, children)));
57
65
  };
58
66
 
59
67
  export default Table;
@@ -1,7 +1,7 @@
1
1
  @import (reference) '../../styles/variables.less';
2
2
 
3
3
  .@{prefix}-table {
4
- margin: 16px 0 32px;
4
+ margin: 24px 0 32px;
5
5
  transform: translate(0, 0);
6
6
 
7
7
  &-content {
@@ -23,15 +23,15 @@
23
23
  left: 0;
24
24
  background-image: linear-gradient(
25
25
  to right,
26
- rgba(0, 0, 0, 0.1),
27
- rgba(0, 0, 0, 0)
26
+ rgb(0 0 0 / 10%),
27
+ rgb(0 0 0 / 0%)
28
28
  );
29
29
 
30
30
  [data-prefers-color='dark'] & {
31
31
  background-image: linear-gradient(
32
32
  to right,
33
- rgba(0, 0, 0, 0.5),
34
- rgba(0, 0, 0, 0)
33
+ rgb(0 0 0 / 50%),
34
+ rgb(0 0 0 / 0%)
35
35
  );
36
36
  }
37
37
  }
@@ -40,15 +40,15 @@
40
40
  right: 0;
41
41
  background-image: linear-gradient(
42
42
  to left,
43
- rgba(0, 0, 0, 0.1),
44
- rgba(0, 0, 0, 0)
43
+ rgb(0 0 0 / 10%),
44
+ rgb(0 0 0 / 0%)
45
45
  );
46
46
 
47
47
  [data-prefers-color='dark'] & {
48
48
  background-image: linear-gradient(
49
49
  to left,
50
- rgba(0, 0, 0, 0.5),
51
- rgba(0, 0, 0, 0)
50
+ rgb(0 0 0 / 50%),
51
+ rgb(0 0 0 / 0%)
52
52
  );
53
53
  }
54
54
  }
@@ -3,10 +3,11 @@
3
3
  body {
4
4
  margin: 0;
5
5
  padding: 0;
6
- background-color: @c-site-bg;
7
6
  }
8
7
 
9
8
  .@{prefix}-doc-layout {
9
+ background-color: @c-site-bg;
10
+
10
11
  @media @mobile {
11
12
  &::before {
12
13
  content: '';
@@ -41,6 +41,54 @@
41
41
  padding-inline-end: 16px;
42
42
  border-color: @c-border-light;
43
43
  }
44
+
45
+ // blockquote
46
+ blockquote {
47
+ font-style: italic;
48
+ margin-inline-start: 0;
49
+ margin-inline-end: 0;
50
+ background-color: tint(@c-site-bg, 50%);
51
+ border-left: 5px solid @c-border-light;
52
+ }
53
+
54
+ // list
55
+ ul li {
56
+ line-height: 1.8;
57
+ }
58
+
59
+ // anchor of headings
60
+ h1,
61
+ h2,
62
+ h3,
63
+ h4,
64
+ h5,
65
+ h6 {
66
+ > a[aria-hidden]:first-child {
67
+ float: left;
68
+ width: 20px;
69
+ padding-right: 4px;
70
+ margin-left: -24px;
71
+ color: @c-text;
72
+ // hide phantom blank node
73
+ font-size: 0;
74
+ text-align: right;
75
+ line-height: inherit;
76
+
77
+ &:hover {
78
+ border: 0;
79
+ }
80
+
81
+ > .icon-link::before {
82
+ content: '#';
83
+ color: @c-text-secondary;
84
+ font-size: 20px;
85
+ }
86
+ }
87
+
88
+ &:not(:hover) > a[aria-hidden]:first-child > .icon-link {
89
+ visibility: hidden;
90
+ }
91
+ }
44
92
  }
45
93
 
46
94
  .@{prefix}-content {
@@ -48,7 +48,7 @@
48
48
 
49
49
  > h3 {
50
50
  margin: 4px 0;
51
- color: #2c4262;
51
+ color: @c-text;
52
52
  font-weight: normal;
53
53
  font-size: 20px;
54
54
 
@@ -59,7 +59,7 @@
59
59
 
60
60
  > p {
61
61
  margin: 12px 0;
62
- color: #61728a;
62
+ color: @c-text-secondary;
63
63
  font-size: 16px;
64
64
  line-height: 1.475;
65
65
 
@@ -35,7 +35,7 @@
35
35
 
36
36
  > p {
37
37
  margin: 32px;
38
- color: #4e6789;
38
+ color: @c-text-secondary;
39
39
  font-size: 20px;
40
40
  line-height: 1.6;
41
41
 
@@ -15,7 +15,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
15
15
  import { ReactComponent as IconSearch } from '@ant-design/icons-svg/inline-svg/outlined/search.svg';
16
16
  import { useIntl, useSiteSearch } from 'dumi';
17
17
  import React, { useEffect, useRef, useState } from 'react';
18
- import { SearchResult } from "../SearchResult";
18
+ import SearchResult from "../SearchResult";
19
19
  import "./index.less";
20
20
  var isAppleDevice = /(mac|iphone|ipod|ipad)/i.test(typeof navigator !== 'undefined' ? (_navigator = navigator) === null || _navigator === void 0 ? void 0 : _navigator.platform : '');
21
21
 
@@ -2,8 +2,8 @@ import { type useSiteSearch } from 'dumi';
2
2
  import { type FC } from 'react';
3
3
  import './index.less';
4
4
  declare type ISearchResult = ReturnType<typeof useSiteSearch>['result'];
5
- export declare const SearchResult: FC<{
5
+ declare const SearchResult: FC<{
6
6
  data: ISearchResult;
7
7
  loading: boolean;
8
8
  }>;
9
- export {};
9
+ export default SearchResult;
@@ -106,7 +106,7 @@ var useFlatSearchData = function useFlatSearchData(data) {
106
106
  return flatData;
107
107
  };
108
108
 
109
- export var SearchResult = function SearchResult(props) {
109
+ var SearchResult = function SearchResult(props) {
110
110
  var _useFlatSearchData = useFlatSearchData(props.data),
111
111
  _useFlatSearchData2 = _slicedToArray(_useFlatSearchData, 2),
112
112
  data = _useFlatSearchData2[0],
@@ -165,4 +165,6 @@ export var SearchResult = function SearchResult(props) {
165
165
  }, /*#__PURE__*/React.createElement(IconInbox, null), /*#__PURE__*/React.createElement(FormattedMessage, {
166
166
  id: "search.not.found"
167
167
  })));
168
- };
168
+ };
169
+
170
+ export default SearchResult;
@@ -7,9 +7,9 @@
7
7
  @s-header-height-m: 52px;
8
8
 
9
9
  @c-primary: #1677ff;
10
- @c-text: #333;
11
- @c-text-secondary: #666;
12
- @c-text-note: #999;
10
+ @c-text: #30363f;
11
+ @c-text-secondary: #4f5866;
12
+ @c-text-note: #8a9099;
13
13
  @c-border: #d0d5d8;
14
14
  @c-border-light: #e4e9ec;
15
15
  @c-site-bg: #f7f9fb;