diff --git a/front-end/uibuilder.esm.js b/front-end/uibuilder.esm.js index 9b8f138c..f8330c13 100644 --- a/front-end/uibuilder.esm.js +++ b/front-end/uibuilder.esm.js @@ -5895,7 +5895,7 @@ var Uib = (_a = class { type: "eventSend", id: target.id !== "" ? target.id : void 0, name: target.name !== "" ? target.name : void 0, - slotText: target.textContent && target.textContent !== "" ? target.textContent.substring(0, 255) : void 0, + slotText: target.textContent ? target.textContent.substring(0, 255) : void 0, form, props, attribs, diff --git a/front-end/uibuilder.esm.min.js b/front-end/uibuilder.esm.min.js index 7931d73b..2c7db444 100644 --- a/front-end/uibuilder.esm.min.js +++ b/front-end/uibuilder.esm.min.js @@ -1,2 +1,2 @@ -var _t=Object.create;var le=Object.defineProperty;var Et=Object.getOwnPropertyDescriptor;var Ct=Object.getOwnPropertyNames;var St=Object.getPrototypeOf,Nt=Object.prototype.hasOwnProperty;var xt=(s,e,t)=>e in s?le(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var Be=(s=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(s,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):s)(function(s){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+s+'" is not supported')});var Ot=(s,e)=>()=>(e||s((e={exports:{}}).exports,e),e.exports),Rt=(s,e)=>{for(var t in e)le(s,t,{get:e[t],enumerable:!0})},At=(s,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Ct(e))!Nt.call(s,n)&&n!==t&&le(s,n,{get:()=>e[n],enumerable:!(i=Et(e,n))||i.enumerable});return s};var _e=(s,e,t)=>(t=s!=null?_t(St(s)):{},At(e||!s||!s.__esModule?le(t,"default",{value:s,enumerable:!0}):t,s));var h=(s,e,t)=>(xt(s,typeof e!="symbol"?e+"":e,t),t),De=(s,e,t)=>{if(!e.has(s))throw TypeError("Cannot "+t)};var u=(s,e,t)=>(De(s,e,"read from private field"),t?t.call(s):e.get(s)),C=(s,e,t)=>{if(e.has(s))throw TypeError("Cannot add the same private member more than once");e instanceof WeakSet?e.add(s):e.set(s,t)},A=(s,e,t,i)=>(De(s,e,"write to private field"),i?i.call(s,t):e.set(s,t),t);var qe=Ot((ii,Pe)=>{var d,Tt=(d=class{constructor(e,t,i){h(this,"version","6.6.0-src");h(this,"sanitiseExtraTags",["uib-var"]);h(this,"sanitiseExtraAttribs",["variable","report","undefined"]);h(this,"window");if(e)this.window=e;else throw new Error("Ui:constructor. Current environment does not include `window`, UI functions cannot be used.");this.document=this.window.document,t?d.log=t:d.log=function(){return function(){}},i?this.syntaxHighlight=i:this.syntaxHighlight=function(){}}ui(e){let t={};e._ui?t=e:t._ui=e,this._uiManager(t)}replaceSlot(e,t){t.slot&&e&&(this.window.DOMPurify&&(t.slot=this.window.DOMPurify.sanitize(t.slot)),e.innerHTML=t.slot)}convertMarkdown(e){if(!e)return"";if(!this.window.markdownit)return e;let t={html:!0,linkify:!0,_highlight:!0,langPrefix:"language-",highlight(n,r){if(r&&this.window.hljs&&this.window.hljs.getLanguage(r))try{return'
\n                                ').concat(this.window.hljs.highlightAuto(n).value,"
")}finally{}return'
'.concat(i.utils.escapeHtml(n),"
")}},i=this.window.markdownit(t);return i.render(e)}sanitiseHTML(e){return this.window.DOMPurify?this.window.DOMPurify.sanitize(e,{ADD_TAGS:this.sanitiseExtraTags,ADD_ATTR:this.sanitiseExtraAttribs}):e}replaceSlotMarkdown(e,t){e&&t.slotMarkdown&&(t.slotMarkdown=this.convertMarkdown(t.slotMarkdown),t.slotMarkdown=this.sanitiseHTML(t.slotMarkdown),e.innerHTML=t.slotMarkdown)}loadScriptSrc(e){let t=this.document.createElement("script");t.src=e,t.async=!1,this.document.head.appendChild(t)}loadStyleSrc(e){let t=this.document.createElement("link");t.href=e,t.rel="stylesheet",t.type="text/css",this.document.head.appendChild(t)}loadScriptTxt(e){let t=this.document.createElement("script");t.async=!1,t.textContent=e,this.document.head.appendChild(t)}loadStyleTxt(e){let t=this.document.createElement("style");t.textContent=e,this.document.head.appendChild(t)}showDialog(e,t,i){let n="";if(i.payload&&typeof i.payload=="string"&&(n+=i.payload),t.content&&(n+=t.content),n===""){d.log(1,"Ui:showDialog","Toast content is blank. Not shown.")();return}!t.title&&i.topic&&(t.title=i.topic),t.title&&(n='

'.concat(t.title,"

").concat(n,"

")),t.noAutohide&&(t.noAutoHide=t.noAutohide),t.noAutoHide&&(t.autohide=!t.noAutoHide),t.autoHideDelay?(t.autohide||(t.autohide=!0),t.delay=t.autoHideDelay):t.autoHideDelay=1e4,Object.prototype.hasOwnProperty.call(t,"autohide")||(t.autohide=!0),e==="alert"&&(t.modal=!0,t.autohide=!1,n=' '.concat(n));let r=this.document.getElementById("toaster");r===null&&(r=this.document.createElement("div"),r.id="toaster",r.title="Click to clear all notifcations",r.setAttribute("class","toaster"),r.setAttribute("role","dialog"),r.setAttribute("arial-label","Toast message"),r.onclick=function(){r.remove()},this.document.body.insertAdjacentElement("afterbegin",r));let o=this.document.createElement("div");o.title="Click to clear this notifcation",o.setAttribute("class","toast ".concat(t.variant?t.variant:""," ").concat(e)),o.innerHTML=n,o.setAttribute("role","alertdialog"),t.modal&&o.setAttribute("aria-modal",t.modal),o.onclick=function(c){c.stopPropagation(),o.remove(),r.childElementCount<1&&r.remove()},r.insertAdjacentElement(t.appendToast===!0?"beforeend":"afterbegin",o),t.autohide===!0&&setInterval(()=>{o.remove(),r.childElementCount<1&&r.remove()},t.autoHideDelay)}_showNotification(e){e.topic&&!e.title&&(e.title=e.topic),e.title||(e.title="uibuilder notification"),e.payload&&!e.body&&(e.body=e.payload),e.body||(e.body=" No message given.");try{let t=new Notification(e.title,e);return new Promise((i,n)=>{t.addEventListener("close",r=>{r.currentTarget.userAction="close",i(r)}),t.addEventListener("click",r=>{r.currentTarget.userAction="click",i(r)}),t.addEventListener("error",r=>{r.currentTarget.userAction="error",n(r)})})}catch{return Promise.reject(new Error("Browser refused to create a Notification"))}}async notification(e){if(typeof e=="string"&&(e={body:e}),typeof Notification>"u")return Promise.reject(new Error("Notifications not available in this browser"));let t=Notification.permission;return t==="denied"?Promise.reject(new Error("Notifications not permitted by user")):t==="granted"?this._showNotification(e):(t=await Notification.requestPermission(),t==="granted"?this._showNotification(e):Promise.reject(new Error("Notifications not permitted by user")))}loadui(e){if(!fetch){d.log(0,"Ui:loadui","Current environment does not include `fetch`, skipping.")();return}if(!e){d.log(0,"Ui:loadui","url parameter must be provided, skipping.")();return}fetch(e).then(t=>{if(t.ok===!1)throw new Error("Could not load '".concat(e,"'. Status ").concat(t.status,", Error: ").concat(t.statusText));d.log("trace","Ui:loadui:then1","Loaded '".concat(e,"'. Status ").concat(t.status,", ").concat(t.statusText))();let i=t.headers.get("content-type");if(!i||!i.includes("application/json"))throw new TypeError("Fetch '".concat(e,"' did not return JSON, ignoring"));return t.json()}).then(t=>t!==void 0?(d.log("trace","Ui:loadui:then2","Parsed JSON successfully obtained")(),this._uiManager({_ui:t}),!0):!1).catch(t=>{d.log("warn","Ui:loadui:catch","Error. ",t)()})}_uiComposeComponent(e,t){t.attributes&&Object.keys(t.attributes).forEach(i=>{i==="value"&&(e.value=t.attributes[i]),i.startsWith("xlink:")?e.setAttributeNS("http://www.w3.org/1999/xlink",i,t.attributes[i]):e.setAttribute(i,t.attributes[i])}),t.id&&e.setAttribute("id",t.id),t.type==="svg"&&(e.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns","http://www.w3.org/2000/svg"),e.setAttributeNS("http://www.w3.org/2000/xmlns/","xmlns:xlink","http://www.w3.org/1999/xlink")),t.events&&Object.keys(t.events).forEach(i=>{i.toLowerCase==="onclick"&&(i="click");try{e.addEventListener(i,n=>{new Function("evt","".concat(t.events[i],"(evt)"))(n)})}catch(n){d.log("error","Ui:_uiComposeComponent","Add event '".concat(i,"' for element '").concat(t.type,"': Cannot add event handler. ").concat(n.message))()}}),t.properties&&Object.keys(t.properties).forEach(i=>{e[i]=t.properties[i]}),t.slot&&this.replaceSlot(e,t),t.slotMarkdown&&this.replaceSlotMarkdown(e,t)}uiEnhanceElement(e,t){this._uiComposeComponent(e,t)}_uiExtendEl(e,t,i=""){t.forEach((n,r)=>{d.log("trace","Ui:_uiExtendEl:components-forEach:".concat(r),n)();let o;n.ns=i,n.ns==="html"?(o=e,e.innerHTML=n.slot):n.ns==="svg"?(o=this.document.createElementNS("http://www.w3.org/2000/svg",n.type),this._uiComposeComponent(o,n),e.appendChild(o)):(o=this.document.createElement(n.type==="html"?"div":n.type),this._uiComposeComponent(o,n),e.appendChild(o)),n.components&&this._uiExtendEl(o,n.components,n.ns)})}_uiAdd(e,t){d.log("trace","Ui:_uiManager:add","Starting _uiAdd")(),e.components.forEach((i,n)=>{d.log("trace","Ui:_uiAdd:components-forEach:".concat(n),"Component to add: ",i)();let r;switch(i.type){case"html":{i.ns="html",r=this.document.createElement("div");break}case"svg":{i.ns="svg",r=this.document.createElementNS("http://www.w3.org/2000/svg","svg");break}default:{i.ns="dom",r=this.document.createElement(i.type);break}}!i.slot&&e.payload&&(i.slot=e.payload),this._uiComposeComponent(r,i);let o;i.parentEl?o=i.parentEl:e.parentEl?o=e.parentEl:i.parent?o=this.document.querySelector(i.parent):e.parent&&(o=this.document.querySelector(e.parent)),o||(d.log("info","Ui:_uiAdd","No parent found, adding to body")(),o=this.document.querySelector("body")),i.position&&i.position==="first"?o.insertBefore(r,o.firstChild):i.position&&Number.isInteger(Number(i.position))?o.insertBefore(r,o.children[i.position]):o.appendChild(r),i.components&&this._uiExtendEl(r,i.components,i.ns)})}_uiRemove(e,t=!1){e.components.forEach(i=>{let n;t!==!0?n=[this.document.querySelector(i)]:n=this.document.querySelectorAll(i),n.forEach(r=>{try{r.remove()}catch(o){d.log("trace","Ui:_uiRemove","Could not remove. ".concat(o.message))()}})})}_uiReplace(e){d.log("trace","Ui:_uiReplace","Starting")(),e.components.forEach((t,i)=>{d.log("trace","Ui:_uiReplace:components-forEach:".concat(i),"Component to replace: ",t)();let n;if(t.id?n=this.document.getElementById(t.id):t.selector||t.select?n=this.document.querySelector(t.selector):t.name?n=this.document.querySelector('[name="'.concat(t.name,'"]')):t.type&&(n=this.document.querySelector(t.type)),d.log("trace","Ui:_uiReplace:components-forEach:".concat(i),"Element to replace: ",n)(),n==null){d.log("trace","Ui:_uiReplace:components-forEach:".concat(i,":noReplace"),"Cannot find the DOM element. Adding instead.",t)(),this._uiAdd({components:[t]},!1);return}let r;switch(t.type){case"html":{t.ns="html",r=this.document.createElement("div");break}case"svg":{t.ns="svg",r=this.document.createElementNS("http://www.w3.org/2000/svg","svg");break}default:{t.ns="dom",r=this.document.createElement(t.type);break}}this._uiComposeComponent(r,t),n.replaceWith(r),t.components&&this._uiExtendEl(r,t.components,t.ns)})}_uiUpdate(e){d.log("trace","Ui:_uiManager:update","Starting _uiUpdate")(),e.components||(e.components=[Object.assign({},e)]),e.components.forEach((t,i)=>{d.log("trace","_uiUpdate:components-forEach","Component #".concat(i),t)();let n;if(t.id?n=this.document.querySelectorAll("#".concat(t.id)):t.selector||t.select?n=this.document.querySelectorAll(t.selector):t.name?n=this.document.querySelectorAll('[name="'.concat(t.name,'"]')):t.type&&(n=this.document.querySelectorAll(t.type)),n===void 0||n.length<1){d.log("warn","Ui:_uiManager:update","Cannot find the DOM element. Ignoring.",t)();return}d.log("trace","_uiUpdate:components-forEach","Element(s) to update. Count: ".concat(n.length),n)(),!t.slot&&t.payload&&(t.slot=t.payload),n.forEach(r=>{this._uiComposeComponent(r,t)}),t.components&&n.forEach(r=>{d.log("trace","_uiUpdate:components","el",r)(),this._uiUpdate({method:e.method,parentEl:r,components:t.components})})})}_uiLoad(e){e.components&&(Array.isArray(e.components)||(e.components=[e.components]),e.components.forEach(async t=>{await Promise.resolve().then(()=>_e(Be(t)))})),e.srcScripts&&(Array.isArray(e.srcScripts)||(e.srcScripts=[e.srcScripts]),e.srcScripts.forEach(t=>{this.loadScriptSrc(t)})),e.txtScripts&&(Array.isArray(e.txtScripts)||(e.txtScripts=[e.txtScripts]),this.loadScriptTxt(e.txtScripts.join("\n"))),e.srcStyles&&(Array.isArray(e.srcStyles)||(e.srcStyles=[e.srcStyles]),e.srcStyles.forEach(t=>{this.loadStyleSrc(t)})),e.txtStyles&&(Array.isArray(e.txtStyles)||(e.txtStyles=[e.txtStyles]),this.loadStyleTxt(e.txtStyles.join("\n")))}_uiReload(){d.log("trace","Ui:uiManager:reload","reloading")(),location.reload()}_uiManager(e){e._ui&&(Array.isArray(e._ui)||(e._ui=[e._ui]),e._ui.forEach((t,i)=>{if(!t.method){d.log("error","Ui:_uiManager","No method defined for msg._ui[".concat(i,"]. Ignoring"))();return}switch(t.payload=e.payload,t.topic=e.topic,t.method){case"add":{this._uiAdd(t,!1);break}case"remove":{this._uiRemove(t,!1);break}case"removeAll":{this._uiRemove(t,!0);break}case"replace":{this._uiReplace(t);break}case"update":{this._uiUpdate(t);break}case"load":{this._uiLoad(t);break}case"reload":{this._uiReload();break}case"notify":{this.showDialog("notify",t,e);break}case"alert":{this.showDialog("alert",t,e);break}default:{d.log("error","Ui:_uiManager","Invalid msg._ui[".concat(i,"].method (").concat(t.method,"). Ignoring"))();break}}}))}nodeGet(e,t){let i={id:e.id===""?void 0:e.id,name:e.name,children:e.childNodes.length,type:e.nodeName,attributes:void 0,isUserInput:!!e.validity,userInput:e.validity?{value:e.value,validity:void 0,willValidate:e.willValidate,valueAsDate:e.valueAsDate,valueAsNumber:e.valueAsNumber,type:e.type}:void 0};if(["UL","OL"].includes(e.nodeName)){let n=this.document.querySelectorAll("".concat(t," li"));n&&(i.list={entries:n.length})}if(e.nodeName==="DL"){let n=this.document.querySelectorAll("".concat(t," dt"));n&&(i.list={entries:n.length})}if(e.nodeName==="TABLE"){let n=this.document.querySelectorAll("".concat(t," > tbody > tr")),r=this.document.querySelectorAll("".concat(t," > thead > tr")),o=this.document.querySelectorAll("".concat(t," > tbody > tr:last-child > *"));(n||r||o)&&(i.table={headRows:r?r.length:0,bodyRows:n?n.length:0,columns:o?o.length:0})}if(e.nodeName!=="#text"&&e.attributes&&e.attributes.length>0){i.attributes={};for(let n of e.attributes)n.name!=="id"&&(i.attributes[n.name]=e.attributes[n.name].value)}e.nodeName==="#text"&&(i.text=e.textContent),e.validity&&(i.userInput.validity={});for(let n in e.validity)i.userInput.validity[n]=e.validity[n];return i}uiGet(e,t=null){let i=this.document.querySelectorAll(e),n=[];return i.forEach(r=>{if(t!==null&&t!==""){let o=r.getAttribute(t);if(o==null)try{o=r[t]}catch{}if(o==null)t.toLowerCase()==="value"?n.push(r.innerText):n.push("Property '".concat(t,"' not found"));else if(o.constructor.name==="NamedNodeMap"){let c={};for(let l of o)c[l.name]=o[l.name].value;n.push(c)}else if(!o.constructor.name.toLowerCase().includes("map"))n.push({[t]:o});else{let c={};for(let l in o)c[l]=o[l];n.push(c)}}else n.push(this.nodeGet(r,e))}),n}async include(e,t){if(!fetch)return d.log(0,"Ui:include","Current environment does not include `fetch`, skipping.")(),"Current environment does not include `fetch`, skipping.";if(!e)return d.log(0,"Ui:include","url parameter must be provided, skipping.")(),"url parameter must be provided, skipping.";if(!t||!t.id)return d.log(0,"Ui:include","uiOptions parameter MUST be provided and must contain at least an `id` property, skipping.")(),"uiOptions parameter MUST be provided and must contain at least an `id` property, skipping.";let i;try{i=await fetch(e)}catch(m){return d.log(0,"Ui:include","Fetch of file '".concat(e,"' failed. "),m.message)(),m.message}if(!i.ok)return d.log(0,"Ui:include","Fetch of file '".concat(e,"' failed. Status='").concat(i.statusText,"'"))(),i.statusText;let n=await i.headers.get("content-type"),r=null;n&&(n.includes("text/html")?r="html":n.includes("application/json")?r="json":n.includes("multipart/form-data")?r="form":n.includes("image/")?r="image":n.includes("video/")?r="video":n.includes("application/pdf")?r="pdf":n.includes("text/plain")&&(r="text"));let o="",c="Include successful",l;switch(r){case"html":{l=await i.text(),o=l;break}case"json":{l=await i.json(),o='
',o+=this.syntaxHighlight(l),o+="
";break}case"form":{l=await i.formData(),o='
',o+=this.syntaxHighlight(l),o+="
";break}case"image":{l=await i.blob(),o=''),this.window.DOMPurify&&(c="Include successful. BUT DOMPurify loaded which may block its use.",d.log("warn","Ui:include:image",c)());break}case"video":{l=await i.blob(),o=''),this.window.DOMPurify&&(c="Include successful. BUT DOMPurify loaded which may block its use.",d.log("warn","Ui:include:video",c)());break}case"pdf":case"text":default:{l=await i.blob(),o='