sceyt-chat-react-uikit 1.8.9-beta.16 → 1.8.9-beta.17

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.
@@ -1 +1,11 @@
1
1
  export declare const hasSendableTextOrPoll: (messageText: string, isPoll: boolean) => boolean;
2
+ export declare const DEFAULT_MEDIA_EXTENSIONS: string[];
3
+ export declare const isDefaultSupportedMediaMimeType: (mimeType: string) => boolean;
4
+ declare type MediaAttachmentValidationOptions = {
5
+ allowedExtensions?: string[];
6
+ sizeLimitKb?: number;
7
+ invalidTypeMessage?: string;
8
+ sizeLimitMessage?: string;
9
+ };
10
+ export declare const getMediaAttachmentValidationError: (file: Pick<File, 'name' | 'size'>, { allowedExtensions, sizeLimitKb, invalidTypeMessage, sizeLimitMessage }: MediaAttachmentValidationOptions) => string | null;
11
+ export {};
package/index.js CHANGED
@@ -48851,6 +48851,33 @@ var createMessageMarkerBatcher = function createMessageMarkerBatcher(_ref) {
48851
48851
  };
48852
48852
  };
48853
48853
 
48854
+ var hasSendableTextOrPoll = function hasSendableTextOrPoll(messageText, isPoll) {
48855
+ return Boolean(messageText.trim() || isPoll);
48856
+ };
48857
+ var DEFAULT_MEDIA_EXTENSIONS = ['jpg', 'jpeg', 'png', 'gif', 'mp4', 'mov', 'avi', 'wmv', 'flv', 'webm', 'jfif'];
48858
+ var DEFAULT_MEDIA_MIME_TYPES = new Set(['image/jpeg', 'image/png', 'image/gif', 'image/jfif', 'image/pjpeg', 'video/mp4', 'video/quicktime', 'video/x-msvideo', 'video/avi', 'video/x-ms-wmv', 'video/x-flv', 'video/webm']);
48859
+ var isDefaultSupportedMediaMimeType = function isDefaultSupportedMediaMimeType(mimeType) {
48860
+ return DEFAULT_MEDIA_MIME_TYPES.has(mimeType.toLowerCase());
48861
+ };
48862
+ var getMediaAttachmentValidationError = function getMediaAttachmentValidationError(file, _ref) {
48863
+ var _file$name$split$pop;
48864
+ var allowedExtensions = _ref.allowedExtensions,
48865
+ sizeLimitKb = _ref.sizeLimitKb,
48866
+ invalidTypeMessage = _ref.invalidTypeMessage,
48867
+ sizeLimitMessage = _ref.sizeLimitMessage;
48868
+ if (sizeLimitKb && file.size / 1024 > sizeLimitKb) {
48869
+ return sizeLimitMessage != null ? sizeLimitMessage : "File size exceeds the limit of " + sizeLimitKb + " KB.";
48870
+ }
48871
+ var supportedExtensions = (allowedExtensions !== null && allowedExtensions !== void 0 && allowedExtensions.length ? allowedExtensions : DEFAULT_MEDIA_EXTENSIONS).map(function (extension) {
48872
+ return extension.replace(/^\./, '').toLowerCase();
48873
+ });
48874
+ var extension = (_file$name$split$pop = file.name.split('.').pop()) === null || _file$name$split$pop === void 0 ? void 0 : _file$name$split$pop.toLowerCase();
48875
+ if (!extension || !supportedExtensions.includes(extension)) {
48876
+ return invalidTypeMessage != null ? invalidTypeMessage : "Invalid file type. Allowed extensions are: " + supportedExtensions.join(', ') + ".";
48877
+ }
48878
+ return null;
48879
+ };
48880
+
48854
48881
  var _templateObject$P, _templateObject2$K, _templateObject3$C, _templateObject4$x, _templateObject5$s, _templateObject6$o, _templateObject7$m, _templateObject8$k, _templateObject9$i, _templateObject0$h, _templateObject1$e, _templateObject10$b, _templateObject11$8;
