@xuda.io/runtime-bundle 1.0.1338 → 1.0.1339

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.
@@ -28200,6 +28200,7 @@ func.UI.find_field_in_progUi_attributes = function (progUi, field_id, prop, tag_
28200
28200
  };
28201
28201
 
28202
28202
  func.UI.update_xu_ref = function (SESSION_ID, dsSessionP, ref_field_id, $elm) {
28203
+ return;
28203
28204
  let ret;
28204
28205
  const _session = SESSION_OBJ[SESSION_ID];
28205
28206
  let _ds_0 = _session.DS_GLB[0];
@@ -28327,13 +28328,126 @@ func.UI.update_xu_ref = function (SESSION_ID, dsSessionP, ref_field_id, $elm) {
28327
28328
  }
28328
28329
  return a;
28329
28330
  }
28330
- // deepUpdateObject(SYS_GLOBAL_OBJ_REFS[ref_field_id], obj);
28331
- SYS_GLOBAL_OBJ_REFS[ref_field_id] = obj;
28331
+ deepUpdateObject(SYS_GLOBAL_OBJ_REFS[ref_field_id], obj);
28332
+ // SYS_GLOBAL_OBJ_REFS[ref_field_id] = obj;
28332
28333
  ret = true;
28333
28334
  }
28334
28335
 
28335
28336
  return ret;
28336
28337
  };
28338
+
28339
+ func.UI.create_xu_ref = function (SESSION_ID, dsSessionP, ref_field_id, $elm) {
28340
+ let ret;
28341
+ const _session = SESSION_OBJ[SESSION_ID];
28342
+ let _ds_0 = _session.DS_GLB[0];
28343
+
28344
+ function createWatchedObject(obj, onChange) {
28345
+ const watchers = new WeakMap();
28346
+
28347
+ function createProxy(target, path = []) {
28348
+ if (watchers.has(target)) {
28349
+ return watchers.get(target);
28350
+ }
28351
+
28352
+ const proxy = new Proxy(target, {
28353
+ set(obj, prop, value) {
28354
+ const oldValue = obj[prop];
28355
+ let currentPath = [...path, prop];
28356
+
28357
+ // Set the new value
28358
+ obj[prop] = value;
28359
+
28360
+ // If the new value is an object, make it observable too
28361
+ if (typeof value === 'object' && value !== null) {
28362
+ obj[prop] = createProxy(value, currentPath);
28363
+ }
28364
+
28365
+ // Notify of change
28366
+ // if (oldValue !== value) {
28367
+ if (!_.isEqual(value, oldValue)) {
28368
+ currentPath.shift();
28369
+ onChange({
28370
+ path: currentPath.join('.'),
28371
+ oldValue,
28372
+ newValue: value,
28373
+ type: 'set',
28374
+ timestamp: Date.now(),
28375
+ });
28376
+ }
28377
+
28378
+ return true;
28379
+ },
28380
+
28381
+ deleteProperty(obj, prop) {
28382
+ const oldValue = obj[prop];
28383
+ const currentPath = [...path, prop];
28384
+
28385
+ delete obj[prop];
28386
+
28387
+ onChange({
28388
+ path: currentPath.join('.'),
28389
+ oldValue,
28390
+ newValue: undefined,
28391
+ type: 'delete',
28392
+ timestamp: Date.now(),
28393
+ });
28394
+
28395
+ return true;
28396
+ },
28397
+ });
28398
+
28399
+ // Make nested objects observable
28400
+ for (const [key, value] of Object.entries(target)) {
28401
+ if (typeof value === 'object' && value !== null) {
28402
+ target[key] = createProxy(value, [...path, key]);
28403
+ }
28404
+ }
28405
+
28406
+ watchers.set(target, proxy);
28407
+ return proxy;
28408
+ }
28409
+
28410
+ return createProxy(obj);
28411
+ }
28412
+
28413
+ let _ds = _session.DS_GLB[dsSessionP];
28414
+
28415
+ const watchedDs = createWatchedObject({ _ref: _ds }, async (change) => {
28416
+ // console.log('Change detected:', change);
28417
+ const { path, newValue, oldValue } = change;
28418
+
28419
+ try {
28420
+ if (_.isEqual(newValue, oldValue)) return;
28421
+
28422
+ const _session = SESSION_OBJ[SESSION_ID];
28423
+
28424
+ if (_session?.watchers?.[path]) {
28425
+ const fx = _session?.watchers?.[path];
28426
+ fx(change);
28427
+ }
28428
+ } catch (error) {}
28429
+ });
28430
+
28431
+ let obj = { ds: watchedDs._ref, data: {}, props: _ds.in_parameters || {} };
28432
+ try {
28433
+ const row_idx = func.common.find_ROWID_idx(_ds, _ds.currentRecordId);
28434
+ obj.data = _ds?.data_feed?.rows?.[row_idx];
28435
+ } catch (error) {
28436
+ // error normal if find_ROWID_idx fail
28437
+ }
28438
+
28439
+ let SYS_GLOBAL_OBJ_REFS = _ds_0.data_system['SYS_GLOBAL_OBJ_REFS'];
28440
+
28441
+ if ($elm) {
28442
+ const attributes = $elm?.data()?.xuData?.xuPanelProps || $elm?.data()?.xuData?.debug_info?.attribute_stat || {};
28443
+ obj.attributes = attributes;
28444
+ obj.xu_ui_id = $elm.attr('xu-ui-id');
28445
+ }
28446
+
28447
+ SYS_GLOBAL_OBJ_REFS[ref_field_id] = obj;
28448
+
28449
+ return ret;
28450
+ };
28337
28451
  func.datasource = {};
28338
28452
  func.datasource.create = async function (
28339
28453
  SESSION_ID,