ant-design-vue/components/vc-tree/src/util.js

427 lines
10 KiB
JavaScript
Raw Normal View History

2018-03-23 13:30:20 +00:00
/* eslint no-loop-func: 0*/
2019-01-12 03:33:27 +00:00
import warning from 'warning';
import TreeNode from './TreeNode';
2020-07-16 14:44:00 +00:00
import { getOptionProps, getSlot } from '../../_util/props-util';
2019-01-12 03:33:27 +00:00
const DRAG_SIDE_RANGE = 0.25;
const DRAG_MIN_GAP = 2;
2018-03-23 13:30:20 +00:00
2019-01-12 03:33:27 +00:00
let onlyTreeNodeWarned = false;
2018-09-26 14:57:01 +00:00
2019-01-12 03:33:27 +00:00
export function warnOnlyTreeNode() {
if (onlyTreeNodeWarned) return;
2018-09-26 14:57:01 +00:00
2019-01-12 03:33:27 +00:00
onlyTreeNodeWarned = true;
warning(false, 'Tree only accept TreeNode as children.');
2018-09-26 14:57:01 +00:00
}
2019-01-12 03:33:27 +00:00
export function arrDel(list, value) {
const clone = list.slice();
const index = clone.indexOf(value);
2018-03-23 13:30:20 +00:00
if (index >= 0) {
2019-01-12 03:33:27 +00:00
clone.splice(index, 1);
2018-03-23 13:30:20 +00:00
}
2019-01-12 03:33:27 +00:00
return clone;
2018-03-23 13:30:20 +00:00
}
2019-01-12 03:33:27 +00:00
export function arrAdd(list, value) {
const clone = list.slice();
2018-03-23 13:30:20 +00:00
if (clone.indexOf(value) === -1) {
2019-01-12 03:33:27 +00:00
clone.push(value);
2018-03-23 13:30:20 +00:00
}
2019-01-12 03:33:27 +00:00
return clone;
2018-03-23 13:30:20 +00:00
}
2019-01-12 03:33:27 +00:00
export function posToArr(pos) {
return pos.split('-');
2018-03-23 13:30:20 +00:00
}
2019-01-12 03:33:27 +00:00
export function getPosition(level, index) {
return `${level}-${index}`;
2018-03-23 13:30:20 +00:00
}
2019-01-12 03:33:27 +00:00
export function isTreeNode(node) {
2020-07-18 13:40:26 +00:00
return node.type && node.type.isTreeNode;
2018-09-26 14:57:01 +00:00
}
2019-01-12 03:33:27 +00:00
export function getNodeChildren(children = []) {
return children.filter(isTreeNode);
2018-03-23 13:30:20 +00:00
}
2019-01-12 03:33:27 +00:00
export function isCheckDisabled(node) {
Feat 1.5.0 (#1853) * feat: add Result component * fix: update md template tag html>tpl - fix `result` typo - update jest `result` snapshots * refactor: svg file to functional component icon - update jest snapshot * feat: add result * Feat descriptions (#1251) * feat: add descriptions * fix: add descriptions types and fix docs * fix: lint change code * fix: demo warning * fix: update demo, snapshot and remove classnames * test: add descriptions test * fix: descriptions demo (#1498) * feat: add page header (#1250) * feat: add page-header component * update site: page-header * ts definition update: page-header * get page-header props with getComponentFromProp func * optimize page-header * doc: add page-header actions.md responsive.md * breadcrumb itemRender add pure function support * style: format code * feat: update style to 3.23.6 from 2.13.6 * feat: update style to 3.26.8 from 3.23.6 * chore: update util * chore: update util * feat: update affix * feat: update alert * feat: update anchor * feat: update auto-complete * feat: update avatar * feat: update back-top * feat: update badge * feat: update button * feat: update breadcrumb * feat: update ts * docs: update doc * feat: update calendat * feat: update card * feat: update carousel * feat: update carousel * feat: update checkbox * feat: update comment * feat: update config-provider * docs: update doc * feat: update collapse * feat: update locale * feat: update date-picker * feat: update divider * feat: update drawer * feat: update dropdown * feat: update rc-trigger * feat: update dropdown * feat: update empty * test: add empty test * feat: update form * feat: update form * feat: update spin * feat: update grid * docs: update grid doc * feat: update icon * feat: update slider * feat: update textarea * feat: update input-number * feat: update layout * feat: update list * feat: update menu * feat: meaage add key for update content * feat: modal add closeIcon support * feat: update notification * feat: add pagination disabled support * feat: popconfirm add disabled support * test: update popover * feat: progress support custom line-gradiend * feat: update radio * test: update radio test * docs: update rate demo * feat: skeleton add avatar support number type * test: add switch test * test: update statistic test * fix: input clear icon event * feat: steps add type、 v-model、subTitle * feat: delete typography component * feat: delete Typography style * perf: update select * feat: add download transformFile previewFile actio * docs: update upload * feat: update tree-select * docs: update tree-select * feat: tree add blockNode selectable * docs: add tree demo * test: update snap * docs: updatedoc * feat: update tag * docs: update ad doc * feat: update tooltip * feat: update timeline * feat: time-picker add clearIcon * docs: update tabs * feat: transfer support custom children * test: update transfer test * feat: update table * test: update table test * test: update test * feat: calendar update locale * test: update test snap * feat: add mentions (#1790) * feat: mentions style * feat: theme default * feat: add mentions component * feat: mentions API * feat: add unit test for mentions * feat: update mentions demo * perf: model and inheritAttrs for mentions * perf: use getComponentFromProp instead of this.$props * perf: mentions rm defaultProps * feat: rm rows in mentionsProps * fix: mentions keyDown didn't work * docs: update mentions api * perf: mentions code * feat: update mentions * bump 1.5.0-alpha.1 * feat: pageheader add ghost prop * docs: update descriptions demo * chore: page-header add ghost type * fix: color error * feat: update to 3.26.12 * fix: some prop default value * fix(typo): form, carousel, upload. duplicate identifier (#1848) * Add Mentions Type (#1845) * feat: add mentions type * feat: add mentions in ant-design-vue.d.ts * docs: update doc * docs: add changelog * fix: mentions getPopupCotainer value (#1850) * docs: update doc * docs: uptate demo * docs: update demo * docs: delete demo * docs: delete doc * test: update snapshots * style: format code * chore: update travis * docs: update demo Co-authored-by: Sendya <18x@loacg.com> Co-authored-by: zkwolf <chenhao5866@gmail.com> Co-authored-by: drafish <xwlyy1991@163.com> Co-authored-by: Amour1688 <31695475+Amour1688@users.noreply.github.com>
2020-03-07 11:45:13 +00:00
const { disabled, disableCheckbox, checkable } = getOptionProps(node) || {};
return !!(disabled || disableCheckbox) || checkable === false;
2018-03-23 13:30:20 +00:00
}
2019-01-12 03:33:27 +00:00
export function traverseTreeNodes(treeNodes, callback) {
function processNode(node, index, parent) {
2020-07-16 14:44:00 +00:00
const children = node ? getSlot(node) : treeNodes;
2019-01-12 03:33:27 +00:00
const pos = node ? getPosition(parent.pos, index) : 0;
2018-03-23 13:30:20 +00:00
// Filter children
2019-01-12 03:33:27 +00:00
const childList = getNodeChildren(children);
2018-03-23 13:30:20 +00:00
// Process node if is not root
if (node) {
2019-01-12 03:33:27 +00:00
let key = node.key;
if (!key && (key === undefined || key === null)) {
2019-01-12 03:33:27 +00:00
key = pos;
}
2018-03-23 13:30:20 +00:00
const data = {
node,
index,
pos,
key,
2018-03-23 13:30:20 +00:00
parentPos: parent.node ? parent.pos : null,
2019-01-12 03:33:27 +00:00
};
callback(data);
2018-03-23 13:30:20 +00:00
}
// Process children node
2018-03-24 09:12:22 +00:00
childList.forEach((subNode, subIndex) => {
2019-01-12 03:33:27 +00:00
processNode(subNode, subIndex, { node, pos });
});
2018-03-23 13:30:20 +00:00
}
2019-01-12 03:33:27 +00:00
processNode(null);
2018-03-23 13:30:20 +00:00
}
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 13:28:54 +00:00
/**
* Use `rc-util` `toArray` to get the children list which keeps the key.
* And return single node if children is only one(This can avoid `key` missing check).
*/
2019-01-12 03:33:27 +00:00
export function mapChildren(children = [], func) {
const list = children.map(func);
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 13:28:54 +00:00
if (list.length === 1) {
2019-01-12 03:33:27 +00:00
return list[0];
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 13:28:54 +00:00
}
2019-01-12 03:33:27 +00:00
return list;
update to antd3.8.3 (#159) * refactor: align * feat: update align to 2.4.3 * feat: update trigger 2.5.4 * feat: update tooltip 3.7.2 * fix: align * feat: update vc-calendar to 9.6.2 * feat: update vc-checkbox to 2.1.5 * feat: update vc-dialog to 7.1.8 * feat: update vc-from to 2.2.1 * feat: update vc-notification to 3.1.1 * test: update snapshots * feat: update vc-tree to 1.12.6 * feat: update vc-table to 6.2.8 * feat: update vc-upload to 2.5.1 * feat: update vc-input-number to 4.0.12 * feat: update vc-tabs to 9.2.6 * refactor: vc-menu * refactor: update vc-menu to 7.0.5 * style: remove unused * feat: update pagination to 1.16.5 * feat: add vc-progress 2.2.5 tag * feat: add vc-rate 2.4.0 tag * feat: update vc-slider to 8.6.1 * fix: tooltip error * style: delete conosle * feat: update vc-steps to 3.1.1 * add vc-switch tag 1.6.0 * feat: update upload to 2.5.1 * fix: update vc-menu * fix: update store * fix: add ref dir * fix: trigger mock shouldComponentUpdate * fix: update vc-select * revert: trigger lazyrenderbox * fix: update vc-select * fix: update vc-select * fix: update vc-select * fix: update vc-menu * fix: update vc-slick ref * update style to 3.8.2 * test: update snapshots * update vc-select * update util & affix * feat: add drawer * fix: support title add slot mode * test: update affix test * update alert * update anchor * update snapshots * fix: doc and vc-drawer * update select & auto-complete * update back-top & grid * feractor: avatar * test: add drawer test * update badge * update button * update card * update divider * feat: update vc-tabs to 9.3.6 and tabs * add afterEnter callback * update form * fix: update drawer * test: update snapshots * update modal & notification * test: update snapshots * update message * update locale-provider * update dropdown * update layout popconfirm popover * update time-picker * update menu * update date-picker * docs: update input docs * update input * update snapshots * update table * update test snapshots * feat: update progress * update checkbox * feat: update spin * update radio * docs: slider steps timeline * update list * update transfer * update collapse * update cascader * update upload
2018-09-05 13:28:54 +00:00
}
2019-01-12 03:33:27 +00:00
export function getDragNodesKeys(treeNodes, node) {
const { eventKey, pos } = getOptionProps(node);
const dragNodesKeys = [];
2018-03-23 13:30:20 +00:00
2018-09-26 14:57:01 +00:00
traverseTreeNodes(treeNodes, ({ key }) => {
2019-01-12 03:33:27 +00:00
dragNodesKeys.push(key);
});
dragNodesKeys.push(eventKey || pos);
return dragNodesKeys;
2018-03-23 13:30:20 +00:00
}
2019-01-12 03:33:27 +00:00
export function calcDropPosition(event, treeNode) {
const { clientY } = event;
2020-07-16 10:31:20 +00:00
const { top, bottom, height } = treeNode.selectHandle.getBoundingClientRect();
2019-01-12 03:33:27 +00:00
const des = Math.max(height * DRAG_SIDE_RANGE, DRAG_MIN_GAP);
2018-04-11 13:25:16 +00:00
if (clientY <= top + des) {
2019-01-12 03:33:27 +00:00
return -1;
Feat 1.5.0 (#1853) * feat: add Result component * fix: update md template tag html>tpl - fix `result` typo - update jest `result` snapshots * refactor: svg file to functional component icon - update jest snapshot * feat: add result * Feat descriptions (#1251) * feat: add descriptions * fix: add descriptions types and fix docs * fix: lint change code * fix: demo warning * fix: update demo, snapshot and remove classnames * test: add descriptions test * fix: descriptions demo (#1498) * feat: add page header (#1250) * feat: add page-header component * update site: page-header * ts definition update: page-header * get page-header props with getComponentFromProp func * optimize page-header * doc: add page-header actions.md responsive.md * breadcrumb itemRender add pure function support * style: format code * feat: update style to 3.23.6 from 2.13.6 * feat: update style to 3.26.8 from 3.23.6 * chore: update util * chore: update util * feat: update affix * feat: update alert * feat: update anchor * feat: update auto-complete * feat: update avatar * feat: update back-top * feat: update badge * feat: update button * feat: update breadcrumb * feat: update ts * docs: update doc * feat: update calendat * feat: update card * feat: update carousel * feat: update carousel * feat: update checkbox * feat: update comment * feat: update config-provider * docs: update doc * feat: update collapse * feat: update locale * feat: update date-picker * feat: update divider * feat: update drawer * feat: update dropdown * feat: update rc-trigger * feat: update dropdown * feat: update empty * test: add empty test * feat: update form * feat: update form * feat: update spin * feat: update grid * docs: update grid doc * feat: update icon * feat: update slider * feat: update textarea * feat: update input-number * feat: update layout * feat: update list * feat: update menu * feat: meaage add key for update content * feat: modal add closeIcon support * feat: update notification * feat: add pagination disabled support * feat: popconfirm add disabled support * test: update popover * feat: progress support custom line-gradiend * feat: update radio * test: update radio test * docs: update rate demo * feat: skeleton add avatar support number type * test: add switch test * test: update statistic test * fix: input clear icon event * feat: steps add type、 v-model、subTitle * feat: delete typography component * feat: delete Typography style * perf: update select * feat: add download transformFile previewFile actio * docs: update upload * feat: update tree-select * docs: update tree-select * feat: tree add blockNode selectable * docs: add tree demo * test: update snap * docs: updatedoc * feat: update tag * docs: update ad doc * feat: update tooltip * feat: update timeline * feat: time-picker add clearIcon * docs: update tabs * feat: transfer support custom children * test: update transfer test * feat: update table * test: update table test * test: update test * feat: calendar update locale * test: update test snap * feat: add mentions (#1790) * feat: mentions style * feat: theme default * feat: add mentions component * feat: mentions API * feat: add unit test for mentions * feat: update mentions demo * perf: model and inheritAttrs for mentions * perf: use getComponentFromProp instead of this.$props * perf: mentions rm defaultProps * feat: rm rows in mentionsProps * fix: mentions keyDown didn't work * docs: update mentions api * perf: mentions code * feat: update mentions * bump 1.5.0-alpha.1 * feat: pageheader add ghost prop * docs: update descriptions demo * chore: page-header add ghost type * fix: color error * feat: update to 3.26.12 * fix: some prop default value * fix(typo): form, carousel, upload. duplicate identifier (#1848) * Add Mentions Type (#1845) * feat: add mentions type * feat: add mentions in ant-design-vue.d.ts * docs: update doc * docs: add changelog * fix: mentions getPopupCotainer value (#1850) * docs: update doc * docs: uptate demo * docs: update demo * docs: delete demo * docs: delete doc * test: update snapshots * style: format code * chore: update travis * docs: update demo Co-authored-by: Sendya <18x@loacg.com> Co-authored-by: zkwolf <chenhao5866@gmail.com> Co-authored-by: drafish <xwlyy1991@163.com> Co-authored-by: Amour1688 <31695475+Amour1688@users.noreply.github.com>
2020-03-07 11:45:13 +00:00
}
if (clientY >= bottom - des) {
2019-01-12 03:33:27 +00:00
return 1;
2018-03-23 13:30:20 +00:00
}
2019-01-12 03:33:27 +00:00
return 0;
2018-03-23 13:30:20 +00:00
}
/**
2018-09-26 14:57:01 +00:00
* Return selectedKeys according with multiple prop
* @param selectedKeys
2018-03-23 13:30:20 +00:00
* @param props
* @returns [string]
*/
2019-01-12 03:33:27 +00:00
export function calcSelectedKeys(selectedKeys, props) {
if (!selectedKeys) {
return undefined;
}
2018-09-26 14:57:01 +00:00
2019-01-12 03:33:27 +00:00
const { multiple } = props;
2018-09-26 14:57:01 +00:00
if (multiple) {
2019-01-12 03:33:27 +00:00
return selectedKeys.slice();
2018-03-23 13:30:20 +00:00
}
2018-09-26 14:57:01 +00:00
if (selectedKeys.length) {
2019-01-12 03:33:27 +00:00
return [selectedKeys[0]];
2018-09-26 14:57:01 +00:00
}
2019-01-12 03:33:27 +00:00
return selectedKeys;
2018-09-26 14:57:01 +00:00
}
2018-03-23 13:30:20 +00:00
2018-09-26 14:57:01 +00:00
/**
* Since React internal will convert key to string,
* we need do this to avoid `checkStrictly` use number match
*/
2019-01-05 08:24:52 +00:00
// function keyListToString (keyList) {
// if (!keyList) return keyList
// return keyList.map(key => String(key))
// }
2018-09-26 14:57:01 +00:00
const internalProcessProps = (props = {}) => {
return {
2020-07-16 10:31:20 +00:00
...props,
2018-09-26 14:57:01 +00:00
class: props.class || props.className,
style: props.style,
key: props.key,
2019-01-12 03:33:27 +00:00
};
};
2020-07-16 10:31:20 +00:00
export function convertDataToTree(treeData, processor) {
2019-01-12 03:33:27 +00:00
if (!treeData) return [];
2018-09-26 14:57:01 +00:00
Feat 1.5.0 (#1853) * feat: add Result component * fix: update md template tag html>tpl - fix `result` typo - update jest `result` snapshots * refactor: svg file to functional component icon - update jest snapshot * feat: add result * Feat descriptions (#1251) * feat: add descriptions * fix: add descriptions types and fix docs * fix: lint change code * fix: demo warning * fix: update demo, snapshot and remove classnames * test: add descriptions test * fix: descriptions demo (#1498) * feat: add page header (#1250) * feat: add page-header component * update site: page-header * ts definition update: page-header * get page-header props with getComponentFromProp func * optimize page-header * doc: add page-header actions.md responsive.md * breadcrumb itemRender add pure function support * style: format code * feat: update style to 3.23.6 from 2.13.6 * feat: update style to 3.26.8 from 3.23.6 * chore: update util * chore: update util * feat: update affix * feat: update alert * feat: update anchor * feat: update auto-complete * feat: update avatar * feat: update back-top * feat: update badge * feat: update button * feat: update breadcrumb * feat: update ts * docs: update doc * feat: update calendat * feat: update card * feat: update carousel * feat: update carousel * feat: update checkbox * feat: update comment * feat: update config-provider * docs: update doc * feat: update collapse * feat: update locale * feat: update date-picker * feat: update divider * feat: update drawer * feat: update dropdown * feat: update rc-trigger * feat: update dropdown * feat: update empty * test: add empty test * feat: update form * feat: update form * feat: update spin * feat: update grid * docs: update grid doc * feat: update icon * feat: update slider * feat: update textarea * feat: update input-number * feat: update layout * feat: update list * feat: update menu * feat: meaage add key for update content * feat: modal add closeIcon support * feat: update notification * feat: add pagination disabled support * feat: popconfirm add disabled support * test: update popover * feat: progress support custom line-gradiend * feat: update radio * test: update radio test * docs: update rate demo * feat: skeleton add avatar support number type * test: add switch test * test: update statistic test * fix: input clear icon event * feat: steps add type、 v-model、subTitle * feat: delete typography component * feat: delete Typography style * perf: update select * feat: add download transformFile previewFile actio * docs: update upload * feat: update tree-select * docs: update tree-select * feat: tree add blockNode selectable * docs: add tree demo * test: update snap * docs: updatedoc * feat: update tag * docs: update ad doc * feat: update tooltip * feat: update timeline * feat: time-picker add clearIcon * docs: update tabs * feat: transfer support custom children * test: update transfer test * feat: update table * test: update table test * test: update test * feat: calendar update locale * test: update test snap * feat: add mentions (#1790) * feat: mentions style * feat: theme default * feat: add mentions component * feat: mentions API * feat: add unit test for mentions * feat: update mentions demo * perf: model and inheritAttrs for mentions * perf: use getComponentFromProp instead of this.$props * perf: mentions rm defaultProps * feat: rm rows in mentionsProps * fix: mentions keyDown didn't work * docs: update mentions api * perf: mentions code * feat: update mentions * bump 1.5.0-alpha.1 * feat: pageheader add ghost prop * docs: update descriptions demo * chore: page-header add ghost type * fix: color error * feat: update to 3.26.12 * fix: some prop default value * fix(typo): form, carousel, upload. duplicate identifier (#1848) * Add Mentions Type (#1845) * feat: add mentions type * feat: add mentions in ant-design-vue.d.ts * docs: update doc * docs: add changelog * fix: mentions getPopupCotainer value (#1850) * docs: update doc * docs: uptate demo * docs: update demo * docs: delete demo * docs: delete doc * test: update snapshots * style: format code * chore: update travis * docs: update demo Co-authored-by: Sendya <18x@loacg.com> Co-authored-by: zkwolf <chenhao5866@gmail.com> Co-authored-by: drafish <xwlyy1991@163.com> Co-authored-by: Amour1688 <31695475+Amour1688@users.noreply.github.com>
2020-03-07 11:45:13 +00:00
const { processProps = internalProcessProps } = processor || {};
2019-01-12 03:33:27 +00:00
const list = Array.isArray(treeData) ? treeData : [treeData];
2018-09-26 14:57:01 +00:00
return list.map(({ children, ...props }) => {
2020-07-16 10:31:20 +00:00
const childrenNodes = convertDataToTree(children, processor);
2019-01-12 03:33:27 +00:00
return <TreeNode {...processProps(props)}>{childrenNodes}</TreeNode>;
});
2018-09-26 14:57:01 +00:00
}
// TODO: ========================= NEW LOGIC =========================
/**
* Calculate treeNodes entities. `processTreeEntity` is used for `rc-tree-select`
* @param treeNodes
* @param processTreeEntity User can customize the entity
*/
2019-01-12 03:33:27 +00:00
export function convertTreeToEntities(
treeNodes,
{ initWrapper, processEntity, onProcessFinished } = {},
) {
const posEntities = new Map();
const keyEntities = new Map();
2018-09-26 14:57:01 +00:00
let wrapper = {
posEntities,
keyEntities,
2019-01-12 03:33:27 +00:00
};
2018-09-26 14:57:01 +00:00
if (initWrapper) {
2019-01-12 03:33:27 +00:00
wrapper = initWrapper(wrapper) || wrapper;
2018-09-26 14:57:01 +00:00
}
2019-01-12 03:33:27 +00:00
traverseTreeNodes(treeNodes, item => {
const { node, index, pos, key, parentPos } = item;
const entity = { node, index, key, pos };
2018-09-26 14:57:01 +00:00
2019-01-12 03:33:27 +00:00
posEntities.set(pos, entity);
keyEntities.set(key, entity);
2018-09-26 14:57:01 +00:00
// Fill children
2019-01-12 03:33:27 +00:00
entity.parent = posEntities.get(parentPos);
2018-09-26 14:57:01 +00:00
if (entity.parent) {
2019-01-12 03:33:27 +00:00
entity.parent.children = entity.parent.children || [];
entity.parent.children.push(entity);
2018-09-26 14:57:01 +00:00
}
2018-03-23 13:30:20 +00:00
2018-09-26 14:57:01 +00:00
if (processEntity) {
2019-01-12 03:33:27 +00:00
processEntity(entity, wrapper);
2018-03-23 13:30:20 +00:00
}
2019-01-12 03:33:27 +00:00
});
2018-03-23 13:30:20 +00:00
2018-09-26 14:57:01 +00:00
if (onProcessFinished) {
2019-01-12 03:33:27 +00:00
onProcessFinished(wrapper);
2018-09-26 14:57:01 +00:00
}
2018-03-23 13:30:20 +00:00
2019-01-12 03:33:27 +00:00
return wrapper;
2018-03-23 13:30:20 +00:00
}
/**
2018-09-26 14:57:01 +00:00
* Parse `checkedKeys` to { checkedKeys, halfCheckedKeys } style
2018-03-23 13:30:20 +00:00
*/
2019-01-12 03:33:27 +00:00
export function parseCheckedKeys(keys) {
2018-09-26 14:57:01 +00:00
if (!keys) {
2019-01-12 03:33:27 +00:00
return null;
2018-03-23 13:30:20 +00:00
}
2018-09-26 14:57:01 +00:00
// Convert keys to object format
2019-01-12 03:33:27 +00:00
let keyProps;
2018-09-26 14:57:01 +00:00
if (Array.isArray(keys)) {
// [Legacy] Follow the api doc
keyProps = {
checkedKeys: keys,
halfCheckedKeys: undefined,
2019-01-12 03:33:27 +00:00
};
2018-09-26 14:57:01 +00:00
} else if (typeof keys === 'object') {
keyProps = {
checkedKeys: keys.checked || undefined,
halfCheckedKeys: keys.halfChecked || undefined,
2019-01-12 03:33:27 +00:00
};
2018-09-26 14:57:01 +00:00
} else {
2019-01-12 03:33:27 +00:00
warning(false, '`checkedKeys` is not an array or an object');
return null;
2018-03-23 13:30:20 +00:00
}
// keyProps.checkedKeys = keyListToString(keyProps.checkedKeys)
// keyProps.halfCheckedKeys = keyListToString(keyProps.halfCheckedKeys)
2018-09-26 14:57:01 +00:00
2019-01-12 03:33:27 +00:00
return keyProps;
2018-03-23 13:30:20 +00:00
}
/**
2018-09-26 14:57:01 +00:00
* Conduct check state by the keyList. It will conduct up & from the provided key.
* If the conduct path reach the disabled or already checked / unchecked node will stop conduct.
* @param keyList list of keys
* @param isCheck is check the node or not
* @param keyEntities parsed by `convertTreeToEntities` function in Tree
* @param checkStatus Can pass current checked status for process (usually for uncheck operation)
* @returns {{checkedKeys: [], halfCheckedKeys: []}}
2018-03-23 13:30:20 +00:00
*/
2019-01-12 03:33:27 +00:00
export function conductCheck(keyList, isCheck, keyEntities, checkStatus = {}) {
const checkedKeys = new Map();
const halfCheckedKeys = new Map(); // Record the key has some child checked (include child half checked)
2018-09-26 14:57:01 +00:00
2019-01-12 03:33:27 +00:00
(checkStatus.checkedKeys || []).forEach(key => {
checkedKeys.set(key, true);
2018-09-26 14:57:01 +00:00
});
2018-03-23 13:30:20 +00:00
2019-01-12 03:33:27 +00:00
(checkStatus.halfCheckedKeys || []).forEach(key => {
halfCheckedKeys.set(key, true);
});
2018-03-23 13:30:20 +00:00
// Conduct up
2019-01-12 03:33:27 +00:00
function conductUp(key) {
if (checkedKeys.get(key) === isCheck) return;
2018-09-26 14:57:01 +00:00
2019-01-12 03:33:27 +00:00
const entity = keyEntities.get(key);
if (!entity) return;
2018-09-26 14:57:01 +00:00
2019-01-12 03:33:27 +00:00
const { children, parent, node } = entity;
2018-03-23 13:30:20 +00:00
2019-01-12 03:33:27 +00:00
if (isCheckDisabled(node)) return;
2018-03-23 13:30:20 +00:00
2018-09-26 14:57:01 +00:00
// Check child node checked status
2019-01-12 03:33:27 +00:00
let everyChildChecked = true;
2018-09-26 14:57:01 +00:00
let someChildChecked = false; // Child checked or half checked
2018-03-23 13:30:20 +00:00
2018-09-26 14:57:01 +00:00
(children || [])
.filter(child => !isCheckDisabled(child.node))
.forEach(({ key: childKey }) => {
2019-01-12 03:33:27 +00:00
const childChecked = checkedKeys.get(childKey);
const childHalfChecked = halfCheckedKeys.get(childKey);
2018-09-26 14:57:01 +00:00
2019-01-12 03:33:27 +00:00
if (childChecked || childHalfChecked) someChildChecked = true;
if (!childChecked) everyChildChecked = false;
});
2018-09-26 14:57:01 +00:00
// Update checked status
if (isCheck) {
2019-01-12 03:33:27 +00:00
checkedKeys.set(key, everyChildChecked);
2018-03-23 13:30:20 +00:00
} else {
2019-01-12 03:33:27 +00:00
checkedKeys.set(key, false);
2018-03-23 13:30:20 +00:00
}
2019-01-12 03:33:27 +00:00
halfCheckedKeys.set(key, someChildChecked);
2018-03-23 13:30:20 +00:00
2018-09-26 14:57:01 +00:00
if (parent) {
2019-01-12 03:33:27 +00:00
conductUp(parent.key);
2018-03-23 13:30:20 +00:00
}
}
// Conduct down
2019-01-12 03:33:27 +00:00
function conductDown(key) {
if (checkedKeys.get(key) === isCheck) return;
2018-09-26 14:57:01 +00:00
2019-01-12 03:33:27 +00:00
const entity = keyEntities.get(key);
if (!entity) return;
2018-09-26 14:57:01 +00:00
2019-01-12 03:33:27 +00:00
const { children, node } = entity;
2018-03-23 13:30:20 +00:00
2019-01-12 03:33:27 +00:00
if (isCheckDisabled(node)) return;
2018-03-23 13:30:20 +00:00
checkedKeys.set(key, isCheck);
2018-03-23 13:30:20 +00:00
2019-01-12 03:33:27 +00:00
(children || []).forEach(child => {
conductDown(child.key);
});
2018-03-23 13:30:20 +00:00
}
2019-01-12 03:33:27 +00:00
function conduct(key) {
const entity = keyEntities.get(key);
2018-09-26 14:57:01 +00:00
if (!entity) {
2019-01-12 03:33:27 +00:00
warning(false, `'${key}' does not exist in the tree.`);
return;
2018-03-23 13:30:20 +00:00
}
2019-01-12 03:33:27 +00:00
const { children, parent, node } = entity;
checkedKeys.set(key, isCheck);
2018-03-23 13:30:20 +00:00
2018-09-26 14:57:01 +00:00
if (isCheckDisabled(node)) return;
2018-04-11 13:25:16 +00:00
2018-03-23 13:30:20 +00:00
// Conduct down
2018-09-26 14:57:01 +00:00
(children || [])
.filter(child => !isCheckDisabled(child.node))
2019-01-12 03:33:27 +00:00
.forEach(child => {
conductDown(child.key);
});
2018-03-23 13:30:20 +00:00
// Conduct up
2018-09-26 14:57:01 +00:00
if (parent) {
2019-01-12 03:33:27 +00:00
conductUp(parent.key);
2018-03-23 13:30:20 +00:00
}
}
2019-01-12 03:33:27 +00:00
(keyList || []).forEach(key => {
conduct(key);
});
2018-03-23 13:30:20 +00:00
2019-01-12 03:33:27 +00:00
const checkedKeyList = [];
const halfCheckedKeyList = [];
2018-09-26 14:57:01 +00:00
// Fill checked list
for (const [key, value] of checkedKeys) {
if (value) {
2019-01-12 03:33:27 +00:00
checkedKeyList.push(key);
2018-09-26 14:57:01 +00:00
}
}
2018-09-26 14:57:01 +00:00
// Fill half checked list
for (const [key, value] of halfCheckedKeys) {
if (!checkedKeys.get(key) && value) {
2019-01-12 03:33:27 +00:00
halfCheckedKeyList.push(key);
2018-09-26 14:57:01 +00:00
}
}
2018-09-26 14:57:01 +00:00
2018-03-23 13:30:20 +00:00
return {
2018-09-26 14:57:01 +00:00
checkedKeys: checkedKeyList,
halfCheckedKeys: halfCheckedKeyList,
2019-01-12 03:33:27 +00:00
};
2018-03-23 13:30:20 +00:00
}
/**
2018-09-26 14:57:01 +00:00
* If user use `autoExpandParent` we should get the list of parent node
* @param keyList
* @param keyEntities
2018-03-23 13:30:20 +00:00
*/
2019-01-12 03:33:27 +00:00
export function conductExpandParent(keyList, keyEntities) {
const expandedKeys = new Map();
2018-03-23 13:30:20 +00:00
2019-01-12 03:33:27 +00:00
function conductUp(key) {
if (expandedKeys.get(key)) return;
2018-03-23 13:30:20 +00:00
2019-01-12 03:33:27 +00:00
const entity = keyEntities.get(key);
if (!entity) return;
2018-09-26 14:57:01 +00:00
2019-01-12 03:33:27 +00:00
expandedKeys.set(key, true);
2018-09-26 14:57:01 +00:00
2019-01-12 03:33:27 +00:00
const { parent, node } = entity;
Feat 1.5.0 (#1853) * feat: add Result component * fix: update md template tag html>tpl - fix `result` typo - update jest `result` snapshots * refactor: svg file to functional component icon - update jest snapshot * feat: add result * Feat descriptions (#1251) * feat: add descriptions * fix: add descriptions types and fix docs * fix: lint change code * fix: demo warning * fix: update demo, snapshot and remove classnames * test: add descriptions test * fix: descriptions demo (#1498) * feat: add page header (#1250) * feat: add page-header component * update site: page-header * ts definition update: page-header * get page-header props with getComponentFromProp func * optimize page-header * doc: add page-header actions.md responsive.md * breadcrumb itemRender add pure function support * style: format code * feat: update style to 3.23.6 from 2.13.6 * feat: update style to 3.26.8 from 3.23.6 * chore: update util * chore: update util * feat: update affix * feat: update alert * feat: update anchor * feat: update auto-complete * feat: update avatar * feat: update back-top * feat: update badge * feat: update button * feat: update breadcrumb * feat: update ts * docs: update doc * feat: update calendat * feat: update card * feat: update carousel * feat: update carousel * feat: update checkbox * feat: update comment * feat: update config-provider * docs: update doc * feat: update collapse * feat: update locale * feat: update date-picker * feat: update divider * feat: update drawer * feat: update dropdown * feat: update rc-trigger * feat: update dropdown * feat: update empty * test: add empty test * feat: update form * feat: update form * feat: update spin * feat: update grid * docs: update grid doc * feat: update icon * feat: update slider * feat: update textarea * feat: update input-number * feat: update layout * feat: update list * feat: update menu * feat: meaage add key for update content * feat: modal add closeIcon support * feat: update notification * feat: add pagination disabled support * feat: popconfirm add disabled support * test: update popover * feat: progress support custom line-gradiend * feat: update radio * test: update radio test * docs: update rate demo * feat: skeleton add avatar support number type * test: add switch test * test: update statistic test * fix: input clear icon event * feat: steps add type、 v-model、subTitle * feat: delete typography component * feat: delete Typography style * perf: update select * feat: add download transformFile previewFile actio * docs: update upload * feat: update tree-select * docs: update tree-select * feat: tree add blockNode selectable * docs: add tree demo * test: update snap * docs: updatedoc * feat: update tag * docs: update ad doc * feat: update tooltip * feat: update timeline * feat: time-picker add clearIcon * docs: update tabs * feat: transfer support custom children * test: update transfer test * feat: update table * test: update table test * test: update test * feat: calendar update locale * test: update test snap * feat: add mentions (#1790) * feat: mentions style * feat: theme default * feat: add mentions component * feat: mentions API * feat: add unit test for mentions * feat: update mentions demo * perf: model and inheritAttrs for mentions * perf: use getComponentFromProp instead of this.$props * perf: mentions rm defaultProps * feat: rm rows in mentionsProps * fix: mentions keyDown didn't work * docs: update mentions api * perf: mentions code * feat: update mentions * bump 1.5.0-alpha.1 * feat: pageheader add ghost prop * docs: update descriptions demo * chore: page-header add ghost type * fix: color error * feat: update to 3.26.12 * fix: some prop default value * fix(typo): form, carousel, upload. duplicate identifier (#1848) * Add Mentions Type (#1845) * feat: add mentions type * feat: add mentions in ant-design-vue.d.ts * docs: update doc * docs: add changelog * fix: mentions getPopupCotainer value (#1850) * docs: update doc * docs: uptate demo * docs: update demo * docs: delete demo * docs: delete doc * test: update snapshots * style: format code * chore: update travis * docs: update demo Co-authored-by: Sendya <18x@loacg.com> Co-authored-by: zkwolf <chenhao5866@gmail.com> Co-authored-by: drafish <xwlyy1991@163.com> Co-authored-by: Amour1688 <31695475+Amour1688@users.noreply.github.com>
2020-03-07 11:45:13 +00:00
const props = getOptionProps(node);
if (props && props.disabled) return;
2018-09-26 14:57:01 +00:00
if (parent) {
2019-01-12 03:33:27 +00:00
conductUp(parent.key);
2018-03-23 13:30:20 +00:00
}
}
2019-01-12 03:33:27 +00:00
(keyList || []).forEach(key => {
conductUp(key);
});
2018-07-11 09:51:20 +00:00
2019-01-12 03:33:27 +00:00
return [...expandedKeys.keys()];
2018-09-26 14:57:01 +00:00
}
2018-03-23 13:30:20 +00:00
2018-09-26 14:57:01 +00:00
/**
* Returns only the data- and aria- key/value pairs
* @param {object} props
*/
2019-01-12 03:33:27 +00:00
export function getDataAndAria(props) {
2018-09-26 14:57:01 +00:00
return Object.keys(props).reduce((prev, key) => {
2019-01-12 03:33:27 +00:00
if (key.substr(0, 5) === 'data-' || key.substr(0, 5) === 'aria-') {
prev[key] = props[key];
2018-09-26 14:57:01 +00:00
}
2019-01-12 03:33:27 +00:00
return prev;
}, {});
2018-03-23 13:30:20 +00:00
}