seeder-resources-view 1.0.14 → 1.3.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
@@ -17664,7 +17664,8 @@ const TreeTitleNode = _ref2 => {
17664
17664
  nodeData,
17665
17665
  handleSave,
17666
17666
  handleDel,
17667
- handleAdd
17667
+ handleAdd,
17668
+ isEditable = true
17668
17669
  } = _ref2;
17669
17670
  const [editing, setEditing] = useState(false);
17670
17671
  const inputRef = useRef(null);
@@ -17759,47 +17760,71 @@ const TreeTitleNode = _ref2 => {
17759
17760
  }, [editing, nodeData.title, save, title, renderIconNode]);
17760
17761
  return /*#__PURE__*/jsx("div", {
17761
17762
  className: "tree-title",
17762
- children: renderChildNode()
17763
+ children: isEditable ? renderChildNode() : /*#__PURE__*/jsx(Typography.Text, {
17764
+ ellipsis: true,
17765
+ style: {
17766
+ width: "100%%"
17767
+ },
17768
+ children: title
17769
+ })
17763
17770
  });
17764
17771
  };
17765
17772
  var TreeTitle$1 = /*#__PURE__*/memo(TreeTitle);
17766
17773
 
17767
17774
  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;
17775
+ let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
17776
+ const {
17777
+ withRoot = true
17778
+ } = options; // 默认包含 root 节点
17779
+
17770
17780
  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
17781
 
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
- }, []);
17782
+ // 如果需要 root 节点,包装一层
17783
+ const processedData = withRoot ? [{
17784
+ name: 'root',
17785
+ type: 'directory',
17786
+ contents: data
17787
+ }] : data;
17788
+
17789
+ // 递归构建树
17790
+ const build = function (nodes) {
17791
+ let basePath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '0';
17792
+ let parentRoute = arguments.length > 2 ? arguments[2] : undefined;
17793
+ return nodes.reduce((acc, item, index) => {
17794
+ var _item$sd_index, _item$path;
17795
+ // 跳过文件类型,只处理目录
17796
+ if (item.type === 'file') return acc;
17797
+ const title = parentRoute ? item.name : (_item$sd_index = item.sd_index) !== null && _item$sd_index !== void 0 ? _item$sd_index : item.name;
17798
+ const key = "".concat(basePath, "-").concat(index);
17799
+ const currentPath = parentRoute ? "".concat(parentRoute, "/").concat(title) : (_item$path = item.path) !== null && _item$path !== void 0 ? _item$path : item.name;
17800
+ const treeNode = {
17801
+ title,
17802
+ // 文件/文件夹名称
17803
+ key,
17804
+ icon: _ref => {
17805
+ let {
17806
+ expanded
17807
+ } = _ref;
17808
+ return expanded ? /*#__PURE__*/jsx(FolderOpenOutlined, {}) : /*#__PURE__*/jsx(FolderOutlined, {});
17809
+ },
17810
+ children: [],
17811
+ isLeaf: false,
17812
+ // isRoot: Boolean(item.sd_index),
17813
+ isRoot: !parentRoute,
17814
+ path: currentPath,
17815
+ contents: (item.contents || []).filter(content => content.type === 'file'),
17816
+ rawData: item // 保留原始数据
17817
+ };
17818
+
17819
+ // 递归处理子目录
17820
+ if (Array.isArray(item.contents) && item.contents.length > 0) {
17821
+ treeNode.children = build(item.contents.filter(content => content.type !== 'file'), key, currentPath);
17822
+ }
17823
+ acc.push(treeNode);
17824
+ return acc;
17825
+ }, []);
17826
+ };
17827
+ return build(processedData);
17803
17828
  };
17804
17829
 
