@react-fabric/date 1.0.0-beta.8 → 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
@@ -9,9 +9,9 @@ import { jsx } from 'react/jsx-runtime';
9
9
 
10
10
  var _excluded = ["pageDate", "isHijri"];
11
11
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
13
  var cols = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
14
- var DecadePage = function DecadePage(_ref) {
14
+ function DecadePage(_ref) {
15
15
  var pageDate = _ref.pageDate,
16
16
  isHijri = _ref.isHijri,
17
17
  props = _objectWithoutProperties(_ref, _excluded);
@@ -29,6 +29,6 @@ var DecadePage = function DecadePage(_ref) {
29
29
  }, props), col);
30
30
  })
31
31
  });
32
- };
32
+ }
33
33
 
34
34
  export { DecadePage };
@@ -9,9 +9,9 @@ import { jsx } from 'react/jsx-runtime';
9
9
 
10
10
  var _excluded = ["pageDate", "isHijri"];
11
11
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
13
  var cols = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11];
14
- var MonthPage = function MonthPage(_ref) {
14
+ function MonthPage(_ref) {
15
15
  var pageDate = _ref.pageDate,
16
16
  isHijri = _ref.isHijri,
17
17
  props = _objectWithoutProperties(_ref, _excluded);
@@ -28,6 +28,6 @@ var MonthPage = function MonthPage(_ref) {
28
28
  }, props), col);
29
29
  })
30
30
  });
31
- };
31
+ }
32
32
 
33
33
  export { MonthPage };
@@ -1,13 +1,12 @@
1
1
  'use client';
2
2
 
3
3
  import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
4
- import { useDebounce } from '@react-fabric/core';
5
- import classNames from 'classnames';
6
- import { useRef, useState, useEffect, useCallback } from 'react';
7
- import classes from './Date.module.css';
4
+ import { usePropState, useDebounce } from '@react-fabric/core';
5
+ import { cn } from '@react-fabric/utilities';
6
+ import { useRef, useCallback } from 'react';
8
7
  import { jsxs, jsx } from 'react/jsx-runtime';
9
8
 
