deepsea-components 5.9.6 → 5.10.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.
Files changed (41) hide show
  1. package/dist/cjs/components/Flow.d.ts +2 -2
  2. package/dist/cjs/components/Flow.js +1 -1
  3. package/dist/cjs/components/Flow.js.map +2 -2
  4. package/dist/cjs/components/ImportExcel.d.ts +4 -4
  5. package/dist/cjs/components/ImportExcel.js +4 -5
  6. package/dist/cjs/components/ImportExcel.js.map +2 -2
  7. package/dist/cjs/components/InputFile.d.ts +16 -43
  8. package/dist/cjs/components/InputFile.js +16 -75
  9. package/dist/cjs/components/InputFile.js.map +2 -2
  10. package/dist/cjs/components/InputFileButton.d.ts +10 -0
  11. package/dist/cjs/components/InputFileButton.js +109 -0
  12. package/dist/cjs/components/InputFileButton.js.map +7 -0
  13. package/dist/cjs/components/Unify.d.ts +1 -1
  14. package/dist/cjs/components/Unify.js.map +2 -2
  15. package/dist/cjs/index.d.ts +1 -0
  16. package/dist/cjs/index.js +2 -0
  17. package/dist/cjs/index.js.map +2 -2
  18. package/dist/esm/components/Flow.d.ts +2 -2
  19. package/dist/esm/components/Flow.js +1 -1
  20. package/dist/esm/components/Flow.js.map +1 -1
  21. package/dist/esm/components/ImportExcel.d.ts +4 -4
  22. package/dist/esm/components/ImportExcel.js +4 -8
  23. package/dist/esm/components/ImportExcel.js.map +1 -1
  24. package/dist/esm/components/InputFile.d.ts +16 -43
  25. package/dist/esm/components/InputFile.js +21 -104
  26. package/dist/esm/components/InputFile.js.map +1 -1
  27. package/dist/esm/components/InputFileButton.d.ts +10 -0
  28. package/dist/esm/components/InputFileButton.js +90 -0
  29. package/dist/esm/components/InputFileButton.js.map +1 -0
  30. package/dist/esm/components/Unify.d.ts +1 -1
  31. package/dist/esm/components/Unify.js.map +1 -1
  32. package/dist/esm/index.d.ts +1 -0
  33. package/dist/esm/index.js +1 -0
  34. package/dist/esm/index.js.map +1 -1
  35. package/package.json +7 -7
  36. package/src/components/Flow.tsx +2 -2
  37. package/src/components/ImportExcel.tsx +7 -7
  38. package/src/components/InputFile.tsx +39 -128
  39. package/src/components/InputFileButton.tsx +102 -0
  40. package/src/components/Unify.tsx +1 -1
  41. package/src/index.ts +1 -0
@@ -1,4 +1,4 @@
1
- import { CSSProperties, HTMLAttributes, Key, ReactNode, RefObject } from "react";
1
+ import { CSSProperties, HTMLAttributes, Key, ReactNode, Ref } from "react";
2
2
  export interface FlowSizeData {
3
3
  /** 容器宽度 */
4
4
  width: number;
@@ -68,7 +68,7 @@ export interface FlowProps<T> extends Omit<HTMLAttributes<HTMLDivElement>, "chil
68
68
  transitionDuration?: number;
69
69
  /** 变化的回调函数 */
70
70
  onSizeChange?: (sizeData: FlowSizeData) => void;
71
- element?: RefObject<HTMLDivElement>;
71
+ element?: Ref<HTMLDivElement>;
72
72
  }
73
73
  export declare function getGapRange(gap?: undefined | number | "auto" | (number | "auto")[]): [number, number | "auto"];
