native-document 1.0.263 → 1.0.265

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "native-document",
3
- "version": "1.0.263",
3
+ "version": "1.0.265",
4
4
  "description": "A reactive JavaScript framework that preserves native DOM simplicity without sacrificing modern features",
5
5
  "author": "AfroCodeur <https://github.com/afrocodeur>",
6
6
  "license": "MIT",
@@ -72,10 +72,12 @@ RadioField.prototype.constructor = RadioField;
72
72
 
73
73
  /**
74
74
  * @param {Array<{ value: *, label: NdChild, props?: GlobalAttributes }>} opts
75
+ * @param {() => ({value: *, label: NdChild, props?: GlobalAttributes})} optionMapper
75
76
  * @returns {this}
76
77
  */
77
- RadioField.prototype.options = function(opts) {
78
+ RadioField.prototype.options = function(opts, optionMapper) {
78
79
  this.$description.options = opts;
80
+ this.$description.optionMapper = optionMapper;
79
81
  return this;
80
82
  };
81
83
 
@@ -37,7 +37,7 @@ export const ObservableObject = function(target, configs = { }) {
37
37
  },
38
38
  set(value) {
39
39
  this.set(value);
40
- }
40
+ },
41
41
  });
42
42
  };
43
43
 
@@ -27,10 +27,18 @@ const I18nService = (function () {
27
27
  }());
28
28
 
29
29
  const tr = (key, params = {}) => {
30
+
30
31
  const isContainObservable = hasObservableParams(params);
31
- const observable = isContainObservable
32
- ? Observable.computed(() => I18nService.tr(key, getParams(params)), getObservableParams(params))
33
- : Observable(I18nService.tr(key, params));
32
+ let observable = null;
33
+ if(key?.__$Observable) {
34
+ observable = isContainObservable
35
+ ? Observable.computed(() => I18nService.tr(key.val(), getParams(params)), [key, ...getObservableParams(params)])
36
+ : Observable.computed(() => I18nService.tr(key.val(), params), [key]);
37
+ } else {
38
+ observable = isContainObservable
39
+ ? Observable.computed(() => I18nService.tr(key, getParams(params)), getObservableParams(params))
40
+ : Observable(I18nService.tr(key, params));
41
+ }
34
42
 
35
43
  i18next.on('languageChanged', (lng) => {
36
44
  const data = isContainObservable ? getParams(params) : params;
@@ -37,7 +37,7 @@ const buildOptions = ($desc, instance) => {
37
37
  if(!$selected?.__$isObservable) {
38
38
  return false;
39
39
  }
40
- return $selected.transform(v => v === optValue);
40
+ return $selected.transform(v => v.valueOf() === optValue?.valueOf());
41
41
  };
42
42
 
43
43
  const onSelect = (optValue) => {
@@ -48,9 +48,11 @@ const buildOptions = ($desc, instance) => {
48
48
  };
49
49
 
50
50
  const buildOption = ($desc, option) => {
51
- const optValue = option.value ?? option;
52
- const optLabel = option.label ?? option;
53
- const optId = ($desc.id || $desc.name) + '-' + optValue;
51
+ const dataSource = $desc.optionMapper ? $desc.optionMapper(option) : option;
52
+ const optValue = dataSource.value ?? option;
53
+ const optLabel = dataSource.label ?? option;
54
+ const optId = ($desc.id || $desc.name).valueOf() + '-' + optValue;
55
+ const $isSelected = isSelected(optValue);
54
56
 
55
57
  const input = Input({
56
58
  class: 'field-radio',
@@ -58,14 +60,14 @@ const buildOptions = ($desc, instance) => {
58
60
  id: optId,
59
61
  name: $desc.name,
60
62
  value: optValue,
61
- checked: isSelected(optValue),
63
+ checked: $isSelected,
62
64
  disabled: $desc.disabled,
63
65
  });
64
66
 
65
67
  input.nd.onChange(() => onSelect(optValue));
66
68
 
67
69
  if($desc.renderItem) {
68
- return Div({class: 'field-radio-wrapper'}, $desc.renderItem(input, option));
70
+ return Div({class: 'field-radio-wrapper'}, $desc.renderItem(input, option, { $isSelected }));
69
71
  }
70
72
 
71
73
  return Div({class: 'field-radio-wrapper'}, [