@sap/ux-ui5-tooling 1.4.7 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- (()=>{"use strict";var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{init:()=>W});const n="post-message-action";function o(e,t){function o(){return"function"==typeof e?e():e}function a(e){const a=o();var r;a&&e.origin===a.origin&&e.source===a&&((r=e.data).type===n&&"object"==typeof r.action?t(e.data.action):console.warn("Unknown message received",e.data))}return window.addEventListener("message",a),{dispose:function(){window.removeEventListener("message",a)},sendAction:function(e){const t=o();if(!t)return;const a={type:n,action:e};t.postMessage(a,t.origin)}}}const a="string",r="input";const i=(c="[ext]",function(e){const t=[c,e].join(" ");function n(e){return{type:t,payload:e}}var o;return n.type=t,n.match=(o=t,function(e){return(null==e?void 0:e.type)===o}),n});var c;const s=i("icons-loaded"),l=i("control-selected"),p=i("select-control"),u=i("delete-property-changes"),d=i("outline-changed"),g=i("change-property"),y=i("property-changed"),m=i("change-property-failed"),f=i("change-stack-modified");async function h(e){let t;try{t=await v(e)}catch(t){console.error(`Error in getting document for ${e}`)}return t}async function v(e){const t=await async function(e){let t;const n={method:"GET",cache:"force-cache",headers:{"Content-Type":"application/xml"}};let o;try{o=await fetch(jQuery.sap.getModulePath(e,".control"),n)}catch(e){console.error("Error in fetching control metadata")}if(200===(null==o?void 0:o.status)){const n=await o.text();t=function(e,t){const n=e.children,o={baseType:I(C(n),t),doc:w(n),properties:{}},a=function(e,t){var n;const o=e.length;let a=null;for(let r=0;r<o;r++)if(e&&e.item(r)&&(null===(n=e.item(r))||void 0===n?void 0:n.tagName)===t){a=e.item(r);break}return a}(e.children,"properties"),r=null==a?void 0:a.children;return b(r).forEach((e=>{o.properties[e.propertyName]={...e}})),o}((new DOMParser).parseFromString(n,"application/xml").documentElement,e)}return t}(e);if(t){const e=t.baseType;if(e){const n=await v(e);return Object.assign({},n,t.properties)}return Object.assign(Object.assign({},t.properties))}return t}function C(e){var t,n;const o=e.length;let a="";for(let r=0;r<o;r++)if(e&&e.item(r)&&"baseType"===(null===(t=e.item(r))||void 0===t?void 0:t.tagName)){a=(null===(n=e.item(r))||void 0===n?void 0:n.innerHTML)||"";break}return a}function b(e){var t,n,o,a;const r=[];for(const i in e){const c={propertyName:"",type:"",defaultValue:"",description:"",propertyType:""},s=parseInt(i);c.propertyName=(null===(t=null==e?void 0:e.item(s))||void 0===t?void 0:t.getAttribute("name"))||"",c.type=I((null===(n=null==e?void 0:e.item(s))||void 0===n?void 0:n.getAttribute("type"))||"string")||"",c.description=N((null===(o=null==e?void 0:e.item(s))||void 0===o?void 0:o.textContent)||"")||"",c.defaultValue=(null===(a=null==e?void 0:e.item(s))||void 0===a?void 0:a.getAttribute("defaultValue"))||"-",c.propertyType=S(c.type),r.push(c)}return r}function w(e){return N(function(e){var t,n;const o=e.length;let a="";for(let r=0;r<o;r++)if(e&&e.item(r)&&"documentation"===(null===(t=e.item(r))||void 0===t?void 0:t.tagName)){a=(null===(n=e.item(r))||void 0===n?void 0:n.textContent)||"";break}return a}(e))}const O="boolean int float number function object string void any",T=O+" Element Control Component";function I(e,t){return e?-1!==e.indexOf("/")?e.replace(/\//g,"."):-1===e.indexOf(".")&&-1!==T.indexOf(e)?"sap.ui.core."+e:t?t.split(".").slice(0,-1).concat([e.replace(/\//g,".")]).join("."):void 0:""}function N(e){return e.replace(new RegExp("<[^>]*>","g"),"")}function S(e){if(e){const t=e.replace(/^sap\.ui\.core\./,"");return-1!==O.indexOf(t.replace("[]",""))?t:e}}const E=e=>{const t=e.replace(/([A-Z])/g," $1");return t.charAt(0).toUpperCase()+t.slice(1)},P=/src|.*icon$|^icon.*/i;function j(e){const t={primitiveType:"any",ui5Type:null,enumValues:null,isArray:!1};if(!e)return;const n=e.getType();if(!n)return;const o=n.getName();if(o){if(o.indexOf("[]")>0)t.primitiveType=o.substring(0,o.indexOf("[]")),t.isArray=!0;else if("void"===o||"object"===o)t.primitiveType=o;else if("any"===o)t.primitiveType="any";else if("boolean"===o||"string"===o||"int"===o||"float"===o)t.primitiveType=o;else{const e=window.sap.ui.base.DataType,n=e.getType(o);if(n&&!(n instanceof e))return t;const a=Object.getPrototypeOf(n).getName();t.primitiveType=a||"enum",t.ui5Type=o,"enum"===t.primitiveType&&(t.enumValues=jQuery.sap.getObject(t.ui5Type))}return t}}function x(e){return!e.isArray&&"any"!==e.primitiveType}function A(e){if(!("object"==typeof e&&e instanceof Object)||Array.isArray(e))return"function"==typeof e?"":e;try{return JSON.stringify(e)}catch(t){return t instanceof Error&&t.message.toLowerCase().includes("converting circular structure to json")?"<Circular JSON cannot be displayed>":e}}async function k(e,t,n=!0){var o,i;const c=e.getMetadata(),s=c.getName(),l=sap.ui.fl.Utils.checkControlId(e),p=t?t.getDesignTimeMetadata().getData().properties:void 0,u=c.getAllProperties(),d=Object.keys(u),g=[],y=n?await h(s):{};for(const n of d){const c=u[n],d=j(c);if(!d)continue;let m=!1;p&&p[c.name]&&(m=p[c.name].ignore);const f={id:e.getId(),name:c.name,newValue:e.getProperty(c.name)},h=e.getBindingInfo(f.name);void 0!==(null==h?void 0:h.bindingString)&&(f.newValue=h.bindingString);const v=null!==(o=null==t?void 0:t.isSelectable())&&void 0!==o&&o&&x(d)&&l&&!m,C=A(f.newValue),b=P.test(c.name)&&"sap.m.Image"!==s&&"sap.ui.core.URI"===d.ui5Type,w=y&&y[c.name]?y[c.name]:{defaultValue:c.defaultValue||"-",description:"",propertyName:c.name,type:d.ui5Type,propertyType:d.ui5Type},O=E(c.name);switch(d.primitiveType){case"enum":{const e=null!==(i=d.enumValues)&&void 0!==i?i:{},t=Object.keys(e).map((t=>({key:t,text:e[t]})));g.push({type:a,editor:"dropdown",name:c.name,readableName:O,value:C,isEnabled:v,options:t,documentation:w});break}case"string":g.push({type:a,editor:r,name:c.name,readableName:O,value:C,isEnabled:v,isIcon:b,documentation:w});break;case"int":g.push({type:"integer",editor:r,name:c.name,readableName:O,value:C,isEnabled:v,documentation:w});break;case"float":g.push({type:"float",editor:r,name:c.name,readableName:O,value:C,isEnabled:v,documentation:w});break;case"boolean":g.push({type:"boolean",editor:"checkbox",name:c.name,readableName:O,value:C,isEnabled:v,documentation:w})}}return{id:e.getId(),type:s,properties:g.sort(((e,t)=>e.name>t.name?1:-1))}}const M=async(e="")=>{let t=!1;const n=sap.ui.getCore().byId(e);if(n){let e=sap.ui.dt.OverlayRegistry.getOverlay(n);if(e&&e.getDomRef()||(e=sap.ui.dt.OverlayUtil.getClosestOverlayFor(n)),e){t=void 0!==(await k(e.getElementInstance(),e,!1)).properties.find((e=>!0===e.isEnabled))}}else{const n=sap.ui.getCore().getComponent(e);if(n){(await k(n,void 0,!1)).properties.find((e=>!0===e.isEnabled));t=!1}}return t};async function V(e,t){var n,o;const a=[...e],r=[];for(;a.length;){const e=a.shift(),i=await M(null==e?void 0:e.id);if("element"===(null==e?void 0:e.type)){const a=(null!==(n=e.elements)&&void 0!==n?n:[]).flatMap((e=>{var t;return"aggregation"===e.type&&null!==(t=e.elements)&&void 0!==t?t:[]})),{text:c}=t(e.id),s={controlId:e.id,controlType:e.technicalName,name:null!=c?c:e.technicalName.split(".").slice(-1)[0],editable:i,visible:null===(o=e.visible)||void 0===o||o,children:await V(a,t)};r.push(s)}}return r}async function F(e,t){const n=await e.getService("outline");n.attachEvent("update",(async function(){const e=await n.get(),o=await V(e,(e=>{const t=sap.ui.getCore().byId(e);if(t&&t.getMetadata().getProperty("text")){const e=t.getProperty("text");return"string"==typeof e&&""!==e.trim()?{text:e}:{}}return{}}));t(d(o))}))}function B(e){return sap.ui.getCore().byId(e)}function D(e){return sap.ui.getCore().getComponent(e)}function H(e){return sap.ui.dt.OverlayRegistry.getOverlay(e)}function R(e){return sap.ui.dt.OverlayUtil.getClosestOverlayFor(e)}function $(){return sap.ui.core.IconPool.getIconNames("undefined").map((e=>{const t=sap.ui.core.IconPool.getIconInfo(e);return{name:e.toLowerCase(),content:t.content,fontFamily:t.fontFamily}})).sort(((e,t)=>e.name<t.name?-1:e.name>t.name?1:0))}function L(e){const t={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(e)};fetch("./control-property-editor/report-telemetry",t).then((async e=>{console.log(e)})).catch((e=>{console.error("There was an error!",e)}))}class SelectionService{constructor(e,t){this.rta=e,this.ui5=t,this.appliedChangeCache=new Map,this.activeChangeHandlers=new Set}init(e,t){const n=new Set;this.rta.attachSelectionChange(this.createOnSelectionChangeHandler(e,n)),t((async t=>{if(p.match(t)){const o=t.payload,a=this.ui5.getControlById(o);if(!a){const t=this.ui5.getComponent(o);if(t){const n=await k(t),o=l(n);e(o)}return}n.add("outline");let r=this.ui5.getOverlay(a);const i=this.rta.getSelection();if(i.length>0)for(let e=0;e<i.length;e++)i[e].setSelected(!1);if(r&&r.getDomRef()||(r=this.ui5.getClosestOverlayFor(a)),r&&r.isSelectable())r.setSelected(!0);else{const t=await k(a),n=l(t);e(n)}}}))}applyControlPropertyChange(e,t){const n=U(e,t);this.appliedChangeCache.set(n,Date.now())}createOnSelectionChangeHandler(e,t){return async n=>{const o=n.getParameter("selection");for(const e of this.activeChangeHandlers)e();if(this.activeChangeHandlers.clear(),Array.isArray(o)&&1===o.length){const n=this.ui5.getControlById(o[0].getId());if(n){const o=n.getElementInstance(),a=o.getMetadata().getName();this.handlePropertyChanges(o,e);try{const r=t.has("outline"),i=a.toLowerCase().startsWith("sap")?a:"Other Control Types";L(r?{category:"Outline Selection",controlName:i}:{category:"Overlay Selection",controlName:i})}catch(e){console.error("Error in reporting telemetry",e)}finally{const a=await k(o,n),r=l(a);e(r),t.delete("outline")}}}}}handlePropertyChanges(e,t){const n=n=>{var o;const a=n.getParameter("name"),r=n.getParameter("id"),i=U(r,a);if(this.appliedChangeCache.get(i))return void this.appliedChangeCache.delete(i);const c=e.getBindingInfo(a),s=null!==(o=null==c?void 0:c.bindingString)&&void 0!==o?o:n.getParameter("newValue"),l=y({controlId:r,propertyName:a,newValue:s});t(l)};e.attachEvent("_change",n),this.activeChangeHandlers.add((()=>{try{e.detachEvent("_change",n)}catch{}}))}}function U(e,t){return[e,t].join(",")}function _(e){return!(!e.startsWith("{")||!e.endsWith("}"))}class ChangeService{constructor(e,t,n){this.options=e,this.ui5=t,this.selectionService=n,this.savedChanges=[]}async init(e,t){t((async t=>{if(g.match(t))try{this.selectionService.applyControlPropertyChange(t.payload.controlId,t.payload.propertyName),await async function(e,t){const{layer:n,componentId:o,rta:a,generator:r}=e,i=sap.ui.getCore().byId(t.controlId);if(!i)return;const c={layer:n,developerMode:!0,baseId:o,projectId:"",scenario:"FE_FROM_SCRATCH"},s="string"==typeof t.value&&_(t.value)?"BindProperty":"Property",l="string"==typeof t.value&&_(t.value)?{propertyName:t.propertyName,newBinding:t.value}:{propertyName:t.propertyName,newValue:t.value},p=await sap.ui.rta.command.CommandFactory.getCommandFor(i,s,l,null,c);p.getPreparedChange().getDefinition().support.generator=r,await a.getCommandStack().pushAndExecute(p)}(this.options,t.payload)}catch(n){let o="";const a=t.payload.controlId||"",r=this.ui5.getControlById(a);r&&(o=r.getMetadata().getName());const i=function(e,t,n){return e.replace("Error: Applying property changes failed:","").replace(`${n}#${t}`,"")}(null==n?void 0:n.toString(),a,o),c=i||`RTA Exception applying expression "${t.payload.value}"`,s=m({...t.payload,errorMessage:c});e(s)}else u.match(t)&&this.deleteChange(t.payload.controlId,t.payload.propertyName)}));const n=await fetch(`/FioriTools/api/getChanges?_=${Date.now()}`).then((e=>e.json())),o=Object.keys(null!=n?n:{}).map((e=>{var t;const o=n[e];try{if(function(e,t){for(const n of e){const e=J(n,t);if(null==e)throw new Error(`Invalid change, missing ${n} in the change file`)}}(["fileName","selector.id","content.property","creation"],o),[o.content.newValue,o.content.newBinding].every((e=>null==e)))throw new Error("Invalid change, missing new value in the change file");return{type:"saved",fileName:o.fileName,controlId:o.selector.id,propertyName:o.content.property,value:null!==(t=o.content.newValue)&&void 0!==t?t:o.content.newBinding,timestamp:new Date(o.creation).getTime()}}catch(e){return void console.error(e)}})).filter((e=>!!e)).sort(((e,t)=>e.timestamp-t.timestamp));this.savedChanges=o,e(f(o)),this.options.rta.attachUndoRedoStackModified(this.createOnStackChangeHandler(e))}async deleteChange(e,t){const n=this.savedChanges.filter((n=>n.controlId===e&&n.propertyName===t)).map((e=>fetch("/FioriTools/api/removeChanges",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({fileName:e.fileName})})));await Promise.all(n).catch(console.error)}createOnStackChangeHandler(e){return async()=>{const t=this.options.rta.getCommandStack().getAllExecutedCommands().map((e=>{try{const t=e.getProperty("selector"),n=e.getProperty("changeType");let o="";switch(n){case"propertyChange":o=e.getProperty("newValue");break;case"propertyBindingChange":o=e.getProperty("newBinding")}return{type:"pending",controlId:t.id,propertyName:e.getProperty("propertyName"),isActive:!0,value:o}}catch(e){console.error(e)}})).filter((e=>!!e));e(f([...this.savedChanges,...t]))}}}function J(e,t){const n=e.split(".");let o=t;for(const e of n)o=o[e];return o}function W(e){console.log("Initializing Control Property Editor");const{rta:t}=e,n={getControlById:B,getIcons:$,getComponent:D,getOverlay:H,getClosestOverlayFor:R},a=[];function r(e){a.push(e)}const i=new SelectionService(t,n),c=[i,new ChangeService(e,n,i)];try{const{sendAction:e}=o(window.parent,(async function(e){for(const t of a)try{await t(e)}catch(e){console.error(e)}}));for(const t of c)t.init(e,r);F(t,e);const i=n.getIcons();e(s(i))}catch(e){console.error("Error during initialization of Control Property Editor",e)}}self["ui5-adaptation"]=t})();
1
+ (()=>{"use strict";var e={d:(t,n)=>{for(var o in n)e.o(n,o)&&!e.o(t,o)&&Object.defineProperty(t,o,{enumerable:!0,get:n[o]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{init:()=>W});const n="post-message-action";function o(e,t){function o(){return"function"==typeof e?e():e}function a(e){const a=o();var r;a&&e.origin===a.origin&&e.source===a&&((r=e.data).type===n&&"object"==typeof r.action?t(e.data.action):console.warn("Unknown message received",e.data))}return window.addEventListener("message",a),{dispose:function(){window.removeEventListener("message",a)},sendAction:function(e){const t=o();if(!t)return;const a={type:n,action:e};t.postMessage(a,t.origin)}}}const a="string",r="input";const i=(c="[ext]",function(e){const t=[c,e].join(" ");function n(e){return{type:t,payload:e}}var o;return n.type=t,n.match=(o=t,function(e){return(null==e?void 0:e.type)===o}),n});var c;const s=i("icons-loaded"),l=i("control-selected"),p=i("select-control"),d=i("delete-property-changes"),u=i("outline-changed"),g=i("change-property"),y=i("property-changed"),m=i("change-property-failed"),f=i("change-stack-modified");async function h(e){let t;try{t=await v(e)}catch(t){console.error(`Error in getting document for ${e}`)}return t}async function v(e){const t=await async function(e){let t;const n={method:"GET",cache:"force-cache",headers:{"Content-Type":"application/xml"}};let o;try{o=await fetch(jQuery.sap.getModulePath(e,".control"),n)}catch(e){console.error("Error in fetching control metadata")}if(200===(null==o?void 0:o.status)){const n=await o.text();t=function(e,t){const n=e.children,o={baseType:T(C(n),t),doc:w(n),properties:{}},a=function(e,t){var n;const o=e.length;let a=null;for(let r=0;r<o;r++)if(e&&e.item(r)&&(null===(n=e.item(r))||void 0===n?void 0:n.tagName)===t){a=e.item(r);break}return a}(e.children,"properties"),r=null==a?void 0:a.children;return b(r).forEach((e=>{o.properties[e.propertyName]={...e}})),o}((new DOMParser).parseFromString(n,"application/xml").documentElement,e)}return t}(e);if(t){const e=t.baseType;if(e){const n=await v(e);return Object.assign({},n,t.properties)}return Object.assign(Object.assign({},t.properties))}return t}function C(e){var t,n;const o=e.length;let a="";for(let r=0;r<o;r++)if(e&&e.item(r)&&"baseType"===(null===(t=e.item(r))||void 0===t?void 0:t.tagName)){a=(null===(n=e.item(r))||void 0===n?void 0:n.innerHTML)||"";break}return a}function b(e){var t,n,o,a;const r=[];for(const i in e){const c={propertyName:"",type:"",defaultValue:"",description:"",propertyType:""},s=parseInt(i);c.propertyName=(null===(t=null==e?void 0:e.item(s))||void 0===t?void 0:t.getAttribute("name"))||"",c.type=T((null===(n=null==e?void 0:e.item(s))||void 0===n?void 0:n.getAttribute("type"))||"string")||"",c.description=I((null===(o=null==e?void 0:e.item(s))||void 0===o?void 0:o.textContent)||"")||"",c.defaultValue=(null===(a=null==e?void 0:e.item(s))||void 0===a?void 0:a.getAttribute("defaultValue"))||"-",c.propertyType=S(c.type),r.push(c)}return r}function w(e){return I(function(e){var t,n;const o=e.length;let a="";for(let r=0;r<o;r++)if(e&&e.item(r)&&"documentation"===(null===(t=e.item(r))||void 0===t?void 0:t.tagName)){a=(null===(n=e.item(r))||void 0===n?void 0:n.textContent)||"";break}return a}(e))}const N="boolean int float number function object string void any",O=N+" Element Control Component";function T(e,t){return e?-1!==e.indexOf("/")?e.replace(/\//g,"."):-1===e.indexOf(".")&&-1!==O.indexOf(e)?"sap.ui.core."+e:t?t.split(".").slice(0,-1).concat([e.replace(/\//g,".")]).join("."):void 0:""}function I(e){return e.replace(new RegExp("<[^>]*>","g"),"")}function S(e){if(e){const t=e.replace(/^sap\.ui\.core\./,"");return-1!==N.indexOf(t.replace("[]",""))?t:e}}const E=e=>{const t=e.replace(/([A-Z])/g," $1");return t.charAt(0).toUpperCase()+t.slice(1)},P=/src|.*icon$|^icon.*/i;function j(e){const t={primitiveType:"any",ui5Type:null,enumValues:null,isArray:!1};if(!e)return;const n=e.getType();if(!n)return;const o=n.getName();if(o){if(o.indexOf("[]")>0)t.primitiveType=o.substring(0,o.indexOf("[]")),t.isArray=!0;else if("void"===o||"object"===o)t.primitiveType=o;else if("any"===o)t.primitiveType="any";else if("boolean"===o||"string"===o||"int"===o||"float"===o)t.primitiveType=o;else{const e=window.sap.ui.base.DataType,n=e.getType(o);if(n&&!(n instanceof e))return t;const a=Object.getPrototypeOf(n).getName();t.primitiveType=a||"enum",t.ui5Type=o,"enum"===t.primitiveType&&(t.enumValues=jQuery.sap.getObject(t.ui5Type))}return t}}function k(e){return!e.isArray&&"any"!==e.primitiveType}function x(e){if(!("object"==typeof e&&e instanceof Object)||Array.isArray(e))return"function"==typeof e?"":e;try{return JSON.stringify(e)}catch(t){return t instanceof Error&&t.message.toLowerCase().includes("converting circular structure to json")?"<Circular JSON cannot be displayed>":e}}async function A(e,t,n=!0){var o,i;const c=e.getMetadata(),s=c.getName(),l=sap.ui.fl.Utils.checkControlId(e),p=t?t.getDesignTimeMetadata().getData().properties:void 0,d=c.getAllProperties(),u=Object.keys(d),g=[],y=n?await h(s):{};for(const n of u){const c=d[n],u=j(c);if(!u)continue;let m=!1;p&&p[c.name]&&(m=p[c.name].ignore);const f={id:e.getId(),name:c.name,newValue:e.getProperty(c.name)},h=e.getBindingInfo(f.name);void 0!==(null==h?void 0:h.bindingString)&&(f.newValue=h.bindingString);const v=null!==(o=null==t?void 0:t.isSelectable())&&void 0!==o&&o&&k(u)&&l&&!m,C=x(f.newValue),b=P.test(c.name)&&"sap.m.Image"!==s&&"sap.ui.core.URI"===u.ui5Type,w=y&&y[c.name]?y[c.name]:{defaultValue:c.defaultValue||"-",description:"",propertyName:c.name,type:u.ui5Type,propertyType:u.ui5Type},N=E(c.name);switch(u.primitiveType){case"enum":{const e=null!==(i=u.enumValues)&&void 0!==i?i:{},t=Object.keys(e).map((t=>({key:t,text:e[t]})));g.push({type:a,editor:"dropdown",name:c.name,readableName:N,value:C,isEnabled:v,options:t,documentation:w});break}case"string":g.push({type:a,editor:r,name:c.name,readableName:N,value:C,isEnabled:v,isIcon:b,documentation:w});break;case"int":g.push({type:"integer",editor:r,name:c.name,readableName:N,value:C,isEnabled:v,documentation:w});break;case"float":g.push({type:"float",editor:r,name:c.name,readableName:N,value:C,isEnabled:v,documentation:w});break;case"boolean":g.push({type:"boolean",editor:"checkbox",name:c.name,readableName:N,value:C,isEnabled:v,documentation:w})}}return{id:e.getId(),type:s,properties:g.sort(((e,t)=>e.name>t.name?1:-1)),name:s}}const M=async(e="")=>{let t=!1;const n=sap.ui.getCore().byId(e);if(n){let e=sap.ui.dt.OverlayRegistry.getOverlay(n);if(e&&e.getDomRef()||(e=sap.ui.dt.OverlayUtil.getClosestOverlayFor(n)),e){t=void 0!==(await A(e.getElementInstance(),e,!1)).properties.find((e=>!0===e.isEnabled))}}else{const n=sap.ui.getCore().getComponent(e);if(n){(await A(n,void 0,!1)).properties.find((e=>!0===e.isEnabled));t=!1}}return t};async function V(e,t){var n,o;const a=[...e],r=[];for(;a.length;){const e=a.shift(),i=await M(null==e?void 0:e.id);if("element"===(null==e?void 0:e.type)){const a=(null!==(n=e.elements)&&void 0!==n?n:[]).flatMap((e=>{var t;return"aggregation"===e.type&&null!==(t=e.elements)&&void 0!==t?t:[]})),{text:c}=t(e.id),s={controlId:e.id,controlType:e.technicalName,name:null!=c?c:e.technicalName.split(".").slice(-1)[0],editable:i,visible:null===(o=e.visible)||void 0===o||o,children:await V(a,t)};r.push(s)}}return r}async function F(e,t){const n=await e.getService("outline");n.attachEvent("update",(async function(){const e=await n.get(),o=await V(e,(e=>{const t=sap.ui.getCore().byId(e);if(t&&t.getMetadata().getProperty("text")){const e=t.getProperty("text");return"string"==typeof e&&""!==e.trim()?{text:e}:{}}return{}}));t(u(o))}))}function B(e){return sap.ui.getCore().byId(e)}function D(e){return sap.ui.getCore().getComponent(e)}function H(e){return sap.ui.dt.OverlayRegistry.getOverlay(e)}function R(e){return sap.ui.dt.OverlayUtil.getClosestOverlayFor(e)}function $(){return sap.ui.core.IconPool.getIconNames("undefined").map((e=>{const t=sap.ui.core.IconPool.getIconInfo(e);return{name:e.toLowerCase(),content:t.content,fontFamily:t.fontFamily}})).sort(((e,t)=>e.name<t.name?-1:e.name>t.name?1:0))}function L(e){const t={method:"POST",headers:{Accept:"application/json","Content-Type":"application/json"},body:JSON.stringify(e)};fetch("./control-property-editor/report-telemetry",t).then((async e=>{console.log(e)})).catch((e=>{console.error("There was an error!",e)}))}class SelectionService{constructor(e,t){this.rta=e,this.ui5=t,this.appliedChangeCache=new Map,this.activeChangeHandlers=new Set}init(e,t){const n=new Set;this.rta.attachSelectionChange(this.createOnSelectionChangeHandler(e,n)),t((async t=>{if(p.match(t)){const o=t.payload,a=this.ui5.getControlById(o);if(!a){const t=this.ui5.getComponent(o);if(t){const n=await A(t),o=l(n);e(o)}return}n.add("outline");let r=this.ui5.getOverlay(a);const i=this.rta.getSelection();if(i.length>0)for(let e=0;e<i.length;e++)i[e].setSelected(!1);if(r&&r.getDomRef()||(r=this.ui5.getClosestOverlayFor(a)),r&&r.isSelectable())r.setSelected(!0);else{const t=await A(a),n=l(t);e(n)}}}))}applyControlPropertyChange(e,t){const n=U(e,t);this.appliedChangeCache.set(n,Date.now())}createOnSelectionChangeHandler(e,t){return async n=>{const o=n.getParameter("selection");for(const e of this.activeChangeHandlers)e();if(this.activeChangeHandlers.clear(),Array.isArray(o)&&1===o.length){const n=this.ui5.getControlById(o[0].getId());if(n){const o=n.getElementInstance(),a=o.getMetadata().getName();this.handlePropertyChanges(o,e);try{const r=t.has("outline"),i=a.toLowerCase().startsWith("sap")?a:"Other Control Types";L(r?{category:"Outline Selection",controlName:i}:{category:"Overlay Selection",controlName:i})}catch(e){console.error("Error in reporting telemetry",e)}finally{const a=await A(o,n),r=l(a);e(r),t.delete("outline")}}}}}handlePropertyChanges(e,t){const n=n=>{var o;const a=n.getParameter("name"),r=n.getParameter("id"),i=U(r,a);if(this.appliedChangeCache.get(i))return void this.appliedChangeCache.delete(i);const c=e.getBindingInfo(a),s=null!==(o=null==c?void 0:c.bindingString)&&void 0!==o?o:n.getParameter("newValue"),l=y({controlId:r,propertyName:a,newValue:s});t(l)};e.attachEvent("_change",n),this.activeChangeHandlers.add((()=>{try{e.detachEvent("_change",n)}catch{}}))}}function U(e,t){return[e,t].join(",")}function _(e){return!(!e.startsWith("{")||!e.endsWith("}"))}class ChangeService{constructor(e,t,n){this.options=e,this.ui5=t,this.selectionService=n,this.savedChanges=[]}async init(e,t){t((async t=>{if(g.match(t))try{this.selectionService.applyControlPropertyChange(t.payload.controlId,t.payload.propertyName),await async function(e,t){const{layer:n,componentId:o,rta:a,generator:r}=e,i=sap.ui.getCore().byId(t.controlId);if(!i)return;const c={layer:n,developerMode:!0,baseId:o,projectId:"",scenario:"FE_FROM_SCRATCH"},s="string"==typeof t.value&&_(t.value)?"BindProperty":"Property",l="string"==typeof t.value&&_(t.value)?{propertyName:t.propertyName,newBinding:t.value}:{propertyName:t.propertyName,newValue:t.value},p=await sap.ui.rta.command.CommandFactory.getCommandFor(i,s,l,null,c);p.getPreparedChange().getDefinition().support.generator=r,await a.getCommandStack().pushAndExecute(p)}(this.options,t.payload)}catch(n){let o="";const a=t.payload.controlId||"",r=this.ui5.getControlById(a);r&&(o=r.getMetadata().getName());const i=function(e,t,n){return e.replace("Error: Applying property changes failed:","").replace(`${n}#${t}`,"")}(null==n?void 0:n.toString(),a,o),c=i||`RTA Exception applying expression "${t.payload.value}"`,s=m({...t.payload,errorMessage:c});e(s)}else d.match(t)&&this.deleteChange(t.payload.controlId,t.payload.propertyName,t.payload.fileName)}));const n=await fetch(`/FioriTools/api/getChanges?_=${Date.now()}`).then((e=>e.json())),o=Object.keys(null!=n?n:{}).map((e=>{var t;const o=n[e];try{if(function(e,t){for(const n of e){const e=J(n,t);if(null==e)throw new Error(`Invalid change, missing ${n} in the change file`)}}(["fileName","selector.id","content.property","creation"],o),[o.content.newValue,o.content.newBinding].every((e=>null==e)))throw new Error("Invalid change, missing new value in the change file");return{type:"saved",kind:"valid",fileName:o.fileName,controlId:o.selector.id,propertyName:o.content.property,value:null!==(t=o.content.newValue)&&void 0!==t?t:o.content.newBinding,timestamp:new Date(o.creation).getTime(),controlName:o.selector.type.split(".").pop()}}catch(e){return o.fileName?{type:"saved",kind:"unknown",fileName:o.fileName}:void console.error(e)}})).filter((e=>!!e)).sort(((e,t)=>e.timestamp-t.timestamp));this.savedChanges=o,e(f({saved:o,pending:[]})),this.options.rta.attachUndoRedoStackModified(this.createOnStackChangeHandler(e))}async deleteChange(e,t,n){const o=this.savedChanges.filter((o=>n?n===o.fileName:o.controlId===e&&o.propertyName===t)).map((e=>fetch("/FioriTools/api/removeChanges",{method:"DELETE",headers:{"Content-Type":"application/json"},body:JSON.stringify({fileName:e.fileName})})));await Promise.all(o).catch(console.error)}createOnStackChangeHandler(e){return async()=>{const t=this.options.rta.getCommandStack(),n=t.getCommands(),o=t.getAllExecutedCommands(),a=n.length-o.length,r=n.map((function(e,t){var n;try{const o=e.getProperty("selector"),r=e.getProperty("changeType");let i="";switch(r){case"propertyChange":i=e.getProperty("newValue");break;case"propertyBindingChange":i=e.getProperty("newBinding")}return{type:"pending",controlId:o.id,propertyName:e.getProperty("propertyName"),isActive:t>=a,value:i,controlName:null!==(n=e.getElement().getMetadata().getName().split(".").pop())&&void 0!==n?n:""}}catch(e){console.error(e)}})).filter((e=>!!e));e(f({saved:this.savedChanges,pending:r}))}}}function J(e,t){const n=e.split(".");let o=t;for(const e of n)o=o[e];return o}function W(e){console.log("Initializing Control Property Editor");const{rta:t}=e,n={getControlById:B,getIcons:$,getComponent:D,getOverlay:H,getClosestOverlayFor:R},a=[];function r(e){a.push(e)}const i=new SelectionService(t,n),c=[i,new ChangeService(e,n,i)];try{const{sendAction:e}=o(window.parent,(async function(e){for(const t of a)try{await t(e)}catch(e){console.error(e)}}));for(const t of c)t.init(e,r);F(t,e);const i=n.getIcons();e(s(i))}catch(e){console.error("Error during initialization of Control Property Editor",e)}}self["ui5-adaptation"]=t})();