@websolutespa/bom-mixer-ui 1.7.13 → 1.7.15

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # @websolutespa/bom-mixer-ui
2
2
 
3
+ ## 1.7.15
4
+
5
+ ### Patch Changes
6
+
7
+ - Fixing: MediaImage getMediaRatio
8
+ - Updated dependencies
9
+ - @websolutespa/bom-mixer-models@1.7.9
10
+
11
+ ## 1.7.14
12
+
13
+ ### Patch Changes
14
+
15
+ - Modified: Media width & height style support & source image size limits
16
+
3
17
  ## 1.7.13
4
18
 
5
19
  ### Patch Changes
package/dist/cjs/index.js CHANGED
@@ -4380,7 +4380,6 @@ function isMediaSizeVariants(item) {
4380
4380
  }
4381
4381
  const StyledMediaImage = styled__default.default.img`
4382
4382
  max-width: 100%;
4383
- // height: auto;
4384
4383
  user-select: none;
4385
4384
  color: transparent;
4386
4385
  `;
@@ -4402,28 +4401,29 @@ const MediaImage = _a => {
4402
4401
  'image-svg': isSVG(props.src)
4403
4402
  });
4404
4403
  const imageProps = getImageProps(props, theme.mediaQuery);
4405
- const onLoad = () => {
4406
- if (typeof onLoaded === 'function') {
4407
- onLoaded(imageRef);
4408
- }
4409
- };
4410
4404
  React.useEffect(() => {
4411
4405
  if (imageRef.current && canLoad) {
4412
- if (imageRef.current.complete) {
4406
+ const image = imageRef.current;
4407
+ if (image.complete) {
4413
4408
  if (typeof onLoaded === 'function') {
4414
4409
  onLoaded(imageRef);
4415
4410
  }
4416
4411
  } else {
4417
- imageRef.current.addEventListener('load', onLoad);
4412
+ const onLoad = () => {
4413
+ if (typeof onLoaded === 'function') {
4414
+ onLoaded(imageRef);
4415
+ }
4416
+ };
4417
+ image.addEventListener('load', onLoad);
4418
4418
  return () => {
4419
- if (imageRef.current) {
4420
- imageRef.current.removeEventListener('load', onLoad);
4419
+ if (image) {
4420
+ image.removeEventListener('load', onLoad);
4421
4421
  }
4422
4422
  };
4423
4423
  }
4424
4424
  }
4425
4425
  return () => {};
4426
- }, [imageRef, canLoad]);
4426
+ }, [canLoad, onLoaded]);
4427
4427
  return jsxRuntime.jsx(StyledMediaImage, Object.assign({
4428
4428
  ref: imageRef
4429
4429
  }, canLoad ? imageProps : undefined, {
@@ -4432,25 +4432,30 @@ const MediaImage = _a => {
4432
4432
  draggable: false
4433
4433
  }));
4434
4434
  };
