@xuda.io/runtime-bundle 1.0.1428 → 1.0.1429
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.
- package/js/xuda-runtime-bundle.js +24 -2
- package/js/xuda-runtime-bundle.min.js +1 -1
- package/js/xuda-runtime-slim.js +24 -2
- package/js/xuda-runtime-slim.min.es.js +24 -2
- package/js/xuda-runtime-slim.min.js +1 -1
- package/js/xuda-server-bundle.min.mjs +1 -1
- package/js/xuda-server-bundle.mjs +24 -2
- package/js/xuda-worker-bundle.js +24 -2
- package/js/xuda-worker-bundle.min.js +1 -1
- package/package.json +1 -1
|
@@ -43416,6 +43416,29 @@ func.events.execute = async function (
|
|
|
43416
43416
|
return result;
|
|
43417
43417
|
},
|
|
43418
43418
|
update: async function () {
|
|
43419
|
+
const resolve_update_field_id = async function (field_expr, iterate_info) {
|
|
43420
|
+
let trimmed = field_expr?.trim?.() || '';
|
|
43421
|
+
if (!trimmed) {
|
|
43422
|
+
return trimmed;
|
|
43423
|
+
}
|
|
43424
|
+
|
|
43425
|
+
const first = trimmed.substring(0, 1);
|
|
43426
|
+
const last = trimmed.substring(trimmed.length - 1);
|
|
43427
|
+
if ((first === "'" || first === '"' || first === '`') && last === first) {
|
|
43428
|
+
trimmed = trimmed.substring(1, trimmed.length - 1).trim();
|
|
43429
|
+
}
|
|
43430
|
+
|
|
43431
|
+
if (/^@?[A-Za-z_][\w\-\:\.]*$/.test(trimmed)) {
|
|
43432
|
+
return trimmed.substring(0, 1) === '@' ? trimmed.substring(1) : trimmed;
|
|
43433
|
+
}
|
|
43434
|
+
|
|
43435
|
+
let ret_field_id = await func.expression.get(SESSION_ID, trimmed, dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
|
|
43436
|
+
if (typeof ret_field_id?.result === 'string' && ret_field_id.result.substring(0, 1) === '@') {
|
|
43437
|
+
return ret_field_id.result.substring(1);
|
|
43438
|
+
}
|
|
43439
|
+
return ret_field_id?.result;
|
|
43440
|
+
};
|
|
43441
|
+
|
|
43419
43442
|
const obj_values_to_update = func.datasource.get_viewFields_for_update_function(SESSION_ID, calling_trigger_prop, null, dsSessionP);
|
|
43420
43443
|
if (!obj_values_to_update || xu_isEmpty(obj_values_to_update)) {
|
|
43421
43444
|
func.utils.debug_report(SESSION_ID, 'Update values object is empty', '', 'W');
|
|
@@ -43433,9 +43456,8 @@ func.events.execute = async function (
|
|
|
43433
43456
|
iterate_info = element_meta?.iterate_info || null;
|
|
43434
43457
|
}
|
|
43435
43458
|
|
|
43436
|
-
let ret_field_id = await func.expression.get(SESSION_ID, val.id.trim(), dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
|
|
43437
43459
|
let ret_value = await func.expression.get(SESSION_ID, val.val.trim(), dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
|
|
43438
|
-
let _field_id =
|
|
43460
|
+
let _field_id = await resolve_update_field_id(val.id, iterate_info);
|
|
43439
43461
|
let _value = ret_value.result;
|
|
43440
43462
|
|
|
43441
43463
|
updates.push({ _field_id, _value });
|
|
@@ -75,7 +75,7 @@
|
|
|
75
75
|
${refIdP.value}
|
|
76
76
|
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,null,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},execute_evaluate_javascript:async function(){const module=await func.common.get_module(SESSION_ID,"xuda-event-javascript-module.mjs");const result=await module.run_javascript(SESSION_ID,jobNoP,dsSession,`(async function(el,evt) {
|
|
77
77
|
${refIdP.value}
|
|
78
|
-
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,true,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){func.runtime.platform.emit(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.workflow?.[eventIdP].name.event;if(_field_obj?.workflow?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!xu_isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||xu_isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;var iterate_info=null;if(elementP){const element_meta=func.runtime.ui.get_meta(elementP,"xuData");iterate_info=element_meta?.iterate_info||null}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let _field_id=ret_field_id.result;let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes,null,null,triggerP);if(_ds.PARAM_OUT_INFO){for await(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds.dsSession,val.parentDataSourceNo)}}if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=payload_arr.reduce((ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){for(const[key2,val2]of Object.entries(_session.WORKER_OBJ.jobs)){if(key2===val){found=true;break}}}if(!found){do_callback();return}},100);var do_callback=function(){clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))func.runtime.platform.set_title(dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"])};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:params_obj.prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:null,source_functionP:"pendingUrlEvent_embed"})}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(xu_isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.action={};func.action.execute=async function(SESSION_ID,actionP,paramsP,isScreenActionP,event_sourceP,jobNoP,containerP){const module=await func.common.get_module(SESSION_ID,"xuda-actions-module.esm.js");await module.action_execute(SESSION_ID,actionP,paramsP,isScreenActionP,event_sourceP,jobNoP,containerP)};func.fcm={};func.UI.main={};func.UI.main.clear_SYNC_INTERVAL=function(){};func.UI.main.embed_prog_execute=async function(SESSION_ID,prog){var _session=SESSION_OBJ[SESSION_ID];const _prog=await func.utils.VIEWS_OBJ.get(SESSION_ID,prog);const get_params_obj=function(){var params_obj={};if(_prog?.properties?.progParams){for(const[key,val]of Object.entries(_prog.properties.progParams)){if(typeof _session.url_params?.[val.data.parameter]!=="undefined"){params_obj[val.data.parameter]=_session.url_params?.[val.data.parameter];continue}console.warn(`Warning: Program ${_prog.properties.menuName} expected In parameter: ${val.data.parameter} but received null instead`)}}return params_obj};let screen_ret=await func.utils.get_screen_obj(SESSION_ID,prog);if(screen_ret){let ret_init=await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:get_params_obj(),source_functionP:"call_embed"});func.runtime.platform.set_title(screen_ret.properties.menuTitle);return}console.error("Program not exist",prog);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)};func.UI.main.embed_loader=async function(SESSION_ID){var _session=SESSION_OBJ[SESSION_ID];const platform=func.runtime.platform;const browser_hash=platform.get_url_hash();var hash="";if(browser_hash)hash=browser_hash.substr(1);_session.SYS_GLOBAL_STR_BROWSER_HASH_ID=hash;_session.SYS_GLOBAL_STR_BROWSER_TITLE=platform.get_document()?.title||"";const init_system_ds=async function(){if(!["main"].includes(_session.opt.app_computing_mode)){await func.index.new_webworker(SESSION_ID,{menuName:"Main"})}const ret=await func.datasource.create(SESSION_ID,"system");func.index.set_ds_0_proxy(SESSION_ID);return ret};const set_SYS_GLOBAL_KEYS_STATE=async function(SESSION_ID,e,state){if(!_session?.DS_GLB?.[0])return;if(e.keyCode!==16&&e.keyCode!==17&&e.keyCode!==18&&e.keyCode!==91){return}var data={};if(e.keyCode===17){data.SYS_GLOBAL_BOL_CONTROL_KEY_STATE=state}if(e.keyCode===16){data.SYS_GLOBAL_BOL_SHIFT_KEY_STATE=state}if(e.keyCode===18){data.SYS_GLOBAL_BOL_ALT_KEY_STATE=state}if(e.keyCode===91){data.SYS_GLOBAL_BOL_COMMAND_KEY_STATE=state}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)};const start_workers=async function(){_session.WORKER_OBJ.fx=new func.utils.job_worker(SESSION_ID);_session.WORKER_OBJ.fx.init()};const create_embed_container=async function(){func.runtime.ui.ensure_embed_container(SESSION_ID)};const execute_PENDING_OPEN_URL_EVENTS=async function(){if(typeof func.events.execute_PENDING_OPEN_URL_EVENTS!=="undefined"&&glb.is_cordova){func.events.execute_PENDING_OPEN_URL_EVENTS()}};const remove_loader=async function(){document.querySelectorAll(".loader").forEach(function(el){el.remove()});const root_node=func.runtime.ui.get_first_node(_session.root_element);if(root_node?.classList){root_node.classList.remove("loader_background_color")}};const perform_callback=async function(){if(_session.api_callback){_session.api_callback("xuda_ready",SESSION_ID,SESSION_OBJ)}};const call_program=async function(){if(_session.route_id){const route_obj=await func.utils.DOCS_OBJ.get(SESSION_ID,_session.route_id);function flattenMenuItems(menu){let flatMenu={};function recurse(items){for(let item of items){flatMenu[item.id]=item;if(item.children&&item.children.length>0){recurse(item.children)}}}recurse(menu);return flatMenu}const flatMenu=flattenMenuItems(route_obj.routeMenu.menu);const menu_obj=flatMenu[_session.menu_id];if(_session.menu_id){if(menu_obj){_session.prog_id=menu_obj.prog_id;if(menu_obj.prog_params){_session.url_params={..._session.url_params,...menu_obj.prog_params}}if(menu_obj.global_params){_session.url_params={..._session.url_params,...menu_obj.global_params}}}}}if(!_session.prog_id)return;await func.utils.TREE_OBJ.get(SESSION_ID,_session.prog_id);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,_session.prog_id);if(screen_ret){func.UI.main.embed_prog_execute(SESSION_ID,_session.prog_id)}else{console.error("Program not exist",_session.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}};const register_run_background_plugins=async function(){if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE)return;for await(const[plugin_name,val]of Object.entries(APP_OBJ[_session.app_id].app_plugins_purchased)){if(val.installed&&val.run_in_background&&val.manifest?.["runtime.mjs"]?.exist){try{const plugin_runtime_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["runtime.mjs"].dist?"dist/":""}runtime.mjs`);if(val.manifest["runtime.mjs"].dist&&val.manifest?.["runtime.mjs"]?.css){const plugin_runtime_css_url=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,"dist/runtime.css");func.utils.load_css_on_demand(plugin_runtime_css_url)}const plugin_script=await import(plugin_runtime_src);eval(plugin_script);let plugin_setup_script_ret=null;if(val.manifest?.["index.mjs"]?.exist){const plugin_setup_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["index.mjs"].dist?"dist/":""}index.mjs`);let plugin_setup_script=await import(plugin_setup_src);if(plugin_setup_script){plugin_setup_script_ret=await func.utils.get_plugin_setup(SESSION_ID,plugin_name);if(plugin_setup_script_ret.code<0){throw plugin_setup_script_ret}}}glb.lifecycle.plugins[plugin_name]={plugin_script:plugin_script,setup_data:plugin_setup_script_ret?.data}}catch(err){console.error(err)}}}};async function updateOnlineStatus(){if(!_session?.DS_GLB?.[0])return;var data={};if(IS_ONLINE){data.SYS_GLOBAL_BOL_ONLINE=1}else{data.SYS_GLOBAL_BOL_ONLINE=0}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)}await register_run_background_plugins();func.runtime.ui.show_root_element(SESSION_ID);func.UI.component.create_app_root_component(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeInit");await start_workers();await init_system_ds();await glb.lifecycle.execute(SESSION_ID,"initialized");await create_embed_container();await execute_PENDING_OPEN_URL_EVENTS();await remove_loader();await func.UI.worker.init(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeMounted");await call_program();await glb.lifecycle.execute(SESSION_ID,"mounted");await perform_callback();func.utils.debug.write(SESSION_ID,"Xuda.ai started.");await glb.lifecycle.execute(SESSION_ID,"systemReady");if(func.runtime.platform.has_document()){document.addEventListener("keydown",function(e){func.runtime.platform.emit("keydown",e)});document.addEventListener("keyup",function(e){func.runtime.platform.emit("keyup",e)})}func.runtime.platform.on("keydown",function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,1)});func.runtime.platform.on("keyup",function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,0)});await updateOnlineStatus();platform.add_window_listener("online",updateOnlineStatus);platform.add_window_listener("offline",updateOnlineStatus);console.log("xuda.ai system ready.");platform.dispatch_body_event(glb.system_ready_event)};func.UI.main.set_custom_css=function(SESSION_ID,callbackP){const css=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system?.["SYS_GLOBAL_STR_SITE_CSS"];if(css){func.runtime.platform.inject_css(css)}callbackP()};func.index={};if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()})}else{setTimeout(function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()},0)}function xuda(...args){const platform=func.runtime.platform;const runtime_location=platform.get_location();let element=null;let opt={};let callback=null;for(const arg of args){if(platform.is_html_element(arg)){element=arg}else if(typeof arg==="object"&&arg!==null&&!Array.isArray(arg)){opt=arg}else if(typeof arg==="function"){callback=arg}}if(!element){if(typeof glb.SLIM_BUNDLE==="undefined"||!glb.SLIM_BUNDLE){return console.error("Xuda Error - element argument is empty")}element="body";console.warn("root element set to body")}if(typeof element==="string"?!document.querySelector(element):!element){return console.error("Xuda Error - element not found")}if(typeof opt==="undefined"){return console.error("Xuda Error - opt argument is undefined")}if(typeof opt!=="object"){return console.error("Xuda Error - opt argument is not an object")}glb.URL_PARAMS=func.common.getJsonFromUrl(platform.get_url_href());glb.worker_type="Worker";if(opt.debug_js){glb.debug_js=true;if((runtime_location?.host?.includes("localhost")||runtime_location?.host?.includes("127.0.0.1"))&&typeof glb.SLIM_BUNDLE==="undefined"&&typeof glb.CODE_BUNDLE==="undefined"){glb.worker_type="Dev"}else{glb.worker_type="Debug"}}const call_xuda=async function(){const _instance_id=Date.now().toString()+Math.round(Math.random()*1e4).toString();const _api_callback=callback;const create_index_html=function(){func.runtime.ui.ensure_app_shell(SESSION_ID,_session.domain)};const device_ready=async function(){return new Promise(function(resolve,reject){if(!func.utils.get_device()){return resolve()}platform.get_document().addEventListener("deviceready",function(){glb.is_cordova=true;resolve()},false)})};const get_fingerprint_component=async function(){return new Promise(function(resolve,reject){Fingerprint2.get(function(components){resolve(components)})})};const get_session_id=function(){return func.runtime.session.get_fingerprint(components,_instance_id)};const get_fingerprint=function(){return func.runtime.session.get_fingerprint(components)};const init_SESSION=function(){return func.runtime.session.create_state(SESSION_ID,{opt:opt,root_element:typeof element==="string"?document.querySelector(element):element,worker_type:glb.worker_type,api_callback:_api_callback,code_bundle:glb.CODE_BUNDLE,slim_bundle:glb.SLIM_BUNDLE,url_params:opt.url_params})};const set_SESSION=async function(){for await(const key of["gtp_token","app_token","prog_id","domain","engine_mode","crawler","app_id","route_id","menu_id","local_live_preview","project_data"]){_session[key]=func.UI.utils.get_url_attribute(SESSION_ID,key);if(!_session[key]){func.runtime.session.set_default_value(_session,key)}switch(key){case"domain":if(_session[key].includes("localhost")||_session[key].includes("127.0.0.1")){const getSubdomain=url=>{let domain=url;if(url.includes("://")){domain=url.split("://")[1]}let subdomain="";if(!_session[key].includes("127.0.0.1")){subdomain=domain.split(".")[0]}return subdomain};_session[key]=getSubdomain(_session[key])?getSubdomain(_session[key])+".xuda.ai":"xuda.ai"}break;case"project_data":{if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE){const{root_element}=_session;if(!_session[key]){_session[key]={}}if(!_session[key].programs){_session[key].programs={}}if(!_session[key].globals){_session[key].globals={_id:"globals",progDataSource:{},properties:{menuType:"globals"},studio_meta:{},progEvents:[],progFields:[]}}const _templates=document.querySelectorAll("template");if(_templates.length){const module=await func.common.get_module(SESSION_ID,"xuda-cli-plugin-html-parser-module.esm.mjs");_templates.forEach(function(el,idx){const _id=el.getAttribute("id")||"template_"+idx.toString();if(!_session[key].programs[_id]){_session[key].programs[_id]={_id:_id,progDataSource:{},properties:{menuType:"component",renderType:"form"},studio_meta:{},progEvents:[],progFields:[]}}if(el.innerHTML){window.xudaStringify=module.xudaStringify;const progUi=module.xudaPrase(el.innerHTML);_session[key].programs[_id].progUi=progUi?.[0]?.children||[]}});if(!_session.prog_id){_session.prog_id=_templates[0]?.getAttribute("id")||"template_0"}root_element.innerHTML=""}}break}default:break}}_session.crawler=opt.crawler};const set_SYS_GLOBAL_OBJ_CLIENT_INFO=function(){func.runtime.session.populate_client_info(_session,components)};const init_globals=function(){const{app_id,worker_type}=_session;if(worker_type!=="Worker"){glb.DEBUG_MODE=true}SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal=-1;PROJECT_OBJ[app_id]={};DOCS_OBJ[app_id]={};glb.APP_INFO[app_id]={};glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes(SESSION_ID);DATASOURCE_INTERVALS[SESSION_ID]={}};const print_version_info=function(){const version_name=`Xuda.ai ${opt.engine_mode} ${opt?.app_version||""} Session Id: ${SESSION_ID}`;const divider="#".repeat(version_name.length);console.info(divider);console.info(version_name);console.info(divider)};const print_xuda_banner=function(){var banner="";["__ ___ _ ____ _ ","\\ \\/ / | | | _ \\ / \\ "," \\ /| | | | | | |/ _ \\ "," / \\| |_| | |_| / ___ \\ ","/_/\\_\\\\___/|____/_/ \\_\\"].forEach(e=>{banner+=e+"\r\n"});console.info(banner)};print_xuda_banner();await func.index.checkConnectivity();var SESSION_ID=Date.now();var components;if(typeof glb.SLIM_BUNDLE==="undefined"||!glb.SLIM_BUNDLE){await device_ready();components=await get_fingerprint_component();SESSION_ID=get_session_id();print_version_info()}var _session=init_SESSION();await set_SESSION();create_index_html();APP_OBJ[_session.app_id]={};init_globals();if(typeof glb.SLIM_BUNDLE!=="undefined"&&glb.SLIM_BUNDLE){await func.UI.main.embed_loader(SESSION_ID);return}set_SYS_GLOBAL_OBJ_CLIENT_INFO(SESSION_ID);if(!_session.app_id){func.UI.utils.progressScreen.show(SESSION_ID,"Error reading app_id",false,true);console.error("no app_id found");return}const module=await func.common.get_module(SESSION_ID,"xuda-project-loader-module.esm.js");const db_adapter=await func.common.get_module(SESSION_ID,"xuda-db-adapter-module.mjs");func.db=db_adapter._db;await module.project_loader(SESSION_ID,_session.app_id);func.db.pouch.init_db_replication(SESSION_ID)};glb.system_ready_event=new Event("on_mounted");call_xuda();return{on_mounted:function(fn){document.body.addEventListener("on_mounted",e=>{fn()},false)}}}func.index.call_worker=async function(SESSION_ID,obj,params,promiseP){var _session=SESSION_OBJ[SESSION_ID];if(_session.opt.app_computing_mode==="main"){return}return new Promise(async function(resolve,reject){var worker_id;const set_promise_queue=function(worker_id){var t=glb.worker_queue_num++;try{func.runtime.workers.set_promise(SESSION_ID,worker_id,t,{resolve:promiseP?promiseP.resolve:resolve,reject:promiseP?promiseP.reject:reject,worker_id:worker_id})}catch(e){console.log(worker_id)}return t};const get_worker_id=function(ds){if(!_session.DS_GLB[ds]){if(ds==0){console.error("Error - onscreen (window,modal etc..) event cannot be invoked by on_load");return}else{return}}if(ds==0){return 1}if(_session.DS_GLB[ds].worker_id){return _session.DS_GLB[ds].worker_id}else{if(typeof _session.DS_GLB[ds].parentDataSourceNo!=="undefined"){return get_worker_id(_session.DS_GLB[ds].parentDataSourceNo)}}};if(obj.service==="datasource_create"){if(!params||params&&!params.done){var prog_obj=await func.utils.TREE_OBJ.get(SESSION_ID,obj.data.prog_id);if(!prog_obj||!prog_obj.dedicatedWorker){if(!Object.keys(WEB_WORKER[SESSION_ID]).length){worker_id=await func.index.new_webworker(SESSION_ID,{menuName:"Main"},obj)}else{if(obj.data.IS_DATASOURCE_REFRESH){worker_id=get_worker_id(obj.data.parentDataSourceNo)}else{worker_id=get_worker_id(obj.data.parentDataSourceNoP)}if(!worker_id){debugger}}}else{if(obj.data.IS_DATASOURCE_REFRESH){worker_id=get_worker_id(obj.data.parentDataSourceNo)}else{worker_id=await func.index.new_webworker(SESSION,prog_obj,obj);return _resolve()}}}else{worker_id=params.worker_id}}else{if(params&¶ms.worker_id){worker_id=params.worker_id}else{worker_id=get_worker_id(obj.data.dssession)}if(!worker_id)worker_id=1}try{var msg=obj;msg.worker_id=worker_id;if(!worker_id){console.warn("missing worker_id")}msg.promise_queue_id=set_promise_queue(worker_id);if(!WEB_WORKER[SESSION_ID][worker_id]){return resolve()}msg=JSON.stringify(obj,func.utils.clean_stringify_null,"\t");let msg_obj=JSON.parse(msg);if(!func.runtime.workers.is_server_transport(_session)){msg_obj.data=JSON.stringify(msg_obj.data)}func.runtime.workers.send_message(SESSION_ID,worker_id,_session,msg_obj,WEBSOCKET_PROCESS_PID)}catch(e){console.error(e);return reject(e)}})};func.index.init_SCREEN_BLOCKER=async function(SESSION_ID){const get_loader=async function(){if(func.runtime.session.is_slim(SESSION_ID)||typeof UI_FRAMEWORK_PLUGIN?.loader!=="function"){return{dismiss:function(){}}}return await UI_FRAMEWORK_PLUGIN.loader(LOADER_TEXT)};setInterval(async function(){if(glb.CURRENT_APP_LOADING||!LOADER_ACTIVE&&xu_isEmpty(SCREEN_BLOCKER_OBJ)){return}glb.CURRENT_APP_LOADING=1;const loader=await get_loader();glb.CURRENT_APP_LOADING=loader;var interval=setInterval(function(){if(xu_isEmpty(SCREEN_BLOCKER_OBJ)&&!LOADER_ACTIVE){if(glb.CURRENT_APP_LOADING){glb.CURRENT_APP_LOADING.dismiss()}clearInterval(interval);glb.CURRENT_APP_LOADING=null}},100)},1e3)};func.index.init_document_listeners=function(){const platform=func.runtime.platform;document.addEventListener("keydown",function(event){CLIENT_ACTIVITY_TS=Date.now();var keys={72:{key:"h",name:"Help",fx:function(){let SESSION_ID=Object.keys(SESSION_OBJ)[0];let _session=SESSION_OBJ[SESSION_ID];let app_id=_session.app_id;if(!_session.opt.enable_utility_screen)return;func.UI.utils.progressScreen.show(SESSION_ID,`
|
|
78
|
+
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,true,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){func.runtime.platform.emit(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.workflow?.[eventIdP].name.event;if(_field_obj?.workflow?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!xu_isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const resolve_update_field_id=async function(field_expr,iterate_info){let trimmed=field_expr?.trim?.()||"";if(!trimmed){return trimmed}const first=trimmed.substring(0,1);const last=trimmed.substring(trimmed.length-1);if((first==="'"||first==='"'||first==="`")&&last===first){trimmed=trimmed.substring(1,trimmed.length-1).trim()}if(/^@?[A-Za-z_][\w\-\:\.]*$/.test(trimmed)){return trimmed.substring(0,1)==="@"?trimmed.substring(1):trimmed}let ret_field_id=await func.expression.get(SESSION_ID,trimmed,dsSessionP,"update",null,null,null,null,null,null,iterate_info);if(typeof ret_field_id?.result==="string"&&ret_field_id.result.substring(0,1)==="@"){return ret_field_id.result.substring(1)}return ret_field_id?.result};const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||xu_isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;var iterate_info=null;if(elementP){const element_meta=func.runtime.ui.get_meta(elementP,"xuData");iterate_info=element_meta?.iterate_info||null}let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let _field_id=await resolve_update_field_id(val.id,iterate_info);let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes,null,null,triggerP);if(_ds.PARAM_OUT_INFO){for await(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds.dsSession,val.parentDataSourceNo)}}if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=payload_arr.reduce((ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){for(const[key2,val2]of Object.entries(_session.WORKER_OBJ.jobs)){if(key2===val){found=true;break}}}if(!found){do_callback();return}},100);var do_callback=function(){clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))func.runtime.platform.set_title(dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"])};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:params_obj.prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:null,source_functionP:"pendingUrlEvent_embed"})}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(xu_isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.action={};func.action.execute=async function(SESSION_ID,actionP,paramsP,isScreenActionP,event_sourceP,jobNoP,containerP){const module=await func.common.get_module(SESSION_ID,"xuda-actions-module.esm.js");await module.action_execute(SESSION_ID,actionP,paramsP,isScreenActionP,event_sourceP,jobNoP,containerP)};func.fcm={};func.UI.main={};func.UI.main.clear_SYNC_INTERVAL=function(){};func.UI.main.embed_prog_execute=async function(SESSION_ID,prog){var _session=SESSION_OBJ[SESSION_ID];const _prog=await func.utils.VIEWS_OBJ.get(SESSION_ID,prog);const get_params_obj=function(){var params_obj={};if(_prog?.properties?.progParams){for(const[key,val]of Object.entries(_prog.properties.progParams)){if(typeof _session.url_params?.[val.data.parameter]!=="undefined"){params_obj[val.data.parameter]=_session.url_params?.[val.data.parameter];continue}console.warn(`Warning: Program ${_prog.properties.menuName} expected In parameter: ${val.data.parameter} but received null instead`)}}return params_obj};let screen_ret=await func.utils.get_screen_obj(SESSION_ID,prog);if(screen_ret){let ret_init=await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:get_params_obj(),source_functionP:"call_embed"});func.runtime.platform.set_title(screen_ret.properties.menuTitle);return}console.error("Program not exist",prog);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)};func.UI.main.embed_loader=async function(SESSION_ID){var _session=SESSION_OBJ[SESSION_ID];const platform=func.runtime.platform;const browser_hash=platform.get_url_hash();var hash="";if(browser_hash)hash=browser_hash.substr(1);_session.SYS_GLOBAL_STR_BROWSER_HASH_ID=hash;_session.SYS_GLOBAL_STR_BROWSER_TITLE=platform.get_document()?.title||"";const init_system_ds=async function(){if(!["main"].includes(_session.opt.app_computing_mode)){await func.index.new_webworker(SESSION_ID,{menuName:"Main"})}const ret=await func.datasource.create(SESSION_ID,"system");func.index.set_ds_0_proxy(SESSION_ID);return ret};const set_SYS_GLOBAL_KEYS_STATE=async function(SESSION_ID,e,state){if(!_session?.DS_GLB?.[0])return;if(e.keyCode!==16&&e.keyCode!==17&&e.keyCode!==18&&e.keyCode!==91){return}var data={};if(e.keyCode===17){data.SYS_GLOBAL_BOL_CONTROL_KEY_STATE=state}if(e.keyCode===16){data.SYS_GLOBAL_BOL_SHIFT_KEY_STATE=state}if(e.keyCode===18){data.SYS_GLOBAL_BOL_ALT_KEY_STATE=state}if(e.keyCode===91){data.SYS_GLOBAL_BOL_COMMAND_KEY_STATE=state}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)};const start_workers=async function(){_session.WORKER_OBJ.fx=new func.utils.job_worker(SESSION_ID);_session.WORKER_OBJ.fx.init()};const create_embed_container=async function(){func.runtime.ui.ensure_embed_container(SESSION_ID)};const execute_PENDING_OPEN_URL_EVENTS=async function(){if(typeof func.events.execute_PENDING_OPEN_URL_EVENTS!=="undefined"&&glb.is_cordova){func.events.execute_PENDING_OPEN_URL_EVENTS()}};const remove_loader=async function(){document.querySelectorAll(".loader").forEach(function(el){el.remove()});const root_node=func.runtime.ui.get_first_node(_session.root_element);if(root_node?.classList){root_node.classList.remove("loader_background_color")}};const perform_callback=async function(){if(_session.api_callback){_session.api_callback("xuda_ready",SESSION_ID,SESSION_OBJ)}};const call_program=async function(){if(_session.route_id){const route_obj=await func.utils.DOCS_OBJ.get(SESSION_ID,_session.route_id);function flattenMenuItems(menu){let flatMenu={};function recurse(items){for(let item of items){flatMenu[item.id]=item;if(item.children&&item.children.length>0){recurse(item.children)}}}recurse(menu);return flatMenu}const flatMenu=flattenMenuItems(route_obj.routeMenu.menu);const menu_obj=flatMenu[_session.menu_id];if(_session.menu_id){if(menu_obj){_session.prog_id=menu_obj.prog_id;if(menu_obj.prog_params){_session.url_params={..._session.url_params,...menu_obj.prog_params}}if(menu_obj.global_params){_session.url_params={..._session.url_params,...menu_obj.global_params}}}}}if(!_session.prog_id)return;await func.utils.TREE_OBJ.get(SESSION_ID,_session.prog_id);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,_session.prog_id);if(screen_ret){func.UI.main.embed_prog_execute(SESSION_ID,_session.prog_id)}else{console.error("Program not exist",_session.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}};const register_run_background_plugins=async function(){if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE)return;for await(const[plugin_name,val]of Object.entries(APP_OBJ[_session.app_id].app_plugins_purchased)){if(val.installed&&val.run_in_background&&val.manifest?.["runtime.mjs"]?.exist){try{const plugin_runtime_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["runtime.mjs"].dist?"dist/":""}runtime.mjs`);if(val.manifest["runtime.mjs"].dist&&val.manifest?.["runtime.mjs"]?.css){const plugin_runtime_css_url=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,"dist/runtime.css");func.utils.load_css_on_demand(plugin_runtime_css_url)}const plugin_script=await import(plugin_runtime_src);eval(plugin_script);let plugin_setup_script_ret=null;if(val.manifest?.["index.mjs"]?.exist){const plugin_setup_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["index.mjs"].dist?"dist/":""}index.mjs`);let plugin_setup_script=await import(plugin_setup_src);if(plugin_setup_script){plugin_setup_script_ret=await func.utils.get_plugin_setup(SESSION_ID,plugin_name);if(plugin_setup_script_ret.code<0){throw plugin_setup_script_ret}}}glb.lifecycle.plugins[plugin_name]={plugin_script:plugin_script,setup_data:plugin_setup_script_ret?.data}}catch(err){console.error(err)}}}};async function updateOnlineStatus(){if(!_session?.DS_GLB?.[0])return;var data={};if(IS_ONLINE){data.SYS_GLOBAL_BOL_ONLINE=1}else{data.SYS_GLOBAL_BOL_ONLINE=0}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)}await register_run_background_plugins();func.runtime.ui.show_root_element(SESSION_ID);func.UI.component.create_app_root_component(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeInit");await start_workers();await init_system_ds();await glb.lifecycle.execute(SESSION_ID,"initialized");await create_embed_container();await execute_PENDING_OPEN_URL_EVENTS();await remove_loader();await func.UI.worker.init(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeMounted");await call_program();await glb.lifecycle.execute(SESSION_ID,"mounted");await perform_callback();func.utils.debug.write(SESSION_ID,"Xuda.ai started.");await glb.lifecycle.execute(SESSION_ID,"systemReady");if(func.runtime.platform.has_document()){document.addEventListener("keydown",function(e){func.runtime.platform.emit("keydown",e)});document.addEventListener("keyup",function(e){func.runtime.platform.emit("keyup",e)})}func.runtime.platform.on("keydown",function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,1)});func.runtime.platform.on("keyup",function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,0)});await updateOnlineStatus();platform.add_window_listener("online",updateOnlineStatus);platform.add_window_listener("offline",updateOnlineStatus);console.log("xuda.ai system ready.");platform.dispatch_body_event(glb.system_ready_event)};func.UI.main.set_custom_css=function(SESSION_ID,callbackP){const css=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system?.["SYS_GLOBAL_STR_SITE_CSS"];if(css){func.runtime.platform.inject_css(css)}callbackP()};func.index={};if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()})}else{setTimeout(function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()},0)}function xuda(...args){const platform=func.runtime.platform;const runtime_location=platform.get_location();let element=null;let opt={};let callback=null;for(const arg of args){if(platform.is_html_element(arg)){element=arg}else if(typeof arg==="object"&&arg!==null&&!Array.isArray(arg)){opt=arg}else if(typeof arg==="function"){callback=arg}}if(!element){if(typeof glb.SLIM_BUNDLE==="undefined"||!glb.SLIM_BUNDLE){return console.error("Xuda Error - element argument is empty")}element="body";console.warn("root element set to body")}if(typeof element==="string"?!document.querySelector(element):!element){return console.error("Xuda Error - element not found")}if(typeof opt==="undefined"){return console.error("Xuda Error - opt argument is undefined")}if(typeof opt!=="object"){return console.error("Xuda Error - opt argument is not an object")}glb.URL_PARAMS=func.common.getJsonFromUrl(platform.get_url_href());glb.worker_type="Worker";if(opt.debug_js){glb.debug_js=true;if((runtime_location?.host?.includes("localhost")||runtime_location?.host?.includes("127.0.0.1"))&&typeof glb.SLIM_BUNDLE==="undefined"&&typeof glb.CODE_BUNDLE==="undefined"){glb.worker_type="Dev"}else{glb.worker_type="Debug"}}const call_xuda=async function(){const _instance_id=Date.now().toString()+Math.round(Math.random()*1e4).toString();const _api_callback=callback;const create_index_html=function(){func.runtime.ui.ensure_app_shell(SESSION_ID,_session.domain)};const device_ready=async function(){return new Promise(function(resolve,reject){if(!func.utils.get_device()){return resolve()}platform.get_document().addEventListener("deviceready",function(){glb.is_cordova=true;resolve()},false)})};const get_fingerprint_component=async function(){return new Promise(function(resolve,reject){Fingerprint2.get(function(components){resolve(components)})})};const get_session_id=function(){return func.runtime.session.get_fingerprint(components,_instance_id)};const get_fingerprint=function(){return func.runtime.session.get_fingerprint(components)};const init_SESSION=function(){return func.runtime.session.create_state(SESSION_ID,{opt:opt,root_element:typeof element==="string"?document.querySelector(element):element,worker_type:glb.worker_type,api_callback:_api_callback,code_bundle:glb.CODE_BUNDLE,slim_bundle:glb.SLIM_BUNDLE,url_params:opt.url_params})};const set_SESSION=async function(){for await(const key of["gtp_token","app_token","prog_id","domain","engine_mode","crawler","app_id","route_id","menu_id","local_live_preview","project_data"]){_session[key]=func.UI.utils.get_url_attribute(SESSION_ID,key);if(!_session[key]){func.runtime.session.set_default_value(_session,key)}switch(key){case"domain":if(_session[key].includes("localhost")||_session[key].includes("127.0.0.1")){const getSubdomain=url=>{let domain=url;if(url.includes("://")){domain=url.split("://")[1]}let subdomain="";if(!_session[key].includes("127.0.0.1")){subdomain=domain.split(".")[0]}return subdomain};_session[key]=getSubdomain(_session[key])?getSubdomain(_session[key])+".xuda.ai":"xuda.ai"}break;case"project_data":{if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE){const{root_element}=_session;if(!_session[key]){_session[key]={}}if(!_session[key].programs){_session[key].programs={}}if(!_session[key].globals){_session[key].globals={_id:"globals",progDataSource:{},properties:{menuType:"globals"},studio_meta:{},progEvents:[],progFields:[]}}const _templates=document.querySelectorAll("template");if(_templates.length){const module=await func.common.get_module(SESSION_ID,"xuda-cli-plugin-html-parser-module.esm.mjs");_templates.forEach(function(el,idx){const _id=el.getAttribute("id")||"template_"+idx.toString();if(!_session[key].programs[_id]){_session[key].programs[_id]={_id:_id,progDataSource:{},properties:{menuType:"component",renderType:"form"},studio_meta:{},progEvents:[],progFields:[]}}if(el.innerHTML){window.xudaStringify=module.xudaStringify;const progUi=module.xudaPrase(el.innerHTML);_session[key].programs[_id].progUi=progUi?.[0]?.children||[]}});if(!_session.prog_id){_session.prog_id=_templates[0]?.getAttribute("id")||"template_0"}root_element.innerHTML=""}}break}default:break}}_session.crawler=opt.crawler};const set_SYS_GLOBAL_OBJ_CLIENT_INFO=function(){func.runtime.session.populate_client_info(_session,components)};const init_globals=function(){const{app_id,worker_type}=_session;if(worker_type!=="Worker"){glb.DEBUG_MODE=true}SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal=-1;PROJECT_OBJ[app_id]={};DOCS_OBJ[app_id]={};glb.APP_INFO[app_id]={};glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes(SESSION_ID);DATASOURCE_INTERVALS[SESSION_ID]={}};const print_version_info=function(){const version_name=`Xuda.ai ${opt.engine_mode} ${opt?.app_version||""} Session Id: ${SESSION_ID}`;const divider="#".repeat(version_name.length);console.info(divider);console.info(version_name);console.info(divider)};const print_xuda_banner=function(){var banner="";["__ ___ _ ____ _ ","\\ \\/ / | | | _ \\ / \\ "," \\ /| | | | | | |/ _ \\ "," / \\| |_| | |_| / ___ \\ ","/_/\\_\\\\___/|____/_/ \\_\\"].forEach(e=>{banner+=e+"\r\n"});console.info(banner)};print_xuda_banner();await func.index.checkConnectivity();var SESSION_ID=Date.now();var components;if(typeof glb.SLIM_BUNDLE==="undefined"||!glb.SLIM_BUNDLE){await device_ready();components=await get_fingerprint_component();SESSION_ID=get_session_id();print_version_info()}var _session=init_SESSION();await set_SESSION();create_index_html();APP_OBJ[_session.app_id]={};init_globals();if(typeof glb.SLIM_BUNDLE!=="undefined"&&glb.SLIM_BUNDLE){await func.UI.main.embed_loader(SESSION_ID);return}set_SYS_GLOBAL_OBJ_CLIENT_INFO(SESSION_ID);if(!_session.app_id){func.UI.utils.progressScreen.show(SESSION_ID,"Error reading app_id",false,true);console.error("no app_id found");return}const module=await func.common.get_module(SESSION_ID,"xuda-project-loader-module.esm.js");const db_adapter=await func.common.get_module(SESSION_ID,"xuda-db-adapter-module.mjs");func.db=db_adapter._db;await module.project_loader(SESSION_ID,_session.app_id);func.db.pouch.init_db_replication(SESSION_ID)};glb.system_ready_event=new Event("on_mounted");call_xuda();return{on_mounted:function(fn){document.body.addEventListener("on_mounted",e=>{fn()},false)}}}func.index.call_worker=async function(SESSION_ID,obj,params,promiseP){var _session=SESSION_OBJ[SESSION_ID];if(_session.opt.app_computing_mode==="main"){return}return new Promise(async function(resolve,reject){var worker_id;const set_promise_queue=function(worker_id){var t=glb.worker_queue_num++;try{func.runtime.workers.set_promise(SESSION_ID,worker_id,t,{resolve:promiseP?promiseP.resolve:resolve,reject:promiseP?promiseP.reject:reject,worker_id:worker_id})}catch(e){console.log(worker_id)}return t};const get_worker_id=function(ds){if(!_session.DS_GLB[ds]){if(ds==0){console.error("Error - onscreen (window,modal etc..) event cannot be invoked by on_load");return}else{return}}if(ds==0){return 1}if(_session.DS_GLB[ds].worker_id){return _session.DS_GLB[ds].worker_id}else{if(typeof _session.DS_GLB[ds].parentDataSourceNo!=="undefined"){return get_worker_id(_session.DS_GLB[ds].parentDataSourceNo)}}};if(obj.service==="datasource_create"){if(!params||params&&!params.done){var prog_obj=await func.utils.TREE_OBJ.get(SESSION_ID,obj.data.prog_id);if(!prog_obj||!prog_obj.dedicatedWorker){if(!Object.keys(WEB_WORKER[SESSION_ID]).length){worker_id=await func.index.new_webworker(SESSION_ID,{menuName:"Main"},obj)}else{if(obj.data.IS_DATASOURCE_REFRESH){worker_id=get_worker_id(obj.data.parentDataSourceNo)}else{worker_id=get_worker_id(obj.data.parentDataSourceNoP)}if(!worker_id){debugger}}}else{if(obj.data.IS_DATASOURCE_REFRESH){worker_id=get_worker_id(obj.data.parentDataSourceNo)}else{worker_id=await func.index.new_webworker(SESSION,prog_obj,obj);return _resolve()}}}else{worker_id=params.worker_id}}else{if(params&¶ms.worker_id){worker_id=params.worker_id}else{worker_id=get_worker_id(obj.data.dssession)}if(!worker_id)worker_id=1}try{var msg=obj;msg.worker_id=worker_id;if(!worker_id){console.warn("missing worker_id")}msg.promise_queue_id=set_promise_queue(worker_id);if(!WEB_WORKER[SESSION_ID][worker_id]){return resolve()}msg=JSON.stringify(obj,func.utils.clean_stringify_null,"\t");let msg_obj=JSON.parse(msg);if(!func.runtime.workers.is_server_transport(_session)){msg_obj.data=JSON.stringify(msg_obj.data)}func.runtime.workers.send_message(SESSION_ID,worker_id,_session,msg_obj,WEBSOCKET_PROCESS_PID)}catch(e){console.error(e);return reject(e)}})};func.index.init_SCREEN_BLOCKER=async function(SESSION_ID){const get_loader=async function(){if(func.runtime.session.is_slim(SESSION_ID)||typeof UI_FRAMEWORK_PLUGIN?.loader!=="function"){return{dismiss:function(){}}}return await UI_FRAMEWORK_PLUGIN.loader(LOADER_TEXT)};setInterval(async function(){if(glb.CURRENT_APP_LOADING||!LOADER_ACTIVE&&xu_isEmpty(SCREEN_BLOCKER_OBJ)){return}glb.CURRENT_APP_LOADING=1;const loader=await get_loader();glb.CURRENT_APP_LOADING=loader;var interval=setInterval(function(){if(xu_isEmpty(SCREEN_BLOCKER_OBJ)&&!LOADER_ACTIVE){if(glb.CURRENT_APP_LOADING){glb.CURRENT_APP_LOADING.dismiss()}clearInterval(interval);glb.CURRENT_APP_LOADING=null}},100)},1e3)};func.index.init_document_listeners=function(){const platform=func.runtime.platform;document.addEventListener("keydown",function(event){CLIENT_ACTIVITY_TS=Date.now();var keys={72:{key:"h",name:"Help",fx:function(){let SESSION_ID=Object.keys(SESSION_OBJ)[0];let _session=SESSION_OBJ[SESSION_ID];let app_id=_session.app_id;if(!_session.opt.enable_utility_screen)return;func.UI.utils.progressScreen.show(SESSION_ID,`
|
|
79
79
|
<center>Utility Screen</center>
|
|
80
80
|
<div class="help_screen">
|
|
81
81
|
<button name="hard_reload">
|
package/js/xuda-runtime-slim.js
CHANGED
|
@@ -19720,6 +19720,29 @@ func.events.execute = async function (
|
|
|
19720
19720
|
return result;
|
|
19721
19721
|
},
|
|
19722
19722
|
update: async function () {
|
|
19723
|
+
const resolve_update_field_id = async function (field_expr, iterate_info) {
|
|
19724
|
+
let trimmed = field_expr?.trim?.() || '';
|
|
19725
|
+
if (!trimmed) {
|
|
19726
|
+
return trimmed;
|
|
19727
|
+
}
|
|
19728
|
+
|
|
19729
|
+
const first = trimmed.substring(0, 1);
|
|
19730
|
+
const last = trimmed.substring(trimmed.length - 1);
|
|
19731
|
+
if ((first === "'" || first === '"' || first === '`') && last === first) {
|
|
19732
|
+
trimmed = trimmed.substring(1, trimmed.length - 1).trim();
|
|
19733
|
+
}
|
|
19734
|
+
|
|
19735
|
+
if (/^@?[A-Za-z_][\w\-\:\.]*$/.test(trimmed)) {
|
|
19736
|
+
return trimmed.substring(0, 1) === '@' ? trimmed.substring(1) : trimmed;
|
|
19737
|
+
}
|
|
19738
|
+
|
|
19739
|
+
let ret_field_id = await func.expression.get(SESSION_ID, trimmed, dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
|
|
19740
|
+
if (typeof ret_field_id?.result === 'string' && ret_field_id.result.substring(0, 1) === '@') {
|
|
19741
|
+
return ret_field_id.result.substring(1);
|
|
19742
|
+
}
|
|
19743
|
+
return ret_field_id?.result;
|
|
19744
|
+
};
|
|
19745
|
+
|
|
19723
19746
|
const obj_values_to_update = func.datasource.get_viewFields_for_update_function(SESSION_ID, calling_trigger_prop, null, dsSessionP);
|
|
19724
19747
|
if (!obj_values_to_update || xu_isEmpty(obj_values_to_update)) {
|
|
19725
19748
|
func.utils.debug_report(SESSION_ID, 'Update values object is empty', '', 'W');
|
|
@@ -19737,9 +19760,8 @@ func.events.execute = async function (
|
|
|
19737
19760
|
iterate_info = element_meta?.iterate_info || null;
|
|
19738
19761
|
}
|
|
19739
19762
|
|
|
19740
|
-
let ret_field_id = await func.expression.get(SESSION_ID, val.id.trim(), dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
|
|
19741
19763
|
let ret_value = await func.expression.get(SESSION_ID, val.val.trim(), dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
|
|
19742
|
-
let _field_id =
|
|
19764
|
+
let _field_id = await resolve_update_field_id(val.id, iterate_info);
|
|
19743
19765
|
let _value = ret_value.result;
|
|
19744
19766
|
|
|
19745
19767
|
updates.push({ _field_id, _value });
|
|
@@ -20411,6 +20411,29 @@ func.events.execute = async function (
|
|
|
20411
20411
|
return result;
|
|
20412
20412
|
},
|
|
20413
20413
|
update: async function () {
|
|
20414
|
+
const resolve_update_field_id = async function (field_expr, iterate_info) {
|
|
20415
|
+
let trimmed = field_expr?.trim?.() || '';
|
|
20416
|
+
if (!trimmed) {
|
|
20417
|
+
return trimmed;
|
|
20418
|
+
}
|
|
20419
|
+
|
|
20420
|
+
const first = trimmed.substring(0, 1);
|
|
20421
|
+
const last = trimmed.substring(trimmed.length - 1);
|
|
20422
|
+
if ((first === "'" || first === '"' || first === '`') && last === first) {
|
|
20423
|
+
trimmed = trimmed.substring(1, trimmed.length - 1).trim();
|
|
20424
|
+
}
|
|
20425
|
+
|
|
20426
|
+
if (/^@?[A-Za-z_][\w\-\:\.]*$/.test(trimmed)) {
|
|
20427
|
+
return trimmed.substring(0, 1) === '@' ? trimmed.substring(1) : trimmed;
|
|
20428
|
+
}
|
|
20429
|
+
|
|
20430
|
+
let ret_field_id = await func.expression.get(SESSION_ID, trimmed, dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
|
|
20431
|
+
if (typeof ret_field_id?.result === 'string' && ret_field_id.result.substring(0, 1) === '@') {
|
|
20432
|
+
return ret_field_id.result.substring(1);
|
|
20433
|
+
}
|
|
20434
|
+
return ret_field_id?.result;
|
|
20435
|
+
};
|
|
20436
|
+
|
|
20414
20437
|
const obj_values_to_update = func.datasource.get_viewFields_for_update_function(SESSION_ID, calling_trigger_prop, null, dsSessionP);
|
|
20415
20438
|
if (!obj_values_to_update || xu_isEmpty(obj_values_to_update)) {
|
|
20416
20439
|
func.utils.debug_report(SESSION_ID, 'Update values object is empty', '', 'W');
|
|
@@ -20428,9 +20451,8 @@ func.events.execute = async function (
|
|
|
20428
20451
|
iterate_info = element_meta?.iterate_info || null;
|
|
20429
20452
|
}
|
|
20430
20453
|
|
|
20431
|
-
let ret_field_id = await func.expression.get(SESSION_ID, val.id.trim(), dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
|
|
20432
20454
|
let ret_value = await func.expression.get(SESSION_ID, val.val.trim(), dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
|
|
20433
|
-
let _field_id =
|
|
20455
|
+
let _field_id = await resolve_update_field_id(val.id, iterate_info);
|
|
20434
20456
|
let _value = ret_value.result;
|
|
20435
20457
|
|
|
20436
20458
|
updates.push({ _field_id, _value });
|
|
@@ -69,7 +69,7 @@
|
|
|
69
69
|
${refIdP.value}
|
|
70
70
|
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,null,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},execute_evaluate_javascript:async function(){const module=await func.common.get_module(SESSION_ID,"xuda-event-javascript-module.mjs");const result=await module.run_javascript(SESSION_ID,jobNoP,dsSession,`(async function(el,evt) {
|
|
71
71
|
${refIdP.value}
|
|
72
|
-
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,true,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){func.runtime.platform.emit(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.workflow?.[eventIdP].name.event;if(_field_obj?.workflow?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!xu_isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||xu_isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;var iterate_info=null;if(elementP){const element_meta=func.runtime.ui.get_meta(elementP,"xuData");iterate_info=element_meta?.iterate_info||null}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let _field_id=ret_field_id.result;let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes,null,null,triggerP);if(_ds.PARAM_OUT_INFO){for await(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds.dsSession,val.parentDataSourceNo)}}if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=payload_arr.reduce((ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){for(const[key2,val2]of Object.entries(_session.WORKER_OBJ.jobs)){if(key2===val){found=true;break}}}if(!found){do_callback();return}},100);var do_callback=function(){clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))func.runtime.platform.set_title(dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"])};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:params_obj.prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:null,source_functionP:"pendingUrlEvent_embed"})}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(xu_isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.expression={};func.expression.get=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP,debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){class xu_class{async get(){if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=true}var ret;var fields={};var error;var warning;function evalJson(text){return eval("("+text+")")}if(valP===null){ret=""}else{switch(typeof valP){case"string":ret=valP;break;case"undefined":ret="";break;case"boolean":ret=valP?"Y":"N";break;default:ret=valP.toString();break}}if(ret.includes("&"))ret=ret.replace(/\&/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const end_results=function(){const replace_quotes=function(ret){for(const[key,val]of Object.entries(fields)){if(typeof val==="string")ret=ret.replace('"'+val+'"',val.replace(/"/gi,""))}return ret};if(["update","javascript"].includes(sourceP)){if(typeof ret==="string")ret=replace_quotes(ret)}const log_error=function(){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}};if(error)log_error();if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=false}const results={result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found};return results};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.startsWith("_DATE_")){ret=ret.slice(6)}else if(ret==="self"||ret&&ret.length===10&&ret[4]==="-"&&ret[7]==="-"){}else{ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}return end_results()}else{ret=ret.replace(/_NULL/gi,"");return end_results()}}catch(err){return end_results()}};if(!func.expression.validate_variables(valP)){return await variable_not_exist()}const validate_email=async function(){const ret=await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback,null,true);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const get_iterate_value_ret=function(fieldIdP){if(!iterate_info||iterate_info.iterator_key!==fieldIdP&&iterate_info.iterator_val!==fieldIdP){return null}const iter_value=iterate_info.iterator_key===fieldIdP?iterate_info._key:iterate_info._val;const iter_type=typeof iter_value!=="undefined"?{}.toString.call(iter_value).match(/\s([a-zA-Z]+)/)[1].toLowerCase():"string";return{ret:{value:iter_value,type:iter_type,prop:["array","object"].includes(iter_type)?iter_value:null},fieldIdP:fieldIdP,currentRecordId:rowIdP,found:typeof iter_value!=="undefined"}};const split=func.expression.parse(ret)||[];const split_entries=Object.entries(split);for(let entry_i=0;entry_i<split_entries.length;entry_i++){const[arr_key,val]=split_entries[entry_i];const key=Number(arr_key);var_Arr[key]={};var_Arr[key].value=val.value;const replace_value_in_string=async function(retP,fieldIdP){if(iterate_info?.iterator_key===fieldIdP||iterate_info?.iterator_val===fieldIdP){if(iterate_info.iterator_key===fieldIdP){retP.value=iterate_info._key}if(iterate_info.iterator_val===fieldIdP){retP.value=iterate_info._val}}const set_value=function(valP){if(typeof valP!=="undefined"){var_Arr[key].value=valP;if(typeof valP==="string")var_Arr[key].type="string"}else{if(retP.type==="object"){var_Arr[key].value="";var_Arr[key].type="string"}}};if(sourceP==="exp"&&retP.type!=="exp"){var_Arr[key].type=retP.type;return}if(typeof retP.value!=="undefined"){var_Arr[key].type=retP.type;var_Arr[key].value=typeof retP.value==="string"&&!retP.value.includes("<svg xmlns=")&&retP.value.indexOf("\\")===-1&&!["UI Attr EXP","update"].includes(sourceP)?retP.value.replaceAll('"','\\"'):retP.value;if(val.value.indexOf("[")>-1|val.value.indexOf(".")>-1){var data=retP.prop;if(retP.type==="object")data=retP.value;var property1,property2;if(val.value.indexOf("[")===-1&&val.value.indexOf("]")>-1&&val.value.substr(0,1)==="@"){var prevData=var_Arr[key-1].value;var_Arr[key].value=prevData[data];if(val.value.indexOf(".")>-1){const props_split=await func.expression.get_property(val.value);property2=props_split.property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{const props=await func.expression.get_property(val.value);property1=props.property1;property2=props.property2;if(property1){var_Arr[key].value=data[property1];if(property2){if(data[property1])set_value(data[property1][property2])}}if(property2&&!property1){if(data){set_value(data[property2])}}}fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}else{fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}}};if(val.fieldId){if(val.fieldId&&val.fieldId.substr(0,5)==="_THIS"&&calling_fieldIdP&&(val.fieldId.length===5||val.fieldId.length>5&&val.fieldId.substr(5,1)===".")){if(val.fieldId.length===5)val.fieldId=calling_fieldIdP;else val.fieldId=calling_fieldIdP+val.fieldId(5,val.fieldId.length-1)}if(!sourceP==="exp"){var_Arr[key].value='""'}fields[val.fieldId]=var_Arr[key].value;const ret=get_iterate_value_ret(val.fieldId)||await func.datasource.get_value(SESSION_ID,val.fieldId,dsSessionP,rowIdP);await replace_value_in_string(ret.ret,ret.fieldIdP)}}try{var res=[];var exp_exist;var var_error_found;var_Arr.forEach(function(val,key){if(sourceP==="UI Property EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,true);if(ret.changed){res[key]=ret.value;return true}}if(sourceP==="UI Attr EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,var_Arr.length==1?false:true);if(ret.changed){res[key]=ret.value;return true}}if(val.type==="exp"){exp_exist=true}res[key]=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){res[key]="`"+val.value+"`"}if(["api_rendered_output"].includes(sourceP)&&["json"].includes(api_output_type)&&["string","date"].includes(val.type)){res[key]=`"`+val.value+`"`}}if(val.fieldId&&val.value&&typeof val.value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP)){if(val.value.indexOf("↵")>-1){res[key]=val.value.split("↵").join("")}res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"")}if(["init","update","virtual"].includes(sourceP)){if(val.value.indexOf("↵")>-1)res[key]=val.value.split("↵").join("\n");res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"\\n")}if(typeof IS_PROCESS_SERVER!=="undefined"){res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"<br>")}fields[val.fieldId]=res[key]}if(typeof val.value==="object"&&var_Arr.length>1){if(!Array.isArray(val.value)&&!var_Arr[key+1].value?.includes(".")){res[key]="("+JSON.stringify(val.value)+")"}else{res[key]=JSON.stringify(val.value)}}if(!exp_exist&&sourceP!=="exp"&&val.value&&typeof val.value==="string"&&val.value.substr(0,1)==="@"){warning="Error encoding "+val.value;var_error_found=true;res[key]=0}});const join=function(arrP){return arrP.join("")};var exp=undefined;if(exp_exist&&sourceP!=="exp"){exp=await func.expression.get(SESSION_ID,join(res),dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);if(exp.res)res=exp.res;else res=[exp.result];fields=Object.assign(exp.fields,fieldsP)}var result=join(res);if(res.length===1){result=res[0]}if(secondPassP){ret=result}else if(sourceP!=="exp"){if(res.length===1&&typeof res[0]==="string"&&typeof res[0]!=="object"){ret=join(res);if(ret&&ret.substr(0,1)==="@"){error="Error encoding @ var";var_error_found=true}}else{if(!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,result,jobNo,dsSessionP,js_script_callback)}else{if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(result))}else{ret=result}}}}return end_results()}catch(err){ret=result;error=err.message;return end_results()}}}const new_class=new xu_class;return new_class.get()};func.expression._parse_cache=new Map;func.expression.parse=function(input){if(typeof input!=="string")return[];if(func.expression._parse_cache.has(input)){return func.expression._parse_cache.get(input).map(function(s){return Object.assign({},s)})}const segments=[];let pos=0;const parts=input.split(/(@\w+)/).filter(Boolean);for(const part of parts){if(part.startsWith("@")){const fieldId=part.slice(1);segments.push({value:part,fieldId:fieldId,pos:pos})}else{segments.push({value:part,pos:pos})}pos+=part.length}if(func.expression._parse_cache.size>=500){const firstKey=func.expression._parse_cache.keys().next().value;func.expression._parse_cache.delete(firstKey)}func.expression._parse_cache.set(input,segments);return segments.map(function(s){return Object.assign({},s)})};func.expression.get_property=async function(valP){async function secure_eval(val){if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(val)}catch(err){console.error(err);return}}try{let vm=new VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(val)}catch(err){throw""}}var property1,property2;if(valP.indexOf("[")>-1&&valP.indexOf("]")>-1){property1=valP.substr(valP.indexOf("[")+1,valP.indexOf("]")-valP.indexOf("[")-1);property1=await secure_eval(property1)}if(valP.indexOf(".")>-1)property2=valP.substr(valP.indexOf(".")+1,valP.length);return{property1:property1,property2:property2}};func.expression.validate_constant=function(valP){var patt=/["']/;if(typeof valP==="string"&&patt.test(valP.substr(0,1))&&patt.test(valP.substr(0,valP.length-1)))return true;else return false};func.expression.validate_variables=function(valP){if(typeof valP==="string"&&valP.indexOf("@")>-1)return true;else return false};func.expression.remove_quotes=function(valP){if(func.expression.validate_constant(valP))return valP.substr(1,valP.length-2);else return valP};func.expression.secure_eval=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt,ignore_errors){if(typeof val!=="string")return val;const xu=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const isServer=typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined";if(!isServer){try{return eval(val)}catch(err){try{if(sourceP==="javascript"&&!ignore_errors)console.error(err);return JSON5.parse(val)}catch(err){if(sourceP==="javascript"&&!ignore_errors)console.error(err);return val}}}const sandbox={func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,...sourceP==="javascript"?{axios:axios,got:got,FormData:FormData}:{}};const handleError=err=>{console.error("Execution error:",err);func.events.delete_job(SESSION_ID,job_id);if(isServer&&!SESSION_OBJ[SESSION_ID].crawler){if(sourceP==="javascript"){__.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}else{__.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}return val};if(sourceP==="javascript"){process.on("uncaughtException",handleError);try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules");const script=new VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, "${job_id}"); }`,{filename:dir,dirname:dir});const vm=new NodeVM({require:{external:true},sandbox:sandbox,timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){return handleError(err)}}try{const vm=new VM({sandbox:sandbox,timeout:1e3,allowAsync:false});return await vm.run(val)}catch{try{return JSON5.parse(val)}catch{return val}}};func.UI.main={};func.UI.main.clear_SYNC_INTERVAL=function(){};func.UI.main.embed_prog_execute=async function(SESSION_ID,prog){var _session=SESSION_OBJ[SESSION_ID];const _prog=await func.utils.VIEWS_OBJ.get(SESSION_ID,prog);const get_params_obj=function(){var params_obj={};if(_prog?.properties?.progParams){for(const[key,val]of Object.entries(_prog.properties.progParams)){if(typeof _session.url_params?.[val.data.parameter]!=="undefined"){params_obj[val.data.parameter]=_session.url_params?.[val.data.parameter];continue}console.warn(`Warning: Program ${_prog.properties.menuName} expected In parameter: ${val.data.parameter} but received null instead`)}}return params_obj};let screen_ret=await func.utils.get_screen_obj(SESSION_ID,prog);if(screen_ret){let ret_init=await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:get_params_obj(),source_functionP:"call_embed"});func.runtime.platform.set_title(screen_ret.properties.menuTitle);return}console.error("Program not exist",prog);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)};func.UI.main.embed_loader=async function(SESSION_ID){var _session=SESSION_OBJ[SESSION_ID];const platform=func.runtime.platform;const browser_hash=platform.get_url_hash();var hash="";if(browser_hash)hash=browser_hash.substr(1);_session.SYS_GLOBAL_STR_BROWSER_HASH_ID=hash;_session.SYS_GLOBAL_STR_BROWSER_TITLE=platform.get_document()?.title||"";const init_system_ds=async function(){if(!["main"].includes(_session.opt.app_computing_mode)){await func.index.new_webworker(SESSION_ID,{menuName:"Main"})}const ret=await func.datasource.create(SESSION_ID,"system");func.index.set_ds_0_proxy(SESSION_ID);return ret};const set_SYS_GLOBAL_KEYS_STATE=async function(SESSION_ID,e,state){if(!_session?.DS_GLB?.[0])return;if(e.keyCode!==16&&e.keyCode!==17&&e.keyCode!==18&&e.keyCode!==91){return}var data={};if(e.keyCode===17){data.SYS_GLOBAL_BOL_CONTROL_KEY_STATE=state}if(e.keyCode===16){data.SYS_GLOBAL_BOL_SHIFT_KEY_STATE=state}if(e.keyCode===18){data.SYS_GLOBAL_BOL_ALT_KEY_STATE=state}if(e.keyCode===91){data.SYS_GLOBAL_BOL_COMMAND_KEY_STATE=state}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)};const start_workers=async function(){_session.WORKER_OBJ.fx=new func.utils.job_worker(SESSION_ID);_session.WORKER_OBJ.fx.init()};const create_embed_container=async function(){func.runtime.ui.ensure_embed_container(SESSION_ID)};const execute_PENDING_OPEN_URL_EVENTS=async function(){if(typeof func.events.execute_PENDING_OPEN_URL_EVENTS!=="undefined"&&glb.is_cordova){func.events.execute_PENDING_OPEN_URL_EVENTS()}};const remove_loader=async function(){document.querySelectorAll(".loader").forEach(function(el){el.remove()});const root_node=func.runtime.ui.get_first_node(_session.root_element);if(root_node?.classList){root_node.classList.remove("loader_background_color")}};const perform_callback=async function(){if(_session.api_callback){_session.api_callback("xuda_ready",SESSION_ID,SESSION_OBJ)}};const call_program=async function(){if(_session.route_id){const route_obj=await func.utils.DOCS_OBJ.get(SESSION_ID,_session.route_id);function flattenMenuItems(menu){let flatMenu={};function recurse(items){for(let item of items){flatMenu[item.id]=item;if(item.children&&item.children.length>0){recurse(item.children)}}}recurse(menu);return flatMenu}const flatMenu=flattenMenuItems(route_obj.routeMenu.menu);const menu_obj=flatMenu[_session.menu_id];if(_session.menu_id){if(menu_obj){_session.prog_id=menu_obj.prog_id;if(menu_obj.prog_params){_session.url_params={..._session.url_params,...menu_obj.prog_params}}if(menu_obj.global_params){_session.url_params={..._session.url_params,...menu_obj.global_params}}}}}if(!_session.prog_id)return;await func.utils.TREE_OBJ.get(SESSION_ID,_session.prog_id);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,_session.prog_id);if(screen_ret){func.UI.main.embed_prog_execute(SESSION_ID,_session.prog_id)}else{console.error("Program not exist",_session.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}};const register_run_background_plugins=async function(){if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE)return;for await(const[plugin_name,val]of Object.entries(APP_OBJ[_session.app_id].app_plugins_purchased)){if(val.installed&&val.run_in_background&&val.manifest?.["runtime.mjs"]?.exist){try{const plugin_runtime_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["runtime.mjs"].dist?"dist/":""}runtime.mjs`);if(val.manifest["runtime.mjs"].dist&&val.manifest?.["runtime.mjs"]?.css){const plugin_runtime_css_url=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,"dist/runtime.css");func.utils.load_css_on_demand(plugin_runtime_css_url)}const plugin_script=await import(plugin_runtime_src);eval(plugin_script);let plugin_setup_script_ret=null;if(val.manifest?.["index.mjs"]?.exist){const plugin_setup_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["index.mjs"].dist?"dist/":""}index.mjs`);let plugin_setup_script=await import(plugin_setup_src);if(plugin_setup_script){plugin_setup_script_ret=await func.utils.get_plugin_setup(SESSION_ID,plugin_name);if(plugin_setup_script_ret.code<0){throw plugin_setup_script_ret}}}glb.lifecycle.plugins[plugin_name]={plugin_script:plugin_script,setup_data:plugin_setup_script_ret?.data}}catch(err){console.error(err)}}}};async function updateOnlineStatus(){if(!_session?.DS_GLB?.[0])return;var data={};if(IS_ONLINE){data.SYS_GLOBAL_BOL_ONLINE=1}else{data.SYS_GLOBAL_BOL_ONLINE=0}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)}await register_run_background_plugins();func.runtime.ui.show_root_element(SESSION_ID);func.UI.component.create_app_root_component(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeInit");await start_workers();await init_system_ds();await glb.lifecycle.execute(SESSION_ID,"initialized");await create_embed_container();await execute_PENDING_OPEN_URL_EVENTS();await remove_loader();await func.UI.worker.init(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeMounted");await call_program();await glb.lifecycle.execute(SESSION_ID,"mounted");await perform_callback();func.utils.debug.write(SESSION_ID,"Xuda.ai started.");await glb.lifecycle.execute(SESSION_ID,"systemReady");if(func.runtime.platform.has_document()){document.addEventListener("keydown",function(e){func.runtime.platform.emit("keydown",e)});document.addEventListener("keyup",function(e){func.runtime.platform.emit("keyup",e)})}func.runtime.platform.on("keydown",function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,1)});func.runtime.platform.on("keyup",function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,0)});await updateOnlineStatus();platform.add_window_listener("online",updateOnlineStatus);platform.add_window_listener("offline",updateOnlineStatus);console.log("xuda.ai system ready.");platform.dispatch_body_event(glb.system_ready_event)};func.UI.main.set_custom_css=function(SESSION_ID,callbackP){const css=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system?.["SYS_GLOBAL_STR_SITE_CSS"];if(css){func.runtime.platform.inject_css(css)}callbackP()};func.index={};if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()})}else{setTimeout(function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()},0)}function xuda(...args){const platform=func.runtime.platform;const runtime_location=platform.get_location();let element=null;let opt={};let callback=null;for(const arg of args){if(platform.is_html_element(arg)){element=arg}else if(typeof arg==="object"&&arg!==null&&!Array.isArray(arg)){opt=arg}else if(typeof arg==="function"){callback=arg}}if(!element){if(typeof glb.SLIM_BUNDLE==="undefined"||!glb.SLIM_BUNDLE){return console.error("Xuda Error - element argument is empty")}element="body";console.warn("root element set to body")}if(typeof element==="string"?!document.querySelector(element):!element){return console.error("Xuda Error - element not found")}if(typeof opt==="undefined"){return console.error("Xuda Error - opt argument is undefined")}if(typeof opt!=="object"){return console.error("Xuda Error - opt argument is not an object")}glb.URL_PARAMS=func.common.getJsonFromUrl(platform.get_url_href());glb.worker_type="Worker";if(opt.debug_js){glb.debug_js=true;if((runtime_location?.host?.includes("localhost")||runtime_location?.host?.includes("127.0.0.1"))&&typeof glb.SLIM_BUNDLE==="undefined"&&typeof glb.CODE_BUNDLE==="undefined"){glb.worker_type="Dev"}else{glb.worker_type="Debug"}}const call_xuda=async function(){const _instance_id=Date.now().toString()+Math.round(Math.random()*1e4).toString();const _api_callback=callback;const create_index_html=function(){func.runtime.ui.ensure_app_shell(SESSION_ID,_session.domain)};const device_ready=async function(){return new Promise(function(resolve,reject){if(!func.utils.get_device()){return resolve()}platform.get_document().addEventListener("deviceready",function(){glb.is_cordova=true;resolve()},false)})};const get_fingerprint_component=async function(){return new Promise(function(resolve,reject){Fingerprint2.get(function(components){resolve(components)})})};const get_session_id=function(){return func.runtime.session.get_fingerprint(components,_instance_id)};const get_fingerprint=function(){return func.runtime.session.get_fingerprint(components)};const init_SESSION=function(){return func.runtime.session.create_state(SESSION_ID,{opt:opt,root_element:typeof element==="string"?document.querySelector(element):element,worker_type:glb.worker_type,api_callback:_api_callback,code_bundle:glb.CODE_BUNDLE,slim_bundle:glb.SLIM_BUNDLE,url_params:opt.url_params})};const set_SESSION=async function(){for await(const key of["gtp_token","app_token","prog_id","domain","engine_mode","crawler","app_id","route_id","menu_id","local_live_preview","project_data"]){_session[key]=func.UI.utils.get_url_attribute(SESSION_ID,key);if(!_session[key]){func.runtime.session.set_default_value(_session,key)}switch(key){case"domain":if(_session[key].includes("localhost")||_session[key].includes("127.0.0.1")){const getSubdomain=url=>{let domain=url;if(url.includes("://")){domain=url.split("://")[1]}let subdomain="";if(!_session[key].includes("127.0.0.1")){subdomain=domain.split(".")[0]}return subdomain};_session[key]=getSubdomain(_session[key])?getSubdomain(_session[key])+".xuda.ai":"xuda.ai"}break;case"project_data":{if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE){const{root_element}=_session;if(!_session[key]){_session[key]={}}if(!_session[key].programs){_session[key].programs={}}if(!_session[key].globals){_session[key].globals={_id:"globals",progDataSource:{},properties:{menuType:"globals"},studio_meta:{},progEvents:[],progFields:[]}}const _templates=document.querySelectorAll("template");if(_templates.length){const module=await func.common.get_module(SESSION_ID,"xuda-cli-plugin-html-parser-module.esm.mjs");_templates.forEach(function(el,idx){const _id=el.getAttribute("id")||"template_"+idx.toString();if(!_session[key].programs[_id]){_session[key].programs[_id]={_id:_id,progDataSource:{},properties:{menuType:"component",renderType:"form"},studio_meta:{},progEvents:[],progFields:[]}}if(el.innerHTML){window.xudaStringify=module.xudaStringify;const progUi=module.xudaPrase(el.innerHTML);_session[key].programs[_id].progUi=progUi?.[0]?.children||[]}});if(!_session.prog_id){_session.prog_id=_templates[0]?.getAttribute("id")||"template_0"}root_element.innerHTML=""}}break}default:break}}_session.crawler=opt.crawler};const set_SYS_GLOBAL_OBJ_CLIENT_INFO=function(){func.runtime.session.populate_client_info(_session,components)};const init_globals=function(){const{app_id,worker_type}=_session;if(worker_type!=="Worker"){glb.DEBUG_MODE=true}SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal=-1;PROJECT_OBJ[app_id]={};DOCS_OBJ[app_id]={};glb.APP_INFO[app_id]={};glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes(SESSION_ID);DATASOURCE_INTERVALS[SESSION_ID]={}};const print_version_info=function(){const version_name=`Xuda.ai ${opt.engine_mode} ${opt?.app_version||""} Session Id: ${SESSION_ID}`;const divider="#".repeat(version_name.length);console.info(divider);console.info(version_name);console.info(divider)};const print_xuda_banner=function(){var banner="";["__ ___ _ ____ _ ","\\ \\/ / | | | _ \\ / \\ "," \\ /| | | | | | |/ _ \\ "," / \\| |_| | |_| / ___ \\ ","/_/\\_\\\\___/|____/_/ \\_\\"].forEach(e=>{banner+=e+"\r\n"});console.info(banner)};print_xuda_banner();await func.index.checkConnectivity();var SESSION_ID=Date.now();var components;if(typeof glb.SLIM_BUNDLE==="undefined"||!glb.SLIM_BUNDLE){await device_ready();components=await get_fingerprint_component();SESSION_ID=get_session_id();print_version_info()}var _session=init_SESSION();await set_SESSION();create_index_html();APP_OBJ[_session.app_id]={};init_globals();if(typeof glb.SLIM_BUNDLE!=="undefined"&&glb.SLIM_BUNDLE){await func.UI.main.embed_loader(SESSION_ID);return}set_SYS_GLOBAL_OBJ_CLIENT_INFO(SESSION_ID);if(!_session.app_id){func.UI.utils.progressScreen.show(SESSION_ID,"Error reading app_id",false,true);console.error("no app_id found");return}const module=await func.common.get_module(SESSION_ID,"xuda-project-loader-module.esm.js");const db_adapter=await func.common.get_module(SESSION_ID,"xuda-db-adapter-module.mjs");func.db=db_adapter._db;await module.project_loader(SESSION_ID,_session.app_id);func.db.pouch.init_db_replication(SESSION_ID)};glb.system_ready_event=new Event("on_mounted");call_xuda();return{on_mounted:function(fn){document.body.addEventListener("on_mounted",e=>{fn()},false)}}}func.index.call_worker=async function(SESSION_ID,obj,params,promiseP){var _session=SESSION_OBJ[SESSION_ID];if(_session.opt.app_computing_mode==="main"){return}return new Promise(async function(resolve,reject){var worker_id;const set_promise_queue=function(worker_id){var t=glb.worker_queue_num++;try{func.runtime.workers.set_promise(SESSION_ID,worker_id,t,{resolve:promiseP?promiseP.resolve:resolve,reject:promiseP?promiseP.reject:reject,worker_id:worker_id})}catch(e){console.log(worker_id)}return t};const get_worker_id=function(ds){if(!_session.DS_GLB[ds]){if(ds==0){console.error("Error - onscreen (window,modal etc..) event cannot be invoked by on_load");return}else{return}}if(ds==0){return 1}if(_session.DS_GLB[ds].worker_id){return _session.DS_GLB[ds].worker_id}else{if(typeof _session.DS_GLB[ds].parentDataSourceNo!=="undefined"){return get_worker_id(_session.DS_GLB[ds].parentDataSourceNo)}}};if(obj.service==="datasource_create"){if(!params||params&&!params.done){var prog_obj=await func.utils.TREE_OBJ.get(SESSION_ID,obj.data.prog_id);if(!prog_obj||!prog_obj.dedicatedWorker){if(!Object.keys(WEB_WORKER[SESSION_ID]).length){worker_id=await func.index.new_webworker(SESSION_ID,{menuName:"Main"},obj)}else{if(obj.data.IS_DATASOURCE_REFRESH){worker_id=get_worker_id(obj.data.parentDataSourceNo)}else{worker_id=get_worker_id(obj.data.parentDataSourceNoP)}if(!worker_id){debugger}}}else{if(obj.data.IS_DATASOURCE_REFRESH){worker_id=get_worker_id(obj.data.parentDataSourceNo)}else{worker_id=await func.index.new_webworker(SESSION,prog_obj,obj);return _resolve()}}}else{worker_id=params.worker_id}}else{if(params&¶ms.worker_id){worker_id=params.worker_id}else{worker_id=get_worker_id(obj.data.dssession)}if(!worker_id)worker_id=1}try{var msg=obj;msg.worker_id=worker_id;if(!worker_id){console.warn("missing worker_id")}msg.promise_queue_id=set_promise_queue(worker_id);if(!WEB_WORKER[SESSION_ID][worker_id]){return resolve()}msg=JSON.stringify(obj,func.utils.clean_stringify_null,"\t");let msg_obj=JSON.parse(msg);if(!func.runtime.workers.is_server_transport(_session)){msg_obj.data=JSON.stringify(msg_obj.data)}func.runtime.workers.send_message(SESSION_ID,worker_id,_session,msg_obj,WEBSOCKET_PROCESS_PID)}catch(e){console.error(e);return reject(e)}})};func.index.init_SCREEN_BLOCKER=async function(SESSION_ID){const get_loader=async function(){if(func.runtime.session.is_slim(SESSION_ID)||typeof UI_FRAMEWORK_PLUGIN?.loader!=="function"){return{dismiss:function(){}}}return await UI_FRAMEWORK_PLUGIN.loader(LOADER_TEXT)};setInterval(async function(){if(glb.CURRENT_APP_LOADING||!LOADER_ACTIVE&&xu_isEmpty(SCREEN_BLOCKER_OBJ)){return}glb.CURRENT_APP_LOADING=1;const loader=await get_loader();glb.CURRENT_APP_LOADING=loader;var interval=setInterval(function(){if(xu_isEmpty(SCREEN_BLOCKER_OBJ)&&!LOADER_ACTIVE){if(glb.CURRENT_APP_LOADING){glb.CURRENT_APP_LOADING.dismiss()}clearInterval(interval);glb.CURRENT_APP_LOADING=null}},100)},1e3)};func.index.init_document_listeners=function(){const platform=func.runtime.platform;document.addEventListener("keydown",function(event){CLIENT_ACTIVITY_TS=Date.now();var keys={72:{key:"h",name:"Help",fx:function(){let SESSION_ID=Object.keys(SESSION_OBJ)[0];let _session=SESSION_OBJ[SESSION_ID];let app_id=_session.app_id;if(!_session.opt.enable_utility_screen)return;func.UI.utils.progressScreen.show(SESSION_ID,`
|
|
72
|
+
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,true,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){func.runtime.platform.emit(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.workflow?.[eventIdP].name.event;if(_field_obj?.workflow?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!xu_isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const resolve_update_field_id=async function(field_expr,iterate_info){let trimmed=field_expr?.trim?.()||"";if(!trimmed){return trimmed}const first=trimmed.substring(0,1);const last=trimmed.substring(trimmed.length-1);if((first==="'"||first==='"'||first==="`")&&last===first){trimmed=trimmed.substring(1,trimmed.length-1).trim()}if(/^@?[A-Za-z_][\w\-\:\.]*$/.test(trimmed)){return trimmed.substring(0,1)==="@"?trimmed.substring(1):trimmed}let ret_field_id=await func.expression.get(SESSION_ID,trimmed,dsSessionP,"update",null,null,null,null,null,null,iterate_info);if(typeof ret_field_id?.result==="string"&&ret_field_id.result.substring(0,1)==="@"){return ret_field_id.result.substring(1)}return ret_field_id?.result};const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||xu_isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;var iterate_info=null;if(elementP){const element_meta=func.runtime.ui.get_meta(elementP,"xuData");iterate_info=element_meta?.iterate_info||null}let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let _field_id=await resolve_update_field_id(val.id,iterate_info);let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes,null,null,triggerP);if(_ds.PARAM_OUT_INFO){for await(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds.dsSession,val.parentDataSourceNo)}}if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=payload_arr.reduce((ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){for(const[key2,val2]of Object.entries(_session.WORKER_OBJ.jobs)){if(key2===val){found=true;break}}}if(!found){do_callback();return}},100);var do_callback=function(){clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))func.runtime.platform.set_title(dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"])};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:params_obj.prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:null,source_functionP:"pendingUrlEvent_embed"})}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(xu_isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.expression={};func.expression.get=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP,debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){class xu_class{async get(){if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=true}var ret;var fields={};var error;var warning;function evalJson(text){return eval("("+text+")")}if(valP===null){ret=""}else{switch(typeof valP){case"string":ret=valP;break;case"undefined":ret="";break;case"boolean":ret=valP?"Y":"N";break;default:ret=valP.toString();break}}if(ret.includes("&"))ret=ret.replace(/\&/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const end_results=function(){const replace_quotes=function(ret){for(const[key,val]of Object.entries(fields)){if(typeof val==="string")ret=ret.replace('"'+val+'"',val.replace(/"/gi,""))}return ret};if(["update","javascript"].includes(sourceP)){if(typeof ret==="string")ret=replace_quotes(ret)}const log_error=function(){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}};if(error)log_error();if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=false}const results={result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found};return results};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.startsWith("_DATE_")){ret=ret.slice(6)}else if(ret==="self"||ret&&ret.length===10&&ret[4]==="-"&&ret[7]==="-"){}else{ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}return end_results()}else{ret=ret.replace(/_NULL/gi,"");return end_results()}}catch(err){return end_results()}};if(!func.expression.validate_variables(valP)){return await variable_not_exist()}const validate_email=async function(){const ret=await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback,null,true);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const get_iterate_value_ret=function(fieldIdP){if(!iterate_info||iterate_info.iterator_key!==fieldIdP&&iterate_info.iterator_val!==fieldIdP){return null}const iter_value=iterate_info.iterator_key===fieldIdP?iterate_info._key:iterate_info._val;const iter_type=typeof iter_value!=="undefined"?{}.toString.call(iter_value).match(/\s([a-zA-Z]+)/)[1].toLowerCase():"string";return{ret:{value:iter_value,type:iter_type,prop:["array","object"].includes(iter_type)?iter_value:null},fieldIdP:fieldIdP,currentRecordId:rowIdP,found:typeof iter_value!=="undefined"}};const split=func.expression.parse(ret)||[];const split_entries=Object.entries(split);for(let entry_i=0;entry_i<split_entries.length;entry_i++){const[arr_key,val]=split_entries[entry_i];const key=Number(arr_key);var_Arr[key]={};var_Arr[key].value=val.value;const replace_value_in_string=async function(retP,fieldIdP){if(iterate_info?.iterator_key===fieldIdP||iterate_info?.iterator_val===fieldIdP){if(iterate_info.iterator_key===fieldIdP){retP.value=iterate_info._key}if(iterate_info.iterator_val===fieldIdP){retP.value=iterate_info._val}}const set_value=function(valP){if(typeof valP!=="undefined"){var_Arr[key].value=valP;if(typeof valP==="string")var_Arr[key].type="string"}else{if(retP.type==="object"){var_Arr[key].value="";var_Arr[key].type="string"}}};if(sourceP==="exp"&&retP.type!=="exp"){var_Arr[key].type=retP.type;return}if(typeof retP.value!=="undefined"){var_Arr[key].type=retP.type;var_Arr[key].value=typeof retP.value==="string"&&!retP.value.includes("<svg xmlns=")&&retP.value.indexOf("\\")===-1&&!["UI Attr EXP","update"].includes(sourceP)?retP.value.replaceAll('"','\\"'):retP.value;if(val.value.indexOf("[")>-1|val.value.indexOf(".")>-1){var data=retP.prop;if(retP.type==="object")data=retP.value;var property1,property2;if(val.value.indexOf("[")===-1&&val.value.indexOf("]")>-1&&val.value.substr(0,1)==="@"){var prevData=var_Arr[key-1].value;var_Arr[key].value=prevData[data];if(val.value.indexOf(".")>-1){const props_split=await func.expression.get_property(val.value);property2=props_split.property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{const props=await func.expression.get_property(val.value);property1=props.property1;property2=props.property2;if(property1){var_Arr[key].value=data[property1];if(property2){if(data[property1])set_value(data[property1][property2])}}if(property2&&!property1){if(data){set_value(data[property2])}}}fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}else{fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}}};if(val.fieldId){if(val.fieldId&&val.fieldId.substr(0,5)==="_THIS"&&calling_fieldIdP&&(val.fieldId.length===5||val.fieldId.length>5&&val.fieldId.substr(5,1)===".")){if(val.fieldId.length===5)val.fieldId=calling_fieldIdP;else val.fieldId=calling_fieldIdP+val.fieldId(5,val.fieldId.length-1)}if(!sourceP==="exp"){var_Arr[key].value='""'}fields[val.fieldId]=var_Arr[key].value;const ret=get_iterate_value_ret(val.fieldId)||await func.datasource.get_value(SESSION_ID,val.fieldId,dsSessionP,rowIdP);await replace_value_in_string(ret.ret,ret.fieldIdP)}}try{var res=[];var exp_exist;var var_error_found;var_Arr.forEach(function(val,key){if(sourceP==="UI Property EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,true);if(ret.changed){res[key]=ret.value;return true}}if(sourceP==="UI Attr EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,var_Arr.length==1?false:true);if(ret.changed){res[key]=ret.value;return true}}if(val.type==="exp"){exp_exist=true}res[key]=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){res[key]="`"+val.value+"`"}if(["api_rendered_output"].includes(sourceP)&&["json"].includes(api_output_type)&&["string","date"].includes(val.type)){res[key]=`"`+val.value+`"`}}if(val.fieldId&&val.value&&typeof val.value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP)){if(val.value.indexOf("↵")>-1){res[key]=val.value.split("↵").join("")}res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"")}if(["init","update","virtual"].includes(sourceP)){if(val.value.indexOf("↵")>-1)res[key]=val.value.split("↵").join("\n");res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"\\n")}if(typeof IS_PROCESS_SERVER!=="undefined"){res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"<br>")}fields[val.fieldId]=res[key]}if(typeof val.value==="object"&&var_Arr.length>1){if(!Array.isArray(val.value)&&!var_Arr[key+1].value?.includes(".")){res[key]="("+JSON.stringify(val.value)+")"}else{res[key]=JSON.stringify(val.value)}}if(!exp_exist&&sourceP!=="exp"&&val.value&&typeof val.value==="string"&&val.value.substr(0,1)==="@"){warning="Error encoding "+val.value;var_error_found=true;res[key]=0}});const join=function(arrP){return arrP.join("")};var exp=undefined;if(exp_exist&&sourceP!=="exp"){exp=await func.expression.get(SESSION_ID,join(res),dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);if(exp.res)res=exp.res;else res=[exp.result];fields=Object.assign(exp.fields,fieldsP)}var result=join(res);if(res.length===1){result=res[0]}if(secondPassP){ret=result}else if(sourceP!=="exp"){if(res.length===1&&typeof res[0]==="string"&&typeof res[0]!=="object"){ret=join(res);if(ret&&ret.substr(0,1)==="@"){error="Error encoding @ var";var_error_found=true}}else{if(!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,result,jobNo,dsSessionP,js_script_callback)}else{if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(result))}else{ret=result}}}}return end_results()}catch(err){ret=result;error=err.message;return end_results()}}}const new_class=new xu_class;return new_class.get()};func.expression._parse_cache=new Map;func.expression.parse=function(input){if(typeof input!=="string")return[];if(func.expression._parse_cache.has(input)){return func.expression._parse_cache.get(input).map(function(s){return Object.assign({},s)})}const segments=[];let pos=0;const parts=input.split(/(@\w+)/).filter(Boolean);for(const part of parts){if(part.startsWith("@")){const fieldId=part.slice(1);segments.push({value:part,fieldId:fieldId,pos:pos})}else{segments.push({value:part,pos:pos})}pos+=part.length}if(func.expression._parse_cache.size>=500){const firstKey=func.expression._parse_cache.keys().next().value;func.expression._parse_cache.delete(firstKey)}func.expression._parse_cache.set(input,segments);return segments.map(function(s){return Object.assign({},s)})};func.expression.get_property=async function(valP){async function secure_eval(val){if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(val)}catch(err){console.error(err);return}}try{let vm=new VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(val)}catch(err){throw""}}var property1,property2;if(valP.indexOf("[")>-1&&valP.indexOf("]")>-1){property1=valP.substr(valP.indexOf("[")+1,valP.indexOf("]")-valP.indexOf("[")-1);property1=await secure_eval(property1)}if(valP.indexOf(".")>-1)property2=valP.substr(valP.indexOf(".")+1,valP.length);return{property1:property1,property2:property2}};func.expression.validate_constant=function(valP){var patt=/["']/;if(typeof valP==="string"&&patt.test(valP.substr(0,1))&&patt.test(valP.substr(0,valP.length-1)))return true;else return false};func.expression.validate_variables=function(valP){if(typeof valP==="string"&&valP.indexOf("@")>-1)return true;else return false};func.expression.remove_quotes=function(valP){if(func.expression.validate_constant(valP))return valP.substr(1,valP.length-2);else return valP};func.expression.secure_eval=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt,ignore_errors){if(typeof val!=="string")return val;const xu=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const isServer=typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined";if(!isServer){try{return eval(val)}catch(err){try{if(sourceP==="javascript"&&!ignore_errors)console.error(err);return JSON5.parse(val)}catch(err){if(sourceP==="javascript"&&!ignore_errors)console.error(err);return val}}}const sandbox={func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,...sourceP==="javascript"?{axios:axios,got:got,FormData:FormData}:{}};const handleError=err=>{console.error("Execution error:",err);func.events.delete_job(SESSION_ID,job_id);if(isServer&&!SESSION_OBJ[SESSION_ID].crawler){if(sourceP==="javascript"){__.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}else{__.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}return val};if(sourceP==="javascript"){process.on("uncaughtException",handleError);try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules");const script=new VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, "${job_id}"); }`,{filename:dir,dirname:dir});const vm=new NodeVM({require:{external:true},sandbox:sandbox,timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){return handleError(err)}}try{const vm=new VM({sandbox:sandbox,timeout:1e3,allowAsync:false});return await vm.run(val)}catch{try{return JSON5.parse(val)}catch{return val}}};func.UI.main={};func.UI.main.clear_SYNC_INTERVAL=function(){};func.UI.main.embed_prog_execute=async function(SESSION_ID,prog){var _session=SESSION_OBJ[SESSION_ID];const _prog=await func.utils.VIEWS_OBJ.get(SESSION_ID,prog);const get_params_obj=function(){var params_obj={};if(_prog?.properties?.progParams){for(const[key,val]of Object.entries(_prog.properties.progParams)){if(typeof _session.url_params?.[val.data.parameter]!=="undefined"){params_obj[val.data.parameter]=_session.url_params?.[val.data.parameter];continue}console.warn(`Warning: Program ${_prog.properties.menuName} expected In parameter: ${val.data.parameter} but received null instead`)}}return params_obj};let screen_ret=await func.utils.get_screen_obj(SESSION_ID,prog);if(screen_ret){let ret_init=await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:get_params_obj(),source_functionP:"call_embed"});func.runtime.platform.set_title(screen_ret.properties.menuTitle);return}console.error("Program not exist",prog);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)};func.UI.main.embed_loader=async function(SESSION_ID){var _session=SESSION_OBJ[SESSION_ID];const platform=func.runtime.platform;const browser_hash=platform.get_url_hash();var hash="";if(browser_hash)hash=browser_hash.substr(1);_session.SYS_GLOBAL_STR_BROWSER_HASH_ID=hash;_session.SYS_GLOBAL_STR_BROWSER_TITLE=platform.get_document()?.title||"";const init_system_ds=async function(){if(!["main"].includes(_session.opt.app_computing_mode)){await func.index.new_webworker(SESSION_ID,{menuName:"Main"})}const ret=await func.datasource.create(SESSION_ID,"system");func.index.set_ds_0_proxy(SESSION_ID);return ret};const set_SYS_GLOBAL_KEYS_STATE=async function(SESSION_ID,e,state){if(!_session?.DS_GLB?.[0])return;if(e.keyCode!==16&&e.keyCode!==17&&e.keyCode!==18&&e.keyCode!==91){return}var data={};if(e.keyCode===17){data.SYS_GLOBAL_BOL_CONTROL_KEY_STATE=state}if(e.keyCode===16){data.SYS_GLOBAL_BOL_SHIFT_KEY_STATE=state}if(e.keyCode===18){data.SYS_GLOBAL_BOL_ALT_KEY_STATE=state}if(e.keyCode===91){data.SYS_GLOBAL_BOL_COMMAND_KEY_STATE=state}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)};const start_workers=async function(){_session.WORKER_OBJ.fx=new func.utils.job_worker(SESSION_ID);_session.WORKER_OBJ.fx.init()};const create_embed_container=async function(){func.runtime.ui.ensure_embed_container(SESSION_ID)};const execute_PENDING_OPEN_URL_EVENTS=async function(){if(typeof func.events.execute_PENDING_OPEN_URL_EVENTS!=="undefined"&&glb.is_cordova){func.events.execute_PENDING_OPEN_URL_EVENTS()}};const remove_loader=async function(){document.querySelectorAll(".loader").forEach(function(el){el.remove()});const root_node=func.runtime.ui.get_first_node(_session.root_element);if(root_node?.classList){root_node.classList.remove("loader_background_color")}};const perform_callback=async function(){if(_session.api_callback){_session.api_callback("xuda_ready",SESSION_ID,SESSION_OBJ)}};const call_program=async function(){if(_session.route_id){const route_obj=await func.utils.DOCS_OBJ.get(SESSION_ID,_session.route_id);function flattenMenuItems(menu){let flatMenu={};function recurse(items){for(let item of items){flatMenu[item.id]=item;if(item.children&&item.children.length>0){recurse(item.children)}}}recurse(menu);return flatMenu}const flatMenu=flattenMenuItems(route_obj.routeMenu.menu);const menu_obj=flatMenu[_session.menu_id];if(_session.menu_id){if(menu_obj){_session.prog_id=menu_obj.prog_id;if(menu_obj.prog_params){_session.url_params={..._session.url_params,...menu_obj.prog_params}}if(menu_obj.global_params){_session.url_params={..._session.url_params,...menu_obj.global_params}}}}}if(!_session.prog_id)return;await func.utils.TREE_OBJ.get(SESSION_ID,_session.prog_id);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,_session.prog_id);if(screen_ret){func.UI.main.embed_prog_execute(SESSION_ID,_session.prog_id)}else{console.error("Program not exist",_session.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}};const register_run_background_plugins=async function(){if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE)return;for await(const[plugin_name,val]of Object.entries(APP_OBJ[_session.app_id].app_plugins_purchased)){if(val.installed&&val.run_in_background&&val.manifest?.["runtime.mjs"]?.exist){try{const plugin_runtime_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["runtime.mjs"].dist?"dist/":""}runtime.mjs`);if(val.manifest["runtime.mjs"].dist&&val.manifest?.["runtime.mjs"]?.css){const plugin_runtime_css_url=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,"dist/runtime.css");func.utils.load_css_on_demand(plugin_runtime_css_url)}const plugin_script=await import(plugin_runtime_src);eval(plugin_script);let plugin_setup_script_ret=null;if(val.manifest?.["index.mjs"]?.exist){const plugin_setup_src=await func.utils.get_plugin_npm_cdn(SESSION_ID,plugin_name,`${val.manifest["index.mjs"].dist?"dist/":""}index.mjs`);let plugin_setup_script=await import(plugin_setup_src);if(plugin_setup_script){plugin_setup_script_ret=await func.utils.get_plugin_setup(SESSION_ID,plugin_name);if(plugin_setup_script_ret.code<0){throw plugin_setup_script_ret}}}glb.lifecycle.plugins[plugin_name]={plugin_script:plugin_script,setup_data:plugin_setup_script_ret?.data}}catch(err){console.error(err)}}}};async function updateOnlineStatus(){if(!_session?.DS_GLB?.[0])return;var data={};if(IS_ONLINE){data.SYS_GLOBAL_BOL_ONLINE=1}else{data.SYS_GLOBAL_BOL_ONLINE=0}var datasource_changes={[0]:{["data_system"]:data}};await func.datasource.update(SESSION_ID,datasource_changes)}await register_run_background_plugins();func.runtime.ui.show_root_element(SESSION_ID);func.UI.component.create_app_root_component(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeInit");await start_workers();await init_system_ds();await glb.lifecycle.execute(SESSION_ID,"initialized");await create_embed_container();await execute_PENDING_OPEN_URL_EVENTS();await remove_loader();await func.UI.worker.init(SESSION_ID);await glb.lifecycle.execute(SESSION_ID,"beforeMounted");await call_program();await glb.lifecycle.execute(SESSION_ID,"mounted");await perform_callback();func.utils.debug.write(SESSION_ID,"Xuda.ai started.");await glb.lifecycle.execute(SESSION_ID,"systemReady");if(func.runtime.platform.has_document()){document.addEventListener("keydown",function(e){func.runtime.platform.emit("keydown",e)});document.addEventListener("keyup",function(e){func.runtime.platform.emit("keyup",e)})}func.runtime.platform.on("keydown",function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,1)});func.runtime.platform.on("keyup",function(e){set_SYS_GLOBAL_KEYS_STATE(SESSION_ID,e,0)});await updateOnlineStatus();platform.add_window_listener("online",updateOnlineStatus);platform.add_window_listener("offline",updateOnlineStatus);console.log("xuda.ai system ready.");platform.dispatch_body_event(glb.system_ready_event)};func.UI.main.set_custom_css=function(SESSION_ID,callbackP){const css=SESSION_OBJ[SESSION_ID].DS_GLB[0].data_system?.["SYS_GLOBAL_STR_SITE_CSS"];if(css){func.runtime.platform.inject_css(css)}callbackP()};func.index={};if(document.readyState==="loading"){document.addEventListener("DOMContentLoaded",function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()})}else{setTimeout(function(){func.index.init_document_listeners();func.UI.utils.indicator.worker.normal();func.index.init_service_workers()},0)}function xuda(...args){const platform=func.runtime.platform;const runtime_location=platform.get_location();let element=null;let opt={};let callback=null;for(const arg of args){if(platform.is_html_element(arg)){element=arg}else if(typeof arg==="object"&&arg!==null&&!Array.isArray(arg)){opt=arg}else if(typeof arg==="function"){callback=arg}}if(!element){if(typeof glb.SLIM_BUNDLE==="undefined"||!glb.SLIM_BUNDLE){return console.error("Xuda Error - element argument is empty")}element="body";console.warn("root element set to body")}if(typeof element==="string"?!document.querySelector(element):!element){return console.error("Xuda Error - element not found")}if(typeof opt==="undefined"){return console.error("Xuda Error - opt argument is undefined")}if(typeof opt!=="object"){return console.error("Xuda Error - opt argument is not an object")}glb.URL_PARAMS=func.common.getJsonFromUrl(platform.get_url_href());glb.worker_type="Worker";if(opt.debug_js){glb.debug_js=true;if((runtime_location?.host?.includes("localhost")||runtime_location?.host?.includes("127.0.0.1"))&&typeof glb.SLIM_BUNDLE==="undefined"&&typeof glb.CODE_BUNDLE==="undefined"){glb.worker_type="Dev"}else{glb.worker_type="Debug"}}const call_xuda=async function(){const _instance_id=Date.now().toString()+Math.round(Math.random()*1e4).toString();const _api_callback=callback;const create_index_html=function(){func.runtime.ui.ensure_app_shell(SESSION_ID,_session.domain)};const device_ready=async function(){return new Promise(function(resolve,reject){if(!func.utils.get_device()){return resolve()}platform.get_document().addEventListener("deviceready",function(){glb.is_cordova=true;resolve()},false)})};const get_fingerprint_component=async function(){return new Promise(function(resolve,reject){Fingerprint2.get(function(components){resolve(components)})})};const get_session_id=function(){return func.runtime.session.get_fingerprint(components,_instance_id)};const get_fingerprint=function(){return func.runtime.session.get_fingerprint(components)};const init_SESSION=function(){return func.runtime.session.create_state(SESSION_ID,{opt:opt,root_element:typeof element==="string"?document.querySelector(element):element,worker_type:glb.worker_type,api_callback:_api_callback,code_bundle:glb.CODE_BUNDLE,slim_bundle:glb.SLIM_BUNDLE,url_params:opt.url_params})};const set_SESSION=async function(){for await(const key of["gtp_token","app_token","prog_id","domain","engine_mode","crawler","app_id","route_id","menu_id","local_live_preview","project_data"]){_session[key]=func.UI.utils.get_url_attribute(SESSION_ID,key);if(!_session[key]){func.runtime.session.set_default_value(_session,key)}switch(key){case"domain":if(_session[key].includes("localhost")||_session[key].includes("127.0.0.1")){const getSubdomain=url=>{let domain=url;if(url.includes("://")){domain=url.split("://")[1]}let subdomain="";if(!_session[key].includes("127.0.0.1")){subdomain=domain.split(".")[0]}return subdomain};_session[key]=getSubdomain(_session[key])?getSubdomain(_session[key])+".xuda.ai":"xuda.ai"}break;case"project_data":{if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE){const{root_element}=_session;if(!_session[key]){_session[key]={}}if(!_session[key].programs){_session[key].programs={}}if(!_session[key].globals){_session[key].globals={_id:"globals",progDataSource:{},properties:{menuType:"globals"},studio_meta:{},progEvents:[],progFields:[]}}const _templates=document.querySelectorAll("template");if(_templates.length){const module=await func.common.get_module(SESSION_ID,"xuda-cli-plugin-html-parser-module.esm.mjs");_templates.forEach(function(el,idx){const _id=el.getAttribute("id")||"template_"+idx.toString();if(!_session[key].programs[_id]){_session[key].programs[_id]={_id:_id,progDataSource:{},properties:{menuType:"component",renderType:"form"},studio_meta:{},progEvents:[],progFields:[]}}if(el.innerHTML){window.xudaStringify=module.xudaStringify;const progUi=module.xudaPrase(el.innerHTML);_session[key].programs[_id].progUi=progUi?.[0]?.children||[]}});if(!_session.prog_id){_session.prog_id=_templates[0]?.getAttribute("id")||"template_0"}root_element.innerHTML=""}}break}default:break}}_session.crawler=opt.crawler};const set_SYS_GLOBAL_OBJ_CLIENT_INFO=function(){func.runtime.session.populate_client_info(_session,components)};const init_globals=function(){const{app_id,worker_type}=_session;if(worker_type!=="Worker"){glb.DEBUG_MODE=true}SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal=-1;PROJECT_OBJ[app_id]={};DOCS_OBJ[app_id]={};glb.APP_INFO[app_id]={};glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes(SESSION_ID);DATASOURCE_INTERVALS[SESSION_ID]={}};const print_version_info=function(){const version_name=`Xuda.ai ${opt.engine_mode} ${opt?.app_version||""} Session Id: ${SESSION_ID}`;const divider="#".repeat(version_name.length);console.info(divider);console.info(version_name);console.info(divider)};const print_xuda_banner=function(){var banner="";["__ ___ _ ____ _ ","\\ \\/ / | | | _ \\ / \\ "," \\ /| | | | | | |/ _ \\ "," / \\| |_| | |_| / ___ \\ ","/_/\\_\\\\___/|____/_/ \\_\\"].forEach(e=>{banner+=e+"\r\n"});console.info(banner)};print_xuda_banner();await func.index.checkConnectivity();var SESSION_ID=Date.now();var components;if(typeof glb.SLIM_BUNDLE==="undefined"||!glb.SLIM_BUNDLE){await device_ready();components=await get_fingerprint_component();SESSION_ID=get_session_id();print_version_info()}var _session=init_SESSION();await set_SESSION();create_index_html();APP_OBJ[_session.app_id]={};init_globals();if(typeof glb.SLIM_BUNDLE!=="undefined"&&glb.SLIM_BUNDLE){await func.UI.main.embed_loader(SESSION_ID);return}set_SYS_GLOBAL_OBJ_CLIENT_INFO(SESSION_ID);if(!_session.app_id){func.UI.utils.progressScreen.show(SESSION_ID,"Error reading app_id",false,true);console.error("no app_id found");return}const module=await func.common.get_module(SESSION_ID,"xuda-project-loader-module.esm.js");const db_adapter=await func.common.get_module(SESSION_ID,"xuda-db-adapter-module.mjs");func.db=db_adapter._db;await module.project_loader(SESSION_ID,_session.app_id);func.db.pouch.init_db_replication(SESSION_ID)};glb.system_ready_event=new Event("on_mounted");call_xuda();return{on_mounted:function(fn){document.body.addEventListener("on_mounted",e=>{fn()},false)}}}func.index.call_worker=async function(SESSION_ID,obj,params,promiseP){var _session=SESSION_OBJ[SESSION_ID];if(_session.opt.app_computing_mode==="main"){return}return new Promise(async function(resolve,reject){var worker_id;const set_promise_queue=function(worker_id){var t=glb.worker_queue_num++;try{func.runtime.workers.set_promise(SESSION_ID,worker_id,t,{resolve:promiseP?promiseP.resolve:resolve,reject:promiseP?promiseP.reject:reject,worker_id:worker_id})}catch(e){console.log(worker_id)}return t};const get_worker_id=function(ds){if(!_session.DS_GLB[ds]){if(ds==0){console.error("Error - onscreen (window,modal etc..) event cannot be invoked by on_load");return}else{return}}if(ds==0){return 1}if(_session.DS_GLB[ds].worker_id){return _session.DS_GLB[ds].worker_id}else{if(typeof _session.DS_GLB[ds].parentDataSourceNo!=="undefined"){return get_worker_id(_session.DS_GLB[ds].parentDataSourceNo)}}};if(obj.service==="datasource_create"){if(!params||params&&!params.done){var prog_obj=await func.utils.TREE_OBJ.get(SESSION_ID,obj.data.prog_id);if(!prog_obj||!prog_obj.dedicatedWorker){if(!Object.keys(WEB_WORKER[SESSION_ID]).length){worker_id=await func.index.new_webworker(SESSION_ID,{menuName:"Main"},obj)}else{if(obj.data.IS_DATASOURCE_REFRESH){worker_id=get_worker_id(obj.data.parentDataSourceNo)}else{worker_id=get_worker_id(obj.data.parentDataSourceNoP)}if(!worker_id){debugger}}}else{if(obj.data.IS_DATASOURCE_REFRESH){worker_id=get_worker_id(obj.data.parentDataSourceNo)}else{worker_id=await func.index.new_webworker(SESSION,prog_obj,obj);return _resolve()}}}else{worker_id=params.worker_id}}else{if(params&¶ms.worker_id){worker_id=params.worker_id}else{worker_id=get_worker_id(obj.data.dssession)}if(!worker_id)worker_id=1}try{var msg=obj;msg.worker_id=worker_id;if(!worker_id){console.warn("missing worker_id")}msg.promise_queue_id=set_promise_queue(worker_id);if(!WEB_WORKER[SESSION_ID][worker_id]){return resolve()}msg=JSON.stringify(obj,func.utils.clean_stringify_null,"\t");let msg_obj=JSON.parse(msg);if(!func.runtime.workers.is_server_transport(_session)){msg_obj.data=JSON.stringify(msg_obj.data)}func.runtime.workers.send_message(SESSION_ID,worker_id,_session,msg_obj,WEBSOCKET_PROCESS_PID)}catch(e){console.error(e);return reject(e)}})};func.index.init_SCREEN_BLOCKER=async function(SESSION_ID){const get_loader=async function(){if(func.runtime.session.is_slim(SESSION_ID)||typeof UI_FRAMEWORK_PLUGIN?.loader!=="function"){return{dismiss:function(){}}}return await UI_FRAMEWORK_PLUGIN.loader(LOADER_TEXT)};setInterval(async function(){if(glb.CURRENT_APP_LOADING||!LOADER_ACTIVE&&xu_isEmpty(SCREEN_BLOCKER_OBJ)){return}glb.CURRENT_APP_LOADING=1;const loader=await get_loader();glb.CURRENT_APP_LOADING=loader;var interval=setInterval(function(){if(xu_isEmpty(SCREEN_BLOCKER_OBJ)&&!LOADER_ACTIVE){if(glb.CURRENT_APP_LOADING){glb.CURRENT_APP_LOADING.dismiss()}clearInterval(interval);glb.CURRENT_APP_LOADING=null}},100)},1e3)};func.index.init_document_listeners=function(){const platform=func.runtime.platform;document.addEventListener("keydown",function(event){CLIENT_ACTIVITY_TS=Date.now();var keys={72:{key:"h",name:"Help",fx:function(){let SESSION_ID=Object.keys(SESSION_OBJ)[0];let _session=SESSION_OBJ[SESSION_ID];let app_id=_session.app_id;if(!_session.opt.enable_utility_screen)return;func.UI.utils.progressScreen.show(SESSION_ID,`
|
|
73
73
|
<center>Utility Screen</center>
|
|
74
74
|
<div class="help_screen">
|
|
75
75
|
<button name="hard_reload">
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
${refIdP.value}
|
|
3
3
|
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,null,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},execute_evaluate_javascript:async function(){const module=await func.common.get_module(SESSION_ID,"xuda-event-javascript-module.mjs");const result=await module.run_javascript(SESSION_ID,jobNoP,dsSession,`(async function(el,evt) {
|
|
4
4
|
${refIdP.value}
|
|
5
|
-
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,true,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){func.runtime.platform.emit(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.workflow?.[eventIdP].name.event;if(_field_obj?.workflow?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!xu_isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||xu_isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;var iterate_info=null;if(elementP){const element_meta=func.runtime.ui.get_meta(elementP,"xuData");iterate_info=element_meta?.iterate_info||null}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let _field_id=ret_field_id.result;let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes,null,null,triggerP);if(_ds.PARAM_OUT_INFO){for await(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds.dsSession,val.parentDataSourceNo)}}if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=payload_arr.reduce((ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){for(const[key2,val2]of Object.entries(_session.WORKER_OBJ.jobs)){if(key2===val){found=true;break}}}if(!found){do_callback();return}},100);var do_callback=function(){clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))func.runtime.platform.set_title(dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"])};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:params_obj.prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:null,source_functionP:"pendingUrlEvent_embed"})}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(xu_isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.expression={};func.expression.get=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP,debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){class xu_class{async get(){if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=true}var ret;var fields={};var error;var warning;function evalJson(text){return eval("("+text+")")}if(valP===null){ret=""}else{switch(typeof valP){case"string":ret=valP;break;case"undefined":ret="";break;case"boolean":ret=valP?"Y":"N";break;default:ret=valP.toString();break}}if(ret.includes("&"))ret=ret.replace(/\&/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const end_results=function(){const replace_quotes=function(ret){for(const[key,val]of Object.entries(fields)){if(typeof val==="string")ret=ret.replace('"'+val+'"',val.replace(/"/gi,""))}return ret};if(["update","javascript"].includes(sourceP)){if(typeof ret==="string")ret=replace_quotes(ret)}const log_error=function(){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}};if(error)log_error();if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=false}const results={result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found};return results};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.startsWith("_DATE_")){ret=ret.slice(6)}else if(ret==="self"||ret&&ret.length===10&&ret[4]==="-"&&ret[7]==="-"){}else{ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}return end_results()}else{ret=ret.replace(/_NULL/gi,"");return end_results()}}catch(err){return end_results()}};if(!func.expression.validate_variables(valP)){return await variable_not_exist()}const validate_email=async function(){const ret=await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback,null,true);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const get_iterate_value_ret=function(fieldIdP){if(!iterate_info||iterate_info.iterator_key!==fieldIdP&&iterate_info.iterator_val!==fieldIdP){return null}const iter_value=iterate_info.iterator_key===fieldIdP?iterate_info._key:iterate_info._val;const iter_type=typeof iter_value!=="undefined"?{}.toString.call(iter_value).match(/\s([a-zA-Z]+)/)[1].toLowerCase():"string";return{ret:{value:iter_value,type:iter_type,prop:["array","object"].includes(iter_type)?iter_value:null},fieldIdP:fieldIdP,currentRecordId:rowIdP,found:typeof iter_value!=="undefined"}};const split=func.expression.parse(ret)||[];const split_entries=Object.entries(split);for(let entry_i=0;entry_i<split_entries.length;entry_i++){const[arr_key,val]=split_entries[entry_i];const key=Number(arr_key);var_Arr[key]={};var_Arr[key].value=val.value;const replace_value_in_string=async function(retP,fieldIdP){if(iterate_info?.iterator_key===fieldIdP||iterate_info?.iterator_val===fieldIdP){if(iterate_info.iterator_key===fieldIdP){retP.value=iterate_info._key}if(iterate_info.iterator_val===fieldIdP){retP.value=iterate_info._val}}const set_value=function(valP){if(typeof valP!=="undefined"){var_Arr[key].value=valP;if(typeof valP==="string")var_Arr[key].type="string"}else{if(retP.type==="object"){var_Arr[key].value="";var_Arr[key].type="string"}}};if(sourceP==="exp"&&retP.type!=="exp"){var_Arr[key].type=retP.type;return}if(typeof retP.value!=="undefined"){var_Arr[key].type=retP.type;var_Arr[key].value=typeof retP.value==="string"&&!retP.value.includes("<svg xmlns=")&&retP.value.indexOf("\\")===-1&&!["UI Attr EXP","update"].includes(sourceP)?retP.value.replaceAll('"','\\"'):retP.value;if(val.value.indexOf("[")>-1|val.value.indexOf(".")>-1){var data=retP.prop;if(retP.type==="object")data=retP.value;var property1,property2;if(val.value.indexOf("[")===-1&&val.value.indexOf("]")>-1&&val.value.substr(0,1)==="@"){var prevData=var_Arr[key-1].value;var_Arr[key].value=prevData[data];if(val.value.indexOf(".")>-1){const props_split=await func.expression.get_property(val.value);property2=props_split.property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{const props=await func.expression.get_property(val.value);property1=props.property1;property2=props.property2;if(property1){var_Arr[key].value=data[property1];if(property2){if(data[property1])set_value(data[property1][property2])}}if(property2&&!property1){if(data){set_value(data[property2])}}}fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}else{fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}}};if(val.fieldId){if(val.fieldId&&val.fieldId.substr(0,5)==="_THIS"&&calling_fieldIdP&&(val.fieldId.length===5||val.fieldId.length>5&&val.fieldId.substr(5,1)===".")){if(val.fieldId.length===5)val.fieldId=calling_fieldIdP;else val.fieldId=calling_fieldIdP+val.fieldId(5,val.fieldId.length-1)}if(!sourceP==="exp"){var_Arr[key].value='""'}fields[val.fieldId]=var_Arr[key].value;const ret=get_iterate_value_ret(val.fieldId)||await func.datasource.get_value(SESSION_ID,val.fieldId,dsSessionP,rowIdP);await replace_value_in_string(ret.ret,ret.fieldIdP)}}try{var res=[];var exp_exist;var var_error_found;var_Arr.forEach(function(val,key){if(sourceP==="UI Property EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,true);if(ret.changed){res[key]=ret.value;return true}}if(sourceP==="UI Attr EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,var_Arr.length==1?false:true);if(ret.changed){res[key]=ret.value;return true}}if(val.type==="exp"){exp_exist=true}res[key]=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){res[key]="`"+val.value+"`"}if(["api_rendered_output"].includes(sourceP)&&["json"].includes(api_output_type)&&["string","date"].includes(val.type)){res[key]=`"`+val.value+`"`}}if(val.fieldId&&val.value&&typeof val.value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP)){if(val.value.indexOf("↵")>-1){res[key]=val.value.split("↵").join("")}res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"")}if(["init","update","virtual"].includes(sourceP)){if(val.value.indexOf("↵")>-1)res[key]=val.value.split("↵").join("\n");res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"\\n")}if(typeof IS_PROCESS_SERVER!=="undefined"){res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"<br>")}fields[val.fieldId]=res[key]}if(typeof val.value==="object"&&var_Arr.length>1){if(!Array.isArray(val.value)&&!var_Arr[key+1].value?.includes(".")){res[key]="("+JSON.stringify(val.value)+")"}else{res[key]=JSON.stringify(val.value)}}if(!exp_exist&&sourceP!=="exp"&&val.value&&typeof val.value==="string"&&val.value.substr(0,1)==="@"){warning="Error encoding "+val.value;var_error_found=true;res[key]=0}});const join=function(arrP){return arrP.join("")};var exp=undefined;if(exp_exist&&sourceP!=="exp"){exp=await func.expression.get(SESSION_ID,join(res),dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);if(exp.res)res=exp.res;else res=[exp.result];fields=Object.assign(exp.fields,fieldsP)}var result=join(res);if(res.length===1){result=res[0]}if(secondPassP){ret=result}else if(sourceP!=="exp"){if(res.length===1&&typeof res[0]==="string"&&typeof res[0]!=="object"){ret=join(res);if(ret&&ret.substr(0,1)==="@"){error="Error encoding @ var";var_error_found=true}}else{if(!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,result,jobNo,dsSessionP,js_script_callback)}else{if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(result))}else{ret=result}}}}return end_results()}catch(err){ret=result;error=err.message;return end_results()}}}const new_class=new xu_class;return new_class.get()};func.expression._parse_cache=new Map;func.expression.parse=function(input){if(typeof input!=="string")return[];if(func.expression._parse_cache.has(input)){return func.expression._parse_cache.get(input).map(function(s){return Object.assign({},s)})}const segments=[];let pos=0;const parts=input.split(/(@\w+)/).filter(Boolean);for(const part of parts){if(part.startsWith("@")){const fieldId=part.slice(1);segments.push({value:part,fieldId:fieldId,pos:pos})}else{segments.push({value:part,pos:pos})}pos+=part.length}if(func.expression._parse_cache.size>=500){const firstKey=func.expression._parse_cache.keys().next().value;func.expression._parse_cache.delete(firstKey)}func.expression._parse_cache.set(input,segments);return segments.map(function(s){return Object.assign({},s)})};func.expression.get_property=async function(valP){async function secure_eval(val){if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(val)}catch(err){console.error(err);return}}try{let vm=new VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(val)}catch(err){throw""}}var property1,property2;if(valP.indexOf("[")>-1&&valP.indexOf("]")>-1){property1=valP.substr(valP.indexOf("[")+1,valP.indexOf("]")-valP.indexOf("[")-1);property1=await secure_eval(property1)}if(valP.indexOf(".")>-1)property2=valP.substr(valP.indexOf(".")+1,valP.length);return{property1:property1,property2:property2}};func.expression.validate_constant=function(valP){var patt=/["']/;if(typeof valP==="string"&&patt.test(valP.substr(0,1))&&patt.test(valP.substr(0,valP.length-1)))return true;else return false};func.expression.validate_variables=function(valP){if(typeof valP==="string"&&valP.indexOf("@")>-1)return true;else return false};func.expression.remove_quotes=function(valP){if(func.expression.validate_constant(valP))return valP.substr(1,valP.length-2);else return valP};func.expression.secure_eval=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt,ignore_errors){if(typeof val!=="string")return val;const xu=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const isServer=typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined";if(!isServer){try{return eval(val)}catch(err){try{if(sourceP==="javascript"&&!ignore_errors)console.error(err);return JSON5.parse(val)}catch(err){if(sourceP==="javascript"&&!ignore_errors)console.error(err);return val}}}const sandbox={func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,...sourceP==="javascript"?{axios:axios,got:got,FormData:FormData}:{}};const handleError=err=>{console.error("Execution error:",err);func.events.delete_job(SESSION_ID,job_id);if(isServer&&!SESSION_OBJ[SESSION_ID].crawler){if(sourceP==="javascript"){__.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}else{__.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}return val};if(sourceP==="javascript"){process.on("uncaughtException",handleError);try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules");const script=new VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, "${job_id}"); }`,{filename:dir,dirname:dir});const vm=new NodeVM({require:{external:true},sandbox:sandbox,timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){return handleError(err)}}try{const vm=new VM({sandbox:sandbox,timeout:1e3,allowAsync:false});return await vm.run(val)}catch{try{return JSON5.parse(val)}catch{return val}}}; export default {
|
|
5
|
+
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,true,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){func.runtime.platform.emit(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.workflow?.[eventIdP].name.event;if(_field_obj?.workflow?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!xu_isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const resolve_update_field_id=async function(field_expr,iterate_info){let trimmed=field_expr?.trim?.()||"";if(!trimmed){return trimmed}const first=trimmed.substring(0,1);const last=trimmed.substring(trimmed.length-1);if((first==="'"||first==='"'||first==="`")&&last===first){trimmed=trimmed.substring(1,trimmed.length-1).trim()}if(/^@?[A-Za-z_][\w\-\:\.]*$/.test(trimmed)){return trimmed.substring(0,1)==="@"?trimmed.substring(1):trimmed}let ret_field_id=await func.expression.get(SESSION_ID,trimmed,dsSessionP,"update",null,null,null,null,null,null,iterate_info);if(typeof ret_field_id?.result==="string"&&ret_field_id.result.substring(0,1)==="@"){return ret_field_id.result.substring(1)}return ret_field_id?.result};const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||xu_isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;var iterate_info=null;if(elementP){const element_meta=func.runtime.ui.get_meta(elementP,"xuData");iterate_info=element_meta?.iterate_info||null}let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let _field_id=await resolve_update_field_id(val.id,iterate_info);let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes,null,null,triggerP);if(_ds.PARAM_OUT_INFO){for await(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds.dsSession,val.parentDataSourceNo)}}if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=payload_arr.reduce((ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){for(const[key2,val2]of Object.entries(_session.WORKER_OBJ.jobs)){if(key2===val){found=true;break}}}if(!found){do_callback();return}},100);var do_callback=function(){clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))func.runtime.platform.set_title(dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"])};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:params_obj.prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:null,source_functionP:"pendingUrlEvent_embed"})}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(xu_isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.expression={};func.expression.get=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP,debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){class xu_class{async get(){if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=true}var ret;var fields={};var error;var warning;function evalJson(text){return eval("("+text+")")}if(valP===null){ret=""}else{switch(typeof valP){case"string":ret=valP;break;case"undefined":ret="";break;case"boolean":ret=valP?"Y":"N";break;default:ret=valP.toString();break}}if(ret.includes("&"))ret=ret.replace(/\&/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const end_results=function(){const replace_quotes=function(ret){for(const[key,val]of Object.entries(fields)){if(typeof val==="string")ret=ret.replace('"'+val+'"',val.replace(/"/gi,""))}return ret};if(["update","javascript"].includes(sourceP)){if(typeof ret==="string")ret=replace_quotes(ret)}const log_error=function(){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}};if(error)log_error();if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=false}const results={result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found};return results};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.startsWith("_DATE_")){ret=ret.slice(6)}else if(ret==="self"||ret&&ret.length===10&&ret[4]==="-"&&ret[7]==="-"){}else{ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}return end_results()}else{ret=ret.replace(/_NULL/gi,"");return end_results()}}catch(err){return end_results()}};if(!func.expression.validate_variables(valP)){return await variable_not_exist()}const validate_email=async function(){const ret=await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback,null,true);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const get_iterate_value_ret=function(fieldIdP){if(!iterate_info||iterate_info.iterator_key!==fieldIdP&&iterate_info.iterator_val!==fieldIdP){return null}const iter_value=iterate_info.iterator_key===fieldIdP?iterate_info._key:iterate_info._val;const iter_type=typeof iter_value!=="undefined"?{}.toString.call(iter_value).match(/\s([a-zA-Z]+)/)[1].toLowerCase():"string";return{ret:{value:iter_value,type:iter_type,prop:["array","object"].includes(iter_type)?iter_value:null},fieldIdP:fieldIdP,currentRecordId:rowIdP,found:typeof iter_value!=="undefined"}};const split=func.expression.parse(ret)||[];const split_entries=Object.entries(split);for(let entry_i=0;entry_i<split_entries.length;entry_i++){const[arr_key,val]=split_entries[entry_i];const key=Number(arr_key);var_Arr[key]={};var_Arr[key].value=val.value;const replace_value_in_string=async function(retP,fieldIdP){if(iterate_info?.iterator_key===fieldIdP||iterate_info?.iterator_val===fieldIdP){if(iterate_info.iterator_key===fieldIdP){retP.value=iterate_info._key}if(iterate_info.iterator_val===fieldIdP){retP.value=iterate_info._val}}const set_value=function(valP){if(typeof valP!=="undefined"){var_Arr[key].value=valP;if(typeof valP==="string")var_Arr[key].type="string"}else{if(retP.type==="object"){var_Arr[key].value="";var_Arr[key].type="string"}}};if(sourceP==="exp"&&retP.type!=="exp"){var_Arr[key].type=retP.type;return}if(typeof retP.value!=="undefined"){var_Arr[key].type=retP.type;var_Arr[key].value=typeof retP.value==="string"&&!retP.value.includes("<svg xmlns=")&&retP.value.indexOf("\\")===-1&&!["UI Attr EXP","update"].includes(sourceP)?retP.value.replaceAll('"','\\"'):retP.value;if(val.value.indexOf("[")>-1|val.value.indexOf(".")>-1){var data=retP.prop;if(retP.type==="object")data=retP.value;var property1,property2;if(val.value.indexOf("[")===-1&&val.value.indexOf("]")>-1&&val.value.substr(0,1)==="@"){var prevData=var_Arr[key-1].value;var_Arr[key].value=prevData[data];if(val.value.indexOf(".")>-1){const props_split=await func.expression.get_property(val.value);property2=props_split.property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{const props=await func.expression.get_property(val.value);property1=props.property1;property2=props.property2;if(property1){var_Arr[key].value=data[property1];if(property2){if(data[property1])set_value(data[property1][property2])}}if(property2&&!property1){if(data){set_value(data[property2])}}}fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}else{fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}}};if(val.fieldId){if(val.fieldId&&val.fieldId.substr(0,5)==="_THIS"&&calling_fieldIdP&&(val.fieldId.length===5||val.fieldId.length>5&&val.fieldId.substr(5,1)===".")){if(val.fieldId.length===5)val.fieldId=calling_fieldIdP;else val.fieldId=calling_fieldIdP+val.fieldId(5,val.fieldId.length-1)}if(!sourceP==="exp"){var_Arr[key].value='""'}fields[val.fieldId]=var_Arr[key].value;const ret=get_iterate_value_ret(val.fieldId)||await func.datasource.get_value(SESSION_ID,val.fieldId,dsSessionP,rowIdP);await replace_value_in_string(ret.ret,ret.fieldIdP)}}try{var res=[];var exp_exist;var var_error_found;var_Arr.forEach(function(val,key){if(sourceP==="UI Property EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,true);if(ret.changed){res[key]=ret.value;return true}}if(sourceP==="UI Attr EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,var_Arr.length==1?false:true);if(ret.changed){res[key]=ret.value;return true}}if(val.type==="exp"){exp_exist=true}res[key]=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){res[key]="`"+val.value+"`"}if(["api_rendered_output"].includes(sourceP)&&["json"].includes(api_output_type)&&["string","date"].includes(val.type)){res[key]=`"`+val.value+`"`}}if(val.fieldId&&val.value&&typeof val.value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP)){if(val.value.indexOf("↵")>-1){res[key]=val.value.split("↵").join("")}res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"")}if(["init","update","virtual"].includes(sourceP)){if(val.value.indexOf("↵")>-1)res[key]=val.value.split("↵").join("\n");res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"\\n")}if(typeof IS_PROCESS_SERVER!=="undefined"){res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"<br>")}fields[val.fieldId]=res[key]}if(typeof val.value==="object"&&var_Arr.length>1){if(!Array.isArray(val.value)&&!var_Arr[key+1].value?.includes(".")){res[key]="("+JSON.stringify(val.value)+")"}else{res[key]=JSON.stringify(val.value)}}if(!exp_exist&&sourceP!=="exp"&&val.value&&typeof val.value==="string"&&val.value.substr(0,1)==="@"){warning="Error encoding "+val.value;var_error_found=true;res[key]=0}});const join=function(arrP){return arrP.join("")};var exp=undefined;if(exp_exist&&sourceP!=="exp"){exp=await func.expression.get(SESSION_ID,join(res),dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);if(exp.res)res=exp.res;else res=[exp.result];fields=Object.assign(exp.fields,fieldsP)}var result=join(res);if(res.length===1){result=res[0]}if(secondPassP){ret=result}else if(sourceP!=="exp"){if(res.length===1&&typeof res[0]==="string"&&typeof res[0]!=="object"){ret=join(res);if(ret&&ret.substr(0,1)==="@"){error="Error encoding @ var";var_error_found=true}}else{if(!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,result,jobNo,dsSessionP,js_script_callback)}else{if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(result))}else{ret=result}}}}return end_results()}catch(err){ret=result;error=err.message;return end_results()}}}const new_class=new xu_class;return new_class.get()};func.expression._parse_cache=new Map;func.expression.parse=function(input){if(typeof input!=="string")return[];if(func.expression._parse_cache.has(input)){return func.expression._parse_cache.get(input).map(function(s){return Object.assign({},s)})}const segments=[];let pos=0;const parts=input.split(/(@\w+)/).filter(Boolean);for(const part of parts){if(part.startsWith("@")){const fieldId=part.slice(1);segments.push({value:part,fieldId:fieldId,pos:pos})}else{segments.push({value:part,pos:pos})}pos+=part.length}if(func.expression._parse_cache.size>=500){const firstKey=func.expression._parse_cache.keys().next().value;func.expression._parse_cache.delete(firstKey)}func.expression._parse_cache.set(input,segments);return segments.map(function(s){return Object.assign({},s)})};func.expression.get_property=async function(valP){async function secure_eval(val){if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(val)}catch(err){console.error(err);return}}try{let vm=new VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(val)}catch(err){throw""}}var property1,property2;if(valP.indexOf("[")>-1&&valP.indexOf("]")>-1){property1=valP.substr(valP.indexOf("[")+1,valP.indexOf("]")-valP.indexOf("[")-1);property1=await secure_eval(property1)}if(valP.indexOf(".")>-1)property2=valP.substr(valP.indexOf(".")+1,valP.length);return{property1:property1,property2:property2}};func.expression.validate_constant=function(valP){var patt=/["']/;if(typeof valP==="string"&&patt.test(valP.substr(0,1))&&patt.test(valP.substr(0,valP.length-1)))return true;else return false};func.expression.validate_variables=function(valP){if(typeof valP==="string"&&valP.indexOf("@")>-1)return true;else return false};func.expression.remove_quotes=function(valP){if(func.expression.validate_constant(valP))return valP.substr(1,valP.length-2);else return valP};func.expression.secure_eval=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt,ignore_errors){if(typeof val!=="string")return val;const xu=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const isServer=typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined";if(!isServer){try{return eval(val)}catch(err){try{if(sourceP==="javascript"&&!ignore_errors)console.error(err);return JSON5.parse(val)}catch(err){if(sourceP==="javascript"&&!ignore_errors)console.error(err);return val}}}const sandbox={func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,...sourceP==="javascript"?{axios:axios,got:got,FormData:FormData}:{}};const handleError=err=>{console.error("Execution error:",err);func.events.delete_job(SESSION_ID,job_id);if(isServer&&!SESSION_OBJ[SESSION_ID].crawler){if(sourceP==="javascript"){__.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}else{__.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}return val};if(sourceP==="javascript"){process.on("uncaughtException",handleError);try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules");const script=new VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, "${job_id}"); }`,{filename:dir,dirname:dir});const vm=new NodeVM({require:{external:true},sandbox:sandbox,timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){return handleError(err)}}try{const vm=new VM({sandbox:sandbox,timeout:1e3,allowAsync:false});return await vm.run(val)}catch{try{return JSON5.parse(val)}catch{return val}}}; export default {
|
|
6
6
|
glb,
|
|
7
7
|
func,
|
|
8
8
|
APP_OBJ,
|
|
@@ -8823,6 +8823,29 @@ func.events.execute = async function (
|
|
|
8823
8823
|
return result;
|
|
8824
8824
|
},
|
|
8825
8825
|
update: async function () {
|
|
8826
|
+
const resolve_update_field_id = async function (field_expr, iterate_info) {
|
|
8827
|
+
let trimmed = field_expr?.trim?.() || '';
|
|
8828
|
+
if (!trimmed) {
|
|
8829
|
+
return trimmed;
|
|
8830
|
+
}
|
|
8831
|
+
|
|
8832
|
+
const first = trimmed.substring(0, 1);
|
|
8833
|
+
const last = trimmed.substring(trimmed.length - 1);
|
|
8834
|
+
if ((first === "'" || first === '"' || first === '`') && last === first) {
|
|
8835
|
+
trimmed = trimmed.substring(1, trimmed.length - 1).trim();
|
|
8836
|
+
}
|
|
8837
|
+
|
|
8838
|
+
if (/^@?[A-Za-z_][\w\-\:\.]*$/.test(trimmed)) {
|
|
8839
|
+
return trimmed.substring(0, 1) === '@' ? trimmed.substring(1) : trimmed;
|
|
8840
|
+
}
|
|
8841
|
+
|
|
8842
|
+
let ret_field_id = await func.expression.get(SESSION_ID, trimmed, dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
|
|
8843
|
+
if (typeof ret_field_id?.result === 'string' && ret_field_id.result.substring(0, 1) === '@') {
|
|
8844
|
+
return ret_field_id.result.substring(1);
|
|
8845
|
+
}
|
|
8846
|
+
return ret_field_id?.result;
|
|
8847
|
+
};
|
|
8848
|
+
|
|
8826
8849
|
const obj_values_to_update = func.datasource.get_viewFields_for_update_function(SESSION_ID, calling_trigger_prop, null, dsSessionP);
|
|
8827
8850
|
if (!obj_values_to_update || xu_isEmpty(obj_values_to_update)) {
|
|
8828
8851
|
func.utils.debug_report(SESSION_ID, 'Update values object is empty', '', 'W');
|
|
@@ -8840,9 +8863,8 @@ func.events.execute = async function (
|
|
|
8840
8863
|
iterate_info = element_meta?.iterate_info || null;
|
|
8841
8864
|
}
|
|
8842
8865
|
|
|
8843
|
-
let ret_field_id = await func.expression.get(SESSION_ID, val.id.trim(), dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
|
|
8844
8866
|
let ret_value = await func.expression.get(SESSION_ID, val.val.trim(), dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
|
|
8845
|
-
let _field_id =
|
|
8867
|
+
let _field_id = await resolve_update_field_id(val.id, iterate_info);
|
|
8846
8868
|
let _value = ret_value.result;
|
|
8847
8869
|
|
|
8848
8870
|
updates.push({ _field_id, _value });
|
package/js/xuda-worker-bundle.js
CHANGED
|
@@ -8823,6 +8823,29 @@ func.events.execute = async function (
|
|
|
8823
8823
|
return result;
|
|
8824
8824
|
},
|
|
8825
8825
|
update: async function () {
|
|
8826
|
+
const resolve_update_field_id = async function (field_expr, iterate_info) {
|
|
8827
|
+
let trimmed = field_expr?.trim?.() || '';
|
|
8828
|
+
if (!trimmed) {
|
|
8829
|
+
return trimmed;
|
|
8830
|
+
}
|
|
8831
|
+
|
|
8832
|
+
const first = trimmed.substring(0, 1);
|
|
8833
|
+
const last = trimmed.substring(trimmed.length - 1);
|
|
8834
|
+
if ((first === "'" || first === '"' || first === '`') && last === first) {
|
|
8835
|
+
trimmed = trimmed.substring(1, trimmed.length - 1).trim();
|
|
8836
|
+
}
|
|
8837
|
+
|
|
8838
|
+
if (/^@?[A-Za-z_][\w\-\:\.]*$/.test(trimmed)) {
|
|
8839
|
+
return trimmed.substring(0, 1) === '@' ? trimmed.substring(1) : trimmed;
|
|
8840
|
+
}
|
|
8841
|
+
|
|
8842
|
+
let ret_field_id = await func.expression.get(SESSION_ID, trimmed, dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
|
|
8843
|
+
if (typeof ret_field_id?.result === 'string' && ret_field_id.result.substring(0, 1) === '@') {
|
|
8844
|
+
return ret_field_id.result.substring(1);
|
|
8845
|
+
}
|
|
8846
|
+
return ret_field_id?.result;
|
|
8847
|
+
};
|
|
8848
|
+
|
|
8826
8849
|
const obj_values_to_update = func.datasource.get_viewFields_for_update_function(SESSION_ID, calling_trigger_prop, null, dsSessionP);
|
|
8827
8850
|
if (!obj_values_to_update || xu_isEmpty(obj_values_to_update)) {
|
|
8828
8851
|
func.utils.debug_report(SESSION_ID, 'Update values object is empty', '', 'W');
|
|
@@ -8840,9 +8863,8 @@ func.events.execute = async function (
|
|
|
8840
8863
|
iterate_info = element_meta?.iterate_info || null;
|
|
8841
8864
|
}
|
|
8842
8865
|
|
|
8843
|
-
let ret_field_id = await func.expression.get(SESSION_ID, val.id.trim(), dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
|
|
8844
8866
|
let ret_value = await func.expression.get(SESSION_ID, val.val.trim(), dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
|
|
8845
|
-
let _field_id =
|
|
8867
|
+
let _field_id = await resolve_update_field_id(val.id, iterate_info);
|
|
8846
8868
|
let _value = ret_value.result;
|
|
8847
8869
|
|
|
8848
8870
|
updates.push({ _field_id, _value });
|
|
@@ -2,4 +2,4 @@
|
|
|
2
2
|
${refIdP.value}
|
|
3
3
|
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,null,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},execute_evaluate_javascript:async function(){const module=await func.common.get_module(SESSION_ID,"xuda-event-javascript-module.mjs");const result=await module.run_javascript(SESSION_ID,jobNoP,dsSession,`(async function(el,evt) {
|
|
4
4
|
${refIdP.value}
|
|
5
|
-
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,true,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){func.runtime.platform.emit(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.workflow?.[eventIdP].name.event;if(_field_obj?.workflow?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!xu_isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||xu_isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;var iterate_info=null;if(elementP){const element_meta=func.runtime.ui.get_meta(elementP,"xuData");iterate_info=element_meta?.iterate_info||null}let ret_field_id=await func.expression.get(SESSION_ID,val.id.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let _field_id=ret_field_id.result;let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes,null,null,triggerP);if(_ds.PARAM_OUT_INFO){for await(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds.dsSession,val.parentDataSourceNo)}}if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=payload_arr.reduce((ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){for(const[key2,val2]of Object.entries(_session.WORKER_OBJ.jobs)){if(key2===val){found=true;break}}}if(!found){do_callback();return}},100);var do_callback=function(){clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))func.runtime.platform.set_title(dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"])};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:params_obj.prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:null,source_functionP:"pendingUrlEvent_embed"})}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(xu_isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.expression={};func.expression.get=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP,debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){class xu_class{async get(){if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=true}var ret;var fields={};var error;var warning;function evalJson(text){return eval("("+text+")")}if(valP===null){ret=""}else{switch(typeof valP){case"string":ret=valP;break;case"undefined":ret="";break;case"boolean":ret=valP?"Y":"N";break;default:ret=valP.toString();break}}if(ret.includes("&"))ret=ret.replace(/\&/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const end_results=function(){const replace_quotes=function(ret){for(const[key,val]of Object.entries(fields)){if(typeof val==="string")ret=ret.replace('"'+val+'"',val.replace(/"/gi,""))}return ret};if(["update","javascript"].includes(sourceP)){if(typeof ret==="string")ret=replace_quotes(ret)}const log_error=function(){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}};if(error)log_error();if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=false}const results={result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found};return results};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.startsWith("_DATE_")){ret=ret.slice(6)}else if(ret==="self"||ret&&ret.length===10&&ret[4]==="-"&&ret[7]==="-"){}else{ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}return end_results()}else{ret=ret.replace(/_NULL/gi,"");return end_results()}}catch(err){return end_results()}};if(!func.expression.validate_variables(valP)){return await variable_not_exist()}const validate_email=async function(){const ret=await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback,null,true);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const get_iterate_value_ret=function(fieldIdP){if(!iterate_info||iterate_info.iterator_key!==fieldIdP&&iterate_info.iterator_val!==fieldIdP){return null}const iter_value=iterate_info.iterator_key===fieldIdP?iterate_info._key:iterate_info._val;const iter_type=typeof iter_value!=="undefined"?{}.toString.call(iter_value).match(/\s([a-zA-Z]+)/)[1].toLowerCase():"string";return{ret:{value:iter_value,type:iter_type,prop:["array","object"].includes(iter_type)?iter_value:null},fieldIdP:fieldIdP,currentRecordId:rowIdP,found:typeof iter_value!=="undefined"}};const split=func.expression.parse(ret)||[];const split_entries=Object.entries(split);for(let entry_i=0;entry_i<split_entries.length;entry_i++){const[arr_key,val]=split_entries[entry_i];const key=Number(arr_key);var_Arr[key]={};var_Arr[key].value=val.value;const replace_value_in_string=async function(retP,fieldIdP){if(iterate_info?.iterator_key===fieldIdP||iterate_info?.iterator_val===fieldIdP){if(iterate_info.iterator_key===fieldIdP){retP.value=iterate_info._key}if(iterate_info.iterator_val===fieldIdP){retP.value=iterate_info._val}}const set_value=function(valP){if(typeof valP!=="undefined"){var_Arr[key].value=valP;if(typeof valP==="string")var_Arr[key].type="string"}else{if(retP.type==="object"){var_Arr[key].value="";var_Arr[key].type="string"}}};if(sourceP==="exp"&&retP.type!=="exp"){var_Arr[key].type=retP.type;return}if(typeof retP.value!=="undefined"){var_Arr[key].type=retP.type;var_Arr[key].value=typeof retP.value==="string"&&!retP.value.includes("<svg xmlns=")&&retP.value.indexOf("\\")===-1&&!["UI Attr EXP","update"].includes(sourceP)?retP.value.replaceAll('"','\\"'):retP.value;if(val.value.indexOf("[")>-1|val.value.indexOf(".")>-1){var data=retP.prop;if(retP.type==="object")data=retP.value;var property1,property2;if(val.value.indexOf("[")===-1&&val.value.indexOf("]")>-1&&val.value.substr(0,1)==="@"){var prevData=var_Arr[key-1].value;var_Arr[key].value=prevData[data];if(val.value.indexOf(".")>-1){const props_split=await func.expression.get_property(val.value);property2=props_split.property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{const props=await func.expression.get_property(val.value);property1=props.property1;property2=props.property2;if(property1){var_Arr[key].value=data[property1];if(property2){if(data[property1])set_value(data[property1][property2])}}if(property2&&!property1){if(data){set_value(data[property2])}}}fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}else{fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}}};if(val.fieldId){if(val.fieldId&&val.fieldId.substr(0,5)==="_THIS"&&calling_fieldIdP&&(val.fieldId.length===5||val.fieldId.length>5&&val.fieldId.substr(5,1)===".")){if(val.fieldId.length===5)val.fieldId=calling_fieldIdP;else val.fieldId=calling_fieldIdP+val.fieldId(5,val.fieldId.length-1)}if(!sourceP==="exp"){var_Arr[key].value='""'}fields[val.fieldId]=var_Arr[key].value;const ret=get_iterate_value_ret(val.fieldId)||await func.datasource.get_value(SESSION_ID,val.fieldId,dsSessionP,rowIdP);await replace_value_in_string(ret.ret,ret.fieldIdP)}}try{var res=[];var exp_exist;var var_error_found;var_Arr.forEach(function(val,key){if(sourceP==="UI Property EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,true);if(ret.changed){res[key]=ret.value;return true}}if(sourceP==="UI Attr EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,var_Arr.length==1?false:true);if(ret.changed){res[key]=ret.value;return true}}if(val.type==="exp"){exp_exist=true}res[key]=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){res[key]="`"+val.value+"`"}if(["api_rendered_output"].includes(sourceP)&&["json"].includes(api_output_type)&&["string","date"].includes(val.type)){res[key]=`"`+val.value+`"`}}if(val.fieldId&&val.value&&typeof val.value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP)){if(val.value.indexOf("↵")>-1){res[key]=val.value.split("↵").join("")}res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"")}if(["init","update","virtual"].includes(sourceP)){if(val.value.indexOf("↵")>-1)res[key]=val.value.split("↵").join("\n");res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"\\n")}if(typeof IS_PROCESS_SERVER!=="undefined"){res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"<br>")}fields[val.fieldId]=res[key]}if(typeof val.value==="object"&&var_Arr.length>1){if(!Array.isArray(val.value)&&!var_Arr[key+1].value?.includes(".")){res[key]="("+JSON.stringify(val.value)+")"}else{res[key]=JSON.stringify(val.value)}}if(!exp_exist&&sourceP!=="exp"&&val.value&&typeof val.value==="string"&&val.value.substr(0,1)==="@"){warning="Error encoding "+val.value;var_error_found=true;res[key]=0}});const join=function(arrP){return arrP.join("")};var exp=undefined;if(exp_exist&&sourceP!=="exp"){exp=await func.expression.get(SESSION_ID,join(res),dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);if(exp.res)res=exp.res;else res=[exp.result];fields=Object.assign(exp.fields,fieldsP)}var result=join(res);if(res.length===1){result=res[0]}if(secondPassP){ret=result}else if(sourceP!=="exp"){if(res.length===1&&typeof res[0]==="string"&&typeof res[0]!=="object"){ret=join(res);if(ret&&ret.substr(0,1)==="@"){error="Error encoding @ var";var_error_found=true}}else{if(!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,result,jobNo,dsSessionP,js_script_callback)}else{if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(result))}else{ret=result}}}}return end_results()}catch(err){ret=result;error=err.message;return end_results()}}}const new_class=new xu_class;return new_class.get()};func.expression._parse_cache=new Map;func.expression.parse=function(input){if(typeof input!=="string")return[];if(func.expression._parse_cache.has(input)){return func.expression._parse_cache.get(input).map(function(s){return Object.assign({},s)})}const segments=[];let pos=0;const parts=input.split(/(@\w+)/).filter(Boolean);for(const part of parts){if(part.startsWith("@")){const fieldId=part.slice(1);segments.push({value:part,fieldId:fieldId,pos:pos})}else{segments.push({value:part,pos:pos})}pos+=part.length}if(func.expression._parse_cache.size>=500){const firstKey=func.expression._parse_cache.keys().next().value;func.expression._parse_cache.delete(firstKey)}func.expression._parse_cache.set(input,segments);return segments.map(function(s){return Object.assign({},s)})};func.expression.get_property=async function(valP){async function secure_eval(val){if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(val)}catch(err){console.error(err);return}}try{let vm=new VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(val)}catch(err){throw""}}var property1,property2;if(valP.indexOf("[")>-1&&valP.indexOf("]")>-1){property1=valP.substr(valP.indexOf("[")+1,valP.indexOf("]")-valP.indexOf("[")-1);property1=await secure_eval(property1)}if(valP.indexOf(".")>-1)property2=valP.substr(valP.indexOf(".")+1,valP.length);return{property1:property1,property2:property2}};func.expression.validate_constant=function(valP){var patt=/["']/;if(typeof valP==="string"&&patt.test(valP.substr(0,1))&&patt.test(valP.substr(0,valP.length-1)))return true;else return false};func.expression.validate_variables=function(valP){if(typeof valP==="string"&&valP.indexOf("@")>-1)return true;else return false};func.expression.remove_quotes=function(valP){if(func.expression.validate_constant(valP))return valP.substr(1,valP.length-2);else return valP};func.expression.secure_eval=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt,ignore_errors){if(typeof val!=="string")return val;const xu=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const isServer=typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined";if(!isServer){try{return eval(val)}catch(err){try{if(sourceP==="javascript"&&!ignore_errors)console.error(err);return JSON5.parse(val)}catch(err){if(sourceP==="javascript"&&!ignore_errors)console.error(err);return val}}}const sandbox={func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,...sourceP==="javascript"?{axios:axios,got:got,FormData:FormData}:{}};const handleError=err=>{console.error("Execution error:",err);func.events.delete_job(SESSION_ID,job_id);if(isServer&&!SESSION_OBJ[SESSION_ID].crawler){if(sourceP==="javascript"){__.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}else{__.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}return val};if(sourceP==="javascript"){process.on("uncaughtException",handleError);try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules");const script=new VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, "${job_id}"); }`,{filename:dir,dirname:dir});const vm=new NodeVM({require:{external:true},sandbox:sandbox,timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){return handleError(err)}}try{const vm=new VM({sandbox:sandbox,timeout:1e3,allowAsync:false});return await vm.run(val)}catch{try{return JSON5.parse(val)}catch{return val}}};
|
|
5
|
+
})(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,true,null,null,evt,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},loader_on:async function(){glb.CURRENT_APP_LOADING=null;LOADER_ACTIVE=true;LOADER_TEXT=descP;func.events.delete_job(SESSION_ID,jobNoP)},loader_off:async function(){LOADER_ACTIVE=false;func.events.delete_job(SESSION_ID,jobNoP)},emit_event:async function(){if(refIdP.value){func.runtime.platform.emit(refIdP.value,[_session.DS_GLB[dsSession]])}else{func.utils.debug_report(SESSION_ID,"func.events.execute","Event name missing","E")}func.events.delete_job(SESSION_ID,jobNoP)},invoke_action:async function(){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,null,expCond);await func.action.execute(SESSION_ID,refIdP.value,_ds,null,null,jobNoP,containerP)},raise_event:async function(){var _ds=_session.DS_GLB[dsSession];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(callingSourceP==="grid"||callingSourceP==="form"){let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",field_elm);var event_name=_field_obj?.workflow?.[eventIdP].name.event;if(_field_obj?.workflow?.[eventIdP].name?.properties["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,props[`xu-exp:event`],dsSession,"event_name expression")).result}if(field_elm&&event_name){const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);return await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,null,calling_trigger_prop?.data?.name?.parameters||{})}}if(callingSourceP.includes("event")){let event_name=refIdP.event;if(refIdP?.properties?.["xu-exp:event"]){event_name=(await func.expression.get(SESSION_ID,refIdP.properties["xu-exp:event"],dsSession,"event_name expression")).result}const dsP=await func.datasource.find_event_dataSource(SESSION_ID,event_name,dsSession);await func.datasource.run_events_functions(SESSION_ID,dsP,event_name,jobNoP,calling_trigger_prop?.props?.async,calling_trigger_prop?.data?.name?.parameters||{})}func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond)},get_data:async function(){const params_obj=await get_params_obj();if(!await get_prog_id()){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program ${prog} is missing`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}var _ds=_session.DS_GLB[dsSession];if(!_ds){func.events.delete_job(SESSION_ID,jobNoP);return}if(_ds){func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,null,calling_trigger_prop,expCond);const ret=await func.datasource.create(SESSION_ID,await get_prog_id(),args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,null,null,args.callingSourceP,args.calling_jobP,args.screen_dsP,args.is_panelP,params_obj);let _ds_new=_session.DS_GLB[ret.dsSessionP];let parameters=args?.calling_trigger_prop?.data?.name?.parameters;if(parameters&&!xu_isEmpty(parameters)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds_new.dsSession,_ds.dsSession)}func.events.delete_job(SESSION_ID,jobNoP);return _ds_new}},set_data:async function(){return this.get_data()},batch:async function(){const result=await this.get_data();return result},update:async function(){const resolve_update_field_id=async function(field_expr,iterate_info){let trimmed=field_expr?.trim?.()||"";if(!trimmed){return trimmed}const first=trimmed.substring(0,1);const last=trimmed.substring(trimmed.length-1);if((first==="'"||first==='"'||first==="`")&&last===first){trimmed=trimmed.substring(1,trimmed.length-1).trim()}if(/^@?[A-Za-z_][\w\-\:\.]*$/.test(trimmed)){return trimmed.substring(0,1)==="@"?trimmed.substring(1):trimmed}let ret_field_id=await func.expression.get(SESSION_ID,trimmed,dsSessionP,"update",null,null,null,null,null,null,iterate_info);if(typeof ret_field_id?.result==="string"&&ret_field_id.result.substring(0,1)==="@"){return ret_field_id.result.substring(1)}return ret_field_id?.result};const obj_values_to_update=func.datasource.get_viewFields_for_update_function(SESSION_ID,calling_trigger_prop,null,dsSessionP);if(!obj_values_to_update||xu_isEmpty(obj_values_to_update)){func.utils.debug_report(SESSION_ID,"Update values object is empty","","W");if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);return}var updates=[];for await(const[key,val]of Object.entries(obj_values_to_update)){var $element;var iterate_info=null;if(elementP){const element_meta=func.runtime.ui.get_meta(elementP,"xuData");iterate_info=element_meta?.iterate_info||null}let ret_value=await func.expression.get(SESSION_ID,val.val.trim(),dsSessionP,"update",null,null,null,null,null,null,iterate_info);let _field_id=await resolve_update_field_id(val.id,iterate_info);let _value=ret_value.result;updates.push({_field_id:_field_id,_value:_value})}let datasource_changes={};for await(const change of updates){let ret_get_value=await func.datasource.get_value(SESSION_ID,change._field_id,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][change._field_id]=change._value}}await func.datasource.update(SESSION_ID,datasource_changes,null,null,triggerP);if(_ds.PARAM_OUT_INFO){for await(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){await func.datasource.update_changes_for_out_parameter(SESSION_ID,_ds.dsSession,val.parentDataSourceNo)}}if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"call_alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},alert:async function(){await func.utils.alerts.invoke(SESSION_ID,"alert",refIdP,log_source,dsSession);func.events.delete_job(SESSION_ID,jobNoP)},delay:async function(){return new Promise(resolve=>{setTimeout(function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP);resolve()},refIdP.value)})},comment:async function(){if(jobNoP)func.events.delete_job(SESSION_ID,jobNoP)},call_project_api:async function(){const params_obj=await get_params_obj();const _prog_id=await get_prog_id();if(!_prog_id){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} > ${triggerP} > ${functionP} > program not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const api_ret=await func.api.call_project_api(_prog_id,params_obj);await func.datasource.set_outputField(SESSION_ID,dsSessionP,api_ret,args);func.events.delete_job(SESSION_ID,jobNoP)},call_system_api:async function(){const api_method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"api_method");if(!api_method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > api_method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}let payload={};const _payload=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");if(_payload){const get_payload_property_value=async function(prop_name){let _prop=_payload;let _value=_prop[prop_name];if(_prop?.[`xu-exp:${prop_name}`]){_value=(await func.expression.get(SESSION_ID,_prop[`xu-exp:${prop_name}`],dsSession,`${prop_name} expression`)).result}return _value};for await(let[key,val]of Object.entries(_payload)){const new_key=key.replaceAll("xu-exp:","");payload[new_key]=await get_payload_property_value(new_key)}}const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_system_api(api_method,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)},call_external_api:async function(){const method=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"method");if(!method){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > method not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const url=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"url");if(!url){func.utils.debug_report(SESSION_ID,"func.events.execute",`${elementP} >${triggerP} >${functionP} > url not defined`,"E");func.events.delete_job(SESSION_ID,jobNoP);return}const payload_arr=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"payload");const report_conversion_error=function(res,typeP,valP){var msg=`${elementP} >${triggerP} >${functionP} > error converting from ${valP} to ${typeP}`;if(error){return func.utils.debug_report(SESSION_ID,msg,"","W")}func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","E")};const report_conversion_warn=function(res){var msg=`${elementP} >${triggerP} >${functionP} > type mismatch auto conversion from value ${valP} to ${typeP}`;func.utils.debug_report(SESSION_ID,msg+" "+(source.charAt(0).toUpperCase()+source.slice(1).toLowerCase())+prog_info,"","W")};if(error){return report_conversion_error()}const module=await func.common.get_module(SESSION_ID,"xuda-get-cast-util-module.mjs");var payload=payload_arr.reduce((ret,val,key)=>{ret[val.key]=module.cast(val.type,val.val,report_conversion_error,report_conversion_warn);return ret},{});const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSession,args,"outputField");const api_ret=await func.api.call_external_api(method,url,payload);if(output_field){let datasource_changes={};let ret_get_value=await func.datasource.get_value(SESSION_ID,output_field,dsSessionP);if(ret_get_value.found){let _ds=_session.DS_GLB[ret_get_value.dsSessionP];if(!datasource_changes[_ds.dsSession]){datasource_changes[_ds.dsSession]={}}if(!datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]){datasource_changes[_ds.dsSession][ret_get_value.currentRecordId]={}}datasource_changes[_ds.dsSession][ret_get_value.currentRecordId][output_field]=api_ret;await func.datasource.update(SESSION_ID,datasource_changes)}}func.events.delete_job(SESSION_ID,jobNoP)}};return await fx[functionP]()};func.events.delete_job=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSessionP;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.delete_job_0=function(SESSION_ID){var job_index=0;var _session=SESSION_OBJ[SESSION_ID];if(!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}var dsSession=_session.WORKER_OBJ.jobs[job_index].dsSession;let ds_obj=_session?.DS_GLB[dsSession];if(ds_obj){delete SCREEN_BLOCKER_OBJ[ds_obj.screenId+(ds_obj.callingScreenId?"_"+ds_obj.callingScreenId:"")]}if(dsSession&&ds_obj&&ds_obj.loops_limit&&ds_obj.loops_count<ds_obj.loops_limit-1){return}_session.WORKER_OBJ.stat=null;_session.WORKER_OBJ.jobs.splice(job_index,1)};func.events.check_jobs_idle=async function(SESSION_ID,jobsP){return new Promise((resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(!jobsP||jobsP&&jobsP.length===0){resolve();return}var listener=setInterval(function(){var found;for(const[key,val]of Object.entries(jobsP)){for(const[key2,val2]of Object.entries(_session.WORKER_OBJ.jobs)){if(key2===val){found=true;break}}}if(!found){do_callback();return}},100);var do_callback=function(){clearInterval(listener);resolve()}})};var loop_detected_obj={};setInterval(function(){loop_detected_obj={}},1e3);func.events.set_browser_changes=function(dsP,fieldsChangedP){if(fieldsChangedP.includes("SYS_GLOBAL_STR_BROWSER_TITLE"))func.runtime.platform.set_title(dsP.dataset_new["SYS_GLOBAL_STR_BROWSER_TITLE"])};func.events.execute_PENDING_OPEN_URL_EVENTS=async function(){for(let[key,url]of Object.entries(PENDING_OPEN_URL_EVENTS)){if(url){glb.WINDOW_LOCATION_SEARCH=url;glb.ROOT_ELEMENT_ATTRIBUTES=func.UI.utils.get_root_element_attributes();const params_obj=func.common.getObjectFromUrl(url,glb.ROOT_ELEMENT_ATTRIBUTES);if(!params_obj.prog){return console.warn("prog empty")}await func.utils.TREE_OBJ.get(SESSION_ID,params_obj.prog);let screen_ret=await func.utils.get_screen_obj(SESSION_ID,params_obj.prog);if(screen_ret){await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:params_obj.prog,sourceScreenP:null,callingDataSource_objP:null,$callingContainerP:func.runtime.ui.get_session_root(SESSION_ID),triggerIdP:null,rowIdP:null,jobNoP:null,is_panelP:null,parameters_obj_inP:null,source_functionP:"pendingUrlEvent_embed"})}else{console.error("Program not exist",params_obj.prog_id);func.UI.utils.progressScreen.show(SESSION_ID,"Program not exist",null,true)}}else{console.warn("url empty")}}};func.events.invoke=async function(event_id){var _session=SESSION_OBJ[SESSION_ID];if(!event_id){console.warn("event_id Cannot be empty");return false}var ds;for await(const[ds_key,val]of Object.entries(_session.DS_GLB)){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,val.prog_id);if(xu_isEmpty(_view_obj.progEvents))continue;if(ds)break;for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val?.data?.type==="user_defined"&&val.data.event_name===event_id){ds=ds_key;break}}}if(!ds){console.warn("event_id not found");return false}func.events.validate(SESSION_ID,"user_defined",ds,event_id)};func.expression={};func.expression.get=async function(SESSION_ID,valP,dsSessionP,sourceP,rowIdP,sourceActionP,secondPassP,calling_fieldIdP,fieldsP,debug_infoP,iterate_info,js_script_callback,jobNo,api_output_type){class xu_class{async get(){if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=true}var ret;var fields={};var error;var warning;function evalJson(text){return eval("("+text+")")}if(valP===null){ret=""}else{switch(typeof valP){case"string":ret=valP;break;case"undefined":ret="";break;case"boolean":ret=valP?"Y":"N";break;default:ret=valP.toString();break}}if(ret.includes("&"))ret=ret.replace(/\&/g,"&");ret=func.utils.replace_studio_drive_url(SESSION_ID,ret);const end_results=function(){const replace_quotes=function(ret){for(const[key,val]of Object.entries(fields)){if(typeof val==="string")ret=ret.replace('"'+val+'"',val.replace(/"/gi,""))}return ret};if(["update","javascript"].includes(sourceP)){if(typeof ret==="string")ret=replace_quotes(ret)}const log_error=function(){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP]){func.utils.debug.log(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].nodeId,{module:"expression",action:sourceP,source:calling_fieldIdP,prop:ret,details:ret,result:ret,error:error,warning:warning,fields:null,type:"exp",prog_id:SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP].prog_id,debug_info:debug_infoP})}};if(error)log_error();if(typeof EXP_BUSY!=="undefined"){EXP_BUSY=false}const results={result:ret,fields:fields,res:res,explain:result,error:error,warning:warning,req:valP,var_error_found:var_error_found};return results};const variable_not_exist=async function(){try{if(sourceP!=="arguments"){if(ret&&ret.startsWith("_DATE_")){ret=ret.slice(6)}else if(ret==="self"||ret&&ret.length===10&&ret[4]==="-"&&ret[7]==="-"){}else{ret=await func.expression.secure_eval(SESSION_ID,sourceP,ret,jobNo,dsSessionP,js_script_callback)}return end_results()}else{ret=ret.replace(/_NULL/gi,"");return end_results()}}catch(err){return end_results()}};if(!func.expression.validate_variables(valP)){return await variable_not_exist()}const validate_email=async function(){const ret=await func.expression.secure_eval(SESSION_ID,sourceP,valP,jobNo,dsSessionP,js_script_callback,null,true);return glb.emailRegex.test(ret)};if(await validate_email()){return await variable_not_exist()}var var_Arr=[];const get_iterate_value_ret=function(fieldIdP){if(!iterate_info||iterate_info.iterator_key!==fieldIdP&&iterate_info.iterator_val!==fieldIdP){return null}const iter_value=iterate_info.iterator_key===fieldIdP?iterate_info._key:iterate_info._val;const iter_type=typeof iter_value!=="undefined"?{}.toString.call(iter_value).match(/\s([a-zA-Z]+)/)[1].toLowerCase():"string";return{ret:{value:iter_value,type:iter_type,prop:["array","object"].includes(iter_type)?iter_value:null},fieldIdP:fieldIdP,currentRecordId:rowIdP,found:typeof iter_value!=="undefined"}};const split=func.expression.parse(ret)||[];const split_entries=Object.entries(split);for(let entry_i=0;entry_i<split_entries.length;entry_i++){const[arr_key,val]=split_entries[entry_i];const key=Number(arr_key);var_Arr[key]={};var_Arr[key].value=val.value;const replace_value_in_string=async function(retP,fieldIdP){if(iterate_info?.iterator_key===fieldIdP||iterate_info?.iterator_val===fieldIdP){if(iterate_info.iterator_key===fieldIdP){retP.value=iterate_info._key}if(iterate_info.iterator_val===fieldIdP){retP.value=iterate_info._val}}const set_value=function(valP){if(typeof valP!=="undefined"){var_Arr[key].value=valP;if(typeof valP==="string")var_Arr[key].type="string"}else{if(retP.type==="object"){var_Arr[key].value="";var_Arr[key].type="string"}}};if(sourceP==="exp"&&retP.type!=="exp"){var_Arr[key].type=retP.type;return}if(typeof retP.value!=="undefined"){var_Arr[key].type=retP.type;var_Arr[key].value=typeof retP.value==="string"&&!retP.value.includes("<svg xmlns=")&&retP.value.indexOf("\\")===-1&&!["UI Attr EXP","update"].includes(sourceP)?retP.value.replaceAll('"','\\"'):retP.value;if(val.value.indexOf("[")>-1|val.value.indexOf(".")>-1){var data=retP.prop;if(retP.type==="object")data=retP.value;var property1,property2;if(val.value.indexOf("[")===-1&&val.value.indexOf("]")>-1&&val.value.substr(0,1)==="@"){var prevData=var_Arr[key-1].value;var_Arr[key].value=prevData[data];if(val.value.indexOf(".")>-1){const props_split=await func.expression.get_property(val.value);property2=props_split.property2;if(prevData[data])set_value(prevData[data][property2])}delete var_Arr[key-1]}else{const props=await func.expression.get_property(val.value);property1=props.property1;property2=props.property2;if(property1){var_Arr[key].value=data[property1];if(property2){if(data[property1])set_value(data[property1][property2])}}if(property2&&!property1){if(data){set_value(data[property2])}}}fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}else{fields[fieldIdP]=var_Arr[key].value;var_Arr[key].fieldId=fieldIdP}}};if(val.fieldId){if(val.fieldId&&val.fieldId.substr(0,5)==="_THIS"&&calling_fieldIdP&&(val.fieldId.length===5||val.fieldId.length>5&&val.fieldId.substr(5,1)===".")){if(val.fieldId.length===5)val.fieldId=calling_fieldIdP;else val.fieldId=calling_fieldIdP+val.fieldId(5,val.fieldId.length-1)}if(!sourceP==="exp"){var_Arr[key].value='""'}fields[val.fieldId]=var_Arr[key].value;const ret=get_iterate_value_ret(val.fieldId)||await func.datasource.get_value(SESSION_ID,val.fieldId,dsSessionP,rowIdP);await replace_value_in_string(ret.ret,ret.fieldIdP)}}try{var res=[];var exp_exist;var var_error_found;var_Arr.forEach(function(val,key){if(sourceP==="UI Property EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,true);if(ret.changed){res[key]=ret.value;return true}}if(sourceP==="UI Attr EXP"){let ret=func.utils.get_drive_url(SESSION_ID,val.value,var_Arr.length==1?false:true);if(ret.changed){res[key]=ret.value;return true}}if(val.type==="exp"){exp_exist=true}res[key]=val.value;if(var_Arr.length>1){if(!["DbQuery","alert","exp","api_rendered_output"].includes(sourceP)&&["string","date"].includes(val.type)){res[key]="`"+val.value+"`"}if(["api_rendered_output"].includes(sourceP)&&["json"].includes(api_output_type)&&["string","date"].includes(val.type)){res[key]=`"`+val.value+`"`}}if(val.fieldId&&val.value&&typeof val.value==="string"){if(["query","condition","range","sort","locate"].includes(sourceP)){if(val.value.indexOf("↵")>-1){res[key]=val.value.split("↵").join("")}res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"")}if(["init","update","virtual"].includes(sourceP)){if(val.value.indexOf("↵")>-1)res[key]=val.value.split("↵").join("\n");res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"\\n")}if(typeof IS_PROCESS_SERVER!=="undefined"){res[key]=res[key].replace(/(\r\n|\n|\r)/gm,"<br>")}fields[val.fieldId]=res[key]}if(typeof val.value==="object"&&var_Arr.length>1){if(!Array.isArray(val.value)&&!var_Arr[key+1].value?.includes(".")){res[key]="("+JSON.stringify(val.value)+")"}else{res[key]=JSON.stringify(val.value)}}if(!exp_exist&&sourceP!=="exp"&&val.value&&typeof val.value==="string"&&val.value.substr(0,1)==="@"){warning="Error encoding "+val.value;var_error_found=true;res[key]=0}});const join=function(arrP){return arrP.join("")};var exp=undefined;if(exp_exist&&sourceP!=="exp"){exp=await func.expression.get(SESSION_ID,join(res),dsSessionP,sourceP,rowIdP,sourceActionP,true,calling_fieldIdP,fields,debug_infoP);if(exp.res)res=exp.res;else res=[exp.result];fields=Object.assign(exp.fields,fieldsP)}var result=join(res);if(res.length===1){result=res[0]}if(secondPassP){ret=result}else if(sourceP!=="exp"){if(res.length===1&&typeof res[0]==="string"&&typeof res[0]!=="object"){ret=join(res);if(ret&&ret.substr(0,1)==="@"){error="Error encoding @ var";var_error_found=true}}else{if(!["arguments","api_rendered_output","DbQuery"].includes(sourceP)){ret=await func.expression.secure_eval(SESSION_ID,sourceP,result,jobNo,dsSessionP,js_script_callback)}else{if(sourceP==="DbQuery"){ret=JSON.stringify(evalJson(result))}else{ret=result}}}}return end_results()}catch(err){ret=result;error=err.message;return end_results()}}}const new_class=new xu_class;return new_class.get()};func.expression._parse_cache=new Map;func.expression.parse=function(input){if(typeof input!=="string")return[];if(func.expression._parse_cache.has(input)){return func.expression._parse_cache.get(input).map(function(s){return Object.assign({},s)})}const segments=[];let pos=0;const parts=input.split(/(@\w+)/).filter(Boolean);for(const part of parts){if(part.startsWith("@")){const fieldId=part.slice(1);segments.push({value:part,fieldId:fieldId,pos:pos})}else{segments.push({value:part,pos:pos})}pos+=part.length}if(func.expression._parse_cache.size>=500){const firstKey=func.expression._parse_cache.keys().next().value;func.expression._parse_cache.delete(firstKey)}func.expression._parse_cache.set(input,segments);return segments.map(function(s){return Object.assign({},s)})};func.expression.get_property=async function(valP){async function secure_eval(val){if(typeof IS_PROCESS_SERVER==="undefined"){try{return eval(val)}catch(err){console.error(err);return}}try{let vm=new VM({sandbox:{func:func,SESSION_ID:SESSION_ID,SESSION_OBJ:{[`${SESSION_ID}`]:SESSION_OBJ[SESSION_ID]}},timeout:1e3,allowAsync:false});return await vm.run(val)}catch(err){throw""}}var property1,property2;if(valP.indexOf("[")>-1&&valP.indexOf("]")>-1){property1=valP.substr(valP.indexOf("[")+1,valP.indexOf("]")-valP.indexOf("[")-1);property1=await secure_eval(property1)}if(valP.indexOf(".")>-1)property2=valP.substr(valP.indexOf(".")+1,valP.length);return{property1:property1,property2:property2}};func.expression.validate_constant=function(valP){var patt=/["']/;if(typeof valP==="string"&&patt.test(valP.substr(0,1))&&patt.test(valP.substr(0,valP.length-1)))return true;else return false};func.expression.validate_variables=function(valP){if(typeof valP==="string"&&valP.indexOf("@")>-1)return true;else return false};func.expression.remove_quotes=function(valP){if(func.expression.validate_constant(valP))return valP.substr(1,valP.length-2);else return valP};func.expression.secure_eval=async function(SESSION_ID,sourceP,val,job_id,dsSessionP,js_script_callback,evt,ignore_errors){if(typeof val!=="string")return val;const xu=await func.common.get_module(SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:SESSION_ID,APP_OBJ:APP_OBJ,dsSession:dsSessionP,job_id:job_id});const isServer=typeof IS_PROCESS_SERVER!=="undefined"||typeof IS_DOCKER!=="undefined";if(!isServer){try{return eval(val)}catch(err){try{if(sourceP==="javascript"&&!ignore_errors)console.error(err);return JSON5.parse(val)}catch(err){if(sourceP==="javascript"&&!ignore_errors)console.error(err);return val}}}const sandbox={func:func,xu:xu,SESSION_ID:SESSION_ID,SESSION_OBJ:{[SESSION_ID]:SESSION_OBJ[SESSION_ID]},callback:js_script_callback,job_id:job_id,...sourceP==="javascript"?{axios:axios,got:got,FormData:FormData}:{}};const handleError=err=>{console.error("Execution error:",err);func.events.delete_job(SESSION_ID,job_id);if(isServer&&!SESSION_OBJ[SESSION_ID].crawler){if(sourceP==="javascript"){__.rpi.write_log(SESSION_OBJ[SESSION_ID].app_id,"error","worker","vm error",err,null,val,"func.expression.get.secure_eval")}else{__.db.add_error_log(SESSION_OBJ[SESSION_ID].app_id,"api",err)}}return val};if(sourceP==="javascript"){process.on("uncaughtException",handleError);try{const dir=path.join(_conf.studio_drive_path,SESSION_OBJ[SESSION_ID].app_id,"node_modules");const script=new VMScript(`try { ${val} } catch (e) { func.api.error(SESSION_ID, "nodejs error", e); console.error(e); func.events.delete_job(SESSION_ID, "${job_id}"); }`,{filename:dir,dirname:dir});const vm=new NodeVM({require:{external:true},sandbox:sandbox,timeout:6e4});return await vm.run(script,{filename:dir,dirname:dir})}catch(err){return handleError(err)}}try{const vm=new VM({sandbox:sandbox,timeout:1e3,allowAsync:false});return await vm.run(val)}catch{try{return JSON5.parse(val)}catch{return val}}};
|
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.1429",
|
|
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"
|