@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.
- package/dist/pages/404.js +2 -2
- package/dist/pages/Example/index.js +7 -7
- package/dist/plugin/index.js +26 -12
- package/dist/plugin/rehypeObservable.d.ts +1 -0
- package/dist/plugin/{utils.js → rehypeObservable.js} +43 -22
- package/dist/slots/CodeEditor/Toolbar.d.ts +1 -0
- package/dist/slots/CodeEditor/Toolbar.js +6 -5
- package/dist/slots/CodeEditor/index.js +220 -54
- package/dist/slots/CodeEditor/utils.d.ts +1 -1
- package/dist/slots/CodeEditor/utils.js +2 -1
- package/dist/slots/Header/Search/SearchResult.d.ts +21 -0
- package/dist/slots/Header/Search/SearchResult.js +35 -0
- package/dist/slots/Header/Search/SearchResult.module.less +65 -0
- package/dist/slots/Header/Search/helper.d.ts +8 -0
- package/dist/slots/Header/Search/helper.js +25 -0
- package/dist/slots/Header/Search/index.d.ts +2 -0
- package/dist/slots/Header/Search/index.js +59 -0
- package/dist/slots/Header/{Search.module.less → Search/index.module.less} +1 -9
- package/dist/slots/ManualContent/Preview.d.ts +7 -0
- package/dist/slots/ManualContent/Preview.js +203 -0
- package/dist/slots/ManualContent/Preview.module.less +62 -0
- package/dist/slots/ManualContent/index.js +11 -9
- package/dist/slots/ManualContent/usePreview.d.ts +1 -0
- package/dist/slots/ManualContent/usePreview.js +97 -0
- package/dist/slots/ManualContent/utils.d.ts +1 -0
- package/dist/slots/ManualContent/utils.js +7 -4
- package/dist/slots/utils.js +16 -5
- package/package.json +7 -3
- package/dist/plugin/utils.d.ts +0 -5
- package/dist/slots/Header/Search.d.ts +0 -12
- package/dist/slots/Header/Search.js +0 -87
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
export declare type ITextSegment = {
|
|
3
|
+
text: string;
|
|
4
|
+
highlighted?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare type ISearchResult = {
|
|
7
|
+
/**
|
|
8
|
+
* 搜索结果的主题,显示在最左边,一般是页面的标题。
|
|
9
|
+
*/
|
|
10
|
+
subject: string;
|
|
11
|
+
tilte: ITextSegment[];
|
|
12
|
+
description?: ITextSegment[];
|
|
13
|
+
link: string;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* 展示搜索结果
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
export declare const SearchResult: React.FC<{
|
|
20
|
+
results: ISearchResult[];
|
|
21
|
+
}>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styles from "./SearchResult.module.less";
|
|
3
|
+
var getHighlightInfo = function getHighlightInfo(textSegments) {
|
|
4
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, textSegments.map(function (segment) {
|
|
5
|
+
return /*#__PURE__*/React.createElement("span", {
|
|
6
|
+
className: "".concat(styles.segment, " ").concat(segment.highlighted ? styles.highlighted : '')
|
|
7
|
+
}, segment.text);
|
|
8
|
+
}));
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* 展示搜索结果
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
export var SearchResult = function SearchResult(_ref) {
|
|
16
|
+
var results = _ref.results;
|
|
17
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
18
|
+
className: styles.searchResult
|
|
19
|
+
}, results.map(function (r) {
|
|
20
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
21
|
+
className: styles.item
|
|
22
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
23
|
+
className: styles.subject
|
|
24
|
+
}, r.subject), /*#__PURE__*/React.createElement("div", {
|
|
25
|
+
className: styles.br
|
|
26
|
+
}), /*#__PURE__*/React.createElement("a", {
|
|
27
|
+
className: styles.result,
|
|
28
|
+
href: r.link
|
|
29
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
30
|
+
className: styles.title
|
|
31
|
+
}, getHighlightInfo(r.tilte)), /*#__PURE__*/React.createElement("div", {
|
|
32
|
+
className: styles.description
|
|
33
|
+
}, getHighlightInfo(r.description))));
|
|
34
|
+
}));
|
|
35
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
.searchResult {
|
|
2
|
+
font-size: 12px;
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
align-items: center;
|
|
6
|
+
min-width: 486px;
|
|
7
|
+
max-width: 512px;
|
|
8
|
+
max-height: 50vh;
|
|
9
|
+
overflow-x: hidden;
|
|
10
|
+
overflow-y: auto;
|
|
11
|
+
|
|
12
|
+
.item {
|
|
13
|
+
width: 100%;
|
|
14
|
+
display: flex;
|
|
15
|
+
margin: 6px 0;
|
|
16
|
+
position: relative;
|
|
17
|
+
|
|
18
|
+
.subject {
|
|
19
|
+
text-align: right;
|
|
20
|
+
padding: 4px;
|
|
21
|
+
flex-basis: 120px;
|
|
22
|
+
color: rgb(160, 161, 167);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.br {
|
|
26
|
+
flex-basis: 1px;
|
|
27
|
+
margin: 0 6px;
|
|
28
|
+
background-color: #873bf4;
|
|
29
|
+
opacity: 0.2;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.result {
|
|
33
|
+
flex: 1;
|
|
34
|
+
min-width: 300px;
|
|
35
|
+
padding: 4px 0 4px 6px;
|
|
36
|
+
border-radius: 4px;
|
|
37
|
+
overflow: hidden;
|
|
38
|
+
cursor: pointer;
|
|
39
|
+
|
|
40
|
+
&:hover {
|
|
41
|
+
background-color: #f9f0ff;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.title {
|
|
45
|
+
font-weight: 500;
|
|
46
|
+
color: #000;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.description {
|
|
50
|
+
font-size: 11px;
|
|
51
|
+
color: rgb(160, 161, 167);
|
|
52
|
+
max-height: 55px;
|
|
53
|
+
overflow: hidden;
|
|
54
|
+
.segment {
|
|
55
|
+
padding-left: 1px;
|
|
56
|
+
padding-right: 1px;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.highlighted {
|
|
61
|
+
color: #873bf4;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dumi 搜索结果转页面 UI 的数据结构,默认取 30 条
|
|
3
|
+
* @param dumiResult
|
|
4
|
+
* @param limit
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
export function getSearchResults(dumiResults) {
|
|
8
|
+
var limit = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 30;
|
|
9
|
+
var hints = dumiResults.map(function (r) {
|
|
10
|
+
return r.hints;
|
|
11
|
+
}).flat();
|
|
12
|
+
return hints.slice(0, limit).map(function (_ref) {
|
|
13
|
+
var _ref$pageTitle = _ref.pageTitle,
|
|
14
|
+
pageTitle = _ref$pageTitle === void 0 ? '' : _ref$pageTitle,
|
|
15
|
+
highlightTitleTexts = _ref.highlightTitleTexts,
|
|
16
|
+
highlightTexts = _ref.highlightTexts,
|
|
17
|
+
link = _ref.link;
|
|
18
|
+
return {
|
|
19
|
+
link: link,
|
|
20
|
+
subject: pageTitle,
|
|
21
|
+
tilte: highlightTitleTexts,
|
|
22
|
+
description: highlightTexts
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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."); }
|
|
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
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import React, { useCallback, useEffect, useState } from 'react';
|
|
8
|
+
import { Popover } from 'antd';
|
|
9
|
+
import { useIntl, useSiteSearch } from 'dumi';
|
|
10
|
+
import { SearchOutlined } from '@ant-design/icons';
|
|
11
|
+
import { SearchResult } from "./SearchResult";
|
|
12
|
+
import { getSearchResults } from "./helper";
|
|
13
|
+
import styles from "./index.module.less";
|
|
14
|
+
export var Search = function Search() {
|
|
15
|
+
var intl = useIntl();
|
|
16
|
+
var _useState = useState(false),
|
|
17
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
18
|
+
open = _useState2[0],
|
|
19
|
+
setOpen = _useState2[1];
|
|
20
|
+
var onClose = useCallback(function () {
|
|
21
|
+
return setTimeout(function () {
|
|
22
|
+
return setOpen(false);
|
|
23
|
+
}, 60);
|
|
24
|
+
}, []);
|
|
25
|
+
var _useSiteSearch = useSiteSearch(),
|
|
26
|
+
keywords = _useSiteSearch.keywords,
|
|
27
|
+
setKeywords = _useSiteSearch.setKeywords,
|
|
28
|
+
result = _useSiteSearch.result;
|
|
29
|
+
useEffect(function () {
|
|
30
|
+
setOpen(!!(result !== null && result !== void 0 && result.length));
|
|
31
|
+
}, [result]);
|
|
32
|
+
return /*#__PURE__*/React.createElement(Popover, {
|
|
33
|
+
open: open,
|
|
34
|
+
placement: "topLeft",
|
|
35
|
+
content: /*#__PURE__*/React.createElement(SearchResult, {
|
|
36
|
+
results: getSearchResults(result)
|
|
37
|
+
})
|
|
38
|
+
}, /*#__PURE__*/React.createElement("label", {
|
|
39
|
+
className: styles.search
|
|
40
|
+
}, /*#__PURE__*/React.createElement(SearchOutlined, {
|
|
41
|
+
className: styles.icon
|
|
42
|
+
}), /*#__PURE__*/React.createElement("input", {
|
|
43
|
+
className: styles.input,
|
|
44
|
+
value: keywords,
|
|
45
|
+
autoComplete: "off",
|
|
46
|
+
onBlur: function onBlur() {
|
|
47
|
+
return onClose();
|
|
48
|
+
},
|
|
49
|
+
onFocus: function onFocus() {
|
|
50
|
+
return setOpen(!!(result !== null && result !== void 0 && result.length));
|
|
51
|
+
},
|
|
52
|
+
onChange: function onChange(e) {
|
|
53
|
+
return setKeywords(e.target.value);
|
|
54
|
+
},
|
|
55
|
+
placeholder: intl.formatMessage({
|
|
56
|
+
id: '搜索…'
|
|
57
|
+
})
|
|
58
|
+
})));
|
|
59
|
+
};
|
|
@@ -22,18 +22,10 @@
|
|
|
22
22
|
color: #a3b1bf;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
|
|
26
|
-
:global {
|
|
27
|
-
.DocSearch-Search-Icon {
|
|
28
|
-
width: 1em !important;
|
|
29
|
-
height: 1em !important;
|
|
30
|
-
color: #a3b1bf !important;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
25
|
}
|
|
34
26
|
|
|
35
27
|
@media only screen and (max-width: 931.99px) {
|
|
36
28
|
.search {
|
|
37
29
|
display: none;
|
|
38
30
|
}
|
|
39
|
-
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = Object.defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
|
3
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
4
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
5
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
6
|
+
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."); }
|
|
7
|
+
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); }
|
|
8
|
+
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; }
|
|
9
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
10
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
11
|
+
import { PlayCircleOutlined, PushpinOutlined } from '@ant-design/icons';
|
|
12
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
13
|
+
import styles from "./Preview.module.less";
|
|
14
|
+
import { safeEval } from "./utils";
|
|
15
|
+
function normalizeValue(node) {
|
|
16
|
+
return node instanceof Promise ? node : Promise.resolve(node);
|
|
17
|
+
}
|
|
18
|
+
function normalizeDOM(node) {
|
|
19
|
+
if (node instanceof HTMLElement || node instanceof SVGElement) return node;
|
|
20
|
+
var span = document.createElement('span');
|
|
21
|
+
span.textContent = node.toString();
|
|
22
|
+
return span;
|
|
23
|
+
}
|
|
24
|
+
function sizeOf(dom) {
|
|
25
|
+
if (dom.style.display === 'none') return {
|
|
26
|
+
width: 0,
|
|
27
|
+
height: 0
|
|
28
|
+
};
|
|
29
|
+
var parseInt10 = function parseInt10(d) {
|
|
30
|
+
return d ? parseInt(d) : 0;
|
|
31
|
+
};
|
|
32
|
+
var style = getComputedStyle(dom);
|
|
33
|
+
var wrapperWidth = dom.clientWidth || parseInt10(style.width);
|
|
34
|
+
var wrapperHeight = dom.clientHeight || parseInt10(style.height);
|
|
35
|
+
return {
|
|
36
|
+
width: wrapperWidth,
|
|
37
|
+
height: wrapperHeight
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
export var Preview = function Preview(_ref) {
|
|
41
|
+
var source = _ref.source,
|
|
42
|
+
code = _ref.code,
|
|
43
|
+
_ref$pin = _ref.pin,
|
|
44
|
+
pin = _ref$pin === void 0 ? true : _ref$pin;
|
|
45
|
+
var containerRef = useRef(null);
|
|
46
|
+
var ulRef = useRef(null);
|
|
47
|
+
var nodeRef = useRef(null);
|
|
48
|
+
var _useState = useState(false),
|
|
49
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
50
|
+
loading = _useState2[0],
|
|
51
|
+
setLoading = _useState2[1];
|
|
52
|
+
var _useState3 = useState(null),
|
|
53
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
54
|
+
error = _useState4[0],
|
|
55
|
+
setError = _useState4[1];
|
|
56
|
+
var _useState5 = useState(null),
|
|
57
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
58
|
+
node = _useState6[0],
|
|
59
|
+
setNode = _useState6[1];
|
|
60
|
+
function execute(_x2) {
|
|
61
|
+
return _execute.apply(this, arguments);
|
|
62
|
+
}
|
|
63
|
+
function _execute() {
|
|
64
|
+
_execute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(source) {
|
|
65
|
+
var value, rendered, n, _node;
|
|
66
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
67
|
+
while (1) switch (_context.prev = _context.next) {
|
|
68
|
+
case 0:
|
|
69
|
+
setError(null);
|
|
70
|
+
_context.prev = 1;
|
|
71
|
+
value = safeEval(source);
|
|
72
|
+
if (value instanceof Promise) setLoading(true);
|
|
73
|
+
rendered = normalizeValue(value);
|
|
74
|
+
_context.next = 7;
|
|
75
|
+
return rendered;
|
|
76
|
+
case 7:
|
|
77
|
+
n = _context.sent;
|
|
78
|
+
_node = normalizeDOM(n);
|
|
79
|
+
setNode(_node);
|
|
80
|
+
setLoading(false);
|
|
81
|
+
_context.next = 18;
|
|
82
|
+
break;
|
|
83
|
+
case 13:
|
|
84
|
+
_context.prev = 13;
|
|
85
|
+
_context.t0 = _context["catch"](1);
|
|
86
|
+
setLoading(false);
|
|
87
|
+
setError(_context.t0);
|
|
88
|
+
console.error(_context.t0);
|
|
89
|
+
case 18:
|
|
90
|
+
case "end":
|
|
91
|
+
return _context.stop();
|
|
92
|
+
}
|
|
93
|
+
}, _callee, null, [[1, 13]]);
|
|
94
|
+
}));
|
|
95
|
+
return _execute.apply(this, arguments);
|
|
96
|
+
}
|
|
97
|
+
function onPin() {
|
|
98
|
+
if (code.style.display === 'block' || code.style.display === '') {
|
|
99
|
+
code.style.display = 'none';
|
|
100
|
+
} else {
|
|
101
|
+
code.style.display = 'block';
|
|
102
|
+
}
|
|
103
|
+
updateToolHeight();
|
|
104
|
+
}
|
|
105
|
+
function onRun() {
|
|
106
|
+
execute(source);
|
|
107
|
+
}
|
|
108
|
+
function updateToolHeight() {
|
|
109
|
+
var _sizeOf = sizeOf(code),
|
|
110
|
+
codeHeight = _sizeOf.height;
|
|
111
|
+
var _sizeOf2 = sizeOf(containerRef.current),
|
|
112
|
+
nodeHeight = _sizeOf2.height;
|
|
113
|
+
var height = codeHeight + nodeHeight;
|
|
114
|
+
ulRef.current.style.height = height + 'px';
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// 执行代码
|
|
118
|
+
useEffect(function () {
|
|
119
|
+
execute(source);
|
|
120
|
+
}, [source]);
|
|
121
|
+
|
|
122
|
+
// 更新 node
|
|
123
|
+
useEffect(function () {
|
|
124
|
+
if (containerRef.current && node) {
|
|
125
|
+
var _nodeRef$current, _nodeRef$current$clea;
|
|
126
|
+
(_nodeRef$current = nodeRef.current) === null || _nodeRef$current === void 0 ? void 0 : (_nodeRef$current$clea = _nodeRef$current.clear) === null || _nodeRef$current$clea === void 0 ? void 0 : _nodeRef$current$clea.call(_nodeRef$current);
|
|
127
|
+
nodeRef.current = node;
|
|
128
|
+
var oldChild = containerRef.current.children[0];
|
|
129
|
+
if (oldChild) {
|
|
130
|
+
oldChild.replaceWith(node);
|
|
131
|
+
} else {
|
|
132
|
+
containerRef.current.appendChild(node);
|
|
133
|
+
}
|
|
134
|
+
updateToolHeight();
|
|
135
|
+
}
|
|
136
|
+
}, [node]);
|
|
137
|
+
|
|
138
|
+
// 销毁的时候调用 DOM 上的 clear 函数
|
|
139
|
+
useEffect(function () {
|
|
140
|
+
return function () {
|
|
141
|
+
var _nodeRef$current2, _nodeRef$current2$cle;
|
|
142
|
+
return (_nodeRef$current2 = nodeRef.current) === null || _nodeRef$current2 === void 0 ? void 0 : (_nodeRef$current2$cle = _nodeRef$current2.clear) === null || _nodeRef$current2$cle === void 0 ? void 0 : _nodeRef$current2$cle.call(_nodeRef$current2);
|
|
143
|
+
};
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// 是否需要隐藏代码
|
|
147
|
+
useEffect(function () {
|
|
148
|
+
if (pin !== false) return;
|
|
149
|
+
code.style.display = 'none';
|
|
150
|
+
}, [pin]);
|
|
151
|
+
|
|
152
|
+
// 暂时和隐藏 toolbar
|
|
153
|
+
useEffect(function () {
|
|
154
|
+
var enter = function enter() {
|
|
155
|
+
if (ulRef.current) {
|
|
156
|
+
ulRef.current.style.display = 'block';
|
|
157
|
+
code.style.borderBottomLeftRadius = '0px';
|
|
158
|
+
code.style.borderTopLeftRadius = '0px';
|
|
159
|
+
updateToolHeight();
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
var leave = function leave() {
|
|
163
|
+
if (ulRef.current) {
|
|
164
|
+
ulRef.current.style.display = '';
|
|
165
|
+
code.style.borderBottomLeftRadius = '';
|
|
166
|
+
code.style.borderTopLeftRadius = '';
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
code.addEventListener('mouseenter', enter);
|
|
170
|
+
code.addEventListener('mouseleave', leave);
|
|
171
|
+
if (containerRef.current) {
|
|
172
|
+
containerRef.current.addEventListener('mouseenter', enter);
|
|
173
|
+
containerRef.current.addEventListener('mouseleave', leave);
|
|
174
|
+
}
|
|
175
|
+
return function () {
|
|
176
|
+
code.removeEventListener('mouseenter', enter);
|
|
177
|
+
code.removeEventListener('mouseleave', leave);
|
|
178
|
+
if (containerRef.current) {
|
|
179
|
+
containerRef.current.removeEventListener('mouseenter', enter);
|
|
180
|
+
containerRef.current.removeEventListener('mouseleave', leave);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
}, []);
|
|
184
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
185
|
+
className: styles.preview
|
|
186
|
+
}, loading ? /*#__PURE__*/React.createElement("div", {
|
|
187
|
+
className: styles.loading
|
|
188
|
+
}, "running...") : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
|
|
189
|
+
ref: containerRef,
|
|
190
|
+
className: styles.main
|
|
191
|
+
}, error && /*#__PURE__*/React.createElement("span", {
|
|
192
|
+
className: styles.error
|
|
193
|
+
}, error.toString())), /*#__PURE__*/React.createElement("ul", {
|
|
194
|
+
className: styles.ul,
|
|
195
|
+
ref: ulRef
|
|
196
|
+
}, /*#__PURE__*/React.createElement("li", {
|
|
197
|
+
onClick: onPin,
|
|
198
|
+
className: styles.li
|
|
199
|
+
}, /*#__PURE__*/React.createElement(PushpinOutlined, null)), /*#__PURE__*/React.createElement("li", {
|
|
200
|
+
onClick: onRun,
|
|
201
|
+
className: styles.li
|
|
202
|
+
}, /*#__PURE__*/React.createElement(PlayCircleOutlined, null)))));
|
|
203
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
@tool-width: 28px;
|
|
2
|
+
|
|
3
|
+
.preview {
|
|
4
|
+
position: relative;
|
|
5
|
+
|
|
6
|
+
.ul {
|
|
7
|
+
position: absolute;
|
|
8
|
+
list-style: none;
|
|
9
|
+
padding: 0;
|
|
10
|
+
margin: 0;
|
|
11
|
+
margin-left: -@tool-width;
|
|
12
|
+
left: 0;
|
|
13
|
+
top: 0;
|
|
14
|
+
display: none;
|
|
15
|
+
background: #eee;
|
|
16
|
+
width: @tool-width;
|
|
17
|
+
border-bottom-left-radius: 4px;
|
|
18
|
+
border-top-left-radius: 4px;
|
|
19
|
+
|
|
20
|
+
.li {
|
|
21
|
+
list-style-type: none !important;
|
|
22
|
+
cursor: pointer;
|
|
23
|
+
margin: 0 !important;
|
|
24
|
+
padding: 0 !important;
|
|
25
|
+
display: flex;
|
|
26
|
+
align-items: center;
|
|
27
|
+
justify-content: center;
|
|
28
|
+
width: @tool-width;
|
|
29
|
+
height: @tool-width;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.li:hover {
|
|
33
|
+
color: #873bf4;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.li:active {
|
|
37
|
+
transform: scale(1.1);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.ul:hover {
|
|
42
|
+
display: block;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.loading {
|
|
46
|
+
display: block;
|
|
47
|
+
color: #873bf4;
|
|
48
|
+
padding: 0.25rem 0;
|
|
49
|
+
border-left: 3px solid #873bf4;
|
|
50
|
+
padding-left: 12px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.error {
|
|
54
|
+
display: block;
|
|
55
|
+
color: #fb1716;
|
|
56
|
+
padding: 0.25rem 0;
|
|
57
|
+
border-left: 3px solid #ff0000;
|
|
58
|
+
padding-left: 12px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
}
|
|
62
|
+
|
|
@@ -11,21 +11,22 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
11
11
|
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; }
|
|
12
12
|
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
13
13
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
14
|
+
import { MenuFoldOutlined, MenuUnfoldOutlined, VerticalAlignTopOutlined } from '@ant-design/icons';
|
|
15
|
+
import { Affix, BackTop, Layout, Menu } from 'antd';
|
|
16
|
+
import { useFullSidebarData, useLocale, useRouteMeta, useSiteData } from 'dumi';
|
|
17
|
+
import Drawer from 'rc-drawer';
|
|
14
18
|
import React, { useEffect, useState } from 'react';
|
|
15
|
-
import {
|
|
19
|
+
import { useNavigate } from 'react-router-dom';
|
|
16
20
|
import { useMedia } from 'react-use';
|
|
17
|
-
import Drawer from 'rc-drawer';
|
|
18
|
-
import { useLocale, useSiteData, useFullSidebarData, useRouteMeta } from 'dumi';
|
|
19
|
-
import { useNavigate } from "react-router-dom";
|
|
20
|
-
import { MenuFoldOutlined, MenuUnfoldOutlined, VerticalAlignTopOutlined } from '@ant-design/icons';
|
|
21
21
|
import readingTime from 'reading-time';
|
|
22
22
|
import URI from 'uri-parse';
|
|
23
|
+
import { ContentTable } from "dumi/theme/slots/ContentTable";
|
|
23
24
|
import { SEO } from "dumi/theme/slots/SEO";
|
|
24
|
-
import {
|
|
25
|
+
import { useScrollToTop } from "../hooks";
|
|
25
26
|
import { NavigatorBanner } from "./NavigatorBanner";
|
|
26
27
|
import ReadingTime from "./ReadingTime";
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
28
|
+
import { usePreview } from "./usePreview";
|
|
29
|
+
import { getBaseRoute, getIndexRoute, getNavigateUrl, getOpenKeys } from "./utils";
|
|
29
30
|
import 'rc-drawer/assets/index.css';
|
|
30
31
|
import styles from "./index.module.less";
|
|
31
32
|
/**
|
|
@@ -78,7 +79,7 @@ export var ManualContent = function ManualContent(_ref) {
|
|
|
78
79
|
// 递归
|
|
79
80
|
rootList.forEach(function (item) {
|
|
80
81
|
var href = (!baseRoute.startsWith('/en') ? "/".concat(item.slug) : "/en/".concat(item.slug)).toLocaleLowerCase();
|
|
81
|
-
var id = href.split(
|
|
82
|
+
var id = href.split('/').slice(0, href.split('/').length - 1).join('/');
|
|
82
83
|
if (href.includes(baseRoute)) {
|
|
83
84
|
if (id === hrefId) {
|
|
84
85
|
list.push(_objectSpread(_objectSpread({}, item), {}, {
|
|
@@ -193,6 +194,7 @@ export var ManualContent = function ManualContent(_ref) {
|
|
|
193
194
|
// 监听选中的menu-item 拿到 prev and next
|
|
194
195
|
getPreAndNext();
|
|
195
196
|
}, [defaultSelectedKey]);
|
|
197
|
+
usePreview();
|
|
196
198
|
function getPreAndNext() {
|
|
197
199
|
var menuNodes = document.querySelectorAll('aside .ant-menu-item');
|
|
198
200
|
var currentMenuNode = document.querySelector('aside .ant-menu-item-selected');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function usePreview(options?: {}): void;
|