@afeefa/vue-app 0.0.313 → 0.0.315

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 +1 @@
1
- 0.0.313
1
+ 0.0.315
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afeefa/vue-app",
3
- "version": "0.0.313",
3
+ "version": "0.0.315",
4
4
  "description": "",
5
5
  "author": "Afeefa Kollektiv <kollektiv@afeefa.de>",
6
6
  "license": "MIT",
@@ -2,7 +2,7 @@
2
2
  <div :class="['a-date-picker', {'type--month': type === 'month'}]">
3
3
  <v-text-field
4
4
  ref="input"
5
- :value="formattedDate"
5
+ :value="displayedInputValue"
6
6
  :label="label"
7
7
  :placeholder="type === 'month' ? '' : 'DD.MM.JJJJ'"
8
8
  :style="cwm_widthStyle"
@@ -11,7 +11,9 @@
11
11
  append-icon="$calendarIcon"
12
12
  :readonly="type === 'month'"
13
13
  :clearable="clearable"
14
- @input="dateInputChanged"
14
+ @input="onTextInput"
15
+ @focus="onInputFocus"
16
+ @blur="onInputBlur"
15
17
  @click:clear="clearDate"
16
18
  @click:append="open"
17
19
  @mouseup="openIfMonth"
@@ -56,6 +58,8 @@ import { randomCssClass } from '../utils/random'
56
58
  })
57
59
  export default class ADatePicker extends Mixins(ComponentWidthMixin, UsesPositionServiceMixin, CancelOnEscMixin) {
58
60
  value_ = null
61
+ inputFocused = false
62
+ actualInputValue = null
59
63
  errorMessages = []
60
64
  popUpId = randomCssClass(10)
61
65
  isOpen = false
@@ -74,6 +78,8 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin, UsesPositio
74
78
  valueChanged () {
75
79
  this.value_ = this.value
76
80
  this.validate()
81
+
82
+ this.$emit('change', this.value)
77
83
  }
78
84
 
79
85
  @Watch('focus')
@@ -81,11 +87,6 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin, UsesPositio
81
87
  this.setFocus()
82
88
  }
83
89
 
