@agility/plenum-ui 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.esm.js +3156 -352
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +3155 -351
- package/lib/index.js.map +1 -1
- package/package.json +1 -1
package/lib/index.esm.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import React__default, { createContext, forwardRef, useEffect, useCallback, useMemo, useContext, useState, useRef, useReducer, createRef, Fragment, useLayoutEffect, isValidElement, cloneElement, createElement, useImperativeHandle } from 'react';
|
|
2
|
+
import React__default, { createContext, forwardRef, useEffect, useCallback, useMemo, useContext, useState, useRef, useReducer, createRef, Fragment, useLayoutEffect, isValidElement, cloneElement, createElement, memo, useImperativeHandle } from 'react';
|
|
3
3
|
import { createPortal } from 'react-dom';
|
|
4
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
5
|
|
|
5
6
|
var classnames = {exports: {}};
|
|
6
7
|
|
|
@@ -7199,430 +7200,1870 @@ function __spreadArray$1(to, from, pack) {
|
|
|
7199
7200
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
7200
7201
|
}
|
|
7201
7202
|
|
|
7202
|
-
|
|
7203
|
-
|
|
7204
|
-
|
|
7205
|
-
|
|
7206
|
-
|
|
7207
|
-
|
|
7208
|
-
|
|
7203
|
+
/**
|
|
7204
|
+
* Create the React Context
|
|
7205
|
+
*/ const DndContext = createContext({
|
|
7206
|
+
dragDropManager: undefined
|
|
7207
|
+
});
|
|
7208
|
+
|
|
7209
|
+
/**
|
|
7210
|
+
* Adapted from React: https://github.com/facebook/react/blob/master/packages/shared/formatProdErrorMessage.js
|
|
7211
|
+
*
|
|
7212
|
+
* Do not require this module directly! Use normal throw error calls. These messages will be replaced with error codes
|
|
7213
|
+
* during build.
|
|
7214
|
+
* @param {number} code
|
|
7215
|
+
*/
|
|
7216
|
+
function formatProdErrorMessage(code) {
|
|
7217
|
+
return "Minified Redux error #" + code + "; visit https://redux.js.org/Errors?code=" + code + " for the full message or " + 'use the non-minified dev environment for full errors. ';
|
|
7209
7218
|
}
|
|
7210
7219
|
|
|
7211
|
-
|
|
7220
|
+
// Inlined version of the `symbol-observable` polyfill
|
|
7221
|
+
var $$observable = (function () {
|
|
7222
|
+
return typeof Symbol === 'function' && Symbol.observable || '@@observable';
|
|
7223
|
+
})();
|
|
7212
7224
|
|
|
7213
|
-
|
|
7225
|
+
/**
|
|
7226
|
+
* These are private action types reserved by Redux.
|
|
7227
|
+
* For any unknown actions, you must return the current state.
|
|
7228
|
+
* If the current state is undefined, you must return the initial state.
|
|
7229
|
+
* Do not reference these action types directly in your code.
|
|
7230
|
+
*/
|
|
7231
|
+
var randomString = function randomString() {
|
|
7232
|
+
return Math.random().toString(36).substring(7).split('').join('.');
|
|
7233
|
+
};
|
|
7214
7234
|
|
|
7215
|
-
|
|
7235
|
+
var ActionTypes = {
|
|
7236
|
+
INIT: "@@redux/INIT" + randomString(),
|
|
7237
|
+
REPLACE: "@@redux/REPLACE" + randomString(),
|
|
7238
|
+
PROBE_UNKNOWN_ACTION: function PROBE_UNKNOWN_ACTION() {
|
|
7239
|
+
return "@@redux/PROBE_UNKNOWN_ACTION" + randomString();
|
|
7240
|
+
}
|
|
7241
|
+
};
|
|
7216
7242
|
|
|
7217
|
-
|
|
7243
|
+
/**
|
|
7244
|
+
* @param {any} obj The object to inspect.
|
|
7245
|
+
* @returns {boolean} True if the argument appears to be a plain object.
|
|
7246
|
+
*/
|
|
7247
|
+
function isPlainObject(obj) {
|
|
7248
|
+
if (typeof obj !== 'object' || obj === null) return false;
|
|
7249
|
+
var proto = obj;
|
|
7218
7250
|
|
|
7219
|
-
|
|
7251
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
7252
|
+
proto = Object.getPrototypeOf(proto);
|
|
7253
|
+
}
|
|
7220
7254
|
|
|
7221
|
-
|
|
7255
|
+
return Object.getPrototypeOf(obj) === proto;
|
|
7256
|
+
}
|
|
7222
7257
|
|
|
7223
|
-
|
|
7258
|
+
// Inlined / shortened version of `kindOf` from https://github.com/jonschlinkert/kind-of
|
|
7259
|
+
function miniKindOf(val) {
|
|
7260
|
+
if (val === void 0) return 'undefined';
|
|
7261
|
+
if (val === null) return 'null';
|
|
7262
|
+
var type = typeof val;
|
|
7224
7263
|
|
|
7225
|
-
|
|
7264
|
+
switch (type) {
|
|
7265
|
+
case 'boolean':
|
|
7266
|
+
case 'string':
|
|
7267
|
+
case 'number':
|
|
7268
|
+
case 'symbol':
|
|
7269
|
+
case 'function':
|
|
7270
|
+
{
|
|
7271
|
+
return type;
|
|
7272
|
+
}
|
|
7273
|
+
}
|
|
7226
7274
|
|
|
7227
|
-
|
|
7275
|
+
if (Array.isArray(val)) return 'array';
|
|
7276
|
+
if (isDate(val)) return 'date';
|
|
7277
|
+
if (isError(val)) return 'error';
|
|
7278
|
+
var constructorName = ctorName(val);
|
|
7228
7279
|
|
|
7229
|
-
|
|
7280
|
+
switch (constructorName) {
|
|
7281
|
+
case 'Symbol':
|
|
7282
|
+
case 'Promise':
|
|
7283
|
+
case 'WeakMap':
|
|
7284
|
+
case 'WeakSet':
|
|
7285
|
+
case 'Map':
|
|
7286
|
+
case 'Set':
|
|
7287
|
+
return constructorName;
|
|
7288
|
+
} // other
|
|
7230
7289
|
|
|
7231
|
-
var _previews$1 = new WeakMap();
|
|
7232
7290
|
|
|
7233
|
-
|
|
7234
|
-
|
|
7235
|
-
function PreviewListImpl() {
|
|
7236
|
-
var _this = this;
|
|
7291
|
+
return type.slice(8, -1).toLowerCase().replace(/\s/g, '');
|
|
7292
|
+
}
|
|
7237
7293
|
|
|
7238
|
-
|
|
7294
|
+
function ctorName(val) {
|
|
7295
|
+
return typeof val.constructor === 'function' ? val.constructor.name : null;
|
|
7296
|
+
}
|
|
7239
7297
|
|
|
7240
|
-
|
|
7241
|
-
|
|
7242
|
-
|
|
7243
|
-
});
|
|
7298
|
+
function isError(val) {
|
|
7299
|
+
return val instanceof Error || typeof val.message === 'string' && val.constructor && typeof val.constructor.stackTraceLimit === 'number';
|
|
7300
|
+
}
|
|
7244
7301
|
|
|
7245
|
-
|
|
7246
|
-
|
|
7247
|
-
|
|
7302
|
+
function isDate(val) {
|
|
7303
|
+
if (val instanceof Date) return true;
|
|
7304
|
+
return typeof val.toDateString === 'function' && typeof val.getDate === 'function' && typeof val.setDate === 'function';
|
|
7305
|
+
}
|
|
7248
7306
|
|
|
7249
|
-
|
|
7250
|
-
|
|
7307
|
+
function kindOf(val) {
|
|
7308
|
+
var typeOfVal = typeof val;
|
|
7251
7309
|
|
|
7252
|
-
|
|
7253
|
-
|
|
7254
|
-
|
|
7255
|
-
});
|
|
7310
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
7311
|
+
typeOfVal = miniKindOf(val);
|
|
7312
|
+
}
|
|
7256
7313
|
|
|
7257
|
-
|
|
7258
|
-
|
|
7259
|
-
_step;
|
|
7314
|
+
return typeOfVal;
|
|
7315
|
+
}
|
|
7260
7316
|
|
|
7261
|
-
|
|
7262
|
-
|
|
7263
|
-
|
|
7264
|
-
|
|
7265
|
-
|
|
7266
|
-
|
|
7267
|
-
|
|
7268
|
-
|
|
7269
|
-
|
|
7270
|
-
|
|
7271
|
-
|
|
7317
|
+
/**
|
|
7318
|
+
* @deprecated
|
|
7319
|
+
*
|
|
7320
|
+
* **We recommend using the `configureStore` method
|
|
7321
|
+
* of the `@reduxjs/toolkit` package**, which replaces `createStore`.
|
|
7322
|
+
*
|
|
7323
|
+
* Redux Toolkit is our recommended approach for writing Redux logic today,
|
|
7324
|
+
* including store setup, reducers, data fetching, and more.
|
|
7325
|
+
*
|
|
7326
|
+
* **For more details, please read this Redux docs page:**
|
|
7327
|
+
* **https://redux.js.org/introduction/why-rtk-is-redux-today**
|
|
7328
|
+
*
|
|
7329
|
+
* `configureStore` from Redux Toolkit is an improved version of `createStore` that
|
|
7330
|
+
* simplifies setup and helps avoid common bugs.
|
|
7331
|
+
*
|
|
7332
|
+
* You should not be using the `redux` core package by itself today, except for learning purposes.
|
|
7333
|
+
* The `createStore` method from the core `redux` package will not be removed, but we encourage
|
|
7334
|
+
* all users to migrate to using Redux Toolkit for all Redux code.
|
|
7335
|
+
*
|
|
7336
|
+
* If you want to use `createStore` without this visual deprecation warning, use
|
|
7337
|
+
* the `legacy_createStore` import instead:
|
|
7338
|
+
*
|
|
7339
|
+
* `import { legacy_createStore as createStore} from 'redux'`
|
|
7340
|
+
*
|
|
7341
|
+
*/
|
|
7272
7342
|
|
|
7273
|
-
|
|
7274
|
-
|
|
7343
|
+
function createStore(reducer, preloadedState, enhancer) {
|
|
7344
|
+
var _ref2;
|
|
7275
7345
|
|
|
7276
|
-
|
|
7346
|
+
if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') {
|
|
7347
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(0) : '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.');
|
|
7348
|
+
}
|
|
7277
7349
|
|
|
7278
|
-
|
|
7350
|
+
if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {
|
|
7351
|
+
enhancer = preloadedState;
|
|
7352
|
+
preloadedState = undefined;
|
|
7353
|
+
}
|
|
7279
7354
|
|
|
7280
|
-
|
|
7355
|
+
if (typeof enhancer !== 'undefined') {
|
|
7356
|
+
if (typeof enhancer !== 'function') {
|
|
7357
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(1) : "Expected the enhancer to be a function. Instead, received: '" + kindOf(enhancer) + "'");
|
|
7358
|
+
}
|
|
7281
7359
|
|
|
7282
|
-
|
|
7360
|
+
return enhancer(createStore)(reducer, preloadedState);
|
|
7361
|
+
}
|
|
7283
7362
|
|
|
7284
|
-
|
|
7363
|
+
if (typeof reducer !== 'function') {
|
|
7364
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(2) : "Expected the root reducer to be a function. Instead, received: '" + kindOf(reducer) + "'");
|
|
7365
|
+
}
|
|
7285
7366
|
|
|
7286
|
-
|
|
7367
|
+
var currentReducer = reducer;
|
|
7368
|
+
var currentState = preloadedState;
|
|
7369
|
+
var currentListeners = [];
|
|
7370
|
+
var nextListeners = currentListeners;
|
|
7371
|
+
var isDispatching = false;
|
|
7372
|
+
/**
|
|
7373
|
+
* This makes a shallow copy of currentListeners so we can use
|
|
7374
|
+
* nextListeners as a temporary list while dispatching.
|
|
7375
|
+
*
|
|
7376
|
+
* This prevents any bugs around consumers calling
|
|
7377
|
+
* subscribe/unsubscribe in the middle of a dispatch.
|
|
7378
|
+
*/
|
|
7379
|
+
|
|
7380
|
+
function ensureCanMutateNextListeners() {
|
|
7381
|
+
if (nextListeners === currentListeners) {
|
|
7382
|
+
nextListeners = currentListeners.slice();
|
|
7383
|
+
}
|
|
7384
|
+
}
|
|
7385
|
+
/**
|
|
7386
|
+
* Reads the state tree managed by the store.
|
|
7387
|
+
*
|
|
7388
|
+
* @returns {any} The current state tree of your application.
|
|
7389
|
+
*/
|
|
7287
7390
|
|
|
7288
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
7289
7391
|
|
|
7290
|
-
function
|
|
7392
|
+
function getState() {
|
|
7393
|
+
if (isDispatching) {
|
|
7394
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(3) : '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.');
|
|
7395
|
+
}
|
|
7291
7396
|
|
|
7292
|
-
|
|
7397
|
+
return currentState;
|
|
7398
|
+
}
|
|
7399
|
+
/**
|
|
7400
|
+
* Adds a change listener. It will be called any time an action is dispatched,
|
|
7401
|
+
* and some part of the state tree may potentially have changed. You may then
|
|
7402
|
+
* call `getState()` to read the current state tree inside the callback.
|
|
7403
|
+
*
|
|
7404
|
+
* You may call `dispatch()` from a change listener, with the following
|
|
7405
|
+
* caveats:
|
|
7406
|
+
*
|
|
7407
|
+
* 1. The subscriptions are snapshotted just before every `dispatch()` call.
|
|
7408
|
+
* If you subscribe or unsubscribe while the listeners are being invoked, this
|
|
7409
|
+
* will not have any effect on the `dispatch()` that is currently in progress.
|
|
7410
|
+
* However, the next `dispatch()` call, whether nested or not, will use a more
|
|
7411
|
+
* recent snapshot of the subscription list.
|
|
7412
|
+
*
|
|
7413
|
+
* 2. The listener should not expect to see all state changes, as the state
|
|
7414
|
+
* might have been updated multiple times during a nested `dispatch()` before
|
|
7415
|
+
* the listener is called. It is, however, guaranteed that all subscribers
|
|
7416
|
+
* registered before the `dispatch()` started will be called with the latest
|
|
7417
|
+
* state by the time it exits.
|
|
7418
|
+
*
|
|
7419
|
+
* @param {Function} listener A callback to be invoked on every dispatch.
|
|
7420
|
+
* @returns {Function} A function to remove this change listener.
|
|
7421
|
+
*/
|
|
7422
|
+
|
|
7423
|
+
|
|
7424
|
+
function subscribe(listener) {
|
|
7425
|
+
if (typeof listener !== 'function') {
|
|
7426
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(4) : "Expected the listener to be a function. Instead, received: '" + kindOf(listener) + "'");
|
|
7427
|
+
}
|
|
7428
|
+
|
|
7429
|
+
if (isDispatching) {
|
|
7430
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(5) : '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.');
|
|
7431
|
+
}
|
|
7432
|
+
|
|
7433
|
+
var isSubscribed = true;
|
|
7434
|
+
ensureCanMutateNextListeners();
|
|
7435
|
+
nextListeners.push(listener);
|
|
7436
|
+
return function unsubscribe() {
|
|
7437
|
+
if (!isSubscribed) {
|
|
7438
|
+
return;
|
|
7439
|
+
}
|
|
7293
7440
|
|
|
7294
|
-
|
|
7441
|
+
if (isDispatching) {
|
|
7442
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(6) : 'You may not unsubscribe from a store listener while the reducer is executing. ' + 'See https://redux.js.org/api/store#subscribelistener for more details.');
|
|
7443
|
+
}
|
|
7295
7444
|
|
|
7296
|
-
|
|
7445
|
+
isSubscribed = false;
|
|
7446
|
+
ensureCanMutateNextListeners();
|
|
7447
|
+
var index = nextListeners.indexOf(listener);
|
|
7448
|
+
nextListeners.splice(index, 1);
|
|
7449
|
+
currentListeners = null;
|
|
7450
|
+
};
|
|
7451
|
+
}
|
|
7452
|
+
/**
|
|
7453
|
+
* Dispatches an action. It is the only way to trigger a state change.
|
|
7454
|
+
*
|
|
7455
|
+
* The `reducer` function, used to create the store, will be called with the
|
|
7456
|
+
* current state tree and the given `action`. Its return value will
|
|
7457
|
+
* be considered the **next** state of the tree, and the change listeners
|
|
7458
|
+
* will be notified.
|
|
7459
|
+
*
|
|
7460
|
+
* The base implementation only supports plain object actions. If you want to
|
|
7461
|
+
* dispatch a Promise, an Observable, a thunk, or something else, you need to
|
|
7462
|
+
* wrap your store creating function into the corresponding middleware. For
|
|
7463
|
+
* example, see the documentation for the `redux-thunk` package. Even the
|
|
7464
|
+
* middleware will eventually dispatch plain object actions using this method.
|
|
7465
|
+
*
|
|
7466
|
+
* @param {Object} action A plain object representing “what changed”. It is
|
|
7467
|
+
* a good idea to keep actions serializable so you can record and replay user
|
|
7468
|
+
* sessions, or use the time travelling `redux-devtools`. An action must have
|
|
7469
|
+
* a `type` property which may not be `undefined`. It is a good idea to use
|
|
7470
|
+
* string constants for action types.
|
|
7471
|
+
*
|
|
7472
|
+
* @returns {Object} For convenience, the same action object you dispatched.
|
|
7473
|
+
*
|
|
7474
|
+
* Note that, if you use a custom middleware, it may wrap `dispatch()` to
|
|
7475
|
+
* return something else (for example, a Promise you can await).
|
|
7476
|
+
*/
|
|
7477
|
+
|
|
7478
|
+
|
|
7479
|
+
function dispatch(action) {
|
|
7480
|
+
if (!isPlainObject(action)) {
|
|
7481
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(7) : "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.");
|
|
7482
|
+
}
|
|
7483
|
+
|
|
7484
|
+
if (typeof action.type === 'undefined') {
|
|
7485
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(8) : 'Actions may not have an undefined "type" property. You may have misspelled an action type string constant.');
|
|
7486
|
+
}
|
|
7487
|
+
|
|
7488
|
+
if (isDispatching) {
|
|
7489
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(9) : 'Reducers may not dispatch actions.');
|
|
7490
|
+
}
|
|
7297
7491
|
|
|
7298
|
-
|
|
7492
|
+
try {
|
|
7493
|
+
isDispatching = true;
|
|
7494
|
+
currentState = currentReducer(currentState, action);
|
|
7495
|
+
} finally {
|
|
7496
|
+
isDispatching = false;
|
|
7497
|
+
}
|
|
7299
7498
|
|
|
7300
|
-
|
|
7499
|
+
var listeners = currentListeners = nextListeners;
|
|
7301
7500
|
|
|
7302
|
-
var
|
|
7501
|
+
for (var i = 0; i < listeners.length; i++) {
|
|
7502
|
+
var listener = listeners[i];
|
|
7503
|
+
listener();
|
|
7504
|
+
}
|
|
7303
7505
|
|
|
7304
|
-
|
|
7506
|
+
return action;
|
|
7507
|
+
}
|
|
7508
|
+
/**
|
|
7509
|
+
* Replaces the reducer currently used by the store to calculate the state.
|
|
7510
|
+
*
|
|
7511
|
+
* You might need this if your app implements code splitting and you want to
|
|
7512
|
+
* load some of the reducers dynamically. You might also need this if you
|
|
7513
|
+
* implement a hot reloading mechanism for Redux.
|
|
7514
|
+
*
|
|
7515
|
+
* @param {Function} nextReducer The reducer for the store to use instead.
|
|
7516
|
+
* @returns {void}
|
|
7517
|
+
*/
|
|
7518
|
+
|
|
7519
|
+
|
|
7520
|
+
function replaceReducer(nextReducer) {
|
|
7521
|
+
if (typeof nextReducer !== 'function') {
|
|
7522
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(10) : "Expected the nextReducer to be a function. Instead, received: '" + kindOf(nextReducer));
|
|
7523
|
+
}
|
|
7524
|
+
|
|
7525
|
+
currentReducer = nextReducer; // This action has a similiar effect to ActionTypes.INIT.
|
|
7526
|
+
// Any reducers that existed in both the new and old rootReducer
|
|
7527
|
+
// will receive the previous state. This effectively populates
|
|
7528
|
+
// the new state tree with any relevant data from the old one.
|
|
7529
|
+
|
|
7530
|
+
dispatch({
|
|
7531
|
+
type: ActionTypes.REPLACE
|
|
7532
|
+
});
|
|
7533
|
+
}
|
|
7534
|
+
/**
|
|
7535
|
+
* Interoperability point for observable/reactive libraries.
|
|
7536
|
+
* @returns {observable} A minimal observable of state changes.
|
|
7537
|
+
* For more information, see the observable proposal:
|
|
7538
|
+
* https://github.com/tc39/proposal-observable
|
|
7539
|
+
*/
|
|
7540
|
+
|
|
7541
|
+
|
|
7542
|
+
function observable() {
|
|
7543
|
+
var _ref;
|
|
7544
|
+
|
|
7545
|
+
var outerSubscribe = subscribe;
|
|
7546
|
+
return _ref = {
|
|
7547
|
+
/**
|
|
7548
|
+
* The minimal observable subscription method.
|
|
7549
|
+
* @param {Object} observer Any object that can be used as an observer.
|
|
7550
|
+
* The observer object should have a `next` method.
|
|
7551
|
+
* @returns {subscription} An object with an `unsubscribe` method that can
|
|
7552
|
+
* be used to unsubscribe the observable from the store, and prevent further
|
|
7553
|
+
* emission of values from the observable.
|
|
7554
|
+
*/
|
|
7555
|
+
subscribe: function subscribe(observer) {
|
|
7556
|
+
if (typeof observer !== 'object' || observer === null) {
|
|
7557
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(11) : "Expected the observer to be an object. Instead, received: '" + kindOf(observer) + "'");
|
|
7558
|
+
}
|
|
7305
7559
|
|
|
7306
|
-
|
|
7560
|
+
function observeState() {
|
|
7561
|
+
if (observer.next) {
|
|
7562
|
+
observer.next(getState());
|
|
7563
|
+
}
|
|
7564
|
+
}
|
|
7307
7565
|
|
|
7308
|
-
|
|
7566
|
+
observeState();
|
|
7567
|
+
var unsubscribe = outerSubscribe(observeState);
|
|
7568
|
+
return {
|
|
7569
|
+
unsubscribe: unsubscribe
|
|
7570
|
+
};
|
|
7571
|
+
}
|
|
7572
|
+
}, _ref[$$observable] = function () {
|
|
7573
|
+
return this;
|
|
7574
|
+
}, _ref;
|
|
7575
|
+
} // When a store is created, an "INIT" action is dispatched so that every
|
|
7576
|
+
// reducer returns their initial state. This effectively populates
|
|
7577
|
+
// the initial state tree.
|
|
7309
7578
|
|
|
7310
|
-
var _nodes = new WeakMap();
|
|
7311
7579
|
|
|
7312
|
-
|
|
7580
|
+
dispatch({
|
|
7581
|
+
type: ActionTypes.INIT
|
|
7582
|
+
});
|
|
7583
|
+
return _ref2 = {
|
|
7584
|
+
dispatch: dispatch,
|
|
7585
|
+
subscribe: subscribe,
|
|
7586
|
+
getState: getState,
|
|
7587
|
+
replaceReducer: replaceReducer
|
|
7588
|
+
}, _ref2[$$observable] = observable, _ref2;
|
|
7589
|
+
}
|
|
7313
7590
|
|
|
7314
|
-
|
|
7591
|
+
/**
|
|
7592
|
+
* Prints a warning in the console if it exists.
|
|
7593
|
+
*
|
|
7594
|
+
* @param {String} message The warning message.
|
|
7595
|
+
* @returns {void}
|
|
7596
|
+
*/
|
|
7597
|
+
function warning(message) {
|
|
7598
|
+
/* eslint-disable no-console */
|
|
7599
|
+
if (typeof console !== 'undefined' && typeof console.error === 'function') {
|
|
7600
|
+
console.error(message);
|
|
7601
|
+
}
|
|
7602
|
+
/* eslint-enable no-console */
|
|
7315
7603
|
|
|
7316
|
-
var _removeEventListeners = new WeakMap();
|
|
7317
7604
|
|
|
7318
|
-
|
|
7605
|
+
try {
|
|
7606
|
+
// This error was thrown as a convenience so that if you enable
|
|
7607
|
+
// "break on all exceptions" in your console,
|
|
7608
|
+
// it would pause the execution at this line.
|
|
7609
|
+
throw new Error(message);
|
|
7610
|
+
} catch (e) {} // eslint-disable-line no-empty
|
|
7319
7611
|
|
|
7320
|
-
|
|
7612
|
+
}
|
|
7321
7613
|
|
|
7322
|
-
|
|
7614
|
+
/*
|
|
7615
|
+
* This is a dummy function to check if the function name has been altered by minification.
|
|
7616
|
+
* If the function has been minified and NODE_ENV !== 'production', warn the user.
|
|
7617
|
+
*/
|
|
7323
7618
|
|
|
7324
|
-
|
|
7325
|
-
/*private*/
|
|
7619
|
+
function isCrushed() {}
|
|
7326
7620
|
|
|
7327
|
-
|
|
7621
|
+
if (process.env.NODE_ENV !== 'production' && typeof isCrushed.name === 'string' && isCrushed.name !== 'isCrushed') {
|
|
7622
|
+
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.');
|
|
7623
|
+
}
|
|
7328
7624
|
|
|
7329
|
-
|
|
7625
|
+
/**
|
|
7626
|
+
* Use invariant() to assert state which your program assumes to be true.
|
|
7627
|
+
*
|
|
7628
|
+
* Provide sprintf-style format (only %s is supported) and arguments
|
|
7629
|
+
* to provide information about what broke and what you were
|
|
7630
|
+
* expecting.
|
|
7631
|
+
*
|
|
7632
|
+
* The invariant message will be stripped in production, but the invariant
|
|
7633
|
+
* will remain to ensure logic does not differ in production.
|
|
7634
|
+
*/ function invariant(condition, format, ...args) {
|
|
7635
|
+
if (isProduction()) {
|
|
7636
|
+
if (format === undefined) {
|
|
7637
|
+
throw new Error('invariant requires an error message argument');
|
|
7638
|
+
}
|
|
7639
|
+
}
|
|
7640
|
+
if (!condition) {
|
|
7641
|
+
let error;
|
|
7642
|
+
if (format === undefined) {
|
|
7643
|
+
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
|
|
7644
|
+
} else {
|
|
7645
|
+
let argIndex = 0;
|
|
7646
|
+
error = new Error(format.replace(/%s/g, function() {
|
|
7647
|
+
return args[argIndex++];
|
|
7648
|
+
}));
|
|
7649
|
+
error.name = 'Invariant Violation';
|
|
7650
|
+
}
|
|
7651
|
+
error.framesToPop = 1 // we don't care about invariant's own frame
|
|
7652
|
+
;
|
|
7653
|
+
throw error;
|
|
7654
|
+
}
|
|
7655
|
+
}
|
|
7656
|
+
function isProduction() {
|
|
7657
|
+
return typeof process !== 'undefined' && process.env['NODE_ENV'] === 'production';
|
|
7658
|
+
}
|
|
7330
7659
|
|
|
7331
|
-
|
|
7660
|
+
// cheap lodash replacements
|
|
7661
|
+
/**
|
|
7662
|
+
* drop-in replacement for _.get
|
|
7663
|
+
* @param obj
|
|
7664
|
+
* @param path
|
|
7665
|
+
* @param defaultValue
|
|
7666
|
+
*/ function get(obj, path, defaultValue) {
|
|
7667
|
+
return path.split('.').reduce((a, c)=>a && a[c] ? a[c] : defaultValue || null
|
|
7668
|
+
, obj);
|
|
7669
|
+
}
|
|
7670
|
+
/**
|
|
7671
|
+
* drop-in replacement for _.without
|
|
7672
|
+
*/ function without$1(items, item) {
|
|
7673
|
+
return items.filter((i)=>i !== item
|
|
7674
|
+
);
|
|
7675
|
+
}
|
|
7676
|
+
/**
|
|
7677
|
+
* drop-in replacement for _.isString
|
|
7678
|
+
* @param input
|
|
7679
|
+
*/ function isObject(input) {
|
|
7680
|
+
return typeof input === 'object';
|
|
7681
|
+
}
|
|
7682
|
+
/**
|
|
7683
|
+
* replacement for _.xor
|
|
7684
|
+
* @param itemsA
|
|
7685
|
+
* @param itemsB
|
|
7686
|
+
*/ function xor(itemsA, itemsB) {
|
|
7687
|
+
const map = new Map();
|
|
7688
|
+
const insertItem = (item)=>{
|
|
7689
|
+
map.set(item, map.has(item) ? map.get(item) + 1 : 1);
|
|
7690
|
+
};
|
|
7691
|
+
itemsA.forEach(insertItem);
|
|
7692
|
+
itemsB.forEach(insertItem);
|
|
7693
|
+
const result = [];
|
|
7694
|
+
map.forEach((count, key)=>{
|
|
7695
|
+
if (count === 1) {
|
|
7696
|
+
result.push(key);
|
|
7697
|
+
}
|
|
7698
|
+
});
|
|
7699
|
+
return result;
|
|
7700
|
+
}
|
|
7701
|
+
/**
|
|
7702
|
+
* replacement for _.intersection
|
|
7703
|
+
* @param itemsA
|
|
7704
|
+
* @param itemsB
|
|
7705
|
+
*/ function intersection(itemsA, itemsB) {
|
|
7706
|
+
return itemsA.filter((t)=>itemsB.indexOf(t) > -1
|
|
7707
|
+
);
|
|
7708
|
+
}
|
|
7332
7709
|
|
|
7333
|
-
|
|
7334
|
-
|
|
7335
|
-
|
|
7710
|
+
const INIT_COORDS = 'dnd-core/INIT_COORDS';
|
|
7711
|
+
const BEGIN_DRAG = 'dnd-core/BEGIN_DRAG';
|
|
7712
|
+
const PUBLISH_DRAG_SOURCE = 'dnd-core/PUBLISH_DRAG_SOURCE';
|
|
7713
|
+
const HOVER = 'dnd-core/HOVER';
|
|
7714
|
+
const DROP = 'dnd-core/DROP';
|
|
7715
|
+
const END_DRAG = 'dnd-core/END_DRAG';
|
|
7336
7716
|
|
|
7337
|
-
|
|
7717
|
+
function setClientOffset(clientOffset, sourceClientOffset) {
|
|
7718
|
+
return {
|
|
7719
|
+
type: INIT_COORDS,
|
|
7720
|
+
payload: {
|
|
7721
|
+
sourceClientOffset: sourceClientOffset || null,
|
|
7722
|
+
clientOffset: clientOffset || null
|
|
7723
|
+
}
|
|
7724
|
+
};
|
|
7725
|
+
}
|
|
7338
7726
|
|
|
7339
|
-
|
|
7340
|
-
|
|
7341
|
-
|
|
7342
|
-
|
|
7727
|
+
const ResetCoordinatesAction = {
|
|
7728
|
+
type: INIT_COORDS,
|
|
7729
|
+
payload: {
|
|
7730
|
+
clientOffset: null,
|
|
7731
|
+
sourceClientOffset: null
|
|
7732
|
+
}
|
|
7733
|
+
};
|
|
7734
|
+
function createBeginDrag(manager) {
|
|
7735
|
+
return function beginDrag(sourceIds = [], options = {
|
|
7736
|
+
publishSource: true
|
|
7737
|
+
}) {
|
|
7738
|
+
const { publishSource =true , clientOffset , getSourceClientOffset , } = options;
|
|
7739
|
+
const monitor = manager.getMonitor();
|
|
7740
|
+
const registry = manager.getRegistry();
|
|
7741
|
+
// Initialize the coordinates using the client offset
|
|
7742
|
+
manager.dispatch(setClientOffset(clientOffset));
|
|
7743
|
+
verifyInvariants$1(sourceIds, monitor, registry);
|
|
7744
|
+
// Get the draggable source
|
|
7745
|
+
const sourceId = getDraggableSource(sourceIds, monitor);
|
|
7746
|
+
if (sourceId == null) {
|
|
7747
|
+
manager.dispatch(ResetCoordinatesAction);
|
|
7748
|
+
return;
|
|
7749
|
+
}
|
|
7750
|
+
// Get the source client offset
|
|
7751
|
+
let sourceClientOffset = null;
|
|
7752
|
+
if (clientOffset) {
|
|
7753
|
+
if (!getSourceClientOffset) {
|
|
7754
|
+
throw new Error('getSourceClientOffset must be defined');
|
|
7755
|
+
}
|
|
7756
|
+
verifyGetSourceClientOffsetIsFunction(getSourceClientOffset);
|
|
7757
|
+
sourceClientOffset = getSourceClientOffset(sourceId);
|
|
7758
|
+
}
|
|
7759
|
+
// Initialize the full coordinates
|
|
7760
|
+
manager.dispatch(setClientOffset(clientOffset, sourceClientOffset));
|
|
7761
|
+
const source = registry.getSource(sourceId);
|
|
7762
|
+
const item = source.beginDrag(monitor, sourceId);
|
|
7763
|
+
// If source.beginDrag returns null, this is an indicator to cancel the drag
|
|
7764
|
+
if (item == null) {
|
|
7765
|
+
return undefined;
|
|
7766
|
+
}
|
|
7767
|
+
verifyItemIsObject(item);
|
|
7768
|
+
registry.pinSource(sourceId);
|
|
7769
|
+
const itemType = registry.getSourceType(sourceId);
|
|
7770
|
+
return {
|
|
7771
|
+
type: BEGIN_DRAG,
|
|
7772
|
+
payload: {
|
|
7773
|
+
itemType,
|
|
7774
|
+
item,
|
|
7775
|
+
sourceId,
|
|
7776
|
+
clientOffset: clientOffset || null,
|
|
7777
|
+
sourceClientOffset: sourceClientOffset || null,
|
|
7778
|
+
isSourcePublic: !!publishSource
|
|
7779
|
+
}
|
|
7780
|
+
};
|
|
7781
|
+
};
|
|
7782
|
+
}
|
|
7783
|
+
function verifyInvariants$1(sourceIds, monitor, registry) {
|
|
7784
|
+
invariant(!monitor.isDragging(), 'Cannot call beginDrag while dragging.');
|
|
7785
|
+
sourceIds.forEach(function(sourceId) {
|
|
7786
|
+
invariant(registry.getSource(sourceId), 'Expected sourceIds to be registered.');
|
|
7787
|
+
});
|
|
7788
|
+
}
|
|
7789
|
+
function verifyGetSourceClientOffsetIsFunction(getSourceClientOffset) {
|
|
7790
|
+
invariant(typeof getSourceClientOffset === 'function', 'When clientOffset is provided, getSourceClientOffset must be a function.');
|
|
7791
|
+
}
|
|
7792
|
+
function verifyItemIsObject(item) {
|
|
7793
|
+
invariant(isObject(item), 'Item must be an object.');
|
|
7794
|
+
}
|
|
7795
|
+
function getDraggableSource(sourceIds, monitor) {
|
|
7796
|
+
let sourceId = null;
|
|
7797
|
+
for(let i = sourceIds.length - 1; i >= 0; i--){
|
|
7798
|
+
if (monitor.canDragSource(sourceIds[i])) {
|
|
7799
|
+
sourceId = sourceIds[i];
|
|
7800
|
+
break;
|
|
7801
|
+
}
|
|
7802
|
+
}
|
|
7803
|
+
return sourceId;
|
|
7804
|
+
}
|
|
7343
7805
|
|
|
7344
|
-
|
|
7345
|
-
|
|
7346
|
-
|
|
7347
|
-
|
|
7806
|
+
function _defineProperty$6(obj, key, value) {
|
|
7807
|
+
if (key in obj) {
|
|
7808
|
+
Object.defineProperty(obj, key, {
|
|
7809
|
+
value: value,
|
|
7810
|
+
enumerable: true,
|
|
7811
|
+
configurable: true,
|
|
7812
|
+
writable: true
|
|
7813
|
+
});
|
|
7814
|
+
} else {
|
|
7815
|
+
obj[key] = value;
|
|
7816
|
+
}
|
|
7817
|
+
return obj;
|
|
7818
|
+
}
|
|
7819
|
+
function _objectSpread$4(target) {
|
|
7820
|
+
for(var i = 1; i < arguments.length; i++){
|
|
7821
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
7822
|
+
var ownKeys = Object.keys(source);
|
|
7823
|
+
if (typeof Object.getOwnPropertySymbols === 'function') {
|
|
7824
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
7825
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
7826
|
+
}));
|
|
7827
|
+
}
|
|
7828
|
+
ownKeys.forEach(function(key) {
|
|
7829
|
+
_defineProperty$6(target, key, source[key]);
|
|
7830
|
+
});
|
|
7831
|
+
}
|
|
7832
|
+
return target;
|
|
7833
|
+
}
|
|
7834
|
+
function createDrop(manager) {
|
|
7835
|
+
return function drop(options = {}) {
|
|
7836
|
+
const monitor = manager.getMonitor();
|
|
7837
|
+
const registry = manager.getRegistry();
|
|
7838
|
+
verifyInvariants(monitor);
|
|
7839
|
+
const targetIds = getDroppableTargets(monitor);
|
|
7840
|
+
// Multiple actions are dispatched here, which is why this doesn't return an action
|
|
7841
|
+
targetIds.forEach((targetId, index)=>{
|
|
7842
|
+
const dropResult = determineDropResult(targetId, index, registry, monitor);
|
|
7843
|
+
const action = {
|
|
7844
|
+
type: DROP,
|
|
7845
|
+
payload: {
|
|
7846
|
+
dropResult: _objectSpread$4({}, options, dropResult)
|
|
7847
|
+
}
|
|
7848
|
+
};
|
|
7849
|
+
manager.dispatch(action);
|
|
7850
|
+
});
|
|
7851
|
+
};
|
|
7852
|
+
}
|
|
7853
|
+
function verifyInvariants(monitor) {
|
|
7854
|
+
invariant(monitor.isDragging(), 'Cannot call drop while not dragging.');
|
|
7855
|
+
invariant(!monitor.didDrop(), 'Cannot call drop twice during one drag operation.');
|
|
7856
|
+
}
|
|
7857
|
+
function determineDropResult(targetId, index, registry, monitor) {
|
|
7858
|
+
const target = registry.getTarget(targetId);
|
|
7859
|
+
let dropResult = target ? target.drop(monitor, targetId) : undefined;
|
|
7860
|
+
verifyDropResultType(dropResult);
|
|
7861
|
+
if (typeof dropResult === 'undefined') {
|
|
7862
|
+
dropResult = index === 0 ? {} : monitor.getDropResult();
|
|
7863
|
+
}
|
|
7864
|
+
return dropResult;
|
|
7865
|
+
}
|
|
7866
|
+
function verifyDropResultType(dropResult) {
|
|
7867
|
+
invariant(typeof dropResult === 'undefined' || isObject(dropResult), 'Drop result must either be an object or undefined.');
|
|
7868
|
+
}
|
|
7869
|
+
function getDroppableTargets(monitor) {
|
|
7870
|
+
const targetIds = monitor.getTargetIds().filter(monitor.canDropOnTarget, monitor);
|
|
7871
|
+
targetIds.reverse();
|
|
7872
|
+
return targetIds;
|
|
7873
|
+
}
|
|
7874
|
+
|
|
7875
|
+
function createEndDrag(manager) {
|
|
7876
|
+
return function endDrag() {
|
|
7877
|
+
const monitor = manager.getMonitor();
|
|
7878
|
+
const registry = manager.getRegistry();
|
|
7879
|
+
verifyIsDragging(monitor);
|
|
7880
|
+
const sourceId = monitor.getSourceId();
|
|
7881
|
+
if (sourceId != null) {
|
|
7882
|
+
const source = registry.getSource(sourceId, true);
|
|
7883
|
+
source.endDrag(monitor, sourceId);
|
|
7884
|
+
registry.unpinSource();
|
|
7885
|
+
}
|
|
7886
|
+
return {
|
|
7887
|
+
type: END_DRAG
|
|
7888
|
+
};
|
|
7889
|
+
};
|
|
7890
|
+
}
|
|
7891
|
+
function verifyIsDragging(monitor) {
|
|
7892
|
+
invariant(monitor.isDragging(), 'Cannot call endDrag while not dragging.');
|
|
7893
|
+
}
|
|
7348
7894
|
|
|
7349
|
-
|
|
7350
|
-
|
|
7351
|
-
|
|
7352
|
-
|
|
7353
|
-
|
|
7354
|
-
|
|
7355
|
-
|
|
7356
|
-
value: void 0
|
|
7357
|
-
});
|
|
7358
|
-
|
|
7359
|
-
_nodes.set(this, {
|
|
7360
|
-
writable: true,
|
|
7361
|
-
value: void 0
|
|
7362
|
-
});
|
|
7363
|
-
|
|
7364
|
-
_createBackend.set(this, {
|
|
7365
|
-
writable: true,
|
|
7366
|
-
value: function value(manager, context, backend) {
|
|
7367
|
-
var _backend$preview, _backend$skipDispatch;
|
|
7368
|
-
|
|
7369
|
-
if (!backend.backend) {
|
|
7370
|
-
throw new Error("You must specify a 'backend' property in your Backend entry: ".concat(JSON.stringify(backend)));
|
|
7371
|
-
}
|
|
7372
|
-
|
|
7373
|
-
var instance = backend.backend(manager, context, backend.options);
|
|
7374
|
-
var id = backend.id; // Try to infer an `id` if one doesn't exist
|
|
7375
|
-
|
|
7376
|
-
var inferName = !backend.id && instance && instance.constructor;
|
|
7895
|
+
function matchesType(targetType, draggedItemType) {
|
|
7896
|
+
if (draggedItemType === null) {
|
|
7897
|
+
return targetType === null;
|
|
7898
|
+
}
|
|
7899
|
+
return Array.isArray(targetType) ? targetType.some((t)=>t === draggedItemType
|
|
7900
|
+
) : targetType === draggedItemType;
|
|
7901
|
+
}
|
|
7377
7902
|
|
|
7378
|
-
|
|
7379
|
-
|
|
7380
|
-
|
|
7903
|
+
function createHover(manager) {
|
|
7904
|
+
return function hover(targetIdsArg, { clientOffset } = {}) {
|
|
7905
|
+
verifyTargetIdsIsArray(targetIdsArg);
|
|
7906
|
+
const targetIds = targetIdsArg.slice(0);
|
|
7907
|
+
const monitor = manager.getMonitor();
|
|
7908
|
+
const registry = manager.getRegistry();
|
|
7909
|
+
const draggedItemType = monitor.getItemType();
|
|
7910
|
+
removeNonMatchingTargetIds(targetIds, registry, draggedItemType);
|
|
7911
|
+
checkInvariants(targetIds, monitor, registry);
|
|
7912
|
+
hoverAllTargets(targetIds, monitor, registry);
|
|
7913
|
+
return {
|
|
7914
|
+
type: HOVER,
|
|
7915
|
+
payload: {
|
|
7916
|
+
targetIds,
|
|
7917
|
+
clientOffset: clientOffset || null
|
|
7918
|
+
}
|
|
7919
|
+
};
|
|
7920
|
+
};
|
|
7921
|
+
}
|
|
7922
|
+
function verifyTargetIdsIsArray(targetIdsArg) {
|
|
7923
|
+
invariant(Array.isArray(targetIdsArg), 'Expected targetIds to be an array.');
|
|
7924
|
+
}
|
|
7925
|
+
function checkInvariants(targetIds, monitor, registry) {
|
|
7926
|
+
invariant(monitor.isDragging(), 'Cannot call hover while not dragging.');
|
|
7927
|
+
invariant(!monitor.didDrop(), 'Cannot call hover after drop.');
|
|
7928
|
+
for(let i = 0; i < targetIds.length; i++){
|
|
7929
|
+
const targetId = targetIds[i];
|
|
7930
|
+
invariant(targetIds.lastIndexOf(targetId) === i, 'Expected targetIds to be unique in the passed array.');
|
|
7931
|
+
const target = registry.getTarget(targetId);
|
|
7932
|
+
invariant(target, 'Expected targetIds to be registered.');
|
|
7933
|
+
}
|
|
7934
|
+
}
|
|
7935
|
+
function removeNonMatchingTargetIds(targetIds, registry, draggedItemType) {
|
|
7936
|
+
// Remove those targetIds that don't match the targetType. This
|
|
7937
|
+
// fixes shallow isOver which would only be non-shallow because of
|
|
7938
|
+
// non-matching targets.
|
|
7939
|
+
for(let i = targetIds.length - 1; i >= 0; i--){
|
|
7940
|
+
const targetId = targetIds[i];
|
|
7941
|
+
const targetType = registry.getTargetType(targetId);
|
|
7942
|
+
if (!matchesType(targetType, draggedItemType)) {
|
|
7943
|
+
targetIds.splice(i, 1);
|
|
7944
|
+
}
|
|
7945
|
+
}
|
|
7946
|
+
}
|
|
7947
|
+
function hoverAllTargets(targetIds, monitor, registry) {
|
|
7948
|
+
// Finally call hover on all matching targets.
|
|
7949
|
+
targetIds.forEach(function(targetId) {
|
|
7950
|
+
const target = registry.getTarget(targetId);
|
|
7951
|
+
target.hover(monitor, targetId);
|
|
7952
|
+
});
|
|
7953
|
+
}
|
|
7381
7954
|
|
|
7382
|
-
|
|
7383
|
-
|
|
7384
|
-
|
|
7385
|
-
|
|
7386
|
-
|
|
7387
|
-
|
|
7955
|
+
function createPublishDragSource(manager) {
|
|
7956
|
+
return function publishDragSource() {
|
|
7957
|
+
const monitor = manager.getMonitor();
|
|
7958
|
+
if (monitor.isDragging()) {
|
|
7959
|
+
return {
|
|
7960
|
+
type: PUBLISH_DRAG_SOURCE
|
|
7961
|
+
};
|
|
7962
|
+
}
|
|
7963
|
+
return;
|
|
7964
|
+
};
|
|
7965
|
+
}
|
|
7388
7966
|
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7967
|
+
function createDragDropActions(manager) {
|
|
7968
|
+
return {
|
|
7969
|
+
beginDrag: createBeginDrag(manager),
|
|
7970
|
+
publishDragSource: createPublishDragSource(manager),
|
|
7971
|
+
hover: createHover(manager),
|
|
7972
|
+
drop: createDrop(manager),
|
|
7973
|
+
endDrag: createEndDrag(manager)
|
|
7974
|
+
};
|
|
7975
|
+
}
|
|
7392
7976
|
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
preview: (_backend$preview = backend.preview) !== null && _backend$preview !== void 0 ? _backend$preview : false,
|
|
7397
|
-
transition: backend.transition,
|
|
7398
|
-
skipDispatchOnTransition: (_backend$skipDispatch = backend.skipDispatchOnTransition) !== null && _backend$skipDispatch !== void 0 ? _backend$skipDispatch : false
|
|
7399
|
-
};
|
|
7977
|
+
class DragDropManagerImpl {
|
|
7978
|
+
receiveBackend(backend) {
|
|
7979
|
+
this.backend = backend;
|
|
7400
7980
|
}
|
|
7401
|
-
|
|
7402
|
-
|
|
7403
|
-
_defineProperty(this, "setup", function () {
|
|
7404
|
-
if (typeof window === 'undefined') {
|
|
7405
|
-
return;
|
|
7981
|
+
getMonitor() {
|
|
7982
|
+
return this.monitor;
|
|
7406
7983
|
}
|
|
7407
|
-
|
|
7408
|
-
|
|
7409
|
-
throw new Error('Cannot have two MultiBackends at the same time.');
|
|
7984
|
+
getBackend() {
|
|
7985
|
+
return this.backend;
|
|
7410
7986
|
}
|
|
7411
|
-
|
|
7412
|
-
|
|
7413
|
-
|
|
7414
|
-
_classPrivateFieldGet(_this, _addEventListeners).call(_this, window);
|
|
7415
|
-
|
|
7416
|
-
_classPrivateFieldGet(_this, _backends)[_classPrivateFieldGet(_this, _current)].instance.setup();
|
|
7417
|
-
});
|
|
7418
|
-
|
|
7419
|
-
_defineProperty(this, "teardown", function () {
|
|
7420
|
-
if (typeof window === 'undefined') {
|
|
7421
|
-
return;
|
|
7987
|
+
getRegistry() {
|
|
7988
|
+
return this.monitor.registry;
|
|
7422
7989
|
}
|
|
7423
|
-
|
|
7424
|
-
|
|
7425
|
-
|
|
7426
|
-
|
|
7427
|
-
|
|
7428
|
-
|
|
7429
|
-
|
|
7430
|
-
|
|
7431
|
-
|
|
7432
|
-
|
|
7433
|
-
});
|
|
7434
|
-
|
|
7435
|
-
_defineProperty(this, "connectDragPreview", function (sourceId, node, options) {
|
|
7436
|
-
return _classPrivateFieldGet(_this, _connectBackend).call(_this, 'connectDragPreview', sourceId, node, options);
|
|
7437
|
-
});
|
|
7438
|
-
|
|
7439
|
-
_defineProperty(this, "connectDropTarget", function (sourceId, node, options) {
|
|
7440
|
-
return _classPrivateFieldGet(_this, _connectBackend).call(_this, 'connectDropTarget', sourceId, node, options);
|
|
7441
|
-
});
|
|
7442
|
-
|
|
7443
|
-
_defineProperty(this, "profile", function () {
|
|
7444
|
-
return _classPrivateFieldGet(_this, _backends)[_classPrivateFieldGet(_this, _current)].instance.profile();
|
|
7445
|
-
});
|
|
7446
|
-
|
|
7447
|
-
_defineProperty(this, "previewEnabled", function () {
|
|
7448
|
-
return _classPrivateFieldGet(_this, _backends)[_classPrivateFieldGet(_this, _current)].preview;
|
|
7449
|
-
});
|
|
7450
|
-
|
|
7451
|
-
_defineProperty(this, "previewsList", function () {
|
|
7452
|
-
return _classPrivateFieldGet(_this, _previews);
|
|
7453
|
-
});
|
|
7454
|
-
|
|
7455
|
-
_defineProperty(this, "backendsList", function () {
|
|
7456
|
-
return _classPrivateFieldGet(_this, _backendsList);
|
|
7457
|
-
});
|
|
7458
|
-
|
|
7459
|
-
_addEventListeners.set(this, {
|
|
7460
|
-
writable: true,
|
|
7461
|
-
value: function value(target) {
|
|
7462
|
-
_classPrivateFieldGet(_this, _backendsList).forEach(function (backend) {
|
|
7463
|
-
if (backend.transition) {
|
|
7464
|
-
target.addEventListener(backend.transition.event, _classPrivateFieldGet(_this, _backendSwitcher));
|
|
7990
|
+
getActions() {
|
|
7991
|
+
/* eslint-disable-next-line @typescript-eslint/no-this-alias */ const manager = this;
|
|
7992
|
+
const { dispatch } = this.store;
|
|
7993
|
+
function bindActionCreator(actionCreator) {
|
|
7994
|
+
return (...args)=>{
|
|
7995
|
+
const action = actionCreator.apply(manager, args);
|
|
7996
|
+
if (typeof action !== 'undefined') {
|
|
7997
|
+
dispatch(action);
|
|
7998
|
+
}
|
|
7999
|
+
};
|
|
7465
8000
|
}
|
|
7466
|
-
|
|
8001
|
+
const actions = createDragDropActions(this);
|
|
8002
|
+
return Object.keys(actions).reduce((boundActions, key)=>{
|
|
8003
|
+
const action = actions[key];
|
|
8004
|
+
boundActions[key] = bindActionCreator(action);
|
|
8005
|
+
return boundActions;
|
|
8006
|
+
}, {});
|
|
8007
|
+
}
|
|
8008
|
+
dispatch(action) {
|
|
8009
|
+
this.store.dispatch(action);
|
|
8010
|
+
}
|
|
8011
|
+
constructor(store, monitor){
|
|
8012
|
+
this.isSetUp = false;
|
|
8013
|
+
this.handleRefCountChange = ()=>{
|
|
8014
|
+
const shouldSetUp = this.store.getState().refCount > 0;
|
|
8015
|
+
if (this.backend) {
|
|
8016
|
+
if (shouldSetUp && !this.isSetUp) {
|
|
8017
|
+
this.backend.setup();
|
|
8018
|
+
this.isSetUp = true;
|
|
8019
|
+
} else if (!shouldSetUp && this.isSetUp) {
|
|
8020
|
+
this.backend.teardown();
|
|
8021
|
+
this.isSetUp = false;
|
|
8022
|
+
}
|
|
8023
|
+
}
|
|
8024
|
+
};
|
|
8025
|
+
this.store = store;
|
|
8026
|
+
this.monitor = monitor;
|
|
8027
|
+
store.subscribe(this.handleRefCountChange);
|
|
7467
8028
|
}
|
|
7468
|
-
|
|
8029
|
+
}
|
|
7469
8030
|
|
|
7470
|
-
|
|
7471
|
-
|
|
7472
|
-
|
|
7473
|
-
|
|
7474
|
-
|
|
7475
|
-
|
|
7476
|
-
|
|
7477
|
-
|
|
8031
|
+
/**
|
|
8032
|
+
* Coordinate addition
|
|
8033
|
+
* @param a The first coordinate
|
|
8034
|
+
* @param b The second coordinate
|
|
8035
|
+
*/ function add(a, b) {
|
|
8036
|
+
return {
|
|
8037
|
+
x: a.x + b.x,
|
|
8038
|
+
y: a.y + b.y
|
|
8039
|
+
};
|
|
8040
|
+
}
|
|
8041
|
+
/**
|
|
8042
|
+
* Coordinate subtraction
|
|
8043
|
+
* @param a The first coordinate
|
|
8044
|
+
* @param b The second coordinate
|
|
8045
|
+
*/ function subtract(a, b) {
|
|
8046
|
+
return {
|
|
8047
|
+
x: a.x - b.x,
|
|
8048
|
+
y: a.y - b.y
|
|
8049
|
+
};
|
|
8050
|
+
}
|
|
8051
|
+
/**
|
|
8052
|
+
* Returns the cartesian distance of the drag source component's position, based on its position
|
|
8053
|
+
* at the time when the current drag operation has started, and the movement difference.
|
|
8054
|
+
*
|
|
8055
|
+
* Returns null if no item is being dragged.
|
|
8056
|
+
*
|
|
8057
|
+
* @param state The offset state to compute from
|
|
8058
|
+
*/ function getSourceClientOffset(state) {
|
|
8059
|
+
const { clientOffset , initialClientOffset , initialSourceClientOffset } = state;
|
|
8060
|
+
if (!clientOffset || !initialClientOffset || !initialSourceClientOffset) {
|
|
8061
|
+
return null;
|
|
7478
8062
|
}
|
|
7479
|
-
|
|
7480
|
-
|
|
7481
|
-
|
|
7482
|
-
|
|
7483
|
-
|
|
7484
|
-
|
|
7485
|
-
|
|
7486
|
-
|
|
7487
|
-
|
|
7488
|
-
|
|
7489
|
-
|
|
7490
|
-
|
|
7491
|
-
|
|
8063
|
+
return subtract(add(clientOffset, initialSourceClientOffset), initialClientOffset);
|
|
8064
|
+
}
|
|
8065
|
+
/**
|
|
8066
|
+
* Determines the x,y offset between the client offset and the initial client offset
|
|
8067
|
+
*
|
|
8068
|
+
* @param state The offset state to compute from
|
|
8069
|
+
*/ function getDifferenceFromInitialOffset(state) {
|
|
8070
|
+
const { clientOffset , initialClientOffset } = state;
|
|
8071
|
+
if (!clientOffset || !initialClientOffset) {
|
|
8072
|
+
return null;
|
|
8073
|
+
}
|
|
8074
|
+
return subtract(clientOffset, initialClientOffset);
|
|
8075
|
+
}
|
|
7492
8076
|
|
|
8077
|
+
const NONE = [];
|
|
8078
|
+
const ALL = [];
|
|
8079
|
+
NONE.__IS_NONE__ = true;
|
|
8080
|
+
ALL.__IS_ALL__ = true;
|
|
8081
|
+
/**
|
|
8082
|
+
* Determines if the given handler IDs are dirty or not.
|
|
8083
|
+
*
|
|
8084
|
+
* @param dirtyIds The set of dirty handler ids
|
|
8085
|
+
* @param handlerIds The set of handler ids to check
|
|
8086
|
+
*/ function areDirty(dirtyIds, handlerIds) {
|
|
8087
|
+
if (dirtyIds === NONE) {
|
|
7493
8088
|
return false;
|
|
7494
|
-
|
|
7495
|
-
|
|
7496
|
-
|
|
7497
|
-
|
|
7498
|
-
|
|
7499
|
-
|
|
7500
|
-
|
|
7501
|
-
|
|
7502
|
-
|
|
7503
|
-
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
|
|
7507
|
-
|
|
7508
|
-
|
|
7509
|
-
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
|
|
7513
|
-
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
|
|
8089
|
+
}
|
|
8090
|
+
if (dirtyIds === ALL || typeof handlerIds === 'undefined') {
|
|
8091
|
+
return true;
|
|
8092
|
+
}
|
|
8093
|
+
const commonIds = intersection(handlerIds, dirtyIds);
|
|
8094
|
+
return commonIds.length > 0;
|
|
8095
|
+
}
|
|
8096
|
+
|
|
8097
|
+
class DragDropMonitorImpl {
|
|
8098
|
+
subscribeToStateChange(listener, options = {}) {
|
|
8099
|
+
const { handlerIds } = options;
|
|
8100
|
+
invariant(typeof listener === 'function', 'listener must be a function.');
|
|
8101
|
+
invariant(typeof handlerIds === 'undefined' || Array.isArray(handlerIds), 'handlerIds, when specified, must be an array of strings.');
|
|
8102
|
+
let prevStateId = this.store.getState().stateId;
|
|
8103
|
+
const handleChange = ()=>{
|
|
8104
|
+
const state = this.store.getState();
|
|
8105
|
+
const currentStateId = state.stateId;
|
|
8106
|
+
try {
|
|
8107
|
+
const canSkipListener = currentStateId === prevStateId || currentStateId === prevStateId + 1 && !areDirty(state.dirtyHandlerIds, handlerIds);
|
|
8108
|
+
if (!canSkipListener) {
|
|
8109
|
+
listener();
|
|
8110
|
+
}
|
|
8111
|
+
} finally{
|
|
8112
|
+
prevStateId = currentStateId;
|
|
8113
|
+
}
|
|
8114
|
+
};
|
|
8115
|
+
return this.store.subscribe(handleChange);
|
|
8116
|
+
}
|
|
8117
|
+
subscribeToOffsetChange(listener) {
|
|
8118
|
+
invariant(typeof listener === 'function', 'listener must be a function.');
|
|
8119
|
+
let previousState = this.store.getState().dragOffset;
|
|
8120
|
+
const handleChange = ()=>{
|
|
8121
|
+
const nextState = this.store.getState().dragOffset;
|
|
8122
|
+
if (nextState === previousState) {
|
|
8123
|
+
return;
|
|
8124
|
+
}
|
|
8125
|
+
previousState = nextState;
|
|
8126
|
+
listener();
|
|
8127
|
+
};
|
|
8128
|
+
return this.store.subscribe(handleChange);
|
|
8129
|
+
}
|
|
8130
|
+
canDragSource(sourceId) {
|
|
8131
|
+
if (!sourceId) {
|
|
8132
|
+
return false;
|
|
7518
8133
|
}
|
|
7519
|
-
|
|
7520
|
-
|
|
7521
|
-
|
|
7522
|
-
|
|
7523
|
-
newEvent = event.constructor(event.type, event);
|
|
7524
|
-
} catch (_e) {
|
|
7525
|
-
newEvent = document.createEvent('Event');
|
|
7526
|
-
newEvent.initEvent(event.type, event.bubbles, event.cancelable);
|
|
8134
|
+
const source = this.registry.getSource(sourceId);
|
|
8135
|
+
invariant(source, `Expected to find a valid source. sourceId=${sourceId}`);
|
|
8136
|
+
if (this.isDragging()) {
|
|
8137
|
+
return false;
|
|
7527
8138
|
}
|
|
7528
|
-
|
|
7529
|
-
(_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.dispatchEvent(newEvent);
|
|
7530
|
-
}
|
|
8139
|
+
return source.canDrag(this, sourceId);
|
|
7531
8140
|
}
|
|
7532
|
-
|
|
7533
|
-
|
|
7534
|
-
|
|
7535
|
-
|
|
7536
|
-
|
|
7537
|
-
|
|
8141
|
+
canDropOnTarget(targetId) {
|
|
8142
|
+
// undefined on initial render
|
|
8143
|
+
if (!targetId) {
|
|
8144
|
+
return false;
|
|
8145
|
+
}
|
|
8146
|
+
const target = this.registry.getTarget(targetId);
|
|
8147
|
+
invariant(target, `Expected to find a valid target. targetId=${targetId}`);
|
|
8148
|
+
if (!this.isDragging() || this.didDrop()) {
|
|
8149
|
+
return false;
|
|
8150
|
+
}
|
|
8151
|
+
const targetType = this.registry.getTargetType(targetId);
|
|
8152
|
+
const draggedItemType = this.getItemType();
|
|
8153
|
+
return matchesType(targetType, draggedItemType) && target.canDrop(this, targetId);
|
|
7538
8154
|
}
|
|
7539
|
-
|
|
7540
|
-
|
|
7541
|
-
_connectBackend.set(this, {
|
|
7542
|
-
writable: true,
|
|
7543
|
-
value: function value(func, sourceId, node, options) {
|
|
7544
|
-
var nodeId = "".concat(func, "_").concat(sourceId);
|
|
7545
|
-
|
|
7546
|
-
var unsubscribe = _classPrivateFieldGet(_this, _callBackend).call(_this, func, sourceId, node, options);
|
|
7547
|
-
|
|
7548
|
-
_classPrivateFieldGet(_this, _nodes)[nodeId] = {
|
|
7549
|
-
func: func,
|
|
7550
|
-
args: [sourceId, node, options],
|
|
7551
|
-
unsubscribe: unsubscribe
|
|
7552
|
-
};
|
|
7553
|
-
return function () {
|
|
7554
|
-
_classPrivateFieldGet(_this, _nodes)[nodeId].unsubscribe();
|
|
7555
|
-
|
|
7556
|
-
delete _classPrivateFieldGet(_this, _nodes)[nodeId];
|
|
7557
|
-
};
|
|
8155
|
+
isDragging() {
|
|
8156
|
+
return Boolean(this.getItemType());
|
|
7558
8157
|
}
|
|
7559
|
-
|
|
8158
|
+
isDraggingSource(sourceId) {
|
|
8159
|
+
// undefined on initial render
|
|
8160
|
+
if (!sourceId) {
|
|
8161
|
+
return false;
|
|
8162
|
+
}
|
|
8163
|
+
const source = this.registry.getSource(sourceId, true);
|
|
8164
|
+
invariant(source, `Expected to find a valid source. sourceId=${sourceId}`);
|
|
8165
|
+
if (!this.isDragging() || !this.isSourcePublic()) {
|
|
8166
|
+
return false;
|
|
8167
|
+
}
|
|
8168
|
+
const sourceType = this.registry.getSourceType(sourceId);
|
|
8169
|
+
const draggedItemType = this.getItemType();
|
|
8170
|
+
if (sourceType !== draggedItemType) {
|
|
8171
|
+
return false;
|
|
8172
|
+
}
|
|
8173
|
+
return source.isDragging(this, sourceId);
|
|
8174
|
+
}
|
|
8175
|
+
isOverTarget(targetId, options = {
|
|
8176
|
+
shallow: false
|
|
8177
|
+
}) {
|
|
8178
|
+
// undefined on initial render
|
|
8179
|
+
if (!targetId) {
|
|
8180
|
+
return false;
|
|
8181
|
+
}
|
|
8182
|
+
const { shallow } = options;
|
|
8183
|
+
if (!this.isDragging()) {
|
|
8184
|
+
return false;
|
|
8185
|
+
}
|
|
8186
|
+
const targetType = this.registry.getTargetType(targetId);
|
|
8187
|
+
const draggedItemType = this.getItemType();
|
|
8188
|
+
if (draggedItemType && !matchesType(targetType, draggedItemType)) {
|
|
8189
|
+
return false;
|
|
8190
|
+
}
|
|
8191
|
+
const targetIds = this.getTargetIds();
|
|
8192
|
+
if (!targetIds.length) {
|
|
8193
|
+
return false;
|
|
8194
|
+
}
|
|
8195
|
+
const index = targetIds.indexOf(targetId);
|
|
8196
|
+
if (shallow) {
|
|
8197
|
+
return index === targetIds.length - 1;
|
|
8198
|
+
} else {
|
|
8199
|
+
return index > -1;
|
|
8200
|
+
}
|
|
8201
|
+
}
|
|
8202
|
+
getItemType() {
|
|
8203
|
+
return this.store.getState().dragOperation.itemType;
|
|
8204
|
+
}
|
|
8205
|
+
getItem() {
|
|
8206
|
+
return this.store.getState().dragOperation.item;
|
|
8207
|
+
}
|
|
8208
|
+
getSourceId() {
|
|
8209
|
+
return this.store.getState().dragOperation.sourceId;
|
|
8210
|
+
}
|
|
8211
|
+
getTargetIds() {
|
|
8212
|
+
return this.store.getState().dragOperation.targetIds;
|
|
8213
|
+
}
|
|
8214
|
+
getDropResult() {
|
|
8215
|
+
return this.store.getState().dragOperation.dropResult;
|
|
8216
|
+
}
|
|
8217
|
+
didDrop() {
|
|
8218
|
+
return this.store.getState().dragOperation.didDrop;
|
|
8219
|
+
}
|
|
8220
|
+
isSourcePublic() {
|
|
8221
|
+
return Boolean(this.store.getState().dragOperation.isSourcePublic);
|
|
8222
|
+
}
|
|
8223
|
+
getInitialClientOffset() {
|
|
8224
|
+
return this.store.getState().dragOffset.initialClientOffset;
|
|
8225
|
+
}
|
|
8226
|
+
getInitialSourceClientOffset() {
|
|
8227
|
+
return this.store.getState().dragOffset.initialSourceClientOffset;
|
|
8228
|
+
}
|
|
8229
|
+
getClientOffset() {
|
|
8230
|
+
return this.store.getState().dragOffset.clientOffset;
|
|
8231
|
+
}
|
|
8232
|
+
getSourceClientOffset() {
|
|
8233
|
+
return getSourceClientOffset(this.store.getState().dragOffset);
|
|
8234
|
+
}
|
|
8235
|
+
getDifferenceFromInitialOffset() {
|
|
8236
|
+
return getDifferenceFromInitialOffset(this.store.getState().dragOffset);
|
|
8237
|
+
}
|
|
8238
|
+
constructor(store, registry){
|
|
8239
|
+
this.store = store;
|
|
8240
|
+
this.registry = registry;
|
|
8241
|
+
}
|
|
8242
|
+
}
|
|
8243
|
+
|
|
8244
|
+
// Safari 6 and 6.1 for desktop, iPad, and iPhone are the only browsers that
|
|
8245
|
+
// have WebKitMutationObserver but not un-prefixed MutationObserver.
|
|
8246
|
+
// Must use `global` or `self` instead of `window` to work in both frames and web
|
|
8247
|
+
// workers. `global` is a provision of Browserify, Mr, Mrs, or Mop.
|
|
8248
|
+
/* globals self */ const scope = typeof global !== 'undefined' ? global : self;
|
|
8249
|
+
const BrowserMutationObserver = scope.MutationObserver || scope.WebKitMutationObserver;
|
|
8250
|
+
function makeRequestCallFromTimer(callback) {
|
|
8251
|
+
return function requestCall() {
|
|
8252
|
+
// We dispatch a timeout with a specified delay of 0 for engines that
|
|
8253
|
+
// can reliably accommodate that request. This will usually be snapped
|
|
8254
|
+
// to a 4 milisecond delay, but once we're flushing, there's no delay
|
|
8255
|
+
// between events.
|
|
8256
|
+
const timeoutHandle = setTimeout(handleTimer, 0);
|
|
8257
|
+
// However, since this timer gets frequently dropped in Firefox
|
|
8258
|
+
// workers, we enlist an interval handle that will try to fire
|
|
8259
|
+
// an event 20 times per second until it succeeds.
|
|
8260
|
+
const intervalHandle = setInterval(handleTimer, 50);
|
|
8261
|
+
function handleTimer() {
|
|
8262
|
+
// Whichever timer succeeds will cancel both timers and
|
|
8263
|
+
// execute the callback.
|
|
8264
|
+
clearTimeout(timeoutHandle);
|
|
8265
|
+
clearInterval(intervalHandle);
|
|
8266
|
+
callback();
|
|
8267
|
+
}
|
|
8268
|
+
};
|
|
8269
|
+
}
|
|
8270
|
+
// To request a high priority event, we induce a mutation observer by toggling
|
|
8271
|
+
// the text of a text node between "1" and "-1".
|
|
8272
|
+
function makeRequestCallFromMutationObserver(callback) {
|
|
8273
|
+
let toggle = 1;
|
|
8274
|
+
const observer = new BrowserMutationObserver(callback);
|
|
8275
|
+
const node = document.createTextNode('');
|
|
8276
|
+
observer.observe(node, {
|
|
8277
|
+
characterData: true
|
|
8278
|
+
});
|
|
8279
|
+
return function requestCall() {
|
|
8280
|
+
toggle = -toggle;
|
|
8281
|
+
node.data = toggle;
|
|
8282
|
+
};
|
|
8283
|
+
}
|
|
8284
|
+
const makeRequestCall = typeof BrowserMutationObserver === 'function' ? // reliably everywhere they are implemented.
|
|
8285
|
+
// They are implemented in all modern browsers.
|
|
8286
|
+
//
|
|
8287
|
+
// - Android 4-4.3
|
|
8288
|
+
// - Chrome 26-34
|
|
8289
|
+
// - Firefox 14-29
|
|
8290
|
+
// - Internet Explorer 11
|
|
8291
|
+
// - iPad Safari 6-7.1
|
|
8292
|
+
// - iPhone Safari 7-7.1
|
|
8293
|
+
// - Safari 6-7
|
|
8294
|
+
makeRequestCallFromMutationObserver : // task queue, are implemented in Internet Explorer 10, Safari 5.0-1, and Opera
|
|
8295
|
+
// 11-12, and in web workers in many engines.
|
|
8296
|
+
// Although message channels yield to any queued rendering and IO tasks, they
|
|
8297
|
+
// would be better than imposing the 4ms delay of timers.
|
|
8298
|
+
// However, they do not work reliably in Internet Explorer or Safari.
|
|
8299
|
+
// Internet Explorer 10 is the only browser that has setImmediate but does
|
|
8300
|
+
// not have MutationObservers.
|
|
8301
|
+
// Although setImmediate yields to the browser's renderer, it would be
|
|
8302
|
+
// preferrable to falling back to setTimeout since it does not have
|
|
8303
|
+
// the minimum 4ms penalty.
|
|
8304
|
+
// Unfortunately there appears to be a bug in Internet Explorer 10 Mobile (and
|
|
8305
|
+
// Desktop to a lesser extent) that renders both setImmediate and
|
|
8306
|
+
// MessageChannel useless for the purposes of ASAP.
|
|
8307
|
+
// https://github.com/kriskowal/q/issues/396
|
|
8308
|
+
// Timers are implemented universally.
|
|
8309
|
+
// We fall back to timers in workers in most engines, and in foreground
|
|
8310
|
+
// contexts in the following browsers.
|
|
8311
|
+
// However, note that even this simple case requires nuances to operate in a
|
|
8312
|
+
// broad spectrum of browsers.
|
|
8313
|
+
//
|
|
8314
|
+
// - Firefox 3-13
|
|
8315
|
+
// - Internet Explorer 6-9
|
|
8316
|
+
// - iPad Safari 4.3
|
|
8317
|
+
// - Lynx 2.8.7
|
|
8318
|
+
makeRequestCallFromTimer;
|
|
8319
|
+
|
|
8320
|
+
class AsapQueue {
|
|
8321
|
+
// Use the fastest means possible to execute a task in its own turn, with
|
|
8322
|
+
// priority over other events including IO, animation, reflow, and redraw
|
|
8323
|
+
// events in browsers.
|
|
8324
|
+
//
|
|
8325
|
+
// An exception thrown by a task will permanently interrupt the processing of
|
|
8326
|
+
// subsequent tasks. The higher level `asap` function ensures that if an
|
|
8327
|
+
// exception is thrown by a task, that the task queue will continue flushing as
|
|
8328
|
+
// soon as possible, but if you use `rawAsap` directly, you are responsible to
|
|
8329
|
+
// either ensure that no exceptions are thrown from your task, or to manually
|
|
8330
|
+
// call `rawAsap.requestFlush` if an exception is thrown.
|
|
8331
|
+
enqueueTask(task) {
|
|
8332
|
+
const { queue: q , requestFlush } = this;
|
|
8333
|
+
if (!q.length) {
|
|
8334
|
+
requestFlush();
|
|
8335
|
+
this.flushing = true;
|
|
8336
|
+
}
|
|
8337
|
+
// Equivalent to push, but avoids a function call.
|
|
8338
|
+
q[q.length] = task;
|
|
8339
|
+
}
|
|
8340
|
+
constructor(){
|
|
8341
|
+
this.queue = [];
|
|
8342
|
+
// We queue errors to ensure they are thrown in right order (FIFO).
|
|
8343
|
+
// Array-as-queue is good enough here, since we are just dealing with exceptions.
|
|
8344
|
+
this.pendingErrors = [];
|
|
8345
|
+
// Once a flush has been requested, no further calls to `requestFlush` are
|
|
8346
|
+
// necessary until the next `flush` completes.
|
|
8347
|
+
// @ts-ignore
|
|
8348
|
+
this.flushing = false;
|
|
8349
|
+
// The position of the next task to execute in the task queue. This is
|
|
8350
|
+
// preserved between calls to `flush` so that it can be resumed if
|
|
8351
|
+
// a task throws an exception.
|
|
8352
|
+
this.index = 0;
|
|
8353
|
+
// If a task schedules additional tasks recursively, the task queue can grow
|
|
8354
|
+
// unbounded. To prevent memory exhaustion, the task queue will periodically
|
|
8355
|
+
// truncate already-completed tasks.
|
|
8356
|
+
this.capacity = 1024;
|
|
8357
|
+
// The flush function processes all tasks that have been scheduled with
|
|
8358
|
+
// `rawAsap` unless and until one of those tasks throws an exception.
|
|
8359
|
+
// If a task throws an exception, `flush` ensures that its state will remain
|
|
8360
|
+
// consistent and will resume where it left off when called again.
|
|
8361
|
+
// However, `flush` does not make any arrangements to be called again if an
|
|
8362
|
+
// exception is thrown.
|
|
8363
|
+
this.flush = ()=>{
|
|
8364
|
+
const { queue: q } = this;
|
|
8365
|
+
while(this.index < q.length){
|
|
8366
|
+
const currentIndex = this.index;
|
|
8367
|
+
// Advance the index before calling the task. This ensures that we will
|
|
8368
|
+
// begin flushing on the next task the task throws an error.
|
|
8369
|
+
this.index++;
|
|
8370
|
+
q[currentIndex].call();
|
|
8371
|
+
// Prevent leaking memory for long chains of recursive calls to `asap`.
|
|
8372
|
+
// If we call `asap` within tasks scheduled by `asap`, the queue will
|
|
8373
|
+
// grow, but to avoid an O(n) walk for every task we execute, we don't
|
|
8374
|
+
// shift tasks off the queue after they have been executed.
|
|
8375
|
+
// Instead, we periodically shift 1024 tasks off the queue.
|
|
8376
|
+
if (this.index > this.capacity) {
|
|
8377
|
+
// Manually shift all values starting at the index back to the
|
|
8378
|
+
// beginning of the queue.
|
|
8379
|
+
for(let scan = 0, newLength = q.length - this.index; scan < newLength; scan++){
|
|
8380
|
+
q[scan] = q[scan + this.index];
|
|
8381
|
+
}
|
|
8382
|
+
q.length -= this.index;
|
|
8383
|
+
this.index = 0;
|
|
8384
|
+
}
|
|
8385
|
+
}
|
|
8386
|
+
q.length = 0;
|
|
8387
|
+
this.index = 0;
|
|
8388
|
+
this.flushing = false;
|
|
8389
|
+
};
|
|
8390
|
+
// In a web browser, exceptions are not fatal. However, to avoid
|
|
8391
|
+
// slowing down the queue of pending tasks, we rethrow the error in a
|
|
8392
|
+
// lower priority turn.
|
|
8393
|
+
this.registerPendingError = (err)=>{
|
|
8394
|
+
this.pendingErrors.push(err);
|
|
8395
|
+
this.requestErrorThrow();
|
|
8396
|
+
};
|
|
8397
|
+
// `requestFlush` requests that the high priority event queue be flushed as
|
|
8398
|
+
// soon as possible.
|
|
8399
|
+
// This is useful to prevent an error thrown in a task from stalling the event
|
|
8400
|
+
// queue if the exception handled by Node.js’s
|
|
8401
|
+
// `process.on("uncaughtException")` or by a domain.
|
|
8402
|
+
// `requestFlush` is implemented using a strategy based on data collected from
|
|
8403
|
+
// every available SauceLabs Selenium web driver worker at time of writing.
|
|
8404
|
+
// https://docs.google.com/spreadsheets/d/1mG-5UYGup5qxGdEMWkhP6BWCz053NUb2E1QoUTU16uA/edit#gid=783724593
|
|
8405
|
+
this.requestFlush = makeRequestCall(this.flush);
|
|
8406
|
+
this.requestErrorThrow = makeRequestCallFromTimer(()=>{
|
|
8407
|
+
// Throw first error
|
|
8408
|
+
if (this.pendingErrors.length) {
|
|
8409
|
+
throw this.pendingErrors.shift();
|
|
8410
|
+
}
|
|
8411
|
+
});
|
|
8412
|
+
}
|
|
8413
|
+
} // The message channel technique was discovered by Malte Ubl and was the
|
|
8414
|
+
// original foundation for this library.
|
|
8415
|
+
// http://www.nonblocking.io/2011/06/windownexttick.html
|
|
8416
|
+
// Safari 6.0.5 (at least) intermittently fails to create message ports on a
|
|
8417
|
+
// page's first load. Thankfully, this version of Safari supports
|
|
8418
|
+
// MutationObservers, so we don't need to fall back in that case.
|
|
8419
|
+
// function makeRequestCallFromMessageChannel(callback) {
|
|
8420
|
+
// var channel = new MessageChannel();
|
|
8421
|
+
// channel.port1.onmessage = callback;
|
|
8422
|
+
// return function requestCall() {
|
|
8423
|
+
// channel.port2.postMessage(0);
|
|
8424
|
+
// };
|
|
8425
|
+
// }
|
|
8426
|
+
// For reasons explained above, we are also unable to use `setImmediate`
|
|
8427
|
+
// under any circumstances.
|
|
8428
|
+
// Even if we were, there is another bug in Internet Explorer 10.
|
|
8429
|
+
// It is not sufficient to assign `setImmediate` to `requestFlush` because
|
|
8430
|
+
// `setImmediate` must be called *by name* and therefore must be wrapped in a
|
|
8431
|
+
// closure.
|
|
8432
|
+
// Never forget.
|
|
8433
|
+
// function makeRequestCallFromSetImmediate(callback) {
|
|
8434
|
+
// return function requestCall() {
|
|
8435
|
+
// setImmediate(callback);
|
|
8436
|
+
// };
|
|
8437
|
+
// }
|
|
8438
|
+
// Safari 6.0 has a problem where timers will get lost while the user is
|
|
8439
|
+
// scrolling. This problem does not impact ASAP because Safari 6.0 supports
|
|
8440
|
+
// mutation observers, so that implementation is used instead.
|
|
8441
|
+
// However, if we ever elect to use timers in Safari, the prevalent work-around
|
|
8442
|
+
// is to add a scroll event listener that calls for a flush.
|
|
8443
|
+
// `setTimeout` does not call the passed callback if the delay is less than
|
|
8444
|
+
// approximately 7 in web workers in Firefox 8 through 18, and sometimes not
|
|
8445
|
+
// even then.
|
|
8446
|
+
// This is for `asap.js` only.
|
|
8447
|
+
// Its name will be periodically randomized to break any code that depends on
|
|
8448
|
+
// // its existence.
|
|
8449
|
+
// rawAsap.makeRequestCallFromTimer = makeRequestCallFromTimer
|
|
8450
|
+
// ASAP was originally a nextTick shim included in Q. This was factored out
|
|
8451
|
+
// into this ASAP package. It was later adapted to RSVP which made further
|
|
8452
|
+
// amendments. These decisions, particularly to marginalize MessageChannel and
|
|
8453
|
+
// to capture the MutationObserver implementation in a closure, were integrated
|
|
8454
|
+
// back into ASAP proper.
|
|
8455
|
+
// https://github.com/tildeio/rsvp.js/blob/cddf7232546a9cf858524b75cde6f9edf72620a7/lib/rsvp/asap.js
|
|
8456
|
+
|
|
8457
|
+
// `call`, just like a function.
|
|
8458
|
+
class RawTask {
|
|
8459
|
+
call() {
|
|
8460
|
+
try {
|
|
8461
|
+
this.task && this.task();
|
|
8462
|
+
} catch (error) {
|
|
8463
|
+
this.onError(error);
|
|
8464
|
+
} finally{
|
|
8465
|
+
this.task = null;
|
|
8466
|
+
this.release(this);
|
|
8467
|
+
}
|
|
8468
|
+
}
|
|
8469
|
+
constructor(onError, release){
|
|
8470
|
+
this.onError = onError;
|
|
8471
|
+
this.release = release;
|
|
8472
|
+
this.task = null;
|
|
8473
|
+
}
|
|
8474
|
+
}
|
|
7560
8475
|
|
|
7561
|
-
|
|
7562
|
-
|
|
7563
|
-
|
|
8476
|
+
class TaskFactory {
|
|
8477
|
+
create(task) {
|
|
8478
|
+
const tasks = this.freeTasks;
|
|
8479
|
+
const t1 = tasks.length ? tasks.pop() : new RawTask(this.onError, (t)=>tasks[tasks.length] = t
|
|
8480
|
+
);
|
|
8481
|
+
t1.task = task;
|
|
8482
|
+
return t1;
|
|
8483
|
+
}
|
|
8484
|
+
constructor(onError){
|
|
8485
|
+
this.onError = onError;
|
|
8486
|
+
this.freeTasks = [];
|
|
8487
|
+
}
|
|
8488
|
+
}
|
|
7564
8489
|
|
|
7565
|
-
|
|
8490
|
+
const asapQueue = new AsapQueue();
|
|
8491
|
+
const taskFactory = new TaskFactory(asapQueue.registerPendingError);
|
|
8492
|
+
/**
|
|
8493
|
+
* Calls a task as soon as possible after returning, in its own event, with priority
|
|
8494
|
+
* over other events like animation, reflow, and repaint. An error thrown from an
|
|
8495
|
+
* event will not interrupt, nor even substantially slow down the processing of
|
|
8496
|
+
* other events, but will be rather postponed to a lower priority event.
|
|
8497
|
+
* @param {{call}} task A callable object, typically a function that takes no
|
|
8498
|
+
* arguments.
|
|
8499
|
+
*/ function asap(task) {
|
|
8500
|
+
asapQueue.enqueueTask(taskFactory.create(task));
|
|
8501
|
+
}
|
|
8502
|
+
|
|
8503
|
+
const ADD_SOURCE = 'dnd-core/ADD_SOURCE';
|
|
8504
|
+
const ADD_TARGET = 'dnd-core/ADD_TARGET';
|
|
8505
|
+
const REMOVE_SOURCE = 'dnd-core/REMOVE_SOURCE';
|
|
8506
|
+
const REMOVE_TARGET = 'dnd-core/REMOVE_TARGET';
|
|
8507
|
+
function addSource(sourceId) {
|
|
8508
|
+
return {
|
|
8509
|
+
type: ADD_SOURCE,
|
|
8510
|
+
payload: {
|
|
8511
|
+
sourceId
|
|
8512
|
+
}
|
|
8513
|
+
};
|
|
8514
|
+
}
|
|
8515
|
+
function addTarget(targetId) {
|
|
8516
|
+
return {
|
|
8517
|
+
type: ADD_TARGET,
|
|
8518
|
+
payload: {
|
|
8519
|
+
targetId
|
|
8520
|
+
}
|
|
8521
|
+
};
|
|
8522
|
+
}
|
|
8523
|
+
function removeSource(sourceId) {
|
|
8524
|
+
return {
|
|
8525
|
+
type: REMOVE_SOURCE,
|
|
8526
|
+
payload: {
|
|
8527
|
+
sourceId
|
|
8528
|
+
}
|
|
8529
|
+
};
|
|
8530
|
+
}
|
|
8531
|
+
function removeTarget(targetId) {
|
|
8532
|
+
return {
|
|
8533
|
+
type: REMOVE_TARGET,
|
|
8534
|
+
payload: {
|
|
8535
|
+
targetId
|
|
8536
|
+
}
|
|
8537
|
+
};
|
|
8538
|
+
}
|
|
7566
8539
|
|
|
7567
|
-
|
|
8540
|
+
function validateSourceContract(source) {
|
|
8541
|
+
invariant(typeof source.canDrag === 'function', 'Expected canDrag to be a function.');
|
|
8542
|
+
invariant(typeof source.beginDrag === 'function', 'Expected beginDrag to be a function.');
|
|
8543
|
+
invariant(typeof source.endDrag === 'function', 'Expected endDrag to be a function.');
|
|
8544
|
+
}
|
|
8545
|
+
function validateTargetContract(target) {
|
|
8546
|
+
invariant(typeof target.canDrop === 'function', 'Expected canDrop to be a function.');
|
|
8547
|
+
invariant(typeof target.hover === 'function', 'Expected hover to be a function.');
|
|
8548
|
+
invariant(typeof target.drop === 'function', 'Expected beginDrag to be a function.');
|
|
8549
|
+
}
|
|
8550
|
+
function validateType(type, allowArray) {
|
|
8551
|
+
if (allowArray && Array.isArray(type)) {
|
|
8552
|
+
type.forEach((t)=>validateType(t, false)
|
|
8553
|
+
);
|
|
8554
|
+
return;
|
|
8555
|
+
}
|
|
8556
|
+
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.');
|
|
8557
|
+
}
|
|
7568
8558
|
|
|
7569
|
-
|
|
8559
|
+
var HandlerRole;
|
|
8560
|
+
(function(HandlerRole) {
|
|
8561
|
+
HandlerRole["SOURCE"] = "SOURCE";
|
|
8562
|
+
HandlerRole["TARGET"] = "TARGET";
|
|
8563
|
+
})(HandlerRole || (HandlerRole = {}));
|
|
7570
8564
|
|
|
7571
|
-
|
|
7572
|
-
|
|
8565
|
+
let nextUniqueId = 0;
|
|
8566
|
+
function getNextUniqueId() {
|
|
8567
|
+
return nextUniqueId++;
|
|
8568
|
+
}
|
|
7573
8569
|
|
|
7574
|
-
|
|
8570
|
+
function getNextHandlerId(role) {
|
|
8571
|
+
const id = getNextUniqueId().toString();
|
|
8572
|
+
switch(role){
|
|
8573
|
+
case HandlerRole.SOURCE:
|
|
8574
|
+
return `S${id}`;
|
|
8575
|
+
case HandlerRole.TARGET:
|
|
8576
|
+
return `T${id}`;
|
|
8577
|
+
default:
|
|
8578
|
+
throw new Error(`Unknown Handler Role: ${role}`);
|
|
8579
|
+
}
|
|
8580
|
+
}
|
|
8581
|
+
function parseRoleFromHandlerId(handlerId) {
|
|
8582
|
+
switch(handlerId[0]){
|
|
8583
|
+
case 'S':
|
|
8584
|
+
return HandlerRole.SOURCE;
|
|
8585
|
+
case 'T':
|
|
8586
|
+
return HandlerRole.TARGET;
|
|
8587
|
+
default:
|
|
8588
|
+
throw new Error(`Cannot parse handler ID: ${handlerId}`);
|
|
8589
|
+
}
|
|
8590
|
+
}
|
|
8591
|
+
function mapContainsValue(map, searchValue) {
|
|
8592
|
+
const entries = map.entries();
|
|
8593
|
+
let isDone = false;
|
|
8594
|
+
do {
|
|
8595
|
+
const { done , value: [, value] , } = entries.next();
|
|
8596
|
+
if (value === searchValue) {
|
|
8597
|
+
return true;
|
|
8598
|
+
}
|
|
8599
|
+
isDone = !!done;
|
|
8600
|
+
}while (!isDone)
|
|
8601
|
+
return false;
|
|
8602
|
+
}
|
|
8603
|
+
class HandlerRegistryImpl {
|
|
8604
|
+
addSource(type, source) {
|
|
8605
|
+
validateType(type);
|
|
8606
|
+
validateSourceContract(source);
|
|
8607
|
+
const sourceId = this.addHandler(HandlerRole.SOURCE, type, source);
|
|
8608
|
+
this.store.dispatch(addSource(sourceId));
|
|
8609
|
+
return sourceId;
|
|
8610
|
+
}
|
|
8611
|
+
addTarget(type, target) {
|
|
8612
|
+
validateType(type, true);
|
|
8613
|
+
validateTargetContract(target);
|
|
8614
|
+
const targetId = this.addHandler(HandlerRole.TARGET, type, target);
|
|
8615
|
+
this.store.dispatch(addTarget(targetId));
|
|
8616
|
+
return targetId;
|
|
8617
|
+
}
|
|
8618
|
+
containsHandler(handler) {
|
|
8619
|
+
return mapContainsValue(this.dragSources, handler) || mapContainsValue(this.dropTargets, handler);
|
|
8620
|
+
}
|
|
8621
|
+
getSource(sourceId, includePinned = false) {
|
|
8622
|
+
invariant(this.isSourceId(sourceId), 'Expected a valid source ID.');
|
|
8623
|
+
const isPinned = includePinned && sourceId === this.pinnedSourceId;
|
|
8624
|
+
const source = isPinned ? this.pinnedSource : this.dragSources.get(sourceId);
|
|
8625
|
+
return source;
|
|
8626
|
+
}
|
|
8627
|
+
getTarget(targetId) {
|
|
8628
|
+
invariant(this.isTargetId(targetId), 'Expected a valid target ID.');
|
|
8629
|
+
return this.dropTargets.get(targetId);
|
|
8630
|
+
}
|
|
8631
|
+
getSourceType(sourceId) {
|
|
8632
|
+
invariant(this.isSourceId(sourceId), 'Expected a valid source ID.');
|
|
8633
|
+
return this.types.get(sourceId);
|
|
8634
|
+
}
|
|
8635
|
+
getTargetType(targetId) {
|
|
8636
|
+
invariant(this.isTargetId(targetId), 'Expected a valid target ID.');
|
|
8637
|
+
return this.types.get(targetId);
|
|
8638
|
+
}
|
|
8639
|
+
isSourceId(handlerId) {
|
|
8640
|
+
const role = parseRoleFromHandlerId(handlerId);
|
|
8641
|
+
return role === HandlerRole.SOURCE;
|
|
8642
|
+
}
|
|
8643
|
+
isTargetId(handlerId) {
|
|
8644
|
+
const role = parseRoleFromHandlerId(handlerId);
|
|
8645
|
+
return role === HandlerRole.TARGET;
|
|
8646
|
+
}
|
|
8647
|
+
removeSource(sourceId) {
|
|
8648
|
+
invariant(this.getSource(sourceId), 'Expected an existing source.');
|
|
8649
|
+
this.store.dispatch(removeSource(sourceId));
|
|
8650
|
+
asap(()=>{
|
|
8651
|
+
this.dragSources.delete(sourceId);
|
|
8652
|
+
this.types.delete(sourceId);
|
|
8653
|
+
});
|
|
8654
|
+
}
|
|
8655
|
+
removeTarget(targetId) {
|
|
8656
|
+
invariant(this.getTarget(targetId), 'Expected an existing target.');
|
|
8657
|
+
this.store.dispatch(removeTarget(targetId));
|
|
8658
|
+
this.dropTargets.delete(targetId);
|
|
8659
|
+
this.types.delete(targetId);
|
|
8660
|
+
}
|
|
8661
|
+
pinSource(sourceId) {
|
|
8662
|
+
const source = this.getSource(sourceId);
|
|
8663
|
+
invariant(source, 'Expected an existing source.');
|
|
8664
|
+
this.pinnedSourceId = sourceId;
|
|
8665
|
+
this.pinnedSource = source;
|
|
8666
|
+
}
|
|
8667
|
+
unpinSource() {
|
|
8668
|
+
invariant(this.pinnedSource, 'No source is pinned at the time.');
|
|
8669
|
+
this.pinnedSourceId = null;
|
|
8670
|
+
this.pinnedSource = null;
|
|
8671
|
+
}
|
|
8672
|
+
addHandler(role, type, handler) {
|
|
8673
|
+
const id = getNextHandlerId(role);
|
|
8674
|
+
this.types.set(id, type);
|
|
8675
|
+
if (role === HandlerRole.SOURCE) {
|
|
8676
|
+
this.dragSources.set(id, handler);
|
|
8677
|
+
} else if (role === HandlerRole.TARGET) {
|
|
8678
|
+
this.dropTargets.set(id, handler);
|
|
8679
|
+
}
|
|
8680
|
+
return id;
|
|
8681
|
+
}
|
|
8682
|
+
constructor(store){
|
|
8683
|
+
this.types = new Map();
|
|
8684
|
+
this.dragSources = new Map();
|
|
8685
|
+
this.dropTargets = new Map();
|
|
8686
|
+
this.pinnedSourceId = null;
|
|
8687
|
+
this.pinnedSource = null;
|
|
8688
|
+
this.store = store;
|
|
8689
|
+
}
|
|
8690
|
+
}
|
|
7575
8691
|
|
|
7576
|
-
|
|
7577
|
-
|
|
8692
|
+
const strictEquality = (a, b)=>a === b
|
|
8693
|
+
;
|
|
8694
|
+
/**
|
|
8695
|
+
* Determine if two cartesian coordinate offsets are equal
|
|
8696
|
+
* @param offsetA
|
|
8697
|
+
* @param offsetB
|
|
8698
|
+
*/ function areCoordsEqual(offsetA, offsetB) {
|
|
8699
|
+
if (!offsetA && !offsetB) {
|
|
8700
|
+
return true;
|
|
8701
|
+
} else if (!offsetA || !offsetB) {
|
|
8702
|
+
return false;
|
|
8703
|
+
} else {
|
|
8704
|
+
return offsetA.x === offsetB.x && offsetA.y === offsetB.y;
|
|
8705
|
+
}
|
|
8706
|
+
}
|
|
8707
|
+
/**
|
|
8708
|
+
* Determines if two arrays of items are equal
|
|
8709
|
+
* @param a The first array of items
|
|
8710
|
+
* @param b The second array of items
|
|
8711
|
+
*/ function areArraysEqual(a, b, isEqual = strictEquality) {
|
|
8712
|
+
if (a.length !== b.length) {
|
|
8713
|
+
return false;
|
|
8714
|
+
}
|
|
8715
|
+
for(let i = 0; i < a.length; ++i){
|
|
8716
|
+
if (!isEqual(a[i], b[i])) {
|
|
8717
|
+
return false;
|
|
8718
|
+
}
|
|
8719
|
+
}
|
|
8720
|
+
return true;
|
|
8721
|
+
}
|
|
7578
8722
|
|
|
7579
|
-
|
|
8723
|
+
function reduce$5(// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8724
|
+
_state = NONE, action) {
|
|
8725
|
+
switch(action.type){
|
|
8726
|
+
case HOVER:
|
|
8727
|
+
break;
|
|
8728
|
+
case ADD_SOURCE:
|
|
8729
|
+
case ADD_TARGET:
|
|
8730
|
+
case REMOVE_TARGET:
|
|
8731
|
+
case REMOVE_SOURCE:
|
|
8732
|
+
return NONE;
|
|
8733
|
+
case BEGIN_DRAG:
|
|
8734
|
+
case PUBLISH_DRAG_SOURCE:
|
|
8735
|
+
case END_DRAG:
|
|
8736
|
+
case DROP:
|
|
8737
|
+
default:
|
|
8738
|
+
return ALL;
|
|
8739
|
+
}
|
|
8740
|
+
const { targetIds =[] , prevTargetIds =[] } = action.payload;
|
|
8741
|
+
const result = xor(targetIds, prevTargetIds);
|
|
8742
|
+
const didChange = result.length > 0 || !areArraysEqual(targetIds, prevTargetIds);
|
|
8743
|
+
if (!didChange) {
|
|
8744
|
+
return NONE;
|
|
8745
|
+
}
|
|
8746
|
+
// Check the target ids at the innermost position. If they are valid, add them
|
|
8747
|
+
// to the result
|
|
8748
|
+
const prevInnermostTargetId = prevTargetIds[prevTargetIds.length - 1];
|
|
8749
|
+
const innermostTargetId = targetIds[targetIds.length - 1];
|
|
8750
|
+
if (prevInnermostTargetId !== innermostTargetId) {
|
|
8751
|
+
if (prevInnermostTargetId) {
|
|
8752
|
+
result.push(prevInnermostTargetId);
|
|
8753
|
+
}
|
|
8754
|
+
if (innermostTargetId) {
|
|
8755
|
+
result.push(innermostTargetId);
|
|
8756
|
+
}
|
|
8757
|
+
}
|
|
8758
|
+
return result;
|
|
8759
|
+
}
|
|
7580
8760
|
|
|
7581
|
-
|
|
8761
|
+
function _defineProperty$5(obj, key, value) {
|
|
8762
|
+
if (key in obj) {
|
|
8763
|
+
Object.defineProperty(obj, key, {
|
|
8764
|
+
value: value,
|
|
8765
|
+
enumerable: true,
|
|
8766
|
+
configurable: true,
|
|
8767
|
+
writable: true
|
|
8768
|
+
});
|
|
8769
|
+
} else {
|
|
8770
|
+
obj[key] = value;
|
|
8771
|
+
}
|
|
8772
|
+
return obj;
|
|
8773
|
+
}
|
|
8774
|
+
function _objectSpread$3(target) {
|
|
8775
|
+
for(var i = 1; i < arguments.length; i++){
|
|
8776
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
8777
|
+
var ownKeys = Object.keys(source);
|
|
8778
|
+
if (typeof Object.getOwnPropertySymbols === 'function') {
|
|
8779
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
8780
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
8781
|
+
}));
|
|
8782
|
+
}
|
|
8783
|
+
ownKeys.forEach(function(key) {
|
|
8784
|
+
_defineProperty$5(target, key, source[key]);
|
|
8785
|
+
});
|
|
8786
|
+
}
|
|
8787
|
+
return target;
|
|
8788
|
+
}
|
|
8789
|
+
const initialState$3 = {
|
|
8790
|
+
initialSourceClientOffset: null,
|
|
8791
|
+
initialClientOffset: null,
|
|
8792
|
+
clientOffset: null
|
|
7582
8793
|
};
|
|
7583
|
-
|
|
7584
|
-
|
|
7585
|
-
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7596
|
-
|
|
7597
|
-
|
|
7598
|
-
|
|
8794
|
+
function reduce$4(state = initialState$3, action) {
|
|
8795
|
+
const { payload } = action;
|
|
8796
|
+
switch(action.type){
|
|
8797
|
+
case INIT_COORDS:
|
|
8798
|
+
case BEGIN_DRAG:
|
|
8799
|
+
return {
|
|
8800
|
+
initialSourceClientOffset: payload.sourceClientOffset,
|
|
8801
|
+
initialClientOffset: payload.clientOffset,
|
|
8802
|
+
clientOffset: payload.clientOffset
|
|
8803
|
+
};
|
|
8804
|
+
case HOVER:
|
|
8805
|
+
if (areCoordsEqual(state.clientOffset, payload.clientOffset)) {
|
|
8806
|
+
return state;
|
|
8807
|
+
}
|
|
8808
|
+
return _objectSpread$3({}, state, {
|
|
8809
|
+
clientOffset: payload.clientOffset
|
|
8810
|
+
});
|
|
8811
|
+
case END_DRAG:
|
|
8812
|
+
case DROP:
|
|
8813
|
+
return initialState$3;
|
|
8814
|
+
default:
|
|
8815
|
+
return state;
|
|
8816
|
+
}
|
|
8817
|
+
}
|
|
8818
|
+
|
|
8819
|
+
function _defineProperty$4(obj, key, value) {
|
|
8820
|
+
if (key in obj) {
|
|
8821
|
+
Object.defineProperty(obj, key, {
|
|
8822
|
+
value: value,
|
|
8823
|
+
enumerable: true,
|
|
8824
|
+
configurable: true,
|
|
8825
|
+
writable: true
|
|
8826
|
+
});
|
|
8827
|
+
} else {
|
|
8828
|
+
obj[key] = value;
|
|
8829
|
+
}
|
|
8830
|
+
return obj;
|
|
8831
|
+
}
|
|
8832
|
+
function _objectSpread$2(target) {
|
|
8833
|
+
for(var i = 1; i < arguments.length; i++){
|
|
8834
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
8835
|
+
var ownKeys = Object.keys(source);
|
|
8836
|
+
if (typeof Object.getOwnPropertySymbols === 'function') {
|
|
8837
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
8838
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
8839
|
+
}));
|
|
7599
8840
|
}
|
|
8841
|
+
ownKeys.forEach(function(key) {
|
|
8842
|
+
_defineProperty$4(target, key, source[key]);
|
|
8843
|
+
});
|
|
7600
8844
|
}
|
|
7601
|
-
|
|
7602
|
-
|
|
7603
|
-
|
|
7604
|
-
|
|
7605
|
-
|
|
7606
|
-
|
|
7607
|
-
|
|
7608
|
-
|
|
8845
|
+
return target;
|
|
8846
|
+
}
|
|
8847
|
+
const initialState$2 = {
|
|
8848
|
+
itemType: null,
|
|
8849
|
+
item: null,
|
|
8850
|
+
sourceId: null,
|
|
8851
|
+
targetIds: [],
|
|
8852
|
+
dropResult: null,
|
|
8853
|
+
didDrop: false,
|
|
8854
|
+
isSourcePublic: null
|
|
8855
|
+
};
|
|
8856
|
+
function reduce$3(state = initialState$2, action) {
|
|
8857
|
+
const { payload } = action;
|
|
8858
|
+
switch(action.type){
|
|
8859
|
+
case BEGIN_DRAG:
|
|
8860
|
+
return _objectSpread$2({}, state, {
|
|
8861
|
+
itemType: payload.itemType,
|
|
8862
|
+
item: payload.item,
|
|
8863
|
+
sourceId: payload.sourceId,
|
|
8864
|
+
isSourcePublic: payload.isSourcePublic,
|
|
8865
|
+
dropResult: null,
|
|
8866
|
+
didDrop: false
|
|
8867
|
+
});
|
|
8868
|
+
case PUBLISH_DRAG_SOURCE:
|
|
8869
|
+
return _objectSpread$2({}, state, {
|
|
8870
|
+
isSourcePublic: true
|
|
8871
|
+
});
|
|
8872
|
+
case HOVER:
|
|
8873
|
+
return _objectSpread$2({}, state, {
|
|
8874
|
+
targetIds: payload.targetIds
|
|
8875
|
+
});
|
|
8876
|
+
case REMOVE_TARGET:
|
|
8877
|
+
if (state.targetIds.indexOf(payload.targetId) === -1) {
|
|
8878
|
+
return state;
|
|
8879
|
+
}
|
|
8880
|
+
return _objectSpread$2({}, state, {
|
|
8881
|
+
targetIds: without$1(state.targetIds, payload.targetId)
|
|
8882
|
+
});
|
|
8883
|
+
case DROP:
|
|
8884
|
+
return _objectSpread$2({}, state, {
|
|
8885
|
+
dropResult: payload.dropResult,
|
|
8886
|
+
didDrop: true,
|
|
8887
|
+
targetIds: []
|
|
8888
|
+
});
|
|
8889
|
+
case END_DRAG:
|
|
8890
|
+
return _objectSpread$2({}, state, {
|
|
8891
|
+
itemType: null,
|
|
8892
|
+
item: null,
|
|
8893
|
+
sourceId: null,
|
|
8894
|
+
dropResult: null,
|
|
8895
|
+
didDrop: false,
|
|
8896
|
+
isSourcePublic: null,
|
|
8897
|
+
targetIds: []
|
|
8898
|
+
});
|
|
8899
|
+
default:
|
|
8900
|
+
return state;
|
|
8901
|
+
}
|
|
8902
|
+
}
|
|
8903
|
+
|
|
8904
|
+
function reduce$2(state = 0, action) {
|
|
8905
|
+
switch(action.type){
|
|
8906
|
+
case ADD_SOURCE:
|
|
8907
|
+
case ADD_TARGET:
|
|
8908
|
+
return state + 1;
|
|
8909
|
+
case REMOVE_SOURCE:
|
|
8910
|
+
case REMOVE_TARGET:
|
|
8911
|
+
return state - 1;
|
|
8912
|
+
default:
|
|
8913
|
+
return state;
|
|
8914
|
+
}
|
|
8915
|
+
}
|
|
8916
|
+
|
|
8917
|
+
function reduce$1(state = 0) {
|
|
8918
|
+
return state + 1;
|
|
8919
|
+
}
|
|
8920
|
+
|
|
8921
|
+
function _defineProperty$3(obj, key, value) {
|
|
8922
|
+
if (key in obj) {
|
|
8923
|
+
Object.defineProperty(obj, key, {
|
|
8924
|
+
value: value,
|
|
8925
|
+
enumerable: true,
|
|
8926
|
+
configurable: true,
|
|
8927
|
+
writable: true
|
|
8928
|
+
});
|
|
8929
|
+
} else {
|
|
8930
|
+
obj[key] = value;
|
|
8931
|
+
}
|
|
8932
|
+
return obj;
|
|
8933
|
+
}
|
|
8934
|
+
function _objectSpread$1(target) {
|
|
8935
|
+
for(var i = 1; i < arguments.length; i++){
|
|
8936
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
8937
|
+
var ownKeys = Object.keys(source);
|
|
8938
|
+
if (typeof Object.getOwnPropertySymbols === 'function') {
|
|
8939
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
8940
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
7609
8941
|
}));
|
|
7610
|
-
error.name = 'Invariant Violation';
|
|
7611
8942
|
}
|
|
7612
|
-
|
|
7613
|
-
|
|
7614
|
-
|
|
8943
|
+
ownKeys.forEach(function(key) {
|
|
8944
|
+
_defineProperty$3(target, key, source[key]);
|
|
8945
|
+
});
|
|
7615
8946
|
}
|
|
8947
|
+
return target;
|
|
7616
8948
|
}
|
|
7617
|
-
function
|
|
7618
|
-
return
|
|
8949
|
+
function reduce(state = {}, action) {
|
|
8950
|
+
return {
|
|
8951
|
+
dirtyHandlerIds: reduce$5(state.dirtyHandlerIds, {
|
|
8952
|
+
type: action.type,
|
|
8953
|
+
payload: _objectSpread$1({}, action.payload, {
|
|
8954
|
+
prevTargetIds: get(state, 'dragOperation.targetIds', [])
|
|
8955
|
+
})
|
|
8956
|
+
}),
|
|
8957
|
+
dragOffset: reduce$4(state.dragOffset, action),
|
|
8958
|
+
refCount: reduce$2(state.refCount, action),
|
|
8959
|
+
dragOperation: reduce$3(state.dragOperation, action),
|
|
8960
|
+
stateId: reduce$1(state.stateId)
|
|
8961
|
+
};
|
|
7619
8962
|
}
|
|
7620
8963
|
|
|
7621
|
-
|
|
7622
|
-
|
|
7623
|
-
|
|
7624
|
-
|
|
8964
|
+
function createDragDropManager(backendFactory, globalContext = undefined, backendOptions = {}, debugMode = false) {
|
|
8965
|
+
const store = makeStoreInstance(debugMode);
|
|
8966
|
+
const monitor = new DragDropMonitorImpl(store, new HandlerRegistryImpl(store));
|
|
8967
|
+
const manager = new DragDropManagerImpl(store, monitor);
|
|
8968
|
+
const backend = backendFactory(manager, globalContext, backendOptions);
|
|
8969
|
+
manager.receiveBackend(backend);
|
|
8970
|
+
return manager;
|
|
8971
|
+
}
|
|
8972
|
+
function makeStoreInstance(debugMode) {
|
|
8973
|
+
// TODO: if we ever make a react-native version of this,
|
|
8974
|
+
// we'll need to consider how to pull off dev-tooling
|
|
8975
|
+
const reduxDevTools = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__;
|
|
8976
|
+
return createStore(reduce, debugMode && reduxDevTools && reduxDevTools({
|
|
8977
|
+
name: 'dnd-core',
|
|
8978
|
+
instanceId: 'dnd-core'
|
|
8979
|
+
}));
|
|
8980
|
+
}
|
|
8981
|
+
|
|
8982
|
+
function _objectWithoutProperties(source, excluded) {
|
|
8983
|
+
if (source == null) return {};
|
|
8984
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
8985
|
+
var key, i;
|
|
8986
|
+
if (Object.getOwnPropertySymbols) {
|
|
8987
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
8988
|
+
for(i = 0; i < sourceSymbolKeys.length; i++){
|
|
8989
|
+
key = sourceSymbolKeys[i];
|
|
8990
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
8991
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
8992
|
+
target[key] = source[key];
|
|
8993
|
+
}
|
|
8994
|
+
}
|
|
8995
|
+
return target;
|
|
8996
|
+
}
|
|
8997
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
8998
|
+
if (source == null) return {};
|
|
8999
|
+
var target = {};
|
|
9000
|
+
var sourceKeys = Object.keys(source);
|
|
9001
|
+
var key, i;
|
|
9002
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
9003
|
+
key = sourceKeys[i];
|
|
9004
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
9005
|
+
target[key] = source[key];
|
|
9006
|
+
}
|
|
9007
|
+
return target;
|
|
9008
|
+
}
|
|
9009
|
+
let refCount = 0;
|
|
9010
|
+
const INSTANCE_SYM = Symbol.for('__REACT_DND_CONTEXT_INSTANCE__');
|
|
9011
|
+
var DndProvider = /*#__PURE__*/ memo(function DndProvider(_param) {
|
|
9012
|
+
var { children } = _param, props = _objectWithoutProperties(_param, [
|
|
9013
|
+
"children"
|
|
9014
|
+
]);
|
|
9015
|
+
const [manager, isGlobalInstance] = getDndContextValue(props) // memoized from props
|
|
9016
|
+
;
|
|
9017
|
+
/**
|
|
9018
|
+
* If the global context was used to store the DND context
|
|
9019
|
+
* then where theres no more references to it we should
|
|
9020
|
+
* clean it up to avoid memory leaks
|
|
9021
|
+
*/ useEffect(()=>{
|
|
9022
|
+
if (isGlobalInstance) {
|
|
9023
|
+
const context = getGlobalContext();
|
|
9024
|
+
++refCount;
|
|
9025
|
+
return ()=>{
|
|
9026
|
+
if (--refCount === 0) {
|
|
9027
|
+
context[INSTANCE_SYM] = null;
|
|
9028
|
+
}
|
|
9029
|
+
};
|
|
9030
|
+
}
|
|
9031
|
+
return;
|
|
9032
|
+
}, []);
|
|
9033
|
+
return /*#__PURE__*/ jsx(DndContext.Provider, {
|
|
9034
|
+
value: manager,
|
|
9035
|
+
children: children
|
|
9036
|
+
});
|
|
7625
9037
|
});
|
|
9038
|
+
function getDndContextValue(props) {
|
|
9039
|
+
if ('manager' in props) {
|
|
9040
|
+
const manager = {
|
|
9041
|
+
dragDropManager: props.manager
|
|
9042
|
+
};
|
|
9043
|
+
return [
|
|
9044
|
+
manager,
|
|
9045
|
+
false
|
|
9046
|
+
];
|
|
9047
|
+
}
|
|
9048
|
+
const manager = createSingletonDndContext(props.backend, props.context, props.options, props.debugMode);
|
|
9049
|
+
const isGlobalInstance = !props.context;
|
|
9050
|
+
return [
|
|
9051
|
+
manager,
|
|
9052
|
+
isGlobalInstance
|
|
9053
|
+
];
|
|
9054
|
+
}
|
|
9055
|
+
function createSingletonDndContext(backend, context = getGlobalContext(), options, debugMode) {
|
|
9056
|
+
const ctx = context;
|
|
9057
|
+
if (!ctx[INSTANCE_SYM]) {
|
|
9058
|
+
ctx[INSTANCE_SYM] = {
|
|
9059
|
+
dragDropManager: createDragDropManager(backend, context, options, debugMode)
|
|
9060
|
+
};
|
|
9061
|
+
}
|
|
9062
|
+
return ctx[INSTANCE_SYM];
|
|
9063
|
+
}
|
|
9064
|
+
function getGlobalContext() {
|
|
9065
|
+
return typeof global !== 'undefined' ? global : window;
|
|
9066
|
+
}
|
|
7626
9067
|
|
|
7627
9068
|
// do not edit .js files directly - edit src/index.jst
|
|
7628
9069
|
|
|
@@ -8560,6 +10001,1368 @@ function useRegisteredDropTarget(spec, monitor, connector) {
|
|
|
8560
10001
|
];
|
|
8561
10002
|
}
|
|
8562
10003
|
|
|
10004
|
+
// cheap lodash replacements
|
|
10005
|
+
function memoize(fn) {
|
|
10006
|
+
let result = null;
|
|
10007
|
+
const memoized = ()=>{
|
|
10008
|
+
if (result == null) {
|
|
10009
|
+
result = fn();
|
|
10010
|
+
}
|
|
10011
|
+
return result;
|
|
10012
|
+
};
|
|
10013
|
+
return memoized;
|
|
10014
|
+
}
|
|
10015
|
+
/**
|
|
10016
|
+
* drop-in replacement for _.without
|
|
10017
|
+
*/ function without(items, item) {
|
|
10018
|
+
return items.filter((i)=>i !== item
|
|
10019
|
+
);
|
|
10020
|
+
}
|
|
10021
|
+
function union(itemsA, itemsB) {
|
|
10022
|
+
const set = new Set();
|
|
10023
|
+
const insertItem = (item)=>set.add(item)
|
|
10024
|
+
;
|
|
10025
|
+
itemsA.forEach(insertItem);
|
|
10026
|
+
itemsB.forEach(insertItem);
|
|
10027
|
+
const result = [];
|
|
10028
|
+
set.forEach((key)=>result.push(key)
|
|
10029
|
+
);
|
|
10030
|
+
return result;
|
|
10031
|
+
}
|
|
10032
|
+
|
|
10033
|
+
class EnterLeaveCounter {
|
|
10034
|
+
enter(enteringNode) {
|
|
10035
|
+
const previousLength = this.entered.length;
|
|
10036
|
+
const isNodeEntered = (node)=>this.isNodeInDocument(node) && (!node.contains || node.contains(enteringNode))
|
|
10037
|
+
;
|
|
10038
|
+
this.entered = union(this.entered.filter(isNodeEntered), [
|
|
10039
|
+
enteringNode
|
|
10040
|
+
]);
|
|
10041
|
+
return previousLength === 0 && this.entered.length > 0;
|
|
10042
|
+
}
|
|
10043
|
+
leave(leavingNode) {
|
|
10044
|
+
const previousLength = this.entered.length;
|
|
10045
|
+
this.entered = without(this.entered.filter(this.isNodeInDocument), leavingNode);
|
|
10046
|
+
return previousLength > 0 && this.entered.length === 0;
|
|
10047
|
+
}
|
|
10048
|
+
reset() {
|
|
10049
|
+
this.entered = [];
|
|
10050
|
+
}
|
|
10051
|
+
constructor(isNodeInDocument){
|
|
10052
|
+
this.entered = [];
|
|
10053
|
+
this.isNodeInDocument = isNodeInDocument;
|
|
10054
|
+
}
|
|
10055
|
+
}
|
|
10056
|
+
|
|
10057
|
+
class NativeDragSource {
|
|
10058
|
+
initializeExposedProperties() {
|
|
10059
|
+
Object.keys(this.config.exposeProperties).forEach((property)=>{
|
|
10060
|
+
Object.defineProperty(this.item, property, {
|
|
10061
|
+
configurable: true,
|
|
10062
|
+
enumerable: true,
|
|
10063
|
+
get () {
|
|
10064
|
+
// eslint-disable-next-line no-console
|
|
10065
|
+
console.warn(`Browser doesn't allow reading "${property}" until the drop event.`);
|
|
10066
|
+
return null;
|
|
10067
|
+
}
|
|
10068
|
+
});
|
|
10069
|
+
});
|
|
10070
|
+
}
|
|
10071
|
+
loadDataTransfer(dataTransfer) {
|
|
10072
|
+
if (dataTransfer) {
|
|
10073
|
+
const newProperties = {};
|
|
10074
|
+
Object.keys(this.config.exposeProperties).forEach((property)=>{
|
|
10075
|
+
const propertyFn = this.config.exposeProperties[property];
|
|
10076
|
+
if (propertyFn != null) {
|
|
10077
|
+
newProperties[property] = {
|
|
10078
|
+
value: propertyFn(dataTransfer, this.config.matchesTypes),
|
|
10079
|
+
configurable: true,
|
|
10080
|
+
enumerable: true
|
|
10081
|
+
};
|
|
10082
|
+
}
|
|
10083
|
+
});
|
|
10084
|
+
Object.defineProperties(this.item, newProperties);
|
|
10085
|
+
}
|
|
10086
|
+
}
|
|
10087
|
+
canDrag() {
|
|
10088
|
+
return true;
|
|
10089
|
+
}
|
|
10090
|
+
beginDrag() {
|
|
10091
|
+
return this.item;
|
|
10092
|
+
}
|
|
10093
|
+
isDragging(monitor, handle) {
|
|
10094
|
+
return handle === monitor.getSourceId();
|
|
10095
|
+
}
|
|
10096
|
+
endDrag() {
|
|
10097
|
+
// empty
|
|
10098
|
+
}
|
|
10099
|
+
constructor(config){
|
|
10100
|
+
this.config = config;
|
|
10101
|
+
this.item = {};
|
|
10102
|
+
this.initializeExposedProperties();
|
|
10103
|
+
}
|
|
10104
|
+
}
|
|
10105
|
+
|
|
10106
|
+
const FILE = '__NATIVE_FILE__';
|
|
10107
|
+
const URL = '__NATIVE_URL__';
|
|
10108
|
+
const TEXT = '__NATIVE_TEXT__';
|
|
10109
|
+
const HTML = '__NATIVE_HTML__';
|
|
10110
|
+
|
|
10111
|
+
var NativeTypes = /*#__PURE__*/Object.freeze({
|
|
10112
|
+
__proto__: null,
|
|
10113
|
+
FILE: FILE,
|
|
10114
|
+
URL: URL,
|
|
10115
|
+
TEXT: TEXT,
|
|
10116
|
+
HTML: HTML
|
|
10117
|
+
});
|
|
10118
|
+
|
|
10119
|
+
function getDataFromDataTransfer(dataTransfer, typesToTry, defaultValue) {
|
|
10120
|
+
const result = typesToTry.reduce((resultSoFar, typeToTry)=>resultSoFar || dataTransfer.getData(typeToTry)
|
|
10121
|
+
, '');
|
|
10122
|
+
return result != null ? result : defaultValue;
|
|
10123
|
+
}
|
|
10124
|
+
|
|
10125
|
+
const nativeTypesConfig = {
|
|
10126
|
+
[FILE]: {
|
|
10127
|
+
exposeProperties: {
|
|
10128
|
+
files: (dataTransfer)=>Array.prototype.slice.call(dataTransfer.files)
|
|
10129
|
+
,
|
|
10130
|
+
items: (dataTransfer)=>dataTransfer.items
|
|
10131
|
+
,
|
|
10132
|
+
dataTransfer: (dataTransfer)=>dataTransfer
|
|
10133
|
+
},
|
|
10134
|
+
matchesTypes: [
|
|
10135
|
+
'Files'
|
|
10136
|
+
]
|
|
10137
|
+
},
|
|
10138
|
+
[HTML]: {
|
|
10139
|
+
exposeProperties: {
|
|
10140
|
+
html: (dataTransfer, matchesTypes)=>getDataFromDataTransfer(dataTransfer, matchesTypes, '')
|
|
10141
|
+
,
|
|
10142
|
+
dataTransfer: (dataTransfer)=>dataTransfer
|
|
10143
|
+
},
|
|
10144
|
+
matchesTypes: [
|
|
10145
|
+
'Html',
|
|
10146
|
+
'text/html'
|
|
10147
|
+
]
|
|
10148
|
+
},
|
|
10149
|
+
[URL]: {
|
|
10150
|
+
exposeProperties: {
|
|
10151
|
+
urls: (dataTransfer, matchesTypes)=>getDataFromDataTransfer(dataTransfer, matchesTypes, '').split('\n')
|
|
10152
|
+
,
|
|
10153
|
+
dataTransfer: (dataTransfer)=>dataTransfer
|
|
10154
|
+
},
|
|
10155
|
+
matchesTypes: [
|
|
10156
|
+
'Url',
|
|
10157
|
+
'text/uri-list'
|
|
10158
|
+
]
|
|
10159
|
+
},
|
|
10160
|
+
[TEXT]: {
|
|
10161
|
+
exposeProperties: {
|
|
10162
|
+
text: (dataTransfer, matchesTypes)=>getDataFromDataTransfer(dataTransfer, matchesTypes, '')
|
|
10163
|
+
,
|
|
10164
|
+
dataTransfer: (dataTransfer)=>dataTransfer
|
|
10165
|
+
},
|
|
10166
|
+
matchesTypes: [
|
|
10167
|
+
'Text',
|
|
10168
|
+
'text/plain'
|
|
10169
|
+
]
|
|
10170
|
+
}
|
|
10171
|
+
};
|
|
10172
|
+
|
|
10173
|
+
function createNativeDragSource(type, dataTransfer) {
|
|
10174
|
+
const config = nativeTypesConfig[type];
|
|
10175
|
+
if (!config) {
|
|
10176
|
+
throw new Error(`native type ${type} has no configuration`);
|
|
10177
|
+
}
|
|
10178
|
+
const result = new NativeDragSource(config);
|
|
10179
|
+
result.loadDataTransfer(dataTransfer);
|
|
10180
|
+
return result;
|
|
10181
|
+
}
|
|
10182
|
+
function matchNativeItemType(dataTransfer) {
|
|
10183
|
+
if (!dataTransfer) {
|
|
10184
|
+
return null;
|
|
10185
|
+
}
|
|
10186
|
+
const dataTransferTypes = Array.prototype.slice.call(dataTransfer.types || []);
|
|
10187
|
+
return Object.keys(nativeTypesConfig).filter((nativeItemType)=>{
|
|
10188
|
+
const typeConfig = nativeTypesConfig[nativeItemType];
|
|
10189
|
+
if (!(typeConfig === null || typeConfig === void 0 ? void 0 : typeConfig.matchesTypes)) {
|
|
10190
|
+
return false;
|
|
10191
|
+
}
|
|
10192
|
+
return typeConfig.matchesTypes.some((t)=>dataTransferTypes.indexOf(t) > -1
|
|
10193
|
+
);
|
|
10194
|
+
})[0] || null;
|
|
10195
|
+
}
|
|
10196
|
+
|
|
10197
|
+
const isFirefox = memoize(()=>/firefox/i.test(navigator.userAgent)
|
|
10198
|
+
);
|
|
10199
|
+
const isSafari = memoize(()=>Boolean(window.safari)
|
|
10200
|
+
);
|
|
10201
|
+
|
|
10202
|
+
class MonotonicInterpolant {
|
|
10203
|
+
interpolate(x) {
|
|
10204
|
+
const { xs , ys , c1s , c2s , c3s } = this;
|
|
10205
|
+
// The rightmost point in the dataset should give an exact result
|
|
10206
|
+
let i = xs.length - 1;
|
|
10207
|
+
if (x === xs[i]) {
|
|
10208
|
+
return ys[i];
|
|
10209
|
+
}
|
|
10210
|
+
// Search for the interval x is in, returning the corresponding y if x is one of the original xs
|
|
10211
|
+
let low = 0;
|
|
10212
|
+
let high = c3s.length - 1;
|
|
10213
|
+
let mid;
|
|
10214
|
+
while(low <= high){
|
|
10215
|
+
mid = Math.floor(0.5 * (low + high));
|
|
10216
|
+
const xHere = xs[mid];
|
|
10217
|
+
if (xHere < x) {
|
|
10218
|
+
low = mid + 1;
|
|
10219
|
+
} else if (xHere > x) {
|
|
10220
|
+
high = mid - 1;
|
|
10221
|
+
} else {
|
|
10222
|
+
return ys[mid];
|
|
10223
|
+
}
|
|
10224
|
+
}
|
|
10225
|
+
i = Math.max(0, high);
|
|
10226
|
+
// Interpolate
|
|
10227
|
+
const diff = x - xs[i];
|
|
10228
|
+
const diffSq = diff * diff;
|
|
10229
|
+
return ys[i] + c1s[i] * diff + c2s[i] * diffSq + c3s[i] * diff * diffSq;
|
|
10230
|
+
}
|
|
10231
|
+
constructor(xs, ys){
|
|
10232
|
+
const { length } = xs;
|
|
10233
|
+
// Rearrange xs and ys so that xs is sorted
|
|
10234
|
+
const indexes = [];
|
|
10235
|
+
for(let i = 0; i < length; i++){
|
|
10236
|
+
indexes.push(i);
|
|
10237
|
+
}
|
|
10238
|
+
indexes.sort((a, b)=>xs[a] < xs[b] ? -1 : 1
|
|
10239
|
+
);
|
|
10240
|
+
const dxs = [];
|
|
10241
|
+
const ms = [];
|
|
10242
|
+
let dx;
|
|
10243
|
+
let dy;
|
|
10244
|
+
for(let i1 = 0; i1 < length - 1; i1++){
|
|
10245
|
+
dx = xs[i1 + 1] - xs[i1];
|
|
10246
|
+
dy = ys[i1 + 1] - ys[i1];
|
|
10247
|
+
dxs.push(dx);
|
|
10248
|
+
ms.push(dy / dx);
|
|
10249
|
+
}
|
|
10250
|
+
// Get degree-1 coefficients
|
|
10251
|
+
const c1s = [
|
|
10252
|
+
ms[0]
|
|
10253
|
+
];
|
|
10254
|
+
for(let i2 = 0; i2 < dxs.length - 1; i2++){
|
|
10255
|
+
const m2 = ms[i2];
|
|
10256
|
+
const mNext = ms[i2 + 1];
|
|
10257
|
+
if (m2 * mNext <= 0) {
|
|
10258
|
+
c1s.push(0);
|
|
10259
|
+
} else {
|
|
10260
|
+
dx = dxs[i2];
|
|
10261
|
+
const dxNext = dxs[i2 + 1];
|
|
10262
|
+
const common = dx + dxNext;
|
|
10263
|
+
c1s.push(3 * common / ((common + dxNext) / m2 + (common + dx) / mNext));
|
|
10264
|
+
}
|
|
10265
|
+
}
|
|
10266
|
+
c1s.push(ms[ms.length - 1]);
|
|
10267
|
+
// Get degree-2 and degree-3 coefficients
|
|
10268
|
+
const c2s = [];
|
|
10269
|
+
const c3s = [];
|
|
10270
|
+
let m;
|
|
10271
|
+
for(let i3 = 0; i3 < c1s.length - 1; i3++){
|
|
10272
|
+
m = ms[i3];
|
|
10273
|
+
const c1 = c1s[i3];
|
|
10274
|
+
const invDx = 1 / dxs[i3];
|
|
10275
|
+
const common = c1 + c1s[i3 + 1] - m - m;
|
|
10276
|
+
c2s.push((m - c1 - common) * invDx);
|
|
10277
|
+
c3s.push(common * invDx * invDx);
|
|
10278
|
+
}
|
|
10279
|
+
this.xs = xs;
|
|
10280
|
+
this.ys = ys;
|
|
10281
|
+
this.c1s = c1s;
|
|
10282
|
+
this.c2s = c2s;
|
|
10283
|
+
this.c3s = c3s;
|
|
10284
|
+
}
|
|
10285
|
+
}
|
|
10286
|
+
|
|
10287
|
+
const ELEMENT_NODE = 1;
|
|
10288
|
+
function getNodeClientOffset(node) {
|
|
10289
|
+
const el = node.nodeType === ELEMENT_NODE ? node : node.parentElement;
|
|
10290
|
+
if (!el) {
|
|
10291
|
+
return null;
|
|
10292
|
+
}
|
|
10293
|
+
const { top , left } = el.getBoundingClientRect();
|
|
10294
|
+
return {
|
|
10295
|
+
x: left,
|
|
10296
|
+
y: top
|
|
10297
|
+
};
|
|
10298
|
+
}
|
|
10299
|
+
function getEventClientOffset(e) {
|
|
10300
|
+
return {
|
|
10301
|
+
x: e.clientX,
|
|
10302
|
+
y: e.clientY
|
|
10303
|
+
};
|
|
10304
|
+
}
|
|
10305
|
+
function isImageNode(node) {
|
|
10306
|
+
var ref;
|
|
10307
|
+
return node.nodeName === 'IMG' && (isFirefox() || !((ref = document.documentElement) === null || ref === void 0 ? void 0 : ref.contains(node)));
|
|
10308
|
+
}
|
|
10309
|
+
function getDragPreviewSize(isImage, dragPreview, sourceWidth, sourceHeight) {
|
|
10310
|
+
let dragPreviewWidth = isImage ? dragPreview.width : sourceWidth;
|
|
10311
|
+
let dragPreviewHeight = isImage ? dragPreview.height : sourceHeight;
|
|
10312
|
+
// Work around @2x coordinate discrepancies in browsers
|
|
10313
|
+
if (isSafari() && isImage) {
|
|
10314
|
+
dragPreviewHeight /= window.devicePixelRatio;
|
|
10315
|
+
dragPreviewWidth /= window.devicePixelRatio;
|
|
10316
|
+
}
|
|
10317
|
+
return {
|
|
10318
|
+
dragPreviewWidth,
|
|
10319
|
+
dragPreviewHeight
|
|
10320
|
+
};
|
|
10321
|
+
}
|
|
10322
|
+
function getDragPreviewOffset(sourceNode, dragPreview, clientOffset, anchorPoint, offsetPoint) {
|
|
10323
|
+
// The browsers will use the image intrinsic size under different conditions.
|
|
10324
|
+
// Firefox only cares if it's an image, but WebKit also wants it to be detached.
|
|
10325
|
+
const isImage = isImageNode(dragPreview);
|
|
10326
|
+
const dragPreviewNode = isImage ? sourceNode : dragPreview;
|
|
10327
|
+
const dragPreviewNodeOffsetFromClient = getNodeClientOffset(dragPreviewNode);
|
|
10328
|
+
const offsetFromDragPreview = {
|
|
10329
|
+
x: clientOffset.x - dragPreviewNodeOffsetFromClient.x,
|
|
10330
|
+
y: clientOffset.y - dragPreviewNodeOffsetFromClient.y
|
|
10331
|
+
};
|
|
10332
|
+
const { offsetWidth: sourceWidth , offsetHeight: sourceHeight } = sourceNode;
|
|
10333
|
+
const { anchorX , anchorY } = anchorPoint;
|
|
10334
|
+
const { dragPreviewWidth , dragPreviewHeight } = getDragPreviewSize(isImage, dragPreview, sourceWidth, sourceHeight);
|
|
10335
|
+
const calculateYOffset = ()=>{
|
|
10336
|
+
const interpolantY = new MonotonicInterpolant([
|
|
10337
|
+
0,
|
|
10338
|
+
0.5,
|
|
10339
|
+
1
|
|
10340
|
+
], [
|
|
10341
|
+
// Dock to the top
|
|
10342
|
+
offsetFromDragPreview.y,
|
|
10343
|
+
// Align at the center
|
|
10344
|
+
(offsetFromDragPreview.y / sourceHeight) * dragPreviewHeight,
|
|
10345
|
+
// Dock to the bottom
|
|
10346
|
+
offsetFromDragPreview.y + dragPreviewHeight - sourceHeight,
|
|
10347
|
+
]);
|
|
10348
|
+
let y = interpolantY.interpolate(anchorY);
|
|
10349
|
+
// Work around Safari 8 positioning bug
|
|
10350
|
+
if (isSafari() && isImage) {
|
|
10351
|
+
// We'll have to wait for @3x to see if this is entirely correct
|
|
10352
|
+
y += (window.devicePixelRatio - 1) * dragPreviewHeight;
|
|
10353
|
+
}
|
|
10354
|
+
return y;
|
|
10355
|
+
};
|
|
10356
|
+
const calculateXOffset = ()=>{
|
|
10357
|
+
// Interpolate coordinates depending on anchor point
|
|
10358
|
+
// If you know a simpler way to do this, let me know
|
|
10359
|
+
const interpolantX = new MonotonicInterpolant([
|
|
10360
|
+
0,
|
|
10361
|
+
0.5,
|
|
10362
|
+
1
|
|
10363
|
+
], [
|
|
10364
|
+
// Dock to the left
|
|
10365
|
+
offsetFromDragPreview.x,
|
|
10366
|
+
// Align at the center
|
|
10367
|
+
(offsetFromDragPreview.x / sourceWidth) * dragPreviewWidth,
|
|
10368
|
+
// Dock to the right
|
|
10369
|
+
offsetFromDragPreview.x + dragPreviewWidth - sourceWidth,
|
|
10370
|
+
]);
|
|
10371
|
+
return interpolantX.interpolate(anchorX);
|
|
10372
|
+
};
|
|
10373
|
+
// Force offsets if specified in the options.
|
|
10374
|
+
const { offsetX , offsetY } = offsetPoint;
|
|
10375
|
+
const isManualOffsetX = offsetX === 0 || offsetX;
|
|
10376
|
+
const isManualOffsetY = offsetY === 0 || offsetY;
|
|
10377
|
+
return {
|
|
10378
|
+
x: isManualOffsetX ? offsetX : calculateXOffset(),
|
|
10379
|
+
y: isManualOffsetY ? offsetY : calculateYOffset()
|
|
10380
|
+
};
|
|
10381
|
+
}
|
|
10382
|
+
|
|
10383
|
+
class OptionsReader {
|
|
10384
|
+
get window() {
|
|
10385
|
+
if (this.globalContext) {
|
|
10386
|
+
return this.globalContext;
|
|
10387
|
+
} else if (typeof window !== 'undefined') {
|
|
10388
|
+
return window;
|
|
10389
|
+
}
|
|
10390
|
+
return undefined;
|
|
10391
|
+
}
|
|
10392
|
+
get document() {
|
|
10393
|
+
var ref;
|
|
10394
|
+
if ((ref = this.globalContext) === null || ref === void 0 ? void 0 : ref.document) {
|
|
10395
|
+
return this.globalContext.document;
|
|
10396
|
+
} else if (this.window) {
|
|
10397
|
+
return this.window.document;
|
|
10398
|
+
} else {
|
|
10399
|
+
return undefined;
|
|
10400
|
+
}
|
|
10401
|
+
}
|
|
10402
|
+
get rootElement() {
|
|
10403
|
+
var ref;
|
|
10404
|
+
return ((ref = this.optionsArgs) === null || ref === void 0 ? void 0 : ref.rootElement) || this.window;
|
|
10405
|
+
}
|
|
10406
|
+
constructor(globalContext, options){
|
|
10407
|
+
this.ownerDocument = null;
|
|
10408
|
+
this.globalContext = globalContext;
|
|
10409
|
+
this.optionsArgs = options;
|
|
10410
|
+
}
|
|
10411
|
+
}
|
|
10412
|
+
|
|
10413
|
+
function _defineProperty$2(obj, key, value) {
|
|
10414
|
+
if (key in obj) {
|
|
10415
|
+
Object.defineProperty(obj, key, {
|
|
10416
|
+
value: value,
|
|
10417
|
+
enumerable: true,
|
|
10418
|
+
configurable: true,
|
|
10419
|
+
writable: true
|
|
10420
|
+
});
|
|
10421
|
+
} else {
|
|
10422
|
+
obj[key] = value;
|
|
10423
|
+
}
|
|
10424
|
+
return obj;
|
|
10425
|
+
}
|
|
10426
|
+
function _objectSpread(target) {
|
|
10427
|
+
for(var i = 1; i < arguments.length; i++){
|
|
10428
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
10429
|
+
var ownKeys = Object.keys(source);
|
|
10430
|
+
if (typeof Object.getOwnPropertySymbols === 'function') {
|
|
10431
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
10432
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
10433
|
+
}));
|
|
10434
|
+
}
|
|
10435
|
+
ownKeys.forEach(function(key) {
|
|
10436
|
+
_defineProperty$2(target, key, source[key]);
|
|
10437
|
+
});
|
|
10438
|
+
}
|
|
10439
|
+
return target;
|
|
10440
|
+
}
|
|
10441
|
+
class HTML5BackendImpl {
|
|
10442
|
+
/**
|
|
10443
|
+
* Generate profiling statistics for the HTML5Backend.
|
|
10444
|
+
*/ profile() {
|
|
10445
|
+
var ref, ref1;
|
|
10446
|
+
return {
|
|
10447
|
+
sourcePreviewNodes: this.sourcePreviewNodes.size,
|
|
10448
|
+
sourcePreviewNodeOptions: this.sourcePreviewNodeOptions.size,
|
|
10449
|
+
sourceNodeOptions: this.sourceNodeOptions.size,
|
|
10450
|
+
sourceNodes: this.sourceNodes.size,
|
|
10451
|
+
dragStartSourceIds: ((ref = this.dragStartSourceIds) === null || ref === void 0 ? void 0 : ref.length) || 0,
|
|
10452
|
+
dropTargetIds: this.dropTargetIds.length,
|
|
10453
|
+
dragEnterTargetIds: this.dragEnterTargetIds.length,
|
|
10454
|
+
dragOverTargetIds: ((ref1 = this.dragOverTargetIds) === null || ref1 === void 0 ? void 0 : ref1.length) || 0
|
|
10455
|
+
};
|
|
10456
|
+
}
|
|
10457
|
+
// public for test
|
|
10458
|
+
get window() {
|
|
10459
|
+
return this.options.window;
|
|
10460
|
+
}
|
|
10461
|
+
get document() {
|
|
10462
|
+
return this.options.document;
|
|
10463
|
+
}
|
|
10464
|
+
/**
|
|
10465
|
+
* Get the root element to use for event subscriptions
|
|
10466
|
+
*/ get rootElement() {
|
|
10467
|
+
return this.options.rootElement;
|
|
10468
|
+
}
|
|
10469
|
+
setup() {
|
|
10470
|
+
const root = this.rootElement;
|
|
10471
|
+
if (root === undefined) {
|
|
10472
|
+
return;
|
|
10473
|
+
}
|
|
10474
|
+
if (root.__isReactDndBackendSetUp) {
|
|
10475
|
+
throw new Error('Cannot have two HTML5 backends at the same time.');
|
|
10476
|
+
}
|
|
10477
|
+
root.__isReactDndBackendSetUp = true;
|
|
10478
|
+
this.addEventListeners(root);
|
|
10479
|
+
}
|
|
10480
|
+
teardown() {
|
|
10481
|
+
const root = this.rootElement;
|
|
10482
|
+
if (root === undefined) {
|
|
10483
|
+
return;
|
|
10484
|
+
}
|
|
10485
|
+
root.__isReactDndBackendSetUp = false;
|
|
10486
|
+
this.removeEventListeners(this.rootElement);
|
|
10487
|
+
this.clearCurrentDragSourceNode();
|
|
10488
|
+
if (this.asyncEndDragFrameId) {
|
|
10489
|
+
var ref;
|
|
10490
|
+
(ref = this.window) === null || ref === void 0 ? void 0 : ref.cancelAnimationFrame(this.asyncEndDragFrameId);
|
|
10491
|
+
}
|
|
10492
|
+
}
|
|
10493
|
+
connectDragPreview(sourceId, node, options) {
|
|
10494
|
+
this.sourcePreviewNodeOptions.set(sourceId, options);
|
|
10495
|
+
this.sourcePreviewNodes.set(sourceId, node);
|
|
10496
|
+
return ()=>{
|
|
10497
|
+
this.sourcePreviewNodes.delete(sourceId);
|
|
10498
|
+
this.sourcePreviewNodeOptions.delete(sourceId);
|
|
10499
|
+
};
|
|
10500
|
+
}
|
|
10501
|
+
connectDragSource(sourceId, node, options) {
|
|
10502
|
+
this.sourceNodes.set(sourceId, node);
|
|
10503
|
+
this.sourceNodeOptions.set(sourceId, options);
|
|
10504
|
+
const handleDragStart = (e)=>this.handleDragStart(e, sourceId)
|
|
10505
|
+
;
|
|
10506
|
+
const handleSelectStart = (e)=>this.handleSelectStart(e)
|
|
10507
|
+
;
|
|
10508
|
+
node.setAttribute('draggable', 'true');
|
|
10509
|
+
node.addEventListener('dragstart', handleDragStart);
|
|
10510
|
+
node.addEventListener('selectstart', handleSelectStart);
|
|
10511
|
+
return ()=>{
|
|
10512
|
+
this.sourceNodes.delete(sourceId);
|
|
10513
|
+
this.sourceNodeOptions.delete(sourceId);
|
|
10514
|
+
node.removeEventListener('dragstart', handleDragStart);
|
|
10515
|
+
node.removeEventListener('selectstart', handleSelectStart);
|
|
10516
|
+
node.setAttribute('draggable', 'false');
|
|
10517
|
+
};
|
|
10518
|
+
}
|
|
10519
|
+
connectDropTarget(targetId, node) {
|
|
10520
|
+
const handleDragEnter = (e)=>this.handleDragEnter(e, targetId)
|
|
10521
|
+
;
|
|
10522
|
+
const handleDragOver = (e)=>this.handleDragOver(e, targetId)
|
|
10523
|
+
;
|
|
10524
|
+
const handleDrop = (e)=>this.handleDrop(e, targetId)
|
|
10525
|
+
;
|
|
10526
|
+
node.addEventListener('dragenter', handleDragEnter);
|
|
10527
|
+
node.addEventListener('dragover', handleDragOver);
|
|
10528
|
+
node.addEventListener('drop', handleDrop);
|
|
10529
|
+
return ()=>{
|
|
10530
|
+
node.removeEventListener('dragenter', handleDragEnter);
|
|
10531
|
+
node.removeEventListener('dragover', handleDragOver);
|
|
10532
|
+
node.removeEventListener('drop', handleDrop);
|
|
10533
|
+
};
|
|
10534
|
+
}
|
|
10535
|
+
addEventListeners(target) {
|
|
10536
|
+
// SSR Fix (https://github.com/react-dnd/react-dnd/pull/813
|
|
10537
|
+
if (!target.addEventListener) {
|
|
10538
|
+
return;
|
|
10539
|
+
}
|
|
10540
|
+
target.addEventListener('dragstart', this.handleTopDragStart);
|
|
10541
|
+
target.addEventListener('dragstart', this.handleTopDragStartCapture, true);
|
|
10542
|
+
target.addEventListener('dragend', this.handleTopDragEndCapture, true);
|
|
10543
|
+
target.addEventListener('dragenter', this.handleTopDragEnter);
|
|
10544
|
+
target.addEventListener('dragenter', this.handleTopDragEnterCapture, true);
|
|
10545
|
+
target.addEventListener('dragleave', this.handleTopDragLeaveCapture, true);
|
|
10546
|
+
target.addEventListener('dragover', this.handleTopDragOver);
|
|
10547
|
+
target.addEventListener('dragover', this.handleTopDragOverCapture, true);
|
|
10548
|
+
target.addEventListener('drop', this.handleTopDrop);
|
|
10549
|
+
target.addEventListener('drop', this.handleTopDropCapture, true);
|
|
10550
|
+
}
|
|
10551
|
+
removeEventListeners(target) {
|
|
10552
|
+
// SSR Fix (https://github.com/react-dnd/react-dnd/pull/813
|
|
10553
|
+
if (!target.removeEventListener) {
|
|
10554
|
+
return;
|
|
10555
|
+
}
|
|
10556
|
+
target.removeEventListener('dragstart', this.handleTopDragStart);
|
|
10557
|
+
target.removeEventListener('dragstart', this.handleTopDragStartCapture, true);
|
|
10558
|
+
target.removeEventListener('dragend', this.handleTopDragEndCapture, true);
|
|
10559
|
+
target.removeEventListener('dragenter', this.handleTopDragEnter);
|
|
10560
|
+
target.removeEventListener('dragenter', this.handleTopDragEnterCapture, true);
|
|
10561
|
+
target.removeEventListener('dragleave', this.handleTopDragLeaveCapture, true);
|
|
10562
|
+
target.removeEventListener('dragover', this.handleTopDragOver);
|
|
10563
|
+
target.removeEventListener('dragover', this.handleTopDragOverCapture, true);
|
|
10564
|
+
target.removeEventListener('drop', this.handleTopDrop);
|
|
10565
|
+
target.removeEventListener('drop', this.handleTopDropCapture, true);
|
|
10566
|
+
}
|
|
10567
|
+
getCurrentSourceNodeOptions() {
|
|
10568
|
+
const sourceId = this.monitor.getSourceId();
|
|
10569
|
+
const sourceNodeOptions = this.sourceNodeOptions.get(sourceId);
|
|
10570
|
+
return _objectSpread({
|
|
10571
|
+
dropEffect: this.altKeyPressed ? 'copy' : 'move'
|
|
10572
|
+
}, sourceNodeOptions || {});
|
|
10573
|
+
}
|
|
10574
|
+
getCurrentDropEffect() {
|
|
10575
|
+
if (this.isDraggingNativeItem()) {
|
|
10576
|
+
// It makes more sense to default to 'copy' for native resources
|
|
10577
|
+
return 'copy';
|
|
10578
|
+
}
|
|
10579
|
+
return this.getCurrentSourceNodeOptions().dropEffect;
|
|
10580
|
+
}
|
|
10581
|
+
getCurrentSourcePreviewNodeOptions() {
|
|
10582
|
+
const sourceId = this.monitor.getSourceId();
|
|
10583
|
+
const sourcePreviewNodeOptions = this.sourcePreviewNodeOptions.get(sourceId);
|
|
10584
|
+
return _objectSpread({
|
|
10585
|
+
anchorX: 0.5,
|
|
10586
|
+
anchorY: 0.5,
|
|
10587
|
+
captureDraggingState: false
|
|
10588
|
+
}, sourcePreviewNodeOptions || {});
|
|
10589
|
+
}
|
|
10590
|
+
isDraggingNativeItem() {
|
|
10591
|
+
const itemType = this.monitor.getItemType();
|
|
10592
|
+
return Object.keys(NativeTypes).some((key)=>NativeTypes[key] === itemType
|
|
10593
|
+
);
|
|
10594
|
+
}
|
|
10595
|
+
beginDragNativeItem(type, dataTransfer) {
|
|
10596
|
+
this.clearCurrentDragSourceNode();
|
|
10597
|
+
this.currentNativeSource = createNativeDragSource(type, dataTransfer);
|
|
10598
|
+
this.currentNativeHandle = this.registry.addSource(type, this.currentNativeSource);
|
|
10599
|
+
this.actions.beginDrag([
|
|
10600
|
+
this.currentNativeHandle
|
|
10601
|
+
]);
|
|
10602
|
+
}
|
|
10603
|
+
setCurrentDragSourceNode(node) {
|
|
10604
|
+
this.clearCurrentDragSourceNode();
|
|
10605
|
+
this.currentDragSourceNode = node;
|
|
10606
|
+
// A timeout of > 0 is necessary to resolve Firefox issue referenced
|
|
10607
|
+
// See:
|
|
10608
|
+
// * https://github.com/react-dnd/react-dnd/pull/928
|
|
10609
|
+
// * https://github.com/react-dnd/react-dnd/issues/869
|
|
10610
|
+
const MOUSE_MOVE_TIMEOUT = 1000;
|
|
10611
|
+
// Receiving a mouse event in the middle of a dragging operation
|
|
10612
|
+
// means it has ended and the drag source node disappeared from DOM,
|
|
10613
|
+
// so the browser didn't dispatch the dragend event.
|
|
10614
|
+
//
|
|
10615
|
+
// We need to wait before we start listening for mousemove events.
|
|
10616
|
+
// This is needed because the drag preview needs to be drawn or else it fires an 'mousemove' event
|
|
10617
|
+
// immediately in some browsers.
|
|
10618
|
+
//
|
|
10619
|
+
// See:
|
|
10620
|
+
// * https://github.com/react-dnd/react-dnd/pull/928
|
|
10621
|
+
// * https://github.com/react-dnd/react-dnd/issues/869
|
|
10622
|
+
//
|
|
10623
|
+
this.mouseMoveTimeoutTimer = setTimeout(()=>{
|
|
10624
|
+
var ref;
|
|
10625
|
+
return (ref = this.rootElement) === null || ref === void 0 ? void 0 : ref.addEventListener('mousemove', this.endDragIfSourceWasRemovedFromDOM, true);
|
|
10626
|
+
}, MOUSE_MOVE_TIMEOUT);
|
|
10627
|
+
}
|
|
10628
|
+
clearCurrentDragSourceNode() {
|
|
10629
|
+
if (this.currentDragSourceNode) {
|
|
10630
|
+
this.currentDragSourceNode = null;
|
|
10631
|
+
if (this.rootElement) {
|
|
10632
|
+
var ref;
|
|
10633
|
+
(ref = this.window) === null || ref === void 0 ? void 0 : ref.clearTimeout(this.mouseMoveTimeoutTimer || undefined);
|
|
10634
|
+
this.rootElement.removeEventListener('mousemove', this.endDragIfSourceWasRemovedFromDOM, true);
|
|
10635
|
+
}
|
|
10636
|
+
this.mouseMoveTimeoutTimer = null;
|
|
10637
|
+
return true;
|
|
10638
|
+
}
|
|
10639
|
+
return false;
|
|
10640
|
+
}
|
|
10641
|
+
handleDragStart(e, sourceId) {
|
|
10642
|
+
if (e.defaultPrevented) {
|
|
10643
|
+
return;
|
|
10644
|
+
}
|
|
10645
|
+
if (!this.dragStartSourceIds) {
|
|
10646
|
+
this.dragStartSourceIds = [];
|
|
10647
|
+
}
|
|
10648
|
+
this.dragStartSourceIds.unshift(sourceId);
|
|
10649
|
+
}
|
|
10650
|
+
handleDragEnter(_e, targetId) {
|
|
10651
|
+
this.dragEnterTargetIds.unshift(targetId);
|
|
10652
|
+
}
|
|
10653
|
+
handleDragOver(_e, targetId) {
|
|
10654
|
+
if (this.dragOverTargetIds === null) {
|
|
10655
|
+
this.dragOverTargetIds = [];
|
|
10656
|
+
}
|
|
10657
|
+
this.dragOverTargetIds.unshift(targetId);
|
|
10658
|
+
}
|
|
10659
|
+
handleDrop(_e, targetId) {
|
|
10660
|
+
this.dropTargetIds.unshift(targetId);
|
|
10661
|
+
}
|
|
10662
|
+
constructor(manager, globalContext, options){
|
|
10663
|
+
this.sourcePreviewNodes = new Map();
|
|
10664
|
+
this.sourcePreviewNodeOptions = new Map();
|
|
10665
|
+
this.sourceNodes = new Map();
|
|
10666
|
+
this.sourceNodeOptions = new Map();
|
|
10667
|
+
this.dragStartSourceIds = null;
|
|
10668
|
+
this.dropTargetIds = [];
|
|
10669
|
+
this.dragEnterTargetIds = [];
|
|
10670
|
+
this.currentNativeSource = null;
|
|
10671
|
+
this.currentNativeHandle = null;
|
|
10672
|
+
this.currentDragSourceNode = null;
|
|
10673
|
+
this.altKeyPressed = false;
|
|
10674
|
+
this.mouseMoveTimeoutTimer = null;
|
|
10675
|
+
this.asyncEndDragFrameId = null;
|
|
10676
|
+
this.dragOverTargetIds = null;
|
|
10677
|
+
this.lastClientOffset = null;
|
|
10678
|
+
this.hoverRafId = null;
|
|
10679
|
+
this.getSourceClientOffset = (sourceId)=>{
|
|
10680
|
+
const source = this.sourceNodes.get(sourceId);
|
|
10681
|
+
return source && getNodeClientOffset(source) || null;
|
|
10682
|
+
};
|
|
10683
|
+
this.endDragNativeItem = ()=>{
|
|
10684
|
+
if (!this.isDraggingNativeItem()) {
|
|
10685
|
+
return;
|
|
10686
|
+
}
|
|
10687
|
+
this.actions.endDrag();
|
|
10688
|
+
if (this.currentNativeHandle) {
|
|
10689
|
+
this.registry.removeSource(this.currentNativeHandle);
|
|
10690
|
+
}
|
|
10691
|
+
this.currentNativeHandle = null;
|
|
10692
|
+
this.currentNativeSource = null;
|
|
10693
|
+
};
|
|
10694
|
+
this.isNodeInDocument = (node)=>{
|
|
10695
|
+
// Check the node either in the main document or in the current context
|
|
10696
|
+
return Boolean(node && this.document && this.document.body && this.document.body.contains(node));
|
|
10697
|
+
};
|
|
10698
|
+
this.endDragIfSourceWasRemovedFromDOM = ()=>{
|
|
10699
|
+
const node = this.currentDragSourceNode;
|
|
10700
|
+
if (node == null || this.isNodeInDocument(node)) {
|
|
10701
|
+
return;
|
|
10702
|
+
}
|
|
10703
|
+
if (this.clearCurrentDragSourceNode() && this.monitor.isDragging()) {
|
|
10704
|
+
this.actions.endDrag();
|
|
10705
|
+
}
|
|
10706
|
+
this.cancelHover();
|
|
10707
|
+
};
|
|
10708
|
+
this.scheduleHover = (dragOverTargetIds)=>{
|
|
10709
|
+
if (this.hoverRafId === null && typeof requestAnimationFrame !== 'undefined') {
|
|
10710
|
+
this.hoverRafId = requestAnimationFrame(()=>{
|
|
10711
|
+
if (this.monitor.isDragging()) {
|
|
10712
|
+
this.actions.hover(dragOverTargetIds || [], {
|
|
10713
|
+
clientOffset: this.lastClientOffset
|
|
10714
|
+
});
|
|
10715
|
+
}
|
|
10716
|
+
this.hoverRafId = null;
|
|
10717
|
+
});
|
|
10718
|
+
}
|
|
10719
|
+
};
|
|
10720
|
+
this.cancelHover = ()=>{
|
|
10721
|
+
if (this.hoverRafId !== null && typeof cancelAnimationFrame !== 'undefined') {
|
|
10722
|
+
cancelAnimationFrame(this.hoverRafId);
|
|
10723
|
+
this.hoverRafId = null;
|
|
10724
|
+
}
|
|
10725
|
+
};
|
|
10726
|
+
this.handleTopDragStartCapture = ()=>{
|
|
10727
|
+
this.clearCurrentDragSourceNode();
|
|
10728
|
+
this.dragStartSourceIds = [];
|
|
10729
|
+
};
|
|
10730
|
+
this.handleTopDragStart = (e)=>{
|
|
10731
|
+
if (e.defaultPrevented) {
|
|
10732
|
+
return;
|
|
10733
|
+
}
|
|
10734
|
+
const { dragStartSourceIds } = this;
|
|
10735
|
+
this.dragStartSourceIds = null;
|
|
10736
|
+
const clientOffset = getEventClientOffset(e);
|
|
10737
|
+
// Avoid crashing if we missed a drop event or our previous drag died
|
|
10738
|
+
if (this.monitor.isDragging()) {
|
|
10739
|
+
this.actions.endDrag();
|
|
10740
|
+
this.cancelHover();
|
|
10741
|
+
}
|
|
10742
|
+
// Don't publish the source just yet (see why below)
|
|
10743
|
+
this.actions.beginDrag(dragStartSourceIds || [], {
|
|
10744
|
+
publishSource: false,
|
|
10745
|
+
getSourceClientOffset: this.getSourceClientOffset,
|
|
10746
|
+
clientOffset
|
|
10747
|
+
});
|
|
10748
|
+
const { dataTransfer } = e;
|
|
10749
|
+
const nativeType = matchNativeItemType(dataTransfer);
|
|
10750
|
+
if (this.monitor.isDragging()) {
|
|
10751
|
+
if (dataTransfer && typeof dataTransfer.setDragImage === 'function') {
|
|
10752
|
+
// Use custom drag image if user specifies it.
|
|
10753
|
+
// If child drag source refuses drag but parent agrees,
|
|
10754
|
+
// use parent's node as drag image. Neither works in IE though.
|
|
10755
|
+
const sourceId = this.monitor.getSourceId();
|
|
10756
|
+
const sourceNode = this.sourceNodes.get(sourceId);
|
|
10757
|
+
const dragPreview = this.sourcePreviewNodes.get(sourceId) || sourceNode;
|
|
10758
|
+
if (dragPreview) {
|
|
10759
|
+
const { anchorX , anchorY , offsetX , offsetY } = this.getCurrentSourcePreviewNodeOptions();
|
|
10760
|
+
const anchorPoint = {
|
|
10761
|
+
anchorX,
|
|
10762
|
+
anchorY
|
|
10763
|
+
};
|
|
10764
|
+
const offsetPoint = {
|
|
10765
|
+
offsetX,
|
|
10766
|
+
offsetY
|
|
10767
|
+
};
|
|
10768
|
+
const dragPreviewOffset = getDragPreviewOffset(sourceNode, dragPreview, clientOffset, anchorPoint, offsetPoint);
|
|
10769
|
+
dataTransfer.setDragImage(dragPreview, dragPreviewOffset.x, dragPreviewOffset.y);
|
|
10770
|
+
}
|
|
10771
|
+
}
|
|
10772
|
+
try {
|
|
10773
|
+
// Firefox won't drag without setting data
|
|
10774
|
+
dataTransfer === null || dataTransfer === void 0 ? void 0 : dataTransfer.setData('application/json', {});
|
|
10775
|
+
} catch (err) {
|
|
10776
|
+
// IE doesn't support MIME types in setData
|
|
10777
|
+
}
|
|
10778
|
+
// Store drag source node so we can check whether
|
|
10779
|
+
// it is removed from DOM and trigger endDrag manually.
|
|
10780
|
+
this.setCurrentDragSourceNode(e.target);
|
|
10781
|
+
// Now we are ready to publish the drag source.. or are we not?
|
|
10782
|
+
const { captureDraggingState } = this.getCurrentSourcePreviewNodeOptions();
|
|
10783
|
+
if (!captureDraggingState) {
|
|
10784
|
+
// Usually we want to publish it in the next tick so that browser
|
|
10785
|
+
// is able to screenshot the current (not yet dragging) state.
|
|
10786
|
+
//
|
|
10787
|
+
// It also neatly avoids a situation where render() returns null
|
|
10788
|
+
// in the same tick for the source element, and browser freaks out.
|
|
10789
|
+
setTimeout(()=>this.actions.publishDragSource()
|
|
10790
|
+
, 0);
|
|
10791
|
+
} else {
|
|
10792
|
+
// In some cases the user may want to override this behavior, e.g.
|
|
10793
|
+
// to work around IE not supporting custom drag previews.
|
|
10794
|
+
//
|
|
10795
|
+
// When using a custom drag layer, the only way to prevent
|
|
10796
|
+
// the default drag preview from drawing in IE is to screenshot
|
|
10797
|
+
// the dragging state in which the node itself has zero opacity
|
|
10798
|
+
// and height. In this case, though, returning null from render()
|
|
10799
|
+
// will abruptly end the dragging, which is not obvious.
|
|
10800
|
+
//
|
|
10801
|
+
// This is the reason such behavior is strictly opt-in.
|
|
10802
|
+
this.actions.publishDragSource();
|
|
10803
|
+
}
|
|
10804
|
+
} else if (nativeType) {
|
|
10805
|
+
// A native item (such as URL) dragged from inside the document
|
|
10806
|
+
this.beginDragNativeItem(nativeType);
|
|
10807
|
+
} else if (dataTransfer && !dataTransfer.types && (e.target && !e.target.hasAttribute || !e.target.hasAttribute('draggable'))) {
|
|
10808
|
+
// Looks like a Safari bug: dataTransfer.types is null, but there was no draggable.
|
|
10809
|
+
// Just let it drag. It's a native type (URL or text) and will be picked up in
|
|
10810
|
+
// dragenter handler.
|
|
10811
|
+
return;
|
|
10812
|
+
} else {
|
|
10813
|
+
// If by this time no drag source reacted, tell browser not to drag.
|
|
10814
|
+
e.preventDefault();
|
|
10815
|
+
}
|
|
10816
|
+
};
|
|
10817
|
+
this.handleTopDragEndCapture = ()=>{
|
|
10818
|
+
if (this.clearCurrentDragSourceNode() && this.monitor.isDragging()) {
|
|
10819
|
+
// Firefox can dispatch this event in an infinite loop
|
|
10820
|
+
// if dragend handler does something like showing an alert.
|
|
10821
|
+
// Only proceed if we have not handled it already.
|
|
10822
|
+
this.actions.endDrag();
|
|
10823
|
+
}
|
|
10824
|
+
this.cancelHover();
|
|
10825
|
+
};
|
|
10826
|
+
this.handleTopDragEnterCapture = (e)=>{
|
|
10827
|
+
this.dragEnterTargetIds = [];
|
|
10828
|
+
if (this.isDraggingNativeItem()) {
|
|
10829
|
+
var ref;
|
|
10830
|
+
(ref = this.currentNativeSource) === null || ref === void 0 ? void 0 : ref.loadDataTransfer(e.dataTransfer);
|
|
10831
|
+
}
|
|
10832
|
+
const isFirstEnter = this.enterLeaveCounter.enter(e.target);
|
|
10833
|
+
if (!isFirstEnter || this.monitor.isDragging()) {
|
|
10834
|
+
return;
|
|
10835
|
+
}
|
|
10836
|
+
const { dataTransfer } = e;
|
|
10837
|
+
const nativeType = matchNativeItemType(dataTransfer);
|
|
10838
|
+
if (nativeType) {
|
|
10839
|
+
// A native item (such as file or URL) dragged from outside the document
|
|
10840
|
+
this.beginDragNativeItem(nativeType, dataTransfer);
|
|
10841
|
+
}
|
|
10842
|
+
};
|
|
10843
|
+
this.handleTopDragEnter = (e)=>{
|
|
10844
|
+
const { dragEnterTargetIds } = this;
|
|
10845
|
+
this.dragEnterTargetIds = [];
|
|
10846
|
+
if (!this.monitor.isDragging()) {
|
|
10847
|
+
// This is probably a native item type we don't understand.
|
|
10848
|
+
return;
|
|
10849
|
+
}
|
|
10850
|
+
this.altKeyPressed = e.altKey;
|
|
10851
|
+
// If the target changes position as the result of `dragenter`, `dragover` might still
|
|
10852
|
+
// get dispatched despite target being no longer there. The easy solution is to check
|
|
10853
|
+
// whether there actually is a target before firing `hover`.
|
|
10854
|
+
if (dragEnterTargetIds.length > 0) {
|
|
10855
|
+
this.actions.hover(dragEnterTargetIds, {
|
|
10856
|
+
clientOffset: getEventClientOffset(e)
|
|
10857
|
+
});
|
|
10858
|
+
}
|
|
10859
|
+
const canDrop = dragEnterTargetIds.some((targetId)=>this.monitor.canDropOnTarget(targetId)
|
|
10860
|
+
);
|
|
10861
|
+
if (canDrop) {
|
|
10862
|
+
// IE requires this to fire dragover events
|
|
10863
|
+
e.preventDefault();
|
|
10864
|
+
if (e.dataTransfer) {
|
|
10865
|
+
e.dataTransfer.dropEffect = this.getCurrentDropEffect();
|
|
10866
|
+
}
|
|
10867
|
+
}
|
|
10868
|
+
};
|
|
10869
|
+
this.handleTopDragOverCapture = (e)=>{
|
|
10870
|
+
this.dragOverTargetIds = [];
|
|
10871
|
+
if (this.isDraggingNativeItem()) {
|
|
10872
|
+
var ref;
|
|
10873
|
+
(ref = this.currentNativeSource) === null || ref === void 0 ? void 0 : ref.loadDataTransfer(e.dataTransfer);
|
|
10874
|
+
}
|
|
10875
|
+
};
|
|
10876
|
+
this.handleTopDragOver = (e)=>{
|
|
10877
|
+
const { dragOverTargetIds } = this;
|
|
10878
|
+
this.dragOverTargetIds = [];
|
|
10879
|
+
if (!this.monitor.isDragging()) {
|
|
10880
|
+
// This is probably a native item type we don't understand.
|
|
10881
|
+
// Prevent default "drop and blow away the whole document" action.
|
|
10882
|
+
e.preventDefault();
|
|
10883
|
+
if (e.dataTransfer) {
|
|
10884
|
+
e.dataTransfer.dropEffect = 'none';
|
|
10885
|
+
}
|
|
10886
|
+
return;
|
|
10887
|
+
}
|
|
10888
|
+
this.altKeyPressed = e.altKey;
|
|
10889
|
+
this.lastClientOffset = getEventClientOffset(e);
|
|
10890
|
+
this.scheduleHover(dragOverTargetIds);
|
|
10891
|
+
const canDrop = (dragOverTargetIds || []).some((targetId)=>this.monitor.canDropOnTarget(targetId)
|
|
10892
|
+
);
|
|
10893
|
+
if (canDrop) {
|
|
10894
|
+
// Show user-specified drop effect.
|
|
10895
|
+
e.preventDefault();
|
|
10896
|
+
if (e.dataTransfer) {
|
|
10897
|
+
e.dataTransfer.dropEffect = this.getCurrentDropEffect();
|
|
10898
|
+
}
|
|
10899
|
+
} else if (this.isDraggingNativeItem()) {
|
|
10900
|
+
// Don't show a nice cursor but still prevent default
|
|
10901
|
+
// "drop and blow away the whole document" action.
|
|
10902
|
+
e.preventDefault();
|
|
10903
|
+
} else {
|
|
10904
|
+
e.preventDefault();
|
|
10905
|
+
if (e.dataTransfer) {
|
|
10906
|
+
e.dataTransfer.dropEffect = 'none';
|
|
10907
|
+
}
|
|
10908
|
+
}
|
|
10909
|
+
};
|
|
10910
|
+
this.handleTopDragLeaveCapture = (e)=>{
|
|
10911
|
+
if (this.isDraggingNativeItem()) {
|
|
10912
|
+
e.preventDefault();
|
|
10913
|
+
}
|
|
10914
|
+
const isLastLeave = this.enterLeaveCounter.leave(e.target);
|
|
10915
|
+
if (!isLastLeave) {
|
|
10916
|
+
return;
|
|
10917
|
+
}
|
|
10918
|
+
if (this.isDraggingNativeItem()) {
|
|
10919
|
+
setTimeout(()=>this.endDragNativeItem()
|
|
10920
|
+
, 0);
|
|
10921
|
+
}
|
|
10922
|
+
this.cancelHover();
|
|
10923
|
+
};
|
|
10924
|
+
this.handleTopDropCapture = (e)=>{
|
|
10925
|
+
this.dropTargetIds = [];
|
|
10926
|
+
if (this.isDraggingNativeItem()) {
|
|
10927
|
+
var ref;
|
|
10928
|
+
e.preventDefault();
|
|
10929
|
+
(ref = this.currentNativeSource) === null || ref === void 0 ? void 0 : ref.loadDataTransfer(e.dataTransfer);
|
|
10930
|
+
} else if (matchNativeItemType(e.dataTransfer)) {
|
|
10931
|
+
// Dragging some elements, like <a> and <img> may still behave like a native drag event,
|
|
10932
|
+
// even if the current drag event matches a user-defined type.
|
|
10933
|
+
// Stop the default behavior when we're not expecting a native item to be dropped.
|
|
10934
|
+
e.preventDefault();
|
|
10935
|
+
}
|
|
10936
|
+
this.enterLeaveCounter.reset();
|
|
10937
|
+
};
|
|
10938
|
+
this.handleTopDrop = (e)=>{
|
|
10939
|
+
const { dropTargetIds } = this;
|
|
10940
|
+
this.dropTargetIds = [];
|
|
10941
|
+
this.actions.hover(dropTargetIds, {
|
|
10942
|
+
clientOffset: getEventClientOffset(e)
|
|
10943
|
+
});
|
|
10944
|
+
this.actions.drop({
|
|
10945
|
+
dropEffect: this.getCurrentDropEffect()
|
|
10946
|
+
});
|
|
10947
|
+
if (this.isDraggingNativeItem()) {
|
|
10948
|
+
this.endDragNativeItem();
|
|
10949
|
+
} else if (this.monitor.isDragging()) {
|
|
10950
|
+
this.actions.endDrag();
|
|
10951
|
+
}
|
|
10952
|
+
this.cancelHover();
|
|
10953
|
+
};
|
|
10954
|
+
this.handleSelectStart = (e)=>{
|
|
10955
|
+
const target = e.target;
|
|
10956
|
+
// Only IE requires us to explicitly say
|
|
10957
|
+
// we want drag drop operation to start
|
|
10958
|
+
if (typeof target.dragDrop !== 'function') {
|
|
10959
|
+
return;
|
|
10960
|
+
}
|
|
10961
|
+
// Inputs and textareas should be selectable
|
|
10962
|
+
if (target.tagName === 'INPUT' || target.tagName === 'SELECT' || target.tagName === 'TEXTAREA' || target.isContentEditable) {
|
|
10963
|
+
return;
|
|
10964
|
+
}
|
|
10965
|
+
// For other targets, ask IE
|
|
10966
|
+
// to enable drag and drop
|
|
10967
|
+
e.preventDefault();
|
|
10968
|
+
target.dragDrop();
|
|
10969
|
+
};
|
|
10970
|
+
this.options = new OptionsReader(globalContext, options);
|
|
10971
|
+
this.actions = manager.getActions();
|
|
10972
|
+
this.monitor = manager.getMonitor();
|
|
10973
|
+
this.registry = manager.getRegistry();
|
|
10974
|
+
this.enterLeaveCounter = new EnterLeaveCounter(this.isNodeInDocument);
|
|
10975
|
+
}
|
|
10976
|
+
}
|
|
10977
|
+
|
|
10978
|
+
let emptyImage;
|
|
10979
|
+
function getEmptyImage() {
|
|
10980
|
+
if (!emptyImage) {
|
|
10981
|
+
emptyImage = new Image();
|
|
10982
|
+
emptyImage.src = 'data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
|
|
10983
|
+
}
|
|
10984
|
+
return emptyImage;
|
|
10985
|
+
}
|
|
10986
|
+
|
|
10987
|
+
const HTML5Backend = function createBackend(manager, context, options) {
|
|
10988
|
+
return new HTML5BackendImpl(manager, context, options);
|
|
10989
|
+
};
|
|
10990
|
+
|
|
10991
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray$1(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
10992
|
+
|
|
10993
|
+
function _unsupportedIterableToArray$1(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray$1(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen); }
|
|
10994
|
+
|
|
10995
|
+
function _arrayLikeToArray$1(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
10996
|
+
|
|
10997
|
+
function _classCallCheck$1(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
10998
|
+
|
|
10999
|
+
function _defineProperty$1(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11000
|
+
|
|
11001
|
+
function _classPrivateFieldGet$1(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor$1(receiver, privateMap, "get"); return _classApplyDescriptorGet$1(receiver, descriptor); }
|
|
11002
|
+
|
|
11003
|
+
function _classApplyDescriptorGet$1(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
11004
|
+
|
|
11005
|
+
function _classPrivateFieldSet$1(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor$1(receiver, privateMap, "set"); _classApplyDescriptorSet$1(receiver, descriptor, value); return value; }
|
|
11006
|
+
|
|
11007
|
+
function _classExtractFieldDescriptor$1(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
11008
|
+
|
|
11009
|
+
function _classApplyDescriptorSet$1(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
|
|
11010
|
+
|
|
11011
|
+
var _previews$1 = new WeakMap();
|
|
11012
|
+
|
|
11013
|
+
var PreviewListImpl =
|
|
11014
|
+
/*private*/
|
|
11015
|
+
function PreviewListImpl() {
|
|
11016
|
+
var _this = this;
|
|
11017
|
+
|
|
11018
|
+
_classCallCheck$1(this, PreviewListImpl);
|
|
11019
|
+
|
|
11020
|
+
_previews$1.set(this, {
|
|
11021
|
+
writable: true,
|
|
11022
|
+
value: void 0
|
|
11023
|
+
});
|
|
11024
|
+
|
|
11025
|
+
_defineProperty$1(this, "register", function (preview) {
|
|
11026
|
+
_classPrivateFieldGet$1(_this, _previews$1).push(preview);
|
|
11027
|
+
});
|
|
11028
|
+
|
|
11029
|
+
_defineProperty$1(this, "unregister", function (preview) {
|
|
11030
|
+
var index;
|
|
11031
|
+
|
|
11032
|
+
while ((index = _classPrivateFieldGet$1(_this, _previews$1).indexOf(preview)) !== -1) {
|
|
11033
|
+
_classPrivateFieldGet$1(_this, _previews$1).splice(index, 1);
|
|
11034
|
+
}
|
|
11035
|
+
});
|
|
11036
|
+
|
|
11037
|
+
_defineProperty$1(this, "backendChanged", function (backend) {
|
|
11038
|
+
var _iterator = _createForOfIteratorHelper(_classPrivateFieldGet$1(_this, _previews$1)),
|
|
11039
|
+
_step;
|
|
11040
|
+
|
|
11041
|
+
try {
|
|
11042
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
11043
|
+
var preview = _step.value;
|
|
11044
|
+
preview.backendChanged(backend);
|
|
11045
|
+
}
|
|
11046
|
+
} catch (err) {
|
|
11047
|
+
_iterator.e(err);
|
|
11048
|
+
} finally {
|
|
11049
|
+
_iterator.f();
|
|
11050
|
+
}
|
|
11051
|
+
});
|
|
11052
|
+
|
|
11053
|
+
_classPrivateFieldSet$1(this, _previews$1, []);
|
|
11054
|
+
};
|
|
11055
|
+
|
|
11056
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
11057
|
+
|
|
11058
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
11059
|
+
|
|
11060
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
11061
|
+
|
|
11062
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
|
11063
|
+
|
|
11064
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
11065
|
+
|
|
11066
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
11067
|
+
|
|
11068
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
11069
|
+
|
|
11070
|
+
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
11071
|
+
|
|
11072
|
+
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
11073
|
+
|
|
11074
|
+
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
11075
|
+
|
|
11076
|
+
function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
|
|
11077
|
+
|
|
11078
|
+
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
11079
|
+
|
|
11080
|
+
function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
|
|
11081
|
+
|
|
11082
|
+
var _current = new WeakMap();
|
|
11083
|
+
|
|
11084
|
+
var _previews = new WeakMap();
|
|
11085
|
+
|
|
11086
|
+
var _backends = new WeakMap();
|
|
11087
|
+
|
|
11088
|
+
var _backendsList = new WeakMap();
|
|
11089
|
+
|
|
11090
|
+
var _nodes = new WeakMap();
|
|
11091
|
+
|
|
11092
|
+
var _createBackend = new WeakMap();
|
|
11093
|
+
|
|
11094
|
+
var _addEventListeners = new WeakMap();
|
|
11095
|
+
|
|
11096
|
+
var _removeEventListeners = new WeakMap();
|
|
11097
|
+
|
|
11098
|
+
var _backendSwitcher = new WeakMap();
|
|
11099
|
+
|
|
11100
|
+
var _callBackend = new WeakMap();
|
|
11101
|
+
|
|
11102
|
+
var _connectBackend = new WeakMap();
|
|
11103
|
+
|
|
11104
|
+
var MultiBackendImpl =
|
|
11105
|
+
/*private*/
|
|
11106
|
+
|
|
11107
|
+
/*private*/
|
|
11108
|
+
|
|
11109
|
+
/*private*/
|
|
11110
|
+
|
|
11111
|
+
/*private*/
|
|
11112
|
+
|
|
11113
|
+
/*private*/
|
|
11114
|
+
function MultiBackendImpl(_manager, _context, _options) {
|
|
11115
|
+
var _this = this;
|
|
11116
|
+
|
|
11117
|
+
_classCallCheck(this, MultiBackendImpl);
|
|
11118
|
+
|
|
11119
|
+
_current.set(this, {
|
|
11120
|
+
writable: true,
|
|
11121
|
+
value: void 0
|
|
11122
|
+
});
|
|
11123
|
+
|
|
11124
|
+
_previews.set(this, {
|
|
11125
|
+
writable: true,
|
|
11126
|
+
value: void 0
|
|
11127
|
+
});
|
|
11128
|
+
|
|
11129
|
+
_backends.set(this, {
|
|
11130
|
+
writable: true,
|
|
11131
|
+
value: void 0
|
|
11132
|
+
});
|
|
11133
|
+
|
|
11134
|
+
_backendsList.set(this, {
|
|
11135
|
+
writable: true,
|
|
11136
|
+
value: void 0
|
|
11137
|
+
});
|
|
11138
|
+
|
|
11139
|
+
_nodes.set(this, {
|
|
11140
|
+
writable: true,
|
|
11141
|
+
value: void 0
|
|
11142
|
+
});
|
|
11143
|
+
|
|
11144
|
+
_createBackend.set(this, {
|
|
11145
|
+
writable: true,
|
|
11146
|
+
value: function value(manager, context, backend) {
|
|
11147
|
+
var _backend$preview, _backend$skipDispatch;
|
|
11148
|
+
|
|
11149
|
+
if (!backend.backend) {
|
|
11150
|
+
throw new Error("You must specify a 'backend' property in your Backend entry: ".concat(JSON.stringify(backend)));
|
|
11151
|
+
}
|
|
11152
|
+
|
|
11153
|
+
var instance = backend.backend(manager, context, backend.options);
|
|
11154
|
+
var id = backend.id; // Try to infer an `id` if one doesn't exist
|
|
11155
|
+
|
|
11156
|
+
var inferName = !backend.id && instance && instance.constructor;
|
|
11157
|
+
|
|
11158
|
+
if (inferName) {
|
|
11159
|
+
id = instance.constructor.name;
|
|
11160
|
+
}
|
|
11161
|
+
|
|
11162
|
+
if (!id) {
|
|
11163
|
+
throw new Error("You must specify an 'id' property in your Backend entry: ".concat(JSON.stringify(backend), "\n see this guide: https://github.com/louisbrunner/dnd-multi-backend/tree/master/packages/react-dnd-multi-backend#migrating-from-5xx"));
|
|
11164
|
+
} else if (inferName) {
|
|
11165
|
+
console.warn( // eslint-disable-line no-console
|
|
11166
|
+
"Deprecation notice: You are using a pipeline which doesn't include backends' 'id'.\n This might be unsupported in the future, please specify 'id' explicitely for every backend.");
|
|
11167
|
+
}
|
|
11168
|
+
|
|
11169
|
+
if (_classPrivateFieldGet(_this, _backends)[id]) {
|
|
11170
|
+
throw new Error("You must specify a unique 'id' property in your Backend entry:\n ".concat(JSON.stringify(backend), " (conflicts with: ").concat(JSON.stringify(_classPrivateFieldGet(_this, _backends)[id]), ")"));
|
|
11171
|
+
}
|
|
11172
|
+
|
|
11173
|
+
return {
|
|
11174
|
+
id: id,
|
|
11175
|
+
instance: instance,
|
|
11176
|
+
preview: (_backend$preview = backend.preview) !== null && _backend$preview !== void 0 ? _backend$preview : false,
|
|
11177
|
+
transition: backend.transition,
|
|
11178
|
+
skipDispatchOnTransition: (_backend$skipDispatch = backend.skipDispatchOnTransition) !== null && _backend$skipDispatch !== void 0 ? _backend$skipDispatch : false
|
|
11179
|
+
};
|
|
11180
|
+
}
|
|
11181
|
+
});
|
|
11182
|
+
|
|
11183
|
+
_defineProperty(this, "setup", function () {
|
|
11184
|
+
if (typeof window === 'undefined') {
|
|
11185
|
+
return;
|
|
11186
|
+
}
|
|
11187
|
+
|
|
11188
|
+
if (MultiBackendImpl.isSetUp) {
|
|
11189
|
+
throw new Error('Cannot have two MultiBackends at the same time.');
|
|
11190
|
+
}
|
|
11191
|
+
|
|
11192
|
+
MultiBackendImpl.isSetUp = true;
|
|
11193
|
+
|
|
11194
|
+
_classPrivateFieldGet(_this, _addEventListeners).call(_this, window);
|
|
11195
|
+
|
|
11196
|
+
_classPrivateFieldGet(_this, _backends)[_classPrivateFieldGet(_this, _current)].instance.setup();
|
|
11197
|
+
});
|
|
11198
|
+
|
|
11199
|
+
_defineProperty(this, "teardown", function () {
|
|
11200
|
+
if (typeof window === 'undefined') {
|
|
11201
|
+
return;
|
|
11202
|
+
}
|
|
11203
|
+
|
|
11204
|
+
MultiBackendImpl.isSetUp = false;
|
|
11205
|
+
|
|
11206
|
+
_classPrivateFieldGet(_this, _removeEventListeners).call(_this, window);
|
|
11207
|
+
|
|
11208
|
+
_classPrivateFieldGet(_this, _backends)[_classPrivateFieldGet(_this, _current)].instance.teardown();
|
|
11209
|
+
});
|
|
11210
|
+
|
|
11211
|
+
_defineProperty(this, "connectDragSource", function (sourceId, node, options) {
|
|
11212
|
+
return _classPrivateFieldGet(_this, _connectBackend).call(_this, 'connectDragSource', sourceId, node, options);
|
|
11213
|
+
});
|
|
11214
|
+
|
|
11215
|
+
_defineProperty(this, "connectDragPreview", function (sourceId, node, options) {
|
|
11216
|
+
return _classPrivateFieldGet(_this, _connectBackend).call(_this, 'connectDragPreview', sourceId, node, options);
|
|
11217
|
+
});
|
|
11218
|
+
|
|
11219
|
+
_defineProperty(this, "connectDropTarget", function (sourceId, node, options) {
|
|
11220
|
+
return _classPrivateFieldGet(_this, _connectBackend).call(_this, 'connectDropTarget', sourceId, node, options);
|
|
11221
|
+
});
|
|
11222
|
+
|
|
11223
|
+
_defineProperty(this, "profile", function () {
|
|
11224
|
+
return _classPrivateFieldGet(_this, _backends)[_classPrivateFieldGet(_this, _current)].instance.profile();
|
|
11225
|
+
});
|
|
11226
|
+
|
|
11227
|
+
_defineProperty(this, "previewEnabled", function () {
|
|
11228
|
+
return _classPrivateFieldGet(_this, _backends)[_classPrivateFieldGet(_this, _current)].preview;
|
|
11229
|
+
});
|
|
11230
|
+
|
|
11231
|
+
_defineProperty(this, "previewsList", function () {
|
|
11232
|
+
return _classPrivateFieldGet(_this, _previews);
|
|
11233
|
+
});
|
|
11234
|
+
|
|
11235
|
+
_defineProperty(this, "backendsList", function () {
|
|
11236
|
+
return _classPrivateFieldGet(_this, _backendsList);
|
|
11237
|
+
});
|
|
11238
|
+
|
|
11239
|
+
_addEventListeners.set(this, {
|
|
11240
|
+
writable: true,
|
|
11241
|
+
value: function value(target) {
|
|
11242
|
+
_classPrivateFieldGet(_this, _backendsList).forEach(function (backend) {
|
|
11243
|
+
if (backend.transition) {
|
|
11244
|
+
target.addEventListener(backend.transition.event, _classPrivateFieldGet(_this, _backendSwitcher));
|
|
11245
|
+
}
|
|
11246
|
+
});
|
|
11247
|
+
}
|
|
11248
|
+
});
|
|
11249
|
+
|
|
11250
|
+
_removeEventListeners.set(this, {
|
|
11251
|
+
writable: true,
|
|
11252
|
+
value: function value(target) {
|
|
11253
|
+
_classPrivateFieldGet(_this, _backendsList).forEach(function (backend) {
|
|
11254
|
+
if (backend.transition) {
|
|
11255
|
+
target.removeEventListener(backend.transition.event, _classPrivateFieldGet(_this, _backendSwitcher));
|
|
11256
|
+
}
|
|
11257
|
+
});
|
|
11258
|
+
}
|
|
11259
|
+
});
|
|
11260
|
+
|
|
11261
|
+
_backendSwitcher.set(this, {
|
|
11262
|
+
writable: true,
|
|
11263
|
+
value: function value(event) {
|
|
11264
|
+
var oldBackend = _classPrivateFieldGet(_this, _current);
|
|
11265
|
+
|
|
11266
|
+
_classPrivateFieldGet(_this, _backendsList).some(function (backend) {
|
|
11267
|
+
if (backend.id !== _classPrivateFieldGet(_this, _current) && backend.transition && backend.transition.check(event)) {
|
|
11268
|
+
_classPrivateFieldSet(_this, _current, backend.id);
|
|
11269
|
+
|
|
11270
|
+
return true;
|
|
11271
|
+
}
|
|
11272
|
+
|
|
11273
|
+
return false;
|
|
11274
|
+
});
|
|
11275
|
+
|
|
11276
|
+
if (_classPrivateFieldGet(_this, _current) !== oldBackend) {
|
|
11277
|
+
var _event$target;
|
|
11278
|
+
|
|
11279
|
+
_classPrivateFieldGet(_this, _backends)[oldBackend].instance.teardown();
|
|
11280
|
+
|
|
11281
|
+
Object.keys(_classPrivateFieldGet(_this, _nodes)).forEach(function (id) {
|
|
11282
|
+
var _classPrivateFieldGet2;
|
|
11283
|
+
|
|
11284
|
+
var node = _classPrivateFieldGet(_this, _nodes)[id];
|
|
11285
|
+
|
|
11286
|
+
node.unsubscribe();
|
|
11287
|
+
node.unsubscribe = (_classPrivateFieldGet2 = _classPrivateFieldGet(_this, _callBackend)).call.apply(_classPrivateFieldGet2, [_this, node.func].concat(_toConsumableArray(node.args)));
|
|
11288
|
+
});
|
|
11289
|
+
|
|
11290
|
+
_classPrivateFieldGet(_this, _previews).backendChanged(_this);
|
|
11291
|
+
|
|
11292
|
+
var newBackend = _classPrivateFieldGet(_this, _backends)[_classPrivateFieldGet(_this, _current)];
|
|
11293
|
+
|
|
11294
|
+
newBackend.instance.setup();
|
|
11295
|
+
|
|
11296
|
+
if (newBackend.skipDispatchOnTransition) {
|
|
11297
|
+
return;
|
|
11298
|
+
}
|
|
11299
|
+
|
|
11300
|
+
var newEvent = null;
|
|
11301
|
+
|
|
11302
|
+
try {
|
|
11303
|
+
newEvent = event.constructor(event.type, event);
|
|
11304
|
+
} catch (_e) {
|
|
11305
|
+
newEvent = document.createEvent('Event');
|
|
11306
|
+
newEvent.initEvent(event.type, event.bubbles, event.cancelable);
|
|
11307
|
+
}
|
|
11308
|
+
|
|
11309
|
+
(_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.dispatchEvent(newEvent);
|
|
11310
|
+
}
|
|
11311
|
+
}
|
|
11312
|
+
});
|
|
11313
|
+
|
|
11314
|
+
_callBackend.set(this, {
|
|
11315
|
+
writable: true,
|
|
11316
|
+
value: function value(func, sourceId, node, options) {
|
|
11317
|
+
return _classPrivateFieldGet(_this, _backends)[_classPrivateFieldGet(_this, _current)].instance[func](sourceId, node, options);
|
|
11318
|
+
}
|
|
11319
|
+
});
|
|
11320
|
+
|
|
11321
|
+
_connectBackend.set(this, {
|
|
11322
|
+
writable: true,
|
|
11323
|
+
value: function value(func, sourceId, node, options) {
|
|
11324
|
+
var nodeId = "".concat(func, "_").concat(sourceId);
|
|
11325
|
+
|
|
11326
|
+
var unsubscribe = _classPrivateFieldGet(_this, _callBackend).call(_this, func, sourceId, node, options);
|
|
11327
|
+
|
|
11328
|
+
_classPrivateFieldGet(_this, _nodes)[nodeId] = {
|
|
11329
|
+
func: func,
|
|
11330
|
+
args: [sourceId, node, options],
|
|
11331
|
+
unsubscribe: unsubscribe
|
|
11332
|
+
};
|
|
11333
|
+
return function () {
|
|
11334
|
+
_classPrivateFieldGet(_this, _nodes)[nodeId].unsubscribe();
|
|
11335
|
+
|
|
11336
|
+
delete _classPrivateFieldGet(_this, _nodes)[nodeId];
|
|
11337
|
+
};
|
|
11338
|
+
}
|
|
11339
|
+
});
|
|
11340
|
+
|
|
11341
|
+
if (!_options || !_options.backends || _options.backends.length < 1) {
|
|
11342
|
+
throw new Error("You must specify at least one Backend, if you are coming from 2.x.x (or don't understand this error)\n see this guide: https://github.com/louisbrunner/dnd-multi-backend/tree/master/packages/react-dnd-multi-backend#migrating-from-2xx");
|
|
11343
|
+
}
|
|
11344
|
+
|
|
11345
|
+
_classPrivateFieldSet(this, _previews, new PreviewListImpl());
|
|
11346
|
+
|
|
11347
|
+
_classPrivateFieldSet(this, _backends, {});
|
|
11348
|
+
|
|
11349
|
+
_classPrivateFieldSet(this, _backendsList, []);
|
|
11350
|
+
|
|
11351
|
+
_options.backends.forEach(function (backend) {
|
|
11352
|
+
var backendRecord = _classPrivateFieldGet(_this, _createBackend).call(_this, _manager, _context, backend);
|
|
11353
|
+
|
|
11354
|
+
_classPrivateFieldGet(_this, _backends)[backendRecord.id] = backendRecord;
|
|
11355
|
+
|
|
11356
|
+
_classPrivateFieldGet(_this, _backendsList).push(backendRecord);
|
|
11357
|
+
});
|
|
11358
|
+
|
|
11359
|
+
_classPrivateFieldSet(this, _current, _classPrivateFieldGet(this, _backendsList)[0].id);
|
|
11360
|
+
|
|
11361
|
+
_classPrivateFieldSet(this, _nodes, {});
|
|
11362
|
+
};
|
|
11363
|
+
|
|
11364
|
+
_defineProperty(MultiBackendImpl, "isSetUp", false);
|
|
11365
|
+
|
|
8563
11366
|
/******************************************************************************
|
|
8564
11367
|
Copyright (c) Microsoft Corporation.
|
|
8565
11368
|
|
|
@@ -9375,25 +12178,26 @@ var TreeView = function (_a, ref) {
|
|
|
9375
12178
|
setShowTree(false);
|
|
9376
12179
|
}
|
|
9377
12180
|
}, [initialOpen, treeData]);
|
|
9378
|
-
return (React__default.createElement(React__default.Fragment, null,
|
|
9379
|
-
|
|
9380
|
-
|
|
9381
|
-
|
|
9382
|
-
|
|
9383
|
-
|
|
9384
|
-
|
|
9385
|
-
|
|
9386
|
-
|
|
9387
|
-
|
|
9388
|
-
|
|
9389
|
-
|
|
9390
|
-
|
|
9391
|
-
|
|
9392
|
-
|
|
9393
|
-
|
|
9394
|
-
|
|
9395
|
-
|
|
9396
|
-
|
|
12181
|
+
return (React__default.createElement(React__default.Fragment, null,
|
|
12182
|
+
React__default.createElement(DndProvider, { backend: HTML5Backend }, showTree && (React__default.createElement(Tree, { ref: ref, tree: list, classes: {
|
|
12183
|
+
root: 'pl-0 ml-0 !border-l-0',
|
|
12184
|
+
container: 'border-l pl-2 ml-3 border-l-gray-300 relative',
|
|
12185
|
+
listItem: 'flex text-sm font-medium rounded-md flex-col',
|
|
12186
|
+
dropTarget: 'classes-dropTarget',
|
|
12187
|
+
draggingSource: 'classes-draggingSource',
|
|
12188
|
+
placeholder: 'bg-purple-500 h-[2px] absolute w-[calc(100%-16px)] left-4'
|
|
12189
|
+
}, rootId: 0, onDrop: handleDrop, sort: false, insertDroppableFirst: false, canDrop: function (tree, _a) {
|
|
12190
|
+
var dragSource = _a.dragSource, dropTargetId = _a.dropTargetId;
|
|
12191
|
+
if ((dragSource === null || dragSource === void 0 ? void 0 : dragSource.parent) === dropTargetId) {
|
|
12192
|
+
return true;
|
|
12193
|
+
}
|
|
12194
|
+
}, initialOpen: openKeys, dropTargetOffset: 5, placeholderRender: function (node, _a) {
|
|
12195
|
+
var depth = _a.depth;
|
|
12196
|
+
return (React__default.createElement(Placeholder, { node: node, depth: depth }));
|
|
12197
|
+
}, render: function (node, _a) {
|
|
12198
|
+
var depth = _a.depth, isOpen = _a.isOpen, onToggle = _a.onToggle;
|
|
12199
|
+
return (React__default.createElement(CustomNode, { node: node, depth: depth, isOpen: isOpen, onToggle: onToggle, onUpdate: handleUpdateList }));
|
|
12200
|
+
} })))));
|
|
9397
12201
|
};
|
|
9398
12202
|
var _TreeView = forwardRef(TreeView);
|
|
9399
12203
|
|