@xuda.io/runtime-bundle 1.0.1338 → 1.0.1340

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.
@@ -9069,6 +9069,7 @@ func.UI.find_field_in_progUi_attributes = function (progUi, field_id, prop, tag_
9069
9069
  };
9070
9070
 
9071
9071
  func.UI.update_xu_ref = function (SESSION_ID, dsSessionP, ref_field_id, $elm) {
9072
+ return;
9072
9073
  let ret;
9073
9074
  const _session = SESSION_OBJ[SESSION_ID];
9074
9075
  let _ds_0 = _session.DS_GLB[0];
@@ -9196,13 +9197,144 @@ func.UI.update_xu_ref = function (SESSION_ID, dsSessionP, ref_field_id, $elm) {
9196
9197
  }
9197
9198
  return a;
9198
9199
  }
9199
- // deepUpdateObject(SYS_GLOBAL_OBJ_REFS[ref_field_id], obj);
9200
- SYS_GLOBAL_OBJ_REFS[ref_field_id] = obj;
9200
+ deepUpdateObject(SYS_GLOBAL_OBJ_REFS[ref_field_id], obj);
9201
+ // SYS_GLOBAL_OBJ_REFS[ref_field_id] = obj;
9201
9202
  ret = true;
9202
9203
  }
9203
9204
 
9204
9205
  return ret;
9205
9206
  };
9207
+
9208
+ func.UI.create_xu_ref = function (SESSION_ID, dsSessionP, ref_field_id, $elm) {
9209
+ let ret;
9210
+ const _session = SESSION_OBJ[SESSION_ID];
9211
+ let _ds_0 = _session.DS_GLB[0];
9212
+
9213
+ function createWatchedObject(obj, onChange) {
9214
+ const watchers = new WeakMap();
9215
+
9216
+ function createProxy(target, path = []) {
9217
+ if (watchers.has(target)) {
9218
+ return watchers.get(target);
9219
+ }
9220
+
9221
+ const proxy = new Proxy(target, {
9222
+ set(obj, prop, value) {
9223
+ const oldValue = obj[prop];
9224
+ let currentPath = [...path, prop];
9225
+
9226
+ // Set the new value
9227
+ obj[prop] = value;
9228
+
9229
+ // If the new value is an object, make it observable too
9230
+ if (typeof value === 'object' && value !== null) {
9231
+ obj[prop] = createProxy(value, currentPath);
9232
+ }
9233
+
9234
+ // Notify of change
9235
+ // if (oldValue !== value) {
9236
+ if (!_.isEqual(value, oldValue)) {
9237
+ currentPath.shift();
9238
+ onChange({
9239
+ path: currentPath.join('.'),
9240
+ oldValue,
9241
+ newValue: value,
9242
+ type: 'set',
9243
+ timestamp: Date.now(),
9244
+ });
9245
+ }
9246
+
9247
+ return true;
9248
+ },
9249
+
9250
+ deleteProperty(obj, prop) {
9251
+ const oldValue = obj[prop];
9252
+ const currentPath = [...path, prop];
9253
+
9254
+ delete obj[prop];
9255
+
9256
+ onChange({
9257
+ path: currentPath.join('.'),
9258
+ oldValue,
9259
+ newValue: undefined,
9260
+ type: 'delete',
9261
+ timestamp: Date.now(),
9262
+ });
9263
+
9264
+ return true;
9265
+ },
9266
+ });
9267
+
9268
+ // Make nested objects observable
9269
+ for (const [key, value] of Object.entries(target)) {
9270
+ if (typeof value === 'object' && value !== null) {
9271
+ target[key] = createProxy(value, [...path, key]);
9272
+ }
9273
+ }
9274
+
9275
+ watchers.set(target, proxy);
9276
+ return proxy;
9277
+ }
9278
+
9279
+ return createProxy(obj);
9280
+ }
9281
+
9282
+ let _ds = _session.DS_GLB[dsSessionP];
9283
+
9284
+ // const watchedDs = createWatchedObject({ _ref: _ds }, async (change) => {
9285
+ // // console.log('Change detected:', change);
9286
+ // const { path, newValue, oldValue } = change;
9287
+
9288
+ // });
9289
+
9290
+ const createBasicProxy = (target) => {
9291
+ return new Proxy(target, {
9292
+ // Intercept property access
9293
+ get(obj, prop) {
9294
+ console.log(`Getting property: ${String(prop)}`);
9295
+ return prop in obj ? obj[prop] : `Property ${String(prop)} not found`;
9296
+ },
9297
+
9298
+ // Intercept property assignment
9299
+ set(obj, prop, value) {
9300
+ console.log(`Setting property: ${String(prop)} to ${value}`);
9301
+ obj[prop] = value;
9302
+ return true; // indicates success
9303
+ },
9304
+
9305
+ // Intercept property deletion
9306
+ deleteProperty(obj, prop) {
9307
+ console.log(`Deleting property: ${String(prop)}`);
9308
+ if (prop in obj) {
9309
+ delete obj[prop];
9310
+ return true;
9311
+ }
9312
+ return false;
9313
+ },
9314
+ });
9315
+ };
9316
+
9317
+ // let obj = { ds: watchedDs._ref, data: {}, props: _ds.in_parameters || {} };
9318
+ let obj = { ds: createBasicProxy(_ds), data: {}, props: _ds.in_parameters || {} };
9319
+ try {
9320
+ const row_idx = func.common.find_ROWID_idx(_ds, _ds.currentRecordId);
9321
+ obj.data = _ds?.data_feed?.rows?.[row_idx];
9322
+ } catch (error) {
9323
+ // error normal if find_ROWID_idx fail
9324
+ }
9325
+
9326
+ let SYS_GLOBAL_OBJ_REFS = _ds_0.data_system['SYS_GLOBAL_OBJ_REFS'];
9327
+
9328
+ if ($elm) {
9329
+ const attributes = $elm?.data()?.xuData?.xuPanelProps || $elm?.data()?.xuData?.debug_info?.attribute_stat || {};
9330
+ obj.attributes = attributes;
9331
+ obj.xu_ui_id = $elm.attr('xu-ui-id');
9332
+ }
9333
+
9334
+ SYS_GLOBAL_OBJ_REFS[ref_field_id] = obj;
9335
+
9336
+ return ret;
9337
+ };
9206
9338
  func.events = {};
