|
7 | 7 | // |
8 | 8 | ////////////////////////////////////////////////////////////// |
9 | 9 |
|
10 | | -import cn from 'classnames'; |
11 | 10 | import * as React from 'react'; |
12 | 11 | import { ClasslistComposite } from 'aspen-decorations'; |
13 | | -import { Directory, FileEntry, IItemRendererProps, ItemType, RenamePromptHandle, FileType, FileOrDir} from 'react-aspen'; |
| 12 | +import { Directory, FileEntry, IItemRendererProps, ItemType, FileOrDir} from 'react-aspen'; |
14 | 13 | import {IFileTreeXTriggerEvents, FileTreeXEvent } from '../types'; |
15 | | -import _ from 'lodash'; |
16 | 14 | import { Notificar } from 'notificar'; |
17 | | - |
| 15 | +import FileTreeItemComponent from './FileTreeItemComponent'; |
18 | 16 | interface IItemRendererXProps { |
19 | 17 | /** |
20 | 18 | * In this implementation, decoration are null when item is `PromptHandle` |
@@ -58,70 +56,21 @@ export class FileTreeItem extends React.Component<IItemRendererXProps & IItemRen |
58 | 56 |
|
59 | 57 | public render() { |
60 | 58 | const { item, itemType, decorations } = this.props; |
61 | | - |
62 | | - const isRenamePrompt = itemType === ItemType.RenamePrompt; |
63 | | - const isNewPrompt = itemType === ItemType.NewDirectoryPrompt || itemType === ItemType.NewFilePrompt; |
64 | | - const isDirExpanded = itemType === ItemType.Directory |
65 | | - ? (item as Directory).expanded |
66 | | - : itemType === ItemType.RenamePrompt && (item as RenamePromptHandle).target.type === FileType.Directory |
67 | | - ? ((item as RenamePromptHandle).target as Directory).expanded |
68 | | - : false; |
69 | | - |
70 | | - const fileOrDir = |
71 | | - (itemType === ItemType.File || |
72 | | - itemType === ItemType.NewFilePrompt || |
73 | | - (itemType === ItemType.RenamePrompt && (item as RenamePromptHandle).target.constructor === FileEntry)) |
74 | | - ? 'file' |
75 | | - : 'directory'; |
76 | | - |
77 | | - if (this.props.item.parent?.parent && this.props.item.parent?.path) { |
78 | | - this.props.item.resolvedPathCache = this.props.item.parent.path + '/' + this.props.item._metadata.data.id; |
79 | | - } |
80 | | - |
81 | | - const itemChildren = item.children && item.children.length > 0 && item._metadata.data._type.indexOf('coll-') !== -1 ? '(' + item.children.length + ')' : ''; |
82 | | - const extraClasses = item._metadata.data.extraClasses ? item._metadata.data.extraClasses.join(' ') : ''; |
83 | | - |
84 | | - const tags = item._metadata.data?.tags ?? []; |
85 | | - |
86 | | - return ( |
87 | | - <div |
88 | | - className={cn('file-entry', { |
89 | | - renaming: isRenamePrompt, |
90 | | - prompt: isRenamePrompt || isNewPrompt, |
91 | | - new: isNewPrompt, |
92 | | - }, fileOrDir, decorations ? decorations.classlist : null, `depth-${item.depth}`, extraClasses)} |
93 | | - data-depth={item.depth} |
94 | | - onContextMenu={this.handleContextMenu} |
95 | | - onClick={this.handleClick} |
96 | | - onDragStart={this.handleDragStartItem} |
97 | | - onMouseEnter={this.handleMouseEnter} |
98 | | - onMouseLeave={this.handleMouseLeave} |
99 | | - onKeyDown={()=>{/* taken care by parent */}} |
100 | | - // required for rendering context menus when opened through context menu button on keyboard |
101 | | - ref={this.handleDivRef} |
102 | | - draggable={true}> |
103 | | - |
104 | | - {!isNewPrompt && fileOrDir === 'directory' ? |
105 | | - <i className={cn('directory-toggle', isDirExpanded ? 'open' : '')} /> |
106 | | - : null |
107 | | - } |
108 | | - |
109 | | - <span className='file-label' onDoubleClick={this.handleDoubleClick}> |
110 | | - { |
111 | | - item._metadata?.data?.icon ? |
112 | | - <i className={cn('file-icon', item._metadata?.data?.icon ? item._metadata.data.icon : fileOrDir)} /> : null |
113 | | - } |
114 | | - <span className='file-name'> |
115 | | - { _.unescape(this.props.item.getMetadata('data')._label)} |
116 | | - </span> |
117 | | - <span className='children-count'>{itemChildren}</span> |
118 | | - {tags.map((tag)=>( |
119 | | - <div key={tag.text} className='file-tag' style={{'--tag-color': tag.color} as React.CSSProperties}> |
120 | | - {tag.text} |
121 | | - </div> |
122 | | - ))} |
123 | | - </span> |
124 | | - </div>); |
| 59 | + return( |
| 60 | + <div> |
| 61 | + <FileTreeItemComponent |
| 62 | + item={item} |
| 63 | + itemType={itemType} |
| 64 | + decorations={decorations} |
| 65 | + handleContextMenu={this.handleContextMenu} |
| 66 | + handleDragStartItem={this.handleDragStartItem} |
| 67 | + handleMouseEnter={this.handleMouseEnter} |
| 68 | + handleMouseLeave={this.handleMouseLeave} |
| 69 | + handleItemClicked={this.handleClick} |
| 70 | + handleItemDoubleClicked={this.handleDoubleClick} |
| 71 | + handleDivRef={this.handleDivRef}/> |
| 72 | + </div> |
| 73 | + ); |
125 | 74 | } |
126 | 75 |
|
127 | 76 | public componentDidMount() { |
|
0 commit comments