@mekari/pixel3-date-picker 0.0.1-dev.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.
Files changed (103) hide show
  1. package/dist/calendar-panel.d.mts +231 -0
  2. package/dist/calendar-panel.d.ts +231 -0
  3. package/dist/calendar-panel.js +1498 -0
  4. package/dist/calendar-panel.mjs +25 -0
  5. package/dist/chunk-26Y3AVJW.mjs +115 -0
  6. package/dist/chunk-3VROFGJH.mjs +34 -0
  7. package/dist/chunk-3YYRUEIF.mjs +257 -0
  8. package/dist/chunk-5PISTT2K.mjs +131 -0
  9. package/dist/chunk-AGAA7XTC.mjs +20 -0
  10. package/dist/chunk-EJCSF5VR.mjs +492 -0
  11. package/dist/chunk-EQWT6VDG.mjs +34 -0
  12. package/dist/chunk-FTR7OMCT.mjs +0 -0
  13. package/dist/chunk-HJ4V3PM6.mjs +125 -0
  14. package/dist/chunk-J5BK7Z2U.mjs +46 -0
  15. package/dist/chunk-JZ2KFYWF.mjs +127 -0
  16. package/dist/chunk-LVCRFE25.mjs +153 -0
  17. package/dist/chunk-NIUQXHGQ.mjs +56 -0
  18. package/dist/chunk-NVULZQVI.mjs +119 -0
  19. package/dist/chunk-OY5PVQH5.mjs +31 -0
  20. package/dist/chunk-Q3Z5ZITX.mjs +155 -0
  21. package/dist/chunk-QZ7VFGWC.mjs +6 -0
  22. package/dist/chunk-V36XV4LV.mjs +129 -0
  23. package/dist/chunk-V6D6W7RO.mjs +0 -0
  24. package/dist/chunk-VACMCDOZ.mjs +8 -0
  25. package/dist/components/calendar/index.d.mts +11 -0
  26. package/dist/components/calendar/index.d.ts +11 -0
  27. package/dist/components/calendar/index.js +548 -0
  28. package/dist/components/calendar/index.mjs +23 -0
  29. package/dist/components/calendar/table-date.d.mts +97 -0
  30. package/dist/components/calendar/table-date.d.ts +97 -0
  31. package/dist/components/calendar/table-date.js +305 -0
  32. package/dist/components/calendar/table-date.mjs +13 -0
  33. package/dist/components/calendar/table-month.d.mts +90 -0
  34. package/dist/components/calendar/table-month.d.ts +90 -0
  35. package/dist/components/calendar/table-month.js +294 -0
  36. package/dist/components/calendar/table-month.mjs +14 -0
  37. package/dist/components/calendar/table-year.d.mts +71 -0
  38. package/dist/components/calendar/table-year.d.ts +71 -0
  39. package/dist/components/calendar/table-year.js +288 -0
  40. package/dist/components/calendar/table-year.mjs +14 -0
  41. package/dist/components/parts/date.d.mts +38 -0
  42. package/dist/components/parts/date.d.ts +38 -0
  43. package/dist/components/parts/date.js +70 -0
  44. package/dist/components/parts/date.mjs +7 -0
  45. package/dist/components/parts/day.d.mts +6 -0
  46. package/dist/components/parts/day.d.ts +6 -0
  47. package/dist/components/parts/day.js +44 -0
  48. package/dist/components/parts/day.mjs +7 -0
  49. package/dist/components/parts/index.d.mts +9 -0
  50. package/dist/components/parts/index.d.ts +9 -0
  51. package/dist/components/parts/index.js +157 -0
  52. package/dist/components/parts/index.mjs +20 -0
  53. package/dist/components/parts/month.d.mts +29 -0
  54. package/dist/components/parts/month.d.ts +29 -0
  55. package/dist/components/parts/month.js +58 -0
  56. package/dist/components/parts/month.mjs +7 -0
  57. package/dist/components/parts/year.d.mts +29 -0
  58. package/dist/components/parts/year.d.ts +29 -0
  59. package/dist/components/parts/year.js +58 -0
  60. package/dist/components/parts/year.mjs +7 -0
  61. package/dist/composables/useCalendar.d.mts +90 -0
  62. package/dist/composables/useCalendar.d.ts +90 -0
  63. package/dist/composables/useCalendar.js +184 -0
  64. package/dist/composables/useCalendar.mjs +8 -0
  65. package/dist/composables/useCalendarRange.d.mts +277 -0
  66. package/dist/composables/useCalendarRange.d.ts +277 -0
  67. package/dist/composables/useCalendarRange.js +160 -0
  68. package/dist/composables/useCalendarRange.mjs +8 -0
  69. package/dist/date-picker.d.mts +237 -0
  70. package/dist/date-picker.d.ts +237 -0
  71. package/dist/date-picker.js +1851 -0
  72. package/dist/date-picker.mjs +25 -0
  73. package/dist/index.d.mts +3 -0
  74. package/dist/index.d.ts +3 -0
  75. package/dist/index.js +1853 -0
  76. package/dist/index.mjs +25 -0
  77. package/dist/metafile-cjs.json +1 -0
  78. package/dist/metafile-esm.json +1 -0
  79. package/dist/modules/date-picker.context.d.mts +20 -0
  80. package/dist/modules/date-picker.context.d.ts +20 -0
  81. package/dist/modules/date-picker.context.js +33 -0
  82. package/dist/modules/date-picker.context.mjs +9 -0
  83. package/dist/modules/date-picker.hooks.d.mts +53 -0
  84. package/dist/modules/date-picker.hooks.d.ts +53 -0
  85. package/dist/modules/date-picker.hooks.js +337 -0
  86. package/dist/modules/date-picker.hooks.mjs +10 -0
  87. package/dist/modules/date-picker.locales.d.mts +27 -0
  88. package/dist/modules/date-picker.locales.d.ts +27 -0
  89. package/dist/modules/date-picker.locales.js +84 -0
  90. package/dist/modules/date-picker.locales.mjs +8 -0
  91. package/dist/modules/date-picker.props.d.mts +217 -0
  92. package/dist/modules/date-picker.props.d.ts +217 -0
  93. package/dist/modules/date-picker.props.js +181 -0
  94. package/dist/modules/date-picker.props.mjs +11 -0
  95. package/dist/utils/base.d.mts +20 -0
  96. package/dist/utils/base.d.ts +20 -0
  97. package/dist/utils/base.js +80 -0
  98. package/dist/utils/base.mjs +13 -0
  99. package/dist/utils/date.d.mts +19 -0
  100. package/dist/utils/date.d.ts +19 -0
  101. package/dist/utils/date.js +147 -0
  102. package/dist/utils/date.mjs +29 -0
  103. package/package.json +49 -0
