Skip to content

Commit 85f2fa3

Browse files
committed
Merge develop
2 parents 28ada7e + cd79754 commit 85f2fa3

25 files changed

+737
-109
lines changed

.env.example

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,21 @@ EXAMPLE_USER_PASSWORD=hellop5js
1010
GG_EXAMPLES_USERNAME=generativedesign
1111
GG_EXAMPLES_EMAIL=[email protected]
1212
GG_EXAMPLES_PASS=generativedesign
13-
ML5_LIBRARY_USERNAME=ml5
14-
ML5_LIBRARY_EMAIL=[email protected]
15-
ML5_LIBRARY_PASS=helloml5
1613
GITHUB_ID=<your-github-client-id>
1714
GITHUB_SECRET=<your-github-client-secret>
1815
GOOGLE_ID=<your-google-client-id> (use google+ api)
1916
GOOGLE_SECRET=<your-google-client-secret> (use google+ api)
2017
MAILGUN_DOMAIN=<your-mailgun-domain>
2118
MAILGUN_KEY=<your-mailgun-api-key>
19+
ML5_LIBRARY_USERNAME=ml5
20+
ML5_LIBRARY_EMAIL=[email protected]
21+
ML5_LIBRARY_PASS=helloml5
22+
MOBILE_ENABLED=true
2223
MONGO_URL=mongodb://localhost:27017/p5js-web-editor
2324
PORT=8000
2425
S3_BUCKET=<your-s3-bucket>
2526
S3_BUCKET_URL_BASE=<alt-for-s3-url>
2627
SESSION_SECRET=whatever_you_want_this_to_be_it_only_matters_for_production
28+
TRANSLATIONS_ENABLED=true
2729
UI_ACCESS_TOKEN_ENABLED=false
2830
UPLOAD_LIMIT=250000000
29-
MOBILE_ENABLED=true

