@kep-platform/basic-component 1.0.6 → 1.0.8

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) lee-step-jss 1599925910@qq.com
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) lee-step-jss 1599925910@qq.com
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,43 +1,43 @@
1
- # @kep-platform/basic-component
2
-
3
- [![NPM version](https://img.shields.io/npm/v/@kep-platform/basic-component.svg?style=flat)](https://npmjs.org/package/@kep-platform/basic-component)
4
- [![NPM downloads](http://img.shields.io/npm/dm/@kep-platform/basic-component.svg?style=flat)](https://npmjs.org/package/@kep-platform/basic-component)
5
-
6
- A react library developed with dumi
7
-
8
- ## Usage
9
-
10
- TODO
11
-
12
- ## Options
13
-
14
- TODO
15
-
16
- ## Development
17
-
18
- ```bash
19
- # install dependencies
20
- $ npm install
21
-
22
- # develop library by docs demo
23
- $ npm start
24
-
25
- # build library source code
26
- $ npm run build
27
-
28
- # build library source code in watch mode
29
- $ npm run build:watch
30
-
31
- # build docs
32
- $ npm run docs:build
33
-
34
- # Locally preview the production build.
35
- $ npm run docs:preview
36
-
37
- # check your project for potential problems
38
- $ npm run doctor
39
- ```
40
-
41
- ## LICENSE
42
-
43
- MIT
1
+ # @kep-platform/basic-component
2
+
3
+ [![NPM version](https://img.shields.io/npm/v/@kep-platform/basic-component.svg?style=flat)](https://npmjs.org/package/@kep-platform/basic-component)
4
+ [![NPM downloads](http://img.shields.io/npm/dm/@kep-platform/basic-component.svg?style=flat)](https://npmjs.org/package/@kep-platform/basic-component)
5
+
6
+ A react library developed with dumi
7
+
8
+ ## Usage
9
+
10
+ TODO
11
+
12
+ ## Options
13
+
14
+ TODO
15
+
16
+ ## Development
17
+
18
+ ```bash
19
+ # install dependencies
20
+ $ npm install
21
+
22
+ # develop library by docs demo
23
+ $ npm start
24
+
25
+ # build library source code
26
+ $ npm run build
27
+
28
+ # build library source code in watch mode
29
+ $ npm run build:watch
30
+
31
+ # build docs
32
+ $ npm run docs:build
33
+
34
+ # Locally preview the production build.
35
+ $ npm run docs:preview
36
+
37
+ # check your project for potential problems
38
+ $ npm run doctor
39
+ ```
40
+
41
+ ## LICENSE
42
+
43
+ MIT
@@ -1,9 +1,9 @@
1
- // styled.d.ts 文件
2
- import 'styled-components';
3
- import { ButtonTheme } from './theme';
4
-
5
- declare module 'styled-components' {
6
- export interface DefaultTheme {
7
- button?: ButtonTheme;
8
- }
9
- }
1
+ // styled.d.ts 文件
2
+ import 'styled-components';
3
+ import { ButtonTheme } from './theme';
4
+
5
+ declare module 'styled-components' {
6
+ export interface DefaultTheme {
7
+ button?: ButtonTheme;
8
+ }
9
+ }
@@ -1,38 +1,38 @@
1
- export type ButtonTheme = {
2
- /* all */
3
- fontWeight?: string;
4
- borderRadius?: string;
5
- borderWidth?: string;
6
- shadowAnimation?: Keyframes;
7
- /* Default */
8
- defaultTextColor?: string;
9
- defaultBorderColor?: string;
10
- defaultBackgroundColor?: string;
11
- defaultHoverBackgroundColor?: string;
12
- defaultHoverBorderColor: string;
13
- defaultHoverTextColor?: string;
14
- /* Danger */
15
- dangerTextColor?: string;
16
- dangerBorderColor?: string;
17
- dangerBackgroundColor?: string;
18
- dangerHoverBackgroundColor: string;
19
- dangerHoverTextColor?: string;
20
- dangerShadowAnimation?: Keyframes;
21
- /* Primary */
22
- primaryTextColor?: string;
23
- primaryBorderColor?: string;
24
- primaryBackgroundColor?: string;
25
- primaryHoverBackgroundColor: string;
26
- primaryHoverTextColor?: string;
27
- primaryShadowAnimation?: Keyframes;
28
- /* Small */
29
- smallPaddingTop?: string;
30
- smallPaddingLeft?: string;
31
- smallFontSize?: string;
32
- smallBorderRadius?: string;
33
- /* Large */
34
- bargePaddingTop?: string;
35
- bargePaddingLeft?: string;
36
- bargeFontSize?: string;
37
- bargeBorderRadius?: string;
38
- };
1
+ export type ButtonTheme = {
2
+ /* all */
3
+ fontWeight?: string;
4
+ borderRadius?: string;
5
+ borderWidth?: string;
6
+ shadowAnimation?: Keyframes;
7
+ /* Default */
8
+ defaultTextColor?: string;
9
+ defaultBorderColor?: string;
10
+ defaultBackgroundColor?: string;
11
+ defaultHoverBackgroundColor?: string;
12
+ defaultHoverBorderColor: string;
13
+ defaultHoverTextColor?: string;
14
+ /* Danger */
15
+ dangerTextColor?: string;
16
+ dangerBorderColor?: string;
17
+ dangerBackgroundColor?: string;
18
+ dangerHoverBackgroundColor: string;
19
+ dangerHoverTextColor?: string;
20
+ dangerShadowAnimation?: Keyframes;
21
+ /* Primary */
22
+ primaryTextColor?: string;
23
+ primaryBorderColor?: string;
24
+ primaryBackgroundColor?: string;
25
+ primaryHoverBackgroundColor: string;
26
+ primaryHoverTextColor?: string;
27
+ primaryShadowAnimation?: Keyframes;
28
+ /* Small */
29
+ smallPaddingTop?: string;
30
+ smallPaddingLeft?: string;
31
+ smallFontSize?: string;
32
+ smallBorderRadius?: string;
33
+ /* Large */
34
+ bargePaddingTop?: string;
35
+ bargePaddingLeft?: string;
36
+ bargeFontSize?: string;
37
+ bargeBorderRadius?: string;
38
+ };
@@ -1,5 +1,5 @@
1
1
  import React, { ReactNode } from 'react';
2
- export declare const MainArea: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<Omit<import("styled-components").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof React.HtmlHTMLAttributes<HTMLDivElement> | keyof import("../Flex").FlexItemProps> & import("../Flex").FlexItemProps & React.HtmlHTMLAttributes<HTMLDivElement>, "ref"> & {
2
+ export declare const MainArea: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components").FastOmit<Omit<import("styled-components").FastOmit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof import("../Flex").FlexItemProps | keyof React.HtmlHTMLAttributes<HTMLDivElement>> & import("../Flex").FlexItemProps & React.HtmlHTMLAttributes<HTMLDivElement>, "ref"> & {
3
3
  ref?: ((instance: HTMLDivElement | null) => void) | React.RefObject<HTMLDivElement> | null | undefined;
4
4
  }, never>> & string;
5
5
  type MainPropertyProps = {
@@ -17,8 +17,9 @@ export type TreeProps = {
17
17
  isFlex?: boolean;
18
18
  bordered?: boolean;
19
19
  hideColumns?: boolean;
20
+ loadData?: (node: TreeNodeType) => Promise<any>;
20
21
  };
21
- declare const Tree: (({ treeData, columns, fieldNames, title: treeTitle, titleWidth, titleRender, selectedKeys, expandedKeys, isFlex, onSelect, onExpand, contextMenuRender, onContextMenuItemSelect, multiple, bordered, hideColumns, }: TreeProps) => React.JSX.Element) & {
22
+ declare const Tree: (({ treeData, columns, fieldNames, title: treeTitle, titleWidth, titleRender, selectedKeys, expandedKeys, isFlex, onSelect, onExpand, contextMenuRender, onContextMenuItemSelect, loadData, multiple, bordered, hideColumns, }: TreeProps) => React.JSX.Element) & {
22
23
  displayName: string;
23
24
  };
24
25
  export default Tree;
package/dist/Tree/Tree.js CHANGED
@@ -1,11 +1,17 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
2
  var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
3
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
4
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
5
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
7
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
8
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
3
9
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
10
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
5
11
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
12
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
7
13
  import { observer } from 'mobx-react-lite';
8
- import React, { useCallback, useMemo, useRef } from 'react';
14
+ import React, { useCallback, useMemo, useRef, useState } from 'react';
9
15
  import styled, { css } from 'styled-components';
10
16
  import { BoxShadowBox } from "../BoxShadowBox";
11
17
  import { Column, Columns } from "../Columns";
@@ -17,7 +23,7 @@ var TreeContainer = styled('div').withConfig({
17
23
  shouldForwardProp: function shouldForwardProp(prop) {
18
24
  return !['bordered'].includes(prop);
19
25
  }
20
- })(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n position: relative;\n overflow-x: auto;\n border: 1px solid var(--kep-platform-color-border-secondary);\n border-width: ", ";\n"])), function (props) {
26
+ })(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n\tposition: relative;\n\toverflow-x: auto;\n\tborder: 1px solid var(--kep-platform-color-border-secondary);\n\tborder-width: ", ";\n"])), function (props) {
21
27
  return props.bordered ? '1px' : 0;
22
28
  });
23
29
  var TreeBody = styled(List)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral([""])));
@@ -25,15 +31,16 @@ var TreeHeader = styled('div').withConfig({
25
31
  shouldForwardProp: function shouldForwardProp(prop) {
26
32
  return !['width', 'isFlex'].includes(prop);
27
33
  }
28
- })(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n ", "\n background-color: var(--kep-platform-header-bg);\n & ", ",& ", " {\n background-color: var(--kep-platform-header-bg);\n font-weight: 600;\n position: sticky;\n }\n"])), function (props) {
34
+ })(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n\t", "\n\tbackground-color: var(--kep-platform-header-bg);\n\t& ", ",& ", " {\n\t\tbackground-color: var(--kep-platform-header-bg);\n\t\tfont-weight: 600;\n\t\tposition: sticky;\n\t}\n"])), function (props) {
29
35
  if (props.isFlex) {
30
- return css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n width: 100%;\n "])));
36
+ return css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n\t\t\t\twidth: 100%;\n\t\t\t"])));
31
37
  }
32
38
  if (props.width) {
33
- return css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n width: ", "px;\n "])), props.width);
39
+ return css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n\t\t\t\twidth: ", "px;\n\t\t\t"])), props.width);
34
40
  }
35
41
  }, Column, MainArea);
36
42
  var rootLevel = -1;
43
+ var virtualRootKey = Symbol('virtualRootKey');
37
44
  var Tree = observer(function (_ref) {
38
45
  var treeData = _ref.treeData,
39
46
  _ref$columns = _ref.columns,
@@ -60,6 +67,7 @@ var Tree = observer(function (_ref) {
60
67
  onExpand = _ref$onExpand === void 0 ? function () {} : _ref$onExpand,
61
68
  contextMenuRender = _ref.contextMenuRender,
62
69
  onContextMenuItemSelect = _ref.onContextMenuItemSelect,
70
+ loadData = _ref.loadData,
63
71
  _ref$multiple = _ref.multiple,
64
72
  multiple = _ref$multiple === void 0 ? false : _ref$multiple,
65
73
  _ref$bordered = _ref.bordered,
@@ -67,7 +75,7 @@ var Tree = observer(function (_ref) {
67
75
  _ref$hideColumns = _ref.hideColumns,
68
76
  hideColumns = _ref$hideColumns === void 0 ? false : _ref$hideColumns;
69
77
  var rootNode = useMemo(function () {
70
- return _defineProperty(_defineProperty(_defineProperty({}, fieldNames.key, 'root'), "nodeType", nodeTypeMap.virtual), "children", treeData);
78
+ return _defineProperty(_defineProperty(_defineProperty({}, fieldNames.key, virtualRootKey), "nodeType", nodeTypeMap.virtual), "children", treeData);
71
79
  }, [treeData]);
72
80
 
73
81
  /* 复用Columns组件显示行,构造一个类似表格头数据来适应Columns组件的数据结构 */
@@ -132,6 +140,11 @@ var Tree = observer(function (_ref) {
132
140
  boxShadowBox.current.style.left = treeContainer.scrollLeft + titleWidth + 'px';
133
141
  }
134
142
  }, [titleWidth]);
143
+ var _useState = useState([]),
144
+ _useState2 = _slicedToArray(_useState, 2),
145
+ loadedKeys = _useState2[0],
146
+ setLoadedKeys = _useState2[1];
147
+
135
148
  /* 树组件的结构其实比较简单,就是一个树标题(TableMode下),然后树节点形成的列表 */
136
149
  return /*#__PURE__*/React.createElement(TreeContainer, {
137
150
  onScroll: onScrollHandler,
@@ -161,6 +174,9 @@ var Tree = observer(function (_ref) {
161
174
  onSelect: onSelect,
162
175
  expandedKeys: expandedKeys,
163
176
  onExpand: onExpand,
177
+ loadData: loadData,
178
+ loadedKeys: loadedKeys,
179
+ setLoadedKeys: setLoadedKeys,
164
180
  width: isTableMode && !isFlex ? rowWidth : undefined,
165
181
  node: rootNode,
166
182
  fieldNames: fieldNames,
@@ -17,10 +17,13 @@ export type TreeNodeControllerProps = {
17
17
  contextMenuRender?: (node: TreeNodeType) => MenuItem[];
18
18
  onContextMenuItemSelect?: (node: TreeNodeType, key: Key, item: MenuItem) => void;
19
19
  titleRender?: ((node: TreeNodeType) => ReactNode | null) | null | undefined;
20
+ loadData?: (node: TreeNodeType) => Promise<any>;
21
+ loadedKeys: Key[];
22
+ setLoadedKeys: (keys: Key[]) => void;
20
23
  };
21
24
  export declare const nodeTypeMap: {
22
25
  virtual: string;
23
26
  };
24
- export declare const TreeNodeController: (({ node, selectedKeys, width, isTableMode, fieldNames, columns, isFlex, onSelect, multiple, level, mainWidth, expandedKeys, onExpand, contextMenuRender, onContextMenuItemSelect, titleRender, }: TreeNodeControllerProps) => React.JSX.Element) & {
27
+ export declare const TreeNodeController: (({ node, selectedKeys, width, isTableMode, fieldNames, columns, isFlex, onSelect, multiple, level, mainWidth, expandedKeys, onExpand, contextMenuRender, onContextMenuItemSelect, titleRender, loadData, loadedKeys, setLoadedKeys, }: TreeNodeControllerProps) => React.JSX.Element) & {
25
28
  displayName: string;
26
29
  };
@@ -1,4 +1,4 @@
1
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8;
1
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9;
2
2
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
3
3
  function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
4
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -6,7 +6,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
6
6
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
7
7
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
8
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
9
- import { CaretRightOutlined } from '@ant-design/icons';
9
+ import { CaretRightOutlined, LoadingOutlined } from '@ant-design/icons';
10
10
  import { observer } from 'mobx-react-lite';
11
11
  import React, { useCallback, useMemo, useState } from 'react';
12
12
  import styled, { css } from 'styled-components';
@@ -18,26 +18,27 @@ import { Menu } from "../Menu";
18
18
  import { MainArea, MainProperty } from "./MainProperties";
19
19
  var ExpandedIcon = styled(CaretRightOutlined).withConfig({
20
20
  shouldForwardProp: function shouldForwardProp(prop) {
21
- return !['expanded'].includes(prop);
21
+ return !['expanded', 'loading'].includes(prop);
22
22
  }
23
- })(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n transition: transform 0.5s;\n display: block;\n user-select: none;\n ", ";\n font-size: var(--kep-platform-font-size-sm);\n &:hover {\n color: var(--kep-platform-color-primary);\n }\n"])), function (props) {
23
+ })(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n\ttransition: transform 0.5s;\n\tdisplay: block;\n\tuser-select: none;\n\t", ";\n\tfont-size: var(--kep-platform-font-size-sm);\n\t&:hover {\n\t\tcolor: var(--kep-platform-color-primary);\n\t}\n"])), function (props) {
24
24
  if (props.expanded) {
25
- return css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n transform: rotate(90deg);\n "])));
25
+ return css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n\t\t\t\ttransform: rotate(90deg);\n\t\t\t"])));
26
26
  }
27
27
  });
28
- var TitleArea = styled(FlexItem)(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral([""])));
29
- var TreeNode = styled(ListItem)(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n ", "\n & ", ",& ", " {\n background-color: var(--kep-platform-color-bg-base);\n }\n /* \u5904\u7406\u9F20\u6807\u79FB\u5165 */\n &:hover {\n background-color: var(--kep-platform-color-bg-hover);\n & ", ", & ", " {\n background-color: var(--kep-platform-color-bg-hover);\n }\n & ", " {\n overflow-x: auto;\n & > ", " {\n width: auto;\n }\n }\n & ", " {\n overflow-x: auto;\n }\n }\n /* \u5904\u7406\u8282\u70B9\u9009\u4E2D */\n ", "\n"])), function (props) {
28
+ var LoadingIcon = styled(LoadingOutlined)(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n\tfont-size: var(--kep-platform-font-size-sm);\n\tuser-select: none;\n"])));
29
+ var TitleArea = styled(FlexItem)(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral([""])));
30
+ var TreeNode = styled(ListItem)(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n\t", "\n\t& ", ",& ", " {\n\t\tbackground-color: var(--kep-platform-color-bg-base);\n\t}\n\t/* \u5904\u7406\u9F20\u6807\u79FB\u5165 */\n\t&:hover {\n\t\tbackground-color: var(--kep-platform-color-bg-hover);\n\t\t& ", ", & ", " {\n\t\t\tbackground-color: var(--kep-platform-color-bg-hover);\n\t\t}\n\t\t& ", " {\n\t\t\toverflow-x: auto;\n\t\t\t& > ", " {\n\t\t\t\twidth: auto;\n\t\t\t}\n\t\t}\n\t\t& ", " {\n\t\t\toverflow-x: auto;\n\t\t}\n\t}\n\t/* \u5904\u7406\u8282\u70B9\u9009\u4E2D */\n\t", "\n"])), function (props) {
30
31
  if (props.width) {
31
- return css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n width: ", "px;\n "])), props.width);
32
+ return css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n\t\t\t\twidth: ", "px;\n\t\t\t"])), props.width);
32
33
  }
33
34
  }, Column, MainArea, Column, MainArea, MainArea, Flex, TitleArea, function (props) {
34
35
  if (props.selected) {
35
- return css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n background-color: var(--kep-platform-color-bg-active) !important;\n color: var(--kep-platform-color-text-active) !important;\n & ", ", & ", " {\n background-color: var(--kep-platform-color-bg-active) !important;\n color: var(--kep-platform-color-text-active) !important;\n }\n & ", " {\n overflow-x: auto;\n & > ", " {\n width: auto;\n }\n }\n & ", " {\n overflow-x: auto;\n }\n "])), Column, MainArea, MainArea, Flex, TitleArea);
36
+ return css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n\t\t\t\tbackground-color: var(--kep-platform-color-bg-active) !important;\n\t\t\t\tcolor: var(--kep-platform-color-text-active) !important;\n\t\t\t\t& ", ", & ", " {\n\t\t\t\t\tbackground-color: var(--kep-platform-color-bg-active) !important;\n\t\t\t\t\tcolor: var(--kep-platform-color-text-active) !important;\n\t\t\t\t}\n\t\t\t\t& ", " {\n\t\t\t\t\toverflow-x: auto;\n\t\t\t\t\t& > ", " {\n\t\t\t\t\t\twidth: auto;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t& ", " {\n\t\t\t\t\toverflow-x: auto;\n\t\t\t\t}\n\t\t\t"])), Column, MainArea, MainArea, Flex, TitleArea);
36
37
  }
37
38
  });
38
- var TreeNodeGroupNode = styled.li(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n height: 32px;\n line-height: 32px;\n background-color: var(--kep-platform-color-primary);\n color: var(--kep-platform-color-white);\n & span {\n color: var(--kep-platform-color-white) !important;\n }\n cursor: pointer;\n ", "\n"])), function (props) {
39
+ var TreeNodeGroupNode = styled.li(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n\theight: 32px;\n\tline-height: 32px;\n\tbackground-color: var(--kep-platform-color-primary);\n\tcolor: var(--kep-platform-color-white);\n\t& span {\n\t\tcolor: var(--kep-platform-color-white) !important;\n\t}\n\tcursor: pointer;\n\t", "\n"])), function (props) {
39
40
  if (props.width) {
40
- return css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n width: ", "px;\n "])), props.width);
41
+ return css(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n\t\t\t\twidth: ", "px;\n\t\t\t"])), props.width);
41
42
  }
42
43
  });
43
44
  var TreeNodeGroup = function TreeNodeGroup(props) {
@@ -119,17 +120,27 @@ export var TreeNodeController = observer(function (_ref) {
119
120
  onExpand = _ref.onExpand,
120
121
  contextMenuRender = _ref.contextMenuRender,
121
122
  onContextMenuItemSelect = _ref.onContextMenuItemSelect,
122
- titleRender = _ref.titleRender;
123
+ titleRender = _ref.titleRender,
124
+ loadData = _ref.loadData,
125
+ loadedKeys = _ref.loadedKeys,
126
+ setLoadedKeys = _ref.setLoadedKeys;
123
127
  /* 处理子节点缩进 */
124
128
  var childLevel = useMemo(function () {
125
129
  return level + 1;
126
130
  }, [level]);
131
+ var _useState3 = useState(false),
132
+ _useState4 = _slicedToArray(_useState3, 2),
133
+ loading = _useState4[0],
134
+ setLoading = _useState4[1];
127
135
  var selected = useMemo(function () {
128
136
  return selectedKeys.includes(node[fieldNames.key]) && !isFalse(node.selectable);
129
137
  }, [selectedKeys, fieldNames, node]);
130
138
  var expanded = useMemo(function () {
131
- return (expandedKeys.includes(node[fieldNames.key]) || node.nodeType === nodeTypeMap.virtual) && !node.isLeaf;
132
- }, [expandedKeys, fieldNames, node]);
139
+ return (expandedKeys.includes(node[fieldNames.key]) || node.nodeType === nodeTypeMap.virtual) && !node.isLeaf && !loading;
140
+ }, [expandedKeys, fieldNames, node, loading]);
141
+ var loaded = useMemo(function () {
142
+ return (loadedKeys === null || loadedKeys === void 0 ? void 0 : loadedKeys.includes(node[fieldNames.key])) || node.nodeType === nodeTypeMap.virtual;
143
+ }, [loadedKeys, fieldNames, node]);
133
144
  var treeNodeGroup = useMemo(function () {
134
145
  return groupTreeNodeByPropertyName(node.groupBy, node.children || []);
135
146
  }, [node.children, node.groupBy]);
@@ -165,10 +176,11 @@ export var TreeNodeController = observer(function (_ref) {
165
176
  node: node,
166
177
  selected: !selected
167
178
  });
168
- }, [onSelect, selectedKeys, multiple, selected]);
179
+ }, [onSelect, selectedKeys, multiple, selected, node]);
169
180
  var onClickExpandIconhandler = useCallback(function (e) {
170
181
  e.preventDefault();
171
182
  e.stopPropagation();
183
+ if (loading) return;
172
184
  if (expanded) {
173
185
  onExpand(expandedKeys.filter(function (key) {
174
186
  return key !== node[fieldNames.key];
@@ -178,14 +190,30 @@ export var TreeNodeController = observer(function (_ref) {
178
190
  expanded: !expanded
179
191
  });
180
192
  } else {
181
- onExpand(expandedKeys.concat([node[fieldNames.key]]), {
182
- nativeEvent: e,
183
- node: node,
184
- expanded: !expanded
185
- });
193
+ //如果有loadData则触发。
194
+ if (loadData && !loaded) {
195
+ setLoading(true);
196
+ loadData(node).then(function () {
197
+ setLoading(false);
198
+ setLoadedKeys(loadedKeys.concat([node[fieldNames.key]]));
199
+ onExpand(expandedKeys.concat([node[fieldNames.key]]), {
200
+ nativeEvent: e,
201
+ node: node,
202
+ expanded: !expanded
203
+ });
204
+ }, function () {
205
+ setLoading(false);
206
+ });
207
+ } else {
208
+ onExpand(expandedKeys.concat([node[fieldNames.key]]), {
209
+ nativeEvent: e,
210
+ node: node,
211
+ expanded: !expanded
212
+ });
213
+ }
186
214
  }
187
- }, [expandedKeys, onExpand, expanded]);
188
- var nodeEntity = /*#__PURE__*/React.createElement(MainProperty, {
215
+ }, [expandedKeys, onExpand, expanded, loading, loadData, node]);
216
+ var nodeEntity = node.nodeType !== nodeTypeMap.virtual ? null : /*#__PURE__*/React.createElement(MainProperty, {
189
217
  isFlex: isFlex,
190
218
  mainWidth: mainWidth,
191
219
  main: /*#__PURE__*/React.createElement(Flex, null, /*#__PURE__*/React.createElement(FlexItem, null, /*#__PURE__*/React.createElement(Indent, {
@@ -195,7 +223,7 @@ export var TreeNodeController = observer(function (_ref) {
195
223
  align: "center",
196
224
  cursor: "pointer",
197
225
  onClick: onClickExpandIconhandler
198
- }, /*#__PURE__*/React.createElement(ExpandedIcon, {
226
+ }, loading ? /*#__PURE__*/React.createElement(LoadingIcon, null) : /*#__PURE__*/React.createElement(ExpandedIcon, {
199
227
  expanded: expanded,
200
228
  hidden: node.isLeaf
201
229
  })), /*#__PURE__*/React.createElement(TitleArea, {
@@ -234,6 +262,7 @@ export var TreeNodeController = observer(function (_ref) {
234
262
  key: childNode[fieldNames.key],
235
263
  node: childNode,
236
264
  fieldNames: fieldNames,
265
+ loadData: loadData,
237
266
  isFlex: isFlex,
238
267
  isTableMode: isTableMode,
239
268
  columns: columns,
@@ -245,7 +274,9 @@ export var TreeNodeController = observer(function (_ref) {
245
274
  expandedKeys: expandedKeys,
246
275
  contextMenuRender: contextMenuRender,
247
276
  titleRender: titleRender,
248
- onContextMenuItemSelect: onContextMenuItemSelect
277
+ onContextMenuItemSelect: onContextMenuItemSelect,
278
+ loadedKeys: loadedKeys,
279
+ setLoadedKeys: setLoadedKeys
249
280
  });
250
281
  }));
251
282
  }), expanded && treeNodeGroup && Array.isArray(treeNodeGroup) && treeNodeGroup.map(function (childNode) {
@@ -256,6 +287,7 @@ export var TreeNodeController = observer(function (_ref) {
256
287
  node: childNode,
257
288
  fieldNames: fieldNames,
258
289
  isFlex: isFlex,
290
+ loadData: loadData,
259
291
  isTableMode: isTableMode,
260
292
  columns: columns,
261
293
  onSelect: onSelect,
@@ -266,7 +298,9 @@ export var TreeNodeController = observer(function (_ref) {
266
298
  expandedKeys: expandedKeys,
267
299
  contextMenuRender: contextMenuRender,
268
300
  titleRender: titleRender,
269
- onContextMenuItemSelect: onContextMenuItemSelect
301
+ onContextMenuItemSelect: onContextMenuItemSelect,
302
+ loadedKeys: loadedKeys,
303
+ setLoadedKeys: setLoadedKeys
270
304
  });
271
305
  }));
272
306
  });
package/dist/Tree/test.js CHANGED
@@ -72,7 +72,7 @@ var MyStore = /*#__PURE__*/function () {
72
72
  }();
73
73
  var mystore = new MyStore([{
74
74
  key: '1',
75
- title: 'jss',
75
+ title: 'js222s',
76
76
  count: 1,
77
77
  selectable: false,
78
78
  isLeaf: true,
@@ -131,7 +131,7 @@ var mystore = new MyStore([{
131
131
  count: 1
132
132
  }]
133
133
  }]);
134
- var Title = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n width: 100%;\n text-align: center;\n"])));
134
+ var Title = styled.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n\twidth: 100%;\n\ttext-align: center;\n"])));
135
135
  export default (function () {
136
136
  var _useState = useState([]),
137
137
  _useState2 = _slicedToArray(_useState, 2),
@@ -204,6 +204,13 @@ export default (function () {
204
204
  },
205
205
  titleRender: function titleRender(node) {
206
206
  return node.title;
207
+ },
208
+ loadData: function loadData() {
209
+ return new Promise(function (resolve) {
210
+ setTimeout(function () {
211
+ resolve(true);
212
+ }, 2000);
213
+ });
207
214
  }
208
215
  }));
209
216
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kep-platform/basic-component",
3
- "version": "1.0.6",
3
+ "version": "1.0.8",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -86,5 +86,5 @@
86
86
  "authors": [
87
87
  "less-step-jss 1599925910@qq.com"
88
88
  ],
89
- "gitHead": "e64b8404e6b9d9ce2c7d411d6183ce27a2c624bf"
89
+ "gitHead": "a49f28bab74144cfa6a8982009a73edb58a38088"
90
90
  }