@antv/dumi-theme-antv 0.8.3 → 0.8.5
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/components/AI/HomeDialog/index.js +3 -2
- package/dist/layouts/GlobalLayout/index.js +1 -1
- package/dist/slots/CodeEditor/Toolbar.js +3 -13
- package/dist/slots/CodeEditor/index.js +191 -184
- package/dist/slots/CodeEditor/utils.js +1 -0
- package/dist/slots/CodeRunner/index.js +0 -5
- package/dist/slots/Header/Search/SearchResult.js +1 -49
- package/package.json +10 -17
|
@@ -27,8 +27,9 @@ export function HomeDialog(props) {
|
|
|
27
27
|
_fileSummary = _useState4[0],
|
|
28
28
|
setFileSummary = _useState4[1];
|
|
29
29
|
var handleConfirm = function handleConfirm() {
|
|
30
|
-
//
|
|
31
|
-
var
|
|
30
|
+
// 在新标签页打开新站点,携带问题参数,并将选择的技术栈拼接在消息前面
|
|
31
|
+
var libPrefix = snap.lib ? lang === 'zh' ? "\u4F7F\u7528".concat(snap.lib, "\u65F6\uFF0C") : "When using ".concat(snap.lib, ", ") : '';
|
|
32
|
+
var encodedMessage = encodeURIComponent("".concat(libPrefix).concat(promptText));
|
|
32
33
|
var targetUrl = "https://sive.antv.antgroup.com/qa?message=".concat(encodedMessage);
|
|
33
34
|
window.open(targetUrl, '_blank', 'noopener,noreferrer');
|
|
34
35
|
};
|
|
@@ -13,7 +13,7 @@ var GlobalLayout = function GlobalLayout() {
|
|
|
13
13
|
if (typeof window !== 'undefined') {
|
|
14
14
|
window.antd = antd;
|
|
15
15
|
}
|
|
16
|
-
console.log("%c @antv/dumi-theme-antv %c ".concat("0.8.
|
|
16
|
+
console.log("%c @antv/dumi-theme-antv %c ".concat("0.8.5", " %c"), 'background:#35495e; padding: 1px; border-radius: 3px 0 0 3px; color: #fff;', 'background:#41b883; padding: 1px; border-radius: 0 3px 3px 0; color: #fff;', 'background:transparent;');
|
|
17
17
|
}, []);
|
|
18
18
|
return outlet && /*#__PURE__*/React.createElement(QueryClientProvider, {
|
|
19
19
|
client: queryClient
|
|
@@ -16,12 +16,12 @@ import { Tooltip, Typography } from 'antd';
|
|
|
16
16
|
import { FormattedMessage, useLocale } from 'dumi';
|
|
17
17
|
import React, { useEffect, useState } from 'react';
|
|
18
18
|
import { ping } from "../utils";
|
|
19
|
-
import { extractImportDeps,
|
|
19
|
+
import { extractImportDeps, getRiddleConfig, getStackblitzConfig } from "./utils";
|
|
20
20
|
import styles from "./Toolbar.module.less";
|
|
21
21
|
var Paragraph = Typography.Paragraph;
|
|
22
22
|
export var EDITOR_TABS = /*#__PURE__*/function (EDITOR_TABS) {
|
|
23
|
-
EDITOR_TABS["JAVASCRIPT"] = "JavaScript";
|
|
24
23
|
EDITOR_TABS["SPEC"] = "Spec";
|
|
24
|
+
EDITOR_TABS["API"] = "API";
|
|
25
25
|
EDITOR_TABS["DATA"] = "Data";
|
|
26
26
|
return EDITOR_TABS;
|
|
27
27
|
}({});
|
|
@@ -30,17 +30,11 @@ export var Toolbar = function Toolbar(_ref) {
|
|
|
30
30
|
fileExtension = _ref.fileExtension,
|
|
31
31
|
_ref$playground = _ref.playground,
|
|
32
32
|
playground = _ref$playground === void 0 ? {} : _ref$playground,
|
|
33
|
-
location = _ref.location,
|
|
34
33
|
_ref$title = _ref.title,
|
|
35
34
|
title = _ref$title === void 0 ? '' : _ref$title,
|
|
36
|
-
_ref$isFullScreen = _ref.isFullScreen,
|
|
37
|
-
isFullScreen = _ref$isFullScreen === void 0 ? false : _ref$isFullScreen,
|
|
38
35
|
editorTabs = _ref.editorTabs,
|
|
39
|
-
slots = _ref.slots,
|
|
40
36
|
currentEditorTab = _ref.currentEditorTab,
|
|
41
37
|
onEditorTabChange = _ref.onEditorTabChange,
|
|
42
|
-
_ref$onToggleFullscre = _ref.onToggleFullscreen,
|
|
43
|
-
onToggleFullscreen = _ref$onToggleFullscre === void 0 ? null : _ref$onToggleFullscre,
|
|
44
38
|
onExecuteCode = _ref.onExecuteCode,
|
|
45
39
|
onClickAI = _ref.onClickAI,
|
|
46
40
|
onReload = _ref.onReload,
|
|
@@ -52,11 +46,8 @@ export var Toolbar = function Toolbar(_ref) {
|
|
|
52
46
|
// 使用 playground.dependencies 定义的版本号
|
|
53
47
|
var dependencies = _objectSpread(_objectSpread({}, extractImportDeps(sourceCode)), playground.dependencies);
|
|
54
48
|
var devDependencies = playground.devDependencies || {};
|
|
55
|
-
var codeSandboxConfig = getCodeSandboxConfig(exampleTitle, sourceCode, fileExtension, dependencies, devDependencies, playground);
|
|
56
49
|
var riddlePrefillConfig = getRiddleConfig(exampleTitle, sourceCode, fileExtension, dependencies, devDependencies, playground);
|
|
57
50
|
var stackblitzPrefillConfig = getStackblitzConfig(exampleTitle, sourceCode, fileExtension, dependencies, devDependencies, playground);
|
|
58
|
-
// const htmlCode = getHtmlCodeTemplate(exampleTitle, sourceCode, fileExtension, dependencies, devDependencies, playground);
|
|
59
|
-
|
|
60
51
|
var _useState = useState(false),
|
|
61
52
|
_useState2 = _slicedToArray(_useState, 2),
|
|
62
53
|
riddleVisible = _useState2[0],
|
|
@@ -73,14 +64,13 @@ export var Toolbar = function Toolbar(_ref) {
|
|
|
73
64
|
}, /*#__PURE__*/React.createElement("div", {
|
|
74
65
|
className: styles.editortabs
|
|
75
66
|
}, editorTabs.map(function (tab, index) {
|
|
76
|
-
var slot = slots[tab];
|
|
77
67
|
return /*#__PURE__*/React.createElement("span", {
|
|
78
68
|
key: index,
|
|
79
69
|
className: tab === currentEditorTab ? styles.current : '',
|
|
80
70
|
onClick: function onClick() {
|
|
81
71
|
return onEditorTabChange(tab);
|
|
82
72
|
}
|
|
83
|
-
}, tab
|
|
73
|
+
}, tab);
|
|
84
74
|
})), showAI ? /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("a", {
|
|
85
75
|
className: styles.ai,
|
|
86
76
|
onClick: onClickAI
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
2
|
-
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); } }
|
|
3
|
-
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); }); }; }
|
|
4
1
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
5
2
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
6
3
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
7
4
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
5
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
6
|
+
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 e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
7
|
+
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); } }
|
|
8
|
+
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); }); }; }
|
|
9
9
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
10
10
|
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."); }
|
|
11
11
|
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); }
|
|
@@ -13,12 +13,12 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
|
|
|
13
13
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
14
14
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
15
15
|
import MonacoEditor, { loader } from '@monaco-editor/react';
|
|
16
|
-
import { Switch } from 'antd';
|
|
17
16
|
import { autoType as d3AutoType, dsvFormat } from 'd3-dsv';
|
|
18
17
|
import { useLocale, useSiteData } from 'dumi';
|
|
19
18
|
import { debounce, noop } from 'lodash-es';
|
|
20
19
|
import { format } from 'prettier';
|
|
21
20
|
import parserBabel from 'prettier/parser-babel';
|
|
21
|
+
import { useMemoizedFn } from 'ahooks';
|
|
22
22
|
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
23
23
|
import { bind, clear } from 'size-sensor';
|
|
24
24
|
import Loading from "dumi/theme/slots/Loading";
|
|
@@ -35,8 +35,41 @@ loader.config({
|
|
|
35
35
|
vs: 'https://gw.alipayobjects.com/os/lib/monaco-editor/0.34.0/min/vs'
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
+
|
|
39
|
+
// ---- 纯工具函数,不依赖组件状态,提取到组件外部避免重复创建 ----
|
|
40
|
+
|
|
41
|
+
/** 将 JSON 中的 <func>...</func> 标记还原为真实函数代码 */
|
|
42
|
+
function parseFunction(str) {
|
|
43
|
+
return str.replace(/"<func>(.*?)<\/func>"/g, function (_, code) {
|
|
44
|
+
return code.replace(/\\n/g, '\n').replace(/\\"/g, '"');
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** JSON.stringify replacer:将 function 值标记为 <func>...</func> 以便后续还原 */
|
|
49
|
+
function withFunction(_, value) {
|
|
50
|
+
if (typeof value !== 'function') return value;
|
|
51
|
+
return "<func>".concat(value.toString(), "</func>");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** 将 spec 配置对象转换为完整可执行的 JS 代码字符串 */
|
|
55
|
+
function specToCode(specObj) {
|
|
56
|
+
var specStr = parseFunction(JSON.stringify(specObj, withFunction));
|
|
57
|
+
var fullCode = "import { Chart } from '@antv/g2';\n\nconst chart = new Chart({ container: 'container' });\n\nchart.options(".concat(specStr, ");\n\nchart.render();\n");
|
|
58
|
+
return format(fullCode, {
|
|
59
|
+
plugins: [parserBabel]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ---- 组件类型定义 ----
|
|
64
|
+
|
|
38
65
|
/**
|
|
39
66
|
* 代码编辑器
|
|
67
|
+
* showSpecTab=true 时为 Spec first 模式:
|
|
68
|
+
* - Spec tab(可编辑):spec 风格代码,选中时用此代码执行
|
|
69
|
+
* - API tab(可编辑):原始 JS 代码,选中时用此代码执行
|
|
70
|
+
* - 两个 tab 各自独立维护代码状态
|
|
71
|
+
* showSpecTab=false 时为传统模式:
|
|
72
|
+
* - 只有 Spec tab,直接编辑和执行 source 代码
|
|
40
73
|
*/
|
|
41
74
|
var CodeEditor = function CodeEditor(_ref) {
|
|
42
75
|
var _ref$title = _ref.title,
|
|
@@ -47,7 +80,6 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
47
80
|
playground = _ref.playground,
|
|
48
81
|
_ref$replaceId = _ref.replaceId,
|
|
49
82
|
replaceId = _ref$replaceId === void 0 ? 'container' : _ref$replaceId,
|
|
50
|
-
isFullscreen = _ref.isFullscreen,
|
|
51
83
|
exampleId = _ref.exampleId,
|
|
52
84
|
_ref$onReady = _ref.onReady,
|
|
53
85
|
onReady = _ref$onReady === void 0 ? noop : _ref$onReady,
|
|
@@ -55,8 +87,6 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
55
87
|
onDestroy = _ref$onDestroy === void 0 ? noop : _ref$onDestroy,
|
|
56
88
|
_ref$onError = _ref.onError,
|
|
57
89
|
onError = _ref$onError === void 0 ? noop : _ref$onError,
|
|
58
|
-
_ref$onFullscreen = _ref.onFullscreen,
|
|
59
|
-
onFullscreen = _ref$onFullscreen === void 0 ? noop : _ref$onFullscreen,
|
|
60
90
|
_ref$showAI = _ref.showAI,
|
|
61
91
|
showAI = _ref$showAI === void 0 ? true : _ref$showAI,
|
|
62
92
|
style = _ref.style;
|
|
@@ -69,40 +99,35 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
69
99
|
showSpecTab = _themeConfig$showSpec === void 0 ? false : _themeConfig$showSpec;
|
|
70
100
|
var _themeConfig$playgrou = themeConfig.playground.playgroundBeforeExecute,
|
|
71
101
|
playgroundBeforeExecute = _themeConfig$playgrou === void 0 ? '' : _themeConfig$playgrou;
|
|
72
|
-
// 编辑器两个 tab,分别是代码和数据
|
|
73
102
|
var _useState = useState(null),
|
|
74
103
|
_useState2 = _slicedToArray(_useState, 2),
|
|
75
104
|
data = _useState2[0],
|
|
76
105
|
setData = _useState2[1];
|
|
106
|
+
// Spec tab 的代码(仅 showSpecTab=true 时使用,由 spec 事件初始化)
|
|
77
107
|
var _useState3 = useState(null),
|
|
78
108
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
79
|
-
|
|
80
|
-
|
|
109
|
+
specCode = _useState4[0],
|
|
110
|
+
setSpecCode = _useState4[1];
|
|
111
|
+
// API tab 的代码(传统模式下也作为唯一代码源)
|
|
81
112
|
var _useState5 = useState(source),
|
|
82
113
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
var _useState7 = useState(false),
|
|
86
|
-
_useState8 = _slicedToArray(_useState7, 2),
|
|
87
|
-
full = _useState8[0],
|
|
88
|
-
setFull = _useState8[1];
|
|
114
|
+
apiCode = _useState6[0],
|
|
115
|
+
setApiCode = _useState6[1];
|
|
89
116
|
// monaco instance
|
|
90
117
|
var monacoRef = useRef(null);
|
|
91
118
|
// 文件后缀
|
|
92
119
|
var fileExtension = relativePath.split('.')[relativePath.split('.').length - 1] || 'js';
|
|
93
120
|
// 菜单栏
|
|
94
|
-
var
|
|
95
|
-
|
|
96
|
-
editorTabs =
|
|
97
|
-
setEditorTabs =
|
|
121
|
+
var _useState7 = useState([]),
|
|
122
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
123
|
+
editorTabs = _useState8[0],
|
|
124
|
+
setEditorTabs = _useState8[1];
|
|
98
125
|
// 当前选中菜单栏
|
|
99
|
-
var
|
|
100
|
-
|
|
101
|
-
currentEditorTab =
|
|
102
|
-
setCurrentEditorTab =
|
|
126
|
+
var _useState9 = useState(EDITOR_TABS.SPEC),
|
|
127
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
128
|
+
currentEditorTab = _useState10[0],
|
|
129
|
+
setCurrentEditorTab = _useState10[1];
|
|
103
130
|
var containerId = "playgroundScriptContainer_".concat(exampleId);
|
|
104
|
-
|
|
105
|
-
// 出发 auto resize
|
|
106
131
|
var dispatchResizeEvent = function dispatchResizeEvent() {
|
|
107
132
|
var e = new Event('resize');
|
|
108
133
|
window.dispatchEvent(e);
|
|
@@ -111,19 +136,17 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
111
136
|
if (e) {
|
|
112
137
|
console.log(e);
|
|
113
138
|
onError(e);
|
|
114
|
-
e.preventDefault
|
|
139
|
+
if (e.preventDefault) e.preventDefault();
|
|
115
140
|
} else {
|
|
116
141
|
onError(null);
|
|
117
142
|
}
|
|
118
143
|
}, []);
|
|
144
|
+
|
|
145
|
+
// 注册全局错误捕获
|
|
119
146
|
useEffect(function () {
|
|
120
|
-
// 用于上报错误信息,使用 script 执行代码
|
|
121
147
|
if (typeof window !== 'undefined') {
|
|
122
|
-
// Cath error of code.
|
|
123
148
|
window.__reportErrorInPlayground = reportError;
|
|
124
|
-
// Catch error of timeout/raf.
|
|
125
149
|
window.onerror = reportError;
|
|
126
|
-
// Catch error of promise.
|
|
127
150
|
window.addEventListener('unhandledrejection', reportError);
|
|
128
151
|
}
|
|
129
152
|
return function () {
|
|
@@ -134,99 +157,56 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
134
157
|
}
|
|
135
158
|
};
|
|
136
159
|
}, []);
|
|
137
|
-
|
|
160
|
+
|
|
161
|
+
// 编译并执行代码的核心逻辑,通过 useMemoizedFn 保证始终引用最新的 containerId
|
|
162
|
+
var executeCodeFn = useMemoizedFn(function (v) {
|
|
138
163
|
try {
|
|
139
164
|
var playgroundBeforeExecuteFunction = new Function('containerId', playgroundBeforeExecute);
|
|
140
165
|
playgroundBeforeExecuteFunction(containerId);
|
|
141
166
|
} catch (e) {
|
|
142
167
|
reportError(e);
|
|
143
|
-
// 执行出错,不影响后面流程
|
|
144
168
|
}
|
|
145
|
-
if (currentEditorTab !== EDITOR_TABS.JAVASCRIPT) return;
|
|
146
169
|
if (!v) return;
|
|
147
|
-
|
|
148
|
-
// 1. 先编译代码
|
|
149
170
|
var compiled;
|
|
150
171
|
try {
|
|
151
172
|
compiled = compile(replaceInsertCss(v, locale.id), relativePath, es5);
|
|
152
173
|
} catch (e) {
|
|
153
174
|
reportError(e);
|
|
154
|
-
// 执行出错,后面的步骤不用做了!
|
|
155
175
|
return;
|
|
156
176
|
}
|
|
157
|
-
|
|
158
|
-
// 2. 执行代码,try catch 在内部已经做了
|
|
159
177
|
execute(compiled, containerId, playground === null || playground === void 0 ? void 0 : playground.container, replaceId);
|
|
160
|
-
}
|
|
161
|
-
var updateData = function updateData(data) {
|
|
162
|
-
if (!data) return;
|
|
163
|
-
var tabs = showSpecTab ? [EDITOR_TABS.JAVASCRIPT, EDITOR_TABS.SPEC, EDITOR_TABS.DATA] : [EDITOR_TABS.JAVASCRIPT, EDITOR_TABS.DATA];
|
|
164
|
-
setEditorTabs(tabs);
|
|
165
|
-
setData(data);
|
|
166
|
-
};
|
|
178
|
+
});
|
|
167
179
|
|
|
168
|
-
//
|
|
169
|
-
var
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
var dataList = [];
|
|
173
|
-
while (discoverd.length) {
|
|
174
|
-
var node = discoverd.pop();
|
|
175
|
-
var _data = node.data;
|
|
176
|
-
if (_typeof(_data) === 'object' && _data.type === 'fetch') {
|
|
177
|
-
dataList.push(_data);
|
|
178
|
-
}
|
|
179
|
-
discoverd.push.apply(discoverd, _toConsumableArray(node.children || []));
|
|
180
|
-
}
|
|
181
|
-
fetchData(dataList.map(function (d) {
|
|
182
|
-
return d.value;
|
|
183
|
-
})).then(updateData);
|
|
184
|
-
};
|
|
180
|
+
// debounce 实例只创建一次,内部通过 executeCodeFn 间接调用,避免闭包过期
|
|
181
|
+
var executeCode = useRef(debounce(function (v) {
|
|
182
|
+
return executeCodeFn(v);
|
|
183
|
+
}, 300)).current;
|
|
185
184
|
|
|
186
|
-
//
|
|
185
|
+
// 切例子时取消 pending,避免上一案例的代码渲染到新容器
|
|
187
186
|
useEffect(function () {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
// 清空 data 和 spec
|
|
191
|
-
// 放在该案例运行错误,返回之前案例的 data 和 spec
|
|
192
|
-
setData(null);
|
|
193
|
-
if (showSpecTab) {
|
|
194
|
-
setSpec(null);
|
|
195
|
-
setFull(false);
|
|
196
|
-
}
|
|
187
|
+
executeCode.cancel();
|
|
197
188
|
}, [exampleId]);
|
|
198
|
-
|
|
199
|
-
// 代码变化的时候,运行代码
|
|
200
|
-
useEffect(function () {
|
|
201
|
-
executeCode(code);
|
|
202
|
-
}, [code]);
|
|
203
189
|
useEffect(function () {
|
|
204
|
-
var dom = document.getElementById(containerId);
|
|
205
|
-
if (dom) {
|
|
206
|
-
bind(dom, debounce(function () {
|
|
207
|
-
dispatchResizeEvent();
|
|
208
|
-
}, 100));
|
|
209
|
-
}
|
|
210
190
|
return function () {
|
|
211
|
-
|
|
191
|
+
return executeCode.cancel();
|
|
212
192
|
};
|
|
213
193
|
}, []);
|
|
214
194
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
if (
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
195
|
+
/** 根据指定 tab 获取对应的可执行代码 */
|
|
196
|
+
var getCodeForTab = useCallback(function (tab) {
|
|
197
|
+
if (tab === EDITOR_TABS.DATA) return '';
|
|
198
|
+
if (tab === EDITOR_TABS.API) return apiCode;
|
|
199
|
+
// SPEC tab:传统模式用 apiCode,Spec 模式用 specCode
|
|
200
|
+
return showSpecTab ? specCode || '' : apiCode;
|
|
201
|
+
}, [specCode, apiCode, showSpecTab]);
|
|
202
|
+
var updateData = function updateData(data) {
|
|
203
|
+
if (!data) return;
|
|
204
|
+
var tabs = showSpecTab ? [EDITOR_TABS.SPEC, EDITOR_TABS.API, EDITOR_TABS.DATA] : [EDITOR_TABS.SPEC, EDITOR_TABS.DATA];
|
|
205
|
+
setEditorTabs(tabs);
|
|
206
|
+
setData(data);
|
|
207
|
+
};
|
|
228
208
|
|
|
229
|
-
// fetch
|
|
209
|
+
// fetch 多份远程数据,多份时合并为 { url: data } 映射
|
|
230
210
|
var fetchData = /*#__PURE__*/function () {
|
|
231
211
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(urls) {
|
|
232
212
|
var parseCSV, parseJSON, dataList;
|
|
@@ -244,8 +224,8 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
244
224
|
_context.next = 4;
|
|
245
225
|
return Promise.all(urls.map(function (url) {
|
|
246
226
|
return fetch(url).then(function (response) {
|
|
247
|
-
var
|
|
248
|
-
if (
|
|
227
|
+
var fmt = url.split('.').pop();
|
|
228
|
+
if (fmt === 'csv') return parseCSV(response);
|
|
249
229
|
return parseJSON(response);
|
|
250
230
|
});
|
|
251
231
|
}));
|
|
@@ -271,77 +251,135 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
271
251
|
};
|
|
272
252
|
}();
|
|
273
253
|
|
|
274
|
-
//
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
254
|
+
// 从 spec 对象中提取远程数据 URL 并 fetch
|
|
255
|
+
var updateDataFromSpec = function updateDataFromSpec(options) {
|
|
256
|
+
if (!options) return;
|
|
257
|
+
var discovered = [options];
|
|
258
|
+
var dataList = [];
|
|
259
|
+
while (discovered.length) {
|
|
260
|
+
var node = discovered.pop();
|
|
261
|
+
var _data = node.data;
|
|
262
|
+
if (_typeof(_data) === 'object' && _data.type === 'fetch') {
|
|
263
|
+
dataList.push(_data);
|
|
264
|
+
}
|
|
265
|
+
discovered.push.apply(discovered, _toConsumableArray(node.children || []));
|
|
266
|
+
}
|
|
267
|
+
fetchData(dataList.map(function (d) {
|
|
268
|
+
return d.value;
|
|
269
|
+
})).then(updateData);
|
|
270
|
+
};
|
|
279
271
|
|
|
280
|
-
//
|
|
272
|
+
// 案例变化时:重置所有状态 + 重置 tab + 解析数据 + 执行初始代码
|
|
273
|
+
// 合并为单一 effect,消除多个 [exampleId] effect 的隐式顺序依赖
|
|
281
274
|
useEffect(function () {
|
|
282
|
-
//
|
|
275
|
+
// 重置状态
|
|
276
|
+
setApiCode(source);
|
|
277
|
+
setSpecCode(null);
|
|
278
|
+
setData(null);
|
|
279
|
+
setCurrentEditorTab(EDITOR_TABS.SPEC);
|
|
280
|
+
|
|
281
|
+
// 防止快速切换示例时,旧请求的结果覆盖新示例的数据
|
|
282
|
+
var active = true;
|
|
283
|
+
|
|
284
|
+
// 解析 source 中的 fetch URL,加载远程数据
|
|
283
285
|
var match = source.matchAll(/fetch\(\s*["|'](.*)["|'],*\s*\)/g);
|
|
284
286
|
var dataFileMatch = Array.from(match);
|
|
285
287
|
if (dataFileMatch && dataFileMatch.length > 0) {
|
|
286
288
|
fetchData(dataFileMatch.map(function (d) {
|
|
287
289
|
return d[1].trim();
|
|
288
290
|
})).then(function (data) {
|
|
289
|
-
updateData(data);
|
|
291
|
+
if (active) updateData(data);
|
|
290
292
|
});
|
|
291
293
|
} else {
|
|
292
|
-
var tabs = showSpecTab ? [EDITOR_TABS.
|
|
294
|
+
var tabs = showSpecTab ? [EDITOR_TABS.SPEC, EDITOR_TABS.API] : [EDITOR_TABS.SPEC];
|
|
293
295
|
setEditorTabs(tabs);
|
|
294
296
|
}
|
|
297
|
+
|
|
298
|
+
// 执行初始代码
|
|
299
|
+
executeCode(source);
|
|
300
|
+
return function () {
|
|
301
|
+
active = false;
|
|
302
|
+
};
|
|
295
303
|
}, [exampleId]);
|
|
296
304
|
|
|
297
|
-
//
|
|
305
|
+
// 绑定容器 resize 监听
|
|
306
|
+
useEffect(function () {
|
|
307
|
+
var dom = document.getElementById(containerId);
|
|
308
|
+
if (dom) {
|
|
309
|
+
bind(dom, debounce(function () {
|
|
310
|
+
dispatchResizeEvent();
|
|
311
|
+
}, 100));
|
|
312
|
+
}
|
|
313
|
+
return function () {
|
|
314
|
+
if (dom) clear(dom);
|
|
315
|
+
};
|
|
316
|
+
}, []);
|
|
317
|
+
|
|
318
|
+
// 生命周期
|
|
319
|
+
useEffect(function () {
|
|
320
|
+
onReady();
|
|
321
|
+
if (playground !== null && playground !== void 0 && playground.playgroundDidMount) {
|
|
322
|
+
new Function(playground.playgroundDidMount)();
|
|
323
|
+
}
|
|
324
|
+
return function () {
|
|
325
|
+
onDestroy();
|
|
326
|
+
if (playground !== null && playground !== void 0 && playground.playgroundWillUnmount) {
|
|
327
|
+
new Function(playground.playgroundWillUnmount)();
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
}, []);
|
|
331
|
+
|
|
332
|
+
// 监听 spec 事件(由代码执行后 dispatch),首次收到时初始化 specCode
|
|
333
|
+
// 使用 ref 避免闭包过期问题,同时保持 [] 依赖数组只注册一次
|
|
334
|
+
var specCodeRef = useRef(specCode);
|
|
335
|
+
specCodeRef.current = specCode;
|
|
298
336
|
useEffect(function () {
|
|
299
337
|
var update = function update(e) {
|
|
300
338
|
var _ref3 = e.detail,
|
|
301
339
|
options = _ref3.options;
|
|
302
|
-
|
|
340
|
+
if (!options) return;
|
|
303
341
|
updateDataFromSpec(options);
|
|
342
|
+
// 仅在 specCode 未初始化时设置(首次从 source 执行产生)
|
|
343
|
+
if (specCodeRef.current === null) {
|
|
344
|
+
setSpecCode(specToCode(options));
|
|
345
|
+
}
|
|
304
346
|
};
|
|
305
347
|
window.addEventListener('spec', update);
|
|
306
348
|
return function () {
|
|
307
349
|
window.removeEventListener('spec', update);
|
|
308
350
|
};
|
|
309
|
-
});
|
|
351
|
+
}, []);
|
|
310
352
|
|
|
311
|
-
// 切换 tab
|
|
353
|
+
// 切换 tab 时,用目标 tab 对应的代码重新执行渲染
|
|
312
354
|
var onTabChange = useCallback(function (tab) {
|
|
313
355
|
setCurrentEditorTab(tab);
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
// if (monacoRef.current) {
|
|
318
|
-
// const v = currentEditorTab === EDITOR_TABS.JAVASCRIPT ? code : JSON.stringify(data, null, 2);
|
|
319
|
-
// monacoRef.current.setValue(v);
|
|
320
|
-
// }
|
|
321
|
-
// }, [currentEditorTab]);
|
|
356
|
+
var code = getCodeForTab(tab);
|
|
357
|
+
if (code) executeCode(code);
|
|
358
|
+
}, [getCodeForTab]);
|
|
322
359
|
|
|
360
|
+
/**
|
|
361
|
+
* 编辑时更新对应 tab 的代码并执行
|
|
362
|
+
* 统一数据源:传统模式下 Spec tab 写入 apiCode
|
|
363
|
+
*/
|
|
323
364
|
var onCodeChange = useCallback(function (value, event) {
|
|
324
|
-
if (
|
|
325
|
-
|
|
365
|
+
if (event.isFlush) return;
|
|
366
|
+
if (currentEditorTab === EDITOR_TABS.SPEC) {
|
|
367
|
+
if (showSpecTab) {
|
|
368
|
+
setSpecCode(value);
|
|
369
|
+
} else {
|
|
370
|
+
// 传统模式:Spec tab 就是唯一的代码 tab,写入 apiCode
|
|
371
|
+
setApiCode(value);
|
|
372
|
+
}
|
|
373
|
+
executeCode(value);
|
|
374
|
+
} else if (currentEditorTab === EDITOR_TABS.API) {
|
|
375
|
+
setApiCode(value);
|
|
376
|
+
executeCode(value);
|
|
326
377
|
}
|
|
327
|
-
}, [currentEditorTab]);
|
|
328
|
-
var parseFunction = function parseFunction(string) {
|
|
329
|
-
return string.replace(/"\<func\>(.*?)\<\/func\>"/g, function (_, code) {
|
|
330
|
-
return code.replace(/\\n/g, '\n').replace(/\\"/g, '"');
|
|
331
|
-
});
|
|
332
|
-
};
|
|
333
|
-
|
|
334
|
-
// 序列化 JavaScript 对象的时候对 function 进行特殊的标注,
|
|
335
|
-
// 使得解析该字符串的时候能方便的提取 function 对应的字符串。
|
|
336
|
-
// { add: (x, y) => x + y } => '{ add: <func>(x, y) => x + y</func> }'
|
|
337
|
-
var withFunction = function withFunction(_, value) {
|
|
338
|
-
if (typeof value !== 'function') return value;
|
|
339
|
-
return "<func>".concat(value.toString(), "</func>");
|
|
340
|
-
};
|
|
378
|
+
}, [currentEditorTab, showSpecTab]);
|
|
341
379
|
var languageOf = function languageOf(tab) {
|
|
342
380
|
switch (tab) {
|
|
343
|
-
case EDITOR_TABS.JAVASCRIPT:
|
|
344
381
|
case EDITOR_TABS.SPEC:
|
|
382
|
+
case EDITOR_TABS.API:
|
|
345
383
|
return 'javascript';
|
|
346
384
|
case EDITOR_TABS.DATA:
|
|
347
385
|
return 'json';
|
|
@@ -349,79 +387,49 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
349
387
|
return 'javascript';
|
|
350
388
|
}
|
|
351
389
|
};
|
|
390
|
+
|
|
391
|
+
/** 获取 tab 对应的编辑器显示内容(统一数据源) */
|
|
352
392
|
var valueOf = function valueOf(tab) {
|
|
353
393
|
switch (tab) {
|
|
354
|
-
case EDITOR_TABS.JAVASCRIPT:
|
|
355
|
-
return code;
|
|
356
394
|
case EDITOR_TABS.SPEC:
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
};
|
|
362
|
-
return format(parseFunction(_code(JSON.stringify(spec, withFunction))), {
|
|
363
|
-
plugins: [parserBabel]
|
|
364
|
-
});
|
|
365
|
-
}
|
|
395
|
+
// 传统模式用 apiCode,Spec 模式用 specCode
|
|
396
|
+
return showSpecTab ? specCode || '' : apiCode;
|
|
397
|
+
case EDITOR_TABS.API:
|
|
398
|
+
return apiCode;
|
|
366
399
|
case EDITOR_TABS.DATA:
|
|
367
400
|
return JSON.stringify(data, null, 2);
|
|
368
401
|
default:
|
|
369
402
|
return null;
|
|
370
403
|
}
|
|
371
404
|
};
|
|
372
|
-
var defaultOf = function defaultOf(tab) {
|
|
373
|
-
switch (tab) {
|
|
374
|
-
case EDITOR_TABS.JAVASCRIPT:
|
|
375
|
-
return code;
|
|
376
|
-
default:
|
|
377
|
-
return null;
|
|
378
|
-
}
|
|
379
|
-
};
|
|
380
405
|
var onClickAI = function onClickAI() {
|
|
381
406
|
var _themeConfig$ai;
|
|
382
407
|
var aiUrl = (themeConfig === null || themeConfig === void 0 || (_themeConfig$ai = themeConfig.ai) === null || _themeConfig$ai === void 0 ? void 0 : _themeConfig$ai.url) || 'https://sive.antv.antgroup.com/qa';
|
|
383
408
|
window.open(aiUrl);
|
|
384
409
|
};
|
|
385
410
|
var onReload = function onReload() {
|
|
386
|
-
|
|
411
|
+
setApiCode(source);
|
|
412
|
+
setSpecCode(null);
|
|
413
|
+
// 重新执行 source 以重新生成 spec
|
|
414
|
+
executeCode(source);
|
|
387
415
|
};
|
|
388
416
|
return /*#__PURE__*/React.createElement("div", {
|
|
389
417
|
className: styles.editor,
|
|
390
418
|
style: style
|
|
391
419
|
}, /*#__PURE__*/React.createElement(Toolbar, {
|
|
392
420
|
fileExtension: fileExtension,
|
|
393
|
-
sourceCode:
|
|
421
|
+
sourceCode: getCodeForTab(currentEditorTab),
|
|
394
422
|
playground: playground,
|
|
395
|
-
location: location,
|
|
396
423
|
title: title,
|
|
397
|
-
isFullScreen: isFullscreen,
|
|
398
424
|
editorTabs: editorTabs,
|
|
399
425
|
currentEditorTab: currentEditorTab,
|
|
400
426
|
onExecuteCode: function onExecuteCode() {
|
|
401
|
-
return executeCode(
|
|
427
|
+
return executeCode(getCodeForTab(currentEditorTab));
|
|
402
428
|
},
|
|
403
429
|
onEditorTabChange: onTabChange,
|
|
404
|
-
onToggleFullscreen: onFullscreen,
|
|
405
430
|
onClickAI: onClickAI,
|
|
406
431
|
showAI: showAI,
|
|
407
|
-
onReload: onReload
|
|
408
|
-
slots: {
|
|
409
|
-
Spec: /*#__PURE__*/React.createElement("span", {
|
|
410
|
-
style: {
|
|
411
|
-
paddingLeft: '0.25em',
|
|
412
|
-
paddingRight: 0
|
|
413
|
-
}
|
|
414
|
-
}, /*#__PURE__*/React.createElement(Switch, {
|
|
415
|
-
style: {
|
|
416
|
-
width: 30
|
|
417
|
-
},
|
|
418
|
-
size: "small",
|
|
419
|
-
onChange: function onChange(checked) {
|
|
420
|
-
return setFull(checked);
|
|
421
|
-
},
|
|
422
|
-
checked: full
|
|
423
|
-
}))
|
|
424
|
-
}
|
|
432
|
+
onReload: onReload
|
|
425
433
|
}), editorTabs.map(function (tab) {
|
|
426
434
|
return /*#__PURE__*/React.createElement("div", {
|
|
427
435
|
key: tab,
|
|
@@ -433,7 +441,6 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
433
441
|
}, /*#__PURE__*/React.createElement(MonacoEditor, {
|
|
434
442
|
language: languageOf(tab),
|
|
435
443
|
value: valueOf(tab),
|
|
436
|
-
defaultValue: defaultOf(tab),
|
|
437
444
|
path: "".concat(tab, "_").concat(relativePath || exampleId),
|
|
438
445
|
loading: /*#__PURE__*/React.createElement(Loading, {
|
|
439
446
|
style: {
|
|
@@ -441,7 +448,7 @@ var CodeEditor = function CodeEditor(_ref) {
|
|
|
441
448
|
}
|
|
442
449
|
}),
|
|
443
450
|
options: {
|
|
444
|
-
readOnly: tab === EDITOR_TABS.DATA
|
|
451
|
+
readOnly: tab === EDITOR_TABS.DATA,
|
|
445
452
|
automaticLayout: true,
|
|
446
453
|
minimap: {
|
|
447
454
|
enabled: false
|
|
@@ -115,6 +115,7 @@ export function replaceInsertCss(str, lang) {
|
|
|
115
115
|
export function execute(code, playgroundScriptContainer, container) {
|
|
116
116
|
var replaceId = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'container';
|
|
117
117
|
var node = document.getElementById(playgroundScriptContainer);
|
|
118
|
+
if (!node) return;
|
|
118
119
|
var script = document.createElement('script');
|
|
119
120
|
// replace container id in case of multi demos in document
|
|
120
121
|
var newCode = code.replace(/'container'|"container"/, "'".concat(replaceId, "'"));
|
|
@@ -52,10 +52,6 @@ var CodeRunner = function CodeRunner(_ref) {
|
|
|
52
52
|
_useState2 = _slicedToArray(_useState, 2),
|
|
53
53
|
error = _useState2[0],
|
|
54
54
|
setError = _useState2[1];
|
|
55
|
-
var _useState3 = useState(false),
|
|
56
|
-
_useState4 = _slicedToArray(_useState3, 2),
|
|
57
|
-
isFullScreen = _useState4[0],
|
|
58
|
-
setFullscreen = _useState4[1];
|
|
59
55
|
var locale = useLocale();
|
|
60
56
|
var header = /*#__PURE__*/React.createElement(CodeHeader, {
|
|
61
57
|
title: ic(title),
|
|
@@ -75,7 +71,6 @@ var CodeRunner = function CodeRunner(_ref) {
|
|
|
75
71
|
relativePath: relativePath,
|
|
76
72
|
replaceId: replaceId,
|
|
77
73
|
onError: setError,
|
|
78
|
-
onFullscreen: setFullscreen,
|
|
79
74
|
onDestroy: noop,
|
|
80
75
|
onReady: noop,
|
|
81
76
|
playground: playground,
|
|
@@ -1,10 +1,5 @@
|
|
|
1
|
-
import { useIntl, useSiteData } from 'dumi';
|
|
2
1
|
import React from 'react';
|
|
3
2
|
import styles from "./SearchResult.module.less";
|
|
4
|
-
import classnames from "classnames";
|
|
5
|
-
import { AIChatStore, createNewSession } from "../../../model/AIChat";
|
|
6
|
-
import { authStore, showLoginModal } from "../../../model/auth";
|
|
7
|
-
import { useSnapshot } from "valtio";
|
|
8
3
|
var getHighlightInfo = function getHighlightInfo(textSegments) {
|
|
9
4
|
return /*#__PURE__*/React.createElement(React.Fragment, null, textSegments.map(function (segment) {
|
|
10
5
|
return /*#__PURE__*/React.createElement("span", {
|
|
@@ -20,52 +15,9 @@ var getHighlightInfo = function getHighlightInfo(textSegments) {
|
|
|
20
15
|
export var SearchResult = function SearchResult(_ref) {
|
|
21
16
|
var results = _ref.results,
|
|
22
17
|
keywords = _ref.keywords;
|
|
23
|
-
var _useSiteData = useSiteData(),
|
|
24
|
-
themeConfig = _useSiteData.themeConfig;
|
|
25
|
-
var intl = useIntl();
|
|
26
|
-
var authSnap = useSnapshot(authStore);
|
|
27
|
-
function pureSearch() {
|
|
28
|
-
AIChatStore.mode = 'solve';
|
|
29
|
-
createNewSession({
|
|
30
|
-
promptText: keywords,
|
|
31
|
-
mode: 'solve',
|
|
32
|
-
lib: !themeConfig.isAntVSite ? themeConfig.title : undefined,
|
|
33
|
-
jump: true,
|
|
34
|
-
lang: intl.locale === 'zh' ? 'zh' : 'en',
|
|
35
|
-
entry_point: 'SearchResult'
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
18
|
return /*#__PURE__*/React.createElement("div", {
|
|
39
19
|
className: styles.searchResult
|
|
40
|
-
},
|
|
41
|
-
className: styles.item
|
|
42
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
43
|
-
className: styles.subject
|
|
44
|
-
}, /*#__PURE__*/React.createElement("img", {
|
|
45
|
-
src: "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*7svFR6wkPMoAAAAAAAAAAAAADmJ7AQ/original",
|
|
46
|
-
alt: "AntV"
|
|
47
|
-
})), /*#__PURE__*/React.createElement("div", {
|
|
48
|
-
className: styles.br
|
|
49
|
-
}), /*#__PURE__*/React.createElement("a", {
|
|
50
|
-
className: styles.result,
|
|
51
|
-
onClick: function onClick() {
|
|
52
|
-
if (!authSnap.isAuthenticated) {
|
|
53
|
-
showLoginModal(pureSearch);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
pureSearch();
|
|
57
|
-
}
|
|
58
|
-
}, /*#__PURE__*/React.createElement("div", {
|
|
59
|
-
className: classnames(styles.title, styles.highlighted)
|
|
60
|
-
}, keywords), /*#__PURE__*/React.createElement("div", {
|
|
61
|
-
className: styles.description
|
|
62
|
-
}, intl.formatMessage({
|
|
63
|
-
id: 'ai.search.try'
|
|
64
|
-
}), "\xA0", /*#__PURE__*/React.createElement("span", {
|
|
65
|
-
className: styles.highlighted
|
|
66
|
-
}, "AI"), "\xA0", intl.formatMessage({
|
|
67
|
-
id: 'ai.search.visualization'
|
|
68
|
-
})))), results !== null && results !== void 0 && results.length ? results.map(function (r, index) {
|
|
20
|
+
}, results !== null && results !== void 0 && results.length ? results.map(function (r, index) {
|
|
69
21
|
return /*#__PURE__*/React.createElement("div", {
|
|
70
22
|
className: styles.item,
|
|
71
23
|
key: index
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/dumi-theme-antv",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.5",
|
|
4
4
|
"description": "AntV website theme based on dumi2.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"dumi",
|
|
@@ -20,17 +20,6 @@
|
|
|
20
20
|
"files": [
|
|
21
21
|
"dist"
|
|
22
22
|
],
|
|
23
|
-
"scripts": {
|
|
24
|
-
"build": "npm run prepare && father build",
|
|
25
|
-
"dev": "father dev",
|
|
26
|
-
"fix": "prettier ./src --write",
|
|
27
|
-
"lint": "npm run lint:es && npm run lint:css",
|
|
28
|
-
"lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
|
|
29
|
-
"lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
|
|
30
|
-
"prepare": "father link-dev-theme",
|
|
31
|
-
"prepublishOnly": "npm run build",
|
|
32
|
-
"start": "cd example && npm run dev"
|
|
33
|
-
},
|
|
34
23
|
"commitlint": {
|
|
35
24
|
"extends": [
|
|
36
25
|
"@commitlint/config-conventional"
|
|
@@ -180,9 +169,13 @@
|
|
|
180
169
|
"overrides": {
|
|
181
170
|
"@monaco-editor/loader": "1.5.0"
|
|
182
171
|
},
|
|
183
|
-
"
|
|
184
|
-
"
|
|
185
|
-
|
|
186
|
-
|
|
172
|
+
"scripts": {
|
|
173
|
+
"build": "npm run prepare && father build",
|
|
174
|
+
"dev": "father dev",
|
|
175
|
+
"fix": "prettier ./src --write",
|
|
176
|
+
"lint": "npm run lint:es && npm run lint:css",
|
|
177
|
+
"lint:css": "stylelint \"{src,test}/**/*.{css,less}\"",
|
|
178
|
+
"lint:es": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
|
|
179
|
+
"start": "cd example && npm run dev"
|
|
187
180
|
}
|
|
188
|
-
}
|
|
181
|
+
}
|