9207
9339
  func.events.validate = async function (SESSION_ID, triggerP, dsSessionP, eventIdP, sourceP, argumentsP, return_validation_onlyP) {
9208
9340
  var _session = SESSION_OBJ[SESSION_ID];
@@ -9070,6 +9070,7 @@ func.UI.find_field_in_progUi_attributes = function (progUi, field_id, prop, tag_
9070
9070
  };
9071
9071
 
9072
9072
  func.UI.update_xu_ref = function (SESSION_ID, dsSessionP, ref_field_id, $elm) {
9073
+ return;
9073
9074
  let ret;
9074
9075
  const _session = SESSION_OBJ[SESSION_ID];
9075
9076
  let _ds_0 = _session.DS_GLB[0];
@@ -9197,13 +9198,144 @@ func.UI.update_xu_ref = function (SESSION_ID, dsSessionP, ref_field_id, $elm) {
9197
9198
  }
9198
9199
  return a;
9199
9200
  }
9200
- // deepUpdateObject(SYS_GLOBAL_OBJ_REFS[ref_field_id], obj);
9201
- SYS_GLOBAL_OBJ_REFS[ref_field_id] = obj;
9201
+ deepUpdateObject(SYS_GLOBAL_OBJ_REFS[ref_field_id], obj);
9202
+ // SYS_GLOBAL_OBJ_REFS[ref_field_id] = obj;
9202
9203
  ret = true;
9203
9204
  }
9204
9205
 
9205
9206
  return ret;
9206
9207
  };
