@rkmodules/rules 0.0.62 → 0.0.64

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/index.esm.js CHANGED
@@ -6,7 +6,6 @@ import classNames from 'classnames';
6
6
  import rcin from 'rc-input-number';
7
7
  import { create as create$1 } from 'zustand';
8
8
  import { persist } from 'zustand/middleware';
9
- import { HTML5Backend } from 'react-dnd-html5-backend';
10
9
  import { jsx } from 'react/jsx-runtime';
11
10
 
12
11
  /******************************************************************************
@@ -559,7 +558,10 @@ var getValue = {
559
558
  paths = toArray(inputs.path || {});
560
559
  tree = mapTree(inputs.tree, function (value) {
561
560
  // get the property from the object
562
- return getValue$1(value, paths[0]);
561
+ var val = getValue$1(value, paths[0]);
562
+ if (val === undefined)
563
+ return DISCARD;
564
+ return val;
563
565
  });
564
566
  return [2 /*return*/, { tree: tree }];
565
567
  });
@@ -2089,7 +2091,7 @@ function isProduction() {
2089
2091
  }
2090
2092
  /**
2091
2093
  * drop-in replacement for _.without
2092
- */ function without(items, item) {
2094
+ */ function without$1(items, item) {
2093
2095
  return items.filter((i)=>i !== item
2094
2096
  );
2095
2097
  }
@@ -2223,7 +2225,7 @@ function getDraggableSource(sourceIds, monitor) {
2223
2225
  return sourceId;
2224
2226
  }
2225
2227
 
2226
- function _defineProperty$3(obj, key, value) {
2228
+ function _defineProperty$4(obj, key, value) {
2227
2229
  if (key in obj) {
2228
2230
  Object.defineProperty(obj, key, {
2229
2231
  value: value,
@@ -2236,7 +2238,7 @@ function _defineProperty$3(obj, key, value) {
2236
2238
  }
2237
2239
  return obj;
2238
2240
  }
2239
- function _objectSpread$3(target) {
2241
+ function _objectSpread$4(target) {
2240
2242
  for(var i = 1; i < arguments.length; i++){
2241
2243
  var source = arguments[i] != null ? arguments[i] : {};
2242
2244
  var ownKeys = Object.keys(source);
@@ -2246,7 +2248,7 @@ function _objectSpread$3(target) {
2246
2248
  }));
2247
2249
  }
2248
2250
  ownKeys.forEach(function(key) {
2249
- _defineProperty$3(target, key, source[key]);
2251
+ _defineProperty$4(target, key, source[key]);
2250
2252
  });
2251
2253
  }
2252
2254
  return target;
@@ -2263,7 +2265,7 @@ function createDrop(manager) {
2263
2265
  const action = {
2264
2266
  type: DROP,
2265
2267
  payload: {
2266
- dropResult: _objectSpread$3({}, options, dropResult)
2268
+ dropResult: _objectSpread$4({}, options, dropResult)
2267
2269
  }
2268
2270
  };
2269
2271
  manager.dispatch(action);
@@ -3178,7 +3180,7 @@ _state = NONE, action) {
3178
3180
  return result;
3179
3181
  }
3180
3182
 
3181
- function _defineProperty$2(obj, key, value) {
3183
+ function _defineProperty$3(obj, key, value) {
3182
3184
  if (key in obj) {
3183
3185
  Object.defineProperty(obj, key, {
3184
3186
  value: value,
@@ -3191,7 +3193,7 @@ function _defineProperty$2(obj, key, value) {
3191
3193
  }
3192
3194
  return obj;
3193
3195
  }
3194
- function _objectSpread$2(target) {
3196
+ function _objectSpread$3(target) {
3195
3197
  for(var i = 1; i < arguments.length; i++){
3196
3198
  var source = arguments[i] != null ? arguments[i] : {};
3197
3199
  var ownKeys = Object.keys(source);
@@ -3201,7 +3203,7 @@ function _objectSpread$2(target) {
3201
3203
  }));
3202
3204
  }
3203
3205
  ownKeys.forEach(function(key) {
3204
- _defineProperty$2(target, key, source[key]);
3206
+ _defineProperty$3(target, key, source[key]);
3205
3207
  });
3206
3208
  }
3207
3209
  return target;
@@ -3225,7 +3227,7 @@ function reduce$4(state = initialState$1, action) {
3225
3227
  if (areCoordsEqual(state.clientOffset, payload.clientOffset)) {
3226
3228
  return state;
3227
3229
  }
3228
- return _objectSpread$2({}, state, {
3230
+ return _objectSpread$3({}, state, {
3229
3231
  clientOffset: payload.clientOffset
3230
3232
  });
3231
3233
  case END_DRAG:
@@ -3236,7 +3238,7 @@ function reduce$4(state = initialState$1, action) {
3236
3238
  }
3237
3239
  }
3238
3240
 
3239
- function _defineProperty$1(obj, key, value) {
3241
+ function _defineProperty$2(obj, key, value) {
3240
3242
  if (key in obj) {
3241
3243
  Object.defineProperty(obj, key, {
3242
3244
  value: value,
@@ -3249,7 +3251,7 @@ function _defineProperty$1(obj, key, value) {
3249
3251
  }
3250
3252
  return obj;
3251
3253
  }
3252
- function _objectSpread$1(target) {
3254
+ function _objectSpread$2(target) {
3253
3255
  for(var i = 1; i < arguments.length; i++){
3254
3256
  var source = arguments[i] != null ? arguments[i] : {};
3255
3257
  var ownKeys = Object.keys(source);
@@ -3259,7 +3261,7 @@ function _objectSpread$1(target) {
3259
3261
  }));
3260
3262
  }
3261
3263
  ownKeys.forEach(function(key) {
3262
- _defineProperty$1(target, key, source[key]);
3264
+ _defineProperty$2(target, key, source[key]);
3263
3265
  });
3264
3266
  }
3265
3267
  return target;
@@ -3277,7 +3279,7 @@ function reduce$3(state = initialState, action) {
3277
3279
  const { payload } = action;
3278
3280
  switch(action.type){
3279
3281
  case BEGIN_DRAG:
3280
- return _objectSpread$1({}, state, {
3282
+ return _objectSpread$2({}, state, {
3281
3283
  itemType: payload.itemType,
3282
3284
  item: payload.item,
3283
3285
  sourceId: payload.sourceId,
@@ -3286,28 +3288,28 @@ function reduce$3(state = initialState, action) {
3286
3288
  didDrop: false
3287
3289
  });
3288
3290
  case PUBLISH_DRAG_SOURCE:
3289
- return _objectSpread$1({}, state, {
3291
+ return _objectSpread$2({}, state, {
3290
3292
  isSourcePublic: true
3291
3293
  });
3292
3294
  case HOVER:
3293
- return _objectSpread$1({}, state, {
3295
+ return _objectSpread$2({}, state, {
3294
3296
  targetIds: payload.targetIds
3295
3297
  });
3296
3298
  case REMOVE_TARGET:
3297
3299
  if (state.targetIds.indexOf(payload.targetId) === -1) {
3298
3300
  return state;
3299
3301
  }
3300
- return _objectSpread$1({}, state, {
3301
- targetIds: without(state.targetIds, payload.targetId)
3302
+ return _objectSpread$2({}, state, {
3303
+ targetIds: without$1(state.targetIds, payload.targetId)
3302
3304
  });
3303
3305
  case DROP:
3304
- return _objectSpread$1({}, state, {
3306
+ return _objectSpread$2({}, state, {
3305
3307
  dropResult: payload.dropResult,
3306
3308
  didDrop: true,
3307
3309
  targetIds: []
3308
3310
  });
3309
3311
  case END_DRAG:
3310
- return _objectSpread$1({}, state, {
3312
+ return _objectSpread$2({}, state, {
3311
3313
  itemType: null,
3312
3314
  item: null,
3313
3315
  sourceId: null,
@@ -3338,7 +3340,7 @@ function reduce$1(state = 0) {
3338
3340
  return state + 1;
3339
3341
  }
3340
3342
 
3341
- function _defineProperty(obj, key, value) {
3343
+ function _defineProperty$1(obj, key, value) {
3342
3344
  if (key in obj) {
3343
3345
  Object.defineProperty(obj, key, {
3344
3346
  value: value,
@@ -3351,7 +3353,7 @@ function _defineProperty(obj, key, value) {
3351
3353
  }
3352
3354
  return obj;
3353
3355
  }
3354
- function _objectSpread(target) {
3356
+ function _objectSpread$1(target) {
3355
3357
  for(var i = 1; i < arguments.length; i++){
3356
3358
  var source = arguments[i] != null ? arguments[i] : {};
3357
3359
  var ownKeys = Object.keys(source);
@@ -3361,7 +3363,7 @@ function _objectSpread(target) {
3361
3363
  }));
3362
3364
  }
3363
3365
  ownKeys.forEach(function(key) {
3364
- _defineProperty(target, key, source[key]);
3366
+ _defineProperty$1(target, key, source[key]);
3365
3367
  });
3366
3368
  }
3367
3369
  return target;
@@ -3370,7 +3372,7 @@ function reduce(state = {}, action) {
3370
3372
  return {
3371
3373
  dirtyHandlerIds: reduce$5(state.dirtyHandlerIds, {
3372
3374
  type: action.type,
3373
- payload: _objectSpread({}, action.payload, {
3375
+ payload: _objectSpread$1({}, action.payload, {
3374
3376
  prevTargetIds: get(state, 'dragOperation.targetIds', [])
3375
3377
  })
3376
3378
  }),
@@ -5142,6 +5144,984 @@ function useFunction(engine, fn, mount) {
5142
5144
  }); }, [builtFn, run, result]);
5143
5145
  }
5144
5146
 
5147
+ // cheap lodash replacements
5148
+ function memoize(fn) {
5149
+ let result = null;
5150
+ const memoized = ()=>{
5151
+ if (result == null) {
5152
+ result = fn();
5153
+ }
5154
+ return result;
5155
+ };
5156
+ return memoized;
5157
+ }
5158
+ /**
5159
+ * drop-in replacement for _.without
5160
+ */ function without(items, item) {
5161
+ return items.filter((i)=>i !== item
5162
+ );
5163
+ }
5164
+ function union(itemsA, itemsB) {
5165
+ const set = new Set();
5166
+ const insertItem = (item)=>set.add(item)
5167
+ ;
5168
+ itemsA.forEach(insertItem);
5169
+ itemsB.forEach(insertItem);
5170
+ const result = [];
5171
+ set.forEach((key)=>result.push(key)
5172
+ );
5173
+ return result;
5174
+ }
5175
+
5176
+ class EnterLeaveCounter {
5177
+ enter(enteringNode) {
5178
+ const previousLength = this.entered.length;
5179
+ const isNodeEntered = (node)=>this.isNodeInDocument(node) && (!node.contains || node.contains(enteringNode))
5180
+ ;
5181
+ this.entered = union(this.entered.filter(isNodeEntered), [
5182
+ enteringNode
5183
+ ]);
5184
+ return previousLength === 0 && this.entered.length > 0;
5185
+ }
5186
+ leave(leavingNode) {
5187
+ const previousLength = this.entered.length;
5188
+ this.entered = without(this.entered.filter(this.isNodeInDocument), leavingNode);
5189
+ return previousLength > 0 && this.entered.length === 0;
5190
+ }
5191
+ reset() {
5192
+ this.entered = [];
5193
+ }
5194
+ constructor(isNodeInDocument){
5195
+ this.entered = [];
5196
+ this.isNodeInDocument = isNodeInDocument;
5197
+ }
5198
+ }
5199
+
5200
+ class NativeDragSource {
5201
+ initializeExposedProperties() {
5202
+ Object.keys(this.config.exposeProperties).forEach((property)=>{
5203
+ Object.defineProperty(this.item, property, {
5204
+ configurable: true,
5205
+ enumerable: true,
5206
+ get () {
5207
+ // eslint-disable-next-line no-console
5208
+ console.warn(`Browser doesn't allow reading "${property}" until the drop event.`);
5209
+ return null;
5210
+ }
5211
+ });
5212
+ });
5213
+ }
5214
+ loadDataTransfer(dataTransfer) {
5215
+ if (dataTransfer) {
5216
+ const newProperties = {};
5217
+ Object.keys(this.config.exposeProperties).forEach((property)=>{
5218
+ const propertyFn = this.config.exposeProperties[property];
5219
+ if (propertyFn != null) {
5220
+ newProperties[property] = {
5221
+ value: propertyFn(dataTransfer, this.config.matchesTypes),
5222
+ configurable: true,
5223
+ enumerable: true
5224
+ };
5225
+ }
5226
+ });
5227
+ Object.defineProperties(this.item, newProperties);
5228
+ }
5229
+ }
5230
+ canDrag() {
5231
+ return true;
5232
+ }
5233
+ beginDrag() {
5234
+ return this.item;
5235
+ }
5236
+ isDragging(monitor, handle) {
5237
+ return handle === monitor.getSourceId();
5238
+ }
5239
+ endDrag() {
5240
+ // empty
5241
+ }
5242
+ constructor(config){
5243
+ this.config = config;
5244
+ this.item = {};
5245
+ this.initializeExposedProperties();
5246
+ }
5247
+ }
5248
+
5249
+ const FILE = '__NATIVE_FILE__';
5250
+ const URL = '__NATIVE_URL__';
5251
+ const TEXT = '__NATIVE_TEXT__';
5252
+ const HTML = '__NATIVE_HTML__';
5253
+
5254
+ var NativeTypes = /*#__PURE__*/Object.freeze({
5255
+ __proto__: null,
5256
+ FILE: FILE,
5257
+ HTML: HTML,
5258
+ TEXT: TEXT,
5259
+ URL: URL
5260
+ });
5261
+
5262
+ function getDataFromDataTransfer(dataTransfer, typesToTry, defaultValue) {
5263
+ const result = typesToTry.reduce((resultSoFar, typeToTry)=>resultSoFar || dataTransfer.getData(typeToTry)
5264
+ , '');
5265
+ return result != null ? result : defaultValue;
5266
+ }
5267
+
5268
+ const nativeTypesConfig = {
5269
+ [FILE]: {
5270
+ exposeProperties: {
5271
+ files: (dataTransfer)=>Array.prototype.slice.call(dataTransfer.files)
5272
+ ,
5273
+ items: (dataTransfer)=>dataTransfer.items
5274
+ ,
5275
+ dataTransfer: (dataTransfer)=>dataTransfer
5276
+ },
5277
+ matchesTypes: [
5278
+ 'Files'
5279
+ ]
5280
+ },
5281
+ [HTML]: {
5282
+ exposeProperties: {
5283
+ html: (dataTransfer, matchesTypes)=>getDataFromDataTransfer(dataTransfer, matchesTypes, '')
5284
+ ,
5285
+ dataTransfer: (dataTransfer)=>dataTransfer
5286
+ },
5287
+ matchesTypes: [
5288
+ 'Html',
5289
+ 'text/html'
5290
+ ]
5291
+ },
5292
+ [URL]: {
5293
+ exposeProperties: {
5294
+ urls: (dataTransfer, matchesTypes)=>getDataFromDataTransfer(dataTransfer, matchesTypes, '').split('\n')
5295
+ ,
5296
+ dataTransfer: (dataTransfer)=>dataTransfer
5297
+ },
5298
+ matchesTypes: [
5299
+ 'Url',
5300
+ 'text/uri-list'
5301
+ ]
5302
+ },
5303
+ [TEXT]: {
5304
+ exposeProperties: {
5305
+ text: (dataTransfer, matchesTypes)=>getDataFromDataTransfer(dataTransfer, matchesTypes, '')
5306
+ ,
5307
+ dataTransfer: (dataTransfer)=>dataTransfer
5308
+ },
5309
+ matchesTypes: [
5310
+ 'Text',
5311
+ 'text/plain'
5312
+ ]
5313
+ }
5314
+ };
5315
+
5316
+ function createNativeDragSource(type, dataTransfer) {
5317
+ const config = nativeTypesConfig[type];
5318
+ if (!config) {
5319
+ throw new Error(`native type ${type} has no configuration`);
5320
+ }
5321
+ const result = new NativeDragSource(config);
5322
+ result.loadDataTransfer(dataTransfer);
5323
+ return result;
5324
+ }
5325
+ function matchNativeItemType(dataTransfer) {
5326
+ if (!dataTransfer) {
5327
+ return null;
5328
+ }
5329
+ const dataTransferTypes = Array.prototype.slice.call(dataTransfer.types || []);
5330
+ return Object.keys(nativeTypesConfig).filter((nativeItemType)=>{
5331
+ const typeConfig = nativeTypesConfig[nativeItemType];
5332
+ if (!(typeConfig === null || typeConfig === void 0 ? void 0 : typeConfig.matchesTypes)) {
5333
+ return false;
5334
+ }
5335
+ return typeConfig.matchesTypes.some((t)=>dataTransferTypes.indexOf(t) > -1
5336
+ );
5337
+ })[0] || null;
5338
+ }
5339
+
5340
+ const isFirefox = memoize(()=>/firefox/i.test(navigator.userAgent)
5341
+ );
5342
+ const isSafari = memoize(()=>Boolean(window.safari)
5343
+ );
5344
+
5345
+ class MonotonicInterpolant {
5346
+ interpolate(x) {
5347
+ const { xs , ys , c1s , c2s , c3s } = this;
5348
+ // The rightmost point in the dataset should give an exact result
5349
+ let i = xs.length - 1;
5350
+ if (x === xs[i]) {
5351
+ return ys[i];
5352
+ }
5353
+ // Search for the interval x is in, returning the corresponding y if x is one of the original xs
5354
+ let low = 0;
5355
+ let high = c3s.length - 1;
5356
+ let mid;
5357
+ while(low <= high){
5358
+ mid = Math.floor(0.5 * (low + high));
5359
+ const xHere = xs[mid];
5360
+ if (xHere < x) {
5361
+ low = mid + 1;
5362
+ } else if (xHere > x) {
5363
+ high = mid - 1;
5364
+ } else {
5365
+ return ys[mid];
5366
+ }
5367
+ }
5368
+ i = Math.max(0, high);
5369
+ // Interpolate
5370
+ const diff = x - xs[i];
5371
+ const diffSq = diff * diff;
5372
+ return ys[i] + c1s[i] * diff + c2s[i] * diffSq + c3s[i] * diff * diffSq;
5373
+ }
5374
+ constructor(xs, ys){
5375
+ const { length } = xs;
5376
+ // Rearrange xs and ys so that xs is sorted
5377
+ const indexes = [];
5378
+ for(let i = 0; i < length; i++){
5379
+ indexes.push(i);
5380
+ }
5381
+ indexes.sort((a, b)=>xs[a] < xs[b] ? -1 : 1
5382
+ );
5383
+ const dxs = [];
5384
+ const ms = [];
5385
+ let dx;
5386
+ let dy;
5387
+ for(let i1 = 0; i1 < length - 1; i1++){
5388
+ dx = xs[i1 + 1] - xs[i1];
5389
+ dy = ys[i1 + 1] - ys[i1];
5390
+ dxs.push(dx);
5391
+ ms.push(dy / dx);
5392
+ }
5393
+ // Get degree-1 coefficients
5394
+ const c1s = [
5395
+ ms[0]
5396
+ ];
5397
+ for(let i2 = 0; i2 < dxs.length - 1; i2++){
5398
+ const m2 = ms[i2];
5399
+ const mNext = ms[i2 + 1];
5400
+ if (m2 * mNext <= 0) {
5401
+ c1s.push(0);
5402
+ } else {
5403
+ dx = dxs[i2];
5404
+ const dxNext = dxs[i2 + 1];
5405
+ const common = dx + dxNext;
5406
+ c1s.push(3 * common / ((common + dxNext) / m2 + (common + dx) / mNext));
5407
+ }
5408
+ }
5409
+ c1s.push(ms[ms.length - 1]);
5410
+ // Get degree-2 and degree-3 coefficients
5411
+ const c2s = [];
5412
+ const c3s = [];
5413
+ let m;
5414
+ for(let i3 = 0; i3 < c1s.length - 1; i3++){
5415
+ m = ms[i3];
5416
+ const c1 = c1s[i3];
5417
+ const invDx = 1 / dxs[i3];
5418
+ const common = c1 + c1s[i3 + 1] - m - m;
5419
+ c2s.push((m - c1 - common) * invDx);
5420
+ c3s.push(common * invDx * invDx);
5421
+ }
5422
+ this.xs = xs;
5423
+ this.ys = ys;
5424
+ this.c1s = c1s;
5425
+ this.c2s = c2s;
5426
+ this.c3s = c3s;
5427
+ }
5428
+ }
5429
+
5430
+ const ELEMENT_NODE = 1;
5431
+ function getNodeClientOffset(node) {
5432
+ const el = node.nodeType === ELEMENT_NODE ? node : node.parentElement;
5433
+ if (!el) {
5434
+ return null;
5435
+ }
5436
+ const { top , left } = el.getBoundingClientRect();
5437
+ return {
5438
+ x: left,
5439
+ y: top
5440
+ };
5441
+ }
5442
+ function getEventClientOffset(e) {
5443
+ return {
5444
+ x: e.clientX,
5445
+ y: e.clientY
5446
+ };
5447
+ }
5448
+ function isImageNode(node) {
5449
+ var ref;
5450
+ return node.nodeName === 'IMG' && (isFirefox() || !((ref = document.documentElement) === null || ref === void 0 ? void 0 : ref.contains(node)));
5451
+ }
5452
+ function getDragPreviewSize(isImage, dragPreview, sourceWidth, sourceHeight) {
5453
+ let dragPreviewWidth = isImage ? dragPreview.width : sourceWidth;
5454
+ let dragPreviewHeight = isImage ? dragPreview.height : sourceHeight;
5455
+ // Work around @2x coordinate discrepancies in browsers
5456
+ if (isSafari() && isImage) {
5457
+ dragPreviewHeight /= window.devicePixelRatio;
5458
+ dragPreviewWidth /= window.devicePixelRatio;
5459
+ }
5460
+ return {
5461
+ dragPreviewWidth,
5462
+ dragPreviewHeight
5463
+ };
5464
+ }
5465
+ function getDragPreviewOffset(sourceNode, dragPreview, clientOffset, anchorPoint, offsetPoint) {
5466
+ // The browsers will use the image intrinsic size under different conditions.
5467
+ // Firefox only cares if it's an image, but WebKit also wants it to be detached.
5468
+ const isImage = isImageNode(dragPreview);
5469
+ const dragPreviewNode = isImage ? sourceNode : dragPreview;
5470
+ const dragPreviewNodeOffsetFromClient = getNodeClientOffset(dragPreviewNode);
5471
+ const offsetFromDragPreview = {
5472
+ x: clientOffset.x - dragPreviewNodeOffsetFromClient.x,
5473
+ y: clientOffset.y - dragPreviewNodeOffsetFromClient.y
5474
+ };
5475
+ const { offsetWidth: sourceWidth , offsetHeight: sourceHeight } = sourceNode;
5476
+ const { anchorX , anchorY } = anchorPoint;
5477
+ const { dragPreviewWidth , dragPreviewHeight } = getDragPreviewSize(isImage, dragPreview, sourceWidth, sourceHeight);
5478
+ const calculateYOffset = ()=>{
5479
+ const interpolantY = new MonotonicInterpolant([
5480
+ 0,
5481
+ 0.5,
5482
+ 1
5483
+ ], [
5484
+ // Dock to the top
5485
+ offsetFromDragPreview.y,
5486
+ // Align at the center
5487
+ (offsetFromDragPreview.y / sourceHeight) * dragPreviewHeight,
5488
+ // Dock to the bottom
5489
+ offsetFromDragPreview.y + dragPreviewHeight - sourceHeight,
5490
+ ]);
5491
+ let y = interpolantY.interpolate(anchorY);
5492
+ // Work around Safari 8 positioning bug
5493
+ if (isSafari() && isImage) {
5494
+ // We'll have to wait for @3x to see if this is entirely correct
5495
+ y += (window.devicePixelRatio - 1) * dragPreviewHeight;
5496
+ }
5497
+ return y;
5498
+ };
5499
+ const calculateXOffset = ()=>{
5500
+ // Interpolate coordinates depending on anchor point
5501
+ // If you know a simpler way to do this, let me know
5502
+ const interpolantX = new MonotonicInterpolant([
5503
+ 0,
5504
+ 0.5,
5505
+ 1
5506
+ ], [
5507
+ // Dock to the left
5508
+ offsetFromDragPreview.x,
5509
+ // Align at the center
5510
+ (offsetFromDragPreview.x / sourceWidth) * dragPreviewWidth,
5511
+ // Dock to the right
5512
+ offsetFromDragPreview.x + dragPreviewWidth - sourceWidth,
5513
+ ]);
5514
+ return interpolantX.interpolate(anchorX);
5515
+ };
5516
+ // Force offsets if specified in the options.
5517
+ const { offsetX , offsetY } = offsetPoint;
5518
+ const isManualOffsetX = offsetX === 0 || offsetX;
5519
+ const isManualOffsetY = offsetY === 0 || offsetY;
5520
+ return {
5521
+ x: isManualOffsetX ? offsetX : calculateXOffset(),
5522
+ y: isManualOffsetY ? offsetY : calculateYOffset()
5523
+ };
5524
+ }
5525
+
5526
+ class OptionsReader {
5527
+ get window() {
5528
+ if (this.globalContext) {
5529
+ return this.globalContext;
5530
+ } else if (typeof window !== 'undefined') {
5531
+ return window;
5532
+ }
5533
+ return undefined;
5534
+ }
5535
+ get document() {
5536
+ var ref;
5537
+ if ((ref = this.globalContext) === null || ref === void 0 ? void 0 : ref.document) {
5538
+ return this.globalContext.document;
5539
+ } else if (this.window) {
5540
+ return this.window.document;
5541
+ } else {
5542
+ return undefined;
5543
+ }
5544
+ }
5545
+ get rootElement() {
5546
+ var ref;
5547
+ return ((ref = this.optionsArgs) === null || ref === void 0 ? void 0 : ref.rootElement) || this.window;
5548
+ }
5549
+ constructor(globalContext, options){
5550
+ this.ownerDocument = null;
5551
+ this.globalContext = globalContext;
5552
+ this.optionsArgs = options;
5553
+ }
5554
+ }
5555
+
5556
+ function _defineProperty(obj, key, value) {
5557
+ if (key in obj) {
5558
+ Object.defineProperty(obj, key, {
5559
+ value: value,
5560
+ enumerable: true,
5561
+ configurable: true,
5562
+ writable: true
5563
+ });
5564
+ } else {
5565
+ obj[key] = value;
5566
+ }
5567
+ return obj;
5568
+ }
5569
+ function _objectSpread(target) {
5570
+ for(var i = 1; i < arguments.length; i++){
5571
+ var source = arguments[i] != null ? arguments[i] : {};
5572
+ var ownKeys = Object.keys(source);
5573
+ if (typeof Object.getOwnPropertySymbols === 'function') {
5574
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
5575
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
5576
+ }));
5577
+ }
5578
+ ownKeys.forEach(function(key) {
5579
+ _defineProperty(target, key, source[key]);
5580
+ });
5581
+ }
5582
+ return target;
5583
+ }
5584
+ class HTML5BackendImpl {
5585
+ /**
5586
+ * Generate profiling statistics for the HTML5Backend.
5587
+ */ profile() {
5588
+ var ref, ref1;
5589
+ return {
5590
+ sourcePreviewNodes: this.sourcePreviewNodes.size,
5591
+ sourcePreviewNodeOptions: this.sourcePreviewNodeOptions.size,
5592
+ sourceNodeOptions: this.sourceNodeOptions.size,
5593
+ sourceNodes: this.sourceNodes.size,
5594
+ dragStartSourceIds: ((ref = this.dragStartSourceIds) === null || ref === void 0 ? void 0 : ref.length) || 0,
5595
+ dropTargetIds: this.dropTargetIds.length,
5596
+ dragEnterTargetIds: this.dragEnterTargetIds.length,
5597
+ dragOverTargetIds: ((ref1 = this.dragOverTargetIds) === null || ref1 === void 0 ? void 0 : ref1.length) || 0
5598
+ };
5599
+ }
5600
+ // public for test
5601
+ get window() {
5602
+ return this.options.window;
5603
+ }
5604
+ get document() {
5605
+ return this.options.document;
5606
+ }
5607
+ /**
5608
+ * Get the root element to use for event subscriptions
5609
+ */ get rootElement() {
5610
+ return this.options.rootElement;
5611
+ }
5612
+ setup() {
5613
+ const root = this.rootElement;
5614
+ if (root === undefined) {
5615
+ return;
5616
+ }
5617
+ if (root.__isReactDndBackendSetUp) {
5618
+ throw new Error('Cannot have two HTML5 backends at the same time.');
5619
+ }
5620
+ root.__isReactDndBackendSetUp = true;
5621
+ this.addEventListeners(root);
5622
+ }
5623
+ teardown() {
5624
+ const root = this.rootElement;
5625
+ if (root === undefined) {
5626
+ return;
5627
+ }
5628
+ root.__isReactDndBackendSetUp = false;
5629
+ this.removeEventListeners(this.rootElement);
5630
+ this.clearCurrentDragSourceNode();
5631
+ if (this.asyncEndDragFrameId) {
5632
+ var ref;
5633
+ (ref = this.window) === null || ref === void 0 ? void 0 : ref.cancelAnimationFrame(this.asyncEndDragFrameId);
5634
+ }
5635
+ }
5636
+ connectDragPreview(sourceId, node, options) {
5637
+ this.sourcePreviewNodeOptions.set(sourceId, options);
5638
+ this.sourcePreviewNodes.set(sourceId, node);
5639
+ return ()=>{
5640
+ this.sourcePreviewNodes.delete(sourceId);
5641
+ this.sourcePreviewNodeOptions.delete(sourceId);
5642
+ };
5643
+ }
5644
+ connectDragSource(sourceId, node, options) {
5645
+ this.sourceNodes.set(sourceId, node);
5646
+ this.sourceNodeOptions.set(sourceId, options);
5647
+ const handleDragStart = (e)=>this.handleDragStart(e, sourceId)
5648
+ ;
5649
+ const handleSelectStart = (e)=>this.handleSelectStart(e)
5650
+ ;
5651
+ node.setAttribute('draggable', 'true');
5652
+ node.addEventListener('dragstart', handleDragStart);
5653
+ node.addEventListener('selectstart', handleSelectStart);
5654
+ return ()=>{
5655
+ this.sourceNodes.delete(sourceId);
5656
+ this.sourceNodeOptions.delete(sourceId);
5657
+ node.removeEventListener('dragstart', handleDragStart);
5658
+ node.removeEventListener('selectstart', handleSelectStart);
5659
+ node.setAttribute('draggable', 'false');
5660
+ };
5661
+ }
5662
+ connectDropTarget(targetId, node) {
5663
+ const handleDragEnter = (e)=>this.handleDragEnter(e, targetId)
5664
+ ;
5665
+ const handleDragOver = (e)=>this.handleDragOver(e, targetId)
5666
+ ;
5667
+ const handleDrop = (e)=>this.handleDrop(e, targetId)
5668
+ ;
5669
+ node.addEventListener('dragenter', handleDragEnter);
5670
+ node.addEventListener('dragover', handleDragOver);
5671
+ node.addEventListener('drop', handleDrop);
5672
+ return ()=>{
5673
+ node.removeEventListener('dragenter', handleDragEnter);
5674
+ node.removeEventListener('dragover', handleDragOver);
5675
+ node.removeEventListener('drop', handleDrop);
5676
+ };
5677
+ }
5678
+ addEventListeners(target) {
5679
+ // SSR Fix (https://github.com/react-dnd/react-dnd/pull/813
5680
+ if (!target.addEventListener) {
5681
+ return;
5682
+ }
5683
+ target.addEventListener('dragstart', this.handleTopDragStart);
5684
+ target.addEventListener('dragstart', this.handleTopDragStartCapture, true);
5685
+ target.addEventListener('dragend', this.handleTopDragEndCapture, true);
5686
+ target.addEventListener('dragenter', this.handleTopDragEnter);
5687
+ target.addEventListener('dragenter', this.handleTopDragEnterCapture, true);
5688
+ target.addEventListener('dragleave', this.handleTopDragLeaveCapture, true);
5689
+ target.addEventListener('dragover', this.handleTopDragOver);
5690
+ target.addEventListener('dragover', this.handleTopDragOverCapture, true);
5691
+ target.addEventListener('drop', this.handleTopDrop);
5692
+ target.addEventListener('drop', this.handleTopDropCapture, true);
5693
+ }
5694
+ removeEventListeners(target) {
5695
+ // SSR Fix (https://github.com/react-dnd/react-dnd/pull/813
5696
+ if (!target.removeEventListener) {
5697
+ return;
5698
+ }
5699
+ target.removeEventListener('dragstart', this.handleTopDragStart);
5700
+ target.removeEventListener('dragstart', this.handleTopDragStartCapture, true);
5701
+ target.removeEventListener('dragend', this.handleTopDragEndCapture, true);
5702
+ target.removeEventListener('dragenter', this.handleTopDragEnter);
5703
+ target.removeEventListener('dragenter', this.handleTopDragEnterCapture, true);
5704
+ target.removeEventListener('dragleave', this.handleTopDragLeaveCapture, true);
5705
+ target.removeEventListener('dragover', this.handleTopDragOver);
5706
+ target.removeEventListener('dragover', this.handleTopDragOverCapture, true);
5707
+ target.removeEventListener('drop', this.handleTopDrop);
5708
+ target.removeEventListener('drop', this.handleTopDropCapture, true);
5709
+ }
5710
+ getCurrentSourceNodeOptions() {
5711
+ const sourceId = this.monitor.getSourceId();
5712
+ const sourceNodeOptions = this.sourceNodeOptions.get(sourceId);
5713
+ return _objectSpread({
5714
+ dropEffect: this.altKeyPressed ? 'copy' : 'move'
5715
+ }, sourceNodeOptions || {});
5716
+ }
5717
+ getCurrentDropEffect() {
5718
+ if (this.isDraggingNativeItem()) {
5719
+ // It makes more sense to default to 'copy' for native resources
5720
+ return 'copy';
5721
+ }
5722
+ return this.getCurrentSourceNodeOptions().dropEffect;
5723
+ }
5724
+ getCurrentSourcePreviewNodeOptions() {
5725
+ const sourceId = this.monitor.getSourceId();
5726
+ const sourcePreviewNodeOptions = this.sourcePreviewNodeOptions.get(sourceId);
5727
+ return _objectSpread({
5728
+ anchorX: 0.5,
5729
+ anchorY: 0.5,
5730
+ captureDraggingState: false
5731
+ }, sourcePreviewNodeOptions || {});
5732
+ }
5733
+ isDraggingNativeItem() {
5734
+ const itemType = this.monitor.getItemType();
5735
+ return Object.keys(NativeTypes).some((key)=>NativeTypes[key] === itemType
5736
+ );
5737
+ }
5738
+ beginDragNativeItem(type, dataTransfer) {
5739
+ this.clearCurrentDragSourceNode();
5740
+ this.currentNativeSource = createNativeDragSource(type, dataTransfer);
5741
+ this.currentNativeHandle = this.registry.addSource(type, this.currentNativeSource);
5742
+ this.actions.beginDrag([
5743
+ this.currentNativeHandle
5744
+ ]);
5745
+ }
5746
+ setCurrentDragSourceNode(node) {
5747
+ this.clearCurrentDragSourceNode();
5748
+ this.currentDragSourceNode = node;
5749
+ // A timeout of > 0 is necessary to resolve Firefox issue referenced
5750
+ // See:
5751
+ // * https://github.com/react-dnd/react-dnd/pull/928
5752
+ // * https://github.com/react-dnd/react-dnd/issues/869
5753
+ const MOUSE_MOVE_TIMEOUT = 1000;
5754
+ // Receiving a mouse event in the middle of a dragging operation
5755
+ // means it has ended and the drag source node disappeared from DOM,
5756
+ // so the browser didn't dispatch the dragend event.
5757
+ //
5758
+ // We need to wait before we start listening for mousemove events.
5759
+ // This is needed because the drag preview needs to be drawn or else it fires an 'mousemove' event
5760
+ // immediately in some browsers.
5761
+ //
5762
+ // See:
5763
+ // * https://github.com/react-dnd/react-dnd/pull/928
5764
+ // * https://github.com/react-dnd/react-dnd/issues/869
5765
+ //
5766
+ this.mouseMoveTimeoutTimer = setTimeout(()=>{
5767
+ var ref;
5768
+ return (ref = this.rootElement) === null || ref === void 0 ? void 0 : ref.addEventListener('mousemove', this.endDragIfSourceWasRemovedFromDOM, true);
5769
+ }, MOUSE_MOVE_TIMEOUT);
5770
+ }
5771
+ clearCurrentDragSourceNode() {
5772
+ if (this.currentDragSourceNode) {
5773
+ this.currentDragSourceNode = null;
5774
+ if (this.rootElement) {
5775
+ var ref;
5776
+ (ref = this.window) === null || ref === void 0 ? void 0 : ref.clearTimeout(this.mouseMoveTimeoutTimer || undefined);
5777
+ this.rootElement.removeEventListener('mousemove', this.endDragIfSourceWasRemovedFromDOM, true);
5778
+ }
5779
+ this.mouseMoveTimeoutTimer = null;
5780
+ return true;
5781
+ }
5782
+ return false;
5783
+ }
5784
+ handleDragStart(e, sourceId) {
5785
+ if (e.defaultPrevented) {
5786
+ return;
5787
+ }
5788
+ if (!this.dragStartSourceIds) {
5789
+ this.dragStartSourceIds = [];
5790
+ }
5791
+ this.dragStartSourceIds.unshift(sourceId);
5792
+ }
5793
+ handleDragEnter(_e, targetId) {
5794
+ this.dragEnterTargetIds.unshift(targetId);
5795
+ }
5796
+ handleDragOver(_e, targetId) {
5797
+ if (this.dragOverTargetIds === null) {
5798
+ this.dragOverTargetIds = [];
5799
+ }
5800
+ this.dragOverTargetIds.unshift(targetId);
5801
+ }
5802
+ handleDrop(_e, targetId) {
5803
+ this.dropTargetIds.unshift(targetId);
5804
+ }
5805
+ constructor(manager, globalContext, options){
5806
+ this.sourcePreviewNodes = new Map();
5807
+ this.sourcePreviewNodeOptions = new Map();
5808
+ this.sourceNodes = new Map();
5809
+ this.sourceNodeOptions = new Map();
5810
+ this.dragStartSourceIds = null;
5811
+ this.dropTargetIds = [];
5812
+ this.dragEnterTargetIds = [];
5813
+ this.currentNativeSource = null;
5814
+ this.currentNativeHandle = null;
5815
+ this.currentDragSourceNode = null;
5816
+ this.altKeyPressed = false;
5817
+ this.mouseMoveTimeoutTimer = null;
5818
+ this.asyncEndDragFrameId = null;
5819
+ this.dragOverTargetIds = null;
5820
+ this.lastClientOffset = null;
5821
+ this.hoverRafId = null;
5822
+ this.getSourceClientOffset = (sourceId)=>{
5823
+ const source = this.sourceNodes.get(sourceId);
5824
+ return source && getNodeClientOffset(source) || null;
5825
+ };
5826
+ this.endDragNativeItem = ()=>{
5827
+ if (!this.isDraggingNativeItem()) {
5828
+ return;
5829
+ }
5830
+ this.actions.endDrag();
5831
+ if (this.currentNativeHandle) {
5832
+ this.registry.removeSource(this.currentNativeHandle);
5833
+ }
5834
+ this.currentNativeHandle = null;
5835
+ this.currentNativeSource = null;
5836
+ };
5837
+ this.isNodeInDocument = (node)=>{
5838
+ // Check the node either in the main document or in the current context
5839
+ return Boolean(node && this.document && this.document.body && this.document.body.contains(node));
5840
+ };
5841
+ this.endDragIfSourceWasRemovedFromDOM = ()=>{
5842
+ const node = this.currentDragSourceNode;
5843
+ if (node == null || this.isNodeInDocument(node)) {
5844
+ return;
5845
+ }
5846
+ if (this.clearCurrentDragSourceNode() && this.monitor.isDragging()) {
5847
+ this.actions.endDrag();
5848
+ }
5849
+ this.cancelHover();
5850
+ };
5851
+ this.scheduleHover = (dragOverTargetIds)=>{
5852
+ if (this.hoverRafId === null && typeof requestAnimationFrame !== 'undefined') {
5853
+ this.hoverRafId = requestAnimationFrame(()=>{
5854
+ if (this.monitor.isDragging()) {
5855
+ this.actions.hover(dragOverTargetIds || [], {
5856
+ clientOffset: this.lastClientOffset
5857
+ });
5858
+ }
5859
+ this.hoverRafId = null;
5860
+ });
5861
+ }
5862
+ };
5863
+ this.cancelHover = ()=>{
5864
+ if (this.hoverRafId !== null && typeof cancelAnimationFrame !== 'undefined') {
5865
+ cancelAnimationFrame(this.hoverRafId);
5866
+ this.hoverRafId = null;
5867
+ }
5868
+ };
5869
+ this.handleTopDragStartCapture = ()=>{
5870
+ this.clearCurrentDragSourceNode();
5871
+ this.dragStartSourceIds = [];
5872
+ };
5873
+ this.handleTopDragStart = (e)=>{
5874
+ if (e.defaultPrevented) {
5875
+ return;
5876
+ }
5877
+ const { dragStartSourceIds } = this;
5878
+ this.dragStartSourceIds = null;
5879
+ const clientOffset = getEventClientOffset(e);
5880
+ // Avoid crashing if we missed a drop event or our previous drag died
5881
+ if (this.monitor.isDragging()) {
5882
+ this.actions.endDrag();
5883
+ this.cancelHover();
5884
+ }
5885
+ // Don't publish the source just yet (see why below)
5886
+ this.actions.beginDrag(dragStartSourceIds || [], {
5887
+ publishSource: false,
5888
+ getSourceClientOffset: this.getSourceClientOffset,
5889
+ clientOffset
5890
+ });
5891
+ const { dataTransfer } = e;
5892
+ const nativeType = matchNativeItemType(dataTransfer);
5893
+ if (this.monitor.isDragging()) {
5894
+ if (dataTransfer && typeof dataTransfer.setDragImage === 'function') {
5895
+ // Use custom drag image if user specifies it.
5896
+ // If child drag source refuses drag but parent agrees,
5897
+ // use parent's node as drag image. Neither works in IE though.
5898
+ const sourceId = this.monitor.getSourceId();
5899
+ const sourceNode = this.sourceNodes.get(sourceId);
5900
+ const dragPreview = this.sourcePreviewNodes.get(sourceId) || sourceNode;
5901
+ if (dragPreview) {
5902
+ const { anchorX , anchorY , offsetX , offsetY } = this.getCurrentSourcePreviewNodeOptions();
5903
+ const anchorPoint = {
5904
+ anchorX,
5905
+ anchorY
5906
+ };
5907
+ const offsetPoint = {
5908
+ offsetX,
5909
+ offsetY
5910
+ };
5911
+ const dragPreviewOffset = getDragPreviewOffset(sourceNode, dragPreview, clientOffset, anchorPoint, offsetPoint);
5912
+ dataTransfer.setDragImage(dragPreview, dragPreviewOffset.x, dragPreviewOffset.y);
5913
+ }
5914
+ }
5915
+ try {
5916
+ // Firefox won't drag without setting data
5917
+ dataTransfer === null || dataTransfer === void 0 ? void 0 : dataTransfer.setData('application/json', {});
5918
+ } catch (err) {
5919
+ // IE doesn't support MIME types in setData
5920
+ }
5921
+ // Store drag source node so we can check whether
5922
+ // it is removed from DOM and trigger endDrag manually.
5923
+ this.setCurrentDragSourceNode(e.target);
5924
+ // Now we are ready to publish the drag source.. or are we not?
5925
+ const { captureDraggingState } = this.getCurrentSourcePreviewNodeOptions();
5926
+ if (!captureDraggingState) {
5927
+ // Usually we want to publish it in the next tick so that browser
5928
+ // is able to screenshot the current (not yet dragging) state.
5929
+ //
5930
+ // It also neatly avoids a situation where render() returns null
5931
+ // in the same tick for the source element, and browser freaks out.
5932
+ setTimeout(()=>this.actions.publishDragSource()
5933
+ , 0);
5934
+ } else {
5935
+ // In some cases the user may want to override this behavior, e.g.
5936
+ // to work around IE not supporting custom drag previews.
5937
+ //
5938
+ // When using a custom drag layer, the only way to prevent
5939
+ // the default drag preview from drawing in IE is to screenshot
5940
+ // the dragging state in which the node itself has zero opacity
5941
+ // and height. In this case, though, returning null from render()
5942
+ // will abruptly end the dragging, which is not obvious.
5943
+ //
5944
+ // This is the reason such behavior is strictly opt-in.
5945
+ this.actions.publishDragSource();
5946
+ }
5947
+ } else if (nativeType) {
5948
+ // A native item (such as URL) dragged from inside the document
5949
+ this.beginDragNativeItem(nativeType);
5950
+ } else if (dataTransfer && !dataTransfer.types && (e.target && !e.target.hasAttribute || !e.target.hasAttribute('draggable'))) {
5951
+ // Looks like a Safari bug: dataTransfer.types is null, but there was no draggable.
5952
+ // Just let it drag. It's a native type (URL or text) and will be picked up in
5953
+ // dragenter handler.
5954
+ return;
5955
+ } else {
5956
+ // If by this time no drag source reacted, tell browser not to drag.
5957
+ e.preventDefault();
5958
+ }
5959
+ };
5960
+ this.handleTopDragEndCapture = ()=>{
5961
+ if (this.clearCurrentDragSourceNode() && this.monitor.isDragging()) {
5962
+ // Firefox can dispatch this event in an infinite loop
5963
+ // if dragend handler does something like showing an alert.
5964
+ // Only proceed if we have not handled it already.
5965
+ this.actions.endDrag();
5966
+ }
5967
+ this.cancelHover();
5968
+ };
5969
+ this.handleTopDragEnterCapture = (e)=>{
5970
+ this.dragEnterTargetIds = [];
5971
+ if (this.isDraggingNativeItem()) {
5972
+ var ref;
5973
+ (ref = this.currentNativeSource) === null || ref === void 0 ? void 0 : ref.loadDataTransfer(e.dataTransfer);
5974
+ }
5975
+ const isFirstEnter = this.enterLeaveCounter.enter(e.target);
5976
+ if (!isFirstEnter || this.monitor.isDragging()) {
5977
+ return;
5978
+ }
5979
+ const { dataTransfer } = e;
5980
+ const nativeType = matchNativeItemType(dataTransfer);
5981
+ if (nativeType) {
5982
+ // A native item (such as file or URL) dragged from outside the document
5983
+ this.beginDragNativeItem(nativeType, dataTransfer);
5984
+ }
5985
+ };
5986
+ this.handleTopDragEnter = (e)=>{
5987
+ const { dragEnterTargetIds } = this;
5988
+ this.dragEnterTargetIds = [];
5989
+ if (!this.monitor.isDragging()) {
5990
+ // This is probably a native item type we don't understand.
5991
+ return;
5992
+ }
5993
+ this.altKeyPressed = e.altKey;
5994
+ // If the target changes position as the result of `dragenter`, `dragover` might still
5995
+ // get dispatched despite target being no longer there. The easy solution is to check
5996
+ // whether there actually is a target before firing `hover`.
5997
+ if (dragEnterTargetIds.length > 0) {
5998
+ this.actions.hover(dragEnterTargetIds, {
5999
+ clientOffset: getEventClientOffset(e)
6000
+ });
6001
+ }
6002
+ const canDrop = dragEnterTargetIds.some((targetId)=>this.monitor.canDropOnTarget(targetId)
6003
+ );
6004
+ if (canDrop) {
6005
+ // IE requires this to fire dragover events
6006
+ e.preventDefault();
6007
+ if (e.dataTransfer) {
6008
+ e.dataTransfer.dropEffect = this.getCurrentDropEffect();
6009
+ }
6010
+ }
6011
+ };
6012
+ this.handleTopDragOverCapture = (e)=>{
6013
+ this.dragOverTargetIds = [];
6014
+ if (this.isDraggingNativeItem()) {
6015
+ var ref;
6016
+ (ref = this.currentNativeSource) === null || ref === void 0 ? void 0 : ref.loadDataTransfer(e.dataTransfer);
6017
+ }
6018
+ };
6019
+ this.handleTopDragOver = (e)=>{
6020
+ const { dragOverTargetIds } = this;
6021
+ this.dragOverTargetIds = [];
6022
+ if (!this.monitor.isDragging()) {
6023
+ // This is probably a native item type we don't understand.
6024
+ // Prevent default "drop and blow away the whole document" action.
6025
+ e.preventDefault();
6026
+ if (e.dataTransfer) {
6027
+ e.dataTransfer.dropEffect = 'none';
6028
+ }
6029
+ return;
6030
+ }
6031
+ this.altKeyPressed = e.altKey;
6032
+ this.lastClientOffset = getEventClientOffset(e);
6033
+ this.scheduleHover(dragOverTargetIds);
6034
+ const canDrop = (dragOverTargetIds || []).some((targetId)=>this.monitor.canDropOnTarget(targetId)
6035
+ );
6036
+ if (canDrop) {
6037
+ // Show user-specified drop effect.
6038
+ e.preventDefault();
6039
+ if (e.dataTransfer) {
6040
+ e.dataTransfer.dropEffect = this.getCurrentDropEffect();
6041
+ }
6042
+ } else if (this.isDraggingNativeItem()) {
6043
+ // Don't show a nice cursor but still prevent default
6044
+ // "drop and blow away the whole document" action.
6045
+ e.preventDefault();
6046
+ } else {
6047
+ e.preventDefault();
6048
+ if (e.dataTransfer) {
6049
+ e.dataTransfer.dropEffect = 'none';
6050
+ }
6051
+ }
6052
+ };
6053
+ this.handleTopDragLeaveCapture = (e)=>{
6054
+ if (this.isDraggingNativeItem()) {
6055
+ e.preventDefault();
6056
+ }
6057
+ const isLastLeave = this.enterLeaveCounter.leave(e.target);
6058
+ if (!isLastLeave) {
6059
+ return;
6060
+ }
6061
+ if (this.isDraggingNativeItem()) {
6062
+ setTimeout(()=>this.endDragNativeItem()
6063
+ , 0);
6064
+ }
6065
+ this.cancelHover();
6066
+ };
6067
+ this.handleTopDropCapture = (e)=>{
6068
+ this.dropTargetIds = [];
6069
+ if (this.isDraggingNativeItem()) {
6070
+ var ref;
6071
+ e.preventDefault();
6072
+ (ref = this.currentNativeSource) === null || ref === void 0 ? void 0 : ref.loadDataTransfer(e.dataTransfer);
6073
+ } else if (matchNativeItemType(e.dataTransfer)) {
6074
+ // Dragging some elements, like <a> and <img> may still behave like a native drag event,
6075
+ // even if the current drag event matches a user-defined type.
6076
+ // Stop the default behavior when we're not expecting a native item to be dropped.
6077
+ e.preventDefault();
6078
+ }
6079
+ this.enterLeaveCounter.reset();
6080
+ };
6081
+ this.handleTopDrop = (e)=>{
6082
+ const { dropTargetIds } = this;
6083
+ this.dropTargetIds = [];
6084
+ this.actions.hover(dropTargetIds, {
6085
+ clientOffset: getEventClientOffset(e)
6086
+ });
6087
+ this.actions.drop({
6088
+ dropEffect: this.getCurrentDropEffect()
6089
+ });
6090
+ if (this.isDraggingNativeItem()) {
6091
+ this.endDragNativeItem();
6092
+ } else if (this.monitor.isDragging()) {
6093
+ this.actions.endDrag();
6094
+ }
6095
+ this.cancelHover();
6096
+ };
6097
+ this.handleSelectStart = (e)=>{
6098
+ const target = e.target;
6099
+ // Only IE requires us to explicitly say
6100
+ // we want drag drop operation to start
6101
+ if (typeof target.dragDrop !== 'function') {
6102
+ return;
6103
+ }
6104
+ // Inputs and textareas should be selectable
6105
+ if (target.tagName === 'INPUT' || target.tagName === 'SELECT' || target.tagName === 'TEXTAREA' || target.isContentEditable) {
6106
+ return;
6107
+ }
6108
+ // For other targets, ask IE
6109
+ // to enable drag and drop
6110
+ e.preventDefault();
6111
+ target.dragDrop();
6112
+ };
6113
+ this.options = new OptionsReader(globalContext, options);
6114
+ this.actions = manager.getActions();
6115
+ this.monitor = manager.getMonitor();
6116
+ this.registry = manager.getRegistry();
6117
+ this.enterLeaveCounter = new EnterLeaveCounter(this.isNodeInDocument);
6118
+ }
6119
+ }
6120
+
6121
+ const HTML5Backend = function createBackend(manager, context, options) {
6122
+ return new HTML5BackendImpl(manager, context, options);
6123
+ };
6124
+
5145
6125
  function DDContext(_a) {
5146
6126
  var children = _a.children;
5147
6127
  return React.createElement(DndProvider, { backend: HTML5Backend }, children);