@antv/g-plugin-dragndrop 1.6.51 → 1.7.0-beta.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/dist/DragndropPlugin.d.ts +8 -9
- package/dist/index.d.ts +10 -11
- package/dist/index.esm.js +153 -528
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +153 -530
- package/dist/index.js.map +1 -0
- package/dist/index.umd.min.js +2 -1
- package/dist/index.umd.min.js.map +1 -0
- package/dist/interfaces.d.ts +27 -28
- package/package.json +15 -13
- package/dist/DragndropPlugin.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.umd.js +0 -553
- package/dist/interfaces.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,546 +1,169 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
var tslib = require('tslib');
|
|
5
4
|
var gLite = require('@antv/g-lite');
|
|
6
5
|
var util = require('@antv/util');
|
|
7
6
|
|
|
8
|
-
function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
};
|
|
12
|
-
var exports = {},
|
|
13
|
-
Op = Object.prototype,
|
|
14
|
-
hasOwn = Op.hasOwnProperty,
|
|
15
|
-
defineProperty = Object.defineProperty || function (obj, key, desc) {
|
|
16
|
-
obj[key] = desc.value;
|
|
17
|
-
},
|
|
18
|
-
$Symbol = "function" == typeof Symbol ? Symbol : {},
|
|
19
|
-
iteratorSymbol = $Symbol.iterator || "@@iterator",
|
|
20
|
-
asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator",
|
|
21
|
-
toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
|
|
22
|
-
function define(obj, key, value) {
|
|
23
|
-
return Object.defineProperty(obj, key, {
|
|
24
|
-
value: value,
|
|
25
|
-
enumerable: !0,
|
|
26
|
-
configurable: !0,
|
|
27
|
-
writable: !0
|
|
28
|
-
}), obj[key];
|
|
29
|
-
}
|
|
30
|
-
try {
|
|
31
|
-
define({}, "");
|
|
32
|
-
} catch (err) {
|
|
33
|
-
define = function (obj, key, value) {
|
|
34
|
-
return obj[key] = value;
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function wrap(innerFn, outerFn, self, tryLocsList) {
|
|
38
|
-
var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator,
|
|
39
|
-
generator = Object.create(protoGenerator.prototype),
|
|
40
|
-
context = new Context(tryLocsList || []);
|
|
41
|
-
return defineProperty(generator, "_invoke", {
|
|
42
|
-
value: makeInvokeMethod(innerFn, self, context)
|
|
43
|
-
}), generator;
|
|
44
|
-
}
|
|
45
|
-
function tryCatch(fn, obj, arg) {
|
|
46
|
-
try {
|
|
47
|
-
return {
|
|
48
|
-
type: "normal",
|
|
49
|
-
arg: fn.call(obj, arg)
|
|
50
|
-
};
|
|
51
|
-
} catch (err) {
|
|
52
|
-
return {
|
|
53
|
-
type: "throw",
|
|
54
|
-
arg: err
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
exports.wrap = wrap;
|
|
59
|
-
var ContinueSentinel = {};
|
|
60
|
-
function Generator() {}
|
|
61
|
-
function GeneratorFunction() {}
|
|
62
|
-
function GeneratorFunctionPrototype() {}
|
|
63
|
-
var IteratorPrototype = {};
|
|
64
|
-
define(IteratorPrototype, iteratorSymbol, function () {
|
|
65
|
-
return this;
|
|
66
|
-
});
|
|
67
|
-
var getProto = Object.getPrototypeOf,
|
|
68
|
-
NativeIteratorPrototype = getProto && getProto(getProto(values([])));
|
|
69
|
-
NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype);
|
|
70
|
-
var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype);
|
|
71
|
-
function defineIteratorMethods(prototype) {
|
|
72
|
-
["next", "throw", "return"].forEach(function (method) {
|
|
73
|
-
define(prototype, method, function (arg) {
|
|
74
|
-
return this._invoke(method, arg);
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
function AsyncIterator(generator, PromiseImpl) {
|
|
79
|
-
function invoke(method, arg, resolve, reject) {
|
|
80
|
-
var record = tryCatch(generator[method], generator, arg);
|
|
81
|
-
if ("throw" !== record.type) {
|
|
82
|
-
var result = record.arg,
|
|
83
|
-
value = result.value;
|
|
84
|
-
return value && "object" == typeof value && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) {
|
|
85
|
-
invoke("next", value, resolve, reject);
|
|
86
|
-
}, function (err) {
|
|
87
|
-
invoke("throw", err, resolve, reject);
|
|
88
|
-
}) : PromiseImpl.resolve(value).then(function (unwrapped) {
|
|
89
|
-
result.value = unwrapped, resolve(result);
|
|
90
|
-
}, function (error) {
|
|
91
|
-
return invoke("throw", error, resolve, reject);
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
reject(record.arg);
|
|
95
|
-
}
|
|
96
|
-
var previousPromise;
|
|
97
|
-
defineProperty(this, "_invoke", {
|
|
98
|
-
value: function (method, arg) {
|
|
99
|
-
function callInvokeWithMethodAndArg() {
|
|
100
|
-
return new PromiseImpl(function (resolve, reject) {
|
|
101
|
-
invoke(method, arg, resolve, reject);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
|
|
105
|
-
}
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
function makeInvokeMethod(innerFn, self, context) {
|
|
109
|
-
var state = "suspendedStart";
|
|
110
|
-
return function (method, arg) {
|
|
111
|
-
if ("executing" === state) throw new Error("Generator is already running");
|
|
112
|
-
if ("completed" === state) {
|
|
113
|
-
if ("throw" === method) throw arg;
|
|
114
|
-
return doneResult();
|
|
115
|
-
}
|
|
116
|
-
for (context.method = method, context.arg = arg;;) {
|
|
117
|
-
var delegate = context.delegate;
|
|
118
|
-
if (delegate) {
|
|
119
|
-
var delegateResult = maybeInvokeDelegate(delegate, context);
|
|
120
|
-
if (delegateResult) {
|
|
121
|
-
if (delegateResult === ContinueSentinel) continue;
|
|
122
|
-
return delegateResult;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) {
|
|
126
|
-
if ("suspendedStart" === state) throw state = "completed", context.arg;
|
|
127
|
-
context.dispatchException(context.arg);
|
|
128
|
-
} else "return" === context.method && context.abrupt("return", context.arg);
|
|
129
|
-
state = "executing";
|
|
130
|
-
var record = tryCatch(innerFn, self, context);
|
|
131
|
-
if ("normal" === record.type) {
|
|
132
|
-
if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue;
|
|
133
|
-
return {
|
|
134
|
-
value: record.arg,
|
|
135
|
-
done: context.done
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
"throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg);
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
function maybeInvokeDelegate(delegate, context) {
|
|
143
|
-
var methodName = context.method,
|
|
144
|
-
method = delegate.iterator[methodName];
|
|
145
|
-
if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel;
|
|
146
|
-
var record = tryCatch(method, delegate.iterator, context.arg);
|
|
147
|
-
if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel;
|
|
148
|
-
var info = record.arg;
|
|
149
|
-
return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel);
|
|
150
|
-
}
|
|
151
|
-
function pushTryEntry(locs) {
|
|
152
|
-
var entry = {
|
|
153
|
-
tryLoc: locs[0]
|
|
154
|
-
};
|
|
155
|
-
1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry);
|
|
156
|
-
}
|
|
157
|
-
function resetTryEntry(entry) {
|
|
158
|
-
var record = entry.completion || {};
|
|
159
|
-
record.type = "normal", delete record.arg, entry.completion = record;
|
|
160
|
-
}
|
|
161
|
-
function Context(tryLocsList) {
|
|
162
|
-
this.tryEntries = [{
|
|
163
|
-
tryLoc: "root"
|
|
164
|
-
}], tryLocsList.forEach(pushTryEntry, this), this.reset(!0);
|
|
165
|
-
}
|
|
166
|
-
function values(iterable) {
|
|
167
|
-
if (iterable) {
|
|
168
|
-
var iteratorMethod = iterable[iteratorSymbol];
|
|
169
|
-
if (iteratorMethod) return iteratorMethod.call(iterable);
|
|
170
|
-
if ("function" == typeof iterable.next) return iterable;
|
|
171
|
-
if (!isNaN(iterable.length)) {
|
|
172
|
-
var i = -1,
|
|
173
|
-
next = function next() {
|
|
174
|
-
for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next;
|
|
175
|
-
return next.value = undefined, next.done = !0, next;
|
|
176
|
-
};
|
|
177
|
-
return next.next = next;
|
|
178
|
-
}
|
|
7
|
+
var DragndropPlugin = /** @class */ (function () {
|
|
8
|
+
function DragndropPlugin(dragndropPluginOptions) {
|
|
9
|
+
this.dragndropPluginOptions = dragndropPluginOptions;
|
|
179
10
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
throw new Error("illegal catch attempt");
|
|
299
|
-
},
|
|
300
|
-
delegateYield: function (iterable, resultName, nextLoc) {
|
|
301
|
-
return this.delegate = {
|
|
302
|
-
iterator: values(iterable),
|
|
303
|
-
resultName: resultName,
|
|
304
|
-
nextLoc: nextLoc
|
|
305
|
-
}, "next" === this.method && (this.arg = undefined), ContinueSentinel;
|
|
306
|
-
}
|
|
307
|
-
}, exports;
|
|
308
|
-
}
|
|
309
|
-
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
310
|
-
try {
|
|
311
|
-
var info = gen[key](arg);
|
|
312
|
-
var value = info.value;
|
|
313
|
-
} catch (error) {
|
|
314
|
-
reject(error);
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
if (info.done) {
|
|
318
|
-
resolve(value);
|
|
319
|
-
} else {
|
|
320
|
-
Promise.resolve(value).then(_next, _throw);
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
function _asyncToGenerator(fn) {
|
|
324
|
-
return function () {
|
|
325
|
-
var self = this,
|
|
326
|
-
args = arguments;
|
|
327
|
-
return new Promise(function (resolve, reject) {
|
|
328
|
-
var gen = fn.apply(self, args);
|
|
329
|
-
function _next(value) {
|
|
330
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
|
|
331
|
-
}
|
|
332
|
-
function _throw(err) {
|
|
333
|
-
asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
|
|
334
|
-
}
|
|
335
|
-
_next(undefined);
|
|
336
|
-
});
|
|
337
|
-
};
|
|
338
|
-
}
|
|
339
|
-
function _extends() {
|
|
340
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
341
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
342
|
-
var source = arguments[i];
|
|
343
|
-
for (var key in source) {
|
|
344
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
345
|
-
target[key] = source[key];
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
return target;
|
|
350
|
-
};
|
|
351
|
-
return _extends.apply(this, arguments);
|
|
352
|
-
}
|
|
353
|
-
function _inheritsLoose(subClass, superClass) {
|
|
354
|
-
subClass.prototype = Object.create(superClass.prototype);
|
|
355
|
-
subClass.prototype.constructor = subClass;
|
|
356
|
-
_setPrototypeOf(subClass, superClass);
|
|
357
|
-
}
|
|
358
|
-
function _setPrototypeOf(o, p) {
|
|
359
|
-
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
360
|
-
o.__proto__ = p;
|
|
361
|
-
return o;
|
|
362
|
-
};
|
|
363
|
-
return _setPrototypeOf(o, p);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
var DragndropPlugin = /*#__PURE__*/function () {
|
|
367
|
-
function DragndropPlugin(dragndropPluginOptions) {
|
|
368
|
-
this.dragndropPluginOptions = void 0;
|
|
369
|
-
this.dragndropPluginOptions = dragndropPluginOptions;
|
|
370
|
-
}
|
|
371
|
-
var _proto = DragndropPlugin.prototype;
|
|
372
|
-
_proto.apply = function apply(context) {
|
|
373
|
-
var _this = this;
|
|
374
|
-
var renderingService = context.renderingService,
|
|
375
|
-
renderingContext = context.renderingContext;
|
|
376
|
-
var document = renderingContext.root.ownerDocument;
|
|
377
|
-
// TODO: should we add an option like `draggable` to Canvas
|
|
378
|
-
var canvas = document.defaultView;
|
|
379
|
-
var handlePointerdown = function handlePointerdown(event) {
|
|
380
|
-
var target = event.target;
|
|
381
|
-
var isDocument = target === document;
|
|
382
|
-
var draggableEventTarget = isDocument && _this.dragndropPluginOptions.isDocumentDraggable ? document : target.closest && target.closest('[draggable=true]');
|
|
383
|
-
// `draggable` may be set on ancestor nodes:
|
|
384
|
-
// @see https://github.com/antvis/G/issues/1088
|
|
385
|
-
if (draggableEventTarget) {
|
|
386
|
-
// delay triggering dragstart event
|
|
387
|
-
var dragstartTriggered = false;
|
|
388
|
-
var dragstartTimeStamp = event.timeStamp;
|
|
389
|
-
var dragstartClientCoordinates = [event.clientX, event.clientY];
|
|
390
|
-
var currentDroppable = null;
|
|
391
|
-
var lastDragClientCoordinates = [event.clientX, event.clientY];
|
|
392
|
-
// @ts-ignore
|
|
393
|
-
// eslint-disable-next-line no-inner-declarations
|
|
394
|
-
var handlePointermove = /*#__PURE__*/function () {
|
|
395
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(event) {
|
|
396
|
-
var timeElapsed, distanceMoved, point, elementsBelow, elementBelow, droppableBelow;
|
|
397
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
398
|
-
while (1) switch (_context.prev = _context.next) {
|
|
399
|
-
case 0:
|
|
400
|
-
if (dragstartTriggered) {
|
|
401
|
-
_context.next = 8;
|
|
402
|
-
break;
|
|
403
|
-
}
|
|
404
|
-
timeElapsed = event.timeStamp - dragstartTimeStamp;
|
|
405
|
-
distanceMoved = util.distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates); // check thresholds
|
|
406
|
-
if (!(timeElapsed <= _this.dragndropPluginOptions.dragstartTimeThreshold || distanceMoved <= _this.dragndropPluginOptions.dragstartDistanceThreshold)) {
|
|
407
|
-
_context.next = 5;
|
|
408
|
-
break;
|
|
409
|
-
}
|
|
410
|
-
return _context.abrupt("return");
|
|
411
|
-
case 5:
|
|
412
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
|
|
413
|
-
event.type = 'dragstart';
|
|
414
|
-
draggableEventTarget.dispatchEvent(event);
|
|
415
|
-
dragstartTriggered = true;
|
|
416
|
-
case 8:
|
|
417
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
|
|
418
|
-
event.type = 'drag';
|
|
419
|
-
// @ts-ignore
|
|
420
|
-
event.dx = event.clientX - lastDragClientCoordinates[0];
|
|
421
|
-
// @ts-ignore
|
|
422
|
-
event.dy = event.clientY - lastDragClientCoordinates[1];
|
|
423
|
-
draggableEventTarget.dispatchEvent(event);
|
|
424
|
-
lastDragClientCoordinates = [event.clientX, event.clientY];
|
|
425
|
-
if (isDocument) {
|
|
426
|
-
_context.next = 21;
|
|
427
|
-
break;
|
|
428
|
-
}
|
|
429
|
-
point = _this.dragndropPluginOptions.overlap === 'pointer' ? [event.canvasX, event.canvasY] : target.getBounds().center;
|
|
430
|
-
_context.next = 17;
|
|
431
|
-
return document.elementsFromPoint(point[0], point[1]);
|
|
432
|
-
case 17:
|
|
433
|
-
elementsBelow = _context.sent;
|
|
434
|
-
// prevent from picking the dragging element
|
|
435
|
-
elementBelow = elementsBelow[elementsBelow.indexOf(target) + 1];
|
|
436
|
-
droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) || (_this.dragndropPluginOptions.isDocumentDroppable ? document : null);
|
|
437
|
-
if (currentDroppable !== droppableBelow) {
|
|
438
|
-
if (currentDroppable) {
|
|
439
|
-
// null when we were not over a droppable before this event
|
|
440
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
441
|
-
event.type = 'dragleave';
|
|
442
|
-
event.target = currentDroppable;
|
|
443
|
-
currentDroppable.dispatchEvent(event);
|
|
444
|
-
}
|
|
445
|
-
if (droppableBelow) {
|
|
446
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
447
|
-
event.type = 'dragenter';
|
|
448
|
-
event.target = droppableBelow;
|
|
449
|
-
droppableBelow.dispatchEvent(event);
|
|
11
|
+
DragndropPlugin.prototype.apply = function (context) {
|
|
12
|
+
var _this = this;
|
|
13
|
+
var renderingService = context.renderingService, renderingContext = context.renderingContext;
|
|
14
|
+
var document = renderingContext.root.ownerDocument;
|
|
15
|
+
// TODO: should we add an option like `draggable` to Canvas
|
|
16
|
+
var canvas = document.defaultView;
|
|
17
|
+
var handlePointerdown = function (event) {
|
|
18
|
+
var target = event.target;
|
|
19
|
+
var isDocument = target === document;
|
|
20
|
+
var draggableEventTarget = isDocument && _this.dragndropPluginOptions.isDocumentDraggable
|
|
21
|
+
? document
|
|
22
|
+
: target.closest && target.closest('[draggable=true]');
|
|
23
|
+
// `draggable` may be set on ancestor nodes:
|
|
24
|
+
// @see https://github.com/antvis/G/issues/1088
|
|
25
|
+
if (draggableEventTarget) {
|
|
26
|
+
// delay triggering dragstart event
|
|
27
|
+
var dragstartTriggered_1 = false;
|
|
28
|
+
var dragstartTimeStamp_1 = event.timeStamp;
|
|
29
|
+
var dragstartClientCoordinates_1 = [
|
|
30
|
+
event.clientX,
|
|
31
|
+
event.clientY,
|
|
32
|
+
];
|
|
33
|
+
var currentDroppable_1 = null;
|
|
34
|
+
var lastDragClientCoordinates_1 = [event.clientX, event.clientY];
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
// eslint-disable-next-line no-inner-declarations
|
|
37
|
+
var handlePointermove_1 = function (event) { return tslib.__awaiter(_this, void 0, void 0, function () {
|
|
38
|
+
var timeElapsed, distanceMoved, point, elementsBelow, elementBelow, droppableBelow;
|
|
39
|
+
return tslib.__generator(this, function (_a) {
|
|
40
|
+
switch (_a.label) {
|
|
41
|
+
case 0:
|
|
42
|
+
if (!dragstartTriggered_1) {
|
|
43
|
+
timeElapsed = event.timeStamp - dragstartTimeStamp_1;
|
|
44
|
+
distanceMoved = util.distanceSquareRoot([event.clientX, event.clientY], dragstartClientCoordinates_1);
|
|
45
|
+
// check thresholds
|
|
46
|
+
if (timeElapsed <=
|
|
47
|
+
this.dragndropPluginOptions.dragstartTimeThreshold ||
|
|
48
|
+
distanceMoved <=
|
|
49
|
+
this.dragndropPluginOptions.dragstartDistanceThreshold) {
|
|
50
|
+
return [2 /*return*/];
|
|
51
|
+
}
|
|
52
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragstart_event
|
|
53
|
+
event.type = 'dragstart';
|
|
54
|
+
draggableEventTarget.dispatchEvent(event);
|
|
55
|
+
dragstartTriggered_1 = true;
|
|
56
|
+
}
|
|
57
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drag_event
|
|
58
|
+
event.type = 'drag';
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
event.dx = event.clientX - lastDragClientCoordinates_1[0];
|
|
61
|
+
// @ts-ignore
|
|
62
|
+
event.dy = event.clientY - lastDragClientCoordinates_1[1];
|
|
63
|
+
draggableEventTarget.dispatchEvent(event);
|
|
64
|
+
lastDragClientCoordinates_1 = [event.clientX, event.clientY];
|
|
65
|
+
if (!!isDocument) return [3 /*break*/, 2];
|
|
66
|
+
point = this.dragndropPluginOptions.overlap === 'pointer'
|
|
67
|
+
? [event.canvasX, event.canvasY]
|
|
68
|
+
: target.getBounds().center;
|
|
69
|
+
return [4 /*yield*/, document.elementsFromPoint(point[0], point[1])];
|
|
70
|
+
case 1:
|
|
71
|
+
elementsBelow = _a.sent();
|
|
72
|
+
elementBelow = elementsBelow[elementsBelow.indexOf(target) + 1];
|
|
73
|
+
droppableBelow = (elementBelow === null || elementBelow === void 0 ? void 0 : elementBelow.closest('[droppable=true]')) ||
|
|
74
|
+
(this.dragndropPluginOptions.isDocumentDroppable
|
|
75
|
+
? document
|
|
76
|
+
: null);
|
|
77
|
+
if (currentDroppable_1 !== droppableBelow) {
|
|
78
|
+
if (currentDroppable_1) {
|
|
79
|
+
// null when we were not over a droppable before this event
|
|
80
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
81
|
+
event.type = 'dragleave';
|
|
82
|
+
event.target = currentDroppable_1;
|
|
83
|
+
currentDroppable_1.dispatchEvent(event);
|
|
84
|
+
}
|
|
85
|
+
if (droppableBelow) {
|
|
86
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragleave_event
|
|
87
|
+
event.type = 'dragenter';
|
|
88
|
+
event.target = droppableBelow;
|
|
89
|
+
droppableBelow.dispatchEvent(event);
|
|
90
|
+
}
|
|
91
|
+
currentDroppable_1 = droppableBelow;
|
|
92
|
+
if (currentDroppable_1) {
|
|
93
|
+
// null if we're not coming over a droppable now
|
|
94
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragover_event
|
|
95
|
+
event.type = 'dragover';
|
|
96
|
+
event.target = currentDroppable_1;
|
|
97
|
+
currentDroppable_1.dispatchEvent(event);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
_a.label = 2;
|
|
101
|
+
case 2: return [2 /*return*/];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}); };
|
|
105
|
+
canvas.addEventListener('pointermove', handlePointermove_1);
|
|
106
|
+
var stopDragging = function (originalPointerUpEvent) {
|
|
107
|
+
if (dragstartTriggered_1) {
|
|
108
|
+
// prevent click event being triggerd
|
|
109
|
+
// @see https://github.com/antvis/G/issues/1091
|
|
110
|
+
originalPointerUpEvent.detail = {
|
|
111
|
+
preventClick: true,
|
|
112
|
+
};
|
|
113
|
+
// clone event first
|
|
114
|
+
var event_1 = originalPointerUpEvent.clone();
|
|
115
|
+
// drop should fire before dragend
|
|
116
|
+
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/
|
|
117
|
+
if (currentDroppable_1) {
|
|
118
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event
|
|
119
|
+
event_1.type = 'drop';
|
|
120
|
+
event_1.target = currentDroppable_1;
|
|
121
|
+
currentDroppable_1.dispatchEvent(event_1);
|
|
122
|
+
}
|
|
123
|
+
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
|
|
124
|
+
event_1.type = 'dragend';
|
|
125
|
+
draggableEventTarget.dispatchEvent(event_1);
|
|
126
|
+
dragstartTriggered_1 = false;
|
|
450
127
|
}
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
currentDroppable.dispatchEvent(event);
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
case 21:
|
|
461
|
-
case "end":
|
|
462
|
-
return _context.stop();
|
|
463
|
-
}
|
|
464
|
-
}, _callee);
|
|
465
|
-
}));
|
|
466
|
-
return function handlePointermove(_x) {
|
|
467
|
-
return _ref.apply(this, arguments);
|
|
468
|
-
};
|
|
469
|
-
}();
|
|
470
|
-
canvas.addEventListener('pointermove', handlePointermove);
|
|
471
|
-
var stopDragging = function stopDragging(originalPointerUpEvent) {
|
|
472
|
-
if (dragstartTriggered) {
|
|
473
|
-
// prevent click event being triggerd
|
|
474
|
-
// @see https://github.com/antvis/G/issues/1091
|
|
475
|
-
originalPointerUpEvent.detail = {
|
|
476
|
-
preventClick: true
|
|
477
|
-
};
|
|
478
|
-
// clone event first
|
|
479
|
-
var _event = originalPointerUpEvent.clone();
|
|
480
|
-
// drop should fire before dragend
|
|
481
|
-
// @see https://javascript.tutorialink.com/is-there-a-defined-ordering-between-dragend-and-drop-events/
|
|
482
|
-
if (currentDroppable) {
|
|
483
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/drop_event
|
|
484
|
-
_event.type = 'drop';
|
|
485
|
-
_event.target = currentDroppable;
|
|
486
|
-
currentDroppable.dispatchEvent(_event);
|
|
128
|
+
canvas.removeEventListener('pointermove', handlePointermove_1);
|
|
129
|
+
};
|
|
130
|
+
target.addEventListener('pointerup', stopDragging, { once: true });
|
|
131
|
+
target.addEventListener('pointerupoutside', stopDragging, {
|
|
132
|
+
once: true,
|
|
133
|
+
});
|
|
487
134
|
}
|
|
488
|
-
// @see https://developer.mozilla.org/zh-CN/docs/Web/API/Document/dragend_event
|
|
489
|
-
_event.type = 'dragend';
|
|
490
|
-
draggableEventTarget.dispatchEvent(_event);
|
|
491
|
-
dragstartTriggered = false;
|
|
492
|
-
}
|
|
493
|
-
canvas.removeEventListener('pointermove', handlePointermove);
|
|
494
135
|
};
|
|
495
|
-
|
|
496
|
-
|
|
136
|
+
renderingService.hooks.init.tap(DragndropPlugin.tag, function () {
|
|
137
|
+
canvas.addEventListener('pointerdown', handlePointerdown);
|
|
497
138
|
});
|
|
498
|
-
|
|
499
|
-
|
|
139
|
+
renderingService.hooks.destroy.tap(DragndropPlugin.tag, function () {
|
|
140
|
+
canvas.removeEventListener('pointerdown', handlePointerdown);
|
|
500
141
|
});
|
|
501
|
-
}
|
|
502
142
|
};
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
renderingService.hooks.destroy.tap(DragndropPlugin.tag, function () {
|
|
507
|
-
canvas.removeEventListener('pointerdown', handlePointerdown);
|
|
508
|
-
});
|
|
509
|
-
};
|
|
510
|
-
return DragndropPlugin;
|
|
511
|
-
}();
|
|
512
|
-
DragndropPlugin.tag = 'Dragndrop';
|
|
143
|
+
DragndropPlugin.tag = 'Dragndrop';
|
|
144
|
+
return DragndropPlugin;
|
|
145
|
+
}());
|
|
513
146
|
|
|
514
|
-
var Plugin =
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
147
|
+
var Plugin = /** @class */ (function (_super) {
|
|
148
|
+
tslib.__extends(Plugin, _super);
|
|
149
|
+
function Plugin(options) {
|
|
150
|
+
if (options === void 0) { options = {}; }
|
|
151
|
+
var _this = _super.call(this) || this;
|
|
152
|
+
_this.options = options;
|
|
153
|
+
_this.name = 'dragndrop';
|
|
154
|
+
return _this;
|
|
520
155
|
}
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
isDocumentDroppable: false,
|
|
533
|
-
dragstartDistanceThreshold: 0,
|
|
534
|
-
dragstartTimeThreshold: 0
|
|
535
|
-
}, this.options)));
|
|
536
|
-
};
|
|
537
|
-
_proto.destroy = function destroy() {
|
|
538
|
-
this.removeAllRenderingPlugins();
|
|
539
|
-
};
|
|
540
|
-
_proto.setOptions = function setOptions(options) {
|
|
541
|
-
Object.assign(this.plugins[0].dragndropPluginOptions, options);
|
|
542
|
-
};
|
|
543
|
-
return Plugin;
|
|
544
|
-
}(gLite.AbstractRendererPlugin);
|
|
156
|
+
Plugin.prototype.init = function () {
|
|
157
|
+
this.addRenderingPlugin(new DragndropPlugin(tslib.__assign({ overlap: 'pointer', isDocumentDraggable: false, isDocumentDroppable: false, dragstartDistanceThreshold: 0, dragstartTimeThreshold: 0 }, this.options)));
|
|
158
|
+
};
|
|
159
|
+
Plugin.prototype.destroy = function () {
|
|
160
|
+
this.removeAllRenderingPlugins();
|
|
161
|
+
};
|
|
162
|
+
Plugin.prototype.setOptions = function (options) {
|
|
163
|
+
Object.assign(this.plugins[0].dragndropPluginOptions, options);
|
|
164
|
+
};
|
|
165
|
+
return Plugin;
|
|
166
|
+
}(gLite.AbstractRendererPlugin));
|
|
545
167
|
|
|
546
168
|
exports.Plugin = Plugin;
|
|
169
|
+
//# sourceMappingURL=index.js.map
|