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