-
Notifications
You must be signed in to change notification settings - Fork 32
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
1 parent
4f5902f
commit 0b9e7bc
Showing
8 changed files
with
140 additions
and
120 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { TreeData, EventData } from "../dist/common"; | ||
|
||
const rawData: Data[] = [ | ||
{ | ||
text: "Root node 1", | ||
value: { id: 1 }, | ||
state: { | ||
opened: true, | ||
}, | ||
children: [ | ||
{ | ||
text: "Child node 11", | ||
value: { id: 11 }, | ||
}, | ||
{ | ||
text: "Disabled Child node 12", | ||
value: { id: 12 }, | ||
state: { | ||
opened: true, | ||
disabled: true, | ||
}, | ||
children: [ | ||
{ | ||
text: "Child node 121", | ||
value: { id: 121 }, | ||
}, | ||
{ | ||
text: "Disabled Child node 122", | ||
value: { id: 122 }, | ||
state: { | ||
disabled: true, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}, | ||
{ | ||
text: "Loading Root node 2", | ||
value: { id: 2 }, | ||
children: [ | ||
{ | ||
text: "Child node 21", | ||
value: { id: 21 }, | ||
}, | ||
], | ||
}, | ||
]; | ||
|
||
function standardize(treeData: Data) { | ||
if (treeData.state === undefined) { | ||
treeData.state = {}; | ||
} | ||
if (treeData.state.opened === undefined) { | ||
treeData.state.opened = false; | ||
} | ||
if (treeData.state.selected === undefined) { | ||
treeData.state.selected = false; | ||
} | ||
if (treeData.state.disabled === undefined) { | ||
treeData.state.disabled = false; | ||
} | ||
if (treeData.state.loading === undefined) { | ||
treeData.state.loading = false; | ||
} | ||
if (treeData.children) { | ||
for (const child of treeData.children) { | ||
standardize(child); | ||
} | ||
} | ||
} | ||
|
||
for (const child of rawData) { | ||
standardize(child); | ||
} | ||
|
||
console.log(rawData); | ||
|
||
export const data: TreeData[] = rawData as any; | ||
|
||
export function clearSelectionOfTree(tree: TreeData) { | ||
if (tree.state.selected) { | ||
tree.state.selected = false; | ||
} | ||
if (tree.children) { | ||
for (const child of tree.children) { | ||
clearSelectionOfTree(child); | ||
} | ||
} | ||
} | ||
|
||
export function toggle(eventData: EventData) { | ||
if (eventData.data.value.id === 2 && !eventData.data.state.opened) { | ||
eventData.data.state.loading = true; | ||
setTimeout(() => { | ||
eventData.data.state.loading = false; | ||
eventData.data.state.opened = !eventData.data.state.opened; | ||
}, 2000); | ||
} else { | ||
eventData.data.state.opened = !eventData.data.state.opened; | ||
} | ||
} | ||
|
||
type Data = { | ||
text: string; | ||
value?: any; | ||
state?: { | ||
opened?: boolean; | ||
selected?: boolean; | ||
disabled?: boolean; | ||
loading?: boolean; | ||
}; | ||
children?: Data[]; | ||
}; |
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
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