Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { useState, useEffect, useRef } from 'react';
import { useDispatch } from 'react-redux';
import { MenuItem, SelectGroup } from '@scaleflex/ui/core';
import { Success } from '@scaleflex/icons';
import openLink from '@filerobot/utils/lib/openLink';
import Styled from './EmbedFeat.styled';
import { FEAT_KEYS_IDS, COMPRESSION_REGEX, VIDEO_FEATURES_IDS, CONVERSION_REGEX, TRANSCODING_REGEX, RESOLUTIONS_IDS } from '../EmbedVideo.constants';
import { jsx as _jsx } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var EmbedFeat = function EmbedFeat(_ref) {
  var _currentVideo$info, _currentVideo$info$fe, _videoConfigs$videoFe, _videoConfigs$videoFe2, _videoConfigs$videoFe3, _videoConfigs$videoFe4, _useState5, _currentVideo$info2, _currentVideo$info2$f, _currentVideo$info2$f2, _currentVideo$info2$f3, _currentVideo$info3, _currentVideo$info$ch, _currentVideo$info5, _featResponse$featJso, _currentVideo$info$ch9, _currentVideo$info6, _featResponse$featJso2;
  var videoFeat = _ref.videoFeat,
    i18n = _ref.i18n,
    video = _ref.video,
    info = _ref.info,
    videoConfigs = _ref.videoConfigs,
    videoFeatId = _ref.videoFeatId;
  var dispatch = useDispatch();
  var _useState = useState(_objectSpread({}, video)),
    _useState2 = _slicedToArray(_useState, 2),
    currentVideo = _useState2[0],
    setCurrentVideo = _useState2[1];
  var i18nKeyFeathint = videoFeat.i18nKeyFeathint,
    i18nKeyFeatButton = videoFeat.i18nKeyFeatButton,
    i18nKeyReFeatButton = videoFeat.i18nKeyReFeatButton,
    i18nKeyFeatTitle = videoFeat.i18nKeyFeatTitle,
    featJsonKey = videoFeat.featJsonKey,
    _onClick = videoFeat.onClick,
    choosenOptionsKey = videoFeat.choosenOptionsKey;
  var isFeatDone = Boolean(((_currentVideo$info = currentVideo.info) === null || _currentVideo$info === void 0 ? void 0 : (_currentVideo$info$fe = _currentVideo$info[featJsonKey]) === null || _currentVideo$info$fe === void 0 ? void 0 : _currentVideo$info$fe.length) > 0);
  var formatedRes = Array.isArray(videoConfigs === null || videoConfigs === void 0 ? void 0 : (_videoConfigs$videoFe = videoConfigs[videoFeatId]) === null || _videoConfigs$videoFe === void 0 ? void 0 : _videoConfigs$videoFe[choosenOptionsKey]) ? videoConfigs === null || videoConfigs === void 0 ? void 0 : (_videoConfigs$videoFe2 = videoConfigs[videoFeatId]) === null || _videoConfigs$videoFe2 === void 0 ? void 0 : (_videoConfigs$videoFe3 = _videoConfigs$videoFe2[choosenOptionsKey]) === null || _videoConfigs$videoFe3 === void 0 ? void 0 : _videoConfigs$videoFe3.map(function (config) {
    return RESOLUTIONS_IDS[config] || config;
  }) : videoConfigs === null || videoConfigs === void 0 ? void 0 : (_videoConfigs$videoFe4 = videoConfigs[videoFeatId]) === null || _videoConfigs$videoFe4 === void 0 ? void 0 : _videoConfigs$videoFe4[choosenOptionsKey];
  var _useState3 = useState((_useState5 = {}, _defineProperty(_useState5, FEAT_KEYS_IDS.COMPRESSION, []), _defineProperty(_useState5, FEAT_KEYS_IDS.CONVERSION, ''), _defineProperty(_useState5, FEAT_KEYS_IDS.TRANSCODING, ''), _useState5)),
    _useState4 = _slicedToArray(_useState3, 2),
    featResponse = _useState4[0],
    setFeatResponse = _useState4[1];
  var videoUrl = ((_currentVideo$info2 = currentVideo.info) === null || _currentVideo$info2 === void 0 ? void 0 : (_currentVideo$info2$f = _currentVideo$info2[featJsonKey]) === null || _currentVideo$info2$f === void 0 ? void 0 : (_currentVideo$info2$f2 = _currentVideo$info2$f[0]) === null || _currentVideo$info2$f2 === void 0 ? void 0 : (_currentVideo$info2$f3 = _currentVideo$info2$f2[featJsonKey]) === null || _currentVideo$info2$f3 === void 0 ? void 0 : _currentVideo$info2$f3[0]) || ((_currentVideo$info3 = currentVideo.info) === null || _currentVideo$info3 === void 0 ? void 0 : _currentVideo$info3[featJsonKey]) || featResponse[featJsonKey];
  var _useState6 = useState((_currentVideo$info$ch = currentVideo.info[choosenOptionsKey]) === null || _currentVideo$info$ch === void 0 ? void 0 : _currentVideo$info$ch[0]),
    _useState7 = _slicedToArray(_useState6, 2),
    compresSelectedOption = _useState7[0],
    setCompresOption = _useState7[1];
  var _useState8 = useState(videoUrl),
    _useState9 = _slicedToArray(_useState8, 2),
    matchedVideoUrl = _useState9[0],
    setMatchedVideoUrl = _useState9[1];
  var _useState10 = useState(false),
    _useState11 = _slicedToArray(_useState10, 2),
    showSelectOptions = _useState11[0],
    setShowSelectOptions = _useState11[1];
  var _useState12 = useState(false),
    _useState13 = _slicedToArray(_useState12, 2),
    isFeatProcessing = _useState13[0],
    setIsFeatProcessing = _useState13[1];
  var inputRef = useRef();
  var comparFunc = function comparFunc(a, b) {
    return Number(a.split('p')[0]) - Number(b.split('p')[0]);
  };
  var getFormattedCompressions = function getFormattedCompressions() {
    var _compressedVideoUrls$;
    var compressedVideoUrls = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
    return (_compressedVideoUrls$ = compressedVideoUrls.map(function (url) {
      var _url$match;
      return (_url$match = url.match(COMPRESSION_REGEX)) === null || _url$match === void 0 ? void 0 : _url$match[1];
    })) === null || _compressedVideoUrls$ === void 0 ? void 0 : _compressedVideoUrls$.sort(comparFunc);
  };
  var updateCurrentVideoInfo = function updateCurrentVideoInfo() {
    var changes = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
    if (changes && !Object.keys(changes).some(function (propName) {
      var _currentVideo$info4;
      return JSON.stringify(changes[propName]) !== JSON.stringify(currentVideo === null || currentVideo === void 0 ? void 0 : (_currentVideo$info4 = currentVideo.info) === null || _currentVideo$info4 === void 0 ? void 0 : _currentVideo$info4[propName]);
    })) {
      return;
    }
    setCurrentVideo(function (_video) {
      return _objectSpread(_objectSpread({}, _video), {}, {
        info: _objectSpread(_objectSpread({}, _video === null || _video === void 0 ? void 0 : _video.info), changes || {})
      });
    });
  };
  useEffect(function () {
    updateCurrentVideoInfo();
  }, [video]);
  useEffect(function () {
    var _videoUrl$match, _videoUrl$0$split$0$m, _videoUrl$split$0$mat;
    if (isFeatDone) {
      switch (featJsonKey) {
        case FEAT_KEYS_IDS.COMPRESSION:
          updateCurrentVideoInfo(_defineProperty({}, choosenOptionsKey, getFormattedCompressions(videoUrl)));
          break;
        case FEAT_KEYS_IDS.CONVERSION:
          updateCurrentVideoInfo(_defineProperty({}, choosenOptionsKey, [(_videoUrl$match = videoUrl.match(CONVERSION_REGEX)) === null || _videoUrl$match === void 0 ? void 0 : _videoUrl$match[0]]));
          break;
        case FEAT_KEYS_IDS.TRANSCODING:
          updateCurrentVideoInfo(_defineProperty({}, choosenOptionsKey, [Array.isArray(videoUrl) ? (_videoUrl$0$split$0$m = videoUrl[0].split('/currentVideo')[0].match(TRANSCODING_REGEX)) === null || _videoUrl$0$split$0$m === void 0 ? void 0 : _videoUrl$0$split$0$m[0] : (_videoUrl$split$0$mat = videoUrl.split('/currentVideo')[0].match(TRANSCODING_REGEX)) === null || _videoUrl$split$0$mat === void 0 ? void 0 : _videoUrl$split$0$mat[0]]));
          break;
      }
    }
    if (Array.isArray(featResponse === null || featResponse === void 0 ? void 0 : featResponse[featJsonKey])) {
      var _currentVideo$info$ch2;
      setCompresOption((_currentVideo$info$ch2 = currentVideo.info[choosenOptionsKey]) === null || _currentVideo$info$ch2 === void 0 ? void 0 : _currentVideo$info$ch2[0]);
    }
  }, [isFeatDone, currentVideo]);
  useEffect(function () {
    if (Array.isArray(videoUrl) && featJsonKey === FEAT_KEYS_IDS.COMPRESSION) {
      var _videoUrl = videoUrl.find(function (url) {
        return url.includes(compresSelectedOption);
      });
      setMatchedVideoUrl(_videoUrl);
    }
  }, [compresSelectedOption]);

  // TODO: FIX
  // useEffect(() => {
  //   handleInputClicks(inputRef, matchedVideoUrl, compresSelectedOption)
  // }, [])

  useEffect(function () {
    var fetchedVideoUrl = featResponse === null || featResponse === void 0 ? void 0 : featResponse[featJsonKey];
    if ((fetchedVideoUrl === null || fetchedVideoUrl === void 0 ? void 0 : fetchedVideoUrl.length) > 0) {
      setMatchedVideoUrl(Array.isArray(fetchedVideoUrl) ? fetchedVideoUrl[0] : fetchedVideoUrl);
      if (Array.isArray(videoUrl)) {
        if (featJsonKey === FEAT_KEYS_IDS.COMPRESSION) {
          updateCurrentVideoInfo(_defineProperty({}, choosenOptionsKey, getFormattedCompressions(videoUrl)));
        }
        setShowSelectOptions(videoFeatId === VIDEO_FEATURES_IDS.COMPRESSION && Array.isArray(featResponse === null || featResponse === void 0 ? void 0 : featResponse[featJsonKey]) && (featResponse === null || featResponse === void 0 ? void 0 : featResponse[featJsonKey].length) > 1);
      }
    }
  }, [featResponse]);
  useEffect(function () {
    var _currentVideo$info$ch3;
    setShowSelectOptions(videoFeatId === VIDEO_FEATURES_IDS.COMPRESSION && ((_currentVideo$info$ch3 = currentVideo.info[choosenOptionsKey]) === null || _currentVideo$info$ch3 === void 0 ? void 0 : _currentVideo$info$ch3.length) > 1);
  }, [video, currentVideo]);
  useEffect(function () {
    var changes = {};
    Object.keys(videoConfigs).forEach(function (feat) {
      var _videoConfigs$feat;
      if ((_videoConfigs$feat = videoConfigs[feat]) !== null && _videoConfigs$feat !== void 0 && _videoConfigs$feat[choosenOptionsKey]) {
        changes["rest_".concat(choosenOptionsKey)] = getNewOptions(feat);
      }
    });
    updateCurrentVideoInfo(changes);
  }, [video.info[choosenOptionsKey]]);
  var getFeatParams = function getFeatParams() {
    switch (featJsonKey) {
      case FEAT_KEYS_IDS.COMPRESSION:
        return {
          videoResolutions: currentVideo.info["rest_".concat(choosenOptionsKey)],
          bitrate: "".concat(videoConfigs.compression.target_bitrate, "k"),
          isInternal: videoConfigs.compression.target_folder.includes('internal')
        };
      case FEAT_KEYS_IDS.CONVERSION:
        return {
          format: currentVideo.info["rest_".concat(choosenOptionsKey)].toLowerCase(),
          isInternal: videoConfigs.conversion.target_folder.includes('internal')
        };
      case FEAT_KEYS_IDS.TRANSCODING:
        return {
          protocol: currentVideo.info["rest_".concat(choosenOptionsKey)].toLowerCase()
        };
    }
  };
  var getNewOptions = function getNewOptions(feat) {
    var _videoConfigs$feat2;
    if (Array.isArray((_videoConfigs$feat2 = videoConfigs[feat]) === null || _videoConfigs$feat2 === void 0 ? void 0 : _videoConfigs$feat2[choosenOptionsKey])) {
      var _videoConfigs$feat3, _videoConfigs$feat3$c;
      return (_videoConfigs$feat3 = videoConfigs[feat]) === null || _videoConfigs$feat3 === void 0 ? void 0 : (_videoConfigs$feat3$c = _videoConfigs$feat3[choosenOptionsKey]) === null || _videoConfigs$feat3$c === void 0 ? void 0 : _videoConfigs$feat3$c.filter(function (config) {
        var _currentVideo$info$ch4, _currentVideo$info$ch5;
        return !((_currentVideo$info$ch4 = currentVideo.info[choosenOptionsKey]) !== null && _currentVideo$info$ch4 !== void 0 && (_currentVideo$info$ch5 = _currentVideo$info$ch4.join(' ')) !== null && _currentVideo$info$ch5 !== void 0 && _currentVideo$info$ch5.includes(config));
      });
    } else {
      var _currentVideo$info$ch6, _currentVideo$info$ch7, _videoConfigs$feat4, _videoConfigs$feat5;
      return (_currentVideo$info$ch6 = currentVideo.info[choosenOptionsKey]) !== null && _currentVideo$info$ch6 !== void 0 && (_currentVideo$info$ch7 = _currentVideo$info$ch6.join(' ')) !== null && _currentVideo$info$ch7 !== void 0 && _currentVideo$info$ch7.includes((_videoConfigs$feat4 = videoConfigs[feat]) === null || _videoConfigs$feat4 === void 0 ? void 0 : _videoConfigs$feat4[choosenOptionsKey].toLowerCase()) ? '' : (_videoConfigs$feat5 = videoConfigs[feat]) === null || _videoConfigs$feat5 === void 0 ? void 0 : _videoConfigs$feat5[choosenOptionsKey];
    }
  };
  var renderInput = function renderInput() {
    var _currentVideo$info$ch8;
    return /*#__PURE__*/_jsxs(_Fragment, {
      children: [showSelectOptions && /*#__PURE__*/_jsx(SelectGroup, {
        label: i18n('mutualizedResolutionLabel'),
        onChange: function onChange(value) {
          return setCompresOption(value);
        },
        value: compresSelectedOption,
        size: "md",
        SelectProps: {
          MenuProps: {
            position: 'bottom-start'
          }
        },
        children: (_currentVideo$info$ch8 = currentVideo.info[choosenOptionsKey]) === null || _currentVideo$info$ch8 === void 0 ? void 0 : _currentVideo$info$ch8.map(function (option) {
          return /*#__PURE__*/_jsx(MenuItem, {
            size: "sm",
            value: option,
            children: option
          }, option);
        })
      }), /*#__PURE__*/_jsx(Styled.Input, {
        readOnly: true,
        fullWidth: true,
        ref: inputRef,
        isTranscodeInput: featJsonKey === FEAT_KEYS_IDS.TRANSCODING,
        copyTextMessage: i18n('mutualizedCopyLink'),
        copySuccessIcon: /*#__PURE__*/_jsx(Success, {
          size: 16
        }),
        onClick: function onClick() {
          if (featJsonKey === FEAT_KEYS_IDS.TRANSCODING) return;
          openLink(matchedVideoUrl);
        },
        value: matchedVideoUrl || ''
      })]
    });
  };
  return /*#__PURE__*/_jsxs(Styled.Wrapper, {
    children: [/*#__PURE__*/_jsxs(Styled.VideoFeatWrapper, {
      children: [/*#__PURE__*/_jsxs(Styled.TextBlock, {
        children: [/*#__PURE__*/_jsx(Styled.VideoFeatTitle, {
          children: i18n(i18nKeyFeatTitle)
        }), /*#__PURE__*/_jsxs(Styled.VideoFeatHint, {
          children: [i18n(i18nKeyFeathint), /*#__PURE__*/_jsx(Styled.VideoFeatFormats, {
            children: Array.isArray(formatedRes) ? formatedRes.join(', ') : formatedRes
          })]
        })]
      }), ((_currentVideo$info5 = currentVideo.info["rest_".concat(choosenOptionsKey)]) === null || _currentVideo$info5 === void 0 ? void 0 : _currentVideo$info5.length) > 0 && !(featResponse !== null && featResponse !== void 0 && (_featResponse$featJso = featResponse[featJsonKey]) !== null && _featResponse$featJso !== void 0 && _featResponse$featJso.length) > 0 && /*#__PURE__*/_jsx(Styled.ActionBtn, {
        size: "md",
        color: "secondary",
        loading: isFeatProcessing,
        onClick: function onClick() {
          _onClick({
            video: currentVideo,
            info: info,
            i18n: i18n,
            featResponse: featResponse,
            setFeatResponse: setFeatResponse,
            setIsFeatProcessing: setIsFeatProcessing,
            dispatch: dispatch
          }, getFeatParams());
        },
        children: !currentVideo.loading && i18n(((_currentVideo$info$ch9 = currentVideo.info[choosenOptionsKey]) === null || _currentVideo$info$ch9 === void 0 ? void 0 : _currentVideo$info$ch9.length) > 0 && ((_currentVideo$info6 = currentVideo.info["rest_".concat(choosenOptionsKey)]) === null || _currentVideo$info6 === void 0 ? void 0 : _currentVideo$info6.length) > 0 ? i18nKeyReFeatButton : i18nKeyFeatButton)
      })]
    }, i18nKeyFeatTitle), (isFeatDone || (featResponse === null || featResponse === void 0 ? void 0 : (_featResponse$featJso2 = featResponse[featJsonKey]) === null || _featResponse$featJso2 === void 0 ? void 0 : _featResponse$featJso2.length) > 0) && renderInput()]
  });
};
export default EmbedFeat;