@sendbird/uikit-react
Version:
Sendbird UIKit for React: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.
112 lines (109 loc) • 5.33 kB
JavaScript
import React__default from 'react';
import './bundle-Bpofr334.js';
import './bundle-Cdplrrlw.js';
import { ButtonTypes } from '../ui/Button.js';
import { c as ModalFooter } from './bundle-C4anRHWY.js';
import { O as ONE_MiB } from './bundle-JhKiWlXT.js';
import { B as isFileAllowedByAccept } from './bundle-BZSLsKkw.js';
var openAcknowledgeModal = function (_a) {
var openModal = _a.openModal, titleText = _a.titleText, okText = _a.okText;
openModal({
modalProps: { titleText: titleText, hideFooter: true },
childElement: function (_a) {
var closeModal = _a.closeModal;
return (React__default.createElement(ModalFooter, { type: ButtonTypes.PRIMARY, submitText: okText, hideCancelButton: true, onCancel: closeModal, onSubmit: closeModal }));
},
});
};
/**
* Validates that the resulting file count (existing + incoming) does not
* exceed the configured limit. Opens the count-limit modal on failure.
* Returns true when within limit.
*/
var validateFileCount = function (_a) {
var totalCount = _a.totalCount, uikitMultipleFilesMessageLimit = _a.uikitMultipleFilesMessageLimit, openModal = _a.openModal, stringSet = _a.stringSet, logger = _a.logger, _b = _a.logTag, logTag = _b === void 0 ? 'validateFileCount' : _b;
if (totalCount <= uikitMultipleFilesMessageLimit)
return true;
logger === null || logger === void 0 ? void 0 : logger.info("".concat(logTag, ": Cannot upload files more than ").concat(uikitMultipleFilesMessageLimit));
openAcknowledgeModal({
openModal: openModal,
titleText: stringSet.FILE_UPLOAD_NOTIFICATION__COUNT_LIMIT.replace('%d', "".concat(uikitMultipleFilesMessageLimit)),
okText: stringSet.BUTTON__OK,
});
return false;
};
/**
* Validates that every file matches the consumer's acceptableMimeTypes (or
* the UIKit default supported list when unspecified). Opens the unsupported-
* type modal and rejects the whole batch when any file fails.
*/
var validateFileTypes = function (_a) {
var files = _a.files, acceptableMimeTypes = _a.acceptableMimeTypes, openModal = _a.openModal, stringSet = _a.stringSet, logger = _a.logger, _b = _a.logTag, logTag = _b === void 0 ? 'validateFileTypes' : _b;
if (files.every(function (file) { return isFileAllowedByAccept(file, acceptableMimeTypes); }))
return true;
logger === null || logger === void 0 ? void 0 : logger.info("".concat(logTag, ": batch contains unsupported file type(s)"));
openAcknowledgeModal({
openModal: openModal,
titleText: stringSet.FILE_UPLOAD_NOTIFICATION__UNSUPPORTED_FILE_TYPE,
okText: stringSet.BUTTON__OK,
});
return false;
};
/**
* Validates that no file exceeds the configured size limit. Opens the
* size-limit modal on failure. Returns true when all files within limit.
*/
var validateFileSizes = function (_a) {
var files = _a.files, uikitUploadSizeLimit = _a.uikitUploadSizeLimit, openModal = _a.openModal, stringSet = _a.stringSet, logger = _a.logger, _b = _a.logTag, logTag = _b === void 0 ? 'validateFileSizes' : _b;
if (!files.some(function (file) { return file.size > uikitUploadSizeLimit; }))
return true;
logger === null || logger === void 0 ? void 0 : logger.info("".concat(logTag, ": Cannot upload file size exceeding ").concat(uikitUploadSizeLimit));
openAcknowledgeModal({
openModal: openModal,
titleText: stringSet.FILE_UPLOAD_NOTIFICATION__SIZE_LIMIT.replace('%d', "".concat(Math.floor(uikitUploadSizeLimit / ONE_MiB))),
okText: stringSet.BUTTON__OK,
});
return false;
};
/**
* Validates a File[] before upload. Used by the legacy immediate-send hooks.
* Composer staging (usePendingFiles) calls validateFileTypes, validateFileCount,
* and validateFileSizes directly so it can check combined-with-staging count.
*/
var validateFilesForUpload = function (_a) {
var files = _a.files, uikitUploadSizeLimit = _a.uikitUploadSizeLimit, uikitMultipleFilesMessageLimit = _a.uikitMultipleFilesMessageLimit, acceptableMimeTypes = _a.acceptableMimeTypes, openModal = _a.openModal, stringSet = _a.stringSet, logger = _a.logger, _b = _a.logTag, logTag = _b;
if (files.length === 0) {
logger === null || logger === void 0 ? void 0 : logger.warning("".concat(logTag, ": given file list is empty."), { files: files });
return false;
}
if (!validateFileTypes({
files: files,
acceptableMimeTypes: acceptableMimeTypes,
openModal: openModal,
stringSet: stringSet,
logger: logger,
logTag: logTag,
}))
return false;
if (!validateFileCount({
totalCount: files.length,
uikitMultipleFilesMessageLimit: uikitMultipleFilesMessageLimit,
openModal: openModal,
stringSet: stringSet,
logger: logger,
logTag: logTag,
}))
return false;
if (!validateFileSizes({
files: files,
uikitUploadSizeLimit: uikitUploadSizeLimit,
openModal: openModal,
stringSet: stringSet,
logger: logger,
logTag: logTag,
}))
return false;
return true;
};
export { validateFileSizes as a, validateFileTypes as b, validateFilesForUpload as c, validateFileCount as v };
//# sourceMappingURL=bundle-B5xkbY4c.js.map