UNPKG

@tdb/util

Version:
105 lines 4.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var common_1 = require("../common"); var Editor_1 = require("./Editor"); var constants_1 = require("./constants"); var libs_1 = require("./libs"); var ObjectView = (function (_super) { tslib_1.__extends(ObjectView, _super); function ObjectView() { var _this = _super !== null && _super.apply(this, arguments) || this; _this.state = {}; _this.isUnmounted = false; _this.renderNode = function (props) { var depth = props.depth, name = props.name, data = props.data, isNonenumerable = props.isNonenumerable; if (depth === 0) { return _this.renderRootNode(props); } else { return (common_1.React.createElement(libs_1.ObjectLabel, { name: name, data: data, isNonenumerable: isNonenumerable })); } }; _this.renderRootNode = function (props) { var data = props.data, name = props.name; var rootData = Array.isArray(data) ? data : {}; return common_1.React.createElement(libs_1.ObjectRootLabel, { name: name, data: rootData }); }; _this.renderEditorNode = function (props) { var name = props.name, isNonenumerable = props.isNonenumerable; return (common_1.React.createElement("span", null, common_1.React.createElement(libs_1.ObjectName, { name: name, dimmed: isNonenumerable }), common_1.React.createElement("span", null, ": "), common_1.React.createElement(Editor_1.Editor, { fontSize: _this.props.fontSize }))); }; return _this; } ObjectView.prototype.componentWillMount = function () { this.loadData(); }; ObjectView.prototype.componentDidUpdate = function (prevProps, prevState) { if (this.props.data !== prevProps.data && !this.isUnmounted) { this.loadData(); } }; ObjectView.prototype.componentWillUnmount = function () { this.isUnmounted = true; }; ObjectView.prototype.render = function () { var data = this.state.data; var _a = this.props, name = _a.name, _b = _a.expandLevel, expandLevel = _b === void 0 ? 1 : _b, _c = _a.showNonenumerable, showNonenumerable = _c === void 0 ? false : _c, expandPaths = _a.expandPaths, style = _a.style; if (this.state.isLoading) { data = 'Loading...'; } return (common_1.React.createElement("div", tslib_1.__assign({}, common_1.css(style)), common_1.React.createElement(libs_1.ReactInspector, { data: data, name: name, expandLevel: expandLevel, showNonenumerable: showNonenumerable, expandPaths: expandPaths, theme: this.theme, nodeRenderer: this.renderNode }))); }; Object.defineProperty(ObjectView.prototype, "theme", { get: function () { var _a = this.props.fontSize, fontSize = _a === void 0 ? constants_1.DEFAULTS.FONT_SIZE : _a; var fontSizeCss = fontSize + "px"; var lineHeightCss = '1.5em'; return tslib_1.__assign({}, this.baseTheme, { BASE_BACKGROUND_COLOR: 'transparent', BASE_FONT_SIZE: fontSizeCss, TREENODE_FONT_SIZE: fontSizeCss, BASE_LINE_HEIGHT: lineHeightCss, TREENODE_LINE_HEIGHT: lineHeightCss }); }, enumerable: true, configurable: true }); Object.defineProperty(ObjectView.prototype, "baseTheme", { get: function () { var _a = this.props.theme, theme = _a === void 0 ? 'LIGHT' : _a; switch (theme) { case 'LIGHT': return libs_1.THEME.CHROME_LIGHT; case 'DARK': return libs_1.THEME.CHROME_DARK; default: throw new Error("Theme '" + theme + "' not supported."); } }, enumerable: true, configurable: true }); ObjectView.prototype.loadData = function () { return tslib_1.__awaiter(this, void 0, void 0, function () { var data; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: data = this.props.data; if (!common_1.value.isPromise(data)) return [3, 2]; this.setState({ isLoading: true }); return [4, data]; case 1: data = _a.sent(); _a.label = 2; case 2: this.setState({ data: data, isLoading: false }); return [2]; } }); }); }; return ObjectView; }(common_1.React.PureComponent)); exports.ObjectView = ObjectView; //# sourceMappingURL=ObjectView.js.map