@rypen-dev/shared-components 8.0.13 → 8.0.14
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/dist/index.js +379 -376
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/components/NumberInput.vue +19 -3
- package/src/components/TimespanInput.vue +21 -16
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rypen-dev/shared-components",
|
|
3
3
|
"description": "Shared styles and Vuejs ui components for Rypen projects. Starting with version 8, this package is built with Vite 7 and Vue 3.",
|
|
4
|
-
"version": "8.0.
|
|
4
|
+
"version": "8.0.14",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -6,9 +6,7 @@
|
|
|
6
6
|
:pattern="pattern"
|
|
7
7
|
inputmode="numeric"
|
|
8
8
|
ref="inputref"
|
|
9
|
-
@keydown
|
|
10
|
-
@keydown.down.prevent="decrement"
|
|
11
|
-
@keydown.enter="change"
|
|
9
|
+
@keydown="checkKey"
|
|
12
10
|
@input="updateValue"
|
|
13
11
|
@blur="change"
|
|
14
12
|
@focus="focus"
|
|
@@ -46,6 +44,10 @@
|
|
|
46
44
|
type: Boolean,
|
|
47
45
|
default: false,
|
|
48
46
|
},
|
|
47
|
+
enforceNumbersOnly: {
|
|
48
|
+
type: Boolean,
|
|
49
|
+
default: true,
|
|
50
|
+
},
|
|
49
51
|
emitOnInput: {
|
|
50
52
|
type: Boolean,
|
|
51
53
|
default: false,
|
|
@@ -85,6 +87,20 @@
|
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
89
|
|
|
90
|
+
function checkKey(e) {
|
|
91
|
+
const { key } = e;
|
|
92
|
+
|
|
93
|
+
if (key === 'ArrowUp') {
|
|
94
|
+
increment();
|
|
95
|
+
} else if (key === 'ArrowDown') {
|
|
96
|
+
decrement();
|
|
97
|
+
} else if (key === 'Enter') {
|
|
98
|
+
inputref.value.blur();
|
|
99
|
+
} else if (props.enforceNumbersOnly && key.length === 1 && !e.ctrlKey && !e.shiftKey && isNaN(key)) {
|
|
100
|
+
e.preventDefault();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
88
104
|
function between(min, val, max) {
|
|
89
105
|
if (min <= max) {
|
|
90
106
|
return Math.min(max, Math.max(min, val));
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="timespan">
|
|
3
3
|
<div class="input-container">
|
|
4
|
-
<input
|
|
4
|
+
<number-input :value="daysValue" @change="updateValue" :min="0" :max="9999" />
|
|
5
5
|
</div>
|
|
6
6
|
<div class="input-container select">
|
|
7
7
|
<select :value="selectedInterval" @change="updateTimeInterval">
|
|
@@ -13,6 +13,8 @@
|
|
|
13
13
|
</div>
|
|
14
14
|
</template>
|
|
15
15
|
<script setup>
|
|
16
|
+
import NumberInput from './NumberInput.vue';
|
|
17
|
+
|
|
16
18
|
const TIMESPAN_INTERVALS = {
|
|
17
19
|
DAYS: 'DAYS',
|
|
18
20
|
WEEKS: 'WEEKS',
|
|
@@ -30,7 +32,7 @@
|
|
|
30
32
|
});
|
|
31
33
|
const emit = defineEmits(['update']);
|
|
32
34
|
|
|
33
|
-
const daysValue = ref(
|
|
35
|
+
const daysValue = ref(0);
|
|
34
36
|
const selectedInterval = ref(TIMESPAN_INTERVALS.DAYS);
|
|
35
37
|
|
|
36
38
|
onMounted(() => {
|
|
@@ -59,23 +61,26 @@
|
|
|
59
61
|
let newValue = value;
|
|
60
62
|
let newInterval = selectedInterval.value;
|
|
61
63
|
|
|
62
|
-
if (
|
|
63
|
-
if (
|
|
64
|
-
if (
|
|
65
|
-
newValue
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
if (value
|
|
73
|
-
|
|
74
|
-
|
|
64
|
+
if (!isNaN(value)) {
|
|
65
|
+
if (value > 0) {
|
|
66
|
+
if (selectedInterval.value === TIMESPAN_INTERVALS.DAYS) {
|
|
67
|
+
if (newValue % 365 === 0) {
|
|
68
|
+
newValue = newValue / 365;
|
|
69
|
+
newInterval = TIMESPAN_INTERVALS.YEARS;
|
|
70
|
+
} else if (newValue % 7 === 0) {
|
|
71
|
+
newValue = newValue / 7;
|
|
72
|
+
newInterval = TIMESPAN_INTERVALS.WEEKS;
|
|
73
|
+
}
|
|
74
|
+
} else if (selectedInterval.value === TIMESPAN_INTERVALS.WEEKS) {
|
|
75
|
+
if (value % 52 === 0) {
|
|
76
|
+
newValue = value / 52;
|
|
77
|
+
newInterval = TIMESPAN_INTERVALS.YEARS;
|
|
78
|
+
}
|
|
75
79
|
}
|
|
76
80
|
}
|
|
81
|
+
|
|
77
82
|
} else {
|
|
78
|
-
newValue =
|
|
83
|
+
newValue = props.initialValue;
|
|
79
84
|
newInterval = TIMESPAN_INTERVALS.DAYS;
|
|
80
85
|
}
|
|
81
86
|
|