client/components/Nav.jsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,9 @@ class Nav extends React.PureComponent {
422422
onBlur={this.handleBlur}
423423
>
424424
{this.props.t('Nav.Edit.TidyCode')}
425-
<span className="nav__keyboard-shortcut">{'\u21E7'}+Tab</span>
425+
<span className="nav__keyboard-shortcut">
426+
{metaKeyName}+{'\u21E7'}+F
427+
</span>
426428
</button>
427429
</li>
428430
<li className="nav__dropdown-item">
@@ -865,8 +867,6 @@ Nav.propTypes = {
865867
cmController: PropTypes.shape({
866868
tidyCode: PropTypes.func,
867869
showFind: PropTypes.func,
868-
findNext: PropTypes.func,
869-
findPrev: PropTypes.func,
870870
showReplace: PropTypes.func,
871871
getContent: PropTypes.func
872872
}),

client/components/__test__/Nav.test.jsx renamed to client/components/Nav.unit.test.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React from 'react';
22
import { render } from '@testing-library/react';
33

4-
import { NavComponent } from '../Nav';
4+
import { NavComponent } from './Nav';
55

6-
jest.mock('../../i18n');
6+
jest.mock('../i18n');
77

88
describe('Nav', () => {
99
const props = {

client/components/__test__/__snapshots__/Nav.test.jsx.snap renamed to client/components/__snapshots__/Nav.unit.test.jsx.snap

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ exports[`Nav renders correctly 1`] = `
8585
<span
8686
class="nav__keyboard-shortcut"
8787
>
88-
⇧+Tab
88+
⌃+⇧+F
8989
</span>
9090
</button>
9191
</li>

client/modules/IDE/components/AddToCollectionSketchList.jsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ class SketchList extends React.Component {
5252
};
5353

5454
inCollection = (sketch) =>
55-
this.props.collection.items.find((item) => item.project.id === sketch.id) !=
56-
null;
55+
this.props.collection.items.find((item) =>
56+
item.isDeleted ? false : item.project.id === sketch.id
57+
) != null;
5758

5859
render() {
5960
const hasSketches = this.props.sketches.length > 0;

client/modules/IDE/components/Editor.jsx

Lines changed: 45 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import PropTypes from 'prop-types';
22
import React from 'react';
33
import CodeMirror from 'codemirror';
4-
import beautifyJS from 'js-beautify';
4+
import emmet from '@emmetio/codemirror-plugin';
5+
import prettier from 'prettier';
6+
import babelParser from 'prettier/parser-babel';
7+
import htmlParser from 'prettier/parser-html';
8+
import cssParser from 'prettier/parser-postcss';
59
import { withTranslation } from 'react-i18next';
610
import 'codemirror/mode/css/css';
711
import 'codemirror/addon/selection/active-line';
@@ -56,15 +60,12 @@ import * as UserActions from '../../User/actions';
5660
import * as ToastActions from '../actions/toast';
5761
import * as ConsoleActions from '../actions/console';
5862

59-
const beautifyCSS = beautifyJS.css;
60-
const beautifyHTML = beautifyJS.html;
63+
emmet(CodeMirror);
6164

6265
window.JSHINT = JSHINT;
6366
window.CSSLint = CSSLint;
6467
window.HTMLHint = HTMLHint;
65-
delete CodeMirror.keyMap.sublime['Shift-Tab'];
6668

67-
const IS_TAB_INDENT = false;
6869
const INDENTATION_AMOUNT = 2;
6970

7071
class Editor extends React.Component {
@@ -84,8 +85,6 @@ class Editor extends React.Component {
8485
}
8586
}, 2000);
8687
this.showFind = this.showFind.bind(this);
87-
this.findNext = this.findNext.bind(this);
88-
this.findPrev = this.findPrev.bind(this);
8988
this.showReplace = this.showReplace.bind(this);
9089
this.getContent = this.getContent.bind(this);
9190
}
@@ -107,6 +106,11 @@ class Editor extends React.Component {
107106
keyMap: 'sublime',
108107
highlightSelectionMatches: true, // highlight current search match
109108
matchBrackets: true,
109+
emmet: {
110+
preview: ['html'],
111+
markTagPairs: true,
112+
autoRenameTags: true
113+
},
110114
autoCloseBrackets: this.props.autocloseBracketsQuotes,
111115
styleSelectedText: true,
112116
lint: {
@@ -129,6 +133,7 @@ class Editor extends React.Component {
129133
metaKey === 'Ctrl' ? `${metaKey}-H` : `${metaKey}-Option-F`;
130134
this._cm.setOption('extraKeys', {
131135
Tab: (cm) => {
136+
if (!cm.execCommand('emmetExpandAbbreviation')) return;
132137
// might need to specify and indent more?
133138
const selection = cm.doc.getSelection();
134139
if (selection.length > 0) {
@@ -137,11 +142,13 @@ class Editor extends React.Component {
137142
cm.replaceSelection(' '.repeat(INDENTATION_AMOUNT));
138143
}
139144
},
145+
Enter: 'emmetInsertLineBreak',
146+
Esc: 'emmetResetAbbreviation',
140147
[`${metaKey}-Enter`]: () => null,
141148
[`Shift-${metaKey}-Enter`]: () => null,
142149
[`${metaKey}-F`]: 'findPersistent',
143-
[`${metaKey}-G`]: 'findNext',
144-
[`Shift-${metaKey}-G`]: 'findPrev',
150+
[`${metaKey}-G`]: 'findPersistentNext',
151+
[`Shift-${metaKey}-G`]: 'findPersistentPrev',
145152
[replaceCommand]: 'replace'
146153
});
147154

@@ -168,8 +175,14 @@ class Editor extends React.Component {
168175
});
169176

170177
this._cm.on('keydown', (_cm, e) => {
171-
// 9 === Tab
172-
if (e.keyCode === 9 && e.shiftKey) {
178+
// 70 === f
179+
if (
180+
((metaKey === 'Cmd' && e.metaKey) ||
181+
(metaKey === 'Ctrl' && e.ctrlKey)) &&
182+
e.shiftKey &&
183+
e.keyCode === 70
184+
) {
185+
e.preventDefault();
173186
this.tidyCode();
174187
}
175188
});
@@ -181,8 +194,6 @@ class Editor extends React.Component {
181194
this.props.provideController({
182195
tidyCode: this.tidyCode,
183196
showFind: this.showFind,
184-
findNext: this.findNext,
185-
findPrev: this.findPrev,
186197
showReplace: this.showReplace,
187198
getContent: this.getContent
188199
});
@@ -302,16 +313,6 @@ class Editor extends React.Component {
302313
return updatedFile;
303314
}
304315

305-
findPrev() {
306-
this._cm.focus();
307-
this._cm.execCommand('findPrev');
308-
}
309-
310-
findNext() {
311-
this._cm.focus();
312-
this._cm.execCommand('findNext');
313-
}
314-
315316
showFind() {
316317
this._cm.execCommand('findPersistent');
317318
}
@@ -320,31 +321,33 @@ class Editor extends React.Component {
320321
this._cm.execCommand('replace');
321322
}
322323

324+
prettierFormatWithCursor(parser, plugins) {
325+
try {
326+
const { formatted, cursorOffset } = prettier.formatWithCursor(
327+
this._cm.doc.getValue(),
328+
{
329+
cursorOffset: this._cm.doc.indexFromPos(this._cm.doc.getCursor()),
330+
parser,
331+
plugins
332+
}
333+
);
334+
this._cm.doc.setValue(formatted);
335+
this._cm.focus();
336+
this._cm.doc.setCursor(this._cm.doc.posFromIndex(cursorOffset));
337+
} catch (error) {
338+
console.error(error);
339+
}
340+
}
341+
323342
tidyCode() {
324-
const beautifyOptions = {
325-
indent_size: INDENTATION_AMOUNT,
326-
indent_with_tabs: IS_TAB_INDENT
327-
};
328343
const mode = this._cm.getOption('mode');
329-
const currentPosition = this._cm.doc.getCursor();
330344
if (mode === 'javascript') {
331-
this._cm.doc.setValue(
332-
beautifyJS(this._cm.doc.getValue(), beautifyOptions)
333-
);
345+
this.prettierFormatWithCursor('babel', [babelParser]);
334346
} else if (mode === 'css') {
335-
this._cm.doc.setValue(
336-
beautifyCSS(this._cm.doc.getValue(), beautifyOptions)
337-
);
347+
this.prettierFormatWithCursor('css', [cssParser]);
338348
} else if (mode === 'htmlmixed') {
339-
this._cm.doc.setValue(
340-
beautifyHTML(this._cm.doc.getValue(), beautifyOptions)
341-
);
349+
this.prettierFormatWithCursor('html', [htmlParser]);
342350
}
343-
this._cm.focus();
344-
this._cm.doc.setCursor({
345-
line: currentPosition.line,
346-
ch: currentPosition.ch + INDENTATION_AMOUNT
347-
});
348351
}
349352

350353
initializeDocuments(files) {

client/modules/IDE/components/FileNode.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function parseFileName(name) {
1616
const nameArray = name.split('.');
1717
if (nameArray.length > 1) {
1818
const extension = `.${nameArray[nameArray.length - 1]}`;
19-
const baseName = nameArray.slice(0, -1).join('');
19+
const baseName = nameArray.slice(0, -1).join('.');
2020
const firstLetter = baseName[0];
2121
const lastLetter = baseName[baseName.length - 1];
2222
const middleText = baseName.slice(1, -1);

client/modules/IDE/components/KeyboardShortcutModal.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ function KeyboardShortcutModal() {
2424
</p>
2525
<ul className="keyboard-shortcuts__list">
2626
<li className="keyboard-shortcut-item">
27-
<span className="keyboard-shortcut__command">{'\u21E7'} + Tab</span>
27+
<span className="keyboard-shortcut__command">
28+
{metaKeyName} + {'\u21E7'} + F
29+
</span>
2830
<span>{t('KeyboardShortcuts.CodeEditing.Tidy')}</span>
2931
</li>
3032
<li className="keyboard-shortcut-item">

client/modules/IDE/components/PreviewFrame.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
} from '../actions/preferences';
3636
import { setBlobUrl } from '../actions/files';
3737
import { clearConsole, dispatchConsoleEvent } from '../actions/console';
38+
import getConfig from '../../../utils/getConfig';
3839

3940
const shouldRenderSketch = (props, prevProps = undefined) => {
4041
const { isPlaying, previewIsRefreshing, fullView } = props;
@@ -168,7 +169,7 @@ class PreviewFrame extends React.Component {
168169
}
169170

170171
const previewScripts = sketchDoc.createElement('script');
171-
previewScripts.src = '/previewScripts.js';
172+
previewScripts.src = getConfig('PREVIEW_SCRIPTS_URL');
172173
sketchDoc.head.appendChild(previewScripts);
173174

174175
const sketchDocString = `<!DOCTYPE HTML>\n${sketchDoc.documentElement.outerHTML}`;

client/modules/IDE/pages/IDEView.jsx

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,6 @@ class IDEView extends React.Component {
101101
if (nextProps.location !== this.props.location) {
102102
this.props.setPreviousPath(this.props.location.pathname);
103103
}
104-
105-
if (this.props.ide.consoleIsExpanded !== nextProps.ide.consoleIsExpanded) {
106-
this.setState({
107-
consoleSize: nextProps.ide.consoleIsExpanded ? 150 : 29
108-
});
109-
}
110-
111104
if (this.props.ide.sidebarIsExpanded !== nextProps.ide.sidebarIsExpanded) {
112105
this.setState({
113106
sidebarSize: nextProps.ide.sidebarIsExpanded ? 160 : 20
@@ -337,7 +330,9 @@ class IDEView extends React.Component {
337330
<SplitPane
338331
split="horizontal"
339332
primary="second"
340-
size={this.state.consoleSize}
333+
size={
334+
this.props.ide.consoleIsExpanded ? this.state.consoleSize : 29
335+
}
341336
minSize={29}
342337
onChange={(size) => this.setState({ consoleSize: size })}
343338
allowResize={this.props.ide.consoleIsExpanded}
@@ -378,10 +373,7 @@ class IDEView extends React.Component {
378373
</main>
379374
{this.props.ide.modalIsVisible && <NewFileModal />}
380375
{this.props.ide.newFolderModalVisible && (
381-
<NewFolderModal
382-
closeModal={this.props.closeNewFolderModal}
383-
createFolder={this.props.createFolder}
384-
/>
376+
<NewFolderModal closeModal={this.props.closeNewFolderModal} />
385377
)}
386378
{this.props.ide.uploadFileModalVisible && (
387379
<UploadFileModal closeModal={this.props.closeUploadFileModal} />
@@ -505,9 +497,6 @@ IDEView.propTypes = {
505497
}),
506498
updatedAt: PropTypes.string
507499
}).isRequired,
508-
editorAccessibility: PropTypes.shape({
509-
lintMessages: PropTypes.objectOf(PropTypes.shape()).isRequired
510-
}).isRequired,
511500
preferences: PropTypes.shape({
512501
autosave: PropTypes.bool.isRequired,
513502
fontSize: PropTypes.number.isRequired,
@@ -564,7 +553,6 @@ IDEView.propTypes = {
564553
newFolder: PropTypes.func.isRequired,
565554
closeNewFolderModal: PropTypes.func.isRequired,
566555
closeNewFileModal: PropTypes.func.isRequired,
567-
createFolder: PropTypes.func.isRequired,
568556
closeShareModal: PropTypes.func.isRequired,
569557
closeKeyboardShortcutModal: PropTypes.func.isRequired,
570558
toast: PropTypes.shape({

client/modules/IDE/reducers/files.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ function draw() {
1212
const defaultHTML = `<!DOCTYPE html>
1313
<html lang="en">
1414
<head>
15-
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/p5.js"></script>
16-
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.2.0/addons/p5.sound.min.js"></script>
15+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.3.0/p5.js"></script>
16+
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.3.0/addons/p5.sound.min.js"></script>
1717
<link rel="stylesheet" type="text/css" href="style.css">
1818
<meta charset="utf-8" />
1919

client/styles/abstracts/_variables.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ $themes: (
8383
input-text-color: $dark,
8484
input-background-color: $lightest,
8585
input-secondary-background-color: $lightest,
86+
input-selection-text-color: $dark,
87+
input-selection-background-color: $medium-light,
8688
input-border-color: $middle-light,
8789
search-background-color: $lightest,
8890
search-clear-background-color: $light,
@@ -163,6 +165,8 @@ $themes: (
163165
input-text-color: $lightest,
164166
input-background-color: $dark,
165167
input-secondary-background-color: $medium-dark,
168+
input-selection-text-color: $darkest,
169+
input-selection-background-color: $lightest,
166170
input-border-color: $middle-dark,
167171
search-background-color: $lightest,
168172
search-clear-background-color: $medium-dark,
@@ -241,6 +245,8 @@ $themes: (
241245
input-text-color: $lightest,
242246
input-background-color: $dark,
243247
input-secondary-background-color: $medium-dark,
248+
input-selection-text-color: $darkest,
249+
input-selection-background-color: $lightest,
244250
input-border-color: $middle-dark,
245251
search-background-color: $white,
246252
search-clear-background-color: $medium-dark,

client/styles/base/_base.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ textarea {
4444
}
4545
}
4646

47+
input::selection,
48+
textarea::selection {
49+
@include themify() {
50+
color: getThemifyVariable('input-selection-text-color');
51+
background-color: getThemifyVariable('input-selection-background-color');
52+
}
53+
}
54+
4755
button[type="submit"],
4856
input[type="submit"] {
4957
@include themify() {

0 commit comments

Comments
 (0)