@xuda.io/xuda-worker-bundle-min 1.3.2447 → 1.3.2449

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 +156 -1
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -500,6 +500,13 @@ func.runtime.session.create_state = function (SESSION_ID, options) {
500
500
  func.runtime.workers.ensure_registry(SESSION_ID);
501
501
  return SESSION_OBJ[SESSION_ID];
502
502
  };
503
+ func.runtime.session.is_slim = function (SESSION_ID) {
504
+ const session = typeof SESSION_ID === 'undefined' || SESSION_ID === null ? null : SESSION_OBJ?.[SESSION_ID];
505
+ if (session && typeof session.SLIM_BUNDLE !== 'undefined') {
506
+ return !!session.SLIM_BUNDLE;
507
+ }
508
+ return !!glb.SLIM_BUNDLE;
509
+ };
503
510
  func.runtime.session.set_default_value = function (_session, key, value) {
504
511
  _session[key] = value || func.runtime.env.get_default_session_value(key);
505
512
  return _session[key];
@@ -751,6 +758,135 @@ func.runtime.bind.build_datasource_changes = function (dsSessionP, currentRecord
751
758
  },
752
759
  };
753
760
  };
761
+ func.runtime.bind.get_native_adapter = function () {
762
+ const has_explicit_value = function (elm) {
763
+ return !!elm?.hasAttribute?.('value');
764
+ };
765
+ const get_listener_event = function (elm) {
766
+ const tag_name = elm?.tagName?.toLowerCase?.();
767
+ const type = (elm?.type || '').toLowerCase();
768
+
769
+ if (tag_name === 'select' || ['checkbox', 'radio'].includes(type)) {
770
+ return 'change';
771
+ }
772
+ return 'input';
773
+ };
774
+
775
+ return {
776
+ getter: function (elm) {
777
+ if (!elm) {
778
+ return undefined;
779
+ }
780
+
781
+ const tag_name = elm?.tagName?.toLowerCase?.();
782
+ const type = (elm?.type || '').toLowerCase();
783
+
784
+ if (tag_name === 'select' && elm.multiple) {
785
+ return Array.from(elm.options || [])
786
+ .filter(function (option) {
787
+ return option.selected;
788
+ })
789
+ .map(function (option) {
790
+ return option.value;
791
+ });
792
+ }
793
+
794
+ if (type === 'checkbox') {
795
+ return has_explicit_value(elm) ? elm.value : !!elm.checked;
796
+ }
797
+
798
+ if (type === 'radio') {
799
+ return elm.value;
800
+ }
801
+
802
+ return typeof elm.value !== 'undefined' ? elm.value : undefined;
803
+ },
804
+ setter: function (elm, value) {
805
+ if (!elm) {
806
+ return false;
807
+ }
808
+
809
+ const tag_name = elm?.tagName?.toLowerCase?.();
810
+ const type = (elm?.type || '').toLowerCase();
811
+
812
+ if (tag_name === 'select' && elm.multiple) {
813
+ const selected_values = Array.isArray(value)
814
+ ? value.map(function (item) {
815
+ return String(item);
816
+ })
817
+ : [String(value)];
818
+ Array.from(elm.options || []).forEach(function (option) {
819
+ option.selected = selected_values.includes(String(option.value));
820
+ });
821
+ return true;
822
+ }
823
+
824
+ if (type === 'checkbox' || type === 'radio') {
825
+ return true;
826
+ }
827
+
828
+ if (typeof elm.value !== 'undefined') {
829
+ elm.value = value === null || typeof value === 'undefined' ? '' : String(value);
830
+ }
831
+ return true;
832
+ },
833
+ listener: function (elm, handler) {
834
+ if (!elm?.addEventListener || typeof handler !== 'function') {
835
+ return false;
836
+ }
837
+
838
+ const event_name = get_listener_event(elm);
839
+ const listener_key = '__xuda_native_bind_listener_' + event_name;
840
+ if (elm[listener_key]) {
841
+ elm.removeEventListener(event_name, elm[listener_key]);
842
+ }
843
+ elm.addEventListener(event_name, handler);
844
+ elm[listener_key] = handler;
845
+ return true;
846
+ },
847
+ };
848
+ };
849
+ func.runtime.bind.is_valid_adapter = function (adapter) {
850
+ return !!(
851
+ adapter &&
852
+ typeof adapter.getter === 'function' &&
853
+ typeof adapter.setter === 'function' &&
854
+ typeof adapter.listener === 'function'
855
+ );
856
+ };
857
+ func.runtime.bind.get_adapter = function (SESSION_ID) {
858
+ const native_adapter = func.runtime.bind.get_native_adapter();
859
+ if (func.runtime.session.is_slim(SESSION_ID)) {
860
+ return native_adapter;
861
+ }
862
+
863
+ const plugin_bind = UI_FRAMEWORK_PLUGIN?.bind;
864
+ if (!plugin_bind) {
865
+ return native_adapter;
866
+ }
867
+
868
+ if (func.runtime.bind.is_valid_adapter(plugin_bind)) {
869
+ return plugin_bind;
870
+ }
871
+
872
+ if (typeof plugin_bind === 'function') {
873
+ try {
874
+ const bind_instance = new plugin_bind();
875
+ if (func.runtime.bind.is_valid_adapter(bind_instance)) {
876
+ return bind_instance;
877
+ }
878
+ } catch (error) {}
879
+
880
+ try {
881
+ const bind_factory = plugin_bind();
882
+ if (func.runtime.bind.is_valid_adapter(bind_factory)) {
883
+ return bind_factory;
884
+ }
885
+ } catch (error) {}
886
+ }
887
+
888
+ return native_adapter;
889
+ };
754
890
  func.runtime.bind.resolve_field = async function (SESSION_ID, prog_id, dsSessionP, field_id, iterate_info) {
755
891
  let _prog_id = prog_id;
756
892
  let _dsP = dsSessionP;
@@ -9139,6 +9275,25 @@ func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, row
9139
9275
 
9140
9276
  // var split = [];
9141
9277
  var var_Arr = [];
9278
+ const get_iterate_value_ret = function (fieldIdP) {
9279
+ if (!iterate_info || (iterate_info.iterator_key !== fieldIdP && iterate_info.iterator_val !== fieldIdP)) {
9280
+ return null;
9281
+ }
9282
+
9283
+ const iter_value = iterate_info.iterator_key === fieldIdP ? iterate_info._key : iterate_info._val;
9284
+ const iter_type = typeof iter_value !== 'undefined' ? {}.toString.call(iter_value).match(/\s([a-zA-Z]+)/)[1].toLowerCase() : 'string';
9285
+
9286
+ return {
9287
+ ret: {
9288
+ value: iter_value,
9289
+ type: iter_type,
9290
+ prop: ['array', 'object'].includes(iter_type) ? iter_value : null,
9291
+ },
9292
+ fieldIdP,
9293
+ currentRecordId: rowIdP,
9294
+ found: typeof iter_value !== 'undefined',
9295
+ };
9296
+ };
9142
9297
  const split = func.expression.parse(ret) || [];
9143
9298
  // console.log(valP, split);
9144
9299
  const split_entries = Object.entries(split);
@@ -9235,7 +9390,7 @@ func.expression.get = async function (SESSION_ID, valP, dsSessionP, sourceP, row
9235
9390
  } // put default
9236
9391
  fields[val.fieldId] = var_Arr[key].value;
9237
9392
 
9238
- const ret = await func.datasource.get_value(SESSION_ID, val.fieldId, dsSessionP, rowIdP); // find field in dataSources
9393
+ const ret = get_iterate_value_ret(val.fieldId) || (await func.datasource.get_value(SESSION_ID, val.fieldId, dsSessionP, rowIdP)); // find field in dataSources
9239
9394
 
9240
9395
  await replace_value_in_string(ret.ret, ret.fieldIdP);
9241
9396
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xuda.io/xuda-worker-bundle-min",
3
- "version": "1.3.2447",
3
+ "version": "1.3.2449",
4
4
  "description": "xuda framework min",
5
5
  "main": "index.js",
6
6
  "scripts": {