@lazerlen/legend-calendar 1.3.0 → 1.4.0

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