74
74
  export interface GapAndCount {
@@ -26,10 +26,10 @@ __export(Flow_exports, {
26
26
  getGapRange: () => getGapRange
27
27
  });
28
28
  module.exports = __toCommonJS(Flow_exports);
29
- var import_react = require("react");
30
29
  var import_css = require("@emotion/css");
31
30
  var import_ahooks = require("ahooks");
32
31
  var import_deepsea_tools = require("deepsea-tools");
32
+ var import_react = require("react");
33
33
  var import_utils = require("../utils");
34
34
  function getGapRange(gap) {
35
35
  if (typeof gap === "number")
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/Flow.tsx"],
4
- "sourcesContent": ["\"use client\"\n\nimport { CSSProperties, HTMLAttributes, Key, ReactNode, RefObject, useEffect, useImperativeHandle, useRef, useState } from \"react\"\nimport { css } from \"@emotion/css\"\nimport { useSize } from \"ahooks\"\nimport { clsx } from \"deepsea-tools\"\n\nimport { px, transformCSSVariable } from \"@/utils\"\n\nexport interface FlowSizeData {\n /** 容器宽度 */\n width: number\n /** 容器高度 */\n height: number\n /** 元素宽度 */\n itemWidth: number\n /** 元素高度 */\n itemHeight: number\n /** 列间距 */\n columnGap: number\n /** 列数 */\n columnCount: number\n /** 行间距 */\n rowGap: number\n /** 行数 */\n rowCount: number\n /** 元素格数 */\n itemCount: number\n /** 最大行数 */\n maxRows: number | null\n /** 是否有元素被隐藏 */\n overflow: boolean\n}\n\nexport interface FlowProps<T> extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** 元素宽度 */\n itemWidth: number\n /** 元素高度 */\n itemHeight: number\n /**\n * 列间距\n * 1. 如果是数字,表示列间距是固定的\n * 2. 如果是 auto,表示会在尽可能放进更多列的情况下,列间距是平均的\n * 2. 如果是数组,表示列间距是区间的,第一个元素是最小值,第二个元素是最大值\n */\n columnGap?: number | \"auto\" | [number | \"auto\", number | \"auto\"]\n /** 行间距 */\n rowGap?: number\n gap?: number\n /** 最大行数 */\n maxRows?: number | null\n /** 源数据 */\n data?: T[]\n /** 渲染 */\n render: (item: T, index: number, arr: T[]) => ReactNode\n /** key释放器,默认为 index */\n keyExactor?: (item: T, index: number, arr: T[]) => Key\n /**\n * 渲染的元素由两层容器包裹,外层容器类名\n */\n wrapperClassName?: string\n /**\n * 渲染的元素由两层容器包裹,外层容器样式\n */\n wrapperStyle?: CSSProperties\n /**\n * 渲染的元素由两层容器包裹,内层容器类名\n */\n containerClassName?: string\n /**\n * 渲染的元素由两层容器包裹,内层容器样式\n */\n containerStyle?: CSSProperties\n /** 节流时间,单位毫秒,默认200ms,传入 0 不节流 */\n throttle?: number\n /** 动画时间,单位毫秒,默认400ms,传入 0 不展示动画 */\n transitionDuration?: number\n /** 变化的回调函数 */\n onSizeChange?: (sizeData: FlowSizeData) => void\n element?: RefObject<HTMLDivElement>\n}\n\nexport function getGapRange(gap?: undefined | number | \"auto\" | (number | \"auto\")[]): [number, number | \"auto\"] {\n if (typeof gap === \"number\") return [gap, gap]\n if (Array.isArray(gap)) return [typeof gap[0] === \"number\" ? gap[0] : 0, gap[1]]\n return [0, \"auto\"]\n}\n\nexport interface GapAndCount {\n count: number\n gap: number\n}\n\nexport function getGapCountAndSize(width: number, itemWidth: number, minGap: number, maxGap: number | \"auto\"): GapAndCount {\n const count = Math.floor((width + minGap) / (itemWidth + minGap)) || 1\n if (count === 1) return { count, gap: 0 }\n const averageGap = (width - itemWidth * count) / (count - 1)\n if (averageGap < minGap) return { count, gap: minGap }\n if (maxGap !== \"auto\" && averageGap > maxGap) return { count, gap: maxGap }\n return { count, gap: averageGap }\n}\n\nexport interface ManualFlowProps<T> extends FlowProps<T> {\n /** 组件宽度,必须指定 */\n width: number\n}\n\n/** 手动组件,由外界指定宽度,性能更好 */\nexport function ManualFlow<T>(props: ManualFlowProps<T>) {\n let {\n itemWidth,\n itemHeight,\n columnGap,\n rowGap,\n maxRows,\n data = [],\n render,\n keyExactor,\n className,\n style,\n wrapperClassName,\n wrapperStyle,\n throttle,\n transitionDuration,\n onSizeChange,\n containerClassName,\n containerStyle,\n gap = 0,\n width,\n element,\n ...rest\n } = props\n rowGap ??= gap\n columnGap ??= gap\n const [minColumnGap, maxColumnGap] = getGapRange(columnGap)\n const [{ count: columnCount, gap: columnGapSize }, setGapAndCount] = useState(() => getGapCountAndSize(width, itemWidth, minColumnGap, maxColumnGap))\n const ele = useRef<HTMLDivElement>(null)\n const contentRows = Math.ceil(data.length / columnCount)\n const contentShownRows = typeof maxRows === \"number\" ? Math.min(contentRows, maxRows) : contentRows\n const height = contentShownRows > 0 ? contentShownRows * (itemHeight + rowGap) - rowGap : 0\n\n function getPosition(index: number) {\n const y = Math.floor(index / columnCount)\n const x = index - y * columnCount\n return {\n left: x * (itemWidth + columnGapSize),\n top: y * (itemHeight + rowGap!),\n }\n }\n\n function getHidden(index: number) {\n if (typeof maxRows !== \"number\") return false\n return index >= maxRows * columnCount\n }\n\n useImperativeHandle(element, () => ele.current!, [ele.current])\n\n useEffect(() => {\n function task() {\n setGapAndCount(getGapCountAndSize(width, itemWidth, minColumnGap, maxColumnGap))\n }\n if (throttle === 0) return task()\n const timeout = setTimeout(task, throttle || 200)\n return () => clearTimeout(timeout)\n }, [width, itemWidth, throttle, minColumnGap, maxColumnGap])\n\n useEffect(() => {\n onSizeChange?.({\n width,\n height,\n itemWidth,\n itemHeight,\n columnGap: columnGapSize,\n columnCount,\n rowGap: rowGap!,\n rowCount: contentShownRows,\n overflow: data.length > contentShownRows * columnCount,\n itemCount: data.length,\n maxRows: maxRows ?? null,\n })\n }, [width, height, columnGapSize, columnCount, rowGap, contentShownRows, data.length, itemWidth, itemHeight, maxRows])\n\n return (\n <div\n ref={ele}\n className={clsx(\n css`\n position: relative;\n height: var(--height);\n overflow: hidden;\n `,\n className,\n )}\n style={transformCSSVariable({ height: px(height) }, style)}\n {...rest}\n >\n {data.map((item, index, arr) => (\n <div\n key={keyExactor ? keyExactor(item, index, arr) : index}\n className={clsx(\n css`\n position: absolute;\n width: var(--width);\n height: var(--height);\n transition: var(--transition);\n left: 0;\n top: 0;\n transform: translate(var(--left), var(--top));\n `,\n wrapperClassName,\n )}\n style={transformCSSVariable(\n {\n width: px(itemWidth),\n height: px(itemHeight),\n transition: transitionDuration === 0 ? \"none\" : `all ${transitionDuration || 400}ms`,\n left: px(getPosition(index).left),\n top: px(getPosition(index).top),\n },\n wrapperStyle,\n )}\n >\n <div\n className={clsx(\n css`\n width: 100%;\n height: 100%;\n display: var(--display);\n `,\n containerClassName,\n )}\n style={transformCSSVariable({ display: getHidden(index) ? \"none\" : \"block\" }, containerStyle)}\n >\n {render(item, index, arr)}\n </div>\n </div>\n ))}\n </div>\n )\n}\n\n/** 自适应浮动组件 */\nexport function Flow<T>(props: FlowProps<T>): ReactNode {\n const {\n itemWidth,\n itemHeight,\n columnGap,\n rowGap,\n gap,\n maxRows,\n data,\n render,\n keyExactor,\n wrapperClassName,\n wrapperStyle,\n containerClassName,\n containerStyle,\n throttle,\n transitionDuration,\n onSizeChange,\n element,\n ...rest\n } = props\n const ele = useRef<HTMLDivElement>(null)\n const size = useSize(ele)\n const width = useRef(size?.width || 0)\n if (size && size.width !== 0) width.current = size.width\n useImperativeHandle(element, () => ele.current!, [ele.current])\n if (width.current === 0) return <div ref={ele} {...rest} />\n return <ManualFlow element={ele} {...props} width={width.current} />\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA2H;AAC3H,iBAAoB;AACpB,oBAAwB;AACxB,2BAAqB;AAErB,mBAAyC;AA2ElC,SAAS,YAAY,KAAoF;AAC5G,MAAI,OAAO,QAAQ;AAAU,WAAO,CAAC,KAAK,GAAG;AAC7C,MAAI,MAAM,QAAQ,GAAG;AAAG,WAAO,CAAC,OAAO,IAAI,CAAC,MAAM,WAAW,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,CAAC;AAC/E,SAAO,CAAC,GAAG,MAAM;AACrB;AAOO,SAAS,mBAAmB,OAAe,WAAmB,QAAgB,QAAsC;AACvH,QAAM,QAAQ,KAAK,OAAO,QAAQ,WAAW,YAAY,OAAO,KAAK;AACrE,MAAI,UAAU;AAAG,WAAO,EAAE,OAAO,KAAK,EAAE;AACxC,QAAM,cAAc,QAAQ,YAAY,UAAU,QAAQ;AAC1D,MAAI,aAAa;AAAQ,WAAO,EAAE,OAAO,KAAK,OAAO;AACrD,MAAI,WAAW,UAAU,aAAa;AAAQ,WAAO,EAAE,OAAO,KAAK,OAAO;AAC1E,SAAO,EAAE,OAAO,KAAK,WAAW;AACpC;AAQO,SAAS,WAAc,OAA2B;AACrD,MAAI;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO,CAAC;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM;AAAA,IACN;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACP,IAAI;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AA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACP,IAAI;AACJ,QAAM,UAAM,qBAAuB,IAAI;AACvC,QAAM,WAAO,uBAAQ,GAAG;AACxB,QAAM,YAAQ,qBAAO,MAAM,SAAS,CAAC;AACrC,MAAI,QAAQ,KAAK,UAAU;AAAG,UAAM,UAAU,KAAK;AACnD,wCAAoB,SAAS,MAAM,IAAI,SAAU,CAAC,IAAI,OAAO,CAAC;AAC9D,MAAI,MAAM,YAAY;AAAG,WAAO,oCAAC,SAAI,KAAK,KAAM,GAAG,MAAM;AACzD,SAAO,oCAAC,cAAW,SAAS,KAAM,GAAG,OAAO,OAAO,MAAM,SAAS;AACtE;",
4
+ "sourcesContent": ["\"use client\"\n\nimport { css } from \"@emotion/css\"\nimport { useSize } from \"ahooks\"\nimport { clsx } from \"deepsea-tools\"\nimport { CSSProperties, HTMLAttributes, Key, ReactNode, Ref, useEffect, useImperativeHandle, useRef, useState } from \"react\"\n\nimport { px, transformCSSVariable } from \"@/utils\"\n\nexport interface FlowSizeData {\n /** 容器宽度 */\n width: number\n /** 容器高度 */\n height: number\n /** 元素宽度 */\n itemWidth: number\n /** 元素高度 */\n itemHeight: number\n /** 列间距 */\n columnGap: number\n /** 列数 */\n columnCount: number\n /** 行间距 */\n rowGap: number\n /** 行数 */\n rowCount: number\n /** 元素格数 */\n itemCount: number\n /** 最大行数 */\n maxRows: number | null\n /** 是否有元素被隐藏 */\n overflow: boolean\n}\n\nexport interface FlowProps<T> extends Omit<HTMLAttributes<HTMLDivElement>, \"children\"> {\n /** 元素宽度 */\n itemWidth: number\n /** 元素高度 */\n itemHeight: number\n /**\n * 列间距\n * 1. 如果是数字,表示列间距是固定的\n * 2. 如果是 auto,表示会在尽可能放进更多列的情况下,列间距是平均的\n * 2. 如果是数组,表示列间距是区间的,第一个元素是最小值,第二个元素是最大值\n */\n columnGap?: number | \"auto\" | [number | \"auto\", number | \"auto\"]\n /** 行间距 */\n rowGap?: number\n gap?: number\n /** 最大行数 */\n maxRows?: number | null\n /** 源数据 */\n data?: T[]\n /** 渲染 */\n render: (item: T, index: number, arr: T[]) => ReactNode\n /** key释放器,默认为 index */\n keyExactor?: (item: T, index: number, arr: T[]) => Key\n /**\n * 渲染的元素由两层容器包裹,外层容器类名\n */\n wrapperClassName?: string\n /**\n * 渲染的元素由两层容器包裹,外层容器样式\n */\n wrapperStyle?: CSSProperties\n /**\n * 渲染的元素由两层容器包裹,内层容器类名\n */\n containerClassName?: string\n /**\n * 渲染的元素由两层容器包裹,内层容器样式\n */\n containerStyle?: CSSProperties\n /** 节流时间,单位毫秒,默认200ms,传入 0 不节流 */\n throttle?: number\n /** 动画时间,单位毫秒,默认400ms,传入 0 不展示动画 */\n transitionDuration?: number\n /** 变化的回调函数 */\n onSizeChange?: (sizeData: FlowSizeData) => void\n element?: Ref<HTMLDivElement>\n}\n\nexport function getGapRange(gap?: undefined | number | \"auto\" | (number | \"auto\")[]): [number, number | \"auto\"] {\n if (typeof gap === \"number\") return [gap, gap]\n if (Array.isArray(gap)) return [typeof gap[0] === \"number\" ? gap[0] : 0, gap[1]]\n return [0, \"auto\"]\n}\n\nexport interface GapAndCount {\n count: number\n gap: number\n}\n\nexport function getGapCountAndSize(width: number, itemWidth: number, minGap: number, maxGap: number | \"auto\"): GapAndCount {\n const count = Math.floor((width + minGap) / (itemWidth + minGap)) || 1\n if (count === 1) return { count, gap: 0 }\n const averageGap = (width - itemWidth * count) / (count - 1)\n if (averageGap < minGap) return { count, gap: minGap }\n if (maxGap !== \"auto\" && averageGap > maxGap) return { count, gap: maxGap }\n return { count, gap: averageGap }\n}\n\nexport interface ManualFlowProps<T> extends FlowProps<T> {\n /** 组件宽度,必须指定 */\n width: number\n}\n\n/** 手动组件,由外界指定宽度,性能更好 */\nexport function ManualFlow<T>(props: ManualFlowProps<T>) {\n let {\n itemWidth,\n itemHeight,\n columnGap,\n rowGap,\n maxRows,\n data = [],\n render,\n keyExactor,\n className,\n style,\n wrapperClassName,\n wrapperStyle,\n throttle,\n transitionDuration,\n onSizeChange,\n containerClassName,\n containerStyle,\n gap = 0,\n width,\n element,\n ...rest\n } = props\n rowGap ??= gap\n columnGap ??= gap\n const [minColumnGap, maxColumnGap] = getGapRange(columnGap)\n const [{ count: columnCount, gap: columnGapSize }, setGapAndCount] = useState(() => getGapCountAndSize(width, itemWidth, minColumnGap, maxColumnGap))\n const ele = useRef<HTMLDivElement>(null)\n const contentRows = Math.ceil(data.length / columnCount)\n const contentShownRows = typeof maxRows === \"number\" ? Math.min(contentRows, maxRows) : contentRows\n const height = contentShownRows > 0 ? contentShownRows * (itemHeight + rowGap) - rowGap : 0\n\n function getPosition(index: number) {\n const y = Math.floor(index / columnCount)\n const x = index - y * columnCount\n return {\n left: x * (itemWidth + columnGapSize),\n top: y * (itemHeight + rowGap!),\n }\n }\n\n function getHidden(index: number) {\n if (typeof maxRows !== \"number\") return false\n return index >= maxRows * columnCount\n }\n\n useImperativeHandle(element, () => ele.current!, [ele.current])\n\n useEffect(() => {\n function task() {\n setGapAndCount(getGapCountAndSize(width, itemWidth, minColumnGap, maxColumnGap))\n }\n if (throttle === 0) return task()\n const timeout = setTimeout(task, throttle || 200)\n return () => clearTimeout(timeout)\n }, [width, itemWidth, throttle, minColumnGap, maxColumnGap])\n\n useEffect(() => {\n onSizeChange?.({\n width,\n height,\n itemWidth,\n itemHeight,\n columnGap: columnGapSize,\n columnCount,\n rowGap: rowGap!,\n rowCount: contentShownRows,\n overflow: data.length > contentShownRows * columnCount,\n itemCount: data.length,\n maxRows: maxRows ?? null,\n })\n }, [width, height, columnGapSize, columnCount, rowGap, contentShownRows, data.length, itemWidth, itemHeight, maxRows])\n\n return (\n <div\n ref={ele}\n className={clsx(\n css`\n position: relative;\n height: var(--height);\n overflow: hidden;\n `,\n className,\n )}\n style={transformCSSVariable({ height: px(height) }, style)}\n {...rest}\n >\n {data.map((item, index, arr) => (\n <div\n key={keyExactor ? keyExactor(item, index, arr) : index}\n className={clsx(\n css`\n position: absolute;\n width: var(--width);\n height: var(--height);\n transition: var(--transition);\n left: 0;\n top: 0;\n transform: translate(var(--left), var(--top));\n `,\n wrapperClassName,\n )}\n style={transformCSSVariable(\n {\n width: px(itemWidth),\n height: px(itemHeight),\n transition: transitionDuration === 0 ? \"none\" : `all ${transitionDuration || 400}ms`,\n left: px(getPosition(index).left),\n top: px(getPosition(index).top),\n },\n wrapperStyle,\n )}\n >\n <div\n className={clsx(\n css`\n width: 100%;\n height: 100%;\n display: var(--display);\n `,\n containerClassName,\n )}\n style={transformCSSVariable({ display: getHidden(index) ? \"none\" : \"block\" }, containerStyle)}\n >\n {render(item, index, arr)}\n </div>\n </div>\n ))}\n </div>\n )\n}\n\n/** 自适应浮动组件 */\nexport function Flow<T>(props: FlowProps<T>): ReactNode {\n const {\n itemWidth,\n itemHeight,\n columnGap,\n rowGap,\n gap,\n maxRows,\n data,\n render,\n keyExactor,\n wrapperClassName,\n wrapperStyle,\n containerClassName,\n containerStyle,\n throttle,\n transitionDuration,\n onSizeChange,\n element,\n ...rest\n } = props\n const ele = useRef<HTMLDivElement>(null)\n const size = useSize(ele)\n const width = useRef(size?.width || 0)\n if (size && size.width !== 0) width.current = size.width\n useImperativeHandle(element, () => ele.current!, [ele.current])\n if (width.current === 0) return <div ref={ele} {...rest} />\n return <ManualFlow element={ele} {...props} width={width.current} />\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iBAAoB;AACpB,oBAAwB;AACxB,2BAAqB;AACrB,mBAAqH;AAErH,mBAAyC;AA2ElC,SAAS,YAAY,KAAoF;AAC5G,MAAI,OAAO,QAAQ;AAAU,WAAO,CAAC,KAAK,GAAG;AAC7C,MAAI,MAAM,QAAQ,GAAG;AAAG,WAAO,CAAC,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GAAG,MAAM;AACzD,SAAO,oCAAC,cAAW,SAAS,KAAM,GAAG,OAAO,OAAO,MAAM,SAAS;AACtE;",
6
6
  "names": []
7
7
  }
@@ -1,7 +1,7 @@
1
- /// <reference types="react" />
1
+ import { FC } from "react";
2
2
  import { InputFileProps } from "./InputFile";
3
- export interface ImportExcelProps extends Omit<InputFileProps, "multiple" | "onChange" | "accept" | "type"> {
4
- onChange?: (data: Record<string, any>[]) => void;
3
+ export interface ImportExcelProps extends Omit<InputFileProps<false, "arrayBuffer">, "multiple" | "accept" | "type" | "onValueChange"> {
4
+ onValueChange?: (data: Record<string, any>[]) => void;
5
5
  }
6
6
  /** 专门用于读取 excel 的组件 */
7
- export declare const ImportExcel: import("react").ForwardRefExoticComponent<ImportExcelProps & import("react").RefAttributes<HTMLInputElement>>;
7
+ export declare const ImportExcel: FC<ImportExcelProps>;
@@ -23,13 +23,12 @@ __export(ImportExcel_exports, {
23
23
  ImportExcel: () => ImportExcel
24
24
  });
25
25
  module.exports = __toCommonJS(ImportExcel_exports);
26
- var import_react = require("react");
27
26
  var import_deepsea_tools = require("deepsea-tools");
28
27
  var import_InputFile = require("./InputFile");
29
- var ImportExcel = (0, import_react.forwardRef)((props, ref) => {
30
- const { onChange, ...rest } = props;
31
- return /* @__PURE__ */ React.createElement(import_InputFile.InputFile, { ref, accept: ".xlsx", type: "arrayBuffer", onChange: ({ result }) => onChange?.((0, import_deepsea_tools.readExcel)(result)), ...rest });
32
- });
28
+ var ImportExcel = (props) => {
29
+ const { onValueChange, ...rest } = props;
30
+ return /* @__PURE__ */ React.createElement(import_InputFile.InputFile, { accept: ".xlsx", type: "arrayBuffer", onValueChange: (data) => onValueChange?.((0, import_deepsea_tools.readExcel)(data)), ...rest });
31
+ };
33
32
  // Annotate the CommonJS export names for ESM import in node:
34
33
  0 && (module.exports = {
35
34
  ImportExcel
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/ImportExcel.tsx"],
4
- "sourcesContent": ["\"use client\"\n\nimport { forwardRef } from \"react\"\nimport { readExcel } from \"deepsea-tools\"\n\nimport { InputFile, InputFileProps } from \"./InputFile\"\n\nexport interface ImportExcelProps extends Omit<InputFileProps, \"multiple\" | \"onChange\" | \"accept\" | \"type\"> {\n onChange?: (data: Record<string, any>[]) => void\n}\n\n/** 专门用于读取 excel 的组件 */\nexport const ImportExcel = forwardRef<HTMLInputElement, ImportExcelProps>((props, ref) => {\n const { onChange, ...rest } = props\n\n return <InputFile ref={ref} accept=\".xlsx\" type=\"arrayBuffer\" onChange={({ result }) => onChange?.(readExcel(result))} {...rest} />\n})\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA2B;AAC3B,2BAA0B;AAE1B,uBAA0C;AAOnC,IAAM,kBAAc,yBAA+C,CAAC,OAAO,QAAQ;AACtF,QAAM,EAAE,UAAU,GAAG,KAAK,IAAI;AAE9B,SAAO,oCAAC,8BAAU,KAAU,QAAO,SAAQ,MAAK,eAAc,UAAU,CAAC,EAAE,OAAO,MAAM,eAAW,gCAAU,MAAM,CAAC,GAAI,GAAG,MAAM;AACrI,CAAC;",
4
+ "sourcesContent": ["\"use client\"\n\nimport { readExcel } from \"deepsea-tools\"\nimport { FC } from \"react\"\n\nimport { InputFile, InputFileProps } from \"./InputFile\"\n\nexport interface ImportExcelProps extends Omit<InputFileProps<false, \"arrayBuffer\">, \"multiple\" | \"accept\" | \"type\" | \"onValueChange\"> {\n onValueChange?: (data: Record<string, any>[]) => void\n}\n\n/** 专门用于读取 excel 的组件 */\nexport const ImportExcel: FC<ImportExcelProps> = props => {\n const { onValueChange, ...rest } = props\n\n return <InputFile accept=\".xlsx\" type=\"arrayBuffer\" onValueChange={data => onValueChange?.(readExcel(data))} {...rest} />\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,2BAA0B;AAG1B,uBAA0C;AAOnC,IAAM,cAAoC,WAAS;AACtD,QAAM,EAAE,eAAe,GAAG,KAAK,IAAI;AAEnC,SAAO,oCAAC,8BAAU,QAAO,SAAQ,MAAK,eAAc,eAAe,UAAQ,oBAAgB,gCAAU,IAAI,CAAC,GAAI,GAAG,MAAM;AAC3H;",
6
6
  "names": []
7
7
  }
@@ -1,53 +1,26 @@
1
- import { ButtonHTMLAttributes, InputHTMLAttributes } from "react";
2
- export interface InputFileDataTypes {
1
+ import { ComponentProps, ReactNode } from "react";
2
+ export interface InputFileDataTypeMap {
3
3
  base64: string;
4
4
  text: string;
5
5
  arrayBuffer: ArrayBuffer;
6
6
  binary: string;
7
7
  file: File;
8
8
  }
9
- export type InputFileDataType = keyof InputFileDataTypes;
10
- export interface InputFileData<T> {
11
- result: T;
12
- file: File;
9
+ export type InputFileDataType = keyof InputFileDataTypeMap;
10
+ export declare function getFileData<T extends InputFileDataType>(file: File, type: T): Promise<InputFileDataTypeMap[T]>;
11
+ export interface InputFileBaseProps extends Omit<ComponentProps<"input">, "multiple" | "type"> {
13
12
  }
14
- export type InputFileProps = ({
15
- multiple?: false;
16
- type: "base64" | "text" | "binary";
17
- onChange?: (data: InputFileData<string>) => void;
18
- } | {
19
- multiple?: false;
20
- type: "arrayBuffer";
21
- onChange?: (data: InputFileData<ArrayBuffer>) => void;
22
- } | {
23
- multiple?: false;
24
- type?: "file";
25
- onChange?: (data: InputFileData<File>) => void;
26
- } | {
27
- multiple: true;
28
- type: "base64" | "text" | "binary";
29
- onChange?: (data: InputFileData<string>[]) => void;
30
- } | {
31
- multiple: true;
32
- type: "arrayBuffer";
33
- onChange?: (data: InputFileData<ArrayBuffer>[]) => void;
34
- } | {
35
- multiple: true;
36
- type?: "file";
37
- onChange?: (data: InputFileData<File>[]) => void;
38
- }) & Omit<InputHTMLAttributes<HTMLInputElement>, "onChange" | "multiple" | "type"> & {
13
+ export type FileType<Multiple extends boolean> = Multiple extends true ? File[] : File;
14
+ export type ValueType<Multiple extends boolean, Type extends InputFileDataType> = Multiple extends true ? InputFileDataTypeMap[Type][] : InputFileDataTypeMap[Type];
15
+ export interface InputFileExtraProps<Multiple extends boolean = false, Type extends InputFileDataType = "file"> {
16
+ multiple?: Multiple;
17
+ type?: Type;
18
+ onValueChange?: (data: ValueType<Multiple, Type>) => void;
19
+ onFileChange?: (data: FileType<Multiple>) => void;
39
20
  /** 是否在捕获文件后清除 input 上的文件,默认为 false,主要区别在于如果不清除,连续两次选择同样的文件不会触发 onChange 事件,如果用于 form 表单,请设置为 flase */
40
21
  clearAfterChange?: boolean;
41
- };
42
- export declare function getFileData<T extends InputFileDataType>(file: File, type: T): Promise<InputFileDataTypes[T]>;
22
+ }
23
+ export interface InputFileProps<Multiple extends boolean = false, Type extends InputFileDataType = "file"> extends InputFileBaseProps, InputFileExtraProps<Multiple, Type> {
24
+ }
43
25
  /** 专用于读取文件的组件 */
44
- export declare const InputFile: import("react").ForwardRefExoticComponent<InputFileProps & import("react").RefAttributes<HTMLInputElement>>;
45
- export type InputFileButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
46
- input: InputFileProps;
47
- dragFile?: boolean;
48
- };
49
- /** 专用于读取文件的 button 组件 */
50
- export declare const InputFileButton: import("react").ForwardRefExoticComponent<ButtonHTMLAttributes<HTMLButtonElement> & {
51
- input: InputFileProps;
52
- dragFile?: boolean | undefined;
53
- } & import("react").RefAttributes<HTMLButtonElement>>;
26
+ export declare function InputFile<Multiple extends boolean = false, Type extends InputFileDataType = "file">(props: InputFileProps<Multiple, Type>): ReactNode;
@@ -21,7 +21,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  var InputFile_exports = {};
22
22
  __export(InputFile_exports, {
23
23
  InputFile: () => InputFile,
24
- InputFileButton: () => InputFileButton,
25
24
  getFileData: () => getFileData
26
25
  });
27
26
  module.exports = __toCommonJS(InputFile_exports);
@@ -50,10 +49,11 @@ async function getFileData(file, type) {
50
49
  });
51
50
  });
52
51
  }
53
- var InputFile = (0, import_react.forwardRef)((props, ref) => {
54
- const { multiple = false, type = "file", onChange, disabled: inputDisabled, clearAfterChange, ...rest } = props;
52
+ function InputFile(props) {
53
+ const { multiple = false, type = "file", onChange: _onChange, disabled: _disabled, clearAfterChange, onValueChange, onFileChange, ...rest } = props;
55
54
  const [disabled, setDisabled] = (0, import_react.useState)(false);
56
- async function onInputChange(e) {
55
+ async function onChange(e) {
56
+ _onChange?.(e);
57
57
  const input = e.target;
58
58
  const { files } = input;
59
59
  if (!files || files.length === 0)
@@ -61,19 +61,18 @@ var InputFile = (0, import_react.forwardRef)((props, ref) => {
61
61
  setDisabled(true);
62
62
  try {
63
63
  if (multiple) {
64
- const result = [];
65
- for (const file of Array.from(files)) {
66
- result.push({
67
- result: await getFileData(file, type),
68
- file
69
- });
64
+ const files2 = Array.from(files);
65
+ const values = [];
66
+ for (const file of files2) {
67
+ const value = await getFileData(file, type);
68
+ values.push(value);
70
69
  }
71
- onChange?.(result);
70
+ onFileChange?.(files2);
71
+ onValueChange?.(values);
72
72
  } else {
73
- onChange?.({
74
- result: await getFileData(files[0], type),
75
- file: files[0]
76
- });
73
+ const file = files[0];
74
+ onFileChange?.(file);
75
+ onValueChange?.(await getFileData(file, type));
77
76
  }
78
77
  } finally {
79
78
  if (clearAfterChange)
@@ -81,69 +80,11 @@ var InputFile = (0, import_react.forwardRef)((props, ref) => {
81
80
  setDisabled(false);
82
81
  }
83
82
  }
84
- return /* @__PURE__ */ React.createElement("input", { ref, disabled: disabled || inputDisabled, type: "file", multiple, onChange: onInputChange, ...rest });
85
- });
86
- var InputFileButton = (0, import_react.forwardRef)((props, ref) => {
87
- const { onClick: _onClick, input: inputProps, onDrop: _onDrop, onDragOver: _onDragOver, dragFile, disabled: _disabled, ...rest } = props;
88
- const { style, disabled: __disabled, multiple, onChange, type = "file", ...restInputProps } = inputProps;
89
- const [disabled, setDisabled] = (0, import_react.useState)(false);
90
- const input = (0, import_react.useRef)(null);
91
- function onClick(e) {
92
- input.current?.click();
93
- _onClick?.(e);
94
- }
95
- async function onDrop(e) {
96
- _onDrop?.(e);
97
- if (disabled || !dragFile)
98
- return;
99
- e.preventDefault();
100
- const { files } = e.dataTransfer;
101
- if (!files || files.length === 0)
102
- return;
103
- setDisabled(true);
104
- try {
105
- if (multiple) {
106
- const result = [];
107
- for (const file of Array.from(files)) {
108
- result.push({
109
- result: await getFileData(file, type),
110
- file
111
- });
112
- }
113
- onChange?.(result);
114
- } else {
115
- onChange?.({
116
- result: await getFileData(files[0], type),
117
- file: files[0]
118
- });
119
- }
120
- } finally {
121
- setDisabled(false);
122
- }
123
- }
124
- function onDragOver(e) {
125
- _onDragOver?.(e);
126
- if (disabled || !dragFile)
127
- return;
128
- e.preventDefault();
129
- }
130
- return /* @__PURE__ */ React.createElement(import_react.Fragment, null, /* @__PURE__ */ React.createElement(
131
- InputFile,
132
- {
133
- ref: input,
134
- disabled: disabled || _disabled || __disabled,
135
- style: { display: "none", ...style },
136
- multiple,
137
- onChange,
138
- type,
139
- ...restInputProps
140
- }
141
- ), /* @__PURE__ */ React.createElement("button", { ref, type: "button", disabled: disabled || _disabled, onClick, onDrop, onDragOver, ...rest }));
142
- });
83
+ return /* @__PURE__ */ React.createElement("input", { disabled: disabled || _disabled, type: "file", multiple, onChange, ...rest });
84
+ }
143
85
  // Annotate the CommonJS export names for ESM import in node:
144
86
  0 && (module.exports = {
145
87
  InputFile,
146
- InputFileButton,
147
88
  getFileData
148
89
  });
149
90
  //# sourceMappingURL=InputFile.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/InputFile.tsx"],
4
- "sourcesContent": ["\"use client\"\n\nimport { ButtonHTMLAttributes, ChangeEvent, DragEvent, Fragment, InputHTMLAttributes, MouseEvent as ReactMouseEvent, forwardRef, useRef, useState } from \"react\"\n\nexport interface InputFileDataTypes {\n base64: string\n text: string\n arrayBuffer: ArrayBuffer\n binary: string\n file: File\n}\n\nexport type InputFileDataType = keyof InputFileDataTypes\n\nexport interface InputFileData<T> {\n result: T\n file: File\n}\n\nexport type InputFileProps = (\n | {\n multiple?: false\n type: \"base64\" | \"text\" | \"binary\"\n onChange?: (data: InputFileData<string>) => void\n }\n | {\n multiple?: false\n type: \"arrayBuffer\"\n onChange?: (data: InputFileData<ArrayBuffer>) => void\n }\n | {\n multiple?: false\n type?: \"file\"\n onChange?: (data: InputFileData<File>) => void\n }\n | {\n multiple: true\n type: \"base64\" | \"text\" | \"binary\"\n onChange?: (data: InputFileData<string>[]) => void\n }\n | {\n multiple: true\n type: \"arrayBuffer\"\n onChange?: (data: InputFileData<ArrayBuffer>[]) => void\n }\n | {\n multiple: true\n type?: \"file\"\n onChange?: (data: InputFileData<File>[]) => void\n }\n) &\n Omit<InputHTMLAttributes<HTMLInputElement>, \"onChange\" | \"multiple\" | \"type\"> & {\n /** 是否在捕获文件后清除 input 上的文件,默认为 false,主要区别在于如果不清除,连续两次选择同样的文件不会触发 onChange 事件,如果用于 form 表单,请设置为 flase */\n clearAfterChange?: boolean\n }\n\nexport async function getFileData<T extends InputFileDataType>(file: File, type: T): Promise<InputFileDataTypes[T]> {\n const fileReader = new FileReader()\n switch (type) {\n case \"arrayBuffer\":\n fileReader.readAsArrayBuffer(file)\n break\n case \"binary\":\n fileReader.readAsBinaryString(file)\n break\n case \"base64\":\n fileReader.readAsDataURL(file)\n break\n case \"text\":\n fileReader.readAsText(file)\n break\n default:\n return file as any\n }\n return new Promise(resolve => {\n fileReader.addEventListener(\"load\", () => {\n resolve(fileReader.result as any)\n })\n })\n}\n\n/** 专用于读取文件的组件 */\nexport const InputFile = forwardRef<HTMLInputElement, InputFileProps>((props, ref) => {\n const { multiple = false, type = \"file\", onChange, disabled: inputDisabled, clearAfterChange, ...rest } = props\n const [disabled, setDisabled] = useState(false)\n\n async function onInputChange(e: ChangeEvent<HTMLInputElement>) {\n const input = e.target\n const { files } = input\n if (!files || files.length === 0) return\n setDisabled(true)\n try {\n if (multiple) {\n const result: any[] = []\n for (const file of Array.from(files)) {\n result.push({\n result: await getFileData(file, type),\n file,\n })\n }\n onChange?.(result as any)\n } else {\n onChange?.({\n result: await getFileData(files[0], type),\n file: files[0],\n } as any)\n }\n } finally {\n if (clearAfterChange) input.value = \"\"\n setDisabled(false)\n }\n }\n\n return <input ref={ref} disabled={disabled || inputDisabled} type=\"file\" multiple={multiple} onChange={onInputChange} {...rest} />\n})\n\nexport type InputFileButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {\n input: InputFileProps\n dragFile?: boolean\n}\n\n/** 专用于读取文件的 button 组件 */\nexport const InputFileButton = forwardRef<HTMLButtonElement, InputFileButtonProps>((props, ref) => {\n const { onClick: _onClick, input: inputProps, onDrop: _onDrop, onDragOver: _onDragOver, dragFile, disabled: _disabled, ...rest } = props\n const { style, disabled: __disabled, multiple, onChange, type = \"file\", ...restInputProps } = inputProps\n const [disabled, setDisabled] = useState(false)\n const input = useRef<HTMLInputElement>(null)\n\n function onClick(e: ReactMouseEvent<HTMLButtonElement, MouseEvent>) {\n input.current?.click()\n _onClick?.(e)\n }\n\n async function onDrop(e: DragEvent<HTMLButtonElement>) {\n _onDrop?.(e)\n if (disabled || !dragFile) return\n e.preventDefault()\n const { files } = e.dataTransfer\n if (!files || files.length === 0) return\n setDisabled(true)\n try {\n if (multiple) {\n const result: any[] = []\n for (const file of Array.from(files)) {\n result.push({\n result: await getFileData(file, type),\n file,\n })\n }\n onChange?.(result as any)\n } else {\n onChange?.({\n result: await getFileData(files[0], type),\n file: files[0],\n } as any)\n }\n } finally {\n setDisabled(false)\n }\n }\n\n function onDragOver(e: DragEvent<HTMLButtonElement>) {\n _onDragOver?.(e)\n if (disabled || !dragFile) return\n e.preventDefault()\n }\n\n return (\n <Fragment>\n <InputFile\n ref={input}\n disabled={disabled || _disabled || __disabled}\n style={{ display: \"none\", ...style }}\n multiple={multiple as any}\n onChange={onChange as any}\n type={type as any}\n {...restInputProps}\n />\n <button ref={ref} type=\"button\"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,MACZ;AAAA,IACJ,UAAE;AACE,kBAAY,KAAK;AAAA,IACrB;AAAA,EACJ;AAEA,WAAS,WAAW,GAAiC;AACjD,kBAAc,CAAC;AACf,QAAI,YAAY,CAAC;AAAU;AAC3B,MAAE,eAAe;AAAA,EACrB;AAEA,SACI,oCAAC,6BACG;AAAA,IAAC;AAAA;AAAA,MACG,KAAK;AAAA,MACL,UAAU,YAAY,aAAa;AAAA,MACnC,OAAO,EAAE,SAAS,QAAQ,GAAG,MAAM;AAAA,MACnC;AAAA,MACA;AAAA,MACA;AAAA,MACC,GAAG;AAAA;AAAA,EACR,GACA,oCAAC,YAAO,KAAU,MAAK,UAAS,UAAU,YAAY,WAAW,SAAkB,QAAgB,YAAyB,GAAG,MAAM,CACzI;AAER,CAAC;",
4
+ "sourcesContent": ["\"use client\"\n\nimport { ChangeEvent, ComponentProps, ReactNode, useState } from \"react\"\n\nexport interface InputFileDataTypeMap {\n base64: string\n text: string\n arrayBuffer: ArrayBuffer\n binary: string\n file: File\n}\n\nexport type InputFileDataType = keyof InputFileDataTypeMap\n\nexport async function getFileData<T extends InputFileDataType>(file: File, type: T): Promise<InputFileDataTypeMap[T]> {\n const fileReader = new FileReader()\n switch (type) {\n case \"arrayBuffer\":\n fileReader.readAsArrayBuffer(file)\n break\n case \"binary\":\n fileReader.readAsBinaryString(file)\n break\n case \"base64\":\n fileReader.readAsDataURL(file)\n break\n case \"text\":\n fileReader.readAsText(file)\n break\n default:\n return file as any\n }\n return new Promise(resolve => {\n fileReader.addEventListener(\"load\", () => {\n resolve(fileReader.result as any)\n })\n })\n}\n\nexport interface InputFileBaseProps extends Omit<ComponentProps<\"input\">, \"multiple\" | \"type\"> {}\n\nexport type FileType<Multiple extends boolean> = Multiple extends true ? File[] : File\nexport type ValueType<Multiple extends boolean, Type extends InputFileDataType> = Multiple extends true\n ? InputFileDataTypeMap[Type][]\n : InputFileDataTypeMap[Type]\n\nexport interface InputFileExtraProps<Multiple extends boolean = false, Type extends InputFileDataType = \"file\"> {\n multiple?: Multiple\n type?: Type\n onValueChange?: (data: ValueType<Multiple, Type>) => void\n onFileChange?: (data: FileType<Multiple>) => void\n /** 是否在捕获文件后清除 input 上的文件,默认为 false,主要区别在于如果不清除,连续两次选择同样的文件不会触发 onChange 事件,如果用于 form 表单,请设置为 flase */\n clearAfterChange?: boolean\n}\n\nexport interface InputFileProps<Multiple extends boolean = false, Type extends InputFileDataType = \"file\">\n extends InputFileBaseProps,\n InputFileExtraProps<Multiple, Type> {}\n\n/** 专用于读取文件的组件 */\nexport function InputFile<Multiple extends boolean = false, Type extends InputFileDataType = \"file\">(props: InputFileProps<Multiple, Type>): ReactNode {\n const { multiple = false, type = \"file\", onChange: _onChange, disabled: _disabled, clearAfterChange, onValueChange, onFileChange, ...rest } = props\n const [disabled, setDisabled] = useState(false)\n\n async function onChange(e: ChangeEvent<HTMLInputElement>) {\n _onChange?.(e)\n const input = e.target\n const { files } = input\n if (!files || files.length === 0) return\n setDisabled(true)\n try {\n if (multiple) {\n const files2: File[] = Array.from(files)\n const values: InputFileDataTypeMap[Type][] = []\n for (const file of files2) {\n const value = (await getFileData(file, type)) as InputFileDataTypeMap[Type]\n values.push(value)\n }\n onFileChange?.(files2 as FileType<Multiple>)\n onValueChange?.(values as ValueType<Multiple, Type>)\n } else {\n const file = files[0]\n onFileChange?.(file as FileType<Multiple>)\n onValueChange?.((await getFileData(file, type)) as ValueType<Multiple, Type>)\n }\n } finally {\n if (clearAfterChange) input.value = \"\"\n setDisabled(false)\n }\n }\n\n return <input disabled={disabled || _disabled} type=\"file\" multiple={multiple} onChange={onChange} {...rest} />\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAiE;AAYjE,eAAsB,YAAyC,MAAY,MAA2C;AAClH,QAAM,aAAa,IAAI,WAAW;AAClC,UAAQ,MAAM;AAAA,IACV,KAAK;AACD,iBAAW,kBAAkB,IAAI;AACjC;AA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 -0,0 +1,10 @@
1
+ import { ComponentProps, JSX } from "react";
2
+ import { InputFileBaseProps, InputFileDataType, InputFileExtraProps } from "./InputFile";
3
+ export type InputFileButtonProps<Multiple extends boolean = false, Type extends InputFileDataType = "file", AS extends keyof JSX.IntrinsicElements = "button"> = Omit<ComponentProps<AS>, "type" | "disabled"> & InputFileExtraProps<Multiple, Type> & {
4
+ disabled?: boolean;
5
+ inputProps?: InputFileBaseProps;
6
+ dragFile?: boolean;
7
+ as?: AS;
8
+ };
9
+ /** 专用于读取文件的 button 组件 */
10
+ export declare function InputFileButton<Multiple extends boolean = false, Type extends InputFileDataType = "file", AS extends keyof JSX.IntrinsicElements = "button">(props: InputFileButtonProps<Multiple, Type, AS>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,109 @@
1
+ "use client";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/components/InputFileButton.tsx
21
+ var InputFileButton_exports = {};
22
+ __export(InputFileButton_exports, {
23
+ InputFileButton: () => InputFileButton
24
+ });
25
+ module.exports = __toCommonJS(InputFileButton_exports);
26
+ var import_react = require("react");
27
+ var import_InputFile = require("./InputFile");
28
+ function InputFileButton(props) {
29
+ const {
30
+ as = "button",
31
+ onClick: _onClick,
32
+ inputProps = {},
33
+ onDrop: _onDrop,
34
+ onDragOver: _onDragOver,
35
+ dragFile,
36
+ disabled: _disabled,
37
+ type = "file",
38
+ multiple,
39
+ onValueChange,
40
+ onFileChange,
41
+ clearAfterChange,
42
+ ...rest
43
+ } = props;
44
+ const { style, disabled: __disabled, ...restInputProps } = inputProps;
45
+ const [disabled, setDisabled] = (0, import_react.useState)(false);
46
+ const input = (0, import_react.useRef)(null);
47
+ function onClick(e) {
48
+ input.current?.click();
49
+ _onClick?.(e);
50
+ }
51
+ async function onDrop(e) {
52
+ _onDrop?.(e);
53
+ if (disabled || !dragFile)
54
+ return;
55
+ e.preventDefault();
56
+ const { files } = e.dataTransfer;
57
+ if (!files || files.length === 0)
58
+ return;
59
+ setDisabled(true);
60
+ try {
61
+ if (multiple) {
62
+ const files2 = Array.from(files);
63
+ const values = [];
64
+ for (const file of files2) {
65
+ const value = await (0, import_InputFile.getFileData)(file, type);
66
+ values.push(value);
67
+ }
68
+ onFileChange?.(files2);
69
+ onValueChange?.(values);
70
+ } else {
71
+ const file = files[0];
72
+ onFileChange?.(file);
73
+ onValueChange?.(await (0, import_InputFile.getFileData)(file, type));
74
+ }
75
+ } finally {
76
+ setDisabled(false);
77
+ }
78
+ }
79
+ function onDragOver(e) {
80
+ _onDragOver?.(e);
81
+ if (disabled || !dragFile)
82
+ return;
83
+ e.preventDefault();
84
+ }
85
+ return /* @__PURE__ */ React.createElement(import_react.Fragment, null, /* @__PURE__ */ React.createElement(
86
+ import_InputFile.InputFile,
87
+ {
88
+ disabled: disabled || _disabled || __disabled,
89
+ style: { display: "none", ...style },
90
+ multiple,
91
+ type,
92
+ onValueChange,
93
+ onFileChange,
94
+ clearAfterChange,
95
+ ...restInputProps
96
+ }
97
+ ), (0, import_react.createElement)(as, {
98
+ disabled: disabled || _disabled,
99
+ onClick,
100
+ onDrop,
101
+ onDragOver,
102
+ ...rest
103
+ }));
104
+ }
105
+ // Annotate the CommonJS export names for ESM import in node:
106
+ 0 && (module.exports = {
107
+ InputFileButton
108
+ });
109
+ //# sourceMappingURL=InputFileButton.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/components/InputFileButton.tsx"],
4
+ "sourcesContent": ["\"use client\"\r\n\r\nimport { ComponentProps, ComponentRef, createElement, DragEvent, Fragment, JSX, MouseEvent as ReactMouseEvent, useRef, useState } from \"react\"\r\nimport { FileType, getFileData, InputFile, InputFileBaseProps, InputFileDataType, InputFileDataTypeMap, InputFileExtraProps, ValueType } from \"./InputFile\"\r\n\r\nexport type InputFileButtonProps<\r\n Multiple extends boolean = false,\r\n Type extends InputFileDataType = \"file\",\r\n AS extends keyof JSX.IntrinsicElements = \"button\",\r\n> = Omit<ComponentProps<AS>, \"type\" | \"disabled\"> &\r\n InputFileExtraProps<Multiple, Type> & {\r\n disabled?: boolean\r\n inputProps?: InputFileBaseProps\r\n dragFile?: boolean\r\n as?: AS\r\n }\r\n\r\n/** 专用于读取文件的 button 组件 */\r\nexport function InputFileButton<Multiple extends boolean = false, Type extends InputFileDataType = \"file\", AS extends keyof JSX.IntrinsicElements = \"button\">(\r\n props: InputFileButtonProps<Multiple, Type, AS>,\r\n) {\r\n const {\r\n as = \"button\",\r\n onClick: _onClick,\r\n inputProps = {},\r\n onDrop: _onDrop,\r\n onDragOver: _onDragOver,\r\n dragFile,\r\n disabled: _disabled,\r\n type = \"file\",\r\n multiple,\r\n onValueChange,\r\n onFileChange,\r\n clearAfterChange,\r\n ...rest\r\n } = props\r\n\r\n const { style, disabled: __disabled, ...restInputProps } = inputProps\r\n const [disabled, setDisabled] = useState(false)\r\n const input = useRef<HTMLInputElement>(null)\r\n\r\n function onClick(e: ReactMouseEvent<ComponentRef<AS>, MouseEvent>) {\r\n input.current?.click()\r\n _onClick?.(e as any)\r\n }\r\n\r\n async function onDrop(e: DragEvent<ComponentRef<AS>>) {\r\n _onDrop?.(e as any)\r\n if (disabled || !dragFile) return\r\n e.preventDefault()\r\n const { files } = e.dataTransfer\r\n if (!files || files.length === 0) return\r\n setDisabled(true)\r\n try {\r\n if (multiple) {\r\n const files2: File[] = Array.from(files)\r\n const values: InputFileDataTypeMap[Type][] = []\r\n for (const file of files2) {\r\n const value = (await getFileData(file, type)) as InputFileDataTypeMap[Type]\r\n values.push(value)\r\n }\r\n onFileChange?.(files2 as FileType<Multiple>)\r\n onValueChange?.(values as ValueType<Multiple, Type>)\r\n } else {\r\n const file = files[0]\r\n onFileChange?.(file as FileType<Multiple>)\r\n onValueChange?.((await getFileData(file, type)) as ValueType<Multiple, Type>)\r\n }\r\n } finally {\r\n setDisabled(false)\r\n }\r\n }\r\n\r\n function onDragOver(e: DragEvent<ComponentRef<AS>>) {\r\n _onDragOver?.(e as any)\r\n if (disabled || !dragFile) return\r\n e.preventDefault()\r\n }\r\n\r\n return (\r\n <Fragment>\r\n <InputFile<Multiple, Type>\r\n disabled={disabled || _disabled || __disabled}\r\n style={{ display: \"none\", ...style }}\r\n multiple={multiple}\r\n type={type as Type}\r\n onValueChange={onValueChange}\r\n onFileChange={onFileChange}\r\n clearAfterChange={clearAfterChange}\r\n {...restInputProps}\r\n />\r\n {createElement(as, {\r\n disabled: disabled || _disabled,\r\n onClick,\r\n onDrop,\r\n onDragOver,\r\n ...rest,\r\n })}\r\n </Fragment>\r\n )\r\n}\r\n\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAuI;AACvI,uBAA8I;AAevI,SAAS,gBACZ,OACF;AACE,QAAM;AAAA,IACF,KAAK;AAAA,IACL,SAAS;AAAA,IACT,aAAa,CAAC;AAAA,IACd,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ;AAAA,IACA,UAAU;AAAA,IACV,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACP,IAAI;AAEJ,QAAM,EAAE,OAAO,UAAU,YAAY,GAAG,eAAe,IAAI;AAC3D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[]
7
+ }
@@ -1,4 +1,4 @@
1
- import { CSSProperties, ComponentProps, FC, ReactNode } from "react";
1
+ import { CSSProperties, ComponentProps, FC, ReactNode, JSX } from "react";
2
2
  export interface UnifyConfig {
3
3
  className?: string;
4
4
  style?: CSSProperties;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/components/Unify.tsx"],
4
- "sourcesContent": ["\"use client\"\r\n\r\nimport { CSSProperties, ComponentProps, FC, ReactNode, createContext, createElement, useContext } from \"react\"\r\nimport { clsx } from \"deepsea-tools\"\r\n\r\nexport interface UnifyConfig {\r\n className?: string\r\n style?: CSSProperties\r\n}\r\n\r\nconst UnifyConfigContext = createContext<UnifyConfig>({})\r\n\r\nexport interface UnifyConfigProviderProps extends UnifyConfig {\r\n children?: ReactNode\r\n}\r\n\r\nexport const UnifyConfigProvider: FC<UnifyConfigProviderProps> = ({ className, style, children }) => {\r\n const { className: _className, style: _style } = useContext(UnifyConfigContext)\r\n\r\n return (\r\n <UnifyConfigContext.Provider value={{ className: clsx(_className, className), style: { ..._style, ...style } }}>{children}</UnifyConfigContext.Provider>\r\n )\r\n}\r\n\r\nexport type UnifyProps<T extends keyof JSX.IntrinsicElements = \"div\"> = ComponentProps<T> & {\r\n as?: T\r\n}\r\n\r\nexport function Unify<T extends keyof JSX.IntrinsicElements = \"div\">(props: UnifyProps<T>) {\r\n const { as, className, style, ...rest } = props\r\n const { className: _className, style: _style } = useContext(UnifyConfigContext)\r\n\r\n return createElement(as ?? \"div\", {\r\n className: clsx(_className, className),\r\n style: { ..._style, ...style },\r\n ...rest,\r\n }) as ReactNode\r\n}\r\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAuG;AACvG,2BAAqB;AAOrB,IAAM,yBAAqB,4BAA2B,CAAC,CAAC;AAMjD,IAAM,sBAAoD,CAAC,EAAE,WAAW,OAAO,SAAS,MAAM;AACjG,QAAM,EAAE,WAAW,YAAY,OAAO,OAAO,QAAI,yBAAW,kBAAkB;AAE9E,SACI,oCAAC,mBAAmB,UAAnB,EAA4B,OAAO,EAAE,eAAW,2BAAK,YAAY,SAAS,GAAG,OAAO,EAAE,GAAG,QAAQ,GAAG,MAAM,EAAE,KAAI,QAAS;AAElI;AAMO,SAAS,MAAqD,OAAsB;AACvF,QAAM,EAAE,IAAI,WAAW,OAAO,GAAG,KAAK,IAAI;AAC1C,QAAM,EAAE,WAAW,YAAY,OAAO,OAAO,QAAI,yBAAW,kBAAkB;AAE9E,aAAO,4BAAc,MAAM,OAAO;AAAA,IAC9B,eAAW,2BAAK,YAAY,SAAS;AAAA,IACrC,OAAO,EAAE,GAAG,QAAQ,GAAG,MAAM;AAAA,IAC7B,GAAG;AAAA,EACP,CAAC;AACL;",
4
+ "sourcesContent": ["\"use client\"\r\n\r\nimport { CSSProperties, ComponentProps, FC, ReactNode, createContext, createElement, useContext, JSX } from \"react\"\r\nimport { clsx } from \"deepsea-tools\"\r\n\r\nexport interface UnifyConfig {\r\n className?: string\r\n style?: CSSProperties\r\n}\r\n\r\nconst UnifyConfigContext = createContext<UnifyConfig>({})\r\n\r\nexport interface UnifyConfigProviderProps extends UnifyConfig {\r\n children?: ReactNode\r\n}\r\n\r\nexport const UnifyConfigProvider: FC<UnifyConfigProviderProps> = ({ className, style, children }) => {\r\n const { className: _className, style: _style } = useContext(UnifyConfigContext)\r\n\r\n return (\r\n <UnifyConfigContext.Provider value={{ className: clsx(_className, className), style: { ..._style, ...style } }}>{children}</UnifyConfigContext.Provider>\r\n )\r\n}\r\n\r\nexport type UnifyProps<T extends keyof JSX.IntrinsicElements = \"div\"> = ComponentProps<T> & {\r\n as?: T\r\n}\r\n\r\nexport function Unify<T extends keyof JSX.IntrinsicElements = \"div\">(props: UnifyProps<T>) {\r\n const { as, className, style, ...rest } = props\r\n const { className: _className, style: _style } = useContext(UnifyConfigContext)\r\n\r\n return createElement(as ?? \"div\", {\r\n className: clsx(_className, className),\r\n style: { ..._style, ...style },\r\n ...rest,\r\n }) as ReactNode\r\n}\r\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAA4G;AAC5G,2BAAqB;AAOrB,IAAM,yBAAqB,4BAA2B,CAAC,CAAC;AAMjD,IAAM,sBAAoD,CAAC,EAAE,WAAW,OAAO,SAAS,MAAM;AACjG,QAAM,EAAE,WAAW,YAAY,OAAO,OAAO,QAAI,yBAAW,kBAAkB;AAE9E,SACI,oCAAC,mBAAmB,UAAnB,EAA4B,OAAO,EAAE,eAAW,2BAAK,YAAY,SAAS,GAAG,OAAO,EAAE,GAAG,QAAQ,GAAG,MAAM,EAAE,KAAI,QAAS;AAElI;AAMO,SAAS,MAAqD,OAAsB;AACvF,QAAM,EAAE,IAAI,WAAW,OAAO,GAAG,KAAK,IAAI;AAC1C,QAAM,EAAE,WAAW,YAAY,OAAO,OAAO,QAAI,yBAAW,kBAAkB;AAE9E,aAAO,4BAAc,MAAM,OAAO;AAAA,IAC9B,eAAW,2BAAK,YAAY,SAAS;AAAA,IACrC,OAAO,EAAE,GAAG,QAAQ,GAAG,MAAM;AAAA,IAC7B,GAAG;AAAA,EACP,CAAC;AACL;",
6
6
  "names": []
7
7
  }
@@ -11,6 +11,7 @@ export * from "./components/HlsPlayer";
11
11
  export * from "./components/ImportExcel";
12
12
  export * from "./components/InfiniteScroll";
13
13
  export * from "./components/InputFile";
14
+ export * from "./components/InputFileButton";
14
15
  export * from "./components/LoopSwiper";
15
16
  export * from "./components/Ring";
16
17
  export * from "./components/Scroll";
package/dist/cjs/index.js CHANGED
@@ -29,6 +29,7 @@ __reExport(src_exports, require("./components/HlsPlayer"), module.exports);
29
29
  __reExport(src_exports, require("./components/ImportExcel"), module.exports);
30
30
  __reExport(src_exports, require("./components/InfiniteScroll"), module.exports);
31
31
  __reExport(src_exports, require("./components/InputFile"), module.exports);
32
+ __reExport(src_exports, require("./components/InputFileButton"), module.exports);
32
33
  __reExport(src_exports, require("./components/LoopSwiper"), module.exports);
33
34
  __reExport(src_exports, require("./components/Ring"), module.exports);
34
35
  __reExport(src_exports, require("./components/Scroll"), module.exports);
@@ -56,6 +57,7 @@ __reExport(src_exports, require("./utils/index"), module.exports);
56
57
  ...require("./components/ImportExcel"),
57
58
  ...require("./components/InfiniteScroll"),
58
59
  ...require("./components/InputFile"),
60
+ ...require("./components/InputFileButton"),
59
61
  ...require("./components/LoopSwiper"),
60
62
  ...require("./components/Ring"),
61
63
  ...require("./components/Scroll"),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/index.ts"],
4
- "sourcesContent": ["export * from \"@/components/AutoFit\"\nexport * from \"@/components/AutoScroll\"\nexport * from \"@/components/AutoSizeTextarea\"\nexport * from \"@/components/CircleText\"\nexport * from \"@/components/CopyButton\"\nexport * from \"@/components/Echart\"\nexport * from \"@/components/ExportExcel\"\nexport * from \"@/components/Flow\"\nexport * from \"@/components/FormLabel\"\nexport * from \"@/components/HlsPlayer\"\nexport * from \"@/components/ImportExcel\"\nexport * from \"@/components/InfiniteScroll\"\nexport * from \"@/components/InputFile\"\nexport * from \"@/components/LoopSwiper\"\nexport * from \"@/components/Ring\"\nexport * from \"@/components/Scroll\"\nexport * from \"@/components/SectionRing\"\nexport * from \"@/components/Skeleton\"\nexport * from \"@/components/Title\"\nexport * from \"@/components/TransitionBox\"\nexport * from \"@/components/TransitionNum\"\nexport * from \"@/components/Trapezium\"\nexport * from \"@/components/Unify\"\nexport * from \"@/utils/getReactVersion\"\nexport * from \"@/utils/index\"\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,iCAAd;AACA,wBAAc,oCADd;AAEA,wBAAc,0CAFd;AAGA,wBAAc,oCAHd;AAIA,wBAAc,oCAJd;AAKA,wBAAc,gCALd;AAMA,wBAAc,qCANd;AAOA,wBAAc,8BAPd;AAQA,wBAAc,mCARd;AASA,wBAAc,mCATd;AAUA,wBAAc,qCAVd;AAWA,wBAAc,wCAXd;AAYA,wBAAc,mCAZd;AAaA,wBAAc,oCAbd;AAcA,wBAAc,8BAdd;AAeA,wBAAc,gCAfd;AAgBA,wBAAc,qCAhBd;AAiBA,wBAAc,kCAjBd;AAkBA,wBAAc,+BAlBd;AAmBA,wBAAc,uCAnBd;AAoBA,wBAAc,uCApBd;AAqBA,wBAAc,mCArBd;AAsBA,wBAAc,+BAtBd;AAuBA,wBAAc,oCAvBd;AAwBA,wBAAc,0BAxBd;",
4
+ "sourcesContent": ["export * from \"@/components/AutoFit\"\nexport * from \"@/components/AutoScroll\"\nexport * from \"@/components/AutoSizeTextarea\"\nexport * from \"@/components/CircleText\"\nexport * from \"@/components/CopyButton\"\nexport * from \"@/components/Echart\"\nexport * from \"@/components/ExportExcel\"\nexport * from \"@/components/Flow\"\nexport * from \"@/components/FormLabel\"\nexport * from \"@/components/HlsPlayer\"\nexport * from \"@/components/ImportExcel\"\nexport * from \"@/components/InfiniteScroll\"\nexport * from \"@/components/InputFile\"\nexport * from \"@/components/InputFileButton\"\nexport * from \"@/components/LoopSwiper\"\nexport * from \"@/components/Ring\"\nexport * from \"@/components/Scroll\"\nexport * from \"@/components/SectionRing\"\nexport * from \"@/components/Skeleton\"\nexport * from \"@/components/Title\"\nexport * from \"@/components/TransitionBox\"\nexport * from \"@/components/TransitionNum\"\nexport * from \"@/components/Trapezium\"\nexport * from \"@/components/Unify\"\nexport * from \"@/utils/getReactVersion\"\nexport * from \"@/utils/index\"\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAc,iCAAd;AACA,wBAAc,oCADd;AAEA,wBAAc,0CAFd;AAGA,wBAAc,oCAHd;AAIA,wBAAc,oCAJd;AAKA,wBAAc,gCALd;AAMA,wBAAc,qCANd;AAOA,wBAAc,8BAPd;AAQA,wBAAc,mCARd;AASA,wBAAc,mCATd;AAUA,wBAAc,qCAVd;AAWA,wBAAc,wCAXd;AAYA,wBAAc,mCAZd;AAaA,wBAAc,yCAbd;AAcA,wBAAc,oCAdd;AAeA,wBAAc,8BAfd;AAgBA,wBAAc,gCAhBd;AAiBA,wBAAc,qCAjBd;AAkBA,wBAAc,kCAlBd;AAmBA,wBAAc,+BAnBd;AAoBA,wBAAc,uCApBd;AAqBA,wBAAc,uCArBd;AAsBA,wBAAc,mCAtBd;AAuBA,wBAAc,+BAvBd;AAwBA,wBAAc,oCAxBd;AAyBA,wBAAc,0BAzBd;",
6
6
  "names": []
7
7
  }
@@ -1,4 +1,4 @@
1
- import { CSSProperties, HTMLAttributes, Key, ReactNode, RefObject } from "react";
1
+ import { CSSProperties, HTMLAttributes, Key, ReactNode, Ref } from "react";
2
2
  export interface FlowSizeData {
3
3
  /** 容器宽度 */
4
4
  width: number;
@@ -68,7 +68,7 @@ export interface FlowProps<T> extends Omit<HTMLAttributes<HTMLDivElement>, "chil
68
68
  transitionDuration?: number;
69
69
  /** 变化的回调函数 */
70
70
  onSizeChange?: (sizeData: FlowSizeData) => void;
71
- element?: RefObject<HTMLDivElement>;
71
+ element?: Ref<HTMLDivElement>;
72
72
  }
73
73
  export declare function getGapRange(gap?: undefined | number | "auto" | (number | "auto")[]): [number, number | "auto"];
74
74
  export interface GapAndCount {