You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1796 lines
50 KiB
1796 lines
50 KiB
"use strict";
|
|
(self["webpackChunk"] = self["webpackChunk"] || []).push([[6162],{
|
|
|
|
/***/ 16162:
|
|
/*!************************************************************!*\
|
|
!*** ./src/components/monaco-editor/index.jsx + 4 modules ***!
|
|
\************************************************************/
|
|
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
|
|
|
|
|
|
// EXPORTS
|
|
__webpack_require__.d(__webpack_exports__, {
|
|
SV: function() { return /* binding */ DiffEditor; },
|
|
ZP: function() { return /* binding */ monaco_editor; }
|
|
});
|
|
|
|
// UNUSED EXPORTS: getLanguageByMirrorName
|
|
|
|
// EXTERNAL MODULE: ./node_modules/_react@17.0.2@react/index.js
|
|
var _react_17_0_2_react = __webpack_require__(59301);
|
|
// EXTERNAL MODULE: ./node_modules/_resize-observer-polyfill@1.5.1@resize-observer-polyfill/dist/ResizeObserver.es.js
|
|
var ResizeObserver_es = __webpack_require__(76374);
|
|
;// CONCATENATED MODULE: ./src/components/monaco-editor/keywords.tsx
|
|
const cLangage = {
|
|
keywords: ["print", "auto", "break", "case", "char", "const", "continue", "default", "do", "double", "else", "enum", "extern", "float", "for", "goto", "if", "int", "long", "register", "return", "short", "signed", "sizeof", "static", "struct", "switch", "typedef", "union", "unsigned", "void", "volatile", "while"]
|
|
};
|
|
const javaLangage = {
|
|
quickKey: [{
|
|
label: "main",
|
|
content: [
|
|
"public static void main(String[] args) {",
|
|
" $0",
|
|
"}"
|
|
].join("\n")
|
|
}, {
|
|
label: "System.out.println",
|
|
content: [
|
|
"System.out.println($0)"
|
|
].join("\n")
|
|
}, {
|
|
label: "System.out.print",
|
|
content: [
|
|
"System.out.print($0)"
|
|
].join("\n")
|
|
}],
|
|
keywords: [
|
|
"abstract",
|
|
"continue",
|
|
"for",
|
|
"new",
|
|
"switch",
|
|
"assert",
|
|
"default",
|
|
"goto",
|
|
"package",
|
|
"synchronized",
|
|
"boolean",
|
|
"do",
|
|
"if",
|
|
"private",
|
|
"this",
|
|
"break",
|
|
"double",
|
|
"implements",
|
|
"protected",
|
|
"throw",
|
|
"byte",
|
|
"else",
|
|
"import",
|
|
"public",
|
|
"throws",
|
|
"case",
|
|
"enum",
|
|
"instanceof",
|
|
"return",
|
|
"transient",
|
|
"catch",
|
|
"extends",
|
|
"int",
|
|
"short",
|
|
"try",
|
|
"char",
|
|
"final",
|
|
"interface",
|
|
"static",
|
|
"void",
|
|
"class",
|
|
"finally",
|
|
"long",
|
|
"strictfp",
|
|
"volatile",
|
|
"const",
|
|
"float",
|
|
"native",
|
|
"super",
|
|
"while",
|
|
"true",
|
|
"false"
|
|
]
|
|
};
|
|
const cppLangage = {
|
|
keywords: [
|
|
"abstract",
|
|
"amp",
|
|
"array",
|
|
"auto",
|
|
"bool",
|
|
"break",
|
|
"case",
|
|
"catch",
|
|
"char",
|
|
"class",
|
|
"const",
|
|
"constexpr",
|
|
"const_cast",
|
|
"continue",
|
|
"cpu",
|
|
"decltype",
|
|
"default",
|
|
"delegate",
|
|
"delete",
|
|
"do",
|
|
"double",
|
|
"dynamic_cast",
|
|
"each",
|
|
"else",
|
|
"enum",
|
|
"event",
|
|
"explicit",
|
|
"export",
|
|
"extern",
|
|
"false",
|
|
"final",
|
|
"finally",
|
|
"float",
|
|
"friend",
|
|
"gcnew",
|
|
"generic",
|
|
"goto",
|
|
"in",
|
|
"initonly",
|
|
"inline",
|
|
"int",
|
|
"interface",
|
|
"interior_ptr",
|
|
"internal",
|
|
"literal",
|
|
"long",
|
|
"mutable",
|
|
"namespace",
|
|
"new",
|
|
"noexcept",
|
|
"nullptr",
|
|
"__nullptr",
|
|
"operator",
|
|
"override",
|
|
"partial",
|
|
"pascal",
|
|
"pin_ptr",
|
|
"private",
|
|
"property",
|
|
"protected",
|
|
"public",
|
|
"ref",
|
|
"register",
|
|
"reinterpret_cast",
|
|
"restrict",
|
|
"return",
|
|
"safe_cast",
|
|
"sealed",
|
|
"short",
|
|
"signed",
|
|
"sizeof",
|
|
"static",
|
|
"static_assert",
|
|
"static_cast",
|
|
"struct",
|
|
"switch",
|
|
"template",
|
|
"this",
|
|
"thread_local",
|
|
"throw",
|
|
"tile_static",
|
|
"true",
|
|
"try",
|
|
"typedef",
|
|
"typeid",
|
|
"typename",
|
|
"union",
|
|
"unsigned",
|
|
"using",
|
|
"virtual",
|
|
"void",
|
|
"volatile",
|
|
"wchar_t",
|
|
"where",
|
|
"while",
|
|
"_asm",
|
|
"_based",
|
|
"_cdecl",
|
|
"_declspec",
|
|
"_fastcall",
|
|
"_if_exists",
|
|
"_if_not_exists",
|
|
"_inline",
|
|
"_multiple_inheritance",
|
|
"_pascal",
|
|
"_single_inheritance",
|
|
"_stdcall",
|
|
"_virtual_inheritance",
|
|
"_w64",
|
|
"__abstract",
|
|
"__alignof",
|
|
"__asm",
|
|
"__assume",
|
|
"__based",
|
|
"__box",
|
|
"__builtin_alignof",
|
|
"__cdecl",
|
|
"__clrcall",
|
|
"__declspec",
|
|
"__delegate",
|
|
"__event",
|
|
"__except",
|
|
"__fastcall",
|
|
"__finally",
|
|
"__forceinline",
|
|
"__gc",
|
|
"__hook",
|
|
"__identifier",
|
|
"__if_exists",
|
|
"__if_not_exists",
|
|
"__inline",
|
|
"__int128",
|
|
"__int16",
|
|
"__int32",
|
|
"__int64",
|
|
"__int8",
|
|
"__interface",
|
|
"__leave",
|
|
"__m128",
|
|
"__m128d",
|
|
"__m128i",
|
|
"__m256",
|
|
"__m256d",
|
|
"__m256i",
|
|
"__m64",
|
|
"__multiple_inheritance",
|
|
"__newslot",
|
|
"__nogc",
|
|
"__noop",
|
|
"__nounwind",
|
|
"__novtordisp",
|
|
"__pascal",
|
|
"__pin",
|
|
"__pragma",
|
|
"__property",
|
|
"__ptr32",
|
|
"__ptr64",
|
|
"__raise",
|
|
"__restrict",
|
|
"__resume",
|
|
"__sealed",
|
|
"__single_inheritance",
|
|
"__stdcall",
|
|
"__super",
|
|
"__thiscall",
|
|
"__try",
|
|
"__try_cast",
|
|
"__typeof",
|
|
"__unaligned",
|
|
"__unhook",
|
|
"__uuidof",
|
|
"__value",
|
|
"__virtual_inheritance",
|
|
"__w64",
|
|
"__wchar_t"
|
|
],
|
|
operators: [
|
|
"=",
|
|
">",
|
|
"<",
|
|
"!",
|
|
"~",
|
|
"?",
|
|
":",
|
|
"==",
|
|
"<=",
|
|
">=",
|
|
"!=",
|
|
"&&",
|
|
"||",
|
|
"++",
|
|
"--",
|
|
"+",
|
|
"-",
|
|
"*",
|
|
"/",
|
|
"&",
|
|
"|",
|
|
"^",
|
|
"%",
|
|
"<<",
|
|
">>",
|
|
">>>",
|
|
"+=",
|
|
"-=",
|
|
"*=",
|
|
"/=",
|
|
"&=",
|
|
"|=",
|
|
"^=",
|
|
"%=",
|
|
"<<=",
|
|
">>=",
|
|
">>>="
|
|
],
|
|
quickKey: [
|
|
{
|
|
label: "ifelse",
|
|
content: [
|
|
"if (${1:condition}) {",
|
|
" $0",
|
|
"} else {",
|
|
" ",
|
|
"}"
|
|
].join("\n")
|
|
},
|
|
{ label: "include", content: "include<$0>" },
|
|
{ label: "printf", content: "printf($0)" },
|
|
{ label: "system", content: 'system("$0")' },
|
|
{
|
|
label: "main",
|
|
content: [
|
|
"int main () {",
|
|
" $0",
|
|
"}"
|
|
].join("\n")
|
|
},
|
|
{
|
|
label: "if",
|
|
content: [
|
|
"if () {",
|
|
" $0",
|
|
"}"
|
|
].join("\n")
|
|
},
|
|
{
|
|
label: "for",
|
|
content: [
|
|
"for(int j=0 ; j<10; j++){",
|
|
" $0",
|
|
"}"
|
|
].join("\n")
|
|
},
|
|
{
|
|
label: "trycatch",
|
|
content: [
|
|
"try{",
|
|
" $0",
|
|
"}catch(ExceptionName e){",
|
|
"}"
|
|
].join("\n")
|
|
},
|
|
{
|
|
label: "using namespace std;",
|
|
content: [
|
|
"using namespace std;"
|
|
].join("\n")
|
|
},
|
|
{
|
|
label: "include <iostream>",
|
|
content: [
|
|
"#include <iostream>"
|
|
].join("\n")
|
|
},
|
|
{
|
|
label: "include <vector>",
|
|
content: [
|
|
"#include <vector>"
|
|
].join("\n")
|
|
},
|
|
{
|
|
label: "include <cstdio>",
|
|
content: [
|
|
"#include <cstdio>"
|
|
].join("\n")
|
|
},
|
|
{
|
|
label: "include <cstring>",
|
|
content: [
|
|
"#include <cstring>"
|
|
].join("\n")
|
|
},
|
|
{
|
|
label: "include <sstream>",
|
|
content: [
|
|
"#include <sstream>"
|
|
].join("\n")
|
|
},
|
|
{
|
|
label: "include <fstream>",
|
|
content: [
|
|
"#include <fstream>"
|
|
].join("\n")
|
|
},
|
|
{
|
|
label: "include <map>",
|
|
content: [
|
|
"#include <map>"
|
|
].join("\n")
|
|
},
|
|
{
|
|
label: "include <string>",
|
|
content: [
|
|
"#include <string>"
|
|
].join("\n")
|
|
},
|
|
{
|
|
label: "include <cmath>",
|
|
content: [
|
|
"#include <cmath>"
|
|
].join("\n")
|
|
}
|
|
]
|
|
};
|
|
const pythonLangage = {
|
|
keywords: [
|
|
"and",
|
|
"as",
|
|
"assert",
|
|
"break",
|
|
"class",
|
|
"continue",
|
|
"def",
|
|
"del",
|
|
"elif",
|
|
"else",
|
|
"except",
|
|
"exec",
|
|
"finally",
|
|
"for",
|
|
"from",
|
|
"global",
|
|
"if",
|
|
"import",
|
|
"in",
|
|
"is",
|
|
"lambda",
|
|
"None",
|
|
"not",
|
|
"or",
|
|
"pass",
|
|
"raise",
|
|
"return",
|
|
"self",
|
|
"try",
|
|
"while",
|
|
"with",
|
|
"yield",
|
|
"int",
|
|
"float",
|
|
"long",
|
|
"complex",
|
|
"hex",
|
|
"abs",
|
|
"all",
|
|
"any",
|
|
"apply",
|
|
"basestring",
|
|
"bin",
|
|
"bool",
|
|
"buffer",
|
|
"bytearray",
|
|
"callable",
|
|
"chr",
|
|
"classmethod",
|
|
"cmp",
|
|
"coerce",
|
|
"compile",
|
|
"complex",
|
|
"delattr",
|
|
"dict",
|
|
"dir",
|
|
"divmod",
|
|
"enumerate",
|
|
"eval",
|
|
"execfile",
|
|
"file",
|
|
"filter",
|
|
"format",
|
|
"frozenset",
|
|
"getattr",
|
|
"globals",
|
|
"hasattr",
|
|
"hash",
|
|
"help",
|
|
"id",
|
|
"input",
|
|
"intern",
|
|
"isinstance",
|
|
"issubclass",
|
|
"iter",
|
|
"len",
|
|
"locals",
|
|
"list",
|
|
"map",
|
|
"max",
|
|
"memoryview",
|
|
"min",
|
|
"next",
|
|
"object",
|
|
"oct",
|
|
"open",
|
|
"ord",
|
|
"pow",
|
|
"print",
|
|
"property",
|
|
"reversed",
|
|
"range",
|
|
"raw_input",
|
|
"reduce",
|
|
"reload",
|
|
"repr",
|
|
"reversed",
|
|
"round",
|
|
"set",
|
|
"setattr",
|
|
"slice",
|
|
"sorted",
|
|
"staticmethod",
|
|
"str",
|
|
"sum",
|
|
"super",
|
|
"tuple",
|
|
"type",
|
|
"unichr",
|
|
"unicode",
|
|
"vars",
|
|
"xrange",
|
|
"zip",
|
|
"True",
|
|
"False",
|
|
"__dict__",
|
|
"__methods__",
|
|
"__members__",
|
|
"__class__",
|
|
"__bases__",
|
|
"__name__",
|
|
"__mro__",
|
|
"__subclasses__",
|
|
"__init__",
|
|
"__import__"
|
|
],
|
|
quickKey: [
|
|
{
|
|
label: "print",
|
|
content: [
|
|
"print($0)"
|
|
].join("\n")
|
|
}
|
|
// { label: "#include", content: '#include ""' },
|
|
// { label: "printf", content: 'printf("")' },
|
|
]
|
|
};
|
|
const scalaLangage = {
|
|
keywords: [
|
|
"asInstanceOf",
|
|
"catch",
|
|
"class",
|
|
"classOf",
|
|
"def",
|
|
"do",
|
|
"else",
|
|
"extends",
|
|
"finally",
|
|
"for",
|
|
"foreach",
|
|
"forSome",
|
|
"if",
|
|
"import",
|
|
"isInstanceOf",
|
|
"macro",
|
|
"match",
|
|
"new",
|
|
"object",
|
|
"package",
|
|
"return",
|
|
"throw",
|
|
"trait",
|
|
"try",
|
|
"type",
|
|
"until",
|
|
"val",
|
|
"var",
|
|
"while",
|
|
"with",
|
|
"yield",
|
|
// Dotty-specific:
|
|
"given",
|
|
"enum",
|
|
"then"
|
|
],
|
|
quickKey: [
|
|
{
|
|
label: "println",
|
|
content: [
|
|
"println($0)"
|
|
].join("\n")
|
|
}
|
|
// { label: "#include", content: '#include ""' },
|
|
// { label: "printf", content: 'printf("")' },
|
|
]
|
|
};
|
|
|
|
// EXTERNAL MODULE: ./node_modules/_js-beautify@1.15.1@js-beautify/js/index.js
|
|
var js = __webpack_require__(86061);
|
|
var js_default = /*#__PURE__*/__webpack_require__.n(js);
|
|
;// CONCATENATED MODULE: ./src/components/monaco-editor/monaco-suggest-config.tsx
|
|
var __defProp = Object.defineProperty;
|
|
var __defProps = Object.defineProperties;
|
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
var __spreadValues = (a, b) => {
|
|
for (var prop in b || (b = {}))
|
|
if (__hasOwnProp.call(b, prop))
|
|
__defNormalProp(a, prop, b[prop]);
|
|
if (__getOwnPropSymbols)
|
|
for (var prop of __getOwnPropSymbols(b)) {
|
|
if (__propIsEnum.call(b, prop))
|
|
__defNormalProp(a, prop, b[prop]);
|
|
}
|
|
return a;
|
|
};
|
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
var __async = (__this, __arguments, generator) => {
|
|
return new Promise((resolve, reject) => {
|
|
var fulfilled = (value) => {
|
|
try {
|
|
step(generator.next(value));
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
};
|
|
var rejected = (value) => {
|
|
try {
|
|
step(generator.throw(value));
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
};
|
|
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
});
|
|
};
|
|
|
|
|
|
const baseConfig = {
|
|
languages: ["c", "abap", "apex", "azcli", "bat", "cameligo", "clojure", "coffee", "cpp", "csharp", "csp", "css", "dockerfile", "fsharp", "go", "graphql", "handlebars", "html", "ini", "java", "javascript", "json", "kotlin", "less", "lua", "markdown", "mips", "msdax", "mysql", "objective-c", "pascal", "pascaligo", "perl", "pgsql", "php", "postiats", "powerquery", "powershell", "pug", "python", "r", "razor", "redis", "redshift", "restructuredtext", "ruby", "rust", "sb", "scheme", "scss", "shell", "solidity", "sophia", "sql", "st", "swift", "tcl", "twig", "vb", "xml", "yaml'"],
|
|
tables: {
|
|
users: ["name", "id", "email", "phone", "password"],
|
|
roles: ["id", "name", "order", "created_at", "updated_at", "deleted_at"]
|
|
}
|
|
};
|
|
const getKeywordsSuggest = (monaco, keywords) => {
|
|
return keywords.map((key) => ({
|
|
label: key,
|
|
// 显示的名称
|
|
kind: monaco.languages.CompletionItemKind.Keyword,
|
|
insertText: key
|
|
// 真实补全的值
|
|
}));
|
|
};
|
|
const getTableSuggest = (monaco) => {
|
|
return Object.keys(baseConfig.tables).map((key) => ({
|
|
label: key,
|
|
// 显示的名称
|
|
kind: monaco.languages.CompletionItemKind.Variable,
|
|
insertText: key
|
|
// 真实补全的值
|
|
}));
|
|
};
|
|
const getFieldsSuggest = (tableName, monaco) => {
|
|
const fields = baseConfig.tables[tableName];
|
|
if (!fields) {
|
|
return [];
|
|
}
|
|
return fields.map((name) => ({
|
|
label: name,
|
|
kind: monaco.languages.CompletionItemKind.Field,
|
|
insertText: name
|
|
}));
|
|
};
|
|
function getSuggestions(monaco, model, position, keywords, snippts) {
|
|
let word = model.getWordUntilPosition(position);
|
|
let range = {
|
|
startLineNumber: position.lineNumber,
|
|
endLineNumber: position.lineNumber,
|
|
startColumn: word.startColumn,
|
|
endColumn: word.endColumn
|
|
};
|
|
let rs = keywords.map((item) => {
|
|
return {
|
|
label: item,
|
|
kind: monaco.languages.CompletionItemKind.Keyword,
|
|
insertText: item,
|
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
|
range
|
|
};
|
|
});
|
|
snippts.map((item) => {
|
|
rs.push(__spreadProps(__spreadValues({}, item), {
|
|
range
|
|
}));
|
|
});
|
|
return rs;
|
|
}
|
|
/* harmony default export */ var monaco_suggest_config = ((monaco) => {
|
|
baseConfig.languages.map((item) => {
|
|
monaco.languages.registerDocumentFormattingEditProvider(item, {
|
|
provideDocumentFormattingEdits(model, options, token) {
|
|
return __async(this, null, function* () {
|
|
const formattedText = js_default()(model.getValue(), {
|
|
"indent_size": "2",
|
|
"indent_char": " ",
|
|
"max_preserve_newlines": "2",
|
|
"preserve_newlines": true,
|
|
"keep_array_indentation": true,
|
|
"break_chained_methods": false,
|
|
"indent_scripts": "normal",
|
|
"brace_style": "collapse",
|
|
"space_before_conditional": true,
|
|
"unescape_strings": false,
|
|
"jslint_happy": false,
|
|
"end_with_newline": true,
|
|
"wrap_line_length": "0",
|
|
"indent_inner_html": false,
|
|
"comma_first": false,
|
|
"e4x": false,
|
|
"indent_empty_lines": false
|
|
});
|
|
return [
|
|
{
|
|
range: model.getFullModelRange(),
|
|
text: formattedText
|
|
}
|
|
];
|
|
});
|
|
}
|
|
});
|
|
return item;
|
|
});
|
|
const cppKeyPrompt = cppLangage.quickKey.map((item) => {
|
|
return {
|
|
label: item.label,
|
|
kind: monaco.languages.CompletionItemKind.Method,
|
|
insertText: item.content,
|
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet
|
|
};
|
|
});
|
|
const pythonKeyPrompt = pythonLangage.quickKey.map((item) => {
|
|
return {
|
|
label: item.label,
|
|
kind: monaco.languages.CompletionItemKind.Method,
|
|
insertText: item.content,
|
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet
|
|
};
|
|
});
|
|
const javaKeyPrompt = javaLangage.quickKey.map((item) => {
|
|
return {
|
|
label: item.label,
|
|
kind: monaco.languages.CompletionItemKind.Method,
|
|
insertText: item.content,
|
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet
|
|
};
|
|
});
|
|
monaco.languages.registerCompletionItemProvider("cpp", {
|
|
provideCompletionItems: function(model, position) {
|
|
var word = model.getWordUntilPosition(position);
|
|
var wordRange = {
|
|
startLineNumber: position.lineNumber,
|
|
endLineNumber: position.lineNumber,
|
|
startColumn: word.startColumn,
|
|
endColumn: word.endColumn
|
|
};
|
|
var value = model.getLineContent(position.lineNumber).substring(word.startColumn - 2, word.endColumn);
|
|
return {
|
|
suggestions: [
|
|
...cppLangage.keywords.map((item) => {
|
|
return {
|
|
label: item,
|
|
kind: monaco.languages.CompletionItemKind.Function,
|
|
documentation: item,
|
|
insertText: item,
|
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
|
range: wordRange
|
|
};
|
|
}),
|
|
...cppLangage.quickKey.map((item) => {
|
|
return {
|
|
label: item.label,
|
|
kind: monaco.languages.CompletionItemKind.Function,
|
|
documentation: item.content,
|
|
insertText: value.startsWith("#") ? item.content.replace(/#/, "") : item.content,
|
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
|
range: wordRange
|
|
};
|
|
})
|
|
]
|
|
};
|
|
}
|
|
});
|
|
monaco.languages.registerCompletionItemProvider("c", {
|
|
provideCompletionItems: function(model, position) {
|
|
var word = model.getWordUntilPosition(position);
|
|
var wordRange = {
|
|
startLineNumber: position.lineNumber,
|
|
endLineNumber: position.lineNumber,
|
|
startColumn: word.startColumn,
|
|
endColumn: word.endColumn
|
|
};
|
|
return {
|
|
suggestions: [
|
|
...cLangage.keywords.map((item) => {
|
|
return {
|
|
label: item,
|
|
kind: monaco.languages.CompletionItemKind.Function,
|
|
documentation: item,
|
|
insertText: item,
|
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
|
range: wordRange
|
|
};
|
|
})
|
|
]
|
|
};
|
|
}
|
|
});
|
|
monaco.languages.registerCompletionItemProvider("java", {
|
|
provideCompletionItems: function(model, position) {
|
|
var word = model.getWordUntilPosition(position);
|
|
var wordRange = {
|
|
startLineNumber: position.lineNumber,
|
|
endLineNumber: position.lineNumber,
|
|
startColumn: word.startColumn,
|
|
endColumn: word.endColumn
|
|
};
|
|
var value = model.getLineContent(position.lineNumber).substring(word.startColumn - 2, word.endColumn);
|
|
return {
|
|
suggestions: [
|
|
...javaLangage.keywords.map((item) => {
|
|
return {
|
|
label: item,
|
|
kind: monaco.languages.CompletionItemKind.Function,
|
|
documentation: item,
|
|
insertText: item,
|
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
|
range: wordRange
|
|
};
|
|
}),
|
|
...javaLangage.quickKey.map((item) => {
|
|
return {
|
|
label: item.label,
|
|
kind: monaco.languages.CompletionItemKind.Function,
|
|
documentation: item.content,
|
|
insertText: value.startsWith("#") ? item.content.replace(/#/, "") : item.content,
|
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
|
range: wordRange
|
|
};
|
|
})
|
|
]
|
|
};
|
|
}
|
|
});
|
|
monaco.languages.registerCompletionItemProvider("scala", {
|
|
provideCompletionItems: function(model, position) {
|
|
var word = model.getWordUntilPosition(position);
|
|
var wordRange = {
|
|
startLineNumber: position.lineNumber,
|
|
endLineNumber: position.lineNumber,
|
|
startColumn: word.startColumn,
|
|
endColumn: word.endColumn
|
|
};
|
|
var value = model.getLineContent(position.lineNumber).substring(word.startColumn - 2, word.endColumn);
|
|
return {
|
|
suggestions: [
|
|
...scalaLangage.keywords.map((item) => {
|
|
return {
|
|
label: item,
|
|
kind: monaco.languages.CompletionItemKind.Function,
|
|
documentation: item,
|
|
insertText: item,
|
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
|
range: wordRange
|
|
};
|
|
}),
|
|
...scalaLangage.quickKey.map((item) => {
|
|
return {
|
|
label: item.label,
|
|
kind: monaco.languages.CompletionItemKind.Function,
|
|
documentation: item.content,
|
|
insertText: value.startsWith("#") ? item.content.replace(/#/, "") : item.content,
|
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
|
range: wordRange
|
|
};
|
|
})
|
|
]
|
|
};
|
|
}
|
|
});
|
|
monaco.languages.registerCompletionItemProvider("python", {
|
|
provideCompletionItems: function(model, position) {
|
|
var word = model.getWordUntilPosition(position);
|
|
var wordRange = {
|
|
startLineNumber: position.lineNumber,
|
|
endLineNumber: position.lineNumber,
|
|
startColumn: word.startColumn,
|
|
endColumn: word.endColumn
|
|
};
|
|
var value = model.getLineContent(position.lineNumber).substring(word.startColumn - 2, word.endColumn);
|
|
return {
|
|
suggestions: [
|
|
...pythonLangage.keywords.map((item) => {
|
|
return {
|
|
label: item,
|
|
kind: monaco.languages.CompletionItemKind.Function,
|
|
documentation: item,
|
|
insertText: item,
|
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
|
range: wordRange
|
|
};
|
|
}),
|
|
...pythonLangage.quickKey.map((item) => {
|
|
return {
|
|
label: item.label,
|
|
kind: monaco.languages.CompletionItemKind.Function,
|
|
documentation: item.content,
|
|
insertText: value.startsWith("#") ? item.content.replace(/#/, "") : item.content,
|
|
insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet,
|
|
range: wordRange
|
|
};
|
|
})
|
|
]
|
|
};
|
|
}
|
|
});
|
|
});
|
|
const tipTxt = "\u8BE5\u4EFB\u52A1\u5173\u5361\u8BBE\u7F6E\u4E86\u7981\u6B62\u590D\u5236\u7C98\u8D34\uFF0C\u8BF7\u624B\u52A8\u8F93\u5165\u4EE3\u7801\u3002";
|
|
|
|
;// CONCATENATED MODULE: ./src/components/monaco-editor/placeholder.js
|
|
var placeholder_defProp = Object.defineProperty;
|
|
var placeholder_defNormalProp = (obj, key, value) => key in obj ? placeholder_defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
var __publicField = (obj, key, value) => {
|
|
placeholder_defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
return value;
|
|
};
|
|
const _PlaceholderContentWidget = class {
|
|
constructor(placeholder, editor, monaco) {
|
|
this.placeholder = placeholder;
|
|
this.editor = editor;
|
|
this.monaco = monaco;
|
|
editor.onDidChangeModelContent(() => this.onDidChangeModelContent());
|
|
this.onDidChangeModelContent();
|
|
}
|
|
onDidChangeModelContent() {
|
|
if (this.editor.getValue() === "") {
|
|
this.editor.addContentWidget(this);
|
|
} else {
|
|
this.editor.removeContentWidget(this);
|
|
}
|
|
}
|
|
getId() {
|
|
return _PlaceholderContentWidget.ID;
|
|
}
|
|
getDomNode() {
|
|
if (!this.domNode) {
|
|
this.domNode = document.createElement("div");
|
|
this.domNode.style.width = "max-content";
|
|
this.domNode.textContent = this.placeholder;
|
|
this.domNode.style.fontStyle = "initial";
|
|
this.domNode.style.color = "#D7D7D7";
|
|
this.domNode.style.pointerEvents = "none";
|
|
this.editor.applyFontInfo(this.domNode);
|
|
}
|
|
return this.domNode;
|
|
}
|
|
getPosition() {
|
|
return {
|
|
position: { lineNumber: 1, column: 1 },
|
|
preference: [this.monaco.editor.ContentWidgetPositionPreference.EXACT]
|
|
};
|
|
}
|
|
dispose() {
|
|
this.editor.removeContentWidget(this);
|
|
}
|
|
};
|
|
let PlaceholderContentWidget = _PlaceholderContentWidget;
|
|
__publicField(PlaceholderContentWidget, "ID", "editor.widget.placeholderHint");
|
|
/* harmony default export */ var monaco_editor_placeholder = (PlaceholderContentWidget);
|
|
|
|
// EXTERNAL MODULE: ./node_modules/_monaco-editor@0.30.0@monaco-editor/esm/vs/platform/actions/common/actions.js
|
|
var actions = __webpack_require__(96236);
|
|
// EXTERNAL MODULE: ./node_modules/_antd@5.9.0@antd/es/message/index.js + 4 modules
|
|
var message = __webpack_require__(8591);
|
|
// EXTERNAL MODULE: ./node_modules/_lodash@4.17.21@lodash/lodash.js
|
|
var lodash = __webpack_require__(89392);
|
|
// EXTERNAL MODULE: ./src/components/mediator.js
|
|
var mediator = __webpack_require__(50993);
|
|
;// CONCATENATED MODULE: ./src/components/monaco-editor/index.css
|
|
// extracted by mini-css-extract-plugin
|
|
|
|
;// CONCATENATED MODULE: ./src/components/monaco-editor/index.jsx
|
|
var monaco_editor_defProp = Object.defineProperty;
|
|
var monaco_editor_defProps = Object.defineProperties;
|
|
var monaco_editor_getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
var monaco_editor_getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
var monaco_editor_hasOwnProp = Object.prototype.hasOwnProperty;
|
|
var monaco_editor_propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
var monaco_editor_defNormalProp = (obj, key, value) => key in obj ? monaco_editor_defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
var monaco_editor_spreadValues = (a, b) => {
|
|
for (var prop in b || (b = {}))
|
|
if (monaco_editor_hasOwnProp.call(b, prop))
|
|
monaco_editor_defNormalProp(a, prop, b[prop]);
|
|
if (monaco_editor_getOwnPropSymbols)
|
|
for (var prop of monaco_editor_getOwnPropSymbols(b)) {
|
|
if (monaco_editor_propIsEnum.call(b, prop))
|
|
monaco_editor_defNormalProp(a, prop, b[prop]);
|
|
}
|
|
return a;
|
|
};
|
|
var monaco_editor_spreadProps = (a, b) => monaco_editor_defProps(a, monaco_editor_getOwnPropDescs(b));
|
|
var __objRest = (source, exclude) => {
|
|
var target = {};
|
|
for (var prop in source)
|
|
if (monaco_editor_hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
target[prop] = source[prop];
|
|
if (source != null && monaco_editor_getOwnPropSymbols)
|
|
for (var prop of monaco_editor_getOwnPropSymbols(source)) {
|
|
if (exclude.indexOf(prop) < 0 && monaco_editor_propIsEnum.call(source, prop))
|
|
target[prop] = source[prop];
|
|
}
|
|
return target;
|
|
};
|
|
var monaco_editor_async = (__this, __arguments, generator) => {
|
|
return new Promise((resolve, reject) => {
|
|
var fulfilled = (value) => {
|
|
try {
|
|
step(generator.next(value));
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
};
|
|
var rejected = (value) => {
|
|
try {
|
|
step(generator.throw(value));
|
|
} catch (e) {
|
|
reject(e);
|
|
}
|
|
};
|
|
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
});
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function processSize(size) {
|
|
return !/^\d+$/.test(size) ? size : `${size}px`;
|
|
}
|
|
function noop() {
|
|
}
|
|
let __prevent_trigger_change_event = false;
|
|
const DICT = {
|
|
"Python3.6": "python",
|
|
"Python2.7": "python",
|
|
Dynamips: "cpp",
|
|
Java: "java",
|
|
Web: "php",
|
|
Html: "html",
|
|
Hive: "sql",
|
|
Hadoop: "java",
|
|
SDL: "cpp",
|
|
PHP: "php",
|
|
Matlab: "python",
|
|
Git: "python",
|
|
Python: "python",
|
|
"C/C++": "cpp",
|
|
"C++": "cpp",
|
|
C: "cpp",
|
|
Ruby: "ruby",
|
|
Shell: "shell",
|
|
JavaScript: "javascript",
|
|
Perl6: "perl",
|
|
Kotlin: "kotlin",
|
|
Elixir: "elixir",
|
|
Android: "java",
|
|
JavaWeb: "java",
|
|
Go: "go",
|
|
Spark: "sql",
|
|
MachineLearning: "python",
|
|
Verilog: "xml",
|
|
"Verilog/VNC": "xml",
|
|
Docker: "dockerfile",
|
|
"C#": "csharp",
|
|
SQLite3: "sql",
|
|
Oracle: "sql",
|
|
Vhdl: "vhdl",
|
|
R: "r",
|
|
Swift: "swift",
|
|
SQLServer: "mysql",
|
|
MySQL: "mysql",
|
|
Mongo: "sql",
|
|
PostgreSql: "pgsql",
|
|
Hbase: "powershell",
|
|
Sqoop: "sql",
|
|
Nasm: "cpp",
|
|
Kafka: "java",
|
|
Flink: "java",
|
|
Sml: "javascript",
|
|
OpenGL: "cpp",
|
|
Perl5: "perl",
|
|
Orange: "python",
|
|
Scala: "scale",
|
|
solidity: "sol"
|
|
};
|
|
function getLanguageByMirrorName(mirror_name = []) {
|
|
let lang = mirror_name;
|
|
if (Array.isArray(mirror_name)) {
|
|
for (let i = 0; i < mirror_name.length; i++) {
|
|
let languageVal = DICT[mirror_name[i]];
|
|
if (languageVal) {
|
|
return languageVal;
|
|
}
|
|
}
|
|
return lang[0];
|
|
}
|
|
return DICT[lang] || lang;
|
|
}
|
|
let monaco = null;
|
|
/* harmony default export */ var monaco_editor = ((_a) => {
|
|
var _b = _a, {
|
|
width = "100%",
|
|
height = "100%",
|
|
value,
|
|
language = "javascript",
|
|
style = {},
|
|
options = {},
|
|
overrideServices = {},
|
|
theme = "vs-dark",
|
|
onEditBlur,
|
|
onSave,
|
|
autoHeight = false,
|
|
forbidCopy = false,
|
|
onChange = noop,
|
|
editorDidMount = noop,
|
|
onFocus = noop,
|
|
onBreakPoint = noop,
|
|
breakPointValue = [],
|
|
filename = "educoder.txt",
|
|
errorLine,
|
|
errorContent = "",
|
|
highlightLine,
|
|
openBreakPoint = false,
|
|
placeholder = ""
|
|
} = _b, props = __objRest(_b, [
|
|
"width",
|
|
"height",
|
|
"value",
|
|
"language",
|
|
"style",
|
|
"options",
|
|
"overrideServices",
|
|
"theme",
|
|
"onEditBlur",
|
|
"onSave",
|
|
"autoHeight",
|
|
"forbidCopy",
|
|
"onChange",
|
|
"editorDidMount",
|
|
"onFocus",
|
|
"onBreakPoint",
|
|
"breakPointValue",
|
|
"filename",
|
|
"errorLine",
|
|
"errorContent",
|
|
"highlightLine",
|
|
"openBreakPoint",
|
|
"placeholder"
|
|
]);
|
|
const editorEl = (0,_react_17_0_2_react.useRef)();
|
|
const editor = (0,_react_17_0_2_react.useRef)({});
|
|
const optionsRef = (0,_react_17_0_2_react.useRef)();
|
|
const timeRef = (0,_react_17_0_2_react.useRef)();
|
|
const breakpointsFake = (0,_react_17_0_2_react.useRef)([]);
|
|
const inputLock = (0,_react_17_0_2_react.useRef)(false);
|
|
const inputLockTime = (0,_react_17_0_2_react.useRef)();
|
|
const noAllowTime = (0,_react_17_0_2_react.useRef)();
|
|
const [init, setInit] = (0,_react_17_0_2_react.useState)(false);
|
|
function onLayout() {
|
|
let ro;
|
|
if (editorEl.current) {
|
|
ro = new ResizeObserver_es/* default */.Z((entries) => {
|
|
for (let entry of entries) {
|
|
if (entry.target.offsetHeight > 0 || entry.target.offsetWidth > 0) {
|
|
editor.current.instance.layout();
|
|
}
|
|
}
|
|
});
|
|
ro.observe(editorEl.current);
|
|
}
|
|
return ro;
|
|
}
|
|
function tipWarn() {
|
|
message/* default */.ZP.warning({
|
|
content: decodeURIComponent(tipTxt),
|
|
key: "monaco-editor-tip"
|
|
});
|
|
}
|
|
const setCodeValue = () => {
|
|
let instance = editor.current.instance;
|
|
if (value != null && instance && init) {
|
|
const model = instance.getModel();
|
|
if (model && value !== model.getValue()) {
|
|
__prevent_trigger_change_event = true;
|
|
model.setValue(value);
|
|
instance.layout();
|
|
__prevent_trigger_change_event = false;
|
|
}
|
|
}
|
|
};
|
|
(0,_react_17_0_2_react.useEffect)(() => {
|
|
const unSub = mediator/* default */.Z.subscribe("formatDocument", (status) => {
|
|
var _a2;
|
|
let instance = editor.current.instance;
|
|
(_a2 = instance == null ? void 0 : instance.getAction) == null ? void 0 : _a2.call(instance, "editor.action.formatDocument").run();
|
|
});
|
|
window.updateMonacoValue = (value2) => {
|
|
onChange(value2);
|
|
};
|
|
return unSub;
|
|
}, []);
|
|
(0,_react_17_0_2_react.useEffect)(() => {
|
|
var _a2;
|
|
let instance = editor.current.instance;
|
|
if (timeRef.current)
|
|
clearTimeout(timeRef.current);
|
|
timeRef.current = setTimeout(() => {
|
|
setCodeValue();
|
|
}, 500);
|
|
if (value && !!(value == null ? void 0 : value.length)) {
|
|
(_a2 = instance == null ? void 0 : instance.updateOptions) == null ? void 0 : _a2.call(instance, {
|
|
lineNumbersMinChars: Math.max(Math.floor(Math.log10(value.split(/\r\n|\r|\n/g).length)) + 3, 5)
|
|
});
|
|
}
|
|
}, [value, init, editor.current]);
|
|
(0,_react_17_0_2_react.useEffect)(() => {
|
|
if (errorLine && editor.current && editor.current.instance) {
|
|
let instance = editor.current.instance;
|
|
instance.changeViewZones(function(changeAccessor) {
|
|
var domNode = document.createElement("div");
|
|
domNode.style.padding = "10px 20px";
|
|
domNode.style.width = "calc(100% - 20px)";
|
|
domNode.className = "my-error-line-wrp";
|
|
domNode.innerHTML = errorContent;
|
|
changeAccessor.addZone({
|
|
afterLineNumber: errorLine || 11,
|
|
heightInLines: 3,
|
|
domNode
|
|
});
|
|
});
|
|
var overlayWidget = {
|
|
domNode: null,
|
|
getId: function() {
|
|
return "my.overlay.widget";
|
|
},
|
|
getDomNode: function() {
|
|
if (!this.domNode) {
|
|
this.domNode = document.createElement("div");
|
|
this.domNode.innerHTML = "";
|
|
this.domNode.style.width = "100%";
|
|
this.domNode.style.padding = "20px 100px";
|
|
this.domNode.style.right = "0px";
|
|
this.domNode.style.top = "50px";
|
|
this.domNode.style.position = "relative";
|
|
this.domNode.style.color = "#333";
|
|
}
|
|
return this.domNode;
|
|
},
|
|
getPosition: function() {
|
|
return null;
|
|
}
|
|
};
|
|
instance.addOverlayWidget(overlayWidget);
|
|
instance.revealPositionInCenter({ lineNumber: 20, column: 1 });
|
|
}
|
|
}, [errorLine, editor.current, init]);
|
|
const noAllow = (str = "", lineNumber) => {
|
|
if (!str || str.trim() === "") {
|
|
return true;
|
|
}
|
|
const model = editor.current.instance.getModel();
|
|
const lineTokens = model.getLineTokens(lineNumber);
|
|
let comment = false;
|
|
for (let i = 0; i < 2; i++) {
|
|
if (lineTokens.getStandardTokenType(i) === 1) {
|
|
comment = true;
|
|
}
|
|
}
|
|
return comment;
|
|
};
|
|
(0,_react_17_0_2_react.useEffect)(() => {
|
|
var _a2;
|
|
if (((_a2 = editor.current) == null ? void 0 : _a2.instance) && init && openBreakPoint) {
|
|
let instance = editor.current.instance;
|
|
let model = instance.getModel();
|
|
if (!model)
|
|
return;
|
|
const dealHighlightLine = () => {
|
|
var _a3;
|
|
let lines = [];
|
|
let ids = [];
|
|
const decorations = model.getAllDecorations();
|
|
for (let decoration of decorations) {
|
|
if (decoration.options.className === "highlighted-line") {
|
|
lines.push((_a3 = decoration == null ? void 0 : decoration.range) == null ? void 0 : _a3.startLineNumber);
|
|
ids.push(decoration == null ? void 0 : decoration.id);
|
|
}
|
|
}
|
|
if (highlightLine === lines[0])
|
|
return;
|
|
model.deltaDecorations(ids, []);
|
|
const lineCount = model.getLineCount();
|
|
if (!!highlightLine && highlightLine <= lineCount) {
|
|
instance.deltaDecorations([], [
|
|
{
|
|
range: new monaco.Range(highlightLine, 1, highlightLine, model.getLineMaxColumn(highlightLine)),
|
|
options: { isWholeLine: true, className: "highlighted-line" }
|
|
}
|
|
]);
|
|
instance.revealLineInCenter(highlightLine);
|
|
}
|
|
};
|
|
dealHighlightLine();
|
|
const dealBreakPoint = (isReturn = false) => {
|
|
var _a3;
|
|
let lines = [];
|
|
let ids = [];
|
|
const decorations = model.getAllDecorations();
|
|
for (let decoration of decorations) {
|
|
if (decoration.options.linesDecorationsClassName === "breakpoints-select") {
|
|
lines.push((_a3 = decoration == null ? void 0 : decoration.range) == null ? void 0 : _a3.startLineNumber);
|
|
ids.push(decoration == null ? void 0 : decoration.id);
|
|
}
|
|
}
|
|
if (isReturn)
|
|
return {
|
|
lines,
|
|
ids
|
|
};
|
|
onBreakPoint(lines);
|
|
};
|
|
const addBreakPoint = (line) => monaco_editor_async(void 0, null, function* () {
|
|
let value2 = { range: new monaco.Range(line, 1, line, 1), options: { isWholeLine: false, linesDecorationsClassName: "breakpoints-select" } };
|
|
yield model.deltaDecorations([], [value2]);
|
|
dealBreakPoint();
|
|
});
|
|
const removeBreakPoint = (line) => monaco_editor_async(void 0, null, function* () {
|
|
let ids = [];
|
|
const decorations = instance.getLineDecorations(line);
|
|
for (let decoration of decorations) {
|
|
if (decoration.options.linesDecorationsClassName === "breakpoints-select") {
|
|
ids.push(decoration.id);
|
|
}
|
|
}
|
|
yield model.deltaDecorations(ids, []);
|
|
dealBreakPoint();
|
|
});
|
|
const hasBreakPoint = (line) => {
|
|
let decorations = instance.getLineDecorations(line);
|
|
for (let decoration of decorations) {
|
|
if (decoration.options.linesDecorationsClassName === "breakpoints-select") {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
if (!(0,lodash.isEqual)(breakPointValue, dealBreakPoint(true).lines)) {
|
|
model.deltaDecorations(dealBreakPoint(true).ids, []);
|
|
const values = breakPointValue.map((line) => {
|
|
return { range: new monaco.Range(line, 1, line, 1), options: { isWholeLine: false, linesDecorationsClassName: "breakpoints-select" } };
|
|
});
|
|
model.deltaDecorations([], values);
|
|
}
|
|
const elModelContent = instance.onDidChangeModelContent((e) => {
|
|
let pos = instance.getPosition();
|
|
if (pos) {
|
|
let line = pos.lineNumber;
|
|
clearTimeout(noAllowTime.current);
|
|
noAllowTime.current = setTimeout(() => {
|
|
if (noAllow(model.getLineContent(line), line)) {
|
|
removeBreakPoint(line);
|
|
} else if (hasBreakPoint(line)) {
|
|
removeBreakPoint(line);
|
|
addBreakPoint(line);
|
|
} else {
|
|
dealBreakPoint();
|
|
}
|
|
}, 100);
|
|
}
|
|
});
|
|
const elMouseDown = instance.onMouseDown((e) => {
|
|
var _a3, _b2, _c;
|
|
if (e.target.detail && ((_c = (_b2 = (_a3 = e.target) == null ? void 0 : _a3.element) == null ? void 0 : _b2.className) == null ? void 0 : _c.includes("line-numbers"))) {
|
|
let line = e.target.position.lineNumber;
|
|
if (noAllow(model.getLineContent(line), line)) {
|
|
return;
|
|
}
|
|
if (!hasBreakPoint(line)) {
|
|
addBreakPoint(line);
|
|
} else {
|
|
removeBreakPoint(line);
|
|
}
|
|
}
|
|
});
|
|
const addFakeBreakPoint = (line) => {
|
|
let value2 = { range: new monaco.Range(line, 1, line, 1), options: { isWholeLine: false, linesDecorationsClassName: "breakpoints-fake" } };
|
|
breakpointsFake.current = instance.deltaDecorations(breakpointsFake.current, [value2]);
|
|
};
|
|
const removeFakeBreakPoint = () => {
|
|
breakpointsFake.current = instance.deltaDecorations(breakpointsFake.current, []);
|
|
};
|
|
const elMouseMove = instance.onMouseMove((e) => {
|
|
var _a3, _b2, _c;
|
|
removeFakeBreakPoint();
|
|
if (e.target.detail && ((_c = (_b2 = (_a3 = e.target) == null ? void 0 : _a3.element) == null ? void 0 : _b2.className) == null ? void 0 : _c.includes("line-numbers"))) {
|
|
let line = e.target.position.lineNumber;
|
|
if (noAllow(model.getLineContent(line), line)) {
|
|
return;
|
|
}
|
|
addFakeBreakPoint(line);
|
|
}
|
|
});
|
|
const elMouseLeave = instance.onMouseLeave(() => {
|
|
removeFakeBreakPoint();
|
|
});
|
|
return () => {
|
|
elModelContent.dispose();
|
|
elMouseDown.dispose();
|
|
elMouseMove.dispose();
|
|
elMouseLeave.dispose();
|
|
};
|
|
}
|
|
}, [editor.current, init, breakPointValue, highlightLine, openBreakPoint, language]);
|
|
(0,_react_17_0_2_react.useEffect)(() => {
|
|
var _a2;
|
|
if (((_a2 = editor.current) == null ? void 0 : _a2.instance) && openBreakPoint) {
|
|
editor.current.instance.setPosition({ lineNumber: 0, column: 0 });
|
|
}
|
|
}, [highlightLine]);
|
|
function onPaste() {
|
|
let instance = editor.current.instance;
|
|
if (instance) {
|
|
const selection = instance.getSelection();
|
|
const pastePos = editor.current.pastePos || {};
|
|
const range = new monaco.Range(
|
|
pastePos.startLineNumber || selection.endLineNumber,
|
|
pastePos.startColumn || selection.endColumn,
|
|
pastePos.endLineNumber || selection.endLineNumber,
|
|
pastePos.endColumn || selection.endColumn
|
|
);
|
|
setTimeout(() => {
|
|
instance.executeEdits("", [{ range, text: "" }]);
|
|
}, 300);
|
|
}
|
|
}
|
|
function onSaveHandler(e) {
|
|
if ((window.navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey) && e.keyCode == 83) {
|
|
e.preventDefault();
|
|
onSave();
|
|
}
|
|
}
|
|
const autoCalcHeight = () => {
|
|
if (autoHeight && editor.current.instance) {
|
|
const _height = editor.current.instance.getContentHeight();
|
|
setFixedHeight(_height < height ? height : _height);
|
|
} else {
|
|
setFixedHeight(height);
|
|
}
|
|
};
|
|
function fakeClick(obj) {
|
|
var ev = document.createEvent("MouseEvents");
|
|
ev.initMouseEvent(
|
|
"click",
|
|
true,
|
|
false,
|
|
window,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
0,
|
|
false,
|
|
false,
|
|
false,
|
|
false,
|
|
0,
|
|
null
|
|
);
|
|
obj.dispatchEvent(ev);
|
|
}
|
|
const checkPaste2 = (event) => {
|
|
const { keyCode, ctrlKey, metaKey, target, type } = event;
|
|
if ((type === "paste" || (keyCode === 67 || keyCode === 86) && (metaKey || ctrlKey)) && target.nodeName === "TEXTAREA") {
|
|
tipWarn();
|
|
event.preventDefault();
|
|
}
|
|
return false;
|
|
};
|
|
function exportRaw(name, data) {
|
|
var urlObject = window.URL || window.webkitURL || window;
|
|
var export_blob = new Blob([data]);
|
|
var save_link = document.createElementNS(
|
|
"http://www.w3.org/1999/xhtml",
|
|
"a"
|
|
);
|
|
save_link.href = urlObject.createObjectURL(export_blob);
|
|
save_link.download = name;
|
|
fakeClick(save_link);
|
|
}
|
|
(0,_react_17_0_2_react.useEffect)(() => {
|
|
autoCalcHeight();
|
|
}, [autoCalcHeight]);
|
|
(0,_react_17_0_2_react.useEffect)(() => {
|
|
if (editorEl.current && !init) {
|
|
__webpack_require__.e(/*! import() */ 1216).then(__webpack_require__.bind(__webpack_require__, /*! monaco-editor */ 71448)).then((mod) => {
|
|
try {
|
|
monaco = mod;
|
|
editor.current.instance = monaco.editor.create(
|
|
editorEl.current,
|
|
{
|
|
value,
|
|
language: getLanguageByMirrorName(language),
|
|
theme,
|
|
requireConfig: {
|
|
"vs/nls": { availableLanguages: { "*": "zh-cn" } }
|
|
},
|
|
wordWrap: true,
|
|
autoIndent: true,
|
|
contextmenu: true,
|
|
// formatOnPaste: true,
|
|
formatOnType: true
|
|
},
|
|
overrideServices
|
|
);
|
|
const instance = editor.current.instance;
|
|
let menus = actions/* MenuRegistry */.BH._menuItems;
|
|
let contextMenuEntry = [...menus].find((entry) => entry[0]._debugName == "EditorContext");
|
|
let contextMenuLinks = contextMenuEntry[1];
|
|
let removableIds = ["editor.action.clipboardCopyWithSyntaxHighlightingAction", "editor.action.quickCommand", "editor.action.clipboardCopyAction", "editor.action.clipboardPasteAction", "editor.action.clipboardCutAction"];
|
|
let removeById = (list, ids) => {
|
|
var _a2, _b2;
|
|
let node = list._first;
|
|
do {
|
|
let shouldRemove = ids.includes((_b2 = (_a2 = node.element) == null ? void 0 : _a2.command) == null ? void 0 : _b2.id);
|
|
if (shouldRemove) {
|
|
list._remove(node);
|
|
}
|
|
} while (node = node.next);
|
|
};
|
|
editorDidMount(instance, monaco);
|
|
setTimeout(() => {
|
|
autoCalcHeight();
|
|
editor.current.instance.addAction({
|
|
id: "d123123",
|
|
label: "Download File",
|
|
contextMenuGroupId: "9_cutcopypaste",
|
|
run: () => {
|
|
exportRaw(filename || "educoder.txt", instance.getValue());
|
|
}
|
|
});
|
|
}, 500);
|
|
editor.current.subscription = instance.onDidChangeModelContent(
|
|
(event) => {
|
|
if (!inputLock.current) {
|
|
autoCalcHeight();
|
|
onChange(instance.getValue(), event);
|
|
} else {
|
|
clearTimeout(inputLockTime.current);
|
|
}
|
|
inputLockTime.current = setTimeout(() => {
|
|
inputLock.current = false;
|
|
}, 500);
|
|
}
|
|
);
|
|
if (!window.Monaco)
|
|
monaco_suggest_config(monaco, getLanguageByMirrorName(language));
|
|
if (forbidCopy) {
|
|
removeById(contextMenuLinks, removableIds);
|
|
editorEl.current.classList.add("noCopyPaste");
|
|
window.removeEventListener("keydown", checkPaste2);
|
|
window.removeEventListener("paste", checkPaste2);
|
|
window.addEventListener("keydown", checkPaste2);
|
|
window.addEventListener("paste", checkPaste2);
|
|
}
|
|
window.Monaco = monaco;
|
|
if (onEditBlur) {
|
|
instance.onDidBlurEditorWidget(() => {
|
|
onEditBlur(instance.getValue());
|
|
});
|
|
}
|
|
if (onFocus) {
|
|
instance.onDidFocusEditorText(() => {
|
|
onFocus(instance.getValue());
|
|
});
|
|
}
|
|
if (forbidCopy) {
|
|
try {
|
|
instance.onDidPaste((event) => {
|
|
const selection = instance.getSelection();
|
|
const pastePos = editor.current.pastePos || {};
|
|
const range = new monaco.Range(
|
|
pastePos.startLineNumber || selection.endLineNumber,
|
|
pastePos.startColumn || selection.endColumn,
|
|
pastePos.endLineNumber || selection.endLineNumber,
|
|
pastePos.endColumn || selection.endColumn
|
|
);
|
|
instance.executeEdits("", [{ range: event.range, text: "" }]);
|
|
});
|
|
} catch (e) {
|
|
}
|
|
}
|
|
let ro = onLayout();
|
|
if (placeholder && typeof placeholder === "string") {
|
|
new monaco_editor_placeholder(placeholder, instance, monaco);
|
|
}
|
|
setInit(true);
|
|
return () => {
|
|
const el = editor.current.instance;
|
|
el.dispose();
|
|
const model = el.getModel();
|
|
if (model) {
|
|
model.dispose();
|
|
}
|
|
if (editor.current.subscription) {
|
|
editor.current.subscription.dispose();
|
|
}
|
|
ro.unobserve(editorEl.current);
|
|
};
|
|
} catch (e) {
|
|
}
|
|
});
|
|
}
|
|
}, []);
|
|
(0,_react_17_0_2_react.useEffect)(() => {
|
|
let instance = editor.current.instance;
|
|
if (instance && init) {
|
|
document.addEventListener("keydown", onSaveHandler, false);
|
|
return () => {
|
|
document.removeEventListener("keydown", onSaveHandler);
|
|
};
|
|
}
|
|
}, [onSave, init]);
|
|
(0,_react_17_0_2_react.useEffect)(() => {
|
|
let instance = editor.current.instance;
|
|
if (instance && init) {
|
|
let lang = getLanguageByMirrorName(language);
|
|
monaco.editor.setModelLanguage(instance.getModel(), lang);
|
|
}
|
|
}, [language, init]);
|
|
(0,_react_17_0_2_react.useEffect)(() => {
|
|
let instance = editor.current.instance;
|
|
if (instance && init) {
|
|
monaco.editor.setTheme(theme);
|
|
}
|
|
}, [theme, init]);
|
|
(0,_react_17_0_2_react.useEffect)(() => {
|
|
let instance = editor.current.instance;
|
|
optionsRef.current = options;
|
|
if (instance && init) {
|
|
instance.updateOptions(monaco_editor_spreadValues({}, options));
|
|
setTimeout(() => {
|
|
instance.getModel().updateOptions(monaco_editor_spreadValues({}, options));
|
|
}, 200);
|
|
}
|
|
}, [JSON.stringify(options), init]);
|
|
(0,_react_17_0_2_react.useEffect)(() => {
|
|
let instance = editor.current.instance;
|
|
if (instance && init) {
|
|
instance.layout();
|
|
}
|
|
}, [width, height, init]);
|
|
const [fixedWidth, setFixedWidth] = (0,_react_17_0_2_react.useState)(processSize(width));
|
|
const [fixedHeight, setFixedHeight] = (0,_react_17_0_2_react.useState)(processSize(height));
|
|
const mergeStyle = monaco_editor_spreadProps(monaco_editor_spreadValues({}, style), {
|
|
width: fixedWidth,
|
|
height: fixedHeight
|
|
});
|
|
return /* @__PURE__ */ _react_17_0_2_react.createElement("div", { className: "my-monaco-editor", ref: editorEl, style: mergeStyle });
|
|
});
|
|
function DiffEditor({
|
|
width = "100%",
|
|
height = "100%",
|
|
original,
|
|
modified,
|
|
language,
|
|
options = {}
|
|
}) {
|
|
const editorEl = (0,_react_17_0_2_react.useRef)();
|
|
const [instance, setInstance] = (0,_react_17_0_2_react.useState)(null);
|
|
function onLayout(instance2) {
|
|
let ro;
|
|
if (editorEl.current) {
|
|
ro = new ResizeObserver_es/* default */.Z((entries) => {
|
|
for (let entry of entries) {
|
|
if (entry.target.offsetHeight > 0 || entry.target.offsetWidth > 0) {
|
|
instance2.layout();
|
|
}
|
|
}
|
|
});
|
|
ro.observe(editorEl.current);
|
|
}
|
|
return ro;
|
|
}
|
|
(0,_react_17_0_2_react.useEffect)(() => {
|
|
if (editorEl.current) {
|
|
__webpack_require__.e(/*! import() | monaco-editor */ 1216).then(__webpack_require__.bind(__webpack_require__, /*! monaco-editor/esm/vs/editor/editor.api.js */ 2550)).then((mod) => {
|
|
monaco = mod;
|
|
const instance2 = monaco.editor.createDiffEditor(editorEl.current, monaco_editor_spreadProps(monaco_editor_spreadValues({
|
|
enableSplitViewResizing: false,
|
|
scrollBeyondLastLine: false,
|
|
roundedSelection: false,
|
|
renderIndicators: false,
|
|
useShadows: false,
|
|
horizontal: "hidden",
|
|
lineNumbers: "off",
|
|
wordWrap: "off",
|
|
ignoreTrimWhitespace: false,
|
|
"semanticHighlighting.enabled": true,
|
|
followsCaret: true,
|
|
// resets the navigator state when the user selects something in the editor
|
|
ignoreCharChanges: true,
|
|
// jump from line to line,
|
|
minimap: {
|
|
enabled: false
|
|
},
|
|
readOnly: true
|
|
}, options), {
|
|
wordWrap: true
|
|
}));
|
|
setInstance(instance2);
|
|
let ro = onLayout(instance2);
|
|
return () => {
|
|
instance2.dispose();
|
|
const model = instance2.getModel();
|
|
if (model) {
|
|
model.dispose();
|
|
}
|
|
ro.unobserve(editorEl.current);
|
|
};
|
|
});
|
|
}
|
|
return () => {
|
|
window.removeEventListener("keydown", checkPaste);
|
|
window.removeEventListener("paste", checkPaste);
|
|
};
|
|
}, []);
|
|
(0,_react_17_0_2_react.useEffect)(() => {
|
|
if (instance) {
|
|
instance.setModel({
|
|
original: monaco.editor.createModel(original, language),
|
|
modified: monaco.editor.createModel(modified, language)
|
|
});
|
|
}
|
|
}, [original, modified, language, instance]);
|
|
const fixedWidth = processSize(width);
|
|
const fixedHeight = processSize(height);
|
|
const style = {
|
|
width: fixedWidth,
|
|
height: fixedHeight
|
|
};
|
|
return /* @__PURE__ */ _react_17_0_2_react.createElement("div", { className: "my-diff-editor", ref: editorEl, style });
|
|
}
|
|
|
|
|
|
/***/ })
|
|
|
|
}]); |