fix monaco-editor.

This commit is contained in:
2023-04-03 19:14:55 +08:00
parent 9228f3d169
commit 8478c15e55
5 changed files with 20 additions and 11 deletions

11
package-lock.json generated
View File

@@ -34,6 +34,7 @@
"markdown-it-shiki": "^0.8.0", "markdown-it-shiki": "^0.8.0",
"monaco-editor": "^0.36.1", "monaco-editor": "^0.36.1",
"prettier": "^2.8.7", "prettier": "^2.8.7",
"terser": "^5.16.8",
"typescript": "^5.0.3", "typescript": "^5.0.3",
"unplugin-auto-import": "^0.15.2", "unplugin-auto-import": "^0.15.2",
"unplugin-icons": "^0.16.1", "unplugin-icons": "^0.16.1",
@@ -2168,7 +2169,6 @@
"resolved": "https://registry.npmmirror.com/@jridgewell/source-map/-/source-map-0.3.2.tgz", "resolved": "https://registry.npmmirror.com/@jridgewell/source-map/-/source-map-0.3.2.tgz",
"integrity": "sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==", "integrity": "sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==",
"dev": true, "dev": true,
"peer": true,
"dependencies": { "dependencies": {
"@jridgewell/gen-mapping": "^0.3.0", "@jridgewell/gen-mapping": "^0.3.0",
"@jridgewell/trace-mapping": "^0.3.9" "@jridgewell/trace-mapping": "^0.3.9"
@@ -2179,7 +2179,6 @@
"resolved": "https://registry.npmmirror.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz", "resolved": "https://registry.npmmirror.com/@jridgewell/gen-mapping/-/gen-mapping-0.3.2.tgz",
"integrity": "sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A==", "integrity": "sha512-mh65xKQAzI6iBcFzwv28KVWSmCkdRBWoOh+bYQGW3+6OZvbbN3TqMGo5hqYxQniRcH9F2VZIoJCm4pa3BPDK/A==",
"dev": true, "dev": true,
"peer": true,
"dependencies": { "dependencies": {
"@jridgewell/set-array": "^1.0.1", "@jridgewell/set-array": "^1.0.1",
"@jridgewell/sourcemap-codec": "^1.4.10", "@jridgewell/sourcemap-codec": "^1.4.10",
@@ -3153,8 +3152,7 @@
"version": "1.1.2", "version": "1.1.2",
"resolved": "https://registry.npmmirror.com/buffer-from/-/buffer-from-1.1.2.tgz", "resolved": "https://registry.npmmirror.com/buffer-from/-/buffer-from-1.1.2.tgz",
"integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==", "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
"dev": true, "dev": true
"peer": true
}, },
"node_modules/c12": { "node_modules/c12": {
"version": "1.1.2", "version": "1.1.2",
@@ -3284,8 +3282,7 @@
"version": "2.20.3", "version": "2.20.3",
"resolved": "https://registry.npmmirror.com/commander/-/commander-2.20.3.tgz", "resolved": "https://registry.npmmirror.com/commander/-/commander-2.20.3.tgz",
"integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==", "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==",
"dev": true, "dev": true
"peer": true
}, },
"node_modules/compute-scroll-into-view": { "node_modules/compute-scroll-into-view": {
"version": "1.0.20", "version": "1.0.20",
@@ -5282,7 +5279,6 @@
"resolved": "https://registry.npmmirror.com/source-map-support/-/source-map-support-0.5.21.tgz", "resolved": "https://registry.npmmirror.com/source-map-support/-/source-map-support-0.5.21.tgz",
"integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==", "integrity": "sha512-uBHU3L3czsIyYXKX88fdrGovxdSCoTGDRZ6SYXtSRxLZUzHg5P/66Ht6uoUlHu9EZod+inXhKo3qQgwXUT/y1w==",
"dev": true, "dev": true,
"peer": true,
"dependencies": { "dependencies": {
"buffer-from": "^1.0.0", "buffer-from": "^1.0.0",
"source-map": "^0.6.0" "source-map": "^0.6.0"
@@ -5431,7 +5427,6 @@
"resolved": "https://registry.npmmirror.com/terser/-/terser-5.16.8.tgz", "resolved": "https://registry.npmmirror.com/terser/-/terser-5.16.8.tgz",
"integrity": "sha512-QI5g1E/ef7d+PsDifb+a6nnVgC4F22Bg6T0xrBrz6iloVB4PUkkunp6V8nzoOOZJIzjWVdAGqCdlKlhLq/TbIA==", "integrity": "sha512-QI5g1E/ef7d+PsDifb+a6nnVgC4F22Bg6T0xrBrz6iloVB4PUkkunp6V8nzoOOZJIzjWVdAGqCdlKlhLq/TbIA==",
"dev": true, "dev": true,
"peer": true,
"dependencies": { "dependencies": {
"@jridgewell/source-map": "^0.3.2", "@jridgewell/source-map": "^0.3.2",
"acorn": "^8.5.0", "acorn": "^8.5.0",

View File

@@ -36,6 +36,7 @@
"markdown-it-shiki": "^0.8.0", "markdown-it-shiki": "^0.8.0",
"monaco-editor": "^0.36.1", "monaco-editor": "^0.36.1",
"prettier": "^2.8.7", "prettier": "^2.8.7",
"terser": "^5.16.8",
"typescript": "^5.0.3", "typescript": "^5.0.3",
"unplugin-auto-import": "^0.15.2", "unplugin-auto-import": "^0.15.2",
"unplugin-icons": "^0.16.1", "unplugin-icons": "^0.16.1",

View File

@@ -1,10 +1,14 @@
import loader, { Monaco } from "@monaco-editor/loader" import loader, { Monaco } from "@monaco-editor/loader"
import { isLowVersion, protocol } from "~/utils/functions"
export const monaco = ref<Monaco>() export const monaco = ref<Monaco>()
export async function init() { export async function init() {
const version = isLowVersion ? "0.30.1" : "0.36.1"
loader.config({ loader.config({
paths: { vs: "https://cdn.staticfile.org/monaco-editor/0.36.1/min/vs" }, paths: {
vs: `${protocol}://cdn.staticfile.org/monaco-editor/${version}/min/vs`,
},
"vs/nls": { availableLanguages: { "*": "zh-cn" } }, "vs/nls": { availableLanguages: { "*": "zh-cn" } },
}) })

View File

@@ -152,3 +152,12 @@ export function decode(bytes?: string) {
) )
) )
} }
function getChromeVersion() {
var raw = navigator.userAgent.match(/Chrom(e|ium)\/([0-9]+)\./)
return raw ? parseInt(raw[2], 10) : 0
}
export const isLowVersion = getChromeVersion() < 80
export const protocol = isLowVersion ? "http" : "https"

View File

@@ -1,9 +1,9 @@
import axios from "axios" import axios from "axios"
import { DEAD_RESULTS } from "./constants" import { DEAD_RESULTS } from "./constants"
import { decode, encode } from "./functions" import { decode, encode, protocol } from "./functions"
import { Code } from "./types" import { Code } from "./types"
const http = axios.create({ baseURL: "https://judge0api.hyyz.izhai.net" }) const http = axios.create({ baseURL: `${protocol}://judge0api.hyyz.izhai.net` })
export async function createTestSubmission(code: Code, input: string) { export async function createTestSubmission(code: Code, input: string) {
const encodedCode = encode(code.value) const encodedCode = encode(code.value)