ghost-portal/packages/app-js/src/Editor.tsx
Stefanie Doll 333b94001e
Bugfix: deep clone imported snippets (#737)
* Yarn.lock update

* Deep clone imported snippets, state.snippet empty on default

* Fixed wrong defailt type for 'selected'

* Fix onMount behaviour
2019-02-20 12:53:48 +01:00

51 lines
1.1 KiB
TypeScript

// Copyright 2017-2019 @polkadot/app-js authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { BareProps } from '@polkadot/ui-app/types';
import React from 'react';
import CodeFlask from 'codeflask';
type Props = BareProps & {
isDevelopment: boolean,
code: string,
onEdit: (code: string) => void
};
export default class Editor extends React.Component<Props> {
private id: string = `flask-${Date.now()}`;
private editor: any;
componentDidMount () {
const { onEdit } = this.props;
this.editor = new CodeFlask(`#${this.id}`, {
language: 'js',
lineNumbers: true
});
this.editor.updateCode(this.props.code);
this.editor.editorRoot.addEventListener('keydown', () => {
this.editor.onUpdate(onEdit);
});
}
shouldComponentUpdate (nextProps: Props): boolean {
return (
nextProps.code !== this.props.code
);
}
componentDidUpdate () {
this.editor.updateCode(this.props.code);
}
render () {
return (
<div id={this.id} />
);
}
}