Skip to content

Commit 2f73e75

Browse files
authored
New mobx state tree & bug fixes (codesandbox#998)
1 parent ba3263b commit 2f73e75

File tree

26 files changed

+310
-199
lines changed

26 files changed

+310
-199
lines changed

packages/app/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,9 @@
162162
"lru-cache": "^4.1.3",
163163
"match-sorter": "^1.8.1",
164164
"memoize-one": "^4.0.0",
165-
"mobx": "^3.4.0",
166-
"mobx-react": "^4.3.5",
167-
"mobx-state-tree": "^1.2.1",
165+
"mobx": "^4.0.0",
166+
"mobx-react": "^5.2.3",
167+
"mobx-state-tree": "^3.0.0",
168168
"moment": "^2.18.1",
169169
"monaco-editor": "^0.13.1",
170170
"monaco-editor-textmate": "^2.0.0",

packages/app/src/app/components/CodeEditor/Monaco/index.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,11 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
127127
syntaxWorker: ?Worker;
128128
lintWorker: ?Worker;
129129
typingsFetcherWorker: ?Worker;
130-
sizeProbeInterval: ?number;
131130
editor: any;
132131
monaco: any;
133132
receivingCode: ?boolean = false;
134133
transpilationListener: ?Function;
134+
sizeProbeInterval: ?number;
135135

136136
constructor(props: Props) {
137137
super(props);
@@ -164,7 +164,7 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
164164
this.props.width !== nextProps.width ||
165165
this.props.height !== nextProps.height
166166
) {
167-
this.resizeEditor();
167+
this.resizeEditorInstantly();
168168
}
169169

170170
if (this.props.readOnly !== nextProps.readOnly && this.editor) {
@@ -195,7 +195,7 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
195195
if (this.transpilationListener) {
196196
this.transpilationListener();
197197
}
198-
clearTimeout(this.sizeProbeInterval);
198+
clearInterval(this.sizeProbeInterval);
199199

200200
if (this.disposeInitializer) {
201201
this.disposeInitializer();
@@ -256,7 +256,10 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
256256
// this.addKeyCommands();
257257

258258
window.addEventListener('resize', this.resizeEditor);
259-
this.sizeProbeInterval = setInterval(this.resizeEditor.bind(this), 3000);
259+
this.sizeProbeInterval = setInterval(
260+
this.resizeEditorInstantly.bind(this),
261+
3000
262+
);
260263

261264
const { dependencies } = this;
262265
if (dependencies != null) {
@@ -1224,10 +1227,12 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
12241227
forceMoveMarkers: false,
12251228
};
12261229

1227-
// For the live operation we need to send the operation based on the old code,
1228-
// that's why we set the 'liveOperationCode' to the last code so the operation
1229-
// will be applied on that code instead of `currentModule.code`
1230-
this.liveOperationCode = this.getCode();
1230+
if (!this.receivingCode) {
1231+
// For the live operation we need to send the operation based on the old code,
1232+
// that's why we set the 'liveOperationCode' to the last code so the operation
1233+
// will be applied on that code instead of `currentModule.code`
1234+
this.liveOperationCode = this.getCode();
1235+
}
12311236

12321237
this.editor.getModel().pushEditOperations([], [editOperation], null);
12331238
this.editor.setPosition(pos);
@@ -1359,6 +1364,10 @@ class MonacoEditor extends React.Component<Props, State> implements Editor {
13591364
Promise.all(modules.map(module => this.createModel(module, modules)));
13601365

13611366
resizeEditor = () => {
1367+
this.resizeEditorInstantly();
1368+
};
1369+
1370+
resizeEditorInstantly = () => {
13621371
this.forceUpdate(() => {
13631372
if (this.editor) {
13641373
this.editor.layout();

packages/app/src/app/components/ContextMenu/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class ContextMenu extends React.PureComponent {
120120
onMouseDown={e => {
121121
e.preventDefault();
122122
}}
123-
onClick={e => {
123+
onMouseUp={e => {
124124
if (item.action()) {
125125
e.preventDefault();
126126
this.close();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import React from 'react';
2+
import IconBase from 'react-icons/lib/IconBase';
3+
4+
export default props => (
5+
<IconBase
6+
width="1em"
7+
height="1em"
8+
viewBox="0 0 12 12"
9+
version="1.1"
10+
xmlnsXlink="http://www.w3.org/1999/xlink"
11+
{...props}
12+
>
13+
<path
14+
d="M1.50001 0H0L1.43051e-06 6.90909C1.43051e-06 7.50909 0.49091 8 1.09091 8L8.5 8V6.5H1.50001L1.50001 0Z"
15+
transform="translate(0 4)"
16+
fill="currentColor"
17+
/>
18+
<rect
19+
width="9.5"
20+
height="9.5"
21+
rx="1"
22+
transform="translate(2.5)"
23+
fill="currentColor"
24+
/>
25+
</IconBase>
26+
);

packages/app/src/app/components/Preview/Navigator/HorizontalAlign.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ export default props => (
55
<IconBase
66
width="1em"
77
height="1em"
8-
viewBox="0 0 16 16"
8+
viewBox="0 0 12 12"
99
version="1.1"
1010
xmlnsXlink="http://www.w3.org/1999/xlink"
1111
{...props}
1212
>
1313
<path
14-
d="M2.25 8.75v-1.5h11.5v1.5H2.25zm1.25-1.5v5.25h9V7.25h-9zM3 2h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1z"
14+
d="M1.5 1.5V7.5H10.5V1.5H1.5ZM1 0H11C11.5523 0 12 0.447715 12 1V11C12 11.5523 11.5523 12 11 12H1C0.447715 12 0 11.5523 0 11V1C0 0.447715 0.447715 0 1 0Z"
1515
fill="currentColor"
16-
fillRule="nonzero"
1716
/>
1817
</IconBase>
1918
);

packages/app/src/app/components/Preview/Navigator/VerticalAlign.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ export default props => (
55
<IconBase
66
width="1em"
77
height="1em"
8-
viewBox="0 0 16 16"
8+
viewBox="0 0 12 12"
99
version="1.1"
1010
xmlnsXlink="http://www.w3.org/1999/xlink"
1111
{...props}
1212
>
1313
<path
14-
d="M7.25 2.735h1.5V12.75h-1.5V2.735zm0 .765v9h5.25v-9H7.25zM3 2h10a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H3a1 1 0 0 1-1-1V3a1 1 0 0 1 1-1z"
14+
d="M5.25 1.5V10.5H10.5V1.5H5.25ZM1 9.53674e-07H11C11.5523 9.53674e-07 12 0.447716 12 1V11C12 11.5523 11.5523 12 11 12H1C0.447715 12 0 11.5523 0 11V1C0 0.447716 0.447715 9.53674e-07 1 9.53674e-07Z"
15+
transform="translate(12 12) rotate(-180)"
1516
fill="currentColor"
16-
fillRule="nonzero"
1717
/>
1818
</IconBase>
1919
);

packages/app/src/app/components/Preview/Navigator/elements.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import styled from 'styled-components';
1+
import styled, { css } from 'styled-components';
22

33
export const Container = styled.div`
44
display: flex;
@@ -37,6 +37,12 @@ export const Icon = styled.button`
3737
background-color: #e2e2e2;
3838
cursor: pointer;
3939
}`};
40+
41+
${props =>
42+
props.selected &&
43+
css`
44+
color: ${props.theme.secondary()};
45+
`};
4046
`;
4147

4248
export const AddressBarContainer = styled.div`
Lines changed: 4 additions & 0 deletions
Loading
Lines changed: 3 additions & 12 deletions
Loading

packages/app/src/app/components/Preview/Navigator/index.js

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import React from 'react';
33
import LeftIcon from 'react-icons/lib/fa/angle-left';
44
import RightIcon from 'react-icons/lib/fa/angle-right';
55
import RefreshIcon from 'react-icons/lib/md/refresh';
6-
import ExternalIcon from 'react-icons/lib/md/open-in-new';
76

87
import Switch from 'common/components/Switch';
98
import Tooltip from 'common/components/Tooltip';
109

1110
import HorizontalAlign from './HorizontalAlign';
1211
import VerticalAlign from './VerticalAlign';
1312
import AddressBar from '../AddressBar';
13+
import ExternalIcon from './ExternalOpen';
1414
import {
1515
Container,
1616
Icons,
@@ -32,6 +32,7 @@ function Navigator({
3232
zenMode,
3333
alignRight,
3434
alignBottom,
35+
alignDirection,
3536
}) {
3637
return (
3738
<Container className="flying-container-handler" style={{ cursor: 'move' }}>
@@ -53,31 +54,38 @@ function Navigator({
5354
>
5455
<AddressBar url={url} onChange={onChange} onConfirm={onConfirm} />
5556
</AddressBarContainer>
56-
{!zenMode &&
57-
alignBottom && (
58-
<Icon onClick={alignBottom}>
59-
<Tooltip title="Align To Bottom">
60-
<HorizontalAlign />
61-
</Tooltip>
62-
</Icon>
63-
)}
64-
{!zenMode &&
65-
alignRight && (
66-
<Icon onClick={alignRight}>
67-
<Tooltip title="Align To Right">
68-
<VerticalAlign />
69-
</Tooltip>
70-
</Icon>
71-
)}
72-
73-
{!zenMode &&
74-
openNewWindow && (
75-
<Icon style={{ marginRight: '0.75rem' }} onClick={openNewWindow}>
76-
<Tooltip title="Open In A New Window">
77-
<ExternalIcon />
78-
</Tooltip>
79-
</Icon>
80-
)}
57+
{alignBottom && (
58+
<Icon
59+
style={{ fontSize: 18, padding: 4, marginRight: 4 }}
60+
selected={alignDirection === 'bottom'}
61+
onClick={alignBottom}
62+
>
63+
<Tooltip title="Dock to Bottom">
64+
<HorizontalAlign />
65+
</Tooltip>
66+
</Icon>
67+
)}
68+
{alignRight && (
69+
<Icon
70+
style={{ fontSize: 18, padding: 4, marginRight: 4 }}
71+
selected={alignDirection === 'right'}
72+
onClick={alignRight}
73+
>
74+
<Tooltip title="Dock to Right">
75+
<VerticalAlign />
76+
</Tooltip>
77+
</Icon>
78+
)}
79+
{openNewWindow && (
80+
<Icon
81+
style={{ fontSize: 18, padding: 4, marginRight: zenMode ? 8 : 16 }}
82+
onClick={openNewWindow}
83+
>
84+
<Tooltip title="Open In New Window">
85+
<ExternalIcon />
86+
</Tooltip>
87+
</Icon>
88+
)}
8189
{!zenMode &&
8290
toggleProjectView && (
8391
<SwitchContainer>

0 commit comments

Comments
 (0)