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