seeder-st2110-components 1.3.4 → 1.3.5

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.js CHANGED
@@ -54,7 +54,7 @@ var useHardwareWebSocket$1 = useHardwareWebSocket;
54
54
 
55
55
  const formatBytes = function (bytes) {
56
56
  let decimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
57
- if (bytes === 0 || !bytes) return '0 Bytes';
57
+ if (bytes === 0 || !bytes || bytes < 0) return '0 Bytes';
58
58
  const k = 1024;
59
59
  const dm = decimals < 0 ? 0 : decimals;
60
60
  const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
@@ -937,18 +937,6 @@ const TreeTitleNode = _ref2 => {
937
937
  };
938
938
  var TreeTitle$1 = /*#__PURE__*/react.memo(TreeTitle);
939
939
 
940
- const replaceRootPath = path => {
941
- if (typeof path !== 'string') return '';
942
- return path.startsWith('root/') ? path.slice(5) : path;
943
- };
944
-
945
- /**
946
- * 递归转换目录结构为树形结构
947
- * @param {Array} data - 原始数据
948
- * @param {string} [basePath='0'] - 基础路径
949
- * @param {string} [parentRoute] - 父级路由路径
950
- * @returns {Array} 转换后的树形结构
951
- */
952
940
  const buildDirectoryTree = function (data) {
953
941
  let basePath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '0';
954
942
  let parentRoute = arguments.length > 2 ? arguments[2] : undefined;
@@ -956,9 +944,9 @@ const buildDirectoryTree = function (data) {
956
944
  return data.reduce((acc, item, index) => {
957
945
  // 跳过文件类型,只处理目录
958
946
  if (item.type === 'file') return acc;
959
- const title = parentRoute ? item.name : item.sd_index || item.name;
947
+ const title = parentRoute ? item.name : item.sd_index ?? item.name;
960
948
  const key = `${basePath}-${index}`;
961
- const currentPath = parentRoute ? `${parentRoute}/${title}` : item.path || title;
949
+ const currentPath = parentRoute ? `${parentRoute}/${title}` : item.path;
962
950
  const treeNode = {
963
951
  title,
964
952
  // 文件/文件夹名称
@@ -1069,14 +1057,13 @@ const useDirectoryTree = _ref => {
1069
1057
 
1070
1058
  // 路径处理工具
1071
1059
  const pathUtils = {
1072
- replaceRoot: path => replaceRootPath(path),
1073
1060
  getNewPath: (node, newTitle) => {
1074
1061
  const arr = node.path.split('/');
1075
1062
  arr[arr.length - 1] = newTitle;
1076
1063
  return arr.join('/');
1077
1064
  },
1078
1065
  isSamePath: (path1, path2) => {
1079
- return pathUtils.replaceRoot(path1) === pathUtils.replaceRoot(path2);
1066
+ return path1 === path2;
1080
1067
  }
1081
1068
  };
1082
1069
 
@@ -1099,30 +1086,23 @@ const useDirectoryTree = _ref => {
1099
1086
  }
1100
1087
  setOriginTreeData(data.directoryTree);
1101
1088
 
1102
- // 构建根节点并生成树结构
1103
- const rootNode = {
1104
- name: 'root',
1105
- type: 'directory',
1106
- contents: data.directoryTree
1107
- };
1108
1089
  // 递归生成treenodes
1109
- const treeNodes = buildDirectoryTree([rootNode]);
1110
- const rootChildren = treeNodes[0]?.children || [];
1111
- if (!rootChildren.length) {
1090
+ const treeNodes = buildDirectoryTree(data.directoryTree);
1091
+ if (!treeNodes.length) {
1112
1092
  return null;
1113
1093
  }
1114
- const firstChild = rootChildren[0];
1094
+ const firstChild = treeNodes[0];
1115
1095
  const newState = {
1116
- data: rootChildren,
1096
+ data: treeNodes,
1117
1097
  ...(initialization && {
1118
1098
  selectedKeys: [firstChild?.key],
1119
- expandedKeys: getAllNodeKeys(rootChildren),
1099
+ expandedKeys: getAllNodeKeys(treeNodes),
1120
1100
  currentPath: firstChild?.path,
1121
1101
  contents: firstChild?.contents || []
1122
1102
  })
1123
1103
  };
1124
1104
  updateTreeState(newState);
1125
- return rootChildren;
1105
+ return treeNodes;
1126
1106
  } catch (error) {
1127
1107
  handleError(error, 'GET FOLDER DATA');
1128
1108
  }
@@ -1137,7 +1117,7 @@ const useDirectoryTree = _ref => {
1137
1117
  const handleCreate = react.useCallback(async (node, newTitle) => {
1138
1118
  if (!newTitle?.trim()) return false;
1139
1119
  try {
1140
- const path = pathUtils.replaceRoot(`${node.path}/${newTitle}`);
1120
+ const path = `${node.path}/${newTitle}`;
1141
1121
  await createFolder({
1142
1122
  path
1143
1123
  });
@@ -1146,8 +1126,9 @@ const useDirectoryTree = _ref => {
1146
1126
  // 找到新增节点的父节点
1147
1127
  const parentNode = nodeUtils.findNode(newTreeData, node.key);
1148
1128
  if (parentNode?.[0]?.children) {
1129
+ const expectedPath = `${node.path}/${newTitle}`;
1149
1130
  // 通过 path 找到新增节点,得到新增节点的key
1150
- const addedNode = parentNode[0].children.find(ch => pathUtils.isSamePath(ch.path, `root/${newTitle}`));
1131
+ const addedNode = parentNode[0].children.find(ch => pathUtils.isSamePath(ch.path, expectedPath));
1151
1132
  if (addedNode) {
1152
1133
  updateTreeState({
1153
1134
  expandedKeys: [...treeState.expandedKeys, addedNode.key, parentNode[0].key]
@@ -1165,7 +1146,7 @@ const useDirectoryTree = _ref => {
1165
1146
  try {
1166
1147
  await removeFolderFile({
1167
1148
  paths: [{
1168
- path: pathUtils.replaceRoot(node.path)
1149
+ path: node.path
1169
1150
  }]
1170
1151
  });
1171
1152
  // 如果删除的是当前选中节点,则重新初始化
@@ -1182,8 +1163,8 @@ const useDirectoryTree = _ref => {
1182
1163
  if (pathUtils.isSamePath(node.path, newPath)) return false;
1183
1164
  try {
1184
1165
  await renameFolderFile({
1185
- old_path: pathUtils.replaceRoot(node.path),
1186
- new_path: pathUtils.replaceRoot(newPath)
1166
+ old_path: node.path,
1167
+ new_path: newPath
1187
1168
  });
1188
1169
  await fetchFolderData();
1189
1170
  } catch (error) {