@xuda.io/runtime-bundle 1.0.251 → 1.0.253

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.
@@ -33757,7 +33757,7 @@ func.UI.screen.execute_xu_functions = async function (
33757
33757
  "xu-bind": async function ($elm, val) {
33758
33758
  if (is_skeleton) return;
33759
33759
  $f = $elm;
33760
- const view_field_id = val.value;
33760
+ let view_field_id = val.value;
33761
33761
  let _prog_id = $elm.data().xuData.paramsP.prog_id;
33762
33762
  let _dsP = $elm.data().xuData.paramsP.dsSessionP;
33763
33763
  const view_ret = await func.utils.VIEWS_OBJ.get(SESSION_ID, _prog_id);
@@ -33767,6 +33767,13 @@ func.UI.screen.execute_xu_functions = async function (
33767
33767
  let is_dynamic_field = false
33768
33768
  let field_prop
33769
33769
 
33770
+ const iterate_info = $elm?.data()?.xuData?.iterate_info
33771
+ const reference_source_obj = iterate_info?.reference_source_obj
33772
+
33773
+ if (reference_source_obj) {
33774
+ view_field_id = (reference_source_obj.fieldIdP || "") + val.value;
33775
+ }
33776
+
33770
33777
  if (["_FOR_VAL", "_FOR_KEY"].includes(view_field_id)) {
33771
33778
  is_dynamic_field = true
33772
33779
  field_prop = _ds.dynamic_fields[view_field_id]
@@ -34047,12 +34054,12 @@ func.UI.screen.execute_xu_functions = async function (
34047
34054
  "xu-for": async function ($elm, data) {
34048
34055
  if (parent_infoP?.iterate_info || !data.value) return {};
34049
34056
  try {
34050
-
34057
+ // data.value (xu-for) can store actual values such as an array, a CSV, or a field_id that references a specific field within the dataset, initialized with values for the iteration.
34051
34058
  let arr = data.value;
34052
34059
 
34053
34060
  // find reference source field
34054
34061
  let reference_source_obj
34055
- // try {
34062
+
34056
34063
  const _progFields = await func.datasource.get_progFields(
34057
34064
  SESSION_ID,
34058
34065
  paramsP.dsSessionP
@@ -34063,28 +34070,13 @@ func.UI.screen.execute_xu_functions = async function (
34063
34070
  "field_id",
34064
34071
  data.value
34065
34072
  );
34073
+ // detect if data.value (xu-for) is reference field_id by checking if exist in the dataset
34066
34074
  if (view_field_obj) {
34067
- // let _ds = SESSION_OBJ[SESSION_ID].DS_GLB[paramsP.dsSessionP];
34068
- // try {
34069
- // const row_idx = func.common.find_ROWID_idx(
34070
- // _ds,
34071
- // currentRecordId
34072
- // );
34073
- // reference_source_field = data.value
34074
-
34075
- // arr = await func.datasource.get_value(SESSION_ID, paramsP.dsSessionP, reference_source_field)
34076
- // } catch (err) {
34077
-
34078
- // }
34079
- // reference_source_field_id = data.value
34080
- // reference_source_field_type=
34081
-
34075
+ // xu-for is reference field_id
34082
34076
  reference_source_obj = await func.datasource.get_value(SESSION_ID, data.value, paramsP.dsSessionP)
34083
34077
  arr = reference_source_obj?.ret?.value
34084
34078
  } else {
34085
- // throw "field not found"
34086
-
34087
-
34079
+ // xu-for is actual data
34088
34080
  if (typeof data.value === "string") {
34089
34081
  arr = eval(data.value.replaceAll("\\", ""));
34090
34082
  }
@@ -34092,43 +34084,41 @@ func.UI.screen.execute_xu_functions = async function (
34092
34084
  arr = Array.from(Array(arr).keys());
34093
34085
  }
34094
34086
  }
34095
- // } catch (err) {
34096
-
34097
- // }
34098
-
34099
-
34100
-
34101
34087
 
34088
+ const custom_iterator_key = $elm.data().xuData.iterator_key
34089
+ const custom_iterator_val = $elm.data().xuData.iterator_val
34102
34090
 
34091
+ let iterator_key = custom_iterator_key
34092
+ let iterator_val = custom_iterator_val
34103
34093
 
34094
+ // custom FOR_VAL name or namespaced default name
34095
+ if (!custom_iterator_key) {
34096
+ is_key_dynamic_field = true
34097
+ iterator_key = (reference_source_obj?.fieldIdP || "") + "_FOR_KEY";
34098
+ }
34104
34099
 
34100
+ if (!custom_iterator_val) {
34101
+ is_val_dynamic_field = true
34102
+ iterator_val = (reference_source_obj?.fieldIdP || "") + "_FOR_VAL";
34103
+ }
34105
34104
 
34106
- // if (typeof data.value === "string") {
34107
- // arr = eval(data.value.replaceAll("\\", ""));
34108
- // }
34109
- // if (typeof arr === "number") {
34110
- // arr = Array.from(Array(arr).keys());
34111
- // }
34112
- let iterator_val = $elm.data().xuData.iterator_val;
34113
- let iterator_key = $elm.data().xuData.iterator_key;
34114
34105
  var i = 0;
34115
34106
  for await (let [_key, _val] of Object.entries(arr)) {
34116
34107
 
34117
34108
  if (_.isArray(arr)) { _key = Number(_key) }
34118
34109
 
34119
- const set_value = async function (currentRecordId, field_id, value) {
34120
- let is_dynamic_field = false;
34110
+ const set_value = async function (is_dynamic_field, currentRecordId, field_id, value) {
34121
34111
 
34122
34112
 
34113
+ if (is_dynamic_field) {
34123
34114
 
34124
- if (["_FOR_VAL", "_FOR_KEY"].includes(field_id)) {
34125
- is_dynamic_field = true;
34126
34115
  func.datasource.add_dynamic_field_to_ds(
34127
34116
  SESSION_ID,
34128
34117
  paramsP.dsSessionP,
34129
34118
  field_id,
34130
34119
  value
34131
34120
  );
34121
+
34132
34122
  } else {
34133
34123
 
34134
34124
  const _progFields = await func.datasource.get_progFields(
@@ -34157,7 +34147,7 @@ func.UI.screen.execute_xu_functions = async function (
34157
34147
  }
34158
34148
  }
34159
34149
 
34160
- return is_dynamic_field
34150
+
34161
34151
  };
34162
34152
 
34163
34153
  var currentRecordId =
@@ -34165,17 +34155,16 @@ func.UI.screen.execute_xu_functions = async function (
34165
34155
  paramsP.dsSessionP
34166
34156
  ].currentRecordId.toString();
34167
34157
 
34168
- let is_key_dynamic_field = await set_value(currentRecordId, iterator_key || "_FOR_KEY", _key);
34169
- let is_val_dynamic_field = await set_value(currentRecordId, iterator_val || "_FOR_VAL", _val);
34170
-
34158
+ await set_value(is_key_dynamic_field, currentRecordId, iterator_key, _key);
34159
+ await set_value(is_val_dynamic_field, currentRecordId, iterator_val, _val);
34171
34160
 
34172
34161
  var iterate_info = {
34173
34162
  _val,
34174
34163
  _key,
34175
- iterator_key: iterator_key || "_FOR_KEY",
34176
- iterator_val: iterator_val || "_FOR_VAL",
34177
- is_val_dynamic_field,
34164
+ iterator_key,
34165
+ iterator_val,
34178
34166
  is_key_dynamic_field,
34167
+ is_val_dynamic_field,
34179
34168
  reference_source_obj
34180
34169
  };
34181
34170
  if (parent_infoP) {
@@ -34205,10 +34194,6 @@ func.UI.screen.execute_xu_functions = async function (
34205
34194
  $(val).data().xuData.iterate_info = iterate_info;
34206
34195
  }
34207
34196
  });
34208
- // // set values in _FOR record
34209
- // currentRecordId = $divP.data().xuData.ui_id;
34210
- // set_value(currentRecordId, iterator_key || "_FOR_KEY", _key);
34211
- // set_value(currentRecordId, iterator_val || "_FOR_VAL", _val);
34212
34197
 
34213
34198
  i++;
34214
34199
  }