@senx/discovery-code
Version:
Discovery Code Editor
158 lines (157 loc) • 5.59 kB
JavaScript
/*
* Copyright 2022-2024 SenX S.A.S.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { h } from "@stencil/core";
import { Config } from "../../model/config";
import { Logger } from "../../model/logger";
import { JsonLib } from "../../model/jsonLib";
import { Utils } from "../../model/utils";
export class DiscoveryCodeResult {
constructor() {
this.theme = undefined;
this.config = new Config();
this.debug = false;
this.result = undefined;
this.LOG = new Logger(DiscoveryCodeResult, this.debug);
}
setDebug(newValue) {
this.LOG.setDebug(newValue);
}
setResult(res) {
var _a;
this.innerResult = new JsonLib().parse(res || '[]', undefined);
this.LOG.debug(['setResult'], { innerResult: this.innerResult, res });
this.innerResultStr = ((_a = this.innerResult) !== null && _a !== void 0 ? _a : []).map(l => {
const jsonStr = JSON.stringify(l);
return jsonStr.startsWith('[') || jsonStr.startsWith('{') ? jsonStr : l;
});
}
componentWillLoad() {
var _a;
this.innerResult = new JsonLib().parse(this.result || '[]', undefined);
this.innerResultStr = ((_a = this.innerResult) !== null && _a !== void 0 ? _a : []).map(l => {
const jsonStr = JSON.stringify(l);
return jsonStr.startsWith('[') || jsonStr.startsWith('{') ? jsonStr : l;
});
}
isArray(arr) {
return Utils.isArray(arr);
}
render() {
return h("div", { key: '0db0bd5e6195db8bca41f8f7628fcf8c989367bf', class: 'wrapper-result ' + this.theme }, this.innerResult && Utils.isArray(this.innerResult) ?
h("div", { class: this.theme + ' raw' }, this.innerResultStr.map((line, index) => h("span", { class: "line" }, h("pre", { class: "line-num" }, index === 0 ? '[TOP]' : index + 1), h("pre", { class: "line-content", innerHTML: line }))))
: '');
}
static get is() { return "discovery-code-result"; }
static get originalStyleUrls() {
return {
"$": ["discovery-code-result.scss"]
};
}
static get styleUrls() {
return {
"$": ["discovery-code-result.css"]
};
}
static get properties() {
return {
"theme": {
"type": "string",
"mutable": false,
"complexType": {
"original": "'light' | 'dark'",
"resolved": "\"dark\" | \"light\"",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "theme",
"reflect": false
},
"config": {
"type": "string",
"mutable": false,
"complexType": {
"original": "Config | string",
"resolved": "Config | string",
"references": {
"Config": {
"location": "import",
"path": "../../model/config",
"id": "src/model/config.ts::Config"
}
}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "config",
"reflect": false,
"defaultValue": "new Config()"
},
"debug": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "debug",
"reflect": false,
"defaultValue": "false"
},
"result": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"attribute": "result",
"reflect": false
}
};
}
static get watchers() {
return [{
"propName": "debug",
"methodName": "setDebug"
}, {
"propName": "result",
"methodName": "setResult"
}];
}
}