@yr3/ui 1.1.6 → 1.1.7

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.cjs CHANGED
@@ -2133,43 +2133,37 @@ function getMonthCalendar(dataFormat, year, month, startIndex, selected, props)
2133
2133
  props
2134
2134
  };
2135
2135
  }
2136
- function findMonth(value, years, exclude, direction) {
2137
- if (!value) return null;
2136
+ function findMonth(value, years, exclude, direction, indexed = 1) {
2137
+ if (!value) return [];
2138
2138
  let [month, year] = value.split("-").map(Number);
2139
2139
  month -= 1;
2140
2140
  const excludedMap = /* @__PURE__ */ new Map();
2141
2141
  exclude.forEach((item) => {
2142
- excludedMap.set(
2143
- item.year,
2144
- new Set(item.months)
2145
- );
2142
+ excludedMap.set(item.year, new Set(item.months));
2146
2143
  });
2147
2144
  const sortedYears = [...years].sort((a, b) => a - b);
2148
- while (true) {
2145
+ const result = [];
2146
+ while (result.length < indexed) {
2149
2147
  month += direction === "next" ? 1 : -1;
2150
2148
  if (month > 11) {
2151
- const yearIndex = sortedYears.indexOf(year);
2152
- const nextYear = sortedYears[yearIndex + 1];
2153
- if (nextYear == null) {
2154
- return null;
2155
- }
2149
+ const nextYear = sortedYears[sortedYears.indexOf(year) + 1];
2150
+ if (nextYear == null) break;
2156
2151
  year = nextYear;
2157
2152
  month = 0;
2158
2153
  }
2159
2154
  if (month < 0) {
2160
- const yearIndex = sortedYears.indexOf(year);
2161
- const prevYear = sortedYears[yearIndex - 1];
2162
- if (prevYear == null) {
2163
- return null;
2164
- }
2155
+ const prevYear = sortedYears[sortedYears.indexOf(year) - 1];
2156
+ if (prevYear == null) break;
2165
2157
  year = prevYear;
2166
2158
  month = 11;
2167
2159
  }
2168
- const excluded = excludedMap.get(year)?.has(month);
2169
- if (!excluded) {
2170
- return `${String(month + 1).padStart(2, "0")}-${year}`;
2160
+ if (!excludedMap.get(year)?.has(month)) {
2161
+ result.push(
2162
+ `${String(month + 1).padStart(2, "0")}-${year}`
2163
+ );
2171
2164
  }
2172
2165
  }
2166
+ return result;
2173
2167
  }
2174
2168
  function getMonthCalendarProps({ year, data, value, format }) {
2175
2169
  const dtx2 = date(new Date(year, 1.1), format);
@@ -3969,7 +3963,7 @@ var initialPropsComponent3 = {
3969
3963
  style: {}
3970
3964
  }
3971
3965
  };
3972
- var MonthSelector = ({ label, value, disabled, propsComponent, data, format, onNext, onLast, onChange }) => {
3966
+ var MonthSelector = ({ label, value, disabled, propsComponent, data, format, onNext, onLast, onChange, lastIndex, nextIndex }) => {
3973
3967
  const [open, setOpen] = React11.useState(false);
3974
3968
  const [valueState, setValueState] = React11.useState(value || null);
3975
3969
  const [yearSelected, setYearSelected] = React11.useState(data?.years.findIndex((y) => y === data.year) || 0);
@@ -3989,8 +3983,8 @@ var MonthSelector = ({ label, value, disabled, propsComponent, data, format, onN
3989
3983
  const newValue = `${month}-${data.years[yearSelected]}`;
3990
3984
  setValueState(newValue);
3991
3985
  onChange(newValue);
3992
- onNext?.(findMonth(newValue, data.years, data.exclude, "next"));
3993
- onLast?.(findMonth(newValue, data.years, data.exclude, "prev"));
3986
+ onNext?.(findMonth(newValue, data.years, data.exclude, "next", nextIndex));
3987
+ onLast?.(findMonth(newValue, data.years, data.exclude, "prev", lastIndex));
3994
3988
  setOpen(false);
3995
3989
  };
3996
3990
  const classes = monthSelectorVariants({ wrapper: true, disabled });
package/dist/index.d.cts CHANGED
@@ -1553,7 +1553,7 @@ type ExcludeItem = {
1553
1553
  year: number;
1554
1554
  months: number[];
1555
1555
  };
1556
- declare function findMonth(value: string, years: number[], exclude: ExcludeItem[], direction: Direction): string | null;
1556
+ declare function findMonth(value: string, years: number[], exclude: ExcludeItem[], direction: Direction, indexed?: number): string[];
1557
1557
  declare function getMonthCalendarProps({ year, data, value, format }: CalendarMonthProps): any;
1558
1558
 
1559
1559
  declare const rgbToHex: (r: number, g: number, b: number) => string;
@@ -2179,6 +2179,8 @@ type MonthSelectorProps = {
2179
2179
  }[];
2180
2180
  };
2181
2181
  format?: DTXFormat;
2182
+ lastIndex?: number;
2183
+ nextIndex?: number;
2182
2184
  onNext?: (value: string) => void;
2183
2185
  onLast?: (value: string) => void;
2184
2186
  onChange: (value: string) => void;
package/dist/index.d.ts CHANGED
@@ -1553,7 +1553,7 @@ type ExcludeItem = {
1553
1553
  year: number;
1554
1554
  months: number[];
1555
1555
  };
1556
- declare function findMonth(value: string, years: number[], exclude: ExcludeItem[], direction: Direction): string | null;
1556
+ declare function findMonth(value: string, years: number[], exclude: ExcludeItem[], direction: Direction, indexed?: number): string[];
1557
1557
  declare function getMonthCalendarProps({ year, data, value, format }: CalendarMonthProps): any;
1558
1558
 
1559
1559
  declare const rgbToHex: (r: number, g: number, b: number) => string;
@@ -2179,6 +2179,8 @@ type MonthSelectorProps = {
2179
2179
  }[];
2180
2180
  };
2181
2181
  format?: DTXFormat;
2182
+ lastIndex?: number;
2183
+ nextIndex?: number;
2182
2184
  onNext?: (value: string) => void;
2183
2185
  onLast?: (value: string) => void;
2184
2186
  onChange: (value: string) => void;
package/dist/index.js CHANGED
@@ -2012,43 +2012,37 @@ function getMonthCalendar(dataFormat, year, month, startIndex, selected, props)
2012
2012
  props
2013
2013
  };
2014
2014
  }
2015
- function findMonth(value, years, exclude, direction) {
2016
- if (!value) return null;
2015
+ function findMonth(value, years, exclude, direction, indexed = 1) {
2016
+ if (!value) return [];
2017
2017
  let [month, year] = value.split("-").map(Number);
2018
2018
  month -= 1;
2019
2019
  const excludedMap = /* @__PURE__ */ new Map();
2020
2020
  exclude.forEach((item) => {
2021
- excludedMap.set(
2022
- item.year,
2023
- new Set(item.months)
2024
- );
2021
+ excludedMap.set(item.year, new Set(item.months));
2025
2022
  });
2026
2023
  const sortedYears = [...years].sort((a, b) => a - b);
2027
- while (true) {
2024
+ const result = [];
2025
+ while (result.length < indexed) {
2028
2026
  month += direction === "next" ? 1 : -1;
2029
2027
  if (month > 11) {
2030
- const yearIndex = sortedYears.indexOf(year);
2031
- const nextYear = sortedYears[yearIndex + 1];
2032
- if (nextYear == null) {
2033
- return null;
2034
- }
2028
+ const nextYear = sortedYears[sortedYears.indexOf(year) + 1];
2029
+ if (nextYear == null) break;
2035
2030
  year = nextYear;
2036
2031
  month = 0;
2037
2032
  }
2038
2033
  if (month < 0) {
2039
- const yearIndex = sortedYears.indexOf(year);
2040
- const prevYear = sortedYears[yearIndex - 1];
2041
- if (prevYear == null) {
2042
- return null;
2043
- }
2034
+ const prevYear = sortedYears[sortedYears.indexOf(year) - 1];
2035
+ if (prevYear == null) break;
2044
2036
  year = prevYear;
2045
2037
  month = 11;
2046
2038
  }
2047
- const excluded = excludedMap.get(year)?.has(month);
2048
- if (!excluded) {
2049
- return `${String(month + 1).padStart(2, "0")}-${year}`;
2039
+ if (!excludedMap.get(year)?.has(month)) {
2040
+ result.push(
2041
+ `${String(month + 1).padStart(2, "0")}-${year}`
2042
+ );
2050
2043
  }
2051
2044
  }
2045
+ return result;
2052
2046
  }
2053
2047
  function getMonthCalendarProps({ year, data, value, format }) {
2054
2048
  const dtx2 = date(new Date(year, 1.1), format);
@@ -3848,7 +3842,7 @@ var initialPropsComponent3 = {
3848
3842
  style: {}
3849
3843
  }
3850
3844
  };
3851
- var MonthSelector = ({ label, value, disabled, propsComponent, data, format, onNext, onLast, onChange }) => {
3845
+ var MonthSelector = ({ label, value, disabled, propsComponent, data, format, onNext, onLast, onChange, lastIndex, nextIndex }) => {
3852
3846
  const [open, setOpen] = React11.useState(false);
3853
3847
  const [valueState, setValueState] = React11.useState(value || null);
3854
3848
  const [yearSelected, setYearSelected] = React11.useState(data?.years.findIndex((y) => y === data.year) || 0);
@@ -3868,8 +3862,8 @@ var MonthSelector = ({ label, value, disabled, propsComponent, data, format, onN
3868
3862
  const newValue = `${month}-${data.years[yearSelected]}`;
3869
3863
  setValueState(newValue);
3870
3864
  onChange(newValue);
3871
- onNext?.(findMonth(newValue, data.years, data.exclude, "next"));
3872
- onLast?.(findMonth(newValue, data.years, data.exclude, "prev"));
3865
+ onNext?.(findMonth(newValue, data.years, data.exclude, "next", nextIndex));
3866
+ onLast?.(findMonth(newValue, data.years, data.exclude, "prev", lastIndex));
3873
3867
  setOpen(false);
3874
3868
  };
3875
3869
  const classes = monthSelectorVariants({ wrapper: true, disabled });
package/package.json CHANGED
@@ -1,15 +1,16 @@
1
1
  {
2
2
  "name": "@yr3/ui",
3
- "version": "1.1.06",
3
+ "version": "1.1.07",
4
4
  "main": "dist/index.cjs",
5
5
  "module": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "scripts": {
8
+ "start": "concurrently \"npm:dev\" \"npm:demo\"",
8
9
  "build": "tsup && npm run build:css",
9
- "dev": "tsup --watch",
10
+ "dev": "concurrently \"tsup --watch\" \"sass --watch src:dist\"",
11
+ "demo": "vite --port 1235",
10
12
  "test": "vitest",
11
13
  "test:watch": "vitest --watch",
12
- "demo": "vite --port 1235",
13
14
  "build:css": "sass src:dist"
14
15
  },
15
16
  "repository": {
@@ -36,6 +37,7 @@
36
37
  "@types/react": "^19.2.14",
37
38
  "@types/react-dom": "^19.2.3",
38
39
  "@vitejs/plugin-react": "^6.0.1",
40
+ "concurrently": "^10.0.3",
39
41
  "jsdom": "^27.0.1",
40
42
  "sass": "^1.99.0",
41
43
  "tsup": "^8.5.1",