@senx/discovery-code
Version:
Discovery Code Editor
76 lines (72 loc) • 6.87 kB
JavaScript
import { proxyCustomElement, HTMLElement, h } from '@stencil/core/internal/client';
import { C as Config, U as Utils } from './config.js';
import { L as Logger } from './logger.js';
import { J as JsonLib } from './jsonLib.js';
const discoveryCodeResultCss = "/*!\n * Copyright 2020-2023 SenX S.A.S.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */:host,discovery-code-result{position:relative;overflow-y:auto;}:host .wrapper-result,discovery-code-result .wrapper-result{width:100%}:host .loader .spinner,discovery-code-result .loader .spinner{border:5px solid #f3f3f3;-webkit-animation:spin 1s linear infinite;animation:spin 1s linear infinite;border-top:5px solid #555;border-radius:50%;width:50px;height:50px;position:fixed;overflow:visible;z-index:999;margin:auto;top:0;left:0;bottom:0;right:0}:host .loader:after,discovery-code-result .loader:after{content:\"\";display:block;position:absolute;top:0;left:0;width:100%;height:100%;background-color:rgba(0, 0, 0, 0.3)}:host .wrapper.dark,discovery-code-result .wrapper.dark{background-color:#1e1e1e !important;color:#fff;--warp-view-spinner-color:#f3f3f3}:host .wrapper.light,discovery-code-result .wrapper.light{background-color:#fff !important;color:#000}:host .wrapper .loader,discovery-code-result .wrapper .loader{background-color:rgba(0, 0, 0, 0.3);position:absolute;top:0;z-index:1;left:0;right:0;bottom:0}:host .wrapper .loader .spinner,discovery-code-result .wrapper .loader .spinner{-webkit-animation:spin 1s linear infinite;animation:spin 1s linear infinite;border-color:var(--warp-view-spinner-color, #5899DA) transparent transparent transparent;border-style:solid;border-radius:50%;width:50px;height:50px;position:absolute;overflow:visible;z-index:999;margin:auto;top:calc(50% - 25px);left:calc(50% - 25px)}:host .raw,discovery-code-result .raw{font-family:\"Droid Sans Mono\", \"Courier New\", monospace, \"Droid Sans Fallback\";font-weight:normal;font-size:14px;line-height:19px;letter-spacing:0;display:-ms-flexbox;display:flex;-ms-flex-flow:column;flex-flow:column}:host .raw.light,discovery-code-result .raw.light{background-color:#fff !important;color:#343a40}:host .raw.light pre,discovery-code-result .raw.light pre{color:#343a40;font-family:\"Droid Sans Mono\", \"Courier New\", monospace, \"Droid Sans Fallback\";font-weight:normal;font-size:14px;line-height:19px;min-height:19px;height:auto;white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word}:host .raw.light .line-num,discovery-code-result .raw.light .line-num{color:#2b91af}:host .raw.dark,discovery-code-result .raw.dark{background-color:#1e1e1e !important;color:#fff}:host .raw.dark pre,discovery-code-result .raw.dark pre{color:#fff;font-size:14px;line-height:19px;min-height:19px;height:auto;white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word}:host .raw.dark .line-num,discovery-code-result .raw.dark .line-num{color:#5a5a5a}:host .raw .line,discovery-code-result .raw .line{display:block;max-width:calc(100% - 4em)}:host .raw .line-num,discovery-code-result .raw .line-num{width:4em;float:left;text-align:right;padding:0.3em 0.5em 0.3em 0.3em;margin:0}:host .raw .line-content,discovery-code-result .raw .line-content{display:block;border-left:#5a5a5a solid 1px;padding:0.3em 0.3em 0.3em 1em;max-width:calc(100% - 4em);margin:0 0 0 5em}@-webkit-keyframes spin{0%{-webkit-transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg)}}@keyframes spin{0%{-webkit-transform:rotate(0deg);transform:rotate(0deg)}100%{-webkit-transform:rotate(360deg);transform:rotate(360deg)}}";
const DiscoveryCodeResultStyle0 = discoveryCodeResultCss;
const DiscoveryCodeResult = /*@__PURE__*/ proxyCustomElement(class DiscoveryCodeResult extends HTMLElement {
constructor() {
super();
this.__registerHost();
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 watchers() { return {
"debug": ["setDebug"],
"result": ["setResult"]
}; }
static get style() { return DiscoveryCodeResultStyle0; }
}, [0, "discovery-code-result", {
"theme": [1],
"config": [1],
"debug": [4],
"result": [1]
}, undefined, {
"debug": ["setDebug"],
"result": ["setResult"]
}]);
function defineCustomElement() {
if (typeof customElements === "undefined") {
return;
}
const components = ["discovery-code-result"];
components.forEach(tagName => { switch (tagName) {
case "discovery-code-result":
if (!customElements.get(tagName)) {
customElements.define(tagName, DiscoveryCodeResult);
}
break;
} });
}
export { DiscoveryCodeResult as D, defineCustomElement as d };