Skip to content

Commit

Permalink
Added data-convert
Browse files Browse the repository at this point in the history
  • Loading branch information
ackava committed Oct 17, 2024
1 parent b1ab66e commit 969d96f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/basic/FilesDragDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const eventDrop = (e: DragEvent) => {
const uploadEvent = StringHelper.fromHyphenToCamel(currentTarget.getAttribute("data-upload-event"));
const uploadRequested = StringHelper.fromHyphenToCamel(currentTarget.getAttribute("data-upload-requested"));
const extra = currentTarget.getAttribute("data-extra");
const convert = currentTarget.getAttribute("data-convert") === "true";

const fileHandlesPromises = [...e.dataTransfer.items as any]
.filter((item) => item.kind === "file")
Expand Down Expand Up @@ -87,6 +88,7 @@ const eventDrop = (e: DragEvent) => {
const detail = {
files,
extra,
convert,
uploadEvent
};
// console.log(detail);
Expand All @@ -99,10 +101,12 @@ const eventDrop = (e: DragEvent) => {
export const FilesDragDrop = ({
uploadEvent = "files-available",
uploadRequested = "upload-requested",
convert = false,
extra = "",
}) => ({
"data-extra": extra,
"data-drag-drop": "1",
"data-convert": convert,
"data-upload-event": uploadEvent,
"data-upload-requested": uploadRequested,
"event-dragenter": dragEnter,
Expand Down
8 changes: 8 additions & 0 deletions src/basic/UploadEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ export interface IUploadParams<T = any> {
/** Will enforce that the selected file matches the given accept types */
forceType?: boolean;
maxSize?: number;
/** Used for inline video conversion, you must handle conversion before upload by yourself. */
convert?: boolean;
upload?: boolean;
/** Extra will hold other information that will be available in upload event */
extra?: T;
Expand All @@ -69,6 +71,7 @@ const requestUpload = ({
multiple,
authorize,
extra,
convert,
upload,
folder,
uploadEvent
Expand All @@ -77,6 +80,7 @@ const requestUpload = ({
multiple?: boolean,
authorize?: boolean,
extra?: any,
convert?: boolean,
upload?: boolean,
folder?: boolean,
uploadEvent?: string
Expand Down Expand Up @@ -199,12 +203,14 @@ window.addEventListener(uploadCommand.eventName, (ce: MouseEvent) => {
const extra = (element as any).extra ?? element.getAttribute("data-extra");
const upload = element.getAttribute("data-upload") === "true";
const folder = element.hasAttribute("data-folder");
const convert = element.getAttribute("data-convert") === "true";
const uploadEvent = StringHelper.fromHyphenToCamel(element.getAttribute("data-upload-event"));
requestUpload({
element,
authorize,
multiple,
extra,
convert,
upload,
folder,
uploadEvent
Expand All @@ -226,6 +232,7 @@ export default class UploadEvent {
forceType = true,
maxSize = 524288000,
extra,
convert = false,
upload = true,
authorize = true,
ariaLabel = "Upload",
Expand All @@ -240,6 +247,7 @@ export default class UploadEvent {
"data-accept": accept,
"data-multiple": multiple ? "true" : "false",
"data-capture": capture,
"data-convert": convert,
"data-upload": upload ? "true" : "false",
"data-force-type": forceType ? "true" : "false",
"data-max-size" : maxSize ? maxSize.toString() : undefined,
Expand Down

0 comments on commit 969d96f

Please sign in to comment.