@xuda.io/runtime-bundle 1.0.1249 → 1.0.1250

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.
@@ -34482,162 +34482,312 @@ func.UI.screen.panel_post_render_handler = async function (
34482
34482
  return jobNoP;
34483
34483
  };
34484
34484
 
34485
+ // const generate_xu_ui_id = async function (SESSION_ID, nodeP, $container, paramsP, keyP) {
34486
+ // // const _paramsP = _.cloneDeep(paramsP);
34487
+ // const _paramsP = klona.klona(paramsP);
34488
+ // var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[_paramsP.dsSessionP];
34489
+
34490
+ // const currentRecordId = $container?.data?.()?.xuData?.recordid || (_ds ? _ds.currentRecordId : '');
34491
+ // const key_path = `${$container?.data()?.xuData?.key_path || '0'}-${keyP || '0'}`;
34492
+ // const elem_key = `${nodeP.xu_tree_id || nodeP.id}-${key_path}-${currentRecordId}`;
34493
+ // let ui_id = `${nodeP.id}-${elem_key}-${_paramsP?.dsSessionP?.toString() || ''}`; //nodeP.xu_tree_id ||
34494
+
34495
+ // const new_ui_id = await func.common.sha256(ui_id);
34496
+ // return new_ui_id;
34497
+ // };
34498
+
34485
34499
  const generate_xu_ui_id = async function (SESSION_ID, nodeP, $container, paramsP, keyP) {
34486
- // const _paramsP = _.cloneDeep(paramsP);
34487
- const _paramsP = klona.klona(paramsP);
34488
- var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[_paramsP.dsSessionP];
34500
+ // Avoid cloning if we only need dsSessionP
34501
+ const dsSessionP = paramsP.dsSessionP;
34502
+ const _ds = SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];
34503
+
34504
+ // Cache container data access
34505
+ const containerXuData = $container?.data?.()?.xuData;
34506
+ const currentRecordId = containerXuData?.recordid || _ds?.currentRecordId || '';
34489
34507
 
34490
- const currentRecordId = $container?.data?.()?.xuData?.recordid || (_ds ? _ds.currentRecordId : '');
34491
- const key_path = `${$container?.data()?.xuData?.key_path || '0'}-${keyP || '0'}`;
34492
- const elem_key = `${nodeP.xu_tree_id || nodeP.id}-${key_path}-${currentRecordId}`;
34493
- let ui_id = `${nodeP.id}-${elem_key}-${_paramsP?.dsSessionP?.toString() || ''}`; //nodeP.xu_tree_id ||
34508
+ // Build strings efficiently
34509
+ const key_path = `${containerXuData?.key_path || '0'}-${keyP || '0'}`;
34510
+ const nodeId = nodeP.xu_tree_id || nodeP.id;
34511
+ const elem_key = `${nodeId}-${key_path}-${currentRecordId}`;
34512
+ const ui_id = `${nodeP.id}-${elem_key}-${dsSessionP?.toString() || ''}`;
34494
34513
 
34495
- const new_ui_id = await func.common.sha256(ui_id);
34496
- return new_ui_id;
34514
+ return await func.common.fastHash(ui_id);
34497
34515
  };
34498
34516
 
