@afeefa/vue-app 0.0.166 → 0.0.168

Sign up to get free protection for your applications and to get access to all the features.
@@ -1 +1 @@
1
- 0.0.166
1
+ 0.0.168
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@afeefa/vue-app",
3
- "version": "0.0.166",
3
+ "version": "0.0.168",
4
4
  "description": "",
5
5
  "author": "Afeefa Kollektiv <kollektiv@afeefa.de>",
6
6
  "license": "MIT",
@@ -52,7 +52,7 @@ import { PositionConfig } from '../services/PositionService'
52
52
  import { randomCssClass } from '../utils/random'
53
53
 
54
54
  @Component({
55
- props: ['value', 'validator', 'type', {dense: true, outlined: true}]
55
+ props: ['value', 'validator', 'type', {dense: true, outlined: true, focus: false}]
56
56
  })
57
57
  export default class ADatePicker extends Mixins(ComponentWidthMixin, UsesPositionServiceMixin, CancelOnEscMixin) {
58
58
  value_ = null
@@ -65,6 +65,8 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin, UsesPositio
65
65
  }
66
66
 
67
67
  mounted () {
68
+ this.setFocus()
69
+
68
70
  this.validate()
69
71
  }
70
72
 
@@ -74,6 +76,11 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin, UsesPositio
74
76
  this.validate()
75
77
  }
76
78
 
79
+ @Watch('focus')
80
+ focusChanged () {
81
+ this.setFocus()
82
+ }
83
+
77
84
  get clearable () {
78
85
  if (this.validator && this.validator.getParam('filled')) {
79
86
  return false
@@ -182,11 +189,15 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin, UsesPositio
182
189
  return null
183
190
  }
184
191
 
192
+ return this.dateToString(this.value_).substr(0, this.type === 'month' ? 7 : 10)
193
+ }
194
+
195
+ dateToString (date) {
185
196
  // format date to v-date-picker compatible string: https://stackoverflow.com/a/29774197
186
- const offset = this.value_.getTimezoneOffset()
187
- let date = new Date(this.value_.getTime() - (offset * 60 * 1000))
188
- date = date.toISOString().substr(0, this.type === 'month' ? 7 : 10)
189
- return date
197
+ // respecting and adding local time zone time shift to the utc iso string
198
+ const offset = date.getTimezoneOffset()
199
+ date = new Date(date.getTime() - (offset * 60 * 1000))
200
+ return date.toISOString()
190
201
  }
191
202
 
192
203
  get label () {
@@ -208,15 +219,16 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin, UsesPositio
208
219
  this.dateChanged(null)
209
220
  } else if (this.validateTextInput(value)) {
210
221
  const [day, month, year] = value.split('.')
211
- this.dateChanged(new Date(year + '-' + month + '-' + day))
222
+ const date = new Date(year + '-' + month + '-' + day)
223
+ this.dateChanged(this.dateToString(date).split('T')[0])
212
224
  }
213
225
  }
214
226
 
215
- dateChanged (date) {
227
+ dateChanged (date) { // date is a yyyy-mm or yyyy-mm-dd string
216
228
  if (date) {
217
- // take given date string an create a local time date object
218
- // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format
219
- // > 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.
229
+ // take given date string an create a local time date object
230
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date#date_time_string_format
231
+ // > 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.
220
232
  const dateStringThatGetsConvertedToLocalDate = date + 'T00:00'
221
233
  this.value_ = new Date(dateStringThatGetsConvertedToLocalDate)
222
234
  } else {
@@ -287,6 +299,17 @@ export default class ADatePicker extends Mixins(ComponentWidthMixin, UsesPositio
287
299
  }
288
300
  return []
289
301
  }
302
+
303
+ setFocus (force = false) {
304
+ const focus = this.focus || force // set focus if this.focus or else if forced from outside
305
+ if (focus) {
306
+ // if run in a v-dialog, the dialog background would
307
+ // steal the focus without requestAnimationFrame
308
+ requestAnimationFrame(() => {
309
+ this.$el.querySelector('input').focus()
310
+ })
311
+ }
312
+ }
290
313
  }
291
314
  </script>
292
315
 
@@ -76,7 +76,6 @@ export default class FlyingContextContainer extends Vue {
76
76
 
77
77
  this.visible = !!container.children.length
78
78
  const isOpening = mutationRecords.length === 1 && mutationRecords[0].addedNodes.length === 1 // only 1 record ... and this one is 'added'
79
- console.log(mutationRecords)
80
79
 
81
80
  const el = document.documentElement
82
81