@tonar/react-kit 0.3.1 → 0.3.3

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.
@@ -1,3 +1,3 @@
1
- import { i as Carousel, n as AsyncCustomShow, r as CustomShow, t as ErrorBoundary } from "./js/components.BkNTLVji.js";
1
+ import { i as Carousel, n as AsyncCustomShow, r as CustomShow, t as ErrorBoundary } from "./js/components.v42ygn9n.js";
2
2
 
3
3
  export { AsyncCustomShow, Carousel, CustomShow, ErrorBoundary };
package/dist/hooks.es.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
2
  import { clearRAfInterval, rAfInterval } from "@tonar/utils";
3
3
 
4
- //#region src/hooks/state/index.ts
4
+ // src/hooks/state/index.ts
5
5
  function useStaticState(initialValue) {
6
6
  const ref = useRef(initialValue);
7
7
  return [
@@ -66,8 +66,7 @@ const useCreateSafeRef = (hasDiff) => {
66
66
  ];
67
67
  };
68
68
 
69
- //#endregion
70
- //#region src/hooks/timer/index.ts
69
+ // src/hooks/timer/index.ts
71
70
  /**
72
71
  * @author sonion
73
72
  * @description 自管理定时器的interval
@@ -114,8 +113,7 @@ const useRAfInterval = (cb, duration) => {
114
113
  ]), useCallback(() => clearRAfInterval(withTimer()), [withTimer])];
115
114
  };
116
115
 
117
- //#endregion
118
- //#region src/hooks/observer/index.ts
116
+ // src/hooks/observer/index.ts
119
117
  /**
120
118
  * @author sonion
121
119
  * @description dom变化观察器hook
@@ -244,8 +242,7 @@ const useResizeObserver = (callback, once = false) => {
244
242
  };
245
243
  };
246
244
 
247
- //#endregion
248
- //#region src/hooks/storage/index.ts
245
+ // src/hooks/storage/index.ts
249
246
  /**
250
247
  * @author sonion
251
248
  * @description 本地储存
@@ -322,8 +319,7 @@ const useStorage = ({ key, defaultValue, hasDiff, onChange, storage = localStora
322
319
  ];
323
320
  };
324
321
 
325
- //#endregion
326
- //#region src/hooks/async-guard/index.ts
322
+ // src/hooks/async-guard/index.ts
327
323
  /**
328
324
  * @author sonion
329
325
  * @description 异步操作锁,防止重复调用。通过返回的 Promise 确定是否执行中,执行中不可重复触发。
@@ -365,5 +361,4 @@ const useAsyncActionLock = (asyncAction, onPendingChange, msg) => {
365
361
  ])];
366
362
  };
367
363
 
368
- //#endregion
369
364
  export { useAsyncActionLock, useCreateSafeRef, useDistinctState, useIntersectionObserver, useInterval, useLatestCallback, useMutationObserver, useRAfInterval, useResizeObserver, useStaticState, useStorage };
package/dist/index.es.js CHANGED
@@ -1,4 +1,4 @@
1
1
  import { useAsyncActionLock, useCreateSafeRef, useDistinctState, useIntersectionObserver, useInterval, useLatestCallback, useMutationObserver, useRAfInterval, useResizeObserver, useStaticState, useStorage } from "./hooks.es.js";
2
- import { i as Carousel, n as AsyncCustomShow, r as CustomShow, t as ErrorBoundary } from "./js/components.BkNTLVji.js";
2
+ import { i as Carousel, n as AsyncCustomShow, r as CustomShow, t as ErrorBoundary } from "./js/components.v42ygn9n.js";
3
3
 
4
4
  export { AsyncCustomShow, Carousel, CustomShow, ErrorBoundary, useAsyncActionLock, useCreateSafeRef, useDistinctState, useIntersectionObserver, useInterval, useLatestCallback, useMutationObserver, useRAfInterval, useResizeObserver, useStaticState, useStorage };
@@ -3,7 +3,7 @@ import { useCreateSafeRef, useRAfInterval } from "../hooks.es.js";
3
3
  import { Component, cloneElement, forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
 
6
- //#region src/components/carousel/hooks/index.ts
6
+ // src/components/carousel/hooks/index.ts
7
7
  /**
8
8
  * @author sonion
9
9
  * @description 无动画切换
@@ -193,8 +193,7 @@ const useLoopChildren = (children, loop, rerender) => useMemo(() => {
193
193
  return children;
194
194
  }, [rerender === "child" ? children : children?.length, loop]);
195
195
 
196
- //#endregion
197
- //#region src/components/carousel/index.module.scss
196
+ // src/components/carousel/index.module.scss
198
197
  var index_module_default = {
199
198
  "arrow": "arrow__5vdU-W",
200
199
  "carousel": "carousel__5vdU-W",
@@ -205,8 +204,7 @@ var index_module_default = {
205
204
  "wrapper": "wrapper__5vdU-W"
206
205
  };
207
206
 
208
- //#endregion
209
- //#region src/components/carousel/index.tsx
207
+ // src/components/carousel/index.tsx
210
208
  /**
211
209
  * @author sonion
212
210
  * @description 轮播组件,用于展示多个轮播项
@@ -311,8 +309,7 @@ const Carousel = forwardRef(({ cardWidth, cardHeight, wrapperWidth, wrapperHeigh
311
309
  });
312
310
  Carousel.displayName = "Carousel";
313
311
 
314
- //#endregion
315
- //#region src/components/custom-show/index.tsx
312
+ // src/components/custom-show/index.tsx
316
313
  /**
317
314
  * @author sonion
318
315
  * @description 根据条件渲染内容,替代用三目运算和短路规则条件渲染
@@ -326,8 +323,7 @@ function CustomShow({ when, fallback = void 0, children }) {
326
323
  return /* @__PURE__ */ jsx(Fragment, { children: when ? children : fallback });
327
324
  }
