UNPKG

easyui-draganddrop

Version:

Drag and drop elements including a file explorer and a rubbish bin.

1,446 lines (1,151 loc) 400 kB
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.easyuidraganddrop = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ 'use strict'; module.exports = { options: require('./lib/options'), Explorer: require('./lib/explorer'), RubbishBin: require('./lib/rubbishBin') }; },{"./lib/explorer":3,"./lib/options":15,"./lib/rubbishBin":16}],2:[function(require,module,exports){ 'use strict'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var easyui = require('easyui'), Element = easyui.Element; var util = require('./util'), options = require('./options'); var DroppableElement = function (_Element) { _inherits(DroppableElement, _Element); function DroppableElement(selector, moveHandler) { _classCallCheck(this, DroppableElement); var _this = _possibleConstructorReturn(this, (DroppableElement.__proto__ || Object.getPrototypeOf(DroppableElement)).call(this, selector)); _this.moveHandler = moveHandler; _this.droppableElements = []; return _this; } _createClass(DroppableElement, [{ key: 'addDroppableElement', value: function addDroppableElement(droppableElement) { this.droppableElements.push(droppableElement); } }, { key: 'removeDroppableElement', value: function removeDroppableElement(droppableElement) { var index = indexOf(this.droppableElements, droppableElement), found = index !== -1; if (found) { this.droppableElements.splice(index, 1); } } }, { key: 'isOverlappingDraggableEntry', value: function isOverlappingDraggableEntry(draggableEntryCollapsedBounds) { var bounds = this.getBounds(), boundsOverlappingDraggableEntry = bounds.areOverlapping(draggableEntryCollapsedBounds), overlappingDraggableEntry = boundsOverlappingDraggableEntry; return overlappingDraggableEntry; } }, { key: 'getDroppableElementToBeMarked', value: function getDroppableElementToBeMarked(draggableEntry) { var droppableElementToBeMarked = this.droppableElements.reduce(function (droppableElementToBeMarked, droppableElement) { if (droppableElementToBeMarked === null) { if (droppableElement.isToBeMarked(draggableEntry)) { /// droppableElementToBeMarked = droppableElement; } } return droppableElementToBeMarked; }, null); return droppableElementToBeMarked; } }, { key: 'getMarkedDroppableElement', value: function getMarkedDroppableElement() { var markedDroppableElement = this.droppableElements.reduce(function (markedDroppableElement, droppableElement) { if (markedDroppableElement === null) { var droppableElementMarked = droppableElement.isMarked(); if (droppableElementMarked) { markedDroppableElement = droppableElement; } } return markedDroppableElement; }, null); return markedDroppableElement; } }, { key: 'removeMarkerGlobally', value: function removeMarkerGlobally() { var marked = this.isMarked(); if (marked) { this.removeMarker(); } else { var markedDroppableElement = this.getMarkedDroppableElement(); markedDroppableElement.removeMarker(); } } }, { key: 'moveDraggableEntries', value: function moveDraggableEntries(draggableEntries, sourcePath, targetPath, done) { var pathMaps = this.pathMapsFromDraggableEntries(draggableEntries, sourcePath, targetPath); this.moveHandler(pathMaps, function () { var lastDraggableEntry = last(draggableEntries), firstDraggableEntry = first(draggableEntries), firstDraggableEntryExplorer = firstDraggableEntry.getExplorer(), draggableEntriesExplorer = firstDraggableEntryExplorer, /// removeEmptyParentDirectories = draggableEntriesExplorer.hasOption(options.REMOVE_EMPTY_PARENT_DIRECTORIES); if (removeEmptyParentDirectories) { draggableEntriesExplorer.unsetOption(options.REMOVE_EMPTY_PARENT_DIRECTORIES); } draggableEntries.forEach(function (draggableEntry) { if (draggableEntry === lastDraggableEntry) { if (removeEmptyParentDirectories) { draggableEntriesExplorer.setOption(options.REMOVE_EMPTY_PARENT_DIRECTORIES); } } var draggableEntryPath = draggableEntry.getPath(); if (draggableEntryPath !== null) { var _sourcePath = draggableEntryPath, /// pathMap = find(pathMaps, function (pathMap) { var sourceDraggableEntryPath = _sourcePath, movedPath = pathMap[sourceDraggableEntryPath], found = movedPath !== undefined; return found; }), movedPath = pathMap[_sourcePath]; this.moveDraggableEntry(draggableEntry, _sourcePath, movedPath); } }.bind(this)); done(); }.bind(this)); } }, { key: 'moveDraggableEntry', value: function moveDraggableEntry(draggableEntry, sourcePath, movedPath) { var draggableEntryDirectory = draggableEntry.isDirectory(); if (draggableEntryDirectory) { var directory = draggableEntry, /// sourceDirectoryPath = sourcePath, /// movedDirectoryPath = movedPath; this.moveDirectory(directory, sourceDirectoryPath, movedDirectoryPath); } else { var file = draggableEntry, /// sourceFilePath = sourcePath, /// movedFilePath = movedPath; /// this.moveFile(file, sourceFilePath, movedFilePath); } } }]); return DroppableElement; }(Element); module.exports = DroppableElement; function indexOf(array, element) { var index = -1; array.some(function (currentElement, currentElementIndex) { if (currentElement === element) { index = currentElementIndex; return true; } else { return false; } }); return index; } function find(array, callback) { var element = null; array.some(function (currentElement) { if (callback(currentElement)) { element = currentElement; return true; } else { return false; } }); return element; } function first(array) { return array[0]; } function last(array) { return array[array.length - 1]; } },{"./options":15,"./util":17,"easyui":18}],3:[function(require,module,exports){ 'use strict'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var easyui = require('easyui'), Element = easyui.Element, React = easyui.React; var util = require('./util'), options = require('./options'), DroppableElement = require('./droppableElement'), DirectoryMarker = require('./explorer/entry/marker/directory'), RootDirectory = require('./explorer/draggableEntry/directory/root'); var Explorer = function (_DroppableElement) { _inherits(Explorer, _DroppableElement); function Explorer(selector, rootDirectoryName) { var openHandler = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function (sourcePath) {}; var moveHandler = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : function (pathMaps, done) { done(); }; _classCallCheck(this, Explorer); var _this = _possibleConstructorReturn(this, (Explorer.__proto__ || Object.getPrototypeOf(Explorer)).call(this, selector, moveHandler)); var name = rootDirectoryName, /// explorer = _this, /// rootDirectory = React.createElement(RootDirectory, { name: name, explorer: explorer, className: 'directory' }); _this.openHandler = openHandler; _this.options = {}; _this.rootDirectory = rootDirectory; _this.append(rootDirectory); return _this; } _createClass(Explorer, [{ key: 'setOption', value: function setOption(option) { this.options[option] = true; } }, { key: 'unsetOption', value: function unsetOption(option) { delete this.options[option]; } }, { key: 'hasOption', value: function hasOption(option) { option = this.options[option] === true; /// return option; } }, { key: 'getFilePaths', value: function getFilePaths() { return this.rootDirectory.getFilePaths(); } }, { key: 'getRootDirectoryName', value: function getRootDirectoryName() { return this.rootDirectory.getName(); } }, { key: 'getMarkedDirectory', value: function getMarkedDirectory() { return this.rootDirectory.getMarkedDirectory(); } }, { key: 'getDirectoryOverlappingDraggableEntry', value: function getDirectoryOverlappingDraggableEntry(draggableEntry) { return this.rootDirectory.getDirectoryOverlappingDraggableEntry(draggableEntry); } }, { key: 'getDraggableEntryPath', value: function getDraggableEntryPath(draggableEntry) { return this.rootDirectory.getDraggableEntryPath(draggableEntry); } }, { key: 'addFile', value: function addFile(filePath) { this.rootDirectory.addFile(filePath); } }, { key: 'addDirectory', value: function addDirectory(directoryPath, collapsed) { this.rootDirectory.addDirectory(directoryPath, collapsed); } }, { key: 'removeFile', value: function removeFile(filePath) { this.rootDirectory.removeFile(filePath); } }, { key: 'removeDirectory', value: function removeDirectory(directoryPath) { this.rootDirectory.removeDirectory(directoryPath); } }, { key: 'addMarkerInPlace', value: function addMarkerInPlace(draggableEntry) { var draggableEntryPath = draggableEntry.getPath(), draggableEntryType = draggableEntry.getType(), draggableEntryPathTopmostDirectoryName = util.isPathTopmostDirectoryName(draggableEntryPath); if (draggableEntryPathTopmostDirectoryName) { var topmostDirectoryMarkerPath = draggableEntryPath; this.addTopmostDirectoryMarker(topmostDirectoryMarkerPath); } else { var markerPath = draggableEntryPath; this.rootDirectory.addMarker(markerPath, draggableEntryType); } } }, { key: 'addMarker', value: function addMarker(draggableEntry, directoryOverlappingDraggableEntry) { var draggableEntryName = draggableEntry.getName(), draggableEntryType = draggableEntry.getType(), directoryOverlappingDraggableEntryPath = directoryOverlappingDraggableEntry.getPath(), markerPath = directoryOverlappingDraggableEntryPath + '/' + draggableEntryName; this.rootDirectory.addMarker(markerPath, draggableEntryType); } }, { key: 'addTopmostDirectoryMarker', value: function addTopmostDirectoryMarker(topmostDirectoryMarkerPath) { var topmostDirectoryMarkerName = topmostDirectoryMarkerPath, /// name = topmostDirectoryMarkerName, /// topmostDirectoryMarker = React.createElement(DirectoryMarker, { name: name, className: 'marker' }); this.append(topmostDirectoryMarker); } }, { key: 'removeMarker', value: function removeMarker() { var rootDirectoryMarked = this.rootDirectory.isMarked(); if (rootDirectoryMarked) { this.rootDirectory.removeMarker(); } else { var topmostDirectoryMarker = this.retrieveTopmostDirectoryMarker(); topmostDirectoryMarker.remove(); } } }, { key: 'isMarked', value: function isMarked() { var marked = void 0; var rootDirectoryMarked = this.rootDirectory.isMarked(); if (rootDirectoryMarked) { marked = true; } else { var topmostDirectoryMarker = this.retrieveTopmostDirectoryMarker(); marked = topmostDirectoryMarker !== null; } return marked; } }, { key: 'isToBeMarked', value: function isToBeMarked(draggableEntry) { var directoryOverlappingDraggableEntry = this.getDirectoryOverlappingDraggableEntry(draggableEntry), toBeMarked = directoryOverlappingDraggableEntry !== null; return toBeMarked; } }, { key: 'retrieveTopmostDirectoryMarker', value: function retrieveTopmostDirectoryMarker() { var topmostDirectoryMarker = null; var childListElements = this.getChildElements('li'); childListElements.some(function (childElement) { if (childElement instanceof DirectoryMarker) { topmostDirectoryMarker = childElement; /// return true; } else { return false; } }); return topmostDirectoryMarker; } }, { key: 'startDragging', value: function startDragging(draggableEntry) { var marked = this.isMarked(), startedDragging = !marked; if (startedDragging) { this.addMarkerInPlace(draggableEntry); } return startedDragging; } }, { key: 'stopDragging', value: function stopDragging(draggableEntry, done) { var draggableEntryPath = draggableEntry.getPath(), marked = this.isMarked(), markedDroppableElement = marked ? this : this.getMarkedDroppableElement(), markedDirectory = markedDroppableElement.getMarkedDirectory(), markedDirectoryPath = markedDirectory !== null ? markedDirectory.getPath() : null, draggableEntryPathWithoutBottommostName = util.pathWithoutBottommostName(draggableEntryPath), sourcePath = draggableEntryPathWithoutBottommostName, targetPath = markedDirectoryPath, unmoved = sourcePath === targetPath; if (marked && unmoved) { this.removeMarker(); done(); } else { var subDraggableEntries = draggableEntry.getSubEntries(), draggableEntries = subDraggableEntries; /// draggableEntries.reverse(); draggableEntries.push(draggableEntry); markedDroppableElement.moveDraggableEntries(draggableEntries, sourcePath, targetPath, function () { markedDroppableElement.removeMarker(); done(); }); } } }, { key: 'escapeDragging', value: function escapeDragging() { this.removeMarkerGlobally(); } }, { key: 'dragging', value: function dragging(draggableEntry) { var explorer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this; var marked = this.isMarked(); if (marked) { var directoryOverlappingDraggableEntry = void 0; var toBeMarked = this.isToBeMarked(draggableEntry); if (toBeMarked) { var within = explorer === this, /// noDraggingWithin = this.hasOption(options.NO_DRAGGING_WITHIN), noDragging = within && noDraggingWithin; if (!noDragging) { var markedDirectory = this.getMarkedDirectory(); directoryOverlappingDraggableEntry = this.getDirectoryOverlappingDraggableEntry(draggableEntry); if (markedDirectory !== directoryOverlappingDraggableEntry) { this.removeMarker(); this.addMarker(draggableEntry, directoryOverlappingDraggableEntry); } } } else { var droppableElementToBeMarked = this.getDroppableElementToBeMarked(draggableEntry); if (droppableElementToBeMarked !== null) { directoryOverlappingDraggableEntry = droppableElementToBeMarked.getDirectoryOverlappingDraggableEntry(draggableEntry); droppableElementToBeMarked.addMarker(draggableEntry, directoryOverlappingDraggableEntry); } else { explorer.addMarkerInPlace(draggableEntry); } this.removeMarker(); } } else { var markedDroppableElement = this.getMarkedDroppableElement(); markedDroppableElement.dragging(draggableEntry, explorer); } } }, { key: 'moveDirectory', value: function moveDirectory(directory, sourceDirectoryPath, movedDirectoryPath) { var explorer = directory.getExplorer(); var directoryPath = void 0; if (movedDirectoryPath === sourceDirectoryPath) {} else if (movedDirectoryPath === null) { directoryPath = sourceDirectoryPath; /// explorer.removeDirectory(directoryPath); } else { directoryPath = sourceDirectoryPath; /// explorer.removeDirectory(directoryPath); var collapsed = directory.isCollapsed(); directoryPath = movedDirectoryPath; /// this.addDirectory(directoryPath, collapsed); } } }, { key: 'moveFile', value: function moveFile(file, sourceFilePath, movedFilePath) { var explorer = file.getExplorer(); var filePath = void 0; if (movedFilePath === sourceFilePath) {} else if (movedFilePath === null) { filePath = sourceFilePath; /// explorer.removeFile(filePath); } else { filePath = sourceFilePath; /// explorer.removeFile(filePath); filePath = movedFilePath; /// this.addFile(filePath); } } }, { key: 'openFile', value: function openFile(file) { var filePath = file.getPath(this.rootDirectory), sourcePath = filePath; this.openHandler(sourcePath); } }, { key: 'pathMapsFromDraggableEntries', value: function pathMapsFromDraggableEntries(draggableEntries, sourcePath, targetPath) { var pathMaps = draggableEntries.map(function (draggableEntry) { var pathMap = {}, draggableEntryPath = draggableEntry.getPath(), sourceDraggableEntryPath = draggableEntryPath, /// targetDraggableEntryPath = sourcePath === null ? util.prependTargetPath(draggableEntryPath, targetPath) : util.replaceSourcePathWithTargetPath(draggableEntryPath, sourcePath, targetPath); pathMap[sourceDraggableEntryPath] = targetDraggableEntryPath; return pathMap; }); return pathMaps; } }], [{ key: 'clone', value: function clone(selector, rootDirectoryName, openHandler, moveHandler) { return Element.clone(Explorer, selector, rootDirectoryName, openHandler, moveHandler); } }, { key: 'fromHTML', value: function fromHTML(html, rootDirectoryName, openHandler, moveHandler) { return Element.fromHTML(Explorer, html, rootDirectoryName, openHandler, moveHandler); } }, { key: 'fromProperties', value: function fromProperties(properties) { var rootDirectoryName = properties.rootDirectoryName, openHandler = properties.openHandler, onMove = properties.onMove, moveHandler = onMove; /// return Element.fromProperties(Explorer, properties, rootDirectoryName, openHandler, moveHandler); } }]); return Explorer; }(DroppableElement); Object.assign(Explorer, { tagName: 'ul', ignoredAttributes: ['rootDirectoryName', 'openHandler', 'onMove'] }); module.exports = Explorer; },{"./droppableElement":2,"./explorer/draggableEntry/directory/root":6,"./explorer/entry/marker/directory":11,"./options":15,"./util":17,"easyui":18}],4:[function(require,module,exports){ 'use strict'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var easyui = require('easyui'), Element = easyui.Element, window = easyui.window, React = easyui.React; var options = require('../options'), NameButton = require('./nameButton'); var ESCAPE_KEYCODE = 27, START_DRAGGING_DELAY = 175; var DraggableEntry = function (_Element) { _inherits(DraggableEntry, _Element); function DraggableEntry(selector, name, explorer, type) { _classCallCheck(this, DraggableEntry); var _this = _possibleConstructorReturn(this, (DraggableEntry.__proto__ || Object.getPrototypeOf(DraggableEntry)).call(this, selector)); var nameButton = React.createElement( NameButton, { className: 'name' }, name ); _this.explorer = explorer; _this.type = type; _this.timeout = null; _this.topOffset = null; _this.leftOffset = null; _this.nameButton = nameButton; _this.append(nameButton); _this.onMouseDown(_this.mouseDownHandler.bind(_this)); return _this; } _createClass(DraggableEntry, [{ key: 'getName', value: function getName() { return this.nameButton.getName(); } }, { key: 'getExplorer', value: function getExplorer() { return this.explorer; } }, { key: 'getType', value: function getType() { return this.type; } }, { key: 'getPath', value: function getPath() { var path = this.explorer.getDraggableEntryPath(this); return path; } }, { key: 'getCollapsedBounds', value: function getCollapsedBounds() { var bounds = this.getBounds(), collapsedBounds = bounds; /// return collapsedBounds; } }, { key: 'isRootDirectory', value: function isRootDirectory() { return false; } }, { key: 'isOverlappingCollapsedBounds', value: function isOverlappingCollapsedBounds(collapsedBounds) { var bounds = this.getBounds(), overlappingCollapsedBounds = bounds.areOverlapping(collapsedBounds); return overlappingCollapsedBounds; } }, { key: 'setName', value: function setName(name) { this.nameButton.setName(name); } }, { key: 'onDoubleClick', value: function onDoubleClick(handler) { this.nameButton.onDoubleClick(handler); } }, { key: 'startDragging', value: function startDragging(mouseTop, mouseLeft) { var escapeKeyStopsDragging = this.explorer.hasOption(options.ESCAPE_KEY_STOPS_DRAGGING), bounds = this.getBounds(); var top = bounds.getTop(), left = bounds.getLeft(); this.topOffset = top - mouseTop; this.leftOffset = left - mouseLeft; top = top + 'px'; left = left + 'px'; var css = { top: top, left: left }; this.css(css); if (escapeKeyStopsDragging) { this.on('keydown', this.keyDownHandler.bind(this)); } this.addClass('dragging'); } }, { key: 'stopDragging', value: function stopDragging() { var escapeKeyStopsDragging = this.explorer.hasOption(options.ESCAPE_KEY_STOPS_DRAGGING); if (escapeKeyStopsDragging) { this.off('keydown', this.keyDownHandler.bind(this)); } this.removeClass('dragging'); } }, { key: 'dragging', value: function dragging(mouseTop, mouseLeft) { var top = mouseTop + this.topOffset, left = mouseLeft + this.leftOffset; top = top + 'px'; left = left + 'px'; var css = { top: top, left: left }; this.css(css); this.explorer.dragging(this); } }, { key: 'startWaitingToDrag', value: function startWaitingToDrag(mouseTop, mouseLeft, mouseButton) { if (this.timeout === null) { this.timeout = setTimeout(function () { this.timeout = null; var rootDirectory = this.isRootDirectory(), subEntry = !rootDirectory, /// noDragging = this.explorer.hasOption(options.NO_DRAGGING), noDraggingSubEntries = this.explorer.hasOption(options.NO_DRAGGING_SUB_ENTRIES), noDraggingRootDirectory = this.explorer.hasOption(options.NO_DRAGGING_ROOT_DIRECTORY); if (noDragging || subEntry && noDraggingSubEntries || rootDirectory && noDraggingRootDirectory) { return; } var mouseOver = this.isMouseOver(mouseTop, mouseLeft); if (mouseOver) { var startedDragging = this.explorer.startDragging(this); if (startedDragging) { this.startDragging(mouseTop, mouseLeft); } } }.bind(this), START_DRAGGING_DELAY); } } }, { key: 'stopWaitingToDrag', value: function stopWaitingToDrag() { if (this.timeout !== null) { clearTimeout(this.timeout); this.timeout = null; } } }, { key: 'isDragging', value: function isDragging() { var dragging = this.hasClass('dragging'); return dragging; } }, { key: 'isMouseOver', value: function isMouseOver(mouseTop, mouseLeft) { var collapsedBounds = this.getCollapsedBounds(), collapsedBoundsOverlappingMouse = collapsedBounds.isOverlappingMouse(mouseTop, mouseLeft), mouseOver = collapsedBoundsOverlappingMouse; return mouseOver; } }, { key: 'mouseDownHandler', value: function mouseDownHandler(mouseTop, mouseLeft, mouseButton) { window.on('mouseup blur', this.mouseUpHandler.bind(this)); window.onMouseMove(this.mouseMoveHandler.bind(this)); if (mouseButton === Element.LEFT_MOUSE_BUTTON) { var dragging = this.isDragging(); if (!dragging) { this.startWaitingToDrag(mouseTop, mouseLeft); } } } }, { key: 'mouseUpHandler', value: function mouseUpHandler(mouseTop, mouseLeft, mouseButton) { window.off('mouseup blur', this.mouseUpHandler.bind(this)); window.offMouseMove(this.mouseMoveHandler.bind(this)); var dragging = this.isDragging(); if (dragging) { this.explorer.stopDragging(this, function () { this.stopDragging(); }.bind(this)); } else { this.stopWaitingToDrag(); } } }, { key: 'mouseMoveHandler', value: function mouseMoveHandler(mouseTop, mouseLeft, mouseButton) { var dragging = this.isDragging(); if (dragging) { this.dragging(mouseTop, mouseLeft); } } }, { key: 'keyDownHandler', value: function keyDownHandler(event) { var keyCode = event.keyCode || event.which; if (keyCode === ESCAPE_KEYCODE) { var dragging = this.isDragging(); if (dragging) { this.explorer.escapeDragging(); this.stopDragging(); } } } }], [{ key: 'fromProperties', value: function fromProperties(Class, properties) { for (var _len = arguments.length, remainingArguments = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { remainingArguments[_key - 2] = arguments[_key]; } return Element.fromProperties.apply(Element, [Class, properties].concat(remainingArguments)); } }]); return DraggableEntry; }(Element); Object.assign(DraggableEntry, { tagName: 'li' }); module.exports = DraggableEntry; },{"../options":15,"./nameButton":13,"easyui":18}],5:[function(require,module,exports){ 'use strict'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var easyui = require('easyui'), React = easyui.React; var util = require('../../util'), Entry = require('../entry'), Entries = require('../entries'), ToggleButton = require('../toggleButton'), DraggableEntry = require('../draggableEntry'); var Directory = function (_DraggableEntry) { _inherits(Directory, _DraggableEntry); function Directory(selector, name, explorer) { var collapsed = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; _classCallCheck(this, Directory); var type = Entry.types.DIRECTORY; var _this = _possibleConstructorReturn(this, (Directory.__proto__ || Object.getPrototypeOf(Directory)).call(this, selector, name, explorer, type)); var updateHandler = _this.toggleButtonUpdateHandler.bind(_this), toggleButton = React.createElement(ToggleButton, { updateHandler: updateHandler, className: 'toggle' }), entries = React.createElement(Entries, { Directory: Directory, className: 'entries' }); _this.onDoubleClick(_this.doubleClickHandler.bind(_this)); _this.toggleButton = toggleButton; _this.entries = entries; _this.append(entries); _this.prepend(toggleButton); collapsed ? _this.collapse() : _this.expand(); return _this; } _createClass(Directory, [{ key: 'isDirectory', value: function isDirectory() { return true; } }, { key: 'isBefore', value: function isBefore(entry) { var entryType = entry.getType(); switch (entryType) { case Entry.types.FILE: case Entry.types.MARKER: return true; case Entry.types.DIRECTORY: var name = this.getName(), entryName = entry.getName(), before = name.localeCompare(entryName) < 0; return before; } } }, { key: 'getSubEntries', value: function getSubEntries() { var subEntries = []; this.forEachFile(function (file) { var subEntry = file; /// subEntries.push(subEntry); }); this.forEachDirectory(function (directory) { var subEntry = directory, /// directorySubEntries = directory.getSubEntries(); subEntries.push(subEntry); subEntries = subEntries.concat(directorySubEntries); }); return subEntries; } }, { key: 'getFilePaths', value: function getFilePaths() { var filePaths = []; this.forEachFile(function (file) { var filePath = file.getPath(); filePaths.push(filePath); }); this.forEachDirectory(function (directory) { var directoryFilePaths = directory.getFilePaths(); filePaths = filePaths.concat(directoryFilePaths); }); return filePaths; } }, { key: 'getCollapsedBounds', value: function getCollapsedBounds() { var collapsed = this.isCollapsed(); this.collapse(); var bounds = _get(Directory.prototype.__proto__ || Object.getPrototypeOf(Directory.prototype), 'getBounds', this).call(this), collapsedBounds = bounds; /// if (!collapsed) { this.expand(); } return collapsedBounds; } }, { key: 'isOverlappingDraggableEntry', value: function isOverlappingDraggableEntry(draggableEntry) { var overlappingDraggableEntry = void 0; if (this === draggableEntry) { overlappingDraggableEntry = false; } else { var collapsed = this.isCollapsed(); if (collapsed) { overlappingDraggableEntry = false; } else { var draggableEntryCollapsedBounds = draggableEntry.getCollapsedBounds(), overlappingDraggableEntryCollapsedBounds = _get(Directory.prototype.__proto__ || Object.getPrototypeOf(Directory.prototype), 'isOverlappingCollapsedBounds', this).call(this, draggableEntryCollapsedBounds); overlappingDraggableEntry = overlappingDraggableEntryCollapsedBounds; } } return overlappingDraggableEntry; } }, { key: 'isCollapsed', value: function isCollapsed() { return this.toggleButton.isCollapsed(); } }, { key: 'expand', value: function expand() { this.toggleButton.expand(); } }, { key: 'collapse', value: function collapse() { this.toggleButton.collapse(); } }, { key: 'addFile', value: function addFile(filePath) { var addIfNecessary = true, topmostDirectory = this.topmostDirectory(filePath, addIfNecessary); if (topmostDirectory !== null) { var filePathWithoutTopmostDirectoryName = util.pathWithoutTopmostDirectoryName(filePath); topmostDirectory.addFile(filePathWithoutTopmostDirectoryName); } else { var fileName = filePath, /// entriesFile = this.entries.hasFile(fileName); if (!entriesFile) { var explorer = this.getExplorer(); this.entries.addFile(fileName, explorer); } } } }, { key: 'addDirectory', value: function addDirectory(directoryPath, collapsed) { var addIfNecessary = true, topmostDirectory = this.topmostDirectory(directoryPath, addIfNecessary); if (topmostDirectory !== null) { var directoryPathWithoutTopmostDirectoryName = util.pathWithoutTopmostDirectoryName(directoryPath); topmostDirectory.addDirectory(directoryPathWithoutTopmostDirectoryName, collapsed); } else { var directoryName = directoryPath, /// entriesDirectory = this.entries.hasDirectory(directoryName); if (!entriesDirectory) { var explorer = this.getExplorer(); this.entries.addDirectory(directoryName, explorer, collapsed); } } } }, { key: 'removeFile', value: function removeFile(filePath) { var removeEmptyParentDirectories = null; /// var addIfNecessary = false, topmostDirectory = this.topmostDirectory(filePath, addIfNecessary); if (topmostDirectory !== null) { var filePathWithoutTopmostDirectoryName = util.pathWithoutTopmostDirectoryName(filePath); removeEmptyParentDirectories = topmostDirectory.removeFile(filePathWithoutTopmostDirectoryName); } else { var fileName = filePath, /// entriesFile = this.entries.hasFile(fileName); if (entriesFile) { removeEmptyParentDirectories = this.entries.removeFile(fileName); } } if (removeEmptyParentDirectories === true) { var rootDirectory = this.isRootDirectory(); if (!rootDirectory) { var empty = this.isEmpty(); if (empty) { this.remove(); } } } return removeEmptyParentDirectories; } }, { key: 'removeDirectory', value: function removeDirectory(directoryPath) { var removeEmptyParentDirectories = null; /// var addIfNecessary = false, topmostDirectory = this.topmostDirectory(directoryPath, addIfNecessary); if (topmostDirectory !== null) { var directoryPathWithoutTopmostDirectoryName = util.pathWithoutTopmostDirectoryName(directoryPath); removeEmptyParentDirectories = topmostDirectory.removeDirectory(directoryPathWithoutTopmostDirectoryName); } else { var directoryName = directoryPath, /// entriesDirectory = this.entries.hasDirectory(directoryName); if (entriesDirectory) { removeEmptyParentDirectories = this.entries.removeDirectory(directoryName); } } if (removeEmptyParentDirectories === true) { var rootDirectory = this.isRootDirectory(); if (!rootDirectory) { var empty = this.isEmpty(); if (empty) { this.remove(); } } } return removeEmptyParentDirectories; } }, { key: 'addMarker', value: function addMarker(markerPath, draggableEntryType) { var topmostDirectoryName = util.topmostDirectoryName(markerPath); if (topmostDirectoryName === null) { var markerName = markerPath; /// this.entries.addMarker(markerName, draggableEntryType); } else { var topmostDirectory = this.entries.retrieveDirectory(topmostDirectoryName), markerPathWithoutTopmostDirectoryName = util.pathWithoutTopmostDirectoryName(markerPath); topmostDirectory.addMarker(markerPathWithoutTopmostDirectoryName, draggableEntryType); } } }, { key: 'removeMarker', value: function removeMarker() { var removed = void 0; var entriesMarked = this.entries.isMarked(); if (entriesMarked) { this.entries.removeMarker(); removed = true; } else { removed = this.entries.someDirectory(function (directory) { var removed = directory.removeMarker(); return removed; }); } return removed; } }, { key: 'isMarked', value: function isMarked() { var marked = void 0; var entriesMarked = this.entries.isMarked(); if (entriesMarked) { marked = entriesMarked; } else { var directoryMarked = this.entries.someDirectory(function (directory) { var directoryMarked = directory.isMarked(); return directoryMarked; }); marked = directoryMarked; } return marked; } }, { key: 'isEmpty', value: function isEmpty() { return this.entries.isEmpty(); } }, { key: 'forEachFile', value: function forEachFile(callback) { this.entries.forEachFile(callback); } }, { key: 'forEachDirectory', value: function forEachDirectory(callback) { this.entries.forEachDirectory(callback); } }, { key: 'someDirectory', value: function someDirectory(callback) { this.entries.someDirectory(callback); } }, { key: 'getDraggableEntryPath', value: function getDraggableEntryPath(draggableEntry) { var draggableEntryPath = void 0; var name = this.getName(); if (draggableEntry === this) { draggableEntryPath = name; /// } else { draggableEntryPath = this.entries.getDraggableEntryPath(draggableEntry); if (draggableEntryPath !== null) { draggableEntryPath = name + '/' + draggableEntryPath; } } return draggableEntryPath; } }, { key: 'topmostDirectory', value: function topmostDirectory(path, addIfNecessary) { var topmostDirectory = void 0; var topmostDirectoryName = util.topmostDirectoryName(path); if (topmostDirectoryName === null) { topmostDirectory = null; } else { if (addIfNecessary) { var entriesDirectory = this.entries.hasDirectory(topmostDirectoryName); if (!entriesDirectory) { var collapsed = true, explorer = this.getExplorer(); this.entries.addDirectory(topmostDirectoryName, explorer, collapsed); } } topmostDirectory = this.entries.retrieveDirectory(topmostDirectoryName); } return topmostDirectory; } }, { key: 'getMarkedDirectory', value: function getMarkedDirectory() { var markedDirectory = this.entries.getMarkedDirectory(); if (markedDirectory === null) { var marked = this.isMarked(); if (marked) { markedDirectory = this; } } return markedDirectory; } }, { key: 'getDirectoryOverlappingDraggableEntry', value: function getDirectoryOverlappingDraggableEntry(draggableEntry) { var directoryOverlappingDraggableEntry = null; var overlappingDraggableEntry = this.isOverlappingDraggableEntry(draggableEntry); if (overlappingDraggableEntry) { directoryOverlappingDraggableEntry = this.entries.getDirectoryOverlappingDraggableEntry(draggableEntry); if (directoryOverlappingDraggableEntry === null) { directoryOverlappingDraggableEntry = this; } } return directoryOverlappingDraggableEntry; } }, { key: 'toggleButtonUpdateHandler', value: function toggleButtonUpdateHandler(collapsed) { collapsed ? this.addClass('collapsed') : this.removeClass('collapsed'); } }, { key: 'doubleClickHandler', value: function doubleClickHandler() { this.toggleButton.toggle(); } }], [{ key: 'fromProperties', value: function fromProperties(Class, properties) { if (arguments.length === 1) { properties = Class; Class = Directory; } var _properties = properties, name = _properties.name, explorer = _properties.explorer, collapsed = _properties.collapsed; return DraggableEntry.fromProperties(Class, properties, name, explorer, collapsed); } }]); return Directory; }(DraggableEntry); Object.assign(Directory, { ignoredAttributes: ['name', 'explorer', 'collapsed'] }); module.exports = Directory; },{"../../util":17,"../draggableEntry":4,"../entries":8,"../entry":9,"../toggleButton":14,"easyui":18}],6:[function(require,module,exports){ 'use strict'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _get = function get(object, property, receiver) { if (object === null) object = Function.prototype; var desc = Object.getOwnPropertyDescriptor(object, property); if (desc === undefined) { var parent = Object.getPrototypeOf(object); if (parent === null) { return undefined; } else { return get(parent, property, receiver); } } else if ("value" in desc) { return desc.value; } else { var getter = desc.get; if (getter === undefined) { return undefined; } return getter.call(receiver); } }; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var util = require('../../../util'), options = require('../../../options'), Directory = require('../directory'); var RootDirectory = function (_Directory) { _inherits(RootDirectory, _Directory); function RootDirectory() { _classCallCheck(this, RootDirectory); return _possibleConstructorReturn(this, (RootDirectory.__proto__ || Object.getPrototypeOf(RootDirectory)).apply(this, arguments)); } _createClass(RootDirectory, [{ key: 'isRootDirectory', value: function isRootDirectory() { return true; } }, { key: 'getDirectoryOverlappingDraggableEntry', value: function getDirectoryOverlappingDraggableEntry(draggableEntry) { var directoryOverlappingEntry = void 0; var explorer = this.getExplorer(), noDraggingIntoSubdirectories = explorer.hasOption(options.NO_DRAGGING_INTO_SUB_DIRECTORIES); if (noDraggingIntoSubdirectories) { var overlappingEntry = this.isOverlappingDraggableEntry(draggableEntry); directoryOverlappingEntry = overlappingEntry ? this : null; } else { directoryOverlappingEntry = _get(RootDirectory.prototype.__proto__ || Object.getPrototypeOf(RootDi