@react-fabric/date 1.0.0-beta.9 → 1.0.1

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 (139) hide show
  1. package/README.md +2 -9
  2. package/{src/components/Date.module.css → css/_date.css} +5 -5
  3. package/{src/superdate/SuperDate.module.css → css/styles.css} +2 -8
  4. package/dist/cjs/components/DateCell.js +5 -7
  5. package/dist/cjs/components/DateHeader.js +27 -20
  6. package/dist/cjs/components/DatePage.js +10 -12
  7. package/dist/cjs/components/DecadePage.js +3 -3
  8. package/dist/cjs/components/MonthPage.js +3 -3
  9. package/dist/cjs/components/TimeSliders.js +36 -35
  10. package/dist/cjs/components/YearPage.js +3 -3
  11. package/dist/cjs/display/DateDisplay.js +25 -8
  12. package/dist/cjs/display/DateDuration.js +155 -0
  13. package/dist/cjs/hijri/DateConverter.js +154 -0
  14. package/dist/cjs/hijri/FormatDate.js +116 -0
  15. package/dist/cjs/hijri/HijriDate.js +531 -0
  16. package/dist/cjs/hijri/StringDateParser.js +74 -0
  17. package/dist/cjs/hijri/index.js +15 -1025
  18. package/dist/cjs/hijri/initializer.js +113 -0
  19. package/dist/cjs/hijri/locales.js +19 -0
  20. package/dist/cjs/hijri/safe.js +17 -0
  21. package/dist/cjs/i18n/ar/date.json.js +213 -0
  22. package/dist/cjs/i18n/en/date.json.js +83 -0
  23. package/dist/cjs/i18n/index.js +4 -10
  24. package/dist/cjs/index.js +41 -2
  25. package/dist/cjs/panels/BasePanel.js +6 -5
  26. package/dist/cjs/panels/DatePanel.js +45 -21
  27. package/dist/cjs/{superdate → panels}/EventPanel.js +28 -12
  28. package/dist/cjs/panels/RangePanel.js +49 -19
  29. package/dist/cjs/utils/dateUtil.js +3 -5
  30. package/dist/esm/components/DateCell.js +6 -8
  31. package/dist/esm/components/DateHeader.js +28 -21
  32. package/dist/esm/components/DatePage.js +11 -13
  33. package/dist/esm/components/DecadePage.js +3 -3
  34. package/dist/esm/components/MonthPage.js +3 -3
  35. package/dist/esm/components/TimeSliders.js +38 -37
  36. package/dist/esm/components/YearPage.js +3 -3
  37. package/dist/esm/display/DateDisplay.js +26 -9
  38. package/dist/esm/display/DateDuration.js +155 -0
  39. package/dist/esm/hijri/DateConverter.js +152 -0
  40. package/dist/esm/hijri/FormatDate.js +113 -0
  41. package/dist/esm/hijri/HijriDate.js +528 -0
  42. package/dist/esm/hijri/StringDateParser.js +74 -0
  43. package/dist/esm/hijri/index.js +15 -1025
  44. package/dist/esm/hijri/initializer.js +113 -0
  45. package/dist/esm/hijri/locales.js +18 -0
  46. package/dist/esm/hijri/safe.js +14 -0
  47. package/dist/esm/i18n/ar/date.json.js +209 -0
  48. package/dist/esm/i18n/en/date.json.js +79 -0
  49. package/dist/esm/i18n/index.js +2 -8
  50. package/dist/esm/index.js +36 -1
  51. package/dist/esm/panels/BasePanel.js +6 -5
  52. package/dist/esm/panels/DatePanel.js +48 -24
  53. package/dist/esm/{superdate → panels}/EventPanel.js +29 -13
  54. package/dist/esm/panels/RangePanel.js +52 -22
  55. package/dist/esm/utils/dateUtil.js +4 -6
  56. package/dist/types/components/DateCell.d.ts +1 -1
  57. package/dist/types/components/DateHeader.d.ts +1 -1
  58. package/dist/types/components/DatePage.d.ts +1 -1
  59. package/dist/types/components/DecadePage.d.ts +1 -1
  60. package/dist/types/components/MonthPage.d.ts +1 -1
  61. package/dist/types/components/TimeSliders.d.ts +1 -1
  62. package/dist/types/components/YearPage.d.ts +1 -1
  63. package/dist/types/display/DateDisplay.d.ts +17 -4
  64. package/dist/types/display/DateDuration.d.ts +25 -0
  65. package/dist/types/hijri/DateConverter.d.ts +13 -0
  66. package/dist/types/hijri/FormatDate.d.ts +19 -0
  67. package/dist/types/hijri/HijriDate.d.ts +214 -0
  68. package/dist/types/hijri/StringDateParser.d.ts +11 -0
  69. package/dist/types/hijri/index.d.ts +2 -2
  70. package/dist/types/hijri/initializer.d.ts +129 -0
  71. package/dist/types/hijri/locales.d.ts +19 -0
  72. package/dist/types/hijri/safe.d.ts +3 -0
  73. package/dist/types/index.d.ts +32 -1
  74. package/dist/types/panels/BasePanel.d.ts +1 -1
  75. package/dist/types/panels/DatePanel.d.ts +22 -1
  76. package/dist/types/panels/EventPanel.d.ts +17 -0
  77. package/dist/types/panels/RangePanel.d.ts +19 -1
  78. package/dist/types/types/index.d.ts +8 -40
  79. package/package.json +14 -21
  80. package/src/components/DateCell.tsx +20 -75
  81. package/src/components/DateHeader.tsx +27 -78
  82. package/src/components/DatePage.tsx +11 -36
  83. package/src/components/DecadePage.tsx +2 -2
  84. package/src/components/MonthPage.tsx +2 -2
  85. package/src/components/TimeSliders.tsx +20 -60
  86. package/src/components/YearPage.tsx +2 -2
  87. package/src/display/DateDisplay.tsx +26 -38
  88. package/src/display/DateDuration.tsx +170 -0
  89. package/src/hijri/DateConverter.js +175 -0
  90. package/src/hijri/FormatDate.js +134 -0
  91. package/src/hijri/HijriDate.js +477 -0
  92. package/src/hijri/StringDateParser.js +68 -0
  93. package/src/hijri/index.js +16 -1535
  94. package/src/hijri/initializer.js +96 -0
  95. package/src/hijri/locales.js +109 -0
  96. package/src/hijri/safe.js +16 -0
  97. package/src/i18n/ar/date.json +203 -0
  98. package/src/i18n/en/date.json +73 -0
  99. package/src/i18n/index.ts +2 -5
  100. package/src/index.ts +29 -18
  101. package/src/panels/BasePanel.tsx +7 -10
  102. package/src/panels/DatePanel.tsx +41 -33
  103. package/src/{superdate → panels}/EventPanel.tsx +52 -53
  104. package/src/panels/RangePanel.tsx +54 -60
  105. package/src/types/index.ts +8 -43
  106. package/src/utils/dateUtil.ts +26 -82
  107. package/dist/cjs/components/Date.module.css +0 -1
  108. package/dist/cjs/i18n/ar.json.js +0 -25
  109. package/dist/cjs/i18n/en.json.js +0 -21
  110. package/dist/cjs/i18n/superdate/ar.json.js +0 -86
  111. package/dist/cjs/i18n/superdate/en.json.js +0 -93
  112. package/dist/cjs/superdate/QuickSelect.js +0 -134
  113. package/dist/cjs/superdate/RelativeInput.js +0 -79
  114. package/dist/cjs/superdate/RelativePanel.js +0 -91
  115. package/dist/cjs/superdate/SuperDate.module.css +0 -1
  116. package/dist/cjs/superdate/Superdate.js +0 -177
  117. package/dist/esm/components/Date.module.css +0 -1
  118. package/dist/esm/i18n/ar.json.js +0 -21
  119. package/dist/esm/i18n/en.json.js +0 -18
  120. package/dist/esm/i18n/superdate/ar.json.js +0 -79
  121. package/dist/esm/i18n/superdate/en.json.js +0 -85
  122. package/dist/esm/superdate/QuickSelect.js +0 -134
  123. package/dist/esm/superdate/RelativeInput.js +0 -79
  124. package/dist/esm/superdate/RelativePanel.js +0 -91
  125. package/dist/esm/superdate/SuperDate.module.css +0 -1
  126. package/dist/esm/superdate/Superdate.js +0 -176
  127. package/dist/types/superdate/EventPanel.d.ts +0 -4
  128. package/dist/types/superdate/QuickSelect.d.ts +0 -1
  129. package/dist/types/superdate/RelativeInput.d.ts +0 -1
  130. package/dist/types/superdate/RelativePanel.d.ts +0 -1
  131. package/dist/types/superdate/Superdate.d.ts +0 -17
  132. package/src/i18n/ar.json +0 -14
  133. package/src/i18n/en.json +0 -13
  134. package/src/i18n/superdate/ar.json +0 -70
  135. package/src/i18n/superdate/en.json +0 -75
  136. package/src/superdate/QuickSelect.tsx +0 -121
  137. package/src/superdate/RelativeInput.tsx +0 -64
  138. package/src/superdate/RelativePanel.tsx +0 -103
  139. package/src/superdate/Superdate.tsx +0 -198
