@umijs/plugin-docs 4.0.0-rc.14 → 4.0.0-rc.17

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.
@@ -17,7 +17,7 @@ export default () => {
17
17
  }
18
18
 
19
19
  function handleClick() {
20
- if (!currentLanguage) return;
20
+ if (!currentLanguage || languages.length === 1) return;
21
21
  if (languages.length === 2) {
22
22
  switchLanguage(
23
23
  languages[0].locale === currentLanguage.locale
@@ -29,6 +29,8 @@ export default () => {
29
29
  setExpanded((e) => !e);
30
30
  }
31
31
 
32
+ if (!currentLanguage || languages.length === 1) return null;
33
+
32
34
  return (
33
35
  <div>
34
36
  <div
@@ -20,7 +20,8 @@ export default (props: any) => {
20
20
 
21
21
  function updateBlur() {
22
22
  if (!offset || !blur) return;
23
- blur.backgroundPosition = `0px ` + `${-window.scrollY + 100}px`;
23
+ blur.backgroundPosition =
24
+ `0px ` + `calc(var(--anchor-offset) + ${-window.scrollY + 64}px)`;
24
25
  }
25
26
 
26
27
  document.addEventListener('scroll', updateBlur, false), updateBlur();
@@ -42,6 +43,7 @@ export default (props: any) => {
42
43
  components: props.components,
43
44
  themeConfig: props.themeConfig,
44
45
  location: props.location,
46
+ history: props.history,
45
47
  }}
46
48
  >
47
49
  <div
@@ -102,6 +102,7 @@ export default () => {
102
102
  <components.Link
103
103
  to={(isFromPath ? currentLanguage?.locale : '') + r.href}
104
104
  key={i}
105
+ onClick={() => (document.activeElement as HTMLElement)?.blur()}
105
106
  className="group outline-none search-result"
106
107
  onFocus={() => setIsFocused(true)}
107
108
  onBlur={() => setIsFocused(false)}
@@ -6,6 +6,7 @@ function Announcement() {
6
6
  const { themeConfig } = useThemeContext()!;
7
7
 
8
8
  if (!themeConfig.announcement) {
9
+ document.documentElement.style.setProperty('--anchor-offset', '0px');
9
10
  return null;
10
11
  }
11
12
 
@@ -37,6 +37,9 @@ interface IContext {
37
37
  hash: string;
38
38
  key: string;
39
39
  };
40
+ history: {
41
+ push(to: string, state?: any): void;
42
+ };
40
43
  }
41
44
 
42
45
  export const ThemeContext = React.createContext<IContext | null>(null);
@@ -12,9 +12,9 @@
12
12
  .g-glossy-firefox-cover {
13
13
  display: block;
14
14
  position: fixed;
15
- top: var(--anchor-offset);
15
+ top: 0;
16
16
  width: 100%;
17
- height: 72px;
17
+ height: calc(var(--anchor-offset) + 72px);
18
18
  z-index: 22;
19
19
  background-color: white;
20
20
  }
@@ -23,8 +23,8 @@
23
23
  display: block;
24
24
  position: fixed;
25
25
  width: 100%;
26
- top: var(--anchor-offset);
27
- height: 72px;
26
+ top: 0;
27
+ height: calc(var(--anchor-offset) + 72px);
28
28
  z-index: 24;
29
29
  background: -moz-element(#article-body) no-repeat top;
30
30
  filter: blur(10px);
@@ -1,5 +1,5 @@
1
1
  /*
2
- ! tailwindcss v3.0.23 | MIT License | https://tailwindcss.com
2
+ ! tailwindcss v3.0.24 | MIT License | https://tailwindcss.com
3
3
  */
4
4
 
5
5
  /*
@@ -1,5 +1,4 @@
1
1
  // @ts-ignore
2
- import { history } from 'umi';
3
2
  import { useThemeContext } from './context';
4
3
 
5
4
  interface useLanguageResult {
@@ -11,7 +10,7 @@ interface useLanguageResult {
11
10
  }
12
11
 
13
12
  function useLanguage(): useLanguageResult {
14
- const { themeConfig, location } = useThemeContext()!;
13
+ const { themeConfig, location, history } = useThemeContext()!;
15
14
 
16
15
  const languages = themeConfig.i18n;
17
16
  let currentLanguage: { locale: string; text: string } | undefined = undefined;
@@ -57,7 +56,13 @@ function useLanguage(): useLanguageResult {
57
56
  }
58
57
 
59
58
  function render(key: string) {
60
- if (!currentLanguage || !themeConfig.locales) return key;
59
+ if (!themeConfig.locales || Object.keys(themeConfig.locales).length === 0)
60
+ return key;
61
+ if (!currentLanguage) {
62
+ return (
63
+ themeConfig.locales[Object.keys(themeConfig.locales)[0]].key || key
64
+ );
65
+ }
61
66
  if (!themeConfig.locales[currentLanguage.locale]) return key;
62
67
  return themeConfig.locales[currentLanguage.locale][key] || key;
63
68
  }
@@ -1,5 +1,6 @@
1
1
  export declare function compile(opts: {
2
2
  content: string;
3
+ fileName: string;
3
4
  }): Promise<{
4
5
  result: string;
5
6
  }>;
package/dist/compiler.js CHANGED
@@ -1,19 +1,11 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
14
5
  Object.defineProperty(exports, "__esModule", { value: true });
15
6
  exports.compile = void 0;
16
7
  const rehype_pretty_code_1 = __importDefault(require("rehype-pretty-code"));
8
+ const plugin_utils_1 = require("umi/plugin-utils");
17
9
  // @ts-ignore
18
10
  const mdx_1 = require("../compiled/@mdx-js/mdx");
19
11
  // @ts-ignore
@@ -41,14 +33,14 @@ const rehypePrettyCodeOptions = {
41
33
  node.properties.className = ['word'];
42
34
  },
43
35
  };
44
- function compile(opts) {
45
- return __awaiter(this, void 0, void 0, function* () {
46
- const compiler = (0, mdx_1.createProcessor)({
47
- jsx: true,
48
- remarkPlugins: [remark_gfm_1.default],
49
- rehypePlugins: [rehype_slug_1.default, [rehype_pretty_code_1.default, rehypePrettyCodeOptions]],
50
- });
51
- let result = String(yield compiler.process(opts.content));
36
+ async function compile(opts) {
37
+ const compiler = (0, mdx_1.createProcessor)({
38
+ jsx: true,
39
+ remarkPlugins: [remark_gfm_1.default],
40
+ rehypePlugins: [rehype_slug_1.default, [rehype_pretty_code_1.default, rehypePrettyCodeOptions]],
41
+ });
42
+ try {
43
+ let result = String(await compiler.process(opts.content));
52
44
  result = result.replace('function MDXContent(props = {}) {', `
53
45
  import { useEffect } from 'react';
54
46
 
@@ -56,8 +48,11 @@ function MDXContent(props = {}) {
56
48
 
57
49
  useEffect(() => {
58
50
  if (window.location.hash.length !== 0) {
59
- const hash = window.location.hash;
60
- document.getElementById(hash.slice(1))?.scrollIntoView();
51
+ // 为了右侧内容区能正常跳转
52
+ const hash = decodeURIComponent(window.location.hash);
53
+ setTimeout(() => {
54
+ document.getElementById(hash.slice(1))?.scrollIntoView();
55
+ }, 100);
61
56
  } else {
62
57
  window.scrollTo(0, 0);
63
58
  }
@@ -69,6 +64,16 @@ function MDXContent(props = {}) {
69
64
 
70
65
  `);
71
66
  return { result };
72
- });
67
+ }
68
+ catch (e) {
69
+ plugin_utils_1.logger.error(e.reason);
70
+ plugin_utils_1.logger.error(`Above error occurred in ${opts.fileName} at line ${e.line}`);
71
+ plugin_utils_1.logger.error(opts.content
72
+ .split('\n')
73
+ .filter((_, i) => i == e.line - 1)
74
+ .join('\n'));
75
+ plugin_utils_1.logger.error(' '.repeat(e.column - 1) + '^');
76
+ return { result: '' };
77
+ }
73
78
  }
74
79
  exports.compile = compile;
package/dist/index.js CHANGED
@@ -44,7 +44,10 @@ exports.default = (api) => {
44
44
  });
45
45
  }
46
46
  api.modifyDefaultConfig((memo) => {
47
- memo.conventionRoutes = Object.assign(Object.assign({}, memo.conventionRoutes), { base: (0, path_1.join)(api.cwd, 'docs') });
47
+ memo.conventionRoutes = {
48
+ ...memo.conventionRoutes,
49
+ base: (0, path_1.join)(api.cwd, 'docs'),
50
+ };
48
51
  memo.mdx = {
49
52
  loader: require.resolve('./loader'),
50
53
  loaderOptions: {},
@@ -84,7 +87,10 @@ exports.default = (api) => {
84
87
  const defaultLangFile = r[route].file.replace(/(.[a-z]{2}-[A-Z]{2})?.md$/, '');
85
88
  Object.keys(locales).map((l) => {
86
89
  if (r[defaultLangFile] && !r[defaultLangFile + '.' + l]) {
87
- r[defaultLangFile + '.' + l] = Object.assign(Object.assign({}, r[defaultLangFile]), { path: `/${l}/${r[defaultLangFile].path}` });
90
+ r[defaultLangFile + '.' + l] = {
91
+ ...r[defaultLangFile],
92
+ path: `/${l}/${r[defaultLangFile].path}`,
93
+ };
88
94
  }
89
95
  });
90
96
  }
@@ -119,7 +125,7 @@ export { ${exports
119
125
  path: 'Layout.tsx',
120
126
  content: `
121
127
  import React from 'react';
122
- import { useOutlet, useAppData, useLocation, Link } from 'umi';
128
+ import { useOutlet, useAppData, useLocation, Link, history } from 'umi';
123
129
  import { $Layout as Layout } from '${(0, utils_1.winPath)(require.resolve('../client/theme-doc/index.ts'))}';
124
130
  ${themeExists
125
131
  ? `import themeConfig from '${themeConfigPath}'`
@@ -132,7 +138,7 @@ export default () => {
132
138
  const appData = useAppData();
133
139
  const location = useLocation();
134
140
  return (
135
- <Layout appData={appData} components={{Link}} themeConfig={themeConfig} location={location}>
141
+ <Layout appData={appData} components={{Link}} themeConfig={themeConfig} location={location} history={history}>
136
142
  <div>{ outlet }</div>
137
143
  </Layout>
138
144
  );
package/dist/loader.js CHANGED
@@ -1,32 +1,22 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  const compiler_1 = require("./compiler");
13
- function default_1(content) {
14
- return __awaiter(this, void 0, void 0, function* () {
15
- // @ts-ignore
16
- const filename = this.resourcePath;
17
- // @ts-ignore
18
- const callback = this.async();
19
- try {
20
- const { result } = yield (0, compiler_1.compile)({
21
- content,
22
- });
23
- return callback(null, result);
24
- }
25
- catch (e) {
26
- const err = e;
27
- e.message = `${filename}: ${e.message}`;
28
- throw err;
29
- }
30
- });
4
+ async function default_1(content) {
5
+ // @ts-ignore
6
+ const filename = this.resourcePath;
7
+ // @ts-ignore
8
+ const callback = this.async();
9
+ try {
10
+ const { result } = await (0, compiler_1.compile)({
11
+ content,
12
+ fileName: filename,
13
+ });
14
+ return callback(null, result);
15
+ }
16
+ catch (e) {
17
+ const err = e;
18
+ e.message = `${filename}: ${e.message}`;
19
+ throw err;
20
+ }
31
21
  }
32
22
  exports.default = default_1;
package/dist/markdown.js CHANGED
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseTitle = void 0;
4
4
  function parseTitle(opts) {
5
- const lines = opts.content.split('\n');
5
+ const lines = opts.content
6
+ .replace(/{[\n\s\t]*\/\*[\s\S]*?\*\/[\n\s\t]*}/g, '')
7
+ .split('\n');
6
8
  let i = 0;
7
9
  const ret = [];
8
10
  while (i < lines.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umijs/plugin-docs",
3
- "version": "4.0.0-rc.14",
3
+ "version": "4.0.0-rc.17",
4
4
  "description": "@umijs/plugin-docs",
5
5
  "homepage": "https://github.com/umijs/umi-next/tree/master/packages/plugin-docs#readme",
6
6
  "bugs": "https://github.com/umijs/umi-next/issues",
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "keymaster": "1.6.2",
30
30
  "react-helmet": "^6.1.0",
31
- "rehype-pretty-code": "^0.3.0",
31
+ "rehype-pretty-code": "^0.3.1",
32
32
  "shiki": "^0.10.1"
33
33
  },
34
34
  "devDependencies": {
@@ -38,8 +38,8 @@
38
38
  "classnames": "^2.3.1",
39
39
  "rehype-slug": "5.0.1",
40
40
  "remark-gfm": "^3.0.1",
41
- "tailwindcss": "^3.0.23",
42
- "umi": "4.0.0-rc.14"
41
+ "tailwindcss": "^3.0.24",
42
+ "umi": "4.0.0-rc.17"
43
43
  },
44
44
  "publishConfig": {
45
45
  "access": "public"