mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
将monaco-editor作为在线IDE编辑器
This commit is contained in:
1 parent
4c53fc8146
commit
53a6dbeb1a
9 files changed
+81
-134
No files matched your search
@@ -1,13 +1,8 @@
|
||||
import Tether from 'tether';
|
||||
import { NamedPage } from 'vj/misc/PageLoader';
|
||||
import Navigation from 'vj/components/navigation';
|
||||
import Notification from 'vj/components/notification';
|
||||
import { ActionDialog } from 'vj/components/dialog';
|
||||
import DomainSelectAutoComplete from 'vj/components/autocomplete/DomainSelectAutoComplete';
|
||||
import loadReactRedux from 'vj/utils/loadReactRedux';
|
||||
import delay from 'vj/utils/delay';
|
||||
import request from 'vj/utils/request';
|
||||
import i18n from 'vj/utils/i18n';
|
||||
|
||||
class ProblemPageExtender {
|
||||
constructor() {
|
||||
@@ -19,12 +14,8 @@ class ProblemPageExtender {
|
||||
}
|
||||
|
||||
async extend() {
|
||||
if (this.inProgress) {
|
||||
return;
|
||||
}
|
||||
if (this.isExtended) {
|
||||
return;
|
||||
}
|
||||
if (this.inProgress) return;
|
||||
if (this.isExtended) return;
|
||||
this.inProgress = true;
|
||||
|
||||
const bound = this.$contentBound
|
||||
@@ -38,7 +29,6 @@ class ProblemPageExtender {
|
||||
Navigation.instance.logoVisible.set('scratchpad', true);
|
||||
Navigation.instance.expanded.set('scratchpad', true);
|
||||
$('body').addClass('header--collapsed mode--scratchpad');
|
||||
|
||||
await this.$scratchpadContainer
|
||||
.css({
|
||||
left: bound.left,
|
||||
@@ -67,12 +57,8 @@ class ProblemPageExtender {
|
||||
}
|
||||
|
||||
async collapse() {
|
||||
if (this.inProgress) {
|
||||
return;
|
||||
}
|
||||
if (!this.isExtended) {
|
||||
return;
|
||||
}
|
||||
if (this.inProgress) return;
|
||||
if (!this.isExtended) return;
|
||||
this.inProgress = true;
|
||||
|
||||
$(window).scrollTop(0);
|
||||
@@ -109,11 +95,8 @@ class ProblemPageExtender {
|
||||
}
|
||||
|
||||
toggle() {
|
||||
if (this.isExtended) {
|
||||
this.collapse();
|
||||
} else {
|
||||
this.extend();
|
||||
}
|
||||
if (this.isExtended) this.collapse();
|
||||
else this.extend();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,10 +157,7 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
|
||||
}
|
||||
|
||||
async function loadReact() {
|
||||
if (reactLoaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (reactLoaded) return;
|
||||
$('.loader-container').show();
|
||||
|
||||
const SockJs = await import('sockjs-client');
|
||||
@@ -204,61 +184,13 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
|
||||
$('#scratchpad').get(0),
|
||||
);
|
||||
};
|
||||
|
||||
unmountReact = () => {
|
||||
unmountComponentAtNode($('#scratchpad').get(0));
|
||||
};
|
||||
|
||||
reactLoaded = true;
|
||||
|
||||
$('.loader-container').hide();
|
||||
}
|
||||
|
||||
const domainSelector = DomainSelectAutoComplete.getOrConstruct($('.dialog__body--copy-to [name="domain_id"]'));
|
||||
const copyProblemToDialog = new ActionDialog({
|
||||
$body: $('.dialog__body--copy-to > div'),
|
||||
onDispatch(action) {
|
||||
if (action === 'ok' && domainSelector.value() === null) {
|
||||
domainSelector.focus();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
});
|
||||
copyProblemToDialog.clear = function () {
|
||||
domainSelector.clear();
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
async function handleClickCopyProblem() {
|
||||
const action = await copyProblemToDialog.clear().open();
|
||||
if (action !== 'ok') {
|
||||
return;
|
||||
}
|
||||
const domainId = copyProblemToDialog.$dom.find('[name="domain_id"]').val();
|
||||
const useNumericId = copyProblemToDialog.$dom.find('[name="numeric_pid"]').prop('checked');
|
||||
const isHidden = copyProblemToDialog.$dom.find('[name="hidden"]').prop('checked');
|
||||
const payload = {
|
||||
operation: 'copy_to_domain',
|
||||
dest_domain_id: domainId,
|
||||
};
|
||||
if (useNumericId) {
|
||||
payload.numeric_pid = 'on';
|
||||
}
|
||||
if (isHidden) {
|
||||
payload.hidden = 'on';
|
||||
}
|
||||
try {
|
||||
const data = await request.post('', payload);
|
||||
Notification.success(i18n('Problem is successfully copied.'));
|
||||
await delay(1000);
|
||||
window.location.href = data.new_problem_url;
|
||||
} catch (error) {
|
||||
Notification.error(error.message);
|
||||
}
|
||||
}
|
||||
|
||||
async function enterScratchpadMode() {
|
||||
await extender.extend();
|
||||
await loadReact();
|
||||
@@ -284,10 +216,6 @@ const page = new NamedPage(['problem_detail', 'contest_detail_problem', 'homewor
|
||||
leaveScratchpadMode();
|
||||
ev.preventDefault();
|
||||
});
|
||||
$(document).on('click', '[name="problem-sidebar__copy-to"]', (ev) => {
|
||||
handleClickCopyProblem();
|
||||
ev.preventDefault();
|
||||
});
|
||||
$(document).on('click', '[name="problem-sidebar__show-category"]', (ev) => {
|
||||
$(ev.currentTarget).hide();
|
||||
$('[name="problem-sidebar__categories"]').show();
|
||||
|
||||
Reference in new issue
Block a user