@rkmodules/rules 0.0.61 → 0.0.63

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