Skip to content

Make console interactive #667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 54 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
2de3720
init
shinytang6 Aug 4, 2018
66024ee
use rem in scss/remove require
shinytang6 Aug 4, 2018
5f98050
fix linting
shinytang6 Aug 4, 2018
d65f871
update style
shinytang6 Aug 4, 2018
9400872
add reference
shinytang6 Aug 4, 2018
a79958a
update
shinytang6 Aug 30, 2018
fe70c20
support syntax highlighting
shinytang6 Sep 3, 2018
13700dd
update
shinytang6 Sep 4, 2018
17354a0
remove autocomplete code
shinytang6 Sep 5, 2018
99c1f0b
update cursor color
shinytang6 Sep 10, 2018
869737e
update styles
shinytang6 Sep 26, 2018
deae15e
update
shinytang6 Sep 26, 2018
993ad8f
update
shinytang6 Sep 26, 2018
746b90c
update
shinytang6 Sep 26, 2018
f82039e
update
shinytang6 Sep 27, 2018
d20c4f8
update
shinytang6 Sep 27, 2018
5346da8
update
shinytang6 Oct 4, 2018
163c609
adapt the console ouput and font
shinytang6 Oct 4, 2018
c3f2a53
update result/command icon
shinytang6 Oct 4, 2018
f43a28d
update icons
shinytang6 Oct 4, 2018
53f9b90
fix functions printing bug
shinytang6 Nov 8, 2018
f273394
resume
shinytang6 Nov 8, 2018
b1cdbd8
resume
shinytang6 Nov 8, 2018
0d32ba2
remove static file
shinytang6 Nov 8, 2018
5e13be4
fix console function bug
shinytang6 Nov 8, 2018
387b599
Merge branch 'master' into feature-2/interactive-console
shinytang6 Dec 3, 2018
826350b
change console code to use Encode/Decode
shinytang6 Dec 3, 2018
bfe905d
remove object.assign && fix lint warning
shinytang6 Dec 3, 2018
33f98a6
merge in latest master
catarak Oct 9, 2019
b5c2ac9
Merge develop and update to work with Console changes
catarak Jul 28, 2020
d504864
Check origin for postMessage
catarak Jul 30, 2020
7efc078
Merge branch 'develop' into feature-2/interactive-console
catarak Aug 21, 2020
921f136
Move window message handling to component
catarak Aug 21, 2020
dbaa8a5
Add dispatcher utility to handle message channel api
catarak Aug 25, 2020
46f62e3
Merge branch 'develop' into feature-2/interactive-console
catarak Aug 26, 2020
f6aa546
Eval ConsoleInput command in preview frame
catarak Aug 27, 2020
0daeea5
Remove commented-out code, fix console scrolling
catarak Aug 27, 2020
da9f8ec
Render return value from evaluating console input
catarak Aug 27, 2020
1c47498
Fix encoding/decoding of messages
catarak Aug 27, 2020
3d9a4fa
Handle errors when evaluating expression in iframe
catarak Aug 27, 2020
12cb0a5
Update Rendering errors to console from input
catarak Aug 27, 2020
5b3d4d3
Merge develop
catarak Sep 4, 2020
48833c9
Merge branch 'develop' into feature-2/interactive-console
catarak Sep 4, 2020
95a096d
Merge develop
catarak Sep 23, 2020
5762c15
Add ConsoleInput adjustment to font size
catarak Sep 23, 2020
71f68b5
Add command and result icons, rerender console when changing theme an…
catarak Sep 24, 2020
ae71067
Add command/reesult icons for all themes
catarak Sep 25, 2020
b10f498
Change code to force console rerender when changing theme and font size
catarak Sep 25, 2020
d831513
Move MesssageHandler to a custom hook, create hooks directory
catarak Sep 25, 2020
e8cc08a
Remove unnecessary handleConsoleExpressions function
catarak Sep 25, 2020
088f0b0
Remove unnecessary ref in IDEView
catarak Sep 25, 2020
23d45d2
Add command history, not 100% finished
catarak Sep 28, 2020
58b75eb
Update cursor size for multiline commands
catarak Sep 29, 2020
ac5c376
Remove unused variables, add return at end of files
catarak Sep 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/components/useAsModal.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import styled from 'styled-components';
import { useModalBehavior } from '../utils/custom-hooks';
import { useModalBehavior } from '../modules/IDE/hooks/custom-hooks';

