Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Fixing System JS
Browse files Browse the repository at this point in the history
  • Loading branch information
ghecquet committed Mar 22, 2017
1 parent ecc2993 commit 1385cd4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
20 changes: 15 additions & 5 deletions core/src/plugins/editor.codemirror/res/js/Editor.js
Expand Up @@ -22,8 +22,7 @@ import CodeMirror from './CodeMirror';

import SystemJS from 'systemjs';

window.define = SystemJS.amdDefine;
window.require = window.requirejs = SystemJS.amdRequire;
let {define, require} = window

SystemJS.config({
baseURL: 'plugins/editor.codemirror/node_modules',
Expand All @@ -38,9 +37,13 @@ class Editor extends React.Component {
constructor(props) {
super(props)

const {pydio, node, url} = props
const {pydio, node, url, onLoad} = props

let loaded = new Promise((resolve, reject) => {

window.define = SystemJS.amdDefine;
window.require = window.requirejs = SystemJS.amdRequire;

SystemJS.import('codemirror/lib/codemirror').then((m) => {
let CodeMirror = m
SystemJS.import('codemirror/addon/search/search')
Expand All @@ -57,13 +60,19 @@ class Editor extends React.Component {
url: url,
loaded: loaded
}

this.onLoad = (codemirror) => {
this.props.onLoad(codemirror)

window.define = define
window.require = window.requirejs = require
}
}

// Handling loading
componentDidMount() {
this.state.loaded.then((CodeMirror) => {
this.setState({codemirrorInstance: CodeMirror})
this.props.onReady()
})
}

Expand All @@ -79,14 +88,15 @@ class Editor extends React.Component {
codeMirrorInstance={this.state.codemirrorInstance}
options={this.props.options}

onLoad={this.props.onLoad}
onLoad={this.onLoad}
onChange={this.props.onChange}
onCursorChange={this.props.onCursorChange}
/>
)
}
}


Editor.propTypes = {
url: React.PropTypes.string.isRequired,

Expand Down
33 changes: 9 additions & 24 deletions core/src/plugins/editor.codemirror/res/js/PydioCodeMirror.js
Expand Up @@ -36,7 +36,6 @@ class PydioCodeMirror extends React.Component {
ready: false
}

this.onReady = this.onReady.bind(this)
this.onLoad = this.onLoad.bind(this)
this.onChange = this.onChange.bind(this)
this.onCursorChange = this.onCursorChange.bind(this)
Expand Down Expand Up @@ -70,10 +69,6 @@ class PydioCodeMirror extends React.Component {
}, (transport) => this.setState({content: transport.responseText}));
}

onReady() {
this.setState({ ready: true })
}

onLoad(codemirror) {
this.setState({ codemirror: codemirror })
}
Expand All @@ -97,37 +92,27 @@ class PydioCodeMirror extends React.Component {
}

render() {
let editor = null;
let menu = null;

if (this.state.content) {
editor = <Editor
return (
<CompositeEditor
{...this.props}
actions={this.state.codemirror ? [
<MenuOptions pydio={this.props.pydio} codemirror={this.state.codemirror} onSave={this.save.bind(this)} />,
<MenuActions pydio={this.props.pydio} codemirror={this.state.codemirror} cursor={this.state.cursor} />
] : []}
error={this.state.error}
url={this.state.url}
options={{lineNumbers: this.state.lineNumbers, lineWrapping: this.state.lineWrapping}}
content={this.state.content}
onReady={this.onReady}
onLoad={this.onLoad}
onChange={this.onChange}
onCursorChange={this.onCursorChange}
/>
}

if (this.state.codemirror) {
menu = [
<MenuOptions {...this.props} firstChild={true} codemirror={this.state.codemirror} onSave={this.save.bind(this)} />,
<MenuActions {...this.props} lastChild={true} codemirror={this.state.codemirror} cursor={this.state.cursor} />
]
}

return (
<PydioComponents.AbstractEditor {...this.props} loading={!this.state.ready} preview={this.state.preview} errorString={this.state.error} actions={menu}>
{editor}
</PydioComponents.AbstractEditor>
);
}
}

let CompositeEditor = PydioHOCs.withActions(Editor)

// We need to attach the element to window else it won't be found
window.PydioCodeMirror = {
PydioEditor: PydioCodeMirror,
Expand Down

0 comments on commit 1385cd4

Please sign in to comment.