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); }
var _excluded = ["file", "onContextMenu", "toggleFileWindow"];
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 _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
import { useMemo } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { ItemHoverTopOptions } from '@filerobot/common';
import { Download, Link, More, Preview, Share } from '@scaleflex/icons';
import copyText from '@filerobot/utils/lib/copyText';
import isPreviewSupported from '@filerobot/utils/lib/isPreviewSupported';
import getFileLink from '@filerobot/utils/lib/getFileLink';
import { selectIsUserPermittedToShare } from '@filerobot/core/lib/slices/user.slice';
import { sharePanelOpened } from '../../../../slices/panels.slice';
import { downloadOneFile, emitExportEvent } from '../../../../slices/downloads.slice';
import { useExplorer } from '../../../../hooks';
import { useDownloadConsentModal } from '../../../Modals';
import { selectIsShareboxView } from '../../../../slices/views.slice';
import { jsx as _jsx } from "react/jsx-runtime";
var FileTopOptions = function FileTopOptions(_ref) {
  var file = _ref.file,
    onContextMenu = _ref.onContextMenu,
    toggleFileWindow = _ref.toggleFileWindow,
    props = _objectWithoutProperties(_ref, _excluded);
  var dispatch = useDispatch();
  var triggerDownloadConsentModal = useDownloadConsentModal();
  var isUserPermittedToShare = useSelector(selectIsUserPermittedToShare);
  var isShareboxView = useSelector(selectIsShareboxView);
  var _useExplorer = useExplorer(),
    i18n = _useExplorer.i18n,
    info = _useExplorer.info,
    _useExplorer$opts = _useExplorer.opts,
    noImgOperationsAndDownload = _useExplorer$opts.noImgOperationsAndDownload,
    preventDownloadDefaultBehavior = _useExplorer$opts.preventDownloadDefaultBehavior;
  var shareFile = function shareFile() {
    return dispatch(sharePanelOpened({
      "for": [file.uuid],
      closeOthers: true
    }));
  };
  var copyLinkToClipboard = function copyLinkToClipboard() {
    copyText(getFileLink(file), i18n, info);
  };
  var download = function download(event) {
    event.stopPropagation();
    if (preventDownloadDefaultBehavior) {
      var _file$url;
      dispatch(emitExportEvent([{
        link: file === null || file === void 0 ? void 0 : (_file$url = file.url) === null || _file$url === void 0 ? void 0 : _file$url.cdn,
        file: file
      }]));
      return;
    }
    var urlTypeToChoose = isShareboxView && 'cdn';
    triggerDownloadConsentModal(function () {
      return dispatch(downloadOneFile({
        file: file,
        urlTypeToChoose: urlTypeToChoose
      }));
    });
  };
  var options = useMemo(function () {
    return [{
      key: 'GridLi-PreviewFile',
      Icon: Preview,
      iconSize: 12,
      onClick: toggleFileWindow,
      hidden: !isPreviewSupported(file)
    }, {
      key: 'GridLi-CopyLink',
      Icon: Link,
      iconSize: 12,
      onClick: copyLinkToClipboard
    }, {
      key: 'GridLi-DownloadFile',
      Icon: Download,
      iconSize: 12,
      onClick: download,
      hidden: noImgOperationsAndDownload
    }, {
      key: 'GridLi-ShareFile',
      Icon: Share,
      iconSize: 12,
      onClick: shareFile,
      hidden: isShareboxView || !isUserPermittedToShare
    }, {
      key: 'GridLi-OpenMenu',
      Icon: More,
      iconSize: 12,
      onClick: onContextMenu,
      hidden: isShareboxView
    }];
  }, [file, isShareboxView, noImgOperationsAndDownload, isUserPermittedToShare]);
  return /*#__PURE__*/_jsx(ItemHoverTopOptions, _objectSpread({
    options: options,
    onContextMenu: onContextMenu
  }, props));
};
export default FileTopOptions;