@gingkoo/pandora-explorer 0.0.1-alpha.63 → 0.0.1-alpha.65

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 CHANGED
@@ -1,14 +1,14 @@
1
1
  /**
2
- * @gingkoo/pandora-explorer v0.0.1-alpha.63
2
+ * @gingkoo/pandora-explorer v0.0.1-alpha.65
3
3
  */
4
4
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
5
5
  import cx$1 from 'classnames';
6
6
  import * as React from 'react';
7
7
  import React__default, { createContext, useRef, useState, useImperativeHandle, useEffect, useMemo, useContext, createElement, useLayoutEffect as useLayoutEffect$1, forwardRef } from 'react';
8
+ import _$3, { cloneDeep, truncate } from 'lodash';
8
9
  import { createRoot } from 'react-dom/client';
9
10
  import createEmotion from '@emotion/css/create-instance';
10
11
  import { cx as cx$2 } from '@emotion/css';
11
- import { cloneDeep, truncate } from 'lodash';
12
12
  import KeyCode from 'rc-util/lib/KeyCode';
13
13
  import pickAttrs from 'rc-util/lib/pickAttrs';
14
14
  import 'rc-util/lib/warning';
@@ -5166,28 +5166,28 @@ function Menu(props) {
5166
5166
  return data;
5167
5167
  });