84
- @Watch('formattedDate')
85
- formattedDateChanged () {
86
- this.$emit('displayedDateChanged', this.formattedDate)
87
- }
88
-
89
90
  get clearable () {
90
91
  if (this.validator && this.validator.getParam('filled')) {
91
92
  return false
@@ -107,6 +108,8 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin, UsesPositio
107
108
  container.appendChild(this.popUp)
108
109
  this.positionize()
109
110
 
111
+ this.$el.querySelector('input').blur() // fokus entfernen, damit sofort formatiertes datum erscheint und nicht erst bei mousedown im popup
112
+
110
113
  this.isOpen = true
111
114
 
112
115
  this.coe_watchCancel()
@@ -211,6 +214,7 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin, UsesPositio
211
214
 
212
215
  clearDate () {
213
216
  this.value_ = null
217
+ this.actualInputValue = null // wenn fokussiert dann auf leer setzen
214
218
  this.validate()
215
219
  this.$emit('input', this.value_)
216
220
  }
@@ -219,44 +223,94 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin, UsesPositio
219
223
  return value && value.match(/^(3[01]|[12][0-9]|0?[1-9]).(1[012]|0?[1-9]).((?:19|20)\d{2})$/)
220
224
  }
221
225
 
222
- dateInputChanged (value) {
226
+ onInputFocus (test) {
227
+ if (!this.errorMessages.length) { // ersetze content mit DD.MM.YYYY wenn nicht gerade fehlerhaftes Datum drin ist
228
+ this.actualInputValue = formatDate(this.value_)
229
+ }
230
+
231
+ this.inputFocused = true
232
+ }
233
+
234
+ onTextInput (value) {
235
+ this.actualInputValue = value
236
+ }
237
+
238
+ onInputBlur () {
239
+ let value = this.actualInputValue
223
240
  if (!value) {
224
241
  this.dateChanged(null)
225
- } else if (this.validateTextInput(value)) {
226
- const [day, month, year] = value.split('.')
227
- const date = new Date(year + '-' + month + '-' + day)
228
- this.dateChanged(this.dateToString(date).split('T')[0])
242
+ } else {
243
+ // If input is purely 4/6/8 digits, transform directly: 0104 -> 01.04.<thisYear>, 010426 -> 01.04.2026, 02052025 -> 02.05.2025
244
+ if (/^\d{4}$/.test(value) || /^\d{6}$/.test(value) || /^\d{8}$/.test(value)) {
245
+ const day = value.substr(0, 2)
246
+ const month = value.substr(2, 2)
247
+ const year = value.length === 4
248
+ ? new Date().getFullYear().toString()
249
+ : (value.length === 6
250
+ ? (2000 + parseInt(value.substr(4, 2), 10)).toString()
251
+ : value.substr(4, 4))
252
+ value = `${day.padStart(2, '0')}.${month.padStart(2, '0')}.${year}`
253
+ } else {
254
+ // also accept DD.MM.YY and expand to YYYY (covers inputs like '1.2.20')
255
+ const m = value.match(/^(\d{1,2})\.(\d{1,2})\.(\d{2})$/)
256
+ if (m) {
257
+ const day = m[1].padStart(2, '0')
258
+ const month = m[2].padStart(2, '0')
259
+ const year = (2000 + parseInt(m[3], 10)).toString()
260
+ value = `${day}.${month}.${year}`
261
+ }
262
+ }
263
+
264
+ if (this.validateTextInput(value)) {
265
+ const [day, month, year] = value.split('.')
266
+ const date = new Date(year + '-' + month + '-' + day)
267
+ this.dateChanged(this.dateToString(date).split('T')[0])
268
+ }
229
269
  }
270
+
271
+ this.inputFocused = false
230
272
  }
231
273
 
232
274
  dateChanged (date) { // date is a yyyy-mm or yyyy-mm-dd string
275
+ let newValue
233
276
  if (date) {
234
277
  // take given date string an create a local time date object
235
278
  // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format
236
279
  // > When the time zone offset is absent, date-only forms are interpreted as a UTC time and date-time forms are interpreted as local time.
237
280
  const timeString = this.value_ ? this.value_.toTimeString().split(' ')[0] : '00:00:00'
238
281
  const dateStringThatGetsConvertedToLocalDate = date + 'T' + timeString
239
- this.value_ = new Date(dateStringThatGetsConvertedToLocalDate)
282
+ newValue = new Date(dateStringThatGetsConvertedToLocalDate)
240
283
  } else {
241
- this.value_ = null
284
+ newValue = null
285
+ }
286
+
287
+ // bitte kein date dispatchen, wenn die werte gleich sind,
288
+ // weil hier ggf. das day-popup nicht oeffnet, da das input
289
+ // den fokus verliert
290
+ if (this.value_?.getTime() === newValue?.getTime()) {
291
+ return
242
292
  }
243
293
 
294
+ this.value_ = newValue
295
+
244
296
  this.validate()
245
297
 
246
298
  this.close()
247
299
  this.$emit('input', this.value_)
248
300
  }
249
301
 
250
- get formattedDate () {
251
- const date = this.value_
252
- if (!date) {
253
- return null
254
- }
302
+ get displayedInputValue () {
255
303
  if (this.type === 'month') {
304
+ const date = this.value_
256
305
  const monthName = date.toLocaleString('default', { month: 'long' })
257
306
  return monthName + ' ' + date.getFullYear()
258
307
  }
259
- return formatDate(date)
308
+
309
+ if (!this.value_ || this.inputFocused || this.errorMessages.length) {
310
+ return this.actualInputValue
311
+ }
312
+
313
+ return formatDate(this.value_, {day: 'short'})
260
314
  }
261
315
 
262
316
  validate () {
@@ -299,13 +353,6 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin, UsesPositio
299
353
  }]
300
354
  }
301
355
 
302
- get dateValidationRules () {
303
- if (this.validator) {
304
- return this.validator.getRules(this.label)
305
- }
306
- return []
307
- }
308
-
309
356
  setFocus (force = false) {
310
357
  const focus = this.focus || force // set focus if this.focus or else if forced from outside
311
358
  if (focus) {
@@ -8,7 +8,7 @@
8
8
  hide-details
9
9
  v-bind="$attrs"
10
10
  v-on="$listeners"
11
- @displayedDateChanged="displayedDateChanged"
11
+ @change="dateChanged"
12
12
  />
13
13
  </template>
14
14
 
@@ -16,11 +16,16 @@
16
16
  <script>
17
17
  import { Component, Mixins } from '@a-vue'
18
18
  import { ListFilterMixin } from '../ListFilterMixin'
19
+ import { formatDate } from '@a-vue/utils/format-date'
19
20
 
20
21
  @Component
21
22
  export default class ListFilterDate extends Mixins(ListFilterMixin) {
22
- displayedDateChanged (formattedDate) {
23
- this.displayValue = formattedDate
23
+ created () {
24
+ this.displayValue = formatDate(this.filter.value)
25
+ }
26
+
27
+ dateChanged (formattedDate) {
28
+ this.displayValue = formatDate(formattedDate)
24
29
  }
25
30
  }
26
31
  </script>
@@ -9,7 +9,9 @@ export function formatDate (date, options = {}) {
9
9
  return ''
10
10
  }
11
11
 
12
- const dayName = options.day ? date.toLocaleDateString('de-DE', { weekday: options.weekday || 'long' }) + ', ' : ''
12
+ const dayName = options.day
13
+ ? date.toLocaleDateString('de-DE', {weekday: typeof options.day === 'string' ? options.day : 'long'}) + ', '
14
+ : ''
13
15
 
14
16
  const month = addZero(date.getMonth() + 1)
15
17
  const day = addZero(date.getDate())