-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
33 changed files
with
383 additions
and
385 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,15 @@ | ||
import type { App } from 'vue'; | ||
import Tree from './src/tree'; | ||
import NewTree from './src/new-tree'; | ||
|
||
export * from './src/tree-types'; | ||
|
||
export { Tree, NewTree }; | ||
export { Tree }; | ||
|
||
export default { | ||
title: 'Tree 树', | ||
category: '数据展示', | ||
status: '20%', | ||
install(app: App): void { | ||
app.component(Tree.name, Tree); | ||
app.component(NewTree.name, NewTree); | ||
} | ||
}; |
2 changes: 1 addition & 1 deletion
2
packages/devui-vue/devui/tree/src/components/tree-node-content.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/devui-vue/devui/tree/src/components/tree-node-toggle.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
63 changes: 34 additions & 29 deletions
63
packages/devui-vue/devui/tree/src/composables/use-toggle.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,41 @@ | ||
import { ref, Ref, watch } from 'vue'; | ||
import { TreeData, TreeItem } from '../tree-types'; | ||
import { Ref } from 'vue'; | ||
import { IInnerTreeNode, IUseCore } from '../tree-types'; | ||
|
||
interface IUseToggle { | ||
openedData: Ref<TreeData>; | ||
toggle: (target: Event, item: TreeItem) => void; | ||
export interface IUseToggle { | ||
expandNode: (node: IInnerTreeNode) => void; | ||
collapseNode: (node: IInnerTreeNode) => void; | ||
toggleNode: (node: IInnerTreeNode) => void; | ||
} | ||
|
||
export default function useToggle(data: Ref<TreeData>): IUseToggle { | ||
const openedTree = (tree: TreeData): TreeData => { | ||
return tree.reduce((acc: TreeData, item: TreeItem) => ( | ||
item.open | ||
? acc.concat(item, item.children ? openedTree(item.children) : []) | ||
: acc.concat(item) | ||
), []); | ||
}; | ||
export default function () { | ||
return function useToggle(data: Ref<IInnerTreeNode[]>, core: IUseCore): IUseToggle { | ||
const { getNode, setNodeValue } = core; | ||
|
||
const openedData = ref(openedTree(data.value)); | ||
|
||
watch( | ||
() => data.value, | ||
(d) => openedData.value = openedTree(d), | ||
{ deep: true } | ||
); | ||
const toggle = (target: Event, item: TreeItem) => { | ||
target.stopPropagation(); | ||
if (!item.children) {return;} | ||
item.open = !item.open; | ||
openedData.value = openedTree(data.value); | ||
}; | ||
const expandNode = (node: IInnerTreeNode): void => { | ||
if (node.disableToggle) { return; } | ||
|
||
setNodeValue(node, 'expanded', true); | ||
}; | ||
|
||
const collapseNode = (node: IInnerTreeNode): void => { | ||
if (node.disableToggle) { return; } | ||
setNodeValue(node, 'expanded', false); | ||
}; | ||
|
||
const toggleNode = (node: IInnerTreeNode): void => { | ||
if (node.disableToggle) { return; } | ||
|
||
if (getNode(node).expanded) { | ||
setNodeValue(node, 'expanded', false); | ||
} else { | ||
setNodeValue(node, 'expanded', true); | ||
} | ||
}; | ||
|
||
return { | ||
openedData, | ||
toggle, | ||
return { | ||
expandNode, | ||
collapseNode, | ||
toggleNode, | ||
}; | ||
}; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...vui/tree/src/composables/use-draggable.ts → ...c/deprecated-composables/use-draggable.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...ue/devui/tree/src/composables/use-lazy.ts → ...ee/src/deprecated-composables/use-lazy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ui/tree/src/composables/use-merge-node.ts → .../deprecated-composables/use-merge-node.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...evui/tree/src/composables/use-operate.tsx → ...rc/deprecated-composables/use-operate.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
packages/devui-vue/devui/tree/src/deprecated-composables/use-toggle.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ref, Ref, watch } from 'vue'; | ||
import { TreeData, TreeItem } from '../deprecated-tree-types'; | ||
|
||
interface IUseToggle { | ||
openedData: Ref<TreeData>; | ||
toggle: (target: Event, item: TreeItem) => void; | ||
} | ||
|
||
export default function useToggle(data: Ref<TreeData>): IUseToggle { | ||
const openedTree = (tree: TreeData): TreeData => { | ||
return tree.reduce((acc: TreeData, item: TreeItem) => ( | ||
item.open | ||
? acc.concat(item, item.children ? openedTree(item.children) : []) | ||
: acc.concat(item) | ||
), []); | ||
}; | ||
|
||
const openedData = ref(openedTree(data.value)); | ||
|
||
watch( | ||
() => data.value, | ||
(d) => openedData.value = openedTree(d), | ||
{ deep: true } | ||
); | ||
const toggle = (target: Event, item: TreeItem) => { | ||
target.stopPropagation(); | ||
if (!item.children) {return;} | ||
item.open = !item.open; | ||
openedData.value = openedTree(data.value); | ||
}; | ||
|
||
return { | ||
openedData, | ||
toggle, | ||
}; | ||
} |
65 changes: 65 additions & 0 deletions
65
packages/devui-vue/devui/tree/src/deprecated-tree-types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import type { PropType, ExtractPropTypes, SetupContext } from 'vue'; | ||
|
||
export interface TreeItem { | ||
id?: string; | ||
label: string; | ||
isParent?: boolean; | ||
level?: number; | ||
open?: boolean; | ||
addable?: boolean; | ||
editable?: boolean; | ||
deletable?: boolean; | ||
children?: Array<TreeItem>; | ||
[key: string]: unknown; | ||
} | ||
export interface IDropType { | ||
dropPrev?: boolean; | ||
dropNext?: boolean; | ||
dropInner?: boolean; | ||
} | ||
export interface SelectType { | ||
[key: string]: 'none' | 'half' | 'select'; | ||
} | ||
|
||
export interface ReverseTree { | ||
id?: string; | ||
children?: string[]; | ||
parent?: ReverseTree; | ||
} | ||
|
||
export type TreeData = Array<TreeItem>; | ||
|
||
export type CheckableRelationType = 'downward' | 'upward' | 'both' | 'none'; | ||
|
||
export const treeProps = { | ||
data: { | ||
type: Array as PropType<TreeData>, | ||
required: true, | ||
default: () => [], | ||
}, | ||
checkable: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
draggable: { | ||
type: Boolean, | ||
default: false | ||
}, | ||
checkableRelation: { | ||
type: String as () => CheckableRelationType, | ||
default: 'none', | ||
}, | ||
dropType: { | ||
type: Object as PropType<IDropType>, | ||
default: () => ({}), | ||
}, | ||
} as const; | ||
|
||
export type TreeProps = ExtractPropTypes<typeof treeProps>; | ||
|
||
export type Nullable<T> = null | T; | ||
|
||
export interface TreeRootType { | ||
ctx: SetupContext; | ||
props: TreeProps; | ||
} |
Oops, something went wrong.