@antv/dumi-theme-antv 0.3.0-beta.7 → 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";
|
|
@@ -86,15 +87,15 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
86
87
|
window.dispatchEvent(e);
|
|
87
88
|
};
|
|
88
89
|
|
|
89
|
-
var reportError = useCallback(
|
|
90
|
+
var reportError = useCallback(function (e) {
|
|
90
91
|
if (e) {
|
|
91
|
-
console.
|
|
92
|
+
console.log(e);
|
|
92
93
|
onError(e);
|
|
93
|
-
e
|
|
94
|
+
e.preventDefault && e.preventDefault();
|
|
94
95
|
} else {
|
|
95
96
|
onError(null);
|
|
96
97
|
}
|
|
97
|
-
},
|
|
98
|
+
}, []);
|
|
98
99
|
useEffect(function () {
|
|
99
100
|
// 用于上报错误信息,使用 script 执行代码
|
|
100
101
|
if (typeof window !== 'undefined') {
|
|
@@ -113,16 +114,14 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
113
114
|
window.removeEventListener('unhandledrejection', reportError);
|
|
114
115
|
}
|
|
115
116
|
};
|
|
116
|
-
});
|
|
117
|
+
}, []);
|
|
117
118
|
var executeCode = useCallback(debounce(function (v) {
|
|
118
119
|
if (!v) return; // 1. 先编译代码
|
|
119
120
|
|
|
120
121
|
var compiled;
|
|
121
122
|
|
|
122
123
|
try {
|
|
123
|
-
compiled = compile(replaceInsertCss(v, locale.id), relativePath);
|
|
124
|
-
|
|
125
|
-
reportError(null);
|
|
124
|
+
compiled = compile(replaceInsertCss(v, locale.id), relativePath);
|
|
126
125
|
} catch (e) {
|
|
127
126
|
reportError(e); // 执行出错,后面的步骤不用做了!
|
|
128
127
|
|
|
@@ -139,6 +138,10 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
139
138
|
executeCode(code);
|
|
140
139
|
}, [code]);
|
|
141
140
|
useEffect(function () {
|
|
141
|
+
var dom = document.getElementById('playgroundScriptContainer');
|
|
142
|
+
bind(dom, debounce(function () {
|
|
143
|
+
dispatchResizeEvent();
|
|
144
|
+
}, 100));
|
|
142
145
|
onReady();
|
|
143
146
|
|
|
144
147
|
if (playground !== null && playground !== void 0 && playground.playgroundDidMount) {
|
|
@@ -146,6 +149,7 @@ export var CodeEditor = function CodeEditor(_ref) {
|
|
|
146
149
|
}
|
|
147
150
|
|
|
148
151
|
return function () {
|
|
152
|
+
clear(dom);
|
|
149
153
|
onDestroy();
|
|
150
154
|
|
|
151
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
|
},
|