UNPKG

12.5 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports["default"] = void 0;
7
8var _react = _interopRequireWildcard(require("react"));
9
10var _propTypes = _interopRequireDefault(require("prop-types"));
11
12var _reactJsonTree = _interopRequireDefault(require("react-json-tree"));
13
14var _LogMonitorEntryAction = _interopRequireDefault(require("./LogMonitorEntryAction"));
15
16var _function = _interopRequireDefault(require("react-pure-render/function"));
17
18function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
19
20function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
21
22function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
23
24function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
25
26function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
27
28function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
29
30function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
31
32function _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); } }
33
34function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
35
36function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
37
38function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
39
40function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
41
42function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
43
44function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
45
46function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
47
48function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
49
50function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
51
52function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
53
54function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
55
56function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
57
58function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
59
60function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
61
62function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
63
64var styles = {
65 entry: {
66 display: 'block',
67 WebkitUserSelect: 'none'
68 },
69 root: {
70 marginLeft: 0
71 }
72};
73
74var getDeepItem = function getDeepItem(data, path) {
75 return path.reduce(function (obj, key) {
76 return obj && obj[key];
77 }, data);
78};
79
80var dataIsEqual = function dataIsEqual(data, previousData, keyPath) {
81 var path = _toConsumableArray(keyPath).reverse().slice(1);
82
83 return getDeepItem(data, path) === getDeepItem(previousData, path);
84};
85
86var LogMonitorEntry = /*#__PURE__*/function (_Component) {
87 _inherits(LogMonitorEntry, _Component);
88
89 var _super = _createSuper(LogMonitorEntry);
90
91 function LogMonitorEntry(props) {
92 var _this;
93
94 _classCallCheck(this, LogMonitorEntry);
95
96 _this = _super.call(this, props);
97
98 _defineProperty(_assertThisInitialized(_this), "shouldComponentUpdate", _function["default"]);
99
100 _this.handleActionClick = _this.handleActionClick.bind(_assertThisInitialized(_this));
101 _this.shouldExpandNode = _this.shouldExpandNode.bind(_assertThisInitialized(_this));
102 return _this;
103 }
104
105 _createClass(LogMonitorEntry, [{
106 key: "printState",
107 value: function printState(state, error) {
108 var _this2 = this;
109
110 var errorText = error;
111
112 if (!errorText) {
113 try {
114 var data = this.props.select(state);
115 var theme;
116
117 if (this.props.markStateDiff) {
118 var previousData = typeof this.props.previousState !== 'undefined' ? this.props.select(this.props.previousState) : undefined;
119
120 var getValueStyle = function getValueStyle(_ref, nodeType, keyPath) {
121 var style = _ref.style;
122 return {
123 style: _objectSpread(_objectSpread({}, style), {}, {
124 backgroundColor: dataIsEqual(data, previousData, keyPath) ? 'transparent' : _this2.props.theme.base01
125 })
126 };
127 };
128
129 var getNestedNodeStyle = function getNestedNodeStyle(_ref2, keyPath) {
130 var style = _ref2.style;
131 return {
132 style: _objectSpread(_objectSpread({}, style), keyPath.length > 1 ? {} : styles.root)
133 };
134 };
135
136 theme = {
137 extend: this.props.theme,
138 tree: styles.tree,
139 value: getValueStyle,
140 nestedNode: getNestedNodeStyle
141 };
142 } else {
143 theme = this.props.theme;
144 }
145
146 return /*#__PURE__*/_react["default"].createElement(_reactJsonTree["default"], {
147 theme: theme,
148 data: data,
149 invertTheme: false,
150 keyPath: ['state'],
151 shouldExpandNode: this.shouldExpandNode
152 });
153 } catch (err) {
154 errorText = 'Error selecting state.';
155 }
156 }
157
158 return /*#__PURE__*/_react["default"].createElement("div", {
159 style: {
160 color: this.props.theme.base08,
161 paddingTop: 20,
162 paddingLeft: 30,
163 paddingRight: 30,
164 paddingBottom: 35
165 }
166 }, errorText);
167 }
168 }, {
169 key: "handleActionClick",
170 value: function handleActionClick(e) {
171 var _this$props = this.props,
172 actionId = _this$props.actionId,
173 onActionClick = _this$props.onActionClick,
174 onActionShiftClick = _this$props.onActionShiftClick;
175
176 if (actionId > 0) {
177 if (e.shiftKey) {
178 onActionShiftClick(actionId);
179 } else {
180 onActionClick(actionId);
181 }
182 }
183 }
184 }, {
185 key: "shouldExpandNode",
186 value: function shouldExpandNode(keyName, data, level) {
187 return this.props.expandStateRoot && level === 0;
188 }
189 }, {
190 key: "render",
191 value: function render() {
192 var _this$props2 = this.props,
193 actionId = _this$props2.actionId,
194 error = _this$props2.error,
195 action = _this$props2.action,
196 state = _this$props2.state,
197 collapsed = _this$props2.collapsed,
198 selected = _this$props2.selected,
199 inFuture = _this$props2.inFuture;
200 var styleEntry = {
201 opacity: collapsed ? 0.5 : 1,
202 cursor: actionId > 0 ? 'pointer' : 'default'
203 };
204 return /*#__PURE__*/_react["default"].createElement("div", {
205 style: {
206 opacity: selected ? 0.4 : inFuture ? 0.6 : 1,
207 // eslint-disable-line no-nested-ternary
208 textDecoration: collapsed ? 'line-through' : 'none',
209 color: this.props.theme.base06
210 }
211 }, /*#__PURE__*/_react["default"].createElement(_LogMonitorEntryAction["default"], {
212 theme: this.props.theme,
213 collapsed: collapsed,
214 action: action,
215 expandActionRoot: this.props.expandActionRoot,
216 onClick: this.handleActionClick,
217 style: _objectSpread(_objectSpread({}, styles.entry), styleEntry)
218 }), !collapsed && /*#__PURE__*/_react["default"].createElement("div", {
219 style: {
220 paddingLeft: 16
221 }
222 }, this.printState(state, error)));
223 }
224 }]);
225
226 return LogMonitorEntry;
227}(_react.Component);
228
229exports["default"] = LogMonitorEntry;
230
231_defineProperty(LogMonitorEntry, "propTypes", {
232 state: _propTypes["default"].object.isRequired,
233 action: _propTypes["default"].object.isRequired,
234 actionId: _propTypes["default"].number.isRequired,
235 select: _propTypes["default"].func.isRequired,
236 inFuture: _propTypes["default"].bool,
237 error: _propTypes["default"].string,
238 onActionClick: _propTypes["default"].func.isRequired,
239 onActionShiftClick: _propTypes["default"].func.isRequired,
240 collapsed: _propTypes["default"].bool,
241 selected: _propTypes["default"].bool,
242 expandActionRoot: _propTypes["default"].bool,
243 expandStateRoot: _propTypes["default"].bool
244});
\No newline at end of file