@antv/dumi-theme-antv 0.3.7 → 0.3.10

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.
@@ -0,0 +1,8 @@
1
+ import type { ISearchResult } from './SearchResult';
2
+ /**
3
+ * dumi 搜索结果转页面 UI 的数据结构,默认取 30 条
4
+ * @param dumiResult
5
+ * @param limit
6
+ * @returns
7
+ */
8
+ export declare function getSearchResults(dumiResults: any[], limit?: number): ISearchResult[];
@@ -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,2 @@
1
+ /// <reference types="react" />
2
+ export declare const Search: () => JSX.Element;
@@ -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,7 @@
1
+ import { FC } from 'react';
2
+ export declare type PreviewProps = {
3
+ source: string;
4
+ pin: string;
5
+ code: HTMLDivElement;
6
+ };
7
+ export declare const Preview: FC<any>;
@@ -0,0 +1,204 @@
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
+ function normalizeValue(node) {
15
+ return node instanceof Promise ? node : Promise.resolve(node);
16
+ }
17
+ function normalizeDOM(node) {
18
+ if (node instanceof HTMLElement || node instanceof SVGElement) return node;
19
+ var span = document.createElement('span');
20
+ span.textContent = node.toString();
21
+ return span;
22
+ }
23
+ function safeEval(source) {
24
+ return new Function("return ".concat(source))();
25
+ }
26
+ function sizeOf(dom) {
27
+ if (dom.style.display === 'none') return {
28
+ width: 0,
29
+ height: 0
30
+ };
31
+ var parseInt10 = function parseInt10(d) {
32
+ return d ? parseInt(d) : 0;
33
+ };
34
+ var style = getComputedStyle(dom);
35
+ var wrapperWidth = dom.clientWidth || parseInt10(style.width);
36
+ var wrapperHeight = dom.clientHeight || parseInt10(style.height);
37
+ return {
38
+ width: wrapperWidth,
39
+ height: wrapperHeight
40
+ };
41
+ }
42
+ export var Preview = function Preview(_ref) {
43
+ var source = _ref.source,
44
+ code = _ref.code,
45
+ _pin = _ref._pin;
46
+ var containerRef = useRef(null);
47
+ var ulRef = useRef(null);
48
+ var nodeRef = useRef(null);
49
+ var _useState = useState(false),
50
+ _useState2 = _slicedToArray(_useState, 2),
51
+ loading = _useState2[0],
52
+ setLoading = _useState2[1];
53
+ var _useState3 = useState(null),
54
+ _useState4 = _slicedToArray(_useState3, 2),
55
+ error = _useState4[0],
56
+ setError = _useState4[1];
57
+ var _useState5 = useState(null),
58
+ _useState6 = _slicedToArray(_useState5, 2),
59
+ node = _useState6[0],
60
+ setNode = _useState6[1];
61
+ function execute(_x2) {
62
+ return _execute.apply(this, arguments);
63
+ }
64
+ function _execute() {
65
+ _execute = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(source) {
66
+ var value, rendered, n, _node;
67
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
68
+ while (1) switch (_context.prev = _context.next) {
69
+ case 0:
70
+ setError(null);
71
+ _context.prev = 1;
72
+ value = safeEval(source);
73
+ if (value instanceof Promise) setLoading(true);
74
+ rendered = normalizeValue(value);
75
+ _context.next = 7;
76
+ return rendered;
77
+ case 7:
78
+ n = _context.sent;
79
+ _node = normalizeDOM(n);
80
+ setNode(_node);
81
+ setLoading(false);
82
+ _context.next = 18;
83
+ break;
84
+ case 13:
85
+ _context.prev = 13;
86
+ _context.t0 = _context["catch"](1);
87
+ setLoading(false);
88
+ setError(_context.t0);
89
+ console.error(_context.t0);
90
+ case 18:
91
+ case "end":
92
+ return _context.stop();
93
+ }
94
+ }, _callee, null, [[1, 13]]);
95
+ }));
96
+ return _execute.apply(this, arguments);
97
+ }
98
+ function onPin() {
99
+ if (code.style.display === 'block' || code.style.display === '') {
100
+ code.style.display = 'none';
101
+ } else {
102
+ code.style.display = 'block';
103
+ }
104
+ updateToolHeight();
105
+ }
106
+ function onRun() {
107
+ execute(source);
108
+ }
109
+ function updateToolHeight() {
110
+ var _sizeOf = sizeOf(code),
111
+ codeHeight = _sizeOf.height;
112
+ var _sizeOf2 = sizeOf(containerRef.current),
113
+ nodeHeight = _sizeOf2.height;
114
+ var height = codeHeight + nodeHeight;
115
+ ulRef.current.style.height = height + 'px';
116
+ }
117
+
118
+ // 执行代码
119
+ useEffect(function () {
120
+ execute(source);
121
+ }, [source]);
122
+
123
+ // 更新 node
124
+ useEffect(function () {
125
+ if (containerRef.current && node) {
126
+ var _nodeRef$current, _nodeRef$current$clea;
127
+ (_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);
128
+ nodeRef.current = node;
129
+ var oldChild = containerRef.current.children[0];
130
+ if (oldChild) {
131
+ oldChild.replaceWith(node);
132
+ } else {
133
+ containerRef.current.appendChild(node);
134
+ }
135
+ updateToolHeight();
136
+ }
137
+ }, [node]);
138
+
139
+ // 销毁的时候调用 DOM 上的 clear 函数
140
+ useEffect(function () {
141
+ return function () {
142
+ var _nodeRef$current2, _nodeRef$current2$cle;
143
+ 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);
144
+ };
145
+ });
146
+
147
+ // 是否需要隐藏代码
148
+ useEffect(function () {
149
+ if (_pin !== 'false') return;
150
+ code.style.display = 'none';
151
+ }, [_pin]);
152
+
153
+ // 暂时和隐藏 toolbar
154
+ useEffect(function () {
155
+ var enter = function enter() {
156
+ if (ulRef.current) {
157
+ ulRef.current.style.display = 'block';
158
+ code.style.borderBottomLeftRadius = '0px';
159
+ code.style.borderTopLeftRadius = '0px';
160
+ updateToolHeight();
161
+ }
162
+ };
163
+ var leave = function leave() {
164
+ if (ulRef.current) {
165
+ ulRef.current.style.display = '';
166
+ code.style.borderBottomLeftRadius = '';
167
+ code.style.borderTopLeftRadius = '';
168
+ }
169
+ };
170
+ code.addEventListener('mouseenter', enter);
171
+ code.addEventListener('mouseleave', leave);
172
+ if (containerRef.current) {
173
+ containerRef.current.addEventListener('mouseenter', enter);
174
+ containerRef.current.addEventListener('mouseleave', leave);
175
+ }
176
+ return function () {
177
+ code.removeEventListener('mouseenter', enter);
178
+ code.removeEventListener('mouseleave', leave);
179
+ if (containerRef.current) {
180
+ containerRef.current.removeEventListener('mouseenter', enter);
181
+ containerRef.current.removeEventListener('mouseleave', leave);
182
+ }
183
+ };
184
+ }, []);
185
+ return /*#__PURE__*/React.createElement("div", {
186
+ className: styles.preview
187
+ }, loading ? /*#__PURE__*/React.createElement("div", {
188
+ className: styles.loading
189
+ }, "running...") : /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("div", {
190
+ ref: containerRef,
191
+ className: styles.main
192
+ }, error && /*#__PURE__*/React.createElement("span", {
193
+ className: styles.error
194
+ }, error.toString())), /*#__PURE__*/React.createElement("ul", {
195
+ className: styles.ul,
196
+ ref: ulRef
197
+ }, /*#__PURE__*/React.createElement("li", {
198
+ onClick: onPin,
199
+ className: styles.li
200
+ }, /*#__PURE__*/React.createElement(PushpinOutlined, null)), /*#__PURE__*/React.createElement("li", {
201
+ onClick: onRun,
202
+ className: styles.li
203
+ }, /*#__PURE__*/React.createElement(PlayCircleOutlined, null)))));
204
+ };
@@ -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 { Layout, Affix, BackTop, Menu } from 'antd';
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 { getBaseRoute, getIndexRoute, getOpenKeys, getNavigateUrl } from "./utils";
25
+ import { useScrollToTop } from "../hooks";
25
26
  import { NavigatorBanner } from "./NavigatorBanner";