9208
+
9209
+ func.UI.create_xu_ref = function (SESSION_ID, dsSessionP, ref_field_id, $elm) {
9210
+ let ret;
9211
+ const _session = SESSION_OBJ[SESSION_ID];
9212
+ let _ds_0 = _session.DS_GLB[0];
9213
+
9214
+ function createWatchedObject(obj, onChange) {
9215
+ const watchers = new WeakMap();
9216
+
9217
+ function createProxy(target, path = []) {
9218
+ if (watchers.has(target)) {
9219
+ return watchers.get(target);
9220
+ }
9221
+
9222
+ const proxy = new Proxy(target, {
9223
+ set(obj, prop, value) {
9224
+ const oldValue = obj[prop];
9225
+ let currentPath = [...path, prop];
9226
+
9227
+ // Set the new value
9228
+ obj[prop] = value;
9229
+
9230
+ // If the new value is an object, make it observable too
9231
+ if (typeof value === 'object' && value !== null) {
9232
+ obj[prop] = createProxy(value, currentPath);
9233
+ }
9234
+
9235
+ // Notify of change
9236
+ // if (oldValue !== value) {
9237
+ if (!_.isEqual(value, oldValue)) {
9238
+ currentPath.shift();
9239
+ onChange({
9240
+ path: currentPath.join('.'),
9241
+ oldValue,
9242
+ newValue: value,
9243
+ type: 'set',
9244
+ timestamp: Date.now(),
9245
+ });
9246
+ }
9247
+
9248
+ return true;
9249
+ },
9250
+
9251
+ deleteProperty(obj, prop) {
9252
+ const oldValue = obj[prop];
9253
+ const currentPath = [...path, prop];
9254
+
9255
+ delete obj[prop];
9256
+
9257
+ onChange({
9258
+ path: currentPath.join('.'),
9259
+ oldValue,
9260
+ newValue: undefined,
9261
+ type: 'delete',
9262
+ timestamp: Date.now(),
9263
+ });
9264
+
9265
+ return true;
9266
+ },
9267
+ });
9268
+
9269
+ // Make nested objects observable
9270
+ for (const [key, value] of Object.entries(target)) {
9271
+ if (typeof value === 'object' && value !== null) {
9272
+ target[key] = createProxy(value, [...path, key]);
9273
+ }
9274
+ }
9275
+
9276
+ watchers.set(target, proxy);
9277
+ return proxy;
9278
+ }
9279
+
9280
+ return createProxy(obj);
9281
+ }
9282
+
9283
+ let _ds = _session.DS_GLB[dsSessionP];
9284
+
9285
+ // const watchedDs = createWatchedObject({ _ref: _ds }, async (change) => {
9286
+ // // console.log('Change detected:', change);
9287
+ // const { path, newValue, oldValue } = change;
9288
+
9289
+ // });
9290
+
9291
+ const createBasicProxy = (target) => {
9292
+ return new Proxy(target, {
9293
+ // Intercept property access
9294
+ get(obj, prop) {
9295
+ console.log(`Getting property: ${String(prop)}`);
9296
+ return prop in obj ? obj[prop] : `Property ${String(prop)} not found`;
9297
+ },
9298
+
9299
+ // Intercept property assignment
9300
+ set(obj, prop, value) {
9301
+ console.log(`Setting property: ${String(prop)} to ${value}`);
9302
+ obj[prop] = value;
9303
+ return true; // indicates success
9304
+ },
9305
+
9306
+ // Intercept property deletion
9307
+ deleteProperty(obj, prop) {
9308
+ console.log(`Deleting property: ${String(prop)}`);
9309
+ if (prop in obj) {
9310
+ delete obj[prop];
9311
+ return true;
9312
+ }
9313
+ return false;
9314
+ },
9315
+ });
9316
+ };
9317
+
9318
+ // let obj = { ds: watchedDs._ref, data: {}, props: _ds.in_parameters || {} };
9319
+ let obj = { ds: createBasicProxy(_ds), data: {}, props: _ds.in_parameters || {} };
9320
+ try {
9321
+ const row_idx = func.common.find_ROWID_idx(_ds, _ds.currentRecordId);
9322
+ obj.data = _ds?.data_feed?.rows?.[row_idx];
9323
+ } catch (error) {
9324
+ // error normal if find_ROWID_idx fail
9325
+ }
9326
+
9327
+ let SYS_GLOBAL_OBJ_REFS = _ds_0.data_system['SYS_GLOBAL_OBJ_REFS'];
9328
+
9329
+ if ($elm) {
9330
+ const attributes = $elm?.data()?.xuData?.xuPanelProps || $elm?.data()?.xuData?.debug_info?.attribute_stat || {};
9331
+ obj.attributes = attributes;
9332
+ obj.xu_ui_id = $elm.attr('xu-ui-id');
9333
+ }
9334
+
9335
+ SYS_GLOBAL_OBJ_REFS[ref_field_id] = obj;
9336
+
9337
+ return ret;
9338
+ };
9207
9339
  func.UI.screen = {};
9208
9340
  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) {
9209
9341
  if (!prog_id) return console.error('program is empty');