@xuda.io/xuda-worker-bundle-min 1.3.2432 → 1.3.2433
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.
- package/index.js +480 -124
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -11,9 +11,14 @@ func.UI = {};
|
|
|
11
11
|
func.GLB = {};
|
|
12
12
|
func.mobile = {};
|
|
13
13
|
func.runtime = {};
|
|
14
|
+
func.runtime.bind = {};
|
|
15
|
+
func.runtime.program = {};
|
|
16
|
+
func.runtime.resources = {};
|
|
17
|
+
func.runtime.render = {};
|
|
14
18
|
func.runtime.session = {};
|
|
15
19
|
func.runtime.workers = {};
|
|
16
20
|
func.runtime.ui = {};
|
|
21
|
+
func.runtime.widgets = {};
|
|
17
22
|
glb.IS_STUDIO = null;
|
|
18
23
|
|
|
19
24
|
var PROJECT_OBJ = {};
|
|
@@ -429,134 +434,452 @@ func.runtime.workers.delete_promise = function (SESSION_ID, worker_id, promise_q
|
|
|
429
434
|
delete registry_entry.promise_queue[promise_queue_id];
|
|
430
435
|
return true;
|
|
431
436
|
};
|
|
432
|
-
func.runtime.
|
|
433
|
-
return
|
|
434
|
-
};
|
|
435
|
-
func.runtime.
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
func.runtime.ui.ensure_app_shell = function (SESSION_ID, domain) {
|
|
441
|
-
const $root_element = func.runtime.ui.get_root_element(SESSION_ID);
|
|
442
|
-
$root_element.css('position', 'relative');
|
|
443
|
-
|
|
444
|
-
if (!$root_element.find('.loader').length) {
|
|
445
|
-
$root_element.append(`
|
|
446
|
-
|
|
447
|
-
<style>
|
|
448
|
-
.loader {
|
|
449
|
-
position: absolute;
|
|
450
|
-
background: rgb(0 0 0 / 30%);
|
|
451
|
-
z-index: 10;
|
|
452
|
-
overflow-y: auto;
|
|
453
|
-
top: 0;
|
|
454
|
-
right: 0;
|
|
455
|
-
bottom: 0;
|
|
456
|
-
left: 0;
|
|
457
|
-
display: flex;
|
|
458
|
-
flex-direction: column;
|
|
459
|
-
justify-content: center;
|
|
460
|
-
align-items: center;
|
|
461
|
-
}
|
|
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);
|
|
462
445
|
|
|
463
|
-
|
|
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
|
+
}
|
|
464
457
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
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
|
+
}
|
|
470
468
|
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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}`];
|
|
491
548
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
</div>
|
|
498
|
-
<div class="loader_msg"> </div>
|
|
499
|
-
</div>
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
<div class="progressLoader"></div>
|
|
503
|
-
|
|
504
|
-
`);
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
if (!$root_element.find('#tailwind_toast_controller').length) {
|
|
508
|
-
$root_element.append(
|
|
509
|
-
`<div aria-live="assertive"
|
|
510
|
-
class="fixed inset-0 flex items-end px-4 py-6 pointer-events-none sm:p-6 sm:items-start z-[999]">
|
|
511
|
-
<div id="tailwind_toast_controller" class="w-full flex flex-col items-center space-y-4 sm:items-end">
|
|
512
|
-
|
|
513
|
-
</div>
|
|
514
|
-
</div>`,
|
|
515
|
-
);
|
|
549
|
+
}
|
|
550
|
+
continue;
|
|
551
|
+
}
|
|
552
|
+
console.warn(`Warning: Program ${_prog.properties.menuName} expected In parameter: ${val.data.parameter} but received null instead`);
|
|
553
|
+
}
|
|
516
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;
|
|
517
571
|
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
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`;
|
|
525
598
|
}
|
|
526
599
|
|
|
527
|
-
|
|
528
|
-
|
|
600
|
+
return {
|
|
601
|
+
bind_field_id: field_id,
|
|
602
|
+
field_prop,
|
|
603
|
+
is_dynamic_field,
|
|
604
|
+
dsSessionP: _dsP,
|
|
605
|
+
prog_id: _prog_id,
|
|
529
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');
|
|
530
636
|
|
|
531
|
-
|
|
532
|
-
|
|
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;
|
|
533
651
|
};
|
|
534
|
-
func.runtime.
|
|
535
|
-
const
|
|
536
|
-
|
|
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);
|
|
537
662
|
|
|
538
|
-
if (
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
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;
|
|
544
670
|
}
|
|
545
671
|
|
|
546
|
-
|
|
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;
|
|
547
675
|
};
|
|
548
|
-
func.runtime.
|
|
549
|
-
|
|
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
|
+
});
|
|
550
707
|
};
|
|
551
|
-
func.runtime.
|
|
552
|
-
return
|
|
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;
|
|
553
710
|
};
|
|
554
|
-
func.runtime.
|
|
555
|
-
|
|
556
|
-
return $
|
|
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}`;
|
|
557
714
|
};
|
|
558
|
-
func.runtime.
|
|
559
|
-
return func.
|
|
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
|
+
};
|
|
560
883
|
};
|
|
561
884
|
func.common.find_item_by_key = function (arr, key, val) {
|
|
562
885
|
return _.find(arr, function (e) {
|
|
@@ -3761,13 +4084,13 @@ func.datasource.update = async function (SESSION_ID, datasource_changes, update_
|
|
|
3761
4084
|
});
|
|
3762
4085
|
}
|
|
3763
4086
|
|
|
3764
|
-
await func.
|
|
4087
|
+
await func.runtime.ui.refresh_screen({
|
|
3765
4088
|
SESSION_ID,
|
|
3766
|
-
klona.klona(fields_changed),
|
|
3767
|
-
datasource_changed[0],
|
|
3768
|
-
datasource_changed[0],
|
|
3769
|
-
value,
|
|
3770
|
-
);
|
|
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
|
+
});
|
|
3771
4094
|
}
|
|
3772
4095
|
|
|
3773
4096
|
continue;
|
|
@@ -3876,14 +4199,22 @@ func.datasource.update = async function (SESSION_ID, datasource_changes, update_
|
|
|
3876
4199
|
}
|
|
3877
4200
|
|
|
3878
4201
|
// await func.UI.screen.refresh_xu_attributes(SESSION_ID, _.cloneDeep(fields_changed), null, null, findMin(datasource_changed), avoid_xu_for_refresh, trigger);
|
|
3879
|
-
await func.
|
|
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
|
+
});
|
|
3880
4211
|
// await removed from the below function cause to dead lock Mar 3 25
|
|
3881
|
-
await func.
|
|
4212
|
+
await func.runtime.ui.refresh_screen({
|
|
3882
4213
|
SESSION_ID,
|
|
3883
|
-
klona.klona(fields_changed),
|
|
3884
|
-
null,
|
|
3885
|
-
datasource_changed[0],
|
|
3886
|
-
);
|
|
4214
|
+
fields_changed_arr: klona.klona(fields_changed),
|
|
4215
|
+
datasource_changed: null,
|
|
4216
|
+
fields_changed_datasource: datasource_changed[0],
|
|
4217
|
+
});
|
|
3887
4218
|
}
|
|
3888
4219
|
// ///// REFRESH PARAMETERS IN
|
|
3889
4220
|
// if (fields_changed.length) {
|
|
@@ -7311,7 +7642,20 @@ func.events.execute = async function (
|
|
|
7311
7642
|
}
|
|
7312
7643
|
|
|
7313
7644
|
const params_obj = await get_params_obj();
|
|
7314
|
-
return await func.
|
|
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
|
+
});
|
|
7315
7659
|
},
|
|
7316
7660
|
call_modal: async function () {
|
|
7317
7661
|
return await fx.Call_window();
|
|
@@ -8009,7 +8353,19 @@ func.events.execute_PENDING_OPEN_URL_EVENTS = async function () {
|
|
|
8009
8353
|
let screen_ret = await func.utils.get_screen_obj(SESSION_ID, params_obj.prog);
|
|
8010
8354
|
|
|
8011
8355
|
if (screen_ret) {
|
|
8012
|
-
await func.
|
|
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
|
+
});
|
|
8013
8369
|
} else {
|
|
8014
8370
|
console.error('Program not exist', params_obj.prog_id);
|
|
8015
8371
|
func.UI.utils.progressScreen.show(SESSION_ID, 'Program not exist', null, true);
|