xxf_react 0.3.4 → 0.3.6

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.
@@ -59,4 +59,4 @@ interface UseReloadKeyReturn {
59
59
  */
60
60
  export declare function useReloadKey(options?: UseReloadKeyOptions): UseReloadKeyReturn;
61
61
  export {};
62
- //# sourceMappingURL=reload.d.ts.map
62
+ //# sourceMappingURL=Reload.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"reload.d.ts","sourceRoot":"","sources":["../../src/utils/reload.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,UAAU,mBAAmB;IACzB,eAAe;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,QAAQ,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5C;AAED;;GAEG;AACH,UAAU,kBAAkB;IACxB,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,sBAAsB;IACtB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,+BAA+B;IAC/B,WAAW,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,kBAAkB,CA+BlF"}
1
+ {"version":3,"file":"Reload.d.ts","sourceRoot":"","sources":["../../src/utils/Reload.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,UAAU,mBAAmB;IACzB,eAAe;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,8BAA8B;IAC9B,QAAQ,CAAC,EAAE,CAAC,WAAW,EAAE,MAAM,KAAK,IAAI,CAAC;CAC5C;AAED;;GAEG;AACH,UAAU,kBAAkB;IACxB,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,sBAAsB;IACtB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,+BAA+B;IAC/B,WAAW,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,kBAAkB,CA+BlF"}
@@ -69,4 +69,4 @@ export declare const useScrollToCenter: <T extends string | number = string>(opt
69
69
  scrollTo: (element: HTMLElement | null, scrollOptions?: ScrollOptions) => void;
70
70
  };
71
71
  export {};
72
- //# sourceMappingURL=scroll-to-center.d.ts.map
72
+ //# sourceMappingURL=ScrollToCenter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScrollToCenter.d.ts","sourceRoot":"","sources":["../../src/utils/ScrollToCenter.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,KAAK,WAAW,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,GAAG,SAAS,CAAC;AAE1D,aAAa;AACb,UAAU,aAAa;IACnB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,4EAA4E;IAC5E,KAAK,CAAC,EAAE,WAAW,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GACxB,SAAS,WAAW,GAAG,IAAI,EAC3B,WAAW,WAAW,GAAG,IAAI,EAC7B,UAAS,aAAkB,SAmD9B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,YA3Dd,WAAW,GAAG,IAAI,aAChB,WAAW,GAAG,IAAI,YACpB,aAAa,SAyDmB,CAAC;AAE9C,mCAAmC;AACnC,UAAU,wBAAwB;IAC9B,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,4EAA4E;IAC5E,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAChE,UAAS,wBAA6B;IA8DlC,oBAAoB;;IAEpB,4BAA4B;2BArCpB,CAAC,kBAAkB,aAAa;IAuCxC,2BAA2B;wBAjBjB,WAAW,GAAG,IAAI,kBAAkB,aAAa;CAoBlE,CAAC"}
@@ -0,0 +1,60 @@
1
+ import { ReactNode, CSSProperties, ElementType, ComponentPropsWithoutRef } from 'react';
2
+ import React from "react";
3
+ export interface ContainerSize {
4
+ width: number;
5
+ height: number;
6
+ }
7
+ interface SizedContainerProps<T extends ElementType = 'div'> {
8
+ /** 子元素渲染函数,接收容器尺寸和就绪状态 */
9
+ children: (size: ContainerSize & {
10
+ isReady: boolean;
11
+ }) => ReactNode;
12
+ /** 容器的 className */
13
+ className?: string;
14
+ /** 容器的 style */
15
+ style?: CSSProperties;
16
+ /** 自定义容器元素类型,默认 div */
17
+ as?: T;
18
+ /** 是否只监听宽度变化 */
19
+ widthOnly?: boolean;
20
+ /** 是否只监听高度变化 */
21
+ heightOnly?: boolean;
22
+ /** 防抖延迟(毫秒) */
23
+ debounce?: number;
24
+ /** 是否跳过首次挂载时的计算 */
25
+ skipOnMount?: boolean;
26
+ /** 尺寸未就绪时显示的占位内容 */
27
+ fallback?: ReactNode;
28
+ /** 尺寸变化时的回调 */
29
+ onResize?: (size: ContainerSize) => void;
30
+ }
31
+ /**
32
+ * 自动测量尺寸的容器组件
33
+ *
34
+ * @example
35
+ * // 基础用法
36
+ * <SizedContainer className="h-full w-full">
37
+ * {({ width, height, isReady }) => (
38
+ * <VirtuosoGrid style={{ width, height }} ... />
39
+ * )}
40
+ * </SizedContainer>
41
+ *
42
+ * @example
43
+ * // 只监听高度,带防抖和占位符
44
+ * <SizedContainer
45
+ * heightOnly
46
+ * debounce={100}
47
+ * fallback={<Skeleton />}
48
+ * >
49
+ * {({ height }) => <List style={{ height }} />}
50
+ * </SizedContainer>
51
+ *
52
+ * @example
53
+ * // 自定义元素类型
54
+ * <SizedContainer as="section" className="h-full">
55
+ * {({ width, height }) => <Chart width={width} height={height} />}
56
+ * </SizedContainer>
57
+ */
58
+ export declare function SizedContainer<T extends ElementType = 'div'>({ children, className, style, as, widthOnly, heightOnly, debounce, skipOnMount, fallback, onResize, }: SizedContainerProps<T> & Omit<ComponentPropsWithoutRef<T>, keyof SizedContainerProps<T>>): React.JSX.Element;
59
+ export {};
60
+ //# sourceMappingURL=SizedContainer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SizedContainer.d.ts","sourceRoot":"","sources":["../../src/utils/SizedContainer.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,OAAO,CAAC;AACxF,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,MAAM,WAAW,aAAa;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAClB;AAED,UAAU,mBAAmB,CAAC,CAAC,SAAS,WAAW,GAAG,KAAK;IACvD,0BAA0B;IAC1B,QAAQ,EAAE,CAAC,IAAI,EAAE,aAAa,GAAG;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,KAAK,SAAS,CAAC;IACpE,oBAAoB;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,gBAAgB;IAChB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,uBAAuB;IACvB,EAAE,CAAC,EAAE,CAAC,CAAC;IACP,gBAAgB;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,gBAAgB;IAChB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,eAAe;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,mBAAmB;IACnB,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,oBAAoB;IACpB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,eAAe;IACf,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,aAAa,KAAK,IAAI,CAAC;CAC5C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,wBAAgB,cAAc,CAAC,CAAC,SAAS,WAAW,GAAG,KAAK,EAAE,EACI,QAAQ,EACR,SAAS,EACT,KAAK,EACL,EAAE,EACF,SAAiB,EACjB,UAAkB,EAClB,QAAQ,EACR,WAAmB,EACnB,QAAQ,EACR,QAAQ,GACX,EAAE,mBAAmB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,EAAE,MAAM,mBAAmB,CAAC,CAAC,CAAC,CAAC,qBAmCxJ"}
@@ -0,0 +1,60 @@
1
+ 'use client';
2
+ import { useResizeDetector } from 'react-resize-detector';
3
+ import React from "react";
4
+ /**
5
+ * 自动测量尺寸的容器组件
6
+ *
7
+ * @example
8
+ * // 基础用法
9
+ * <SizedContainer className="h-full w-full">
10
+ * {({ width, height, isReady }) => (
11
+ * <VirtuosoGrid style={{ width, height }} ... />
12
+ * )}
13
+ * </SizedContainer>
14
+ *
15
+ * @example
16
+ * // 只监听高度,带防抖和占位符
17
+ * <SizedContainer
18
+ * heightOnly
19
+ * debounce={100}
20
+ * fallback={<Skeleton />}
21
+ * >
22
+ * {({ height }) => <List style={{ height }} />}
23
+ * </SizedContainer>
24
+ *
25
+ * @example
26
+ * // 自定义元素类型
27
+ * <SizedContainer as="section" className="h-full">
28
+ * {({ width, height }) => <Chart width={width} height={height} />}
29
+ * </SizedContainer>
30
+ */
31
+ export function SizedContainer({ children, className, style, as, widthOnly = false, heightOnly = false, debounce, skipOnMount = false, fallback, onResize, }) {
32
+ const { width, height, ref } = useResizeDetector({
33
+ handleWidth: !heightOnly,
34
+ handleHeight: !widthOnly,
35
+ refreshMode: debounce ? 'debounce' : undefined,
36
+ refreshRate: debounce,
37
+ skipOnMount,
38
+ onResize: onResize
39
+ ? ({ width: w, height: h }) => {
40
+ if (w !== null && h !== null) {
41
+ onResize({ width: w, height: h });
42
+ }
43
+ }
44
+ : undefined,
45
+ });
46
+ const size = {
47
+ width: width !== null && width !== void 0 ? width : 0,
48
+ height: height !== null && height !== void 0 ? height : 0,
49
+ };
50
+ // 根据监听模式判断是否就绪
51
+ const isReady = (() => {
52
+ if (widthOnly)
53
+ return size.width > 0;
54
+ if (heightOnly)
55
+ return size.height > 0;
56
+ return size.width > 0 && size.height > 0;
57
+ })();
58
+ const Component = as || 'div';
59
+ return (React.createElement(Component, { ref: ref, className: className, style: style }, isReady ? children({ ...size, isReady }) : fallback));
60
+ }
@@ -1,3 +1,4 @@
1
- export * from './scroll-to-center';
2
- export * from './reload';
1
+ export * from './ScrollToCenter';
2
+ export * from './Reload';
3
+ export * from './SizedContainer';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,cAAc,oBAAoB,CAAA;AAClC,cAAc,UAAU,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAEA,cAAc,kBAAkB,CAAA;AAChC,cAAc,UAAU,CAAA;AACxB,cAAc,kBAAkB,CAAA"}
@@ -1,3 +1,4 @@
1
1
  'use client';
2
- export * from './scroll-to-center';
3
- export * from './reload';
2
+ export * from './ScrollToCenter';
3
+ export * from './Reload';
4
+ export * from './SizedContainer';
package/package.json CHANGED
@@ -1,13 +1,10 @@
1
1
  {
2
2
  "name": "xxf_react",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "private": false,
5
-
6
5
  "type": "module",
7
-
8
6
  "main": "dist/index.js",
9
7
  "types": "dist/index.d.ts",
10
-
11
8
  "exports": {
12
9
  ".": {
13
10
  "types": "./dist/index.d.ts",
@@ -50,28 +47,26 @@
50
47
  "import": "./dist/foundation/index.js"
51
48
  }
52
49
  },
53
-
54
50
  "files": ["dist"],
55
-
56
51
  "scripts": {
57
52
  "build": "tsc"
58
53
  },
59
-
60
54
  "peerDependencies": {
61
55
  "react": ">=18"
62
56
  },
63
-
64
57
  "dependencies": {
65
58
  "@microsoft/fetch-event-source": "^2.0.1",
59
+ "@use-gesture/react": "^10.3.1",
60
+ "dayjs": "^1.11.19",
61
+ "mitt": "^3.0.1",
66
62
  "react-async-hook": "^4.0.0",
63
+ "react-resize-detector": "^12.3.0",
67
64
  "react-responsive": "^10.0.1",
68
65
  "react-toastify": "^11.0.5",
66
+ "react-virtualized-auto-sizer": "^2.0.2",
69
67
  "react-virtuoso": "^4.17.0",
70
- "use-debounce": "^10.0.6",
71
- "mitt": "^3.0.1",
72
- "@use-gesture/react": "^10.3.1",
68
+ "tailwind-variants": "^3.2.2",
73
69
  "tiny-lru": "^11.4.7",
74
- "dayjs": "^1.11.19",
75
- "tailwind-variants": "^3.2.2"
70
+ "use-debounce": "^10.0.6"
76
71
  }
77
72
  }
@@ -1,2 +0,0 @@
1
- export declare function test(): void;
2
- //# sourceMappingURL=TestUtils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"TestUtils.d.ts","sourceRoot":"","sources":["../../src/utils/TestUtils.ts"],"names":[],"mappings":"AAAA,wBAAgB,IAAI,SAEnB"}
@@ -1,3 +0,0 @@
1
- export function test() {
2
- console.log("==============>test success");
3
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"scroll-to-center.d.ts","sourceRoot":"","sources":["../../src/utils/scroll-to-center.ts"],"names":[],"mappings":"AAEA,aAAa;AACb,KAAK,WAAW,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,GAAG,SAAS,CAAC;AAE1D,aAAa;AACb,UAAU,aAAa;IACnB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,4EAA4E;IAC5E,KAAK,CAAC,EAAE,WAAW,CAAC;CACvB;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,GACxB,SAAS,WAAW,GAAG,IAAI,EAC3B,WAAW,WAAW,GAAG,IAAI,EAC7B,UAAS,aAAkB,SAmD9B,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,YA3Dd,WAAW,GAAG,IAAI,aAChB,WAAW,GAAG,IAAI,YACpB,aAAa,SAyDmB,CAAC;AAE9C,mCAAmC;AACnC,UAAU,wBAAwB;IAC9B,kDAAkD;IAClD,YAAY,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,4EAA4E;IAC5E,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,kEAAkE;IAClE,QAAQ,CAAC,EAAE,cAAc,CAAC;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,SAAS,MAAM,GAAG,MAAM,GAAG,MAAM,EAChE,UAAS,wBAA6B;IA8DlC,oBAAoB;;IAEpB,4BAA4B;2BArCpB,CAAC,kBAAkB,aAAa;IAuCxC,2BAA2B;wBAjBjB,WAAW,GAAG,IAAI,kBAAkB,aAAa;CAoBlE,CAAC"}
@@ -1,14 +0,0 @@
1
- import { type ClassValue } from 'clsx';
2
- /**
3
- * // ❌ 直接用 twMerge 很麻烦
4
- * twMerge(`base ${isActive ? 'bg-blue-500' : ''} ${isDisabled ? 'opacity-50' : ''}`)
5
- *
6
- * // ✅ 用 cn 更简洁
7
- * cn('base', isActive && 'bg-blue-500', isDisabled && 'opacity-50')
8
- * cn('base', { 'bg-blue-500': isActive, 'opacity-50': isDisabled })
9
- *
10
- * 合并css样式
11
- * @param inputs
12
- */
13
- export declare function cn(...inputs: ClassValue[]): string;
14
- //# sourceMappingURL=tailwind.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tailwind.d.ts","sourceRoot":"","sources":["../../src/utils/tailwind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAO,KAAK,UAAU,EAAC,MAAM,MAAM,CAAA;AAI1C;;;;;;;;;;GAUG;AACH,wBAAgB,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,UAEzC"}
@@ -1,16 +0,0 @@
1
- import { clsx } from 'clsx';
2
- import { twMerge } from "tailwind-merge";
3
- /**
4
- * // ❌ 直接用 twMerge 很麻烦
5
- * twMerge(`base ${isActive ? 'bg-blue-500' : ''} ${isDisabled ? 'opacity-50' : ''}`)
6
- *
7
- * // ✅ 用 cn 更简洁
8
- * cn('base', isActive && 'bg-blue-500', isDisabled && 'opacity-50')
9
- * cn('base', { 'bg-blue-500': isActive, 'opacity-50': isDisabled })
10
- *
11
- * 合并css样式
12
- * @param inputs
13
- */
14
- export function cn(...inputs) {
15
- return twMerge(clsx(inputs));
16
- }
File without changes