seeder-resources-view 1.3.4 → 1.3.6

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
@@ -17817,6 +17817,7 @@ const buildDirectoryTree = function (data) {
17817
17817
  isRoot: !parentRoute,
17818
17818
  path: currentPath,
17819
17819
  contents: (item.contents || []).filter(content => content.type === 'file'),
17820
+ url: item.url,
17820
17821
  rawData: item // 保留原始数据
17821
17822
  };
17822
17823
 
@@ -17865,7 +17866,7 @@ const getAllNodeKeys = treeData => {
17865
17866
  const stack = [...treeData];
17866
17867
  while (stack.length) {
17867
17868
  const node = stack.pop();
17868
- if (node.key != null) {
17869
+ if (node.key !== null) {
17869
17870
  keys.push(node.key);
17870
17871
  }
17871
17872
  if (Array.isArray(node.children)) {
@@ -17875,6 +17876,48 @@ const getAllNodeKeys = treeData => {
17875
17876
  return keys;
17876
17877
  };
17877
17878
 
17879
+ /**
17880
+ * 根据 URL 查找树节点
17881
+ * @param {Array} treeData - 树数据
17882
+ * @param {string} url - 要查找的 URL
17883
+ * @param {Object} options - 配置选项
17884
+ * @param {boolean} options.exactMatch - 是否精确匹配(默认true)
17885
+ * @param {boolean} options.returnFirst - 是否返回第一个匹配项(默认false,返回所有匹配项)
17886
+ * @returns {Array} 包含匹配节点的数组
17887
+ */
17888
+ const findTreeNodeByUrl = function (treeData, url) {
17889
+ let options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
17890
+ const {
17891
+ exactMatch = true,
17892
+ returnFirst = false
17893
+ } = options;
17894
+ if (!Array.isArray(treeData) || typeof url !== 'string' || !url.trim()) {
17895
+ return [];
17896
+ }
17897
+ const result = [];
17898
+ const stack = [...treeData];
17899
+ while (stack.length) {
17900
+ const node = stack.pop();
17901
+
17902
+ // 检查当前节点是否匹配
17903
+ if (node.url) {
17904
+ const isMatch = exactMatch ? node.url === url : node.url.includes(url);
17905
+ if (isMatch) {
17906
+ result.push(node);
17907
+ if (returnFirst) {
17908
+ return result; // 找到第一个匹配项就结束
17909
+ }
17910
+ }
17911
+ }
17912
+
17913
+ // 递归处理子节点
17914
+ if (Array.isArray(node.children)) {
17915
+ stack.push(...node.children);
17916
+ }
17917
+ }
17918
+ return result;
17919
+ };
17920
+
17878
17921
  const useDirectoryTree = _ref => {
17879
17922
  let {
17880
17923
  getFolderData,
@@ -17899,9 +17942,11 @@ const useDirectoryTree = _ref => {
17899
17942
  paddingTop: 16
17900
17943
  },
17901
17944
  // 包装器样式
17902
- showIcon = true,
17903
- // 新增:是否显示展开/折叠图标
17904
- expandable = true // 新增:是否允许展开/折叠
17945
+ expandable = true,
17946
+ // 新增:是否允许展开/折叠
17947
+ onSelectDir,
17948
+ // 新增:选择目录回调
17949
+ selectedDirPath = '' // 新增:外部传入的选中目录名
17905
17950
  } = _ref;
17906
17951
  const [treeState, setTreeState] = react.useState({
17907
17952
  data: [],
@@ -17939,6 +17984,9 @@ const useDirectoryTree = _ref => {
17939
17984
  const nodeUtils = {
17940
17985
  findNode: (treeData, key) => {
17941
17986
  return findTreeNode(treeData, key);
17987
+ },
17988
+ findNodeByUrl: (treeData, url) => {
17989
+ return findTreeNodeByUrl(treeData, url);
17942
17990
  }
17943
17991
  };
17944
17992
 
@@ -17966,15 +18014,47 @@ const useDirectoryTree = _ref => {
17966
18014
  if (!treeNodes.length) {
17967
18015
  return null;
17968
18016
  }
17969
- const firstChild = treeNodes[0];
18017
+
18018
+ // 确定选中的节点
18019
+ let selectedNode = null;
18020
+
18021
+ // 情况1:selectedDirPath 未传(undefined/null)
18022
+ if (selectedDirPath === undefined || selectedDirPath === null) {
18023
+ var _selectedNode;
18024
+ selectedNode = treeNodes[0];
18025
+ console.log('No path provided, using first node:', (_selectedNode = selectedNode) === null || _selectedNode === void 0 ? void 0 : _selectedNode.title);
18026
+ }
18027
+ // 情况2:selectedDirPath 为空字符串
18028
+ else if (selectedDirPath.trim() === '') {
18029
+ // 不设置 selectedNode,保持为 null
18030
+ // console.log('Empty path provided, not setting default node');
18031
+ }
18032
+ // 情况3:selectedDirPath 有值
18033
+ else {
18034
+ try {
18035
+ const foundNodes = nodeUtils.findNodeByUrl(treeNodes, selectedDirPath);
18036
+ selectedNode = (foundNodes === null || foundNodes === void 0 ? void 0 : foundNodes[0]) || null;
18037
+ if (!selectedNode) {
18038
+ console.warn("No node found for path: \"".concat(selectedDirPath, "\""));
18039
+ }
18040
+ } catch (error) {
18041
+ console.error('Error finding node by URL:', error);
18042
+ selectedNode = null;
18043
+ }
18044
+ }
17970
18045
  const newState = _objectSpread2({
17971
18046
  data: treeNodes
17972
- }, initialization && {
17973
- selectedKeys: [firstChild === null || firstChild === void 0 ? void 0 : firstChild.key],
17974
- expandedKeys: getAllNodeKeys(treeNodes),
17975
- currentPath: firstChild === null || firstChild === void 0 ? void 0 : firstChild.path,
17976
- contents: (firstChild === null || firstChild === void 0 ? void 0 : firstChild.contents) || []
17977
- });
18047
+ }, initialization && _objectSpread2({
18048
+ expandedKeys: getAllNodeKeys(treeNodes)
18049
+ }, selectedNode ? {
18050
+ selectedKeys: [selectedNode.key].filter(Boolean),
18051
+ currentPath: selectedNode.path || '',
18052
+ contents: selectedNode.contents || []
18053
+ } : {
18054
+ selectedKeys: [],
18055
+ currentPath: '',
18056
+ contents: []
18057
+ }));
17978
18058
  updateTreeState(newState);
17979
18059
  return treeNodes;
17980
18060
  } catch (error) {
@@ -18055,12 +18135,19 @@ const useDirectoryTree = _ref => {
18055
18135
 
18056
18136
  // 选择节点
18057
18137
  const onSelect = react.useCallback(async (keys, info) => {
18138
+ // 如果选中了 root 节点,并且有传 onSelectDir 回调,则直接返回
18139
+ if (info.node.path === 'root' && onSelectDir) return;
18058
18140
  if (!keys.length || keys[0] === treeState.selectedKeys[0] && pathUtils.isSamePath(info.node.path, treeState.currentPath)) return;
18059
18141
  updateTreeState({
18060
18142
  selectedKeys: keys,
18061
18143
  currentPath: info.node.path,
18062
18144
  loading: true
18063
18145
  });
18146
+
18147
+ // 触发 onSelectDir 回调(如果存在)
18148
+ if (onSelectDir) {
18149
+ onSelectDir(info.node.rawData);
18150
+ }
18064
18151
  try {
18065
18152
  // 模拟延迟加载
18066
18153
  // eslint-disable-next-line no-promise-executor-return
@@ -18120,7 +18207,7 @@ const useDirectoryTree = _ref => {
18120
18207
  theme: theme,
18121
18208
  children: /*#__PURE__*/jsxRuntime.jsx(antd.Tree, {
18122
18209
  blockNode: true,
18123
- showIcon: showIcon,
18210
+ showIcon: true,
18124
18211
  selectedKeys: treeState.selectedKeys,
18125
18212
  expandedKeys: treeState.expandedKeys,
18126
18213
  onSelect: onSelect,