@desynova-digital/components 9.3.2 → 9.3.3

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.
@@ -14,7 +14,6 @@ var _styledComponents = _interopRequireWildcard(require("styled-components"));
14
14
  var _propTypes = _interopRequireDefault(require("prop-types"));
15
15
  var _tokens = require("@desynova-digital/tokens");
16
16
  var _icon = _interopRequireDefault(require("../../atoms/icon"));
17
- var _tokens2 = require("../../../tokens");
18
17
  var _statusV = _interopRequireDefault(require("../../../tokens/statusV2"));
19
18
  var _cardV = require("./cardV2");
20
19
  var _utils = require("../../_helpers/utils");
@@ -23,6 +22,8 @@ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _temp
23
22
  // styles
24
23
  function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
25
24
  function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
25
+ var DEFAULT_THUMBNAIL_URL = "https://thumbnail.desynova.com/default_placeholder/Contido_Placeholder_Image.png";
26
+ var DEFAULT_FILE_TYPES = ["document", "audio", "video", "music", "image", "file", "folder"];
26
27
  var OverlayBackgroundStyles = (0, _styledComponents.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2["default"])(["\n background: rgba(0, 0, 0, 0.5);\n"])));
27
28
  var assetStyles = {
28
29
  folder: {
@@ -292,6 +293,9 @@ var getStatusLabel = function getStatusLabel(status) {
292
293
  var _ARCHIVED_STATUS_CONF2;
293
294
  return ((_ARCHIVED_STATUS_CONF2 = ARCHIVED_STATUS_CONFIG[normalizeStatusCode(status)]) === null || _ARCHIVED_STATUS_CONF2 === void 0 ? void 0 : _ARCHIVED_STATUS_CONF2.label) || null;
294
295
  };
296
+ var getNormalizedFileType = function getNormalizedFileType(fileType) {
297
+ return String(fileType || "").trim().toLowerCase();
298
+ };
295
299
  var ThumbnailV2 = function ThumbnailV2(props) {
296
300
  var theme = props.theme,
297
301
  width = props.width,
@@ -333,6 +337,11 @@ var ThumbnailV2 = function ThumbnailV2(props) {
333
337
  var displayDuration = hasDuration ? getDisplayTimecode(durationValue, effectiveFrameRate) : "";
334
338
  var supportsDuration = ["audio", "video"].includes(String(file_type || "").trim().toLowerCase());
335
339
  var displayAssetType = asset_type === undefined || asset_type === null ? "" : String(asset_type).trim();
340
+ var rawThumbnail = typeof props.thumbnail === "string" ? props.thumbnail.trim() : "";
341
+ var rawIframeurl = typeof props.iframeurl === "string" ? props.iframeurl.trim() : "";
342
+ var hasNoMediaSources = !rawThumbnail && !rawIframeurl;
343
+ var normalizedFileType = getNormalizedFileType(file_type);
344
+ var isVideoFileType = normalizedFileType === "video";
336
345
  var actionItems = Array.isArray(actions) ? actions : [];
337
346
  var isSegmentCard = Boolean(isSegment || is_segment);
338
347
  var totalSeconds = getTimeInSeconds(resolvedDuration, effectiveFrameRate);
@@ -345,18 +354,30 @@ var ThumbnailV2 = function ThumbnailV2(props) {
345
354
  var segmentWidthPercent = hasSegmentTimeline ? Math.min(100 - segmentLeftPercent, Math.max(1, (segmentEndSeconds - segmentStartSeconds) / totalSeconds * 100)) : 0;
346
355
  var segmentCenterPercent = segmentLeftPercent + segmentWidthPercent / 2;
347
356
  var segmentPopupAlignment = segmentCenterPercent < 40 ? "start" : segmentCenterPercent > 60 ? "end" : "center";
348
- var _useState5 = (0, _react.useState)(null),
357
+ var _useState5 = (0, _react.useState)(false),
349
358
  _useState6 = (0, _slicedToArray2["default"])(_useState5, 2),
350
- statusIndex = _useState6[0],
351
- setStatusIndex = _useState6[1];
359
+ isClickPrevented = _useState6[0],
360
+ setClickPreventation = _useState6[1];
352
361
  var _useState7 = (0, _react.useState)(false),
353
362
  _useState8 = (0, _slicedToArray2["default"])(_useState7, 2),
354
- isClickPrevented = _useState8[0],
355
- setClickPreventation = _useState8[1];
363
+ showTopRightAction = _useState8[0],
364
+ setShowTopRightAction = _useState8[1];
356
365
  var _useState9 = (0, _react.useState)(false),
357
366
  _useState10 = (0, _slicedToArray2["default"])(_useState9, 2),
358
- showTopRightAction = _useState10[0],
359
- setShowTopRightAction = _useState10[1];
367
+ hasThumbnailLoaded = _useState10[0],
368
+ setHasThumbnailLoaded = _useState10[1];
369
+ var _useState11 = (0, _react.useState)(false),
370
+ _useState12 = (0, _slicedToArray2["default"])(_useState11, 2),
371
+ hasThumbnailError = _useState12[0],
372
+ setHasThumbnailError = _useState12[1];
373
+ var _useState13 = (0, _react.useState)(false),
374
+ _useState14 = (0, _slicedToArray2["default"])(_useState13, 2),
375
+ hasIframeLoaded = _useState14[0],
376
+ setHasIframeLoaded = _useState14[1];
377
+ var _useState15 = (0, _react.useState)(false),
378
+ _useState16 = (0, _slicedToArray2["default"])(_useState15, 2),
379
+ hasIframeError = _useState16[0],
380
+ setHasIframeError = _useState16[1];
360
381
  var iframeImageBlockRef = (0, _react.useRef)(null);
361
382
  var iframeImageRef = (0, _react.useRef)(null);
362
383
  var hoverPointerRef = (0, _react.useRef)(null);
@@ -379,11 +400,47 @@ var ThumbnailV2 = function ThumbnailV2(props) {
379
400
  }
380
401
  }, [actionItems]);
381
402
  (0, _react.useEffect)(function () {
382
- var index = _tokens2.CARD_ASSET_STATUS.findIndex(function (label) {
383
- return label.code.includes(card_status || upload_status ? (card_status || upload_status).toLowerCase().split(" ").join("_") : []);
384
- });
385
- setStatusIndex(index);
386
- }, [upload_status, card_status]);
403
+ var isMounted = true;
404
+ var preloaders = [];
405
+
406
+ /**
407
+ * This function preloads an image from the provided URL and handles its load and error states.
408
+ * @param {string} src URL of the image to load.
409
+ * @param {Function} setLoaded State setter for successful image loading.
410
+ * @param {Function} setError State setter for image loading failure.
411
+ */
412
+
413
+ var loadImage = function loadImage(src, setLoaded, setError) {
414
+ setLoaded(false);
415
+ setError(false);
416
+ if (!src) {
417
+ setError(true);
418
+ return;
419
+ }
420
+ var image = new Image();
421
+ image.onload = function () {
422
+ if (!isMounted) return;
423
+ setLoaded(true);
424
+ setError(false);
425
+ };
426
+ image.onerror = function () {
427
+ if (!isMounted) return;
428
+ setLoaded(false);
429
+ setError(true);
430
+ };
431
+ image.src = src;
432
+ preloaders.push(image);
433
+ };
434
+ loadImage(rawThumbnail, setHasThumbnailLoaded, setHasThumbnailError);
435
+ loadImage(rawIframeurl, setHasIframeLoaded, setHasIframeError);
436
+ return function () {
437
+ isMounted = false;
438
+ preloaders.forEach(function (image) {
439
+ image.onload = null;
440
+ image.onerror = null;
441
+ });
442
+ };
443
+ }, [rawThumbnail, rawIframeurl]);
387
444
  (0, _react.useEffect)(function () {
388
445
  if (!showTopRightAction) return;
389
446
  var handleClick = function handleClick(e) {
@@ -446,9 +503,14 @@ var ThumbnailV2 = function ThumbnailV2(props) {
446
503
  onNestedDropdownSelect(item);
447
504
  }
448
505
  }, [onNestedDropdownSelect]);
506
+ var resolvedIconName = normalizedFileType === "video" && value == "collateral" ? "video-icon" : DEFAULT_FILE_TYPES.includes(normalizedFileType) ? "".concat(normalizedFileType, "-icon") : "unsupportedFile-icon";
507
+ var shouldShowThumbnailImage = !hasNoMediaSources && hasThumbnailLoaded;
508
+ var shouldShowDefaultThumbnail = !hasNoMediaSources && isVideoFileType && rawThumbnail && !hasThumbnailLoaded;
509
+ var shouldShowFileTypeIcon = Boolean(file_type) && (hasNoMediaSources || !shouldShowThumbnailImage && !shouldShowDefaultThumbnail);
510
+ var shouldRenderIframePreview = hasIframeLoaded && !hasIframeError;
449
511
  return /*#__PURE__*/_react["default"].createElement(ThumbnailStyles, {
450
512
  width: width,
451
- thumbnail: thumbnail,
513
+ thumbnail: shouldShowThumbnailImage ? rawThumbnail : shouldShowDefaultThumbnail ? DEFAULT_THUMBNAIL_URL : "",
452
514
  isClickPrevented: isClickPrevented,
453
515
  onClick: handleThumbnailClick,
454
516
  theme: props.theme,
@@ -538,15 +600,15 @@ var ThumbnailV2 = function ThumbnailV2(props) {
538
600
  }), /*#__PURE__*/_react["default"].createElement("div", {
539
601
  className: "tooltip"
540
602
  }, item.title));
541
- })) || null, file_type && !thumbnail ? /*#__PURE__*/_react["default"].createElement("div", {
603
+ })) || null, shouldShowFileTypeIcon ? /*#__PURE__*/_react["default"].createElement("div", {
542
604
  className: "thumbnail-image-block background-block"
543
605
  }, /*#__PURE__*/_react["default"].createElement("div", {
544
606
  className: "circle"
545
607
  }, /*#__PURE__*/_react["default"].createElement(_icon["default"], {
546
- name: file_type == "video" && value == "collateral" ? "video-icon" : "".concat(file_type, "-icon"),
608
+ name: resolvedIconName,
547
609
  width: 15,
548
610
  height: 15
549
- }))) : null, iframeurl && /*#__PURE__*/_react["default"].createElement("div", {
611
+ }))) : null, shouldRenderIframePreview && /*#__PURE__*/_react["default"].createElement("div", {
550
612
  onMouseMove: handleMouseMove,
551
613
  className: "iframe-image-block background-block",
552
614
  ref: iframeImageBlockRef
@@ -556,7 +618,7 @@ var ThumbnailV2 = function ThumbnailV2(props) {
556
618
  }), /*#__PURE__*/_react["default"].createElement("img", {
557
619
  ref: iframeImageRef,
558
620
  className: "iframe-image",
559
- src: iframeurl,
621
+ src: rawIframeurl,
560
622
  alt: "preview"
561
623
  })) || null, isSearchPageCard && supportsDuration && displayDuration ? /*#__PURE__*/_react["default"].createElement(DurationBadge, null, displayDuration) : null);