328
325
 
329
- //#endregion
330
- //#region src/components/async-custom-show/index.tsx
326
+ // src/components/async-custom-show/index.tsx
331
327
  /**
332
328
  * @author sonion
333
329
  * @description 异步展示组件
@@ -347,8 +343,7 @@ function AsyncCustomShow({ when, fallback, children }) {
347
343
  return /* @__PURE__ */ jsx(Fragment, { children: show ? children(show) : fallback });
348
344
  }
349
345
 
350
- //#endregion
351
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/typeof.js
346
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/typeof.js
352
347
  function _typeof(o) {
353
348
  "@babel/helpers - typeof";
354
349
  return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
@@ -358,8 +353,7 @@ function _typeof(o) {
358
353
  }, _typeof(o);
359
354
  }
360
355
 
361
- //#endregion
362
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/toPrimitive.js
356
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/toPrimitive.js
363
357
  function toPrimitive(t, r) {
364
358
  if ("object" != _typeof(t) || !t) return t;
365
359
  var e = t[Symbol.toPrimitive];
@@ -371,15 +365,13 @@ function toPrimitive(t, r) {
371
365
  return ("string" === r ? String : Number)(t);
372
366
  }
373
367
 
374
- //#endregion
375
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/toPropertyKey.js
368
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/toPropertyKey.js
376
369
  function toPropertyKey(t) {
377
370
  var i = toPrimitive(t, "string");
378
371
  return "symbol" == _typeof(i) ? i : i + "";
379
372
  }
380
373
 
381
- //#endregion
382
- //#region \0@oxc-project+runtime@0.143.0/helpers/esm/defineProperty.js
374
+ // \0@oxc-project+runtime@0.156.0/helpers/esm/defineProperty.js
383
375
  function _defineProperty(e, r, t) {
384
376
  return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
385
377
  value: t,
@@ -389,8 +381,7 @@ function _defineProperty(e, r, t) {
389
381
  }) : e[r] = t, e;
390
382
  }
391
383
 
392
- //#endregion
393
- //#region src/components/error-boundary/index.tsx
384
+ // src/components/error-boundary/index.tsx
394
385
  /**
395
386
  * @author sonion
396
387
  * @description 错误边界组件,用于捕获子组件的错误并显示自定义的回退内容
@@ -418,5 +409,4 @@ var ErrorBoundary = class extends Component {
418
409
  }
419
410
  };
420
411
 
421
- //#endregion
422
412
  export { Carousel as i, AsyncCustomShow as n, CustomShow as r, ErrorBoundary as t };
@@ -1,5 +1,4 @@
1
1
  import { FC, JSX, ReactNode } from "react";
2
- //#region src/components/async-custom-show/index.d.ts
3
2
  type AsyncCustomShowProps<T> = {
4
3
  /** 异步判断 Promise */
