2
0
mirror of https://github.com/esiur/iui.git synced 2026-04-04 06:58:22 +00:00
This commit is contained in:
2021-10-29 17:09:15 +03:00
parent 1e8ae99d39
commit b3479dbdbd
35 changed files with 857 additions and 166 deletions

68
src/UI/CodePreview.js Normal file
View File

@@ -0,0 +1,68 @@
import IUIElement from "../Core/IUIElement.js";
import { IUI } from "../Core/IUI.js";
export default IUI.module(class CodePreview extends IUIElement {
constructor(properties) {
super();
}
async create() {
if (this.hasAttribute("debug"))
debugger;
this._code = this.innerHTML;
this.textContent = '';
// create elements
this.bar = document.createElement("div");
this.bar.className = this.cssClass + "-bar";
this.content = document.createElement("div");
this.content.className = this.cssClass + "-content";
this.editor = document.createElement("code");
this.editor.className = this.cssClass + "-editor";
this.editor.innerText = this._code;
this.editor.contentEditable = true;
this.editor.setAttribute("skip", true);
let self = this;
this.editor.addEventListener("input", function() {
self._code = self.editor.innerText;
self.update();
}, false);
this.preview = document.createElement("div");
this.preview.className = this.cssClass + "-preview";
//this.preview.setAttribute(":content", "");
this.content.append(this.editor);
this.content.append(this.preview);
this.append(this.bar);
this.append(this.content);
this.field = this.getAttribute("field");
await this.update();
}
async update() {
if (this._updating)
return;
this._updating = true;
this.preview.innerHTML = this._code;
await IUI.create(this.preview);
await IUI.created(this.preview);
IUI.bind(this.preview, this.preview, "preview");
await IUI.render(this.preview, this._data, true);
this._updating = false;
}
});