@rspress/plugin-api-docgen 1.43.13 → 1.44.0

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.
package/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
2
  var __webpack_modules__ = {
3
3
  documentation: function(module) {
4
- module.exports = import("documentation");
4
+ module.exports = import("documentation").then(function(module) {
5
+ return module;
6
+ });
5
7
  }
6
8
  };
7
9
  var __webpack_module_cache__ = {};
@@ -15,12 +17,8 @@ function __webpack_require__(moduleId) {
15
17
  return module.exports;
16
18
  }
17
19
  (()=>{
18
- __webpack_require__.n = function(module) {
19
- var getter = module && module.__esModule ? function() {
20
- return module['default'];
21
- } : function() {
22
- return module;
23
- };
20
+ __webpack_require__.n = (module)=>{
21
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
24
22
  __webpack_require__.d(getter, {
25
23
  a: getter
26
24
  });
@@ -28,7 +26,7 @@ function __webpack_require__(moduleId) {
28
26
  };
29
27
  })();
30
28
  (()=>{
31
- __webpack_require__.d = function(exports1, definition) {
29
+ __webpack_require__.d = (exports1, definition)=>{
32
30
  for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
33
31
  enumerable: true,
34
32
  get: definition[key]
@@ -36,12 +34,10 @@ function __webpack_require__(moduleId) {
36
34
  };
37
35
  })();
38
36
  (()=>{
39
- __webpack_require__.o = function(obj, prop) {
40
- return Object.prototype.hasOwnProperty.call(obj, prop);
41
- };
37
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
42
38
  })();
43
39
  (()=>{
44
- __webpack_require__.r = function(exports1) {
40
+ __webpack_require__.r = (exports1)=>{
45
41
  if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
46
42
  value: 'Module'
47
43
  });
@@ -69,20 +65,20 @@ var __webpack_exports__ = {};
69
65
  const external_react_docgen_typescript_namespaceObject = require("react-docgen-typescript");
70
66
  const locales = {
71
67
  zh: {
72
- copy: '复制',
73
- copied: '复制成功',
74
- expand: '展开代码',
75
- collapse: '收起代码',
76
- className: '节点类名',
77
- style: '节点样式',
78
- children: '子节点',
79
- disabled: '是否禁用',
80
- required: '必填',
81
- property: '属性',
82
- description: '说明',
83
- type: '类型',
84
- defaultValue: '默认值',
85
- overview: '概览'
68
+ copy: "\u590D\u5236",
69
+ copied: "\u590D\u5236\u6210\u529F",
70
+ expand: "\u5C55\u5F00\u4EE3\u7801",
71
+ collapse: "\u6536\u8D77\u4EE3\u7801",
72
+ className: "\u8282\u70B9\u7C7B\u540D",
73
+ style: "\u8282\u70B9\u6837\u5F0F",
74
+ children: "\u5B50\u8282\u70B9",
75
+ disabled: "\u662F\u5426\u7981\u7528",
76
+ required: "\u5FC5\u586B",
77
+ property: "\u5C5E\u6027",
78
+ description: "\u8BF4\u660E",
79
+ type: "\u7C7B\u578B",
80
+ defaultValue: "\u9ED8\u8BA4\u503C",
81
+ overview: "\u6982\u89C8"
86
82
  },
87
83
  en: {
88
84
  copy: 'Copy',
@@ -101,20 +97,20 @@ var __webpack_exports__ = {};
101
97
  overview: 'Overview'
102
98
  },
103
99
  ru: {
104
- copy: 'Копировать',
105
- copied: 'Скопировано успешно',
106
- expand: 'Развернуть код',
107
- collapse: 'Свернуть код',
108
- className: 'Имя класса узла',
109
- style: 'Стиль узла',
110
- children: 'Дочерние элементы',
111
- disabled: 'Отключено',
112
- required: 'Обязательно',
113
- property: 'Свойство',
114
- description: 'Описание',
115
- type: 'Тип',
116
- defaultValue: 'Значение по умолчанию',
117
- overview: 'Обзор'
100
+ copy: "\u041A\u043E\u043F\u0438\u0440\u043E\u0432\u0430\u0442\u044C",
101
+ copied: "\u0421\u043A\u043E\u043F\u0438\u0440\u043E\u0432\u0430\u043D\u043E \u0443\u0441\u043F\u0435\u0448\u043D\u043E",
102
+ expand: "\u0420\u0430\u0437\u0432\u0435\u0440\u043D\u0443\u0442\u044C \u043A\u043E\u0434",
103
+ collapse: "\u0421\u0432\u0435\u0440\u043D\u0443\u0442\u044C \u043A\u043E\u0434",
104
+ className: "\u0418\u043C\u044F \u043A\u043B\u0430\u0441\u0441\u0430 \u0443\u0437\u043B\u0430",
105
+ style: "\u0421\u0442\u0438\u043B\u044C \u0443\u0437\u043B\u0430",
106
+ children: "\u0414\u043E\u0447\u0435\u0440\u043D\u0438\u0435 \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u044B",
107
+ disabled: "\u041E\u0442\u043A\u043B\u044E\u0447\u0435\u043D\u043E",
108
+ required: "\u041E\u0431\u044F\u0437\u0430\u0442\u0435\u043B\u044C\u043D\u043E",
109
+ property: "\u0421\u0432\u043E\u0439\u0441\u0442\u0432\u043E",
110
+ description: "\u041E\u043F\u0438\u0441\u0430\u043D\u0438\u0435",
111
+ type: "\u0422\u0438\u043F",
112
+ defaultValue: "\u0417\u043D\u0430\u0447\u0435\u043D\u0438\u0435 \u043F\u043E \u0443\u043C\u043E\u043B\u0447\u0430\u043D\u0438\u044E",
113
+ overview: "\u041E\u0431\u0437\u043E\u0440"
118
114
  }
119
115
  };
120
116
  const isToolEntries = (obj)=>!!obj.documentation || !!obj["react-docgen-typescript"];
@@ -138,7 +134,7 @@ var __webpack_exports__ = {};
138
134
  ...parseToolOptions.documentation
139
135
  });
140
136
  const apiDoc = await documentation.formats.md(documentationRes, {
141
- noReferenceLinks: (null === (_parseToolOptions_documentation = parseToolOptions.documentation) || void 0 === _parseToolOptions_documentation ? void 0 : _parseToolOptions_documentation.noReferenceLinks) ?? true
137
+ noReferenceLinks: (null == (_parseToolOptions_documentation = parseToolOptions.documentation) ? void 0 : _parseToolOptions_documentation.noReferenceLinks) ?? true
142
138
  });
143
139
  apiDocMap[key] = apiDoc;
144
140
  } else {
@@ -272,7 +268,7 @@ var __webpack_exports__ = {};
272
268
  },
273
269
  async beforeBuild (config, isProd) {
274
270
  var _config_themeConfig_locales, _config_themeConfig, _config_locales;
275
- const languages = ((null === (_config_themeConfig = config.themeConfig) || void 0 === _config_themeConfig ? void 0 : null === (_config_themeConfig_locales = _config_themeConfig.locales) || void 0 === _config_themeConfig_locales ? void 0 : _config_themeConfig_locales.map((locale)=>locale.lang)) || (null === (_config_locales = config.locales) || void 0 === _config_locales ? void 0 : _config_locales.map((locale)=>locale.lang)) || []).filter((lang)=>[
271
+ const languages = ((null == (_config_themeConfig = config.themeConfig) ? void 0 : null == (_config_themeConfig_locales = _config_themeConfig.locales) ? void 0 : _config_themeConfig_locales.map((locale)=>locale.lang)) || (null == (_config_locales = config.locales) ? void 0 : _config_locales.map((locale)=>locale.lang)) || []).filter((lang)=>[
276
272
  'zh',
277
273
  'en',
278
274
  'ru'
@@ -317,8 +313,10 @@ var __webpack_exports__ = {};
317
313
  };
318
314
  }
319
315
  })();
320
- var __webpack_export_target__ = exports;
321
- for(var __webpack_i__ in __webpack_exports__)__webpack_export_target__[__webpack_i__] = __webpack_exports__[__webpack_i__];
322
- if (__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, '__esModule', {
316
+ exports.pluginApiDocgen = __webpack_exports__.pluginApiDocgen;
317
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
318
+ "pluginApiDocgen"
319
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
320
+ Object.defineProperty(exports, '__esModule', {
323
321
  value: true
324
322
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rspress/plugin-api-docgen",
3
- "version": "1.43.13",
3
+ "version": "1.44.0",
4
4
  "description": "A plugin for rspress to generate api doc.",
5
5
  "bugs": "https://github.com/web-infra-dev/rspress/issues",
6
6
  "repository": {
@@ -20,14 +20,17 @@
20
20
  "dependencies": {
21
21
  "chokidar": "^3.6.0",
22
22
  "documentation": "14.0.3",
23
+ "github-slugger": "^2.0.0",
23
24
  "react-docgen-typescript": "2.2.2",
24
25
  "react-markdown": "8.0.7",
25
26
  "remark-gfm": "3.0.1",
26
- "@rspress/shared": "1.43.13"
27
+ "unist-util-visit": "^4.1.2",
28
+ "@rspress/shared": "1.44.0"
27
29
  },
28
30
  "devDependencies": {
29
31
  "@microsoft/api-extractor": "^7.49.2",
30
- "@rslib/core": "0.5.2",
32
+ "@rslib/core": "~0.6.9",
33
+ "@types/hast": "^2.3.10",
31
34
  "@types/mdast": "^3.0.15",
32
35
  "@types/node": "^18.11.17",
33
36
  "@types/react": "^18.3.18",
@@ -36,11 +39,10 @@
36
39
  "react-dom": "^18.3.1",
37
40
  "react-router-dom": "^6.29.0",
38
41
  "typescript": "^5.5.3",
39
- "unified": "^10.1.2",
40
- "unist-util-visit": "^4.1.2"
42
+ "unified": "^10.1.2"
41
43
  },
42
44
  "peerDependencies": {
43
- "@rspress/core": "^1.43.13",
45
+ "@rspress/core": "^1.44.0",
44
46
  "react": ">=17.0.0",
45
47
  "react-router-dom": "^6.8.1",
46
48
  "typescript": "^5.5.3"
@@ -5,6 +5,97 @@ import { getCustomMDXComponent } from '@rspress/core/theme';
5
5
  import ReactMarkdown from 'react-markdown';
6
6
  import remarkGfm from 'remark-gfm';
7
7
  import './API.scss';
8
+ import GithubSlugger from 'github-slugger';
9
+ import type { Content, Element, Root } from 'hast';
10
+ // biome-ignore lint/style/useImportType: <exact>
11
+ import React from 'react';
12
+ import type { Plugin } from 'unified';
13
+ import { visit } from 'unist-util-visit';
14
+
15
+ function headingRank(node: Root | Content): number | null {
16
+ const name =
17
+ (node && node.type === 'element' && node.tagName.toLowerCase()) || '';
18
+ const code =
19
+ name.length === 2 && name.charCodeAt(0) === 104 /* `h` */
20
+ ? name.charCodeAt(1)
21
+ : 0;
22
+ return code > 48 /* `0` */ && code < 55 /* `7` */
23
+ ? code - 48 /* `0` */
24
+ : null;
25
+ }
26
+
27
+ const rehypeHeaderAnchor: Plugin<[], Root> = () => {
28
+ const slugger = new GithubSlugger();
29
+ return tree => {
30
+ visit(tree, 'element', node => {
31
+ if (!headingRank(node)) {
32
+ return;
33
+ }
34
+ // generate id
35
+
36
+ if (!node.properties?.id) {
37
+ const text = collectHeaderText(node);
38
+ node.properties ??= {};
39
+ node.properties.id = slugger.slug(text);
40
+ }
41
+ // apply to headings
42
+ node.children.unshift(create(node));
43
+ });
44
+ };
45
+ };
46
+
47
+ /**
48
+ * Create an `a`.
49
+ *
50
+ * @param {Readonly<Element>} node
51
+ * Related heading.
52
+ * @returns {Element}
53
+ * Link.
54
+ */
55
+ function create(node: Element): Element {
56
+ return {
57
+ type: 'element',
58
+ tagName: 'a',
59
+ properties: {
60
+ class: 'header-anchor',
61
+ ariaHidden: 'true',
62
+ href: `#${node.properties!.id}`,
63
+ },
64
+ children: [
65
+ {
66
+ type: 'text',
67
+ value: '#',
68
+ },
69
+ ],
70
+ };
71
+ }
72
+
73
+ const extractTextAndId = (title?: string): string => {
74
+ if (!title) {
75
+ return '';
76
+ }
77
+ const text = title.trimEnd();
78
+ return text;
79
+ };
80
+
81
+ const collectHeaderText = (node: Element): string => {
82
+ let text = '';
83
+ node.children.forEach(child => {
84
+ if (child.type === 'text') {
85
+ const textPart = extractTextAndId(child.value);
86
+ child.value = textPart;
87
+ text += textPart;
88
+ }
89
+ if (child.type === 'element') {
90
+ child.children.forEach(c => {
91
+ if (c.type === 'text') {
92
+ text += c.value;
93
+ }
94
+ });
95
+ }
96
+ });
97
+ return text;
98
+ };
8
99
 
9
100
  export default (props: { moduleName: string }) => {
10
101
  const lang = useLang();
@@ -18,6 +109,7 @@ export default (props: { moduleName: string }) => {
18
109
  return (
19
110
  <ReactMarkdown
20
111
  remarkPlugins={[[remarkGfm]]}
112
+ rehypePlugins={[[rehypeHeaderAnchor]]}
21
113
  components={getCustomMDXComponent() as Record<string, React.ElementType>}
22
114
  skipHtml={true}
23
115
  className="rspress-plugin-api-docgen"