@xuda.io/xuda-worker-bundle-min 1.3.2434 → 1.3.2435

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 +37 -910
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -10,15 +10,6 @@ var func = {};
10
10
  func.UI = {};
11
11
  func.GLB = {};
12
12
  func.mobile = {};
13
- func.runtime = {};
14
- func.runtime.bind = {};
15
- func.runtime.program = {};
16
- func.runtime.resources = {};
17
- func.runtime.render = {};
18
- func.runtime.session = {};
19
- func.runtime.workers = {};
20
- func.runtime.ui = {};
21
- func.runtime.widgets = {};
22
13
  glb.IS_STUDIO = null;
23
14
 
24
15
  var PROJECT_OBJ = {};
@@ -32,855 +23,6 @@ glb.PROTECTED_VARS = ['_NULL', '_THIS', '_FOR_KEY', '_FOR_VAL', '_ROWNO', '_ROWI
32
23
  // glb.newRecord = 999999;
33
24
 
34
25
  func.common = {};
35
- func.runtime.platform = {
36
- has_window: function () {
37
- return typeof window !== 'undefined';
38
- },
39
- has_document: function () {
40
- return typeof document !== 'undefined';
41
- },
42
- get_window: function () {
43
- if (func.runtime.platform.has_window()) {
44
- return window;
45
- }
46
- return null;
47
- },
48
- get_document: function () {
49
- if (func.runtime.platform.has_document()) {
50
- return document;
51
- }
52
- return null;
53
- },
54
- get_location: function () {
55
- const win = func.runtime.platform.get_window();
56
- return win?.location || null;
57
- },
58
- get_navigator: function () {
59
- const win = func.runtime.platform.get_window();
60
- if (win?.navigator) {
61
- return win.navigator;
62
- }
63
- if (typeof navigator !== 'undefined') {
64
- return navigator;
65
- }
66
- return null;
67
- },
68
- is_html_element: function (value) {
69
- if (typeof HTMLElement === 'undefined') {
70
- return false;
71
- }
72
- return value instanceof HTMLElement;
73
- },
74
- get_storage: function (type) {
75
- const win = func.runtime.platform.get_window();
76
- try {
77
- if (!win) {
78
- return null;
79
- }
80
- if (type === 'session') {
81
- return win.sessionStorage || null;
82
- }
83
- return win.localStorage || null;
84
- } catch (error) {
85
- return null;
86
- }
87
- },
88
- get_storage_item: function (key, type) {
89
- const storage = func.runtime.platform.get_storage(type);
90
- if (!storage) {
91
- return null;
92
- }
93
- try {
94
- return storage.getItem(key);
95
- } catch (error) {
96
- return null;
97
- }
98
- },
99
- set_storage_item: function (key, value, type) {
100
- const storage = func.runtime.platform.get_storage(type);
101
- if (!storage) {
102
- return false;
103
- }
104
- try {
105
- storage.setItem(key, value);
106
- return true;
107
- } catch (error) {
108
- return false;
109
- }
110
- },
111
- get_url_href: function () {
112
- return func.runtime.platform.get_location()?.href || '';
113
- },
114
- get_url_search: function () {
115
- return func.runtime.platform.get_location()?.search || '';
116
- },
117
- get_url_hash: function () {
118
- return func.runtime.platform.get_location()?.hash || '';
119
- },
120
- get_host: function () {
121
- return func.runtime.platform.get_location()?.host || '';
122
- },
123
- get_hostname: function () {
124
- return func.runtime.platform.get_location()?.hostname || '';
125
- },
126
- get_device_uuid: function () {
127
- const win = func.runtime.platform.get_window();
128
- return win?.device?.uuid || null;
129
- },
130
- get_device_name: function () {
131
- const win = func.runtime.platform.get_window();
132
- return win?.device?.name || null;
133
- },
134
- get_inner_size: function () {
135
- const win = func.runtime.platform.get_window();
136
- return {
137
- width: win?.innerWidth || 0,
138
- height: win?.innerHeight || 0,
139
- };
140
- },
141
- add_window_listener: function (name, handler) {
142
- const win = func.runtime.platform.get_window();
143
- if (!win?.addEventListener) {
144
- return false;
145
- }
146
- win.addEventListener(name, handler);
147
- return true;
148
- },
149
- dispatch_body_event: function (event) {
150
- const doc = func.runtime.platform.get_document();
151
- if (!doc?.body?.dispatchEvent) {
152
- return false;
153
- }
154
- doc.body.dispatchEvent(event);
155
- return true;
156
- },
157
- reload_top_window: function () {
158
- const win = func.runtime.platform.get_window();
159
- if (!win?.top?.location?.reload) {
160
- return false;
161
- }
162
- win.top.location.reload();
163
- return true;
164
- },
165
- get_service_worker: function () {
166
- const nav = func.runtime.platform.get_navigator();
167
- return nav?.serviceWorker || null;
168
- },
169
- has_service_worker: function () {
170
- return !!func.runtime.platform.get_service_worker();
171
- },
172
- register_service_worker: function (script_url) {
173
- const service_worker = func.runtime.platform.get_service_worker();
174
- if (!service_worker?.register) {
175
- return Promise.reject(new Error('serviceWorker is not available'));
176
- }
177
- return service_worker.register(script_url);
178
- },
179
- add_service_worker_listener: function (name, handler) {
180
- const service_worker = func.runtime.platform.get_service_worker();
181
- if (!service_worker?.addEventListener) {
182
- return false;
183
- }
184
- service_worker.addEventListener(name, handler);
185
- return true;
186
- },
187
- };
188
- func.runtime.env = {
189
- get_url_params: function () {
190
- const search = func.runtime.platform.get_url_search();
191
- return new URLSearchParams(search);
192
- },
193
- get_url_parameters_object: function () {
194
- const search_params = func.runtime.env.get_url_params();
195
- const parameters = {};
196
- for (const [key, value] of search_params.entries()) {
197
- parameters[key] = value;
198
- }
199
- return parameters;
200
- },
201
- get_default_session_value: function (key) {
202
- switch (key) {
203
- case 'domain':
204
- return func.runtime.platform.get_host();
205
- case 'engine_mode':
206
- return 'miniapp';
207
- case 'app_id':
208
- return 'unknown';
209
- default:
210
- return null;
211
- }
212
- },
213
- };
214
- func.runtime.session.create_tab_id = function () {
215
- const session_storage = func.runtime.platform.get_storage('session');
216
- const local_storage = func.runtime.platform.get_storage('local');
217
- var page_tab_id = session_storage?.getItem('tabID');
218
- if (page_tab_id == null) {
219
- var local_tab_id = local_storage?.getItem('tabID');
220
- page_tab_id = local_tab_id == null ? 1 : Number(local_tab_id) + 1;
221
- func.runtime.platform.set_storage_item('tabID', page_tab_id, 'local');
222
- func.runtime.platform.set_storage_item('tabID', page_tab_id, 'session');
223
- }
224
- return page_tab_id;
225
- };
226
- func.runtime.session.get_fingerprint = function (components, instance_id) {
227
- const device_uuid = func.runtime.platform.get_device_uuid();
228
- if (func.utils.get_device() && device_uuid) {
229
- if (instance_id) {
230
- return instance_id + device_uuid;
231
- }
232
- return device_uuid;
233
- }
234
- const fingerprint_id = Fingerprint2.x64hash128(
235
- components
236
- .map(function (pair) {
237
- return pair.value;
238
- })
239
- .join(),
240
- 31,
241
- );
242
-
243
- if (instance_id) {
244
- return instance_id + fingerprint_id + func.runtime.session.create_tab_id();
245
- }
246
- return fingerprint_id;
247
- };
248
- func.runtime.session.create_state = function (SESSION_ID, options) {
249
- const runtime_host = func.runtime.platform.get_host();
250
- SESSION_OBJ[SESSION_ID] = {
251
- JOB_NO: 1000,
252
- opt: options.opt,
253
- root_element: options.root_element,
254
- worker_type: options.worker_type,
255
- api_callback: options.api_callback,
256
- CODE_BUNDLE: options.code_bundle,
257
- SLIM_BUNDLE: options.slim_bundle,
258
- WORKER_OBJ: {
259
- jobs: [],
260
- num: 1000,
261
- stat: null,
262
- },
263
- DS_GLB: {},
264
- SYS_GLOBAL_OBJ_FIREBASE_AUTH_INFO: {
265
- token: '',
266
- first_name: '',
267
- last_name: '',
268
- email: '',
269
- user_id: '',
270
- picture: '',
271
- verified_email: '',
272
- locale: '',
273
- error_code: '',
274
- error_msg: '',
275
- },
276
- SYS_GLOBAL_OBJ_CLIENT_INFO: {
277
- fingerprint: '',
278
- device: '',
279
- user_agent: '',
280
- browser_version: '',
281
- browser_name: '',
282
- engine_version: '',
283
- client_ip: '',
284
- engine_name: '',
285
- os_name: '',
286
- os_version: '',
287
- device_model: '',
288
- device_vendor: '',
289
- device_type: '',
290
- screen_current_resolution_x: '',
291
- screen_current_resolution_y: '',
292
- screen_available_resolution_x: '',
293
- screen_available_resolution_y: '',
294
- language: '',
295
- time_zone: '',
296
- cpu_architecture: '',
297
- uuid: '',
298
- },
299
- PUSH_NOTIFICATION_GRANTED: null,
300
- FIREBASE_TOKEN_ID: null,
301
- USR_OBJ: {},
302
- debug_js: null,
303
- DS_UI_EVENTS_GLB: {},
304
- host: runtime_host,
305
- req_id: 0,
306
- build_info: {},
307
- CACHE_REQ: {},
308
- url_params: {
309
- ...func.common.getParametersFromUrl(),
310
- ...options.url_params,
311
- },
312
- };
313
- func.runtime.workers.ensure_registry(SESSION_ID);
314
- return SESSION_OBJ[SESSION_ID];
315
- };
316
- func.runtime.session.set_default_value = function (_session, key, value) {
317
- _session[key] = value || func.runtime.env.get_default_session_value(key);
318
- return _session[key];
319
- };
320
- func.runtime.session.populate_client_info = function (_session, components) {
321
- const _client_info = _session.SYS_GLOBAL_OBJ_CLIENT_INFO;
322
- const platform = func.runtime.platform;
323
- const { engine_mode } = _session;
324
-
325
- _client_info.fingerprint = func.runtime.session.get_fingerprint(components);
326
-
327
- if (engine_mode === 'live_preview') {
328
- const inner_size = platform.get_inner_size();
329
- _client_info.screen_current_resolution_x = inner_size.width;
330
- _client_info.screen_current_resolution_y = inner_size.height;
331
- _client_info.screen_available_resolution_x = inner_size.width;
332
- _client_info.screen_available_resolution_y = inner_size.height;
333
- } else {
334
- _client_info.screen_current_resolution_x = components[6].value[0];
335
- _client_info.screen_current_resolution_y = components[6].value[1];
336
- _client_info.screen_available_resolution_x = components[7].value[0];
337
- _client_info.screen_available_resolution_y = components[7].value[1];
338
- }
339
-
340
- const client = new ClientJS();
341
- _client_info.device = func.utils.get_device();
342
-
343
- const browser_data = client.getBrowserData();
344
- _client_info.user_agent = browser_data.ua;
345
- _client_info.browser_version = browser_data.browser.name;
346
- _client_info.browser_name = browser_data.browser.version;
347
- _client_info.engine_version = browser_data.engine.name;
348
- _client_info.engine_name = browser_data.engine.version;
349
- _client_info.os_name = browser_data.os.name;
350
- _client_info.os_version = browser_data.os.version;
351
- _client_info.device_model = browser_data.device.name;
352
- _client_info.device_vendor = browser_data.device.name;
353
- _client_info.device_type = browser_data.device.name;
354
- _client_info.language = client.getLanguage();
355
- _client_info.time_zone = client.getTimeZone();
356
- _client_info.cpu_architecture = browser_data.cpu.architecture;
357
-
358
- if (['android', 'ios', 'windows', 'macos', 'linux', 'live_preview'].includes(engine_mode) && func.utils.get_device()) {
359
- _client_info.uuid = platform.get_device_uuid();
360
- const device_name = platform.get_device_name();
361
- if (device_name) {
362
- _client_info.device_name = device_name;
363
- }
364
- }
365
- return _client_info;
366
- };
367
- func.runtime.workers.ensure_registry = function (SESSION_ID) {
368
- if (!WEB_WORKER[SESSION_ID]) {
369
- WEB_WORKER[SESSION_ID] = {};
370
- }
371
- return WEB_WORKER[SESSION_ID];
372
- };
373
- func.runtime.workers.get_registry_entry = function (SESSION_ID, worker_id) {
374
- return func.runtime.workers.ensure_registry(SESSION_ID)?.[worker_id] || null;
375
- };
376
- func.runtime.workers.set_registry_entry = function (SESSION_ID, worker_id, entry) {
377
- const worker_registry = func.runtime.workers.ensure_registry(SESSION_ID);
378
- worker_registry[worker_id] = entry;
379
- return worker_registry[worker_id];
380
- };
381
- func.runtime.workers.build_worker_name = function (glb_worker_type, session, prog_obj, worker_id, build_id) {
382
- return (
383
- `${typeof session.SLIM_BUNDLE === 'undefined' || !session.SLIM_BUNDLE ? '' : 'Slim '}${prog_obj.menuName} worker` +
384
- ' ' +
385
- glb_worker_type +
386
- ': #' +
387
- worker_id.toString() +
388
- ' ' +
389
- (build_id || '') +
390
- ' ' +
391
- session.domain
392
- );
393
- };
394
- func.runtime.workers.is_server_transport = function (session) {
395
- return !!(RUNTIME_SERVER_WEBSOCKET && RUNTIME_SERVER_WEBSOCKET_CONNECTED && (!session.opt.app_computing_mode || session.opt.app_computing_mode === 'server'));
396
- };
397
- func.runtime.workers.send_message = function (SESSION_ID, worker_id, session, msg, process_pid) {
398
- const registry_entry = func.runtime.workers.get_registry_entry(SESSION_ID, worker_id);
399
- if (!registry_entry?.worker) {
400
- return false;
401
- }
402
-
403
- if (func.runtime.workers.is_server_transport(session)) {
404
- if (process_pid) {
405
- msg.process_pid = process_pid;
406
- }
407
- registry_entry.worker.emit('message', msg);
408
- return true;
409
- }
410
-
411
- registry_entry.worker.postMessage(msg);
412
- return true;
413
- };
414
- func.runtime.workers.set_promise = function (SESSION_ID, worker_id, promise_queue_id, value) {
415
- const registry_entry = func.runtime.workers.get_registry_entry(SESSION_ID, worker_id);
416
- if (!registry_entry) {
417
- return null;
418
- }
419
- registry_entry.promise_queue[promise_queue_id] = value;
420
- return registry_entry.promise_queue[promise_queue_id];
421
- };
422
- func.runtime.workers.get_promise = function (SESSION_ID, worker_id, promise_queue_id) {
423
- const registry_entry = func.runtime.workers.get_registry_entry(SESSION_ID, worker_id);
424
- if (!registry_entry) {
425
- return null;
426
- }
427
- return registry_entry.promise_queue[promise_queue_id];
428
- };
429
- func.runtime.workers.delete_promise = function (SESSION_ID, worker_id, promise_queue_id) {
430
- const registry_entry = func.runtime.workers.get_registry_entry(SESSION_ID, worker_id);
431
- if (!registry_entry?.promise_queue) {
432
- return false;
433
- }
434
- delete registry_entry.promise_queue[promise_queue_id];
435
- return true;
436
- };
437
- func.runtime.render.get_root_data_system = function (SESSION_ID) {
438
- return SESSION_OBJ[SESSION_ID]?.DS_GLB?.[0]?.data_system || null;
439
- };
440
- func.runtime.render.resolve_xu_for_source = async function (SESSION_ID, dsSessionP, value) {
441
- let arr = value;
442
- let reference_source_obj;
443
- const _progFields = await func.datasource.get_progFields(SESSION_ID, dsSessionP);
444
- let view_field_obj = func.common.find_item_by_key(_progFields, 'field_id', value);
445
-
446
- if (view_field_obj) {
447
- reference_source_obj = await func.datasource.get_value(SESSION_ID, value, dsSessionP);
448
- arr = reference_source_obj?.ret?.value;
449
- } else {
450
- if (typeof value === 'string') {
451
- arr = eval(value.replaceAll('\\', ''));
452
- }
453
- if (typeof arr === 'number') {
454
- arr = Array.from(Array(arr).keys());
455
- }
456
- }
457
-
458
- return {
459
- arr,
460
- reference_source_obj,
461
- };
462
- };
463
- func.runtime.render.apply_iterate_value_to_ds = function (SESSION_ID, dsSessionP, currentRecordId, progFields, field_id, value, is_dynamic_field) {
464
- if (is_dynamic_field) {
465
- func.datasource.add_dynamic_field_to_ds(SESSION_ID, dsSessionP, field_id, value);
466
- return true;
467
- }
468
-
469
- let view_field_obj = func.common.find_item_by_key(progFields || [], 'field_id', field_id);
470
- if (!view_field_obj) {
471
- console.error('field not exist in dataset for xu-for method');
472
- return false;
473
- }
474
-
475
- let _ds = SESSION_OBJ[SESSION_ID].DS_GLB[dsSessionP];
476
- try {
477
- const row_idx = func.common.find_ROWID_idx(_ds, currentRecordId);
478
- _ds.data_feed.rows[row_idx][field_id] = value;
479
- return true;
480
- } catch (err) {
481
- console.error(err);
482
- return false;
483
- }
484
- };
485
- func.runtime.render.build_iterate_info = function (options) {
486
- return {
487
- _val: options._val,
488
- _key: options._key,
489
- iterator_key: options.iterator_key,
490
- iterator_val: options.iterator_val,
491
- is_key_dynamic_field: options.is_key_dynamic_field,
492
- is_val_dynamic_field: options.is_val_dynamic_field,
493
- reference_source_obj: options.reference_source_obj,
494
- };
495
- };
496
- func.runtime.render.apply_iterate_info_to_current_record = function (SESSION_ID, dsSessionP, currentRecordId, progFields, iterate_info) {
497
- if (!iterate_info) {
498
- return false;
499
- }
500
- func.runtime.render.apply_iterate_value_to_ds(SESSION_ID, dsSessionP, currentRecordId, progFields, iterate_info.iterator_key, iterate_info._key, iterate_info.is_key_dynamic_field);
501
- func.runtime.render.apply_iterate_value_to_ds(SESSION_ID, dsSessionP, currentRecordId, progFields, iterate_info.iterator_val, iterate_info._val, iterate_info.is_val_dynamic_field);
502
- return true;
503
- };
504
- func.runtime.render.sync_iterate_info_to_dataset = function (_ds, iterate_info) {
505
- if (!iterate_info) {
506
- return false;
507
- }
508
-
509
- const sync_field = function (field_id, value, is_dynamic_field) {
510
- if (is_dynamic_field) {
511
- _ds.dynamic_fields[field_id].value = value;
512
- return true;
513
- }
514
- try {
515
- const row_idx = func.common.find_ROWID_idx(_ds, _ds.currentRecordId);
516
- _ds.data_feed.rows[row_idx][field_id] = value;
517
- return true;
518
- } catch (err) {
519
- console.error(err);
520
- return false;
521
- }
522
- };
523
-
524
- sync_field(iterate_info.iterator_key, iterate_info._key, iterate_info.is_key_dynamic_field);
525
- sync_field(iterate_info.iterator_val, iterate_info._val, iterate_info.is_val_dynamic_field);
526
- return true;
527
- };
528
- func.runtime.program.get_params_obj = async function (SESSION_ID, prog_id, nodeP, dsSession) {
529
- const _prog = await func.utils.VIEWS_OBJ.get(SESSION_ID, prog_id);
530
- if (!_prog) return;
531
-
532
- let params_res = {},
533
- params_raw = {};
534
- if (_prog?.properties?.progParams) {
535
- for await (const [key, val] of Object.entries(_prog.properties.progParams)) {
536
- if (!['in', 'out'].includes(val.data.dir)) continue;
537
-
538
- if (nodeP.attributes) {
539
- if (nodeP.attributes[val.data.parameter]) {
540
- params_res[val.data.parameter] = nodeP.attributes[val.data.parameter];
541
- } else if (nodeP.attributes[`xu-exp:${val.data.parameter}`]) {
542
- if (val.data.dir == 'out') {
543
- params_res[val.data.parameter] = nodeP.attributes[`xu-exp:${val.data.parameter}`].replaceAll('@', '');
544
- } else {
545
- let ret = await func.expression.get(SESSION_ID, nodeP.attributes[`xu-exp:${val.data.parameter}`], dsSession, 'parameters');
546
- params_res[val.data.parameter] = ret.result;
547
- params_raw[val.data.parameter] = nodeP.attributes[`xu-exp:${val.data.parameter}`];
548
- }
549
- }
550
- continue;
551
- }
552
- console.warn(`Warning: Program ${_prog.properties.menuName} expected In parameter: ${val.data.parameter} but received null instead`);
553
- }
554
- }
555
- return { params_res, params_raw };
556
- };
557
- func.runtime.bind.build_datasource_changes = function (dsSessionP, currentRecordId, field_id, value) {
558
- return {
559
- [dsSessionP]: {
560
- [currentRecordId]: {
561
- [field_id]: value,
562
- },
563
- },
564
- };
565
- };
566
- func.runtime.bind.resolve_field = async function (SESSION_ID, prog_id, dsSessionP, field_id) {
567
- let _prog_id = prog_id;
568
- let _dsP = dsSessionP;
569
- let is_dynamic_field = false;
570
- let field_prop;
571
-
572
- const find_in_view = async function (field_id, prog_id) {
573
- const view_ret = await func.utils.VIEWS_OBJ.get(SESSION_ID, prog_id);
574
- if (!view_ret) {
575
- return null;
576
- }
577
- return func.common.find_item_by_key(view_ret.progFields, 'field_id', field_id);
578
- };
579
-
580
- if (['_FOR_VAL', '_FOR_KEY'].includes(field_id)) {
581
- is_dynamic_field = true;
582
- field_prop = SESSION_OBJ[SESSION_ID]?.DS_GLB?.[_dsP]?.dynamic_fields?.[field_id];
583
- } else {
584
- field_prop = await find_in_view(field_id, _prog_id);
585
- if (!field_prop) {
586
- const ret_get_value = await func.datasource.get_value(SESSION_ID, field_id, _dsP);
587
- if (ret_get_value.found) {
588
- _dsP = ret_get_value.dsSessionP;
589
- let _ds = SESSION_OBJ[SESSION_ID].DS_GLB[_dsP];
590
- _prog_id = _ds.prog_id;
591
- field_prop = await find_in_view(field_id, _prog_id);
592
- }
593
- }
594
- }
595
-
596
- if (!field_prop) {
597
- throw `field ${field_id} not found in the program scope`;
598
- }
599
-
600
- return {
601
- bind_field_id: field_id,
602
- field_prop,
603
- is_dynamic_field,
604
- dsSessionP: _dsP,
605
- prog_id: _prog_id,
606
- };
607
- };
608
- func.runtime.bind.get_field_type = function (field_prop) {
609
- return field_prop?.props?.fieldType;
610
- };
611
- func.runtime.bind.toggle_array_value = function (arr_value_before_cast, value_from_getter) {
612
- if (arr_value_before_cast.includes(value_from_getter)) {
613
- return arr_value_before_cast.filter((item) => !_.isEqual(item, value_from_getter));
614
- }
615
- arr_value_before_cast.push(value_from_getter);
616
- return arr_value_before_cast;
617
- };
618
- func.runtime.bind.get_cast_value = async function (SESSION_ID, field_prop, input_field_type, raw_value) {
619
- const field_type = func.runtime.bind.get_field_type(field_prop);
620
- var value = await func.common.get_cast_val(SESSION_ID, 'xu-bind', 'value', field_type, raw_value);
621
- if (field_type === 'object') {
622
- value = await func.common.get_cast_val(SESSION_ID, 'xu-bind', 'value', input_field_type, raw_value);
623
- }
624
- return value;
625
- };
626
- func.runtime.bind.get_source_value = function (_ds, bind_field_id, is_dynamic_field) {
627
- if (is_dynamic_field) {
628
- return _ds.dynamic_fields[bind_field_id].value;
629
- }
630
- const row_idx = func.common.find_ROWID_idx(_ds, _ds.currentRecordId);
631
- return _ds.data_feed.rows?.[row_idx]?.[bind_field_id];
632
- };
633
- func.runtime.bind.format_display_value = function ($elm, field_prop, bind_field_id, expression_value, value, input_field_type) {
634
- const field_type = func.runtime.bind.get_field_type(field_prop);
635
- const elm_value = $elm.attr('value');
636
-
637
- if (field_type === 'array' && input_field_type === 'checkbox' && elm_value) {
638
- return value.includes(elm_value);
639
- }
640
- if (field_type === 'array' && input_field_type === 'radio' && elm_value) {
641
- if (value.includes(elm_value)) {
642
- return elm_value;
643
- }
644
- return false;
645
- }
646
- if (field_type === 'object' && expression_value.split('.').length > 1) {
647
- let str = expression_value.replace(bind_field_id, '(' + JSON.stringify(value) + ')');
648
- return eval(str);
649
- }
650
- return value;
651
- };
652
- func.runtime.bind.update_reference_source_array = async function (options) {
653
- const field_type = func.runtime.bind.get_field_type(options.field_prop);
654
- const reference_source_obj = options.iterate_info?.reference_source_obj;
655
- if (!reference_source_obj || reference_source_obj.ret.type !== 'array' || options.iterate_info?.iterator_val !== options.bind_field_id) {
656
- return false;
657
- }
658
-
659
- const arr_idx = Number(options.iterate_info._key);
660
- const dataset_arr = await func.datasource.get_value(options.SESSION_ID, reference_source_obj.fieldIdP, options.dsSessionP, reference_source_obj.currentRecordId);
661
- let new_arr = _.cloneDeep(dataset_arr.ret.value);
662
-
663
- if (field_type === 'object' && options.val_is_reference_field) {
664
- let obj_item = new_arr[arr_idx];
665
- let e_exp = options.expression_value.replace(options.bind_field_id, 'obj_item');
666
- eval(e_exp + (options.input_field_type === 'string' ? `="${options.value}"` : `=${options.value}`));
667
- new_arr[arr_idx] = obj_item;
668
- } else {
669
- new_arr[arr_idx] = options.value;
670
- }
671
-
672
- let datasource_changes = func.runtime.bind.build_datasource_changes(options.dsSessionP, options.currentRecordId, reference_source_obj.fieldIdP, new_arr);
673
- await func.datasource.update(options.SESSION_ID, datasource_changes, null, true);
674
- return true;
675
- };
676
- func.runtime.resources.load_cdn = async function (SESSION_ID, resource) {
677
- let normalized_resource = resource;
678
- if (!_.isObject(normalized_resource) && _.isString(normalized_resource)) {
679
- normalized_resource = { src: normalized_resource, type: 'js' };
680
- }
681
- if (!_.isObject(normalized_resource)) {
682
- throw new Error('cdn resource in wrong format');
683
- }
684
-
685
- return new Promise(async (resolve) => {
686
- try {
687
- switch (normalized_resource.type) {
688
- case 'js':
689
- await func.utils.load_js_on_demand(normalized_resource.src);
690
- break;
691
- case 'css':
692
- await func.utils.load_js_on_demand(normalized_resource.src);
693
- break;
694
- case 'module':
695
- func.utils.load_js_on_demand(normalized_resource.src, 'module');
696
- break;
697
- default:
698
- await func.utils.load_js_on_demand(normalized_resource.src);
699
- break;
700
- }
701
- resolve();
702
- } catch (error) {
703
- func.utils.debug_report(SESSION_ID, 'xu-cdn', 'Fail to load: ' + normalized_resource, 'W');
704
- resolve();
705
- }
706
- });
707
- };
708
- func.runtime.resources.get_plugin_manifest_entry = function (_session, plugin_name) {
709
- return APP_OBJ[_session.app_id]?.app_plugins_purchased?.[plugin_name] || null;
710
- };
711
- func.runtime.resources.get_plugin_module_path = function (plugin, resource) {
712
- const manifest_entry = plugin?.manifest?.[resource];
713
- return `${manifest_entry?.dist ? 'dist/' : ''}${resource}`;
714
- };
715
- func.runtime.resources.get_plugin_module_url = async function (SESSION_ID, plugin_name, plugin, resource) {
716
- return await func.utils.get_plugin_npm_cdn(SESSION_ID, plugin_name, func.runtime.resources.get_plugin_module_path(plugin, resource));
717
- };
718
- func.runtime.resources.load_plugin_runtime_css = async function (SESSION_ID, plugin_name, plugin) {
719
- if (!plugin?.manifest?.['runtime.mjs']?.dist || !plugin?.manifest?.['runtime.mjs']?.css) {
720
- return false;
721
- }
722
- const plugin_runtime_css_url = await func.utils.get_plugin_npm_cdn(SESSION_ID, plugin_name, 'dist/runtime.css');
723
- func.utils.load_css_on_demand(plugin_runtime_css_url);
724
- return true;
725
- };
726
- func.runtime.resources.resolve_plugin_properties = async function (SESSION_ID, dsSessionP, attributes, properties) {
727
- let resolved_properties = _.cloneDeep(properties);
728
- for await (let [prop_name, prop_val] of Object.entries(resolved_properties || {})) {
729
- prop_val.value = attributes?.[prop_name];
730
- if (attributes?.[`xu-exp:${prop_name}`]) {
731
- const res = await func.expression.get(SESSION_ID, attributes[`xu-exp:${prop_name}`], dsSessionP, 'UI Attr EXP');
732
- prop_val.value = res.result;
733
- }
734
- }
735
- return resolved_properties;
736
- };
737
- func.runtime.resources.run_ui_plugin = async function (SESSION_ID, paramsP, $elm, plugin_name, value) {
738
- var _session = SESSION_OBJ[SESSION_ID];
739
- const plugin = func.runtime.resources.get_plugin_manifest_entry(_session, plugin_name);
740
- if (!plugin?.installed || !plugin?.manifest?.['runtime.mjs']?.exist || !plugin?.manifest?.['index.mjs']?.exist || !value?.enabled) {
741
- return false;
742
- }
743
-
744
- await func.runtime.resources.load_plugin_runtime_css(SESSION_ID, plugin_name, plugin);
745
-
746
- const plugin_index_src = await func.runtime.resources.get_plugin_module_url(SESSION_ID, plugin_name, plugin, 'index.mjs');
747
- const plugin_index_resources = await import(plugin_index_src);
748
- const properties = await func.runtime.resources.resolve_plugin_properties(SESSION_ID, paramsP.dsSessionP, value?.attributes, plugin_index_resources.properties);
749
-
750
- const plugin_runtime_src = await func.runtime.resources.get_plugin_module_url(SESSION_ID, plugin_name, plugin, 'runtime.mjs');
751
- const plugin_runtime_resources = await import(plugin_runtime_src);
752
-
753
- if (plugin_runtime_resources.cdn && _.isArray(plugin_runtime_resources.cdn)) {
754
- for await (const resource of plugin_runtime_resources.cdn) {
755
- await func.runtime.resources.load_cdn(SESSION_ID, resource);
756
- }
757
- }
758
-
759
- if (plugin_runtime_resources.fn) {
760
- await plugin_runtime_resources.fn(plugin_name, $elm?.[0], properties);
761
- }
762
- return true;
763
- };
764
- func.runtime.widgets.create_context = function (SESSION_ID, paramsP, prop) {
765
- const _session = SESSION_OBJ[SESSION_ID];
766
- const plugin_name = prop['xu-widget'];
767
- return {
768
- SESSION_ID,
769
- _session,
770
- plugin_name,
771
- method: prop['xu-method'] || '_default',
772
- dsP: paramsP.dsSessionP,
773
- propsP: prop,
774
- sourceP: 'widgets',
775
- plugin: APP_OBJ[_session.app_id]?.app_plugins_purchased?.[plugin_name] || null,
776
- };
777
- };
778
- func.runtime.widgets.report_error = function (context, descP, warn) {
779
- const program = context?._session?.DS_GLB?.[context.dsP];
780
- if (!program) {
781
- return null;
782
- }
783
- func.utils.debug.log(context.SESSION_ID, program.prog_id + '_' + program.callingMenuId, {
784
- module: 'widgets',
785
- action: 'Init',
786
- source: context.sourceP,
787
- prop: descP,
788
- details: descP,
789
- result: null,
790
- error: warn ? false : true,
791
- fields: null,
792
- type: 'widgets',
793
- prog_id: program.prog_id,
794
- });
795
- return null;
796
- };
797
- func.runtime.widgets.get_property_value = async function (context, fieldIdP, val, props) {
798
- if (!val) return;
799
- var value = fieldIdP in props ? props[fieldIdP] : typeof val.defaultValue === 'function' ? val?.defaultValue?.() : val?.defaultValue;
800
- if (val.render === 'eventId') {
801
- value = props?.[fieldIdP]?.event;
802
- }
803
-
804
- if (props[`xu-exp:${fieldIdP}`]) {
805
- value = (await func.expression.get(context.SESSION_ID, props[`xu-exp:${fieldIdP}`], context.dsP, 'widget property')).result;
806
- }
807
-
808
- return func.common.get_cast_val(
809
- context.SESSION_ID,
810
- 'widgets',
811
- fieldIdP,
812
- val.type,
813
- value,
814
- null,
815
- );
816
- };
817
- func.runtime.widgets.get_fields_data = async function (context, fields, props) {
818
- var data_obj = {};
819
- var return_code = 1;
820
- for await (const [key, val] of Object.entries(fields || {})) {
821
- data_obj[key] = await func.runtime.widgets.get_property_value(context, key, val, props);
822
- if (!data_obj[key] && val.mandatory) {
823
- return_code = -1;
824
- func.runtime.widgets.report_error(context, `${key} is a mandatory field.`);
825
- break;
826
- }
827
- }
828
- for await (const key of ['xu-bind']) {
829
- data_obj[key] = await func.runtime.widgets.get_property_value(context, key, props?.[key], props);
830
- }
831
-
832
- return { code: return_code, data: data_obj };
833
- };
834
- func.runtime.widgets.get_resource_path = function (context, resource) {
835
- if (context._session.worker_type === 'Dev') {
836
- return `../../plugins/${context.plugin_name}/${resource}`;
837
- }
838
- const manifest_entry = context.plugin?.manifest?.[resource];
839
- const dist_prefix = manifest_entry?.dist ? 'dist/' : '';
840
- return `https://${context._session.domain}/plugins/${context.plugin_name}/${dist_prefix}${resource}?gtp_token=${context._session.gtp_token}&app_id=${context._session.app_id}`;
841
- };
842
- func.runtime.widgets.load_css_style = function (context) {
843
- func.utils.load_css_on_demand(func.runtime.widgets.get_resource_path(context, 'style.css'));
844
- return true;
845
- };
846
- func.runtime.widgets.get_resource = async function (context, resource) {
847
- const manifest_entry = context.plugin?.manifest?.[resource];
848
- const path = `${manifest_entry?.dist ? 'dist/' : ''}${resource}`;
849
- return await func.utils.get_plugin_resource(context.SESSION_ID, context.plugin_name, path);
850
- };
851
- func.runtime.widgets.get_methods = async function (context) {
852
- const index = await func.runtime.widgets.get_resource(context, 'index.mjs');
853
- return index?.methods || {};
854
- };
855
- func.runtime.widgets.load_runtime_css = async function (context) {
856
- if (!context.plugin?.manifest?.['runtime.mjs']?.dist || !context.plugin?.manifest?.['runtime.mjs']?.css) {
857
- return false;
858
- }
859
- const plugin_runtime_css_url = await func.utils.get_plugin_npm_cdn(context.SESSION_ID, context.plugin_name, 'dist/runtime.css');
860
- func.utils.load_css_on_demand(plugin_runtime_css_url);
861
- return true;
862
- };
863
- func.runtime.widgets.build_params = function (context, $containerP, plugin_setup, api_utils, extra = {}) {
864
- return {
865
- SESSION_ID: context.SESSION_ID,
866
- method: context.method,
867
- _session: context._session,
868
- dsP: context.dsP,
869
- sourceP: context.sourceP,
870
- propsP: context.propsP,
871
- plugin_name: context.plugin_name,
872
- $containerP,
873
- plugin_setup,
874
- report_error: function (descP, warn) {
875
- return func.runtime.widgets.report_error(context, descP, warn);
876
- },
877
- call_plugin_api: async function (plugin_nameP, dataP) {
878
- return await func.utils.call_plugin_api(context.SESSION_ID, plugin_nameP, dataP);
879
- },
880
- api_utils,
881
- ...extra,
882
- };
883
- };
884
26
  func.common.find_item_by_key = function (arr, key, val) {
885
27
  return _.find(arr, function (e) {
886
28
  return e.data[key] === val;
@@ -1269,10 +411,19 @@ func.common.db = async function (SESSION_ID, serviceP, dataP, opt = {}, dsSessio
1269
411
  };
1270
412
 
1271
413
  func.common.getJsonFromUrl = function () {
1272
- return func.runtime.env.get_url_params();
414
+ const queryString = window.location.search;
415
+ const urlParams = new URLSearchParams(queryString);
416
+ return urlParams;
1273
417
  };
1274
418
  func.common.getParametersFromUrl = function () {
1275
- return func.runtime.env.get_url_parameters_object();
419
+ const searchParams = new URLSearchParams(window.location.search);
420
+ const parameters = {};
421
+
422
+ for (const [key, value] of searchParams.entries()) {
423
+ parameters[key] = value;
424
+ }
425
+
426
+ return parameters;
1276
427
  };
1277
428
 
1278
429
  func.common.getObjectFromUrl = function (url, element_attributes_obj, embed_params_obj) {
@@ -4084,13 +3235,13 @@ func.datasource.update = async function (SESSION_ID, datasource_changes, update_
4084
3235
  });
4085
3236
  }
4086
3237
 
4087
- await func.runtime.ui.refresh_screen({
3238
+ await func.UI.screen.refresh_screen(
4088
3239
  SESSION_ID,
4089
- fields_changed_arr: klona.klona(fields_changed),
4090
- datasource_changed: datasource_changed[0],
4091
- fields_changed_datasource: datasource_changed[0],
4092
- watcher: value,
4093
- });
3240
+ klona.klona(fields_changed), // _.cloneDeep(fields_changed),
3241
+ datasource_changed[0],
3242
+ datasource_changed[0], // refresh the current datasource only
3243
+ value,
3244
+ );
4094
3245
  }
4095
3246
 
4096
3247
  continue;
@@ -4194,27 +3345,28 @@ func.datasource.update = async function (SESSION_ID, datasource_changes, update_
4194
3345
  }
4195
3346
  ///// REFRESH SCREEN
4196
3347
  if (fields_changed.length) {
3348
+ // Push changes into reactive signals (V2 reactive system)
3349
+ if (func.reactive?.bridge?.interceptUpdate) {
3350
+ func.reactive.bridge.interceptUpdate(SESSION_ID, datasource_changes, fields_changed, datasource_changed);
3351
+ }
3352
+
4197
3353
  function findMin(arr) {
4198
3354
  return Math.min(...arr.map(Number));
4199
3355
  }
4200
3356
 
4201
- // await func.UI.screen.refresh_xu_attributes(SESSION_ID, _.cloneDeep(fields_changed), null, null, findMin(datasource_changed), avoid_xu_for_refresh, trigger);
4202
- await func.runtime.ui.refresh_xu_attributes({
4203
- SESSION_ID,
4204
- fields_arr: klona.klona(fields_changed),
4205
- jobNoP: null,
4206
- $elm_to_search: null,
4207
- dsSession_changed: findMin(datasource_changed),
4208
- avoid_xu_for_refresh,
4209
- trigger,
4210
- });
4211
- // await removed from the below function cause to dead lock Mar 3 25
4212
- await func.runtime.ui.refresh_screen({
4213
- SESSION_ID,
4214
- fields_changed_arr: klona.klona(fields_changed),
4215
- datasource_changed: null,
4216
- fields_changed_datasource: datasource_changed[0],
4217
- });
3357
+ // In reactive mode, effects handle DOM updates automatically via the scheduler.
3358
+ // Skip the legacy scan-based refresh which does O(n) element scanning.
3359
+ if (!_session._reactiveMode) {
3360
+ // await func.UI.screen.refresh_xu_attributes(SESSION_ID, _.cloneDeep(fields_changed), null, null, findMin(datasource_changed), avoid_xu_for_refresh, trigger);
3361
+ await func.UI.screen.refresh_xu_attributes(SESSION_ID, klona.klona(fields_changed), null, null, findMin(datasource_changed), avoid_xu_for_refresh, trigger);
3362
+ // await removed from the below function cause to dead lock Mar 3 25
3363
+ await func.UI.screen.refresh_screen(
3364
+ SESSION_ID,
3365
+ klona.klona(fields_changed), // _.cloneDeep(fields_changed),
3366
+ null,
3367
+ datasource_changed[0], // refresh the current datasource only
3368
+ );
3369
+ }
4218
3370
  }
4219
3371
  // ///// REFRESH PARAMETERS IN
4220
3372
  // if (fields_changed.length) {
@@ -7642,20 +6794,7 @@ func.events.execute = async function (
7642
6794
  }
7643
6795
 
7644
6796
  const params_obj = await get_params_obj();
7645
- return await func.runtime.ui.init_screen({
7646
- SESSION_ID,
7647
- prog_id: await get_prog_id(),
7648
- sourceScreenP: $(containerP)?.data()?.xuData.screenId,
7649
- callingDataSource_objP: _session.DS_GLB[dsSession],
7650
- $callingContainerP: $calling_container,
7651
- triggerIdP: eventIdP,
7652
- rowIdP: rowP,
7653
- jobNoP,
7654
- is_panelP: is_panel,
7655
- parameters_obj_inP: params_obj,
7656
- source_functionP: functionP,
7657
- call_screen_propertiesP: args.call_screen_propertiesP,
7658
- });
6797
+ return await func.UI.screen.init(SESSION_ID, await get_prog_id(), $(containerP)?.data()?.xuData.screenId, _session.DS_GLB[dsSession], $calling_container, eventIdP, rowP, jobNoP, is_panel, params_obj, functionP, args.call_screen_propertiesP);
7659
6798
  },
7660
6799
  call_modal: async function () {
7661
6800
  return await fx.Call_window();
@@ -8353,19 +7492,7 @@ func.events.execute_PENDING_OPEN_URL_EVENTS = async function () {
8353
7492
  let screen_ret = await func.utils.get_screen_obj(SESSION_ID, params_obj.prog);
8354
7493
 
8355
7494
  if (screen_ret) {
8356
- await func.runtime.ui.init_screen({
8357
- SESSION_ID,
8358
- prog_id: params_obj.prog,
8359
- sourceScreenP: null,
8360
- callingDataSource_objP: null,
8361
- $callingContainerP: $('#embed_' + SESSION_ID),
8362
- triggerIdP: null,
8363
- rowIdP: null,
8364
- jobNoP: null,
8365
- is_panelP: null,
8366
- parameters_obj_inP: null,
8367
- source_functionP: 'pendingUrlEvent_embed',
8368
- });
7495
+ await func.UI.screen.init(SESSION_ID, params_obj.prog, null, null, $('#embed_' + SESSION_ID), null, null, null, null, null, 'pendingUrlEvent_embed');
8369
7496
  } else {
8370
7497
  console.error('Program not exist', params_obj.prog_id);
8371
7498
  func.UI.utils.progressScreen.show(SESSION_ID, 'Program not exist', null, true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-worker-bundle-min",
3
- "version": "1.3.2434",
3
+ "version": "1.3.2435",
4
4
  "description": "xuda framework min",
5
5
  "main": "index.js",
6
6
  "scripts": {