mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
ui: set input/output draggable
This commit is contained in:
6 files changed
+19
-49
No files matched your search
@@ -1,4 +1,3 @@
|
|||||||
import classNames from 'classnames';
|
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
|
||||||
export default function DataInputComponent(props) {
|
export default function DataInputComponent(props) {
|
||||||
@@ -10,9 +9,8 @@ export default function DataInputComponent(props) {
|
|||||||
className,
|
className,
|
||||||
...rest
|
...rest
|
||||||
} = props;
|
} = props;
|
||||||
const cn = classNames(className, 'flex-col flex-fill');
|
|
||||||
return (
|
return (
|
||||||
<div {...rest} className={cn}>
|
<div {...rest} className={className} style={{ height: '100%', width: '100%' }}>
|
||||||
{html ? (
|
{html ? (
|
||||||
<div
|
<div
|
||||||
className="scratchpad__data-input"
|
className="scratchpad__data-input"
|
||||||
|
|||||||
@@ -6,3 +6,13 @@
|
|||||||
padding: rem(0 5px)
|
padding: rem(0 5px)
|
||||||
font-size: rem($font-size-small)
|
font-size: rem($font-size-small)
|
||||||
color: #FFF
|
color: #FFF
|
||||||
|
|
||||||
|
.splitpane-fill
|
||||||
|
display: flex
|
||||||
|
position: absolute
|
||||||
|
overflow: hidden
|
||||||
|
left: 0
|
||||||
|
width: 100%
|
||||||
|
top: 0
|
||||||
|
height: 100%
|
||||||
|
user-select: none
|
||||||
@@ -8,17 +8,11 @@ interface ScratchpadOptions {
|
|||||||
value?: string;
|
value?: string;
|
||||||
language?: string;
|
language?: string;
|
||||||
handleUpdateCode?: (str: string, event: monaco.editor.IModelContentChangedEvent) => void;
|
handleUpdateCode?: (str: string, event: monaco.editor.IModelContentChangedEvent) => void;
|
||||||
mainSize?: number;
|
|
||||||
recordSize?: number;
|
|
||||||
pretestSize?: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default connect((state: any) => ({
|
export default connect((state: any) => ({
|
||||||
value: state.editor.code,
|
value: state.editor.code,
|
||||||
language: window.LANGS[state.editor.lang]?.monaco,
|
language: window.LANGS[state.editor.lang]?.monaco,
|
||||||
mainSize: state.ui.main.size,
|
|
||||||
pretestSize: state.ui.pretest.size,
|
|
||||||
recordSize: state.ui.records.size,
|
|
||||||
}), (dispatch) => ({
|
}), (dispatch) => ({
|
||||||
handleUpdateCode: (code: string) => {
|
handleUpdateCode: (code: string) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
@@ -66,7 +60,7 @@ export default connect((state: any) => ({
|
|||||||
|
|
||||||
async componentDidUpdate(prevProps) {
|
async componentDidUpdate(prevProps) {
|
||||||
const {
|
const {
|
||||||
value, language, mainSize, recordSize, pretestSize,
|
value, language,
|
||||||
} = this.props;
|
} = this.props;
|
||||||
const { monaco } = await load([language]);
|
const { monaco } = await load([language]);
|
||||||
const { editor, model } = this;
|
const { editor, model } = this;
|
||||||
@@ -94,11 +88,6 @@ export default connect((state: any) => ({
|
|||||||
this.model = monaco.editor.getModel(uri) || monaco.editor.createModel(val, language, uri);
|
this.model = monaco.editor.getModel(uri) || monaco.editor.createModel(val, language, uri);
|
||||||
editor.setModel(this.model);
|
editor.setModel(this.model);
|
||||||
}
|
}
|
||||||
if (editor) {
|
|
||||||
if (prevProps.mainSize !== mainSize
|
|
||||||
|| prevProps.recordSize !== recordSize
|
|
||||||
|| prevProps.pretestSize !== pretestSize) editor.layout();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillUnmount() {
|
componentWillUnmount() {
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { Allotment } from 'allotment';
|
||||||
import AnsiUp from 'ansi_up';
|
import AnsiUp from 'ansi_up';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
@@ -38,7 +39,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadPret
|
|||||||
</span>
|
</span>
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<div className="flex-row flex-fill">
|
<Allotment>
|
||||||
<DataInput
|
<DataInput
|
||||||
title={i18n('Input')}
|
title={i18n('Input')}
|
||||||
value={this.props.input}
|
value={this.props.input}
|
||||||
@@ -49,7 +50,7 @@ export default connect(mapStateToProps, mapDispatchToProps)(class ScratchpadPret
|
|||||||
value={AU.ansi_to_html(this.props.output)}
|
value={AU.ansi_to_html(this.props.output)}
|
||||||
html
|
html
|
||||||
/>
|
/>
|
||||||
</div>
|
</Allotment>
|
||||||
</Panel>
|
</Panel>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,6 +67,7 @@ export default function ScratchpadContainer() {
|
|||||||
const ui = useSelector<any, any>((state) => state.ui, _.isEqual);
|
const ui = useSelector<any, any>((state) => state.ui, _.isEqual);
|
||||||
|
|
||||||
const handleChangeSize = _.debounce(() => {
|
const handleChangeSize = _.debounce(() => {
|
||||||
|
ctx.scratchpad.editor?.layout?.();
|
||||||
$('#scratchpad').trigger('vjScratchpadRelayout');
|
$('#scratchpad').trigger('vjScratchpadRelayout');
|
||||||
forceUpdate();
|
forceUpdate();
|
||||||
}, 500);
|
}, 500);
|
||||||
@@ -77,12 +78,10 @@ export default function ScratchpadContainer() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const showSidebar = Object.keys(pages).length > 1;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Allotment onChange={handleChangeSize}>
|
<Allotment onChange={handleChangeSize}>
|
||||||
<Allotment.Pane visible={showSidebar} minSize={50} maxSize={50}>
|
<Allotment.Pane visible={Object.keys(pages).length > 1} minSize={50} maxSize={50}>
|
||||||
<div className="scratchpad__tablist" style={{ display: showSidebar ? 'block' : 'none' }}>
|
<div className="scratchpad__tablist">
|
||||||
{Object.keys(pages).map((key) => {
|
{Object.keys(pages).map((key) => {
|
||||||
const Component = pages[key].icon;
|
const Component = pages[key].icon;
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -2,19 +2,13 @@ import Notification from 'vj/components/notification';
|
|||||||
import { i18n } from 'vj/utils';
|
import { i18n } from 'vj/utils';
|
||||||
|
|
||||||
export default function reducer(state = {
|
export default function reducer(state = {
|
||||||
main: {
|
|
||||||
size: '50%',
|
|
||||||
savedSize: '50%',
|
|
||||||
},
|
|
||||||
pretest: {
|
pretest: {
|
||||||
visible: ['default', 'fileio'].includes(UiContext.pdoc.config?.type)
|
visible: ['default', 'fileio'].includes(UiContext.pdoc.config?.type)
|
||||||
? localStorage.getItem('scratchpad/pretest') === 'true'
|
? localStorage.getItem('scratchpad/pretest') === 'true'
|
||||||
: false,
|
: false,
|
||||||
size: 200,
|
|
||||||
},
|
},
|
||||||
records: {
|
records: {
|
||||||
visible: UiContext.canViewRecord && localStorage.getItem('scratchpad/records') === 'true',
|
visible: UiContext.canViewRecord && localStorage.getItem('scratchpad/records') === 'true',
|
||||||
size: 100,
|
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
},
|
},
|
||||||
isPosting: false,
|
isPosting: false,
|
||||||
@@ -24,16 +18,6 @@ export default function reducer(state = {
|
|||||||
activePage: 'problem',
|
activePage: 'problem',
|
||||||
}, action: any = {}) {
|
}, action: any = {}) {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case 'SCRATCHPAD_UI_CHANGE_SIZE': {
|
|
||||||
const { uiElement, size } = action.payload;
|
|
||||||
return {
|
|
||||||
...state,
|
|
||||||
[uiElement]: {
|
|
||||||
...state[uiElement],
|
|
||||||
size,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
case 'SCRATCHPAD_UI_SET_VISIBILITY': {
|
case 'SCRATCHPAD_UI_SET_VISIBILITY': {
|
||||||
const { uiElement, visibility } = action.payload;
|
const { uiElement, visibility } = action.payload;
|
||||||
localStorage.setItem(`scratchpad/${uiElement}`, visibility.toString());
|
localStorage.setItem(`scratchpad/${uiElement}`, visibility.toString());
|
||||||
@@ -130,20 +114,9 @@ export default function reducer(state = {
|
|||||||
}
|
}
|
||||||
case 'SCRATCHPAD_SWITCH_TO_PAGE': {
|
case 'SCRATCHPAD_SWITCH_TO_PAGE': {
|
||||||
let newPage = action.payload;
|
let newPage = action.payload;
|
||||||
let { size } = state.main;
|
if (newPage === state.activePage) newPage = null;
|
||||||
if (newPage === state.activePage) {
|
|
||||||
newPage = null;
|
|
||||||
(size as any) = 0;
|
|
||||||
} else if (state.activePage === null) {
|
|
||||||
size = state.main.savedSize;
|
|
||||||
}
|
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
main: {
|
|
||||||
...state.main,
|
|
||||||
size,
|
|
||||||
savedSize: state.main.size,
|
|
||||||
},
|
|
||||||
activePage: newPage,
|
activePage: newPage,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user