This repository was archived by the owner on Sep 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Simulate indentation of the project tree using some divs #12047
Merged
+98
−48
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1dda74c
Simulate indentation of the project tree using some divs
ficristo ef80a26
Review comments
ficristo de1f63f
Remove thickness class, add stopPropagation in rename, fix order of l…
ficristo 80aeead
fix folder behaviour
ficristo dc8cb32
Rework folder code and fix bouncing effect
ficristo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -60,6 +60,8 @@ define(function (require, exports, module) { | |
| RIGHT_MOUSE_BUTTON = 2, | ||
| LEFT_MOUSE_BUTTON = 0; | ||
|
|
||
| var INDENTATION_WIDTH = 10; | ||
|
|
||
| /** | ||
| * @private | ||
| * | ||
|
|
@@ -108,6 +110,40 @@ define(function (require, exports, module) { | |
| return width; | ||
| } | ||
|
|
||
| /** | ||
| * @private | ||
| * | ||
| * Create an appropriate div based "thickness" to indent the tree correctly. | ||
| * | ||
| * @param {int} depth The depth of the current node. | ||
| * @return {ReactComponent} The resulting div. | ||
| */ | ||
| function _createThickness(depth) { | ||
| return DOM.div({ | ||
| style: { | ||
| display: "inline-block", | ||
| width: INDENTATION_WIDTH * depth | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unitless value here, does React automatically convert it to |
||
| } | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * @private | ||
| * | ||
| * Create, and indent correctly, the arrow icons used for the folders. | ||
| * | ||
| * @param {int} depth The depth of the current node. | ||
| * @return {ReactComponent} The resulting ins. | ||
| */ | ||
| function _createAlignedIns(depth) { | ||
| return DOM.ins({ | ||
| className: "jstree-icon", | ||
| style: { | ||
| marginLeft: INDENTATION_WIDTH * depth | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * This is a mixin that provides rename input behavior. It is responsible for taking keyboard input | ||
| * and invoking the correct action based on that input. | ||
|
|
@@ -391,6 +427,7 @@ define(function (require, exports, module) { | |
| handleClick: function (e) { | ||
| // If we're renaming, allow the click to go through to the rename input. | ||
| if (this.props.entry.get("rename")) { | ||
| e.stopPropagation(); | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -457,7 +494,22 @@ define(function (require, exports, module) { | |
| 'context-node': this.props.entry.get("context") | ||
| }); | ||
|
|
||
| var liArgs = [ | ||
| { | ||
| className: this.getClasses("jstree-leaf"), | ||
| onClick: this.handleClick, | ||
| onMouseDown: this.handleMouseDown, | ||
| onDoubleClick: this.handleDoubleClick | ||
| }, | ||
| DOM.ins({ | ||
| className: "jstree-icon" | ||
| }), | ||
| ]; | ||
|
|
||
| var thickness = _createThickness(this.props.depth); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Consecutive |
||
|
|
||
| if (this.props.entry.get("rename")) { | ||
| liArgs.push(thickness); | ||
| nameDisplay = fileRenameInput({ | ||
| actions: this.props.actions, | ||
| entry: this.props.entry, | ||
|
|
@@ -469,20 +521,13 @@ define(function (require, exports, module) { | |
| var aArgs = _.flatten([{ | ||
| href: "#", | ||
| className: fileClasses | ||
| }, this.getIcons(), name, extension]); | ||
| }, thickness, this.getIcons(), name, extension]); | ||
| nameDisplay = DOM.a.apply(DOM.a, aArgs); | ||
| } | ||
|
|
||
| return DOM.li({ | ||
| className: this.getClasses("jstree-leaf"), | ||
| onClick: this.handleClick, | ||
| onMouseDown: this.handleMouseDown, | ||
| onDoubleClick: this.handleDoubleClick | ||
| }, | ||
| DOM.ins({ | ||
| className: "jstree-icon" | ||
| }, " "), | ||
| nameDisplay); | ||
| liArgs.push(nameDisplay); | ||
|
|
||
| return DOM.li.apply(DOM.li, liArgs); | ||
| } | ||
| })); | ||
|
|
||
|
|
@@ -612,6 +657,11 @@ define(function (require, exports, module) { | |
| * If you click on a directory, it will toggle between open and closed. | ||
| */ | ||
| handleClick: function (event) { | ||
| if (this.props.entry.get("rename")) { | ||
| event.stopPropagation(); | ||
| return; | ||
| } | ||
|
|
||
| if (event.button !== LEFT_MOUSE_BUTTON) { | ||
| return; | ||
| } | ||
|
|
@@ -662,12 +712,12 @@ define(function (require, exports, module) { | |
| nodeClass, | ||
| childNodes, | ||
| children = entry.get("children"), | ||
| isOpen = entry.get("open"), | ||
| directoryClasses = ""; | ||
| isOpen = entry.get("open"); | ||
|
|
||
| if (isOpen && children) { | ||
| nodeClass = "open"; | ||
| childNodes = directoryContents({ | ||
| depth: this.props.depth + 1, | ||
| parentPath: this.myPath(), | ||
| contents: children, | ||
| extensions: this.props.extensions, | ||
|
|
@@ -680,46 +730,46 @@ define(function (require, exports, module) { | |
| nodeClass = "closed"; | ||
| } | ||
|
|
||
| if (this.props.entry.get("selected")) { | ||
| directoryClasses += " jstree-clicked sidebar-selection"; | ||
| } | ||
| var nameDisplay, | ||
| cx = Classnames; | ||
|
|
||
| if (entry.get("context")) { | ||
| directoryClasses += " context-node"; | ||
| } | ||
| var directoryClasses = cx({ | ||
| 'jstree-clicked sidebar-selection': entry.get("selected"), | ||
| 'context-node': entry.get("context") | ||
| }); | ||
|
|
||
| var liArgs = [ | ||
| { | ||
| className: this.getClasses("jstree-" + nodeClass), | ||
| onClick: this.handleClick, | ||
| onMouseDown: this.handleMouseDown | ||
| }, | ||
| _createAlignedIns(this.props.depth) | ||
| ]; | ||
|
|
||
| var thickness = _createThickness(this.props.depth); | ||
|
|
||
| var nameDisplay, renameInput; | ||
| if (entry.get("rename")) { | ||
| renameInput = directoryRenameInput({ | ||
| liArgs.push(thickness); | ||
| nameDisplay = directoryRenameInput({ | ||
| actions: this.props.actions, | ||
| entry: this.props.entry, | ||
| entry: entry, | ||
| name: this.props.name, | ||
| parentPath: this.props.parentPath | ||
| }); | ||
| } else { | ||
| // Need to flatten the arguments because getIcons returns an array | ||
| var aArgs = _.flatten([{ | ||
| href: "#", | ||
| className: directoryClasses | ||
| }, thickness, this.getIcons(), this.props.name]); | ||
| nameDisplay = DOM.a.apply(DOM.a, aArgs); | ||
| } | ||
|
|
||
| // Need to flatten the arguments because getIcons returns an array | ||
| var aArgs = _.flatten([{ | ||
| href: "#", | ||
| className: directoryClasses | ||
| }, this.getIcons()]); | ||
| if (!entry.get("rename")) { | ||
| aArgs.push(this.props.name); | ||
| } | ||
|
|
||
| nameDisplay = DOM.a.apply(DOM.a, aArgs); | ||
| liArgs.push(nameDisplay); | ||
| liArgs.push(childNodes); | ||
|
|
||
| return DOM.li({ | ||
| className: this.getClasses("jstree-" + nodeClass), | ||
| onClick: this.handleClick, | ||
| onMouseDown: this.handleMouseDown | ||
| }, | ||
| DOM.ins({ | ||
| className: "jstree-icon" | ||
| }, " "), | ||
| renameInput, | ||
| nameDisplay, | ||
| childNodes); | ||
| return DOM.li.apply(DOM.li, liArgs); | ||
| } | ||
| })); | ||
|
|
||
|
|
@@ -764,6 +814,7 @@ define(function (require, exports, module) { | |
|
|
||
| if (FileTreeViewModel.isFile(entry)) { | ||
| return fileNode({ | ||
| depth: this.props.depth, | ||
| parentPath: this.props.parentPath, | ||
| name: name, | ||
| entry: entry, | ||
|
|
@@ -775,6 +826,7 @@ define(function (require, exports, module) { | |
| }); | ||
| } else { | ||
| return directoryNode({ | ||
| depth: this.props.depth, | ||
| parentPath: this.props.parentPath, | ||
| name: name, | ||
| entry: entry, | ||
|
|
@@ -971,6 +1023,7 @@ define(function (require, exports, module) { | |
| }), | ||
| contents = directoryContents({ | ||
| isRoot: true, | ||
| depth: 1, | ||
| parentPath: this.props.parentPath, | ||
| sortDirectoriesFirst: this.props.sortDirectoriesFirst, | ||
| contents: this.props.treeData, | ||
|
|
||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this
divhave defineddisplayasinline-block?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just saw it is defined in the
thicknessclass, may be we can define it inside thestyleprop?