@nectary/components 5.23.0 → 5.23.1
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/bundle.js +22 -17
- package/input/index.js +22 -17
- package/package.json +1 -1
package/bundle.js
CHANGED
|
@@ -5528,6 +5528,11 @@ class Input extends NectaryElement {
|
|
|
5528
5528
|
#sizeContext;
|
|
5529
5529
|
#maskSymbols = null;
|
|
5530
5530
|
#internals;
|
|
5531
|
+
#lastDispatchedValue = "";
|
|
5532
|
+
#isControlledInput = false;
|
|
5533
|
+
get #previousValue() {
|
|
5534
|
+
return this.#isControlledInput === true && this.hasAttribute("value") === true ? this.getAttribute("value") ?? "" : this.#lastDispatchedValue;
|
|
5535
|
+
}
|
|
5531
5536
|
static formAssociated = true;
|
|
5532
5537
|
constructor() {
|
|
5533
5538
|
super();
|
|
@@ -5552,6 +5557,10 @@ class Input extends NectaryElement {
|
|
|
5552
5557
|
if (this.#controller === null) {
|
|
5553
5558
|
this.#controller = new AbortController();
|
|
5554
5559
|
}
|
|
5560
|
+
this.#isControlledInput = this.hasAttribute("value");
|
|
5561
|
+
if (this.#isControlledInput === false) {
|
|
5562
|
+
this.#lastDispatchedValue = this.#$input.value;
|
|
5563
|
+
}
|
|
5555
5564
|
const options = {
|
|
5556
5565
|
signal: this.#controller.signal
|
|
5557
5566
|
};
|
|
@@ -5593,6 +5602,7 @@ class Input extends NectaryElement {
|
|
|
5593
5602
|
}
|
|
5594
5603
|
formResetCallback() {
|
|
5595
5604
|
this.#$input.value = "";
|
|
5605
|
+
this.#lastDispatchedValue = "";
|
|
5596
5606
|
setFormValue(this.#internals, "");
|
|
5597
5607
|
}
|
|
5598
5608
|
formStateRestoreCallback(state) {
|
|
@@ -5637,11 +5647,7 @@ class Input extends NectaryElement {
|
|
|
5637
5647
|
this.#$input.value = min;
|
|
5638
5648
|
setFormValue(this.#internals, min);
|
|
5639
5649
|
this.#updateAriaValueAttributes();
|
|
5640
|
-
this
|
|
5641
|
-
new CustomEvent("-change", {
|
|
5642
|
-
detail: min
|
|
5643
|
-
})
|
|
5644
|
-
);
|
|
5650
|
+
this.#dispatchChangeEvent(min);
|
|
5645
5651
|
}
|
|
5646
5652
|
}
|
|
5647
5653
|
break;
|
|
@@ -5653,11 +5659,7 @@ class Input extends NectaryElement {
|
|
|
5653
5659
|
this.#$input.value = max;
|
|
5654
5660
|
setFormValue(this.#internals, max);
|
|
5655
5661
|
this.#updateAriaValueAttributes();
|
|
5656
|
-
this
|
|
5657
|
-
new CustomEvent("-change", {
|
|
5658
|
-
detail: max
|
|
5659
|
-
})
|
|
5660
|
-
);
|
|
5662
|
+
this.#dispatchChangeEvent(max);
|
|
5661
5663
|
}
|
|
5662
5664
|
}
|
|
5663
5665
|
}
|
|
@@ -5708,6 +5710,8 @@ class Input extends NectaryElement {
|
|
|
5708
5710
|
case "value": {
|
|
5709
5711
|
const nextVal = newVal ?? "";
|
|
5710
5712
|
const prevVal = this.#$input.value;
|
|
5713
|
+
this.#lastDispatchedValue = nextVal;
|
|
5714
|
+
this.#isControlledInput = newVal !== null;
|
|
5711
5715
|
if (this.#wasClearedByMask) {
|
|
5712
5716
|
this.#wasClearedByMask = false;
|
|
5713
5717
|
if (nextVal.length === 0) {
|
|
@@ -5924,7 +5928,7 @@ class Input extends NectaryElement {
|
|
|
5924
5928
|
this.#dispatchChangeEvent(mergedValue);
|
|
5925
5929
|
}
|
|
5926
5930
|
}
|
|
5927
|
-
if ((res === null || res.mergedValue.length === 0) && this.
|
|
5931
|
+
if ((res === null || res.mergedValue.length === 0) && this.#previousValue.length !== 0) {
|
|
5928
5932
|
this.#dispatchMaskClearChangeEvent();
|
|
5929
5933
|
}
|
|
5930
5934
|
} else {
|
|
@@ -5936,6 +5940,7 @@ class Input extends NectaryElement {
|
|
|
5936
5940
|
e.preventDefault();
|
|
5937
5941
|
};
|
|
5938
5942
|
#handleMaskBeforeInput(inputType, data2) {
|
|
5943
|
+
this.#wasClearedByMask = false;
|
|
5939
5944
|
const selectionStart = this.#$input.selectionStart ?? 0;
|
|
5940
5945
|
const selectionEnd = this.#$input.selectionEnd ?? 0;
|
|
5941
5946
|
let res = null;
|
|
@@ -5970,19 +5975,19 @@ class Input extends NectaryElement {
|
|
|
5970
5975
|
this.#dispatchChangeEvent(mergedValue);
|
|
5971
5976
|
}
|
|
5972
5977
|
}
|
|
5973
|
-
if ((res === null || res.mergedValue.length === 0) && this.
|
|
5978
|
+
if ((res === null || res.mergedValue.length === 0) && this.#previousValue.length !== 0) {
|
|
5974
5979
|
this.#dispatchMaskClearChangeEvent();
|
|
5975
5980
|
}
|
|
5976
5981
|
}
|
|
5977
5982
|
#handleBeforeInput(inputType, data2) {
|
|
5978
5983
|
const selectionStart = this.#$input.selectionStart ?? 0;
|
|
5979
5984
|
const selectionEnd = this.#$input.selectionEnd ?? 0;
|
|
5985
|
+
const value = this.#$input.value;
|
|
5980
5986
|
switch (inputType) {
|
|
5981
5987
|
case "insertFromPaste": {
|
|
5982
5988
|
if (data2 === null) {
|
|
5983
5989
|
return;
|
|
5984
5990
|
}
|
|
5985
|
-
const value = this.value;
|
|
5986
5991
|
const cursorPos = selectionStart + data2.length;
|
|
5987
5992
|
const nextValue = value.substring(0, selectionStart) + data2 + value.substring(selectionEnd);
|
|
5988
5993
|
this.#selectionStart = cursorPos;
|
|
@@ -5991,7 +5996,6 @@ class Input extends NectaryElement {
|
|
|
5991
5996
|
break;
|
|
5992
5997
|
}
|
|
5993
5998
|
case "deleteByCut": {
|
|
5994
|
-
const value = this.value;
|
|
5995
5999
|
const cursorPos = selectionStart;
|
|
5996
6000
|
const nextValue = value.substring(0, selectionStart) + value.substring(selectionEnd);
|
|
5997
6001
|
this.#selectionStart = cursorPos;
|
|
@@ -6009,12 +6013,12 @@ class Input extends NectaryElement {
|
|
|
6009
6013
|
return;
|
|
6010
6014
|
}
|
|
6011
6015
|
const nextValue = this.#$input.value;
|
|
6012
|
-
const prevValue = this
|
|
6016
|
+
const prevValue = this.#previousValue;
|
|
6013
6017
|
setFormValue(this.#internals, nextValue);
|
|
6014
6018
|
if (prevValue !== nextValue) {
|
|
6015
6019
|
const nextSelectionStart = this.#$input.selectionStart;
|
|
6016
6020
|
const nextSelectionEnd = this.#$input.selectionEnd;
|
|
6017
|
-
if (this.hasAttribute("value") === true) {
|
|
6021
|
+
if (this.#isControlledInput === true && this.hasAttribute("value") === true) {
|
|
6018
6022
|
this.#$input.value = prevValue;
|
|
6019
6023
|
this.#setSelectionRange(this.#selectionStart, this.#selectionEnd);
|
|
6020
6024
|
}
|
|
@@ -6143,9 +6147,10 @@ class Input extends NectaryElement {
|
|
|
6143
6147
|
this.#dispatchChangeEvent("");
|
|
6144
6148
|
}
|
|
6145
6149
|
#dispatchChangeEvent(value) {
|
|
6146
|
-
if (value === this
|
|
6150
|
+
if (value === this.#previousValue) {
|
|
6147
6151
|
return;
|
|
6148
6152
|
}
|
|
6153
|
+
this.#lastDispatchedValue = value;
|
|
6149
6154
|
this.dispatchEvent(
|
|
6150
6155
|
new CustomEvent("-change", {
|
|
6151
6156
|
detail: value
|
package/input/index.js
CHANGED
|
@@ -28,6 +28,11 @@ class Input extends NectaryElement {
|
|
|
28
28
|
#sizeContext;
|
|
29
29
|
#maskSymbols = null;
|
|
30
30
|
#internals;
|
|
31
|
+
#lastDispatchedValue = "";
|
|
32
|
+
#isControlledInput = false;
|
|
33
|
+
get #previousValue() {
|
|
34
|
+
return this.#isControlledInput === true && this.hasAttribute("value") === true ? this.getAttribute("value") ?? "" : this.#lastDispatchedValue;
|
|
35
|
+
}
|
|
31
36
|
static formAssociated = true;
|
|
32
37
|
constructor() {
|
|
33
38
|
super();
|
|
@@ -52,6 +57,10 @@ class Input extends NectaryElement {
|
|
|
52
57
|
if (this.#controller === null) {
|
|
53
58
|
this.#controller = new AbortController();
|
|
54
59
|
}
|
|
60
|
+
this.#isControlledInput = this.hasAttribute("value");
|
|
61
|
+
if (this.#isControlledInput === false) {
|
|
62
|
+
this.#lastDispatchedValue = this.#$input.value;
|
|
63
|
+
}
|
|
55
64
|
const options = {
|
|
56
65
|
signal: this.#controller.signal
|
|
57
66
|
};
|
|
@@ -93,6 +102,7 @@ class Input extends NectaryElement {
|
|
|
93
102
|
}
|
|
94
103
|
formResetCallback() {
|
|
95
104
|
this.#$input.value = "";
|
|
105
|
+
this.#lastDispatchedValue = "";
|
|
96
106
|
setFormValue(this.#internals, "");
|
|
97
107
|
}
|
|
98
108
|
formStateRestoreCallback(state) {
|
|
@@ -137,11 +147,7 @@ class Input extends NectaryElement {
|
|
|
137
147
|
this.#$input.value = min;
|
|
138
148
|
setFormValue(this.#internals, min);
|
|
139
149
|
this.#updateAriaValueAttributes();
|
|
140
|
-
this
|
|
141
|
-
new CustomEvent("-change", {
|
|
142
|
-
detail: min
|
|
143
|
-
})
|
|
144
|
-
);
|
|
150
|
+
this.#dispatchChangeEvent(min);
|
|
145
151
|
}
|
|
146
152
|
}
|
|
147
153
|
break;
|
|
@@ -153,11 +159,7 @@ class Input extends NectaryElement {
|
|
|
153
159
|
this.#$input.value = max;
|
|
154
160
|
setFormValue(this.#internals, max);
|
|
155
161
|
this.#updateAriaValueAttributes();
|
|
156
|
-
this
|
|
157
|
-
new CustomEvent("-change", {
|
|
158
|
-
detail: max
|
|
159
|
-
})
|
|
160
|
-
);
|
|
162
|
+
this.#dispatchChangeEvent(max);
|
|
161
163
|
}
|
|
162
164
|
}
|
|
163
165
|
}
|
|
@@ -208,6 +210,8 @@ class Input extends NectaryElement {
|
|
|
208
210
|
case "value": {
|
|
209
211
|
const nextVal = newVal ?? "";
|
|
210
212
|
const prevVal = this.#$input.value;
|
|
213
|
+
this.#lastDispatchedValue = nextVal;
|
|
214
|
+
this.#isControlledInput = newVal !== null;
|
|
211
215
|
if (this.#wasClearedByMask) {
|
|
212
216
|
this.#wasClearedByMask = false;
|
|
213
217
|
if (nextVal.length === 0) {
|
|
@@ -424,7 +428,7 @@ class Input extends NectaryElement {
|
|
|
424
428
|
this.#dispatchChangeEvent(mergedValue);
|
|
425
429
|
}
|
|
426
430
|
}
|
|
427
|
-
if ((res === null || res.mergedValue.length === 0) && this.
|
|
431
|
+
if ((res === null || res.mergedValue.length === 0) && this.#previousValue.length !== 0) {
|
|
428
432
|
this.#dispatchMaskClearChangeEvent();
|
|
429
433
|
}
|
|
430
434
|
} else {
|
|
@@ -436,6 +440,7 @@ class Input extends NectaryElement {
|
|
|
436
440
|
e.preventDefault();
|
|
437
441
|
};
|
|
438
442
|
#handleMaskBeforeInput(inputType, data) {
|
|
443
|
+
this.#wasClearedByMask = false;
|
|
439
444
|
const selectionStart = this.#$input.selectionStart ?? 0;
|
|
440
445
|
const selectionEnd = this.#$input.selectionEnd ?? 0;
|
|
441
446
|
let res = null;
|
|
@@ -470,19 +475,19 @@ class Input extends NectaryElement {
|
|
|
470
475
|
this.#dispatchChangeEvent(mergedValue);
|
|
471
476
|
}
|
|
472
477
|
}
|
|
473
|
-
if ((res === null || res.mergedValue.length === 0) && this.
|
|
478
|
+
if ((res === null || res.mergedValue.length === 0) && this.#previousValue.length !== 0) {
|
|
474
479
|
this.#dispatchMaskClearChangeEvent();
|
|
475
480
|
}
|
|
476
481
|
}
|
|
477
482
|
#handleBeforeInput(inputType, data) {
|
|
478
483
|
const selectionStart = this.#$input.selectionStart ?? 0;
|
|
479
484
|
const selectionEnd = this.#$input.selectionEnd ?? 0;
|
|
485
|
+
const value = this.#$input.value;
|
|
480
486
|
switch (inputType) {
|
|
481
487
|
case "insertFromPaste": {
|
|
482
488
|
if (data === null) {
|
|
483
489
|
return;
|
|
484
490
|
}
|
|
485
|
-
const value = this.value;
|
|
486
491
|
const cursorPos = selectionStart + data.length;
|
|
487
492
|
const nextValue = value.substring(0, selectionStart) + data + value.substring(selectionEnd);
|
|
488
493
|
this.#selectionStart = cursorPos;
|
|
@@ -491,7 +496,6 @@ class Input extends NectaryElement {
|
|
|
491
496
|
break;
|
|
492
497
|
}
|
|
493
498
|
case "deleteByCut": {
|
|
494
|
-
const value = this.value;
|
|
495
499
|
const cursorPos = selectionStart;
|
|
496
500
|
const nextValue = value.substring(0, selectionStart) + value.substring(selectionEnd);
|
|
497
501
|
this.#selectionStart = cursorPos;
|
|
@@ -509,12 +513,12 @@ class Input extends NectaryElement {
|
|
|
509
513
|
return;
|
|
510
514
|
}
|
|
511
515
|
const nextValue = this.#$input.value;
|
|
512
|
-
const prevValue = this
|
|
516
|
+
const prevValue = this.#previousValue;
|
|
513
517
|
setFormValue(this.#internals, nextValue);
|
|
514
518
|
if (prevValue !== nextValue) {
|
|
515
519
|
const nextSelectionStart = this.#$input.selectionStart;
|
|
516
520
|
const nextSelectionEnd = this.#$input.selectionEnd;
|
|
517
|
-
if (this.hasAttribute("value") === true) {
|
|
521
|
+
if (this.#isControlledInput === true && this.hasAttribute("value") === true) {
|
|
518
522
|
this.#$input.value = prevValue;
|
|
519
523
|
this.#setSelectionRange(this.#selectionStart, this.#selectionEnd);
|
|
520
524
|
}
|
|
@@ -643,9 +647,10 @@ class Input extends NectaryElement {
|
|
|
643
647
|
this.#dispatchChangeEvent("");
|
|
644
648
|
}
|
|
645
649
|
#dispatchChangeEvent(value) {
|
|
646
|
-
if (value === this
|
|
650
|
+
if (value === this.#previousValue) {
|
|
647
651
|
return;
|
|
648
652
|
}
|
|
653
|
+
this.#lastDispatchedValue = value;
|
|
649
654
|
this.dispatchEvent(
|
|
650
655
|
new CustomEvent("-change", {
|
|
651
656
|
detail: value
|