@xuda.io/xuda-worker-bundle 1.3.2614 → 1.3.2616

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.
Files changed (2) hide show
  1. package/index.js +141 -67
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -185,6 +185,104 @@ func.runtime.platform = {
185
185
  return true;
186
186
  },
187
187
  };
188
+
189
+ // ── Platform-agnostic event bus ──
190
+ // Works in browser, worker, and Node environments.
191
+ // In browser, bridge DOM events into this bus so core code never touches $(document) directly.
192
+ func.runtime.platform._event_bus = {};
193
+ func.runtime.platform.on = function (name, handler) {
194
+ if (!func.runtime.platform._event_bus[name]) {
195
+ func.runtime.platform._event_bus[name] = [];
196
+ }
197
+ func.runtime.platform._event_bus[name].push(handler);
198
+ };
199
+ func.runtime.platform.off = function (name, handler) {
200
+ const handlers = func.runtime.platform._event_bus[name];
201
+ if (!handlers) return;
202
+ if (!handler) {
203
+ delete func.runtime.platform._event_bus[name];
204
+ return;
205
+ }
206
+ const index = handlers.indexOf(handler);
207
+ if (index !== -1) {
208
+ handlers.splice(index, 1);
209
+ }
210
+ };
211
+ func.runtime.platform._emitting = {};
212
+ func.runtime.platform.emit = function (name, data) {
213
+ // re-entrancy guard: prevent infinite loops when DOM bridge triggers the same event
214
+ if (func.runtime.platform._emitting[name]) return;
215
+ func.runtime.platform._emitting[name] = true;
216
+ try {
217
+ const handlers = func.runtime.platform._event_bus[name];
218
+ if (handlers) {
219
+ for (let i = 0; i < handlers.length; i++) {
220
+ handlers[i](data);
221
+ }
222
+ }
223
+ // also fire on DOM if in browser (for backward compatibility with $(document).on listeners)
224
+ if (func.runtime.platform.has_document() && typeof $ !== 'undefined') {
225
+ $(document).trigger(name, Array.isArray(data) ? data : [data]);
226
+ }
227
+ } finally {
228
+ func.runtime.platform._emitting[name] = false;
229
+ }
230
+ };
231
+
232
+ // ── Platform helpers for DOM-independent resource loading ──
233
+ func.runtime.platform.load_script = function (url, type, callback) {
234
+ if (typeof document !== 'undefined') {
235
+ const script = document.createElement('script');
236
+ script.src = url;
237
+ if (type) script.type = type;
238
+ script.onload = callback;
239
+ document.head.appendChild(script);
240
+ } else if (callback) {
241
+ callback();
242
+ }
243
+ };
244
+ func.runtime.platform.load_css = function (href) {
245
+ if (typeof document === 'undefined') return;
246
+ try {
247
+ if (document.querySelector('link[href="' + href + '"]')) return;
248
+ } catch (err) {
249
+ return;
250
+ }
251
+ const link = document.createElement('link');
252
+ link.rel = 'stylesheet';
253
+ link.type = 'text/css';
254
+ link.href = href;
255
+ document.head.insertBefore(link, document.head.firstChild);
256
+ };
257
+ func.runtime.platform.remove_js_css = function (filename, filetype) {
258
+ if (typeof document === 'undefined') return;
259
+ const tagName = filetype === 'js' ? 'script' : filetype === 'css' ? 'link' : 'none';
260
+ const attr = filetype === 'js' ? 'src' : filetype === 'css' ? 'href' : 'none';
261
+ const elements = document.getElementsByTagName(tagName);
262
+ for (let i = elements.length - 1; i >= 0; i--) {
263
+ if (elements[i] && elements[i].getAttribute(attr) != null && elements[i].getAttribute(attr).indexOf(filename) !== -1) {
264
+ elements[i].parentNode.removeChild(elements[i]);
265
+ }
266
+ }
267
+ };
268
+ func.runtime.platform.inject_css = function (cssText) {
269
+ if (typeof document === 'undefined' || !cssText) return;
270
+ const style = document.createElement('style');
271
+ style.type = 'text/css';
272
+ style.textContent = cssText;
273
+ document.head.appendChild(style);
274
+ };
275
+ func.runtime.platform.set_title = function (title) {
276
+ if (typeof document !== 'undefined') {
277
+ document.title = title;
278
+ }
279
+ };
280
+ func.runtime.platform.set_cursor = function (element, cursor) {
281
+ if (typeof $ !== 'undefined' && element) {
282
+ $(element).css('cursor', cursor);
283
+ }
284
+ };
285
+
188
286
  func.runtime.env = {
189
287
  get_url_params: function () {
190
288
  const search = func.runtime.platform.get_url_search();
@@ -3748,7 +3846,8 @@ func.datasource.execute_view_events = async function (SESSION_ID, dataSourceSess
3748
3846
  if (cond) {
3749
3847
  var elem_params = undefined;
3750
3848
  if (!glb.IS_WORKER) {
3751
- elem_params = $('#' + _ds.containerId).data('params');
3849
+ const container_meta = func.runtime.ui.get_meta_by_element_id(_ds.containerId);
3850
+ elem_params = container_meta?.params;
3752
3851
  }
3753
3852
  const ret = await func.events.execute(
3754
3853
  SESSION_ID,
@@ -3884,13 +3983,12 @@ func.datasource.clean = function (SESSION_ID, screenIdP) {
3884
3983
  var arr = [];
3885
3984
  for (const [key, val] of Object.entries(SESSION_OBJ[SESSION_ID].DS_GLB)) {
3886
3985
  try {
3986
+ const screen_parent_id = (typeof $ !== 'undefined' && val.screenId) ? $('#' + val.screenId).parent().attr('id') : null;
3887
3987
  if (
3888
3988
  Number(key) > 0 &&
3889
3989
  (val.screenId === screenIdP ||
3890
3990
  val.rootScreenId === screenIdP ||
3891
- $('#' + val.screenId)
3892
- .parent()
3893
- .attr('id') === screenIdP ||
3991
+ screen_parent_id === screenIdP ||
3894
3992
  (val && val.parentDataSourceNo && arr.includes(val.parentDataSourceNo.toString())))
3895
3993
  ) {
3896
3994
  arr.push(key);
@@ -3959,9 +4057,7 @@ func.datasource.del = function (SESSION_ID, dsP) {
3959
4057
  _.forEach(SESSION_OBJ[SESSION_ID].WORKER_OBJ.jobs, function (val, key) {
3960
4058
  if (val && val.dsSessionP == dsP) {
3961
4059
  arr.push(key);
3962
- for (const [key, val] of Object.entries($('.screen_blocker'))) {
3963
- $(val).remove();
3964
- }
4060
+ func.runtime.ui.clear_screen_blockers();
3965
4061
  }
3966
4062
  });
3967
4063
  for (let val of arr.reverse()) {
@@ -3982,10 +4078,13 @@ func.datasource.del = function (SESSION_ID, dsP) {
3982
4078
  }
3983
4079
  }
3984
4080
  }
3985
- if ($(SESSION_OBJ[SESSION_ID].root_element).find('xu-nav').length) {
3986
- var ds_obj = $(SESSION_OBJ[SESSION_ID].root_element).find('xu-nav')?.data()?.xuData.nav_params;
3987
- if (ds_obj) {
3988
- delete ds_obj[dsP];
4081
+ if (typeof $ !== 'undefined') {
4082
+ const $xu_nav = $(SESSION_OBJ[SESSION_ID].root_element).find('xu-nav');
4083
+ if ($xu_nav.length) {
4084
+ var ds_obj = func.runtime.ui.get_data($xu_nav)?.xuData?.nav_params;
4085
+ if (ds_obj) {
4086
+ delete ds_obj[dsP];
4087
+ }
3989
4088
  }
3990
4089
  }
3991
4090
  }
@@ -4316,7 +4415,7 @@ func.datasource.callback = async function (SESSION_ID, dsSessionP, rowIdP, jobNo
4316
4415
  dsSession: dsSessionP,
4317
4416
  prop: _ds.log_prop + ' ' + 'adapter',
4318
4417
  });
4319
- if (!glb.IS_WORKER) $(_session.root_element).css('cursor', 'default');
4418
+ if (!glb.IS_WORKER) func.runtime.platform.set_cursor(_session.root_element, 'default');
4320
4419
 
4321
4420
  if (_ds.prog_id) {
4322
4421
  let _ds = _session.DS_GLB[dsSessionP];
@@ -5386,7 +5485,7 @@ func.utils.job_worker = function (session_id) {
5386
5485
  func.utils.debug_report(SESSION_ID, 'utils.worker.reset', 'worker not responding', 'E', '', _session.WORKER_OBJ.jobs);
5387
5486
  _session.WORKER_OBJ.jobs = [];
5388
5487
  _session.WORKER_OBJ.stat = null;
5389
- $('.screen_blocker').remove();
5488
+ func.runtime.ui.clear_screen_blockers();
5390
5489
  };
5391
5490
  return {
5392
5491
  _interval: null,
@@ -5527,8 +5626,9 @@ func.utils.makeid = function (length) {
5527
5626
  func.utils.get_device = function () {
5528
5627
  var device;
5529
5628
  try {
5530
- if (window.cordova) {
5531
- device = window.cordova.platformId;
5629
+ const win = func.runtime.platform.get_window();
5630
+ if (win?.cordova) {
5631
+ device = win.cordova.platformId;
5532
5632
  }
5533
5633
  } catch (e) {
5534
5634
  console.error('error using ui element in server side request');
@@ -5869,16 +5969,8 @@ func.utils.clean_stringify_null = function (key, value) {
5869
5969
 
5870
5970
  func.utils.load_js_on_demand = async function (js_src, type) {
5871
5971
  const get_script = function (callback) {
5872
- function getScript(scriptUrl, callback) {
5873
- const script = document.createElement('script');
5874
- script.src = scriptUrl;
5875
- if (type) script.type = type;
5876
- script.onload = callback;
5877
-
5878
- document.head.appendChild(script);
5879
- }
5880
5972
  if (glb.IS_WORKER) {
5881
- callback(script);
5973
+ callback();
5882
5974
  return;
5883
5975
  }
5884
5976
  function isScriptLoaded(src) {
@@ -5888,8 +5980,7 @@ func.utils.load_js_on_demand = async function (js_src, type) {
5888
5980
  if (isScriptLoaded(js_src)) {
5889
5981
  callback(false);
5890
5982
  } else {
5891
- getScript(js_src, function (response, status) {
5892
- // console.log(response,status)
5983
+ func.runtime.platform.load_script(js_src, type, function () {
5893
5984
  callback(true);
5894
5985
  GLB_JS_SCRIPTS_LOADED.push(js_src);
5895
5986
  });
@@ -5902,33 +5993,11 @@ func.utils.load_js_on_demand = async function (js_src, type) {
5902
5993
  };
5903
5994
 
5904
5995
  func.utils.load_css_on_demand = function (css_href) {
5905
- function isCssLoaded(src) {
5906
- try {
5907
- return document.querySelector('link[href="' + src + '"]') ? true : false;
5908
- } catch (err) {
5909
- console.warn(`load css ${css_href} failed`);
5910
- return true;
5911
- }
5912
- }
5913
-
5914
- if (isCssLoaded(css_href)) {
5915
- return;
5916
- }
5917
- return $('<link/>', {
5918
- rel: 'stylesheet',
5919
- type: 'text/css',
5920
- href: css_href,
5921
- }).prependTo('head');
5996
+ func.runtime.platform.load_css(css_href);
5922
5997
  };
5923
5998
 
5924
5999
  func.utils.remove_js_css_file = function (filename, filetype) {
5925
- var targetelement = filetype == 'js' ? 'script' : filetype == 'css' ? 'link' : 'none'; //determine element type to create nodelist from
5926
- var targetattr = filetype == 'js' ? 'src' : filetype == 'css' ? 'href' : 'none'; //determine corresponding attribute to test for
5927
- var allsuspects = document.getElementsByTagName(targetelement);
5928
- for (var i = allsuspects.length; i >= 0; i--) {
5929
- //search backwards within node list for matching elements to remove
5930
- if (allsuspects[i] && allsuspects[i].getAttribute(targetattr) != null && allsuspects[i].getAttribute(targetattr).indexOf(filename) != -1) allsuspects[i].parentNode.removeChild(allsuspects[i]); //remove element by calling parentNode.removeChild()
5931
- }
6000
+ func.runtime.platform.remove_js_css(filename, filetype);
5932
6001
  };
5933
6002
 
5934
6003
  func.utils.replace_studio_drive_url = function (SESSION_ID, val) {
@@ -7237,17 +7306,19 @@ func.events.validate = async function (SESSION_ID, triggerP, dsSessionP, eventId
7237
7306
  if (_ds.panel_div_id) {
7238
7307
  try {
7239
7308
  container = '#' + _ds.panel_div_id;
7240
- if ($(container).data().xuData.panel_info) {
7241
- screen_prop = $(container).data().xuData.panel_info.paramsP;
7309
+ const panel_meta = func.runtime.ui.get_meta_by_element_id(_ds.panel_div_id);
7310
+ if (panel_meta?.xuData?.panel_info) {
7311
+ screen_prop = panel_meta.xuData.panel_info.paramsP;
7242
7312
  } else {
7243
7313
  ///////////////
7244
7314
  container = '#' + _session.DS_GLB[dsSessionP].screenId;
7315
+ const screen_meta = func.runtime.ui.get_meta_by_element_id(_session.DS_GLB[dsSessionP].screenId);
7245
7316
 
7246
- if ($(container) && $(container).data()) {
7247
- screen_prop = $(container).data().xuData.paramsP;
7317
+ if (screen_meta?.xuData) {
7318
+ screen_prop = screen_meta.xuData.paramsP;
7248
7319
  }
7249
7320
 
7250
- if (!$(container) || !$(container).length) {
7321
+ if (!screen_meta) {
7251
7322
  container = '#' + _session.DS_GLB[dsSessionP].containerId;
7252
7323
  }
7253
7324
  //////////////
@@ -7257,12 +7328,13 @@ func.events.validate = async function (SESSION_ID, triggerP, dsSessionP, eventId
7257
7328
  }
7258
7329
  } else {
7259
7330
  container = '#' + _ds.screenId;
7331
+ const screen_meta = func.runtime.ui.get_meta_by_element_id(_ds.screenId);
7260
7332
 
7261
- if ($(container) && $(container).data()) {
7262
- screen_prop = $(container).data().xuData.paramsP;
7333
+ if (screen_meta?.xuData) {
7334
+ screen_prop = screen_meta.xuData.paramsP;
7263
7335
  }
7264
7336
 
7265
- if (!$(container) || !$(container).length) {
7337
+ if (!screen_meta) {
7266
7338
  container = '#' + _ds.containerId;
7267
7339
  }
7268
7340
  }
@@ -7663,7 +7735,7 @@ func.events.execute = async function (
7663
7735
  var $calling_container;
7664
7736
  if (_session.WORKER_OBJ.jobs[job_index]) {
7665
7737
  if (_session.WORKER_OBJ.jobs[job_index].paramsP) {
7666
- $calling_container = $('#' + _session.WORKER_OBJ.jobs[job_index].paramsP.callingContainerP);
7738
+ $calling_container = func.runtime.ui.find_element_by_id(_session.WORKER_OBJ.jobs[job_index].paramsP.callingContainerP);
7667
7739
  } else {
7668
7740
  $calling_container = ''; // calling from datasource 0
7669
7741
  _session.WORKER_OBJ.jobs[job_index].paramsP = {};
@@ -7679,7 +7751,7 @@ func.events.execute = async function (
7679
7751
  return await func.runtime.ui.init_screen({
7680
7752
  SESSION_ID,
7681
7753
  prog_id: await get_prog_id(),
7682
- sourceScreenP: $(containerP)?.data()?.xuData.screenId,
7754
+ sourceScreenP: func.runtime.ui.get_data(containerP)?.xuData?.screenId,
7683
7755
  callingDataSource_objP: _session.DS_GLB[dsSession],
7684
7756
  $callingContainerP: $calling_container,
7685
7757
  triggerIdP: eventIdP,
@@ -7926,7 +7998,7 @@ func.events.execute = async function (
7926
7998
  emit_event: async function () {
7927
7999
  if (refIdP.value) {
7928
8000
  // if (descP.value) {
7929
- $(document).trigger(refIdP.value, [_session.DS_GLB[dsSession]]);
8001
+ func.runtime.platform.emit(refIdP.value, [_session.DS_GLB[dsSession]]);
7930
8002
  } else {
7931
8003
  func.utils.debug_report(SESSION_ID, 'func.events.execute', 'Event name missing', 'E');
7932
8004
  }
@@ -8027,12 +8099,14 @@ func.events.execute = async function (
8027
8099
  for await (const [key, val] of Object.entries(obj_values_to_update)) {
8028
8100
  var $element;
8029
8101
 
8102
+ var iterate_info = null;
8030
8103
  if (elementP) {
8031
- $element = $(`[xu-ui-id="${elementP}"]`).clone(true);
8104
+ const element_meta = func.runtime.ui.get_meta(elementP, 'xuData');
8105
+ iterate_info = element_meta?.iterate_info || null;
8032
8106
  }
8033
8107
 
8034
- let ret_field_id = await func.expression.get(SESSION_ID, val.id.trim(), dsSessionP, 'update', null, null, null, null, null, null, $element?.length ? $element?.data()?.xuData?.iterate_info : null);
8035
- let ret_value = await func.expression.get(SESSION_ID, val.val.trim(), dsSessionP, 'update', null, null, null, null, null, null, $element?.length ? $element?.data()?.xuData?.iterate_info : null);
8108
+ let ret_field_id = await func.expression.get(SESSION_ID, val.id.trim(), dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
8109
+ let ret_value = await func.expression.get(SESSION_ID, val.val.trim(), dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
8036
8110
  let _field_id = ret_field_id.result;
8037
8111
  let _value = ret_value.result;
8038
8112
 
@@ -8357,7 +8431,7 @@ func.events.check_jobs_idle = async function (SESSION_ID, jobsP) {
8357
8431
  }
8358
8432
  }, 100);
8359
8433
  var do_callback = function () {
8360
- window.clearInterval(listener);
8434
+ clearInterval(listener);
8361
8435
  resolve();
8362
8436
  };
8363
8437
  });
@@ -8369,7 +8443,7 @@ setInterval(function () {
8369
8443
  }, 1000);
8370
8444
 
8371
8445
  func.events.set_browser_changes = function (dsP, fieldsChangedP) {
8372
- if (fieldsChangedP.includes('SYS_GLOBAL_STR_BROWSER_TITLE')) document.title = dsP.dataset_new['SYS_GLOBAL_STR_BROWSER_TITLE'];
8446
+ if (fieldsChangedP.includes('SYS_GLOBAL_STR_BROWSER_TITLE')) func.runtime.platform.set_title(dsP.dataset_new['SYS_GLOBAL_STR_BROWSER_TITLE']);
8373
8447
  };
8374
8448
 
8375
8449
  func.events.execute_PENDING_OPEN_URL_EVENTS = async function () {
@@ -8392,7 +8466,7 @@ func.events.execute_PENDING_OPEN_URL_EVENTS = async function () {
8392
8466
  prog_id: params_obj.prog,
8393
8467
  sourceScreenP: null,
8394
8468
  callingDataSource_objP: null,
8395
- $callingContainerP: $('#embed_' + SESSION_ID),
8469
+ $callingContainerP: func.runtime.ui.get_session_root(SESSION_ID),
8396
8470
  triggerIdP: null,
8397
8471
  rowIdP: null,
8398
8472
  jobNoP: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-worker-bundle",
3
- "version": "1.3.2614",
3
+ "version": "1.3.2616",
4
4
  "description": "xuda framework",
5
5
  "main": "index.js",
6
6
  "scripts": {