@eturnity/eturnity_reusable_components 8.19.8-EPDM-14766.0 → 8.19.8-EPDM-6306.3
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
@@ -61,7 +61,7 @@
|
|
61
61
|
:show-linear-unit-name="showLinearUnitName"
|
62
62
|
:slot-size="slotSize"
|
63
63
|
:text-align="textAlign"
|
64
|
-
:value="
|
64
|
+
:value="formattedValue"
|
65
65
|
@blur="onInputBlur($event)"
|
66
66
|
@focus="focusInput()"
|
67
67
|
@input="onInput($event)"
|
@@ -75,7 +75,7 @@
|
|
75
75
|
|
76
76
|
<UnitContainer
|
77
77
|
v-if="unitName && showLinearUnitName && !hasSlot"
|
78
|
-
:has-length="
|
78
|
+
:has-length="hasLength"
|
79
79
|
:is-error="isError"
|
80
80
|
>{{ unitName }}</UnitContainer
|
81
81
|
>
|
@@ -92,7 +92,7 @@
|
|
92
92
|
:disabled="isSelectDisabled"
|
93
93
|
:select-width="`${selectWidth}px`"
|
94
94
|
:show-border="false"
|
95
|
-
@input-change="
|
95
|
+
@input-change="handleSelectChange"
|
96
96
|
>
|
97
97
|
<template #selector>
|
98
98
|
<SelectText>{{ getSelectValue }}</SelectText>
|
@@ -457,8 +457,18 @@
|
|
457
457
|
background-color: ${({ theme }) => theme.colors.grey4};
|
458
458
|
`
|
459
459
|
|
460
|
+
const EVENT_TYPES = {
|
461
|
+
INPUT_FOCUS: 'input-focus',
|
462
|
+
INPUT_CHANGE: 'input-change',
|
463
|
+
INPUT_BLUR: 'input-blur',
|
464
|
+
PRESS_ENTER: 'on-enter-click',
|
465
|
+
INPUT_DRAG: 'on-input-drag',
|
466
|
+
SELECT_CHANGE: 'select-change',
|
467
|
+
}
|
468
|
+
|
460
469
|
export default {
|
461
470
|
name: 'InputNumber',
|
471
|
+
emits: [...Object.values(EVENT_TYPES)],
|
462
472
|
components: {
|
463
473
|
Container,
|
464
474
|
InputContainer,
|
@@ -702,9 +712,10 @@
|
|
702
712
|
},
|
703
713
|
data() {
|
704
714
|
return {
|
705
|
-
textInput: '',
|
706
715
|
isFocused: false,
|
707
716
|
warningIcon: warningIcon,
|
717
|
+
inputValue: null,
|
718
|
+
enteredValue: null,
|
708
719
|
}
|
709
720
|
},
|
710
721
|
computed: {
|
@@ -727,6 +738,14 @@
|
|
727
738
|
|
728
739
|
return item ? item.label : '-'
|
729
740
|
},
|
741
|
+
formattedValue() {
|
742
|
+
return this.isFocused
|
743
|
+
? this.enteredValue
|
744
|
+
: this.formatWithCurrency(this.value)
|
745
|
+
},
|
746
|
+
hasLength() {
|
747
|
+
return this.formattedValue !== null && this.formattedValue.length > 0
|
748
|
+
},
|
730
749
|
},
|
731
750
|
watch: {
|
732
751
|
focus(value) {
|
@@ -737,30 +756,22 @@
|
|
737
756
|
clearInput: function (value) {
|
738
757
|
if (value) {
|
739
758
|
// If the value is typed, then we should clear the textInput on Continue
|
740
|
-
this.
|
759
|
+
this.inputValue = ''
|
760
|
+
this.enteredValue = ''
|
741
761
|
}
|
742
762
|
},
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
minDecimals: this.minDecimals,
|
756
|
-
})
|
757
|
-
} else if (this.minNumber !== null) {
|
758
|
-
this.textInput = numberToString({
|
759
|
-
value: this.minNumber,
|
760
|
-
numberPrecision: this.numberPrecision,
|
761
|
-
minDecimals: this.minDecimals,
|
762
|
-
})
|
763
|
-
}
|
763
|
+
value: {
|
764
|
+
immediate: true,
|
765
|
+
handler(val) {
|
766
|
+
if (this.value !== this.inputValue && !Number.isNaN(this.value)) {
|
767
|
+
this.inputValue = this.value
|
768
|
+
this.enteredValue =
|
769
|
+
typeof this.value === 'number' && !isNaN(this.value)
|
770
|
+
? Number(this.value.toFixed(this.numberPrecision))
|
771
|
+
: this.value
|
772
|
+
}
|
773
|
+
},
|
774
|
+
},
|
764
775
|
},
|
765
776
|
mounted() {
|
766
777
|
if (this.focus) {
|
@@ -799,32 +810,31 @@
|
|
799
810
|
}
|
800
811
|
},
|
801
812
|
onEnterPress() {
|
802
|
-
this.$emit(
|
813
|
+
this.$emit(EVENT_TYPES.PRESS_ENTER)
|
803
814
|
this.$refs.inputField1.$el.blur()
|
804
815
|
},
|
805
|
-
onChangeHandler(
|
806
|
-
if (isNaN(
|
807
|
-
|
816
|
+
onChangeHandler(value) {
|
817
|
+
if (isNaN(value) || value === '') {
|
818
|
+
value = this.defaultNumber
|
808
819
|
? this.defaultNumber
|
809
820
|
: this.minNumber || this.minNumber === 0
|
810
821
|
? this.minNumber
|
811
|
-
:
|
822
|
+
: value
|
812
823
|
}
|
813
824
|
if (!this.allowNegative) {
|
814
|
-
|
825
|
+
value = Math.abs(value)
|
815
826
|
}
|
816
|
-
if (this.minNumber && this.minNumber >
|
817
|
-
|
827
|
+
if (this.minNumber && this.minNumber > value) {
|
828
|
+
value = this.minNumber
|
818
829
|
}
|
819
|
-
event = parseFloat(event)
|
820
830
|
// Need to return an integer rather than a string
|
821
|
-
|
831
|
+
value = parseFloat(value)
|
832
|
+
return value
|
822
833
|
},
|
823
|
-
onEvaluateCode(
|
834
|
+
onEvaluateCode(value) {
|
824
835
|
// function to perform math on the code
|
825
836
|
// filter the string in case of any malicious content
|
826
|
-
|
827
|
-
let filtered = val.replace('(auto)', '').replace(/[^-()\d/*+.,]/g, '')
|
837
|
+
let filtered = value.replace('(auto)', '').replace(/[^-()\d/*+.,]/g, '')
|
828
838
|
filtered = filtered.split(/([-+*/()])/)
|
829
839
|
let formatted = filtered.map((item) => {
|
830
840
|
if (
|
@@ -882,59 +892,42 @@
|
|
882
892
|
return array
|
883
893
|
},
|
884
894
|
onInput(event) {
|
885
|
-
|
895
|
+
console.log('onInput', event.target.value)
|
896
|
+
this.enteredValue = event.target.value
|
897
|
+
if (!this.isFocused || this.enteredValue === this.inputValue) {
|
886
898
|
return
|
887
899
|
}
|
888
|
-
if (event.target.value === '') {
|
889
|
-
this.$emit('on-input', '')
|
890
|
-
}
|
891
900
|
let evaluatedVal
|
892
901
|
try {
|
893
|
-
evaluatedVal = this.onEvaluateCode(
|
902
|
+
evaluatedVal = this.onEvaluateCode(String(this.enteredValue))
|
894
903
|
} finally {
|
895
|
-
|
896
|
-
|
904
|
+
this.inputValue = this.onChangeHandler(evaluatedVal)
|
905
|
+
|
906
|
+
if (this.isFocused && typeof this.enteredValue !== 'number') {
|
907
|
+
this.$emit(EVENT_TYPES.INPUT_CHANGE, this.inputValue)
|
897
908
|
}
|
898
909
|
}
|
899
910
|
this.textInput = evaluatedVal
|
900
911
|
},
|
901
912
|
onInputBlur(e) {
|
902
913
|
this.isFocused = false
|
903
|
-
|
904
|
-
|
905
|
-
this.onChangeHandler(evaluatedInput ? evaluatedInput : value)
|
906
|
-
if ((evaluatedInput && value.length) || this.minNumber !== null) {
|
907
|
-
this.textInput = numberToString({
|
908
|
-
value:
|
909
|
-
evaluatedInput && value.length
|
910
|
-
? evaluatedInput
|
911
|
-
: this.defaultNumber
|
912
|
-
? this.defaultNumber
|
913
|
-
: this.minNumber,
|
914
|
-
numberPrecision: this.numberPrecision,
|
915
|
-
minDecimals: this.minDecimals,
|
916
|
-
})
|
914
|
+
if (!Number.isNaN(this.inputValue)) {
|
915
|
+
this.enteredValue = this.inputValue
|
917
916
|
}
|
918
|
-
|
919
|
-
|
920
|
-
|
921
|
-
|
922
|
-
? this.defaultNumber
|
923
|
-
: this.minNumber || this.minNumber === 0
|
924
|
-
? this.minNumber
|
925
|
-
: ''
|
926
|
-
this.$emit('input-blur', adjustedMinValue)
|
917
|
+
this.$emit(
|
918
|
+
EVENT_TYPES.INPUT_BLUR,
|
919
|
+
Number(this.onEvaluateCode(String(this.inputValue)))
|
920
|
+
)
|
927
921
|
},
|
928
922
|
focusInput() {
|
929
923
|
if (this.disabled) {
|
930
924
|
return
|
931
925
|
}
|
932
926
|
this.isFocused = true
|
933
|
-
this.textInput = this.formatWithCurrency(this.value)
|
934
927
|
this.$nextTick(() => {
|
935
928
|
this.$refs.inputField1.$el.select()
|
936
929
|
})
|
937
|
-
this.$emit(
|
930
|
+
this.$emit(EVENT_TYPES.INPUT_FOCUS, this.inputValue)
|
938
931
|
},
|
939
932
|
blurInput() {
|
940
933
|
if (this.disabled) {
|
@@ -954,7 +947,7 @@
|
|
954
947
|
: this.minNumber || this.minNumber === 0
|
955
948
|
? this.minNumber
|
956
949
|
: ''
|
957
|
-
if (
|
950
|
+
if (adjustedMinValue || adjustedMinValue === 0) {
|
958
951
|
let input = this.numberToStringEnabled
|
959
952
|
? numberToString({
|
960
953
|
value: adjustedMinValue,
|
@@ -967,6 +960,8 @@
|
|
967
960
|
return input + ' ' + unit
|
968
961
|
} else if (!adjustedMinValue && adjustedMinValue !== 0) {
|
969
962
|
return ''
|
963
|
+
} else if (this.isFocused) {
|
964
|
+
return value
|
970
965
|
} else {
|
971
966
|
return this.numberToStringEnabled
|
972
967
|
? numberToString({
|
@@ -987,14 +982,7 @@
|
|
987
982
|
e.preventDefault()
|
988
983
|
let value = parseFloat(this.value || 0)
|
989
984
|
value += parseFloat(this.interactionStep) * parseInt(e.movementX)
|
990
|
-
this.$emit(
|
991
|
-
|
992
|
-
this.textInput = numberToString({
|
993
|
-
value: value && value.length ? value : this.minNumber,
|
994
|
-
numberPrecision: this.numberPrecision,
|
995
|
-
minDecimals: this.minDecimals,
|
996
|
-
})
|
997
|
-
//this.value=value
|
985
|
+
this.$emit(EVENT_TYPES.INPUT_DRAG, this.onChangeHandler(value))
|
998
986
|
},
|
999
987
|
stopInteract(e) {
|
1000
988
|
e.preventDefault()
|
@@ -1002,6 +990,9 @@
|
|
1002
990
|
window.removeEventListener('mouseup', this.stopInteract, false)
|
1003
991
|
this.blurInput()
|
1004
992
|
},
|
993
|
+
handleSelectChange(value) {
|
994
|
+
this.$emit(EVENT_TYPES.SELECT_CHANGE, value)
|
995
|
+
},
|
1005
996
|
},
|
1006
997
|
}
|
1007
998
|
</script>
|
@@ -94,7 +94,7 @@ export const stringToNumber = ({
|
|
94
94
|
|
95
95
|
export const numberToString = ({ value, numberPrecision, minDecimals }) => {
|
96
96
|
const minimumRounding = minDecimals ? minDecimals : 0
|
97
|
-
value = parseFloat(value)
|
97
|
+
value = !Number.isNaN(parseFloat(value)) ? parseFloat(value) : 0
|
98
98
|
return value.toLocaleString(langForLocaleString(), {
|
99
99
|
minimumFractionDigits: minimumRounding, // removing this for now. Why do we need this to be a minimum amount?
|
100
100
|
maximumFractionDigits:
|