@yr3/ui 1.1.5 → 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);
@@ -3590,7 +3584,7 @@ var initialPropsComponent2 = {
3590
3584
  container: {},
3591
3585
  onClose: false
3592
3586
  };
3593
- var Drawer = ({ open, anchor = null, onClose, children, propsComponent }) => {
3587
+ var Drawer = ({ open, anchor = null, onClose, children, propsComponent, onTransitionEnd }) => {
3594
3588
  const { show, hide } = useBackdrop();
3595
3589
  const ref = React9.useRef(null);
3596
3590
  const properties = mergeDeep2(initialPropsComponent2, propsComponent);
@@ -3617,6 +3611,10 @@ var Drawer = ({ open, anchor = null, onClose, children, propsComponent }) => {
3617
3611
  }, [properties?.onClose]);
3618
3612
  const classesBem = bem("yr3Drawer");
3619
3613
  const drawerClasses = classesBem(void 0, { [anchor]: anchor, open });
3614
+ const stateRef = React9.useRef(open ? "in" : "out");
3615
+ React9.useEffect(() => {
3616
+ stateRef.current = open ? "in" : "out";
3617
+ }, [open]);
3620
3618
  return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
3621
3619
  "div",
3622
3620
  {
@@ -3624,6 +3622,11 @@ var Drawer = ({ open, anchor = null, onClose, children, propsComponent }) => {
3624
3622
  style: properties?.drawer,
3625
3623
  onClick: (e) => e.stopPropagation(),
3626
3624
  ref,
3625
+ onTransitionEnd: (e) => {
3626
+ if (e.target === e.currentTarget && e.propertyName === "transform") {
3627
+ onTransitionEnd?.(stateRef?.current);
3628
+ }
3629
+ },
3627
3630
  "data-testid": "yr3Drawer",
3628
3631
  children: /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
3629
3632
  DrawerContainer_default,
@@ -3960,7 +3963,7 @@ var initialPropsComponent3 = {
3960
3963
  style: {}
3961
3964
  }
3962
3965
  };
3963
- 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 }) => {
3964
3967
  const [open, setOpen] = React11.useState(false);
3965
3968
  const [valueState, setValueState] = React11.useState(value || null);
3966
3969
  const [yearSelected, setYearSelected] = React11.useState(data?.years.findIndex((y) => y === data.year) || 0);
@@ -3980,8 +3983,8 @@ var MonthSelector = ({ label, value, disabled, propsComponent, data, format, onN
3980
3983
  const newValue = `${month}-${data.years[yearSelected]}`;
3981
3984
  setValueState(newValue);
3982
3985
  onChange(newValue);
3983
- onNext?.(findMonth(newValue, data.years, data.exclude, "next"));
3984
- 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));
3985
3988
  setOpen(false);
3986
3989
  };
3987
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;
@@ -2104,6 +2104,7 @@ type DrawerProps = {
2104
2104
  onClose: () => void;
2105
2105
  children?: React$1.ReactNode;
2106
2106
  anchor?: 'left' | 'right' | 'top' | 'bottom' | null;
2107
+ onTransitionEnd?: (state: 'in' | 'out') => void;
2107
2108
  propsComponent?: {
2108
2109
  drawer?: React$1.CSSProperties;
2109
2110
  closing?: "drawer" | "container" | null;
@@ -2178,6 +2179,8 @@ type MonthSelectorProps = {
2178
2179
  }[];
2179
2180
  };
2180
2181
  format?: DTXFormat;
2182
+ lastIndex?: number;
2183
+ nextIndex?: number;
2181
2184
  onNext?: (value: string) => void;
2182
2185
  onLast?: (value: string) => void;
2183
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;
@@ -2104,6 +2104,7 @@ type DrawerProps = {
2104
2104
  onClose: () => void;
2105
2105
  children?: React$1.ReactNode;
2106
2106
  anchor?: 'left' | 'right' | 'top' | 'bottom' | null;
2107
+ onTransitionEnd?: (state: 'in' | 'out') => void;
2107
2108
  propsComponent?: {
2108
2109
  drawer?: React$1.CSSProperties;
2109
2110
  closing?: "drawer" | "container" | null;
@@ -2178,6 +2179,8 @@ type MonthSelectorProps = {
2178
2179
  }[];
2179
2180
  };
2180
2181
  format?: DTXFormat;
2182
+ lastIndex?: number;
2183
+ nextIndex?: number;
2181
2184
  onNext?: (value: string) => void;
2182
2185
  onLast?: (value: string) => void;
2183
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);
@@ -3469,7 +3463,7 @@ var initialPropsComponent2 = {
3469
3463
  container: {},
3470
3464
  onClose: false
3471
3465
  };
3472
- var Drawer = ({ open, anchor = null, onClose, children, propsComponent }) => {
3466
+ var Drawer = ({ open, anchor = null, onClose, children, propsComponent, onTransitionEnd }) => {
3473
3467
  const { show, hide } = useBackdrop();
3474
3468
  const ref = React9.useRef(null);
3475
3469
  const properties = mergeDeep2(initialPropsComponent2, propsComponent);
@@ -3496,6 +3490,10 @@ var Drawer = ({ open, anchor = null, onClose, children, propsComponent }) => {
3496
3490
  }, [properties?.onClose]);
3497
3491
  const classesBem = bem("yr3Drawer");
3498
3492
  const drawerClasses = classesBem(void 0, { [anchor]: anchor, open });
3493
+ const stateRef = React9.useRef(open ? "in" : "out");
3494
+ React9.useEffect(() => {
3495
+ stateRef.current = open ? "in" : "out";
3496
+ }, [open]);
3499
3497
  return /* @__PURE__ */ jsx18(
3500
3498
  "div",
3501
3499
  {
@@ -3503,6 +3501,11 @@ var Drawer = ({ open, anchor = null, onClose, children, propsComponent }) => {
3503
3501
  style: properties?.drawer,
3504
3502
  onClick: (e) => e.stopPropagation(),
3505
3503
  ref,
3504
+ onTransitionEnd: (e) => {
3505
+ if (e.target === e.currentTarget && e.propertyName === "transform") {
3506
+ onTransitionEnd?.(stateRef?.current);
3507
+ }
3508
+ },
3506
3509
  "data-testid": "yr3Drawer",
3507
3510
  children: /* @__PURE__ */ jsx18(
3508
3511
  DrawerContainer_default,
@@ -3839,7 +3842,7 @@ var initialPropsComponent3 = {
3839
3842
  style: {}
3840
3843
  }
3841
3844
  };
3842
- 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 }) => {
3843
3846
  const [open, setOpen] = React11.useState(false);
3844
3847
  const [valueState, setValueState] = React11.useState(value || null);
3845
3848
  const [yearSelected, setYearSelected] = React11.useState(data?.years.findIndex((y) => y === data.year) || 0);
@@ -3859,8 +3862,8 @@ var MonthSelector = ({ label, value, disabled, propsComponent, data, format, onN
3859
3862
  const newValue = `${month}-${data.years[yearSelected]}`;
3860
3863
  setValueState(newValue);
3861
3864
  onChange(newValue);
3862
- onNext?.(findMonth(newValue, data.years, data.exclude, "next"));
3863
- 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));
3864
3867
  setOpen(false);
3865
3868
  };
3866
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.05",
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",