diff --git a/front-end/ui.esm.js b/front-end/ui.esm.js index 54def492..6854f498 100644 --- a/front-end/ui.esm.js +++ b/front-end/ui.esm.js @@ -19,7 +19,7 @@ var require_ui = __commonJS({ */ constructor(win, extLog, jsonHighlight) { //#region --- Class variables --- - __publicField(this, "version", "7.0.3-src"); + __publicField(this, "version", "7.0.4-src"); // List of tags and attributes not in sanitise defaults but allowed in uibuilder. __publicField(this, "sanitiseExtraTags", ["uib-var"]); __publicField(this, "sanitiseExtraAttribs", ["variable", "report", "undefined"]); diff --git a/front-end/ui.esm.min.js b/front-end/ui.esm.min.js index 74f25ab8..9f03f558 100644 --- a/front-end/ui.esm.min.js +++ b/front-end/ui.esm.min.js @@ -1,2 +1,2 @@ -var b=Object.create;var h=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var v=Object.getOwnPropertyNames;var k=Object.getPrototypeOf,S=Object.prototype.hasOwnProperty;var $=(c,t,e)=>t in c?h(c,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):c[t]=e;var g=(c=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(c,{get:(t,e)=>(typeof require<"u"?require:t)[e]}):c)(function(c){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+c+'" is not supported')});var C=(c,t)=>()=>(t||c((t={exports:{}}).exports,t),t.exports);var x=(c,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of v(t))!S.call(c,n)&&n!==e&&h(c,n,{get:()=>t[n],enumerable:!(i=E(t,n))||i.enumerable});return c};var m=(c,t,e)=>(e=c!=null?b(k(c)):{},x(t||!c||!c.__esModule?h(e,"default",{value:c,enumerable:!0}):e,c));var u=(c,t,e)=>$(c,typeof t!="symbol"?t+"":t,e);var M=C((L,p)=>{var r,A=(r=class{constructor(t,e,i){u(this,"version","7.0.3-esm.min");u(this,"sanitiseExtraTags",["uib-var"]);u(this,"sanitiseExtraAttribs",["variable","report","undefined"]);u(this,"ui_md_plugins");if(t)r.win=t;else throw new Error("Ui:constructor. Current environment does not include `window`, UI functions cannot be used.");r.doc=r.win.document,e?r.log=e:r.log=function(){return function(){}},i?this.syntaxHighlight=i:this.syntaxHighlight=function(){},r.win.markdownit&&(r.mdOpts={html:!0,xhtmlOut:!1,linkify:!0,_highlight:!0,_strict:!1,_view:"html",langPrefix:"language-",highlight:function(n,a){if(a&&window.hljs&&window.hljs.getLanguage(a))try{return'
\n                                    '.concat(window.hljs.highlight(n,{language:a,ignoreIllegals:!0}).value,"
")}finally{}return'
'.concat(r.md.utils.escapeHtml(n).trim(),"
")}},r.md=r.win.markdownit(r.mdOpts))}_markDownIt(){if(r.win.markdownit&&(!this.ui_md_plugins&&r.win.uibuilder&&r.win.uibuilder.ui_md_plugins&&(this.ui_md_plugins=r.win.uibuilder.ui_md_plugins),r.mdOpts={html:!0,xhtmlOut:!1,linkify:!0,_highlight:!0,_strict:!1,_view:"html",langPrefix:"language-",highlight:function(t,e){if(window.hljs)if(e&&window.hljs.getLanguage(e))try{return'
").concat(window.hljs.highlight(t,{language:e,ignoreIllegals:!0}).value,"
")}finally{}else try{let i=window.hljs.highlightAuto(t);return'
").concat(i.value,"
")}finally{}return'
'.concat(r.md.utils.escapeHtml(t).trim(),"
")}},r.md=r.win.markdownit(r.mdOpts),this.ui_md_plugins)){if(!Array.isArray(this.ui_md_plugins)){r.log("error","Ui:_markDownIt:plugins","Could not load plugins, ui_md_plugins is not an array")();return}this.ui_md_plugins.forEach(t=>{if(typeof t=="string")r.md.use(r.win[t]);else{let e=Object.keys(t)[0];r.md.use(r.win[e],t[e])}})}}_showNotification(t){t.topic&&!t.title&&(t.title=t.topic),t.title||(t.title="uibuilder notification"),t.payload&&!t.body&&(t.body=t.payload),t.body||(t.body=" No message given.");try{let e=new Notification(t.title,t);return new Promise((i,n)=>{e.addEventListener("close",a=>{a.currentTarget.userAction="close",i(a)}),e.addEventListener("click",a=>{a.currentTarget.userAction="click",i(a)}),e.addEventListener("error",a=>{a.currentTarget.userAction="error",n(a)})})}catch{return Promise.reject(new Error("Browser refused to create a Notification"))}}_uiAdd(t,e){r.log("trace","Ui:_uiManager:add","Starting _uiAdd")(),t.components.forEach((i,n)=>{r.log("trace","Ui:_uiAdd:components-forEach:".concat(n),"Component to add: ",i)();let a;switch(i.type){case"html":{i.ns="html",a=r.doc.createElement("div");break}case"svg":{i.ns="svg",a=r.doc.createElementNS("http://www.w3.org/2000/svg","svg");break}default:{i.ns="dom",a=r.doc.createElement(i.type);break}}!i.slot&&t.payload&&(i.slot=t.payload),this._uiComposeComponent(a,i);let s;i.parentEl?s=i.parentEl:t.parentEl?s=t.parentEl:i.parent?s=r.doc.querySelector(i.parent):t.parent&&(s=r.doc.querySelector(t.parent)),s||(r.log("info","Ui:_uiAdd","No parent found, adding to body")(),s=r.doc.querySelector("body")),i.position&&i.position==="first"?s.insertBefore(a,s.firstChild):i.position&&Number.isInteger(Number(i.position))?s.insertBefore(a,s.children[i.position]):s.appendChild(a),i.components&&this._uiExtendEl(a,i.components,i.ns)})}_uiComposeComponent(t,e){e.attributes&&Object.keys(e.attributes).forEach(i=>{i==="class"&&Array.isArray(e.attributes[i])&&e.attributes[i].join(" "),r.log("trace","_uiComposeComponent:attributes-forEach","Attribute: '".concat(i,"', value: '").concat(e.attributes[i],"'"))(),i==="value"&&(t.value=e.attributes[i]),i.startsWith("xlink:")?t.setAttributeNS("http://www.w3.org/1999/xlink",i,e.attributes[i]):t.setAttribute(i,e.attributes[i])}),e.id&&t.setAttribute("id",e.id),e.type==="svg"&&(t.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns","http://www.w3.org/2000/svg"),t.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink")),e.events&&Object.keys(e.events).forEach(i=>{i.toLowerCase==="onclick"&&(i="click");try{t.addEventListener(i,n=>{new Function("evt","".concat(e.events[i],"(evt)"))(n)})}catch(n){r.log("error","Ui:_uiComposeComponent","Add event '".concat(i,"' for element '").concat(e.type,"': Cannot add event handler. ").concat(n.message))()}}),e.properties&&Object.keys(e.properties).forEach(i=>{t[i]=e.properties[i],["value","checked"].includes(i)&&(t.dispatchEvent(new Event("input")),t.dispatchEvent(new Event("change")))}),e.slot&&this.replaceSlot(t,e.slot),e.slotMarkdown&&this.replaceSlotMarkdown(t,e)}_uiExtendEl(t,e,i=""){e.forEach((n,a)=>{r.log("trace","Ui:_uiExtendEl:components-forEach:".concat(a),n)();let s;n.ns=i,n.ns==="html"?(s=t,this.replaceSlot(t,n.slot)):n.ns==="svg"?(s=r.doc.createElementNS("http://www.w3.org/2000/svg",n.type),this._uiComposeComponent(s,n),t.appendChild(s)):(s=r.doc.createElement(n.type==="html"?"div":n.type),this._uiComposeComponent(s,n),t.appendChild(s)),n.components&&this._uiExtendEl(s,n.components,n.ns)})}_uiLoad(t){t.components&&(Array.isArray(t.components)||(t.components=[t.components]),t.components.forEach(async e=>{Promise.resolve().then(()=>m(g(e)))})),t.srcScripts&&(Array.isArray(t.srcScripts)||(t.srcScripts=[t.srcScripts]),t.srcScripts.forEach(e=>{this.loadScriptSrc(e)})),t.txtScripts&&(Array.isArray(t.txtScripts)||(t.txtScripts=[t.txtScripts]),this.loadScriptTxt(t.txtScripts.join("\n"))),t.srcStyles&&(Array.isArray(t.srcStyles)||(t.srcStyles=[t.srcStyles]),t.srcStyles.forEach(e=>{this.loadStyleSrc(e)})),t.txtStyles&&(Array.isArray(t.txtStyles)||(t.txtStyles=[t.txtStyles]),this.loadStyleTxt(t.txtStyles.join("\n")))}_uiManager(t){t._ui&&(Array.isArray(t._ui)||(t._ui=[t._ui]),t._ui.forEach((e,i)=>{if(e.mode&&!e.method&&(e.method=e.mode),!e.method){r.log("error","Ui:_uiManager","No method defined for msg._ui[".concat(i,"]. Ignoring. "),e)();return}switch(e.payload=t.payload,e.topic=t.topic,e.method){case"add":{this._uiAdd(e,!1);break}case"remove":{this._uiRemove(e,!1);break}case"removeAll":{this._uiRemove(e,!0);break}case"replace":{this._uiReplace(e);break}case"update":{this._uiUpdate(e);break}case"load":{this._uiLoad(e);break}case"reload":{this._uiReload();break}case"notify":{this.showDialog("notify",e,t);break}case"alert":{this.showDialog("alert",e,t);break}default:{r.log("error","Ui:_uiManager","Invalid msg._ui[".concat(i,"].method (").concat(e.method,"). Ignoring"))();break}}}))}_uiReload(){r.log("trace","Ui:uiManager:reload","reloading")(),location.reload()}_uiRemove(t,e=!1){t.components.forEach(i=>{let n;e!==!0?n=[r.doc.querySelector(i)]:n=r.doc.querySelectorAll(i),n.forEach(a=>{try{a.remove()}catch(s){r.log("trace","Ui:_uiRemove","Could not remove. ".concat(s.message))()}})})}_uiReplace(t){r.log("trace","Ui:_uiReplace","Starting")(),t.components.forEach((e,i)=>{r.log("trace","Ui:_uiReplace:components-forEach:".concat(i),"Component to replace: ",e)();let n;if(e.id?n=r.doc.getElementById(e.id):e.selector||e.select?n=r.doc.querySelector(e.selector):e.name?n=r.doc.querySelector('[name="'.concat(e.name,'"]')):e.type&&(n=r.doc.querySelector(e.type)),r.log("trace","Ui:_uiReplace:components-forEach:".concat(i),"Element to replace: ",n)(),n==null){r.log("trace","Ui:_uiReplace:components-forEach:".concat(i,":noReplace"),"Cannot find the DOM element. Adding instead.",e)(),this._uiAdd({components:[e]},!1);return}let a;switch(e.type){case"html":{e.ns="html",a=r.doc.createElement("div");break}case"svg":{e.ns="svg",a=r.doc.createElementNS("http://www.w3.org/2000/svg","svg");break}default:{e.ns="dom",a=r.doc.createElement(e.type);break}}this._uiComposeComponent(a,e),n.replaceWith(a),e.components&&this._uiExtendEl(a,e.components,e.ns)})}_uiUpdate(t){r.log("trace","UI:_uiUpdate:update","Starting _uiUpdate",t)(),t.components||(t.components=[Object.assign({},t)]),t.components.forEach((e,i)=>{r.log("trace","_uiUpdate:components-forEach","Start loop #".concat(i),e)();let n;if(e.parentEl?n=e.parentEl:e.id?n=r.doc.querySelectorAll("#".concat(e.id)):e.selector||e.select?n=r.doc.querySelectorAll(e.selector):e.name?n=r.doc.querySelectorAll('[name="'.concat(e.name,'"]')):e.type&&(n=r.doc.querySelectorAll(e.type)),n===void 0||n.length<1){r.log("warn","Ui:_uiManager:update","Cannot find the DOM element. Ignoring.",e)();return}r.log("trace","_uiUpdate:components-forEach","Element(s) to update. Count: ".concat(n.length),n)(),!e.slot&&e.payload&&(e.slot=e.payload),n.forEach((a,s)=>{if(r.log("trace","_uiUpdate:components-forEach","Updating element #".concat(s),a)(),this._uiComposeComponent(a,e),e.components){r.log("trace","_uiUpdate:nested-component","Element #".concat(s," - nested-component"),e,a)();let o={_ui:[]};e.components.forEach((l,d)=>{let f=l.method||e.method||t.method;l.method&&delete l.method,Array.isArray(l)||(l=[l]),r.log("trace","_uiUpdate:nested-component","Element #".concat(s," - nested-component #").concat(d),l)(),o._ui.push({method:f,parentEl:a,components:l})}),r.log("trace","_uiUpdate:nested-component","Element #".concat(s," - nested-component new manager"),o)(),this._uiManager(o)}})})}$(t,e){let i=r.doc.querySelector(t);if(!i)return r.log(1,"Uib:$","No element found for CSS selector ".concat(t))(),null;if(i.nodeName==="TEMPLATE"&&(i=i.content.firstElementChild,!i))return r.log(0,"Uib:$","Template selected for CSS selector ".concat(t," but it is empty"))(),null;e||(e="el");let n;try{switch(e.toLowerCase()){case"text":{n=i.innerText;break}case"html":{n=i.innerHTML;break}case"attr":case"attributes":{n={};for(let a of i.attributes)n[a.name]=a.value;break}default:{n=i;break}}}catch(a){n=i,r.log(1,"Uib:$",'Could not process output type "'.concat(e,'" for CSS selector ').concat(t,", returned the DOM element. ").concat(a.message),a)()}return n}$$(t){return Array.from(r.doc.querySelectorAll(t))}addClass(t,e){Array.isArray(t)||(t=[t]),e&&e.classList.add(...t)}applyTemplate(t,e,i){i||(i={onceOnly:!1});let n=r.doc.getElementById(t),a=r.doc.getElementById(e);if(n&&a){let s;try{i.onceOnly!==!0?s=r.doc.importNode(n.content,!0):s=r.doc.adoptNode(n.content)}catch{r.log("error","Ui:applyTemplate","Source must be a