@xuda.io/runtime-bundle 1.0.1441 → 1.0.1442

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.
@@ -71,7 +71,7 @@
71
71
  </div>`)}if(!func.runtime.ui.has_selector($root_element,"#progressScreen2")){func.runtime.ui.append_html($root_element,`
72
72
  <div id="progressScreen2" style="display: none">
73
73
  <div id="progressScreen2_text"></div>
74
- </div>`)}const get_url=function(domain,method,path){return`https://${domain}/${method}${path?"/"+path:"/"}`};func.utils.load_css_on_demand(get_url(domain,"dist","runtime/css/mobile.css"));return $root_element};func.runtime.ui.ensure_embed_container=function(SESSION_ID){const $root_element=func.runtime.ui.get_root_element(SESSION_ID);let $embed_container=func.runtime.ui.find_by_selector($root_element,`#embed_${SESSION_ID}`,true);if(!$embed_container.length){const $ssr_embed_container=func.runtime.ui.find_by_selector($root_element,`[data-xuda-ssr-embed="true"]`,true);const ssr_embed_node=func.runtime.ui.get_first_node($ssr_embed_container);if(ssr_embed_node){ssr_embed_node.id="embed_"+SESSION_ID;$embed_container=func.runtime.ui._wrap_matches([ssr_embed_node])}}if(!$embed_container.length){const embed_node=document.createElement("div");embed_node.id="embed_"+SESSION_ID;embed_node.className="xu_embed_div";func.runtime.ui.set_data(embed_node,"xuData",{});$embed_container=func.runtime.ui._wrap_matches([embed_node]);func.runtime.ui.append_to($embed_container,$root_element)}return $embed_container};func.runtime.ui.get_embed_container=function(SESSION_ID){return func.runtime.ui.find_by_selector(func.runtime.ui.get_root_element(SESSION_ID),`#embed_${SESSION_ID}`,true)};func.runtime.ui.get_embed_screen_containers=function(){return func.runtime.ui.find_by_selector(document.body,".xu_embed_container")};func.runtime.ui.append_to_body=function($element){func.runtime.ui.append_to($element,document.body);return $element};func.runtime.ui.find_in_root=function(SESSION_ID,selector){return func.runtime.ui.find_by_selector(func.runtime.ui.get_root_element(SESSION_ID),selector)};func.runtime.ui.get_root_tag_name=function(){let root_tag_name="div";if(!func.runtime.session.is_slim()){if(typeof UI_FRAMEWORK_PLUGIN?.core!=="function"){return root_tag_name}const ui_plugin_core=new UI_FRAMEWORK_PLUGIN.core;root_tag_name=ui_plugin_core?.rootTagName()||root_tag_name}return root_tag_name};func.runtime.ui.find_ssr_screen_host=function($container,screenId,containerId){const container_node=func.runtime.ui.get_first_node($container);if(!container_node||!screenId){return null}const dialog_node=container_node.querySelector?.(`#${CSS?.escape?CSS.escape(screenId):screenId}`)||container_node.querySelector?.(`[data-xuda-ssr-screen-id="${screenId}"]`);if(!dialog_node){return null}const root_frame_node=(containerId?dialog_node.querySelector?.(`#${CSS?.escape?CSS.escape(containerId):containerId}`):null)||dialog_node.querySelector?.('[data-xuda-ssr-root-frame="true"]');if(!root_frame_node){return null}return{$dialogDiv:func.runtime.ui._wrap_matches([dialog_node]),$rootFrame:func.runtime.ui._wrap_matches([root_frame_node]),reused_ssr_host:true}};func.runtime.ui.create_screen_host=function(SESSION_ID,screen_type,params,$callingContainerP,screenId){var $dialogDiv;var $rootFrame;let reused_ssr_host=false;switch(screen_type){case"embed":{const ssr_host=func.runtime.ui.find_ssr_screen_host($callingContainerP,screenId,params?.containerIdP);if(ssr_host){return ssr_host}const dialogNode=document.createElement("div");dialogNode.id=screenId;dialogNode.setAttribute("ui_engine",UI_FRAMEWORK_INSTALLED);dialogNode.classList.add("xu_embed_container");dialogNode.style.display="contents";func.runtime.ui.set_data(dialogNode,"xuData",{paramsP:params,screenInfo:params.screenInfo});$dialogDiv=func.runtime.ui._wrap_matches([dialogNode]);const root_tag_name=func.runtime.ui.get_root_tag_name();const rootFrameNode=document.createElement(root_tag_name);func.runtime.ui.set_data(rootFrameNode,"xuData",{});func.runtime.ui.set_data(rootFrameNode,"xuAttributes",{});dialogNode.appendChild(rootFrameNode);$rootFrame=func.runtime.ui._wrap_matches([rootFrameNode]);func.runtime.ui.append_to($dialogDiv,$callingContainerP);break}case"panel":$dialogDiv=$callingContainerP;func.runtime.ui.set_data($dialogDiv,"xuData",{paramsP:params,screenInfo:params.screenInfo});$rootFrame=$dialogDiv;break;case"page":case"modal":case"popover":{const dialogNode=document.createElement("div");const rootFrameNode=document.createElement("div");dialogNode.appendChild(rootFrameNode);$dialogDiv=func.runtime.ui._wrap_matches([dialogNode]);$rootFrame=func.runtime.ui._wrap_matches([rootFrameNode]);func.runtime.ui.append_to_body($dialogDiv);break}default:break}return{$dialogDiv:$dialogDiv,$rootFrame:$rootFrame,reused_ssr_host:reused_ssr_host}};func.runtime.ui.find_xu_ui_in_root=function(SESSION_ID,xu_ui_id){if(!SESSION_ID||!xu_ui_id){return func.runtime.ui._wrap_matches([])}if(func.runtime.ui.get_refresh_indexed_element_by_ui_id){const elm=func.runtime.ui.get_refresh_indexed_element_by_ui_id(SESSION_ID,xu_ui_id);return func.runtime.ui._wrap_matches(elm?[elm]:[])}return func.runtime.ui.find_in_root(SESSION_ID,`[xu-ui-id="${xu_ui_id}"]`)};func.runtime.ui.find_panel_wrapper_in_root=function(SESSION_ID,xu_ui_id){if(func.runtime.ui.get_refresh_indexed_panel_wrapper_by_id){const elm=func.runtime.ui.get_refresh_indexed_panel_wrapper_by_id(SESSION_ID,xu_ui_id);return func.runtime.ui._wrap_matches(elm?[elm]:[])}return func.runtime.ui.find_in_root(SESSION_ID,`[xu-panel-wrapper-id=${xu_ui_id}]`)};func.runtime.ui.find_element_data_in_root=function(SESSION_ID,dataKey,property,value){if(dataKey==="xuData"&&property==="ui_id"&&typeof value!=="undefined"&&func.runtime.ui.get_refresh_indexed_element_by_ui_id){const elm=func.runtime.ui.get_refresh_indexed_element_by_ui_id(SESSION_ID,value);return func.runtime.ui._wrap_matches(elm?[elm]:[])}if(dataKey==="xuData"&&property==="nodeid"&&typeof value!=="undefined"&&func.runtime.ui.get_refresh_indexed_elements_by_node_id){return func.runtime.ui.get_refresh_indexed_elements_by_node_id(SESSION_ID,value)}if(dataKey==="xuPanelWrapper"&&property==="isWrapper"&&typeof value==="undefined"){if(func.runtime.ui.get_refresh_indexed_panel_wrappers){return func.runtime.ui.get_refresh_indexed_panel_wrappers(SESSION_ID)}return func.runtime.ui.find_in_root(SESSION_ID,"[xu-panel-wrapper-id]")}return func.UI.utils.find_in_element_data(dataKey,func.runtime.ui.get_root_element(SESSION_ID),property,value)};func.runtime.ui.find_element_data_in_parent=function($container,dataKey,property,value){const container_node=func.runtime.ui.get_first_node($container);const parent_node=container_node?.parentElement;if(!parent_node){return func.runtime.ui._wrap_matches([])}if(dataKey==="xuData"&&property==="ui_id"&&typeof value!=="undefined"){if(func.runtime.ui.find_refresh_elements_by_attr){return func.runtime.ui.find_refresh_elements_by_attr(parent_node,"xu-ui-id",value,true)}return func.runtime.ui.find_by_selector(parent_node,`[xu-ui-id="${value}"]`)}return func.UI.utils.find_in_element_data(dataKey,func.runtime.ui._wrap_matches([parent_node]),property,value)};func.runtime.ui.sync_child_parent_container=function($div){const div_node=func.runtime.ui.get_first_node($div);const parent_container=func.runtime.ui.get_data(div_node)?.xuData?.parent_container;const children=div_node?.children?Array.from(div_node.children):[];for(let index=0;index<children.length;index++){const child_data=func.runtime.ui.get_data(children[index]);if(!child_data?.xuData?.parent_container){continue}child_data.xuData.parent_container=parent_container}return $div};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.ui.ui_id_hash_cache=func.runtime.ui.ui_id_hash_cache||new Map;func.runtime.ui.node_snapshot_cache=func.runtime.ui.node_snapshot_cache||new WeakMap;func.runtime.ui.node_child_items_cache=func.runtime.ui.node_child_items_cache||new WeakMap;func.runtime.ui.node_children_by_id_cache=func.runtime.ui.node_children_by_id_cache||new WeakMap;func.runtime.ui._meta_store=func.runtime.ui._meta_store||{};func.runtime.ui._element_id_to_xu_ui_id=func.runtime.ui._element_id_to_xu_ui_id||{};func.runtime.ui.set_meta=function(xu_ui_id,key,value){if(!xu_ui_id)return;if(!func.runtime.ui._meta_store[xu_ui_id]){func.runtime.ui._meta_store[xu_ui_id]={}}func.runtime.ui._meta_store[xu_ui_id][key]=value};func.runtime.ui.get_meta=function(xu_ui_id,key){const entry=func.runtime.ui._meta_store[xu_ui_id];if(!entry)return undefined;return key?entry[key]:entry};func.runtime.ui.delete_meta=function(xu_ui_id){delete func.runtime.ui._meta_store[xu_ui_id];for(const id in func.runtime.ui._element_id_to_xu_ui_id){if(func.runtime.ui._element_id_to_xu_ui_id[id]===xu_ui_id){delete func.runtime.ui._element_id_to_xu_ui_id[id]}}};func.runtime.ui.register_element_id=function(element_id,xu_ui_id){if(element_id&&xu_ui_id){func.runtime.ui._element_id_to_xu_ui_id[element_id]=xu_ui_id}};func.runtime.ui.get_meta_by_element_id=function(element_id){if(!element_id)return undefined;const xu_ui_id=func.runtime.ui._element_id_to_xu_ui_id[element_id];if(xu_ui_id){return func.runtime.ui._meta_store[xu_ui_id]}if(typeof document!=="undefined"){const clean_id=element_id.startsWith("#")?element_id.substring(1):element_id;const el=document.getElementById(clean_id);if(el){const dom_xu_ui_id=el.getAttribute("xu-ui-id");if(dom_xu_ui_id){func.runtime.ui.register_element_id(clean_id,dom_xu_ui_id);return func.runtime.ui._meta_store[dom_xu_ui_id]}return func.runtime.ui.get_data(el)}}return undefined};func.runtime.ui.find_element_by_id=function(element_id){if(!element_id)return null;if(typeof document!=="undefined"){return document.getElementById(element_id)||null}return null};func.runtime.ui.get_parent_element_id=function(element_id){if(!element_id){return null}const clean_id=element_id.startsWith("#")?element_id.substring(1):element_id;const element=func.runtime.ui.find_element_by_id(clean_id);return element?.parentElement?.id||null};func.runtime.ui.get_session_root=function(SESSION_ID){if(typeof document!=="undefined"){return document.getElementById("embed_"+SESSION_ID)||null}return null};func.runtime.ui.clear_screen_blockers=function(){if(typeof document!=="undefined"){const blockers=document.querySelectorAll(".screen_blocker");for(let i=0;i<blockers.length;i++){blockers[i].remove()}}};func.runtime.ui.as_jquery=function(target){const node=func.runtime.ui.get_first_node(target);return func.runtime.ui._wrap_matches(node?[node]:[])};func.runtime.ui.get_first_node=function(target){if(!target){return null}if(target?.nodeType){return target}if(Array.isArray(target)||typeof target?.length==="number"){return target[0]||null}return null};func.runtime.ui.get_data=function(target){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.getAttribute){const xu_ui_id=target_node.getAttribute("xu-ui-id");if(xu_ui_id){const meta=func.runtime.ui._meta_store[xu_ui_id];if(meta)return meta}}if(target_node){if(!target_node.__xuData){target_node.__xuData={}}return target_node.__xuData}return{}};func.runtime.ui.get_parent=function(target){const target_node=func.runtime.ui.get_first_node(target);return target_node?.parentElement||null};func.runtime.ui.get_children=function(target){const target_node=func.runtime.ui.get_first_node(target);return target_node?.children?Array.from(target_node.children):[]};func.runtime.ui._wrap_matches=function(matches){if(!matches)matches=[];const result={length:matches.length,toArray:function(){return matches.slice()}};for(let i=0;i<matches.length;i++){result[i]=matches[i]}result[Symbol.iterator]=function(){let idx=0;return{next:function(){if(idx<matches.length){return{value:matches[idx++],done:false}}return{done:true}}}};return result};func.runtime.ui.find_by_selector=function(target,selector,first_only=false){const target_node=func.runtime.ui.get_first_node(target);const root_nodes=target_node?[target_node]:Array.isArray(target)?target:target?.length?Array.from(target):[];const matches=[];for(let root_index=0;root_index<root_nodes.length;root_index++){const root_node=root_nodes[root_index];if(root_node?.matches?.(selector)){matches.push(root_node);if(first_only){break}}if(first_only&&matches.length){break}if(first_only){const first_match=root_node?.querySelector?.(selector);if(first_match){matches.push(first_match);break}continue}const descendants=root_node?.querySelectorAll?.(selector)||[];for(let index=0;index<descendants.length;index++){matches.push(descendants[index])}}return func.runtime.ui._wrap_matches(matches)};func.runtime.ui.insert_before=function($element,$reference){const element_node=func.runtime.ui.get_first_node($element);const reference_node=func.runtime.ui.get_first_node($reference);if(reference_node?.before&&element_node){reference_node.before(element_node)}if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target($reference,func.runtime.ui.get_data($element)?.xuData?.SESSION_ID)}return $element};func.runtime.ui.insert_after=function($element,$reference){const element_node=func.runtime.ui.get_first_node($element);const reference_node=func.runtime.ui.get_first_node($reference);if(reference_node?.after&&element_node){reference_node.after(element_node)}if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target($reference,func.runtime.ui.get_data($element)?.xuData?.SESSION_ID)}return $element};func.runtime.ui.has_selector=function(target,selector){return!!func.runtime.ui.get_first_node(func.runtime.ui.find_by_selector(target,selector,true))};func.runtime.ui.append_html=function(target,html){const target_node=func.runtime.ui.get_first_node(target);if(!target_node||!html){return target_node||null}target_node.insertAdjacentHTML("beforeend",html);if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target(target_node)}return target_node};func.runtime.ui.set_style=function(target,prop,value){const target_node=func.runtime.ui.get_first_node(target);if(!target_node?.style||!prop){return target_node||null}target_node.style[prop]=value;return target_node};func.runtime.ui.normalize_external_asset_url=function(value){if(typeof value!=="string"||!value.trim()){return value}const trimmed_value=value.trim();try{const url=new URL(trimmed_value,typeof document!=="undefined"?document.baseURI:"https://xuda.ai");if(url.hostname==="via.placeholder.com"){url.hostname="placehold.co";return url.toString()}}catch(_){if(trimmed_value.startsWith("https://via.placeholder.com/")||trimmed_value.startsWith("http://via.placeholder.com/")){return trimmed_value.replace("via.placeholder.com","placehold.co")}}return value};func.runtime.ui.normalize_svg_path_value=function(value){if(typeof value!=="string"||!value.trim()){return value}let normalized_value=value.trim();normalized_value=normalized_value.replace(/([zZ])+\s*[mMlLhHvVcCsSqQtTaA]\s*$/g,"$1");return normalized_value};func.runtime.ui.normalize_attr_value=function(target_or_tag,key,value){if(typeof value!=="string"){return value}const target_tag_name=typeof target_or_tag==="string"?target_or_tag:func.runtime.ui.get_first_node(target_or_tag)?.tagName||"";const tag_name=`${target_tag_name||""}`.trim().toLowerCase();const attr_name=`${key||""}`.trim().toLowerCase();if((tag_name==="img"||tag_name==="image")&&["src","href","xlink:href"].includes(attr_name)){return func.runtime.ui.normalize_external_asset_url(value)}if(tag_name==="path"&&attr_name==="d"){return func.runtime.ui.normalize_svg_path_value(value)}return value};func.runtime.ui.get_attr=function(target,key){const target_node=func.runtime.ui.get_first_node(target);return target_node?.getAttribute?.(key)??undefined};func.runtime.ui.set_attr=function(target,key,value){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.setAttribute){const normalized_value=func.runtime.ui.normalize_attr_value(target_node,key,value);try{target_node.setAttribute(key,normalized_value)}catch(error){console.warn(`Failed to set attribute "${key}" on <${target_node.tagName?.toLowerCase?.()||"unknown"}>`,error)}}return target_node||target};func.runtime.ui.set_data=function(target,key,value){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.getAttribute){const xu_ui_id=target_node.getAttribute("xu-ui-id");if(xu_ui_id){func.runtime.ui.set_meta(xu_ui_id,key,value);return target}}if(target_node){if(!target_node.__xuData)target_node.__xuData={};target_node.__xuData[key]=value}return target};func.runtime.ui.clear_data=function(target){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.getAttribute){const xu_ui_id=target_node.getAttribute("xu-ui-id");if(xu_ui_id){func.runtime.ui.delete_meta(xu_ui_id)}}if(target_node?.__xuData){delete target_node.__xuData}return target};func.runtime.ui.add_class=function(target,class_name){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.classList){target_node.classList.add(class_name);return target_node}return target_node||null};func.runtime.ui.remove_class=function(target,class_name){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.classList){target_node.classList.remove(class_name);return target_node}return target_node||null};func.runtime.ui.set_html=function(target,value){const target_node=func.runtime.ui.get_first_node(target);if(typeof target_node?.innerHTML!=="undefined"){target_node.innerHTML=value;return target_node}return target_node||null};func.runtime.ui.set_text=function(target,value){const target_node=func.runtime.ui.get_first_node(target);if(typeof target_node?.textContent!=="undefined"){target_node.textContent=value;return target_node}return target_node||null};func.runtime.ui.show=function(target){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.style){target_node.style.removeProperty("display");return target_node}return target_node||null};func.runtime.ui.hide=function(target){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.style){target_node.style.display="none";return target_node}return target_node||null};func.runtime.ui.append=function($target,$element){const target_node=func.runtime.ui.get_first_node($target);const element_node=func.runtime.ui.get_first_node($element);if(target_node&&element_node){target_node.appendChild(element_node)}if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target($target,func.runtime.ui.get_data($element)?.xuData?.SESSION_ID)}func.runtime?.perf?.increment?.(func.runtime.ui.get_data($element)?.xuData?.SESSION_ID,"dom_appends");return $element};func.runtime.ui.append_to=function($element,$target){const target_node=func.runtime.ui.get_first_node($target);const element_node=func.runtime.ui.get_first_node($element);if(target_node&&element_node){target_node.appendChild(element_node)}if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target($target,func.runtime.ui.get_data($element)?.xuData?.SESSION_ID)}func.runtime?.perf?.increment?.(func.runtime.ui.get_data($element)?.xuData?.SESSION_ID,"dom_appends");return $element};func.runtime.ui.empty=function(target){const target_node=func.runtime.ui.get_first_node(target);if(target_node){target_node.replaceChildren()}if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target(target)}return target_node||null};func.runtime.ui.remove=function(target){if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target(target)}let target_nodes;if(target?.nodeType){target_nodes=[target]}else if(Array.isArray(target)){target_nodes=target}else if(target?.length){target_nodes=Array.from(target)}else{target_nodes=[]}const session_id=func.runtime.ui.get_data(target_nodes[0]||target)?.xuData?.SESSION_ID;for(let index=0;index<target_nodes.length;index++){const target_node=target_nodes[index];const xu_ui_id=target_node?.getAttribute?.("xu-ui-id");if(xu_ui_id){func.runtime.ui.delete_meta(xu_ui_id)}if(target_node?.remove){target_node.remove()}}func.runtime?.perf?.increment?.(session_id,"dom_removes",target_nodes.length||1);return true};func.runtime.ui.set_display_contents=function($element){return func.runtime.ui.set_style($element,"display","contents")};func.runtime.ui.create_xurender=function(xu_ui_id,$target,hidden){const xurender=document.createElement("xurender");xurender.setAttribute("xu-ui-id",xu_ui_id);if(hidden){xurender.setAttribute("hidden","true")}return func.runtime.ui.append_to(xurender,$target)};func.runtime.ui.replace_with=function($source,$target){if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target($source,func.runtime.ui.get_data($source)?.xuData?.SESSION_ID||func.runtime.ui.get_data($target)?.xuData?.SESSION_ID)}const source_node=func.runtime.ui.get_first_node($source);const target_node=func.runtime.ui.get_first_node($target);if(source_node?.replaceWith&&target_node){source_node.replaceWith(target_node)}return $target};func.runtime.ui.remove_xu_ui=function(xu_ui_id){const $targets=func.runtime.ui.find_by_selector(document.body,`[xu-ui-id="${xu_ui_id}"]`,false);if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target($targets)}const targets=$targets.toArray();for(let index=0;index<targets.length;index++){targets[index].remove?.()}return true};func.runtime.ui.build_debug_info=function(nodeP,$container,items){return{id:nodeP.id,parent_id:func.runtime.ui.get_data($container)?.xuData?.ui_id,items:items}};func.runtime.ui.get_node_snapshot=function(nodeP){if(!nodeP){return nodeP}if(func.runtime.ui.node_snapshot_cache.has(nodeP)){return func.runtime.ui.node_snapshot_cache.get(nodeP)}const snapshot=structuredClone(nodeP);func.runtime.ui.node_snapshot_cache.set(nodeP,snapshot);return snapshot};func.runtime.ui.get_node_child_items=function(nodeP){if(!nodeP?.children?.length){return[]}if(func.runtime.ui.node_child_items_cache.has(nodeP)){return func.runtime.ui.node_child_items_cache.get(nodeP)}const items=nodeP.children.map(function(val){return val.xu_tree_id||val.id});func.runtime.ui.node_child_items_cache.set(nodeP,items);return items};func.runtime.ui.get_node_children_by_id=function(nodeP){if(!nodeP?.children?.length){return{}}if(func.runtime.ui.node_children_by_id_cache.has(nodeP)){return func.runtime.ui.node_children_by_id_cache.get(nodeP)}const children_by_id={};for(let index=0;index<nodeP.children.length;index++){const child_node=nodeP.children[index];if(child_node?.id){children_by_id[child_node.id]=child_node}}func.runtime.ui.node_children_by_id_cache.set(nodeP,children_by_id);return children_by_id};func.runtime.ui.build_container_xu_data=function(options){return{SESSION_ID:options.SESSION_ID,prog_id:options.paramsP.prog_id,nodeid:options.nodeP.id,ui_type:options.nodeP.tagName,recordid:options.currentRecordId,paramsP:options.paramsP,key:options.keyP,key_path:options.key_path,screenId:options.paramsP.screenId,parent_container:func.runtime.ui.get_attr(options.$container,"id"),elem_key:options.elem_key,properties:options.prop,node:options.nodeP,node_org:func.runtime.ui.get_node_snapshot(options.nodeP),is_panelP:options.paramsP.is_panelP,ui_id:options.ui_id,elem_prop:options.elem_propP,debug_info:func.runtime.ui.build_debug_info(options.nodeP,options.$container,options.items),parent_node:options.parent_nodeP,currentRecordId:options.currentRecordId,$root_container:options.$root_container,parent_element_ui_id:func.runtime.ui.get_data(options.$container)?.xuData?.ui_id,is_placeholder:!!options.is_placeholder}};func.runtime.ui.apply_container_meta=function($div,options){const div_node=func.runtime.ui.get_first_node($div);func.runtime.ui.set_attr(div_node,"xu-ui-id",options.ui_id);func.runtime.ui.set_attr(div_node,"data-xuda-kind",options.treeP?.kind||options.nodeP?.tagName||"element");func.runtime.ui.set_attr(div_node,"data-xuda-node-id",options.nodeP?.id||options.nodeP?.id_org||"");if(options.treeP?.meta?.tree_id!==null&&typeof options.treeP?.meta?.tree_id!=="undefined"){func.runtime.ui.set_attr(div_node,"data-xuda-tree-id",options.treeP.meta.tree_id)}const xuData=func.runtime.ui.build_container_xu_data(options);if(options.parent_infoP?.iterate_info){xuData.iterate_info=options.parent_infoP.iterate_info}func.runtime.ui.set_data(div_node,"xuData",xuData);func.runtime.ui.set_data(div_node,"xuAttributes",{});func.runtime.ui.set_meta(options.ui_id,"xuData",xuData);func.runtime.ui.set_meta(options.ui_id,"xuAttributes",{});const container_id=func.runtime.ui.get_attr(div_node,"id");if(container_id){func.runtime.ui.register_element_id(container_id,options.ui_id)}if(options.is_placeholder){func.runtime.ui.add_class(div_node,"display_none")}if(options.classP){func.runtime.ui.add_class(div_node,options.classP)}return $div};func.runtime.ui.get_append_target=function($container,$appendToP){const $appendTo=$appendToP||$container;if(!$appendTo){return null}const node=func.runtime.ui.get_first_node($appendTo);if(!node){return null}return $appendTo};func.runtime.ui.create_element=function(tag_name,attr_str){const el=document.createElement(tag_name);if(attr_str){const attr_regex=/([a-zA-Z_][\w\-.:]*)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|(\S+)))?/g;let match;while((match=attr_regex.exec(attr_str))!==null){const key=match[1];const value=match[2]!==undefined?match[2]:match[3]!==undefined?match[3]:match[4]!==undefined?match[4]:"";const normalized_value=func.runtime.ui.normalize_attr_value(tag_name,key,value);try{el.setAttribute(key,normalized_value)}catch(error){console.warn(`Failed to set attribute "${key}" on <${tag_name}>`,error)}}}return el};func.runtime.ui.create_svg_element=function(element,prop,nodeP,$appendTo){const get_tag_str=function(element,prop,val){let attr_str="";for(const[key,value]of Object.entries(prop)){if(key.substr(0,2)!=="xu"){const normalized_value=func.runtime.ui.normalize_attr_value(element,key,value);attr_str+=` ${key}="${normalized_value}" `}}if(element==="svg"){return`<${element} ${attr_str} > `}let ret="";if(val?.children?.length){ret=iterate_svg(val)}return`<${element} ${attr_str} > ${ret} </${element}>`};const iterate_svg=function(node){let ret="";if(node.children){for(let val of node.children){if(val.type==="comment")continue;ret+=get_tag_str(val.tagName,val.attributes,val)}}return ret};const svg_str=get_tag_str(element,prop);const inner_str=iterate_svg(nodeP);const full_svg_str=svg_str+inner_str+"</svg>";const tmp=document.createElement("div");tmp.innerHTML=full_svg_str;const svg_el=tmp.firstElementChild;return func.runtime.ui.append_to(svg_el,$appendTo)};func.runtime.ui.create_container_element=function(div_typeP,attr_str,prop,nodeP,$appendTo){const div=div_typeP||"div";if(div==="svg"){return func.runtime.ui.create_svg_element(div_typeP,prop,nodeP,$appendTo)}return func.runtime.ui.create_element(div,attr_str)};func.runtime.ui.find_hydration_candidate=function(options){if(!func.runtime.render.is_hydration_mode(SESSION_OBJ?.[options.SESSION_ID])){return null}if(!func.runtime.render.should_use_ssr_payload(options.SESSION_ID,options.paramsP)){return null}if(options.is_placeholder||!options.treeP?.meta?.tree_id){return null}const append_node=func.runtime.ui.get_first_node(options.$appendTo||options.$container);if(!append_node){return null}const children=func.runtime.ui.get_children(append_node);for(let index=0;index<children.length;index++){const child=children[index];if(child?.__xuda_hydration_claimed){continue}if(func.runtime.ui.get_attr(child,"data-xuda-tree-id")!==`${options.treeP.meta.tree_id}`){continue}child.__xuda_hydration_claimed=true;func.runtime.ui.set_attr(child,"data-xuda-client-activation","hydrate");return child}return null};func.runtime.ui.build_xu_ui_id_seed=function(nodeP,dsSessionP,key_path,currentRecordId){const nodeId=nodeP.xu_tree_id||nodeP.id;const elem_key=`${nodeId}-${key_path}-${currentRecordId}`;return`${nodeP.id}-${elem_key}-${dsSessionP?.toString()||""}`};func.runtime.ui.build_container_key_path=function(container_xu_data,keyP,parent_infoP,nodeP,parent_nodeP){const key_segment=typeof keyP==="undefined"||keyP===null?"0":`${keyP}`;let key_path=`${container_xu_data?.key_path||"0"}-${key_segment}`;const parent_identity=parent_nodeP?.xu_tree_id||parent_nodeP?.id;const node_identity=nodeP?.xu_tree_id||nodeP?.id;const is_iterated_clone=!!(parent_infoP?.iterate_info&&parent_identity&&node_identity&&parent_identity===node_identity);if(is_iterated_clone){key_path+="-iter"}return key_path};func.runtime.ui.generate_xu_ui_id=async function(SESSION_ID,nodeP,$container,paramsP,keyP,precomputed={}){const dsSessionP=paramsP.dsSessionP;const _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];const containerXuData=precomputed.container_xu_data||func.runtime.ui.get_data($container)?.xuData;const currentRecordId=typeof precomputed.currentRecordId!=="undefined"?precomputed.currentRecordId:containerXuData?.recordid||_ds?.currentRecordId||"";const key_path=precomputed.key_path||func.runtime.ui.build_container_key_path(containerXuData,keyP,precomputed.parent_infoP,nodeP,precomputed.parent_nodeP);const ui_id=func.runtime.ui.build_xu_ui_id_seed(nodeP,dsSessionP,key_path,currentRecordId);if(func.runtime.ui.ui_id_hash_cache.has(ui_id)){return func.runtime.ui.ui_id_hash_cache.get(ui_id)}const hashed_ui_id=await func.common.fastHash(ui_id);func.runtime.ui.ui_id_hash_cache.set(ui_id,hashed_ui_id);return hashed_ui_id};func.runtime.ui.create_container=async function(options){let _paramsP;try{_paramsP=JSON.parse(JSON.stringify(options.paramsP))}catch(e){_paramsP=Object.assign({},options.paramsP)}const _ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[_paramsP.dsSessionP];const $appendTo=func.runtime.ui.get_append_target(options.$container,options.$appendToP);if(!$appendTo)return null;const container_data=func.runtime.ui.get_data(options.$container);const container_xu_data=container_data?.xuData;const items=func.runtime.ui.get_node_child_items(options.nodeP);const currentRecordId=container_xu_data?.recordid||(_ds?_ds.currentRecordId:"");try{const key_path=func.runtime.ui.build_container_key_path(container_xu_data,options.keyP,options.parent_infoP,options.nodeP,options.parent_nodeP);const elem_key=`${options.nodeP.xu_tree_id||options.nodeP.id}-${key_path}-${currentRecordId}`;const hydration_candidate=func.runtime.ui.find_hydration_candidate({...options,$appendTo:$appendTo});const $div=hydration_candidate||func.runtime.ui.create_container_element(options.div_typeP,options.attr_str,options.prop,options.nodeP,$appendTo);const new_ui_id=await func.runtime.ui.generate_xu_ui_id(options.SESSION_ID,options.nodeP,options.$container,options.paramsP,options.keyP,{container_xu_data:container_xu_data,currentRecordId:currentRecordId,key_path:key_path,parent_infoP:options.parent_infoP,parent_nodeP:options.parent_nodeP});func.runtime.ui.apply_container_meta($div,{ui_id:new_ui_id,paramsP:_paramsP,nodeP:options.nodeP,currentRecordId:currentRecordId,keyP:options.keyP,key_path:key_path,$container:options.$container,prop:options.prop,elem_key:elem_key,elem_propP:options.elem_propP,items:items,parent_nodeP:options.parent_nodeP,$root_container:options.$root_container,parent_infoP:options.parent_infoP,is_placeholder:options.is_placeholder,classP:options.classP,treeP:options.treeP});if(!hydration_candidate&&options.div_typeP!=="svg"){func.runtime.ui.append_to($div,$appendTo)}return $div}catch(e){console.error(e)}return null};func.UI.utils={};func.UI.utils.indicator={};func.UI.utils.indicator.worker={};func.UI.utils.indicator.worker.busy=function(){document.querySelectorAll(".progressLoader").forEach(function(el){el.classList.add("progress_busy")})};func.UI.utils.indicator.worker.normal=function(){document.querySelectorAll(".progressLoader").forEach(function(el){el.classList.remove("progress_busy")})};func.UI.utils.indicator.server={};func.UI.utils.indicator.server.busy=function(){func.UI.utils.indicator.worker.busy()};func.UI.utils.indicator.server.normal=function(){func.UI.utils.indicator.worker.normal()};func.UI.utils.indicator.screen={};func.UI.utils.indicator.screen.busy=function(){document.querySelectorAll(".progressLoader").forEach(function(el){el.classList.add("progress_busy2")})};func.UI.utils.indicator.screen.normal=function(){document.querySelectorAll(".progressLoader").forEach(function(el){el.classList.remove("progress_busy2")})};func.UI.utils.save=function(SESSION_ID,stateP){if(stateP)func.UI.utils.indicator.worker.busy();else func.UI.utils.indicator.worker.normal()};func.UI.utils.screen_blocker=function(onP,idP,dsP){if(!idP){func.utils.debug_report("","Worker","Missing reference id","E");return}window.oncontextmenu=function(){if(onP)return false;else return true};if(!onP){delete SCREEN_BLOCKER_OBJ[idP];return}if(idP!=="Worker"){SCREEN_BLOCKER_OBJ[idP]=Date.now()}};func.UI.utils.get_node_elm=function(SESSION_ID,dsSessionP,ui_idP,$container,is_app_panel,ui_type,functionP){if(!$container){$container=func.runtime.ui._wrap_matches([document.body])}var $elm;if(!is_app_panel&&func.runtime?.ui?.find_xu_ui_in_root){$elm=func.runtime.ui.find_xu_ui_in_root(SESSION_ID,ui_idP)}else if(is_app_panel&&func.runtime?.ui?.find_panel_wrapper_in_root){$elm=func.runtime.ui.find_panel_wrapper_in_root(SESSION_ID,ui_idP)}if(!$elm?.length){$elm=func.UI.utils.find_in_element_data(is_app_panel?"xuPanelData":"xuData",$container,"ui_id",ui_idP)}const _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dsSessionP];if(_ds.tree_obj.renderType==="form"){return $elm}var $grid_elm;const grid_elements=$elm.toArray();for(let index=0;index<grid_elements.length;index++){const candidate=grid_elements[index];if(func.runtime.ui.get_data(candidate)?.xuData?.recordid===_ds.currentRecordId){$grid_elm=func.runtime.ui._wrap_matches([candidate]);break}}return $grid_elm;return $elm};func.UI.utils.get_nodeId=function(SESSION_ID,dsSessionP,ui_idP,$container,is_app_panel){var $elm=func.UI.utils.get_node_elm(SESSION_ID,dsSessionP,ui_idP,$container,is_app_panel,null,null);if(is_app_panel){return func.runtime.ui.get_data($elm)?.xuData?.panel_info?.prop?.id}else{return func.runtime.ui.get_attr($elm,"nodeId")}};func.UI.utils.get_ui_id_count=function(SESSION_ID,dsSessionP,ui_idP,$container){return func.UI.utils.get_node_elm(SESSION_ID,dsSessionP,ui_idP,$container,null,null).length};func.UI.utils.clean_node_busy=function(node){var run_node=function(node){node.busy=false;for(var key in node.children){run_node(node.children[key])}};run_node(node);return node};func.UI.utils.live_preview_element_inspect_on=function(SESSION_ID,service){var elements=document.querySelectorAll("[xu-ui-id]");elements.forEach(function(val){var _mouseenter_handler=function(){document.querySelectorAll(".preview_mark").forEach(function(el){el.classList.remove("preview_mark");el.removeEventListener("click",el._live_preview_click_handler)});val.classList.add("preview_mark");var _click_handler=function(e){const _session=SESSION_OBJ[SESSION_ID];console.log(func.runtime.ui.get_data(this));const data=func.runtime.ui.get_data(this);const obj={service:service+"_result",id:STUDIO_WEBSOCKET_CONNECTION_ID,uid:_session.USR_OBJ._id,source:"runtime",app_id:_session.app_id,gtp_token:_session.gtp_token,session_id:SESSION_ID,app_token:_session.app_token};switch(service){case"live_preview_element_reference":obj.data={prog_id:data.xuData.prog_id,node:data.xuData.node};break;case"live_preview_element_info":obj.data={element_info:data.debug_info,datasource:_session.DS_GLB[data.paramsP.dsSessionP]};break;case"live_preview_element_dnd":break;default:}STUDIO_PEER_CONN_SEND_METHOD(obj);func.UI.utils.live_preview_element_inspect_off();if(typeof LIVE_PREVIEW_APP_ACTIVE!=="undefined"){var refBtn=document.getElementById("live_preview_element_reference_btn");if(refBtn)refBtn.style.color="unset";var infoBtn=document.getElementById("live_preview_element_info_btn");if(infoBtn)infoBtn.style.color="unset"}};val._live_preview_click_handler=_click_handler;val.addEventListener("click",_click_handler)};var _mouseleave_handler=function(){val.classList.remove("preview_mark");if(val._live_preview_click_handler){val.removeEventListener("click",val._live_preview_click_handler);delete val._live_preview_click_handler}};val._live_preview_mouseenter_handler=_mouseenter_handler;val._live_preview_mouseleave_handler=_mouseleave_handler;val.addEventListener("mouseenter",_mouseenter_handler);val.addEventListener("mouseleave",_mouseleave_handler)})};func.UI.utils.live_preview_element_inspect_off=function(){document.querySelectorAll("[xu-ui-id]").forEach(function(val){if(val._live_preview_mouseenter_handler){val.removeEventListener("mouseenter",val._live_preview_mouseenter_handler);delete val._live_preview_mouseenter_handler}if(val._live_preview_mouseleave_handler){val.removeEventListener("mouseleave",val._live_preview_mouseleave_handler);delete val._live_preview_mouseleave_handler}});document.querySelectorAll(".preview_mark").forEach(function(el){el.classList.remove("preview_mark");if(el._live_preview_click_handler){el.removeEventListener("click",el._live_preview_click_handler);delete el._live_preview_click_handler}})};func.UI.utils.live_preview_show_selected_element=function(nodeid){document.querySelectorAll(".preview_mark").forEach(function(el){el.classList.remove("preview_mark")});document.querySelectorAll(`[nodeid="${nodeid}"]`).forEach(function(el){el.classList.add("preview_mark")})};func.UI.utils.get_url_attribute=function(SESSION_ID,key){const _session=SESSION_OBJ[SESSION_ID];const platform=func.runtime.platform;const url_param=glb.URL_PARAMS?.get?.(key);const root_attribute=func.runtime.ui.get_attr(_session.root_element,key);const option_param=_session.opt?.params?.[key];const option_value=_session.opt?.[key];const cookie_value=platform.get_cookie_item(key);const storage_value=platform.get_storage_item(key,"local");return url_param||root_attribute||option_param||option_value||cookie_value||storage_value};func.UI.utils.get_root_element_attributes=function(SESSION_ID){var ret={};var root_el=func.runtime.ui.get_first_node(SESSION_OBJ[SESSION_ID].root_element);if(root_el){var attrs=root_el.attributes;for(var i=0;i<attrs.length;i++){if(attrs[i].specified){ret[attrs[i].name]=attrs[i].value}}}return ret};func.UI.utils.prompt_confirm_window=async function(SESSION_ID,messageP,picP,confirmYesFuncP,confirmNoFuncP,confirmCancelFuncP,title,colorP){if(confirmNoFuncP){buttons.push({text:"Disagree",role:"no",cssClass:"secondary",handler:()=>{confirmNoFuncP()}})}if(confirmYesFuncP){buttons.push({text:"Agree",role:"yes",cssClass:"secondary",handler:()=>{confirmYesFuncP()}})}if(confirmCancelFuncP){buttons.push({text:"Dismiss",role:"cancel",cssClass:"secondary",handler:()=>{confirmCancelFuncP()}})}UI_FRAMEWORK_PLUGIN.modal(title,messageP,buttons)};func.UI.utils.alert=function(msg){console.error(msg)};func.UI.utils.progressScreen={};func.UI.utils.progressScreen.show=function(SESSION_ID,textP,show_bytesP,error,progress_off,logo_off){if(glb.IS_WORKER){return}const app_obj=APP_OBJ?.[SESSION_OBJ?.[SESSION_ID]?.app_id];var background_color="";var icon=app_obj?._conf?.logo_url||"https://xuda.ai/dist/images/xuda_logo.png";if(app_obj?.app_pic){icon=app_obj.app_pic}if(app_obj&&app_obj.app_icon_prop){if(app_obj.app_icon_prop.app_icon_background_color){background_color=app_obj.app_icon_prop.app_icon_background_color}}IS_PROGRESS_SCREEN_OPEN=true;var progressScreen=document.getElementById("progressScreen2");if(progressScreen)progressScreen.innerHTML="";document.querySelectorAll(".loader").forEach(function(el){el.style.display="none"});if(background_color&&progressScreen){progressScreen.style.color=func.common.getContrast_color(background_color);progressScreen.style.backgroundColor=background_color}setTimeout(function(){if(IS_PROGRESS_SCREEN_OPEN){var error_msg=`<h4>${textP}</h4>`;var progressText=document.getElementById("progressScreen2_text");if(progressText){progressText.style.display="";if(!logo_off){var img=document.createElement("img");img.className="progressScreen_logo";img.src=icon;progressText.prepend(img)}if(error){progressText.insertAdjacentHTML("beforeend",error_msg)}else if(typeof textP==="object"){progressText.appendChild(textP)}else{progressText.insertAdjacentHTML("beforeend",`<p>${textP}</p>`)}}}},500);if(progressScreen)progressScreen.style.display="";var textDiv=document.createElement("div");textDiv.id="progressScreen2_text";textDiv.style.display="none";if(progressScreen)progressScreen.appendChild(textDiv)};func.UI.utils.progressScreen.hide=function(){if(glb.IS_WORKER){return}IS_PROGRESS_SCREEN_OPEN=false;var ps2=document.getElementById("progressScreen2");if(ps2)ps2.style.display="none";var ps2text=document.getElementById("progressScreen2_text");if(ps2text)ps2text.innerHTML=""};func.UI.utils.find_in_element_data=function(folder,$elm,key,val){if(!$elm?.length){return func.runtime.ui._wrap_matches([])}if(folder==="xuData"&&key==="ui_id"&&typeof val!=="undefined"){return func.runtime.ui.find_by_selector($elm,`[xu-ui-id="${val}"]`)}if(folder==="xuPanelWrapper"&&key==="isWrapper"&&typeof val==="undefined"){return func.runtime.ui.find_by_selector($elm,"[xu-panel-wrapper-id]")}let candidate_selector;if(folder==="xuData"||folder==="xuPanelData"){candidate_selector="[xu-ui-id]"}else if(folder==="xuPanelWrapper"){candidate_selector="[xu-panel-wrapper-id]"}else{candidate_selector="*"}const matches=[];const roots=$elm.toArray();for(let root_index=0;root_index<roots.length;root_index++){const root_node=roots[root_index];const candidates=root_node?.querySelectorAll?.(candidate_selector)||[];for(let candidate_index=0;candidate_index<candidates.length;candidate_index++){const candidate=candidates[candidate_index];const folder_data=func.runtime.ui.get_data(candidate)?.[folder];if(!folder_data){continue}if(typeof val==="undefined"){if(!folder_data[key]){continue}}else if(folder_data[key]!=val){continue}matches.push(candidate)}}return func.runtime.ui._wrap_matches(matches)};func.UI.utils.init_ui_framework=async function(SESSION_ID,prog_id){if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE)return;var _session=SESSION_OBJ[SESSION_ID];var tree_obj=await func.utils.TREE_OBJ.get(SESSION_ID,prog_id);if(xu_isEmpty(tree_obj)){return console.error("Error: prog "+prog_id+" not found.")}const report_error=function(descP,warn){func.utils.debug.log(SESSION_ID,prog_id,{module:"component",action:"Init",source:"install ui framework",prop:descP,details:descP,result:null,error:warn?false:true,fields:null,type:"component",prog_id:prog_id})};const plugin_name=tree_obj.uiFramework;if(!plugin_name){return report_error("no frameworks plugin defined",true)}if(plugin_name===UI_FRAMEWORK_INSTALLED)return;const _plugin=APP_OBJ[_session.app_id]?.app_plugins_purchased?.[plugin_name];if(!_plugin?.installed){return report_error(`plugin ${plugin_name} not installed`)}const get_path=function(plugin_name,resource){var path=`https://${_session.domain}/plugins/${plugin_name}${resource?"/"+resource:""}?app_id=${_session.app_id}`;return path};var _ui_framework_index;try{const runtime_mjs=`${_plugin.manifest["runtime.mjs"].dist?"dist/":""}runtime.mjs`;_ui_framework_index=await import(get_path(plugin_name,runtime_mjs))}catch(error){return report_error(`plugin ${plugin_name} not found`)}if(!_ui_framework_index){return report_error(`plugin ${plugin_name} is empty`)}if(!_ui_framework_index.core){return report_error(`plugin core not found in ${plugin_name} `)}var _ui_framework_dashboard_setup;var _ui_framework_dashboard_setup_data_ret;const ui_framework_core=new _ui_framework_index.core;if(ui_framework_core.init){try{const setup_mjs=`${_plugin.manifest["index.mjs"].dist?"dist/":""}index.mjs`;_ui_framework_dashboard_setup=await import(get_path(plugin_name,setup_mjs));if(_ui_framework_dashboard_setup){_ui_framework_dashboard_setup_data_ret=await func.utils.get_plugin_setup(SESSION_ID,plugin_name)}}catch(error){}}if(plugin_name!==UI_FRAMEWORK_INSTALLED){UI_FRAMEWORK_INSTALLED=plugin_name;const _plugin_INSTALLED=APP_OBJ[_session.app_id]?.app_plugins_purchased?.[UI_FRAMEWORK_INSTALLED];UI_FRAMEWORK_PLUGIN=_ui_framework_index;if(UI_FRAMEWORK_INSTALLED){var _current_ui_framework_runtime;try{const _runtime_mjs=`${_plugin_INSTALLED.manifest["runtime.mjs"].dist?"dist/":""}runtime.mjs`;_current_ui_framework_runtime=await import(get_path(UI_FRAMEWORK_INSTALLED,_runtime_mjs))}catch(error){return report_error(`plugin ${UI_FRAMEWORK_INSTALLED} not found`)}if(UI_FRAMEWORK_PLUGIN.core.discard&&UI_FRAMEWORK_PLUGIN.init_id){UI_FRAMEWORK_PLUGIN.core.discard(UI_FRAMEWORK_PLUGIN.init_id)}if(_ui_framework_index.resources){for(var key in _current_ui_framework_runtime.resources){var val=_current_ui_framework_runtime.resources[key];func.utils.remove_js_css_file(val.url,val.type)}}}var init_id;if(_ui_framework_index.resources){for await(var val of _ui_framework_index.resources){var ret=undefined;var url=val.url;switch(val.type){case"module":try{ret=await func.utils.load_js_on_demand(url,"module")}catch(error){debugger}break;case"css":ret=func.utils.load_css_on_demand(url);break;case"js":ret=await func.utils.load_js_on_demand(url);break;default:break}if(val.callback){val.callback(ret)}}}if(ui_framework_core.init){init_id=await ui_framework_core.init(_ui_framework_dashboard_setup_data_ret?.code>-1&&_ui_framework_dashboard_setup_data_ret.data);UI_FRAMEWORK_PLUGIN.init_id=init_id}}};func.UI.utils.get_panels_wrapper_from_dom=async function(SESSION_ID,$xu_embed_container,ignore_disableAutoRefresh){const get_refresh_state=function(){return func.runtime?.ui?.ensure_refresh_dependency_state?.(SESSION_ID)||null};const get_cached_panels_obj=function(refresh_state){const cached_panels=ignore_disableAutoRefresh?refresh_state?.panel_wrappers_cache:refresh_state?.panel_wrappers_active_cache;const panels_obj=cached_panels||{};let requires_rebuild=false;const panel_keys=Object.keys(refresh_state?.panel_wrappers_cache||{});for(let index=0;index<panel_keys.length;index++){const panel_entry=refresh_state.panel_wrappers_cache[panel_keys[index]];if(!panel_entry?.$panel_div?.length||!panel_entry.$panel_div[0]?.isConnected){requires_rebuild=true;break}}if(requires_rebuild){refresh_state.panel_wrappers_dirty=true;refresh_state.panel_wrappers_cache={};refresh_state.panel_wrappers_active_cache={};return null}return panels_obj};const refresh_state=get_refresh_state();if(refresh_state&&!refresh_state.panel_wrappers_dirty&&!xu_isEmpty(refresh_state.panel_wrappers_cache)){const cached_panels_obj=get_cached_panels_obj(refresh_state);if(cached_panels_obj){return cached_panels_obj}}let $elm=func.runtime?.ui?.get_refresh_indexed_panel_wrappers?.(SESSION_ID);if(!$elm?.length){const $root=func.runtime?.ui?.get_refresh_index_root?.(SESSION_ID)||func.runtime.ui._wrap_matches([func.runtime.ui.get_first_node(SESSION_OBJ[SESSION_ID].root_element)]);if(func.runtime?.ui?.find_refresh_elements_by_attr){$elm=func.runtime.ui.find_refresh_elements_by_attr($root,"xu-panel-wrapper-id")}else{var _root_node=func.runtime.ui.get_first_node($root);var _panel_matches=[];if(_root_node?.matches?.("[xu-panel-wrapper-id]"))_panel_matches.push(_root_node);_root_node?.querySelectorAll?.("[xu-panel-wrapper-id]")?.forEach(function(el){_panel_matches.push(el)});$elm=func.runtime.ui._wrap_matches(_panel_matches)}}const panels_obj={};const prog_doc_cache={};const panel_elements=Array.isArray($elm)?$elm:$elm.toArray?$elm.toArray():Array.from($elm);for(let elem_index=0;elem_index<panel_elements.length;elem_index++){const $panel_div=func.runtime.ui._wrap_matches([panel_elements[elem_index]]);const panel_wrapper_data=func.runtime.ui.get_data($panel_div)?.xuPanelWrapper;const panelXuAttributes=panel_wrapper_data?.panelXuAttributes;const panelDivData=panel_wrapper_data?.panelDivData;if(!panelXuAttributes)continue;const xu_ui_id=func.runtime.ui.get_attr($panel_div,"xu-ui-id");if(!panels_obj[xu_ui_id]){var _session=SESSION_OBJ[SESSION_ID];let _ds=_session?.DS_GLB[panelDivData.xuData.paramsP.dsSessionP];if(!_ds)continue;let prog_doc=prog_doc_cache[_ds.prog_id];if(!prog_doc){prog_doc=await func.utils.DOCS_OBJ.get(SESSION_ID,_ds.prog_id);prog_doc_cache[_ds.prog_id]=prog_doc}if(!ignore_disableAutoRefresh&&prog_doc.properties.disableAutoRefresh){continue}const ids=[];const child_nodes=$panel_div[0]?.children||[];for(let child_index=0;child_index<child_nodes.length;child_index++){const child_node=child_nodes[child_index];if(func.runtime.ui.get_data(child_node)?.xuPanelData){ids.push(func.runtime.ui.get_attr(child_node,"xu-ui-id"))}}panels_obj[xu_ui_id]={panelXuAttributes:panelXuAttributes,progUi:prog_doc.progUi,prog_doc:prog_doc,$panel_div:$panel_div,_ds:_ds,ids:ids}}}if(refresh_state){refresh_state.panel_wrappers_cache=panels_obj;refresh_state.panel_wrappers_active_cache={};const panel_keys=Object.keys(panels_obj);for(let index=0;index<panel_keys.length;index++){const xu_ui_id=panel_keys[index];const panel_entry=panels_obj[xu_ui_id];if(panel_entry?.prog_doc?.properties?.disableAutoRefresh){continue}refresh_state.panel_wrappers_active_cache[xu_ui_id]=panel_entry}refresh_state.panel_wrappers_dirty=false}if(!ignore_disableAutoRefresh){return refresh_state?.panel_wrappers_active_cache||panels_obj}return panels_obj};func.UI.worker={};func.UI.worker.ID=null;func.UI.worker.idle=0;func.UI.worker.ensure_runtime_indexes=function(){if(!UI_WORKER_OBJ.job_index_by_num){UI_WORKER_OBJ.job_index_by_num={}}if(!UI_WORKER_OBJ.jobs_by_queue_key){UI_WORKER_OBJ.jobs_by_queue_key={}}if(!UI_WORKER_OBJ.viewport_height_set_ids_set){UI_WORKER_OBJ.viewport_height_set_ids_set=new Set(UI_WORKER_OBJ.viewport_height_set_ids||[])}if(!UI_WORKER_OBJ.pending_delete_sessions){UI_WORKER_OBJ.pending_delete_sessions=new Set}if(!UI_WORKER_OBJ.pending_delete_elements_by_session){UI_WORKER_OBJ.pending_delete_elements_by_session={}}if(typeof UI_WORKER_OBJ.run_timer==="undefined"){UI_WORKER_OBJ.run_timer=null}if(typeof UI_WORKER_OBJ.run_in_progress==="undefined"){UI_WORKER_OBJ.run_in_progress=false}if(typeof UI_WORKER_OBJ.run_again==="undefined"){UI_WORKER_OBJ.run_again=false}if(typeof UI_WORKER_OBJ.run_schedule_type==="undefined"){UI_WORKER_OBJ.run_schedule_type=null}if(typeof UI_WORKER_OBJ.dom_jobs_per_frame==="undefined"){UI_WORKER_OBJ.dom_jobs_per_frame=8}if(!UI_WORKER_OBJ.job_lane_counts){UI_WORKER_OBJ.job_lane_counts={data:0,dom:0};(UI_WORKER_OBJ.jobs||[]).forEach(function(job){if(!job){return}const lane=job.lane||func.UI.worker.get_job_lane(job.functionP);UI_WORKER_OBJ.job_lane_counts[lane]=(UI_WORKER_OBJ.job_lane_counts[lane]||0)+1})}if(typeof UI_WORKER_OBJ.active_jobs_count==="undefined"){UI_WORKER_OBJ.active_jobs_count=0;for(let index=0;index<(UI_WORKER_OBJ.jobs||[]).length;index++){if(UI_WORKER_OBJ.jobs[index]){UI_WORKER_OBJ.active_jobs_count++}}}if(typeof UI_WORKER_OBJ.job_holes_count==="undefined"){UI_WORKER_OBJ.job_holes_count=Math.max(0,(UI_WORKER_OBJ.jobs||[]).length-UI_WORKER_OBJ.active_jobs_count)}if(typeof UI_WORKER_OBJ.first_active_job_index==="undefined"){UI_WORKER_OBJ.first_active_job_index=null;for(let index=0;index<(UI_WORKER_OBJ.jobs||[]).length;index++){if(UI_WORKER_OBJ.jobs[index]){UI_WORKER_OBJ.first_active_job_index=index;break}}}};func.UI.worker.get_job_lane=function(functionP){if(functionP==="update_datasource"){return"data"}return"dom"};func.UI.worker.register_job=function(job,index=UI_WORKER_OBJ.jobs.length-1){func.UI.worker.ensure_runtime_indexes();if(!job){return false}if(!job.lane){job.lane=func.UI.worker.get_job_lane(job.functionP)}UI_WORKER_OBJ.job_index_by_num[job.job_num]=index;if(job.queue_key){UI_WORKER_OBJ.jobs_by_queue_key[job.queue_key]=job}UI_WORKER_OBJ.job_lane_counts[job.lane]=(UI_WORKER_OBJ.job_lane_counts[job.lane]||0)+1;UI_WORKER_OBJ.active_jobs_count++;if(UI_WORKER_OBJ.first_active_job_index===null||index<UI_WORKER_OBJ.first_active_job_index){UI_WORKER_OBJ.first_active_job_index=index}return true};func.UI.worker.unregister_job=function(job){func.UI.worker.ensure_runtime_indexes();if(!job){return false}delete UI_WORKER_OBJ.job_index_by_num[job.job_num];if(job.queue_key&&UI_WORKER_OBJ.jobs_by_queue_key[job.queue_key]?.job_num===job.job_num){delete UI_WORKER_OBJ.jobs_by_queue_key[job.queue_key]}if(job.lane&&UI_WORKER_OBJ.job_lane_counts[job.lane]>0){UI_WORKER_OBJ.job_lane_counts[job.lane]--}if(UI_WORKER_OBJ.active_jobs_count>0){UI_WORKER_OBJ.active_jobs_count--}return true};func.UI.worker.advance_first_active_job_index=function(start_index=UI_WORKER_OBJ.first_active_job_index||0){func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.active_jobs_count){UI_WORKER_OBJ.first_active_job_index=null;return null}for(let index=Math.max(0,start_index);index<UI_WORKER_OBJ.jobs.length;index++){if(UI_WORKER_OBJ.jobs[index]){UI_WORKER_OBJ.first_active_job_index=index;return UI_WORKER_OBJ.jobs[index]}}UI_WORKER_OBJ.first_active_job_index=null;return null};func.UI.worker.compact_jobs=function(){func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.job_holes_count){return false}const compacted_jobs=[];UI_WORKER_OBJ.job_index_by_num={};UI_WORKER_OBJ.jobs_by_queue_key={};UI_WORKER_OBJ.job_lane_counts={data:0,dom:0};UI_WORKER_OBJ.job_holes_count=0;UI_WORKER_OBJ.first_active_job_index=null;for(let index=0;index<UI_WORKER_OBJ.jobs.length;index++){const job=UI_WORKER_OBJ.jobs[index];if(!job){continue}const compacted_index=compacted_jobs.length;compacted_jobs.push(job);UI_WORKER_OBJ.job_index_by_num[job.job_num]=compacted_index;if(job.queue_key){UI_WORKER_OBJ.jobs_by_queue_key[job.queue_key]=job}UI_WORKER_OBJ.job_lane_counts[job.lane]=(UI_WORKER_OBJ.job_lane_counts[job.lane]||0)+1;if(UI_WORKER_OBJ.first_active_job_index===null){UI_WORKER_OBJ.first_active_job_index=compacted_index}}UI_WORKER_OBJ.jobs=compacted_jobs;return true};func.UI.worker.maybe_compact_jobs=function(force=false){func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.job_holes_count){return false}const jobs_length=UI_WORKER_OBJ.jobs.length;const should_compact=force||UI_WORKER_OBJ.job_holes_count>=50||UI_WORKER_OBJ.job_holes_count>=Math.ceil(jobs_length/3)||UI_WORKER_OBJ.first_active_job_index!==null&&UI_WORKER_OBJ.first_active_job_index>0;if(!should_compact){return false}return func.UI.worker.compact_jobs()};func.UI.worker.get_first_active_job=function(){func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.active_jobs_count){UI_WORKER_OBJ.first_active_job_index=null;return null}if(UI_WORKER_OBJ.first_active_job_index!==null){const active_job=UI_WORKER_OBJ.jobs[UI_WORKER_OBJ.first_active_job_index];if(active_job){return active_job}}const job=func.UI.worker.advance_first_active_job_index(0);if(job){if(UI_WORKER_OBJ.first_active_job_index>0){func.UI.worker.maybe_compact_jobs(true)}return job}UI_WORKER_OBJ.active_jobs_count=0;UI_WORKER_OBJ.job_holes_count=UI_WORKER_OBJ.jobs.length;UI_WORKER_OBJ.first_active_job_index=null;func.UI.worker.maybe_compact_jobs(true);return null};func.UI.worker.get_pending_run_mode=function(){func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.active_jobs_count){return null}if(UI_WORKER_OBJ.job_lane_counts?.data>0){return"data"}return"dom"};func.UI.worker.cancel_pending_run=function(){func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.run_timer){return false}if(UI_WORKER_OBJ.run_schedule_type==="dom_frame"){if(typeof window!=="undefined"&&typeof window.cancelAnimationFrame==="function"){window.cancelAnimationFrame(UI_WORKER_OBJ.run_timer)}else if(typeof cancelAnimationFrame==="function"){cancelAnimationFrame(UI_WORKER_OBJ.run_timer)}else{clearTimeout(UI_WORKER_OBJ.run_timer)}}else{clearTimeout(UI_WORKER_OBJ.run_timer)}UI_WORKER_OBJ.run_timer=null;UI_WORKER_OBJ.run_schedule_type=null;return true};func.UI.worker.request_frame=function(callback){if(typeof window!=="undefined"&&typeof window.requestAnimationFrame==="function"){return window.requestAnimationFrame(callback)}if(typeof requestAnimationFrame==="function"){return requestAnimationFrame(callback)}return setTimeout(callback,16)};func.UI.worker.reindex_jobs_from=function(start_index=0){func.UI.worker.ensure_runtime_indexes();for(let index=Math.max(0,start_index);index<UI_WORKER_OBJ.jobs.length;index++){const job=UI_WORKER_OBJ.jobs[index];if(!job){continue}UI_WORKER_OBJ.job_index_by_num[job.job_num]=index;if(job.queue_key){UI_WORKER_OBJ.jobs_by_queue_key[job.queue_key]=job}}};func.UI.worker.get_session_root=function(SESSION_ID){if(func.runtime?.ui?.get_root_element){const $root=func.runtime.ui.get_root_element(SESSION_ID);if($root?.length){return $root}}return func.runtime.ui._wrap_matches([document.body])};func.UI.worker.get_session_runtime_elements=function(SESSION_ID){if(func.runtime?.ui?.get_refresh_indexed_runtime_elements){const $indexed=func.runtime.ui.get_refresh_indexed_runtime_elements(SESSION_ID);if($indexed?.length){return $indexed}}const $root=func.UI.worker.get_session_root(SESSION_ID);if(func.runtime?.ui?.get_refresh_index_elements){return func.runtime.ui.get_refresh_index_elements(SESSION_ID,$root)}var _rt_root_node=func.runtime.ui.get_first_node($root);var _rt_matches=[];if(_rt_root_node?.matches?.("[xu-ui-id]"))_rt_matches.push(_rt_root_node);_rt_root_node?.querySelectorAll?.("[xu-ui-id]")?.forEach(function(el){_rt_matches.push(el)});return func.runtime.ui._wrap_matches(_rt_matches)};func.UI.worker.mark_pending_delete_session=function(SESSION_ID){func.UI.worker.ensure_runtime_indexes();if(SESSION_ID){UI_WORKER_OBJ.pending_delete_sessions.add(SESSION_ID)}};func.UI.worker.mark_pending_delete_element=function(SESSION_ID,target){func.UI.worker.ensure_runtime_indexes();if(!SESSION_ID||!target){return false}if(!UI_WORKER_OBJ.pending_delete_elements_by_session[SESSION_ID]){UI_WORKER_OBJ.pending_delete_elements_by_session[SESSION_ID]=new Set}const elements=Array.isArray(target)?target:target?.length!==undefined?Array.from(target):[func.runtime.ui.get_first_node(target)].filter(Boolean);elements.forEach(function(element){UI_WORKER_OBJ.pending_delete_elements_by_session[SESSION_ID].add(element)});UI_WORKER_OBJ.pending_delete_sessions.add(SESSION_ID);return true};func.UI.worker.cleanup_pending_to_delete=function(SESSION_ID=Object.keys(SESSION_OBJ)[0]){func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.pending_delete_sessions.has(SESSION_ID)){return}const pending_elements=UI_WORKER_OBJ.pending_delete_elements_by_session[SESSION_ID];if(pending_elements?.size){pending_elements.forEach(function(element){const element_data=func.runtime.ui.get_data(element);if(element_data?.xuData?.pending_to_delete){element_data.xuData.pending_to_delete=false}});pending_elements.clear()}else{const runtime_elements=func.UI.worker.get_session_runtime_elements(SESSION_ID);for(let index=0;index<runtime_elements.length;index++){const val=runtime_elements[index];const element_data=func.runtime.ui.get_data(val);if(element_data?.xuData?.pending_to_delete){element_data.xuData.pending_to_delete=false}}}UI_WORKER_OBJ.pending_delete_sessions.delete(SESSION_ID)};func.UI.worker.init=async function(SESSION_ID){func.UI.worker.ensure_runtime_indexes();func.UI.utils.isInViewport=function(el){var node=func.runtime.ui.get_first_node(el);if(!node)return false;var rect=node.getBoundingClientRect();return rect.bottom>0&&rect.top<(window.innerHeight||document.documentElement.clientHeight)};if(typeof $!=="undefined"&&$.fn){$.fn.isInViewport=function(){return func.UI.utils.isInViewport(this[0])}}if(!UI_WORKER_OBJ.in_flight_job_elements){UI_WORKER_OBJ.in_flight_job_elements=[]}const contains_job_element=function($parent,$child){const parent_node=$parent?.[0];const child_node=$child?.[0];if(!parent_node||!child_node){return false}return parent_node.contains(child_node)};func.UI.worker.cancel_child_in_flight_jobs=function($parent_element){if(!$parent_element?.length||!UI_WORKER_OBJ.in_flight_job_elements.length)return;const parent_node=$parent_element[0];if(!parent_node)return;for(let i=UI_WORKER_OBJ.in_flight_job_elements.length-1;i>=0;i--){const child_el=UI_WORKER_OBJ.in_flight_job_elements[i];const child_node=child_el?.[0];if(child_node&&parent_node.contains(child_node)){UI_WORKER_OBJ.in_flight_job_elements.splice(i,1)}}};const overlaps_any_in_flight=function(job){if(!job?.elementP){return false}for(let index=0;index<UI_WORKER_OBJ.in_flight_job_elements.length;index++){const active_el=UI_WORKER_OBJ.in_flight_job_elements[index];if(!active_el)continue;if(contains_job_element(active_el,job.elementP)){return true}}return false};const job_iterator=async function(run_mode="data"){const mark_pending_delete_on_descendants=function($element){if(!$element?.length){return}const descendants=$element[0]?.querySelectorAll?.("[xu-ui-id]")||[];for(let index=0;index<descendants.length;index++){const val=descendants[index];const elm_data=func.runtime.ui.get_data(val);if(!elm_data?.xuData){continue}elm_data.xuData.pending_to_delete=true;func.UI.worker.mark_pending_delete_element(SESSION_ID,val)}};const dom_job_budget=run_mode==="dom"?UI_WORKER_OBJ.dom_jobs_per_frame:Number.POSITIVE_INFINITY;let dom_jobs_processed=0;const dispatched_jobs=[];if(UI_WORKER_OBJ.active_jobs_count){func.UI.worker.idle=0;for(let key=0;key<UI_WORKER_OBJ.jobs.length;key++){const val=UI_WORKER_OBJ.jobs[key];try{if(!val)continue;if(val.stat==="busy")continue;const job_lane=val.lane||func.UI.worker.get_job_lane(val.functionP);val.lane=job_lane;if(run_mode==="data"&&job_lane!=="data")continue;if(job_lane==="dom"&&dom_jobs_processed>=dom_job_budget)continue;if(overlaps_any_in_flight(val))continue;if(!val.elementP){const job_promise=func.UI.worker.execute(val.SESSION_ID,val).catch(function(err){console.error(err)});dispatched_jobs.push(job_promise);if(job_lane==="dom"){dom_jobs_processed++}continue}const active_xu_ui_id=func.runtime.ui.get_attr(val.elementP,"xu-ui-id");if(!active_xu_ui_id)continue;const running_job_obj=func.UI.worker.get_first_active_job();if(!running_job_obj){break}if(running_job_obj.job_num!==val.job_num){if(contains_job_element(running_job_obj.elementP,val.elementP)){continue}if(contains_job_element(val.elementP,running_job_obj.elementP)){continue}}const in_flight_entry=val.elementP;UI_WORKER_OBJ.in_flight_job_elements.push(in_flight_entry);const job_promise=func.UI.worker.execute(val.SESSION_ID,val).catch(function(err){console.error(err)}).finally(function(){const idx=UI_WORKER_OBJ.in_flight_job_elements.indexOf(in_flight_entry);if(idx!==-1){UI_WORKER_OBJ.in_flight_job_elements.splice(idx,1)}func.UI.worker.schedule_run(0)});dispatched_jobs.push(job_promise);if(job_lane==="dom"){dom_jobs_processed++}continue}catch(err){console.error(err)}}}};func.UI.worker.schedule_run=function(delay=0,preferred_mode){func.UI.worker.ensure_runtime_indexes();if(UI_WORKER_OBJ.run_in_progress){UI_WORKER_OBJ.run_again=true;return}const run_mode=preferred_mode||func.UI.worker.get_pending_run_mode()||"data";if(UI_WORKER_OBJ.run_timer){const should_promote_data=run_mode==="data"&&UI_WORKER_OBJ.run_schedule_type&&UI_WORKER_OBJ.run_schedule_type!=="data";if(!should_promote_data){return}func.UI.worker.cancel_pending_run()}const run_once=async function(){UI_WORKER_OBJ.run_timer=null;UI_WORKER_OBJ.run_schedule_type=null;UI_WORKER_OBJ.run_in_progress=true;try{await job_iterator(run_mode)}finally{UI_WORKER_OBJ.run_in_progress=false;func.UI.worker.maybe_compact_jobs();const next_run_mode=func.UI.worker.get_pending_run_mode();const should_continue=UI_WORKER_OBJ.run_again||!!next_run_mode;UI_WORKER_OBJ.run_again=false;if(should_continue){func.UI.worker.schedule_run(0,next_run_mode||undefined)}}};UI_WORKER_OBJ.run_schedule_type=run_mode;if(run_mode==="dom"){if(delay>0){UI_WORKER_OBJ.run_schedule_type="dom_delay";UI_WORKER_OBJ.run_timer=setTimeout(function(){UI_WORKER_OBJ.run_schedule_type="dom_frame";UI_WORKER_OBJ.run_timer=func.UI.worker.request_frame(run_once)},delay)}else{UI_WORKER_OBJ.run_schedule_type="dom_frame";UI_WORKER_OBJ.run_timer=func.UI.worker.request_frame(run_once)}}else{UI_WORKER_OBJ.run_schedule_type="data";UI_WORKER_OBJ.run_timer=setTimeout(run_once,delay)}this._interval=UI_WORKER_OBJ.run_timer};if(!UI_WORKER_OBJ.maintenance_intervals_initialized){UI_WORKER_OBJ.maintenance_intervals_initialized=true;setInterval(async function(){func.UI.ds_garbage_collector()},1e4);setInterval(async function(){func.UI.worker.cleanup_pending_to_delete();func.UI.refs_garbage_collector();func.UI.teleport_garbage_collector()},1e3)}};func.UI.worker.add_to_queue=async function(SESSION_ID,source,functionP,paramsP,calling_job,elementP,dsSession,calling_trigger_prop){func.UI.worker.ensure_runtime_indexes();var obj={SESSION_ID:SESSION_ID,source:source,functionP:functionP,paramsP:paramsP,calling_job:calling_job,elementP:elementP,dsSession:dsSession,calling_trigger_prop:calling_trigger_prop,job_num:UI_WORKER_OBJ.num};obj.lane=func.UI.worker.get_job_lane(functionP);const get_ui_id=function(target){return func.runtime?.ui?.get_attr?func.runtime.ui.get_attr(target,"xu-ui-id"):target?.attr?.("xu-ui-id")};const get_parent_ui_id=function(target){const parent_node=func.runtime.ui.get_first_node(target)?.parentElement;if(!parent_node){return""}return get_ui_id(parent_node)};const get_queue_key=function(){if(functionP==="update_datasource"){return source+"_"+functionP+"_"+(dsSession||"")+"_"+(paramsP?.currentRecordId||"")+"_"+(paramsP?.field_id||"")}if(functionP==="render_viewport"){return source+"_"+functionP+"_"+(get_ui_id(paramsP?.$div)||"")}if(functionP==="set_viewport_height"){return source+"_"+functionP+"_"+(get_parent_ui_id(paramsP?.$div)||"")}if(functionP==="execute_xu_all_attributes"){return source+"_"+functionP+"_"+(get_ui_id(elementP)||"")+"_"+(paramsP?.fields_arr?.toString()||"")}if(functionP==="execute_xu_render_attributes"){return source+"_"+functionP+"_"+(get_ui_id(elementP)||"")+"_"+(paramsP?.attr_value?.toString?.()||paramsP?.attr_value||"")+"_"+(paramsP?.fields_arr?.toString()||"")}if(functionP==="execute_xu_for"){return source+"_"+functionP+"_"+(get_ui_id(elementP)||"")+"_"+(paramsP?.xu_for_item_id||"")}if(functionP==="execute_xu_widget"){return source+"_"+functionP+"_"+(get_ui_id(elementP)||"")}return null};const queue_key=get_queue_key();if(queue_key){obj.queue_key=queue_key;let exist_job=UI_WORKER_OBJ.jobs_by_queue_key?.[queue_key];if(exist_job){func.runtime?.perf?.increment?.(SESSION_ID,"jobs_coalesced");func.runtime?.perf?.increment_map?.(SESSION_ID,"jobs_coalesced_by_function",functionP);exist_job.paramsP=paramsP;exist_job.calling_trigger_prop=calling_trigger_prop;exist_job.elementP=elementP;exist_job.dsSession=dsSession;exist_job.lane=obj.lane;return exist_job.job_num}}UI_WORKER_OBJ.jobs.push(obj);func.UI.worker.register_job(obj,UI_WORKER_OBJ.jobs.length-1);func.runtime?.perf?.increment?.(SESSION_ID,"jobs_queued");func.runtime?.perf?.increment_map?.(SESSION_ID,"jobs_queued_by_function",functionP);if(func.UI.worker.schedule_run){func.UI.worker.schedule_run(0,obj.lane==="data"?"data":undefined)}UI_WORKER_OBJ.num++;return UI_WORKER_OBJ.num-1};func.UI.worker.delete_job=async function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.UI.worker.find_job_index(SESSION_ID,jobNoP);if(job_index===null||typeof job_index==="undefined"||!UI_WORKER_OBJ.jobs[job_index]){return}const removed_job=UI_WORKER_OBJ.jobs[job_index];func.runtime?.perf?.increment?.(SESSION_ID,"jobs_completed");func.runtime?.perf?.increment_map?.(SESSION_ID,"jobs_completed_by_function",removed_job.functionP);var dsSession=removed_job.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?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}func.UI.worker.unregister_job(removed_job);UI_WORKER_OBJ.jobs[job_index]=null;UI_WORKER_OBJ.job_holes_count++;if(UI_WORKER_OBJ.first_active_job_index===job_index){func.UI.worker.advance_first_active_job_index(job_index+1)}func.UI.worker.maybe_compact_jobs(job_index===0)};func.UI.worker.execute=async function(SESSION_ID,queue_obj){var job_index=func.UI.worker.find_job_index(SESSION_ID,queue_obj.job_num);if(queue_obj.jobNoP)UI_WORKER_OBJ.stat=job_index;if(UI_WORKER_OBJ.jobs[job_index]){UI_WORKER_OBJ.jobs[job_index].stat="busy"}func.runtime?.perf?.increment?.(SESSION_ID,"jobs_executed");func.runtime?.perf?.increment_map?.(SESSION_ID,"jobs_executed_by_function",queue_obj.functionP);const fx={get_element_by_ui_id:function(xu_ui_id){if(!xu_ui_id){return func.runtime.ui._wrap_matches([])}if(func.runtime?.ui?.get_refresh_indexed_element_by_ui_id){const _elm=func.runtime.ui.get_refresh_indexed_element_by_ui_id(SESSION_ID,xu_ui_id);return func.runtime.ui._wrap_matches(_elm?[_elm]:[])}const $root=func.UI.worker.get_session_root(SESSION_ID);if(func.runtime?.ui?.find_refresh_elements_by_attr){return func.runtime.ui.find_refresh_elements_by_attr($root,"xu-ui-id",xu_ui_id,true)}return func.runtime.ui.find_by_selector($root,`[xu-ui-id="${xu_ui_id}"]`)},get_live_element_context:function(elem_key,fallback_$elm,context={}){let raw_$elm=elem_key?fx.get_element_by_ui_id(elem_key):fallback_$elm;let $elm=func.runtime?.ui?.get_preferred_live_element?func.runtime.ui.get_preferred_live_element(raw_$elm):raw_$elm;const matches_context=function(node_xu_data,allow_loose_match=false){if(!node_xu_data){return false}if(context.node_id&&node_xu_data.nodeid!==context.node_id){return false}if(typeof context.key!=="undefined"&&context.key!==null&&node_xu_data.key!==context.key){return false}if(context.key_path&&node_xu_data.key_path!==context.key_path){return false}if(context.recordid&&node_xu_data.recordid!==context.recordid){return false}if(!allow_loose_match){if(context.prog_id&&node_xu_data.paramsP?.prog_id!==context.prog_id){return false}if(context.parent_element_ui_id&&node_xu_data.parent_element_ui_id!==context.parent_element_ui_id){return false}}if(node_xu_data.pending_to_delete){return false}return true};const resolved_node=func.runtime.ui.get_first_node($elm);const resolved_data=resolved_node?func.runtime.ui.get_data(resolved_node)?.xuData:null;const has_matching_resolved_node=matches_context(resolved_data);if(context.node_id&&!has_matching_resolved_node){const $root=func.UI.worker.get_session_root(SESSION_ID);const runtime_nodes=func.runtime?.ui?.get_refresh_index_elements?func.runtime.ui.get_refresh_index_elements(SESSION_ID,$root).toArray():Array.from(func.runtime.ui.get_first_node($root)?.querySelectorAll("[xu-ui-id]")||[]);let matching_nodes=[];for(let index=0;index<runtime_nodes.length;index++){const node=runtime_nodes[index];const node_data=func.runtime.ui.get_data(node);const node_xu_data=node_data?.xuData;if(!matches_context(node_xu_data)){continue}matching_nodes.push(node)}if(!matching_nodes.length){for(let index=0;index<runtime_nodes.length;index++){const node=runtime_nodes[index];const node_data=func.runtime.ui.get_data(node);const node_xu_data=node_data?.xuData;if(!matches_context(node_xu_data,true)){continue}matching_nodes.push(node)}}if(matching_nodes.length){raw_$elm=func.runtime.ui._wrap_matches(matching_nodes);$elm=func.runtime?.ui?.get_preferred_live_element?func.runtime.ui.get_preferred_live_element(raw_$elm):raw_$elm}}const _resolved_node=func.runtime.ui.get_first_node($elm);if(!_resolved_node){return{$elm:func.runtime.ui._wrap_matches([]),data:null}}if(!$elm?.length){$elm=func.runtime.ui._wrap_matches([_resolved_node])}const data=func.runtime.ui.get_data($elm);return{$elm:$elm,data:data}},get_child_node_by_id:function(xuData,node_id){if(!xuData?.node_org?.children?.length||!node_id){return null}if(func.runtime?.ui?.get_node_children_by_id){const children_by_id=func.runtime.ui.get_node_children_by_id(xuData.node_org);return children_by_id[node_id]||null}if(!xuData.node_org_children_by_id){xuData.node_org_children_by_id={};for(let index=0;index<xuData.node_org.children.length;index++){const child_node=xuData.node_org.children[index];if(child_node?.id){xuData.node_org_children_by_id[child_node.id]=child_node}}}return xuData.node_org_children_by_id[node_id]||null},get_refresh_execution_plan:function(live_data,refresh_attributes){const xuData=live_data?.xuData;if(!xuData){return[]}if(!xuData.refresh_execution_plan_cache){xuData.refresh_execution_plan_cache={}}const cache_key=(refresh_attributes||[]).join("|");if(xuData.refresh_execution_plan_cache[cache_key]){return xuData.refresh_execution_plan_cache[cache_key]}const skip_attributes={"xu-exp:xu-render":true,"xu-exp:xu-for":true,"xu-for":true,"xu-exp:xu-bind":true};const raw_value_attributes={"xu-bind":true,"xu-ref":true,"xu-on":true,"xu-for-key":true,"xu-for-val":true,"xu-click":true,"xu-change":true,"xu-blur":true,"xu-focus":true,"xu-init":true,"xu-attrs":true,"xu-cdn":true,"xu-style":true,"xu-style-global":true,"xu-script":true,"xu-viewport":true,"xu-ui-plugin":true};const execution_plan=[];for(let index=0;index<(refresh_attributes||[]).length;index++){const attr=refresh_attributes[index];if(!attr||skip_attributes[attr]){continue}const attr_new=attr.split("xu-exp:")[1];const xu_func=attr_new||attr;const is_raw_value_attribute=!!raw_value_attributes[attr]||attr.substr(0,6)==="xu-on:";execution_plan.push({attr:attr,attr_new:attr_new,xu_func:xu_func,is_regular_attribute:!!(attr_new&&attr_new.substr(0,2)!=="xu"),requires_expression:!is_raw_value_attribute&&attr!=="xu-class"&&attr!=="xu-ui-plugin",regular_attr_name:attr_new?attr_new!=="viewBox"?attr_new.toLowerCase():attr_new:null})}xuData.refresh_execution_plan_cache[cache_key]=execution_plan;return execution_plan},get_expression_cache_key:function(options){const iterate_info=options.iterate_info;const iterate_key=iterate_info?[iterate_info.iterator_key??"",iterate_info.iterator_val??"",iterate_info._key??"",iterate_info._val??""].join("::"):"";return[options.expression_text,options.dsSessionP,options.recordid,iterate_key].join("||")},get_expression_result:async function(cache,options){const cache_key=fx.get_expression_cache_key(options);if(Object.prototype.hasOwnProperty.call(cache,cache_key)){return cache[cache_key]}const result=await func.expression.get(options.SESSION_ID,options.expression_text,options.dsSessionP,"UI Property EXP",options.recordid,null,null,null,null,null,options.iterate_info);cache[cache_key]=result;return result},update_datasource:async function(currentRecordId){if(queue_obj?.paramsP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[queue_obj.dsSession];_ds.currentRecordId=currentRecordId||queue_obj.paramsP.currentRecordId;var datasource_changes={[_ds.dsSession]:{[_ds.currentRecordId]:"set"}};await func.datasource.update(SESSION_ID,datasource_changes);if(queue_obj.paramsP.field_id){datasource_changes={[_ds.dsSession]:{[_ds.currentRecordId]:{[queue_obj.paramsP.field_id]:queue_obj.paramsP.field_value}}};await func.datasource.update(SESSION_ID,datasource_changes)}}if(!currentRecordId)return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)},execute_xu_render_attributes:async function(){const perf_end=func.runtime?.perf?.start?.(SESSION_ID,"execute_xu_render_attributes");const live_context=fx.get_live_element_context(queue_obj.paramsP?.elem_key,queue_obj.elementP||queue_obj.paramsP?.elem_val?.$elm,queue_obj.paramsP);const _data=live_context.data;try{if(_data?.xuData?.paramsP){const live_xu_data=_data.xuData;await func.runtime.render.execute_xu_function({SESSION_ID:SESSION_ID,is_skeleton:null,$root_container:live_xu_data.$root_container,nodeP:live_xu_data.node,$container:fx.get_element_by_ui_id(live_xu_data.parent_element_ui_id)||live_xu_data.$container,paramsP:live_xu_data.paramsP,parent_infoP:live_xu_data.iterate_info?{iterate_info:live_xu_data.iterate_info}:{},jobNoP:queue_obj.jobNoP,keyP:live_xu_data.key,parent_nodeP:live_xu_data.parent_node,xu_func:"xu-render",$elm:live_context.$elm,$live_elm:live_context.$elm,val:{key:"xu-render",value:queue_obj.paramsP.attr_value,fields_arr:queue_obj.paramsP.fields_arr,jobNoP:queue_obj.jobNoP},get_params_obj_new:func.runtime.program.get_params_obj})}return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)}finally{perf_end?.()}},execute_xu_all_attributes:async function(){const perf_end=func.runtime?.perf?.start?.(SESSION_ID,"execute_xu_all_attributes");const done=function(){return func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)};try{const live_context=fx.get_live_element_context(queue_obj.paramsP?.elem_key,queue_obj.elementP||queue_obj.paramsP?.elem_val?.$elm,queue_obj.paramsP);const $elm=live_context.$elm;const live_data=live_context.data;const elm_node=$elm?.[0];if(!$elm.length||!live_data?.xuData||!live_data?.xuAttributes){return done()}const live_xu_data=live_data.xuData;const live_xu_attributes=live_data.xuAttributes;const refresh_attributes=queue_obj.paramsP?.elem_val?.attributes||[];const execution_plan=fx.get_refresh_execution_plan(live_data,refresh_attributes);const expression_results_cache={};const live_parent_container=fx.get_element_by_ui_id(live_xu_data.parent_element_ui_id);const xu_execution_context={SESSION_ID:SESSION_ID,is_skeleton:null,$root_container:live_xu_data.$root_container,nodeP:live_xu_data.node,$container:live_parent_container?.length?live_parent_container:live_xu_data.$container,paramsP:live_xu_data.paramsP,parent_infoP:live_xu_data.iterate_info?{iterate_info:live_xu_data.iterate_info}:{},jobNoP:queue_obj.jobNoP,keyP:live_xu_data.key,parent_nodeP:live_xu_data.parent_node,$elm:$elm,$live_elm:$elm,get_params_obj_new:func.runtime.program.get_params_obj};const handler_bundle=func.runtime.render.build_xu_handlers(xu_execution_context,SESSION_OBJ[SESSION_ID].DS_GLB[live_xu_data.paramsP.dsSessionP]);for(let index=0;index<execution_plan.length;index++){const plan=execution_plan[index];const attr=plan.attr;const attr_value=live_xu_attributes[attr];if(typeof attr_value==="undefined"){continue}let result=attr_value;if(plan.requires_expression){const expression_result=await fx.get_expression_result(expression_results_cache,{SESSION_ID:queue_obj.paramsP.SESSION_ID,expression_text:attr_value,dsSessionP:live_xu_data.paramsP.dsSessionP,recordid:live_xu_data.recordid,iterate_info:live_xu_data.iterate_info});result=expression_result.result}if(plan.is_regular_attribute){if(plan.regular_attr_name==="class"){func.runtime.render.apply_expression_class($elm,result)}else{func.runtime.ui.set_attr($elm,plan.regular_attr_name,result)}}else{try{await func.runtime.render.execute_xu_function({...xu_execution_context,xu_func:plan.xu_func,val:{key:plan.xu_func,value:result},handler_bundle:handler_bundle})}catch(error){debugger}}}return done()}finally{perf_end?.()}},execute_xu_for:async function(){const perf_end=func.runtime?.perf?.start?.(SESSION_ID,"execute_xu_for");try{const live_context=fx.get_live_element_context(queue_obj.paramsP?.elem_key,queue_obj.elementP||queue_obj?.paramsP?.elem_val?.$elm,queue_obj.paramsP);var $elm=live_context.$elm;if(!$elm?.length){return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)}const existing_children_map=new Set;if(func.runtime?.ui?.get_refresh_indexed_elements_by_node_id){const indexed_children=func.runtime.ui.get_refresh_indexed_elements_by_node_id(SESSION_ID,queue_obj?.paramsP?.xu_for_item_id).toArray();for(let index=0;index<indexed_children.length;index++){if(indexed_children[index].parentElement===func.runtime.ui.get_first_node($elm)){existing_children_map.add(indexed_children[index])}}}const children=func.runtime.ui.get_children($elm);for(let index=0;index<children.length;index++){const child=children[index];const child_data=func.runtime.ui.get_data(child);if(child_data?.xuData?.nodeid===queue_obj?.paramsP?.xu_for_item_id){existing_children_map.add(child)}}if(existing_children_map.size){func.runtime.ui.remove(func.runtime.ui._wrap_matches(Array.from(existing_children_map)))}let _data=live_context.data||func.runtime.ui.get_data($elm);const node_to_render=fx.get_child_node_by_id(_data?.xuData,queue_obj?.paramsP?.xu_for_item_id);await func.runtime.render.render_ui_tree(queue_obj.paramsP.SESSION_ID,$elm,node_to_render,null,_data.xuData.paramsP,queue_obj.jobNoP,null,_data.xuData.key,null,_data.xuData.parent_node,null,_data.xuData.$root_container)}catch(error){}finally{perf_end?.()}return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)},render_viewport:async function(){const{nodeP,$div,parent_infoP,$root_container,jobNoP,is_skeleton,paramsP,$container}=queue_obj?.paramsP||{};const _div_node=func.runtime.ui.get_first_node($div);if(nodeP?.children?.length&&!_div_node?.children?.length){await fx.update_datasource(func.runtime.ui.get_data($div)?.xuData?.currentRecordId);func.runtime.ui.remove_class($div,"skeleton");for(let index=0;index<nodeP.children.length;index++){await func.runtime.render.render_ui_tree(SESSION_ID,$div,nodeP.children[index],parent_infoP,paramsP,jobNoP,is_skeleton,index,null,nodeP,null,$root_container)}_div_node.style.removeProperty("height");func.runtime.ui.get_data($div).xuData.viewport_height=_div_node?.offsetHeight||0;const parent_id=func.runtime.ui.get_attr(_div_node?.parentElement,"xu-ui-id");func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.viewport_height_set_ids_set.has(parent_id)){UI_WORKER_OBJ.viewport_height_set_ids_set.add(parent_id);UI_WORKER_OBJ.viewport_height_set_ids.push(parent_id);func.UI.worker.add_to_queue(SESSION_ID,"gui event","set_viewport_height",{$div:$div,height:func.runtime.ui.get_first_node($div)?.offsetHeight||0},null,null,paramsP.dsSessionP)}}return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)},set_viewport_height:async function(){const{$div,height}=queue_obj?.paramsP||{};const siblings=func.runtime.ui.get_first_node($div)?.parentElement?.children||[];for(let index=0;index<siblings.length;index++){const elm=siblings[index];if(!elm.style.height&&!elm.childElementCount){func.runtime.ui.set_style(elm,"height",`${height}px`)}}return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)},execute_xu_widget:async function(){try{const live_context=fx.get_live_element_context(queue_obj.paramsP?.elem_key,queue_obj.elementP||queue_obj?.paramsP?.elem_val?.$elm,queue_obj.paramsP);var $elm=live_context.$elm;if(!$elm?.length){return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)}const parent_id=func.runtime.ui.get_attr(func.runtime.ui.get_first_node($elm)?.parentElement,"xu-ui-id");let _data=live_context.data||func.runtime.ui.get_data($elm);func.runtime.ui.remove($elm);if(!_data?.xuData){return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)}const node_to_render=_data.xuData.node_org;await func.runtime.render.render_ui_tree(queue_obj.paramsP.SESSION_ID,fx.get_element_by_ui_id(parent_id),node_to_render,null,_data.xuData.paramsP,queue_obj.jobNoP,null,_data.xuData.key,null,_data.xuData.parent_node,null,_data.xuData.$root_container)}catch(error){}return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)}};try{return await fx[queue_obj.functionP]()}catch(error){console.error(error);const failed_job_index=func.UI.worker.find_job_index(SESSION_ID,queue_obj.job_num);if(failed_job_index!==null&&typeof failed_job_index!=="undefined"&&UI_WORKER_OBJ.jobs[failed_job_index]){await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)}return null}};func.UI.worker.find_job_index=function(SESSION_ID,jobNoP){var ret=null;if(!UI_WORKER_OBJ)return ret;func.UI.worker.ensure_runtime_indexes();if(Object.prototype.hasOwnProperty.call(UI_WORKER_OBJ.job_index_by_num,jobNoP)){const indexed_job=UI_WORKER_OBJ.job_index_by_num[jobNoP];if(UI_WORKER_OBJ.jobs[indexed_job]){return indexed_job}delete UI_WORKER_OBJ.job_index_by_num[jobNoP]}for(let key=0;key<UI_WORKER_OBJ.jobs.length;key++){const val=UI_WORKER_OBJ.jobs[key];if(val&&val.job_num==jobNoP){ret=key;UI_WORKER_OBJ.job_index_by_num[jobNoP]=ret;break}}return ret};func.UI.ds_garbage_collector=function(SESSION_ID=Object.keys(SESSION_OBJ)[0],re_check){let _session=SESSION_OBJ[SESSION_ID];const _data_system=_session?.DS_GLB?.[0]?.data_system;if(_data_system?.SYS_GLOBAL_BOL_AJAX_BUSY)return;if(!_data_system?.SYS_GLOBAL_BOL_IDLE)return;const ds_keys=Object.keys(_session.DS_GLB||{});let abort=false;for(let index=0;index<ds_keys.length;index++){const _ds=_session.DS_GLB[ds_keys[index]];if(_ds.stat==="busy"){abort=true;break}}if(abort){return}const ds_pending_to_delete=new Set;const active_ds_sessions=new Set;const runtime_elements=func.UI.worker.get_session_runtime_elements(SESSION_ID);for(let index=0;index<runtime_elements.length;index++){const val=runtime_elements[index];const dsSessionP=func.runtime.ui.get_data(val)?.xuData?.paramsP?.dsSessionP;if(typeof dsSessionP==="undefined"||dsSessionP===null)continue;active_ds_sessions.add(dsSessionP.toString())}for(let index=0;index<ds_keys.length;index++){const dsP=ds_keys[index];const _ds=_session.DS_GLB[dsP];if(!_ds.screen_params)continue;if(!active_ds_sessions.has(dsP.toString())){ds_pending_to_delete.add(dsP.toString())}}const sortedKeys=ds_keys.slice().sort((a,b)=>b.localeCompare(a));for(let index=0;index<sortedKeys.length;index++){const key=sortedKeys[index];const val=_session.DS_GLB[key];const parent_ds=typeof val.parentDataSourceNo!=="undefined"?val.parentDataSourceNo.toString():null;if(!ds_pending_to_delete.has(key)&&parent_ds&&ds_pending_to_delete.has(parent_ds)){ds_pending_to_delete.delete(parent_ds)}}for(const val of ds_pending_to_delete){func.datasource.del(SESSION_ID,val)}};func.UI.refs_garbage_collector=function(SESSION_ID=Object.keys(SESSION_OBJ)[0]){if(!xu_isEmpty(SCREEN_BLOCKER_OBJ)){return}let _session=SESSION_OBJ[SESSION_ID];const _data_system=_session?.DS_GLB?.[0]?.data_system;const refs_obj=_data_system?.SYS_GLOBAL_OBJ_REFS||{};const ref_keys=Object.keys(refs_obj);for(let ref_index=0;ref_index<ref_keys.length;ref_index++){const key=ref_keys[ref_index];const val=refs_obj[key];const $root=func.UI.worker.get_session_root(SESSION_ID);const _raw_el=func.runtime?.ui?.get_refresh_indexed_element_by_ui_id?func.runtime.ui.get_refresh_indexed_element_by_ui_id(SESSION_ID,val.xu_ui_id):null;const $element=_raw_el?func.runtime.ui._wrap_matches([_raw_el]):func.runtime?.ui?.find_refresh_elements_by_attr?func.runtime.ui.find_refresh_elements_by_attr($root,"xu-ui-id",val.xu_ui_id,true):func.runtime.ui.find_by_selector($root,`[xu-ui-id='${val.xu_ui_id}']`);const $panel_wrapper=func.runtime?.ui?.find_panel_wrapper_in_root?func.runtime.ui.find_panel_wrapper_in_root(SESSION_ID,val.xu_ui_id):func.runtime?.ui?.find_refresh_elements_by_attr?func.runtime.ui.find_refresh_elements_by_attr($root,"xu-panel-wrapper-id",val.xu_ui_id,true):func.runtime.ui.find_by_selector($root,`[xu-panel-wrapper-id='${val.xu_ui_id}']`);if(!$element?.length&&!$panel_wrapper?.length){delete _data_system.SYS_GLOBAL_OBJ_REFS[key]}}};func.UI.teleport_garbage_collector=function(SESSION_ID=Object.keys(SESSION_OBJ)[0]){if(!xu_isEmpty(SCREEN_BLOCKER_OBJ)){return}const $root=func.UI.worker.get_session_root(SESSION_ID);const teleport_elements=$root[0]?.querySelectorAll?.(`[xu-teleport-parent-id^='node-']`)||[];for(let index=0;index<teleport_elements.length;index++){const val=teleport_elements[index];const xu_teleport_parent_id=val.getAttribute("xu-teleport-parent-id");const _raw_parent=func.runtime?.ui?.get_refresh_indexed_element_by_ui_id?func.runtime.ui.get_refresh_indexed_element_by_ui_id(SESSION_ID,xu_teleport_parent_id):null;const $parent=_raw_parent?func.runtime.ui._wrap_matches([_raw_parent]):func.runtime?.ui?.find_refresh_elements_by_attr?func.runtime.ui.find_refresh_elements_by_attr($root,"xu-ui-id",xu_teleport_parent_id,true):func.runtime.ui.find_by_selector($root,`[xu-ui-id='${xu_teleport_parent_id}']`);if(!$parent?.length){func.runtime.ui.remove(val)}}};func.UI.utils.prog_ui_attribute_index_cache=func.UI.utils.prog_ui_attribute_index_cache||new WeakMap;func.UI.utils.get_prog_ui_attribute_index=function(progUi,prop,tag_name){if(!Array.isArray(progUi)||!prop){return{}}let prog_cache=func.UI.utils.prog_ui_attribute_index_cache.get(progUi);if(!prog_cache){prog_cache={};func.UI.utils.prog_ui_attribute_index_cache.set(progUi,prog_cache)}const cache_key=`${prop||""}::${tag_name||""}`;if(prog_cache[cache_key]){return prog_cache[cache_key]}const index={};const add_field=function(field_ref,item){if(!field_ref){return}if(!index[field_ref]){index[field_ref]=[]}index[field_ref].push(item)};const iterate_progUi=function(node){for(let item of node){if((!tag_name||item.tagName===tag_name)&&!xu_isEmpty(item.attributes)){const attribute_keys=Object.keys(item.attributes);for(let attr_index=0;attr_index<attribute_keys.length;attr_index++){const attr=attribute_keys[attr_index];const val=item.attributes[attr];if(attr!==`xu-exp:${prop}`&&attr!==prop){continue}const attr_str=typeof val==="string"?val:JSON.stringify(val);if(!attr_str){continue}for(const match of attr_str.matchAll(/@([A-Za-z0-9_$.-]+)/g)){add_field(match[1],item)}}}if(item.children){iterate_progUi(item.children)}}};iterate_progUi(progUi);prog_cache[cache_key]=index;return index};func.UI.find_field_in_progUi_attributes=function(progUi,field_id,prop,tag_name){if(prop){const index=func.UI.utils.get_prog_ui_attribute_index(progUi,prop,tag_name);return index[field_id]||[]}let elm_nodes=[];const iterate_progUi=function(node){for(let item of node){if(!tag_name||item.tagName===tag_name){if(tag_name){elm_nodes.push(item)}}if(item.children){iterate_progUi(item.children)}}};iterate_progUi(progUi);return elm_nodes};func.UI.update_xu_ref=function(SESSION_ID,dsSessionP,ref_field_id,$elm){let ret;const _session=SESSION_OBJ[SESSION_ID];let _ds_0=_session.DS_GLB[0];const _ds=func.utils.clean_returned_datasource(SESSION_ID,dsSessionP);let obj={ds:_ds,data:{},props:_ds.in_parameters||{}};try{const row_idx=func.common.find_ROWID_idx(_ds,_ds.currentRecordId);obj.data=_ds?.data_feed?.rows?.[row_idx]}catch(error){}let SYS_GLOBAL_OBJ_REFS=_ds_0.data_system["SYS_GLOBAL_OBJ_REFS"];if($elm){const elm_data=func.runtime.ui.get_data($elm);const attributes=elm_data?.xuData?.xuPanelProps||elm_data?.xuData?.debug_info?.attribute_stat||{};obj.attributes=attributes;obj.xu_ui_id=func.runtime.ui.get_attr($elm,"xu-ui-id")}if(!xu_isEqual(SYS_GLOBAL_OBJ_REFS?.[ref_field_id]||{},obj)){if(!SYS_GLOBAL_OBJ_REFS[ref_field_id]){SYS_GLOBAL_OBJ_REFS[ref_field_id]={}}function deepUpdateObject(a,b){for(let key in b){if(b.hasOwnProperty(key)){if(typeof b[key]==="object"&&b[key]!==null&&!Array.isArray(b[key])&&a[key]&&typeof a[key]==="object"){deepUpdateObject(a[key],b[key])}else{if(!xu_isEqual(a[key],b[key])){a[key]=b[key]}}}}return a}deepUpdateObject(SYS_GLOBAL_OBJ_REFS[ref_field_id],obj);ret=true}return ret};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.perf=func.runtime.perf||{};func.runtime.perf.global_stats=func.runtime.perf.global_stats||{sessions:{}};func.runtime.perf.get_host=function(){if(typeof window!=="undefined"){return window}if(typeof globalThis!=="undefined"){return globalThis}return{}};func.runtime.perf.sync_global_ref=function(){const host=func.runtime.perf.get_host();host.XUDA_RUNTIME_STATS=func.runtime.perf.global_stats;return host.XUDA_RUNTIME_STATS};func.runtime.perf.is_enabled=function(){const host=func.runtime.perf.get_host();const debug_mode=typeof glb!=="undefined"&&!!glb.DEBUG_MODE;return!!(debug_mode||host.XUDA_RUNTIME_STATS_ENABLED)};func.runtime.perf.now=function(){if(typeof performance!=="undefined"&&typeof performance.now==="function"){return performance.now()}return Date.now()};func.runtime.perf.ensure_session_stats=function(SESSION_ID){const global_stats=func.runtime.perf.global_stats;if(!global_stats.sessions[SESSION_ID]){global_stats.sessions[SESSION_ID]={created_at:Date.now(),counters:{},durations:{},maps:{}}}if(SESSION_OBJ?.[SESSION_ID]){SESSION_OBJ[SESSION_ID].runtime_stats=global_stats.sessions[SESSION_ID]}func.runtime.perf.sync_global_ref();return global_stats.sessions[SESSION_ID]};func.runtime.perf.reset_session=function(SESSION_ID){if(!SESSION_ID){return false}delete func.runtime.perf.global_stats.sessions[SESSION_ID];if(SESSION_OBJ?.[SESSION_ID]){delete SESSION_OBJ[SESSION_ID].runtime_stats}func.runtime.perf.sync_global_ref();return true};func.runtime.perf.reset=function(){func.runtime.perf.global_stats={sessions:{}};const session_ids=Object.keys(SESSION_OBJ||{});for(let index=0;index<session_ids.length;index++){delete SESSION_OBJ[session_ids[index]].runtime_stats}func.runtime.perf.sync_global_ref();return func.runtime.perf.global_stats};func.runtime.perf.get_session_stats=function(SESSION_ID){if(!SESSION_ID){return null}return func.runtime.perf.global_stats.sessions[SESSION_ID]||null};func.runtime.perf.increment=function(SESSION_ID,key,amount=1){if(!func.runtime.perf.is_enabled()){return 0}const stats=func.runtime.perf.ensure_session_stats(SESSION_ID);stats.counters[key]=(stats.counters[key]||0)+amount;return stats.counters[key]};func.runtime.perf.increment_map=function(SESSION_ID,bucket,key,amount=1){if(!func.runtime.perf.is_enabled()||typeof key==="undefined"||key===null){return 0}const stats=func.runtime.perf.ensure_session_stats(SESSION_ID);if(!stats.maps[bucket]){stats.maps[bucket]={}}const map_key=key.toString();stats.maps[bucket][map_key]=(stats.maps[bucket][map_key]||0)+amount;return stats.maps[bucket][map_key]};func.runtime.perf.record_duration=function(SESSION_ID,key,duration_ms){if(!func.runtime.perf.is_enabled()){return null}const stats=func.runtime.perf.ensure_session_stats(SESSION_ID);if(!stats.durations[key]){stats.durations[key]={count:0,total_ms:0,max_ms:0,last_ms:0,avg_ms:0}}const metric=stats.durations[key];metric.count++;metric.total_ms+=duration_ms;metric.last_ms=duration_ms;metric.max_ms=Math.max(metric.max_ms,duration_ms);metric.avg_ms=metric.total_ms/metric.count;return metric};func.runtime.perf.start=function(SESSION_ID,key){if(!func.runtime.perf.is_enabled()){return null}const started_at=func.runtime.perf.now();return function(){return func.runtime.perf.record_duration(SESSION_ID,key,func.runtime.perf.now()-started_at)}};func.runtime.ui.init_screen=async function(options){const{SESSION_ID,prog_id,sourceScreenP,callingDataSource_objP,$callingContainerP,triggerIdP,rowIdP,jobNoP,is_panelP,parameters_obj_inP,source_functionP,call_screen_propertiesP,refreshed_ds,parameters_raw_obj}=options;if(!prog_id)return console.error("program is empty");const screen_ret=await func.utils.get_screen_obj(SESSION_ID,prog_id);if(!screen_ret)return console.error("program is not a screen object");await func.UI.utils.init_ui_framework(SESSION_ID,prog_id);const _session=SESSION_OBJ[SESSION_ID];const screenInfo=structuredClone(screen_ret);const ssr_payload=func.runtime.render.should_use_ssr_payload(SESSION_ID,{prog_id:prog_id})?func.runtime.render.get_ssr_payload(_session):null;const screen_type=source_functionP?.split("_")?.[1];const screenId=ssr_payload?.screenId||(glb.screen_num++).toString();if(SCREEN_BLOCKER_OBJ[prog_id+(sourceScreenP?"_"+sourceScreenP:"")]){const wait_for_SCREEN_BLOCKER_release=function(){return new Promise(resolve=>{const interval=setInterval(function(){if(!SCREEN_BLOCKER_OBJ[prog_id+(sourceScreenP?"_"+sourceScreenP:"")]){clearInterval(interval);resolve()}},5)})};await wait_for_SCREEN_BLOCKER_release()}func.UI.utils.screen_blocker(true,prog_id+(sourceScreenP?"_"+sourceScreenP:""));if($callingContainerP&&!xu_isEmpty($callingContainerP)){const calling_data=func.runtime.ui.get_data($callingContainerP);if(calling_data?.xuData)calling_data.xuData.screenInfo=screenInfo}let $dialogDiv;let $rootFrame;const params={prog_id:prog_id,sourceScreenP:sourceScreenP,$callingContainerP:$callingContainerP,triggerIdP:triggerIdP,callingDataSource_objP:callingDataSource_objP,rowIdP:rowIdP,renderType:screenInfo.properties?.renderType,parameters_obj_inP:parameters_obj_inP,source_functionP:source_functionP,is_panelP:is_panelP,screen_type:screen_type,screenInfo:screenInfo,call_screen_propertiesP:call_screen_propertiesP,parentDataSourceNoP:_session.DS_GLB?.[callingDataSource_objP?.dsSession]?.dsSession||callingDataSource_objP?.parentDataSourceNo||0,parameters_raw_obj:parameters_raw_obj,containerIdP:ssr_payload?.containerId||null,ssr_payload:ssr_payload};const screen_host=func.runtime.ui.create_screen_host(SESSION_ID,screen_type,params,$callingContainerP,screenId);$dialogDiv=screen_host.$dialogDiv;$rootFrame=screen_host.$rootFrame;params.containerIdP=func.runtime.ui.get_attr($rootFrame,"id");params.$container=$rootFrame;const containerId="container_"+params.screenInfo.properties?.id+"_"+screenId;const data={note:" ROOT container",root:true,screenId:screenId,is_panelP:is_panelP,prog_id:prog_id,screen_type:screen_type,container:"#"+containerId};if(is_panelP){func.runtime.ui.get_data($rootFrame).xuData.rootFrame=data}else{const rf_data=func.runtime.ui.get_data($rootFrame);if(!rf_data?.xuData){func.runtime.ui.set_data($rootFrame,"xuData",{})}func.runtime.ui.set_attr($rootFrame,"id",containerId);func.runtime.ui.get_data($rootFrame).xuData.rootFrame=data;func.runtime.ui.set_style($rootFrame,"display","contents")}if(screen_host.reused_ssr_host&&func.runtime.render.is_takeover_mode(_session)){func.runtime.ui.empty($rootFrame)}if(!is_panelP)func.UI.utils.indicator.screen.busy();const ret=await func.datasource.create(SESSION_ID,prog_id,refreshed_ds,params.parentDataSourceNoP,func.runtime.ui.get_attr($rootFrame,"id"),rowIdP,jobNoP,null,parameters_raw_obj,null,null,null,null,is_panelP,parameters_obj_inP);const _ds=SESSION_OBJ[SESSION_ID].DS_GLB[ret.dsSessionP];_ds.screen_params=params;params.dsSessionP=ret.dsSessionP;func.runtime.ui.update_sys_obj_win_info(SESSION_ID,params.dsSessionP);if(ret.dsSessionP<0){return}let viewDoc;const view_ret=await func.utils.VIEWS_OBJ.get(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[ret.dsSessionP].prog_id);if(view_ret){viewDoc=view_ret}if(!viewDoc?.progUi){return func.utils.alerts.invoke(SESSION_ID,"system_msg","SYS_MSG_0780",params.renderType,ret.dsSessionP)}let node=structuredClone(viewDoc.progUi);if(!node.length)return console.warn("ui node empty");const root_tree=await func.runtime.render.build_tree({SESSION_ID:SESSION_ID,nodeP:node[0],paramsP:params});const ret_render_$container=await func.runtime.render.render_tree(root_tree,{SESSION_ID:SESSION_ID,$container:$rootFrame,parent_infoP:null,paramsP:params,jobNoP:jobNoP,is_skeleton:null,keyP:null,refreshed_ds:null,parent_nodeP:null,check_existP:null,$root_container:$rootFrame});if(!is_panelP)func.UI.utils.indicator.screen.normal();return await func.runtime.ui.screen_loading_done({SESSION_ID:SESSION_ID,paramsP:params,$div:ret_render_$container,jobNoP:jobNoP})};func.runtime.ui.update_sys_obj_win_info=function(SESSION_ID,dsNoP){const _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsNoP];if(!_ds)return;if(!_ds.data_system){_ds.data_system={}}_ds.data_system["SYS_STR_WIN_ID"]=_ds.tree_obj?.id;_ds.data_system["SYS_STR_WIN_NAME"]=_ds.tree_obj?.menuName;if(SESSION_OBJ[SESSION_ID].DS_GLB[dsNoP].mode){_ds.data_system["SYS_STR_WIN_MODE"]=SESSION_OBJ[SESSION_ID].DS_GLB[dsNoP].mode}};func.runtime.ui.validate_exit_events=async function(SESSION_ID,div_data_paramsP,forceP){return new Promise(async resolve=>{await func.events.validate(SESSION_ID,"on_exit",div_data_paramsP.dsSessionP,null,"screen");const interval=setInterval(function(){if(!SESSION_OBJ[SESSION_ID].WORKER_OBJ.jobs.length||forceP){clearInterval(interval);resolve()}},5)})};func.runtime.ui.call_embed=function(SESSION_ID,prog){const $embed=func.runtime.ui.get_embed_container(SESSION_ID);func.runtime.ui.empty($embed);const embed_data=func.runtime.ui.get_data($embed);if(embed_data?.xuData){embed_data.xuData.screenInfo=null}for(const[key,val]of Object.entries(SESSION_OBJ[SESSION_ID].DS_GLB)){if(key)func.datasource.del(SESSION_ID,key)}func.UI.main.embed_prog_execute(SESSION_ID,prog)};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.ui.ensure_modal_controller=function(SESSION_ID,modal_id){var modal_controller=document.querySelector("xu-modal-controller");if(!modal_controller){func.UI.component.create_app_modal_component(SESSION_ID,modal_id);modal_controller=document.querySelector("xu-modal-controller")}return modal_controller};func.runtime.ui.get_controller_params=function(controller_element){return func.runtime.ui.get_data(controller_element,"xuControllerParams")||{}};func.runtime.ui.set_controller_params=function(controller_element,params){func.runtime.ui.set_data(controller_element,"xuControllerParams",params);return params};func.runtime.ui.get_nav=function(SESSION_ID){return func.runtime.ui.find_in_root(SESSION_ID,"xu-nav")};func.runtime.ui.ensure_nav=function(SESSION_ID,$container){let nav=func.runtime.ui.get_nav(SESSION_ID);if(nav&&nav.length){return nav}var nav_el=document.createElement("xu-nav");func.runtime.ui.append($container,nav_el);var $nav=func.runtime.ui._wrap_matches([nav_el]);func.UI.component.init_xu_nav($container,$nav);return $nav};func.runtime.ui.get_page_component_name=function(dsSessionP){return"xu-page-component-"+dsSessionP};func.runtime.ui.resolve_screen_property=async function(SESSION_ID,paramsP,property){var property_value=paramsP?.screenInfo?.properties?.[property]||paramsP?.screenInfo?.properties?.frameworkProperties?.[property];if(paramsP?.call_screen_propertiesP){if(paramsP.call_screen_propertiesP?.[property]){property_value=paramsP.call_screen_propertiesP[property]}if(paramsP.call_screen_propertiesP[`xu-exp:${property}`]){property_value=(await func.expression.get(SESSION_ID,paramsP.call_screen_propertiesP[`xu-exp:${property}`],paramsP.dsSessionP,property)).result}}return property_value};func.runtime.ui.apply_framework_properties=async function(SESSION_ID,paramsP,ui_framework,params){params.properties={};params.properties["name"]=await func.runtime.ui.resolve_screen_property(SESSION_ID,paramsP,"menuTitle");const properties=await ui_framework?.properties?.();if(!properties){return params.properties}for await(const[key,val]of Object.entries(properties)){params.properties[key]=await func.runtime.ui.resolve_screen_property(SESSION_ID,paramsP,key)}return params.properties};func.runtime.ui.build_modal_params=function(paramsP,$div,$container,close_callback){return{screenId:paramsP.screenId,$dialogDiv:func.runtime.ui.get_children($div),$container:$container,dsSession:paramsP.dsSessionP,modal_id:"app_modal-"+paramsP.dsSessionP.toString(),screenInfo:paramsP.screenInfo,close_callback:close_callback,paramsP:paramsP}};func.runtime.ui.set_modal_params=function(SESSION_ID,modal_id,params){var xu_modal_controller=func.runtime.ui.ensure_modal_controller(SESSION_ID,modal_id);var controller_params=func.runtime.ui.get_controller_params(xu_modal_controller);controller_params[modal_id]=params;func.runtime.ui.set_controller_params(xu_modal_controller,controller_params);return xu_modal_controller};func.runtime.ui.get_modal_params=function(SESSION_ID,modal_id){const xu_modal_controller=func.runtime.ui.ensure_modal_controller(SESSION_ID,modal_id);return func.runtime.ui.get_controller_params(xu_modal_controller)[modal_id]};func.runtime.ui.set_modal_instance=function(modal_id,modal){APP_MODAL_OBJ[modal_id]=modal;return modal};func.runtime.ui.has_modal_instance=function(modal_id){return!!APP_MODAL_OBJ[modal_id]};func.runtime.ui.delete_modal_instance=function(modal_id){delete APP_MODAL_OBJ[modal_id];return true};func.runtime.ui.close_all_modals=function(){for(const[key,val]of Object.entries(APP_MODAL_OBJ)){if(val){UI_FRAMEWORK_PLUGIN.modal.close(key)}}return true};func.runtime.ui.build_popover_params=function(paramsP,$div,$container){return{menuTitle:paramsP.screenInfo.properties?.menuTitle,screenId:paramsP.screenId,$dialogDiv:func.runtime.ui.get_children($div),$container:$container}};func.runtime.ui.build_page_params=function(SESSION_ID,paramsP,$div_content,$container,nav){return{div:$div_content,name:paramsP.screenInfo.properties?.menuTitle,screenId:paramsP.screenId,$container:$container,dsSession:paramsP.dsSessionP,SESSION_ID:SESSION_ID,nav:nav,paramsP:paramsP}};func.runtime.ui.get_nav_data=function($nav){return func.runtime.ui.get_data($nav)?.xuData||null};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.ensure_nav_params_registry=function($nav){const nav_data=func.runtime.ui.get_nav_data($nav);if(!nav_data){return null}if(!nav_data.nav_params){nav_data.nav_params={}}return nav_data.nav_params};func.runtime.ui.restore_page_validate_state=function($nav,dsSessionP,$container){const nav_data=func.runtime.ui.get_nav_data($nav);const existing_params=nav_data?.params?.[dsSessionP];if(func.runtime.ui.get_data(existing_params?.$container)?.xuData?.validate_screen_ready){func.runtime.ui.get_data($container).xuData.validate_screen_ready=func.runtime.ui.get_data(existing_params.$container).xuData.validate_screen_ready;return true}return false};func.runtime.ui.register_page_params=function($nav,dsSessionP,params){const nav_params=func.runtime.ui.ensure_nav_params_registry($nav);if(!nav_params){return false}nav_params[dsSessionP]=params;return true};func.runtime.ui.get_root_component_name=function(SESSION_ID){return"xu-root-component-"+SESSION_ID};func.runtime.ui.attach_nav_root_div=function($nav,$div_content){const nav_data=func.runtime.ui.get_nav_data($nav);if(!nav_data){return false}nav_data.$div=$div_content;return true};func.runtime.ui.set_nav_root=async function($nav,SESSION_ID){const nav_element=func.runtime.ui.get_first_node($nav);if(!nav_element?.setRoot){return false}await nav_element.setRoot(func.runtime.ui.get_root_component_name(SESSION_ID));return true};func.runtime.ui.release_screen_blocker=function(paramsP){func.UI.utils.screen_blocker(false,paramsP.prog_id+"_"+paramsP.sourceScreenP);return true};func.runtime.ui.close_modal_session=async function(SESSION_ID,modal_id){func.runtime.ui.delete_modal_instance(modal_id);const params=func.runtime.ui.get_modal_params(SESSION_ID,modal_id);if(params&&params.$container){await func.runtime.ui.validate_exit_events(SESSION_ID,func.runtime.ui.get_data(params.$container)?.xuData?.paramsP,null);func.datasource.clean_all(SESSION_ID,params.dsSession)}return true};func.runtime.ui.render_screen_type=async function(options){const $div_content=func.runtime.ui.get_children(options.$div);func.runtime.ui.sync_child_parent_container(options.$div);const assert_framework_screen_supported=function(screen_type){if(!func.runtime.session.is_slim(options.SESSION_ID)){return}throw new Error('Slim mode does not support "'+screen_type+'" screens without a UI framework plugin')};let $ret=options.$div;let $nav=func.runtime.ui.get_nav(options.SESSION_ID);let params;switch(options.paramsP.screen_type){case"modal":{assert_framework_screen_supported("modal");params=func.runtime.ui.build_modal_params(options.paramsP,options.$div,options.$container,options.close_modal);const modal_id=params.modal_id;func.runtime.ui.set_modal_params(options.SESSION_ID,modal_id,params);const modalController=await new UI_FRAMEWORK_PLUGIN.modal;await func.runtime.ui.apply_framework_properties(options.SESSION_ID,options.paramsP,modalController,params);if(!func.runtime.ui.has_modal_instance(modal_id)){const modal=await modalController.create(params);func.runtime.ui.set_modal_instance(modal_id,modal)}else{func.runtime.ui.empty(document.querySelector(modal_id))}await modalController.init(params);break}case"popover":{assert_framework_screen_supported("popover");const xu_popover_controller=func.UI.component.create_app_popover_component(options.SESSION_ID);params=func.runtime.ui.build_popover_params(options.paramsP,options.$div,options.$container);func.runtime.ui.set_data(xu_popover_controller,"xuControllerParams",params);const popover=new UI_FRAMEWORK_PLUGIN.popover(options.SESSION_ID);await func.runtime.ui.apply_framework_properties(options.SESSION_ID,options.paramsP,popover,params);await popover.open(params);CURRENT_APP_POPOVER=popover;func.runtime.ui.release_screen_blocker(options.paramsP);break}case"page":{assert_framework_screen_supported("page");const nav=func.runtime.ui.get_first_node($nav);params=func.runtime.ui.build_page_params(options.SESSION_ID,options.paramsP,$div_content,options.$container,nav);const component_name=func.runtime.ui.get_page_component_name(options.paramsP.dsSessionP);func.runtime.ui.ensure_nav_params_registry($nav);func.runtime.ui.restore_page_validate_state($nav,options.paramsP.dsSessionP,params.$container);if(!func.runtime.ui.get_nav_data($nav))return;func.runtime.ui.register_page_params($nav,options.paramsP.dsSessionP,params);if(!document.querySelector(component_name)){await func.UI.component.create_app_page_component(options.SESSION_ID,options.paramsP.dsSessionP);const page=new UI_FRAMEWORK_PLUGIN.page;await func.runtime.ui.apply_framework_properties(options.SESSION_ID,options.paramsP,page,params);await page.create(params);await page.init(params);nav.push(component_name,{params:params})}else{debugger;func.runtime.ui.empty(component_name);await UI_FRAMEWORK_PLUGIN.page(options.SESSION_ID,options.paramsP.dsSessionP)}func.runtime.ui.get_data(options.$div).xuData.paramsP=func.runtime.ui.get_data(options.$container).xuData.paramsP;break}case"panel":func.runtime.ui.append(options.$container,$div_content);$ret=options.$container;break;default:$nav=func.runtime.ui.ensure_nav(options.SESSION_ID,options.$container);func.runtime.ui.attach_nav_root_div($nav,$div_content);await func.runtime.ui.set_nav_root($nav,options.SESSION_ID);$ret=options.$container;break}return $ret};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.ensure_container_attributes=async function(options){const container_data=func.runtime.ui.get_data(options.$container);if(!xu_isEmpty(container_data?.xuAttributes)){return options.$container}await func.runtime.render.set_attributes_new({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$elm:options.$container,is_init:true});return options.$container};func.runtime.ui.copy_runtime_state=function($source,$target){const source_data=func.runtime.ui.get_data($source);const target_data=func.runtime.ui.get_data($target);if(!source_data?.xuData||!target_data?.xuData||!source_data?.xuAttributes||!target_data?.xuAttributes){return $target}const xu_data_keys=Object.keys(source_data.xuData);for(let index=0;index<xu_data_keys.length;index++){const key=xu_data_keys[index];const val=source_data.xuData[key];try{target_data.xuData[key]=structuredClone(val)}catch(_){target_data.xuData[key]=val}}const xu_attribute_keys=Object.keys(source_data.xuAttributes);for(let index=0;index<xu_attribute_keys.length;index++){const key=xu_attribute_keys[index];const val=source_data.xuAttributes[key];try{target_data.xuAttributes[key]=structuredClone(val)}catch(_){target_data.xuAttributes[key]=val}}return $target};func.runtime.ui.ensure_multi_view_state=function($div,nodeP,$container){const div_data=func.runtime.ui.get_data($div);const container_data=func.runtime.ui.get_data($container);if(!div_data?.xuData?.node||!div_data.xuData.node.children){div_data.xuData.node=nodeP}if(!div_data?.xuData?.debug_info){div_data.xuData.debug_info={id:nodeP.id,parent_id:container_data?.xuData?.ui_id}}return $div};func.runtime.ui.should_close_mobile_overlays=function(paramsP){return!REFRESHER_IN_PROGRESS&&(paramsP.is_mobile_popover||paramsP.is_mobile_page)};func.runtime.ui.render_single_view_node=async function(options){const exist_elm_obj=func.runtime.render.find_existing_element({$container:options.$container,nodeP:options.nodeP,keyP:options.keyP,render_context:options.render_context});let $div=exist_elm_obj.div;if(!$div){const $wrapper=document.createElement("div");$div=await func.runtime.ui.create_container({SESSION_ID:options.SESSION_ID,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,treeP:options.treeP,parent_nodeP:options.parent_nodeP,prop:options.prop,div_typeP:"div",$appendToP:$wrapper,attr_str:""});if(!$div)return;if(func.runtime.ui.should_close_mobile_overlays(options.paramsP)){func.runtime.ui.close_all_modals()}const div_el=func.runtime.ui.get_first_node($div);if(div_el){div_el.addEventListener("mouseenter",function(e){options.hover_handlers.hover_in($div,e)});div_el.addEventListener("mouseleave",function(){options.hover_handlers.hover_out()})}}await options.iterate_child($div,options.nodeP,null,$div);await func.runtime.ui.ensure_container_attributes({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP});func.runtime.ui.copy_runtime_state($div,options.$container);return await func.runtime.ui.render_screen_type({SESSION_ID:options.SESSION_ID,$div:$div,$container:options.$container,paramsP:options.paramsP,close_modal:options.close_modal})};func.runtime.ui.render_multi_view_node=async function(options){const $div=options.$container;func.runtime.ui.ensure_multi_view_state($div,options.nodeP,options.$container);const done=async function(continuous_idx){await func.runtime.ui.ensure_container_attributes({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP});return await func.runtime.ui.render_screen_type({SESSION_ID:options.SESSION_ID,$div:$div,$container:options.$container,paramsP:options.paramsP,close_modal:options.close_modal})};if(func.runtime.ui.should_close_mobile_overlays(options.paramsP)){func.runtime.ui.close_all_modals()}const _ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[options.paramsP.dsSessionP];if(!_ds.data_feed||xu_isEmpty(_ds.data_feed.rows)){await func.events.validate(options.SESSION_ID,"record_not_found",options.paramsP.dsSessionP);return await done(null)}const rows=_ds.data_feed.rows||[];for(let row_index=0;row_index<rows.length;row_index++){const val=rows[row_index];const node=JSON.parse(JSON.stringify(options.nodeP));_ds.currentRecordId=val._ROWID;await options.iterate_child($div,node,{continuous_idx:null},options.$root_container);await func.runtime.ui.ensure_container_attributes({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP})}return await done(null)};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.render_panel_node=async function(options){const $wrapper=document.createElement("div");const $div=await func.runtime.ui.create_container({SESSION_ID:options.SESSION_ID,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,treeP:options.treeP,parent_nodeP:options.parent_nodeP,prop:options.prop,$appendToP:$wrapper,attr_str:""});let ret=await func.runtime.render.set_attributes_new({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$elm:$div.cloneNode(true),is_init:true,refreshed_ds:options.refreshed_ds});if(ret.abort){const _tpl=document.createElement("template");_tpl.appendChild($div);return ret.$new_div=_tpl}let $ret_panel_div=ret.$new_div;if(!func.runtime.ui.get_first_node($ret_panel_div)?.childElementCount&&options.nodeP.children.length){$ret_panel_div=await func.runtime.render.render_ui_tree(options.SESSION_ID,options.$container,options.nodeP.children[0],options.parent_infoP,options.paramsP,options.jobNoP,null,0,null,options.nodeP,null,options.$root_container)}const container_data=func.runtime.ui.get_data(options.$container);if(!container_data?.xuData?.paramsP){return options.$container}const $div_items=func.runtime.ui.get_data($div)?.xuData?.node?.children;await func.runtime.ui.panel_post_render_handler({SESSION_ID:options.SESSION_ID,$container:options.$container,$wrapper:$ret_panel_div,nodeP:options.nodeP,$panel_div:$div,jobNoP:options.jobNoP});if(container_data?.xuData?.node){container_data.xuData.node.children=$div_items}return options.$container};func.runtime.ui.panel_post_render_handler=async function(options){try{const container_data=func.runtime.ui.get_data(options.$container);const wrapper_data=func.runtime.ui.get_data(options.$wrapper);const parent_container_data=func.runtime.ui.get_data(func.runtime.ui.get_parent(options.$container));const _container_ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[container_data?.xuData?.paramsP?.dsSessionP];const _ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[wrapper_data?.xuData?.paramsP?.dsSessionP];const panel_wrapper_id=container_data?.xuPanelData?.xu_panel_xu_ui_id;const find_old_panels_elements=function(){if(!panel_wrapper_id){return func.runtime.ui._wrap_matches([])}return func.runtime.ui.find_panel_wrapper_in_root(options.SESSION_ID,panel_wrapper_id)};const $old_panel_div=find_old_panels_elements();const wrapper_children=func.runtime.ui.get_children(options.$wrapper);const set_xuPanelData_to_the_new_rendered_items=function(){container_data.xuPanelWrapper={isWrapper:true,panelXuAttributes:{...wrapper_data?.xuAttributes},panelDivData:{...wrapper_data}};func.runtime.ui.set_attr(options.$container,"xu-panel-wrapper-id",func.runtime.ui.get_attr(options.$wrapper,"xu-ui-id"));for(let child_index=0;child_index<wrapper_children.length;child_index++){const val=wrapper_children[child_index];const val_data=func.runtime.ui.get_data(val);if(!val_data.xuPanelData){val_data.xuPanelData={}}val_data.xuPanelData.parent_element_ui_id=$old_panel_div?.length?parent_container_data?.xuData?.ui_id:container_data?.xuData?.ui_id;val_data.xuPanelData.xu_panel_xu_ui_id=(options.nodeP.xu_tree_id||options.nodeP.id)+"-"+_container_ds?.currentRecordId;val_data.xuPanelData.node=options.nodeP;val_data.xuPanelData.$panel_div=options.$panel_div.cloneNode(true)}};set_xuPanelData_to_the_new_rendered_items();if($old_panel_div?.length){func.runtime.ui.get_first_node($old_panel_div).after(...wrapper_children)}else{const existing_children=func.runtime.ui.get_children(options.$container);const existing_children_by_elem_key={};for(let existing_index=0;existing_index<existing_children.length;existing_index++){const elm=existing_children[existing_index];const elem_key=func.runtime.ui.get_data(elm)?.xuData?.elem_key;if(elem_key){existing_children_by_elem_key[elem_key]=elm}}for(let child_index=0;child_index<wrapper_children.length;child_index++){const child=wrapper_children[child_index];const elem_key=func.runtime.ui.get_data(child)?.xuData?.elem_key;if(elem_key&&existing_children_by_elem_key[elem_key]){func.runtime.ui.remove(existing_children_by_elem_key[elem_key])}func.runtime.ui.append(options.$container,child)}}if(!wrapper_data?.xuData?.dsSession){return options.jobNoP}if($old_panel_div?.length){if(parent_container_data?.xuData?.paramsP){parent_container_data.xuData.paramsP.dsSessionP=_ds.parentDataSourceNo}}else{if(container_data?.xuData?.paramsP){container_data.xuData.paramsP.dsSessionP=_ds.parentDataSourceNo}}if($old_panel_div?.length){func.runtime.ui.remove($old_panel_div)}return options.jobNoP}catch(error){return options.jobNoP}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.refresh_screen_ready_fields=async function(options){const current_record_id=options._ds?.currentRecordId;const changed_fields=options._ds?.data_feed?.form_fields_changed?.[current_record_id];if(!changed_fields){return false}const fields_to_refresh=Object.keys(changed_fields);const containerId=options._ds.containerId;const container=func.runtime.ui.find_element_by_id(containerId);if(container){container.dispatchEvent(new CustomEvent(containerId+".refresh",{detail:["init",fields_to_refresh]}))}if(options.$div_objP){await func.runtime.ui.refresh_xu_attributes({SESSION_ID:options.SESSION_ID,fields_arr:fields_to_refresh,$elm_to_search:options.$div_objP,dsSession_changed:options.paramsP.dsSessionP})}return true};func.runtime.ui.collect_screen_ready_events=async function(options){const _prog=await func.utils.VIEWS_OBJ.get(options.SESSION_ID,options._ds.prog_id);const viewEventExec_arr=[];if(!_prog?.progEvents||xu_isEmpty(_prog.progEvents)){return viewEventExec_arr}for await(const event_obj of _prog.progEvents){if(event_obj.data.type!=="screen_ready"||xu_isEmpty(event_obj.workflow)){continue}if(event_obj.data.condition){const res=await func.expression.get(options.SESSION_ID,event_obj.data.condition,options.paramsP.dsSessionP,"condition",options.paramsP.rowIdP,null,null,null,null,event_obj);if(!res.result){continue}}for await(const trigger_obj of event_obj.workflow){if(!trigger_obj.data.enabled){continue}const expression=trigger_obj.props.condition||undefined;if(expression){const expCond=await func.expression.get(options.SESSION_ID,expression,options.paramsP.dsSessionP,"condition",options.paramsP.rowIdP,trigger_obj.data.type);if(!expCond.result){continue}}if(!trigger_obj.data.action){func.utils.debug_report(options.SESSION_ID,"collect_screen_ready_events",`Error initiating screen_ready prog: ${options._ds.viewSourceDesc} reason: missing action`,"E");break}if(!glb.REFERENCE_LESS_FUNCTIONS.includes(trigger_obj.data.action)&&!trigger_obj.data.name?.prog){func.utils.debug_report(options.SESSION_ID,"collect_screen_ready_events",`Error initiating screen_ready prog: ${options._ds.viewSourceDesc} reason: missing reference`,"E");break}viewEventExec_arr.push({eventInfo:trigger_obj,eventId:event_obj.id,triggerId:trigger_obj.id,expression:expression})}}return viewEventExec_arr};func.runtime.ui.execute_screen_ready_events=async function(options){const _ds=SESSION_OBJ[options.SESSION_ID]?.DS_GLB?.[options.paramsP.dsSessionP];if(!_ds){return}try{const viewEventExec_arr=await func.runtime.ui.collect_screen_ready_events({SESSION_ID:options.SESSION_ID,paramsP:options.paramsP,_ds:_ds});if(!viewEventExec_arr.length){return}for await(const val of viewEventExec_arr){let cond=val.eventInfo.data.enabled;if(val.expression){const expCond=await func.expression.get(options.SESSION_ID,val.expression,options.paramsP.dsSessionP,"condition",options.paramsP.rowIdP);cond=expCond.result}if(!cond){continue}await func.events.execute(options.SESSION_ID,null,val.eventId,val.triggerId,val.eventInfo.data.action,val.eventInfo.data.name,null,null,null,null,val.eventInfo.data.action,null,options.paramsP.dsSessionP,val.eventId,options.sourceP+" event",true,null,null,options.paramsP.dsSessionP,null,null,val.eventInfo,null,null,_ds.prog_id,_ds.nodeId,_ds.parentDataSourceNo,options.$div);await func.runtime.ui.refresh_screen_ready_fields({SESSION_ID:options.SESSION_ID,paramsP:options.paramsP,_ds:_ds,$div_objP:options.$div_objP})}}catch(error){debugger}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.screen_loading_done=async function(options){let retries=0;const interval=setInterval(()=>{const xu_ui_id=func.runtime.ui.get_attr(options.$div,"xu-ui-id");if(!func.runtime.ui.find_xu_ui_in_root(options.SESSION_ID,xu_ui_id).length&&!func.runtime.ui.find_panel_wrapper_in_root(options.SESSION_ID,xu_ui_id).length&&!xu_ui_id&&xu_ui_id){retries++;if(retries>100){console.warn("deadlock detected for screen ready")}else{return options.$div}}clearInterval(interval);func.runtime.ui.execute_screen_ready_events({SESSION_ID:options.SESSION_ID,paramsP:options.paramsP,sourceP:options.paramsP.screenInfo.properties?.renderType,$div:options.$div,jobNoP:options.jobNoP});const _session=SESSION_OBJ[options.SESSION_ID];if(func.runtime.render.should_use_ssr_payload(options.SESSION_ID,options.paramsP)){const root_node=func.runtime.ui.get_root_node(options.SESSION_ID);if(root_node){func.runtime.ui.set_attr(root_node,"data-xuda-client-activation",_session.opt.app_client_activation||"none");func.runtime.ui.set_attr(root_node,"data-xuda-ssr-status",_session.opt.app_client_activation==="hydrate"?"hydrated":"taken-over")}func.runtime.render.mark_ssr_payload_consumed(options.SESSION_ID)}func.events.delete_job(options.SESSION_ID,options.jobNoP);func.UI.utils.screen_blocker(false,options.paramsP.prog_id+(options.paramsP.sourceScreenP?"_"+options.paramsP.sourceScreenP:""));if(_session.prog_id===options.paramsP.prog_id){_session.system_ready=true;if(_session.engine_mode==="live_preview"&&STUDIO_PEER_CONN_SEND_METHOD){STUDIO_PEER_CONN_SEND_METHOD({service:"system_ready",data:{},id:STUDIO_PEER.id,source:"runtime",session_id:options.SESSION_ID,app_id:_session.app_id,gtp_token:_session.gtp_token,app_token:_session.app_token})}}},100);return options.$div};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui._to_node_array=func.runtime.ui._to_node_array||function(input){if(!input){return[]}if(typeof input?.toArray==="function"&&typeof input?.length==="number"&&!input?.nodeType){return input.toArray()}if(Array.isArray(input)){return input}if(input.nodeType){return[input]}if(typeof input.length==="number"){const arr=[];for(let i=0;i<input.length;i++){if(input[i]){arr.push(input[i])}}return arr}return[]};func.runtime.ui.ensure_refresh_dependency_state=function(SESSION_ID){const _session=SESSION_OBJ?.[SESSION_ID];if(!_session){return null}if(!_session.refresh_dependency_state){_session.refresh_dependency_state={dirty:true,index:{},elements_by_ui_id:{},elements_by_nodeid:{},panel_wrappers_by_id:{},xu_for_dirty:true,xu_for_index:{},panel_wrappers_dirty:true,panel_wrappers_cache:{},panel_wrappers_active_cache:{},runtime_elements_cache:null,panel_wrapper_elements_cache:null}}if(typeof _session.refresh_dependency_state.dirty!=="boolean"){_session.refresh_dependency_state.dirty=true}if(!_session.refresh_dependency_state.index){_session.refresh_dependency_state.index={}}if(!_session.refresh_dependency_state.elements_by_ui_id){_session.refresh_dependency_state.elements_by_ui_id={}}if(!_session.refresh_dependency_state.elements_by_nodeid){_session.refresh_dependency_state.elements_by_nodeid={}}if(!_session.refresh_dependency_state.panel_wrappers_by_id){_session.refresh_dependency_state.panel_wrappers_by_id={}}if(typeof _session.refresh_dependency_state.xu_for_dirty!=="boolean"){_session.refresh_dependency_state.xu_for_dirty=true}if(!_session.refresh_dependency_state.xu_for_index){_session.refresh_dependency_state.xu_for_index={}}if(typeof _session.refresh_dependency_state.panel_wrappers_dirty!=="boolean"){_session.refresh_dependency_state.panel_wrappers_dirty=true}if(!_session.refresh_dependency_state.panel_wrappers_cache){_session.refresh_dependency_state.panel_wrappers_cache={}}if(!_session.refresh_dependency_state.panel_wrappers_active_cache){_session.refresh_dependency_state.panel_wrappers_active_cache={}}if(typeof _session.refresh_dependency_state.runtime_elements_cache==="undefined"){_session.refresh_dependency_state.runtime_elements_cache=null}if(typeof _session.refresh_dependency_state.panel_wrapper_elements_cache==="undefined"){_session.refresh_dependency_state.panel_wrapper_elements_cache=null}return _session.refresh_dependency_state};func.runtime.ui.resolve_refresh_index_session_id=function(target,explicit_session_id){if(explicit_session_id&&SESSION_OBJ?.[explicit_session_id]){return explicit_session_id}const target_node=func.runtime.ui.get_first_node(target);const session_from_data=func.runtime.ui.get_data(target_node)?.xuData?.SESSION_ID;if(session_from_data){return session_from_data}const session_ids=Object.keys(SESSION_OBJ||{});if(session_ids.length===1){return session_ids[0]}return null};func.runtime.ui.mark_refresh_index_dirty=function(SESSION_ID){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return false}state.dirty=true;state.xu_for_dirty=true;state.panel_wrappers_dirty=true;state.runtime_elements_cache=null;state.panel_wrapper_elements_cache=null;return true};func.runtime.ui.mark_refresh_index_dirty_from_target=function(target,explicit_session_id){const session_id=func.runtime.ui.resolve_refresh_index_session_id(target,explicit_session_id);if(!session_id){return false}return func.runtime.ui.mark_refresh_index_dirty(session_id)};func.runtime.ui.remove_refresh_dependency_entry=function($elm,attr_key){const session_id=func.runtime.ui.resolve_refresh_index_session_id($elm);const selector_id=func.runtime.ui.get_attr($elm,"xu-ui-id");const elm_data=func.runtime.ui.get_data($elm);const dependency_store=elm_data?.xuData?.refresh_dependency_by_attr;if(!session_id||!selector_id||!dependency_store?.[attr_key]){return false}const state=func.runtime.ui.ensure_refresh_dependency_state(session_id);const old_fields=dependency_store[attr_key]||[];if(!state||state.dirty){delete dependency_store[attr_key];return true}for(const field_id of old_fields){const field_index=state.index?.[field_id];const selector_entry=field_index?.[selector_id];if(!selector_entry){continue}selector_entry.attributes.delete(attr_key);if(!selector_entry.attributes.size){delete field_index[selector_id]}if(xu_isEmpty(field_index)){delete state.index[field_id]}}delete dependency_store[attr_key];return true};func.runtime.ui.update_refresh_dependency_entry=function($elm,attr_key,attr_val){const session_id=func.runtime.ui.resolve_refresh_index_session_id($elm);const selector_id=func.runtime.ui.get_attr($elm,"xu-ui-id");const elm_data=func.runtime.ui.get_data($elm);if(!session_id||!selector_id||!elm_data?.xuData){return false}if(!elm_data.xuData.refresh_dependency_by_attr){elm_data.xuData.refresh_dependency_by_attr={}}func.runtime.ui.remove_refresh_dependency_entry($elm,attr_key);const state=func.runtime.ui.ensure_refresh_dependency_state(session_id);const fields=[...func.runtime.ui.collect_refresh_attribute_fields(elm_data,attr_key,attr_val)];elm_data.xuData.refresh_dependency_by_attr[attr_key]=fields;if(!state||state.dirty||!fields.length){return!!fields.length}for(const field_id of fields){if(!state.index[field_id]){state.index[field_id]={}}if(!state.index[field_id][selector_id]){state.index[field_id][selector_id]={attributes:new Set,$elm:$elm}}state.index[field_id][selector_id].attributes.add(attr_key);state.index[field_id][selector_id].$elm=$elm}return true};func.runtime.ui.prune_stale_refresh_dependencies=function($elm,node_attributes){const elm_data=func.runtime.ui.get_data($elm);const stored_attributes=elm_data?.xuAttributes;if(!stored_attributes){return false}let changed=false;for(const key of Object.keys(stored_attributes)){if(key.substr(0,3)!=="xu-"){continue}if(Object.prototype.hasOwnProperty.call(node_attributes||{},key)){continue}func.runtime.ui.remove_refresh_dependency_entry($elm,key);delete stored_attributes[key];changed=true}return changed};func.runtime.ui.normalize_refresh_field_reference=function(field_ref){if(!field_ref){return[]}const normalized=new Set;normalized.add(field_ref);const base_field=field_ref.split(/[.[(]/)[0];if(base_field){normalized.add(base_field)}return[...normalized].filter(Boolean)};func.runtime.ui.extract_expression_refresh_fields=function(elm_data,expression_text,without_var,_visited){const fields=new Set;if(!expression_text){return fields}const add_field=function(field_ref){for(const normalized of func.runtime.ui.normalize_refresh_field_reference(field_ref)){fields.add(normalized)}};const text=typeof expression_text==="string"?expression_text:JSON.stringify(expression_text);if(!text){return fields}if(without_var){const trimmed=text.trim();const root_match=trimmed.match(/^([A-Za-z0-9_$.-]+)/);if(root_match?.[1]){add_field(root_match[1])}}for(const match of text.matchAll(/@([A-Za-z0-9_$.-]+)/g)){add_field(match[1])}const parameters_raw_obj=elm_data?.xuData?.paramsP?.parameters_raw_obj||{};const parameter_keys=Object.keys(parameters_raw_obj);const visited=_visited||new Set;for(let index=0;index<parameter_keys.length;index++){const param_key=parameter_keys[index];if(visited.has(param_key)){continue}const param_val=parameters_raw_obj[param_key];if(!param_val?.includes?.("@")){continue}const param_token=`${without_var?"":"@"}${param_key}`;if(!text.includes(param_token)){continue}visited.add(param_key);const nested_fields=func.runtime.ui.extract_expression_refresh_fields(elm_data,param_val,false,visited);nested_fields.forEach(function(field_id){add_field(field_id)})}return fields};func.runtime.ui.validate_refresh_parameter_reference=function(elm_data,exp,field_id,without_var){let expression_text;if(typeof exp==="string"){expression_text=exp}else if(typeof exp==="object"){expression_text=JSON.stringify(exp)}if(!expression_text||!expression_text.includes("@")){return false}if(xu_isEmpty(elm_data?.xuData?.paramsP?.parameters_raw_obj)){return false}const parameters_raw_obj=elm_data.xuData.paramsP.parameters_raw_obj;const parameter_keys=Object.keys(parameters_raw_obj);for(let index=0;index<parameter_keys.length;index++){const param_key=parameter_keys[index];const param_val=parameters_raw_obj[param_key];if(!param_val?.includes?.("@")){continue}expression_text=expression_text.replaceAll((without_var?"":"@")+param_key,param_val)}return expression_text.includes((without_var?"":"@")+field_id)};func.runtime.ui.collect_refresh_attribute_fields=function(elm_data,key,val){const fields=new Set;const add_fields=function(values){values?.forEach?.(function(field_id){fields.add(field_id)})};if(typeof val!=="string"&&typeof val!=="object"){return fields}if(key==="xu-bind"||key==="xu-for"){add_fields(func.runtime.ui.extract_expression_refresh_fields(elm_data,val,true));add_fields(func.runtime.ui.extract_expression_refresh_fields(elm_data,val,false));return fields}if(key.substr(0,6)==="xu-exp"&&key.substr(6,1)===":"){add_fields(func.runtime.ui.extract_expression_refresh_fields(elm_data,val,false));return fields}if(key.substr(0,8)==="xu-class"){try{const classes_obj=typeof val==="string"?JSON.parse(val):val||{};const class_keys=Object.keys(classes_obj||{});for(let index=0;index<class_keys.length;index++){add_fields(func.runtime.ui.extract_expression_refresh_fields(elm_data,classes_obj[class_keys[index]],false))}}catch(error){console.warn("parse error:"+val)}return fields}if(key==="xu-ui-plugin"){add_fields(func.runtime.ui.extract_expression_refresh_fields(elm_data,JSON.stringify(val),false))}return fields};func.runtime.ui.collect_element_refresh_dependencies=function(elm_data){const dependency_store=elm_data?.xuData?.refresh_dependency_by_attr;if(!xu_isEmpty(dependency_store)){const stored_dependencies={};const attr_keys=Object.keys(dependency_store||{});for(let attr_index=0;attr_index<attr_keys.length;attr_index++){const attr_key=attr_keys[attr_index];const fields_arr=dependency_store[attr_key]||[];for(let field_index=0;field_index<fields_arr.length;field_index++){const field_id=fields_arr[field_index];if(!stored_dependencies[field_id]){stored_dependencies[field_id]=new Set}stored_dependencies[field_id].add(attr_key)}}return stored_dependencies}const dependencies={};const xu_attributes=elm_data?.xuAttributes||{};const attr_keys=Object.keys(xu_attributes);for(let attr_index=0;attr_index<attr_keys.length;attr_index++){const key=attr_keys[attr_index];const val=xu_attributes[key];if(key.substr(0,3)!=="xu-"){continue}const fields=func.runtime.ui.collect_refresh_attribute_fields(elm_data,key,val);fields.forEach(function(field_id){if(!dependencies[field_id]){dependencies[field_id]=new Set}dependencies[field_id].add(key)})}return dependencies};func.runtime.ui.matches_refresh_search_root=function(elm,search_roots){if(!search_roots?.length){return true}const elm_node=func.runtime.ui.get_first_node(elm);if(!elm_node){return false}for(let index=0;index<search_roots.length;index++){const root_node=func.runtime.ui.get_first_node(search_roots[index]);if(elm_node===root_node||root_node&&root_node.contains(elm_node)){return true}}return false};func.runtime.ui.collect_refresh_attributes=function(elm_data,field_id){const attributes=[];const xu_attributes=elm_data?.xuAttributes||{};const attr_keys=Object.keys(xu_attributes);for(let attr_index=0;attr_index<attr_keys.length;attr_index++){const key=attr_keys[attr_index];const val=xu_attributes[key];if(typeof val!=="string"&&typeof val!=="object"){continue}if(typeof val==="string"&&!val?.includes("@")&&key!=="xu-bind"&&key!=="xu-for"){continue}if(key.substr(0,3)!=="xu-"){continue}if(key==="xu-bind"||key==="xu-for"){if(val?.includes?.(field_id)||func.runtime.ui.validate_refresh_parameter_reference(elm_data,val,field_id,true)){attributes.push(key)}continue}if(key.substr(0,6)==="xu-exp"&&key.substr(6,1)===":"){if(val?.includes?.("@"+field_id)||func.runtime.ui.validate_refresh_parameter_reference(elm_data,val,field_id)){attributes.push(key)}continue}if(key.substr(0,8)==="xu-class"){try{const classes_obj=typeof val==="string"?JSON.parse(val):val||{};const class_keys=Object.keys(classes_obj||{});for(let class_index=0;class_index<class_keys.length;class_index++){const cond=classes_obj[class_keys[class_index]];if(cond?.includes?.("@"+field_id)||func.runtime.ui.validate_refresh_parameter_reference(elm_data,cond,field_id)){attributes.push("xu-class");break}}if(attributes.length){break}}catch(error){console.warn("parse error:"+val)}continue}if(key==="xu-ui-plugin"){const plugin_str=JSON.stringify(val);if(plugin_str.includes("@"+field_id)||func.runtime.ui.validate_refresh_parameter_reference(elm_data,plugin_str,field_id)){attributes.push(key);break}}}return attributes};func.runtime.ui.normalize_refresh_fields=function(fields_arr){return new Set((fields_arr||[]).map(function(field_id){return field_id?.toString?.()||field_id}))};func.runtime.ui.collect_refresh_attributes_for_fields=function(elm_data,fields_arr,requested_fields){const attributes=new Set;requested_fields=requested_fields||func.runtime.ui.normalize_refresh_fields(fields_arr);if(!requested_fields.size){return[]}let dependencies={};const dependency_store=elm_data?.xuData?.refresh_dependency_by_attr||{};const dependency_attr_keys=Object.keys(dependency_store);for(let attr_index=0;attr_index<dependency_attr_keys.length;attr_index++){const attr_key=dependency_attr_keys[attr_index];const attr_fields=dependency_store[attr_key]||[];for(let field_index=0;field_index<attr_fields.length;field_index++){const field_id=attr_fields[field_index];const normalized_field_id=field_id?.toString?.()||field_id;if(!requested_fields.has(normalized_field_id)){continue}if(!dependencies[normalized_field_id]){dependencies[normalized_field_id]=new Set}dependencies[normalized_field_id].add(attr_key)}}if(xu_isEmpty(dependencies)){dependencies=func.runtime.ui.collect_element_refresh_dependencies(elm_data)}requested_fields.forEach(function(field_id){const attr_set=dependencies[field_id];attr_set?.forEach?.(function(attr_key){attributes.add(attr_key)})});return[...attributes]};func.runtime.ui.register_refresh_index_element=function(elements_by_ui_id,elements_by_nodeid,panel_wrappers_by_id,selector_id,elm_data,$elm){if(!selector_id||!elm_data?.xuData){return false}elements_by_ui_id[selector_id]=$elm;const panel_wrapper_id=func.runtime.ui.get_attr($elm,"xu-panel-wrapper-id");if(panel_wrapper_id){panel_wrappers_by_id[panel_wrapper_id]=$elm}const node_id=elm_data.xuData.nodeid;if(!node_id){return true}if(!elements_by_nodeid[node_id]){elements_by_nodeid[node_id]={}}elements_by_nodeid[node_id][selector_id]=$elm;return true};func.runtime.ui.find_refresh_elements_by_attr=function(root_nodes_input,attr_name,attr_value,first_only=false){const root_nodes=func.runtime.ui._to_node_array(root_nodes_input);if(!root_nodes.length||!attr_name){return func.runtime.ui._wrap_matches([])}const selector=typeof attr_value==="undefined"?`[${attr_name}]`:`[${attr_name}="${attr_value}"]`;const elements=[];for(let root_index=0;root_index<root_nodes.length;root_index++){const root_node=root_nodes[root_index];if(root_node?.matches?.(selector)){elements.push(root_node);if(first_only){break}}if(first_only&&elements.length){break}if(first_only){const first_match=root_node?.querySelector?.(selector);if(first_match){elements.push(first_match);break}continue}const descendants=root_node?.querySelectorAll?.(selector)||[];for(let index=0;index<descendants.length;index++){elements.push(descendants[index])}}return func.runtime.ui._wrap_matches(elements)};func.runtime.ui.get_preferred_live_element=function(target){const elements=func.runtime.ui._to_node_array(target);if(!elements.length){return null}let best_node=null;let best_score=-Infinity;for(let index=0;index<elements.length;index++){const node=elements[index];if(!node){continue}const node_data=func.runtime.ui.get_data(node);let score=0;if(node.isConnected){score+=100}if(!node_data?.xuData?.pending_to_delete){score+=50}if(node.getClientRects?.().length){score+=25}if(!node.hidden){score+=10}if(score>=best_score){best_score=score;best_node=node}}return best_node||elements[elements.length-1]||null};func.runtime.ui.get_refresh_indexed_element_by_ui_id=function(SESSION_ID,selector_id){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return null}if(state.dirty){func.runtime.ui.rebuild_refresh_dependency_index(SESSION_ID)}let elm=state.elements_by_ui_id?.[selector_id];elm=func.runtime.ui.get_preferred_live_element(elm);if(elm?.isConnected){state.elements_by_ui_id[selector_id]=elm;return elm}const root_nodes=func.runtime.ui.get_refresh_index_root(SESSION_ID);elm=func.runtime.ui.get_preferred_live_element(func.runtime.ui.find_refresh_elements_by_attr(root_nodes,"xu-ui-id",selector_id));if(elm){state.elements_by_ui_id[selector_id]=elm;state.runtime_elements_cache=null}else if(state.elements_by_ui_id?.[selector_id]){delete state.elements_by_ui_id[selector_id];state.runtime_elements_cache=null}return elm};func.runtime.ui.get_refresh_indexed_elements_by_node_id=function(SESSION_ID,node_id){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return func.runtime.ui._wrap_matches([])}if(state.dirty){func.runtime.ui.rebuild_refresh_dependency_index(SESSION_ID)}const indexed_elements=state.elements_by_nodeid?.[node_id]||{};const elements=[];const selector_ids=Object.keys(indexed_elements);for(let index=0;index<selector_ids.length;index++){const selector_id=selector_ids[index];let candidate=indexed_elements[selector_id];if(!candidate?.isConnected){candidate=func.runtime.ui.get_refresh_indexed_element_by_ui_id(SESSION_ID,selector_id);if(!candidate){delete indexed_elements[selector_id];continue}indexed_elements[selector_id]=candidate}if(candidate){elements.push(candidate)}}return func.runtime.ui._wrap_matches(elements)};func.runtime.ui.get_refresh_index_root=function(SESSION_ID){const root=func.runtime.ui.get_first_node(func.runtime.ui.get_root_element?.(SESSION_ID));if(root){return[root]}return[document.body]};func.runtime.ui.get_refresh_index_elements=function(SESSION_ID,search_root_input){const root_nodes=func.runtime.ui._to_node_array(search_root_input);if(!root_nodes.length){const default_roots=func.runtime.ui.get_refresh_index_root(SESSION_ID);root_nodes.push(...default_roots)}const elements=[];for(let root_index=0;root_index<root_nodes.length;root_index++){const root_node=root_nodes[root_index];if(root_node?.matches?.("[xu-ui-id]")){elements.push(root_node)}const descendants=root_node?.querySelectorAll?.("[xu-ui-id]")||[];for(let element_index=0;element_index<descendants.length;element_index++){elements.push(descendants[element_index])}}return func.runtime.ui._wrap_matches(elements)};func.runtime.ui.get_refresh_indexed_runtime_elements=function(SESSION_ID){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return[]}if(state.dirty){func.runtime.ui.rebuild_refresh_dependency_index(SESSION_ID)}if(state.runtime_elements_cache!==null){return state.runtime_elements_cache}const elements=[];const selector_ids=Object.keys(state.elements_by_ui_id||{});for(let index=0;index<selector_ids.length;index++){const selector_id=selector_ids[index];let candidate=state.elements_by_ui_id[selector_id];if(!candidate?.isConnected){candidate=func.runtime.ui.get_refresh_indexed_element_by_ui_id(SESSION_ID,selector_id)}if(candidate){elements.push(candidate)}}state.runtime_elements_cache=elements;return state.runtime_elements_cache};func.runtime.ui.get_refresh_indexed_panel_wrapper_by_id=function(SESSION_ID,wrapper_id){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return null}if(state.dirty){func.runtime.ui.rebuild_refresh_dependency_index(SESSION_ID)}let elm=state.panel_wrappers_by_id?.[wrapper_id];elm=func.runtime.ui.get_preferred_live_element(elm);if(elm?.isConnected){state.panel_wrappers_by_id[wrapper_id]=elm;return elm}const root_nodes=func.runtime.ui.get_refresh_index_root(SESSION_ID);elm=func.runtime.ui.get_preferred_live_element(func.runtime.ui.find_refresh_elements_by_attr(root_nodes,"xu-panel-wrapper-id",wrapper_id));if(elm){state.panel_wrappers_by_id[wrapper_id]=elm;state.panel_wrapper_elements_cache=null}else if(state.panel_wrappers_by_id?.[wrapper_id]){delete state.panel_wrappers_by_id[wrapper_id];state.panel_wrapper_elements_cache=null}return elm};func.runtime.ui.get_refresh_indexed_panel_wrappers=function(SESSION_ID){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return[]}if(state.dirty){func.runtime.ui.rebuild_refresh_dependency_index(SESSION_ID)}if(state.panel_wrapper_elements_cache!==null){return state.panel_wrapper_elements_cache}const elements=[];const wrapper_ids=Object.keys(state.panel_wrappers_by_id||{});for(let index=0;index<wrapper_ids.length;index++){const wrapper_id=wrapper_ids[index];let candidate=state.panel_wrappers_by_id[wrapper_id];if(!candidate?.isConnected){candidate=func.runtime.ui.get_refresh_indexed_panel_wrapper_by_id(SESSION_ID,wrapper_id)}if(candidate){elements.push(candidate)}}state.panel_wrapper_elements_cache=elements;return state.panel_wrapper_elements_cache};func.runtime.ui.rebuild_refresh_dependency_index=function(SESSION_ID){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return{}}const index={};const elements_by_ui_id={};const elements_by_nodeid={};const panel_wrappers_by_id={};const refresh_elements=func.runtime.ui.get_refresh_index_elements(SESSION_ID);for(let element_index=0;element_index<refresh_elements.length;element_index++){const elm=refresh_elements[element_index];const elm_data=func.runtime.ui.get_data(elm);const selector_id=func.runtime.ui.get_attr(elm,"xu-ui-id");if(!selector_id||!elm_data?.xuData||!elm_data?.xuAttributes){continue}func.runtime.ui.register_refresh_index_element(elements_by_ui_id,elements_by_nodeid,panel_wrappers_by_id,selector_id,elm_data,elm);const dependencies=func.runtime.ui.collect_element_refresh_dependencies(elm_data);const field_ids=Object.keys(dependencies);for(let field_index=0;field_index<field_ids.length;field_index++){const field_id=field_ids[field_index];const attrs=dependencies[field_id];if(!index[field_id]){index[field_id]={}}if(!index[field_id][selector_id]){index[field_id][selector_id]={attributes:new Set,$elm:elm}}for(const attr_key of attrs||[]){index[field_id][selector_id].attributes.add(attr_key)}}}state.index=index;state.elements_by_ui_id=elements_by_ui_id;state.elements_by_nodeid=elements_by_nodeid;state.panel_wrappers_by_id=panel_wrappers_by_id;const runtime_elements=[];const runtime_selector_ids=Object.keys(elements_by_ui_id);for(let index=0;index<runtime_selector_ids.length;index++){const element=elements_by_ui_id[runtime_selector_ids[index]];if(element){runtime_elements.push(element)}}const panel_wrapper_elements=[];const panel_wrapper_ids=Object.keys(panel_wrappers_by_id);for(let index=0;index<panel_wrapper_ids.length;index++){const element=panel_wrappers_by_id[panel_wrapper_ids[index]];if(element){panel_wrapper_elements.push(element)}}state.runtime_elements_cache=runtime_elements;state.panel_wrapper_elements_cache=panel_wrapper_elements;state.dirty=false;return index};func.runtime.ui.collect_refresh_selectors_from_index=function(options){const perf_end=func.runtime?.perf?.start?.(options.SESSION_ID,"collect_refresh_selectors_from_index");func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_index_calls");const state=func.runtime.ui.ensure_refresh_dependency_state(options.SESSION_ID);if(!state){perf_end?.();return{}}if(state.dirty){func.runtime.ui.rebuild_refresh_dependency_index(options.SESSION_ID)}const selectors={};const index=state.index||{};const search_roots=func.runtime.ui._to_node_array(options.$elm_to_search);const search_root=search_roots.length?search_roots:null;const requested_fields=[...func.runtime.ui.normalize_refresh_fields(options.fields_arr)];for(let field_index=0;field_index<requested_fields.length;field_index++){const val_field=requested_fields[field_index];const indexed_elements=index[val_field]||{};const selector_ids=Object.keys(indexed_elements);for(let selector_index=0;selector_index<selector_ids.length;selector_index++){const selector_id=selector_ids[selector_index];const entry=indexed_elements[selector_id];let elm=entry.$elm;if(!elm?.isConnected){elm=func.runtime.ui.get_refresh_indexed_element_by_ui_id(options.SESSION_ID,selector_id);entry.$elm=elm}if(!elm){delete indexed_elements[selector_id];continue}const elm_data=func.runtime.ui.get_data(elm);if(!elm_data?.xuData){delete indexed_elements[selector_id];continue}if(!func.runtime.ui.matches_refresh_search_root(elm,search_root)){continue}if(typeof options.dsSession_changed!=="undefined"&&elm_data.xuData.paramsP&&elm_data.xuData.paramsP.dsSessionP<options.dsSession_changed){continue}if(!selectors[selector_id]){selectors[selector_id]={attributes:new Set,$elm:elm}}const attr_values=[...entry.attributes];for(let attr_index=0;attr_index<attr_values.length;attr_index++){selectors[selector_id].attributes.add(attr_values[attr_index])}}}const selector_result_ids=Object.keys(selectors);for(let selector_index=0;selector_index<selector_result_ids.length;selector_index++){const selector_id=selector_result_ids[selector_index];selectors[selector_id].attributes=[...selectors[selector_id].attributes]}func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_index_found",selector_result_ids.length);perf_end?.();return selectors};func.runtime.ui.collect_refresh_selectors_by_scan=function(options){const perf_end=func.runtime?.perf?.start?.(options.SESSION_ID,"collect_refresh_selectors_by_scan");func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_scan_calls");const selectors={};const search_roots=func.runtime.ui._to_node_array(options.$elm_to_search);const search_root=search_roots.length?search_roots:func.runtime.ui.get_refresh_index_root(options.SESSION_ID);const requested_fields=func.runtime.ui.normalize_refresh_fields(options.fields_arr);const refresh_elements=func.runtime.ui.get_refresh_index_elements(options.SESSION_ID,search_root);for(let element_index=0;element_index<refresh_elements.length;element_index++){const elm=refresh_elements[element_index];const elm_data=func.runtime.ui.get_data(elm);if(!elm_data.xuData){continue}if(typeof options.dsSession_changed!=="undefined"&&elm_data.xuData.paramsP&&elm_data.xuData.paramsP.dsSessionP<options.dsSession_changed){continue}const attributes=func.runtime.ui.collect_refresh_attributes_for_fields(elm_data,options.fields_arr,requested_fields);const selector_id=func.runtime.ui.get_attr(elm,"xu-ui-id");if(!attributes.length||!selector_id){continue}if(!selectors[selector_id]){selectors[selector_id]={attributes:new Set,$elm:elm}}for(let attr_index=0;attr_index<attributes.length;attr_index++){selectors[selector_id].attributes.add(attributes[attr_index])}}const selector_ids=Object.keys(selectors);for(let selector_index=0;selector_index<selector_ids.length;selector_index++){const selector_id=selector_ids[selector_index];selectors[selector_id].attributes=[...selectors[selector_id].attributes]}func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_scan_found",selector_ids.length);perf_end?.();return selectors};func.runtime.ui.collect_refresh_selectors=function(options){const selectors=func.runtime.ui.collect_refresh_selectors_from_index(options);if(!xu_isEmpty(selectors)){func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_index_used");return selectors}func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_scan_used");return func.runtime.ui.collect_refresh_selectors_by_scan(options)};func.runtime.ui.build_refresh_job_obj=function(options,elem_key,elem_val,extra={}){const elm_data=func.runtime.ui.get_data(elem_val.$elm);return{ui_type:elm_data?.xuData?.ui_type,SESSION_ID:options.SESSION_ID,fields_arr:options.fields_arr,elem_key:elem_key,node_id:elm_data?.xuData?.nodeid,key:elm_data?.xuData?.key,key_path:elm_data?.xuData?.key_path,recordid:elm_data?.xuData?.recordid,parent_element_ui_id:elm_data?.xuData?.parent_element_ui_id,prog_id:elm_data?.xuData?.paramsP?.prog_id,elem_val:{attributes:[...elem_val.attributes||[]]},...extra}};func.runtime.ui.queue_refresh_execute_job=async function(options,elem_key,elem_val,type,current_job){const elm_data=func.runtime.ui.get_data(elem_val.$elm);if(!elm_data?.xuData){return current_job}try{const obj=func.runtime.ui.build_refresh_job_obj(options,elem_key,elem_val);const next_job=await func.UI.worker.add_to_queue(options.SESSION_ID,"gui event",type,obj,current_job,elem_val.$elm);return next_job}catch(error){debugger;return current_job}};func.runtime.ui.queue_refresh_render_job=async function(options,elem_key,elem_val,attr_value,current_job){const elm_data=func.runtime.ui.get_data(elem_val?.$elm);if(!elm_data?.xuData?.ui_type){return current_job}const obj=func.runtime.ui.build_refresh_job_obj(options,elem_key,elem_val,{attr_value:attr_value});const next_job=await func.UI.worker.add_to_queue(options.SESSION_ID,"gui event","execute_xu_render_attributes",obj,current_job,elem_val.$elm,elm_data.xuData.paramsP.dsSessionP);if(glb.DEBUG_MODE){console.info("execute_xu_render_attributes",obj)}return next_job};func.runtime.ui.mark_refresh_pending_delete=function(elm_input){const elm=func.runtime.ui.get_first_node(elm_input);const session_id=func.runtime.ui.resolve_refresh_index_session_id?func.runtime.ui.resolve_refresh_index_session_id(elm):func.runtime.ui.get_data(elm)?.xuData?.SESSION_ID;const descendants=elm?.querySelectorAll?.("[xu-ui-id]")||[];for(let index=0;index<descendants.length;index++){const val=descendants[index];const element_data=func.runtime.ui.get_data(val);if(element_data?.xuData){element_data.xuData.pending_to_delete=true;if(func.UI?.worker?.mark_pending_delete_element&&session_id){func.UI.worker.mark_pending_delete_element(session_id,val)}}}if(func.UI?.worker?.mark_pending_delete_session&&session_id){func.UI.worker.mark_pending_delete_session(session_id)}return elm_input};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.prog_ui_xu_for_dependency_cache=func.runtime.ui.prog_ui_xu_for_dependency_cache||new WeakMap;func.runtime.ui.prog_ui_xu_for_fields_cache=func.runtime.ui.prog_ui_xu_for_fields_cache||new Map;func.runtime.ui.get_refresh_parent_element_ui_id=function($elm){const elm_data=func.runtime.ui.get_data($elm);if(elm_data?.xuPanelData){return elm_data.xuPanelData.parent_element_ui_id}return elm_data?.xuData?.parent_element_ui_id};func.runtime.ui.resolve_refresh_xu_for_item_id=function($elm){const elm_data=func.runtime.ui.get_data($elm);if(elm_data?.xuPanelData){return elm_data.xuPanelData.node.id}return elm_data?.xuData?.nodeid};func.runtime.ui.build_refresh_element_value=function($elm){const elem_val={attributes:Object.keys(func.runtime.ui.get_data($elm)?.xuAttributes||{}),$elm:$elm};return elem_val};func.runtime.ui.build_xu_for_refresh_job_obj=function(options,elem_key,$elm,xu_for_item_id){const elm_data=func.runtime.ui.get_data($elm);return{ui_type:elm_data.xuData.ui_type,SESSION_ID:options.SESSION_ID,fields_arr:options.fields_arr,elem_key:elem_key,elem_val:{},xu_for_item_id:xu_for_item_id}};func.runtime.ui.queue_xu_for_refresh=async function(options,$elm,xu_for_item_id,current_job,debug_label,debug_context){const elm_data=func.runtime.ui.get_data($elm);if(options.avoid_xu_for_refresh||!$elm?.length||!elm_data?.xuData){return current_job}const elem_key=func.runtime.ui.get_attr($elm,"xu-ui-id");const obj=func.runtime.ui.build_xu_for_refresh_job_obj(options,elem_key,$elm,xu_for_item_id);await func.UI.worker.add_to_queue(options.SESSION_ID,"gui event","execute_xu_for",obj,current_job,$elm,elm_data.xuData.paramsP.dsSessionP);if(glb.DEBUG_MODE){console.info(debug_label||"execute_xu_for",obj,debug_context)}return current_job};func.runtime.ui.collect_prog_ui_xu_for_fields=function(attr_val){const cache_key=typeof attr_val==="string"?`str:${attr_val}`:`obj:${JSON.stringify(attr_val||{})}`;const cached_fields=func.runtime.ui.prog_ui_xu_for_fields_cache.get(cache_key);if(cached_fields){return cached_fields}const fields=new Set;const add_fields=function(values){values?.forEach?.(function(field_id){fields.add(field_id)})};add_fields(func.runtime.ui.extract_expression_refresh_fields({},attr_val,true));add_fields(func.runtime.ui.extract_expression_refresh_fields({},attr_val,false));const result=[...fields].filter(Boolean);func.runtime.ui.prog_ui_xu_for_fields_cache.set(cache_key,result);return result};func.runtime.ui.add_prog_ui_xu_for_dependency=function(index,field_id,entry){if(!field_id){return}if(!index[field_id]){index[field_id]={}}const entry_key=`${entry.parent_node_id||""}::${entry.xu_for_item_id}`;index[field_id][entry_key]=entry};func.runtime.ui.collect_prog_ui_xu_for_dependencies=function(progUi,index={},parent_node_id){if(!Array.isArray(progUi)){return index}for(const item of progUi){if(!xu_isEmpty(item?.attributes)){const attribute_keys=Object.keys(item.attributes);for(let attr_index=0;attr_index<attribute_keys.length;attr_index++){const attr=attribute_keys[attr_index];const val=item.attributes[attr];if(attr!=="xu-exp:xu-for"&&attr!=="xu-for"){continue}const fields=func.runtime.ui.collect_prog_ui_xu_for_fields(val);for(const field_id of fields){func.runtime.ui.add_prog_ui_xu_for_dependency(index,field_id,{parent_node_id:parent_node_id,xu_for_item_id:item.id})}}}if(item?.children){func.runtime.ui.collect_prog_ui_xu_for_dependencies(item.children,index,item.id)}}return index};func.runtime.ui.get_prog_ui_xu_for_dependencies=function(progUi){if(!Array.isArray(progUi)){return{}}let cached_dependencies=func.runtime.ui.prog_ui_xu_for_dependency_cache.get(progUi);if(cached_dependencies){return cached_dependencies}cached_dependencies=func.runtime.ui.collect_prog_ui_xu_for_dependencies(progUi,{});func.runtime.ui.prog_ui_xu_for_dependency_cache.set(progUi,cached_dependencies);return cached_dependencies};func.runtime.ui.merge_prog_ui_xu_for_dependencies=function(target_index,source_index){if(xu_isEmpty(source_index)){return target_index}const field_ids=Object.keys(source_index);for(let field_index=0;field_index<field_ids.length;field_index++){const field_id=field_ids[field_index];const entry_obj=source_index[field_id];if(!target_index[field_id]){target_index[field_id]={}}const entry_keys=Object.keys(entry_obj||{});for(let entry_index=0;entry_index<entry_keys.length;entry_index++){const entry_key=entry_keys[entry_index];const entry=entry_obj[entry_key];target_index[field_id][entry_key]=entry}}return target_index};func.runtime.ui.rebuild_refresh_xu_for_index=async function(SESSION_ID,panels_obj,$xu_embed_container){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return{}}const index={};const $embed_container=$xu_embed_container?.length?$xu_embed_container:func.runtime.ui.get_embed_screen_containers();const root_prog_ui=func.runtime.ui.get_data($embed_container)?.xuData?.screenInfo?.progUi;if(root_prog_ui){func.runtime.ui.merge_prog_ui_xu_for_dependencies(index,func.runtime.ui.get_prog_ui_xu_for_dependencies(root_prog_ui))}const resolved_panels_obj=panels_obj||await func.UI.utils.get_panels_wrapper_from_dom(SESSION_ID,$embed_container,true);for(const panel_val of Object.values(resolved_panels_obj||{})){func.runtime.ui.merge_prog_ui_xu_for_dependencies(index,func.runtime.ui.get_prog_ui_xu_for_dependencies(panel_val?.progUi))}state.xu_for_index=index;state.xu_for_dirty=false;return index};func.runtime.ui.collect_refresh_xu_for_entries=async function(options,panels_obj,$xu_embed_container){const state=func.runtime.ui.ensure_refresh_dependency_state(options.SESSION_ID);if(!state){return{entries:[],missing_fields:[...options.fields_arr||[]],panels_obj:panels_obj||{}}}let resolved_panels_obj=panels_obj;if(state.xu_for_dirty){if(!resolved_panels_obj){const $embed_container=$xu_embed_container?.length?$xu_embed_container:func.runtime.ui.get_embed_screen_containers();resolved_panels_obj=await func.UI.utils.get_panels_wrapper_from_dom(options.SESSION_ID,$embed_container,true)}await func.runtime.ui.rebuild_refresh_xu_for_index(options.SESSION_ID,resolved_panels_obj,$xu_embed_container)}const entries={};const missing_fields=[];const fields_arr=options.fields_arr||[];for(let field_index=0;field_index<fields_arr.length;field_index++){const field_id=fields_arr[field_index];const field_entries=state.xu_for_index?.[field_id];if(xu_isEmpty(field_entries)){missing_fields.push(field_id);continue}const entry_keys=Object.keys(field_entries);for(let entry_index=0;entry_index<entry_keys.length;entry_index++){const entry_key=entry_keys[entry_index];const entry=field_entries[entry_key];entries[`${field_id}::${entry_key}`]=entry}}return{entries:Object.values(entries),missing_fields:missing_fields,panels_obj:resolved_panels_obj||{}}};func.runtime.ui.iterate_refresh_field_in_prog_ui=async function(options,progUi,field_id,refreshed_ids=[],panel_val,current_job){const dependencies=func.runtime.ui.get_prog_ui_xu_for_dependencies(progUi);const field_entries=Object.values(dependencies?.[field_id]||{});for(const entry of field_entries){const $elem=func.runtime.ui.get_refresh_indexed_elements_by_node_id(options.SESSION_ID,entry.parent_node_id);if(!$elem?.length){continue}const parent_element_ui_id=func.runtime.ui.get_attr($elem,"xu-ui-id");const refresh_key=parent_element_ui_id&&entry.xu_for_item_id?`${parent_element_ui_id}::${entry.xu_for_item_id}`:parent_element_ui_id;const is_refreshed=refreshed_ids instanceof Set?refreshed_ids.has(refresh_key):refreshed_ids.includes(refresh_key);if(is_refreshed){continue}await func.runtime.ui.queue_xu_for_refresh(options,$elem,entry.xu_for_item_id,current_job,"node execute_xu_for",panel_val);if(refreshed_ids instanceof Set){refreshed_ids.add(refresh_key)}else{refreshed_ids.push(refresh_key)}}return current_job};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.refresh_xu_attributes=async function(options){if(!options.ignore_screen_blocker&&options.trigger!=="click"&&!xu_isEmpty(SCREEN_BLOCKER_OBJ)){setTimeout(()=>{func.runtime.ui.refresh_xu_attributes(options)},100);return}const perf_end=func.runtime?.perf?.start?.(options.SESSION_ID,"refresh_xu_attributes");UI_WORKER_OBJ.cache={};try{let new_job=options.jobNoP;let selectors=func.runtime.ui.collect_refresh_selectors(options);const xu_for_selectors=[];const refreshed_ids=new Set;const selector_keys=Object.keys(selectors);func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_batches");func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_total",selector_keys.length);for(let selector_index=0;selector_index<selector_keys.length;selector_index++){const elem_key=selector_keys[selector_index];const elem_val=selectors[elem_key];if(!elem_val)continue;const $elm=elem_val.$elm;const elm_data=func.runtime.ui.get_data($elm);const xuData=elm_data?.xuData;const xuAttributes=elm_data?.xuAttributes;if(!xuData||xuData.pending_to_delete)continue;const attr_list=elem_val.attributes||[];const has_xu_exp_render=attr_list.includes("xu-exp:xu-render");const has_xu_for=attr_list.includes("xu-exp:xu-for")||attr_list.includes("xu-for");let performed_render;if(!xuAttributes)continue;if(has_xu_exp_render){const res=await func.expression.get(options.SESSION_ID,xuAttributes["xu-exp:xu-render"],xuData.paramsP.dsSessionP,"UI Property EXP",xuData.recordid);const attr_value=await func.common.get_cast_val(options.SESSION_ID,"refresh xu-attributes","xu-render","bool",res.result);const _elm_node=func.runtime.ui.get_first_node($elm);if(!attr_value&&_elm_node?.tagName==="XURENDER")continue;if(attr_value&&_elm_node?.tagName!=="XURENDER"){new_job=await func.runtime.ui.queue_refresh_execute_job(options,elem_key,elem_val,"execute_xu_all_attributes",new_job);continue}new_job=await func.runtime.ui.queue_refresh_render_job(options,elem_key,elem_val,attr_value,options.jobNoP);performed_render=true;func.runtime.ui.mark_refresh_pending_delete($elm)}const _elm_tag_node=func.runtime.ui.get_first_node($elm);if(performed_render||_elm_tag_node?.tagName==="XURENDER")continue;if(has_xu_for){xu_for_selectors.push(elem_val);continue}if(xuData.ui_type==="xu-widget"){new_job=await func.runtime.ui.queue_refresh_execute_job(options,elem_key,elem_val,"execute_xu_widget",new_job)}else{new_job=await func.runtime.ui.queue_refresh_execute_job(options,elem_key,elem_val,"execute_xu_all_attributes",new_job)}}for(let xu_for_index=0;xu_for_index<xu_for_selectors.length;xu_for_index++){const elem_val=xu_for_selectors[xu_for_index];const $elm=elem_val?.$elm;const xuData=func.runtime.ui.get_data($elm)?.xuData;if(!xuData||xuData.pending_to_delete)continue;const parent_element_ui_id=func.runtime.ui.get_refresh_parent_element_ui_id($elm);const xu_for_item_id=func.runtime.ui.resolve_refresh_xu_for_item_id($elm);const refresh_key=parent_element_ui_id&&xu_for_item_id?`${parent_element_ui_id}::${xu_for_item_id}`:parent_element_ui_id;if(!parent_element_ui_id||refreshed_ids.has(refresh_key)){continue}let _$elem=func.runtime.ui.get_refresh_indexed_element_by_ui_id(options.SESSION_ID,parent_element_ui_id);if(_$elem&&!_$elem.length)_$elem=func.runtime.ui._wrap_matches([_$elem]);await func.runtime.ui.queue_xu_for_refresh(options,_$elem,xu_for_item_id,new_job,"execute_xu_for");refreshed_ids.add(refresh_key)}const $xu_embed_container=func.runtime.ui.get_embed_screen_containers();const refresh_state=func.runtime.ui.ensure_refresh_dependency_state(options.SESSION_ID);const preload_panels_obj=refresh_state?.xu_for_dirty?await func.UI.utils.get_panels_wrapper_from_dom(options.SESSION_ID,$xu_embed_container,true):null;let{entries:xu_for_entries,missing_fields,panels_obj}=await func.runtime.ui.collect_refresh_xu_for_entries(options,preload_panels_obj,$xu_embed_container);if(missing_fields.length&&xu_isEmpty(panels_obj)){panels_obj=await func.UI.utils.get_panels_wrapper_from_dom(options.SESSION_ID,$xu_embed_container,true)}for(let entry_index=0;entry_index<xu_for_entries.length;entry_index++){const entry=xu_for_entries[entry_index];const $elem=func.runtime.ui.get_refresh_indexed_elements_by_node_id(options.SESSION_ID,entry.parent_node_id);if(!$elem?.length){continue}const indexed_parent_element_ui_id=func.runtime.ui.get_attr($elem,"xu-ui-id");const indexed_refresh_key=indexed_parent_element_ui_id&&entry.xu_for_item_id?`${indexed_parent_element_ui_id}::${entry.xu_for_item_id}`:indexed_parent_element_ui_id;if(!indexed_parent_element_ui_id||refreshed_ids.has(indexed_refresh_key)){continue}await func.runtime.ui.queue_xu_for_refresh(options,$elem,entry.xu_for_item_id,new_job,"indexed execute_xu_for",entry);refreshed_ids.add(indexed_refresh_key)}func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_xu_for_entries_total",xu_for_entries.length);func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_xu_for_missing_fields_total",missing_fields.length);for(let missing_index=0;missing_index<missing_fields.length;missing_index++){const field_id=missing_fields[missing_index];if($xu_embed_container.length){const progUi=func.runtime.ui.get_data($xu_embed_container)?.xuData?.screenInfo?.progUi;if(progUi){await func.runtime.ui.iterate_refresh_field_in_prog_ui(options,progUi,field_id,refreshed_ids,null,new_job)}}const panel_ids=Object.keys(panels_obj||{});for(let panel_index=0;panel_index<panel_ids.length;panel_index++){const panel_val=panels_obj[panel_ids[panel_index]];await func.runtime.ui.iterate_refresh_field_in_prog_ui(options,panel_val.progUi,field_id,refreshed_ids,panel_val,new_job)}}func.events.delete_job(options.SESSION_ID,options.jobNoP)}finally{perf_end?.()}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.prog_doc_refresh_dependency_cache=func.runtime.ui.prog_doc_refresh_dependency_cache||new WeakMap;func.runtime.ui.panel_refresh_dependency_cache=func.runtime.ui.panel_refresh_dependency_cache||new WeakMap;func.runtime.ui.extract_refresh_fields_from_text=function(text){const fields=new Set;const str=typeof text==="string"?text:JSON.stringify(text||{});if(!str){return fields}for(const match of str.matchAll(/@([A-Za-z0-9_$.-]+)/g)){if(match?.[1]){fields.add(match[1])}}return fields};func.runtime.ui.get_prog_doc_refresh_dependencies=function(prog_doc){if(!prog_doc||typeof prog_doc!=="object"){return{prog_fields:new Set,xu_for_fields:new Set}}let cache=func.runtime.ui.prog_doc_refresh_dependency_cache.get(prog_doc);if(cache){return cache}const prog_fields=new Set;const prog_data_source_str=JSON.stringify(prog_doc.progDataSource||{});for(const match of prog_data_source_str.matchAll(/@([A-Za-z0-9_$.-]+)/g)){if(match?.[1]){prog_fields.add(match[1])}}const xu_for_index=func.UI.utils.get_prog_ui_attribute_index?.(prog_doc.progUi,"xu-for")||{};const xu_for_fields=new Set(Object.keys(xu_for_index));cache={prog_fields:prog_fields,xu_for_fields:xu_for_fields};func.runtime.ui.prog_doc_refresh_dependency_cache.set(prog_doc,cache);return cache};func.runtime.ui.get_panel_refresh_dependencies=function(panelXuAttributes){if(!panelXuAttributes||typeof panelXuAttributes!=="object"){return{program_fields:new Set,parameter_entries:[]}}let cache=func.runtime.ui.panel_refresh_dependency_cache.get(panelXuAttributes);if(cache){return cache}const program_fields=func.runtime.ui.extract_refresh_fields_from_text(panelXuAttributes["xu-exp:program"]);const parameter_entries=[];const panel_attr_keys=Object.keys(panelXuAttributes);for(let attr_index=0;attr_index<panel_attr_keys.length;attr_index++){const attr=panel_attr_keys[attr_index];const value=panelXuAttributes[attr];const match=attr.match(/xu-exp:(\w+)/);if(!match||match[1]==="program"){continue}parameter_entries.push({parameter_in_field_id:match[1],value_str:typeof value==="string"?value:JSON.stringify(value||{})})}cache={program_fields:program_fields,parameter_entries:parameter_entries};func.runtime.ui.panel_refresh_dependency_cache.set(panelXuAttributes,cache);return cache};func.runtime.ui.refresh_screen=async function(options){const perf_end=func.runtime?.perf?.start?.(options.SESSION_ID,"refresh_screen");let found;let refresh_reason;let refresh_details;try{const validate_change=function(prog_doc,panelXuAttributes,skip_ui_check){found=null;refresh_reason=null;refresh_details=null;if(options.watcher?.path?.includes("progDataSource")){found=true;refresh_reason=`progDataSource by watcher ${options.watcher.path}`;refresh_details=options.watcher;return}const refresh_dependencies=func.runtime.ui.get_prog_doc_refresh_dependencies(prog_doc);const _attributes=panelXuAttributes||{};const panel_refresh_dependencies=func.runtime.ui.get_panel_refresh_dependencies(_attributes);for(const field_id of options.fields_changed_arr){found=panel_refresh_dependencies.program_fields.has(field_id);if(found){refresh_reason=`program ${_attributes["xu-exp:program"]} ${field_id} changed `;refresh_details=_attributes;break}for(const parameter_entry of panel_refresh_dependencies.parameter_entries){const parameter_in_field_id=parameter_entry.parameter_in_field_id;if(parameter_entry.value_str?.includes(field_id)){found=refresh_dependencies.prog_fields.has(parameter_in_field_id);if(found){refresh_reason=`field ${field_id} in progDataSource parameter_in changed`;refresh_details=prog_doc?.progDataSource;break}if(!skip_ui_check){found=refresh_dependencies.xu_for_fields.has(parameter_in_field_id);if(found){refresh_reason=`field ${field_id} in progUi xu-for parameter_in changed`;refresh_details=found;break}}}}if(found)break;found=refresh_dependencies.prog_fields.has(field_id);if(found){refresh_reason=`field ${field_id} in progDataSource changed`;refresh_details=prog_doc?.progDataSource;break}if(!skip_ui_check){found=refresh_dependencies.xu_for_fields.has(field_id);if(found){refresh_reason=`field ${field_id} in progUi xu-for changed`;refresh_details=found;break}}if(found){break}}};if(options.fields_changed_datasource){const _session=SESSION_OBJ[options.SESSION_ID];const _ds=_session.DS_GLB[options.fields_changed_datasource];const prog_doc=await func.utils.DOCS_OBJ.get(options.SESSION_ID,_ds.prog_id);if(prog_doc.progUi){validate_change(prog_doc,null,true);if(found){const $elm=func.runtime.ui.find_in_root(options.SESSION_ID,`#container_${_ds.prog_id}_0`);if($elm?.length){const elm_data=func.runtime.ui.get_data($elm);const refreshed_ds=_ds.dsSession;func.runtime.ui.empty($elm);if(func.runtime.ui.get_data($elm)){func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_screen_main_rerenders");await func.runtime.render.render_ui_tree(options.SESSION_ID,$elm,structuredClone(elm_data.xuData.node),{},elm_data.xuData.paramsP,null,null,elm_data.xuData.key,refreshed_ds,elm_data.xuData.parent_node,null,elm_data.xuData.$root_container);if(glb.DEBUG_MODE){console.info("========= refresh main info ==============");console.info("reason:",refresh_reason);console.info("element:",$elm);console.info("==========================================")}return}}}}}const panels_obj=await func.UI.utils.get_panels_wrapper_from_dom(options.SESSION_ID,func.runtime.ui.get_root_element(options.SESSION_ID),false);found=false;const panel_ids=Object.keys(panels_obj||{});for(let panel_index=0;panel_index<panel_ids.length;panel_index++){const panel_val=panels_obj[panel_ids[panel_index]];const panel_data=func.runtime.ui.get_data(panel_val.$panel_div);const panel_xu_data=panel_data?.xuData;if(!panel_xu_data)continue;if(panel_xu_data.pending_to_delete)continue;if(!options.watcher&&options.fields_changed_arr){if(options.fields_changed_datasource&&panel_val._ds.dsSession<=Number(options.fields_changed_datasource)){continue}validate_change(panel_val.prog_doc,panel_val?.panelXuAttributes)}if(options.datasource_changed&&panel_val._ds.dsSession==options.datasource_changed){refresh_reason=`panel datasource ${options.datasource_changed} changed`;refresh_details="";found=true}if(found){UI_WORKER_OBJ.cache={};const _session=SESSION_OBJ[options.SESSION_ID];if(glb.DEBUG_MODE){console.info("========= refresh info ==============");console.info("reason:",refresh_reason);console.info("details:",refresh_details);console.info("panel:",panel_val);console.info("=====================================")}const $div_elm=panel_val.$panel_div;const wrapper_data=panel_data;const get_element_by_ui_id=function(xu_ui_id){if(func.runtime?.ui?.get_refresh_indexed_element_by_ui_id){return func.runtime.ui.get_refresh_indexed_element_by_ui_id(options.SESSION_ID,xu_ui_id)}return func.runtime.ui._wrap_matches(Array.from(document.querySelectorAll(`[xu-ui-id='${xu_ui_id}']`)))};if(xu_isEmpty(wrapper_data))continue;try{func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_screen_panel_rerenders");const ts=Date.now();for(let id_index=0;id_index<panel_val.ids.length;id_index++){const val=panel_val.ids[id_index];const _matched=get_element_by_ui_id(val);const _arr=_matched?.toArray?_matched.toArray():_matched?[_matched]:[];for(let _mi=0;_mi<_arr.length;_mi++){func.runtime.ui.set_attr(_arr[_mi],"xu-ui-id",val+ts);func.runtime.ui.clear_data(_arr[_mi])}}let refreshed_ds;if(_session.DS_GLB[panel_val._ds.dsSession]){refreshed_ds=panel_val._ds.dsSession}for(let child_index=0;child_index<wrapper_data.xuData.node_org.children.length;child_index++){const item=wrapper_data.xuData.node_org.children[child_index];if(item.tagName!=="xu-panel")continue;await func.runtime.render.render_ui_tree(options.SESSION_ID,$div_elm,structuredClone(item),{},wrapper_data.xuData.paramsP,null,null,wrapper_data.xuData.key,refreshed_ds,wrapper_data.xuData.parent_node,null,wrapper_data.xuData.$root_container)}for(let id_index=0;id_index<panel_val.ids.length;id_index++){const val=panel_val.ids[id_index];func.runtime.ui.remove(get_element_by_ui_id(val+ts))}}catch(error){debugger}}}}finally{perf_end?.()}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.refresh_document_changes_for_realtime_update=async function(SESSION_ID,doc_change){const _session=SESSION_OBJ[SESSION_ID];for(const[key,_ds]of Object.entries(_session.DS_GLB)){const prog_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(prog_obj?.progDataSource?.dataSourceRealtime&&prog_obj?.progDataSource?.dataSourceTableId===doc_change.table_id){try{if(!_ds.screen_params)continue;if(_ds.screen_params.is_panelP){func.runtime.ui.refresh_screen({SESSION_ID:SESSION_ID,fields_changed_arr:null,datasource_changed:key})}else{func.action.execute(SESSION_ID,"act_refresh",_ds,null,null)}}catch(err){}}}if(glb.new_xu_render){for(const[ui_cache_key,ui_cache_val]of Object.entries(UI_WORKER_OBJ.xu_render_cache)){const prog_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,ui_cache_val.paramsP.prog_id);if(prog_obj?.progDataSource?.dataSourceTableId===doc_change.table_id){ui_cache_val.$div=null}}}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.get_screen_context=function(SESSION_ID,$container,paramsP,is_skeleton){const _session=SESSION_OBJ[SESSION_ID];const _ds=is_skeleton?null:_session?.DS_GLB?.[paramsP.dsSessionP];const container_xu_data=func.runtime.ui.get_data($container)?.xuData;const currentRecordId=container_xu_data?.recordid||_ds?.currentRecordId||"";return{_session:_session,_ds:_ds,container_xu_data:container_xu_data,currentRecordId:currentRecordId,is_mobile:glb.MOBILE_ARR.includes(paramsP.screenInfo.properties?.menuType)}};func.runtime.render.get_node_attributes=function(nodeP){try{if(func.runtime.render.is_tree_node?.(nodeP)){return nodeP.attributes}return nodeP?.attributes}catch(error){return undefined}};func.runtime.render.find_existing_element=function(options){const currentRecordId=options.currentRecordId||options.render_context?.currentRecordId;const SESSION_ID=options.SESSION_ID||func.runtime.ui.get_data(options.$container)?.xuData?.SESSION_ID;const is_matching_candidate=function(candidate){if(!candidate)return false;const candidate_data=func.runtime.ui.get_data(candidate);return!candidate_data?.xuData?.is_placeholder&&!candidate_data?.xuData?.xu_for_placeholder&&candidate_data?.xuData?.recordid===currentRecordId&&candidate_data?.xuData?.key===options.keyP&&candidate.tagName!=="XURENDER"};const get_indexed_match=function(){if(!SESSION_ID||!func.runtime.ui.get_refresh_indexed_elements_by_node_id){return null}const indexed_candidates=func.runtime.ui.get_refresh_indexed_elements_by_node_id(SESSION_ID,options.nodeP.id).toArray();for(let index=0;index<indexed_candidates.length;index++){const candidate=indexed_candidates[index];if(candidate.parentElement!==func.runtime.ui.get_first_node(options.$container)){continue}if(is_matching_candidate(candidate)){return func.runtime.ui._wrap_matches([candidate])}}return null};const indexed_match=get_indexed_match();if(indexed_match?.length){return{div:indexed_match,candidates:indexed_match}}let $candidates=func.runtime.ui.find_element_data_in_parent(options.$container,"xuData","nodeid",options.nodeP.id);let $matched=null;const fallback_candidates=$candidates?.toArray?.()||[];for(let index=0;index<fallback_candidates.length;index++){const candidate=fallback_candidates[index];if(is_matching_candidate(candidate)){$matched=func.runtime.ui._wrap_matches([candidate]);break}}return{div:$matched,candidates:$candidates}};func.runtime.render.log_tree_debug=function(options){return func.utils.debug.log(options.SESSION_ID,options.paramsP.prog_id+"_"+options.nodeP.id_org+"_ui_prop",{module:"gui",action:"init",prop:options.nodeP.id,details:options.error_descP,result:null,error:options.is_errorP,source:options._ds?.tree_obj?.menuName||"",fields:null,type:null,prog_id:options.paramsP.prog_id,dsSession:null})};func.runtime.render.create_temp_render_container=function($container){const tmp=document.createElement("tmp");func.runtime.ui.set_data(tmp,"xuData",func.runtime.ui.get_data($container)?.xuData);return tmp};func.runtime.render.insert_ordered_child=function($container,$child,target_key){const children=func.runtime.ui.get_children($container);if(!children.length){return func.runtime.ui.append_to($child,$container)}const normalized_target_key=Number.isFinite(Number(target_key))?Number(target_key):`${target_key}`;for(let index=0;index<children.length;index++){const existing_child=children[index];const existing_key=func.runtime.ui.get_data(existing_child)?.xuData?.key;if(typeof existing_key==="undefined"||existing_key===null){continue}const normalized_existing_key=Number.isFinite(Number(existing_key))?Number(existing_key):`${existing_key}`;if(normalized_existing_key>normalized_target_key){return func.runtime.ui.insert_before($child,existing_child)}}return func.runtime.ui.append_to($child,$container)};func.runtime.render.prepare_draw_context=async function(options){let temp_$div=null;let render_container=options.$container;let $div;if(options.buffered){temp_$div=await func.runtime.ui.create_container({SESSION_ID:options.SESSION_ID,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,treeP:options.treeP,parent_nodeP:options.parent_nodeP,prop:options.prop,div_typeP:options.element,attr_str:options.attr_str||"",is_placeholder:true});render_container=func.runtime.render.create_temp_render_container(options.$container);$div=func.runtime.ui.get_first_node(temp_$div)?.cloneNode(true);const cloned_data=func.runtime.ui.get_data($div);if(cloned_data?.xuData){cloned_data.xuData.is_placeholder=false}}else{$div=await func.runtime.ui.create_container({SESSION_ID:options.SESSION_ID,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,treeP:options.treeP,parent_nodeP:options.parent_nodeP,prop:options.prop,div_typeP:options.element,attr_str:options.attr_str||""})}return{$div:$div,temp_$div:temp_$div,$live_elm:temp_$div||$div,render_container:render_container}};func.runtime.render.run_draw_pipeline=async function(options){if(!options.element||options.element==="script"){return{$div:null,temp_$div:null,render_container:options.$container,ret:{}}}const draw_context=await func.runtime.render.prepare_draw_context(options);const{$div,temp_$div,$live_elm,render_container}=draw_context;func.runtime.render.bind_hover_handlers($div,options.hover_handlers,options.include_hover_click);const ret=await func.runtime.render.set_attributes_new({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:render_container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$elm:$div,$live_elm:$live_elm,is_init:true});if(!func.runtime.render.should_stop_after_attributes(options.nodeP,ret)){await func.runtime.render.process_post_attribute_children({SESSION_ID:options.SESSION_ID,$div:$div,nodeP:options.nodeP,parent_infoP:options.parent_infoP,$root_container:options.$root_container,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,keyP:options.keyP,refreshed_ds:options.refreshed_ds,parent_nodeP:options.parent_nodeP,check_existP:options.check_existP,render_container:render_container,hover_in:options.hover_handlers.hover_in,iterate_child:options.iterate_child,await_children:!options.buffered,defer_when_background:options.buffered,ret:ret})}return{$div:$div,temp_$div:temp_$div,$live_elm:$live_elm,render_container:render_container,ret:ret}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.parent_ds_fields_cache=func.runtime.render.parent_ds_fields_cache||new Map;func.runtime.render.parent_ds_field_names_cache=func.runtime.render.parent_ds_field_names_cache||new Map;func.runtime.render.xu_render_cache_str_cache=func.runtime.render.xu_render_cache_str_cache||new Map;func.runtime.render.xu_render_exclude_fields_cache=func.runtime.render.xu_render_exclude_fields_cache||new WeakMap;func.runtime.render.set_small_cache_entry=function(cache,key,value,max_entries=1e3){if(cache.size>=max_entries&&!cache.has(key)){cache.clear()}cache.set(key,value);return value};func.runtime.render.get_runtime_descendants=function($div){const _div_node=func.runtime.ui.get_first_node($div);if(!_div_node){return[]}return _div_node.querySelectorAll?.("[xu-ui-id]")||[]};func.runtime.render.collect_dependency_fields_from_store=function(dependency_store,dependency_fields){const attr_keys=Object.keys(dependency_store||{});for(let attr_index=0;attr_index<attr_keys.length;attr_index++){const fields=dependency_store[attr_keys[attr_index]]||[];for(let field_index=0;field_index<fields.length;field_index++){dependency_fields.add(fields[field_index])}}return dependency_fields};func.runtime.render.collect_dependency_fields_from_attributes=function(xu_attributes,dependency_fields){const attr_keys=Object.keys(xu_attributes||{});for(let attr_index=0;attr_index<attr_keys.length;attr_index++){const attr_val=xu_attributes[attr_keys[attr_index]];if(typeof attr_val!=="string"){continue}const matches=attr_val.match(/@([A-Za-z0-9_]+)/g)||[];for(let match_index=0;match_index<matches.length;match_index++){dependency_fields.add(matches[match_index].slice(1))}}return dependency_fields};func.runtime.render.build_xu_render_original_data=function(options){return{$container:options.$container,nodeP:func.runtime.ui.get_node_snapshot?func.runtime.ui.get_node_snapshot(options.nodeP):structuredClone(options.nodeP),parent_infoP:options.parent_infoP,paramsP:options.paramsP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$root_container:options.$root_container}};func.runtime.render.attach_xu_render_state=function($xurender,options){func.runtime.ui.set_data($xurender,"xuData",options.xuData);func.runtime.ui.get_data($xurender).xuData.original_data_obj=options.original_data_obj;if(options.xurender_node){func.runtime.ui.get_data($xurender).xuData.xurender_node=options.xurender_node}func.runtime.ui.get_data($xurender).xuAttributes=options.xuAttributes||{};return $xurender};func.runtime.render.create_xu_render_placeholder=function(xu_ui_id,$target,options={}){const $xurender=func.runtime.ui.create_xurender(xu_ui_id,$target,options.hidden);return func.runtime.render.attach_xu_render_state($xurender,options)};func.runtime.render.collect_dependency_fields=function($div){if(!$div?.length){return[]}const dependency_fields=new Set;const descendants=func.runtime.render.get_runtime_descendants($div);for(let index=0;index<descendants.length;index++){const elm_data=func.runtime.ui.get_data(descendants[index]);const dependency_store=elm_data?.xuData?.refresh_dependency_by_attr;if(dependency_store){func.runtime.render.collect_dependency_fields_from_store(dependency_store,dependency_fields);continue}const xu_attributes=elm_data?.xuAttributes;if(!xu_attributes){continue}func.runtime.render.collect_dependency_fields_from_attributes(xu_attributes,dependency_fields)}return[...dependency_fields]};func.runtime.render.cache_xu_render=function(cache_key,value){if(value?.$div&&!value.dependency_fields){value.dependency_fields=func.runtime.render.collect_dependency_fields(value.$div)}UI_WORKER_OBJ.xu_render_cache[cache_key]=value;return UI_WORKER_OBJ.xu_render_cache[cache_key]};func.runtime.render.get_parent_ds_cache_signature=function(SESSION_ID,dsSessionP){var _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dsSessionP];if(!_ds){return`${dsSessionP||""}:`}let signature=`${dsSessionP}:${_ds.currentRecordId||""}`;if(typeof _ds.parentDataSourceNo!=="undefined"){signature+=`|${func.runtime.render.get_parent_ds_cache_signature(SESSION_ID,_ds.parentDataSourceNo)}`}return signature};func.runtime.render.build_parent_ds_fields=function(SESSION_ID,dsSessionP){var _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dsSessionP];if(!_ds){return{}}const idx=func.common.find_ROWID_idx(_ds,_ds.currentRecordId);const data=_ds.data_feed.rows[idx]||{};let obj={};if(typeof _ds.parentDataSourceNo!=="undefined"){obj=func.runtime.render.get_parent_ds_fields(SESSION_ID,_ds.parentDataSourceNo)}return{...data,...obj}};func.runtime.render.get_parent_ds_fields=function(SESSION_ID,dsSessionP){const signature=func.runtime.render.get_parent_ds_cache_signature(SESSION_ID,dsSessionP);const cache_key=`${SESSION_ID}:${signature}`;if(func.runtime.render.parent_ds_fields_cache.has(cache_key)){return func.runtime.render.parent_ds_fields_cache.get(cache_key)}const fields=func.runtime.render.build_parent_ds_fields(SESSION_ID,dsSessionP);return func.runtime.render.set_small_cache_entry(func.runtime.render.parent_ds_fields_cache,cache_key,fields)};func.runtime.render.get_parent_ds_field_names=function(SESSION_ID,dsSessionP){const signature=func.runtime.render.get_parent_ds_cache_signature(SESSION_ID,dsSessionP);const cache_key=`${SESSION_ID}:${signature}`;if(func.runtime.render.parent_ds_field_names_cache.has(cache_key)){return func.runtime.render.parent_ds_field_names_cache.get(cache_key)}const fields=Object.keys(func.runtime.render.get_parent_ds_fields(SESSION_ID,dsSessionP));return func.runtime.render.set_small_cache_entry(func.runtime.render.parent_ds_field_names_cache,cache_key,fields)};func.runtime.render.get_xu_render_exclude_fields=function($elm){const fields_obj=func.runtime.ui.get_data($elm)?.xuData?.attr_exp_info?.["xu-render"]?.fields;if(!fields_obj){return[]}if(func.runtime.render.xu_render_exclude_fields_cache.has(fields_obj)){return func.runtime.render.xu_render_exclude_fields_cache.get(fields_obj)}const fields=Object.keys(fields_obj);func.runtime.render.xu_render_exclude_fields_cache.set(fields_obj,fields);return fields};func.runtime.render.get_xu_render_cache_str=async function(SESSION_ID,dsSessionP,exclude_vars=[]){const exclude_key=[...exclude_vars].sort().join("|");const signature=func.runtime.render.get_parent_ds_cache_signature(SESSION_ID,dsSessionP);const cache_key=`${SESSION_ID}:${signature}:${exclude_key}`;if(func.runtime.render.xu_render_cache_str_cache.has(cache_key)){return func.runtime.render.xu_render_cache_str_cache.get(cache_key)}const fields_obj=func.runtime.render.get_parent_ds_fields(SESSION_ID,dsSessionP);const exclude_vars_set=new Set(exclude_vars);let str="";const field_keys=Object.keys(fields_obj);for(let index=0;index<field_keys.length;index++){const key=field_keys[index];const val=fields_obj[key];if(exclude_vars_set.has(key))continue;str+=typeof val!=="undefined"?JSON.stringify(val):""}const cache_str="C-"+await func.common.sha256(str);return func.runtime.render.set_small_cache_entry(func.runtime.render.xu_render_cache_str_cache,cache_key,cache_str)};func.runtime.render.has_parent_field_dependency=function($div,parent_fields=[],dependency_fields=null){if(!parent_fields?.length){return false}const parent_field_set=new Set(parent_fields);if(dependency_fields?.length){for(let index=0;index<dependency_fields.length;index++){if(parent_field_set.has(dependency_fields[index])){return true}}return false}if(!$div?.length){return false}const descendants=func.runtime.render.get_runtime_descendants($div);for(let index=0;index<descendants.length;index++){const elm_data=func.runtime.ui.get_data(descendants[index]);const dependency_store=elm_data?.xuData?.refresh_dependency_by_attr;if(dependency_store){const attr_keys=Object.keys(dependency_store);for(let attr_index=0;attr_index<attr_keys.length;attr_index++){const fields=dependency_store[attr_keys[attr_index]]||[];for(let field_index=0;field_index<fields.length;field_index++){if(parent_field_set.has(fields[field_index])){return true}}}continue}const xu_attributes=elm_data?.xuAttributes;if(!xu_attributes){continue}const attr_keys=Object.keys(xu_attributes);for(let attr_index=0;attr_index<attr_keys.length;attr_index++){const attr_val=xu_attributes[attr_keys[attr_index]];if(typeof attr_val!=="string"){continue}for(let field_index=0;field_index<parent_fields.length;field_index++){if(attr_val.includes("@"+parent_fields[field_index])){return true}}}}return false};func.runtime.render.finalize_buffered_draw=async function(options){const xu_ui_id=func.runtime.ui.get_attr(options.$div,"xu-ui-id");if(options.ret.has_xu_exp_render_attribute){const exclude_fields=func.runtime.render.get_xu_render_exclude_fields(options.$div);const xu_render_cache_id=await func.runtime.render.get_xu_render_cache_str(options.SESSION_ID,options.paramsP.dsSessionP,exclude_fields);const _$div=func.runtime.ui.get_first_node(options.$div)?.cloneNode(true);func.runtime.render.cache_xu_render(xu_ui_id+xu_render_cache_id,{$div:_$div,paramsP:options.paramsP,data:func.runtime.ui.get_data(_$div)});options.nodeP.xu_render_xu_ui_id=xu_ui_id;options.nodeP.xu_render_cache_id=xu_render_cache_id}return func.runtime.render.finalize_temp_draw(options.temp_$div,options.$div,options.ret)};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.viewport_observers=func.runtime.render.viewport_observers||null;func.runtime.render.style_tag_cache=func.runtime.render.style_tag_cache||new Set;func.runtime.render.finalize_temp_draw=function(temp_$div,$div,ret={}){func.runtime.ui.remove_class($div,"display_none");if(ret.consume_placeholder){func.runtime.ui.remove(temp_$div);return $div}if(ret.xu_render_background_processing||ret.has_xu_render_attribute){func.runtime.ui.remove(temp_$div);return $div}func.runtime.ui.replace_with(temp_$div,$div);return $div};func.runtime.render.get_viewport_observers=function(){if(func.runtime.render.viewport_observers){return func.runtime.render.viewport_observers}const observer_inViewport=new IntersectionObserver(function(entries){entries.forEach(entry=>{if(entry.isIntersecting){entry.target.dispatchEvent(new CustomEvent("inViewport"));observer_inViewport.unobserve(entry.target)}})},{threshold:.1});const observer_outViewport=new IntersectionObserver(function(entries){entries.forEach(entry=>{if(!entry.isIntersecting){entry.target.dispatchEvent(new CustomEvent("outViewport"))}})},{threshold:0});func.runtime.render.viewport_observers={observer_inViewport:observer_inViewport,observer_outViewport:observer_outViewport};return func.runtime.render.viewport_observers};func.runtime.render.bind_viewport_render=function($div,handlers){const{observer_inViewport,observer_outViewport}=func.runtime.render.get_viewport_observers();const div_node=func.runtime.ui.get_first_node($div);let ui_job_id;if(div_node._xuda_inViewportHandler){div_node.removeEventListener("inViewport",div_node._xuda_inViewportHandler)}div_node._xuda_inViewportHandler=function(){ui_job_id=handlers.onEnter({observer_outViewport:observer_outViewport})};div_node.addEventListener("inViewport",div_node._xuda_inViewportHandler);if(div_node._xuda_outViewportHandler){div_node.removeEventListener("outViewport",div_node._xuda_outViewportHandler)}div_node._xuda_outViewportHandler=function(){handlers.onExit({observer_inViewport:observer_inViewport,ui_job_id:ui_job_id})};div_node.addEventListener("outViewport",div_node._xuda_outViewportHandler);func.runtime.ui.add_class($div,"skeleton");observer_inViewport.observe(div_node);return $div};func.runtime.render.has_terminal_content_attributes=function(nodeP){return!xu_isEmpty(nodeP?.attributes?.["xu-text"])||!xu_isEmpty(nodeP?.attributes?.["xu-html"])||!xu_isEmpty(nodeP?.attributes?.["xu-exp:xu-text"])||!xu_isEmpty(nodeP?.attributes?.["xu-exp:xu-html"])};func.runtime.render.should_stop_after_attributes=function(nodeP,ret={}){return!!(ret.abort||nodeP.tagName==="svg"||func.runtime.render.has_terminal_content_attributes(nodeP))};func.runtime.render.should_use_viewport_render=function(nodeP){return nodeP?.attributes?.["xu-viewport"]=="true"};func.runtime.render.bind_draw_viewport=function(options){const div_node=func.runtime.ui.get_first_node(options.$div);func.runtime.render.bind_viewport_render(options.$div,{onEnter:({observer_outViewport})=>{if(div_node?.childElementCount){func.runtime.ui.remove_class(options.$div,"skeleton");return null}options.hover_in(options.$div);const ui_job_id=func.UI.worker.add_to_queue(options.SESSION_ID,"gui event","render_viewport",{$div:options.$div,nodeP:options.nodeP,parent_infoP:options.parent_infoP,$root_container:options.$root_container,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,keyP:options.keyP,refreshed_ds:options.refreshed_ds,parent_nodeP:options.parent_nodeP,check_existP:options.check_existP,$container:options.render_container},null,null,options.paramsP.dsSessionP);observer_outViewport.observe(div_node);return ui_job_id},onExit:({observer_inViewport,ui_job_id})=>{func.UI.worker.delete_job(options.SESSION_ID,ui_job_id);if(div_node?.childElementCount){func.runtime.ui.empty(options.$div);const height=func.runtime.ui.get_data(options.$div)?.xuData?.viewport_height||10;if(typeof height!=="undefined"){func.runtime.ui.set_style(options.$div,"height",`${height}px`)}}observer_inViewport.observe(div_node)}});return options.$div};func.runtime.render.process_post_attribute_children=async function(options){if(func.runtime.render.should_use_viewport_render(options.nodeP)){return func.runtime.render.bind_draw_viewport(options)}if(options.defer_when_background&&options.ret?.xu_render_background_processing){return options.$div}if(options.await_children){await options.iterate_child(options.$div,options.nodeP,options.parent_infoP,options.$root_container);return options.$div}options.iterate_child(options.$div,options.nodeP,options.parent_infoP,options.$root_container);return options.$div};func.runtime.render.append_style_tag=function(cssText){if(!cssText||func.runtime.render.style_tag_cache.has(cssText)){return false}func.runtime.render.style_tag_cache.add(cssText);const style_node=document.createElement("style");style_node.textContent=cssText;document.head.appendChild(style_node);return true};func.runtime.render.scope_css_to_xu_ui=function($elm,cssText){var parser=new cssjs;var parsed=parser.parseCSS(cssText);var xuUiId=`[xu-ui-id="${func.runtime.ui.get_attr($elm,"xu-ui-id")}"]`;for(var key=0;key<parsed.length;key++){var val=parsed[key];var selectors_arr=val.selector.split(",");for(var key2=0;key2<selectors_arr.length;key2++){selectors_arr[key2]=`${xuUiId} ${selectors_arr[key2]}, ${xuUiId}${selectors_arr[key2]}`}val.selector=selectors_arr.join(",")}return parser.getCSSForEditor(parsed)};func.runtime.render.bind_xu_event=function(options){const decode_html_entities=function(value){if(typeof value!=="string"||value.indexOf("&")===-1){return value}if(typeof document!=="undefined"){const textarea=document.createElement("textarea");textarea.innerHTML=value;return textarea.value}return value.replaceAll("&quot;",'"').replaceAll("&#34;",'"').replaceAll("&#39;","'").replaceAll("&#039;","'").replaceAll("&lt;","<").replaceAll("&gt;",">").replaceAll("&amp;","&")};const normalize_event_handlers=function(raw_handlers){if(typeof raw_handlers!=="string"){return raw_handlers}const decoded_value=decode_html_entities(raw_handlers).trim();if(!decoded_value){return[]}try{return JSON5.parse(decoded_value)}catch(error){console.error("XUDA RUNTIME",`xu-on has invalid workflow syntax: ${decoded_value}`,error);return[]}};CLIENT_ACTIVITY_TS=Date.now();const trigger=options.val.key.split("xu-on:")[1].toLowerCase();const handler_key=`_xuda_xuOn_${trigger.replace(/[^a-z0-9_]/gi,"_")}`;const elm_node=func.runtime.ui.get_first_node(options.$elm);if(elm_node[handler_key]){elm_node.removeEventListener(trigger,elm_node[handler_key])}elm_node[handler_key]=async function(evt){const _$elm=evt.currentTarget;const elm_data=func.runtime.ui.get_data(_$elm);const xuAttributes=elm_data?.xuAttributes;const event_attr_key="xu-on:"+evt.type;const event_handlers=normalize_event_handlers(xuAttributes?.[event_attr_key]);if(xuAttributes&&event_handlers!==xuAttributes?.[event_attr_key]){xuAttributes[event_attr_key]=event_handlers}if(xu_isEmpty(xuAttributes)||xu_isEmpty(event_handlers))return;const handler_keys=Object.keys(event_handlers);for(let handler_index=0;handler_index<handler_keys.length;handler_index++){const val=event_handlers[handler_keys[handler_index]];const handler_props=val?.props||{};if(!xu_isEmpty(handler_props.condition)){const expCond=await func.expression.get(options.SESSION_ID,handler_props.condition,options.paramsP.dsSessionP,"condition",options.paramsP.recordid);if(!expCond.result)continue}if(val?.event_modifiers&&evt[val.event_modifiers]){evt[val.event_modifiers]()}const workflow=val?.workflow||val?.event;if(workflow){const workflow_keys=Object.keys(workflow);for(let workflow_index=0;workflow_index<workflow_keys.length;workflow_index++){const val2=workflow[workflow_keys[workflow_index]];if(!val2?.data?.action)continue;if(val2.data.enabled===false)continue;func.events.add_to_queue(options.SESSION_ID,"element event",val2.id,evt.type,val2.data.action,val2.data.name,null,func.runtime.ui.get_attr(_$elm,"xu-ui-id"),null,evt,null,null,null,options.paramsP.dsSessionP,null,null,null,evt.type,val2.data.name,null,null,val2,null,null,null,null,null,null)}}}};elm_node.addEventListener(trigger,elm_node[handler_key]);return options.$elm};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.should_bind_hover_click=function(paramsP,parent_infoP){return paramsP.paramsP==="grid"||!!parent_infoP?.iterate_info};func.runtime.render.create_hover_handlers=function(options){return{hover_in:function($div,e){return func.runtime.render.handle_hover_in({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,e:e,$div:$div,$container:options.$container,_ds:options._ds,paramsP:options.paramsP})},hover_out:function(){return func.runtime.render.handle_hover_out({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$container:options.$container,_ds:options._ds})}}};func.runtime.render.bind_hover_handlers=function($div,handlers,include_click){const el=func.runtime.ui.get_first_node($div);if(!el)return $div;el.addEventListener("mouseenter",function(e){handlers.hover_in($div,e)});el.addEventListener("mouseleave",function(){handlers.hover_out()});if(include_click){el.addEventListener("click",function(e){handlers.hover_in($div,e)});el.addEventListener("contextmenu",function(e){handlers.hover_in($div,e)})}return $div};func.runtime.render.resolve_debug_element=function($elm){try{const el=func.runtime.ui.get_first_node($elm);const id=el?.getAttribute?.("xu-ui-id");if(!id||!glb.DEBUG_MODE){return $elm}const matches=document.querySelectorAll(`[xu-ui-id="${id}"]`);if(matches.length>1){console.warn("Multiple elements for xu-ui-id: "+id,matches)}return matches[0]||$elm}catch(e){console.error(e);return $elm}};func.runtime.render.set_hover_item=function($container,$target){const resolved_container=func.runtime.render.resolve_debug_element($container);const resolved_data=func.runtime.ui.get_data(resolved_container);if(!resolved_data?.xuData?.debug_info){return false}const target_el=func.runtime.ui.get_first_node($target);resolved_data.xuData.debug_info.hover_item=target_el?.getAttribute?.("xu-ui-id")||null;return true};func.runtime.render.get_element_attributes=function($div){let attributes={};const el=func.runtime.ui.get_first_node($div);const attrs=el?.attributes||[];for(let index=0;index<attrs.length;index++){const attr=attrs[index];attributes[attr.name]=attr.value}return attributes};func.runtime.render.set_hovered_attributes=function(SESSION_ID,attributes){const root_data_system=func.runtime.render.get_root_data_system(SESSION_ID);if(!root_data_system){return false}root_data_system.SYS_OBJ_WIN_ELEMENT_HOVERED_ATTRIBUTES=attributes;return true};func.runtime.render.clear_hovered_attributes=function(SESSION_ID){return func.runtime.render.set_hovered_attributes(SESSION_ID,{})};func.runtime.render.queue_datasource_update=function(SESSION_ID,dsSessionP,currentRecordId,field_id,field_value){const payload={currentRecordId:currentRecordId};if(typeof field_id!=="undefined"){payload.field_id=field_id;payload.field_value=field_value}func.UI.worker.add_to_queue(SESSION_ID,"gui event","update_datasource",payload,null,null,dsSessionP);return payload};func.runtime.render.queue_hover_updates=function(options){const resolved_div=func.runtime.render.resolve_debug_element(options.$div);const resolved_data=func.runtime.ui.get_data(resolved_div);const currentRecordId=resolved_data?.xuData?.currentRecordId;if(options.$div&&resolved_div&&options._ds&&options.paramsP.renderType==="grid"&&currentRecordId){func.runtime.render.queue_datasource_update(options.SESSION_ID,options.paramsP.dsSessionP,currentRecordId)}const div_data=func.runtime.ui.get_data(options.$div);const iterate_info=div_data?.xuData?.iterate_info||div_data?.iterate_info;if(!iterate_info||!currentRecordId){return false}if(iterate_info.iterator_key){func.runtime.render.queue_datasource_update(options.SESSION_ID,options.paramsP.dsSessionP,currentRecordId,iterate_info.iterator_key,iterate_info._key)}if(iterate_info.iterator_val){func.runtime.render.queue_datasource_update(options.SESSION_ID,options.paramsP.dsSessionP,currentRecordId,iterate_info.iterator_val,iterate_info._val)}return true};func.runtime.render.handle_hover_in=function(options){if(options.is_skeleton||options.e&&(EXP_BUSY||UI_WORKER_OBJ.active_jobs_count)){return false}CLIENT_ACTIVITY_TS=Date.now();const $target=options.$div||options.$container;func.runtime.render.set_hover_item(options.$container,$target);if(!options._ds){return true}func.runtime.render.set_hovered_attributes(options.SESSION_ID,func.runtime.render.get_element_attributes($target));const target_data=func.runtime.ui.get_data($target);if(!target_data?.xuData){return true}const iterate_info=target_data.xuData.iterate_info;func.runtime.render.sync_iterate_info_to_dataset(options._ds,iterate_info);func.runtime.render.queue_hover_updates({SESSION_ID:options.SESSION_ID,paramsP:options.paramsP,$div:$target,_ds:options._ds});return true};func.runtime.render.handle_hover_out=function(options){if(options.is_skeleton){return false}CLIENT_ACTIVITY_TS=Date.now();func.runtime.render.set_hover_item(options.$container,null);if(options._ds?.data_system){func.runtime.render.clear_hovered_attributes(options.SESSION_ID);return true}return false};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.widgets.render_node=async function(options){const exist_elm_obj=func.runtime.render.find_existing_element({$container:options.$container,nodeP:options.nodeP,keyP:options.keyP,render_context:options.render_context});let $div=exist_elm_obj.div;if(!$div){$div=await func.runtime.ui.create_container({SESSION_ID:options.SESSION_ID,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,treeP:options.treeP,parent_nodeP:options.parent_nodeP,prop:options.prop,classP:"widget_wrapper"});if(func.runtime.render.is_hydration_mode(SESSION_OBJ?.[options.SESSION_ID])&&func.runtime.render.should_use_ssr_payload(options.SESSION_ID,options.paramsP)){func.runtime.ui.empty($div)}const widget_context=func.runtime.widgets.create_context(options.SESSION_ID,options.paramsP,options.prop);const{plugin_name,method,propsP,plugin:_plugin}=widget_context;const report_error=function(descP,warn){return func.runtime.widgets.report_error(widget_context,descP,warn)};const definition=await func.runtime.widgets.get_definition(widget_context);if(!func.runtime.widgets.supports_current_environment(definition)){return report_error(`plugin ${plugin_name} is not available in the current environment`,true)}const methods=definition?.methods||{};if(methods&&!methods[method]){return report_error("method not found")}const fields_ret=await func.runtime.widgets.get_fields_data(widget_context,methods[method].fields,propsP);if(fields_ret.code<0){return report_error(fields_ret.data)}const fields=fields_ret.data;let exclude_attributes=[];const prop_keys=Object.keys(propsP||{});for(let prop_index=0;prop_index<prop_keys.length;prop_index++){const key=prop_keys[prop_index];if(typeof fields[key]!=="undefined"||typeof fields[`xu-exp:${key}`]!=="undefined"){exclude_attributes.push(key)}}await func.runtime.render.set_attributes_new({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$elm:$div,is_init:true,execute_attributes:exclude_attributes});func.runtime.ui.add_class($div,"widget_wrapper");if(!_plugin){return report_error(`plugin ${plugin_name} not found`)}if(_plugin.manifest["style.css"].exist){func.runtime.widgets.load_css_style(widget_context)}const plugin_setup_ret=await func.utils.get_plugin_setup(options.SESSION_ID,plugin_name);if(plugin_setup_ret.code<0){return report_error(plugin_setup_ret)}const api_utils=await func.common.get_module(options.SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:options.SESSION_ID,APP_OBJ:APP_OBJ,dsSession:options.paramsP.dsSessionP,job_id:options.jobNoP});const params=func.runtime.widgets.build_params(widget_context,func.runtime.ui.get_first_node($div),func.runtime.ui.get_data($div),plugin_setup_ret.data,api_utils);const fx=await func.runtime.widgets.get_resource(widget_context,"runtime.mjs");await func.runtime.widgets.load_runtime_css(widget_context);if(!fx[method]){throw`Method: ${method} does not exist`}try{await fx[method](fields,params)}catch(err){func.utils.debug_report(options.SESSION_ID,`${plugin_name} widget`,err.message,"E")}}return $div};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};const normalize_runtime_tag_name=function(tag_name){return`${tag_name||""}`.trim().toLowerCase()};const get_runtime_node_attributes=function(nodeP){if(!nodeP?.attributes||typeof nodeP.attributes!=="object"){return{}}return nodeP.attributes};const get_runtime_node_content=function(nodeP){if(typeof nodeP?.content==="string"){return nodeP.content}if(typeof nodeP?.text==="string"){return nodeP.text}if(!Array.isArray(nodeP?.children)){return""}return nodeP.children.map(function(child){if(typeof child==="string"){return child}if(typeof child?.content==="string"){return child.content}if(typeof child?.text==="string"){return child.text}return""}).join("")};const get_runtime_asset_key=function(options,tag_name){const source_node=options.treeP||options.nodeP||{};const parts=["xuda-html-asset",options.paramsP?.prog_id||"",tag_name,source_node.id||source_node.id_org||"",typeof options.keyP==="undefined"||options.keyP===null?"":`${options.keyP}`].filter(function(part){return`${part||""}`.trim()!==""});return parts.join(":")};const get_runtime_asset_signature=function(attributes,content){const normalized_attributes={};const attr_keys=Object.keys(attributes||{}).sort();for(let index=0;index<attr_keys.length;index++){const key=attr_keys[index];normalized_attributes[key]=attributes[key]}return JSON.stringify({attributes:normalized_attributes,content:`${content||""}`})};const escape_runtime_asset_selector_value=function(value){const win=func.runtime.platform.get_window?.();if(win?.CSS?.escape){return win.CSS.escape(value)}return`${value||""}`.replace(/\\/g,"\\\\").replace(/"/g,'\\"')};const find_runtime_head_asset=function(head,tag_name,asset_key){if(!head?.querySelector||!asset_key){return null}return head.querySelector(`${tag_name}[data-xuda-asset-key="${escape_runtime_asset_selector_value(asset_key)}"]`)};const find_runtime_head_asset_by_attr=function(head,tag_name,attr_name,attr_value){if(!head?.querySelectorAll||!attr_name||!attr_value){return null}const candidates=Array.from(head.querySelectorAll(tag_name));return candidates.find(function(candidate){return candidate.getAttribute(attr_name)===attr_value||candidate[attr_name]===attr_value})||null};const wait_for_runtime_asset_load=function(node){if(!node?.addEventListener){return Promise.resolve(node)}if(node.getAttribute?.("data-xuda-loaded")==="true"){return Promise.resolve(node)}if(!node.getAttribute?.("data-xuda-asset-key")){return Promise.resolve(node)}const tag_name=normalize_runtime_tag_name(node.tagName);if(tag_name!=="script"&&!(tag_name==="link"&&normalize_runtime_tag_name(node.getAttribute?.("rel"))==="stylesheet")){return Promise.resolve(node)}return new Promise(function(resolve){const done=function(){node.setAttribute?.("data-xuda-loaded","true");resolve(node)};node.addEventListener("load",done,{once:true});node.addEventListener("error",done,{once:true})})};const remove_runtime_head_asset=function(node){if(node?.parentNode?.removeChild){node.parentNode.removeChild(node)}};const apply_runtime_asset_metadata=function(node,asset_key,signature){if(!node?.setAttribute){return node}if(asset_key){node.setAttribute("data-xuda-asset-key",asset_key)}node.setAttribute("data-xuda-asset-signature",signature);return node};const create_runtime_head_element=function(doc,tag_name,attributes,asset_key,signature){const node=doc.createElement(tag_name);apply_runtime_asset_metadata(node,asset_key,signature);func.runtime.platform.apply_element_attributes(node,attributes);return node};const get_runtime_html_script_queue=function(){return func.runtime.render._html_script_queue||(func.runtime.render._html_script_queue={items:[],running:false})};const queue_runtime_html_script_task=function(task){const queue=get_runtime_html_script_queue();queue.items.push(task)};func.runtime.render.flush_html_script_queue=async function(){const queue=get_runtime_html_script_queue();if(queue.running||!queue.items.length){return}queue.running=true;try{while(queue.items.length){const next_task=queue.items.shift();await next_task()}}catch(error){console.error(error)}finally{queue.running=false}};const upsert_runtime_head_element=async function(options){const doc=func.runtime.platform.get_document?.();const head=doc?.head;const tag_name=normalize_runtime_tag_name(options.tag_name);if(!doc?.createElement||!head?.appendChild||!tag_name){return null}const asset_key=options.asset_key||"";const signature=options.signature||"";const attributes=options.attributes||{};const content=typeof options.content==="string"?options.content:"";const existing_by_key=find_runtime_head_asset(head,tag_name,asset_key);if(existing_by_key&&existing_by_key.getAttribute("data-xuda-asset-signature")===signature){return options.await_load?await wait_for_runtime_asset_load(existing_by_key):existing_by_key}if(existing_by_key){remove_runtime_head_asset(existing_by_key)}if(options.find_existing_attr?.name&&options.find_existing_attr?.value){const existing_by_attr=find_runtime_head_asset_by_attr(head,tag_name,options.find_existing_attr.name,options.find_existing_attr.value);if(existing_by_attr){apply_runtime_asset_metadata(existing_by_attr,asset_key,signature);existing_by_attr.setAttribute?.("data-xuda-loaded","true");return existing_by_attr}}const node=create_runtime_head_element(doc,tag_name,attributes,asset_key,signature);if(tag_name==="script"&&attributes.src&&!Object.prototype.hasOwnProperty.call(attributes,"async")){const script_type=normalize_runtime_tag_name(attributes.type);if(script_type!=="module"){node.async=false}}if(tag_name==="style"||tag_name==="script"&&!attributes.src){node.textContent=content}head.appendChild(node);if(tag_name!=="script"&&tag_name!=="link"){node.setAttribute("data-xuda-loaded","true")}return options.await_load?await wait_for_runtime_asset_load(node):node};const render_runtime_html_asset=async function(options){if(options.is_skeleton){return options.$container}const nodeP=options.treeP||options.nodeP||{};const tag_name=normalize_runtime_tag_name(nodeP.tagName);const attributes={...get_runtime_node_attributes(nodeP)};const content=get_runtime_node_content(nodeP);const asset_key=get_runtime_asset_key(options,tag_name);const signature=get_runtime_asset_signature(attributes,content);switch(tag_name){case"title":func.runtime.platform.set_title(content);return options.$container;case"style":await upsert_runtime_head_element({tag_name:tag_name,attributes:attributes,content:content,asset_key:asset_key,signature:signature});return options.$container;case"meta":if(!Object.keys(attributes).length){return options.$container}await upsert_runtime_head_element({tag_name:tag_name,attributes:attributes,asset_key:asset_key,signature:signature});return options.$container;case"link":{const href=`${attributes.href||""}`.trim();if(!href){return options.$container}await upsert_runtime_head_element({tag_name:tag_name,attributes:attributes,asset_key:asset_key,signature:signature,find_existing_attr:{name:"href",value:href},await_load:normalize_runtime_tag_name(attributes.rel)==="stylesheet"});return options.$container}case"script":{const src=`${attributes.src||""}`.trim();if(!src&&!content.trim()){return options.$container}queue_runtime_html_script_task(async function(){await upsert_runtime_head_element({tag_name:tag_name,attributes:attributes,content:content,asset_key:asset_key,signature:signature,find_existing_attr:src?{name:"src",value:src}:null,await_load:!!src})});return options.$container}default:return null}};func.runtime.render.render_special_node=async function(options){const treeP=options.treeP||null;const nodeP=options.nodeP||func.runtime.render.get_tree_source_node(treeP);const render_tag_name=treeP?.tagName||nodeP?.tagName;const normalized_render_tag_name=normalize_runtime_tag_name(render_tag_name);const is_native_html_asset=["title","style","meta","link","script"].includes(normalized_render_tag_name);if(!is_native_html_asset&&treeP?.content&&nodeP?.attributes){nodeP.attributes["xu-content"]=treeP.content}else if(!is_native_html_asset&&nodeP?.content&&nodeP.attributes){nodeP.attributes["xu-content"]=nodeP.content}const renderers={"xu-widget":async function(){if(options.is_skeleton)return;return await func.runtime.widgets.render_node({SESSION_ID:options.SESSION_ID,$container:options.$container,$root_container:options.$root_container,treeP:treeP,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,keyP:options.keyP,parent_nodeP:options.parent_nodeP,prop:options.prop,render_context:options.render_context})},"xu-single-view":async function(){return await func.runtime.ui.render_single_view_node({SESSION_ID:options.SESSION_ID,$container:options.$container,$root_container:options.$root_container,treeP:treeP,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,keyP:options.keyP,parent_nodeP:options.parent_nodeP,prop:options.prop,render_context:options.render_context,hover_handlers:options.hover_handlers,iterate_child:options.iterate_child,close_modal:options.close_modal})},"xu-multi-view":async function(){return await func.runtime.ui.render_multi_view_node({SESSION_ID:options.SESSION_ID,$container:options.$container,$root_container:options.$root_container,treeP:treeP,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,keyP:options.keyP,parent_nodeP:options.parent_nodeP,iterate_child:options.iterate_child,close_modal:options.close_modal})},"xu-panel":async function(){return await func.runtime.ui.render_panel_node({SESSION_ID:options.SESSION_ID,$container:options.$container,$root_container:options.$root_container,treeP:treeP,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,keyP:options.keyP,parent_nodeP:options.parent_nodeP,prop:options.prop,refreshed_ds:options.refreshed_ds})},title:async function(){return await render_runtime_html_asset(options)},style:async function(){return await render_runtime_html_asset(options)},meta:async function(){return await render_runtime_html_asset(options)},link:async function(){return await render_runtime_html_asset(options)},script:async function(){return await render_runtime_html_asset(options)}};const renderer=renderers[normalized_render_tag_name];if(!renderer){return{handled:false}}return{handled:true,result:await renderer()}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.get_xu_for_iterators=function($elm){const elm_data=func.runtime.ui.get_data($elm);const custom_iterator_key=elm_data.xuData.iterator_key;const custom_iterator_val=elm_data.xuData.iterator_val;return{iterator_key:custom_iterator_key||"_FOR_KEY",iterator_val:custom_iterator_val||"_FOR_VAL",is_key_dynamic_field:true,is_val_dynamic_field:true}};func.runtime.render.attach_iterate_info_to_children=function($divP,iterate_info){const el=func.runtime.ui.get_first_node($divP);const children=el?.children?Array.from(el.children):[];for(let index=0;index<children.length;index++){const child_data=func.runtime.ui.get_data(children[index]);if(child_data?.xuData){child_data.xuData.iterate_info=iterate_info}}return $divP};func.runtime.render.can_iterate_children=function(nodeP,is_mobile){if(!nodeP){return false}if(!is_mobile&&nodeP.busy){return false}return true};func.runtime.render.mark_node_busy=function(nodeP){if(!nodeP){return false}nodeP.busy=true;return true};func.runtime.render.release_node_busy=function(nodeP,delay=1e3){if(!nodeP){return false}setTimeout(function(){nodeP.busy=false},delay);return true};func.runtime.render.render_child_nodes=async function(options){if(!options.nodeP?.children){return options.$divP}if(options.before_record_function){await options.before_record_function()}if(options.nodeP.children.length){const render_tasks=new Array(options.nodeP.children.length);for(let index=0;index<options.nodeP.children.length;index++){const child=options.nodeP.children[index];render_tasks[index]=options.render_child(index,child)}await Promise.all(render_tasks)}return options.$divP};func.runtime.render.iterate_children=async function(options){if(!func.runtime.render.can_iterate_children(options.nodeP,options.is_mobile))return;func.runtime.render.mark_node_busy(options.nodeP);const done=async function($divP){func.runtime.render.release_node_busy(options.nodeP);return $divP};if(!options.nodeP||!options.nodeP.children){return await done(options.$divP)}await func.runtime.render.render_child_nodes({$divP:options.$divP,nodeP:options.nodeP,before_record_function:options.before_record_function,render_child:options.render_child});return await done(options.$divP)};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.create_tree_runtime=function(options){const render_node=options.nodeP||func.runtime.render.get_tree_source_node(options.treeP);const render_context=func.runtime.render.get_screen_context(options.SESSION_ID,options.$container,options.paramsP,options.is_skeleton);const prop=func.runtime.render.get_node_attributes(options.treeP||render_node);const is_mobile=render_context.is_mobile?true:false;const hover_handlers=func.runtime.render.create_hover_handlers({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$container:options.$container,_ds:render_context._ds,paramsP:options.paramsP});const include_hover_click=func.runtime.render.should_bind_hover_click(options.paramsP,options.parent_infoP);const close_modal=async function(modal_id){return await func.runtime.ui.close_modal_session(options.SESSION_ID,modal_id)};const iterate_child=async function($divP,nodeP,parent_infoP,$root_container,before_record_function){const child_tree=await func.runtime.render.ensure_tree_node({SESSION_ID:options.SESSION_ID,nodeP:nodeP||options.treeP||render_node,parent_infoP:parent_infoP,paramsP:options.paramsP,keyP:options.keyP,parent_nodeP:render_node,pathP:options.treeP?.meta?.path||[]});return await func.runtime.render.iterate_children({$divP:$divP,nodeP:child_tree,is_mobile:is_mobile,before_record_function:before_record_function,render_child:async function(key,child){await options.render_child($divP,child,parent_infoP,key,render_node,$root_container)}})};return{render_context:render_context,prop:prop,is_mobile:is_mobile,hover_handlers:hover_handlers,include_hover_click:include_hover_click,close_modal:close_modal,iterate_child:iterate_child}};func.runtime.render.draw_node=async function(options){const draw_ret=await func.runtime.render.run_draw_pipeline({SESSION_ID:options.SESSION_ID,$container:options.$container,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,keyP:options.keyP,refreshed_ds:options.refreshed_ds,parent_nodeP:options.parent_nodeP,check_existP:options.check_existP,$root_container:options.$root_container,prop:options.prop,element:options.treeP?.tagName||options.nodeP.tagName,hover_handlers:options.hover_handlers,include_hover_click:options.include_hover_click,iterate_child:options.iterate_child,buffered:!!glb.new_xu_render});if(!glb.new_xu_render){return draw_ret.$div}if(!draw_ret.$div){return draw_ret.$div}return await func.runtime.render.finalize_buffered_draw({SESSION_ID:options.SESSION_ID,$div:draw_ret.$div,temp_$div:draw_ret.temp_$div,ret:draw_ret.ret,paramsP:options.paramsP,nodeP:options.nodeP})};func.runtime.render.render_tree=async function(treeP,renderer_context){if(!treeP)return;const nodeP=func.runtime.render.get_tree_source_node(treeP);const perf_end=func.runtime?.perf?.start?.(renderer_context.SESSION_ID,"render_ui_tree");func.runtime?.perf?.increment_map?.(renderer_context.SESSION_ID,"render_node_counts",treeP.id||nodeP?.id||nodeP?.id_org||treeP.tagName||"unknown");try{const tree_runtime=func.runtime.render.create_tree_runtime({SESSION_ID:renderer_context.SESSION_ID,$container:renderer_context.$container,treeP:treeP,nodeP:nodeP,parent_infoP:renderer_context.parent_infoP,paramsP:renderer_context.paramsP,jobNoP:renderer_context.jobNoP,is_skeleton:renderer_context.is_skeleton,keyP:renderer_context.keyP,render_child:async function($divP,child,parent_infoP,key,parentNodeP,rootContainerP){await func.runtime.render.render_tree(child,{...renderer_context,$container:$divP,parent_infoP:parent_infoP,keyP:key,refreshed_ds:null,parent_nodeP:parentNodeP,check_existP:null,$root_container:rootContainerP})}});const render_context=tree_runtime.render_context;const _ds=render_context._ds;const prop=tree_runtime.prop;const hover_handlers=tree_runtime.hover_handlers;const include_hover_click=tree_runtime.include_hover_click;const close_modal=tree_runtime.close_modal;const iterate_child=tree_runtime.iterate_child;func.runtime.render.log_tree_debug({SESSION_ID:renderer_context.SESSION_ID,paramsP:renderer_context.paramsP,nodeP:nodeP,_ds:_ds});const special_render=await func.runtime.render.render_special_node({SESSION_ID:renderer_context.SESSION_ID,$container:renderer_context.$container,$root_container:renderer_context.$root_container,treeP:treeP,nodeP:nodeP,parent_infoP:renderer_context.parent_infoP,paramsP:renderer_context.paramsP,jobNoP:renderer_context.jobNoP,is_skeleton:renderer_context.is_skeleton,keyP:renderer_context.keyP,refreshed_ds:renderer_context.refreshed_ds,parent_nodeP:renderer_context.parent_nodeP,prop:prop,render_context:render_context,hover_handlers:hover_handlers,iterate_child:iterate_child,close_modal:close_modal});if(special_render.handled){func.runtime?.perf?.increment?.(renderer_context.SESSION_ID,"render_special_node_hits");return special_render.result}return await func.runtime.render.draw_node({SESSION_ID:renderer_context.SESSION_ID,$container:renderer_context.$container,$root_container:renderer_context.$root_container,treeP:treeP,nodeP:nodeP,parent_infoP:renderer_context.parent_infoP,paramsP:renderer_context.paramsP,jobNoP:renderer_context.jobNoP,is_skeleton:renderer_context.is_skeleton,keyP:renderer_context.keyP,refreshed_ds:renderer_context.refreshed_ds,parent_nodeP:renderer_context.parent_nodeP,check_existP:renderer_context.check_existP,prop:prop,hover_handlers:hover_handlers,include_hover_click:include_hover_click,iterate_child:iterate_child})}finally{perf_end?.()}};func.runtime.render.render_ui_tree=async function(SESSION_ID,$container,nodeP,parent_infoP,paramsP,jobNoP,is_skeleton,keyP,refreshed_ds,parent_nodeP,check_existP,$root_container){if(!nodeP)return;const treeP=await func.runtime.render.ensure_tree_node({SESSION_ID:SESSION_ID,nodeP:nodeP,parent_infoP:parent_infoP,paramsP:paramsP,keyP:keyP,parent_nodeP:parent_nodeP});const render_depth=func.runtime.render._html_script_render_depth||(func.runtime.render._html_script_render_depth={});render_depth[SESSION_ID]=(render_depth[SESSION_ID]||0)+1;try{return await func.runtime.render.render_tree(treeP,{SESSION_ID:SESSION_ID,$container:$container,parent_infoP:parent_infoP,paramsP:paramsP,jobNoP:jobNoP,is_skeleton:is_skeleton,keyP:keyP,refreshed_ds:refreshed_ds,parent_nodeP:parent_nodeP,check_existP:check_existP,$root_container:$root_container})}finally{render_depth[SESSION_ID]=Math.max((render_depth[SESSION_ID]||1)-1,0);if(render_depth[SESSION_ID]===0){await func.runtime.render.flush_html_script_queue?.();delete render_depth[SESSION_ID]}}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.normalize_node_attributes=function(nodeP){if(nodeP?.type!=="element"||!nodeP.attributes){return{}}const attributes=nodeP.attributes;const attribute_keys=Object.keys(attributes);for(let index=0;index<attribute_keys.length;index++){const key=attribute_keys[index];let val=attributes[key];if(key.substring(0,6)==="xu-exp"){if(xu_isEmpty(val)){delete attributes[key];continue}const clean_key=key.split(":")[1];if(typeof attributes[clean_key]!=="undefined"){delete attributes[clean_key]}}if(glb.attr_abbreviations_arr.includes(key)){attributes[`xu-on:${key.substring(3)}`]=[{handler:"custom",props:{},workflow:[{id:Date.now(),data:{action:"update",name:{value:val},enabled:true},props:{}}]}];delete attributes[key]}}const normalized_keys=Object.keys(attributes);for(let index=0;index<normalized_keys.length;index++){const key=normalized_keys[index];let val=attributes[key];val=func.runtime.render.fix_val_defaults(key,val);if(typeof val==="undefined"||val===null){delete attributes[key];continue}if(glb.solid_attributes.includes(key)&&!val){delete attributes[key];continue}attributes[key]=val}return attributes};func.runtime.render.get_attribute_base_key=function(key){return key.split(":")[0]};func.runtime.render.get_expression_attribute_target=function(key){return key.split("xu-exp:")[1]||""};func.runtime.render.is_native_attribute=function(nodeTag,key){const new_key=func.runtime.render.get_attribute_base_key(key);if(nodeTag==="xu-panel"||nodeTag==="xu-teleport"){return false}return!(new_key.substr(0,2)==="xu"&&new_key.substr(2,1)==="-")};func.runtime.render.should_abort=function($container,ret){return!!(ret?.abort||func.runtime.ui.get_data($container)?.xuData?.pending_to_delete)};func.runtime.render.should_skip_phase_attribute=function(attr,execute_attributes=[]){return glb.html5_events_handler.includes(attr)||execute_attributes.includes(attr)};func.runtime.render.has_attribute_or_expression=function(nodeP,attr){return!!(nodeP?.attributes?.hasOwnProperty(attr)||nodeP?.attributes?.hasOwnProperty(`xu-exp:${attr}`))};func.runtime.render.should_run_before_attribute=function(nodeP,attr){if(!func.runtime.render.has_attribute_or_expression(nodeP,attr)){return false}if(!nodeP.attributes[`xu-exp:${attr}`]&&nodeP?.attributes?.hasOwnProperty(attr)&&typeof func.runtime.render.fix_val_defaults(attr,nodeP.attributes[attr])==="undefined"){return false}return true};func.runtime.render.should_defer_runtime_attribute=function(nodeP,new_key){return new_key==="xu-exp"||nodeP.attributes["xu-exp:"+new_key]||glb.run_xu_before.includes(new_key)||glb.run_xu_after.includes(new_key)};func.runtime.render.should_run_expression_attribute=function(attr,execute_attributes=[],done_exp,key){if(!attr){return false}if(func.runtime.render.should_skip_phase_attribute(attr,execute_attributes)){return false}if(done_exp?.has&&done_exp.has(key)){return false}if(done_exp?.includes&&done_exp.includes(key)){return false}return true};func.runtime.render.should_run_after_attribute=function(nodeP,attr,execute_attributes=[]){if(func.runtime.render.should_skip_phase_attribute(attr,execute_attributes)){return false}if(!nodeP.attributes){return false}return!!(nodeP.attributes[attr]||nodeP.attributes[`xu-exp:${attr}`])};func.runtime.render.is_xu_tag=function(tagName){return typeof tagName==="string"&&tagName.substr(0,3)==="xu-"};func.runtime.render.execute_attribute=async function(options){return await func.runtime.render.execute_xu_function({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,xu_func:options.xu_func,$elm:options.$elm,$live_elm:options.$live_elm,val:options.value_obj,is_init:options.is_init,refreshed_ds:options.refreshed_ds,handler_bundle:options.handler_bundle,get_params_obj_new:func.runtime.program.get_params_obj})};func.runtime.render.set_native_dom_attribute=function($elm,key,val){try{func.runtime.ui.set_attr($elm,key,val);return true}catch(err){console.error(err.message);return false}};func.runtime.render.store_xu_attribute=function($elm,key,val){try{const elm_data=func.runtime.ui.get_data($elm);if(elm_data?.xuAttributes){elm_data.xuAttributes[key]=val;if(func.runtime.ui.update_refresh_dependency_entry){func.runtime.ui.update_refresh_dependency_entry($elm,key,val)}return true}}catch(error){debugger;console.error(error)}return false};func.runtime.render.record_attribute_stat=function($elm,key,value){const elm_data=func.runtime.ui.get_data($elm);if(!elm_data?.xuData){return false}if(!elm_data.xuData.debug_info.attribute_stat){elm_data.xuData.debug_info.attribute_stat={}}elm_data.xuData.debug_info.attribute_stat[key]=value;return true};func.runtime.render.fix_val_defaults=function(key,val){let ret=val;if(key==="xu-render"&&(typeof val==="undefined"||val===null||val==="")){ret=true}if(key==="xu-show"&&(typeof val==="undefined"||val===null||val==="")){ret=true}return ret};func.runtime.render.get_attribute_phase_plan=function(nodeP){if(nodeP?.type!=="element"||!nodeP.attributes){return{has_xu_attrs:false,before_attrs:[],attribute_entries:[],expression_entries:[],after_attrs:[]}}if(nodeP._runtime_attribute_phase_plan&&nodeP._runtime_attribute_phase_plan_source===nodeP.attributes){return nodeP._runtime_attribute_phase_plan}const attributes=nodeP.attributes||{};const attribute_entries=[];const expression_entries=[];const html_event_entries=[];const attribute_keys=Object.keys(attributes);for(let index=0;index<attribute_keys.length;index++){const key=attribute_keys[index];const val=attributes[key];const new_key=func.runtime.render.get_attribute_base_key(key);attribute_entries.push({key:key,val:val,new_key:new_key,is_native:func.runtime.render.is_native_attribute(nodeP.tagName,key),should_defer:func.runtime.render.should_defer_runtime_attribute(nodeP,new_key),xu_func:new_key==="xu-on"?"xu-on":new_key});if(glb.html5_events_handler.includes(key)){html_event_entries.push({key:key})}const exp_attr=func.runtime.render.get_expression_attribute_target(key);if(exp_attr){expression_entries.push({key:key,attr:exp_attr,val:val})}}const plan={has_xu_attrs:!!(attributes["xu-attrs"]||attributes["xu-exp:xu-attrs"]),before_attrs:glb.run_xu_before.filter(function(attr){return func.runtime.render.should_run_before_attribute(nodeP,attr)}),attribute_entries:attribute_entries,html_event_entries:html_event_entries,expression_entries:expression_entries,after_attrs:glb.run_xu_after.filter(function(attr){return func.runtime.render.has_attribute_or_expression(nodeP,attr)})};nodeP._runtime_attribute_phase_plan_source=nodeP.attributes;nodeP._runtime_attribute_phase_plan=plan;return plan};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.create_attribute_reader=function(options){const done_exp=new Set;const attr_value_cache={};const xu_exp_cache={};const elm_data=func.runtime.ui.get_data(options.$elm);const xuData=elm_data?.xuData;const get_xuExp=async function(attrib){if(Object.prototype.hasOwnProperty.call(xu_exp_cache,attrib)){return xu_exp_cache[attrib]}if(options.is_skeleton)return;if(glb.new_xu_render){if(xuData&&!xuData.attr_exp_info){xuData.attr_exp_info={}}}const attr=`xu-exp:${attrib}`;if(!options.nodeP?.attributes?.hasOwnProperty(attr))return;const exp=options.nodeP.attributes[attr];const res=await func.expression.get(options.SESSION_ID,exp,options.paramsP.dsSessionP,"UI Attr EXP",options._ds.currentRecordId);if(glb.new_xu_render&&xuData){xuData.attr_exp_info[attrib]=res}done_exp.add(attr);xu_exp_cache[attrib]=res.result;return xu_exp_cache[attrib]};const get_attr_value=async function(key){if(Object.prototype.hasOwnProperty.call(attr_value_cache,key)){return attr_value_cache[key]}let ret=func.runtime.render.fix_val_defaults(key,options.nodeP.attributes[key]);if(options.nodeP?.attributes?.hasOwnProperty(`xu-exp:${key}`)){ret=await get_xuExp(key)}attr_value_cache[key]=ret;return attr_value_cache[key]};return{done_exp:done_exp,get_attr_value:get_attr_value}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.apply_attribute_phases=async function(options){let _ret={};if(options.nodeP.type!=="element"||!options.nodeP.attributes)return _ret;func.runtime.render.normalize_node_attributes(options.nodeP);const phase_plan=func.runtime.render.get_attribute_phase_plan(options.nodeP);if(phase_plan.has_xu_attrs){const attr="xu-attrs";await func.runtime.render.execute_attribute({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,xu_func:attr,$elm:options.$elm,$live_elm:options.$live_elm,value_obj:{key:attr,value:await options.get_attr_value(attr)},is_init:options.is_init,handler_bundle:options.handler_bundle})}if(!xu_isEmpty(options.nodeP.attributes)){for(let index=0;index<phase_plan.before_attrs.length;index++){const attr=phase_plan.before_attrs[index];if(func.runtime.render.should_abort(options.$container,_ret))break;if(func.runtime.render.should_skip_phase_attribute(attr,options.execute_attributes))continue;const ret=await func.runtime.render.execute_attribute({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,xu_func:attr,$elm:options.$elm,$live_elm:options.$live_elm,value_obj:{key:attr,value:await options.get_attr_value(attr)},is_init:options.is_init,handler_bundle:options.handler_bundle});_ret=Object.assign(_ret,ret)}}for(let index=0;index<phase_plan.attribute_entries.length;index++){const entry=phase_plan.attribute_entries[index];const key=entry.key;const val=entry.val;if(func.runtime.render.should_abort(options.$container,_ret))break;if(func.runtime.render.should_skip_phase_attribute(key,options.execute_attributes))continue;if(entry.is_native){func.runtime.render.set_native_dom_attribute(options.$elm,key,val);continue}func.runtime.render.store_xu_attribute(options.$elm,key,val);if(entry.should_defer){continue}if(entry.new_key==="xu-on"){const ret=await func.runtime.render.execute_attribute({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,xu_func:"xu-on",$elm:options.$elm,$live_elm:options.$live_elm,value_obj:{key:key,value:await options.get_attr_value(key)},is_init:options.is_init,refreshed_ds:options.refreshed_ds,handler_bundle:options.handler_bundle});_ret=Object.assign(_ret,ret);continue}const ret=await func.runtime.render.execute_attribute({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,xu_func:entry.xu_func,$elm:options.$elm,$live_elm:options.$live_elm,value_obj:{key:key,value:await options.get_attr_value(key)},is_init:options.is_init,refreshed_ds:options.refreshed_ds,handler_bundle:options.handler_bundle});_ret=Object.assign(_ret,ret)}for(let index=0;index<phase_plan.expression_entries.length;index++){const entry=phase_plan.expression_entries[index];const key=entry.key;const val=entry.val;if(func.runtime.render.should_abort(options.$container,_ret))break;const attr=entry.attr;if(!func.runtime.render.should_run_expression_attribute(attr,options.execute_attributes,options.done_exp,key)){continue}const ret=await func.runtime.render.execute_attribute({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,xu_func:"xu-exp",$elm:options.$elm,$live_elm:options.$live_elm,value_obj:{key:attr,value:val},is_init:true,refreshed_ds:options.refreshed_ds,handler_bundle:options.handler_bundle});_ret=Object.assign(_ret,ret)}for(let index=0;index<phase_plan.after_attrs.length;index++){const attr=phase_plan.after_attrs[index];if(func.runtime.render.should_abort(options.$container,_ret))break;if(!func.runtime.render.should_run_after_attribute(options.nodeP,attr,options.execute_attributes))continue;const ret=await func.runtime.render.execute_attribute({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,xu_func:attr,$elm:options.$elm,$live_elm:options.$live_elm,value_obj:{key:attr,value:await options.get_attr_value(attr)},is_init:options.is_init,refreshed_ds:options.refreshed_ds,handler_bundle:options.handler_bundle});_ret=Object.assign(_ret,ret)}return _ret};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.normalize_set_attributes_options=function(...args){if(typeof args[0]==="object"&&args[0]!==null&&!Array.isArray(args[0])){return{...args[0],$live_elm:args[0].$live_elm||args[0].$elm}}const[SESSION_ID,is_skeleton,$root_container,nodeP,$container,paramsP,parent_infoP,jobNoP,keyP,parent_nodeP,$elm,is_init,execute_attributes=[],refreshed_ds]=args;return{SESSION_ID:SESSION_ID,is_skeleton:is_skeleton,$root_container:$root_container,nodeP:nodeP,$container:$container,paramsP:paramsP,parent_infoP:parent_infoP,jobNoP:jobNoP,keyP:keyP,parent_nodeP:parent_nodeP,$elm:$elm,$live_elm:$elm,is_init:is_init,execute_attributes:execute_attributes,refreshed_ds:refreshed_ds}};func.runtime.render.set_attributes_new=async function(...args){const options=func.runtime.render.normalize_set_attributes_options(...args);const _ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[options.paramsP.dsSessionP];if(!_ds)return{abort:true};if(func.runtime.ui.prune_stale_refresh_dependencies){func.runtime.ui.prune_stale_refresh_dependencies(options.$elm,options.nodeP?.attributes||{})}const attr_reader=func.runtime.render.create_attribute_reader({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$elm:options.$elm,nodeP:options.nodeP,paramsP:options.paramsP,_ds:_ds});const handler_bundle=func.runtime.render.build_xu_handlers({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$elm:options.$elm,$live_elm:options.$live_elm,is_init:options.is_init,refreshed_ds:options.refreshed_ds,get_params_obj_new:func.runtime.program.get_params_obj},_ds);const _ret=await func.runtime.render.apply_attribute_phases({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$elm:options.$elm,$live_elm:options.$live_elm,is_init:options.is_init,execute_attributes:options.execute_attributes||[],refreshed_ds:options.refreshed_ds,done_exp:attr_reader.done_exp,get_attr_value:attr_reader.get_attr_value,handler_bundle:handler_bundle});const phase_plan=func.runtime.render.get_attribute_phase_plan(options.nodeP);for(let index=0;index<phase_plan.html_event_entries.length;index++){const key=phase_plan.html_event_entries[index].key;if(func.runtime.render.should_abort(options.$container,_ret))break;func.runtime.ui.set_attr(options.$elm,key,await attr_reader.get_attr_value(key))}return _ret};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.handle_xu_ref=async function(options){if(!options.val.value){return{}}func.UI.update_xu_ref(options.SESSION_ID,options.dsSession||options.paramsP.dsSessionP,options.val.value,options.$elm);const targetNode=func.runtime.ui.get_first_node(options.$elm);if(!targetNode){return{}}const target_data=func.runtime.ui.get_data(options.$elm);if(target_data?.xuData?.xu_ref_observer){target_data.xuData.xu_ref_observer.disconnect()}const observer=new MutationObserver(()=>{func.runtime.ui.refresh_xu_attributes({SESSION_ID:options.SESSION_ID,fields_arr:[options.val.value]})});observer.observe(targetNode,{attributes:true,childList:true,subtree:true});if(target_data?.xuData){target_data.xuData.xu_ref_observer=observer}return{}};func.runtime.render.handle_xu_bind=async function(options){if(options.is_skeleton)return{};const $elm=func.runtime?.ui?.get_preferred_live_element?func.runtime.ui.get_preferred_live_element(options.$elm):options.$elm;const elm_data=func.runtime.ui.get_data($elm);const xuData=elm_data?.xuData;const bind_expression=typeof options?.val?.value==="string"?options.val.value:elm_data?.xuAttributes?.["xu-bind"]||func.runtime.ui.get_attr($elm,"xu-bind");if(!xuData?.paramsP){return{}}if(!bind_expression){return{}}let val_is_reference_field=false;let _prog_id=xuData.paramsP.prog_id;let _dsP=xuData.paramsP.dsSessionP;let is_dynamic_field=false;let field_prop;let bind_field_id;const _bind_elm_node=func.runtime.ui.get_first_node($elm);const input_field_type=_bind_elm_node?.type||func.runtime.ui.get_attr($elm,"type");const bind_ui_id=xuData.ui_id||func.runtime.ui.get_attr($elm,"xu-ui-id");const get_bind_targets=function(){const $root=func.runtime.ui.get_refresh_index_root?.(options.SESSION_ID)||func.runtime.ui.get_root_element?.(options.SESSION_ID)||func.runtime.ui._wrap_matches([document.body]);const live_targets=[];const seen_nodes=new Set;const add_candidate=function(node){if(!node||seen_nodes.has(node)){return}const target_data=func.runtime.ui.get_data(node);if(!node.isConnected||target_data?.xuData?.pending_to_delete){return}seen_nodes.add(node);live_targets.push(node)};if(bind_ui_id&&options.SESSION_ID&&func.runtime?.ui?.find_refresh_elements_by_attr){const ui_id_targets=func.runtime.ui.find_refresh_elements_by_attr($root,"xu-ui-id",bind_ui_id).toArray();for(let index=0;index<ui_id_targets.length;index++){add_candidate(ui_id_targets[index])}}const runtime_nodes=func.runtime?.ui?.get_refresh_index_elements?func.runtime.ui.get_refresh_index_elements(options.SESSION_ID,$root).toArray():func.runtime.ui.find_by_selector($root,"[xu-ui-id]").toArray();const target_parent_ui_id=xuData.parent_element_ui_id;const target_node_id=xuData.nodeid;const target_recordid=xuData.recordid;const target_prog_id=xuData.paramsP?.prog_id;for(let index=0;index<runtime_nodes.length;index++){const node=runtime_nodes[index];const node_data=func.runtime.ui.get_data(node);const node_xu_data=node_data?.xuData;if(!node_xu_data){continue}if(target_node_id&&node_xu_data.nodeid!==target_node_id){continue}if(target_parent_ui_id&&node_xu_data.parent_element_ui_id!==target_parent_ui_id){continue}if(target_prog_id&&node_xu_data.paramsP?.prog_id!==target_prog_id){continue}if(typeof target_recordid!=="undefined"&&target_recordid!==null&&node_xu_data.recordid!==target_recordid){continue}const node_bind_expression=node_data?.xuAttributes?.["xu-bind"]||func.runtime.ui.get_attr(node,"xu-bind");if(node_bind_expression!==bind_expression){continue}add_candidate(node)}if(!live_targets.length){const _node=func.runtime.ui.get_first_node($elm);return func.runtime.ui._wrap_matches(_node?[_node]:[])}for(let index=0;index<live_targets.length;index++){const node=live_targets[index];const target_data=func.runtime.ui.get_data(node);if(!node?.isConnected||target_data?.xuData?.pending_to_delete){continue}add_candidate(node)}if(!live_targets.length){const _node=func.runtime.ui.get_first_node($elm);return func.runtime.ui._wrap_matches(_node?[_node]:[])}const target_nodes=live_targets;const visible_targets=[];for(let index=0;index<target_nodes.length;index++){const node=target_nodes[index];if(node.getClientRects?.().length&&!node.hidden){visible_targets.push(node)}}return func.runtime.ui._wrap_matches(visible_targets.length?visible_targets:live_targets)};try{const bind_field=await func.runtime.bind.resolve_field(options.SESSION_ID,_prog_id,_dsP,bind_expression.split(".")[0],xuData.iterate_info);bind_field_id=bind_field.bind_field_id;field_prop=bind_field.field_prop;is_dynamic_field=bind_field.is_dynamic_field;_dsP=bind_field.dsSessionP;_prog_id=bind_field.prog_id;val_is_reference_field=true}catch(err){console.error(err?.message||err);return{}}const bind=func.runtime.bind.get_adapter(options.SESSION_ID);const field_changed=async function(){const _ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[_dsP];const field_type=func.runtime.bind.get_field_type(field_prop);if(field_type==="array"&&input_field_type==="checkbox"&&val_is_reference_field){const arr_value_before_cast=[...(await func.datasource.get_value(options.SESSION_ID,bind_field_id,_dsP,_ds.currentRecordId)).ret.value];const value_from_getter=bind.getter(func.runtime.ui.get_first_node(options.$elm));const value=func.runtime.bind.toggle_array_value(arr_value_before_cast,value_from_getter);const datasource_changes=func.runtime.bind.build_datasource_changes(_dsP,_ds.currentRecordId,bind_field_id,value);return await func.datasource.update(options.SESSION_ID,datasource_changes)}if(field_type==="array"&&input_field_type==="radio"&&val_is_reference_field){const value_from_getter=bind.getter(func.runtime.ui.get_first_node(options.$elm));const datasource_changes=func.runtime.bind.build_datasource_changes(_dsP,_ds.currentRecordId,bind_field_id,[value_from_getter]);return await func.datasource.update(options.SESSION_ID,datasource_changes)}const raw_value=bind.getter(func.runtime.ui.get_first_node(options.$elm));const value=await func.runtime.bind.get_cast_value(options.SESSION_ID,field_prop,input_field_type,raw_value);if(!_ds.currentRecordId)return;const iterate_info=xuData.iterate_info;const is_iterate_field=is_dynamic_field&&iterate_info&&(iterate_info.iterator_val===bind_field_id||iterate_info.iterator_key===bind_field_id);if(!is_iterate_field){const datasource_changes=func.runtime.bind.build_datasource_changes(_dsP,_ds.currentRecordId,bind_field_id,value);await func.datasource.update(options.SESSION_ID,datasource_changes)}await func.runtime.bind.update_reference_source_array({SESSION_ID:options.SESSION_ID,dsSessionP:_dsP,currentRecordId:_ds.currentRecordId,iterate_info:iterate_info,bind_field_id:bind_field_id,field_prop:field_prop,val_is_reference_field:val_is_reference_field,input_field_type:input_field_type,expression_value:bind_expression,value:value});await func.datasource.update_changes_for_out_parameter(options.SESSION_ID,_dsP,_ds.parentDataSourceNo)};const bind_targets=get_bind_targets();const target_nodes=bind_targets.toArray();for(let index=0;index<target_nodes.length;index++){const target=target_nodes[index];const target_data=func.runtime.ui.get_data(target);if(!target_data?.xuData||target_data.xuData.bind_listener_attached){continue}bind.listener(target,field_changed);target_data.xuData.bind_listener_attached=true}const set_value=async function(){const _ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[_dsP];if(!_ds)return;const target_record_id=xuData.recordid||_ds.currentRecordId;if(!target_record_id)return;let value;try{if(val_is_reference_field){const iter=xuData.iterate_info;if(iter&&is_dynamic_field&&(iter.iterator_val===bind_field_id||iter.iterator_key===bind_field_id)){value=iter.iterator_val===bind_field_id?iter._val:iter._key}else{const resolved_value=await func.datasource.get_value(options.SESSION_ID,bind_field_id,_dsP,target_record_id);if(resolved_value?.found){value=resolved_value.ret.value}else{value=func.runtime.bind.get_source_value(_ds,bind_field_id,is_dynamic_field)}}value=func.runtime.bind.format_display_value($elm,field_prop,bind_field_id,bind_expression,value,input_field_type)}else{value=bind_expression}if(typeof value==="undefined")return;const live_bind_targets=get_bind_targets().toArray();for(let index=0;index<live_bind_targets.length;index++){const elm=live_bind_targets[index];if(!elm){continue}bind.setter(elm,value);const target_input_type=elm.type||input_field_type;switch(target_input_type){case"radio":elm.checked=elm.value===String(value);break;case"checkbox":elm.checked=!!value;break;default:if(typeof elm.value!=="undefined"){elm.value=value===null?"":String(value)}break}}}catch(err){console.error(err)}};const bind_refresh_event="xu-bind-refresh."+_dsP.toString();const bind_handler_key="_xuda_bind_"+(bind_ui_id||bind_field_id||"bind");if(document.body[bind_handler_key]){document.body.removeEventListener(bind_refresh_event,document.body[bind_handler_key])}document.body[bind_handler_key]=async()=>{await set_value()};document.body.addEventListener(bind_refresh_event,document.body[bind_handler_key]);await set_value();return{}};func.runtime.render.apply_xu_class=async function(options){try{const raw_value=options?.val?.value;const xuData=func.runtime.ui.get_data(options.$elm)?.xuData;if(typeof raw_value==="string"){const trimmed=raw_value.trim();const looks_like_object=trimmed.startsWith("{")&&trimmed.endsWith("}");if(!looks_like_object){func.runtime.render.apply_expression_class(options.$elm,raw_value);xuData.debug_info.attribute_stat["xu-class"]=func.runtime.ui.get_first_node(options.$elm)?.className||func.runtime.ui.get_attr(options.$elm,"class");return{}}}const classes_obj=typeof raw_value==="string"?JSON5.parse(raw_value):Object.assign({},{},raw_value);if(typeof classes_obj!=="object"||classes_obj===null||Array.isArray(classes_obj)){throw new Error("xu-class expects an object map or a class string")}const class_names=Object.keys(classes_obj);for(let index=0;index<class_names.length;index++){const cla=class_names[index];const cond=classes_obj[cla];const res=await func.expression.get(options.SESSION_ID,cond,options.paramsP.dsSessionP,"UI Attr EXP",xuData.currentRecordId,null,null,null,null,null,xuData.iterate_info);if(res.result){func.runtime.ui.add_class(options.$elm,cla)}else{func.runtime.ui.remove_class(options.$elm,cla)}}xuData.debug_info.attribute_stat["xu-class"]=func.runtime.ui.get_first_node(options.$elm)?.className||func.runtime.ui.get_attr(options.$elm,"class");return{}}catch(e){await func.runtime.render.report_xu_runtime_error({...options,xu_func:"xu-class",val:{key:"xu-class",value:options?.val?.value}},e,"xu-class has invalid syntax");return{abort:true}}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.handle_xu_for=async function(options){if(options.parent_infoP?.iterate_info)return{};if(!options.data.value)return{};try{const $live_elm=options.$live_elm||options.$elm;const{arr,reference_source_obj}=await func.runtime.render.resolve_xu_for_source(options.SESSION_ID,options.paramsP.dsSessionP,options.data.value);const{iterator_key,iterator_val,is_key_dynamic_field,is_val_dynamic_field}=func.runtime.render.get_xu_for_iterators(options.$elm);const _progFields=await func.datasource.get_progFields(options.SESSION_ID,options.paramsP.dsSessionP);let i=0;if(Array.isArray(arr)){for(let idx=0;idx<arr.length;idx++){let _key=idx;let _val=arr[idx];const currentRecordId=SESSION_OBJ[options.SESSION_ID].DS_GLB[options.paramsP.dsSessionP].currentRecordId.toString();const iterate_info=func.runtime.render.build_iterate_info({_val:_val,_key:_key,iterator_key:iterator_key,iterator_val:iterator_val,is_key_dynamic_field:is_key_dynamic_field,is_val_dynamic_field:is_val_dynamic_field,reference_source_obj:reference_source_obj});func.runtime.render.apply_iterate_info_to_current_record(options.SESSION_ID,options.paramsP.dsSessionP,currentRecordId,_progFields,iterate_info);const _parent_info=structuredClone(options.parent_infoP)||{};_parent_info.iterate_info=iterate_info;const $divP=await func.runtime.render.render_ui_tree(options.SESSION_ID,options.$container,options.nodeP,_parent_info,options.paramsP,options.jobNoP,null,i,null,options.nodeP,null,options.$root_container);func.runtime.render.attach_iterate_info_to_children($divP,iterate_info);i++}}else{const iterate_keys=Object.keys(arr||{});for(let idx=0;idx<iterate_keys.length;idx++){let _key=iterate_keys[idx];let _val=arr[_key];const currentRecordId=SESSION_OBJ[options.SESSION_ID].DS_GLB[options.paramsP.dsSessionP].currentRecordId.toString();const iterate_info=func.runtime.render.build_iterate_info({_val:_val,_key:_key,iterator_key:iterator_key,iterator_val:iterator_val,is_key_dynamic_field:is_key_dynamic_field,is_val_dynamic_field:is_val_dynamic_field,reference_source_obj:reference_source_obj});func.runtime.render.apply_iterate_info_to_current_record(options.SESSION_ID,options.paramsP.dsSessionP,currentRecordId,_progFields,iterate_info);const _parent_info=structuredClone(options.parent_infoP)||{};_parent_info.iterate_info=iterate_info;const $divP=await func.runtime.render.render_ui_tree(options.SESSION_ID,options.$container,options.nodeP,_parent_info,options.paramsP,options.jobNoP,null,i,null,options.nodeP,null,options.$root_container);func.runtime.render.attach_iterate_info_to_children($divP,iterate_info);i++}}const _live_node=func.runtime.ui.get_first_node($live_elm);if(_live_node){func.runtime.ui.remove($live_elm)}const _options_node=func.runtime.ui.get_first_node(options.$elm);if(_options_node&&_options_node!==_live_node){func.runtime.ui.remove(options.$elm)}return{abort:true,consume_placeholder:true}}catch(e){console.error(" Iterator Arr parse error");return{abort:true}}};func.runtime.render.set_iterator_name=function($elm,key,value){func.runtime.ui.get_data($elm).xuData[key]=value;return{}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.handle_legacy_xu_render=async function(options){const value=await func.common.get_cast_val(options.SESSION_ID,"common fx","xu-render","bool",options.val.value);const init_render=function(){if(!value){const cloned_div=func.runtime.ui.get_first_node(options.$elm)?.cloneNode(true);const original_data_obj=func.runtime.render.build_xu_render_original_data({$container:cloned_div,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$root_container:options.$root_container});const snapshot_xuData=func.runtime.ui.get_data(cloned_div).xuData;const snapshot_xuAttributes=options.nodeP.attributes||{};const xu_ui_id=func.runtime.ui.get_attr(options.$elm,"xu-ui-id");const _elm_node=func.runtime.ui.get_first_node(options.$elm);if(_elm_node?.remove){_elm_node.remove()}func.runtime.render.create_xu_render_placeholder(xu_ui_id,options.$container,{hidden:true,xuData:snapshot_xuData,original_data_obj:original_data_obj,xurender_node:cloned_div,xuAttributes:snapshot_xuAttributes});return{abort:true}}return{}};const replace_rendered_xu_node=async function(new_$div){const $parent=func.runtime.ui.get_parent(options.$elm);func.runtime.ui.replace_with(options.$elm,new_$div);if(options.from_panel){const xuPanelWrapper={...func.runtime.ui.get_data(new_$div).xuPanelWrapper};if(func.runtime.ui.get_data($parent)){func.runtime.ui.get_data($parent).xuPanelWrapper=xuPanelWrapper}func.runtime.ui.replace_with(options.$elm,func.runtime.ui.get_children(new_$div))}if(options.val.fields_arr){return await func.runtime.ui.refresh_xu_attributes({SESSION_ID:options.SESSION_ID,fields_arr:options.val.fields_arr,jobNoP:options.val.jobNoP,$elm_to_search:new_$div})}func.events.delete_job(options.SESSION_ID,options.jobNoP)};const post_render=async function(){if(value){try{const elm_node=func.runtime.ui.get_first_node(options.$elm);if(elm_node?.tagName!=="XURENDER"&&elm_node){return func.events.delete_job(options.SESSION_ID,options.jobNoP)}const original_data_obj=func.runtime.ui.get_data(options.$elm).xuData.original_data_obj;if(!original_data_obj){func.events.delete_job(options.SESSION_ID,options.jobNoP);return{delete_job:options.jobNoP}}const new_$div=await func.runtime.render.render_ui_tree(options.SESSION_ID,options.$elm,structuredClone(original_data_obj.nodeP),original_data_obj.parent_infoP,original_data_obj.paramsP,options.jobNoP,null,original_data_obj.keyP,null,original_data_obj.parent_nodeP,null,original_data_obj.$root_container);func.runtime.ui.get_data(new_$div).xuData.original_data_obj=original_data_obj;func.runtime.ui.get_data(new_$div).xuData.xurender_node=func.runtime.ui.get_first_node(options.$elm)?.cloneNode(true);func.runtime.ui.get_data(new_$div).xuAttributes=func.runtime.ui.get_data(options.$elm).xuAttributes||{};const xu_ui_id=func.runtime.ui.get_attr(options.$elm,"xu-ui-id");let $live_elm;if(func.runtime.ui.get_first_node(options.$elm)&&xu_ui_id){if(func.runtime?.ui?.get_refresh_indexed_element_by_ui_id){const _elm=func.runtime.ui.get_refresh_indexed_element_by_ui_id(options.SESSION_ID,xu_ui_id);$live_elm=func.runtime.ui._wrap_matches(_elm?[_elm]:[])}else if(func.runtime?.ui?.find_xu_ui_in_root){$live_elm=func.runtime.ui.find_xu_ui_in_root(options.SESSION_ID,xu_ui_id)}else{$live_elm=func.runtime.ui.find_by_selector(document.body,`[xu-ui-id="${xu_ui_id}"]`)}}else{$live_elm=func.runtime.ui._wrap_matches([])}if($live_elm.length){if(func.runtime.ui.get_data(new_$div).xuData.paramsP){return await replace_rendered_xu_node(new_$div)}func.events.delete_job(options.SESSION_ID,options.jobNoP)}}catch(error){func.events.delete_job(options.SESSION_ID,options.jobNoP)}return}if(func.runtime.ui.get_first_node(options.$elm)?.tagName==="XURENDER"){func.events.delete_job(options.SESSION_ID,options.jobNoP);return}const tmp_div=document.createElement("div");const $xurender=func.runtime.ui.create_xurender(func.runtime.ui.get_attr(options.$elm,"xu-ui-id"),tmp_div);const elm_data=func.runtime.ui.get_data(options.$elm);const elm_xu_data=elm_data?.xuData||{};const elm_xu_attributes=elm_data?.xuAttributes||{};const xurender_node_data=func.runtime.ui.get_data(elm_xu_data.xurender_node);if(elm_xu_data.xurender_node){func.runtime.ui.set_data($xurender,"xuAttributes",xurender_node_data?.xuAttributes||{});func.runtime.ui.set_data($xurender,"xuData",xurender_node_data?.xuData||{})}else{func.runtime.ui.set_data($xurender,"xuAttributes",elm_xu_attributes);func.runtime.ui.set_data($xurender,"xuData",elm_xu_data);const original_data_obj=func.runtime.render.build_xu_render_original_data({nodeP:elm_xu_data.node_org,paramsP:elm_xu_data.paramsP,$container:func.runtime.ui.get_first_node(options.$elm)?.cloneNode(true),parent_infoP:options.parent_infoP});func.runtime.ui.get_data($xurender).xuData.original_data_obj=original_data_obj}const elm_first_node=func.runtime.ui.get_first_node(options.$elm);const teleport_nodes=elm_first_node?.querySelectorAll?.("xu-teleport")||[];for(let index=0;index<teleport_nodes.length;index++){const val=teleport_nodes[index];const xuTeleportData=func.runtime.ui.get_data(val).xuTeleportData||[];for(const teleported_elm_id of xuTeleportData){func.runtime.ui.remove_xu_ui(teleported_elm_id)}}func.runtime.ui.replace_with(options.$elm,func.runtime.ui.get_children(tmp_div));func.events.delete_job(options.SESSION_ID,options.jobNoP)};if(options.is_init){return init_render()}return await post_render()};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.handle_modern_xu_render=async function(options){const value=await func.common.get_cast_val(options.SESSION_ID,"common fx","xu-render","bool",options.val.value);const has_xu_render_attribute=true;const elm_data=func.runtime.ui.get_data(options.$elm);const has_xu_exp_render_attribute=elm_data?.xuData?.attr_exp_info?.["xu-render"]?true:false;const init_render=async function(){options.nodeP.xu_render_made=value;if(!value){if(has_xu_exp_render_attribute){return{has_xu_exp_render_attribute:has_xu_exp_render_attribute,has_xu_render_attribute:has_xu_render_attribute,xu_render_background_processing:true}}return{has_xu_render_attribute:has_xu_render_attribute,abort:true}}return{has_xu_exp_render_attribute:has_xu_exp_render_attribute,has_xu_render_attribute:has_xu_render_attribute}};const post_render=async function(){const container_data=func.runtime.ui.get_data(options.$container);if(!container_data?.xuData?.node?.children?.[options.keyP]){return}const nodeP=container_data.xuData.node.children[options.keyP];nodeP.xu_render_made=value;if(value){try{const exclude_fields=func.runtime.render.get_xu_render_exclude_fields(options.$elm);const xu_render_cache_id=await func.runtime.render.get_xu_render_cache_str(options.SESSION_ID,options.paramsP.dsSessionP,exclude_fields);const xu_ui_id=func.runtime.ui.get_attr(options.$elm,"xu-ui-id");const cached_entry=UI_WORKER_OBJ?.xu_render_cache?.[xu_ui_id+xu_render_cache_id];let found_parent_vars=false;if(cached_entry?.$div){const parent_fields=func.runtime.render.get_parent_ds_field_names(options.SESSION_ID,options.paramsP.dsSessionP);found_parent_vars=func.runtime.render.has_parent_field_dependency(cached_entry.$div,parent_fields,cached_entry?.dependency_fields)}let new_$div=!found_parent_vars&&cached_entry?.$div?func.runtime.ui.get_first_node(cached_entry.$div)?.cloneNode(true):null;if(!new_$div||found_parent_vars){func.runtime.render.cache_xu_render(xu_ui_id+xu_render_cache_id,{paramsP:options.paramsP});nodeP.xu_render_xu_ui_id=xu_ui_id;nodeP.xu_render_cache_id=xu_render_cache_id;new_$div=await func.runtime.render.render_ui_tree(options.SESSION_ID,options.$container,nodeP,options.parent_infoP,options.paramsP,options.jobNoP,null,options.keyP,null,options.parent_nodeP,null,options.$root_container);const _$div=func.runtime.ui.get_first_node(new_$div)?.cloneNode(true);func.runtime.render.cache_xu_render(xu_ui_id+xu_render_cache_id,{...UI_WORKER_OBJ.xu_render_cache[xu_ui_id+xu_render_cache_id],$div:_$div,data:func.runtime.ui.get_data(_$div)})}func.runtime.render.insert_ordered_child(options.$container,new_$div,options.keyP);if(func.runtime.ui.get_first_node(options.$elm)?.tagName==="XURENDER"){func.runtime.ui.remove(options.$elm)}}catch(error){func.events.delete_job(options.SESSION_ID,options.jobNoP)}return}if(func.UI?.worker?.cancel_child_in_flight_jobs){func.UI.worker.cancel_child_in_flight_jobs(options.$elm)}const xu_ui_id=func.runtime.ui.get_attr(options.$elm,"xu-ui-id");const exclude_fields=func.runtime.render.get_xu_render_exclude_fields(options.$elm);const cache_str=await func.runtime.render.get_xu_render_cache_str(options.SESSION_ID,options.paramsP.dsSessionP,exclude_fields);const _$div=func.runtime.ui.get_first_node(options.$elm)?.cloneNode(true);func.runtime.render.cache_xu_render(xu_ui_id+cache_str,{$div:_$div,data:func.runtime.ui.get_data(_$div),paramsP:options.paramsP});func.runtime.ui.remove(options.$elm);func.events.delete_job(options.SESSION_ID,options.jobNoP)};if(options.is_init){return await init_render()}return await post_render()};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.handle_xu_render=async function(options){if(glb.new_xu_render){return await func.runtime.render.handle_modern_xu_render(options)}return await func.runtime.render.handle_legacy_xu_render(options)};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.apply_expression_attribute=async function(options){const new_val={key:options.key,value:func.runtime.render.fix_val_defaults(options.key,options.exp_ret.result)};if(func.runtime.render.is_xu_tag(options.nodeP.tagName)){if(options.tag_fx?.[options.nodeP.tagName]?.[new_val.key]){return await options.tag_fx[options.nodeP.tagName][new_val.key](options.$elm,new_val)}console.warn(`attribute ${new_val.key} not found for ${options.nodeP.tagName}`);return{}}if(!func.runtime.ui.get_data(options.$elm)?.xuData){return{}}func.runtime.render.record_attribute_stat(options.$elm,new_val.key,new_val.value);if(typeof new_val.value==="undefined"||new_val.value===null){return{}}if(glb.solid_attributes.includes(new_val.key)&&!new_val.value){return{}}if(new_val.key.substr(0,2)==="xu"){return await options.common_fx[new_val.key](options.$elm,new_val)}if(new_val.key==="class"){return func.runtime.render.apply_expression_class(options.$elm,new_val.value)}const existing_value=func.runtime.ui.get_attr(options.$elm,new_val.key)||"";func.runtime.ui.set_attr(options.$elm,new_val.key,existing_value+new_val.value);return{}};func.runtime.render.apply_expression_class=function($elm,new_class_value){const xuData=func.runtime.ui.get_data($elm)?.xuData;const old_exp_classes=xuData?._exp_class_cache||"";if(old_exp_classes){const old_classes=old_exp_classes.split(/\s+/).filter(Boolean);for(let i=0;i<old_classes.length;i++){func.runtime.ui.remove_class($elm,old_classes[i])}}const new_value=(new_class_value||"").toString();const new_classes=new_value.split(/\s+/).filter(Boolean);for(let i=0;i<new_classes.length;i++){func.runtime.ui.add_class($elm,new_classes[i])}if(xuData){xuData._exp_class_cache=new_value}return{}};func.runtime.render.apply_visibility=function($elm,value){if(value){func.runtime.ui.show($elm);return}func.runtime.ui.hide($elm)};func.runtime.render.apply_dom_content=function($elm,value,mode="html"){if(mode==="text"){func.runtime.ui.set_text($elm,value);return}func.runtime.ui.set_html($elm,value)};func.runtime.render.run_inline_script=function($elm,script_body){const checkExist=setInterval(async function(){const node=func.runtime.ui.get_first_node($elm);if(node&&node.offsetParent!==null){try{const fn=`async (el)=>{${script_body} };`;const res=eval(fn);await res(node)}catch(e){eval(script_body)}clearInterval(checkExist)}},100)};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.handle_xu_panel_program=async function(options){let ret={};const _session=SESSION_OBJ[options.SESSION_ID];const _ds=_session.DS_GLB[options.paramsP.dsSessionP];const _refreshed_ds=_session.DS_GLB[options.refreshed_ds];const render_panel_init=async function(){const prog_id=options.val.value?.prog||options.val.value;let create_new_ds=true;if(options.refreshed_ds&&_refreshed_ds?.prog_id===prog_id){create_new_ds=false}const params_obj=await options.get_params_obj_new(options.SESSION_ID,prog_id,options.nodeP,options.paramsP.dsSessionP);const ret_panel=await func.runtime.ui.init_screen({SESSION_ID:options.SESSION_ID,prog_id:prog_id,sourceScreenP:options.paramsP.screenId,callingDataSource_objP:_ds,$callingContainerP:options.$elm,triggerIdP:null,rowIdP:_ds.currentRecordId,jobNoP:null,is_panelP:true,parameters_obj_inP:params_obj.params_res,source_functionP:"initXu_panel",call_screen_propertiesP:undefined,refreshed_ds:create_new_ds?null:options.refreshed_ds,parameters_raw_obj:params_obj.params_raw});ret={$new_div:ret_panel};const container_data=func.runtime.ui.get_data(options.$container);if(container_data?.xuData){container_data.xuData.xuPanelProps=func.runtime.ui.get_data(options.$elm)?.xuAttributes;container_data.xuData.xuPanelData=func.runtime.ui.get_data(ret_panel)}return ret};const render_panel_alter=async function(){const program=options.val.value?.prog||options.val.value;const $wrapper=document.createElement("div");const $div=await func.runtime.ui.create_container({SESSION_ID:options.SESSION_ID,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,treeP:options.treeP,parent_nodeP:options.parent_nodeP,prop:options.nodeP.attributes,$appendToP:$wrapper,attr_str:""});const params_obj=await options.get_params_obj_new(options.SESSION_ID,program,options.nodeP,options.paramsP.dsSessionP);const ret_init=await func.runtime.ui.init_screen({SESSION_ID:options.SESSION_ID,prog_id:program,sourceScreenP:options.paramsP.screenId,callingDataSource_objP:_ds,$callingContainerP:$div,triggerIdP:null,rowIdP:_ds.currentRecordId,jobNoP:options.jobNoP,is_panelP:true,parameters_obj_inP:params_obj.params_res,source_functionP:"alterXu_panel",call_screen_propertiesP:undefined,refreshed_ds:undefined,parameters_raw_obj:params_obj.params_raw});ret={$new_div:ret_init,abort:true};await func.runtime.ui.panel_post_render_handler({SESSION_ID:options.SESSION_ID,$container:options.$elm,$wrapper:ret.$new_div,nodeP:options.nodeP,$panel_div:$div,jobNoP:options.jobNoP});return ret};if(!options.val.value){if(options.is_init){options.val.value="_empty_panel_program"}else{return{abort:true}}}if(options.is_init){return await render_panel_init()}return await render_panel_alter()};func.runtime.render.handle_xu_teleport=async function(options){if(glb.new_xu_render){return{}}if(!options.val.value){return{abort:true}}const $parent=func.runtime.ui.get_parent(options.$elm);const parent_data=func.runtime.ui.get_data($parent);if(parent_data?.xuData){func.runtime.ui.set_data($parent,"xuTeleportData",[]);const parent_xu_ui_id=func.runtime.ui.get_attr($parent,"xu-ui-id");for(let index=0;index<options.nodeP.children.length;index++){const node=options.nodeP.children[index];const $teleport_elm=await func.runtime.render.render_ui_tree(options.SESSION_ID,document.querySelector(options.val.value),node,options.parent_infoP,options.paramsP,options.jobNoP,options.is_skeleton,index,null,node,null,options.$root_container);parent_data.xuTeleportData.push(func.runtime.ui.get_attr($teleport_elm,"xu-ui-id"));func.runtime.ui.set_attr($teleport_elm,"xu-teleport-parent-id",parent_xu_ui_id)}func.runtime.ui.remove(options.$elm);return{abort:true}}func.runtime.ui.set_data(options.$elm,"xuTeleportData",[]);func.runtime.ui.set_attr(options.$elm,"hidden",true);for(let index=0;index<options.nodeP.children.length;index++){const node=options.nodeP.children[index];const $to_container=document.querySelector(options.val.value);if(!$to_container){console.error(`container ${options.val.value} for xuTeleportData not found`);return{abort:true}}const $teleport_elm=await func.runtime.render.render_ui_tree(options.SESSION_ID,$to_container,node,options.parent_infoP,options.paramsP,options.jobNoP,options.is_skeleton,index,null,node,null,options.$root_container);func.runtime.ui.get_data(options.$elm).xuTeleportData.push(func.runtime.ui.get_attr($teleport_elm,"xu-ui-id"));func.runtime.ui.set_attr($teleport_elm,"xu-teleport-parent-id",func.runtime.ui.get_attr(options.$elm,"xu-ui-id"))}return{abort:true}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.build_base_xu_handlers=function(options,_ds){const decode_html_entities=function(value){if(typeof value!=="string"||value.indexOf("&")===-1){return value}if(typeof document!=="undefined"){const textarea=document.createElement("textarea");textarea.innerHTML=value;return textarea.value}return value.replaceAll("&quot;",'"').replaceAll("&#34;",'"').replaceAll("&#39;","'").replaceAll("&#039;","'").replaceAll("&lt;","<").replaceAll("&gt;",">").replaceAll("&amp;","&")};const parse_object_value=function(attr_name,val,shape="object"){let parsed_value=val?.value;if(typeof parsed_value==="string"){const decoded_value=decode_html_entities(parsed_value);const trimmed_value=decoded_value.trim();const wrapped_candidate=trimmed_value.startsWith("(")&&trimmed_value.endsWith(")")?trimmed_value.slice(1,-1).trim():trimmed_value;const looks_like_wrapped_shape=shape==="object"&&wrapped_candidate.startsWith("{")&&wrapped_candidate.endsWith("}")||shape==="array"&&wrapped_candidate.startsWith("[")&&wrapped_candidate.endsWith("]");try{parsed_value=JSON5.parse(looks_like_wrapped_shape?wrapped_candidate:trimmed_value)}catch(error){throw func.runtime.render.build_xu_runtime_error({...options,xu_func:attr_name,val:{key:attr_name,value:val?.value}},error,`${attr_name} has invalid ${shape} syntax`)}}const valid=shape==="array"?Array.isArray(parsed_value):typeof parsed_value==="object"&&parsed_value!==null&&!Array.isArray(parsed_value);if(!valid){throw func.runtime.render.build_xu_runtime_error({...options,xu_func:attr_name,val:{key:attr_name,value:val?.value}},null,`${attr_name} expects a ${shape} value`)}return parsed_value};return{"xu-attrs":async function($elm,val){if(!val.value)return{};const attrs_obj=parse_object_value("xu-attrs",val,"object");const attr_keys=Object.keys(attrs_obj);for(let index=0;index<attr_keys.length;index++){const attr_key=attr_keys[index];options.nodeP.attributes[attr_key]=attrs_obj[attr_key]}return{}},"xu-ref":async function($elm,val,dsSession){return await func.runtime.render.handle_xu_ref({SESSION_ID:options.SESSION_ID,$elm:$elm,paramsP:options.paramsP,val:val,dsSession:dsSession})},"xu-bind":async function($elm,val){return await func.runtime.render.handle_xu_bind({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$elm:$elm,paramsP:options.paramsP,val:val,ds:_ds})},"xu-render":async function($elm,val,from_panel){return await func.runtime.render.handle_xu_render({SESSION_ID:options.SESSION_ID,$elm:$elm,$container:options.$container,$root_container:options.$root_container,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,val:val,is_init:options.is_init,from_panel:from_panel})},"xu-show":async function($elm,val){const value=await func.common.get_cast_val(options.SESSION_ID,"common fx","xu-show","bool",val.value);func.runtime.render.apply_visibility($elm,value);return{}},"xu-content":async function($elm,val){try{func.runtime.render.apply_dom_content($elm,val.value,"html")}catch(error){console.warn(error)}return},"xu-text":async function($elm,val){try{func.runtime.render.apply_dom_content($elm,val.value,"text")}catch(error){console.warn(error)}return},"xu-html":async function($elm,val){try{func.runtime.render.apply_dom_content($elm,val.value,"html")}catch(error){console.warn(error)}return},"xu-for":async function($elm,data){return await func.runtime.render.handle_xu_for({SESSION_ID:options.SESSION_ID,$elm:$elm,$live_elm:options.$live_elm||$elm,$container:options.$container,$root_container:options.$root_container,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,data:data})},"xu-for-key":async function($elm,val){return func.runtime.render.set_iterator_name($elm,"iterator_key",val.value)},"xu-for-val":async function($elm,val){return func.runtime.render.set_iterator_name($elm,"iterator_val",val.value)},"xu-class":async function($elm,val){return await func.runtime.render.apply_xu_class({SESSION_ID:options.SESSION_ID,$elm:$elm,paramsP:options.paramsP,val:val})},"xu-on":async function($elm,val){func.runtime.render.bind_xu_event({SESSION_ID:options.SESSION_ID,paramsP:options.paramsP,$elm:$elm,val:val});return{}},"xu-script":async function($elm,val){func.runtime.render.run_inline_script($elm,val.value);return{}},"xu-style-global":async function($elm,val){func.runtime.render.append_style_tag(val.value);return{}},"xu-style":async function($elm,val){const newCSSString=func.runtime.render.scope_css_to_xu_ui($elm,val.value);func.runtime.render.append_style_tag(newCSSString);return{}},"xu-cdn":async function($elm,val){const resources_obj=parse_object_value("xu-cdn",val,"object");const resource_keys=Object.keys(resources_obj);for(let index=0;index<resource_keys.length;index++){const resource=resources_obj[resource_keys[index]];await func.runtime.resources.load_cdn(options.SESSION_ID,resource)}return{}},"xu-ui-plugin":async function($elm,val){const plugins_obj=parse_object_value("xu-ui-plugin",val,"object");const plugin_names=Object.keys(plugins_obj);for(let index=0;index<plugin_names.length;index++){const plugin_name=plugin_names[index];const value=plugins_obj[plugin_name];await func.runtime.resources.run_ui_plugin(options.SESSION_ID,options.paramsP,$elm,plugin_name,value)}return{}},"xu-store":async function($elm,val){try{const fields_obj=parse_object_value("xu-store",val,"object");const field_ids=Object.keys(fields_obj);for(let index=0;index<field_ids.length;index++){const field_id=field_ids[index];func.datasource.add_dynamic_field_to_ds(options.SESSION_ID,options.paramsP.dsSessionP,field_id,fields_obj[field_id])}}catch(err){throw err}return{}},"xu-viewport":async function(){return{}}}};func.runtime.render.build_expression_xu_handler=function(options,common_fx,tag_fx){return async function($elm,val){if(!SESSION_OBJ[options.SESSION_ID].DS_GLB[options.paramsP.dsSessionP])return{};const exp=val.value===null?true:val.value;const xuData=func.runtime.ui.get_data($elm)?.xuData;const exp_ret=await func.expression.get(options.SESSION_ID,exp,options.paramsP.dsSessionP,"UI Attr EXP",SESSION_OBJ[options.SESSION_ID].DS_GLB[options.paramsP.dsSessionP].currentRecordId,null,null,null,null,null,xuData?.iterate_info);return await func.runtime.render.apply_expression_attribute({$elm:$elm,key:val.key,exp_ret:exp_ret,nodeP:options.nodeP,tag_fx:tag_fx,common_fx:common_fx})}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.build_tag_xu_handlers=function(options,common_fx){return{"xu-panel":{program:async function($elm,val){return await func.runtime.render.handle_xu_panel_program({SESSION_ID:options.SESSION_ID,$elm:$elm,$container:options.$container,$root_container:options.$root_container,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,val:val,is_init:options.is_init,refreshed_ds:options.refreshed_ds,get_params_obj_new:options.get_params_obj_new})},"xu-render":async function($elm,val){return await common_fx["xu-render"]($elm,val,true)},"xu-ref":async function($elm,val){if(!val.value)return{};return await common_fx["xu-ref"](options.$container,val,func.runtime.ui.get_data(options.$container)?.xuData?.xuPanelData?.xuData?.paramsP?.dsSessionP)}},"xu-teleport":{to:async function($elm,val){return await func.runtime.render.handle_xu_teleport({SESSION_ID:options.SESSION_ID,$elm:$elm,$root_container:options.$root_container,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,val:val})},"xu-render":async function($elm,val){return await common_fx["xu-render"]($elm,val,true)},"xu-show":async function($elm,val){return await common_fx["xu-show"]($elm,val,true)}}}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.build_common_xu_handlers=function(options,_ds,tag_fx){const common_fx=func.runtime.render.build_base_xu_handlers(options,_ds);common_fx["xu-exp"]=func.runtime.render.build_expression_xu_handler(options,common_fx,tag_fx);return common_fx};func.runtime.render.build_xu_handlers=function(options,_ds){const common_fx=func.runtime.render.build_base_xu_handlers(options,_ds);const tag_fx=func.runtime.render.build_tag_xu_handlers(options,common_fx);common_fx["xu-exp"]=func.runtime.render.build_expression_xu_handler(options,common_fx,tag_fx);return{common_fx:common_fx,tag_fx:tag_fx}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.build_xu_runtime_error=function(options,error,fallback_message){const raw_message=error?.message||error||fallback_message||"Unknown runtime error";const err=error instanceof Error?error:new Error(raw_message);err.xu_func=options?.xu_func;err.node_tag=options?.nodeP?.tagName;err.raw_value=options?.val?.value;err.ui_id=func.runtime?.ui?.get_attr?func.runtime.ui.get_attr(options?.$elm,"xu-ui-id"):null;return err};func.runtime.render.report_xu_runtime_error=async function(options,error,fallback_message){const err=func.runtime.render.build_xu_runtime_error(options,error,fallback_message);const attr_name=options?.val?.key||options?.xu_func||"xu-*";const tag_name=options?.nodeP?.tagName||"unknown";const raw_value=typeof err.raw_value==="string"?err.raw_value:JSON.stringify(err.raw_value);const message=[`${attr_name} failed on <${tag_name}>`,err.message];if(raw_value){message.push(`Value: ${raw_value}`)}if(err.ui_id){message.push(`xu-ui-id: ${err.ui_id}`)}console.error("XUDA RUNTIME",message.join(" | "),err);if(func.utils?.debug_report){await func.utils.debug_report(options?.SESSION_ID,"Slim runtime",message.join(" | "),"E",err)}return{}};func.runtime.render.execute_xu_function=async function(options){if(options.is_skeleton)return;const _ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[options.paramsP.dsSessionP];const handler_bundle=options.handler_bundle||func.runtime.render.build_xu_handlers({...options,$live_elm:options.$live_elm||options.$elm},_ds);const{common_fx,tag_fx}=handler_bundle;if(func.runtime.render.is_xu_tag(options.nodeP.tagName)){if(options.xu_func==="xu-exp"){return await common_fx[options.xu_func](options.$elm,options.val)}if(tag_fx?.[options.nodeP.tagName]?.[options.xu_func]){return await tag_fx[options.nodeP.tagName][options.xu_func](options.$elm,options.val)}console.warn(`attribute ${options.xu_func} not found for ${options.nodeP.tagName}`);return{}}if(xu_isEmpty(func.runtime.ui.get_data(options.$elm))){return{}}if(options.xu_func!=="xu-exp"){func.runtime.render.record_attribute_stat(options.$elm,options.xu_func,options.val.value)}try{if(!common_fx[options.xu_func]){await func.runtime.render.report_xu_runtime_error(options,null,`Unknown xu directive: ${options.xu_func}`);return{}}return await common_fx[options.xu_func](options.$elm,options.val)}catch(error){return await func.runtime.render.report_xu_runtime_error(options,error)}};func.datasource={};func.datasource.create=async function(SESSION_ID,prog_id,dataSourceNoP=null,parentDataSourceNoP,containerIdP,rowIdP,jobNoP,calling_trigger_prop,parameters_raw_obj,NA_isInitP,NA_callingSourceP,calling_jobP,NA_screen_dsP,is_panelP,parameters_obj_inP,static_refreshP,worker_id,NA_eventChangesResults){return new Promise(async function(resolve,reject){if(!prog_id)return reject("Program is empty");var _session=SESSION_OBJ[SESSION_ID];if(!_session.DS_GLB)return reject("DS_GLB not exist");var _prog_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,prog_id);if(!_prog_obj)return reject("Program not found");var args={SESSION_ID:SESSION_ID,prog_id:prog_id,dataSourceNoP:dataSourceNoP,parentDataSourceNoP:parentDataSourceNoP,containerIdP:containerIdP,rowIdP:rowIdP,jobNoP:jobNoP,calling_trigger_prop:calling_trigger_prop,calling_jobP:calling_jobP,is_panelP:is_panelP,parameters_obj_inP:parameters_obj_inP,static_refreshP:static_refreshP,worker_id:worker_id,parameters_raw_obj:parameters_raw_obj};var IS_DATASOURCE_REFRESH=null;var _ds=_session.DS_GLB[dataSourceNoP];var old_dataSource_vars={};if(_ds)IS_DATASOURCE_REFRESH=true;if(IS_DATASOURCE_REFRESH){old_dataSource_vars.sortOrder=_ds.sortOrder;old_dataSource_vars.sortOrderTypeExp=_ds.sortOrderTypeExp;if(_ds.data_system){old_dataSource_vars.SYS_OBJ_WIN_MODE=_ds.data_system.SYS_OBJ_WIN_MODE;old_dataSource_vars.SYS_STR_WIN_ID=_ds.data_system.SYS_STR_WIN_ID;old_dataSource_vars.SYS_STR_WIN_NAME=_ds.data_system.SYS_STR_WIN_NAME}if(static_refreshP)old_dataSource_vars.in_parameters=_ds.in_parameters;await func.datasource.update(SESSION_ID,{[dataSourceNoP]:{["datasource_main"]:{stat:"busy",stat_ts:Date.now(),is_worker:glb.IS_WORKER}}})}const restore_old_dataSource_vars=function(dsSessionP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];if(_ds.data_system){_ds.data_system.SYS_OBJ_WIN_MODE=old_dataSource_vars.SYS_OBJ_WIN_MODE;_ds.data_system.SYS_STR_WIN_ID=old_dataSource_vars.SYS_STR_WIN_ID;_ds.data_system.SYS_STR_WIN_NAME=old_dataSource_vars.SYS_STR_WIN_NAME}if(static_refreshP)_ds.in_parameters=old_dataSource_vars.in_parameters};var run_at=_prog_obj?.properties?.runAt;if(_session.opt.app_computing_mode==="main"){run_at="client"}if(_prog_obj?.properties.menuType==="globals"){run_at="client"}if(!run_at&&parentDataSourceNoP&&_session.DS_GLB[parentDataSourceNoP]){if(_session.DS_GLB[parentDataSourceNoP]._run_at)run_at=_session.DS_GLB[parentDataSourceNoP].v.run_at}const done=function(SESSION_ID,dsSessionP,response_returned_from_worker){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];if(IS_DATASOURCE_REFRESH){restore_old_dataSource_vars(dsSessionP)}if(!IS_DATASOURCE_REFRESH){if(!glb.IS_WORKER){DATASOURCE_INTERVALS[SESSION_ID][dsSessionP]=new func.datasource.interval(SESSION_ID,dsSessionP,"client_interval");DATASOURCE_INTERVALS[SESSION_ID][dsSessionP].init()}}const set_stat_idle=async function(){let ds_connected=[];for(const[dsP,_ds]of Object.entries(_session.DS_GLB)){if(_ds.parentDataSourceNo==dsSessionP){ds_connected.push(dsP)}}const datasource_changes={[dsSessionP]:{["datasource_main"]:{stat:"idle",stat_ts:Date.now(),is_worker:glb.IS_WORKER}}};if(!ds_connected.length){return await func.datasource.update(SESSION_ID,datasource_changes)}let interval=setInterval(()=>{let idle_count=0;for(const dsSession of ds_connected){const _ds=_session.DS_GLB[dsSession];if(_ds.stat=="idle"){idle_count++}}if(ds_connected.length===idle_count){clearInterval(interval);func.datasource.update(SESSION_ID,datasource_changes)}},1e3)};set_stat_idle();resolve({SESSION_ID:SESSION_ID,dsSessionP:dsSessionP,rowIdP:_ds.args.rowIdP,jobNoP:_ds.args.jobNoP,callingLogId:_ds.callingLogId,calling_jobP:_ds.calling_jobP})};var db_driver;var is_system_client_vars=false;if(jobNoP){}if(glb.IS_WORKER||run_at==="client"||is_system_client_vars||db_driver==="pouchdb"){const ret=await func.datasource.prepare(args.SESSION_ID,args.prog_id,args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,args.parameters_raw_obj,null,null,args.calling_jobP,null,args.is_panelP,args.parameters_obj_inP,args.static_refreshP,run_at,worker_id);return done(SESSION_ID,ret.dsSessionP)}if(_ds)IS_DATASOURCE_REFRESH=true;var data=Object.assign({session_id:SESSION_ID,dataSourceSessionGlobal:SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal,parentDataSourceNo:IS_DATASOURCE_REFRESH?_ds.parentDataSourceNo:null,IS_DATASOURCE_REFRESH:IS_DATASOURCE_REFRESH},args);delete data.SESSION_ID;const jsonP=await func.index.call_worker(SESSION_ID,{service:"datasource_create",data:data,id:SESSION_OBJ[SESSION_ID].worker_id});_session.DS_GLB[jsonP.dsSession]=jsonP;if(jsonP.dataSourceSessionGlobal>_session.dataSourceSessionGlobal){_session.dataSourceSessionGlobal=jsonP.dataSourceSessionGlobal}return done(SESSION_ID,jsonP.dsSession,true)})};func.datasource.prepare=async function(SESSION_ID,prog_id,dataSourceNoP,parentDataSourceNoP,containerIdP,rowIdP,jobNoP,calling_trigger_prop,parameters_raw_obj,NA_isInitP,callingSourceP,calling_jobP,NA_screen_dsP,is_panelP,parameters_obj_inP,static_refreshP,run_atP,worker_id){const set_parameters=async function(){var _session=SESSION_OBJ[SESSION_ID];const get_Out_parameters=async function(fieldIdP,located_field_param_idxP,param_row_idP){var ret=parameters_obj_inP?.[fieldIdP]||fieldIdP;PARAM_OUT_INFO[prog_id+"_"+param_row_idP]={module:_ds.viewModule,action:"parameters",prop:"out",details:ret,result:ret,source:_ds.viewSourceDesc,type:"parameters",prog_id:prog_id,dsSession:dataSourceSession,fieldId:fieldIdP,parentDataSourceNo:parentDataSourceNoP};return ret};const screenInfo=await func.utils.get_screen_obj(SESSION_ID,prog_id);if(screenInfo?.properties?.progParams){if(!xu_isEmpty(screenInfo.properties.progParams)){_ds.in_parameters={};_ds.out_parameters={};for await(let[key,val]of Object.entries(screenInfo.properties?.progParams)){if(val.data.dir==="in"){_ds.in_parameters[val.data.parameter]={type:val.data.type};if(typeof parameters_obj_inP?.[val.data.parameter]!=="undefined"){_ds.in_parameters[val.data.parameter].value=parameters_obj_inP[val.data.parameter]}else if(["live_preview","miniapp"].includes(_session.engine_mode)){_ds.in_parameters[val.data.parameter].value=_session?.url_params?.[val.data.parameter]}continue}if(val.data.dir==="out"&&val.data.parameter){_ds.out_parameters[val.data.parameter]=await get_Out_parameters(val.data.parameter,key,val.id)}}_ds.PARAM_OUT_INFO=PARAM_OUT_INFO}}};const build_GLOBAL_SYS_fields=function(){if(!_ds.data_system)_ds.data_system={};_ds.data_system["SYS_GLOBAL_UTC"]=-(new Date).getTimezoneOffset()/60;_ds.data_system["SYS_GLOBAL_STR_APP_ID"]=APP_OBJ[_session.app_id]._id;_ds.data_system["SYS_GLOBAL_STR_SESSION_ID"]=SESSION_ID;_ds.data_system["SYS_GLOBAL_STR_LOGIN_USER_ID"]=_session.USR_OBJ._id;if(!["live_preview","miniapp"].includes(_session.engine_mode)&&PROJECT_OBJ[_session.app_id].info){_ds.data_system["SYS_GLOBAL_OBJ_APP_INFO"]={build:PROJECT_OBJ[_session.app_id].info.build_id,author:PROJECT_OBJ[_session.app_id].info.author,date:PROJECT_OBJ[_session.app_id].info.build_date,name:APP_OBJ[_session.app_id].app_name}}_ds.data_system["SYS_GLOBAL_OBJ_LOGIN_USER_INFO"]={id:_session.USR_OBJ._id,user_name:_session.USR_OBJ.usr_name,first_name:_session.USR_OBJ.usr_first_name,last_name:_session.USR_OBJ.usr_last_name,email:_session.USR_OBJ.usr_email,profile_picture:_session.USR_OBJ.usr_profile_picture};_ds.data_system["SYS_GLOBAL_STR_BROWSER_HASH_ID"]=_session.SYS_GLOBAL_STR_BROWSER_HASH_ID;_ds.data_system["SYS_GLOBAL_STR_BROWSER_TITLE"]=_session.SYS_GLOBAL_STR_BROWSER_TITLE;_ds.data_system["SYS_GLOBAL_STR_SITE_CSS"]={};_ds.data_system["SYS_GLOBAL_BOL_SHIFT_KEY_STATE"]=0;_ds.data_system["SYS_GLOBAL_BOL_COMMAND_KEY_STATE"]=0;_ds.data_system["SYS_GLOBAL_BOL_CONTROL_KEY_STATE"]=0;_ds.data_system["SYS_GLOBAL_BOL_ALT_KEY_STATE"]=0;_ds.data_system["SYS_GLOBAL_BOL_ONLINE"]=0;_ds.data_system["SYS_GLOBAL_BOL_REPLICATION_STAT"]=0;_ds.data_system["SYS_GLOBAL_BOL_AJAX_BUSY"]=0;_ds.data_system["SYS_GLOBAL_BOL_CONNECTED"]=1;_ds.data_system["SYS_GLOBAL_BOL_IDLE"]=0;_ds.data_system["SYS_GLOBAL_STR_FIREBASE_TOKEN_ID"]=0;_ds.data_system["SYS_GLOBAL_BOL_PUSH_NOTIFICATION_GRANTED"]=_session.PUSH_NOTIFICATION_GRANTED;_ds.data_system["SYS_GLOBAL_OBJ_FIREBASE_AUTH_INFO"]=_session.SYS_GLOBAL_OBJ_FIREBASE_AUTH_INFO;_ds.data_system["SYS_GLOBAL_OBJ_CLIENT_INFO"]=_session.SYS_GLOBAL_OBJ_CLIENT_INFO;_ds.data_system["SYS_GLOBAL_OBJ_REFS"]={}};if(!SESSION_OBJ[SESSION_ID].DS_GLB)return;if(dataSourceNoP&&!SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceNoP]){return func.utils.debug_report(SESSION_ID,"Datasource","Datasource not exist: "+dataSourceNoP,"E")}if(!prog_id){return func.utils.debug_report(SESSION_ID,"Datasource","Program is null","E")}const args={SESSION_ID:SESSION_ID,prog_id:prog_id,dataSourceNoP:dataSourceNoP,parentDataSourceNoP:parentDataSourceNoP,containerIdP:containerIdP,rowIdP:rowIdP,jobNoP:jobNoP,calling_trigger_prop:calling_trigger_prop,calling_jobP:calling_jobP,is_panelP:is_panelP,parameters_obj_inP:parameters_obj_inP,static_refreshP:static_refreshP,run_atP:run_atP,worker_id:worker_id,parameters_raw_obj:parameters_raw_obj};var dataSourceSession=null;var IS_DATASOURCE_REFRESH=null;var PARAM_OUT_INFO={};const init_dataSource=async function(){const init_new_dataSource=async function(){if(!["main"].includes(SESSION_OBJ[SESSION_ID].opt.app_computing_mode)&&run_atP==="client"&&prog_id!=="system"){const ret=await func.index.call_worker(SESSION_ID,{service:"get_dataSourceSessionGlobal",data:{session_id:SESSION_ID},id:SESSION_OBJ[SESSION_ID].worker_id});SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal=ret?.new_dataSourceSessionGlobal||1}else{SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal++}dataSourceSession=SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal;SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession]={data_feed:{rows:[]}}};const init_existing_dataSource=function(){let _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceNoP];console.log("DATASOURCE_REFRESH",dataSourceNoP);IS_DATASOURCE_REFRESH=true;_ds.refreshed=true;if(_ds.watcher){xu_set(_ds,_ds.watcher.path,_ds.watcher.newValue)}try{if(!_ds.v)_ds.v={};delete _ds.v.old_dataSource;delete _ds.rows_found;_ds.data_feed={};_ds.v.old_dataSource=structuredClone(_ds)}catch(err){console.error("function: init_existing_dataSource - error");return}dataSourceSession=dataSourceNoP};if(typeof dataSourceNoP==="undefined"||dataSourceNoP===null){await init_new_dataSource()}else{init_existing_dataSource()}return SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession]};var _ds=await init_dataSource();_ds.stat="busy";_ds._run_at=run_atP;if(_ds.refreshed){await func.datasource.update(SESSION_ID,{[_ds.dsSession]:{["datasource_main"]:{stat:"busy",stat_ts:Date.now(),is_worker:glb.IS_WORKER}}})}if(IS_DATASOURCE_REFRESH){if(!static_refreshP)await set_parameters();return func.datasource.execute(SESSION_ID,dataSourceSession,true)}_ds.tree_obj=await func.utils.TREE_OBJ.get(SESSION_ID,prog_id);if(!_ds.tree_obj){return func.utils.debug_report(SESSION_ID,"Datasource","Program not exist: "+prog_id,"E")}await func.datasource.set_VIEW_data(SESSION_ID,args,_ds);if(!_ds.v.viewSourceDesc){_ds.v.viewSourceDesc=callingSourceP}if(dataSourceSession===0)_ds.v.viewSourceDesc="system startup";var _session=SESSION_OBJ[SESSION_ID];const set_DS_GLB=async function(){_ds.dataSource_init_arr={};_ds.containerId=containerIdP;_ds.jobNoP=jobNoP;_ds.viewSourceDesc=_ds.v.viewSourceDesc;_ds.callingSource=callingSourceP;_ds.calling_jobP=calling_jobP;_ds.viewModule=_ds.v.viewModule;_ds.viewSourceProp=_ds.v.viewSourceProp;_ds.dsSession=dataSourceSession;_ds.args=args;_ds.worker_id=worker_id;_ds.prog_id=prog_id;_ds.parentDataSourceNo=parentDataSourceNoP};await set_DS_GLB();if(prog_id==="system"&&!parentDataSourceNoP){build_GLOBAL_SYS_fields()}await set_parameters();_ds.client_interval=func.datasource.get_event_interval_arr(SESSION_ID,dataSourceSession,"client_interval");if(prog_id==="system"){_ds.server_interval=func.datasource.get_event_interval_arr(SESSION_ID,dataSourceSession,"server_interval")}let ret_execute=await func.datasource.execute(SESSION_ID,dataSourceSession);return ret_execute};func.datasource.execute=async function(SESSION_ID,dataSourceSession,IS_DATASOURCE_REFRESH){var _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dataSourceSession];var args=_ds.args;let tree_obj=await func.utils.TREE_OBJ.get(SESSION_ID,_ds.prog_id);let prog_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);const callback_datasource=async function(){const run_on_load_events=async function(){if(!await func.datasource.get_view_events_count(SESSION_ID,dataSourceSession,"on_load")){return false}await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"on_load");return true};const schedule_panel_on_load_events=function(){setTimeout(async function(){try{await run_on_load_events()}catch(error){console.error(error)}},0)};if(typeof IS_WORKER==="undefined"&&typeof IS_DOCKER==="undefined"&&typeof IS_PROCESS_SERVER==="undefined"&&_ds.viewSourceProp==="globals"){if(!["main"].includes(_session.opt.app_computing_mode)){await func.index.call_worker(SESSION_ID,{service:"create_webworker_globals",data:{ds_data:_ds,session_id:SESSION_ID}})}}if(args.is_panelP){const callback_ret=await func.datasource.callback(SESSION_ID,dataSourceSession,args.rowIdP,args.jobNoP,_ds.prog_id);schedule_panel_on_load_events();return callback_ret}await run_on_load_events();return await func.datasource.callback(SESSION_ID,dataSourceSession,args.rowIdP,args.jobNoP,_ds.prog_id)};const get_limit=async function(){var ret=0;let tree_ret=await func.utils.TREE_OBJ.get(SESSION_ID,_ds.prog_id);if(tree_ret.menuType==="get_data"){return 1}ret=_ds.progDataSource?.dataSourceLimit;if(prog_obj.progDataSource?.dataSourceLoopExp){ret=(await func.expression.get(SESSION_ID,prog_obj.progDataSource.dataSourceLoopExp,dataSourceSession,"view_loop",args.rowIdP)).result}return ret};const get_skip=async function(){var ret=0;ret=_ds.progDataSource?.dataSourceSkip;if(prog_obj.progDataSource?.dataSourceSkipExp){ret=(await func.expression.get(SESSION_ID,prog_obj.progDataSource.dataSourceSkipExp,dataSourceSession,"view_loop",args.rowIdP)).result}return ret};const calc_batch_loops=async()=>{if(!prog_obj.progDataSource?.dataSourceType||_ds.progDataSource.dataSourceType==="none"){_ds.v.batch_loops=await get_limit();return false}_ds.v.batch_loops=await get_limit()<=_ds.v.raw_data?.rows?.length?await get_limit():_ds.v.raw_data?.rows?.length;return true};const render_api_output=async function(){if(prog_obj?.scriptData?.value){var exp=await func.expression.get(SESSION_ID,prog_obj.scriptData.value,dataSourceSession,"api_rendered_output",null,null,null,null,null,null,null,null,null,tree_obj.apiOutput);let output_result=exp.result;if(tree_obj.apiOutput==="json"){try{let output_result_obj=await func.expression.secure_eval(SESSION_ID,"api_rendered_output","("+output_result+")",null,dataSourceSession);output_result=JSON.stringify(output_result_obj)}catch(err){console.error(err)}}_ds.api_rendered_output+=output_result+(tree_obj.apiOutput==="json"?",":"")}else{_ds.api_rendered_output=""}};if(_ds.prog_id==="system"){_ds.currentRecordId="dataset";await func.datasource.render_fields_dataset(SESSION_ID,dataSourceSession,{id:"dataset",value:_session.url_params});return await callback_datasource()}let db_adapter_module;if(prog_obj.progDataSource?.dataSourceType){db_adapter_module=await func.common.get_module(SESSION_ID,"xuda-datasource-db-adapter-module.mjs")}const get_data_from_source=async function(){switch(prog_obj.progDataSource.dataSourceSrcType){case"input":{const{result,error}=await func.expression.get(SESSION_ID,prog_obj.progDataSource.progDataSourceInput,dataSourceSession,"datasource select");if(error){func.utils.debug_report(SESSION_ID,"Data source",`Datasource parse error using ${prog_obj.progDataSource?.dataSourceType} input`,"E");return null}return result;break}case"url":{let opt={method:prog_obj.progDataSource.dataSourceMethod||"POST",headers:{Accept:"application/json","Content-Type":"application/json"}};let data={};if(prog_obj.progDataSource.dataSourceMethod=="POST"&&prog_obj.progDataSource.dataSourceParameters){for(let val of prog_obj.progDataSource.dataSourceParameters){data[val.key]=val.val}opt.body=JSON.stringify(data)}try{const response=await fetch("https://"+prog_obj.progDataSource.dataSourceDataUrl,opt);const json=await response.json();return json.data}catch(err){func.utils.debug_report(SESSION_ID,"Data source",err.message+" https://"+prog_obj.progDataSource.dataSourceDataUrl,"E");return null}break}default:return null;break}};if(!_ds.v.raw_data){_ds.v.raw_data={rows:[]}}_ds.data_feed.rows=[];switch(prog_obj.progDataSource?.dataSourceType){case"table":{_ds._dataSourceTableId=prog_obj.progDataSource?.dataSourceTableId;if(prog_obj.progDataSource?.dataSourceTableIdExp){_ds.v.dataSourceTableIdExp=await func.expression.get(SESSION_ID,prog_obj.progDataSource?.dataSourceTableIdExp,dataSourceSession,"dataSourceTableIdExp",args.rowIdP);if(_ds.v.dataSourceTableIdExp.result){_ds._dataSourceTableId=_ds.v.dataSourceTableIdExp.result}else{func.utils.debug_report(SESSION_ID,"get_VIEW_data","Table Expression returned empty result","W")}}if(!_ds._dataSourceTableId){return func.utils.debug_report(SESSION_ID,"Data source","Table cannot be empty when Db Table selected","E")}let table_ret=await func.utils.TREE_OBJ.get(SESSION_ID,_ds._dataSourceTableId);if(!table_ret){return func.utils.debug_report(SESSION_ID,"Data source","Table not found: "+_ds._dataSourceTableId,"E")}await db_adapter_module.build_filter(SESSION_ID,dataSourceSession,_ds.v,_ds);let filterModelMongo=_ds.progDataSource.filterModelMongo;if(_ds.progDataSource.filterModelMongoFx){let ret=await func.expression.get(SESSION_ID,_ds.progDataSource.filterModelMongoFx,dataSourceSession,"query");filterModelMongo=ret.result}let filterModelSql=_ds.progDataSource.filterModelSql;if(_ds.progDataSource.filterModelSqlFx){let ret=await func.expression.get(SESSION_ID,_ds.progDataSource.filterModelSqlFx,dataSourceSession,"query");filterModelSql=ret.result}const filterModel={filterModelNative:_ds.progDataSource.filterModelNative,filterModelMongo:filterModelMongo,filterModelSql:filterModelSql,filterModelUserMongo:_ds.progDataSource.filterModelUserMongo,filterModelUserSql:_ds.progDataSource.filterModelUserSql};let _dataSourceFilterModelType=_ds?.progDataSource?.dataSourceFilterModelType;if(_ds?.progDataSource?.dataSourceFilterModelTypeFx){const fx_ret=await func.expression.get(SESSION_ID,_ds.progDataSource.dataSourceFilterModelTypeFx,dataSourceSession,"query");_dataSourceFilterModelType=fx_ret.result}if(_dataSourceFilterModelType&&!["query","index"].includes(_dataSourceFilterModelType)){return func.utils.debug_report(SESSION_ID,"Data source",`Valid values for dataSourceFilterModelType are: "query" or "index" (${_dataSourceFilterModelType})`,"E")}_ds.v.raw_data=await func.db.get_query(SESSION_ID,_ds._dataSourceTableId,_ds.v.couchView,dataSourceSession,_ds.viewSourceDesc,"datasource table",prog_obj.progDataSource.dataSourceReduce,await get_skip(),await get_limit()||99999999,null,null,_ds?.progDataSource?.sortModel,null,filterModel,_dataSourceFilterModelType);if(_dataSourceFilterModelType==="index"&&_ds?.progDataSource?.sortModel){function sortByKeys(array,sortConfig){return array.sort((a,b)=>{for(let config of sortConfig){const key=config.field_id;const direction=config.sort_dir==="desc"?-1:1;const valA=a.value[key];const valB=b.value[key];if(typeof valA==="number"&&typeof valB==="number"){if(valA!==valB){return(valA-valB)*direction}}else if(typeof valA==="string"&&typeof valB==="string"){if(valA!==valB){return valA.localeCompare(valB)*direction}}}return 0})}const sorted=sortByKeys(_ds.v.raw_data.rows,_ds.progDataSource.sortModel);_ds.v.raw_data.rows=sorted}if(_ds?.progDataSource?.dataSourceLimit){const ret_rows_found=await func.db.get_query(SESSION_ID,_ds._dataSourceTableId,_ds.v.couchView,dataSourceSession,_ds.viewSourceDesc,"datasource table",prog_obj.progDataSource.dataSourceReduce,null,null,true,null,null,null,filterModel,_dataSourceFilterModelType);_ds.rows_found=ret_rows_found?.rows?.[0]?.value||0;_ds.rows_found_opt=ret_rows_found?.opt}else{_ds.rows_found=_ds?.v?.raw_data?.rows?.length||0;_ds.rows_found_opt=_ds?.v?.raw_data?.opt}break}case"array":{let data=await get_data_from_source();if(data===null){data=[]}_ds.rows_found=data?.length||0;let _KEY=0;for(const _VAL of data){_ds.v.raw_data.rows.push({id:_KEY,value:{_KEY:_KEY,_VAL:_VAL}});_KEY++}break}case"json":{let data=await get_data_from_source();if(data===null){data={}}_ds.rows_found=Object.keys(data)?.length||0;for(let[_KEY,_VAL]of Object.keys(data)){_ds.v.raw_data.rows.push({id:_KEY,value:{_KEY:_KEY,_VAL:_VAL}})}break}case"csv":{let data=await get_data_from_source();if(data===null){data=""}let _KEY=0;let arr=data.split(",");for(const _VAL of arr){_ds.v.raw_data.rows.push({id:_KEY,value:{_KEY:_KEY,_VAL:_VAL}});_KEY++}_ds.rows_found=arr?.length||0;break}default:break}let ret;const get_before_record_count=async()=>{return await func.datasource.get_view_events_count(SESSION_ID,dataSourceSession,"before_record")};const get_after_record_count=async()=>{return await func.datasource.get_view_events_count(SESSION_ID,dataSourceSession,"after_record")};let _raw_data_rows=[];switch(tree_obj.menuType){case"api":{_ds.api_rendered_output="";let has_datasource=await calc_batch_loops();_raw_data_rows=_ds.v.raw_data.rows||[];if(!has_datasource){for(n=0;n<_ds.v.batch_loops;n++){_raw_data_rows.push({id:n,value:{}})}}_ds.currentRecordId="dataset";for await(let[key,raw_data_row]of Object.entries(_raw_data_rows)){if(has_datasource&&Number(key)>=_ds.v.batch_loops)break;if(!has_datasource){raw_data_row=_ds?.v.raw_data?.rows?.[key]||{id:key,value:{}}}if(await get_before_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"before_record")}await func.datasource.render_fields_dataset(SESSION_ID,dataSourceSession,raw_data_row);if(await get_after_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"after_record")}await render_api_output()}if(tree_obj.apiOutput==="json"){var str=_ds.api_rendered_output.substring(0,_ds.api_rendered_output.length-1);if(Number(_ds.progDataSource?.dataSourceLimit)===1){_ds.api_rendered_output=str}else{_ds.api_rendered_output="["+str+"]"}}break}case"batch":{let has_datasource=await calc_batch_loops();_raw_data_rows=_ds?.v.raw_data?.rows||[];if(!has_datasource){for(n=0;n<_ds.v.batch_loops;n++){_raw_data_rows.push({id:n,value:{}})}}_ds.currentRecordId="dataset";for await(let[key,raw_data_row]of Object.entries(_raw_data_rows)){if(has_datasource&&Number(key)>=_ds.v.batch_loops)break;if(!has_datasource){raw_data_row=_ds?.v.raw_data?.rows?.[key]||{id:key,value:{}}}if(await get_before_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"before_record")}await func.datasource.render_fields_dataset(SESSION_ID,dataSourceSession,raw_data_row);if(await get_after_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"after_record")}}await func.datasource.set_outputField(SESSION_ID,dataSourceSession,_ds?.v?.raw_data?.rows,_ds.args);break}case"get_data":{if(await get_before_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"before_record")}ret=await db_adapter_module.process_view_dataset(SESSION_ID,dataSourceSession,_ds);if(await get_after_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"after_record")}await func.datasource.set_outputField(SESSION_ID,dataSourceSession,_ds?.v?.raw_data?.rows,_ds.args);break}case"set_data":{if(!prog_obj.progDataSource?.dataSourceType||_ds.progDataSource.dataSourceType!=="table"||!_ds._dataSourceTableId){return func.utils.debug_report(SESSION_ID,"Data source","Datasource DB Table must be defined for Set Data operation","E")}const find_ROWID_idx_from_raw_data_arr=function(rowId){if(!_raw_data_rows){throw new Error("_raw_data_rows not found")}const index=_raw_data_rows.findIndex(item=>item.id===rowId);if(index===-1){throw new Error(`ROWID "${rowId}" not found`)}return index};if(tree_obj.crudMode==="U"){_ds.set_mode="U";_raw_data_rows=_ds?.v.raw_data?.rows||[]}if(tree_obj.crudMode==="D"){_ds.set_mode="D";_raw_data_rows=_ds?.v.raw_data?.rows||[]}if(tree_obj.crudMode==="U"&&tree_obj.allowCreate&&!_raw_data_rows?.length){_ds.set_mode="C";try{const row_idx=find_ROWID_idx_from_raw_data_arr("newRecord");_raw_data_rows[row_idx]=[{id:"newRecord",value:{}}]}catch(error){_raw_data_rows.push({_ROWID:"newRecord"})}}if(tree_obj.crudMode==="C"){_ds.set_mode="C";try{const row_idx=find_ROWID_idx_from_raw_data_arr("newRecord");_raw_data_rows[row_idx]=[{id:"newRecord",value:{}}]}catch(error){_raw_data_rows.push({id:"newRecord",value:{}})}}for await(let raw_data_row of _raw_data_rows){_ds.currentRecordId=raw_data_row.id;if(await get_before_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"before_record")}await func.datasource.render_fields_dataset(SESSION_ID,dataSourceSession,raw_data_row);let data_feed_str=JSON.stringify(_ds.data_feed);if(await get_after_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"after_record")}if(_ds.set_mode==="C"||JSON.stringify(_ds.data_feed)!==data_feed_str){const dbMsgP=await func.db.save_data(SESSION_ID,dataSourceSession);if(dbMsgP)_ds.currentRecordId=dbMsgP.id;_ds.set_mode="U"}if(_ds.set_mode==="D"){const dbMsgP=await func.db.save_data(SESSION_ID,dataSourceSession);if(dbMsgP)_ds.currentRecordId=dbMsgP.id}}await func.datasource.set_outputField(SESSION_ID,dataSourceSession,_ds?.v?.raw_data?.rows,_ds.args);break}case"component":{_raw_data_rows=_ds?.v.raw_data?.rows||[];_ds.rows_processed=0;_ds.viewRangeExp_rows_deleted=0;let rows=_ds?.v.raw_data?.rows?.length;_ds.data_feed.rows_changed=[];_ds.data_feed.rows_deleted=[];_ds.data_feed.rows_added=[];if(tree_obj.rwMode==="U"){_ds.set_mode="U"}else{_ds.set_mode="R"}const row_not_found=async function(){if(!prog_obj.progDataSource?.dataSourceType||prog_obj.properties.renderType==="form"||tree_obj.rwMode==="U"&&tree_obj.allowCreate){_ds.currentRecordId="newRecord";if(tree_obj.rwMode==="U"&&tree_obj.allowCreate){_ds.set_mode="C"}if(prog_obj.progDataSource?.dataSourceType){_ds.record_not_found=true}try{const row_idx=func.common.find_ROWID_idx(_ds,_ds.currentRecordId)}catch(error){await func.datasource.render_fields_form(SESSION_ID,dataSourceSession,{id:"newRecord",value:{}})}var count=await func.datasource.get_field_init_count(SESSION_ID,dataSourceSession,"newRecord",false);if(count>0){await func.datasource.execute_field_init_events(SESSION_ID,dataSourceSession,"form","newRecord")}}await func.datasource.callback(SESSION_ID,dataSourceSession,args.rowIdP,args.jobNoP,_ds.prog_id)};if(!rows){await row_not_found();break}_ds.firstRecordId=_raw_data_rows[0].id;const finish_form=async function(){if(_ds.locatedRecordId){try{const row_idx=func.common.find_ROWID_idx(_ds,_ds.locatedRecordId)}catch(error){delete _ds.locatedRecordId}}_ds.finalRecordId=func.datasource.get_currentRecordId(SESSION_ID,dataSourceSession,true);_ds.currentRecordId=_ds.finalRecordId};for await(const[key,raw_data_row]of Object.entries(_raw_data_rows)){const idx=Number(key);if(await get_before_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"before_record")}_ds.currentRecordId=raw_data_row.id;await func.datasource.render_fields_form(SESSION_ID,dataSourceSession,raw_data_row);try{const init_count=await func.datasource.get_field_init_count(SESSION_ID,dataSourceSession,raw_data_row.id,false,_ds.oninit_triggers_to_run);if(init_count>0){await func.datasource.execute_field_init_events(SESSION_ID,dataSourceSession,"form",raw_data_row.id)}}catch(err){console.error(err)}if(await get_after_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"after_record")}}await finish_form();break}default:return func.utils.debug_report(SESSION_ID,"Data source","Program type not defined","E")}ret=await callback_datasource();return ret};func.datasource.render_fields_dataset=async function(SESSION_ID,dataSourceSession,raw_data_row){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var args=_ds.args;const _progFields=await func.datasource.get_progFields(SESSION_ID,dataSourceSession);if(!_progFields){return}const get_value=async(field_id,value)=>{let view_field_obj=func.common.find_item_by_key(_progFields,"field_id",field_id);var fieldType=view_field_obj?.props?.fieldType;let table_field_obj;if(view_field_obj.data.type==="table"&&field_id!=="REDUCE_VALUE"){if(!_ds.progDataSource?.dataSourceTableId){return func.utils.debug_report(SESSION_ID,"Datasource",`Table type defined without dataSourceTableId deceleration`,"E")}let table_obj=await func.utils.FILES_OBJ.get(SESSION_ID,_ds._dataSourceTableId);if(!table_obj){return func.utils.debug_report(SESSION_ID,"Datasource",`dataSourceTableId reference error: `+_ds._dataSourceTableId,"E")}table_field_obj=func.common.find_item_by_key(table_obj.tableFields,"field_id",field_id);fieldType=table_field_obj.props?.fieldType}return await func.common.get_cast_val(SESSION_ID,`render fields dataset ${_ds.viewSourceDesc}`,field_id,fieldType,value,null)};if(!_ds.data_feed){_ds.data_feed={rows:[{_ROWID:_ds.currentRecordId}]}}let row_idx;try{row_idx=func.common.find_ROWID_idx(_ds,_ds.currentRecordId)}catch(err){_ds.data_feed.rows.push({_ROWID:_ds.currentRecordId});row_idx=func.common.find_ROWID_idx(_ds,_ds.currentRecordId)}_ds.dataset_alias={};for await(const val of _progFields){try{var fieldId=val.data.field_id;if(val.data.type==="virtual"||_ds.set_mode==="C"){if(typeof raw_data_row?.value?.[fieldId]!=="undefined"){_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,raw_data_row.value[fieldId]);continue}if(val.props?.propExpressions?.fieldValue){let ret=await func.expression.get(SESSION_ID,val.props?.propExpressions?.fieldValue,dataSourceSession,"update",args.rowIdP);_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,ret.result);continue}_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,val.props?.fieldValue);continue}if(val.data.type==="table"||val.data.type==="datasource"){if(typeof raw_data_row.value[fieldId]==="undefined"){throw"field do not exist in data: "+fieldId}_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,raw_data_row.value[fieldId])}}catch(err){func.utils.debug_report(SESSION_ID,"Datasource",err,"E",null,_ds)}}};func.datasource.run_events_functions=async function(SESSION_ID,dataSourceSession,event_id,calling_job,async_event,event_parameters){if(typeof dataSourceSession==="undefined"||dataSourceSession===null){console.warn(`Event ${event_id} not exist or not found`);return}var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var args=_ds.args;const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);let job_promises=[];if(_view_obj.progEvents){for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val.data.type==="user_defined"&&val.data.event_name&&val.data.event_name===event_id){const jobs=await func.events.validate(SESSION_ID,"user_defined",dataSourceSession,val.data.event_name,args.callingSourceP,event_parameters);if(calling_job||async_event)continue;for(let job_num of jobs){job_promises.push(new Promise((resolve,reject)=>{let i=0;const interval=setInterval(()=>{i++;var job_index=func.events.find_job_index(SESSION_ID,job_num);if(job_index==null){clearInterval(interval);resolve(job_num)}if(i>200){console.error("deadlock detected");clearInterval(interval);resolve(job_num)}},100)}))}}}}if(job_promises.length){await Promise.all(job_promises)}};func.datasource.render_fields_form=async function(SESSION_ID,dataSourceSession,raw_data_row){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];const _progFields=await func.datasource.get_progFields(SESSION_ID,dataSourceSession);if(!_progFields){return}const get_value=async(field_id,value)=>{let view_field_obj=func.common.find_item_by_key(_progFields,"field_id",field_id);var fieldType=view_field_obj.props?.fieldType;let table_field_obj;if(view_field_obj.data.type==="table"&&field_id!=="REDUCE_VALUE"){if(!_ds._dataSourceTableId){return func.utils.debug_report(SESSION_ID,"Datasource",`Table type defined without dataSourceTableId deceleration`,"E")}let table_obj=await func.utils.FILES_OBJ.get(SESSION_ID,_ds._dataSourceTableId);if(!table_obj){return func.utils.debug_report(SESSION_ID,"Datasource",`dataSourceTableId reference error: `+_ds._dataSourceTableId,"E")}table_field_obj=func.common.find_item_by_key(table_obj.tableFields,"field_id",field_id);if(!table_field_obj){return func.utils.debug_report(SESSION_ID,"Datasource",`Field Id: ${field_id} not exist in table ${table_obj.properties.menuName}`,"E")}fieldType=table_field_obj.props?.fieldType}return await func.common.get_cast_val(SESSION_ID,`render fields datasource ${_ds.viewSourceDesc}`,field_id,fieldType,value,null)};let row_idx;try{row_idx=func.common.find_ROWID_idx(_ds,raw_data_row.id)}catch(error){_ds.data_feed.rows.push({_ROWID:raw_data_row.id});row_idx=func.common.find_ROWID_idx(_ds,raw_data_row.id)}_ds.dataset_alias={};for await(const val of _progFields){try{var fieldId=val.data.field_id;if(val.data.type==="virtual"||raw_data_row.id==="newRecord"){if(glb.PROTECTED_VARS.includes(fieldId)){switch(fieldId){case"_ROWNO":{_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,row_idx);continue}case"_ROWID":{_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,raw_data_row.id);continue}case"_ROWDOC":{_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,raw_data_row.value);continue}}}if(val.props?.propExpressions?.fieldValue){let ret=await func.expression.get(SESSION_ID,val.props?.propExpressions?.fieldValue,dataSourceSession,"update",raw_data_row.id);_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,ret.result);continue}_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,val.props?.fieldValue);continue}if(val.data.type==="table"||val.data.type==="datasource"){if(typeof raw_data_row.value[fieldId]==="undefined"){throw"field do not exist in data: "+fieldId}_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,raw_data_row.value[fieldId])}}catch(err){func.utils.debug_report(SESSION_ID,"Datasource",err,"E",null,_ds)}}};func.datasource.execute_field_init_events=async function(SESSION_ID,dataSourceSession,sourceP,rowIdP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var args=_ds.args;var arr=_ds.dataSource_init_arr[rowIdP];for await(const val of arr){if(!func.utils.is_onscreen_event(val.eventInfo.data.action)){var cond=val?.eventInfo?.data?.enabled;var expression=undefined;if(val.eventInfo.props.condition)expression=val.eventInfo.props.condition;var expCond={};if(expression&&!xu_isEmpty(expression)){expCond=await func.expression.get(SESSION_ID,expression,dataSourceSession,"condition",rowIdP,null,null,val.fieldId);cond=expCond.result;expCond.conditional=true;val.DEBUG_INFO_OBJ.result=expCond.result;val.DEBUG_INFO_OBJ.error=expCond.error;val.DEBUG_INFO_OBJ.fields=expCond.fields;val.DEBUG_INFO_OBJ.conditional=expCond.conditional;val.DEBUG_INFO_OBJ.details=expression}func.utils.debug.log(SESSION_ID,val.node_id,val.DEBUG_INFO_OBJ);if(cond){if(!_ds)continue;var ds=_ds.prog_id;await func.events.execute(SESSION_ID,null,val.triggerId,val.eventInfo.data.name,val.eventInfo.data.action,val.eventInfo.data.name,null,val.fieldId,val.rowId,val.colId,null,null,dataSourceSession,val.eventInfo.id,sourceP,true,null,null,args.jobNoP,null,null,val.eventInfo,null,null,null,null,ds.parentDataSourceNo,null)}}}};func.datasource.get_field_init_count=async function(SESSION_ID,dataSourceSession,rowIdP,pre_initP,oninit_triggers_to_runP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var args=_ds.args;const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);var ret=0;for await(const field_obj of _view_obj.progFields){var fieldId=field_obj.data.field_id;if(!field_obj?.workflow?.length){continue}for await(const trigger_obj of field_obj.workflow){if(oninit_triggers_to_runP&&!oninit_triggers_to_runP?.includes(trigger_obj.id)){continue}if(["get_data","set_data","batch","update","raise_event"].includes(trigger_obj.data.action)){if(!trigger_obj.data.action){func.utils.debug_report(SESSION_ID,"_ds.get_field_init_count",`Error initiating event for field: ${fieldId} prog: ${_ds.v.viewSourceDesc} row: ${rowIdP} reason: missing action`,"E");break}if(trigger_obj.data.enabled){if(!_ds.dataSource_init_arr[rowIdP]){_ds.dataSource_init_arr[rowIdP]=[]}_ds.dataSource_init_arr[rowIdP].push({eventInfo:trigger_obj,triggerId:trigger_obj.id,fieldId:fieldId,rowId:rowIdP,colId:field_obj.id,node_id:args.prog_id+"_"+trigger_obj.id+"_"+field_obj.id,fieldProp:field_obj,DEBUG_INFO_OBJ:{module:_ds.viewModule,action:"init field event",prop:fieldId,source:_ds.viewSourceDesc,type:"event",prog_id:args.prog_id,dsSession:dataSourceSession}});ret++}}}}return ret};func.datasource.get_view_events_count=async function(SESSION_ID,dataSourceSession,typeP,eventIdP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];const _prog=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(!_ds)return 0;var args=_ds.args;var index=typeP;if(eventIdP)index=typeP+"_"+eventIdP;if(!_ds.viewEventExec_arr)_ds.viewEventExec_arr={};_ds.viewEventExec_arr[index]=[];if(!_prog.progEvents||xu_isEmpty(_prog.progEvents))return 0;for(const event_obj of _prog.progEvents){if(event_obj.data.type!==typeP)continue;if(eventIdP&&event_obj.id!==eventIdP)continue;if(event_obj.data.condition){let res=await func.expression.get(SESSION_ID,event_obj.data.condition,dataSourceSession,"condition",args.rowIdP,null,null,null,null,event_obj);if(!res.result){continue}}if(xu_isEmpty(event_obj.workflow))continue;for(const trigger_obj of event_obj.workflow){if(trigger_obj.data.enabled){var expression;if(trigger_obj.props.condition)expression=trigger_obj.props.condition;var expCond={};if(expression){expCond.conditional=true}func.utils.debug.log(SESSION_ID,args.prog_id+"_"+trigger_obj.id,{module:_ds.viewModule,action:trigger_obj.data.action,prop:event_obj.data.type,details:expression,result:expCond.result,error:expCond.error,source:_ds.viewSourceDesc,fields:expCond.fields,type:"event",prog_id:args.prog_id,dsSession:dataSourceSession,conditional:expCond.conditional})}if(!trigger_obj.data.action){func.utils.debug_report(SESSION_ID,"get_view_events_count",`Error initiating ${typeP} prog:${_ds.v.viewSourceDesc} reason: missing action`,"E");break}if(!glb.REFERENCE_LESS_FUNCTIONS.includes(trigger_obj.data.action)&&!trigger_obj.data.action){func.utils.debug_report(SESSION_ID,"get_view_events_count",`Error initiating ${typeP} prog: ${_ds.v.viewSourceDesc} reason: missing reference`,"E");break}if(trigger_obj.data.enabled){_ds.viewEventExec_arr[index].push({eventInfo:trigger_obj,eventId:event_obj.id,triggerId:trigger_obj.id,expression:expression})}}}return _ds.viewEventExec_arr[index].length};func.datasource.execute_view_events=async function(SESSION_ID,dataSourceSession,typeP,eventIdP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var args=_ds.args;var i=-1;var index=typeP;if(eventIdP)index=typeP+"_"+eventIdP;var arr=_ds.viewEventExec_arr[index];if(xu_isEmpty(arr))return;for await(const val of arr){if(!glb.IS_WORKER||!func.utils.is_onscreen_event(val.eventInfo.data.action)||glb.IS_WORKER&&_ds.v.run_at==="server"&&!func.utils.is_onscreen_event(val.eventInfo.data.action)){var cond=true;if(val.expression){var expCond=await func.expression.get(SESSION_ID,val.expression,dataSourceSession,"condition",args.rowIdP,null,null,null,null,val.eventInfo);cond=expCond.result}if(cond){var elem_params=undefined;if(!glb.IS_WORKER){const container_meta=func.runtime.ui.get_meta_by_element_id(_ds.containerId);elem_params=container_meta?.params}const ret=await func.events.execute(SESSION_ID,null,val.triggerId,val.eventInfo.data.trigger,val.eventInfo.data.action,val.eventInfo.data.name,null,null,null,null,val.eventInfo.data.action,null,dataSourceSession,val.eventId,_ds.tree_obj.menuType+" event",true,null,null,args.jobNoP,elem_params,null,val.eventInfo)}continue}if(typeP=="before_record"||typeP=="after_record"||typeP=="on_load"||typeP=="on_exit"){_ds.v.onscreen_events_active={i:i,type:typeP};var parent_ds_chain=func.datasource.get_parent_ds_chain(SESSION_ID,dataSourceSession);var obj={ds_obj:func.utils.clean_returned_datasource(SESSION_ID,dataSourceSession),dsSessionP:dataSourceSession};obj.ds_obj.parent_ds_chain=parent_ds_chain}}};func.datasource.get_parent_ds_chain=function(SESSION_ID,dataSourceSession){var arr=[];var drill=function(ds){if(SESSION_OBJ[SESSION_ID].DS_GLB[ds]){if(typeof SESSION_OBJ[SESSION_ID].DS_GLB[ds].parentDataSourceNo!=="undefined"){arr.push(SESSION_OBJ[SESSION_ID].DS_GLB[ds].parentDataSourceNo);drill(SESSION_OBJ[SESSION_ID].DS_GLB[ds].parentDataSourceNo)}}};drill(dataSourceSession);return arr};func.datasource.execute_onscreen_view_events=async function(SESSION_ID,dataSourceSession,sourceP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var args=_ds.args;var i=_ds.v.onscreen_events_active.i;var type=_ds.v.onscreen_events_active.type;var evnt;if(_ds.viewEventExec_arr?.[type]?.[i]){evnt=_ds.viewEventExec_arr[type][i];evnt.done=true;var cond=true;if(evnt.expression){var expCond=await func.expression.get(SESSION_ID,evnt.expression,dataSourceSession,"condition",args.rowIdP);cond=expCond.result}if(cond){let ret=await func.events.execute(SESSION_ID,null,evnt.triggerId,evnt.eventInfo.data.trigger,evnt.eventInfo.data.action,evnt.eventInfo.data.name,null,null,null,null,evnt.eventInfo.data.name,null,dataSourceSession,null,sourceP+" event",true,null,null,args.jobNoP)}}else console.error("*execute_onscreen_view_events error")};func.datasource.get_event_interval_arr=function(SESSION_ID,dataSourceSession,typeP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var arr=[];var ret=0;if(!_ds.v.progEvents)return 0;for(let val of _ds.v.progEvents){if(val.data.type!==typeP)continue;arr.push([val.id,val.data.properties,val.data.condition])}return arr};func.datasource.clean_all=function(SESSION_ID,dsP){var arr=[dsP];var get_child_ds=function(ds){var arr=[];for(const[key,val]of Object.entries(SESSION_OBJ[SESSION_ID].DS_GLB)){if(val.parentDataSourceNo==ds){arr.push(key);arr=arr.concat(get_child_ds(key))}}return arr};arr=arr.concat(get_child_ds(dsP));for(let val of arr){func.datasource.del(SESSION_ID,val)}};func.datasource.clean=function(SESSION_ID,screenIdP){var arr=[];for(const[key,val]of Object.entries(SESSION_OBJ[SESSION_ID].DS_GLB)){try{const screen_parent_id=val.screenId&&func.runtime?.ui?.get_parent_element_id?func.runtime.ui.get_parent_element_id(val.screenId):null;if(Number(key)>0&&(val.screenId===screenIdP||val.rootScreenId===screenIdP||screen_parent_id===screenIdP||val&&val.parentDataSourceNo&&arr.includes(val.parentDataSourceNo.toString()))){arr.push(key);if(val.screenId&&func.UI?.utils?.screen_blocker)func.UI.utils.screen_blocker(false,val.screenId)}}catch(err){console.warn("func.datasource.clean failed");func.datasource.reset_jobs(SESSION_ID,key,"datasource.clean",err)}}for(let val of arr){func.datasource.del(SESSION_ID,val)}};func.datasource.del=function(SESSION_ID,dsP){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsP]&&SESSION_OBJ[SESSION_ID].DS_GLB[dsP].keep_alive||dsP==0)return;if(DATASOURCE_INTERVALS[SESSION_ID]&&DATASOURCE_INTERVALS[SESSION_ID][dsP]){DATASOURCE_INTERVALS[SESSION_ID][dsP].clear()}const perform_delete=async function(){var response={success:function(jsonP,ajaxP){},error:function(status){console.error("error datasource:"+status)},fail:function(status){console.error("error datasource:"+status)}};var data={session_id:SESSION_ID,dssession:dsP};if(!SESSION_OBJ[SESSION_ID].DS_GLB[dsP])return;if(!glb.IS_WORKER){let _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsP];if(_ds.worker_id){if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){WEB_WORKER[SESSION_ID][_ds.worker_id].emit("message",{service:"close_websocket"})}else{WEB_WORKER[SESSION_ID][_ds.worker_id].worker.terminate()}delete WEB_WORKER[SESSION_ID][_ds.worker_id]}else{const json=await func.index.call_worker(SESSION_ID,{service:"datasource_delete",data:data,id:_ds.worker_id});response.success(json,true)}if(DS_UI_EVENTS_GLB)delete DS_UI_EVENTS_GLB[dsP]}delete SESSION_OBJ[SESSION_ID].DS_GLB[dsP]};var delete_pending_jobs=function(){var arr=[];for(const[key,val]of Object.entries(SESSION_OBJ[SESSION_ID].WORKER_OBJ.jobs)){if(val&&val.dsSessionP==dsP){arr.push(key);func.runtime.ui.clear_screen_blockers()}}for(let val of arr.reverse()){SESSION_OBJ[SESSION_ID].WORKER_OBJ.jobs.splice(val,1)}if(!SESSION_OBJ[SESSION_ID].WORKER_OBJ.jobs.length)SESSION_OBJ[SESSION_ID].WORKER_OBJ.stat=null};if(!glb.IS_WORKER){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsP]){delete SCREEN_BLOCKER_OBJ[SESSION_OBJ[SESSION_ID].DS_GLB[dsP].screenId+"_"+SESSION_OBJ[SESSION_ID].DS_GLB[dsP].callingScreenId];delete_pending_jobs();if(glb.new_xu_render){for(const[ui_cache_key,ui_cache_val]of Object.entries(UI_WORKER_OBJ.xu_render_cache)){if(ui_cache_val.paramsP.dsSessionP===dsP){delete UI_WORKER_OBJ.xu_render_cache[ui_cache_key]}}}}const _nav_node=func.runtime.ui.get_first_node(SESSION_OBJ[SESSION_ID].root_element)?.querySelector?.("xu-nav");if(_nav_node){var ds_obj=func.runtime.ui.get_data(_nav_node)?.xuData?.nav_params;if(ds_obj){delete ds_obj[dsP]}}}perform_delete()};func.datasource.update=async function(SESSION_ID,datasource_changes,update_local_scope_only,avoid_xu_for_refresh,trigger){return new Promise(async(resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(_session.IS_API||typeof IS_MASTER_WEBSOCKET!=="undefined"||typeof IS_PROCESS_SERVER!=="undefined"){update_local_scope_only=true}if(typeof glb.GLOBAL_VARS==="undefined"){glb.GLOBAL_VARS=(await func.common.get_module(SESSION_ID,"xuda-system-globals-module.mjs")).system_globals}const set_fieldComputed_dependencies=async function(dsNo,field_id,parent_ds){for(const[dsSession,_ds]of Object.entries(_session.DS_GLB)){if(parent_ds!==null){if(_ds.parentDataSourceNo!=parent_ds)continue}else{if(dsSession!=dsNo)continue}let tree_ret=await func.utils.TREE_OBJ.get(SESSION_ID,_ds.prog_id);if(tree_ret.menuType==="component"||tree_ret.menuType==="globals"){const _progFields=await func.datasource.get_progFields(SESSION_ID,dsSession);let fieldComputed_propExpressions,fieldComputed_id;for await(const val of _progFields){const fieldId=val.data.field_id;if(val.data.type!=="virtual"||!val.props.fieldComputed)continue;const _propExpressions=val.props?.propExpressions?.fieldValue;if(_propExpressions&&JSON.stringify(_propExpressions).includes(field_id)){fieldComputed_propExpressions=_propExpressions;fieldComputed_id=fieldId}}if(!fieldComputed_id)return;for(const row of _ds.data_feed?.rows||[]){for(const[key,val]of Object.entries(row)){if(key!==fieldComputed_id)continue;try{let ret=await func.expression.get(SESSION_ID,fieldComputed_propExpressions,dsNo,"update",row._ROWID);const row_idx=func.common.find_ROWID_idx(_ds,row._ROWID);if(_ds.data_feed.rows[row_idx][fieldComputed_id]!==ret.result){_ds.data_feed.rows[row_idx][fieldComputed_id]=ret.result;if(!fields_changed.includes(fieldComputed_id)){fields_changed.push(fieldComputed_id)}if(!datasource_changed.includes(dsSession)){datasource_changed.push(dsSession)}}}catch(err){console.error(err)}}}}await set_fieldComputed_dependencies(dsNo,field_id,dsSession)}};var fields_changed=[];var datasource_changed=[];let client_datasource_changes={};let server_datasource_changes={};const mark_field_changed=async function(dataSource,field_id){if(!fields_changed.includes(field_id)){fields_changed.push(field_id);for(const[_dsSession,_ds]of Object.entries(_session.DS_GLB)){if(_ds.args.parameters_raw_obj){for(const[key,exp]of Object.entries(_ds.args.parameters_raw_obj)){if(exp.includes(field_id)){let ret=await func.expression.get(SESSION_ID,exp,_dsSession,"parameters");_ds.in_parameters[key].value=ret.result}}}}}if(!datasource_changed.includes(dataSource)){datasource_changed.push(dataSource)}};const queue_remote_change=async function(dataSource,record_id,field_id,value,_ds){if(update_local_scope_only){return}let tree_ret=await func.utils.TREE_OBJ.get(SESSION_ID,_ds.prog_id);if(glb.IS_WORKER){if(tree_ret.menuType==="globals"||tree_ret.menuType==="component"){const _progFields=await func.datasource.get_progFields(SESSION_ID,dataSource);let view_field_obj=func.common.find_item_by_key(_progFields,"field_id",field_id);if(!view_field_obj?.data?.serverField&&record_id!=="data_system"){if(!client_datasource_changes[dataSource]){client_datasource_changes[dataSource]={}}if(!client_datasource_changes[dataSource][record_id]){client_datasource_changes[dataSource][record_id]={}}client_datasource_changes[dataSource][record_id][field_id]=value}}}else{if(tree_ret.menuType==="component"&&_ds._run_at!=="client"||tree_ret.menuType==="globals"){if(!server_datasource_changes[dataSource]){server_datasource_changes[dataSource]={}}if(!server_datasource_changes[dataSource][record_id]){server_datasource_changes[dataSource][record_id]={}}server_datasource_changes[dataSource][record_id][field_id]=value}}};const update_xu_ref=function(dataSource){let ret;let _ds_0=_session.DS_GLB[0];for([ref_name,val]of Object.entries(_ds_0.data_system["SYS_GLOBAL_OBJ_REFS"])){if(val.ds.dsSession==dataSource){ret=func.UI.update_xu_ref(SESSION_ID,dataSource,ref_name)}}return ret};for await(const[dataSource,row_data]of Object.entries(datasource_changes)){var _ds=_session.DS_GLB[dataSource];if(!_ds){continue}for(const[record_id,fields_data]of Object.entries(row_data)){for(const[field_id,value]of Object.entries(fields_data)){if(record_id==="datasource_main"){xu_set(_ds,field_id,value);const ret=update_xu_ref(dataSource);if(ret){fields_changed.push(field_id);datasource_changed.push(dataSource)}if(!glb.IS_WORKER&&field_id==="watcher"){if(!server_datasource_changes[dataSource]){server_datasource_changes[dataSource]={}}if(!server_datasource_changes[dataSource][record_id]){server_datasource_changes[dataSource][record_id]={}}server_datasource_changes[dataSource][record_id][field_id]=value;if(!update_local_scope_only){const ret=await func.index.call_worker(SESSION_ID,{service:"update_datasource_changes_from_client",data:{session_id:SESSION_ID,datasource_changes:server_datasource_changes},id:_ds.worker_id})}await func.runtime.ui.refresh_screen({SESSION_ID:SESSION_ID,fields_changed_arr:structuredClone(fields_changed),datasource_changed:datasource_changed[0],fields_changed_datasource:datasource_changed[0],watcher:value})}continue}if(typeof fields_data==="object"){if(glb.GLOBAL_VARS[field_id]){_ds.data_system[field_id]=value;continue}const dynamic_field=_ds?.dynamic_fields?.[field_id];if(dynamic_field){if(!xu_isEqual(dynamic_field.value,value)){dynamic_field.value=value;await set_fieldComputed_dependencies(dataSource,field_id,null);update_xu_ref(dataSource);await queue_remote_change(dataSource,record_id,field_id,value,_ds);await mark_field_changed(dataSource,field_id)}continue}try{const row_idx=func.common.find_ROWID_idx(_ds,record_id);if(!xu_isEqual(_ds.data_feed.rows[row_idx][field_id],value)){_ds.data_feed.rows[row_idx][field_id]=value;await set_fieldComputed_dependencies(dataSource,field_id,null);update_xu_ref(dataSource);await queue_remote_change(dataSource,record_id,field_id,value,_ds);await mark_field_changed(dataSource,field_id);if(!_ds.data_feed.rows_changed){_ds.data_feed.rows_changed=[]}if(!_ds.data_feed.rows_changed.includes(record_id))_ds.data_feed.rows_changed.push(record_id)}}catch(error){}}else if(fields_data==="set"){_ds.currentRecordId=record_id}}}}if(glb.IS_WORKER){if(!update_local_scope_only&&!xu_isEmpty(client_datasource_changes)){func.utils.post_back_to_client(SESSION_ID,"update_client_eventChangesResults_from_worker",_session.worker_id,client_datasource_changes)}}else{if(!update_local_scope_only&&!xu_isEmpty(server_datasource_changes)){const ret=await func.index.call_worker(SESSION_ID,{service:"update_datasource_changes_from_client",data:{session_id:SESSION_ID,datasource_changes:server_datasource_changes},id:_ds.worker_id})}if(fields_changed.length){function findMin(arr){return Math.min(...arr.map(Number))}await func.runtime.ui.refresh_xu_attributes({SESSION_ID:SESSION_ID,fields_arr:structuredClone(fields_changed),jobNoP:null,$elm_to_search:null,dsSession_changed:findMin(datasource_changed),avoid_xu_for_refresh:avoid_xu_for_refresh,trigger:trigger,ignore_screen_blocker:true});await func.runtime.ui.refresh_screen({SESSION_ID:SESSION_ID,fields_changed_arr:structuredClone(fields_changed),datasource_changed:null,fields_changed_datasource:datasource_changed[0]})}}resolve()})};func.datasource.callback=async function(SESSION_ID,dsSessionP,rowIdP,jobNoP,nodeIdP){var _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dsSessionP];try{const row_idx=func.common.find_ROWID_idx(_ds,"dataset");if(_ds.PARAM_OUT_INFO){for(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){if(typeof _ds?.data_feed?.rows?.[row_idx]?.[val.fieldId]==="undefined"){func.utils.alerts.invoke(SESSION_ID,"system_msg","SYS_MSG_0310",val.fieldId,dsSessionP);break}val.result=_ds.data_feed.rows[row_idx][val.fieldId]}}}catch(err){}const datasetOutputField=_ds?.progDataSource?.datasetOutputField;if(datasetOutputField){let ret_get_value=await func.datasource.get_value(SESSION_ID,datasetOutputField,_ds.dsSession);if(ret_get_value.found){let datasource_changes={};if(!datasource_changes[ret_get_value.dsSessionP]){datasource_changes[ret_get_value.dsSessionP]={}}if(!datasource_changes[ret_get_value.dsSessionP][ret_get_value.currentRecordId]){datasource_changes[ret_get_value.dsSessionP][ret_get_value.currentRecordId]={};datasource_changes[ret_get_value.dsSessionP][ret_get_value.currentRecordId][_ds?.progDataSource?.datasetOutputField]=_ds?.data_feed?.rows||[];await func.datasource.update(SESSION_ID,datasource_changes)}}}func.utils.debug.log(SESSION_ID,nodeIdP,{module:_ds.viewModule,action:"close",source:_ds.viewSourceDesc,type:"adapter",prog_id:_ds.prog_id,dsSession:dsSessionP,prop:_ds.log_prop+" "+"adapter"});if(!glb.IS_WORKER)func.runtime.platform.set_cursor(_session.root_element,"default");if(_ds.prog_id){let _ds=_session.DS_GLB[dsSessionP];func.utils.debug.watch(SESSION_ID,_ds.prog_id,"program",{in_parameters:_ds.in_parameters,out_parameters:_ds.out_parameters,data_feed:_ds.data_feed},_ds.tree_obj.menuType)}delete _ds.old_dataSource;return{SESSION_ID:SESSION_ID,dsSessionP:dsSessionP,rowIdP:rowIdP,jobNoP:jobNoP,callingLogId:_ds.callingLogId,calling_jobP:_ds.calling_jobP}};func.datasource.validate_viewRange=async function(SESSION_ID,viewRangeExpP,dsSessionP,rowIdP,sourceP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];if(viewRangeExpP&&_ds){var ret=func.expression.remove_quotes(await func.expression.get(SESSION_ID,viewRangeExpP,dsSessionP,"range",rowIdP));ret.result=func.expression.remove_quotes(ret.result);func.utils.debug.log(SESSION_ID,_ds.prog_id,{module:_ds.viewModule,action:"range Exp",prop:sourceP,details:viewRangeExpP,result:ret.result,error:ret.error,source:_ds.viewSourceDesc,json:ret.explain,fields:ret.fields,dsSession:dsSessionP});_ds.viewRangeExpResults=ret.fields;if(glb.DEBUG_MODE){if(!_ds.debug){_ds.debug={}}if(!_ds.debug.viewRangeExp){_ds.debug.viewRangeExp=[]}_ds.debug.viewRangeExp.push(ret)}return ret.result}else return false};func.datasource.validate_viewLocate=async function(SESSION_ID,viewLocateExpP,dsSessionP,rowIdP,sourceP){if(viewLocateExpP&&_ds){var ret=func.expression.remove_quotes(await func.expression.get(SESSION_ID,viewLocateExpP,dsSessionP,"locate",rowIdP));ret.result=func.expression.remove_quotes(ret.result);func.utils.debug.log(SESSION_ID,_ds.prog_id,{module:_ds.viewModule,action:"locate Exp",prop:sourceP,details:viewLocateExpP,result:ret.result,error:ret.error,source:_ds.viewSourceDesc,json:ret.explain,fields:ret.fields,dsSession:dsSessionP});_ds.viewLocateExpResults=ret.fields;return ret.result}else return false};func.datasource.get_viewFields_for_update_function=function(SESSION_ID,calling_trigger_prop,na,dsSessionP){var viewFields=[];var exp=calling_trigger_prop?.data?.name?.value;if(!exp){return viewFields}const trim_wrapping_braces=function(value){const trimmed=value.trim();if(trimmed.startsWith("{")&&trimmed.endsWith("}")){return trimmed.substring(1,trimmed.length-1)}return trimmed};const strip_wrapping_quotes=function(value){const trimmed=value.trim();const first=trimmed.substring(0,1);const last=trimmed.substring(trimmed.length-1);if((first==="'"||first==='"'||first==="`")&&last===first){return trimmed.substring(1,trimmed.length-1)}return trimmed};const split_top_level=function(value){const parts=[];let current="";let quote=null;let escape=false;let paren_depth=0;let bracket_depth=0;let brace_depth=0;for(let index=0;index<value.length;index++){const char=value[index];if(escape){current+=char;escape=false;continue}if(quote){current+=char;if(char==="\\"){escape=true}else if(char===quote){quote=null}continue}if(char==="'"||char==='"'||char==="`"){quote=char;current+=char;continue}if(char==="(")paren_depth++;if(char===")")paren_depth=Math.max(0,paren_depth-1);if(char==="[")bracket_depth++;if(char==="]")bracket_depth=Math.max(0,bracket_depth-1);if(char==="{")brace_depth++;if(char==="}")brace_depth=Math.max(0,brace_depth-1);if((char===","||char===";")&&!paren_depth&&!bracket_depth&&!brace_depth){if(current.trim()){parts.push(current.trim())}current="";continue}current+=char}if(current.trim()){parts.push(current.trim())}return parts};const find_top_level_colon=function(value){let quote=null;let escape=false;let paren_depth=0;let bracket_depth=0;let brace_depth=0;for(let index=0;index<value.length;index++){const char=value[index];if(escape){escape=false;continue}if(quote){if(char==="\\"){escape=true}else if(char===quote){quote=null}continue}if(char==="'"||char==='"'||char==="`"){quote=char;continue}if(char==="(")paren_depth++;if(char===")")paren_depth=Math.max(0,paren_depth-1);if(char==="[")bracket_depth++;if(char==="]")bracket_depth=Math.max(0,bracket_depth-1);if(char==="{")brace_depth++;if(char==="}")brace_depth=Math.max(0,brace_depth-1);if(char===":"&&!paren_depth&&!bracket_depth&&!brace_depth){return index}}return-1};exp=trim_wrapping_braces(exp.replace(/\n/gi,""));const exp_arr=split_top_level(exp);for(let index=0;index<exp_arr.length;index++){const segment=exp_arr[index];const pos=find_top_level_colon(segment);if(pos===-1){continue}let id=strip_wrapping_quotes(segment.substring(0,pos));const val=segment.substring(pos+1).trim();if(id.substring(0,1)==="@"){id=id.substring(1)}if(!id||!val){continue}viewFields.push({id:id,val:val})}return viewFields};func.datasource.get_value=async function(SESSION_ID,fieldIdP,dsSessionP,rowIdP,org_dsSessionP){const normalize_field_id=function(field_id){if(typeof field_id==="string"){return field_id}if(typeof field_id?.field_id==="string"){return field_id.field_id}if(typeof field_id?.id==="string"){return field_id.id}if(typeof field_id==="number"||typeof field_id==="boolean"||typeof field_id==="bigint"){return field_id.toString()}const coerced=field_id?.toString?.();if(typeof coerced==="string"&&coerced&&coerced!=="[object Object]"){return coerced}return null};const return_missing_value=function(field_id,currentRecordId=null){return{ret:{value:undefined,type:"string",prop:null},dsSessionP:dsSessionP,fieldIdP:field_id,currentRecordId:currentRecordId,found:false}};const return_value=async(field_id,value)=>{const _progFields=await func.datasource.get_progFields(SESSION_ID,dsSessionP);let view_field_obj=func.common.find_item_by_key(_progFields,"field_id",field_id);var fieldType=view_field_obj?.props?.fieldType||"string";var fieldProp=view_field_obj?.props;let table_field_obj;if(view_field_obj?.data?.type==="table"){if(!_ds._dataSourceTableId){return func.utils.debug_report(SESSION_ID,"Datasource",`Table type defined without dataSourceTableId deceleration`,"E")}let table_obj=await func.utils.FILES_OBJ.get(SESSION_ID,_ds._dataSourceTableId);if(!table_obj){return func.utils.debug_report(SESSION_ID,"Datasource",`dataSourceTableId reference error: `+_ds._dataSourceTableId,"E")}table_field_obj=func.common.find_item_by_key(table_obj.tableFields,"field_id",field_id);fieldType=table_field_obj.props?.fieldType;fieldProp=table_field_obj.props}let ret={value:await func.common.get_cast_val(SESSION_ID,`datasource get value ${_ds.tree_obj.menuName}`,fieldIdP,fieldType,value,null),type:fieldType,prop:fieldProp};if(ret.value&&typeof ret.value==="string"&&ret.type!=="exp"){if(/"/.test(ret.value)&&ret.value.indexOf("\\")===-1)ret.value=ret.value.replace(/"/g,'"')}return{ret:ret,dsSessionP:dsSessionP,fieldIdP:field_id,currentRecordId:_ds.currentRecordId,found:typeof value!=="undefined"}};const return_dynamic_value=async(field_id,value)=>{let view_field_obj=_ds.dynamic_fields[field_id];var fieldType=view_field_obj?.props?.fieldType||"string";var fieldProp=view_field_obj?.props;let ret={value:view_field_obj.value,type:fieldType,prop:fieldProp};if(ret.value&&typeof ret.value==="string"&&ret.type!=="exp"){if(/"/.test(ret.value)&&ret.value.indexOf("\\")===-1)ret.value=ret.value.replace(/"/g,'"')}return{ret:ret,dsSessionP:dsSessionP,fieldIdP:field_id,currentRecordId:_ds.currentRecordId,found:typeof value!=="undefined"}};const return_value_parameters=async(field_id,value)=>{let ret={value:await func.common.get_cast_val(SESSION_ID,"datasource get value",fieldIdP,value.type,value.value,null),type:value.type,prop:null};if(ret.value&&typeof ret.value==="string"&&ret.type!=="exp"){if(!ret.value.includes("<svg xmlns=")&&/"/.test(ret.value)&&ret.value.indexOf("\\")===-1)ret.value=ret.value.replace(/"/g,'"')}return{ret:ret,dsSessionP:dsSessionP,fieldIdP:field_id,currentRecordId:_ds.currentRecordId,found:typeof value!=="undefined"}};const return_value_system=async(field_id,value)=>{let fieldType=glb.GLOBAL_VARS[field_id].type;let fieldProp=null;let ret={value:await func.common.get_cast_val(SESSION_ID,`datasource get value ${_ds.tree_obj.menuName}`,field_id,fieldType,value,null),type:fieldType,prop:fieldProp};return{ret:ret,dsSessionP:dsSessionP,fieldIdP:field_id,currentRecordId:_ds.currentRecordId,found:typeof value!=="undefined"}};const search_in_parameters=async field_id=>{if(typeof _ds?.in_parameters?.[field_id]?.value!=="undefined"){let ret=await return_value_parameters(field_id,_ds.in_parameters[field_id]);return ret}if(typeof _ds.parentDataSourceNo!=="undefined"){var org_dsSession=org_dsSessionP;if(!org_dsSessionP)org_dsSession=dsSessionP;if(recordId&&recordId!=="newRecord")org_dsSession=null;return await func.datasource.get_value(SESSION_ID,fieldIdP,_ds.parentDataSourceNo,recordId,org_dsSession)}return await return_value(field_id)};if(typeof glb.GLOBAL_VARS==="undefined"){glb.GLOBAL_VARS=(await func.common.get_module(SESSION_ID,"xuda-system-globals-module.mjs")).system_globals}var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];if(!_ds){if(dsSessionP>0){return await func.datasource.get_value(SESSION_ID,fieldIdP,dsSessionP-1,rowIdP,org_dsSessionP)}const normalized_missing_field=normalize_field_id(fieldIdP);if(normalized_missing_field===null){return return_missing_value(fieldIdP)}fieldIdP=normalized_missing_field;return await return_value(fieldIdP)}const normalized_field_id=normalize_field_id(fieldIdP);if(normalized_field_id===null){func.utils.debug_report(SESSION_ID,"Datasource get value",`Invalid field id type: ${typeof fieldIdP}`,"W");return return_missing_value(fieldIdP,_ds.currentRecordId)}fieldIdP=normalized_field_id;let recordId=rowIdP;if(!recordId){recordId=_ds.currentRecordId}if(glb.GLOBAL_VARS[fieldIdP]){if(!_ds.data_system){_ds.data_system={}}if(dsSessionP>0){_ds.data_system["SYS_STR_ACTIVE_ROW_ID"]=_ds.currentRecordId;_ds.data_system["SYS_STR_PROG_DS_SESSION"]=dsSessionP}if(glb.SYS_DATE_ARR.includes(fieldIdP)){var _ds_0=SESSION_OBJ[SESSION_ID].DS_GLB[0];if(_ds_0){if(!_ds_0.data_system){_ds_0.data_system={}}const ts=await func.utils.get_dateTime(SESSION_ID,"SYS_DATE_VALUE");for(const val of glb.SYS_DATE_ARR){_ds_0.data_system[val]=await func.utils.get_dateTime(SESSION_ID,val,ts)}}}if(typeof _ds?.data_system?.[fieldIdP]!=="undefined"){return await return_value_system(fieldIdP,_ds?.data_system?.[fieldIdP])}return await search_in_parameters(fieldIdP)}if(!_ds.data_feed){return await search_in_parameters(fieldIdP)}var _field_id=fieldIdP;if(fieldIdP.substr(0,1)==="_"){if(_ds.alias)_field_id=_ds.alias[fieldIdP]}if(typeof _ds?.dynamic_fields?.[_field_id]!=="undefined"){return await return_dynamic_value(_field_id,_ds.dynamic_fields[_field_id])}if(!org_dsSessionP&&recordId){try{const row_idx=func.common.find_ROWID_idx(_ds,recordId);if(typeof _ds.data_feed?.rows?.[row_idx]?.[_field_id]!=="undefined"){if(Object.keys(_ds.data_feed?.rows?.[row_idx]||{})?.includes(_field_id)){return await return_value(_field_id,_ds.data_feed.rows[row_idx][_field_id])}if(Object.keys(_ds?.dynamic_fields||{})?.includes(_field_id)){return await return_dynamic_value(_field_id,_ds.dynamic_fields[_field_id])}}}catch(err){}}try{const row_idx=func.common.find_ROWID_idx(_ds,_ds.currentRecordId);if(typeof _ds.data_feed?.rows?.[row_idx]?.[_field_id]!=="undefined"){return await return_value(_field_id,_ds.data_feed.rows[row_idx][_field_id])}}catch(error){}return await search_in_parameters(fieldIdP)};func.datasource.find_event_dataSource=async function(SESSION_ID,eventIdP,dsSessionP){const _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];var ret;if(_ds?.prog_id){let view_ret=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(view_ret?.progEvents&&func.common.find_item_by_key(view_ret.progEvents,"event_name",eventIdP)){ret=dsSessionP;if(_ds.callingSource==="system")ret=0;if(_ds.callingSource==="program"||!_ds.callingSource)ret=dsSessionP;return ret}}if(!ret&&dsSessionP!==0){if(_ds&&_ds.parentDataSourceNo&&Number(_ds.parentDataSourceNo)>0&&Number(_ds.parentDataSourceNo)<dsSessionP){return await func.datasource.find_event_dataSource(SESSION_ID,eventIdP,_ds.parentDataSourceNo)}else{if(!ret)return await func.datasource.find_event_dataSource(SESSION_ID,eventIdP,0)}}};func.datasource.reset_jobs=function(SESSION_ID,dsSessionP,sourceP,errP){for(const[key,val]of Object.entries(SESSION_OBJ[SESSION_ID].WORKER_OBJ.jobs)){if(val.dsSessionP===dsSessionP){func.events.delete_job(SESSION_ID,val.job_num);break}}func.utils.debug_report(SESSION_ID,sourceP+"Missing datasource: "+dsSessionP,errP,"W",null)};func.datasource.get_currentRecordId=function(SESSION_ID,dsSessionP,from_datasourceP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];if(_ds._dataSourceTableId!==""){var firstRecordId=_ds.firstRecordId;var currentRecordId=_ds.currentRecordId;var locatedRecordId=_ds.locatedRecordId;if(!currentRecordId||from_datasourceP){if(!locatedRecordId)currentRecordId=firstRecordId;else currentRecordId=locatedRecordId}}else currentRecordId="newRecord";return currentRecordId};func.datasource.interval=function(session_id,dsSessionP,typeP){var SESSION_ID=session_id;var interval=[];var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];var arr=_ds[typeP];var fx={init:async function(){if(arr?.length){for(let val of arr){var event_id=val[0];var interval_rate=val[1];var condition=val[2];interval.push(setInterval(async function(){if(!SESSION_OBJ[SESSION_ID])return;var event_count=await func.datasource.get_view_events_count(SESSION_ID,dsSessionP,typeP,event_id);if(!event_count){fx.clear();return}var event_condition=await func.expression.get(SESSION_ID,condition,dsSessionP,"condition");if(condition&&!event_condition.result)return;const e=await func.datasource.execute_view_events(SESSION_ID,dsSessionP,typeP,event_id)},Number(interval_rate)*1e3))}}else{await fx.clear();return}},clear:function(){if(DATASOURCE_INTERVALS[session_id])delete DATASOURCE_INTERVALS[session_id][dsSessionP];for(const[key,val]of Object.entries(interval)){clearInterval(val)}}};return fx};func.datasource.get_viewLoops=async function(SESSION_ID,dataSourceSession,data,batch_source,default_limit){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var args=_ds.args;var ret=default_limit;if(batch_source==="db_data")ret=data.rows.length;if(batch_source==="array"||batch_source==="csv")ret=data.length;if(batch_source==="json")ret=Object.keys(data).length;if(_ds.progDataSource?.dataSourceLimit){if(batch_source!=="no_data"&&Number(_ds.progDataSource?.dataSourceLimit)<ret){ret=Number(_ds.progDataSource.dataSourceLimit)}if(!batch_source)ret=Number(_ds.progDataSource.dataSourceLimit)}if(prog_obj.progDataSource?.dataSourceLoopExp){var n=(await func.expression.get(SESSION_ID,_ds.v.viewLoopsExp,dataSourceSession,"view_loop",args.rowIdP)).result;if(batch_source!=="no_data"&&n<ret)ret=n;if(!batch_source)ret=n}return ret};func.datasource.set_VIEW_data=async function(SESSION_ID,args,_ds){_ds.v={viewFieldsProp:{},segFrom:[],segTo:[],segLocateFrom:[],segLocateTo:[],viewModule:"adapter"};_ds.viewEventExec_arr={};var view=structuredClone(await func.utils.VIEWS_OBJ.get(SESSION_ID,args.prog_id));_ds.v.dataSourceSrcType=view.dataSourceSrcType;if(view.progDataSource)_ds.progDataSource=view.progDataSource;_ds.v.viewIndex=view?.progDataSource?.dataSourceIndexesObj;let tree_ret=await func.utils.TREE_OBJ.get(SESSION_ID,args.prog_id);_ds.v.viewSourceDesc=tree_ret.menuName;if(!_ds.v.viewSourceDesc&&tree_ret){_ds.v.viewSourceDesc=tree_ret.menuName}if(glb.FUNCTION_NODES_ARR.includes(tree_ret.menuType)){_ds.v.viewModule="function"}_ds.v.viewSourceProp=tree_ret.menuType;if(view.progEvents)_ds.v.progEvents=view.progEvents;_ds._progDataSource_fields=[];if(_ds.progDataSource){let ret=func.expression.parse(JSON.stringify(_ds.progDataSource));_ds._progDataSource_fields=ret.map(e=>{if(e.fieldId)return e.fieldId})}};func.datasource.get_cast_val=async function(SESSION_ID,source,dsSession,valP,typeP,req,error){var prog_id,prog_name;var _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dsSession];prog_id=_ds.prog_id;prog_name=await func.utils.TREE_OBJ.get(SESSION_ID,_ds.prog_id).menuName;const prog_info=prog_id?` (prog: ${prog_id} ${prog_name})`:"";const report_conversion_error=function(res){var msg=`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=`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");return module.cast(typeP,valP,report_conversion_error,report_conversion_warn)};func.datasource.get_field_init_triggers_to_run=function(SESSION_ID,dataSourceSession,pre_init_fieldsP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];if(!_ds)return;return[]};func.datasource.get_pre_init_fields=function(SESSION_ID,dsSessionP,viewRangeExpP,viewSortExpP,viewGroupByExpP,viewLocateExpP){var ret=[];return};func.datasource.add_dynamic_field_to_ds=function(SESSION_ID,dsSessionP,key,val){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];if(!_ds.dynamic_fields){_ds.dynamic_fields={}}const toType=function(obj){return{}.toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()};_ds.dynamic_fields[key]={id:crypto.randomUUID(),data:{type:"virtual",field_id:key},props:{fieldType:typeof val!=="undefined"?toType(val):"string"},value:val}};func.datasource.get_progFields=async function(SESSION_ID,dsSessionP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);return _view_obj.progFields};func.datasource.update_changes_for_out_parameter=async function(SESSION_ID,dsSessionP,calling_dsP){let _session=SESSION_OBJ[SESSION_ID];let _ds=_session.DS_GLB[dsSessionP];const _calling_ds=_session.DS_GLB[calling_dsP];if(_ds.PARAM_OUT_INFO){let data={};for await(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){if(val.prop==="out"){try{const row_idx=func.common.find_ROWID_idx(_ds,_ds.currentRecordId);data[val.details]=_ds.data_feed.rows[row_idx][val.fieldId]}catch(err){console.error(err)}}}if(!xu_isEmpty(data)){let datasource_changes={[calling_dsP]:{[_calling_ds.currentRecordId]:data}};await func.datasource.update(SESSION_ID,datasource_changes)}}};func.datasource.set_outputField=async function(SESSION_ID,dsSessionP,result,args){var _session=SESSION_OBJ[SESSION_ID];const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSessionP,args,"outputField");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]=result;await func.datasource.update(SESSION_ID,datasource_changes)}}};func.datasource.get_args_property_value=async function(SESSION_ID,dsSession,args,prop_name){let _prop=args?.calling_trigger_prop?.data?.name;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};func.UI.screen={};func.UI.screen.init=async function(SESSION_ID,prog_id,sourceScreenP,callingDataSource_objP,$callingContainerP,triggerIdP,rowIdP,jobNoP,is_panelP,parameters_obj_inP,source_functionP,call_screen_propertiesP,refreshed_ds,parameters_raw_obj){return await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:prog_id,sourceScreenP:sourceScreenP,callingDataSource_objP:callingDataSource_objP,$callingContainerP:$callingContainerP,triggerIdP:triggerIdP,rowIdP:rowIdP,jobNoP:jobNoP,is_panelP:is_panelP,parameters_obj_inP:parameters_obj_inP,source_functionP:source_functionP,call_screen_propertiesP:call_screen_propertiesP,refreshed_ds:refreshed_ds,parameters_raw_obj:parameters_raw_obj})};func.UI.screen.update_SYS_OBJ_WIN_INFO=function(SESSION_ID,dsNoP){return func.runtime.ui.update_sys_obj_win_info(SESSION_ID,dsNoP)};func.UI.screen.validate_exit_events=async function(SESSION_ID,div_data_paramsP,forceP){return await func.runtime.ui.validate_exit_events(SESSION_ID,div_data_paramsP,forceP)};func.UI.screen.call_embed=function(SESSION_ID,prog){return func.runtime.ui.call_embed(SESSION_ID,prog)};func.UI.screen.refresh_xu_attributes=async function(SESSION_ID,fields_arr,jobNoP,$elm_to_search,dsSession_changed,avoid_xu_for_refresh,trigger){return await func.runtime.ui.refresh_xu_attributes({SESSION_ID:SESSION_ID,fields_arr:fields_arr,jobNoP:jobNoP,$elm_to_search:$elm_to_search,dsSession_changed:dsSession_changed,avoid_xu_for_refresh:avoid_xu_for_refresh,trigger:trigger})};func.UI.screen.refresh_screen=async function(SESSION_ID,fields_changed_arr,datasource_changed,fields_changed_datasource,watcher){return await func.runtime.ui.refresh_screen({SESSION_ID:SESSION_ID,fields_changed_arr:fields_changed_arr,datasource_changed:datasource_changed,fields_changed_datasource:fields_changed_datasource,watcher:watcher})};func.UI.screen.execute_xu_functions=async function(SESSION_ID,is_skeleton,$root_container,nodeP,$container,paramsP,parent_infoP,jobNoP,keyP,parent_nodeP,xu_func,$elm,val,is_init,refreshed_ds){if(is_skeleton)return;return await func.runtime.render.execute_xu_function({SESSION_ID:SESSION_ID,is_skeleton:is_skeleton,$root_container:$root_container,nodeP:nodeP,$container:$container,paramsP:paramsP,parent_infoP:parent_infoP,jobNoP:jobNoP,keyP:keyP,parent_nodeP:parent_nodeP,xu_func:xu_func,$elm:$elm,val:val,is_init:is_init,refreshed_ds:refreshed_ds,get_params_obj_new:func.runtime.program.get_params_obj})};func.UI.screen.fix_val_defaults=function(key,val){return func.runtime.render.fix_val_defaults(key,val)};func.UI.screen.set_attributes_new=async function(SESSION_ID,is_skeleton,$root_container,nodeP,$container,paramsP,parent_infoP,jobNoP,keyP,parent_nodeP,$elm,is_init,execute_attributes=[],refreshed_ds){return await func.runtime.render.set_attributes_new({SESSION_ID:SESSION_ID,is_skeleton:is_skeleton,$root_container:$root_container,nodeP:nodeP,$container:$container,paramsP:paramsP,parent_infoP:parent_infoP,jobNoP:jobNoP,keyP:keyP,parent_nodeP:parent_nodeP,$elm:$elm,is_init:is_init,execute_attributes:execute_attributes,refreshed_ds:refreshed_ds})};func.UI.screen.panel_post_render_handler=async function(SESSION_ID,$container,$wrapper,nodeP,$panel_div,jobNoP){return await func.runtime.ui.panel_post_render_handler({SESSION_ID:SESSION_ID,$container:$container,$wrapper:$wrapper,nodeP:nodeP,$panel_div:$panel_div,jobNoP:jobNoP})};func.UI.screen.create_container=async function(SESSION_ID,$root_container,nodeP,$container,paramsP,parent_infoP,jobNoP,keyP,parent_nodeP,prop,classP,elem_propP,div_typeP,$appendToP,attr_str,is_placeholder){return await func.runtime.ui.create_container({SESSION_ID:SESSION_ID,$root_container:$root_container,nodeP:nodeP,$container:$container,paramsP:paramsP,parent_infoP:parent_infoP,jobNoP:jobNoP,keyP:keyP,parent_nodeP:parent_nodeP,prop:prop,classP:classP,elem_propP:elem_propP,div_typeP:div_typeP,$appendToP:$appendToP,attr_str:attr_str,is_placeholder:is_placeholder})};func.UI.screen.execute_screen_ready_events=async function(SESSION_ID,paramsP,sourceP,$div,jobNoP,$div_objP){return await func.runtime.ui.execute_screen_ready_events({SESSION_ID:SESSION_ID,paramsP:paramsP,sourceP:sourceP,$div:$div,jobNoP:jobNoP,$div_objP:$div_objP})};func.UI.screen.screen_loading_done=async function(SESSION_ID,paramsP,$div,jobNoP){return await func.runtime.ui.screen_loading_done({SESSION_ID:SESSION_ID,paramsP:paramsP,$div:$div,jobNoP:jobNoP})};func.UI.screen.render_ui_tree=async function(SESSION_ID,$container,nodeP,parent_infoP,paramsP,jobNoP,is_skeleton,keyP,refreshed_ds,parent_nodeP,check_existP,$root_container){return await func.runtime.render.render_ui_tree(SESSION_ID,$container,nodeP,parent_infoP,paramsP,jobNoP,is_skeleton,keyP,refreshed_ds,parent_nodeP,check_existP,$root_container)};func.UI.screen.refresh_document_changes_for_realtime_update=async function(SESSION_ID,doc_change){return await func.runtime.ui.refresh_document_changes_for_realtime_update(SESSION_ID,doc_change)};func.UI.screen.live_preview_hot_module_reload=async function(SESSION_ID,doc){return await func.runtime.ui.live_preview_hot_module_reload(SESSION_ID,doc)};func.UI.component={};func.UI.component.get_wrapped_nodes=function(target){if(!target){return[]}if(typeof target.toArray==="function"){return target.toArray().filter(Boolean)}if(Array.isArray(target)){return target.filter(Boolean)}const first_node=func.runtime.ui.get_first_node(target);return first_node?[first_node]:[]};func.UI.component.move_wrapped_nodes=function(target,source){const target_node=func.runtime.ui.get_first_node(target);if(!target_node){return false}const nodes=func.UI.component.get_wrapped_nodes(source);for(let index=0;index<nodes.length;index++){target_node.appendChild(nodes[index])}return true};func.UI.component.create_app_modal_component=function(SESSION_ID,modal_content_name){const root_element=SESSION_OBJ[SESSION_ID].root_element;const xu_modal_controller_id="xu-modal-controller";var xu_modal_controller=root_element.querySelector(xu_modal_controller_id);if(!xu_modal_controller){xu_modal_controller=document.createElement(xu_modal_controller_id);root_element.prepend(xu_modal_controller)}customElements.define(modal_content_name,class extends HTMLElement{constructor(){super()}connectedCallback(){}});return xu_modal_controller_id};func.UI.component.create_app_page_component=async function(SESSION_ID,id){const component_id="xu-page-component-"+id;customElements.define(component_id,class extends HTMLElement{constructor(){super();var xu_nav=SESSION_OBJ[SESSION_ID].root_element.querySelector("xu-nav");var params=func.runtime.ui.get_data(xu_nav);var container_data=func.runtime.ui.get_data(params.xuData.nav_params[id].$container);for(const[key,val]of Object.entries(container_data)){func.runtime.ui.set_data(this,key,val)}}connectedCallback(){const page_back_callback=async()=>{await func.runtime.ui.validate_exit_events(SESSION_ID,func.runtime.ui.get_data(params.$container).xuData.paramsP,null);nav.back();func.datasource.clean_all(SESSION_ID,params.dsSession)};const nav=SESSION_OBJ[SESSION_ID].root_element.querySelector("xu-nav");const params=func.runtime.ui.get_data(nav).xuData.nav_params[id];params.callback(this,page_back_callback)}});return component_id};func.UI.component.create_app_root_component=function(SESSION_ID){customElements.define("xu-root-component-"+SESSION_ID,class ModalContent extends HTMLElement{connectedCallback(){const xu_nav=SESSION_OBJ[SESSION_ID].root_element.querySelector("xu-nav");const xu_nav_data=func.runtime.ui.get_data(xu_nav);func.UI.component.move_wrapped_nodes(this,xu_nav_data?.xuData?.$div);const root_component_callback=xu_nav_data.xuData.root_component_callback;if(root_component_callback){root_component_callback()}}})};func.UI.component.create_app_popover_component=function(SESSION_ID){const root_element=SESSION_OBJ[SESSION_ID].root_element;const xu_popover_controller_id="xu-popover-controller-"+SESSION_ID;var xu_popover_controller_el=root_element.querySelector(xu_popover_controller_id);if(!xu_popover_controller_el){xu_popover_controller_el=document.createElement(xu_popover_controller_id);root_element.prepend(xu_popover_controller_el)}customElements.define("xu-popover-content-"+SESSION_ID,class ModalContent extends HTMLElement{connectedCallback(){const xu_popover_controller=document.querySelector("xu-popover-controller-"+SESSION_ID);var params=func.runtime.ui.get_data(xu_popover_controller,"xuControllerParams");var popover_el=document.querySelector("xu-popover-content-"+SESSION_ID);popover_el.setAttribute("id",func.runtime.ui.get_attr(params.$container,"id"));var container_data=func.runtime.ui.get_data(params.$container);for(const[key,val]of Object.entries(container_data)){func.runtime.ui.set_data(popover_el,key,val)}popover_el.innerHTML="";func.UI.component.move_wrapped_nodes(popover_el,params.$dialogDiv)}});return xu_popover_controller_id};func.UI.component.create_camera_select_popover_component=function(SESSION_ID){customElements.define("popover-camera-select-page"+SESSION_ID,class ModalContent extends HTMLElement{connectedCallback(){const xu_popover_controller=document.querySelector("ion-popover-controller");var params=func.runtime.ui.get_data(xu_popover_controller,"xuControllerParams");func.UI.component.move_wrapped_nodes(this,params.$dialogDiv)}})};func.UI.component.init_xu_nav=function($container,$nav){const container_el=func.runtime.ui.get_first_node($container);const nav_el=func.runtime.ui.get_first_node($nav);func.runtime.ui.set_data(nav_el,"xuData",{nav_stack:[]});Object.defineProperty(nav_el,"setRoot",{value:async function(component_id){return new Promise(async function(resolve,reject){func.runtime.ui.get_data(nav_el).xuData.nav_stack.unshift(component_id);container_el.insertAdjacentHTML("beforeend","<"+component_id+">");await customElements.whenDefined(component_id);resolve()})},configurable:true});Object.defineProperty(nav_el,"push",{value:async function(component_id){return new Promise(async function(resolve,reject){let last_component=func.runtime.ui.get_data(nav_el).xuData.nav_stack.at(-1);var last_el=document.querySelector(last_component);if(last_el)last_el.style.display="none";func.runtime.ui.get_data(nav_el).xuData.nav_stack.push(component_id);container_el.insertAdjacentHTML("beforeend","<"+component_id+">");await customElements.whenDefined(component_id);resolve()})},configurable:true});Object.defineProperty(nav_el,"popToRoot",{value:async function(){return new Promise(async function(resolve,reject){let last_component=func.runtime.ui.get_data(nav_el).xuData.nav_stack.at(-1);var last_el=document.querySelector(last_component);if(last_el)last_el.remove();let root_component=func.runtime.ui.get_data(nav_el).xuData.nav_stack[0];func.runtime.ui.get_data(nav_el).xuData.nav_stack[root_component];var root_el=document.querySelector(root_component);if(root_el)root_el.style.display="";await customElements.whenDefined(root_component);resolve()})},configurable:true});Object.defineProperty(nav_el,"popTo",{value:async function(index){return new Promise(async function(resolve,reject){let last_component=func.runtime.ui.get_data(nav_el).xuData.nav_stack.at(-1);let last_component_index=func.runtime.ui.get_data(nav_el).xuData.nav_stack.length-1;var last_el=document.querySelector(last_component);if(last_el)last_el.remove();try{var selected_component=func.runtime.ui.get_data(nav_el).xuData.nav_stack[index||last_component_index-1]}catch(error){console.error(error);return reject(error)}var selected_el=document.querySelector(selected_component);if(selected_el)selected_el.style.display="";func.runtime.ui.get_data(nav_el).xuData.nav_stack.splice(last_component_index,1);await customElements.whenDefined(selected_component);resolve()})},configurable:true});Object.defineProperty(nav_el,"back",{value:async function(index){return new Promise(async function(resolve,reject){let last_component=func.runtime.ui.get_data(nav_el).xuData.nav_stack.at(-1);let last_component_index=func.runtime.ui.get_data(nav_el).xuData.nav_stack.length-1;if(last_component_index===0)return;var last_el=document.querySelector(last_component);if(last_el)last_el.remove();try{var selected_component=func.runtime.ui.get_data(nav_el).xuData.nav_stack[last_component_index-1]}catch(error){console.error(error);return reject(error)}var selected_el=document.querySelector(selected_component);if(selected_el)selected_el.style.display="";func.runtime.ui.get_data(nav_el).xuData.nav_stack.splice(last_component_index,1);await customElements.whenDefined(selected_component);resolve()})},configurable:true})};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("&amp;"))ret=ret.replace(/\&amp;/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.events={};func.events.validate=async function(SESSION_ID,triggerP,dsSessionP,eventIdP,sourceP,argumentsP,return_validation_onlyP){var _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dsSessionP];var args={triggerP:triggerP,dsSessionP:dsSessionP,eventIdP:eventIdP,sourceP:sourceP,argumentsP:argumentsP,return_validation_onlyP:return_validation_onlyP};const search_event_in_parent_ds=async function(){if(_ds&&typeof _ds.parentDataSourceNo!=="undefined"){await func.events.validate(SESSION_ID,triggerP,_ds.parentDataSourceNo,eventIdP,sourceP,argumentsP,return_validation_onlyP)}};var ret=false;var jobs=[];if(_ds?.prog_id){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(!glb.IS_WORKER)_ds.event_stat_obj={};if(_view_obj.progEvents){if(_session.api_callback&&eventIdP){_session.api_callback(eventIdP,SESSION_ID,SESSION_OBJ)}for await(let val of _view_obj.progEvents){var eventProp=undefined;if(val.data.type===triggerP){if(triggerP!=="user_defined"|(triggerP==="user_defined"&&eventIdP===val.data.event_name)){var expCond;if(val.data.condition)expCond=await func.expression.get(SESSION_ID,val.data.condition,dsSessionP,"condition");if(!val.data.condition||expCond.result){func.utils.debug.watch(SESSION_ID,_ds.prog_id+"%"+val.id,"view_event",val,triggerP+" "+eventIdP,expCond);ret=true;if(return_validation_onlyP)break;const set_arguments=async function(){var args=argumentsP||{};for await(let[key,fieldId]of Object.entries(val.data.parameters)){const field_info=func.common.find_item_by_key(_view_obj.progFields,"field_id",fieldId);if(field_info?.data?.type!=="virtual"){console.warn("parameter field must be virtual, update ignored");continue}if(!args[fieldId])continue;let value=await func.common.get_cast_val(SESSION_ID,"events",fieldId,field_info.props.fieldType,args[fieldId].value);if(!xu_isEmpty(args[fieldId].fx)){const fx_ret=await func.expression.get(SESSION_ID,args[fieldId].fx,dsSessionP,"update");value=fx_ret.result}const ret=await func.datasource.get_value(SESSION_ID,fieldId,dsSessionP,_ds.currentRecordId);const datasource_changes={[ret.dsSessionP]:{[ret.currentRecordId]:{[fieldId]:value}}};await func.datasource.update(SESSION_ID,datasource_changes)}await add_event()};const add_event=async function(){const _event=func.common.find_item_by_key_root(_view_obj.progEvents,"id",val.id);if(_event.workflow){if(!_event.workflow||xu_isEmpty(_event.workflow))return;for(const trigger_obj of _event.workflow){if(!trigger_obj.data.action)continue;if(!trigger_obj.data.enabled)continue;var callingEventId=val.data.event_name;if(!callingEventId)callingEventId=val.id;const ref_id=trigger_obj.data.name;var container=undefined;var screen_prop=undefined;if(!glb.IS_WORKER){if(_ds.panel_div_id){try{container="#"+_ds.panel_div_id;const panel_meta=func.runtime.ui.get_meta_by_element_id(_ds.panel_div_id);if(panel_meta?.xuData?.panel_info){screen_prop=panel_meta.xuData.panel_info.paramsP}else{container="#"+_session.DS_GLB[dsSessionP].screenId;const screen_meta=func.runtime.ui.get_meta_by_element_id(_session.DS_GLB[dsSessionP].screenId);if(screen_meta?.xuData){screen_prop=screen_meta.xuData.paramsP}if(!screen_meta){container="#"+_session.DS_GLB[dsSessionP].containerId}}}catch(e){console.error(e)}}else{container="#"+_ds.screenId;const screen_meta=func.runtime.ui.get_meta_by_element_id(_ds.screenId);if(screen_meta?.xuData){screen_prop=screen_meta.xuData.paramsP}if(!screen_meta){container="#"+_ds.containerId}}}else{screen_prop={callingContainerP:_ds.containerId}}jobs.push(await func.events.add_to_queue(SESSION_ID,sourceP+" event",trigger_obj.id,null,trigger_obj.data.action,ref_id,container,null,_ds.currentRecordId,null,trigger_obj.data.name,null,null,dsSessionP,null,null,trigger_obj,triggerP,screen_prop,null,null,trigger_obj,trigger_obj.data.parameter_source_data,val.id,null,args,null,null))}}};if(val.data.parameters){await set_arguments()}else{await add_event()}}else{if(val.data.condition&&!expCond.result){func.utils.debug.watch(SESSION_ID,_ds.prog_id+"%"+val.id,"view_event",val,triggerP+" "+eventIdP,expCond,true)}}}}}}}if(return_validation_onlyP)return ret;if(!ret)await search_event_in_parent_ds();return jobs};func.events.add_to_queue=async function(SESSION_ID,typeP,eventIdP,triggerP,functionP,refIdP,containerP,elementP,rowP,evt,descP,NA_rootScreenIdP,NA_callingEventIdP,dsSessionP,NA_isInitP,NA_calling_program,event_propertiesP,calling_triggerP,paramsP,NA_target_frame_idP,_NA2,calling_trigger_prop,argumentsP,source_event_idP,calling_job,args,$div,$container){var _session=SESSION_OBJ[SESSION_ID];var obj={SESSION_ID:SESSION_ID,typeP:typeP,eventIdP:eventIdP,triggerP:triggerP,functionP:functionP,refIdP:refIdP,containerP:containerP,elementP:elementP,rowP:rowP,descP:descP,dsSessionP:dsSessionP,event_propertiesP:event_propertiesP,calling_triggerP:calling_triggerP,paramsP:paramsP,calling_trigger_prop:calling_trigger_prop,argumentsP:argumentsP,source_event_idP:source_event_idP,calling_job:calling_job,args:args,$div:$div,$container:$container,evt:evt,job_num:_session.WORKER_OBJ.num};var _ds=_session.DS_GLB[dsSessionP];if(!_ds)return;if(typeof dsSessionP!=="undefined"&&dsSessionP!==null){obj.prog_id=_ds.prog_id;obj.parentDataSourceNo=_ds.parentDataSourceNo;obj.nodeId=_ds.nodeId}if(glb.IS_WORKER&&func.utils.is_onscreen_event(functionP)){obj.client=true;if(functionP==="call_library"){obj.client=false}if(typeof dsSessionP!=="undefined"&&dsSessionP!==null){obj.ds_obj=func.utils.clean_returned_datasource(SESSION_ID,dsSessionP)}if(obj.client){_session.WORKER_OBJ.num++;func.utils.post_back_to_client(SESSION_ID,"job",_session.worker_id,obj);return}}if(calling_job){var job_index=func.events.find_job_index(SESSION_ID,calling_job);try{if(!_session.WORKER_OBJ.jobs[job_index].splice_count){_session.WORKER_OBJ.jobs[job_index].splice_count=0}_session.WORKER_OBJ.jobs[job_index].splice_count++;_session.WORKER_OBJ.jobs.splice(job_index+_session.WORKER_OBJ.jobs[job_index].splice_count,0,obj)}catch(e){console.error("bug")}}else{_session.WORKER_OBJ.jobs.push(obj)}_session.WORKER_OBJ.num++;return _session.WORKER_OBJ.num-1};func.events.find_job_index=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var ret=null;if(!_session.WORKER_OBJ)return ret;for(const[key,val]of Object.entries(_session.WORKER_OBJ.jobs)){if(val&&val.job_num==jobNoP){ret=key;break}}return ret};func.events.execute=async function(SESSION_ID,jobNoP,eventIdP,triggerP,functionP,refIdP,containerP,elementP,rowP,evt,descP,rootScreenIdP,dsSessionP,NA_callingEventIdP,callingSourceP,NA_isInitP,event_propertiesP,calling_triggerP,calling_jobP,paramsP,NA_target_frame_idP,calling_trigger_prop,NA_calling_program,argumentsP,NA_viewIdP,NA_nodeIdP,NA_parentDataSourceNoP,$div){var _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dsSessionP];if(functionP==="update")refIdP=null;var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(_session.WORKER_OBJ.jobs?.[job_index]?.stat==="busy"){if(jobNoP)_session.WORKER_OBJ.stat=job_index;return}if(jobNoP&&!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}if(jobNoP)_session.WORKER_OBJ.stat=job_index;if(jobNoP&&calling_trigger_prop?.props?.async){func.events.delete_job(SESSION_ID,jobNoP);_session.WORKER_OBJ.stat=null}if(_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.jobs[job_index].stat="busy"}var dsSession=dsSessionP;var field_elm=elementP;var calling_field_id=field_elm;if(field_elm&&typeof field_elm==="object")calling_field_id=func.runtime.ui.get_attr(field_elm,"xu-ui-id");var log_nodeId;var log_prog_id;var log_source;if(_session.DS_GLB[dsSession]?.prog_id)log_prog_id=_session.DS_GLB[dsSession].prog_id;log_nodeId=log_prog_id+"_"+eventIdP;var log_prop=callingSourceP;if(callingSourceP==="system event"){log_prop="global event"}if(calling_field_id){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",calling_field_id);log_nodeId=log_prog_id+"_"+eventIdP+"_"+_field_obj?.id;log_source=calling_field_id}if(elementP){log_prop=triggerP;log_nodeId=log_nodeId+"_ui_prop"}var expCond;if(event_propertiesP){if(event_propertiesP?.props?.condition){expCond=await func.expression.get(SESSION_ID,event_propertiesP.props.condition,dsSession,"condition",null,null,null,calling_field_id?calling_field_id:calling_triggerP,null,descP);func.utils.debug.log(SESSION_ID,log_nodeId,{module:"event",action:log_prop,source:log_source,prop:descP,details:event_propertiesP.props.condition,result:expCond.result,error:expCond.error,fields:expCond.fields,type:"event",prog_id:log_prog_id,conditional:true});var cond=expCond.result;if(!cond||expCond.error){func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond,true);return}}else{func.utils.debug.log(SESSION_ID,log_nodeId,{module:"event",action:log_prop,source:log_source,prop:descP,details:null,result:null,error:null,fields:null,type:"event",prog_id:log_prog_id})}}const get_params_obj=async function(){const _prog=await func.utils.VIEWS_OBJ.get(SESSION_ID,await get_prog_id());if(!_prog){func.events.delete_job(SESSION_ID,jobNoP);return func.utils.debug_report(SESSION_ID,"func.events.execute","Program not found: "+refIdP.prog,"E")}var params_obj={};if(_prog?.properties?.progParams){for await(const[key,val]of Object.entries(_prog.properties.progParams)){if(typeof args.parameters_obj_inP?.[val.data.parameter]!=="undefined"){if(args.parameters_obj_inP?.[val.data.parameter].fx){let ret=await func.expression.get(SESSION_ID,args.parameters_obj_inP?.[val.data.parameter].fx,dsSession,"parameters");params_obj[val.data.parameter]=ret.result}else{params_obj[val.data.parameter]=args.parameters_obj_inP?.[val.data.parameter].value}continue}console.warn(`Warning: Program ${_prog.properties.menuName} expected In parameter: ${val.data.parameter} but received null instead`)}}return params_obj};const get_prog_id=async function(){let _prop=args?.calling_trigger_prop?.data?.name?.properties;let _prog_id=args.prog_id;if(_prop?.["xu-exp:prog"]){_prog_id=(await func.expression.get(SESSION_ID,_prop["xu-exp:prog"],dsSession,"prog_id expression")).result}return _prog_id};var args={prog_id:refIdP?.prog,screenIdP:refIdP?.prog,callingFieldIdP:field_elm,dataSourceNoP:null,parentDataSourceNoP:dsSession,triggerIdP:eventIdP,containerIdP:null,rowIdP:rowP,jobNoP:jobNoP,callingSourceP:callingSourceP,calling_jobP:calling_jobP,screen_dsP:null,is_panelP:null,argument_listP:null,calling_trigger_prop:calling_trigger_prop,parameters_obj_inP:refIdP?.parameters,call_screen_propertiesP:refIdP?.properties};const fx={Call_window:async function(){var is_panel;var $calling_container;if(_session.WORKER_OBJ.jobs[job_index]){if(_session.WORKER_OBJ.jobs[job_index].paramsP){$calling_container=func.runtime.ui.find_element_by_id(_session.WORKER_OBJ.jobs[job_index].paramsP.callingContainerP)}else{$calling_container="";_session.WORKER_OBJ.jobs[job_index].paramsP={}}}if(!refIdP.prog){func.events.delete_job(SESSION_ID,jobNoP);return func.utils.debug_report(SESSION_ID,"func.events.execute","Program is empty","E")}const params_obj=await get_params_obj();return await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:await get_prog_id(),sourceScreenP:func.runtime.ui.get_data(containerP)?.xuData?.screenId,callingDataSource_objP:_session.DS_GLB[dsSession],$callingContainerP:$calling_container,triggerIdP:eventIdP,rowIdP:rowP,jobNoP:jobNoP,is_panelP:is_panel,parameters_obj_inP:params_obj,source_functionP:functionP,call_screen_propertiesP:args.call_screen_propertiesP})},call_modal:async function(){return await fx.Call_window()},call_popover:async function(){return await fx.Call_window()},call_page:async function(){return await fx.Call_window()},call_library:async function(){let plugin_name=refIdP.plugin_name,method=refIdP.library_method,$containerP=$div,dsP=dsSession,propsP=refIdP.library_props,sourceP=descP;var _session=SESSION_OBJ[SESSION_ID];const set_SYS_GLOBAL_OBJ_WIDGET_INFO=async function(docP){var obj={...docP};obj.date=await func.utils.get_dateTime(SESSION_ID,"SYS_DATE",docP.date);obj.time=await func.utils.get_dateTime(SESSION_ID,"SYS_TIME",docP.date);var datasource_changes={[0]:{["data_system"]:{["SYS_GLOBAL_OBJ_WIDGET_INFO"]:obj}}};await func.datasource.update(SESSION_ID,datasource_changes)};const call_plugin_api=async function(plugin_nameP,dataP){return await func.utils.call_plugin_api(SESSION_ID,plugin_nameP,dataP)};const report_error=function(descP,warn){func.utils.debug.log(SESSION_ID,_session.DS_GLB[dsP].prog_id+"_"+_session.DS_GLB[dsP].callingMenuId,{module:"widgets",action:"Init",source:sourceP,prop:descP,details:descP,result:null,error:warn?false:true,fields:null,type:"widgets",prog_id:_session.DS_GLB[dsP].prog_id})};const get_fields_data=async function(fields,props){const report_error=function(descP,warn){func.utils.debug.log(SESSION_ID,_session.DS_GLB[dsP].prog_id+"_"+_session.DS_GLB[dsP].callingMenuId,{module:"widgets",action:"Init",source:sourceP,prop:descP,details:descP,result:null,error:warn?false:true,fields:null,type:"widgets",prog_id:_session.DS_GLB[dsP].prog_id})};const get_property_value=async function(fieldIdP,val){var value=props[fieldIdP]||(typeof val.defaultValue==="function"?val?.defaultValue?.():val?.defaultValue);if(props[`xu-exp:${fieldIdP}`]){value=(await func.expression.get(SESSION_ID,props[`xu-exp:${fieldIdP}`],dsP,"widget property")).result}return func.common.get_cast_val(SESSION_ID,"widgets",fieldIdP,val.type,value,null)};var data_obj={};var return_code=1;for await(const[key,val]of Object.entries(fields)){try{data_obj[key]=await get_property_value(key,val);if(!data_obj[key]&&val.mandatory){return_code=-1;report_error(`${key} is a mandatory field.`);break}}catch(error){debugger}}return{code:return_code,data:data_obj}};try{const _plugin=APP_OBJ[_session.app_id]?.app_plugins_purchased?.[plugin_name];const index=await func.utils.get_plugin_resource(SESSION_ID,plugin_name,`${_plugin.manifest["index.mjs"].dist?"dist/":""}index.mjs`);const methods=index.methods;if(methods&&!methods[method]){return report_error("method not found")}const fields_ret=await get_fields_data(methods[method].fields,propsP);if(fields_ret.code<0){return report_error(fields_ret.data)}const fields=fields_ret.data;const plugin_setup_ret=await func.utils.get_plugin_setup(SESSION_ID,plugin_name);if(plugin_setup_ret.code<0){return report_error(plugin_setup_ret)}const api_utils=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:dsP,job_id:jobNoP});const params={SESSION_ID:SESSION_ID,method:method,_session:_session,dsP:dsP,sourceP:sourceP,propsP:propsP,plugin_name:plugin_name,$containerP:$containerP,plugin_setup:plugin_setup_ret.data,report_error:report_error,call_plugin_api:call_plugin_api,set_SYS_GLOBAL_OBJ_WIDGET_INFO:set_SYS_GLOBAL_OBJ_WIDGET_INFO,api_utils:api_utils};const fx=await func.utils.get_plugin_resource(SESSION_ID,plugin_name,`${_plugin.manifest["runtime.mjs"].dist?"dist/":""}runtime.mjs`);if(!fx[method]){throw`Method: ${method} does not exist`}await fx[method](fields,params)}catch(err){report_error(err)}func.events.delete_job(SESSION_ID,jobNoP)},call_native_javascript:async function(){const module=await func.common.get_module(SESSION_ID,"xuda-event-javascript-module.mjs");const result=await module.call_javascript(SESSION_ID,jobNoP,refIdP,dsSession,false,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},call_evaluate_javascript:async function(){const module=await func.common.get_module(SESSION_ID,"xuda-event-javascript-module.mjs");const result=await module.call_javascript(SESSION_ID,jobNoP,refIdP,dsSession,true,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},execute_native_javascript:async function(){const module=await func.common.get_module(SESSION_ID,"xuda-event-javascript-module.mjs");const resolved_element_expr=`(func.runtime.ui && func.runtime.ui.find_xu_ui_in_root && func.runtime.ui.get_first_node ? func.runtime.ui.get_first_node(func.runtime.ui.find_xu_ui_in_root(SESSION_ID, ${JSON.stringify(elementP)})) : null)`;const result=await module.run_javascript(SESSION_ID,jobNoP,dsSession,`(async function(el,evt) {
74
+ </div>`)}const get_url=function(domain,method,path){return`https://${domain}/${method}${path?"/"+path:"/"}`};func.utils.load_css_on_demand(get_url(domain,"dist","runtime/css/mobile.css"));return $root_element};func.runtime.ui.ensure_embed_container=function(SESSION_ID){const $root_element=func.runtime.ui.get_root_element(SESSION_ID);let $embed_container=func.runtime.ui.find_by_selector($root_element,`#embed_${SESSION_ID}`,true);if(!$embed_container.length){const $ssr_embed_container=func.runtime.ui.find_by_selector($root_element,`[data-xuda-ssr-embed="true"]`,true);const ssr_embed_node=func.runtime.ui.get_first_node($ssr_embed_container);if(ssr_embed_node){ssr_embed_node.id="embed_"+SESSION_ID;$embed_container=func.runtime.ui._wrap_matches([ssr_embed_node])}}if(!$embed_container.length){const embed_node=document.createElement("div");embed_node.id="embed_"+SESSION_ID;embed_node.className="xu_embed_div";func.runtime.ui.set_data(embed_node,"xuData",{});$embed_container=func.runtime.ui._wrap_matches([embed_node]);func.runtime.ui.append_to($embed_container,$root_element)}return $embed_container};func.runtime.ui.get_embed_container=function(SESSION_ID){return func.runtime.ui.find_by_selector(func.runtime.ui.get_root_element(SESSION_ID),`#embed_${SESSION_ID}`,true)};func.runtime.ui.get_embed_screen_containers=function(){return func.runtime.ui.find_by_selector(document.body,".xu_embed_container")};func.runtime.ui.append_to_body=function($element){func.runtime.ui.append_to($element,document.body);return $element};func.runtime.ui.find_in_root=function(SESSION_ID,selector){return func.runtime.ui.find_by_selector(func.runtime.ui.get_root_element(SESSION_ID),selector)};func.runtime.ui.get_root_tag_name=function(){let root_tag_name="div";if(!func.runtime.session.is_slim()){if(typeof UI_FRAMEWORK_PLUGIN?.core!=="function"){return root_tag_name}const ui_plugin_core=new UI_FRAMEWORK_PLUGIN.core;root_tag_name=ui_plugin_core?.rootTagName()||root_tag_name}return root_tag_name};func.runtime.ui.find_ssr_screen_host=function($container,screenId,containerId){const container_node=func.runtime.ui.get_first_node($container);if(!container_node||!screenId){return null}const dialog_node=container_node.querySelector?.(`#${CSS?.escape?CSS.escape(screenId):screenId}`)||container_node.querySelector?.(`[data-xuda-ssr-screen-id="${screenId}"]`);if(!dialog_node){return null}const root_frame_node=(containerId?dialog_node.querySelector?.(`#${CSS?.escape?CSS.escape(containerId):containerId}`):null)||dialog_node.querySelector?.('[data-xuda-ssr-root-frame="true"]');if(!root_frame_node){return null}return{$dialogDiv:func.runtime.ui._wrap_matches([dialog_node]),$rootFrame:func.runtime.ui._wrap_matches([root_frame_node]),reused_ssr_host:true}};func.runtime.ui.create_screen_host=function(SESSION_ID,screen_type,params,$callingContainerP,screenId){var $dialogDiv;var $rootFrame;let reused_ssr_host=false;switch(screen_type){case"embed":{const ssr_host=func.runtime.ui.find_ssr_screen_host($callingContainerP,screenId,params?.containerIdP);if(ssr_host){return ssr_host}const dialogNode=document.createElement("div");dialogNode.id=screenId;dialogNode.setAttribute("ui_engine",UI_FRAMEWORK_INSTALLED);dialogNode.classList.add("xu_embed_container");dialogNode.style.display="contents";func.runtime.ui.set_data(dialogNode,"xuData",{paramsP:params,screenInfo:params.screenInfo});$dialogDiv=func.runtime.ui._wrap_matches([dialogNode]);const root_tag_name=func.runtime.ui.get_root_tag_name();const rootFrameNode=document.createElement(root_tag_name);func.runtime.ui.set_data(rootFrameNode,"xuData",{});func.runtime.ui.set_data(rootFrameNode,"xuAttributes",{});dialogNode.appendChild(rootFrameNode);$rootFrame=func.runtime.ui._wrap_matches([rootFrameNode]);func.runtime.ui.append_to($dialogDiv,$callingContainerP);break}case"panel":$dialogDiv=$callingContainerP;func.runtime.ui.set_data($dialogDiv,"xuData",{paramsP:params,screenInfo:params.screenInfo});$rootFrame=$dialogDiv;break;case"page":case"modal":case"popover":{const dialogNode=document.createElement("div");const rootFrameNode=document.createElement("div");dialogNode.appendChild(rootFrameNode);$dialogDiv=func.runtime.ui._wrap_matches([dialogNode]);$rootFrame=func.runtime.ui._wrap_matches([rootFrameNode]);func.runtime.ui.append_to_body($dialogDiv);break}default:break}return{$dialogDiv:$dialogDiv,$rootFrame:$rootFrame,reused_ssr_host:reused_ssr_host}};func.runtime.ui.find_xu_ui_in_root=function(SESSION_ID,xu_ui_id){if(!SESSION_ID||!xu_ui_id){return func.runtime.ui._wrap_matches([])}if(func.runtime.ui.get_refresh_indexed_element_by_ui_id){const elm=func.runtime.ui.get_refresh_indexed_element_by_ui_id(SESSION_ID,xu_ui_id);return func.runtime.ui._wrap_matches(elm?[elm]:[])}return func.runtime.ui.find_in_root(SESSION_ID,`[xu-ui-id="${xu_ui_id}"]`)};func.runtime.ui.find_panel_wrapper_in_root=function(SESSION_ID,xu_ui_id){if(func.runtime.ui.get_refresh_indexed_panel_wrapper_by_id){const elm=func.runtime.ui.get_refresh_indexed_panel_wrapper_by_id(SESSION_ID,xu_ui_id);return func.runtime.ui._wrap_matches(elm?[elm]:[])}return func.runtime.ui.find_in_root(SESSION_ID,`[xu-panel-wrapper-id=${xu_ui_id}]`)};func.runtime.ui.find_element_data_in_root=function(SESSION_ID,dataKey,property,value){if(dataKey==="xuData"&&property==="ui_id"&&typeof value!=="undefined"&&func.runtime.ui.get_refresh_indexed_element_by_ui_id){const elm=func.runtime.ui.get_refresh_indexed_element_by_ui_id(SESSION_ID,value);return func.runtime.ui._wrap_matches(elm?[elm]:[])}if(dataKey==="xuData"&&property==="nodeid"&&typeof value!=="undefined"&&func.runtime.ui.get_refresh_indexed_elements_by_node_id){return func.runtime.ui.get_refresh_indexed_elements_by_node_id(SESSION_ID,value)}if(dataKey==="xuPanelWrapper"&&property==="isWrapper"&&typeof value==="undefined"){if(func.runtime.ui.get_refresh_indexed_panel_wrappers){return func.runtime.ui.get_refresh_indexed_panel_wrappers(SESSION_ID)}return func.runtime.ui.find_in_root(SESSION_ID,"[xu-panel-wrapper-id]")}return func.UI.utils.find_in_element_data(dataKey,func.runtime.ui.get_root_element(SESSION_ID),property,value)};func.runtime.ui.find_element_data_in_parent=function($container,dataKey,property,value){const container_node=func.runtime.ui.get_first_node($container);const parent_node=container_node?.parentElement;if(!parent_node){return func.runtime.ui._wrap_matches([])}if(dataKey==="xuData"&&property==="ui_id"&&typeof value!=="undefined"){if(func.runtime.ui.find_refresh_elements_by_attr){return func.runtime.ui.find_refresh_elements_by_attr(parent_node,"xu-ui-id",value,true)}return func.runtime.ui.find_by_selector(parent_node,`[xu-ui-id="${value}"]`)}return func.UI.utils.find_in_element_data(dataKey,func.runtime.ui._wrap_matches([parent_node]),property,value)};func.runtime.ui.sync_child_parent_container=function($div){const div_node=func.runtime.ui.get_first_node($div);const parent_container=func.runtime.ui.get_data(div_node)?.xuData?.parent_container;const children=div_node?.children?Array.from(div_node.children):[];for(let index=0;index<children.length;index++){const child_data=func.runtime.ui.get_data(children[index]);if(!child_data?.xuData?.parent_container){continue}child_data.xuData.parent_container=parent_container}return $div};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.ui.ui_id_hash_cache=func.runtime.ui.ui_id_hash_cache||new Map;func.runtime.ui.node_snapshot_cache=func.runtime.ui.node_snapshot_cache||new WeakMap;func.runtime.ui.node_child_items_cache=func.runtime.ui.node_child_items_cache||new WeakMap;func.runtime.ui.node_children_by_id_cache=func.runtime.ui.node_children_by_id_cache||new WeakMap;func.runtime.ui._meta_store=func.runtime.ui._meta_store||{};func.runtime.ui._element_id_to_xu_ui_id=func.runtime.ui._element_id_to_xu_ui_id||{};func.runtime.ui.set_meta=function(xu_ui_id,key,value){if(!xu_ui_id)return;if(!func.runtime.ui._meta_store[xu_ui_id]){func.runtime.ui._meta_store[xu_ui_id]={}}func.runtime.ui._meta_store[xu_ui_id][key]=value};func.runtime.ui.get_meta=function(xu_ui_id,key){const entry=func.runtime.ui._meta_store[xu_ui_id];if(!entry)return undefined;return key?entry[key]:entry};func.runtime.ui.delete_meta=function(xu_ui_id){delete func.runtime.ui._meta_store[xu_ui_id];for(const id in func.runtime.ui._element_id_to_xu_ui_id){if(func.runtime.ui._element_id_to_xu_ui_id[id]===xu_ui_id){delete func.runtime.ui._element_id_to_xu_ui_id[id]}}};func.runtime.ui.register_element_id=function(element_id,xu_ui_id){if(element_id&&xu_ui_id){func.runtime.ui._element_id_to_xu_ui_id[element_id]=xu_ui_id}};func.runtime.ui.get_meta_by_element_id=function(element_id){if(!element_id)return undefined;const xu_ui_id=func.runtime.ui._element_id_to_xu_ui_id[element_id];if(xu_ui_id){return func.runtime.ui._meta_store[xu_ui_id]}if(typeof document!=="undefined"){const clean_id=element_id.startsWith("#")?element_id.substring(1):element_id;const el=document.getElementById(clean_id);if(el){const dom_xu_ui_id=el.getAttribute("xu-ui-id");if(dom_xu_ui_id){func.runtime.ui.register_element_id(clean_id,dom_xu_ui_id);return func.runtime.ui._meta_store[dom_xu_ui_id]}return func.runtime.ui.get_data(el)}}return undefined};func.runtime.ui.find_element_by_id=function(element_id){if(!element_id)return null;if(typeof document!=="undefined"){return document.getElementById(element_id)||null}return null};func.runtime.ui.get_parent_element_id=function(element_id){if(!element_id){return null}const clean_id=element_id.startsWith("#")?element_id.substring(1):element_id;const element=func.runtime.ui.find_element_by_id(clean_id);return element?.parentElement?.id||null};func.runtime.ui.get_session_root=function(SESSION_ID){if(typeof document!=="undefined"){return document.getElementById("embed_"+SESSION_ID)||null}return null};func.runtime.ui.clear_screen_blockers=function(){if(typeof document!=="undefined"){const blockers=document.querySelectorAll(".screen_blocker");for(let i=0;i<blockers.length;i++){blockers[i].remove()}}};func.runtime.ui.as_jquery=function(target){const node=func.runtime.ui.get_first_node(target);return func.runtime.ui._wrap_matches(node?[node]:[])};func.runtime.ui.get_first_node=function(target){if(!target){return null}if(target?.nodeType){return target}if(Array.isArray(target)||typeof target?.length==="number"){return target[0]||null}return null};func.runtime.ui.get_data=function(target){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.getAttribute){const xu_ui_id=target_node.getAttribute("xu-ui-id");if(xu_ui_id){const meta=func.runtime.ui._meta_store[xu_ui_id];if(meta)return meta}}if(target_node){if(!target_node.__xuData){target_node.__xuData={}}return target_node.__xuData}return{}};func.runtime.ui.get_parent=function(target){const target_node=func.runtime.ui.get_first_node(target);return target_node?.parentElement||null};func.runtime.ui.get_children=function(target){const target_node=func.runtime.ui.get_first_node(target);return target_node?.children?Array.from(target_node.children):[]};func.runtime.ui._wrap_matches=function(matches){if(!matches)matches=[];const result={length:matches.length,toArray:function(){return matches.slice()}};for(let i=0;i<matches.length;i++){result[i]=matches[i]}result[Symbol.iterator]=function(){let idx=0;return{next:function(){if(idx<matches.length){return{value:matches[idx++],done:false}}return{done:true}}}};return result};func.runtime.ui.find_by_selector=function(target,selector,first_only=false){const target_node=func.runtime.ui.get_first_node(target);const root_nodes=target_node?[target_node]:Array.isArray(target)?target:target?.length?Array.from(target):[];const matches=[];for(let root_index=0;root_index<root_nodes.length;root_index++){const root_node=root_nodes[root_index];if(root_node?.matches?.(selector)){matches.push(root_node);if(first_only){break}}if(first_only&&matches.length){break}if(first_only){const first_match=root_node?.querySelector?.(selector);if(first_match){matches.push(first_match);break}continue}const descendants=root_node?.querySelectorAll?.(selector)||[];for(let index=0;index<descendants.length;index++){matches.push(descendants[index])}}return func.runtime.ui._wrap_matches(matches)};func.runtime.ui.insert_before=function($element,$reference){const element_node=func.runtime.ui.get_first_node($element);const reference_node=func.runtime.ui.get_first_node($reference);if(reference_node?.before&&element_node){reference_node.before(element_node)}if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target($reference,func.runtime.ui.get_data($element)?.xuData?.SESSION_ID)}return $element};func.runtime.ui.insert_after=function($element,$reference){const element_node=func.runtime.ui.get_first_node($element);const reference_node=func.runtime.ui.get_first_node($reference);if(reference_node?.after&&element_node){reference_node.after(element_node)}if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target($reference,func.runtime.ui.get_data($element)?.xuData?.SESSION_ID)}return $element};func.runtime.ui.has_selector=function(target,selector){return!!func.runtime.ui.get_first_node(func.runtime.ui.find_by_selector(target,selector,true))};func.runtime.ui.append_html=function(target,html){const target_node=func.runtime.ui.get_first_node(target);if(!target_node||!html){return target_node||null}target_node.insertAdjacentHTML("beforeend",html);if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target(target_node)}return target_node};func.runtime.ui.set_style=function(target,prop,value){const target_node=func.runtime.ui.get_first_node(target);if(!target_node?.style||!prop){return target_node||null}target_node.style[prop]=value;return target_node};func.runtime.ui.normalize_external_asset_url=function(value){if(typeof value!=="string"||!value.trim()){return value}const trimmed_value=value.trim();try{const url=new URL(trimmed_value,typeof document!=="undefined"?document.baseURI:"https://xuda.ai");if(url.hostname==="via.placeholder.com"){url.hostname="placehold.co";return url.toString()}}catch(_){if(trimmed_value.startsWith("https://via.placeholder.com/")||trimmed_value.startsWith("http://via.placeholder.com/")){return trimmed_value.replace("via.placeholder.com","placehold.co")}}return value};func.runtime.ui.normalize_svg_path_value=function(value){if(typeof value!=="string"||!value.trim()){return value}let normalized_value=value.trim();normalized_value=normalized_value.replace(/([zZ])+\s*[mMlLhHvVcCsSqQtTaA]\s*$/g,"$1");return normalized_value};func.runtime.ui.normalize_attr_value=function(target_or_tag,key,value){if(typeof value!=="string"){return value}const target_tag_name=typeof target_or_tag==="string"?target_or_tag:func.runtime.ui.get_first_node(target_or_tag)?.tagName||"";const tag_name=`${target_tag_name||""}`.trim().toLowerCase();const attr_name=`${key||""}`.trim().toLowerCase();if((tag_name==="img"||tag_name==="image")&&["src","href","xlink:href"].includes(attr_name)){return func.runtime.ui.normalize_external_asset_url(value)}if(tag_name==="path"&&attr_name==="d"){return func.runtime.ui.normalize_svg_path_value(value)}return value};func.runtime.ui.get_attr=function(target,key){const target_node=func.runtime.ui.get_first_node(target);return target_node?.getAttribute?.(key)??undefined};func.runtime.ui.set_attr=function(target,key,value){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.setAttribute){const normalized_value=func.runtime.ui.normalize_attr_value(target_node,key,value);try{target_node.setAttribute(key,normalized_value)}catch(error){console.warn(`Failed to set attribute "${key}" on <${target_node.tagName?.toLowerCase?.()||"unknown"}>`,error)}}return target_node||target};func.runtime.ui.set_data=function(target,key,value){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.getAttribute){const xu_ui_id=target_node.getAttribute("xu-ui-id");if(xu_ui_id){func.runtime.ui.set_meta(xu_ui_id,key,value);return target}}if(target_node){if(!target_node.__xuData)target_node.__xuData={};target_node.__xuData[key]=value}return target};func.runtime.ui.clear_data=function(target){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.getAttribute){const xu_ui_id=target_node.getAttribute("xu-ui-id");if(xu_ui_id){func.runtime.ui.delete_meta(xu_ui_id)}}if(target_node?.__xuData){delete target_node.__xuData}return target};func.runtime.ui.add_class=function(target,class_name){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.classList){target_node.classList.add(class_name);return target_node}return target_node||null};func.runtime.ui.remove_class=function(target,class_name){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.classList){target_node.classList.remove(class_name);return target_node}return target_node||null};func.runtime.ui.set_html=function(target,value){const target_node=func.runtime.ui.get_first_node(target);if(typeof target_node?.innerHTML!=="undefined"){target_node.innerHTML=value;return target_node}return target_node||null};func.runtime.ui.set_text=function(target,value){const target_node=func.runtime.ui.get_first_node(target);if(typeof target_node?.textContent!=="undefined"){target_node.textContent=value;return target_node}return target_node||null};func.runtime.ui.show=function(target){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.style){target_node.style.removeProperty("display");return target_node}return target_node||null};func.runtime.ui.hide=function(target){const target_node=func.runtime.ui.get_first_node(target);if(target_node?.style){target_node.style.display="none";return target_node}return target_node||null};func.runtime.ui.append=function($target,$element){const target_node=func.runtime.ui.get_first_node($target);const element_node=func.runtime.ui.get_first_node($element);if(target_node&&element_node){target_node.appendChild(element_node)}if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target($target,func.runtime.ui.get_data($element)?.xuData?.SESSION_ID)}func.runtime?.perf?.increment?.(func.runtime.ui.get_data($element)?.xuData?.SESSION_ID,"dom_appends");return $element};func.runtime.ui.append_to=function($element,$target){const target_node=func.runtime.ui.get_first_node($target);const element_node=func.runtime.ui.get_first_node($element);if(target_node&&element_node){target_node.appendChild(element_node)}if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target($target,func.runtime.ui.get_data($element)?.xuData?.SESSION_ID)}func.runtime?.perf?.increment?.(func.runtime.ui.get_data($element)?.xuData?.SESSION_ID,"dom_appends");return $element};func.runtime.ui.empty=function(target){const target_node=func.runtime.ui.get_first_node(target);if(target_node){target_node.replaceChildren()}if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target(target)}return target_node||null};func.runtime.ui.remove=function(target){if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target(target)}let target_nodes;if(target?.nodeType){target_nodes=[target]}else if(Array.isArray(target)){target_nodes=target}else if(target?.length){target_nodes=Array.from(target)}else{target_nodes=[]}const session_id=func.runtime.ui.get_data(target_nodes[0]||target)?.xuData?.SESSION_ID;for(let index=0;index<target_nodes.length;index++){const target_node=target_nodes[index];const xu_ui_id=target_node?.getAttribute?.("xu-ui-id");if(xu_ui_id){func.runtime.ui.delete_meta(xu_ui_id)}if(target_node?.remove){target_node.remove()}}func.runtime?.perf?.increment?.(session_id,"dom_removes",target_nodes.length||1);return true};func.runtime.ui.set_display_contents=function($element){return func.runtime.ui.set_style($element,"display","contents")};func.runtime.ui.create_xurender=function(xu_ui_id,$target,hidden){const xurender=document.createElement("xurender");xurender.setAttribute("xu-ui-id",xu_ui_id);if(hidden){xurender.setAttribute("hidden","true")}return func.runtime.ui.append_to(xurender,$target)};func.runtime.ui.replace_with=function($source,$target){if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target($source,func.runtime.ui.get_data($source)?.xuData?.SESSION_ID||func.runtime.ui.get_data($target)?.xuData?.SESSION_ID)}const source_node=func.runtime.ui.get_first_node($source);const target_node=func.runtime.ui.get_first_node($target);if(source_node?.replaceWith&&target_node){source_node.replaceWith(target_node)}return $target};func.runtime.ui.remove_xu_ui=function(xu_ui_id){const $targets=func.runtime.ui.find_by_selector(document.body,`[xu-ui-id="${xu_ui_id}"]`,false);if(func.runtime.ui.mark_refresh_index_dirty_from_target){func.runtime.ui.mark_refresh_index_dirty_from_target($targets)}const targets=$targets.toArray();for(let index=0;index<targets.length;index++){targets[index].remove?.()}return true};func.runtime.ui.build_debug_info=function(nodeP,$container,items){return{id:nodeP.id,parent_id:func.runtime.ui.get_data($container)?.xuData?.ui_id,items:items}};func.runtime.ui.get_node_snapshot=function(nodeP){if(!nodeP){return nodeP}if(func.runtime.ui.node_snapshot_cache.has(nodeP)){return func.runtime.ui.node_snapshot_cache.get(nodeP)}const snapshot=structuredClone(nodeP);func.runtime.ui.node_snapshot_cache.set(nodeP,snapshot);return snapshot};func.runtime.ui.get_node_child_items=function(nodeP){if(!nodeP?.children?.length){return[]}if(func.runtime.ui.node_child_items_cache.has(nodeP)){return func.runtime.ui.node_child_items_cache.get(nodeP)}const items=nodeP.children.map(function(val){return val.xu_tree_id||val.id});func.runtime.ui.node_child_items_cache.set(nodeP,items);return items};func.runtime.ui.get_node_children_by_id=function(nodeP){if(!nodeP?.children?.length){return{}}if(func.runtime.ui.node_children_by_id_cache.has(nodeP)){return func.runtime.ui.node_children_by_id_cache.get(nodeP)}const children_by_id={};for(let index=0;index<nodeP.children.length;index++){const child_node=nodeP.children[index];if(child_node?.id){children_by_id[child_node.id]=child_node}}func.runtime.ui.node_children_by_id_cache.set(nodeP,children_by_id);return children_by_id};func.runtime.ui.build_container_xu_data=function(options){return{SESSION_ID:options.SESSION_ID,prog_id:options.paramsP.prog_id,nodeid:options.nodeP.id,ui_type:options.nodeP.tagName,recordid:options.currentRecordId,paramsP:options.paramsP,key:options.keyP,key_path:options.key_path,screenId:options.paramsP.screenId,parent_container:func.runtime.ui.get_attr(options.$container,"id"),elem_key:options.elem_key,properties:options.prop,node:options.nodeP,node_org:func.runtime.ui.get_node_snapshot(options.nodeP),is_panelP:options.paramsP.is_panelP,ui_id:options.ui_id,elem_prop:options.elem_propP,debug_info:func.runtime.ui.build_debug_info(options.nodeP,options.$container,options.items),parent_node:options.parent_nodeP,currentRecordId:options.currentRecordId,$root_container:options.$root_container,parent_element_ui_id:func.runtime.ui.get_data(options.$container)?.xuData?.ui_id,is_placeholder:!!options.is_placeholder}};func.runtime.ui.apply_container_meta=function($div,options){const div_node=func.runtime.ui.get_first_node($div);func.runtime.ui.set_attr(div_node,"xu-ui-id",options.ui_id);func.runtime.ui.set_attr(div_node,"data-xuda-kind",options.treeP?.kind||options.nodeP?.tagName||"element");func.runtime.ui.set_attr(div_node,"data-xuda-node-id",options.nodeP?.id||options.nodeP?.id_org||"");if(options.treeP?.meta?.tree_id!==null&&typeof options.treeP?.meta?.tree_id!=="undefined"){func.runtime.ui.set_attr(div_node,"data-xuda-tree-id",options.treeP.meta.tree_id)}const xuData=func.runtime.ui.build_container_xu_data(options);if(options.parent_infoP?.iterate_info){xuData.iterate_info=options.parent_infoP.iterate_info}func.runtime.ui.set_data(div_node,"xuData",xuData);func.runtime.ui.set_data(div_node,"xuAttributes",{});func.runtime.ui.set_meta(options.ui_id,"xuData",xuData);func.runtime.ui.set_meta(options.ui_id,"xuAttributes",{});const container_id=func.runtime.ui.get_attr(div_node,"id");if(container_id){func.runtime.ui.register_element_id(container_id,options.ui_id)}if(options.is_placeholder){func.runtime.ui.add_class(div_node,"display_none")}if(options.classP){func.runtime.ui.add_class(div_node,options.classP)}return $div};func.runtime.ui.get_append_target=function($container,$appendToP){const $appendTo=$appendToP||$container;if(!$appendTo){return null}const node=func.runtime.ui.get_first_node($appendTo);if(!node){return null}return $appendTo};func.runtime.ui.create_element=function(tag_name,attr_str){const el=document.createElement(tag_name);if(attr_str){const attr_regex=/([a-zA-Z_][\w\-.:]*)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|(\S+)))?/g;let match;while((match=attr_regex.exec(attr_str))!==null){const key=match[1];const value=match[2]!==undefined?match[2]:match[3]!==undefined?match[3]:match[4]!==undefined?match[4]:"";const normalized_value=func.runtime.ui.normalize_attr_value(tag_name,key,value);try{el.setAttribute(key,normalized_value)}catch(error){console.warn(`Failed to set attribute "${key}" on <${tag_name}>`,error)}}}return el};func.runtime.ui.create_svg_element=function(element,prop,nodeP,$appendTo){const get_tag_str=function(element,prop,val){let attr_str="";for(const[key,value]of Object.entries(prop)){if(key.substr(0,2)!=="xu"){const normalized_value=func.runtime.ui.normalize_attr_value(element,key,value);attr_str+=` ${key}="${normalized_value}" `}}if(element==="svg"){return`<${element} ${attr_str} > `}let ret="";if(val?.children?.length){ret=iterate_svg(val)}return`<${element} ${attr_str} > ${ret} </${element}>`};const iterate_svg=function(node){let ret="";if(node.children){for(let val of node.children){if(val.type==="comment")continue;ret+=get_tag_str(val.tagName,val.attributes,val)}}return ret};const svg_str=get_tag_str(element,prop);const inner_str=iterate_svg(nodeP);const full_svg_str=svg_str+inner_str+"</svg>";const tmp=document.createElement("div");tmp.innerHTML=full_svg_str;const svg_el=tmp.firstElementChild;return func.runtime.ui.append_to(svg_el,$appendTo)};func.runtime.ui.create_container_element=function(div_typeP,attr_str,prop,nodeP,$appendTo){const div=div_typeP||"div";if(div==="svg"){return func.runtime.ui.create_svg_element(div_typeP,prop,nodeP,$appendTo)}return func.runtime.ui.create_element(div,attr_str)};func.runtime.ui.find_hydration_candidate=function(options){if(!func.runtime.render.is_hydration_mode(SESSION_OBJ?.[options.SESSION_ID])){return null}if(!func.runtime.render.should_use_ssr_payload(options.SESSION_ID,options.paramsP)){return null}if(options.is_placeholder||!options.treeP?.meta?.tree_id){return null}const append_node=func.runtime.ui.get_first_node(options.$appendTo||options.$container);if(!append_node){return null}const children=func.runtime.ui.get_children(append_node);for(let index=0;index<children.length;index++){const child=children[index];if(child?.__xuda_hydration_claimed){continue}if(func.runtime.ui.get_attr(child,"data-xuda-tree-id")!==`${options.treeP.meta.tree_id}`){continue}child.__xuda_hydration_claimed=true;func.runtime.ui.set_attr(child,"data-xuda-client-activation","hydrate");return child}return null};func.runtime.ui.build_xu_ui_id_seed=function(nodeP,dsSessionP,key_path,currentRecordId){const nodeId=nodeP.xu_tree_id||nodeP.id;const elem_key=`${nodeId}-${key_path}-${currentRecordId}`;return`${nodeP.id}-${elem_key}-${dsSessionP?.toString()||""}`};func.runtime.ui.build_container_key_path=function(container_xu_data,keyP,parent_infoP,nodeP,parent_nodeP){const key_segment=typeof keyP==="undefined"||keyP===null?"0":`${keyP}`;let key_path=`${container_xu_data?.key_path||"0"}-${key_segment}`;const parent_identity=parent_nodeP?.xu_tree_id||parent_nodeP?.id;const node_identity=nodeP?.xu_tree_id||nodeP?.id;const is_iterated_clone=!!(parent_infoP?.iterate_info&&parent_identity&&node_identity&&parent_identity===node_identity);if(is_iterated_clone){key_path+="-iter"}return key_path};func.runtime.ui.generate_xu_ui_id=async function(SESSION_ID,nodeP,$container,paramsP,keyP,precomputed={}){const dsSessionP=paramsP.dsSessionP;const _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];const containerXuData=precomputed.container_xu_data||func.runtime.ui.get_data($container)?.xuData;const currentRecordId=typeof precomputed.currentRecordId!=="undefined"?precomputed.currentRecordId:containerXuData?.recordid||_ds?.currentRecordId||"";const key_path=precomputed.key_path||func.runtime.ui.build_container_key_path(containerXuData,keyP,precomputed.parent_infoP,nodeP,precomputed.parent_nodeP);const ui_id=func.runtime.ui.build_xu_ui_id_seed(nodeP,dsSessionP,key_path,currentRecordId);if(func.runtime.ui.ui_id_hash_cache.has(ui_id)){return func.runtime.ui.ui_id_hash_cache.get(ui_id)}const hashed_ui_id=await func.common.fastHash(ui_id);func.runtime.ui.ui_id_hash_cache.set(ui_id,hashed_ui_id);return hashed_ui_id};func.runtime.ui.create_container=async function(options){let _paramsP;try{_paramsP=JSON.parse(JSON.stringify(options.paramsP))}catch(e){_paramsP=Object.assign({},options.paramsP)}const _ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[_paramsP.dsSessionP];const $appendTo=func.runtime.ui.get_append_target(options.$container,options.$appendToP);if(!$appendTo)return null;const container_data=func.runtime.ui.get_data(options.$container);const container_xu_data=container_data?.xuData;const items=func.runtime.ui.get_node_child_items(options.nodeP);const currentRecordId=container_xu_data?.recordid||(_ds?_ds.currentRecordId:"");try{const key_path=func.runtime.ui.build_container_key_path(container_xu_data,options.keyP,options.parent_infoP,options.nodeP,options.parent_nodeP);const elem_key=`${options.nodeP.xu_tree_id||options.nodeP.id}-${key_path}-${currentRecordId}`;const hydration_candidate=func.runtime.ui.find_hydration_candidate({...options,$appendTo:$appendTo});const $div=hydration_candidate||func.runtime.ui.create_container_element(options.div_typeP,options.attr_str,options.prop,options.nodeP,$appendTo);const new_ui_id=await func.runtime.ui.generate_xu_ui_id(options.SESSION_ID,options.nodeP,options.$container,options.paramsP,options.keyP,{container_xu_data:container_xu_data,currentRecordId:currentRecordId,key_path:key_path,parent_infoP:options.parent_infoP,parent_nodeP:options.parent_nodeP});func.runtime.ui.apply_container_meta($div,{ui_id:new_ui_id,paramsP:_paramsP,nodeP:options.nodeP,currentRecordId:currentRecordId,keyP:options.keyP,key_path:key_path,$container:options.$container,prop:options.prop,elem_key:elem_key,elem_propP:options.elem_propP,items:items,parent_nodeP:options.parent_nodeP,$root_container:options.$root_container,parent_infoP:options.parent_infoP,is_placeholder:options.is_placeholder,classP:options.classP,treeP:options.treeP});if(!hydration_candidate&&options.div_typeP!=="svg"){func.runtime.ui.append_to($div,$appendTo)}return $div}catch(e){console.error(e)}return null};func.UI.utils={};func.UI.utils.indicator={};func.UI.utils.indicator.worker={};func.UI.utils.indicator.worker.busy=function(){document.querySelectorAll(".progressLoader").forEach(function(el){el.classList.add("progress_busy")})};func.UI.utils.indicator.worker.normal=function(){document.querySelectorAll(".progressLoader").forEach(function(el){el.classList.remove("progress_busy")})};func.UI.utils.indicator.server={};func.UI.utils.indicator.server.busy=function(){func.UI.utils.indicator.worker.busy()};func.UI.utils.indicator.server.normal=function(){func.UI.utils.indicator.worker.normal()};func.UI.utils.indicator.screen={};func.UI.utils.indicator.screen.busy=function(){document.querySelectorAll(".progressLoader").forEach(function(el){el.classList.add("progress_busy2")})};func.UI.utils.indicator.screen.normal=function(){document.querySelectorAll(".progressLoader").forEach(function(el){el.classList.remove("progress_busy2")})};func.UI.utils.save=function(SESSION_ID,stateP){if(stateP)func.UI.utils.indicator.worker.busy();else func.UI.utils.indicator.worker.normal()};func.UI.utils.screen_blocker=function(onP,idP,dsP){if(!idP){func.utils.debug_report("","Worker","Missing reference id","E");return}window.oncontextmenu=function(){if(onP)return false;else return true};if(!onP){delete SCREEN_BLOCKER_OBJ[idP];return}if(idP!=="Worker"){SCREEN_BLOCKER_OBJ[idP]=Date.now()}};func.UI.utils.get_node_elm=function(SESSION_ID,dsSessionP,ui_idP,$container,is_app_panel,ui_type,functionP){if(!$container){$container=func.runtime.ui._wrap_matches([document.body])}var $elm;if(!is_app_panel&&func.runtime?.ui?.find_xu_ui_in_root){$elm=func.runtime.ui.find_xu_ui_in_root(SESSION_ID,ui_idP)}else if(is_app_panel&&func.runtime?.ui?.find_panel_wrapper_in_root){$elm=func.runtime.ui.find_panel_wrapper_in_root(SESSION_ID,ui_idP)}if(!$elm?.length){$elm=func.UI.utils.find_in_element_data(is_app_panel?"xuPanelData":"xuData",$container,"ui_id",ui_idP)}const _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dsSessionP];if(_ds.tree_obj.renderType==="form"){return $elm}var $grid_elm;const grid_elements=$elm.toArray();for(let index=0;index<grid_elements.length;index++){const candidate=grid_elements[index];if(func.runtime.ui.get_data(candidate)?.xuData?.recordid===_ds.currentRecordId){$grid_elm=func.runtime.ui._wrap_matches([candidate]);break}}return $grid_elm;return $elm};func.UI.utils.get_nodeId=function(SESSION_ID,dsSessionP,ui_idP,$container,is_app_panel){var $elm=func.UI.utils.get_node_elm(SESSION_ID,dsSessionP,ui_idP,$container,is_app_panel,null,null);if(is_app_panel){return func.runtime.ui.get_data($elm)?.xuData?.panel_info?.prop?.id}else{return func.runtime.ui.get_attr($elm,"nodeId")}};func.UI.utils.get_ui_id_count=function(SESSION_ID,dsSessionP,ui_idP,$container){return func.UI.utils.get_node_elm(SESSION_ID,dsSessionP,ui_idP,$container,null,null).length};func.UI.utils.clean_node_busy=function(node){var run_node=function(node){node.busy=false;for(var key in node.children){run_node(node.children[key])}};run_node(node);return node};func.UI.utils.live_preview_element_inspect_on=function(SESSION_ID,service){var elements=document.querySelectorAll("[xu-ui-id]");elements.forEach(function(val){var _mouseenter_handler=function(){document.querySelectorAll(".preview_mark").forEach(function(el){el.classList.remove("preview_mark");el.removeEventListener("click",el._live_preview_click_handler)});val.classList.add("preview_mark");var _click_handler=function(e){const _session=SESSION_OBJ[SESSION_ID];console.log(func.runtime.ui.get_data(this));const data=func.runtime.ui.get_data(this);const obj={service:service+"_result",id:STUDIO_WEBSOCKET_CONNECTION_ID,uid:_session.USR_OBJ._id,source:"runtime",app_id:_session.app_id,gtp_token:_session.gtp_token,session_id:SESSION_ID,app_token:_session.app_token};switch(service){case"live_preview_element_reference":obj.data={prog_id:data.xuData.prog_id,node:data.xuData.node};break;case"live_preview_element_info":obj.data={element_info:data.debug_info,datasource:_session.DS_GLB[data.paramsP.dsSessionP]};break;case"live_preview_element_dnd":break;default:}STUDIO_PEER_CONN_SEND_METHOD(obj);func.UI.utils.live_preview_element_inspect_off();if(typeof LIVE_PREVIEW_APP_ACTIVE!=="undefined"){var refBtn=document.getElementById("live_preview_element_reference_btn");if(refBtn)refBtn.style.color="unset";var infoBtn=document.getElementById("live_preview_element_info_btn");if(infoBtn)infoBtn.style.color="unset"}};val._live_preview_click_handler=_click_handler;val.addEventListener("click",_click_handler)};var _mouseleave_handler=function(){val.classList.remove("preview_mark");if(val._live_preview_click_handler){val.removeEventListener("click",val._live_preview_click_handler);delete val._live_preview_click_handler}};val._live_preview_mouseenter_handler=_mouseenter_handler;val._live_preview_mouseleave_handler=_mouseleave_handler;val.addEventListener("mouseenter",_mouseenter_handler);val.addEventListener("mouseleave",_mouseleave_handler)})};func.UI.utils.live_preview_element_inspect_off=function(){document.querySelectorAll("[xu-ui-id]").forEach(function(val){if(val._live_preview_mouseenter_handler){val.removeEventListener("mouseenter",val._live_preview_mouseenter_handler);delete val._live_preview_mouseenter_handler}if(val._live_preview_mouseleave_handler){val.removeEventListener("mouseleave",val._live_preview_mouseleave_handler);delete val._live_preview_mouseleave_handler}});document.querySelectorAll(".preview_mark").forEach(function(el){el.classList.remove("preview_mark");if(el._live_preview_click_handler){el.removeEventListener("click",el._live_preview_click_handler);delete el._live_preview_click_handler}})};func.UI.utils.live_preview_show_selected_element=function(nodeid){document.querySelectorAll(".preview_mark").forEach(function(el){el.classList.remove("preview_mark")});document.querySelectorAll(`[nodeid="${nodeid}"]`).forEach(function(el){el.classList.add("preview_mark")})};func.UI.utils.get_url_attribute=function(SESSION_ID,key){const _session=SESSION_OBJ[SESSION_ID];const platform=func.runtime.platform;const url_param=glb.URL_PARAMS?.get?.(key);const root_attribute=func.runtime.ui.get_attr(_session.root_element,key);const option_param=_session.opt?.params?.[key];const option_value=_session.opt?.[key];const cookie_value=platform.get_cookie_item(key);const storage_value=platform.get_storage_item(key,"local");return url_param||root_attribute||option_param||option_value||cookie_value||storage_value};func.UI.utils.get_root_element_attributes=function(SESSION_ID){var ret={};var root_el=func.runtime.ui.get_first_node(SESSION_OBJ[SESSION_ID].root_element);if(root_el){var attrs=root_el.attributes;for(var i=0;i<attrs.length;i++){if(attrs[i].specified){ret[attrs[i].name]=attrs[i].value}}}return ret};func.UI.utils.prompt_confirm_window=async function(SESSION_ID,messageP,picP,confirmYesFuncP,confirmNoFuncP,confirmCancelFuncP,title,colorP){if(confirmNoFuncP){buttons.push({text:"Disagree",role:"no",cssClass:"secondary",handler:()=>{confirmNoFuncP()}})}if(confirmYesFuncP){buttons.push({text:"Agree",role:"yes",cssClass:"secondary",handler:()=>{confirmYesFuncP()}})}if(confirmCancelFuncP){buttons.push({text:"Dismiss",role:"cancel",cssClass:"secondary",handler:()=>{confirmCancelFuncP()}})}UI_FRAMEWORK_PLUGIN.modal(title,messageP,buttons)};func.UI.utils.alert=function(msg){console.error(msg)};func.UI.utils.progressScreen={};func.UI.utils.progressScreen.show=function(SESSION_ID,textP,show_bytesP,error,progress_off,logo_off){if(glb.IS_WORKER){return}const app_obj=APP_OBJ?.[SESSION_OBJ?.[SESSION_ID]?.app_id];var background_color="";var icon=app_obj?._conf?.logo_url||"https://xuda.ai/dist/images/xuda_logo.png";if(app_obj?.app_pic){icon=app_obj.app_pic}if(app_obj&&app_obj.app_icon_prop){if(app_obj.app_icon_prop.app_icon_background_color){background_color=app_obj.app_icon_prop.app_icon_background_color}}IS_PROGRESS_SCREEN_OPEN=true;var progressScreen=document.getElementById("progressScreen2");if(progressScreen)progressScreen.innerHTML="";document.querySelectorAll(".loader").forEach(function(el){el.style.display="none"});if(background_color&&progressScreen){progressScreen.style.color=func.common.getContrast_color(background_color);progressScreen.style.backgroundColor=background_color}setTimeout(function(){if(IS_PROGRESS_SCREEN_OPEN){var error_msg=`<h4>${textP}</h4>`;var progressText=document.getElementById("progressScreen2_text");if(progressText){progressText.style.display="";if(!logo_off){var img=document.createElement("img");img.className="progressScreen_logo";img.src=icon;progressText.prepend(img)}if(error){progressText.insertAdjacentHTML("beforeend",error_msg)}else if(typeof textP==="object"){progressText.appendChild(textP)}else{progressText.insertAdjacentHTML("beforeend",`<p>${textP}</p>`)}}}},500);if(progressScreen)progressScreen.style.display="";var textDiv=document.createElement("div");textDiv.id="progressScreen2_text";textDiv.style.display="none";if(progressScreen)progressScreen.appendChild(textDiv)};func.UI.utils.progressScreen.hide=function(){if(glb.IS_WORKER){return}IS_PROGRESS_SCREEN_OPEN=false;var ps2=document.getElementById("progressScreen2");if(ps2)ps2.style.display="none";var ps2text=document.getElementById("progressScreen2_text");if(ps2text)ps2text.innerHTML=""};func.UI.utils.find_in_element_data=function(folder,$elm,key,val){if(!$elm?.length){return func.runtime.ui._wrap_matches([])}if(folder==="xuData"&&key==="ui_id"&&typeof val!=="undefined"){return func.runtime.ui.find_by_selector($elm,`[xu-ui-id="${val}"]`)}if(folder==="xuPanelWrapper"&&key==="isWrapper"&&typeof val==="undefined"){return func.runtime.ui.find_by_selector($elm,"[xu-panel-wrapper-id]")}let candidate_selector;if(folder==="xuData"||folder==="xuPanelData"){candidate_selector="[xu-ui-id]"}else if(folder==="xuPanelWrapper"){candidate_selector="[xu-panel-wrapper-id]"}else{candidate_selector="*"}const matches=[];const roots=$elm.toArray();for(let root_index=0;root_index<roots.length;root_index++){const root_node=roots[root_index];const candidates=root_node?.querySelectorAll?.(candidate_selector)||[];for(let candidate_index=0;candidate_index<candidates.length;candidate_index++){const candidate=candidates[candidate_index];const folder_data=func.runtime.ui.get_data(candidate)?.[folder];if(!folder_data){continue}if(typeof val==="undefined"){if(!folder_data[key]){continue}}else if(folder_data[key]!=val){continue}matches.push(candidate)}}return func.runtime.ui._wrap_matches(matches)};func.UI.utils.init_ui_framework=async function(SESSION_ID,prog_id){if(typeof glb.SLIM_BUNDLE!=="undefined"||glb.SLIM_BUNDLE)return;var _session=SESSION_OBJ[SESSION_ID];var tree_obj=await func.utils.TREE_OBJ.get(SESSION_ID,prog_id);if(xu_isEmpty(tree_obj)){return console.error("Error: prog "+prog_id+" not found.")}const report_error=function(descP,warn){func.utils.debug.log(SESSION_ID,prog_id,{module:"component",action:"Init",source:"install ui framework",prop:descP,details:descP,result:null,error:warn?false:true,fields:null,type:"component",prog_id:prog_id})};const plugin_name=tree_obj.uiFramework;if(!plugin_name){return report_error("no frameworks plugin defined",true)}if(plugin_name===UI_FRAMEWORK_INSTALLED)return;const _plugin=APP_OBJ[_session.app_id]?.app_plugins_purchased?.[plugin_name];if(!_plugin?.installed){return report_error(`plugin ${plugin_name} not installed`)}const get_path=function(plugin_name,resource){var path=`https://${_session.domain}/plugins/${plugin_name}${resource?"/"+resource:""}?app_id=${_session.app_id}`;return path};var _ui_framework_index;try{const runtime_mjs=`${_plugin.manifest["runtime.mjs"].dist?"dist/":""}runtime.mjs`;_ui_framework_index=await import(get_path(plugin_name,runtime_mjs))}catch(error){return report_error(`plugin ${plugin_name} not found`)}if(!_ui_framework_index){return report_error(`plugin ${plugin_name} is empty`)}if(!_ui_framework_index.core){return report_error(`plugin core not found in ${plugin_name} `)}var _ui_framework_dashboard_setup;var _ui_framework_dashboard_setup_data_ret;const ui_framework_core=new _ui_framework_index.core;if(ui_framework_core.init){try{const setup_mjs=`${_plugin.manifest["index.mjs"].dist?"dist/":""}index.mjs`;_ui_framework_dashboard_setup=await import(get_path(plugin_name,setup_mjs));if(_ui_framework_dashboard_setup){_ui_framework_dashboard_setup_data_ret=await func.utils.get_plugin_setup(SESSION_ID,plugin_name)}}catch(error){}}if(plugin_name!==UI_FRAMEWORK_INSTALLED){UI_FRAMEWORK_INSTALLED=plugin_name;const _plugin_INSTALLED=APP_OBJ[_session.app_id]?.app_plugins_purchased?.[UI_FRAMEWORK_INSTALLED];UI_FRAMEWORK_PLUGIN=_ui_framework_index;if(UI_FRAMEWORK_INSTALLED){var _current_ui_framework_runtime;try{const _runtime_mjs=`${_plugin_INSTALLED.manifest["runtime.mjs"].dist?"dist/":""}runtime.mjs`;_current_ui_framework_runtime=await import(get_path(UI_FRAMEWORK_INSTALLED,_runtime_mjs))}catch(error){return report_error(`plugin ${UI_FRAMEWORK_INSTALLED} not found`)}if(UI_FRAMEWORK_PLUGIN.core.discard&&UI_FRAMEWORK_PLUGIN.init_id){UI_FRAMEWORK_PLUGIN.core.discard(UI_FRAMEWORK_PLUGIN.init_id)}if(_ui_framework_index.resources){for(var key in _current_ui_framework_runtime.resources){var val=_current_ui_framework_runtime.resources[key];func.utils.remove_js_css_file(val.url,val.type)}}}var init_id;if(_ui_framework_index.resources){for await(var val of _ui_framework_index.resources){var ret=undefined;var url=val.url;switch(val.type){case"module":try{ret=await func.utils.load_js_on_demand(url,"module")}catch(error){debugger}break;case"css":ret=func.utils.load_css_on_demand(url);break;case"js":ret=await func.utils.load_js_on_demand(url);break;default:break}if(val.callback){val.callback(ret)}}}if(ui_framework_core.init){init_id=await ui_framework_core.init(_ui_framework_dashboard_setup_data_ret?.code>-1&&_ui_framework_dashboard_setup_data_ret.data);UI_FRAMEWORK_PLUGIN.init_id=init_id}}};func.UI.utils.get_panels_wrapper_from_dom=async function(SESSION_ID,$xu_embed_container,ignore_disableAutoRefresh){const get_refresh_state=function(){return func.runtime?.ui?.ensure_refresh_dependency_state?.(SESSION_ID)||null};const get_cached_panels_obj=function(refresh_state){const cached_panels=ignore_disableAutoRefresh?refresh_state?.panel_wrappers_cache:refresh_state?.panel_wrappers_active_cache;const panels_obj=cached_panels||{};let requires_rebuild=false;const panel_keys=Object.keys(refresh_state?.panel_wrappers_cache||{});for(let index=0;index<panel_keys.length;index++){const panel_entry=refresh_state.panel_wrappers_cache[panel_keys[index]];if(!panel_entry?.$panel_div?.length||!panel_entry.$panel_div[0]?.isConnected){requires_rebuild=true;break}}if(requires_rebuild){refresh_state.panel_wrappers_dirty=true;refresh_state.panel_wrappers_cache={};refresh_state.panel_wrappers_active_cache={};return null}return panels_obj};const refresh_state=get_refresh_state();if(refresh_state&&!refresh_state.panel_wrappers_dirty&&!xu_isEmpty(refresh_state.panel_wrappers_cache)){const cached_panels_obj=get_cached_panels_obj(refresh_state);if(cached_panels_obj){return cached_panels_obj}}let $elm=func.runtime?.ui?.get_refresh_indexed_panel_wrappers?.(SESSION_ID);if(!$elm?.length){const $root=func.runtime?.ui?.get_refresh_index_root?.(SESSION_ID)||func.runtime.ui._wrap_matches([func.runtime.ui.get_first_node(SESSION_OBJ[SESSION_ID].root_element)]);if(func.runtime?.ui?.find_refresh_elements_by_attr){$elm=func.runtime.ui.find_refresh_elements_by_attr($root,"xu-panel-wrapper-id")}else{var _root_node=func.runtime.ui.get_first_node($root);var _panel_matches=[];if(_root_node?.matches?.("[xu-panel-wrapper-id]"))_panel_matches.push(_root_node);_root_node?.querySelectorAll?.("[xu-panel-wrapper-id]")?.forEach(function(el){_panel_matches.push(el)});$elm=func.runtime.ui._wrap_matches(_panel_matches)}}const panels_obj={};const prog_doc_cache={};const panel_elements=Array.isArray($elm)?$elm:$elm.toArray?$elm.toArray():Array.from($elm);for(let elem_index=0;elem_index<panel_elements.length;elem_index++){const $panel_div=func.runtime.ui._wrap_matches([panel_elements[elem_index]]);const panel_wrapper_data=func.runtime.ui.get_data($panel_div)?.xuPanelWrapper;const panelXuAttributes=panel_wrapper_data?.panelXuAttributes;const panelDivData=panel_wrapper_data?.panelDivData;if(!panelXuAttributes)continue;const xu_ui_id=func.runtime.ui.get_attr($panel_div,"xu-ui-id");if(!panels_obj[xu_ui_id]){var _session=SESSION_OBJ[SESSION_ID];let _ds=_session?.DS_GLB[panelDivData.xuData.paramsP.dsSessionP];if(!_ds)continue;let prog_doc=prog_doc_cache[_ds.prog_id];if(!prog_doc){prog_doc=await func.utils.DOCS_OBJ.get(SESSION_ID,_ds.prog_id);prog_doc_cache[_ds.prog_id]=prog_doc}if(!ignore_disableAutoRefresh&&prog_doc.properties.disableAutoRefresh){continue}const ids=[];const child_nodes=$panel_div[0]?.children||[];for(let child_index=0;child_index<child_nodes.length;child_index++){const child_node=child_nodes[child_index];if(func.runtime.ui.get_data(child_node)?.xuPanelData){ids.push(func.runtime.ui.get_attr(child_node,"xu-ui-id"))}}panels_obj[xu_ui_id]={panelXuAttributes:panelXuAttributes,progUi:prog_doc.progUi,prog_doc:prog_doc,$panel_div:$panel_div,_ds:_ds,ids:ids}}}if(refresh_state){refresh_state.panel_wrappers_cache=panels_obj;refresh_state.panel_wrappers_active_cache={};const panel_keys=Object.keys(panels_obj);for(let index=0;index<panel_keys.length;index++){const xu_ui_id=panel_keys[index];const panel_entry=panels_obj[xu_ui_id];if(panel_entry?.prog_doc?.properties?.disableAutoRefresh){continue}refresh_state.panel_wrappers_active_cache[xu_ui_id]=panel_entry}refresh_state.panel_wrappers_dirty=false}if(!ignore_disableAutoRefresh){return refresh_state?.panel_wrappers_active_cache||panels_obj}return panels_obj};func.UI.worker={};func.UI.worker.ID=null;func.UI.worker.idle=0;func.UI.worker.ensure_runtime_indexes=function(){if(!UI_WORKER_OBJ.job_index_by_num){UI_WORKER_OBJ.job_index_by_num={}}if(!UI_WORKER_OBJ.jobs_by_queue_key){UI_WORKER_OBJ.jobs_by_queue_key={}}if(!UI_WORKER_OBJ.viewport_height_set_ids_set){UI_WORKER_OBJ.viewport_height_set_ids_set=new Set(UI_WORKER_OBJ.viewport_height_set_ids||[])}if(!UI_WORKER_OBJ.pending_delete_sessions){UI_WORKER_OBJ.pending_delete_sessions=new Set}if(!UI_WORKER_OBJ.pending_delete_elements_by_session){UI_WORKER_OBJ.pending_delete_elements_by_session={}}if(typeof UI_WORKER_OBJ.run_timer==="undefined"){UI_WORKER_OBJ.run_timer=null}if(typeof UI_WORKER_OBJ.run_in_progress==="undefined"){UI_WORKER_OBJ.run_in_progress=false}if(typeof UI_WORKER_OBJ.run_again==="undefined"){UI_WORKER_OBJ.run_again=false}if(typeof UI_WORKER_OBJ.run_schedule_type==="undefined"){UI_WORKER_OBJ.run_schedule_type=null}if(typeof UI_WORKER_OBJ.dom_jobs_per_frame==="undefined"){UI_WORKER_OBJ.dom_jobs_per_frame=8}if(!UI_WORKER_OBJ.job_lane_counts){UI_WORKER_OBJ.job_lane_counts={data:0,dom:0};(UI_WORKER_OBJ.jobs||[]).forEach(function(job){if(!job){return}const lane=job.lane||func.UI.worker.get_job_lane(job.functionP);UI_WORKER_OBJ.job_lane_counts[lane]=(UI_WORKER_OBJ.job_lane_counts[lane]||0)+1})}if(typeof UI_WORKER_OBJ.active_jobs_count==="undefined"){UI_WORKER_OBJ.active_jobs_count=0;for(let index=0;index<(UI_WORKER_OBJ.jobs||[]).length;index++){if(UI_WORKER_OBJ.jobs[index]){UI_WORKER_OBJ.active_jobs_count++}}}if(typeof UI_WORKER_OBJ.job_holes_count==="undefined"){UI_WORKER_OBJ.job_holes_count=Math.max(0,(UI_WORKER_OBJ.jobs||[]).length-UI_WORKER_OBJ.active_jobs_count)}if(typeof UI_WORKER_OBJ.first_active_job_index==="undefined"){UI_WORKER_OBJ.first_active_job_index=null;for(let index=0;index<(UI_WORKER_OBJ.jobs||[]).length;index++){if(UI_WORKER_OBJ.jobs[index]){UI_WORKER_OBJ.first_active_job_index=index;break}}}};func.UI.worker.get_job_lane=function(functionP){if(functionP==="update_datasource"){return"data"}return"dom"};func.UI.worker.register_job=function(job,index=UI_WORKER_OBJ.jobs.length-1){func.UI.worker.ensure_runtime_indexes();if(!job){return false}if(!job.lane){job.lane=func.UI.worker.get_job_lane(job.functionP)}UI_WORKER_OBJ.job_index_by_num[job.job_num]=index;if(job.queue_key){UI_WORKER_OBJ.jobs_by_queue_key[job.queue_key]=job}UI_WORKER_OBJ.job_lane_counts[job.lane]=(UI_WORKER_OBJ.job_lane_counts[job.lane]||0)+1;UI_WORKER_OBJ.active_jobs_count++;if(UI_WORKER_OBJ.first_active_job_index===null||index<UI_WORKER_OBJ.first_active_job_index){UI_WORKER_OBJ.first_active_job_index=index}return true};func.UI.worker.unregister_job=function(job){func.UI.worker.ensure_runtime_indexes();if(!job){return false}delete UI_WORKER_OBJ.job_index_by_num[job.job_num];if(job.queue_key&&UI_WORKER_OBJ.jobs_by_queue_key[job.queue_key]?.job_num===job.job_num){delete UI_WORKER_OBJ.jobs_by_queue_key[job.queue_key]}if(job.lane&&UI_WORKER_OBJ.job_lane_counts[job.lane]>0){UI_WORKER_OBJ.job_lane_counts[job.lane]--}if(UI_WORKER_OBJ.active_jobs_count>0){UI_WORKER_OBJ.active_jobs_count--}return true};func.UI.worker.advance_first_active_job_index=function(start_index=UI_WORKER_OBJ.first_active_job_index||0){func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.active_jobs_count){UI_WORKER_OBJ.first_active_job_index=null;return null}for(let index=Math.max(0,start_index);index<UI_WORKER_OBJ.jobs.length;index++){if(UI_WORKER_OBJ.jobs[index]){UI_WORKER_OBJ.first_active_job_index=index;return UI_WORKER_OBJ.jobs[index]}}UI_WORKER_OBJ.first_active_job_index=null;return null};func.UI.worker.compact_jobs=function(){func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.job_holes_count){return false}const compacted_jobs=[];UI_WORKER_OBJ.job_index_by_num={};UI_WORKER_OBJ.jobs_by_queue_key={};UI_WORKER_OBJ.job_lane_counts={data:0,dom:0};UI_WORKER_OBJ.job_holes_count=0;UI_WORKER_OBJ.first_active_job_index=null;for(let index=0;index<UI_WORKER_OBJ.jobs.length;index++){const job=UI_WORKER_OBJ.jobs[index];if(!job){continue}const compacted_index=compacted_jobs.length;compacted_jobs.push(job);UI_WORKER_OBJ.job_index_by_num[job.job_num]=compacted_index;if(job.queue_key){UI_WORKER_OBJ.jobs_by_queue_key[job.queue_key]=job}UI_WORKER_OBJ.job_lane_counts[job.lane]=(UI_WORKER_OBJ.job_lane_counts[job.lane]||0)+1;if(UI_WORKER_OBJ.first_active_job_index===null){UI_WORKER_OBJ.first_active_job_index=compacted_index}}UI_WORKER_OBJ.jobs=compacted_jobs;return true};func.UI.worker.maybe_compact_jobs=function(force=false){func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.job_holes_count){return false}const jobs_length=UI_WORKER_OBJ.jobs.length;const should_compact=force||UI_WORKER_OBJ.job_holes_count>=50||UI_WORKER_OBJ.job_holes_count>=Math.ceil(jobs_length/3)||UI_WORKER_OBJ.first_active_job_index!==null&&UI_WORKER_OBJ.first_active_job_index>0;if(!should_compact){return false}return func.UI.worker.compact_jobs()};func.UI.worker.get_first_active_job=function(){func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.active_jobs_count){UI_WORKER_OBJ.first_active_job_index=null;return null}if(UI_WORKER_OBJ.first_active_job_index!==null){const active_job=UI_WORKER_OBJ.jobs[UI_WORKER_OBJ.first_active_job_index];if(active_job){return active_job}}const job=func.UI.worker.advance_first_active_job_index(0);if(job){if(UI_WORKER_OBJ.first_active_job_index>0){func.UI.worker.maybe_compact_jobs(true)}return job}UI_WORKER_OBJ.active_jobs_count=0;UI_WORKER_OBJ.job_holes_count=UI_WORKER_OBJ.jobs.length;UI_WORKER_OBJ.first_active_job_index=null;func.UI.worker.maybe_compact_jobs(true);return null};func.UI.worker.get_pending_run_mode=function(){func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.active_jobs_count){return null}if(UI_WORKER_OBJ.job_lane_counts?.data>0){return"data"}return"dom"};func.UI.worker.cancel_pending_run=function(){func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.run_timer){return false}if(UI_WORKER_OBJ.run_schedule_type==="dom_frame"){if(typeof window!=="undefined"&&typeof window.cancelAnimationFrame==="function"){window.cancelAnimationFrame(UI_WORKER_OBJ.run_timer)}else if(typeof cancelAnimationFrame==="function"){cancelAnimationFrame(UI_WORKER_OBJ.run_timer)}else{clearTimeout(UI_WORKER_OBJ.run_timer)}}else{clearTimeout(UI_WORKER_OBJ.run_timer)}UI_WORKER_OBJ.run_timer=null;UI_WORKER_OBJ.run_schedule_type=null;return true};func.UI.worker.request_frame=function(callback){if(typeof window!=="undefined"&&typeof window.requestAnimationFrame==="function"){return window.requestAnimationFrame(callback)}if(typeof requestAnimationFrame==="function"){return requestAnimationFrame(callback)}return setTimeout(callback,16)};func.UI.worker.reindex_jobs_from=function(start_index=0){func.UI.worker.ensure_runtime_indexes();for(let index=Math.max(0,start_index);index<UI_WORKER_OBJ.jobs.length;index++){const job=UI_WORKER_OBJ.jobs[index];if(!job){continue}UI_WORKER_OBJ.job_index_by_num[job.job_num]=index;if(job.queue_key){UI_WORKER_OBJ.jobs_by_queue_key[job.queue_key]=job}}};func.UI.worker.get_session_root=function(SESSION_ID){if(func.runtime?.ui?.get_root_element){const $root=func.runtime.ui.get_root_element(SESSION_ID);if($root?.length){return $root}}return func.runtime.ui._wrap_matches([document.body])};func.UI.worker.get_session_runtime_elements=function(SESSION_ID){if(func.runtime?.ui?.get_refresh_indexed_runtime_elements){const $indexed=func.runtime.ui.get_refresh_indexed_runtime_elements(SESSION_ID);if($indexed?.length){return $indexed}}const $root=func.UI.worker.get_session_root(SESSION_ID);if(func.runtime?.ui?.get_refresh_index_elements){return func.runtime.ui.get_refresh_index_elements(SESSION_ID,$root)}var _rt_root_node=func.runtime.ui.get_first_node($root);var _rt_matches=[];if(_rt_root_node?.matches?.("[xu-ui-id]"))_rt_matches.push(_rt_root_node);_rt_root_node?.querySelectorAll?.("[xu-ui-id]")?.forEach(function(el){_rt_matches.push(el)});return func.runtime.ui._wrap_matches(_rt_matches)};func.UI.worker.mark_pending_delete_session=function(SESSION_ID){func.UI.worker.ensure_runtime_indexes();if(SESSION_ID){UI_WORKER_OBJ.pending_delete_sessions.add(SESSION_ID)}};func.UI.worker.mark_pending_delete_element=function(SESSION_ID,target){func.UI.worker.ensure_runtime_indexes();if(!SESSION_ID||!target){return false}if(!UI_WORKER_OBJ.pending_delete_elements_by_session[SESSION_ID]){UI_WORKER_OBJ.pending_delete_elements_by_session[SESSION_ID]=new Set}const elements=Array.isArray(target)?target:target?.length!==undefined?Array.from(target):[func.runtime.ui.get_first_node(target)].filter(Boolean);elements.forEach(function(element){UI_WORKER_OBJ.pending_delete_elements_by_session[SESSION_ID].add(element)});UI_WORKER_OBJ.pending_delete_sessions.add(SESSION_ID);return true};func.UI.worker.cleanup_pending_to_delete=function(SESSION_ID=Object.keys(SESSION_OBJ)[0]){func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.pending_delete_sessions.has(SESSION_ID)){return}const pending_elements=UI_WORKER_OBJ.pending_delete_elements_by_session[SESSION_ID];if(pending_elements?.size){pending_elements.forEach(function(element){const element_data=func.runtime.ui.get_data(element);if(element_data?.xuData?.pending_to_delete){element_data.xuData.pending_to_delete=false}});pending_elements.clear()}else{const runtime_elements=func.UI.worker.get_session_runtime_elements(SESSION_ID);for(let index=0;index<runtime_elements.length;index++){const val=runtime_elements[index];const element_data=func.runtime.ui.get_data(val);if(element_data?.xuData?.pending_to_delete){element_data.xuData.pending_to_delete=false}}}UI_WORKER_OBJ.pending_delete_sessions.delete(SESSION_ID)};func.UI.worker.init=async function(SESSION_ID){func.UI.worker.ensure_runtime_indexes();func.UI.utils.isInViewport=function(el){var node=func.runtime.ui.get_first_node(el);if(!node)return false;var rect=node.getBoundingClientRect();return rect.bottom>0&&rect.top<(window.innerHeight||document.documentElement.clientHeight)};if(typeof $!=="undefined"&&$.fn){$.fn.isInViewport=function(){return func.UI.utils.isInViewport(this[0])}}if(!UI_WORKER_OBJ.in_flight_job_elements){UI_WORKER_OBJ.in_flight_job_elements=[]}const contains_job_element=function($parent,$child){const parent_node=$parent?.[0];const child_node=$child?.[0];if(!parent_node||!child_node){return false}return parent_node.contains(child_node)};func.UI.worker.cancel_child_in_flight_jobs=function($parent_element){if(!$parent_element?.length||!UI_WORKER_OBJ.in_flight_job_elements.length)return;const parent_node=$parent_element[0];if(!parent_node)return;for(let i=UI_WORKER_OBJ.in_flight_job_elements.length-1;i>=0;i--){const child_el=UI_WORKER_OBJ.in_flight_job_elements[i];const child_node=child_el?.[0];if(child_node&&parent_node.contains(child_node)){UI_WORKER_OBJ.in_flight_job_elements.splice(i,1)}}};const overlaps_any_in_flight=function(job){if(!job?.elementP){return false}for(let index=0;index<UI_WORKER_OBJ.in_flight_job_elements.length;index++){const active_el=UI_WORKER_OBJ.in_flight_job_elements[index];if(!active_el)continue;if(contains_job_element(active_el,job.elementP)){return true}}return false};const job_iterator=async function(run_mode="data"){const mark_pending_delete_on_descendants=function($element){if(!$element?.length){return}const descendants=$element[0]?.querySelectorAll?.("[xu-ui-id]")||[];for(let index=0;index<descendants.length;index++){const val=descendants[index];const elm_data=func.runtime.ui.get_data(val);if(!elm_data?.xuData){continue}elm_data.xuData.pending_to_delete=true;func.UI.worker.mark_pending_delete_element(SESSION_ID,val)}};const dom_job_budget=run_mode==="dom"?UI_WORKER_OBJ.dom_jobs_per_frame:Number.POSITIVE_INFINITY;let dom_jobs_processed=0;const dispatched_jobs=[];if(UI_WORKER_OBJ.active_jobs_count){func.UI.worker.idle=0;for(let key=0;key<UI_WORKER_OBJ.jobs.length;key++){const val=UI_WORKER_OBJ.jobs[key];try{if(!val)continue;if(val.stat==="busy")continue;const job_lane=val.lane||func.UI.worker.get_job_lane(val.functionP);val.lane=job_lane;if(run_mode==="data"&&job_lane!=="data")continue;if(job_lane==="dom"&&dom_jobs_processed>=dom_job_budget)continue;if(overlaps_any_in_flight(val))continue;if(!val.elementP){const job_promise=func.UI.worker.execute(val.SESSION_ID,val).catch(function(err){console.error(err)});dispatched_jobs.push(job_promise);if(job_lane==="dom"){dom_jobs_processed++}continue}const active_xu_ui_id=func.runtime.ui.get_attr(val.elementP,"xu-ui-id");if(!active_xu_ui_id)continue;const running_job_obj=func.UI.worker.get_first_active_job();if(!running_job_obj){break}if(running_job_obj.job_num!==val.job_num){if(contains_job_element(running_job_obj.elementP,val.elementP)){continue}if(contains_job_element(val.elementP,running_job_obj.elementP)){continue}}const in_flight_entry=val.elementP;UI_WORKER_OBJ.in_flight_job_elements.push(in_flight_entry);const job_promise=func.UI.worker.execute(val.SESSION_ID,val).catch(function(err){console.error(err)}).finally(function(){const idx=UI_WORKER_OBJ.in_flight_job_elements.indexOf(in_flight_entry);if(idx!==-1){UI_WORKER_OBJ.in_flight_job_elements.splice(idx,1)}func.UI.worker.schedule_run(0)});dispatched_jobs.push(job_promise);if(job_lane==="dom"){dom_jobs_processed++}continue}catch(err){console.error(err)}}}};func.UI.worker.schedule_run=function(delay=0,preferred_mode){func.UI.worker.ensure_runtime_indexes();if(UI_WORKER_OBJ.run_in_progress){UI_WORKER_OBJ.run_again=true;return}const run_mode=preferred_mode||func.UI.worker.get_pending_run_mode()||"data";if(UI_WORKER_OBJ.run_timer){const should_promote_data=run_mode==="data"&&UI_WORKER_OBJ.run_schedule_type&&UI_WORKER_OBJ.run_schedule_type!=="data";if(!should_promote_data){return}func.UI.worker.cancel_pending_run()}const run_once=async function(){UI_WORKER_OBJ.run_timer=null;UI_WORKER_OBJ.run_schedule_type=null;UI_WORKER_OBJ.run_in_progress=true;try{await job_iterator(run_mode)}finally{UI_WORKER_OBJ.run_in_progress=false;func.UI.worker.maybe_compact_jobs();const next_run_mode=func.UI.worker.get_pending_run_mode();const should_continue=UI_WORKER_OBJ.run_again||!!next_run_mode;UI_WORKER_OBJ.run_again=false;if(should_continue){func.UI.worker.schedule_run(0,next_run_mode||undefined)}}};UI_WORKER_OBJ.run_schedule_type=run_mode;if(run_mode==="dom"){if(delay>0){UI_WORKER_OBJ.run_schedule_type="dom_delay";UI_WORKER_OBJ.run_timer=setTimeout(function(){UI_WORKER_OBJ.run_schedule_type="dom_frame";UI_WORKER_OBJ.run_timer=func.UI.worker.request_frame(run_once)},delay)}else{UI_WORKER_OBJ.run_schedule_type="dom_frame";UI_WORKER_OBJ.run_timer=func.UI.worker.request_frame(run_once)}}else{UI_WORKER_OBJ.run_schedule_type="data";UI_WORKER_OBJ.run_timer=setTimeout(run_once,delay)}this._interval=UI_WORKER_OBJ.run_timer};if(!UI_WORKER_OBJ.maintenance_intervals_initialized){UI_WORKER_OBJ.maintenance_intervals_initialized=true;setInterval(async function(){func.UI.ds_garbage_collector()},1e4);setInterval(async function(){func.UI.worker.cleanup_pending_to_delete();func.UI.refs_garbage_collector();func.UI.teleport_garbage_collector()},1e3)}};func.UI.worker.add_to_queue=async function(SESSION_ID,source,functionP,paramsP,calling_job,elementP,dsSession,calling_trigger_prop){func.UI.worker.ensure_runtime_indexes();var obj={SESSION_ID:SESSION_ID,source:source,functionP:functionP,paramsP:paramsP,calling_job:calling_job,elementP:elementP,dsSession:dsSession,calling_trigger_prop:calling_trigger_prop,job_num:UI_WORKER_OBJ.num};obj.lane=func.UI.worker.get_job_lane(functionP);const get_ui_id=function(target){return func.runtime?.ui?.get_attr?func.runtime.ui.get_attr(target,"xu-ui-id"):target?.attr?.("xu-ui-id")};const get_parent_ui_id=function(target){const parent_node=func.runtime.ui.get_first_node(target)?.parentElement;if(!parent_node){return""}return get_ui_id(parent_node)};const get_queue_key=function(){if(functionP==="update_datasource"){return source+"_"+functionP+"_"+(dsSession||"")+"_"+(paramsP?.currentRecordId||"")+"_"+(paramsP?.field_id||"")}if(functionP==="render_viewport"){return source+"_"+functionP+"_"+(get_ui_id(paramsP?.$div)||"")}if(functionP==="set_viewport_height"){return source+"_"+functionP+"_"+(get_parent_ui_id(paramsP?.$div)||"")}if(functionP==="execute_xu_all_attributes"){return source+"_"+functionP+"_"+(get_ui_id(elementP)||"")+"_"+(paramsP?.fields_arr?.toString()||"")}if(functionP==="execute_xu_render_attributes"){return source+"_"+functionP+"_"+(get_ui_id(elementP)||"")+"_"+(paramsP?.attr_value?.toString?.()||paramsP?.attr_value||"")+"_"+(paramsP?.fields_arr?.toString()||"")}if(functionP==="execute_xu_for"){return source+"_"+functionP+"_"+(get_ui_id(elementP)||"")+"_"+(paramsP?.xu_for_item_id||"")}if(functionP==="execute_xu_widget"){return source+"_"+functionP+"_"+(get_ui_id(elementP)||"")}return null};const queue_key=get_queue_key();if(queue_key){obj.queue_key=queue_key;let exist_job=UI_WORKER_OBJ.jobs_by_queue_key?.[queue_key];if(exist_job){func.runtime?.perf?.increment?.(SESSION_ID,"jobs_coalesced");func.runtime?.perf?.increment_map?.(SESSION_ID,"jobs_coalesced_by_function",functionP);exist_job.paramsP=paramsP;exist_job.calling_trigger_prop=calling_trigger_prop;exist_job.elementP=elementP;exist_job.dsSession=dsSession;exist_job.lane=obj.lane;return exist_job.job_num}}UI_WORKER_OBJ.jobs.push(obj);func.UI.worker.register_job(obj,UI_WORKER_OBJ.jobs.length-1);func.runtime?.perf?.increment?.(SESSION_ID,"jobs_queued");func.runtime?.perf?.increment_map?.(SESSION_ID,"jobs_queued_by_function",functionP);if(func.UI.worker.schedule_run){func.UI.worker.schedule_run(0,obj.lane==="data"?"data":undefined)}UI_WORKER_OBJ.num++;return UI_WORKER_OBJ.num-1};func.UI.worker.delete_job=async function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var job_index=func.UI.worker.find_job_index(SESSION_ID,jobNoP);if(job_index===null||typeof job_index==="undefined"||!UI_WORKER_OBJ.jobs[job_index]){return}const removed_job=UI_WORKER_OBJ.jobs[job_index];func.runtime?.perf?.increment?.(SESSION_ID,"jobs_completed");func.runtime?.perf?.increment_map?.(SESSION_ID,"jobs_completed_by_function",removed_job.functionP);var dsSession=removed_job.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?.loops_limit&&ds_obj?.loops_count<ds_obj?.loops_limit-1){return}func.UI.worker.unregister_job(removed_job);UI_WORKER_OBJ.jobs[job_index]=null;UI_WORKER_OBJ.job_holes_count++;if(UI_WORKER_OBJ.first_active_job_index===job_index){func.UI.worker.advance_first_active_job_index(job_index+1)}func.UI.worker.maybe_compact_jobs(job_index===0)};func.UI.worker.execute=async function(SESSION_ID,queue_obj){var job_index=func.UI.worker.find_job_index(SESSION_ID,queue_obj.job_num);if(queue_obj.jobNoP)UI_WORKER_OBJ.stat=job_index;if(UI_WORKER_OBJ.jobs[job_index]){UI_WORKER_OBJ.jobs[job_index].stat="busy"}func.runtime?.perf?.increment?.(SESSION_ID,"jobs_executed");func.runtime?.perf?.increment_map?.(SESSION_ID,"jobs_executed_by_function",queue_obj.functionP);const fx={get_element_by_ui_id:function(xu_ui_id){if(!xu_ui_id){return func.runtime.ui._wrap_matches([])}if(func.runtime?.ui?.get_refresh_indexed_element_by_ui_id){const _elm=func.runtime.ui.get_refresh_indexed_element_by_ui_id(SESSION_ID,xu_ui_id);return func.runtime.ui._wrap_matches(_elm?[_elm]:[])}const $root=func.UI.worker.get_session_root(SESSION_ID);if(func.runtime?.ui?.find_refresh_elements_by_attr){return func.runtime.ui.find_refresh_elements_by_attr($root,"xu-ui-id",xu_ui_id,true)}return func.runtime.ui.find_by_selector($root,`[xu-ui-id="${xu_ui_id}"]`)},get_live_element_context:function(elem_key,fallback_$elm,context={}){let raw_$elm=elem_key?fx.get_element_by_ui_id(elem_key):fallback_$elm;let $elm=func.runtime?.ui?.get_preferred_live_element?func.runtime.ui.get_preferred_live_element(raw_$elm):raw_$elm;const matches_context=function(node_xu_data,allow_loose_match=false){if(!node_xu_data){return false}if(context.node_id&&node_xu_data.nodeid!==context.node_id){return false}if(typeof context.key!=="undefined"&&context.key!==null&&node_xu_data.key!==context.key){return false}if(context.key_path&&node_xu_data.key_path!==context.key_path){return false}if(context.recordid&&node_xu_data.recordid!==context.recordid){return false}if(!allow_loose_match){if(context.prog_id&&node_xu_data.paramsP?.prog_id!==context.prog_id){return false}if(context.parent_element_ui_id&&node_xu_data.parent_element_ui_id!==context.parent_element_ui_id){return false}}if(node_xu_data.pending_to_delete){return false}return true};const resolved_node=func.runtime.ui.get_first_node($elm);const resolved_data=resolved_node?func.runtime.ui.get_data(resolved_node)?.xuData:null;const has_matching_resolved_node=matches_context(resolved_data);if(context.node_id&&!has_matching_resolved_node){const $root=func.UI.worker.get_session_root(SESSION_ID);const runtime_nodes=func.runtime?.ui?.get_refresh_index_elements?func.runtime.ui.get_refresh_index_elements(SESSION_ID,$root).toArray():Array.from(func.runtime.ui.get_first_node($root)?.querySelectorAll("[xu-ui-id]")||[]);let matching_nodes=[];for(let index=0;index<runtime_nodes.length;index++){const node=runtime_nodes[index];const node_data=func.runtime.ui.get_data(node);const node_xu_data=node_data?.xuData;if(!matches_context(node_xu_data)){continue}matching_nodes.push(node)}if(!matching_nodes.length){for(let index=0;index<runtime_nodes.length;index++){const node=runtime_nodes[index];const node_data=func.runtime.ui.get_data(node);const node_xu_data=node_data?.xuData;if(!matches_context(node_xu_data,true)){continue}matching_nodes.push(node)}}if(matching_nodes.length){raw_$elm=func.runtime.ui._wrap_matches(matching_nodes);$elm=func.runtime?.ui?.get_preferred_live_element?func.runtime.ui.get_preferred_live_element(raw_$elm):raw_$elm}}const _resolved_node=func.runtime.ui.get_first_node($elm);if(!_resolved_node){return{$elm:func.runtime.ui._wrap_matches([]),data:null}}if(!$elm?.length){$elm=func.runtime.ui._wrap_matches([_resolved_node])}const data=func.runtime.ui.get_data($elm);return{$elm:$elm,data:data}},get_child_node_by_id:function(xuData,node_id){if(!xuData?.node_org?.children?.length||!node_id){return null}if(func.runtime?.ui?.get_node_children_by_id){const children_by_id=func.runtime.ui.get_node_children_by_id(xuData.node_org);return children_by_id[node_id]||null}if(!xuData.node_org_children_by_id){xuData.node_org_children_by_id={};for(let index=0;index<xuData.node_org.children.length;index++){const child_node=xuData.node_org.children[index];if(child_node?.id){xuData.node_org_children_by_id[child_node.id]=child_node}}}return xuData.node_org_children_by_id[node_id]||null},get_refresh_execution_plan:function(live_data,refresh_attributes){const xuData=live_data?.xuData;if(!xuData){return[]}if(!xuData.refresh_execution_plan_cache){xuData.refresh_execution_plan_cache={}}const cache_key=(refresh_attributes||[]).join("|");if(xuData.refresh_execution_plan_cache[cache_key]){return xuData.refresh_execution_plan_cache[cache_key]}const skip_attributes={"xu-exp:xu-render":true,"xu-exp:xu-for":true,"xu-for":true,"xu-exp:xu-bind":true};const raw_value_attributes={"xu-bind":true,"xu-ref":true,"xu-on":true,"xu-for-key":true,"xu-for-val":true,"xu-click":true,"xu-change":true,"xu-blur":true,"xu-focus":true,"xu-init":true,"xu-attrs":true,"xu-cdn":true,"xu-style":true,"xu-style-global":true,"xu-script":true,"xu-viewport":true,"xu-ui-plugin":true};const execution_plan=[];for(let index=0;index<(refresh_attributes||[]).length;index++){const attr=refresh_attributes[index];if(!attr||skip_attributes[attr]){continue}const attr_new=attr.split("xu-exp:")[1];const xu_func=attr_new||attr;const is_raw_value_attribute=!!raw_value_attributes[attr]||attr.substr(0,6)==="xu-on:";execution_plan.push({attr:attr,attr_new:attr_new,xu_func:xu_func,is_regular_attribute:!!(attr_new&&attr_new.substr(0,2)!=="xu"),requires_expression:!is_raw_value_attribute&&attr!=="xu-class"&&attr!=="xu-ui-plugin",regular_attr_name:attr_new?attr_new!=="viewBox"?attr_new.toLowerCase():attr_new:null})}xuData.refresh_execution_plan_cache[cache_key]=execution_plan;return execution_plan},get_expression_cache_key:function(options){const iterate_info=options.iterate_info;const iterate_key=iterate_info?[iterate_info.iterator_key??"",iterate_info.iterator_val??"",iterate_info._key??"",iterate_info._val??""].join("::"):"";return[options.expression_text,options.dsSessionP,options.recordid,iterate_key].join("||")},get_expression_result:async function(cache,options){const cache_key=fx.get_expression_cache_key(options);if(Object.prototype.hasOwnProperty.call(cache,cache_key)){return cache[cache_key]}const result=await func.expression.get(options.SESSION_ID,options.expression_text,options.dsSessionP,"UI Property EXP",options.recordid,null,null,null,null,null,options.iterate_info);cache[cache_key]=result;return result},update_datasource:async function(currentRecordId){if(queue_obj?.paramsP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[queue_obj.dsSession];_ds.currentRecordId=currentRecordId||queue_obj.paramsP.currentRecordId;var datasource_changes={[_ds.dsSession]:{[_ds.currentRecordId]:"set"}};await func.datasource.update(SESSION_ID,datasource_changes);if(queue_obj.paramsP.field_id){datasource_changes={[_ds.dsSession]:{[_ds.currentRecordId]:{[queue_obj.paramsP.field_id]:queue_obj.paramsP.field_value}}};await func.datasource.update(SESSION_ID,datasource_changes)}}if(!currentRecordId)return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)},execute_xu_render_attributes:async function(){const perf_end=func.runtime?.perf?.start?.(SESSION_ID,"execute_xu_render_attributes");const live_context=fx.get_live_element_context(queue_obj.paramsP?.elem_key,queue_obj.elementP||queue_obj.paramsP?.elem_val?.$elm,queue_obj.paramsP);const _data=live_context.data;try{if(_data?.xuData?.paramsP){const live_xu_data=_data.xuData;await func.runtime.render.execute_xu_function({SESSION_ID:SESSION_ID,is_skeleton:null,$root_container:live_xu_data.$root_container,nodeP:live_xu_data.node,$container:fx.get_element_by_ui_id(live_xu_data.parent_element_ui_id)||live_xu_data.$container,paramsP:live_xu_data.paramsP,parent_infoP:live_xu_data.iterate_info?{iterate_info:live_xu_data.iterate_info}:{},jobNoP:queue_obj.jobNoP,keyP:live_xu_data.key,parent_nodeP:live_xu_data.parent_node,xu_func:"xu-render",$elm:live_context.$elm,$live_elm:live_context.$elm,val:{key:"xu-render",value:queue_obj.paramsP.attr_value,fields_arr:queue_obj.paramsP.fields_arr,jobNoP:queue_obj.jobNoP},get_params_obj_new:func.runtime.program.get_params_obj})}return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)}finally{perf_end?.()}},execute_xu_all_attributes:async function(){const perf_end=func.runtime?.perf?.start?.(SESSION_ID,"execute_xu_all_attributes");const done=function(){return func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)};try{const live_context=fx.get_live_element_context(queue_obj.paramsP?.elem_key,queue_obj.elementP||queue_obj.paramsP?.elem_val?.$elm,queue_obj.paramsP);const $elm=live_context.$elm;const live_data=live_context.data;const elm_node=$elm?.[0];if(!$elm.length||!live_data?.xuData||!live_data?.xuAttributes){return done()}const live_xu_data=live_data.xuData;const live_xu_attributes=live_data.xuAttributes;const refresh_attributes=queue_obj.paramsP?.elem_val?.attributes||[];const execution_plan=fx.get_refresh_execution_plan(live_data,refresh_attributes);const expression_results_cache={};const live_parent_container=fx.get_element_by_ui_id(live_xu_data.parent_element_ui_id);const xu_execution_context={SESSION_ID:SESSION_ID,is_skeleton:null,$root_container:live_xu_data.$root_container,nodeP:live_xu_data.node,$container:live_parent_container?.length?live_parent_container:live_xu_data.$container,paramsP:live_xu_data.paramsP,parent_infoP:live_xu_data.iterate_info?{iterate_info:live_xu_data.iterate_info}:{},jobNoP:queue_obj.jobNoP,keyP:live_xu_data.key,parent_nodeP:live_xu_data.parent_node,$elm:$elm,$live_elm:$elm,get_params_obj_new:func.runtime.program.get_params_obj};const handler_bundle=func.runtime.render.build_xu_handlers(xu_execution_context,SESSION_OBJ[SESSION_ID].DS_GLB[live_xu_data.paramsP.dsSessionP]);for(let index=0;index<execution_plan.length;index++){const plan=execution_plan[index];const attr=plan.attr;const attr_value=live_xu_attributes[attr];if(typeof attr_value==="undefined"){continue}let result=attr_value;if(plan.requires_expression){const expression_result=await fx.get_expression_result(expression_results_cache,{SESSION_ID:queue_obj.paramsP.SESSION_ID,expression_text:attr_value,dsSessionP:live_xu_data.paramsP.dsSessionP,recordid:live_xu_data.recordid,iterate_info:live_xu_data.iterate_info});result=expression_result.result}if(plan.is_regular_attribute){if(plan.regular_attr_name==="class"){func.runtime.render.apply_expression_class($elm,result)}else{func.runtime.ui.set_attr($elm,plan.regular_attr_name,result)}}else{try{await func.runtime.render.execute_xu_function({...xu_execution_context,xu_func:plan.xu_func,val:{key:plan.xu_func,value:result},handler_bundle:handler_bundle})}catch(error){debugger}}}return done()}finally{perf_end?.()}},execute_xu_for:async function(){const perf_end=func.runtime?.perf?.start?.(SESSION_ID,"execute_xu_for");try{const live_context=fx.get_live_element_context(queue_obj.paramsP?.elem_key,queue_obj.elementP||queue_obj?.paramsP?.elem_val?.$elm,queue_obj.paramsP);var $elm=live_context.$elm;if(!$elm?.length){return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)}const existing_children_map=new Set;if(func.runtime?.ui?.get_refresh_indexed_elements_by_node_id){const indexed_children=func.runtime.ui.get_refresh_indexed_elements_by_node_id(SESSION_ID,queue_obj?.paramsP?.xu_for_item_id).toArray();for(let index=0;index<indexed_children.length;index++){if(indexed_children[index].parentElement===func.runtime.ui.get_first_node($elm)){existing_children_map.add(indexed_children[index])}}}const children=func.runtime.ui.get_children($elm);for(let index=0;index<children.length;index++){const child=children[index];const child_data=func.runtime.ui.get_data(child);if(child_data?.xuData?.nodeid===queue_obj?.paramsP?.xu_for_item_id){existing_children_map.add(child)}}if(existing_children_map.size){func.runtime.ui.remove(func.runtime.ui._wrap_matches(Array.from(existing_children_map)))}let _data=live_context.data||func.runtime.ui.get_data($elm);const node_to_render=fx.get_child_node_by_id(_data?.xuData,queue_obj?.paramsP?.xu_for_item_id);await func.runtime.render.render_ui_tree(queue_obj.paramsP.SESSION_ID,$elm,node_to_render,null,_data.xuData.paramsP,queue_obj.jobNoP,null,_data.xuData.key,null,_data.xuData.parent_node,null,_data.xuData.$root_container)}catch(error){}finally{perf_end?.()}return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)},render_viewport:async function(){const{nodeP,$div,parent_infoP,$root_container,jobNoP,is_skeleton,paramsP,$container}=queue_obj?.paramsP||{};const _div_node=func.runtime.ui.get_first_node($div);if(nodeP?.children?.length&&!_div_node?.children?.length){await fx.update_datasource(func.runtime.ui.get_data($div)?.xuData?.currentRecordId);func.runtime.ui.remove_class($div,"skeleton");for(let index=0;index<nodeP.children.length;index++){await func.runtime.render.render_ui_tree(SESSION_ID,$div,nodeP.children[index],parent_infoP,paramsP,jobNoP,is_skeleton,index,null,nodeP,null,$root_container)}_div_node.style.removeProperty("height");func.runtime.ui.get_data($div).xuData.viewport_height=_div_node?.offsetHeight||0;const parent_id=func.runtime.ui.get_attr(_div_node?.parentElement,"xu-ui-id");func.UI.worker.ensure_runtime_indexes();if(!UI_WORKER_OBJ.viewport_height_set_ids_set.has(parent_id)){UI_WORKER_OBJ.viewport_height_set_ids_set.add(parent_id);UI_WORKER_OBJ.viewport_height_set_ids.push(parent_id);func.UI.worker.add_to_queue(SESSION_ID,"gui event","set_viewport_height",{$div:$div,height:func.runtime.ui.get_first_node($div)?.offsetHeight||0},null,null,paramsP.dsSessionP)}}return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)},set_viewport_height:async function(){const{$div,height}=queue_obj?.paramsP||{};const siblings=func.runtime.ui.get_first_node($div)?.parentElement?.children||[];for(let index=0;index<siblings.length;index++){const elm=siblings[index];if(!elm.style.height&&!elm.childElementCount){func.runtime.ui.set_style(elm,"height",`${height}px`)}}return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)},execute_xu_widget:async function(){try{const live_context=fx.get_live_element_context(queue_obj.paramsP?.elem_key,queue_obj.elementP||queue_obj?.paramsP?.elem_val?.$elm,queue_obj.paramsP);var $elm=live_context.$elm;if(!$elm?.length){return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)}const parent_id=func.runtime.ui.get_attr(func.runtime.ui.get_first_node($elm)?.parentElement,"xu-ui-id");let _data=live_context.data||func.runtime.ui.get_data($elm);func.runtime.ui.remove($elm);if(!_data?.xuData){return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)}const node_to_render=_data.xuData.node_org;await func.runtime.render.render_ui_tree(queue_obj.paramsP.SESSION_ID,fx.get_element_by_ui_id(parent_id),node_to_render,null,_data.xuData.paramsP,queue_obj.jobNoP,null,_data.xuData.key,null,_data.xuData.parent_node,null,_data.xuData.$root_container)}catch(error){}return await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)}};try{return await fx[queue_obj.functionP]()}catch(error){console.error(error);const failed_job_index=func.UI.worker.find_job_index(SESSION_ID,queue_obj.job_num);if(failed_job_index!==null&&typeof failed_job_index!=="undefined"&&UI_WORKER_OBJ.jobs[failed_job_index]){await func.UI.worker.delete_job(SESSION_ID,queue_obj.job_num)}return null}};func.UI.worker.find_job_index=function(SESSION_ID,jobNoP){var ret=null;if(!UI_WORKER_OBJ)return ret;func.UI.worker.ensure_runtime_indexes();if(Object.prototype.hasOwnProperty.call(UI_WORKER_OBJ.job_index_by_num,jobNoP)){const indexed_job=UI_WORKER_OBJ.job_index_by_num[jobNoP];if(UI_WORKER_OBJ.jobs[indexed_job]){return indexed_job}delete UI_WORKER_OBJ.job_index_by_num[jobNoP]}for(let key=0;key<UI_WORKER_OBJ.jobs.length;key++){const val=UI_WORKER_OBJ.jobs[key];if(val&&val.job_num==jobNoP){ret=key;UI_WORKER_OBJ.job_index_by_num[jobNoP]=ret;break}}return ret};func.UI.ds_garbage_collector=function(SESSION_ID=Object.keys(SESSION_OBJ)[0],re_check){let _session=SESSION_OBJ[SESSION_ID];const _data_system=_session?.DS_GLB?.[0]?.data_system;if(_data_system?.SYS_GLOBAL_BOL_AJAX_BUSY)return;if(!_data_system?.SYS_GLOBAL_BOL_IDLE)return;const ds_keys=Object.keys(_session.DS_GLB||{});let abort=false;for(let index=0;index<ds_keys.length;index++){const _ds=_session.DS_GLB[ds_keys[index]];if(_ds.stat==="busy"){abort=true;break}}if(abort){return}const ds_pending_to_delete=new Set;const active_ds_sessions=new Set;const runtime_elements=func.UI.worker.get_session_runtime_elements(SESSION_ID);for(let index=0;index<runtime_elements.length;index++){const val=runtime_elements[index];const dsSessionP=func.runtime.ui.get_data(val)?.xuData?.paramsP?.dsSessionP;if(typeof dsSessionP==="undefined"||dsSessionP===null)continue;active_ds_sessions.add(dsSessionP.toString())}for(let index=0;index<ds_keys.length;index++){const dsP=ds_keys[index];const _ds=_session.DS_GLB[dsP];if(!_ds.screen_params)continue;if(!active_ds_sessions.has(dsP.toString())){ds_pending_to_delete.add(dsP.toString())}}const sortedKeys=ds_keys.slice().sort((a,b)=>b.localeCompare(a));for(let index=0;index<sortedKeys.length;index++){const key=sortedKeys[index];const val=_session.DS_GLB[key];const parent_ds=typeof val.parentDataSourceNo!=="undefined"?val.parentDataSourceNo.toString():null;if(!ds_pending_to_delete.has(key)&&parent_ds&&ds_pending_to_delete.has(parent_ds)){ds_pending_to_delete.delete(parent_ds)}}for(const val of ds_pending_to_delete){func.datasource.del(SESSION_ID,val)}};func.UI.refs_garbage_collector=function(SESSION_ID=Object.keys(SESSION_OBJ)[0]){if(!xu_isEmpty(SCREEN_BLOCKER_OBJ)){return}let _session=SESSION_OBJ[SESSION_ID];const _data_system=_session?.DS_GLB?.[0]?.data_system;const refs_obj=_data_system?.SYS_GLOBAL_OBJ_REFS||{};const ref_keys=Object.keys(refs_obj);for(let ref_index=0;ref_index<ref_keys.length;ref_index++){const key=ref_keys[ref_index];const val=refs_obj[key];const $root=func.UI.worker.get_session_root(SESSION_ID);const _raw_el=func.runtime?.ui?.get_refresh_indexed_element_by_ui_id?func.runtime.ui.get_refresh_indexed_element_by_ui_id(SESSION_ID,val.xu_ui_id):null;const $element=_raw_el?func.runtime.ui._wrap_matches([_raw_el]):func.runtime?.ui?.find_refresh_elements_by_attr?func.runtime.ui.find_refresh_elements_by_attr($root,"xu-ui-id",val.xu_ui_id,true):func.runtime.ui.find_by_selector($root,`[xu-ui-id='${val.xu_ui_id}']`);const $panel_wrapper=func.runtime?.ui?.find_panel_wrapper_in_root?func.runtime.ui.find_panel_wrapper_in_root(SESSION_ID,val.xu_ui_id):func.runtime?.ui?.find_refresh_elements_by_attr?func.runtime.ui.find_refresh_elements_by_attr($root,"xu-panel-wrapper-id",val.xu_ui_id,true):func.runtime.ui.find_by_selector($root,`[xu-panel-wrapper-id='${val.xu_ui_id}']`);if(!$element?.length&&!$panel_wrapper?.length){delete _data_system.SYS_GLOBAL_OBJ_REFS[key]}}};func.UI.teleport_garbage_collector=function(SESSION_ID=Object.keys(SESSION_OBJ)[0]){if(!xu_isEmpty(SCREEN_BLOCKER_OBJ)){return}const $root=func.UI.worker.get_session_root(SESSION_ID);const teleport_elements=$root[0]?.querySelectorAll?.(`[xu-teleport-parent-id^='node-']`)||[];for(let index=0;index<teleport_elements.length;index++){const val=teleport_elements[index];const xu_teleport_parent_id=val.getAttribute("xu-teleport-parent-id");const _raw_parent=func.runtime?.ui?.get_refresh_indexed_element_by_ui_id?func.runtime.ui.get_refresh_indexed_element_by_ui_id(SESSION_ID,xu_teleport_parent_id):null;const $parent=_raw_parent?func.runtime.ui._wrap_matches([_raw_parent]):func.runtime?.ui?.find_refresh_elements_by_attr?func.runtime.ui.find_refresh_elements_by_attr($root,"xu-ui-id",xu_teleport_parent_id,true):func.runtime.ui.find_by_selector($root,`[xu-ui-id='${xu_teleport_parent_id}']`);if(!$parent?.length){func.runtime.ui.remove(val)}}};func.UI.utils.prog_ui_attribute_index_cache=func.UI.utils.prog_ui_attribute_index_cache||new WeakMap;func.UI.utils.get_prog_ui_attribute_index=function(progUi,prop,tag_name){if(!Array.isArray(progUi)||!prop){return{}}let prog_cache=func.UI.utils.prog_ui_attribute_index_cache.get(progUi);if(!prog_cache){prog_cache={};func.UI.utils.prog_ui_attribute_index_cache.set(progUi,prog_cache)}const cache_key=`${prop||""}::${tag_name||""}`;if(prog_cache[cache_key]){return prog_cache[cache_key]}const index={};const add_field=function(field_ref,item){if(!field_ref){return}if(!index[field_ref]){index[field_ref]=[]}index[field_ref].push(item)};const iterate_progUi=function(node){for(let item of node){if((!tag_name||item.tagName===tag_name)&&!xu_isEmpty(item.attributes)){const attribute_keys=Object.keys(item.attributes);for(let attr_index=0;attr_index<attribute_keys.length;attr_index++){const attr=attribute_keys[attr_index];const val=item.attributes[attr];if(attr!==`xu-exp:${prop}`&&attr!==prop){continue}const attr_str=typeof val==="string"?val:JSON.stringify(val);if(!attr_str){continue}for(const match of attr_str.matchAll(/@([A-Za-z0-9_$.-]+)/g)){add_field(match[1],item)}}}if(item.children){iterate_progUi(item.children)}}};iterate_progUi(progUi);prog_cache[cache_key]=index;return index};func.UI.find_field_in_progUi_attributes=function(progUi,field_id,prop,tag_name){if(prop){const index=func.UI.utils.get_prog_ui_attribute_index(progUi,prop,tag_name);return index[field_id]||[]}let elm_nodes=[];const iterate_progUi=function(node){for(let item of node){if(!tag_name||item.tagName===tag_name){if(tag_name){elm_nodes.push(item)}}if(item.children){iterate_progUi(item.children)}}};iterate_progUi(progUi);return elm_nodes};func.UI.update_xu_ref=function(SESSION_ID,dsSessionP,ref_field_id,$elm){let ret;const _session=SESSION_OBJ[SESSION_ID];let _ds_0=_session.DS_GLB[0];const _ds=func.utils.clean_returned_datasource(SESSION_ID,dsSessionP);let obj={ds:_ds,data:{},props:_ds.in_parameters||{}};try{const row_idx=func.common.find_ROWID_idx(_ds,_ds.currentRecordId);obj.data=_ds?.data_feed?.rows?.[row_idx]}catch(error){}let SYS_GLOBAL_OBJ_REFS=_ds_0.data_system["SYS_GLOBAL_OBJ_REFS"];if($elm){const elm_data=func.runtime.ui.get_data($elm);const attributes=elm_data?.xuData?.xuPanelProps||elm_data?.xuData?.debug_info?.attribute_stat||{};obj.attributes=attributes;obj.xu_ui_id=func.runtime.ui.get_attr($elm,"xu-ui-id")}if(!xu_isEqual(SYS_GLOBAL_OBJ_REFS?.[ref_field_id]||{},obj)){if(!SYS_GLOBAL_OBJ_REFS[ref_field_id]){SYS_GLOBAL_OBJ_REFS[ref_field_id]={}}function deepUpdateObject(a,b){for(let key in b){if(b.hasOwnProperty(key)){if(typeof b[key]==="object"&&b[key]!==null&&!Array.isArray(b[key])&&a[key]&&typeof a[key]==="object"){deepUpdateObject(a[key],b[key])}else{if(!xu_isEqual(a[key],b[key])){a[key]=b[key]}}}}return a}deepUpdateObject(SYS_GLOBAL_OBJ_REFS[ref_field_id],obj);ret=true}return ret};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.perf=func.runtime.perf||{};func.runtime.perf.global_stats=func.runtime.perf.global_stats||{sessions:{}};func.runtime.perf.get_host=function(){if(typeof window!=="undefined"){return window}if(typeof globalThis!=="undefined"){return globalThis}return{}};func.runtime.perf.sync_global_ref=function(){const host=func.runtime.perf.get_host();host.XUDA_RUNTIME_STATS=func.runtime.perf.global_stats;return host.XUDA_RUNTIME_STATS};func.runtime.perf.is_enabled=function(){const host=func.runtime.perf.get_host();const debug_mode=typeof glb!=="undefined"&&!!glb.DEBUG_MODE;return!!(debug_mode||host.XUDA_RUNTIME_STATS_ENABLED)};func.runtime.perf.now=function(){if(typeof performance!=="undefined"&&typeof performance.now==="function"){return performance.now()}return Date.now()};func.runtime.perf.ensure_session_stats=function(SESSION_ID){const global_stats=func.runtime.perf.global_stats;if(!global_stats.sessions[SESSION_ID]){global_stats.sessions[SESSION_ID]={created_at:Date.now(),counters:{},durations:{},maps:{}}}if(SESSION_OBJ?.[SESSION_ID]){SESSION_OBJ[SESSION_ID].runtime_stats=global_stats.sessions[SESSION_ID]}func.runtime.perf.sync_global_ref();return global_stats.sessions[SESSION_ID]};func.runtime.perf.reset_session=function(SESSION_ID){if(!SESSION_ID){return false}delete func.runtime.perf.global_stats.sessions[SESSION_ID];if(SESSION_OBJ?.[SESSION_ID]){delete SESSION_OBJ[SESSION_ID].runtime_stats}func.runtime.perf.sync_global_ref();return true};func.runtime.perf.reset=function(){func.runtime.perf.global_stats={sessions:{}};const session_ids=Object.keys(SESSION_OBJ||{});for(let index=0;index<session_ids.length;index++){delete SESSION_OBJ[session_ids[index]].runtime_stats}func.runtime.perf.sync_global_ref();return func.runtime.perf.global_stats};func.runtime.perf.get_session_stats=function(SESSION_ID){if(!SESSION_ID){return null}return func.runtime.perf.global_stats.sessions[SESSION_ID]||null};func.runtime.perf.increment=function(SESSION_ID,key,amount=1){if(!func.runtime.perf.is_enabled()){return 0}const stats=func.runtime.perf.ensure_session_stats(SESSION_ID);stats.counters[key]=(stats.counters[key]||0)+amount;return stats.counters[key]};func.runtime.perf.increment_map=function(SESSION_ID,bucket,key,amount=1){if(!func.runtime.perf.is_enabled()||typeof key==="undefined"||key===null){return 0}const stats=func.runtime.perf.ensure_session_stats(SESSION_ID);if(!stats.maps[bucket]){stats.maps[bucket]={}}const map_key=key.toString();stats.maps[bucket][map_key]=(stats.maps[bucket][map_key]||0)+amount;return stats.maps[bucket][map_key]};func.runtime.perf.record_duration=function(SESSION_ID,key,duration_ms){if(!func.runtime.perf.is_enabled()){return null}const stats=func.runtime.perf.ensure_session_stats(SESSION_ID);if(!stats.durations[key]){stats.durations[key]={count:0,total_ms:0,max_ms:0,last_ms:0,avg_ms:0}}const metric=stats.durations[key];metric.count++;metric.total_ms+=duration_ms;metric.last_ms=duration_ms;metric.max_ms=Math.max(metric.max_ms,duration_ms);metric.avg_ms=metric.total_ms/metric.count;return metric};func.runtime.perf.start=function(SESSION_ID,key){if(!func.runtime.perf.is_enabled()){return null}const started_at=func.runtime.perf.now();return function(){return func.runtime.perf.record_duration(SESSION_ID,key,func.runtime.perf.now()-started_at)}};func.runtime.ui.init_screen=async function(options){const{SESSION_ID,prog_id,sourceScreenP,callingDataSource_objP,$callingContainerP,triggerIdP,rowIdP,jobNoP,is_panelP,parameters_obj_inP,source_functionP,call_screen_propertiesP,refreshed_ds,parameters_raw_obj}=options;if(!prog_id)return console.error("program is empty");const screen_ret=await func.utils.get_screen_obj(SESSION_ID,prog_id);if(!screen_ret)return console.error("program is not a screen object");await func.UI.utils.init_ui_framework(SESSION_ID,prog_id);const _session=SESSION_OBJ[SESSION_ID];const screenInfo=structuredClone(screen_ret);const ssr_payload=func.runtime.render.should_use_ssr_payload(SESSION_ID,{prog_id:prog_id})?func.runtime.render.get_ssr_payload(_session):null;const screen_type=source_functionP?.split("_")?.[1];const screenId=ssr_payload?.screenId||(glb.screen_num++).toString();if(SCREEN_BLOCKER_OBJ[prog_id+(sourceScreenP?"_"+sourceScreenP:"")]){const wait_for_SCREEN_BLOCKER_release=function(){return new Promise(resolve=>{const interval=setInterval(function(){if(!SCREEN_BLOCKER_OBJ[prog_id+(sourceScreenP?"_"+sourceScreenP:"")]){clearInterval(interval);resolve()}},5)})};await wait_for_SCREEN_BLOCKER_release()}func.UI.utils.screen_blocker(true,prog_id+(sourceScreenP?"_"+sourceScreenP:""));if($callingContainerP&&!xu_isEmpty($callingContainerP)){const calling_data=func.runtime.ui.get_data($callingContainerP);if(calling_data?.xuData)calling_data.xuData.screenInfo=screenInfo}let $dialogDiv;let $rootFrame;const params={prog_id:prog_id,sourceScreenP:sourceScreenP,$callingContainerP:$callingContainerP,triggerIdP:triggerIdP,callingDataSource_objP:callingDataSource_objP,rowIdP:rowIdP,renderType:screenInfo.properties?.renderType,parameters_obj_inP:parameters_obj_inP,source_functionP:source_functionP,is_panelP:is_panelP,screen_type:screen_type,screenInfo:screenInfo,call_screen_propertiesP:call_screen_propertiesP,parentDataSourceNoP:_session.DS_GLB?.[callingDataSource_objP?.dsSession]?.dsSession||callingDataSource_objP?.parentDataSourceNo||0,parameters_raw_obj:parameters_raw_obj,containerIdP:ssr_payload?.containerId||null,ssr_payload:ssr_payload};const screen_host=func.runtime.ui.create_screen_host(SESSION_ID,screen_type,params,$callingContainerP,screenId);$dialogDiv=screen_host.$dialogDiv;$rootFrame=screen_host.$rootFrame;params.containerIdP=func.runtime.ui.get_attr($rootFrame,"id");params.$container=$rootFrame;const containerId="container_"+params.screenInfo.properties?.id+"_"+screenId;const data={note:" ROOT container",root:true,screenId:screenId,is_panelP:is_panelP,prog_id:prog_id,screen_type:screen_type,container:"#"+containerId};if(is_panelP){func.runtime.ui.get_data($rootFrame).xuData.rootFrame=data}else{const rf_data=func.runtime.ui.get_data($rootFrame);if(!rf_data?.xuData){func.runtime.ui.set_data($rootFrame,"xuData",{})}func.runtime.ui.set_attr($rootFrame,"id",containerId);func.runtime.ui.get_data($rootFrame).xuData.rootFrame=data;func.runtime.ui.set_style($rootFrame,"display","contents")}if(screen_host.reused_ssr_host&&func.runtime.render.is_takeover_mode(_session)){func.runtime.ui.empty($rootFrame)}if(!is_panelP)func.UI.utils.indicator.screen.busy();const ret=await func.datasource.create(SESSION_ID,prog_id,refreshed_ds,params.parentDataSourceNoP,func.runtime.ui.get_attr($rootFrame,"id"),rowIdP,jobNoP,null,parameters_raw_obj,null,null,null,null,is_panelP,parameters_obj_inP);const _ds=SESSION_OBJ[SESSION_ID].DS_GLB[ret.dsSessionP];_ds.screen_params=params;params.dsSessionP=ret.dsSessionP;func.runtime.ui.update_sys_obj_win_info(SESSION_ID,params.dsSessionP);if(ret.dsSessionP<0){return}let viewDoc;const view_ret=await func.utils.VIEWS_OBJ.get(SESSION_ID,SESSION_OBJ[SESSION_ID].DS_GLB[ret.dsSessionP].prog_id);if(view_ret){viewDoc=view_ret}if(!viewDoc?.progUi){return func.utils.alerts.invoke(SESSION_ID,"system_msg","SYS_MSG_0780",params.renderType,ret.dsSessionP)}let node=structuredClone(viewDoc.progUi);if(!node.length)return console.warn("ui node empty");const root_tree=await func.runtime.render.build_tree({SESSION_ID:SESSION_ID,nodeP:node[0],paramsP:params});const ret_render_$container=await func.runtime.render.render_tree(root_tree,{SESSION_ID:SESSION_ID,$container:$rootFrame,parent_infoP:null,paramsP:params,jobNoP:jobNoP,is_skeleton:null,keyP:null,refreshed_ds:null,parent_nodeP:null,check_existP:null,$root_container:$rootFrame});if(!is_panelP)func.UI.utils.indicator.screen.normal();return await func.runtime.ui.screen_loading_done({SESSION_ID:SESSION_ID,paramsP:params,$div:ret_render_$container,jobNoP:jobNoP})};func.runtime.ui.update_sys_obj_win_info=function(SESSION_ID,dsNoP){const _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsNoP];if(!_ds)return;if(!_ds.data_system){_ds.data_system={}}_ds.data_system["SYS_STR_WIN_ID"]=_ds.tree_obj?.id;_ds.data_system["SYS_STR_WIN_NAME"]=_ds.tree_obj?.menuName;if(SESSION_OBJ[SESSION_ID].DS_GLB[dsNoP].mode){_ds.data_system["SYS_STR_WIN_MODE"]=SESSION_OBJ[SESSION_ID].DS_GLB[dsNoP].mode}};func.runtime.ui.validate_exit_events=async function(SESSION_ID,div_data_paramsP,forceP){return new Promise(async resolve=>{await func.events.validate(SESSION_ID,"on_exit",div_data_paramsP.dsSessionP,null,"screen");const interval=setInterval(function(){if(!SESSION_OBJ[SESSION_ID].WORKER_OBJ.jobs.length||forceP){clearInterval(interval);resolve()}},5)})};func.runtime.ui.call_embed=function(SESSION_ID,prog){const $embed=func.runtime.ui.get_embed_container(SESSION_ID);func.runtime.ui.empty($embed);const embed_data=func.runtime.ui.get_data($embed);if(embed_data?.xuData){embed_data.xuData.screenInfo=null}for(const[key,val]of Object.entries(SESSION_OBJ[SESSION_ID].DS_GLB)){if(key)func.datasource.del(SESSION_ID,key)}func.UI.main.embed_prog_execute(SESSION_ID,prog)};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.ui.ensure_modal_controller=function(SESSION_ID,modal_id){var modal_controller=document.querySelector("xu-modal-controller");if(!modal_controller){func.UI.component.create_app_modal_component(SESSION_ID,modal_id);modal_controller=document.querySelector("xu-modal-controller")}return modal_controller};func.runtime.ui.get_controller_params=function(controller_element){return func.runtime.ui.get_data(controller_element,"xuControllerParams")||{}};func.runtime.ui.set_controller_params=function(controller_element,params){func.runtime.ui.set_data(controller_element,"xuControllerParams",params);return params};func.runtime.ui.get_nav=function(SESSION_ID){return func.runtime.ui.find_in_root(SESSION_ID,"xu-nav")};func.runtime.ui.ensure_nav=function(SESSION_ID,$container){let nav=func.runtime.ui.get_nav(SESSION_ID);if(nav&&nav.length){return nav}var nav_el=document.createElement("xu-nav");func.runtime.ui.append($container,nav_el);var $nav=func.runtime.ui._wrap_matches([nav_el]);func.UI.component.init_xu_nav($container,$nav);return $nav};func.runtime.ui.get_page_component_name=function(dsSessionP){return"xu-page-component-"+dsSessionP};func.runtime.ui.resolve_screen_property=async function(SESSION_ID,paramsP,property){var property_value=paramsP?.screenInfo?.properties?.[property]||paramsP?.screenInfo?.properties?.frameworkProperties?.[property];if(paramsP?.call_screen_propertiesP){if(paramsP.call_screen_propertiesP?.[property]){property_value=paramsP.call_screen_propertiesP[property]}if(paramsP.call_screen_propertiesP[`xu-exp:${property}`]){property_value=(await func.expression.get(SESSION_ID,paramsP.call_screen_propertiesP[`xu-exp:${property}`],paramsP.dsSessionP,property)).result}}return property_value};func.runtime.ui.apply_framework_properties=async function(SESSION_ID,paramsP,ui_framework,params){params.properties={};params.properties["name"]=await func.runtime.ui.resolve_screen_property(SESSION_ID,paramsP,"menuTitle");const properties=await ui_framework?.properties?.();if(!properties){return params.properties}for await(const[key,val]of Object.entries(properties)){params.properties[key]=await func.runtime.ui.resolve_screen_property(SESSION_ID,paramsP,key)}return params.properties};func.runtime.ui.build_modal_params=function(paramsP,$div,$container,close_callback){return{screenId:paramsP.screenId,$dialogDiv:func.runtime.ui.get_children($div),$container:$container,dsSession:paramsP.dsSessionP,modal_id:"app_modal-"+paramsP.dsSessionP.toString(),screenInfo:paramsP.screenInfo,close_callback:close_callback,paramsP:paramsP}};func.runtime.ui.set_modal_params=function(SESSION_ID,modal_id,params){var xu_modal_controller=func.runtime.ui.ensure_modal_controller(SESSION_ID,modal_id);var controller_params=func.runtime.ui.get_controller_params(xu_modal_controller);controller_params[modal_id]=params;func.runtime.ui.set_controller_params(xu_modal_controller,controller_params);return xu_modal_controller};func.runtime.ui.get_modal_params=function(SESSION_ID,modal_id){const xu_modal_controller=func.runtime.ui.ensure_modal_controller(SESSION_ID,modal_id);return func.runtime.ui.get_controller_params(xu_modal_controller)[modal_id]};func.runtime.ui.set_modal_instance=function(modal_id,modal){APP_MODAL_OBJ[modal_id]=modal;return modal};func.runtime.ui.has_modal_instance=function(modal_id){return!!APP_MODAL_OBJ[modal_id]};func.runtime.ui.delete_modal_instance=function(modal_id){delete APP_MODAL_OBJ[modal_id];return true};func.runtime.ui.close_all_modals=function(){for(const[key,val]of Object.entries(APP_MODAL_OBJ)){if(val){UI_FRAMEWORK_PLUGIN.modal.close(key)}}return true};func.runtime.ui.build_popover_params=function(paramsP,$div,$container){return{menuTitle:paramsP.screenInfo.properties?.menuTitle,screenId:paramsP.screenId,$dialogDiv:func.runtime.ui.get_children($div),$container:$container}};func.runtime.ui.build_page_params=function(SESSION_ID,paramsP,$div_content,$container,nav){return{div:$div_content,name:paramsP.screenInfo.properties?.menuTitle,screenId:paramsP.screenId,$container:$container,dsSession:paramsP.dsSessionP,SESSION_ID:SESSION_ID,nav:nav,paramsP:paramsP}};func.runtime.ui.get_nav_data=function($nav){return func.runtime.ui.get_data($nav)?.xuData||null};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.ensure_nav_params_registry=function($nav){const nav_data=func.runtime.ui.get_nav_data($nav);if(!nav_data){return null}if(!nav_data.nav_params){nav_data.nav_params={}}return nav_data.nav_params};func.runtime.ui.restore_page_validate_state=function($nav,dsSessionP,$container){const nav_data=func.runtime.ui.get_nav_data($nav);const existing_params=nav_data?.params?.[dsSessionP];if(func.runtime.ui.get_data(existing_params?.$container)?.xuData?.validate_screen_ready){func.runtime.ui.get_data($container).xuData.validate_screen_ready=func.runtime.ui.get_data(existing_params.$container).xuData.validate_screen_ready;return true}return false};func.runtime.ui.register_page_params=function($nav,dsSessionP,params){const nav_params=func.runtime.ui.ensure_nav_params_registry($nav);if(!nav_params){return false}nav_params[dsSessionP]=params;return true};func.runtime.ui.get_root_component_name=function(SESSION_ID){return"xu-root-component-"+SESSION_ID};func.runtime.ui.attach_nav_root_div=function($nav,$div_content){const nav_data=func.runtime.ui.get_nav_data($nav);if(!nav_data){return false}nav_data.$div=$div_content;return true};func.runtime.ui.set_nav_root=async function($nav,SESSION_ID){const nav_element=func.runtime.ui.get_first_node($nav);if(!nav_element?.setRoot){return false}await nav_element.setRoot(func.runtime.ui.get_root_component_name(SESSION_ID));return true};func.runtime.ui.release_screen_blocker=function(paramsP){func.UI.utils.screen_blocker(false,paramsP.prog_id+"_"+paramsP.sourceScreenP);return true};func.runtime.ui.close_modal_session=async function(SESSION_ID,modal_id){func.runtime.ui.delete_modal_instance(modal_id);const params=func.runtime.ui.get_modal_params(SESSION_ID,modal_id);if(params&&params.$container){await func.runtime.ui.validate_exit_events(SESSION_ID,func.runtime.ui.get_data(params.$container)?.xuData?.paramsP,null);func.datasource.clean_all(SESSION_ID,params.dsSession)}return true};func.runtime.ui.render_screen_type=async function(options){const $div_content=func.runtime.ui.get_children(options.$div);func.runtime.ui.sync_child_parent_container(options.$div);const assert_framework_screen_supported=function(screen_type){if(!func.runtime.session.is_slim(options.SESSION_ID)){return}throw new Error('Slim mode does not support "'+screen_type+'" screens without a UI framework plugin')};let $ret=options.$div;let $nav=func.runtime.ui.get_nav(options.SESSION_ID);let params;switch(options.paramsP.screen_type){case"modal":{assert_framework_screen_supported("modal");params=func.runtime.ui.build_modal_params(options.paramsP,options.$div,options.$container,options.close_modal);const modal_id=params.modal_id;func.runtime.ui.set_modal_params(options.SESSION_ID,modal_id,params);const modalController=await new UI_FRAMEWORK_PLUGIN.modal;await func.runtime.ui.apply_framework_properties(options.SESSION_ID,options.paramsP,modalController,params);if(!func.runtime.ui.has_modal_instance(modal_id)){const modal=await modalController.create(params);func.runtime.ui.set_modal_instance(modal_id,modal)}else{func.runtime.ui.empty(document.querySelector(modal_id))}await modalController.init(params);break}case"popover":{assert_framework_screen_supported("popover");const xu_popover_controller=func.UI.component.create_app_popover_component(options.SESSION_ID);params=func.runtime.ui.build_popover_params(options.paramsP,options.$div,options.$container);func.runtime.ui.set_data(xu_popover_controller,"xuControllerParams",params);const popover=new UI_FRAMEWORK_PLUGIN.popover(options.SESSION_ID);await func.runtime.ui.apply_framework_properties(options.SESSION_ID,options.paramsP,popover,params);await popover.open(params);CURRENT_APP_POPOVER=popover;func.runtime.ui.release_screen_blocker(options.paramsP);break}case"page":{assert_framework_screen_supported("page");const nav=func.runtime.ui.get_first_node($nav);params=func.runtime.ui.build_page_params(options.SESSION_ID,options.paramsP,$div_content,options.$container,nav);const component_name=func.runtime.ui.get_page_component_name(options.paramsP.dsSessionP);func.runtime.ui.ensure_nav_params_registry($nav);func.runtime.ui.restore_page_validate_state($nav,options.paramsP.dsSessionP,params.$container);if(!func.runtime.ui.get_nav_data($nav))return;func.runtime.ui.register_page_params($nav,options.paramsP.dsSessionP,params);if(!document.querySelector(component_name)){await func.UI.component.create_app_page_component(options.SESSION_ID,options.paramsP.dsSessionP);const page=new UI_FRAMEWORK_PLUGIN.page;await func.runtime.ui.apply_framework_properties(options.SESSION_ID,options.paramsP,page,params);await page.create(params);await page.init(params);nav.push(component_name,{params:params})}else{debugger;func.runtime.ui.empty(component_name);await UI_FRAMEWORK_PLUGIN.page(options.SESSION_ID,options.paramsP.dsSessionP)}func.runtime.ui.get_data(options.$div).xuData.paramsP=func.runtime.ui.get_data(options.$container).xuData.paramsP;break}case"panel":func.runtime.ui.append(options.$container,$div_content);$ret=options.$container;break;default:$nav=func.runtime.ui.ensure_nav(options.SESSION_ID,options.$container);func.runtime.ui.attach_nav_root_div($nav,$div_content);await func.runtime.ui.set_nav_root($nav,options.SESSION_ID);$ret=options.$container;break}return $ret};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.ensure_container_attributes=async function(options){const container_data=func.runtime.ui.get_data(options.$container);if(!xu_isEmpty(container_data?.xuAttributes)){return options.$container}await func.runtime.render.set_attributes_new({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$elm:options.$container,is_init:true});return options.$container};func.runtime.ui.copy_runtime_state=function($source,$target){const source_data=func.runtime.ui.get_data($source);const target_data=func.runtime.ui.get_data($target);if(!source_data?.xuData||!target_data?.xuData||!source_data?.xuAttributes||!target_data?.xuAttributes){return $target}const xu_data_keys=Object.keys(source_data.xuData);for(let index=0;index<xu_data_keys.length;index++){const key=xu_data_keys[index];const val=source_data.xuData[key];try{target_data.xuData[key]=structuredClone(val)}catch(_){target_data.xuData[key]=val}}const xu_attribute_keys=Object.keys(source_data.xuAttributes);for(let index=0;index<xu_attribute_keys.length;index++){const key=xu_attribute_keys[index];const val=source_data.xuAttributes[key];try{target_data.xuAttributes[key]=structuredClone(val)}catch(_){target_data.xuAttributes[key]=val}}return $target};func.runtime.ui.ensure_multi_view_state=function($div,nodeP,$container){const div_data=func.runtime.ui.get_data($div);const container_data=func.runtime.ui.get_data($container);if(!div_data?.xuData?.node||!div_data.xuData.node.children){div_data.xuData.node=nodeP}if(!div_data?.xuData?.debug_info){div_data.xuData.debug_info={id:nodeP.id,parent_id:container_data?.xuData?.ui_id}}return $div};func.runtime.ui.should_close_mobile_overlays=function(paramsP){return!REFRESHER_IN_PROGRESS&&(paramsP.is_mobile_popover||paramsP.is_mobile_page)};func.runtime.ui.render_single_view_node=async function(options){const exist_elm_obj=func.runtime.render.find_existing_element({$container:options.$container,nodeP:options.nodeP,keyP:options.keyP,render_context:options.render_context});let $div=exist_elm_obj.div;if(!$div){const $wrapper=document.createElement("div");$div=await func.runtime.ui.create_container({SESSION_ID:options.SESSION_ID,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,treeP:options.treeP,parent_nodeP:options.parent_nodeP,prop:options.prop,div_typeP:"div",$appendToP:$wrapper,attr_str:""});if(!$div)return;if(func.runtime.ui.should_close_mobile_overlays(options.paramsP)){func.runtime.ui.close_all_modals()}const div_el=func.runtime.ui.get_first_node($div);if(div_el){div_el.addEventListener("mouseenter",function(e){options.hover_handlers.hover_in($div,e)});div_el.addEventListener("mouseleave",function(){options.hover_handlers.hover_out()})}}await options.iterate_child($div,options.nodeP,null,$div);await func.runtime.ui.ensure_container_attributes({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP});func.runtime.ui.copy_runtime_state($div,options.$container);return await func.runtime.ui.render_screen_type({SESSION_ID:options.SESSION_ID,$div:$div,$container:options.$container,paramsP:options.paramsP,close_modal:options.close_modal})};func.runtime.ui.render_multi_view_node=async function(options){const $div=options.$container;func.runtime.ui.ensure_multi_view_state($div,options.nodeP,options.$container);const done=async function(continuous_idx){await func.runtime.ui.ensure_container_attributes({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP});return await func.runtime.ui.render_screen_type({SESSION_ID:options.SESSION_ID,$div:$div,$container:options.$container,paramsP:options.paramsP,close_modal:options.close_modal})};if(func.runtime.ui.should_close_mobile_overlays(options.paramsP)){func.runtime.ui.close_all_modals()}const _ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[options.paramsP.dsSessionP];if(!_ds.data_feed||xu_isEmpty(_ds.data_feed.rows)){await func.events.validate(options.SESSION_ID,"record_not_found",options.paramsP.dsSessionP);return await done(null)}const rows=_ds.data_feed.rows||[];for(let row_index=0;row_index<rows.length;row_index++){const val=rows[row_index];const node=JSON.parse(JSON.stringify(options.nodeP));_ds.currentRecordId=val._ROWID;await options.iterate_child($div,node,{continuous_idx:null},options.$root_container);await func.runtime.ui.ensure_container_attributes({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP})}return await done(null)};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.render_panel_node=async function(options){const $wrapper=document.createElement("div");const $div=await func.runtime.ui.create_container({SESSION_ID:options.SESSION_ID,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,treeP:options.treeP,parent_nodeP:options.parent_nodeP,prop:options.prop,$appendToP:$wrapper,attr_str:""});let ret=await func.runtime.render.set_attributes_new({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$elm:$div.cloneNode(true),is_init:true,refreshed_ds:options.refreshed_ds});if(ret.abort){const _tpl=document.createElement("template");_tpl.appendChild($div);return ret.$new_div=_tpl}let $ret_panel_div=ret.$new_div;if(!func.runtime.ui.get_first_node($ret_panel_div)?.childElementCount&&options.nodeP.children.length){$ret_panel_div=await func.runtime.render.render_ui_tree(options.SESSION_ID,options.$container,options.nodeP.children[0],options.parent_infoP,options.paramsP,options.jobNoP,null,0,null,options.nodeP,null,options.$root_container)}const container_data=func.runtime.ui.get_data(options.$container);if(!container_data?.xuData?.paramsP){return options.$container}const $div_items=func.runtime.ui.get_data($div)?.xuData?.node?.children;await func.runtime.ui.panel_post_render_handler({SESSION_ID:options.SESSION_ID,$container:options.$container,$wrapper:$ret_panel_div,nodeP:options.nodeP,$panel_div:$div,jobNoP:options.jobNoP});if(container_data?.xuData?.node){container_data.xuData.node.children=$div_items}return options.$container};func.runtime.ui.panel_post_render_handler=async function(options){try{const container_data=func.runtime.ui.get_data(options.$container);const wrapper_data=func.runtime.ui.get_data(options.$wrapper);const parent_container_data=func.runtime.ui.get_data(func.runtime.ui.get_parent(options.$container));const _container_ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[container_data?.xuData?.paramsP?.dsSessionP];const _ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[wrapper_data?.xuData?.paramsP?.dsSessionP];const panel_wrapper_id=container_data?.xuPanelData?.xu_panel_xu_ui_id;const find_old_panels_elements=function(){if(!panel_wrapper_id){return func.runtime.ui._wrap_matches([])}return func.runtime.ui.find_panel_wrapper_in_root(options.SESSION_ID,panel_wrapper_id)};const $old_panel_div=find_old_panels_elements();const wrapper_children=func.runtime.ui.get_children(options.$wrapper);const set_xuPanelData_to_the_new_rendered_items=function(){container_data.xuPanelWrapper={isWrapper:true,panelXuAttributes:{...wrapper_data?.xuAttributes},panelDivData:{...wrapper_data}};func.runtime.ui.set_attr(options.$container,"xu-panel-wrapper-id",func.runtime.ui.get_attr(options.$wrapper,"xu-ui-id"));for(let child_index=0;child_index<wrapper_children.length;child_index++){const val=wrapper_children[child_index];const val_data=func.runtime.ui.get_data(val);if(!val_data.xuPanelData){val_data.xuPanelData={}}val_data.xuPanelData.parent_element_ui_id=$old_panel_div?.length?parent_container_data?.xuData?.ui_id:container_data?.xuData?.ui_id;val_data.xuPanelData.xu_panel_xu_ui_id=(options.nodeP.xu_tree_id||options.nodeP.id)+"-"+_container_ds?.currentRecordId;val_data.xuPanelData.node=options.nodeP;val_data.xuPanelData.$panel_div=options.$panel_div.cloneNode(true)}};set_xuPanelData_to_the_new_rendered_items();if($old_panel_div?.length){func.runtime.ui.get_first_node($old_panel_div).after(...wrapper_children)}else{const existing_children=func.runtime.ui.get_children(options.$container);const existing_children_by_elem_key={};for(let existing_index=0;existing_index<existing_children.length;existing_index++){const elm=existing_children[existing_index];const elem_key=func.runtime.ui.get_data(elm)?.xuData?.elem_key;if(elem_key){existing_children_by_elem_key[elem_key]=elm}}for(let child_index=0;child_index<wrapper_children.length;child_index++){const child=wrapper_children[child_index];const elem_key=func.runtime.ui.get_data(child)?.xuData?.elem_key;if(elem_key&&existing_children_by_elem_key[elem_key]){func.runtime.ui.remove(existing_children_by_elem_key[elem_key])}func.runtime.ui.append(options.$container,child)}}if(!wrapper_data?.xuData?.dsSession){return options.jobNoP}if($old_panel_div?.length){if(parent_container_data?.xuData?.paramsP){parent_container_data.xuData.paramsP.dsSessionP=_ds.parentDataSourceNo}}else{if(container_data?.xuData?.paramsP){container_data.xuData.paramsP.dsSessionP=_ds.parentDataSourceNo}}if($old_panel_div?.length){func.runtime.ui.remove($old_panel_div)}return options.jobNoP}catch(error){return options.jobNoP}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.refresh_screen_ready_fields=async function(options){const current_record_id=options._ds?.currentRecordId;const changed_fields=options._ds?.data_feed?.form_fields_changed?.[current_record_id];if(!changed_fields){return false}const fields_to_refresh=Object.keys(changed_fields);const containerId=options._ds.containerId;const container=func.runtime.ui.find_element_by_id(containerId);if(container){container.dispatchEvent(new CustomEvent(containerId+".refresh",{detail:["init",fields_to_refresh]}))}if(options.$div_objP){await func.runtime.ui.refresh_xu_attributes({SESSION_ID:options.SESSION_ID,fields_arr:fields_to_refresh,$elm_to_search:options.$div_objP,dsSession_changed:options.paramsP.dsSessionP})}return true};func.runtime.ui.collect_screen_ready_events=async function(options){const _prog=await func.utils.VIEWS_OBJ.get(options.SESSION_ID,options._ds.prog_id);const viewEventExec_arr=[];if(!_prog?.progEvents||xu_isEmpty(_prog.progEvents)){return viewEventExec_arr}for await(const event_obj of _prog.progEvents){if(event_obj.data.type!=="screen_ready"||xu_isEmpty(event_obj.workflow)){continue}if(event_obj.data.condition){const res=await func.expression.get(options.SESSION_ID,event_obj.data.condition,options.paramsP.dsSessionP,"condition",options.paramsP.rowIdP,null,null,null,null,event_obj);if(!res.result){continue}}for await(const trigger_obj of event_obj.workflow){if(!trigger_obj.data.enabled){continue}const expression=trigger_obj.props.condition||undefined;if(expression){const expCond=await func.expression.get(options.SESSION_ID,expression,options.paramsP.dsSessionP,"condition",options.paramsP.rowIdP,trigger_obj.data.type);if(!expCond.result){continue}}if(!trigger_obj.data.action){func.utils.debug_report(options.SESSION_ID,"collect_screen_ready_events",`Error initiating screen_ready prog: ${options._ds.viewSourceDesc} reason: missing action`,"E");break}if(!glb.REFERENCE_LESS_FUNCTIONS.includes(trigger_obj.data.action)&&!trigger_obj.data.name?.prog){func.utils.debug_report(options.SESSION_ID,"collect_screen_ready_events",`Error initiating screen_ready prog: ${options._ds.viewSourceDesc} reason: missing reference`,"E");break}viewEventExec_arr.push({eventInfo:trigger_obj,eventId:event_obj.id,triggerId:trigger_obj.id,expression:expression})}}return viewEventExec_arr};func.runtime.ui.execute_screen_ready_events=async function(options){const _ds=SESSION_OBJ[options.SESSION_ID]?.DS_GLB?.[options.paramsP.dsSessionP];if(!_ds){return}try{const viewEventExec_arr=await func.runtime.ui.collect_screen_ready_events({SESSION_ID:options.SESSION_ID,paramsP:options.paramsP,_ds:_ds});if(!viewEventExec_arr.length){return}for await(const val of viewEventExec_arr){let cond=val.eventInfo.data.enabled;if(val.expression){const expCond=await func.expression.get(options.SESSION_ID,val.expression,options.paramsP.dsSessionP,"condition",options.paramsP.rowIdP);cond=expCond.result}if(!cond){continue}await func.events.execute(options.SESSION_ID,null,val.eventId,val.triggerId,val.eventInfo.data.action,val.eventInfo.data.name,null,null,null,null,val.eventInfo.data.action,null,options.paramsP.dsSessionP,val.eventId,options.sourceP+" event",true,null,null,options.paramsP.dsSessionP,null,null,val.eventInfo,null,null,_ds.prog_id,_ds.nodeId,_ds.parentDataSourceNo,options.$div);await func.runtime.ui.refresh_screen_ready_fields({SESSION_ID:options.SESSION_ID,paramsP:options.paramsP,_ds:_ds,$div_objP:options.$div_objP})}}catch(error){debugger}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.screen_loading_done=async function(options){let retries=0;const interval=setInterval(()=>{const xu_ui_id=func.runtime.ui.get_attr(options.$div,"xu-ui-id");if(!func.runtime.ui.find_xu_ui_in_root(options.SESSION_ID,xu_ui_id).length&&!func.runtime.ui.find_panel_wrapper_in_root(options.SESSION_ID,xu_ui_id).length&&!xu_ui_id&&xu_ui_id){retries++;if(retries>100){console.warn("deadlock detected for screen ready")}else{return options.$div}}clearInterval(interval);func.runtime.ui.execute_screen_ready_events({SESSION_ID:options.SESSION_ID,paramsP:options.paramsP,sourceP:options.paramsP.screenInfo.properties?.renderType,$div:options.$div,jobNoP:options.jobNoP});const _session=SESSION_OBJ[options.SESSION_ID];if(func.runtime.render.should_use_ssr_payload(options.SESSION_ID,options.paramsP)){const root_node=func.runtime.ui.get_root_node(options.SESSION_ID);if(root_node){func.runtime.ui.set_attr(root_node,"data-xuda-client-activation",_session.opt.app_client_activation||"none");func.runtime.ui.set_attr(root_node,"data-xuda-ssr-status",_session.opt.app_client_activation==="hydrate"?"hydrated":"taken-over")}func.runtime.render.mark_ssr_payload_consumed(options.SESSION_ID)}func.events.delete_job(options.SESSION_ID,options.jobNoP);func.UI.utils.screen_blocker(false,options.paramsP.prog_id+(options.paramsP.sourceScreenP?"_"+options.paramsP.sourceScreenP:""));if(_session.prog_id===options.paramsP.prog_id){_session.system_ready=true;if(_session.engine_mode==="live_preview"&&STUDIO_PEER_CONN_SEND_METHOD){STUDIO_PEER_CONN_SEND_METHOD({service:"system_ready",data:{},id:STUDIO_PEER.id,source:"runtime",session_id:options.SESSION_ID,app_id:_session.app_id,gtp_token:_session.gtp_token,app_token:_session.app_token})}}},100);return options.$div};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui._to_node_array=func.runtime.ui._to_node_array||function(input){if(!input){return[]}if(typeof input?.toArray==="function"&&typeof input?.length==="number"&&!input?.nodeType){return input.toArray()}if(Array.isArray(input)){return input}if(input.nodeType){return[input]}if(typeof input.length==="number"){const arr=[];for(let i=0;i<input.length;i++){if(input[i]){arr.push(input[i])}}return arr}return[]};func.runtime.ui.ensure_refresh_dependency_state=function(SESSION_ID){const _session=SESSION_OBJ?.[SESSION_ID];if(!_session){return null}if(!_session.refresh_dependency_state){_session.refresh_dependency_state={dirty:true,index:{},elements_by_ui_id:{},elements_by_nodeid:{},panel_wrappers_by_id:{},xu_for_dirty:true,xu_for_index:{},panel_wrappers_dirty:true,panel_wrappers_cache:{},panel_wrappers_active_cache:{},runtime_elements_cache:null,panel_wrapper_elements_cache:null}}if(typeof _session.refresh_dependency_state.dirty!=="boolean"){_session.refresh_dependency_state.dirty=true}if(!_session.refresh_dependency_state.index){_session.refresh_dependency_state.index={}}if(!_session.refresh_dependency_state.elements_by_ui_id){_session.refresh_dependency_state.elements_by_ui_id={}}if(!_session.refresh_dependency_state.elements_by_nodeid){_session.refresh_dependency_state.elements_by_nodeid={}}if(!_session.refresh_dependency_state.panel_wrappers_by_id){_session.refresh_dependency_state.panel_wrappers_by_id={}}if(typeof _session.refresh_dependency_state.xu_for_dirty!=="boolean"){_session.refresh_dependency_state.xu_for_dirty=true}if(!_session.refresh_dependency_state.xu_for_index){_session.refresh_dependency_state.xu_for_index={}}if(typeof _session.refresh_dependency_state.panel_wrappers_dirty!=="boolean"){_session.refresh_dependency_state.panel_wrappers_dirty=true}if(!_session.refresh_dependency_state.panel_wrappers_cache){_session.refresh_dependency_state.panel_wrappers_cache={}}if(!_session.refresh_dependency_state.panel_wrappers_active_cache){_session.refresh_dependency_state.panel_wrappers_active_cache={}}if(typeof _session.refresh_dependency_state.runtime_elements_cache==="undefined"){_session.refresh_dependency_state.runtime_elements_cache=null}if(typeof _session.refresh_dependency_state.panel_wrapper_elements_cache==="undefined"){_session.refresh_dependency_state.panel_wrapper_elements_cache=null}return _session.refresh_dependency_state};func.runtime.ui.resolve_refresh_index_session_id=function(target,explicit_session_id){if(explicit_session_id&&SESSION_OBJ?.[explicit_session_id]){return explicit_session_id}const target_node=func.runtime.ui.get_first_node(target);const session_from_data=func.runtime.ui.get_data(target_node)?.xuData?.SESSION_ID;if(session_from_data){return session_from_data}const session_ids=Object.keys(SESSION_OBJ||{});if(session_ids.length===1){return session_ids[0]}return null};func.runtime.ui.mark_refresh_index_dirty=function(SESSION_ID){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return false}state.dirty=true;state.xu_for_dirty=true;state.panel_wrappers_dirty=true;state.runtime_elements_cache=null;state.panel_wrapper_elements_cache=null;return true};func.runtime.ui.mark_refresh_index_dirty_from_target=function(target,explicit_session_id){const session_id=func.runtime.ui.resolve_refresh_index_session_id(target,explicit_session_id);if(!session_id){return false}return func.runtime.ui.mark_refresh_index_dirty(session_id)};func.runtime.ui.remove_refresh_dependency_entry=function($elm,attr_key){const session_id=func.runtime.ui.resolve_refresh_index_session_id($elm);const selector_id=func.runtime.ui.get_attr($elm,"xu-ui-id");const elm_data=func.runtime.ui.get_data($elm);const dependency_store=elm_data?.xuData?.refresh_dependency_by_attr;if(!session_id||!selector_id||!dependency_store?.[attr_key]){return false}const state=func.runtime.ui.ensure_refresh_dependency_state(session_id);const old_fields=dependency_store[attr_key]||[];if(!state||state.dirty){delete dependency_store[attr_key];return true}for(const field_id of old_fields){const field_index=state.index?.[field_id];const selector_entry=field_index?.[selector_id];if(!selector_entry){continue}selector_entry.attributes.delete(attr_key);if(!selector_entry.attributes.size){delete field_index[selector_id]}if(xu_isEmpty(field_index)){delete state.index[field_id]}}delete dependency_store[attr_key];return true};func.runtime.ui.update_refresh_dependency_entry=function($elm,attr_key,attr_val){const session_id=func.runtime.ui.resolve_refresh_index_session_id($elm);const selector_id=func.runtime.ui.get_attr($elm,"xu-ui-id");const elm_data=func.runtime.ui.get_data($elm);if(!session_id||!selector_id||!elm_data?.xuData){return false}if(!elm_data.xuData.refresh_dependency_by_attr){elm_data.xuData.refresh_dependency_by_attr={}}func.runtime.ui.remove_refresh_dependency_entry($elm,attr_key);const state=func.runtime.ui.ensure_refresh_dependency_state(session_id);const fields=[...func.runtime.ui.collect_refresh_attribute_fields(elm_data,attr_key,attr_val)];elm_data.xuData.refresh_dependency_by_attr[attr_key]=fields;if(!state||state.dirty||!fields.length){return!!fields.length}for(const field_id of fields){if(!state.index[field_id]){state.index[field_id]={}}if(!state.index[field_id][selector_id]){state.index[field_id][selector_id]={attributes:new Set,$elm:$elm}}state.index[field_id][selector_id].attributes.add(attr_key);state.index[field_id][selector_id].$elm=$elm}return true};func.runtime.ui.prune_stale_refresh_dependencies=function($elm,node_attributes){const elm_data=func.runtime.ui.get_data($elm);const stored_attributes=elm_data?.xuAttributes;if(!stored_attributes){return false}let changed=false;for(const key of Object.keys(stored_attributes)){if(key.substr(0,3)!=="xu-"){continue}if(Object.prototype.hasOwnProperty.call(node_attributes||{},key)){continue}func.runtime.ui.remove_refresh_dependency_entry($elm,key);delete stored_attributes[key];changed=true}return changed};func.runtime.ui.normalize_refresh_field_reference=function(field_ref){if(!field_ref){return[]}const normalized=new Set;normalized.add(field_ref);const base_field=field_ref.split(/[.[(]/)[0];if(base_field){normalized.add(base_field)}return[...normalized].filter(Boolean)};func.runtime.ui.extract_expression_refresh_fields=function(elm_data,expression_text,without_var,_visited){const fields=new Set;if(!expression_text){return fields}const add_field=function(field_ref){for(const normalized of func.runtime.ui.normalize_refresh_field_reference(field_ref)){fields.add(normalized)}};const text=typeof expression_text==="string"?expression_text:JSON.stringify(expression_text);if(!text){return fields}if(without_var){const trimmed=text.trim();const root_match=trimmed.match(/^([A-Za-z0-9_$.-]+)/);if(root_match?.[1]){add_field(root_match[1])}}for(const match of text.matchAll(/@([A-Za-z0-9_$.-]+)/g)){add_field(match[1])}const parameters_raw_obj=elm_data?.xuData?.paramsP?.parameters_raw_obj||{};const parameter_keys=Object.keys(parameters_raw_obj);const visited=_visited||new Set;for(let index=0;index<parameter_keys.length;index++){const param_key=parameter_keys[index];if(visited.has(param_key)){continue}const param_val=parameters_raw_obj[param_key];if(!param_val?.includes?.("@")){continue}const param_token=`${without_var?"":"@"}${param_key}`;if(!text.includes(param_token)){continue}visited.add(param_key);const nested_fields=func.runtime.ui.extract_expression_refresh_fields(elm_data,param_val,false,visited);nested_fields.forEach(function(field_id){add_field(field_id)})}return fields};func.runtime.ui.validate_refresh_parameter_reference=function(elm_data,exp,field_id,without_var){let expression_text;if(typeof exp==="string"){expression_text=exp}else if(typeof exp==="object"){expression_text=JSON.stringify(exp)}if(!expression_text||!expression_text.includes("@")){return false}if(xu_isEmpty(elm_data?.xuData?.paramsP?.parameters_raw_obj)){return false}const parameters_raw_obj=elm_data.xuData.paramsP.parameters_raw_obj;const parameter_keys=Object.keys(parameters_raw_obj);for(let index=0;index<parameter_keys.length;index++){const param_key=parameter_keys[index];const param_val=parameters_raw_obj[param_key];if(!param_val?.includes?.("@")){continue}expression_text=expression_text.replaceAll((without_var?"":"@")+param_key,param_val)}return expression_text.includes((without_var?"":"@")+field_id)};func.runtime.ui.collect_refresh_attribute_fields=function(elm_data,key,val){const fields=new Set;const add_fields=function(values){values?.forEach?.(function(field_id){fields.add(field_id)})};if(typeof val!=="string"&&typeof val!=="object"){return fields}if(key==="xu-bind"||key==="xu-for"){add_fields(func.runtime.ui.extract_expression_refresh_fields(elm_data,val,true));add_fields(func.runtime.ui.extract_expression_refresh_fields(elm_data,val,false));return fields}if(key.substr(0,6)==="xu-exp"&&key.substr(6,1)===":"){add_fields(func.runtime.ui.extract_expression_refresh_fields(elm_data,val,false));return fields}if(key.substr(0,8)==="xu-class"){try{const classes_obj=typeof val==="string"?JSON.parse(val):val||{};const class_keys=Object.keys(classes_obj||{});for(let index=0;index<class_keys.length;index++){add_fields(func.runtime.ui.extract_expression_refresh_fields(elm_data,classes_obj[class_keys[index]],false))}}catch(error){console.warn("parse error:"+val)}return fields}if(key==="xu-ui-plugin"){add_fields(func.runtime.ui.extract_expression_refresh_fields(elm_data,JSON.stringify(val),false))}return fields};func.runtime.ui.collect_element_refresh_dependencies=function(elm_data){const dependency_store=elm_data?.xuData?.refresh_dependency_by_attr;if(!xu_isEmpty(dependency_store)){const stored_dependencies={};const attr_keys=Object.keys(dependency_store||{});for(let attr_index=0;attr_index<attr_keys.length;attr_index++){const attr_key=attr_keys[attr_index];const fields_arr=dependency_store[attr_key]||[];for(let field_index=0;field_index<fields_arr.length;field_index++){const field_id=fields_arr[field_index];if(!stored_dependencies[field_id]){stored_dependencies[field_id]=new Set}stored_dependencies[field_id].add(attr_key)}}return stored_dependencies}const dependencies={};const xu_attributes=elm_data?.xuAttributes||{};const attr_keys=Object.keys(xu_attributes);for(let attr_index=0;attr_index<attr_keys.length;attr_index++){const key=attr_keys[attr_index];const val=xu_attributes[key];if(key.substr(0,3)!=="xu-"){continue}const fields=func.runtime.ui.collect_refresh_attribute_fields(elm_data,key,val);fields.forEach(function(field_id){if(!dependencies[field_id]){dependencies[field_id]=new Set}dependencies[field_id].add(key)})}return dependencies};func.runtime.ui.matches_refresh_search_root=function(elm,search_roots){if(!search_roots?.length){return true}const elm_node=func.runtime.ui.get_first_node(elm);if(!elm_node){return false}for(let index=0;index<search_roots.length;index++){const root_node=func.runtime.ui.get_first_node(search_roots[index]);if(elm_node===root_node||root_node&&root_node.contains(elm_node)){return true}}return false};func.runtime.ui.collect_refresh_attributes=function(elm_data,field_id){const attributes=[];const xu_attributes=elm_data?.xuAttributes||{};const attr_keys=Object.keys(xu_attributes);for(let attr_index=0;attr_index<attr_keys.length;attr_index++){const key=attr_keys[attr_index];const val=xu_attributes[key];if(typeof val!=="string"&&typeof val!=="object"){continue}if(typeof val==="string"&&!val?.includes("@")&&key!=="xu-bind"&&key!=="xu-for"){continue}if(key.substr(0,3)!=="xu-"){continue}if(key==="xu-bind"||key==="xu-for"){if(val?.includes?.(field_id)||func.runtime.ui.validate_refresh_parameter_reference(elm_data,val,field_id,true)){attributes.push(key)}continue}if(key.substr(0,6)==="xu-exp"&&key.substr(6,1)===":"){if(val?.includes?.("@"+field_id)||func.runtime.ui.validate_refresh_parameter_reference(elm_data,val,field_id)){attributes.push(key)}continue}if(key.substr(0,8)==="xu-class"){try{const classes_obj=typeof val==="string"?JSON.parse(val):val||{};const class_keys=Object.keys(classes_obj||{});for(let class_index=0;class_index<class_keys.length;class_index++){const cond=classes_obj[class_keys[class_index]];if(cond?.includes?.("@"+field_id)||func.runtime.ui.validate_refresh_parameter_reference(elm_data,cond,field_id)){attributes.push("xu-class");break}}if(attributes.length){break}}catch(error){console.warn("parse error:"+val)}continue}if(key==="xu-ui-plugin"){const plugin_str=JSON.stringify(val);if(plugin_str.includes("@"+field_id)||func.runtime.ui.validate_refresh_parameter_reference(elm_data,plugin_str,field_id)){attributes.push(key);break}}}return attributes};func.runtime.ui.normalize_refresh_fields=function(fields_arr){return new Set((fields_arr||[]).map(function(field_id){return field_id?.toString?.()||field_id}))};func.runtime.ui.collect_refresh_attributes_for_fields=function(elm_data,fields_arr,requested_fields){const attributes=new Set;requested_fields=requested_fields||func.runtime.ui.normalize_refresh_fields(fields_arr);if(!requested_fields.size){return[]}let dependencies={};const dependency_store=elm_data?.xuData?.refresh_dependency_by_attr||{};const dependency_attr_keys=Object.keys(dependency_store);for(let attr_index=0;attr_index<dependency_attr_keys.length;attr_index++){const attr_key=dependency_attr_keys[attr_index];const attr_fields=dependency_store[attr_key]||[];for(let field_index=0;field_index<attr_fields.length;field_index++){const field_id=attr_fields[field_index];const normalized_field_id=field_id?.toString?.()||field_id;if(!requested_fields.has(normalized_field_id)){continue}if(!dependencies[normalized_field_id]){dependencies[normalized_field_id]=new Set}dependencies[normalized_field_id].add(attr_key)}}if(xu_isEmpty(dependencies)){dependencies=func.runtime.ui.collect_element_refresh_dependencies(elm_data)}requested_fields.forEach(function(field_id){const attr_set=dependencies[field_id];attr_set?.forEach?.(function(attr_key){attributes.add(attr_key)})});return[...attributes]};func.runtime.ui.register_refresh_index_element=function(elements_by_ui_id,elements_by_nodeid,panel_wrappers_by_id,selector_id,elm_data,$elm){if(!selector_id||!elm_data?.xuData){return false}elements_by_ui_id[selector_id]=$elm;const panel_wrapper_id=func.runtime.ui.get_attr($elm,"xu-panel-wrapper-id");if(panel_wrapper_id){panel_wrappers_by_id[panel_wrapper_id]=$elm}const node_id=elm_data.xuData.nodeid;if(!node_id){return true}if(!elements_by_nodeid[node_id]){elements_by_nodeid[node_id]={}}elements_by_nodeid[node_id][selector_id]=$elm;return true};func.runtime.ui.find_refresh_elements_by_attr=function(root_nodes_input,attr_name,attr_value,first_only=false){const root_nodes=func.runtime.ui._to_node_array(root_nodes_input);if(!root_nodes.length||!attr_name){return func.runtime.ui._wrap_matches([])}const selector=typeof attr_value==="undefined"?`[${attr_name}]`:`[${attr_name}="${attr_value}"]`;const elements=[];for(let root_index=0;root_index<root_nodes.length;root_index++){const root_node=root_nodes[root_index];if(root_node?.matches?.(selector)){elements.push(root_node);if(first_only){break}}if(first_only&&elements.length){break}if(first_only){const first_match=root_node?.querySelector?.(selector);if(first_match){elements.push(first_match);break}continue}const descendants=root_node?.querySelectorAll?.(selector)||[];for(let index=0;index<descendants.length;index++){elements.push(descendants[index])}}return func.runtime.ui._wrap_matches(elements)};func.runtime.ui.get_preferred_live_element=function(target){const elements=func.runtime.ui._to_node_array(target);if(!elements.length){return null}let best_node=null;let best_score=-Infinity;for(let index=0;index<elements.length;index++){const node=elements[index];if(!node){continue}const node_data=func.runtime.ui.get_data(node);let score=0;if(node.isConnected){score+=100}if(!node_data?.xuData?.pending_to_delete){score+=50}if(node.getClientRects?.().length){score+=25}if(!node.hidden){score+=10}if(score>=best_score){best_score=score;best_node=node}}return best_node||elements[elements.length-1]||null};func.runtime.ui.get_refresh_indexed_element_by_ui_id=function(SESSION_ID,selector_id){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return null}if(state.dirty){func.runtime.ui.rebuild_refresh_dependency_index(SESSION_ID)}let elm=state.elements_by_ui_id?.[selector_id];elm=func.runtime.ui.get_preferred_live_element(elm);if(elm?.isConnected){state.elements_by_ui_id[selector_id]=elm;return elm}const root_nodes=func.runtime.ui.get_refresh_index_root(SESSION_ID);elm=func.runtime.ui.get_preferred_live_element(func.runtime.ui.find_refresh_elements_by_attr(root_nodes,"xu-ui-id",selector_id));if(elm){state.elements_by_ui_id[selector_id]=elm;state.runtime_elements_cache=null}else if(state.elements_by_ui_id?.[selector_id]){delete state.elements_by_ui_id[selector_id];state.runtime_elements_cache=null}return elm};func.runtime.ui.get_refresh_indexed_elements_by_node_id=function(SESSION_ID,node_id){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return func.runtime.ui._wrap_matches([])}if(state.dirty){func.runtime.ui.rebuild_refresh_dependency_index(SESSION_ID)}const indexed_elements=state.elements_by_nodeid?.[node_id]||{};const elements=[];const selector_ids=Object.keys(indexed_elements);for(let index=0;index<selector_ids.length;index++){const selector_id=selector_ids[index];let candidate=indexed_elements[selector_id];if(!candidate?.isConnected){candidate=func.runtime.ui.get_refresh_indexed_element_by_ui_id(SESSION_ID,selector_id);if(!candidate){delete indexed_elements[selector_id];continue}indexed_elements[selector_id]=candidate}if(candidate){elements.push(candidate)}}return func.runtime.ui._wrap_matches(elements)};func.runtime.ui.get_refresh_index_root=function(SESSION_ID){const root=func.runtime.ui.get_first_node(func.runtime.ui.get_root_element?.(SESSION_ID));if(root){return[root]}return[document.body]};func.runtime.ui.get_refresh_index_elements=function(SESSION_ID,search_root_input){const root_nodes=func.runtime.ui._to_node_array(search_root_input);if(!root_nodes.length){const default_roots=func.runtime.ui.get_refresh_index_root(SESSION_ID);root_nodes.push(...default_roots)}const elements=[];for(let root_index=0;root_index<root_nodes.length;root_index++){const root_node=root_nodes[root_index];if(root_node?.matches?.("[xu-ui-id]")){elements.push(root_node)}const descendants=root_node?.querySelectorAll?.("[xu-ui-id]")||[];for(let element_index=0;element_index<descendants.length;element_index++){elements.push(descendants[element_index])}}return func.runtime.ui._wrap_matches(elements)};func.runtime.ui.get_refresh_indexed_runtime_elements=function(SESSION_ID){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return[]}if(state.dirty){func.runtime.ui.rebuild_refresh_dependency_index(SESSION_ID)}if(state.runtime_elements_cache!==null){return state.runtime_elements_cache}const elements=[];const selector_ids=Object.keys(state.elements_by_ui_id||{});for(let index=0;index<selector_ids.length;index++){const selector_id=selector_ids[index];let candidate=state.elements_by_ui_id[selector_id];if(!candidate?.isConnected){candidate=func.runtime.ui.get_refresh_indexed_element_by_ui_id(SESSION_ID,selector_id)}if(candidate){elements.push(candidate)}}state.runtime_elements_cache=elements;return state.runtime_elements_cache};func.runtime.ui.get_refresh_indexed_panel_wrapper_by_id=function(SESSION_ID,wrapper_id){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return null}if(state.dirty){func.runtime.ui.rebuild_refresh_dependency_index(SESSION_ID)}let elm=state.panel_wrappers_by_id?.[wrapper_id];elm=func.runtime.ui.get_preferred_live_element(elm);if(elm?.isConnected){state.panel_wrappers_by_id[wrapper_id]=elm;return elm}const root_nodes=func.runtime.ui.get_refresh_index_root(SESSION_ID);elm=func.runtime.ui.get_preferred_live_element(func.runtime.ui.find_refresh_elements_by_attr(root_nodes,"xu-panel-wrapper-id",wrapper_id));if(elm){state.panel_wrappers_by_id[wrapper_id]=elm;state.panel_wrapper_elements_cache=null}else if(state.panel_wrappers_by_id?.[wrapper_id]){delete state.panel_wrappers_by_id[wrapper_id];state.panel_wrapper_elements_cache=null}return elm};func.runtime.ui.get_refresh_indexed_panel_wrappers=function(SESSION_ID){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return[]}if(state.dirty){func.runtime.ui.rebuild_refresh_dependency_index(SESSION_ID)}if(state.panel_wrapper_elements_cache!==null){return state.panel_wrapper_elements_cache}const elements=[];const wrapper_ids=Object.keys(state.panel_wrappers_by_id||{});for(let index=0;index<wrapper_ids.length;index++){const wrapper_id=wrapper_ids[index];let candidate=state.panel_wrappers_by_id[wrapper_id];if(!candidate?.isConnected){candidate=func.runtime.ui.get_refresh_indexed_panel_wrapper_by_id(SESSION_ID,wrapper_id)}if(candidate){elements.push(candidate)}}state.panel_wrapper_elements_cache=elements;return state.panel_wrapper_elements_cache};func.runtime.ui.rebuild_refresh_dependency_index=function(SESSION_ID){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return{}}const index={};const elements_by_ui_id={};const elements_by_nodeid={};const panel_wrappers_by_id={};const refresh_elements=func.runtime.ui.get_refresh_index_elements(SESSION_ID);for(let element_index=0;element_index<refresh_elements.length;element_index++){const elm=refresh_elements[element_index];const elm_data=func.runtime.ui.get_data(elm);const selector_id=func.runtime.ui.get_attr(elm,"xu-ui-id");if(!selector_id||!elm_data?.xuData||!elm_data?.xuAttributes){continue}func.runtime.ui.register_refresh_index_element(elements_by_ui_id,elements_by_nodeid,panel_wrappers_by_id,selector_id,elm_data,elm);const dependencies=func.runtime.ui.collect_element_refresh_dependencies(elm_data);const field_ids=Object.keys(dependencies);for(let field_index=0;field_index<field_ids.length;field_index++){const field_id=field_ids[field_index];const attrs=dependencies[field_id];if(!index[field_id]){index[field_id]={}}if(!index[field_id][selector_id]){index[field_id][selector_id]={attributes:new Set,$elm:elm}}for(const attr_key of attrs||[]){index[field_id][selector_id].attributes.add(attr_key)}}}state.index=index;state.elements_by_ui_id=elements_by_ui_id;state.elements_by_nodeid=elements_by_nodeid;state.panel_wrappers_by_id=panel_wrappers_by_id;const runtime_elements=[];const runtime_selector_ids=Object.keys(elements_by_ui_id);for(let index=0;index<runtime_selector_ids.length;index++){const element=elements_by_ui_id[runtime_selector_ids[index]];if(element){runtime_elements.push(element)}}const panel_wrapper_elements=[];const panel_wrapper_ids=Object.keys(panel_wrappers_by_id);for(let index=0;index<panel_wrapper_ids.length;index++){const element=panel_wrappers_by_id[panel_wrapper_ids[index]];if(element){panel_wrapper_elements.push(element)}}state.runtime_elements_cache=runtime_elements;state.panel_wrapper_elements_cache=panel_wrapper_elements;state.dirty=false;return index};func.runtime.ui.collect_refresh_selectors_from_index=function(options){const perf_end=func.runtime?.perf?.start?.(options.SESSION_ID,"collect_refresh_selectors_from_index");func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_index_calls");const state=func.runtime.ui.ensure_refresh_dependency_state(options.SESSION_ID);if(!state){perf_end?.();return{}}if(state.dirty){func.runtime.ui.rebuild_refresh_dependency_index(options.SESSION_ID)}const selectors={};const index=state.index||{};const search_roots=func.runtime.ui._to_node_array(options.$elm_to_search);const search_root=search_roots.length?search_roots:null;const requested_fields=[...func.runtime.ui.normalize_refresh_fields(options.fields_arr)];for(let field_index=0;field_index<requested_fields.length;field_index++){const val_field=requested_fields[field_index];const indexed_elements=index[val_field]||{};const selector_ids=Object.keys(indexed_elements);for(let selector_index=0;selector_index<selector_ids.length;selector_index++){const selector_id=selector_ids[selector_index];const entry=indexed_elements[selector_id];let elm=entry.$elm;if(!elm?.isConnected){elm=func.runtime.ui.get_refresh_indexed_element_by_ui_id(options.SESSION_ID,selector_id);entry.$elm=elm}if(!elm){delete indexed_elements[selector_id];continue}const elm_data=func.runtime.ui.get_data(elm);if(!elm_data?.xuData){delete indexed_elements[selector_id];continue}if(!func.runtime.ui.matches_refresh_search_root(elm,search_root)){continue}if(typeof options.dsSession_changed!=="undefined"&&elm_data.xuData.paramsP&&elm_data.xuData.paramsP.dsSessionP<options.dsSession_changed){continue}if(!selectors[selector_id]){selectors[selector_id]={attributes:new Set,$elm:elm}}const attr_values=[...entry.attributes];for(let attr_index=0;attr_index<attr_values.length;attr_index++){selectors[selector_id].attributes.add(attr_values[attr_index])}}}const selector_result_ids=Object.keys(selectors);for(let selector_index=0;selector_index<selector_result_ids.length;selector_index++){const selector_id=selector_result_ids[selector_index];selectors[selector_id].attributes=[...selectors[selector_id].attributes]}func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_index_found",selector_result_ids.length);perf_end?.();return selectors};func.runtime.ui.collect_refresh_selectors_by_scan=function(options){const perf_end=func.runtime?.perf?.start?.(options.SESSION_ID,"collect_refresh_selectors_by_scan");func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_scan_calls");const selectors={};const search_roots=func.runtime.ui._to_node_array(options.$elm_to_search);const search_root=search_roots.length?search_roots:func.runtime.ui.get_refresh_index_root(options.SESSION_ID);const requested_fields=func.runtime.ui.normalize_refresh_fields(options.fields_arr);const refresh_elements=func.runtime.ui.get_refresh_index_elements(options.SESSION_ID,search_root);for(let element_index=0;element_index<refresh_elements.length;element_index++){const elm=refresh_elements[element_index];const elm_data=func.runtime.ui.get_data(elm);if(!elm_data.xuData){continue}if(typeof options.dsSession_changed!=="undefined"&&elm_data.xuData.paramsP&&elm_data.xuData.paramsP.dsSessionP<options.dsSession_changed){continue}const attributes=func.runtime.ui.collect_refresh_attributes_for_fields(elm_data,options.fields_arr,requested_fields);const selector_id=func.runtime.ui.get_attr(elm,"xu-ui-id");if(!attributes.length||!selector_id){continue}if(!selectors[selector_id]){selectors[selector_id]={attributes:new Set,$elm:elm}}for(let attr_index=0;attr_index<attributes.length;attr_index++){selectors[selector_id].attributes.add(attributes[attr_index])}}const selector_ids=Object.keys(selectors);for(let selector_index=0;selector_index<selector_ids.length;selector_index++){const selector_id=selector_ids[selector_index];selectors[selector_id].attributes=[...selectors[selector_id].attributes]}func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_scan_found",selector_ids.length);perf_end?.();return selectors};func.runtime.ui.collect_refresh_selectors=function(options){const selectors=func.runtime.ui.collect_refresh_selectors_from_index(options);if(!xu_isEmpty(selectors)){func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_index_used");return selectors}func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_scan_used");return func.runtime.ui.collect_refresh_selectors_by_scan(options)};func.runtime.ui.build_refresh_job_obj=function(options,elem_key,elem_val,extra={}){const elm_data=func.runtime.ui.get_data(elem_val.$elm);return{ui_type:elm_data?.xuData?.ui_type,SESSION_ID:options.SESSION_ID,fields_arr:options.fields_arr,elem_key:elem_key,node_id:elm_data?.xuData?.nodeid,key:elm_data?.xuData?.key,key_path:elm_data?.xuData?.key_path,recordid:elm_data?.xuData?.recordid,parent_element_ui_id:elm_data?.xuData?.parent_element_ui_id,prog_id:elm_data?.xuData?.paramsP?.prog_id,elem_val:{attributes:[...elem_val.attributes||[]]},...extra}};func.runtime.ui.queue_refresh_execute_job=async function(options,elem_key,elem_val,type,current_job){const elm_data=func.runtime.ui.get_data(elem_val.$elm);if(!elm_data?.xuData){return current_job}try{const obj=func.runtime.ui.build_refresh_job_obj(options,elem_key,elem_val);const next_job=await func.UI.worker.add_to_queue(options.SESSION_ID,"gui event",type,obj,current_job,elem_val.$elm);return next_job}catch(error){debugger;return current_job}};func.runtime.ui.queue_refresh_render_job=async function(options,elem_key,elem_val,attr_value,current_job){const elm_data=func.runtime.ui.get_data(elem_val?.$elm);if(!elm_data?.xuData?.ui_type){return current_job}const obj=func.runtime.ui.build_refresh_job_obj(options,elem_key,elem_val,{attr_value:attr_value});const next_job=await func.UI.worker.add_to_queue(options.SESSION_ID,"gui event","execute_xu_render_attributes",obj,current_job,elem_val.$elm,elm_data.xuData.paramsP.dsSessionP);if(glb.DEBUG_MODE){console.info("execute_xu_render_attributes",obj)}return next_job};func.runtime.ui.mark_refresh_pending_delete=function(elm_input){const elm=func.runtime.ui.get_first_node(elm_input);const session_id=func.runtime.ui.resolve_refresh_index_session_id?func.runtime.ui.resolve_refresh_index_session_id(elm):func.runtime.ui.get_data(elm)?.xuData?.SESSION_ID;const descendants=elm?.querySelectorAll?.("[xu-ui-id]")||[];for(let index=0;index<descendants.length;index++){const val=descendants[index];const element_data=func.runtime.ui.get_data(val);if(element_data?.xuData){element_data.xuData.pending_to_delete=true;if(func.UI?.worker?.mark_pending_delete_element&&session_id){func.UI.worker.mark_pending_delete_element(session_id,val)}}}if(func.UI?.worker?.mark_pending_delete_session&&session_id){func.UI.worker.mark_pending_delete_session(session_id)}return elm_input};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.prog_ui_xu_for_dependency_cache=func.runtime.ui.prog_ui_xu_for_dependency_cache||new WeakMap;func.runtime.ui.prog_ui_xu_for_fields_cache=func.runtime.ui.prog_ui_xu_for_fields_cache||new Map;func.runtime.ui.get_refresh_parent_element_ui_id=function($elm){const elm_data=func.runtime.ui.get_data($elm);if(elm_data?.xuPanelData){return elm_data.xuPanelData.parent_element_ui_id}return elm_data?.xuData?.parent_element_ui_id};func.runtime.ui.resolve_refresh_xu_for_item_id=function($elm){const elm_data=func.runtime.ui.get_data($elm);if(elm_data?.xuPanelData){return elm_data.xuPanelData.node.id}return elm_data?.xuData?.nodeid};func.runtime.ui.build_refresh_element_value=function($elm){const elem_val={attributes:Object.keys(func.runtime.ui.get_data($elm)?.xuAttributes||{}),$elm:$elm};return elem_val};func.runtime.ui.build_xu_for_refresh_job_obj=function(options,elem_key,$elm,xu_for_item_id){const elm_data=func.runtime.ui.get_data($elm);return{ui_type:elm_data.xuData.ui_type,SESSION_ID:options.SESSION_ID,fields_arr:options.fields_arr,elem_key:elem_key,elem_val:{},xu_for_item_id:xu_for_item_id}};func.runtime.ui.queue_xu_for_refresh=async function(options,$elm,xu_for_item_id,current_job,debug_label,debug_context){const elm_data=func.runtime.ui.get_data($elm);if(options.avoid_xu_for_refresh||!$elm?.length||!elm_data?.xuData){return current_job}const elem_key=func.runtime.ui.get_attr($elm,"xu-ui-id");const obj=func.runtime.ui.build_xu_for_refresh_job_obj(options,elem_key,$elm,xu_for_item_id);await func.UI.worker.add_to_queue(options.SESSION_ID,"gui event","execute_xu_for",obj,current_job,$elm,elm_data.xuData.paramsP.dsSessionP);if(glb.DEBUG_MODE){console.info(debug_label||"execute_xu_for",obj,debug_context)}return current_job};func.runtime.ui.collect_prog_ui_xu_for_fields=function(attr_val){const cache_key=typeof attr_val==="string"?`str:${attr_val}`:`obj:${JSON.stringify(attr_val||{})}`;const cached_fields=func.runtime.ui.prog_ui_xu_for_fields_cache.get(cache_key);if(cached_fields){return cached_fields}const fields=new Set;const add_fields=function(values){values?.forEach?.(function(field_id){fields.add(field_id)})};add_fields(func.runtime.ui.extract_expression_refresh_fields({},attr_val,true));add_fields(func.runtime.ui.extract_expression_refresh_fields({},attr_val,false));const result=[...fields].filter(Boolean);func.runtime.ui.prog_ui_xu_for_fields_cache.set(cache_key,result);return result};func.runtime.ui.add_prog_ui_xu_for_dependency=function(index,field_id,entry){if(!field_id){return}if(!index[field_id]){index[field_id]={}}const entry_key=`${entry.parent_node_id||""}::${entry.xu_for_item_id}`;index[field_id][entry_key]=entry};func.runtime.ui.collect_prog_ui_xu_for_dependencies=function(progUi,index={},parent_node_id){if(!Array.isArray(progUi)){return index}for(const item of progUi){if(!xu_isEmpty(item?.attributes)){const attribute_keys=Object.keys(item.attributes);for(let attr_index=0;attr_index<attribute_keys.length;attr_index++){const attr=attribute_keys[attr_index];const val=item.attributes[attr];if(attr!=="xu-exp:xu-for"&&attr!=="xu-for"){continue}const fields=func.runtime.ui.collect_prog_ui_xu_for_fields(val);for(const field_id of fields){func.runtime.ui.add_prog_ui_xu_for_dependency(index,field_id,{parent_node_id:parent_node_id,xu_for_item_id:item.id})}}}if(item?.children){func.runtime.ui.collect_prog_ui_xu_for_dependencies(item.children,index,item.id)}}return index};func.runtime.ui.get_prog_ui_xu_for_dependencies=function(progUi){if(!Array.isArray(progUi)){return{}}let cached_dependencies=func.runtime.ui.prog_ui_xu_for_dependency_cache.get(progUi);if(cached_dependencies){return cached_dependencies}cached_dependencies=func.runtime.ui.collect_prog_ui_xu_for_dependencies(progUi,{});func.runtime.ui.prog_ui_xu_for_dependency_cache.set(progUi,cached_dependencies);return cached_dependencies};func.runtime.ui.merge_prog_ui_xu_for_dependencies=function(target_index,source_index){if(xu_isEmpty(source_index)){return target_index}const field_ids=Object.keys(source_index);for(let field_index=0;field_index<field_ids.length;field_index++){const field_id=field_ids[field_index];const entry_obj=source_index[field_id];if(!target_index[field_id]){target_index[field_id]={}}const entry_keys=Object.keys(entry_obj||{});for(let entry_index=0;entry_index<entry_keys.length;entry_index++){const entry_key=entry_keys[entry_index];const entry=entry_obj[entry_key];target_index[field_id][entry_key]=entry}}return target_index};func.runtime.ui.rebuild_refresh_xu_for_index=async function(SESSION_ID,panels_obj,$xu_embed_container){const state=func.runtime.ui.ensure_refresh_dependency_state(SESSION_ID);if(!state){return{}}const index={};const $embed_container=$xu_embed_container?.length?$xu_embed_container:func.runtime.ui.get_embed_screen_containers();const root_prog_ui=func.runtime.ui.get_data($embed_container)?.xuData?.screenInfo?.progUi;if(root_prog_ui){func.runtime.ui.merge_prog_ui_xu_for_dependencies(index,func.runtime.ui.get_prog_ui_xu_for_dependencies(root_prog_ui))}const resolved_panels_obj=panels_obj||await func.UI.utils.get_panels_wrapper_from_dom(SESSION_ID,$embed_container,true);for(const panel_val of Object.values(resolved_panels_obj||{})){func.runtime.ui.merge_prog_ui_xu_for_dependencies(index,func.runtime.ui.get_prog_ui_xu_for_dependencies(panel_val?.progUi))}state.xu_for_index=index;state.xu_for_dirty=false;return index};func.runtime.ui.collect_refresh_xu_for_entries=async function(options,panels_obj,$xu_embed_container){const state=func.runtime.ui.ensure_refresh_dependency_state(options.SESSION_ID);if(!state){return{entries:[],missing_fields:[...options.fields_arr||[]],panels_obj:panels_obj||{}}}let resolved_panels_obj=panels_obj;if(state.xu_for_dirty){if(!resolved_panels_obj){const $embed_container=$xu_embed_container?.length?$xu_embed_container:func.runtime.ui.get_embed_screen_containers();resolved_panels_obj=await func.UI.utils.get_panels_wrapper_from_dom(options.SESSION_ID,$embed_container,true)}await func.runtime.ui.rebuild_refresh_xu_for_index(options.SESSION_ID,resolved_panels_obj,$xu_embed_container)}const entries={};const missing_fields=[];const fields_arr=options.fields_arr||[];for(let field_index=0;field_index<fields_arr.length;field_index++){const field_id=fields_arr[field_index];const field_entries=state.xu_for_index?.[field_id];if(xu_isEmpty(field_entries)){missing_fields.push(field_id);continue}const entry_keys=Object.keys(field_entries);for(let entry_index=0;entry_index<entry_keys.length;entry_index++){const entry_key=entry_keys[entry_index];const entry=field_entries[entry_key];entries[`${field_id}::${entry_key}`]=entry}}return{entries:Object.values(entries),missing_fields:missing_fields,panels_obj:resolved_panels_obj||{}}};func.runtime.ui.iterate_refresh_field_in_prog_ui=async function(options,progUi,field_id,refreshed_ids=[],panel_val,current_job){const dependencies=func.runtime.ui.get_prog_ui_xu_for_dependencies(progUi);const field_entries=Object.values(dependencies?.[field_id]||{});for(const entry of field_entries){const $elem=func.runtime.ui.get_refresh_indexed_elements_by_node_id(options.SESSION_ID,entry.parent_node_id);if(!$elem?.length){continue}const parent_element_ui_id=func.runtime.ui.get_attr($elem,"xu-ui-id");const refresh_key=parent_element_ui_id&&entry.xu_for_item_id?`${parent_element_ui_id}::${entry.xu_for_item_id}`:parent_element_ui_id;const is_refreshed=refreshed_ids instanceof Set?refreshed_ids.has(refresh_key):refreshed_ids.includes(refresh_key);if(is_refreshed){continue}await func.runtime.ui.queue_xu_for_refresh(options,$elem,entry.xu_for_item_id,current_job,"node execute_xu_for",panel_val);if(refreshed_ids instanceof Set){refreshed_ids.add(refresh_key)}else{refreshed_ids.push(refresh_key)}}return current_job};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.refresh_xu_attributes=async function(options){if(!options.ignore_screen_blocker&&options.trigger!=="click"&&!xu_isEmpty(SCREEN_BLOCKER_OBJ)){setTimeout(()=>{func.runtime.ui.refresh_xu_attributes(options)},100);return}const perf_end=func.runtime?.perf?.start?.(options.SESSION_ID,"refresh_xu_attributes");UI_WORKER_OBJ.cache={};try{let new_job=options.jobNoP;let selectors=func.runtime.ui.collect_refresh_selectors(options);const xu_for_selectors=[];const refreshed_ids=new Set;const selector_keys=Object.keys(selectors);func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_batches");func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_selector_total",selector_keys.length);for(let selector_index=0;selector_index<selector_keys.length;selector_index++){const elem_key=selector_keys[selector_index];const elem_val=selectors[elem_key];if(!elem_val)continue;const $elm=elem_val.$elm;const elm_data=func.runtime.ui.get_data($elm);const xuData=elm_data?.xuData;const xuAttributes=elm_data?.xuAttributes;if(!xuData||xuData.pending_to_delete)continue;const attr_list=elem_val.attributes||[];const has_xu_exp_render=attr_list.includes("xu-exp:xu-render");const has_xu_for=attr_list.includes("xu-exp:xu-for")||attr_list.includes("xu-for");let performed_render;if(!xuAttributes)continue;if(has_xu_exp_render){const res=await func.expression.get(options.SESSION_ID,xuAttributes["xu-exp:xu-render"],xuData.paramsP.dsSessionP,"UI Property EXP",xuData.recordid);const attr_value=await func.common.get_cast_val(options.SESSION_ID,"refresh xu-attributes","xu-render","bool",res.result);const _elm_node=func.runtime.ui.get_first_node($elm);if(!attr_value&&_elm_node?.tagName==="XURENDER")continue;if(attr_value&&_elm_node?.tagName!=="XURENDER"){new_job=await func.runtime.ui.queue_refresh_execute_job(options,elem_key,elem_val,"execute_xu_all_attributes",new_job);continue}new_job=await func.runtime.ui.queue_refresh_render_job(options,elem_key,elem_val,attr_value,options.jobNoP);performed_render=true;func.runtime.ui.mark_refresh_pending_delete($elm)}const _elm_tag_node=func.runtime.ui.get_first_node($elm);if(performed_render||_elm_tag_node?.tagName==="XURENDER")continue;if(has_xu_for){xu_for_selectors.push(elem_val);continue}if(xuData.ui_type==="xu-widget"){new_job=await func.runtime.ui.queue_refresh_execute_job(options,elem_key,elem_val,"execute_xu_widget",new_job)}else{new_job=await func.runtime.ui.queue_refresh_execute_job(options,elem_key,elem_val,"execute_xu_all_attributes",new_job)}}for(let xu_for_index=0;xu_for_index<xu_for_selectors.length;xu_for_index++){const elem_val=xu_for_selectors[xu_for_index];const $elm=elem_val?.$elm;const xuData=func.runtime.ui.get_data($elm)?.xuData;if(!xuData||xuData.pending_to_delete)continue;const parent_element_ui_id=func.runtime.ui.get_refresh_parent_element_ui_id($elm);const xu_for_item_id=func.runtime.ui.resolve_refresh_xu_for_item_id($elm);const refresh_key=parent_element_ui_id&&xu_for_item_id?`${parent_element_ui_id}::${xu_for_item_id}`:parent_element_ui_id;if(!parent_element_ui_id||refreshed_ids.has(refresh_key)){continue}let _$elem=func.runtime.ui.get_refresh_indexed_element_by_ui_id(options.SESSION_ID,parent_element_ui_id);if(_$elem&&!_$elem.length)_$elem=func.runtime.ui._wrap_matches([_$elem]);await func.runtime.ui.queue_xu_for_refresh(options,_$elem,xu_for_item_id,new_job,"execute_xu_for");refreshed_ids.add(refresh_key)}const $xu_embed_container=func.runtime.ui.get_embed_screen_containers();const refresh_state=func.runtime.ui.ensure_refresh_dependency_state(options.SESSION_ID);const preload_panels_obj=refresh_state?.xu_for_dirty?await func.UI.utils.get_panels_wrapper_from_dom(options.SESSION_ID,$xu_embed_container,true):null;let{entries:xu_for_entries,missing_fields,panels_obj}=await func.runtime.ui.collect_refresh_xu_for_entries(options,preload_panels_obj,$xu_embed_container);if(missing_fields.length&&xu_isEmpty(panels_obj)){panels_obj=await func.UI.utils.get_panels_wrapper_from_dom(options.SESSION_ID,$xu_embed_container,true)}for(let entry_index=0;entry_index<xu_for_entries.length;entry_index++){const entry=xu_for_entries[entry_index];const $elem=func.runtime.ui.get_refresh_indexed_elements_by_node_id(options.SESSION_ID,entry.parent_node_id);if(!$elem?.length){continue}const indexed_parent_element_ui_id=func.runtime.ui.get_attr($elem,"xu-ui-id");const indexed_refresh_key=indexed_parent_element_ui_id&&entry.xu_for_item_id?`${indexed_parent_element_ui_id}::${entry.xu_for_item_id}`:indexed_parent_element_ui_id;if(!indexed_parent_element_ui_id||refreshed_ids.has(indexed_refresh_key)){continue}await func.runtime.ui.queue_xu_for_refresh(options,$elem,entry.xu_for_item_id,new_job,"indexed execute_xu_for",entry);refreshed_ids.add(indexed_refresh_key)}func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_xu_for_entries_total",xu_for_entries.length);func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_xu_for_missing_fields_total",missing_fields.length);for(let missing_index=0;missing_index<missing_fields.length;missing_index++){const field_id=missing_fields[missing_index];if($xu_embed_container.length){const progUi=func.runtime.ui.get_data($xu_embed_container)?.xuData?.screenInfo?.progUi;if(progUi){await func.runtime.ui.iterate_refresh_field_in_prog_ui(options,progUi,field_id,refreshed_ids,null,new_job)}}const panel_ids=Object.keys(panels_obj||{});for(let panel_index=0;panel_index<panel_ids.length;panel_index++){const panel_val=panels_obj[panel_ids[panel_index]];await func.runtime.ui.iterate_refresh_field_in_prog_ui(options,panel_val.progUi,field_id,refreshed_ids,panel_val,new_job)}}func.events.delete_job(options.SESSION_ID,options.jobNoP)}finally{perf_end?.()}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.prog_doc_refresh_dependency_cache=func.runtime.ui.prog_doc_refresh_dependency_cache||new WeakMap;func.runtime.ui.panel_refresh_dependency_cache=func.runtime.ui.panel_refresh_dependency_cache||new WeakMap;func.runtime.ui.extract_refresh_fields_from_text=function(text){const fields=new Set;const str=typeof text==="string"?text:JSON.stringify(text||{});if(!str){return fields}for(const match of str.matchAll(/@([A-Za-z0-9_$.-]+)/g)){if(match?.[1]){fields.add(match[1])}}return fields};func.runtime.ui.get_prog_doc_refresh_dependencies=function(prog_doc){if(!prog_doc||typeof prog_doc!=="object"){return{prog_fields:new Set,xu_for_fields:new Set}}let cache=func.runtime.ui.prog_doc_refresh_dependency_cache.get(prog_doc);if(cache){return cache}const prog_fields=new Set;const prog_data_source_str=JSON.stringify(prog_doc.progDataSource||{});for(const match of prog_data_source_str.matchAll(/@([A-Za-z0-9_$.-]+)/g)){if(match?.[1]){prog_fields.add(match[1])}}const xu_for_index=func.UI.utils.get_prog_ui_attribute_index?.(prog_doc.progUi,"xu-for")||{};const xu_for_fields=new Set(Object.keys(xu_for_index));cache={prog_fields:prog_fields,xu_for_fields:xu_for_fields};func.runtime.ui.prog_doc_refresh_dependency_cache.set(prog_doc,cache);return cache};func.runtime.ui.get_panel_refresh_dependencies=function(panelXuAttributes){if(!panelXuAttributes||typeof panelXuAttributes!=="object"){return{program_fields:new Set,parameter_entries:[]}}let cache=func.runtime.ui.panel_refresh_dependency_cache.get(panelXuAttributes);if(cache){return cache}const program_fields=func.runtime.ui.extract_refresh_fields_from_text(panelXuAttributes["xu-exp:program"]);const parameter_entries=[];const panel_attr_keys=Object.keys(panelXuAttributes);for(let attr_index=0;attr_index<panel_attr_keys.length;attr_index++){const attr=panel_attr_keys[attr_index];const value=panelXuAttributes[attr];const match=attr.match(/xu-exp:(\w+)/);if(!match||match[1]==="program"){continue}parameter_entries.push({parameter_in_field_id:match[1],value_str:typeof value==="string"?value:JSON.stringify(value||{})})}cache={program_fields:program_fields,parameter_entries:parameter_entries};func.runtime.ui.panel_refresh_dependency_cache.set(panelXuAttributes,cache);return cache};func.runtime.ui.refresh_screen=async function(options){const perf_end=func.runtime?.perf?.start?.(options.SESSION_ID,"refresh_screen");let found;let refresh_reason;let refresh_details;try{const validate_change=function(prog_doc,panelXuAttributes,skip_ui_check){found=null;refresh_reason=null;refresh_details=null;if(options.watcher?.path?.includes("progDataSource")){found=true;refresh_reason=`progDataSource by watcher ${options.watcher.path}`;refresh_details=options.watcher;return}const refresh_dependencies=func.runtime.ui.get_prog_doc_refresh_dependencies(prog_doc);const _attributes=panelXuAttributes||{};const panel_refresh_dependencies=func.runtime.ui.get_panel_refresh_dependencies(_attributes);for(const field_id of options.fields_changed_arr){found=panel_refresh_dependencies.program_fields.has(field_id);if(found){refresh_reason=`program ${_attributes["xu-exp:program"]} ${field_id} changed `;refresh_details=_attributes;break}for(const parameter_entry of panel_refresh_dependencies.parameter_entries){const parameter_in_field_id=parameter_entry.parameter_in_field_id;if(parameter_entry.value_str?.includes(field_id)){found=refresh_dependencies.prog_fields.has(parameter_in_field_id);if(found){refresh_reason=`field ${field_id} in progDataSource parameter_in changed`;refresh_details=prog_doc?.progDataSource;break}if(!skip_ui_check){found=refresh_dependencies.xu_for_fields.has(parameter_in_field_id);if(found){refresh_reason=`field ${field_id} in progUi xu-for parameter_in changed`;refresh_details=found;break}}}}if(found)break;found=refresh_dependencies.prog_fields.has(field_id);if(found){refresh_reason=`field ${field_id} in progDataSource changed`;refresh_details=prog_doc?.progDataSource;break}if(!skip_ui_check){found=refresh_dependencies.xu_for_fields.has(field_id);if(found){refresh_reason=`field ${field_id} in progUi xu-for changed`;refresh_details=found;break}}if(found){break}}};if(options.fields_changed_datasource){const _session=SESSION_OBJ[options.SESSION_ID];const _ds=_session.DS_GLB[options.fields_changed_datasource];const prog_doc=await func.utils.DOCS_OBJ.get(options.SESSION_ID,_ds.prog_id);if(prog_doc.progUi){validate_change(prog_doc,null,true);if(found){const $elm=func.runtime.ui.find_in_root(options.SESSION_ID,`#container_${_ds.prog_id}_0`);if($elm?.length){const elm_data=func.runtime.ui.get_data($elm);const refreshed_ds=_ds.dsSession;func.runtime.ui.empty($elm);if(func.runtime.ui.get_data($elm)){func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_screen_main_rerenders");await func.runtime.render.render_ui_tree(options.SESSION_ID,$elm,structuredClone(elm_data.xuData.node),{},elm_data.xuData.paramsP,null,null,elm_data.xuData.key,refreshed_ds,elm_data.xuData.parent_node,null,elm_data.xuData.$root_container);if(glb.DEBUG_MODE){console.info("========= refresh main info ==============");console.info("reason:",refresh_reason);console.info("element:",$elm);console.info("==========================================")}return}}}}}const panels_obj=await func.UI.utils.get_panels_wrapper_from_dom(options.SESSION_ID,func.runtime.ui.get_root_element(options.SESSION_ID),false);found=false;const panel_ids=Object.keys(panels_obj||{});for(let panel_index=0;panel_index<panel_ids.length;panel_index++){const panel_val=panels_obj[panel_ids[panel_index]];const panel_data=func.runtime.ui.get_data(panel_val.$panel_div);const panel_xu_data=panel_data?.xuData;if(!panel_xu_data)continue;if(panel_xu_data.pending_to_delete)continue;if(!options.watcher&&options.fields_changed_arr){if(options.fields_changed_datasource&&panel_val._ds.dsSession<=Number(options.fields_changed_datasource)){continue}validate_change(panel_val.prog_doc,panel_val?.panelXuAttributes)}if(options.datasource_changed&&panel_val._ds.dsSession==options.datasource_changed){refresh_reason=`panel datasource ${options.datasource_changed} changed`;refresh_details="";found=true}if(found){UI_WORKER_OBJ.cache={};const _session=SESSION_OBJ[options.SESSION_ID];if(glb.DEBUG_MODE){console.info("========= refresh info ==============");console.info("reason:",refresh_reason);console.info("details:",refresh_details);console.info("panel:",panel_val);console.info("=====================================")}const $div_elm=panel_val.$panel_div;const wrapper_data=panel_data;const get_element_by_ui_id=function(xu_ui_id){if(func.runtime?.ui?.get_refresh_indexed_element_by_ui_id){return func.runtime.ui.get_refresh_indexed_element_by_ui_id(options.SESSION_ID,xu_ui_id)}return func.runtime.ui._wrap_matches(Array.from(document.querySelectorAll(`[xu-ui-id='${xu_ui_id}']`)))};if(xu_isEmpty(wrapper_data))continue;try{func.runtime?.perf?.increment?.(options.SESSION_ID,"refresh_screen_panel_rerenders");const ts=Date.now();for(let id_index=0;id_index<panel_val.ids.length;id_index++){const val=panel_val.ids[id_index];const _matched=get_element_by_ui_id(val);const _arr=_matched?.toArray?_matched.toArray():_matched?[_matched]:[];for(let _mi=0;_mi<_arr.length;_mi++){func.runtime.ui.set_attr(_arr[_mi],"xu-ui-id",val+ts);func.runtime.ui.clear_data(_arr[_mi])}}let refreshed_ds;if(_session.DS_GLB[panel_val._ds.dsSession]){refreshed_ds=panel_val._ds.dsSession}for(let child_index=0;child_index<wrapper_data.xuData.node_org.children.length;child_index++){const item=wrapper_data.xuData.node_org.children[child_index];if(item.tagName!=="xu-panel")continue;await func.runtime.render.render_ui_tree(options.SESSION_ID,$div_elm,structuredClone(item),{},wrapper_data.xuData.paramsP,null,null,wrapper_data.xuData.key,refreshed_ds,wrapper_data.xuData.parent_node,null,wrapper_data.xuData.$root_container)}for(let id_index=0;id_index<panel_val.ids.length;id_index++){const val=panel_val.ids[id_index];func.runtime.ui.remove(get_element_by_ui_id(val+ts))}}catch(error){debugger}}}}finally{perf_end?.()}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.ui.refresh_document_changes_for_realtime_update=async function(SESSION_ID,doc_change){const _session=SESSION_OBJ[SESSION_ID];for(const[key,_ds]of Object.entries(_session.DS_GLB)){const prog_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(prog_obj?.progDataSource?.dataSourceRealtime&&prog_obj?.progDataSource?.dataSourceTableId===doc_change.table_id){try{if(!_ds.screen_params)continue;if(_ds.screen_params.is_panelP){func.runtime.ui.refresh_screen({SESSION_ID:SESSION_ID,fields_changed_arr:null,datasource_changed:key})}else{func.action.execute(SESSION_ID,"act_refresh",_ds,null,null)}}catch(err){}}}if(glb.new_xu_render){for(const[ui_cache_key,ui_cache_val]of Object.entries(UI_WORKER_OBJ.xu_render_cache)){const prog_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,ui_cache_val.paramsP.prog_id);if(prog_obj?.progDataSource?.dataSourceTableId===doc_change.table_id){ui_cache_val.$div=null}}}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.get_screen_context=function(SESSION_ID,$container,paramsP,is_skeleton){const _session=SESSION_OBJ[SESSION_ID];const _ds=is_skeleton?null:_session?.DS_GLB?.[paramsP.dsSessionP];const container_xu_data=func.runtime.ui.get_data($container)?.xuData;const currentRecordId=container_xu_data?.recordid||_ds?.currentRecordId||"";return{_session:_session,_ds:_ds,container_xu_data:container_xu_data,currentRecordId:currentRecordId,is_mobile:glb.MOBILE_ARR.includes(paramsP.screenInfo.properties?.menuType)}};func.runtime.render.get_node_attributes=function(nodeP){try{if(func.runtime.render.is_tree_node?.(nodeP)){return nodeP.attributes}return nodeP?.attributes}catch(error){return undefined}};func.runtime.render.find_existing_element=function(options){const currentRecordId=options.currentRecordId||options.render_context?.currentRecordId;const SESSION_ID=options.SESSION_ID||func.runtime.ui.get_data(options.$container)?.xuData?.SESSION_ID;const is_matching_candidate=function(candidate){if(!candidate)return false;const candidate_data=func.runtime.ui.get_data(candidate);return!candidate_data?.xuData?.is_placeholder&&!candidate_data?.xuData?.xu_for_placeholder&&candidate_data?.xuData?.recordid===currentRecordId&&candidate_data?.xuData?.key===options.keyP&&candidate.tagName!=="XURENDER"};const get_indexed_match=function(){if(!SESSION_ID||!func.runtime.ui.get_refresh_indexed_elements_by_node_id){return null}const indexed_candidates=func.runtime.ui.get_refresh_indexed_elements_by_node_id(SESSION_ID,options.nodeP.id).toArray();for(let index=0;index<indexed_candidates.length;index++){const candidate=indexed_candidates[index];if(candidate.parentElement!==func.runtime.ui.get_first_node(options.$container)){continue}if(is_matching_candidate(candidate)){return func.runtime.ui._wrap_matches([candidate])}}return null};const indexed_match=get_indexed_match();if(indexed_match?.length){return{div:indexed_match,candidates:indexed_match}}let $candidates=func.runtime.ui.find_element_data_in_parent(options.$container,"xuData","nodeid",options.nodeP.id);let $matched=null;const fallback_candidates=$candidates?.toArray?.()||[];for(let index=0;index<fallback_candidates.length;index++){const candidate=fallback_candidates[index];if(is_matching_candidate(candidate)){$matched=func.runtime.ui._wrap_matches([candidate]);break}}return{div:$matched,candidates:$candidates}};func.runtime.render.log_tree_debug=function(options){return func.utils.debug.log(options.SESSION_ID,options.paramsP.prog_id+"_"+options.nodeP.id_org+"_ui_prop",{module:"gui",action:"init",prop:options.nodeP.id,details:options.error_descP,result:null,error:options.is_errorP,source:options._ds?.tree_obj?.menuName||"",fields:null,type:null,prog_id:options.paramsP.prog_id,dsSession:null})};func.runtime.render.create_temp_render_container=function($container){const tmp=document.createElement("tmp");func.runtime.ui.set_data(tmp,"xuData",func.runtime.ui.get_data($container)?.xuData);return tmp};func.runtime.render.insert_ordered_child=function($container,$child,target_key){const children=func.runtime.ui.get_children($container);if(!children.length){return func.runtime.ui.append_to($child,$container)}const normalized_target_key=Number.isFinite(Number(target_key))?Number(target_key):`${target_key}`;for(let index=0;index<children.length;index++){const existing_child=children[index];const existing_key=func.runtime.ui.get_data(existing_child)?.xuData?.key;if(typeof existing_key==="undefined"||existing_key===null){continue}const normalized_existing_key=Number.isFinite(Number(existing_key))?Number(existing_key):`${existing_key}`;if(normalized_existing_key>normalized_target_key){return func.runtime.ui.insert_before($child,existing_child)}}return func.runtime.ui.append_to($child,$container)};func.runtime.render.prepare_draw_context=async function(options){let temp_$div=null;let render_container=options.$container;let $div;if(options.buffered){temp_$div=await func.runtime.ui.create_container({SESSION_ID:options.SESSION_ID,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,treeP:options.treeP,parent_nodeP:options.parent_nodeP,prop:options.prop,div_typeP:options.element,attr_str:options.attr_str||"",is_placeholder:true});render_container=func.runtime.render.create_temp_render_container(options.$container);$div=func.runtime.ui.get_first_node(temp_$div)?.cloneNode(true);const cloned_data=func.runtime.ui.get_data($div);if(cloned_data?.xuData){cloned_data.xuData.is_placeholder=false}}else{$div=await func.runtime.ui.create_container({SESSION_ID:options.SESSION_ID,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,treeP:options.treeP,parent_nodeP:options.parent_nodeP,prop:options.prop,div_typeP:options.element,attr_str:options.attr_str||""})}return{$div:$div,temp_$div:temp_$div,$live_elm:temp_$div||$div,render_container:render_container}};func.runtime.render.run_draw_pipeline=async function(options){if(!options.element||options.element==="script"){return{$div:null,temp_$div:null,render_container:options.$container,ret:{}}}const draw_context=await func.runtime.render.prepare_draw_context(options);const{$div,temp_$div,$live_elm,render_container}=draw_context;func.runtime.render.bind_hover_handlers($div,options.hover_handlers,options.include_hover_click);const ret=await func.runtime.render.set_attributes_new({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:render_container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$elm:$div,$live_elm:$live_elm,is_init:true});if(!func.runtime.render.should_stop_after_attributes(options.nodeP,ret)){await func.runtime.render.process_post_attribute_children({SESSION_ID:options.SESSION_ID,$div:$div,nodeP:options.nodeP,parent_infoP:options.parent_infoP,$root_container:options.$root_container,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,keyP:options.keyP,refreshed_ds:options.refreshed_ds,parent_nodeP:options.parent_nodeP,check_existP:options.check_existP,render_container:render_container,hover_in:options.hover_handlers.hover_in,iterate_child:options.iterate_child,await_children:!options.buffered,defer_when_background:options.buffered,ret:ret})}return{$div:$div,temp_$div:temp_$div,$live_elm:$live_elm,render_container:render_container,ret:ret}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.parent_ds_fields_cache=func.runtime.render.parent_ds_fields_cache||new Map;func.runtime.render.parent_ds_field_names_cache=func.runtime.render.parent_ds_field_names_cache||new Map;func.runtime.render.xu_render_cache_str_cache=func.runtime.render.xu_render_cache_str_cache||new Map;func.runtime.render.xu_render_exclude_fields_cache=func.runtime.render.xu_render_exclude_fields_cache||new WeakMap;func.runtime.render.set_small_cache_entry=function(cache,key,value,max_entries=1e3){if(cache.size>=max_entries&&!cache.has(key)){cache.clear()}cache.set(key,value);return value};func.runtime.render.get_runtime_descendants=function($div){const _div_node=func.runtime.ui.get_first_node($div);if(!_div_node){return[]}return _div_node.querySelectorAll?.("[xu-ui-id]")||[]};func.runtime.render.collect_dependency_fields_from_store=function(dependency_store,dependency_fields){const attr_keys=Object.keys(dependency_store||{});for(let attr_index=0;attr_index<attr_keys.length;attr_index++){const fields=dependency_store[attr_keys[attr_index]]||[];for(let field_index=0;field_index<fields.length;field_index++){dependency_fields.add(fields[field_index])}}return dependency_fields};func.runtime.render.collect_dependency_fields_from_attributes=function(xu_attributes,dependency_fields){const attr_keys=Object.keys(xu_attributes||{});for(let attr_index=0;attr_index<attr_keys.length;attr_index++){const attr_val=xu_attributes[attr_keys[attr_index]];if(typeof attr_val!=="string"){continue}const matches=attr_val.match(/@([A-Za-z0-9_]+)/g)||[];for(let match_index=0;match_index<matches.length;match_index++){dependency_fields.add(matches[match_index].slice(1))}}return dependency_fields};func.runtime.render.build_xu_render_original_data=function(options){return{$container:options.$container,nodeP:func.runtime.ui.get_node_snapshot?func.runtime.ui.get_node_snapshot(options.nodeP):structuredClone(options.nodeP),parent_infoP:options.parent_infoP,paramsP:options.paramsP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$root_container:options.$root_container}};func.runtime.render.attach_xu_render_state=function($xurender,options){func.runtime.ui.set_data($xurender,"xuData",options.xuData);func.runtime.ui.get_data($xurender).xuData.original_data_obj=options.original_data_obj;if(options.xurender_node){func.runtime.ui.get_data($xurender).xuData.xurender_node=options.xurender_node}func.runtime.ui.get_data($xurender).xuAttributes=options.xuAttributes||{};return $xurender};func.runtime.render.create_xu_render_placeholder=function(xu_ui_id,$target,options={}){const $xurender=func.runtime.ui.create_xurender(xu_ui_id,$target,options.hidden);return func.runtime.render.attach_xu_render_state($xurender,options)};func.runtime.render.collect_dependency_fields=function($div){if(!$div?.length){return[]}const dependency_fields=new Set;const descendants=func.runtime.render.get_runtime_descendants($div);for(let index=0;index<descendants.length;index++){const elm_data=func.runtime.ui.get_data(descendants[index]);const dependency_store=elm_data?.xuData?.refresh_dependency_by_attr;if(dependency_store){func.runtime.render.collect_dependency_fields_from_store(dependency_store,dependency_fields);continue}const xu_attributes=elm_data?.xuAttributes;if(!xu_attributes){continue}func.runtime.render.collect_dependency_fields_from_attributes(xu_attributes,dependency_fields)}return[...dependency_fields]};func.runtime.render.cache_xu_render=function(cache_key,value){if(value?.$div&&!value.dependency_fields){value.dependency_fields=func.runtime.render.collect_dependency_fields(value.$div)}UI_WORKER_OBJ.xu_render_cache[cache_key]=value;return UI_WORKER_OBJ.xu_render_cache[cache_key]};func.runtime.render.get_parent_ds_cache_signature=function(SESSION_ID,dsSessionP){var _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dsSessionP];if(!_ds){return`${dsSessionP||""}:`}let signature=`${dsSessionP}:${_ds.currentRecordId||""}`;if(typeof _ds.parentDataSourceNo!=="undefined"){signature+=`|${func.runtime.render.get_parent_ds_cache_signature(SESSION_ID,_ds.parentDataSourceNo)}`}return signature};func.runtime.render.build_parent_ds_fields=function(SESSION_ID,dsSessionP){var _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dsSessionP];if(!_ds){return{}}const idx=func.common.find_ROWID_idx(_ds,_ds.currentRecordId);const data=_ds.data_feed.rows[idx]||{};let obj={};if(typeof _ds.parentDataSourceNo!=="undefined"){obj=func.runtime.render.get_parent_ds_fields(SESSION_ID,_ds.parentDataSourceNo)}return{...data,...obj}};func.runtime.render.get_parent_ds_fields=function(SESSION_ID,dsSessionP){const signature=func.runtime.render.get_parent_ds_cache_signature(SESSION_ID,dsSessionP);const cache_key=`${SESSION_ID}:${signature}`;if(func.runtime.render.parent_ds_fields_cache.has(cache_key)){return func.runtime.render.parent_ds_fields_cache.get(cache_key)}const fields=func.runtime.render.build_parent_ds_fields(SESSION_ID,dsSessionP);return func.runtime.render.set_small_cache_entry(func.runtime.render.parent_ds_fields_cache,cache_key,fields)};func.runtime.render.get_parent_ds_field_names=function(SESSION_ID,dsSessionP){const signature=func.runtime.render.get_parent_ds_cache_signature(SESSION_ID,dsSessionP);const cache_key=`${SESSION_ID}:${signature}`;if(func.runtime.render.parent_ds_field_names_cache.has(cache_key)){return func.runtime.render.parent_ds_field_names_cache.get(cache_key)}const fields=Object.keys(func.runtime.render.get_parent_ds_fields(SESSION_ID,dsSessionP));return func.runtime.render.set_small_cache_entry(func.runtime.render.parent_ds_field_names_cache,cache_key,fields)};func.runtime.render.get_xu_render_exclude_fields=function($elm){const fields_obj=func.runtime.ui.get_data($elm)?.xuData?.attr_exp_info?.["xu-render"]?.fields;if(!fields_obj){return[]}if(func.runtime.render.xu_render_exclude_fields_cache.has(fields_obj)){return func.runtime.render.xu_render_exclude_fields_cache.get(fields_obj)}const fields=Object.keys(fields_obj);func.runtime.render.xu_render_exclude_fields_cache.set(fields_obj,fields);return fields};func.runtime.render.get_xu_render_cache_str=async function(SESSION_ID,dsSessionP,exclude_vars=[]){const exclude_key=[...exclude_vars].sort().join("|");const signature=func.runtime.render.get_parent_ds_cache_signature(SESSION_ID,dsSessionP);const cache_key=`${SESSION_ID}:${signature}:${exclude_key}`;if(func.runtime.render.xu_render_cache_str_cache.has(cache_key)){return func.runtime.render.xu_render_cache_str_cache.get(cache_key)}const fields_obj=func.runtime.render.get_parent_ds_fields(SESSION_ID,dsSessionP);const exclude_vars_set=new Set(exclude_vars);let str="";const field_keys=Object.keys(fields_obj);for(let index=0;index<field_keys.length;index++){const key=field_keys[index];const val=fields_obj[key];if(exclude_vars_set.has(key))continue;str+=typeof val!=="undefined"?JSON.stringify(val):""}const cache_str="C-"+await func.common.sha256(str);return func.runtime.render.set_small_cache_entry(func.runtime.render.xu_render_cache_str_cache,cache_key,cache_str)};func.runtime.render.has_parent_field_dependency=function($div,parent_fields=[],dependency_fields=null){if(!parent_fields?.length){return false}const parent_field_set=new Set(parent_fields);if(dependency_fields?.length){for(let index=0;index<dependency_fields.length;index++){if(parent_field_set.has(dependency_fields[index])){return true}}return false}if(!$div?.length){return false}const descendants=func.runtime.render.get_runtime_descendants($div);for(let index=0;index<descendants.length;index++){const elm_data=func.runtime.ui.get_data(descendants[index]);const dependency_store=elm_data?.xuData?.refresh_dependency_by_attr;if(dependency_store){const attr_keys=Object.keys(dependency_store);for(let attr_index=0;attr_index<attr_keys.length;attr_index++){const fields=dependency_store[attr_keys[attr_index]]||[];for(let field_index=0;field_index<fields.length;field_index++){if(parent_field_set.has(fields[field_index])){return true}}}continue}const xu_attributes=elm_data?.xuAttributes;if(!xu_attributes){continue}const attr_keys=Object.keys(xu_attributes);for(let attr_index=0;attr_index<attr_keys.length;attr_index++){const attr_val=xu_attributes[attr_keys[attr_index]];if(typeof attr_val!=="string"){continue}for(let field_index=0;field_index<parent_fields.length;field_index++){if(attr_val.includes("@"+parent_fields[field_index])){return true}}}}return false};func.runtime.render.finalize_buffered_draw=async function(options){const xu_ui_id=func.runtime.ui.get_attr(options.$div,"xu-ui-id");if(options.ret.has_xu_exp_render_attribute){const exclude_fields=func.runtime.render.get_xu_render_exclude_fields(options.$div);const xu_render_cache_id=await func.runtime.render.get_xu_render_cache_str(options.SESSION_ID,options.paramsP.dsSessionP,exclude_fields);const _$div=func.runtime.ui.get_first_node(options.$div)?.cloneNode(true);func.runtime.render.cache_xu_render(xu_ui_id+xu_render_cache_id,{$div:_$div,paramsP:options.paramsP,data:func.runtime.ui.get_data(_$div)});options.nodeP.xu_render_xu_ui_id=xu_ui_id;options.nodeP.xu_render_cache_id=xu_render_cache_id}return func.runtime.render.finalize_temp_draw(options.temp_$div,options.$div,options.ret)};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.viewport_observers=func.runtime.render.viewport_observers||null;func.runtime.render.style_tag_cache=func.runtime.render.style_tag_cache||new Set;func.runtime.render.finalize_temp_draw=function(temp_$div,$div,ret={}){func.runtime.ui.remove_class($div,"display_none");if(ret.consume_placeholder){func.runtime.ui.remove(temp_$div);return $div}if(ret.xu_render_background_processing||ret.has_xu_render_attribute){func.runtime.ui.remove(temp_$div);return $div}func.runtime.ui.replace_with(temp_$div,$div);return $div};func.runtime.render.get_viewport_observers=function(){if(func.runtime.render.viewport_observers){return func.runtime.render.viewport_observers}const observer_inViewport=new IntersectionObserver(function(entries){entries.forEach(entry=>{if(entry.isIntersecting){entry.target.dispatchEvent(new CustomEvent("inViewport"));observer_inViewport.unobserve(entry.target)}})},{threshold:.1});const observer_outViewport=new IntersectionObserver(function(entries){entries.forEach(entry=>{if(!entry.isIntersecting){entry.target.dispatchEvent(new CustomEvent("outViewport"))}})},{threshold:0});func.runtime.render.viewport_observers={observer_inViewport:observer_inViewport,observer_outViewport:observer_outViewport};return func.runtime.render.viewport_observers};func.runtime.render.bind_viewport_render=function($div,handlers){const{observer_inViewport,observer_outViewport}=func.runtime.render.get_viewport_observers();const div_node=func.runtime.ui.get_first_node($div);let ui_job_id;if(div_node._xuda_inViewportHandler){div_node.removeEventListener("inViewport",div_node._xuda_inViewportHandler)}div_node._xuda_inViewportHandler=function(){ui_job_id=handlers.onEnter({observer_outViewport:observer_outViewport})};div_node.addEventListener("inViewport",div_node._xuda_inViewportHandler);if(div_node._xuda_outViewportHandler){div_node.removeEventListener("outViewport",div_node._xuda_outViewportHandler)}div_node._xuda_outViewportHandler=function(){handlers.onExit({observer_inViewport:observer_inViewport,ui_job_id:ui_job_id})};div_node.addEventListener("outViewport",div_node._xuda_outViewportHandler);func.runtime.ui.add_class($div,"skeleton");observer_inViewport.observe(div_node);return $div};func.runtime.render.has_terminal_content_attributes=function(nodeP){return!xu_isEmpty(nodeP?.attributes?.["xu-text"])||!xu_isEmpty(nodeP?.attributes?.["xu-html"])||!xu_isEmpty(nodeP?.attributes?.["xu-exp:xu-text"])||!xu_isEmpty(nodeP?.attributes?.["xu-exp:xu-html"])};func.runtime.render.should_stop_after_attributes=function(nodeP,ret={}){return!!(ret.abort||nodeP.tagName==="svg"||func.runtime.render.has_terminal_content_attributes(nodeP))};func.runtime.render.should_use_viewport_render=function(nodeP){return nodeP?.attributes?.["xu-viewport"]=="true"};func.runtime.render.bind_draw_viewport=function(options){const div_node=func.runtime.ui.get_first_node(options.$div);func.runtime.render.bind_viewport_render(options.$div,{onEnter:({observer_outViewport})=>{if(div_node?.childElementCount){func.runtime.ui.remove_class(options.$div,"skeleton");return null}options.hover_in(options.$div);const ui_job_id=func.UI.worker.add_to_queue(options.SESSION_ID,"gui event","render_viewport",{$div:options.$div,nodeP:options.nodeP,parent_infoP:options.parent_infoP,$root_container:options.$root_container,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,keyP:options.keyP,refreshed_ds:options.refreshed_ds,parent_nodeP:options.parent_nodeP,check_existP:options.check_existP,$container:options.render_container},null,null,options.paramsP.dsSessionP);observer_outViewport.observe(div_node);return ui_job_id},onExit:({observer_inViewport,ui_job_id})=>{func.UI.worker.delete_job(options.SESSION_ID,ui_job_id);if(div_node?.childElementCount){func.runtime.ui.empty(options.$div);const height=func.runtime.ui.get_data(options.$div)?.xuData?.viewport_height||10;if(typeof height!=="undefined"){func.runtime.ui.set_style(options.$div,"height",`${height}px`)}}observer_inViewport.observe(div_node)}});return options.$div};func.runtime.render.process_post_attribute_children=async function(options){if(func.runtime.render.should_use_viewport_render(options.nodeP)){return func.runtime.render.bind_draw_viewport(options)}if(options.defer_when_background&&options.ret?.xu_render_background_processing){return options.$div}if(options.await_children){await options.iterate_child(options.$div,options.nodeP,options.parent_infoP,options.$root_container);return options.$div}options.iterate_child(options.$div,options.nodeP,options.parent_infoP,options.$root_container);return options.$div};func.runtime.render.append_style_tag=function(cssText){if(!cssText||func.runtime.render.style_tag_cache.has(cssText)){return false}func.runtime.render.style_tag_cache.add(cssText);const style_node=document.createElement("style");style_node.textContent=cssText;document.head.appendChild(style_node);return true};func.runtime.render.scope_css_to_xu_ui=function($elm,cssText){var parser=new cssjs;var parsed=parser.parseCSS(cssText);var xuUiId=`[xu-ui-id="${func.runtime.ui.get_attr($elm,"xu-ui-id")}"]`;for(var key=0;key<parsed.length;key++){var val=parsed[key];var selectors_arr=val.selector.split(",");for(var key2=0;key2<selectors_arr.length;key2++){selectors_arr[key2]=`${xuUiId} ${selectors_arr[key2]}, ${xuUiId}${selectors_arr[key2]}`}val.selector=selectors_arr.join(",")}return parser.getCSSForEditor(parsed)};func.runtime.render.bind_xu_event=function(options){const decode_html_entities=function(value){if(typeof value!=="string"||value.indexOf("&")===-1){return value}if(typeof document!=="undefined"){const textarea=document.createElement("textarea");textarea.innerHTML=value;return textarea.value}return value.replaceAll("&quot;",'"').replaceAll("&#34;",'"').replaceAll("&#39;","'").replaceAll("&#039;","'").replaceAll("&lt;","<").replaceAll("&gt;",">").replaceAll("&amp;","&")};const normalize_event_handlers=function(raw_handlers){if(typeof raw_handlers!=="string"){return raw_handlers}const decoded_value=decode_html_entities(raw_handlers).trim();if(!decoded_value){return[]}try{return JSON5.parse(decoded_value)}catch(error){console.error("XUDA RUNTIME",`xu-on has invalid workflow syntax: ${decoded_value}`,error);return[]}};CLIENT_ACTIVITY_TS=Date.now();const trigger=options.val.key.split("xu-on:")[1].toLowerCase();const handler_key=`_xuda_xuOn_${trigger.replace(/[^a-z0-9_]/gi,"_")}`;const elm_node=func.runtime.ui.get_first_node(options.$elm);if(elm_node[handler_key]){elm_node.removeEventListener(trigger,elm_node[handler_key])}elm_node[handler_key]=async function(evt){const _$elm=evt.currentTarget;const elm_data=func.runtime.ui.get_data(_$elm);const xuAttributes=elm_data?.xuAttributes;const event_attr_key="xu-on:"+evt.type;const event_handlers=normalize_event_handlers(xuAttributes?.[event_attr_key]);if(xuAttributes&&event_handlers!==xuAttributes?.[event_attr_key]){xuAttributes[event_attr_key]=event_handlers}if(xu_isEmpty(xuAttributes)||xu_isEmpty(event_handlers))return;const handler_keys=Object.keys(event_handlers);for(let handler_index=0;handler_index<handler_keys.length;handler_index++){const val=event_handlers[handler_keys[handler_index]];const handler_props=val?.props||{};if(!xu_isEmpty(handler_props.condition)){const expCond=await func.expression.get(options.SESSION_ID,handler_props.condition,options.paramsP.dsSessionP,"condition",options.paramsP.recordid);if(!expCond.result)continue}if(val?.event_modifiers&&evt[val.event_modifiers]){evt[val.event_modifiers]()}const workflow=val?.workflow||val?.event;if(workflow){const workflow_keys=Object.keys(workflow);for(let workflow_index=0;workflow_index<workflow_keys.length;workflow_index++){const val2=workflow[workflow_keys[workflow_index]];if(!val2?.data?.action)continue;if(val2.data.enabled===false)continue;func.events.add_to_queue(options.SESSION_ID,"element event",val2.id,evt.type,val2.data.action,val2.data.name,null,func.runtime.ui.get_attr(_$elm,"xu-ui-id"),null,evt,null,null,null,options.paramsP.dsSessionP,null,null,null,evt.type,val2.data.name,null,null,val2,null,null,null,null,null,null)}}}};elm_node.addEventListener(trigger,elm_node[handler_key]);return options.$elm};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.should_bind_hover_click=function(paramsP,parent_infoP){return paramsP.paramsP==="grid"||!!parent_infoP?.iterate_info};func.runtime.render.create_hover_handlers=function(options){return{hover_in:function($div,e){return func.runtime.render.handle_hover_in({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,e:e,$div:$div,$container:options.$container,_ds:options._ds,paramsP:options.paramsP})},hover_out:function(){return func.runtime.render.handle_hover_out({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$container:options.$container,_ds:options._ds})}}};func.runtime.render.bind_hover_handlers=function($div,handlers,include_click){const el=func.runtime.ui.get_first_node($div);if(!el)return $div;el.addEventListener("mouseenter",function(e){handlers.hover_in($div,e)});el.addEventListener("mouseleave",function(){handlers.hover_out()});if(include_click){el.addEventListener("click",function(e){handlers.hover_in($div,e)});el.addEventListener("contextmenu",function(e){handlers.hover_in($div,e)})}return $div};func.runtime.render.resolve_debug_element=function($elm){try{const el=func.runtime.ui.get_first_node($elm);const id=el?.getAttribute?.("xu-ui-id");if(!id||!glb.DEBUG_MODE){return $elm}const matches=document.querySelectorAll(`[xu-ui-id="${id}"]`);if(matches.length>1){console.warn("Multiple elements for xu-ui-id: "+id,matches)}return matches[0]||$elm}catch(e){console.error(e);return $elm}};func.runtime.render.set_hover_item=function($container,$target){const resolved_container=func.runtime.render.resolve_debug_element($container);const resolved_data=func.runtime.ui.get_data(resolved_container);if(!resolved_data?.xuData?.debug_info){return false}const target_el=func.runtime.ui.get_first_node($target);resolved_data.xuData.debug_info.hover_item=target_el?.getAttribute?.("xu-ui-id")||null;return true};func.runtime.render.get_element_attributes=function($div){let attributes={};const el=func.runtime.ui.get_first_node($div);const attrs=el?.attributes||[];for(let index=0;index<attrs.length;index++){const attr=attrs[index];attributes[attr.name]=attr.value}return attributes};func.runtime.render.set_hovered_attributes=function(SESSION_ID,attributes){const root_data_system=func.runtime.render.get_root_data_system(SESSION_ID);if(!root_data_system){return false}root_data_system.SYS_OBJ_WIN_ELEMENT_HOVERED_ATTRIBUTES=attributes;return true};func.runtime.render.clear_hovered_attributes=function(SESSION_ID){return func.runtime.render.set_hovered_attributes(SESSION_ID,{})};func.runtime.render.queue_datasource_update=function(SESSION_ID,dsSessionP,currentRecordId,field_id,field_value){const payload={currentRecordId:currentRecordId};if(typeof field_id!=="undefined"){payload.field_id=field_id;payload.field_value=field_value}func.UI.worker.add_to_queue(SESSION_ID,"gui event","update_datasource",payload,null,null,dsSessionP);return payload};func.runtime.render.queue_hover_updates=function(options){const resolved_div=func.runtime.render.resolve_debug_element(options.$div);const resolved_data=func.runtime.ui.get_data(resolved_div);const currentRecordId=resolved_data?.xuData?.currentRecordId;if(options.$div&&resolved_div&&options._ds&&options.paramsP.renderType==="grid"&&currentRecordId){func.runtime.render.queue_datasource_update(options.SESSION_ID,options.paramsP.dsSessionP,currentRecordId)}const div_data=func.runtime.ui.get_data(options.$div);const iterate_info=div_data?.xuData?.iterate_info||div_data?.iterate_info;if(!iterate_info||!currentRecordId){return false}if(iterate_info.iterator_key){func.runtime.render.queue_datasource_update(options.SESSION_ID,options.paramsP.dsSessionP,currentRecordId,iterate_info.iterator_key,iterate_info._key)}if(iterate_info.iterator_val){func.runtime.render.queue_datasource_update(options.SESSION_ID,options.paramsP.dsSessionP,currentRecordId,iterate_info.iterator_val,iterate_info._val)}return true};func.runtime.render.handle_hover_in=function(options){if(options.is_skeleton||options.e&&(EXP_BUSY||UI_WORKER_OBJ.active_jobs_count)){return false}CLIENT_ACTIVITY_TS=Date.now();const $target=options.$div||options.$container;func.runtime.render.set_hover_item(options.$container,$target);if(!options._ds){return true}func.runtime.render.set_hovered_attributes(options.SESSION_ID,func.runtime.render.get_element_attributes($target));const target_data=func.runtime.ui.get_data($target);if(!target_data?.xuData){return true}const iterate_info=target_data.xuData.iterate_info;func.runtime.render.sync_iterate_info_to_dataset(options._ds,iterate_info);func.runtime.render.queue_hover_updates({SESSION_ID:options.SESSION_ID,paramsP:options.paramsP,$div:$target,_ds:options._ds});return true};func.runtime.render.handle_hover_out=function(options){if(options.is_skeleton){return false}CLIENT_ACTIVITY_TS=Date.now();func.runtime.render.set_hover_item(options.$container,null);if(options._ds?.data_system){func.runtime.render.clear_hovered_attributes(options.SESSION_ID);return true}return false};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.widgets.render_node=async function(options){const exist_elm_obj=func.runtime.render.find_existing_element({$container:options.$container,nodeP:options.nodeP,keyP:options.keyP,render_context:options.render_context});let $div=exist_elm_obj.div;if(!$div){$div=await func.runtime.ui.create_container({SESSION_ID:options.SESSION_ID,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,treeP:options.treeP,parent_nodeP:options.parent_nodeP,prop:options.prop,classP:"widget_wrapper"});if(func.runtime.render.is_hydration_mode(SESSION_OBJ?.[options.SESSION_ID])&&func.runtime.render.should_use_ssr_payload(options.SESSION_ID,options.paramsP)){func.runtime.ui.empty($div)}const widget_context=func.runtime.widgets.create_context(options.SESSION_ID,options.paramsP,options.prop);const{plugin_name,method,propsP,plugin:_plugin}=widget_context;const report_error=function(descP,warn){return func.runtime.widgets.report_error(widget_context,descP,warn)};const definition=await func.runtime.widgets.get_definition(widget_context);if(!func.runtime.widgets.supports_current_environment(definition)){return report_error(`plugin ${plugin_name} is not available in the current environment`,true)}const methods=definition?.methods||{};if(methods&&!methods[method]){return report_error("method not found")}const fields_ret=await func.runtime.widgets.get_fields_data(widget_context,methods[method].fields,propsP);if(fields_ret.code<0){return report_error(fields_ret.data)}const fields=fields_ret.data;let exclude_attributes=[];const prop_keys=Object.keys(propsP||{});for(let prop_index=0;prop_index<prop_keys.length;prop_index++){const key=prop_keys[prop_index];if(typeof fields[key]!=="undefined"||typeof fields[`xu-exp:${key}`]!=="undefined"){exclude_attributes.push(key)}}await func.runtime.render.set_attributes_new({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$elm:$div,is_init:true,execute_attributes:exclude_attributes});func.runtime.ui.add_class($div,"widget_wrapper");if(!_plugin){return report_error(`plugin ${plugin_name} not found`)}if(_plugin.manifest["style.css"].exist){func.runtime.widgets.load_css_style(widget_context)}const plugin_setup_ret=await func.utils.get_plugin_setup(options.SESSION_ID,plugin_name);if(plugin_setup_ret.code<0){return report_error(plugin_setup_ret)}const api_utils=await func.common.get_module(options.SESSION_ID,"xuda-api-library.mjs",{func:func,glb:glb,SESSION_OBJ:SESSION_OBJ,SESSION_ID:options.SESSION_ID,APP_OBJ:APP_OBJ,dsSession:options.paramsP.dsSessionP,job_id:options.jobNoP});const params=func.runtime.widgets.build_params(widget_context,func.runtime.ui.get_first_node($div),func.runtime.ui.get_data($div),plugin_setup_ret.data,api_utils);const fx=await func.runtime.widgets.get_resource(widget_context,"runtime.mjs");await func.runtime.widgets.load_runtime_css(widget_context);if(!fx[method]){throw`Method: ${method} does not exist`}try{await fx[method](fields,params)}catch(err){func.utils.debug_report(options.SESSION_ID,`${plugin_name} widget`,err.message,"E")}}return $div};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};const normalize_runtime_tag_name=function(tag_name){return`${tag_name||""}`.trim().toLowerCase()};const get_runtime_node_attributes=function(nodeP){if(!nodeP?.attributes||typeof nodeP.attributes!=="object"){return{}}return nodeP.attributes};const get_runtime_node_content=function(nodeP){if(typeof nodeP?.content==="string"){return nodeP.content}if(typeof nodeP?.text==="string"){return nodeP.text}if(!Array.isArray(nodeP?.children)){return""}return nodeP.children.map(function(child){if(typeof child==="string"){return child}if(typeof child?.content==="string"){return child.content}if(typeof child?.text==="string"){return child.text}return""}).join("")};const get_runtime_asset_key=function(options,tag_name){const source_node=options.treeP||options.nodeP||{};const parts=["xuda-html-asset",options.paramsP?.prog_id||"",tag_name,source_node.id||source_node.id_org||"",typeof options.keyP==="undefined"||options.keyP===null?"":`${options.keyP}`].filter(function(part){return`${part||""}`.trim()!==""});return parts.join(":")};const get_runtime_asset_signature=function(attributes,content){const normalized_attributes={};const attr_keys=Object.keys(attributes||{}).sort();for(let index=0;index<attr_keys.length;index++){const key=attr_keys[index];normalized_attributes[key]=attributes[key]}return JSON.stringify({attributes:normalized_attributes,content:`${content||""}`})};const escape_runtime_asset_selector_value=function(value){const win=func.runtime.platform.get_window?.();if(win?.CSS?.escape){return win.CSS.escape(value)}return`${value||""}`.replace(/\\/g,"\\\\").replace(/"/g,'\\"')};const find_runtime_head_asset=function(head,tag_name,asset_key){if(!head?.querySelector||!asset_key){return null}return head.querySelector(`${tag_name}[data-xuda-asset-key="${escape_runtime_asset_selector_value(asset_key)}"]`)};const find_runtime_head_asset_by_attr=function(head,tag_name,attr_name,attr_value){if(!head?.querySelectorAll||!attr_name||!attr_value){return null}const candidates=Array.from(head.querySelectorAll(tag_name));return candidates.find(function(candidate){return candidate.getAttribute(attr_name)===attr_value||candidate[attr_name]===attr_value})||null};const wait_for_runtime_asset_load=function(node){if(!node?.addEventListener){return Promise.resolve(node)}if(node.getAttribute?.("data-xuda-loaded")==="true"){return Promise.resolve(node)}if(!node.getAttribute?.("data-xuda-asset-key")){return Promise.resolve(node)}const tag_name=normalize_runtime_tag_name(node.tagName);if(tag_name!=="script"&&!(tag_name==="link"&&normalize_runtime_tag_name(node.getAttribute?.("rel"))==="stylesheet")){return Promise.resolve(node)}return new Promise(function(resolve){const done=function(){node.setAttribute?.("data-xuda-loaded","true");resolve(node)};node.addEventListener("load",done,{once:true});node.addEventListener("error",done,{once:true})})};const is_runtime_tailwind_script_src=function(src){const normalized_src=`${src||""}`.trim().toLowerCase();if(!normalized_src){return false}return normalized_src.includes("cdn.tailwindcss.com")||/(?:^|\/)tailwind\.cdn\.js(?:[?#].*)?$/.test(normalized_src)};const is_runtime_tailwind_config_script=function(content){return/(?:^|[^\w.])tailwind\.config\s*=/.test(`${content||""}`)};const has_runtime_tailwind=function(){const win=func.runtime.platform.get_window?.();return!!win?.tailwind};const refresh_runtime_tailwind=async function(){const win=func.runtime.platform.get_window?.();const refresh=win?.tailwind?.refresh;if(typeof refresh!=="function"){return false}try{await refresh();return true}catch(error){console.error(error);return false}};const remove_runtime_head_asset=function(node){if(node?.parentNode?.removeChild){node.parentNode.removeChild(node)}};const apply_runtime_asset_metadata=function(node,asset_key,signature){if(!node?.setAttribute){return node}if(asset_key){node.setAttribute("data-xuda-asset-key",asset_key)}node.setAttribute("data-xuda-asset-signature",signature);return node};const create_runtime_head_element=function(doc,tag_name,attributes,asset_key,signature){const node=doc.createElement(tag_name);apply_runtime_asset_metadata(node,asset_key,signature);func.runtime.platform.apply_element_attributes(node,attributes);return node};const get_runtime_html_script_queue=function(){return func.runtime.render._html_script_queue||(func.runtime.render._html_script_queue={items:[],running:false})};const queue_runtime_html_script_task=function(task){const queue=get_runtime_html_script_queue();queue.items.push(task)};func.runtime.render.flush_html_script_queue=async function(){const queue=get_runtime_html_script_queue();if(queue.running||!queue.items.length){return}queue.running=true;try{while(queue.items.length){const next_task=queue.items.shift();await next_task()}}catch(error){console.error(error)}finally{queue.running=false}};const upsert_runtime_head_element=async function(options){const doc=func.runtime.platform.get_document?.();const head=doc?.head;const tag_name=normalize_runtime_tag_name(options.tag_name);if(!doc?.createElement||!head?.appendChild||!tag_name){return null}const asset_key=options.asset_key||"";const signature=options.signature||"";const attributes=options.attributes||{};const content=typeof options.content==="string"?options.content:"";const existing_by_key=find_runtime_head_asset(head,tag_name,asset_key);if(existing_by_key&&existing_by_key.getAttribute("data-xuda-asset-signature")===signature){return options.await_load?await wait_for_runtime_asset_load(existing_by_key):existing_by_key}if(existing_by_key){remove_runtime_head_asset(existing_by_key)}if(options.find_existing_attr?.name&&options.find_existing_attr?.value){const existing_by_attr=find_runtime_head_asset_by_attr(head,tag_name,options.find_existing_attr.name,options.find_existing_attr.value);if(existing_by_attr){apply_runtime_asset_metadata(existing_by_attr,asset_key,signature);existing_by_attr.setAttribute?.("data-xuda-loaded","true");return existing_by_attr}}const node=create_runtime_head_element(doc,tag_name,attributes,asset_key,signature);if(tag_name==="script"&&attributes.src&&!Object.prototype.hasOwnProperty.call(attributes,"async")){const script_type=normalize_runtime_tag_name(attributes.type);if(script_type!=="module"){node.async=false}}if(tag_name==="style"||tag_name==="script"&&!attributes.src){node.textContent=content}head.appendChild(node);if(tag_name!=="script"&&tag_name!=="link"){node.setAttribute("data-xuda-loaded","true")}return options.await_load?await wait_for_runtime_asset_load(node):node};const render_runtime_html_asset=async function(options){if(options.is_skeleton){return options.$container}const nodeP=options.treeP||options.nodeP||{};const tag_name=normalize_runtime_tag_name(nodeP.tagName);const attributes={...get_runtime_node_attributes(nodeP)};const content=get_runtime_node_content(nodeP);const asset_key=get_runtime_asset_key(options,tag_name);const signature=get_runtime_asset_signature(attributes,content);switch(tag_name){case"title":func.runtime.platform.set_title(content);return options.$container;case"style":await upsert_runtime_head_element({tag_name:tag_name,attributes:attributes,content:content,asset_key:asset_key,signature:signature});return options.$container;case"meta":if(!Object.keys(attributes).length){return options.$container}await upsert_runtime_head_element({tag_name:tag_name,attributes:attributes,asset_key:asset_key,signature:signature});return options.$container;case"link":{const href=`${attributes.href||""}`.trim();if(!href){return options.$container}await upsert_runtime_head_element({tag_name:tag_name,attributes:attributes,asset_key:asset_key,signature:signature,find_existing_attr:{name:"href",value:href},await_load:normalize_runtime_tag_name(attributes.rel)==="stylesheet"});return options.$container}case"script":{const src=`${attributes.src||""}`.trim();const is_tailwind_script=is_runtime_tailwind_script_src(src);const is_tailwind_config_script=is_runtime_tailwind_config_script(content);if(!src&&!content.trim()){return options.$container}queue_runtime_html_script_task(async function(){if(src&&is_tailwind_script&&has_runtime_tailwind()){return}await upsert_runtime_head_element({tag_name:tag_name,attributes:attributes,content:content,asset_key:asset_key,signature:signature,find_existing_attr:src?{name:"src",value:src}:null,await_load:!!src});if(is_tailwind_config_script){await refresh_runtime_tailwind()}});return options.$container}default:return null}};func.runtime.render.render_special_node=async function(options){const treeP=options.treeP||null;const nodeP=options.nodeP||func.runtime.render.get_tree_source_node(treeP);const render_tag_name=treeP?.tagName||nodeP?.tagName;const normalized_render_tag_name=normalize_runtime_tag_name(render_tag_name);const is_native_html_asset=["title","style","meta","link","script"].includes(normalized_render_tag_name);if(!is_native_html_asset&&treeP?.content&&nodeP?.attributes){nodeP.attributes["xu-content"]=treeP.content}else if(!is_native_html_asset&&nodeP?.content&&nodeP.attributes){nodeP.attributes["xu-content"]=nodeP.content}const renderers={"xu-widget":async function(){if(options.is_skeleton)return;return await func.runtime.widgets.render_node({SESSION_ID:options.SESSION_ID,$container:options.$container,$root_container:options.$root_container,treeP:treeP,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,keyP:options.keyP,parent_nodeP:options.parent_nodeP,prop:options.prop,render_context:options.render_context})},"xu-single-view":async function(){return await func.runtime.ui.render_single_view_node({SESSION_ID:options.SESSION_ID,$container:options.$container,$root_container:options.$root_container,treeP:treeP,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,keyP:options.keyP,parent_nodeP:options.parent_nodeP,prop:options.prop,render_context:options.render_context,hover_handlers:options.hover_handlers,iterate_child:options.iterate_child,close_modal:options.close_modal})},"xu-multi-view":async function(){return await func.runtime.ui.render_multi_view_node({SESSION_ID:options.SESSION_ID,$container:options.$container,$root_container:options.$root_container,treeP:treeP,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,keyP:options.keyP,parent_nodeP:options.parent_nodeP,iterate_child:options.iterate_child,close_modal:options.close_modal})},"xu-panel":async function(){return await func.runtime.ui.render_panel_node({SESSION_ID:options.SESSION_ID,$container:options.$container,$root_container:options.$root_container,treeP:treeP,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,keyP:options.keyP,parent_nodeP:options.parent_nodeP,prop:options.prop,refreshed_ds:options.refreshed_ds})},title:async function(){return await render_runtime_html_asset(options)},style:async function(){return await render_runtime_html_asset(options)},meta:async function(){return await render_runtime_html_asset(options)},link:async function(){return await render_runtime_html_asset(options)},script:async function(){return await render_runtime_html_asset(options)}};const renderer=renderers[normalized_render_tag_name];if(!renderer){return{handled:false}}return{handled:true,result:await renderer()}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.get_xu_for_iterators=function($elm){const elm_data=func.runtime.ui.get_data($elm);const custom_iterator_key=elm_data.xuData.iterator_key;const custom_iterator_val=elm_data.xuData.iterator_val;return{iterator_key:custom_iterator_key||"_FOR_KEY",iterator_val:custom_iterator_val||"_FOR_VAL",is_key_dynamic_field:true,is_val_dynamic_field:true}};func.runtime.render.attach_iterate_info_to_children=function($divP,iterate_info){const el=func.runtime.ui.get_first_node($divP);const children=el?.children?Array.from(el.children):[];for(let index=0;index<children.length;index++){const child_data=func.runtime.ui.get_data(children[index]);if(child_data?.xuData){child_data.xuData.iterate_info=iterate_info}}return $divP};func.runtime.render.can_iterate_children=function(nodeP,is_mobile){if(!nodeP){return false}if(!is_mobile&&nodeP.busy){return false}return true};func.runtime.render.mark_node_busy=function(nodeP){if(!nodeP){return false}nodeP.busy=true;return true};func.runtime.render.release_node_busy=function(nodeP,delay=1e3){if(!nodeP){return false}setTimeout(function(){nodeP.busy=false},delay);return true};func.runtime.render.render_child_nodes=async function(options){if(!options.nodeP?.children){return options.$divP}if(options.before_record_function){await options.before_record_function()}if(options.nodeP.children.length){const render_tasks=new Array(options.nodeP.children.length);for(let index=0;index<options.nodeP.children.length;index++){const child=options.nodeP.children[index];render_tasks[index]=options.render_child(index,child)}await Promise.all(render_tasks)}return options.$divP};func.runtime.render.iterate_children=async function(options){if(!func.runtime.render.can_iterate_children(options.nodeP,options.is_mobile))return;func.runtime.render.mark_node_busy(options.nodeP);const done=async function($divP){func.runtime.render.release_node_busy(options.nodeP);return $divP};if(!options.nodeP||!options.nodeP.children){return await done(options.$divP)}await func.runtime.render.render_child_nodes({$divP:options.$divP,nodeP:options.nodeP,before_record_function:options.before_record_function,render_child:options.render_child});return await done(options.$divP)};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.create_tree_runtime=function(options){const render_node=options.nodeP||func.runtime.render.get_tree_source_node(options.treeP);const render_context=func.runtime.render.get_screen_context(options.SESSION_ID,options.$container,options.paramsP,options.is_skeleton);const prop=func.runtime.render.get_node_attributes(options.treeP||render_node);const is_mobile=render_context.is_mobile?true:false;const hover_handlers=func.runtime.render.create_hover_handlers({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$container:options.$container,_ds:render_context._ds,paramsP:options.paramsP});const include_hover_click=func.runtime.render.should_bind_hover_click(options.paramsP,options.parent_infoP);const close_modal=async function(modal_id){return await func.runtime.ui.close_modal_session(options.SESSION_ID,modal_id)};const iterate_child=async function($divP,nodeP,parent_infoP,$root_container,before_record_function){const child_tree=await func.runtime.render.ensure_tree_node({SESSION_ID:options.SESSION_ID,nodeP:nodeP||options.treeP||render_node,parent_infoP:parent_infoP,paramsP:options.paramsP,keyP:options.keyP,parent_nodeP:render_node,pathP:options.treeP?.meta?.path||[]});return await func.runtime.render.iterate_children({$divP:$divP,nodeP:child_tree,is_mobile:is_mobile,before_record_function:before_record_function,render_child:async function(key,child){await options.render_child($divP,child,parent_infoP,key,render_node,$root_container)}})};return{render_context:render_context,prop:prop,is_mobile:is_mobile,hover_handlers:hover_handlers,include_hover_click:include_hover_click,close_modal:close_modal,iterate_child:iterate_child}};func.runtime.render.draw_node=async function(options){const draw_ret=await func.runtime.render.run_draw_pipeline({SESSION_ID:options.SESSION_ID,$container:options.$container,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,keyP:options.keyP,refreshed_ds:options.refreshed_ds,parent_nodeP:options.parent_nodeP,check_existP:options.check_existP,$root_container:options.$root_container,prop:options.prop,element:options.treeP?.tagName||options.nodeP.tagName,hover_handlers:options.hover_handlers,include_hover_click:options.include_hover_click,iterate_child:options.iterate_child,buffered:!!glb.new_xu_render});if(!glb.new_xu_render){return draw_ret.$div}if(!draw_ret.$div){return draw_ret.$div}return await func.runtime.render.finalize_buffered_draw({SESSION_ID:options.SESSION_ID,$div:draw_ret.$div,temp_$div:draw_ret.temp_$div,ret:draw_ret.ret,paramsP:options.paramsP,nodeP:options.nodeP})};func.runtime.render.render_tree=async function(treeP,renderer_context){if(!treeP)return;const nodeP=func.runtime.render.get_tree_source_node(treeP);const perf_end=func.runtime?.perf?.start?.(renderer_context.SESSION_ID,"render_ui_tree");func.runtime?.perf?.increment_map?.(renderer_context.SESSION_ID,"render_node_counts",treeP.id||nodeP?.id||nodeP?.id_org||treeP.tagName||"unknown");try{const tree_runtime=func.runtime.render.create_tree_runtime({SESSION_ID:renderer_context.SESSION_ID,$container:renderer_context.$container,treeP:treeP,nodeP:nodeP,parent_infoP:renderer_context.parent_infoP,paramsP:renderer_context.paramsP,jobNoP:renderer_context.jobNoP,is_skeleton:renderer_context.is_skeleton,keyP:renderer_context.keyP,render_child:async function($divP,child,parent_infoP,key,parentNodeP,rootContainerP){await func.runtime.render.render_tree(child,{...renderer_context,$container:$divP,parent_infoP:parent_infoP,keyP:key,refreshed_ds:null,parent_nodeP:parentNodeP,check_existP:null,$root_container:rootContainerP})}});const render_context=tree_runtime.render_context;const _ds=render_context._ds;const prop=tree_runtime.prop;const hover_handlers=tree_runtime.hover_handlers;const include_hover_click=tree_runtime.include_hover_click;const close_modal=tree_runtime.close_modal;const iterate_child=tree_runtime.iterate_child;func.runtime.render.log_tree_debug({SESSION_ID:renderer_context.SESSION_ID,paramsP:renderer_context.paramsP,nodeP:nodeP,_ds:_ds});const special_render=await func.runtime.render.render_special_node({SESSION_ID:renderer_context.SESSION_ID,$container:renderer_context.$container,$root_container:renderer_context.$root_container,treeP:treeP,nodeP:nodeP,parent_infoP:renderer_context.parent_infoP,paramsP:renderer_context.paramsP,jobNoP:renderer_context.jobNoP,is_skeleton:renderer_context.is_skeleton,keyP:renderer_context.keyP,refreshed_ds:renderer_context.refreshed_ds,parent_nodeP:renderer_context.parent_nodeP,prop:prop,render_context:render_context,hover_handlers:hover_handlers,iterate_child:iterate_child,close_modal:close_modal});if(special_render.handled){func.runtime?.perf?.increment?.(renderer_context.SESSION_ID,"render_special_node_hits");return special_render.result}return await func.runtime.render.draw_node({SESSION_ID:renderer_context.SESSION_ID,$container:renderer_context.$container,$root_container:renderer_context.$root_container,treeP:treeP,nodeP:nodeP,parent_infoP:renderer_context.parent_infoP,paramsP:renderer_context.paramsP,jobNoP:renderer_context.jobNoP,is_skeleton:renderer_context.is_skeleton,keyP:renderer_context.keyP,refreshed_ds:renderer_context.refreshed_ds,parent_nodeP:renderer_context.parent_nodeP,check_existP:renderer_context.check_existP,prop:prop,hover_handlers:hover_handlers,include_hover_click:include_hover_click,iterate_child:iterate_child})}finally{perf_end?.()}};func.runtime.render.render_ui_tree=async function(SESSION_ID,$container,nodeP,parent_infoP,paramsP,jobNoP,is_skeleton,keyP,refreshed_ds,parent_nodeP,check_existP,$root_container){if(!nodeP)return;const treeP=await func.runtime.render.ensure_tree_node({SESSION_ID:SESSION_ID,nodeP:nodeP,parent_infoP:parent_infoP,paramsP:paramsP,keyP:keyP,parent_nodeP:parent_nodeP});const render_depth=func.runtime.render._html_script_render_depth||(func.runtime.render._html_script_render_depth={});render_depth[SESSION_ID]=(render_depth[SESSION_ID]||0)+1;try{return await func.runtime.render.render_tree(treeP,{SESSION_ID:SESSION_ID,$container:$container,parent_infoP:parent_infoP,paramsP:paramsP,jobNoP:jobNoP,is_skeleton:is_skeleton,keyP:keyP,refreshed_ds:refreshed_ds,parent_nodeP:parent_nodeP,check_existP:check_existP,$root_container:$root_container})}finally{render_depth[SESSION_ID]=Math.max((render_depth[SESSION_ID]||1)-1,0);if(render_depth[SESSION_ID]===0){await func.runtime.render.flush_html_script_queue?.();delete render_depth[SESSION_ID]}}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.normalize_node_attributes=function(nodeP){if(nodeP?.type!=="element"||!nodeP.attributes){return{}}const attributes=nodeP.attributes;const attribute_keys=Object.keys(attributes);for(let index=0;index<attribute_keys.length;index++){const key=attribute_keys[index];let val=attributes[key];if(key.substring(0,6)==="xu-exp"){if(xu_isEmpty(val)){delete attributes[key];continue}const clean_key=key.split(":")[1];if(typeof attributes[clean_key]!=="undefined"){delete attributes[clean_key]}}if(glb.attr_abbreviations_arr.includes(key)){attributes[`xu-on:${key.substring(3)}`]=[{handler:"custom",props:{},workflow:[{id:Date.now(),data:{action:"update",name:{value:val},enabled:true},props:{}}]}];delete attributes[key]}}const normalized_keys=Object.keys(attributes);for(let index=0;index<normalized_keys.length;index++){const key=normalized_keys[index];let val=attributes[key];val=func.runtime.render.fix_val_defaults(key,val);if(typeof val==="undefined"||val===null){delete attributes[key];continue}if(glb.solid_attributes.includes(key)&&!val){delete attributes[key];continue}attributes[key]=val}return attributes};func.runtime.render.get_attribute_base_key=function(key){return key.split(":")[0]};func.runtime.render.get_expression_attribute_target=function(key){return key.split("xu-exp:")[1]||""};func.runtime.render.is_native_attribute=function(nodeTag,key){const new_key=func.runtime.render.get_attribute_base_key(key);if(nodeTag==="xu-panel"||nodeTag==="xu-teleport"){return false}return!(new_key.substr(0,2)==="xu"&&new_key.substr(2,1)==="-")};func.runtime.render.should_abort=function($container,ret){return!!(ret?.abort||func.runtime.ui.get_data($container)?.xuData?.pending_to_delete)};func.runtime.render.should_skip_phase_attribute=function(attr,execute_attributes=[]){return glb.html5_events_handler.includes(attr)||execute_attributes.includes(attr)};func.runtime.render.has_attribute_or_expression=function(nodeP,attr){return!!(nodeP?.attributes?.hasOwnProperty(attr)||nodeP?.attributes?.hasOwnProperty(`xu-exp:${attr}`))};func.runtime.render.should_run_before_attribute=function(nodeP,attr){if(!func.runtime.render.has_attribute_or_expression(nodeP,attr)){return false}if(!nodeP.attributes[`xu-exp:${attr}`]&&nodeP?.attributes?.hasOwnProperty(attr)&&typeof func.runtime.render.fix_val_defaults(attr,nodeP.attributes[attr])==="undefined"){return false}return true};func.runtime.render.should_defer_runtime_attribute=function(nodeP,new_key){return new_key==="xu-exp"||nodeP.attributes["xu-exp:"+new_key]||glb.run_xu_before.includes(new_key)||glb.run_xu_after.includes(new_key)};func.runtime.render.should_run_expression_attribute=function(attr,execute_attributes=[],done_exp,key){if(!attr){return false}if(func.runtime.render.should_skip_phase_attribute(attr,execute_attributes)){return false}if(done_exp?.has&&done_exp.has(key)){return false}if(done_exp?.includes&&done_exp.includes(key)){return false}return true};func.runtime.render.should_run_after_attribute=function(nodeP,attr,execute_attributes=[]){if(func.runtime.render.should_skip_phase_attribute(attr,execute_attributes)){return false}if(!nodeP.attributes){return false}return!!(nodeP.attributes[attr]||nodeP.attributes[`xu-exp:${attr}`])};func.runtime.render.is_xu_tag=function(tagName){return typeof tagName==="string"&&tagName.substr(0,3)==="xu-"};func.runtime.render.execute_attribute=async function(options){return await func.runtime.render.execute_xu_function({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,xu_func:options.xu_func,$elm:options.$elm,$live_elm:options.$live_elm,val:options.value_obj,is_init:options.is_init,refreshed_ds:options.refreshed_ds,handler_bundle:options.handler_bundle,get_params_obj_new:func.runtime.program.get_params_obj})};func.runtime.render.set_native_dom_attribute=function($elm,key,val){try{func.runtime.ui.set_attr($elm,key,val);return true}catch(err){console.error(err.message);return false}};func.runtime.render.store_xu_attribute=function($elm,key,val){try{const elm_data=func.runtime.ui.get_data($elm);if(elm_data?.xuAttributes){elm_data.xuAttributes[key]=val;if(func.runtime.ui.update_refresh_dependency_entry){func.runtime.ui.update_refresh_dependency_entry($elm,key,val)}return true}}catch(error){debugger;console.error(error)}return false};func.runtime.render.record_attribute_stat=function($elm,key,value){const elm_data=func.runtime.ui.get_data($elm);if(!elm_data?.xuData){return false}if(!elm_data.xuData.debug_info.attribute_stat){elm_data.xuData.debug_info.attribute_stat={}}elm_data.xuData.debug_info.attribute_stat[key]=value;return true};func.runtime.render.fix_val_defaults=function(key,val){let ret=val;if(key==="xu-render"&&(typeof val==="undefined"||val===null||val==="")){ret=true}if(key==="xu-show"&&(typeof val==="undefined"||val===null||val==="")){ret=true}return ret};func.runtime.render.get_attribute_phase_plan=function(nodeP){if(nodeP?.type!=="element"||!nodeP.attributes){return{has_xu_attrs:false,before_attrs:[],attribute_entries:[],expression_entries:[],after_attrs:[]}}if(nodeP._runtime_attribute_phase_plan&&nodeP._runtime_attribute_phase_plan_source===nodeP.attributes){return nodeP._runtime_attribute_phase_plan}const attributes=nodeP.attributes||{};const attribute_entries=[];const expression_entries=[];const html_event_entries=[];const attribute_keys=Object.keys(attributes);for(let index=0;index<attribute_keys.length;index++){const key=attribute_keys[index];const val=attributes[key];const new_key=func.runtime.render.get_attribute_base_key(key);attribute_entries.push({key:key,val:val,new_key:new_key,is_native:func.runtime.render.is_native_attribute(nodeP.tagName,key),should_defer:func.runtime.render.should_defer_runtime_attribute(nodeP,new_key),xu_func:new_key==="xu-on"?"xu-on":new_key});if(glb.html5_events_handler.includes(key)){html_event_entries.push({key:key})}const exp_attr=func.runtime.render.get_expression_attribute_target(key);if(exp_attr){expression_entries.push({key:key,attr:exp_attr,val:val})}}const plan={has_xu_attrs:!!(attributes["xu-attrs"]||attributes["xu-exp:xu-attrs"]),before_attrs:glb.run_xu_before.filter(function(attr){return func.runtime.render.should_run_before_attribute(nodeP,attr)}),attribute_entries:attribute_entries,html_event_entries:html_event_entries,expression_entries:expression_entries,after_attrs:glb.run_xu_after.filter(function(attr){return func.runtime.render.has_attribute_or_expression(nodeP,attr)})};nodeP._runtime_attribute_phase_plan_source=nodeP.attributes;nodeP._runtime_attribute_phase_plan=plan;return plan};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.create_attribute_reader=function(options){const done_exp=new Set;const attr_value_cache={};const xu_exp_cache={};const elm_data=func.runtime.ui.get_data(options.$elm);const xuData=elm_data?.xuData;const get_xuExp=async function(attrib){if(Object.prototype.hasOwnProperty.call(xu_exp_cache,attrib)){return xu_exp_cache[attrib]}if(options.is_skeleton)return;if(glb.new_xu_render){if(xuData&&!xuData.attr_exp_info){xuData.attr_exp_info={}}}const attr=`xu-exp:${attrib}`;if(!options.nodeP?.attributes?.hasOwnProperty(attr))return;const exp=options.nodeP.attributes[attr];const res=await func.expression.get(options.SESSION_ID,exp,options.paramsP.dsSessionP,"UI Attr EXP",options._ds.currentRecordId);if(glb.new_xu_render&&xuData){xuData.attr_exp_info[attrib]=res}done_exp.add(attr);xu_exp_cache[attrib]=res.result;return xu_exp_cache[attrib]};const get_attr_value=async function(key){if(Object.prototype.hasOwnProperty.call(attr_value_cache,key)){return attr_value_cache[key]}let ret=func.runtime.render.fix_val_defaults(key,options.nodeP.attributes[key]);if(options.nodeP?.attributes?.hasOwnProperty(`xu-exp:${key}`)){ret=await get_xuExp(key)}attr_value_cache[key]=ret;return attr_value_cache[key]};return{done_exp:done_exp,get_attr_value:get_attr_value}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.apply_attribute_phases=async function(options){let _ret={};if(options.nodeP.type!=="element"||!options.nodeP.attributes)return _ret;func.runtime.render.normalize_node_attributes(options.nodeP);const phase_plan=func.runtime.render.get_attribute_phase_plan(options.nodeP);if(phase_plan.has_xu_attrs){const attr="xu-attrs";await func.runtime.render.execute_attribute({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,xu_func:attr,$elm:options.$elm,$live_elm:options.$live_elm,value_obj:{key:attr,value:await options.get_attr_value(attr)},is_init:options.is_init,handler_bundle:options.handler_bundle})}if(!xu_isEmpty(options.nodeP.attributes)){for(let index=0;index<phase_plan.before_attrs.length;index++){const attr=phase_plan.before_attrs[index];if(func.runtime.render.should_abort(options.$container,_ret))break;if(func.runtime.render.should_skip_phase_attribute(attr,options.execute_attributes))continue;const ret=await func.runtime.render.execute_attribute({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,xu_func:attr,$elm:options.$elm,$live_elm:options.$live_elm,value_obj:{key:attr,value:await options.get_attr_value(attr)},is_init:options.is_init,handler_bundle:options.handler_bundle});_ret=Object.assign(_ret,ret)}}for(let index=0;index<phase_plan.attribute_entries.length;index++){const entry=phase_plan.attribute_entries[index];const key=entry.key;const val=entry.val;if(func.runtime.render.should_abort(options.$container,_ret))break;if(func.runtime.render.should_skip_phase_attribute(key,options.execute_attributes))continue;if(entry.is_native){func.runtime.render.set_native_dom_attribute(options.$elm,key,val);continue}func.runtime.render.store_xu_attribute(options.$elm,key,val);if(entry.should_defer){continue}if(entry.new_key==="xu-on"){const ret=await func.runtime.render.execute_attribute({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,xu_func:"xu-on",$elm:options.$elm,$live_elm:options.$live_elm,value_obj:{key:key,value:await options.get_attr_value(key)},is_init:options.is_init,refreshed_ds:options.refreshed_ds,handler_bundle:options.handler_bundle});_ret=Object.assign(_ret,ret);continue}const ret=await func.runtime.render.execute_attribute({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,xu_func:entry.xu_func,$elm:options.$elm,$live_elm:options.$live_elm,value_obj:{key:key,value:await options.get_attr_value(key)},is_init:options.is_init,refreshed_ds:options.refreshed_ds,handler_bundle:options.handler_bundle});_ret=Object.assign(_ret,ret)}for(let index=0;index<phase_plan.expression_entries.length;index++){const entry=phase_plan.expression_entries[index];const key=entry.key;const val=entry.val;if(func.runtime.render.should_abort(options.$container,_ret))break;const attr=entry.attr;if(!func.runtime.render.should_run_expression_attribute(attr,options.execute_attributes,options.done_exp,key)){continue}const ret=await func.runtime.render.execute_attribute({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,xu_func:"xu-exp",$elm:options.$elm,$live_elm:options.$live_elm,value_obj:{key:attr,value:val},is_init:true,refreshed_ds:options.refreshed_ds,handler_bundle:options.handler_bundle});_ret=Object.assign(_ret,ret)}for(let index=0;index<phase_plan.after_attrs.length;index++){const attr=phase_plan.after_attrs[index];if(func.runtime.render.should_abort(options.$container,_ret))break;if(!func.runtime.render.should_run_after_attribute(options.nodeP,attr,options.execute_attributes))continue;const ret=await func.runtime.render.execute_attribute({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,xu_func:attr,$elm:options.$elm,$live_elm:options.$live_elm,value_obj:{key:attr,value:await options.get_attr_value(attr)},is_init:options.is_init,refreshed_ds:options.refreshed_ds,handler_bundle:options.handler_bundle});_ret=Object.assign(_ret,ret)}return _ret};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.normalize_set_attributes_options=function(...args){if(typeof args[0]==="object"&&args[0]!==null&&!Array.isArray(args[0])){return{...args[0],$live_elm:args[0].$live_elm||args[0].$elm}}const[SESSION_ID,is_skeleton,$root_container,nodeP,$container,paramsP,parent_infoP,jobNoP,keyP,parent_nodeP,$elm,is_init,execute_attributes=[],refreshed_ds]=args;return{SESSION_ID:SESSION_ID,is_skeleton:is_skeleton,$root_container:$root_container,nodeP:nodeP,$container:$container,paramsP:paramsP,parent_infoP:parent_infoP,jobNoP:jobNoP,keyP:keyP,parent_nodeP:parent_nodeP,$elm:$elm,$live_elm:$elm,is_init:is_init,execute_attributes:execute_attributes,refreshed_ds:refreshed_ds}};func.runtime.render.set_attributes_new=async function(...args){const options=func.runtime.render.normalize_set_attributes_options(...args);const _ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[options.paramsP.dsSessionP];if(!_ds)return{abort:true};if(func.runtime.ui.prune_stale_refresh_dependencies){func.runtime.ui.prune_stale_refresh_dependencies(options.$elm,options.nodeP?.attributes||{})}const attr_reader=func.runtime.render.create_attribute_reader({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$elm:options.$elm,nodeP:options.nodeP,paramsP:options.paramsP,_ds:_ds});const handler_bundle=func.runtime.render.build_xu_handlers({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$elm:options.$elm,$live_elm:options.$live_elm,is_init:options.is_init,refreshed_ds:options.refreshed_ds,get_params_obj_new:func.runtime.program.get_params_obj},_ds);const _ret=await func.runtime.render.apply_attribute_phases({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$elm:options.$elm,$live_elm:options.$live_elm,is_init:options.is_init,execute_attributes:options.execute_attributes||[],refreshed_ds:options.refreshed_ds,done_exp:attr_reader.done_exp,get_attr_value:attr_reader.get_attr_value,handler_bundle:handler_bundle});const phase_plan=func.runtime.render.get_attribute_phase_plan(options.nodeP);for(let index=0;index<phase_plan.html_event_entries.length;index++){const key=phase_plan.html_event_entries[index].key;if(func.runtime.render.should_abort(options.$container,_ret))break;func.runtime.ui.set_attr(options.$elm,key,await attr_reader.get_attr_value(key))}return _ret};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.handle_xu_ref=async function(options){if(!options.val.value){return{}}func.UI.update_xu_ref(options.SESSION_ID,options.dsSession||options.paramsP.dsSessionP,options.val.value,options.$elm);const targetNode=func.runtime.ui.get_first_node(options.$elm);if(!targetNode){return{}}const target_data=func.runtime.ui.get_data(options.$elm);if(target_data?.xuData?.xu_ref_observer){target_data.xuData.xu_ref_observer.disconnect()}const observer=new MutationObserver(()=>{func.runtime.ui.refresh_xu_attributes({SESSION_ID:options.SESSION_ID,fields_arr:[options.val.value]})});observer.observe(targetNode,{attributes:true,childList:true,subtree:true});if(target_data?.xuData){target_data.xuData.xu_ref_observer=observer}return{}};func.runtime.render.handle_xu_bind=async function(options){if(options.is_skeleton)return{};const $elm=func.runtime?.ui?.get_preferred_live_element?func.runtime.ui.get_preferred_live_element(options.$elm):options.$elm;const elm_data=func.runtime.ui.get_data($elm);const xuData=elm_data?.xuData;const bind_expression=typeof options?.val?.value==="string"?options.val.value:elm_data?.xuAttributes?.["xu-bind"]||func.runtime.ui.get_attr($elm,"xu-bind");if(!xuData?.paramsP){return{}}if(!bind_expression){return{}}let val_is_reference_field=false;let _prog_id=xuData.paramsP.prog_id;let _dsP=xuData.paramsP.dsSessionP;let is_dynamic_field=false;let field_prop;let bind_field_id;const _bind_elm_node=func.runtime.ui.get_first_node($elm);const input_field_type=_bind_elm_node?.type||func.runtime.ui.get_attr($elm,"type");const bind_ui_id=xuData.ui_id||func.runtime.ui.get_attr($elm,"xu-ui-id");const get_bind_targets=function(){const $root=func.runtime.ui.get_refresh_index_root?.(options.SESSION_ID)||func.runtime.ui.get_root_element?.(options.SESSION_ID)||func.runtime.ui._wrap_matches([document.body]);const live_targets=[];const seen_nodes=new Set;const add_candidate=function(node){if(!node||seen_nodes.has(node)){return}const target_data=func.runtime.ui.get_data(node);if(!node.isConnected||target_data?.xuData?.pending_to_delete){return}seen_nodes.add(node);live_targets.push(node)};if(bind_ui_id&&options.SESSION_ID&&func.runtime?.ui?.find_refresh_elements_by_attr){const ui_id_targets=func.runtime.ui.find_refresh_elements_by_attr($root,"xu-ui-id",bind_ui_id).toArray();for(let index=0;index<ui_id_targets.length;index++){add_candidate(ui_id_targets[index])}}const runtime_nodes=func.runtime?.ui?.get_refresh_index_elements?func.runtime.ui.get_refresh_index_elements(options.SESSION_ID,$root).toArray():func.runtime.ui.find_by_selector($root,"[xu-ui-id]").toArray();const target_parent_ui_id=xuData.parent_element_ui_id;const target_node_id=xuData.nodeid;const target_recordid=xuData.recordid;const target_prog_id=xuData.paramsP?.prog_id;for(let index=0;index<runtime_nodes.length;index++){const node=runtime_nodes[index];const node_data=func.runtime.ui.get_data(node);const node_xu_data=node_data?.xuData;if(!node_xu_data){continue}if(target_node_id&&node_xu_data.nodeid!==target_node_id){continue}if(target_parent_ui_id&&node_xu_data.parent_element_ui_id!==target_parent_ui_id){continue}if(target_prog_id&&node_xu_data.paramsP?.prog_id!==target_prog_id){continue}if(typeof target_recordid!=="undefined"&&target_recordid!==null&&node_xu_data.recordid!==target_recordid){continue}const node_bind_expression=node_data?.xuAttributes?.["xu-bind"]||func.runtime.ui.get_attr(node,"xu-bind");if(node_bind_expression!==bind_expression){continue}add_candidate(node)}if(!live_targets.length){const _node=func.runtime.ui.get_first_node($elm);return func.runtime.ui._wrap_matches(_node?[_node]:[])}for(let index=0;index<live_targets.length;index++){const node=live_targets[index];const target_data=func.runtime.ui.get_data(node);if(!node?.isConnected||target_data?.xuData?.pending_to_delete){continue}add_candidate(node)}if(!live_targets.length){const _node=func.runtime.ui.get_first_node($elm);return func.runtime.ui._wrap_matches(_node?[_node]:[])}const target_nodes=live_targets;const visible_targets=[];for(let index=0;index<target_nodes.length;index++){const node=target_nodes[index];if(node.getClientRects?.().length&&!node.hidden){visible_targets.push(node)}}return func.runtime.ui._wrap_matches(visible_targets.length?visible_targets:live_targets)};try{const bind_field=await func.runtime.bind.resolve_field(options.SESSION_ID,_prog_id,_dsP,bind_expression.split(".")[0],xuData.iterate_info);bind_field_id=bind_field.bind_field_id;field_prop=bind_field.field_prop;is_dynamic_field=bind_field.is_dynamic_field;_dsP=bind_field.dsSessionP;_prog_id=bind_field.prog_id;val_is_reference_field=true}catch(err){console.error(err?.message||err);return{}}const bind=func.runtime.bind.get_adapter(options.SESSION_ID);const field_changed=async function(){const _ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[_dsP];const field_type=func.runtime.bind.get_field_type(field_prop);if(field_type==="array"&&input_field_type==="checkbox"&&val_is_reference_field){const arr_value_before_cast=[...(await func.datasource.get_value(options.SESSION_ID,bind_field_id,_dsP,_ds.currentRecordId)).ret.value];const value_from_getter=bind.getter(func.runtime.ui.get_first_node(options.$elm));const value=func.runtime.bind.toggle_array_value(arr_value_before_cast,value_from_getter);const datasource_changes=func.runtime.bind.build_datasource_changes(_dsP,_ds.currentRecordId,bind_field_id,value);return await func.datasource.update(options.SESSION_ID,datasource_changes)}if(field_type==="array"&&input_field_type==="radio"&&val_is_reference_field){const value_from_getter=bind.getter(func.runtime.ui.get_first_node(options.$elm));const datasource_changes=func.runtime.bind.build_datasource_changes(_dsP,_ds.currentRecordId,bind_field_id,[value_from_getter]);return await func.datasource.update(options.SESSION_ID,datasource_changes)}const raw_value=bind.getter(func.runtime.ui.get_first_node(options.$elm));const value=await func.runtime.bind.get_cast_value(options.SESSION_ID,field_prop,input_field_type,raw_value);if(!_ds.currentRecordId)return;const iterate_info=xuData.iterate_info;const is_iterate_field=is_dynamic_field&&iterate_info&&(iterate_info.iterator_val===bind_field_id||iterate_info.iterator_key===bind_field_id);if(!is_iterate_field){const datasource_changes=func.runtime.bind.build_datasource_changes(_dsP,_ds.currentRecordId,bind_field_id,value);await func.datasource.update(options.SESSION_ID,datasource_changes)}await func.runtime.bind.update_reference_source_array({SESSION_ID:options.SESSION_ID,dsSessionP:_dsP,currentRecordId:_ds.currentRecordId,iterate_info:iterate_info,bind_field_id:bind_field_id,field_prop:field_prop,val_is_reference_field:val_is_reference_field,input_field_type:input_field_type,expression_value:bind_expression,value:value});await func.datasource.update_changes_for_out_parameter(options.SESSION_ID,_dsP,_ds.parentDataSourceNo)};const bind_targets=get_bind_targets();const target_nodes=bind_targets.toArray();for(let index=0;index<target_nodes.length;index++){const target=target_nodes[index];const target_data=func.runtime.ui.get_data(target);if(!target_data?.xuData||target_data.xuData.bind_listener_attached){continue}bind.listener(target,field_changed);target_data.xuData.bind_listener_attached=true}const set_value=async function(){const _ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[_dsP];if(!_ds)return;const target_record_id=xuData.recordid||_ds.currentRecordId;if(!target_record_id)return;let value;try{if(val_is_reference_field){const iter=xuData.iterate_info;if(iter&&is_dynamic_field&&(iter.iterator_val===bind_field_id||iter.iterator_key===bind_field_id)){value=iter.iterator_val===bind_field_id?iter._val:iter._key}else{const resolved_value=await func.datasource.get_value(options.SESSION_ID,bind_field_id,_dsP,target_record_id);if(resolved_value?.found){value=resolved_value.ret.value}else{value=func.runtime.bind.get_source_value(_ds,bind_field_id,is_dynamic_field)}}value=func.runtime.bind.format_display_value($elm,field_prop,bind_field_id,bind_expression,value,input_field_type)}else{value=bind_expression}if(typeof value==="undefined")return;const live_bind_targets=get_bind_targets().toArray();for(let index=0;index<live_bind_targets.length;index++){const elm=live_bind_targets[index];if(!elm){continue}bind.setter(elm,value);const target_input_type=elm.type||input_field_type;switch(target_input_type){case"radio":elm.checked=elm.value===String(value);break;case"checkbox":elm.checked=!!value;break;default:if(typeof elm.value!=="undefined"){elm.value=value===null?"":String(value)}break}}}catch(err){console.error(err)}};const bind_refresh_event="xu-bind-refresh."+_dsP.toString();const bind_handler_key="_xuda_bind_"+(bind_ui_id||bind_field_id||"bind");if(document.body[bind_handler_key]){document.body.removeEventListener(bind_refresh_event,document.body[bind_handler_key])}document.body[bind_handler_key]=async()=>{await set_value()};document.body.addEventListener(bind_refresh_event,document.body[bind_handler_key]);await set_value();return{}};func.runtime.render.apply_xu_class=async function(options){try{const raw_value=options?.val?.value;const xuData=func.runtime.ui.get_data(options.$elm)?.xuData;if(typeof raw_value==="string"){const trimmed=raw_value.trim();const looks_like_object=trimmed.startsWith("{")&&trimmed.endsWith("}");if(!looks_like_object){func.runtime.render.apply_expression_class(options.$elm,raw_value);xuData.debug_info.attribute_stat["xu-class"]=func.runtime.ui.get_first_node(options.$elm)?.className||func.runtime.ui.get_attr(options.$elm,"class");return{}}}const classes_obj=typeof raw_value==="string"?JSON5.parse(raw_value):Object.assign({},{},raw_value);if(typeof classes_obj!=="object"||classes_obj===null||Array.isArray(classes_obj)){throw new Error("xu-class expects an object map or a class string")}const class_names=Object.keys(classes_obj);for(let index=0;index<class_names.length;index++){const cla=class_names[index];const cond=classes_obj[cla];const res=await func.expression.get(options.SESSION_ID,cond,options.paramsP.dsSessionP,"UI Attr EXP",xuData.currentRecordId,null,null,null,null,null,xuData.iterate_info);if(res.result){func.runtime.ui.add_class(options.$elm,cla)}else{func.runtime.ui.remove_class(options.$elm,cla)}}xuData.debug_info.attribute_stat["xu-class"]=func.runtime.ui.get_first_node(options.$elm)?.className||func.runtime.ui.get_attr(options.$elm,"class");return{}}catch(e){await func.runtime.render.report_xu_runtime_error({...options,xu_func:"xu-class",val:{key:"xu-class",value:options?.val?.value}},e,"xu-class has invalid syntax");return{abort:true}}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.handle_xu_for=async function(options){if(options.parent_infoP?.iterate_info)return{};if(!options.data.value)return{};try{const $live_elm=options.$live_elm||options.$elm;const{arr,reference_source_obj}=await func.runtime.render.resolve_xu_for_source(options.SESSION_ID,options.paramsP.dsSessionP,options.data.value);const{iterator_key,iterator_val,is_key_dynamic_field,is_val_dynamic_field}=func.runtime.render.get_xu_for_iterators(options.$elm);const _progFields=await func.datasource.get_progFields(options.SESSION_ID,options.paramsP.dsSessionP);let i=0;if(Array.isArray(arr)){for(let idx=0;idx<arr.length;idx++){let _key=idx;let _val=arr[idx];const currentRecordId=SESSION_OBJ[options.SESSION_ID].DS_GLB[options.paramsP.dsSessionP].currentRecordId.toString();const iterate_info=func.runtime.render.build_iterate_info({_val:_val,_key:_key,iterator_key:iterator_key,iterator_val:iterator_val,is_key_dynamic_field:is_key_dynamic_field,is_val_dynamic_field:is_val_dynamic_field,reference_source_obj:reference_source_obj});func.runtime.render.apply_iterate_info_to_current_record(options.SESSION_ID,options.paramsP.dsSessionP,currentRecordId,_progFields,iterate_info);const _parent_info=structuredClone(options.parent_infoP)||{};_parent_info.iterate_info=iterate_info;const $divP=await func.runtime.render.render_ui_tree(options.SESSION_ID,options.$container,options.nodeP,_parent_info,options.paramsP,options.jobNoP,null,i,null,options.nodeP,null,options.$root_container);func.runtime.render.attach_iterate_info_to_children($divP,iterate_info);i++}}else{const iterate_keys=Object.keys(arr||{});for(let idx=0;idx<iterate_keys.length;idx++){let _key=iterate_keys[idx];let _val=arr[_key];const currentRecordId=SESSION_OBJ[options.SESSION_ID].DS_GLB[options.paramsP.dsSessionP].currentRecordId.toString();const iterate_info=func.runtime.render.build_iterate_info({_val:_val,_key:_key,iterator_key:iterator_key,iterator_val:iterator_val,is_key_dynamic_field:is_key_dynamic_field,is_val_dynamic_field:is_val_dynamic_field,reference_source_obj:reference_source_obj});func.runtime.render.apply_iterate_info_to_current_record(options.SESSION_ID,options.paramsP.dsSessionP,currentRecordId,_progFields,iterate_info);const _parent_info=structuredClone(options.parent_infoP)||{};_parent_info.iterate_info=iterate_info;const $divP=await func.runtime.render.render_ui_tree(options.SESSION_ID,options.$container,options.nodeP,_parent_info,options.paramsP,options.jobNoP,null,i,null,options.nodeP,null,options.$root_container);func.runtime.render.attach_iterate_info_to_children($divP,iterate_info);i++}}const _live_node=func.runtime.ui.get_first_node($live_elm);if(_live_node){func.runtime.ui.remove($live_elm)}const _options_node=func.runtime.ui.get_first_node(options.$elm);if(_options_node&&_options_node!==_live_node){func.runtime.ui.remove(options.$elm)}return{abort:true,consume_placeholder:true}}catch(e){console.error(" Iterator Arr parse error");return{abort:true}}};func.runtime.render.set_iterator_name=function($elm,key,value){func.runtime.ui.get_data($elm).xuData[key]=value;return{}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.handle_legacy_xu_render=async function(options){const value=await func.common.get_cast_val(options.SESSION_ID,"common fx","xu-render","bool",options.val.value);const init_render=function(){if(!value){const cloned_div=func.runtime.ui.get_first_node(options.$elm)?.cloneNode(true);const original_data_obj=func.runtime.render.build_xu_render_original_data({$container:cloned_div,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,$root_container:options.$root_container});const snapshot_xuData=func.runtime.ui.get_data(cloned_div).xuData;const snapshot_xuAttributes=options.nodeP.attributes||{};const xu_ui_id=func.runtime.ui.get_attr(options.$elm,"xu-ui-id");const _elm_node=func.runtime.ui.get_first_node(options.$elm);if(_elm_node?.remove){_elm_node.remove()}func.runtime.render.create_xu_render_placeholder(xu_ui_id,options.$container,{hidden:true,xuData:snapshot_xuData,original_data_obj:original_data_obj,xurender_node:cloned_div,xuAttributes:snapshot_xuAttributes});return{abort:true}}return{}};const replace_rendered_xu_node=async function(new_$div){const $parent=func.runtime.ui.get_parent(options.$elm);func.runtime.ui.replace_with(options.$elm,new_$div);if(options.from_panel){const xuPanelWrapper={...func.runtime.ui.get_data(new_$div).xuPanelWrapper};if(func.runtime.ui.get_data($parent)){func.runtime.ui.get_data($parent).xuPanelWrapper=xuPanelWrapper}func.runtime.ui.replace_with(options.$elm,func.runtime.ui.get_children(new_$div))}if(options.val.fields_arr){return await func.runtime.ui.refresh_xu_attributes({SESSION_ID:options.SESSION_ID,fields_arr:options.val.fields_arr,jobNoP:options.val.jobNoP,$elm_to_search:new_$div})}func.events.delete_job(options.SESSION_ID,options.jobNoP)};const post_render=async function(){if(value){try{const elm_node=func.runtime.ui.get_first_node(options.$elm);if(elm_node?.tagName!=="XURENDER"&&elm_node){return func.events.delete_job(options.SESSION_ID,options.jobNoP)}const original_data_obj=func.runtime.ui.get_data(options.$elm).xuData.original_data_obj;if(!original_data_obj){func.events.delete_job(options.SESSION_ID,options.jobNoP);return{delete_job:options.jobNoP}}const new_$div=await func.runtime.render.render_ui_tree(options.SESSION_ID,options.$elm,structuredClone(original_data_obj.nodeP),original_data_obj.parent_infoP,original_data_obj.paramsP,options.jobNoP,null,original_data_obj.keyP,null,original_data_obj.parent_nodeP,null,original_data_obj.$root_container);func.runtime.ui.get_data(new_$div).xuData.original_data_obj=original_data_obj;func.runtime.ui.get_data(new_$div).xuData.xurender_node=func.runtime.ui.get_first_node(options.$elm)?.cloneNode(true);func.runtime.ui.get_data(new_$div).xuAttributes=func.runtime.ui.get_data(options.$elm).xuAttributes||{};const xu_ui_id=func.runtime.ui.get_attr(options.$elm,"xu-ui-id");let $live_elm;if(func.runtime.ui.get_first_node(options.$elm)&&xu_ui_id){if(func.runtime?.ui?.get_refresh_indexed_element_by_ui_id){const _elm=func.runtime.ui.get_refresh_indexed_element_by_ui_id(options.SESSION_ID,xu_ui_id);$live_elm=func.runtime.ui._wrap_matches(_elm?[_elm]:[])}else if(func.runtime?.ui?.find_xu_ui_in_root){$live_elm=func.runtime.ui.find_xu_ui_in_root(options.SESSION_ID,xu_ui_id)}else{$live_elm=func.runtime.ui.find_by_selector(document.body,`[xu-ui-id="${xu_ui_id}"]`)}}else{$live_elm=func.runtime.ui._wrap_matches([])}if($live_elm.length){if(func.runtime.ui.get_data(new_$div).xuData.paramsP){return await replace_rendered_xu_node(new_$div)}func.events.delete_job(options.SESSION_ID,options.jobNoP)}}catch(error){func.events.delete_job(options.SESSION_ID,options.jobNoP)}return}if(func.runtime.ui.get_first_node(options.$elm)?.tagName==="XURENDER"){func.events.delete_job(options.SESSION_ID,options.jobNoP);return}const tmp_div=document.createElement("div");const $xurender=func.runtime.ui.create_xurender(func.runtime.ui.get_attr(options.$elm,"xu-ui-id"),tmp_div);const elm_data=func.runtime.ui.get_data(options.$elm);const elm_xu_data=elm_data?.xuData||{};const elm_xu_attributes=elm_data?.xuAttributes||{};const xurender_node_data=func.runtime.ui.get_data(elm_xu_data.xurender_node);if(elm_xu_data.xurender_node){func.runtime.ui.set_data($xurender,"xuAttributes",xurender_node_data?.xuAttributes||{});func.runtime.ui.set_data($xurender,"xuData",xurender_node_data?.xuData||{})}else{func.runtime.ui.set_data($xurender,"xuAttributes",elm_xu_attributes);func.runtime.ui.set_data($xurender,"xuData",elm_xu_data);const original_data_obj=func.runtime.render.build_xu_render_original_data({nodeP:elm_xu_data.node_org,paramsP:elm_xu_data.paramsP,$container:func.runtime.ui.get_first_node(options.$elm)?.cloneNode(true),parent_infoP:options.parent_infoP});func.runtime.ui.get_data($xurender).xuData.original_data_obj=original_data_obj}const elm_first_node=func.runtime.ui.get_first_node(options.$elm);const teleport_nodes=elm_first_node?.querySelectorAll?.("xu-teleport")||[];for(let index=0;index<teleport_nodes.length;index++){const val=teleport_nodes[index];const xuTeleportData=func.runtime.ui.get_data(val).xuTeleportData||[];for(const teleported_elm_id of xuTeleportData){func.runtime.ui.remove_xu_ui(teleported_elm_id)}}func.runtime.ui.replace_with(options.$elm,func.runtime.ui.get_children(tmp_div));func.events.delete_job(options.SESSION_ID,options.jobNoP)};if(options.is_init){return init_render()}return await post_render()};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.handle_modern_xu_render=async function(options){const value=await func.common.get_cast_val(options.SESSION_ID,"common fx","xu-render","bool",options.val.value);const has_xu_render_attribute=true;const elm_data=func.runtime.ui.get_data(options.$elm);const has_xu_exp_render_attribute=elm_data?.xuData?.attr_exp_info?.["xu-render"]?true:false;const init_render=async function(){options.nodeP.xu_render_made=value;if(!value){if(has_xu_exp_render_attribute){return{has_xu_exp_render_attribute:has_xu_exp_render_attribute,has_xu_render_attribute:has_xu_render_attribute,xu_render_background_processing:true}}return{has_xu_render_attribute:has_xu_render_attribute,abort:true}}return{has_xu_exp_render_attribute:has_xu_exp_render_attribute,has_xu_render_attribute:has_xu_render_attribute}};const post_render=async function(){const container_data=func.runtime.ui.get_data(options.$container);if(!container_data?.xuData?.node?.children?.[options.keyP]){return}const nodeP=container_data.xuData.node.children[options.keyP];nodeP.xu_render_made=value;if(value){try{const exclude_fields=func.runtime.render.get_xu_render_exclude_fields(options.$elm);const xu_render_cache_id=await func.runtime.render.get_xu_render_cache_str(options.SESSION_ID,options.paramsP.dsSessionP,exclude_fields);const xu_ui_id=func.runtime.ui.get_attr(options.$elm,"xu-ui-id");const cached_entry=UI_WORKER_OBJ?.xu_render_cache?.[xu_ui_id+xu_render_cache_id];let found_parent_vars=false;if(cached_entry?.$div){const parent_fields=func.runtime.render.get_parent_ds_field_names(options.SESSION_ID,options.paramsP.dsSessionP);found_parent_vars=func.runtime.render.has_parent_field_dependency(cached_entry.$div,parent_fields,cached_entry?.dependency_fields)}let new_$div=!found_parent_vars&&cached_entry?.$div?func.runtime.ui.get_first_node(cached_entry.$div)?.cloneNode(true):null;if(!new_$div||found_parent_vars){func.runtime.render.cache_xu_render(xu_ui_id+xu_render_cache_id,{paramsP:options.paramsP});nodeP.xu_render_xu_ui_id=xu_ui_id;nodeP.xu_render_cache_id=xu_render_cache_id;new_$div=await func.runtime.render.render_ui_tree(options.SESSION_ID,options.$container,nodeP,options.parent_infoP,options.paramsP,options.jobNoP,null,options.keyP,null,options.parent_nodeP,null,options.$root_container);const _$div=func.runtime.ui.get_first_node(new_$div)?.cloneNode(true);func.runtime.render.cache_xu_render(xu_ui_id+xu_render_cache_id,{...UI_WORKER_OBJ.xu_render_cache[xu_ui_id+xu_render_cache_id],$div:_$div,data:func.runtime.ui.get_data(_$div)})}func.runtime.render.insert_ordered_child(options.$container,new_$div,options.keyP);if(func.runtime.ui.get_first_node(options.$elm)?.tagName==="XURENDER"){func.runtime.ui.remove(options.$elm)}}catch(error){func.events.delete_job(options.SESSION_ID,options.jobNoP)}return}if(func.UI?.worker?.cancel_child_in_flight_jobs){func.UI.worker.cancel_child_in_flight_jobs(options.$elm)}const xu_ui_id=func.runtime.ui.get_attr(options.$elm,"xu-ui-id");const exclude_fields=func.runtime.render.get_xu_render_exclude_fields(options.$elm);const cache_str=await func.runtime.render.get_xu_render_cache_str(options.SESSION_ID,options.paramsP.dsSessionP,exclude_fields);const _$div=func.runtime.ui.get_first_node(options.$elm)?.cloneNode(true);func.runtime.render.cache_xu_render(xu_ui_id+cache_str,{$div:_$div,data:func.runtime.ui.get_data(_$div),paramsP:options.paramsP});func.runtime.ui.remove(options.$elm);func.events.delete_job(options.SESSION_ID,options.jobNoP)};if(options.is_init){return await init_render()}return await post_render()};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.handle_xu_render=async function(options){if(glb.new_xu_render){return await func.runtime.render.handle_modern_xu_render(options)}return await func.runtime.render.handle_legacy_xu_render(options)};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.apply_expression_attribute=async function(options){const new_val={key:options.key,value:func.runtime.render.fix_val_defaults(options.key,options.exp_ret.result)};if(func.runtime.render.is_xu_tag(options.nodeP.tagName)){if(options.tag_fx?.[options.nodeP.tagName]?.[new_val.key]){return await options.tag_fx[options.nodeP.tagName][new_val.key](options.$elm,new_val)}console.warn(`attribute ${new_val.key} not found for ${options.nodeP.tagName}`);return{}}if(!func.runtime.ui.get_data(options.$elm)?.xuData){return{}}func.runtime.render.record_attribute_stat(options.$elm,new_val.key,new_val.value);if(typeof new_val.value==="undefined"||new_val.value===null){return{}}if(glb.solid_attributes.includes(new_val.key)&&!new_val.value){return{}}if(new_val.key.substr(0,2)==="xu"){return await options.common_fx[new_val.key](options.$elm,new_val)}if(new_val.key==="class"){return func.runtime.render.apply_expression_class(options.$elm,new_val.value)}const existing_value=func.runtime.ui.get_attr(options.$elm,new_val.key)||"";func.runtime.ui.set_attr(options.$elm,new_val.key,existing_value+new_val.value);return{}};func.runtime.render.apply_expression_class=function($elm,new_class_value){const xuData=func.runtime.ui.get_data($elm)?.xuData;const old_exp_classes=xuData?._exp_class_cache||"";if(old_exp_classes){const old_classes=old_exp_classes.split(/\s+/).filter(Boolean);for(let i=0;i<old_classes.length;i++){func.runtime.ui.remove_class($elm,old_classes[i])}}const new_value=(new_class_value||"").toString();const new_classes=new_value.split(/\s+/).filter(Boolean);for(let i=0;i<new_classes.length;i++){func.runtime.ui.add_class($elm,new_classes[i])}if(xuData){xuData._exp_class_cache=new_value}return{}};func.runtime.render.apply_visibility=function($elm,value){if(value){func.runtime.ui.show($elm);return}func.runtime.ui.hide($elm)};func.runtime.render.apply_dom_content=function($elm,value,mode="html"){if(mode==="text"){func.runtime.ui.set_text($elm,value);return}func.runtime.ui.set_html($elm,value)};func.runtime.render.run_inline_script=function($elm,script_body){const checkExist=setInterval(async function(){const node=func.runtime.ui.get_first_node($elm);if(node&&node.offsetParent!==null){try{const fn=`async (el)=>{${script_body} };`;const res=eval(fn);await res(node)}catch(e){eval(script_body)}clearInterval(checkExist)}},100)};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.handle_xu_panel_program=async function(options){let ret={};const _session=SESSION_OBJ[options.SESSION_ID];const _ds=_session.DS_GLB[options.paramsP.dsSessionP];const _refreshed_ds=_session.DS_GLB[options.refreshed_ds];const render_panel_init=async function(){const prog_id=options.val.value?.prog||options.val.value;let create_new_ds=true;if(options.refreshed_ds&&_refreshed_ds?.prog_id===prog_id){create_new_ds=false}const params_obj=await options.get_params_obj_new(options.SESSION_ID,prog_id,options.nodeP,options.paramsP.dsSessionP);const ret_panel=await func.runtime.ui.init_screen({SESSION_ID:options.SESSION_ID,prog_id:prog_id,sourceScreenP:options.paramsP.screenId,callingDataSource_objP:_ds,$callingContainerP:options.$elm,triggerIdP:null,rowIdP:_ds.currentRecordId,jobNoP:null,is_panelP:true,parameters_obj_inP:params_obj.params_res,source_functionP:"initXu_panel",call_screen_propertiesP:undefined,refreshed_ds:create_new_ds?null:options.refreshed_ds,parameters_raw_obj:params_obj.params_raw});ret={$new_div:ret_panel};const container_data=func.runtime.ui.get_data(options.$container);if(container_data?.xuData){container_data.xuData.xuPanelProps=func.runtime.ui.get_data(options.$elm)?.xuAttributes;container_data.xuData.xuPanelData=func.runtime.ui.get_data(ret_panel)}return ret};const render_panel_alter=async function(){const program=options.val.value?.prog||options.val.value;const $wrapper=document.createElement("div");const $div=await func.runtime.ui.create_container({SESSION_ID:options.SESSION_ID,$root_container:options.$root_container,nodeP:options.nodeP,$container:options.$container,paramsP:options.paramsP,parent_infoP:options.parent_infoP,jobNoP:options.jobNoP,keyP:options.keyP,treeP:options.treeP,parent_nodeP:options.parent_nodeP,prop:options.nodeP.attributes,$appendToP:$wrapper,attr_str:""});const params_obj=await options.get_params_obj_new(options.SESSION_ID,program,options.nodeP,options.paramsP.dsSessionP);const ret_init=await func.runtime.ui.init_screen({SESSION_ID:options.SESSION_ID,prog_id:program,sourceScreenP:options.paramsP.screenId,callingDataSource_objP:_ds,$callingContainerP:$div,triggerIdP:null,rowIdP:_ds.currentRecordId,jobNoP:options.jobNoP,is_panelP:true,parameters_obj_inP:params_obj.params_res,source_functionP:"alterXu_panel",call_screen_propertiesP:undefined,refreshed_ds:undefined,parameters_raw_obj:params_obj.params_raw});ret={$new_div:ret_init,abort:true};await func.runtime.ui.panel_post_render_handler({SESSION_ID:options.SESSION_ID,$container:options.$elm,$wrapper:ret.$new_div,nodeP:options.nodeP,$panel_div:$div,jobNoP:options.jobNoP});return ret};if(!options.val.value){if(options.is_init){options.val.value="_empty_panel_program"}else{return{abort:true}}}if(options.is_init){return await render_panel_init()}return await render_panel_alter()};func.runtime.render.handle_xu_teleport=async function(options){if(glb.new_xu_render){return{}}if(!options.val.value){return{abort:true}}const $parent=func.runtime.ui.get_parent(options.$elm);const parent_data=func.runtime.ui.get_data($parent);if(parent_data?.xuData){func.runtime.ui.set_data($parent,"xuTeleportData",[]);const parent_xu_ui_id=func.runtime.ui.get_attr($parent,"xu-ui-id");for(let index=0;index<options.nodeP.children.length;index++){const node=options.nodeP.children[index];const $teleport_elm=await func.runtime.render.render_ui_tree(options.SESSION_ID,document.querySelector(options.val.value),node,options.parent_infoP,options.paramsP,options.jobNoP,options.is_skeleton,index,null,node,null,options.$root_container);parent_data.xuTeleportData.push(func.runtime.ui.get_attr($teleport_elm,"xu-ui-id"));func.runtime.ui.set_attr($teleport_elm,"xu-teleport-parent-id",parent_xu_ui_id)}func.runtime.ui.remove(options.$elm);return{abort:true}}func.runtime.ui.set_data(options.$elm,"xuTeleportData",[]);func.runtime.ui.set_attr(options.$elm,"hidden",true);for(let index=0;index<options.nodeP.children.length;index++){const node=options.nodeP.children[index];const $to_container=document.querySelector(options.val.value);if(!$to_container){console.error(`container ${options.val.value} for xuTeleportData not found`);return{abort:true}}const $teleport_elm=await func.runtime.render.render_ui_tree(options.SESSION_ID,$to_container,node,options.parent_infoP,options.paramsP,options.jobNoP,options.is_skeleton,index,null,node,null,options.$root_container);func.runtime.ui.get_data(options.$elm).xuTeleportData.push(func.runtime.ui.get_attr($teleport_elm,"xu-ui-id"));func.runtime.ui.set_attr($teleport_elm,"xu-teleport-parent-id",func.runtime.ui.get_attr(options.$elm,"xu-ui-id"))}return{abort:true}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.build_base_xu_handlers=function(options,_ds){const decode_html_entities=function(value){if(typeof value!=="string"||value.indexOf("&")===-1){return value}if(typeof document!=="undefined"){const textarea=document.createElement("textarea");textarea.innerHTML=value;return textarea.value}return value.replaceAll("&quot;",'"').replaceAll("&#34;",'"').replaceAll("&#39;","'").replaceAll("&#039;","'").replaceAll("&lt;","<").replaceAll("&gt;",">").replaceAll("&amp;","&")};const parse_object_value=function(attr_name,val,shape="object"){let parsed_value=val?.value;if(typeof parsed_value==="string"){const decoded_value=decode_html_entities(parsed_value);const trimmed_value=decoded_value.trim();const wrapped_candidate=trimmed_value.startsWith("(")&&trimmed_value.endsWith(")")?trimmed_value.slice(1,-1).trim():trimmed_value;const looks_like_wrapped_shape=shape==="object"&&wrapped_candidate.startsWith("{")&&wrapped_candidate.endsWith("}")||shape==="array"&&wrapped_candidate.startsWith("[")&&wrapped_candidate.endsWith("]");try{parsed_value=JSON5.parse(looks_like_wrapped_shape?wrapped_candidate:trimmed_value)}catch(error){throw func.runtime.render.build_xu_runtime_error({...options,xu_func:attr_name,val:{key:attr_name,value:val?.value}},error,`${attr_name} has invalid ${shape} syntax`)}}const valid=shape==="array"?Array.isArray(parsed_value):typeof parsed_value==="object"&&parsed_value!==null&&!Array.isArray(parsed_value);if(!valid){throw func.runtime.render.build_xu_runtime_error({...options,xu_func:attr_name,val:{key:attr_name,value:val?.value}},null,`${attr_name} expects a ${shape} value`)}return parsed_value};return{"xu-attrs":async function($elm,val){if(!val.value)return{};const attrs_obj=parse_object_value("xu-attrs",val,"object");const attr_keys=Object.keys(attrs_obj);for(let index=0;index<attr_keys.length;index++){const attr_key=attr_keys[index];options.nodeP.attributes[attr_key]=attrs_obj[attr_key]}return{}},"xu-ref":async function($elm,val,dsSession){return await func.runtime.render.handle_xu_ref({SESSION_ID:options.SESSION_ID,$elm:$elm,paramsP:options.paramsP,val:val,dsSession:dsSession})},"xu-bind":async function($elm,val){return await func.runtime.render.handle_xu_bind({SESSION_ID:options.SESSION_ID,is_skeleton:options.is_skeleton,$elm:$elm,paramsP:options.paramsP,val:val,ds:_ds})},"xu-render":async function($elm,val,from_panel){return await func.runtime.render.handle_xu_render({SESSION_ID:options.SESSION_ID,$elm:$elm,$container:options.$container,$root_container:options.$root_container,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,val:val,is_init:options.is_init,from_panel:from_panel})},"xu-show":async function($elm,val){const value=await func.common.get_cast_val(options.SESSION_ID,"common fx","xu-show","bool",val.value);func.runtime.render.apply_visibility($elm,value);return{}},"xu-content":async function($elm,val){try{func.runtime.render.apply_dom_content($elm,val.value,"html")}catch(error){console.warn(error)}return},"xu-text":async function($elm,val){try{func.runtime.render.apply_dom_content($elm,val.value,"text")}catch(error){console.warn(error)}return},"xu-html":async function($elm,val){try{func.runtime.render.apply_dom_content($elm,val.value,"html")}catch(error){console.warn(error)}return},"xu-for":async function($elm,data){return await func.runtime.render.handle_xu_for({SESSION_ID:options.SESSION_ID,$elm:$elm,$live_elm:options.$live_elm||$elm,$container:options.$container,$root_container:options.$root_container,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,data:data})},"xu-for-key":async function($elm,val){return func.runtime.render.set_iterator_name($elm,"iterator_key",val.value)},"xu-for-val":async function($elm,val){return func.runtime.render.set_iterator_name($elm,"iterator_val",val.value)},"xu-class":async function($elm,val){return await func.runtime.render.apply_xu_class({SESSION_ID:options.SESSION_ID,$elm:$elm,paramsP:options.paramsP,val:val})},"xu-on":async function($elm,val){func.runtime.render.bind_xu_event({SESSION_ID:options.SESSION_ID,paramsP:options.paramsP,$elm:$elm,val:val});return{}},"xu-script":async function($elm,val){func.runtime.render.run_inline_script($elm,val.value);return{}},"xu-style-global":async function($elm,val){func.runtime.render.append_style_tag(val.value);return{}},"xu-style":async function($elm,val){const newCSSString=func.runtime.render.scope_css_to_xu_ui($elm,val.value);func.runtime.render.append_style_tag(newCSSString);return{}},"xu-cdn":async function($elm,val){const resources_obj=parse_object_value("xu-cdn",val,"object");const resource_keys=Object.keys(resources_obj);for(let index=0;index<resource_keys.length;index++){const resource=resources_obj[resource_keys[index]];await func.runtime.resources.load_cdn(options.SESSION_ID,resource)}return{}},"xu-ui-plugin":async function($elm,val){const plugins_obj=parse_object_value("xu-ui-plugin",val,"object");const plugin_names=Object.keys(plugins_obj);for(let index=0;index<plugin_names.length;index++){const plugin_name=plugin_names[index];const value=plugins_obj[plugin_name];await func.runtime.resources.run_ui_plugin(options.SESSION_ID,options.paramsP,$elm,plugin_name,value)}return{}},"xu-store":async function($elm,val){try{const fields_obj=parse_object_value("xu-store",val,"object");const field_ids=Object.keys(fields_obj);for(let index=0;index<field_ids.length;index++){const field_id=field_ids[index];func.datasource.add_dynamic_field_to_ds(options.SESSION_ID,options.paramsP.dsSessionP,field_id,fields_obj[field_id])}}catch(err){throw err}return{}},"xu-viewport":async function(){return{}}}};func.runtime.render.build_expression_xu_handler=function(options,common_fx,tag_fx){return async function($elm,val){if(!SESSION_OBJ[options.SESSION_ID].DS_GLB[options.paramsP.dsSessionP])return{};const exp=val.value===null?true:val.value;const xuData=func.runtime.ui.get_data($elm)?.xuData;const exp_ret=await func.expression.get(options.SESSION_ID,exp,options.paramsP.dsSessionP,"UI Attr EXP",SESSION_OBJ[options.SESSION_ID].DS_GLB[options.paramsP.dsSessionP].currentRecordId,null,null,null,null,null,xuData?.iterate_info);return await func.runtime.render.apply_expression_attribute({$elm:$elm,key:val.key,exp_ret:exp_ret,nodeP:options.nodeP,tag_fx:tag_fx,common_fx:common_fx})}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.build_tag_xu_handlers=function(options,common_fx){return{"xu-panel":{program:async function($elm,val){return await func.runtime.render.handle_xu_panel_program({SESSION_ID:options.SESSION_ID,$elm:$elm,$container:options.$container,$root_container:options.$root_container,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,keyP:options.keyP,parent_nodeP:options.parent_nodeP,val:val,is_init:options.is_init,refreshed_ds:options.refreshed_ds,get_params_obj_new:options.get_params_obj_new})},"xu-render":async function($elm,val){return await common_fx["xu-render"]($elm,val,true)},"xu-ref":async function($elm,val){if(!val.value)return{};return await common_fx["xu-ref"](options.$container,val,func.runtime.ui.get_data(options.$container)?.xuData?.xuPanelData?.xuData?.paramsP?.dsSessionP)}},"xu-teleport":{to:async function($elm,val){return await func.runtime.render.handle_xu_teleport({SESSION_ID:options.SESSION_ID,$elm:$elm,$root_container:options.$root_container,nodeP:options.nodeP,parent_infoP:options.parent_infoP,paramsP:options.paramsP,jobNoP:options.jobNoP,is_skeleton:options.is_skeleton,val:val})},"xu-render":async function($elm,val){return await common_fx["xu-render"]($elm,val,true)},"xu-show":async function($elm,val){return await common_fx["xu-show"]($elm,val,true)}}}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.build_common_xu_handlers=function(options,_ds,tag_fx){const common_fx=func.runtime.render.build_base_xu_handlers(options,_ds);common_fx["xu-exp"]=func.runtime.render.build_expression_xu_handler(options,common_fx,tag_fx);return common_fx};func.runtime.render.build_xu_handlers=function(options,_ds){const common_fx=func.runtime.render.build_base_xu_handlers(options,_ds);const tag_fx=func.runtime.render.build_tag_xu_handlers(options,common_fx);common_fx["xu-exp"]=func.runtime.render.build_expression_xu_handler(options,common_fx,tag_fx);return{common_fx:common_fx,tag_fx:tag_fx}};func.runtime=func.runtime||{};func.runtime.ui=func.runtime.ui||{};func.runtime.render=func.runtime.render||{};func.runtime.widgets=func.runtime.widgets||{};func.runtime.render.build_xu_runtime_error=function(options,error,fallback_message){const raw_message=error?.message||error||fallback_message||"Unknown runtime error";const err=error instanceof Error?error:new Error(raw_message);err.xu_func=options?.xu_func;err.node_tag=options?.nodeP?.tagName;err.raw_value=options?.val?.value;err.ui_id=func.runtime?.ui?.get_attr?func.runtime.ui.get_attr(options?.$elm,"xu-ui-id"):null;return err};func.runtime.render.report_xu_runtime_error=async function(options,error,fallback_message){const err=func.runtime.render.build_xu_runtime_error(options,error,fallback_message);const attr_name=options?.val?.key||options?.xu_func||"xu-*";const tag_name=options?.nodeP?.tagName||"unknown";const raw_value=typeof err.raw_value==="string"?err.raw_value:JSON.stringify(err.raw_value);const message=[`${attr_name} failed on <${tag_name}>`,err.message];if(raw_value){message.push(`Value: ${raw_value}`)}if(err.ui_id){message.push(`xu-ui-id: ${err.ui_id}`)}console.error("XUDA RUNTIME",message.join(" | "),err);if(func.utils?.debug_report){await func.utils.debug_report(options?.SESSION_ID,"Slim runtime",message.join(" | "),"E",err)}return{}};func.runtime.render.execute_xu_function=async function(options){if(options.is_skeleton)return;const _ds=SESSION_OBJ[options.SESSION_ID].DS_GLB[options.paramsP.dsSessionP];const handler_bundle=options.handler_bundle||func.runtime.render.build_xu_handlers({...options,$live_elm:options.$live_elm||options.$elm},_ds);const{common_fx,tag_fx}=handler_bundle;if(func.runtime.render.is_xu_tag(options.nodeP.tagName)){if(options.xu_func==="xu-exp"){return await common_fx[options.xu_func](options.$elm,options.val)}if(tag_fx?.[options.nodeP.tagName]?.[options.xu_func]){return await tag_fx[options.nodeP.tagName][options.xu_func](options.$elm,options.val)}console.warn(`attribute ${options.xu_func} not found for ${options.nodeP.tagName}`);return{}}if(xu_isEmpty(func.runtime.ui.get_data(options.$elm))){return{}}if(options.xu_func!=="xu-exp"){func.runtime.render.record_attribute_stat(options.$elm,options.xu_func,options.val.value)}try{if(!common_fx[options.xu_func]){await func.runtime.render.report_xu_runtime_error(options,null,`Unknown xu directive: ${options.xu_func}`);return{}}return await common_fx[options.xu_func](options.$elm,options.val)}catch(error){return await func.runtime.render.report_xu_runtime_error(options,error)}};func.datasource={};func.datasource.create=async function(SESSION_ID,prog_id,dataSourceNoP=null,parentDataSourceNoP,containerIdP,rowIdP,jobNoP,calling_trigger_prop,parameters_raw_obj,NA_isInitP,NA_callingSourceP,calling_jobP,NA_screen_dsP,is_panelP,parameters_obj_inP,static_refreshP,worker_id,NA_eventChangesResults){return new Promise(async function(resolve,reject){if(!prog_id)return reject("Program is empty");var _session=SESSION_OBJ[SESSION_ID];if(!_session.DS_GLB)return reject("DS_GLB not exist");var _prog_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,prog_id);if(!_prog_obj)return reject("Program not found");var args={SESSION_ID:SESSION_ID,prog_id:prog_id,dataSourceNoP:dataSourceNoP,parentDataSourceNoP:parentDataSourceNoP,containerIdP:containerIdP,rowIdP:rowIdP,jobNoP:jobNoP,calling_trigger_prop:calling_trigger_prop,calling_jobP:calling_jobP,is_panelP:is_panelP,parameters_obj_inP:parameters_obj_inP,static_refreshP:static_refreshP,worker_id:worker_id,parameters_raw_obj:parameters_raw_obj};var IS_DATASOURCE_REFRESH=null;var _ds=_session.DS_GLB[dataSourceNoP];var old_dataSource_vars={};if(_ds)IS_DATASOURCE_REFRESH=true;if(IS_DATASOURCE_REFRESH){old_dataSource_vars.sortOrder=_ds.sortOrder;old_dataSource_vars.sortOrderTypeExp=_ds.sortOrderTypeExp;if(_ds.data_system){old_dataSource_vars.SYS_OBJ_WIN_MODE=_ds.data_system.SYS_OBJ_WIN_MODE;old_dataSource_vars.SYS_STR_WIN_ID=_ds.data_system.SYS_STR_WIN_ID;old_dataSource_vars.SYS_STR_WIN_NAME=_ds.data_system.SYS_STR_WIN_NAME}if(static_refreshP)old_dataSource_vars.in_parameters=_ds.in_parameters;await func.datasource.update(SESSION_ID,{[dataSourceNoP]:{["datasource_main"]:{stat:"busy",stat_ts:Date.now(),is_worker:glb.IS_WORKER}}})}const restore_old_dataSource_vars=function(dsSessionP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];if(_ds.data_system){_ds.data_system.SYS_OBJ_WIN_MODE=old_dataSource_vars.SYS_OBJ_WIN_MODE;_ds.data_system.SYS_STR_WIN_ID=old_dataSource_vars.SYS_STR_WIN_ID;_ds.data_system.SYS_STR_WIN_NAME=old_dataSource_vars.SYS_STR_WIN_NAME}if(static_refreshP)_ds.in_parameters=old_dataSource_vars.in_parameters};var run_at=_prog_obj?.properties?.runAt;if(_session.opt.app_computing_mode==="main"){run_at="client"}if(_prog_obj?.properties.menuType==="globals"){run_at="client"}if(!run_at&&parentDataSourceNoP&&_session.DS_GLB[parentDataSourceNoP]){if(_session.DS_GLB[parentDataSourceNoP]._run_at)run_at=_session.DS_GLB[parentDataSourceNoP].v.run_at}const done=function(SESSION_ID,dsSessionP,response_returned_from_worker){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];if(IS_DATASOURCE_REFRESH){restore_old_dataSource_vars(dsSessionP)}if(!IS_DATASOURCE_REFRESH){if(!glb.IS_WORKER){DATASOURCE_INTERVALS[SESSION_ID][dsSessionP]=new func.datasource.interval(SESSION_ID,dsSessionP,"client_interval");DATASOURCE_INTERVALS[SESSION_ID][dsSessionP].init()}}const set_stat_idle=async function(){let ds_connected=[];for(const[dsP,_ds]of Object.entries(_session.DS_GLB)){if(_ds.parentDataSourceNo==dsSessionP){ds_connected.push(dsP)}}const datasource_changes={[dsSessionP]:{["datasource_main"]:{stat:"idle",stat_ts:Date.now(),is_worker:glb.IS_WORKER}}};if(!ds_connected.length){return await func.datasource.update(SESSION_ID,datasource_changes)}let interval=setInterval(()=>{let idle_count=0;for(const dsSession of ds_connected){const _ds=_session.DS_GLB[dsSession];if(_ds.stat=="idle"){idle_count++}}if(ds_connected.length===idle_count){clearInterval(interval);func.datasource.update(SESSION_ID,datasource_changes)}},1e3)};set_stat_idle();resolve({SESSION_ID:SESSION_ID,dsSessionP:dsSessionP,rowIdP:_ds.args.rowIdP,jobNoP:_ds.args.jobNoP,callingLogId:_ds.callingLogId,calling_jobP:_ds.calling_jobP})};var db_driver;var is_system_client_vars=false;if(jobNoP){}if(glb.IS_WORKER||run_at==="client"||is_system_client_vars||db_driver==="pouchdb"){const ret=await func.datasource.prepare(args.SESSION_ID,args.prog_id,args.dataSourceNoP,args.parentDataSourceNoP,args.containerIdP,args.rowIdP,args.jobNoP,args.calling_trigger_prop,args.parameters_raw_obj,null,null,args.calling_jobP,null,args.is_panelP,args.parameters_obj_inP,args.static_refreshP,run_at,worker_id);return done(SESSION_ID,ret.dsSessionP)}if(_ds)IS_DATASOURCE_REFRESH=true;var data=Object.assign({session_id:SESSION_ID,dataSourceSessionGlobal:SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal,parentDataSourceNo:IS_DATASOURCE_REFRESH?_ds.parentDataSourceNo:null,IS_DATASOURCE_REFRESH:IS_DATASOURCE_REFRESH},args);delete data.SESSION_ID;const jsonP=await func.index.call_worker(SESSION_ID,{service:"datasource_create",data:data,id:SESSION_OBJ[SESSION_ID].worker_id});_session.DS_GLB[jsonP.dsSession]=jsonP;if(jsonP.dataSourceSessionGlobal>_session.dataSourceSessionGlobal){_session.dataSourceSessionGlobal=jsonP.dataSourceSessionGlobal}return done(SESSION_ID,jsonP.dsSession,true)})};func.datasource.prepare=async function(SESSION_ID,prog_id,dataSourceNoP,parentDataSourceNoP,containerIdP,rowIdP,jobNoP,calling_trigger_prop,parameters_raw_obj,NA_isInitP,callingSourceP,calling_jobP,NA_screen_dsP,is_panelP,parameters_obj_inP,static_refreshP,run_atP,worker_id){const set_parameters=async function(){var _session=SESSION_OBJ[SESSION_ID];const get_Out_parameters=async function(fieldIdP,located_field_param_idxP,param_row_idP){var ret=parameters_obj_inP?.[fieldIdP]||fieldIdP;PARAM_OUT_INFO[prog_id+"_"+param_row_idP]={module:_ds.viewModule,action:"parameters",prop:"out",details:ret,result:ret,source:_ds.viewSourceDesc,type:"parameters",prog_id:prog_id,dsSession:dataSourceSession,fieldId:fieldIdP,parentDataSourceNo:parentDataSourceNoP};return ret};const screenInfo=await func.utils.get_screen_obj(SESSION_ID,prog_id);if(screenInfo?.properties?.progParams){if(!xu_isEmpty(screenInfo.properties.progParams)){_ds.in_parameters={};_ds.out_parameters={};for await(let[key,val]of Object.entries(screenInfo.properties?.progParams)){if(val.data.dir==="in"){_ds.in_parameters[val.data.parameter]={type:val.data.type};if(typeof parameters_obj_inP?.[val.data.parameter]!=="undefined"){_ds.in_parameters[val.data.parameter].value=parameters_obj_inP[val.data.parameter]}else if(["live_preview","miniapp"].includes(_session.engine_mode)){_ds.in_parameters[val.data.parameter].value=_session?.url_params?.[val.data.parameter]}continue}if(val.data.dir==="out"&&val.data.parameter){_ds.out_parameters[val.data.parameter]=await get_Out_parameters(val.data.parameter,key,val.id)}}_ds.PARAM_OUT_INFO=PARAM_OUT_INFO}}};const build_GLOBAL_SYS_fields=function(){if(!_ds.data_system)_ds.data_system={};_ds.data_system["SYS_GLOBAL_UTC"]=-(new Date).getTimezoneOffset()/60;_ds.data_system["SYS_GLOBAL_STR_APP_ID"]=APP_OBJ[_session.app_id]._id;_ds.data_system["SYS_GLOBAL_STR_SESSION_ID"]=SESSION_ID;_ds.data_system["SYS_GLOBAL_STR_LOGIN_USER_ID"]=_session.USR_OBJ._id;if(!["live_preview","miniapp"].includes(_session.engine_mode)&&PROJECT_OBJ[_session.app_id].info){_ds.data_system["SYS_GLOBAL_OBJ_APP_INFO"]={build:PROJECT_OBJ[_session.app_id].info.build_id,author:PROJECT_OBJ[_session.app_id].info.author,date:PROJECT_OBJ[_session.app_id].info.build_date,name:APP_OBJ[_session.app_id].app_name}}_ds.data_system["SYS_GLOBAL_OBJ_LOGIN_USER_INFO"]={id:_session.USR_OBJ._id,user_name:_session.USR_OBJ.usr_name,first_name:_session.USR_OBJ.usr_first_name,last_name:_session.USR_OBJ.usr_last_name,email:_session.USR_OBJ.usr_email,profile_picture:_session.USR_OBJ.usr_profile_picture};_ds.data_system["SYS_GLOBAL_STR_BROWSER_HASH_ID"]=_session.SYS_GLOBAL_STR_BROWSER_HASH_ID;_ds.data_system["SYS_GLOBAL_STR_BROWSER_TITLE"]=_session.SYS_GLOBAL_STR_BROWSER_TITLE;_ds.data_system["SYS_GLOBAL_STR_SITE_CSS"]={};_ds.data_system["SYS_GLOBAL_BOL_SHIFT_KEY_STATE"]=0;_ds.data_system["SYS_GLOBAL_BOL_COMMAND_KEY_STATE"]=0;_ds.data_system["SYS_GLOBAL_BOL_CONTROL_KEY_STATE"]=0;_ds.data_system["SYS_GLOBAL_BOL_ALT_KEY_STATE"]=0;_ds.data_system["SYS_GLOBAL_BOL_ONLINE"]=0;_ds.data_system["SYS_GLOBAL_BOL_REPLICATION_STAT"]=0;_ds.data_system["SYS_GLOBAL_BOL_AJAX_BUSY"]=0;_ds.data_system["SYS_GLOBAL_BOL_CONNECTED"]=1;_ds.data_system["SYS_GLOBAL_BOL_IDLE"]=0;_ds.data_system["SYS_GLOBAL_STR_FIREBASE_TOKEN_ID"]=0;_ds.data_system["SYS_GLOBAL_BOL_PUSH_NOTIFICATION_GRANTED"]=_session.PUSH_NOTIFICATION_GRANTED;_ds.data_system["SYS_GLOBAL_OBJ_FIREBASE_AUTH_INFO"]=_session.SYS_GLOBAL_OBJ_FIREBASE_AUTH_INFO;_ds.data_system["SYS_GLOBAL_OBJ_CLIENT_INFO"]=_session.SYS_GLOBAL_OBJ_CLIENT_INFO;_ds.data_system["SYS_GLOBAL_OBJ_REFS"]={}};if(!SESSION_OBJ[SESSION_ID].DS_GLB)return;if(dataSourceNoP&&!SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceNoP]){return func.utils.debug_report(SESSION_ID,"Datasource","Datasource not exist: "+dataSourceNoP,"E")}if(!prog_id){return func.utils.debug_report(SESSION_ID,"Datasource","Program is null","E")}const args={SESSION_ID:SESSION_ID,prog_id:prog_id,dataSourceNoP:dataSourceNoP,parentDataSourceNoP:parentDataSourceNoP,containerIdP:containerIdP,rowIdP:rowIdP,jobNoP:jobNoP,calling_trigger_prop:calling_trigger_prop,calling_jobP:calling_jobP,is_panelP:is_panelP,parameters_obj_inP:parameters_obj_inP,static_refreshP:static_refreshP,run_atP:run_atP,worker_id:worker_id,parameters_raw_obj:parameters_raw_obj};var dataSourceSession=null;var IS_DATASOURCE_REFRESH=null;var PARAM_OUT_INFO={};const init_dataSource=async function(){const init_new_dataSource=async function(){if(!["main"].includes(SESSION_OBJ[SESSION_ID].opt.app_computing_mode)&&run_atP==="client"&&prog_id!=="system"){const ret=await func.index.call_worker(SESSION_ID,{service:"get_dataSourceSessionGlobal",data:{session_id:SESSION_ID},id:SESSION_OBJ[SESSION_ID].worker_id});SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal=ret?.new_dataSourceSessionGlobal||1}else{SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal++}dataSourceSession=SESSION_OBJ[SESSION_ID].dataSourceSessionGlobal;SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession]={data_feed:{rows:[]}}};const init_existing_dataSource=function(){let _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceNoP];console.log("DATASOURCE_REFRESH",dataSourceNoP);IS_DATASOURCE_REFRESH=true;_ds.refreshed=true;if(_ds.watcher){xu_set(_ds,_ds.watcher.path,_ds.watcher.newValue)}try{if(!_ds.v)_ds.v={};delete _ds.v.old_dataSource;delete _ds.rows_found;_ds.data_feed={};_ds.v.old_dataSource=structuredClone(_ds)}catch(err){console.error("function: init_existing_dataSource - error");return}dataSourceSession=dataSourceNoP};if(typeof dataSourceNoP==="undefined"||dataSourceNoP===null){await init_new_dataSource()}else{init_existing_dataSource()}return SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession]};var _ds=await init_dataSource();_ds.stat="busy";_ds._run_at=run_atP;if(_ds.refreshed){await func.datasource.update(SESSION_ID,{[_ds.dsSession]:{["datasource_main"]:{stat:"busy",stat_ts:Date.now(),is_worker:glb.IS_WORKER}}})}if(IS_DATASOURCE_REFRESH){if(!static_refreshP)await set_parameters();return func.datasource.execute(SESSION_ID,dataSourceSession,true)}_ds.tree_obj=await func.utils.TREE_OBJ.get(SESSION_ID,prog_id);if(!_ds.tree_obj){return func.utils.debug_report(SESSION_ID,"Datasource","Program not exist: "+prog_id,"E")}await func.datasource.set_VIEW_data(SESSION_ID,args,_ds);if(!_ds.v.viewSourceDesc){_ds.v.viewSourceDesc=callingSourceP}if(dataSourceSession===0)_ds.v.viewSourceDesc="system startup";var _session=SESSION_OBJ[SESSION_ID];const set_DS_GLB=async function(){_ds.dataSource_init_arr={};_ds.containerId=containerIdP;_ds.jobNoP=jobNoP;_ds.viewSourceDesc=_ds.v.viewSourceDesc;_ds.callingSource=callingSourceP;_ds.calling_jobP=calling_jobP;_ds.viewModule=_ds.v.viewModule;_ds.viewSourceProp=_ds.v.viewSourceProp;_ds.dsSession=dataSourceSession;_ds.args=args;_ds.worker_id=worker_id;_ds.prog_id=prog_id;_ds.parentDataSourceNo=parentDataSourceNoP};await set_DS_GLB();if(prog_id==="system"&&!parentDataSourceNoP){build_GLOBAL_SYS_fields()}await set_parameters();_ds.client_interval=func.datasource.get_event_interval_arr(SESSION_ID,dataSourceSession,"client_interval");if(prog_id==="system"){_ds.server_interval=func.datasource.get_event_interval_arr(SESSION_ID,dataSourceSession,"server_interval")}let ret_execute=await func.datasource.execute(SESSION_ID,dataSourceSession);return ret_execute};func.datasource.execute=async function(SESSION_ID,dataSourceSession,IS_DATASOURCE_REFRESH){var _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dataSourceSession];var args=_ds.args;let tree_obj=await func.utils.TREE_OBJ.get(SESSION_ID,_ds.prog_id);let prog_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);const callback_datasource=async function(){const run_on_load_events=async function(){if(!await func.datasource.get_view_events_count(SESSION_ID,dataSourceSession,"on_load")){return false}await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"on_load");return true};const schedule_panel_on_load_events=function(){setTimeout(async function(){try{await run_on_load_events()}catch(error){console.error(error)}},0)};if(typeof IS_WORKER==="undefined"&&typeof IS_DOCKER==="undefined"&&typeof IS_PROCESS_SERVER==="undefined"&&_ds.viewSourceProp==="globals"){if(!["main"].includes(_session.opt.app_computing_mode)){await func.index.call_worker(SESSION_ID,{service:"create_webworker_globals",data:{ds_data:_ds,session_id:SESSION_ID}})}}if(args.is_panelP){const callback_ret=await func.datasource.callback(SESSION_ID,dataSourceSession,args.rowIdP,args.jobNoP,_ds.prog_id);schedule_panel_on_load_events();return callback_ret}await run_on_load_events();return await func.datasource.callback(SESSION_ID,dataSourceSession,args.rowIdP,args.jobNoP,_ds.prog_id)};const get_limit=async function(){var ret=0;let tree_ret=await func.utils.TREE_OBJ.get(SESSION_ID,_ds.prog_id);if(tree_ret.menuType==="get_data"){return 1}ret=_ds.progDataSource?.dataSourceLimit;if(prog_obj.progDataSource?.dataSourceLoopExp){ret=(await func.expression.get(SESSION_ID,prog_obj.progDataSource.dataSourceLoopExp,dataSourceSession,"view_loop",args.rowIdP)).result}return ret};const get_skip=async function(){var ret=0;ret=_ds.progDataSource?.dataSourceSkip;if(prog_obj.progDataSource?.dataSourceSkipExp){ret=(await func.expression.get(SESSION_ID,prog_obj.progDataSource.dataSourceSkipExp,dataSourceSession,"view_loop",args.rowIdP)).result}return ret};const calc_batch_loops=async()=>{if(!prog_obj.progDataSource?.dataSourceType||_ds.progDataSource.dataSourceType==="none"){_ds.v.batch_loops=await get_limit();return false}_ds.v.batch_loops=await get_limit()<=_ds.v.raw_data?.rows?.length?await get_limit():_ds.v.raw_data?.rows?.length;return true};const render_api_output=async function(){if(prog_obj?.scriptData?.value){var exp=await func.expression.get(SESSION_ID,prog_obj.scriptData.value,dataSourceSession,"api_rendered_output",null,null,null,null,null,null,null,null,null,tree_obj.apiOutput);let output_result=exp.result;if(tree_obj.apiOutput==="json"){try{let output_result_obj=await func.expression.secure_eval(SESSION_ID,"api_rendered_output","("+output_result+")",null,dataSourceSession);output_result=JSON.stringify(output_result_obj)}catch(err){console.error(err)}}_ds.api_rendered_output+=output_result+(tree_obj.apiOutput==="json"?",":"")}else{_ds.api_rendered_output=""}};if(_ds.prog_id==="system"){_ds.currentRecordId="dataset";await func.datasource.render_fields_dataset(SESSION_ID,dataSourceSession,{id:"dataset",value:_session.url_params});return await callback_datasource()}let db_adapter_module;if(prog_obj.progDataSource?.dataSourceType){db_adapter_module=await func.common.get_module(SESSION_ID,"xuda-datasource-db-adapter-module.mjs")}const get_data_from_source=async function(){switch(prog_obj.progDataSource.dataSourceSrcType){case"input":{const{result,error}=await func.expression.get(SESSION_ID,prog_obj.progDataSource.progDataSourceInput,dataSourceSession,"datasource select");if(error){func.utils.debug_report(SESSION_ID,"Data source",`Datasource parse error using ${prog_obj.progDataSource?.dataSourceType} input`,"E");return null}return result;break}case"url":{let opt={method:prog_obj.progDataSource.dataSourceMethod||"POST",headers:{Accept:"application/json","Content-Type":"application/json"}};let data={};if(prog_obj.progDataSource.dataSourceMethod=="POST"&&prog_obj.progDataSource.dataSourceParameters){for(let val of prog_obj.progDataSource.dataSourceParameters){data[val.key]=val.val}opt.body=JSON.stringify(data)}try{const response=await fetch("https://"+prog_obj.progDataSource.dataSourceDataUrl,opt);const json=await response.json();return json.data}catch(err){func.utils.debug_report(SESSION_ID,"Data source",err.message+" https://"+prog_obj.progDataSource.dataSourceDataUrl,"E");return null}break}default:return null;break}};if(!_ds.v.raw_data){_ds.v.raw_data={rows:[]}}_ds.data_feed.rows=[];switch(prog_obj.progDataSource?.dataSourceType){case"table":{_ds._dataSourceTableId=prog_obj.progDataSource?.dataSourceTableId;if(prog_obj.progDataSource?.dataSourceTableIdExp){_ds.v.dataSourceTableIdExp=await func.expression.get(SESSION_ID,prog_obj.progDataSource?.dataSourceTableIdExp,dataSourceSession,"dataSourceTableIdExp",args.rowIdP);if(_ds.v.dataSourceTableIdExp.result){_ds._dataSourceTableId=_ds.v.dataSourceTableIdExp.result}else{func.utils.debug_report(SESSION_ID,"get_VIEW_data","Table Expression returned empty result","W")}}if(!_ds._dataSourceTableId){return func.utils.debug_report(SESSION_ID,"Data source","Table cannot be empty when Db Table selected","E")}let table_ret=await func.utils.TREE_OBJ.get(SESSION_ID,_ds._dataSourceTableId);if(!table_ret){return func.utils.debug_report(SESSION_ID,"Data source","Table not found: "+_ds._dataSourceTableId,"E")}await db_adapter_module.build_filter(SESSION_ID,dataSourceSession,_ds.v,_ds);let filterModelMongo=_ds.progDataSource.filterModelMongo;if(_ds.progDataSource.filterModelMongoFx){let ret=await func.expression.get(SESSION_ID,_ds.progDataSource.filterModelMongoFx,dataSourceSession,"query");filterModelMongo=ret.result}let filterModelSql=_ds.progDataSource.filterModelSql;if(_ds.progDataSource.filterModelSqlFx){let ret=await func.expression.get(SESSION_ID,_ds.progDataSource.filterModelSqlFx,dataSourceSession,"query");filterModelSql=ret.result}const filterModel={filterModelNative:_ds.progDataSource.filterModelNative,filterModelMongo:filterModelMongo,filterModelSql:filterModelSql,filterModelUserMongo:_ds.progDataSource.filterModelUserMongo,filterModelUserSql:_ds.progDataSource.filterModelUserSql};let _dataSourceFilterModelType=_ds?.progDataSource?.dataSourceFilterModelType;if(_ds?.progDataSource?.dataSourceFilterModelTypeFx){const fx_ret=await func.expression.get(SESSION_ID,_ds.progDataSource.dataSourceFilterModelTypeFx,dataSourceSession,"query");_dataSourceFilterModelType=fx_ret.result}if(_dataSourceFilterModelType&&!["query","index"].includes(_dataSourceFilterModelType)){return func.utils.debug_report(SESSION_ID,"Data source",`Valid values for dataSourceFilterModelType are: "query" or "index" (${_dataSourceFilterModelType})`,"E")}_ds.v.raw_data=await func.db.get_query(SESSION_ID,_ds._dataSourceTableId,_ds.v.couchView,dataSourceSession,_ds.viewSourceDesc,"datasource table",prog_obj.progDataSource.dataSourceReduce,await get_skip(),await get_limit()||99999999,null,null,_ds?.progDataSource?.sortModel,null,filterModel,_dataSourceFilterModelType);if(_dataSourceFilterModelType==="index"&&_ds?.progDataSource?.sortModel){function sortByKeys(array,sortConfig){return array.sort((a,b)=>{for(let config of sortConfig){const key=config.field_id;const direction=config.sort_dir==="desc"?-1:1;const valA=a.value[key];const valB=b.value[key];if(typeof valA==="number"&&typeof valB==="number"){if(valA!==valB){return(valA-valB)*direction}}else if(typeof valA==="string"&&typeof valB==="string"){if(valA!==valB){return valA.localeCompare(valB)*direction}}}return 0})}const sorted=sortByKeys(_ds.v.raw_data.rows,_ds.progDataSource.sortModel);_ds.v.raw_data.rows=sorted}if(_ds?.progDataSource?.dataSourceLimit){const ret_rows_found=await func.db.get_query(SESSION_ID,_ds._dataSourceTableId,_ds.v.couchView,dataSourceSession,_ds.viewSourceDesc,"datasource table",prog_obj.progDataSource.dataSourceReduce,null,null,true,null,null,null,filterModel,_dataSourceFilterModelType);_ds.rows_found=ret_rows_found?.rows?.[0]?.value||0;_ds.rows_found_opt=ret_rows_found?.opt}else{_ds.rows_found=_ds?.v?.raw_data?.rows?.length||0;_ds.rows_found_opt=_ds?.v?.raw_data?.opt}break}case"array":{let data=await get_data_from_source();if(data===null){data=[]}_ds.rows_found=data?.length||0;let _KEY=0;for(const _VAL of data){_ds.v.raw_data.rows.push({id:_KEY,value:{_KEY:_KEY,_VAL:_VAL}});_KEY++}break}case"json":{let data=await get_data_from_source();if(data===null){data={}}_ds.rows_found=Object.keys(data)?.length||0;for(let[_KEY,_VAL]of Object.keys(data)){_ds.v.raw_data.rows.push({id:_KEY,value:{_KEY:_KEY,_VAL:_VAL}})}break}case"csv":{let data=await get_data_from_source();if(data===null){data=""}let _KEY=0;let arr=data.split(",");for(const _VAL of arr){_ds.v.raw_data.rows.push({id:_KEY,value:{_KEY:_KEY,_VAL:_VAL}});_KEY++}_ds.rows_found=arr?.length||0;break}default:break}let ret;const get_before_record_count=async()=>{return await func.datasource.get_view_events_count(SESSION_ID,dataSourceSession,"before_record")};const get_after_record_count=async()=>{return await func.datasource.get_view_events_count(SESSION_ID,dataSourceSession,"after_record")};let _raw_data_rows=[];switch(tree_obj.menuType){case"api":{_ds.api_rendered_output="";let has_datasource=await calc_batch_loops();_raw_data_rows=_ds.v.raw_data.rows||[];if(!has_datasource){for(n=0;n<_ds.v.batch_loops;n++){_raw_data_rows.push({id:n,value:{}})}}_ds.currentRecordId="dataset";for await(let[key,raw_data_row]of Object.entries(_raw_data_rows)){if(has_datasource&&Number(key)>=_ds.v.batch_loops)break;if(!has_datasource){raw_data_row=_ds?.v.raw_data?.rows?.[key]||{id:key,value:{}}}if(await get_before_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"before_record")}await func.datasource.render_fields_dataset(SESSION_ID,dataSourceSession,raw_data_row);if(await get_after_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"after_record")}await render_api_output()}if(tree_obj.apiOutput==="json"){var str=_ds.api_rendered_output.substring(0,_ds.api_rendered_output.length-1);if(Number(_ds.progDataSource?.dataSourceLimit)===1){_ds.api_rendered_output=str}else{_ds.api_rendered_output="["+str+"]"}}break}case"batch":{let has_datasource=await calc_batch_loops();_raw_data_rows=_ds?.v.raw_data?.rows||[];if(!has_datasource){for(n=0;n<_ds.v.batch_loops;n++){_raw_data_rows.push({id:n,value:{}})}}_ds.currentRecordId="dataset";for await(let[key,raw_data_row]of Object.entries(_raw_data_rows)){if(has_datasource&&Number(key)>=_ds.v.batch_loops)break;if(!has_datasource){raw_data_row=_ds?.v.raw_data?.rows?.[key]||{id:key,value:{}}}if(await get_before_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"before_record")}await func.datasource.render_fields_dataset(SESSION_ID,dataSourceSession,raw_data_row);if(await get_after_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"after_record")}}await func.datasource.set_outputField(SESSION_ID,dataSourceSession,_ds?.v?.raw_data?.rows,_ds.args);break}case"get_data":{if(await get_before_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"before_record")}ret=await db_adapter_module.process_view_dataset(SESSION_ID,dataSourceSession,_ds);if(await get_after_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"after_record")}await func.datasource.set_outputField(SESSION_ID,dataSourceSession,_ds?.v?.raw_data?.rows,_ds.args);break}case"set_data":{if(!prog_obj.progDataSource?.dataSourceType||_ds.progDataSource.dataSourceType!=="table"||!_ds._dataSourceTableId){return func.utils.debug_report(SESSION_ID,"Data source","Datasource DB Table must be defined for Set Data operation","E")}const find_ROWID_idx_from_raw_data_arr=function(rowId){if(!_raw_data_rows){throw new Error("_raw_data_rows not found")}const index=_raw_data_rows.findIndex(item=>item.id===rowId);if(index===-1){throw new Error(`ROWID "${rowId}" not found`)}return index};if(tree_obj.crudMode==="U"){_ds.set_mode="U";_raw_data_rows=_ds?.v.raw_data?.rows||[]}if(tree_obj.crudMode==="D"){_ds.set_mode="D";_raw_data_rows=_ds?.v.raw_data?.rows||[]}if(tree_obj.crudMode==="U"&&tree_obj.allowCreate&&!_raw_data_rows?.length){_ds.set_mode="C";try{const row_idx=find_ROWID_idx_from_raw_data_arr("newRecord");_raw_data_rows[row_idx]=[{id:"newRecord",value:{}}]}catch(error){_raw_data_rows.push({_ROWID:"newRecord"})}}if(tree_obj.crudMode==="C"){_ds.set_mode="C";try{const row_idx=find_ROWID_idx_from_raw_data_arr("newRecord");_raw_data_rows[row_idx]=[{id:"newRecord",value:{}}]}catch(error){_raw_data_rows.push({id:"newRecord",value:{}})}}for await(let raw_data_row of _raw_data_rows){_ds.currentRecordId=raw_data_row.id;if(await get_before_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"before_record")}await func.datasource.render_fields_dataset(SESSION_ID,dataSourceSession,raw_data_row);let data_feed_str=JSON.stringify(_ds.data_feed);if(await get_after_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"after_record")}if(_ds.set_mode==="C"||JSON.stringify(_ds.data_feed)!==data_feed_str){const dbMsgP=await func.db.save_data(SESSION_ID,dataSourceSession);if(dbMsgP)_ds.currentRecordId=dbMsgP.id;_ds.set_mode="U"}if(_ds.set_mode==="D"){const dbMsgP=await func.db.save_data(SESSION_ID,dataSourceSession);if(dbMsgP)_ds.currentRecordId=dbMsgP.id}}await func.datasource.set_outputField(SESSION_ID,dataSourceSession,_ds?.v?.raw_data?.rows,_ds.args);break}case"component":{_raw_data_rows=_ds?.v.raw_data?.rows||[];_ds.rows_processed=0;_ds.viewRangeExp_rows_deleted=0;let rows=_ds?.v.raw_data?.rows?.length;_ds.data_feed.rows_changed=[];_ds.data_feed.rows_deleted=[];_ds.data_feed.rows_added=[];if(tree_obj.rwMode==="U"){_ds.set_mode="U"}else{_ds.set_mode="R"}const row_not_found=async function(){if(!prog_obj.progDataSource?.dataSourceType||prog_obj.properties.renderType==="form"||tree_obj.rwMode==="U"&&tree_obj.allowCreate){_ds.currentRecordId="newRecord";if(tree_obj.rwMode==="U"&&tree_obj.allowCreate){_ds.set_mode="C"}if(prog_obj.progDataSource?.dataSourceType){_ds.record_not_found=true}try{const row_idx=func.common.find_ROWID_idx(_ds,_ds.currentRecordId)}catch(error){await func.datasource.render_fields_form(SESSION_ID,dataSourceSession,{id:"newRecord",value:{}})}var count=await func.datasource.get_field_init_count(SESSION_ID,dataSourceSession,"newRecord",false);if(count>0){await func.datasource.execute_field_init_events(SESSION_ID,dataSourceSession,"form","newRecord")}}await func.datasource.callback(SESSION_ID,dataSourceSession,args.rowIdP,args.jobNoP,_ds.prog_id)};if(!rows){await row_not_found();break}_ds.firstRecordId=_raw_data_rows[0].id;const finish_form=async function(){if(_ds.locatedRecordId){try{const row_idx=func.common.find_ROWID_idx(_ds,_ds.locatedRecordId)}catch(error){delete _ds.locatedRecordId}}_ds.finalRecordId=func.datasource.get_currentRecordId(SESSION_ID,dataSourceSession,true);_ds.currentRecordId=_ds.finalRecordId};for await(const[key,raw_data_row]of Object.entries(_raw_data_rows)){const idx=Number(key);if(await get_before_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"before_record")}_ds.currentRecordId=raw_data_row.id;await func.datasource.render_fields_form(SESSION_ID,dataSourceSession,raw_data_row);try{const init_count=await func.datasource.get_field_init_count(SESSION_ID,dataSourceSession,raw_data_row.id,false,_ds.oninit_triggers_to_run);if(init_count>0){await func.datasource.execute_field_init_events(SESSION_ID,dataSourceSession,"form",raw_data_row.id)}}catch(err){console.error(err)}if(await get_after_record_count()){await func.datasource.execute_view_events(SESSION_ID,dataSourceSession,"after_record")}}await finish_form();break}default:return func.utils.debug_report(SESSION_ID,"Data source","Program type not defined","E")}ret=await callback_datasource();return ret};func.datasource.render_fields_dataset=async function(SESSION_ID,dataSourceSession,raw_data_row){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var args=_ds.args;const _progFields=await func.datasource.get_progFields(SESSION_ID,dataSourceSession);if(!_progFields){return}const get_value=async(field_id,value)=>{let view_field_obj=func.common.find_item_by_key(_progFields,"field_id",field_id);var fieldType=view_field_obj?.props?.fieldType;let table_field_obj;if(view_field_obj.data.type==="table"&&field_id!=="REDUCE_VALUE"){if(!_ds.progDataSource?.dataSourceTableId){return func.utils.debug_report(SESSION_ID,"Datasource",`Table type defined without dataSourceTableId deceleration`,"E")}let table_obj=await func.utils.FILES_OBJ.get(SESSION_ID,_ds._dataSourceTableId);if(!table_obj){return func.utils.debug_report(SESSION_ID,"Datasource",`dataSourceTableId reference error: `+_ds._dataSourceTableId,"E")}table_field_obj=func.common.find_item_by_key(table_obj.tableFields,"field_id",field_id);fieldType=table_field_obj.props?.fieldType}return await func.common.get_cast_val(SESSION_ID,`render fields dataset ${_ds.viewSourceDesc}`,field_id,fieldType,value,null)};if(!_ds.data_feed){_ds.data_feed={rows:[{_ROWID:_ds.currentRecordId}]}}let row_idx;try{row_idx=func.common.find_ROWID_idx(_ds,_ds.currentRecordId)}catch(err){_ds.data_feed.rows.push({_ROWID:_ds.currentRecordId});row_idx=func.common.find_ROWID_idx(_ds,_ds.currentRecordId)}_ds.dataset_alias={};for await(const val of _progFields){try{var fieldId=val.data.field_id;if(val.data.type==="virtual"||_ds.set_mode==="C"){if(typeof raw_data_row?.value?.[fieldId]!=="undefined"){_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,raw_data_row.value[fieldId]);continue}if(val.props?.propExpressions?.fieldValue){let ret=await func.expression.get(SESSION_ID,val.props?.propExpressions?.fieldValue,dataSourceSession,"update",args.rowIdP);_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,ret.result);continue}_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,val.props?.fieldValue);continue}if(val.data.type==="table"||val.data.type==="datasource"){if(typeof raw_data_row.value[fieldId]==="undefined"){throw"field do not exist in data: "+fieldId}_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,raw_data_row.value[fieldId])}}catch(err){func.utils.debug_report(SESSION_ID,"Datasource",err,"E",null,_ds)}}};func.datasource.run_events_functions=async function(SESSION_ID,dataSourceSession,event_id,calling_job,async_event,event_parameters){if(typeof dataSourceSession==="undefined"||dataSourceSession===null){console.warn(`Event ${event_id} not exist or not found`);return}var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var args=_ds.args;const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);let job_promises=[];if(_view_obj.progEvents){for await(const[key,val]of Object.entries(_view_obj.progEvents)){if(val.data.type==="user_defined"&&val.data.event_name&&val.data.event_name===event_id){const jobs=await func.events.validate(SESSION_ID,"user_defined",dataSourceSession,val.data.event_name,args.callingSourceP,event_parameters);if(calling_job||async_event)continue;for(let job_num of jobs){job_promises.push(new Promise((resolve,reject)=>{let i=0;const interval=setInterval(()=>{i++;var job_index=func.events.find_job_index(SESSION_ID,job_num);if(job_index==null){clearInterval(interval);resolve(job_num)}if(i>200){console.error("deadlock detected");clearInterval(interval);resolve(job_num)}},100)}))}}}}if(job_promises.length){await Promise.all(job_promises)}};func.datasource.render_fields_form=async function(SESSION_ID,dataSourceSession,raw_data_row){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];const _progFields=await func.datasource.get_progFields(SESSION_ID,dataSourceSession);if(!_progFields){return}const get_value=async(field_id,value)=>{let view_field_obj=func.common.find_item_by_key(_progFields,"field_id",field_id);var fieldType=view_field_obj.props?.fieldType;let table_field_obj;if(view_field_obj.data.type==="table"&&field_id!=="REDUCE_VALUE"){if(!_ds._dataSourceTableId){return func.utils.debug_report(SESSION_ID,"Datasource",`Table type defined without dataSourceTableId deceleration`,"E")}let table_obj=await func.utils.FILES_OBJ.get(SESSION_ID,_ds._dataSourceTableId);if(!table_obj){return func.utils.debug_report(SESSION_ID,"Datasource",`dataSourceTableId reference error: `+_ds._dataSourceTableId,"E")}table_field_obj=func.common.find_item_by_key(table_obj.tableFields,"field_id",field_id);if(!table_field_obj){return func.utils.debug_report(SESSION_ID,"Datasource",`Field Id: ${field_id} not exist in table ${table_obj.properties.menuName}`,"E")}fieldType=table_field_obj.props?.fieldType}return await func.common.get_cast_val(SESSION_ID,`render fields datasource ${_ds.viewSourceDesc}`,field_id,fieldType,value,null)};let row_idx;try{row_idx=func.common.find_ROWID_idx(_ds,raw_data_row.id)}catch(error){_ds.data_feed.rows.push({_ROWID:raw_data_row.id});row_idx=func.common.find_ROWID_idx(_ds,raw_data_row.id)}_ds.dataset_alias={};for await(const val of _progFields){try{var fieldId=val.data.field_id;if(val.data.type==="virtual"||raw_data_row.id==="newRecord"){if(glb.PROTECTED_VARS.includes(fieldId)){switch(fieldId){case"_ROWNO":{_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,row_idx);continue}case"_ROWID":{_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,raw_data_row.id);continue}case"_ROWDOC":{_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,raw_data_row.value);continue}}}if(val.props?.propExpressions?.fieldValue){let ret=await func.expression.get(SESSION_ID,val.props?.propExpressions?.fieldValue,dataSourceSession,"update",raw_data_row.id);_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,ret.result);continue}_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,val.props?.fieldValue);continue}if(val.data.type==="table"||val.data.type==="datasource"){if(typeof raw_data_row.value[fieldId]==="undefined"){throw"field do not exist in data: "+fieldId}_ds.data_feed.rows[row_idx][fieldId]=await get_value(fieldId,raw_data_row.value[fieldId])}}catch(err){func.utils.debug_report(SESSION_ID,"Datasource",err,"E",null,_ds)}}};func.datasource.execute_field_init_events=async function(SESSION_ID,dataSourceSession,sourceP,rowIdP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var args=_ds.args;var arr=_ds.dataSource_init_arr[rowIdP];for await(const val of arr){if(!func.utils.is_onscreen_event(val.eventInfo.data.action)){var cond=val?.eventInfo?.data?.enabled;var expression=undefined;if(val.eventInfo.props.condition)expression=val.eventInfo.props.condition;var expCond={};if(expression&&!xu_isEmpty(expression)){expCond=await func.expression.get(SESSION_ID,expression,dataSourceSession,"condition",rowIdP,null,null,val.fieldId);cond=expCond.result;expCond.conditional=true;val.DEBUG_INFO_OBJ.result=expCond.result;val.DEBUG_INFO_OBJ.error=expCond.error;val.DEBUG_INFO_OBJ.fields=expCond.fields;val.DEBUG_INFO_OBJ.conditional=expCond.conditional;val.DEBUG_INFO_OBJ.details=expression}func.utils.debug.log(SESSION_ID,val.node_id,val.DEBUG_INFO_OBJ);if(cond){if(!_ds)continue;var ds=_ds.prog_id;await func.events.execute(SESSION_ID,null,val.triggerId,val.eventInfo.data.name,val.eventInfo.data.action,val.eventInfo.data.name,null,val.fieldId,val.rowId,val.colId,null,null,dataSourceSession,val.eventInfo.id,sourceP,true,null,null,args.jobNoP,null,null,val.eventInfo,null,null,null,null,ds.parentDataSourceNo,null)}}}};func.datasource.get_field_init_count=async function(SESSION_ID,dataSourceSession,rowIdP,pre_initP,oninit_triggers_to_runP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var args=_ds.args;const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);var ret=0;for await(const field_obj of _view_obj.progFields){var fieldId=field_obj.data.field_id;if(!field_obj?.workflow?.length){continue}for await(const trigger_obj of field_obj.workflow){if(oninit_triggers_to_runP&&!oninit_triggers_to_runP?.includes(trigger_obj.id)){continue}if(["get_data","set_data","batch","update","raise_event"].includes(trigger_obj.data.action)){if(!trigger_obj.data.action){func.utils.debug_report(SESSION_ID,"_ds.get_field_init_count",`Error initiating event for field: ${fieldId} prog: ${_ds.v.viewSourceDesc} row: ${rowIdP} reason: missing action`,"E");break}if(trigger_obj.data.enabled){if(!_ds.dataSource_init_arr[rowIdP]){_ds.dataSource_init_arr[rowIdP]=[]}_ds.dataSource_init_arr[rowIdP].push({eventInfo:trigger_obj,triggerId:trigger_obj.id,fieldId:fieldId,rowId:rowIdP,colId:field_obj.id,node_id:args.prog_id+"_"+trigger_obj.id+"_"+field_obj.id,fieldProp:field_obj,DEBUG_INFO_OBJ:{module:_ds.viewModule,action:"init field event",prop:fieldId,source:_ds.viewSourceDesc,type:"event",prog_id:args.prog_id,dsSession:dataSourceSession}});ret++}}}}return ret};func.datasource.get_view_events_count=async function(SESSION_ID,dataSourceSession,typeP,eventIdP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];const _prog=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(!_ds)return 0;var args=_ds.args;var index=typeP;if(eventIdP)index=typeP+"_"+eventIdP;if(!_ds.viewEventExec_arr)_ds.viewEventExec_arr={};_ds.viewEventExec_arr[index]=[];if(!_prog.progEvents||xu_isEmpty(_prog.progEvents))return 0;for(const event_obj of _prog.progEvents){if(event_obj.data.type!==typeP)continue;if(eventIdP&&event_obj.id!==eventIdP)continue;if(event_obj.data.condition){let res=await func.expression.get(SESSION_ID,event_obj.data.condition,dataSourceSession,"condition",args.rowIdP,null,null,null,null,event_obj);if(!res.result){continue}}if(xu_isEmpty(event_obj.workflow))continue;for(const trigger_obj of event_obj.workflow){if(trigger_obj.data.enabled){var expression;if(trigger_obj.props.condition)expression=trigger_obj.props.condition;var expCond={};if(expression){expCond.conditional=true}func.utils.debug.log(SESSION_ID,args.prog_id+"_"+trigger_obj.id,{module:_ds.viewModule,action:trigger_obj.data.action,prop:event_obj.data.type,details:expression,result:expCond.result,error:expCond.error,source:_ds.viewSourceDesc,fields:expCond.fields,type:"event",prog_id:args.prog_id,dsSession:dataSourceSession,conditional:expCond.conditional})}if(!trigger_obj.data.action){func.utils.debug_report(SESSION_ID,"get_view_events_count",`Error initiating ${typeP} prog:${_ds.v.viewSourceDesc} reason: missing action`,"E");break}if(!glb.REFERENCE_LESS_FUNCTIONS.includes(trigger_obj.data.action)&&!trigger_obj.data.action){func.utils.debug_report(SESSION_ID,"get_view_events_count",`Error initiating ${typeP} prog: ${_ds.v.viewSourceDesc} reason: missing reference`,"E");break}if(trigger_obj.data.enabled){_ds.viewEventExec_arr[index].push({eventInfo:trigger_obj,eventId:event_obj.id,triggerId:trigger_obj.id,expression:expression})}}}return _ds.viewEventExec_arr[index].length};func.datasource.execute_view_events=async function(SESSION_ID,dataSourceSession,typeP,eventIdP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var args=_ds.args;var i=-1;var index=typeP;if(eventIdP)index=typeP+"_"+eventIdP;var arr=_ds.viewEventExec_arr[index];if(xu_isEmpty(arr))return;for await(const val of arr){if(!glb.IS_WORKER||!func.utils.is_onscreen_event(val.eventInfo.data.action)||glb.IS_WORKER&&_ds.v.run_at==="server"&&!func.utils.is_onscreen_event(val.eventInfo.data.action)){var cond=true;if(val.expression){var expCond=await func.expression.get(SESSION_ID,val.expression,dataSourceSession,"condition",args.rowIdP,null,null,null,null,val.eventInfo);cond=expCond.result}if(cond){var elem_params=undefined;if(!glb.IS_WORKER){const container_meta=func.runtime.ui.get_meta_by_element_id(_ds.containerId);elem_params=container_meta?.params}const ret=await func.events.execute(SESSION_ID,null,val.triggerId,val.eventInfo.data.trigger,val.eventInfo.data.action,val.eventInfo.data.name,null,null,null,null,val.eventInfo.data.action,null,dataSourceSession,val.eventId,_ds.tree_obj.menuType+" event",true,null,null,args.jobNoP,elem_params,null,val.eventInfo)}continue}if(typeP=="before_record"||typeP=="after_record"||typeP=="on_load"||typeP=="on_exit"){_ds.v.onscreen_events_active={i:i,type:typeP};var parent_ds_chain=func.datasource.get_parent_ds_chain(SESSION_ID,dataSourceSession);var obj={ds_obj:func.utils.clean_returned_datasource(SESSION_ID,dataSourceSession),dsSessionP:dataSourceSession};obj.ds_obj.parent_ds_chain=parent_ds_chain}}};func.datasource.get_parent_ds_chain=function(SESSION_ID,dataSourceSession){var arr=[];var drill=function(ds){if(SESSION_OBJ[SESSION_ID].DS_GLB[ds]){if(typeof SESSION_OBJ[SESSION_ID].DS_GLB[ds].parentDataSourceNo!=="undefined"){arr.push(SESSION_OBJ[SESSION_ID].DS_GLB[ds].parentDataSourceNo);drill(SESSION_OBJ[SESSION_ID].DS_GLB[ds].parentDataSourceNo)}}};drill(dataSourceSession);return arr};func.datasource.execute_onscreen_view_events=async function(SESSION_ID,dataSourceSession,sourceP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var args=_ds.args;var i=_ds.v.onscreen_events_active.i;var type=_ds.v.onscreen_events_active.type;var evnt;if(_ds.viewEventExec_arr?.[type]?.[i]){evnt=_ds.viewEventExec_arr[type][i];evnt.done=true;var cond=true;if(evnt.expression){var expCond=await func.expression.get(SESSION_ID,evnt.expression,dataSourceSession,"condition",args.rowIdP);cond=expCond.result}if(cond){let ret=await func.events.execute(SESSION_ID,null,evnt.triggerId,evnt.eventInfo.data.trigger,evnt.eventInfo.data.action,evnt.eventInfo.data.name,null,null,null,null,evnt.eventInfo.data.name,null,dataSourceSession,null,sourceP+" event",true,null,null,args.jobNoP)}}else console.error("*execute_onscreen_view_events error")};func.datasource.get_event_interval_arr=function(SESSION_ID,dataSourceSession,typeP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var arr=[];var ret=0;if(!_ds.v.progEvents)return 0;for(let val of _ds.v.progEvents){if(val.data.type!==typeP)continue;arr.push([val.id,val.data.properties,val.data.condition])}return arr};func.datasource.clean_all=function(SESSION_ID,dsP){var arr=[dsP];var get_child_ds=function(ds){var arr=[];for(const[key,val]of Object.entries(SESSION_OBJ[SESSION_ID].DS_GLB)){if(val.parentDataSourceNo==ds){arr.push(key);arr=arr.concat(get_child_ds(key))}}return arr};arr=arr.concat(get_child_ds(dsP));for(let val of arr){func.datasource.del(SESSION_ID,val)}};func.datasource.clean=function(SESSION_ID,screenIdP){var arr=[];for(const[key,val]of Object.entries(SESSION_OBJ[SESSION_ID].DS_GLB)){try{const screen_parent_id=val.screenId&&func.runtime?.ui?.get_parent_element_id?func.runtime.ui.get_parent_element_id(val.screenId):null;if(Number(key)>0&&(val.screenId===screenIdP||val.rootScreenId===screenIdP||screen_parent_id===screenIdP||val&&val.parentDataSourceNo&&arr.includes(val.parentDataSourceNo.toString()))){arr.push(key);if(val.screenId&&func.UI?.utils?.screen_blocker)func.UI.utils.screen_blocker(false,val.screenId)}}catch(err){console.warn("func.datasource.clean failed");func.datasource.reset_jobs(SESSION_ID,key,"datasource.clean",err)}}for(let val of arr){func.datasource.del(SESSION_ID,val)}};func.datasource.del=function(SESSION_ID,dsP){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsP]&&SESSION_OBJ[SESSION_ID].DS_GLB[dsP].keep_alive||dsP==0)return;if(DATASOURCE_INTERVALS[SESSION_ID]&&DATASOURCE_INTERVALS[SESSION_ID][dsP]){DATASOURCE_INTERVALS[SESSION_ID][dsP].clear()}const perform_delete=async function(){var response={success:function(jsonP,ajaxP){},error:function(status){console.error("error datasource:"+status)},fail:function(status){console.error("error datasource:"+status)}};var data={session_id:SESSION_ID,dssession:dsP};if(!SESSION_OBJ[SESSION_ID].DS_GLB[dsP])return;if(!glb.IS_WORKER){let _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsP];if(_ds.worker_id){if(RUNTIME_SERVER_WEBSOCKET&&RUNTIME_SERVER_WEBSOCKET_CONNECTED&&(!_session.opt.app_computing_mode||_session.opt.app_computing_mode==="server")){WEB_WORKER[SESSION_ID][_ds.worker_id].emit("message",{service:"close_websocket"})}else{WEB_WORKER[SESSION_ID][_ds.worker_id].worker.terminate()}delete WEB_WORKER[SESSION_ID][_ds.worker_id]}else{const json=await func.index.call_worker(SESSION_ID,{service:"datasource_delete",data:data,id:_ds.worker_id});response.success(json,true)}if(DS_UI_EVENTS_GLB)delete DS_UI_EVENTS_GLB[dsP]}delete SESSION_OBJ[SESSION_ID].DS_GLB[dsP]};var delete_pending_jobs=function(){var arr=[];for(const[key,val]of Object.entries(SESSION_OBJ[SESSION_ID].WORKER_OBJ.jobs)){if(val&&val.dsSessionP==dsP){arr.push(key);func.runtime.ui.clear_screen_blockers()}}for(let val of arr.reverse()){SESSION_OBJ[SESSION_ID].WORKER_OBJ.jobs.splice(val,1)}if(!SESSION_OBJ[SESSION_ID].WORKER_OBJ.jobs.length)SESSION_OBJ[SESSION_ID].WORKER_OBJ.stat=null};if(!glb.IS_WORKER){if(SESSION_OBJ[SESSION_ID].DS_GLB[dsP]){delete SCREEN_BLOCKER_OBJ[SESSION_OBJ[SESSION_ID].DS_GLB[dsP].screenId+"_"+SESSION_OBJ[SESSION_ID].DS_GLB[dsP].callingScreenId];delete_pending_jobs();if(glb.new_xu_render){for(const[ui_cache_key,ui_cache_val]of Object.entries(UI_WORKER_OBJ.xu_render_cache)){if(ui_cache_val.paramsP.dsSessionP===dsP){delete UI_WORKER_OBJ.xu_render_cache[ui_cache_key]}}}}const _nav_node=func.runtime.ui.get_first_node(SESSION_OBJ[SESSION_ID].root_element)?.querySelector?.("xu-nav");if(_nav_node){var ds_obj=func.runtime.ui.get_data(_nav_node)?.xuData?.nav_params;if(ds_obj){delete ds_obj[dsP]}}}perform_delete()};func.datasource.update=async function(SESSION_ID,datasource_changes,update_local_scope_only,avoid_xu_for_refresh,trigger){return new Promise(async(resolve,reject)=>{var _session=SESSION_OBJ[SESSION_ID];if(_session.IS_API||typeof IS_MASTER_WEBSOCKET!=="undefined"||typeof IS_PROCESS_SERVER!=="undefined"){update_local_scope_only=true}if(typeof glb.GLOBAL_VARS==="undefined"){glb.GLOBAL_VARS=(await func.common.get_module(SESSION_ID,"xuda-system-globals-module.mjs")).system_globals}const set_fieldComputed_dependencies=async function(dsNo,field_id,parent_ds){for(const[dsSession,_ds]of Object.entries(_session.DS_GLB)){if(parent_ds!==null){if(_ds.parentDataSourceNo!=parent_ds)continue}else{if(dsSession!=dsNo)continue}let tree_ret=await func.utils.TREE_OBJ.get(SESSION_ID,_ds.prog_id);if(tree_ret.menuType==="component"||tree_ret.menuType==="globals"){const _progFields=await func.datasource.get_progFields(SESSION_ID,dsSession);let fieldComputed_propExpressions,fieldComputed_id;for await(const val of _progFields){const fieldId=val.data.field_id;if(val.data.type!=="virtual"||!val.props.fieldComputed)continue;const _propExpressions=val.props?.propExpressions?.fieldValue;if(_propExpressions&&JSON.stringify(_propExpressions).includes(field_id)){fieldComputed_propExpressions=_propExpressions;fieldComputed_id=fieldId}}if(!fieldComputed_id)return;for(const row of _ds.data_feed?.rows||[]){for(const[key,val]of Object.entries(row)){if(key!==fieldComputed_id)continue;try{let ret=await func.expression.get(SESSION_ID,fieldComputed_propExpressions,dsNo,"update",row._ROWID);const row_idx=func.common.find_ROWID_idx(_ds,row._ROWID);if(_ds.data_feed.rows[row_idx][fieldComputed_id]!==ret.result){_ds.data_feed.rows[row_idx][fieldComputed_id]=ret.result;if(!fields_changed.includes(fieldComputed_id)){fields_changed.push(fieldComputed_id)}if(!datasource_changed.includes(dsSession)){datasource_changed.push(dsSession)}}}catch(err){console.error(err)}}}}await set_fieldComputed_dependencies(dsNo,field_id,dsSession)}};var fields_changed=[];var datasource_changed=[];let client_datasource_changes={};let server_datasource_changes={};const mark_field_changed=async function(dataSource,field_id){if(!fields_changed.includes(field_id)){fields_changed.push(field_id);for(const[_dsSession,_ds]of Object.entries(_session.DS_GLB)){if(_ds.args.parameters_raw_obj){for(const[key,exp]of Object.entries(_ds.args.parameters_raw_obj)){if(exp.includes(field_id)){let ret=await func.expression.get(SESSION_ID,exp,_dsSession,"parameters");_ds.in_parameters[key].value=ret.result}}}}}if(!datasource_changed.includes(dataSource)){datasource_changed.push(dataSource)}};const queue_remote_change=async function(dataSource,record_id,field_id,value,_ds){if(update_local_scope_only){return}let tree_ret=await func.utils.TREE_OBJ.get(SESSION_ID,_ds.prog_id);if(glb.IS_WORKER){if(tree_ret.menuType==="globals"||tree_ret.menuType==="component"){const _progFields=await func.datasource.get_progFields(SESSION_ID,dataSource);let view_field_obj=func.common.find_item_by_key(_progFields,"field_id",field_id);if(!view_field_obj?.data?.serverField&&record_id!=="data_system"){if(!client_datasource_changes[dataSource]){client_datasource_changes[dataSource]={}}if(!client_datasource_changes[dataSource][record_id]){client_datasource_changes[dataSource][record_id]={}}client_datasource_changes[dataSource][record_id][field_id]=value}}}else{if(tree_ret.menuType==="component"&&_ds._run_at!=="client"||tree_ret.menuType==="globals"){if(!server_datasource_changes[dataSource]){server_datasource_changes[dataSource]={}}if(!server_datasource_changes[dataSource][record_id]){server_datasource_changes[dataSource][record_id]={}}server_datasource_changes[dataSource][record_id][field_id]=value}}};const update_xu_ref=function(dataSource){let ret;let _ds_0=_session.DS_GLB[0];for([ref_name,val]of Object.entries(_ds_0.data_system["SYS_GLOBAL_OBJ_REFS"])){if(val.ds.dsSession==dataSource){ret=func.UI.update_xu_ref(SESSION_ID,dataSource,ref_name)}}return ret};for await(const[dataSource,row_data]of Object.entries(datasource_changes)){var _ds=_session.DS_GLB[dataSource];if(!_ds){continue}for(const[record_id,fields_data]of Object.entries(row_data)){for(const[field_id,value]of Object.entries(fields_data)){if(record_id==="datasource_main"){xu_set(_ds,field_id,value);const ret=update_xu_ref(dataSource);if(ret){fields_changed.push(field_id);datasource_changed.push(dataSource)}if(!glb.IS_WORKER&&field_id==="watcher"){if(!server_datasource_changes[dataSource]){server_datasource_changes[dataSource]={}}if(!server_datasource_changes[dataSource][record_id]){server_datasource_changes[dataSource][record_id]={}}server_datasource_changes[dataSource][record_id][field_id]=value;if(!update_local_scope_only){const ret=await func.index.call_worker(SESSION_ID,{service:"update_datasource_changes_from_client",data:{session_id:SESSION_ID,datasource_changes:server_datasource_changes},id:_ds.worker_id})}await func.runtime.ui.refresh_screen({SESSION_ID:SESSION_ID,fields_changed_arr:structuredClone(fields_changed),datasource_changed:datasource_changed[0],fields_changed_datasource:datasource_changed[0],watcher:value})}continue}if(typeof fields_data==="object"){if(glb.GLOBAL_VARS[field_id]){_ds.data_system[field_id]=value;continue}const dynamic_field=_ds?.dynamic_fields?.[field_id];if(dynamic_field){if(!xu_isEqual(dynamic_field.value,value)){dynamic_field.value=value;await set_fieldComputed_dependencies(dataSource,field_id,null);update_xu_ref(dataSource);await queue_remote_change(dataSource,record_id,field_id,value,_ds);await mark_field_changed(dataSource,field_id)}continue}try{const row_idx=func.common.find_ROWID_idx(_ds,record_id);if(!xu_isEqual(_ds.data_feed.rows[row_idx][field_id],value)){_ds.data_feed.rows[row_idx][field_id]=value;await set_fieldComputed_dependencies(dataSource,field_id,null);update_xu_ref(dataSource);await queue_remote_change(dataSource,record_id,field_id,value,_ds);await mark_field_changed(dataSource,field_id);if(!_ds.data_feed.rows_changed){_ds.data_feed.rows_changed=[]}if(!_ds.data_feed.rows_changed.includes(record_id))_ds.data_feed.rows_changed.push(record_id)}}catch(error){}}else if(fields_data==="set"){_ds.currentRecordId=record_id}}}}if(glb.IS_WORKER){if(!update_local_scope_only&&!xu_isEmpty(client_datasource_changes)){func.utils.post_back_to_client(SESSION_ID,"update_client_eventChangesResults_from_worker",_session.worker_id,client_datasource_changes)}}else{if(!update_local_scope_only&&!xu_isEmpty(server_datasource_changes)){const ret=await func.index.call_worker(SESSION_ID,{service:"update_datasource_changes_from_client",data:{session_id:SESSION_ID,datasource_changes:server_datasource_changes},id:_ds.worker_id})}if(fields_changed.length){function findMin(arr){return Math.min(...arr.map(Number))}await func.runtime.ui.refresh_xu_attributes({SESSION_ID:SESSION_ID,fields_arr:structuredClone(fields_changed),jobNoP:null,$elm_to_search:null,dsSession_changed:findMin(datasource_changed),avoid_xu_for_refresh:avoid_xu_for_refresh,trigger:trigger,ignore_screen_blocker:true});await func.runtime.ui.refresh_screen({SESSION_ID:SESSION_ID,fields_changed_arr:structuredClone(fields_changed),datasource_changed:null,fields_changed_datasource:datasource_changed[0]})}}resolve()})};func.datasource.callback=async function(SESSION_ID,dsSessionP,rowIdP,jobNoP,nodeIdP){var _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dsSessionP];try{const row_idx=func.common.find_ROWID_idx(_ds,"dataset");if(_ds.PARAM_OUT_INFO){for(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){if(typeof _ds?.data_feed?.rows?.[row_idx]?.[val.fieldId]==="undefined"){func.utils.alerts.invoke(SESSION_ID,"system_msg","SYS_MSG_0310",val.fieldId,dsSessionP);break}val.result=_ds.data_feed.rows[row_idx][val.fieldId]}}}catch(err){}const datasetOutputField=_ds?.progDataSource?.datasetOutputField;if(datasetOutputField){let ret_get_value=await func.datasource.get_value(SESSION_ID,datasetOutputField,_ds.dsSession);if(ret_get_value.found){let datasource_changes={};if(!datasource_changes[ret_get_value.dsSessionP]){datasource_changes[ret_get_value.dsSessionP]={}}if(!datasource_changes[ret_get_value.dsSessionP][ret_get_value.currentRecordId]){datasource_changes[ret_get_value.dsSessionP][ret_get_value.currentRecordId]={};datasource_changes[ret_get_value.dsSessionP][ret_get_value.currentRecordId][_ds?.progDataSource?.datasetOutputField]=_ds?.data_feed?.rows||[];await func.datasource.update(SESSION_ID,datasource_changes)}}}func.utils.debug.log(SESSION_ID,nodeIdP,{module:_ds.viewModule,action:"close",source:_ds.viewSourceDesc,type:"adapter",prog_id:_ds.prog_id,dsSession:dsSessionP,prop:_ds.log_prop+" "+"adapter"});if(!glb.IS_WORKER)func.runtime.platform.set_cursor(_session.root_element,"default");if(_ds.prog_id){let _ds=_session.DS_GLB[dsSessionP];func.utils.debug.watch(SESSION_ID,_ds.prog_id,"program",{in_parameters:_ds.in_parameters,out_parameters:_ds.out_parameters,data_feed:_ds.data_feed},_ds.tree_obj.menuType)}delete _ds.old_dataSource;return{SESSION_ID:SESSION_ID,dsSessionP:dsSessionP,rowIdP:rowIdP,jobNoP:jobNoP,callingLogId:_ds.callingLogId,calling_jobP:_ds.calling_jobP}};func.datasource.validate_viewRange=async function(SESSION_ID,viewRangeExpP,dsSessionP,rowIdP,sourceP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];if(viewRangeExpP&&_ds){var ret=func.expression.remove_quotes(await func.expression.get(SESSION_ID,viewRangeExpP,dsSessionP,"range",rowIdP));ret.result=func.expression.remove_quotes(ret.result);func.utils.debug.log(SESSION_ID,_ds.prog_id,{module:_ds.viewModule,action:"range Exp",prop:sourceP,details:viewRangeExpP,result:ret.result,error:ret.error,source:_ds.viewSourceDesc,json:ret.explain,fields:ret.fields,dsSession:dsSessionP});_ds.viewRangeExpResults=ret.fields;if(glb.DEBUG_MODE){if(!_ds.debug){_ds.debug={}}if(!_ds.debug.viewRangeExp){_ds.debug.viewRangeExp=[]}_ds.debug.viewRangeExp.push(ret)}return ret.result}else return false};func.datasource.validate_viewLocate=async function(SESSION_ID,viewLocateExpP,dsSessionP,rowIdP,sourceP){if(viewLocateExpP&&_ds){var ret=func.expression.remove_quotes(await func.expression.get(SESSION_ID,viewLocateExpP,dsSessionP,"locate",rowIdP));ret.result=func.expression.remove_quotes(ret.result);func.utils.debug.log(SESSION_ID,_ds.prog_id,{module:_ds.viewModule,action:"locate Exp",prop:sourceP,details:viewLocateExpP,result:ret.result,error:ret.error,source:_ds.viewSourceDesc,json:ret.explain,fields:ret.fields,dsSession:dsSessionP});_ds.viewLocateExpResults=ret.fields;return ret.result}else return false};func.datasource.get_viewFields_for_update_function=function(SESSION_ID,calling_trigger_prop,na,dsSessionP){var viewFields=[];var exp=calling_trigger_prop?.data?.name?.value;if(!exp){return viewFields}const trim_wrapping_braces=function(value){const trimmed=value.trim();if(trimmed.startsWith("{")&&trimmed.endsWith("}")){return trimmed.substring(1,trimmed.length-1)}return trimmed};const strip_wrapping_quotes=function(value){const trimmed=value.trim();const first=trimmed.substring(0,1);const last=trimmed.substring(trimmed.length-1);if((first==="'"||first==='"'||first==="`")&&last===first){return trimmed.substring(1,trimmed.length-1)}return trimmed};const split_top_level=function(value){const parts=[];let current="";let quote=null;let escape=false;let paren_depth=0;let bracket_depth=0;let brace_depth=0;for(let index=0;index<value.length;index++){const char=value[index];if(escape){current+=char;escape=false;continue}if(quote){current+=char;if(char==="\\"){escape=true}else if(char===quote){quote=null}continue}if(char==="'"||char==='"'||char==="`"){quote=char;current+=char;continue}if(char==="(")paren_depth++;if(char===")")paren_depth=Math.max(0,paren_depth-1);if(char==="[")bracket_depth++;if(char==="]")bracket_depth=Math.max(0,bracket_depth-1);if(char==="{")brace_depth++;if(char==="}")brace_depth=Math.max(0,brace_depth-1);if((char===","||char===";")&&!paren_depth&&!bracket_depth&&!brace_depth){if(current.trim()){parts.push(current.trim())}current="";continue}current+=char}if(current.trim()){parts.push(current.trim())}return parts};const find_top_level_colon=function(value){let quote=null;let escape=false;let paren_depth=0;let bracket_depth=0;let brace_depth=0;for(let index=0;index<value.length;index++){const char=value[index];if(escape){escape=false;continue}if(quote){if(char==="\\"){escape=true}else if(char===quote){quote=null}continue}if(char==="'"||char==='"'||char==="`"){quote=char;continue}if(char==="(")paren_depth++;if(char===")")paren_depth=Math.max(0,paren_depth-1);if(char==="[")bracket_depth++;if(char==="]")bracket_depth=Math.max(0,bracket_depth-1);if(char==="{")brace_depth++;if(char==="}")brace_depth=Math.max(0,brace_depth-1);if(char===":"&&!paren_depth&&!bracket_depth&&!brace_depth){return index}}return-1};exp=trim_wrapping_braces(exp.replace(/\n/gi,""));const exp_arr=split_top_level(exp);for(let index=0;index<exp_arr.length;index++){const segment=exp_arr[index];const pos=find_top_level_colon(segment);if(pos===-1){continue}let id=strip_wrapping_quotes(segment.substring(0,pos));const val=segment.substring(pos+1).trim();if(id.substring(0,1)==="@"){id=id.substring(1)}if(!id||!val){continue}viewFields.push({id:id,val:val})}return viewFields};func.datasource.get_value=async function(SESSION_ID,fieldIdP,dsSessionP,rowIdP,org_dsSessionP){const normalize_field_id=function(field_id){if(typeof field_id==="string"){return field_id}if(typeof field_id?.field_id==="string"){return field_id.field_id}if(typeof field_id?.id==="string"){return field_id.id}if(typeof field_id==="number"||typeof field_id==="boolean"||typeof field_id==="bigint"){return field_id.toString()}const coerced=field_id?.toString?.();if(typeof coerced==="string"&&coerced&&coerced!=="[object Object]"){return coerced}return null};const return_missing_value=function(field_id,currentRecordId=null){return{ret:{value:undefined,type:"string",prop:null},dsSessionP:dsSessionP,fieldIdP:field_id,currentRecordId:currentRecordId,found:false}};const return_value=async(field_id,value)=>{const _progFields=await func.datasource.get_progFields(SESSION_ID,dsSessionP);let view_field_obj=func.common.find_item_by_key(_progFields,"field_id",field_id);var fieldType=view_field_obj?.props?.fieldType||"string";var fieldProp=view_field_obj?.props;let table_field_obj;if(view_field_obj?.data?.type==="table"){if(!_ds._dataSourceTableId){return func.utils.debug_report(SESSION_ID,"Datasource",`Table type defined without dataSourceTableId deceleration`,"E")}let table_obj=await func.utils.FILES_OBJ.get(SESSION_ID,_ds._dataSourceTableId);if(!table_obj){return func.utils.debug_report(SESSION_ID,"Datasource",`dataSourceTableId reference error: `+_ds._dataSourceTableId,"E")}table_field_obj=func.common.find_item_by_key(table_obj.tableFields,"field_id",field_id);fieldType=table_field_obj.props?.fieldType;fieldProp=table_field_obj.props}let ret={value:await func.common.get_cast_val(SESSION_ID,`datasource get value ${_ds.tree_obj.menuName}`,fieldIdP,fieldType,value,null),type:fieldType,prop:fieldProp};if(ret.value&&typeof ret.value==="string"&&ret.type!=="exp"){if(/"/.test(ret.value)&&ret.value.indexOf("\\")===-1)ret.value=ret.value.replace(/"/g,'"')}return{ret:ret,dsSessionP:dsSessionP,fieldIdP:field_id,currentRecordId:_ds.currentRecordId,found:typeof value!=="undefined"}};const return_dynamic_value=async(field_id,value)=>{let view_field_obj=_ds.dynamic_fields[field_id];var fieldType=view_field_obj?.props?.fieldType||"string";var fieldProp=view_field_obj?.props;let ret={value:view_field_obj.value,type:fieldType,prop:fieldProp};if(ret.value&&typeof ret.value==="string"&&ret.type!=="exp"){if(/"/.test(ret.value)&&ret.value.indexOf("\\")===-1)ret.value=ret.value.replace(/"/g,'"')}return{ret:ret,dsSessionP:dsSessionP,fieldIdP:field_id,currentRecordId:_ds.currentRecordId,found:typeof value!=="undefined"}};const return_value_parameters=async(field_id,value)=>{let ret={value:await func.common.get_cast_val(SESSION_ID,"datasource get value",fieldIdP,value.type,value.value,null),type:value.type,prop:null};if(ret.value&&typeof ret.value==="string"&&ret.type!=="exp"){if(!ret.value.includes("<svg xmlns=")&&/"/.test(ret.value)&&ret.value.indexOf("\\")===-1)ret.value=ret.value.replace(/"/g,'"')}return{ret:ret,dsSessionP:dsSessionP,fieldIdP:field_id,currentRecordId:_ds.currentRecordId,found:typeof value!=="undefined"}};const return_value_system=async(field_id,value)=>{let fieldType=glb.GLOBAL_VARS[field_id].type;let fieldProp=null;let ret={value:await func.common.get_cast_val(SESSION_ID,`datasource get value ${_ds.tree_obj.menuName}`,field_id,fieldType,value,null),type:fieldType,prop:fieldProp};return{ret:ret,dsSessionP:dsSessionP,fieldIdP:field_id,currentRecordId:_ds.currentRecordId,found:typeof value!=="undefined"}};const search_in_parameters=async field_id=>{if(typeof _ds?.in_parameters?.[field_id]?.value!=="undefined"){let ret=await return_value_parameters(field_id,_ds.in_parameters[field_id]);return ret}if(typeof _ds.parentDataSourceNo!=="undefined"){var org_dsSession=org_dsSessionP;if(!org_dsSessionP)org_dsSession=dsSessionP;if(recordId&&recordId!=="newRecord")org_dsSession=null;return await func.datasource.get_value(SESSION_ID,fieldIdP,_ds.parentDataSourceNo,recordId,org_dsSession)}return await return_value(field_id)};if(typeof glb.GLOBAL_VARS==="undefined"){glb.GLOBAL_VARS=(await func.common.get_module(SESSION_ID,"xuda-system-globals-module.mjs")).system_globals}var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];if(!_ds){if(dsSessionP>0){return await func.datasource.get_value(SESSION_ID,fieldIdP,dsSessionP-1,rowIdP,org_dsSessionP)}const normalized_missing_field=normalize_field_id(fieldIdP);if(normalized_missing_field===null){return return_missing_value(fieldIdP)}fieldIdP=normalized_missing_field;return await return_value(fieldIdP)}const normalized_field_id=normalize_field_id(fieldIdP);if(normalized_field_id===null){func.utils.debug_report(SESSION_ID,"Datasource get value",`Invalid field id type: ${typeof fieldIdP}`,"W");return return_missing_value(fieldIdP,_ds.currentRecordId)}fieldIdP=normalized_field_id;let recordId=rowIdP;if(!recordId){recordId=_ds.currentRecordId}if(glb.GLOBAL_VARS[fieldIdP]){if(!_ds.data_system){_ds.data_system={}}if(dsSessionP>0){_ds.data_system["SYS_STR_ACTIVE_ROW_ID"]=_ds.currentRecordId;_ds.data_system["SYS_STR_PROG_DS_SESSION"]=dsSessionP}if(glb.SYS_DATE_ARR.includes(fieldIdP)){var _ds_0=SESSION_OBJ[SESSION_ID].DS_GLB[0];if(_ds_0){if(!_ds_0.data_system){_ds_0.data_system={}}const ts=await func.utils.get_dateTime(SESSION_ID,"SYS_DATE_VALUE");for(const val of glb.SYS_DATE_ARR){_ds_0.data_system[val]=await func.utils.get_dateTime(SESSION_ID,val,ts)}}}if(typeof _ds?.data_system?.[fieldIdP]!=="undefined"){return await return_value_system(fieldIdP,_ds?.data_system?.[fieldIdP])}return await search_in_parameters(fieldIdP)}if(!_ds.data_feed){return await search_in_parameters(fieldIdP)}var _field_id=fieldIdP;if(fieldIdP.substr(0,1)==="_"){if(_ds.alias)_field_id=_ds.alias[fieldIdP]}if(typeof _ds?.dynamic_fields?.[_field_id]!=="undefined"){return await return_dynamic_value(_field_id,_ds.dynamic_fields[_field_id])}if(!org_dsSessionP&&recordId){try{const row_idx=func.common.find_ROWID_idx(_ds,recordId);if(typeof _ds.data_feed?.rows?.[row_idx]?.[_field_id]!=="undefined"){if(Object.keys(_ds.data_feed?.rows?.[row_idx]||{})?.includes(_field_id)){return await return_value(_field_id,_ds.data_feed.rows[row_idx][_field_id])}if(Object.keys(_ds?.dynamic_fields||{})?.includes(_field_id)){return await return_dynamic_value(_field_id,_ds.dynamic_fields[_field_id])}}}catch(err){}}try{const row_idx=func.common.find_ROWID_idx(_ds,_ds.currentRecordId);if(typeof _ds.data_feed?.rows?.[row_idx]?.[_field_id]!=="undefined"){return await return_value(_field_id,_ds.data_feed.rows[row_idx][_field_id])}}catch(error){}return await search_in_parameters(fieldIdP)};func.datasource.find_event_dataSource=async function(SESSION_ID,eventIdP,dsSessionP){const _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];var ret;if(_ds?.prog_id){let view_ret=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(view_ret?.progEvents&&func.common.find_item_by_key(view_ret.progEvents,"event_name",eventIdP)){ret=dsSessionP;if(_ds.callingSource==="system")ret=0;if(_ds.callingSource==="program"||!_ds.callingSource)ret=dsSessionP;return ret}}if(!ret&&dsSessionP!==0){if(_ds&&_ds.parentDataSourceNo&&Number(_ds.parentDataSourceNo)>0&&Number(_ds.parentDataSourceNo)<dsSessionP){return await func.datasource.find_event_dataSource(SESSION_ID,eventIdP,_ds.parentDataSourceNo)}else{if(!ret)return await func.datasource.find_event_dataSource(SESSION_ID,eventIdP,0)}}};func.datasource.reset_jobs=function(SESSION_ID,dsSessionP,sourceP,errP){for(const[key,val]of Object.entries(SESSION_OBJ[SESSION_ID].WORKER_OBJ.jobs)){if(val.dsSessionP===dsSessionP){func.events.delete_job(SESSION_ID,val.job_num);break}}func.utils.debug_report(SESSION_ID,sourceP+"Missing datasource: "+dsSessionP,errP,"W",null)};func.datasource.get_currentRecordId=function(SESSION_ID,dsSessionP,from_datasourceP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];if(_ds._dataSourceTableId!==""){var firstRecordId=_ds.firstRecordId;var currentRecordId=_ds.currentRecordId;var locatedRecordId=_ds.locatedRecordId;if(!currentRecordId||from_datasourceP){if(!locatedRecordId)currentRecordId=firstRecordId;else currentRecordId=locatedRecordId}}else currentRecordId="newRecord";return currentRecordId};func.datasource.interval=function(session_id,dsSessionP,typeP){var SESSION_ID=session_id;var interval=[];var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];var arr=_ds[typeP];var fx={init:async function(){if(arr?.length){for(let val of arr){var event_id=val[0];var interval_rate=val[1];var condition=val[2];interval.push(setInterval(async function(){if(!SESSION_OBJ[SESSION_ID])return;var event_count=await func.datasource.get_view_events_count(SESSION_ID,dsSessionP,typeP,event_id);if(!event_count){fx.clear();return}var event_condition=await func.expression.get(SESSION_ID,condition,dsSessionP,"condition");if(condition&&!event_condition.result)return;const e=await func.datasource.execute_view_events(SESSION_ID,dsSessionP,typeP,event_id)},Number(interval_rate)*1e3))}}else{await fx.clear();return}},clear:function(){if(DATASOURCE_INTERVALS[session_id])delete DATASOURCE_INTERVALS[session_id][dsSessionP];for(const[key,val]of Object.entries(interval)){clearInterval(val)}}};return fx};func.datasource.get_viewLoops=async function(SESSION_ID,dataSourceSession,data,batch_source,default_limit){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];var args=_ds.args;var ret=default_limit;if(batch_source==="db_data")ret=data.rows.length;if(batch_source==="array"||batch_source==="csv")ret=data.length;if(batch_source==="json")ret=Object.keys(data).length;if(_ds.progDataSource?.dataSourceLimit){if(batch_source!=="no_data"&&Number(_ds.progDataSource?.dataSourceLimit)<ret){ret=Number(_ds.progDataSource.dataSourceLimit)}if(!batch_source)ret=Number(_ds.progDataSource.dataSourceLimit)}if(prog_obj.progDataSource?.dataSourceLoopExp){var n=(await func.expression.get(SESSION_ID,_ds.v.viewLoopsExp,dataSourceSession,"view_loop",args.rowIdP)).result;if(batch_source!=="no_data"&&n<ret)ret=n;if(!batch_source)ret=n}return ret};func.datasource.set_VIEW_data=async function(SESSION_ID,args,_ds){_ds.v={viewFieldsProp:{},segFrom:[],segTo:[],segLocateFrom:[],segLocateTo:[],viewModule:"adapter"};_ds.viewEventExec_arr={};var view=structuredClone(await func.utils.VIEWS_OBJ.get(SESSION_ID,args.prog_id));_ds.v.dataSourceSrcType=view.dataSourceSrcType;if(view.progDataSource)_ds.progDataSource=view.progDataSource;_ds.v.viewIndex=view?.progDataSource?.dataSourceIndexesObj;let tree_ret=await func.utils.TREE_OBJ.get(SESSION_ID,args.prog_id);_ds.v.viewSourceDesc=tree_ret.menuName;if(!_ds.v.viewSourceDesc&&tree_ret){_ds.v.viewSourceDesc=tree_ret.menuName}if(glb.FUNCTION_NODES_ARR.includes(tree_ret.menuType)){_ds.v.viewModule="function"}_ds.v.viewSourceProp=tree_ret.menuType;if(view.progEvents)_ds.v.progEvents=view.progEvents;_ds._progDataSource_fields=[];if(_ds.progDataSource){let ret=func.expression.parse(JSON.stringify(_ds.progDataSource));_ds._progDataSource_fields=ret.map(e=>{if(e.fieldId)return e.fieldId})}};func.datasource.get_cast_val=async function(SESSION_ID,source,dsSession,valP,typeP,req,error){var prog_id,prog_name;var _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dsSession];prog_id=_ds.prog_id;prog_name=await func.utils.TREE_OBJ.get(SESSION_ID,_ds.prog_id).menuName;const prog_info=prog_id?` (prog: ${prog_id} ${prog_name})`:"";const report_conversion_error=function(res){var msg=`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=`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");return module.cast(typeP,valP,report_conversion_error,report_conversion_warn)};func.datasource.get_field_init_triggers_to_run=function(SESSION_ID,dataSourceSession,pre_init_fieldsP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dataSourceSession];if(!_ds)return;return[]};func.datasource.get_pre_init_fields=function(SESSION_ID,dsSessionP,viewRangeExpP,viewSortExpP,viewGroupByExpP,viewLocateExpP){var ret=[];return};func.datasource.add_dynamic_field_to_ds=function(SESSION_ID,dsSessionP,key,val){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];if(!_ds.dynamic_fields){_ds.dynamic_fields={}}const toType=function(obj){return{}.toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase()};_ds.dynamic_fields[key]={id:crypto.randomUUID(),data:{type:"virtual",field_id:key},props:{fieldType:typeof val!=="undefined"?toType(val):"string"},value:val}};func.datasource.get_progFields=async function(SESSION_ID,dsSessionP){var _ds=SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);return _view_obj.progFields};func.datasource.update_changes_for_out_parameter=async function(SESSION_ID,dsSessionP,calling_dsP){let _session=SESSION_OBJ[SESSION_ID];let _ds=_session.DS_GLB[dsSessionP];const _calling_ds=_session.DS_GLB[calling_dsP];if(_ds.PARAM_OUT_INFO){let data={};for await(const[key,val]of Object.entries(_ds.PARAM_OUT_INFO)){if(val.prop==="out"){try{const row_idx=func.common.find_ROWID_idx(_ds,_ds.currentRecordId);data[val.details]=_ds.data_feed.rows[row_idx][val.fieldId]}catch(err){console.error(err)}}}if(!xu_isEmpty(data)){let datasource_changes={[calling_dsP]:{[_calling_ds.currentRecordId]:data}};await func.datasource.update(SESSION_ID,datasource_changes)}}};func.datasource.set_outputField=async function(SESSION_ID,dsSessionP,result,args){var _session=SESSION_OBJ[SESSION_ID];const output_field=await func.datasource.get_args_property_value(SESSION_ID,dsSessionP,args,"outputField");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]=result;await func.datasource.update(SESSION_ID,datasource_changes)}}};func.datasource.get_args_property_value=async function(SESSION_ID,dsSession,args,prop_name){let _prop=args?.calling_trigger_prop?.data?.name;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};func.UI.screen={};func.UI.screen.init=async function(SESSION_ID,prog_id,sourceScreenP,callingDataSource_objP,$callingContainerP,triggerIdP,rowIdP,jobNoP,is_panelP,parameters_obj_inP,source_functionP,call_screen_propertiesP,refreshed_ds,parameters_raw_obj){return await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:prog_id,sourceScreenP:sourceScreenP,callingDataSource_objP:callingDataSource_objP,$callingContainerP:$callingContainerP,triggerIdP:triggerIdP,rowIdP:rowIdP,jobNoP:jobNoP,is_panelP:is_panelP,parameters_obj_inP:parameters_obj_inP,source_functionP:source_functionP,call_screen_propertiesP:call_screen_propertiesP,refreshed_ds:refreshed_ds,parameters_raw_obj:parameters_raw_obj})};func.UI.screen.update_SYS_OBJ_WIN_INFO=function(SESSION_ID,dsNoP){return func.runtime.ui.update_sys_obj_win_info(SESSION_ID,dsNoP)};func.UI.screen.validate_exit_events=async function(SESSION_ID,div_data_paramsP,forceP){return await func.runtime.ui.validate_exit_events(SESSION_ID,div_data_paramsP,forceP)};func.UI.screen.call_embed=function(SESSION_ID,prog){return func.runtime.ui.call_embed(SESSION_ID,prog)};func.UI.screen.refresh_xu_attributes=async function(SESSION_ID,fields_arr,jobNoP,$elm_to_search,dsSession_changed,avoid_xu_for_refresh,trigger){return await func.runtime.ui.refresh_xu_attributes({SESSION_ID:SESSION_ID,fields_arr:fields_arr,jobNoP:jobNoP,$elm_to_search:$elm_to_search,dsSession_changed:dsSession_changed,avoid_xu_for_refresh:avoid_xu_for_refresh,trigger:trigger})};func.UI.screen.refresh_screen=async function(SESSION_ID,fields_changed_arr,datasource_changed,fields_changed_datasource,watcher){return await func.runtime.ui.refresh_screen({SESSION_ID:SESSION_ID,fields_changed_arr:fields_changed_arr,datasource_changed:datasource_changed,fields_changed_datasource:fields_changed_datasource,watcher:watcher})};func.UI.screen.execute_xu_functions=async function(SESSION_ID,is_skeleton,$root_container,nodeP,$container,paramsP,parent_infoP,jobNoP,keyP,parent_nodeP,xu_func,$elm,val,is_init,refreshed_ds){if(is_skeleton)return;return await func.runtime.render.execute_xu_function({SESSION_ID:SESSION_ID,is_skeleton:is_skeleton,$root_container:$root_container,nodeP:nodeP,$container:$container,paramsP:paramsP,parent_infoP:parent_infoP,jobNoP:jobNoP,keyP:keyP,parent_nodeP:parent_nodeP,xu_func:xu_func,$elm:$elm,val:val,is_init:is_init,refreshed_ds:refreshed_ds,get_params_obj_new:func.runtime.program.get_params_obj})};func.UI.screen.fix_val_defaults=function(key,val){return func.runtime.render.fix_val_defaults(key,val)};func.UI.screen.set_attributes_new=async function(SESSION_ID,is_skeleton,$root_container,nodeP,$container,paramsP,parent_infoP,jobNoP,keyP,parent_nodeP,$elm,is_init,execute_attributes=[],refreshed_ds){return await func.runtime.render.set_attributes_new({SESSION_ID:SESSION_ID,is_skeleton:is_skeleton,$root_container:$root_container,nodeP:nodeP,$container:$container,paramsP:paramsP,parent_infoP:parent_infoP,jobNoP:jobNoP,keyP:keyP,parent_nodeP:parent_nodeP,$elm:$elm,is_init:is_init,execute_attributes:execute_attributes,refreshed_ds:refreshed_ds})};func.UI.screen.panel_post_render_handler=async function(SESSION_ID,$container,$wrapper,nodeP,$panel_div,jobNoP){return await func.runtime.ui.panel_post_render_handler({SESSION_ID:SESSION_ID,$container:$container,$wrapper:$wrapper,nodeP:nodeP,$panel_div:$panel_div,jobNoP:jobNoP})};func.UI.screen.create_container=async function(SESSION_ID,$root_container,nodeP,$container,paramsP,parent_infoP,jobNoP,keyP,parent_nodeP,prop,classP,elem_propP,div_typeP,$appendToP,attr_str,is_placeholder){return await func.runtime.ui.create_container({SESSION_ID:SESSION_ID,$root_container:$root_container,nodeP:nodeP,$container:$container,paramsP:paramsP,parent_infoP:parent_infoP,jobNoP:jobNoP,keyP:keyP,parent_nodeP:parent_nodeP,prop:prop,classP:classP,elem_propP:elem_propP,div_typeP:div_typeP,$appendToP:$appendToP,attr_str:attr_str,is_placeholder:is_placeholder})};func.UI.screen.execute_screen_ready_events=async function(SESSION_ID,paramsP,sourceP,$div,jobNoP,$div_objP){return await func.runtime.ui.execute_screen_ready_events({SESSION_ID:SESSION_ID,paramsP:paramsP,sourceP:sourceP,$div:$div,jobNoP:jobNoP,$div_objP:$div_objP})};func.UI.screen.screen_loading_done=async function(SESSION_ID,paramsP,$div,jobNoP){return await func.runtime.ui.screen_loading_done({SESSION_ID:SESSION_ID,paramsP:paramsP,$div:$div,jobNoP:jobNoP})};func.UI.screen.render_ui_tree=async function(SESSION_ID,$container,nodeP,parent_infoP,paramsP,jobNoP,is_skeleton,keyP,refreshed_ds,parent_nodeP,check_existP,$root_container){return await func.runtime.render.render_ui_tree(SESSION_ID,$container,nodeP,parent_infoP,paramsP,jobNoP,is_skeleton,keyP,refreshed_ds,parent_nodeP,check_existP,$root_container)};func.UI.screen.refresh_document_changes_for_realtime_update=async function(SESSION_ID,doc_change){return await func.runtime.ui.refresh_document_changes_for_realtime_update(SESSION_ID,doc_change)};func.UI.screen.live_preview_hot_module_reload=async function(SESSION_ID,doc){return await func.runtime.ui.live_preview_hot_module_reload(SESSION_ID,doc)};func.UI.component={};func.UI.component.get_wrapped_nodes=function(target){if(!target){return[]}if(typeof target.toArray==="function"){return target.toArray().filter(Boolean)}if(Array.isArray(target)){return target.filter(Boolean)}const first_node=func.runtime.ui.get_first_node(target);return first_node?[first_node]:[]};func.UI.component.move_wrapped_nodes=function(target,source){const target_node=func.runtime.ui.get_first_node(target);if(!target_node){return false}const nodes=func.UI.component.get_wrapped_nodes(source);for(let index=0;index<nodes.length;index++){target_node.appendChild(nodes[index])}return true};func.UI.component.create_app_modal_component=function(SESSION_ID,modal_content_name){const root_element=SESSION_OBJ[SESSION_ID].root_element;const xu_modal_controller_id="xu-modal-controller";var xu_modal_controller=root_element.querySelector(xu_modal_controller_id);if(!xu_modal_controller){xu_modal_controller=document.createElement(xu_modal_controller_id);root_element.prepend(xu_modal_controller)}customElements.define(modal_content_name,class extends HTMLElement{constructor(){super()}connectedCallback(){}});return xu_modal_controller_id};func.UI.component.create_app_page_component=async function(SESSION_ID,id){const component_id="xu-page-component-"+id;customElements.define(component_id,class extends HTMLElement{constructor(){super();var xu_nav=SESSION_OBJ[SESSION_ID].root_element.querySelector("xu-nav");var params=func.runtime.ui.get_data(xu_nav);var container_data=func.runtime.ui.get_data(params.xuData.nav_params[id].$container);for(const[key,val]of Object.entries(container_data)){func.runtime.ui.set_data(this,key,val)}}connectedCallback(){const page_back_callback=async()=>{await func.runtime.ui.validate_exit_events(SESSION_ID,func.runtime.ui.get_data(params.$container).xuData.paramsP,null);nav.back();func.datasource.clean_all(SESSION_ID,params.dsSession)};const nav=SESSION_OBJ[SESSION_ID].root_element.querySelector("xu-nav");const params=func.runtime.ui.get_data(nav).xuData.nav_params[id];params.callback(this,page_back_callback)}});return component_id};func.UI.component.create_app_root_component=function(SESSION_ID){customElements.define("xu-root-component-"+SESSION_ID,class ModalContent extends HTMLElement{connectedCallback(){const xu_nav=SESSION_OBJ[SESSION_ID].root_element.querySelector("xu-nav");const xu_nav_data=func.runtime.ui.get_data(xu_nav);func.UI.component.move_wrapped_nodes(this,xu_nav_data?.xuData?.$div);const root_component_callback=xu_nav_data.xuData.root_component_callback;if(root_component_callback){root_component_callback()}}})};func.UI.component.create_app_popover_component=function(SESSION_ID){const root_element=SESSION_OBJ[SESSION_ID].root_element;const xu_popover_controller_id="xu-popover-controller-"+SESSION_ID;var xu_popover_controller_el=root_element.querySelector(xu_popover_controller_id);if(!xu_popover_controller_el){xu_popover_controller_el=document.createElement(xu_popover_controller_id);root_element.prepend(xu_popover_controller_el)}customElements.define("xu-popover-content-"+SESSION_ID,class ModalContent extends HTMLElement{connectedCallback(){const xu_popover_controller=document.querySelector("xu-popover-controller-"+SESSION_ID);var params=func.runtime.ui.get_data(xu_popover_controller,"xuControllerParams");var popover_el=document.querySelector("xu-popover-content-"+SESSION_ID);popover_el.setAttribute("id",func.runtime.ui.get_attr(params.$container,"id"));var container_data=func.runtime.ui.get_data(params.$container);for(const[key,val]of Object.entries(container_data)){func.runtime.ui.set_data(popover_el,key,val)}popover_el.innerHTML="";func.UI.component.move_wrapped_nodes(popover_el,params.$dialogDiv)}});return xu_popover_controller_id};func.UI.component.create_camera_select_popover_component=function(SESSION_ID){customElements.define("popover-camera-select-page"+SESSION_ID,class ModalContent extends HTMLElement{connectedCallback(){const xu_popover_controller=document.querySelector("ion-popover-controller");var params=func.runtime.ui.get_data(xu_popover_controller,"xuControllerParams");func.UI.component.move_wrapped_nodes(this,params.$dialogDiv)}})};func.UI.component.init_xu_nav=function($container,$nav){const container_el=func.runtime.ui.get_first_node($container);const nav_el=func.runtime.ui.get_first_node($nav);func.runtime.ui.set_data(nav_el,"xuData",{nav_stack:[]});Object.defineProperty(nav_el,"setRoot",{value:async function(component_id){return new Promise(async function(resolve,reject){func.runtime.ui.get_data(nav_el).xuData.nav_stack.unshift(component_id);container_el.insertAdjacentHTML("beforeend","<"+component_id+">");await customElements.whenDefined(component_id);resolve()})},configurable:true});Object.defineProperty(nav_el,"push",{value:async function(component_id){return new Promise(async function(resolve,reject){let last_component=func.runtime.ui.get_data(nav_el).xuData.nav_stack.at(-1);var last_el=document.querySelector(last_component);if(last_el)last_el.style.display="none";func.runtime.ui.get_data(nav_el).xuData.nav_stack.push(component_id);container_el.insertAdjacentHTML("beforeend","<"+component_id+">");await customElements.whenDefined(component_id);resolve()})},configurable:true});Object.defineProperty(nav_el,"popToRoot",{value:async function(){return new Promise(async function(resolve,reject){let last_component=func.runtime.ui.get_data(nav_el).xuData.nav_stack.at(-1);var last_el=document.querySelector(last_component);if(last_el)last_el.remove();let root_component=func.runtime.ui.get_data(nav_el).xuData.nav_stack[0];func.runtime.ui.get_data(nav_el).xuData.nav_stack[root_component];var root_el=document.querySelector(root_component);if(root_el)root_el.style.display="";await customElements.whenDefined(root_component);resolve()})},configurable:true});Object.defineProperty(nav_el,"popTo",{value:async function(index){return new Promise(async function(resolve,reject){let last_component=func.runtime.ui.get_data(nav_el).xuData.nav_stack.at(-1);let last_component_index=func.runtime.ui.get_data(nav_el).xuData.nav_stack.length-1;var last_el=document.querySelector(last_component);if(last_el)last_el.remove();try{var selected_component=func.runtime.ui.get_data(nav_el).xuData.nav_stack[index||last_component_index-1]}catch(error){console.error(error);return reject(error)}var selected_el=document.querySelector(selected_component);if(selected_el)selected_el.style.display="";func.runtime.ui.get_data(nav_el).xuData.nav_stack.splice(last_component_index,1);await customElements.whenDefined(selected_component);resolve()})},configurable:true});Object.defineProperty(nav_el,"back",{value:async function(index){return new Promise(async function(resolve,reject){let last_component=func.runtime.ui.get_data(nav_el).xuData.nav_stack.at(-1);let last_component_index=func.runtime.ui.get_data(nav_el).xuData.nav_stack.length-1;if(last_component_index===0)return;var last_el=document.querySelector(last_component);if(last_el)last_el.remove();try{var selected_component=func.runtime.ui.get_data(nav_el).xuData.nav_stack[last_component_index-1]}catch(error){console.error(error);return reject(error)}var selected_el=document.querySelector(selected_component);if(selected_el)selected_el.style.display="";func.runtime.ui.get_data(nav_el).xuData.nav_stack.splice(last_component_index,1);await customElements.whenDefined(selected_component);resolve()})},configurable:true})};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("&amp;"))ret=ret.replace(/\&amp;/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.events={};func.events.validate=async function(SESSION_ID,triggerP,dsSessionP,eventIdP,sourceP,argumentsP,return_validation_onlyP){var _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dsSessionP];var args={triggerP:triggerP,dsSessionP:dsSessionP,eventIdP:eventIdP,sourceP:sourceP,argumentsP:argumentsP,return_validation_onlyP:return_validation_onlyP};const search_event_in_parent_ds=async function(){if(_ds&&typeof _ds.parentDataSourceNo!=="undefined"){await func.events.validate(SESSION_ID,triggerP,_ds.parentDataSourceNo,eventIdP,sourceP,argumentsP,return_validation_onlyP)}};var ret=false;var jobs=[];if(_ds?.prog_id){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);if(!glb.IS_WORKER)_ds.event_stat_obj={};if(_view_obj.progEvents){if(_session.api_callback&&eventIdP){_session.api_callback(eventIdP,SESSION_ID,SESSION_OBJ)}for await(let val of _view_obj.progEvents){var eventProp=undefined;if(val.data.type===triggerP){if(triggerP!=="user_defined"|(triggerP==="user_defined"&&eventIdP===val.data.event_name)){var expCond;if(val.data.condition)expCond=await func.expression.get(SESSION_ID,val.data.condition,dsSessionP,"condition");if(!val.data.condition||expCond.result){func.utils.debug.watch(SESSION_ID,_ds.prog_id+"%"+val.id,"view_event",val,triggerP+" "+eventIdP,expCond);ret=true;if(return_validation_onlyP)break;const set_arguments=async function(){var args=argumentsP||{};for await(let[key,fieldId]of Object.entries(val.data.parameters)){const field_info=func.common.find_item_by_key(_view_obj.progFields,"field_id",fieldId);if(field_info?.data?.type!=="virtual"){console.warn("parameter field must be virtual, update ignored");continue}if(!args[fieldId])continue;let value=await func.common.get_cast_val(SESSION_ID,"events",fieldId,field_info.props.fieldType,args[fieldId].value);if(!xu_isEmpty(args[fieldId].fx)){const fx_ret=await func.expression.get(SESSION_ID,args[fieldId].fx,dsSessionP,"update");value=fx_ret.result}const ret=await func.datasource.get_value(SESSION_ID,fieldId,dsSessionP,_ds.currentRecordId);const datasource_changes={[ret.dsSessionP]:{[ret.currentRecordId]:{[fieldId]:value}}};await func.datasource.update(SESSION_ID,datasource_changes)}await add_event()};const add_event=async function(){const _event=func.common.find_item_by_key_root(_view_obj.progEvents,"id",val.id);if(_event.workflow){if(!_event.workflow||xu_isEmpty(_event.workflow))return;for(const trigger_obj of _event.workflow){if(!trigger_obj.data.action)continue;if(!trigger_obj.data.enabled)continue;var callingEventId=val.data.event_name;if(!callingEventId)callingEventId=val.id;const ref_id=trigger_obj.data.name;var container=undefined;var screen_prop=undefined;if(!glb.IS_WORKER){if(_ds.panel_div_id){try{container="#"+_ds.panel_div_id;const panel_meta=func.runtime.ui.get_meta_by_element_id(_ds.panel_div_id);if(panel_meta?.xuData?.panel_info){screen_prop=panel_meta.xuData.panel_info.paramsP}else{container="#"+_session.DS_GLB[dsSessionP].screenId;const screen_meta=func.runtime.ui.get_meta_by_element_id(_session.DS_GLB[dsSessionP].screenId);if(screen_meta?.xuData){screen_prop=screen_meta.xuData.paramsP}if(!screen_meta){container="#"+_session.DS_GLB[dsSessionP].containerId}}}catch(e){console.error(e)}}else{container="#"+_ds.screenId;const screen_meta=func.runtime.ui.get_meta_by_element_id(_ds.screenId);if(screen_meta?.xuData){screen_prop=screen_meta.xuData.paramsP}if(!screen_meta){container="#"+_ds.containerId}}}else{screen_prop={callingContainerP:_ds.containerId}}jobs.push(await func.events.add_to_queue(SESSION_ID,sourceP+" event",trigger_obj.id,null,trigger_obj.data.action,ref_id,container,null,_ds.currentRecordId,null,trigger_obj.data.name,null,null,dsSessionP,null,null,trigger_obj,triggerP,screen_prop,null,null,trigger_obj,trigger_obj.data.parameter_source_data,val.id,null,args,null,null))}}};if(val.data.parameters){await set_arguments()}else{await add_event()}}else{if(val.data.condition&&!expCond.result){func.utils.debug.watch(SESSION_ID,_ds.prog_id+"%"+val.id,"view_event",val,triggerP+" "+eventIdP,expCond,true)}}}}}}}if(return_validation_onlyP)return ret;if(!ret)await search_event_in_parent_ds();return jobs};func.events.add_to_queue=async function(SESSION_ID,typeP,eventIdP,triggerP,functionP,refIdP,containerP,elementP,rowP,evt,descP,NA_rootScreenIdP,NA_callingEventIdP,dsSessionP,NA_isInitP,NA_calling_program,event_propertiesP,calling_triggerP,paramsP,NA_target_frame_idP,_NA2,calling_trigger_prop,argumentsP,source_event_idP,calling_job,args,$div,$container){var _session=SESSION_OBJ[SESSION_ID];var obj={SESSION_ID:SESSION_ID,typeP:typeP,eventIdP:eventIdP,triggerP:triggerP,functionP:functionP,refIdP:refIdP,containerP:containerP,elementP:elementP,rowP:rowP,descP:descP,dsSessionP:dsSessionP,event_propertiesP:event_propertiesP,calling_triggerP:calling_triggerP,paramsP:paramsP,calling_trigger_prop:calling_trigger_prop,argumentsP:argumentsP,source_event_idP:source_event_idP,calling_job:calling_job,args:args,$div:$div,$container:$container,evt:evt,job_num:_session.WORKER_OBJ.num};var _ds=_session.DS_GLB[dsSessionP];if(!_ds)return;if(typeof dsSessionP!=="undefined"&&dsSessionP!==null){obj.prog_id=_ds.prog_id;obj.parentDataSourceNo=_ds.parentDataSourceNo;obj.nodeId=_ds.nodeId}if(glb.IS_WORKER&&func.utils.is_onscreen_event(functionP)){obj.client=true;if(functionP==="call_library"){obj.client=false}if(typeof dsSessionP!=="undefined"&&dsSessionP!==null){obj.ds_obj=func.utils.clean_returned_datasource(SESSION_ID,dsSessionP)}if(obj.client){_session.WORKER_OBJ.num++;func.utils.post_back_to_client(SESSION_ID,"job",_session.worker_id,obj);return}}if(calling_job){var job_index=func.events.find_job_index(SESSION_ID,calling_job);try{if(!_session.WORKER_OBJ.jobs[job_index].splice_count){_session.WORKER_OBJ.jobs[job_index].splice_count=0}_session.WORKER_OBJ.jobs[job_index].splice_count++;_session.WORKER_OBJ.jobs.splice(job_index+_session.WORKER_OBJ.jobs[job_index].splice_count,0,obj)}catch(e){console.error("bug")}}else{_session.WORKER_OBJ.jobs.push(obj)}_session.WORKER_OBJ.num++;return _session.WORKER_OBJ.num-1};func.events.find_job_index=function(SESSION_ID,jobNoP){var _session=SESSION_OBJ[SESSION_ID];var ret=null;if(!_session.WORKER_OBJ)return ret;for(const[key,val]of Object.entries(_session.WORKER_OBJ.jobs)){if(val&&val.job_num==jobNoP){ret=key;break}}return ret};func.events.execute=async function(SESSION_ID,jobNoP,eventIdP,triggerP,functionP,refIdP,containerP,elementP,rowP,evt,descP,rootScreenIdP,dsSessionP,NA_callingEventIdP,callingSourceP,NA_isInitP,event_propertiesP,calling_triggerP,calling_jobP,paramsP,NA_target_frame_idP,calling_trigger_prop,NA_calling_program,argumentsP,NA_viewIdP,NA_nodeIdP,NA_parentDataSourceNoP,$div){var _session=SESSION_OBJ[SESSION_ID];var _ds=_session.DS_GLB[dsSessionP];if(functionP==="update")refIdP=null;var job_index=func.events.find_job_index(SESSION_ID,jobNoP);if(_session.WORKER_OBJ.jobs?.[job_index]?.stat==="busy"){if(jobNoP)_session.WORKER_OBJ.stat=job_index;return}if(jobNoP&&!_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.stat=null;return}if(jobNoP)_session.WORKER_OBJ.stat=job_index;if(jobNoP&&calling_trigger_prop?.props?.async){func.events.delete_job(SESSION_ID,jobNoP);_session.WORKER_OBJ.stat=null}if(_session.WORKER_OBJ.jobs[job_index]){_session.WORKER_OBJ.jobs[job_index].stat="busy"}var dsSession=dsSessionP;var field_elm=elementP;var calling_field_id=field_elm;if(field_elm&&typeof field_elm==="object")calling_field_id=func.runtime.ui.get_attr(field_elm,"xu-ui-id");var log_nodeId;var log_prog_id;var log_source;if(_session.DS_GLB[dsSession]?.prog_id)log_prog_id=_session.DS_GLB[dsSession].prog_id;log_nodeId=log_prog_id+"_"+eventIdP;var log_prop=callingSourceP;if(callingSourceP==="system event"){log_prop="global event"}if(calling_field_id){const _view_obj=await func.utils.VIEWS_OBJ.get(SESSION_ID,_ds.prog_id);let _field_obj=func.common.find_item_by_key(_view_obj.progFields,"field_id",calling_field_id);log_nodeId=log_prog_id+"_"+eventIdP+"_"+_field_obj?.id;log_source=calling_field_id}if(elementP){log_prop=triggerP;log_nodeId=log_nodeId+"_ui_prop"}var expCond;if(event_propertiesP){if(event_propertiesP?.props?.condition){expCond=await func.expression.get(SESSION_ID,event_propertiesP.props.condition,dsSession,"condition",null,null,null,calling_field_id?calling_field_id:calling_triggerP,null,descP);func.utils.debug.log(SESSION_ID,log_nodeId,{module:"event",action:log_prop,source:log_source,prop:descP,details:event_propertiesP.props.condition,result:expCond.result,error:expCond.error,fields:expCond.fields,type:"event",prog_id:log_prog_id,conditional:true});var cond=expCond.result;if(!cond||expCond.error){func.events.delete_job(SESSION_ID,jobNoP);func.utils.debug.watch(SESSION_ID,calling_trigger_prop?.id,functionP,"","",expCond,true);return}}else{func.utils.debug.log(SESSION_ID,log_nodeId,{module:"event",action:log_prop,source:log_source,prop:descP,details:null,result:null,error:null,fields:null,type:"event",prog_id:log_prog_id})}}const get_params_obj=async function(){const _prog=await func.utils.VIEWS_OBJ.get(SESSION_ID,await get_prog_id());if(!_prog){func.events.delete_job(SESSION_ID,jobNoP);return func.utils.debug_report(SESSION_ID,"func.events.execute","Program not found: "+refIdP.prog,"E")}var params_obj={};if(_prog?.properties?.progParams){for await(const[key,val]of Object.entries(_prog.properties.progParams)){if(typeof args.parameters_obj_inP?.[val.data.parameter]!=="undefined"){if(args.parameters_obj_inP?.[val.data.parameter].fx){let ret=await func.expression.get(SESSION_ID,args.parameters_obj_inP?.[val.data.parameter].fx,dsSession,"parameters");params_obj[val.data.parameter]=ret.result}else{params_obj[val.data.parameter]=args.parameters_obj_inP?.[val.data.parameter].value}continue}console.warn(`Warning: Program ${_prog.properties.menuName} expected In parameter: ${val.data.parameter} but received null instead`)}}return params_obj};const get_prog_id=async function(){let _prop=args?.calling_trigger_prop?.data?.name?.properties;let _prog_id=args.prog_id;if(_prop?.["xu-exp:prog"]){_prog_id=(await func.expression.get(SESSION_ID,_prop["xu-exp:prog"],dsSession,"prog_id expression")).result}return _prog_id};var args={prog_id:refIdP?.prog,screenIdP:refIdP?.prog,callingFieldIdP:field_elm,dataSourceNoP:null,parentDataSourceNoP:dsSession,triggerIdP:eventIdP,containerIdP:null,rowIdP:rowP,jobNoP:jobNoP,callingSourceP:callingSourceP,calling_jobP:calling_jobP,screen_dsP:null,is_panelP:null,argument_listP:null,calling_trigger_prop:calling_trigger_prop,parameters_obj_inP:refIdP?.parameters,call_screen_propertiesP:refIdP?.properties};const fx={Call_window:async function(){var is_panel;var $calling_container;if(_session.WORKER_OBJ.jobs[job_index]){if(_session.WORKER_OBJ.jobs[job_index].paramsP){$calling_container=func.runtime.ui.find_element_by_id(_session.WORKER_OBJ.jobs[job_index].paramsP.callingContainerP)}else{$calling_container="";_session.WORKER_OBJ.jobs[job_index].paramsP={}}}if(!refIdP.prog){func.events.delete_job(SESSION_ID,jobNoP);return func.utils.debug_report(SESSION_ID,"func.events.execute","Program is empty","E")}const params_obj=await get_params_obj();return await func.runtime.ui.init_screen({SESSION_ID:SESSION_ID,prog_id:await get_prog_id(),sourceScreenP:func.runtime.ui.get_data(containerP)?.xuData?.screenId,callingDataSource_objP:_session.DS_GLB[dsSession],$callingContainerP:$calling_container,triggerIdP:eventIdP,rowIdP:rowP,jobNoP:jobNoP,is_panelP:is_panel,parameters_obj_inP:params_obj,source_functionP:functionP,call_screen_propertiesP:args.call_screen_propertiesP})},call_modal:async function(){return await fx.Call_window()},call_popover:async function(){return await fx.Call_window()},call_page:async function(){return await fx.Call_window()},call_library:async function(){let plugin_name=refIdP.plugin_name,method=refIdP.library_method,$containerP=$div,dsP=dsSession,propsP=refIdP.library_props,sourceP=descP;var _session=SESSION_OBJ[SESSION_ID];const set_SYS_GLOBAL_OBJ_WIDGET_INFO=async function(docP){var obj={...docP};obj.date=await func.utils.get_dateTime(SESSION_ID,"SYS_DATE",docP.date);obj.time=await func.utils.get_dateTime(SESSION_ID,"SYS_TIME",docP.date);var datasource_changes={[0]:{["data_system"]:{["SYS_GLOBAL_OBJ_WIDGET_INFO"]:obj}}};await func.datasource.update(SESSION_ID,datasource_changes)};const call_plugin_api=async function(plugin_nameP,dataP){return await func.utils.call_plugin_api(SESSION_ID,plugin_nameP,dataP)};const report_error=function(descP,warn){func.utils.debug.log(SESSION_ID,_session.DS_GLB[dsP].prog_id+"_"+_session.DS_GLB[dsP].callingMenuId,{module:"widgets",action:"Init",source:sourceP,prop:descP,details:descP,result:null,error:warn?false:true,fields:null,type:"widgets",prog_id:_session.DS_GLB[dsP].prog_id})};const get_fields_data=async function(fields,props){const report_error=function(descP,warn){func.utils.debug.log(SESSION_ID,_session.DS_GLB[dsP].prog_id+"_"+_session.DS_GLB[dsP].callingMenuId,{module:"widgets",action:"Init",source:sourceP,prop:descP,details:descP,result:null,error:warn?false:true,fields:null,type:"widgets",prog_id:_session.DS_GLB[dsP].prog_id})};const get_property_value=async function(fieldIdP,val){var value=props[fieldIdP]||(typeof val.defaultValue==="function"?val?.defaultValue?.():val?.defaultValue);if(props[`xu-exp:${fieldIdP}`]){value=(await func.expression.get(SESSION_ID,props[`xu-exp:${fieldIdP}`],dsP,"widget property")).result}return func.common.get_cast_val(SESSION_ID,"widgets",fieldIdP,val.type,value,null)};var data_obj={};var return_code=1;for await(const[key,val]of Object.entries(fields)){try{data_obj[key]=await get_property_value(key,val);if(!data_obj[key]&&val.mandatory){return_code=-1;report_error(`${key} is a mandatory field.`);break}}catch(error){debugger}}return{code:return_code,data:data_obj}};try{const _plugin=APP_OBJ[_session.app_id]?.app_plugins_purchased?.[plugin_name];const index=await func.utils.get_plugin_resource(SESSION_ID,plugin_name,`${_plugin.manifest["index.mjs"].dist?"dist/":""}index.mjs`);const methods=index.methods;if(methods&&!methods[method]){return report_error("method not found")}const fields_ret=await get_fields_data(methods[method].fields,propsP);if(fields_ret.code<0){return report_error(fields_ret.data)}const fields=fields_ret.data;const plugin_setup_ret=await func.utils.get_plugin_setup(SESSION_ID,plugin_name);if(plugin_setup_ret.code<0){return report_error(plugin_setup_ret)}const api_utils=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:dsP,job_id:jobNoP});const params={SESSION_ID:SESSION_ID,method:method,_session:_session,dsP:dsP,sourceP:sourceP,propsP:propsP,plugin_name:plugin_name,$containerP:$containerP,plugin_setup:plugin_setup_ret.data,report_error:report_error,call_plugin_api:call_plugin_api,set_SYS_GLOBAL_OBJ_WIDGET_INFO:set_SYS_GLOBAL_OBJ_WIDGET_INFO,api_utils:api_utils};const fx=await func.utils.get_plugin_resource(SESSION_ID,plugin_name,`${_plugin.manifest["runtime.mjs"].dist?"dist/":""}runtime.mjs`);if(!fx[method]){throw`Method: ${method} does not exist`}await fx[method](fields,params)}catch(err){report_error(err)}func.events.delete_job(SESSION_ID,jobNoP)},call_native_javascript:async function(){const module=await func.common.get_module(SESSION_ID,"xuda-event-javascript-module.mjs");const result=await module.call_javascript(SESSION_ID,jobNoP,refIdP,dsSession,false,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},call_evaluate_javascript:async function(){const module=await func.common.get_module(SESSION_ID,"xuda-event-javascript-module.mjs");const result=await module.call_javascript(SESSION_ID,jobNoP,refIdP,dsSession,true,$div);await func.datasource.set_outputField(SESSION_ID,dsSessionP,result,args);return result},execute_native_javascript:async function(){const module=await func.common.get_module(SESSION_ID,"xuda-event-javascript-module.mjs");const resolved_element_expr=`(func.runtime.ui && func.runtime.ui.find_xu_ui_in_root && func.runtime.ui.get_first_node ? func.runtime.ui.get_first_node(func.runtime.ui.find_xu_ui_in_root(SESSION_ID, ${JSON.stringify(elementP)})) : null)`;const result=await module.run_javascript(SESSION_ID,jobNoP,dsSession,`(async function(el,evt) {
75
75
  ${refIdP.value}
76
76
  })(${resolved_element_expr},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 resolved_element_expr=`(func.runtime.ui && func.runtime.ui.find_xu_ui_in_root && func.runtime.ui.get_first_node ? func.runtime.ui.get_first_node(func.runtime.ui.find_xu_ui_in_root(SESSION_ID, ${JSON.stringify(elementP)})) : null)`;const result=await module.run_javascript(SESSION_ID,jobNoP,dsSession,`(async function(el,evt) {
77
77
  ${refIdP.value}