@uxf/ui 10.7.0 → 10.8.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.
@@ -6,7 +6,8 @@ export interface FileInputBaseProps extends FormControlProps<FileResponse | null
6
6
  className?: string;
7
7
  form?: string;
8
8
  id?: string;
9
+ maxFileSize?: number;
9
10
  onUploadError?: (err: unknown) => void;
10
- onUploadFile: (file: File) => Promise<FileResponse>;
11
+ onUploadFile: (file: File | undefined) => Promise<FileResponse | null>;
11
12
  }
12
13
  export declare const _FileInputBase: React.ForwardRefExoticComponent<FileInputBaseProps & React.RefAttributes<HTMLInputElement>>;
@@ -25,16 +25,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports._FileInputBase = void 0;
27
27
  const react_1 = __importStar(require("react"));
28
+ const validator_exceptions_1 = require("../utils/validator/validator-exceptions");
28
29
  exports._FileInputBase = (0, react_1.forwardRef)((props, ref) => {
29
30
  const onChange = async (e) => {
30
- var _a;
31
- if (e.target.files) {
31
+ var _a, _b;
32
+ if ((_a = e.target.files) === null || _a === void 0 ? void 0 : _a.length) {
32
33
  try {
33
- const response = await props.onUploadFile(e.target.files[0]);
34
+ const file = e.target.files[0];
35
+ if (props.maxFileSize && file.size > props.maxFileSize) {
36
+ throw validator_exceptions_1.ValidatorExceptions.MaxFileSize;
37
+ }
38
+ const response = await props.onUploadFile(file);
34
39
  await props.onChange(response, e);
35
40
  }
36
41
  catch (err) {
37
- (_a = props.onUploadError) === null || _a === void 0 ? void 0 : _a.call(props, err);
42
+ (_b = props.onUploadError) === null || _b === void 0 ? void 0 : _b.call(props, err);
38
43
  }
39
44
  }
40
45
  else {
@@ -36,10 +36,8 @@ const input_1 = require("@uxf/ui/input");
36
36
  const label_1 = require("@uxf/ui/label");
37
37
  const react_2 = __importStar(require("react"));
38
38
  const Option = (props) => {
39
- var _a, _b, _c, _d;
40
- const optionKey = (_a = props.keyExtractor) === null || _a === void 0 ? void 0 : _a.call(props, props.option);
41
39
  const HUIComponent = props.HUIComponent;
42
- return (react_2.default.createElement(HUIComponent.Option, { className: (optionState) => (0, cx_1.cx)("uxf-dropdown__item", optionState.active && classes_1.CLASSES.IS_ACTIVE, optionState.disabled && classes_1.CLASSES.IS_DISABLED, optionState.selected && classes_1.CLASSES.IS_SELECTED), key: optionKey !== null && optionKey !== void 0 ? optionKey : props.option.id, value: props.option }, (_d = (_c = (_b = props.renderOption) === null || _b === void 0 ? void 0 : _b.call(props, props.option)) !== null && _c !== void 0 ? _c : optionKey) !== null && _d !== void 0 ? _d : props.option.label));
40
+ return (react_2.default.createElement(HUIComponent.Option, { className: (optionState) => (0, cx_1.cx)("uxf-dropdown__item", optionState.active && classes_1.CLASSES.IS_ACTIVE, optionState.disabled && classes_1.CLASSES.IS_DISABLED, optionState.selected && classes_1.CLASSES.IS_SELECTED), value: props.option }, (optionState) => { var _a, _b; return (_b = (_a = props.renderOption) === null || _a === void 0 ? void 0 : _a.call(props, props.option, optionState.selected)) !== null && _b !== void 0 ? _b : props.option.label; }));
43
41
  };
44
42
  Option.displayName = "UxfUiSelectBaseOption";
45
43
  function isHUICombobox(HUIComponent) {
@@ -68,9 +66,9 @@ const Options = (props) => {
68
66
  return (react_2.default.createElement(HUIComponent.Options, { className: (0, cx_1.cx)("uxf-dropdown uxf-select-base__options", `uxf-dropdown--size-${(_a = props.size) !== null && _a !== void 0 ? _a : "default"}`, `uxf-dropdown--variant-${(_b = props.variant) !== null && _b !== void 0 ? _b : "default"}`, props.matchWidth
69
67
  ? "uxf-select-base__options--match-width"
70
68
  : "uxf-select-base__options--not-match-width", props.placement === "bottom" && "uxf-dropdown--bottom", props.placement === "top" && "uxf-dropdown--top", props.className), ref: props.forwardRef, static: true, style: props.style }, props.options && props.options.length > 0 ? (props.options.map((option) => {
71
- var _a;
72
- const optionKey = (_a = props.keyExtractor) === null || _a === void 0 ? void 0 : _a.call(props, option);
73
- return (react_2.default.createElement(Option, { key: optionKey, keyExtractor: props.keyExtractor, option: option, HUIComponent: HUIComponent }));
69
+ var _a, _b;
70
+ const optionKey = (_b = (_a = props.keyExtractor) === null || _a === void 0 ? void 0 : _a.call(props, option)) !== null && _b !== void 0 ? _b : option.id;
71
+ return (react_2.default.createElement(Option, { HUIComponent: HUIComponent, key: optionKey, option: option, renderOption: props.renderOption }));
74
72
  })) : (react_2.default.createElement("div", { className: "uxf-dropdown__empty-wrapper" }, props.emptyMessage))));
75
73
  };
76
74
  Options.displayName = "UxfUiSelectBaseOptions";
@@ -45,11 +45,18 @@ exports.AvatarFileInput = (0, react_1.forwardRef)((props, ref) => {
45
45
  const stateClassName = (0, cx_1.cx)(((_a = props.isFocused) !== null && _a !== void 0 ? _a : input.focused) && classes_1.CLASSES.IS_FOCUSED, props.isDisabled && classes_1.CLASSES.IS_DISABLED, props.isInvalid && classes_1.CLASSES.IS_INVALID, props.isReadOnly && classes_1.CLASSES.IS_READONLY, props.isRequired && classes_1.CLASSES.IS_REQUIRED);
46
46
  const rootClassName = (0, cx_1.cx)(`uxf-avatar-file-input uxf-avatar-file-input--variant-${(_b = props.variant) !== null && _b !== void 0 ? _b : "default"}`, stateClassName, props.className);
47
47
  const onSelectFile = () => { var _a; return (_a = innerRef.current) === null || _a === void 0 ? void 0 : _a.click(); };
48
- const onRemoveFile = () => props.onChange(null);
48
+ const onRemoveFile = () => {
49
+ props.onChange(null);
50
+ // this ensures that the file input is cleared on remove, so that the same file can be selected again
51
+ const inputNode = innerRef.current;
52
+ if (inputNode) {
53
+ inputNode.value = "";
54
+ }
55
+ };
49
56
  return (react_1.default.createElement(form_component_1.FormComponent, { className: rootClassName, errorId: props.id, helperText: props.helperText, hiddenLabel: props.hiddenLabel, inputId: id, label: props.label },
50
57
  react_1.default.createElement("div", { className: "uxf-avatar-file-input__inner-wrapper" },
51
58
  react_1.default.createElement("div", { className: (0, cx_1.cx)("uxf-avatar-file-input__input", stateClassName), onClick: onSelectFile },
52
- react_1.default.createElement(_file_input_base_1._FileInputBase, { accept: (_c = props.accept) !== null && _c !== void 0 ? _c : "image/*", "aria-describedby": errorId, "aria-invalid": props.isInvalid, className: "uxf-avatar-file-input__input-element", form: props.form, id: id, isDisabled: props.isDisabled, isFocused: props.isFocused, isInvalid: props.isInvalid, isReadOnly: props.isReadOnly, isRequired: props.isRequired, name: props.name, onBlur: input.onBlur, onFocus: input.onFocus, onChange: props.onChange, onUploadError: props.onUploadError, onUploadFile: props.onUploadFile, ref: (0, composeRefs_1.composeRefs)(innerRef, ref), value: props.value }),
59
+ react_1.default.createElement(_file_input_base_1._FileInputBase, { accept: (_c = props.accept) !== null && _c !== void 0 ? _c : "image/*", "aria-describedby": errorId, "aria-invalid": props.isInvalid, className: "uxf-avatar-file-input__input-element", form: props.form, id: id, isDisabled: props.isDisabled, isFocused: props.isFocused, isInvalid: props.isInvalid, isReadOnly: props.isReadOnly, isRequired: props.isRequired, maxFileSize: props.maxFileSize, name: props.name, onBlur: input.onBlur, onFocus: input.onFocus, onChange: props.onChange, onUploadError: props.onUploadError, onUploadFile: props.onUploadFile, ref: (0, composeRefs_1.composeRefs)(innerRef, ref), value: props.value }),
53
60
  props.value ? (react_1.default.createElement(avatar_1.Avatar, { className: "uxf-avatar-file-input__input-avatar", src: (0, file_1.getFileUrl)(props.value) })) : (react_1.default.createElement("div", { className: "uxf-avatar-file-input__input-empty" },
54
61
  react_1.default.createElement(icon_1.Icon, { className: "uxf-avatar-file-input__input-empty-icon", name: (_d = props.icon) !== null && _d !== void 0 ? _d : "cloud" })))),
55
62
  react_1.default.createElement("div", { className: "uxf-avatar-file-input__controls" }, props.customControls ? (props.customControls({
@@ -33,7 +33,7 @@ const react_1 = __importStar(require("react"));
33
33
  exports.CalendarDayCell = (0, react_1.memo)((props) => {
34
34
  const dayCellRef = (0, react_1.useRef)(null);
35
35
  const innerRef = (0, react_1.useRef)(null);
36
- const { disabledDate, isHovered, isSelected, isInsideRange, isToday, isWithinHoverRange, onClick, onKeyDown, onMouseEnter, tabIndex, } = (0, use_day_1.useDay)({
36
+ const { disabledDate, isHovered, isSelected, isInsideRange, isToday, isWithinHoverRange, onClick, onKeyDown, onMouseEnter, tabIndex, isFirstDisabled, isLastDisabled, } = (0, use_day_1.useDay)({
37
37
  date: props.day.date,
38
38
  focusedDate: props.datePickerProps.focusedDate,
39
39
  isDateBlocked: props.datePickerProps.isDateBlocked,
@@ -46,6 +46,7 @@ exports.CalendarDayCell = (0, react_1.memo)((props) => {
46
46
  onDateSelect: props.datePickerProps.onDateSelect,
47
47
  dayRef: dayCellRef,
48
48
  preventScroll: props.datePickerProps.preventScroll,
49
+ unavailableDates: props.datePickerProps.unavailableDates,
49
50
  });
50
51
  (0, useOnMount_1.useOnMount)(() => {
51
52
  const node = innerRef.current;
@@ -56,7 +57,7 @@ exports.CalendarDayCell = (0, react_1.memo)((props) => {
56
57
  if (!props.day.dayLabel) {
57
58
  return react_1.default.createElement("div", null);
58
59
  }
59
- return (react_1.default.createElement("button", { className: (0, cx_1.cx)("uxf-calendar__cell uxf-calendar__cell-day", disabledDate && classes_1.CLASSES.IS_DISABLED, isToday && "uxf-calendar__cell--today", isSelected && "uxf-calendar__cell--selected", isInsideRange && "uxf-calendar__cell--inside-range", isWithinHoverRange && "uxf-calendar__cell--is-within-hover-range", isHovered && "uxf-calendar__cell--is-hovered", !props.day.currentMonth && "uxf-calendar__cell--not-current-month"), ref: disabledDate ? undefined : (0, composeRefs_1.composeRefs)(dayCellRef, innerRef), onClick: onClick, onKeyDown: onKeyDown, onMouseEnter: onMouseEnter, tabIndex: tabIndex, type: "button" },
60
+ return (react_1.default.createElement("button", { className: (0, cx_1.cx)("uxf-calendar__cell uxf-calendar__cell-day", isFirstDisabled && props.day.currentMonth && "is-disabled-start", isLastDisabled && props.day.currentMonth && "is-disabled-end", disabledDate && classes_1.CLASSES.IS_DISABLED, isToday && "uxf-calendar__cell--today", isSelected && "uxf-calendar__cell--selected", isInsideRange && "uxf-calendar__cell--inside-range", isWithinHoverRange && "uxf-calendar__cell--is-within-hover-range", isHovered && "uxf-calendar__cell--is-hovered", !props.day.currentMonth && "uxf-calendar__cell--not-current-month"), ref: disabledDate ? undefined : (0, composeRefs_1.composeRefs)(dayCellRef, innerRef), onClick: onClick, onKeyDown: onKeyDown, onMouseEnter: onMouseEnter, tabIndex: tabIndex, type: "button" },
60
61
  react_1.default.createElement("span", { className: "uxf-calendar__cell__inner" }, props.day.dayLabel)));
61
62
  });
62
63
  exports.CalendarDayCell.displayName = "UxfUiCalendarDayCell";
@@ -8,5 +8,6 @@ export interface CheckboxInputProps extends FormControlProps<boolean | undefined
8
8
  label: ReactNode;
9
9
  size?: CheckboxSize;
10
10
  style?: CSSProperties;
11
+ helperText?: ReactNode;
11
12
  }
12
13
  export declare const CheckboxInput: React.ForwardRefExoticComponent<CheckboxInputProps & React.RefAttributes<HTMLDivElement>>;
@@ -28,10 +28,15 @@ const react_1 = require("@headlessui/react");
28
28
  const react_2 = __importStar(require("react"));
29
29
  const checkbox_1 = require("../checkbox");
30
30
  exports.CheckboxInput = (0, react_2.forwardRef)((props, ref) => {
31
- var _a;
31
+ var _a, _b;
32
+ const generatedId = (0, react_2.useId)();
33
+ const id = (_a = props.id) !== null && _a !== void 0 ? _a : generatedId;
34
+ const errorId = props.isInvalid ? `${id}--error-message` : undefined;
32
35
  return (react_2.default.createElement(react_1.Switch.Group, null,
33
- react_2.default.createElement("div", { className: `uxf-checkbox-input__wrapper ${(_a = props.className) !== null && _a !== void 0 ? _a : ""}` },
36
+ react_2.default.createElement("div", { className: `uxf-checkbox-input__wrapper ${(_b = props.className) !== null && _b !== void 0 ? _b : ""}` },
34
37
  react_2.default.createElement(react_1.Switch, { as: react_2.Fragment, checked: props.value, name: props.name, onChange: props.onChange }, ({ checked }) => (react_2.default.createElement(checkbox_1.Checkbox, { className: "uxf-checkbox-input", id: props.id, indeterminate: props.indeterminate, isDisabled: props.isDisabled, isFocused: props.isFocused, isInvalid: props.isInvalid, isReadOnly: props.isReadOnly, isRequired: props.isRequired, onChange: props.onChange, ref: ref, size: props.size, style: props.style, value: checked }))),
35
- react_2.default.createElement(react_1.Switch.Label, { className: "uxf-checkbox-input__label" }, props.label))));
38
+ react_2.default.createElement(react_1.Switch.Label, { className: "uxf-checkbox-input__label" },
39
+ react_2.default.createElement("span", { className: "uxf-checkbox-input__label--text" }, props.label),
40
+ react_2.default.createElement("span", { id: errorId, className: "uxf-checkbox-input__label--subtitle" }, props.helperText)))));
36
41
  });
37
42
  exports.CheckboxInput.displayName = "UxfUiCheckboxInput";
@@ -1,6 +1,8 @@
1
1
  .uxf-checkbox-input {
2
+ margin-top: 4px;
3
+
2
4
  &__wrapper {
3
- @apply flex items-center justify-between space-x-3;
5
+ @apply flex justify-between space-x-3;
4
6
  }
5
7
 
6
8
  &__label {
@@ -15,6 +17,12 @@
15
17
  }
16
18
  }
17
19
 
20
+ &__label--subtitle {
21
+ color: theme("colors.error.DEFAULT");
22
+ display: block;
23
+ font-size: theme("fontSize.caption");
24
+ }
25
+
18
26
  &.is-disabled,
19
27
  &.is-readonly {
20
28
  & + .uxf-checkbox-input__label {
@@ -22,8 +22,12 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
25
28
  Object.defineProperty(exports, "__esModule", { value: true });
26
29
  exports.Default = void 0;
30
+ const dayjs_1 = __importDefault(require("dayjs"));
27
31
  const react_1 = __importStar(require("react"));
28
32
  const action_1 = require("../utils/action");
29
33
  const date_picker_1 = require("./date-picker");
@@ -31,12 +35,24 @@ exports.default = {
31
35
  title: "UI/DatePicker",
32
36
  component: date_picker_1.DatePicker,
33
37
  };
38
+ const today = (0, dayjs_1.default)();
39
+ const unavailableDates = [
40
+ today.toDate(),
41
+ today.add(5, "days").toDate(),
42
+ today.add(6, "days").toDate(),
43
+ today.add(7, "days").toDate(),
44
+ today.add(11, "days").toDate(),
45
+ today.add(12, "days").toDate(),
46
+ ];
34
47
  function Default() {
35
48
  const [value, setValue] = (0, react_1.useState)(null);
36
49
  const onChange = (0, action_1.action)("onChange", setValue);
37
50
  const onClose = () => null;
38
51
  const testDatePickers = (react_1.default.createElement(react_1.default.Fragment, null,
39
- react_1.default.createElement(date_picker_1.DatePicker, { closePopoverHandler: onClose, onChange: onChange, selectedDate: value })));
52
+ react_1.default.createElement("p", { className: "text-lg" }, "Date picker"),
53
+ react_1.default.createElement(date_picker_1.DatePicker, { closePopoverHandler: onClose, onChange: onChange, selectedDate: value }),
54
+ react_1.default.createElement("p", { className: "text-lg" }, "Date picker with unavailable dates"),
55
+ react_1.default.createElement(date_picker_1.DatePicker, { onChange: onChange, selectedDate: value, unavailableDates: unavailableDates })));
40
56
  return (react_1.default.createElement(react_1.default.Fragment, null,
41
57
  react_1.default.createElement("div", { className: "light max-w-[640px] space-y-4 rounded bg-white p-8" }, testDatePickers),
42
58
  react_1.default.createElement("div", { className: "dark max-w-[640px] space-y-4 rounded bg-gray-900 p-8 text-white" }, testDatePickers)));
@@ -15,6 +15,6 @@ export interface DropzoneInputProps extends FormControlProps<DropzoneFile[] | un
15
15
  noClick?: boolean;
16
16
  noDrag?: boolean;
17
17
  onUploadError?: (err: unknown) => void;
18
- onUploadFile: (file: File, options?: UploadOptions) => Promise<FileResponse>;
18
+ onUploadFile: (file: File | undefined, options?: UploadOptions) => Promise<FileResponse | null>;
19
19
  }
20
20
  export declare const DropzoneInput: React.ForwardRefExoticComponent<DropzoneInputProps & React.RefAttributes<HTMLDivElement>>;
@@ -51,7 +51,7 @@ function progressHandler(progressEvent, file, onValuesChange, values) {
51
51
  }
52
52
  }
53
53
  function fileUploadedHandler(uploadedFile, dropzoneFile, onValuesChange, values) {
54
- if (values) {
54
+ if (values && uploadedFile) {
55
55
  onValuesChange(values.map((f) => f.id === dropzoneFile.id ? { ...uploadedFile, progress: 100, originalFile: f.originalFile } : f));
56
56
  }
57
57
  }
@@ -5,11 +5,11 @@ import { FileInputBaseProps } from "../_file-input-base";
5
5
  export interface FileInputProps extends FileInputBaseProps, Clearable {
6
6
  className?: string;
7
7
  helperText?: ReactNode;
8
- label?: ReactNode;
9
8
  hiddenLabel?: boolean;
9
+ label?: ReactNode;
10
10
  placeholder?: string;
11
- uploadButtonLabel?: string;
12
11
  size?: keyof InputGroupSizes;
12
+ uploadButtonLabel?: string;
13
13
  variant?: keyof InputGroupVariants;
14
14
  }
15
15
  export declare const FileInput: React.ForwardRefExoticComponent<FileInputProps & React.RefAttributes<HTMLInputElement>>;
@@ -53,7 +53,7 @@ exports.FileInput = (0, react_1.forwardRef)((props, ref) => {
53
53
  };
54
54
  return (react_1.default.createElement(form_component_1.FormComponent, { className: (0, cx_1.cx)(input.focused && classes_1.CLASSES.IS_FOCUSED, props.isDisabled && classes_1.CLASSES.IS_DISABLED, props.isInvalid && classes_1.CLASSES.IS_INVALID, props.isReadOnly && classes_1.CLASSES.IS_READONLY), errorId: errorId, form: props.form, helperText: props.helperText, inputId: id, isRequired: props.isRequired, label: props.label, hiddenLabel: props.hiddenLabel },
55
55
  react_1.default.createElement(react_1.default.Fragment, null,
56
- react_1.default.createElement(_file_input_base_1._FileInputBase, { accept: props.accept, "aria-describedby": errorId, "aria-invalid": props.isInvalid, className: `uxf-file-input__input ${(_a = props.className) !== null && _a !== void 0 ? _a : ""}`, form: props.form, id: id, isDisabled: props.isDisabled || isUploading, isInvalid: props.isInvalid, isReadOnly: props.isReadOnly, isRequired: props.isRequired, name: props.name, onBlur: input.onBlur, onChange: props.onChange, onFocus: input.onFocus, onUploadError: props.onUploadError, onUploadFile: onUploadFile, ref: ref, value: props.value }),
56
+ react_1.default.createElement(_file_input_base_1._FileInputBase, { accept: props.accept, "aria-describedby": errorId, "aria-invalid": props.isInvalid, className: `uxf-file-input__input ${(_a = props.className) !== null && _a !== void 0 ? _a : ""}`, form: props.form, id: id, isDisabled: props.isDisabled || isUploading, isInvalid: props.isInvalid, isReadOnly: props.isReadOnly, isRequired: props.isRequired, maxFileSize: props.maxFileSize, name: props.name, onBlur: input.onBlur, onChange: props.onChange, onFocus: input.onFocus, onUploadError: props.onUploadError, onUploadFile: onUploadFile, ref: ref, value: props.value }),
57
57
  react_1.default.createElement("label", { className: (0, cx_1.cx)("uxf-input", "uxf-file-input__label", input.focused && classes_1.CLASSES.IS_FOCUSED, (props.isDisabled || props.isReadOnly) && classes_1.CLASSES.IS_DISABLED, props.isInvalid && classes_1.CLASSES.IS_INVALID, isUploading && classes_1.CLASSES.IS_LOADING, isUploading && "uxf-file-input__label--has-right-addon", `uxf-input--size-${(_b = props.size) !== null && _b !== void 0 ? _b : "default"}`, `uxf-input--variant-${(_c = props.variant) !== null && _c !== void 0 ? _c : "default"}`), htmlFor: id },
58
58
  react_1.default.createElement("div", { className: "uxf-input__left-addon uxf-file-input__label__button" }, !isUploading ? ((_d = props.uploadButtonLabel) !== null && _d !== void 0 ? _d : "Vyberte soubor") : (react_1.default.createElement(loader_1.Loader, { className: "uxf-file-input__label__loader", size: "sm" }))),
59
59
  react_1.default.createElement("div", { className: "uxf-file-input__label__wrapper" },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uxf/ui",
3
- "version": "10.7.0",
3
+ "version": "10.8.1",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -18,7 +18,7 @@
18
18
  "@floating-ui/react": "0.26.0",
19
19
  "@headlessui/react": "1.7.14",
20
20
  "@uxf/core": "10.4.0",
21
- "@uxf/datepicker": "10.0.0",
21
+ "@uxf/datepicker": "10.8.0",
22
22
  "@uxf/styles": "10.4.0",
23
23
  "color2k": "2.0.2",
24
24
  "dayjs": "1.11.10",
@@ -1,2 +1,2 @@
1
1
  import { FileResponse, UploadOptions } from "@uxf/ui/types";
2
- export declare function uploadFile(file: File, uploadOptions?: UploadOptions): Promise<FileResponse>;
2
+ export declare function uploadFile(file: File | undefined, uploadOptions?: UploadOptions): Promise<FileResponse | null>;
@@ -10,37 +10,40 @@ function getRandomUuid() {
10
10
  .join(""))
11
11
  .join("-");
12
12
  }
13
- function uploadFile(file, uploadOptions) {
14
- // axios.put("/api/upload", file, { signal: uploadOptions?.abortController?.signal, onUploadProgress: uploadOptions?.onUploadProgress });
15
- return new Promise((resolve) => {
16
- const time = file.size / 100;
17
- const interval = time / 10;
18
- let loaded = 0;
19
- const intervalTimer = window.setInterval(() => {
20
- var _a, _b;
21
- if ((_a = uploadOptions === null || uploadOptions === void 0 ? void 0 : uploadOptions.abortController) === null || _a === void 0 ? void 0 : _a.signal.aborted) {
13
+ async function uploadFile(file, uploadOptions) {
14
+ if (file) {
15
+ // axios.put("/api/upload", file, { signal: uploadOptions?.abortController?.signal, onUploadProgress: uploadOptions?.onUploadProgress });
16
+ return new Promise((resolve) => {
17
+ const time = file.size / 100;
18
+ const interval = time / 10;
19
+ let loaded = 0;
20
+ const intervalTimer = window.setInterval(() => {
21
+ var _a, _b;
22
+ if ((_a = uploadOptions === null || uploadOptions === void 0 ? void 0 : uploadOptions.abortController) === null || _a === void 0 ? void 0 : _a.signal.aborted) {
23
+ clearInterval(intervalTimer);
24
+ // eslint-disable-next-line @typescript-eslint/no-use-before-define
25
+ clearTimeout(timeoutTimer);
26
+ return;
27
+ }
28
+ loaded += (file.size / time) * interval;
29
+ (_b = uploadOptions === null || uploadOptions === void 0 ? void 0 : uploadOptions.onUploadProgress) === null || _b === void 0 ? void 0 : _b.call(uploadOptions, {
30
+ lengthComputable: true,
31
+ loaded,
32
+ total: file.size,
33
+ });
34
+ }, interval);
35
+ const timeoutTimer = window.setTimeout(() => {
22
36
  clearInterval(intervalTimer);
23
- // eslint-disable-next-line @typescript-eslint/no-use-before-define
24
37
  clearTimeout(timeoutTimer);
25
- return;
26
- }
27
- loaded += (file.size / time) * interval;
28
- (_b = uploadOptions === null || uploadOptions === void 0 ? void 0 : uploadOptions.onUploadProgress) === null || _b === void 0 ? void 0 : _b.call(uploadOptions, {
29
- lengthComputable: true,
30
- loaded,
31
- total: file.size,
32
- });
33
- }, interval);
34
- const timeoutTimer = window.setTimeout(() => {
35
- clearInterval(intervalTimer);
36
- clearTimeout(timeoutTimer);
37
- resolve({
38
- id: Math.round(Math.random() * 100000000),
39
- uuid: getRandomUuid(),
40
- name: file.name,
41
- extension: file.name.split(".").slice(-1).join(""),
42
- });
43
- }, time);
44
- });
38
+ resolve({
39
+ id: Math.round(Math.random() * 100000000),
40
+ uuid: getRandomUuid(),
41
+ name: file.name,
42
+ extension: file.name.split(".").slice(-1).join(""),
43
+ });
44
+ }, time);
45
+ });
46
+ }
47
+ return null;
45
48
  }
46
49
  exports.uploadFile = uploadFile;
@@ -0,0 +1,3 @@
1
+ export declare enum ValidatorExceptions {
2
+ MaxFileSize = "MaxFileSizeException"
3
+ }
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ValidatorExceptions = void 0;
4
+ var ValidatorExceptions;
5
+ (function (ValidatorExceptions) {
6
+ ValidatorExceptions["MaxFileSize"] = "MaxFileSizeException";
7
+ })(ValidatorExceptions || (exports.ValidatorExceptions = ValidatorExceptions = {}));