@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.js CHANGED
@@ -1899,6 +1899,9 @@ var useCalendarList = (t0) => {
1899
1899
  let t3;
1900
1900
  if ($[10] !== calendarFirstDayOfWeek || $[11] !== calendarMaxDateId || $[12] !== monthList) {
1901
1901
  t3 = (numberOfMonths) => {
1902
+ if (numberOfMonths <= 0) {
1903
+ return monthList;
1904
+ }
1902
1905
  const startingMonth_0 = addMonths(monthList[monthList.length - 1].date, 1);
1903
1906
  const endingMonth_0 = getEndingMonth(Math.max(numberOfMonths - 1, 0), calendarMaxDateId, startingMonth_0);
1904
1907
  const hasReachedEndingMonth = monthList.find((m) => m.id === toDateId(endingMonth_0));
@@ -1924,6 +1927,9 @@ var useCalendarList = (t0) => {
1924
1927
  let t4;
1925
1928
  if ($[14] !== calendarFirstDayOfWeek || $[15] !== calendarMinDateId || $[16] !== monthList) {
1926
1929
  t4 = (numberOfMonths_0) => {
1930
+ if (numberOfMonths_0 <= 0) {
1931
+ return monthList;
1932
+ }
1927
1933
  const endingMonth_1 = subMonths(monthList[0].date, 1);
1928
1934
  const startingMonth_1 = getStartingMonth(Math.max(numberOfMonths_0 - 1, 0), calendarMinDateId, endingMonth_1);
1929
1935
  const hasReachedStartingMonth = monthList.find((m_0) => m_0.id === toDateId(startingMonth_1));
@@ -2023,7 +2029,7 @@ var import_jsx_runtime10 = require("react/jsx-runtime");
2023
2029
  var LegendList = import_react_native9.LegendList;
2024
2030
  var keyExtractor = (month) => month.id;
2025
2031
  function CalendarList(t0) {
2026
- const $ = (0, import_compiler_runtime12.c)(42);
2032
+ const $ = (0, import_compiler_runtime12.c)(49);
2027
2033
  const _a = t0, {
2028
2034
  ref
2029
2035
  } = _a, props = __objRest(_a, [
@@ -2031,23 +2037,25 @@ function CalendarList(t0) {
2031
2037
  ]);
2032
2038
  const _b = props, {
2033
2039
  calendarInitialMonthId,
2034
- calendarPastScrollRangeInMonths: t1,
2035
- calendarFutureScrollRangeInMonths: t2,
2036
- calendarFirstDayOfWeek: t3,
2040
+ calendarInitialScrollToActiveRange: t1,
2041
+ calendarPastScrollRangeInMonths: t2,
2042
+ calendarFutureScrollRangeInMonths: t3,
2043
+ calendarFirstDayOfWeek: t4,
2037
2044
  calendarFormatLocale,
2038
- calendarSpacing: t4,
2045
+ calendarSpacing: t5,
2039
2046
  calendarRowHorizontalSpacing,
2040
- calendarRowVerticalSpacing: t5,
2041
- calendarMonthHeaderHeight: t6,
2042
- calendarDayHeight: t7,
2043
- calendarWeekHeaderHeight: t8,
2044
- calendarAdditionalHeight: t9,
2047
+ calendarRowVerticalSpacing: t6,
2048
+ calendarMonthHeaderHeight: t7,
2049
+ calendarDayHeight: t8,
2050
+ calendarWeekHeaderHeight: t9,
2051
+ calendarAdditionalHeight: t10,
2045
2052
  calendarColorScheme,
2046
2053
  theme,
2047
2054
  onEndReached,
2048
2055
  onStartReached
2049
2056
  } = _b, otherProps = __objRest(_b, [
2050
2057
  "calendarInitialMonthId",
2058
+ "calendarInitialScrollToActiveRange",
2051
2059
  "calendarPastScrollRangeInMonths",
2052
2060
  "calendarFutureScrollRangeInMonths",
2053
2061
  "calendarFirstDayOfWeek",
@@ -2064,15 +2072,16 @@ function CalendarList(t0) {
2064
2072
  "onEndReached",
2065
2073
  "onStartReached"
2066
2074
  ]);
2067
- const calendarPastScrollRangeInMonths = t1 === void 0 ? 12 : t1;
2068
- const calendarFutureScrollRangeInMonths = t2 === void 0 ? 12 : t2;
2069
- const calendarFirstDayOfWeek = t3 === void 0 ? "sunday" : t3;
2070
- const calendarSpacing = t4 === void 0 ? 20 : t4;
2071
- const calendarRowVerticalSpacing = t5 === void 0 ? 8 : t5;
2072
- const calendarMonthHeaderHeight = t6 === void 0 ? 20 : t6;
2073
- const calendarDayHeight = t7 === void 0 ? 32 : t7;
2074
- const calendarWeekHeaderHeight = t8 === void 0 ? calendarDayHeight : t8;
2075
- const calendarAdditionalHeight = t9 === void 0 ? 0 : t9;
2075
+ const calendarInitialScrollToActiveRange = t1 === void 0 ? true : t1;
2076
+ const calendarPastScrollRangeInMonths = t2 === void 0 ? 12 : t2;
2077
+ const calendarFutureScrollRangeInMonths = t3 === void 0 ? 12 : t3;
2078
+ const calendarFirstDayOfWeek = t4 === void 0 ? "sunday" : t4;
2079
+ const calendarSpacing = t5 === void 0 ? 20 : t5;
2080
+ const calendarRowVerticalSpacing = t6 === void 0 ? 8 : t6;
2081
+ const calendarMonthHeaderHeight = t7 === void 0 ? 20 : t7;
2082
+ const calendarDayHeight = t8 === void 0 ? 32 : t8;
2083
+ const calendarWeekHeaderHeight = t9 === void 0 ? calendarDayHeight : t9;
2084
+ const calendarAdditionalHeight = t10 === void 0 ? 0 : t10;
2076
2085
  const _c14 = otherProps, {
2077
2086
  calendarActiveDateRanges,
2078
2087
  calendarDisabledDateIds,
@@ -2133,50 +2142,87 @@ function CalendarList(t0) {
2133
2142
  calendarMaxDateId,
2134
2143
  calendarMinDateId
2135
2144
  });
2136
- const monthListWithCalendarProps = monthList.map((month) => __spreadProps(__spreadValues({}, month), {
2145
+ let computedInitialScrollIndex = initialMonthIndex;
2146
+ if (calendarInitialScrollToActiveRange && calendarActiveDateRanges) {
2147
+ const firstRange = calendarActiveDateRanges[0];
2148
+ if (firstRange == null ? void 0 : firstRange.startId) {
2149
+ let t112;
2150
+ if ($[0] !== firstRange.startId) {
2151
+ const startDate = fromDateId(firstRange.startId);
2152
+ t112 = toDateId(startOfMonth(startDate));
2153
+ $[0] = firstRange.startId;
2154
+ $[1] = t112;
2155
+ } else {
2156
+ t112 = $[1];
2157
+ }
2158
+ const monthId = t112;
2159
+ let t122;
2160
+ if ($[2] !== monthId || $[3] !== monthList) {
2161
+ let t132;
2162
+ if ($[5] !== monthId) {
2163
+ t132 = (month) => month.id === monthId;
2164
+ $[5] = monthId;
2165
+ $[6] = t132;
2166
+ } else {
2167
+ t132 = $[6];
2168
+ }
2169
+ t122 = monthList.findIndex(t132);
2170
+ $[2] = monthId;
2171
+ $[3] = monthList;
2172
+ $[4] = t122;
2173
+ } else {
2174
+ t122 = $[4];
2175
+ }
2176
+ const monthIndex = t122;
2177
+ if (monthIndex !== -1) {
2178
+ computedInitialScrollIndex = monthIndex;
2179
+ }
2180
+ }
2181
+ }
2182
+ const monthListWithCalendarProps = monthList.map((month_0) => __spreadProps(__spreadValues({}, month_0), {
2137
2183
  calendarProps
2138
2184
  }));
2139
- let t10;
2140
- if ($[0] !== appendMonths || $[1] !== calendarFutureScrollRangeInMonths || $[2] !== onEndReached) {
2141
- t10 = (info) => {
2185
+ let t11;
2186
+ if ($[7] !== appendMonths || $[8] !== calendarFutureScrollRangeInMonths || $[9] !== onEndReached) {
2187
+ t11 = (info) => {
2142
2188
  appendMonths(calendarFutureScrollRangeInMonths);
2143
2189
  onEndReached == null ? void 0 : onEndReached(info);
2144
2190
  };
2145
- $[0] = appendMonths;
2146
- $[1] = calendarFutureScrollRangeInMonths;
2147
- $[2] = onEndReached;
2148
- $[3] = t10;
2191
+ $[7] = appendMonths;
2192
+ $[8] = calendarFutureScrollRangeInMonths;
2193
+ $[9] = onEndReached;
2194
+ $[10] = t11;
2149
2195
  } else {
2150
- t10 = $[3];
2196
+ t11 = $[10];
2151
2197
  }
2152
- const handleOnEndReached = t10;
2153
- let t11;
2154
- if ($[4] !== calendarPastScrollRangeInMonths || $[5] !== onStartReached || $[6] !== prependMonths) {
2155
- t11 = (info_0) => {
2198
+ const handleOnEndReached = t11;
2199
+ let t12;
2200
+ if ($[11] !== calendarPastScrollRangeInMonths || $[12] !== onStartReached || $[13] !== prependMonths) {
2201
+ t12 = (info_0) => {
2156
2202
  prependMonths(calendarPastScrollRangeInMonths);
2157
2203
  onStartReached == null ? void 0 : onStartReached(info_0);
2158
2204
  };
2159
- $[4] = calendarPastScrollRangeInMonths;
2160
- $[5] = onStartReached;
2161
- $[6] = prependMonths;
2162
- $[7] = t11;
2205
+ $[11] = calendarPastScrollRangeInMonths;
2206
+ $[12] = onStartReached;
2207
+ $[13] = prependMonths;
2208
+ $[14] = t12;
2163
2209
  } else {
2164
- t11 = $[7];
2210
+ t12 = $[14];
2165
2211
  }
2166
- const handleOnStartReached = t11;
2167
- let t12;
2168
- if ($[8] !== addMissingMonths || $[9] !== calendarAdditionalHeight || $[10] !== calendarDayHeight || $[11] !== calendarMonthHeaderHeight || $[12] !== calendarRowVerticalSpacing || $[13] !== calendarSpacing || $[14] !== calendarWeekHeaderHeight || $[15] !== monthList) {
2169
- t12 = (date) => {
2170
- const monthId = toDateId(startOfMonth(date));
2212
+ const handleOnStartReached = t12;
2213
+ let t13;
2214
+ if ($[15] !== addMissingMonths || $[16] !== calendarAdditionalHeight || $[17] !== calendarDayHeight || $[18] !== calendarMonthHeaderHeight || $[19] !== calendarRowVerticalSpacing || $[20] !== calendarSpacing || $[21] !== calendarWeekHeaderHeight || $[22] !== monthList) {
2215
+ t13 = (date) => {
2216
+ const monthId_0 = toDateId(startOfMonth(date));
2171
2217
  let baseMonthList = monthList;
2172
- let index = baseMonthList.findIndex((month_0) => month_0.id === monthId);
2218
+ let index = baseMonthList.findIndex((month_1) => month_1.id === monthId_0);
2173
2219
  if (index === -1) {
2174
- baseMonthList = addMissingMonths(monthId);
2175
- index = baseMonthList.findIndex((month_1) => month_1.id === monthId);
2220
+ baseMonthList = addMissingMonths(monthId_0);
2221
+ index = baseMonthList.findIndex((month_2) => month_2.id === monthId_0);
2176
2222
  }
2177
- return baseMonthList.slice(0, index).reduce((acc, month_2) => {
2223
+ return baseMonthList.slice(0, index).reduce((acc, month_3) => {
2178
2224
  const currentHeight = getHeightForMonth({
2179
- calendarMonth: month_2,
2225
+ calendarMonth: month_3,
2180
2226
  calendarSpacing,
2181
2227
  calendarDayHeight,
2182
2228
  calendarMonthHeaderHeight,
@@ -2187,30 +2233,30 @@ function CalendarList(t0) {
2187
2233
  return acc + currentHeight;
2188
2234
  }, 0);
2189
2235
  };
2190
- $[8] = addMissingMonths;
2191
- $[9] = calendarAdditionalHeight;
2192
- $[10] = calendarDayHeight;
2193
- $[11] = calendarMonthHeaderHeight;
2194
- $[12] = calendarRowVerticalSpacing;
2195
- $[13] = calendarSpacing;
2196
- $[14] = calendarWeekHeaderHeight;
2197
- $[15] = monthList;
2198
- $[16] = t12;
2199
- } else {
2200
- t12 = $[16];
2201
- }
2202
- const getScrollOffsetForMonth = t12;
2236
+ $[15] = addMissingMonths;
2237
+ $[16] = calendarAdditionalHeight;
2238
+ $[17] = calendarDayHeight;
2239
+ $[18] = calendarMonthHeaderHeight;
2240
+ $[19] = calendarRowVerticalSpacing;
2241
+ $[20] = calendarSpacing;
2242
+ $[21] = calendarWeekHeaderHeight;
2243
+ $[22] = monthList;
2244
+ $[23] = t13;
2245
+ } else {
2246
+ t13 = $[23];
2247
+ }
2248
+ const getScrollOffsetForMonth = t13;
2203
2249
  const legendListRef = (0, import_react11.useRef)(null);
2204
- let t13;
2205
- if ($[17] !== calendarDayHeight || $[18] !== calendarFirstDayOfWeek || $[19] !== calendarRowVerticalSpacing || $[20] !== calendarWeekHeaderHeight || $[21] !== getScrollOffsetForMonth) {
2206
- t13 = () => ({
2207
- scrollToMonth(date_0, animated, t142) {
2250
+ let t14;
2251
+ if ($[24] !== calendarDayHeight || $[25] !== calendarFirstDayOfWeek || $[26] !== calendarRowVerticalSpacing || $[27] !== calendarWeekHeaderHeight || $[28] !== getScrollOffsetForMonth) {
2252
+ t14 = () => ({
2253
+ scrollToMonth(date_0, animated, t152) {
2208
2254
  const {
2209
- additionalOffset: t152
2210
- } = t142 === void 0 ? {
2255
+ additionalOffset: t162
2256
+ } = t152 === void 0 ? {
2211
2257
  additionalOffset: 0
2212
- } : t142;
2213
- const additionalOffset = t152 === void 0 ? 0 : t152;
2258
+ } : t152;
2259
+ const additionalOffset = t162 === void 0 ? 0 : t162;
2214
2260
  setTimeout(() => {
2215
2261
  var _a2;
2216
2262
  (_a2 = legendListRef.current) == null ? void 0 : _a2.scrollToOffset({
@@ -2219,14 +2265,14 @@ function CalendarList(t0) {
2219
2265
  });
2220
2266
  }, 0);
2221
2267
  },
2222
- scrollToDate(date_1, animated_0, t162) {
2268
+ scrollToDate(date_1, animated_0, t172) {
2223
2269
  var _a2;
2224
2270
  const {
2225
- additionalOffset: t172
2226
- } = t162 === void 0 ? {
2271
+ additionalOffset: t182
2272
+ } = t172 === void 0 ? {
2227
2273
  additionalOffset: 0
2228
- } : t162;
2229
- const additionalOffset_0 = t172 === void 0 ? 0 : t172;
2274
+ } : t172;
2275
+ const additionalOffset_0 = t182 === void 0 ? 0 : t182;
2230
2276
  const currentMonthOffset = getScrollOffsetForMonth(date_1);
2231
2277
  const weekOfMonthIndex = getWeekOfMonth(date_1, calendarFirstDayOfWeek);
2232
2278
  const rowHeight = calendarDayHeight + calendarRowVerticalSpacing;
@@ -2245,30 +2291,30 @@ function CalendarList(t0) {
2245
2291
  });
2246
2292
  }
2247
2293
  });
2248
- $[17] = calendarDayHeight;
2249
- $[18] = calendarFirstDayOfWeek;
2250
- $[19] = calendarRowVerticalSpacing;
2251
- $[20] = calendarWeekHeaderHeight;
2252
- $[21] = getScrollOffsetForMonth;
2253
- $[22] = t13;
2294
+ $[24] = calendarDayHeight;
2295
+ $[25] = calendarFirstDayOfWeek;
2296
+ $[26] = calendarRowVerticalSpacing;
2297
+ $[27] = calendarWeekHeaderHeight;
2298
+ $[28] = getScrollOffsetForMonth;
2299
+ $[29] = t14;
2254
2300
  } else {
2255
- t13 = $[22];
2301
+ t14 = $[29];
2256
2302
  }
2257
- (0, import_react11.useImperativeHandle)(ref, t13);
2258
- let t14;
2259
- if ($[23] !== calendarSpacing) {
2260
- t14 = {
2303
+ (0, import_react11.useImperativeHandle)(ref, t14);
2304
+ let t15;
2305
+ if ($[30] !== calendarSpacing) {
2306
+ t15 = {
2261
2307
  paddingBottom: calendarSpacing
2262
2308
  };
2263
- $[23] = calendarSpacing;
2264
- $[24] = t14;
2309
+ $[30] = calendarSpacing;
2310
+ $[31] = t15;
2265
2311
  } else {
2266
- t14 = $[24];
2312
+ t15 = $[31];
2267
2313
  }
2268
- const calendarContainerStyle = t14;
2269
- let t15;
2270
- if ($[25] !== calendarAdditionalHeight || $[26] !== calendarDayHeight || $[27] !== calendarMonthHeaderHeight || $[28] !== calendarRowVerticalSpacing || $[29] !== calendarSpacing || $[30] !== calendarWeekHeaderHeight) {
2271
- t15 = (item) => getHeightForMonth({
2314
+ const calendarContainerStyle = t15;
2315
+ let t16;
2316
+ if ($[32] !== calendarAdditionalHeight || $[33] !== calendarDayHeight || $[34] !== calendarMonthHeaderHeight || $[35] !== calendarRowVerticalSpacing || $[36] !== calendarSpacing || $[37] !== calendarWeekHeaderHeight) {
2317
+ t16 = (item) => getHeightForMonth({
2272
2318
  calendarMonth: item,
2273
2319
  calendarSpacing,
2274
2320
  calendarDayHeight,
@@ -2277,23 +2323,23 @@ function CalendarList(t0) {
2277
2323
  calendarWeekHeaderHeight,
2278
2324
  calendarAdditionalHeight
2279
2325
  });
2280
- $[25] = calendarAdditionalHeight;
2281
- $[26] = calendarDayHeight;
2282
- $[27] = calendarMonthHeaderHeight;
2283
- $[28] = calendarRowVerticalSpacing;
2284
- $[29] = calendarSpacing;
2285
- $[30] = calendarWeekHeaderHeight;
2286
- $[31] = t15;
2326
+ $[32] = calendarAdditionalHeight;
2327
+ $[33] = calendarDayHeight;
2328
+ $[34] = calendarMonthHeaderHeight;
2329
+ $[35] = calendarRowVerticalSpacing;
2330
+ $[36] = calendarSpacing;
2331
+ $[37] = calendarWeekHeaderHeight;
2332
+ $[38] = t16;
2287
2333
  } else {
2288
- t15 = $[31];
2334
+ t16 = $[38];
2289
2335
  }
2290
- const getFixedItemSize = t15;
2291
- let t16;
2292
- if ($[32] !== calendarContainerStyle) {
2293
- t16 = (t172) => {
2336
+ const getFixedItemSize = t16;
2337
+ let t17;
2338
+ if ($[39] !== calendarContainerStyle) {
2339
+ t17 = (t182) => {
2294
2340
  const {
2295
2341
  item: item_0
2296
- } = t172;
2342
+ } = t182;
2297
2343
  return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_react_native10.View, {
2298
2344
  style: calendarContainerStyle,
2299
2345
  children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Calendar, __spreadValues({
@@ -2301,21 +2347,21 @@ function CalendarList(t0) {
2301
2347
  }, item_0.calendarProps))
2302
2348
  });
2303
2349
  };
2304
- $[32] = calendarContainerStyle;
2305
- $[33] = t16;
2350
+ $[39] = calendarContainerStyle;
2351
+ $[40] = t17;
2306
2352
  } else {
2307
- t16 = $[33];
2353
+ t17 = $[40];
2308
2354
  }
2309
- const handleRenderItem = t16;
2355
+ const handleRenderItem = t17;
2310
2356
  const handleViewableItemsChanged = _temp;
2311
- let t17;
2312
- if ($[34] !== flatListProps || $[35] !== getFixedItemSize || $[36] !== handleOnEndReached || $[37] !== handleOnStartReached || $[38] !== handleRenderItem || $[39] !== initialMonthIndex || $[40] !== monthListWithCalendarProps) {
2313
- t17 = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(LegendList, __spreadValues({
2357
+ let t18;
2358
+ if ($[41] !== computedInitialScrollIndex || $[42] !== flatListProps || $[43] !== getFixedItemSize || $[44] !== handleOnEndReached || $[45] !== handleOnStartReached || $[46] !== handleRenderItem || $[47] !== monthListWithCalendarProps) {
2359
+ t18 = /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(LegendList, __spreadValues({
2314
2360
  data: monthListWithCalendarProps,
2315
2361
  drawDistance: 560,
2316
2362
  estimatedItemSize: 273,
2317
2363
  getFixedItemSize,
2318
- initialScrollIndex: initialMonthIndex,
2364
+ initialScrollIndex: computedInitialScrollIndex,
2319
2365
  keyExtractor,
2320
2366
  maintainVisibleContentPosition: true,
2321
2367
  onEndReached: handleOnEndReached,
@@ -2327,18 +2373,18 @@ function CalendarList(t0) {
2327
2373
  showsVerticalScrollIndicator: false,
2328
2374
  style: styles8.container
2329
2375
  }, flatListProps));
2330
- $[34] = flatListProps;
2331
- $[35] = getFixedItemSize;
2332
- $[36] = handleOnEndReached;
2333
- $[37] = handleOnStartReached;
2334
- $[38] = handleRenderItem;
2335
- $[39] = initialMonthIndex;
2336
- $[40] = monthListWithCalendarProps;
2337
- $[41] = t17;
2338
- } else {
2339
- t17 = $[41];
2340
- }
2341
- return t17;
2376
+ $[41] = computedInitialScrollIndex;
2377
+ $[42] = flatListProps;
2378
+ $[43] = getFixedItemSize;
2379
+ $[44] = handleOnEndReached;
2380
+ $[45] = handleOnStartReached;
2381
+ $[46] = handleRenderItem;
2382
+ $[47] = monthListWithCalendarProps;
2383
+ $[48] = t18;
2384
+ } else {
2385
+ t18 = $[48];
2386
+ }
2387
+ return t18;
2342
2388
  }
2343
2389
  function _temp() {
2344
2390
  }