@antv/dumi-theme-antv 0.3.8 → 0.3.11

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.
Files changed (31) hide show
  1. package/dist/pages/404.js +2 -2
  2. package/dist/pages/Example/index.js +7 -7
  3. package/dist/plugin/index.js +26 -12
  4. package/dist/plugin/rehypeObservable.d.ts +1 -0
  5. package/dist/plugin/{utils.js → rehypeObservable.js} +43 -22
  6. package/dist/slots/CodeEditor/Toolbar.d.ts +1 -0
  7. package/dist/slots/CodeEditor/Toolbar.js +6 -5
  8. package/dist/slots/CodeEditor/index.js +220 -54
  9. package/dist/slots/CodeEditor/utils.d.ts +1 -1
  10. package/dist/slots/CodeEditor/utils.js +2 -1
  11. package/dist/slots/Header/Search/SearchResult.d.ts +21 -0
  12. package/dist/slots/Header/Search/SearchResult.js +35 -0
  13. package/dist/slots/Header/Search/SearchResult.module.less +65 -0
  14. package/dist/slots/Header/Search/helper.d.ts +8 -0
  15. package/dist/slots/Header/Search/helper.js +25 -0
  16. package/dist/slots/Header/Search/index.d.ts +2 -0
  17. package/dist/slots/Header/Search/index.js +59 -0
  18. package/dist/slots/Header/{Search.module.less → Search/index.module.less} +1 -9
  19. package/dist/slots/ManualContent/Preview.d.ts +7 -0
  20. package/dist/slots/ManualContent/Preview.js +203 -0
  21. package/dist/slots/ManualContent/Preview.module.less +62 -0
  22. package/dist/slots/ManualContent/index.js +11 -9
  23. package/dist/slots/ManualContent/usePreview.d.ts +1 -0
  24. package/dist/slots/ManualContent/usePreview.js +97 -0
  25. package/dist/slots/ManualContent/utils.d.ts +1 -0
  26. package/dist/slots/ManualContent/utils.js +7 -4
  27. package/dist/slots/utils.js +16 -5
  28. package/package.json +7 -3
  29. package/dist/plugin/utils.d.ts +0 -5
  30. package/dist/slots/Header/Search.d.ts +0 -12
  31. package/dist/slots/Header/Search.js +0 -87
