@mapomodule/uikit 1.0.0-alpha.41 → 1.0.0-alpha.43

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.
@@ -19,6 +19,8 @@ const components = {
19
19
  // customs
20
20
  wygEditor: () => import("@mapomodule/uikit/components/Form/fields/wygEditor/wygEditor.vue"),
21
21
  DateField: () => import("@mapomodule/uikit/components/Form/fields/DateField.vue"),
22
+ TimeField: () => import("@mapomodule/uikit/components/Form/fields/TimeField.vue"),
23
+ DateTimeField: () => import("@mapomodule/uikit/components/Form/fields/DateTimeField.vue"),
22
24
  FksField: () => import("@mapomodule/uikit/components/Form/fields/FksField.vue"),
23
25
  MediaM2mField: () => import("@mapomodule/uikit/components/Form/fields/MediaM2mField.vue"),
24
26
  MediaField: () => import("@mapomodule/uikit/components/Form/fields/MediaField.vue"),
@@ -33,6 +35,8 @@ const mapping = {
33
35
  text: components.vTextField,
34
36
  select: components.vSelect,
35
37
  date: components.DateField,
38
+ time: components.TimeField,
39
+ datetime: components.DateTimeField,
36
40
  textarea: components.vTextarea,
37
41
  switch: components.vSwitch,
38
42
  slider: components.vSlider,
@@ -0,0 +1,270 @@
1
+ <template>
2
+ <div>
3
+ <v-menu ref="menu" v-model="menu" :close-on-content-click="false" max-width="580">
4
+ <template v-slot:activator="{ on, attrs }">
5
+ <v-text-field
6
+ :value="textFieldString"
7
+ prepend-inner-icon="mdi-calendar"
8
+ readonly
9
+ v-bind="{ ...$attrs, ...attrs }"
10
+ v-on="readonly ? undefined : on"
11
+ :clearable="!readonly"
12
+ class="rounded-inherit"
13
+ ></v-text-field>
14
+ </template>
15
+ <v-card>
16
+ <div class="d-flex flex-nowrap">
17
+ <v-date-picker
18
+ v-model="dateModel"
19
+ :range="range"
20
+ no-title
21
+ v-bind="datePickerAttrs"
22
+ class="rounded-0"
23
+ ref="datePicker"
24
+ >
25
+ </v-date-picker
26
+ ><v-time-picker
27
+ v-model="timeModel"
28
+ no-title
29
+ v-bind="timePickerAttrs"
30
+ ref="timePicker"
31
+ class="rounded-0"
32
+ >
33
+ </v-time-picker>
34
+ </div>
35
+ <v-card-actions class="justify-center">
36
+ <input
37
+ v-model="startRawDateTime"
38
+ type="datetime-local"
39
+ class="primary--text text-h6 raw-input"
40
+ ref="startRawInput"
41
+ autofocus
42
+ @click="disableCalendar"
43
+ @keydown="disableCalendar"
44
+ />
45
+ <v-divider class="mx-4" v-if="range"></v-divider>
46
+ <input
47
+ v-if="range"
48
+ :disabled="!startDateTime"
49
+ v-model="endRawDateTime"
50
+ type="datetime-local"
51
+ class="primary--text text-h6 raw-input"
52
+ ref="endRawInput"
53
+ autofocus
54
+ @click="disableCalendar"
55
+ @keydown="disableCalendar"
56
+ />
57
+ </v-card-actions>
58
+ </v-card>
59
+ </v-menu>
60
+ </div>
61
+ </template>
62
+
63
+ <style scoped>
64
+ .rounded-inherit {
65
+ border-radius: inherit;
66
+ }
67
+ .raw-input {
68
+ outline: none;
69
+ }
70
+ </style>
71
+
72
+ <script>
73
+ import {
74
+ formatLocalTime,
75
+ formatLocalDate,
76
+ formatLocalDateTime,
77
+ mergeDate,
78
+ mergeTime,
79
+ cleanDateStr,
80
+ } from "@mapomodule/utils/helpers/datetime";
81
+
82
+ /**
83
+ * This component is used to edit a datetime in iso format. It is a combination of "v-text-field", "v-date-picker" and "v-time-picker".
84
+ * All dates are emitted using UTC timezone.
85
+ */
86
+ export default {
87
+ name: "DateTimeField",
88
+ data() {
89
+ return {
90
+ startDateTime: null,
91
+ endDateTime: null,
92
+ menu: null,
93
+ isStartFocused: true,
94
+ focusinFunc: () => {
95
+ this.isStartFocused = document.activeElement !== this.$refs.endRawInput;
96
+ },
97
+ };
98
+ },
99
+ props: {
100
+ // V-model property. Is the date to be modified. It can be also array in case of date range.
101
+ value: {
102
+ // `String|Array`
103
+ type: String | Array,
104
+ },
105
+ // Determines if we need to work with date ranges.
106
+ range: {
107
+ type: Boolean,
108
+ default: false,
109
+ },
110
+ // This set the component status to readonly, stopping the user interaction.
111
+ readonly: {
112
+ type: Boolean,
113
+ default: false,
114
+ },
115
+ datePickerAttrs: {
116
+ type: Object,
117
+ default: () => {},
118
+ },
119
+ timePickerAttrs: {
120
+ type: Object,
121
+ default: () => {},
122
+ },
123
+ },
124
+ watch: {
125
+ value(val) {
126
+ this.setupValue();
127
+ },
128
+ menu(val) {
129
+ if (val)
130
+ setTimeout(() => {
131
+ this.$refs.startRawInput?.focus();
132
+ this.$refs.timePicker.selecting = 1;
133
+ });
134
+ },
135
+ isStartFocused(val, old) {
136
+ if (val != old) this.$refs.timePicker.selecting = 1;
137
+ },
138
+ },
139
+ methods: {
140
+ disableCalendar(evt) {
141
+ if (!evt.keyCode || evt.keyCode == 13) {
142
+ evt.preventDefault();
143
+ return false;
144
+ }
145
+ },
146
+ selectTimePickerMethod(oldDateTime, newDateTime) {
147
+ const currentValue = oldDateTime?.split("T").splice(-1)[0]?.split(":") || [];
148
+ const nextValue = newDateTime?.split("T").splice(-1)[0].split(":") || [];
149
+ for (
150
+ let index = 0;
151
+ index < Math.min(currentValue.length, nextValue.length);
152
+ index++
153
+ ) {
154
+ if (currentValue[index] != nextValue[index]) {
155
+ this.$refs.timePicker.selecting = index + 1;
156
+ break;
157
+ }
158
+ }
159
+ },
160
+ emit() {
161
+ if (this.range) {
162
+ const start = this.startDateTime && new Date(this.startDateTime);
163
+ const end = this.endDateTime && new Date(this.endDateTime);
164
+ if (start && end && start > end)
165
+ [this.startDateTime, this.endDateTime] = [this.endDateTime, this.startDateTime];
166
+ }
167
+ this.$emit(
168
+ "input",
169
+ this.range
170
+ ? [this.startDateTime, this.endDateTime].filter((d) => d)
171
+ : this.startDateTime
172
+ );
173
+ },
174
+ setupValue() {
175
+ const dates =
176
+ (typeof this.value == "string" && this.value
177
+ ? this.value.split(",").filter((v) => v)
178
+ : this.value) || [];
179
+ this.startDateTime = dates.length > 0 ? cleanDateStr(dates[0]) : null;
180
+ this.endDateTime = dates.length > 1 ? cleanDateStr(dates[1]) : null;
181
+ },
182
+ },
183
+ computed: {
184
+ timeModel: {
185
+ get() {
186
+ const time = this.isStartFocused ? this.startDateTime : this.endDateTime;
187
+ if (!time) return null;
188
+ return formatLocalTime(time);
189
+ },
190
+ set(value) {
191
+ if (this.isStartFocused)
192
+ this.startDateTime = mergeTime(this.startDateTime, value).toISOString();
193
+ else this.endDateTime = mergeTime(this.endDateTime, value).toISOString();
194
+ this.emit();
195
+ },
196
+ },
197
+ dateModel: {
198
+ get() {
199
+ const d = [this.startDateTime, this.endDateTime]
200
+ .filter((d) => d)
201
+ .map((d) => formatLocalDate(d));
202
+ if (this.range) return d;
203
+ else if (d.length > 0) return d[0];
204
+ return null;
205
+ },
206
+ set(value) {
207
+ if (this.range && value.length == 2) {
208
+ this.endDateTime = mergeDate(this.endDateTime || null, value[1]).toISOString();
209
+ this.startDateTime = mergeDate(
210
+ this.startDateTime || null,
211
+ value[0]
212
+ ).toISOString();
213
+ setTimeout(() => this.$refs.endRawInput?.focus());
214
+ } else {
215
+ this.endDateTime = null;
216
+ this.startDateTime = mergeDate(
217
+ this.startDateTime || null,
218
+ Array.isArray(value) ? value[0] : value
219
+ ).toISOString();
220
+ }
221
+ this.emit();
222
+ },
223
+ },
224
+ startRawDateTime: {
225
+ get() {
226
+ if (!this.startDateTime) return null;
227
+ return formatLocalDateTime(this.startDateTime);
228
+ },
229
+ set(value) {
230
+ const oldDateTime = this.startDateTime;
231
+ if (value) this.startDateTime = new Date(value).toISOString();
232
+ this.selectTimePickerMethod(oldDateTime, this.startDateTime);
233
+ this.emit();
234
+ },
235
+ },
236
+ endRawDateTime: {
237
+ get() {
238
+ if (!this.endDateTime) return null;
239
+ return formatLocalDateTime(this.endDateTime);
240
+ },
241
+ set(value) {
242
+ const oldDateTime = this.endDateTime;
243
+ if (value) this.endDateTime = new Date(value).toISOString();
244
+ this.selectTimePickerMethod(oldDateTime, this.endDateTime);
245
+ setTimeout(() => this.$refs.endRawInput?.focus());
246
+ this.emit();
247
+ },
248
+ },
249
+ textFieldString() {
250
+ return this.range
251
+ ? [this.startDateTime, this.endDateTime]
252
+ .filter((d) => d)
253
+ .map((d) => new Date(d).toLocaleString())
254
+ .join(", ")
255
+ : this.startDateTime && new Date(this.startDateTime).toLocaleString();
256
+ },
257
+ },
258
+ mounted() {
259
+ if (process.client) {
260
+ document.addEventListener("focusin", this.focusinFunc);
261
+ }
262
+ this.setupValue();
263
+ },
264
+ destroyed() {
265
+ if (process.client) {
266
+ document.removeEventListener("focusin", this.focusinFunc);
267
+ }
268
+ },
269
+ };
270
+ </script>
@@ -0,0 +1,146 @@
1
+ <template>
2
+ <div>
3
+ <v-menu
4
+ ref="menu"
5
+ v-model="menu"
6
+ :close-on-content-click="false"
7
+ transition="scale-transition"
8
+ offset-y
9
+ min-width="auto"
10
+ >
11
+ <template v-slot:activator="{ on, attrs }">
12
+ <v-text-field
13
+ v-model="localModel"
14
+ prepend-inner-icon="mdi-clock"
15
+ v-bind="{ ...$attrs, ...attrs }"
16
+ v-on="readonly ? undefined : on"
17
+ readonly
18
+ :clearable="!readonly"
19
+ class="rounded-inherit"
20
+ ></v-text-field>
21
+ </template>
22
+ <v-time-picker v-model="localModel" no-title v-bind="$attrs" ref="timePicker">
23
+ <div class="raw-input-container">
24
+ <input
25
+ :value="localModel"
26
+ type="time"
27
+ class="primary--text text-h6"
28
+ ref="rawInput"
29
+ @input="setModel"
30
+ autofocus
31
+ v-bind="$attrs"
32
+ />
33
+ </div>
34
+ </v-time-picker>
35
+ </v-menu>
36
+ </div>
37
+ </template>
38
+
39
+ <style scoped>
40
+ .rounded-inherit {
41
+ border-radius: inherit;
42
+ }
43
+ .raw-input-container {
44
+ width: 100%;
45
+ }
46
+ .raw-input-container input {
47
+ width: 100%;
48
+ text-align: center;
49
+ outline: none;
50
+ }
51
+ </style>
52
+
53
+ <script>
54
+ import {
55
+ formatLocalTime,
56
+ cleanDateStr,
57
+ formatUTCTime,
58
+ mergeTime,
59
+ } from "@mapomodule/utils/helpers/datetime";
60
+
61
+ /**
62
+ * This component is used to edit a time in iso format. It is a combination of "v-text-field" and "v-time-picker".
63
+ * Can get time from a full ISO date (as string in UTC timezone) or from string in a HH:MM:ss format.
64
+ */
65
+ export default {
66
+ name: "TimeField",
67
+ data() {
68
+ return {
69
+ model: { model: null, returnDate: false },
70
+ menu: null,
71
+ };
72
+ },
73
+ props: {
74
+ // V-model property. Is the time to be modified.
75
+ value: {
76
+ // `String`
77
+ type: String, // TODO: make it work also with arrays for ranges
78
+ },
79
+ // This set the component status to readonly, stopping the user interaction.
80
+ readonly: {
81
+ type: Boolean,
82
+ default: false,
83
+ },
84
+ },
85
+ watch: {
86
+ value(val) {
87
+ const model = this.setupModel(val);
88
+ if (JSON.stringify(model) != JSON.stringify(this.model)) {
89
+ this.model = model;
90
+ }
91
+ },
92
+ model: {
93
+ handler: function (val) {
94
+ // Fired when the v-model changes
95
+ //@arg Emits the time edited.
96
+ if (val.returnDate) this.$emit("input", val.model.toISOString());
97
+ else this.$emit("input", formatUTCTime(val.model));
98
+ },
99
+ deep: true,
100
+ },
101
+ menu(val) {
102
+ if (val)
103
+ setTimeout(() => {
104
+ this.$refs.rawInput.focus();
105
+ });
106
+ },
107
+ },
108
+ computed: {
109
+ localModel: {
110
+ get() {
111
+ return this.model?.model && formatLocalTime(this.model?.model);
112
+ },
113
+ set(value) {
114
+ this.model.model = mergeTime(this?.model?.model || new Date(), value);
115
+ },
116
+ },
117
+ },
118
+ methods: {
119
+ setModel(evt) {
120
+ const model = evt.target.value;
121
+ const currentValue = this.localModel?.split(":") || [];
122
+ const nextValue = model?.split(":") || [];
123
+ for (
124
+ let index = 0;
125
+ index < Math.min(currentValue.length, nextValue.length);
126
+ index++
127
+ ) {
128
+ if (currentValue[index] != nextValue[index]) {
129
+ this.$refs.timePicker.selecting = index + 1;
130
+ break;
131
+ }
132
+ }
133
+ this.localModel = model;
134
+ },
135
+ setupModel(val) {
136
+ const d = new Date(cleanDateStr(val));
137
+ const returnDate = !isNaN(d);
138
+ const model = !isNaN(d) ? d : mergeTime(new Date(), cleanDateStr(val));
139
+ return { returnDate, model };
140
+ },
141
+ },
142
+ mounted() {
143
+ this.model = this.setupModel(this.value);
144
+ },
145
+ };
146
+ </script>
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <v-container>
2
+ <v-container class="container">
3
3
  <drop-area @change="updateMediaList($event)" multiple>
4
4
  <template v-slot:actions="{ clearList }">
5
5
  <div v-if="mediaList && mediaList.length">
@@ -59,6 +59,13 @@
59
59
  </v-container>
60
60
  </template>
61
61
 
62
+ <style scoped>
63
+ .container {
64
+ height: 100%;
65
+ overflow: auto;
66
+ }
67
+ </style>
68
+
62
69
  <script>
63
70
  import { mapGetters } from "vuex"
64
71
  const MAX_IMAGE_SIZE = 1000000 // 1mb
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@mapomodule/uikit",
3
- "version": "1.0.0-alpha.41",
3
+ "version": "1.0.0-alpha.43",
4
4
  "license": "MIT",
5
5
  "description": "This is part of Mapo nuxt module. Injects Mapo ui components in the nuxt component discovery system.",
6
6
  "author": "bnznamco <gabriele.baldi.01@gmail.com>",
7
7
  "repository": "https://github.com/lotrekagency/mapo",
8
8
  "main": "./module.js",
9
9
  "dependencies": {
10
- "@mapomodule/utils": "^1.0.0-alpha.40",
10
+ "@mapomodule/utils": "^1.0.0-alpha.43",
11
11
  "@nuxtjs/i18n": "^7.2.2",
12
12
  "@nuxtjs/vuetify": "^1.12.3",
13
13
  "vuedraggable": "^2.24.3"
@@ -15,5 +15,5 @@
15
15
  "publishConfig": {
16
16
  "access": "public"
17
17
  },
18
- "gitHead": "9f6bc45ab0ae3b56ed6fa98597c80808efced174"
18
+ "gitHead": "ffa0eeb2768f663bd8906832c614c51c76987027"
19
19
  }