@antv/dumi-theme-antv 0.3.0-beta.6 → 0.3.0-beta.8
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.
|
@@ -14,6 +14,7 @@ import React, { useRef, useState, useCallback, useEffect } from 'react';
|
|
|
14
14
|
import MonacoEditor, { loader } from '@monaco-editor/react';
|
|
15
15
|
import { useSiteData, useLocale } from 'dumi';
|
|
16
16
|
import { debounce, noop } from 'lodash-es';
|
|
17
|
+
import { bind, clear } from 'size-sensor';
|
|
17
18
|
import { replaceInsertCss, execute, compile } from "./utils";
|
|
18
19
|
import { Toolbar, EDITOR_TABS } from "./Toolbar";
|
|
19
20
|
import { Loading } from "../Loading";
|
|
@@ -88,8 +89,11 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
88
89
|
|
|
89
90
|
var reportError = useCallback(function (e) {
|
|
90
91
|
if (e) {
|
|
91
|
-
console.
|
|
92
|
+
console.log(e);
|
|
92
93
|
onError(e);
|
|
94
|
+
e.preventDefault && e.preventDefault();
|
|
95
|
+
} else {
|
|
96
|
+
onError(null);
|
|
93
97
|
}
|
|
94
98
|
}, []);
|
|
95
99
|
useEffect(function () {
|
|
@@ -110,19 +114,16 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
110
114
|
window.removeEventListener('unhandledrejection', reportError);
|
|
111
115
|
}
|
|
112
116
|
};
|
|
113
|
-
});
|
|
117
|
+
}, []);
|
|
114
118
|
var executeCode = useCallback(debounce(function (v) {
|
|
115
119
|
if (!v) return; // 1. 先编译代码
|
|
116
120
|
|
|
117
121
|
var compiled;
|
|
118
122
|
|
|
119
123
|
try {
|
|
120
|
-
compiled = compile(replaceInsertCss(v, locale.id), relativePath);
|
|
121
|
-
|
|
122
|
-
onError(null);
|
|
124
|
+
compiled = compile(replaceInsertCss(v, locale.id), relativePath);
|
|
123
125
|
} catch (e) {
|
|
124
|
-
|
|
125
|
-
onError(e); // 执行出错,后面的步骤不用做了!
|
|
126
|
+
reportError(e); // 执行出错,后面的步骤不用做了!
|
|
126
127
|
|
|
127
128
|
return;
|
|
128
129
|
} // 2. 执行代码,try catch 在内部已经做了
|
|
@@ -137,6 +138,10 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
137
138
|
executeCode(code);
|
|
138
139
|
}, [code]);
|
|
139
140
|
useEffect(function () {
|
|
141
|
+
var dom = document.getElementById('playgroundScriptContainer');
|
|
142
|
+
bind(dom, debounce(function () {
|
|
143
|
+
dispatchResizeEvent();
|
|
144
|
+
}, 100));
|
|
140
145
|
onReady();
|
|
141
146
|
|
|
142
147
|
if (playground !== null && playground !== void 0 && playground.playgroundDidMount) {
|
|
@@ -144,6 +149,7 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
144
149
|
}
|
|
145
150
|
|
|
146
151
|
return function () {
|
|
152
|
+
clear(dom);
|
|
147
153
|
onDestroy();
|
|
148
154
|
|
|
149
155
|
if (playground !== null && playground !== void 0 && playground.playgroundWillUnmount) {
|
|
@@ -135,7 +135,7 @@ export function execute(code, playgroundScriptContainer, container) {
|
|
|
135
135
|
var script = document.createElement('script'); // replace container id in case of multi demos in document
|
|
136
136
|
|
|
137
137
|
var newCode = code.replace(/'container'|"container"/, "'".concat(replaceId, "'"));
|
|
138
|
-
script.innerHTML = "\n// Can only have one anonymous define call per script file\n// \u548C monaco loader \u52A0\u8F7D\u51B2\u7A81\nvar __runnerDefine = window['define'];\nwindow['define'] = null;\ntry {\n ".concat(newCode, "\n\n window.__reportErrorInPlayground && window.__reportErrorInPlayground(null);\n} catch(e) {\n window.__reportErrorInPlayground && window.__reportErrorInPlayground(e);\n} finally {\n window['define'] = __runnerDefine;\n}\n "); // 追加图表容器
|
|
138
|
+
script.innerHTML = "\n// Can only have one anonymous define call per script file\n// \u548C monaco loader \u52A0\u8F7D\u51B2\u7A81\nvar __runnerDefine = window['define'];\nwindow['define'] = null;\ntry {\n ".concat(newCode, "\n\n // \u6E05\u9664\u663E\u793A\u7684\u9519\u8BEF\n window.__reportErrorInPlayground && window.__reportErrorInPlayground(null);\n} catch(e) {\n window.__reportErrorInPlayground && window.__reportErrorInPlayground(e);\n} finally {\n window['define'] = __runnerDefine;\n}\n "); // 追加图表容器
|
|
139
139
|
|
|
140
140
|
node.innerHTML = container || "<div id=".concat(replaceId, " />"); // 运行 script
|
|
141
141
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/dumi-theme-antv",
|
|
3
|
-
"version": "0.3.0-beta.
|
|
3
|
+
"version": "0.3.0-beta.8",
|
|
4
4
|
"description": "AntV website theme based on dumi2.",
|
|
5
5
|
"types": "dist/types.d.ts",
|
|
6
6
|
"scripts": {
|
|
@@ -81,6 +81,7 @@
|
|
|
81
81
|
"react-split-pane": "^0.1.92",
|
|
82
82
|
"react-use": "^17.4.0",
|
|
83
83
|
"reading-time": "^1.5.0",
|
|
84
|
+
"size-sensor": "^1.0.1",
|
|
84
85
|
"slick-carousel": "^1.8.1",
|
|
85
86
|
"uri-parse": "^1.0.0"
|
|
86
87
|
},
|