mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-19 17:38:19 +08:00
ui: problem_files: yaml editor with schema
This commit is contained in:
1 parent
3ab02d72d8
commit
d0569a6816
6 files changed
+83
-11
No files matched your search
@@ -30,6 +30,7 @@ packages/**/*.js
|
|||||||
!/install/jssh.d.ts
|
!/install/jssh.d.ts
|
||||||
## ui-default
|
## ui-default
|
||||||
!packages/ui-default/**/*.js
|
!packages/ui-default/**/*.js
|
||||||
|
!examples/**
|
||||||
packages/ui-default/public
|
packages/ui-default/public
|
||||||
packages/ui-default/misc/.iconfont
|
packages/ui-default/misc/.iconfont
|
||||||
packages/ui-default/static/locale
|
packages/ui-default/static/locale
|
||||||
|
|||||||
@@ -142,6 +142,7 @@ export default function (env = {}) {
|
|||||||
'window.jQuery': 'jquery',
|
'window.jQuery': 'jquery',
|
||||||
katex: 'katex/dist/katex.js',
|
katex: 'katex/dist/katex.js',
|
||||||
React: 'react',
|
React: 'react',
|
||||||
|
monaco: 'monaco-editor/esm/vs/editor/editor.api',
|
||||||
}),
|
}),
|
||||||
new ExtractCssPlugin({
|
new ExtractCssPlugin({
|
||||||
filename: '[name].css?[hash:10]',
|
filename: '[name].css?[hash:10]',
|
||||||
@@ -184,7 +185,16 @@ export default function (env = {}) {
|
|||||||
customInterpolateName: (url) => beautifyOutputUrl(url),
|
customInterpolateName: (url) => beautifyOutputUrl(url),
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
new MonacoWebpackPlugin({}),
|
new MonacoWebpackPlugin({
|
||||||
|
customLanguages: [{
|
||||||
|
label: 'yaml',
|
||||||
|
entry: require.resolve('@undefined-moe/monaco-yaml/lib/esm/monaco.contribution'),
|
||||||
|
worker: {
|
||||||
|
id: 'vs/language/yaml/yamlWorker',
|
||||||
|
entry: require.resolve('@undefined-moe/monaco-yaml/lib/esm/yaml.worker.js'),
|
||||||
|
},
|
||||||
|
}],
|
||||||
|
}),
|
||||||
new StaticManifestPlugin({
|
new StaticManifestPlugin({
|
||||||
fileName: 'static-manifest.json',
|
fileName: 'static-manifest.json',
|
||||||
ignore: [
|
ignore: [
|
||||||
|
|||||||
@@ -31,12 +31,12 @@ export default class Editor extends DOMAttachedObject {
|
|||||||
super($dom);
|
super($dom);
|
||||||
this.options = options;
|
this.options = options;
|
||||||
if (UserContext.preferredEditorType === 'monaco') this.initMonaco();
|
if (UserContext.preferredEditorType === 'monaco') this.initMonaco();
|
||||||
else if (options.language && options.langua !== 'markdown') this.initMonaco();
|
else if (options.language && options.language !== 'markdown') this.initMonaco();
|
||||||
else this.initVditor();
|
else this.initVditor();
|
||||||
}
|
}
|
||||||
|
|
||||||
async initMonaco() {
|
async initMonaco() {
|
||||||
const monaco = await import('monaco-editor/esm/vs/editor/editor.api');
|
const { default: monaco } = await import('vj/components/monaco/index');
|
||||||
const {
|
const {
|
||||||
onChange, language = 'markdown',
|
onChange, language = 'markdown',
|
||||||
theme = UserContext.monacoTheme || 'vs-light',
|
theme = UserContext.monacoTheme || 'vs-light',
|
||||||
@@ -52,7 +52,14 @@ export default class Editor extends DOMAttachedObject {
|
|||||||
$dom.hide();
|
$dom.hide();
|
||||||
origin.parentElement.appendChild(ele);
|
origin.parentElement.appendChild(ele);
|
||||||
const value = this.options.value || $dom.val();
|
const value = this.options.value || $dom.val();
|
||||||
this.model = typeof model === 'string' ? monaco.editor.createModel(value, language, monaco.Uri.parse(model)) : model;
|
// eslint-disable-next-line no-nested-ternary
|
||||||
|
this.model = typeof model === 'string'
|
||||||
|
? monaco.editor.getModel(monaco.Uri.parse(model))
|
||||||
|
? monaco.editor.getModel(monaco.Uri.parse(model))
|
||||||
|
: monaco.editor.createModel(value, language, monaco.Uri.parse(model))
|
||||||
|
: model;
|
||||||
|
this.model.setValue(value);
|
||||||
|
this.model.updateOptions({ language });
|
||||||
const cfg = {
|
const cfg = {
|
||||||
theme,
|
theme,
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
|
|||||||
@@ -20,12 +20,55 @@ monaco.languages.yaml.yamlDefaults.setDiagnosticsOptions({
|
|||||||
enableSchemaRequest: true,
|
enableSchemaRequest: true,
|
||||||
hover: true,
|
hover: true,
|
||||||
completion: true,
|
completion: true,
|
||||||
|
format: true,
|
||||||
schemas: [
|
schemas: [
|
||||||
{
|
{
|
||||||
uri: '/manage/system-schema.json',
|
uri: 'https://hydro.js.org/schema/problemConfig.json',
|
||||||
fileMatch: ['hydro://system/config.yaml'],
|
fileMatch: ['hydro://problem/file/config.yaml'],
|
||||||
|
schema: {
|
||||||
|
type: 'object',
|
||||||
|
def: {
|
||||||
|
cases: { type: 'array', items: { $ref: '#/def/case' } },
|
||||||
|
case: {
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
input: { type: 'string' },
|
||||||
|
output: { type: 'string' },
|
||||||
|
},
|
||||||
|
required: ['input'],
|
||||||
|
},
|
||||||
|
subtask: {
|
||||||
|
description: 'Subtask Info',
|
||||||
|
type: 'object',
|
||||||
|
properties: {
|
||||||
|
time: { $ref: '#/def/time' },
|
||||||
|
memory: { $ref: '#/def/memory' },
|
||||||
|
score: { $ref: '#/def/score', description: 'score' },
|
||||||
|
cases: { $ref: '#/def/cases' },
|
||||||
|
if: { type: 'array', items: { type: 'integer' } },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
time: { type: 'string', pattern: '^([0-9]+(?:\\.[0-9]*)?)([mu]?)s?$' },
|
||||||
|
memory: { type: 'string', pattern: '^([0-9]+(?:\\.[0-9]*)?)([kmg])b?$' },
|
||||||
|
score: { type: 'integer', maximum: 100, minimum: 1 },
|
||||||
|
},
|
||||||
|
properties: {
|
||||||
|
type: { enum: ['default', 'interactive', 'submit_answer'] },
|
||||||
|
checker_type: { enum: ['default', 'lemon', 'syzoj', 'testlib', 'strict', 'qduoj'] },
|
||||||
|
checker: { type: 'string', pattern: '\\.' },
|
||||||
|
interactor: { type: 'string', pattern: '\\.' },
|
||||||
|
user_extra_files: { type: 'array', items: { type: 'string' } },
|
||||||
|
judge_extra_files: { type: 'array', items: { type: 'string' } },
|
||||||
|
cases: { $ref: '#/def/cases' },
|
||||||
|
subtasks: { type: 'array', items: { $ref: '#/def/subtask' } },
|
||||||
|
outputs: { type: 'array' },
|
||||||
|
filename: { type: 'string' },
|
||||||
|
time: { $ref: '#/def/time' },
|
||||||
|
memory: { $ref: '#/def/memory' },
|
||||||
|
score: { $ref: '#/def/score' },
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
...window.Context.schemas,
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
{
|
{
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"./node_modules",
|
|
||||||
"./public",
|
"./public",
|
||||||
"../../node_modules"
|
|
||||||
],
|
],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"allowSyntheticDefaultImports": true,
|
"allowSyntheticDefaultImports": true,
|
||||||
|
|||||||
@@ -213,7 +213,6 @@ const page = new NamedPage('problem_files', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function startEdit(filename, value) {
|
async function startEdit(filename, value) {
|
||||||
console.log(filename, value);
|
|
||||||
const { default: Editor } = await import('vj/components/editor/index');
|
const { default: Editor } = await import('vj/components/editor/index');
|
||||||
const promise = new ActionDialog({
|
const promise = new ActionDialog({
|
||||||
$body: tpl`
|
$body: tpl`
|
||||||
@@ -223,7 +222,21 @@ const page = new NamedPage('problem_files', () => {
|
|||||||
width: `${window.innerWidth - 200}px`,
|
width: `${window.innerWidth - 200}px`,
|
||||||
height: `${window.innerHeight - 100}px`,
|
height: `${window.innerHeight - 100}px`,
|
||||||
}).open();
|
}).open();
|
||||||
const editor = new Editor($('[name="fileContent"]'), { value, autoResize: false, autoLayout: false });
|
const language = {
|
||||||
|
yaml: 'yaml',
|
||||||
|
yml: 'yaml',
|
||||||
|
txt: 'plain',
|
||||||
|
in: 'plain',
|
||||||
|
out: 'plain',
|
||||||
|
ans: 'plain',
|
||||||
|
}[filename.split('.').pop()];
|
||||||
|
const editor = new Editor($('[name="fileContent"]'), {
|
||||||
|
value,
|
||||||
|
autoResize: false,
|
||||||
|
autoLayout: false,
|
||||||
|
language,
|
||||||
|
model: `hydro://problem/file/${filename}`,
|
||||||
|
});
|
||||||
const action = await promise;
|
const action = await promise;
|
||||||
value = editor.value();
|
value = editor.value();
|
||||||
editor.destory();
|
editor.destory();
|
||||||
|
|||||||
Reference in new issue
Block a user