34517
+ // 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) {
34518
+ // // const _paramsP = _.cloneDeep(paramsP);
34519
+ // const _paramsP = klona.klona(paramsP);
34520
+ // var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[_paramsP.dsSessionP];
34521
+ // var $appendTo = $container;
34522
+ // if ($appendToP) $appendTo = $appendToP;
34523
+ // if (!$appendTo || !$appendTo.length) return null; // screen closed or not exist abort build
34524
+ // var div = 'div';
34525
+ // if (div_typeP) div = div_typeP;
34526
+ // var items = [];
34527
+ // if (nodeP.children)
34528
+ // items = nodeP.children.map(function (val) {
34529
+ // return val.xu_tree_id || val.id;
34530
+ // });
34531
+ // var currentRecordId = $container?.data?.()?.xuData?.recordid || (_ds ? _ds.currentRecordId : '');
34532
+ // // var xu_id = (glb.screen_num++).toString();
34533
+ // // xu_id = xu_id += '_' + currentRecordId;
34534
+
34535
+ // try {
34536
+ // const key_path = `${$container?.data()?.xuData?.key_path || '0'}-${keyP || '0'}`;
34537
+ // const elem_key = `${nodeP.xu_tree_id || nodeP.id}-${key_path}-${currentRecordId}`;
34538
+ // // let ui_id = `${nodeP.id}-${elem_key}-${_paramsP?.dsSessionP?.toString() || ''}`; //nodeP.xu_tree_id ||
34539
+
34540
+ // /////////////////////////////////
34541
+
34542
+ // var $div;
34543
+
34544
+ // if (div === 'svg') {
34545
+ // const draw_svg = function (element) {
34546
+ // const get_tag_str = function (element, prop, val) {
34547
+ // let class_str = '';
34548
+ // let attr_str = '';
34549
+ // for (const [key, val] of Object.entries(prop)) {
34550
+ // if (key.substr(0, 2) !== 'xu') {
34551
+ // attr_str += ` ${key}="${val}" `;
34552
+ // }
34553
+ // }
34554
+ // if (element === 'svg') {
34555
+ // return `<${element} ${attr_str} > `;
34556
+ // }
34557
+ // let ret = '';
34558
+ // if (val?.children?.length) {
34559
+ // ret = iterate_svg(val);
34560
+ // }
34561
+
34562
+ // return `<${element} ${class_str} ${attr_str} > ${ret} </${element}>`;
34563
+ // };
34564
+ // let svg_str = get_tag_str(element, prop);
34565
+ // let inner_str = '';
34566
+ // const iterate_svg = function (node) {
34567
+ // let ret = '';
34568
+ // if (node.children) {
34569
+ // for (let val of node.children) {
34570
+ // let prop = val.attributes;
34571
+ // ret += get_tag_str(val.tagName, prop, val);
34572
+ // }
34573
+ // }
34574
+ // return ret;
34575
+ // };
34576
+ // inner_str = iterate_svg(nodeP);
34577
+
34578
+ // $div = $(svg_str + inner_str + '</svg>').appendTo($appendTo);
34579
+ // };
34580
+
34581
+ // draw_svg(div_typeP);
34582
+ // } else {
34583
+ // $div = $(`<${div} ${attr_str ? attr_str : ''}>`);
34584
+ // }
34585
+
34586
+ // // // Returns a 32-bit unsigned integer hash of a string (FNV-1a)
34587
+ // // function hash32(str) {
34588
+ // // let h = 0x811c9dc5; // FNV offset basis
34589
+ // // for (let i = 0; i < str.length; i++) {
34590
+ // // h ^= str.charCodeAt(i);
34591
+ // // // multiply by FNV prime (2^24 + 2^8 + 0x93) with 32-bit overflow
34592
+ // // h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24);
34593
+ // // }
34594
+ // // // Convert to unsigned 32-bit
34595
+ // // return h >>> 0;
34596
+ // // }
34597
+
34598
+ // // function hash32hex(str) {
34599
+ // // return (hash32(str) >>> 0).toString(16).padStart(8, '0');
34600
+ // // }
34601
+
34602
+ // // const new_ui_id = hash32hex(ui_id);
34603
+ // // const new_ui_id = await func.common.sha256(ui_id);
34604
+ // const new_ui_id = await generate_xu_ui_id(SESSION_ID, nodeP, $container, paramsP, keyP);
34605
+
34606
+ // $div
34607
+ // .attr('xu-ui-id', new_ui_id)
34608
+ // // .attr('xu-node-id', nodeP.id)
34609
+ // .data({
34610
+ // xuData: {
34611
+ // prog_id: _paramsP.prog_id,
34612
+ // nodeid: nodeP.id,
34613
+ // ui_type: nodeP.tagName,
34614
+ // // xu_id,
34615
+ // recordid: currentRecordId,
34616
+ // paramsP: _paramsP,
34617
+ // key: keyP,
34618
+ // key_path, //:($container?.data()?.xuData?.key || "0") + "-" + (keyP || "0"),
34619
+ // screenId: _paramsP.screenId,
34620
+ // parent_container: $container?.attr('id'),
34621
+ // elem_key,
34622
+ // properties: prop,
34623
+ // node: nodeP,
34624
+ // node_org: _.cloneDeep(nodeP),
34625
+ // is_panelP: _paramsP.is_panelP,
34626
+ // ui_id: new_ui_id,
34627
+ // elem_prop: elem_propP,
34628
+ // debug_info: {
34629
+ // id: nodeP.id,
34630
+ // parent_id: $container?.data()?.xuData?.ui_id,
34631
+ // items: items,
34632
+ // },
34633
+ // parent_node: parent_nodeP,
34634
+ // currentRecordId: currentRecordId,
34635
+ // $root_container: $root_container,
34636
+ // parent_element_ui_id: $container?.data()?.xuData?.ui_id,
34637
+ // },
34638
+ // xuAttributes: {},
34639
+ // });
34640
+ // if (is_placeholder) {
34641
+ // $div.addClass('display_none');
34642
+ // }
34643
+
34644
+ // if (div_typeP !== 'svg') {
34645
+ // $div.appendTo($appendTo);
34646
+ // }
34647
+ // } catch (e) {
34648
+ // console.error(e);
34649
+ // }
34650
+
34651
+ // if (parent_infoP?.iterate_info) {
34652
+ // $div.data().xuData.iterate_info = parent_infoP.iterate_info;
34653
+ // }
34654
+
34655
+ // if (classP) $div.addClass(classP);
34656
+
34657
+ // return $div;
34658
+ // };
34659
+
34499
34660
  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) {
34500
- // const _paramsP = _.cloneDeep(paramsP);
34501
34661
  const _paramsP = klona.klona(paramsP);
34502
- var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[_paramsP.dsSessionP];
34503
- var $appendTo = $container;
34504
- if ($appendToP) $appendTo = $appendToP;
34505
- if (!$appendTo || !$appendTo.length) return null; // screen closed or not exist abort build
34506
- var div = 'div';
34507
- if (div_typeP) div = div_typeP;
34508
- var items = [];
34509
- if (nodeP.children)
34510
- items = nodeP.children.map(function (val) {
34511
- return val.xu_tree_id || val.id;
34512
- });
34513
- var currentRecordId = $container?.data?.()?.xuData?.recordid || (_ds ? _ds.currentRecordId : '');
34514
- // var xu_id = (glb.screen_num++).toString();
34515
- // xu_id = xu_id += '_' + currentRecordId;
34662
+ const _ds = SESSION_OBJ[SESSION_ID].DS_GLB[_paramsP.dsSessionP];
34663
+ const $appendTo = $appendToP || $container;
34664
+
34665
+ // Early exit if container doesn't exist
34666
+ if (!$appendTo?.length) return null;
34667
+
34668
+ const div = div_typeP || 'div';
34669
+
34670
+ // Cache container data to avoid repeated access
34671
+ const containerData = $container?.data?.();
34672
+ const containerXuData = containerData?.xuData;
34673
+ const currentRecordId = containerXuData?.recordid || (_ds ? _ds.currentRecordId : '');
34674
+
34675
+ // Pre-compute items array
34676
+ const items = nodeP.children ? nodeP.children.map((val) => val.xu_tree_id || val.id) : [];
34516
34677
 
34517
34678
  try {
34518
- const key_path = `${$container?.data()?.xuData?.key_path || '0'}-${keyP || '0'}`;
34679
+ const key_path = `${containerXuData?.key_path || '0'}-${keyP || '0'}`;
34519
34680
  const elem_key = `${nodeP.xu_tree_id || nodeP.id}-${key_path}-${currentRecordId}`;
34520
- // let ui_id = `${nodeP.id}-${elem_key}-${_paramsP?.dsSessionP?.toString() || ''}`; //nodeP.xu_tree_id ||
34521
34681
 
34522
- /////////////////////////////////
34523
-
34524
- var $div;
34682
+ let $div;
34525
34683
 
34684
+ // Handle SVG creation
34526
34685
  if (div === 'svg') {
34527
34686
  const draw_svg = function (element) {
34528
34687
  const get_tag_str = function (element, prop, val) {
34529
- let class_str = '';
34530
- let attr_str = '';
34531
- for (const [key, val] of Object.entries(prop)) {
34532
- if (key.substr(0, 2) !== 'xu') {
34533
- attr_str += ` ${key}="${val}" `;
34688
+ const attrs = [];
34689
+
34690
+ for (const [key, value] of Object.entries(prop)) {
34691
+ if (!key.startsWith('xu')) {
34692
+ attrs.push(`${key}="${value}"`);
34534
34693
  }
34535
34694
  }
34695
+
34696
+ const attr_str = attrs.join(' ');
34697
+
34536
34698
  if (element === 'svg') {
34537
- return `<${element} ${attr_str} > `;
34538
- }
34539
- let ret = '';
34540
- if (val?.children?.length) {
34541
- ret = iterate_svg(val);
34699
+ return `<${element} ${attr_str}>`;
34542
34700
  }
34543
34701
 
34544
- return `<${element} ${class_str} ${attr_str} > ${ret} </${element}>`;
34702
+ const inner = val?.children?.length ? iterate_svg(val) : '';
34703
+ return `<${element} ${attr_str}>${inner}</${element}>`;
34545
34704
  };
34546
- let svg_str = get_tag_str(element, prop);
34547
- let inner_str = '';
34705
+
34548
34706
  const iterate_svg = function (node) {
34549
- let ret = '';
34550
- if (node.children) {
34551
- for (let val of node.children) {
34552
- let prop = val.attributes;
34553
- ret += get_tag_str(val.tagName, prop, val);
34554
- }
34555
- }
34556
- return ret;
34707
+ if (!node.children) return '';
34708
+
34709
+ return node.children.map((val) => get_tag_str(val.tagName, val.attributes, val)).join('');
34557
34710
  };
34558
- inner_str = iterate_svg(nodeP);
34711
+
34712
+ const svg_str = get_tag_str(element, prop);
34713
+ const inner_str = iterate_svg(nodeP);
34559
34714
 
34560
34715
  $div = $(svg_str + inner_str + '</svg>').appendTo($appendTo);
34561
34716
  };
34562
34717
 
34563
34718
  draw_svg(div_typeP);
34564
34719
  } else {
34565
- $div = $(`<${div} ${attr_str ? attr_str : ''}>`);
34720
+ $div = $(`<${div}${attr_str ? ' ' + attr_str : ''}>`);
34566
34721
  }
34567
34722
 
34568
- // // Returns a 32-bit unsigned integer hash of a string (FNV-1a)
34569
- // function hash32(str) {
34570
- // let h = 0x811c9dc5; // FNV offset basis
34571
- // for (let i = 0; i < str.length; i++) {
34572
- // h ^= str.charCodeAt(i);
34573
- // // multiply by FNV prime (2^24 + 2^8 + 0x93) with 32-bit overflow
34574
- // h += (h << 1) + (h << 4) + (h << 7) + (h << 8) + (h << 24);
34575
- // }
34576
- // // Convert to unsigned 32-bit
34577
- // return h >>> 0;
34578
- // }
34723
+ // Generate UI ID
34724
+ const new_ui_id = await generate_xu_ui_id(SESSION_ID, nodeP, $container, paramsP, keyP);
34579
34725
 
34580
- // function hash32hex(str) {
34581
- // return (hash32(str) >>> 0).toString(16).padStart(8, '0');
34582
- // }
34726
+ // Set attributes and data in one go
34727
+ $div.attr('xu-ui-id', new_ui_id);
34728
+
34729
+ // Build xuData object efficiently
34730
+ const xuData = {
34731
+ prog_id: _paramsP.prog_id,
34732
+ nodeid: nodeP.id,
34733
+ ui_type: nodeP.tagName,
34734
+ recordid: currentRecordId,
34735
+ paramsP: _paramsP,
34736
+ key: keyP,
34737
+ key_path,
34738
+ screenId: _paramsP.screenId,
34739
+ parent_container: containerData?.id,
34740
+ elem_key,
34741
+ properties: prop,
34742
+ node: nodeP,
34743
+ node_org: _.cloneDeep(nodeP),
34744
+ is_panelP: _paramsP.is_panelP,
34745
+ ui_id: new_ui_id,
34746
+ elem_prop: elem_propP,
34747
+ debug_info: {
34748
+ id: nodeP.id,
34749
+ parent_id: containerXuData?.ui_id,
34750
+ items: items,
34751
+ },
34752
+ parent_node: parent_nodeP,
34753
+ currentRecordId: currentRecordId,
34754
+ $root_container: $root_container,
34755
+ parent_element_ui_id: containerXuData?.ui_id,
34756
+ };
34583
34757
 
34584
- // const new_ui_id = hash32hex(ui_id);
34585
- // const new_ui_id = await func.common.sha256(ui_id);
34586
- const new_ui_id = await generate_xu_ui_id(SESSION_ID, nodeP, $container, paramsP, keyP);
34758
+ // Add iterate_info if present
34759
+ if (parent_infoP?.iterate_info) {
34760
+ xuData.iterate_info = parent_infoP.iterate_info;
34761
+ }
34587
34762
 
34588
- $div
34589
- .attr('xu-ui-id', new_ui_id)
34590
- // .attr('xu-node-id', nodeP.id)
34591
- .data({
34592
- xuData: {
34593
- prog_id: _paramsP.prog_id,
34594
- nodeid: nodeP.id,
34595
- ui_type: nodeP.tagName,
34596
- // xu_id,
34597
- recordid: currentRecordId,
34598
- paramsP: _paramsP,
34599
- key: keyP,
34600
- key_path, //:($container?.data()?.xuData?.key || "0") + "-" + (keyP || "0"),
34601
- screenId: _paramsP.screenId,
34602
- parent_container: $container?.attr('id'),
34603
- elem_key,
34604
- properties: prop,
34605
- node: nodeP,
34606
- node_org: _.cloneDeep(nodeP),
34607
- is_panelP: _paramsP.is_panelP,
34608
- ui_id: new_ui_id,
34609
- elem_prop: elem_propP,
34610
- debug_info: {
34611
- id: nodeP.id,
34612
- parent_id: $container?.data()?.xuData?.ui_id,
34613
- items: items,
34614
- },
34615
- parent_node: parent_nodeP,
34616
- currentRecordId: currentRecordId,
34617
- $root_container: $root_container,
34618
- parent_element_ui_id: $container?.data()?.xuData?.ui_id,
34619
- },
34620
- xuAttributes: {},
34621
- });
34763
+ // Set data once
34764
+ $div.data({
34765
+ xuData: xuData,
34766
+ xuAttributes: {},
34767
+ });
34768
+
34769
+ // Apply placeholder class if needed
34622
34770
  if (is_placeholder) {
34623
34771
  $div.addClass('display_none');
34624
34772
  }
34625
34773
 
34774
+ // Apply custom class if provided
34775
+ if (classP) {
34776
+ $div.addClass(classP);
34777
+ }
34778
+
34779
+ // Append to DOM (only for non-SVG elements)
34626
34780
  if (div_typeP !== 'svg') {
34627
34781
  $div.appendTo($appendTo);
34628
34782
  }
34629
- } catch (e) {
34630
- console.error(e);
34631
- }
34632
34783
 
34633
- if (parent_infoP?.iterate_info) {
34634
- $div.data().xuData.iterate_info = parent_infoP.iterate_info;
34784
+ return $div;
34785
+ } catch (e) {
34786
+ console.error('create_container error:', e);
34787
+ return null;
34635
34788
  }
34636
-
34637
- if (classP) $div.addClass(classP);
34638
-
34639
- return $div;
34640
34789
  };
34790
+
34641
34791
  func.UI.screen.execute_screen_ready_events = async function (SESSION_ID, paramsP, sourceP, $div, jobNoP, $div_objP) {
34642
34792
  var _ds = SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP];
34643
34793
  if (!_ds) return;