@levelcaptech/gantt-task-react-custom 0.4.1 → 0.4.2

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.
@@ -1786,6 +1786,157 @@ var VerticalScroll = function VerticalScroll(_ref) {
1786
1786
  }));
1787
1787
  };
1788
1788
 
1789
+ var JP_HOLIDAYS = {
1790
+ 2024: ["2024-01-01", "2024-01-08", "2024-02-11", "2024-02-12", "2024-02-23", "2024-03-20", "2024-04-29", "2024-05-03", "2024-05-04", "2024-05-05", "2024-05-06", "2024-07-15", "2024-08-11", "2024-08-12", "2024-09-16", "2024-09-22", "2024-09-23", "2024-10-14", "2024-11-03", "2024-11-04", "2024-11-23"],
1791
+ 2025: ["2025-01-01", "2025-01-13", "2025-02-11", "2025-02-23", "2025-02-24", "2025-03-20", "2025-04-29", "2025-05-03", "2025-05-04", "2025-05-05", "2025-05-06", "2025-07-21", "2025-08-11", "2025-09-15", "2025-09-23", "2025-10-13", "2025-11-03", "2025-11-23", "2025-11-24"],
1792
+ 2026: ["2026-01-01", "2026-01-12", "2026-02-11", "2026-02-23", "2026-03-20", "2026-04-29", "2026-05-03", "2026-05-04", "2026-05-05", "2026-05-06", "2026-07-20", "2026-08-11", "2026-09-21", "2026-09-22", "2026-10-12", "2026-11-03", "2026-11-23"]
1793
+ };
1794
+ var getJPHolidaySet = function getJPHolidaySet() {
1795
+ var holidays = new Set();
1796
+ Object.values(JP_HOLIDAYS).forEach(function (yearHolidays) {
1797
+ yearHolidays.forEach(function (holiday) {
1798
+ return holidays.add(holiday);
1799
+ });
1800
+ });
1801
+ return holidays;
1802
+ };
1803
+ var JP_HOLIDAYS_SET = getJPHolidaySet();
1804
+
1805
+ var emittedWarnings = new Set();
1806
+ var warnOnce = function warnOnce(key, message) {
1807
+ if (!emittedWarnings.has(key) && typeof console !== "undefined") {
1808
+ console.warn(message);
1809
+ emittedWarnings.add(key);
1810
+ }
1811
+ };
1812
+ var normalizeCalendarConfig = function normalizeCalendarConfig(config) {
1813
+ var _config$locale, _config$enableJPHolid, _config$highlightNonW;
1814
+ var rawLocale = ((_config$locale = config.locale) === null || _config$locale === void 0 ? void 0 : _config$locale.trim()) || "";
1815
+ var locale = rawLocale || "ja";
1816
+ var dateFormat = config.dateFormat || "MM/dd(EEE)";
1817
+ var enableJPHoliday = (_config$enableJPHolid = config.enableJPHoliday) != null ? _config$enableJPHolid : true;
1818
+ var highlightNonWorkingDays = (_config$highlightNonW = config.highlightNonWorkingDays) != null ? _config$highlightNonW : true;
1819
+ var workOnSaturday = config.workOnSaturday === true;
1820
+ var extraHolidays = new Set();
1821
+ if (config.extraHolidays) {
1822
+ config.extraHolidays.forEach(function (dateStr) {
1823
+ var normalized = normalizeISODate(dateStr);
1824
+ if (normalized) {
1825
+ extraHolidays.add(normalized);
1826
+ }
1827
+ });
1828
+ }
1829
+ var extraWorkingDays = new Set();
1830
+ if (config.extraWorkingDays) {
1831
+ config.extraWorkingDays.forEach(function (dateStr) {
1832
+ var normalized = normalizeISODate(dateStr);
1833
+ if (normalized) {
1834
+ extraWorkingDays.add(normalized);
1835
+ }
1836
+ });
1837
+ }
1838
+ if (!locale.toLowerCase().startsWith("ja")) {
1839
+ var localeKey = locale.trim().toLowerCase();
1840
+ warnOnce("gantt-calendar-locale-" + localeKey, "[Gantt Calendar] Non-Japanese locale \"" + locale + "\" specified. " + "Holiday definitions (including Japanese public holidays) are still based on the Japanese calendar.");
1841
+ }
1842
+ if (dateFormat !== "MM/dd(EEE)") {
1843
+ var dateFormatKey = dateFormat.trim().toLowerCase();
1844
+ warnOnce("gantt-calendar-dateFormat-" + dateFormatKey, "[Gantt Calendar] Custom dateFormat \"" + dateFormat + "\" specified. " + "Note: dateFormat is currently a legacy field and does not affect date rendering. " + "The format \"MM/dd(EEE)\" is used internally regardless of this setting.");
1845
+ }
1846
+ return {
1847
+ locale: locale,
1848
+ dateFormat: dateFormat,
1849
+ enableJPHoliday: enableJPHoliday,
1850
+ highlightNonWorkingDays: highlightNonWorkingDays,
1851
+ workOnSaturday: workOnSaturday,
1852
+ extraHolidays: extraHolidays,
1853
+ extraWorkingDays: extraWorkingDays
1854
+ };
1855
+ };
1856
+ var normalizeISODate = function normalizeISODate(dateStr) {
1857
+ try {
1858
+ var trimmed = dateStr.trim();
1859
+ if (!/^\d{4}-\d{1,2}-\d{1,2}$/.test(trimmed)) {
1860
+ return null;
1861
+ }
1862
+ var parts = trimmed.split("-");
1863
+ if (parts.length !== 3) return null;
1864
+ var year = Number(parts[0]);
1865
+ var month = Number(parts[1]);
1866
+ var day = Number(parts[2]);
1867
+ if (isNaN(year) || isNaN(month) || isNaN(day) || month < 1 || month > 12 || day < 1 || day > 31) {
1868
+ return null;
1869
+ }
1870
+ var date = new Date(year, month - 1, day);
1871
+ if (date.getFullYear() !== year || date.getMonth() !== month - 1 || date.getDate() !== day) {
1872
+ return null;
1873
+ }
1874
+ var paddedMonth = String(month).padStart(2, "0");
1875
+ var paddedDay = String(day).padStart(2, "0");
1876
+ return year + "-" + paddedMonth + "-" + paddedDay;
1877
+ } catch (e) {
1878
+ if (typeof console !== "undefined") {
1879
+ console.warn("[Gantt Calendar] Invalid date string: " + dateStr);
1880
+ }
1881
+ return null;
1882
+ }
1883
+ };
1884
+ var toISODateString = function toISODateString(date) {
1885
+ var year = date.getFullYear();
1886
+ var month = String(date.getMonth() + 1).padStart(2, "0");
1887
+ var day = String(date.getDate()).padStart(2, "0");
1888
+ return year + "-" + month + "-" + day;
1889
+ };
1890
+ var isWorkingDay = function isWorkingDay(date, config) {
1891
+ var dateStr = toISODateString(date);
1892
+ if (config.extraWorkingDays.has(dateStr)) {
1893
+ return true;
1894
+ }
1895
+ if (config.extraHolidays.has(dateStr)) {
1896
+ return false;
1897
+ }
1898
+ var dayOfWeek = date.getDay();
1899
+ if (dayOfWeek === 0) {
1900
+ return false;
1901
+ }
1902
+ if (dayOfWeek === 6 && !config.workOnSaturday) {
1903
+ return false;
1904
+ }
1905
+ if (config.enableJPHoliday) {
1906
+ if (JP_HOLIDAYS_SET.has(dateStr)) {
1907
+ return false;
1908
+ }
1909
+ }
1910
+ return true;
1911
+ };
1912
+ var formatJapaneseDate = function formatJapaneseDate(date) {
1913
+ try {
1914
+ var formatter = new Intl.DateTimeFormat("ja", {
1915
+ month: "2-digit",
1916
+ day: "2-digit",
1917
+ weekday: "short"
1918
+ });
1919
+ var parts = formatter.formatToParts(date);
1920
+ var month = "";
1921
+ var day = "";
1922
+ var weekday = "";
1923
+ parts.forEach(function (part) {
1924
+ if (part.type === "month") {
1925
+ month = part.value;
1926
+ } else if (part.type === "day") {
1927
+ day = part.value;
1928
+ } else if (part.type === "weekday") {
1929
+ weekday = part.value;
1930
+ }
1931
+ });
1932
+ return month + "/" + day + "(" + weekday + ")";
1933
+ } catch (e) {
1934
+ var _month = String(date.getMonth() + 1).padStart(2, "0");
1935
+ var _day = String(date.getDate()).padStart(2, "0");
1936
+ return _month + "/" + _day;
1937
+ }
1938
+ };
1939
+
1789
1940
  var styles$4 = {"gridRow":"_2dZTy","gridRowLine":"_3rUKi","gridTick":"_RuwuK"};