4435
- function getMediaSizes(mediaQuery, ratio, size) {
4436
- // console.log('getMediaSizes', size, ratio);
4435
+ function getMediaSizes(mediaQuery, ratio, size, maxWidth, maxHeight) {
4436
+ if (maxWidth === void 0) {
4437
+ maxWidth = Number.POSITIVE_INFINITY;
4438
+ }
4439
+ if (maxHeight === void 0) {
4440
+ maxHeight = Number.POSITIVE_INFINITY;
4441
+ }
4442
+ // console.log('getMediaSizes', mediaQuery, ratio, size, maxWidth, maxHeight);
4443
+ let sizes = [];
4437
4444
  if (size) {
4438
4445
  if (typeof size === 'number') {
4439
4446
  const s = size;
4440
4447
  // console.log('typeof size === \'number\'', size);
4441
- const sizes = Object.entries(ratio).map(_ref2 => {
4448
+ sizes = Object.entries(ratio).map(_ref2 => {
4442
4449
  let [k, v] = _ref2;
4443
4450
  const w = IMAGE_SIZEMAP[k];
4444
4451
  return [w && s > w ? w : s, parseInt(String(mediaQuery[k])), v];
4445
4452
  }).filter(x => x[0] >= x[1]);
4446
4453
  // console.log(size, 'sizes', sizes);
4447
- return sizes;
4448
- }
4449
- if (isMediaSizeVariant(size)) {
4454
+ } else if (isMediaSizeVariant(size)) {
4450
4455
  // console.log('isMediaSizeVariant');
4451
4456
  const sizeLimit = IMAGE_SIZEMAP[size] || 0;
4452
4457
  // console.log(size, ratio[size], sizeLimit);
4453
- return Object.entries(IMAGE_SIZEMAP).filter(_ref3 => {
4458
+ sizes = Object.entries(IMAGE_SIZEMAP).filter(_ref3 => {
4454
4459
  let [k, v] = _ref3;
4455
4460
  return v <= sizeLimit;
4456
4461
  }).map(_ref4 => {
@@ -4458,14 +4463,17 @@ function getMediaSizes(mediaQuery, ratio, size) {
4458
4463
  return [v, parseInt(String(mediaQuery[k])), ratio[k]];
4459
4464
  });
4460
4465
  }
4466
+ } else {
4467
+ size = size || IMAGE_SIZEMAP;
4468
+ // console.log('size || IMAGE_SIZEMAP', size, IMAGE_SIZEMAP);
4469
+ sizes = Object.entries(size).map(_ref5 => {
4470
+ let [k, v] = _ref5;
4471
+ return [v, parseInt(String(mediaQuery[k])), ratio[k]];
4472
+ });
4461
4473
  }
4462
- size = size || IMAGE_SIZEMAP;
4463
- // console.log('size || IMAGE_SIZEMAP', size, IMAGE_SIZEMAP);
4464
- const sizes = Object.entries(size).map(_ref5 => {
4465
- let [k, v] = _ref5;
4466
- return [v, parseInt(String(mediaQuery[k])), ratio[k]];
4467
- });
4468
4474
  // console.log(size, 'sizes', sizes, ratio);
4475
+ sizes = sizes.filter((size, i) => i === 0 || size[0] <= maxWidth && (size[2] === 0 || size[0] / size[2] <= maxHeight));
4476
+ // console.log(sizes[0][2] ? sizes[0][0] / sizes[0][2] : 0, maxHeight);
4469
4477
  return sizes;
4470
4478
  }
4471
4479
  function getImageProps(_a, mediaQuery) {
@@ -4485,18 +4493,25 @@ function getImageProps(_a, mediaQuery) {
4485
4493
  } = props,
4486
4494
  otherProps = __rest(props, ["width", "height", "size"]);
4487
4495
  let useSize = size;
4496
+ let useWidth = undefined;
4488
4497
  if (typeof width === 'string' && width.indexOf('px') !== -1) {
4489
- useSize = parseInt(width);
4498
+ useWidth = parseInt(width);
4499
+ useSize = useWidth;
4500
+ } else if (typeof width === 'number') {
4501
+ useWidth = width;
4490
4502
  }
4491
- // console.log(useSize, width);
4492
- const ratio = getMediaRatio(props);
4493
- const sizes = getMediaSizes(mediaQuery, ratio, useSize);
4503
+ let useHeight = undefined;
4504
+ if (typeof height === 'string' && height.indexOf('px') !== -1) {
4505
+ useHeight = parseInt(height);
4506
+ } else if (typeof height === 'number') {
4507
+ useHeight = height;
4508
+ }
4509
+ const ratio = getMediaRatio(useWidth, useHeight, props.aspectRatio, props.aspectRatioSm, props.aspectRatioMd, props.aspectRatioLg, props.aspectRatioXl);
4510
+ const sizes = getMediaSizes(mediaQuery, ratio, useSize, props.mediaWidth, props.mediaHeight);
4494
4511
  const imageSrc = getImageSrc(src, sizes[0][0], sizes[0][2]);
4495
4512
  const imageSrcSet = getImageSrcset(src, sizes);
4496
4513
  const imageSizes = getImageSizes(sizes);
4497
- let useWidth = typeof width === 'string' ? parseInt(width) : width;
4498
- let useHeight = typeof height === 'string' ? parseInt(height) : height;
4499
- // console.log('width', width, 'useWidth', useWidth, 'height', height, 'useHeight', useHeight, 'useSize', useSize);
4514
+ // console.log('useSize', useSize, 'width', width, useWidth, 'height', height, useHeight);
4500
4515
  return Object.assign({
4501
4516
  src: imageSrc,
4502
4517
  srcSet: imageSrcSet,
@@ -4505,23 +4520,14 @@ function getImageProps(_a, mediaQuery) {
4505
4520
  height: useHeight ? `${useHeight}px` : undefined
4506
4521
  }, otherProps);
4507
4522
  }
4508
- function getMediaRatio(props) {
4509
- let width = undefined;
4510
- let height = undefined;
4511
- if (props.width) {
4512
- width = parseInt(String(props.width));
4513
- }
4514
- props.width = width;
4515
- if (props.height) {
4516
- height = parseInt(String(props.height));
4517
- }
4518
- props.height = height;
4523
+ function getMediaRatio(width, height, aspectRatio, aspectRatioSm, aspectRatioMd, aspectRatioLg, aspectRatioXl) {
4524
+ // console.log('getMediaRatio', width, height, aspectRatio);
4519
4525
  const defaultRatio = width && height ? width / height : 0;
4520
- const xs = getRatio(props.aspectRatio, defaultRatio);
4521
- const sm = getRatio(props.aspectRatioSm, xs);
4522
- const md = getRatio(props.aspectRatioMd, sm);
4523
- const lg = getRatio(props.aspectRatioLg, md);
4524
- const xl = getRatio(props.aspectRatioXl, lg);
4526
+ const xs = getRatio(aspectRatio, defaultRatio);
4527
+ const sm = getRatio(aspectRatioSm, xs);
4528
+ const md = getRatio(aspectRatioMd, sm);
4529
+ const lg = getRatio(aspectRatioLg, md);
4530
+ const xl = getRatio(aspectRatioXl, lg);
4525
4531
  const ratio = {
4526
4532
  xs,
4527
4533
  sm,
@@ -4605,16 +4611,15 @@ const MediaVideo = _a => {
4605
4611
  };
4606
4612
  React.useEffect(() => {
4607
4613
  if (videoRef.current && canLoad) {
4608
- if (videoRef.current.readyState && videoRef.current.readyState >= 2) {
4614
+ const video = videoRef.current;
4615
+ if (video.readyState && video.readyState >= 2) {
4609
4616
  if (typeof onLoaded === 'function') {
4610
4617
  onLoaded(videoRef);
4611
4618
  }
4612
4619
  } else {
4613
- videoRef.current.addEventListener('loadeddata', onLoad);
4620
+ video.addEventListener('loadeddata', onLoad);
4614
4621
  return () => {
4615
- if (videoRef.current) {
4616
- videoRef.current.removeEventListener('loadeddata', onLoad);
4617
- }
4622
+ video.removeEventListener('loadeddata', onLoad);
4618
4623
  };
4619
4624
  }
4620
4625
  }
@@ -4647,81 +4652,8 @@ const MediaItem = _ref => {
4647
4652
  item,
4648
4653
  options = {}
4649
4654
  } = _ref;
4650
- const mediaItem = React.useMemo(() => {
4651
- if (typeof item['media'] === 'object') {
4652
- item = item['media'];
4653
- }
4654
- const mediaItem = {
4655
- type: item.type,
4656
- src: item.src
4657
- };
4658
- if (item.abstract) {
4659
- mediaItem.abstract = item.abstract;
4660
- }
4661
- if (item.alt) {
4662
- mediaItem.alt = item.alt;
4663
- }
4664
- if (item.mimeType) {
4665
- mediaItem.mimeType = item.mimeType;
4666
- }
4667
- if (item.url) {
4668
- mediaItem.src = item.url;
4669
- }
4670
- if (item.title) {
4671
- mediaItem.title = item.title;
4672
- }
4673
- mediaItem.width = options.width || item.width;
4674
- mediaItem.height = options.height || item.height;
4675
- mediaItem.aspectRatio = options.aspectRatio;
4676
- mediaItem.aspectRatioSm = options.aspectRatioSm;
4677
- mediaItem.aspectRatioMd = options.aspectRatioMd;
4678
- mediaItem.aspectRatioLg = options.aspectRatioLg;
4679
- mediaItem.aspectRatioXl = options.aspectRatioXl;
4680
- mediaItem.onLoaded = options.onLoaded;
4681
- mediaItem.canLoad = options.canLoad;
4682
- return mediaItem;
4683
- }, [item, options]);
4684
- const mediaItemProps = React.useMemo(() => {
4685
- const media = __rest(mediaItem, ["width", "height", "sizes"]);
4686
- const title = media.title || options.title || media.alt || options.alt;
4687
- const alt = media.alt || options.alt || media.title || options.title;
4688
- const src = media.src || media.url || '';
4689
- const mediaItemProps = {
4690
- src,
4691
- title,
4692
- alt,
4693
- size: options.size,
4694
- onLoaded: mediaItem.onLoaded,
4695
- canLoad: mediaItem.canLoad
4696
- };
4697
- const hasGallery = options.galleryId != null && typeof options.open === 'function';
4698
- if (hasGallery) {
4699
- mediaItemProps['data-gallery'] = JSON.stringify({
4700
- galleryId: options.galleryId,
4701
- media
4702
- });
4703
- mediaItemProps.onClick = event => {
4704
- if (options.open) {
4705
- options.open(media);
4706
- }
4707
- };
4708
- }
4709
- if (bomCore.isMediaImage(media)) {
4710
- if (options.width) {
4711
- mediaItemProps.width = options.width;
4712
- }
4713
- mediaItemProps.height = options.height;
4714
- mediaItemProps.aspectRatio = options.aspectRatio;
4715
- mediaItemProps.aspectRatioSm = options.aspectRatioSm;
4716
- mediaItemProps.aspectRatioMd = options.aspectRatioMd;
4717
- mediaItemProps.aspectRatioLg = options.aspectRatioLg;
4718
- mediaItemProps.aspectRatioXl = options.aspectRatioXl;
4719
- if (options.eager) {
4720
- mediaItemProps.loading = 'eager';
4721
- }
4722
- }
4723
- return mediaItemProps;
4724
- }, [mediaItem]);
4655
+ const mediaItem = React.useMemo(() => getMediaItem(item, options), [item, options]);
4656
+ const mediaItemProps = React.useMemo(() => getMediaItemProps(mediaItem, options), [mediaItem, options]);
4725
4657
  return bomCore.isMediaVideo(mediaItem) ? jsxRuntime.jsx(MediaVideo, Object.assign({}, mediaItemProps)) : jsxRuntime.jsx(MediaImage, Object.assign({}, mediaItemProps));
4726
4658
  };
4727
4659
  const MediaItems = _ref2 => {
@@ -4735,6 +4667,87 @@ const MediaItems = _ref2 => {
4735
4667
  options: options
4736
4668
  }, m));
4737
4669
  };
4670
+ function getMediaItem(item, options) {
4671
+ if (typeof item['media'] === 'object') {
4672
+ item = item['media'];
4673
+ }
4674
+ const mediaItem = {
4675
+ type: item.type,
4676
+ src: item.src
4677
+ };
4678
+ if (item.abstract) {
4679
+ mediaItem.abstract = item.abstract;
4680
+ }
4681
+ if (item.alt) {
4682
+ mediaItem.alt = item.alt;
4683
+ }
4684
+ if (item.mimeType) {
4685
+ mediaItem.mimeType = item.mimeType;
4686
+ }
4687
+ if (item.url) {
4688
+ mediaItem.src = item.url;
4689
+ }
4690
+ if (item.title) {
4691
+ mediaItem.title = item.title;
4692
+ }
4693
+ if (typeof item.width === 'number') {
4694
+ mediaItem.mediaWidth = item.width;
4695
+ }
4696
+ if (typeof item.height === 'number') {
4697
+ mediaItem.mediaHeight = item.height;
4698
+ }
4699
+ mediaItem.width = options.width;
4700
+ mediaItem.height = options.height;
4701
+ mediaItem.aspectRatio = options.aspectRatio;
4702
+ mediaItem.aspectRatioSm = options.aspectRatioSm;
4703
+ mediaItem.aspectRatioMd = options.aspectRatioMd;
4704
+ mediaItem.aspectRatioLg = options.aspectRatioLg;
4705
+ mediaItem.aspectRatioXl = options.aspectRatioXl;
4706
+ mediaItem.onLoaded = options.onLoaded;
4707
+ mediaItem.canLoad = options.canLoad;
4708
+ return mediaItem;
4709
+ }
4710
+ function getMediaItemProps(mediaItem, options) {
4711
+ const media = __rest(mediaItem, ["width", "height", "sizes"]);
4712
+ const title = media.title || options.title || media.alt || options.alt;
4713
+ const alt = media.alt || options.alt || media.title || options.title;
4714
+ const src = media.src || media.url || '';
4715
+ const mediaItemProps = {
4716
+ src,
4717
+ title,
4718
+ alt,
4719
+ size: options.size,
4720
+ onLoaded: mediaItem.onLoaded,
4721
+ canLoad: mediaItem.canLoad
4722
+ };
4723
+ const hasGallery = options.galleryId != null && typeof options.open === 'function';
4724
+ if (hasGallery) {
4725
+ mediaItemProps['data-gallery'] = JSON.stringify({
4726
+ galleryId: options.galleryId,
4727
+ media
4728
+ });
4729
+ mediaItemProps.onClick = event => {
4730
+ if (options.open) {
4731
+ options.open(media);
4732
+ }
4733
+ };
4734
+ }
4735
+ if (bomCore.isMediaImage(media)) {
4736
+ mediaItemProps.mediaWidth = mediaItem.mediaWidth;
4737
+ mediaItemProps.mediaHeight = mediaItem.mediaHeight;
4738
+ mediaItemProps.width = options.width;
4739
+ mediaItemProps.height = options.height;
4740
+ mediaItemProps.aspectRatio = options.aspectRatio;
4741
+ mediaItemProps.aspectRatioSm = options.aspectRatioSm;
4742
+ mediaItemProps.aspectRatioMd = options.aspectRatioMd;
4743
+ mediaItemProps.aspectRatioLg = options.aspectRatioLg;
4744
+ mediaItemProps.aspectRatioXl = options.aspectRatioXl;
4745
+ if (options.eager) {
4746
+ mediaItemProps.loading = 'eager';
4747
+ }
4748
+ }
4749
+ return mediaItemProps;
4750
+ }
4738
4751
 
4739
4752
  const StyledMediaInfo = styled__default.default.div`
4740
4753
  position: absolute;
@@ -4836,7 +4849,7 @@ const StyledMedia$1 = styled__default.default.div`
4836
4849
  left: 0;
4837
4850
  width: 100%;
4838
4851
  height: 100%;
4839
- ${typeof props.overlay === 'number' ? `background: rgba(0,0,0,${props.overlay});` : `background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.1) 15.9%, rgba(0, 0, 0, 0) 41.67%, rgba(0, 0, 0, 0.1) 61.79%, rgba(0, 0, 0, 0.6) 100%);`}
4852
+ ${typeof props.overlay === 'number' ? `background: rgba(0,0,0,${props.overlay});` : 'background-image: linear-gradient(180deg, rgba(0, 0, 0, 0.5) 0%, rgba(0, 0, 0, 0.1) 15.9%, rgba(0, 0, 0, 0) 41.67%, rgba(0, 0, 0, 0.1) 61.79%, rgba(0, 0, 0, 0.6) 100%);'}
4840
4853
  }
4841
4854
  ` : ''}
4842
4855
  `;
@@ -4865,10 +4878,10 @@ const MediaBase = /*#__PURE__*/React.forwardRef((_a, ref) => {
4865
4878
  'media--gallery': id
4866
4879
  });
4867
4880
  const style = {};
4868
- if (typeof width === 'string' && width.indexOf('px') !== -1) {
4881
+ if (typeof width === 'string') {
4869
4882
  style.width = width;
4870
4883
  }
4871
- if (typeof height === 'string' && height.indexOf('px') !== -1) {
4884
+ if (typeof height === 'string') {
4872
4885
  style.height = height;
4873
4886
  }
4874
4887
  return jsxRuntime.jsx(StyledMedia$1, Object.assign({