deepsea-components 5.10.0 → 5.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/InputFileButton.d.ts +5 -4
- package/dist/cjs/components/InputFileButton.js +2 -0
- package/dist/cjs/components/InputFileButton.js.map +2 -2
- package/dist/cjs/components/Unify.d.ts +4 -4
- package/dist/cjs/components/Unify.js +3 -3
- package/dist/cjs/components/Unify.js.map +2 -2
- package/dist/esm/components/InputFileButton.d.ts +5 -4
- package/dist/esm/components/InputFileButton.js +2 -0
- package/dist/esm/components/InputFileButton.js.map +1 -1
- package/dist/esm/components/Unify.d.ts +4 -4
- package/dist/esm/components/Unify.js +3 -3
- package/dist/esm/components/Unify.js.map +1 -1
- package/package.json +1 -1
- package/src/components/InputFileButton.tsx +23 -8
- package/src/components/Unify.tsx +6 -6
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ComponentProps, JSX } from "react";
|
|
1
|
+
import { ComponentProps, JSX, JSXElementConstructor } from "react";
|
|
2
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> & {
|
|
3
|
+
export type InputFileButtonProps<Multiple extends boolean = false, Type extends InputFileDataType = "file", AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = "button"> = Omit<ComponentProps<AS>, "as" | "type" | "disabled"> & InputFileExtraProps<Multiple, Type> & {
|
|
4
4
|
disabled?: boolean;
|
|
5
|
-
inputProps?: InputFileBaseProps
|
|
5
|
+
inputProps?: Omit<InputFileBaseProps, "accept">;
|
|
6
|
+
accept?: string;
|
|
6
7
|
dragFile?: boolean;
|
|
7
8
|
as?: AS;
|
|
8
9
|
};
|
|
9
10
|
/** 专用于读取文件的 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;
|
|
11
|
+
export declare function InputFileButton<Multiple extends boolean = false, Type extends InputFileDataType = "file", AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = "button">(props: InputFileButtonProps<Multiple, Type, AS>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -30,6 +30,7 @@ function InputFileButton(props) {
|
|
|
30
30
|
as = "button",
|
|
31
31
|
onClick: _onClick,
|
|
32
32
|
inputProps = {},
|
|
33
|
+
accept,
|
|
33
34
|
onDrop: _onDrop,
|
|
34
35
|
onDragOver: _onDragOver,
|
|
35
36
|
dragFile,
|
|
@@ -88,6 +89,7 @@ function InputFileButton(props) {
|
|
|
88
89
|
disabled: disabled || _disabled || __disabled,
|
|
89
90
|
style: { display: "none", ...style },
|
|
90
91
|
multiple,
|
|
92
|
+
accept,
|
|
91
93
|
type,
|
|
92
94
|
onValueChange,
|
|
93
95
|
onFileChange,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/InputFileButton.tsx"],
|
|
4
|
-
"sourcesContent": ["\"use client\"\r\n\r\nimport {
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,
|
|
4
|
+
"sourcesContent": ["\"use client\"\r\n\r\nimport {\r\n ComponentProps,\r\n ComponentRef,\r\n createElement,\r\n DragEvent,\r\n Fragment,\r\n JSX,\r\n JSXElementConstructor,\r\n MouseEvent as ReactMouseEvent,\r\n useRef,\r\n useState,\r\n} 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 | JSXElementConstructor<any> = \"button\",\r\n> = Omit<ComponentProps<AS>, \"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<\r\n Multiple extends boolean = false,\r\n Type extends InputFileDataType = \"file\",\r\n AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = \"button\",\r\n>(props: InputFileButtonProps<Multiple, Type, AS>) {\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,mBAWO;AACP,uBAA8I;AAgBvI,SAAS,gBAId,OAAiD;AAC/C,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;AAAA,IACA,GAAG;AAAA,EACP,IAAI;AAEJ,QAAM,EAAE,OAAO,UAAU,YAAY,GAAG,eAAe,IAAI;AAC3D,QAAM,CAAC,UAAU,WAAW,QAAI,uBAAS,KAAK;AAC9C,QAAM,YAAQ,qBAAyB,IAAI;AAE3C,WAAS,QAAQ,GAAkD;AAC/D,UAAM,SAAS,MAAM;AACrB,eAAW,CAAQ;AAAA,EACvB;AAEA,iBAAe,OAAO,GAAgC;AAClD,cAAU,CAAQ;AAClB,QAAI,YAAY,CAAC;AAAU;AAC3B,MAAE,eAAe;AACjB,UAAM,EAAE,MAAM,IAAI,EAAE;AACpB,QAAI,CAAC,SAAS,MAAM,WAAW;AAAG;AAClC,gBAAY,IAAI;AAChB,QAAI;AACA,UAAI,UAAU;AACV,cAAM,SAAiB,MAAM,KAAK,KAAK;AACvC,cAAM,SAAuC,CAAC;AAC9C,mBAAW,QAAQ,QAAQ;AACvB,gBAAM,QAAS,UAAM,8BAAY,MAAM,IAAI;AAC3C,iBAAO,KAAK,KAAK;AAAA,QACrB;AACA,uBAAe,MAA4B;AAC3C,wBAAgB,MAAmC;AAAA,MACvD,OAAO;AACH,cAAM,OAAO,MAAM,CAAC;AACpB,uBAAe,IAA0B;AACzC,wBAAiB,UAAM,8BAAY,MAAM,IAAI,CAA+B;AAAA,MAChF;AAAA,IACJ,UAAE;AACE,kBAAY,KAAK;AAAA,IACrB;AAAA,EACJ;AAEA,WAAS,WAAW,GAAgC;AAChD,kBAAc,CAAQ;AACtB,QAAI,YAAY,CAAC;AAAU;AAC3B,MAAE,eAAe;AAAA,EACrB;AAEA,SACI,oCAAC,6BACG;AAAA,IAAC;AAAA;AAAA,MACG,UAAU,YAAY,aAAa;AAAA,MACnC,OAAO,EAAE,SAAS,QAAQ,GAAG,MAAM;AAAA,MACnC;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACC,GAAG;AAAA;AAAA,EACR,OACC,4BAAc,IAAI;AAAA,IACf,UAAU,YAAY;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EACP,CAAC,CACL;AAER;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CSSProperties, ComponentProps, FC,
|
|
1
|
+
import { CSSProperties, ComponentProps, FC, JSX, JSXElementConstructor, ReactNode } from "react";
|
|
2
2
|
export interface UnifyConfig {
|
|
3
3
|
className?: string;
|
|
4
4
|
style?: CSSProperties;
|
|
@@ -7,7 +7,7 @@ export interface UnifyConfigProviderProps extends UnifyConfig {
|
|
|
7
7
|
children?: ReactNode;
|
|
8
8
|
}
|
|
9
9
|
export declare const UnifyConfigProvider: FC<UnifyConfigProviderProps>;
|
|
10
|
-
export type UnifyProps<
|
|
11
|
-
as?:
|
|
10
|
+
export type UnifyProps<AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = "div"> = Omit<ComponentProps<AS>, "as"> & {
|
|
11
|
+
as?: AS;
|
|
12
12
|
};
|
|
13
|
-
export declare function Unify<
|
|
13
|
+
export declare function Unify<AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = "div">(props: UnifyProps<AS>): ReactNode;
|
|
@@ -24,17 +24,17 @@ __export(Unify_exports, {
|
|
|
24
24
|
UnifyConfigProvider: () => UnifyConfigProvider
|
|
25
25
|
});
|
|
26
26
|
module.exports = __toCommonJS(Unify_exports);
|
|
27
|
-
var import_react = require("react");
|
|
28
27
|
var import_deepsea_tools = require("deepsea-tools");
|
|
28
|
+
var import_react = require("react");
|
|
29
29
|
var UnifyConfigContext = (0, import_react.createContext)({});
|
|
30
30
|
var UnifyConfigProvider = ({ className, style, children }) => {
|
|
31
31
|
const { className: _className, style: _style } = (0, import_react.useContext)(UnifyConfigContext);
|
|
32
32
|
return /* @__PURE__ */ React.createElement(UnifyConfigContext.Provider, { value: { className: (0, import_deepsea_tools.clsx)(_className, className), style: { ..._style, ...style } } }, children);
|
|
33
33
|
};
|
|
34
34
|
function Unify(props) {
|
|
35
|
-
const { as, className, style, ...rest } = props;
|
|
35
|
+
const { as = "div", className, style, ...rest } = props;
|
|
36
36
|
const { className: _className, style: _style } = (0, import_react.useContext)(UnifyConfigContext);
|
|
37
|
-
return (0, import_react.createElement)(as
|
|
37
|
+
return (0, import_react.createElement)(as, {
|
|
38
38
|
className: (0, import_deepsea_tools.clsx)(_className, className),
|
|
39
39
|
style: { ..._style, ...style },
|
|
40
40
|
...rest
|
|
@@ -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
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,
|
|
4
|
+
"sourcesContent": ["\"use client\"\r\n\r\nimport { clsx } from \"deepsea-tools\"\r\nimport { CSSProperties, ComponentProps, FC, JSX, JSXElementConstructor, ReactNode, createContext, createElement, useContext } from \"react\"\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<AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = \"div\"> = Omit<ComponentProps<AS>, \"as\"> & {\r\n as?: AS\r\n}\r\n\r\nexport function Unify<AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = \"div\">(props: UnifyProps<AS>) {\r\n const { as = \"div\", className, style, ...rest } = props\r\n const { className: _className, style: _style } = useContext(UnifyConfigContext)\r\n\r\n return createElement(as, {\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,2BAAqB;AACrB,mBAAmI;AAOnI,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,MAAmF,OAAuB;AACtH,QAAM,EAAE,KAAK,OAAO,WAAW,OAAO,GAAG,KAAK,IAAI;AAClD,QAAM,EAAE,WAAW,YAAY,OAAO,OAAO,QAAI,yBAAW,kBAAkB;AAE9E,aAAO,4BAAc,IAAI;AAAA,IACrB,eAAW,2BAAK,YAAY,SAAS;AAAA,IACrC,OAAO,EAAE,GAAG,QAAQ,GAAG,MAAM;AAAA,IAC7B,GAAG;AAAA,EACP,CAAC;AACL;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ComponentProps, JSX } from "react";
|
|
1
|
+
import { ComponentProps, JSX, JSXElementConstructor } from "react";
|
|
2
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> & {
|
|
3
|
+
export type InputFileButtonProps<Multiple extends boolean = false, Type extends InputFileDataType = "file", AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = "button"> = Omit<ComponentProps<AS>, "as" | "type" | "disabled"> & InputFileExtraProps<Multiple, Type> & {
|
|
4
4
|
disabled?: boolean;
|
|
5
|
-
inputProps?: InputFileBaseProps
|
|
5
|
+
inputProps?: Omit<InputFileBaseProps, "accept">;
|
|
6
|
+
accept?: string;
|
|
6
7
|
dragFile?: boolean;
|
|
7
8
|
as?: AS;
|
|
8
9
|
};
|
|
9
10
|
/** 专用于读取文件的 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;
|
|
11
|
+
export declare function InputFileButton<Multiple extends boolean = false, Type extends InputFileDataType = "file", AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = "button">(props: InputFileButtonProps<Multiple, Type, AS>): import("react/jsx-runtime").JSX.Element;
|
|
@@ -10,6 +10,7 @@ export function InputFileButton(props) {
|
|
|
10
10
|
as = "button",
|
|
11
11
|
onClick: _onClick,
|
|
12
12
|
inputProps = {},
|
|
13
|
+
accept,
|
|
13
14
|
onDrop: _onDrop,
|
|
14
15
|
onDragOver: _onDragOver,
|
|
15
16
|
dragFile,
|
|
@@ -73,6 +74,7 @@ export function InputFileButton(props) {
|
|
|
73
74
|
...style
|
|
74
75
|
},
|
|
75
76
|
multiple: multiple,
|
|
77
|
+
accept: accept,
|
|
76
78
|
type: type,
|
|
77
79
|
onValueChange: onValueChange,
|
|
78
80
|
onFileChange: onFileChange,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createElement","Fragment","useRef","useState","getFileData","InputFile","jsx","_jsx","jsxs","_jsxs","InputFileButton","props","as","onClick","_onClick","inputProps","onDrop","_onDrop","onDragOver","_onDragOver","dragFile","disabled","_disabled","type","multiple","onValueChange","onFileChange","clearAfterChange","rest","style","__disabled","restInputProps","setDisabled","input","e","current","click","preventDefault","files","dataTransfer","length","files2","Array","from","values","file","value","push","children","display"],"sources":["../../../src/components/InputFileButton.tsx"],"sourcesContent":["\"use client\"\r\n\r\nimport {
|
|
1
|
+
{"version":3,"names":["createElement","Fragment","useRef","useState","getFileData","InputFile","jsx","_jsx","jsxs","_jsxs","InputFileButton","props","as","onClick","_onClick","inputProps","accept","onDrop","_onDrop","onDragOver","_onDragOver","dragFile","disabled","_disabled","type","multiple","onValueChange","onFileChange","clearAfterChange","rest","style","__disabled","restInputProps","setDisabled","input","e","current","click","preventDefault","files","dataTransfer","length","files2","Array","from","values","file","value","push","children","display"],"sources":["../../../src/components/InputFileButton.tsx"],"sourcesContent":["\"use client\"\r\n\r\nimport {\r\n ComponentProps,\r\n ComponentRef,\r\n createElement,\r\n DragEvent,\r\n Fragment,\r\n JSX,\r\n JSXElementConstructor,\r\n MouseEvent as ReactMouseEvent,\r\n useRef,\r\n useState,\r\n} 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 | JSXElementConstructor<any> = \"button\",\r\n> = Omit<ComponentProps<AS>, \"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<\r\n Multiple extends boolean = false,\r\n Type extends InputFileDataType = \"file\",\r\n AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = \"button\",\r\n>(props: InputFileButtonProps<Multiple, Type, AS>) {\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"],"mappings":"AAAA,YAAY;;AAEZ,SAGIA,aAAa,EAEbC,QAAQ,EAIRC,MAAM,EACNC,QAAQ,QACL,OAAO;AACd,SAAmBC,WAAW,EAAEC,SAAS;AAAkH,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AAe3J;AACA,OAAO,SAASC,eAAeA,C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Props, FC, JSX, JSXElementConstructor, ReactNode } from "react";
|
|
2
2
|
export interface UnifyConfig {
|
|
3
3
|
className?: string;
|
|
4
4
|
style?: CSSProperties;
|
|
@@ -7,7 +7,7 @@ export interface UnifyConfigProviderProps extends UnifyConfig {
|
|
|
7
7
|
children?: ReactNode;
|
|
8
8
|
}
|
|
9
9
|
export declare const UnifyConfigProvider: FC<UnifyConfigProviderProps>;
|
|
10
|
-
export type UnifyProps<
|
|
11
|
-
as?:
|
|
10
|
+
export type UnifyProps<AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = "div"> = Omit<ComponentProps<AS>, "as"> & {
|
|
11
|
+
as?: AS;
|
|
12
12
|
};
|
|
13
|
-
export declare function Unify<
|
|
13
|
+
export declare function Unify<AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = "div">(props: UnifyProps<AS>): ReactNode;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
|
|
3
|
-
import { createContext, createElement, useContext } from "react";
|
|
4
3
|
import { clsx } from "deepsea-tools";
|
|
4
|
+
import { createContext, createElement, useContext } from "react";
|
|
5
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
6
6
|
const UnifyConfigContext = /*#__PURE__*/createContext({});
|
|
7
7
|
export const UnifyConfigProvider = ({
|
|
@@ -26,7 +26,7 @@ export const UnifyConfigProvider = ({
|
|
|
26
26
|
};
|
|
27
27
|
export function Unify(props) {
|
|
28
28
|
const {
|
|
29
|
-
as,
|
|
29
|
+
as = "div",
|
|
30
30
|
className,
|
|
31
31
|
style,
|
|
32
32
|
...rest
|
|
@@ -35,7 +35,7 @@ export function Unify(props) {
|
|
|
35
35
|
className: _className,
|
|
36
36
|
style: _style
|
|
37
37
|
} = useContext(UnifyConfigContext);
|
|
38
|
-
return /*#__PURE__*/createElement(as
|
|
38
|
+
return /*#__PURE__*/createElement(as, {
|
|
39
39
|
className: clsx(_className, className),
|
|
40
40
|
style: {
|
|
41
41
|
..._style,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["createContext","createElement","useContext","
|
|
1
|
+
{"version":3,"names":["clsx","createContext","createElement","useContext","jsx","_jsx","UnifyConfigContext","UnifyConfigProvider","className","style","children","_className","_style","Provider","value","Unify","props","as","rest"],"sources":["../../../src/components/Unify.tsx"],"sourcesContent":["\"use client\"\r\n\r\nimport { clsx } from \"deepsea-tools\"\r\nimport { CSSProperties, ComponentProps, FC, JSX, JSXElementConstructor, ReactNode, createContext, createElement, useContext } from \"react\"\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<AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = \"div\"> = Omit<ComponentProps<AS>, \"as\"> & {\r\n as?: AS\r\n}\r\n\r\nexport function Unify<AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = \"div\">(props: UnifyProps<AS>) {\r\n const { as = \"div\", className, style, ...rest } = props\r\n const { className: _className, style: _style } = useContext(UnifyConfigContext)\r\n\r\n return createElement(as, {\r\n className: clsx(_className, className),\r\n style: { ..._style, ...style },\r\n ...rest,\r\n }) as ReactNode\r\n}\r\n"],"mappings":"AAAA,YAAY;;AAEZ,SAASA,IAAI,QAAQ,eAAe;AACpC,SAAmFC,aAAa,EAAEC,aAAa,EAAEC,UAAU,QAAQ,OAAO;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAO1I,MAAMC,kBAAkB,gBAAGL,aAAa,CAAc,CAAC,CAAC,CAAC;AAMzD,OAAO,MAAMM,mBAAiD,GAAGA,CAAC;EAAEC,SAAS;EAAEC,KAAK;EAAEC;AAAS,CAAC,KAAK;EACjG,MAAM;IAAEF,SAAS,EAAEG,UAAU;IAAEF,KAAK,EAAEG;EAAO,CAAC,GAAGT,UAAU,CAACG,kBAAkB,CAAC;EAE/E,oBACID,IAAA,CAACC,kBAAkB,CAACO,QAAQ;IAACC,KAAK,EAAE;MAAEN,SAAS,EAAER,IAAI,CAACW,UAAU,EAAEH,SAAS,CAAC;MAAEC,KAAK,EAAE;QAAE,GAAGG,MAAM;QAAE,GAAGH;MAAM;IAAE,CAAE;IAAAC,QAAA,EAAEA;EAAQ,CAA8B,CAAC;AAEhK,CAAC;AAMD,OAAO,SAASK,KAAKA,CAA8EC,KAAqB,EAAE;EACtH,MAAM;IAAEC,EAAE,GAAG,KAAK;IAAET,SAAS;IAAEC,KAAK;IAAE,GAAGS;EAAK,CAAC,GAAGF,KAAK;EACvD,MAAM;IAAER,SAAS,EAAEG,UAAU;IAAEF,KAAK,EAAEG;EAAO,CAAC,GAAGT,UAAU,CAACG,kBAAkB,CAAC;EAE/E,oBAAOJ,aAAa,CAACe,EAAE,EAAE;IACrBT,SAAS,EAAER,IAAI,CAACW,UAAU,EAAEH,SAAS,CAAC;IACtCC,KAAK,EAAE;MAAE,GAAGG,MAAM;MAAE,GAAGH;IAAM,CAAC;IAC9B,GAAGS;EACP,CAAC,CAAC;AACN"}
|
package/package.json
CHANGED
|
@@ -1,28 +1,43 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
ComponentProps,
|
|
5
|
+
ComponentRef,
|
|
6
|
+
createElement,
|
|
7
|
+
DragEvent,
|
|
8
|
+
Fragment,
|
|
9
|
+
JSX,
|
|
10
|
+
JSXElementConstructor,
|
|
11
|
+
MouseEvent as ReactMouseEvent,
|
|
12
|
+
useRef,
|
|
13
|
+
useState,
|
|
14
|
+
} from "react"
|
|
4
15
|
import { FileType, getFileData, InputFile, InputFileBaseProps, InputFileDataType, InputFileDataTypeMap, InputFileExtraProps, ValueType } from "./InputFile"
|
|
5
16
|
|
|
6
17
|
export type InputFileButtonProps<
|
|
7
18
|
Multiple extends boolean = false,
|
|
8
19
|
Type extends InputFileDataType = "file",
|
|
9
|
-
AS extends keyof JSX.IntrinsicElements = "button",
|
|
10
|
-
> = Omit<ComponentProps<AS>, "type" | "disabled"> &
|
|
20
|
+
AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = "button",
|
|
21
|
+
> = Omit<ComponentProps<AS>, "as" | "type" | "disabled"> &
|
|
11
22
|
InputFileExtraProps<Multiple, Type> & {
|
|
12
23
|
disabled?: boolean
|
|
13
|
-
inputProps?: InputFileBaseProps
|
|
24
|
+
inputProps?: Omit<InputFileBaseProps, "accept">
|
|
25
|
+
accept?: string
|
|
14
26
|
dragFile?: boolean
|
|
15
27
|
as?: AS
|
|
16
28
|
}
|
|
17
29
|
|
|
18
30
|
/** 专用于读取文件的 button 组件 */
|
|
19
|
-
export function InputFileButton<
|
|
20
|
-
|
|
21
|
-
|
|
31
|
+
export function InputFileButton<
|
|
32
|
+
Multiple extends boolean = false,
|
|
33
|
+
Type extends InputFileDataType = "file",
|
|
34
|
+
AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = "button",
|
|
35
|
+
>(props: InputFileButtonProps<Multiple, Type, AS>) {
|
|
22
36
|
const {
|
|
23
37
|
as = "button",
|
|
24
38
|
onClick: _onClick,
|
|
25
39
|
inputProps = {},
|
|
40
|
+
accept,
|
|
26
41
|
onDrop: _onDrop,
|
|
27
42
|
onDragOver: _onDragOver,
|
|
28
43
|
dragFile,
|
|
@@ -83,6 +98,7 @@ export function InputFileButton<Multiple extends boolean = false, Type extends I
|
|
|
83
98
|
disabled={disabled || _disabled || __disabled}
|
|
84
99
|
style={{ display: "none", ...style }}
|
|
85
100
|
multiple={multiple}
|
|
101
|
+
accept={accept}
|
|
86
102
|
type={type as Type}
|
|
87
103
|
onValueChange={onValueChange}
|
|
88
104
|
onFileChange={onFileChange}
|
|
@@ -99,4 +115,3 @@ export function InputFileButton<Multiple extends boolean = false, Type extends I
|
|
|
99
115
|
</Fragment>
|
|
100
116
|
)
|
|
101
117
|
}
|
|
102
|
-
|
package/src/components/Unify.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
|
|
3
|
-
import { CSSProperties, ComponentProps, FC, ReactNode, createContext, createElement, useContext, JSX } from "react"
|
|
4
3
|
import { clsx } from "deepsea-tools"
|
|
4
|
+
import { CSSProperties, ComponentProps, FC, JSX, JSXElementConstructor, ReactNode, createContext, createElement, useContext } from "react"
|
|
5
5
|
|
|
6
6
|
export interface UnifyConfig {
|
|
7
7
|
className?: string
|
|
@@ -22,15 +22,15 @@ export const UnifyConfigProvider: FC<UnifyConfigProviderProps> = ({ className, s
|
|
|
22
22
|
)
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export type UnifyProps<
|
|
26
|
-
as?:
|
|
25
|
+
export type UnifyProps<AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = "div"> = Omit<ComponentProps<AS>, "as"> & {
|
|
26
|
+
as?: AS
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export function Unify<
|
|
30
|
-
const { as, className, style, ...rest } = props
|
|
29
|
+
export function Unify<AS extends keyof JSX.IntrinsicElements | JSXElementConstructor<any> = "div">(props: UnifyProps<AS>) {
|
|
30
|
+
const { as = "div", className, style, ...rest } = props
|
|
31
31
|
const { className: _className, style: _style } = useContext(UnifyConfigContext)
|
|
32
32
|
|
|
33
|
-
return createElement(as
|
|
33
|
+
return createElement(as, {
|
|
34
34
|
className: clsx(_className, className),
|
|
35
35
|
style: { ..._style, ...style },
|
|
36
36
|
...rest,
|