@koumoul/vjsf 3.15.0 → 3.15.1

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koumoul/vjsf",
3
- "version": "3.15.0",
3
+ "version": "3.15.1",
4
4
  "description": "Generate forms for the vuetify UI library (vuejs) based on annotated JSON schemas.",
5
5
  "scripts": {
6
6
  "test": "vitest run",
@@ -4,9 +4,12 @@ import { VIcon } from 'vuetify/components/VIcon'
4
4
  import { VDatePicker } from 'vuetify/components/VDatePicker'
5
5
  import { useDefaults } from 'vuetify'
6
6
  import { computed, ref, toRef, watch } from 'vue'
7
+ import Debug from 'debug'
7
8
  import { getDateTimeParts, getDateTimeWithOffset, localeKeyboardFormat } from '../../utils/dates.js'
8
9
  import useNode from '../../composables/use-node.js'
9
10
 
11
+ const debug = Debug('vjsf:date-picker')
12
+
10
13
  useDefaults({}, 'VjsfDatePicker')
11
14
 
12
15
  const props = defineProps({
@@ -28,10 +31,12 @@ const { compProps, localData } = useNode(toRef(props, 'modelValue'), props.state
28
31
 
29
32
  const updateValue = (/** @type {Date | null} */value) => {
30
33
  if (!value) return
34
+
31
35
  const isoValue = props.modelValue.layout.format === 'date-time'
32
36
  ? getDateTimeWithOffset(value)
33
37
  : getDateTimeParts(/** @type Date */(/** @type unknown */(value)))[0]
34
38
  if (isoValue !== localData.value) {
39
+ debug(`apply normalized iso value ${value.toLocaleString()} -> ${isoValue}`)
35
40
  props.statefulLayout.input(props.modelValue, isoValue)
36
41
  menuOpened.value = false
37
42
  }
@@ -57,6 +62,7 @@ watch(localData, setFormattedValue, { immediate: true })
57
62
  const updateFormattedValue = () => {
58
63
  if (formattedValue.value) {
59
64
  const newValue = localeKeyboardFormat(props.modelValue.options.locale).parse(formattedValue.value)
65
+ debug(`parsed user input as date ${formattedValue.value} -> ${newValue?.toLocaleString()}`)
60
66
  if (!newValue) setFormattedValue()
61
67
  else updateValue(newValue)
62
68
  }
@@ -1,9 +1,9 @@
1
1
  // TODO: parts of this can probably be replaced by https://vuetifyjs.com/en/features/dates/
2
2
 
3
3
  // 1 => 01, 12 => 12
4
- export const padTimeComponent = (/** @type number */val) => {
4
+ export const padNumber = (/** @type number */val, size = 2) => {
5
5
  const s = '' + val
6
- return s.length === 1 ? '0' + s : s
6
+ return s.padStart(size, '0')
7
7
  }
8
8
 
9
9
  // storing ISO times with the user's timezone offset is more dense in information that always storing the base ISO date
@@ -12,18 +12,18 @@ export const padTimeComponent = (/** @type number */val) => {
12
12
  // 2020-04-03T19:07:43.152Z => 2020-04-03T21:07:43+02:00
13
13
  export const getDateTimeWithOffset = (/** @type Date */date) => {
14
14
  const offsetMinutes = date.getTimezoneOffset()
15
- const offsetAbs = `${padTimeComponent(Math.abs(offsetMinutes / 60))}:${padTimeComponent(Math.abs(offsetMinutes % 60))}`
15
+ const offsetAbs = `${padNumber(Math.abs(offsetMinutes / 60))}:${padNumber(Math.abs(offsetMinutes % 60))}`
16
16
  let offset
17
17
  if (offsetMinutes < 0) offset = `+${offsetAbs}`
18
18
  else if (offsetMinutes > 0) offset = `-${offsetAbs}`
19
19
  else offset = 'Z'
20
- return `${date.getFullYear()}-${padTimeComponent(date.getMonth() + 1)}-${padTimeComponent(date.getDate())}T${padTimeComponent(date.getHours())}:${padTimeComponent(date.getMinutes())}:${padTimeComponent(date.getSeconds())}${offset}`
20
+ return `${padNumber(date.getFullYear(), 4)}-${padNumber(date.getMonth() + 1)}-${padNumber(date.getDate())}T${padNumber(date.getHours())}:${padNumber(date.getMinutes())}:${padNumber(date.getSeconds())}${offset}`
21
21
  }
22
22
 
23
23
  // get the the date and short time components expected by date-time picker from a full date
24
24
  // 2020-04-03T21:07:43+02:00 => ['2020-04-03', '21:07']
25
25
  export const getDateTimeParts = (/** @type Date */date) => {
26
- return [`${date.getFullYear()}-${padTimeComponent(date.getMonth() + 1)}-${padTimeComponent(date.getDate())}`, `${padTimeComponent(date.getHours())}:${padTimeComponent(date.getMinutes())}`]
26
+ return [`${padNumber(date.getFullYear(), 4)}-${padNumber(date.getMonth() + 1)}-${padNumber(date.getDate())}`, `${padNumber(date.getHours())}:${padNumber(date.getMinutes())}`]
27
27
  }
28
28
 
29
29
  // get a full date-time from the date and time parts edited by date-time picker
@@ -1,4 +1,4 @@
1
- export function padTimeComponent(val: number): string;
1
+ export function padNumber(val: number, size?: number): string;
2
2
  export function getDateTimeWithOffset(date: Date): string;
3
3
  export function getDateTimeParts(date: Date): string[];
4
4
  export function getDateTime(parts: [string, string]): string;
@@ -1 +1 @@
1
- {"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../../src/utils/dates.js"],"names":[],"mappings":"AAGO,sCAAoC,MAAM,UAGhD;AAMM,4CAAyC,IAAI,UAQnD;AAIM,uCAAoC,IAAI,YAE9C;AAIM,mCAA+B,CAAC,MAAM,EAAE,MAAM,CAAC,UAWrD;AAGM,mCAAgC,MAAM,GAAG,SAAS,UAGxD;AAEM,kCAA+B,MAAM,UAE3C;AA2BM,6CAAwC,MAAM;mBAK9B,IAAI;2BACL,MAAM;EAkC3B"}
1
+ {"version":3,"file":"dates.d.ts","sourceRoot":"","sources":["../../src/utils/dates.js"],"names":[],"mappings":"AAGO,+BAA6B,MAAM,yBAGzC;AAMM,4CAAyC,IAAI,UAQnD;AAIM,uCAAoC,IAAI,YAE9C;AAIM,mCAA+B,CAAC,MAAM,EAAE,MAAM,CAAC,UAWrD;AAGM,mCAAgC,MAAM,GAAG,SAAS,UAGxD;AAEM,kCAA+B,MAAM,UAE3C;AA2BM,6CAAwC,MAAM;mBAK9B,IAAI;2BACL,MAAM;EAkC3B"}