@kep-platform/basic-component 0.0.14 → 0.0.18
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/@types/index.d.ts +0 -1
- package/dist/Menu/Menu.d.ts +4 -2
- package/dist/Menu/Menu.js +33 -15
- package/dist/Tree/BOMTree.js +3 -0
- package/dist/Tree/Tree.d.ts +2 -1
- package/dist/Tree/Tree.js +2 -0
- package/dist/Tree/TreeNode.d.ts +1 -0
- package/dist/Tree/TreeNode.js +19 -9
- package/package.json +3 -3
package/dist/@types/index.d.ts
CHANGED
package/dist/Menu/Menu.d.ts
CHANGED
@@ -1,9 +1,11 @@
|
|
1
|
-
import React, { ReactNode } from 'react';
|
1
|
+
import React, { ReactNode, type Key } from 'react';
|
2
2
|
export type MenuProps = {
|
3
3
|
items: MenuItem[];
|
4
4
|
direction?: Direction;
|
5
|
+
activeKey?: Key;
|
6
|
+
onSelect?: (key: Key, item: MenuItem) => void;
|
5
7
|
};
|
6
|
-
declare function Menu({ items, direction }: MenuProps): React.JSX.Element;
|
8
|
+
declare function Menu({ items, direction, onSelect, activeKey: outerActiveKey }: MenuProps): React.JSX.Element;
|
7
9
|
declare namespace Menu {
|
8
10
|
var Popup: typeof PopupMenu;
|
9
11
|
}
|
package/dist/Menu/Menu.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
var _excluded = ["children", "trigger"];
|
1
|
+
var _excluded = ["children", "onSelect", "activeKey", "trigger"];
|
2
2
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
3
3
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
4
4
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
@@ -20,7 +20,7 @@ var MenuList = styled(List).withConfig({
|
|
20
20
|
var MenuListItem = styled(ListItem).withConfig({
|
21
21
|
displayName: "MenuListItem",
|
22
22
|
componentId: "basic-component-347b__sc-d665dh-1"
|
23
|
-
})(["background-color:var(--kep-platform-color-bg-base);border-radius:var(--kep-platform-border-radius-sm);margin:var(--kep-platform-margin-xxxs);padding:0 var(--kep-platform-padding-xs);height:var(--kep-platform-menu-item-height);line-height:var(--kep-platform-menu-item-line-height);&:hover{background-color:var(--kep-platform-color-bg-hover);}", ""], function (props) {
|
23
|
+
})(["background-color:var(--kep-platform-color-bg-base);border-radius:var(--kep-platform-border-radius-sm);margin:var(--kep-platform-margin-xxxs);padding:0 var(--kep-platform-padding-xs);height:var(--kep-platform-menu-item-height);line-height:var(--kep-platform-menu-item-line-height);color:var(--kep-platform-color-text) !important;&:hover{background-color:var(--kep-platform-color-bg-hover);}", ""], function (props) {
|
24
24
|
if (props.active) {
|
25
25
|
return css(["background-color:var(--kep-platform-color-bg-active) !important;color:var(--kep-platform-color-text-active) !important;"]);
|
26
26
|
}
|
@@ -28,38 +28,48 @@ var MenuListItem = styled(ListItem).withConfig({
|
|
28
28
|
function Menu(_ref) {
|
29
29
|
var items = _ref.items,
|
30
30
|
_ref$direction = _ref.direction,
|
31
|
-
direction = _ref$direction === void 0 ? 'row' : _ref$direction
|
32
|
-
|
31
|
+
direction = _ref$direction === void 0 ? 'row' : _ref$direction,
|
32
|
+
onSelect = _ref.onSelect,
|
33
|
+
outerActiveKey = _ref.activeKey;
|
34
|
+
var _useState = useState(outerActiveKey),
|
33
35
|
_useState2 = _slicedToArray(_useState, 2),
|
34
36
|
activeKey = _useState2[0],
|
35
37
|
setActiveKey = _useState2[1];
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
}, []);
|
38
|
+
useEffect(function () {
|
39
|
+
setActiveKey(outerActiveKey);
|
40
|
+
}, [outerActiveKey]);
|
40
41
|
return /*#__PURE__*/React.createElement(MenuList, {
|
41
42
|
direction: direction
|
42
43
|
}, items.map(function (item) {
|
43
44
|
return /*#__PURE__*/React.createElement(MenuListItem, {
|
44
45
|
key: item.key,
|
45
46
|
active: activeKey === item.key,
|
46
|
-
onClick:
|
47
|
+
onClick: function onClick() {
|
48
|
+
setActiveKey(item.key);
|
49
|
+
onSelect === null || onSelect === void 0 || onSelect(item.key, item);
|
50
|
+
},
|
47
51
|
"data-key": item.key
|
48
52
|
}, item.label);
|
49
53
|
}));
|
50
54
|
}
|
51
55
|
export function PopupMenu(props) {
|
52
56
|
var children = props.children,
|
57
|
+
onSelect = props.onSelect,
|
58
|
+
outerActiveKey = props.activeKey,
|
53
59
|
_props$trigger = props.trigger,
|
54
60
|
trigger = _props$trigger === void 0 ? 'click' : _props$trigger,
|
55
61
|
rest = _objectWithoutProperties(props, _excluded);
|
56
|
-
var _useState3 = useState(
|
62
|
+
var _useState3 = useState(outerActiveKey),
|
63
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
64
|
+
activeKey = _useState4[0],
|
65
|
+
setActiveKey = _useState4[1];
|
66
|
+
var _useState5 = useState({
|
57
67
|
left: 0,
|
58
68
|
top: 0
|
59
69
|
}),
|
60
|
-
|
61
|
-
pos =
|
62
|
-
setPos =
|
70
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
71
|
+
pos = _useState6[0],
|
72
|
+
setPos = _useState6[1];
|
63
73
|
var triggerController = useRef(null);
|
64
74
|
var popupBox = useRef(null);
|
65
75
|
var mergeProps = useMemo(function () {
|
@@ -68,7 +78,6 @@ export function PopupMenu(props) {
|
|
68
78
|
};
|
69
79
|
}, []);
|
70
80
|
var showPopupMenu = useCallback(function (e) {
|
71
|
-
e.stopPropagation();
|
72
81
|
e.preventDefault();
|
73
82
|
var _ref2 = e,
|
74
83
|
clientX = _ref2.clientX,
|
@@ -77,6 +86,7 @@ export function PopupMenu(props) {
|
|
77
86
|
left: clientX,
|
78
87
|
top: clientY
|
79
88
|
});
|
89
|
+
setActiveKey(undefined);
|
80
90
|
}, []);
|
81
91
|
var hidePopupMenu = useCallback(function () {
|
82
92
|
setPos({
|
@@ -84,6 +94,11 @@ export function PopupMenu(props) {
|
|
84
94
|
top: -999
|
85
95
|
});
|
86
96
|
}, []);
|
97
|
+
var onSelectHandler = useCallback(function (key, item) {
|
98
|
+
onSelect === null || onSelect === void 0 || onSelect(key, item);
|
99
|
+
setActiveKey(key);
|
100
|
+
hidePopupMenu();
|
101
|
+
}, [onSelect, hidePopupMenu]);
|
87
102
|
useClickOutsize('mousedown', popupBox, hidePopupMenu);
|
88
103
|
useClickOutsize('scroll', popupBox, hidePopupMenu);
|
89
104
|
useEffect(function () {
|
@@ -97,8 +112,11 @@ export function PopupMenu(props) {
|
|
97
112
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(PopupBox, {
|
98
113
|
left: pos.left,
|
99
114
|
top: pos.top,
|
100
|
-
ref: popupBox
|
115
|
+
ref: popupBox,
|
116
|
+
onClick: hidePopupMenu
|
101
117
|
}, /*#__PURE__*/React.createElement(Menu, _extends({}, rest, {
|
118
|
+
activeKey: outerActiveKey || activeKey,
|
119
|
+
onSelect: onSelectHandler,
|
102
120
|
direction: "column"
|
103
121
|
}))), /*#__PURE__*/React.cloneElement(children, mergeProps));
|
104
122
|
} else console.warn('PopupMenu需要一个触发元素!');
|
package/dist/Tree/BOMTree.js
CHANGED
@@ -100,6 +100,9 @@ export default (function () {
|
|
100
100
|
multiple: true,
|
101
101
|
titleWidth: 400,
|
102
102
|
contextMenuRender: contextMenuRender,
|
103
|
+
onContextMenuItemSelect: function onContextMenuItemSelect(node) {
|
104
|
+
console.log(node.key);
|
105
|
+
},
|
103
106
|
treeData: treeData,
|
104
107
|
columns: columns,
|
105
108
|
selectedKeys: selectedKeys,
|
package/dist/Tree/Tree.d.ts
CHANGED
@@ -9,7 +9,8 @@ export type TreeProps = {
|
|
9
9
|
titleRender?: ((node: TreeNodeType) => ReactNode | null) | null | undefined;
|
10
10
|
onExpand?: onExpandHandler;
|
11
11
|
onSelect?: onSelectHandler;
|
12
|
-
contextMenuRender
|
12
|
+
contextMenuRender?: (node: TreeNodeType) => MenuItem[];
|
13
|
+
onContextMenuItemSelect?: (node: TreeNodeType, key: Key, item: MenuItem) => void;
|
13
14
|
titleWidth?: number;
|
14
15
|
title?: ReactNode;
|
15
16
|
isFlex?: boolean;
|
package/dist/Tree/Tree.js
CHANGED
@@ -57,6 +57,7 @@ var Tree = function Tree(_ref) {
|
|
57
57
|
_ref$onExpand = _ref.onExpand,
|
58
58
|
onExpand = _ref$onExpand === void 0 ? function () {} : _ref$onExpand,
|
59
59
|
contextMenuRender = _ref.contextMenuRender,
|
60
|
+
onContextMenuItemSelect = _ref.onContextMenuItemSelect,
|
60
61
|
_ref$multiple = _ref.multiple,
|
61
62
|
multiple = _ref$multiple === void 0 ? false : _ref$multiple,
|
62
63
|
_ref$bordered = _ref.bordered,
|
@@ -166,6 +167,7 @@ var Tree = function Tree(_ref) {
|
|
166
167
|
level: rootLevel,
|
167
168
|
mainWidth: titleWidth,
|
168
169
|
contextMenuRender: contextMenuRender,
|
170
|
+
onContextMenuItemSelect: onContextMenuItemSelect,
|
169
171
|
titleRender: titleRender
|
170
172
|
})));
|
171
173
|
};
|
package/dist/Tree/TreeNode.d.ts
CHANGED
@@ -14,6 +14,7 @@ export type TreeNodeControllerProps = {
|
|
14
14
|
expandedKeys: Key[];
|
15
15
|
onExpand: onExpandHandler;
|
16
16
|
contextMenuRender?: (node: TreeNodeType) => MenuItem[];
|
17
|
+
onContextMenuItemSelect?: (node: TreeNodeType, key: Key, item: MenuItem) => void;
|
17
18
|
titleRender?: ((node: TreeNodeType) => ReactNode | null) | null | undefined;
|
18
19
|
};
|
19
20
|
export declare const nodeTypeMap: {
|
package/dist/Tree/TreeNode.js
CHANGED
@@ -21,21 +21,25 @@ var ExpandedIcon = styled(CaretRightOutlined).withConfig({
|
|
21
21
|
return css(["transform:rotate(90deg);"]);
|
22
22
|
}
|
23
23
|
});
|
24
|
+
var TitleArea = styled(FlexItem).withConfig({
|
25
|
+
displayName: "TitleArea",
|
26
|
+
componentId: "basic-component-347b__sc-tzoomn-1"
|
27
|
+
})([""]);
|
24
28
|
var TreeNode = styled(ListItem).withConfig({
|
25
29
|
displayName: "TreeNode",
|
26
|
-
componentId: "basic-component-347b__sc-tzoomn-
|
27
|
-
})(["", " & ", ",& ", "{background-color:var(--kep-platform-color-bg-base);}&:hover{background-color:var(--kep-platform-color-bg-hover);& ", ",& ", "{background-color:var(--kep-platform-color-bg-hover);}& ", "{overflow-x:auto;& > ", "{width:auto;}}}", ""], function (props) {
|
30
|
+
componentId: "basic-component-347b__sc-tzoomn-2"
|
31
|
+
})(["", " & ", ",& ", "{background-color:var(--kep-platform-color-bg-base);}&:hover{background-color:var(--kep-platform-color-bg-hover);& ", ",& ", "{background-color:var(--kep-platform-color-bg-hover);}& ", "{overflow-x:auto;& > ", "{width:auto;}}& ", "{overflow-x:auto;}}", ""], function (props) {
|
28
32
|
if (props.width) {
|
29
33
|
return css(["width:", "px;"], props.width);
|
30
34
|
}
|
31
|
-
}, Column, MainArea, Column, MainArea, MainArea, Flex, function (props) {
|
35
|
+
}, Column, MainArea, Column, MainArea, MainArea, Flex, TitleArea, function (props) {
|
32
36
|
if (props.selected) {
|
33
|
-
return css(["background-color:var(--kep-platform-color-bg-active) !important;color:var(--kep-platform-color-text-active) !important;& ", ",& ", "{background-color:var(--kep-platform-color-bg-active) !important;color:var(--kep-platform-color-text-active) !important;}& ", "{overflow-x:auto;& > ", "{width:auto;}}"], Column, MainArea, MainArea, Flex);
|
37
|
+
return css(["background-color:var(--kep-platform-color-bg-active) !important;color:var(--kep-platform-color-text-active) !important;& ", ",& ", "{background-color:var(--kep-platform-color-bg-active) !important;color:var(--kep-platform-color-text-active) !important;}& ", "{overflow-x:auto;& > ", "{width:auto;}}& ", "{overflow-x:auto;}"], Column, MainArea, MainArea, Flex, TitleArea);
|
34
38
|
}
|
35
39
|
});
|
36
40
|
var TreeNodeGroupNode = styled.li.withConfig({
|
37
41
|
displayName: "TreeNodeGroupNode",
|
38
|
-
componentId: "basic-component-347b__sc-tzoomn-
|
42
|
+
componentId: "basic-component-347b__sc-tzoomn-3"
|
39
43
|
})(["height:40px;line-height:40px;background-color:var(--kep-platform-color-primary);color:var(--kep-platform-color-white);& span{color:var(--kep-platform-color-white) !important;}cursor:pointer;", ""], function (props) {
|
40
44
|
if (props.width) {
|
41
45
|
return css(["width:", "px;"], props.width);
|
@@ -105,6 +109,7 @@ export var TreeNodeController = function TreeNodeController(_ref) {
|
|
105
109
|
expandedKeys = _ref.expandedKeys,
|
106
110
|
onExpand = _ref.onExpand,
|
107
111
|
contextMenuRender = _ref.contextMenuRender,
|
112
|
+
onContextMenuItemSelect = _ref.onContextMenuItemSelect,
|
108
113
|
titleRender = _ref.titleRender;
|
109
114
|
/* 处理子节点缩进 */
|
110
115
|
var childLevel = useMemo(function () {
|
@@ -179,7 +184,7 @@ export var TreeNodeController = function TreeNodeController(_ref) {
|
|
179
184
|
onClick: onClickExpandIconhandler
|
180
185
|
}, /*#__PURE__*/React.createElement(ExpandedIcon, {
|
181
186
|
expanded: expanded
|
182
|
-
})), /*#__PURE__*/React.createElement(
|
187
|
+
})), /*#__PURE__*/React.createElement(TitleArea, {
|
183
188
|
flex: 1
|
184
189
|
}, titleRender ? titleRender(node) : node[fieldNames.title])),
|
185
190
|
property: isTableMode && /*#__PURE__*/React.createElement(Columns, {
|
@@ -192,10 +197,14 @@ export var TreeNodeController = function TreeNodeController(_ref) {
|
|
192
197
|
return /*#__PURE__*/React.createElement(React.Fragment, null, node.nodeType !== nodeTypeMap.virtual && /*#__PURE__*/React.createElement(TreeNode, {
|
193
198
|
selected: selectedKeys.includes(node[fieldNames.key]),
|
194
199
|
width: width,
|
195
|
-
onClick: onClickNodeHandler
|
200
|
+
onClick: onClickNodeHandler,
|
201
|
+
onContextMenu: onClickNodeHandler
|
196
202
|
}, contextMenuRender ? /*#__PURE__*/React.createElement(Menu.Popup, {
|
197
203
|
trigger: "contextmenu",
|
198
|
-
items: contextMenuRender(node)
|
204
|
+
items: contextMenuRender(node),
|
205
|
+
onSelect: function onSelect(key, item) {
|
206
|
+
return onContextMenuItemSelect === null || onContextMenuItemSelect === void 0 ? void 0 : onContextMenuItemSelect(node, key, item);
|
207
|
+
}
|
199
208
|
}, nodeEntity) : nodeEntity), expanded && treeNodeGroup && Object.keys(treeNodeGroup).map(function (groupKey) {
|
200
209
|
return /*#__PURE__*/React.createElement(TreeNodeGroup, {
|
201
210
|
width: width,
|
@@ -221,7 +230,8 @@ export var TreeNodeController = function TreeNodeController(_ref) {
|
|
221
230
|
onExpand: onExpand,
|
222
231
|
expandedKeys: expandedKeys,
|
223
232
|
contextMenuRender: contextMenuRender,
|
224
|
-
titleRender: titleRender
|
233
|
+
titleRender: titleRender,
|
234
|
+
onContextMenuItemSelect: onContextMenuItemSelect
|
225
235
|
});
|
226
236
|
}));
|
227
237
|
}));
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@kep-platform/basic-component",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.18",
|
4
4
|
"description": "A react library developed with dumi",
|
5
5
|
"module": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
@@ -74,10 +74,10 @@
|
|
74
74
|
"react-dom": "^18.0.0",
|
75
75
|
"stylelint": "^14.9.1"
|
76
76
|
},
|
77
|
-
"gitHead": "
|
77
|
+
"gitHead": "87aa5fd0616b79fc6cad62d3f57b6599325afd85",
|
78
78
|
"dependencies": {
|
79
79
|
"@ant-design/icons": "^5.3.7",
|
80
|
-
"@kep-platform/hooks": "^0.0.
|
80
|
+
"@kep-platform/hooks": "^0.0.18",
|
81
81
|
"color": "^4.2.3",
|
82
82
|
"rc-pagination": "^4.1.0",
|
83
83
|
"styled-components": "^6.1.11"
|