diff --git a/css/iui.css b/css/iui.css index cc9fc2e..0b99752 100644 --- a/css/iui.css +++ b/css/iui.css @@ -3098,4 +3098,20 @@ html[dir='rtl'] .navbar-item[level='1'] { .codepreview-bar { +} + +.iui-error { + background: #7171714d; + position: absolute; + top: 0; + left: 0; + height: 100%; + width: 100%; + pointer-events: none; +} + +.iui-error > span { + background: red; + color: white; + padding: 4px; } \ No newline at end of file diff --git a/src/Core/Binding.js b/src/Core/Binding.js index fa7fb21..36ab8f0 100644 --- a/src/Core/Binding.js +++ b/src/Core/Binding.js @@ -179,6 +179,10 @@ export class Binding { if (context.error != undefined) { + if (thisArg instanceof IUIElement){ + thisArg.setError(context.error); + } + console.log("Execution failed", context.error.name + ": " + context.error.message, this.script, this.target); return; } @@ -192,6 +196,11 @@ export class Binding { { return await context.value; } catch(ex) { + + if (thisArg instanceof IUIElement){ + thisArg.setError(ex); + } + console.log("Execution failed", ex.name + ": " + ex.message, this.script, this.target); } } diff --git a/src/Core/IUI.js b/src/Core/IUI.js index 4fa9571..26bb39b 100644 --- a/src/Core/IUI.js +++ b/src/Core/IUI.js @@ -6,6 +6,8 @@ import BindingList from "./BindingList.js"; export class IUI { + static debugMode = true; + static _menus = []; static views = []; static modules = {}; diff --git a/src/Core/IUIElement.js b/src/Core/IUIElement.js index c0f1d3a..ea7c002 100644 --- a/src/Core/IUIElement.js +++ b/src/Core/IUIElement.js @@ -63,6 +63,22 @@ export default class IUIElement extends HTMLElement { await this.updated(); } + + setError(exception) { + if (!IUI.debugMode) + return; + + if (this._errorElement == null) { + this._errorElement = document.createElement("div"); + this._errorElement.className = "iui-error"; + this.append(this._errorElement); + } + + var label = document.createElement("span"); + label.innerHTML = exception; + this._errorElement.append(label); + } + async updated() { // to be implemented by the user.