dockview-core 6.3.0 → 6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/cjs/dnd/backend.d.ts +70 -0
- package/dist/cjs/dnd/backend.js +171 -0
- package/dist/cjs/dnd/dropOverlay.d.ts +20 -0
- package/dist/cjs/dnd/dropOverlay.js +197 -0
- package/dist/cjs/dnd/droptarget.d.ts +20 -6
- package/dist/cjs/dnd/droptarget.js +14 -208
- package/dist/cjs/dnd/pointer/index.d.ts +11 -0
- package/dist/cjs/dnd/pointer/index.js +13 -0
- package/dist/cjs/dnd/pointer/longPress.d.ts +32 -0
- package/dist/cjs/dnd/pointer/longPress.js +151 -0
- package/dist/cjs/dnd/pointer/pointerDragController.d.ts +60 -0
- package/dist/cjs/dnd/pointer/pointerDragController.js +241 -0
- package/dist/cjs/dnd/pointer/pointerDragSource.d.ts +61 -0
- package/dist/cjs/dnd/pointer/pointerDragSource.js +195 -0
- package/dist/cjs/dnd/pointer/pointerDropTarget.d.ts +39 -0
- package/dist/cjs/dnd/pointer/pointerDropTarget.js +198 -0
- package/dist/cjs/dnd/pointer/pointerGhost.d.ts +30 -0
- package/dist/cjs/dnd/pointer/pointerGhost.js +44 -0
- package/dist/cjs/dnd/pointer/types.d.ts +16 -0
- package/dist/cjs/dnd/pointer/types.js +2 -0
- package/dist/cjs/dockview/components/panel/content.d.ts +3 -1
- package/dist/cjs/dockview/components/panel/content.js +33 -16
- package/dist/cjs/dockview/components/popupService.js +34 -0
- package/dist/cjs/dockview/components/tab/tab.d.ts +11 -3
- package/dist/cjs/dockview/components/tab/tab.js +151 -117
- package/dist/cjs/dockview/components/titlebar/tabGroupChip.d.ts +9 -2
- package/dist/cjs/dockview/components/titlebar/tabGroupChip.js +15 -6
- package/dist/cjs/dockview/components/titlebar/tabGroups.d.ts +33 -5
- package/dist/cjs/dockview/components/titlebar/tabGroups.js +231 -40
- package/dist/cjs/dockview/components/titlebar/tabs.d.ts +38 -1
- package/dist/cjs/dockview/components/titlebar/tabs.js +372 -251
- package/dist/cjs/dockview/components/titlebar/tabsContainer.d.ts +5 -3
- package/dist/cjs/dockview/components/titlebar/voidContainer.d.ts +6 -2
- package/dist/cjs/dockview/components/titlebar/voidContainer.js +189 -27
- package/dist/cjs/dockview/contextMenu.js +19 -4
- package/dist/cjs/dockview/dndCapabilities.d.ts +19 -0
- package/dist/cjs/dockview/dndCapabilities.js +39 -0
- package/dist/cjs/dockview/dockviewComponent.d.ts +1 -0
- package/dist/cjs/dockview/dockviewComponent.js +54 -33
- package/dist/cjs/dockview/dockviewGroupPanelModel.d.ts +9 -5
- package/dist/cjs/dockview/dockviewGroupPanelModel.js +25 -11
- package/dist/cjs/dockview/events.d.ts +2 -1
- package/dist/cjs/dockview/events.js +1 -0
- package/dist/cjs/dockview/options.d.ts +18 -3
- package/dist/cjs/dockview/options.js +1 -0
- package/dist/cjs/dom.js +7 -3
- package/dist/cjs/overlay/overlay.d.ts +12 -0
- package/dist/cjs/overlay/overlay.js +84 -16
- package/dist/cjs/paneview/draggablePaneviewPanel.d.ts +3 -1
- package/dist/cjs/paneview/draggablePaneviewPanel.js +27 -26
- package/dist/cjs/paneview/options.d.ts +4 -3
- package/dist/dockview-core.js +2199 -834
- package/dist/dockview-core.min.js +2 -2
- package/dist/dockview-core.min.js.map +1 -1
- package/dist/dockview-core.min.noStyle.js +2 -2
- package/dist/dockview-core.min.noStyle.js.map +1 -1
- package/dist/dockview-core.noStyle.js +2202 -837
- package/dist/esm/dnd/backend.d.ts +70 -0
- package/dist/esm/dnd/backend.js +148 -0
- package/dist/esm/dnd/dropOverlay.d.ts +20 -0
- package/dist/esm/dnd/dropOverlay.js +192 -0
- package/dist/esm/dnd/droptarget.d.ts +20 -6
- package/dist/esm/dnd/droptarget.js +16 -210
- package/dist/esm/dnd/pointer/index.d.ts +11 -0
- package/dist/esm/dnd/pointer/index.js +5 -0
- package/dist/esm/dnd/pointer/longPress.d.ts +32 -0
- package/dist/esm/dnd/pointer/longPress.js +127 -0
- package/dist/esm/dnd/pointer/pointerDragController.d.ts +60 -0
- package/dist/esm/dnd/pointer/pointerDragController.js +191 -0
- package/dist/esm/dnd/pointer/pointerDragSource.d.ts +61 -0
- package/dist/esm/dnd/pointer/pointerDragSource.js +171 -0
- package/dist/esm/dnd/pointer/pointerDropTarget.d.ts +39 -0
- package/dist/esm/dnd/pointer/pointerDropTarget.js +168 -0
- package/dist/esm/dnd/pointer/pointerGhost.d.ts +30 -0
- package/dist/esm/dnd/pointer/pointerGhost.js +39 -0
- package/dist/esm/dnd/pointer/types.d.ts +16 -0
- package/dist/esm/dnd/pointer/types.js +1 -0
- package/dist/esm/dockview/components/panel/content.d.ts +3 -1
- package/dist/esm/dockview/components/panel/content.js +33 -16
- package/dist/esm/dockview/components/popupService.js +34 -0
- package/dist/esm/dockview/components/tab/tab.d.ts +11 -3
- package/dist/esm/dockview/components/tab/tab.js +139 -114
- package/dist/esm/dockview/components/titlebar/tabGroupChip.d.ts +9 -2
- package/dist/esm/dockview/components/titlebar/tabGroupChip.js +15 -6
- package/dist/esm/dockview/components/titlebar/tabGroups.d.ts +33 -5
- package/dist/esm/dockview/components/titlebar/tabGroups.js +177 -12
- package/dist/esm/dockview/components/titlebar/tabs.d.ts +38 -1
- package/dist/esm/dockview/components/titlebar/tabs.js +348 -227
- package/dist/esm/dockview/components/titlebar/tabsContainer.d.ts +5 -3
- package/dist/esm/dockview/components/titlebar/voidContainer.d.ts +6 -2
- package/dist/esm/dockview/components/titlebar/voidContainer.js +179 -31
- package/dist/esm/dockview/contextMenu.js +19 -4
- package/dist/esm/dockview/dndCapabilities.d.ts +19 -0
- package/dist/esm/dockview/dndCapabilities.js +36 -0
- package/dist/esm/dockview/dockviewComponent.d.ts +1 -0
- package/dist/esm/dockview/dockviewComponent.js +55 -34
- package/dist/esm/dockview/dockviewGroupPanelModel.d.ts +9 -5
- package/dist/esm/dockview/dockviewGroupPanelModel.js +24 -11
- package/dist/esm/dockview/events.d.ts +2 -1
- package/dist/esm/dockview/events.js +1 -0
- package/dist/esm/dockview/options.d.ts +18 -3
- package/dist/esm/dockview/options.js +1 -0
- package/dist/esm/dom.js +7 -3
- package/dist/esm/overlay/overlay.d.ts +12 -0
- package/dist/esm/overlay/overlay.js +85 -17
- package/dist/esm/paneview/draggablePaneviewPanel.d.ts +3 -1
- package/dist/esm/paneview/draggablePaneviewPanel.js +26 -20
- package/dist/esm/paneview/options.d.ts +4 -3
- package/dist/package/main.cjs.js +2202 -837
- package/dist/package/main.cjs.min.js +2 -2
- package/dist/package/main.esm.min.mjs +2 -2
- package/dist/package/main.esm.mjs +2202 -837
- package/dist/styles/dockview.css +117 -1
- package/package.json +3 -1
- package/dist/cjs/dnd/abstractDragHandler.d.ts +0 -14
- package/dist/cjs/dnd/abstractDragHandler.js +0 -86
- package/dist/cjs/dnd/groupDragHandler.d.ts +0 -12
- package/dist/cjs/dnd/groupDragHandler.js +0 -104
- package/dist/esm/dnd/abstractDragHandler.d.ts +0 -14
- package/dist/esm/dnd/abstractDragHandler.js +0 -63
- package/dist/esm/dnd/groupDragHandler.d.ts +0 -12
- package/dist/esm/dnd/groupDragHandler.js +0 -81
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { disableIframePointEvents } from '../../dom';
|
|
2
|
+
import { addDisposableListener, Emitter } from '../../events';
|
|
3
|
+
import { CompositeDisposable } from '../../lifecycle';
|
|
4
|
+
/**
|
|
5
|
+
* Singleton — only one pointer-driven drag active at a time.
|
|
6
|
+
*
|
|
7
|
+
* State is shared across every Dockview instance on the page. Targets
|
|
8
|
+
* from instance B receive hit-tests from drags originating in instance A;
|
|
9
|
+
* that's intentional for cross-instance drops since `LocalSelectionTransfer`
|
|
10
|
+
* is also process-wide. The corollary is that every Tabs subscriber to
|
|
11
|
+
* `onDragMove` fires for every pointer drag globally — each subscriber
|
|
12
|
+
* hit-tests against its own DOM, so this is O(N) per pointermove where N
|
|
13
|
+
* is the number of registered listeners across all instances.
|
|
14
|
+
*/
|
|
15
|
+
export class PointerDragController extends CompositeDisposable {
|
|
16
|
+
static getInstance() {
|
|
17
|
+
if (!PointerDragController._instance) {
|
|
18
|
+
PointerDragController._instance = new PointerDragController();
|
|
19
|
+
}
|
|
20
|
+
return PointerDragController._instance;
|
|
21
|
+
}
|
|
22
|
+
constructor() {
|
|
23
|
+
super();
|
|
24
|
+
this._targets = new Set();
|
|
25
|
+
/** Kept in sync with `_targets` so hit-testing is allocation-free. */
|
|
26
|
+
this._targetByElement = new Map();
|
|
27
|
+
this._onDragStart = new Emitter();
|
|
28
|
+
this.onDragStart = this._onDragStart.event;
|
|
29
|
+
this._onDragMove = new Emitter();
|
|
30
|
+
this.onDragMove = this._onDragMove.event;
|
|
31
|
+
this._onDragEnd = new Emitter();
|
|
32
|
+
this.onDragEnd = this._onDragEnd.event;
|
|
33
|
+
this.addDisposables(this._onDragStart, this._onDragMove, this._onDragEnd);
|
|
34
|
+
}
|
|
35
|
+
get active() {
|
|
36
|
+
return this._active;
|
|
37
|
+
}
|
|
38
|
+
registerTarget(target) {
|
|
39
|
+
this._targets.add(target);
|
|
40
|
+
this._targetByElement.set(target.element, target);
|
|
41
|
+
return {
|
|
42
|
+
dispose: () => {
|
|
43
|
+
this._targets.delete(target);
|
|
44
|
+
if (this._targetByElement.get(target.element) === target) {
|
|
45
|
+
this._targetByElement.delete(target.element);
|
|
46
|
+
}
|
|
47
|
+
if (this._currentTarget === target) {
|
|
48
|
+
this._currentTarget = undefined;
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
beginDrag(args) {
|
|
54
|
+
var _a, _b, _c;
|
|
55
|
+
if (this._active) {
|
|
56
|
+
this.cancel();
|
|
57
|
+
}
|
|
58
|
+
const { pointerEvent, source } = args;
|
|
59
|
+
// Call `getData()` before mutating controller state — a throw
|
|
60
|
+
// here would otherwise leave `_active` populated with no window
|
|
61
|
+
// listeners installed, blocking every subsequent drag.
|
|
62
|
+
const dataDisposable = args.getData();
|
|
63
|
+
this._active = {
|
|
64
|
+
pointerId: pointerEvent.pointerId,
|
|
65
|
+
startX: pointerEvent.clientX,
|
|
66
|
+
startY: pointerEvent.clientY,
|
|
67
|
+
source,
|
|
68
|
+
};
|
|
69
|
+
this._onDragMoveCallback = args.onDragMove;
|
|
70
|
+
this._onDragEndCallback = args.onDragEnd;
|
|
71
|
+
this._dataDisposable = dataDisposable;
|
|
72
|
+
this._ghost = args.ghost;
|
|
73
|
+
// Iframes capture pointermove once the cursor crosses into them,
|
|
74
|
+
// which would freeze the drag from the parent window's POV.
|
|
75
|
+
this._iframeShield = disableIframePointEvents((_a = source.ownerDocument) !== null && _a !== void 0 ? _a : document);
|
|
76
|
+
const startEvent = {
|
|
77
|
+
clientX: pointerEvent.clientX,
|
|
78
|
+
clientY: pointerEvent.clientY,
|
|
79
|
+
pointerEvent,
|
|
80
|
+
};
|
|
81
|
+
this._onDragStart.fire(startEvent);
|
|
82
|
+
// Source's owning window — popout drags fire on their own window,
|
|
83
|
+
// not the main one.
|
|
84
|
+
const targetWindow = (_c = (_b = source.ownerDocument) === null || _b === void 0 ? void 0 : _b.defaultView) !== null && _c !== void 0 ? _c : window;
|
|
85
|
+
this._moveListener = addDisposableListener(targetWindow, 'pointermove', (e) => {
|
|
86
|
+
if (!this._active || e.pointerId !== this._active.pointerId) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
this._handleMove(e);
|
|
90
|
+
});
|
|
91
|
+
this._upListener = addDisposableListener(targetWindow, 'pointerup', (e) => {
|
|
92
|
+
if (!this._active || e.pointerId !== this._active.pointerId) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
this._handleEnd(e, true);
|
|
96
|
+
});
|
|
97
|
+
this._cancelListener = addDisposableListener(targetWindow, 'pointercancel', (e) => {
|
|
98
|
+
if (!this._active || e.pointerId !== this._active.pointerId) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this._handleEnd(e, false);
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
cancel() {
|
|
105
|
+
var _a, _b;
|
|
106
|
+
if (!this._active) {
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
(_a = this._currentTarget) === null || _a === void 0 ? void 0 : _a.handleDragLeave();
|
|
110
|
+
this._teardown();
|
|
111
|
+
(_b = this._dataDisposable) === null || _b === void 0 ? void 0 : _b.dispose();
|
|
112
|
+
this._dataDisposable = undefined;
|
|
113
|
+
}
|
|
114
|
+
_findTargetUnder(x, y) {
|
|
115
|
+
var _a, _b;
|
|
116
|
+
// `elementsFromPoint` is topmost-first; walk up to find the closest
|
|
117
|
+
// registered ancestor (so a tab beats the layout-root that contains it).
|
|
118
|
+
// Use the source's owning document so popout drags hit their own targets.
|
|
119
|
+
const sourceDoc = (_b = (_a = this._active) === null || _a === void 0 ? void 0 : _a.source.ownerDocument) !== null && _b !== void 0 ? _b : document;
|
|
120
|
+
const elements = sourceDoc.elementsFromPoint(x, y);
|
|
121
|
+
for (const el of elements) {
|
|
122
|
+
let current = el;
|
|
123
|
+
while (current) {
|
|
124
|
+
const target = this._targetByElement.get(current);
|
|
125
|
+
if (target) {
|
|
126
|
+
return target;
|
|
127
|
+
}
|
|
128
|
+
current = current.parentElement;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return undefined;
|
|
132
|
+
}
|
|
133
|
+
_handleMove(e) {
|
|
134
|
+
var _a, _b, _c;
|
|
135
|
+
(_a = this._ghost) === null || _a === void 0 ? void 0 : _a.update(e.clientX, e.clientY);
|
|
136
|
+
const dragEvent = {
|
|
137
|
+
clientX: e.clientX,
|
|
138
|
+
clientY: e.clientY,
|
|
139
|
+
pointerEvent: e,
|
|
140
|
+
};
|
|
141
|
+
const newTarget = this._findTargetUnder(e.clientX, e.clientY);
|
|
142
|
+
if (newTarget !== this._currentTarget) {
|
|
143
|
+
(_b = this._currentTarget) === null || _b === void 0 ? void 0 : _b.handleDragLeave();
|
|
144
|
+
this._currentTarget = newTarget;
|
|
145
|
+
}
|
|
146
|
+
if (newTarget) {
|
|
147
|
+
newTarget.handleDragOver(dragEvent);
|
|
148
|
+
}
|
|
149
|
+
(_c = this._onDragMoveCallback) === null || _c === void 0 ? void 0 : _c.call(this, dragEvent);
|
|
150
|
+
this._onDragMove.fire(dragEvent);
|
|
151
|
+
}
|
|
152
|
+
_handleEnd(e, dropped) {
|
|
153
|
+
var _a;
|
|
154
|
+
const dragEvent = {
|
|
155
|
+
clientX: e.clientX,
|
|
156
|
+
clientY: e.clientY,
|
|
157
|
+
pointerEvent: e,
|
|
158
|
+
};
|
|
159
|
+
if (dropped && this._currentTarget) {
|
|
160
|
+
this._currentTarget.handleDrop(dragEvent);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
(_a = this._currentTarget) === null || _a === void 0 ? void 0 : _a.handleDragLeave();
|
|
164
|
+
}
|
|
165
|
+
const onEnd = this._onDragEndCallback;
|
|
166
|
+
const dataDisposable = this._dataDisposable;
|
|
167
|
+
this._teardown();
|
|
168
|
+
this._dataDisposable = undefined;
|
|
169
|
+
// Defer disposal so drop handlers can still read the transfer data.
|
|
170
|
+
setTimeout(() => dataDisposable === null || dataDisposable === void 0 ? void 0 : dataDisposable.dispose(), 0);
|
|
171
|
+
onEnd === null || onEnd === void 0 ? void 0 : onEnd(dragEvent, dropped);
|
|
172
|
+
this._onDragEnd.fire(dragEvent);
|
|
173
|
+
}
|
|
174
|
+
_teardown() {
|
|
175
|
+
var _a, _b, _c, _d, _e;
|
|
176
|
+
this._currentTarget = undefined;
|
|
177
|
+
this._active = undefined;
|
|
178
|
+
this._onDragMoveCallback = undefined;
|
|
179
|
+
this._onDragEndCallback = undefined;
|
|
180
|
+
(_a = this._ghost) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
181
|
+
this._ghost = undefined;
|
|
182
|
+
(_b = this._iframeShield) === null || _b === void 0 ? void 0 : _b.release();
|
|
183
|
+
this._iframeShield = undefined;
|
|
184
|
+
(_c = this._moveListener) === null || _c === void 0 ? void 0 : _c.dispose();
|
|
185
|
+
(_d = this._upListener) === null || _d === void 0 ? void 0 : _d.dispose();
|
|
186
|
+
(_e = this._cancelListener) === null || _e === void 0 ? void 0 : _e.dispose();
|
|
187
|
+
this._moveListener = undefined;
|
|
188
|
+
this._upListener = undefined;
|
|
189
|
+
this._cancelListener = undefined;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CompositeDisposable, IDisposable } from '../../lifecycle';
|
|
2
|
+
import { PointerGhost } from './pointerGhost';
|
|
3
|
+
import { PointerDragEvent } from './types';
|
|
4
|
+
export interface PointerDragSourceOptions {
|
|
5
|
+
/** Populate transfer data; returned disposer clears it on drag end. */
|
|
6
|
+
getData: (event: PointerEvent) => IDisposable;
|
|
7
|
+
onDragStart?: (event: PointerEvent) => void;
|
|
8
|
+
onDragMove?: (event: PointerDragEvent) => void;
|
|
9
|
+
onDragEnd?: (event: PointerDragEvent, dropped: boolean) => void;
|
|
10
|
+
/** Cancels the drag at pointerdown time. */
|
|
11
|
+
isCancelled?: (event: PointerEvent) => boolean;
|
|
12
|
+
/** Default 5px. Touch pointers also need `touchInitiationDelay` to elapse. */
|
|
13
|
+
threshold?: number;
|
|
14
|
+
/**
|
|
15
|
+
* Touch-only long-press; movement past `pressTolerance` during the delay
|
|
16
|
+
* still arms the drag (any flick is drag intent). Default 250ms. May be
|
|
17
|
+
* a function so callers can vary it per gesture (e.g. require a longer
|
|
18
|
+
* hold for floating-group redock vs docked-group rearrange).
|
|
19
|
+
*/
|
|
20
|
+
touchInitiationDelay?: number | (() => number);
|
|
21
|
+
/** Default 8px. May be a function — see `touchInitiationDelay`. */
|
|
22
|
+
pressTolerance?: number | (() => number);
|
|
23
|
+
/** Default true: mouse defers to HTML5; pointer path handles touch / pen only. */
|
|
24
|
+
touchOnly?: boolean;
|
|
25
|
+
/** Follow-finger ghost factory; if omitted the user only sees drop overlays. */
|
|
26
|
+
createGhost?: (event: PointerEvent) => PointerGhost | undefined;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Pointer-event drag source. Waits for movement past `threshold` (and
|
|
30
|
+
* touch-only `touchInitiationDelay`) before promoting to a drag so taps
|
|
31
|
+
* pass through unaffected.
|
|
32
|
+
*/
|
|
33
|
+
export declare class PointerDragSource extends CompositeDisposable {
|
|
34
|
+
private readonly element;
|
|
35
|
+
private readonly options;
|
|
36
|
+
private _disabled;
|
|
37
|
+
private _touchOnly;
|
|
38
|
+
private _pendingPointerId;
|
|
39
|
+
private _pendingMoveListener;
|
|
40
|
+
private _pendingUpListener;
|
|
41
|
+
private _pendingCancelListener;
|
|
42
|
+
private _armTimer;
|
|
43
|
+
private _armed;
|
|
44
|
+
private _startX;
|
|
45
|
+
private _startY;
|
|
46
|
+
private _startEvent;
|
|
47
|
+
constructor(element: HTMLElement, options: PointerDragSourceOptions);
|
|
48
|
+
setDisabled(value: boolean): void;
|
|
49
|
+
/**
|
|
50
|
+
* `false` lets the pointer source also handle mouse pointers; used when
|
|
51
|
+
* `dndStrategy: 'pointer'` to drive every input type through this path.
|
|
52
|
+
*/
|
|
53
|
+
setTouchOnly(value: boolean): void;
|
|
54
|
+
private _shouldHandle;
|
|
55
|
+
private _onPointerDown;
|
|
56
|
+
/** For sibling gesture detectors (e.g. LongPressDetector) to dismiss a pending drag. */
|
|
57
|
+
cancelPending(): void;
|
|
58
|
+
private _cancelPending;
|
|
59
|
+
private _beginDrag;
|
|
60
|
+
dispose(): void;
|
|
61
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { addDisposableListener } from '../../events';
|
|
2
|
+
import { CompositeDisposable } from '../../lifecycle';
|
|
3
|
+
import { PointerDragController } from './pointerDragController';
|
|
4
|
+
const DEFAULT_THRESHOLD = 5;
|
|
5
|
+
const DEFAULT_TOUCH_INITIATION_DELAY = 250;
|
|
6
|
+
const DEFAULT_PRESS_TOLERANCE = 8;
|
|
7
|
+
/**
|
|
8
|
+
* Pointer-event drag source. Waits for movement past `threshold` (and
|
|
9
|
+
* touch-only `touchInitiationDelay`) before promoting to a drag so taps
|
|
10
|
+
* pass through unaffected.
|
|
11
|
+
*/
|
|
12
|
+
export class PointerDragSource extends CompositeDisposable {
|
|
13
|
+
constructor(element, options) {
|
|
14
|
+
var _a;
|
|
15
|
+
super();
|
|
16
|
+
this.element = element;
|
|
17
|
+
this.options = options;
|
|
18
|
+
this._disabled = false;
|
|
19
|
+
this._armed = false;
|
|
20
|
+
this._startX = 0;
|
|
21
|
+
this._startY = 0;
|
|
22
|
+
this._touchOnly = (_a = options.touchOnly) !== null && _a !== void 0 ? _a : true;
|
|
23
|
+
this.addDisposables(addDisposableListener(this.element, 'pointerdown', (e) => {
|
|
24
|
+
this._onPointerDown(e);
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
setDisabled(value) {
|
|
28
|
+
this._disabled = value;
|
|
29
|
+
if (value) {
|
|
30
|
+
this._cancelPending();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* `false` lets the pointer source also handle mouse pointers; used when
|
|
35
|
+
* `dndStrategy: 'pointer'` to drive every input type through this path.
|
|
36
|
+
*/
|
|
37
|
+
setTouchOnly(value) {
|
|
38
|
+
if (this._touchOnly === value) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
this._touchOnly = value;
|
|
42
|
+
// A pending mouse-tracked drag should be abandoned if we re-enable
|
|
43
|
+
// the touch-only filter mid-flight.
|
|
44
|
+
if (value) {
|
|
45
|
+
this._cancelPending();
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
_shouldHandle(event) {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
if (this._disabled) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
// Pointer-type filter runs before isCancelled — consumer state read
|
|
54
|
+
// by isCancelled may not be populated for events we'll never handle.
|
|
55
|
+
if (this._touchOnly &&
|
|
56
|
+
event.pointerType !== 'touch' &&
|
|
57
|
+
event.pointerType !== 'pen') {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
if ((_b = (_a = this.options).isCancelled) === null || _b === void 0 ? void 0 : _b.call(_a, event)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
_onPointerDown(event) {
|
|
66
|
+
var _a, _b, _c, _d, _e;
|
|
67
|
+
if (!this._shouldHandle(event)) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
// Defensive: a fresh pointerdown supersedes any in-flight tracking.
|
|
71
|
+
this._cancelPending();
|
|
72
|
+
this._pendingPointerId = event.pointerId;
|
|
73
|
+
this._startX = event.clientX;
|
|
74
|
+
this._startY = event.clientY;
|
|
75
|
+
this._startEvent = event;
|
|
76
|
+
const isTouch = event.pointerType === 'touch' || event.pointerType === 'pen';
|
|
77
|
+
// Touch waits a short window so a still finger can press-and-hold
|
|
78
|
+
// before drifting; once the timer fires, any motion past `threshold`
|
|
79
|
+
// begins the drag.
|
|
80
|
+
const initiationDelayOpt = this.options.touchInitiationDelay;
|
|
81
|
+
const initiationDelay = (_a = (typeof initiationDelayOpt === 'function'
|
|
82
|
+
? initiationDelayOpt()
|
|
83
|
+
: initiationDelayOpt)) !== null && _a !== void 0 ? _a : DEFAULT_TOUCH_INITIATION_DELAY;
|
|
84
|
+
this._armed = !isTouch || initiationDelay <= 0;
|
|
85
|
+
if (isTouch && initiationDelay > 0 && isFinite(initiationDelay)) {
|
|
86
|
+
this._armTimer = setTimeout(() => {
|
|
87
|
+
this._armTimer = undefined;
|
|
88
|
+
this._armed = true;
|
|
89
|
+
}, initiationDelay);
|
|
90
|
+
}
|
|
91
|
+
const threshold = (_b = this.options.threshold) !== null && _b !== void 0 ? _b : DEFAULT_THRESHOLD;
|
|
92
|
+
const pressToleranceOpt = this.options.pressTolerance;
|
|
93
|
+
const pressTolerance = (_c = (typeof pressToleranceOpt === 'function'
|
|
94
|
+
? pressToleranceOpt()
|
|
95
|
+
: pressToleranceOpt)) !== null && _c !== void 0 ? _c : DEFAULT_PRESS_TOLERANCE;
|
|
96
|
+
// Source's owning window — popout drags fire on their own window.
|
|
97
|
+
const targetWindow = (_e = (_d = this.element.ownerDocument) === null || _d === void 0 ? void 0 : _d.defaultView) !== null && _e !== void 0 ? _e : window;
|
|
98
|
+
this._pendingMoveListener = addDisposableListener(targetWindow, 'pointermove', (moveEvent) => {
|
|
99
|
+
if (moveEvent.pointerId !== this._pendingPointerId) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const dx = moveEvent.clientX - this._startX;
|
|
103
|
+
const dy = moveEvent.clientY - this._startY;
|
|
104
|
+
const distance = Math.hypot(dx, dy);
|
|
105
|
+
if (this._armed) {
|
|
106
|
+
if (distance >= threshold) {
|
|
107
|
+
this._beginDrag(moveEvent);
|
|
108
|
+
}
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
// Pre-arm phase: a flick past `pressTolerance` in any
|
|
112
|
+
// direction is treated as drag intent. The element opts out
|
|
113
|
+
// of native scroll via `touch-action: none`; container-level
|
|
114
|
+
// scrolling lives on the surrounding strip's empty space.
|
|
115
|
+
if (distance > pressTolerance) {
|
|
116
|
+
this._beginDrag(moveEvent);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
this._pendingUpListener = addDisposableListener(targetWindow, 'pointerup', (upEvent) => {
|
|
120
|
+
if (upEvent.pointerId !== this._pendingPointerId) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
this._cancelPending();
|
|
124
|
+
});
|
|
125
|
+
this._pendingCancelListener = addDisposableListener(targetWindow, 'pointercancel', (cancelEvent) => {
|
|
126
|
+
if (cancelEvent.pointerId !== this._pendingPointerId) {
|
|
127
|
+
return;
|
|
128
|
+
}
|
|
129
|
+
this._cancelPending();
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/** For sibling gesture detectors (e.g. LongPressDetector) to dismiss a pending drag. */
|
|
133
|
+
cancelPending() {
|
|
134
|
+
this._cancelPending();
|
|
135
|
+
}
|
|
136
|
+
_cancelPending() {
|
|
137
|
+
var _a, _b, _c;
|
|
138
|
+
this._pendingPointerId = undefined;
|
|
139
|
+
if (this._armTimer !== undefined) {
|
|
140
|
+
clearTimeout(this._armTimer);
|
|
141
|
+
this._armTimer = undefined;
|
|
142
|
+
}
|
|
143
|
+
this._armed = false;
|
|
144
|
+
(_a = this._pendingMoveListener) === null || _a === void 0 ? void 0 : _a.dispose();
|
|
145
|
+
(_b = this._pendingUpListener) === null || _b === void 0 ? void 0 : _b.dispose();
|
|
146
|
+
(_c = this._pendingCancelListener) === null || _c === void 0 ? void 0 : _c.dispose();
|
|
147
|
+
this._pendingMoveListener = undefined;
|
|
148
|
+
this._pendingUpListener = undefined;
|
|
149
|
+
this._pendingCancelListener = undefined;
|
|
150
|
+
this._startEvent = undefined;
|
|
151
|
+
}
|
|
152
|
+
_beginDrag(triggerEvent) {
|
|
153
|
+
var _a, _b, _c, _d, _e;
|
|
154
|
+
const startEvent = (_a = this._startEvent) !== null && _a !== void 0 ? _a : triggerEvent;
|
|
155
|
+
this._cancelPending();
|
|
156
|
+
(_c = (_b = this.options).onDragStart) === null || _c === void 0 ? void 0 : _c.call(_b, startEvent);
|
|
157
|
+
const ghost = (_e = (_d = this.options).createGhost) === null || _e === void 0 ? void 0 : _e.call(_d, startEvent);
|
|
158
|
+
PointerDragController.getInstance().beginDrag({
|
|
159
|
+
pointerEvent: triggerEvent,
|
|
160
|
+
source: this.element,
|
|
161
|
+
getData: () => this.options.getData(startEvent),
|
|
162
|
+
ghost,
|
|
163
|
+
onDragMove: this.options.onDragMove,
|
|
164
|
+
onDragEnd: this.options.onDragEnd,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
dispose() {
|
|
168
|
+
this._cancelPending();
|
|
169
|
+
super.dispose();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Event } from '../../events';
|
|
2
|
+
import { CompositeDisposable } from '../../lifecycle';
|
|
3
|
+
import { CanDisplayOverlay, DropTargetTargetModel, DroptargetEvent, DroptargetOverlayModel, IDropTarget, Position, WillShowOverlayEvent } from '../droptarget';
|
|
4
|
+
export interface PointerDropTargetOptions {
|
|
5
|
+
canDisplayOverlay: CanDisplayOverlay;
|
|
6
|
+
acceptedTargetZones: Position[];
|
|
7
|
+
overlayModel?: DroptargetOverlayModel;
|
|
8
|
+
/** Render into an external anchor container (floating groups, layout root). */
|
|
9
|
+
getOverrideTarget?: () => DropTargetTargetModel | undefined;
|
|
10
|
+
/** Outline element for positioning; falls back to the drop element. */
|
|
11
|
+
getOverlayOutline?: () => HTMLElement | null;
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
/** Pointer-driven counterpart to `Droptarget` with identical visual output. */
|
|
15
|
+
export declare class PointerDropTarget extends CompositeDisposable implements IDropTarget {
|
|
16
|
+
private readonly element;
|
|
17
|
+
private readonly options;
|
|
18
|
+
private _targetElement;
|
|
19
|
+
private _overlayElement;
|
|
20
|
+
private _state;
|
|
21
|
+
private _acceptedTargetZonesSet;
|
|
22
|
+
private readonly _onDrop;
|
|
23
|
+
readonly onDrop: Event<DroptargetEvent>;
|
|
24
|
+
private readonly _onWillShowOverlay;
|
|
25
|
+
readonly onWillShowOverlay: Event<WillShowOverlayEvent>;
|
|
26
|
+
private _disabled;
|
|
27
|
+
get disabled(): boolean;
|
|
28
|
+
set disabled(value: boolean);
|
|
29
|
+
get state(): Position | undefined;
|
|
30
|
+
constructor(element: HTMLElement, options: PointerDropTargetOptions);
|
|
31
|
+
setTargetZones(zones: Position[]): void;
|
|
32
|
+
setOverlayModel(model: DroptargetOverlayModel): void;
|
|
33
|
+
dispose(): void;
|
|
34
|
+
private _onDragOver;
|
|
35
|
+
private _onDragLeave;
|
|
36
|
+
private _onDropEvent;
|
|
37
|
+
private _calculateQuadrant;
|
|
38
|
+
private _removeOverlay;
|
|
39
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { Emitter } from '../../events';
|
|
2
|
+
import { CompositeDisposable } from '../../lifecycle';
|
|
3
|
+
import { createOverlayElements, renderAnchoredOverlay, renderInPlaceOverlay, } from '../dropOverlay';
|
|
4
|
+
import { calculateQuadrantAsPercentage, calculateQuadrantAsPixels, WillShowOverlayEvent, } from '../droptarget';
|
|
5
|
+
import { PointerDragController } from './pointerDragController';
|
|
6
|
+
const DEFAULT_ACTIVATION_SIZE = {
|
|
7
|
+
value: 20,
|
|
8
|
+
type: 'percentage',
|
|
9
|
+
};
|
|
10
|
+
/** Pointer-driven counterpart to `Droptarget` with identical visual output. */
|
|
11
|
+
export class PointerDropTarget extends CompositeDisposable {
|
|
12
|
+
get disabled() {
|
|
13
|
+
return this._disabled;
|
|
14
|
+
}
|
|
15
|
+
set disabled(value) {
|
|
16
|
+
this._disabled = value;
|
|
17
|
+
if (value) {
|
|
18
|
+
this._removeOverlay();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
get state() {
|
|
22
|
+
return this._state;
|
|
23
|
+
}
|
|
24
|
+
constructor(element, options) {
|
|
25
|
+
super();
|
|
26
|
+
this.element = element;
|
|
27
|
+
this.options = options;
|
|
28
|
+
this._onDrop = new Emitter();
|
|
29
|
+
this.onDrop = this._onDrop.event;
|
|
30
|
+
this._onWillShowOverlay = new Emitter();
|
|
31
|
+
this.onWillShowOverlay = this._onWillShowOverlay.event;
|
|
32
|
+
this._disabled = false;
|
|
33
|
+
this._acceptedTargetZonesSet = new Set(options.acceptedTargetZones);
|
|
34
|
+
const handle = {
|
|
35
|
+
element: this.element,
|
|
36
|
+
handleDragOver: (e) => this._onDragOver(e),
|
|
37
|
+
handleDragLeave: () => this._onDragLeave(),
|
|
38
|
+
handleDrop: (e) => this._onDropEvent(e),
|
|
39
|
+
};
|
|
40
|
+
this.addDisposables(this._onDrop, this._onWillShowOverlay, PointerDragController.getInstance().registerTarget(handle));
|
|
41
|
+
}
|
|
42
|
+
setTargetZones(zones) {
|
|
43
|
+
this._acceptedTargetZonesSet = new Set(zones);
|
|
44
|
+
}
|
|
45
|
+
setOverlayModel(model) {
|
|
46
|
+
this.options.overlayModel = model;
|
|
47
|
+
}
|
|
48
|
+
dispose() {
|
|
49
|
+
this._removeOverlay();
|
|
50
|
+
super.dispose();
|
|
51
|
+
}
|
|
52
|
+
_onDragOver(event) {
|
|
53
|
+
var _a, _b, _c, _d, _e;
|
|
54
|
+
if (this._disabled) {
|
|
55
|
+
this._removeOverlay();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const overrideTarget = (_b = (_a = this.options).getOverrideTarget) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
59
|
+
if (this._acceptedTargetZonesSet.size === 0) {
|
|
60
|
+
if (overrideTarget) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
this._removeOverlay();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const outlineEl = (_e = (_d = (_c = this.options).getOverlayOutline) === null || _d === void 0 ? void 0 : _d.call(_c)) !== null && _e !== void 0 ? _e : this.element;
|
|
67
|
+
const width = outlineEl.offsetWidth;
|
|
68
|
+
const height = outlineEl.offsetHeight;
|
|
69
|
+
if (width === 0 || height === 0) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const rect = outlineEl.getBoundingClientRect();
|
|
73
|
+
const x = event.clientX - rect.left;
|
|
74
|
+
const y = event.clientY - rect.top;
|
|
75
|
+
const quadrant = this._calculateQuadrant(x, y, width, height);
|
|
76
|
+
if (quadrant === null) {
|
|
77
|
+
this._removeOverlay();
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (!this.options.canDisplayOverlay(event.pointerEvent, quadrant)) {
|
|
81
|
+
if (overrideTarget) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
this._removeOverlay();
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
const willShow = new WillShowOverlayEvent({
|
|
88
|
+
nativeEvent: event.pointerEvent,
|
|
89
|
+
position: quadrant,
|
|
90
|
+
});
|
|
91
|
+
this._onWillShowOverlay.fire(willShow);
|
|
92
|
+
if (willShow.defaultPrevented) {
|
|
93
|
+
this._removeOverlay();
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (overrideTarget) {
|
|
97
|
+
renderAnchoredOverlay({
|
|
98
|
+
outlineElement: outlineEl,
|
|
99
|
+
targetModel: overrideTarget,
|
|
100
|
+
quadrant,
|
|
101
|
+
width,
|
|
102
|
+
height,
|
|
103
|
+
overlayModel: this.options.overlayModel,
|
|
104
|
+
className: this.options.className,
|
|
105
|
+
});
|
|
106
|
+
this._state = quadrant;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (!this._targetElement) {
|
|
110
|
+
const els = createOverlayElements();
|
|
111
|
+
this._targetElement = els.dropzone;
|
|
112
|
+
this._overlayElement = els.selection;
|
|
113
|
+
this._state = 'center';
|
|
114
|
+
this.element.classList.add('dv-drop-target');
|
|
115
|
+
this.element.append(this._targetElement);
|
|
116
|
+
}
|
|
117
|
+
if (this._overlayElement) {
|
|
118
|
+
renderInPlaceOverlay(this._overlayElement, quadrant, width, height, this.options.overlayModel);
|
|
119
|
+
}
|
|
120
|
+
this._state = quadrant;
|
|
121
|
+
}
|
|
122
|
+
_onDragLeave() {
|
|
123
|
+
var _a, _b;
|
|
124
|
+
const overrideTarget = (_b = (_a = this.options).getOverrideTarget) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
125
|
+
// Anchor target owns its own lifecycle; just clear our latched
|
|
126
|
+
// state so a subsequent pointerup doesn't fire a stale drop.
|
|
127
|
+
if (overrideTarget) {
|
|
128
|
+
this._state = undefined;
|
|
129
|
+
overrideTarget.clear();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
this._removeOverlay();
|
|
133
|
+
}
|
|
134
|
+
_onDropEvent(event) {
|
|
135
|
+
var _a, _b;
|
|
136
|
+
const state = this._state;
|
|
137
|
+
const overrideTarget = (_b = (_a = this.options).getOverrideTarget) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
138
|
+
this._removeOverlay();
|
|
139
|
+
overrideTarget === null || overrideTarget === void 0 ? void 0 : overrideTarget.clear();
|
|
140
|
+
if (state) {
|
|
141
|
+
this._onDrop.fire({
|
|
142
|
+
position: state,
|
|
143
|
+
nativeEvent: event.pointerEvent,
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
_calculateQuadrant(x, y, width, height) {
|
|
148
|
+
var _a, _b;
|
|
149
|
+
const activation = (_b = (_a = this.options.overlayModel) === null || _a === void 0 ? void 0 : _a.activationSize) !== null && _b !== void 0 ? _b : DEFAULT_ACTIVATION_SIZE;
|
|
150
|
+
if (activation.type === 'percentage') {
|
|
151
|
+
return calculateQuadrantAsPercentage(this._acceptedTargetZonesSet, x, y, width, height, activation.value);
|
|
152
|
+
}
|
|
153
|
+
return calculateQuadrantAsPixels(this._acceptedTargetZonesSet, x, y, width, height, activation.value);
|
|
154
|
+
}
|
|
155
|
+
_removeOverlay() {
|
|
156
|
+
var _a;
|
|
157
|
+
if (this._targetElement) {
|
|
158
|
+
this._state = undefined;
|
|
159
|
+
(_a = this._targetElement.parentElement) === null || _a === void 0 ? void 0 : _a.classList.remove('dv-drop-target');
|
|
160
|
+
this._targetElement.remove();
|
|
161
|
+
this._targetElement = undefined;
|
|
162
|
+
this._overlayElement = undefined;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
this._state = undefined;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { IDisposable } from '../../lifecycle';
|
|
2
|
+
export interface PointerGhostOptions {
|
|
3
|
+
element: HTMLElement;
|
|
4
|
+
initialX: number;
|
|
5
|
+
initialY: number;
|
|
6
|
+
/** Pointer position within the ghost; default top-left. */
|
|
7
|
+
offsetX?: number;
|
|
8
|
+
offsetY?: number;
|
|
9
|
+
/** Default 0.8. */
|
|
10
|
+
opacity?: number;
|
|
11
|
+
/**
|
|
12
|
+
* Source element whose `ownerDocument.body` hosts the ghost — pass for
|
|
13
|
+
* popout-window drags so the ghost renders in the popout's document.
|
|
14
|
+
*/
|
|
15
|
+
owner?: Element;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Floating clone that follows the pointer; appended to the owning
|
|
19
|
+
* document's body with `pointer-events: none` so it doesn't intercept
|
|
20
|
+
* hit-testing.
|
|
21
|
+
*/
|
|
22
|
+
export declare class PointerGhost implements IDisposable {
|
|
23
|
+
private readonly element;
|
|
24
|
+
private readonly offsetX;
|
|
25
|
+
private readonly offsetY;
|
|
26
|
+
private _disposed;
|
|
27
|
+
constructor(opts: PointerGhostOptions);
|
|
28
|
+
update(clientX: number, clientY: number): void;
|
|
29
|
+
dispose(): void;
|
|
30
|
+
}
|