@xuda.io/runtime-bundle 1.0.1433 → 1.0.1435

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.
@@ -196,6 +196,23 @@ func.runtime.platform = {
196
196
  return false;
197
197
  }
198
198
  },
199
+ get_cookie_item: function (key) {
200
+ if (!key) {
201
+ return null;
202
+ }
203
+ const doc = func.runtime.platform.get_document();
204
+ const cookie_string = doc?.cookie;
205
+ if (!cookie_string) {
206
+ return null;
207
+ }
208
+ const cookie_entry = cookie_string.split('; ').find(function (cookie) {
209
+ return cookie.startsWith(key + '=');
210
+ });
211
+ if (!cookie_entry) {
212
+ return null;
213
+ }
214
+ return cookie_entry.split('=').slice(1).join('=') || null;
215
+ },
199
216
  get_url_href: function () {
200
217
  return func.runtime.platform.get_location()?.href || '';
201
218
  },
@@ -2549,6 +2566,9 @@ func.runtime.ui.get_meta_by_element_id = function (element_id) {
2549
2566
  func.runtime.ui.find_element_by_id = function () {
2550
2567
  return null;
2551
2568
  };
2569
+ func.runtime.ui.get_parent_element_id = function () {
2570
+ return null;
2571
+ };
2552
2572
  func.runtime.ui.get_session_root = function () {
2553
2573
  return null;
2554
2574
  };
@@ -2606,8 +2626,30 @@ func.runtime.ui.get_children = function (target) {
2606
2626
  if (target?._v_id) return target.children.slice();
2607
2627
  return [];
2608
2628
  };
2629
+ func.runtime.ui._wrap_matches = function (matches) {
2630
+ if (!matches) matches = [];
2631
+ const result = {
2632
+ length: matches.length,
2633
+ toArray: function () { return matches.slice(); },
2634
+ };
2635
+ for (let i = 0; i < matches.length; i++) {
2636
+ result[i] = matches[i];
2637
+ }
2638
+ result[Symbol.iterator] = function () {
2639
+ let idx = 0;
2640
+ return {
2641
+ next: function () {
2642
+ if (idx < matches.length) {
2643
+ return { value: matches[idx++], done: false };
2644
+ }
2645
+ return { done: true };
2646
+ },
2647
+ };
2648
+ };
2649
+ return result;
2650
+ };
2609
2651
  func.runtime.ui.find_by_selector = function () {
2610
- return { length: 0, toArray: function () { return []; } };
2652
+ return func.runtime.ui._wrap_matches([]);
2611
2653
  };
2612
2654
  func.runtime.ui.insert_before = function ($element) { return $element; };
2613
2655
  func.runtime.ui.insert_after = function ($element) { return $element; };
@@ -2717,6 +2759,9 @@ func.runtime.ui.remove_xu_ui = function (xu_ui_id) {
2717
2759
  func.runtime.ui.delete_meta(xu_ui_id);
2718
2760
  return true;
2719
2761
  };
2762
+ func.runtime.ui.find_xu_ui_in_root = function () {
2763
+ return func.runtime.ui._wrap_matches([]);
2764
+ };
2720
2765
  func.runtime.ui.build_debug_info = function (nodeP, $container, items) {
2721
2766
  const container_data = func.runtime.ui.get_data($container);
2722
2767
  return {
@@ -2818,13 +2863,24 @@ func.runtime.ui.build_xu_ui_id_seed = function (nodeP, dsSessionP, key_path, cur
2818
2863
  const elem_key = `${nodeId}-${key_path}-${currentRecordId}`;
2819
2864
  return `${nodeP.id}-${elem_key}-${dsSessionP?.toString() || ''}`;
2820
2865
  };
2866
+ func.runtime.ui.build_container_key_path = function (container_xu_data, keyP, parent_infoP, nodeP, parent_nodeP) {
2867
+ const key_segment = typeof keyP === 'undefined' || keyP === null ? '0' : `${keyP}`;
2868
+ let key_path = `${container_xu_data?.key_path || '0'}-${key_segment}`;
2869
+ const parent_identity = parent_nodeP?.xu_tree_id || parent_nodeP?.id;
2870
+ const node_identity = nodeP?.xu_tree_id || nodeP?.id;
2871
+ const is_iterated_clone = !!(parent_infoP?.iterate_info && parent_identity && node_identity && parent_identity === node_identity);
2872
+ if (is_iterated_clone) {
2873
+ key_path += '-iter';
2874
+ }
2875
+ return key_path;
2876
+ };
2821
2877
  func.runtime.ui.generate_xu_ui_id = async function (SESSION_ID, nodeP, $container, paramsP, keyP, precomputed) {
2822
2878
  precomputed = precomputed || {};
2823
2879
  const dsSessionP = paramsP.dsSessionP;
2824
2880
  const _ds = SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];
2825
2881
  const containerXuData = precomputed.container_xu_data || func.runtime.ui.get_data($container)?.xuData;
2826
2882
  const currentRecordId = typeof precomputed.currentRecordId !== 'undefined' ? precomputed.currentRecordId : containerXuData?.recordid || _ds?.currentRecordId || '';
2827
- const key_path = precomputed.key_path || `${containerXuData?.key_path || '0'}-${keyP || '0'}`;
2883
+ const key_path = precomputed.key_path || func.runtime.ui.build_container_key_path(containerXuData, keyP, precomputed.parent_infoP, nodeP, precomputed.parent_nodeP);
2828
2884
  const ui_id = func.runtime.ui.build_xu_ui_id_seed(nodeP, dsSessionP, key_path, currentRecordId);
2829
2885
 
2830
2886
  if (func.runtime.ui.ui_id_hash_cache.has(ui_id)) {
@@ -2846,13 +2902,15 @@ func.runtime.ui.create_container = async function (options) {
2846
2902
  const currentRecordId = container_xu_data?.recordid || (_ds ? _ds.currentRecordId : '');
2847
2903
 
2848
2904
  try {
2849
- const key_path = `${container_xu_data?.key_path || '0'}-${options.keyP || '0'}`;
2905
+ const key_path = func.runtime.ui.build_container_key_path(container_xu_data, options.keyP, options.parent_infoP, options.nodeP, options.parent_nodeP);
2850
2906
  const elem_key = `${options.nodeP.xu_tree_id || options.nodeP.id}-${key_path}-${currentRecordId}`;
2851
2907
  const $div = func.runtime.ui.create_container_element(options.div_typeP);
2852
2908
  const new_ui_id = await func.runtime.ui.generate_xu_ui_id(options.SESSION_ID, options.nodeP, options.$container, options.paramsP, options.keyP, {
2853
2909
  container_xu_data,
2854
2910
  currentRecordId,
2855
2911
  key_path,
2912
+ parent_infoP: options.parent_infoP,
2913
+ parent_nodeP: options.parent_nodeP,
2856
2914
  });
2857
2915
 
2858
2916
  func.runtime.ui.apply_container_meta($div, {
@@ -4609,8 +4667,9 @@ func.datasource.clean = function (SESSION_ID, screenIdP) {
4609
4667
  var arr = [];
4610
4668
  for (const [key, val] of Object.entries(SESSION_OBJ[SESSION_ID].DS_GLB)) {
4611
4669
  try {
4612
- const _screen_el = val.screenId ? document.getElementById(val.screenId) : null;
4613
- const screen_parent_id = _screen_el?.parentElement?.id || null;
4670
+ const screen_parent_id = val.screenId && func.runtime?.ui?.get_parent_element_id
4671
+ ? func.runtime.ui.get_parent_element_id(val.screenId)
4672
+ : null;
4614
4673
  if (
4615
4674
  Number(key) > 0 &&
4616
4675
  (val.screenId === screenIdP ||
@@ -4619,7 +4678,7 @@ func.datasource.clean = function (SESSION_ID, screenIdP) {
4619
4678
  (val && val.parentDataSourceNo && arr.includes(val.parentDataSourceNo.toString())))
4620
4679
  ) {
4621
4680
  arr.push(key);
4622
- if (val.screenId) func.UI.utils.screen_blocker(false, val.screenId);
4681
+ if (val.screenId && func.UI?.utils?.screen_blocker) func.UI.utils.screen_blocker(false, val.screenId);
4623
4682
  }
4624
4683
  } catch (err) {
4625
4684
  console.warn('func.datasource.clean failed');
@@ -8722,6 +8781,7 @@ func.events.execute = async function (
8722
8781
  },
8723
8782
  execute_native_javascript: async function () {
8724
8783
  const module = await func.common.get_module(SESSION_ID, 'xuda-event-javascript-module.mjs');
8784
+ 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)`;
8725
8785
 
8726
8786
  const result = await module.run_javascript(
8727
8787
  SESSION_ID,
@@ -8729,7 +8789,7 @@ func.events.execute = async function (
8729
8789
  dsSession,
8730
8790
  `(async function(el,evt) {
8731
8791
  ${refIdP.value}
8732
- })(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,
8792
+ })(${resolved_element_expr},evt)`,
8733
8793
  null,
8734
8794
  null,
8735
8795
  null,
@@ -8742,6 +8802,7 @@ func.events.execute = async function (
8742
8802
  },
8743
8803
  execute_evaluate_javascript: async function () {
8744
8804
  const module = await func.common.get_module(SESSION_ID, 'xuda-event-javascript-module.mjs');
8805
+ 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)`;
8745
8806
 
8746
8807
  const result = await module.run_javascript(
8747
8808
  SESSION_ID,
@@ -8749,7 +8810,7 @@ func.events.execute = async function (
8749
8810
  dsSession,
8750
8811
  `(async function(el,evt) {
8751
8812
  ${refIdP.value}
8752
- })(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,
8813
+ })(${resolved_element_expr},evt)`,
8753
8814
  true,
8754
8815
  null,
8755
8816
  null,
@@ -196,6 +196,23 @@ func.runtime.platform = {
196
196
  return false;
197
197
  }
198
198
  },
199
+ get_cookie_item: function (key) {
200
+ if (!key) {
201
+ return null;
202
+ }
203
+ const doc = func.runtime.platform.get_document();
204
+ const cookie_string = doc?.cookie;
205
+ if (!cookie_string) {
206
+ return null;
207
+ }
208
+ const cookie_entry = cookie_string.split('; ').find(function (cookie) {
209
+ return cookie.startsWith(key + '=');
210
+ });
211
+ if (!cookie_entry) {
212
+ return null;
213
+ }
214
+ return cookie_entry.split('=').slice(1).join('=') || null;
215
+ },
199
216
  get_url_href: function () {
200
217
  return func.runtime.platform.get_location()?.href || '';
201
218
  },
@@ -2549,6 +2566,9 @@ func.runtime.ui.get_meta_by_element_id = function (element_id) {
2549
2566
  func.runtime.ui.find_element_by_id = function () {
2550
2567
  return null;
2551
2568
  };
2569
+ func.runtime.ui.get_parent_element_id = function () {
2570
+ return null;
2571
+ };
2552
2572
  func.runtime.ui.get_session_root = function () {
2553
2573
  return null;
2554
2574
  };
@@ -2606,8 +2626,30 @@ func.runtime.ui.get_children = function (target) {
2606
2626
  if (target?._v_id) return target.children.slice();
2607
2627
  return [];
2608
2628
  };
2629
+ func.runtime.ui._wrap_matches = function (matches) {
2630
+ if (!matches) matches = [];
2631
+ const result = {
2632
+ length: matches.length,
2633
+ toArray: function () { return matches.slice(); },
2634
+ };
2635
+ for (let i = 0; i < matches.length; i++) {
2636
+ result[i] = matches[i];
2637
+ }
2638
+ result[Symbol.iterator] = function () {
2639
+ let idx = 0;
2640
+ return {
2641
+ next: function () {
2642
+ if (idx < matches.length) {
2643
+ return { value: matches[idx++], done: false };
2644
+ }
2645
+ return { done: true };
2646
+ },
2647
+ };
2648
+ };
2649
+ return result;
2650
+ };
2609
2651
  func.runtime.ui.find_by_selector = function () {
2610
- return { length: 0, toArray: function () { return []; } };
2652
+ return func.runtime.ui._wrap_matches([]);
2611
2653
  };
2612
2654
  func.runtime.ui.insert_before = function ($element) { return $element; };
2613
2655
  func.runtime.ui.insert_after = function ($element) { return $element; };
@@ -2717,6 +2759,9 @@ func.runtime.ui.remove_xu_ui = function (xu_ui_id) {
2717
2759
  func.runtime.ui.delete_meta(xu_ui_id);
2718
2760
  return true;
2719
2761
  };
2762
+ func.runtime.ui.find_xu_ui_in_root = function () {
2763
+ return func.runtime.ui._wrap_matches([]);
2764
+ };
2720
2765
  func.runtime.ui.build_debug_info = function (nodeP, $container, items) {
2721
2766
  const container_data = func.runtime.ui.get_data($container);
2722
2767
  return {
@@ -2818,13 +2863,24 @@ func.runtime.ui.build_xu_ui_id_seed = function (nodeP, dsSessionP, key_path, cur
2818
2863
  const elem_key = `${nodeId}-${key_path}-${currentRecordId}`;
2819
2864
  return `${nodeP.id}-${elem_key}-${dsSessionP?.toString() || ''}`;
2820
2865
  };
2866
+ func.runtime.ui.build_container_key_path = function (container_xu_data, keyP, parent_infoP, nodeP, parent_nodeP) {
2867
+ const key_segment = typeof keyP === 'undefined' || keyP === null ? '0' : `${keyP}`;
2868
+ let key_path = `${container_xu_data?.key_path || '0'}-${key_segment}`;
2869
+ const parent_identity = parent_nodeP?.xu_tree_id || parent_nodeP?.id;
2870
+ const node_identity = nodeP?.xu_tree_id || nodeP?.id;
2871
+ const is_iterated_clone = !!(parent_infoP?.iterate_info && parent_identity && node_identity && parent_identity === node_identity);
2872
+ if (is_iterated_clone) {
2873
+ key_path += '-iter';
2874
+ }
2875
+ return key_path;
2876
+ };
2821
2877
  func.runtime.ui.generate_xu_ui_id = async function (SESSION_ID, nodeP, $container, paramsP, keyP, precomputed) {
2822
2878
  precomputed = precomputed || {};
2823
2879
  const dsSessionP = paramsP.dsSessionP;
2824
2880
  const _ds = SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];
2825
2881
  const containerXuData = precomputed.container_xu_data || func.runtime.ui.get_data($container)?.xuData;
2826
2882
  const currentRecordId = typeof precomputed.currentRecordId !== 'undefined' ? precomputed.currentRecordId : containerXuData?.recordid || _ds?.currentRecordId || '';
2827
- const key_path = precomputed.key_path || `${containerXuData?.key_path || '0'}-${keyP || '0'}`;
2883
+ const key_path = precomputed.key_path || func.runtime.ui.build_container_key_path(containerXuData, keyP, precomputed.parent_infoP, nodeP, precomputed.parent_nodeP);
2828
2884
  const ui_id = func.runtime.ui.build_xu_ui_id_seed(nodeP, dsSessionP, key_path, currentRecordId);
2829
2885
 
2830
2886
  if (func.runtime.ui.ui_id_hash_cache.has(ui_id)) {
@@ -2846,13 +2902,15 @@ func.runtime.ui.create_container = async function (options) {
2846
2902
  const currentRecordId = container_xu_data?.recordid || (_ds ? _ds.currentRecordId : '');
2847
2903
 
2848
2904
  try {
2849
- const key_path = `${container_xu_data?.key_path || '0'}-${options.keyP || '0'}`;
2905
+ const key_path = func.runtime.ui.build_container_key_path(container_xu_data, options.keyP, options.parent_infoP, options.nodeP, options.parent_nodeP);
2850
2906
  const elem_key = `${options.nodeP.xu_tree_id || options.nodeP.id}-${key_path}-${currentRecordId}`;
2851
2907
  const $div = func.runtime.ui.create_container_element(options.div_typeP);
2852
2908
  const new_ui_id = await func.runtime.ui.generate_xu_ui_id(options.SESSION_ID, options.nodeP, options.$container, options.paramsP, options.keyP, {
2853
2909
  container_xu_data,
2854
2910
  currentRecordId,
2855
2911
  key_path,
2912
+ parent_infoP: options.parent_infoP,
2913
+ parent_nodeP: options.parent_nodeP,
2856
2914
  });
2857
2915
 
2858
2916
  func.runtime.ui.apply_container_meta($div, {
@@ -4609,8 +4667,9 @@ func.datasource.clean = function (SESSION_ID, screenIdP) {
4609
4667
  var arr = [];
4610
4668
  for (const [key, val] of Object.entries(SESSION_OBJ[SESSION_ID].DS_GLB)) {
4611
4669
  try {
4612
- const _screen_el = val.screenId ? document.getElementById(val.screenId) : null;
4613
- const screen_parent_id = _screen_el?.parentElement?.id || null;
4670
+ const screen_parent_id = val.screenId && func.runtime?.ui?.get_parent_element_id
4671
+ ? func.runtime.ui.get_parent_element_id(val.screenId)
4672
+ : null;
4614
4673
  if (
4615
4674
  Number(key) > 0 &&
4616
4675
  (val.screenId === screenIdP ||
@@ -4619,7 +4678,7 @@ func.datasource.clean = function (SESSION_ID, screenIdP) {
4619
4678
  (val && val.parentDataSourceNo && arr.includes(val.parentDataSourceNo.toString())))
4620
4679
  ) {
4621
4680
  arr.push(key);
4622
- if (val.screenId) func.UI.utils.screen_blocker(false, val.screenId);
4681
+ if (val.screenId && func.UI?.utils?.screen_blocker) func.UI.utils.screen_blocker(false, val.screenId);
4623
4682
  }
4624
4683
  } catch (err) {
4625
4684
  console.warn('func.datasource.clean failed');
@@ -8722,6 +8781,7 @@ func.events.execute = async function (
8722
8781
  },
8723
8782
  execute_native_javascript: async function () {
8724
8783
  const module = await func.common.get_module(SESSION_ID, 'xuda-event-javascript-module.mjs');
8784
+ 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)`;
8725
8785
 
8726
8786
  const result = await module.run_javascript(
8727
8787
  SESSION_ID,
@@ -8729,7 +8789,7 @@ func.events.execute = async function (
8729
8789
  dsSession,
8730
8790
  `(async function(el,evt) {
8731
8791
  ${refIdP.value}
8732
- })(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,
8792
+ })(${resolved_element_expr},evt)`,
8733
8793
  null,
8734
8794
  null,
8735
8795
  null,
@@ -8742,6 +8802,7 @@ func.events.execute = async function (
8742
8802
  },
8743
8803
  execute_evaluate_javascript: async function () {
8744
8804
  const module = await func.common.get_module(SESSION_ID, 'xuda-event-javascript-module.mjs');
8805
+ 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)`;
8745
8806
 
8746
8807
  const result = await module.run_javascript(
8747
8808
  SESSION_ID,
@@ -8749,7 +8810,7 @@ func.events.execute = async function (
8749
8810
  dsSession,
8750
8811
  `(async function(el,evt) {
8751
8812
  ${refIdP.value}
8752
- })(document.querySelector(\`[xu-ui-id="${elementP}"]\`),evt)`,
8813
+ })(${resolved_element_expr},evt)`,
8753
8814
  true,
8754
8815
  null,
8755
8816
  null,