@xuda.io/xuda-worker-bundle 1.3.2613 → 1.3.2615

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 +133 -67
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -185,6 +185,96 @@ 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.emit = function (name, data) {
212
+ const handlers = func.runtime.platform._event_bus[name];
213
+ if (handlers) {
214
+ for (let i = 0; i < handlers.length; i++) {
215
+ handlers[i](data);
216
+ }
217
+ }
218
+ // also fire on DOM if in browser (for backward compatibility with $(document).on listeners)
219
+ if (func.runtime.platform.has_document() && typeof $ !== 'undefined') {
220
+ $(document).trigger(name, Array.isArray(data) ? data : [data]);
221
+ }
222
+ };
223
+
224
+ // ── Platform helpers for DOM-independent resource loading ──
225
+ func.runtime.platform.load_script = function (url, type, callback) {
226
+ if (typeof document !== 'undefined') {
227
+ const script = document.createElement('script');
228
+ script.src = url;
229
+ if (type) script.type = type;
230
+ script.onload = callback;
231
+ document.head.appendChild(script);
232
+ } else if (callback) {
233
+ callback();
234
+ }
235
+ };
236
+ func.runtime.platform.load_css = function (href) {
237
+ if (typeof document === 'undefined') return;
238
+ try {
239
+ if (document.querySelector('link[href="' + href + '"]')) return;
240
+ } catch (err) {
241
+ return;
242
+ }
243
+ const link = document.createElement('link');
244
+ link.rel = 'stylesheet';
245
+ link.type = 'text/css';
246
+ link.href = href;
247
+ document.head.insertBefore(link, document.head.firstChild);
248
+ };
249
+ func.runtime.platform.remove_js_css = function (filename, filetype) {
250
+ if (typeof document === 'undefined') return;
251
+ const tagName = filetype === 'js' ? 'script' : filetype === 'css' ? 'link' : 'none';
252
+ const attr = filetype === 'js' ? 'src' : filetype === 'css' ? 'href' : 'none';
253
+ const elements = document.getElementsByTagName(tagName);
254
+ for (let i = elements.length - 1; i >= 0; i--) {
255
+ if (elements[i] && elements[i].getAttribute(attr) != null && elements[i].getAttribute(attr).indexOf(filename) !== -1) {
256
+ elements[i].parentNode.removeChild(elements[i]);
257
+ }
258
+ }
259
+ };
260
+ func.runtime.platform.inject_css = function (cssText) {
261
+ if (typeof document === 'undefined' || !cssText) return;
262
+ const style = document.createElement('style');
263
+ style.type = 'text/css';
264
+ style.textContent = cssText;
265
+ document.head.appendChild(style);
266
+ };
267
+ func.runtime.platform.set_title = function (title) {
268
+ if (typeof document !== 'undefined') {
269
+ document.title = title;
270
+ }
271
+ };
272
+ func.runtime.platform.set_cursor = function (element, cursor) {
273
+ if (typeof $ !== 'undefined' && element) {
274
+ $(element).css('cursor', cursor);
275
+ }
276
+ };
277
+
188
278
  func.runtime.env = {
189
279
  get_url_params: function () {
190
280
  const search = func.runtime.platform.get_url_search();
@@ -3748,7 +3838,8 @@ func.datasource.execute_view_events = async function (SESSION_ID, dataSourceSess
3748
3838
  if (cond) {
3749
3839
  var elem_params = undefined;
3750
3840
  if (!glb.IS_WORKER) {
3751
- elem_params = $('#' + _ds.containerId).data('params');
3841
+ const container_meta = func.runtime.ui.get_meta_by_element_id(_ds.containerId);
3842
+ elem_params = container_meta?.params;
3752
3843
  }
3753
3844
  const ret = await func.events.execute(
3754
3845
  SESSION_ID,
@@ -3884,13 +3975,12 @@ func.datasource.clean = function (SESSION_ID, screenIdP) {
3884
3975
  var arr = [];
3885
3976
  for (const [key, val] of Object.entries(SESSION_OBJ[SESSION_ID].DS_GLB)) {
3886
3977
  try {
3978
+ const screen_parent_id = (typeof $ !== 'undefined' && val.screenId) ? $('#' + val.screenId).parent().attr('id') : null;
3887
3979
  if (
3888
3980
  Number(key) > 0 &&
3889
3981
  (val.screenId === screenIdP ||
3890
3982
  val.rootScreenId === screenIdP ||
3891
- $('#' + val.screenId)
3892
- .parent()
3893
- .attr('id') === screenIdP ||
3983
+ screen_parent_id === screenIdP ||
3894
3984
  (val && val.parentDataSourceNo && arr.includes(val.parentDataSourceNo.toString())))
3895
3985
  ) {
3896
3986
  arr.push(key);
@@ -3959,9 +4049,7 @@ func.datasource.del = function (SESSION_ID, dsP) {
3959
4049
  _.forEach(SESSION_OBJ[SESSION_ID].WORKER_OBJ.jobs, function (val, key) {
3960
4050
  if (val && val.dsSessionP == dsP) {
3961
4051
  arr.push(key);
3962
- for (const [key, val] of Object.entries($('.screen_blocker'))) {
3963
- $(val).remove();
3964
- }
4052
+ func.runtime.ui.clear_screen_blockers();
3965
4053
  }
3966
4054
  });
3967
4055
  for (let val of arr.reverse()) {
@@ -3982,10 +4070,13 @@ func.datasource.del = function (SESSION_ID, dsP) {
3982
4070
  }
3983
4071
  }
3984
4072
  }
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];
4073
+ if (typeof $ !== 'undefined') {
4074
+ const $xu_nav = $(SESSION_OBJ[SESSION_ID].root_element).find('xu-nav');
4075
+ if ($xu_nav.length) {
4076
+ var ds_obj = func.runtime.ui.get_data($xu_nav)?.xuData?.nav_params;
4077
+ if (ds_obj) {
4078
+ delete ds_obj[dsP];
4079
+ }
3989
4080
  }
3990
4081
  }
3991
4082
  }
@@ -4316,7 +4407,7 @@ func.datasource.callback = async function (SESSION_ID, dsSessionP, rowIdP, jobNo
4316
4407
  dsSession: dsSessionP,
4317
4408
  prop: _ds.log_prop + ' ' + 'adapter',
4318
4409
  });
4319
- if (!glb.IS_WORKER) $(_session.root_element).css('cursor', 'default');
4410
+ if (!glb.IS_WORKER) func.runtime.platform.set_cursor(_session.root_element, 'default');
4320
4411
 
4321
4412
  if (_ds.prog_id) {
4322
4413
  let _ds = _session.DS_GLB[dsSessionP];
@@ -5386,7 +5477,7 @@ func.utils.job_worker = function (session_id) {
5386
5477
  func.utils.debug_report(SESSION_ID, 'utils.worker.reset', 'worker not responding', 'E', '', _session.WORKER_OBJ.jobs);
5387
5478
  _session.WORKER_OBJ.jobs = [];
5388
5479
  _session.WORKER_OBJ.stat = null;
5389
- $('.screen_blocker').remove();
5480
+ func.runtime.ui.clear_screen_blockers();
5390
5481
  };
5391
5482
  return {
5392
5483
  _interval: null,
@@ -5527,8 +5618,9 @@ func.utils.makeid = function (length) {
5527
5618
  func.utils.get_device = function () {
5528
5619
  var device;
5529
5620
  try {
5530
- if (window.cordova) {
5531
- device = window.cordova.platformId;
5621
+ const win = func.runtime.platform.get_window();
5622
+ if (win?.cordova) {
5623
+ device = win.cordova.platformId;
5532
5624
  }
5533
5625
  } catch (e) {
5534
5626
  console.error('error using ui element in server side request');
@@ -5869,16 +5961,8 @@ func.utils.clean_stringify_null = function (key, value) {
5869
5961
 
5870
5962
  func.utils.load_js_on_demand = async function (js_src, type) {
5871
5963
  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
5964
  if (glb.IS_WORKER) {
5881
- callback(script);
5965
+ callback();
5882
5966
  return;
5883
5967
  }
5884
5968
  function isScriptLoaded(src) {
@@ -5888,8 +5972,7 @@ func.utils.load_js_on_demand = async function (js_src, type) {
5888
5972
  if (isScriptLoaded(js_src)) {
5889
5973
  callback(false);
5890
5974
  } else {
5891
- getScript(js_src, function (response, status) {
5892
- // console.log(response,status)
5975
+ func.runtime.platform.load_script(js_src, type, function () {
5893
5976
  callback(true);
5894
5977
  GLB_JS_SCRIPTS_LOADED.push(js_src);
5895
5978
  });
@@ -5902,33 +5985,11 @@ func.utils.load_js_on_demand = async function (js_src, type) {
5902
5985
  };
5903
5986
 
5904
5987
  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');
5988
+ func.runtime.platform.load_css(css_href);
5922
5989
  };
5923
5990
 
5924
5991
  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
- }
5992
+ func.runtime.platform.remove_js_css(filename, filetype);
5932
5993
  };
5933
5994
 
5934
5995
  func.utils.replace_studio_drive_url = function (SESSION_ID, val) {
@@ -7237,17 +7298,19 @@ func.events.validate = async function (SESSION_ID, triggerP, dsSessionP, eventId
7237
7298
  if (_ds.panel_div_id) {
7238
7299
  try {
7239
7300
  container = '#' + _ds.panel_div_id;
7240
- if ($(container).data().xuData.panel_info) {
7241
- screen_prop = $(container).data().xuData.panel_info.paramsP;
7301
+ const panel_meta = func.runtime.ui.get_meta_by_element_id(_ds.panel_div_id);
7302
+ if (panel_meta?.xuData?.panel_info) {
7303
+ screen_prop = panel_meta.xuData.panel_info.paramsP;
7242
7304
  } else {
7243
7305
  ///////////////
7244
7306
  container = '#' + _session.DS_GLB[dsSessionP].screenId;
7307
+ const screen_meta = func.runtime.ui.get_meta_by_element_id(_session.DS_GLB[dsSessionP].screenId);
7245
7308
 
7246
- if ($(container) && $(container).data()) {
7247
- screen_prop = $(container).data().xuData.paramsP;
7309
+ if (screen_meta?.xuData) {
7310
+ screen_prop = screen_meta.xuData.paramsP;
7248
7311
  }
7249
7312
 
7250
- if (!$(container) || !$(container).length) {
7313
+ if (!screen_meta) {
7251
7314
  container = '#' + _session.DS_GLB[dsSessionP].containerId;
7252
7315
  }
7253
7316
  //////////////
@@ -7257,12 +7320,13 @@ func.events.validate = async function (SESSION_ID, triggerP, dsSessionP, eventId
7257
7320
  }
7258
7321
  } else {
7259
7322
  container = '#' + _ds.screenId;
7323
+ const screen_meta = func.runtime.ui.get_meta_by_element_id(_ds.screenId);
7260
7324
 
7261
- if ($(container) && $(container).data()) {
7262
- screen_prop = $(container).data().xuData.paramsP;
7325
+ if (screen_meta?.xuData) {
7326
+ screen_prop = screen_meta.xuData.paramsP;
7263
7327
  }
7264
7328
 
7265
- if (!$(container) || !$(container).length) {
7329
+ if (!screen_meta) {
7266
7330
  container = '#' + _ds.containerId;
7267
7331
  }
7268
7332
  }
@@ -7663,7 +7727,7 @@ func.events.execute = async function (
7663
7727
  var $calling_container;
7664
7728
  if (_session.WORKER_OBJ.jobs[job_index]) {
7665
7729
  if (_session.WORKER_OBJ.jobs[job_index].paramsP) {
7666
- $calling_container = $('#' + _session.WORKER_OBJ.jobs[job_index].paramsP.callingContainerP);
7730
+ $calling_container = func.runtime.ui.find_element_by_id(_session.WORKER_OBJ.jobs[job_index].paramsP.callingContainerP);
7667
7731
  } else {
7668
7732
  $calling_container = ''; // calling from datasource 0
7669
7733
  _session.WORKER_OBJ.jobs[job_index].paramsP = {};
@@ -7679,7 +7743,7 @@ func.events.execute = async function (
7679
7743
  return await func.runtime.ui.init_screen({
7680
7744
  SESSION_ID,
7681
7745
  prog_id: await get_prog_id(),
7682
- sourceScreenP: $(containerP)?.data()?.xuData.screenId,
7746
+ sourceScreenP: func.runtime.ui.get_data(containerP)?.xuData?.screenId,
7683
7747
  callingDataSource_objP: _session.DS_GLB[dsSession],
7684
7748
  $callingContainerP: $calling_container,
7685
7749
  triggerIdP: eventIdP,
@@ -7926,7 +7990,7 @@ func.events.execute = async function (
7926
7990
  emit_event: async function () {
7927
7991
  if (refIdP.value) {
7928
7992
  // if (descP.value) {
7929
- $(document).trigger(refIdP.value, [_session.DS_GLB[dsSession]]);
7993
+ func.runtime.platform.emit(refIdP.value, [_session.DS_GLB[dsSession]]);
7930
7994
  } else {
7931
7995
  func.utils.debug_report(SESSION_ID, 'func.events.execute', 'Event name missing', 'E');
7932
7996
  }
@@ -8027,12 +8091,14 @@ func.events.execute = async function (
8027
8091
  for await (const [key, val] of Object.entries(obj_values_to_update)) {
8028
8092
  var $element;
8029
8093
 
8094
+ var iterate_info = null;
8030
8095
  if (elementP) {
8031
- $element = $(`[xu-ui-id="${elementP}"]`).clone(true);
8096
+ const element_meta = func.runtime.ui.get_meta(elementP, 'xuData');
8097
+ iterate_info = element_meta?.iterate_info || null;
8032
8098
  }
8033
8099
 
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);
8100
+ let ret_field_id = await func.expression.get(SESSION_ID, val.id.trim(), dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
8101
+ let ret_value = await func.expression.get(SESSION_ID, val.val.trim(), dsSessionP, 'update', null, null, null, null, null, null, iterate_info);
8036
8102
  let _field_id = ret_field_id.result;
8037
8103
  let _value = ret_value.result;
8038
8104
 
@@ -8357,7 +8423,7 @@ func.events.check_jobs_idle = async function (SESSION_ID, jobsP) {
8357
8423
  }
8358
8424
  }, 100);
8359
8425
  var do_callback = function () {
8360
- window.clearInterval(listener);
8426
+ clearInterval(listener);
8361
8427
  resolve();
8362
8428
  };
8363
8429
  });
@@ -8369,7 +8435,7 @@ setInterval(function () {
8369
8435
  }, 1000);
8370
8436
 
8371
8437
  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'];
8438
+ if (fieldsChangedP.includes('SYS_GLOBAL_STR_BROWSER_TITLE')) func.runtime.platform.set_title(dsP.dataset_new['SYS_GLOBAL_STR_BROWSER_TITLE']);
8373
8439
  };
8374
8440
 
8375
8441
  func.events.execute_PENDING_OPEN_URL_EVENTS = async function () {
@@ -8392,7 +8458,7 @@ func.events.execute_PENDING_OPEN_URL_EVENTS = async function () {
8392
8458
  prog_id: params_obj.prog,
8393
8459
  sourceScreenP: null,
8394
8460
  callingDataSource_objP: null,
8395
- $callingContainerP: $('#embed_' + SESSION_ID),
8461
+ $callingContainerP: func.runtime.ui.get_session_root(SESSION_ID),
8396
8462
  triggerIdP: null,
8397
8463
  rowIdP: null,
8398
8464
  jobNoP: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-worker-bundle",
3
- "version": "1.3.2613",
3
+ "version": "1.3.2615",
4
4
  "description": "xuda framework",
5
5
  "main": "index.js",
6
6
  "scripts": {