gridstack 7.3.0 → 8.0.1
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 +9 -2
- package/dist/dd-base-impl.d.ts +20 -20
- package/dist/dd-base-impl.js +31 -35
- package/dist/dd-base-impl.js.map +1 -1
- package/dist/dd-draggable.d.ts +28 -28
- package/dist/dd-draggable.js +336 -344
- package/dist/dd-draggable.js.map +1 -1
- package/dist/dd-droppable.d.ts +26 -26
- package/dist/dd-droppable.js +146 -148
- package/dist/dd-droppable.js.map +1 -1
- package/dist/dd-element.d.ts +27 -27
- package/dist/dd-element.js +90 -94
- package/dist/dd-element.js.map +1 -1
- package/dist/dd-gridstack.d.ts +34 -34
- package/dist/dd-gridstack.js +127 -124
- package/dist/dd-gridstack.js.map +1 -1
- package/dist/dd-manager.d.ts +22 -22
- package/dist/dd-manager.js +9 -13
- package/dist/dd-manager.js.map +1 -1
- package/dist/dd-resizable-handle.d.ts +14 -14
- package/dist/dd-resizable-handle.js +102 -105
- package/dist/dd-resizable-handle.js.map +1 -1
- package/dist/dd-resizable.d.ts +28 -28
- package/dist/dd-resizable.js +290 -296
- package/dist/dd-resizable.js.map +1 -1
- package/dist/dd-touch.d.ts +33 -33
- package/dist/dd-touch.js +173 -182
- package/dist/dd-touch.js.map +1 -1
- package/dist/es5/dd-base-impl.d.ts +20 -20
- package/dist/es5/dd-base-impl.js +40 -40
- package/dist/es5/dd-base-impl.js.map +1 -1
- package/dist/es5/dd-draggable.d.ts +28 -28
- package/dist/es5/dd-draggable.js +366 -367
- package/dist/es5/dd-draggable.js.map +1 -1
- package/dist/es5/dd-droppable.d.ts +26 -26
- package/dist/es5/dd-droppable.js +181 -179
- package/dist/es5/dd-droppable.js.map +1 -1
- package/dist/es5/dd-element.d.ts +27 -27
- package/dist/es5/dd-element.js +95 -95
- package/dist/es5/dd-element.js.map +1 -1
- package/dist/es5/dd-gridstack.d.ts +34 -34
- package/dist/es5/dd-gridstack.js +144 -144
- package/dist/es5/dd-gridstack.js.map +1 -1
- package/dist/es5/dd-manager.d.ts +22 -22
- package/dist/es5/dd-manager.js +16 -16
- package/dist/es5/dd-manager.js.map +1 -1
- package/dist/es5/dd-resizable-handle.d.ts +14 -14
- package/dist/es5/dd-resizable-handle.js +105 -106
- package/dist/es5/dd-resizable-handle.js.map +1 -1
- package/dist/es5/dd-resizable.d.ts +28 -28
- package/dist/es5/dd-resizable.js +317 -318
- package/dist/es5/dd-resizable.js.map +1 -1
- package/dist/es5/dd-touch.d.ts +33 -33
- package/dist/es5/dd-touch.js +185 -185
- package/dist/es5/dd-touch.js.map +1 -1
- package/dist/es5/gridstack-all.js +1 -1
- package/dist/es5/gridstack-all.js.LICENSE.txt +1 -1
- package/dist/es5/gridstack-all.js.map +1 -1
- package/dist/es5/gridstack-engine.d.ts +102 -102
- package/dist/es5/gridstack-engine.js +1000 -995
- package/dist/es5/gridstack-engine.js.map +1 -1
- package/dist/es5/gridstack-poly.js +1 -1
- package/dist/es5/gridstack.d.ts +392 -376
- package/dist/es5/gridstack.js +2254 -2233
- package/dist/es5/gridstack.js.map +1 -1
- package/dist/es5/types.d.ts +279 -284
- package/dist/es5/types.js +47 -35
- package/dist/es5/types.js.map +1 -1
- package/dist/es5/utils.d.ts +95 -93
- package/dist/es5/utils.js +600 -569
- package/dist/es5/utils.js.map +1 -1
- package/dist/gridstack-all.js +1 -1
- package/dist/gridstack-all.js.LICENSE.txt +1 -1
- package/dist/gridstack-all.js.map +1 -1
- package/dist/gridstack-engine.d.ts +102 -102
- package/dist/gridstack-engine.js +950 -954
- package/dist/gridstack-engine.js.map +1 -1
- package/dist/gridstack-extra.css +0 -390
- package/dist/gridstack-extra.min.css +1 -1
- package/dist/gridstack.css +19 -97
- package/dist/gridstack.d.ts +392 -376
- package/dist/gridstack.js +2155 -2157
- package/dist/gridstack.js.map +1 -1
- package/dist/gridstack.min.css +1 -1
- package/dist/ng/README.md +154 -0
- package/dist/ng/gridstack-item.component.d.ts +29 -0
- package/dist/ng/gridstack-item.component.js +65 -0
- package/dist/ng/gridstack-item.component.js.map +1 -0
- package/dist/ng/gridstack.component.d.ts +118 -0
- package/dist/ng/gridstack.component.js +245 -0
- package/dist/ng/gridstack.component.js.map +1 -0
- package/dist/src/gridstack-extra.scss +0 -2
- package/dist/src/gridstack.scss +14 -9
- package/dist/types.d.ts +279 -284
- package/dist/types.js +44 -35
- package/dist/types.js.map +1 -1
- package/dist/utils.d.ts +95 -93
- package/dist/utils.js +546 -527
- package/dist/utils.js.map +1 -1
- package/{dist → dist_save}/angular/gridstack-item.component.ts +5 -3
- package/{dist → dist_save}/angular/gridstack.component.ts +32 -18
- package/dist_save/dd-base-impl.d.ts +20 -0
- package/dist_save/dd-base-impl.js +36 -0
- package/dist_save/dd-base-impl.js.map +1 -0
- package/dist_save/dd-draggable.d.ts +28 -0
- package/dist_save/dd-draggable.js +343 -0
- package/dist_save/dd-draggable.js.map +1 -0
- package/dist_save/dd-droppable.d.ts +26 -0
- package/dist_save/dd-droppable.js +149 -0
- package/dist_save/dd-droppable.js.map +1 -0
- package/dist_save/dd-element.d.ts +27 -0
- package/dist_save/dd-element.js +95 -0
- package/dist_save/dd-element.js.map +1 -0
- package/dist_save/dd-gridstack.d.ts +34 -0
- package/dist_save/dd-gridstack.js +125 -0
- package/dist_save/dd-gridstack.js.map +1 -0
- package/dist_save/dd-manager.d.ts +22 -0
- package/dist_save/dd-manager.js +14 -0
- package/dist_save/dd-manager.js.map +1 -0
- package/dist_save/dd-resizable-handle.d.ts +14 -0
- package/dist_save/dd-resizable-handle.js +106 -0
- package/dist_save/dd-resizable-handle.js.map +1 -0
- package/dist_save/dd-resizable.d.ts +28 -0
- package/dist_save/dd-resizable.js +294 -0
- package/dist_save/dd-resizable.js.map +1 -0
- package/dist_save/dd-touch.d.ts +33 -0
- package/dist_save/dd-touch.js +183 -0
- package/dist_save/dd-touch.js.map +1 -0
- package/dist_save/es5/dd-base-impl.d.ts +20 -0
- package/dist_save/es5/dd-base-impl.js +41 -0
- package/dist_save/es5/dd-base-impl.js.map +1 -0
- package/dist_save/es5/dd-draggable.d.ts +28 -0
- package/dist_save/es5/dd-draggable.js +366 -0
- package/dist_save/es5/dd-draggable.js.map +1 -0
- package/dist_save/es5/dd-droppable.d.ts +26 -0
- package/dist_save/es5/dd-droppable.js +180 -0
- package/dist_save/es5/dd-droppable.js.map +1 -0
- package/dist_save/es5/dd-element.d.ts +27 -0
- package/dist_save/es5/dd-element.js +96 -0
- package/dist_save/es5/dd-element.js.map +1 -0
- package/dist_save/es5/dd-gridstack.d.ts +34 -0
- package/dist_save/es5/dd-gridstack.js +145 -0
- package/dist_save/es5/dd-gridstack.js.map +1 -0
- package/dist_save/es5/dd-manager.d.ts +22 -0
- package/dist_save/es5/dd-manager.js +17 -0
- package/dist_save/es5/dd-manager.js.map +1 -0
- package/dist_save/es5/dd-resizable-handle.d.ts +14 -0
- package/dist_save/es5/dd-resizable-handle.js +107 -0
- package/dist_save/es5/dd-resizable-handle.js.map +1 -0
- package/dist_save/es5/dd-resizable.d.ts +28 -0
- package/dist_save/es5/dd-resizable.js +316 -0
- package/dist_save/es5/dd-resizable.js.map +1 -0
- package/dist_save/es5/dd-touch.d.ts +33 -0
- package/dist_save/es5/dd-touch.js +186 -0
- package/dist_save/es5/dd-touch.js.map +1 -0
- package/dist_save/es5/gridstack-all.js +3 -0
- package/dist_save/es5/gridstack-all.js.LICENSE.txt +7 -0
- package/dist_save/es5/gridstack-all.js.map +1 -0
- package/dist_save/es5/gridstack-engine.d.ts +102 -0
- package/dist_save/es5/gridstack-engine.js +997 -0
- package/dist_save/es5/gridstack-engine.js.map +1 -0
- package/dist_save/es5/gridstack-poly.js +356 -0
- package/dist_save/es5/gridstack.d.ts +376 -0
- package/dist_save/es5/gridstack.js +2238 -0
- package/dist_save/es5/gridstack.js.map +1 -0
- package/dist_save/es5/types.d.ts +284 -0
- package/dist_save/es5/types.js +36 -0
- package/dist_save/es5/types.js.map +1 -0
- package/dist_save/es5/utils.d.ts +95 -0
- package/dist_save/es5/utils.js +590 -0
- package/dist_save/es5/utils.js.map +1 -0
- package/dist_save/gridstack-all.js +3 -0
- package/dist_save/gridstack-all.js.LICENSE.txt +7 -0
- package/dist_save/gridstack-all.js.map +1 -0
- package/dist_save/gridstack-engine.d.ts +102 -0
- package/dist_save/gridstack-engine.js +956 -0
- package/dist_save/gridstack-engine.js.map +1 -0
- package/dist_save/gridstack-extra.css +433 -0
- package/dist_save/gridstack-extra.min.css +1 -0
- package/dist_save/gridstack.css +226 -0
- package/dist_save/gridstack.d.ts +376 -0
- package/dist_save/gridstack.js +2162 -0
- package/dist_save/gridstack.js.map +1 -0
- package/dist_save/gridstack.min.css +1 -0
- package/dist_save/src/gridstack-extra.scss +27 -0
- package/dist_save/src/gridstack.scss +131 -0
- package/dist_save/types.d.ts +284 -0
- package/dist_save/types.js +36 -0
- package/dist_save/types.js.map +1 -0
- package/dist_save/utils.d.ts +95 -0
- package/dist_save/utils.js +548 -0
- package/dist_save/utils.js.map +1 -0
- package/doc/CHANGES.md +20 -0
- package/doc/README.md +21 -14
- package/package.json +25 -24
- /package/{dist → dist_save}/angular/README.md +0 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* dd-draggable.ts 7.3.0-dev
|
|
4
|
+
* Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DDDraggable = void 0;
|
|
8
|
+
const dd_manager_1 = require("./dd-manager");
|
|
9
|
+
const utils_1 = require("./utils");
|
|
10
|
+
const dd_base_impl_1 = require("./dd-base-impl");
|
|
11
|
+
const dd_touch_1 = require("./dd-touch");
|
|
12
|
+
// let count = 0; // TEST
|
|
13
|
+
class DDDraggable extends dd_base_impl_1.DDBaseImplement {
|
|
14
|
+
constructor(el, option = {}) {
|
|
15
|
+
super();
|
|
16
|
+
this.el = el;
|
|
17
|
+
this.option = option;
|
|
18
|
+
// get the element that is actually supposed to be dragged by
|
|
19
|
+
let handleName = option.handle.substring(1);
|
|
20
|
+
this.dragEl = el.classList.contains(handleName) ? el : el.querySelector(option.handle) || el;
|
|
21
|
+
// create var event binding so we can easily remove and still look like TS methods (unlike anonymous functions)
|
|
22
|
+
this._mouseDown = this._mouseDown.bind(this);
|
|
23
|
+
this._mouseMove = this._mouseMove.bind(this);
|
|
24
|
+
this._mouseUp = this._mouseUp.bind(this);
|
|
25
|
+
this.enable();
|
|
26
|
+
}
|
|
27
|
+
on(event, callback) {
|
|
28
|
+
super.on(event, callback);
|
|
29
|
+
}
|
|
30
|
+
off(event) {
|
|
31
|
+
super.off(event);
|
|
32
|
+
}
|
|
33
|
+
enable() {
|
|
34
|
+
if (this.disabled === false)
|
|
35
|
+
return;
|
|
36
|
+
super.enable();
|
|
37
|
+
this.dragEl.addEventListener('mousedown', this._mouseDown);
|
|
38
|
+
if (dd_touch_1.isTouch) {
|
|
39
|
+
this.dragEl.addEventListener('touchstart', dd_touch_1.touchstart);
|
|
40
|
+
this.dragEl.addEventListener('pointerdown', dd_touch_1.pointerdown);
|
|
41
|
+
// this.dragEl.style.touchAction = 'none'; // not needed unlike pointerdown doc comment
|
|
42
|
+
}
|
|
43
|
+
this.el.classList.remove('ui-draggable-disabled');
|
|
44
|
+
}
|
|
45
|
+
disable(forDestroy = false) {
|
|
46
|
+
if (this.disabled === true)
|
|
47
|
+
return;
|
|
48
|
+
super.disable();
|
|
49
|
+
this.dragEl.removeEventListener('mousedown', this._mouseDown);
|
|
50
|
+
if (dd_touch_1.isTouch) {
|
|
51
|
+
this.dragEl.removeEventListener('touchstart', dd_touch_1.touchstart);
|
|
52
|
+
this.dragEl.removeEventListener('pointerdown', dd_touch_1.pointerdown);
|
|
53
|
+
}
|
|
54
|
+
if (!forDestroy)
|
|
55
|
+
this.el.classList.add('ui-draggable-disabled');
|
|
56
|
+
}
|
|
57
|
+
destroy() {
|
|
58
|
+
if (this.dragTimeout)
|
|
59
|
+
window.clearTimeout(this.dragTimeout);
|
|
60
|
+
delete this.dragTimeout;
|
|
61
|
+
if (this.dragging)
|
|
62
|
+
this._mouseUp(this.mouseDownEvent);
|
|
63
|
+
this.disable(true);
|
|
64
|
+
delete this.el;
|
|
65
|
+
delete this.helper;
|
|
66
|
+
delete this.option;
|
|
67
|
+
super.destroy();
|
|
68
|
+
}
|
|
69
|
+
updateOption(opts) {
|
|
70
|
+
Object.keys(opts).forEach(key => this.option[key] = opts[key]);
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
/** @internal call when mouse goes down before a dragstart happens */
|
|
74
|
+
_mouseDown(e) {
|
|
75
|
+
// don't let more than one widget handle mouseStart
|
|
76
|
+
if (dd_manager_1.DDManager.mouseHandled)
|
|
77
|
+
return;
|
|
78
|
+
if (e.button !== 0)
|
|
79
|
+
return true; // only left click
|
|
80
|
+
// make sure we are not clicking on known object that handles mouseDown (TODO: make this extensible ?) #2054
|
|
81
|
+
const skipMouseDown = ['input', 'textarea', 'button', 'select', 'option'];
|
|
82
|
+
const name = e.target.nodeName.toLowerCase();
|
|
83
|
+
if (skipMouseDown.find(skip => skip === name))
|
|
84
|
+
return true;
|
|
85
|
+
// also check for content editable
|
|
86
|
+
if (e.target.closest('[contenteditable="true"]'))
|
|
87
|
+
return true;
|
|
88
|
+
// REMOVE: why would we get the event if it wasn't for us or child ?
|
|
89
|
+
// make sure we are clicking on a drag handle or child of it...
|
|
90
|
+
// Note: we don't need to check that's handle is an immediate child, as mouseHandled will prevent parents from also handling it (lowest wins)
|
|
91
|
+
// let className = this.option.handle.substring(1);
|
|
92
|
+
// let el = e.target as HTMLElement;
|
|
93
|
+
// while (el && !el.classList.contains(className)) { el = el.parentElement; }
|
|
94
|
+
// if (!el) return;
|
|
95
|
+
this.mouseDownEvent = e;
|
|
96
|
+
delete this.dragging;
|
|
97
|
+
delete dd_manager_1.DDManager.dragElement;
|
|
98
|
+
delete dd_manager_1.DDManager.dropElement;
|
|
99
|
+
// document handler so we can continue receiving moves as the item is 'fixed' position, and capture=true so WE get a first crack
|
|
100
|
+
document.addEventListener('mousemove', this._mouseMove, true); // true=capture, not bubble
|
|
101
|
+
document.addEventListener('mouseup', this._mouseUp, true);
|
|
102
|
+
if (dd_touch_1.isTouch) {
|
|
103
|
+
this.dragEl.addEventListener('touchmove', dd_touch_1.touchmove);
|
|
104
|
+
this.dragEl.addEventListener('touchend', dd_touch_1.touchend);
|
|
105
|
+
}
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
// preventDefault() prevents blur event which occurs just after mousedown event.
|
|
108
|
+
// if an editable content has focus, then blur must be call
|
|
109
|
+
if (document.activeElement)
|
|
110
|
+
document.activeElement.blur();
|
|
111
|
+
dd_manager_1.DDManager.mouseHandled = true;
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
/** @internal method to call actual drag event */
|
|
115
|
+
_callDrag(e) {
|
|
116
|
+
if (!this.dragging)
|
|
117
|
+
return;
|
|
118
|
+
const ev = utils_1.Utils.initEvent(e, { target: this.el, type: 'drag' });
|
|
119
|
+
if (this.option.drag) {
|
|
120
|
+
this.option.drag(ev, this.ui());
|
|
121
|
+
}
|
|
122
|
+
this.triggerEvent('drag', ev);
|
|
123
|
+
}
|
|
124
|
+
/** @internal called when the main page (after successful mousedown) receives a move event to drag the item around the screen */
|
|
125
|
+
_mouseMove(e) {
|
|
126
|
+
var _a;
|
|
127
|
+
// console.log(`${count++} move ${e.x},${e.y}`)
|
|
128
|
+
let s = this.mouseDownEvent;
|
|
129
|
+
if (this.dragging) {
|
|
130
|
+
this._dragFollow(e);
|
|
131
|
+
// delay actual grid handling drag until we pause for a while if set
|
|
132
|
+
if (dd_manager_1.DDManager.pauseDrag) {
|
|
133
|
+
const pause = Number.isInteger(dd_manager_1.DDManager.pauseDrag) ? dd_manager_1.DDManager.pauseDrag : 100;
|
|
134
|
+
if (this.dragTimeout)
|
|
135
|
+
window.clearTimeout(this.dragTimeout);
|
|
136
|
+
this.dragTimeout = window.setTimeout(() => this._callDrag(e), pause);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
this._callDrag(e);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else if (Math.abs(e.x - s.x) + Math.abs(e.y - s.y) > 3) {
|
|
143
|
+
/**
|
|
144
|
+
* don't start unless we've moved at least 3 pixels
|
|
145
|
+
*/
|
|
146
|
+
this.dragging = true;
|
|
147
|
+
dd_manager_1.DDManager.dragElement = this;
|
|
148
|
+
// if we're dragging an actual grid item, set the current drop as the grid (to detect enter/leave)
|
|
149
|
+
let grid = (_a = this.el.gridstackNode) === null || _a === void 0 ? void 0 : _a.grid;
|
|
150
|
+
if (grid) {
|
|
151
|
+
dd_manager_1.DDManager.dropElement = grid.el.ddElement.ddDroppable;
|
|
152
|
+
}
|
|
153
|
+
else {
|
|
154
|
+
delete dd_manager_1.DDManager.dropElement;
|
|
155
|
+
}
|
|
156
|
+
this.helper = this._createHelper(e);
|
|
157
|
+
this._setupHelperContainmentStyle();
|
|
158
|
+
this.dragOffset = this._getDragOffset(e, this.el, this.helperContainment);
|
|
159
|
+
const ev = utils_1.Utils.initEvent(e, { target: this.el, type: 'dragstart' });
|
|
160
|
+
this._setupHelperStyle(e);
|
|
161
|
+
if (this.option.start) {
|
|
162
|
+
this.option.start(ev, this.ui());
|
|
163
|
+
}
|
|
164
|
+
this.triggerEvent('dragstart', ev);
|
|
165
|
+
}
|
|
166
|
+
e.preventDefault(); // needed otherwise we get text sweep text selection as we drag around
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
/** @internal call when the mouse gets released to drop the item at current location */
|
|
170
|
+
_mouseUp(e) {
|
|
171
|
+
var _a;
|
|
172
|
+
document.removeEventListener('mousemove', this._mouseMove, true);
|
|
173
|
+
document.removeEventListener('mouseup', this._mouseUp, true);
|
|
174
|
+
if (dd_touch_1.isTouch) {
|
|
175
|
+
this.dragEl.removeEventListener('touchmove', dd_touch_1.touchmove, true);
|
|
176
|
+
this.dragEl.removeEventListener('touchend', dd_touch_1.touchend, true);
|
|
177
|
+
}
|
|
178
|
+
if (this.dragging) {
|
|
179
|
+
delete this.dragging;
|
|
180
|
+
// reset the drop target if dragging over ourself (already parented, just moving during stop callback below)
|
|
181
|
+
if (((_a = dd_manager_1.DDManager.dropElement) === null || _a === void 0 ? void 0 : _a.el) === this.el.parentElement) {
|
|
182
|
+
delete dd_manager_1.DDManager.dropElement;
|
|
183
|
+
}
|
|
184
|
+
this.helperContainment.style.position = this.parentOriginStylePosition || null;
|
|
185
|
+
if (this.helper === this.el) {
|
|
186
|
+
this._removeHelperStyle();
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
this.helper.remove();
|
|
190
|
+
}
|
|
191
|
+
const ev = utils_1.Utils.initEvent(e, { target: this.el, type: 'dragstop' });
|
|
192
|
+
if (this.option.stop) {
|
|
193
|
+
this.option.stop(ev); // NOTE: destroy() will be called when removing item, so expect NULL ptr after!
|
|
194
|
+
}
|
|
195
|
+
this.triggerEvent('dragstop', ev);
|
|
196
|
+
// call the droppable method to receive the item
|
|
197
|
+
if (dd_manager_1.DDManager.dropElement) {
|
|
198
|
+
dd_manager_1.DDManager.dropElement.drop(e);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
delete this.helper;
|
|
202
|
+
delete this.mouseDownEvent;
|
|
203
|
+
delete dd_manager_1.DDManager.dragElement;
|
|
204
|
+
delete dd_manager_1.DDManager.dropElement;
|
|
205
|
+
delete dd_manager_1.DDManager.mouseHandled;
|
|
206
|
+
e.preventDefault();
|
|
207
|
+
}
|
|
208
|
+
/** @internal create a clone copy (or user defined method) of the original drag item if set */
|
|
209
|
+
_createHelper(event) {
|
|
210
|
+
let helper = this.el;
|
|
211
|
+
if (typeof this.option.helper === 'function') {
|
|
212
|
+
helper = this.option.helper(event);
|
|
213
|
+
}
|
|
214
|
+
else if (this.option.helper === 'clone') {
|
|
215
|
+
helper = utils_1.Utils.cloneNode(this.el);
|
|
216
|
+
}
|
|
217
|
+
if (!document.body.contains(helper)) {
|
|
218
|
+
utils_1.Utils.appendTo(helper, this.option.appendTo === 'parent' ? this.el.parentNode : this.option.appendTo);
|
|
219
|
+
}
|
|
220
|
+
if (helper === this.el) {
|
|
221
|
+
this.dragElementOriginStyle = DDDraggable.originStyleProp.map(prop => this.el.style[prop]);
|
|
222
|
+
}
|
|
223
|
+
return helper;
|
|
224
|
+
}
|
|
225
|
+
/** @internal set the fix position of the dragged item */
|
|
226
|
+
_setupHelperStyle(e) {
|
|
227
|
+
this.helper.classList.add('ui-draggable-dragging');
|
|
228
|
+
// TODO: set all at once with style.cssText += ... ? https://stackoverflow.com/questions/3968593
|
|
229
|
+
const style = this.helper.style;
|
|
230
|
+
style.pointerEvents = 'none'; // needed for over items to get enter/leave
|
|
231
|
+
// style.cursor = 'move'; // TODO: can't set with pointerEvents=none ! (done in CSS as well)
|
|
232
|
+
style['min-width'] = 0; // since we no longer relative to our parent and we don't resize anyway (normally 100/#column %)
|
|
233
|
+
style.width = this.dragOffset.width + 'px';
|
|
234
|
+
style.height = this.dragOffset.height + 'px';
|
|
235
|
+
style.willChange = 'left, top';
|
|
236
|
+
style.position = 'fixed'; // let us drag between grids by not clipping as parent .grid-stack is position: 'relative'
|
|
237
|
+
this._dragFollow(e); // now position it
|
|
238
|
+
style.transition = 'none'; // show up instantly
|
|
239
|
+
setTimeout(() => {
|
|
240
|
+
if (this.helper) {
|
|
241
|
+
style.transition = null; // recover animation
|
|
242
|
+
}
|
|
243
|
+
}, 0);
|
|
244
|
+
return this;
|
|
245
|
+
}
|
|
246
|
+
/** @internal restore back the original style before dragging */
|
|
247
|
+
_removeHelperStyle() {
|
|
248
|
+
var _a;
|
|
249
|
+
this.helper.classList.remove('ui-draggable-dragging');
|
|
250
|
+
let node = (_a = this.helper) === null || _a === void 0 ? void 0 : _a.gridstackNode;
|
|
251
|
+
// don't bother restoring styles if we're gonna remove anyway...
|
|
252
|
+
if (!(node === null || node === void 0 ? void 0 : node._isAboutToRemove) && this.dragElementOriginStyle) {
|
|
253
|
+
let helper = this.helper;
|
|
254
|
+
// don't animate, otherwise we animate offseted when switching back to 'absolute' from 'fixed'.
|
|
255
|
+
// TODO: this also removes resizing animation which doesn't have this issue, but others.
|
|
256
|
+
// Ideally both would animate ('move' would immediately restore 'absolute' and adjust coordinate to match,
|
|
257
|
+
// then trigger a delay (repaint) to restore to final dest with animate) but then we need to make sure 'resizestop'
|
|
258
|
+
// is called AFTER 'transitionend' event is received (see https://github.com/gridstack/gridstack.js/issues/2033)
|
|
259
|
+
let transition = this.dragElementOriginStyle['transition'] || null;
|
|
260
|
+
helper.style.transition = this.dragElementOriginStyle['transition'] = 'none'; // can't be NULL #1973
|
|
261
|
+
DDDraggable.originStyleProp.forEach(prop => helper.style[prop] = this.dragElementOriginStyle[prop] || null);
|
|
262
|
+
setTimeout(() => helper.style.transition = transition, 50); // recover animation from saved vars after a pause (0 isn't enough #1973)
|
|
263
|
+
}
|
|
264
|
+
delete this.dragElementOriginStyle;
|
|
265
|
+
return this;
|
|
266
|
+
}
|
|
267
|
+
/** @internal updates the top/left position to follow the mouse */
|
|
268
|
+
_dragFollow(e) {
|
|
269
|
+
let containmentRect = { left: 0, top: 0 };
|
|
270
|
+
// if (this.helper.style.position === 'absolute') { // we use 'fixed'
|
|
271
|
+
// const { left, top } = this.helperContainment.getBoundingClientRect();
|
|
272
|
+
// containmentRect = { left, top };
|
|
273
|
+
// }
|
|
274
|
+
const style = this.helper.style;
|
|
275
|
+
const offset = this.dragOffset;
|
|
276
|
+
style.left = e.clientX + offset.offsetLeft - containmentRect.left + 'px';
|
|
277
|
+
style.top = e.clientY + offset.offsetTop - containmentRect.top + 'px';
|
|
278
|
+
}
|
|
279
|
+
/** @internal */
|
|
280
|
+
_setupHelperContainmentStyle() {
|
|
281
|
+
this.helperContainment = this.helper.parentElement;
|
|
282
|
+
if (this.helper.style.position !== 'fixed') {
|
|
283
|
+
this.parentOriginStylePosition = this.helperContainment.style.position;
|
|
284
|
+
if (window.getComputedStyle(this.helperContainment).position.match(/static/)) {
|
|
285
|
+
this.helperContainment.style.position = 'relative';
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return this;
|
|
289
|
+
}
|
|
290
|
+
/** @internal */
|
|
291
|
+
_getDragOffset(event, el, parent) {
|
|
292
|
+
// in case ancestor has transform/perspective css properties that change the viewpoint
|
|
293
|
+
let xformOffsetX = 0;
|
|
294
|
+
let xformOffsetY = 0;
|
|
295
|
+
if (parent) {
|
|
296
|
+
const testEl = document.createElement('div');
|
|
297
|
+
utils_1.Utils.addElStyles(testEl, {
|
|
298
|
+
opacity: '0',
|
|
299
|
+
position: 'fixed',
|
|
300
|
+
top: 0 + 'px',
|
|
301
|
+
left: 0 + 'px',
|
|
302
|
+
width: '1px',
|
|
303
|
+
height: '1px',
|
|
304
|
+
zIndex: '-999999',
|
|
305
|
+
});
|
|
306
|
+
parent.appendChild(testEl);
|
|
307
|
+
const testElPosition = testEl.getBoundingClientRect();
|
|
308
|
+
parent.removeChild(testEl);
|
|
309
|
+
xformOffsetX = testElPosition.left;
|
|
310
|
+
xformOffsetY = testElPosition.top;
|
|
311
|
+
// TODO: scale ?
|
|
312
|
+
}
|
|
313
|
+
const targetOffset = el.getBoundingClientRect();
|
|
314
|
+
return {
|
|
315
|
+
left: targetOffset.left,
|
|
316
|
+
top: targetOffset.top,
|
|
317
|
+
offsetLeft: -event.clientX + targetOffset.left - xformOffsetX,
|
|
318
|
+
offsetTop: -event.clientY + targetOffset.top - xformOffsetY,
|
|
319
|
+
width: targetOffset.width,
|
|
320
|
+
height: targetOffset.height
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
/** @internal TODO: set to public as called by DDDroppable! */
|
|
324
|
+
ui() {
|
|
325
|
+
const containmentEl = this.el.parentElement;
|
|
326
|
+
const containmentRect = containmentEl.getBoundingClientRect();
|
|
327
|
+
const offset = this.helper.getBoundingClientRect();
|
|
328
|
+
return {
|
|
329
|
+
position: {
|
|
330
|
+
top: offset.top - containmentRect.top,
|
|
331
|
+
left: offset.left - containmentRect.left
|
|
332
|
+
}
|
|
333
|
+
/* not used by GridStack for now...
|
|
334
|
+
helper: [this.helper], //The object arr representing the helper that's being dragged.
|
|
335
|
+
offset: { top: offset.top, left: offset.left } // Current offset position of the helper as { top, left } object.
|
|
336
|
+
*/
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
exports.DDDraggable = DDDraggable;
|
|
341
|
+
/** @internal properties we change during dragging, and restore back */
|
|
342
|
+
DDDraggable.originStyleProp = ['transition', 'pointerEvents', 'position', 'left', 'top', 'minWidth', 'willChange'];
|
|
343
|
+
//# sourceMappingURL=dd-draggable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dd-draggable.js","sourceRoot":"","sources":["../src/dd-draggable.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6CAAyC;AACzC,mCAAgC;AAChC,iDAAuE;AAGvE,yCAAmF;AA0BnF,yBAAyB;AAEzB,MAAa,WAAY,SAAQ,8BAAe;IAwB9C,YAAY,EAAe,EAAE,SAAyB,EAAE;QACtD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,6DAA6D;QAC7D,IAAI,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QAC5C,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;QAC7F,+GAA+G;QAC/G,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,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AE,CAAE,KAAK,CAAC,OAAO,GAAG,YAAY,CAAC,GAAG,GAAG,YAAY;YAC5D,KAAK,EAAE,YAAY,CAAC,KAAK;YACzB,MAAM,EAAE,YAAY,CAAC,MAAM;SAC5B,CAAC;IACJ,CAAC;IAED,8DAA8D;IACvD,EAAE;QACP,MAAM,aAAa,GAAG,IAAI,CAAC,EAAE,CAAC,aAAa,CAAC;QAC5C,MAAM,eAAe,GAAG,aAAa,CAAC,qBAAqB,EAAE,CAAC;QAC9D,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,qBAAqB,EAAE,CAAC;QACnD,OAAO;YACL,QAAQ,EAAE;gBACR,GAAG,EAAE,MAAM,CAAC,GAAG,GAAG,eAAe,CAAC,GAAG;gBACrC,IAAI,EAAE,MAAM,CAAC,IAAI,GAAG,eAAe,CAAC,IAAI;aACzC;YACD;;;cAGE;SACH,CAAC;IACJ,CAAC;;AArWH,kCAsWC;AAnVC,uEAAuE;AACtD,2BAAe,GAAG,CAAC,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,EAAE,YAAY,CAAC,CAAC","sourcesContent":["/**\n * dd-draggable.ts 7.3.0-dev\n * Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license\n */\n\nimport { DDManager } from './dd-manager';\nimport { Utils } from './utils';\nimport { DDBaseImplement, HTMLElementExtendOpt } from './dd-base-impl';\nimport { GridItemHTMLElement, DDUIData } from './types';\nimport { DDElementHost } from './dd-element';\nimport { isTouch, touchend, touchmove, touchstart, pointerdown } from './dd-touch';\n\n// TODO: merge with DDDragOpt ?\nexport interface DDDraggableOpt {\n appendTo?: string | HTMLElement;\n handle?: string;\n helper?: string | HTMLElement | ((event: Event) => HTMLElement);\n // containment?: string | HTMLElement; // TODO: not implemented yet\n // revert?: string | boolean | unknown; // TODO: not implemented yet\n // scroll?: boolean; // native support by HTML5 drag drop, can't be switch to off actually\n start?: (event: Event, ui: DDUIData) => void;\n stop?: (event: Event) => void;\n drag?: (event: Event, ui: DDUIData) => void;\n}\n\ninterface DragOffset {\n left: number;\n top: number;\n width: number;\n height: number;\n offsetLeft: number;\n offsetTop: number;\n}\n\ntype DDDragEvent = 'drag' | 'dragstart' | 'dragstop';\n\n// let count = 0; // TEST\n\nexport class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt<DDDraggableOpt> {\n public el: HTMLElement;\n public option: DDDraggableOpt;\n public helper: HTMLElement; // used by GridStackDDNative\n\n /** @internal */\n protected mouseDownEvent: MouseEvent;\n /** @internal */\n protected dragOffset: DragOffset;\n /** @internal */\n protected dragElementOriginStyle: Array<string>;\n /** @internal */\n protected dragEl: HTMLElement;\n /** @internal true while we are dragging an item around */\n protected dragging: boolean;\n /** @internal */\n protected parentOriginStylePosition: string;\n /** @internal */\n protected helperContainment: HTMLElement;\n /** @internal properties we change during dragging, and restore back */\n protected static originStyleProp = ['transition', 'pointerEvents', 'position', 'left', 'top', 'minWidth', 'willChange'];\n /** @internal pause before we call the actual drag hit collision code */\n protected dragTimeout: number;\n\n constructor(el: HTMLElement, option: DDDraggableOpt = {}) {\n super();\n this.el = el;\n this.option = option;\n // get the element that is actually supposed to be dragged by\n let handleName = option.handle.substring(1);\n this.dragEl = el.classList.contains(handleName) ? el : el.querySelector(option.handle) || el;\n // create var event binding so we can easily remove and still look like TS methods (unlike anonymous functions)\n this._mouseDown = this._mouseDown.bind(this);\n this._mouseMove = this._mouseMove.bind(this);\n this._mouseUp = this._mouseUp.bind(this);\n this.enable();\n }\n\n public on(event: DDDragEvent, callback: (event: DragEvent) => void): void {\n super.on(event, callback);\n }\n\n public off(event: DDDragEvent): void {\n super.off(event);\n }\n\n public enable(): void {\n if (this.disabled === false) return;\n super.enable();\n this.dragEl.addEventListener('mousedown', this._mouseDown);\n if (isTouch) {\n this.dragEl.addEventListener('touchstart', touchstart);\n this.dragEl.addEventListener('pointerdown', pointerdown);\n // this.dragEl.style.touchAction = 'none'; // not needed unlike pointerdown doc comment\n }\n this.el.classList.remove('ui-draggable-disabled');\n }\n\n public disable(forDestroy = false): void {\n if (this.disabled === true) return;\n super.disable();\n this.dragEl.removeEventListener('mousedown', this._mouseDown);\n if (isTouch) {\n this.dragEl.removeEventListener('touchstart', touchstart);\n this.dragEl.removeEventListener('pointerdown', pointerdown);\n }\n if (!forDestroy) this.el.classList.add('ui-draggable-disabled');\n }\n\n public destroy(): void {\n if (this.dragTimeout) window.clearTimeout(this.dragTimeout);\n delete this.dragTimeout;\n if (this.dragging) this._mouseUp(this.mouseDownEvent);\n this.disable(true);\n delete this.el;\n delete this.helper;\n delete this.option;\n super.destroy();\n }\n\n public updateOption(opts: DDDraggableOpt): DDDraggable {\n Object.keys(opts).forEach(key => this.option[key] = opts[key]);\n return this;\n }\n\n /** @internal call when mouse goes down before a dragstart happens */\n protected _mouseDown(e: MouseEvent): boolean {\n // don't let more than one widget handle mouseStart\n if (DDManager.mouseHandled) return;\n if (e.button !== 0) return true; // only left click\n\n // make sure we are not clicking on known object that handles mouseDown (TODO: make this extensible ?) #2054\n const skipMouseDown = ['input', 'textarea', 'button', 'select', 'option'];\n const name = (e.target as HTMLElement).nodeName.toLowerCase();\n if (skipMouseDown.find(skip => skip === name)) return true;\n // also check for content editable\n if ((e.target as HTMLElement).closest('[contenteditable=\"true\"]')) return true;\n\n // REMOVE: why would we get the event if it wasn't for us or child ?\n // make sure we are clicking on a drag handle or child of it...\n // Note: we don't need to check that's handle is an immediate child, as mouseHandled will prevent parents from also handling it (lowest wins)\n // let className = this.option.handle.substring(1);\n // let el = e.target as HTMLElement;\n // while (el && !el.classList.contains(className)) { el = el.parentElement; }\n // if (!el) return;\n\n this.mouseDownEvent = e;\n delete this.dragging;\n delete DDManager.dragElement;\n delete DDManager.dropElement;\n // document handler so we can continue receiving moves as the item is 'fixed' position, and capture=true so WE get a first crack\n document.addEventListener('mousemove', this._mouseMove, true); // true=capture, not bubble\n document.addEventListener('mouseup', this._mouseUp, true);\n if (isTouch) {\n this.dragEl.addEventListener('touchmove', touchmove);\n this.dragEl.addEventListener('touchend', touchend);\n }\n\n e.preventDefault();\n // preventDefault() prevents blur event which occurs just after mousedown event.\n // if an editable content has focus, then blur must be call\n if (document.activeElement) (document.activeElement as HTMLElement).blur();\n\n DDManager.mouseHandled = true;\n return true;\n }\n\n /** @internal method to call actual drag event */\n protected _callDrag(e: DragEvent): void {\n if (!this.dragging) return;\n const ev = Utils.initEvent<DragEvent>(e, { target: this.el, type: 'drag' });\n if (this.option.drag) {\n this.option.drag(ev, this.ui());\n }\n this.triggerEvent('drag', ev);\n }\n\n /** @internal called when the main page (after successful mousedown) receives a move event to drag the item around the screen */\n protected _mouseMove(e: DragEvent): boolean {\n // console.log(`${count++} move ${e.x},${e.y}`)\n let s = this.mouseDownEvent;\n\n if (this.dragging) {\n this._dragFollow(e);\n // delay actual grid handling drag until we pause for a while if set\n if (DDManager.pauseDrag) {\n const pause = Number.isInteger(DDManager.pauseDrag) ? DDManager.pauseDrag as number : 100;\n if (this.dragTimeout) window.clearTimeout(this.dragTimeout);\n this.dragTimeout = window.setTimeout(() => this._callDrag(e), pause);\n } else {\n this._callDrag(e);\n }\n } else if (Math.abs(e.x - s.x) + Math.abs(e.y - s.y) > 3) {\n /**\n * don't start unless we've moved at least 3 pixels\n */\n this.dragging = true;\n DDManager.dragElement = this;\n // if we're dragging an actual grid item, set the current drop as the grid (to detect enter/leave)\n let grid = (this.el as GridItemHTMLElement).gridstackNode?.grid;\n if (grid) {\n DDManager.dropElement = (grid.el as DDElementHost).ddElement.ddDroppable;\n } else {\n delete DDManager.dropElement;\n }\n this.helper = this._createHelper(e);\n this._setupHelperContainmentStyle();\n this.dragOffset = this._getDragOffset(e, this.el, this.helperContainment);\n const ev = Utils.initEvent<DragEvent>(e, { target: this.el, type: 'dragstart' });\n\n this._setupHelperStyle(e);\n if (this.option.start) {\n this.option.start(ev, this.ui());\n }\n this.triggerEvent('dragstart', ev);\n }\n e.preventDefault(); // needed otherwise we get text sweep text selection as we drag around\n return true;\n }\n\n /** @internal call when the mouse gets released to drop the item at current location */\n protected _mouseUp(e: MouseEvent): void {\n document.removeEventListener('mousemove', this._mouseMove, true);\n document.removeEventListener('mouseup', this._mouseUp, true);\n if (isTouch) {\n this.dragEl.removeEventListener('touchmove', touchmove, true);\n this.dragEl.removeEventListener('touchend', touchend, true);\n }\n if (this.dragging) {\n delete this.dragging;\n\n // reset the drop target if dragging over ourself (already parented, just moving during stop callback below)\n if (DDManager.dropElement?.el === this.el.parentElement) {\n delete DDManager.dropElement;\n }\n\n this.helperContainment.style.position = this.parentOriginStylePosition || null;\n if (this.helper === this.el) {\n this._removeHelperStyle();\n } else {\n this.helper.remove();\n }\n const ev = Utils.initEvent<DragEvent>(e, { target: this.el, type: 'dragstop' });\n if (this.option.stop) {\n this.option.stop(ev); // NOTE: destroy() will be called when removing item, so expect NULL ptr after!\n }\n this.triggerEvent('dragstop', ev);\n\n // call the droppable method to receive the item\n if (DDManager.dropElement) {\n DDManager.dropElement.drop(e);\n }\n }\n delete this.helper;\n delete this.mouseDownEvent;\n delete DDManager.dragElement;\n delete DDManager.dropElement;\n delete DDManager.mouseHandled;\n e.preventDefault();\n }\n\n /** @internal create a clone copy (or user defined method) of the original drag item if set */\n protected _createHelper(event: DragEvent): HTMLElement {\n let helper = this.el;\n if (typeof this.option.helper === 'function') {\n helper = this.option.helper(event);\n } else if (this.option.helper === 'clone') {\n helper = Utils.cloneNode(this.el);\n }\n if (!document.body.contains(helper)) {\n Utils.appendTo(helper, this.option.appendTo === 'parent' ? this.el.parentNode : this.option.appendTo);\n }\n if (helper === this.el) {\n this.dragElementOriginStyle = DDDraggable.originStyleProp.map(prop => this.el.style[prop]);\n }\n return helper;\n }\n\n /** @internal set the fix position of the dragged item */\n protected _setupHelperStyle(e: DragEvent): DDDraggable {\n this.helper.classList.add('ui-draggable-dragging');\n // TODO: set all at once with style.cssText += ... ? https://stackoverflow.com/questions/3968593\n const style = this.helper.style;\n style.pointerEvents = 'none'; // needed for over items to get enter/leave\n // style.cursor = 'move'; // TODO: can't set with pointerEvents=none ! (done in CSS as well)\n style['min-width'] = 0; // since we no longer relative to our parent and we don't resize anyway (normally 100/#column %)\n style.width = this.dragOffset.width + 'px';\n style.height = this.dragOffset.height + 'px';\n style.willChange = 'left, top';\n style.position = 'fixed'; // let us drag between grids by not clipping as parent .grid-stack is position: 'relative'\n this._dragFollow(e); // now position it\n style.transition = 'none'; // show up instantly\n setTimeout(() => {\n if (this.helper) {\n style.transition = null; // recover animation\n }\n }, 0);\n return this;\n }\n\n /** @internal restore back the original style before dragging */\n protected _removeHelperStyle(): DDDraggable {\n this.helper.classList.remove('ui-draggable-dragging');\n let node = (this.helper as GridItemHTMLElement)?.gridstackNode;\n // don't bother restoring styles if we're gonna remove anyway...\n if (!node?._isAboutToRemove && this.dragElementOriginStyle) {\n let helper = this.helper;\n // don't animate, otherwise we animate offseted when switching back to 'absolute' from 'fixed'.\n // TODO: this also removes resizing animation which doesn't have this issue, but others.\n // Ideally both would animate ('move' would immediately restore 'absolute' and adjust coordinate to match,\n // then trigger a delay (repaint) to restore to final dest with animate) but then we need to make sure 'resizestop'\n // is called AFTER 'transitionend' event is received (see https://github.com/gridstack/gridstack.js/issues/2033)\n let transition = this.dragElementOriginStyle['transition'] || null;\n helper.style.transition = this.dragElementOriginStyle['transition'] = 'none'; // can't be NULL #1973\n DDDraggable.originStyleProp.forEach(prop => helper.style[prop] = this.dragElementOriginStyle[prop] || null);\n setTimeout(() => helper.style.transition = transition, 50); // recover animation from saved vars after a pause (0 isn't enough #1973)\n }\n delete this.dragElementOriginStyle;\n return this;\n }\n\n /** @internal updates the top/left position to follow the mouse */\n protected _dragFollow(e: DragEvent): void {\n let containmentRect = { left: 0, top: 0 };\n // if (this.helper.style.position === 'absolute') { // we use 'fixed'\n // const { left, top } = this.helperContainment.getBoundingClientRect();\n // containmentRect = { left, top };\n // }\n const style = this.helper.style;\n const offset = this.dragOffset;\n style.left = e.clientX + offset.offsetLeft - containmentRect.left + 'px';\n style.top = e.clientY + offset.offsetTop - containmentRect.top + 'px';\n }\n\n /** @internal */\n protected _setupHelperContainmentStyle(): DDDraggable {\n this.helperContainment = this.helper.parentElement;\n if (this.helper.style.position !== 'fixed') {\n this.parentOriginStylePosition = this.helperContainment.style.position;\n if (window.getComputedStyle(this.helperContainment).position.match(/static/)) {\n this.helperContainment.style.position = 'relative';\n }\n }\n return this;\n }\n\n /** @internal */\n protected _getDragOffset(event: DragEvent, el: HTMLElement, parent: HTMLElement): DragOffset {\n\n // in case ancestor has transform/perspective css properties that change the viewpoint\n let xformOffsetX = 0;\n let xformOffsetY = 0;\n if (parent) {\n const testEl = document.createElement('div');\n Utils.addElStyles(testEl, {\n opacity: '0',\n position: 'fixed',\n top: 0 + 'px',\n left: 0 + 'px',\n width: '1px',\n height: '1px',\n zIndex: '-999999',\n });\n parent.appendChild(testEl);\n const testElPosition = testEl.getBoundingClientRect();\n parent.removeChild(testEl);\n xformOffsetX = testElPosition.left;\n xformOffsetY = testElPosition.top;\n // TODO: scale ?\n }\n\n const targetOffset = el.getBoundingClientRect();\n return {\n left: targetOffset.left,\n top: targetOffset.top,\n offsetLeft: - event.clientX + targetOffset.left - xformOffsetX,\n offsetTop: - event.clientY + targetOffset.top - xformOffsetY,\n width: targetOffset.width,\n height: targetOffset.height\n };\n }\n\n /** @internal TODO: set to public as called by DDDroppable! */\n public ui(): DDUIData {\n const containmentEl = this.el.parentElement;\n const containmentRect = containmentEl.getBoundingClientRect();\n const offset = this.helper.getBoundingClientRect();\n return {\n position: { //Current CSS position of the helper as { top, left } object\n top: offset.top - containmentRect.top,\n left: offset.left - containmentRect.left\n }\n /* not used by GridStack for now...\n helper: [this.helper], //The object arr representing the helper that's being dragged.\n offset: { top: offset.top, left: offset.left } // Current offset position of the helper as { top, left } object.\n */\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dd-droppable.ts 7.3.0-dev
|
|
3
|
+
* Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
|
|
4
|
+
*/
|
|
5
|
+
import { DDBaseImplement, HTMLElementExtendOpt } from './dd-base-impl';
|
|
6
|
+
import { DDUIData } from './types';
|
|
7
|
+
export interface DDDroppableOpt {
|
|
8
|
+
accept?: string | ((el: HTMLElement) => boolean);
|
|
9
|
+
drop?: (event: DragEvent, ui: DDUIData) => void;
|
|
10
|
+
over?: (event: DragEvent, ui: DDUIData) => void;
|
|
11
|
+
out?: (event: DragEvent, ui: DDUIData) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare class DDDroppable extends DDBaseImplement implements HTMLElementExtendOpt<DDDroppableOpt> {
|
|
14
|
+
accept: (el: HTMLElement) => boolean;
|
|
15
|
+
el: HTMLElement;
|
|
16
|
+
option: DDDroppableOpt;
|
|
17
|
+
constructor(el: HTMLElement, opts?: DDDroppableOpt);
|
|
18
|
+
on(event: 'drop' | 'dropover' | 'dropout', callback: (event: DragEvent) => void): void;
|
|
19
|
+
off(event: 'drop' | 'dropover' | 'dropout'): void;
|
|
20
|
+
enable(): void;
|
|
21
|
+
disable(forDestroy?: boolean): void;
|
|
22
|
+
destroy(): void;
|
|
23
|
+
updateOption(opts: DDDroppableOpt): DDDroppable;
|
|
24
|
+
/** item is being dropped on us - called by the drag mouseup handler - this calls the client drop event */
|
|
25
|
+
drop(e: MouseEvent): void;
|
|
26
|
+
}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* dd-droppable.ts 7.3.0-dev
|
|
4
|
+
* Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.DDDroppable = void 0;
|
|
8
|
+
const dd_manager_1 = require("./dd-manager");
|
|
9
|
+
const dd_base_impl_1 = require("./dd-base-impl");
|
|
10
|
+
const utils_1 = require("./utils");
|
|
11
|
+
const dd_touch_1 = require("./dd-touch");
|
|
12
|
+
// let count = 0; // TEST
|
|
13
|
+
class DDDroppable extends dd_base_impl_1.DDBaseImplement {
|
|
14
|
+
constructor(el, opts = {}) {
|
|
15
|
+
super();
|
|
16
|
+
this.el = el;
|
|
17
|
+
this.option = opts;
|
|
18
|
+
// create var event binding so we can easily remove and still look like TS methods (unlike anonymous functions)
|
|
19
|
+
this._mouseEnter = this._mouseEnter.bind(this);
|
|
20
|
+
this._mouseLeave = this._mouseLeave.bind(this);
|
|
21
|
+
this.enable();
|
|
22
|
+
this._setupAccept();
|
|
23
|
+
}
|
|
24
|
+
on(event, callback) {
|
|
25
|
+
super.on(event, callback);
|
|
26
|
+
}
|
|
27
|
+
off(event) {
|
|
28
|
+
super.off(event);
|
|
29
|
+
}
|
|
30
|
+
enable() {
|
|
31
|
+
if (this.disabled === false)
|
|
32
|
+
return;
|
|
33
|
+
super.enable();
|
|
34
|
+
this.el.classList.add('ui-droppable');
|
|
35
|
+
this.el.classList.remove('ui-droppable-disabled');
|
|
36
|
+
this.el.addEventListener('mouseenter', this._mouseEnter);
|
|
37
|
+
this.el.addEventListener('mouseleave', this._mouseLeave);
|
|
38
|
+
if (dd_touch_1.isTouch) {
|
|
39
|
+
this.el.addEventListener('pointerenter', dd_touch_1.pointerenter);
|
|
40
|
+
this.el.addEventListener('pointerleave', dd_touch_1.pointerleave);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
disable(forDestroy = false) {
|
|
44
|
+
if (this.disabled === true)
|
|
45
|
+
return;
|
|
46
|
+
super.disable();
|
|
47
|
+
this.el.classList.remove('ui-droppable');
|
|
48
|
+
if (!forDestroy)
|
|
49
|
+
this.el.classList.add('ui-droppable-disabled');
|
|
50
|
+
this.el.removeEventListener('mouseenter', this._mouseEnter);
|
|
51
|
+
this.el.removeEventListener('mouseleave', this._mouseLeave);
|
|
52
|
+
if (dd_touch_1.isTouch) {
|
|
53
|
+
this.el.removeEventListener('pointerenter', dd_touch_1.pointerenter);
|
|
54
|
+
this.el.removeEventListener('pointerleave', dd_touch_1.pointerleave);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
destroy() {
|
|
58
|
+
this.disable(true);
|
|
59
|
+
this.el.classList.remove('ui-droppable');
|
|
60
|
+
this.el.classList.remove('ui-droppable-disabled');
|
|
61
|
+
super.destroy();
|
|
62
|
+
}
|
|
63
|
+
updateOption(opts) {
|
|
64
|
+
Object.keys(opts).forEach(key => this.option[key] = opts[key]);
|
|
65
|
+
this._setupAccept();
|
|
66
|
+
return this;
|
|
67
|
+
}
|
|
68
|
+
/** @internal called when the cursor enters our area - prepare for a possible drop and track leaving */
|
|
69
|
+
_mouseEnter(e) {
|
|
70
|
+
// console.log(`${count++} Enter ${this.el.id || (this.el as GridHTMLElement).gridstack.opts.id}`); // TEST
|
|
71
|
+
if (!dd_manager_1.DDManager.dragElement)
|
|
72
|
+
return;
|
|
73
|
+
if (!this._canDrop(dd_manager_1.DDManager.dragElement.el))
|
|
74
|
+
return;
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
e.stopPropagation();
|
|
77
|
+
// make sure when we enter this, that the last one gets a leave FIRST to correctly cleanup as we don't always do
|
|
78
|
+
if (dd_manager_1.DDManager.dropElement && dd_manager_1.DDManager.dropElement !== this) {
|
|
79
|
+
dd_manager_1.DDManager.dropElement._mouseLeave(e);
|
|
80
|
+
}
|
|
81
|
+
dd_manager_1.DDManager.dropElement = this;
|
|
82
|
+
const ev = utils_1.Utils.initEvent(e, { target: this.el, type: 'dropover' });
|
|
83
|
+
if (this.option.over) {
|
|
84
|
+
this.option.over(ev, this._ui(dd_manager_1.DDManager.dragElement));
|
|
85
|
+
}
|
|
86
|
+
this.triggerEvent('dropover', ev);
|
|
87
|
+
this.el.classList.add('ui-droppable-over');
|
|
88
|
+
// console.log('tracking'); // TEST
|
|
89
|
+
}
|
|
90
|
+
/** @internal called when the item is leaving our area, stop tracking if we had moving item */
|
|
91
|
+
_mouseLeave(e) {
|
|
92
|
+
var _a;
|
|
93
|
+
// console.log(`${count++} Leave ${this.el.id || (this.el as GridHTMLElement).gridstack.opts.id}`); // TEST
|
|
94
|
+
if (!dd_manager_1.DDManager.dragElement || dd_manager_1.DDManager.dropElement !== this)
|
|
95
|
+
return;
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
e.stopPropagation();
|
|
98
|
+
const ev = utils_1.Utils.initEvent(e, { target: this.el, type: 'dropout' });
|
|
99
|
+
if (this.option.out) {
|
|
100
|
+
this.option.out(ev, this._ui(dd_manager_1.DDManager.dragElement));
|
|
101
|
+
}
|
|
102
|
+
this.triggerEvent('dropout', ev);
|
|
103
|
+
if (dd_manager_1.DDManager.dropElement === this) {
|
|
104
|
+
delete dd_manager_1.DDManager.dropElement;
|
|
105
|
+
// console.log('not tracking'); // TEST
|
|
106
|
+
// if we're still over a parent droppable, send it an enter as we don't get one from leaving nested children
|
|
107
|
+
let parentDrop;
|
|
108
|
+
let parent = this.el.parentElement;
|
|
109
|
+
while (!parentDrop && parent) {
|
|
110
|
+
parentDrop = (_a = parent.ddElement) === null || _a === void 0 ? void 0 : _a.ddDroppable;
|
|
111
|
+
parent = parent.parentElement;
|
|
112
|
+
}
|
|
113
|
+
if (parentDrop) {
|
|
114
|
+
parentDrop._mouseEnter(e);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** item is being dropped on us - called by the drag mouseup handler - this calls the client drop event */
|
|
119
|
+
drop(e) {
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
const ev = utils_1.Utils.initEvent(e, { target: this.el, type: 'drop' });
|
|
122
|
+
if (this.option.drop) {
|
|
123
|
+
this.option.drop(ev, this._ui(dd_manager_1.DDManager.dragElement));
|
|
124
|
+
}
|
|
125
|
+
this.triggerEvent('drop', ev);
|
|
126
|
+
}
|
|
127
|
+
/** @internal true if element matches the string/method accept option */
|
|
128
|
+
_canDrop(el) {
|
|
129
|
+
return el && (!this.accept || this.accept(el));
|
|
130
|
+
}
|
|
131
|
+
/** @internal */
|
|
132
|
+
_setupAccept() {
|
|
133
|
+
if (!this.option.accept)
|
|
134
|
+
return this;
|
|
135
|
+
if (typeof this.option.accept === 'string') {
|
|
136
|
+
this.accept = (el) => el.matches(this.option.accept);
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
this.accept = this.option.accept;
|
|
140
|
+
}
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
/** @internal */
|
|
144
|
+
_ui(drag) {
|
|
145
|
+
return Object.assign({ draggable: drag.el }, drag.ui());
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.DDDroppable = DDDroppable;
|
|
149
|
+
//# sourceMappingURL=dd-droppable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dd-droppable.js","sourceRoot":"","sources":["../src/dd-droppable.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,6CAAyC;AACzC,iDAAuE;AACvE,mCAAgC;AAEhC,yCAAiE;AAUjE,yBAAyB;AAEzB,MAAa,WAAY,SAAQ,8BAAe;IAM9C,YAAY,EAAe,EAAE,OAAuB,EAAE;QACpD,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,+GAA+G;QAC/G,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,EAAE,CAAC;QACd,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAEM,EAAE,CAAC,KAAsC,EAAE,QAAoC;QACpF,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;IAC5B,CAAC;IAEM,GAAG,CAAC,KAAsC;QAC/C,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AAE,IACf,IAAI,CAAC,EAAE,EAAE,EACZ;IACJ,CAAC;CACF;AAtJD,kCAsJC","sourcesContent":["/**\n * dd-droppable.ts 7.3.0-dev\n * Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license\n */\n\nimport { DDDraggable } from './dd-draggable';\nimport { DDManager } from './dd-manager';\nimport { DDBaseImplement, HTMLElementExtendOpt } from './dd-base-impl';\nimport { Utils } from './utils';\nimport { DDElementHost } from './dd-element';\nimport { isTouch, pointerenter, pointerleave } from './dd-touch';\nimport { DDUIData } from './types';\n\nexport interface DDDroppableOpt {\n accept?: string | ((el: HTMLElement) => boolean);\n drop?: (event: DragEvent, ui: DDUIData) => void;\n over?: (event: DragEvent, ui: DDUIData) => void;\n out?: (event: DragEvent, ui: DDUIData) => void;\n}\n\n// let count = 0; // TEST\n\nexport class DDDroppable extends DDBaseImplement implements HTMLElementExtendOpt<DDDroppableOpt> {\n\n public accept: (el: HTMLElement) => boolean;\n public el: HTMLElement;\n public option: DDDroppableOpt;\n\n constructor(el: HTMLElement, opts: DDDroppableOpt = {}) {\n super();\n this.el = el;\n this.option = opts;\n // create var event binding so we can easily remove and still look like TS methods (unlike anonymous functions)\n this._mouseEnter = this._mouseEnter.bind(this);\n this._mouseLeave = this._mouseLeave.bind(this);\n this.enable();\n this._setupAccept();\n }\n\n public on(event: 'drop' | 'dropover' | 'dropout', callback: (event: DragEvent) => void): void {\n super.on(event, callback);\n }\n\n public off(event: 'drop' | 'dropover' | 'dropout'): void {\n super.off(event);\n }\n\n public enable(): void {\n if (this.disabled === false) return;\n super.enable();\n this.el.classList.add('ui-droppable');\n this.el.classList.remove('ui-droppable-disabled');\n this.el.addEventListener('mouseenter', this._mouseEnter);\n this.el.addEventListener('mouseleave', this._mouseLeave);\n if (isTouch) {\n this.el.addEventListener('pointerenter', pointerenter);\n this.el.addEventListener('pointerleave', pointerleave);\n }\n }\n\n public disable(forDestroy = false): void {\n if (this.disabled === true) return;\n super.disable();\n this.el.classList.remove('ui-droppable');\n if (!forDestroy) this.el.classList.add('ui-droppable-disabled');\n this.el.removeEventListener('mouseenter', this._mouseEnter);\n this.el.removeEventListener('mouseleave', this._mouseLeave);\n if (isTouch) {\n this.el.removeEventListener('pointerenter', pointerenter);\n this.el.removeEventListener('pointerleave', pointerleave);\n }\n }\n\n public destroy(): void {\n this.disable(true);\n this.el.classList.remove('ui-droppable');\n this.el.classList.remove('ui-droppable-disabled');\n super.destroy();\n }\n\n public updateOption(opts: DDDroppableOpt): DDDroppable {\n Object.keys(opts).forEach(key => this.option[key] = opts[key]);\n this._setupAccept();\n return this;\n }\n\n /** @internal called when the cursor enters our area - prepare for a possible drop and track leaving */\n protected _mouseEnter(e: MouseEvent): void {\n // console.log(`${count++} Enter ${this.el.id || (this.el as GridHTMLElement).gridstack.opts.id}`); // TEST\n if (!DDManager.dragElement) return;\n if (!this._canDrop(DDManager.dragElement.el)) return;\n e.preventDefault();\n e.stopPropagation();\n\n // make sure when we enter this, that the last one gets a leave FIRST to correctly cleanup as we don't always do\n if (DDManager.dropElement && DDManager.dropElement !== this) {\n DDManager.dropElement._mouseLeave(e as DragEvent);\n }\n DDManager.dropElement = this;\n\n const ev = Utils.initEvent<DragEvent>(e, { target: this.el, type: 'dropover' });\n if (this.option.over) {\n this.option.over(ev, this._ui(DDManager.dragElement))\n }\n this.triggerEvent('dropover', ev);\n this.el.classList.add('ui-droppable-over');\n // console.log('tracking'); // TEST\n }\n\n /** @internal called when the item is leaving our area, stop tracking if we had moving item */\n protected _mouseLeave(e: MouseEvent): void {\n // console.log(`${count++} Leave ${this.el.id || (this.el as GridHTMLElement).gridstack.opts.id}`); // TEST\n if (!DDManager.dragElement || DDManager.dropElement !== this) return;\n e.preventDefault();\n e.stopPropagation();\n\n const ev = Utils.initEvent<DragEvent>(e, { target: this.el, type: 'dropout' });\n if (this.option.out) {\n this.option.out(ev, this._ui(DDManager.dragElement))\n }\n this.triggerEvent('dropout', ev);\n\n if (DDManager.dropElement === this) {\n delete DDManager.dropElement;\n // console.log('not tracking'); // TEST\n\n // if we're still over a parent droppable, send it an enter as we don't get one from leaving nested children\n let parentDrop: DDDroppable;\n let parent: DDElementHost = this.el.parentElement;\n while (!parentDrop && parent) {\n parentDrop = parent.ddElement?.ddDroppable;\n parent = parent.parentElement;\n }\n if (parentDrop) {\n parentDrop._mouseEnter(e);\n }\n }\n }\n\n /** item is being dropped on us - called by the drag mouseup handler - this calls the client drop event */\n public drop(e: MouseEvent): void {\n e.preventDefault();\n const ev = Utils.initEvent<DragEvent>(e, { target: this.el, type: 'drop' });\n if (this.option.drop) {\n this.option.drop(ev, this._ui(DDManager.dragElement))\n }\n this.triggerEvent('drop', ev);\n }\n\n /** @internal true if element matches the string/method accept option */\n protected _canDrop(el: HTMLElement): boolean {\n return el && (!this.accept || this.accept(el));\n }\n\n /** @internal */\n protected _setupAccept(): DDDroppable {\n if (!this.option.accept) return this;\n if (typeof this.option.accept === 'string') {\n this.accept = (el: HTMLElement) => el.matches(this.option.accept as string);\n } else {\n this.accept = this.option.accept;\n }\n return this;\n }\n\n /** @internal */\n protected _ui(drag: DDDraggable): DDUIData {\n return {\n draggable: drag.el,\n ...drag.ui()\n };\n }\n}\n\n"]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dd-elements.ts 7.3.0-dev
|
|
3
|
+
* Copyright (c) 2021 Alain Dumesny - see GridStack root license
|
|
4
|
+
*/
|
|
5
|
+
import { DDResizable, DDResizableOpt } from './dd-resizable';
|
|
6
|
+
import { GridItemHTMLElement } from './types';
|
|
7
|
+
import { DDDraggable, DDDraggableOpt } from './dd-draggable';
|
|
8
|
+
import { DDDroppable, DDDroppableOpt } from './dd-droppable';
|
|
9
|
+
export interface DDElementHost extends GridItemHTMLElement {
|
|
10
|
+
ddElement?: DDElement;
|
|
11
|
+
}
|
|
12
|
+
export declare class DDElement {
|
|
13
|
+
static init(el: DDElementHost): DDElement;
|
|
14
|
+
el: DDElementHost;
|
|
15
|
+
ddDraggable?: DDDraggable;
|
|
16
|
+
ddDroppable?: DDDroppable;
|
|
17
|
+
ddResizable?: DDResizable;
|
|
18
|
+
constructor(el: DDElementHost);
|
|
19
|
+
on(eventName: string, callback: (event: MouseEvent) => void): DDElement;
|
|
20
|
+
off(eventName: string): DDElement;
|
|
21
|
+
setupDraggable(opts: DDDraggableOpt): DDElement;
|
|
22
|
+
cleanDraggable(): DDElement;
|
|
23
|
+
setupResizable(opts: DDResizableOpt): DDElement;
|
|
24
|
+
cleanResizable(): DDElement;
|
|
25
|
+
setupDroppable(opts: DDDroppableOpt): DDElement;
|
|
26
|
+
cleanDroppable(): DDElement;
|
|
27
|
+
}
|