26
27
  import ReadingTime from "./ReadingTime";
27
- import { ContentTable } from "dumi/theme/slots/ContentTable";
28
- import { useScrollToTop } from "../hooks";
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("/").slice(0, href.split("/").length - 1).join("/");
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;
@@ -0,0 +1,89 @@
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
+ function optionsOf(p) {
9
+ var keys = ['_pin', '_only'];
10
+ return Object.fromEntries(keys.map(function (key) {
11
+ return [key, p.getAttribute(key)];
12
+ }));
13
+ }
14
+ function sourceOf(block) {
15
+ var cloned = block.cloneNode(true);
16
+ // 去掉 comments
17
+ var comments = Array.from(cloned.querySelectorAll('.comment'));
18
+ comments.forEach(function (comment) {
19
+ return comment.remove();
20
+ });
21
+ return cloned.textContent;
22
+ }
23
+ export function usePreview() {
24
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
25
+ useEffect(function () {
26
+ var blocks = Array.from(document.querySelectorAll('.markdown .preview + .dumi-default-source-code'));
27
+
28
+ // 过滤实际展示的 block
29
+ var I = Array.from({
30
+ length: blocks.length
31
+ }, function (_, i) {
32
+ return i;
33
+ });
34
+ var OI = I.filter(function (i) {
35
+ var p = blocks[i].previousSibling;
36
+ var options = optionsOf(p);
37
+ var _only = options._only;
38
+ return _only === 'true';
39
+ });
40
+ var FI = OI.length === 0 ? I : OI;
41
+
42
+ // 将 p 标签替换成渲染后结果
43
+ var W = [];
44
+ var P = [];
45
+ var _iterator = _createForOfIteratorHelper(FI),
46
+ _step;
47
+ try {
48
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
49
+ var i = _step.value;
50
+ var block = blocks[i];
51
+ var source = sourceOf(block);
52
+ var p = block.previousSibling;
53
+
54
+ // 渲染并且挂载代码运行结果
55
+ var wrapper = document.createElement('div');
56
+ var _options = optionsOf(p);
57
+ var root = createRoot(wrapper);
58
+ root.render( /*#__PURE__*/React.createElement(Preview, _extends({
59
+ source: source,
60
+ code: block
61
+ }, _options)));
62
+ p.replaceWith(wrapper);
63
+ W[i] = wrapper;
64
+ P[i] = p;
65
+ }
66
+ } catch (err) {
67
+ _iterator.e(err);
68
+ } finally {
69
+ _iterator.f();
70
+ }
71
+ return function () {
72
+ // 复原
73
+ var _iterator2 = _createForOfIteratorHelper(FI),
74
+ _step2;
75
+ try {
76
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
77
+ var i = _step2.value;
78
+ var wrapper = W[i];
79
+ var p = P[i];
80
+ wrapper.replaceWith(p);
81
+ }
82
+ } catch (err) {
83
+ _iterator2.e(err);
84
+ } finally {
85
+ _iterator2.f();
86
+ }
87
+ };
88
+ });
89
+ }
@@ -25,11 +25,22 @@ function _ping() {
25
25
  });
