@privyid/persona 0.15.0 → 0.16.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 (53) hide show
  1. package/dist/components/avatar/Avatar.vue.d.ts +3 -3
  2. package/dist/components/button/Button.vue.d.ts +3 -3
  3. package/dist/components/calendar/Calendar.vue +162 -38
  4. package/dist/components/calendar/Calendar.vue.d.ts +63 -10
  5. package/dist/components/calendar/adapter/adapter.d.ts +8 -2
  6. package/dist/components/calendar/adapter/adapter.mjs +38 -1
  7. package/dist/components/calendar/adapter/date.mjs +10 -8
  8. package/dist/components/calendar/adapter/month.mjs +11 -8
  9. package/dist/components/calendar/adapter/year.mjs +7 -7
  10. package/dist/components/checkbox/Checkbox.vue.d.ts +6 -6
  11. package/dist/components/contextual-bar/ContextualBar.vue.d.ts +2 -2
  12. package/dist/components/cropper/Cropper.vue.d.ts +2 -2
  13. package/dist/components/datepicker/Datepicker.vue +37 -3
  14. package/dist/components/datepicker/Datepicker.vue.d.ts +50 -3
  15. package/dist/components/dropdown/Dropdown.vue.d.ts +5 -5
  16. package/dist/components/filterbar/pinned/PinnedSelect.vue.d.ts +2 -2
  17. package/dist/components/filterbar/pinned/PinnedToggle.vue.d.ts +6 -6
  18. package/dist/components/input/Input.vue.d.ts +1 -1
  19. package/dist/components/input-file/InputFile.vue.d.ts +2 -2
  20. package/dist/components/input-group/InputGroup.vue.d.ts +1 -1
  21. package/dist/components/input-pin/InputPin.vue.d.ts +1 -1
  22. package/dist/components/input-range/InputRange.vue +4 -4
  23. package/dist/components/input-range/InputRange.vue.d.ts +4 -4
  24. package/dist/components/label/Label.vue.d.ts +2 -2
  25. package/dist/components/modal/Modal.vue.d.ts +2 -2
  26. package/dist/components/nav/Nav.vue +29 -7
  27. package/dist/components/nav/Nav.vue.d.ts +18 -0
  28. package/dist/components/nav/NavItem.vue +9 -1
  29. package/dist/components/nav/NavItem.vue.d.ts +9 -0
  30. package/dist/components/nav/NavItemDropdown.vue.d.ts +4 -4
  31. package/dist/components/nav/NavSubItem.vue +1 -1
  32. package/dist/components/navbar/Navbar.vue +6 -2
  33. package/dist/components/pdf-object/PdfObject.vue +18 -8
  34. package/dist/components/pdf-object/PdfObject.vue.d.ts +4 -4
  35. package/dist/components/pdf-object/utils/position.mjs +9 -3
  36. package/dist/components/pdf-text/PdfText.vue.d.ts +2 -2
  37. package/dist/components/pdf-viewer/PdfViewer.vue +1 -1
  38. package/dist/components/pdf-viewer/PdfViewer.vue.d.ts +2 -2
  39. package/dist/components/radio/Radio.vue.d.ts +4 -4
  40. package/dist/components/select/Select.vue.d.ts +3 -3
  41. package/dist/components/sidebar/Sidebar.vue +3 -1
  42. package/dist/components/sidebar/SidebarNav.vue +95 -4
  43. package/dist/components/sidebar/SidebarNav.vue.d.ts +29 -0
  44. package/dist/components/sidebar-menu/SidebarMenu.vue +4 -1
  45. package/dist/components/sidebar-menu/index.d.ts +3 -0
  46. package/dist/components/signature-text/SignatureText.vue.d.ts +1 -1
  47. package/dist/components/text/Text.vue +2 -1
  48. package/dist/components/toast/ToastContainer.vue +4 -0
  49. package/dist/components/toast/index.d.ts +1 -0
  50. package/dist/components/toggle/Toggle.vue.d.ts +6 -6
  51. package/dist/components/tour/TourDialog.vue.d.ts +2 -2
  52. package/dist/module.json +1 -1
  53. package/package.json +8 -5
@@ -22,7 +22,7 @@ declare const _default: import("vue-demi").DefineComponent<{
22
22
  default: string;
23
23
  };