17805
17830
  /**
@@ -17852,6 +17877,10 @@ const useDirectoryTree = _ref => {
17852
17877
  createFolder,
17853
17878
  removeFolderFile,
17854
17879
  renameFolderFile,
17880
+ mediaType,
17881
+ isEditable = true,
17882
+ batchOperations = true,
17883
+ withRootNode = true,
17855
17884
  height = 828,
17856
17885
  theme = {
17857
17886
  components: {
@@ -17882,13 +17911,14 @@ const useDirectoryTree = _ref => {
17882
17911
 
17883
17912
  // 路径处理工具
17884
17913
  const pathUtils = {
17914
+ replaceRoot: path => path.replace(/^root\//, ''),
17885
17915
  getNewPath: (node, newTitle) => {
17886
17916
  const arr = node.path.split('/');
17887
17917
  arr[arr.length - 1] = newTitle;
17888
17918
  return arr.join('/');
17889
17919
  },
17890
17920
  isSamePath: (path1, path2) => {
17891
- return path1 === path2;
17921
+ return pathUtils.replaceRoot(path1) === pathUtils.replaceRoot(path2);
17892
17922
  }
17893
17923
  };
17894
17924
 
@@ -17903,16 +17933,23 @@ const useDirectoryTree = _ref => {
17903
17933
  const fetchFolderData = useCallback(async function () {
17904
17934
  let initialization = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
17905
17935
  try {
17906
- const data = await getFolderData({
17936
+ // 构建请求参数
17937
+ const requestParams = {
17907
17938
  folder: ""
17908
- });
17939
+ };
17940
+ if (mediaType) {
17941
+ requestParams.media_type = mediaType;
17942
+ }
17943
+ const data = await getFolderData(requestParams);
17909
17944
  if (!(data !== null && data !== void 0 && data.directoryTree)) {
17910
17945
  return null;
17911
17946
  }
17912
17947
  setOriginTreeData(data.directoryTree);
17913
17948
 
17914
17949
  // 递归生成treenodes
17915
- const treeNodes = buildDirectoryTree(data.directoryTree);
17950
+ const treeNodes = buildDirectoryTree(data.directoryTree, {
17951
+ withRoot: withRootNode
17952
+ });
17916
17953
  if (!treeNodes.length) {
17917
17954
  return null;
17918
17955
  }
@@ -17930,7 +17967,7 @@ const useDirectoryTree = _ref => {
17930
17967
  } catch (error) {
17931
17968
  handleError(error, 'GET FOLDER DATA');
17932
17969
  }
17933
- }, []);
17970
+ }, [mediaType, withRootNode]);
17934
17971
 
17935
17972
  // 初始化数据
17936
17973
  useEffect(() => {
@@ -17942,7 +17979,7 @@ const useDirectoryTree = _ref => {
17942
17979
  if (!(newTitle !== null && newTitle !== void 0 && newTitle.trim())) return false;
17943
17980
  try {
17944
17981
  var _parentNode$;
17945
- const path = "".concat(node.path, "/").concat(newTitle);
17982
+ const path = pathUtils.replaceRoot("".concat(node.path, "/").concat(newTitle));
17946
17983
  await createFolder({
17947
17984
  path
17948
17985
  });
@@ -17969,10 +18006,12 @@ const useDirectoryTree = _ref => {
17969
18006
  const handleRemove = useCallback(async node => {
17970
18007
  if (!node.path) return;
17971
18008
  try {
17972
- await removeFolderFile({
18009
+ batchOperations ? await removeFolderFile({
17973
18010
  paths: [{
17974
- path: node.path
18011
+ path: pathUtils.replaceRoot(node.path)
17975
18012
  }]
18013
+ }) : await removeFolderFile({
18014
+ path: pathUtils.replaceRoot(node.path)
17976
18015
  });
17977
18016
  // 如果删除的是当前选中节点,则重新初始化
17978
18017
  const shouldReinitialize = treeState.selectedKeys[0] === node.key;
@@ -17988,8 +18027,8 @@ const useDirectoryTree = _ref => {
17988
18027
  if (pathUtils.isSamePath(node.path, newPath)) return false;
17989
18028
  try {
17990
18029
  await renameFolderFile({
17991
- old_path: node.path,
17992
- new_path: newPath
18030
+ old_path: pathUtils.replaceRoot(node.path),
18031
+ new_path: pathUtils.replaceRoot(newPath)
17993
18032
  });
17994
18033
  await fetchFolderData();
17995
18034
  } catch (error) {
@@ -18075,6 +18114,7 @@ const useDirectoryTree = _ref => {
18075
18114
  titleRender: nodeData => /*#__PURE__*/jsx(TreeTitle$1, {
18076
18115
  title: nodeData.title,
18077
18116
  nodeData: nodeData,
18117
+ isEditable: isEditable,
18078
18118
  handleSave: handleRename,
18079
18119
  handleDel: handleRemove,
18080
18120
  handleAdd: handleCreate
@@ -18133,6 +18173,7 @@ const ResourcesView = _ref => {
18133
18173
  style = {},
18134
18174
  renderTreeHeader,
18135
18175
  renderGridHeader,
18176
+ withRootNode = true,
18136
18177
  acceptFileTypes = "video/*,.mxf,application/mxf,video/mxf",
18137
18178
  uploadTimeout = 60 * 60 * 1000,
18138
18179
  searchPlaceholder = "Search ..."
@@ -18167,7 +18208,9 @@ const ResourcesView = _ref => {
18167
18208
  getFolderData: mergedApiConfig.getFolderData,
18168
18209
  createFolder: mergedApiConfig.createFolder,
18169
18210
  removeFolderFile: mergedApiConfig.removeFolderFile,
18170
- renameFolderFile: mergedApiConfig.renameFolderFile
18211
+ renameFolderFile: mergedApiConfig.renameFolderFile,
18212
+ batchOperations: mergedFeatures.batchOperations,
18213
+ withRootNode
18171
18214
  });
18172
18215
  const [showProgress, setShowProgress] = useState(false);
18173
18216
  const [percent, setPercent] = useState(0);