glib-web 4.40.0 → 4.41.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,5 +1,7 @@
1
1
  // import Launch from "../../utils/launch";
2
2
 
3
+ import Action from "../../action";
4
+
3
5
  export default class {
4
6
  execute(properties, component) {
5
7
  const spec = Object.assign({}, properties, {
@@ -13,5 +15,7 @@ export default class {
13
15
  ]
14
16
  });
15
17
  Utils.launch.dialog.open(spec, component);
18
+
19
+ Action.execute(properties.onOpen, component);
16
20
  }
17
21
  }
@@ -1,3 +1,4 @@
1
+ import Action from "../../action";
1
2
  import { dialogs } from "../../store";
2
3
 
3
4
  export default class {
@@ -13,5 +14,7 @@ export default class {
13
14
  }
14
15
 
15
16
  Utils.launch.dialog.open(prop, component);
17
+
18
+ Action.execute(spec.onOpen, component);
16
19
  }
17
20
  }
@@ -1,3 +1,4 @@
1
+ import Action from "../../action";
1
2
  import { dialogs } from "../../store";
2
3
 
3
4
  export default class {
@@ -12,5 +13,6 @@ export default class {
12
13
  return;
13
14
  }
14
15
  Utils.launch.dialog.open(prop, component);
16
+ Action.execute(spec.onShow, component);
15
17
  }
16
18
  }
@@ -1,10 +1,10 @@
1
1
  import moment from "moment-timezone";
2
+ import { isString } from "../../utils/type";
2
3
 
