seeder-resources-view 1.0.14 → 1.2.0

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.
package/dist/index.esm.js CHANGED
@@ -17765,41 +17765,59 @@ const TreeTitleNode = _ref2 => {
17765
17765
  var TreeTitle$1 = /*#__PURE__*/memo(TreeTitle);
17766
17766
 
17767
17767
  const buildDirectoryTree = function (data) {
17768
- let basePath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '0';
17769
- let parentRoute = arguments.length > 2 ? arguments[2] : undefined;
17768
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17769
+ const {
17770
+ withRoot = true
17771
+ } = options; // 默认包含 root 节点
17772
+
17770
17773
  if (!Array.isArray(data)) return [];
17771
- return data.reduce((acc, item, index) => {
17772
- var _item$sd_index;
17773
- // 跳过文件类型,只处理目录
17774
- if (item.type === 'file') return acc;
17775
- const title = parentRoute ? item.name : (_item$sd_index = item.sd_index) !== null && _item$sd_index !== void 0 ? _item$sd_index : item.name;
17776
- const key = "".concat(basePath, "-").concat(index);
17777
- const currentPath = parentRoute ? "".concat(parentRoute, "/").concat(title) : item.path;
17778
- const treeNode = {
17779
- title,
17780
- // 文件/文件夹名称
17781
- key,
17782
- icon: _ref => {
17783
- let {
17784
- expanded
17785
- } = _ref;
17786
- return expanded ? /*#__PURE__*/jsx(FolderOpenOutlined, {}) : /*#__PURE__*/jsx(FolderOutlined, {});
17787
- },
17788
- children: [],
17789
- isLeaf: false,
17790
- isRoot: Boolean(item.sd_index),
17791
- path: currentPath,
17792
- contents: (item.contents || []).filter(content => content.type === 'file'),
17793
- rawData: item // 保留原始数据
17794
- };
17795
17774
 
17796
- // 递归处理子目录
17797
- if (Array.isArray(item.contents) && item.contents.length > 0) {
17798
- treeNode.children = buildDirectoryTree(item.contents.filter(content => content.type !== 'file'), key, currentPath);
17799
- }
17800
- acc.push(treeNode);
17801
- return acc;
17802
- }, []);
17775
+ // 如果需要 root 节点,包装一层
17776
+ const processedData = withRoot ? [{
17777
+ name: 'root',
17778
+ type: 'directory',
17779
+ contents: data
17780
+ }] : data;
17781
+
17782
+ // 递归构建树
17783
+ const build = function (nodes) {
17784
+ let basePath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '0';
17785
+ let parentRoute = arguments.length > 2 ? arguments[2] : undefined;
17786
+ return nodes.reduce((acc, item, index) => {
17787
+ var _item$sd_index, _item$path;
17788
+ // 跳过文件类型,只处理目录
17789
+ if (item.type === 'file') return acc;
17790
+ const title = parentRoute ? item.name : (_item$sd_index = item.sd_index) !== null && _item$sd_index !== void 0 ? _item$sd_index : item.name;
17791
+ const key = "".concat(basePath, "-").concat(index);
17792
+ const currentPath = parentRoute ? "".concat(parentRoute, "/").concat(title) : (_item$path = item.path) !== null && _item$path !== void 0 ? _item$path : item.name;
17793
+ const treeNode = {
17794
+ title,
17795
+ // 文件/文件夹名称
17796
+ key,
17797
+ icon: _ref => {
17798
+ let {
17799
+ expanded
17800
+ } = _ref;
17801
+ return expanded ? /*#__PURE__*/jsx(FolderOpenOutlined, {}) : /*#__PURE__*/jsx(FolderOutlined, {});
17802
+ },
17803
+ children: [],
17804
+ isLeaf: false,
17805
+ // isRoot: Boolean(item.sd_index),
17806
+ isRoot: !parentRoute,
17807
+ path: currentPath,
17808
+ contents: (item.contents || []).filter(content => content.type === 'file'),
17809
+ rawData: item // 保留原始数据
17810
+ };
17811
+
17812
+ // 递归处理子目录
17813
+ if (Array.isArray(item.contents) && item.contents.length > 0) {
17814
+ treeNode.children = build(item.contents.filter(content => content.type !== 'file'), key, currentPath);
17815
+ }
17816
+ acc.push(treeNode);
17817
+ return acc;
17818
+ }, []);
17819
+ };
17820
+ return build(processedData);
17803
17821
  };
17804
17822
 
17805
17823
  /**
@@ -17852,6 +17870,8 @@ const useDirectoryTree = _ref => {
17852
17870
  createFolder,
17853
17871
  removeFolderFile,
17854
17872
  renameFolderFile,
17873
+ batchOperations = true,
17874
+ withRootNode = true,
17855
17875
  height = 828,
17856
17876
  theme = {
17857
17877
  components: {
@@ -17882,13 +17902,14 @@ const useDirectoryTree = _ref => {
17882
17902
 
17883
17903
  // 路径处理工具
17884
17904
  const pathUtils = {
17905
+ replaceRoot: path => path.replace(/^root\//, ''),
17885
17906
  getNewPath: (node, newTitle) => {
17886
17907
  const arr = node.path.split('/');
17887
17908
  arr[arr.length - 1] = newTitle;
17888
17909
  return arr.join('/');
17889
17910
  },
17890
17911
  isSamePath: (path1, path2) => {
17891
- return path1 === path2;
17912
+ return pathUtils.replaceRoot(path1) === pathUtils.replaceRoot(path2);
17892
17913
  }
17893
17914
  };
17894
17915
 
@@ -17912,7 +17933,9 @@ const useDirectoryTree = _ref => {
17912
17933
  setOriginTreeData(data.directoryTree);
17913
17934
 
17914
17935
  // 递归生成treenodes
17915
- const treeNodes = buildDirectoryTree(data.directoryTree);
17936
+ const treeNodes = buildDirectoryTree(data.directoryTree, {
17937
+ withRoot: withRootNode
17938
+ });
17916
17939
  if (!treeNodes.length) {
17917
17940
  return null;
17918
17941
  }
@@ -17930,7 +17953,7 @@ const useDirectoryTree = _ref => {
17930
17953
  } catch (error) {
17931
17954
  handleError(error, 'GET FOLDER DATA');
17932
17955
  }
17933
- }, []);
17956
+ }, [withRootNode]);
17934
17957
 
17935
17958
  // 初始化数据
17936
17959
  useEffect(() => {
@@ -17942,7 +17965,7 @@ const useDirectoryTree = _ref => {
17942
17965
  if (!(newTitle !== null && newTitle !== void 0 && newTitle.trim())) return false;
17943
17966
  try {
17944
17967
  var _parentNode$;
17945
- const path = "".concat(node.path, "/").concat(newTitle);
17968
+ const path = pathUtils.replaceRoot("".concat(node.path, "/").concat(newTitle));
17946
17969
  await createFolder({
17947
17970
  path
17948
17971
  });
@@ -17969,10 +17992,12 @@ const useDirectoryTree = _ref => {
17969
17992
  const handleRemove = useCallback(async node => {
17970
17993
  if (!node.path) return;
17971
17994
  try {
17972
- await removeFolderFile({
17995
+ batchOperations ? await removeFolderFile({
17973
17996
  paths: [{
17974
- path: node.path
17997
+ path: pathUtils.replaceRoot(node.path)
17975
17998
  }]
17999
+ }) : await removeFolderFile({
18000
+ path: pathUtils.replaceRoot(node.path)
17976
18001
  });
17977
18002
  // 如果删除的是当前选中节点,则重新初始化
17978
18003
  const shouldReinitialize = treeState.selectedKeys[0] === node.key;
@@ -17988,8 +18013,8 @@ const useDirectoryTree = _ref => {
17988
18013
  if (pathUtils.isSamePath(node.path, newPath)) return false;
17989
18014
  try {
17990
18015
  await renameFolderFile({
17991
- old_path: node.path,
17992
- new_path: newPath
18016
+ old_path: pathUtils.replaceRoot(node.path),
18017
+ new_path: pathUtils.replaceRoot(newPath)
17993
18018
  });
17994
18019
  await fetchFolderData();
17995
18020
  } catch (error) {
@@ -18133,6 +18158,7 @@ const ResourcesView = _ref => {
18133
18158
  style = {},
18134
18159
  renderTreeHeader,
18135
18160
  renderGridHeader,
18161
+ withRootNode = true,
18136
18162
  acceptFileTypes = "video/*,.mxf,application/mxf,video/mxf",
18137
18163
  uploadTimeout = 60 * 60 * 1000,
18138
18164
  searchPlaceholder = "Search ..."
@@ -18167,7 +18193,9 @@ const ResourcesView = _ref => {
18167
18193
  getFolderData: mergedApiConfig.getFolderData,
18168
18194
  createFolder: mergedApiConfig.createFolder,
18169
18195
  removeFolderFile: mergedApiConfig.removeFolderFile,
18170
- renameFolderFile: mergedApiConfig.renameFolderFile
18196
+ renameFolderFile: mergedApiConfig.renameFolderFile,
18197
+ batchOperations: mergedFeatures.batchOperations,
18198
+ withRootNode
18171
18199
  });
18172
18200
  const [showProgress, setShowProgress] = useState(false);
18173
18201
  const [percent, setPercent] = useState(0);