@xuda.io/runtime-bundle 1.0.1350 → 1.0.1352

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.
@@ -42766,6 +42766,8 @@ func.index.set_ds_0_proxy = function (SESSION_ID) {
42766
42766
  if (!path.includes(prefix)) continue;
42767
42767
  const clean_path_prop = path.split(prefix)[1]; //[path.split('.')[0] === 'SYS_GLOBAL_OBJ_REFS' ? 2 : 1];
42768
42768
  console.log(clean_path_prop);
42769
+ if (!clean_path_prop.includes('progDataSource')) continue;
42770
+
42769
42771
  const _ref = SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS[ref_id];
42770
42772
  if (!_ref) continue;
42771
42773
  const _ds = _ref.ds;
@@ -42777,7 +42779,7 @@ func.index.set_ds_0_proxy = function (SESSION_ID) {
42777
42779
  const datasource_changes = {
42778
42780
  [_ds.dsSession]: {
42779
42781
  ['datasource_main']: {
42780
- watcher: { path: path.replace(prefix_path + '.', ''), newValue },
42782
+ watcher: { path: clean_path_prop, newValue },
42781
42783
  },
42782
42784
  },
42783
42785
  };
@@ -116,4 +116,4 @@
116
116
 
117
117
  </div>
118
118
 
119
- `);setTimeout(()=>{$(`[name="hard_reload"]`).off("click").on("click",async function(){await func.index.delete_pouch(SESSION_ID);location.reload()});$(`[name="reset_worker"]`).off("click").on("click",function(){_session.WORKER_OBJ.jobs[0].stat=null;_session.WORKER_OBJ.stat=null;func.UI.utils.progressScreen.hide(SESSION_ID)});$(`[name="get_support"]`).off("click").on("click",async function(){const get_support=await func.common.get_module(SESSION_ID,"xuda-get-support-module.esm.js");var name,subject;const prompt_name=()=>{name=window.prompt(`Get support from your ${APP_OBJ[app_id].app_general_prop?.app_name} team, \n\nYour Name (required):`);if(name==="")prompt_name()};const prompt_subject=()=>{subject=window.prompt(`When you click on "Ok," you are granting permission to ${APP_OBJ[app_id]?.app_name} team to access your browser. \n\nSubject (required):`);if(subject==="")prompt_subject()};if(!SUPPORT_PEER){try{name=firebase.auth().currentUser.displayName}catch(error){if(_session?.USR_OBJ?.usr_name){name=_session.USR_OBJ.usr_name}else{prompt_name()}}if(name===null)return;prompt_subject();if(subject===null)return;func.common.db(SESSION_ID,"get_support",{name:name,subject:subject});setTimeout(()=>{$("body").addClass("get_support_request");$("body").remove(".get_support_request_title").append("<div class='get_support_request_title'>Support pending</div>")},2e3)}else{get_support.terminate_peer(SESSION_ID)}func.UI.utils.progressScreen.hide(SESSION_ID)})},1e3)}}};if(event.which===27){let SESSION_ID=Object.keys(SESSION_OBJ)[0];func.UI.utils.progressScreen.hide(SESSION_ID)}if(event.ctrlKey&&event.shiftKey){if(keys[event.which]){keys[event.which].fx()}}});$(document).mousemove(function(e){CLIENT_ACTIVITY_TS=Date.now();posX=e.pageX;posY=e.pageY;if(SESSION_OBJ[SESSION_ID]?.DS_GLB?.[0]){SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system["SYS_GLOBAL_OBJ_CLIENT_INFO"].cursor_pos_x=posX;SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system["SYS_GLOBAL_OBJ_CLIENT_INFO"].cursor_pos_y=posY}});$.fn.draggable=function(){CLIENT_ACTIVITY_TS=Date.now();var $this=this,ns="draggable_"+(Math.random()+"").replace(".",""),mm="mousemove."+ns,mu="mouseup."+ns,$w=$(window),isFixed=$this.css("position")==="fixed",adjX=0,adjY=0;$this.mousedown(function(ev){var pos=$this.offset();if(isFixed){adjX=$w.scrollLeft();adjY=$w.scrollTop()}var ox=ev.pageX-pos.left,oy=ev.pageY-pos.top;$this.data(ns,{x:ox,y:oy});$w.on(mm,function(ev){ev.preventDefault();ev.stopPropagation();if(isFixed){adjX=$w.scrollLeft();adjY=$w.scrollTop()}var offset=$this.data(ns);$this.css({left:ev.pageX-adjX-offset.x,top:ev.pageY-adjY-offset.y})});$w.on(mu,function(){$w.off(mm+" "+mu).removeData(ns)})});return this};var heartbeat_attempts=0;var heartbeat_internal=setInterval(async function(){const SESSION_ID=Object.keys(SESSION_OBJ)[0];if(!SESSION_ID)return;let _session=SESSION_OBJ[SESSION_ID];if(!_session)return;if(_session.crawler)return;const set_idle=async function(stat){var datasource_changes={[0]:{["data_system"]:{SYS_GLOBAL_BOL_IDLE:stat}}};await func.datasource.update(SESSION_ID,datasource_changes)};if(Date.now()-CLIENT_ACTIVITY_TS>3e4){set_idle(1)}else{set_idle(0)}if(_session.engine_mode==="live_preview"||!_session.opt.enable_user_assist){return}const ret=await func.common.db(SESSION_ID,"heartbeat",{stat:Date.now()-CLIENT_ACTIVITY_TS>3e4?1:2}).catch(err=>{heartbeat_attempts++;console.warn(err.message);if(heartbeat_attempts<10)return;clearInterval(heartbeat_internal)});heartbeat_attempts=0;if(ret?.session_stat===3){await func.index.delete_pouch();window.top.location.reload()}$("body").removeClass("get_support_request");$("body").find(".get_support_request_title").remove();$("body").removeClass("get_support_online");$("body").find(".get_support_online_title").remove();if(ret?.data?.peer?.peer_status===1){if(ret.data.peer.peer_regional_server){get_support.init_peer(SESSION_ID,ret.data.peer.peer_regional_server)}$("body").addClass("get_support_request");$("body").remove(".get_support_request_title").append("<div class='get_support_request_title'>Support pending</div>")}if(ret?.data?.peer?.peer_status===2){$("body").addClass("get_support_online");$("body").remove(".get_support_online_title").append("<div class='get_support_online_title'>Support online</div>")}_session.res_token=ret.res_token},3e4);glb.WINDOW_LOCATION_SEARCH=window.location.search};func.index.checkConnectivity=async function(){const endpoints=["https://xuda.io/favicon.ico"];const promises=endpoints.map(url=>fetch(url,{method:"HEAD",mode:"no-cors"}).then(()=>true).catch(()=>false));const results=await Promise.all(promises);IS_ONLINE=results.some(result=>result===true);window.addEventListener("online",function(){IS_ONLINE=true;$("body").trigger("set_db_replication_from_server")});window.addEventListener("offline",function(){IS_ONLINE=false})};func.index.init_service_workers=function(){if("serviceWorker"in navigator){navigator.serviceWorker.addEventListener("message",function(event){console.log("serviceWorker message:",event)});navigator.serviceWorker.register("xuda-sw.js").then(function(registration){console.log("ServiceWorker registration successful with scope: ",registration.scope);glb.sw_registration=registration},function(err){console.log("ServiceWorker registration failed: ",err)})}};func.index.delete_pouch=async function(SESSION_ID=Object.keys(SESSION_OBJ)[0]){const db=await func.utils.connect_pouchdb(SESSION_ID);try{return await db.destroy()}catch(err){console.log(err)}};func.index.new_webworker=async function(SESSION_ID,prog_obj,obj){var worker_id=Object.keys(WEB_WORKER[SESSION_ID]).length+1;var _session=SESSION_OBJ[SESSION_ID];if(!_session.engine_mode==="docker"){ver=APP_OBJ[_session.app_id].app_version}var build_id=["live_preview","miniapp"].includes(_session.engine_mode)?"":_session.opt.app_build_id;if(typeof XUDA_BUILD_ID!=="undefined"){build_id=XUDA_BUILD_ID}const worker_name=`${typeof _session.SLIM_BUNDLE==="undefined"||!_session.SLIM_BUNDLE?"":"Slim "}${prog_obj.menuName} worker`+" "+glb.worker_type+": #"+worker_id.toString()+" "+(build_id||"")+" "+_session.domain;const init_worker_session=function(worker_id){var _session=_.cloneDeep(SESSION_OBJ[SESSION_ID]);delete _session.root_element;const get_parent_ds=function(ds){var ds_obj={};if(ds&&_session.DS_GLB[ds].parentDataSourceNo!==null){ds_obj[ds]=func.utils.clean_returned_datasource(SESSION_ID,ds);_.forEach(get_parent_ds(_session.DS_GLB[ds].parentDataSourceNo),function(val,key){ds_obj[key]=val})}else{ds_obj[ds]=func.utils.clean_returned_datasource(SESSION_ID,ds)}return ds_obj};var ds_obj={};if(typeof obj?.data?.parentDataSourceNoP!=="undefined"){ds_obj=get_parent_ds(obj.data.parentDataSourceNoP)}_session.DS_GLB={};_session.WORKER_OBJ={jobs:[],num:1e3,stat:null};var app_id=_session.app_id;var data={SESSION_ID:SESSION_ID,app_id:app_id,APP_OBJ:APP_OBJ[app_id],PROJECT_OBJ:PROJECT_OBJ[app_id],DOCS_OBJ:DOCS_OBJ[app_id],APP_INFO:glb.APP_INFO[app_id],DEBUG_MODE:glb.DEBUG_MODE,DEBUG_INFO_OBJ:glb.DEBUG_INFO_OBJ,WINDOW_LOCATION_SEARCH:glb.WINDOW_LOCATION_SEARCH,ROOT_ELEMENT_ATTRIBUTES:glb.ROOT_ELEMENT_ATTRIBUTES,DS_GLB:ds_obj,SESSION_INFO:JSON.parse(JSON.stringify(_session)),session_id:SESSION_ID,engine_mode:_session.engine_mode,STUDIO_WEBSOCKET_CONNECTION_ID:STUDIO_WEBSOCKET_CONNECTION_ID};if(_session.engine_mode==="live_preview"){data.DOCS_OBJ=DOCS_OBJ[app_id]}delete data.SESSION_INFO.root_element;data.SESSION_INFO.worker_id=worker_id;var ds_arr=[];$.map(_session.DS_GLB,function(val,i){ds_arr.push(i)});WEB_WORKER[SESSION_ID][worker_id].ds_arr=ds_arr;delete data.SESSION_INFO.DS_UI_EVENTS_GLB;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){WEB_WORKER[SESSION_ID][worker_id].worker.emit("message",{service:"init",data:data,worker_id:worker_id})}else{WEB_WORKER[SESSION_ID][worker_id].worker.postMessage({service:"init",data:JSON.stringify(data),worker_id:worker_id})}};const create_worker=async function(){return new Promise((resolve,reject)=>{if(glb.worker_type==="Dev"){WEB_WORKER[SESSION_ID][worker_id]={worker:new Worker("js/xuda_worker.js",{name:worker_name}),promise_queue:{}}}else{function getWorkerURL(url){const content=`importScripts( "${url}" );`;return URL.createObjectURL(new Blob([content],{type:"text/javascript"}))}const _session=SESSION_OBJ[SESSION_ID];let blob=getWorkerURL(func.common.get_url(SESSION_ID,"dist",func.utils.get_resource_filename(["live_preview","miniapp"].includes(_session.engine_mode)?"":_session?.opt?.app_build_id,"runtime/js/xuda_worker.js")));WEB_WORKER[SESSION_ID][worker_id]={worker:new Worker(blob,{name:worker_name}),promise_queue:{}}}WEB_WORKER[SESSION_ID][worker_id].worker.addEventListener("message",function(e){if(e.data.service==="worker_ready"){return resolve()}worker_functions(e)},false)})};const create_websocket=async function(){return new Promise((resolve,reject)=>{WEB_WORKER[SESSION_ID][worker_id]={worker:RUNTIME_SERVER_WEBSOCKET,promise_queue:{}};WEB_WORKER[SESSION_ID][worker_id].worker.on("message",async e=>{if(["deployment_server","http_call"].includes(e.source))return;worker_functions({data:e})});resolve()})};const worker_functions=async function(e_raw){return new Promise(async(resolve,reject)=>{var e={};e.data=e_raw.data;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){WEBSOCKET_PROCESS_PID=e.data.process_pid}var val=e.data.params;var fx={init_done:async function(){if(!obj){return _resolve()}},alert:function(){if(val[1]==="save_on"){func.UI.utils.save(SESSION_ID,true);return true}if(val[1]==="save_off"){func.UI.utils.save(SESSION_ID,false);return true}func.utils.alerts.execute(SESSION_ID,val[1],val[2],val[3],val[4]);return _resolve()},progress_on:function(){func.UI.utils.progressScreen.show(SESSION_ID,val,null);return _resolve()},progress_off:function(){func.UI.utils.progressScreen.hide();return _resolve()},worker_busy_on:function(){func.UI.utils.indicator.worker.busy();return _resolve()},worker_busy_off:function(){func.UI.utils.indicator.worker.normal();return _resolve()},screen_blocker_on:function(){func.UI.utils.screen_blocker(true,"Worker");return _resolve()},ajax_error:function(){func.utils.request_error(SESSION_ID,"ajax","Session error");return _resolve()},screen_blocker_off:function(){func.UI.utils.screen_blocker(false,"Worker");return _resolve()},job:function(){func.events.add_to_queue(SESSION_ID,val.typeP,val.eventIdP,val.triggerP,val.functionP,val.refIdP,val.containerP,val.elementP,val.rowP,null,val.descP,null,null,val.dsSessionP,null,null,val.event_propertiesP,val.calling_triggerP,val.paramsP,null,null,val.calling_trigger_prop,val.argumentsP,val.source_event_idP,val.calling_job,val.args);return _resolve()},update_client_eventChangesResults_from_worker:async function(){await func.datasource.update(SESSION_ID,val,true);if(!val.worker_id){return}fx.acknowledged_worker_with_eventChangesResults_done(val.dssession,val.worker_id);for await(const[worker_id,ds_arr]of Object.entries(WEB_WORKER[SESSION_ID])){if(val.worker_id==worker_id)continue;await func.index.call_worker(SESSION_ID,{service:"update_datasource_changes_from_client",data:data},{worker_id:worker_id})}},post_datasource:async function(){if(typeof val.dsSessionP==="undefined"||val.dsSessionP===null)return;if(!SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP]){SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP]=val.ds_obj}else{const update_existing_ds_object=function(old_obj,new_obj){for(const[key,val]of Object.entries(new_obj)){if(typeof val!=="object"){old_obj[key]=val2}else{if(!old_obj[key]){old_obj[key]=val}else update_existing_ds_object(old_obj[key],val)}}};update_existing_ds_object(SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP],val.ds_obj)}var verify_set_parent_ds=function(){var dsSession=val.dsSessionP;for(const[key,val]of Object.entries(SESSION_OBJ[SESSION_ID].DS_GLB[dsSession].parent_ds_chain)){if(SESSION_OBJ[SESSION_ID].DS_GLB[val]){SESSION_OBJ[SESSION_ID].DS_GLB[dsSession].parentDataSourceNo=val;break}}};verify_set_parent_ds();if(val.ds_obj.dataSourceSessionGlobal>SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal)SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal=val.ds_obj.dataSourceSessionGlobal},return_to_data_source:function(type,dsSessionP,ds){var data={session_id:SESSION_ID,dssession:dsSessionP,onscreen_events_active:ds.v.onscreen_events_active,viewEventExec_arr:JSON.stringify(ds.viewEventExec_arr),return_to_data_source_type:type};func.index.call_worker(SESSION_ID,{service:"return_to_data_source",data:data})},acknowledged_worker_with_eventChangesResults_done:async function(dsSessionP,worker_id){var data={session_id:SESSION_ID,dssession:dsSessionP};await func.index.call_worker(SESSION_ID,{service:"acknowledged_worker_with_eventChangesResults_done",data:data},{worker_id:worker_id});return _resolve()},execute_onscreen_view_events:async function(){await fx.post_datasource();var ds=SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP];await func.datasource.execute_onscreen_view_events(SESSION_ID,val.dsSessionP,"onscreen events");if(!ds.v.onscreen_events_active)return;var type=ds.v.onscreen_events_active.type;ds.v.onscreen_events_active=null;fx.return_to_data_source(type,val.dsSessionP,ds);return _resolve()},execute_local_db_query:async function(){await fx.post_datasource();const data=await func.db.get_query(SESSION_ID,val.fileIdP,val.queryP,val.dsSessionP,val.viewSourceDescP,val.sourceP,val.reduceP,val.skipP,val.limitP,val.countP,val.idsP);var msg={};msg.worker_id=worker_id;msg.data={};msg.service="return_from_db_query";msg.data.worker_id=worker_id;msg.data.callback_id=val.callback_id;msg.data.session_id=SESSION_ID;msg.data.data=data;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){msg.process_pid=WEBSOCKET_PROCESS_PID;WEB_WORKER[SESSION_ID][worker_id].worker.emit("message",msg)}else{WEB_WORKER[SESSION_ID][worker_id].worker.postMessage(msg)}_resolve()},execute_local_sava_data:async function(){await fx.post_datasource();const data=await func.db.save_data(SESSION_ID,val.dsSessionP,val.keyP);var msg={};msg.worker_id=worker_id;msg.data={};msg.service="return_from_sava_data";msg.data.worker_id=worker_id;msg.data.callback_id=val.callback_id;msg.data.session_id=SESSION_ID;msg.data.data=data;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){msg.process_pid=WEBSOCKET_PROCESS_PID;WEB_WORKER[SESSION_ID][worker_id].worker.emit("message",msg)}else{WEB_WORKER[SESSION_ID][worker_id].worker.postMessage(msg)}_resolve()},write_debug_log:function(params){func.utils.debug.write(SESSION_ID,val.data);_resolve()},write_log:async function(params){if(SESSION_OBJ[SESSION_ID].crawler)return;await func.common.db(SESSION_ID,"write_log",{msg:val.data,source:"runtime",log_type:"error"});_resolve()},change_loaded_image:function(params){const new_image=e.data.params.data;var $img=$("img");$.each($img,function(key,val){var src=$(val).prop("src");if(src.indexOf(new_image)>0){$(val).attr("src",src+"?ts="+(new Date).valueOf())}});_resolve()},send_watch_to_studio_websocket:function(params){STUDIO_WEBSOCKET.emit("message",val);_resolve()},get_doc_from_studio:async function(params){const module=await func.common.get_module(SESSION_ID,`xuda-progs-loader-module.mjs`);const data=await module.get_doc_from_studio(SESSION_ID,SESSION_OBJ[SESSION_ID].app_id,params.params.doc_id);func.index.call_worker(SESSION_ID,{service:"return_doc_from_studio",data:data});_resolve()},get_doc_from_websocket:async function(params){const module=await func.common.get_module(SESSION_ID,`xuda-progs-loader-module.mjs`);const data=await module.get_doc_from_websocket(SESSION_ID,SESSION_OBJ[SESSION_ID].app_id,params.params.doc_id);func.index.call_worker(SESSION_ID,{service:"return_doc_from_websocket",data:data});_resolve()},get_dbs_data_from_websocket:async function(params){const data=await func.common.get_data_from_websocket(SESSION_ID,params.params.service,params.params.data);func.index.call_worker(SESSION_ID,{service:"return_dbs_data_from_websocket",data:{data:data,websocket_queue_num:params.params.websocket_queue_num}});_resolve()},perform_rpi_request_from_studio:async function(params){const data=await func.common.db(SESSION_ID,params.params.service,params.params.data);func.index.call_worker(SESSION_ID,{service:"return_rpi_request_from_studio",data:{data:data.data,table_id:params.params.req_id}});_resolve()},refresh_document_changes_for_realtime_update:async function(params){func.UI.screen.refresh_document_changes_for_realtime_update(SESSION_ID,params.params.doc_change);_resolve()}};const get_promise_queue=function(t,worker_id){if(!WEB_WORKER[SESSION_ID][worker_id]){console.warn("worker job not found");return}return WEB_WORKER[SESSION_ID][worker_id].promise_queue[t]};const promise_ret=await get_promise_queue(e.data.promise_queue_id,e.data.worker_id);const _resolve=function(params){if(!promise_ret)return resolve();promise_ret.resolve(params);setTimeout(function(){if(WEB_WORKER[SESSION_ID][e.data.worker_id])delete WEB_WORKER[SESSION_ID][e.data.worker_id].promise_queue[e.data.promise_queue_id]},1e3)};if(fx[e.data.fx_to_execute]){return await fx[e.data.fx_to_execute](e.data)}if(!promise_ret)return console.error("promise not found");if(!e.data.fx_to_execute){return _resolve(e.data.params)}if(e.data.fx_to_execute==="worker_response"){return _resolve(e.data.params)}})};if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){await create_websocket()}else{await create_worker()}init_worker_session(worker_id);return worker_id};func.index.set_ds_0_proxy=function(SESSION_ID){const _session=SESSION_OBJ[SESSION_ID];let _ds=_session.DS_GLB[0];function createWatchedObject(obj,onChange){const watchers=new WeakMap;function createProxy(target,path=[]){if(watchers.has(target)){return watchers.get(target)}const proxy=new Proxy(target,{set(obj,prop,value){const oldValue=obj[prop];let currentPath=[...path,prop];obj[prop]=value;if(typeof value==="object"&&value!==null){obj[prop]=createProxy(value,currentPath)}if(!_.isEqual(value,oldValue)){currentPath.shift();onChange({path:currentPath.join("."),oldValue:oldValue,newValue:value,type:"set",timestamp:Date.now()})}return true},deleteProperty(obj,prop){const oldValue=obj[prop];const currentPath=[...path,prop];delete obj[prop];onChange({path:currentPath.join("."),oldValue:oldValue,newValue:undefined,type:"delete",timestamp:Date.now()});return true}});for(const[key,value]of Object.entries(target)){if(typeof value==="object"&&value!==null){target[key]=createProxy(value,[...path,key])}}watchers.set(target,proxy);return proxy}return createProxy(obj)}const watchedDs=createWatchedObject({_ref:_ds},async change=>{const{path,newValue,oldValue}=change;try{if(_.isEqual(newValue,oldValue))return;const _session=SESSION_OBJ[SESSION_ID];if(_session?.watchers?.[path]){const fx=_session?.watchers?.[path];fx(change)}const _refs=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS;for(const[ref_id,val]of Object.entries(_refs)){const prefix=`${ref_id}.ds.`;if(!path.includes(prefix))continue;const clean_path_prop=path.split(prefix)[1];console.log(clean_path_prop);const _ref=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS[ref_id];if(!_ref)continue;const _ds=_ref.ds;const target_ds=_session.DS_GLB[_ds.dsSession];const target_value=_.get(target_ds,clean_path_prop);if(target_value===newValue)continue;const datasource_changes={[_ds.dsSession]:{["datasource_main"]:{watcher:{path:path.replace(prefix_path+".",""),newValue:newValue}}}};await func.datasource.update(SESSION_ID,datasource_changes)}return;if(path.split(".")[0]!=="SYS_GLOBAL_OBJ_REFS")return;const ref_id=path.split(".")[1];if(!ref_id)return;const prefix=`SYS_GLOBAL_OBJ_REFS.${ref_id}.ds.`;if(!path.includes(prefix))return;const _ref=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS[ref_id];if(!_ref)return;const _ds=_ref.ds;const clean_path_prop=path.replace(prefix,"");const target_ds=_session.DS_GLB[_ds.dsSession];const target_value=_.get(target_ds,clean_path_prop);if(target_value===newValue)return;const datasource_changes={[_ds.dsSession]:{["datasource_main"]:{watcher:{path:path.replace(prefix_path+".",""),newValue:newValue}}}};await func.datasource.update(SESSION_ID,datasource_changes);return}catch(error){}});_session.DS_GLB[0]=watchedDs._ref};glb.CODE_BUNDLE=1;
119
+ `);setTimeout(()=>{$(`[name="hard_reload"]`).off("click").on("click",async function(){await func.index.delete_pouch(SESSION_ID);location.reload()});$(`[name="reset_worker"]`).off("click").on("click",function(){_session.WORKER_OBJ.jobs[0].stat=null;_session.WORKER_OBJ.stat=null;func.UI.utils.progressScreen.hide(SESSION_ID)});$(`[name="get_support"]`).off("click").on("click",async function(){const get_support=await func.common.get_module(SESSION_ID,"xuda-get-support-module.esm.js");var name,subject;const prompt_name=()=>{name=window.prompt(`Get support from your ${APP_OBJ[app_id].app_general_prop?.app_name} team, \n\nYour Name (required):`);if(name==="")prompt_name()};const prompt_subject=()=>{subject=window.prompt(`When you click on "Ok," you are granting permission to ${APP_OBJ[app_id]?.app_name} team to access your browser. \n\nSubject (required):`);if(subject==="")prompt_subject()};if(!SUPPORT_PEER){try{name=firebase.auth().currentUser.displayName}catch(error){if(_session?.USR_OBJ?.usr_name){name=_session.USR_OBJ.usr_name}else{prompt_name()}}if(name===null)return;prompt_subject();if(subject===null)return;func.common.db(SESSION_ID,"get_support",{name:name,subject:subject});setTimeout(()=>{$("body").addClass("get_support_request");$("body").remove(".get_support_request_title").append("<div class='get_support_request_title'>Support pending</div>")},2e3)}else{get_support.terminate_peer(SESSION_ID)}func.UI.utils.progressScreen.hide(SESSION_ID)})},1e3)}}};if(event.which===27){let SESSION_ID=Object.keys(SESSION_OBJ)[0];func.UI.utils.progressScreen.hide(SESSION_ID)}if(event.ctrlKey&&event.shiftKey){if(keys[event.which]){keys[event.which].fx()}}});$(document).mousemove(function(e){CLIENT_ACTIVITY_TS=Date.now();posX=e.pageX;posY=e.pageY;if(SESSION_OBJ[SESSION_ID]?.DS_GLB?.[0]){SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system["SYS_GLOBAL_OBJ_CLIENT_INFO"].cursor_pos_x=posX;SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system["SYS_GLOBAL_OBJ_CLIENT_INFO"].cursor_pos_y=posY}});$.fn.draggable=function(){CLIENT_ACTIVITY_TS=Date.now();var $this=this,ns="draggable_"+(Math.random()+"").replace(".",""),mm="mousemove."+ns,mu="mouseup."+ns,$w=$(window),isFixed=$this.css("position")==="fixed",adjX=0,adjY=0;$this.mousedown(function(ev){var pos=$this.offset();if(isFixed){adjX=$w.scrollLeft();adjY=$w.scrollTop()}var ox=ev.pageX-pos.left,oy=ev.pageY-pos.top;$this.data(ns,{x:ox,y:oy});$w.on(mm,function(ev){ev.preventDefault();ev.stopPropagation();if(isFixed){adjX=$w.scrollLeft();adjY=$w.scrollTop()}var offset=$this.data(ns);$this.css({left:ev.pageX-adjX-offset.x,top:ev.pageY-adjY-offset.y})});$w.on(mu,function(){$w.off(mm+" "+mu).removeData(ns)})});return this};var heartbeat_attempts=0;var heartbeat_internal=setInterval(async function(){const SESSION_ID=Object.keys(SESSION_OBJ)[0];if(!SESSION_ID)return;let _session=SESSION_OBJ[SESSION_ID];if(!_session)return;if(_session.crawler)return;const set_idle=async function(stat){var datasource_changes={[0]:{["data_system"]:{SYS_GLOBAL_BOL_IDLE:stat}}};await func.datasource.update(SESSION_ID,datasource_changes)};if(Date.now()-CLIENT_ACTIVITY_TS>3e4){set_idle(1)}else{set_idle(0)}if(_session.engine_mode==="live_preview"||!_session.opt.enable_user_assist){return}const ret=await func.common.db(SESSION_ID,"heartbeat",{stat:Date.now()-CLIENT_ACTIVITY_TS>3e4?1:2}).catch(err=>{heartbeat_attempts++;console.warn(err.message);if(heartbeat_attempts<10)return;clearInterval(heartbeat_internal)});heartbeat_attempts=0;if(ret?.session_stat===3){await func.index.delete_pouch();window.top.location.reload()}$("body").removeClass("get_support_request");$("body").find(".get_support_request_title").remove();$("body").removeClass("get_support_online");$("body").find(".get_support_online_title").remove();if(ret?.data?.peer?.peer_status===1){if(ret.data.peer.peer_regional_server){get_support.init_peer(SESSION_ID,ret.data.peer.peer_regional_server)}$("body").addClass("get_support_request");$("body").remove(".get_support_request_title").append("<div class='get_support_request_title'>Support pending</div>")}if(ret?.data?.peer?.peer_status===2){$("body").addClass("get_support_online");$("body").remove(".get_support_online_title").append("<div class='get_support_online_title'>Support online</div>")}_session.res_token=ret.res_token},3e4);glb.WINDOW_LOCATION_SEARCH=window.location.search};func.index.checkConnectivity=async function(){const endpoints=["https://xuda.io/favicon.ico"];const promises=endpoints.map(url=>fetch(url,{method:"HEAD",mode:"no-cors"}).then(()=>true).catch(()=>false));const results=await Promise.all(promises);IS_ONLINE=results.some(result=>result===true);window.addEventListener("online",function(){IS_ONLINE=true;$("body").trigger("set_db_replication_from_server")});window.addEventListener("offline",function(){IS_ONLINE=false})};func.index.init_service_workers=function(){if("serviceWorker"in navigator){navigator.serviceWorker.addEventListener("message",function(event){console.log("serviceWorker message:",event)});navigator.serviceWorker.register("xuda-sw.js").then(function(registration){console.log("ServiceWorker registration successful with scope: ",registration.scope);glb.sw_registration=registration},function(err){console.log("ServiceWorker registration failed: ",err)})}};func.index.delete_pouch=async function(SESSION_ID=Object.keys(SESSION_OBJ)[0]){const db=await func.utils.connect_pouchdb(SESSION_ID);try{return await db.destroy()}catch(err){console.log(err)}};func.index.new_webworker=async function(SESSION_ID,prog_obj,obj){var worker_id=Object.keys(WEB_WORKER[SESSION_ID]).length+1;var _session=SESSION_OBJ[SESSION_ID];if(!_session.engine_mode==="docker"){ver=APP_OBJ[_session.app_id].app_version}var build_id=["live_preview","miniapp"].includes(_session.engine_mode)?"":_session.opt.app_build_id;if(typeof XUDA_BUILD_ID!=="undefined"){build_id=XUDA_BUILD_ID}const worker_name=`${typeof _session.SLIM_BUNDLE==="undefined"||!_session.SLIM_BUNDLE?"":"Slim "}${prog_obj.menuName} worker`+" "+glb.worker_type+": #"+worker_id.toString()+" "+(build_id||"")+" "+_session.domain;const init_worker_session=function(worker_id){var _session=_.cloneDeep(SESSION_OBJ[SESSION_ID]);delete _session.root_element;const get_parent_ds=function(ds){var ds_obj={};if(ds&&_session.DS_GLB[ds].parentDataSourceNo!==null){ds_obj[ds]=func.utils.clean_returned_datasource(SESSION_ID,ds);_.forEach(get_parent_ds(_session.DS_GLB[ds].parentDataSourceNo),function(val,key){ds_obj[key]=val})}else{ds_obj[ds]=func.utils.clean_returned_datasource(SESSION_ID,ds)}return ds_obj};var ds_obj={};if(typeof obj?.data?.parentDataSourceNoP!=="undefined"){ds_obj=get_parent_ds(obj.data.parentDataSourceNoP)}_session.DS_GLB={};_session.WORKER_OBJ={jobs:[],num:1e3,stat:null};var app_id=_session.app_id;var data={SESSION_ID:SESSION_ID,app_id:app_id,APP_OBJ:APP_OBJ[app_id],PROJECT_OBJ:PROJECT_OBJ[app_id],DOCS_OBJ:DOCS_OBJ[app_id],APP_INFO:glb.APP_INFO[app_id],DEBUG_MODE:glb.DEBUG_MODE,DEBUG_INFO_OBJ:glb.DEBUG_INFO_OBJ,WINDOW_LOCATION_SEARCH:glb.WINDOW_LOCATION_SEARCH,ROOT_ELEMENT_ATTRIBUTES:glb.ROOT_ELEMENT_ATTRIBUTES,DS_GLB:ds_obj,SESSION_INFO:JSON.parse(JSON.stringify(_session)),session_id:SESSION_ID,engine_mode:_session.engine_mode,STUDIO_WEBSOCKET_CONNECTION_ID:STUDIO_WEBSOCKET_CONNECTION_ID};if(_session.engine_mode==="live_preview"){data.DOCS_OBJ=DOCS_OBJ[app_id]}delete data.SESSION_INFO.root_element;data.SESSION_INFO.worker_id=worker_id;var ds_arr=[];$.map(_session.DS_GLB,function(val,i){ds_arr.push(i)});WEB_WORKER[SESSION_ID][worker_id].ds_arr=ds_arr;delete data.SESSION_INFO.DS_UI_EVENTS_GLB;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){WEB_WORKER[SESSION_ID][worker_id].worker.emit("message",{service:"init",data:data,worker_id:worker_id})}else{WEB_WORKER[SESSION_ID][worker_id].worker.postMessage({service:"init",data:JSON.stringify(data),worker_id:worker_id})}};const create_worker=async function(){return new Promise((resolve,reject)=>{if(glb.worker_type==="Dev"){WEB_WORKER[SESSION_ID][worker_id]={worker:new Worker("js/xuda_worker.js",{name:worker_name}),promise_queue:{}}}else{function getWorkerURL(url){const content=`importScripts( "${url}" );`;return URL.createObjectURL(new Blob([content],{type:"text/javascript"}))}const _session=SESSION_OBJ[SESSION_ID];let blob=getWorkerURL(func.common.get_url(SESSION_ID,"dist",func.utils.get_resource_filename(["live_preview","miniapp"].includes(_session.engine_mode)?"":_session?.opt?.app_build_id,"runtime/js/xuda_worker.js")));WEB_WORKER[SESSION_ID][worker_id]={worker:new Worker(blob,{name:worker_name}),promise_queue:{}}}WEB_WORKER[SESSION_ID][worker_id].worker.addEventListener("message",function(e){if(e.data.service==="worker_ready"){return resolve()}worker_functions(e)},false)})};const create_websocket=async function(){return new Promise((resolve,reject)=>{WEB_WORKER[SESSION_ID][worker_id]={worker:RUNTIME_SERVER_WEBSOCKET,promise_queue:{}};WEB_WORKER[SESSION_ID][worker_id].worker.on("message",async e=>{if(["deployment_server","http_call"].includes(e.source))return;worker_functions({data:e})});resolve()})};const worker_functions=async function(e_raw){return new Promise(async(resolve,reject)=>{var e={};e.data=e_raw.data;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){WEBSOCKET_PROCESS_PID=e.data.process_pid}var val=e.data.params;var fx={init_done:async function(){if(!obj){return _resolve()}},alert:function(){if(val[1]==="save_on"){func.UI.utils.save(SESSION_ID,true);return true}if(val[1]==="save_off"){func.UI.utils.save(SESSION_ID,false);return true}func.utils.alerts.execute(SESSION_ID,val[1],val[2],val[3],val[4]);return _resolve()},progress_on:function(){func.UI.utils.progressScreen.show(SESSION_ID,val,null);return _resolve()},progress_off:function(){func.UI.utils.progressScreen.hide();return _resolve()},worker_busy_on:function(){func.UI.utils.indicator.worker.busy();return _resolve()},worker_busy_off:function(){func.UI.utils.indicator.worker.normal();return _resolve()},screen_blocker_on:function(){func.UI.utils.screen_blocker(true,"Worker");return _resolve()},ajax_error:function(){func.utils.request_error(SESSION_ID,"ajax","Session error");return _resolve()},screen_blocker_off:function(){func.UI.utils.screen_blocker(false,"Worker");return _resolve()},job:function(){func.events.add_to_queue(SESSION_ID,val.typeP,val.eventIdP,val.triggerP,val.functionP,val.refIdP,val.containerP,val.elementP,val.rowP,null,val.descP,null,null,val.dsSessionP,null,null,val.event_propertiesP,val.calling_triggerP,val.paramsP,null,null,val.calling_trigger_prop,val.argumentsP,val.source_event_idP,val.calling_job,val.args);return _resolve()},update_client_eventChangesResults_from_worker:async function(){await func.datasource.update(SESSION_ID,val,true);if(!val.worker_id){return}fx.acknowledged_worker_with_eventChangesResults_done(val.dssession,val.worker_id);for await(const[worker_id,ds_arr]of Object.entries(WEB_WORKER[SESSION_ID])){if(val.worker_id==worker_id)continue;await func.index.call_worker(SESSION_ID,{service:"update_datasource_changes_from_client",data:data},{worker_id:worker_id})}},post_datasource:async function(){if(typeof val.dsSessionP==="undefined"||val.dsSessionP===null)return;if(!SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP]){SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP]=val.ds_obj}else{const update_existing_ds_object=function(old_obj,new_obj){for(const[key,val]of Object.entries(new_obj)){if(typeof val!=="object"){old_obj[key]=val2}else{if(!old_obj[key]){old_obj[key]=val}else update_existing_ds_object(old_obj[key],val)}}};update_existing_ds_object(SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP],val.ds_obj)}var verify_set_parent_ds=function(){var dsSession=val.dsSessionP;for(const[key,val]of Object.entries(SESSION_OBJ[SESSION_ID].DS_GLB[dsSession].parent_ds_chain)){if(SESSION_OBJ[SESSION_ID].DS_GLB[val]){SESSION_OBJ[SESSION_ID].DS_GLB[dsSession].parentDataSourceNo=val;break}}};verify_set_parent_ds();if(val.ds_obj.dataSourceSessionGlobal>SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal)SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal=val.ds_obj.dataSourceSessionGlobal},return_to_data_source:function(type,dsSessionP,ds){var data={session_id:SESSION_ID,dssession:dsSessionP,onscreen_events_active:ds.v.onscreen_events_active,viewEventExec_arr:JSON.stringify(ds.viewEventExec_arr),return_to_data_source_type:type};func.index.call_worker(SESSION_ID,{service:"return_to_data_source",data:data})},acknowledged_worker_with_eventChangesResults_done:async function(dsSessionP,worker_id){var data={session_id:SESSION_ID,dssession:dsSessionP};await func.index.call_worker(SESSION_ID,{service:"acknowledged_worker_with_eventChangesResults_done",data:data},{worker_id:worker_id});return _resolve()},execute_onscreen_view_events:async function(){await fx.post_datasource();var ds=SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP];await func.datasource.execute_onscreen_view_events(SESSION_ID,val.dsSessionP,"onscreen events");if(!ds.v.onscreen_events_active)return;var type=ds.v.onscreen_events_active.type;ds.v.onscreen_events_active=null;fx.return_to_data_source(type,val.dsSessionP,ds);return _resolve()},execute_local_db_query:async function(){await fx.post_datasource();const data=await func.db.get_query(SESSION_ID,val.fileIdP,val.queryP,val.dsSessionP,val.viewSourceDescP,val.sourceP,val.reduceP,val.skipP,val.limitP,val.countP,val.idsP);var msg={};msg.worker_id=worker_id;msg.data={};msg.service="return_from_db_query";msg.data.worker_id=worker_id;msg.data.callback_id=val.callback_id;msg.data.session_id=SESSION_ID;msg.data.data=data;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){msg.process_pid=WEBSOCKET_PROCESS_PID;WEB_WORKER[SESSION_ID][worker_id].worker.emit("message",msg)}else{WEB_WORKER[SESSION_ID][worker_id].worker.postMessage(msg)}_resolve()},execute_local_sava_data:async function(){await fx.post_datasource();const data=await func.db.save_data(SESSION_ID,val.dsSessionP,val.keyP);var msg={};msg.worker_id=worker_id;msg.data={};msg.service="return_from_sava_data";msg.data.worker_id=worker_id;msg.data.callback_id=val.callback_id;msg.data.session_id=SESSION_ID;msg.data.data=data;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){msg.process_pid=WEBSOCKET_PROCESS_PID;WEB_WORKER[SESSION_ID][worker_id].worker.emit("message",msg)}else{WEB_WORKER[SESSION_ID][worker_id].worker.postMessage(msg)}_resolve()},write_debug_log:function(params){func.utils.debug.write(SESSION_ID,val.data);_resolve()},write_log:async function(params){if(SESSION_OBJ[SESSION_ID].crawler)return;await func.common.db(SESSION_ID,"write_log",{msg:val.data,source:"runtime",log_type:"error"});_resolve()},change_loaded_image:function(params){const new_image=e.data.params.data;var $img=$("img");$.each($img,function(key,val){var src=$(val).prop("src");if(src.indexOf(new_image)>0){$(val).attr("src",src+"?ts="+(new Date).valueOf())}});_resolve()},send_watch_to_studio_websocket:function(params){STUDIO_WEBSOCKET.emit("message",val);_resolve()},get_doc_from_studio:async function(params){const module=await func.common.get_module(SESSION_ID,`xuda-progs-loader-module.mjs`);const data=await module.get_doc_from_studio(SESSION_ID,SESSION_OBJ[SESSION_ID].app_id,params.params.doc_id);func.index.call_worker(SESSION_ID,{service:"return_doc_from_studio",data:data});_resolve()},get_doc_from_websocket:async function(params){const module=await func.common.get_module(SESSION_ID,`xuda-progs-loader-module.mjs`);const data=await module.get_doc_from_websocket(SESSION_ID,SESSION_OBJ[SESSION_ID].app_id,params.params.doc_id);func.index.call_worker(SESSION_ID,{service:"return_doc_from_websocket",data:data});_resolve()},get_dbs_data_from_websocket:async function(params){const data=await func.common.get_data_from_websocket(SESSION_ID,params.params.service,params.params.data);func.index.call_worker(SESSION_ID,{service:"return_dbs_data_from_websocket",data:{data:data,websocket_queue_num:params.params.websocket_queue_num}});_resolve()},perform_rpi_request_from_studio:async function(params){const data=await func.common.db(SESSION_ID,params.params.service,params.params.data);func.index.call_worker(SESSION_ID,{service:"return_rpi_request_from_studio",data:{data:data.data,table_id:params.params.req_id}});_resolve()},refresh_document_changes_for_realtime_update:async function(params){func.UI.screen.refresh_document_changes_for_realtime_update(SESSION_ID,params.params.doc_change);_resolve()}};const get_promise_queue=function(t,worker_id){if(!WEB_WORKER[SESSION_ID][worker_id]){console.warn("worker job not found");return}return WEB_WORKER[SESSION_ID][worker_id].promise_queue[t]};const promise_ret=await get_promise_queue(e.data.promise_queue_id,e.data.worker_id);const _resolve=function(params){if(!promise_ret)return resolve();promise_ret.resolve(params);setTimeout(function(){if(WEB_WORKER[SESSION_ID][e.data.worker_id])delete WEB_WORKER[SESSION_ID][e.data.worker_id].promise_queue[e.data.promise_queue_id]},1e3)};if(fx[e.data.fx_to_execute]){return await fx[e.data.fx_to_execute](e.data)}if(!promise_ret)return console.error("promise not found");if(!e.data.fx_to_execute){return _resolve(e.data.params)}if(e.data.fx_to_execute==="worker_response"){return _resolve(e.data.params)}})};if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){await create_websocket()}else{await create_worker()}init_worker_session(worker_id);return worker_id};func.index.set_ds_0_proxy=function(SESSION_ID){const _session=SESSION_OBJ[SESSION_ID];let _ds=_session.DS_GLB[0];function createWatchedObject(obj,onChange){const watchers=new WeakMap;function createProxy(target,path=[]){if(watchers.has(target)){return watchers.get(target)}const proxy=new Proxy(target,{set(obj,prop,value){const oldValue=obj[prop];let currentPath=[...path,prop];obj[prop]=value;if(typeof value==="object"&&value!==null){obj[prop]=createProxy(value,currentPath)}if(!_.isEqual(value,oldValue)){currentPath.shift();onChange({path:currentPath.join("."),oldValue:oldValue,newValue:value,type:"set",timestamp:Date.now()})}return true},deleteProperty(obj,prop){const oldValue=obj[prop];const currentPath=[...path,prop];delete obj[prop];onChange({path:currentPath.join("."),oldValue:oldValue,newValue:undefined,type:"delete",timestamp:Date.now()});return true}});for(const[key,value]of Object.entries(target)){if(typeof value==="object"&&value!==null){target[key]=createProxy(value,[...path,key])}}watchers.set(target,proxy);return proxy}return createProxy(obj)}const watchedDs=createWatchedObject({_ref:_ds},async change=>{const{path,newValue,oldValue}=change;try{if(_.isEqual(newValue,oldValue))return;const _session=SESSION_OBJ[SESSION_ID];if(_session?.watchers?.[path]){const fx=_session?.watchers?.[path];fx(change)}const _refs=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS;for(const[ref_id,val]of Object.entries(_refs)){const prefix=`${ref_id}.ds.`;if(!path.includes(prefix))continue;const clean_path_prop=path.split(prefix)[1];console.log(clean_path_prop);if(!clean_path_prop.includes("progDataSource"))continue;const _ref=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS[ref_id];if(!_ref)continue;const _ds=_ref.ds;const target_ds=_session.DS_GLB[_ds.dsSession];const target_value=_.get(target_ds,clean_path_prop);if(target_value===newValue)continue;const datasource_changes={[_ds.dsSession]:{["datasource_main"]:{watcher:{path:clean_path_prop,newValue:newValue}}}};await func.datasource.update(SESSION_ID,datasource_changes)}return;if(path.split(".")[0]!=="SYS_GLOBAL_OBJ_REFS")return;const ref_id=path.split(".")[1];if(!ref_id)return;const prefix=`SYS_GLOBAL_OBJ_REFS.${ref_id}.ds.`;if(!path.includes(prefix))return;const _ref=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS[ref_id];if(!_ref)return;const _ds=_ref.ds;const clean_path_prop=path.replace(prefix,"");const target_ds=_session.DS_GLB[_ds.dsSession];const target_value=_.get(target_ds,clean_path_prop);if(target_value===newValue)return;const datasource_changes={[_ds.dsSession]:{["datasource_main"]:{watcher:{path:path.replace(prefix_path+".",""),newValue:newValue}}}};await func.datasource.update(SESSION_ID,datasource_changes);return}catch(error){}});_session.DS_GLB[0]=watchedDs._ref};glb.CODE_BUNDLE=1;
@@ -20279,6 +20279,8 @@ func.index.set_ds_0_proxy = function (SESSION_ID) {
20279
20279
  if (!path.includes(prefix)) continue;
20280
20280
  const clean_path_prop = path.split(prefix)[1]; //[path.split('.')[0] === 'SYS_GLOBAL_OBJ_REFS' ? 2 : 1];
20281
20281
  console.log(clean_path_prop);
20282
+ if (!clean_path_prop.includes('progDataSource')) continue;
20283
+
20282
20284
  const _ref = SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS[ref_id];
20283
20285
  if (!_ref) continue;
20284
20286
  const _ds = _ref.ds;
@@ -20290,7 +20292,7 @@ func.index.set_ds_0_proxy = function (SESSION_ID) {
20290
20292
  const datasource_changes = {
20291
20293
  [_ds.dsSession]: {
20292
20294
  ['datasource_main']: {
20293
- watcher: { path: path.replace(prefix_path + '.', ''), newValue },
20295
+ watcher: { path: clean_path_prop, newValue },
20294
20296
  },
20295
20297
  },
20296
20298
  };
@@ -20280,6 +20280,8 @@ func.index.set_ds_0_proxy = function (SESSION_ID) {
20280
20280
  if (!path.includes(prefix)) continue;
20281
20281
  const clean_path_prop = path.split(prefix)[1]; //[path.split('.')[0] === 'SYS_GLOBAL_OBJ_REFS' ? 2 : 1];
20282
20282
  console.log(clean_path_prop);
20283
+ if (!clean_path_prop.includes('progDataSource')) continue;
20284
+
20283
20285
  const _ref = SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS[ref_id];
20284
20286
  if (!_ref) continue;
20285
20287
  const _ds = _ref.ds;
@@ -20291,7 +20293,7 @@ func.index.set_ds_0_proxy = function (SESSION_ID) {
20291
20293
  const datasource_changes = {
20292
20294
  [_ds.dsSession]: {
20293
20295
  ['datasource_main']: {
20294
- watcher: { path: path.replace(prefix_path + '.', ''), newValue },
20296
+ watcher: { path: clean_path_prop, newValue },
20295
20297
  },
20296
20298
  },
20297
20299
  };
@@ -110,4 +110,4 @@
110
110
 
111
111
  </div>
112
112
 
113
- `);setTimeout(()=>{$(`[name="hard_reload"]`).off("click").on("click",async function(){await func.index.delete_pouch(SESSION_ID);location.reload()});$(`[name="reset_worker"]`).off("click").on("click",function(){_session.WORKER_OBJ.jobs[0].stat=null;_session.WORKER_OBJ.stat=null;func.UI.utils.progressScreen.hide(SESSION_ID)});$(`[name="get_support"]`).off("click").on("click",async function(){const get_support=await func.common.get_module(SESSION_ID,"xuda-get-support-module.esm.js");var name,subject;const prompt_name=()=>{name=window.prompt(`Get support from your ${APP_OBJ[app_id].app_general_prop?.app_name} team, \n\nYour Name (required):`);if(name==="")prompt_name()};const prompt_subject=()=>{subject=window.prompt(`When you click on "Ok," you are granting permission to ${APP_OBJ[app_id]?.app_name} team to access your browser. \n\nSubject (required):`);if(subject==="")prompt_subject()};if(!SUPPORT_PEER){try{name=firebase.auth().currentUser.displayName}catch(error){if(_session?.USR_OBJ?.usr_name){name=_session.USR_OBJ.usr_name}else{prompt_name()}}if(name===null)return;prompt_subject();if(subject===null)return;func.common.db(SESSION_ID,"get_support",{name:name,subject:subject});setTimeout(()=>{$("body").addClass("get_support_request");$("body").remove(".get_support_request_title").append("<div class='get_support_request_title'>Support pending</div>")},2e3)}else{get_support.terminate_peer(SESSION_ID)}func.UI.utils.progressScreen.hide(SESSION_ID)})},1e3)}}};if(event.which===27){let SESSION_ID=Object.keys(SESSION_OBJ)[0];func.UI.utils.progressScreen.hide(SESSION_ID)}if(event.ctrlKey&&event.shiftKey){if(keys[event.which]){keys[event.which].fx()}}});$(document).mousemove(function(e){CLIENT_ACTIVITY_TS=Date.now();posX=e.pageX;posY=e.pageY;if(SESSION_OBJ[SESSION_ID]?.DS_GLB?.[0]){SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system["SYS_GLOBAL_OBJ_CLIENT_INFO"].cursor_pos_x=posX;SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system["SYS_GLOBAL_OBJ_CLIENT_INFO"].cursor_pos_y=posY}});$.fn.draggable=function(){CLIENT_ACTIVITY_TS=Date.now();var $this=this,ns="draggable_"+(Math.random()+"").replace(".",""),mm="mousemove."+ns,mu="mouseup."+ns,$w=$(window),isFixed=$this.css("position")==="fixed",adjX=0,adjY=0;$this.mousedown(function(ev){var pos=$this.offset();if(isFixed){adjX=$w.scrollLeft();adjY=$w.scrollTop()}var ox=ev.pageX-pos.left,oy=ev.pageY-pos.top;$this.data(ns,{x:ox,y:oy});$w.on(mm,function(ev){ev.preventDefault();ev.stopPropagation();if(isFixed){adjX=$w.scrollLeft();adjY=$w.scrollTop()}var offset=$this.data(ns);$this.css({left:ev.pageX-adjX-offset.x,top:ev.pageY-adjY-offset.y})});$w.on(mu,function(){$w.off(mm+" "+mu).removeData(ns)})});return this};var heartbeat_attempts=0;var heartbeat_internal=setInterval(async function(){const SESSION_ID=Object.keys(SESSION_OBJ)[0];if(!SESSION_ID)return;let _session=SESSION_OBJ[SESSION_ID];if(!_session)return;if(_session.crawler)return;const set_idle=async function(stat){var datasource_changes={[0]:{["data_system"]:{SYS_GLOBAL_BOL_IDLE:stat}}};await func.datasource.update(SESSION_ID,datasource_changes)};if(Date.now()-CLIENT_ACTIVITY_TS>3e4){set_idle(1)}else{set_idle(0)}if(_session.engine_mode==="live_preview"||!_session.opt.enable_user_assist){return}const ret=await func.common.db(SESSION_ID,"heartbeat",{stat:Date.now()-CLIENT_ACTIVITY_TS>3e4?1:2}).catch(err=>{heartbeat_attempts++;console.warn(err.message);if(heartbeat_attempts<10)return;clearInterval(heartbeat_internal)});heartbeat_attempts=0;if(ret?.session_stat===3){await func.index.delete_pouch();window.top.location.reload()}$("body").removeClass("get_support_request");$("body").find(".get_support_request_title").remove();$("body").removeClass("get_support_online");$("body").find(".get_support_online_title").remove();if(ret?.data?.peer?.peer_status===1){if(ret.data.peer.peer_regional_server){get_support.init_peer(SESSION_ID,ret.data.peer.peer_regional_server)}$("body").addClass("get_support_request");$("body").remove(".get_support_request_title").append("<div class='get_support_request_title'>Support pending</div>")}if(ret?.data?.peer?.peer_status===2){$("body").addClass("get_support_online");$("body").remove(".get_support_online_title").append("<div class='get_support_online_title'>Support online</div>")}_session.res_token=ret.res_token},3e4);glb.WINDOW_LOCATION_SEARCH=window.location.search};func.index.checkConnectivity=async function(){const endpoints=["https://xuda.io/favicon.ico"];const promises=endpoints.map(url=>fetch(url,{method:"HEAD",mode:"no-cors"}).then(()=>true).catch(()=>false));const results=await Promise.all(promises);IS_ONLINE=results.some(result=>result===true);window.addEventListener("online",function(){IS_ONLINE=true;$("body").trigger("set_db_replication_from_server")});window.addEventListener("offline",function(){IS_ONLINE=false})};func.index.init_service_workers=function(){if("serviceWorker"in navigator){navigator.serviceWorker.addEventListener("message",function(event){console.log("serviceWorker message:",event)});navigator.serviceWorker.register("xuda-sw.js").then(function(registration){console.log("ServiceWorker registration successful with scope: ",registration.scope);glb.sw_registration=registration},function(err){console.log("ServiceWorker registration failed: ",err)})}};func.index.delete_pouch=async function(SESSION_ID=Object.keys(SESSION_OBJ)[0]){const db=await func.utils.connect_pouchdb(SESSION_ID);try{return await db.destroy()}catch(err){console.log(err)}};func.index.new_webworker=async function(SESSION_ID,prog_obj,obj){var worker_id=Object.keys(WEB_WORKER[SESSION_ID]).length+1;var _session=SESSION_OBJ[SESSION_ID];if(!_session.engine_mode==="docker"){ver=APP_OBJ[_session.app_id].app_version}var build_id=["live_preview","miniapp"].includes(_session.engine_mode)?"":_session.opt.app_build_id;if(typeof XUDA_BUILD_ID!=="undefined"){build_id=XUDA_BUILD_ID}const worker_name=`${typeof _session.SLIM_BUNDLE==="undefined"||!_session.SLIM_BUNDLE?"":"Slim "}${prog_obj.menuName} worker`+" "+glb.worker_type+": #"+worker_id.toString()+" "+(build_id||"")+" "+_session.domain;const init_worker_session=function(worker_id){var _session=_.cloneDeep(SESSION_OBJ[SESSION_ID]);delete _session.root_element;const get_parent_ds=function(ds){var ds_obj={};if(ds&&_session.DS_GLB[ds].parentDataSourceNo!==null){ds_obj[ds]=func.utils.clean_returned_datasource(SESSION_ID,ds);_.forEach(get_parent_ds(_session.DS_GLB[ds].parentDataSourceNo),function(val,key){ds_obj[key]=val})}else{ds_obj[ds]=func.utils.clean_returned_datasource(SESSION_ID,ds)}return ds_obj};var ds_obj={};if(typeof obj?.data?.parentDataSourceNoP!=="undefined"){ds_obj=get_parent_ds(obj.data.parentDataSourceNoP)}_session.DS_GLB={};_session.WORKER_OBJ={jobs:[],num:1e3,stat:null};var app_id=_session.app_id;var data={SESSION_ID:SESSION_ID,app_id:app_id,APP_OBJ:APP_OBJ[app_id],PROJECT_OBJ:PROJECT_OBJ[app_id],DOCS_OBJ:DOCS_OBJ[app_id],APP_INFO:glb.APP_INFO[app_id],DEBUG_MODE:glb.DEBUG_MODE,DEBUG_INFO_OBJ:glb.DEBUG_INFO_OBJ,WINDOW_LOCATION_SEARCH:glb.WINDOW_LOCATION_SEARCH,ROOT_ELEMENT_ATTRIBUTES:glb.ROOT_ELEMENT_ATTRIBUTES,DS_GLB:ds_obj,SESSION_INFO:JSON.parse(JSON.stringify(_session)),session_id:SESSION_ID,engine_mode:_session.engine_mode,STUDIO_WEBSOCKET_CONNECTION_ID:STUDIO_WEBSOCKET_CONNECTION_ID};if(_session.engine_mode==="live_preview"){data.DOCS_OBJ=DOCS_OBJ[app_id]}delete data.SESSION_INFO.root_element;data.SESSION_INFO.worker_id=worker_id;var ds_arr=[];$.map(_session.DS_GLB,function(val,i){ds_arr.push(i)});WEB_WORKER[SESSION_ID][worker_id].ds_arr=ds_arr;delete data.SESSION_INFO.DS_UI_EVENTS_GLB;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){WEB_WORKER[SESSION_ID][worker_id].worker.emit("message",{service:"init",data:data,worker_id:worker_id})}else{WEB_WORKER[SESSION_ID][worker_id].worker.postMessage({service:"init",data:JSON.stringify(data),worker_id:worker_id})}};const create_worker=async function(){return new Promise((resolve,reject)=>{if(glb.worker_type==="Dev"){WEB_WORKER[SESSION_ID][worker_id]={worker:new Worker("js/xuda_worker.js",{name:worker_name}),promise_queue:{}}}else{function getWorkerURL(url){const content=`importScripts( "${url}" );`;return URL.createObjectURL(new Blob([content],{type:"text/javascript"}))}const _session=SESSION_OBJ[SESSION_ID];let blob=getWorkerURL(func.common.get_url(SESSION_ID,"dist",func.utils.get_resource_filename(["live_preview","miniapp"].includes(_session.engine_mode)?"":_session?.opt?.app_build_id,"runtime/js/xuda_worker.js")));WEB_WORKER[SESSION_ID][worker_id]={worker:new Worker(blob,{name:worker_name}),promise_queue:{}}}WEB_WORKER[SESSION_ID][worker_id].worker.addEventListener("message",function(e){if(e.data.service==="worker_ready"){return resolve()}worker_functions(e)},false)})};const create_websocket=async function(){return new Promise((resolve,reject)=>{WEB_WORKER[SESSION_ID][worker_id]={worker:RUNTIME_SERVER_WEBSOCKET,promise_queue:{}};WEB_WORKER[SESSION_ID][worker_id].worker.on("message",async e=>{if(["deployment_server","http_call"].includes(e.source))return;worker_functions({data:e})});resolve()})};const worker_functions=async function(e_raw){return new Promise(async(resolve,reject)=>{var e={};e.data=e_raw.data;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){WEBSOCKET_PROCESS_PID=e.data.process_pid}var val=e.data.params;var fx={init_done:async function(){if(!obj){return _resolve()}},alert:function(){if(val[1]==="save_on"){func.UI.utils.save(SESSION_ID,true);return true}if(val[1]==="save_off"){func.UI.utils.save(SESSION_ID,false);return true}func.utils.alerts.execute(SESSION_ID,val[1],val[2],val[3],val[4]);return _resolve()},progress_on:function(){func.UI.utils.progressScreen.show(SESSION_ID,val,null);return _resolve()},progress_off:function(){func.UI.utils.progressScreen.hide();return _resolve()},worker_busy_on:function(){func.UI.utils.indicator.worker.busy();return _resolve()},worker_busy_off:function(){func.UI.utils.indicator.worker.normal();return _resolve()},screen_blocker_on:function(){func.UI.utils.screen_blocker(true,"Worker");return _resolve()},ajax_error:function(){func.utils.request_error(SESSION_ID,"ajax","Session error");return _resolve()},screen_blocker_off:function(){func.UI.utils.screen_blocker(false,"Worker");return _resolve()},job:function(){func.events.add_to_queue(SESSION_ID,val.typeP,val.eventIdP,val.triggerP,val.functionP,val.refIdP,val.containerP,val.elementP,val.rowP,null,val.descP,null,null,val.dsSessionP,null,null,val.event_propertiesP,val.calling_triggerP,val.paramsP,null,null,val.calling_trigger_prop,val.argumentsP,val.source_event_idP,val.calling_job,val.args);return _resolve()},update_client_eventChangesResults_from_worker:async function(){await func.datasource.update(SESSION_ID,val,true);if(!val.worker_id){return}fx.acknowledged_worker_with_eventChangesResults_done(val.dssession,val.worker_id);for await(const[worker_id,ds_arr]of Object.entries(WEB_WORKER[SESSION_ID])){if(val.worker_id==worker_id)continue;await func.index.call_worker(SESSION_ID,{service:"update_datasource_changes_from_client",data:data},{worker_id:worker_id})}},post_datasource:async function(){if(typeof val.dsSessionP==="undefined"||val.dsSessionP===null)return;if(!SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP]){SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP]=val.ds_obj}else{const update_existing_ds_object=function(old_obj,new_obj){for(const[key,val]of Object.entries(new_obj)){if(typeof val!=="object"){old_obj[key]=val2}else{if(!old_obj[key]){old_obj[key]=val}else update_existing_ds_object(old_obj[key],val)}}};update_existing_ds_object(SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP],val.ds_obj)}var verify_set_parent_ds=function(){var dsSession=val.dsSessionP;for(const[key,val]of Object.entries(SESSION_OBJ[SESSION_ID].DS_GLB[dsSession].parent_ds_chain)){if(SESSION_OBJ[SESSION_ID].DS_GLB[val]){SESSION_OBJ[SESSION_ID].DS_GLB[dsSession].parentDataSourceNo=val;break}}};verify_set_parent_ds();if(val.ds_obj.dataSourceSessionGlobal>SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal)SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal=val.ds_obj.dataSourceSessionGlobal},return_to_data_source:function(type,dsSessionP,ds){var data={session_id:SESSION_ID,dssession:dsSessionP,onscreen_events_active:ds.v.onscreen_events_active,viewEventExec_arr:JSON.stringify(ds.viewEventExec_arr),return_to_data_source_type:type};func.index.call_worker(SESSION_ID,{service:"return_to_data_source",data:data})},acknowledged_worker_with_eventChangesResults_done:async function(dsSessionP,worker_id){var data={session_id:SESSION_ID,dssession:dsSessionP};await func.index.call_worker(SESSION_ID,{service:"acknowledged_worker_with_eventChangesResults_done",data:data},{worker_id:worker_id});return _resolve()},execute_onscreen_view_events:async function(){await fx.post_datasource();var ds=SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP];await func.datasource.execute_onscreen_view_events(SESSION_ID,val.dsSessionP,"onscreen events");if(!ds.v.onscreen_events_active)return;var type=ds.v.onscreen_events_active.type;ds.v.onscreen_events_active=null;fx.return_to_data_source(type,val.dsSessionP,ds);return _resolve()},execute_local_db_query:async function(){await fx.post_datasource();const data=await func.db.get_query(SESSION_ID,val.fileIdP,val.queryP,val.dsSessionP,val.viewSourceDescP,val.sourceP,val.reduceP,val.skipP,val.limitP,val.countP,val.idsP);var msg={};msg.worker_id=worker_id;msg.data={};msg.service="return_from_db_query";msg.data.worker_id=worker_id;msg.data.callback_id=val.callback_id;msg.data.session_id=SESSION_ID;msg.data.data=data;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){msg.process_pid=WEBSOCKET_PROCESS_PID;WEB_WORKER[SESSION_ID][worker_id].worker.emit("message",msg)}else{WEB_WORKER[SESSION_ID][worker_id].worker.postMessage(msg)}_resolve()},execute_local_sava_data:async function(){await fx.post_datasource();const data=await func.db.save_data(SESSION_ID,val.dsSessionP,val.keyP);var msg={};msg.worker_id=worker_id;msg.data={};msg.service="return_from_sava_data";msg.data.worker_id=worker_id;msg.data.callback_id=val.callback_id;msg.data.session_id=SESSION_ID;msg.data.data=data;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){msg.process_pid=WEBSOCKET_PROCESS_PID;WEB_WORKER[SESSION_ID][worker_id].worker.emit("message",msg)}else{WEB_WORKER[SESSION_ID][worker_id].worker.postMessage(msg)}_resolve()},write_debug_log:function(params){func.utils.debug.write(SESSION_ID,val.data);_resolve()},write_log:async function(params){if(SESSION_OBJ[SESSION_ID].crawler)return;await func.common.db(SESSION_ID,"write_log",{msg:val.data,source:"runtime",log_type:"error"});_resolve()},change_loaded_image:function(params){const new_image=e.data.params.data;var $img=$("img");$.each($img,function(key,val){var src=$(val).prop("src");if(src.indexOf(new_image)>0){$(val).attr("src",src+"?ts="+(new Date).valueOf())}});_resolve()},send_watch_to_studio_websocket:function(params){STUDIO_WEBSOCKET.emit("message",val);_resolve()},get_doc_from_studio:async function(params){const module=await func.common.get_module(SESSION_ID,`xuda-progs-loader-module.mjs`);const data=await module.get_doc_from_studio(SESSION_ID,SESSION_OBJ[SESSION_ID].app_id,params.params.doc_id);func.index.call_worker(SESSION_ID,{service:"return_doc_from_studio",data:data});_resolve()},get_doc_from_websocket:async function(params){const module=await func.common.get_module(SESSION_ID,`xuda-progs-loader-module.mjs`);const data=await module.get_doc_from_websocket(SESSION_ID,SESSION_OBJ[SESSION_ID].app_id,params.params.doc_id);func.index.call_worker(SESSION_ID,{service:"return_doc_from_websocket",data:data});_resolve()},get_dbs_data_from_websocket:async function(params){const data=await func.common.get_data_from_websocket(SESSION_ID,params.params.service,params.params.data);func.index.call_worker(SESSION_ID,{service:"return_dbs_data_from_websocket",data:{data:data,websocket_queue_num:params.params.websocket_queue_num}});_resolve()},perform_rpi_request_from_studio:async function(params){const data=await func.common.db(SESSION_ID,params.params.service,params.params.data);func.index.call_worker(SESSION_ID,{service:"return_rpi_request_from_studio",data:{data:data.data,table_id:params.params.req_id}});_resolve()},refresh_document_changes_for_realtime_update:async function(params){func.UI.screen.refresh_document_changes_for_realtime_update(SESSION_ID,params.params.doc_change);_resolve()}};const get_promise_queue=function(t,worker_id){if(!WEB_WORKER[SESSION_ID][worker_id]){console.warn("worker job not found");return}return WEB_WORKER[SESSION_ID][worker_id].promise_queue[t]};const promise_ret=await get_promise_queue(e.data.promise_queue_id,e.data.worker_id);const _resolve=function(params){if(!promise_ret)return resolve();promise_ret.resolve(params);setTimeout(function(){if(WEB_WORKER[SESSION_ID][e.data.worker_id])delete WEB_WORKER[SESSION_ID][e.data.worker_id].promise_queue[e.data.promise_queue_id]},1e3)};if(fx[e.data.fx_to_execute]){return await fx[e.data.fx_to_execute](e.data)}if(!promise_ret)return console.error("promise not found");if(!e.data.fx_to_execute){return _resolve(e.data.params)}if(e.data.fx_to_execute==="worker_response"){return _resolve(e.data.params)}})};if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){await create_websocket()}else{await create_worker()}init_worker_session(worker_id);return worker_id};func.index.set_ds_0_proxy=function(SESSION_ID){const _session=SESSION_OBJ[SESSION_ID];let _ds=_session.DS_GLB[0];function createWatchedObject(obj,onChange){const watchers=new WeakMap;function createProxy(target,path=[]){if(watchers.has(target)){return watchers.get(target)}const proxy=new Proxy(target,{set(obj,prop,value){const oldValue=obj[prop];let currentPath=[...path,prop];obj[prop]=value;if(typeof value==="object"&&value!==null){obj[prop]=createProxy(value,currentPath)}if(!_.isEqual(value,oldValue)){currentPath.shift();onChange({path:currentPath.join("."),oldValue:oldValue,newValue:value,type:"set",timestamp:Date.now()})}return true},deleteProperty(obj,prop){const oldValue=obj[prop];const currentPath=[...path,prop];delete obj[prop];onChange({path:currentPath.join("."),oldValue:oldValue,newValue:undefined,type:"delete",timestamp:Date.now()});return true}});for(const[key,value]of Object.entries(target)){if(typeof value==="object"&&value!==null){target[key]=createProxy(value,[...path,key])}}watchers.set(target,proxy);return proxy}return createProxy(obj)}const watchedDs=createWatchedObject({_ref:_ds},async change=>{const{path,newValue,oldValue}=change;try{if(_.isEqual(newValue,oldValue))return;const _session=SESSION_OBJ[SESSION_ID];if(_session?.watchers?.[path]){const fx=_session?.watchers?.[path];fx(change)}const _refs=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS;for(const[ref_id,val]of Object.entries(_refs)){const prefix=`${ref_id}.ds.`;if(!path.includes(prefix))continue;const clean_path_prop=path.split(prefix)[1];console.log(clean_path_prop);const _ref=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS[ref_id];if(!_ref)continue;const _ds=_ref.ds;const target_ds=_session.DS_GLB[_ds.dsSession];const target_value=_.get(target_ds,clean_path_prop);if(target_value===newValue)continue;const datasource_changes={[_ds.dsSession]:{["datasource_main"]:{watcher:{path:path.replace(prefix_path+".",""),newValue:newValue}}}};await func.datasource.update(SESSION_ID,datasource_changes)}return;if(path.split(".")[0]!=="SYS_GLOBAL_OBJ_REFS")return;const ref_id=path.split(".")[1];if(!ref_id)return;const prefix=`SYS_GLOBAL_OBJ_REFS.${ref_id}.ds.`;if(!path.includes(prefix))return;const _ref=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS[ref_id];if(!_ref)return;const _ds=_ref.ds;const clean_path_prop=path.replace(prefix,"");const target_ds=_session.DS_GLB[_ds.dsSession];const target_value=_.get(target_ds,clean_path_prop);if(target_value===newValue)return;const datasource_changes={[_ds.dsSession]:{["datasource_main"]:{watcher:{path:path.replace(prefix_path+".",""),newValue:newValue}}}};await func.datasource.update(SESSION_ID,datasource_changes);return}catch(error){}});_session.DS_GLB[0]=watchedDs._ref};glb.SLIM_BUNDLE=1;
113
+ `);setTimeout(()=>{$(`[name="hard_reload"]`).off("click").on("click",async function(){await func.index.delete_pouch(SESSION_ID);location.reload()});$(`[name="reset_worker"]`).off("click").on("click",function(){_session.WORKER_OBJ.jobs[0].stat=null;_session.WORKER_OBJ.stat=null;func.UI.utils.progressScreen.hide(SESSION_ID)});$(`[name="get_support"]`).off("click").on("click",async function(){const get_support=await func.common.get_module(SESSION_ID,"xuda-get-support-module.esm.js");var name,subject;const prompt_name=()=>{name=window.prompt(`Get support from your ${APP_OBJ[app_id].app_general_prop?.app_name} team, \n\nYour Name (required):`);if(name==="")prompt_name()};const prompt_subject=()=>{subject=window.prompt(`When you click on "Ok," you are granting permission to ${APP_OBJ[app_id]?.app_name} team to access your browser. \n\nSubject (required):`);if(subject==="")prompt_subject()};if(!SUPPORT_PEER){try{name=firebase.auth().currentUser.displayName}catch(error){if(_session?.USR_OBJ?.usr_name){name=_session.USR_OBJ.usr_name}else{prompt_name()}}if(name===null)return;prompt_subject();if(subject===null)return;func.common.db(SESSION_ID,"get_support",{name:name,subject:subject});setTimeout(()=>{$("body").addClass("get_support_request");$("body").remove(".get_support_request_title").append("<div class='get_support_request_title'>Support pending</div>")},2e3)}else{get_support.terminate_peer(SESSION_ID)}func.UI.utils.progressScreen.hide(SESSION_ID)})},1e3)}}};if(event.which===27){let SESSION_ID=Object.keys(SESSION_OBJ)[0];func.UI.utils.progressScreen.hide(SESSION_ID)}if(event.ctrlKey&&event.shiftKey){if(keys[event.which]){keys[event.which].fx()}}});$(document).mousemove(function(e){CLIENT_ACTIVITY_TS=Date.now();posX=e.pageX;posY=e.pageY;if(SESSION_OBJ[SESSION_ID]?.DS_GLB?.[0]){SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system["SYS_GLOBAL_OBJ_CLIENT_INFO"].cursor_pos_x=posX;SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system["SYS_GLOBAL_OBJ_CLIENT_INFO"].cursor_pos_y=posY}});$.fn.draggable=function(){CLIENT_ACTIVITY_TS=Date.now();var $this=this,ns="draggable_"+(Math.random()+"").replace(".",""),mm="mousemove."+ns,mu="mouseup."+ns,$w=$(window),isFixed=$this.css("position")==="fixed",adjX=0,adjY=0;$this.mousedown(function(ev){var pos=$this.offset();if(isFixed){adjX=$w.scrollLeft();adjY=$w.scrollTop()}var ox=ev.pageX-pos.left,oy=ev.pageY-pos.top;$this.data(ns,{x:ox,y:oy});$w.on(mm,function(ev){ev.preventDefault();ev.stopPropagation();if(isFixed){adjX=$w.scrollLeft();adjY=$w.scrollTop()}var offset=$this.data(ns);$this.css({left:ev.pageX-adjX-offset.x,top:ev.pageY-adjY-offset.y})});$w.on(mu,function(){$w.off(mm+" "+mu).removeData(ns)})});return this};var heartbeat_attempts=0;var heartbeat_internal=setInterval(async function(){const SESSION_ID=Object.keys(SESSION_OBJ)[0];if(!SESSION_ID)return;let _session=SESSION_OBJ[SESSION_ID];if(!_session)return;if(_session.crawler)return;const set_idle=async function(stat){var datasource_changes={[0]:{["data_system"]:{SYS_GLOBAL_BOL_IDLE:stat}}};await func.datasource.update(SESSION_ID,datasource_changes)};if(Date.now()-CLIENT_ACTIVITY_TS>3e4){set_idle(1)}else{set_idle(0)}if(_session.engine_mode==="live_preview"||!_session.opt.enable_user_assist){return}const ret=await func.common.db(SESSION_ID,"heartbeat",{stat:Date.now()-CLIENT_ACTIVITY_TS>3e4?1:2}).catch(err=>{heartbeat_attempts++;console.warn(err.message);if(heartbeat_attempts<10)return;clearInterval(heartbeat_internal)});heartbeat_attempts=0;if(ret?.session_stat===3){await func.index.delete_pouch();window.top.location.reload()}$("body").removeClass("get_support_request");$("body").find(".get_support_request_title").remove();$("body").removeClass("get_support_online");$("body").find(".get_support_online_title").remove();if(ret?.data?.peer?.peer_status===1){if(ret.data.peer.peer_regional_server){get_support.init_peer(SESSION_ID,ret.data.peer.peer_regional_server)}$("body").addClass("get_support_request");$("body").remove(".get_support_request_title").append("<div class='get_support_request_title'>Support pending</div>")}if(ret?.data?.peer?.peer_status===2){$("body").addClass("get_support_online");$("body").remove(".get_support_online_title").append("<div class='get_support_online_title'>Support online</div>")}_session.res_token=ret.res_token},3e4);glb.WINDOW_LOCATION_SEARCH=window.location.search};func.index.checkConnectivity=async function(){const endpoints=["https://xuda.io/favicon.ico"];const promises=endpoints.map(url=>fetch(url,{method:"HEAD",mode:"no-cors"}).then(()=>true).catch(()=>false));const results=await Promise.all(promises);IS_ONLINE=results.some(result=>result===true);window.addEventListener("online",function(){IS_ONLINE=true;$("body").trigger("set_db_replication_from_server")});window.addEventListener("offline",function(){IS_ONLINE=false})};func.index.init_service_workers=function(){if("serviceWorker"in navigator){navigator.serviceWorker.addEventListener("message",function(event){console.log("serviceWorker message:",event)});navigator.serviceWorker.register("xuda-sw.js").then(function(registration){console.log("ServiceWorker registration successful with scope: ",registration.scope);glb.sw_registration=registration},function(err){console.log("ServiceWorker registration failed: ",err)})}};func.index.delete_pouch=async function(SESSION_ID=Object.keys(SESSION_OBJ)[0]){const db=await func.utils.connect_pouchdb(SESSION_ID);try{return await db.destroy()}catch(err){console.log(err)}};func.index.new_webworker=async function(SESSION_ID,prog_obj,obj){var worker_id=Object.keys(WEB_WORKER[SESSION_ID]).length+1;var _session=SESSION_OBJ[SESSION_ID];if(!_session.engine_mode==="docker"){ver=APP_OBJ[_session.app_id].app_version}var build_id=["live_preview","miniapp"].includes(_session.engine_mode)?"":_session.opt.app_build_id;if(typeof XUDA_BUILD_ID!=="undefined"){build_id=XUDA_BUILD_ID}const worker_name=`${typeof _session.SLIM_BUNDLE==="undefined"||!_session.SLIM_BUNDLE?"":"Slim "}${prog_obj.menuName} worker`+" "+glb.worker_type+": #"+worker_id.toString()+" "+(build_id||"")+" "+_session.domain;const init_worker_session=function(worker_id){var _session=_.cloneDeep(SESSION_OBJ[SESSION_ID]);delete _session.root_element;const get_parent_ds=function(ds){var ds_obj={};if(ds&&_session.DS_GLB[ds].parentDataSourceNo!==null){ds_obj[ds]=func.utils.clean_returned_datasource(SESSION_ID,ds);_.forEach(get_parent_ds(_session.DS_GLB[ds].parentDataSourceNo),function(val,key){ds_obj[key]=val})}else{ds_obj[ds]=func.utils.clean_returned_datasource(SESSION_ID,ds)}return ds_obj};var ds_obj={};if(typeof obj?.data?.parentDataSourceNoP!=="undefined"){ds_obj=get_parent_ds(obj.data.parentDataSourceNoP)}_session.DS_GLB={};_session.WORKER_OBJ={jobs:[],num:1e3,stat:null};var app_id=_session.app_id;var data={SESSION_ID:SESSION_ID,app_id:app_id,APP_OBJ:APP_OBJ[app_id],PROJECT_OBJ:PROJECT_OBJ[app_id],DOCS_OBJ:DOCS_OBJ[app_id],APP_INFO:glb.APP_INFO[app_id],DEBUG_MODE:glb.DEBUG_MODE,DEBUG_INFO_OBJ:glb.DEBUG_INFO_OBJ,WINDOW_LOCATION_SEARCH:glb.WINDOW_LOCATION_SEARCH,ROOT_ELEMENT_ATTRIBUTES:glb.ROOT_ELEMENT_ATTRIBUTES,DS_GLB:ds_obj,SESSION_INFO:JSON.parse(JSON.stringify(_session)),session_id:SESSION_ID,engine_mode:_session.engine_mode,STUDIO_WEBSOCKET_CONNECTION_ID:STUDIO_WEBSOCKET_CONNECTION_ID};if(_session.engine_mode==="live_preview"){data.DOCS_OBJ=DOCS_OBJ[app_id]}delete data.SESSION_INFO.root_element;data.SESSION_INFO.worker_id=worker_id;var ds_arr=[];$.map(_session.DS_GLB,function(val,i){ds_arr.push(i)});WEB_WORKER[SESSION_ID][worker_id].ds_arr=ds_arr;delete data.SESSION_INFO.DS_UI_EVENTS_GLB;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){WEB_WORKER[SESSION_ID][worker_id].worker.emit("message",{service:"init",data:data,worker_id:worker_id})}else{WEB_WORKER[SESSION_ID][worker_id].worker.postMessage({service:"init",data:JSON.stringify(data),worker_id:worker_id})}};const create_worker=async function(){return new Promise((resolve,reject)=>{if(glb.worker_type==="Dev"){WEB_WORKER[SESSION_ID][worker_id]={worker:new Worker("js/xuda_worker.js",{name:worker_name}),promise_queue:{}}}else{function getWorkerURL(url){const content=`importScripts( "${url}" );`;return URL.createObjectURL(new Blob([content],{type:"text/javascript"}))}const _session=SESSION_OBJ[SESSION_ID];let blob=getWorkerURL(func.common.get_url(SESSION_ID,"dist",func.utils.get_resource_filename(["live_preview","miniapp"].includes(_session.engine_mode)?"":_session?.opt?.app_build_id,"runtime/js/xuda_worker.js")));WEB_WORKER[SESSION_ID][worker_id]={worker:new Worker(blob,{name:worker_name}),promise_queue:{}}}WEB_WORKER[SESSION_ID][worker_id].worker.addEventListener("message",function(e){if(e.data.service==="worker_ready"){return resolve()}worker_functions(e)},false)})};const create_websocket=async function(){return new Promise((resolve,reject)=>{WEB_WORKER[SESSION_ID][worker_id]={worker:RUNTIME_SERVER_WEBSOCKET,promise_queue:{}};WEB_WORKER[SESSION_ID][worker_id].worker.on("message",async e=>{if(["deployment_server","http_call"].includes(e.source))return;worker_functions({data:e})});resolve()})};const worker_functions=async function(e_raw){return new Promise(async(resolve,reject)=>{var e={};e.data=e_raw.data;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){WEBSOCKET_PROCESS_PID=e.data.process_pid}var val=e.data.params;var fx={init_done:async function(){if(!obj){return _resolve()}},alert:function(){if(val[1]==="save_on"){func.UI.utils.save(SESSION_ID,true);return true}if(val[1]==="save_off"){func.UI.utils.save(SESSION_ID,false);return true}func.utils.alerts.execute(SESSION_ID,val[1],val[2],val[3],val[4]);return _resolve()},progress_on:function(){func.UI.utils.progressScreen.show(SESSION_ID,val,null);return _resolve()},progress_off:function(){func.UI.utils.progressScreen.hide();return _resolve()},worker_busy_on:function(){func.UI.utils.indicator.worker.busy();return _resolve()},worker_busy_off:function(){func.UI.utils.indicator.worker.normal();return _resolve()},screen_blocker_on:function(){func.UI.utils.screen_blocker(true,"Worker");return _resolve()},ajax_error:function(){func.utils.request_error(SESSION_ID,"ajax","Session error");return _resolve()},screen_blocker_off:function(){func.UI.utils.screen_blocker(false,"Worker");return _resolve()},job:function(){func.events.add_to_queue(SESSION_ID,val.typeP,val.eventIdP,val.triggerP,val.functionP,val.refIdP,val.containerP,val.elementP,val.rowP,null,val.descP,null,null,val.dsSessionP,null,null,val.event_propertiesP,val.calling_triggerP,val.paramsP,null,null,val.calling_trigger_prop,val.argumentsP,val.source_event_idP,val.calling_job,val.args);return _resolve()},update_client_eventChangesResults_from_worker:async function(){await func.datasource.update(SESSION_ID,val,true);if(!val.worker_id){return}fx.acknowledged_worker_with_eventChangesResults_done(val.dssession,val.worker_id);for await(const[worker_id,ds_arr]of Object.entries(WEB_WORKER[SESSION_ID])){if(val.worker_id==worker_id)continue;await func.index.call_worker(SESSION_ID,{service:"update_datasource_changes_from_client",data:data},{worker_id:worker_id})}},post_datasource:async function(){if(typeof val.dsSessionP==="undefined"||val.dsSessionP===null)return;if(!SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP]){SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP]=val.ds_obj}else{const update_existing_ds_object=function(old_obj,new_obj){for(const[key,val]of Object.entries(new_obj)){if(typeof val!=="object"){old_obj[key]=val2}else{if(!old_obj[key]){old_obj[key]=val}else update_existing_ds_object(old_obj[key],val)}}};update_existing_ds_object(SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP],val.ds_obj)}var verify_set_parent_ds=function(){var dsSession=val.dsSessionP;for(const[key,val]of Object.entries(SESSION_OBJ[SESSION_ID].DS_GLB[dsSession].parent_ds_chain)){if(SESSION_OBJ[SESSION_ID].DS_GLB[val]){SESSION_OBJ[SESSION_ID].DS_GLB[dsSession].parentDataSourceNo=val;break}}};verify_set_parent_ds();if(val.ds_obj.dataSourceSessionGlobal>SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal)SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal=val.ds_obj.dataSourceSessionGlobal},return_to_data_source:function(type,dsSessionP,ds){var data={session_id:SESSION_ID,dssession:dsSessionP,onscreen_events_active:ds.v.onscreen_events_active,viewEventExec_arr:JSON.stringify(ds.viewEventExec_arr),return_to_data_source_type:type};func.index.call_worker(SESSION_ID,{service:"return_to_data_source",data:data})},acknowledged_worker_with_eventChangesResults_done:async function(dsSessionP,worker_id){var data={session_id:SESSION_ID,dssession:dsSessionP};await func.index.call_worker(SESSION_ID,{service:"acknowledged_worker_with_eventChangesResults_done",data:data},{worker_id:worker_id});return _resolve()},execute_onscreen_view_events:async function(){await fx.post_datasource();var ds=SESSION_OBJ[SESSION_ID].DS_GLB[val.dsSessionP];await func.datasource.execute_onscreen_view_events(SESSION_ID,val.dsSessionP,"onscreen events");if(!ds.v.onscreen_events_active)return;var type=ds.v.onscreen_events_active.type;ds.v.onscreen_events_active=null;fx.return_to_data_source(type,val.dsSessionP,ds);return _resolve()},execute_local_db_query:async function(){await fx.post_datasource();const data=await func.db.get_query(SESSION_ID,val.fileIdP,val.queryP,val.dsSessionP,val.viewSourceDescP,val.sourceP,val.reduceP,val.skipP,val.limitP,val.countP,val.idsP);var msg={};msg.worker_id=worker_id;msg.data={};msg.service="return_from_db_query";msg.data.worker_id=worker_id;msg.data.callback_id=val.callback_id;msg.data.session_id=SESSION_ID;msg.data.data=data;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){msg.process_pid=WEBSOCKET_PROCESS_PID;WEB_WORKER[SESSION_ID][worker_id].worker.emit("message",msg)}else{WEB_WORKER[SESSION_ID][worker_id].worker.postMessage(msg)}_resolve()},execute_local_sava_data:async function(){await fx.post_datasource();const data=await func.db.save_data(SESSION_ID,val.dsSessionP,val.keyP);var msg={};msg.worker_id=worker_id;msg.data={};msg.service="return_from_sava_data";msg.data.worker_id=worker_id;msg.data.callback_id=val.callback_id;msg.data.session_id=SESSION_ID;msg.data.data=data;if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){msg.process_pid=WEBSOCKET_PROCESS_PID;WEB_WORKER[SESSION_ID][worker_id].worker.emit("message",msg)}else{WEB_WORKER[SESSION_ID][worker_id].worker.postMessage(msg)}_resolve()},write_debug_log:function(params){func.utils.debug.write(SESSION_ID,val.data);_resolve()},write_log:async function(params){if(SESSION_OBJ[SESSION_ID].crawler)return;await func.common.db(SESSION_ID,"write_log",{msg:val.data,source:"runtime",log_type:"error"});_resolve()},change_loaded_image:function(params){const new_image=e.data.params.data;var $img=$("img");$.each($img,function(key,val){var src=$(val).prop("src");if(src.indexOf(new_image)>0){$(val).attr("src",src+"?ts="+(new Date).valueOf())}});_resolve()},send_watch_to_studio_websocket:function(params){STUDIO_WEBSOCKET.emit("message",val);_resolve()},get_doc_from_studio:async function(params){const module=await func.common.get_module(SESSION_ID,`xuda-progs-loader-module.mjs`);const data=await module.get_doc_from_studio(SESSION_ID,SESSION_OBJ[SESSION_ID].app_id,params.params.doc_id);func.index.call_worker(SESSION_ID,{service:"return_doc_from_studio",data:data});_resolve()},get_doc_from_websocket:async function(params){const module=await func.common.get_module(SESSION_ID,`xuda-progs-loader-module.mjs`);const data=await module.get_doc_from_websocket(SESSION_ID,SESSION_OBJ[SESSION_ID].app_id,params.params.doc_id);func.index.call_worker(SESSION_ID,{service:"return_doc_from_websocket",data:data});_resolve()},get_dbs_data_from_websocket:async function(params){const data=await func.common.get_data_from_websocket(SESSION_ID,params.params.service,params.params.data);func.index.call_worker(SESSION_ID,{service:"return_dbs_data_from_websocket",data:{data:data,websocket_queue_num:params.params.websocket_queue_num}});_resolve()},perform_rpi_request_from_studio:async function(params){const data=await func.common.db(SESSION_ID,params.params.service,params.params.data);func.index.call_worker(SESSION_ID,{service:"return_rpi_request_from_studio",data:{data:data.data,table_id:params.params.req_id}});_resolve()},refresh_document_changes_for_realtime_update:async function(params){func.UI.screen.refresh_document_changes_for_realtime_update(SESSION_ID,params.params.doc_change);_resolve()}};const get_promise_queue=function(t,worker_id){if(!WEB_WORKER[SESSION_ID][worker_id]){console.warn("worker job not found");return}return WEB_WORKER[SESSION_ID][worker_id].promise_queue[t]};const promise_ret=await get_promise_queue(e.data.promise_queue_id,e.data.worker_id);const _resolve=function(params){if(!promise_ret)return resolve();promise_ret.resolve(params);setTimeout(function(){if(WEB_WORKER[SESSION_ID][e.data.worker_id])delete WEB_WORKER[SESSION_ID][e.data.worker_id].promise_queue[e.data.promise_queue_id]},1e3)};if(fx[e.data.fx_to_execute]){return await fx[e.data.fx_to_execute](e.data)}if(!promise_ret)return console.error("promise not found");if(!e.data.fx_to_execute){return _resolve(e.data.params)}if(e.data.fx_to_execute==="worker_response"){return _resolve(e.data.params)}})};if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){await create_websocket()}else{await create_worker()}init_worker_session(worker_id);return worker_id};func.index.set_ds_0_proxy=function(SESSION_ID){const _session=SESSION_OBJ[SESSION_ID];let _ds=_session.DS_GLB[0];function createWatchedObject(obj,onChange){const watchers=new WeakMap;function createProxy(target,path=[]){if(watchers.has(target)){return watchers.get(target)}const proxy=new Proxy(target,{set(obj,prop,value){const oldValue=obj[prop];let currentPath=[...path,prop];obj[prop]=value;if(typeof value==="object"&&value!==null){obj[prop]=createProxy(value,currentPath)}if(!_.isEqual(value,oldValue)){currentPath.shift();onChange({path:currentPath.join("."),oldValue:oldValue,newValue:value,type:"set",timestamp:Date.now()})}return true},deleteProperty(obj,prop){const oldValue=obj[prop];const currentPath=[...path,prop];delete obj[prop];onChange({path:currentPath.join("."),oldValue:oldValue,newValue:undefined,type:"delete",timestamp:Date.now()});return true}});for(const[key,value]of Object.entries(target)){if(typeof value==="object"&&value!==null){target[key]=createProxy(value,[...path,key])}}watchers.set(target,proxy);return proxy}return createProxy(obj)}const watchedDs=createWatchedObject({_ref:_ds},async change=>{const{path,newValue,oldValue}=change;try{if(_.isEqual(newValue,oldValue))return;const _session=SESSION_OBJ[SESSION_ID];if(_session?.watchers?.[path]){const fx=_session?.watchers?.[path];fx(change)}const _refs=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS;for(const[ref_id,val]of Object.entries(_refs)){const prefix=`${ref_id}.ds.`;if(!path.includes(prefix))continue;const clean_path_prop=path.split(prefix)[1];console.log(clean_path_prop);if(!clean_path_prop.includes("progDataSource"))continue;const _ref=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS[ref_id];if(!_ref)continue;const _ds=_ref.ds;const target_ds=_session.DS_GLB[_ds.dsSession];const target_value=_.get(target_ds,clean_path_prop);if(target_value===newValue)continue;const datasource_changes={[_ds.dsSession]:{["datasource_main"]:{watcher:{path:clean_path_prop,newValue:newValue}}}};await func.datasource.update(SESSION_ID,datasource_changes)}return;if(path.split(".")[0]!=="SYS_GLOBAL_OBJ_REFS")return;const ref_id=path.split(".")[1];if(!ref_id)return;const prefix=`SYS_GLOBAL_OBJ_REFS.${ref_id}.ds.`;if(!path.includes(prefix))return;const _ref=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS[ref_id];if(!_ref)return;const _ds=_ref.ds;const clean_path_prop=path.replace(prefix,"");const target_ds=_session.DS_GLB[_ds.dsSession];const target_value=_.get(target_ds,clean_path_prop);if(target_value===newValue)return;const datasource_changes={[_ds.dsSession]:{["datasource_main"]:{watcher:{path:path.replace(prefix_path+".",""),newValue:newValue}}}};await func.datasource.update(SESSION_ID,datasource_changes);return}catch(error){}});_session.DS_GLB[0]=watchedDs._ref};glb.SLIM_BUNDLE=1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/runtime-bundle",
3
- "version": "1.0.1350",
3
+ "version": "1.0.1352",
4
4
  "description": "The Xuda Runtime Bundle refers to a collection of scripts and libraries packaged together to provide the necessary runtime environment for executing plugins or components in the Xuda platform. ",
5
5
  "scripts": {
6
6
  "pub": "npm version patch --force && npm publish --access public"