3
- export function sanitize(val, type, timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone) {
4
-
4
+ export function sanitize(val, type, timeZone) {
5
5
  if (!val) return;
6
-
7
- val = moment(val).tz(timeZone).toISOString(true);
6
+ const hasTimeZone = isString(timeZone) && timeZone !== "";
7
+ val = hasTimeZone ? moment.tz(val, timeZone).toISOString(true) : moment(val).toISOString(true);
8
8
 
9
9
  switch (type) {
10
10
  case "date":
@@ -31,4 +31,4 @@ export function localeString(val, type, format) {
31
31
  return new Date(val).toLocaleDateString(undefined, fmt);
32
32
  }
33
33
 
34
- }
34
+ }
@@ -1,20 +1,28 @@
1
1
  <template>
2
- <div :style="$styles()" :class="$classes()" v-if="loadIf">
2
+ <div :style="$styles()" :class="$classes()" class="pattern-picker-field" v-if="loadIf">
3
3
  <button-date v-if="spec.template" :type="type" :spec="spec" @datePicked="handleDatePicked"></button-date>
4
4
  <!-- See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date for why we need to use `pattern` -->
5
- <v-text-field v-else ref="field" :color="gcolor" v-model="fieldModel" :name="fieldName" :label="spec.label"
6
- :hint="spec.hint" :type="type" :readonly="spec.readOnly" :disabled="inputDisabled" :min="sanitizeValue(spec.min)"
7
- :max="sanitizeValue(spec.max)" :pattern="pattern" :rules="$validation()" :style="$styles()"
8
- :density="$classes().includes('compact') ? 'compact' : 'default'" :clearable="spec.clearable" @change="onChange"
9
- :variant="variant" validate-on="blur" persistent-placeholder />
5
+
6
+ <template v-else>
7
+ <v-text-field ref="field" :color="gcolor" :label="spec.label" :hint="spec.hint" :readonly="spec.readOnly"
8
+ :disabled="inputDisabled" :style="$styles()" :density="$classes().includes('compact') ? 'compact' : 'default'"
9
+ :clearable="spec.clearable" @change="onChange" :variant="variant" validate-on="blur" persistent-placeholder
10
+ :placeholder="spec.placeholder" @click="openPicker" :value="format" />
11
+ <input ref="nativePicker" v-model="fieldModel" class="native-picker" :type="type" :name="fieldName"
12
+ :min="sanitizeValue(spec.min)" :max="sanitizeValue(spec.max)" :value="sanitizeValue(fieldModel)"
13
+ @change="handleNativeChange" />
14
+ <v-input :model-value="fieldModel" :rules="$validation()"></v-input>
15
+ </template>
10
16
  </div>
11
17
  </template>
12
18
 
13
19
  <script>
20
+ import { useDate } from "vuetify";
14
21
  import { sanitize } from "../composable/date";
15
22
  import { useGlibInput } from "../composable/form";
16
23
  import inputVariant from '../mixins/inputVariant';
17
24
  import buttonDate from "./_buttonDate.vue";
25
+ import { isPresent, isString, isFunction } from "../../utils/type";
18
26
 
19
27
  export default {
20
28
  mixins: [inputVariant],
@@ -25,20 +33,73 @@ export default {
25
33
  pattern: { type: String, required: true }
26
34
  },
27
35
  setup(props) {
36
+ const adapter = useDate();
28
37
  useGlibInput({ props });
38
+
39
+ return { adapter };
40
+ },
41
+ computed: {
42
+ isDateType() {
43
+ return this.type === 'date';
44
+ },
45
+ isDateTimeType() {
46
+ return this.type === 'datetime-local';
47
+ },
48
+ format() {
49
+ if (!isPresent(this.fieldModel)) return;
50
+ if (!isPresent(this.spec.format)) {
51
+ switch (this.type) {
52
+ case 'date':
53
+ return this.adapter.format(this.fieldModel, 'fullDate');
54
+
55
+ case 'datetime-local':
56
+ return this.adapter.format(this.fieldModel, 'keyboardDateTime24h');
57
+
58
+ default:
59
+ return this.adapter.format(this.fieldModel, 'keyboardDateTime24h');
60
+ }
61
+ }
62
+
63
+ return this.adapter.format(this.fieldModel, this.spec.format);
64
+ }
29
65
  },
30
66
  methods: {
31
67
  _linkFieldModels(valueChanged) {
32
68
  if (valueChanged) this.fieldModel = this.sanitizeValue(this.spec.value);
33
69
  },
34
- sanitizeValue(val) {
35
- if (val) {
36
- return sanitize(val, this.type, this.spec.time_zone);
70
+ sanitizeValue(val, timeZone = this.spec.time_zone) {
71
+ if (isPresent(val)) {
72
+ return sanitize(val, this.type, timeZone);
73
+ }
74
+ },
75
+ openPicker() {
76
+ if (this.inputDisabled || this.spec.readOnly) return;
77
+
78
+ const picker = this.$refs.nativePicker;
79
+ if (!picker) return;
80
+
81
+ if (isPresent(this.fieldModel)) {
82
+ picker.value = this.sanitizeValue(this.fieldModel);
83
+ } else if (isPresent(this.spec.value)) {
84
+ picker.value = this.sanitizeValue(this.spec.value);
85
+ }
86
+
87
+ if (isFunction(picker.showPicker)) {
88
+ picker.showPicker();
89
+ } else {
90
+ picker.click();
37
91
  }
38
92
  },
39
93
  onChange() {
40
94
  this.$executeOnChange();
41
95
  },
96
+ handleNativeChange(event) {
97
+ const value = event?.target?.value;
98
+ if (!isString(value)) return;
99
+
100
+ this.fieldModel = this.sanitizeValue(value, '');
101
+ this.$executeOnChange();
102
+ },
42
103
  handleDatePicked(value) {
43
104
  this.fieldModel = value;
44
105
  this.$executeOnChange();
@@ -62,4 +123,17 @@ export default {
62
123
  padding-bottom: unset;
63
124
  }
64
125
  }
126
+
127
+ .pattern-picker-field {
128
+ position: relative;
129
+ }
130
+
131
+ .native-picker {
132
+ position: absolute;
133
+ inset: 0;
134
+ opacity: 0;
135
+ width: 100%;
136
+ height: 100%;
137
+ pointer-events: none;
138
+ }
65
139
  </style>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glib-web",
3
- "version": "4.40.0",
3
+ "version": "4.41.0",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -11,6 +11,17 @@ const opts = {
11
11
  // blueprint: md3,
12
12
  components,
13
13
  // directives,
14
+ date: {
15
+ formats: {
16
+ glibDate: (d) => {
17
+ const yyyy = d.getFullYear();
18
+ const mm = String(d.getMonth() + 1).padStart(2, "0");
19
+ const dd = String(d.getDate()).padStart(2, "0");
20
+
21
+ return `${yyyy} ${mm} ${dd}`;
22
+ }
23
+ }
24
+ },
14
25
  icons: {
15
26
  defaultSet: 'md',
16
27
  aliases,
@@ -24,4 +35,4 @@ const opts = {
24
35
  }
25
36
  };
26
37
 
27
- export default new createVuetify(opts);
38
+ export default new createVuetify(opts);