sceyt-chat-react-uikit 1.9.1-beta.6 → 1.9.1-beta.7

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.
package/index.js CHANGED
@@ -42681,6 +42681,13 @@ var getMediaSizes = function getMediaSizes(file) {
42681
42681
  height: (metadata === null || metadata === void 0 ? void 0 : metadata.szh) || 0
42682
42682
  };
42683
42683
  };
42684
+ var isMediaWiderThanBox = function isMediaWiderThanBox(file, boxRatio) {
42685
+ var _getMediaSizes = getMediaSizes(file),
42686
+ width = _getMediaSizes.width,
42687
+ height = _getMediaSizes.height;
42688
+ if (!width || !height || !boxRatio) return width >= height;
42689
+ return width / height >= boxRatio;
42690
+ };
42684
42691
  var sliderDiagnosticSource = function sliderDiagnosticSource(source) {
42685
42692
  if (!source) return null;
42686
42693
  return source.startsWith('blob:') ? source : source.split(/[?#]/)[0];
@@ -42724,11 +42731,15 @@ var SliderPopup = function SliderPopup(_ref) {
42724
42731
  var _useState8 = React.useState(),
42725
42732
  messageToDelete = _useState8[0],
42726
42733
  setMessageToDelete = _useState8[1];
42734
+ var _useState9 = React.useState(0),
42735
+ mediaBoxRatio = _useState9[0],
42736
+ setMediaBoxRatio = _useState9[1];
42737
+ var sliderBodyRef = React.useRef(null);
42727
42738
  var attachmentLoadingStateForPopup = useSelector(attachmentForPopupLoadingStateSelector);
42728
42739
  var attachmentsForPopupHasPrev = useSelector(attachmentsForPopupHasPrevSelector);
42729
42740
  var attachmentsForPopupHasNext = useSelector(attachmentsForPopupHasNextSelector);
42730
42741
  var attachmentUpdatedMap = useSelector(attachmentUpdatedMapSelector) || {};
42731
- var _useState9 = React.useState(function () {
42742
+ var _useState0 = React.useState(function () {
42732
42743
  if (currentMediaFile.id && currentMediaFile.type === 'image') {
42733
42744
  var imageKey = getAttachmentURLWithVersion(currentMediaFile.url + '_original_image_url');
42734
42745
  if (attachmentUpdatedMap[imageKey]) {
@@ -42738,8 +42749,8 @@ var SliderPopup = function SliderPopup(_ref) {
42738
42749
  }
42739
42750
  return {};
42740
42751
  }),
42741
- itemsLoadedMap = _useState9[0],
42742
- setItemsLoadedMap = _useState9[1];
42752
+ itemsLoadedMap = _useState0[0],
42753
+ setItemsLoadedMap = _useState0[1];
42743
42754
  var prefixUrl = React.useMemo(function () {
42744
42755
  return (currentFile === null || currentFile === void 0 ? void 0 : currentFile.type) === 'image' ? '_original_image_url' : (currentFile === null || currentFile === void 0 ? void 0 : currentFile.type) === 'video' ? '_original_video_url' : '';
42745
42756
  }, [currentFile === null || currentFile === void 0 ? void 0 : currentFile.type]);
@@ -43106,6 +43117,29 @@ var SliderPopup = function SliderPopup(_ref) {
43106
43117
  return item.id === currentFile.id;
43107
43118
  });
43108
43119
  }, [currentFile, popupAttachments]);
43120
+ var isCarouselRendered = activeFileIndex >= 0 && popupAttachments.length > 0;
43121
+ React.useLayoutEffect(function () {
43122
+ var sliderBody = sliderBodyRef.current;
43123
+ if (!isCarouselRendered || !sliderBody) return;
43124
+ var updateMediaBoxRatio = function updateMediaBoxRatio() {
43125
+ var item = sliderBody.querySelector('.custom_carousel_item');
43126
+ if (!item || !item.clientWidth || !item.clientHeight) return;
43127
+ setMediaBoxRatio(item.clientWidth / item.clientHeight);
43128
+ };
43129
+ updateMediaBoxRatio();
43130
+ var ResizeObserverCtor = window.ResizeObserver;
43131
+ if (!ResizeObserverCtor) {
43132
+ window.addEventListener('resize', updateMediaBoxRatio);
43133
+ return function () {
43134
+ return window.removeEventListener('resize', updateMediaBoxRatio);
43135
+ };
43136
+ }
43137
+ var resizeObserver = new ResizeObserverCtor(updateMediaBoxRatio);
43138
+ resizeObserver.observe(sliderBody);
43139
+ return function () {
43140
+ return resizeObserver.disconnect();
43141
+ };
43142
+ }, [isCarouselRendered]);
43109
43143
  React.useEffect(function () {
43110
43144
  var latestCurrentFile = attachmentsList.find(function (file) {
43111
43145
  return file.id === currentFile.id;
@@ -43195,6 +43229,7 @@ var SliderPopup = function SliderPopup(_ref) {
43195
43229
  }, /*#__PURE__*/React__default.createElement(SvgCancel, {
43196
43230
  color: textOnPrimary
43197
43231
  })))), /*#__PURE__*/React__default.createElement(SliderBody, {
43232
+ ref: sliderBodyRef,
43198
43233
  onClick: handleClicks,
43199
43234
  onMouseDown: function onMouseDown(e) {
43200
43235
  if (e.button === 2) {
@@ -43208,7 +43243,7 @@ var SliderPopup = function SliderPopup(_ref) {
43208
43243
  className: 'upload_cont'
43209
43244
  }, /*#__PURE__*/React__default.createElement(UploadingIcon, {
43210
43245
  color: textOnPrimary
43211
- }))), activeFileIndex >= 0 && popupAttachments.length > 0 && (/*#__PURE__*/React__default.createElement(Carousel, {
43246
+ }))), isCarouselRendered && (/*#__PURE__*/React__default.createElement(Carousel, {
43212
43247
  pagination: false,
43213
43248
  className: 'custom_carousel',
43214
43249
  initialActiveIndex: activeFileIndex >= 0 ? activeFileIndex : 0,
@@ -43253,9 +43288,8 @@ var SliderPopup = function SliderPopup(_ref) {
43253
43288
  },
43254
43289
  isRTL: false
43255
43290
  }, popupAttachments.map(function (file) {
43256
- var sizes = getMediaSizes(file);
43257
43291
  return /*#__PURE__*/React__default.createElement(CarouselItem$1, {
43258
- widthBigThenHeight: sizes.width >= sizes.height,
43292
+ widthBigThenHeight: isMediaWiderThanBox(file, mediaBoxRatio),
43259
43293
  className: 'custom_carousel_item',
43260
43294
  key: file.id,
43261
43295
  draggable: false,
package/index.modern.js CHANGED
@@ -42661,6 +42661,13 @@ var getMediaSizes = function getMediaSizes(file) {
42661
42661
  height: (metadata === null || metadata === void 0 ? void 0 : metadata.szh) || 0
42662
42662
  };
42663
42663
  };
42664
+ var isMediaWiderThanBox = function isMediaWiderThanBox(file, boxRatio) {
42665
+ var _getMediaSizes = getMediaSizes(file),
42666
+ width = _getMediaSizes.width,
42667
+ height = _getMediaSizes.height;
42668
+ if (!width || !height || !boxRatio) return width >= height;
42669
+ return width / height >= boxRatio;
42670
+ };
42664
42671
  var sliderDiagnosticSource = function sliderDiagnosticSource(source) {
42665
42672
  if (!source) return null;
42666
42673
  return source.startsWith('blob:') ? source : source.split(/[?#]/)[0];
@@ -42704,11 +42711,15 @@ var SliderPopup = function SliderPopup(_ref) {
42704
42711
  var _useState8 = useState(),
42705
42712
  messageToDelete = _useState8[0],
42706
42713
  setMessageToDelete = _useState8[1];
42714
+ var _useState9 = useState(0),
42715
+ mediaBoxRatio = _useState9[0],
42716
+ setMediaBoxRatio = _useState9[1];
42717
+ var sliderBodyRef = useRef(null);
42707
42718
  var attachmentLoadingStateForPopup = useSelector(attachmentForPopupLoadingStateSelector);
42708
42719
  var attachmentsForPopupHasPrev = useSelector(attachmentsForPopupHasPrevSelector);
42709
42720
  var attachmentsForPopupHasNext = useSelector(attachmentsForPopupHasNextSelector);
42710
42721
  var attachmentUpdatedMap = useSelector(attachmentUpdatedMapSelector) || {};
42711
- var _useState9 = useState(function () {
42722
+ var _useState0 = useState(function () {
42712
42723
  if (currentMediaFile.id && currentMediaFile.type === 'image') {
42713
42724
  var imageKey = getAttachmentURLWithVersion(currentMediaFile.url + '_original_image_url');
42714
42725
  if (attachmentUpdatedMap[imageKey]) {
@@ -42718,8 +42729,8 @@ var SliderPopup = function SliderPopup(_ref) {
42718
42729
  }
42719
42730
  return {};
42720
42731
  }),
42721
- itemsLoadedMap = _useState9[0],
42722
- setItemsLoadedMap = _useState9[1];
42732
+ itemsLoadedMap = _useState0[0],
42733
+ setItemsLoadedMap = _useState0[1];
42723
42734
  var prefixUrl = useMemo(function () {
42724
42735
  return (currentFile === null || currentFile === void 0 ? void 0 : currentFile.type) === 'image' ? '_original_image_url' : (currentFile === null || currentFile === void 0 ? void 0 : currentFile.type) === 'video' ? '_original_video_url' : '';
42725
42736
  }, [currentFile === null || currentFile === void 0 ? void 0 : currentFile.type]);
@@ -43086,6 +43097,29 @@ var SliderPopup = function SliderPopup(_ref) {
43086
43097
  return item.id === currentFile.id;
43087
43098
  });
43088
43099
  }, [currentFile, popupAttachments]);
43100
+ var isCarouselRendered = activeFileIndex >= 0 && popupAttachments.length > 0;
43101
+ useLayoutEffect(function () {
43102
+ var sliderBody = sliderBodyRef.current;
43103
+ if (!isCarouselRendered || !sliderBody) return;
43104
+ var updateMediaBoxRatio = function updateMediaBoxRatio() {
43105
+ var item = sliderBody.querySelector('.custom_carousel_item');
43106
+ if (!item || !item.clientWidth || !item.clientHeight) return;
43107
+ setMediaBoxRatio(item.clientWidth / item.clientHeight);
43108
+ };
43109
+ updateMediaBoxRatio();
43110
+ var ResizeObserverCtor = window.ResizeObserver;
43111
+ if (!ResizeObserverCtor) {
43112
+ window.addEventListener('resize', updateMediaBoxRatio);
43113
+ return function () {
43114
+ return window.removeEventListener('resize', updateMediaBoxRatio);
43115
+ };
43116
+ }
43117
+ var resizeObserver = new ResizeObserverCtor(updateMediaBoxRatio);
43118
+ resizeObserver.observe(sliderBody);
43119
+ return function () {
43120
+ return resizeObserver.disconnect();
43121
+ };
43122
+ }, [isCarouselRendered]);
43089
43123
  useEffect(function () {
43090
43124
  var latestCurrentFile = attachmentsList.find(function (file) {
43091
43125
  return file.id === currentFile.id;
@@ -43175,6 +43209,7 @@ var SliderPopup = function SliderPopup(_ref) {
43175
43209
  }, /*#__PURE__*/React__default.createElement(SvgCancel, {
43176
43210
  color: textOnPrimary
43177
43211
  })))), /*#__PURE__*/React__default.createElement(SliderBody, {
43212
+ ref: sliderBodyRef,
43178
43213
  onClick: handleClicks,
43179
43214
  onMouseDown: function onMouseDown(e) {
43180
43215
  if (e.button === 2) {
@@ -43188,7 +43223,7 @@ var SliderPopup = function SliderPopup(_ref) {
43188
43223
  className: 'upload_cont'
43189
43224
  }, /*#__PURE__*/React__default.createElement(UploadingIcon, {
43190
43225
  color: textOnPrimary
43191
- }))), activeFileIndex >= 0 && popupAttachments.length > 0 && (/*#__PURE__*/React__default.createElement(Carousel, {
43226
+ }))), isCarouselRendered && (/*#__PURE__*/React__default.createElement(Carousel, {
43192
43227
  pagination: false,
43193
43228
  className: 'custom_carousel',
43194
43229
  initialActiveIndex: activeFileIndex >= 0 ? activeFileIndex : 0,
@@ -43233,9 +43268,8 @@ var SliderPopup = function SliderPopup(_ref) {
43233
43268
  },
43234
43269
  isRTL: false
43235
43270
  }, popupAttachments.map(function (file) {
43236
- var sizes = getMediaSizes(file);
43237
43271
  return /*#__PURE__*/React__default.createElement(CarouselItem$1, {
43238
- widthBigThenHeight: sizes.width >= sizes.height,
43272
+ widthBigThenHeight: isMediaWiderThanBox(file, mediaBoxRatio),
43239
43273
  className: 'custom_carousel_item',
43240
43274
  key: file.id,
43241
43275
  draggable: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sceyt-chat-react-uikit",
3
- "version": "1.9.1-beta.6",
3
+ "version": "1.9.1-beta.7",
4
4
  "description": "Interactive React UI Components for Sceyt Chat.",
5
5
  "author": "Sceyt",
6
6
  "license": "MIT",