5
4
  when: Promise<T> | undefined | null | false;
@@ -20,5 +19,4 @@ interface AsyncCustomShowType<T> extends FC<AsyncCustomShowProps<T>> {
20
19
  * @param {(value: T | undefined | null | false) => ReactNode} props.children 异步成功时的展示
21
20
  */
22
21
  declare function AsyncCustomShow<T>({ when, fallback, children }: AsyncCustomShowProps<T>): JSX.Element;
23
- //#endregion
24
22
  export { AsyncCustomShowProps, AsyncCustomShowType, AsyncCustomShow as default };
@@ -1,5 +1,4 @@
1
1
  import { ReactElement } from "react";
2
- //#region src/components/carousel/hooks/index.d.ts
3
2
  type ShowArrowType = 'always' | 'auto' | 'hover' | 'none';
4
3
  type NonLoopEndFuncType = (
5
4
  /** 切换方向 */
@@ -16,5 +15,4 @@ offset: number) => void;
16
15
  * child 依赖 children本身的变化
17
16
  */
18
17
  type RerenderType = 'length' | 'child';
19
- //#endregion
20
18
  export { NonLoopEndFuncType, RerenderType, ShowArrowType };
@@ -1,6 +1,5 @@
1
1
  import { NonLoopEndFuncType, RerenderType, ShowArrowType } from "./hooks/index.js";
2
2
  import { CSSProperties, FC, ReactElement } from "react";
3
- //#region src/components/carousel/index.d.ts
4
3
  type IndicatorType = 'line' | 'dot' | 'none';
5
4
  type CarouselProps = {
6
5
  /** 单个轮播项的宽度 */
@@ -84,5 +83,4 @@ type CarouselRef = {
84
83
  */
85
84
  declare const Carousel: import("react").ForwardRefExoticComponent<CarouselProps & import("react").RefAttributes<CarouselRef>>;
86
85
  type CarouselType = typeof Carousel;
87
- //#endregion
88
86
  export { CarouselProps, CarouselRef, type CarouselType, type RerenderType, type ShowArrowType, Carousel as default };
@@ -1,5 +1,4 @@
1
1
  import { FC, JSX, PropsWithChildren, ReactNode } from "react";
2
- //#region src/components/custom-show/index.d.ts
3
2
  type CustomShowProps<T> = PropsWithChildren<{
4
3
  /** 判断条件 */
5
4
  when: T | null | undefined | false;
@@ -19,5 +18,4 @@ interface CustomShowType<T> extends FC<CustomShowProps<T>> {
19
18
  * @returns {JSX.Element} - 组件节点
20
19
  */
21
20
  declare function CustomShow<T>({ when, fallback, children }: CustomShowProps<T>): JSX.Element;
22
- //#endregion
23
21
  export { CustomShowProps, CustomShowType, CustomShow as default };
@@ -1,5 +1,4 @@
1
1
  import { Component, ErrorInfo, ReactNode } from "react";
2
- //#region src/components/error-boundary/index.d.ts
3
2
  interface ErrorBoundaryProps {
4
3
  /** 正常展示 */
5
4
  children: ReactNode;
@@ -28,5 +27,4 @@ declare class ErrorBoundary extends Component<ErrorBoundaryProps, State> {
28
27
  render(): ReactNode;
29
28
  }
30
29
  type ErrorBoundaryType = typeof ErrorBoundary;
31
- //#endregion
32
30
  export { ErrorBoundaryProps, type ErrorBoundaryType, ErrorBoundary as default };
@@ -1,4 +1,3 @@
1
- //#region src/hooks/async-guard/index.d.ts
2
1
  /**
3
2
  * @author sonion
4
3
  * @description 异步操作锁,防止重复调用。通过返回的 Promise 确定是否执行中,执行中不可重复触发。
@@ -8,5 +7,4 @@
8
7
  * @returns {[boolean, (...args: T) => Promise<R | void>]} - 返回是否执行中,执行方法
9
8
  */
10
9
  declare const useAsyncActionLock: <T extends unknown[], R>(asyncAction: (...args: T) => Promise<R>, onPendingChange?: (isPending: boolean, ...args: T) => void, msg?: string) => readonly [boolean, (...args: T) => Promise<R | void>];
11
- //#endregion
12
10
  export { useAsyncActionLock };
@@ -1,4 +1,3 @@
1
- //#region src/hooks/observer/index.d.ts
2
1
  type MutationObserverCallback = (entry: MutationRecord[], observer: MutationObserver) => void;
3
2
  /**
4
3
  * @author sonion
@@ -68,5 +67,4 @@ declare const useResizeObserver: (callback: ResizeObserverCallback, once?: boole
68
67
  /** 取消所有观察,用observe重新启用 */
69
68
  disconnect: () => void | undefined;
70
69
  };
71
- //#endregion
72
70
  export { useIntersectionObserver, useMutationObserver, useResizeObserver };
@@ -1,5 +1,4 @@
1
1
  import { SetStateAction } from "react";
2
- //#region src/hooks/state/index.d.ts
3
2
  /**
4
3
  * @author sonion
5
4
  * @description 创建静态的state, 不会触发组件重新渲染
@@ -47,5 +46,4 @@ declare function useDistinctState<T>(params: {
47
46
  * @param {(oldNode?: T, newNode?: T) => boolean} [hasDiff] - 对比函数,返回true变更生效。默认对比引用是否不相同。
48
47
  */
49
48
  declare const useCreateSafeRef: <T extends object = HTMLElement>(hasDiff?: (oldNode?: T, newNode?: T) => boolean) => readonly [T | undefined, (node: T | null) => void, import("react").MutableRefObject<boolean>];
50
- //#endregion
51
49
  export { useCreateSafeRef, useDistinctState, useLatestCallback, useStaticState };
@@ -1,5 +1,4 @@
1
1
  import { useDistinctState } from "../state/index.js";
2
- //#region src/hooks/storage/index.d.ts
3
2
  type StorageParams<T> = Omit<Parameters<typeof useDistinctState<T>>[0], 'onlyEvent' | 'initialValue'> & {
4
3
  /** 储存的key */
5
4
  key: string;
@@ -25,5 +24,4 @@ type StorageParams<T> = Omit<Parameters<typeof useDistinctState<T>>[0], 'onlyEve
25
24
  * @param [params.beforeunload] - tab关闭前的回调。
26
25
  */
27
26
  declare const useStorage: <T>({ key, defaultValue, hasDiff, onChange, storage, checkType, beforeunload }: StorageParams<T>) => readonly [T, (value: T | ((val: T) => T)) => void, () => void, () => void | undefined];
28
- //#endregion
29
27
  export { useStorage };
@@ -1,4 +1,3 @@
1
- //#region src/hooks/timer/index.d.ts
2
1
  /**
3
2
  * @author sonion
4
3
  * @description 自管理定时器的interval
@@ -15,5 +14,4 @@ declare const useInterval: (cb: () => void, duration: number) => readonly [() =>
15
14
  * @returns {[() => void, () => void]} - [启动函数, 清除函数]
16
15
  */
17
16
  declare const useRAfInterval: (cb: () => void, duration: number) => readonly [() => void, () => void];
18
- //#endregion
19
17
  export { useInterval, useRAfInterval };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tonar/react-kit",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "private": false,
5
5
  "description": "@tonar/react-kit: React 18 components and hooks for carousels, conditional rendering, error boundaries, state helpers, observers, storage, timers, and async action locking.",
6
6
  "keywords": [
@@ -43,14 +43,15 @@
43
43
  }
44
44
  },
45
45
  "dependencies": {
46
- "@tonar/utils": "0.3.1"
46
+ "@tonar/utils": "0.3.3"
47
47
  },
48
48
  "devDependencies": {
49
- "@testing-library/react": "^16.3.2",
49
+ "@testing-library/react": "^16.3.3",
50
50
  "@types/react": "^18.3.31",
51
51
  "@types/react-dom": "^18.3.7",
52
52
  "react": "^18.3.1",
53
- "react-dom": "^18.3.1"
53
+ "react-dom": "^18.3.1",
54
+ "sass": "^1.108.2"
54
55
  },
55
56
  "peerDependencies": {
56
57
  "react": "^18.0.0",