48855
48882
  var MessageList = function MessageList(_ref) {
48856
48883
  var _scrollRef$current, _scrollRef$current$of, _scrollRef$current2;
@@ -49237,8 +49264,7 @@ var MessageList = function MessageList(_ref) {
49237
49264
  } else {
49238
49265
  var fileList = Array.from(e.dataTransfer.items);
49239
49266
  var hasMedia = fileList.some(function (item) {
49240
- var fileType = item.type.split('/')[0];
49241
- return fileType === 'image' || fileType === 'video';
49267
+ return isDefaultSupportedMediaMimeType(item.type);
49242
49268
  });
49243
49269
  filesType = hasMedia ? 'media' : 'file';
49244
49270
  }
@@ -53198,10 +53224,6 @@ var SettingItem = styled__default.div(_templateObject9$j || (_templateObject9$j
53198
53224
  return props.color;
53199
53225
  });
53200
53226
 
53201
- var hasSendableTextOrPoll = function hasSendableTextOrPoll(messageText, isPoll) {
53202
- return Boolean(messageText.trim() || isPoll);
53203
- };
53204
-
53205
53227
  var _templateObject$W, _templateObject2$R, _templateObject3$I, _templateObject4$C, _templateObject5$x, _templateObject6$t, _templateObject7$q, _templateObject8$n, _templateObject9$k, _templateObject0$i, _templateObject1$f, _templateObject10$c, _templateObject11$9, _templateObject12$7, _templateObject13$6, _templateObject14$5, _templateObject15$3, _templateObject16$2, _templateObject17$2, _templateObject18$2, _templateObject19$2, _templateObject20$2, _templateObject21$2, _templateObject22$1, _templateObject23$1, _templateObject24$1, _templateObject25$1, _templateObject26$1, _templateObject27$1, _templateObject28$1, _templateObject29$1, _templateObject30$1, _templateObject31$1, _templateObject32$1, _templateObject33$1, _templateObject34$1, _templateObject35$1, _templateObject36$1, _templateObject37$1, _templateObject38$1, _templateObject39$1, _templateObject40$1, _templateObject41$1, _templateObject42, _templateObject43, _templateObject44, _templateObject45, _templateObject46;
53206
53228
  function AutoFocusPlugin(_ref) {
53207
53229
  var messageForReply = _ref.messageForReply;
@@ -54073,6 +54095,14 @@ var SendMessageInput = function SendMessageInput(_ref3) {
54073
54095
  setUploadErrorMessage('');
54074
54096
  }, 3000);
54075
54097
  };
