UNPKG

dockview

Version:

Zero dependency layout manager supporting tabs, grids and splitviews with ReactJS support

143 lines 5.77 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.DragAndDrop = exports.DragAndDropObserver = void 0; var events_1 = require("../events"); var lifecycle_1 = require("../lifecycle"); var dataTransfer_1 = require("./dataTransfer"); var DragAndDropObserver = /** @class */ (function (_super) { __extends(DragAndDropObserver, _super); function DragAndDropObserver(element, callbacks) { var _this = _super.call(this) || this; _this.element = element; _this.callbacks = callbacks; // A helper to fix issues with repeated DRAG_ENTER / DRAG_LEAVE // calls see https://github.com/microsoft/vscode/issues/14470 // when the element has child elements where the events are fired // repeadedly. _this.counter = 0; _this.registerListeners(); return _this; } DragAndDropObserver.prototype.registerListeners = function () { var _this = this; this.addDisposables((0, events_1.addDisposableListener)(this.element, 'dragenter', function (e) { _this.counter++; _this.callbacks.onDragEnter(e); })); this.addDisposables((0, events_1.addDisposableListener)(this.element, 'dragover', function (e) { e.preventDefault(); // needed so that the drop event fires (https://stackoverflow.com/questions/21339924/drop-event-not-firing-in-chrome) if (_this.callbacks.onDragOver) { _this.callbacks.onDragOver(e); } })); this.addDisposables((0, events_1.addDisposableListener)(this.element, 'dragleave', function (e) { _this.counter--; if (_this.counter === 0) { _this.callbacks.onDragLeave(e); } })); this.addDisposables((0, events_1.addDisposableListener)(this.element, 'dragend', function (e) { _this.counter = 0; _this.callbacks.onDragEnd(e); })); this.addDisposables((0, events_1.addDisposableListener)(this.element, 'drop', function (e) { _this.counter = 0; _this.callbacks.onDrop(e); })); }; return DragAndDropObserver; }(lifecycle_1.CompositeDisposable)); exports.DragAndDropObserver = DragAndDropObserver; var DockviewIdentifier = /** @class */ (function () { function DockviewIdentifier(data) { this.data = data; // } return DockviewIdentifier; }()); var DragAndDrop = /** @class */ (function (_super) { __extends(DragAndDrop, _super); function DragAndDrop() { var _this = _super.call(this) || this; _this._onDragStart = new events_1.Emitter(); _this._onDragEnd = new events_1.Emitter(); _this.transferData = dataTransfer_1.LocalSelectionTransfer.getInstance(); _this.addDisposables(_this._onDragStart, _this._onDragEnd); return _this; } Object.defineProperty(DragAndDrop, "INSTANCE", { get: function () { if (!DragAndDrop._instance) { DragAndDrop._instance = new DragAndDrop(); } return DragAndDrop._instance; }, enumerable: false, configurable: true }); DragAndDrop.prototype.registerTarget = function (element, callbacks) { var disposables = new lifecycle_1.CompositeDisposable(); disposables.addDisposables(new DragAndDropObserver(element, { onDragEnd: function (e) { // no-op }, onDragEnter: function (e) { e.preventDefault(); }, onDragLeave: function (e) { // }, onDrop: function (e) { // }, onDragOver: function (e) { // }, })); return disposables; }; DragAndDrop.prototype.registerDraggable = function (element, draggedItemProvider, callbacks) { var _this = this; element.draggable = true; var disposables = new lifecycle_1.CompositeDisposable(); disposables.addDisposables((0, events_1.addDisposableListener)(element, 'dragstart', function (e) { _this._onDragStart.fire({ event: e }); })); disposables.addDisposables(new DragAndDropObserver(element, { onDragEnd: function (e) { // no-op }, onDragEnter: function (e) { // }, onDragLeave: function (e) { // }, onDrop: function (e) { // }, onDragOver: function (e) { // }, })); return disposables; }; return DragAndDrop; }(lifecycle_1.CompositeDisposable)); exports.DragAndDrop = DragAndDrop; //# sourceMappingURL=dnd.js.map