1790
1941
 
1791
1942
  var GridBody = function GridBody(_ref) {
@@ -1795,7 +1946,8 @@ var GridBody = function GridBody(_ref) {
1795
1946
  svgWidth = _ref.svgWidth,
1796
1947
  columnWidth = _ref.columnWidth,
1797
1948
  todayColor = _ref.todayColor,
1798
- rtl = _ref.rtl;
1949
+ rtl = _ref.rtl,
1950
+ calendarConfig = _ref.calendarConfig;
1799
1951
  var y = 0;
1800
1952
  var gridRows = [];
1801
1953
  var rowLines = [React.createElement("line", {
@@ -1829,6 +1981,7 @@ var GridBody = function GridBody(_ref) {
1829
1981
  var now = new Date();
1830
1982
  var tickX = 0;
1831
1983
  var ticks = [];
1984
+ var nonWorkingDays = [];
1832
1985
  var today = React.createElement("rect", null);
1833
1986
  for (var i = 0; i < dates.length; i++) {
1834
1987
  var date = dates[i];
@@ -1840,6 +1993,16 @@ var GridBody = function GridBody(_ref) {
1840
1993
  y2: y,
1841
1994
  className: styles$4.gridTick
1842
1995
  }));
1996
+ if (calendarConfig && calendarConfig.highlightNonWorkingDays && !isWorkingDay(date, calendarConfig)) {
1997
+ nonWorkingDays.push(React.createElement("rect", {
1998
+ key: "non-working-" + date.getTime(),
1999
+ x: tickX,
2000
+ y: 0,
2001
+ width: columnWidth,
2002
+ height: y,
2003
+ fill: "rgba(0, 0, 0, 0.05)"
2004
+ }));
2005
+ }
1843
2006
  if (i + 1 !== dates.length && date.getTime() < now.getTime() && dates[i + 1].getTime() >= now.getTime() || i !== 0 && i + 1 === dates.length && date.getTime() < now.getTime() && addToDate(date, date.getTime() - dates[i - 1].getTime(), "millisecond").getTime() >= now.getTime()) {
1844
2007
  today = React.createElement("rect", {
1845
2008
  x: tickX,
@@ -1865,6 +2028,8 @@ var GridBody = function GridBody(_ref) {
1865
2028
  }, React.createElement("g", {
1866
2029
  className: "rows"
1867
2030
  }, gridRows), React.createElement("g", {
2031
+ className: "nonWorkingDays"
2032
+ }, nonWorkingDays), React.createElement("g", {
1868
2033
  className: "rowLines"
1869
2034
  }, rowLines), React.createElement("g", {
1870
2035
  className: "ticks"
@@ -1913,7 +2078,9 @@ var Calendar = function Calendar(_ref) {
1913
2078
  headerHeight = _ref.headerHeight,
1914
2079
  columnWidth = _ref.columnWidth,
1915
2080
  fontFamily = _ref.fontFamily,
1916
- fontSize = _ref.fontSize;
2081
+ fontSize = _ref.fontSize,
2082
+ calendarConfig = _ref.calendarConfig;
2083
+ var effectiveLocale = (calendarConfig === null || calendarConfig === void 0 ? void 0 : calendarConfig.locale) || locale;
1917
2084
  var getCalendarValuesForYear = function getCalendarValuesForYear() {
1918
2085
  var topValues = [];
1919
2086
  var bottomValues = [];
@@ -1988,7 +2155,7 @@ var Calendar = function Calendar(_ref) {
1988
2155
  var topDefaultHeight = headerHeight * 0.5;
1989
2156
  for (var i = 0; i < dateSetup.dates.length; i++) {
1990
2157
  var date = dateSetup.dates[i];
1991
- var bottomValue = getLocaleMonth(date, locale);
2158
+ var bottomValue = getLocaleMonth(date, effectiveLocale);
1992
2159
  bottomValues.push(React.createElement("text", {
1993
2160
  key: bottomValue + date.getFullYear(),
1994
2161
  y: headerHeight * 0.8,
@@ -2026,7 +2193,7 @@ var Calendar = function Calendar(_ref) {
2026
2193
  var date = dates[i];
2027
2194
  var topValue = "";
2028
2195
  if (i === 0 || date.getMonth() !== dates[i - 1].getMonth()) {
2029
- topValue = getLocaleMonth(date, locale) + ", " + date.getFullYear();
2196
+ topValue = getLocaleMonth(date, effectiveLocale) + ", " + date.getFullYear();
2030
2197
  }
2031
2198
  var bottomValue = "W" + getWeekNumberISO8601(date);
2032
2199
  bottomValues.push(React.createElement("text", {
@@ -2060,7 +2227,8 @@ var Calendar = function Calendar(_ref) {
2060
2227
  var dates = dateSetup.dates;
2061
2228
  for (var i = 0; i < dates.length; i++) {
2062
2229
  var date = dates[i];
2063
- var bottomValue = getLocalDayOfWeek(date, locale, "short") + ", " + date.getDate().toString();
2230
+ var useJapaneseFormat = !!calendarConfig && typeof calendarConfig.locale === "string" && calendarConfig.locale.toLowerCase().startsWith("ja");
2231
+ var bottomValue = useJapaneseFormat ? formatJapaneseDate(date) : getLocalDayOfWeek(date, effectiveLocale, "short") + ", " + date.getDate().toString();
2064
2232
  bottomValues.push(React.createElement("text", {
2065
2233
  key: date.getTime(),
2066
2234
  y: headerHeight * 0.8,
@@ -2068,7 +2236,7 @@ var Calendar = function Calendar(_ref) {
2068
2236
  className: styles$5.calendarBottomText
2069
2237
  }, bottomValue));
2070
2238
  if (i + 1 !== dates.length && date.getMonth() !== dates[i + 1].getMonth()) {
2071
- var topValue = getLocaleMonth(date, locale);
2239
+ var topValue = getLocaleMonth(date, effectiveLocale);
2072
2240
  topValues.push(React.createElement(TopPartOfCalendar, {
2073
2241
  key: topValue + date.getFullYear(),
2074
2242
  value: topValue,
@@ -2090,7 +2258,7 @@ var Calendar = function Calendar(_ref) {
2090
2258
  var dates = dateSetup.dates;
2091
2259
  for (var i = 0; i < dates.length; i++) {
2092
2260
  var date = dates[i];
2093
- var bottomValue = getCachedDateTimeFormat(locale, {
2261
+ var bottomValue = getCachedDateTimeFormat(effectiveLocale, {
2094
2262
  hour: "numeric"
2095
2263
  }).format(date);
2096
2264
  bottomValues.push(React.createElement("text", {
@@ -2101,7 +2269,7 @@ var Calendar = function Calendar(_ref) {
2101
2269
  fontFamily: fontFamily
2102
2270
  }, bottomValue));
2103
2271
  if (i === 0 || date.getDate() !== dates[i - 1].getDate()) {
2104
- var topValue = getLocalDayOfWeek(date, locale, "short") + ", " + date.getDate() + " " + getLocaleMonth(date, locale);
2272
+ var topValue = getLocalDayOfWeek(date, effectiveLocale, "short") + ", " + date.getDate() + " " + getLocaleMonth(date, effectiveLocale);
2105
2273
  topValues.push(React.createElement(TopPartOfCalendar, {
2106
2274
  key: topValue + date.getFullYear(),
2107
2275
  value: topValue,
@@ -2122,7 +2290,7 @@ var Calendar = function Calendar(_ref) {
2122
2290
  var dates = dateSetup.dates;
2123
2291
  for (var i = 0; i < dates.length; i++) {
2124
2292
  var date = dates[i];
2125
- var bottomValue = getCachedDateTimeFormat(locale, {
2293
+ var bottomValue = getCachedDateTimeFormat(effectiveLocale, {
2126
2294
  hour: "numeric"
2127
2295
  }).format(date);
2128
2296
  bottomValues.push(React.createElement("text", {
@@ -2134,7 +2302,7 @@ var Calendar = function Calendar(_ref) {
2134
2302
  }, bottomValue));
2135
2303
  if (i !== 0 && date.getDate() !== dates[i - 1].getDate()) {
2136
2304
  var displayDate = dates[i - 1];
2137
- var topValue = getLocalDayOfWeek(displayDate, locale, "long") + ", " + displayDate.getDate() + " " + getLocaleMonth(displayDate, locale);
2305
+ var topValue = getLocalDayOfWeek(displayDate, effectiveLocale, "long") + ", " + displayDate.getDate() + " " + getLocaleMonth(displayDate, effectiveLocale);
2138
2306
  var topPosition = (date.getHours() - 24) / 2;
2139
2307
  topValues.push(React.createElement(TopPartOfCalendar, {
2140
2308
  key: topValue + displayDate.getFullYear(),
@@ -3304,6 +3472,7 @@ var Gantt = function Gantt(_ref) {
3304
3472
  preStepsCount = _ref$preStepsCount === void 0 ? 1 : _ref$preStepsCount,
3305
3473
  _ref$locale = _ref.locale,
3306
3474
  locale = _ref$locale === void 0 ? "en-GB" : _ref$locale,
3475
+ calendar = _ref.calendar,
3307
3476
  _ref$barFill = _ref.barFill,
3308
3477
  barFill = _ref$barFill === void 0 ? 60 : _ref$barFill,
3309
3478
  _ref$barCornerRadius = _ref.barCornerRadius,
@@ -3365,6 +3534,9 @@ var Gantt = function Gantt(_ref) {
3365
3534
  onExpanderClick = _ref.onExpanderClick,
3366
3535
  onTaskUpdate = _ref.onTaskUpdate,
3367
3536
  onCellCommit = _ref.onCellCommit;
3537
+ var calendarConfig = useMemo(function () {
3538
+ return calendar ? normalizeCalendarConfig(calendar) : undefined;
3539
+ }, [calendar]);
3368
3540
  var wrapperRef = useRef(null);
3369
3541
  var taskListRef = useRef(null);
3370
3542
  var taskListHeaderRef = useRef(null);
@@ -3778,7 +3950,8 @@ var Gantt = function Gantt(_ref) {
3778
3950
  rowHeight: rowHeight,
3779
3951
  dates: dateSetup.dates,
3780
3952
  todayColor: todayColor,
3781
- rtl: rtl
3953
+ rtl: rtl,
3954
+ calendarConfig: calendarConfig
3782
3955
  };
3783
3956
  var calendarProps = {
3784
3957
  dateSetup: dateSetup,
@@ -3788,7 +3961,8 @@ var Gantt = function Gantt(_ref) {
3788
3961
  columnWidth: columnWidth,
3789
3962
  fontFamily: fontFamily,
3790
3963
  fontSize: fontSize,
3791
- rtl: rtl
3964
+ rtl: rtl,
3965
+ calendarConfig: calendarConfig
3792
3966
  };
3793
3967
  var barProps = {
3794
3968
  tasks: barTasks,