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:
var _excluded = ["fileUuid", "handleNavigatingThroughArrows", "hideTopOptions"];
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; }
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, useState, useCallback } from 'react';
import { useSelector, useDispatch } from 'react-redux';
import { Play } from '@scaleflex/icons';
import FileInfo from '@filerobot/explorer/lib/components/FileItem/FileInfo';
import formatSeconds from '@filerobot/utils/lib/formatSeconds';
import _getItemIcon from '@filerobot/utils/lib/getItemIcon';
import isPreviewSupported from '@filerobot/utils/lib/isPreviewSupported';
import { ItemHoverTopOptions, AssetPreview } from '@filerobot/common';
import ignoreEvent from '@filerobot/utils/lib/ignoreEvent';
import { TooltipV2 } from '@scaleflex/ui/core';
import DnD from '../../../DnD';
import FileTopOptions from './FileTopOptions';
import FileBottomOptions from './FileBottomOptions';
import Styled from '../../AssetsList.styled';
import relevanceBadge from '../../relevanceBadge';
import { useExplorer } from '../../../../hooks';
import { fileWindowUpdated, selectRenameItemFor } from '../../../../slices/panels.slice';
import { selectIsItemChecked, toggleSelection } from '../../../../slices/selections.slice';
import { selectSearchQuery } from '../../../../slices/search.slice';
import { selectIsRelevanceAvailable } from '@filerobot/core/lib/slices/common.slice';
import { selectCurrentFileByUuid } from '../../../../slices/files.slice';
import { selectIsAssetsView, selectIsSearchOrFiltersView, selectIsShareboxView, selectViewLayout } from '../../../../slices/views.slice';
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
import { Fragment as _Fragment } from "react/jsx-runtime";
var checkboxOnChange = function checkboxOnChange() {};
var FileCell = function FileCell(_ref) {
  var fileUuid = _ref.fileUuid,
    handleNavigatingThroughArrows = _ref.handleNavigatingThroughArrows,
    hideTopOptions = _ref.hideTopOptions,
    props = _objectWithoutProperties(_ref, _excluded);
  var dispatch = useDispatch();
  var _useExplorer = useExplorer(),
    i18n = _useExplorer.i18n,
    container = _useExplorer.container,
    isDevEnv = _useExplorer.isDevEnv,
    opts = _useExplorer.opts;
  var renameItemFor = useSelector(selectRenameItemFor);
  var isChecked = useSelector(function (state) {
    return selectIsItemChecked(state, fileUuid);
  });
  var isRelevanceAvailable = useSelector(selectIsRelevanceAvailable);
  var searchQuery = useSelector(selectSearchQuery);
  var fromSearch = useSelector(selectIsSearchOrFiltersView);
  var isAssetsView = useSelector(selectIsAssetsView);
  var isShareboxView = useSelector(selectIsShareboxView);
  var viewLayout = useSelector(selectViewLayout);
  var file = useSelector(function (state) {
    return selectCurrentFileByUuid(state, fileUuid);
  });
  var _useState = useState(false),
    _useState2 = _slicedToArray(_useState, 2),
    showVideoGif = _useState2[0],
    setShowVideoGif = _useState2[1];
  var floaty = opts.floaty,
    showMeta = opts.showMeta,
    disableMultipleSelect = opts.disableMultipleSelect,
    disableFilesContextMenu = opts.disableFilesContextMenu,
    hideFileOptions = opts.hideFileOptions;
  var isSearchMode = isAssetsView && searchQuery;
  var id = file.uuid;
  var fileName = file.name;
  var isLoading = file.loading;
  var showSearchDebugInfo = JSON.parse(localStorage.getItem('debug_search')) || false;
  var handleSelect = function handleSelect(event) {
    if (isLoading) {
      return;
    }
    dispatch(toggleSelection({
      event: event,
      itemUuid: id,
      isMultiple: !!event.isMultiple
    }));
  };
  var handleOnContextMenu = function handleOnContextMenu(event) {
    if (!isLoading && !disableFilesContextMenu && typeof props.handleContextMenuToggle === 'function') {
      props.handleContextMenuToggle(event, file);
    }
  };
  var toggleFileWindow = useCallback(function (event) {
    if (event.target.tagName === 'INPUT' || isLoading) return;
    dispatch(fileWindowUpdated(id));
  }, [file]);
  var isItemBeingRenamed = renameItemFor === id;
  var isFileChecked = isChecked;
  var options = useMemo(function () {
    return [{
      key: 'GridLi-PreviewVideo',
      Icon: Play,
      iconSize: 22,
      onClick: toggleFileWindow,
      hidden: !isPreviewSupported(file)
    }];
  }, [file]);
  var handleMouseOver = function handleMouseOver() {
    var _file$info, _file$info2;
    if (isLoading) {
      return;
    }
    if (showSearchDebugInfo && fromSearch) {
      console.log('Name: ', file.name);
      console.log('Uuid:', file.uuid);
      console.log('Relevance Score:', file.relevance);
      console.log('Debug Search:', file.debug_search);
      console.log('________________________');
    }
    if ((_file$info = file.info) !== null && _file$info !== void 0 && _file$info.video_gif || (_file$info2 = file.info) !== null && _file$info2 !== void 0 && _file$info2.video_thumbnail) {
      setShowVideoGif(true);
    }
  };
  var handleMouseLeave = function handleMouseLeave() {
    var _file$info3, _file$info4;
    if (isLoading) {
      return;
    }
    if ((_file$info3 = file.info) !== null && _file$info3 !== void 0 && _file$info3.video_gif || (_file$info4 = file.info) !== null && _file$info4 !== void 0 && _file$info4.video_thumbnail) {
      setShowVideoGif(false);
    }
  };
  var getSearchDebugInfo = function getSearchDebugInfo() {
    var _file$debug_search;
    return /*#__PURE__*/_jsxs(_Fragment, {
      children: [/*#__PURE__*/_jsx(Styled.RelevanceScore, {
        children: "Score: ".concat(file.relevance)
      }), /*#__PURE__*/_jsx("table", {
        children: Object.keys((file === null || file === void 0 ? void 0 : (_file$debug_search = file.debug_search) === null || _file$debug_search === void 0 ? void 0 : _file$debug_search.details) || {}).map(function (item, key) {
          var _file$debug_search2, _file$debug_search2$d;
          return /*#__PURE__*/_jsxs("tr", {
            children: [/*#__PURE__*/_jsxs("td", {
              children: [item, ":"]
            }), /*#__PURE__*/_jsx("td", {
              children: file === null || file === void 0 ? void 0 : (_file$debug_search2 = file.debug_search) === null || _file$debug_search2 === void 0 ? void 0 : (_file$debug_search2$d = _file$debug_search2.details) === null || _file$debug_search2$d === void 0 ? void 0 : _file$debug_search2$d[item]
            })]
          }, key);
        })
      })]
    });
  };
  var renderFileCell = function renderFileCell() {
    var _file$info5, _file$info6, _file$info7;
    return /*#__PURE__*/_jsxs(Styled.FileSectionItem, {
      className: "".concat(props.isDragging ? ' filerobot-Dragging-files' : ''),
      onKeyDown: isLoading ? undefined : handleNavigatingThroughArrows,
      "data-filerobot-focusable-uuid": id,
      tabIndex: "-1",
      onClick: handleSelect,
      onMouseOver: handleMouseOver,
      onMouseLeave: handleMouseLeave,
      onContextMenu: ignoreEvent,
      selected: isFileChecked,
      $loading: isLoading,
      children: [((_file$info5 = file.info) === null || _file$info5 === void 0 ? void 0 : _file$info5.video_duration) && /*#__PURE__*/_jsx(Styled.FileVideoDurationWrapper, {
        children: formatSeconds((_file$info6 = file.info) === null || _file$info6 === void 0 ? void 0 : _file$info6.video_duration)
      }), ((_file$info7 = file.info) === null || _file$info7 === void 0 ? void 0 : _file$info7.video_duration) && /*#__PURE__*/_jsx(Styled.FileVideoOptions, {
        children: /*#__PURE__*/_jsx(ItemHoverTopOptions, {
          options: options,
          style: {
            top: '25%',
            right: '37%'
          }
        })
      }), typeof isChecked !== 'undefined' && /*#__PURE__*/_jsx(Styled.FileSectionItemCheckbox, {
        // TODO: fix
        // we use onClick instead of onChange as onChange causes multiple rerenders
        // we add onChange as empty function to avoid type warning
        onClick: function onClick(e) {
          e.isMultiple = !disableMultipleSelect;
        },
        onChange: checkboxOnChange,
        checked: isFileChecked,
        onContextMenu: handleOnContextMenu,
        size: "md",
        selected: isFileChecked
      }), !hideTopOptions && !hideFileOptions && /*#__PURE__*/_jsx(FileTopOptions, {
        file: file,
        onContextMenu: handleOnContextMenu,
        toggleFileWindow: toggleFileWindow
      }), !isShareboxView && /*#__PURE__*/_jsx(FileBottomOptions, {
        file: file,
        onContextMenu: handleOnContextMenu
      }), isRelevanceAvailable && isSearchMode && relevanceBadge({
        relevance: file.relevance,
        isListView: false,
        isFileChecked: isFileChecked
      }), /*#__PURE__*/_jsxs(Styled.FileSectionItemButton, {
        type: "button",
        className: "filerobot-u-reset".concat(showMeta ? ' with-meta' : ''),
        onDoubleClick: toggleFileWindow,
        onContextMenu: handleOnContextMenu,
        role: "option",
        "aria-label": isFileChecked ? i18n('mutualizedUnselectFileNamedLabel', {
          name: fileName
        }) : i18n('mutualizedSelectFileNamedLabel', {
          name: props.title
        }),
        "aria-selected": isFileChecked,
        "aria-disabled": isFileChecked,
        children: [showMeta && /*#__PURE__*/_jsx(FileInfo, {
          file: file,
          containerWidth: props.containerWidth,
          showMeta: showMeta,
          handleContextMenuToggle: handleOnContextMenu,
          visibilities: props.visibilities,
          noTruncate: true,
          showFiles: props.showFiles
        }), /*#__PURE__*/_jsx(AssetPreview, {
          file: file,
          getItemIcon: function getItemIcon() {
            return _getItemIcon({
              fileOrFolder: file,
              viewLayout: viewLayout,
              forceIcon: false,
              showVideoGif: showVideoGif
            });
          },
          filePreviewToggle: toggleFileWindow,
          viewLayout: viewLayout,
          isDevEnv: isDevEnv,
          floaty: floaty,
          container: container
        })]
      })]
    });
  };
  return /*#__PURE__*/_jsx(DnD, {
    disableDrag: isItemBeingRenamed || isLoading,
    item: file,
    disableDrop: true,
    children: showSearchDebugInfo && fromSearch ? /*#__PURE__*/_jsx("div", {
      children: /*#__PURE__*/_jsx(TooltipV2, {
        arrow: true,
        position: "right",
        size: "md",
        title: getSearchDebugInfo(),
        children: renderFileCell()
      })
    }) : renderFileCell()
  });
};
export default FileCell;