@webitel/ui-sdk 26.6.76 → 26.6.77
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/dist/{components-BTdvsbd3.js → components-DfoMgyOo.js} +3 -3
- package/dist/ui-sdk.css +1 -1
- package/dist/ui-sdk.js +1 -1
- package/dist/ui-sdk.umd.cjs +125 -125
- package/dist/{wt-chat-emoji-HFmQmJ8S.js → wt-chat-emoji-ePyFdXBg.js} +1 -1
- package/dist/{wt-datepicker-CxwX-c2T.js → wt-datepicker-Dj4InHRH.js} +94 -67
- package/dist/{wt-display-chip-items-Bmqm6_Ef.js → wt-display-chip-items-B6wckCGh.js} +1 -1
- package/dist/{wt-send-message-popup-BDPAZ-Wt.js → wt-send-message-popup-CrNuWhly.js} +1 -1
- package/dist/{wt-type-extension-value-input-BpT4QIMd.js → wt-type-extension-value-input-DXALLG2f.js} +1 -1
- package/dist/{wt-vidstack-player-DIL9OGud.js → wt-vidstack-player-D5Coove0.js} +1 -1
- package/package.json +1 -1
- package/src/components/wt-datepicker/_internals/composables/useRestoreOnBlur.ts +53 -0
- package/src/components/wt-datepicker/wt-datepicker.vue +14 -0
- package/types/components/wt-datepicker/_internals/composables/useRestoreOnBlur.d.ts +21 -0
|
@@ -3,7 +3,7 @@ import { d as t, f as n, l as r, r as i } from "./enums-De8CDKZ1.js";
|
|
|
3
3
|
import { a, i as o, n as s, r as c, t as l } from "./toZonedTime-B8L5kbse.js";
|
|
4
4
|
import { t as u } from "./vue-i18n-Db_oYfO8.js";
|
|
5
5
|
import { t as d } from "./useValidation-DGl2otXJ.js";
|
|
6
|
-
import { computed as f, createBlock as p, createCommentVNode as m, createElementBlock as
|
|
6
|
+
import { computed as f, createBlock as p, createCommentVNode as m, createElementBlock as ee, createElementVNode as h, createTextVNode as g, createVNode as _, defineComponent as v, guardReactiveProps as y, mergeModels as b, mergeProps as x, nextTick as S, normalizeProps as C, onMounted as w, onUnmounted as T, openBlock as E, renderSlot as D, resolveComponent as O, toDisplayString as k, toRefs as A, unref as j, useModel as M, useTemplateRef as N, vShow as P, watch as F, withCtx as I, withDirectives as L } from "vue";
|
|
7
7
|
import R from "primevue/datepicker";
|
|
8
8
|
//#region node_modules/date-fns-tz/dist/esm/fromZonedTime/index.js
|
|
9
9
|
function z(e, t, n) {
|
|
@@ -38,35 +38,56 @@ function B(e) {
|
|
|
38
38
|
let n = e.target, { value: r, cursor: i } = t;
|
|
39
39
|
t = null, n.value !== r && (n.value = r, n.setSelectionRange(i, i), e.stopImmediatePropagation());
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
w(() => {
|
|
42
42
|
let t = e();
|
|
43
43
|
t && (t.addEventListener("input", n, { capture: !0 }), t.addEventListener("input", r));
|
|
44
|
-
}),
|
|
44
|
+
}), T(() => {
|
|
45
45
|
let t = e();
|
|
46
46
|
t && (t.removeEventListener("input", n, { capture: !0 }), t.removeEventListener("input", r));
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
//#endregion
|
|
50
|
+
//#region src/components/wt-datepicker/_internals/composables/useRestoreOnBlur.ts
|
|
51
|
+
function V(e, t, n) {
|
|
52
|
+
let r = null;
|
|
53
|
+
function i() {
|
|
54
|
+
F(e, (e) => {
|
|
55
|
+
e !== null && (r = e);
|
|
56
|
+
}, { immediate: !0 });
|
|
57
|
+
}
|
|
58
|
+
function a() {
|
|
59
|
+
if (n()) return;
|
|
60
|
+
let e = t();
|
|
61
|
+
e && e.rawValue === null && r !== null && S(() => {
|
|
62
|
+
e.updateModel(new Date(r.getTime()));
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
onBlur: a,
|
|
67
|
+
watchRestoreOnBlurLastValidValue: i
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
50
71
|
//#region src/components/wt-datepicker/wt-datepicker.vue?vue&type=script&setup=true&lang.ts
|
|
51
|
-
var
|
|
72
|
+
var H = { class: "wt-datepicker" }, U = { class: "wt-datepicker__button-bar" }, W = [
|
|
52
73
|
"onMousedown",
|
|
53
74
|
"onMouseup",
|
|
54
75
|
"onMouseleave"
|
|
55
|
-
],
|
|
76
|
+
], G = [
|
|
56
77
|
"onMousedown",
|
|
57
78
|
"onMouseup",
|
|
58
79
|
"onMouseleave"
|
|
59
|
-
],
|
|
80
|
+
], K = [
|
|
60
81
|
"onMousedown",
|
|
61
82
|
"onMouseup",
|
|
62
83
|
"onMouseleave"
|
|
63
|
-
],
|
|
84
|
+
], q = [
|
|
64
85
|
"onMousedown",
|
|
65
86
|
"onMouseup",
|
|
66
87
|
"onMouseleave"
|
|
67
|
-
],
|
|
88
|
+
], J = /*#__PURE__*/ e(/* @__PURE__ */ v({
|
|
68
89
|
__name: "wt-datepicker",
|
|
69
|
-
props: /*@__PURE__*/
|
|
90
|
+
props: /*@__PURE__*/ b({
|
|
70
91
|
showTime: { type: Boolean },
|
|
71
92
|
minDate: {},
|
|
72
93
|
maxDate: {},
|
|
@@ -146,7 +167,7 @@ var V = { class: "wt-datepicker" }, H = { class: "wt-datepicker__button-bar" },
|
|
|
146
167
|
modelValue: { default: null },
|
|
147
168
|
modelModifiers: {}
|
|
148
169
|
}),
|
|
149
|
-
emits: /*@__PURE__*/
|
|
170
|
+
emits: /*@__PURE__*/ b([
|
|
150
171
|
"update:modelValue",
|
|
151
172
|
"value-change",
|
|
152
173
|
"input",
|
|
@@ -162,7 +183,7 @@ var V = { class: "wt-datepicker" }, H = { class: "wt-datepicker__button-bar" },
|
|
|
162
183
|
"keydown"
|
|
163
184
|
], ["update:modelValue"]),
|
|
164
185
|
setup(e, { emit: a }) {
|
|
165
|
-
let o = e, s =
|
|
186
|
+
let o = e, s = M(e, "modelValue"), { t: c } = u(), v = f({
|
|
166
187
|
get() {
|
|
167
188
|
if (!s.value) return null;
|
|
168
189
|
let e = /* @__PURE__ */ new Date(+s.value);
|
|
@@ -170,54 +191,58 @@ var V = { class: "wt-datepicker" }, H = { class: "wt-datepicker__button-bar" },
|
|
|
170
191
|
},
|
|
171
192
|
set(e) {
|
|
172
193
|
if (!e) {
|
|
194
|
+
if (!o.clearable) return;
|
|
173
195
|
s.value = null;
|
|
174
196
|
return;
|
|
175
197
|
}
|
|
176
198
|
let t = o.timezone ? z(e, o.timezone) : e;
|
|
177
199
|
s.value = t.getTime();
|
|
178
200
|
}
|
|
179
|
-
}),
|
|
180
|
-
B(() =>
|
|
181
|
-
let
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
201
|
+
}), b = N("datepicker"), w = `datepicker-${Math.random().toString(36).slice(2, 11)}`;
|
|
202
|
+
B(() => b.value?.$el?.querySelector("input"));
|
|
203
|
+
let { onBlur: T, watchRestoreOnBlurLastValidValue: F } = V(v, () => b.value, () => !!o.clearable);
|
|
204
|
+
F();
|
|
205
|
+
let J = f(() => o.placholder || `dd/mm/yyyy ${o.showTime ? "hh:mm" : ""}`), Y = () => {
|
|
206
|
+
if (o.showTime && v.value) {
|
|
207
|
+
let e = v.value;
|
|
208
|
+
S(() => {
|
|
209
|
+
v.value = new Date(e.getTime());
|
|
186
210
|
});
|
|
187
211
|
}
|
|
188
212
|
setTimeout(() => {
|
|
189
|
-
|
|
190
|
-
let e =
|
|
213
|
+
b.value?.alignOverlay();
|
|
214
|
+
let e = b.value?.overlay;
|
|
191
215
|
e && (e.style.minWidth = "");
|
|
192
216
|
}, 0);
|
|
193
|
-
},
|
|
194
|
-
v:
|
|
195
|
-
customValidators:
|
|
217
|
+
}, X = f(() => o.required ? `${o.label}*` : o.label), { v: Z, customValidators: Q } = A(o), { isValidation: te, invalid: ne, validationText: $, validationTextColor: re } = d({
|
|
218
|
+
v: Z,
|
|
219
|
+
customValidators: Q
|
|
196
220
|
});
|
|
197
221
|
return (a, o) => {
|
|
198
|
-
let s =
|
|
199
|
-
return
|
|
200
|
-
|
|
201
|
-
for:
|
|
202
|
-
invalid:
|
|
222
|
+
let s = O("wt-label"), l = O("wt-button"), u = O("wt-icon-btn"), d = O("wt-message");
|
|
223
|
+
return E(), ee("div", H, [
|
|
224
|
+
_(s, x(e.labelProps, { disabled: e.disabled }, {
|
|
225
|
+
for: w,
|
|
226
|
+
invalid: j(ne)
|
|
203
227
|
}), {
|
|
204
|
-
default: I(() => [
|
|
228
|
+
default: I(() => [D(a.$slots, "label", C(y({ label: e.label })), () => [g(k(X.value), 1)], !0)], void 0, !0),
|
|
205
229
|
_: 3
|
|
206
230
|
}, 16, ["disabled", "invalid"]),
|
|
207
|
-
|
|
231
|
+
_(j(R), {
|
|
208
232
|
ref_key: "datepicker",
|
|
209
|
-
ref:
|
|
210
|
-
id:
|
|
211
|
-
modelValue:
|
|
212
|
-
"onUpdate:modelValue": o[0] ||= (e) =>
|
|
233
|
+
ref: b,
|
|
234
|
+
id: w,
|
|
235
|
+
modelValue: v.value,
|
|
236
|
+
"onUpdate:modelValue": o[0] ||= (e) => v.value = e,
|
|
213
237
|
"date-format": "dd/mm/yy",
|
|
238
|
+
"input-class": "typo-body-1",
|
|
214
239
|
required: e.required,
|
|
215
240
|
disabled: e.disabled,
|
|
216
241
|
"show-time": e.showTime,
|
|
217
242
|
"min-date": e.minDate,
|
|
218
243
|
"max-date": e.maxDate,
|
|
219
|
-
placeholder:
|
|
220
|
-
"show-clear": e.clearable &&
|
|
244
|
+
placeholder: J.value,
|
|
245
|
+
"show-clear": e.clearable && v.value,
|
|
221
246
|
"show-button-bar": "",
|
|
222
247
|
fluid: "",
|
|
223
248
|
pt: {
|
|
@@ -229,68 +254,69 @@ var V = { class: "wt-datepicker" }, H = { class: "wt-datepicker__button-bar" },
|
|
|
229
254
|
minute: { class: "typo-body-2" },
|
|
230
255
|
panel: { style: { maxWidth: "380px" } }
|
|
231
256
|
},
|
|
232
|
-
onShow:
|
|
257
|
+
onShow: Y,
|
|
258
|
+
onBlur: j(T)
|
|
233
259
|
}, {
|
|
234
|
-
buttonbar: I(({ todayCallback: i, clearCallback: a }) => [
|
|
235
|
-
color:
|
|
236
|
-
variant:
|
|
237
|
-
size:
|
|
260
|
+
buttonbar: I(({ todayCallback: i, clearCallback: a }) => [h("div", U, [_(l, {
|
|
261
|
+
color: j(n).SECONDARY,
|
|
262
|
+
variant: j(t).OUTLINED,
|
|
263
|
+
size: j(r).SM,
|
|
238
264
|
onClick: i
|
|
239
265
|
}, {
|
|
240
|
-
default: I(() => [
|
|
266
|
+
default: I(() => [g(k(j(c)("reusable.today")), 1)], void 0, !0),
|
|
241
267
|
_: 1
|
|
242
268
|
}, 8, [
|
|
243
269
|
"color",
|
|
244
270
|
"variant",
|
|
245
271
|
"size",
|
|
246
272
|
"onClick"
|
|
247
|
-
]), L(
|
|
248
|
-
color:
|
|
249
|
-
variant:
|
|
250
|
-
size:
|
|
273
|
+
]), L(_(l, {
|
|
274
|
+
color: j(n).SECONDARY,
|
|
275
|
+
variant: j(t).OUTLINED,
|
|
276
|
+
size: j(r).SM,
|
|
251
277
|
onClick: a
|
|
252
278
|
}, {
|
|
253
|
-
default: I(() => [
|
|
279
|
+
default: I(() => [g(k(j(c)("reusable.clear")), 1)], void 0, !0),
|
|
254
280
|
_: 1
|
|
255
281
|
}, 8, [
|
|
256
282
|
"color",
|
|
257
283
|
"variant",
|
|
258
284
|
"size",
|
|
259
285
|
"onClick"
|
|
260
|
-
]), [[
|
|
261
|
-
prevbutton: I(({ actionCallback: e }) => [
|
|
286
|
+
]), [[P, e.clearable && v.value]])])]),
|
|
287
|
+
prevbutton: I(({ actionCallback: e }) => [_(u, {
|
|
262
288
|
icon: "arrow-left",
|
|
263
289
|
onClick: e
|
|
264
290
|
}, null, 8, ["onClick"])]),
|
|
265
|
-
nextbutton: I(({ actionCallback: e }) => [
|
|
291
|
+
nextbutton: I(({ actionCallback: e }) => [_(u, {
|
|
266
292
|
icon: "arrow-right",
|
|
267
293
|
onClick: e
|
|
268
294
|
}, null, 8, ["onClick"])]),
|
|
269
|
-
clearicon: I(({ clearCallback: e }) => [
|
|
295
|
+
clearicon: I(({ clearCallback: e }) => [_(u, {
|
|
270
296
|
icon: "close",
|
|
271
297
|
class: "wt-datepicker__clear-icon",
|
|
272
298
|
onClick: e
|
|
273
299
|
}, null, 8, ["onClick"])]),
|
|
274
|
-
hourincrementbutton: I(({ callbacks: e }) => [
|
|
300
|
+
hourincrementbutton: I(({ callbacks: e }) => [h("span", {
|
|
275
301
|
onMousedown: e.mousedown,
|
|
276
302
|
onMouseup: e.mouseup,
|
|
277
303
|
onMouseleave: e.mouseleave
|
|
278
|
-
}, [
|
|
279
|
-
hourdecrementbutton: I(({ callbacks: e }) => [
|
|
304
|
+
}, [_(u, { icon: "arrow-up" })], 40, W)]),
|
|
305
|
+
hourdecrementbutton: I(({ callbacks: e }) => [h("span", {
|
|
280
306
|
onMousedown: e.mousedown,
|
|
281
307
|
onMouseup: e.mouseup,
|
|
282
308
|
onMouseleave: e.mouseleave
|
|
283
|
-
}, [
|
|
284
|
-
minuteincrementbutton: I(({ callbacks: e }) => [
|
|
309
|
+
}, [_(u, { icon: "arrow-down" })], 40, G)]),
|
|
310
|
+
minuteincrementbutton: I(({ callbacks: e }) => [h("span", {
|
|
285
311
|
onMousedown: e.mousedown,
|
|
286
312
|
onMouseup: e.mouseup,
|
|
287
313
|
onMouseleave: e.mouseleave
|
|
288
|
-
}, [
|
|
289
|
-
minutedecrementbutton: I(({ callbacks: e }) => [
|
|
314
|
+
}, [_(u, { icon: "arrow-up" })], 40, K)]),
|
|
315
|
+
minutedecrementbutton: I(({ callbacks: e }) => [h("span", {
|
|
290
316
|
onMousedown: e.mousedown,
|
|
291
317
|
onMouseup: e.mouseup,
|
|
292
318
|
onMouseleave: e.mouseleave
|
|
293
|
-
}, [
|
|
319
|
+
}, [_(u, { icon: "arrow-down" })], 40, q)]),
|
|
294
320
|
_: 1
|
|
295
321
|
}, 8, [
|
|
296
322
|
"modelValue",
|
|
@@ -300,15 +326,16 @@ var V = { class: "wt-datepicker" }, H = { class: "wt-datepicker__button-bar" },
|
|
|
300
326
|
"min-date",
|
|
301
327
|
"max-date",
|
|
302
328
|
"placeholder",
|
|
303
|
-
"show-clear"
|
|
329
|
+
"show-clear",
|
|
330
|
+
"onBlur"
|
|
304
331
|
]),
|
|
305
|
-
|
|
332
|
+
j(te) && j($) ? (E(), p(d, {
|
|
306
333
|
key: 0,
|
|
307
|
-
color:
|
|
308
|
-
variant:
|
|
309
|
-
size:
|
|
334
|
+
color: j(re),
|
|
335
|
+
variant: j(i).SIMPLE,
|
|
336
|
+
size: j(r).SM
|
|
310
337
|
}, {
|
|
311
|
-
default: I(() => [
|
|
338
|
+
default: I(() => [g(k(j($)), 1)], void 0, !0),
|
|
312
339
|
_: 1
|
|
313
340
|
}, 8, [
|
|
314
341
|
"color",
|
|
@@ -318,6 +345,6 @@ var V = { class: "wt-datepicker" }, H = { class: "wt-datepicker__button-bar" },
|
|
|
318
345
|
]);
|
|
319
346
|
};
|
|
320
347
|
}
|
|
321
|
-
}), [["__scopeId", "data-v-
|
|
348
|
+
}), [["__scopeId", "data-v-4be684aa"]]);
|
|
322
349
|
//#endregion
|
|
323
|
-
export {
|
|
350
|
+
export { J as default };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as e, i as t } from "./components-
|
|
1
|
+
import { C as e, i as t } from "./components-DfoMgyOo.js";
|
|
2
2
|
import { t as n } from "./_plugin-vue_export-helper-B3ysoDQm.js";
|
|
3
3
|
import { t as r } from "./displayText-CtaxzaBz.js";
|
|
4
4
|
import { Fragment as i, computed as a, createCommentVNode as o, createElementBlock as s, createTextVNode as c, createVNode as l, defineComponent as u, openBlock as d, renderList as f, renderSlot as p, toDisplayString as m, unref as h, withCtx as g } from "vue";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as e, r as t } from "./clients-CIZxqjbV.js";
|
|
2
|
-
import { n } from "./components-
|
|
2
|
+
import { n } from "./components-DfoMgyOo.js";
|
|
3
3
|
import { t as r } from "./vue-i18n-Db_oYfO8.js";
|
|
4
4
|
import { createBlock as i, createTextVNode as a, createVNode as o, defineComponent as s, inject as c, mergeProps as l, onMounted as u, openBlock as d, ref as f, resolveComponent as p, toDisplayString as m, unref as h, withCtx as g } from "vue";
|
|
5
5
|
//#endregion
|
package/dist/{wt-type-extension-value-input-BpT4QIMd.js → wt-type-extension-value-input-DXALLG2f.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as e } from "./clients-CIZxqjbV.js";
|
|
2
|
-
import { a as t, o as n, r, s as i } from "./components-
|
|
2
|
+
import { a as t, o as n, r, s as i } from "./components-DfoMgyOo.js";
|
|
3
3
|
import { t as a } from "./enums-De8CDKZ1.js";
|
|
4
4
|
import { t as o } from "./vue-i18n-Db_oYfO8.js";
|
|
5
5
|
import { computed as s, createBlock as c, createCommentVNode as l, createVNode as u, defineComponent as d, mergeModels as f, mergeProps as p, openBlock as m, renderSlot as h, resolveComponent as g, unref as _, useModel as v } from "vue";
|
package/package.json
CHANGED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { nextTick, type WritableComputedRef, watch } from 'vue';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @author @HlukhovYe
|
|
5
|
+
*
|
|
6
|
+
* https://webitel.atlassian.net/browse/WTEL-9880
|
|
7
|
+
*
|
|
8
|
+
* When the datepicker is not clearable, restores the last valid value on blur
|
|
9
|
+
* if the user left the field empty or typed an invalid date.
|
|
10
|
+
*
|
|
11
|
+
* Since the parent model never becomes null (null writes are blocked in the
|
|
12
|
+
* modelValue setter), PrimeVue's watcher won't re-fire on restore. Instead we
|
|
13
|
+
* call PrimeVue's internal updateModel() directly so it resyncs rawValue and
|
|
14
|
+
* redraws the input.
|
|
15
|
+
*/
|
|
16
|
+
export function useRestoreOnBlur(
|
|
17
|
+
modelValue: WritableComputedRef<Date | null>,
|
|
18
|
+
getDatepicker: () => {
|
|
19
|
+
rawValue: Date | null;
|
|
20
|
+
updateModel: (v: Date) => void;
|
|
21
|
+
} | null,
|
|
22
|
+
isClearable: () => boolean,
|
|
23
|
+
) {
|
|
24
|
+
let lastValid: Date | null = null;
|
|
25
|
+
|
|
26
|
+
function watchRestoreOnBlurLastValidValue() {
|
|
27
|
+
watch(
|
|
28
|
+
modelValue,
|
|
29
|
+
(value) => {
|
|
30
|
+
if (value !== null) lastValid = value;
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
immediate: true,
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function onBlur() {
|
|
39
|
+
if (isClearable()) return;
|
|
40
|
+
const datePickerEl = getDatepicker();
|
|
41
|
+
if (!datePickerEl) return;
|
|
42
|
+
if (datePickerEl.rawValue === null && lastValid !== null) {
|
|
43
|
+
nextTick(() => {
|
|
44
|
+
datePickerEl.updateModel(new Date(lastValid.getTime()));
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
onBlur,
|
|
51
|
+
watchRestoreOnBlurLastValidValue,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
:id="datepickerId"
|
|
14
14
|
v-model="modelValue"
|
|
15
15
|
date-format="dd/mm/yy"
|
|
16
|
+
input-class="typo-body-1"
|
|
16
17
|
:required="required"
|
|
17
18
|
:disabled="disabled"
|
|
18
19
|
:show-time="showTime"
|
|
@@ -48,6 +49,7 @@
|
|
|
48
49
|
}
|
|
49
50
|
}"
|
|
50
51
|
@show="onPanelShow"
|
|
52
|
+
@blur="onBlur"
|
|
51
53
|
>
|
|
52
54
|
<template #buttonbar="{ todayCallback, clearCallback }">
|
|
53
55
|
<div class="wt-datepicker__button-bar">
|
|
@@ -151,6 +153,7 @@ import {
|
|
|
151
153
|
} from '../../enums';
|
|
152
154
|
import { useValidation } from '../../mixins/validationMixin/useValidation';
|
|
153
155
|
import { usePreventZeroPad } from './_internals/composables/usePreventZeroPad';
|
|
156
|
+
import { useRestoreOnBlur } from './_internals/composables/useRestoreOnBlur';
|
|
154
157
|
|
|
155
158
|
interface Props extends DatePickerProps {
|
|
156
159
|
showTime?: boolean;
|
|
@@ -188,6 +191,9 @@ const modelValue = computed({
|
|
|
188
191
|
},
|
|
189
192
|
set(value) {
|
|
190
193
|
if (!value) {
|
|
194
|
+
// When not clearable, don't propagate null to the parent while the user
|
|
195
|
+
// is typing — the blur handler will restore the last valid value instead.
|
|
196
|
+
if (!props.clearable) return;
|
|
191
197
|
model.value = null;
|
|
192
198
|
return;
|
|
193
199
|
}
|
|
@@ -202,6 +208,14 @@ const datepickerId = `datepicker-${Math.random().toString(36).slice(2, 11)}`;
|
|
|
202
208
|
|
|
203
209
|
usePreventZeroPad(() => datepicker.value?.$el?.querySelector('input'));
|
|
204
210
|
|
|
211
|
+
const { onBlur, watchRestoreOnBlurLastValidValue } = useRestoreOnBlur(
|
|
212
|
+
modelValue,
|
|
213
|
+
() => datepicker.value,
|
|
214
|
+
() => !!props.clearable,
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
watchRestoreOnBlurLastValidValue();
|
|
218
|
+
|
|
205
219
|
const getPlaceholder = computed(() => {
|
|
206
220
|
return props.placholder || `dd/mm/yyyy ${props.showTime ? 'hh:mm' : ''}`;
|
|
207
221
|
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type WritableComputedRef } from 'vue';
|
|
2
|
+
/**
|
|
3
|
+
* @author @HlukhovYe
|
|
4
|
+
*
|
|
5
|
+
* https://webitel.atlassian.net/browse/WTEL-9880
|
|
6
|
+
*
|
|
7
|
+
* When the datepicker is not clearable, restores the last valid value on blur
|
|
8
|
+
* if the user left the field empty or typed an invalid date.
|
|
9
|
+
*
|
|
10
|
+
* Since the parent model never becomes null (null writes are blocked in the
|
|
11
|
+
* modelValue setter), PrimeVue's watcher won't re-fire on restore. Instead we
|
|
12
|
+
* call PrimeVue's internal updateModel() directly so it resyncs rawValue and
|
|
13
|
+
* redraws the input.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useRestoreOnBlur(modelValue: WritableComputedRef<Date | null>, getDatepicker: () => {
|
|
16
|
+
rawValue: Date | null;
|
|
17
|
+
updateModel: (v: Date) => void;
|
|
18
|
+
} | null, isClearable: () => boolean): {
|
|
19
|
+
onBlur: () => void;
|
|
20
|
+
watchRestoreOnBlurLastValidValue: () => void;
|
|
21
|
+
};
|