fluency-v8-components 1.3.9 → 1.4.0

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.
@@ -1,4 +1,4 @@
1
- import { c as Da, _ as Va, g as il } from "./index-DrG6GyAN.mjs";
1
+ import { c as Da, _ as Va, g as il } from "./index-Br4jyWhU.mjs";
2
2
  var fn = {}, cn = {}, cr, vn;
3
3
  function Q() {
4
4
  if (vn) return cr;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fluency-v8-components",
3
- "version": "1.3.9",
3
+ "version": "1.4.0",
4
4
  "main": "dist/fluency-v8-components.umd.js",
5
5
  "module": "dist/fluency-v8-components.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -1,11 +1,11 @@
1
1
  <template>
2
2
  <div class="col">
3
- <vue-tailwind-datepicker :shortcuts="customShortcuts" v-model="dateValue" />
3
+ <VueTailwindDatepicker :shortcuts="customShortcuts" v-model="dateValue" />
4
4
  </div>
5
5
  </template>
6
6
 
7
7
  <script setup>
8
- import { ref, watch, onMounted } from "vue";
8
+ import { ref, watch } from "vue";
9
9
  import VueTailwindDatepicker from "vue-tailwind-datepicker";
10
10
  import moment from "moment";
11
11
 
@@ -14,40 +14,47 @@ const props = defineProps({
14
14
  to: Number,
15
15
  });
16
16
  const emits = defineEmits(["selectTime"]);
17
- const dateValue = ref([]);
17
+ const dateValue = ref(defaultRange());
18
18
 
19
- watch(dateValue, (val) => {
20
- emits("selectTime", [moment(val[0]).valueOf(), moment(val[1]).valueOf()]);
21
- });
22
19
  watch(
23
- () => props.from,
24
- (val) => {
25
- if (val) {
26
- dateValue.value[0] = formatTime(val);
20
+ () => [props.from, props.to],
21
+ ([from, to]) => {
22
+ const baseRange = Array.isArray(dateValue.value) ? dateValue.value : [];
23
+ const nextRange = baseRange.length === 2 ? [...baseRange] : defaultRange();
24
+ let updated = false;
25
+
26
+ if (isValidTimestamp(from)) {
27
+ nextRange[0] = formatTime(from);
28
+ updated = true;
29
+ }
30
+
31
+ if (isValidTimestamp(to)) {
32
+ nextRange[1] = formatTime(to);
33
+ updated = true;
34
+ }
35
+
36
+ if (updated) {
37
+ dateValue.value = nextRange;
27
38
  } else {
28
39
  resetDate();
29
40
  }
30
- }
41
+ },
42
+ { immediate: true }
31
43
  );
44
+
32
45
  watch(
33
- () => props.to,
46
+ dateValue,
34
47
  (val) => {
35
- if (val) {
36
- dateValue.value[1] = formatTime(val);
48
+ if (Array.isArray(val) && val.length === 2 && val[0] && val[1]) {
49
+ emits("selectTime", [
50
+ moment(val[0]).valueOf(),
51
+ moment(val[1]).valueOf(),
52
+ ]);
37
53
  }
38
- }
54
+ },
55
+ { deep: true }
39
56
  );
40
57
 
41
- onMounted(() => {
42
- if (props.from && props.to) {
43
- const fromFormatted = formatTime(props.from);
44
- const toFormatted = formatTime(props.to);
45
- dateValue.value = [fromFormatted, toFormatted];
46
- } else {
47
- resetDate();
48
- }
49
- });
50
-
51
58
  function customShortcuts() {
52
59
  const date = moment().valueOf();
53
60
  return [
@@ -97,13 +104,21 @@ function customShortcuts() {
97
104
  }
98
105
 
99
106
  function resetDate() {
100
- dateValue.value = [
107
+ dateValue.value = defaultRange();
108
+ }
109
+
110
+ function formatTime(time) {
111
+ return moment(time).format("YYYY-MM-DD HH:mm:ss");
112
+ }
113
+
114
+ function defaultRange() {
115
+ return [
101
116
  formatTime(moment().subtract(1, "hours")),
102
117
  formatTime(moment()),
103
118
  ];
104
119
  }
105
120
 
106
- function formatTime(time) {
107
- return moment(time).format("YYYY-MM-DD HH:mm:ss");
121
+ function isValidTimestamp(value) {
122
+ return typeof value === "number" && !Number.isNaN(value);
108
123
  }
109
124
  </script>
@@ -2,7 +2,7 @@
2
2
  <input
3
3
  type="password"
4
4
  :class="[
5
- 'input-block',
5
+ 'pl-3 input-block',
6
6
  error ? 'ring-red-600 ' : '',
7
7
  readonly ? 'disabled' : '',
8
8
  ]"