@lazerlen/legend-calendar 1.3.0 → 1.4.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.
package/dist/index.mjs CHANGED
@@ -1867,6 +1867,9 @@ var useCalendarList = (t0) => {
1867
1867
  let t3;
1868
1868
  if ($[10] !== calendarFirstDayOfWeek || $[11] !== calendarMaxDateId || $[12] !== monthList) {
1869
1869
  t3 = (numberOfMonths) => {
1870
+ if (numberOfMonths <= 0) {
1871
+ return monthList;
1872
+ }
1870
1873
  const startingMonth_0 = addMonths(monthList[monthList.length - 1].date, 1);
1871
1874
  const endingMonth_0 = getEndingMonth(Math.max(numberOfMonths - 1, 0), calendarMaxDateId, startingMonth_0);
1872
1875
  const hasReachedEndingMonth = monthList.find((m) => m.id === toDateId(endingMonth_0));
@@ -1892,6 +1895,9 @@ var useCalendarList = (t0) => {
1892
1895
  let t4;
1893
1896
  if ($[14] !== calendarFirstDayOfWeek || $[15] !== calendarMinDateId || $[16] !== monthList) {
1894
1897
  t4 = (numberOfMonths_0) => {
1898
+ if (numberOfMonths_0 <= 0) {
1899
+ return monthList;
1900
+ }
1895
1901
  const endingMonth_1 = subMonths(monthList[0].date, 1);
1896
1902
  const startingMonth_1 = getStartingMonth(Math.max(numberOfMonths_0 - 1, 0), calendarMinDateId, endingMonth_1);
1897
1903
  const hasReachedStartingMonth = monthList.find((m_0) => m_0.id === toDateId(startingMonth_1));
@@ -1991,7 +1997,7 @@ import { jsx as _jsx10 } from "react/jsx-runtime";
1991
1997
  var LegendList = LegendListBase;
1992
1998
  var keyExtractor = (month) => month.id;
1993
1999
  function CalendarList(t0) {
1994
- const $ = _c12(42);
2000
+ const $ = _c12(49);
1995
2001
  const _a = t0, {
1996
2002
  ref
1997
2003
  } = _a, props = __objRest(_a, [
@@ -1999,23 +2005,25 @@ function CalendarList(t0) {
1999
2005
  ]);
2000
2006
  const _b = props, {
2001
2007
  calendarInitialMonthId,
2002
- calendarPastScrollRangeInMonths: t1,
2003
- calendarFutureScrollRangeInMonths: t2,
2004
- calendarFirstDayOfWeek: t3,
2008
+ calendarInitialScrollToActiveRange: t1,
2009
+ calendarPastScrollRangeInMonths: t2,
2010
+ calendarFutureScrollRangeInMonths: t3,
2011
+ calendarFirstDayOfWeek: t4,
2005
2012
  calendarFormatLocale,
2006
- calendarSpacing: t4,
2013
+ calendarSpacing: t5,
2007
2014
  calendarRowHorizontalSpacing,
2008
- calendarRowVerticalSpacing: t5,
2009
- calendarMonthHeaderHeight: t6,
2010
- calendarDayHeight: t7,
2011
- calendarWeekHeaderHeight: t8,
2012
- calendarAdditionalHeight: t9,
2015
+ calendarRowVerticalSpacing: t6,
2016
+ calendarMonthHeaderHeight: t7,
2017
+ calendarDayHeight: t8,
2018
+ calendarWeekHeaderHeight: t9,
2019
+ calendarAdditionalHeight: t10,
2013
2020
  calendarColorScheme,
2014
2021
  theme,
2015
2022
  onEndReached,
2016
2023
  onStartReached
2017
2024
  } = _b, otherProps = __objRest(_b, [
2018
2025
  "calendarInitialMonthId",
2026
+ "calendarInitialScrollToActiveRange",
2019
2027
  "calendarPastScrollRangeInMonths",
2020
2028
  "calendarFutureScrollRangeInMonths",
2021
2029
  "calendarFirstDayOfWeek",
@@ -2032,15 +2040,16 @@ function CalendarList(t0) {
2032
2040
  "onEndReached",
2033
2041
  "onStartReached"
2034
2042
  ]);
2035
- const calendarPastScrollRangeInMonths = t1 === void 0 ? 12 : t1;
2036
- const calendarFutureScrollRangeInMonths = t2 === void 0 ? 12 : t2;
2037
- const calendarFirstDayOfWeek = t3 === void 0 ? "sunday" : t3;
2038
- const calendarSpacing = t4 === void 0 ? 20 : t4;
2039
- const calendarRowVerticalSpacing = t5 === void 0 ? 8 : t5;
2040
- const calendarMonthHeaderHeight = t6 === void 0 ? 20 : t6;
2041
- const calendarDayHeight = t7 === void 0 ? 32 : t7;
2042
- const calendarWeekHeaderHeight = t8 === void 0 ? calendarDayHeight : t8;
2043
- const calendarAdditionalHeight = t9 === void 0 ? 0 : t9;
2043
+ const calendarInitialScrollToActiveRange = t1 === void 0 ? true : t1;
2044
+ const calendarPastScrollRangeInMonths = t2 === void 0 ? 12 : t2;
2045
+ const calendarFutureScrollRangeInMonths = t3 === void 0 ? 12 : t3;
2046
+ const calendarFirstDayOfWeek = t4 === void 0 ? "sunday" : t4;
2047
+ const calendarSpacing = t5 === void 0 ? 20 : t5;
2048
+ const calendarRowVerticalSpacing = t6 === void 0 ? 8 : t6;
2049
+ const calendarMonthHeaderHeight = t7 === void 0 ? 20 : t7;
2050
+ const calendarDayHeight = t8 === void 0 ? 32 : t8;
2051
+ const calendarWeekHeaderHeight = t9 === void 0 ? calendarDayHeight : t9;
2052
+ const calendarAdditionalHeight = t10 === void 0 ? 0 : t10;
2044
2053
  const _c14 = otherProps, {
2045
2054
  calendarActiveDateRanges,
2046
2055
  calendarDisabledDateIds,
@@ -2101,50 +2110,87 @@ function CalendarList(t0) {
2101
2110
  calendarMaxDateId,
2102
2111
  calendarMinDateId
2103
2112
  });
2104
- const monthListWithCalendarProps = monthList.map((month) => __spreadProps(__spreadValues({}, month), {
2113
+ let computedInitialScrollIndex = initialMonthIndex;
2114
+ if (calendarInitialScrollToActiveRange && calendarActiveDateRanges) {
2115
+ const firstRange = calendarActiveDateRanges[0];
2116
+ if (firstRange == null ? void 0 : firstRange.startId) {
2117
+ let t112;
2118
+ if ($[0] !== firstRange.startId) {
2119
+ const startDate = fromDateId(firstRange.startId);
2120
+ t112 = toDateId(startOfMonth(startDate));
2121
+ $[0] = firstRange.startId;
2122
+ $[1] = t112;
2123
+ } else {
2124
+ t112 = $[1];
2125
+ }
2126
+ const monthId = t112;
2127
+ let t122;
2128
+ if ($[2] !== monthId || $[3] !== monthList) {
2129
+ let t132;
2130
+ if ($[5] !== monthId) {
2131
+ t132 = (month) => month.id === monthId;
2132
+ $[5] = monthId;
2133
+ $[6] = t132;
2134
+ } else {
2135
+ t132 = $[6];
2136
+ }
2137
+ t122 = monthList.findIndex(t132);
2138
+ $[2] = monthId;
2139
+ $[3] = monthList;
2140
+ $[4] = t122;
2141
+ } else {
2142
+ t122 = $[4];
2143
+ }
2144
+ const monthIndex = t122;
2145
+ if (monthIndex !== -1) {
2146
+ computedInitialScrollIndex = monthIndex;
2147
+ }
2148
+ }
2149
+ }
2150
+ const monthListWithCalendarProps = monthList.map((month_0) => __spreadProps(__spreadValues({}, month_0), {
2105
2151
  calendarProps
2106
2152
  }));
2107
- let t10;
2108
- if ($[0] !== appendMonths || $[1] !== calendarFutureScrollRangeInMonths || $[2] !== onEndReached) {
2109
- t10 = (info) => {
2153
+ let t11;
2154
+ if ($[7] !== appendMonths || $[8] !== calendarFutureScrollRangeInMonths || $[9] !== onEndReached) {
2155
+ t11 = (info) => {
2110
2156
  appendMonths(calendarFutureScrollRangeInMonths);
2111
2157
  onEndReached == null ? void 0 : onEndReached(info);
2112
2158
  };
2113
- $[0] = appendMonths;
2114
- $[1] = calendarFutureScrollRangeInMonths;
2115
- $[2] = onEndReached;
2116
- $[3] = t10;
2159
+ $[7] = appendMonths;
2160
+ $[8] = calendarFutureScrollRangeInMonths;
2161
+ $[9] = onEndReached;
2162
+ $[10] = t11;
2117
2163
  } else {
2118
- t10 = $[3];
2164
+ t11 = $[10];
2119
2165
  }
2120
- const handleOnEndReached = t10;
2121
- let t11;
2122
- if ($[4] !== calendarPastScrollRangeInMonths || $[5] !== onStartReached || $[6] !== prependMonths) {
2123
- t11 = (info_0) => {
2166
+ const handleOnEndReached = t11;
2167
+ let t12;
2168
+ if ($[11] !== calendarPastScrollRangeInMonths || $[12] !== onStartReached || $[13] !== prependMonths) {
2169
+ t12 = (info_0) => {
2124
2170
  prependMonths(calendarPastScrollRangeInMonths);
2125
2171
  onStartReached == null ? void 0 : onStartReached(info_0);
2126
2172
  };
2127
- $[4] = calendarPastScrollRangeInMonths;
2128
- $[5] = onStartReached;
2129
- $[6] = prependMonths;
2130
- $[7] = t11;
2173
+ $[11] = calendarPastScrollRangeInMonths;
2174
+ $[12] = onStartReached;
2175
+ $[13] = prependMonths;
2176
+ $[14] = t12;
2131
2177
  } else {
2132
- t11 = $[7];
2178
+ t12 = $[14];
2133
2179
  }
2134
- const handleOnStartReached = t11;
2135
- let t12;
2136
- if ($[8] !== addMissingMonths || $[9] !== calendarAdditionalHeight || $[10] !== calendarDayHeight || $[11] !== calendarMonthHeaderHeight || $[12] !== calendarRowVerticalSpacing || $[13] !== calendarSpacing || $[14] !== calendarWeekHeaderHeight || $[15] !== monthList) {
2137
- t12 = (date) => {
2138
- const monthId = toDateId(startOfMonth(date));
2180
+ const handleOnStartReached = t12;
2181
+ let t13;
2182
+ if ($[15] !== addMissingMonths || $[16] !== calendarAdditionalHeight || $[17] !== calendarDayHeight || $[18] !== calendarMonthHeaderHeight || $[19] !== calendarRowVerticalSpacing || $[20] !== calendarSpacing || $[21] !== calendarWeekHeaderHeight || $[22] !== monthList) {
2183
+ t13 = (date) => {
2184
+ const monthId_0 = toDateId(startOfMonth(date));
2139
2185
  let baseMonthList = monthList;
2140
- let index = baseMonthList.findIndex((month_0) => month_0.id === monthId);
2186
+ let index = baseMonthList.findIndex((month_1) => month_1.id === monthId_0);
2141
2187
  if (index === -1) {
2142
- baseMonthList = addMissingMonths(monthId);
2143
- index = baseMonthList.findIndex((month_1) => month_1.id === monthId);
2188
+ baseMonthList = addMissingMonths(monthId_0);
2189
+ index = baseMonthList.findIndex((month_2) => month_2.id === monthId_0);
2144
2190
  }
2145
- return baseMonthList.slice(0, index).reduce((acc, month_2) => {
2191
+ return baseMonthList.slice(0, index).reduce((acc, month_3) => {
2146
2192
  const currentHeight = getHeightForMonth({
2147
- calendarMonth: month_2,
2193
+ calendarMonth: month_3,
2148
2194
  calendarSpacing,
2149
2195
  calendarDayHeight,
2150
2196
  calendarMonthHeaderHeight,
@@ -2155,30 +2201,30 @@ function CalendarList(t0) {
2155
2201
  return acc + currentHeight;
2156
2202
  }, 0);
2157
2203
  };
2158
- $[8] = addMissingMonths;
2159
- $[9] = calendarAdditionalHeight;
2160
- $[10] = calendarDayHeight;
2161
- $[11] = calendarMonthHeaderHeight;
2162
- $[12] = calendarRowVerticalSpacing;
2163
- $[13] = calendarSpacing;
2164
- $[14] = calendarWeekHeaderHeight;
2165
- $[15] = monthList;
2166
- $[16] = t12;
2167
- } else {
2168
- t12 = $[16];
2169
- }
2170
- const getScrollOffsetForMonth = t12;
2204
+ $[15] = addMissingMonths;
2205
+ $[16] = calendarAdditionalHeight;
2206
+ $[17] = calendarDayHeight;
2207
+ $[18] = calendarMonthHeaderHeight;
2208
+ $[19] = calendarRowVerticalSpacing;
2209
+ $[20] = calendarSpacing;
2210
+ $[21] = calendarWeekHeaderHeight;
2211
+ $[22] = monthList;
2212
+ $[23] = t13;
2213
+ } else {
2214
+ t13 = $[23];
2215
+ }
2216
+ const getScrollOffsetForMonth = t13;
2171
2217
  const legendListRef = useRef(null);
2172
- let t13;
2173
- if ($[17] !== calendarDayHeight || $[18] !== calendarFirstDayOfWeek || $[19] !== calendarRowVerticalSpacing || $[20] !== calendarWeekHeaderHeight || $[21] !== getScrollOffsetForMonth) {
2174
- t13 = () => ({
2175
- scrollToMonth(date_0, animated, t142) {
2218
+ let t14;
2219
+ if ($[24] !== calendarDayHeight || $[25] !== calendarFirstDayOfWeek || $[26] !== calendarRowVerticalSpacing || $[27] !== calendarWeekHeaderHeight || $[28] !== getScrollOffsetForMonth) {
2220
+ t14 = () => ({
2221
+ scrollToMonth(date_0, animated, t152) {
2176
2222
  const {
2177
- additionalOffset: t152
2178
- } = t142 === void 0 ? {
2223
+ additionalOffset: t162
2224
+ } = t152 === void 0 ? {
2179
2225
  additionalOffset: 0
2180
- } : t142;
2181
- const additionalOffset = t152 === void 0 ? 0 : t152;
2226
+ } : t152;
2227
+ const additionalOffset = t162 === void 0 ? 0 : t162;
2182
2228
  setTimeout(() => {
2183
2229
  var _a2;
2184
2230
  (_a2 = legendListRef.current) == null ? void 0 : _a2.scrollToOffset({
@@ -2187,14 +2233,14 @@ function CalendarList(t0) {
2187
2233
  });
2188
2234
  }, 0);
2189
2235
  },
2190
- scrollToDate(date_1, animated_0, t162) {
2236
+ scrollToDate(date_1, animated_0, t172) {
2191
2237
  var _a2;
2192
2238
  const {
2193
- additionalOffset: t172
2194
- } = t162 === void 0 ? {
2239
+ additionalOffset: t182
2240
+ } = t172 === void 0 ? {
2195
2241
  additionalOffset: 0
2196
- } : t162;
2197
- const additionalOffset_0 = t172 === void 0 ? 0 : t172;
2242
+ } : t172;
2243
+ const additionalOffset_0 = t182 === void 0 ? 0 : t182;
2198
2244
  const currentMonthOffset = getScrollOffsetForMonth(date_1);
2199
2245
  const weekOfMonthIndex = getWeekOfMonth(date_1, calendarFirstDayOfWeek);
2200
2246
  const rowHeight = calendarDayHeight + calendarRowVerticalSpacing;
@@ -2213,30 +2259,30 @@ function CalendarList(t0) {
2213
2259
  });
2214
2260
  }
2215
2261
  });
2216
- $[17] = calendarDayHeight;
2217
- $[18] = calendarFirstDayOfWeek;
2218
- $[19] = calendarRowVerticalSpacing;
2219
- $[20] = calendarWeekHeaderHeight;
2220
- $[21] = getScrollOffsetForMonth;
2221
- $[22] = t13;
2262
+ $[24] = calendarDayHeight;
2263
+ $[25] = calendarFirstDayOfWeek;
2264
+ $[26] = calendarRowVerticalSpacing;
2265
+ $[27] = calendarWeekHeaderHeight;
2266
+ $[28] = getScrollOffsetForMonth;
2267
+ $[29] = t14;
2222
2268
  } else {
2223
- t13 = $[22];
2269
+ t14 = $[29];
2224
2270
  }
2225
- useImperativeHandle(ref, t13);
2226
- let t14;
2227
- if ($[23] !== calendarSpacing) {
2228
- t14 = {
2271
+ useImperativeHandle(ref, t14);
2272
+ let t15;
2273
+ if ($[30] !== calendarSpacing) {
2274
+ t15 = {
2229
2275
  paddingBottom: calendarSpacing
2230
2276
  };
2231
- $[23] = calendarSpacing;
2232
- $[24] = t14;
2277
+ $[30] = calendarSpacing;
2278
+ $[31] = t15;
2233
2279
  } else {
2234
- t14 = $[24];
2280
+ t15 = $[31];
2235
2281
  }
2236
- const calendarContainerStyle = t14;
2237
- let t15;
2238
- if ($[25] !== calendarAdditionalHeight || $[26] !== calendarDayHeight || $[27] !== calendarMonthHeaderHeight || $[28] !== calendarRowVerticalSpacing || $[29] !== calendarSpacing || $[30] !== calendarWeekHeaderHeight) {
2239
- t15 = (item) => getHeightForMonth({
2282
+ const calendarContainerStyle = t15;
2283
+ let t16;
2284
+ if ($[32] !== calendarAdditionalHeight || $[33] !== calendarDayHeight || $[34] !== calendarMonthHeaderHeight || $[35] !== calendarRowVerticalSpacing || $[36] !== calendarSpacing || $[37] !== calendarWeekHeaderHeight) {
2285
+ t16 = (item) => getHeightForMonth({
2240
2286
  calendarMonth: item,
2241
2287
  calendarSpacing,
2242
2288
  calendarDayHeight,
@@ -2245,23 +2291,23 @@ function CalendarList(t0) {
2245
2291
  calendarWeekHeaderHeight,
2246
2292
  calendarAdditionalHeight
2247
2293
  });
2248
- $[25] = calendarAdditionalHeight;
2249
- $[26] = calendarDayHeight;
2250
- $[27] = calendarMonthHeaderHeight;
2251
- $[28] = calendarRowVerticalSpacing;
2252
- $[29] = calendarSpacing;
2253
- $[30] = calendarWeekHeaderHeight;
2254
- $[31] = t15;
2294
+ $[32] = calendarAdditionalHeight;
2295
+ $[33] = calendarDayHeight;
2296
+ $[34] = calendarMonthHeaderHeight;
2297
+ $[35] = calendarRowVerticalSpacing;
2298
+ $[36] = calendarSpacing;
2299
+ $[37] = calendarWeekHeaderHeight;
2300
+ $[38] = t16;
2255
2301
  } else {
2256
- t15 = $[31];
2302
+ t16 = $[38];
2257
2303
  }
2258
- const getFixedItemSize = t15;
2259
- let t16;
2260
- if ($[32] !== calendarContainerStyle) {
2261
- t16 = (t172) => {
2304
+ const getFixedItemSize = t16;
2305
+ let t17;
2306
+ if ($[39] !== calendarContainerStyle) {
2307
+ t17 = (t182) => {
2262
2308
  const {
2263
2309
  item: item_0
2264
- } = t172;
2310
+ } = t182;
2265
2311
  return /* @__PURE__ */ _jsx10(View7, {
2266
2312
  style: calendarContainerStyle,
2267
2313
  children: /* @__PURE__ */ _jsx10(Calendar, __spreadValues({
@@ -2269,21 +2315,21 @@ function CalendarList(t0) {
2269
2315
  }, item_0.calendarProps))
2270
2316
  });
2271
2317
  };
2272
- $[32] = calendarContainerStyle;
2273
- $[33] = t16;
2318
+ $[39] = calendarContainerStyle;
2319
+ $[40] = t17;
2274
2320
  } else {
2275
- t16 = $[33];
2321
+ t17 = $[40];
2276
2322
  }
2277
- const handleRenderItem = t16;
2323
+ const handleRenderItem = t17;
2278
2324
  const handleViewableItemsChanged = _temp;
2279
- let t17;
2280
- if ($[34] !== flatListProps || $[35] !== getFixedItemSize || $[36] !== handleOnEndReached || $[37] !== handleOnStartReached || $[38] !== handleRenderItem || $[39] !== initialMonthIndex || $[40] !== monthListWithCalendarProps) {
2281
- t17 = /* @__PURE__ */ _jsx10(LegendList, __spreadValues({
2325
+ let t18;
2326
+ if ($[41] !== computedInitialScrollIndex || $[42] !== flatListProps || $[43] !== getFixedItemSize || $[44] !== handleOnEndReached || $[45] !== handleOnStartReached || $[46] !== handleRenderItem || $[47] !== monthListWithCalendarProps) {
2327
+ t18 = /* @__PURE__ */ _jsx10(LegendList, __spreadValues({
2282
2328
  data: monthListWithCalendarProps,
2283
2329
  drawDistance: 560,
2284
2330
  estimatedItemSize: 273,
2285
2331
  getFixedItemSize,
2286
- initialScrollIndex: initialMonthIndex,
2332
+ initialScrollIndex: computedInitialScrollIndex,
2287
2333
  keyExtractor,
2288
2334
  maintainVisibleContentPosition: true,
2289
2335
  onEndReached: handleOnEndReached,
@@ -2295,18 +2341,18 @@ function CalendarList(t0) {
2295
2341
  showsVerticalScrollIndicator: false,
2296
2342
  style: styles8.container
2297
2343
  }, flatListProps));
2298
- $[34] = flatListProps;
2299
- $[35] = getFixedItemSize;
2300
- $[36] = handleOnEndReached;
2301
- $[37] = handleOnStartReached;
2302
- $[38] = handleRenderItem;
2303
- $[39] = initialMonthIndex;
2304
- $[40] = monthListWithCalendarProps;
2305
- $[41] = t17;
2306
- } else {
2307
- t17 = $[41];
2308
- }
2309
- return t17;
2344
+ $[41] = computedInitialScrollIndex;
2345
+ $[42] = flatListProps;
2346
+ $[43] = getFixedItemSize;
2347
+ $[44] = handleOnEndReached;
2348
+ $[45] = handleOnStartReached;
2349
+ $[46] = handleRenderItem;
2350
+ $[47] = monthListWithCalendarProps;
2351
+ $[48] = t18;
2352
+ } else {
2353
+ t18 = $[48];
2354
+ }
2355
+ return t18;
2310
2356
  }
2311
2357
  function _temp() {
2312
2358
  }