seeder-st2110-components 1.3.3 → 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.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { useState, useCallback, useEffect, memo, useMemo, useRef, forwardRef, useContext, createContext } from 'react';
2
2
  import { useWebSocket, useInterval } from 'ahooks';
3
- import { Tooltip, Space, Divider, App, Modal, Form, Input, Alert, message, Dropdown, Spin, Popover, Flex as Flex$1, Button, Popconfirm, Typography, Empty, ConfigProvider, Tree, InputNumber, Badge, Switch, Select, List, Checkbox, Row, Col } from 'antd';
3
+ import { Tooltip, Space, Flex, Divider, App, Modal, Form, Input, Alert, message, Dropdown, Spin, Popover, Button, Popconfirm, Typography, Empty, ConfigProvider, Tree, InputNumber, Badge, Switch, Select, List, Checkbox, Row, Col } from 'antd';
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import { LoadingOutlined, ExclamationCircleFilled, FolderOpenOutlined, FolderOutlined, PlusOutlined } from '@ant-design/icons';
6
6
  import axios from 'axios';
@@ -52,7 +52,7 @@ var useHardwareWebSocket$1 = useHardwareWebSocket;
52
52
 
53
53
  const formatBytes = function (bytes) {
54
54
  let decimals = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
55
- if (bytes === 0 || !bytes) return '0 Bytes';
55
+ if (bytes === 0 || !bytes || bytes < 0) return '0 Bytes';
56
56
  const k = 1024;
57
57
  const dm = decimals < 0 ? 0 : decimals;
58
58
  const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
@@ -752,7 +752,7 @@ const PopoverContent = /*#__PURE__*/forwardRef((_ref, ref) => {
752
752
  },
753
753
  autoFocus: true
754
754
  })
