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    
@filerobot/explorer / lib / components / FoldersView / FoldersTree / FoldersTree.utils.js
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); }
import { SORT_BY, SORT_ORDER } from '../../common/Sort/Sort.constants';
export var extractFolderTreeSlice = function extractFolderTreeSlice(folder) {
  var _folder$count, _folder$size, _folder$childrenUuids, _folder$isExpanded, _folder$isLoaded, _folder$loading, _folder$error, _folder$visibility;
  return {
    // name, created_at, modified_at, assets_count, size, props should always have the name as SORT_BY props
    uuid: folder.uuid,
    path: folder.path,
    name: folder.name,
    created_at: folder.created_at,
    modified_at: folder.updated_at,
    assets_count: (_folder$count = folder.count) === null || _folder$count === void 0 ? void 0 : _folder$count.files_recursive,
    size: (_folder$size = folder.size) === null || _folder$size === void 0 ? void 0 : _folder$size.total_recursive_bytes,
    parentUuid: folder.parentUuid,
    childrenUuids: (_folder$childrenUuids = folder.childrenUuids) !== null && _folder$childrenUuids !== void 0 ? _folder$childrenUuids : [],
    isExpanded: (_folder$isExpanded = folder.isExpanded) !== null && _folder$isExpanded !== void 0 ? _folder$isExpanded : false,
    isLoaded: (_folder$isLoaded = folder.isLoaded) !== null && _folder$isLoaded !== void 0 ? _folder$isLoaded : false,
    loading: (_folder$loading = folder.loading) !== null && _folder$loading !== void 0 ? _folder$loading : false,
    error: (_folder$error = folder.error) !== null && _folder$error !== void 0 ? _folder$error : null,
    isFolder: true,
    type: 'folder',
    visibility: (_folder$visibility = folder.visibility) !== null && _folder$visibility !== void 0 ? _folder$visibility : null
  };
};
export var getNormalizedFoldersSlicesByUuids = function getNormalizedFoldersSlicesByUuids(folders, parentUuid) {
  if ((folders === null || folders === void 0 ? void 0 : folders.length) === 0) return {
    normalizedFoldersSlices: {},
    uuids: []
  };
  var normalizedFoldersSlices = folders.reduce(function (foldersByUuid, folder) {
    return _objectSpread(_objectSpread({}, foldersByUuid), {}, _defineProperty({}, folder.uuid, extractFolderTreeSlice(_objectSpread(_objectSpread({}, folder), {}, {
      parentUuid: parentUuid !== null && parentUuid !== void 0 ? parentUuid : folder.parentUuid
    }))));
  }, {});
  return {
    normalizedFoldersSlices: normalizedFoldersSlices,
    uuids: Object.keys(normalizedFoldersSlices)
  };
};

// This works good as long as the folder path doesn't end with (/) slash.
export var isDirectChildFolder = function isDirectChildFolder(folderPath, parentFolderPath) {
  return folderPath.slice(0, folderPath.lastIndexOf('/')) === parentFolderPath;
};
export var getSortedFoldersUuids = function getSortedFoldersUuids(_ref) {
  var sortOrder = _ref.sortOrder,
    sortedBy = _ref.sortedBy,
    allFolders = _ref.allFolders,
    foldersUuidsToSort = _ref.foldersUuidsToSort;
  var orderFactor = sortOrder === SORT_ORDER.DSC ? -1 : 1;
  if (sortedBy === SORT_BY.NAME) {
    var getStringWithoutSpecialChars = function getStringWithoutSpecialChars(string) {
      return string.replace(/[$&+,:;=?@#|'<>.*()%!{}_-]/g, '');
    };
    return foldersUuidsToSort.sort(function (aUuid, bUuid) {
      var _allFolders$aUuid, _allFolders$bUuid;
      var firstName = getStringWithoutSpecialChars((_allFolders$aUuid = allFolders[aUuid]) === null || _allFolders$aUuid === void 0 ? void 0 : _allFolders$aUuid[sortedBy]);
      var secondName = getStringWithoutSpecialChars((_allFolders$bUuid = allFolders[bUuid]) === null || _allFolders$bUuid === void 0 ? void 0 : _allFolders$bUuid[sortedBy]);
      return firstName.toLowerCase().localeCompare(secondName.toLowerCase()) * orderFactor;
    });
  }
  return foldersUuidsToSort.sort(function (aUuid, bUuid) {
    var _allFolders$aUuid2, _allFolders$bUuid2;
    return (((_allFolders$aUuid2 = allFolders[aUuid]) === null || _allFolders$aUuid2 === void 0 ? void 0 : _allFolders$aUuid2[sortedBy]) > ((_allFolders$bUuid2 = allFolders[bUuid]) === null || _allFolders$bUuid2 === void 0 ? void 0 : _allFolders$bUuid2[sortedBy]) ? 1 : -1) * orderFactor;
  });
};
export var getParentFolderPath = function getParentFolderPath(path) {
  return path === null || path === void 0 ? void 0 : path.slice(0, path.lastIndexOf('/'));
};
export var getFolderItemKey = function getFolderItemKey(folder, index) {
  return "".concat(folder.uuid, "-").concat(index);
};