2016-07-13 12:44:24 -08:00
|
|
|
import React from 'react';
|
|
|
|
|
import Component from '../component';
|
2016-10-03 18:00:50 -08:00
|
|
|
import {decorate, getTermGroupProps} from '../utils/plugins';
|
|
|
|
|
import TermGroup_ from './term-group';
|
2016-07-13 12:44:24 -08:00
|
|
|
|
2016-10-03 18:00:50 -08:00
|
|
|
const TermGroup = decorate(TermGroup_, 'TermGroup');
|
2016-07-13 12:44:24 -08:00
|
|
|
|
|
|
|
|
export default class Terms extends Component {
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
constructor(props, context) {
|
2016-07-13 12:44:24 -08:00
|
|
|
super(props, context);
|
|
|
|
|
this.terms = {};
|
|
|
|
|
this.bound = new WeakMap();
|
|
|
|
|
this.onRef = this.onRef.bind(this);
|
|
|
|
|
props.ref_(this);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
componentWillReceiveProps(next) {
|
|
|
|
|
const {write} = next;
|
2016-07-13 12:44:24 -08:00
|
|
|
if (write && this.props.write !== write) {
|
|
|
|
|
this.getTermByUid(write.uid).write(write.data);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
shouldComponentUpdate(nextProps) {
|
2016-07-14 07:45:59 -08:00
|
|
|
for (const i in nextProps) {
|
2016-09-21 06:27:11 -08:00
|
|
|
if (i === 'write') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-07-14 07:45:59 -08:00
|
|
|
if (this.props[i] !== nextProps[i]) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (const i in this.props) {
|
2016-09-21 06:27:11 -08:00
|
|
|
if (i === 'write') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2016-07-14 07:45:59 -08:00
|
|
|
if (this.props[i] !== nextProps[i]) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
2016-07-14 07:45:59 -08:00
|
|
|
return false;
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
onRef(uid, term) {
|
2016-07-13 12:44:24 -08:00
|
|
|
if (term) {
|
|
|
|
|
this.terms[uid] = term;
|
2016-10-03 18:00:50 -08:00
|
|
|
} else if (!this.props.sessions[uid]) {
|
2016-07-13 12:44:24 -08:00
|
|
|
delete this.terms[uid];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
getTermByUid(uid) {
|
2016-07-13 12:44:24 -08:00
|
|
|
return this.terms[uid];
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
getActiveTerm() {
|
2016-07-13 12:44:24 -08:00
|
|
|
return this.getTermByUid(this.props.activeSession);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
getLastTermIndex() {
|
2016-07-22 11:38:15 -08:00
|
|
|
return this.props.sessions.length - 1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
onTerminal(uid, term) {
|
2016-07-13 12:44:24 -08:00
|
|
|
this.terms[uid] = term;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
componentWillUnmount() {
|
2016-07-13 12:44:24 -08:00
|
|
|
this.props.ref_(null);
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
template(css) {
|
|
|
|
|
return (<div
|
|
|
|
|
className={css('terms')}
|
|
|
|
|
>
|
2016-07-13 12:44:24 -08:00
|
|
|
{ this.props.customChildrenBefore }
|
|
|
|
|
{
|
2016-10-03 18:00:50 -08:00
|
|
|
this.props.termGroups.map(termGroup => {
|
|
|
|
|
const {uid} = termGroup;
|
|
|
|
|
const isActive = uid === this.props.activeRootGroup;
|
|
|
|
|
const props = getTermGroupProps(uid, this.props, {
|
|
|
|
|
termGroup,
|
|
|
|
|
terms: this.terms,
|
|
|
|
|
sessions: this.props.sessions,
|
2016-07-13 12:44:24 -08:00
|
|
|
customCSS: this.props.customCSS,
|
|
|
|
|
fontSize: this.props.fontSize,
|
2016-10-03 18:00:50 -08:00
|
|
|
borderColor: this.props.borderColor,
|
2016-07-13 12:44:24 -08:00
|
|
|
cursorColor: this.props.cursorColor,
|
2016-07-21 15:15:23 -08:00
|
|
|
cursorShape: this.props.cursorShape,
|
2016-07-13 12:44:24 -08:00
|
|
|
fontFamily: this.props.fontFamily,
|
2016-07-19 10:30:57 -08:00
|
|
|
fontSmoothing: this.props.fontSmoothing,
|
2016-07-13 12:44:24 -08:00
|
|
|
foregroundColor: this.props.foregroundColor,
|
2016-10-03 18:00:50 -08:00
|
|
|
backgroundColor: this.props.backgroundColor,
|
|
|
|
|
padding: this.props.padding,
|
2016-07-13 12:44:24 -08:00
|
|
|
colors: this.props.colors,
|
2016-08-05 14:30:40 -08:00
|
|
|
bell: this.props.bell,
|
2016-08-13 13:03:44 -08:00
|
|
|
bellSoundURL: this.props.bellSoundURL,
|
2016-09-30 04:30:11 -08:00
|
|
|
copyOnSelect: this.props.copyOnSelect,
|
2016-10-03 18:00:50 -08:00
|
|
|
modifierKeys: this.props.modifierKeys,
|
|
|
|
|
onActive: this.props.onActive,
|
|
|
|
|
onResize: this.props.onResize,
|
|
|
|
|
onTitle: this.props.onTitle,
|
|
|
|
|
onData: this.props.onData,
|
|
|
|
|
onURLAbort: this.props.onURLAbort
|
2016-07-13 12:44:24 -08:00
|
|
|
});
|
2016-10-03 18:00:50 -08:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={`d${uid}`}
|
|
|
|
|
className={css('termGroup', isActive && 'termGroupActive')}
|
|
|
|
|
>
|
|
|
|
|
<TermGroup
|
|
|
|
|
key={uid}
|
|
|
|
|
ref_={this.onRef}
|
|
|
|
|
{...props}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2016-07-13 12:44:24 -08:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
{ this.props.customChildren }
|
2016-09-21 06:27:11 -08:00
|
|
|
</div>);
|
2016-07-13 12:44:24 -08:00
|
|
|
}
|
|
|
|
|
|
2016-09-21 06:27:11 -08:00
|
|
|
styles() {
|
2016-07-13 12:44:24 -08:00
|
|
|
return {
|
|
|
|
|
terms: {
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
marginTop: '34px',
|
|
|
|
|
top: 0,
|
|
|
|
|
right: 0,
|
|
|
|
|
left: 0,
|
|
|
|
|
bottom: 0,
|
|
|
|
|
color: '#fff'
|
|
|
|
|
},
|
|
|
|
|
|
2016-10-03 18:00:50 -08:00
|
|
|
termGroup: {
|
2016-07-13 12:44:24 -08:00
|
|
|
display: 'none',
|
|
|
|
|
width: '100%',
|
|
|
|
|
height: '100%'
|
|
|
|
|
},
|
|
|
|
|
|
2016-10-03 18:00:50 -08:00
|
|
|
termGroupActive: {
|
2016-07-13 12:44:24 -08:00
|
|
|
display: 'block'
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|