deepsea-components 5.9.7 → 5.10.1

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,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,11 @@
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?: Omit<InputFileBaseProps, "accept">;
6
+ accept?: string;
7
+ dragFile?: boolean;
8
+ as?: AS;
9
+ };
10
+ /** 专用于读取文件的 button 组件 */
11
+ 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,111 @@
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
+ accept,
34
+ onDrop: _onDrop,
35
+ onDragOver: _onDragOver,
36
+ dragFile,
37
+ disabled: _disabled,
38
+ type = "file",
39
+ multiple,
40
+ onValueChange,
41
+ onFileChange,
42
+ clearAfterChange,
43
+ ...rest
44
+ } = props;
45
+ const { style, disabled: __disabled, ...restInputProps } = inputProps;
46
+ const [disabled, setDisabled] = (0, import_react.useState)(false);
47
+ const input = (0, import_react.useRef)(null);
48
+ function onClick(e) {
49
+ input.current?.click();
50
+ _onClick?.(e);
51
+ }
52
+ async function onDrop(e) {
53
+ _onDrop?.(e);
54
+ if (disabled || !dragFile)
55
+ return;
56
+ e.preventDefault();
57
+ const { files } = e.dataTransfer;
58
+ if (!files || files.length === 0)
59
+ return;
60
+ setDisabled(true);
61
+ try {
62
+ if (multiple) {
63
+ const files2 = Array.from(files);
64
+ const values = [];
65
+ for (const file of files2) {
66
+ const value = await (0, import_InputFile.getFileData)(file, type);
67
+ values.push(value);
68
+ }
69
+ onFileChange?.(files2);
70
+ onValueChange?.(values);
71
+ } else {
72
+ const file = files[0];
73
+ onFileChange?.(file);
74
+ onValueChange?.(await (0, import_InputFile.getFileData)(file, type));
75
+ }
76
+ } finally {
77
+ setDisabled(false);
78
+ }
79
+ }
80
+ function onDragOver(e) {
81
+ _onDragOver?.(e);
82
+ if (disabled || !dragFile)
83
+ return;
84
+ e.preventDefault();
85
+ }
86
+ return /* @__PURE__ */ React.createElement(import_react.Fragment, null, /* @__PURE__ */ React.createElement(
87
+ import_InputFile.InputFile,
88
+ {
89
+ disabled: disabled || _disabled || __disabled,
90
+ style: { display: "none", ...style },
91
+ multiple,
92
+ accept,
93
+ type,
94
+ onValueChange,
95
+ onFileChange,
96
+ clearAfterChange,
97
+ ...restInputProps
98
+ }
99
+ ), (0, import_react.createElement)(as, {
100
+ disabled: disabled || _disabled,
101
+ onClick,
102
+ onDrop,
103
+ onDragOver,
104
+ ...rest
105
+ }));
106
+ }
107
+ // Annotate the CommonJS export names for ESM import in node:
108
+ 0 && (module.exports = {
109
+ InputFileButton
110
+ });
111
+ //# 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?: Omit<InputFileBaseProps, \"accept\">\r\n accept?: string\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 accept,\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 accept={accept}\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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,mBAAuI;AACvI,uBAA8I;AAgBvI,SAAS,gBACZ,OACF;AACE,QAAM;AAAA,IACF,KAAK;AAAA,IACL,SAAS;AAAA,IACT,aAAa,CAAC;AAAA,IACd;AAAA,IACA,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ;AAAA,IACA,UAAU;AAAA,IACV,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA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A,IACf,UAAU,YAAY;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACP,CAAC,CACL;AAER;",
6
+ "names": []
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,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>;
@@ -1,23 +1,19 @@
1
1
  "use client";
2
2
 
3
- import { forwardRef } from "react";
4
3
  import { readExcel } from "deepsea-tools";
5
4
  import { InputFile } from "./InputFile";
6
5
  import { jsx as _jsx } from "react/jsx-runtime";
7
6
  /** 专门用于读取 excel 的组件 */
8
- export const ImportExcel = /*#__PURE__*/forwardRef((props, ref) => {
7
+ export const ImportExcel = props => {
9
8
  const {
10
- onChange,
9
+ onValueChange,
11
10
  ...rest
12
11
  } = props;
13
12
  return /*#__PURE__*/_jsx(InputFile, {
14
- ref: ref,
15
13
  accept: ".xlsx",
16
14
  type: "arrayBuffer",
17
- onChange: ({
18
- result
19
- }) => onChange?.(readExcel(result)),
15
+ onValueChange: data => onValueChange?.(readExcel(data)),
20
16
  ...rest
21
17
  });
22
- });
18
+ };
23
19
  //# sourceMappingURL=ImportExcel.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["forwardRef","readExcel","InputFile","jsx","_jsx","ImportExcel","props","ref","onChange","rest","accept","type","result"],"sources":["../../../src/components/ImportExcel.tsx"],"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"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,UAAU,QAAQ,OAAO;AAClC,SAASC,SAAS,QAAQ,eAAe;AAEzC,SAASC,SAAS;AAAqC,SAAAC,GAAA,IAAAC,IAAA;AAMvD;AACA,OAAO,MAAMC,WAAW,gBAAGL,UAAU,CAAqC,CAACM,KAAK,EAAEC,GAAG,KAAK;EACtF,MAAM;IAAEC,QAAQ;IAAE,GAAGC;EAAK,CAAC,GAAGH,KAAK;EAEnC,oBAAOF,IAAA,CAACF,SAAS;IAACK,GAAG,EAAEA,GAAI;IAACG,MAAM,EAAC,OAAO;IAACC,IAAI,EAAC,aAAa;IAACH,QAAQ,EAAEA,CAAC;MAAEI;IAAO,CAAC,KAAKJ,QAAQ,GAAGP,SAAS,CAACW,MAAM,CAAC,CAAE;IAAA,GAAKH;EAAI,CAAG,CAAC;AACvI,CAAC,CAAC"}
1
+ {"version":3,"names":["readExcel","InputFile","jsx","_jsx","ImportExcel","props","onValueChange","rest","accept","type","data"],"sources":["../../../src/components/ImportExcel.tsx"],"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"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,SAAS,QAAQ,eAAe;AAGzC,SAASC,SAAS;AAAqC,SAAAC,GAAA,IAAAC,IAAA;AAMvD;AACA,OAAO,MAAMC,WAAiC,GAAGC,KAAK,IAAI;EACtD,MAAM;IAAEC,aAAa;IAAE,GAAGC;EAAK,CAAC,GAAGF,KAAK;EAExC,oBAAOF,IAAA,CAACF,SAAS;IAACO,MAAM,EAAC,OAAO;IAACC,IAAI,EAAC,aAAa;IAACH,aAAa,EAAEI,IAAI,IAAIJ,aAAa,GAAGN,SAAS,CAACU,IAAI,CAAC,CAAE;IAAA,GAAKH;EAAI,CAAG,CAAC;AAC7H,CAAC"}
@@ -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;