24
24
  imgClass: {
25
- type: (StringConstructor | ArrayConstructor | ObjectConstructor)[];
25
+ type: (StringConstructor | ObjectConstructor | ArrayConstructor)[];
26
26
  default: undefined;
27
27
  };
28
28
  }, {
@@ -51,7 +51,7 @@ declare const _default: import("vue-demi").DefineComponent<{
51
51
  default: string;
52
52
  };
53
53
  imgClass: {
54
- type: (StringConstructor | ArrayConstructor | ObjectConstructor)[];
54
+ type: (StringConstructor | ObjectConstructor | ArrayConstructor)[];
55
55
  default: undefined;
56
56
  };
57
57
  }>> & {
@@ -60,9 +60,9 @@ declare const _default: import("vue-demi").DefineComponent<{
60
60
  }, {
61
61
  name: string;
62
62
  variant: TypeVariant;
63
+ size: SizeVariant;
63
64
  src: string;
64
65
  fallbackSrc: string;
65
- size: SizeVariant;
66
66
  imgClass: string | Record<string, any> | unknown[];
67
67
  }, {}>;
68
68
  export default _default;
@@ -55,10 +55,10 @@ declare const _default: import("vue-demi").DefineComponent<{
55
55
  };
56
56
  }>>, {
57
57
  variant: StyleVariant;
58
- size: SizeVariant;
59
- href: string;
60
- color: ColorVariant;
61
58
  icon: boolean;
59
+ color: ColorVariant;
60
+ href: string;
61
+ size: SizeVariant;
62
62
  pill: boolean;
63
63
  }, {}>;
64
64
  export default _default;
@@ -1,12 +1,12 @@
1
1
  <template>
2
- <Card
2
+ <p-card
3
3
  data-testid="calendar"
4
4
  class="calendar"
5
5
  element="div"
6
6
  :viewmode="viewmode"
7
7
  :class="classNames">
8
8
  <div class="calendar__nav">
9
- <Button
9
+ <p-button
10
10
  data-testid="calendar-prev"
11
11
  variant="solid"
12
12
  icon
@@ -14,18 +14,18 @@
14
14
  :readonly="disabled || readonly"
15
15
  @click="prev">
16
16
  <IconBack />
17
- </Button>
17
+ </p-button>
18
18
 
19
- <Button
19
+ <p-button
20
20
  data-testid="calendar-title"
21
21
  class="calendar__nav-title"
22
22
  variant="solid"
23
23
  :readonly="disabled || readonly"
24
24
  @click="changeMode(1)">
25
25
  {{ title }}
26
- </Button>
26
+ </p-button>
27
27
 
28
- <Button
28
+ <p-button
29
29
  data-testid="calendar-next"
30
30
  variant="solid"
31
31
  icon
@@ -33,7 +33,7 @@
33
33
  :disabled="!canNext"
34
34
  @click="next">
35
35
  <IconNext />
36
- </Button>
36
+ </p-button>
37
37
  </div>
38
38
 
39
39
  <Transition
@@ -47,41 +47,57 @@
47
47
  <template
48
48
  v-for="(item, i) in items"
49
49
  :key="i">
50
- <Button
50
+ <p-button
51
51
  variant="solid"
52
52
  data-testid="calendar-item"
53
53
  :readonly="item.readonly || disabled || readonly"
54
54
  :active="item.active"
55
55
  :disabled="item.disabled"
56
- @click="selectItem(item)">
56
+ :class="{
57
+ 'calendar__item--in-range': isInRange(item),
58
+ 'calendar__item--head': item.head,
59
+ 'calendar__item--tail': item.tail,
60
+ }"
61
+ @click="selectItem(item)"
62
+ @mouseover="setHover(item)">
57
63
  {{ item.text }}
58
- </Button>
64
+ </p-button>
59
65
  </template>
60
66
  </div>
61
67
  </Transition>
62
- </Card>
68
+ </p-card>
63
69
  </template>
64
70
 
65
71
  <script>