755
- }), /*#__PURE__*/jsxs(Flex$1, {
755
+ }), /*#__PURE__*/jsxs(Flex, {
756
756
  justify: "flex-end",
757
757
  gap: "small",
758
758
  children: [/*#__PURE__*/jsx(Button, {
@@ -935,18 +935,6 @@ const TreeTitleNode = _ref2 => {
935
935
  };
936
936
  var TreeTitle$1 = /*#__PURE__*/memo(TreeTitle);
937
937
 
938
- const replaceRootPath = path => {
939
- if (typeof path !== 'string') return '';
940
- return path.startsWith('root/') ? path.slice(5) : path;
941
- };
942
-
943
- /**
944
- * 递归转换目录结构为树形结构
945
- * @param {Array} data - 原始数据
946
- * @param {string} [basePath='0'] - 基础路径
947
- * @param {string} [parentRoute] - 父级路由路径
948
- * @returns {Array} 转换后的树形结构
949
- */
950
938
  const buildDirectoryTree = function (data) {
951
939
  let basePath = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '0';
952
940
  let parentRoute = arguments.length > 2 ? arguments[2] : undefined;
@@ -954,9 +942,9 @@ const buildDirectoryTree = function (data) {
954
942
  return data.reduce((acc, item, index) => {
955
943
  // 跳过文件类型,只处理目录
956
944
  if (item.type === 'file') return acc;
957
- const title = parentRoute ? item.name : item.sd_index || item.name;
945
+ const title = parentRoute ? item.name : item.sd_index ?? item.name;
958
946
  const key = `${basePath}-${index}`;
959
- const currentPath = parentRoute ? `${parentRoute}/${title}` : item.path || title;
947
+ const currentPath = parentRoute ? `${parentRoute}/${title}` : item.path;
960
948
  const treeNode = {
961
949
  title,
962
950
  // 文件/文件夹名称
@@ -1067,14 +1055,13 @@ const useDirectoryTree = _ref => {
1067
1055
 
1068
1056
  // 路径处理工具
1069
1057
  const pathUtils = {
1070
- replaceRoot: path => replaceRootPath(path),
1071
1058
  getNewPath: (node, newTitle) => {
1072
1059
  const arr = node.path.split('/');
1073
1060
  arr[arr.length - 1] = newTitle;
1074
1061
  return arr.join('/');
1075
1062
  },
1076
1063
  isSamePath: (path1, path2) => {
1077
- return pathUtils.replaceRoot(path1) === pathUtils.replaceRoot(path2);
1064
+ return path1 === path2;
1078
1065
  }
1079
1066
  };
1080
1067
 
@@ -1097,30 +1084,23 @@ const useDirectoryTree = _ref => {
1097
1084
  }
1098
1085
  setOriginTreeData(data.directoryTree);
1099
1086
 
1100
- // 构建根节点并生成树结构
1101
- const rootNode = {
1102
- name: 'root',
1103
- type: 'directory',
1104
- contents: data.directoryTree
1105
- };
1106
1087
  // 递归生成treenodes
1107
- const treeNodes = buildDirectoryTree([rootNode]);
1108
- const rootChildren = treeNodes[0]?.children || [];
1109
- if (!rootChildren.length) {
1088
+ const treeNodes = buildDirectoryTree(data.directoryTree);
1089
+ if (!treeNodes.length) {
1110
1090
  return null;
1111
1091
  }
1112
- const firstChild = rootChildren[0];
1092
+ const firstChild = treeNodes[0];
1113
1093
  const newState = {
1114
- data: rootChildren,
1094
+ data: treeNodes,
1115
1095
  ...(initialization && {
1116
1096
  selectedKeys: [firstChild?.key],
1117
- expandedKeys: getAllNodeKeys(rootChildren),
1097
+ expandedKeys: getAllNodeKeys(treeNodes),
1118
1098
  currentPath: firstChild?.path,
1119
1099
  contents: firstChild?.contents || []
1120
1100
  })
1121
1101
  };
1122
1102
  updateTreeState(newState);
1123
- return rootChildren;
1103
+ return treeNodes;
1124
1104
  } catch (error) {
1125
1105
  handleError(error, 'GET FOLDER DATA');
1126
1106
  }
@@ -1135,7 +1115,7 @@ const useDirectoryTree = _ref => {
1135
1115
  const handleCreate = useCallback(async (node, newTitle) => {
1136
1116
  if (!newTitle?.trim()) return false;
1137
1117
  try {
1138
- const path = pathUtils.replaceRoot(`${node.path}/${newTitle}`);
1118
+ const path = `${node.path}/${newTitle}`;
1139
1119
  await createFolder({
1140
1120
  path
1141
1121
  });
@@ -1144,8 +1124,9 @@ const useDirectoryTree = _ref => {
1144
1124
  // 找到新增节点的父节点
1145
1125
  const parentNode = nodeUtils.findNode(newTreeData, node.key);
1146
1126
  if (parentNode?.[0]?.children) {
1127
+ const expectedPath = `${node.path}/${newTitle}`;
1147
1128
  // 通过 path 找到新增节点,得到新增节点的key
1148
- const addedNode = parentNode[0].children.find(ch => pathUtils.isSamePath(ch.path, `root/${newTitle}`));
1129
+ const addedNode = parentNode[0].children.find(ch => pathUtils.isSamePath(ch.path, expectedPath));
1149
1130
  if (addedNode) {
1150
1131
  updateTreeState({
1151
1132
  expandedKeys: [...treeState.expandedKeys, addedNode.key, parentNode[0].key]
@@ -1163,7 +1144,7 @@ const useDirectoryTree = _ref => {
1163
1144
  try {
1164
1145
  await removeFolderFile({
1165
1146
  paths: [{
1166
- path: pathUtils.replaceRoot(node.path)
1147
+ path: node.path
1167
1148
  }]
1168
1149
  });
1169
1150
  // 如果删除的是当前选中节点,则重新初始化
@@ -1180,8 +1161,8 @@ const useDirectoryTree = _ref => {
1180
1161
  if (pathUtils.isSamePath(node.path, newPath)) return false;
1181
1162
  try {
1182
1163
  await renameFolderFile({
1183
- old_path: pathUtils.replaceRoot(node.path),
1184
- new_path: pathUtils.replaceRoot(newPath)
1164
+ old_path: node.path,
1165
+ new_path: newPath
1185
1166
  });
1186
1167
  await fetchFolderData();
1187
1168
  } catch (error) {
@@ -3396,7 +3377,7 @@ const RightDetailForm = /*#__PURE__*/memo(_ref3 => {
3396
3377
  };
3397
3378
  });
3398
3379
  }, [initialSelected, isEditing, hasCategoryList, fields.category_list]);
3399
- return /*#__PURE__*/jsxs(Flex$1, {
3380
+ return /*#__PURE__*/jsxs(Flex, {
3400
3381
  vertical: true,
3401
3382
  className: "h-full",
3402
3383
  children: [/*#__PURE__*/jsxs(Form, {
@@ -3686,7 +3667,7 @@ const Preset = _ref => {
3686
3667
  saveButton: texts.saveButton
3687
3668
  },
3688
3669
  presetChanged: presetChanged
3689
- }) : /*#__PURE__*/jsx(Flex$1, {
3670
+ }) : /*#__PURE__*/jsx(Flex, {
3690
3671
  vertical: true,
3691
3672
  justify: "center",
3692
3673
  align: "center",