@xuda.io/runtime-bundle 1.0.1354 → 1.0.1356
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.
|
@@ -42750,22 +42750,21 @@ func.index.set_ds_0_proxy = function (SESSION_ID) {
|
|
|
42750
42750
|
const { path, newValue, oldValue } = change;
|
|
42751
42751
|
console.log('Change detected:', path);
|
|
42752
42752
|
try {
|
|
42753
|
-
if (_.isEqual(newValue, oldValue)) return;
|
|
42754
|
-
|
|
42755
42753
|
const _session = SESSION_OBJ[SESSION_ID];
|
|
42756
42754
|
|
|
42757
|
-
let watch_path =
|
|
42755
|
+
let watch_path = 'data_system.' + path;
|
|
42758
42756
|
|
|
42759
42757
|
if (_session?.watchers?.[watch_path]) {
|
|
42760
42758
|
const fx = _session?.watchers?.[watch_path];
|
|
42761
42759
|
fx(change);
|
|
42762
42760
|
} else {
|
|
42763
|
-
watch_path =
|
|
42761
|
+
watch_path = 'data_system.SYS_GLOBAL_OBJ_REFS.' + path;
|
|
42764
42762
|
if (_session?.watchers?.[watch_path]) {
|
|
42765
42763
|
const fx = _session?.watchers?.[watch_path];
|
|
42766
42764
|
fx(change);
|
|
42767
42765
|
}
|
|
42768
42766
|
}
|
|
42767
|
+
if (_.isEqual(newValue, oldValue)) return;
|
|
42769
42768
|
////////////////////////
|
|
42770
42769
|
const _refs = SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS;
|
|
42771
42770
|
for (const [ref_id, val] of Object.entries(_refs)) {
|
|
@@ -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;console.log("Change detected:",path);try{if(_.isEqual(newValue,oldValue))return;const _session=SESSION_OBJ[SESSION_ID];let watch_path=path.replace("data_system.","");if(_session?.watchers?.[watch_path]){const fx=_session?.watchers?.[watch_path];fx(change)}else{watch_path=path.replace("data_system.SYS_GLOBAL_OBJ_REFS.","");if(_session?.watchers?.[watch_path]){const fx=_session?.watchers?.[watch_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];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(_.isEqual(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;
|
|
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;console.log("Change detected:",path);try{const _session=SESSION_OBJ[SESSION_ID];let watch_path="data_system."+path;if(_session?.watchers?.[watch_path]){const fx=_session?.watchers?.[watch_path];fx(change)}else{watch_path="data_system.SYS_GLOBAL_OBJ_REFS."+path;if(_session?.watchers?.[watch_path]){const fx=_session?.watchers?.[watch_path];fx(change)}}if(_.isEqual(newValue,oldValue))return;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];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(_.isEqual(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;
|
package/js/xuda-runtime-slim.js
CHANGED
|
@@ -20263,22 +20263,21 @@ func.index.set_ds_0_proxy = function (SESSION_ID) {
|
|
|
20263
20263
|
const { path, newValue, oldValue } = change;
|
|
20264
20264
|
console.log('Change detected:', path);
|
|
20265
20265
|
try {
|
|
20266
|
-
if (_.isEqual(newValue, oldValue)) return;
|
|
20267
|
-
|
|
20268
20266
|
const _session = SESSION_OBJ[SESSION_ID];
|
|
20269
20267
|
|
|
20270
|
-
let watch_path =
|
|
20268
|
+
let watch_path = 'data_system.' + path;
|
|
20271
20269
|
|
|
20272
20270
|
if (_session?.watchers?.[watch_path]) {
|
|
20273
20271
|
const fx = _session?.watchers?.[watch_path];
|
|
20274
20272
|
fx(change);
|
|
20275
20273
|
} else {
|
|
20276
|
-
watch_path =
|
|
20274
|
+
watch_path = 'data_system.SYS_GLOBAL_OBJ_REFS.' + path;
|
|
20277
20275
|
if (_session?.watchers?.[watch_path]) {
|
|
20278
20276
|
const fx = _session?.watchers?.[watch_path];
|
|
20279
20277
|
fx(change);
|
|
20280
20278
|
}
|
|
20281
20279
|
}
|
|
20280
|
+
if (_.isEqual(newValue, oldValue)) return;
|
|
20282
20281
|
////////////////////////
|
|
20283
20282
|
const _refs = SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS;
|
|
20284
20283
|
for (const [ref_id, val] of Object.entries(_refs)) {
|
|
@@ -20264,22 +20264,21 @@ func.index.set_ds_0_proxy = function (SESSION_ID) {
|
|
|
20264
20264
|
const { path, newValue, oldValue } = change;
|
|
20265
20265
|
console.log('Change detected:', path);
|
|
20266
20266
|
try {
|
|
20267
|
-
if (_.isEqual(newValue, oldValue)) return;
|
|
20268
|
-
|
|
20269
20267
|
const _session = SESSION_OBJ[SESSION_ID];
|
|
20270
20268
|
|
|
20271
|
-
let watch_path =
|
|
20269
|
+
let watch_path = 'data_system.' + path;
|
|
20272
20270
|
|
|
20273
20271
|
if (_session?.watchers?.[watch_path]) {
|
|
20274
20272
|
const fx = _session?.watchers?.[watch_path];
|
|
20275
20273
|
fx(change);
|
|
20276
20274
|
} else {
|
|
20277
|
-
watch_path =
|
|
20275
|
+
watch_path = 'data_system.SYS_GLOBAL_OBJ_REFS.' + path;
|
|
20278
20276
|
if (_session?.watchers?.[watch_path]) {
|
|
20279
20277
|
const fx = _session?.watchers?.[watch_path];
|
|
20280
20278
|
fx(change);
|
|
20281
20279
|
}
|
|
20282
20280
|
}
|
|
20281
|
+
if (_.isEqual(newValue, oldValue)) return;
|
|
20283
20282
|
////////////////////////
|
|
20284
20283
|
const _refs = SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system.SYS_GLOBAL_OBJ_REFS;
|
|
20285
20284
|
for (const [ref_id, val] of Object.entries(_refs)) {
|
|
@@ -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;console.log("Change detected:",path);try{if(_.isEqual(newValue,oldValue))return;const _session=SESSION_OBJ[SESSION_ID];let watch_path=path.replace("data_system.","");if(_session?.watchers?.[watch_path]){const fx=_session?.watchers?.[watch_path];fx(change)}else{watch_path=path.replace("data_system.SYS_GLOBAL_OBJ_REFS.","");if(_session?.watchers?.[watch_path]){const fx=_session?.watchers?.[watch_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];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(_.isEqual(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;
|
|
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;console.log("Change detected:",path);try{const _session=SESSION_OBJ[SESSION_ID];let watch_path="data_system."+path;if(_session?.watchers?.[watch_path]){const fx=_session?.watchers?.[watch_path];fx(change)}else{watch_path="data_system.SYS_GLOBAL_OBJ_REFS."+path;if(_session?.watchers?.[watch_path]){const fx=_session?.watchers?.[watch_path];fx(change)}}if(_.isEqual(newValue,oldValue))return;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];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(_.isEqual(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.
|
|
3
|
+
"version": "1.0.1356",
|
|
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"
|