Skip to content

fix: 2.x animation duplicate key #106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@wsfe/ctree",
"version": "2.4.0",
"version": "2.4.1",
"main": "./dist/ctree.umd.min.js",
"types": "./types",
"description": "A vue tree component using virtual list.",
Expand Down
11 changes: 8 additions & 3 deletions src/components/Tree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ export default (Vue as VueConstructor<Vue & {
ready: false,
currentExpandState: false,

expandRenderStart: 0,
topNodes: [] as TreeNode[],
middleNodes: [] as TreeNode[],
bottomNodes: [] as TreeNode[],
Expand Down Expand Up @@ -945,6 +946,7 @@ export default (Vue as VueConstructor<Vue & {
this.expandAnimation.index = -1
this.expandAnimation.level = -1

this.expandAnimation.expandRenderStart = 0
this.expandAnimation.topNodes = []
this.expandAnimation.middleNodes = []
this.expandAnimation.bottomNodes = []
Expand All @@ -954,7 +956,8 @@ export default (Vue as VueConstructor<Vue & {
const nodeToExpandLevel = this.expandAnimation.level
const middleNodes: TreeNode[] = []
const renderNodesLength = this.renderNodes.length
for (let i = this.expandAnimation.index + 1; i < renderNodesLength; i++) {
const expandRenderStartDiff = this.renderStart - this.expandAnimation.expandRenderStart
for (let i = this.expandAnimation.index - expandRenderStartDiff + 1; i < renderNodesLength; i++) {
if (this.renderNodes[i]._level > nodeToExpandLevel) {
middleNodes.push(this.renderNodes[i])
} else break
Expand All @@ -974,6 +977,7 @@ export default (Vue as VueConstructor<Vue & {
this.expandAnimation.start = true
this.expandAnimation.currentExpandState = nodeToExpand.expand
this.expandAnimation.nextState = !nodeToExpand.expand
this.expandAnimation.expandRenderStart = this.renderStart

if (this.expandAnimation.nextState) {
this.expandAnimation.bottomNodes = this.renderNodes.slice(this.expandAnimation.index + 1)
Expand All @@ -994,11 +998,12 @@ export default (Vue as VueConstructor<Vue & {
if (this.expandAnimation.index === -1) return

this.$nextTick(() => {
this.expandAnimation.topNodes = this.renderNodes.slice(0, this.expandAnimation.index + 1)
const expandRenderStartDiff = this.renderStart - this.expandAnimation.expandRenderStart
this.expandAnimation.topNodes = this.renderNodes.slice(0, this.expandAnimation.index - expandRenderStartDiff + 1)
if (this.expandAnimation.nextState) {
this.updateMiddleNodes()
} else {
this.expandAnimation.bottomNodes = this.renderNodes.slice(this.expandAnimation.index + 1)
this.expandAnimation.bottomNodes = this.renderNodes.slice(this.expandAnimation.index - expandRenderStartDiff + 1)
}
this.expandAnimation.ready = true
this.$nextTick(() => {
Expand Down
7 changes: 4 additions & 3 deletions types/src/components/Tree.vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ declare const _default: import("vue/types/vue").ExtendedVue<Vue & {
nextState: boolean;
ready: boolean;
currentExpandState: boolean;
expandRenderStart: number;
topNodes: TreeNode[];
middleNodes: TreeNode[];
bottomNodes: TreeNode[];
Expand All @@ -70,8 +71,8 @@ declare const _default: import("vue/types/vue").ExtendedVue<Vue & {
setExpand(key: TreeNodeKeyType, value: boolean, expandParent?: boolean): void;
setExpandKeys(keys: TreeNodeKeyType[], value: boolean): void;
setExpandAll(value: boolean): void;
getCheckedNodes(ignoreMode?: "none" | "parents" | "children" | undefined): TreeNode[];
getCheckedKeys(ignoreMode?: "none" | "parents" | "children" | undefined): TreeNodeKeyType[];
getCheckedNodes(ignoreMode?: "children" | "none" | "parents" | undefined): TreeNode[];
getCheckedKeys(ignoreMode?: "children" | "none" | "parents" | undefined): TreeNodeKeyType[];
getIndeterminateNodes(): TreeNode[];
getSelectedNode(): TreeNode | null;
getSelectedKey(): string | number | null;
Expand Down Expand Up @@ -189,7 +190,7 @@ declare const _default: import("vue/types/vue").ExtendedVue<Vue & {
draggable: boolean;
droppable: boolean;
beforeDropMethod: (dragKey: TreeNodeKeyType, dropKey: TreeNodeKeyType, hoverPart: dragHoverPartEnum) => boolean;
ignoreMode: "none" | "parents" | "children";
ignoreMode: "children" | "none" | "parents";
autoLoad: boolean;
load: (node: TreeNode | null, resolve: Function, reject: Function) => any;
render: (h: CreateElement, node: TreeNode) => VNode;
Expand Down
15 changes: 8 additions & 7 deletions types/src/components/TreeDrop.vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ declare const _default: import("vue/types/vue").ExtendedVue<Vue & {
setExpand: (key: TreeNodeKeyType, value: boolean, expandParent?: boolean) => void;
setExpandKeys: (keys: TreeNodeKeyType[], value: boolean) => void;
setExpandAll: (value: boolean) => void;
getCheckedNodes: (ignoreMode?: "none" | "parents" | "children" | undefined) => TreeNode[];
getCheckedKeys: (ignoreMode?: "none" | "parents" | "children" | undefined) => TreeNodeKeyType[];
getCheckedNodes: (ignoreMode?: "children" | "none" | "parents" | undefined) => TreeNode[];
getCheckedKeys: (ignoreMode?: "children" | "none" | "parents" | undefined) => TreeNodeKeyType[];
getIndeterminateNodes: () => TreeNode[];
getSelectedNode: () => TreeNode | null;
getSelectedKey: () => string | number | null;
Expand Down Expand Up @@ -106,6 +106,7 @@ declare const _default: import("vue/types/vue").ExtendedVue<Vue & {
nextState: boolean;
ready: boolean;
currentExpandState: boolean;
expandRenderStart: number;
topNodes: TreeNode[];
middleNodes: TreeNode[];
bottomNodes: TreeNode[];
Expand All @@ -123,8 +124,8 @@ declare const _default: import("vue/types/vue").ExtendedVue<Vue & {
setExpand(key: TreeNodeKeyType, value: boolean, expandParent?: boolean): void;
setExpandKeys(keys: TreeNodeKeyType[], value: boolean): void;
setExpandAll(value: boolean): void;
getCheckedNodes(ignoreMode?: "none" | "parents" | "children" | undefined): TreeNode[];
getCheckedKeys(ignoreMode?: "none" | "parents" | "children" | undefined): TreeNodeKeyType[];
getCheckedNodes(ignoreMode?: "children" | "none" | "parents" | undefined): TreeNode[];
getCheckedKeys(ignoreMode?: "children" | "none" | "parents" | undefined): TreeNodeKeyType[];
getIndeterminateNodes(): TreeNode[];
getSelectedNode(): TreeNode | null;
getSelectedKey(): string | number | null;
Expand Down Expand Up @@ -205,7 +206,7 @@ declare const _default: import("vue/types/vue").ExtendedVue<Vue & {
draggable: boolean;
droppable: boolean;
beforeDropMethod: (dragKey: TreeNodeKeyType, dropKey: TreeNodeKeyType, hoverPart: import("../const").dragHoverPartEnum) => boolean;
ignoreMode: "none" | "parents" | "children";
ignoreMode: "children" | "none" | "parents";
autoLoad: boolean;
load: (node: TreeNode | null, resolve: Function, reject: Function) => any;
render: (h: import("vue").CreateElement, node: TreeNode) => import("vue").VNode;
Expand Down Expand Up @@ -274,8 +275,8 @@ declare const _default: import("vue/types/vue").ExtendedVue<Vue & {
setExpand: (key: TreeNodeKeyType, value: boolean, expandParent?: boolean) => void;
setExpandKeys: (keys: TreeNodeKeyType[], value: boolean) => void;
setExpandAll: (value: boolean) => void;
getCheckedNodes: (ignoreMode?: "none" | "parents" | "children" | undefined) => TreeNode[];
getCheckedKeys: (ignoreMode?: "none" | "parents" | "children" | undefined) => TreeNodeKeyType[];
getCheckedNodes: (ignoreMode?: "children" | "none" | "parents" | undefined) => TreeNode[];
getCheckedKeys: (ignoreMode?: "children" | "none" | "parents" | undefined) => TreeNodeKeyType[];
getIndeterminateNodes: () => TreeNode[];
getSelectedNode: () => TreeNode | null;
getSelectedKey: () => string | number | null;
Expand Down
11 changes: 6 additions & 5 deletions types/src/components/TreeSearch.vue.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ declare const _default: import("vue/types/vue").ExtendedVue<Vue & {
nextState: boolean;
ready: boolean;
currentExpandState: boolean;
expandRenderStart: number;
topNodes: TreeNode[];
middleNodes: TreeNode[];
bottomNodes: TreeNode[];
Expand All @@ -42,8 +43,8 @@ declare const _default: import("vue/types/vue").ExtendedVue<Vue & {
setExpand(key: TreeNodeKeyType, value: boolean, expandParent?: boolean): void;
setExpandKeys(keys: TreeNodeKeyType[], value: boolean): void;
setExpandAll(value: boolean): void;
getCheckedNodes(ignoreMode?: "none" | "parents" | "children" | undefined): TreeNode[];
getCheckedKeys(ignoreMode?: "none" | "parents" | "children" | undefined): TreeNodeKeyType[];
getCheckedNodes(ignoreMode?: "children" | "none" | "parents" | undefined): TreeNode[];
getCheckedKeys(ignoreMode?: "children" | "none" | "parents" | undefined): TreeNodeKeyType[];
getIndeterminateNodes(): TreeNode[];
getSelectedNode(): TreeNode | null;
getSelectedKey(): string | number | null;
Expand Down Expand Up @@ -124,7 +125,7 @@ declare const _default: import("vue/types/vue").ExtendedVue<Vue & {
draggable: boolean;
droppable: boolean;
beforeDropMethod: (dragKey: TreeNodeKeyType, dropKey: TreeNodeKeyType, hoverPart: import("../const").dragHoverPartEnum) => boolean;
ignoreMode: "none" | "parents" | "children";
ignoreMode: "children" | "none" | "parents";
autoLoad: boolean;
load: (node: TreeNode | null, resolve: Function, reject: Function) => any;
render: (h: import("vue").CreateElement, node: TreeNode) => import("vue").VNode;
Expand Down Expand Up @@ -199,8 +200,8 @@ declare const _default: import("vue/types/vue").ExtendedVue<Vue & {
setExpand: (key: TreeNodeKeyType, value: boolean, expandParent?: boolean) => void;
setExpandKeys: (keys: TreeNodeKeyType[], value: boolean) => void;
setExpandAll: (value: boolean) => void;
getCheckedNodes: (ignoreMode?: "none" | "parents" | "children" | undefined) => TreeNode[];
getCheckedKeys: (ignoreMode?: "none" | "parents" | "children" | undefined) => TreeNodeKeyType[];
getCheckedNodes: (ignoreMode?: "children" | "none" | "parents" | undefined) => TreeNode[];
getCheckedKeys: (ignoreMode?: "children" | "none" | "parents" | undefined) => TreeNodeKeyType[];
getIndeterminateNodes: () => TreeNode[];
getSelectedNode: () => TreeNode | null;
getSelectedKey: () => string | number | null;
Expand Down
4 changes: 2 additions & 2 deletions types/src/store/tree-store.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ export default class TreeStore {
* 获取多选选中节点
* @param ignoreMode 忽略模式,可选择忽略父节点或子节点,默认值是 CTree 的 ignoreMode Prop
*/
getCheckedNodes(ignoreMode?: "none" | "parents" | "children" | undefined): TreeNode[];
getCheckedNodes(ignoreMode?: "children" | "none" | "parents" | undefined): TreeNode[];
/**
* 获取多选选中的节点 key ,包括未加载的 key
* @param ignoreMode 忽略模式,同 `getCheckedNodes`
*/
getCheckedKeys(ignoreMode?: "none" | "parents" | "children" | undefined): TreeNodeKeyType[];
getCheckedKeys(ignoreMode?: "children" | "none" | "parents" | undefined): TreeNodeKeyType[];
/**
* 获取多选半选状态节点
*/
Expand Down