dn-react-router-toolkit 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/auth-kit/with_auth.d.mts +5 -5
- package/dist/auth-kit/with_auth.d.ts +5 -5
- package/dist/auth-kit/with_auth.js +3 -5
- package/dist/auth-kit/with_auth.mjs +3 -5
- package/dist/file-kit/client/drop_file_input.d.mts +7 -4
- package/dist/file-kit/client/drop_file_input.d.ts +7 -4
- package/dist/file-kit/client/drop_file_input.js +241 -179
- package/dist/file-kit/client/drop_file_input.mjs +240 -177
- package/dist/file-kit/client/file_uploader.d.mts +1 -0
- package/dist/file-kit/client/file_uploader.d.ts +1 -0
- package/dist/file-kit/client/file_uploader.js +40 -33
- package/dist/file-kit/client/file_uploader.mjs +38 -33
- package/dist/file-kit/client/metadata.d.mts +3 -0
- package/dist/file-kit/client/metadata.d.ts +3 -0
- package/dist/file-kit/client/metadata.js +59 -0
- package/dist/file-kit/client/metadata.mjs +34 -0
- package/package.json +3 -3
|
@@ -6,12 +6,12 @@ import '../file-kit/object_storage.mjs';
|
|
|
6
6
|
import '@aws-sdk/client-s3';
|
|
7
7
|
import './repository.mjs';
|
|
8
8
|
|
|
9
|
-
type
|
|
10
|
-
type InputFN = (auth?: JWTPayload) =>
|
|
11
|
-
type WithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (fn: InputFN) =>
|
|
12
|
-
declare function createWithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs>({ JWT_MANAGER, AUTH
|
|
9
|
+
type Handler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (arg: T) => Promise<unknown> | unknown;
|
|
10
|
+
type InputFN = (auth?: JWTPayload) => Handler<LoaderFunctionArgs> | Handler<ActionFunctionArgs>;
|
|
11
|
+
type WithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (fn: InputFN) => Handler<T>;
|
|
12
|
+
declare function createWithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs>({ JWT_MANAGER, AUTH }: {
|
|
13
13
|
JWT_MANAGER: JWTManager;
|
|
14
14
|
AUTH: AuthService;
|
|
15
|
-
}):
|
|
15
|
+
}): <THandler extends Handler<T>>(fn: (auth?: JWTPayload) => THandler) => THandler;
|
|
16
16
|
|
|
17
17
|
export { type WithAuthHandler, createWithAuthHandler };
|
|
@@ -6,12 +6,12 @@ import '../file-kit/object_storage.js';
|
|
|
6
6
|
import '@aws-sdk/client-s3';
|
|
7
7
|
import './repository.js';
|
|
8
8
|
|
|
9
|
-
type
|
|
10
|
-
type InputFN = (auth?: JWTPayload) =>
|
|
11
|
-
type WithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (fn: InputFN) =>
|
|
12
|
-
declare function createWithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs>({ JWT_MANAGER, AUTH
|
|
9
|
+
type Handler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (arg: T) => Promise<unknown> | unknown;
|
|
10
|
+
type InputFN = (auth?: JWTPayload) => Handler<LoaderFunctionArgs> | Handler<ActionFunctionArgs>;
|
|
11
|
+
type WithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs> = (fn: InputFN) => Handler<T>;
|
|
12
|
+
declare function createWithAuthHandler<T extends LoaderFunctionArgs | ActionFunctionArgs>({ JWT_MANAGER, AUTH }: {
|
|
13
13
|
JWT_MANAGER: JWTManager;
|
|
14
14
|
AUTH: AuthService;
|
|
15
|
-
}):
|
|
15
|
+
}): <THandler extends Handler<T>>(fn: (auth?: JWTPayload) => THandler) => THandler;
|
|
16
16
|
|
|
17
17
|
export { type WithAuthHandler, createWithAuthHandler };
|
|
@@ -54,12 +54,9 @@ var REFRESH_TOKEN_COOKIE = (0, import_react_router.createCookie)(REFRESH_TOKEN_K
|
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
// src/auth-kit/with_auth.ts
|
|
57
|
-
function createWithAuthHandler({
|
|
58
|
-
JWT_MANAGER,
|
|
59
|
-
AUTH
|
|
60
|
-
}) {
|
|
57
|
+
function createWithAuthHandler({ JWT_MANAGER, AUTH }) {
|
|
61
58
|
return function(fn) {
|
|
62
|
-
|
|
59
|
+
const handler = async function(arg) {
|
|
63
60
|
const cookie = arg.request.headers.get("cookie");
|
|
64
61
|
const accessToken = await ACCESS_TOKEN_COOKIE.parse(cookie);
|
|
65
62
|
if (accessToken) {
|
|
@@ -98,6 +95,7 @@ function createWithAuthHandler({
|
|
|
98
95
|
}
|
|
99
96
|
return fn(void 0)(arg);
|
|
100
97
|
};
|
|
98
|
+
return handler;
|
|
101
99
|
};
|
|
102
100
|
}
|
|
103
101
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -18,12 +18,9 @@ var REFRESH_TOKEN_COOKIE = createCookie(REFRESH_TOKEN_KEY, {
|
|
|
18
18
|
});
|
|
19
19
|
|
|
20
20
|
// src/auth-kit/with_auth.ts
|
|
21
|
-
function createWithAuthHandler({
|
|
22
|
-
JWT_MANAGER,
|
|
23
|
-
AUTH
|
|
24
|
-
}) {
|
|
21
|
+
function createWithAuthHandler({ JWT_MANAGER, AUTH }) {
|
|
25
22
|
return function(fn) {
|
|
26
|
-
|
|
23
|
+
const handler = async function(arg) {
|
|
27
24
|
const cookie = arg.request.headers.get("cookie");
|
|
28
25
|
const accessToken = await ACCESS_TOKEN_COOKIE.parse(cookie);
|
|
29
26
|
if (accessToken) {
|
|
@@ -62,6 +59,7 @@ function createWithAuthHandler({
|
|
|
62
59
|
}
|
|
63
60
|
return fn(void 0)(arg);
|
|
64
61
|
};
|
|
62
|
+
return handler;
|
|
65
63
|
};
|
|
66
64
|
}
|
|
67
65
|
export {
|
|
@@ -11,18 +11,21 @@ type FileInputProps = Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTM
|
|
|
11
11
|
};
|
|
12
12
|
type FileItem<T> = {
|
|
13
13
|
key: string;
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
14
16
|
item?: T;
|
|
15
17
|
};
|
|
16
18
|
type Props<T> = {
|
|
17
19
|
defaultValue?: T | T[];
|
|
18
20
|
options?: FileUploaderOptions;
|
|
19
|
-
uploadFile?: (file: File, options?: FileUploaderOptions) => Promise<T>;
|
|
20
21
|
onFileInput?: (files: File[]) => void;
|
|
21
22
|
onFileUploaded?: (file: T) => Promise<void>;
|
|
22
|
-
onChange?: (files:
|
|
23
|
+
onChange?: (files: T[]) => void;
|
|
23
24
|
limit?: number;
|
|
24
25
|
};
|
|
25
|
-
declare function
|
|
26
|
+
declare function createUseDropFileInput<T>({ uploadFile, }: {
|
|
27
|
+
uploadFile: (file: File, options?: FileUploaderOptions) => Promise<T>;
|
|
28
|
+
}): ({ defaultValue, options, onChange, onFileInput, onFileUploaded, limit, }?: Props<T>) => {
|
|
26
29
|
fileIds: string[];
|
|
27
30
|
files: FileItem<T>[];
|
|
28
31
|
setFiles: React.Dispatch<React.SetStateAction<FileItem<T>[]>>;
|
|
@@ -30,4 +33,4 @@ declare function useDropFileInput<T>({ defaultValue, options, uploadFile, onFile
|
|
|
30
33
|
};
|
|
31
34
|
declare function DropFileMessageBox(): React.JSX.Element;
|
|
32
35
|
|
|
33
|
-
export { DropFileMessageBox, type FileInputProps, type FileItem,
|
|
36
|
+
export { DropFileMessageBox, type FileInputProps, type FileItem, createUseDropFileInput as default };
|
|
@@ -11,18 +11,21 @@ type FileInputProps = Omit<React.DetailedHTMLProps<React.InputHTMLAttributes<HTM
|
|
|
11
11
|
};
|
|
12
12
|
type FileItem<T> = {
|
|
13
13
|
key: string;
|
|
14
|
+
width?: number;
|
|
15
|
+
height?: number;
|
|
14
16
|
item?: T;
|
|
15
17
|
};
|
|
16
18
|
type Props<T> = {
|
|
17
19
|
defaultValue?: T | T[];
|
|
18
20
|
options?: FileUploaderOptions;
|
|
19
|
-
uploadFile?: (file: File, options?: FileUploaderOptions) => Promise<T>;
|
|
20
21
|
onFileInput?: (files: File[]) => void;
|
|
21
22
|
onFileUploaded?: (file: T) => Promise<void>;
|
|
22
|
-
onChange?: (files:
|
|
23
|
+
onChange?: (files: T[]) => void;
|
|
23
24
|
limit?: number;
|
|
24
25
|
};
|
|
25
|
-
declare function
|
|
26
|
+
declare function createUseDropFileInput<T>({ uploadFile, }: {
|
|
27
|
+
uploadFile: (file: File, options?: FileUploaderOptions) => Promise<T>;
|
|
28
|
+
}): ({ defaultValue, options, onChange, onFileInput, onFileUploaded, limit, }?: Props<T>) => {
|
|
26
29
|
fileIds: string[];
|
|
27
30
|
files: FileItem<T>[];
|
|
28
31
|
setFiles: React.Dispatch<React.SetStateAction<FileItem<T>[]>>;
|
|
@@ -30,4 +33,4 @@ declare function useDropFileInput<T>({ defaultValue, options, uploadFile, onFile
|
|
|
30
33
|
};
|
|
31
34
|
declare function DropFileMessageBox(): React.JSX.Element;
|
|
32
35
|
|
|
33
|
-
export { DropFileMessageBox, type FileInputProps, type FileItem,
|
|
36
|
+
export { DropFileMessageBox, type FileInputProps, type FileItem, createUseDropFileInput as default };
|
|
@@ -31,8 +31,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var drop_file_input_exports = {};
|
|
32
32
|
__export(drop_file_input_exports, {
|
|
33
33
|
DropFileMessageBox: () => DropFileMessageBox,
|
|
34
|
-
default: () =>
|
|
35
|
-
useDropFileInput: () => useDropFileInput
|
|
34
|
+
default: () => createUseDropFileInput
|
|
36
35
|
});
|
|
37
36
|
module.exports = __toCommonJS(drop_file_input_exports);
|
|
38
37
|
var import_react = __toESM(require("react"));
|
|
@@ -43,193 +42,256 @@ function cn(...classes) {
|
|
|
43
42
|
return classes.filter(Boolean).join(" ").trim();
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
// src/file-kit/client/
|
|
47
|
-
function
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
key: (0, import_uuid.v4)(),
|
|
59
|
-
item: v
|
|
45
|
+
// src/file-kit/client/metadata.ts
|
|
46
|
+
function generateMetadata(blob) {
|
|
47
|
+
return new Promise((resolve, reject) => {
|
|
48
|
+
if (blob.type.startsWith("image/")) {
|
|
49
|
+
const img = new Image();
|
|
50
|
+
img.src = URL.createObjectURL(blob);
|
|
51
|
+
img.onload = () => {
|
|
52
|
+
resolve({
|
|
53
|
+
width: img.width,
|
|
54
|
+
height: img.height
|
|
55
|
+
});
|
|
60
56
|
};
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (f.key === fileItem.key) {
|
|
124
|
-
return {
|
|
125
|
-
...f,
|
|
126
|
-
item
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
return f;
|
|
130
|
-
})
|
|
131
|
-
);
|
|
132
|
-
});
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
[props.accept]
|
|
136
|
-
);
|
|
137
|
-
const handleDrop = (0, import_react.useCallback)(
|
|
138
|
-
(e) => {
|
|
57
|
+
img.onerror = reject;
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
if (blob.type.startsWith("video/")) {
|
|
61
|
+
const video = document.createElement("video");
|
|
62
|
+
video.src = URL.createObjectURL(blob);
|
|
63
|
+
video.onloadedmetadata = () => {
|
|
64
|
+
resolve({
|
|
65
|
+
width: video.videoWidth,
|
|
66
|
+
height: video.videoHeight,
|
|
67
|
+
duration: video.duration
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
video.onerror = reject;
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
resolve({});
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// src/file-kit/client/drop_file_input.tsx
|
|
78
|
+
function createUseDropFileInput({
|
|
79
|
+
uploadFile
|
|
80
|
+
}) {
|
|
81
|
+
return function useDropFileInput({
|
|
82
|
+
defaultValue,
|
|
83
|
+
options,
|
|
84
|
+
onChange,
|
|
85
|
+
onFileInput,
|
|
86
|
+
onFileUploaded,
|
|
87
|
+
limit
|
|
88
|
+
} = {}) {
|
|
89
|
+
const [files, setFiles] = (0, import_react.useState)(
|
|
90
|
+
defaultValue ? (Array.isArray(defaultValue) ? defaultValue : [defaultValue]).map((v) => {
|
|
91
|
+
return {
|
|
92
|
+
key: (0, import_uuid.v4)(),
|
|
93
|
+
item: v
|
|
94
|
+
};
|
|
95
|
+
}).slice(0, limit ? limit : Infinity) : []
|
|
96
|
+
);
|
|
97
|
+
const fileRef = (0, import_react.useRef)([]);
|
|
98
|
+
(0, import_react.useEffect)(() => {
|
|
99
|
+
fileRef.current = files;
|
|
100
|
+
onChange?.(files.map((f) => f.item).filter(Boolean));
|
|
101
|
+
}, [files]);
|
|
102
|
+
const Component = (0, import_react.useCallback)(
|
|
103
|
+
function Component2({
|
|
104
|
+
className,
|
|
105
|
+
container = "border border-dashed border-neutral-300 rounded flex items-center justify-center",
|
|
106
|
+
draggingClassName,
|
|
107
|
+
name,
|
|
108
|
+
hideMessage = false,
|
|
109
|
+
children,
|
|
110
|
+
...props
|
|
111
|
+
}) {
|
|
112
|
+
const [isDragging, setIsDragging] = (0, import_react.useState)(false);
|
|
113
|
+
const handleDragEnter = (0, import_react.useCallback)((e) => {
|
|
114
|
+
e.preventDefault();
|
|
115
|
+
e.stopPropagation();
|
|
116
|
+
setIsDragging(true);
|
|
117
|
+
}, []);
|
|
118
|
+
const handleDragLeave = (0, import_react.useCallback)((e) => {
|
|
139
119
|
e.preventDefault();
|
|
140
120
|
e.stopPropagation();
|
|
141
121
|
setIsDragging(false);
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
handleClick();
|
|
157
|
-
}
|
|
158
|
-
},
|
|
159
|
-
[handleClick]
|
|
160
|
-
);
|
|
161
|
-
const handleChange = (0, import_react.useCallback)(
|
|
162
|
-
(e) => {
|
|
163
|
-
if (e.target.files && e.target.files.length > 0) {
|
|
164
|
-
handleFiles(Array.from(e.target.files));
|
|
165
|
-
e.target.value = "";
|
|
166
|
-
}
|
|
167
|
-
},
|
|
168
|
-
[handleFiles]
|
|
169
|
-
);
|
|
170
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
171
|
-
"div",
|
|
172
|
-
{
|
|
173
|
-
className: cn(
|
|
174
|
-
className,
|
|
175
|
-
container,
|
|
176
|
-
draggingClassName?.(isDragging) || (isDragging ? "bg-neutral-300/25" : "hover:bg-neutral-300/25"),
|
|
177
|
-
"transition-colors cursor-pointer"
|
|
178
|
-
),
|
|
179
|
-
onDragEnter: handleDragEnter,
|
|
180
|
-
onDragLeave: handleDragLeave,
|
|
181
|
-
onDragOver: handleDragOver,
|
|
182
|
-
onDrop: handleDrop,
|
|
183
|
-
onClick: handleClick,
|
|
184
|
-
onChange: handleChange,
|
|
185
|
-
onKeyDown: handleKeyDown,
|
|
186
|
-
tabIndex: 0,
|
|
187
|
-
role: "button"
|
|
188
|
-
},
|
|
189
|
-
/* @__PURE__ */ import_react.default.createElement("input", { ...props, defaultValue: "", type: "file", hidden: true, ref: inputRef }),
|
|
190
|
-
/* @__PURE__ */ import_react.default.createElement(
|
|
191
|
-
"input",
|
|
192
|
-
{
|
|
193
|
-
name,
|
|
194
|
-
hidden: true,
|
|
195
|
-
readOnly: true,
|
|
196
|
-
value: files.map((file) => {
|
|
197
|
-
if (file.item && typeof file.item === "object" && "id" in file.item) {
|
|
198
|
-
return file.item.id;
|
|
122
|
+
}, []);
|
|
123
|
+
const handleDragOver = (0, import_react.useCallback)((e) => {
|
|
124
|
+
e.preventDefault();
|
|
125
|
+
e.stopPropagation();
|
|
126
|
+
}, []);
|
|
127
|
+
const handleFiles = (0, import_react.useCallback)(
|
|
128
|
+
async (files2) => {
|
|
129
|
+
if (limit && fileRef.current.length >= limit) {
|
|
130
|
+
alert(`\uD30C\uC77C\uC740 \uCD5C\uB300 ${limit}\uAC1C \uC5C5\uB85C\uB4DC\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.`);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const filteredFiles = files2.filter((file) => {
|
|
134
|
+
if (!props.accept) {
|
|
135
|
+
return true;
|
|
199
136
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
137
|
+
const accepts = props.accept.split(",");
|
|
138
|
+
for (const accept of accepts) {
|
|
139
|
+
const trimmedAccept = accept.trim();
|
|
140
|
+
if (file.type === trimmedAccept || file.type.endsWith(trimmedAccept) || file.name.endsWith(trimmedAccept)) {
|
|
141
|
+
return true;
|
|
142
|
+
}
|
|
143
|
+
if (trimmedAccept.endsWith("/*")) {
|
|
144
|
+
const baseType = trimmedAccept.replace("/*", "");
|
|
145
|
+
if (file.type.startsWith(baseType + "/")) {
|
|
146
|
+
return true;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
return false;
|
|
151
|
+
});
|
|
152
|
+
if (files2.length !== filteredFiles.length) {
|
|
153
|
+
alert(`${props.accept} \uD615\uC2DD\uC758 \uD30C\uC77C\uB9CC \uC5C5\uB85C\uB4DC\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.`);
|
|
154
|
+
}
|
|
155
|
+
const limitedFiles = filteredFiles.slice(
|
|
156
|
+
0,
|
|
157
|
+
limit ? limit - fileRef.current.length : Infinity
|
|
158
|
+
);
|
|
159
|
+
if (limitedFiles.length === 0) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (onFileInput) {
|
|
163
|
+
onFileInput(limitedFiles);
|
|
164
|
+
}
|
|
165
|
+
for (const file of limitedFiles) {
|
|
166
|
+
const { width, height } = await generateMetadata(file);
|
|
167
|
+
const fileItem = {
|
|
168
|
+
key: (0, import_uuid.v4)(),
|
|
169
|
+
width: Number(width) || void 0,
|
|
170
|
+
height: Number(height) || void 0
|
|
171
|
+
};
|
|
172
|
+
setFiles((prevFiles) => [...prevFiles, fileItem]);
|
|
173
|
+
uploadFile?.(file, options).then(async (item) => {
|
|
174
|
+
await onFileUploaded?.(item);
|
|
175
|
+
setFiles(
|
|
176
|
+
(prevFiles) => prevFiles.map((f) => {
|
|
177
|
+
if (f.key === fileItem.key) {
|
|
178
|
+
return {
|
|
179
|
+
...f,
|
|
180
|
+
item
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
return f;
|
|
184
|
+
})
|
|
185
|
+
);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
},
|
|
189
|
+
[props.accept]
|
|
190
|
+
);
|
|
191
|
+
const handleDrop = (0, import_react.useCallback)(
|
|
192
|
+
(e) => {
|
|
193
|
+
e.preventDefault();
|
|
194
|
+
e.stopPropagation();
|
|
195
|
+
setIsDragging(false);
|
|
196
|
+
if (e.dataTransfer.files && e.dataTransfer.files.length > 0) {
|
|
197
|
+
handleFiles(Array.from(e.dataTransfer.files));
|
|
198
|
+
e.dataTransfer.clearData();
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
[handleFiles]
|
|
202
|
+
);
|
|
203
|
+
const inputRef = (0, import_react.useRef)(null);
|
|
204
|
+
const handleClick = (0, import_react.useCallback)(() => {
|
|
205
|
+
inputRef.current?.click();
|
|
206
|
+
}, []);
|
|
207
|
+
const handleKeyDown = (0, import_react.useCallback)(
|
|
208
|
+
(e) => {
|
|
209
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
210
|
+
handleClick();
|
|
211
|
+
}
|
|
212
|
+
},
|
|
213
|
+
[handleClick]
|
|
214
|
+
);
|
|
215
|
+
const handleChange = (0, import_react.useCallback)(
|
|
216
|
+
(e) => {
|
|
217
|
+
if (e.target.files && e.target.files.length > 0) {
|
|
218
|
+
handleFiles(Array.from(e.target.files));
|
|
219
|
+
e.target.value = "";
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
[handleFiles]
|
|
223
|
+
);
|
|
224
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
225
|
+
"div",
|
|
226
|
+
{
|
|
227
|
+
className: cn(
|
|
228
|
+
className,
|
|
229
|
+
container,
|
|
230
|
+
draggingClassName?.(isDragging) || (isDragging ? "bg-neutral-300/25" : "hover:bg-neutral-300/25"),
|
|
231
|
+
"transition-colors cursor-pointer"
|
|
232
|
+
),
|
|
233
|
+
onDragEnter: handleDragEnter,
|
|
234
|
+
onDragLeave: handleDragLeave,
|
|
235
|
+
onDragOver: handleDragOver,
|
|
236
|
+
onDrop: handleDrop,
|
|
237
|
+
onClick: handleClick,
|
|
238
|
+
onChange: handleChange,
|
|
239
|
+
onKeyDown: handleKeyDown,
|
|
240
|
+
tabIndex: 0,
|
|
241
|
+
role: "button"
|
|
242
|
+
},
|
|
243
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
244
|
+
"input",
|
|
245
|
+
{
|
|
246
|
+
...props,
|
|
247
|
+
defaultValue: "",
|
|
248
|
+
type: "file",
|
|
249
|
+
hidden: true,
|
|
250
|
+
ref: inputRef
|
|
251
|
+
}
|
|
252
|
+
),
|
|
253
|
+
/* @__PURE__ */ import_react.default.createElement(
|
|
254
|
+
"input",
|
|
255
|
+
{
|
|
256
|
+
name,
|
|
257
|
+
hidden: true,
|
|
258
|
+
readOnly: true,
|
|
259
|
+
value: files.map((file) => {
|
|
260
|
+
if (file.item && typeof file.item === "object" && "id" in file.item) {
|
|
261
|
+
return file.item.id;
|
|
262
|
+
}
|
|
263
|
+
return null;
|
|
264
|
+
}).filter(Boolean).join(",")
|
|
265
|
+
}
|
|
266
|
+
),
|
|
267
|
+
children || !(hideMessage && !isDragging) && /* @__PURE__ */ import_react.default.createElement(DropFileMessageBox, null)
|
|
268
|
+
);
|
|
269
|
+
},
|
|
270
|
+
[limit, fileRef, files, options, uploadFile, onFileInput, onFileUploaded]
|
|
271
|
+
);
|
|
272
|
+
const loadedFileIds = files.map((file) => {
|
|
273
|
+
if (file.item && typeof file.item === "object" && "id" in file.item) {
|
|
274
|
+
return file.item.id;
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
277
|
+
}).filter(Boolean);
|
|
278
|
+
const loadedFileIdsString = loadedFileIds.join(",");
|
|
279
|
+
const fileIds = (0, import_react.useMemo)(
|
|
280
|
+
() => loadedFileIdsString.split(",").filter(Boolean),
|
|
281
|
+
[loadedFileIdsString]
|
|
282
|
+
);
|
|
283
|
+
return {
|
|
284
|
+
fileIds,
|
|
285
|
+
files,
|
|
286
|
+
setFiles,
|
|
287
|
+
Component
|
|
288
|
+
};
|
|
225
289
|
};
|
|
226
290
|
}
|
|
227
291
|
function DropFileMessageBox() {
|
|
228
292
|
return /* @__PURE__ */ import_react.default.createElement("div", { className: "text-sm pointer-events-none flex justify-center items-center" }, /* @__PURE__ */ import_react.default.createElement("div", { className: "flex flex-col items-center" }, /* @__PURE__ */ import_react.default.createElement("span", null, "\uD30C\uC77C\uC744 \uC5EC\uAE30\uB85C \uB04C\uC5B4\uB2E4 \uB193\uAC70\uB098 \uD074\uB9AD\uD574\uC11C \uC120\uD0DD\uD574 \uC8FC\uC138\uC694")));
|
|
229
293
|
}
|
|
230
|
-
var drop_file_input_default = useDropFileInput;
|
|
231
294
|
// Annotate the CommonJS export names for ESM import in node:
|
|
232
295
|
0 && (module.exports = {
|
|
233
|
-
DropFileMessageBox
|
|
234
|
-
useDropFileInput
|
|
296
|
+
DropFileMessageBox
|
|
235
297
|
});
|