@@ -21,6 +21,10 @@
21
21
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
22
  */
23
23
 
24
+ /* eslint-disable @typescript-eslint/no-unsafe-enum-comparison */
25
+
26
+ import { isNil, isString } from "@react-fabric/utilities";
27
+ import type { Locale } from "date-fns";
24
28
  import {
25
29
  addDays as _addDays,
26
30
  addMonths as _addMonths,
@@ -51,26 +55,11 @@ import {
51
55
  startOfMinute,
52
56
  startOfQuarter,
53
57
  } from "date-fns";
54
- import { DatePart, PageType, type DateLike } from "../types";
55
- // import { parseDate } from "./dateMath";
56
- import { isNil, isString } from "@react-fabric/utilities";
57
- import {
58
- arSA as ar,
59
- de,
60
- enUS as en,
61
- es,
62
- fr,
63
- hi,
64
- it,
65
- ja,
66
- ko,
67
- pt,
68
- ru,
69
- zhCN as zh,
70
- } from "date-fns/locale";
58
+ import { arSA as ar, de, enUS as en, es, fr, hi, it, ja, ko, pt, ru, zhCN as zh } from "date-fns/locale";
71
59
  import i18next from "i18next";
60
+ import { DatePart, PageType, type DateLike } from "../types";
72
61
 
73
- const Locales: KeyValue = {
62
+ const Locales: KeyValue<Locale> = {
74
63
  ar,
75
64
  en,
76
65
  de,
@@ -83,9 +72,8 @@ const Locales: KeyValue = {
83
72
  pt,
84
73
  ru,
85
74
  zh,
86
- };
75
+ } as const;
87
76
 
88
- // eslint-disable-next-line @typescript-eslint/no-namespace
89
77
  export namespace DateUtil {
90
78
  const translateNumber = (d: string) => {
91
79
  return d
@@ -138,19 +126,12 @@ export namespace DateUtil {
138
126
  return hdate;
139
127
  };
140
128
 
141
- export const format = (
142
- date?: DateLike,
143
- fmt = "dd MMM yyyy",
144
- locale?: string,
145
- isHijri?: boolean,
146
- ) => {
129
+ export const format = (date?: DateLike, fmt = "dd MMM yyyy", locale?: string, isHijri?: boolean) => {
147
130
  let formatted = "";
148
131
  if (!isNil(date)) {
149
132
  const dt = isRelative(date) ? parseDate(date) : new Date(date);
150
133
  if (dt != null) {
151
- formatted = isHijri
152
- ? formatHijri(dt, fmt, locale)
153
- : formatGregorian(dt, fmt, locale);
134
+ formatted = isHijri ? formatHijri(dt, fmt, locale) : formatGregorian(dt, fmt, locale);
154
135
  }
155
136
  }
156
137
  return formatted;
@@ -161,10 +142,7 @@ export namespace DateUtil {
161
142
  };
162
143
 
163
144
  export const isRelativeRange = (date: DateLike): date is string => {
164
- return (
165
- isString(date) &&
166
- date.match(/^(\$\w+)([+-])(\d+)?\|(\$\w+)([+-])(\d+)?$/) !== null
167
- );
145
+ return isString(date) && date.match(/^(\$\w+)([+-])(\d+)?\|(\$\w+)([+-])(\d+)?$/) !== null;
168
146
  };
169
147
 
170
148
  export const startOfDay = (date?: Date, isHijri: boolean = false) => {
@@ -318,11 +296,7 @@ export namespace DateUtil {
318
296
  }
319
297
  };
320
298
 
321
- export const addMonths = (
322
- date: Date,
323
- d: number,
324
- isHijri: boolean = false,
325
- ) => {
299
+ export const addMonths = (date: Date, d: number, isHijri: boolean = false) => {
326
300
  if (isHijri) {
327
301
  return addHijriMonth(date, d).toGregorian();
328
302
  } else {
@@ -340,12 +314,8 @@ export namespace DateUtil {
340
314
  }
341
315
  };
342
316
 
343
- export const getWeek = (
344
- date: Date,
345
- locale: string,
346
- isHijri: boolean = false,
347
- ) => {
348
- let ret = "";
317
+ export const getWeek = (date: Date, locale: string, isHijri: boolean = false) => {
318
+ let ret;
349
319
  if (isHijri) {
350
320
  const start = startOfYear(date, isHijri);
351
321
  ret = format(new Date(date.getTime() - start.getTime()), "ww");
@@ -358,11 +328,7 @@ export namespace DateUtil {
358
328
  return ret;
359
329
  };
360
330
 
361
- export const isSameMonth = (
362
- date: Date,
363
- compare: Date,
364
- isHijri: boolean = false,
365
- ) => {
331
+ export const isSameMonth = (date: Date, compare: Date, isHijri: boolean = false) => {
366
332
  if (isHijri) {
367
333
  const hdate = date.toHijri().ignoreTime();
368
334
  const hcompare = compare.toHijri().ignoreTime();
@@ -372,11 +338,7 @@ export namespace DateUtil {
372
338
  }
373
339
  };
374
340
 
375
- export const isSameYear = (
376
- date: Date,
377
- compare: Date,
378
- isHijri: boolean = false,
379
- ) => {
341
+ export const isSameYear = (date: Date, compare: Date, isHijri: boolean = false) => {
380
342
  if (isHijri) {
381
343
  const hdate = date.toHijri().ignoreTime();
382
344
  const hcompare = compare.toHijri().ignoreTime();
@@ -386,12 +348,7 @@ export namespace DateUtil {
386
348
  }
387
349
  };
388
350
 
389
- export const isDisabled = (
390
- date: Date,
391
- page: PageType,
392
- min?: DateLike,
393
- max?: DateLike,
394
- ) => {
351
+ export const isDisabled = (date: Date, page: PageType, min?: DateLike, max?: DateLike) => {
395
352
  let methods = [_startOfDay, _endOfDay];
396
353
  if (page === PageType.MONTH) {
397
354
  methods = [_startOfMonth, _endOfMonth];
@@ -401,10 +358,7 @@ export namespace DateUtil {
401
358
  methods = [_startOfDecade, _endOfDecade];
402
359
  }
403
360
  const [start, end] = methods;
404
- return (
405
- (!(min == null) && isBefore(start(date), start(min))) ||
406
- (!(max == null) && isAfter(end(date), end(max)))
407
- );
361
+ return (!(min == null) && isBefore(start(date), start(min))) || (!(max == null) && isAfter(end(date), end(max)));
408
362
  };
409
363
 
410
364
  export const parseDate = (datelike: DateLike): Date => {
@@ -417,9 +371,7 @@ export namespace DateUtil {
417
371
  const parseStart = _parse(start, !end ? "start" : undefined);
418
372
  const parseEnd = _parse(end ?? start, !end ? "end" : undefined);
419
373
 
420
- return isBefore(parseStart, parseEnd)
421
- ? [parseStart, parseEnd]
422
- : [parseEnd, parseStart];
374
+ return isBefore(parseStart, parseEnd) ? [parseStart, parseEnd] : [parseEnd, parseStart];
423
375
  };
424
376
 
425
377
  export const relativeTooltip = (datelike?: string, isHijri = false) => {
@@ -447,12 +399,7 @@ export namespace DateUtil {
447
399
  const parseEnd = _parse(end);
448
400
  if (isSameYear(parseStart, parseEnd)) {
449
401
  labels = [
450
- format(
451
- parseStart,
452
- isSameMonth(parseStart, parseEnd) ? "dd" : "dd MMM",
453
- i18next.language,
454
- isHijri,
455
- ),
402
+ format(parseStart, isSameMonth(parseStart, parseEnd) ? "dd" : "dd MMM", i18next.language, isHijri),
456
403
  format(parseEnd, "dd MMM yyyy", i18next.language, isHijri),
457
404
  ];
458
405
  } else {
@@ -466,26 +413,23 @@ export namespace DateUtil {
466
413
  labels = [format(parseStart, "dd MMM yyyy", i18next.language, isHijri)];
467
414
  }
468
415
 
469
- return end
470
- ? labels.join(` ${i18next.t(`superdate:separator`, "→")} `)
471
- : labels[0];
416
+ return end ? labels.join(` ${i18next.t(`superdate:separator`, "→")} `) : labels[0];
472
417
  };
473
418
 
474
419
  const _parseLabel = (dt: string) => {
475
420
  if (!dt) return "";
476
- const [, part, op = "+", diff = 0] =
477
- dt.match(/^(\$\w+)([+-])?(\d+)?$/) ?? [];
421
+ const [, part, op = "+", diff = 0] = dt.match(/^(\$\w+)([+-])?(\d+)?$/) ?? [];
478
422
  if (part) {
479
- const t = (k: string, o?: AnyObject) => i18next.t(`superdate:${k}`, o);
423
+ const t = (k: string, o?: KeyValue<number>) => i18next.t(`superdate:${k}`, o);
480
424
  if (part === DatePart.NOW) {
481
- return t(`label.${DatePart.NOW}`) as string;
425
+ return t(`label.${DatePart.NOW}`);
482
426
  }
483
427
  if (diff === 0) {
484
- return t(`now.${part}`) as string;
428
+ return t(`now.${part}`);
485
429
  } else {
486
430
  return t(`${op === "+" ? "next" : "prev"}.${part}`, {
487
431
  count: parseInt(diff, 10),
488
- }) as string;
432
+ });
489
433
  }
490
434
  }
491
435
  };
@@ -1 +0,0 @@
1
- @layer comp{.dateHeader{box-shadow:inset 0 -1px 0 theme(colors.tint.200/50%)}.timeSlider{height:11.25rem;&:after,&:before{box-shadow:0 0 3rem .25rem theme(colors.tint.600);content:"";display:block;z-index:10}&:before{position:sticky;top:0}&:after{bottom:0;position:sticky}&>:first-child,&>:last-child{height:calc(50% - .75rem)}& [data-skew="1"]>div{opacity:.9;transform:scaleY(.9)}& [data-skew="2"]>div{opacity:.75;transform:scaleY(.75)}& [data-skew="3"]>div{opacity:.65;transform:scaleY(.65)}& [data-skew="4"]>div{opacity:.5;transform:scaleY(.5)}}}
@@ -1,25 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var label = {
6
- prevMonth: "الشهر الماضى",
7
- prevYear: "السنة الماضية",
8
- prevDecade: "العقد السابق",
9
- nextMonth: "الشهر القادم",
10
- nextYear: "العام القادم",
11
- nextDecade: "العقد القادم",
12
- today: "اليوم",
13
- hijri: "هجري",
14
- gregorian: "ميلادي"
15
- };
16
- var number = {
17
- };
18
- var ar = {
19
- label: label,
20
- number: number
21
- };
22
-
23
- exports.default = ar;
24
- exports.label = label;
25
- exports.number = number;
@@ -1,21 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var label = {
6
- prevMonth: "Previous Month",
7
- prevYear: "Previous Year",
8
- prevDecade: "Previous Decade",
9
- nextMonth: "Next Month",
10
- nextYear: "Next Year",
11
- nextDecade: "Next Decade",
12
- today: "Today",
13
- hijri: "Hijri",
14
- gregorian: "Gregorian"
15
- };
16
- var en = {
17
- label: label
18
- };
19
-
20
- exports.default = en;
21
- exports.label = label;
@@ -1,86 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var separator = " ⇽ ";
6
- var label = {
7
- quick: "حدد مسرعا",
8
- relative: "نسبيا",
9
- events: "الأحداث",
10
- absolute: "مطلق",
11
- preset: "المسبقة",
12
- current: "تيار",
13
- previous: "السابق",
14
- from: "من عند",
15
- to: "إلى",
16
- "+": "من الان",
17
- "-": "منذ",
18
- apply: "يتقدم",
19
- $now: "الآن",
20
- $minute: "دقيقة",
21
- $hour: "ساعة",
22
- $day: "يوم",
23
- $week: "أسبوع",
24
- $month: "شهر",
25
- $quarter: "ربع",
26
- $year: "عام",
27
- $decade: "عقد"
28
- };
29
- var now = {
30
- $day: "اليوم",
31
- $week: "هذا الاسبوع",
32
- $month: "هذا الشهر",
33
- $quarter: "هذا الربع",
34
- $year: "هذه السنة",
35
- $decade: "هذا العقد"
36
- };
37
- var next = {
38
- $day: "غدا",
39
- $week: "الاسبوع القادم",
40
- $month: "الشهر القادم",
41
- $quarter: "الربع القادم",
42
- $year: "العام القادم",
43
- $decade: "العقد القادم",
44
- $minute: "بعد دقيقة",
45
- $hour: "بعد ساعة",
46
- $minute_plural: "بعد {{count}} دقائق",
47
- $hour_plural: "بعد {{count}} ساعات",
48
- $day_plural: "بعد {{count}} أيام",
49
- $week_plural: "بعد {{count}} أسابيع",
50
- $month_plural: "بعد {{count}} أشهر",
51
- $quarter_plural: "بعد {{count}} أرباع",
52
- $year_plural: "بعد {{count}} سنوات",
53
- $decade_plural: "بعد {{count}} عقود"
54
- };
55
- var prev = {
56
- $day: "في الامس",
57
- $week: "الاسبوع الماضي",
58
- $month: "الشهر الماضي",
59
- $quarter: "الربع الأخير",
60
- $year: "العام الماضي",
61
- $decade: "العقد الماضي",
62
- $minute: "منذ دقيقة",
63
- $hour: "منذ ساعة",
64
- $minute_plural: "منذ {{count}} دقيقة",
65
- $hour_plural: "منذ {{count}} ساعات",
66
- $day_plural: "منذ {{count}} أيام",
67
- $week_plural: "من {{count}} اسابيع",
68
- $month_plural: "قبل {{count}} أشهر",
69
- $quarter_plural: "منذ {{count}} أرباع",
70
- $year_plural: "منذ {{count}} سنوات",
71
- $decade_plural: "منذ {{count}} عقود"
72
- };
73
- var arSuper = {
74
- separator: separator,
75
- label: label,
76
- now: now,
77
- next: next,
78
- prev: prev
79
- };
80
-
81
- exports.default = arSuper;
82
- exports.label = label;
83
- exports.next = next;
84
- exports.now = now;
85
- exports.prev = prev;
86
- exports.separator = separator;
@@ -1,93 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var separator = " ⇾ ";
6
- var event = {
7
- ramadan: "Ramadan",
8
- christmas: "Christmas",
9
- newYear: "New Year"
10
- };
11
- var label = {
12
- quick: "Quick Select",
13
- relative: "Relative",
14
- absolute: "Absolute",
15
- events: "Events",
16
- preset: "Presets",
17
- current: "Current",
18
- previous: "Previous",
19
- from: "From",
20
- to: "To",
21
- "+": "From now",
22
- "-": "Ago",
23
- apply: "Apply",
24
- $now: "Now",
25
- $minute: "Minute",
26
- $hour: "Hour",
27
- $day: "Day",
28
- $week: "Week",
29
- $month: "Month",
30
- $quarter: "Quarter",
31
- $year: "Year",
32
- $decade: "Decade"
33
- };
34
- var now = {
35
- $day: "Today",
36
- $week: "This week",
37
- $month: "This month",
38
- $quarter: "This quarter",
39
- $year: "This year",
40
- $decade: "This decade"
41
- };
42
- var next = {
43
- $day: "Tomorrow",
44
- $week: "Next week",
45
- $month: "Next month",
46
- $quarter: "Next quarter",
47
- $year: "Next year",
48
- $decade: "Next decade",
49
- $minute: "A minute later",
50
- $hour: "An hour later",
51
- $minute_other: "{{count}} minutes later",
52
- $hour_other: "{{count}} hours later",
53
- $day_other: "{{count}} days later",
54
- $week_other: "{{count}} weeks later",
55
- $month_other: "{{count}} months later",
56
- $quarter_other: "{{count}} quarters later",
57
- $year_other: "{{count}} years later",
58
- $decade_other: "{{count}} decades later"
59
- };
60
- var prev = {
61
- $day: "Yesterday",
62
- $week: "Last week",
63
- $month: "Last month",
64
- $quarter: "Last quarter",
65
- $year: "Last year",
66
- $decade: "Last decade",
67
- $minute: "A minute ago",
68
- $hour: "An hour ago",
69
- $minute_other: "{{count}} minutes ago",
70
- $hour_other: "{{count}} hours ago",
71
- $day_other: "{{count}} days ago",
72
- $week_other: "{{count}} weeks ago",
73
- $month_other: "{{count}} months ago",
74
- $quarter_other: "{{count}} quarters ago",
75
- $year_other: "{{count}} years ago",
76
- $decade_other: "{{count}} decades ago"
77
- };
78
- var enSuper = {
79
- separator: separator,
80
- event: event,
81
- label: label,
82
- now: now,
83
- next: next,
84
- prev: prev
85
- };
86
-
87
- exports.default = enSuper;
88
- exports.event = event;
89
- exports.label = label;
90
- exports.next = next;
91
- exports.now = now;
92
- exports.prev = prev;
93
- exports.separator = separator;
@@ -1,134 +0,0 @@
1
- 'use strict';
2
-
3
- var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
4
- var core = require('@react-fabric/core');
5
- var form = require('@react-fabric/form');
6
- var utilities = require('@react-fabric/utilities');
7
- var react = require('react');
8
- var reactI18next = require('react-i18next');
9
- var index = require('../types/index.js');
10
- var RelativeInput = require('./RelativeInput.js');
11
- var jsxRuntime = require('react/jsx-runtime');
12
-
13
- var DEFAULT_PRESETS = [{
14
- value: "$day",
15
- label: "superdate:now.$day"
16
- }, {
17
- value: "$day-1",
18
- label: "superdate:prev.$day"
19
- }, {
20
- value: "$day+1",
21
- label: "superdate:next.$day"
22
- }, {
23
- value: "$week",
24
- label: "superdate:now.$week"
25
- }, {
26
- value: "$week-1",
27
- label: "superdate:prev.$week"
28
- }, {
29
- value: "$week+1",
30
- label: "superdate:next.$week"
31
- }, {
32
- value: "$month",
33
- label: "superdate:now.$month"
34
- }, {
35
- value: "$month-1",
36
- label: "superdate:prev.$month"
37
- }, {
38
- value: "$month+1",
39
- label: "superdate:next.$month"
40
- }, {
41
- value: "$quarter",
42
- label: "superdate:now.$quarter"
43
- }, {
44
- value: "$quarter-1",
45
- label: "superdate:prev.$quarter"
46
- }, {
47
- value: "$quarter+1",
48
- label: "superdate:next.$quarter"
49
- }, {
50
- value: "$year",
51
- label: "superdate:now.$year"
52
- }, {
53
- value: "$year-1",
54
- label: "superdate:prev.$year"
55
- }, {
56
- value: "$year+1",
57
- label: "superdate:next.$year"
58
- }];
59
- var schema = utilities.yup.object({
60
- rel: utilities.yup.object({
61
- diff: utilities.yup.number().required().label("Difference"),
62
- op: utilities.yup.string().required().oneOf(["+", "-"]).label("Operator"),
63
- part: utilities.yup.string().required().oneOf(Object.values(index.DatePart)).label("Date part")
64
- })
65
- });
66
- var QuickSelect = function QuickSelect(_ref) {
67
- var _ref$presets = _ref.presets,
68
- presets = _ref$presets === void 0 ? DEFAULT_PRESETS : _ref$presets,
69
- _ref$value = _ref.value,
70
- value = _ref$value === void 0 ? "" : _ref$value,
71
- onChange = _ref.onChange;
72
- var _useTranslation = reactI18next.useTranslation(),
73
- t = _useTranslation.t;
74
- var handleChange = react.useCallback(function (_ref2) {
75
- var _ref2$rel = _ref2.rel,
76
- part = _ref2$rel.part,
77
- diff = _ref2$rel.diff,
78
- op = _ref2$rel.op;
79
- onChange("".concat(part).concat(op).concat(diff, "|").concat(index.DatePart.NOW));
80
- }, []);
81
- var defaultValue = react.useMemo(function () {
82
- if (value !== null && value !== void 0 && value.endsWith(index.DatePart.NOW)) {
83
- var _value$split$shift$ma;
84
- var _ref3 = (_value$split$shift$ma = value.split("|").shift().match(/^(\$\w+)([+-])(\d+)?$/)) !== null && _value$split$shift$ma !== void 0 ? _value$split$shift$ma : [],
85
- _ref4 = _slicedToArray(_ref3, 4),
86
- part = _ref4[1],
87
- op = _ref4[2],
88
- _ref4$ = _ref4[3],
89
- diff = _ref4$ === void 0 ? "0" : _ref4$;
90
- return {
91
- rel: {
92
- part: part,
93
- op: op,
94
- diff: diff
95
- }
96
- };
97
- }
98
- }, [value]);
99
- return /*#__PURE__*/jsxRuntime.jsxs(core.Content, {
100
- children: [/*#__PURE__*/jsxRuntime.jsx("div", {
101
- className: "inline-block origin-left rtl:origin-right",
102
- style: {
103
- zoom: 0.85
104
- },
105
- children: /*#__PURE__*/jsxRuntime.jsx(form.Form, {
106
- schema: schema,
107
- onSubmit: handleChange,
108
- defaultValues: defaultValue,
109
- children: /*#__PURE__*/jsxRuntime.jsx(RelativeInput.RelativeInput, {
110
- label: t("superdate:label.relative"),
111
- prefix: "rel",
112
- showApply: true
113
- })
114
- })
115
- }), /*#__PURE__*/jsxRuntime.jsx(core.Divider, {
116
- children: t("superdate:label.preset")
117
- }), /*#__PURE__*/jsxRuntime.jsx("div", {
118
- className: "grid grid-cols-3 flex-row text-sm gap-2",
119
- children: presets.map(function (pr) {
120
- return /*#__PURE__*/jsxRuntime.jsx("button", {
121
- className: "link appearance-none text-start",
122
- onClick: function onClick() {
123
- return onChange === null || onChange === void 0 ? void 0 : onChange(pr.value);
124
- },
125
- children: t(pr.label, {
126
- defaultValue: pr.label
127
- })
128
- }, pr.value);
129
- })
130
- })]
131
- });
132
- };
133
-
134
- exports.QuickSelect = QuickSelect;
@@ -1,79 +0,0 @@
1
- 'use strict';
2
-
3
- var core = require('@react-fabric/core');
4
- var form = require('@react-fabric/form');
5
- var reactI18next = require('react-i18next');
6
- var index = require('../types/index.js');
7
- var jsxRuntime = require('react/jsx-runtime');
8
-
9
- /*
10
- * React Fabric
11
- * @version: 1.0.0
12
- *
13
- *
14
- * The MIT License (MIT)
15
- * Copyright (c) 2024 Adarsh Pastakia
16
- *
17
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
18
- * and associated documentation files (the "Software"), to deal in the Software without restriction,
19
- * including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
20
- * and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
21
- * subject to the following conditions:
22
- *
23
- * The above copyright notice and this permission notice shall be included in all copies or substantial
24
- * portions of the Software.
25
- *
26
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
27
- * TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
28
- * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
29
- * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30
- */
31
-
32
- var RelativeInput = function RelativeInput(_ref) {
33
- var label = _ref.label,
34
- prefix = _ref.prefix,
35
- showApply = _ref.showApply;
36
- var _useTranslation = reactI18next.useTranslation("superdate"),
37
- t = _useTranslation.t;
38
- return /*#__PURE__*/jsxRuntime.jsxs(form.Field, {
39
- label: label,
40
- className: "mb-2",
41
- children: [/*#__PURE__*/jsxRuntime.jsx(form.Controller, {
42
- name: "".concat(prefix, ".diff"),
43
- children: /*#__PURE__*/jsxRuntime.jsx(form.Number, {
44
- width: "5rem",
45
- min: 1,
46
- max: 99
47
- })
48
- }), /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
49
- name: "".concat(prefix, ".part"),
50
- children: /*#__PURE__*/jsxRuntime.jsx(form.Select, {
51
- width: "6rem",
52
- options: Object.values(index.DatePart).slice(1).map(function (dt) {
53
- return {
54
- id: dt,
55
- label: t("label.".concat(dt))
56
- };
57
- })
58
- })
59
- }), /*#__PURE__*/jsxRuntime.jsx(form.Controller, {
60
- name: "".concat(prefix, ".op"),
61
- children: /*#__PURE__*/jsxRuntime.jsx(form.Select, {
62
- width: "7rem",
63
- options: [{
64
- id: "-",
65
- label: t("label.-")
66
- }, {
67
- id: "+",
68
- label: t("label.+")
69
- }]
70
- })
71
- }), showApply && /*#__PURE__*/jsxRuntime.jsx(core.Button, {
72
- variant: "solid",
73
- type: "submit",
74
- children: t("label.apply")
75
- })]
76
- });
77
- };
78
-
79
- exports.RelativeInput = RelativeInput;