@gingkoo/pandora-explorer 0.0.1-alpha.62 → 0.0.1-alpha.64

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.62
2
+ * @gingkoo/pandora-explorer v0.0.1-alpha.64
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';
@@ -4736,7 +4736,7 @@ registerMenu('cur-folder', [{
4736
4736
  }, {
4737
4737
  key: 'create',
4738
4738
  icon: 'folder',
4739
- title: '新建文件'
4739
+ title: '新建文件夹'
4740
4740
  }, {
4741
4741
  type: 'line'
4742
4742
  }, {
@@ -6118,6 +6118,10 @@ const ExplorerMenu = props => {
6118
6118
  loadMenu: loadMenu,
6119
6119
  onChange: onChange,
6120
6120
  onRename: onRename,
6121
+ isEdit: store.isEdit,
6122
+ isDelect: store.isDelect,
6123
+ isDownload: store.isDownload,
6124
+ isUpload: store.isDownload,
6121
6125
  openMenu: openMenu,
6122
6126
  closeMenu: store.closeMenu,
6123
6127
  onSelect: v => {
@@ -6684,8 +6688,6 @@ const SelectBox = props => {
6684
6688
  }
6685
6689
  if (!key) return;
6686
6690
  typeof props.onUpload === 'function' && props?.onUpload(files, key, empty);
6687
- store.curInfo && loadData(store.curInfo?.key);
6688
- store.curInfo?.key && store.reloadNode(store.curInfo.key);
6689
6691
  };
6690
6692
  function handleDragEnter(e) {
6691
6693
  e.preventDefault();
@@ -7340,10 +7342,6 @@ const Layout$1 = props => {
7340
7342
  onMenuClick: _onMenuClick
7341
7343
  } = props;
7342
7344
  const store = useContext(ExampleContext);
7343
- const [expandkey, setExpandkey] = useState([]);
7344
- useEffect(() => {
7345
- setExpandkey([]);
7346
- }, [store?.curInfo?.key]);
7347
7345
  function Loading() {
7348
7346
  return jsx("div", {
7349
7347
  className: 'explorer-columns-loading',
@@ -7367,6 +7365,7 @@ const Layout$1 = props => {
7367
7365
  }
7368
7366
  function _onDblclick(key, info) {
7369
7367
  if (info.type == 'folder') {
7368
+ if (!isNavtab) return;
7370
7369
  if (Array.isArray(info?.children) && !info?.children.lenght) {
7371
7370
  store.setCurInfo(info);
7372
7371
  store.setCurList(info?.children);
@@ -7384,7 +7383,7 @@ const Layout$1 = props => {
7384
7383
  store.setLogIndex(arr.length);
7385
7384
  } else {
7386
7385
  onDblclick?.(key, {
7387
- info,
7386
+ ...info,
7388
7387
  isEdit: store.isEdit
7389
7388
  });
7390
7389
  }
@@ -7445,7 +7444,7 @@ const Layout$1 = props => {
7445
7444
  type: 'table',
7446
7445
  checks: checks,
7447
7446
  selectedKeys: [store.curSelect],
7448
- expandedKeys: expandkey,
7447
+ expandedKeys: store.expandkey,
7449
7448
  loadedKeys: store.loadkey,
7450
7449
  treeData: store.curlist,
7451
7450
  columns: store.columns,
@@ -7489,7 +7488,7 @@ const Layout$1 = props => {
7489
7488
  store.setLoadKey(v);
7490
7489
  },
7491
7490
  onExpand: v => {
7492
- setExpandkey(v);
7491
+ store.setExpandkey(v);
7493
7492
  },
7494
7493
  onChange: v => {
7495
7494
  store.setCurList(v);
@@ -7766,6 +7765,26 @@ const defaultColumns = [{
7766
7765
  });
7767
7766
  }
7768
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
+ });
7769
7788
  const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7770
7789
  const {
7771
7790
  data,
@@ -7776,12 +7795,14 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7776
7795
  isUpload = true,
7777
7796
  isEdit = true,
7778
7797
  isDownload = true,
7798
+ isNavtab = true,
7779
7799
  createFile,
7780
7800
  onCopy,
7781
7801
  onShear,
7782
7802
  onPaste,
7783
7803
  onDelect,
7784
7804
  onChange,
7805
+ onChangeCurMap,
7785
7806
  loadData: _loadData,
7786
7807
  onRename: _onRename,
7787
7808
  onMenuClick: _onMenuClick
@@ -7797,6 +7818,7 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7797
7818
  const [reamekey, setReName] = useState(null);
7798
7819
  const [logindex, setLogIndex] = useState(0); //前进
7799
7820
  const [log, setLog] = useState([]); //后退
7821
+ const [expandkey, setExpandkey] = useState([]);
7800
7822
  const [loadkey, setLoadKey] = useState([]);
7801
7823
  const [nav_loadKey, setNavLoadKey] = useState([]);
7802
7824
  const [menutype, setMenutype] = useState('tile');
@@ -7821,8 +7843,11 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7821
7843
  if (key) {
7822
7844
  loadData(key, undefined, closeload);
7823
7845
  } else {
7824
- curInfo?.key && loadData(curInfo.key, undefined, closeload);
7846
+ loadData(curInfo?.key || '', undefined, closeload);
7825
7847
  }
7848
+ },
7849
+ updateCurListNode: key => {
7850
+ updateCurlist(key || '');
7826
7851
  }
7827
7852
  }));
7828
7853
  /* ************ 挂载监听 **************** */
@@ -7928,11 +7953,12 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7928
7953
  });
7929
7954
  };
7930
7955
  useEffect(() => {
7956
+ if (!isNavtab) return;
7931
7957
  if (!curInfo) {
7932
7958
  setCurList(data?.[0]?.children || []);
7933
7959
  setCurInfo(data?.[0] || null);
7934
7960
  }
7935
- }, [data]);
7961
+ }, [data, isNavtab]);
7936
7962
  useEffect(() => {
7937
7963
  const addLevel = (data, map) => {
7938
7964
  let i = 0;
@@ -7949,6 +7975,20 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
7949
7975
  let map = addLevel(curlist, {});
7950
7976
  setDataMap(map);
7951
7977
  }, [curlist]);
7978
+ useEffect(() => {
7979
+ setExpandkey([]);
7980
+ }, [curInfo?.key]);
7981
+ useEffect(() => {
7982
+ if (isNavtab) return;
7983
+ if (!curlist?.length) {
7984
+ if (Array.isArray(data)) {
7985
+ setCurList(data);
7986
+ }
7987
+ }
7988
+ }, [curlist, isNavtab, data]);
7989
+ useEffect(() => {
7990
+ onChangeCurMap?.(dataMap);
7991
+ }, [dataMap]);
7952
7992
  /* ************ 加载更新数据 **************** */
7953
7993
  async function loadData(key, param, closeload = true) {
7954
7994
  closeload && setLoading(ApiStatusEnum.LOADING);
@@ -8019,6 +8059,30 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
8019
8059
  let arr = fixData(data || [], id, param);
8020
8060
  onChange?.(arr);
8021
8061
  }
8062
+ async function updateCurlist(key) {
8063
+ let data = await reduceGetTreeData(curlist, key || curInfo?.key || '', expandkey);
8064
+ setCurList(data);
8065
+ }
8066
+ async function reduceGetTreeData(data, key, expand) {
8067
+ let res = await loadNode(key);
8068
+ const newData = [];
8069
+ // @ts-ignore
8070
+ await data.myforeach(async v => {
8071
+ let obj = _$3.cloneDeep(v);
8072
+ if (expand.includes(obj.key)) {
8073
+ obj.children = await reduceGetTreeData(obj.children, obj.key, expand);
8074
+ }
8075
+ if (obj.type == 'file') {
8076
+ let match = res.filter(it => it.key === obj.key);
8077
+ if (match.length) {
8078
+ newData.push(match[0]);
8079
+ return null;
8080
+ }
8081
+ }
8082
+ newData.push(obj);
8083
+ });
8084
+ return newData;
8085
+ }
8022
8086
  /* ************ 功能方法 **************** */
8023
8087
  //创建和重名
8024
8088
  async function onRename(key, value, info, type) {
@@ -8266,6 +8330,7 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
8266
8330
  curSelectFile,
8267
8331
  loadkey,
8268
8332
  nav_loadKey,
8333
+ expandkey,
8269
8334
  //icon
8270
8335
  getIcons: Icons,
8271
8336
  loadMenu: props.loadMenu,
@@ -8288,7 +8353,8 @@ const Explorer = /*#__PURE__*/forwardRef((props, ref) => {
8288
8353
  setCurSelect,
8289
8354
  setCurSelectFile,
8290
8355
  setLoadKey,
8291
- setNavLoadKey
8356
+ setNavLoadKey,
8357
+ setExpandkey
8292
8358
  },
8293
8359
  children: jsx("div", {
8294
8360
  className: 'explorer-container',