ui: auto-resize editor by default

This commit is contained in:
undefined committed 2021-05-07 13:43:28 +08:00
1 parent cd3f8af392
commit 34cd4d62e9
5 files changed
+9 -17

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "hydrooj", "name": "hydrooj",
"version": "2.24.21", "version": "2.24.22",
"bin": "bin/hydrooj.js", "bin": "bin/hydrooj.js",
"main": "dist/loader.js", "main": "dist/loader.js",
"typings": "dist/loader.d.ts", "typings": "dist/loader.d.ts",
+2 -2
View File
@@ -423,7 +423,7 @@ export class Handler extends HandlerCommon {
query: ctx.query, query: ctx.query,
path: ctx.path, path: ctx.path,
params: ctx.params, params: ctx.params,
referer: ctx.request.headers.referer || '/', referer: ctx.request.headers.referer,
json: (ctx.request.headers.accept || '').includes('application/json'), json: (ctx.request.headers.accept || '').includes('application/json'),
}; };
this.response = { this.response = {
@@ -520,7 +520,7 @@ export class Handler extends HandlerCommon {
text: global.Hydro.lib[key].text, text: global.Hydro.lib[key].text,
})); }));
if (!this.noCheckPermView) this.checkPerm(PERM.PERM_VIEW); if (!this.noCheckPermView) this.checkPerm(PERM.PERM_VIEW);
if (this.request.method === 'post' && this.request.headers.referer !== '/') { if (this.request.method === 'post' && this.request.headers.referer) {
const host = new URL(this.request.headers.referer).host; const host = new URL(this.request.headers.referer).host;
if (host !== this.request.host) throw new CsrfTokenError(host); if (host !== this.request.host) throw new CsrfTokenError(host);
} }
@@ -50,9 +50,7 @@ function onClickDummyBox(ev) {
const $evTarget = $(ev.currentTarget); const $evTarget = $(ev.currentTarget);
if (CommentBox.get($evTarget)) { if (CommentBox.get($evTarget)) {
CommentBox CommentBox.get($evTarget).focus();
.get($evTarget)
.focus();
return; return;
} }
@@ -125,9 +123,7 @@ async function onCommentClickEdit(mode, ev) {
const $evTarget = $(ev.currentTarget); const $evTarget = $(ev.currentTarget);
if (CommentBox.get($evTarget)) { if (CommentBox.get($evTarget)) {
CommentBox CommentBox.get($evTarget).focus();
.get($evTarget)
.focus();
return; return;
} }
@@ -174,9 +170,7 @@ async function onCommentClickDelete(type, ev) {
<p>${i18n(message)}</p> <p>${i18n(message)}</p>
</div>`, </div>`,
}).open(); }).open();
if (action !== 'yes') { if (action !== 'yes') return;
return;
}
const $evTarget = $(ev.currentTarget); const $evTarget = $(ev.currentTarget);
const form = JSON.parse($evTarget.attr('data-form')); const form = JSON.parse($evTarget.attr('data-form'));
@@ -40,8 +40,7 @@ export default class Editor extends DOMAttachedObject {
const hasFocus = $dom.is(':focus') || $dom.hasClass('autofocus'); const hasFocus = $dom.is(':focus') || $dom.hasClass('autofocus');
const origin = $dom.get(0); const origin = $dom.get(0);
const ele = document.createElement('div'); const ele = document.createElement('div');
$(ele).width('100%'); $(ele).width('100%').addClass('textbox');
$(ele).addClass('textbox');
$dom.hide(); $dom.hide();
origin.parentElement.appendChild(ele); origin.parentElement.appendChild(ele);
const value = $dom.val(); const value = $dom.val();
@@ -49,7 +48,7 @@ export default class Editor extends DOMAttachedObject {
onChange, language = 'markdown', onChange, language = 'markdown',
theme = UserContext.monacoTheme || 'vs-light', theme = UserContext.monacoTheme || 'vs-light',
model = `file://model-${Math.random().toString(16)}`, model = `file://model-${Math.random().toString(16)}`,
autoResize = $dom.hasClass('auto-resize'), autoResize = true,
} = this.options; } = this.options;
this.model = typeof model === 'string' ? monaco.editor.createModel(value, language, monaco.Uri.parse(model)) : model; this.model = typeof model === 'string' ? monaco.editor.createModel(value, language, monaco.Uri.parse(model)) : model;
const cfg = { const cfg = {
@@ -63,7 +62,6 @@ export default class Editor extends DOMAttachedObject {
if (autoResize) { if (autoResize) {
cfg.scrollbar = { cfg.scrollbar = {
vertical: 'hidden', vertical: 'hidden',
alwaysConsumeMouseWheel: false,
handleMouseWheel: false, handleMouseWheel: false,
}; };
cfg.scrollBeyondLastLine = false; cfg.scrollBeyondLastLine = false;
+1 -1
View File
@@ -1,6 +1,6 @@
{ {
"name": "@hydrooj/ui-default", "name": "@hydrooj/ui-default",
"version": "4.7.7", "version": "4.7.8",
"author": "undefined <i@undefined.moe>", "author": "undefined <i@undefined.moe>",
"license": "AGPL-3.0", "license": "AGPL-3.0",
"main": "hydro.js", "main": "hydro.js",