dockview-core
Version:
Zero dependency layout manager supporting tabs, groups, grids and splitviews for vanilla TypeScript
121 lines (120 loc) • 6.57 kB
JavaScript
;
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.VoidContainer = void 0;
var dataTransfer_1 = require("../../../dnd/dataTransfer");
var backend_1 = require("../../../dnd/backend");
var events_1 = require("../../../events");
var lifecycle_1 = require("../../../lifecycle");
var dom_1 = require("../../../dom");
var groupDragSource_1 = require("./groupDragSource");
var VoidContainer = /** @class */ (function (_super) {
__extends(VoidContainer, _super);
function VoidContainer(accessor, group) {
var _a, _b, _c, _d, _e, _f, _g;
var _this = _super.call(this) || this;
_this.accessor = accessor;
_this.group = group;
_this._onDrop = new events_1.Emitter();
_this.onDrop = _this._onDrop.event;
_this._onDragStart = new events_1.Emitter();
_this.onDragStart = _this._onDragStart.event;
_this._element = document.createElement('div');
_this._element.className = 'dv-void-container';
_this.addDisposables(_this._onDrop, _this._onDragStart, (0, events_1.addDisposableListener)(_this._element, 'pointerdown', function () {
_this.accessor.doSetGroupActive(_this.group);
}),
// Shift+pointerdown marks the event so the group's overlay
// drag (move-by-floating) sees it was consumed and doesn't
// fire alongside the HTML5 drag. quasiPreventDefault sets the
// marker without calling preventDefault — that would also
// block dragstart, which we need to fire.
(0, events_1.addDisposableListener)(_this._element, 'pointerdown', function (e) {
if (e.shiftKey) {
(0, dom_1.quasiPreventDefault)(e);
}
}, true));
// The drag-source (move-the-float disambiguation, redock ghost and
// group-level PanelTransfer) is shared with the floating title bar.
_this.dragSource = new groupDragSource_1.GroupDragSource({
element: _this._element,
accessor: _this.accessor,
group: _this.group,
// The void container is the float's move handle only when there is
// no dedicated title bar. When a title bar moves the float (the
// overlay is `.dv-resize-container-with-titlebar`), the void
// container redocks with a plain drag, like a group in the grid.
isFloatingMoveHandle: function () {
return !_this._element.closest('.dv-resize-container-with-titlebar');
},
});
var canDisplayOverlay = function (event, position) {
if (_this.group.api.locked) {
// Dropping on the void/header space adds the panel
// to this group, which `locked` is meant to prevent
// (both `true` and `'no-drop-target'`).
return false;
}
var data = (0, dataTransfer_1.getPanelData)();
if (data && _this.accessor.id === data.viewId) {
return true;
}
return group.model.canDisplayOverlay(event, position, 'header_space');
};
_this.dropTarget = backend_1.html5Backend.createDropTarget(_this._element, {
acceptedTargetZones: ['center'],
canDisplayOverlay: canDisplayOverlay,
getOverrideTarget: function () { var _a; return (_a = group.model.dropTargetContainer) === null || _a === void 0 ? void 0 : _a.model; },
overlayModel: (_b = (_a = _this.accessor).resolveDropOverlayModel) === null || _b === void 0 ? void 0 : _b.call(_a, 'header_space', _this.group),
});
_this.pointerDropTarget = backend_1.pointerBackend.createDropTarget(_this._element, {
acceptedTargetZones: ['center'],
canDisplayOverlay: canDisplayOverlay,
getOverrideTarget: function () { var _a; return (_a = group.model.dropTargetContainer) === null || _a === void 0 ? void 0 : _a.model; },
overlayModel: (_d = (_c = _this.accessor).resolveDropOverlayModel) === null || _d === void 0 ? void 0 : _d.call(_c, 'header_space', _this.group),
});
_this.onWillShowOverlay = events_1.Event.any(_this.dropTarget.onWillShowOverlay, _this.pointerDropTarget.onWillShowOverlay);
_this.addDisposables(_this.dragSource, _this.dragSource.onDragStart(function (event) {
_this._onDragStart.fire(event);
}), _this.dropTarget.onDrop(function (event) {
_this._onDrop.fire(event);
}), _this.pointerDropTarget.onDrop(function (event) {
_this._onDrop.fire(event);
}), _this.dropTarget, _this.pointerDropTarget,
// Re-apply the app-supplied overlay model when options change.
// `{}` resets to the built-in default (all fields optional).
(_g = (_f = (_e = _this.accessor).onDidOptionsChange) === null || _f === void 0 ? void 0 : _f.call(_e, function () {
var _a, _b, _c;
var model = (_c = (_b = (_a = _this.accessor).resolveDropOverlayModel) === null || _b === void 0 ? void 0 : _b.call(_a, 'header_space', _this.group)) !== null && _c !== void 0 ? _c : {};
_this.dropTarget.setOverlayModel(model);
_this.pointerDropTarget.setOverlayModel(model);
})) !== null && _g !== void 0 ? _g : lifecycle_1.Disposable.NONE);
return _this;
}
Object.defineProperty(VoidContainer.prototype, "element", {
get: function () {
return this._element;
},
enumerable: false,
configurable: true
});
VoidContainer.prototype.updateDragAndDropState = function () {
this.dragSource.updateDragAndDropState();
};
return VoidContainer;
}(lifecycle_1.CompositeDisposable));
exports.VoidContainer = VoidContainer;