native-document 1.0.295 → 1.0.296

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.295",
3
+ "version": "1.0.296",
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",
@@ -301,6 +301,10 @@ ObservableItem.prototype.toBoolean = function () {
301
301
  return $checker(this, x => !!x);
302
302
  };
303
303
 
304
+ ObservableItem.prototype.toNumber = function () {
305
+ return $checker(this, Number);
306
+ };
307
+
304
308
  /**
305
309
  * Returns a derived observable that emits a string with the placeholder replaced by the current value.
306
310
  * Alias: toFormatted
@@ -64,7 +64,7 @@ ObservableItem.prototype.is = function(callbackOrValue) {
64
64
  if(typeof callbackOrValue === 'function') {
65
65
  return new ObservableChecker(this, callbackOrValue);
66
66
  }
67
- return new ObservableChecker(this, (value) => value === callbackOrValue);
67
+ return this.isEqualTo(callbackOrValue);
68
68
  };
69
69
  ObservableItem.prototype.select = ObservableItem.prototype.check;
70
70
 
@@ -25,15 +25,35 @@ export default function ListItemRender($desc, instance) {
25
25
 
26
26
  const $list = instance.$parent;
27
27
 
28
- // Checkbox — réactif via ShowIf
29
28
  const selectedValues = $list.$description.selectedValues;
30
29
  const value = $desc.value ?? instance;
31
30
  const isChecked = selectedValues ? selectedValues.isIncludes(value) : null;
32
31
 
32
+
33
33
  if($list.$description?.selectable || $desc.selected) {
34
34
  const selectedSource = $desc.selected ?? isChecked;
35
35
  props.class.add('is-selected', selectedSource);
36
36
  props['aria-selected'] = selectedSource;
37
+
38
+ if(selectedSource.__$Observable) {
39
+ selectedSource.subscribe((isSelected) => {
40
+ const $values = $list.$description.selectedValues;
41
+ if (!$values) return;
42
+ const value = $desc.value ?? instance;
43
+
44
+ if(isSelected) {
45
+ if(!$values.includes(value)) {
46
+ if (!$list.$description.multiSelect.val()) {
47
+ $values.clear();
48
+ }
49
+ $values.push(value);
50
+ }
51
+ } else {
52
+ $values.removeItem(value);
53
+ }
54
+ });
55
+ }
56
+
37
57
  }
38
58
 
39
59
  if ($list?.$description?.selectByCheckbox) {
@@ -48,26 +68,21 @@ export default function ListItemRender($desc, instance) {
48
68
  );
49
69
  }
50
70
 
71
+
72
+
51
73
  if ($desc.icon) {
52
74
  frontContent.push(Span({ class: 'list-item-icon' }, $desc.icon));
53
75
  }
54
76
 
55
77
  frontContent.push(buildBody($desc));
56
78
 
57
- // Select indicator — réactif via isIncludes
58
79
  if ($list?.$description?.selectByClick) {
59
- const selectedValues = $list.$description.selectedValues;
60
- const value = $desc.value ?? instance;
61
- const isSelected = selectedValues ? selectedValues.isIncludes(value) : null;
62
-
63
- if (isSelected) {
64
- frontContent.push(
65
- Span({
66
- class: isSelected.transform((s) => 'list-item-indicator' + (s ? ' is-visible' : '')),
67
- 'aria-hidden': 'true',
68
- }, $desc.isSelectedIcon)
69
- );
70
- }
80
+ frontContent.push(
81
+ Span({
82
+ class: isChecked.transform((s) => 'list-item-indicator' + (s ? ' is-visible' : '')),
83
+ 'aria-hidden': 'true',
84
+ }, $desc.isSelectedIcon)
85
+ );
71
86
  }
72
87
 
73
88
  if ($desc.trailing) {
@@ -138,6 +138,7 @@ export interface ObservableItem<T = any> {
138
138
  toTrimmed(): ObservableChecker<string>;
139
139
  toBoolean(): ObservableChecker<boolean>;
140
140
  toLiteral(template: string, placeholder?: string): ObservableChecker<string>;
141
+ toNumber(): ObservableChecker<number>;
141
142
  toFormatted(template: string, placeholder?: string): ObservableChecker<string>;
142
143
  toProperty<U = any>(path: string): ObservableChecker<U>;
143
144
  toLength(): ObservableChecker<number>;