1+ // TODO: convert to functional component
2+
13import PropTypes from 'prop-types' ;
24import React from 'react' ;
35import CodeMirror from 'codemirror' ;
@@ -40,32 +42,35 @@ import classNames from 'classnames';
4042import { debounce } from 'lodash' ;
4143import { connect } from 'react-redux' ;
4244import { bindActionCreators } from 'redux' ;
43- import '../../../utils/htmlmixed' ;
44- import '../../../utils/p5-javascript' ;
45- import Timer from '../components/Timer' ;
46- import EditorAccessibility from '../components/EditorAccessibility' ;
47- import { selectActiveFile } from '../selectors/files' ;
48- import AssetPreview from './AssetPreview' ;
49- import { metaKey } from '../../../utils/metaKey' ;
50- import './show-hint' ;
51- import * as hinter from '../../../utils/p5-hinter' ;
52-
53- import '../../../utils/codemirror-search' ;
54-
55- import beepUrl from '../../../sounds/audioAlert.mp3' ;
56- import UnsavedChangesDotIcon from '../../../images/unsaved-changes-dot.svg' ;
57- import RightArrowIcon from '../../../images/right-arrow.svg' ;
58- import LeftArrowIcon from '../../../images/left-arrow.svg' ;
59- import { getHTMLFile } from '../reducers/files' ;
60-
61- import * as FileActions from '../actions/files' ;
62- import * as IDEActions from '../actions/ide' ;
63- import * as ProjectActions from '../actions/project' ;
64- import * as EditorAccessibilityActions from '../actions/editorAccessibility' ;
65- import * as PreferencesActions from '../actions/preferences' ;
66- import * as UserActions from '../../User/actions' ;
67- import * as ToastActions from '../actions/toast' ;
68- import * as ConsoleActions from '../actions/console' ;
45+ import MediaQuery from 'react-responsive' ;
46+ import '../../../../utils/htmlmixed' ;
47+ import '../../../../utils/p5-javascript' ;
48+ import { metaKey } from '../../../../utils/metaKey' ;
49+ import '../show-hint' ;
50+ import * as hinter from '../../../../utils/p5-hinter' ;
51+ import '../../../../utils/codemirror-search' ;
52+
53+ import beepUrl from '../../../../sounds/audioAlert.mp3' ;
54+ import RightArrowIcon from '../../../../images/right-arrow.svg' ;
55+ import LeftArrowIcon from '../../../../images/left-arrow.svg' ;
56+ import { getHTMLFile } from '../../reducers/files' ;
57+ import { selectActiveFile } from '../../selectors/files' ;
58+
59+ import * as FileActions from '../../actions/files' ;
60+ import * as IDEActions from '../../actions/ide' ;
61+ import * as ProjectActions from '../../actions/project' ;
62+ import * as EditorAccessibilityActions from '../../actions/editorAccessibility' ;
63+ import * as PreferencesActions from '../../actions/preferences' ;
64+ import * as UserActions from '../../../User/actions' ;
65+ import * as ConsoleActions from '../../actions/console' ;
66+
67+ import AssetPreview from '../AssetPreview' ;
68+ import Timer from '../Timer' ;
69+ import EditorAccessibility from '../EditorAccessibility' ;
70+ import UnsavedChangesIndicator from '../UnsavedChangesIndicator' ;
71+ import { EditorContainer , EditorHolder } from './MobileEditor' ;
72+ import { FolderIcon } from '../../../../common/icons' ;
73+ import IconButton from '../../../../components/mobile/IconButton' ;
6974
7075emmet ( CodeMirror ) ;
7176
@@ -98,7 +103,7 @@ class Editor extends React.Component {
98103
99104 componentDidMount ( ) {
100105 this . beep = new Audio ( beepUrl ) ;
101- this . widgets = [ ] ;
106+ // this.widgets = [];
102107 this . _cm = CodeMirror ( this . codemirrorContainer , {
103108 theme : `p5-${ this . props . theme } ` ,
104109 lineNumbers : this . props . lineNumbers ,
@@ -306,6 +311,13 @@ class Editor extends React.Component {
306311 this . _cm . removeLineClass ( i , 'background' , 'line-runtime-error' ) ;
307312 }
308313 }
314+
315+ this . props . provideController ( {
316+ tidyCode : this . tidyCode ,
317+ showFind : this . showFind ,
318+ showReplace : this . showReplace ,
319+ getContent : this . getContent
320+ } ) ;
309321 }
310322
311323 componentWillUnmount ( ) {
@@ -496,52 +508,80 @@ class Editor extends React.Component {
496508 } ) ;
497509
498510 return (
499- < section className = { editorSectionClass } >
500- < header className = "editor__header" >
501- < button
502- aria-label = { this . props . t ( 'Editor.OpenSketchARIA' ) }
503- className = "sidebar__contract"
504- onClick = { ( ) => {
505- this . props . collapseSidebar ( ) ;
506- this . props . closeProjectOptions ( ) ;
507- } }
508- >
509- < LeftArrowIcon focusable = "false" aria-hidden = "true" />
510- </ button >
511- < button
512- aria-label = { this . props . t ( 'Editor.CloseSketchARIA' ) }
513- className = "sidebar__expand"
514- onClick = { this . props . expandSidebar }
515- >
516- < RightArrowIcon focusable = "false" aria-hidden = "true" />
517- </ button >
518- < div className = "editor__file-name" >
519- < span >
520- { this . props . file . name }
521- < span className = "editor__unsaved-changes" >
522- { this . props . unsavedChanges ? (
523- < UnsavedChangesDotIcon
524- role = "img"
525- aria-label = { this . props . t ( 'Editor.UnsavedChangesARIA' ) }
526- focusable = "false"
511+ < MediaQuery minWidth = { 770 } >
512+ { ( matches ) =>
513+ matches ? (
514+ < section className = { editorSectionClass } >
515+ < header className = "editor__header" >
516+ < button
517+ aria-label = { this . props . t ( 'Editor.OpenSketchARIA' ) }
518+ className = "sidebar__contract"
519+ onClick = { ( ) => {
520+ this . props . collapseSidebar ( ) ;
521+ this . props . closeProjectOptions ( ) ;
522+ } }
523+ >
524+ < LeftArrowIcon focusable = "false" aria-hidden = "true" />
525+ </ button >
526+ < button
527+ aria-label = { this . props . t ( 'Editor.CloseSketchARIA' ) }
528+ className = "sidebar__expand"
529+ onClick = { this . props . expandSidebar }
530+ >
531+ < RightArrowIcon focusable = "false" aria-hidden = "true" />
532+ </ button >
533+ < div className = "editor__file-name" >
534+ < span >
535+ { this . props . file . name }
536+ < UnsavedChangesIndicator />
537+ </ span >
538+ < Timer />
539+ </ div >
540+ </ header >
541+ < article
542+ ref = { ( element ) => {
543+ this . codemirrorContainer = element ;
544+ } }
545+ className = { editorHolderClass }
546+ />
547+ { this . props . file . url ? (
548+ < AssetPreview
549+ url = { this . props . file . url }
550+ name = { this . props . file . name }
551+ />
552+ ) : null }
553+ < EditorAccessibility lintMessages = { this . props . lintMessages } />
554+ </ section >
555+ ) : (
556+ < EditorContainer expanded = { this . props . isExpanded } >
557+ < header >
558+ < IconButton
559+ onClick = { this . props . expandSidebar }
560+ icon = { FolderIcon }
561+ />
562+ < span >
563+ { this . props . file . name }
564+ < UnsavedChangesIndicator />
565+ </ span >
566+ </ header >
567+ < section >
568+ < EditorHolder
569+ ref = { ( element ) => {
570+ this . codemirrorContainer = element ;
571+ } }
572+ />
573+ { this . props . file . url ? (
574+ < AssetPreview
575+ url = { this . props . file . url }
576+ name = { this . props . file . name }
527577 />
528578 ) : null }
529- </ span >
530- </ span >
531- < Timer />
532- </ div >
533- </ header >
534- < article
535- ref = { ( element ) => {
536- this . codemirrorContainer = element ;
537- } }
538- className = { editorHolderClass }
539- />
540- { this . props . file . url ? (
541- < AssetPreview url = { this . props . file . url } name = { this . props . file . name } />
542- ) : null }
543- < EditorAccessibility lintMessages = { this . props . lintMessages } />
544- </ section >
579+ < EditorAccessibility lintMessages = { this . props . lintMessages } />
580+ </ section >
581+ </ EditorContainer >
582+ )
583+ }
584+ </ MediaQuery >
545585 ) ;
546586 }
547587}
@@ -613,7 +653,6 @@ function mapStateToProps(state) {
613653 editorAccessibility : state . editorAccessibility ,
614654 user : state . user ,
615655 project : state . project ,
616- toast : state . toast ,
617656 consoleEvents : state . console ,
618657
619658 ...state . preferences ,
@@ -634,7 +673,6 @@ function mapDispatchToProps(dispatch) {
634673 IDEActions ,
635674 PreferencesActions ,
636675 UserActions ,
637- ToastActions ,
638676 ConsoleActions
639677 ) ,
640678 dispatch
0 commit comments