@gingkoo/pandora-explorer 0.1.11-alpha.1 → 0.1.11-alpha.2
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/lib/es/index.js +63 -30
- package/lib/es/index.js.map +1 -1
- package/package.json +1 -1
package/lib/es/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @gingkoo/pandora-explorer v0.1.11-alpha.
|
|
2
|
+
* @gingkoo/pandora-explorer v0.1.11-alpha.2
|
|
3
3
|
*/
|
|
4
4
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import cx$1 from 'classnames';
|
|
@@ -9546,6 +9546,7 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
9546
9546
|
const box = useRef(null);
|
|
9547
9547
|
const boxMenu = useRef(null);
|
|
9548
9548
|
const menu = useRef(null);
|
|
9549
|
+
const expandedKeysRef = useRef([]);
|
|
9549
9550
|
useImperativeHandle(ref, () => ({
|
|
9550
9551
|
removeLog: () => {
|
|
9551
9552
|
//清空日志
|
|
@@ -9565,8 +9566,8 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
9565
9566
|
await loadData(curInfo?.key || '', undefined, closeload);
|
|
9566
9567
|
}
|
|
9567
9568
|
},
|
|
9568
|
-
updateCurListNode: key => {
|
|
9569
|
-
updateCurlist(key || '');
|
|
9569
|
+
updateCurListNode: async key => {
|
|
9570
|
+
await updateCurlist(key || '');
|
|
9570
9571
|
},
|
|
9571
9572
|
createFolder: createFolder,
|
|
9572
9573
|
setNavSelect: params => {
|
|
@@ -9716,9 +9717,10 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
9716
9717
|
onChangeCurMap?.(dataMap);
|
|
9717
9718
|
}, [dataMap]);
|
|
9718
9719
|
useEffect(() => {
|
|
9719
|
-
|
|
9720
|
-
|
|
9721
|
-
|
|
9720
|
+
const expandedKeys = cloneDeep(props?.expandedKeys) || [];
|
|
9721
|
+
if (_$3.isEqual(expandedKeysRef.current, expandedKeys)) return;
|
|
9722
|
+
expandedKeysRef.current = expandedKeys;
|
|
9723
|
+
setExpandNavKey(expandedKeys);
|
|
9722
9724
|
}, [props.expandedKeys]);
|
|
9723
9725
|
/* ************ 加载更新数据 **************** */
|
|
9724
9726
|
async function loadData(key, param, closeload = true) {
|
|
@@ -9749,6 +9751,56 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
9749
9751
|
let data = await props.loadData?.(key);
|
|
9750
9752
|
return data?.fileList || [];
|
|
9751
9753
|
}
|
|
9754
|
+
async function hydrateExpandedList(list = [], expandedKeys = []) {
|
|
9755
|
+
const expandedKeySet = new Set(expandedKeys);
|
|
9756
|
+
const result = [];
|
|
9757
|
+
for (const item of list) {
|
|
9758
|
+
const next = cloneDeep(item);
|
|
9759
|
+
if (next?.type == 'folder' && next?.key && expandedKeySet.has(next.key)) {
|
|
9760
|
+
const data = await props.loadData?.(next.key);
|
|
9761
|
+
next.children = await hydrateExpandedList(data?.fileList || [], expandedKeys);
|
|
9762
|
+
next.api = true;
|
|
9763
|
+
next.isLeaf = false;
|
|
9764
|
+
}
|
|
9765
|
+
result.push(next);
|
|
9766
|
+
}
|
|
9767
|
+
return result;
|
|
9768
|
+
}
|
|
9769
|
+
async function loadExpandedData(key, expandedKeys = []) {
|
|
9770
|
+
if (!props.loadData) return null;
|
|
9771
|
+
const data = await props.loadData?.(key);
|
|
9772
|
+
if (!data || data.status == 'Err') return null;
|
|
9773
|
+
return {
|
|
9774
|
+
...data,
|
|
9775
|
+
fileList: await hydrateExpandedList(data?.fileList || [], expandedKeys)
|
|
9776
|
+
};
|
|
9777
|
+
}
|
|
9778
|
+
async function refreshCurrentList(key, expandedKeys = expandkey) {
|
|
9779
|
+
const data = await loadExpandedData(key || curInfo?.key || '', expandedKeys);
|
|
9780
|
+
if (!data) return false;
|
|
9781
|
+
setCurList(data?.fileList || []);
|
|
9782
|
+
setCurInfo(data?.current || {});
|
|
9783
|
+
setTotalNum(data?.totalNum || 0);
|
|
9784
|
+
setLoadKey(expandedKeys);
|
|
9785
|
+
setExpandkey(expandedKeys);
|
|
9786
|
+
return true;
|
|
9787
|
+
}
|
|
9788
|
+
async function refreshNavData(expandedKeys = nav_expandkey) {
|
|
9789
|
+
if (!onChange || !Array.isArray(data)) return;
|
|
9790
|
+
const tree = await hydrateExpandedList(data || [], expandedKeys);
|
|
9791
|
+
onChange(tree);
|
|
9792
|
+
setNavLoadKey(expandedKeys);
|
|
9793
|
+
setExpandNavKey(expandedKeys);
|
|
9794
|
+
}
|
|
9795
|
+
async function refreshAfterMove() {
|
|
9796
|
+
const currentExpandKeys = cloneDeep(expandkey || []);
|
|
9797
|
+
const navExpandKeys = cloneDeep(nav_expandkey || []);
|
|
9798
|
+
setLoading(ApiStatusEnum.LOADING);
|
|
9799
|
+
await Promise.all([refreshCurrentList(curInfo?.key || '', currentExpandKeys), refreshNavData(navExpandKeys)]);
|
|
9800
|
+
setCurSelect(null);
|
|
9801
|
+
setCurSelectFile(null);
|
|
9802
|
+
setLoading(ApiStatusEnum.READY);
|
|
9803
|
+
}
|
|
9752
9804
|
// 直接通过 刷新数节点 达到刷新效果
|
|
9753
9805
|
const reloadNode = (key, params) => {
|
|
9754
9806
|
let isfix = false;
|
|
@@ -9851,29 +9903,7 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
9851
9903
|
onChange?.(arr);
|
|
9852
9904
|
}
|
|
9853
9905
|
async function updateCurlist(key) {
|
|
9854
|
-
|
|
9855
|
-
data = await reduceGetTreeData(curlist, key || curInfo?.key || '', expandkey);
|
|
9856
|
-
setCurList(data);
|
|
9857
|
-
}
|
|
9858
|
-
async function reduceGetTreeData(data, key, expand) {
|
|
9859
|
-
let res = await loadNode(key);
|
|
9860
|
-
const newData = [];
|
|
9861
|
-
// @ts-ignore
|
|
9862
|
-
await data.myforeach(async v => {
|
|
9863
|
-
let obj = _$3.cloneDeep(v);
|
|
9864
|
-
if (expand.includes(obj.key)) {
|
|
9865
|
-
obj.children = await reduceGetTreeData(obj.children || [], obj.key, expand);
|
|
9866
|
-
}
|
|
9867
|
-
if (obj.type == 'file') {
|
|
9868
|
-
let match = res.filter(it => it.key === obj.key);
|
|
9869
|
-
if (match.length) {
|
|
9870
|
-
newData.push(match[0]);
|
|
9871
|
-
return null;
|
|
9872
|
-
}
|
|
9873
|
-
}
|
|
9874
|
-
newData.push(obj);
|
|
9875
|
-
});
|
|
9876
|
-
return newData;
|
|
9906
|
+
await refreshCurrentList(key || curInfo?.key || '', expandkey);
|
|
9877
9907
|
}
|
|
9878
9908
|
/* ************ 功能方法 **************** */
|
|
9879
9909
|
async function uploadFile(param) {
|
|
@@ -10205,7 +10235,10 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
10205
10235
|
data.push(dataMap?.[v]);
|
|
10206
10236
|
}
|
|
10207
10237
|
});
|
|
10208
|
-
_onMoveFile
|
|
10238
|
+
if (!_onMoveFile) return;
|
|
10239
|
+
const result = await _onMoveFile?.(data, info);
|
|
10240
|
+
if (result === false) return;
|
|
10241
|
+
await refreshAfterMove();
|
|
10209
10242
|
}
|
|
10210
10243
|
return jsx(ExampleContext.Provider, {
|
|
10211
10244
|
value: {
|