54098
+ var validateMediaAttachment = function validateMediaAttachment(file) {
54099
+ return getMediaAttachmentValidationError(file, {
54100
+ allowedExtensions: allowedMediaExtensions,
54101
+ sizeLimitKb: mediaAttachmentSizeLimit,
54102
+ invalidTypeMessage: allowedMediaExtensionsErrorMessage,
54103
+ sizeLimitMessage: attachmentSizeLimitErrorMessage
54104
+ });
54105
+ };
54076
54106
  var handleFileUpload = function handleFileUpload(e) {
54077
54107
  var isMediaAttachment = e.target.accept === mediaExtensions;
54078
54108
  var fileList = Object.values(e.target.files);
@@ -54089,27 +54119,12 @@ var SendMessageInput = function SendMessageInput(_ref3) {
54089
54119
  }
54090
54120
  filesToProcess.forEach(function (file) {
54091
54121
  try {
54092
- var allowUpload = true;
54093
- var errorMessage = '';
54094
- if (isMediaAttachment) {
54095
- if (mediaAttachmentSizeLimit && file.size / 1024 > mediaAttachmentSizeLimit) {
54096
- allowUpload = false;
54097
- errorMessage = attachmentSizeLimitErrorMessage != null ? attachmentSizeLimitErrorMessage : "File size exceeds the limit of " + mediaAttachmentSizeLimit + " KB.";
54098
- }
54099
- if (allowedMediaExtensions !== null && allowedMediaExtensions !== void 0 && allowedMediaExtensions.length) {
54100
- var fileName = file.name;
54101
- var fileExtension = fileName.split('.').pop().toLowerCase();
54102
- if (!allowedMediaExtensions.includes(fileExtension)) {
54103
- allowUpload = false;
54104
- errorMessage = allowedMediaExtensionsErrorMessage != null ? allowedMediaExtensionsErrorMessage : "Invalid file type. Allowed extensions are: " + allowedMediaExtensions.join(', ') + ".";
54105
- }
54106
- }
54107
- }
54122
+ var validationError = isMediaAttachment ? validateMediaAttachment(file) : null;
54108
54123
  var _temp8 = function () {
54109
- if (allowUpload) {
54124
+ if (!validationError) {
54110
54125
  return Promise.resolve(handleAddAttachmentWithViewOnceCheck(file, isMediaAttachment)).then(function () {});
54111
54126
  } else {
54112
- showFileUploadError(errorMessage);
54127
+ showFileUploadError(validationError);
54113
54128
  }
54114
54129
  }();
54115
54130
  return Promise.resolve(_temp8 && _temp8.then ? _temp8.then(function () {}) : void 0);
@@ -54149,25 +54164,12 @@ var SendMessageInput = function SendMessageInput(_ref3) {
54149
54164
  }
54150
54165
  filesToProcess.forEach(function (file) {
54151
54166
  try {
54152
- var allowUpload = true;
54153
- var errorMessage = '';
54154
- if (mediaAttachmentSizeLimit && file.size / 1024 > mediaAttachmentSizeLimit) {
54155
- allowUpload = false;
54156
- errorMessage = attachmentSizeLimitErrorMessage != null ? attachmentSizeLimitErrorMessage : "File size exceeds the limit of " + mediaAttachmentSizeLimit + " KB.";
54157
- }
54158
- if (allowedMediaExtensions !== null && allowedMediaExtensions !== void 0 && allowedMediaExtensions.length) {
54159
- var fileName = file.name;
54160
- var fileExtension = fileName.split('.').pop().toLowerCase();
54161
- if (!allowedMediaExtensions.includes(fileExtension)) {
54162
- allowUpload = false;
54163
- errorMessage = allowedMediaExtensionsErrorMessage != null ? allowedMediaExtensionsErrorMessage : "Invalid file type. Allowed extensions are: " + allowedMediaExtensions.join(', ') + ".";
54164
- }
54165
- }
54167
+ var validationError = validateMediaAttachment(file);
54166
54168
  var _temp9 = function () {
54167
- if (allowUpload) {
54169
+ if (!validationError) {
54168
54170
  return Promise.resolve(handleAddAttachmentWithViewOnceCheck(file, true)).then(function () {});
54169
54171
  } else {
54170
- showFileUploadError(errorMessage);
54172
+ showFileUploadError(validationError);
54171
54173
  }
54172
54174
  }();
54173
54175
  return Promise.resolve(_temp9 && _temp9.then ? _temp9.then(function () {}) : void 0);
@@ -54503,27 +54505,12 @@ var SendMessageInput = function SendMessageInput(_ref3) {
54503
54505
  var isMediaAttachment = draggedAttachments[0].attachmentType === 'media';
54504
54506
  filesToProcess.forEach(function (file) {
54505
54507
  try {
54506
- var allowUpload = true;
54507
- var errorMessage = '';
54508
- if (isMediaAttachment) {
54509
- if (mediaAttachmentSizeLimit && file.size / 1024 > mediaAttachmentSizeLimit) {
54510
- allowUpload = false;
54511
- errorMessage = attachmentSizeLimitErrorMessage != null ? attachmentSizeLimitErrorMessage : "File size exceeds the limit of " + mediaAttachmentSizeLimit + " KB.";
54512
- }
54513
- if (allowedMediaExtensions !== null && allowedMediaExtensions !== void 0 && allowedMediaExtensions.length) {
54514
- var fileName = file.name;
54515
- var fileExtension = fileName.split('.').pop().toLowerCase();
54516
- if (!allowedMediaExtensions.includes(fileExtension)) {
54517
- allowUpload = false;
54518
- errorMessage = allowedMediaExtensionsErrorMessage != null ? allowedMediaExtensionsErrorMessage : "Invalid file type. Allowed extensions are: " + allowedMediaExtensions.join(', ') + ".";
54519
- }
54520
- }
54521
- }
54508
+ var validationError = isMediaAttachment ? validateMediaAttachment(file) : null;
54522
54509
  var _temp19 = function () {
54523
- if (allowUpload) {
54510
+ if (!validationError) {
54524
54511
  return Promise.resolve(handleAddAttachmentWithViewOnceCheck(file, isMediaAttachment)).then(function () {});
54525
54512
  } else {
54526
- showFileUploadError(errorMessage);
54513
+ showFileUploadError(validationError);
54527
54514
  }
54528
54515
  }();
54529
54516
  return Promise.resolve(_temp19 && _temp19.then ? _temp19.then(function () {}) : void 0);
package/index.modern.js CHANGED
@@ -48831,6 +48831,33 @@ var createMessageMarkerBatcher = function createMessageMarkerBatcher(_ref) {
48831
48831
  };
48832
48832
  };
48833
48833
 
48834
+ var hasSendableTextOrPoll = function hasSendableTextOrPoll(messageText, isPoll) {
48835
+ return Boolean(messageText.trim() || isPoll);
48836
+ };
48837
+ var DEFAULT_MEDIA_EXTENSIONS = ['jpg', 'jpeg', 'png', 'gif', 'mp4', 'mov', 'avi', 'wmv', 'flv', 'webm', 'jfif'];
48838
+ var DEFAULT_MEDIA_MIME_TYPES = new Set(['image/jpeg', 'image/png', 'image/gif', 'image/jfif', 'image/pjpeg', 'video/mp4', 'video/quicktime', 'video/x-msvideo', 'video/avi', 'video/x-ms-wmv', 'video/x-flv', 'video/webm']);
48839
+ var isDefaultSupportedMediaMimeType = function isDefaultSupportedMediaMimeType(mimeType) {
48840
+ return DEFAULT_MEDIA_MIME_TYPES.has(mimeType.toLowerCase());
48841
+ };
48842
+ var getMediaAttachmentValidationError = function getMediaAttachmentValidationError(file, _ref) {
48843
+ var _file$name$split$pop;
48844
+ var allowedExtensions = _ref.allowedExtensions,
48845
+ sizeLimitKb = _ref.sizeLimitKb,
48846
+ invalidTypeMessage = _ref.invalidTypeMessage,
48847
+ sizeLimitMessage = _ref.sizeLimitMessage;
48848
+ if (sizeLimitKb && file.size / 1024 > sizeLimitKb) {
48849
+ return sizeLimitMessage != null ? sizeLimitMessage : "File size exceeds the limit of " + sizeLimitKb + " KB.";
48850
+ }
48851
+ var supportedExtensions = (allowedExtensions !== null && allowedExtensions !== void 0 && allowedExtensions.length ? allowedExtensions : DEFAULT_MEDIA_EXTENSIONS).map(function (extension) {
48852
+ return extension.replace(/^\./, '').toLowerCase();
48853
+ });
48854
+ var extension = (_file$name$split$pop = file.name.split('.').pop()) === null || _file$name$split$pop === void 0 ? void 0 : _file$name$split$pop.toLowerCase();
48855
+ if (!extension || !supportedExtensions.includes(extension)) {
48856
+ return invalidTypeMessage != null ? invalidTypeMessage : "Invalid file type. Allowed extensions are: " + supportedExtensions.join(', ') + ".";
48857
+ }
48858
+ return null;
48859
+ };
48860
+
48834
48861
  var _templateObject$P, _templateObject2$K, _templateObject3$C, _templateObject4$x, _templateObject5$s, _templateObject6$o, _templateObject7$m, _templateObject8$k, _templateObject9$i, _templateObject0$h, _templateObject1$e, _templateObject10$b, _templateObject11$8;
48835
48862
  var MessageList = function MessageList(_ref) {
48836
48863
  var _scrollRef$current, _scrollRef$current$of, _scrollRef$current2;
@@ -49217,8 +49244,7 @@ var MessageList = function MessageList(_ref) {
49217
49244
  } else {
49218
49245
  var fileList = Array.from(e.dataTransfer.items);
49219
49246
  var hasMedia = fileList.some(function (item) {
49220
- var fileType = item.type.split('/')[0];
49221
- return fileType === 'image' || fileType === 'video';
49247
+ return isDefaultSupportedMediaMimeType(item.type);
49222
49248
  });
49223
49249
  filesType = hasMedia ? 'media' : 'file';
49224
49250
  }
@@ -53178,10 +53204,6 @@ var SettingItem = styled.div(_templateObject9$j || (_templateObject9$j = _tagged
53178
53204
  return props.color;
53179
53205
  });
53180
53206
 
53181
- var hasSendableTextOrPoll = function hasSendableTextOrPoll(messageText, isPoll) {
53182
- return Boolean(messageText.trim() || isPoll);
53183
- };
53184
-
53185
53207
  var _templateObject$W, _templateObject2$R, _templateObject3$I, _templateObject4$C, _templateObject5$x, _templateObject6$t, _templateObject7$q, _templateObject8$n, _templateObject9$k, _templateObject0$i, _templateObject1$f, _templateObject10$c, _templateObject11$9, _templateObject12$7, _templateObject13$6, _templateObject14$5, _templateObject15$3, _templateObject16$2, _templateObject17$2, _templateObject18$2, _templateObject19$2, _templateObject20$2, _templateObject21$2, _templateObject22$1, _templateObject23$1, _templateObject24$1, _templateObject25$1, _templateObject26$1, _templateObject27$1, _templateObject28$1, _templateObject29$1, _templateObject30$1, _templateObject31$1, _templateObject32$1, _templateObject33$1, _templateObject34$1, _templateObject35$1, _templateObject36$1, _templateObject37$1, _templateObject38$1, _templateObject39$1, _templateObject40$1, _templateObject41$1, _templateObject42, _templateObject43, _templateObject44, _templateObject45, _templateObject46;
53186
53208
  function AutoFocusPlugin(_ref) {
53187
53209
  var messageForReply = _ref.messageForReply;
@@ -54053,6 +54075,14 @@ var SendMessageInput = function SendMessageInput(_ref3) {
54053
54075
  setUploadErrorMessage('');
54054
54076
  }, 3000);
54055
54077
  };
54078
+ var validateMediaAttachment = function validateMediaAttachment(file) {
54079
+ return getMediaAttachmentValidationError(file, {
54080
+ allowedExtensions: allowedMediaExtensions,
54081
+ sizeLimitKb: mediaAttachmentSizeLimit,
54082
+ invalidTypeMessage: allowedMediaExtensionsErrorMessage,
54083
+ sizeLimitMessage: attachmentSizeLimitErrorMessage
54084
+ });
54085
+ };
54056
54086
  var handleFileUpload = function handleFileUpload(e) {
54057
54087
  var isMediaAttachment = e.target.accept === mediaExtensions;
54058
54088
  var fileList = Object.values(e.target.files);
@@ -54069,27 +54099,12 @@ var SendMessageInput = function SendMessageInput(_ref3) {
54069
54099
  }
54070
54100
  filesToProcess.forEach(function (file) {
54071
54101
  try {
54072
- var allowUpload = true;
54073
- var errorMessage = '';
54074
- if (isMediaAttachment) {
54075
- if (mediaAttachmentSizeLimit && file.size / 1024 > mediaAttachmentSizeLimit) {
54076
- allowUpload = false;
54077
- errorMessage = attachmentSizeLimitErrorMessage != null ? attachmentSizeLimitErrorMessage : "File size exceeds the limit of " + mediaAttachmentSizeLimit + " KB.";
54078
- }
54079
- if (allowedMediaExtensions !== null && allowedMediaExtensions !== void 0 && allowedMediaExtensions.length) {
54080
- var fileName = file.name;
54081
- var fileExtension = fileName.split('.').pop().toLowerCase();
54082
- if (!allowedMediaExtensions.includes(fileExtension)) {
54083
- allowUpload = false;
54084
- errorMessage = allowedMediaExtensionsErrorMessage != null ? allowedMediaExtensionsErrorMessage : "Invalid file type. Allowed extensions are: " + allowedMediaExtensions.join(', ') + ".";
54085
- }
54086
- }
54087
- }
54102
+ var validationError = isMediaAttachment ? validateMediaAttachment(file) : null;
54088
54103
  var _temp8 = function () {
54089
- if (allowUpload) {
54104
+ if (!validationError) {
54090
54105
  return Promise.resolve(handleAddAttachmentWithViewOnceCheck(file, isMediaAttachment)).then(function () {});
54091
54106
  } else {
54092
- showFileUploadError(errorMessage);
54107
+ showFileUploadError(validationError);
54093
54108
  }
54094
54109
  }();
54095
54110
  return Promise.resolve(_temp8 && _temp8.then ? _temp8.then(function () {}) : void 0);
@@ -54129,25 +54144,12 @@ var SendMessageInput = function SendMessageInput(_ref3) {
54129
54144
  }
54130
54145
  filesToProcess.forEach(function (file) {
54131
54146
  try {
54132
- var allowUpload = true;
54133
- var errorMessage = '';
54134
- if (mediaAttachmentSizeLimit && file.size / 1024 > mediaAttachmentSizeLimit) {
54135
- allowUpload = false;
54136
- errorMessage = attachmentSizeLimitErrorMessage != null ? attachmentSizeLimitErrorMessage : "File size exceeds the limit of " + mediaAttachmentSizeLimit + " KB.";
54137
- }
54138
- if (allowedMediaExtensions !== null && allowedMediaExtensions !== void 0 && allowedMediaExtensions.length) {
54139
- var fileName = file.name;
54140
- var fileExtension = fileName.split('.').pop().toLowerCase();
54141
- if (!allowedMediaExtensions.includes(fileExtension)) {
54142
- allowUpload = false;
54143
- errorMessage = allowedMediaExtensionsErrorMessage != null ? allowedMediaExtensionsErrorMessage : "Invalid file type. Allowed extensions are: " + allowedMediaExtensions.join(', ') + ".";
54144
- }
54145
- }
54147
+ var validationError = validateMediaAttachment(file);
54146
54148
  var _temp9 = function () {
54147
- if (allowUpload) {
54149
+ if (!validationError) {
54148
54150
  return Promise.resolve(handleAddAttachmentWithViewOnceCheck(file, true)).then(function () {});
54149
54151
  } else {
54150
- showFileUploadError(errorMessage);
54152
+ showFileUploadError(validationError);
54151
54153
  }
54152
54154
  }();
54153
54155
  return Promise.resolve(_temp9 && _temp9.then ? _temp9.then(function () {}) : void 0);
@@ -54483,27 +54485,12 @@ var SendMessageInput = function SendMessageInput(_ref3) {
54483
54485
  var isMediaAttachment = draggedAttachments[0].attachmentType === 'media';
54484
54486
  filesToProcess.forEach(function (file) {
54485
54487
  try {
54486
- var allowUpload = true;
54487
- var errorMessage = '';
54488
- if (isMediaAttachment) {
54489
- if (mediaAttachmentSizeLimit && file.size / 1024 > mediaAttachmentSizeLimit) {
54490
- allowUpload = false;
54491
- errorMessage = attachmentSizeLimitErrorMessage != null ? attachmentSizeLimitErrorMessage : "File size exceeds the limit of " + mediaAttachmentSizeLimit + " KB.";
54492
- }
54493
- if (allowedMediaExtensions !== null && allowedMediaExtensions !== void 0 && allowedMediaExtensions.length) {
54494
- var fileName = file.name;
54495
- var fileExtension = fileName.split('.').pop().toLowerCase();
54496
- if (!allowedMediaExtensions.includes(fileExtension)) {
54497
- allowUpload = false;
54498
- errorMessage = allowedMediaExtensionsErrorMessage != null ? allowedMediaExtensionsErrorMessage : "Invalid file type. Allowed extensions are: " + allowedMediaExtensions.join(', ') + ".";
54499
- }
54500
- }
54501
- }
54488
+ var validationError = isMediaAttachment ? validateMediaAttachment(file) : null;
54502
54489
  var _temp19 = function () {
54503
- if (allowUpload) {
54490
+ if (!validationError) {
54504
54491
  return Promise.resolve(handleAddAttachmentWithViewOnceCheck(file, isMediaAttachment)).then(function () {});
54505
54492
  } else {
54506
- showFileUploadError(errorMessage);
54493
+ showFileUploadError(validationError);
54507
54494
  }
54508
54495
  }();
54509
54496
  return Promise.resolve(_temp19 && _temp19.then ? _temp19.then(function () {}) : void 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sceyt-chat-react-uikit",
3
- "version": "1.8.9-beta.16",
3
+ "version": "1.8.9-beta.17",
4
4
  "description": "Interactive React UI Components for Sceyt Chat.",
5
5
  "author": "Sceyt",
6
6
  "license": "MIT",