package/dist/index.js ADDED
@@ -0,0 +1,1853 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/index.ts
32
+ var src_exports = {};
33
+ __export(src_exports, {
34
+ MpDatePicker: () => MpDatePicker
35
+ });
36
+ module.exports = __toCommonJS(src_exports);
37
+
38
+ // src/date-picker.tsx
39
+ var import_vue20 = require("vue");
40
+ var import_vue21 = require("vue");
41
+ var import_pixel3_input = require("@mekari/pixel3-input");
42
+ var import_pixel3_popover = require("@mekari/pixel3-popover");
43
+ var import_pixel3_icon = require("@mekari/pixel3-icon");
44
+
45
+ // src/calendar-panel.tsx
46
+ var import_vue17 = require("vue");
47
+ var import_vue18 = require("vue");
48
+
49
+ // src/components/calendar/table-date.tsx
50
+ var import_vue9 = require("vue");
51
+ var import_vue10 = require("vue");
52
+ var import_pixel3_button = require("@mekari/pixel3-button");
53
+
54
+ // src/components/parts/date.tsx
55
+ var import_vue = require("vue");
56
+ var import_vue2 = require("vue");
57
+ var import_recipes = require("@mekari/pixel3-styled-system/recipes");
58
+ var Date2 = (0, import_vue2.defineComponent)({
59
+ name: "Date",
60
+ props: {
61
+ status: {
62
+ type: String
63
+ },
64
+ isDisabled: {
65
+ type: Boolean,
66
+ default: false
67
+ },
68
+ isShowPinbar: {
69
+ type: Boolean,
70
+ default: false
71
+ }
72
+ },
73
+ setup(props, {
74
+ slots
75
+ }) {
76
+ return () => {
77
+ const dateItemClasses = (0, import_recipes.dateItemRecipe)({
78
+ status: props.status
79
+ });
80
+ const {
81
+ root,
82
+ pinbar
83
+ } = (0, import_recipes.pinbarSlotRecipe)();
84
+ return (0, import_vue.createVNode)("button", {
85
+ "disabled": props.isDisabled,
86
+ "data-status": props.status,
87
+ "class": dateItemClasses
88
+ }, [slots.default(), props.isShowPinbar && (0, import_vue.createVNode)("div", {
89
+ "class": root
90
+ }, [(0, import_vue.createVNode)("div", {
91
+ "class": pinbar
92
+ }, null)])]);
93
+ };
94
+ }
95
+ });
96
+
97
+ // src/components/parts/day.tsx
98
+ var import_vue3 = require("vue");
99
+ var import_vue4 = require("vue");
100
+ var import_recipes2 = require("@mekari/pixel3-styled-system/recipes");
101
+ var Day = (0, import_vue4.defineComponent)({
102
+ name: "Day",
103
+ setup(props, {
104
+ slots
105
+ }) {
106
+ return () => {
107
+ return (0, import_vue3.createVNode)("div", {
108
+ "class": (0, import_recipes2.dayItemRecipe)()
109
+ }, [slots.default()]);
110
+ };
111
+ }
112
+ });
113
+
114
+ // src/components/parts/month.tsx
115
+ var import_vue5 = require("vue");
116
+ var import_vue6 = require("vue");
117
+ var import_recipes3 = require("@mekari/pixel3-styled-system/recipes");
118
+ var Month = (0, import_vue6.defineComponent)({
119
+ name: "Month",
120
+ props: {
121
+ status: {
122
+ type: String
123
+ },
124
+ isDisabled: {
125
+ type: Boolean,
126
+ default: false
127
+ }
128
+ },
129
+ setup(props, {
130
+ slots
131
+ }) {
132
+ return () => {
133
+ const classes = (0, import_recipes3.monthItemRecipe)({
134
+ status: props.status
135
+ });
136
+ return (0, import_vue5.createVNode)("button", {
137
+ "disabled": props.isDisabled,
138
+ "data-status": props.status,
139
+ "class": classes
140
+ }, [slots.default()]);
141
+ };
142
+ }
143
+ });
144
+
145
+ // src/components/parts/year.tsx
146
+ var import_vue7 = require("vue");
147
+ var import_vue8 = require("vue");
148
+ var import_recipes4 = require("@mekari/pixel3-styled-system/recipes");
149
+ var YearItem = (0, import_vue8.defineComponent)({
150
+ name: "YearItem",
151
+ props: {
152
+ status: {
153
+ type: String
154
+ },
155
+ isDisabled: {
156
+ type: Boolean,
157
+ default: false
158
+ }
159
+ },
160
+ setup(props, {
161
+ slots
162
+ }) {
163
+ return () => {
164
+ const classes = (0, import_recipes4.yearItemRecipe)({
165
+ status: props.status
166
+ });
167
+ return (0, import_vue7.createVNode)("button", {
168
+ "disabled": props.isDisabled,
169
+ "data-status": props.status,
170
+ "class": classes
171
+ }, [slots.default()]);
172
+ };
173
+ }
174
+ });
175
+
176
+ // src/utils/base.ts
177
+ function chunk(arr, size) {
178
+ if (!Array.isArray(arr)) {
179
+ return [];
180
+ }
181
+ const result = [];
182
+ const len = arr.length;
183
+ let i = 0;
184
+ size = size || len;
185
+ while (i < len) {
186
+ result.push(arr.slice(i, i += size));
187
+ }
188
+ return result;
189
+ }
190
+ __name(chunk, "chunk");
191
+ var isObject = /* @__PURE__ */ __name((value) => {
192
+ return !!value && value.constructor === Object;
193
+ }, "isObject");
194
+ var assign = /* @__PURE__ */ __name((initial, override) => {
195
+ var _a;
196
+ if (!initial || !override)
197
+ return (_a = initial != null ? initial : override) != null ? _a : {};
198
+ return Object.entries({
199
+ ...initial,
200
+ ...override
201
+ }).reduce((acc, [key, value]) => {
202
+ return {
203
+ ...acc,
204
+ [key]: (() => {
205
+ if (isObject(initial[key]))
206
+ return assign(initial[key], value);
207
+ return value;
208
+ })()
209
+ };
210
+ }, {});
211
+ }, "assign");
212
+
213
+ // src/components/calendar/table-date.tsx
214
+ var import_recipes5 = require("@mekari/pixel3-styled-system/recipes");
215
+ var TableDate = (0, import_vue10.defineComponent)({
216
+ name: "TableDate",
217
+ props: {
218
+ days: {
219
+ type: Array,
220
+ default: () => []
221
+ },
222
+ dates: {
223
+ type: Array,
224
+ default: () => []
225
+ },
226
+ headerLabel: {
227
+ type: String,
228
+ default: ""
229
+ },
230
+ shortcutLabel: {
231
+ type: String,
232
+ default: ""
233
+ },
234
+ getDateStatus: {
235
+ type: Function,
236
+ default: () => {
237
+ }
238
+ },
239
+ isShowShortcut: {
240
+ type: Boolean
241
+ },
242
+ isRange: {
243
+ type: Boolean
244
+ },
245
+ isHideNotThisMonthDate: {
246
+ type: Boolean
247
+ }
248
+ },
249
+ emits: ["next", "previous", "changePanel", "select", "clickHeaderLabel", "mouseEnter", "mouseLeave"],
250
+ setup(props, {
251
+ emit
252
+ }) {
253
+ const {
254
+ headerRoot,
255
+ headerLabel,
256
+ dayWrapper,
257
+ dateItemRoot,
258
+ dateItemWrapper,
259
+ shortcutLabelWrapper
260
+ } = (0, import_recipes5.tableDateSlotRecipe)();
261
+ const getDates = (0, import_vue10.computed)(() => {
262
+ return chunk(props.dates, 7);
263
+ });
264
+ function onNextButton() {
265
+ emit("next");
266
+ }
267
+ __name(onNextButton, "onNextButton");
268
+ function onPreviousButton() {
269
+ emit("previous");
270
+ }
271
+ __name(onPreviousButton, "onPreviousButton");
272
+ function onSelectDate(date) {
273
+ emit("select", date);
274
+ }
275
+ __name(onSelectDate, "onSelectDate");
276
+ function onSelectToday() {
277
+ const today = /* @__PURE__ */ new Date();
278
+ onSelectDate(today);
279
+ }
280
+ __name(onSelectToday, "onSelectToday");
281
+ function getDateAttrs(date) {
282
+ const {
283
+ status,
284
+ isDisabled,
285
+ isShowPinbar
286
+ } = props.getDateStatus(date);
287
+ return {
288
+ status: isDisabled ? "disabled" : status,
289
+ isDisabled,
290
+ isShowPinbar,
291
+ onClick: () => onSelectDate(date),
292
+ onMouseenter: () => {
293
+ emit("mouseEnter", date);
294
+ },
295
+ onMouseleave: () => {
296
+ emit("mouseLeave");
297
+ },
298
+ style: {
299
+ visibility: props.isHideNotThisMonthDate && status === "notThisMonth" ? "hidden" : ""
300
+ }
301
+ };
302
+ }
303
+ __name(getDateAttrs, "getDateAttrs");
304
+ return () => {
305
+ return (0, import_vue9.createVNode)("div", null, [(0, import_vue9.createVNode)("div", {
306
+ "data-pixel-parts": "Header",
307
+ "class": headerRoot
308
+ }, [(0, import_vue9.createVNode)(import_pixel3_button.MpButton, {
309
+ "left-icon": "chevrons-left",
310
+ "variant": "ghost",
311
+ "size": "sm",
312
+ "onClick": onPreviousButton
313
+ }, null), (0, import_vue9.createVNode)("button", {
314
+ "class": headerLabel,
315
+ "onClick": () => emit("clickHeaderLabel")
316
+ }, [props.headerLabel]), (0, import_vue9.createVNode)(import_pixel3_button.MpButton, {
317
+ "right-icon": "chevrons-right",
318
+ "variant": "ghost",
319
+ "size": "sm",
320
+ "onClick": onNextButton
321
+ }, null)]), (0, import_vue9.createVNode)("div", {
322
+ "data-pixel-parts": "Content",
323
+ "class": dayWrapper
324
+ }, [props.days.map((day) => (0, import_vue9.createVNode)(Day, null, {
325
+ default: () => [(0, import_vue9.createTextVNode)(" "), day, (0, import_vue9.createTextVNode)(" ")]
326
+ }))]), (0, import_vue9.createVNode)("div", {
327
+ "data-pixel-parts": "Content",
328
+ "class": dateItemRoot
329
+ }, [getDates.value.map((dates, index) => (0, import_vue9.createVNode)("div", {
330
+ "class": dateItemWrapper,
331
+ "data-row-index": index
332
+ }, [dates.map((date) => (0, import_vue9.createVNode)(Date2, getDateAttrs(date), {
333
+ default: () => [(0, import_vue9.createTextVNode)(" "), date.getDate(), (0, import_vue9.createTextVNode)(" ")]
334
+ }))]))]), props.isShowShortcut && (0, import_vue9.createVNode)("div", {
335
+ "data-pixel-parts": "Shortcut",
336
+ "class": shortcutLabelWrapper
337
+ }, [(0, import_vue9.createVNode)(import_pixel3_button.MpButton, {
338
+ "variant": "ghost",
339
+ "onClick": onSelectToday
340
+ }, {
341
+ default: () => [props.shortcutLabel]
342
+ })])]);
343
+ };
344
+ }
345
+ });
346
+
347
+ // src/components/calendar/table-month.tsx
348
+ var import_vue11 = require("vue");
349
+ var import_vue12 = require("vue");
350
+ var import_pixel3_button2 = require("@mekari/pixel3-button");
351
+
352
+ // src/utils/date.ts
353
+ var import_date_fns = require("date-fns");
354
+ function createDate(y, M = 0, d = 1, h = 0, m = 0, s = 0, ms = 0) {
355
+ const date = new Date(y, M, d, h, m, s, ms);
356
+ if (y < 100 && y >= 0) {
357
+ date.setFullYear(y);
358
+ }
359
+ return date;
360
+ }
361
+ __name(createDate, "createDate");
362
+ function isValidDate(date) {
363
+ return date instanceof Date && !isNaN(date);
364
+ }
365
+ __name(isValidDate, "isValidDate");
366
+ function isValidRangeDate(date) {
367
+ return Array.isArray(date) && date.length === 2 && date.every(isValidDate) && date[0] <= date[1];
368
+ }
369
+ __name(isValidRangeDate, "isValidRangeDate");
370
+ function startOfMonth(value) {
371
+ const date = new Date(value);
372
+ date.setDate(1);
373
+ date.setHours(0, 0, 0, 0);
374
+ return date;
375
+ }
376
+ __name(startOfMonth, "startOfMonth");
377
+ function startOfWeek(value, firstDayOfWeek = 0) {
378
+ if (!(firstDayOfWeek >= 0 && firstDayOfWeek <= 6)) {
379
+ throw new RangeError("weekStartsOn must be between 0 and 6");
380
+ }
381
+ const date = new Date(value);
382
+ const day = date.getDay();
383
+ const diff = (day + 7 - firstDayOfWeek) % 7;
384
+ date.setDate(date.getDate() - diff);
385
+ date.setHours(0, 0, 0, 0);
386
+ return date;
387
+ }
388
+ __name(startOfWeek, "startOfWeek");
389
+ function getCalendar({
390
+ firstDayOfWeek,
391
+ year,
392
+ month
393
+ }) {
394
+ const arr = [];
395
+ const calendar = createDate(year, month, 0);
396
+ const lastDayInLastMonth = calendar.getDate();
397
+ const firstDayInLastMonth = lastDayInLastMonth - (calendar.getDay() + 7 - firstDayOfWeek) % 7;
398
+ for (let i = firstDayInLastMonth; i <= lastDayInLastMonth; i++) {
399
+ arr.push(createDate(year, month, i - lastDayInLastMonth));
400
+ }
401
+ calendar.setMonth(month + 1, 0);
402
+ const lastDayInCurrentMonth = calendar.getDate();
403
+ for (let i = 1; i <= lastDayInCurrentMonth; i++) {
404
+ arr.push(createDate(year, month, i));
405
+ }
406
+ const lastMonthLength = lastDayInLastMonth - firstDayInLastMonth + 1;
407
+ const nextMonthLength = 6 * 7 - lastMonthLength - lastDayInCurrentMonth;
408
+ for (let i = 1; i <= nextMonthLength; i++) {
409
+ arr.push(createDate(year, month, lastDayInCurrentMonth + i));
410
+ }
411
+ return arr;
412
+ }
413
+ __name(getCalendar, "getCalendar");
414
+ function getNextMonth(date) {
415
+ return (0, import_date_fns.addMonths)(date, 1);
416
+ }
417
+ __name(getNextMonth, "getNextMonth");
418
+ function getPreviousMonth(date) {
419
+ return (0, import_date_fns.addMonths)(date, -1);
420
+ }
421
+ __name(getPreviousMonth, "getPreviousMonth");
422
+ function addDays(value, days) {
423
+ const date = new Date(value);
424
+ date.setDate(date.getDate() + days);
425
+ return date;
426
+ }
427
+ __name(addDays, "addDays");
428
+ function isDateBetween(date, min, max) {
429
+ const _date = new Date(date);
430
+ const _min = new Date(min);
431
+ const _max = new Date(max);
432
+ return _date.getTime() >= _min.getTime() && _date.getTime() <= _max.getTime();
433
+ }
434
+ __name(isDateBetween, "isDateBetween");
435
+
436
+ // src/components/calendar/table-month.tsx
437
+ var import_recipes6 = require("@mekari/pixel3-styled-system/recipes");
438
+ var TableMonth = (0, import_vue12.defineComponent)({
439
+ name: "TableMonth",
440
+ props: {
441
+ calendar: {
442
+ type: Date,
443
+ default: () => /* @__PURE__ */ new Date()
444
+ },
445
+ months: {
446
+ type: Array,
447
+ default: () => []
448
+ },
449
+ headerLabel: {
450
+ type: String,
451
+ default: ""
452
+ },
453
+ shortcutLabel: {
454
+ type: String,
455
+ default: ""
456
+ },
457
+ getMonthStatus: {
458
+ type: Function,
459
+ default: () => {
460
+ }
461
+ },
462
+ isShowShortcut: {
463
+ type: Boolean
464
+ }
465
+ },
466
+ emits: ["next", "previous", "select", "clickHeaderLabel", "mouseEnter", "mouseLeave"],
467
+ setup(props, {
468
+ emit
469
+ }) {
470
+ const {
471
+ headerRoot,
472
+ headerLabel,
473
+ monthItemRoot,
474
+ monthItemWrapper,
475
+ shortcutLabelWrapper
476
+ } = (0, import_recipes6.tableMonthSlotRecipe)();
477
+ const getMonths = (0, import_vue12.computed)(() => {
478
+ return chunk(props.months, 3);
479
+ });
480
+ const getCalendarYear = (0, import_vue12.computed)(() => props.calendar.getFullYear());
481
+ function onNextButton() {
482
+ emit("next");
483
+ }
484
+ __name(onNextButton, "onNextButton");
485
+ function onPreviousButton() {
486
+ emit("previous", "previousMonth");
487
+ }
488
+ __name(onPreviousButton, "onPreviousButton");
489
+ function onSelectMonth(month, year) {
490
+ emit("select", month, year);
491
+ }
492
+ __name(onSelectMonth, "onSelectMonth");
493
+ function getMonthAttrs(month) {
494
+ const {
495
+ status,
496
+ isDisabled
497
+ } = props.getMonthStatus(month, getCalendarYear.value);
498
+ return {
499
+ status: isDisabled ? "disabled" : status,
500
+ isDisabled,
501
+ onClick: () => onSelectMonth(month, getCalendarYear.value),
502
+ onMouseenter: () => {
503
+ emit("mouseEnter", createDate(getCalendarYear.value, month));
504
+ },
505
+ onMouseleave: () => {
506
+ emit("mouseLeave");
507
+ }
508
+ };
509
+ }
510
+ __name(getMonthAttrs, "getMonthAttrs");
511
+ return () => {
512
+ return (0, import_vue11.createVNode)("div", null, [(0, import_vue11.createVNode)("div", {
513
+ "data-pixel-parts": "Header",
514
+ "class": headerRoot
515
+ }, [(0, import_vue11.createVNode)(import_pixel3_button2.MpButton, {
516
+ "left-icon": "chevrons-left",
517
+ "variant": "ghost",
518
+ "size": "sm",
519
+ "onClick": onPreviousButton
520
+ }, null), (0, import_vue11.createVNode)("button", {
521
+ "class": headerLabel,
522
+ "onClick": () => emit("clickHeaderLabel")
523
+ }, [props.headerLabel]), (0, import_vue11.createVNode)(import_pixel3_button2.MpButton, {
524
+ "right-icon": "chevrons-right",
525
+ "variant": "ghost",
526
+ "size": "sm",
527
+ "onClick": onNextButton
528
+ }, null)]), (0, import_vue11.createVNode)("div", {
529
+ "data-pixel-parts": "Content",
530
+ "class": monthItemRoot
531
+ }, [getMonths.value.map((data) => (0, import_vue11.createVNode)("div", {
532
+ "class": monthItemWrapper
533
+ }, [data.map((month) => (0, import_vue11.createVNode)(Month, getMonthAttrs(month.month), {
534
+ default: () => [" ", month.text, " "]
535
+ }))]))]), props.isShowShortcut && (0, import_vue11.createVNode)("div", {
536
+ "data-pixel-parts": "Shortcut",
537
+ "class": shortcutLabelWrapper
538
+ }, [(0, import_vue11.createVNode)(import_pixel3_button2.MpButton, {
539
+ "variant": "ghost",
540
+ "onClick": () => onSelectMonth((/* @__PURE__ */ new Date()).getMonth(), getCalendarYear.value)
541
+ }, {
542
+ default: () => [props.shortcutLabel]
543
+ })])]);
544
+ };
545
+ }
546
+ });
547
+
548
+ // src/components/calendar/table-year.tsx
549
+ var import_vue13 = require("vue");
550
+ var import_vue14 = require("vue");
551
+ var import_pixel3_button3 = require("@mekari/pixel3-button");
552
+ var import_recipes7 = require("@mekari/pixel3-styled-system/recipes");
553
+ var TableYear = (0, import_vue14.defineComponent)({
554
+ name: "TableYear",
555
+ props: {
556
+ years: {
557
+ type: Array,
558
+ default: () => []
559
+ },
560
+ headerLabel: {
561
+ type: String,
562
+ default: ""
563
+ },
564
+ shortcutLabel: {
565
+ type: String,
566
+ default: ""
567
+ },
568
+ getYearStatus: {
569
+ type: Function,
570
+ default: () => {
571
+ }
572
+ },
573
+ isShowShortcut: {
574
+ type: Boolean
575
+ }
576
+ },
577
+ emits: ["next", "previous", "select", "mouseEnter", "mouseLeave"],
578
+ setup(props, {
579
+ emit
580
+ }) {
581
+ const {
582
+ headerRoot,
583
+ headerLabel,
584
+ yearItemRoot,
585
+ yearItemWrapper,
586
+ shortcutLabelWrapper
587
+ } = (0, import_recipes7.tableYearSlotRecipe)();
588
+ const getYears = (0, import_vue14.computed)(() => {
589
+ return chunk(props.years, 4);
590
+ });
591
+ function onNextButton() {
592
+ const lastYear = props.years[props.years.length - 1];
593
+ emit("next", lastYear + 1);
594
+ }
595
+ __name(onNextButton, "onNextButton");
596
+ function onPreviousButton() {
597
+ const firstYear = props.years[0];
598
+ emit("previous", firstYear - 1);
599
+ }
600
+ __name(onPreviousButton, "onPreviousButton");
601
+ function onSelectYear(year) {
602
+ emit("select", year);
603
+ }
604
+ __name(onSelectYear, "onSelectYear");
605
+ function getMonthAttrs(year) {
606
+ const {
607
+ status,
608
+ isDisabled
609
+ } = props.getYearStatus(year);
610
+ return {
611
+ status: isDisabled ? "disabled" : status,
612
+ isDisabled,
613
+ onClick: () => onSelectYear(year),
614
+ onMouseenter: () => {
615
+ emit("mouseEnter", createDate(year));
616
+ },
617
+ onMouseleave: () => {
618
+ emit("mouseLeave");
619
+ }
620
+ };
621
+ }
622
+ __name(getMonthAttrs, "getMonthAttrs");
623
+ return () => {
624
+ return (0, import_vue13.createVNode)("div", null, [(0, import_vue13.createVNode)("div", {
625
+ "data-pixel-parts": "Header",
626
+ "class": headerRoot
627
+ }, [(0, import_vue13.createVNode)(import_pixel3_button3.MpButton, {
628
+ "left-icon": "chevrons-left",
629
+ "variant": "ghost",
630
+ "size": "sm",
631
+ "onClick": onPreviousButton
632
+ }, null), (0, import_vue13.createVNode)("button", {
633
+ "class": headerLabel
634
+ }, [props.headerLabel]), (0, import_vue13.createVNode)(import_pixel3_button3.MpButton, {
635
+ "right-icon": "chevrons-right",
636
+ "variant": "ghost",
637
+ "size": "sm",
638
+ "onClick": onNextButton
639
+ }, null)]), (0, import_vue13.createVNode)("div", {
640
+ "class": yearItemRoot
641
+ }, [getYears.value.map((data) => (0, import_vue13.createVNode)("div", {
642
+ "class": yearItemWrapper
643
+ }, [data.map((year) => (0, import_vue13.createVNode)(YearItem, getMonthAttrs(year), {
644
+ default: () => [(0, import_vue13.createTextVNode)(" "), year, (0, import_vue13.createTextVNode)(" ")]
645
+ }))]))]), props.isShowShortcut && (0, import_vue13.createVNode)("div", {
646
+ "class": shortcutLabelWrapper
647
+ }, [(0, import_vue13.createVNode)(import_pixel3_button3.MpButton, {
648
+ "variant": "ghost",
649
+ "onClick": () => onSelectYear((/* @__PURE__ */ new Date()).getFullYear())
650
+ }, {
651
+ default: () => [props.shortcutLabel]
652
+ })])]);
653
+ };
654
+ }
655
+ });
656
+
657
+ // src/calendar-panel.tsx
658
+ var import_date_fns3 = require("date-fns");
659
+
660
+ // src/composables/useCalendar.ts
661
+ var import_vue15 = require("vue");
662
+ var import_date_fns2 = require("date-fns");
663
+ function useCalendar(date, locale) {
664
+ const currentDate = (0, import_vue15.ref)(isValidDate(date) ? date : /* @__PURE__ */ new Date());
665
+ const currentPanel = (0, import_vue15.ref)("date");
666
+ const nextMonth = /* @__PURE__ */ __name(() => {
667
+ currentDate.value = getNextMonth(currentDate.value);
668
+ }, "nextMonth");
669
+ const previousMonth = /* @__PURE__ */ __name(() => {
670
+ currentDate.value = getPreviousMonth(currentDate.value);
671
+ }, "previousMonth");
672
+ const nextYear = /* @__PURE__ */ __name(() => {
673
+ currentDate.value = (0, import_date_fns2.addYears)(currentDate.value, 1);
674
+ }, "nextYear");
675
+ const previousYear = /* @__PURE__ */ __name(() => {
676
+ currentDate.value = (0, import_date_fns2.addYears)(currentDate.value, -1);
677
+ }, "previousYear");
678
+ const changeYear = /* @__PURE__ */ __name((year) => {
679
+ currentDate.value = (0, import_date_fns2.setYear)(currentDate.value, year);
680
+ }, "changeYear");
681
+ const changeMonth = /* @__PURE__ */ __name((month) => {
682
+ currentDate.value = (0, import_date_fns2.setMonth)(currentDate.value, month);
683
+ }, "changeMonth");
684
+ const getSplitDates = (0, import_vue15.computed)(() => {
685
+ return {
686
+ day: currentDate.value.getDay(),
687
+ month: currentDate.value.getMonth(),
688
+ year: currentDate.value.getFullYear(),
689
+ monthLabel: locale.value.months[currentDate.value.getMonth()]
690
+ };
691
+ });
692
+ const getDates = (0, import_vue15.computed)(() => {
693
+ const {
694
+ year,
695
+ month
696
+ } = getSplitDates.value;
697
+ const arr = getCalendar({
698
+ firstDayOfWeek: locale.value.formatLocale.firstDayOfWeek || 0,
699
+ year,
700
+ month
701
+ });
702
+ return arr;
703
+ });
704
+ const getMonths = (0, import_vue15.computed)(() => {
705
+ const monthsLocale = locale.value.formatLocale.monthsShort || locale.value.months;
706
+ const months = monthsLocale.map((text, month) => {
707
+ return {
708
+ text,
709
+ month
710
+ };
711
+ });
712
+ return months;
713
+ });
714
+ const getYears = (0, import_vue15.computed)(() => {
715
+ const {
716
+ year
717
+ } = getSplitDates.value;
718
+ const firstYear = Math.floor(year / 10) * 10;
719
+ const years = [];
720
+ for (let i = 0; i < 10; i++) {
721
+ years.push(firstYear + i);
722
+ }
723
+ return years;
724
+ });
725
+ const getLabel = (0, import_vue15.computed)(() => {
726
+ const {
727
+ year,
728
+ monthLabel
729
+ } = getSplitDates.value;
730
+ if (currentPanel.value === "date")
731
+ return `${monthLabel} ${year}`;
732
+ if (currentPanel.value === "month")
733
+ return `${year}`;
734
+ if (currentPanel.value === "year")
735
+ return `${getYears.value[0]} - ${getYears.value[9]}`;
736
+ return "";
737
+ });
738
+ function changePanel(value) {
739
+ currentPanel.value = value;
740
+ }
741
+ __name(changePanel, "changePanel");
742
+ function setPanelDate(date2) {
743
+ currentDate.value = date2;
744
+ }
745
+ __name(setPanelDate, "setPanelDate");
746
+ return {
747
+ currentDate,
748
+ currentPanel,
749
+ nextMonth,
750
+ previousMonth,
751
+ nextYear,
752
+ previousYear,
753
+ changeYear,
754
+ changeMonth,
755
+ getDates,
756
+ getMonths,
757
+ getYears,
758
+ getLabel,
759
+ getSplitDates,
760
+ changePanel,
761
+ setPanelDate
762
+ };
763
+ }
764
+ __name(useCalendar, "useCalendar");
765
+
766
+ // src/composables/useCalendarRange.ts
767
+ var import_vue16 = require("vue");
768
+ function useCalendarRange(props) {
769
+ const leftCalendar = startOfMonth(/* @__PURE__ */ new Date());
770
+ const rightCalendar = startOfMonth(getNextMonth(/* @__PURE__ */ new Date()));
771
+ const startDate = (0, import_vue16.ref)(props.modelValue[0]);
772
+ const endDate = (0, import_vue16.ref)(props.modelValue[1]);
773
+ const hoveredDate = (0, import_vue16.ref)();
774
+ const calendars = (0, import_vue16.ref)([leftCalendar, rightCalendar]);
775
+ const getCurrentDates = (0, import_vue16.computed)(() => {
776
+ if (startDate.value && !endDate.value)
777
+ return [startDate.value];
778
+ if (startDate.value && endDate.value)
779
+ return [startDate.value, endDate.value];
780
+ return [];
781
+ });
782
+ const calendarMinDiff = (0, import_vue16.computed)(() => {
783
+ const map = {
784
+ date: 1,
785
+ // type:date min 1 month
786
+ month: 1 * 12,
787
+ // type:month min 1 year
788
+ year: 10 * 12
789
+ // type:year min 10 year
790
+ };
791
+ return map[props.type] || map.date;
792
+ });
793
+ const calendarMaxDiff = (0, import_vue16.computed)(() => Infinity);
794
+ function setStartDate(date) {
795
+ startDate.value = date;
796
+ }
797
+ __name(setStartDate, "setStartDate");
798
+ function setEndDate(date) {
799
+ endDate.value = date;
800
+ }
801
+ __name(setEndDate, "setEndDate");
802
+ function setHoveredDate(date) {
803
+ hoveredDate.value = date;
804
+ }
805
+ __name(setHoveredDate, "setHoveredDate");
806
+ function getDateRangeStatus(cellDate) {
807
+ const status = {
808
+ inRange: false,
809
+ hoverInRange: false,
810
+ activeDragRange: false
811
+ };
812
+ const isInRange = /* @__PURE__ */ __name((data, range, fn = (v) => v.getTime()) => {
813
+ const value = fn(data);
814
+ let [min, max] = range.map(fn);
815
+ if (min > max) {
816
+ [min, max] = [max, min];
817
+ }
818
+ return value > min && value < max;
819
+ }, "isInRange");
820
+ if (getCurrentDates.value.length === 2 && isInRange(cellDate, getCurrentDates.value)) {
821
+ status.inRange = true;
822
+ }
823
+ if (getCurrentDates.value.length === 1 && hoveredDate.value && isInRange(cellDate, [getCurrentDates.value[0], hoveredDate.value])) {
824
+ status.hoverInRange = true;
825
+ }
826
+ if (getCurrentDates.value[0]) {
827
+ status.activeDragRange = true;
828
+ }
829
+ return status;
830
+ }
831
+ __name(getDateRangeStatus, "getDateRangeStatus");
832
+ function updateStartCalendar(value) {
833
+ updateCalendars([value, calendars.value[1]], 1);
834
+ }
835
+ __name(updateStartCalendar, "updateStartCalendar");
836
+ function updateEndCalendar(value) {
837
+ updateCalendars([calendars.value[0], value], 0);
838
+ }
839
+ __name(updateEndCalendar, "updateEndCalendar");
840
+ function updateCalendars(value, adjustIndex = 1) {
841
+ const gap = getCalendarGap(value);
842
+ if (gap) {
843
+ const calendar = new Date(value[adjustIndex]);
844
+ calendar.setMonth(calendar.getMonth() + (adjustIndex === 0 ? -gap : gap));
845
+ value[adjustIndex] = calendar;
846
+ }
847
+ calendars.value = value;
848
+ }
849
+ __name(updateCalendars, "updateCalendars");
850
+ function getCalendarGap(calendars2) {
851
+ const [calendarLeft, calendarRight] = calendars2;
852
+ const yearDiff = calendarRight.getFullYear() - calendarLeft.getFullYear();
853
+ const monthDiff = calendarRight.getMonth() - calendarLeft.getMonth();
854
+ const diff = yearDiff * 12 + monthDiff;
855
+ const min = calendarMinDiff.value;
856
+ const max = calendarMaxDiff.value;
857
+ if (diff < min) {
858
+ return min - diff;
859
+ }
860
+ if (diff > max) {
861
+ return max - diff;
862
+ }
863
+ return 0;
864
+ }
865
+ __name(getCalendarGap, "getCalendarGap");
866
+ return {
867
+ startDate,
868
+ endDate,
869
+ hoveredDate,
870
+ calendars,
871
+ getCurrentDates,
872
+ setStartDate,
873
+ setEndDate,
874
+ setHoveredDate,
875
+ getDateRangeStatus,
876
+ updateStartCalendar,
877
+ updateEndCalendar
878
+ };
879
+ }
880
+ __name(useCalendarRange, "useCalendarRange");
881
+
882
+ // src/modules/date-picker.props.ts
883
+ var calendarPanelProps = {
884
+ modelValue: {
885
+ type: Date
886
+ },
887
+ defaultValue: {
888
+ type: Date
889
+ },
890
+ type: {
891
+ type: String,
892
+ default: "date"
893
+ },
894
+ calendar: {
895
+ type: Date
896
+ },
897
+ isRange: {
898
+ type: Boolean,
899
+ default: false
900
+ },
901
+ isShowShortcut: {
902
+ type: Boolean,
903
+ default: true
904
+ },
905
+ disabledDate: {
906
+ type: Function,
907
+ default: () => {
908
+ }
909
+ },
910
+ disabledMonth: {
911
+ type: Function,
912
+ default: () => {
913
+ }
914
+ },
915
+ disabledYear: {
916
+ type: Function,
917
+ default: () => {
918
+ }
919
+ },
920
+ getDateStatus: {
921
+ type: Function,
922
+ default: void 0
923
+ },
924
+ getMonthStatus: {
925
+ type: Function,
926
+ default: void 0
927
+ },
928
+ getYearStatus: {
929
+ type: Function,
930
+ default: void 0
931
+ },
932
+ isHideNotThisMonthDate: {
933
+ type: Boolean
934
+ }
935
+ };
936
+ var calendarPanelRangeProps = {
937
+ ...calendarPanelProps,
938
+ modelValue: {
939
+ type: Array
940
+ }
941
+ };
942
+ var datePickerProps = {
943
+ id: {
944
+ type: String
945
+ },
946
+ modelValue: {
947
+ type: [String, Number, Date, Array]
948
+ },
949
+ type: calendarPanelProps.type,
950
+ valueType: {
951
+ type: String,
952
+ default: "date"
953
+ },
954
+ format: {
955
+ type: String
956
+ },
957
+ rangeSeparator: {
958
+ type: String,
959
+ default: " - "
960
+ },
961
+ placeholder: {
962
+ type: String,
963
+ default: ""
964
+ },
965
+ errorMessage: {
966
+ type: String,
967
+ default: "Format tanggal/waktu salah"
968
+ },
969
+ disabledMessage: {
970
+ type: String,
971
+ default: ""
972
+ },
973
+ lang: {
974
+ type: Object,
975
+ default: () => {
976
+ }
977
+ },
978
+ inputAttr: {
979
+ type: Object,
980
+ default: () => ({})
981
+ },
982
+ contentAttr: {
983
+ type: Object,
984
+ default: () => ({})
985
+ },
986
+ isRange: calendarPanelProps.isRange,
987
+ isReadOnly: {
988
+ type: Boolean,
989
+ default: false
990
+ },
991
+ isDisabled: {
992
+ type: Boolean,
993
+ default: false
994
+ },
995
+ isClearable: {
996
+ type: Boolean,
997
+ default: true
998
+ },
999
+ isInvalid: {
1000
+ type: Boolean,
1001
+ default: false
1002
+ },
1003
+ usePortal: {
1004
+ type: Boolean,
1005
+ default: false
1006
+ },
1007
+ isKeepAlive: {
1008
+ type: Boolean,
1009
+ default: false
1010
+ },
1011
+ isInline: {
1012
+ type: Boolean,
1013
+ default: false
1014
+ },
1015
+ isNotClickable: {
1016
+ type: Boolean,
1017
+ default: false
1018
+ },
1019
+ isDisableHeader: {
1020
+ type: Boolean,
1021
+ default: false
1022
+ },
1023
+ isShowShortcut: {
1024
+ type: Boolean,
1025
+ default: false
1026
+ },
1027
+ disabledDate: calendarPanelProps.disabledDate,
1028
+ disabledMonth: calendarPanelProps.disabledMonth,
1029
+ disabledYear: calendarPanelProps.disabledYear
1030
+ };
1031
+
1032
+ // src/modules/date-picker.context.ts
1033
+ var import_pixel3_utils = require("@mekari/pixel3-utils");
1034
+ var [DatePickerProvider, useDatePickerContext] = (0, import_pixel3_utils.usePixelCreateContext)("DatePickerContext");
1035
+
1036
+ // src/modules/date-picker.locales.ts
1037
+ var import_en = __toESM(require("date-format-parse/lib/locale/en"));
1038
+ var locales = {
1039
+ formatLocale: import_en.default,
1040
+ days: import_en.default.weekdaysMin,
1041
+ months: import_en.default.monthsShort,
1042
+ yearFormat: "YYYY",
1043
+ monthFormat: "MMM",
1044
+ monthBeforeYear: true,
1045
+ todayText: "Today",
1046
+ thisMonthText: "This Month",
1047
+ thisYearText: "This Year"
1048
+ };
1049
+ function getLocale(config) {
1050
+ if (!config) {
1051
+ return locales;
1052
+ }
1053
+ return assign(locales, config);
1054
+ }
1055
+ __name(getLocale, "getLocale");
1056
+
1057
+ // src/calendar-panel.tsx
1058
+ var import_recipes8 = require("@mekari/pixel3-styled-system/recipes");
1059
+ var CalendarPanel = (0, import_vue18.defineComponent)({
1060
+ name: "CalendarPanel",
1061
+ props: calendarPanelProps,
1062
+ emits: ["update:modelValue", "mouseEnter", "mouseLeave", "updateCalendar"],
1063
+ setup(props, {
1064
+ emit
1065
+ }) {
1066
+ const {
1067
+ locale
1068
+ } = useDatePickerContext();
1069
+ const restValue = (0, import_vue18.ref)(props.modelValue);
1070
+ const {
1071
+ currentDate: currentPanelDate,
1072
+ currentPanel,
1073
+ changePanel,
1074
+ getDates,
1075
+ getMonths,
1076
+ getYears,
1077
+ nextMonth,
1078
+ previousMonth,
1079
+ nextYear,
1080
+ previousYear,
1081
+ getLabel,
1082
+ changeMonth,
1083
+ changeYear
1084
+ } = useCalendar(props.modelValue || props.defaultValue, locale);
1085
+ function onSelectDate(date) {
1086
+ currentPanelDate.value = date;
1087
+ restValue.value = date;
1088
+ emit("update:modelValue", restValue.value);
1089
+ }
1090
+ __name(onSelectDate, "onSelectDate");
1091
+ function onSelectMonth(value, year) {
1092
+ if (props.type === "month") {
1093
+ const day = 1;
1094
+ const month = value;
1095
+ const date = new Date(year, month, day);
1096
+ restValue.value = date;
1097
+ emit("update:modelValue", restValue.value);
1098
+ return;
1099
+ }
1100
+ changeMonth(value);
1101
+ changePanel("date");
1102
+ }
1103
+ __name(onSelectMonth, "onSelectMonth");
1104
+ function onSelectYear(value) {
1105
+ if (props.type === "year") {
1106
+ const day = 1;
1107
+ const month = currentPanelDate.value.getMonth();
1108
+ const year = value;
1109
+ const date = new Date(year, month, day);
1110
+ restValue.value = date;
1111
+ emit("update:modelValue", restValue.value);
1112
+ return;
1113
+ }
1114
+ changeYear(value);
1115
+ changePanel("month");
1116
+ }
1117
+ __name(onSelectYear, "onSelectYear");
1118
+ function getDateStatus(date) {
1119
+ let status = "default";
1120
+ if ((0, import_date_fns3.isToday)(date))
1121
+ status = "today";
1122
+ if ((0, import_date_fns3.isEqual)(props.modelValue, date)) {
1123
+ status = "selected";
1124
+ }
1125
+ const isCurrentMonth = currentPanelDate.value.getMonth() === date.getMonth();
1126
+ if (!isCurrentMonth)
1127
+ status = "notThisMonth";
1128
+ if (props.getDateStatus && props.getDateStatus(date)) {
1129
+ status = props.getDateStatus(date);
1130
+ if (props.isHideNotThisMonthDate && !isCurrentMonth) {
1131
+ status = "notThisMonth";
1132
+ }
1133
+ }
1134
+ return {
1135
+ status,
1136
+ isDisabled: props.disabledDate ? props.disabledDate(date) : false,
1137
+ // TODO : Handle show pin bar
1138
+ isShowPinbar: false
1139
+ };
1140
+ }
1141
+ __name(getDateStatus, "getDateStatus");
1142
+ function getMonthStatus(month, year) {
1143
+ let status = "default";
1144
+ const isCurrentMonth = currentPanelDate.value.getMonth() === month && year === (/* @__PURE__ */ new Date()).getFullYear();
1145
+ if (isCurrentMonth)
1146
+ status = "today";
1147
+ if (props.type === "month" && props.modelValue) {
1148
+ const isMonthEqual = props.modelValue.getMonth() === month;
1149
+ const isYearEqual = props.modelValue.getFullYear() === currentPanelDate.value.getFullYear();
1150
+ const isSelected = isMonthEqual && isYearEqual;
1151
+ if (isSelected)
1152
+ status = "selected";
1153
+ }
1154
+ if (props.getMonthStatus && props.getMonthStatus(month, year)) {
1155
+ status = props.getMonthStatus(month, year);
1156
+ }
1157
+ return {
1158
+ status,
1159
+ isDisabled: props.disabledMonth(month, year) || false
1160
+ };
1161
+ }
1162
+ __name(getMonthStatus, "getMonthStatus");
1163
+ function getYearStatus(year) {
1164
+ var _a;
1165
+ let status = "default";
1166
+ const isCurrentYear = (/* @__PURE__ */ new Date()).getFullYear() === year;
1167
+ if (isCurrentYear)
1168
+ status = "today";
1169
+ const isSelected = ((_a = props.modelValue) == null ? void 0 : _a.getFullYear()) === year;
1170
+ if (isSelected)
1171
+ status = "selected";
1172
+ if (props.getYearStatus && props.getYearStatus(year)) {
1173
+ status = props.getYearStatus(year);
1174
+ }
1175
+ return {
1176
+ status,
1177
+ isDisabled: props.disabledYear(year) || false
1178
+ };
1179
+ }
1180
+ __name(getYearStatus, "getYearStatus");
1181
+ function initCalendar() {
1182
+ if (props.calendar) {
1183
+ const calendarDate = props.calendar;
1184
+ currentPanelDate.value = calendarDate;
1185
+ }
1186
+ }
1187
+ __name(initCalendar, "initCalendar");
1188
+ (0, import_vue18.watch)(() => props.modelValue, (newValue) => {
1189
+ if (newValue)
1190
+ restValue.value = newValue;
1191
+ }, {
1192
+ immediate: true
1193
+ });
1194
+ (0, import_vue18.watch)(() => props.type, (newValue) => {
1195
+ if (newValue)
1196
+ currentPanel.value = newValue;
1197
+ }, {
1198
+ immediate: true
1199
+ });
1200
+ (0, import_vue18.watch)(() => currentPanelDate.value, (newValue) => {
1201
+ if (newValue) {
1202
+ emit("updateCalendar", newValue);
1203
+ }
1204
+ });
1205
+ (0, import_vue18.watch)(() => props.calendar, () => {
1206
+ initCalendar();
1207
+ }, {
1208
+ immediate: true
1209
+ });
1210
+ return () => {
1211
+ if (currentPanel.value === "date") {
1212
+ return (0, import_vue17.createVNode)(TableDate, {
1213
+ "days": locale.value.days,
1214
+ "dates": getDates.value,
1215
+ "headerLabel": getLabel.value,
1216
+ "shortcutLabel": locale.value.todayText,
1217
+ "onNext": nextMonth,
1218
+ "onPrevious": previousMonth,
1219
+ "onClickHeaderLabel": () => changePanel("year"),
1220
+ "onSelect": onSelectDate,
1221
+ "getDateStatus": getDateStatus,
1222
+ "isShowShortcut": props.isShowShortcut,
1223
+ "onMouseEnter": (value) => emit("mouseEnter", value),
1224
+ "onMouseLeave": () => emit("mouseLeave"),
1225
+ "isHideNotThisMonthDate": props.isHideNotThisMonthDate
1226
+ }, null);
1227
+ }
1228
+ if (currentPanel.value === "month") {
1229
+ return (0, import_vue17.createVNode)(TableMonth, {
1230
+ "calendar": currentPanelDate.value,
1231
+ "months": getMonths.value,
1232
+ "headerLabel": getLabel.value,
1233
+ "shortcutLabel": locale.value.thisMonthText,
1234
+ "onNext": nextYear,
1235
+ "onPrevious": previousYear,
1236
+ "onClickHeaderLabel": () => changePanel("year"),
1237
+ "onSelect": onSelectMonth,
1238
+ "getMonthStatus": getMonthStatus,
1239
+ "onMouseEnter": (value) => emit("mouseEnter", value),
1240
+ "onMouseLeave": () => emit("mouseLeave"),
1241
+ "isShowShortcut": props.isShowShortcut
1242
+ }, null);
1243
+ }
1244
+ if (currentPanel.value === "year") {
1245
+ return (0, import_vue17.createVNode)(TableYear, {
1246
+ "years": getYears.value,
1247
+ "headerLabel": getLabel.value,
1248
+ "shortcutLabel": locale.value.thisYearText,
1249
+ "onNext": (year) => changeYear(year),
1250
+ "onPrevious": (year) => changeYear(year),
1251
+ "onSelect": onSelectYear,
1252
+ "getYearStatus": getYearStatus,
1253
+ "onMouseEnter": (value) => emit("mouseEnter", value),
1254
+ "onMouseLeave": () => emit("mouseLeave"),
1255
+ "isShowShortcut": props.isShowShortcut
1256
+ }, null);
1257
+ }
1258
+ };
1259
+ }
1260
+ });
1261
+ var CalendarPanelRange = (0, import_vue18.defineComponent)({
1262
+ name: "CalendarPanelRange",
1263
+ props: calendarPanelRangeProps,
1264
+ emits: ["update:modelValue"],
1265
+ setup(props, {
1266
+ emit
1267
+ }) {
1268
+ var _a;
1269
+ const {
1270
+ startDate,
1271
+ endDate,
1272
+ hoveredDate,
1273
+ calendars,
1274
+ setStartDate,
1275
+ setEndDate,
1276
+ setHoveredDate,
1277
+ getDateRangeStatus,
1278
+ getCurrentDates,
1279
+ updateStartCalendar,
1280
+ updateEndCalendar
1281
+ } = useCalendarRange(props);
1282
+ if ((_a = props.modelValue) == null ? void 0 : _a.length) {
1283
+ updateStartCalendar(props.modelValue[0]);
1284
+ updateEndCalendar(props.modelValue[1]);
1285
+ }
1286
+ function onSelectDate(date) {
1287
+ if (props.type === "week" || props.type === "biweek") {
1288
+ const gap = {
1289
+ week: 6,
1290
+ biweek: 13
1291
+ };
1292
+ const startDate2 = startOfWeek(date, getLocale().formatLocale.firstDayOfWeek);
1293
+ const endDate2 = addDays(startDate2, gap[props.type]);
1294
+ setStartDate(startDate2);
1295
+ setEndDate(endDate2);
1296
+ emit("update:modelValue", getCurrentDates.value);
1297
+ return;
1298
+ }
1299
+ if (startDate.value && endDate.value) {
1300
+ setStartDate(void 0);
1301
+ setEndDate(void 0);
1302
+ setStartDate(date);
1303
+ return;
1304
+ }
1305
+ if (startDate.value && !endDate.value) {
1306
+ setEndDate(date);
1307
+ if (startDate.value && endDate.value) {
1308
+ emit("update:modelValue", getCurrentDates.value);
1309
+ }
1310
+ return;
1311
+ }
1312
+ if (!startDate.value && !endDate.value) {
1313
+ setStartDate(date);
1314
+ if (startDate.value && endDate.value) {
1315
+ emit("update:modelValue", getCurrentDates.value);
1316
+ }
1317
+ return;
1318
+ }
1319
+ }
1320
+ __name(onSelectDate, "onSelectDate");
1321
+ function getDateStatus(date) {
1322
+ var _a2, _b;
1323
+ let status = "default";
1324
+ if ((0, import_date_fns3.isToday)(date))
1325
+ status = "today";
1326
+ const {
1327
+ inRange,
1328
+ hoverInRange
1329
+ } = getDateRangeStatus(date);
1330
+ if (inRange || hoverInRange) {
1331
+ status = "range";
1332
+ }
1333
+ if (startDate.value && !endDate.value && (0, import_date_fns3.isEqual)(hoveredDate.value, date)) {
1334
+ status = "selected";
1335
+ }
1336
+ if ((0, import_date_fns3.isEqual)(startDate.value, date)) {
1337
+ status = "selected";
1338
+ }
1339
+ if ((0, import_date_fns3.isEqual)(endDate.value, date)) {
1340
+ status = "selected";
1341
+ }
1342
+ if (props.type === "week") {
1343
+ if ((_a2 = props.modelValue) == null ? void 0 : _a2.length) {
1344
+ const startDate2 = startOfWeek(props.modelValue[0], getLocale().formatLocale.firstDayOfWeek);
1345
+ const endDate2 = addDays(startDate2, 6);
1346
+ if (isDateBetween(date, startDate2, endDate2)) {
1347
+ status = "weekSelectedMiddle";
1348
+ if ((0, import_date_fns3.isEqual)(startDate2, date))
1349
+ status = "weekSelectedStart";
1350
+ if ((0, import_date_fns3.isEqual)(endDate2, date))
1351
+ status = "weekSelectedEnd";
1352
+ }
1353
+ }
1354
+ if (hoveredDate.value) {
1355
+ const startDate2 = startOfWeek(hoveredDate.value, getLocale().formatLocale.firstDayOfWeek);
1356
+ const endDate2 = addDays(startDate2, 6);
1357
+ if (isDateBetween(date, startDate2, endDate2)) {
1358
+ status = "weekHoveredMiddle";
1359
+ if ((0, import_date_fns3.isEqual)(startDate2, date))
1360
+ status = "weekHoveredStart";
1361
+ if ((0, import_date_fns3.isEqual)(endDate2, date))
1362
+ status = "weekHoveredEnd";
1363
+ }
1364
+ }
1365
+ }
1366
+ if (props.type === "biweek") {
1367
+ const getBiweekDates = /* @__PURE__ */ __name((date2) => {
1368
+ const firstWeekStartDate = startOfWeek(date2, getLocale().formatLocale.firstDayOfWeek);
1369
+ const firstWeekEndDate = addDays(firstWeekStartDate, 6);
1370
+ const secondWeekStartDate = startOfWeek(addDays(firstWeekStartDate, 7), getLocale().formatLocale.firstDayOfWeek);
1371
+ const secondWeekEndDate = addDays(secondWeekStartDate, 6);
1372
+ return {
1373
+ firstWeekStartDate,
1374
+ firstWeekEndDate,
1375
+ secondWeekStartDate,
1376
+ secondWeekEndDate
1377
+ };
1378
+ }, "getBiweekDates");
1379
+ if ((_b = props.modelValue) == null ? void 0 : _b.length) {
1380
+ const {
1381
+ firstWeekStartDate,
1382
+ firstWeekEndDate,
1383
+ secondWeekStartDate,
1384
+ secondWeekEndDate
1385
+ } = getBiweekDates(props.modelValue[0]);
1386
+ if (isDateBetween(date, firstWeekStartDate, secondWeekEndDate)) {
1387
+ status = "weekSelectedMiddle";
1388
+ if ((0, import_date_fns3.isEqual)(firstWeekStartDate, date))
1389
+ status = "weekSelectedStart";
1390
+ if ((0, import_date_fns3.isEqual)(firstWeekEndDate, date))
1391
+ status = "weekSelectedEnd";
1392
+ if ((0, import_date_fns3.isEqual)(secondWeekStartDate, date))
1393
+ status = "weekSelectedStart";
1394
+ if ((0, import_date_fns3.isEqual)(secondWeekEndDate, date))
1395
+ status = "weekSelectedEnd";
1396
+ }
1397
+ }
1398
+ if (hoveredDate.value) {
1399
+ const {
1400
+ firstWeekStartDate,
1401
+ firstWeekEndDate,
1402
+ secondWeekStartDate,
1403
+ secondWeekEndDate
1404
+ } = getBiweekDates(hoveredDate.value);
1405
+ if (isDateBetween(date, firstWeekStartDate, secondWeekEndDate)) {
1406
+ status = "weekHoveredMiddle";
1407
+ if ((0, import_date_fns3.isEqual)(firstWeekStartDate, date))
1408
+ status = "weekHoveredStart";
1409
+ if ((0, import_date_fns3.isEqual)(firstWeekEndDate, date))
1410
+ status = "weekHoveredEnd";
1411
+ if ((0, import_date_fns3.isEqual)(secondWeekStartDate, date))
1412
+ status = "weekHoveredStart";
1413
+ if ((0, import_date_fns3.isEqual)(secondWeekEndDate, date))
1414
+ status = "weekHoveredEnd";
1415
+ }
1416
+ }
1417
+ }
1418
+ return status;
1419
+ }
1420
+ __name(getDateStatus, "getDateStatus");
1421
+ function getMonthStatus(month, year) {
1422
+ let status = "default";
1423
+ const parseToDate = createDate(year, month);
1424
+ const {
1425
+ inRange,
1426
+ hoverInRange
1427
+ } = getDateRangeStatus(parseToDate);
1428
+ if (inRange || hoverInRange) {
1429
+ status = "range";
1430
+ }
1431
+ if (startDate.value && !endDate.value && (0, import_date_fns3.isEqual)(hoveredDate.value, parseToDate)) {
1432
+ status = "selected";
1433
+ }
1434
+ if ((0, import_date_fns3.isEqual)(startDate.value, parseToDate)) {
1435
+ status = "selected";
1436
+ }
1437
+ if ((0, import_date_fns3.isEqual)(endDate.value, parseToDate)) {
1438
+ status = "selected";
1439
+ }
1440
+ return status;
1441
+ }
1442
+ __name(getMonthStatus, "getMonthStatus");
1443
+ function getYearStatus(year) {
1444
+ var _a2, _b, _c;
1445
+ let status = "default";
1446
+ const parseToDate = createDate(year);
1447
+ const {
1448
+ inRange,
1449
+ hoverInRange
1450
+ } = getDateRangeStatus(parseToDate);
1451
+ if (inRange || hoverInRange) {
1452
+ status = "range";
1453
+ }
1454
+ if (startDate.value && !endDate.value && ((_a2 = hoveredDate.value) == null ? void 0 : _a2.getFullYear()) === parseToDate.getFullYear()) {
1455
+ status = "selected";
1456
+ }
1457
+ if (((_b = startDate.value) == null ? void 0 : _b.getFullYear()) === parseToDate.getFullYear()) {
1458
+ status = "selected";
1459
+ }
1460
+ if (((_c = endDate.value) == null ? void 0 : _c.getFullYear()) === parseToDate.getFullYear()) {
1461
+ status = "selected";
1462
+ }
1463
+ return status;
1464
+ }
1465
+ __name(getYearStatus, "getYearStatus");
1466
+ return () => {
1467
+ const isWeekAndBiweek = props.type === "week" || props.type === "biweek";
1468
+ const classes = isWeekAndBiweek ? "" : (0, import_recipes8.calendarPanelRangeRecipe)();
1469
+ const calendarPanelAttrs = {
1470
+ isRange: true,
1471
+ type: props.type,
1472
+ isHideNotThisMonthDate: props.type === "week" || props.type === "biweek" ? false : true,
1473
+ isShowShortcut: false,
1474
+ getDateStatus,
1475
+ getMonthStatus,
1476
+ getYearStatus,
1477
+ "onUpdate:modelValue": (date) => onSelectDate(date),
1478
+ onMouseEnter: (date) => setHoveredDate(date),
1479
+ onMouseLeave: () => setHoveredDate(void 0)
1480
+ };
1481
+ const leftNode = (0, import_vue17.createVNode)(CalendarPanel, (0, import_vue17.mergeProps)({
1482
+ "data-pixel-parts": "CalendarPanelLeft"
1483
+ }, calendarPanelAttrs, {
1484
+ "onUpdateCalendar": (value) => updateStartCalendar(value),
1485
+ "calendar": calendars.value[0]
1486
+ }), null);
1487
+ const rightNode = (0, import_vue17.createVNode)(CalendarPanel, (0, import_vue17.mergeProps)({
1488
+ "data-pixel-parts": "CalendarPanelRight"
1489
+ }, calendarPanelAttrs, {
1490
+ "onUpdateCalendar": (value) => updateEndCalendar(value),
1491
+ "calendar": calendars.value[1]
1492
+ }), null);
1493
+ const weekAndBiweekNode = (0, import_vue17.createVNode)(CalendarPanel, (0, import_vue17.mergeProps)({
1494
+ "data-pixel-parts": "CalendarPanel"
1495
+ }, calendarPanelAttrs, {
1496
+ "onUpdateCalendar": (value) => updateStartCalendar(value),
1497
+ "calendar": props.modelValue[0],
1498
+ "type": "date"
1499
+ }), null);
1500
+ return (0, import_vue17.createVNode)("div", {
1501
+ "class": classes
1502
+ }, [isWeekAndBiweek ? weekAndBiweekNode : [leftNode, rightNode]]);
1503
+ };
1504
+ }
1505
+ });
1506
+
1507
+ // src/modules/date-picker.hooks.ts
1508
+ var import_vue19 = require("vue");
1509
+ var import_pixel3_utils2 = require("@mekari/pixel3-utils");
1510
+ var import_date_format_parse = require("date-format-parse");
1511
+ function useDatePicker(props, emit) {
1512
+ const getId = props.id || (0, import_pixel3_utils2.getUniqueId)("", "datepicker").value;
1513
+ const currentLabel = (0, import_vue19.ref)("");
1514
+ const isOutside = (0, import_vue19.ref)(true);
1515
+ const isPopoverOpen = (0, import_vue19.ref)(false);
1516
+ const isInnerInvalid = (0, import_vue19.ref)(false);
1517
+ const userInput = (0, import_vue19.ref)(null);
1518
+ const innerValueDate = (0, import_vue19.ref)();
1519
+ const isUseRange = (0, import_vue19.computed)(() => {
1520
+ if (props.isRange || props.type === "biweek" || props.type === "week")
1521
+ return true;
1522
+ return false;
1523
+ });
1524
+ const innerFormat = (0, import_vue19.computed)(() => {
1525
+ const format2 = {
1526
+ date: "DD-MM-YYYY",
1527
+ datetime: "DD-MM-YYYY HH:mm:ss",
1528
+ year: "YYYY",
1529
+ month: "YYYY-MM",
1530
+ time: "HH:mm:ss",
1531
+ week: "DD-MM-YYYY",
1532
+ biweek: "DD-MM-YYYY"
1533
+ };
1534
+ return props.format || format2[props.type] || format2.date;
1535
+ });
1536
+ const innerValue = (0, import_vue19.computed)(() => {
1537
+ if (isUseRange.value) {
1538
+ if (isValidRangeDate(props.modelValue)) {
1539
+ const startDate = valueToDate(props.modelValue[0]);
1540
+ const endDate = valueToDate(props.modelValue[1]);
1541
+ return [startDate, endDate];
1542
+ }
1543
+ return [];
1544
+ }
1545
+ return valueToDate(props.modelValue);
1546
+ });
1547
+ const text = (0, import_vue19.computed)(() => {
1548
+ if (userInput.value !== null)
1549
+ return userInput.value;
1550
+ if (!innerValue.value)
1551
+ return "";
1552
+ if (isUseRange.value) {
1553
+ if (!isValidRangeDate(innerValue.value))
1554
+ return "";
1555
+ } else {
1556
+ if (!isValidDate(innerValue.value))
1557
+ return "";
1558
+ }
1559
+ if (Array.isArray(innerValue.value)) {
1560
+ return innerValue.value.map((v) => formatDate(v)).join(props.rangeSeparator);
1561
+ }
1562
+ return formatDate(innerValue.value);
1563
+ });
1564
+ const locale = (0, import_vue19.computed)(() => {
1565
+ if (isObject(props.lang)) {
1566
+ return getLocale(props.lang);
1567
+ }
1568
+ return getLocale();
1569
+ });
1570
+ function onOpenPopover() {
1571
+ if (props.isReadOnly)
1572
+ return;
1573
+ isPopoverOpen.value = true;
1574
+ }
1575
+ __name(onOpenPopover, "onOpenPopover");
1576
+ function onClosePopover() {
1577
+ isPopoverOpen.value = false;
1578
+ }
1579
+ __name(onClosePopover, "onClosePopover");
1580
+ function onBlur() {
1581
+ onClosePopover();
1582
+ const inputEl = document.getElementById(`${getId}-control`);
1583
+ inputEl == null ? void 0 : inputEl.blur();
1584
+ }
1585
+ __name(onBlur, "onBlur");
1586
+ function handleForceFocusToInput() {
1587
+ const inputEl = document.getElementById(`${getId}-control`);
1588
+ inputEl == null ? void 0 : inputEl.focus();
1589
+ }
1590
+ __name(handleForceFocusToInput, "handleForceFocusToInput");
1591
+ function onClear() {
1592
+ isOutside.value = true;
1593
+ userInput.value = null;
1594
+ emit("update:modelValue", "");
1595
+ onBlur();
1596
+ }
1597
+ __name(onClear, "onClear");
1598
+ function onInputChange(e) {
1599
+ var _a;
1600
+ if (e) {
1601
+ const target = e.target;
1602
+ userInput.value = typeof e === "string" ? e : target.value;
1603
+ if (userInput.value === null)
1604
+ return;
1605
+ const text2 = ((_a = userInput.value) == null ? void 0 : _a.trim()) || "";
1606
+ if (text2 === "") {
1607
+ onClear();
1608
+ isInnerInvalid.value = false;
1609
+ return;
1610
+ }
1611
+ let date;
1612
+ if (isUseRange.value) {
1613
+ let arr = text2.split(props.rangeSeparator);
1614
+ if (arr.length !== 2) {
1615
+ arr = text2.split(props.rangeSeparator.trim());
1616
+ }
1617
+ date = arr.map((v) => parseDate(v.trim()));
1618
+ } else {
1619
+ date = parseDate(text2);
1620
+ }
1621
+ if (isValidValueAndNotDisabled(date)) {
1622
+ innerValueDate.value = date;
1623
+ (0, import_vue19.nextTick)(() => {
1624
+ isOutside.value = true;
1625
+ isInnerInvalid.value = false;
1626
+ onBlur();
1627
+ });
1628
+ } else {
1629
+ isInnerInvalid.value = true;
1630
+ emit("error", text2);
1631
+ }
1632
+ }
1633
+ }
1634
+ __name(onInputChange, "onInputChange");
1635
+ function onEmitModelValue(value) {
1636
+ userInput.value = null;
1637
+ innerValueDate.value = value;
1638
+ if (isUseRange.value) {
1639
+ const dates = value;
1640
+ const startDate = dateToValue(new Date(dates[0]));
1641
+ const endDate = dateToValue(new Date(dates[1]));
1642
+ emit("update:modelValue", [startDate, endDate]);
1643
+ } else {
1644
+ emit("update:modelValue", dateToValue(new Date(value)));
1645
+ }
1646
+ (0, import_vue19.nextTick)(() => {
1647
+ isOutside.value = true;
1648
+ onBlur();
1649
+ });
1650
+ }
1651
+ __name(onEmitModelValue, "onEmitModelValue");
1652
+ function parseDate(value) {
1653
+ const backupDate = /* @__PURE__ */ new Date();
1654
+ return (0, import_date_format_parse.parse)(value, innerFormat.value, {
1655
+ locale: locale.value.formatLocale,
1656
+ backupDate
1657
+ });
1658
+ }
1659
+ __name(parseDate, "parseDate");
1660
+ function formatDate(date) {
1661
+ return (0, import_date_format_parse.format)(date, innerFormat.value, {
1662
+ locale: locale.value.formatLocale
1663
+ });
1664
+ }
1665
+ __name(formatDate, "formatDate");
1666
+ function valueToDate(value) {
1667
+ switch (props.valueType) {
1668
+ case "date":
1669
+ return value instanceof Date ? new Date(value.getTime()) : /* @__PURE__ */ new Date(NaN);
1670
+ case "timestamp":
1671
+ return typeof value === "number" ? new Date(value) : /* @__PURE__ */ new Date(NaN);
1672
+ case "string":
1673
+ return typeof value === "string" ? parseDate(value) : /* @__PURE__ */ new Date(NaN);
1674
+ default:
1675
+ return typeof value === "string" ? parseDate(value) : /* @__PURE__ */ new Date(NaN);
1676
+ }
1677
+ }
1678
+ __name(valueToDate, "valueToDate");
1679
+ function dateToValue(date) {
1680
+ if (!isValidDate(date))
1681
+ return null;
1682
+ switch (props.valueType) {
1683
+ case "date":
1684
+ return date;
1685
+ case "timestamp":
1686
+ return date.getTime();
1687
+ case "string":
1688
+ return formatDate(date);
1689
+ default:
1690
+ return formatDate(date);
1691
+ }
1692
+ }
1693
+ __name(dateToValue, "dateToValue");
1694
+ function isValidValue(value) {
1695
+ if (isUseRange.value)
1696
+ return isValidRangeDate(value);
1697
+ return isValidDate(value);
1698
+ }
1699
+ __name(isValidValue, "isValidValue");
1700
+ function isValidValueAndNotDisabled(value) {
1701
+ if (!isValidValue(value))
1702
+ return false;
1703
+ const disabledDate = typeof props.disabledDate === "function" ? props.disabledDate : () => false;
1704
+ if (!Array.isArray(value)) {
1705
+ value = [value];
1706
+ }
1707
+ return value.every((v) => !disabledDate(v));
1708
+ }
1709
+ __name(isValidValueAndNotDisabled, "isValidValueAndNotDisabled");
1710
+ const rootAttrs = {
1711
+ style: {
1712
+ width: "100%",
1713
+ position: "relative"
1714
+ },
1715
+ onMouseenter: () => {
1716
+ isOutside.value = false;
1717
+ },
1718
+ onMouseleave: () => {
1719
+ isOutside.value = true;
1720
+ }
1721
+ };
1722
+ return {
1723
+ rootAttrs,
1724
+ isOutside,
1725
+ isPopoverOpen,
1726
+ currentLabel,
1727
+ userInput,
1728
+ innerFormat,
1729
+ innerValueDate,
1730
+ innerValue,
1731
+ isUseRange,
1732
+ onOpenPopover,
1733
+ onClosePopover,
1734
+ onClear,
1735
+ onInputChange,
1736
+ getId,
1737
+ onBlur,
1738
+ handleForceFocusToInput,
1739
+ text,
1740
+ locale,
1741
+ isInnerInvalid,
1742
+ onEmitModelValue
1743
+ };
1744
+ }
1745
+ __name(useDatePicker, "useDatePicker");
1746
+
1747
+ // src/date-picker.tsx
1748
+ var import_recipes9 = require("@mekari/pixel3-styled-system/recipes");
1749
+ function _isSlot(s) {
1750
+ return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !(0, import_vue20.isVNode)(s);
1751
+ }
1752
+ __name(_isSlot, "_isSlot");
1753
+ var MpDatePicker = (0, import_vue21.defineComponent)({
1754
+ name: "MpDatePicker",
1755
+ props: datePickerProps,
1756
+ emits: ["update:modelValue", "error"],
1757
+ setup(props, {
1758
+ emit
1759
+ }) {
1760
+ const {
1761
+ text,
1762
+ getId,
1763
+ innerValue,
1764
+ locale,
1765
+ isOutside,
1766
+ isPopoverOpen,
1767
+ isInnerInvalid,
1768
+ isUseRange,
1769
+ onOpenPopover,
1770
+ onBlur,
1771
+ onClear,
1772
+ onInputChange,
1773
+ onEmitModelValue
1774
+ } = useDatePicker(props, emit);
1775
+ DatePickerProvider({
1776
+ rootProps: props,
1777
+ locale
1778
+ });
1779
+ return () => {
1780
+ const {
1781
+ root,
1782
+ popoverContent
1783
+ } = (0, import_recipes9.datePickerSlotRecipe)();
1784
+ const inputNode = (0, import_vue20.createVNode)(import_pixel3_input.MpInputGroup, null, {
1785
+ default: () => [(0, import_vue20.createVNode)(import_pixel3_input.MpInput, {
1786
+ "id": getId,
1787
+ "placeholder": props.placeholder,
1788
+ "isClearable": props.isClearable,
1789
+ "isDisabled": props.isDisabled,
1790
+ "isInvalid": props.isInvalid || isInnerInvalid.value,
1791
+ "isReadOnly": props.isReadOnly,
1792
+ "modelValue": text.value,
1793
+ "onInput": onInputChange,
1794
+ "onClear": onClear,
1795
+ "onFocus": () => onOpenPopover(),
1796
+ "onBlur": (e) => {
1797
+ if (isOutside.value) {
1798
+ onBlur();
1799
+ return;
1800
+ }
1801
+ const target = e.target;
1802
+ target.focus();
1803
+ }
1804
+ }, null), (0, import_vue20.createVNode)(import_pixel3_input.MpInputRightAddon, null, {
1805
+ default: () => [(0, import_vue20.createVNode)(import_pixel3_icon.MpIcon, {
1806
+ "name": "calendar"
1807
+ }, null)]
1808
+ })]
1809
+ });
1810
+ const calendarPanelAttrs = {
1811
+ type: props.type,
1812
+ "onUpdate:modelValue": onEmitModelValue,
1813
+ disabledDate: props.disabledDate,
1814
+ disabledMonth: props.disabledMonth,
1815
+ disabledYear: props.disabledYear
1816
+ };
1817
+ const panelNode = isUseRange.value ? (0, import_vue20.createVNode)(CalendarPanelRange, (0, import_vue20.mergeProps)(calendarPanelAttrs, {
1818
+ "modelValue": innerValue.value
1819
+ }), null) : (0, import_vue20.createVNode)(CalendarPanel, (0, import_vue20.mergeProps)(calendarPanelAttrs, {
1820
+ "modelValue": innerValue.value
1821
+ }), null);
1822
+ const withPopover = (0, import_vue20.createVNode)(import_pixel3_popover.MpPopover, {
1823
+ "id": getId,
1824
+ "isManual": true,
1825
+ "isOpen": isPopoverOpen.value,
1826
+ "isKeepAlive": props.isKeepAlive,
1827
+ "usePortal": props.usePortal
1828
+ }, {
1829
+ default: () => [(0, import_vue20.createVNode)(import_pixel3_popover.MpPopoverTrigger, null, _isSlot(inputNode) ? inputNode : {
1830
+ default: () => [inputNode]
1831
+ }), (0, import_vue20.createVNode)(import_pixel3_popover.MpPopoverContent, {
1832
+ "class": popoverContent,
1833
+ "style": {
1834
+ width: props.isRange ? "590px" : ""
1835
+ },
1836
+ "onMouseenter": () => isOutside.value = false,
1837
+ "onMouseleave": () => isOutside.value = true
1838
+ }, _isSlot(panelNode) ? panelNode : {
1839
+ default: () => [panelNode]
1840
+ })]
1841
+ });
1842
+ return (0, import_vue20.createVNode)("div", {
1843
+ "class": root,
1844
+ "onMouseenter": () => isOutside.value = false,
1845
+ "onMouseleave": () => isOutside.value = true
1846
+ }, [props.isInline ? panelNode : withPopover]);
1847
+ };
1848
+ }
1849
+ });
1850
+ // Annotate the CommonJS export names for ESM import in node:
1851
+ 0 && (module.exports = {
1852
+ MpDatePicker
1853
+ });