562
624
  };
@@ -590,7 +652,7 @@ ThumbnailV2.propTypes = {
590
652
  ThumbnailV2.defaultProps = {
591
653
  theme: "dark",
592
654
  width: "lg",
593
- thumbnail: "https://thumbnail.desynova.com/default_placeholder/Contido_Placeholder_Image.png",
655
+ thumbnail: DEFAULT_THUMBNAIL_URL,
594
656
  iframeurl: "",
595
657
  isAdobe: false,
596
658
  isSearchPageCard: false
@@ -2019,6 +2019,14 @@
2019
2019
  ],
2020
2020
  "width": 14,
2021
2021
  "height": 14
2022
+ },
2023
+ "unsupportedFile-icon": {
2024
+ "viewBox": "0 -960 960 960",
2025
+ "paths": [
2026
+ "M160-160q-33 0-56.5-23.5T80-240v-120h360q33 0 56.5-23.5T520-440v-360h280q33 0 56.5 23.5T880-720v480q0 33-23.5 56.5T800-160H160ZM80-400v-240q0-33 23.5-56.5T160-720h240L80-400Zm153-40 207-207v207H233Z"
2027
+ ],
2028
+ "width": 24,
2029
+ "height": 24
2022
2030
  }
2023
2031
  }
2024
2032
  }
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@desynova-digital/components",
3
- "version": "9.3.2",
3
+ "version": "9.3.3",
4
4
  "description": "Components for Desynova Digital",
5
5
  "main": "index.js",
6
6
  "author": "desynova-digital",
7
7
  "license": "MIT",
8
8
  "repository": "desynova-digital",
9
9
  "dependencies": {
10
- "@desynova-digital/tokens": "9.3.2",
10
+ "@desynova-digital/tokens": "9.3.3",
11
11
  "prop-types": "^15.7.2",
12
12
  "styled-components": "^4.3.2"
13
13
  },