const BackgroundOverlay = styled.div`
position: fixed;
Expand Down
13 changes: 13 additions & 0 deletions client/images/console-command-contrast.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions client/images/console-command-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions client/images/console-command-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions client/images/console-result-contrast.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions client/images/console-result-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions client/images/console-result-light.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion client/modules/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class App extends React.Component {
render() {
return (
<div className="app">
{false && this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && <DevTools />}
{this.state.isMounted && !window.devToolsExtension && getConfig('NODE_ENV') === 'development' && <DevTools />}
{this.props.children}
</div>
);
Expand Down
94 changes: 63 additions & 31 deletions client/modules/IDE/components/Console.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useRef } from 'react';
import React, { useRef, useEffect } from 'react';
import PropTypes from 'prop-types';
import { withTranslation } from 'react-i18next';

Expand All @@ -23,40 +23,58 @@ import debugContrastUrl from '../../../images/console-debug-contrast.svg?byUrl';
import infoLightUrl from '../../../images/console-info-light.svg?byUrl';
import infoDarkUrl from '../../../images/console-info-dark.svg?byUrl';
import infoContrastUrl from '../../../images/console-info-contrast.svg?byUrl';
import ConsoleInput from './ConsoleInput';

import commandLightUrl from '../../../images/console-command-light.svg?byUrl';
import resultLightUrl from '../../../images/console-result-light.svg?byUrl';
import commandDarkUrl from '../../../images/console-command-dark.svg?byUrl';
import resultDarkUrl from '../../../images/console-result-dark.svg?byUrl';
import commandContrastUrl from '../../../images/console-command-contrast.svg?byUrl';
import resultContrastUrl from '../../../images/console-result-contrast.svg?byUrl';

import UpArrowIcon from '../../../images/up-arrow.svg';
import DownArrowIcon from '../../../images/down-arrow.svg';

import * as IDEActions from '../../IDE/actions/ide';
import * as ConsoleActions from '../../IDE/actions/console';
import { useDidUpdate } from '../../../utils/custom-hooks';
import { useDidUpdate } from '../hooks/custom-hooks';
import useHandleMessageEvent from '../hooks/useHandleMessageEvent';
import { listen } from '../../../utils/dispatcher';

const getConsoleFeedStyle = (theme, times, fontSize) => {
const style = {};
const style = {
BASE_FONT_FAMILY: 'Inconsolata, monospace',
};
const CONSOLE_FEED_LIGHT_ICONS = {
LOG_WARN_ICON: `url(${warnLightUrl})`,
LOG_ERROR_ICON: `url(${errorLightUrl})`,
LOG_DEBUG_ICON: `url(${debugLightUrl})`,
LOG_INFO_ICON: `url(${infoLightUrl})`
LOG_INFO_ICON: `url(${infoLightUrl})`,
LOG_COMMAND_ICON: `url(${commandLightUrl})`,
LOG_RESULT_ICON: `url(${resultLightUrl})`
};
const CONSOLE_FEED_DARK_ICONS = {
LOG_WARN_ICON: `url(${warnDarkUrl})`,
LOG_ERROR_ICON: `url(${errorDarkUrl})`,
LOG_DEBUG_ICON: `url(${debugDarkUrl})`,
LOG_INFO_ICON: `url(${infoDarkUrl})`
LOG_INFO_ICON: `url(${infoDarkUrl})`,
LOG_COMMAND_ICON: `url(${commandDarkUrl})`,
LOG_RESULT_ICON: `url(${resultDarkUrl})`
};
const CONSOLE_FEED_CONTRAST_ICONS = {
LOG_WARN_ICON: `url(${warnContrastUrl})`,
LOG_ERROR_ICON: `url(${errorContrastUrl})`,
LOG_DEBUG_ICON: `url(${debugContrastUrl})`,
LOG_INFO_ICON: `url(${infoContrastUrl})`
LOG_INFO_ICON: `url(${infoContrastUrl})`,
LOG_COMMAND_ICON: `url(${commandContrastUrl})`,
LOG_RESULT_ICON: `url(${resultContrastUrl})`
};
const CONSOLE_FEED_SIZES = {
TREENODE_LINE_HEIGHT: 1.2,
BASE_FONT_SIZE: fontSize,
ARROW_FONT_SIZE: fontSize,
LOG_ICON_WIDTH: fontSize,
LOG_ICON_HEIGHT: 1.45 * fontSize,
LOG_ICON_HEIGHT: 1.45 * fontSize
};

if (times > 1) {
Expand All @@ -77,21 +95,25 @@ const getConsoleFeedStyle = (theme, times, fontSize) => {
const Console = ({ t }) => {
const consoleEvents = useSelector(state => state.console);
const isExpanded = useSelector(state => state.ide.consoleIsExpanded);
const isPlaying = useSelector(state => state.ide.isPlaying);
const { theme, fontSize } = useSelector(state => state.preferences);

const {
collapseConsole, expandConsole, clearConsole, dispatchConsoleEvent
} = bindActionCreators({ ...IDEActions, ...ConsoleActions }, useDispatch());

useDidUpdate(() => {
clearConsole();
dispatchConsoleEvent(consoleEvents);
}, [theme, fontSize]);

const cm = useRef({});

useDidUpdate(() => { cm.current.scrollTop = cm.current.scrollHeight; });

const handleMessageEvent = useHandleMessageEvent();
useEffect(() => {
const unsubscribe = listen(handleMessageEvent);
return function cleanup() {
unsubscribe();
};
});

const consoleClass = classNames({
'preview-console': true,
'preview-console--collapsed': !isExpanded
Expand All @@ -117,26 +139,36 @@ const Console = ({ t }) => {
</button>
</div>
</header>
<div ref={cm} className="preview-console__messages">
{consoleEvents.map((consoleEvent) => {
const { method, times } = consoleEvent;
return (
<div key={consoleEvent.id} className={`preview-console__message preview-console__message--${method}`}>
{ times > 1 &&
<div
className="preview-console__logged-times"
style={{ fontSize, borderRadius: fontSize / 2 }}
>
{times}
<div className="preview-console__body">
<div ref={cm} className="preview-console__messages">
{consoleEvents.map((consoleEvent) => {
const { method, times } = consoleEvent;
return (
<div key={consoleEvent.id} className={`preview-console__message preview-console__message--${method}`}>
{ times > 1 &&
<div
className="preview-console__logged-times"
style={{ fontSize, borderRadius: fontSize / 2 }}
>
{times}
</div>
}
<ConsoleFeed
styles={getConsoleFeedStyle(theme, times, fontSize)}
logs={[consoleEvent]}
key={`${consoleEvent.id}-${theme}-${fontSize}`}
/>
</div>
}
<ConsoleFeed
styles={getConsoleFeedStyle(theme, times, fontSize)}
logs={[consoleEvent]}
/>
</div>
);
})}
);
})}
</div>
{ isExpanded && isPlaying &&
<ConsoleInput
theme={theme}
dispatchConsoleEvent={dispatchConsoleEvent}
fontSize={fontSize}
/>
}
</div>
</section>
);
Expand Down
Loading