material-react-table 0.8.6 → 0.8.9

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.
@@ -10,8 +10,7 @@ var iconsMaterial = require('@mui/icons-material');
10
10
  var reactTable = require('@tanstack/react-table');
11
11
  var material = require('@mui/material');
12
12
  var matchSorterUtils = require('@tanstack/match-sorter-utils');
13
- var reactDnd = require('react-dnd');
14
- var reactDndHtml5Backend = require('react-dnd-html5-backend');
13
+ var jsxRuntime = require('react/jsx-runtime');
15
14
 
16
15
  function _extends() {
17
16
  _extends = Object.assign ? Object.assign.bind() : function (target) {
@@ -1199,6 +1198,3753 @@ var MRT_SelectCheckbox = function MRT_SelectCheckbox(_ref) {
1199
1198
  })));
1200
1199
  };
1201
1200
 
1201
+ /**
1202
+ * Create the React Context
1203
+ */ const DndContext = React.createContext({
1204
+ dragDropManager: undefined
1205
+ });
1206
+
1207
+ // Inlined version of the `symbol-observable` polyfill
1208
+ var $$observable = (function () {
1209
+ return typeof Symbol === 'function' && Symbol.observable || '@@observable';
1210
+ })();
1211
+
1212
+ /**
1213
+ * These are private action types reserved by Redux.
1214
+ * For any unknown actions, you must return the current state.
1215
+ * If the current state is undefined, you must return the initial state.
1216
+ * Do not reference these action types directly in your code.
1217
+ */
1218
+ var randomString = function randomString() {
1219
+ return Math.random().toString(36).substring(7).split('').join('.');
1220
+ };
1221
+
1222
+ var ActionTypes = {
1223
+ INIT: "@@redux/INIT" + randomString(),
1224
+ REPLACE: "@@redux/REPLACE" + randomString(),
1225
+ PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() {
1226
+ return "@@redux/PROBE_UNKNOWN_ACTION" + randomString();
1227
+ }
1228
+ };
1229
+
1230
+ /**
1231
+ * @param {any} obj The object to inspect.
1232
+ * @returns {boolean} True if the argument appears to be a plain object.
1233
+ */
1234
+ function isPlainObject(obj) {
1235
+ if (typeof obj !== 'object' || obj === null) return false;
1236
+ var proto = obj;
1237
+
1238
+ while (Object.getPrototypeOf(proto) !== null) {
1239
+ proto = Object.getPrototypeOf(proto);
1240
+ }
1241
+
1242
+ return Object.getPrototypeOf(obj) === proto;
1243
+ }
1244
+
1245
+ // Inlined / shortened version of `kindOf` from https://github.com/jonschlinkert/kind-of
1246
+ function miniKindOf(val) {
1247
+ if (val === void 0) return 'undefined';
1248
+ if (val === null) return 'null';
1249
+ var type = typeof val;
1250
+
1251
+ switch (type) {
1252
+ case 'boolean':
1253
+ case 'string':
1254
+ case 'number':
1255
+ case 'symbol':
1256
+ case 'function':
1257
+ {
1258
+ return type;
1259
+ }
1260
+ }
1261
+
1262
+ if (Array.isArray(val)) return 'array';
1263
+ if (isDate(val)) return 'date';
1264
+ if (isError(val)) return 'error';
1265
+ var constructorName = ctorName(val);
1266
+
1267
+ switch (constructorName) {
1268
+ case 'Symbol':
1269
+ case 'Promise':
1270
+ case 'WeakMap':
1271
+ case 'WeakSet':
1272
+ case 'Map':
1273
+ case 'Set':
1274
+ return constructorName;
1275
+ } // other
1276
+
1277
+
1278
+ return type.slice(8, -1).toLowerCase().replace(/\s/g, '');
1279
+ }
1280
+
1281
+ function ctorName(val) {
1282
+ return typeof val.constructor === 'function' ? val.constructor.name : null;
1283
+ }
1284
+
1285
+ function isError(val) {
1286
+ return val instanceof Error || typeof val.message === 'string' && val.constructor && typeof val.constructor.stackTraceLimit === 'number';
1287
+ }
1288
+
1289
+ function isDate(val) {
1290
+ if (val instanceof Date) return true;
1291
+ return typeof val.toDateString === 'function' && typeof val.getDate === 'function' && typeof val.setDate === 'function';
1292
+ }
1293
+
1294
+ function kindOf(val) {
1295
+ var typeOfVal = typeof val;
1296
+
1297
+ {
1298
+ typeOfVal = miniKindOf(val);
1299
+ }
1300
+
1301
+ return typeOfVal;
1302
+ }
1303
+
1304
+ /**
1305
+ * @deprecated
1306
+ *
1307
+ * **We recommend using the `configureStore` method
1308
+ * of the `@reduxjs/toolkit` package**, which replaces `createStore`.
1309
+ *
1310
+ * Redux Toolkit is our recommended approach for writing Redux logic today,
1311
+ * including store setup, reducers, data fetching, and more.
1312
+ *
1313
+ * **For more details, please read this Redux docs page:**
1314
+ * **https://redux.js.org/introduction/why-rtk-is-redux-today**
1315
+ *
1316
+ * `configureStore` from Redux Toolkit is an improved version of `createStore` that
1317
+ * simplifies setup and helps avoid common bugs.
1318
+ *
1319
+ * You should not be using the `redux` core package by itself today, except for learning purposes.
1320
+ * The `createStore` method from the core `redux` package will not be removed, but we encourage
1321
+ * all users to migrate to using Redux Toolkit for all Redux code.
1322
+ *
1323
+ * If you want to use `createStore` without this visual deprecation warning, use
1324
+ * the `legacy_createStore` import instead:
1325
+ *
1326
+ * `import { legacy_createStore as createStore} from 'redux'`
1327
+ *
1328
+ */
1329
+
1330
+ function createStore(reducer, preloadedState, enhancer) {
1331
+ var _ref2;
1332
+
1333
+ if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') {
1334
+ throw new Error( 'It looks like you are passing several store enhancers to ' + 'createStore(). This is not supported. Instead, compose them ' + 'together to a single function. See https://redux.js.org/tutorials/fundamentals/part-4-store#creating-a-store-with-enhancers for an example.');
1335
+ }
1336
+
1337
+ if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {
1338
+ enhancer = preloadedState;
1339
+ preloadedState = undefined;
1340
+ }
1341
+
1342
+ if (typeof enhancer !== 'undefined') {
1343
+ if (typeof enhancer !== 'function') {
1344
+ throw new Error( "Expected the enhancer to be a function. Instead, received: '" + kindOf(enhancer) + "'");
1345
+ }
1346
+
1347
+ return enhancer(createStore)(reducer, preloadedState);
1348
+ }
1349
+
1350
+ if (typeof reducer !== 'function') {
1351
+ throw new Error( "Expected the root reducer to be a function. Instead, received: '" + kindOf(reducer) + "'");
1352
+ }
1353
+
1354
+ var currentReducer = reducer;
1355
+ var currentState = preloadedState;
1356
+ var currentListeners = [];
1357
+ var nextListeners = currentListeners;
1358
+ var isDispatching = false;
1359
+ /**
1360
+ * This makes a shallow copy of currentListeners so we can use
1361
+ * nextListeners as a temporary list while dispatching.
1362
+ *
1363
+ * This prevents any bugs around consumers calling
1364
+ * subscribe/unsubscribe in the middle of a dispatch.
1365
+ */
1366
+
1367
+ function ensureCanMutateNextListeners() {
1368
+ if (nextListeners === currentListeners) {
1369
+ nextListeners = currentListeners.slice();
1370
+ }
1371
+ }
1372
+ /**
1373
+ * Reads the state tree managed by the store.
1374
+ *
1375
+ * @returns {any} The current state tree of your application.
1376
+ */
1377
+
1378
+
1379
+ function getState() {
1380
+ if (isDispatching) {
1381
+ throw new Error( 'You may not call store.getState() while the reducer is executing. ' + 'The reducer has already received the state as an argument. ' + 'Pass it down from the top reducer instead of reading it from the store.');
1382
+ }
1383
+
1384
+ return currentState;
1385
+ }
1386
+ /**
1387
+ * Adds a change listener. It will be called any time an action is dispatched,
1388
+ * and some part of the state tree may potentially have changed. You may then
1389
+ * call `getState()` to read the current state tree inside the callback.
1390
+ *
1391
+ * You may call `dispatch()` from a change listener, with the following
1392
+ * caveats:
1393
+ *
1394
+ * 1. The subscriptions are snapshotted just before every `dispatch()` call.
1395
+ * If you subscribe or unsubscribe while the listeners are being invoked, this
1396
+ * will not have any effect on the `dispatch()` that is currently in progress.
1397
+ * However, the next `dispatch()` call, whether nested or not, will use a more
1398
+ * recent snapshot of the subscription list.
1399
+ *
1400
+ * 2. The listener should not expect to see all state changes, as the state
1401
+ * might have been updated multiple times during a nested `dispatch()` before
1402
+ * the listener is called. It is, however, guaranteed that all subscribers
1403
+ * registered before the `dispatch()` started will be called with the latest
1404
+ * state by the time it exits.
1405
+ *
1406
+ * @param {Function} listener A callback to be invoked on every dispatch.
1407
+ * @returns {Function} A function to remove this change listener.
1408
+ */
1409
+
1410
+
1411
+ function subscribe(listener) {
1412
+ if (typeof listener !== 'function') {
1413
+ throw new Error( "Expected the listener to be a function. Instead, received: '" + kindOf(listener) + "'");
1414
+ }
1415
+
1416
+ if (isDispatching) {
1417
+ throw new Error( 'You may not call store.subscribe() while the reducer is executing. ' + 'If you would like to be notified after the store has been updated, subscribe from a ' + 'component and invoke store.getState() in the callback to access the latest state. ' + 'See https://redux.js.org/api/store#subscribelistener for more details.');
1418
+ }
1419
+
1420
+ var isSubscribed = true;
1421
+ ensureCanMutateNextListeners();
1422
+ nextListeners.push(listener);
1423
+ return function unsubscribe() {
1424
+ if (!isSubscribed) {
1425
+ return;
1426
+ }
1427
+
1428
+ if (isDispatching) {
1429
+ throw new Error( 'You may not unsubscribe from a store listener while the reducer is executing. ' + 'See https://redux.js.org/api/store#subscribelistener for more details.');
1430
+ }
1431
+
1432
+ isSubscribed = false;
1433
+ ensureCanMutateNextListeners();
1434
+ var index = nextListeners.indexOf(listener);
1435
+ nextListeners.splice(index, 1);
1436
+ currentListeners = null;
1437
+ };
1438
+ }
1439
+ /**
1440
+ * Dispatches an action. It is the only way to trigger a state change.
1441
+ *
1442
+ * The `reducer` function, used to create the store, will be called with the
1443
+ * current state tree and the given `action`. Its return value will
1444
+ * be considered the **next** state of the tree, and the change listeners
1445
+ * will be notified.
1446
+ *
1447
+ * The base implementation only supports plain object actions. If you want to
1448
+ * dispatch a Promise, an Observable, a thunk, or something else, you need to
1449
+ * wrap your store creating function into the corresponding middleware. For
1450
+ * example, see the documentation for the `redux-thunk` package. Even the
1451
+ * middleware will eventually dispatch plain object actions using this method.
1452
+ *
1453
+ * @param {Object} action A plain object representing “what changed”. It is
1454
+ * a good idea to keep actions serializable so you can record and replay user
1455
+ * sessions, or use the time travelling `redux-devtools`. An action must have
1456
+ * a `type` property which may not be `undefined`. It is a good idea to use
1457
+ * string constants for action types.
1458
+ *
1459
+ * @returns {Object} For convenience, the same action object you dispatched.
1460
+ *
1461
+ * Note that, if you use a custom middleware, it may wrap `dispatch()` to
1462
+ * return something else (for example, a Promise you can await).
1463
+ */
1464
+
1465
+
1466
+ function dispatch(action) {
1467
+ if (!isPlainObject(action)) {
1468
+ throw new Error( "Actions must be plain objects. Instead, the actual type was: '" + kindOf(action) + "'. You may need to add middleware to your store setup to handle dispatching other values, such as 'redux-thunk' to handle dispatching functions. See https://redux.js.org/tutorials/fundamentals/part-4-store#middleware and https://redux.js.org/tutorials/fundamentals/part-6-async-logic#using-the-redux-thunk-middleware for examples.");
1469
+ }
1470
+
1471
+ if (typeof action.type === 'undefined') {
1472
+ throw new Error( 'Actions may not have an undefined "type" property. You may have misspelled an action type string constant.');
1473
+ }
1474
+
1475
+ if (isDispatching) {
1476
+ throw new Error( 'Reducers may not dispatch actions.');
1477
+ }
1478
+
1479
+ try {
1480
+ isDispatching = true;
1481
+ currentState = currentReducer(currentState, action);
1482
+ } finally {
1483
+ isDispatching = false;
1484
+ }
1485
+
1486
+ var listeners = currentListeners = nextListeners;
1487
+
1488
+ for (var i = 0; i < listeners.length; i++) {
1489
+ var listener = listeners[i];
1490
+ listener();
1491
+ }
1492
+
1493
+ return action;
1494
+ }
1495
+ /**
1496
+ * Replaces the reducer currently used by the store to calculate the state.
1497
+ *
1498
+ * You might need this if your app implements code splitting and you want to
1499
+ * load some of the reducers dynamically. You might also need this if you
1500
+ * implement a hot reloading mechanism for Redux.
1501
+ *
1502
+ * @param {Function} nextReducer The reducer for the store to use instead.
1503
+ * @returns {void}
1504
+ */
1505
+
1506
+
1507
+ function replaceReducer(nextReducer) {
1508
+ if (typeof nextReducer !== 'function') {
1509
+ throw new Error( "Expected the nextReducer to be a function. Instead, received: '" + kindOf(nextReducer));
1510
+ }
1511
+
1512
+ currentReducer = nextReducer; // This action has a similiar effect to ActionTypes.INIT.
1513
+ // Any reducers that existed in both the new and old rootReducer
1514
+ // will receive the previous state. This effectively populates
1515
+ // the new state tree with any relevant data from the old one.
1516
+
1517
+ dispatch({
1518
+ type: ActionTypes.REPLACE
1519
+ });
1520
+ }
1521
+ /**
1522
+ * Interoperability point for observable/reactive libraries.
1523
+ * @returns {observable} A minimal observable of state changes.
1524
+ * For more information, see the observable proposal:
1525
+ * https://github.com/tc39/proposal-observable
1526
+ */
1527
+
1528
+
1529
+ function observable() {
1530
+ var _ref;
1531
+
1532
+ var outerSubscribe = subscribe;
1533
+ return _ref = {
1534
+ /**
1535
+ * The minimal observable subscription method.
1536
+ * @param {Object} observer Any object that can be used as an observer.
1537
+ * The observer object should have a `next` method.
1538
+ * @returns {subscription} An object with an `unsubscribe` method that can
1539
+ * be used to unsubscribe the observable from the store, and prevent further
1540
+ * emission of values from the observable.
1541
+ */
1542
+ subscribe: function subscribe(observer) {
1543
+ if (typeof observer !== 'object' || observer === null) {
1544
+ throw new Error( "Expected the observer to be an object. Instead, received: '" + kindOf(observer) + "'");
1545
+ }
1546
+
1547
+ function observeState() {
1548
+ if (observer.next) {
1549
+ observer.next(getState());
1550
+ }
1551
+ }
1552
+
1553
+ observeState();
1554
+ var unsubscribe = outerSubscribe(observeState);
1555
+ return {
1556
+ unsubscribe: unsubscribe
1557
+ };
1558
+ }
1559
+ }, _ref[$$observable] = function () {
1560
+ return this;
1561
+ }, _ref;
1562
+ } // When a store is created, an "INIT" action is dispatched so that every
1563
+ // reducer returns their initial state. This effectively populates
1564
+ // the initial state tree.
1565
+
1566
+
1567
+ dispatch({
1568
+ type: ActionTypes.INIT
1569
+ });
1570
+ return _ref2 = {
1571
+ dispatch: dispatch,
1572
+ subscribe: subscribe,
1573
+ getState: getState,
1574
+ replaceReducer: replaceReducer
1575
+ }, _ref2[$$observable] = observable, _ref2;
1576
+ }
1577
+
1578
+ /**
1579
+ * Prints a warning in the console if it exists.
1580
+ *
1581
+ * @param {String} message The warning message.
1582
+ * @returns {void}
1583
+ */
1584
+ function warning(message) {
1585
+ /* eslint-disable no-console */
1586
+ if (typeof console !== 'undefined' && typeof console.error === 'function') {
1587
+ console.error(message);
1588
+ }
1589
+ /* eslint-enable no-console */
1590
+
1591
+
1592
+ try {
1593
+ // This error was thrown as a convenience so that if you enable
1594
+ // "break on all exceptions" in your console,
1595
+ // it would pause the execution at this line.
1596
+ throw new Error(message);
1597
+ } catch (e) {} // eslint-disable-line no-empty
1598
+
1599
+ }
1600
+
1601
+ /*
1602
+ * This is a dummy function to check if the function name has been altered by minification.
1603
+ * If the function has been minified and NODE_ENV !== 'production', warn the user.
1604
+ */
1605
+
1606
+ function isCrushed() {}
1607
+
1608
+ if ( typeof isCrushed.name === 'string' && isCrushed.name !== 'isCrushed') {
1609
+ warning('You are currently using minified code outside of NODE_ENV === "production". ' + 'This means that you are running a slower development build of Redux. ' + 'You can use loose-envify (https://github.com/zertosh/loose-envify) for browserify ' + 'or setting mode to production in webpack (https://webpack.js.org/concepts/mode/) ' + 'to ensure you have the correct code for your production build.');
1610
+ }
1611
+
1612
+ /**
1613
+ * Use invariant() to assert state which your program assumes to be true.
1614
+ *
1615
+ * Provide sprintf-style format (only %s is supported) and arguments
1616
+ * to provide information about what broke and what you were
1617
+ * expecting.
1618
+ *
1619
+ * The invariant message will be stripped in production, but the invariant
1620
+ * will remain to ensure logic does not differ in production.
1621
+ */ function invariant(condition, format, ...args) {
1622
+ if (isProduction()) {
1623
+ if (format === undefined) {
1624
+ throw new Error('invariant requires an error message argument');
1625
+ }
1626
+ }
1627
+ if (!condition) {
1628
+ let error;
1629
+ if (format === undefined) {
1630
+ error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
1631
+ } else {
1632
+ let argIndex = 0;
1633
+ error = new Error(format.replace(/%s/g, function() {
1634
+ return args[argIndex++];
1635
+ }));
1636
+ error.name = 'Invariant Violation';
1637
+ }
1638
+ error.framesToPop = 1 // we don't care about invariant's own frame
1639
+ ;
1640
+ throw error;
1641
+ }
1642
+ }
1643
+ function isProduction() {
1644
+ return typeof process !== 'undefined' && process.env['NODE_ENV'] === 'production';
1645
+ }
1646
+
1647
+ // cheap lodash replacements
1648
+ /**
1649
+ * drop-in replacement for _.get
1650
+ * @param obj
1651
+ * @param path
1652
+ * @param defaultValue
1653
+ */ function get(obj, path, defaultValue) {
1654
+ return path.split('.').reduce((a, c)=>a && a[c] ? a[c] : defaultValue || null
1655
+ , obj);
1656
+ }
1657
+ /**
1658
+ * drop-in replacement for _.without
1659
+ */ function without(items, item) {
1660
+ return items.filter((i)=>i !== item
1661
+ );
1662
+ }
1663
+ /**
1664
+ * drop-in replacement for _.isString
1665
+ * @param input
1666
+ */ function isObject(input) {
1667
+ return typeof input === 'object';
1668
+ }
1669
+ /**
1670
+ * replacement for _.xor
1671
+ * @param itemsA
1672
+ * @param itemsB
1673
+ */ function xor(itemsA, itemsB) {
1674
+ const map = new Map();
1675
+ const insertItem = (item)=>{
1676
+ map.set(item, map.has(item) ? map.get(item) + 1 : 1);
1677
+ };
1678
+ itemsA.forEach(insertItem);
1679
+ itemsB.forEach(insertItem);
1680
+ const result = [];
1681
+ map.forEach((count, key)=>{
1682
+ if (count === 1) {
1683
+ result.push(key);
1684
+ }
1685
+ });
1686
+ return result;
1687
+ }
1688
+ /**
1689
+ * replacement for _.intersection
1690
+ * @param itemsA
1691
+ * @param itemsB
1692
+ */ function intersection(itemsA, itemsB) {
1693
+ return itemsA.filter((t)=>itemsB.indexOf(t) > -1
1694
+ );
1695
+ }
1696
+
1697
+ const INIT_COORDS = 'dnd-core/INIT_COORDS';
1698
+ const BEGIN_DRAG = 'dnd-core/BEGIN_DRAG';
1699
+ const PUBLISH_DRAG_SOURCE = 'dnd-core/PUBLISH_DRAG_SOURCE';
1700
+ const HOVER = 'dnd-core/HOVER';
1701
+ const DROP = 'dnd-core/DROP';
1702
+ const END_DRAG = 'dnd-core/END_DRAG';
1703
+
1704
+ function setClientOffset(clientOffset, sourceClientOffset) {
1705
+ return {
1706
+ type: INIT_COORDS,
1707
+ payload: {
1708
+ sourceClientOffset: sourceClientOffset || null,
1709
+ clientOffset: clientOffset || null
1710
+ }
1711
+ };
1712
+ }
1713
+
1714
+ const ResetCoordinatesAction = {
1715
+ type: INIT_COORDS,
1716
+ payload: {
1717
+ clientOffset: null,
1718
+ sourceClientOffset: null
1719
+ }
1720
+ };
1721
+ function createBeginDrag(manager) {
1722
+ return function beginDrag(sourceIds = [], options = {
1723
+ publishSource: true
1724
+ }) {
1725
+ const { publishSource =true , clientOffset , getSourceClientOffset , } = options;
1726
+ const monitor = manager.getMonitor();
1727
+ const registry = manager.getRegistry();
1728
+ // Initialize the coordinates using the client offset
1729
+ manager.dispatch(setClientOffset(clientOffset));
1730
+ verifyInvariants(sourceIds, monitor, registry);
1731
+ // Get the draggable source
1732
+ const sourceId = getDraggableSource(sourceIds, monitor);
1733
+ if (sourceId == null) {
1734
+ manager.dispatch(ResetCoordinatesAction);
1735
+ return;
1736
+ }
1737
+ // Get the source client offset
1738
+ let sourceClientOffset = null;
1739
+ if (clientOffset) {
1740
+ if (!getSourceClientOffset) {
1741
+ throw new Error('getSourceClientOffset must be defined');
1742
+ }
1743
+ verifyGetSourceClientOffsetIsFunction(getSourceClientOffset);
1744
+ sourceClientOffset = getSourceClientOffset(sourceId);
1745
+ }
1746
+ // Initialize the full coordinates
1747
+ manager.dispatch(setClientOffset(clientOffset, sourceClientOffset));
1748
+ const source = registry.getSource(sourceId);
1749
+ const item = source.beginDrag(monitor, sourceId);
1750
+ // If source.beginDrag returns null, this is an indicator to cancel the drag
1751
+ if (item == null) {
1752
+ return undefined;
1753
+ }
1754
+ verifyItemIsObject(item);
1755
+ registry.pinSource(sourceId);
1756
+ const itemType = registry.getSourceType(sourceId);
1757
+ return {
1758
+ type: BEGIN_DRAG,
1759
+ payload: {
1760
+ itemType,
1761
+ item,
1762
+ sourceId,
1763
+ clientOffset: clientOffset || null,
1764
+ sourceClientOffset: sourceClientOffset || null,
1765
+ isSourcePublic: !!publishSource
1766
+ }
1767
+ };
1768
+ };
1769
+ }
1770
+ function verifyInvariants(sourceIds, monitor, registry) {
1771
+ invariant(!monitor.isDragging(), 'Cannot call beginDrag while dragging.');
1772
+ sourceIds.forEach(function(sourceId) {
1773
+ invariant(registry.getSource(sourceId), 'Expected sourceIds to be registered.');
1774
+ });
1775
+ }
1776
+ function verifyGetSourceClientOffsetIsFunction(getSourceClientOffset) {
1777
+ invariant(typeof getSourceClientOffset === 'function', 'When clientOffset is provided, getSourceClientOffset must be a function.');
1778
+ }
1779
+ function verifyItemIsObject(item) {
1780
+ invariant(isObject(item), 'Item must be an object.');
1781
+ }
1782
+ function getDraggableSource(sourceIds, monitor) {
1783
+ let sourceId = null;
1784
+ for(let i = sourceIds.length - 1; i >= 0; i--){
1785
+ if (monitor.canDragSource(sourceIds[i])) {
1786
+ sourceId = sourceIds[i];
1787
+ break;
1788
+ }
1789
+ }
1790
+ return sourceId;
1791
+ }
1792
+
1793
+ function _defineProperty(obj, key, value) {
1794
+ if (key in obj) {
1795
+ Object.defineProperty(obj, key, {
1796
+ value: value,
1797
+ enumerable: true,
1798
+ configurable: true,
1799
+ writable: true
1800
+ });
1801
+ } else {
1802
+ obj[key] = value;
1803
+ }
1804
+ return obj;
1805
+ }
1806
+ function _objectSpread(target) {
1807
+ for(var i = 1; i < arguments.length; i++){
1808
+ var source = arguments[i] != null ? arguments[i] : {};
1809
+ var ownKeys = Object.keys(source);
1810
+ if (typeof Object.getOwnPropertySymbols === 'function') {
1811
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
1812
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
1813
+ }));
1814
+ }
1815
+ ownKeys.forEach(function(key) {
1816
+ _defineProperty(target, key, source[key]);
1817
+ });
1818
+ }
1819
+ return target;
1820
+ }
1821
+ function createDrop(manager) {
1822
+ return function drop(options = {}) {
1823
+ const monitor = manager.getMonitor();
1824
+ const registry = manager.getRegistry();
1825
+ verifyInvariants$1(monitor);
1826
+ const targetIds = getDroppableTargets(monitor);
1827
+ // Multiple actions are dispatched here, which is why this doesn't return an action
1828
+ targetIds.forEach((targetId, index)=>{
1829
+ const dropResult = determineDropResult(targetId, index, registry, monitor);
1830
+ const action = {
1831
+ type: DROP,
1832
+ payload: {
1833
+ dropResult: _objectSpread({}, options, dropResult)
1834
+ }
1835
+ };
1836
+ manager.dispatch(action);
1837
+ });
1838
+ };
1839
+ }
1840
+ function verifyInvariants$1(monitor) {
1841
+ invariant(monitor.isDragging(), 'Cannot call drop while not dragging.');
1842
+ invariant(!monitor.didDrop(), 'Cannot call drop twice during one drag operation.');
1843
+ }
1844
+ function determineDropResult(targetId, index, registry, monitor) {
1845
+ const target = registry.getTarget(targetId);
1846
+ let dropResult = target ? target.drop(monitor, targetId) : undefined;
1847
+ verifyDropResultType(dropResult);
1848
+ if (typeof dropResult === 'undefined') {
1849
+ dropResult = index === 0 ? {} : monitor.getDropResult();
1850
+ }
1851
+ return dropResult;
1852
+ }
1853
+ function verifyDropResultType(dropResult) {
1854
+ invariant(typeof dropResult === 'undefined' || isObject(dropResult), 'Drop result must either be an object or undefined.');
1855
+ }
1856
+ function getDroppableTargets(monitor) {
1857
+ const targetIds = monitor.getTargetIds().filter(monitor.canDropOnTarget, monitor);
1858
+ targetIds.reverse();
1859
+ return targetIds;
1860
+ }
1861
+
1862
+ function createEndDrag(manager) {
1863
+ return function endDrag() {
1864
+ const monitor = manager.getMonitor();
1865
+ const registry = manager.getRegistry();
1866
+ verifyIsDragging(monitor);
1867
+ const sourceId = monitor.getSourceId();
1868
+ if (sourceId != null) {
1869
+ const source = registry.getSource(sourceId, true);
1870
+ source.endDrag(monitor, sourceId);
1871
+ registry.unpinSource();
1872
+ }
1873
+ return {
1874
+ type: END_DRAG
1875
+ };
1876
+ };
1877
+ }
1878
+ function verifyIsDragging(monitor) {
1879
+ invariant(monitor.isDragging(), 'Cannot call endDrag while not dragging.');
1880
+ }
1881
+
1882
+ function matchesType(targetType, draggedItemType) {
1883
+ if (draggedItemType === null) {
1884
+ return targetType === null;
1885
+ }
1886
+ return Array.isArray(targetType) ? targetType.some((t)=>t === draggedItemType
1887
+ ) : targetType === draggedItemType;
1888
+ }
1889
+
1890
+ function createHover(manager) {
1891
+ return function hover(targetIdsArg, { clientOffset } = {}) {
1892
+ verifyTargetIdsIsArray(targetIdsArg);
1893
+ const targetIds = targetIdsArg.slice(0);
1894
+ const monitor = manager.getMonitor();
1895
+ const registry = manager.getRegistry();
1896
+ const draggedItemType = monitor.getItemType();
1897
+ removeNonMatchingTargetIds(targetIds, registry, draggedItemType);
1898
+ checkInvariants(targetIds, monitor, registry);
1899
+ hoverAllTargets(targetIds, monitor, registry);
1900
+ return {
1901
+ type: HOVER,
1902
+ payload: {
1903
+ targetIds,
1904
+ clientOffset: clientOffset || null
1905
+ }
1906
+ };
1907
+ };
1908
+ }
1909
+ function verifyTargetIdsIsArray(targetIdsArg) {
1910
+ invariant(Array.isArray(targetIdsArg), 'Expected targetIds to be an array.');
1911
+ }
1912
+ function checkInvariants(targetIds, monitor, registry) {
1913
+ invariant(monitor.isDragging(), 'Cannot call hover while not dragging.');
1914
+ invariant(!monitor.didDrop(), 'Cannot call hover after drop.');
1915
+ for(let i = 0; i < targetIds.length; i++){
1916
+ const targetId = targetIds[i];
1917
+ invariant(targetIds.lastIndexOf(targetId) === i, 'Expected targetIds to be unique in the passed array.');
1918
+ const target = registry.getTarget(targetId);
1919
+ invariant(target, 'Expected targetIds to be registered.');
1920
+ }
1921
+ }
1922
+ function removeNonMatchingTargetIds(targetIds, registry, draggedItemType) {
1923
+ // Remove those targetIds that don't match the targetType. This
1924
+ // fixes shallow isOver which would only be non-shallow because of
1925
+ // non-matching targets.
1926
+ for(let i = targetIds.length - 1; i >= 0; i--){
1927
+ const targetId = targetIds[i];
1928
+ const targetType = registry.getTargetType(targetId);
1929
+ if (!matchesType(targetType, draggedItemType)) {
1930
+ targetIds.splice(i, 1);
1931
+ }
1932
+ }
1933
+ }
1934
+ function hoverAllTargets(targetIds, monitor, registry) {
1935
+ // Finally call hover on all matching targets.
1936
+ targetIds.forEach(function(targetId) {
1937
+ const target = registry.getTarget(targetId);
1938
+ target.hover(monitor, targetId);
1939
+ });
1940
+ }
1941
+
1942
+ function createPublishDragSource(manager) {
1943
+ return function publishDragSource() {
1944
+ const monitor = manager.getMonitor();
1945
+ if (monitor.isDragging()) {
1946
+ return {
1947
+ type: PUBLISH_DRAG_SOURCE
1948
+ };
1949
+ }
1950
+ return;
1951
+ };
1952
+ }
1953
+
1954
+ function createDragDropActions(manager) {
1955
+ return {
1956
+ beginDrag: createBeginDrag(manager),
1957
+ publishDragSource: createPublishDragSource(manager),
1958
+ hover: createHover(manager),
1959
+ drop: createDrop(manager),
1960
+ endDrag: createEndDrag(manager)
1961
+ };
1962
+ }
1963
+
1964
+ class DragDropManagerImpl {
1965
+ receiveBackend(backend) {
1966
+ this.backend = backend;
1967
+ }
1968
+ getMonitor() {
1969
+ return this.monitor;
1970
+ }
1971
+ getBackend() {
1972
+ return this.backend;
1973
+ }
1974
+ getRegistry() {
1975
+ return this.monitor.registry;
1976
+ }
1977
+ getActions() {
1978
+ /* eslint-disable-next-line @typescript-eslint/no-this-alias */ const manager = this;
1979
+ const { dispatch } = this.store;
1980
+ function bindActionCreator(actionCreator) {
1981
+ return (...args)=>{
1982
+ const action = actionCreator.apply(manager, args);
1983
+ if (typeof action !== 'undefined') {
1984
+ dispatch(action);
1985
+ }
1986
+ };
1987
+ }
1988
+ const actions = createDragDropActions(this);
1989
+ return Object.keys(actions).reduce((boundActions, key)=>{
1990
+ const action = actions[key];
1991
+ boundActions[key] = bindActionCreator(action);
1992
+ return boundActions;
1993
+ }, {});
1994
+ }
1995
+ dispatch(action) {
1996
+ this.store.dispatch(action);
1997
+ }
1998
+ constructor(store, monitor){
1999
+ this.isSetUp = false;
2000
+ this.handleRefCountChange = ()=>{
2001
+ const shouldSetUp = this.store.getState().refCount > 0;
2002
+ if (this.backend) {
2003
+ if (shouldSetUp && !this.isSetUp) {
2004
+ this.backend.setup();
2005
+ this.isSetUp = true;
2006
+ } else if (!shouldSetUp && this.isSetUp) {
2007
+ this.backend.teardown();
2008
+ this.isSetUp = false;
2009
+ }
2010
+ }
2011
+ };
2012
+ this.store = store;
2013
+ this.monitor = monitor;
2014
+ store.subscribe(this.handleRefCountChange);
2015
+ }
2016
+ }
2017
+
2018
+ /**
2019
+ * Coordinate addition
2020
+ * @param a The first coordinate
2021
+ * @param b The second coordinate
2022
+ */ function add(a, b) {
2023
+ return {
2024
+ x: a.x + b.x,
2025
+ y: a.y + b.y
2026
+ };
2027
+ }
2028
+ /**
2029
+ * Coordinate subtraction
2030
+ * @param a The first coordinate
2031
+ * @param b The second coordinate
2032
+ */ function subtract(a, b) {
2033
+ return {
2034
+ x: a.x - b.x,
2035
+ y: a.y - b.y
2036
+ };
2037
+ }
2038
+ /**
2039
+ * Returns the cartesian distance of the drag source component's position, based on its position
2040
+ * at the time when the current drag operation has started, and the movement difference.
2041
+ *
2042
+ * Returns null if no item is being dragged.
2043
+ *
2044
+ * @param state The offset state to compute from
2045
+ */ function getSourceClientOffset(state) {
2046
+ const { clientOffset , initialClientOffset , initialSourceClientOffset } = state;
2047
+ if (!clientOffset || !initialClientOffset || !initialSourceClientOffset) {
2048
+ return null;
2049
+ }
2050
+ return subtract(add(clientOffset, initialSourceClientOffset), initialClientOffset);
2051
+ }
2052
+ /**
2053
+ * Determines the x,y offset between the client offset and the initial client offset
2054
+ *
2055
+ * @param state The offset state to compute from
2056
+ */ function getDifferenceFromInitialOffset(state) {
2057
+ const { clientOffset , initialClientOffset } = state;
2058
+ if (!clientOffset || !initialClientOffset) {
2059
+ return null;
2060
+ }
2061
+ return subtract(clientOffset, initialClientOffset);
2062
+ }
2063
+
2064
+ const NONE = [];
2065
+ const ALL = [];
2066
+ NONE.__IS_NONE__ = true;
2067
+ ALL.__IS_ALL__ = true;
2068
+ /**
2069
+ * Determines if the given handler IDs are dirty or not.
2070
+ *
2071
+ * @param dirtyIds The set of dirty handler ids
2072
+ * @param handlerIds The set of handler ids to check
2073
+ */ function areDirty(dirtyIds, handlerIds) {
2074
+ if (dirtyIds === NONE) {
2075
+ return false;
2076
+ }
2077
+ if (dirtyIds === ALL || typeof handlerIds === 'undefined') {
2078
+ return true;
2079
+ }
2080
+ const commonIds = intersection(handlerIds, dirtyIds);
2081
+ return commonIds.length > 0;
2082
+ }
2083
+
2084
+ class DragDropMonitorImpl {
2085
+ subscribeToStateChange(listener, options = {}) {
2086
+ const { handlerIds } = options;
2087
+ invariant(typeof listener === 'function', 'listener must be a function.');
2088
+ invariant(typeof handlerIds === 'undefined' || Array.isArray(handlerIds), 'handlerIds, when specified, must be an array of strings.');
2089
+ let prevStateId = this.store.getState().stateId;
2090
+ const handleChange = ()=>{
2091
+ const state = this.store.getState();
2092
+ const currentStateId = state.stateId;
2093
+ try {
2094
+ const canSkipListener = currentStateId === prevStateId || currentStateId === prevStateId + 1 && !areDirty(state.dirtyHandlerIds, handlerIds);
2095
+ if (!canSkipListener) {
2096
+ listener();
2097
+ }
2098
+ } finally{
2099
+ prevStateId = currentStateId;
2100
+ }
2101
+ };
2102
+ return this.store.subscribe(handleChange);
2103
+ }
2104
+ subscribeToOffsetChange(listener) {
2105
+ invariant(typeof listener === 'function', 'listener must be a function.');
2106
+ let previousState = this.store.getState().dragOffset;
2107
+ const handleChange = ()=>{
2108
+ const nextState = this.store.getState().dragOffset;
2109
+ if (nextState === previousState) {
2110
+ return;
2111
+ }
2112
+ previousState = nextState;
2113
+ listener();
2114
+ };
2115
+ return this.store.subscribe(handleChange);
2116
+ }
2117
+ canDragSource(sourceId) {
2118
+ if (!sourceId) {
2119
+ return false;
2120
+ }
2121
+ const source = this.registry.getSource(sourceId);
2122
+ invariant(source, `Expected to find a valid source. sourceId=${sourceId}`);
2123
+ if (this.isDragging()) {
2124
+ return false;
2125
+ }
2126
+ return source.canDrag(this, sourceId);
2127
+ }
2128
+ canDropOnTarget(targetId) {
2129
+ // undefined on initial render
2130
+ if (!targetId) {
2131
+ return false;
2132
+ }
2133
+ const target = this.registry.getTarget(targetId);
2134
+ invariant(target, `Expected to find a valid target. targetId=${targetId}`);
2135
+ if (!this.isDragging() || this.didDrop()) {
2136
+ return false;
2137
+ }
2138
+ const targetType = this.registry.getTargetType(targetId);
2139
+ const draggedItemType = this.getItemType();
2140
+ return matchesType(targetType, draggedItemType) && target.canDrop(this, targetId);
2141
+ }
2142
+ isDragging() {
2143
+ return Boolean(this.getItemType());
2144
+ }
2145
+ isDraggingSource(sourceId) {
2146
+ // undefined on initial render
2147
+ if (!sourceId) {
2148
+ return false;
2149
+ }
2150
+ const source = this.registry.getSource(sourceId, true);
2151
+ invariant(source, `Expected to find a valid source. sourceId=${sourceId}`);
2152
+ if (!this.isDragging() || !this.isSourcePublic()) {
2153
+ return false;
2154
+ }
2155
+ const sourceType = this.registry.getSourceType(sourceId);
2156
+ const draggedItemType = this.getItemType();
2157
+ if (sourceType !== draggedItemType) {
2158
+ return false;
2159
+ }
2160
+ return source.isDragging(this, sourceId);
2161
+ }
2162
+ isOverTarget(targetId, options = {
2163
+ shallow: false
2164
+ }) {
2165
+ // undefined on initial render
2166
+ if (!targetId) {
2167
+ return false;
2168
+ }
2169
+ const { shallow } = options;
2170
+ if (!this.isDragging()) {
2171
+ return false;
2172
+ }
2173
+ const targetType = this.registry.getTargetType(targetId);
2174
+ const draggedItemType = this.getItemType();
2175
+ if (draggedItemType && !matchesType(targetType, draggedItemType)) {
2176
+ return false;
2177
+ }
2178
+ const targetIds = this.getTargetIds();
2179
+ if (!targetIds.length) {
2180
+ return false;
2181
+ }
2182
+ const index = targetIds.indexOf(targetId);
2183
+ if (shallow) {
2184
+ return index === targetIds.length - 1;
2185
+ } else {
2186
+ return index > -1;
2187
+ }
2188
+ }
2189
+ getItemType() {
2190
+ return this.store.getState().dragOperation.itemType;
2191
+ }
2192
+ getItem() {
2193
+ return this.store.getState().dragOperation.item;
2194
+ }
2195
+ getSourceId() {
2196
+ return this.store.getState().dragOperation.sourceId;
2197
+ }
2198
+ getTargetIds() {
2199
+ return this.store.getState().dragOperation.targetIds;
2200
+ }
2201
+ getDropResult() {
2202
+ return this.store.getState().dragOperation.dropResult;
2203
+ }
2204
+ didDrop() {
2205
+ return this.store.getState().dragOperation.didDrop;
2206
+ }
2207
+ isSourcePublic() {
2208
+ return Boolean(this.store.getState().dragOperation.isSourcePublic);
2209
+ }
2210
+ getInitialClientOffset() {
2211
+ return this.store.getState().dragOffset.initialClientOffset;
2212
+ }
2213
+ getInitialSourceClientOffset() {
2214
+ return this.store.getState().dragOffset.initialSourceClientOffset;
2215
+ }
2216
+ getClientOffset() {
2217
+ return this.store.getState().dragOffset.clientOffset;
2218
+ }
2219
+ getSourceClientOffset() {
2220
+ return getSourceClientOffset(this.store.getState().dragOffset);
2221
+ }
2222
+ getDifferenceFromInitialOffset() {
2223
+ return getDifferenceFromInitialOffset(this.store.getState().dragOffset);
2224
+ }
2225
+ constructor(store, registry){
2226
+ this.store = store;
2227
+ this.registry = registry;
2228
+ }
2229
+ }
2230
+
2231
+ // Safari 6 and 6.1 for desktop, iPad, and iPhone are the only browsers that
2232
+ // have WebKitMutationObserver but not un-prefixed MutationObserver.
2233
+ // Must use `global` or `self` instead of `window` to work in both frames and web
2234
+ // workers. `global` is a provision of Browserify, Mr, Mrs, or Mop.
2235
+ /* globals self */ const scope = typeof global !== 'undefined' ? global : self;
2236
+ const BrowserMutationObserver = scope.MutationObserver || scope.WebKitMutationObserver;
2237
+ function makeRequestCallFromTimer(callback) {
2238
+ return function requestCall() {
2239
+ // We dispatch a timeout with a specified delay of 0 for engines that
2240
+ // can reliably accommodate that request. This will usually be snapped
2241
+ // to a 4 milisecond delay, but once we're flushing, there's no delay
2242
+ // between events.
2243
+ const timeoutHandle = setTimeout(handleTimer, 0);
2244
+ // However, since this timer gets frequently dropped in Firefox
2245
+ // workers, we enlist an interval handle that will try to fire
2246
+ // an event 20 times per second until it succeeds.
2247
+ const intervalHandle = setInterval(handleTimer, 50);
2248
+ function handleTimer() {
2249
+ // Whichever timer succeeds will cancel both timers and
2250
+ // execute the callback.
2251
+ clearTimeout(timeoutHandle);
2252
+ clearInterval(intervalHandle);
2253
+ callback();
2254
+ }
2255
+ };
2256
+ }
2257
+ // To request a high priority event, we induce a mutation observer by toggling
2258
+ // the text of a text node between "1" and "-1".
2259
+ function makeRequestCallFromMutationObserver(callback) {
2260
+ let toggle = 1;
2261
+ const observer = new BrowserMutationObserver(callback);
2262
+ const node = document.createTextNode('');
2263
+ observer.observe(node, {
2264
+ characterData: true
2265
+ });
2266
+ return function requestCall() {
2267
+ toggle = -toggle;
2268
+ node.data = toggle;
2269
+ };
2270
+ }
2271
+ const makeRequestCall = typeof BrowserMutationObserver === 'function' ? // reliably everywhere they are implemented.
2272
+ // They are implemented in all modern browsers.
2273
+ //
2274
+ // - Android 4-4.3
2275
+ // - Chrome 26-34
2276
+ // - Firefox 14-29
2277
+ // - Internet Explorer 11
2278
+ // - iPad Safari 6-7.1
2279
+ // - iPhone Safari 7-7.1
2280
+ // - Safari 6-7
2281
+ makeRequestCallFromMutationObserver : // task queue, are implemented in Internet Explorer 10, Safari 5.0-1, and Opera
2282
+ // 11-12, and in web workers in many engines.
2283
+ // Although message channels yield to any queued rendering and IO tasks, they
2284
+ // would be better than imposing the 4ms delay of timers.
2285
+ // However, they do not work reliably in Internet Explorer or Safari.
2286
+ // Internet Explorer 10 is the only browser that has setImmediate but does
2287
+ // not have MutationObservers.
2288
+ // Although setImmediate yields to the browser's renderer, it would be
2289
+ // preferrable to falling back to setTimeout since it does not have
2290
+ // the minimum 4ms penalty.
2291
+ // Unfortunately there appears to be a bug in Internet Explorer 10 Mobile (and
2292
+ // Desktop to a lesser extent) that renders both setImmediate and
2293
+ // MessageChannel useless for the purposes of ASAP.
2294
+ // https://github.com/kriskowal/q/issues/396
2295
+ // Timers are implemented universally.
2296
+ // We fall back to timers in workers in most engines, and in foreground
2297
+ // contexts in the following browsers.
2298
+ // However, note that even this simple case requires nuances to operate in a
2299
+ // broad spectrum of browsers.
2300
+ //
2301
+ // - Firefox 3-13
2302
+ // - Internet Explorer 6-9
2303
+ // - iPad Safari 4.3
2304
+ // - Lynx 2.8.7
2305
+ makeRequestCallFromTimer;
2306
+
2307
+ class AsapQueue {
2308
+ // Use the fastest means possible to execute a task in its own turn, with
2309
+ // priority over other events including IO, animation, reflow, and redraw
2310
+ // events in browsers.
2311
+ //
2312
+ // An exception thrown by a task will permanently interrupt the processing of
2313
+ // subsequent tasks. The higher level `asap` function ensures that if an
2314
+ // exception is thrown by a task, that the task queue will continue flushing as
2315
+ // soon as possible, but if you use `rawAsap` directly, you are responsible to
2316
+ // either ensure that no exceptions are thrown from your task, or to manually
2317
+ // call `rawAsap.requestFlush` if an exception is thrown.
2318
+ enqueueTask(task) {
2319
+ const { queue: q , requestFlush } = this;
2320
+ if (!q.length) {
2321
+ requestFlush();
2322
+ this.flushing = true;
2323
+ }
2324
+ // Equivalent to push, but avoids a function call.
2325
+ q[q.length] = task;
2326
+ }
2327
+ constructor(){
2328
+ this.queue = [];
2329
+ // We queue errors to ensure they are thrown in right order (FIFO).
2330
+ // Array-as-queue is good enough here, since we are just dealing with exceptions.
2331
+ this.pendingErrors = [];
2332
+ // Once a flush has been requested, no further calls to `requestFlush` are
2333
+ // necessary until the next `flush` completes.
2334
+ // @ts-ignore
2335
+ this.flushing = false;
2336
+ // The position of the next task to execute in the task queue. This is
2337
+ // preserved between calls to `flush` so that it can be resumed if
2338
+ // a task throws an exception.
2339
+ this.index = 0;
2340
+ // If a task schedules additional tasks recursively, the task queue can grow
2341
+ // unbounded. To prevent memory exhaustion, the task queue will periodically
2342
+ // truncate already-completed tasks.
2343
+ this.capacity = 1024;
2344
+ // The flush function processes all tasks that have been scheduled with
2345
+ // `rawAsap` unless and until one of those tasks throws an exception.
2346
+ // If a task throws an exception, `flush` ensures that its state will remain
2347
+ // consistent and will resume where it left off when called again.
2348
+ // However, `flush` does not make any arrangements to be called again if an
2349
+ // exception is thrown.
2350
+ this.flush = ()=>{
2351
+ const { queue: q } = this;
2352
+ while(this.index < q.length){
2353
+ const currentIndex = this.index;
2354
+ // Advance the index before calling the task. This ensures that we will
2355
+ // begin flushing on the next task the task throws an error.
2356
+ this.index++;
2357
+ q[currentIndex].call();
2358
+ // Prevent leaking memory for long chains of recursive calls to `asap`.
2359
+ // If we call `asap` within tasks scheduled by `asap`, the queue will
2360
+ // grow, but to avoid an O(n) walk for every task we execute, we don't
2361
+ // shift tasks off the queue after they have been executed.
2362
+ // Instead, we periodically shift 1024 tasks off the queue.
2363
+ if (this.index > this.capacity) {
2364
+ // Manually shift all values starting at the index back to the
2365
+ // beginning of the queue.
2366
+ for(let scan = 0, newLength = q.length - this.index; scan < newLength; scan++){
2367
+ q[scan] = q[scan + this.index];
2368
+ }
2369
+ q.length -= this.index;
2370
+ this.index = 0;
2371
+ }
2372
+ }
2373
+ q.length = 0;
2374
+ this.index = 0;
2375
+ this.flushing = false;
2376
+ };
2377
+ // In a web browser, exceptions are not fatal. However, to avoid
2378
+ // slowing down the queue of pending tasks, we rethrow the error in a
2379
+ // lower priority turn.
2380
+ this.registerPendingError = (err)=>{
2381
+ this.pendingErrors.push(err);
2382
+ this.requestErrorThrow();
2383
+ };
2384
+ // `requestFlush` requests that the high priority event queue be flushed as
2385
+ // soon as possible.
2386
+ // This is useful to prevent an error thrown in a task from stalling the event
2387
+ // queue if the exception handled by Node.js’s
2388
+ // `process.on("uncaughtException")` or by a domain.
2389
+ // `requestFlush` is implemented using a strategy based on data collected from
2390
+ // every available SauceLabs Selenium web driver worker at time of writing.
2391
+ // https://docs.google.com/spreadsheets/d/1mG-5UYGup5qxGdEMWkhP6BWCz053NUb2E1QoUTU16uA/edit#gid=783724593
2392
+ this.requestFlush = makeRequestCall(this.flush);
2393
+ this.requestErrorThrow = makeRequestCallFromTimer(()=>{
2394
+ // Throw first error
2395
+ if (this.pendingErrors.length) {
2396
+ throw this.pendingErrors.shift();
2397
+ }
2398
+ });
2399
+ }
2400
+ } // The message channel technique was discovered by Malte Ubl and was the
2401
+ // original foundation for this library.
2402
+ // http://www.nonblocking.io/2011/06/windownexttick.html
2403
+ // Safari 6.0.5 (at least) intermittently fails to create message ports on a
2404
+ // page's first load. Thankfully, this version of Safari supports
2405
+ // MutationObservers, so we don't need to fall back in that case.
2406
+ // function makeRequestCallFromMessageChannel(callback) {
2407
+ // var channel = new MessageChannel();
2408
+ // channel.port1.onmessage = callback;
2409
+ // return function requestCall() {
2410
+ // channel.port2.postMessage(0);
2411
+ // };
2412
+ // }
2413
+ // For reasons explained above, we are also unable to use `setImmediate`
2414
+ // under any circumstances.
2415
+ // Even if we were, there is another bug in Internet Explorer 10.
2416
+ // It is not sufficient to assign `setImmediate` to `requestFlush` because
2417
+ // `setImmediate` must be called *by name* and therefore must be wrapped in a
2418
+ // closure.
2419
+ // Never forget.
2420
+ // function makeRequestCallFromSetImmediate(callback) {
2421
+ // return function requestCall() {
2422
+ // setImmediate(callback);
2423
+ // };
2424
+ // }
2425
+ // Safari 6.0 has a problem where timers will get lost while the user is
2426
+ // scrolling. This problem does not impact ASAP because Safari 6.0 supports
2427
+ // mutation observers, so that implementation is used instead.
2428
+ // However, if we ever elect to use timers in Safari, the prevalent work-around
2429
+ // is to add a scroll event listener that calls for a flush.
2430
+ // `setTimeout` does not call the passed callback if the delay is less than
2431
+ // approximately 7 in web workers in Firefox 8 through 18, and sometimes not
2432
+ // even then.
2433
+ // This is for `asap.js` only.
2434
+ // Its name will be periodically randomized to break any code that depends on
2435
+ // // its existence.
2436
+ // rawAsap.makeRequestCallFromTimer = makeRequestCallFromTimer
2437
+ // ASAP was originally a nextTick shim included in Q. This was factored out
2438
+ // into this ASAP package. It was later adapted to RSVP which made further
2439
+ // amendments. These decisions, particularly to marginalize MessageChannel and
2440
+ // to capture the MutationObserver implementation in a closure, were integrated
2441
+ // back into ASAP proper.
2442
+ // https://github.com/tildeio/rsvp.js/blob/cddf7232546a9cf858524b75cde6f9edf72620a7/lib/rsvp/asap.js
2443
+
2444
+ // `call`, just like a function.
2445
+ class RawTask {
2446
+ call() {
2447
+ try {
2448
+ this.task && this.task();
2449
+ } catch (error) {
2450
+ this.onError(error);
2451
+ } finally{
2452
+ this.task = null;
2453
+ this.release(this);
2454
+ }
2455
+ }
2456
+ constructor(onError, release){
2457
+ this.onError = onError;
2458
+ this.release = release;
2459
+ this.task = null;
2460
+ }
2461
+ }
2462
+
2463
+ class TaskFactory {
2464
+ create(task) {
2465
+ const tasks = this.freeTasks;
2466
+ const t1 = tasks.length ? tasks.pop() : new RawTask(this.onError, (t)=>tasks[tasks.length] = t
2467
+ );
2468
+ t1.task = task;
2469
+ return t1;
2470
+ }
2471
+ constructor(onError){
2472
+ this.onError = onError;
2473
+ this.freeTasks = [];
2474
+ }
2475
+ }
2476
+
2477
+ const asapQueue = new AsapQueue();
2478
+ const taskFactory = new TaskFactory(asapQueue.registerPendingError);
2479
+ /**
2480
+ * Calls a task as soon as possible after returning, in its own event, with priority
2481
+ * over other events like animation, reflow, and repaint. An error thrown from an
2482
+ * event will not interrupt, nor even substantially slow down the processing of
2483
+ * other events, but will be rather postponed to a lower priority event.
2484
+ * @param {{call}} task A callable object, typically a function that takes no
2485
+ * arguments.
2486
+ */ function asap(task) {
2487
+ asapQueue.enqueueTask(taskFactory.create(task));
2488
+ }
2489
+
2490
+ const ADD_SOURCE = 'dnd-core/ADD_SOURCE';
2491
+ const ADD_TARGET = 'dnd-core/ADD_TARGET';
2492
+ const REMOVE_SOURCE = 'dnd-core/REMOVE_SOURCE';
2493
+ const REMOVE_TARGET = 'dnd-core/REMOVE_TARGET';
2494
+ function addSource(sourceId) {
2495
+ return {
2496
+ type: ADD_SOURCE,
2497
+ payload: {
2498
+ sourceId
2499
+ }
2500
+ };
2501
+ }
2502
+ function addTarget(targetId) {
2503
+ return {
2504
+ type: ADD_TARGET,
2505
+ payload: {
2506
+ targetId
2507
+ }
2508
+ };
2509
+ }
2510
+ function removeSource(sourceId) {
2511
+ return {
2512
+ type: REMOVE_SOURCE,
2513
+ payload: {
2514
+ sourceId
2515
+ }
2516
+ };
2517
+ }
2518
+ function removeTarget(targetId) {
2519
+ return {
2520
+ type: REMOVE_TARGET,
2521
+ payload: {
2522
+ targetId
2523
+ }
2524
+ };
2525
+ }
2526
+
2527
+ function validateSourceContract(source) {
2528
+ invariant(typeof source.canDrag === 'function', 'Expected canDrag to be a function.');
2529
+ invariant(typeof source.beginDrag === 'function', 'Expected beginDrag to be a function.');
2530
+ invariant(typeof source.endDrag === 'function', 'Expected endDrag to be a function.');
2531
+ }
2532
+ function validateTargetContract(target) {
2533
+ invariant(typeof target.canDrop === 'function', 'Expected canDrop to be a function.');
2534
+ invariant(typeof target.hover === 'function', 'Expected hover to be a function.');
2535
+ invariant(typeof target.drop === 'function', 'Expected beginDrag to be a function.');
2536
+ }
2537
+ function validateType(type, allowArray) {
2538
+ if (allowArray && Array.isArray(type)) {
2539
+ type.forEach((t)=>validateType(t, false)
2540
+ );
2541
+ return;
2542
+ }
2543
+ invariant(typeof type === 'string' || typeof type === 'symbol', allowArray ? 'Type can only be a string, a symbol, or an array of either.' : 'Type can only be a string or a symbol.');
2544
+ }
2545
+
2546
+ var HandlerRole;
2547
+ (function(HandlerRole) {
2548
+ HandlerRole["SOURCE"] = "SOURCE";
2549
+ HandlerRole["TARGET"] = "TARGET";
2550
+ })(HandlerRole || (HandlerRole = {}));
2551
+
2552
+ let nextUniqueId = 0;
2553
+ function getNextUniqueId() {
2554
+ return nextUniqueId++;
2555
+ }
2556
+
2557
+ function getNextHandlerId(role) {
2558
+ const id = getNextUniqueId().toString();
2559
+ switch(role){
2560
+ case HandlerRole.SOURCE:
2561
+ return `S${id}`;
2562
+ case HandlerRole.TARGET:
2563
+ return `T${id}`;
2564
+ default:
2565
+ throw new Error(`Unknown Handler Role: ${role}`);
2566
+ }
2567
+ }
2568
+ function parseRoleFromHandlerId(handlerId) {
2569
+ switch(handlerId[0]){
2570
+ case 'S':
2571
+ return HandlerRole.SOURCE;
2572
+ case 'T':
2573
+ return HandlerRole.TARGET;
2574
+ default:
2575
+ throw new Error(`Cannot parse handler ID: ${handlerId}`);
2576
+ }
2577
+ }
2578
+ function mapContainsValue(map, searchValue) {
2579
+ const entries = map.entries();
2580
+ let isDone = false;
2581
+ do {
2582
+ const { done , value: [, value] , } = entries.next();
2583
+ if (value === searchValue) {
2584
+ return true;
2585
+ }
2586
+ isDone = !!done;
2587
+ }while (!isDone)
2588
+ return false;
2589
+ }
2590
+ class HandlerRegistryImpl {
2591
+ addSource(type, source) {
2592
+ validateType(type);
2593
+ validateSourceContract(source);
2594
+ const sourceId = this.addHandler(HandlerRole.SOURCE, type, source);
2595
+ this.store.dispatch(addSource(sourceId));
2596
+ return sourceId;
2597
+ }
2598
+ addTarget(type, target) {
2599
+ validateType(type, true);
2600
+ validateTargetContract(target);
2601
+ const targetId = this.addHandler(HandlerRole.TARGET, type, target);
2602
+ this.store.dispatch(addTarget(targetId));
2603
+ return targetId;
2604
+ }
2605
+ containsHandler(handler) {
2606
+ return mapContainsValue(this.dragSources, handler) || mapContainsValue(this.dropTargets, handler);
2607
+ }
2608
+ getSource(sourceId, includePinned = false) {
2609
+ invariant(this.isSourceId(sourceId), 'Expected a valid source ID.');
2610
+ const isPinned = includePinned && sourceId === this.pinnedSourceId;
2611
+ const source = isPinned ? this.pinnedSource : this.dragSources.get(sourceId);
2612
+ return source;
2613
+ }
2614
+ getTarget(targetId) {
2615
+ invariant(this.isTargetId(targetId), 'Expected a valid target ID.');
2616
+ return this.dropTargets.get(targetId);
2617
+ }
2618
+ getSourceType(sourceId) {
2619
+ invariant(this.isSourceId(sourceId), 'Expected a valid source ID.');
2620
+ return this.types.get(sourceId);
2621
+ }
2622
+ getTargetType(targetId) {
2623
+ invariant(this.isTargetId(targetId), 'Expected a valid target ID.');
2624
+ return this.types.get(targetId);
2625
+ }
2626
+ isSourceId(handlerId) {
2627
+ const role = parseRoleFromHandlerId(handlerId);
2628
+ return role === HandlerRole.SOURCE;
2629
+ }
2630
+ isTargetId(handlerId) {
2631
+ const role = parseRoleFromHandlerId(handlerId);
2632
+ return role === HandlerRole.TARGET;
2633
+ }
2634
+ removeSource(sourceId) {
2635
+ invariant(this.getSource(sourceId), 'Expected an existing source.');
2636
+ this.store.dispatch(removeSource(sourceId));
2637
+ asap(()=>{
2638
+ this.dragSources.delete(sourceId);
2639
+ this.types.delete(sourceId);
2640
+ });
2641
+ }
2642
+ removeTarget(targetId) {
2643
+ invariant(this.getTarget(targetId), 'Expected an existing target.');
2644
+ this.store.dispatch(removeTarget(targetId));
2645
+ this.dropTargets.delete(targetId);
2646
+ this.types.delete(targetId);
2647
+ }
2648
+ pinSource(sourceId) {
2649
+ const source = this.getSource(sourceId);
2650
+ invariant(source, 'Expected an existing source.');
2651
+ this.pinnedSourceId = sourceId;
2652
+ this.pinnedSource = source;
2653
+ }
2654
+ unpinSource() {
2655
+ invariant(this.pinnedSource, 'No source is pinned at the time.');
2656
+ this.pinnedSourceId = null;
2657
+ this.pinnedSource = null;
2658
+ }
2659
+ addHandler(role, type, handler) {
2660
+ const id = getNextHandlerId(role);
2661
+ this.types.set(id, type);
2662
+ if (role === HandlerRole.SOURCE) {
2663
+ this.dragSources.set(id, handler);
2664
+ } else if (role === HandlerRole.TARGET) {
2665
+ this.dropTargets.set(id, handler);
2666
+ }
2667
+ return id;
2668
+ }
2669
+ constructor(store){
2670
+ this.types = new Map();
2671
+ this.dragSources = new Map();
2672
+ this.dropTargets = new Map();
2673
+ this.pinnedSourceId = null;
2674
+ this.pinnedSource = null;
2675
+ this.store = store;
2676
+ }
2677
+ }
2678
+
2679
+ const strictEquality = (a, b)=>a === b
2680
+ ;
2681
+ /**
2682
+ * Determine if two cartesian coordinate offsets are equal
2683
+ * @param offsetA
2684
+ * @param offsetB
2685
+ */ function areCoordsEqual(offsetA, offsetB) {
2686
+ if (!offsetA && !offsetB) {
2687
+ return true;
2688
+ } else if (!offsetA || !offsetB) {
2689
+ return false;
2690
+ } else {
2691
+ return offsetA.x === offsetB.x && offsetA.y === offsetB.y;
2692
+ }
2693
+ }
2694
+ /**
2695
+ * Determines if two arrays of items are equal
2696
+ * @param a The first array of items
2697
+ * @param b The second array of items
2698
+ */ function areArraysEqual(a, b, isEqual = strictEquality) {
2699
+ if (a.length !== b.length) {
2700
+ return false;
2701
+ }
2702
+ for(let i = 0; i < a.length; ++i){
2703
+ if (!isEqual(a[i], b[i])) {
2704
+ return false;
2705
+ }
2706
+ }
2707
+ return true;
2708
+ }
2709
+
2710
+ function reduce(// eslint-disable-next-line @typescript-eslint/no-unused-vars
2711
+ _state = NONE, action) {
2712
+ switch(action.type){
2713
+ case HOVER:
2714
+ break;
2715
+ case ADD_SOURCE:
2716
+ case ADD_TARGET:
2717
+ case REMOVE_TARGET:
2718
+ case REMOVE_SOURCE:
2719
+ return NONE;
2720
+ case BEGIN_DRAG:
2721
+ case PUBLISH_DRAG_SOURCE:
2722
+ case END_DRAG:
2723
+ case DROP:
2724
+ default:
2725
+ return ALL;
2726
+ }
2727
+ const { targetIds =[] , prevTargetIds =[] } = action.payload;
2728
+ const result = xor(targetIds, prevTargetIds);
2729
+ const didChange = result.length > 0 || !areArraysEqual(targetIds, prevTargetIds);
2730
+ if (!didChange) {
2731
+ return NONE;
2732
+ }
2733
+ // Check the target ids at the innermost position. If they are valid, add them
2734
+ // to the result
2735
+ const prevInnermostTargetId = prevTargetIds[prevTargetIds.length - 1];
2736
+ const innermostTargetId = targetIds[targetIds.length - 1];
2737
+ if (prevInnermostTargetId !== innermostTargetId) {
2738
+ if (prevInnermostTargetId) {
2739
+ result.push(prevInnermostTargetId);
2740
+ }
2741
+ if (innermostTargetId) {
2742
+ result.push(innermostTargetId);
2743
+ }
2744
+ }
2745
+ return result;
2746
+ }
2747
+
2748
+ function _defineProperty$1(obj, key, value) {
2749
+ if (key in obj) {
2750
+ Object.defineProperty(obj, key, {
2751
+ value: value,
2752
+ enumerable: true,
2753
+ configurable: true,
2754
+ writable: true
2755
+ });
2756
+ } else {
2757
+ obj[key] = value;
2758
+ }
2759
+ return obj;
2760
+ }
2761
+ function _objectSpread$1(target) {
2762
+ for(var i = 1; i < arguments.length; i++){
2763
+ var source = arguments[i] != null ? arguments[i] : {};
2764
+ var ownKeys = Object.keys(source);
2765
+ if (typeof Object.getOwnPropertySymbols === 'function') {
2766
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
2767
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
2768
+ }));
2769
+ }
2770
+ ownKeys.forEach(function(key) {
2771
+ _defineProperty$1(target, key, source[key]);
2772
+ });
2773
+ }
2774
+ return target;
2775
+ }
2776
+ const initialState = {
2777
+ initialSourceClientOffset: null,
2778
+ initialClientOffset: null,
2779
+ clientOffset: null
2780
+ };
2781
+ function reduce$1(state = initialState, action) {
2782
+ const { payload } = action;
2783
+ switch(action.type){
2784
+ case INIT_COORDS:
2785
+ case BEGIN_DRAG:
2786
+ return {
2787
+ initialSourceClientOffset: payload.sourceClientOffset,
2788
+ initialClientOffset: payload.clientOffset,
2789
+ clientOffset: payload.clientOffset
2790
+ };
2791
+ case HOVER:
2792
+ if (areCoordsEqual(state.clientOffset, payload.clientOffset)) {
2793
+ return state;
2794
+ }
2795
+ return _objectSpread$1({}, state, {
2796
+ clientOffset: payload.clientOffset
2797
+ });
2798
+ case END_DRAG:
2799
+ case DROP:
2800
+ return initialState;
2801
+ default:
2802
+ return state;
2803
+ }
2804
+ }
2805
+
2806
+ function _defineProperty$2(obj, key, value) {
2807
+ if (key in obj) {
2808
+ Object.defineProperty(obj, key, {
2809
+ value: value,
2810
+ enumerable: true,
2811
+ configurable: true,
2812
+ writable: true
2813
+ });
2814
+ } else {
2815
+ obj[key] = value;
2816
+ }
2817
+ return obj;
2818
+ }
2819
+ function _objectSpread$2(target) {
2820
+ for(var i = 1; i < arguments.length; i++){
2821
+ var source = arguments[i] != null ? arguments[i] : {};
2822
+ var ownKeys = Object.keys(source);
2823
+ if (typeof Object.getOwnPropertySymbols === 'function') {
2824
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
2825
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
2826
+ }));
2827
+ }
2828
+ ownKeys.forEach(function(key) {
2829
+ _defineProperty$2(target, key, source[key]);
2830
+ });
2831
+ }
2832
+ return target;
2833
+ }
2834
+ const initialState$1 = {
2835
+ itemType: null,
2836
+ item: null,
2837
+ sourceId: null,
2838
+ targetIds: [],
2839
+ dropResult: null,
2840
+ didDrop: false,
2841
+ isSourcePublic: null
2842
+ };
2843
+ function reduce$2(state = initialState$1, action) {
2844
+ const { payload } = action;
2845
+ switch(action.type){
2846
+ case BEGIN_DRAG:
2847
+ return _objectSpread$2({}, state, {
2848
+ itemType: payload.itemType,
2849
+ item: payload.item,
2850
+ sourceId: payload.sourceId,
2851
+ isSourcePublic: payload.isSourcePublic,
2852
+ dropResult: null,
2853
+ didDrop: false
2854
+ });
2855
+ case PUBLISH_DRAG_SOURCE:
2856
+ return _objectSpread$2({}, state, {
2857
+ isSourcePublic: true
2858
+ });
2859
+ case HOVER:
2860
+ return _objectSpread$2({}, state, {
2861
+ targetIds: payload.targetIds
2862
+ });
2863
+ case REMOVE_TARGET:
2864
+ if (state.targetIds.indexOf(payload.targetId) === -1) {
2865
+ return state;
2866
+ }
2867
+ return _objectSpread$2({}, state, {
2868
+ targetIds: without(state.targetIds, payload.targetId)
2869
+ });
2870
+ case DROP:
2871
+ return _objectSpread$2({}, state, {
2872
+ dropResult: payload.dropResult,
2873
+ didDrop: true,
2874
+ targetIds: []
2875
+ });
2876
+ case END_DRAG:
2877
+ return _objectSpread$2({}, state, {
2878
+ itemType: null,
2879
+ item: null,
2880
+ sourceId: null,
2881
+ dropResult: null,
2882
+ didDrop: false,
2883
+ isSourcePublic: null,
2884
+ targetIds: []
2885
+ });
2886
+ default:
2887
+ return state;
2888
+ }
2889
+ }
2890
+
2891
+ function reduce$3(state = 0, action) {
2892
+ switch(action.type){
2893
+ case ADD_SOURCE:
2894
+ case ADD_TARGET:
2895
+ return state + 1;
2896
+ case REMOVE_SOURCE:
2897
+ case REMOVE_TARGET:
2898
+ return state - 1;
2899
+ default:
2900
+ return state;
2901
+ }
2902
+ }
2903
+
2904
+ function reduce$4(state = 0) {
2905
+ return state + 1;
2906
+ }
2907
+
2908
+ function _defineProperty$3(obj, key, value) {
2909
+ if (key in obj) {
2910
+ Object.defineProperty(obj, key, {
2911
+ value: value,
2912
+ enumerable: true,
2913
+ configurable: true,
2914
+ writable: true
2915
+ });
2916
+ } else {
2917
+ obj[key] = value;
2918
+ }
2919
+ return obj;
2920
+ }
2921
+ function _objectSpread$3(target) {
2922
+ for(var i = 1; i < arguments.length; i++){
2923
+ var source = arguments[i] != null ? arguments[i] : {};
2924
+ var ownKeys = Object.keys(source);
2925
+ if (typeof Object.getOwnPropertySymbols === 'function') {
2926
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
2927
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
2928
+ }));
2929
+ }
2930
+ ownKeys.forEach(function(key) {
2931
+ _defineProperty$3(target, key, source[key]);
2932
+ });
2933
+ }
2934
+ return target;
2935
+ }
2936
+ function reduce$5(state = {}, action) {
2937
+ return {
2938
+ dirtyHandlerIds: reduce(state.dirtyHandlerIds, {
2939
+ type: action.type,
2940
+ payload: _objectSpread$3({}, action.payload, {
2941
+ prevTargetIds: get(state, 'dragOperation.targetIds', [])
2942
+ })
2943
+ }),
2944
+ dragOffset: reduce$1(state.dragOffset, action),
2945
+ refCount: reduce$3(state.refCount, action),
2946
+ dragOperation: reduce$2(state.dragOperation, action),
2947
+ stateId: reduce$4(state.stateId)
2948
+ };
2949
+ }
2950
+
2951
+ function createDragDropManager(backendFactory, globalContext = undefined, backendOptions = {}, debugMode = false) {
2952
+ const store = makeStoreInstance(debugMode);
2953
+ const monitor = new DragDropMonitorImpl(store, new HandlerRegistryImpl(store));
2954
+ const manager = new DragDropManagerImpl(store, monitor);
2955
+ const backend = backendFactory(manager, globalContext, backendOptions);
2956
+ manager.receiveBackend(backend);
2957
+ return manager;
2958
+ }
2959
+ function makeStoreInstance(debugMode) {
2960
+ // TODO: if we ever make a react-native version of this,
2961
+ // we'll need to consider how to pull off dev-tooling
2962
+ const reduxDevTools = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__;
2963
+ return createStore(reduce$5, debugMode && reduxDevTools && reduxDevTools({
2964
+ name: 'dnd-core',
2965
+ instanceId: 'dnd-core'
2966
+ }));
2967
+ }
2968
+
2969
+ function _objectWithoutProperties(source, excluded) {
2970
+ if (source == null) return {};
2971
+ var target = _objectWithoutPropertiesLoose$1(source, excluded);
2972
+ var key, i;
2973
+ if (Object.getOwnPropertySymbols) {
2974
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
2975
+ for(i = 0; i < sourceSymbolKeys.length; i++){
2976
+ key = sourceSymbolKeys[i];
2977
+ if (excluded.indexOf(key) >= 0) continue;
2978
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
2979
+ target[key] = source[key];
2980
+ }
2981
+ }
2982
+ return target;
2983
+ }
2984
+ function _objectWithoutPropertiesLoose$1(source, excluded) {
2985
+ if (source == null) return {};
2986
+ var target = {};
2987
+ var sourceKeys = Object.keys(source);
2988
+ var key, i;
2989
+ for(i = 0; i < sourceKeys.length; i++){
2990
+ key = sourceKeys[i];
2991
+ if (excluded.indexOf(key) >= 0) continue;
2992
+ target[key] = source[key];
2993
+ }
2994
+ return target;
2995
+ }
2996
+ let refCount = 0;
2997
+ const INSTANCE_SYM = Symbol.for('__REACT_DND_CONTEXT_INSTANCE__');
2998
+ var DndProvider = /*#__PURE__*/ React.memo(function DndProvider(_param) {
2999
+ var { children } = _param, props = _objectWithoutProperties(_param, [
3000
+ "children"
3001
+ ]);
3002
+ const [manager, isGlobalInstance] = getDndContextValue(props) // memoized from props
3003
+ ;
3004
+ /**
3005
+ * If the global context was used to store the DND context
3006
+ * then where theres no more references to it we should
3007
+ * clean it up to avoid memory leaks
3008
+ */ React.useEffect(()=>{
3009
+ if (isGlobalInstance) {
3010
+ const context = getGlobalContext();
3011
+ ++refCount;
3012
+ return ()=>{
3013
+ if (--refCount === 0) {
3014
+ context[INSTANCE_SYM] = null;
3015
+ }
3016
+ };
3017
+ }
3018
+ return;
3019
+ }, []);
3020
+ return /*#__PURE__*/ jsxRuntime.jsx(DndContext.Provider, {
3021
+ value: manager,
3022
+ children: children
3023
+ });
3024
+ });
3025
+ function getDndContextValue(props) {
3026
+ if ('manager' in props) {
3027
+ const manager = {
3028
+ dragDropManager: props.manager
3029
+ };
3030
+ return [
3031
+ manager,
3032
+ false
3033
+ ];
3034
+ }
3035
+ const manager = createSingletonDndContext(props.backend, props.context, props.options, props.debugMode);
3036
+ const isGlobalInstance = !props.context;
3037
+ return [
3038
+ manager,
3039
+ isGlobalInstance
3040
+ ];
3041
+ }
3042
+ function createSingletonDndContext(backend, context = getGlobalContext(), options, debugMode) {
3043
+ const ctx = context;
3044
+ if (!ctx[INSTANCE_SYM]) {
3045
+ ctx[INSTANCE_SYM] = {
3046
+ dragDropManager: createDragDropManager(backend, context, options, debugMode)
3047
+ };
3048
+ }
3049
+ return ctx[INSTANCE_SYM];
3050
+ }
3051
+ function getGlobalContext() {
3052
+ return typeof global !== 'undefined' ? global : window;
3053
+ }
3054
+
3055
+ // do not edit .js files directly - edit src/index.jst
3056
+
3057
+
3058
+
3059
+ var fastDeepEqual = function equal(a, b) {
3060
+ if (a === b) return true;
3061
+
3062
+ if (a && b && typeof a == 'object' && typeof b == 'object') {
3063
+ if (a.constructor !== b.constructor) return false;
3064
+
3065
+ var length, i, keys;
3066
+ if (Array.isArray(a)) {
3067
+ length = a.length;
3068
+ if (length != b.length) return false;
3069
+ for (i = length; i-- !== 0;)
3070
+ if (!equal(a[i], b[i])) return false;
3071
+ return true;
3072
+ }
3073
+
3074
+
3075
+
3076
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
3077
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
3078
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
3079
+
3080
+ keys = Object.keys(a);
3081
+ length = keys.length;
3082
+ if (length !== Object.keys(b).length) return false;
3083
+
3084
+ for (i = length; i-- !== 0;)
3085
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
3086
+
3087
+ for (i = length; i-- !== 0;) {
3088
+ var key = keys[i];
3089
+
3090
+ if (!equal(a[key], b[key])) return false;
3091
+ }
3092
+
3093
+ return true;
3094
+ }
3095
+
3096
+ // true if both NaN, false otherwise
3097
+ return a!==a && b!==b;
3098
+ };
3099
+
3100
+ // suppress the useLayoutEffect warning on server side.
3101
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
3102
+
3103
+ /**
3104
+ *
3105
+ * @param monitor The monitor to collect state from
3106
+ * @param collect The collecting function
3107
+ * @param onUpdate A method to invoke when updates occur
3108
+ */ function useCollector(monitor, collect, onUpdate) {
3109
+ const [collected, setCollected] = React.useState(()=>collect(monitor)
3110
+ );
3111
+ const updateCollected = React.useCallback(()=>{
3112
+ const nextValue = collect(monitor);
3113
+ // This needs to be a deep-equality check because some monitor-collected values
3114
+ // include XYCoord objects that may be equivalent, but do not have instance equality.
3115
+ if (!fastDeepEqual(collected, nextValue)) {
3116
+ setCollected(nextValue);
3117
+ if (onUpdate) {
3118
+ onUpdate();
3119
+ }
3120
+ }
3121
+ }, [
3122
+ collected,
3123
+ monitor,
3124
+ onUpdate
3125
+ ]);
3126
+ // update the collected properties after react renders.
3127
+ // Note that the "Dustbin Stress Test" fails if this is not
3128
+ // done when the component updates
3129
+ useIsomorphicLayoutEffect(updateCollected);
3130
+ return [
3131
+ collected,
3132
+ updateCollected
3133
+ ];
3134
+ }
3135
+
3136
+ function useMonitorOutput(monitor, collect, onCollect) {
3137
+ const [collected, updateCollected] = useCollector(monitor, collect, onCollect);
3138
+ useIsomorphicLayoutEffect(function subscribeToMonitorStateChange() {
3139
+ const handlerId = monitor.getHandlerId();
3140
+ if (handlerId == null) {
3141
+ return;
3142
+ }
3143
+ return monitor.subscribeToStateChange(updateCollected, {
3144
+ handlerIds: [
3145
+ handlerId
3146
+ ]
3147
+ });
3148
+ }, [
3149
+ monitor,
3150
+ updateCollected
3151
+ ]);
3152
+ return collected;
3153
+ }
3154
+
3155
+ function useCollectedProps(collector, monitor, connector) {
3156
+ return useMonitorOutput(monitor, collector || (()=>({})
3157
+ ), ()=>connector.reconnect()
3158
+ );
3159
+ }
3160
+
3161
+ function useOptionalFactory(arg, deps) {
3162
+ const memoDeps = [
3163
+ ...deps || []
3164
+ ];
3165
+ if (deps == null && typeof arg !== 'function') {
3166
+ memoDeps.push(arg);
3167
+ }
3168
+ return React.useMemo(()=>{
3169
+ return typeof arg === 'function' ? arg() : arg;
3170
+ }, memoDeps);
3171
+ }
3172
+
3173
+ function useConnectDragSource(connector) {
3174
+ return React.useMemo(()=>connector.hooks.dragSource()
3175
+ , [
3176
+ connector
3177
+ ]);
3178
+ }
3179
+ function useConnectDragPreview(connector) {
3180
+ return React.useMemo(()=>connector.hooks.dragPreview()
3181
+ , [
3182
+ connector
3183
+ ]);
3184
+ }
3185
+
3186
+ let isCallingCanDrag = false;
3187
+ let isCallingIsDragging = false;
3188
+ class DragSourceMonitorImpl {
3189
+ receiveHandlerId(sourceId) {
3190
+ this.sourceId = sourceId;
3191
+ }
3192
+ getHandlerId() {
3193
+ return this.sourceId;
3194
+ }
3195
+ canDrag() {
3196
+ invariant(!isCallingCanDrag, 'You may not call monitor.canDrag() inside your canDrag() implementation. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor');
3197
+ try {
3198
+ isCallingCanDrag = true;
3199
+ return this.internalMonitor.canDragSource(this.sourceId);
3200
+ } finally{
3201
+ isCallingCanDrag = false;
3202
+ }
3203
+ }
3204
+ isDragging() {
3205
+ if (!this.sourceId) {
3206
+ return false;
3207
+ }
3208
+ invariant(!isCallingIsDragging, 'You may not call monitor.isDragging() inside your isDragging() implementation. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor');
3209
+ try {
3210
+ isCallingIsDragging = true;
3211
+ return this.internalMonitor.isDraggingSource(this.sourceId);
3212
+ } finally{
3213
+ isCallingIsDragging = false;
3214
+ }
3215
+ }
3216
+ subscribeToStateChange(listener, options) {
3217
+ return this.internalMonitor.subscribeToStateChange(listener, options);
3218
+ }
3219
+ isDraggingSource(sourceId) {
3220
+ return this.internalMonitor.isDraggingSource(sourceId);
3221
+ }
3222
+ isOverTarget(targetId, options) {
3223
+ return this.internalMonitor.isOverTarget(targetId, options);
3224
+ }
3225
+ getTargetIds() {
3226
+ return this.internalMonitor.getTargetIds();
3227
+ }
3228
+ isSourcePublic() {
3229
+ return this.internalMonitor.isSourcePublic();
3230
+ }
3231
+ getSourceId() {
3232
+ return this.internalMonitor.getSourceId();
3233
+ }
3234
+ subscribeToOffsetChange(listener) {
3235
+ return this.internalMonitor.subscribeToOffsetChange(listener);
3236
+ }
3237
+ canDragSource(sourceId) {
3238
+ return this.internalMonitor.canDragSource(sourceId);
3239
+ }
3240
+ canDropOnTarget(targetId) {
3241
+ return this.internalMonitor.canDropOnTarget(targetId);
3242
+ }
3243
+ getItemType() {
3244
+ return this.internalMonitor.getItemType();
3245
+ }
3246
+ getItem() {
3247
+ return this.internalMonitor.getItem();
3248
+ }
3249
+ getDropResult() {
3250
+ return this.internalMonitor.getDropResult();
3251
+ }
3252
+ didDrop() {
3253
+ return this.internalMonitor.didDrop();
3254
+ }
3255
+ getInitialClientOffset() {
3256
+ return this.internalMonitor.getInitialClientOffset();
3257
+ }
3258
+ getInitialSourceClientOffset() {
3259
+ return this.internalMonitor.getInitialSourceClientOffset();
3260
+ }
3261
+ getSourceClientOffset() {
3262
+ return this.internalMonitor.getSourceClientOffset();
3263
+ }
3264
+ getClientOffset() {
3265
+ return this.internalMonitor.getClientOffset();
3266
+ }
3267
+ getDifferenceFromInitialOffset() {
3268
+ return this.internalMonitor.getDifferenceFromInitialOffset();
3269
+ }
3270
+ constructor(manager){
3271
+ this.sourceId = null;
3272
+ this.internalMonitor = manager.getMonitor();
3273
+ }
3274
+ }
3275
+
3276
+ let isCallingCanDrop = false;
3277
+ class DropTargetMonitorImpl {
3278
+ receiveHandlerId(targetId) {
3279
+ this.targetId = targetId;
3280
+ }
3281
+ getHandlerId() {
3282
+ return this.targetId;
3283
+ }
3284
+ subscribeToStateChange(listener, options) {
3285
+ return this.internalMonitor.subscribeToStateChange(listener, options);
3286
+ }
3287
+ canDrop() {
3288
+ // Cut out early if the target id has not been set. This should prevent errors
3289
+ // where the user has an older version of dnd-core like in
3290
+ // https://github.com/react-dnd/react-dnd/issues/1310
3291
+ if (!this.targetId) {
3292
+ return false;
3293
+ }
3294
+ invariant(!isCallingCanDrop, 'You may not call monitor.canDrop() inside your canDrop() implementation. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs/api/drop-target-monitor');
3295
+ try {
3296
+ isCallingCanDrop = true;
3297
+ return this.internalMonitor.canDropOnTarget(this.targetId);
3298
+ } finally{
3299
+ isCallingCanDrop = false;
3300
+ }
3301
+ }
3302
+ isOver(options) {
3303
+ if (!this.targetId) {
3304
+ return false;
3305
+ }
3306
+ return this.internalMonitor.isOverTarget(this.targetId, options);
3307
+ }
3308
+ getItemType() {
3309
+ return this.internalMonitor.getItemType();
3310
+ }
3311
+ getItem() {
3312
+ return this.internalMonitor.getItem();
3313
+ }
3314
+ getDropResult() {
3315
+ return this.internalMonitor.getDropResult();
3316
+ }
3317
+ didDrop() {
3318
+ return this.internalMonitor.didDrop();
3319
+ }
3320
+ getInitialClientOffset() {
3321
+ return this.internalMonitor.getInitialClientOffset();
3322
+ }
3323
+ getInitialSourceClientOffset() {
3324
+ return this.internalMonitor.getInitialSourceClientOffset();
3325
+ }
3326
+ getSourceClientOffset() {
3327
+ return this.internalMonitor.getSourceClientOffset();
3328
+ }
3329
+ getClientOffset() {
3330
+ return this.internalMonitor.getClientOffset();
3331
+ }
3332
+ getDifferenceFromInitialOffset() {
3333
+ return this.internalMonitor.getDifferenceFromInitialOffset();
3334
+ }
3335
+ constructor(manager){
3336
+ this.targetId = null;
3337
+ this.internalMonitor = manager.getMonitor();
3338
+ }
3339
+ }
3340
+
3341
+ function registerTarget(type, target, manager) {
3342
+ const registry = manager.getRegistry();
3343
+ const targetId = registry.addTarget(type, target);
3344
+ return [
3345
+ targetId,
3346
+ ()=>registry.removeTarget(targetId)
3347
+ ];
3348
+ }
3349
+ function registerSource(type, source, manager) {
3350
+ const registry = manager.getRegistry();
3351
+ const sourceId = registry.addSource(type, source);
3352
+ return [
3353
+ sourceId,
3354
+ ()=>registry.removeSource(sourceId)
3355
+ ];
3356
+ }
3357
+
3358
+ function shallowEqual(objA, objB, compare, compareContext) {
3359
+ let compareResult = compare ? compare.call(compareContext, objA, objB) : void 0;
3360
+ if (compareResult !== void 0) {
3361
+ return !!compareResult;
3362
+ }
3363
+ if (objA === objB) {
3364
+ return true;
3365
+ }
3366
+ if (typeof objA !== 'object' || !objA || typeof objB !== 'object' || !objB) {
3367
+ return false;
3368
+ }
3369
+ const keysA = Object.keys(objA);
3370
+ const keysB = Object.keys(objB);
3371
+ if (keysA.length !== keysB.length) {
3372
+ return false;
3373
+ }
3374
+ const bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
3375
+ // Test for A's keys different from B.
3376
+ for(let idx = 0; idx < keysA.length; idx++){
3377
+ const key = keysA[idx];
3378
+ if (!bHasOwnProperty(key)) {
3379
+ return false;
3380
+ }
3381
+ const valueA = objA[key];
3382
+ const valueB = objB[key];
3383
+ compareResult = compare ? compare.call(compareContext, valueA, valueB, key) : void 0;
3384
+ if (compareResult === false || compareResult === void 0 && valueA !== valueB) {
3385
+ return false;
3386
+ }
3387
+ }
3388
+ return true;
3389
+ }
3390
+
3391
+ function isRef(obj) {
3392
+ return(// eslint-disable-next-line no-prototype-builtins
3393
+ obj !== null && typeof obj === 'object' && Object.prototype.hasOwnProperty.call(obj, 'current'));
3394
+ }
3395
+
3396
+ function throwIfCompositeComponentElement(element) {
3397
+ // Custom components can no longer be wrapped directly in React DnD 2.0
3398
+ // so that we don't need to depend on findDOMNode() from react-dom.
3399
+ if (typeof element.type === 'string') {
3400
+ return;
3401
+ }
3402
+ const displayName = element.type.displayName || element.type.name || 'the component';
3403
+ throw new Error('Only native element nodes can now be passed to React DnD connectors.' + `You can either wrap ${displayName} into a <div>, or turn it into a ` + 'drag source or a drop target itself.');
3404
+ }
3405
+ function wrapHookToRecognizeElement(hook) {
3406
+ return (elementOrNode = null, options = null)=>{
3407
+ // When passed a node, call the hook straight away.
3408
+ if (!React.isValidElement(elementOrNode)) {
3409
+ const node = elementOrNode;
3410
+ hook(node, options);
3411
+ // return the node so it can be chained (e.g. when within callback refs
3412
+ // <div ref={node => connectDragSource(connectDropTarget(node))}/>
3413
+ return node;
3414
+ }
3415
+ // If passed a ReactElement, clone it and attach this function as a ref.
3416
+ // This helps us achieve a neat API where user doesn't even know that refs
3417
+ // are being used under the hood.
3418
+ const element = elementOrNode;
3419
+ throwIfCompositeComponentElement(element);
3420
+ // When no options are passed, use the hook directly
3421
+ const ref = options ? (node)=>hook(node, options)
3422
+ : hook;
3423
+ return cloneWithRef(element, ref);
3424
+ };
3425
+ }
3426
+ function wrapConnectorHooks(hooks) {
3427
+ const wrappedHooks = {};
3428
+ Object.keys(hooks).forEach((key)=>{
3429
+ const hook = hooks[key];
3430
+ // ref objects should be passed straight through without wrapping
3431
+ if (key.endsWith('Ref')) {
3432
+ wrappedHooks[key] = hooks[key];
3433
+ } else {
3434
+ const wrappedHook = wrapHookToRecognizeElement(hook);
3435
+ wrappedHooks[key] = ()=>wrappedHook
3436
+ ;
3437
+ }
3438
+ });
3439
+ return wrappedHooks;
3440
+ }
3441
+ function setRef(ref, node) {
3442
+ if (typeof ref === 'function') {
3443
+ ref(node);
3444
+ } else {
3445
+ ref.current = node;
3446
+ }
3447
+ }
3448
+ function cloneWithRef(element, newRef) {
3449
+ const previousRef = element.ref;
3450
+ invariant(typeof previousRef !== 'string', 'Cannot connect React DnD to an element with an existing string ref. ' + 'Please convert it to use a callback ref instead, or wrap it into a <span> or <div>. ' + 'Read more: https://reactjs.org/docs/refs-and-the-dom.html#callback-refs');
3451
+ if (!previousRef) {
3452
+ // When there is no ref on the element, use the new ref directly
3453
+ return React.cloneElement(element, {
3454
+ ref: newRef
3455
+ });
3456
+ } else {
3457
+ return React.cloneElement(element, {
3458
+ ref: (node)=>{
3459
+ setRef(previousRef, node);
3460
+ setRef(newRef, node);
3461
+ }
3462
+ });
3463
+ }
3464
+ }
3465
+
3466
+ class SourceConnector {
3467
+ receiveHandlerId(newHandlerId) {
3468
+ if (this.handlerId === newHandlerId) {
3469
+ return;
3470
+ }
3471
+ this.handlerId = newHandlerId;
3472
+ this.reconnect();
3473
+ }
3474
+ get connectTarget() {
3475
+ return this.dragSource;
3476
+ }
3477
+ get dragSourceOptions() {
3478
+ return this.dragSourceOptionsInternal;
3479
+ }
3480
+ set dragSourceOptions(options) {
3481
+ this.dragSourceOptionsInternal = options;
3482
+ }
3483
+ get dragPreviewOptions() {
3484
+ return this.dragPreviewOptionsInternal;
3485
+ }
3486
+ set dragPreviewOptions(options) {
3487
+ this.dragPreviewOptionsInternal = options;
3488
+ }
3489
+ reconnect() {
3490
+ const didChange = this.reconnectDragSource();
3491
+ this.reconnectDragPreview(didChange);
3492
+ }
3493
+ reconnectDragSource() {
3494
+ const dragSource = this.dragSource;
3495
+ // if nothing has changed then don't resubscribe
3496
+ const didChange = this.didHandlerIdChange() || this.didConnectedDragSourceChange() || this.didDragSourceOptionsChange();
3497
+ if (didChange) {
3498
+ this.disconnectDragSource();
3499
+ }
3500
+ if (!this.handlerId) {
3501
+ return didChange;
3502
+ }
3503
+ if (!dragSource) {
3504
+ this.lastConnectedDragSource = dragSource;
3505
+ return didChange;
3506
+ }
3507
+ if (didChange) {
3508
+ this.lastConnectedHandlerId = this.handlerId;
3509
+ this.lastConnectedDragSource = dragSource;
3510
+ this.lastConnectedDragSourceOptions = this.dragSourceOptions;
3511
+ this.dragSourceUnsubscribe = this.backend.connectDragSource(this.handlerId, dragSource, this.dragSourceOptions);
3512
+ }
3513
+ return didChange;
3514
+ }
3515
+ reconnectDragPreview(forceDidChange = false) {
3516
+ const dragPreview = this.dragPreview;
3517
+ // if nothing has changed then don't resubscribe
3518
+ const didChange = forceDidChange || this.didHandlerIdChange() || this.didConnectedDragPreviewChange() || this.didDragPreviewOptionsChange();
3519
+ if (didChange) {
3520
+ this.disconnectDragPreview();
3521
+ }
3522
+ if (!this.handlerId) {
3523
+ return;
3524
+ }
3525
+ if (!dragPreview) {
3526
+ this.lastConnectedDragPreview = dragPreview;
3527
+ return;
3528
+ }
3529
+ if (didChange) {
3530
+ this.lastConnectedHandlerId = this.handlerId;
3531
+ this.lastConnectedDragPreview = dragPreview;
3532
+ this.lastConnectedDragPreviewOptions = this.dragPreviewOptions;
3533
+ this.dragPreviewUnsubscribe = this.backend.connectDragPreview(this.handlerId, dragPreview, this.dragPreviewOptions);
3534
+ }
3535
+ }
3536
+ didHandlerIdChange() {
3537
+ return this.lastConnectedHandlerId !== this.handlerId;
3538
+ }
3539
+ didConnectedDragSourceChange() {
3540
+ return this.lastConnectedDragSource !== this.dragSource;
3541
+ }
3542
+ didConnectedDragPreviewChange() {
3543
+ return this.lastConnectedDragPreview !== this.dragPreview;
3544
+ }
3545
+ didDragSourceOptionsChange() {
3546
+ return !shallowEqual(this.lastConnectedDragSourceOptions, this.dragSourceOptions);
3547
+ }
3548
+ didDragPreviewOptionsChange() {
3549
+ return !shallowEqual(this.lastConnectedDragPreviewOptions, this.dragPreviewOptions);
3550
+ }
3551
+ disconnectDragSource() {
3552
+ if (this.dragSourceUnsubscribe) {
3553
+ this.dragSourceUnsubscribe();
3554
+ this.dragSourceUnsubscribe = undefined;
3555
+ }
3556
+ }
3557
+ disconnectDragPreview() {
3558
+ if (this.dragPreviewUnsubscribe) {
3559
+ this.dragPreviewUnsubscribe();
3560
+ this.dragPreviewUnsubscribe = undefined;
3561
+ this.dragPreviewNode = null;
3562
+ this.dragPreviewRef = null;
3563
+ }
3564
+ }
3565
+ get dragSource() {
3566
+ return this.dragSourceNode || this.dragSourceRef && this.dragSourceRef.current;
3567
+ }
3568
+ get dragPreview() {
3569
+ return this.dragPreviewNode || this.dragPreviewRef && this.dragPreviewRef.current;
3570
+ }
3571
+ clearDragSource() {
3572
+ this.dragSourceNode = null;
3573
+ this.dragSourceRef = null;
3574
+ }
3575
+ clearDragPreview() {
3576
+ this.dragPreviewNode = null;
3577
+ this.dragPreviewRef = null;
3578
+ }
3579
+ constructor(backend){
3580
+ this.hooks = wrapConnectorHooks({
3581
+ dragSource: (node, options)=>{
3582
+ this.clearDragSource();
3583
+ this.dragSourceOptions = options || null;
3584
+ if (isRef(node)) {
3585
+ this.dragSourceRef = node;
3586
+ } else {
3587
+ this.dragSourceNode = node;
3588
+ }
3589
+ this.reconnectDragSource();
3590
+ },
3591
+ dragPreview: (node, options)=>{
3592
+ this.clearDragPreview();
3593
+ this.dragPreviewOptions = options || null;
3594
+ if (isRef(node)) {
3595
+ this.dragPreviewRef = node;
3596
+ } else {
3597
+ this.dragPreviewNode = node;
3598
+ }
3599
+ this.reconnectDragPreview();
3600
+ }
3601
+ });
3602
+ this.handlerId = null;
3603
+ // The drop target may either be attached via ref or connect function
3604
+ this.dragSourceRef = null;
3605
+ this.dragSourceOptionsInternal = null;
3606
+ // The drag preview may either be attached via ref or connect function
3607
+ this.dragPreviewRef = null;
3608
+ this.dragPreviewOptionsInternal = null;
3609
+ this.lastConnectedHandlerId = null;
3610
+ this.lastConnectedDragSource = null;
3611
+ this.lastConnectedDragSourceOptions = null;
3612
+ this.lastConnectedDragPreview = null;
3613
+ this.lastConnectedDragPreviewOptions = null;
3614
+ this.backend = backend;
3615
+ }
3616
+ }
3617
+
3618
+ class TargetConnector {
3619
+ get connectTarget() {
3620
+ return this.dropTarget;
3621
+ }
3622
+ reconnect() {
3623
+ // if nothing has changed then don't resubscribe
3624
+ const didChange = this.didHandlerIdChange() || this.didDropTargetChange() || this.didOptionsChange();
3625
+ if (didChange) {
3626
+ this.disconnectDropTarget();
3627
+ }
3628
+ const dropTarget = this.dropTarget;
3629
+ if (!this.handlerId) {
3630
+ return;
3631
+ }
3632
+ if (!dropTarget) {
3633
+ this.lastConnectedDropTarget = dropTarget;
3634
+ return;
3635
+ }
3636
+ if (didChange) {
3637
+ this.lastConnectedHandlerId = this.handlerId;
3638
+ this.lastConnectedDropTarget = dropTarget;
3639
+ this.lastConnectedDropTargetOptions = this.dropTargetOptions;
3640
+ this.unsubscribeDropTarget = this.backend.connectDropTarget(this.handlerId, dropTarget, this.dropTargetOptions);
3641
+ }
3642
+ }
3643
+ receiveHandlerId(newHandlerId) {
3644
+ if (newHandlerId === this.handlerId) {
3645
+ return;
3646
+ }
3647
+ this.handlerId = newHandlerId;
3648
+ this.reconnect();
3649
+ }
3650
+ get dropTargetOptions() {
3651
+ return this.dropTargetOptionsInternal;
3652
+ }
3653
+ set dropTargetOptions(options) {
3654
+ this.dropTargetOptionsInternal = options;
3655
+ }
3656
+ didHandlerIdChange() {
3657
+ return this.lastConnectedHandlerId !== this.handlerId;
3658
+ }
3659
+ didDropTargetChange() {
3660
+ return this.lastConnectedDropTarget !== this.dropTarget;
3661
+ }
3662
+ didOptionsChange() {
3663
+ return !shallowEqual(this.lastConnectedDropTargetOptions, this.dropTargetOptions);
3664
+ }
3665
+ disconnectDropTarget() {
3666
+ if (this.unsubscribeDropTarget) {
3667
+ this.unsubscribeDropTarget();
3668
+ this.unsubscribeDropTarget = undefined;
3669
+ }
3670
+ }
3671
+ get dropTarget() {
3672
+ return this.dropTargetNode || this.dropTargetRef && this.dropTargetRef.current;
3673
+ }
3674
+ clearDropTarget() {
3675
+ this.dropTargetRef = null;
3676
+ this.dropTargetNode = null;
3677
+ }
3678
+ constructor(backend){
3679
+ this.hooks = wrapConnectorHooks({
3680
+ dropTarget: (node, options)=>{
3681
+ this.clearDropTarget();
3682
+ this.dropTargetOptions = options;
3683
+ if (isRef(node)) {
3684
+ this.dropTargetRef = node;
3685
+ } else {
3686
+ this.dropTargetNode = node;
3687
+ }
3688
+ this.reconnect();
3689
+ }
3690
+ });
3691
+ this.handlerId = null;
3692
+ // The drop target may either be attached via ref or connect function
3693
+ this.dropTargetRef = null;
3694
+ this.dropTargetOptionsInternal = null;
3695
+ this.lastConnectedHandlerId = null;
3696
+ this.lastConnectedDropTarget = null;
3697
+ this.lastConnectedDropTargetOptions = null;
3698
+ this.backend = backend;
3699
+ }
3700
+ }
3701
+
3702
+ /**
3703
+ * A hook to retrieve the DragDropManager from Context
3704
+ */ function useDragDropManager() {
3705
+ const { dragDropManager } = React.useContext(DndContext);
3706
+ invariant(dragDropManager != null, 'Expected drag drop context');
3707
+ return dragDropManager;
3708
+ }
3709
+
3710
+ function useDragSourceConnector(dragSourceOptions, dragPreviewOptions) {
3711
+ const manager = useDragDropManager();
3712
+ const connector = React.useMemo(()=>new SourceConnector(manager.getBackend())
3713
+ , [
3714
+ manager
3715
+ ]);
3716
+ useIsomorphicLayoutEffect(()=>{
3717
+ connector.dragSourceOptions = dragSourceOptions || null;
3718
+ connector.reconnect();
3719
+ return ()=>connector.disconnectDragSource()
3720
+ ;
3721
+ }, [
3722
+ connector,
3723
+ dragSourceOptions
3724
+ ]);
3725
+ useIsomorphicLayoutEffect(()=>{
3726
+ connector.dragPreviewOptions = dragPreviewOptions || null;
3727
+ connector.reconnect();
3728
+ return ()=>connector.disconnectDragPreview()
3729
+ ;
3730
+ }, [
3731
+ connector,
3732
+ dragPreviewOptions
3733
+ ]);
3734
+ return connector;
3735
+ }
3736
+
3737
+ function useDragSourceMonitor() {
3738
+ const manager = useDragDropManager();
3739
+ return React.useMemo(()=>new DragSourceMonitorImpl(manager)
3740
+ , [
3741
+ manager
3742
+ ]);
3743
+ }
3744
+
3745
+ class DragSourceImpl {
3746
+ beginDrag() {
3747
+ const spec = this.spec;
3748
+ const monitor = this.monitor;
3749
+ let result = null;
3750
+ if (typeof spec.item === 'object') {
3751
+ result = spec.item;
3752
+ } else if (typeof spec.item === 'function') {
3753
+ result = spec.item(monitor);
3754
+ } else {
3755
+ result = {};
3756
+ }
3757
+ return result !== null && result !== void 0 ? result : null;
3758
+ }
3759
+ canDrag() {
3760
+ const spec = this.spec;
3761
+ const monitor = this.monitor;
3762
+ if (typeof spec.canDrag === 'boolean') {
3763
+ return spec.canDrag;
3764
+ } else if (typeof spec.canDrag === 'function') {
3765
+ return spec.canDrag(monitor);
3766
+ } else {
3767
+ return true;
3768
+ }
3769
+ }
3770
+ isDragging(globalMonitor, target) {
3771
+ const spec = this.spec;
3772
+ const monitor = this.monitor;
3773
+ const { isDragging } = spec;
3774
+ return isDragging ? isDragging(monitor) : target === globalMonitor.getSourceId();
3775
+ }
3776
+ endDrag() {
3777
+ const spec = this.spec;
3778
+ const monitor = this.monitor;
3779
+ const connector = this.connector;
3780
+ const { end } = spec;
3781
+ if (end) {
3782
+ end(monitor.getItem(), monitor);
3783
+ }
3784
+ connector.reconnect();
3785
+ }
3786
+ constructor(spec, monitor, connector){
3787
+ this.spec = spec;
3788
+ this.monitor = monitor;
3789
+ this.connector = connector;
3790
+ }
3791
+ }
3792
+
3793
+ function useDragSource(spec, monitor, connector) {
3794
+ const handler = React.useMemo(()=>new DragSourceImpl(spec, monitor, connector)
3795
+ , [
3796
+ monitor,
3797
+ connector
3798
+ ]);
3799
+ React.useEffect(()=>{
3800
+ handler.spec = spec;
3801
+ }, [
3802
+ spec
3803
+ ]);
3804
+ return handler;
3805
+ }
3806
+
3807
+ function useDragType(spec) {
3808
+ return React.useMemo(()=>{
3809
+ const result = spec.type;
3810
+ invariant(result != null, 'spec.type must be defined');
3811
+ return result;
3812
+ }, [
3813
+ spec
3814
+ ]);
3815
+ }
3816
+
3817
+ function useRegisteredDragSource(spec, monitor, connector) {
3818
+ const manager = useDragDropManager();
3819
+ const handler = useDragSource(spec, monitor, connector);
3820
+ const itemType = useDragType(spec);
3821
+ useIsomorphicLayoutEffect(function registerDragSource() {
3822
+ if (itemType != null) {
3823
+ const [handlerId, unregister] = registerSource(itemType, handler, manager);
3824
+ monitor.receiveHandlerId(handlerId);
3825
+ connector.receiveHandlerId(handlerId);
3826
+ return unregister;
3827
+ }
3828
+ return;
3829
+ }, [
3830
+ manager,
3831
+ monitor,
3832
+ connector,
3833
+ handler,
3834
+ itemType
3835
+ ]);
3836
+ }
3837
+
3838
+ /**
3839
+ * useDragSource hook
3840
+ * @param sourceSpec The drag source specification (object or function, function preferred)
3841
+ * @param deps The memoization deps array to use when evaluating spec changes
3842
+ */ function useDrag(specArg, deps) {
3843
+ const spec = useOptionalFactory(specArg, deps);
3844
+ invariant(!spec.begin, `useDrag::spec.begin was deprecated in v14. Replace spec.begin() with spec.item(). (see more here - https://react-dnd.github.io/react-dnd/docs/api/use-drag)`);
3845
+ const monitor = useDragSourceMonitor();
3846
+ const connector = useDragSourceConnector(spec.options, spec.previewOptions);
3847
+ useRegisteredDragSource(spec, monitor, connector);
3848
+ return [
3849
+ useCollectedProps(spec.collect, monitor, connector),
3850
+ useConnectDragSource(connector),
3851
+ useConnectDragPreview(connector),
3852
+ ];
3853
+ }
3854
+
3855
+ function useConnectDropTarget(connector) {
3856
+ return React.useMemo(()=>connector.hooks.dropTarget()
3857
+ , [
3858
+ connector
3859
+ ]);
3860
+ }
3861
+
3862
+ function useDropTargetConnector(options) {
3863
+ const manager = useDragDropManager();
3864
+ const connector = React.useMemo(()=>new TargetConnector(manager.getBackend())
3865
+ , [
3866
+ manager
3867
+ ]);
3868
+ useIsomorphicLayoutEffect(()=>{
3869
+ connector.dropTargetOptions = options || null;
3870
+ connector.reconnect();
3871
+ return ()=>connector.disconnectDropTarget()
3872
+ ;
3873
+ }, [
3874
+ options
3875
+ ]);
3876
+ return connector;
3877
+ }
3878
+
3879
+ function useDropTargetMonitor() {
3880
+ const manager = useDragDropManager();
3881
+ return React.useMemo(()=>new DropTargetMonitorImpl(manager)
3882
+ , [
3883
+ manager
3884
+ ]);
3885
+ }
3886
+
3887
+ /**
3888
+ * Internal utility hook to get an array-version of spec.accept.
3889
+ * The main utility here is that we aren't creating a new array on every render if a non-array spec.accept is passed in.
3890
+ * @param spec
3891
+ */ function useAccept(spec) {
3892
+ const { accept } = spec;
3893
+ return React.useMemo(()=>{
3894
+ invariant(spec.accept != null, 'accept must be defined');
3895
+ return Array.isArray(accept) ? accept : [
3896
+ accept
3897
+ ];
3898
+ }, [
3899
+ accept
3900
+ ]);
3901
+ }
3902
+
3903
+ class DropTargetImpl {
3904
+ canDrop() {
3905
+ const spec = this.spec;
3906
+ const monitor = this.monitor;
3907
+ return spec.canDrop ? spec.canDrop(monitor.getItem(), monitor) : true;
3908
+ }
3909
+ hover() {
3910
+ const spec = this.spec;
3911
+ const monitor = this.monitor;
3912
+ if (spec.hover) {
3913
+ spec.hover(monitor.getItem(), monitor);
3914
+ }
3915
+ }
3916
+ drop() {
3917
+ const spec = this.spec;
3918
+ const monitor = this.monitor;
3919
+ if (spec.drop) {
3920
+ return spec.drop(monitor.getItem(), monitor);
3921
+ }
3922
+ return;
3923
+ }
3924
+ constructor(spec, monitor){
3925
+ this.spec = spec;
3926
+ this.monitor = monitor;
3927
+ }
3928
+ }
3929
+
3930
+ function useDropTarget(spec, monitor) {
3931
+ const dropTarget = React.useMemo(()=>new DropTargetImpl(spec, monitor)
3932
+ , [
3933
+ monitor
3934
+ ]);
3935
+ React.useEffect(()=>{
3936
+ dropTarget.spec = spec;
3937
+ }, [
3938
+ spec
3939
+ ]);
3940
+ return dropTarget;
3941
+ }
3942
+
3943
+ function useRegisteredDropTarget(spec, monitor, connector) {
3944
+ const manager = useDragDropManager();
3945
+ const dropTarget = useDropTarget(spec, monitor);
3946
+ const accept = useAccept(spec);
3947
+ useIsomorphicLayoutEffect(function registerDropTarget() {
3948
+ const [handlerId, unregister] = registerTarget(accept, dropTarget, manager);
3949
+ monitor.receiveHandlerId(handlerId);
3950
+ connector.receiveHandlerId(handlerId);
3951
+ return unregister;
3952
+ }, [
3953
+ manager,
3954
+ monitor,
3955
+ dropTarget,
3956
+ connector,
3957
+ accept.map((a)=>a.toString()
3958
+ ).join('|'),
3959
+ ]);
3960
+ }
3961
+
3962
+ /**
3963
+ * useDropTarget Hook
3964
+ * @param spec The drop target specification (object or function, function preferred)
3965
+ * @param deps The memoization deps array to use when evaluating spec changes
3966
+ */ function useDrop(specArg, deps) {
3967
+ const spec = useOptionalFactory(specArg, deps);
3968
+ const monitor = useDropTargetMonitor();
3969
+ const connector = useDropTargetConnector(spec.options);
3970
+ useRegisteredDropTarget(spec, monitor, connector);
3971
+ return [
3972
+ useCollectedProps(spec.collect, monitor, connector),
3973
+ useConnectDropTarget(connector),
3974
+ ];
3975
+ }
3976
+
3977
+ // cheap lodash replacements
3978
+ function memoize(fn) {
3979
+ let result = null;
3980
+ const memoized = ()=>{
3981
+ if (result == null) {
3982
+ result = fn();
3983
+ }
3984
+ return result;
3985
+ };
3986
+ return memoized;
3987
+ }
3988
+ /**
3989
+ * drop-in replacement for _.without
3990
+ */ function without$1(items, item) {
3991
+ return items.filter((i)=>i !== item
3992
+ );
3993
+ }
3994
+ function union(itemsA, itemsB) {
3995
+ const set = new Set();
3996
+ const insertItem = (item)=>set.add(item)
3997
+ ;
3998
+ itemsA.forEach(insertItem);
3999
+ itemsB.forEach(insertItem);
4000
+ const result = [];
4001
+ set.forEach((key)=>result.push(key)
4002
+ );
4003
+ return result;
4004
+ }
4005
+
4006
+ class EnterLeaveCounter {
4007
+ enter(enteringNode) {
4008
+ const previousLength = this.entered.length;
4009
+ const isNodeEntered = (node)=>this.isNodeInDocument(node) && (!node.contains || node.contains(enteringNode))
4010
+ ;
4011
+ this.entered = union(this.entered.filter(isNodeEntered), [
4012
+ enteringNode
4013
+ ]);
4014
+ return previousLength === 0 && this.entered.length > 0;
4015
+ }
4016
+ leave(leavingNode) {
4017
+ const previousLength = this.entered.length;
4018
+ this.entered = without$1(this.entered.filter(this.isNodeInDocument), leavingNode);
4019
+ return previousLength > 0 && this.entered.length === 0;
4020
+ }
4021
+ reset() {
4022
+ this.entered = [];
4023
+ }
4024
+ constructor(isNodeInDocument){
4025
+ this.entered = [];
4026
+ this.isNodeInDocument = isNodeInDocument;
4027
+ }
4028
+ }
4029
+
4030
+ class NativeDragSource {
4031
+ initializeExposedProperties() {
4032
+ Object.keys(this.config.exposeProperties).forEach((property)=>{
4033
+ Object.defineProperty(this.item, property, {
4034
+ configurable: true,
4035
+ enumerable: true,
4036
+ get () {
4037
+ // eslint-disable-next-line no-console
4038
+ console.warn(`Browser doesn't allow reading "${property}" until the drop event.`);
4039
+ return null;
4040
+ }
4041
+ });
4042
+ });
4043
+ }
4044
+ loadDataTransfer(dataTransfer) {
4045
+ if (dataTransfer) {
4046
+ const newProperties = {};
4047
+ Object.keys(this.config.exposeProperties).forEach((property)=>{
4048
+ const propertyFn = this.config.exposeProperties[property];
4049
+ if (propertyFn != null) {
4050
+ newProperties[property] = {
4051
+ value: propertyFn(dataTransfer, this.config.matchesTypes),
4052
+ configurable: true,
4053
+ enumerable: true
4054
+ };
4055
+ }
4056
+ });
4057
+ Object.defineProperties(this.item, newProperties);
4058
+ }
4059
+ }
4060
+ canDrag() {
4061
+ return true;
4062
+ }
4063
+ beginDrag() {
4064
+ return this.item;
4065
+ }
4066
+ isDragging(monitor, handle) {
4067
+ return handle === monitor.getSourceId();
4068
+ }
4069
+ endDrag() {
4070
+ // empty
4071
+ }
4072
+ constructor(config){
4073
+ this.config = config;
4074
+ this.item = {};
4075
+ this.initializeExposedProperties();
4076
+ }
4077
+ }
4078
+
4079
+ const FILE = '__NATIVE_FILE__';
4080
+ const URL = '__NATIVE_URL__';
4081
+ const TEXT = '__NATIVE_TEXT__';
4082
+ const HTML = '__NATIVE_HTML__';
4083
+
4084
+ var NativeTypes = {
4085
+ __proto__: null,
4086
+ FILE: FILE,
4087
+ URL: URL,
4088
+ TEXT: TEXT,
4089
+ HTML: HTML
4090
+ };
4091
+
4092
+ function getDataFromDataTransfer(dataTransfer, typesToTry, defaultValue) {
4093
+ const result = typesToTry.reduce((resultSoFar, typeToTry)=>resultSoFar || dataTransfer.getData(typeToTry)
4094
+ , '');
4095
+ return result != null ? result : defaultValue;
4096
+ }
4097
+
4098
+ const nativeTypesConfig = {
4099
+ [FILE]: {
4100
+ exposeProperties: {
4101
+ files: (dataTransfer)=>Array.prototype.slice.call(dataTransfer.files)
4102
+ ,
4103
+ items: (dataTransfer)=>dataTransfer.items
4104
+ ,
4105
+ dataTransfer: (dataTransfer)=>dataTransfer
4106
+ },
4107
+ matchesTypes: [
4108
+ 'Files'
4109
+ ]
4110
+ },
4111
+ [HTML]: {
4112
+ exposeProperties: {
4113
+ html: (dataTransfer, matchesTypes)=>getDataFromDataTransfer(dataTransfer, matchesTypes, '')
4114
+ ,
4115
+ dataTransfer: (dataTransfer)=>dataTransfer
4116
+ },
4117
+ matchesTypes: [
4118
+ 'Html',
4119
+ 'text/html'
4120
+ ]
4121
+ },
4122
+ [URL]: {
4123
+ exposeProperties: {
4124
+ urls: (dataTransfer, matchesTypes)=>getDataFromDataTransfer(dataTransfer, matchesTypes, '').split('\n')
4125
+ ,
4126
+ dataTransfer: (dataTransfer)=>dataTransfer
4127
+ },
4128
+ matchesTypes: [
4129
+ 'Url',
4130
+ 'text/uri-list'
4131
+ ]
4132
+ },
4133
+ [TEXT]: {
4134
+ exposeProperties: {
4135
+ text: (dataTransfer, matchesTypes)=>getDataFromDataTransfer(dataTransfer, matchesTypes, '')
4136
+ ,
4137
+ dataTransfer: (dataTransfer)=>dataTransfer
4138
+ },
4139
+ matchesTypes: [
4140
+ 'Text',
4141
+ 'text/plain'
4142
+ ]
4143
+ }
4144
+ };
4145
+
4146
+ function createNativeDragSource(type, dataTransfer) {
4147
+ const config = nativeTypesConfig[type];
4148
+ if (!config) {
4149
+ throw new Error(`native type ${type} has no configuration`);
4150
+ }
4151
+ const result = new NativeDragSource(config);
4152
+ result.loadDataTransfer(dataTransfer);
4153
+ return result;
4154
+ }
4155
+ function matchNativeItemType(dataTransfer) {
4156
+ if (!dataTransfer) {
4157
+ return null;
4158
+ }
4159
+ const dataTransferTypes = Array.prototype.slice.call(dataTransfer.types || []);
4160
+ return Object.keys(nativeTypesConfig).filter((nativeItemType)=>{
4161
+ const typeConfig = nativeTypesConfig[nativeItemType];
4162
+ if (!(typeConfig === null || typeConfig === void 0 ? void 0 : typeConfig.matchesTypes)) {
4163
+ return false;
4164
+ }
4165
+ return typeConfig.matchesTypes.some((t)=>dataTransferTypes.indexOf(t) > -1
4166
+ );
4167
+ })[0] || null;
4168
+ }
4169
+
4170
+ const isFirefox = memoize(()=>/firefox/i.test(navigator.userAgent)
4171
+ );
4172
+ const isSafari = memoize(()=>Boolean(window.safari)
4173
+ );
4174
+
4175
+ class MonotonicInterpolant {
4176
+ interpolate(x) {
4177
+ const { xs , ys , c1s , c2s , c3s } = this;
4178
+ // The rightmost point in the dataset should give an exact result
4179
+ let i = xs.length - 1;
4180
+ if (x === xs[i]) {
4181
+ return ys[i];
4182
+ }
4183
+ // Search for the interval x is in, returning the corresponding y if x is one of the original xs
4184
+ let low = 0;
4185
+ let high = c3s.length - 1;
4186
+ let mid;
4187
+ while(low <= high){
4188
+ mid = Math.floor(0.5 * (low + high));
4189
+ const xHere = xs[mid];
4190
+ if (xHere < x) {
4191
+ low = mid + 1;
4192
+ } else if (xHere > x) {
4193
+ high = mid - 1;
4194
+ } else {
4195
+ return ys[mid];
4196
+ }
4197
+ }
4198
+ i = Math.max(0, high);
4199
+ // Interpolate
4200
+ const diff = x - xs[i];
4201
+ const diffSq = diff * diff;
4202
+ return ys[i] + c1s[i] * diff + c2s[i] * diffSq + c3s[i] * diff * diffSq;
4203
+ }
4204
+ constructor(xs, ys){
4205
+ const { length } = xs;
4206
+ const dxs = [];
4207
+ const ms = [];
4208
+ let dx;
4209
+ let dy;
4210
+ for(let i1 = 0; i1 < length - 1; i1++){
4211
+ dx = xs[i1 + 1] - xs[i1];
4212
+ dy = ys[i1 + 1] - ys[i1];
4213
+ dxs.push(dx);
4214
+ ms.push(dy / dx);
4215
+ }
4216
+ // Get degree-1 coefficients
4217
+ const c1s = [
4218
+ ms[0]
4219
+ ];
4220
+ for(let i2 = 0; i2 < dxs.length - 1; i2++){
4221
+ const m2 = ms[i2];
4222
+ const mNext = ms[i2 + 1];
4223
+ if (m2 * mNext <= 0) {
4224
+ c1s.push(0);
4225
+ } else {
4226
+ dx = dxs[i2];
4227
+ const dxNext = dxs[i2 + 1];
4228
+ const common = dx + dxNext;
4229
+ c1s.push(3 * common / ((common + dxNext) / m2 + (common + dx) / mNext));
4230
+ }
4231
+ }
4232
+ c1s.push(ms[ms.length - 1]);
4233
+ // Get degree-2 and degree-3 coefficients
4234
+ const c2s = [];
4235
+ const c3s = [];
4236
+ let m;
4237
+ for(let i3 = 0; i3 < c1s.length - 1; i3++){
4238
+ m = ms[i3];
4239
+ const c1 = c1s[i3];
4240
+ const invDx = 1 / dxs[i3];
4241
+ const common = c1 + c1s[i3 + 1] - m - m;
4242
+ c2s.push((m - c1 - common) * invDx);
4243
+ c3s.push(common * invDx * invDx);
4244
+ }
4245
+ this.xs = xs;
4246
+ this.ys = ys;
4247
+ this.c1s = c1s;
4248
+ this.c2s = c2s;
4249
+ this.c3s = c3s;
4250
+ }
4251
+ }
4252
+
4253
+ const ELEMENT_NODE = 1;
4254
+ function getNodeClientOffset(node) {
4255
+ const el = node.nodeType === ELEMENT_NODE ? node : node.parentElement;
4256
+ if (!el) {
4257
+ return null;
4258
+ }
4259
+ const { top , left } = el.getBoundingClientRect();
4260
+ return {
4261
+ x: left,
4262
+ y: top
4263
+ };
4264
+ }
4265
+ function getEventClientOffset(e) {
4266
+ return {
4267
+ x: e.clientX,
4268
+ y: e.clientY
4269
+ };
4270
+ }
4271
+ function isImageNode(node) {
4272
+ var ref;
4273
+ return node.nodeName === 'IMG' && (isFirefox() || !((ref = document.documentElement) === null || ref === void 0 ? void 0 : ref.contains(node)));
4274
+ }
4275
+ function getDragPreviewSize(isImage, dragPreview, sourceWidth, sourceHeight) {
4276
+ let dragPreviewWidth = isImage ? dragPreview.width : sourceWidth;
4277
+ let dragPreviewHeight = isImage ? dragPreview.height : sourceHeight;
4278
+ // Work around @2x coordinate discrepancies in browsers
4279
+ if (isSafari() && isImage) {
4280
+ dragPreviewHeight /= window.devicePixelRatio;
4281
+ dragPreviewWidth /= window.devicePixelRatio;
4282
+ }
4283
+ return {
4284
+ dragPreviewWidth,
4285
+ dragPreviewHeight
4286
+ };
4287
+ }
4288
+ function getDragPreviewOffset(sourceNode, dragPreview, clientOffset, anchorPoint, offsetPoint) {
4289
+ // The browsers will use the image intrinsic size under different conditions.
4290
+ // Firefox only cares if it's an image, but WebKit also wants it to be detached.
4291
+ const isImage = isImageNode(dragPreview);
4292
+ const dragPreviewNode = isImage ? sourceNode : dragPreview;
4293
+ const dragPreviewNodeOffsetFromClient = getNodeClientOffset(dragPreviewNode);
4294
+ const offsetFromDragPreview = {
4295
+ x: clientOffset.x - dragPreviewNodeOffsetFromClient.x,
4296
+ y: clientOffset.y - dragPreviewNodeOffsetFromClient.y
4297
+ };
4298
+ const { offsetWidth: sourceWidth , offsetHeight: sourceHeight } = sourceNode;
4299
+ const { anchorX , anchorY } = anchorPoint;
4300
+ const { dragPreviewWidth , dragPreviewHeight } = getDragPreviewSize(isImage, dragPreview, sourceWidth, sourceHeight);
4301
+ const calculateYOffset = ()=>{
4302
+ const interpolantY = new MonotonicInterpolant([
4303
+ 0,
4304
+ 0.5,
4305
+ 1
4306
+ ], [
4307
+ // Dock to the top
4308
+ offsetFromDragPreview.y,
4309
+ // Align at the center
4310
+ (offsetFromDragPreview.y / sourceHeight) * dragPreviewHeight,
4311
+ // Dock to the bottom
4312
+ offsetFromDragPreview.y + dragPreviewHeight - sourceHeight,
4313
+ ]);
4314
+ let y = interpolantY.interpolate(anchorY);
4315
+ // Work around Safari 8 positioning bug
4316
+ if (isSafari() && isImage) {
4317
+ // We'll have to wait for @3x to see if this is entirely correct
4318
+ y += (window.devicePixelRatio - 1) * dragPreviewHeight;
4319
+ }
4320
+ return y;
4321
+ };
4322
+ const calculateXOffset = ()=>{
4323
+ // Interpolate coordinates depending on anchor point
4324
+ // If you know a simpler way to do this, let me know
4325
+ const interpolantX = new MonotonicInterpolant([
4326
+ 0,
4327
+ 0.5,
4328
+ 1
4329
+ ], [
4330
+ // Dock to the left
4331
+ offsetFromDragPreview.x,
4332
+ // Align at the center
4333
+ (offsetFromDragPreview.x / sourceWidth) * dragPreviewWidth,
4334
+ // Dock to the right
4335
+ offsetFromDragPreview.x + dragPreviewWidth - sourceWidth,
4336
+ ]);
4337
+ return interpolantX.interpolate(anchorX);
4338
+ };
4339
+ // Force offsets if specified in the options.
4340
+ const { offsetX , offsetY } = offsetPoint;
4341
+ const isManualOffsetX = offsetX === 0 || offsetX;
4342
+ const isManualOffsetY = offsetY === 0 || offsetY;
4343
+ return {
4344
+ x: isManualOffsetX ? offsetX : calculateXOffset(),
4345
+ y: isManualOffsetY ? offsetY : calculateYOffset()
4346
+ };
4347
+ }
4348
+
4349
+ class OptionsReader {
4350
+ get window() {
4351
+ if (this.globalContext) {
4352
+ return this.globalContext;
4353
+ } else if (typeof window !== 'undefined') {
4354
+ return window;
4355
+ }
4356
+ return undefined;
4357
+ }
4358
+ get document() {
4359
+ var ref;
4360
+ if ((ref = this.globalContext) === null || ref === void 0 ? void 0 : ref.document) {
4361
+ return this.globalContext.document;
4362
+ } else if (this.window) {
4363
+ return this.window.document;
4364
+ } else {
4365
+ return undefined;
4366
+ }
4367
+ }
4368
+ get rootElement() {
4369
+ var ref;
4370
+ return ((ref = this.optionsArgs) === null || ref === void 0 ? void 0 : ref.rootElement) || this.window;
4371
+ }
4372
+ constructor(globalContext, options){
4373
+ this.ownerDocument = null;
4374
+ this.globalContext = globalContext;
4375
+ this.optionsArgs = options;
4376
+ }
4377
+ }
4378
+
4379
+ function _defineProperty$4(obj, key, value) {
4380
+ if (key in obj) {
4381
+ Object.defineProperty(obj, key, {
4382
+ value: value,
4383
+ enumerable: true,
4384
+ configurable: true,
4385
+ writable: true
4386
+ });
4387
+ } else {
4388
+ obj[key] = value;
4389
+ }
4390
+ return obj;
4391
+ }
4392
+ function _objectSpread$4(target) {
4393
+ for(var i = 1; i < arguments.length; i++){
4394
+ var source = arguments[i] != null ? arguments[i] : {};
4395
+ var ownKeys = Object.keys(source);
4396
+ if (typeof Object.getOwnPropertySymbols === 'function') {
4397
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
4398
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
4399
+ }));
4400
+ }
4401
+ ownKeys.forEach(function(key) {
4402
+ _defineProperty$4(target, key, source[key]);
4403
+ });
4404
+ }
4405
+ return target;
4406
+ }
4407
+ class HTML5BackendImpl {
4408
+ /**
4409
+ * Generate profiling statistics for the HTML5Backend.
4410
+ */ profile() {
4411
+ var ref, ref1;
4412
+ return {
4413
+ sourcePreviewNodes: this.sourcePreviewNodes.size,
4414
+ sourcePreviewNodeOptions: this.sourcePreviewNodeOptions.size,
4415
+ sourceNodeOptions: this.sourceNodeOptions.size,
4416
+ sourceNodes: this.sourceNodes.size,
4417
+ dragStartSourceIds: ((ref = this.dragStartSourceIds) === null || ref === void 0 ? void 0 : ref.length) || 0,
4418
+ dropTargetIds: this.dropTargetIds.length,
4419
+ dragEnterTargetIds: this.dragEnterTargetIds.length,
4420
+ dragOverTargetIds: ((ref1 = this.dragOverTargetIds) === null || ref1 === void 0 ? void 0 : ref1.length) || 0
4421
+ };
4422
+ }
4423
+ // public for test
4424
+ get window() {
4425
+ return this.options.window;
4426
+ }
4427
+ get document() {
4428
+ return this.options.document;
4429
+ }
4430
+ /**
4431
+ * Get the root element to use for event subscriptions
4432
+ */ get rootElement() {
4433
+ return this.options.rootElement;
4434
+ }
4435
+ setup() {
4436
+ const root = this.rootElement;
4437
+ if (root === undefined) {
4438
+ return;
4439
+ }
4440
+ if (root.__isReactDndBackendSetUp) {
4441
+ throw new Error('Cannot have two HTML5 backends at the same time.');
4442
+ }
4443
+ root.__isReactDndBackendSetUp = true;
4444
+ this.addEventListeners(root);
4445
+ }
4446
+ teardown() {
4447
+ const root = this.rootElement;
4448
+ if (root === undefined) {
4449
+ return;
4450
+ }
4451
+ root.__isReactDndBackendSetUp = false;
4452
+ this.removeEventListeners(this.rootElement);
4453
+ this.clearCurrentDragSourceNode();
4454
+ if (this.asyncEndDragFrameId) {
4455
+ var ref;
4456
+ (ref = this.window) === null || ref === void 0 ? void 0 : ref.cancelAnimationFrame(this.asyncEndDragFrameId);
4457
+ }
4458
+ }
4459
+ connectDragPreview(sourceId, node, options) {
4460
+ this.sourcePreviewNodeOptions.set(sourceId, options);
4461
+ this.sourcePreviewNodes.set(sourceId, node);
4462
+ return ()=>{
4463
+ this.sourcePreviewNodes.delete(sourceId);
4464
+ this.sourcePreviewNodeOptions.delete(sourceId);
4465
+ };
4466
+ }
4467
+ connectDragSource(sourceId, node, options) {
4468
+ this.sourceNodes.set(sourceId, node);
4469
+ this.sourceNodeOptions.set(sourceId, options);
4470
+ const handleDragStart = (e)=>this.handleDragStart(e, sourceId)
4471
+ ;
4472
+ const handleSelectStart = (e)=>this.handleSelectStart(e)
4473
+ ;
4474
+ node.setAttribute('draggable', 'true');
4475
+ node.addEventListener('dragstart', handleDragStart);
4476
+ node.addEventListener('selectstart', handleSelectStart);
4477
+ return ()=>{
4478
+ this.sourceNodes.delete(sourceId);
4479
+ this.sourceNodeOptions.delete(sourceId);
4480
+ node.removeEventListener('dragstart', handleDragStart);
4481
+ node.removeEventListener('selectstart', handleSelectStart);
4482
+ node.setAttribute('draggable', 'false');
4483
+ };
4484
+ }
4485
+ connectDropTarget(targetId, node) {
4486
+ const handleDragEnter = (e)=>this.handleDragEnter(e, targetId)
4487
+ ;
4488
+ const handleDragOver = (e)=>this.handleDragOver(e, targetId)
4489
+ ;
4490
+ const handleDrop = (e)=>this.handleDrop(e, targetId)
4491
+ ;
4492
+ node.addEventListener('dragenter', handleDragEnter);
4493
+ node.addEventListener('dragover', handleDragOver);
4494
+ node.addEventListener('drop', handleDrop);
4495
+ return ()=>{
4496
+ node.removeEventListener('dragenter', handleDragEnter);
4497
+ node.removeEventListener('dragover', handleDragOver);
4498
+ node.removeEventListener('drop', handleDrop);
4499
+ };
4500
+ }
4501
+ addEventListeners(target) {
4502
+ // SSR Fix (https://github.com/react-dnd/react-dnd/pull/813
4503
+ if (!target.addEventListener) {
4504
+ return;
4505
+ }
4506
+ target.addEventListener('dragstart', this.handleTopDragStart);
4507
+ target.addEventListener('dragstart', this.handleTopDragStartCapture, true);
4508
+ target.addEventListener('dragend', this.handleTopDragEndCapture, true);
4509
+ target.addEventListener('dragenter', this.handleTopDragEnter);
4510
+ target.addEventListener('dragenter', this.handleTopDragEnterCapture, true);
4511
+ target.addEventListener('dragleave', this.handleTopDragLeaveCapture, true);
4512
+ target.addEventListener('dragover', this.handleTopDragOver);
4513
+ target.addEventListener('dragover', this.handleTopDragOverCapture, true);
4514
+ target.addEventListener('drop', this.handleTopDrop);
4515
+ target.addEventListener('drop', this.handleTopDropCapture, true);
4516
+ }
4517
+ removeEventListeners(target) {
4518
+ // SSR Fix (https://github.com/react-dnd/react-dnd/pull/813
4519
+ if (!target.removeEventListener) {
4520
+ return;
4521
+ }
4522
+ target.removeEventListener('dragstart', this.handleTopDragStart);
4523
+ target.removeEventListener('dragstart', this.handleTopDragStartCapture, true);
4524
+ target.removeEventListener('dragend', this.handleTopDragEndCapture, true);
4525
+ target.removeEventListener('dragenter', this.handleTopDragEnter);
4526
+ target.removeEventListener('dragenter', this.handleTopDragEnterCapture, true);
4527
+ target.removeEventListener('dragleave', this.handleTopDragLeaveCapture, true);
4528
+ target.removeEventListener('dragover', this.handleTopDragOver);
4529
+ target.removeEventListener('dragover', this.handleTopDragOverCapture, true);
4530
+ target.removeEventListener('drop', this.handleTopDrop);
4531
+ target.removeEventListener('drop', this.handleTopDropCapture, true);
4532
+ }
4533
+ getCurrentSourceNodeOptions() {
4534
+ const sourceId = this.monitor.getSourceId();
4535
+ const sourceNodeOptions = this.sourceNodeOptions.get(sourceId);
4536
+ return _objectSpread$4({
4537
+ dropEffect: this.altKeyPressed ? 'copy' : 'move'
4538
+ }, sourceNodeOptions || {});
4539
+ }
4540
+ getCurrentDropEffect() {
4541
+ if (this.isDraggingNativeItem()) {
4542
+ // It makes more sense to default to 'copy' for native resources
4543
+ return 'copy';
4544
+ }
4545
+ return this.getCurrentSourceNodeOptions().dropEffect;
4546
+ }
4547
+ getCurrentSourcePreviewNodeOptions() {
4548
+ const sourceId = this.monitor.getSourceId();
4549
+ const sourcePreviewNodeOptions = this.sourcePreviewNodeOptions.get(sourceId);
4550
+ return _objectSpread$4({
4551
+ anchorX: 0.5,
4552
+ anchorY: 0.5,
4553
+ captureDraggingState: false
4554
+ }, sourcePreviewNodeOptions || {});
4555
+ }
4556
+ isDraggingNativeItem() {
4557
+ const itemType = this.monitor.getItemType();
4558
+ return Object.keys(NativeTypes).some((key)=>NativeTypes[key] === itemType
4559
+ );
4560
+ }
4561
+ beginDragNativeItem(type, dataTransfer) {
4562
+ this.clearCurrentDragSourceNode();
4563
+ this.currentNativeSource = createNativeDragSource(type, dataTransfer);
4564
+ this.currentNativeHandle = this.registry.addSource(type, this.currentNativeSource);
4565
+ this.actions.beginDrag([
4566
+ this.currentNativeHandle
4567
+ ]);
4568
+ }
4569
+ setCurrentDragSourceNode(node) {
4570
+ this.clearCurrentDragSourceNode();
4571
+ this.currentDragSourceNode = node;
4572
+ // A timeout of > 0 is necessary to resolve Firefox issue referenced
4573
+ // See:
4574
+ // * https://github.com/react-dnd/react-dnd/pull/928
4575
+ // * https://github.com/react-dnd/react-dnd/issues/869
4576
+ const MOUSE_MOVE_TIMEOUT = 1000;
4577
+ // Receiving a mouse event in the middle of a dragging operation
4578
+ // means it has ended and the drag source node disappeared from DOM,
4579
+ // so the browser didn't dispatch the dragend event.
4580
+ //
4581
+ // We need to wait before we start listening for mousemove events.
4582
+ // This is needed because the drag preview needs to be drawn or else it fires an 'mousemove' event
4583
+ // immediately in some browsers.
4584
+ //
4585
+ // See:
4586
+ // * https://github.com/react-dnd/react-dnd/pull/928
4587
+ // * https://github.com/react-dnd/react-dnd/issues/869
4588
+ //
4589
+ this.mouseMoveTimeoutTimer = setTimeout(()=>{
4590
+ var ref;
4591
+ return (ref = this.rootElement) === null || ref === void 0 ? void 0 : ref.addEventListener('mousemove', this.endDragIfSourceWasRemovedFromDOM, true);
4592
+ }, MOUSE_MOVE_TIMEOUT);
4593
+ }
4594
+ clearCurrentDragSourceNode() {
4595
+ if (this.currentDragSourceNode) {
4596
+ this.currentDragSourceNode = null;
4597
+ if (this.rootElement) {
4598
+ var ref;
4599
+ (ref = this.window) === null || ref === void 0 ? void 0 : ref.clearTimeout(this.mouseMoveTimeoutTimer || undefined);
4600
+ this.rootElement.removeEventListener('mousemove', this.endDragIfSourceWasRemovedFromDOM, true);
4601
+ }
4602
+ this.mouseMoveTimeoutTimer = null;
4603
+ return true;
4604
+ }
4605
+ return false;
4606
+ }
4607
+ handleDragStart(e, sourceId) {
4608
+ if (e.defaultPrevented) {
4609
+ return;
4610
+ }
4611
+ if (!this.dragStartSourceIds) {
4612
+ this.dragStartSourceIds = [];
4613
+ }
4614
+ this.dragStartSourceIds.unshift(sourceId);
4615
+ }
4616
+ handleDragEnter(_e, targetId) {
4617
+ this.dragEnterTargetIds.unshift(targetId);
4618
+ }
4619
+ handleDragOver(_e, targetId) {
4620
+ if (this.dragOverTargetIds === null) {
4621
+ this.dragOverTargetIds = [];
4622
+ }
4623
+ this.dragOverTargetIds.unshift(targetId);
4624
+ }
4625
+ handleDrop(_e, targetId) {
4626
+ this.dropTargetIds.unshift(targetId);
4627
+ }
4628
+ constructor(manager, globalContext, options){
4629
+ this.sourcePreviewNodes = new Map();
4630
+ this.sourcePreviewNodeOptions = new Map();
4631
+ this.sourceNodes = new Map();
4632
+ this.sourceNodeOptions = new Map();
4633
+ this.dragStartSourceIds = null;
4634
+ this.dropTargetIds = [];
4635
+ this.dragEnterTargetIds = [];
4636
+ this.currentNativeSource = null;
4637
+ this.currentNativeHandle = null;
4638
+ this.currentDragSourceNode = null;
4639
+ this.altKeyPressed = false;
4640
+ this.mouseMoveTimeoutTimer = null;
4641
+ this.asyncEndDragFrameId = null;
4642
+ this.dragOverTargetIds = null;
4643
+ this.lastClientOffset = null;
4644
+ this.hoverRafId = null;
4645
+ this.getSourceClientOffset = (sourceId)=>{
4646
+ const source = this.sourceNodes.get(sourceId);
4647
+ return source && getNodeClientOffset(source) || null;
4648
+ };
4649
+ this.endDragNativeItem = ()=>{
4650
+ if (!this.isDraggingNativeItem()) {
4651
+ return;
4652
+ }
4653
+ this.actions.endDrag();
4654
+ if (this.currentNativeHandle) {
4655
+ this.registry.removeSource(this.currentNativeHandle);
4656
+ }
4657
+ this.currentNativeHandle = null;
4658
+ this.currentNativeSource = null;
4659
+ };
4660
+ this.isNodeInDocument = (node)=>{
4661
+ // Check the node either in the main document or in the current context
4662
+ return Boolean(node && this.document && this.document.body && this.document.body.contains(node));
4663
+ };
4664
+ this.endDragIfSourceWasRemovedFromDOM = ()=>{
4665
+ const node = this.currentDragSourceNode;
4666
+ if (node == null || this.isNodeInDocument(node)) {
4667
+ return;
4668
+ }
4669
+ if (this.clearCurrentDragSourceNode() && this.monitor.isDragging()) {
4670
+ this.actions.endDrag();
4671
+ }
4672
+ this.cancelHover();
4673
+ };
4674
+ this.scheduleHover = (dragOverTargetIds)=>{
4675
+ if (this.hoverRafId === null && typeof requestAnimationFrame !== 'undefined') {
4676
+ this.hoverRafId = requestAnimationFrame(()=>{
4677
+ if (this.monitor.isDragging()) {
4678
+ this.actions.hover(dragOverTargetIds || [], {
4679
+ clientOffset: this.lastClientOffset
4680
+ });
4681
+ }
4682
+ this.hoverRafId = null;
4683
+ });
4684
+ }
4685
+ };
4686
+ this.cancelHover = ()=>{
4687
+ if (this.hoverRafId !== null && typeof cancelAnimationFrame !== 'undefined') {
4688
+ cancelAnimationFrame(this.hoverRafId);
4689
+ this.hoverRafId = null;
4690
+ }
4691
+ };
4692
+ this.handleTopDragStartCapture = ()=>{
4693
+ this.clearCurrentDragSourceNode();
4694
+ this.dragStartSourceIds = [];
4695
+ };
4696
+ this.handleTopDragStart = (e)=>{
4697
+ if (e.defaultPrevented) {
4698
+ return;
4699
+ }
4700
+ const { dragStartSourceIds } = this;
4701
+ this.dragStartSourceIds = null;
4702
+ const clientOffset = getEventClientOffset(e);
4703
+ // Avoid crashing if we missed a drop event or our previous drag died
4704
+ if (this.monitor.isDragging()) {
4705
+ this.actions.endDrag();
4706
+ this.cancelHover();
4707
+ }
4708
+ // Don't publish the source just yet (see why below)
4709
+ this.actions.beginDrag(dragStartSourceIds || [], {
4710
+ publishSource: false,
4711
+ getSourceClientOffset: this.getSourceClientOffset,
4712
+ clientOffset
4713
+ });
4714
+ const { dataTransfer } = e;
4715
+ const nativeType = matchNativeItemType(dataTransfer);
4716
+ if (this.monitor.isDragging()) {
4717
+ if (dataTransfer && typeof dataTransfer.setDragImage === 'function') {
4718
+ // Use custom drag image if user specifies it.
4719
+ // If child drag source refuses drag but parent agrees,
4720
+ // use parent's node as drag image. Neither works in IE though.
4721
+ const sourceId = this.monitor.getSourceId();
4722
+ const sourceNode = this.sourceNodes.get(sourceId);
4723
+ const dragPreview = this.sourcePreviewNodes.get(sourceId) || sourceNode;
4724
+ if (dragPreview) {
4725
+ const { anchorX , anchorY , offsetX , offsetY } = this.getCurrentSourcePreviewNodeOptions();
4726
+ const anchorPoint = {
4727
+ anchorX,
4728
+ anchorY
4729
+ };
4730
+ const offsetPoint = {
4731
+ offsetX,
4732
+ offsetY
4733
+ };
4734
+ const dragPreviewOffset = getDragPreviewOffset(sourceNode, dragPreview, clientOffset, anchorPoint, offsetPoint);
4735
+ dataTransfer.setDragImage(dragPreview, dragPreviewOffset.x, dragPreviewOffset.y);
4736
+ }
4737
+ }
4738
+ try {
4739
+ // Firefox won't drag without setting data
4740
+ dataTransfer === null || dataTransfer === void 0 ? void 0 : dataTransfer.setData('application/json', {});
4741
+ } catch (err) {
4742
+ // IE doesn't support MIME types in setData
4743
+ }
4744
+ // Store drag source node so we can check whether
4745
+ // it is removed from DOM and trigger endDrag manually.
4746
+ this.setCurrentDragSourceNode(e.target);
4747
+ // Now we are ready to publish the drag source.. or are we not?
4748
+ const { captureDraggingState } = this.getCurrentSourcePreviewNodeOptions();
4749
+ if (!captureDraggingState) {
4750
+ // Usually we want to publish it in the next tick so that browser
4751
+ // is able to screenshot the current (not yet dragging) state.
4752
+ //
4753
+ // It also neatly avoids a situation where render() returns null
4754
+ // in the same tick for the source element, and browser freaks out.
4755
+ setTimeout(()=>this.actions.publishDragSource()
4756
+ , 0);
4757
+ } else {
4758
+ // In some cases the user may want to override this behavior, e.g.
4759
+ // to work around IE not supporting custom drag previews.
4760
+ //
4761
+ // When using a custom drag layer, the only way to prevent
4762
+ // the default drag preview from drawing in IE is to screenshot
4763
+ // the dragging state in which the node itself has zero opacity
4764
+ // and height. In this case, though, returning null from render()
4765
+ // will abruptly end the dragging, which is not obvious.
4766
+ //
4767
+ // This is the reason such behavior is strictly opt-in.
4768
+ this.actions.publishDragSource();
4769
+ }
4770
+ } else if (nativeType) {
4771
+ // A native item (such as URL) dragged from inside the document
4772
+ this.beginDragNativeItem(nativeType);
4773
+ } else if (dataTransfer && !dataTransfer.types && (e.target && !e.target.hasAttribute || !e.target.hasAttribute('draggable'))) {
4774
+ // Looks like a Safari bug: dataTransfer.types is null, but there was no draggable.
4775
+ // Just let it drag. It's a native type (URL or text) and will be picked up in
4776
+ // dragenter handler.
4777
+ return;
4778
+ } else {
4779
+ // If by this time no drag source reacted, tell browser not to drag.
4780
+ e.preventDefault();
4781
+ }
4782
+ };
4783
+ this.handleTopDragEndCapture = ()=>{
4784
+ if (this.clearCurrentDragSourceNode() && this.monitor.isDragging()) {
4785
+ // Firefox can dispatch this event in an infinite loop
4786
+ // if dragend handler does something like showing an alert.
4787
+ // Only proceed if we have not handled it already.
4788
+ this.actions.endDrag();
4789
+ }
4790
+ this.cancelHover();
4791
+ };
4792
+ this.handleTopDragEnterCapture = (e)=>{
4793
+ this.dragEnterTargetIds = [];
4794
+ if (this.isDraggingNativeItem()) {
4795
+ var ref;
4796
+ (ref = this.currentNativeSource) === null || ref === void 0 ? void 0 : ref.loadDataTransfer(e.dataTransfer);
4797
+ }
4798
+ const isFirstEnter = this.enterLeaveCounter.enter(e.target);
4799
+ if (!isFirstEnter || this.monitor.isDragging()) {
4800
+ return;
4801
+ }
4802
+ const { dataTransfer } = e;
4803
+ const nativeType = matchNativeItemType(dataTransfer);
4804
+ if (nativeType) {
4805
+ // A native item (such as file or URL) dragged from outside the document
4806
+ this.beginDragNativeItem(nativeType, dataTransfer);
4807
+ }
4808
+ };
4809
+ this.handleTopDragEnter = (e)=>{
4810
+ const { dragEnterTargetIds } = this;
4811
+ this.dragEnterTargetIds = [];
4812
+ if (!this.monitor.isDragging()) {
4813
+ // This is probably a native item type we don't understand.
4814
+ return;
4815
+ }
4816
+ this.altKeyPressed = e.altKey;
4817
+ // If the target changes position as the result of `dragenter`, `dragover` might still
4818
+ // get dispatched despite target being no longer there. The easy solution is to check
4819
+ // whether there actually is a target before firing `hover`.
4820
+ if (dragEnterTargetIds.length > 0) {
4821
+ this.actions.hover(dragEnterTargetIds, {
4822
+ clientOffset: getEventClientOffset(e)
4823
+ });
4824
+ }
4825
+ const canDrop = dragEnterTargetIds.some((targetId)=>this.monitor.canDropOnTarget(targetId)
4826
+ );
4827
+ if (canDrop) {
4828
+ // IE requires this to fire dragover events
4829
+ e.preventDefault();
4830
+ if (e.dataTransfer) {
4831
+ e.dataTransfer.dropEffect = this.getCurrentDropEffect();
4832
+ }
4833
+ }
4834
+ };
4835
+ this.handleTopDragOverCapture = (e)=>{
4836
+ this.dragOverTargetIds = [];
4837
+ if (this.isDraggingNativeItem()) {
4838
+ var ref;
4839
+ (ref = this.currentNativeSource) === null || ref === void 0 ? void 0 : ref.loadDataTransfer(e.dataTransfer);
4840
+ }
4841
+ };
4842
+ this.handleTopDragOver = (e)=>{
4843
+ const { dragOverTargetIds } = this;
4844
+ this.dragOverTargetIds = [];
4845
+ if (!this.monitor.isDragging()) {
4846
+ // This is probably a native item type we don't understand.
4847
+ // Prevent default "drop and blow away the whole document" action.
4848
+ e.preventDefault();
4849
+ if (e.dataTransfer) {
4850
+ e.dataTransfer.dropEffect = 'none';
4851
+ }
4852
+ return;
4853
+ }
4854
+ this.altKeyPressed = e.altKey;
4855
+ this.lastClientOffset = getEventClientOffset(e);
4856
+ this.scheduleHover(dragOverTargetIds);
4857
+ const canDrop = (dragOverTargetIds || []).some((targetId)=>this.monitor.canDropOnTarget(targetId)
4858
+ );
4859
+ if (canDrop) {
4860
+ // Show user-specified drop effect.
4861
+ e.preventDefault();
4862
+ if (e.dataTransfer) {
4863
+ e.dataTransfer.dropEffect = this.getCurrentDropEffect();
4864
+ }
4865
+ } else if (this.isDraggingNativeItem()) {
4866
+ // Don't show a nice cursor but still prevent default
4867
+ // "drop and blow away the whole document" action.
4868
+ e.preventDefault();
4869
+ } else {
4870
+ e.preventDefault();
4871
+ if (e.dataTransfer) {
4872
+ e.dataTransfer.dropEffect = 'none';
4873
+ }
4874
+ }
4875
+ };
4876
+ this.handleTopDragLeaveCapture = (e)=>{
4877
+ if (this.isDraggingNativeItem()) {
4878
+ e.preventDefault();
4879
+ }
4880
+ const isLastLeave = this.enterLeaveCounter.leave(e.target);
4881
+ if (!isLastLeave) {
4882
+ return;
4883
+ }
4884
+ if (this.isDraggingNativeItem()) {
4885
+ setTimeout(()=>this.endDragNativeItem()
4886
+ , 0);
4887
+ }
4888
+ this.cancelHover();
4889
+ };
4890
+ this.handleTopDropCapture = (e)=>{
4891
+ this.dropTargetIds = [];
4892
+ if (this.isDraggingNativeItem()) {
4893
+ var ref;
4894
+ e.preventDefault();
4895
+ (ref = this.currentNativeSource) === null || ref === void 0 ? void 0 : ref.loadDataTransfer(e.dataTransfer);
4896
+ } else if (matchNativeItemType(e.dataTransfer)) {
4897
+ // Dragging some elements, like <a> and <img> may still behave like a native drag event,
4898
+ // even if the current drag event matches a user-defined type.
4899
+ // Stop the default behavior when we're not expecting a native item to be dropped.
4900
+ e.preventDefault();
4901
+ }
4902
+ this.enterLeaveCounter.reset();
4903
+ };
4904
+ this.handleTopDrop = (e)=>{
4905
+ const { dropTargetIds } = this;
4906
+ this.dropTargetIds = [];
4907
+ this.actions.hover(dropTargetIds, {
4908
+ clientOffset: getEventClientOffset(e)
4909
+ });
4910
+ this.actions.drop({
4911
+ dropEffect: this.getCurrentDropEffect()
4912
+ });
4913
+ if (this.isDraggingNativeItem()) {
4914
+ this.endDragNativeItem();
4915
+ } else if (this.monitor.isDragging()) {
4916
+ this.actions.endDrag();
4917
+ }
4918
+ this.cancelHover();
4919
+ };
4920
+ this.handleSelectStart = (e)=>{
4921
+ const target = e.target;
4922
+ // Only IE requires us to explicitly say
4923
+ // we want drag drop operation to start
4924
+ if (typeof target.dragDrop !== 'function') {
4925
+ return;
4926
+ }
4927
+ // Inputs and textareas should be selectable
4928
+ if (target.tagName === 'INPUT' || target.tagName === 'SELECT' || target.tagName === 'TEXTAREA' || target.isContentEditable) {
4929
+ return;
4930
+ }
4931
+ // For other targets, ask IE
4932
+ // to enable drag and drop
4933
+ e.preventDefault();
4934
+ target.dragDrop();
4935
+ };
4936
+ this.options = new OptionsReader(globalContext, options);
4937
+ this.actions = manager.getActions();
4938
+ this.monitor = manager.getMonitor();
4939
+ this.registry = manager.getRegistry();
4940
+ this.enterLeaveCounter = new EnterLeaveCounter(this.isNodeInDocument);
4941
+ }
4942
+ }
4943
+
4944
+ const HTML5Backend = function createBackend(manager, context, options) {
4945
+ return new HTML5BackendImpl(manager, context, options);
4946
+ };
4947
+
1202
4948
  var _excluded = ["tableInstance"];