@@ -0,0 +1,97 @@
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
+ function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
5
+ import React, { useEffect } from 'react';
6
+ import { createRoot } from 'react-dom/client';
7
+ import { Preview } from "./Preview";
8
+ import { safeEval } from "./utils";
9
+ function optionsOf(p) {
10
+ try {
11
+ var _meta$match;
12
+ var meta = p.getAttribute('meta');
13
+ var options = (_meta$match = meta.match(/\|\s*ob\s*({.*})/)) === null || _meta$match === void 0 ? void 0 : _meta$match[1];
14
+ if (!options) return {};
15
+ return safeEval(options);
16
+ } catch (e) {
17
+ console.error(e);
18
+ return {};
19
+ }
20
+ }
21
+ function sourceOf(block) {
22
+ var cloned = block.cloneNode(true);
23
+ // 去掉 comments
24
+ var comments = Array.from(cloned.querySelectorAll('.comment'));
25
+ comments.forEach(function (comment) {
26
+ return comment.remove();
27
+ });
28
+ return cloned.textContent;
29
+ }
30
+ export function usePreview() {
31
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
32
+ useEffect(function () {
33
+ var blocks = Array.from(document.querySelectorAll('.ob-codeblock .dumi-default-source-code'));
34
+
35
+ // 过滤实际展示的 block
36
+ var I = Array.from({
37
+ length: blocks.length
38
+ }, function (_, i) {
39
+ return i;
40
+ });
41
+ var OI = I.filter(function (i) {
42
+ var p = blocks[i].previousSibling;
43
+ var options = optionsOf(p);
44
+ var _options$only = options.only,
45
+ only = _options$only === void 0 ? false : _options$only;
46
+ return only === true;
47
+ });
48
+ var FI = OI.length === 0 ? I : OI;
49
+
50
+ // 将 p 标签替换成渲染后结果
51
+ var W = [];
52
+ var P = [];
53
+ var _iterator = _createForOfIteratorHelper(FI),
54
+ _step;
55
+ try {
56
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
57
+ var i = _step.value;
58
+ var block = blocks[i];
59
+ var source = sourceOf(block);
60
+ var p = block.previousSibling;
61
+
62
+ // 渲染并且挂载代码运行结果
63
+ var wrapper = document.createElement('div');
64
+ var _options = optionsOf(p);
65
+ var root = createRoot(wrapper);
66
+ root.render( /*#__PURE__*/React.createElement(Preview, _extends({
67
+ source: source,
68
+ code: block
69
+ }, _options)));
70
+ p.replaceWith(wrapper);
71
+ W[i] = wrapper;
72
+ P[i] = p;
73
+ }
74
+ } catch (err) {
75
+ _iterator.e(err);
76
+ } finally {
77
+ _iterator.f();
78
+ }
79
+ return function () {
80
+ // 复原
81
+ var _iterator2 = _createForOfIteratorHelper(FI),
82
+ _step2;
83
+ try {
84
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
85
+ var i = _step2.value;
86
+ var wrapper = W[i];
87
+ var p = P[i];
88
+ wrapper.replaceWith(p);
89
+ }
90
+ } catch (err) {
91
+ _iterator2.e(err);
92
+ } finally {
93
+ _iterator2.f();
94
+ }
95
+ };
96
+ });
97
+ }
@@ -16,3 +16,4 @@ export declare function getIndexRoute(MenuData: any): any;
16
16
  * @param p
17
17
  */
18
18
  export declare function getNavigateUrl(pathname: string, first: string, siderbarMenu: any[]): string;
