UNPKG

3.47 kBJavaScriptView Raw
1/**
2 * React Blessed Text Component
3 * =============================
4 *
5 * React component abstraction for the rendered text nodes.
6 */
7'use strict';
8
9Object.defineProperty(exports, '__esModule', {
10 value: true
11});
12
13var _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; }; })();
14
15function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
16
17function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }
18
19var _blessed = require('blessed');
20
21var _blessed2 = _interopRequireDefault(_blessed);
22
23var _ReactBlessedIDOperations = require('./ReactBlessedIDOperations');
24
25/**
26 * Renders the given text element with blessed.
27 *
28 * @constructor ReactBlessedTextComponent
29 */
30
31var _ReactBlessedIDOperations2 = _interopRequireDefault(_ReactBlessedIDOperations);
32
33var ReactBlessedTextComponent = (function () {
34 function ReactBlessedTextComponent(props) {
35 _classCallCheck(this, ReactBlessedTextComponent);
36 }
37
38 /**
39 * @param {ReactText} text
40 * @internal
41 */
42
43 _createClass(ReactBlessedTextComponent, [{
44 key: 'construct',
45 value: function construct(text) {
46 this._currentElement = text;
47 this._rootNodeID = null;
48 this._stringText = '' + text;
49 }
50
51 /**
52 * Setting the content etc. of the parent node.
53 *
54 * @param {string} rootID - DOM ID of the root node.
55 * @param {ReactBlessedReconcileTransaction} transaction
56 * @param {object} context
57 * @internal
58 */
59 }, {
60 key: 'mountComponent',
61 value: function mountComponent(rootID, transaction, context) {
62 this._rootNodeID = rootID;
63
64 var parent = _ReactBlessedIDOperations2['default'].getParent(rootID);
65
66 // Setting content of parent
67 parent.setContent(this._stringText);
68 }
69
70 /**
71 * Updates this component by updating the text content.
72 *
73 * @param {ReactText} nextText - The next text content.
74 * @param {ReactBlessedReconcileTransaction} transaction
75 * @internal
76 */
77 }, {
78 key: 'receiveComponent',
79 value: function receiveComponent(nextText, transaction) {
80 this._currentElement = nextText;
81 var nextStringText = '' + nextText;
82
83 if (nextStringText !== this._stringText) {
84
85 this._stringText = nextStringText;
86
87 var _parent = _ReactBlessedIDOperations2['default'].getParent(this._rootNodeID);
88
89 // Setting content of parent
90 _parent.setContent(this._stringText);
91 }
92 }
93
94 /**
95 * Dropping the text component.
96 */
97 }, {
98 key: 'unmountComponent',
99 value: function unmountComponent() {
100 var parent = _ReactBlessedIDOperations2['default'].getParent(this._rootNodeID);
101
102 // Setting content of parent
103 parent.setContent('');
104 }
105 }]);
106
107 return ReactBlessedTextComponent;
108})();
109
110exports['default'] = ReactBlessedTextComponent;
111module.exports = exports['default'];
\No newline at end of file