1203
4949
  var MRT_FullScreenToggleButton = function MRT_FullScreenToggleButton(_ref) {
1204
4950
  var tableInstance = _ref.tableInstance,
@@ -2364,7 +6110,7 @@ var MRT_DraggableTableHeadCell = function MRT_DraggableTableHeadCell(_ref) {
2364
6110
  setColumnOrder([].concat(columnOrder));
2365
6111
  };
2366
6112
 
2367
- var _useDrop = reactDnd.useDrop({
6113
+ var _useDrop = useDrop({
2368
6114
  accept: 'header',
2369
6115
  drop: function drop(item) {
2370
6116
  return reorder(item, header.index);
@@ -2372,7 +6118,7 @@ var MRT_DraggableTableHeadCell = function MRT_DraggableTableHeadCell(_ref) {
2372
6118
  }),
2373
6119
  drop = _useDrop[1];
2374
6120
 
2375
- var _useDrag = reactDnd.useDrag({
6121
+ var _useDrag = useDrag({
2376
6122
  collect: function collect(monitor) {
2377
6123
  return {
2378
6124
  isDragging: monitor.isDragging()
@@ -2929,7 +6675,7 @@ var MRT_Table = function MRT_Table(_ref) {
2929
6675
  }));
2930
6676
  };
2931
6677
 
2932
- var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
6678
+ var useIsomorphicLayoutEffect$1 = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
2933
6679
  var MRT_TableContainer = function MRT_TableContainer(_ref) {
2934
6680
  var tableInstance = _ref.tableInstance;
2935
6681
  var getState = tableInstance.getState,
@@ -2948,7 +6694,7 @@ var MRT_TableContainer = function MRT_TableContainer(_ref) {
2948
6694
  var tableContainerProps = muiTableContainerProps instanceof Function ? muiTableContainerProps({
2949
6695
  tableInstance: tableInstance
2950
6696
  }) : muiTableContainerProps;
2951
- useIsomorphicLayoutEffect(function () {
6697
+ useIsomorphicLayoutEffect$1(function () {
2952
6698
  var _document$getElementB, _document, _document$getElementB2, _document$getElementB3, _document2, _document2$getElement;
2953
6699
 
2954
6700
  var topToolbarHeight = typeof document !== 'undefined' ? (_document$getElementB = (_document = document) == null ? void 0 : (_document$getElementB2 = _document.getElementById("mrt-" + idPrefix + "-toolbar-top")) == null ? void 0 : _document$getElementB2.offsetHeight) != null ? _document$getElementB : 0 : 0;
@@ -2994,8 +6740,8 @@ var MRT_TablePaper = function MRT_TablePaper(_ref) {
2994
6740
  var tablePaperProps = muiTablePaperProps instanceof Function ? muiTablePaperProps({
2995
6741
  tableInstance: tableInstance
2996
6742
  }) : muiTablePaperProps;
2997
- return React__default.createElement(reactDnd.DndProvider, {
2998
- backend: reactDndHtml5Backend.HTML5Backend
6743
+ return React__default.createElement(DndProvider, {
6744
+ backend: HTML5Backend
2999
6745
  }, React__default.createElement(material.Paper, Object.assign({
3000
6746
  elevation: 2
3001
6747
  }, tablePaperProps, {