26
26
  network = new Promise(function (resolve) {
27
27
  var url = 'https://private-a' + 'lipay' + 'objects.alip' + 'ay.com/alip' + 'ay-rmsdeploy-image/rmsportal/RKuAiriJqrUhyqW.png';
28
- fetch(url).then(function (resp) {
29
- return resolve(resp.status === 200 ? 'responded' : 'error');
30
- });
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;
31
40
  });
32
- return _context.abrupt("return", Promise.race([timeout, network]));
41
+ return _context.abrupt("return", Promise.race([timeout, network]).catch(function (r) {
42
+ return 'error';
43
+ }));
33
44
  case 3:
34
45
  case "end":
35
46
  return _context.stop();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@antv/dumi-theme-antv",
3
- "version": "0.3.7",
3
+ "version": "0.3.10",
4
4
  "description": "AntV website theme based on dumi2.",
5
5
  "types": "dist/types.d.ts",
6
6
  "scripts": {
@@ -61,8 +61,8 @@
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",
@@ -90,7 +90,7 @@
90
90
  "video-react": "^0.16.0"
91
91
  },
92
92
  "peerDependencies": {
93
- "dumi": "^2.0.0-beta.15",
93
+ "dumi": "^2.0.0",
94
94
  "react": ">=16.9.0",
95
95
  "react-dom": ">=16.9.0"
96
96
  },
@@ -106,6 +106,7 @@
106
106
  "@types/react-router-dom": "^5.3.3",
107
107
  "@types/react-slick": "^0.23.10",
108
108
  "@umijs/lint": "^4.0.0",
109
+ "dumi": "^2.0.0",
109
110
  "eslint": "^8.23.0",
110
111
  "father": "^4.1.0",
111
112
  "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;