66
- import Button from "../button/Button.vue";
67
- import Card from "../card/Card.vue";
68
- import IconNext from "@carbon/icons-vue/lib/chevron--right/20";
69
- import IconBack from "@carbon/icons-vue/lib/chevron--left/20";
72
+ import pButton from "../button/Button.vue";
73
+ import pCard from "../card/Card.vue";
74
+ import IconNext from "@privyid/persona-icon/vue/chevron-right/20.vue";
75
+ import IconBack from "@privyid/persona-icon/vue/chevron-left/20.vue";
70
76
  import {
71
77
  defineComponent,
72
78
  ref,
73
79
  computed,
74
- watch,
75
- toRef
80
+ watch
76
81
  } from "vue-demi";
77
82
  import {
78
- CalendarFormat
83
+ CalendarFormat,
84
+ validateDuration,
85
+ parseDuration
79
86
  } from "./adapter/adapter";
80
87
  import DateAdapter from "./adapter/date";
81
88
  import MonthAdapter from "./adapter/month";
82
89
  import YearAdapter from "./adapter/year";
83
- import { startOfMonth } from "date-fns";
84
- import { useVModel } from "../input";
90
+ import {
91
+ isWithinInterval,
92
+ startOfMonth,
93
+ min as minDate,
94
+ max as maxDate,
95
+ minTime as MIN_TIME,
96
+ maxTime as MAX_TIME,
97
+ add,
98
+ sub
99
+ } from "date-fns";
100
+ import { syncRef } from "@vueuse/core";
85
101
  const Adapters = {
86
102
  date: DateAdapter,
87
103
  month: MonthAdapter,
@@ -89,14 +105,21 @@ const Adapters = {
89
105
  };
90
106
  export default defineComponent({
91
107
  components: {
92
- // eslint-disable-next-line vue/no-reserved-component-names
93
- Button,
94
- Card,
108
+ pButton,
109
+ pCard,
95
110
  IconNext,
96
111
  IconBack
97
112
  },
98
113
  props: {
99
114
  modelValue: {
115
+ type: [Date, Array],
116
+ default: void 0
117
+ },
118
+ start: {
119
+ type: Date,
120
+ default: void 0
121
+ },
122
+ end: {
100
123
  type: Date,
101
124
  default: void 0
102
125
  },
@@ -108,30 +131,81 @@ export default defineComponent({
108
131
  type: Boolean,
109
132
  default: void 0
110
133
  },
111
- max: {
134
+ min: {
112
135
  type: Date,
113
- default: void 0
136
+ default: () => new Date(MIN_TIME)
114
137
  },
115
- min: {
138
+ max: {
116
139
  type: Date,
117
- default: void 0
140
+ default: () => new Date(MAX_TIME)
118
141
  },
119
142
  mode: {
120
143
  type: String,
121
144
  default: "date"
145
+ },
146
+ range: {
147
+ type: Boolean,
148
+ default: false
149
+ },
150
+ minRange: {
151
+ type: String,
152
+ default: void 0,
153
+ validator(value) {
154
+ return validateDuration(value);
155
+ }
156
+ },
157
+ maxRange: {
158
+ type: String,
159
+ default: void 0,
160
+ validator(value) {
161
+ return validateDuration(value);
162
+ }
122
163
  }
123
164
  },
124
- emits: ["update:modelValue", "change"],
165
+ emits: [
166
+ "update:modelValue",
167
+ "update:start",
168
+ "update:end",
169
+ "change"
170
+ ],
125
171
  setup(props, { emit }) {
126
172
  const viewmode = ref(props.mode);
127
173
  const transition = ref("slide-left");
128
- const cursor = ref(startOfMonth(props.modelValue ?? /* @__PURE__ */ new Date()));
129
- const model = useVModel(props);
174
+ const localStart = ref(Array.isArray(props.modelValue) ? props.modelValue[0] : props.start ?? props.modelValue);
175
+ const localEnd = ref(Array.isArray(props.modelValue) ? props.modelValue[1] : props.end ?? props.modelValue);
176
+ const vStart = computed({
177
+ get() {
178
+ return Array.isArray(props.modelValue) ? props.modelValue[0] : props.start ?? props.modelValue;
179
+ },
180
+ set(value) {
181
+ emit("update:start", value);
182
+ }
183
+ });
184
+ const vEnd = computed({
185
+ get() {
186
+ return Array.isArray(props.modelValue) ? props.modelValue[1] : props.end ?? props.modelValue;
187
+ },
188
+ set(value) {
189
+ emit("update:end", value);
190
+ }
191
+ });
192
+ const cursor = ref(startOfMonth(localStart.value ?? /* @__PURE__ */ new Date()));
193
+ const hover = ref();
194
+ const minRange = computed(() => parseDuration(props.minRange));
195
+ const maxRange = computed(() => parseDuration(props.maxRange));
196
+ const isTempLock = computed(() => props.range && localStart.value && !localEnd.value);
197
+ const min = computed(() => {
198
+ return isTempLock.value ? maxDate([add(localStart.value, minRange.value ?? {}), props.min]) : props.min;
199
+ });
200
+ const max = computed(() => {
201
+ return isTempLock.value && maxRange.value ? minDate([add(localStart.value, maxRange.value), props.max]) : sub(props.max, minRange.value ?? {});
202
+ });
130
203
  const context = {
131
204
  cursor,
132
- model,
133
- min: toRef(props, "min"),
134
- max: toRef(props, "max")
205
+ start: localStart,
206
+ end: localEnd,
207
+ min,
208
+ max
135
209
  };
136
210
  const adapter = computed(() => {
137
211
  return Adapters[viewmode.value];
@@ -154,6 +228,8 @@ export default defineComponent({
154
228
  result.push("calendar--disabled");
155
229
  if (props.readonly)
156
230
  result.push("calendar--readonly");
231
+ if (props.range)
232
+ result.push("calendar--range");
157
233
  return result;
158
234
  });
159
235
  function next() {
@@ -174,13 +250,44 @@ export default defineComponent({
174
250
  }
175
251
  function selectItem(item) {
176
252
  if (viewmode.value === props.mode) {
177
- model.value = item.value;
178
- emit("change", item.value);
253
+ if (props.range && (localStart.value && !localEnd.value)) {
254
+ localEnd.value = maxDate([localStart.value, item.value]);
255
+ localStart.value = minDate([localStart.value, item.value]);
256
+ } else {
257
+ localStart.value = item.value;
258
+ localEnd.value = void 0;
259
+ }
179
260
  } else {
180
261
  cursor.value = item.value;
181
262
  changeMode(-1);
182
263
  }
183
264
  }
265
+ function setHover(item) {
266
+ if (props.range && !item.readonly && !item.disabled)
267
+ hover.value = item.value;
268
+ }
269
+ function isInRange(item) {
270
+ if (props.range && localStart.value && (localEnd.value || hover.value) && !item.readonly && !item.active) {
271
+ return isWithinInterval(item.value, {
272
+ start: minDate([localStart.value, localEnd.value ?? hover.value]),
273
+ end: maxDate([localStart.value, localEnd.value ?? hover.value])
274
+ });
275
+ }
276
+ return false;
277
+ }
278
+ syncRef(localStart, vStart);
279
+ syncRef(localEnd, vEnd);
280
+ watch([localStart, localEnd], ([startVal, endVal]) => {
281
+ if (props.range) {
282
+ if (startVal && endVal) {
283
+ emit("update:modelValue", [startVal, endVal]);
284
+ emit("change", [startVal, endVal]);
285
+ }
286
+ } else {
287
+ emit("update:modelValue", startVal);
288
+ emit("change", startVal);
289
+ }
290
+ });
184
291
  watch(() => props.mode, (value) => {
185
292
  const newIndex = CalendarFormat.indexOf(value);
186
293
  const currentIndex = CalendarFormat.indexOf(viewmode.value);
@@ -206,7 +313,9 @@ export default defineComponent({
206
313
  next,
207
314
  prev,
208
315
  changeMode,
209
- selectItem
316
+ selectItem,
317
+ isInRange,
318
+ setHover
210
319
  };
211
320
  }
212
321
  });
@@ -245,6 +354,11 @@ export default defineComponent({
245
354
  @apply text-muted;
246
355
  @apply dark:text-dark-muted;
247
356
  }
357
+
358
+ &.calendar__item--in-range {
359
+ @apply bg-info rounded-none;
360
+ @apply dark:bg-dark-info;
361
+ }
248
362
  }
249
363
 
250
364
  &[readonly] {
@@ -254,7 +368,7 @@ export default defineComponent({
254
368
 
255
369
  .calendar__items {
256
370
  &[viewmode="date"] {
257
- @apply grid grid-cols-7 gap-1;
371
+ @apply grid grid-cols-7 gap-y-1;
258
372
 
259
373
  .btn--md {
260
374
  @apply p-1 md:p-2;
@@ -267,13 +381,23 @@ export default defineComponent({
267
381
 
268
382
  &[viewmode="month"],
269
383
  &[viewmode="year"] {
270
- @apply grid grid-cols-4 gap-1;
384
+ @apply grid grid-cols-4 gap-y-1;
271
385
  .btn--md {
272
386
  @apply px-3;
273
387
  }
274
388
  }
275
389
  }
276
390
 
391
+ &--range {
392
+ .calendar__item--head:not(.calendar__item--tail) {
393
+ @apply rounded-r-none;
394
+ }
395
+
396
+ .calendar__item--tail:not(.calendar__item--head) {
397
+ @apply rounded-l-none;
398
+ }
399
+ }
400
+
277
401
  &--disabled {
278
402
  @apply opacity-50;
279
403
  }
@@ -3,6 +3,14 @@ import { CalendarItem } from './adapter/adapter';
3
3
  type TransitionMode = 'slide-left' | 'slide-right' | 'zoom-in' | 'zoom-out';
4
4
  declare const _default: import("vue-demi").DefineComponent<{
5
5
  modelValue: {
6
+ type: PropType<Date | [Date, Date]>;
7
+ default: undefined;
8
+ };
9
+ start: {
10
+ type: DateConstructor;
11
+ default: undefined;
12
+ };
13
+ end: {
6
14
  type: DateConstructor;
7
15
  default: undefined;
8
16
  };
@@ -14,18 +22,32 @@ declare const _default: import("vue-demi").DefineComponent<{
14
22
  type: BooleanConstructor;
15
23
  default: undefined;
16
24
  };
17
- max: {
25
+ min: {
18
26
  type: DateConstructor;
19
- default: undefined;
27
+ default: () => Date;
20
28
  };
21
- min: {
29
+ max: {
22
30
  type: DateConstructor;
23
- default: undefined;
31
+ default: () => Date;
24
32
  };
25
33
  mode: {
26
34
  type: PropType<"date" | "month" | "year">;
27
35
  default: string;
28
36
  };
37
+ range: {
38
+ type: BooleanConstructor;
39
+ default: boolean;
40
+ };
41
+ minRange: {
42
+ type: StringConstructor;
43
+ default: undefined;
44
+ validator(value: string): boolean;
45
+ };
46
+ maxRange: {
47
+ type: StringConstructor;
48
+ default: undefined;
49
+ validator(value: string): boolean;
50
+ };
29
51
  }, {
30
52
  transition: import("vue-demi").Ref<TransitionMode>;
31
53
  title: import("vue-demi").ComputedRef<string>;
@@ -102,8 +124,18 @@ declare const _default: import("vue-demi").DefineComponent<{
102
124
  prev: () => void;
103
125
  changeMode: (step?: number) => void;
104
126
  selectItem: (item: CalendarItem) => void;
105
- }, unknown, {}, {}, import("vue-demi").ComponentOptionsMixin, import("vue-demi").ComponentOptionsMixin, ("change" | "update:modelValue")[], "change" | "update:modelValue", import("vue-demi").VNodeProps & import("vue-demi").AllowedComponentProps & import("vue-demi").ComponentCustomProps, Readonly<import("vue-demi").ExtractPropTypes<{
127
+ isInRange: (item: CalendarItem) => boolean;
128
+ setHover: (item: CalendarItem) => void;
129
+ }, unknown, {}, {}, import("vue-demi").ComponentOptionsMixin, import("vue-demi").ComponentOptionsMixin, ("change" | "update:modelValue" | "update:start" | "update:end")[], "change" | "update:modelValue" | "update:start" | "update:end", import("vue-demi").VNodeProps & import("vue-demi").AllowedComponentProps & import("vue-demi").ComponentCustomProps, Readonly<import("vue-demi").ExtractPropTypes<{
106
130
  modelValue: {
131
+ type: PropType<Date | [Date, Date]>;
132
+ default: undefined;
133
+ };
134
+ start: {
135
+ type: DateConstructor;
136
+ default: undefined;
137
+ };
138
+ end: {
107
139
  type: DateConstructor;
108
140
  default: undefined;
109
141
  };
@@ -115,27 +147,48 @@ declare const _default: import("vue-demi").DefineComponent<{
115
147
  type: BooleanConstructor;
116
148
  default: undefined;
117
149
  };
118
- max: {
150
+ min: {
119
151
  type: DateConstructor;
120
- default: undefined;
152
+ default: () => Date;
121
153
  };
122
- min: {
154
+ max: {
123
155
  type: DateConstructor;
124
- default: undefined;
156
+ default: () => Date;
125
157
  };
126
158
  mode: {
127
159
  type: PropType<"date" | "month" | "year">;
128
160
  default: string;
129
161
  };
162
+ range: {
163
+ type: BooleanConstructor;
164
+ default: boolean;
165
+ };
166
+ minRange: {
167
+ type: StringConstructor;
168
+ default: undefined;
169
+ validator(value: string): boolean;
170
+ };
171
+ maxRange: {
172
+ type: StringConstructor;
173
+ default: undefined;
174
+ validator(value: string): boolean;
175
+ };
130
176
  }>> & {
131
177
  onChange?: ((...args: any[]) => any) | undefined;
132
178
  "onUpdate:modelValue"?: ((...args: any[]) => any) | undefined;
179
+ "onUpdate:start"?: ((...args: any[]) => any) | undefined;
180
+ "onUpdate:end"?: ((...args: any[]) => any) | undefined;
133
181
  }, {
182
+ start: Date;
183
+ end: Date;
134
184
  min: Date;
135
185
  max: Date;
136
- modelValue: Date;
186
+ modelValue: Date | [Date, Date];
137
187
  disabled: boolean;
138
188
  readonly: boolean;
139
189
  mode: "date" | "month" | "year";
190
+ range: boolean;
191
+ minRange: string;
192
+ maxRange: string;
140
193
  }, {}>;
141
194
  export default _default;
@@ -1,16 +1,20 @@
1
1
  import { Ref } from 'vue-demi';
2
+ import { Duration } from 'date-fns';
2
3
  export interface CalendarItem {
3
4
  value: Date;
4
5
  text: string;
5
6
  disabled: boolean;
6
7
  readonly: boolean;
7
8
  active: boolean;
9
+ head: boolean;
10
+ tail: boolean;
8
11
  }
9
12
  export interface CalendarContext {
10
13
  cursor: Ref<Date>;
11
- model: Ref<Date>;
12
- max: Ref<Date | undefined>;
14
+ start: Ref<Date>;
15
+ end: Ref<Date>;
13
16
  min: Ref<Date | undefined>;
17
+ max: Ref<Date | undefined>;
14
18
  }
15
19
  export interface CalendarAdapter {
16
20
  getItems: (this: this, context: CalendarContext) => CalendarItem[];
@@ -30,3 +34,5 @@ export declare function defineAdapter(adapter: CalendarAdapter): CalendarAdapter
30
34
  * @param formatStr date format
31
35
  */
32
36
  export declare function formatDate(date: Date, formatStr: string): string;
37
+ export declare function validateDuration(duration?: string): boolean;
38
+ export declare function parseDuration(duration?: string): Duration | undefined;
@@ -1,7 +1,10 @@
1
- import { format } from "date-fns";
1
+ import {
2
+ format
3
+ } from "date-fns";
2
4
  import id from "date-fns/locale/id/index";
3
5
  import en from "date-fns/locale/en-US/index";
4
6
  import { getLang } from "../../global/context.mjs";
7
+ import { chunk } from "lodash-es";
5
8
  const localePacks = { en, id };
6
9
  export const CalendarFormat = [
7
10
  "date",
@@ -14,3 +17,37 @@ export function defineAdapter(adapter) {
14
17
  export function formatDate(date, formatStr) {
15
18
  return format(date, formatStr, { locale: localePacks[getLang()] });
16
19
  }
20
+ const DURATION_SUFFIX = {
21
+ Y: "years",
22
+ y: "years",
23
+ M: "months",
24
+ W: "weeks",
25
+ w: "weeks",
26
+ D: "days",
27
+ d: "days",
28
+ H: "hours",
29
+ h: "hours",
30
+ m: "minutes",
31
+ s: "seconds"
32
+ };
33
+ const DURATION_REGEX = /((-?\d+)([DHMWYdhmswy]))/;
34
+ export function validateDuration(duration) {
35
+ if (!duration)
36
+ return false;
37
+ const match = duration.split(DURATION_REGEX).filter(Boolean);
38
+ const segment = chunk(match, 3);
39
+ return segment.every(([text]) => text.match(DURATION_REGEX));
40
+ }
41
+ export function parseDuration(duration) {
42
+ if (!duration)
43
+ return;
44
+ const match = duration.split(DURATION_REGEX).filter(Boolean);
45
+ const segment = chunk(match, 3);
46
+ const result = {};
47
+ for (const item of segment) {
48
+ const key = DURATION_SUFFIX[item[2]];
49
+ const value = Number.parseInt(item[1]);
50
+ result[key] = value + (result[key] ?? 0);
51
+ }
52
+ return result;
53
+ }
@@ -10,9 +10,7 @@ import {
10
10
  subMonths,
11
11
  isAfter,
12
12
  isBefore,
13
- isWithinInterval,
14
- minTime,
15
- maxTime
13
+ isWithinInterval
16
14
  } from "date-fns";
17
15
  import {
18
16
  defineAdapter,
@@ -27,16 +25,18 @@ function getInterval(date) {
27
25
  };
28
26
  }
29
27
  export default defineAdapter({
30
- getItems({ cursor, model, min, max }) {
28
+ getItems({ cursor, start, end, min, max }) {
31
29
  const dates = eachDayOfInterval(getInterval(cursor.value)).map((date) => {
32
- const start = min.value ?? minTime;
33
- const end = max.value ?? maxTime;
34
- const isDisabled = !isSameMonth(cursor.value, date) || !isWithinInterval(date, { start, end });
30
+ const isDisabled = !isSameMonth(cursor.value, date) || !isWithinInterval(date, { start: min.value, end: max.value });
31
+ const isHead = isSameDay(start.value, date);
32
+ const isTail = isSameDay(end.value, date);
35
33
  return {
36
34
  value: date,
37
35
  text: date.getDate().toString(),
38
36
  disabled: isDisabled,
39
- active: isSameDay(model.value, date),
37
+ head: isHead,
38
+ tail: isTail,
39
+ active: isHead || isTail,
40
40
  readonly: false
41
41
  };
42
42
  });
@@ -46,6 +46,8 @@ export default defineAdapter({
46
46
  text: formatDate(item.value, "EEEEEE"),
47
47
  disabled: false,
48
48
  readonly: true,
49
+ head: false,
50
+ tail: false,
49
51
  active: false
50
52
  };
51
53
  });
@@ -6,12 +6,13 @@ import {
6
6
  isBefore,
7
7
  isSameMonth,
8
8
  isWithinInterval,
9
- maxTime,
10
- minTime,
11
9
  startOfYear,
12
10
  subYears
13
11
  } from "date-fns";
14
- import { defineAdapter, formatDate } from "./adapter.mjs";
12
+ import {
13
+ defineAdapter,
14
+ formatDate
15
+ } from "./adapter.mjs";
15
16
  function getInterval(date) {
16
17
  const start = startOfYear(date);
17
18
  const end = endOfYear(date);
@@ -21,17 +22,19 @@ function getInterval(date) {
21
22
  };
22
23
  }
23
24
  export default defineAdapter({
24
- getItems({ cursor, model, min, max }) {
25
+ getItems({ cursor, start, end, min, max }) {
25
26
  return eachMonthOfInterval(getInterval(cursor.value)).map((date) => {
26
- const start = min.value ?? minTime;
27
- const end = max.value ?? maxTime;
28
- const isDisabled = !isSameMonth(start, date) && !isSameMonth(end, date) && !isWithinInterval(date, { start, end });
27
+ const isDisabled = !isSameMonth(min.value, date) && !isSameMonth(max.value, date) && !isWithinInterval(date, { start: min.value, end: max.value });
28
+ const isHead = isSameMonth(start.value, date);
29
+ const isTail = isSameMonth(end.value, date);
29
30
  return {
30
31
  value: date,
31
32
  text: formatDate(date, "MMM"),
32
33
  disabled: isDisabled,
33
34
  readonly: false,
34
- active: isSameMonth(model.value, date)
35
+ head: isHead,
36
+ tail: isTail,
37
+ active: isHead || isTail
35
38
  };
36
39
  });
37
40
  },