react-blessed
Version:
A react renderer for blessed.
111 lines (87 loc) • 3.47 kB
JavaScript
/**
* React Blessed Text Component
* =============================
*
* React component abstraction for the rendered text nodes.
*/
;
Object.defineProperty(exports, '__esModule', {
value: true
});
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
var _blessed = require('blessed');
var _blessed2 = _interopRequireDefault(_blessed);
var _ReactBlessedIDOperations = require('./ReactBlessedIDOperations');
/**
* Renders the given text element with blessed.
*
* @constructor ReactBlessedTextComponent
*/
var _ReactBlessedIDOperations2 = _interopRequireDefault(_ReactBlessedIDOperations);
var ReactBlessedTextComponent = (function () {
function ReactBlessedTextComponent(props) {
_classCallCheck(this, ReactBlessedTextComponent);
}
/**
* @param {ReactText} text
* @internal
*/
_createClass(ReactBlessedTextComponent, [{
key: 'construct',
value: function construct(text) {
this._currentElement = text;
this._rootNodeID = null;
this._stringText = '' + text;
}
/**
* Setting the content etc. of the parent node.
*
* @param {string} rootID - DOM ID of the root node.
* @param {ReactBlessedReconcileTransaction} transaction
* @param {object} context
* @internal
*/
}, {
key: 'mountComponent',
value: function mountComponent(rootID, transaction, context) {
this._rootNodeID = rootID;
var parent = _ReactBlessedIDOperations2['default'].getParent(rootID);
// Setting content of parent
parent.setContent(this._stringText);
}
/**
* Updates this component by updating the text content.
*
* @param {ReactText} nextText - The next text content.
* @param {ReactBlessedReconcileTransaction} transaction
* @internal
*/
}, {
key: 'receiveComponent',
value: function receiveComponent(nextText, transaction) {
this._currentElement = nextText;
var nextStringText = '' + nextText;
if (nextStringText !== this._stringText) {
this._stringText = nextStringText;
var _parent = _ReactBlessedIDOperations2['default'].getParent(this._rootNodeID);
// Setting content of parent
_parent.setContent(this._stringText);
}
}
/**
* Dropping the text component.
*/
}, {
key: 'unmountComponent',
value: function unmountComponent() {
var parent = _ReactBlessedIDOperations2['default'].getParent(this._rootNodeID);
// Setting content of parent
parent.setContent('');
}
}]);
return ReactBlessedTextComponent;
})();
exports['default'] = ReactBlessedTextComponent;
module.exports = exports['default'];