@antv/dumi-theme-antv 0.3.10 → 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.
- package/dist/pages/404.js +2 -2
- package/dist/plugin/index.js +15 -5
- package/dist/plugin/rehypeObservable.d.ts +1 -0
- package/dist/plugin/rehypeObservable.js +74 -0
- package/dist/slots/CodeEditor/index.js +11 -3
- package/dist/slots/Header/Search/index.js +1 -1
- package/dist/slots/ManualContent/Preview.d.ts +1 -1
- package/dist/slots/ManualContent/Preview.js +5 -6
- package/dist/slots/ManualContent/usePreview.js +15 -7
- package/dist/slots/ManualContent/utils.d.ts +1 -0
- package/dist/slots/ManualContent/utils.js +7 -4
- package/package.json +4 -1
package/dist/pages/404.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { SEO } from "dumi/theme/slots/SEO";
|
|
3
|
-
import { Header } from "dumi/theme/slots/Header";
|
|
4
2
|
import { NotFound as NotFoundPage } from "dumi/theme/slots/404";
|
|
5
3
|
import { Footer } from "dumi/theme/slots/Footer";
|
|
4
|
+
import { Header } from "dumi/theme/slots/Header";
|
|
5
|
+
import { SEO } from "dumi/theme/slots/SEO";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* 404 页面
|
package/dist/plugin/index.js
CHANGED
|
@@ -32,9 +32,10 @@ __export(plugin_exports, {
|
|
|
32
32
|
default: () => plugin_default
|
|
33
33
|
});
|
|
34
34
|
module.exports = __toCommonJS(plugin_exports);
|
|
35
|
-
var path = __toESM(require("path"));
|
|
36
35
|
var import_plugin_utils = require("dumi/plugin-utils");
|
|
36
|
+
var path = __toESM(require("path"));
|
|
37
37
|
var import_examples = require("./examples");
|
|
38
|
+
var import_rehypeObservable = __toESM(require("./rehypeObservable"));
|
|
38
39
|
var ALIAS_PAGES_KEY = "@/antv__theme__pages";
|
|
39
40
|
var MOCK_META = { frontmatter: { title: "mock-meta" }, texts: [], toc: [] };
|
|
40
41
|
var plugin_default = (api) => {
|
|
@@ -44,8 +45,11 @@ var plugin_default = (api) => {
|
|
|
44
45
|
memo.exportStatic.extraRoutePaths = (0, import_examples.getExamplePaths)();
|
|
45
46
|
memo.mfsu = false;
|
|
46
47
|
memo.jsMinifier = "terser";
|
|
47
|
-
memo.favicons = [
|
|
48
|
+
memo.favicons = [
|
|
49
|
+
"https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*7svFR6wkPMoAAAAAAAAAAAAADmJ7AQ/original"
|
|
50
|
+
];
|
|
48
51
|
memo.alias[ALIAS_PAGES_KEY] = path.join(__dirname, "../pages");
|
|
52
|
+
memo.extraRehypePlugins = [import_rehypeObservable.default];
|
|
49
53
|
return memo;
|
|
50
54
|
});
|
|
51
55
|
const pages = [
|
|
@@ -91,7 +95,9 @@ var plugin_default = (api) => {
|
|
|
91
95
|
content: `
|
|
92
96
|
import React from 'react';
|
|
93
97
|
import { useOutlet, useSiteData } from 'dumi';
|
|
94
|
-
import { ThemeAntVContext } from '${(0, import_plugin_utils.winPath)(
|
|
98
|
+
import { ThemeAntVContext } from '${(0, import_plugin_utils.winPath)(
|
|
99
|
+
path.join(__dirname, "../context")
|
|
100
|
+
)}';
|
|
95
101
|
|
|
96
102
|
export default function ThemeAntVContextWrapper() {
|
|
97
103
|
const outlet = useOutlet();
|
|
@@ -100,7 +106,9 @@ export default function ThemeAntVContextWrapper() {
|
|
|
100
106
|
<ThemeAntVContext.Provider
|
|
101
107
|
value={{
|
|
102
108
|
meta: ${JSON.stringify({
|
|
103
|
-
exampleTopics: (0, import_examples.getExamplesPageTopics)(
|
|
109
|
+
exampleTopics: (0, import_examples.getExamplesPageTopics)(
|
|
110
|
+
api.config.themeConfig.examples || []
|
|
111
|
+
)
|
|
104
112
|
})}
|
|
105
113
|
}}
|
|
106
114
|
>
|
|
@@ -130,7 +138,9 @@ export default function ThemeAntVContextWrapper() {
|
|
|
130
138
|
routes["404"].meta = MOCK_META;
|
|
131
139
|
return routes;
|
|
132
140
|
});
|
|
133
|
-
api.addTmpGenerateWatcherPaths(() => [
|
|
141
|
+
api.addTmpGenerateWatcherPaths(() => [
|
|
142
|
+
path.resolve(process.cwd(), "examples")
|
|
143
|
+
]);
|
|
134
144
|
};
|
|
135
145
|
// Annotate the CommonJS export names for ESM import in node:
|
|
136
146
|
0 && (module.exports = {});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export default function rehypeObservable(): (tree: any) => Promise<void>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
|
|
29
|
+
// src/plugin/rehypeObservable.ts
|
|
30
|
+
var rehypeObservable_exports = {};
|
|
31
|
+
__export(rehypeObservable_exports, {
|
|
32
|
+
default: () => rehypeObservable
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(rehypeObservable_exports);
|
|
35
|
+
var visit;
|
|
36
|
+
(async () => {
|
|
37
|
+
({ visit } = await import("unist-util-visit"));
|
|
38
|
+
})();
|
|
39
|
+
function isObservable(node) {
|
|
40
|
+
if (!node.data)
|
|
41
|
+
return;
|
|
42
|
+
const { meta } = node.data;
|
|
43
|
+
if (!meta)
|
|
44
|
+
return;
|
|
45
|
+
return meta.match(/\|\s*ob\s*{*/);
|
|
46
|
+
}
|
|
47
|
+
function rehypeObservable() {
|
|
48
|
+
return async (tree) => {
|
|
49
|
+
visit(tree, "element", (node, i, parent) => {
|
|
50
|
+
if (!isObservable(node))
|
|
51
|
+
return;
|
|
52
|
+
if (node.tagName === "SourceCode") {
|
|
53
|
+
parent.children.splice(i, 1, {
|
|
54
|
+
type: "element",
|
|
55
|
+
tagName: "div",
|
|
56
|
+
properties: {
|
|
57
|
+
class: "ob-codeblock"
|
|
58
|
+
},
|
|
59
|
+
children: [
|
|
60
|
+
{
|
|
61
|
+
type: "element",
|
|
62
|
+
tagName: "p",
|
|
63
|
+
properties: { meta: node.data.meta },
|
|
64
|
+
children: []
|
|
65
|
+
},
|
|
66
|
+
{ ...node }
|
|
67
|
+
]
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
74
|
+
0 && (module.exports = {});
|
|
@@ -171,6 +171,11 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
171
171
|
// 案例变化的时候,修改代码
|
|
172
172
|
useEffect(function () {
|
|
173
173
|
setCode(source);
|
|
174
|
+
|
|
175
|
+
// 清空 data 和 spec
|
|
176
|
+
// 放在该案例运行错误,返回之前案例的 data 和 spec
|
|
177
|
+
setData(null);
|
|
178
|
+
if (showSpecTab) setSpec(null);
|
|
174
179
|
}, [exampleId]);
|
|
175
180
|
|
|
176
181
|
// 代码变化的时候,运行代码
|
|
@@ -257,9 +262,12 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
257
262
|
// hook 用户的数据
|
|
258
263
|
useEffect(function () {
|
|
259
264
|
// 需要匹配首位的换行符,以及 ' 和 "
|
|
260
|
-
var
|
|
265
|
+
var match = source.matchAll(/fetch\(\s*["|'](.*)["|'],*\s*\)/g);
|
|
266
|
+
var dataFileMatch = Array.from(match);
|
|
261
267
|
if (dataFileMatch && dataFileMatch.length > 0) {
|
|
262
|
-
fetchData(
|
|
268
|
+
fetchData(dataFileMatch.map(function (d) {
|
|
269
|
+
return d[1].trim();
|
|
270
|
+
})).then(function (data) {
|
|
263
271
|
updateData(data);
|
|
264
272
|
});
|
|
265
273
|
} else {
|
|
@@ -300,7 +308,7 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
300
308
|
}
|
|
301
309
|
}, [currentEditorTab]);
|
|
302
310
|
var parseFunction = function parseFunction(string) {
|
|
303
|
-
return string.replace(/"\<func\>(
|
|
311
|
+
return string.replace(/"\<func\>(.*?)\<\/func\>"/g, function (_, code) {
|
|
304
312
|
return code;
|
|
305
313
|
});
|
|
306
314
|
};
|
|
@@ -44,7 +44,7 @@ export var Search = function Search() {
|
|
|
44
44
|
value: keywords,
|
|
45
45
|
autoComplete: "off",
|
|
46
46
|
onBlur: function onBlur() {
|
|
47
|
-
return onClose;
|
|
47
|
+
return onClose();
|
|
48
48
|
},
|
|
49
49
|
onFocus: function onFocus() {
|
|
50
50
|
return setOpen(!!(result !== null && result !== void 0 && result.length));
|
|
@@ -11,6 +11,7 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
11
11
|
import { PlayCircleOutlined, PushpinOutlined } from '@ant-design/icons';
|
|
12
12
|
import React, { useEffect, useRef, useState } from 'react';
|
|
13
13
|
import styles from "./Preview.module.less";
|
|
14
|
+
import { safeEval } from "./utils";
|
|
14
15
|
function normalizeValue(node) {
|
|
15
16
|
return node instanceof Promise ? node : Promise.resolve(node);
|
|
16
17
|
}
|
|
@@ -20,9 +21,6 @@ function normalizeDOM(node) {
|
|
|
20
21
|
span.textContent = node.toString();
|
|
21
22
|
return span;
|
|
22
23
|
}
|
|
23
|
-
function safeEval(source) {
|
|
24
|
-
return new Function("return ".concat(source))();
|
|
25
|
-
}
|
|
26
24
|
function sizeOf(dom) {
|
|
27
25
|
if (dom.style.display === 'none') return {
|
|
28
26
|
width: 0,
|
|
@@ -42,7 +40,8 @@ function sizeOf(dom) {
|
|
|
42
40
|
export var Preview = function Preview(_ref) {
|
|
43
41
|
var source = _ref.source,
|
|
44
42
|
code = _ref.code,
|
|
45
|
-
|
|
43
|
+
_ref$pin = _ref.pin,
|
|
44
|
+
pin = _ref$pin === void 0 ? true : _ref$pin;
|
|
46
45
|
var containerRef = useRef(null);
|
|
47
46
|
var ulRef = useRef(null);
|
|
48
47
|
var nodeRef = useRef(null);
|
|
@@ -146,9 +145,9 @@ export var Preview = function Preview(_ref) {
|
|
|
146
145
|
|
|
147
146
|
// 是否需要隐藏代码
|
|
148
147
|
useEffect(function () {
|
|
149
|
-
if (
|
|
148
|
+
if (pin !== false) return;
|
|
150
149
|
code.style.display = 'none';
|
|
151
|
-
}, [
|
|
150
|
+
}, [pin]);
|
|
152
151
|
|
|
153
152
|
// 暂时和隐藏 toolbar
|
|
154
153
|
useEffect(function () {
|
|
@@ -5,11 +5,18 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
5
5
|
import React, { useEffect } from 'react';
|
|
6
6
|
import { createRoot } from 'react-dom/client';
|
|
7
7
|
import { Preview } from "./Preview";
|
|
8
|
+
import { safeEval } from "./utils";
|
|
8
9
|
function optionsOf(p) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
}
|
|
13
20
|
}
|
|
14
21
|
function sourceOf(block) {
|
|
15
22
|
var cloned = block.cloneNode(true);
|
|
@@ -23,7 +30,7 @@ function sourceOf(block) {
|
|
|
23
30
|
export function usePreview() {
|
|
24
31
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
25
32
|
useEffect(function () {
|
|
26
|
-
var blocks = Array.from(document.querySelectorAll('.
|
|
33
|
+
var blocks = Array.from(document.querySelectorAll('.ob-codeblock .dumi-default-source-code'));
|
|
27
34
|
|
|
28
35
|
// 过滤实际展示的 block
|
|
29
36
|
var I = Array.from({
|
|
@@ -34,8 +41,9 @@ export function usePreview() {
|
|
|
34
41
|
var OI = I.filter(function (i) {
|
|
35
42
|
var p = blocks[i].previousSibling;
|
|
36
43
|
var options = optionsOf(p);
|
|
37
|
-
var
|
|
38
|
-
|
|
44
|
+
var _options$only = options.only,
|
|
45
|
+
only = _options$only === void 0 ? false : _options$only;
|
|
46
|
+
return only === true;
|
|
39
47
|
});
|
|
40
48
|
var FI = OI.length === 0 ? I : OI;
|
|
41
49
|
|
|
@@ -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
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/dumi-theme-antv",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.11",
|
|
4
4
|
"description": "AntV website theme based on dumi2.",
|
|
5
5
|
"types": "dist/types.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -66,6 +66,7 @@
|
|
|
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,6 +87,8 @@
|
|
|
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
|
},
|