10
- var TimeSlider = function TimeSlider(_ref) {
9
+ function TimeSlider(_ref) {
11
10
  var _ref$hour = _ref.hour,
12
11
  hour = _ref$hour === void 0 ? 0 : _ref$hour,
13
12
  _ref$minute = _ref.minute,
@@ -15,28 +14,24 @@ var TimeSlider = function TimeSlider(_ref) {
15
14
  onTimeChange = _ref.onTimeChange;
16
15
  var hourRef = useRef(null);
17
16
  var minuteRef = useRef(null);
18
- var _useState = useState(hour),
19
- _useState2 = _slicedToArray(_useState, 2),
20
- h = _useState2[0],
21
- setH = _useState2[1];
22
- var _useState3 = useState(minute),
23
- _useState4 = _slicedToArray(_useState3, 2),
24
- m = _useState4[0],
25
- setM = _useState4[1];
26
- useEffect(function () {
27
- var _hourRef$current;
28
- setH(hour);
29
- (_hourRef$current = hourRef.current) === null || _hourRef$current === void 0 || (_hourRef$current = _hourRef$current.children.item(hour + 1)) === null || _hourRef$current === void 0 || _hourRef$current.scrollIntoView({
30
- block: "center"
31
- });
32
- }, [hour]);
33
- useEffect(function () {
34
- var _minuteRef$current;
35
- setM(minute);
36
- (_minuteRef$current = minuteRef.current) === null || _minuteRef$current === void 0 || (_minuteRef$current = _minuteRef$current.children.item(minute + 1)) === null || _minuteRef$current === void 0 || _minuteRef$current.scrollIntoView({
37
- block: "center"
38
- });
39
- }, [minute]);
17
+ var _usePropState = usePropState(hour, function (hr) {
18
+ var _hourRef$current;
19
+ return (_hourRef$current = hourRef.current) === null || _hourRef$current === void 0 || (_hourRef$current = _hourRef$current.children.item(hr + 1)) === null || _hourRef$current === void 0 ? void 0 : _hourRef$current.scrollIntoView({
20
+ block: "center"
21
+ });
22
+ }),
23
+ _usePropState2 = _slicedToArray(_usePropState, 2),
24
+ h = _usePropState2[0],
25
+ setH = _usePropState2[1];
26
+ var _usePropState3 = usePropState(minute, function (mn) {
27
+ var _minuteRef$current;
28
+ return (_minuteRef$current = minuteRef.current) === null || _minuteRef$current === void 0 || (_minuteRef$current = _minuteRef$current.children.item(mn + 1)) === null || _minuteRef$current === void 0 ? void 0 : _minuteRef$current.scrollIntoView({
29
+ block: "center"
30
+ });
31
+ }),
32
+ _usePropState4 = _slicedToArray(_usePropState3, 2),
33
+ m = _usePropState4[0],
34
+ setM = _usePropState4[1];
40
35
  var fireChange = useDebounce(onTimeChange, [onTimeChange]);
41
36
  var calculateTime = useCallback(function () {
42
37
  var _hourRef$current$scro, _hourRef$current2, _offsetHeight, _hourRef$current3, _minuteRef$current$sc, _minuteRef$current2, _offsetHeight2, _minuteRef$current3;
@@ -52,22 +47,22 @@ var TimeSlider = function TimeSlider(_ref) {
52
47
  hour: hour,
53
48
  minute: minute
54
49
  });
55
- }, [onTimeChange]);
50
+ }, [fireChange, setH, setM]);
56
51
  return /*#__PURE__*/jsxs("div", {
57
- className: classNames("area-[time] flex flex-col flex-nowrap border-s border-s-tint-50 overflow-hidden bg-base"),
52
+ className: cn("area-[time] flex flex-col flex-nowrap border-s border-s-tint-50 overflow-hidden bg-default"),
58
53
  children: [/*#__PURE__*/jsxs("div", {
59
54
  className: "flex",
60
55
  children: [/*#__PURE__*/jsx("div", {
61
- className: classNames(classes.dateHeader, "flex-1 font-medium text-muted text-sm p-1 mx-px text-center bg-tint-50"),
56
+ className: cn("fabric-dateHeader", "flex-1 font-medium text-muted text-sm p-1 mx-px text-center bg-tint-50"),
62
57
  children: "H"
63
58
  }), /*#__PURE__*/jsx("div", {
64
- className: classNames(classes.dateHeader, "flex-1 font-medium text-muted text-sm p-1 mx-px text-center bg-tint-50"),
59
+ className: cn("fabric-dateHeader", "flex-1 font-medium text-muted text-sm p-1 mx-px text-center bg-tint-50"),
65
60
  children: "M"
66
61
  })]
67
62
  }), /*#__PURE__*/jsxs("div", {
68
- className: "flex flex-1 flex-nowrap overflow-hidden relative",
63
+ className: "flex flex-1 flex-nowrap items-stretch overflow-hidden relative",
69
64
  children: [/*#__PURE__*/jsxs("div", {
70
- className: classNames("flex-1 overflow-auto scroll-hide snap-y snap-mandatory", classes.timeSlider),
65
+ className: cn("flex-1 overflow-auto scroll-hide snap-y snap-mandatory", "fabric-date-timeSlider"),
71
66
  onScroll: calculateTime,
72
67
  ref: hourRef,
73
68
  children: [/*#__PURE__*/jsx("div", {
@@ -75,7 +70,10 @@ var TimeSlider = function TimeSlider(_ref) {
75
70
  }), Array(24).fill(0).map(function (_, i) {
76
71
  return /*#__PURE__*/jsx("div", {
77
72
  role: "none",
78
- className: classNames("ps-2 pe-1 snap-center outline outline-muted", i === h && "font-medium text-primary-600"),
73
+ className: cn("ps-2 pe-1 snap-center outline outline-muted", i === h && "font-medium text-primary-600")
74
+ // eslint-disable-next-line @eslint-react/no-array-index-key
75
+ ,
76
+
79
77
  "data-skew": i === h - 5 || i === h + 5 ? 5 : i === h - 4 || i === h + 4 ? 4 : i === h - 3 || i === h + 3 ? 3 : i === h - 2 || i === h + 2 ? 2 : i === h - 1 || i === h + 1 ? 1 : undefined,
80
78
  "data-selected": i === h,
81
79
  onClick: function onClick(e) {
@@ -92,7 +90,7 @@ var TimeSlider = function TimeSlider(_ref) {
92
90
  className: "w-full"
93
91
  })]
94
92
  }), /*#__PURE__*/jsxs("div", {
95
- className: classNames("flex-1 overflow-auto scroll-hide snap-y snap-mandatory", classes.timeSlider),
93
+ className: cn("flex-1 overflow-auto scroll-hide snap-y snap-mandatory", "fabric-date-timeSlider"),
96
94
  onScroll: calculateTime,
97
95
  ref: minuteRef,
98
96
  children: [/*#__PURE__*/jsx("div", {
@@ -100,7 +98,10 @@ var TimeSlider = function TimeSlider(_ref) {
100
98
  }), Array(60).fill(0).map(function (_, i) {
101
99
  return /*#__PURE__*/jsx("div", {
102
100
  role: "none",
103
- className: classNames("ps-1 pe-2 snap-center outline outline-muted", i === m && "font-medium text-primary-600"),
101
+ className: cn("ps-1 pe-2 snap-center outline outline-muted", i === m && "font-medium text-primary-600")
102
+ // eslint-disable-next-line @eslint-react/no-array-index-key
103
+ ,
104
+
104
105
  "data-skew": i === m - 5 || i === m + 5 ? 5 : i === m - 4 || i === m + 4 ? 4 : i === m - 3 || i === m + 3 ? 3 : i === m - 2 || i === m + 2 ? 2 : i === m - 1 || i === m + 1 ? 1 : undefined,
105
106
  "data-selected": i === m,
106
107
  onClick: function onClick(e) {
@@ -126,6 +127,6 @@ var TimeSlider = function TimeSlider(_ref) {
126
127
  })]
127
128
  })]
128
129
  });
129
- };
130
+ }
130
131
 
131
132
  export { TimeSlider };
@@ -9,9 +9,9 @@ import { jsx } from 'react/jsx-runtime';
9
9
 
10
10
  var _excluded = ["pageDate", "isHijri"];
11
11
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
12
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
13
  var cols = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
14
- var YearPage = function YearPage(_ref) {
14
+ function YearPage(_ref) {
15
15
  var pageDate = _ref.pageDate,
16
16
  isHijri = _ref.isHijri,
17
17
  props = _objectWithoutProperties(_ref, _excluded);
@@ -29,6 +29,6 @@ var YearPage = function YearPage(_ref) {
29
29
  }, props), col);
30
30
  })
31
31
  });
32
- };
32
+ }
33
33
 
34
34
  export { YearPage };
@@ -2,34 +2,51 @@
2
2
 
3
3
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
4
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
5
- import { useGlobals, Tooltip, Dropdown } from '@react-fabric/core';
5
+ import { useApplicationContext, Tooltip, Dropdown } from '@react-fabric/core';
6
+ import { cn } from '@react-fabric/utilities';
6
7
  import { DateUtil } from '../utils/dateUtil.js';
7
8
  import { jsx, jsxs } from 'react/jsx-runtime';
8
9
 
9
- var _excluded = ["date", "className", "format", "children"];
10
+ var _excluded = ["date", "className", "format", "children", "showAlternateDate"];
10
11
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
11
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
12
- var DateDisplay = function DateDisplay(_ref) {
12
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
13
+ /**
14
+ * DateDisplay component to display a formatted gregorian or hijri date with optional tooltip and dropdown.
15
+ * It uses the current calendar and locale from the global context.
16
+ * It formats the date using the provided format or a default format.
17
+ * If `showAlternateDate` is true, it shows a tooltip with the formatted date.
18
+ * If `children` are provided, it wraps the date in a dropdown.
19
+ *
20
+ * @example
21
+ * ```jsx
22
+ * <DateDisplay date={new Date()} />
23
+ * ```
24
+ */
25
+ function DateDisplay(_ref) {
13
26
  var date = _ref.date,
14
27
  className = _ref.className,
15
28
  _ref$format = _ref.format,
16
29
  format = _ref$format === void 0 ? "eee, PPpp" : _ref$format,
17
30
  children = _ref.children,
31
+ showAlternateDate = _ref.showAlternateDate,
18
32
  aria = _objectWithoutProperties(_ref, _excluded);
19
- var _useGlobals = useGlobals(),
20
- currentCalendar = _useGlobals.currentCalendar,
21
- currentLocale = _useGlobals.currentLocale;
33
+ var _useApplicationContex = useApplicationContext(),
34
+ currentCalendar = _useApplicationContex.currentCalendar,
35
+ currentLocale = _useApplicationContex.currentLocale;
22
36
  var dtLabel = /*#__PURE__*/jsx(Tooltip, {
37
+ disabled: !showAlternateDate,
23
38
  content: DateUtil.format(date, format, currentLocale, currentCalendar !== "hijri"),
24
39
  children: /*#__PURE__*/jsx("span", _objectSpread(_objectSpread({
25
- className: className
40
+ className: cn(className, !!children && "underline decoration-dotted cursor-pointer")
26
41
  }, aria), {}, {
27
42
  children: DateUtil.format(date, format, currentLocale, currentCalendar === "hijri")
28
43
  }))
29
44
  });
30
45
  return children ? /*#__PURE__*/jsxs(Dropdown, {
46
+ showArrow: true,
47
+ closeOnClick: true,
31
48
  children: [dtLabel, children]
32
49
  }) : dtLabel;
33
- };
50
+ }
34
51
 
35
52
  export { DateDisplay };
@@ -0,0 +1,155 @@
1
+ 'use client';
2
+
3
+ import _defineProperty from '@babel/runtime/helpers/defineProperty';
4
+ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
5
+ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
6
+ import { Tooltip, Dropdown } from '@react-fabric/core';
7
+ import { cn, Format } from '@react-fabric/utilities';
8
+ import { intervalToDuration, isBefore } from 'date-fns';
9
+ import { useState, useEffect, useMemo } from 'react';
10
+ import { useTranslation } from 'react-i18next';
11
+ import { DateUtil } from '../utils/dateUtil.js';
12
+ import { jsx, jsxs } from 'react/jsx-runtime';
13
+
14
+ var _excluded = ["date", "children", "className", "format"];
15
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
+ /**
18
+ * DateDuration component to display the duration from a given date to now.
19
+ * It calculates the difference in years, months, weeks, days, hours, minutes, and seconds,
20
+ * and displays it in a human-readable format.
21
+ * It uses the current locale for translations.
22
+ *
23
+ * @example
24
+ * ```jsx
25
+ * <DateDuration date={new Date("2020-01-01")} />
26
+ * ```
27
+ */
28
+ function DateDuration(_ref) {
29
+ var date = _ref.date,
30
+ children = _ref.children,
31
+ className = _ref.className,
32
+ _ref$format = _ref.format,
33
+ format = _ref$format === void 0 ? "PPpp" : _ref$format,
34
+ props = _objectWithoutProperties(_ref, _excluded);
35
+ var _useTranslation = useTranslation("date"),
36
+ t = _useTranslation.t;
37
+ var _useState = useState(function () {
38
+ return {};
39
+ }),
40
+ _useState2 = _slicedToArray(_useState, 2),
41
+ dateInterval = _useState2[0],
42
+ setDateInterval = _useState2[1];
43
+ useEffect(function () {
44
+ // eslint-disable-next-line @eslint-react/set-state-in-effect
45
+ setDateInterval(intervalToDuration({
46
+ start: new Date(date),
47
+ end: new Date()
48
+ }));
49
+ // update interval every minute
50
+ var tmr = setInterval(function () {
51
+ setDateInterval(intervalToDuration({
52
+ start: new Date(date),
53
+ end: new Date()
54
+ }));
55
+ }, 60 * 1000);
56
+ return function () {
57
+ return clearInterval(tmr);
58
+ };
59
+ }, [date]);
60
+ var label = useMemo(function () {
61
+ var before = isBefore(DateUtil.parseDate(date), new Date());
62
+ var tkey = before ? "relative.before" : "relative.after";
63
+ var part = "now";
64
+ var count = 0;
65
+ if (dateInterval.years && dateInterval.years > 0) {
66
+ var _dateInterval$months;
67
+ part = "years";
68
+ count = dateInterval.years;
69
+ if (((_dateInterval$months = dateInterval.months) !== null && _dateInterval$months !== void 0 ? _dateInterval$months : 0) > 10) {
70
+ part = "yearsX";
71
+ count += 1;
72
+ }
73
+ } else if (dateInterval.months && dateInterval.months > 0) {
74
+ var _dateInterval$weeks;
75
+ part = "months";
76
+ count = dateInterval.months;
77
+ if (dateInterval.months > 10) {
78
+ part = "yearsX";
79
+ count = 1;
80
+ } else if (((_dateInterval$weeks = dateInterval.weeks) !== null && _dateInterval$weeks !== void 0 ? _dateInterval$weeks : 0) > 3) {
81
+ part = "monthsX";
82
+ count += 1;
83
+ }
84
+ } else if (dateInterval.weeks && dateInterval.weeks > 0) {
85
+ var _dateInterval$days;
86
+ part = "weeks";
87
+ count = dateInterval.weeks;
88
+ if (dateInterval.weeks > 3) {
89
+ part = "monthsX";
90
+ count = 1;
91
+ } else if (((_dateInterval$days = dateInterval.days) !== null && _dateInterval$days !== void 0 ? _dateInterval$days : 0) > 5) {
92
+ part = "weeksX";
93
+ count += 1;
94
+ }
95
+ } else if (dateInterval.days && dateInterval.days > 0) {
96
+ var _dateInterval$hours;
97
+ part = "days";
98
+ count = dateInterval.days;
99
+ if (dateInterval.days > 5) {
100
+ part = "weeksX";
101
+ count = 1;
102
+ } else if (((_dateInterval$hours = dateInterval.hours) !== null && _dateInterval$hours !== void 0 ? _dateInterval$hours : 0) > 20) {
103
+ part = "daysX";
104
+ count += 1;
105
+ }
106
+ } else if (dateInterval.hours && dateInterval.hours > 0) {
107
+ var _dateInterval$minutes;
108
+ part = "hours";
109
+ count = dateInterval.hours;
110
+ if (dateInterval.hours > 20) {
111
+ part = "daysX";
112
+ count = 1;
113
+ } else if (((_dateInterval$minutes = dateInterval.minutes) !== null && _dateInterval$minutes !== void 0 ? _dateInterval$minutes : 0) > 45) {
114
+ part = "hoursX";
115
+ count += 1;
116
+ }
117
+ } else if (dateInterval.minutes && dateInterval.minutes > 0) {
118
+ var _dateInterval$seconds;
119
+ part = "minutes";
120
+ count = dateInterval.minutes;
121
+ if (dateInterval.minutes > 45) {
122
+ part = "hoursX";
123
+ count = 1;
124
+ } else if (((_dateInterval$seconds = dateInterval.seconds) !== null && _dateInterval$seconds !== void 0 ? _dateInterval$seconds : 0) > 45) {
125
+ part = "minuteX";
126
+ count += 1;
127
+ }
128
+ } else if (dateInterval.seconds && dateInterval.seconds > 15) {
129
+ part = "seconds";
130
+ count = dateInterval.seconds;
131
+ if (dateInterval.seconds > 45) {
132
+ part = "minutesX";
133
+ count = 1;
134
+ }
135
+ }
136
+ return t("".concat(tkey, ".").concat(part), {
137
+ count: count
138
+ });
139
+ }, [date, dateInterval.days, dateInterval.hours, dateInterval.minutes, dateInterval.months, dateInterval.seconds, dateInterval.weeks, dateInterval.years, t]);
140
+ var dtLabel = /*#__PURE__*/jsx(Tooltip, {
141
+ content: Format.date(date, format),
142
+ children: /*#__PURE__*/jsx("span", _objectSpread(_objectSpread({
143
+ className: cn(className, !!children && "underline decoration-dotted cursor-pointer")
144
+ }, props), {}, {
145
+ children: label
146
+ }))
147
+ });
148
+ return children ? /*#__PURE__*/jsxs(Dropdown, {
149
+ showArrow: true,
150
+ closeOnClick: true,
151
+ children: [dtLabel, children]
152
+ }) : dtLabel;
153
+ }
154
+
155
+ export { DateDuration };
@@ -0,0 +1,152 @@
1
+ 'use client';
2
+
3
+ function intPart(floatNum) {
4
+ if (floatNum < -1e-7) {
5
+ return Math.ceil(floatNum - 0.0000001);
6
+ }
7
+ return Math.floor(floatNum + 0.0000001);
8
+ }
9
+ var delta = 1;
10
+ function GregToIsl(arg) {
11
+ var d = parseInt(arg.CDay.value);
12
+ var m = parseInt(arg.CMonth.value);
13
+ var y = parseInt(arg.CYear.value);
14
+ var jd,
15
+ l,
16
+ jd1,
17
+ n,
18
+ j,
19
+ delta = 1;
20
+ if (y > 1582 || y == 1582 && m > 10 || y == 1582 && m == 10 && d > 14) {
21
+ //added delta=1 on jd to comply isna rulling 2007
22
+ jd = intPart(1461 * (y + 4800 + intPart((m - 14) / 12)) / 4) + intPart(367 * (m - 2 - 12 * intPart((m - 14) / 12)) / 12) - intPart(3 * intPart((y + 4900 + intPart((m - 14) / 12)) / 100) / 4) + d - 32075 + delta;
23
+ } else {
24
+ //added +1 on jd to comply isna rulling
25
+ jd = 367 * y - intPart(7 * (y + 5001 + intPart((m - 9) / 7)) / 4) + intPart(275 * m / 9) + d + 1729777 + delta;
26
+ }
27
+
28
+ //added -1 on jd1 to comply isna rulling
29
+ jd1 = jd - delta;
30
+ l = jd - 1948440 + 10632;
31
+ n = intPart((l - 1) / 10631);
32
+ l = l - 10631 * n + 354;
33
+ j = intPart((10985 - l) / 5316) * intPart(50 * l / 17719) + intPart(l / 5670) * intPart(43 * l / 15238);
34
+ l = l - intPart((30 - j) / 15) * intPart(17719 * j / 50) - intPart(j / 16) * intPart(15238 * j / 43) + 29;
35
+ m = intPart(24 * l / 709);
36
+ d = l - intPart(709 * m / 24);
37
+ y = 30 * n + j - 30;
38
+ return {
39
+ d: d,
40
+ m: m,
41
+ y: y,
42
+ dateOfWeek: jd1 % 7,
43
+ dayName: weekDay(jd1 % 7)
44
+ };
45
+ }
46
+ function IslToGreg(arg) {
47
+ var d = parseInt(arg.HDay.value);
48
+ var m = parseInt(arg.HMonth.value);
49
+ var y = parseInt(arg.HYear.value);
50
+ //added - delta=1 on jd to comply isna rulling
51
+ var jd = intPart((11 * y + 3) / 30) + 354 * y + 30 * m - intPart((m - 1) / 2) + d + 1948440 - 385 - delta;
52
+ var l, n, i, j, k;
53
+ if (jd > 2299160) {
54
+ l = jd + 68569;
55
+ n = intPart(4 * l / 146097);
56
+ l = l - intPart((146097 * n + 3) / 4);
57
+ i = intPart(4000 * (l + 1) / 1461001);
58
+ l = l - intPart(1461 * i / 4) + 31;
59
+ j = intPart(80 * l / 2447);
60
+ d = l - intPart(2447 * j / 80);
61
+ l = intPart(j / 11);
62
+ m = j + 2 - 12 * l;
63
+ y = 100 * (n - 49) + i + l;
64
+ } else {
65
+ j = jd + 1402;
66
+ k = intPart((j - 1) / 1461);
67
+ l = j - 1461 * k;
68
+ n = intPart((l - 1) / 365) - intPart(l / 1461);
69
+ i = l - 365 * n + 30;
70
+ j = intPart(80 * i / 2447);
71
+ d = i - intPart(2447 * j / 80);
72
+ i = intPart(j / 11);
73
+ m = j + 2 - 12 * i;
74
+ y = 4 * k + n + i - 4716;
75
+ }
76
+
77
+ //arg.CDay.value=d
78
+ //arg.CMonth.value=m
79
+ //arg.CYear.value=y
80
+
81
+ return {
82
+ d: d,
83
+ m: m,
84
+ y: y,
85
+ dateOfWeek: jd % 7,
86
+ dayName: weekDay(jd % 7)
87
+ };
88
+ }
89
+ function weekDay(wdn) {
90
+ if (wdn == 0) {
91
+ return "Mon";
92
+ }
93
+ if (wdn == 1) {
94
+ return "Tue";
95
+ }
96
+ if (wdn == 2) {
97
+ return "Wed";
98
+ }
99
+ if (wdn == 3) {
100
+ return "Thu";
101
+ }
102
+ if (wdn == 4) {
103
+ return "Fri";
104
+ }
105
+ if (wdn == 5) {
106
+ return "Sat";
107
+ }
108
+ if (wdn == 6) {
109
+ return "Sun";
110
+ }
111
+ return "";
112
+ }
113
+ function GregToHijri(gregDate) {
114
+ var hijriDate = GregToIsl({
115
+ CDay: {
116
+ value: gregDate.getDate()
117
+ },
118
+ CYear: {
119
+ value: gregDate.getFullYear()
120
+ },
121
+ CMonth: {
122
+ value: gregDate.getMonth() + 1
123
+ }
124
+ });
125
+ return {
126
+ year: hijriDate.y,
127
+ month: hijriDate.m,
128
+ date: hijriDate.d,
129
+ hours: gregDate.getHours(),
130
+ minutes: gregDate.getMinutes(),
131
+ seconds: gregDate.getSeconds(),
132
+ milliseconds: gregDate.getMilliseconds(),
133
+ day: hijriDate.dateOfWeek,
134
+ dayName: hijriDate.dayName
135
+ };
136
+ }
137
+ function HijriToGreg(hijriDate) {
138
+ var gregDate = IslToGreg({
139
+ HDay: {
140
+ value: hijriDate._date || hijriDate.date
141
+ },
142
+ HYear: {
143
+ value: hijriDate._year || hijriDate.year
144
+ },
145
+ HMonth: {
146
+ value: hijriDate._month || hijriDate.month
147
+ }
148
+ });
149
+ return new Date(gregDate.y, gregDate.m - 1, gregDate.d, hijriDate.getHours(), hijriDate.getMinutes(), hijriDate.getSeconds(), hijriDate.getMilliseconds());
150
+ }
151
+
152
+ export { GregToHijri, HijriToGreg, weekDay };