19
+ export declare function safeEval(source: any): any;
@@ -37,12 +37,12 @@ export function getIndexRoute(MenuData) {
37
37
  * /en/docs/api/ ----> /en/api/[first-doc]
38
38
  * /zh/docs/api/ ----> /api/[first-doc]
39
39
  *
40
- * /en/docs/api/xxx ----> /en/api/xxx
40
+ * /en/docs/api/xxx ----> /en/api/xxx
41
41
  * /zh/docs/api/xxx ----> /api/xxx
42
- *
42
+ *
43
43
  * /docs/api/xxx -----> /api/xxx
44
- *
45
- * @param p
44
+ *
45
+ * @param p
46
46
  */
47
47
  export function getNavigateUrl(pathname, first, siderbarMenu) {
48
48
  // 兜底 如果 nav 指定有误则自动重定向到 indexDocRoute
@@ -56,4 +56,7 @@ export function getNavigateUrl(pathname, first, siderbarMenu) {
56
56
  return first;
57
57
  }
58
58
  return pathname;
59
+ }
60
+ export function safeEval(source) {
61
+ return new Function("return ".concat(source))();
59
62
  }
@@ -14,7 +14,7 @@ export function ping() {
14
14
  }
15
15
  function _ping() {
16
16
  _ping = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
17
- var timeout, url, network;
17
+ var timeout, network;
18
18
  return _regeneratorRuntime().wrap(function _callee$(_context) {
19
19
  while (1) switch (_context.prev = _context.next) {
20
20
  case 0:
@@ -23,14 +23,25 @@ function _ping() {
23
23
  resolve('timeout');
24
24
  }, 1500);
25
25
  });
26
- url = 'https://private-a' + 'lipay' + 'objects.alip' + 'ay.com/alip' + 'ay-rmsdeploy-image/rmsportal/RKuAiriJqrUhyqW.png';
27
- network = fetch(url).then(function (resp) {
28
- return resp.status === 200 ? 'responded' : 'error';
26
+ network = new Promise(function (resolve) {
27
+ var url = 'https://private-a' + 'lipay' + 'objects.alip' + 'ay.com/alip' + 'ay-rmsdeploy-image/rmsportal/RKuAiriJqrUhyqW.png';
28
+ var img = new Image();
29
+ img.onload = function () {
30
+ img.onload = null;
31
+ img.onerror = null;
32
+ resolve('responded');
33
+ };
34
+ img.onerror = function () {
35
+ img.onload = null;
36
+ img.onerror = null;
37
+ resolve('error');
38
+ };
39
+ img.src = url;
29
40
  });
30
41
  return _context.abrupt("return", Promise.race([timeout, network]).catch(function (r) {
31
42
  return 'error';
32
43
  }));
33
- case 4:
44
+ case 3:
34
45
  case "end":
35
46
  return _context.stop();
36
47
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/dumi-theme-antv",
3
- "version": "0.3.8",
3
+ "version": "0.3.11",
4
4
  "description": "AntV website theme based on dumi2.",
5
5
  "types": "dist/types.d.ts",
6
6
  "scripts": {
@@ -61,11 +61,12 @@
61
61
  "antd": "^4.23.5",
62
62
  "classnames": "^2.3.2",
63
63
  "codesandbox": "^2.2.3",
64
+ "d3-dsv": "^3.0.1",
64
65
  "docsearch.js": "^2.6.3",
65
- "dumi": "^2.0.0-beta.15",
66
66
  "front-matter": "^4.0.2",
67
67
  "fs-extra": "^10.1.0",
68
68
  "glob": "^8.0.3",
69
+ "hast": "^1.0.0",
69
70
  "indent-string": "^5.0.0",
70
71
  "insert-css": "^2.0.0",
71
72
  "lodash-es": "^4.17.21",
@@ -86,11 +87,13 @@
86
87
  "semver": "^7.3.8",
87
88
  "size-sensor": "^1.0.1",
88
89
  "slick-carousel": "^1.8.1",
90
+ "unified": "^10.1.2",
91
+ "unist-util-visit": "^4.1.2",
89
92
  "uri-parse": "^1.0.0",
90
93
  "video-react": "^0.16.0"
91
94
  },
92
95
  "peerDependencies": {
93
- "dumi": "^2.0.0-beta.15",
96
+ "dumi": "^2.0.0",
94
97
  "react": ">=16.9.0",
95
98
  "react-dom": ">=16.9.0"
96
99
  },
@@ -106,6 +109,7 @@
106
109
  "@types/react-router-dom": "^5.3.3",
107
110
  "@types/react-slick": "^0.23.10",
108
111
  "@umijs/lint": "^4.0.0",
112
+ "dumi": "^2.0.0",
109
113
  "eslint": "^8.23.0",
110
114
  "father": "^4.1.0",
111
115
  "father-plugin-dumi-theme": "^1.0.0-beta.1",
@@ -1,5 +0,0 @@
1
- /**
2
- * 自定义的 resolve 函数,优先找 tsx,如果找不到则找对应的 js 文件。
3
- * 因为 dumi-theme-antv 编译之后,全部变成 js 文件
4
- */
5
- export declare function myResolve(p: string, alternateExts?: string[]): string;
@@ -1,12 +0,0 @@
1
- import React from 'react';
2
- import '@docsearch/css';
3
- import 'docsearch.js/dist/cdn/docsearch.min.css';
4
- export interface SearchProps {
5
- docsearchOptions?: {
6
- versionV3?: boolean;
7
- appId?: string;
8
- apiKey: string;
9
- indexName: string;
10
- };
11
- }
12
- export declare const Search: React.FC<SearchProps>;
@@ -1,87 +0,0 @@
1
- import React, { useEffect } from 'react';
2
- import { SearchOutlined } from '@ant-design/icons';
3
- import { DocSearch } from '@docsearch/react';
4
- import { useLocale, useIntl } from 'dumi';
5
- import '@docsearch/css';
6
- import styles from "./Search.module.less";
7
- import 'docsearch.js/dist/cdn/docsearch.min.css';
8
- function initDocSearchV2(_ref) {
9
- var docsearchV2 = _ref.docsearchV2,
10
- lang = _ref.lang,
11
- docsearchOptions = _ref.docsearchOptions;
12
- var _ref2 = docsearchOptions || {},
13
- _ref2$apiKey = _ref2.apiKey,
14
- apiKey = _ref2$apiKey === void 0 ? '194b1be7fb1254c787f4e036912af3eb' : _ref2$apiKey,
15
- _ref2$indexName = _ref2.indexName,
16
- indexName = _ref2$indexName === void 0 ? 'antv' : _ref2$indexName;
17
- docsearchV2({
18
- apiKey: apiKey,
19
- indexName: indexName,
20
- inputSelector: ".".concat(styles.input),
21
- algoliaOptions: {
22
- facetFilters: ["tags:".concat(lang)]
23
- },
24
- transformData: function transformData(hits) {
25
- hits.forEach(function (hit) {
26
- /* eslint-disable no-param-reassign */
27
- hit.url = hit.url.replace('g2.antv.vision', window.location.host);
28
- hit.url = hit.url.replace('g6.antv.vision', window.location.host);
29
- hit.url = hit.url.replace('f2.antv.vision', window.location.host);
30
- hit.url = hit.url.replace('l7.antv.vision', window.location.host);
31
- hit.url = hit.url.replace('x6.antv.vision', window.location.host);
32
- hit.url = hit.url.replace('g2plot.antv.vision', window.location.host);
33
- hit.url = hit.url.replace('graphin.antv.vision', window.location.host);
34
- hit.url = hit.url.replace('https:', window.location.protocol);
35
- hit.url = hit.url.replace('#gatsby-focus-wrapper', '');
36
- /* eslint-enable no-param-reassign */
37
- });
38
-
39
- return hits;
40
- },
41
- debug: false // Set debug to true if you want to inspect the dropdown
42
- });
43
- }
44
-
45
- export var Search = function Search(_ref3) {
46
- var docsearchOptions = _ref3.docsearchOptions;
47
- var locale = useLocale();
48
- var intl = useIntl();
49
- var _ref4 = docsearchOptions || {},
50
- _ref4$apiKey = _ref4.apiKey,
51
- apiKey = _ref4$apiKey === void 0 ? '' : _ref4$apiKey,
52
- _ref4$indexName = _ref4.indexName,
53
- indexName = _ref4$indexName === void 0 ? '' : _ref4$indexName,
54
- _ref4$versionV = _ref4.versionV3,
55
- versionV3 = _ref4$versionV === void 0 ? false : _ref4$versionV,
56
- _ref4$appId = _ref4.appId,
57
- appId = _ref4$appId === void 0 ? '' : _ref4$appId;
58
- useEffect(function () {
59
- if (typeof window !== 'undefined' && !versionV3) {
60
- import('docsearch.js').then(function (_ref5) {
61
- var docsearchV2 = _ref5.default;
62
- initDocSearchV2({
63
- docsearchV2: docsearchV2,
64
- lang: locale.id,
65
- docsearchOptions: docsearchOptions
66
- });
67
- });
68
- }
69
- }, []);
70
- return /*#__PURE__*/React.createElement("label", {
71
- className: styles.search,
72
- htmlFor: "search",
73
- id: "search"
74
- }, versionV3 ? /*#__PURE__*/React.createElement(DocSearch, {
75
- appId: appId,
76
- indexName: indexName,
77
- apiKey: apiKey
78
- }) : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(SearchOutlined, {
79
- className: styles.icon
80
- }), /*#__PURE__*/React.createElement("input", {
81
- className: styles.input,
82
- id: "search",
83
- placeholder: intl.formatMessage({
84
- id: '搜索…'
85
- })
86
- })));
87
- };