@sendbird/uikit-react
Version:
Sendbird UIKit for React: A feature-rich and customizable chat UI kit with messaging, channel management, and user authentication.
121 lines (115 loc) • 5.6 kB
JavaScript
'use strict';
var React = require('react');
require('./bundle-jAsAzWpU.js');
require('./bundle-DxZzcGya.js');
var ui_Button = require('../ui/Button.js');
var ui_Modal = require('./bundle-BFmC2V1o.js');
var consts = require('./bundle-DZN-28o5.js');
var index = require('./bundle-CskFALvU.js');
function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'default' in e ? e : { default: e }; }
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
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.default.createElement(ui_Modal.ModalFooter, { type: ui_Button.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 index.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 / consts.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;
};
exports.validateFileCount = validateFileCount;
exports.validateFileSizes = validateFileSizes;
exports.validateFileTypes = validateFileTypes;
exports.validateFilesForUpload = validateFilesForUpload;
//# sourceMappingURL=bundle-Hqqb920S.js.map