Skip to content

Commit 34172a9

Browse files
committed
Merge branch 'master' into heroku-deployment
2 parents 0c1cbe4 + 5bcb511 commit 34172a9

File tree

9 files changed

+70
-48
lines changed

9 files changed

+70
-48
lines changed

client/components/Nav.jsx

+42-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
3+
import { bindActionCreators } from 'redux';
4+
import { connect } from 'react-redux';
5+
import { withRouter } from 'react-router';
36
import { Link } from 'react-router';
47
import InlineSVG from 'react-inlinesvg';
58
import classNames from 'classnames';
9+
import * as IDEActions from '../modules/IDE/actions/ide';
610

711
import {
812
metaKeyName,
@@ -315,6 +319,30 @@ class Nav extends React.PureComponent {
315319
<span>Sketch</span>
316320
<InlineSVG src={triangleUrl} />
317321
</button>
322+
<li className="nav__dropdown-item">
323+
<button
324+
onClick={() => {
325+
this.props.newFile();
326+
this.setDropdown('none');
327+
}}
328+
onFocus={this.handleFocus.bind(this, 'sketch')}
329+
onBlur={this.handleBlur}
330+
>
331+
Add File
332+
</button>
333+
</li>
334+
<li className="nav__dropdown-item">
335+
<button
336+
onClick={() => {
337+
this.props.newFolder();
338+
this.setDropdown('none');
339+
}}
340+
onFocus={this.handleFocus.bind(this, 'sketch')}
341+
onBlur={this.handleBlur}
342+
>
343+
Add Folder
344+
</button>
345+
</li>
318346
<li className="nav__dropdown-item">
319347
<button
320348
onClick={() => {
@@ -558,7 +586,9 @@ Nav.propTypes = {
558586
}),
559587
startSketch: PropTypes.func.isRequired,
560588
stopSketch: PropTypes.func.isRequired,
561-
setAllAccessibleOutput: PropTypes.func.isRequired
589+
setAllAccessibleOutput: PropTypes.func.isRequired,
590+
newFile: PropTypes.func.isRequired,
591+
newFolder: PropTypes.func.isRequired
562592
};
563593

564594
Nav.defaultProps = {
@@ -569,4 +599,14 @@ Nav.defaultProps = {
569599
cmController: {}
570600
};
571601

572-
export default Nav;
602+
function mapDispatchToProps(dispatch) {
603+
return bindActionCreators(
604+
Object.assign(
605+
{},
606+
IDEActions
607+
),
608+
dispatch
609+
);
610+
}
611+
612+
export default withRouter(connect(() => ({}), mapDispatchToProps)(Nav));

client/modules/IDE/components/Console.jsx

+2-17
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,6 @@ class Console extends React.Component {
7070
}
7171
}
7272

73-
formatData(args) {
74-
if (!Array.isArray(args)) {
75-
return Array.of(args);
76-
}
77-
return args;
78-
}
79-
8073
render() {
8174
const consoleClass = classNames({
8275
'preview-console': true,
@@ -105,16 +98,8 @@ class Console extends React.Component {
10598
</div>
10699
<div ref={(element) => { this.consoleMessages = element; }} className="preview-console__messages">
107100
{this.props.consoleEvents.map((consoleEvent) => {
108-
const { arguments: args, method, times } = consoleEvent;
101+
const { method, times } = consoleEvent;
109102
const { theme } = this.props;
110-
Object.assign(consoleEvent, { data: this.formatData(args) });
111-
if (Object.keys(args).length === 0) {
112-
return (
113-
<div key={consoleEvent.id} className="preview-console__message preview-console__message--undefined">
114-
<span key={`${consoleEvent.id}-0`}>undefined</span>
115-
</div>
116-
);
117-
}
118103
return (
119104
<div key={consoleEvent.id} className={`preview-console__message preview-console__message--${method}`}>
120105
{ times > 1 &&
@@ -127,7 +112,7 @@ class Console extends React.Component {
127112
}
128113
<ConsoleFeed
129114
styles={this.getConsoleFeedStyle(theme, times)}
130-
logs={Array.of(consoleEvent)}
115+
logs={[consoleEvent]}
131116
/>
132117
</div>
133118
);

client/modules/IDE/components/Editor.jsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,8 @@ class Editor extends React.Component {
194194
if (this.props.runtimeErrorWarningVisible && this._cm.getDoc().modeOption === 'javascript') {
195195
this.props.consoleEvents.forEach((consoleEvent) => {
196196
if (consoleEvent.method === 'error') {
197-
if (consoleEvent.arguments.indexOf(')') > -1) {
198-
const n = consoleEvent.arguments.replace(')', '').split(' ');
197+
if (consoleEvent.data[0].indexOf(')') > -1) {
198+
const n = consoleEvent.data[0].replace(')', '').split(' ');
199199
const lineNumber = parseInt(n[n.length - 1], 10) - 1;
200200
this._cm.addLineClass(lineNumber, 'background', 'line-runtime-error');
201201
}

client/modules/IDE/components/PreviewFrame.jsx

+7-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import loopProtect from 'loop-protect';
88
import { JSHINT } from 'jshint';
99
import decomment from 'decomment';
1010
import classNames from 'classnames';
11+
import { Decode } from 'console-feed';
1112
import { getBlobUrl } from '../actions/files';
1213
import { resolvePathToFile } from '../../../../server/utils/filePath';
1314
import {
@@ -80,8 +81,10 @@ class PreviewFrame extends React.Component {
8081

8182
handleConsoleEvent(messageEvent) {
8283
if (Array.isArray(messageEvent.data)) {
83-
messageEvent.data.every((message, index, arr) => {
84-
const { arguments: args } = message;
84+
const decodedMessages = messageEvent.data.map(message => Object.assign(Decode(message.log), { source: message.source }));
85+
86+
decodedMessages.every((message, index, arr) => {
87+
const { data: args } = message;
8588
let hasInfiniteLoop = false;
8689
Object.keys(args).forEach((key) => {
8790
if (typeof args[key] === 'string' && args[key].includes('Exiting potential infinite loop')) {
@@ -99,7 +102,7 @@ class PreviewFrame extends React.Component {
99102
}
100103
const cur = Object.assign(message, { times: 1 });
101104
const nextIndex = index + 1;
102-
while (isEqual(cur.arguments, arr[nextIndex].arguments) && cur.method === arr[nextIndex].method) {
105+
while (isEqual(cur.data, arr[nextIndex].data) && cur.method === arr[nextIndex].method) {
103106
cur.times += 1;
104107
arr.splice(nextIndex, 1);
105108
if (nextIndex === arr.length) {
@@ -109,7 +112,7 @@ class PreviewFrame extends React.Component {
109112
return true;
110113
});
111114

112-
this.props.dispatchConsoleEvent(messageEvent.data);
115+
this.props.dispatchConsoleEvent(decodedMessages);
113116
}
114117
}
115118

client/modules/IDE/pages/IDEView.jsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -671,7 +671,8 @@ IDEView.propTypes = {
671671
function mapStateToProps(state) {
672672
return {
673673
files: state.files,
674-
selectedFile: state.files.find(file => file.isSelectedFile),
674+
selectedFile: state.files.find(file => file.isSelectedFile) ||
675+
state.files.find(file => file.name === 'sketch.js'),
675676
htmlFile: getHTMLFile(state.files),
676677
ide: state.ide,
677678
preferences: state.preferences,

client/modules/IDE/reducers/console.js

-5
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@ import * as ActionTypes from '../../../constants';
22

33
const consoleMax = 500;
44
const initialState = [];
5-
let messageId = 0;
65

76
const console = (state = initialState, action) => {
87
let messages;
98
switch (action.type) {
109
case ActionTypes.CONSOLE_EVENT:
1110
messages = [...action.event];
12-
messages.forEach((message) => {
13-
message.id = messageId;
14-
messageId += 1;
15-
});
1611
return state.concat(messages).slice(-consoleMax);
1712
case ActionTypes.CLEAR_CONSOLE:
1813
return [];

client/utils/consoleUtils.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,11 @@ export const hijackConsoleErrorsScript = (offs) => {
3131
data = msg + ' (' + fileInfo[1] + ': line ' + fileInfo[0] + ')';
3232
}
3333
window.parent.postMessage([{
34-
method: 'error',
35-
arguments: data,
34+
log: [{
35+
method: 'error',
36+
data: [data],
37+
id: Date.now().toString()
38+
}],
3639
source: fileInfo[1]
3740
}], '*');
3841
return false;
@@ -58,8 +61,8 @@ export const getAllScriptOffsets = (htmlFile) => {
5861
} else {
5962
endFilenameInd = htmlFile.indexOf('.js', ind + startTag.length + 3);
6063
filename = htmlFile.substring(ind + startTag.length, endFilenameInd);
61-
// the length of hijackConsoleErrorsScript is 33 lines
62-
lineOffset = htmlFile.substring(0, ind).split('\n').length + 33;
64+
// the length of hijackConsoleErrorsScript is 36 lines
65+
lineOffset = htmlFile.substring(0, ind).split('\n').length + 36;
6366
offs.push([lineOffset, filename]);
6467
lastInd = ind + 1;
6568
}

client/utils/previewEntry.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ window.loopProtect = loopProtect;
66
const consoleBuffer = [];
77
const LOGWAIT = 500;
88
Hook(window.console, (log) => {
9-
const { method, data: args } = log[0];
109
consoleBuffer.push({
11-
method,
12-
arguments: args,
10+
log,
1311
source: 'sketch'
1412
});
1513
});

server/scripts/examples-gg-latest.js

+7-10
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,21 @@ const defaultHTML =
2121
`<!DOCTYPE html>
2222
<html>
2323
<head>
24-
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/p5.min.js"></script>
25-
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/addons/p5.dom.min.js"></script>
26-
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.1/addons/p5.sound.min.js"></script>
24+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.2/p5.min.js"></script>
25+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.2/addons/p5.dom.min.js"></script>
26+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.2/addons/p5.sound.min.js"></script>
2727
2828
<!-- Generative Design Dependencies here -->
2929
<!-- GG Bundled -->
30-
<script src=
31-
"https://rawgit.com/generative-design/Code-Package-p5.js/${branchName}/libraries/gg-dep-bundle/gg-dep-bundle.js">
32-
</script>
33-
30+
<script src="https://raw.githack.com/generative-design/Code-Package-p5.js/${branchName}/libraries/gg-dep-bundle/gg-dep-bundle.js"></script>
3431
<!-- Opentype -->
3532
<script src="https://cdnjs.cloudflare.com/ajax/libs/opentype.js/0.7.3/opentype.min.js"></script>
3633
<!-- Rita -->
3734
<script src="https://cdnjs.cloudflare.com/ajax/libs/rita/1.3.11/rita-small.min.js"></script>
3835
<!-- Chroma -->
3936
<script src="https://cdnjs.cloudflare.com/ajax/libs/chroma-js/1.3.6/chroma.min.js"></script>
4037
<!-- Jquery -->
41-
<script src="http://code.jquery.com/jquery-3.3.1.min.js"
38+
<script src="https://code.jquery.com/jquery-3.3.1.min.js"
4239
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
4340
crossorigin="anonymous"></script>
4441
@@ -432,10 +429,10 @@ function getAllSketchContent(newProjectList) {
432429
console.log(sketchFile.name);
433430
// https://cdn.rawgit.com/opensourcedesign/fonts/2f220059/gnu-freefont_freesans/FreeSans.otf?raw=true
434431
// "https://raw.githubusercontent.com/generative-design/Code-Package-p5.js/gg4editor/01_P/P_3_2_1_01/data/FreeSans.otf",
435-
const rawGitRef = `https://cdn.rawgit.com/${newProject.files[i].url.split('.com/')[1]}`;
432+
const rawGitRef = `https://raw.githack.com/${newProject.files[i].url.split('.com/')[1]}`;
436433
sketchFile.content = rawGitRef;
437434
sketchFile.url = rawGitRef;
438-
435+
// https://raw.githack.com/generative-design/Code-Package-p5.js/master/libraries/gg-dep-bundle/gg-dep-bundle.js
439436
// replace ref in sketch.js ==> should serve from the file?
440437
// newProject.files[1].content = newProject.files[1].content.replace(`'data/${sketchFile.name}'`, `'${rawGitRef}'`);
441438
resolve(newProject);

0 commit comments

Comments
 (0)