@cloudbase/weda-ui 3.18.6 → 3.19.0
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/configs/components/lottery.d.ts +2 -0
- package/dist/configs/components/lottery.js +6 -1
- package/dist/configs/components/wd-checkbox.js +4 -0
- package/dist/configs/components/wd-image.js +1 -0
- package/dist/configs/components/wd-radio.js +4 -0
- package/dist/configs/components/wd-table.d.ts +16 -0
- package/dist/configs/components/wd-table.js +16 -0
- package/dist/configs/components/wd-tree.d.ts +33 -0
- package/dist/configs/components/wd-tree.js +58 -0
- package/dist/configs/index.d.ts +60 -0
- package/dist/configs/type-utils/type-form.js +4 -0
- package/dist/style/index.css +2 -1
- package/dist/style/index.scss +1 -1
- package/dist/style/weda-ui.min.css +2 -2
- package/dist/web/components/customer-service/customer-service.js +4 -3
- package/dist/web/components/lottery/index.d.ts +1 -0
- package/dist/web/components/lottery/index.js +19 -47
- package/dist/web/components/lottery/lotteryUtil.d.ts +1 -1
- package/dist/web/components/lottery/lotteryUtil.js +4 -5
- package/dist/web/components/wd-table/components/Table/index.js +9 -14
- package/dist/web/components/wd-table/utils/index.d.ts +1 -0
- package/dist/web/components/wd-table/utils/index.js +1 -1
- package/dist/web/components/wd-table/wd-table.js +4 -0
- package/dist/web/components/wd-tree/utils.d.ts +29 -3
- package/dist/web/components/wd-tree/utils.js +26 -12
- package/dist/web/components/wd-tree/wd-tree.d.ts +1 -0
- package/dist/web/components/wd-tree/wd-tree.js +65 -40
- package/package.json +5 -5
|
@@ -74,19 +74,20 @@ const judgeCheck = (treeNode, checkedCustom) => {
|
|
|
74
74
|
* @param {IInitData} param0
|
|
75
75
|
* @returns
|
|
76
76
|
*/
|
|
77
|
-
const initData = ({ data, parent, showIcon, expendIcon, foldIcon, leafIcon, pos = ''
|
|
77
|
+
const initData = ({ data, parent, showIcon, expendIcon, foldIcon, leafIcon, pos = '' }) => {
|
|
78
78
|
if (!Array.isArray(data))
|
|
79
79
|
return [];
|
|
80
80
|
return data
|
|
81
81
|
.filter((item) => item === null || item === void 0 ? void 0 : item.value)
|
|
82
|
-
.map((
|
|
82
|
+
.map((_item, index) => {
|
|
83
83
|
var _a;
|
|
84
|
+
const item = { ..._item };
|
|
84
85
|
item.pos = `${pos ? `${pos}-` : ''}${index}`;
|
|
85
86
|
item.root = item.root || { ...deepClone(item), pos: item.pos };
|
|
86
87
|
if ((_a = item.children) === null || _a === void 0 ? void 0 : _a.length) {
|
|
87
88
|
item.children = initData({
|
|
88
|
-
data:
|
|
89
|
-
parent: item,
|
|
89
|
+
data: _item.children,
|
|
90
|
+
parent: { ...item },
|
|
90
91
|
showIcon,
|
|
91
92
|
expendIcon,
|
|
92
93
|
foldIcon,
|
|
@@ -98,7 +99,7 @@ const initData = ({ data, parent, showIcon, expendIcon, foldIcon, leafIcon, pos
|
|
|
98
99
|
item.foldIcon = item.foldIcon || foldIcon;
|
|
99
100
|
item.leafIcon = item.leafIcon || leafIcon;
|
|
100
101
|
item.showIcon = showIcon;
|
|
101
|
-
item.parent = parent;
|
|
102
|
+
item.parent = { ...parent };
|
|
102
103
|
return item;
|
|
103
104
|
});
|
|
104
105
|
};
|
|
@@ -107,7 +108,7 @@ const initData = ({ data, parent, showIcon, expendIcon, foldIcon, leafIcon, pos
|
|
|
107
108
|
* @param {IGetStateOfChildrenParams} param0
|
|
108
109
|
* @returns
|
|
109
110
|
*/
|
|
110
|
-
const getStateOfChildren = ({ treeNode, key, state
|
|
111
|
+
const getStateOfChildren = ({ treeNode, key, state }) => {
|
|
111
112
|
var _a, _b, _c;
|
|
112
113
|
const notHas = (_a = treeNode.children) === null || _a === void 0 ? void 0 : _a.map((v) => v[key]).includes(state.notHas);
|
|
113
114
|
const has = (_b = treeNode.children) === null || _b === void 0 ? void 0 : _b.map((v) => v[key]).includes(state.has);
|
|
@@ -194,9 +195,7 @@ const initTreeState = ({ data, checkedCustom, expandType, expandCustom, searchKe
|
|
|
194
195
|
item.expanded = item.searched ? 'expand' : '';
|
|
195
196
|
}
|
|
196
197
|
// 被搜索到的或根据输入判断需要展开的都认为要展开
|
|
197
|
-
item.isExpand =
|
|
198
|
-
!!((_b = item.children) === null || _b === void 0 ? void 0 : _b.length) &&
|
|
199
|
-
(searchKey ? !!item.searched : !!item.expanded);
|
|
198
|
+
item.isExpand = !!((_b = item.children) === null || _b === void 0 ? void 0 : _b.length) && (searchKey ? !!item.searched : !!item.expanded);
|
|
200
199
|
if (item.showIcon) {
|
|
201
200
|
if ((_c = item.children) === null || _c === void 0 ? void 0 : _c.length) {
|
|
202
201
|
item.iconShow = item.isExpand ? item.expendIcon : item.foldIcon;
|
|
@@ -212,9 +211,10 @@ const initTreeState = ({ data, checkedCustom, expandType, expandCustom, searchKe
|
|
|
212
211
|
* 当某节点的选择状态变化时,处理该节点的父和子的选择状态
|
|
213
212
|
* @param treeNode
|
|
214
213
|
*/
|
|
215
|
-
const dealCheck = (
|
|
214
|
+
const dealCheck = (_treeNode, showData) => {
|
|
216
215
|
var _a;
|
|
217
|
-
|
|
216
|
+
const treeNode = getTreeNode(showData, _treeNode);
|
|
217
|
+
let parent = getTreeNode(showData, treeNode.parent);
|
|
218
218
|
const adjust = (arr, checked) => {
|
|
219
219
|
arr.forEach((item) => {
|
|
220
220
|
var _a;
|
|
@@ -231,6 +231,7 @@ const dealCheck = (treeNode) => {
|
|
|
231
231
|
if ((_a = treeNode.children) === null || _a === void 0 ? void 0 : _a.length) {
|
|
232
232
|
adjust(treeNode.children, treeNode.checked);
|
|
233
233
|
}
|
|
234
|
+
return treeNode;
|
|
234
235
|
};
|
|
235
236
|
/**
|
|
236
237
|
* 查找满足要求的节点
|
|
@@ -286,4 +287,17 @@ const getTreeInfo = (params, checkable) => {
|
|
|
286
287
|
delete info.selectedPositions;
|
|
287
288
|
return info;
|
|
288
289
|
};
|
|
289
|
-
export
|
|
290
|
+
export const getTreeNode = (tree = [], node) => {
|
|
291
|
+
var _a;
|
|
292
|
+
for (const item of tree) {
|
|
293
|
+
if (item.value === (node === null || node === void 0 ? void 0 : node.value))
|
|
294
|
+
return item;
|
|
295
|
+
if ((_a = item.children) === null || _a === void 0 ? void 0 : _a.length) {
|
|
296
|
+
const found = getTreeNode(item.children, node);
|
|
297
|
+
if (found)
|
|
298
|
+
return found; // 立即返回已找到的节点
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return null; // 明确返回null表示未找到
|
|
302
|
+
};
|
|
303
|
+
export { TREE_INFO_GOT, initData, initTreeState, dealCheck, findNode, getTreeInfo };
|
|
@@ -3,4 +3,5 @@ import type { CommonPropsType } from '../../types';
|
|
|
3
3
|
import type { DataType } from '../../../configs/components/wd-tree';
|
|
4
4
|
export declare const WdTree: React.ForwardRefExoticComponent<WdTreeProps & React.RefAttributes<unknown>>;
|
|
5
5
|
export interface WdTreeProps extends CommonPropsType, DataType {
|
|
6
|
+
contentSlot_treeNode?: any;
|
|
6
7
|
}
|
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useImperativeHandle, useEffect, useState, useCallback, } from 'react';
|
|
2
|
+
import React, { forwardRef, useImperativeHandle, useEffect, useState, useCallback, useRef } from 'react';
|
|
3
3
|
import classNames from '../../utils/classnames';
|
|
4
4
|
import { useConfig } from '../../utils/config-context';
|
|
5
5
|
import { usePlatform } from '../../utils/platform';
|
|
6
6
|
import WdCheckbox from '../wd-checkbox';
|
|
7
7
|
import WdIcon from '../wd-icon';
|
|
8
|
-
import { TREE_INFO_GOT, initData, initTreeState, dealCheck, getTreeInfo
|
|
8
|
+
import { TREE_INFO_GOT, initData, initTreeState, dealCheck, getTreeInfo } from './utils';
|
|
9
9
|
import { deepClone } from '../../utils/tool';
|
|
10
|
+
import isObjectEqual from '../../utils/isObjectEqual';
|
|
11
|
+
const TreeNodeSlot = React.memo(function TreeNodeSlot({ Slot, item, itemIndex }) {
|
|
12
|
+
if (typeof Slot === 'function') {
|
|
13
|
+
return _jsx(Slot, { item: item, itemIndex: itemIndex });
|
|
14
|
+
}
|
|
15
|
+
return Slot !== null && Slot !== void 0 ? Slot : null;
|
|
16
|
+
});
|
|
10
17
|
export const WdTree = forwardRef(function WdTree(props, ref) {
|
|
11
18
|
var _a;
|
|
12
|
-
const { className = '', style, id, events, data, checkable, checkedCustom, expandType, expandCustom, showIcon, foldIcon, expendIcon, leafIcon, line, } = props;
|
|
19
|
+
const { className = '', style, id, events, data, checkable, checkedCustom, expandType, expandCustom, showIcon, foldIcon, expendIcon, leafIcon, line, enableSearchText = true, isSupportSlot, } = props;
|
|
13
20
|
const platform = usePlatform();
|
|
14
21
|
// 样式
|
|
15
22
|
const { classPrefix } = useConfig();
|
|
@@ -28,6 +35,8 @@ export const WdTree = forwardRef(function WdTree(props, ref) {
|
|
|
28
35
|
const [selected, setSelected] = useState(((_a = props.checkedCustom) === null || _a === void 0 ? void 0 : _a.length) ? props.checkedCustom[0] : '');
|
|
29
36
|
// 搜索内容
|
|
30
37
|
const [searchKey, setSearchKey] = useState('');
|
|
38
|
+
const [treeNodeList, setTreeNodeList] = useState([]);
|
|
39
|
+
const showDataRef = useRef(null);
|
|
31
40
|
/**
|
|
32
41
|
* 组件搜索节点方法
|
|
33
42
|
*/
|
|
@@ -47,6 +56,7 @@ export const WdTree = forwardRef(function WdTree(props, ref) {
|
|
|
47
56
|
methods: {
|
|
48
57
|
searchNode,
|
|
49
58
|
},
|
|
59
|
+
treeNodeList,
|
|
50
60
|
treeInfo,
|
|
51
61
|
data,
|
|
52
62
|
checkable,
|
|
@@ -62,6 +72,7 @@ export const WdTree = forwardRef(function WdTree(props, ref) {
|
|
|
62
72
|
expandedNodes: treeInfo === null || treeInfo === void 0 ? void 0 : treeInfo.expandedNodes,
|
|
63
73
|
};
|
|
64
74
|
}, [
|
|
75
|
+
treeNodeList,
|
|
65
76
|
checkable,
|
|
66
77
|
checkedCustom,
|
|
67
78
|
data,
|
|
@@ -124,7 +135,7 @@ export const WdTree = forwardRef(function WdTree(props, ref) {
|
|
|
124
135
|
check: () => {
|
|
125
136
|
treeNode.checked = state ? 'checked' : '';
|
|
126
137
|
// 处理节点的父/子节点选中状态
|
|
127
|
-
dealCheck(treeNode);
|
|
138
|
+
dealCheck(treeNode, showData);
|
|
128
139
|
},
|
|
129
140
|
select: () => {
|
|
130
141
|
state = selectedKey !== treeNode.value;
|
|
@@ -160,41 +171,55 @@ export const WdTree = forwardRef(function WdTree(props, ref) {
|
|
|
160
171
|
}, 0);
|
|
161
172
|
event !== 'select' && setShowData([...showData]);
|
|
162
173
|
};
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
const
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
if (item.disabled)
|
|
187
|
-
return;
|
|
188
|
-
change(item, 'check', item.checked !== 'checked');
|
|
189
|
-
}, checkedItemValue: { [item.value]: item.checked === 'checked' }, ...{} })), item.iconShow && (_jsx(WdIcon, { "data-testid": "wd-tree-icon-test", className: `${classPrefix}-tree__label-icon `, name: item.iconShow, src: item.iconShow, type: item.iconShow.startsWith('http') ||
|
|
190
|
-
item.iconShow.startsWith('data:')
|
|
191
|
-
? 'custom'
|
|
192
|
-
: 'inner', size: "sm" })), _jsx("label", { className: `${classPrefix}-tree__label-text`, htmlFor: "", style: disableStyle, children: searchKey
|
|
193
|
-
? item.label.split(searchKey).map((v, i) => (_jsxs("span", { children: [i !== 0 && (_jsx("span", { className: `${classPrefix}-tree__label-text-search`, children: searchKey })), v] }, i)))
|
|
194
|
-
: item.label })] })] }, item.value));
|
|
195
|
-
subTree && item.isExpand && renderNode(subTree, count + STEP);
|
|
196
|
-
});
|
|
197
|
-
return list;
|
|
174
|
+
const renderTreeNode = ({ item, count, index, itemIndex }) => {
|
|
175
|
+
var _a;
|
|
176
|
+
const subTree = ((_a = item === null || item === void 0 ? void 0 : item.children) === null || _a === void 0 ? void 0 : _a.length) > 0 ? true : false;
|
|
177
|
+
const spaceDom = [];
|
|
178
|
+
const disableStyle = (item === null || item === void 0 ? void 0 : item.disabled) ? { cursor: 'not-allowed', color: 'rgba(0,0,0,.26)' } : {};
|
|
179
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
180
|
+
const { children, parent, ...rest } = item;
|
|
181
|
+
const nodeItem = { ...rest };
|
|
182
|
+
for (let i = 0; i < count; i++) {
|
|
183
|
+
spaceDom.push(_jsx("span", { className: `${classPrefix}-tree__space` }, Math.random()));
|
|
184
|
+
}
|
|
185
|
+
return (_jsxs("div", {
|
|
186
|
+
// 叶子节点 加 `${classPrefix}-tree-node--leaf` 为了连线的时候,对横线特殊处理
|
|
187
|
+
// 选中态,加 is-selected
|
|
188
|
+
className: `${nodeClassName} ${subTree ? '' : `${classPrefix}-tree-node--leaf`} ${selected === item.value && !props.checkable ? 'is-selected' : ''}`, "data-testid": nodeClassName, children: [spaceDom, _jsx("div", { className: `${classPrefix}-tree__switcher`, onClick: () => change(item, 'expand', !item.isExpand), children: subTree && (
|
|
189
|
+
// 展开/收起的图标
|
|
190
|
+
_jsx(WdIcon, { className: `${classPrefix}-tree__switcher-icon`, name: item.isExpand ? 'td:caret-down-small' : 'td:caret-right-small', size: "sm" })) }), _jsxs("div", { className: `${classPrefix}-tree__label`, onClick: () => change(item, 'select'), children: [props.checkable && (_jsx(WdCheckbox, { index: index + count, option: { value: item.value }, isAll: item.checked === 'childChecked', size: "md", disabled: item.disabled, getChangeHandler: () => {
|
|
191
|
+
if (item.disabled)
|
|
192
|
+
return;
|
|
193
|
+
change(item, 'check', item.checked !== 'checked');
|
|
194
|
+
}, checkedItemValue: { [item.value]: item.checked === 'checked' }, ...{} })), item.iconShow && (_jsx(WdIcon, { "data-testid": "wd-tree-icon-test", className: `${classPrefix}-tree__label-icon `, name: item.iconShow, src: item.iconShow, type: item.iconShow.startsWith('http') || item.iconShow.startsWith('data:') ? 'custom' : 'inner', size: "sm" })), enableSearchText && (_jsx("label", { className: `${classPrefix}-tree__label-text`, htmlFor: "", style: disableStyle, children: searchKey
|
|
195
|
+
? item.label.split(searchKey).map((v, i) => (_jsxs("span", { children: [i !== 0 && _jsx("span", { className: `${classPrefix}-tree__label-text-search`, children: searchKey }), v] }, i)))
|
|
196
|
+
: item.label })), isSupportSlot && nodeItem && (_jsx("label", { className: `${classPrefix}-tree__label-text`, htmlFor: "", style: disableStyle, children: _jsx(TreeNodeSlot, { item: nodeItem, Slot: props.contentSlot_treeNode, itemIndex: itemIndex }) }))] })] }, item.value));
|
|
198
197
|
};
|
|
199
|
-
|
|
198
|
+
useEffect(() => {
|
|
199
|
+
if (!isObjectEqual(showDataRef.current, showData)) {
|
|
200
|
+
const list = [];
|
|
201
|
+
const renderNode = (d, count) => {
|
|
202
|
+
if (!Array.isArray(d))
|
|
203
|
+
return [];
|
|
204
|
+
// @ts-ignore const 会报错,应该是let
|
|
205
|
+
count = count || 0;
|
|
206
|
+
const STEP = 1;
|
|
207
|
+
d.filter((item) => item === null || item === void 0 ? void 0 : item.value).forEach((item, index) => {
|
|
208
|
+
var _a;
|
|
209
|
+
const hasChildren = ((_a = item.children) === null || _a === void 0 ? void 0 : _a.length) > 0;
|
|
210
|
+
const subTree = hasChildren ? [...item.children] : undefined;
|
|
211
|
+
list.push({ item, count, index });
|
|
212
|
+
subTree && item.isExpand && renderNode(subTree, count + STEP);
|
|
213
|
+
});
|
|
214
|
+
return list;
|
|
215
|
+
};
|
|
216
|
+
let _treeNode = renderNode(showData, 0);
|
|
217
|
+
_treeNode = (_treeNode === null || _treeNode === void 0 ? void 0 : _treeNode.length) > 0 ? _treeNode === null || _treeNode === void 0 ? void 0 : _treeNode.map((i, index) => ({ ...i, itemIndex: index })) : [];
|
|
218
|
+
setTreeNodeList(_treeNode);
|
|
219
|
+
showDataRef.current = { ...showData };
|
|
220
|
+
}
|
|
221
|
+
}, [showData]);
|
|
222
|
+
return (_jsx("div", { id: id, style: style, className: classNames(classes, className), "data-testid": "wd-tree-test", children: treeNodeList === null || treeNodeList === void 0 ? void 0 : treeNodeList.map((i, index) => {
|
|
223
|
+
return _jsxs(React.Fragment, { children: [" ", renderTreeNode(i), " "] }, index);
|
|
224
|
+
}) }));
|
|
200
225
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/weda-ui",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.19.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"module": "./dist/index",
|
|
6
6
|
"miniprogram": "mpdist",
|
|
@@ -85,7 +85,7 @@
|
|
|
85
85
|
"description": "腾讯云微搭低代码组件库模板",
|
|
86
86
|
"dependencies": {
|
|
87
87
|
"@antv/g6": "^4.8.5",
|
|
88
|
-
"@cloudbase/weda-client": "^1.1.
|
|
88
|
+
"@cloudbase/weda-client": "^1.1.33",
|
|
89
89
|
"@codemirror/autocomplete": "^6.16.0",
|
|
90
90
|
"@codemirror/lang-javascript": "^6.2.2",
|
|
91
91
|
"@codemirror/lang-json": "^6.0.1",
|
|
@@ -147,9 +147,9 @@
|
|
|
147
147
|
"@babel/preset-env": "^7.22.15",
|
|
148
148
|
"@babel/preset-react": "^7.22.15",
|
|
149
149
|
"@babel/preset-typescript": "^7.22.15",
|
|
150
|
-
"@cloudbase/cals": "^1.2.
|
|
151
|
-
"@cloudbase/lowcode-cli": "^0.22.
|
|
152
|
-
"@cloudbase/weda-cloud-sdk": "^1.0.
|
|
150
|
+
"@cloudbase/cals": "^1.2.15",
|
|
151
|
+
"@cloudbase/lowcode-cli": "^0.22.3",
|
|
152
|
+
"@cloudbase/weda-cloud-sdk": "^1.0.104",
|
|
153
153
|
"@commitlint/cli": "^16.0.2",
|
|
154
154
|
"@commitlint/config-conventional": "^17.7.0",
|
|
155
155
|
"@craco/craco": "^7.1.0",
|