5168
5168
  _menu.map(v => {
5169
- if (!store.isEdit && edit.includes(v.key)) {
5169
+ if (!store.isEdit && edit.includes(v?.key)) {
5170
5170
  arr.push({
5171
5171
  ...v,
5172
5172
  disabled: true
5173
5173
  });
5174
5174
  return;
5175
5175
  }
5176
- if (!store.isDelect && delect.includes(v.key)) {
5176
+ if (!store.isDelect && delect.includes(v?.key)) {
5177
5177
  arr.push({
5178
5178
  ...v,
5179
5179
  disabled: true
5180
5180
  });
5181
5181
  return;
5182
5182
  }
5183
- if (!store.isDownload && download.includes(v.key)) {
5183
+ if (!store.isDownload && download.includes(v?.key)) {
5184
5184
  arr.push({
5185
5185
  ...v,
5186
5186
  disabled: true
5187
5187
  });
5188
5188
  return;
5189
5189
  }
5190
- if (!store.isUpload && upload.includes(v.key)) {
5190
+ if (!store.isUpload && upload.includes(v?.key)) {
5191
5191
  arr.push({
5192
5192
  ...v,
5193
5193
  disabled: true
@@ -7342,10 +7342,6 @@ const Layout$1 = props => {
7342
7342
  onMenuClick: _onMenuClick
7343
7343
  } = props;
7344
7344
  const store = useContext(ExampleContext);
7345
- const [expandkey, setExpandkey] = useState([]);
7346
- useEffect(() => {
7347
- setExpandkey([]);
7348
- }, [store?.curInfo?.key]);
7349
7345
  function Loading() {
7350
7346
  return jsx("div", {
7351
7347
  className: 'explorer-columns-loading',
@@ -7448,7 +7444,7 @@ const Layout$1 = props => {
7448
7444
  type: 'table',
7449
7445
  checks: checks,
7450
7446
  selectedKeys: [store.curSelect],
7451
- expandedKeys: expandkey,
7447
+ expandedKeys: store.expandkey,
7452
7448
  loadedKeys: store.loadkey,
7453
7449
  treeData: store.curlist,
7454
7450
  columns: store.columns,
@@ -7492,7 +7488,7 @@ const Layout$1 = props => {
7492
7488
  store.setLoadKey(v);
7493
7489
  },
7494
7490
  onExpand: v => {
7495
- setExpandkey(v);
7491
+ store.setExpandkey(v);
7496
7492
  },
7497
7493
  onChange: v => {
7498
7494
  store.setCurList(v);
@@ -7526,7 +7522,7 @@ styleInject(css_248z);
7526
7522
 
7527
7523
  function ExplorerInfo(props) {
7528
7524
  const {
7529
- infoshow,
7525
+ infoshow = false,
7530
7526
  getIcons,
7531
7527
  curInfo,
7532
7528
  dataMap,
@@ -7769,6 +7765,26 @@ const defaultColumns = [{
7769
7765
  });
7770
7766
  }
7771
7767
  }];
7768
+ Object.defineProperty(Array.prototype, 'myforeach', {
7769
+ value: async function (fn, context = null) {
7770
+ let index = 0;
7771
+ let arr = this;
7772
+ if (typeof fn !== 'function') {
7773
+ throw new TypeError(fn + ' is not a function');
7774
+ }
7775
+ while (index < arr.length) {
7776
+ if (index in arr) {
7777
+ try {
7778
+ await fn.call(context, arr[index], index, arr);
7779
+ } catch (e) {
7780
+ console.log(e);
7781
+ }
7782
+ }
7783
+ index++;
7784
+ }
7785
+ },
7786
+ enumerable: false
7787
+ });
7772
7788
  const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7773
7789
  const {
7774
7790
  data,
@@ -7786,6 +7802,7 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7786
7802
  onPaste,
7787
7803
  onDelect,
7788
7804
  onChange,
7805
+ onChangeCurMap,
7789
7806
  loadData: _loadData,
7790
7807
  onRename: _onRename,
7791
7808
  onMenuClick: _onMenuClick
@@ -7801,6 +7818,7 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7801
7818
  const [reamekey, setReName] = useState(null);
7802
7819
  const [logindex, setLogIndex] = useState(0); //前进
7803
7820
  const [log, setLog] = useState([]); //后退
7821
+ const [expandkey, setExpandkey] = useState([]);
7804
7822
  const [loadkey, setLoadKey] = useState([]);
7805
7823
  const [nav_loadKey, setNavLoadKey] = useState([]);
7806
7824
  const [menutype, setMenutype] = useState('tile');
@@ -7825,8 +7843,11 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7825
7843
  if (key) {
7826
7844
  loadData(key, undefined, closeload);
7827
7845
  } else {
7828
- curInfo?.key && loadData(curInfo.key, undefined, closeload);
7846
+ loadData(curInfo?.key || '', undefined, closeload);
7829
7847
  }
7848
+ },
7849
+ updateCurListNode: key => {
7850
+ updateCurlist(key || '');
7830
7851
  }
7831
7852
  }));
7832
7853
  /* ************ 挂载监听 **************** */
@@ -7843,7 +7864,7 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7843
7864
  return () => {
7844
7865
  window.removeEventListener('keydown', handleKeyDown);
7845
7866
  };
7846
- }, [curSelect, dataMap]);
7867
+ }, [curSelect, dataMap, isDelect, isEdit]);
7847
7868
  const handleKeyDown = e => {
7848
7869
  if (e.altKey && e.key === '3') {
7849
7870
  setMenutype('column');
@@ -7855,6 +7876,7 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7855
7876
  setMenutype('tile');
7856
7877
  }
7857
7878
  if ((e.ctrlKey || e.metaKey) && e.key === 'c') {
7879
+ if (!isEdit) return;
7858
7880
  if (curSelect && dataMap?.[curSelect]) {
7859
7881
  onCopy?.(dataMap?.[curSelect]);
7860
7882
  } else {
@@ -7862,6 +7884,7 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7862
7884
  }
7863
7885
  }
7864
7886
  if ((e.ctrlKey || e.metaKey) && e.key === 'x') {
7887
+ if (!isEdit) return;
7865
7888
  if (curSelect && dataMap?.[curSelect]) {
7866
7889
  onShear?.(dataMap?.[curSelect]);
7867
7890
  } else {
@@ -7869,6 +7892,7 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7869
7892
  }
7870
7893
  }
7871
7894
  if ((e.ctrlKey || e.metaKey) && e.key === 'v') {
7895
+ if (!isEdit) return;
7872
7896
  curInfo && onPaste?.(curInfo);
7873
7897
  curInfo && reloadNode(curInfo.key);
7874
7898
  }
@@ -7932,11 +7956,12 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7932
7956
  });
7933
7957
  };
7934
7958
  useEffect(() => {
7959
+ if (!isNavtab) return;
7935
7960
  if (!curInfo) {
7936
7961
  setCurList(data?.[0]?.children || []);
7937
7962
  setCurInfo(data?.[0] || null);
7938
7963
  }
7939
- }, [data]);
7964
+ }, [data, isNavtab]);
7940
7965
  useEffect(() => {
7941
7966
  const addLevel = (data, map) => {
7942
7967
  let i = 0;
@@ -7953,16 +7978,20 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7953
7978
  let map = addLevel(curlist, {});
7954
7979
  setDataMap(map);
7955
7980
  }, [curlist]);
7981
+ useEffect(() => {
7982
+ setExpandkey([]);
7983
+ }, [curInfo?.key]);
7956
7984
  useEffect(() => {
7957
7985
  if (isNavtab) return;
7958
- console.log(data, '我是data');
7959
- console.log(curlist, '我是cur');
7960
7986
  if (!curlist?.length) {
7961
7987
  if (Array.isArray(data)) {
7962
7988
  setCurList(data);
7963
7989
  }
7964
7990
  }
7965
7991
  }, [curlist, isNavtab, data]);
7992
+ useEffect(() => {
7993
+ onChangeCurMap?.(dataMap);
7994
+ }, [dataMap]);
7966
7995
  /* ************ 加载更新数据 **************** */
7967
7996
  async function loadData(key, param, closeload = true) {
7968
7997
  closeload && setLoading(ApiStatusEnum.LOADING);
@@ -8033,6 +8062,30 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
8033
8062
  let arr = fixData(data || [], id, param);
8034
8063
  onChange?.(arr);
8035
8064
  }
8065
+ async function updateCurlist(key) {
8066
+ let data = await reduceGetTreeData(curlist, key || curInfo?.key || '', expandkey);
8067
+ setCurList(data);
8068
+ }
8069
+ async function reduceGetTreeData(data, key, expand) {
8070
+ let res = await loadNode(key);
8071
+ const newData = [];
8072
+ // @ts-ignore
8073
+ await data.myforeach(async v => {
8074
+ let obj = _$3.cloneDeep(v);
8075
+ if (expand.includes(obj.key)) {
8076
+ obj.children = await reduceGetTreeData(obj.children, obj.key, expand);
8077
+ }
8078
+ if (obj.type == 'file') {
8079
+ let match = res.filter(it => it.key === obj.key);
8080
+ if (match.length) {
8081
+ newData.push(match[0]);
8082
+ return null;
8083
+ }
8084
+ }
8085
+ newData.push(obj);
8086
+ });
8087
+ return newData;
8088
+ }
8036
8089
  /* ************ 功能方法 **************** */
8037
8090
  //创建和重名
8038
8091
  async function onRename(key, value, info, type) {
@@ -8280,6 +8333,7 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
8280
8333
  curSelectFile,
8281
8334
  loadkey,
8282
8335
  nav_loadKey,
8336
+ expandkey,
8283
8337
  //icon
8284
8338
  getIcons: Icons,
8285
8339
  loadMenu: props.loadMenu,
@@ -8302,7 +8356,8 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
8302
8356
  setCurSelect,
8303
8357
  setCurSelectFile,
8304
8358
  setLoadKey,
8305
- setNavLoadKey
8359
+ setNavLoadKey,
8360
+ setExpandkey
8306
8361
  },
8307
8362
  children: jsx("div", {
8308
8363
  className: 'explorer-container',