vueless 0.0.331 → 0.0.332

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.
@@ -6,15 +6,31 @@ import { computed, watchEffect } from "vue";
6
6
  import defaultConfig from "./config.js";
7
7
  import { POSITION } from "../composables/useAutoPosition.js";
8
8
 
9
- export default function useAttrs(props, { isShownMenu, isTop, isRight }) {
9
+ export default function useAttrs(props, { isShownMenu, isTop, isRight, isPeriod }) {
10
10
  const { config, getAttrs, isSystemKey, hasSlotContent, isCVA } = useUI(
11
11
  defaultConfig,
12
12
  () => props.config,
13
13
  );
14
14
  const attrs = {};
15
15
 
16
+ const variantKeys = [
17
+ "rangeInputFirst",
18
+ "rangeInputLast",
19
+ "periodButtonActive",
20
+ "periodDateWeekList",
21
+ "periodDateMonthList",
22
+ "periodDateQuarterList",
23
+ "periodDateYearList",
24
+ "firstPeriodGridDate",
25
+ "firstPeriodListDate",
26
+ "lastPeriodGridDate",
27
+ "lastPeriodListDate",
28
+ "periodDateActive",
29
+ "periodDateInRange",
30
+ ];
31
+
16
32
  for (const key in defaultConfig) {
17
- if (isSystemKey(key)) continue;
33
+ if (isSystemKey(key) && variantKeys.includes(key)) continue;
18
34
 
19
35
  const classes = computed(() => {
20
36
  let value = config.value[key];
@@ -66,24 +82,6 @@ export default function useAttrs(props, { isShownMenu, isTop, isRight }) {
66
82
  }));
67
83
  }
68
84
 
69
- if (key === "periodButton") {
70
- attrs[`${key}Attrs`] = (classes) => {
71
- return getAttrs("periodButton", { classes }).value;
72
- };
73
- }
74
-
75
- if (key === "periodDateList") {
76
- attrs[`${key}Attrs`] = (classes) => {
77
- return getAttrs("periodDateList", { classes }).value;
78
- };
79
- }
80
-
81
- if (key === "periodDate") {
82
- attrs[`${key}Attrs`] = (classes) => {
83
- return getAttrs("periodDate", { classes }).value;
84
- };
85
- }
86
-
87
85
  if (key === "calendar") {
88
86
  // This watcher rewrites default calendar locales with datepicker range locales
89
87
  // Watcher will not rewrite custom calendar locales
@@ -123,8 +121,128 @@ export default function useAttrs(props, { isShownMenu, isTop, isRight }) {
123
121
  }
124
122
  }
125
123
 
124
+ for (const key of variantKeys) {
125
+ if (key === "rangeInputFirst") {
126
+ attrs[`${key}Attrs`] = computed(() => ({
127
+ ...attrs.rangeInputAttrs.value,
128
+ class: cx([attrs.rangeInputAttrs.value.class, config.value.rangeInputFirst]),
129
+ }));
130
+ }
131
+
132
+ if (key === "rangeInputLast") {
133
+ attrs[`${key}Attrs`] = computed(() => ({
134
+ ...attrs.rangeInputAttrs.value,
135
+ class: cx([attrs.rangeInputAttrs.value.class, config.value.rangeInputLast]),
136
+ }));
137
+ }
138
+
139
+ if (key === "periodButtonActive") {
140
+ attrs[`${key}Attrs`] = computed(() => ({
141
+ ...attrs.periodButtonAttrs.value,
142
+ class: cx([attrs.periodButtonAttrs.value.class, config.value.periodButtonActive]),
143
+ }));
144
+ }
145
+
146
+ if (key === "periodDateWeekList") {
147
+ attrs[`${key}Attrs`] = computed(() => ({
148
+ ...attrs.periodDateListAttrs.value,
149
+ class: cx([attrs.periodDateListAttrs.value.class, config.value.periodDateWeekList]),
150
+ }));
151
+ }
152
+
153
+ if (key === "periodDateMonthList") {
154
+ attrs[`${key}Attrs`] = computed(() => ({
155
+ ...attrs.periodDateListAttrs.value,
156
+ class: cx([attrs.periodDateListAttrs.value.class, config.value.periodDateMonthList]),
157
+ }));
158
+ }
159
+
160
+ if (key === "periodDateQuarterList") {
161
+ attrs[`${key}Attrs`] = computed(() => ({
162
+ ...attrs.periodDateListAttrs.value,
163
+ class: cx([attrs.periodDateListAttrs.value.class, config.value.periodDateQuarterList]),
164
+ }));
165
+ }
166
+
167
+ if (key === "periodDateYearList") {
168
+ attrs[`${key}Attrs`] = computed(() => ({
169
+ ...attrs.periodDateListAttrs.value,
170
+ class: cx([attrs.periodDateListAttrs.value.class, config.value.periodDateYearList]),
171
+ }));
172
+ }
173
+
174
+ if (key === "periodDateActive") {
175
+ attrs[`${key}Attrs`] = computed(() => ({
176
+ ...attrs.periodDateAttrs.value,
177
+ class: cx([attrs.periodDateAttrs.value.class, config.value.periodDateActive]),
178
+ }));
179
+ }
180
+
181
+ if (key === "periodDateInRange") {
182
+ attrs[`${key}Attrs`] = computed(() => ({
183
+ ...attrs.periodDateAttrs.value,
184
+ class: cx([attrs.periodDateAttrs.value.class, config.value.periodDateInRange]),
185
+ }));
186
+ }
187
+
188
+ if (
189
+ [
190
+ "firstPeriodGridDate",
191
+ "firstPeriodListDate",
192
+ "lastPeriodGridDate",
193
+ "lastPeriodListDate",
194
+ ].includes(key)
195
+ ) {
196
+ attrs[`${key}Attrs`] = computed(() => ({
197
+ ...attrs.periodDateAttrs.value,
198
+ class: cx([
199
+ attrs.periodDateAttrs.value.class,
200
+ config.value.edgePeriodDate,
201
+ config.value[key],
202
+ ]),
203
+ }));
204
+ }
205
+ }
206
+
207
+ const periodDateListAttrs = computed(() => {
208
+ if (isPeriod.value.week) return attrs.periodDateWeekListAttrs.value;
209
+ if (isPeriod.value.month) return attrs.periodDateMonthListAttrs.value;
210
+ if (isPeriod.value.quarter) return attrs.periodDateQuarterListAttrs.value;
211
+ if (isPeriod.value.year) return attrs.periodDateYearListAttrs.value;
212
+
213
+ return attrs.periodDateListAttrs.value;
214
+ });
215
+
216
+ console.log(attrs.customRangeDescription);
217
+
218
+ const periodDatesMenuAttrs = computed(() => ({
219
+ periodsRowAttrs: attrs.periodsRowAttrs.value,
220
+ periodButtonAttrs: attrs.periodButtonAttrs.value,
221
+ periodButtonActiveAttrs: attrs.periodButtonActiveAttrs.value,
222
+ periodDateAttrs: attrs.periodDateAttrs.value,
223
+ periodDateActiveAttrs: attrs.periodDateActiveAttrs.value,
224
+ periodDateInRangeAttrs: attrs.periodDateInRangeAttrs.value,
225
+ periodDateListAttrs: periodDateListAttrs.value,
226
+ rangeSwitchWrapperAttrs: attrs.rangeSwitchWrapperAttrs.value,
227
+ rangeSwitchButtonAttrs: attrs.rangeSwitchButtonAttrs.value,
228
+ rangeSwitchTitleAttrs: attrs.rangeSwitchTitleAttrs.value,
229
+ lastPeriodGridDateAttrs: attrs.lastPeriodGridDateAttrs.value,
230
+ firstPeriodGridDateAttrs: attrs.firstPeriodGridDateAttrs.value,
231
+ lastPeriodListDateAttrs: attrs.lastPeriodListDateAttrs.value,
232
+ firstPeriodListDateAttrs: attrs.firstPeriodListDateAttrs.value,
233
+ customRangeDescription: attrs.customRangeDescriptionAttrs.value,
234
+ }));
235
+
236
+ const rangeInputsAttrs = computed(() => ({
237
+ rangeInputFirstAttrs: attrs.rangeInputFirstAttrs.value,
238
+ rangeInputLastAttrs: attrs.rangeInputLastAttrs.value,
239
+ }));
240
+
126
241
  return {
127
242
  ...attrs,
243
+ periodDatesMenuAttrs,
244
+ rangeInputsAttrs,
245
+ periodDateListAttrs,
128
246
  config,
129
247
  hasSlotContent,
130
248
  };
@@ -0,0 +1,63 @@
1
+ import { computed } from "vue";
2
+ import { useLocale as useGlobalLocale } from "../composables/useLocale.js";
3
+
4
+ import { merge } from "lodash-es";
5
+ import { getSortedLocale } from "../ui.form-calendar/utilDate.js";
6
+
7
+ import { LOCALE_TYPE } from "../ui.form-calendar/constants.js";
8
+ import { UDatePickerRange } from "./constants.js";
9
+ import defaultConfig from "./config.js";
10
+
11
+ export function useLocale(props) {
12
+ const { tm } = useGlobalLocale();
13
+
14
+ const i18nGlobal = tm(UDatePickerRange);
15
+
16
+ const currentLocale = computed(() => merge(defaultConfig.i18n, i18nGlobal, props.config.i18n));
17
+
18
+ const locale = computed(() => {
19
+ const { months, weekdays } = currentLocale.value;
20
+
21
+ // formatted locale
22
+ return {
23
+ ...currentLocale.value,
24
+ months: {
25
+ shorthand: getSortedLocale(months.shorthand, LOCALE_TYPE.month),
26
+ longhand: getSortedLocale(months.longhand, LOCALE_TYPE.month),
27
+ },
28
+ weekdays: {
29
+ shorthand: getSortedLocale(weekdays.shorthand, LOCALE_TYPE.day),
30
+ longhand: getSortedLocale(weekdays.longhand, LOCALE_TYPE.day),
31
+ },
32
+ };
33
+ });
34
+
35
+ const userFormatLocale = computed(() => {
36
+ const { months, weekdays } = currentLocale.value;
37
+
38
+ const monthsLonghand =
39
+ Boolean(props.config.i18n?.months?.userFormat) || Boolean(i18nGlobal?.months?.userFormat)
40
+ ? months.userFormat
41
+ : months.longhand;
42
+
43
+ const weekdaysLonghand =
44
+ Boolean(props.config.i18n?.weekdays?.userFormat) || Boolean(i18nGlobal?.weekdays?.userFormat)
45
+ ? weekdays.userFormat
46
+ : weekdays.longhand;
47
+
48
+ // formatted locale
49
+ return {
50
+ ...currentLocale,
51
+ months: {
52
+ shorthand: getSortedLocale(months.shorthand, LOCALE_TYPE.month),
53
+ longhand: getSortedLocale(monthsLonghand, LOCALE_TYPE.month),
54
+ },
55
+ weekdays: {
56
+ shorthand: getSortedLocale(weekdays.shorthand, LOCALE_TYPE.day),
57
+ longhand: getSortedLocale(weekdaysLonghand, LOCALE_TYPE.day),
58
+ },
59
+ };
60
+ });
61
+
62
+ return { userFormatLocale, locale };
63
+ }
@@ -0,0 +1,86 @@
1
+ import { computed } from "vue";
2
+
3
+ import useBreakpoint from "../composables/useBreakpoint.js";
4
+
5
+ import { isSameMonth } from "../ui.form-calendar/utilDate.js";
6
+
7
+ export function useUserFormat(localValue, userFormatLocale, isPeriod, isVariant) {
8
+ const { isMobileBreakpoint } = useBreakpoint();
9
+
10
+ const userFormatDate = computed(() => {
11
+ if ((!localValue.value.from && !localValue.value.to) || !localValue.value.from) return "";
12
+
13
+ let title = "";
14
+
15
+ const isDefaultTitle = isPeriod.value.week || isPeriod.value.custom || isPeriod.value.ownRange;
16
+
17
+ const from = localValue.value.from;
18
+ const to = localValue.value.to !== null ? localValue.value.to : null;
19
+
20
+ if (isDefaultTitle) {
21
+ let startMonthName = userFormatLocale.value.months.longhand[from.getMonth()];
22
+ let startYear = from.getFullYear();
23
+ let endMonthName = userFormatLocale.value.months.longhand[to?.getMonth()];
24
+ let endYear = to?.getFullYear();
25
+
26
+ if (startMonthName === endMonthName && endMonthName === endYear) {
27
+ startMonthName = "";
28
+ }
29
+
30
+ if (startYear.year === endYear) {
31
+ startYear = "";
32
+ }
33
+
34
+ const isDatesToSameMonth = isSameMonth(from, to);
35
+ const isDatesToSameYear = from.getFullYear() === to.getFullYear();
36
+
37
+ let fromTitle = `${from.getDate()} ${startMonthName} ${startYear}`;
38
+
39
+ if (isDatesToSameMonth && isDatesToSameYear) {
40
+ fromTitle = from.getDate();
41
+ }
42
+
43
+ if (!isDatesToSameMonth && isDatesToSameYear) {
44
+ fromTitle = `${from.getDate()} ${startMonthName}`;
45
+ }
46
+
47
+ const toTitle = to ? `${to.getDate()} ${endMonthName} ${endYear}` : "";
48
+
49
+ title = `${fromTitle} – ${toTitle}`;
50
+ }
51
+
52
+ if (isPeriod.value.month) {
53
+ const startMonthName = userFormatLocale.value.months.longhand[from.getMonth()];
54
+ const startYear = from.getFullYear();
55
+
56
+ title = `${startMonthName} ${startYear}`;
57
+ }
58
+
59
+ if (isPeriod.value.quarter || isPeriod.value.year) {
60
+ const startMonthName = userFormatLocale.value.months.longhand[from.getMonth()];
61
+ const endMonthName = userFormatLocale.value.months.longhand[to?.getMonth()];
62
+ const endYear = to?.getFullYear();
63
+
64
+ const fromTitle = `${from.getDate()} ${startMonthName}`;
65
+ const toTitle = to ? `${to.getDate()} ${endMonthName} ${endYear}` : "";
66
+
67
+ title = `${fromTitle} – ${toTitle}`;
68
+ }
69
+
70
+ if (isMobileBreakpoint.value && !isPeriod.value.month && isVariant.value.button) {
71
+ const startDay = String(from.getDate()).padStart(2, "0");
72
+ const endDay = String(to?.getDate())?.padStart(2, "0");
73
+ const startMonth = String(from.getMonth()).padStart(2, "0");
74
+ const endMonth = String(to?.getMonth())?.padStart(2, "0");
75
+
76
+ const fromTitle = `${startDay}.${startMonth}`;
77
+ const toTitle = to ? `${endDay}.${endMonth} / ${to.getFullYear()}` : "";
78
+
79
+ title = `${fromTitle} – ${toTitle}`;
80
+ }
81
+
82
+ return title;
83
+ });
84
+
85
+ return { userFormatDate };
86
+ }
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "framework": "vue",
3
3
  "name": "vueless",
4
- "version": "0.0.331",
4
+ "version": "0.0.332",
5
5
  "contributions": {
6
6
  "html": {
7
7
  "description-markup": "markdown",
@@ -2856,6 +2856,140 @@
2856
2856
  "symbol": "default"
2857
2857
  }
2858
2858
  },
2859
+ {
2860
+ "name": "UDatePickerRangeInputs",
2861
+ "description": "",
2862
+ "attributes": [
2863
+ {
2864
+ "name": "locale",
2865
+ "required": true,
2866
+ "value": {
2867
+ "kind": "expression",
2868
+ "type": "object"
2869
+ }
2870
+ },
2871
+ {
2872
+ "name": "dateFormat",
2873
+ "value": {
2874
+ "kind": "expression",
2875
+ "type": "string|undefined"
2876
+ }
2877
+ },
2878
+ {
2879
+ "name": "rangeInputName",
2880
+ "required": true,
2881
+ "value": {
2882
+ "kind": "expression",
2883
+ "type": "string"
2884
+ }
2885
+ },
2886
+ {
2887
+ "name": "config",
2888
+ "required": true,
2889
+ "value": {
2890
+ "kind": "expression",
2891
+ "type": "object"
2892
+ }
2893
+ },
2894
+ {
2895
+ "name": "attrs",
2896
+ "required": true,
2897
+ "value": {
2898
+ "kind": "expression",
2899
+ "type": "object"
2900
+ }
2901
+ }
2902
+ ],
2903
+ "source": {
2904
+ "module": "./src/ui.form-date-picker-range/UDatePickerRangeInputs.vue",
2905
+ "symbol": "default"
2906
+ }
2907
+ },
2908
+ {
2909
+ "name": "UDatePickerRangePeriodMenu",
2910
+ "description": "",
2911
+ "attributes": [
2912
+ {
2913
+ "name": "locale",
2914
+ "required": true,
2915
+ "value": {
2916
+ "kind": "expression",
2917
+ "type": "object"
2918
+ }
2919
+ },
2920
+ {
2921
+ "name": "isPeriod",
2922
+ "required": true,
2923
+ "value": {
2924
+ "kind": "expression",
2925
+ "type": "object"
2926
+ }
2927
+ },
2928
+ {
2929
+ "name": "customRangeButton",
2930
+ "required": true,
2931
+ "value": {
2932
+ "kind": "expression",
2933
+ "type": "object"
2934
+ }
2935
+ },
2936
+ {
2937
+ "name": "dateFormat",
2938
+ "value": {
2939
+ "kind": "expression",
2940
+ "type": "string|undefined"
2941
+ }
2942
+ },
2943
+ {
2944
+ "name": "minDate",
2945
+ "value": {
2946
+ "kind": "expression",
2947
+ "type": "string|date"
2948
+ }
2949
+ },
2950
+ {
2951
+ "name": "maxDate",
2952
+ "value": {
2953
+ "kind": "expression",
2954
+ "type": "string|date"
2955
+ }
2956
+ },
2957
+ {
2958
+ "name": "config",
2959
+ "required": true,
2960
+ "value": {
2961
+ "kind": "expression",
2962
+ "type": "object"
2963
+ }
2964
+ },
2965
+ {
2966
+ "name": "attrs",
2967
+ "required": true,
2968
+ "value": {
2969
+ "kind": "expression",
2970
+ "type": "object"
2971
+ }
2972
+ }
2973
+ ],
2974
+ "events": [
2975
+ {
2976
+ "name": "toggleMenu"
2977
+ },
2978
+ {
2979
+ "name": "closeMenu"
2980
+ },
2981
+ {
2982
+ "name": "clickPrev"
2983
+ },
2984
+ {
2985
+ "name": "clickNext"
2986
+ }
2987
+ ],
2988
+ "source": {
2989
+ "module": "./src/ui.form-date-picker-range/UDatePickerRangePeriodMenu.vue",
2990
+ "symbol": "default"
2991
+ }
2992
+ },
2859
2993
  {
2860
2994
  "name": "UDivider",
2861
2995
  "description": "",