@rkmodules/rules 0.0.54 → 0.0.56
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs.js +1914 -110
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.esm.js +1915 -112
- package/dist/index.esm.js.map +1 -1
- package/dist/lib/ddcontext.d.ts +4 -0
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -8,6 +8,8 @@ var classNames = require('classnames');
|
|
|
8
8
|
var rcin = require('rc-input-number');
|
|
9
9
|
var zustand = require('zustand');
|
|
10
10
|
var middleware = require('zustand/middleware');
|
|
11
|
+
var reactDndHtml5Backend = require('react-dnd-html5-backend');
|
|
12
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
11
13
|
|
|
12
14
|
/******************************************************************************
|
|
13
15
|
Copyright (c) Microsoft Corporation.
|
|
@@ -596,7 +598,7 @@ var primitives$6 = (_a$6 = {},
|
|
|
596
598
|
_a$6[value.name] = value,
|
|
597
599
|
_a$6);
|
|
598
600
|
|
|
599
|
-
var add = {
|
|
601
|
+
var add$1 = {
|
|
600
602
|
name: "add",
|
|
601
603
|
label: "Add",
|
|
602
604
|
description: "Add two numbers",
|
|
@@ -806,8 +808,8 @@ var greaterThan = {
|
|
|
806
808
|
label: "Greater Than",
|
|
807
809
|
description: "Compare on greater than or greater than or equal to",
|
|
808
810
|
inputs: {
|
|
809
|
-
a: "number",
|
|
810
|
-
b: "number",
|
|
811
|
+
a: { type: "number", default: 0 },
|
|
812
|
+
b: { type: "number", default: 0 },
|
|
811
813
|
},
|
|
812
814
|
outputs: {
|
|
813
815
|
gt: "boolean",
|
|
@@ -817,9 +819,13 @@ var greaterThan = {
|
|
|
817
819
|
return __generator(this, function (_a) {
|
|
818
820
|
return [2 /*return*/, {
|
|
819
821
|
gt: binaryOnTree(inputs.a, inputs.b, function (itemA, itemB) {
|
|
822
|
+
if (itemA === undefined || itemB === undefined)
|
|
823
|
+
return DISCARD;
|
|
820
824
|
return itemA > itemB;
|
|
821
825
|
}, true),
|
|
822
826
|
gte: binaryOnTree(inputs.a, inputs.b, function (itemA, itemB) {
|
|
827
|
+
if (itemA === undefined || itemB === undefined)
|
|
828
|
+
return DISCARD;
|
|
823
829
|
return itemA >= itemB;
|
|
824
830
|
}, true),
|
|
825
831
|
}];
|
|
@@ -832,8 +838,8 @@ var lessThan = {
|
|
|
832
838
|
label: "Less Than",
|
|
833
839
|
description: "Compare on less than or less than or equal to",
|
|
834
840
|
inputs: {
|
|
835
|
-
a: "number",
|
|
836
|
-
b: "number",
|
|
841
|
+
a: { type: "number", default: 0 },
|
|
842
|
+
b: { type: "number", default: 0 },
|
|
837
843
|
},
|
|
838
844
|
outputs: {
|
|
839
845
|
lt: "boolean",
|
|
@@ -843,9 +849,13 @@ var lessThan = {
|
|
|
843
849
|
return __generator(this, function (_a) {
|
|
844
850
|
return [2 /*return*/, {
|
|
845
851
|
lt: binaryOnTree(inputs.a, inputs.b, function (itemA, itemB) {
|
|
852
|
+
if (itemA === undefined || itemB === undefined)
|
|
853
|
+
return DISCARD;
|
|
846
854
|
return itemA < itemB;
|
|
847
855
|
}, true),
|
|
848
856
|
lte: binaryOnTree(inputs.a, inputs.b, function (itemA, itemB) {
|
|
857
|
+
if (itemA === undefined || itemB === undefined)
|
|
858
|
+
return DISCARD;
|
|
849
859
|
return itemA <= itemB;
|
|
850
860
|
}, true),
|
|
851
861
|
}];
|
|
@@ -875,7 +885,7 @@ var multiply = {
|
|
|
875
885
|
}); },
|
|
876
886
|
};
|
|
877
887
|
|
|
878
|
-
var subtract = {
|
|
888
|
+
var subtract$1 = {
|
|
879
889
|
name: "subtract",
|
|
880
890
|
label: "Subtract",
|
|
881
891
|
description: "Subtract two numbers",
|
|
@@ -902,8 +912,8 @@ var primitives$5 = (_a$5 = {},
|
|
|
902
912
|
_a$5[calc.name] = calc,
|
|
903
913
|
_a$5[lessThan.name] = lessThan,
|
|
904
914
|
_a$5[greaterThan.name] = greaterThan,
|
|
905
|
-
_a$5[add.name] = add,
|
|
906
|
-
_a$5[subtract.name] = subtract,
|
|
915
|
+
_a$5[add$1.name] = add$1,
|
|
916
|
+
_a$5[subtract$1.name] = subtract$1,
|
|
907
917
|
_a$5[multiply.name] = multiply,
|
|
908
918
|
_a$5[divide.name] = divide,
|
|
909
919
|
_a$5);
|
|
@@ -965,21 +975,23 @@ var listItem = {
|
|
|
965
975
|
},
|
|
966
976
|
outputs: {
|
|
967
977
|
item: "any",
|
|
978
|
+
others: "any",
|
|
968
979
|
},
|
|
969
980
|
impl: function (inputs) { return __awaiter(void 0, void 0, void 0, function () {
|
|
981
|
+
var item, others;
|
|
970
982
|
return __generator(this, function (_a) {
|
|
983
|
+
item = binaryOnTreeBranch(inputs.list || {}, inputs.index || {}, function (branch, indices) {
|
|
984
|
+
if (indices) {
|
|
985
|
+
return indices.map(function (i) { return branch[i]; });
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
others = binaryOnTreeBranch(inputs.list || {}, inputs.index || {}, function (branch, indices) {
|
|
989
|
+
console.log("others", branch, indices);
|
|
990
|
+
return branch.filter(function (i) { return !(indices === null || indices === void 0 ? void 0 : indices.includes(i)); });
|
|
991
|
+
});
|
|
971
992
|
return [2 /*return*/, {
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
// if (indices) {
|
|
975
|
-
// return indices.map((i) => branch[i]);
|
|
976
|
-
// }
|
|
977
|
-
// }),
|
|
978
|
-
item: binaryOnTreeBranch(inputs.list || {}, inputs.index || {}, function (branch, indices) {
|
|
979
|
-
if (indices) {
|
|
980
|
-
return indices.map(function (i) { return branch[i]; });
|
|
981
|
-
}
|
|
982
|
-
}),
|
|
993
|
+
item: item,
|
|
994
|
+
others: others,
|
|
983
995
|
}];
|
|
984
996
|
});
|
|
985
997
|
}); },
|
|
@@ -1526,116 +1538,1902 @@ var Engine = /** @class */ (function () {
|
|
|
1526
1538
|
}
|
|
1527
1539
|
});
|
|
1528
1540
|
});
|
|
1529
|
-
return newFn;
|
|
1541
|
+
return newFn;
|
|
1542
|
+
};
|
|
1543
|
+
Engine.prototype.applyEdgeDelete = function (oldFn, fromNode, toNode, fromField, toField) {
|
|
1544
|
+
var newFn = __assign(__assign({}, oldFn), { body: __assign({}, oldFn.body) });
|
|
1545
|
+
var from = newFn.body[fromNode];
|
|
1546
|
+
var to = newFn.body[toNode];
|
|
1547
|
+
if (!from || !to) {
|
|
1548
|
+
console.warn("Invalid nodes for edge deletion");
|
|
1549
|
+
return newFn;
|
|
1550
|
+
}
|
|
1551
|
+
if (to.inputs && to.inputs[toField] === "<".concat(fromNode, ".").concat(fromField, ">")) {
|
|
1552
|
+
delete to.inputs[toField];
|
|
1553
|
+
}
|
|
1554
|
+
else {
|
|
1555
|
+
console.warn("No matching edge found to delete");
|
|
1556
|
+
}
|
|
1557
|
+
return newFn;
|
|
1558
|
+
};
|
|
1559
|
+
Engine.prototype.applyNodeAdd = function (oldFn, nodeName, callback) {
|
|
1560
|
+
var newFn = __assign(__assign({}, oldFn), { body: __assign({}, oldFn.body) });
|
|
1561
|
+
var id = uid$1();
|
|
1562
|
+
// ensure unique id
|
|
1563
|
+
while (newFn.body[id]) {
|
|
1564
|
+
id = uid$1();
|
|
1565
|
+
}
|
|
1566
|
+
// get inputs defaults
|
|
1567
|
+
var inputs = {};
|
|
1568
|
+
Object.entries(this.fnIndex[nodeName].inputs || {}).forEach(function (_a) {
|
|
1569
|
+
var _b = __read(_a, 2), key = _b[0], def = _b[1];
|
|
1570
|
+
var normDef = normalizeVarDef(def);
|
|
1571
|
+
if (normDef.default !== undefined) {
|
|
1572
|
+
inputs[key] = normDef.default;
|
|
1573
|
+
}
|
|
1574
|
+
});
|
|
1575
|
+
// get params defaults
|
|
1576
|
+
var params = {};
|
|
1577
|
+
Object.entries(this.fnIndex[nodeName].params || {}).forEach(function (_a) {
|
|
1578
|
+
var _b = __read(_a, 2), key = _b[0], def = _b[1];
|
|
1579
|
+
var normDef = normalizeVarDef(def);
|
|
1580
|
+
if (normDef.default !== undefined) {
|
|
1581
|
+
params[key] = normDef.default;
|
|
1582
|
+
}
|
|
1583
|
+
});
|
|
1584
|
+
var newCall = {
|
|
1585
|
+
name: nodeName,
|
|
1586
|
+
inputs: inputs,
|
|
1587
|
+
params: params,
|
|
1588
|
+
};
|
|
1589
|
+
newFn.body[id] = newCall;
|
|
1590
|
+
callback === null || callback === void 0 ? void 0 : callback(newCall, id);
|
|
1591
|
+
return topSort(newFn);
|
|
1592
|
+
};
|
|
1593
|
+
Engine.prototype.applyNodeConnect = function (oldFn, fromNode, toNode, fromField, toField) {
|
|
1594
|
+
var newFn = __assign(__assign({}, oldFn), { body: __assign({}, oldFn.body) });
|
|
1595
|
+
var from = newFn.body[fromNode];
|
|
1596
|
+
var to = __assign({}, newFn.body[toNode]);
|
|
1597
|
+
if (!from || !to) {
|
|
1598
|
+
console.warn("Invalid nodes for connection");
|
|
1599
|
+
return newFn;
|
|
1600
|
+
}
|
|
1601
|
+
if (!to.inputs) {
|
|
1602
|
+
to.inputs = {};
|
|
1603
|
+
}
|
|
1604
|
+
// add the reference
|
|
1605
|
+
to.inputs[toField] = "<".concat(fromNode, ".").concat(fromField, ">");
|
|
1606
|
+
newFn.body[toNode] = to;
|
|
1607
|
+
return topSort(newFn);
|
|
1608
|
+
};
|
|
1609
|
+
return Engine;
|
|
1610
|
+
}());
|
|
1611
|
+
|
|
1612
|
+
/**
|
|
1613
|
+
* Create the React Context
|
|
1614
|
+
*/ const DndContext = React.createContext({
|
|
1615
|
+
dragDropManager: undefined
|
|
1616
|
+
});
|
|
1617
|
+
|
|
1618
|
+
/**
|
|
1619
|
+
* Adapted from React: https://github.com/facebook/react/blob/master/packages/shared/formatProdErrorMessage.js
|
|
1620
|
+
*
|
|
1621
|
+
* Do not require this module directly! Use normal throw error calls. These messages will be replaced with error codes
|
|
1622
|
+
* during build.
|
|
1623
|
+
* @param {number} code
|
|
1624
|
+
*/
|
|
1625
|
+
function formatProdErrorMessage(code) {
|
|
1626
|
+
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. ';
|
|
1627
|
+
}
|
|
1628
|
+
|
|
1629
|
+
// Inlined version of the `symbol-observable` polyfill
|
|
1630
|
+
var $$observable = (function () {
|
|
1631
|
+
return typeof Symbol === 'function' && Symbol.observable || '@@observable';
|
|
1632
|
+
})();
|
|
1633
|
+
|
|
1634
|
+
/**
|
|
1635
|
+
* These are private action types reserved by Redux.
|
|
1636
|
+
* For any unknown actions, you must return the current state.
|
|
1637
|
+
* If the current state is undefined, you must return the initial state.
|
|
1638
|
+
* Do not reference these action types directly in your code.
|
|
1639
|
+
*/
|
|
1640
|
+
var randomString = function randomString() {
|
|
1641
|
+
return Math.random().toString(36).substring(7).split('').join('.');
|
|
1642
|
+
};
|
|
1643
|
+
|
|
1644
|
+
var ActionTypes = {
|
|
1645
|
+
INIT: "@@redux/INIT" + randomString(),
|
|
1646
|
+
REPLACE: "@@redux/REPLACE" + randomString()};
|
|
1647
|
+
|
|
1648
|
+
/**
|
|
1649
|
+
* @param {any} obj The object to inspect.
|
|
1650
|
+
* @returns {boolean} True if the argument appears to be a plain object.
|
|
1651
|
+
*/
|
|
1652
|
+
function isPlainObject(obj) {
|
|
1653
|
+
if (typeof obj !== 'object' || obj === null) return false;
|
|
1654
|
+
var proto = obj;
|
|
1655
|
+
|
|
1656
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
1657
|
+
proto = Object.getPrototypeOf(proto);
|
|
1658
|
+
}
|
|
1659
|
+
|
|
1660
|
+
return Object.getPrototypeOf(obj) === proto;
|
|
1661
|
+
}
|
|
1662
|
+
|
|
1663
|
+
// Inlined / shortened version of `kindOf` from https://github.com/jonschlinkert/kind-of
|
|
1664
|
+
function miniKindOf(val) {
|
|
1665
|
+
if (val === void 0) return 'undefined';
|
|
1666
|
+
if (val === null) return 'null';
|
|
1667
|
+
var type = typeof val;
|
|
1668
|
+
|
|
1669
|
+
switch (type) {
|
|
1670
|
+
case 'boolean':
|
|
1671
|
+
case 'string':
|
|
1672
|
+
case 'number':
|
|
1673
|
+
case 'symbol':
|
|
1674
|
+
case 'function':
|
|
1675
|
+
{
|
|
1676
|
+
return type;
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
if (Array.isArray(val)) return 'array';
|
|
1681
|
+
if (isDate(val)) return 'date';
|
|
1682
|
+
if (isError(val)) return 'error';
|
|
1683
|
+
var constructorName = ctorName(val);
|
|
1684
|
+
|
|
1685
|
+
switch (constructorName) {
|
|
1686
|
+
case 'Symbol':
|
|
1687
|
+
case 'Promise':
|
|
1688
|
+
case 'WeakMap':
|
|
1689
|
+
case 'WeakSet':
|
|
1690
|
+
case 'Map':
|
|
1691
|
+
case 'Set':
|
|
1692
|
+
return constructorName;
|
|
1693
|
+
} // other
|
|
1694
|
+
|
|
1695
|
+
|
|
1696
|
+
return type.slice(8, -1).toLowerCase().replace(/\s/g, '');
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
function ctorName(val) {
|
|
1700
|
+
return typeof val.constructor === 'function' ? val.constructor.name : null;
|
|
1701
|
+
}
|
|
1702
|
+
|
|
1703
|
+
function isError(val) {
|
|
1704
|
+
return val instanceof Error || typeof val.message === 'string' && val.constructor && typeof val.constructor.stackTraceLimit === 'number';
|
|
1705
|
+
}
|
|
1706
|
+
|
|
1707
|
+
function isDate(val) {
|
|
1708
|
+
if (val instanceof Date) return true;
|
|
1709
|
+
return typeof val.toDateString === 'function' && typeof val.getDate === 'function' && typeof val.setDate === 'function';
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
function kindOf(val) {
|
|
1713
|
+
var typeOfVal = typeof val;
|
|
1714
|
+
|
|
1715
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1716
|
+
typeOfVal = miniKindOf(val);
|
|
1717
|
+
}
|
|
1718
|
+
|
|
1719
|
+
return typeOfVal;
|
|
1720
|
+
}
|
|
1721
|
+
|
|
1722
|
+
/**
|
|
1723
|
+
* @deprecated
|
|
1724
|
+
*
|
|
1725
|
+
* **We recommend using the `configureStore` method
|
|
1726
|
+
* of the `@reduxjs/toolkit` package**, which replaces `createStore`.
|
|
1727
|
+
*
|
|
1728
|
+
* Redux Toolkit is our recommended approach for writing Redux logic today,
|
|
1729
|
+
* including store setup, reducers, data fetching, and more.
|
|
1730
|
+
*
|
|
1731
|
+
* **For more details, please read this Redux docs page:**
|
|
1732
|
+
* **https://redux.js.org/introduction/why-rtk-is-redux-today**
|
|
1733
|
+
*
|
|
1734
|
+
* `configureStore` from Redux Toolkit is an improved version of `createStore` that
|
|
1735
|
+
* simplifies setup and helps avoid common bugs.
|
|
1736
|
+
*
|
|
1737
|
+
* You should not be using the `redux` core package by itself today, except for learning purposes.
|
|
1738
|
+
* The `createStore` method from the core `redux` package will not be removed, but we encourage
|
|
1739
|
+
* all users to migrate to using Redux Toolkit for all Redux code.
|
|
1740
|
+
*
|
|
1741
|
+
* If you want to use `createStore` without this visual deprecation warning, use
|
|
1742
|
+
* the `legacy_createStore` import instead:
|
|
1743
|
+
*
|
|
1744
|
+
* `import { legacy_createStore as createStore} from 'redux'`
|
|
1745
|
+
*
|
|
1746
|
+
*/
|
|
1747
|
+
|
|
1748
|
+
function createStore(reducer, preloadedState, enhancer) {
|
|
1749
|
+
var _ref2;
|
|
1750
|
+
|
|
1751
|
+
if (typeof preloadedState === 'function' && typeof enhancer === 'function' || typeof enhancer === 'function' && typeof arguments[3] === 'function') {
|
|
1752
|
+
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.');
|
|
1753
|
+
}
|
|
1754
|
+
|
|
1755
|
+
if (typeof preloadedState === 'function' && typeof enhancer === 'undefined') {
|
|
1756
|
+
enhancer = preloadedState;
|
|
1757
|
+
preloadedState = undefined;
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
if (typeof enhancer !== 'undefined') {
|
|
1761
|
+
if (typeof enhancer !== 'function') {
|
|
1762
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(1) : "Expected the enhancer to be a function. Instead, received: '" + kindOf(enhancer) + "'");
|
|
1763
|
+
}
|
|
1764
|
+
|
|
1765
|
+
return enhancer(createStore)(reducer, preloadedState);
|
|
1766
|
+
}
|
|
1767
|
+
|
|
1768
|
+
if (typeof reducer !== 'function') {
|
|
1769
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(2) : "Expected the root reducer to be a function. Instead, received: '" + kindOf(reducer) + "'");
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
var currentReducer = reducer;
|
|
1773
|
+
var currentState = preloadedState;
|
|
1774
|
+
var currentListeners = [];
|
|
1775
|
+
var nextListeners = currentListeners;
|
|
1776
|
+
var isDispatching = false;
|
|
1777
|
+
/**
|
|
1778
|
+
* This makes a shallow copy of currentListeners so we can use
|
|
1779
|
+
* nextListeners as a temporary list while dispatching.
|
|
1780
|
+
*
|
|
1781
|
+
* This prevents any bugs around consumers calling
|
|
1782
|
+
* subscribe/unsubscribe in the middle of a dispatch.
|
|
1783
|
+
*/
|
|
1784
|
+
|
|
1785
|
+
function ensureCanMutateNextListeners() {
|
|
1786
|
+
if (nextListeners === currentListeners) {
|
|
1787
|
+
nextListeners = currentListeners.slice();
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
/**
|
|
1791
|
+
* Reads the state tree managed by the store.
|
|
1792
|
+
*
|
|
1793
|
+
* @returns {any} The current state tree of your application.
|
|
1794
|
+
*/
|
|
1795
|
+
|
|
1796
|
+
|
|
1797
|
+
function getState() {
|
|
1798
|
+
if (isDispatching) {
|
|
1799
|
+
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.');
|
|
1800
|
+
}
|
|
1801
|
+
|
|
1802
|
+
return currentState;
|
|
1803
|
+
}
|
|
1804
|
+
/**
|
|
1805
|
+
* Adds a change listener. It will be called any time an action is dispatched,
|
|
1806
|
+
* and some part of the state tree may potentially have changed. You may then
|
|
1807
|
+
* call `getState()` to read the current state tree inside the callback.
|
|
1808
|
+
*
|
|
1809
|
+
* You may call `dispatch()` from a change listener, with the following
|
|
1810
|
+
* caveats:
|
|
1811
|
+
*
|
|
1812
|
+
* 1. The subscriptions are snapshotted just before every `dispatch()` call.
|
|
1813
|
+
* If you subscribe or unsubscribe while the listeners are being invoked, this
|
|
1814
|
+
* will not have any effect on the `dispatch()` that is currently in progress.
|
|
1815
|
+
* However, the next `dispatch()` call, whether nested or not, will use a more
|
|
1816
|
+
* recent snapshot of the subscription list.
|
|
1817
|
+
*
|
|
1818
|
+
* 2. The listener should not expect to see all state changes, as the state
|
|
1819
|
+
* might have been updated multiple times during a nested `dispatch()` before
|
|
1820
|
+
* the listener is called. It is, however, guaranteed that all subscribers
|
|
1821
|
+
* registered before the `dispatch()` started will be called with the latest
|
|
1822
|
+
* state by the time it exits.
|
|
1823
|
+
*
|
|
1824
|
+
* @param {Function} listener A callback to be invoked on every dispatch.
|
|
1825
|
+
* @returns {Function} A function to remove this change listener.
|
|
1826
|
+
*/
|
|
1827
|
+
|
|
1828
|
+
|
|
1829
|
+
function subscribe(listener) {
|
|
1830
|
+
if (typeof listener !== 'function') {
|
|
1831
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(4) : "Expected the listener to be a function. Instead, received: '" + kindOf(listener) + "'");
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
if (isDispatching) {
|
|
1835
|
+
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.');
|
|
1836
|
+
}
|
|
1837
|
+
|
|
1838
|
+
var isSubscribed = true;
|
|
1839
|
+
ensureCanMutateNextListeners();
|
|
1840
|
+
nextListeners.push(listener);
|
|
1841
|
+
return function unsubscribe() {
|
|
1842
|
+
if (!isSubscribed) {
|
|
1843
|
+
return;
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
if (isDispatching) {
|
|
1847
|
+
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.');
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
isSubscribed = false;
|
|
1851
|
+
ensureCanMutateNextListeners();
|
|
1852
|
+
var index = nextListeners.indexOf(listener);
|
|
1853
|
+
nextListeners.splice(index, 1);
|
|
1854
|
+
currentListeners = null;
|
|
1855
|
+
};
|
|
1856
|
+
}
|
|
1857
|
+
/**
|
|
1858
|
+
* Dispatches an action. It is the only way to trigger a state change.
|
|
1859
|
+
*
|
|
1860
|
+
* The `reducer` function, used to create the store, will be called with the
|
|
1861
|
+
* current state tree and the given `action`. Its return value will
|
|
1862
|
+
* be considered the **next** state of the tree, and the change listeners
|
|
1863
|
+
* will be notified.
|
|
1864
|
+
*
|
|
1865
|
+
* The base implementation only supports plain object actions. If you want to
|
|
1866
|
+
* dispatch a Promise, an Observable, a thunk, or something else, you need to
|
|
1867
|
+
* wrap your store creating function into the corresponding middleware. For
|
|
1868
|
+
* example, see the documentation for the `redux-thunk` package. Even the
|
|
1869
|
+
* middleware will eventually dispatch plain object actions using this method.
|
|
1870
|
+
*
|
|
1871
|
+
* @param {Object} action A plain object representing “what changed”. It is
|
|
1872
|
+
* a good idea to keep actions serializable so you can record and replay user
|
|
1873
|
+
* sessions, or use the time travelling `redux-devtools`. An action must have
|
|
1874
|
+
* a `type` property which may not be `undefined`. It is a good idea to use
|
|
1875
|
+
* string constants for action types.
|
|
1876
|
+
*
|
|
1877
|
+
* @returns {Object} For convenience, the same action object you dispatched.
|
|
1878
|
+
*
|
|
1879
|
+
* Note that, if you use a custom middleware, it may wrap `dispatch()` to
|
|
1880
|
+
* return something else (for example, a Promise you can await).
|
|
1881
|
+
*/
|
|
1882
|
+
|
|
1883
|
+
|
|
1884
|
+
function dispatch(action) {
|
|
1885
|
+
if (!isPlainObject(action)) {
|
|
1886
|
+
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.");
|
|
1887
|
+
}
|
|
1888
|
+
|
|
1889
|
+
if (typeof action.type === 'undefined') {
|
|
1890
|
+
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.');
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
if (isDispatching) {
|
|
1894
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(9) : 'Reducers may not dispatch actions.');
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
try {
|
|
1898
|
+
isDispatching = true;
|
|
1899
|
+
currentState = currentReducer(currentState, action);
|
|
1900
|
+
} finally {
|
|
1901
|
+
isDispatching = false;
|
|
1902
|
+
}
|
|
1903
|
+
|
|
1904
|
+
var listeners = currentListeners = nextListeners;
|
|
1905
|
+
|
|
1906
|
+
for (var i = 0; i < listeners.length; i++) {
|
|
1907
|
+
var listener = listeners[i];
|
|
1908
|
+
listener();
|
|
1909
|
+
}
|
|
1910
|
+
|
|
1911
|
+
return action;
|
|
1912
|
+
}
|
|
1913
|
+
/**
|
|
1914
|
+
* Replaces the reducer currently used by the store to calculate the state.
|
|
1915
|
+
*
|
|
1916
|
+
* You might need this if your app implements code splitting and you want to
|
|
1917
|
+
* load some of the reducers dynamically. You might also need this if you
|
|
1918
|
+
* implement a hot reloading mechanism for Redux.
|
|
1919
|
+
*
|
|
1920
|
+
* @param {Function} nextReducer The reducer for the store to use instead.
|
|
1921
|
+
* @returns {void}
|
|
1922
|
+
*/
|
|
1923
|
+
|
|
1924
|
+
|
|
1925
|
+
function replaceReducer(nextReducer) {
|
|
1926
|
+
if (typeof nextReducer !== 'function') {
|
|
1927
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(10) : "Expected the nextReducer to be a function. Instead, received: '" + kindOf(nextReducer));
|
|
1928
|
+
}
|
|
1929
|
+
|
|
1930
|
+
currentReducer = nextReducer; // This action has a similiar effect to ActionTypes.INIT.
|
|
1931
|
+
// Any reducers that existed in both the new and old rootReducer
|
|
1932
|
+
// will receive the previous state. This effectively populates
|
|
1933
|
+
// the new state tree with any relevant data from the old one.
|
|
1934
|
+
|
|
1935
|
+
dispatch({
|
|
1936
|
+
type: ActionTypes.REPLACE
|
|
1937
|
+
});
|
|
1938
|
+
}
|
|
1939
|
+
/**
|
|
1940
|
+
* Interoperability point for observable/reactive libraries.
|
|
1941
|
+
* @returns {observable} A minimal observable of state changes.
|
|
1942
|
+
* For more information, see the observable proposal:
|
|
1943
|
+
* https://github.com/tc39/proposal-observable
|
|
1944
|
+
*/
|
|
1945
|
+
|
|
1946
|
+
|
|
1947
|
+
function observable() {
|
|
1948
|
+
var _ref;
|
|
1949
|
+
|
|
1950
|
+
var outerSubscribe = subscribe;
|
|
1951
|
+
return _ref = {
|
|
1952
|
+
/**
|
|
1953
|
+
* The minimal observable subscription method.
|
|
1954
|
+
* @param {Object} observer Any object that can be used as an observer.
|
|
1955
|
+
* The observer object should have a `next` method.
|
|
1956
|
+
* @returns {subscription} An object with an `unsubscribe` method that can
|
|
1957
|
+
* be used to unsubscribe the observable from the store, and prevent further
|
|
1958
|
+
* emission of values from the observable.
|
|
1959
|
+
*/
|
|
1960
|
+
subscribe: function subscribe(observer) {
|
|
1961
|
+
if (typeof observer !== 'object' || observer === null) {
|
|
1962
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(11) : "Expected the observer to be an object. Instead, received: '" + kindOf(observer) + "'");
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
function observeState() {
|
|
1966
|
+
if (observer.next) {
|
|
1967
|
+
observer.next(getState());
|
|
1968
|
+
}
|
|
1969
|
+
}
|
|
1970
|
+
|
|
1971
|
+
observeState();
|
|
1972
|
+
var unsubscribe = outerSubscribe(observeState);
|
|
1973
|
+
return {
|
|
1974
|
+
unsubscribe: unsubscribe
|
|
1975
|
+
};
|
|
1976
|
+
}
|
|
1977
|
+
}, _ref[$$observable] = function () {
|
|
1978
|
+
return this;
|
|
1979
|
+
}, _ref;
|
|
1980
|
+
} // When a store is created, an "INIT" action is dispatched so that every
|
|
1981
|
+
// reducer returns their initial state. This effectively populates
|
|
1982
|
+
// the initial state tree.
|
|
1983
|
+
|
|
1984
|
+
|
|
1985
|
+
dispatch({
|
|
1986
|
+
type: ActionTypes.INIT
|
|
1987
|
+
});
|
|
1988
|
+
return _ref2 = {
|
|
1989
|
+
dispatch: dispatch,
|
|
1990
|
+
subscribe: subscribe,
|
|
1991
|
+
getState: getState,
|
|
1992
|
+
replaceReducer: replaceReducer
|
|
1993
|
+
}, _ref2[$$observable] = observable, _ref2;
|
|
1994
|
+
}
|
|
1995
|
+
|
|
1996
|
+
/**
|
|
1997
|
+
* Use invariant() to assert state which your program assumes to be true.
|
|
1998
|
+
*
|
|
1999
|
+
* Provide sprintf-style format (only %s is supported) and arguments
|
|
2000
|
+
* to provide information about what broke and what you were
|
|
2001
|
+
* expecting.
|
|
2002
|
+
*
|
|
2003
|
+
* The invariant message will be stripped in production, but the invariant
|
|
2004
|
+
* will remain to ensure logic does not differ in production.
|
|
2005
|
+
*/ function invariant(condition, format, ...args) {
|
|
2006
|
+
if (isProduction()) {
|
|
2007
|
+
if (format === undefined) {
|
|
2008
|
+
throw new Error('invariant requires an error message argument');
|
|
2009
|
+
}
|
|
2010
|
+
}
|
|
2011
|
+
if (!condition) {
|
|
2012
|
+
let error;
|
|
2013
|
+
if (format === undefined) {
|
|
2014
|
+
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
|
|
2015
|
+
} else {
|
|
2016
|
+
let argIndex = 0;
|
|
2017
|
+
error = new Error(format.replace(/%s/g, function() {
|
|
2018
|
+
return args[argIndex++];
|
|
2019
|
+
}));
|
|
2020
|
+
error.name = 'Invariant Violation';
|
|
2021
|
+
}
|
|
2022
|
+
error.framesToPop = 1 // we don't care about invariant's own frame
|
|
2023
|
+
;
|
|
2024
|
+
throw error;
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
function isProduction() {
|
|
2028
|
+
return typeof process !== 'undefined' && process.env['NODE_ENV'] === 'production';
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
// cheap lodash replacements
|
|
2032
|
+
/**
|
|
2033
|
+
* drop-in replacement for _.get
|
|
2034
|
+
* @param obj
|
|
2035
|
+
* @param path
|
|
2036
|
+
* @param defaultValue
|
|
2037
|
+
*/ function get(obj, path, defaultValue) {
|
|
2038
|
+
return path.split('.').reduce((a, c)=>a && a[c] ? a[c] : defaultValue || null
|
|
2039
|
+
, obj);
|
|
2040
|
+
}
|
|
2041
|
+
/**
|
|
2042
|
+
* drop-in replacement for _.without
|
|
2043
|
+
*/ function without(items, item) {
|
|
2044
|
+
return items.filter((i)=>i !== item
|
|
2045
|
+
);
|
|
2046
|
+
}
|
|
2047
|
+
/**
|
|
2048
|
+
* drop-in replacement for _.isString
|
|
2049
|
+
* @param input
|
|
2050
|
+
*/ function isObject(input) {
|
|
2051
|
+
return typeof input === 'object';
|
|
2052
|
+
}
|
|
2053
|
+
/**
|
|
2054
|
+
* replacement for _.xor
|
|
2055
|
+
* @param itemsA
|
|
2056
|
+
* @param itemsB
|
|
2057
|
+
*/ function xor(itemsA, itemsB) {
|
|
2058
|
+
const map = new Map();
|
|
2059
|
+
const insertItem = (item)=>{
|
|
2060
|
+
map.set(item, map.has(item) ? map.get(item) + 1 : 1);
|
|
2061
|
+
};
|
|
2062
|
+
itemsA.forEach(insertItem);
|
|
2063
|
+
itemsB.forEach(insertItem);
|
|
2064
|
+
const result = [];
|
|
2065
|
+
map.forEach((count, key)=>{
|
|
2066
|
+
if (count === 1) {
|
|
2067
|
+
result.push(key);
|
|
2068
|
+
}
|
|
2069
|
+
});
|
|
2070
|
+
return result;
|
|
2071
|
+
}
|
|
2072
|
+
/**
|
|
2073
|
+
* replacement for _.intersection
|
|
2074
|
+
* @param itemsA
|
|
2075
|
+
* @param itemsB
|
|
2076
|
+
*/ function intersection(itemsA, itemsB) {
|
|
2077
|
+
return itemsA.filter((t)=>itemsB.indexOf(t) > -1
|
|
2078
|
+
);
|
|
2079
|
+
}
|
|
2080
|
+
|
|
2081
|
+
const INIT_COORDS = 'dnd-core/INIT_COORDS';
|
|
2082
|
+
const BEGIN_DRAG = 'dnd-core/BEGIN_DRAG';
|
|
2083
|
+
const PUBLISH_DRAG_SOURCE = 'dnd-core/PUBLISH_DRAG_SOURCE';
|
|
2084
|
+
const HOVER = 'dnd-core/HOVER';
|
|
2085
|
+
const DROP = 'dnd-core/DROP';
|
|
2086
|
+
const END_DRAG = 'dnd-core/END_DRAG';
|
|
2087
|
+
|
|
2088
|
+
function setClientOffset(clientOffset, sourceClientOffset) {
|
|
2089
|
+
return {
|
|
2090
|
+
type: INIT_COORDS,
|
|
2091
|
+
payload: {
|
|
2092
|
+
sourceClientOffset: sourceClientOffset || null,
|
|
2093
|
+
clientOffset: clientOffset || null
|
|
2094
|
+
}
|
|
2095
|
+
};
|
|
2096
|
+
}
|
|
2097
|
+
|
|
2098
|
+
const ResetCoordinatesAction = {
|
|
2099
|
+
type: INIT_COORDS,
|
|
2100
|
+
payload: {
|
|
2101
|
+
clientOffset: null,
|
|
2102
|
+
sourceClientOffset: null
|
|
2103
|
+
}
|
|
2104
|
+
};
|
|
2105
|
+
function createBeginDrag(manager) {
|
|
2106
|
+
return function beginDrag(sourceIds = [], options = {
|
|
2107
|
+
publishSource: true
|
|
2108
|
+
}) {
|
|
2109
|
+
const { publishSource =true , clientOffset , getSourceClientOffset , } = options;
|
|
2110
|
+
const monitor = manager.getMonitor();
|
|
2111
|
+
const registry = manager.getRegistry();
|
|
2112
|
+
// Initialize the coordinates using the client offset
|
|
2113
|
+
manager.dispatch(setClientOffset(clientOffset));
|
|
2114
|
+
verifyInvariants$1(sourceIds, monitor, registry);
|
|
2115
|
+
// Get the draggable source
|
|
2116
|
+
const sourceId = getDraggableSource(sourceIds, monitor);
|
|
2117
|
+
if (sourceId == null) {
|
|
2118
|
+
manager.dispatch(ResetCoordinatesAction);
|
|
2119
|
+
return;
|
|
2120
|
+
}
|
|
2121
|
+
// Get the source client offset
|
|
2122
|
+
let sourceClientOffset = null;
|
|
2123
|
+
if (clientOffset) {
|
|
2124
|
+
if (!getSourceClientOffset) {
|
|
2125
|
+
throw new Error('getSourceClientOffset must be defined');
|
|
2126
|
+
}
|
|
2127
|
+
verifyGetSourceClientOffsetIsFunction(getSourceClientOffset);
|
|
2128
|
+
sourceClientOffset = getSourceClientOffset(sourceId);
|
|
2129
|
+
}
|
|
2130
|
+
// Initialize the full coordinates
|
|
2131
|
+
manager.dispatch(setClientOffset(clientOffset, sourceClientOffset));
|
|
2132
|
+
const source = registry.getSource(sourceId);
|
|
2133
|
+
const item = source.beginDrag(monitor, sourceId);
|
|
2134
|
+
// If source.beginDrag returns null, this is an indicator to cancel the drag
|
|
2135
|
+
if (item == null) {
|
|
2136
|
+
return undefined;
|
|
2137
|
+
}
|
|
2138
|
+
verifyItemIsObject(item);
|
|
2139
|
+
registry.pinSource(sourceId);
|
|
2140
|
+
const itemType = registry.getSourceType(sourceId);
|
|
2141
|
+
return {
|
|
2142
|
+
type: BEGIN_DRAG,
|
|
2143
|
+
payload: {
|
|
2144
|
+
itemType,
|
|
2145
|
+
item,
|
|
2146
|
+
sourceId,
|
|
2147
|
+
clientOffset: clientOffset || null,
|
|
2148
|
+
sourceClientOffset: sourceClientOffset || null,
|
|
2149
|
+
isSourcePublic: !!publishSource
|
|
2150
|
+
}
|
|
2151
|
+
};
|
|
2152
|
+
};
|
|
2153
|
+
}
|
|
2154
|
+
function verifyInvariants$1(sourceIds, monitor, registry) {
|
|
2155
|
+
invariant(!monitor.isDragging(), 'Cannot call beginDrag while dragging.');
|
|
2156
|
+
sourceIds.forEach(function(sourceId) {
|
|
2157
|
+
invariant(registry.getSource(sourceId), 'Expected sourceIds to be registered.');
|
|
2158
|
+
});
|
|
2159
|
+
}
|
|
2160
|
+
function verifyGetSourceClientOffsetIsFunction(getSourceClientOffset) {
|
|
2161
|
+
invariant(typeof getSourceClientOffset === 'function', 'When clientOffset is provided, getSourceClientOffset must be a function.');
|
|
2162
|
+
}
|
|
2163
|
+
function verifyItemIsObject(item) {
|
|
2164
|
+
invariant(isObject(item), 'Item must be an object.');
|
|
2165
|
+
}
|
|
2166
|
+
function getDraggableSource(sourceIds, monitor) {
|
|
2167
|
+
let sourceId = null;
|
|
2168
|
+
for(let i = sourceIds.length - 1; i >= 0; i--){
|
|
2169
|
+
if (monitor.canDragSource(sourceIds[i])) {
|
|
2170
|
+
sourceId = sourceIds[i];
|
|
2171
|
+
break;
|
|
2172
|
+
}
|
|
2173
|
+
}
|
|
2174
|
+
return sourceId;
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
function _defineProperty$3(obj, key, value) {
|
|
2178
|
+
if (key in obj) {
|
|
2179
|
+
Object.defineProperty(obj, key, {
|
|
2180
|
+
value: value,
|
|
2181
|
+
enumerable: true,
|
|
2182
|
+
configurable: true,
|
|
2183
|
+
writable: true
|
|
2184
|
+
});
|
|
2185
|
+
} else {
|
|
2186
|
+
obj[key] = value;
|
|
2187
|
+
}
|
|
2188
|
+
return obj;
|
|
2189
|
+
}
|
|
2190
|
+
function _objectSpread$3(target) {
|
|
2191
|
+
for(var i = 1; i < arguments.length; i++){
|
|
2192
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
2193
|
+
var ownKeys = Object.keys(source);
|
|
2194
|
+
if (typeof Object.getOwnPropertySymbols === 'function') {
|
|
2195
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
2196
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
2197
|
+
}));
|
|
2198
|
+
}
|
|
2199
|
+
ownKeys.forEach(function(key) {
|
|
2200
|
+
_defineProperty$3(target, key, source[key]);
|
|
2201
|
+
});
|
|
2202
|
+
}
|
|
2203
|
+
return target;
|
|
2204
|
+
}
|
|
2205
|
+
function createDrop(manager) {
|
|
2206
|
+
return function drop(options = {}) {
|
|
2207
|
+
const monitor = manager.getMonitor();
|
|
2208
|
+
const registry = manager.getRegistry();
|
|
2209
|
+
verifyInvariants(monitor);
|
|
2210
|
+
const targetIds = getDroppableTargets(monitor);
|
|
2211
|
+
// Multiple actions are dispatched here, which is why this doesn't return an action
|
|
2212
|
+
targetIds.forEach((targetId, index)=>{
|
|
2213
|
+
const dropResult = determineDropResult(targetId, index, registry, monitor);
|
|
2214
|
+
const action = {
|
|
2215
|
+
type: DROP,
|
|
2216
|
+
payload: {
|
|
2217
|
+
dropResult: _objectSpread$3({}, options, dropResult)
|
|
2218
|
+
}
|
|
2219
|
+
};
|
|
2220
|
+
manager.dispatch(action);
|
|
2221
|
+
});
|
|
2222
|
+
};
|
|
2223
|
+
}
|
|
2224
|
+
function verifyInvariants(monitor) {
|
|
2225
|
+
invariant(monitor.isDragging(), 'Cannot call drop while not dragging.');
|
|
2226
|
+
invariant(!monitor.didDrop(), 'Cannot call drop twice during one drag operation.');
|
|
2227
|
+
}
|
|
2228
|
+
function determineDropResult(targetId, index, registry, monitor) {
|
|
2229
|
+
const target = registry.getTarget(targetId);
|
|
2230
|
+
let dropResult = target ? target.drop(monitor, targetId) : undefined;
|
|
2231
|
+
verifyDropResultType(dropResult);
|
|
2232
|
+
if (typeof dropResult === 'undefined') {
|
|
2233
|
+
dropResult = index === 0 ? {} : monitor.getDropResult();
|
|
2234
|
+
}
|
|
2235
|
+
return dropResult;
|
|
2236
|
+
}
|
|
2237
|
+
function verifyDropResultType(dropResult) {
|
|
2238
|
+
invariant(typeof dropResult === 'undefined' || isObject(dropResult), 'Drop result must either be an object or undefined.');
|
|
2239
|
+
}
|
|
2240
|
+
function getDroppableTargets(monitor) {
|
|
2241
|
+
const targetIds = monitor.getTargetIds().filter(monitor.canDropOnTarget, monitor);
|
|
2242
|
+
targetIds.reverse();
|
|
2243
|
+
return targetIds;
|
|
2244
|
+
}
|
|
2245
|
+
|
|
2246
|
+
function createEndDrag(manager) {
|
|
2247
|
+
return function endDrag() {
|
|
2248
|
+
const monitor = manager.getMonitor();
|
|
2249
|
+
const registry = manager.getRegistry();
|
|
2250
|
+
verifyIsDragging(monitor);
|
|
2251
|
+
const sourceId = monitor.getSourceId();
|
|
2252
|
+
if (sourceId != null) {
|
|
2253
|
+
const source = registry.getSource(sourceId, true);
|
|
2254
|
+
source.endDrag(monitor, sourceId);
|
|
2255
|
+
registry.unpinSource();
|
|
2256
|
+
}
|
|
2257
|
+
return {
|
|
2258
|
+
type: END_DRAG
|
|
2259
|
+
};
|
|
2260
|
+
};
|
|
2261
|
+
}
|
|
2262
|
+
function verifyIsDragging(monitor) {
|
|
2263
|
+
invariant(monitor.isDragging(), 'Cannot call endDrag while not dragging.');
|
|
2264
|
+
}
|
|
2265
|
+
|
|
2266
|
+
function matchesType(targetType, draggedItemType) {
|
|
2267
|
+
if (draggedItemType === null) {
|
|
2268
|
+
return targetType === null;
|
|
2269
|
+
}
|
|
2270
|
+
return Array.isArray(targetType) ? targetType.some((t)=>t === draggedItemType
|
|
2271
|
+
) : targetType === draggedItemType;
|
|
2272
|
+
}
|
|
2273
|
+
|
|
2274
|
+
function createHover(manager) {
|
|
2275
|
+
return function hover(targetIdsArg, { clientOffset } = {}) {
|
|
2276
|
+
verifyTargetIdsIsArray(targetIdsArg);
|
|
2277
|
+
const targetIds = targetIdsArg.slice(0);
|
|
2278
|
+
const monitor = manager.getMonitor();
|
|
2279
|
+
const registry = manager.getRegistry();
|
|
2280
|
+
const draggedItemType = monitor.getItemType();
|
|
2281
|
+
removeNonMatchingTargetIds(targetIds, registry, draggedItemType);
|
|
2282
|
+
checkInvariants(targetIds, monitor, registry);
|
|
2283
|
+
hoverAllTargets(targetIds, monitor, registry);
|
|
2284
|
+
return {
|
|
2285
|
+
type: HOVER,
|
|
2286
|
+
payload: {
|
|
2287
|
+
targetIds,
|
|
2288
|
+
clientOffset: clientOffset || null
|
|
2289
|
+
}
|
|
2290
|
+
};
|
|
2291
|
+
};
|
|
2292
|
+
}
|
|
2293
|
+
function verifyTargetIdsIsArray(targetIdsArg) {
|
|
2294
|
+
invariant(Array.isArray(targetIdsArg), 'Expected targetIds to be an array.');
|
|
2295
|
+
}
|
|
2296
|
+
function checkInvariants(targetIds, monitor, registry) {
|
|
2297
|
+
invariant(monitor.isDragging(), 'Cannot call hover while not dragging.');
|
|
2298
|
+
invariant(!monitor.didDrop(), 'Cannot call hover after drop.');
|
|
2299
|
+
for(let i = 0; i < targetIds.length; i++){
|
|
2300
|
+
const targetId = targetIds[i];
|
|
2301
|
+
invariant(targetIds.lastIndexOf(targetId) === i, 'Expected targetIds to be unique in the passed array.');
|
|
2302
|
+
const target = registry.getTarget(targetId);
|
|
2303
|
+
invariant(target, 'Expected targetIds to be registered.');
|
|
2304
|
+
}
|
|
2305
|
+
}
|
|
2306
|
+
function removeNonMatchingTargetIds(targetIds, registry, draggedItemType) {
|
|
2307
|
+
// Remove those targetIds that don't match the targetType. This
|
|
2308
|
+
// fixes shallow isOver which would only be non-shallow because of
|
|
2309
|
+
// non-matching targets.
|
|
2310
|
+
for(let i = targetIds.length - 1; i >= 0; i--){
|
|
2311
|
+
const targetId = targetIds[i];
|
|
2312
|
+
const targetType = registry.getTargetType(targetId);
|
|
2313
|
+
if (!matchesType(targetType, draggedItemType)) {
|
|
2314
|
+
targetIds.splice(i, 1);
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
function hoverAllTargets(targetIds, monitor, registry) {
|
|
2319
|
+
// Finally call hover on all matching targets.
|
|
2320
|
+
targetIds.forEach(function(targetId) {
|
|
2321
|
+
const target = registry.getTarget(targetId);
|
|
2322
|
+
target.hover(monitor, targetId);
|
|
2323
|
+
});
|
|
2324
|
+
}
|
|
2325
|
+
|
|
2326
|
+
function createPublishDragSource(manager) {
|
|
2327
|
+
return function publishDragSource() {
|
|
2328
|
+
const monitor = manager.getMonitor();
|
|
2329
|
+
if (monitor.isDragging()) {
|
|
2330
|
+
return {
|
|
2331
|
+
type: PUBLISH_DRAG_SOURCE
|
|
2332
|
+
};
|
|
2333
|
+
}
|
|
2334
|
+
return;
|
|
2335
|
+
};
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
function createDragDropActions(manager) {
|
|
2339
|
+
return {
|
|
2340
|
+
beginDrag: createBeginDrag(manager),
|
|
2341
|
+
publishDragSource: createPublishDragSource(manager),
|
|
2342
|
+
hover: createHover(manager),
|
|
2343
|
+
drop: createDrop(manager),
|
|
2344
|
+
endDrag: createEndDrag(manager)
|
|
2345
|
+
};
|
|
2346
|
+
}
|
|
2347
|
+
|
|
2348
|
+
class DragDropManagerImpl {
|
|
2349
|
+
receiveBackend(backend) {
|
|
2350
|
+
this.backend = backend;
|
|
2351
|
+
}
|
|
2352
|
+
getMonitor() {
|
|
2353
|
+
return this.monitor;
|
|
2354
|
+
}
|
|
2355
|
+
getBackend() {
|
|
2356
|
+
return this.backend;
|
|
2357
|
+
}
|
|
2358
|
+
getRegistry() {
|
|
2359
|
+
return this.monitor.registry;
|
|
2360
|
+
}
|
|
2361
|
+
getActions() {
|
|
2362
|
+
/* eslint-disable-next-line @typescript-eslint/no-this-alias */ const manager = this;
|
|
2363
|
+
const { dispatch } = this.store;
|
|
2364
|
+
function bindActionCreator(actionCreator) {
|
|
2365
|
+
return (...args)=>{
|
|
2366
|
+
const action = actionCreator.apply(manager, args);
|
|
2367
|
+
if (typeof action !== 'undefined') {
|
|
2368
|
+
dispatch(action);
|
|
2369
|
+
}
|
|
2370
|
+
};
|
|
2371
|
+
}
|
|
2372
|
+
const actions = createDragDropActions(this);
|
|
2373
|
+
return Object.keys(actions).reduce((boundActions, key)=>{
|
|
2374
|
+
const action = actions[key];
|
|
2375
|
+
boundActions[key] = bindActionCreator(action);
|
|
2376
|
+
return boundActions;
|
|
2377
|
+
}, {});
|
|
2378
|
+
}
|
|
2379
|
+
dispatch(action) {
|
|
2380
|
+
this.store.dispatch(action);
|
|
2381
|
+
}
|
|
2382
|
+
constructor(store, monitor){
|
|
2383
|
+
this.isSetUp = false;
|
|
2384
|
+
this.handleRefCountChange = ()=>{
|
|
2385
|
+
const shouldSetUp = this.store.getState().refCount > 0;
|
|
2386
|
+
if (this.backend) {
|
|
2387
|
+
if (shouldSetUp && !this.isSetUp) {
|
|
2388
|
+
this.backend.setup();
|
|
2389
|
+
this.isSetUp = true;
|
|
2390
|
+
} else if (!shouldSetUp && this.isSetUp) {
|
|
2391
|
+
this.backend.teardown();
|
|
2392
|
+
this.isSetUp = false;
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
};
|
|
2396
|
+
this.store = store;
|
|
2397
|
+
this.monitor = monitor;
|
|
2398
|
+
store.subscribe(this.handleRefCountChange);
|
|
2399
|
+
}
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
/**
|
|
2403
|
+
* Coordinate addition
|
|
2404
|
+
* @param a The first coordinate
|
|
2405
|
+
* @param b The second coordinate
|
|
2406
|
+
*/ function add(a, b) {
|
|
2407
|
+
return {
|
|
2408
|
+
x: a.x + b.x,
|
|
2409
|
+
y: a.y + b.y
|
|
2410
|
+
};
|
|
2411
|
+
}
|
|
2412
|
+
/**
|
|
2413
|
+
* Coordinate subtraction
|
|
2414
|
+
* @param a The first coordinate
|
|
2415
|
+
* @param b The second coordinate
|
|
2416
|
+
*/ function subtract(a, b) {
|
|
2417
|
+
return {
|
|
2418
|
+
x: a.x - b.x,
|
|
2419
|
+
y: a.y - b.y
|
|
2420
|
+
};
|
|
2421
|
+
}
|
|
2422
|
+
/**
|
|
2423
|
+
* Returns the cartesian distance of the drag source component's position, based on its position
|
|
2424
|
+
* at the time when the current drag operation has started, and the movement difference.
|
|
2425
|
+
*
|
|
2426
|
+
* Returns null if no item is being dragged.
|
|
2427
|
+
*
|
|
2428
|
+
* @param state The offset state to compute from
|
|
2429
|
+
*/ function getSourceClientOffset(state) {
|
|
2430
|
+
const { clientOffset , initialClientOffset , initialSourceClientOffset } = state;
|
|
2431
|
+
if (!clientOffset || !initialClientOffset || !initialSourceClientOffset) {
|
|
2432
|
+
return null;
|
|
2433
|
+
}
|
|
2434
|
+
return subtract(add(clientOffset, initialSourceClientOffset), initialClientOffset);
|
|
2435
|
+
}
|
|
2436
|
+
/**
|
|
2437
|
+
* Determines the x,y offset between the client offset and the initial client offset
|
|
2438
|
+
*
|
|
2439
|
+
* @param state The offset state to compute from
|
|
2440
|
+
*/ function getDifferenceFromInitialOffset(state) {
|
|
2441
|
+
const { clientOffset , initialClientOffset } = state;
|
|
2442
|
+
if (!clientOffset || !initialClientOffset) {
|
|
2443
|
+
return null;
|
|
2444
|
+
}
|
|
2445
|
+
return subtract(clientOffset, initialClientOffset);
|
|
2446
|
+
}
|
|
2447
|
+
|
|
2448
|
+
const NONE = [];
|
|
2449
|
+
const ALL = [];
|
|
2450
|
+
NONE.__IS_NONE__ = true;
|
|
2451
|
+
ALL.__IS_ALL__ = true;
|
|
2452
|
+
/**
|
|
2453
|
+
* Determines if the given handler IDs are dirty or not.
|
|
2454
|
+
*
|
|
2455
|
+
* @param dirtyIds The set of dirty handler ids
|
|
2456
|
+
* @param handlerIds The set of handler ids to check
|
|
2457
|
+
*/ function areDirty(dirtyIds, handlerIds) {
|
|
2458
|
+
if (dirtyIds === NONE) {
|
|
2459
|
+
return false;
|
|
2460
|
+
}
|
|
2461
|
+
if (dirtyIds === ALL || typeof handlerIds === 'undefined') {
|
|
2462
|
+
return true;
|
|
2463
|
+
}
|
|
2464
|
+
const commonIds = intersection(handlerIds, dirtyIds);
|
|
2465
|
+
return commonIds.length > 0;
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
class DragDropMonitorImpl {
|
|
2469
|
+
subscribeToStateChange(listener, options = {}) {
|
|
2470
|
+
const { handlerIds } = options;
|
|
2471
|
+
invariant(typeof listener === 'function', 'listener must be a function.');
|
|
2472
|
+
invariant(typeof handlerIds === 'undefined' || Array.isArray(handlerIds), 'handlerIds, when specified, must be an array of strings.');
|
|
2473
|
+
let prevStateId = this.store.getState().stateId;
|
|
2474
|
+
const handleChange = ()=>{
|
|
2475
|
+
const state = this.store.getState();
|
|
2476
|
+
const currentStateId = state.stateId;
|
|
2477
|
+
try {
|
|
2478
|
+
const canSkipListener = currentStateId === prevStateId || currentStateId === prevStateId + 1 && !areDirty(state.dirtyHandlerIds, handlerIds);
|
|
2479
|
+
if (!canSkipListener) {
|
|
2480
|
+
listener();
|
|
2481
|
+
}
|
|
2482
|
+
} finally{
|
|
2483
|
+
prevStateId = currentStateId;
|
|
2484
|
+
}
|
|
2485
|
+
};
|
|
2486
|
+
return this.store.subscribe(handleChange);
|
|
2487
|
+
}
|
|
2488
|
+
subscribeToOffsetChange(listener) {
|
|
2489
|
+
invariant(typeof listener === 'function', 'listener must be a function.');
|
|
2490
|
+
let previousState = this.store.getState().dragOffset;
|
|
2491
|
+
const handleChange = ()=>{
|
|
2492
|
+
const nextState = this.store.getState().dragOffset;
|
|
2493
|
+
if (nextState === previousState) {
|
|
2494
|
+
return;
|
|
2495
|
+
}
|
|
2496
|
+
previousState = nextState;
|
|
2497
|
+
listener();
|
|
2498
|
+
};
|
|
2499
|
+
return this.store.subscribe(handleChange);
|
|
2500
|
+
}
|
|
2501
|
+
canDragSource(sourceId) {
|
|
2502
|
+
if (!sourceId) {
|
|
2503
|
+
return false;
|
|
2504
|
+
}
|
|
2505
|
+
const source = this.registry.getSource(sourceId);
|
|
2506
|
+
invariant(source, `Expected to find a valid source. sourceId=${sourceId}`);
|
|
2507
|
+
if (this.isDragging()) {
|
|
2508
|
+
return false;
|
|
2509
|
+
}
|
|
2510
|
+
return source.canDrag(this, sourceId);
|
|
2511
|
+
}
|
|
2512
|
+
canDropOnTarget(targetId) {
|
|
2513
|
+
// undefined on initial render
|
|
2514
|
+
if (!targetId) {
|
|
2515
|
+
return false;
|
|
2516
|
+
}
|
|
2517
|
+
const target = this.registry.getTarget(targetId);
|
|
2518
|
+
invariant(target, `Expected to find a valid target. targetId=${targetId}`);
|
|
2519
|
+
if (!this.isDragging() || this.didDrop()) {
|
|
2520
|
+
return false;
|
|
2521
|
+
}
|
|
2522
|
+
const targetType = this.registry.getTargetType(targetId);
|
|
2523
|
+
const draggedItemType = this.getItemType();
|
|
2524
|
+
return matchesType(targetType, draggedItemType) && target.canDrop(this, targetId);
|
|
2525
|
+
}
|
|
2526
|
+
isDragging() {
|
|
2527
|
+
return Boolean(this.getItemType());
|
|
2528
|
+
}
|
|
2529
|
+
isDraggingSource(sourceId) {
|
|
2530
|
+
// undefined on initial render
|
|
2531
|
+
if (!sourceId) {
|
|
2532
|
+
return false;
|
|
2533
|
+
}
|
|
2534
|
+
const source = this.registry.getSource(sourceId, true);
|
|
2535
|
+
invariant(source, `Expected to find a valid source. sourceId=${sourceId}`);
|
|
2536
|
+
if (!this.isDragging() || !this.isSourcePublic()) {
|
|
2537
|
+
return false;
|
|
2538
|
+
}
|
|
2539
|
+
const sourceType = this.registry.getSourceType(sourceId);
|
|
2540
|
+
const draggedItemType = this.getItemType();
|
|
2541
|
+
if (sourceType !== draggedItemType) {
|
|
2542
|
+
return false;
|
|
2543
|
+
}
|
|
2544
|
+
return source.isDragging(this, sourceId);
|
|
2545
|
+
}
|
|
2546
|
+
isOverTarget(targetId, options = {
|
|
2547
|
+
shallow: false
|
|
2548
|
+
}) {
|
|
2549
|
+
// undefined on initial render
|
|
2550
|
+
if (!targetId) {
|
|
2551
|
+
return false;
|
|
2552
|
+
}
|
|
2553
|
+
const { shallow } = options;
|
|
2554
|
+
if (!this.isDragging()) {
|
|
2555
|
+
return false;
|
|
2556
|
+
}
|
|
2557
|
+
const targetType = this.registry.getTargetType(targetId);
|
|
2558
|
+
const draggedItemType = this.getItemType();
|
|
2559
|
+
if (draggedItemType && !matchesType(targetType, draggedItemType)) {
|
|
2560
|
+
return false;
|
|
2561
|
+
}
|
|
2562
|
+
const targetIds = this.getTargetIds();
|
|
2563
|
+
if (!targetIds.length) {
|
|
2564
|
+
return false;
|
|
2565
|
+
}
|
|
2566
|
+
const index = targetIds.indexOf(targetId);
|
|
2567
|
+
if (shallow) {
|
|
2568
|
+
return index === targetIds.length - 1;
|
|
2569
|
+
} else {
|
|
2570
|
+
return index > -1;
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
getItemType() {
|
|
2574
|
+
return this.store.getState().dragOperation.itemType;
|
|
2575
|
+
}
|
|
2576
|
+
getItem() {
|
|
2577
|
+
return this.store.getState().dragOperation.item;
|
|
2578
|
+
}
|
|
2579
|
+
getSourceId() {
|
|
2580
|
+
return this.store.getState().dragOperation.sourceId;
|
|
2581
|
+
}
|
|
2582
|
+
getTargetIds() {
|
|
2583
|
+
return this.store.getState().dragOperation.targetIds;
|
|
2584
|
+
}
|
|
2585
|
+
getDropResult() {
|
|
2586
|
+
return this.store.getState().dragOperation.dropResult;
|
|
2587
|
+
}
|
|
2588
|
+
didDrop() {
|
|
2589
|
+
return this.store.getState().dragOperation.didDrop;
|
|
2590
|
+
}
|
|
2591
|
+
isSourcePublic() {
|
|
2592
|
+
return Boolean(this.store.getState().dragOperation.isSourcePublic);
|
|
2593
|
+
}
|
|
2594
|
+
getInitialClientOffset() {
|
|
2595
|
+
return this.store.getState().dragOffset.initialClientOffset;
|
|
2596
|
+
}
|
|
2597
|
+
getInitialSourceClientOffset() {
|
|
2598
|
+
return this.store.getState().dragOffset.initialSourceClientOffset;
|
|
2599
|
+
}
|
|
2600
|
+
getClientOffset() {
|
|
2601
|
+
return this.store.getState().dragOffset.clientOffset;
|
|
2602
|
+
}
|
|
2603
|
+
getSourceClientOffset() {
|
|
2604
|
+
return getSourceClientOffset(this.store.getState().dragOffset);
|
|
2605
|
+
}
|
|
2606
|
+
getDifferenceFromInitialOffset() {
|
|
2607
|
+
return getDifferenceFromInitialOffset(this.store.getState().dragOffset);
|
|
2608
|
+
}
|
|
2609
|
+
constructor(store, registry){
|
|
2610
|
+
this.store = store;
|
|
2611
|
+
this.registry = registry;
|
|
2612
|
+
}
|
|
2613
|
+
}
|
|
2614
|
+
|
|
2615
|
+
// Safari 6 and 6.1 for desktop, iPad, and iPhone are the only browsers that
|
|
2616
|
+
// have WebKitMutationObserver but not un-prefixed MutationObserver.
|
|
2617
|
+
// Must use `global` or `self` instead of `window` to work in both frames and web
|
|
2618
|
+
// workers. `global` is a provision of Browserify, Mr, Mrs, or Mop.
|
|
2619
|
+
/* globals self */ const scope = typeof global !== 'undefined' ? global : self;
|
|
2620
|
+
const BrowserMutationObserver = scope.MutationObserver || scope.WebKitMutationObserver;
|
|
2621
|
+
function makeRequestCallFromTimer(callback) {
|
|
2622
|
+
return function requestCall() {
|
|
2623
|
+
// We dispatch a timeout with a specified delay of 0 for engines that
|
|
2624
|
+
// can reliably accommodate that request. This will usually be snapped
|
|
2625
|
+
// to a 4 milisecond delay, but once we're flushing, there's no delay
|
|
2626
|
+
// between events.
|
|
2627
|
+
const timeoutHandle = setTimeout(handleTimer, 0);
|
|
2628
|
+
// However, since this timer gets frequently dropped in Firefox
|
|
2629
|
+
// workers, we enlist an interval handle that will try to fire
|
|
2630
|
+
// an event 20 times per second until it succeeds.
|
|
2631
|
+
const intervalHandle = setInterval(handleTimer, 50);
|
|
2632
|
+
function handleTimer() {
|
|
2633
|
+
// Whichever timer succeeds will cancel both timers and
|
|
2634
|
+
// execute the callback.
|
|
2635
|
+
clearTimeout(timeoutHandle);
|
|
2636
|
+
clearInterval(intervalHandle);
|
|
2637
|
+
callback();
|
|
2638
|
+
}
|
|
2639
|
+
};
|
|
2640
|
+
}
|
|
2641
|
+
// To request a high priority event, we induce a mutation observer by toggling
|
|
2642
|
+
// the text of a text node between "1" and "-1".
|
|
2643
|
+
function makeRequestCallFromMutationObserver(callback) {
|
|
2644
|
+
let toggle = 1;
|
|
2645
|
+
const observer = new BrowserMutationObserver(callback);
|
|
2646
|
+
const node = document.createTextNode('');
|
|
2647
|
+
observer.observe(node, {
|
|
2648
|
+
characterData: true
|
|
2649
|
+
});
|
|
2650
|
+
return function requestCall() {
|
|
2651
|
+
toggle = -toggle;
|
|
2652
|
+
node.data = toggle;
|
|
2653
|
+
};
|
|
2654
|
+
}
|
|
2655
|
+
const makeRequestCall = typeof BrowserMutationObserver === 'function' ? // reliably everywhere they are implemented.
|
|
2656
|
+
// They are implemented in all modern browsers.
|
|
2657
|
+
//
|
|
2658
|
+
// - Android 4-4.3
|
|
2659
|
+
// - Chrome 26-34
|
|
2660
|
+
// - Firefox 14-29
|
|
2661
|
+
// - Internet Explorer 11
|
|
2662
|
+
// - iPad Safari 6-7.1
|
|
2663
|
+
// - iPhone Safari 7-7.1
|
|
2664
|
+
// - Safari 6-7
|
|
2665
|
+
makeRequestCallFromMutationObserver : // task queue, are implemented in Internet Explorer 10, Safari 5.0-1, and Opera
|
|
2666
|
+
// 11-12, and in web workers in many engines.
|
|
2667
|
+
// Although message channels yield to any queued rendering and IO tasks, they
|
|
2668
|
+
// would be better than imposing the 4ms delay of timers.
|
|
2669
|
+
// However, they do not work reliably in Internet Explorer or Safari.
|
|
2670
|
+
// Internet Explorer 10 is the only browser that has setImmediate but does
|
|
2671
|
+
// not have MutationObservers.
|
|
2672
|
+
// Although setImmediate yields to the browser's renderer, it would be
|
|
2673
|
+
// preferrable to falling back to setTimeout since it does not have
|
|
2674
|
+
// the minimum 4ms penalty.
|
|
2675
|
+
// Unfortunately there appears to be a bug in Internet Explorer 10 Mobile (and
|
|
2676
|
+
// Desktop to a lesser extent) that renders both setImmediate and
|
|
2677
|
+
// MessageChannel useless for the purposes of ASAP.
|
|
2678
|
+
// https://github.com/kriskowal/q/issues/396
|
|
2679
|
+
// Timers are implemented universally.
|
|
2680
|
+
// We fall back to timers in workers in most engines, and in foreground
|
|
2681
|
+
// contexts in the following browsers.
|
|
2682
|
+
// However, note that even this simple case requires nuances to operate in a
|
|
2683
|
+
// broad spectrum of browsers.
|
|
2684
|
+
//
|
|
2685
|
+
// - Firefox 3-13
|
|
2686
|
+
// - Internet Explorer 6-9
|
|
2687
|
+
// - iPad Safari 4.3
|
|
2688
|
+
// - Lynx 2.8.7
|
|
2689
|
+
makeRequestCallFromTimer;
|
|
2690
|
+
|
|
2691
|
+
class AsapQueue {
|
|
2692
|
+
// Use the fastest means possible to execute a task in its own turn, with
|
|
2693
|
+
// priority over other events including IO, animation, reflow, and redraw
|
|
2694
|
+
// events in browsers.
|
|
2695
|
+
//
|
|
2696
|
+
// An exception thrown by a task will permanently interrupt the processing of
|
|
2697
|
+
// subsequent tasks. The higher level `asap` function ensures that if an
|
|
2698
|
+
// exception is thrown by a task, that the task queue will continue flushing as
|
|
2699
|
+
// soon as possible, but if you use `rawAsap` directly, you are responsible to
|
|
2700
|
+
// either ensure that no exceptions are thrown from your task, or to manually
|
|
2701
|
+
// call `rawAsap.requestFlush` if an exception is thrown.
|
|
2702
|
+
enqueueTask(task) {
|
|
2703
|
+
const { queue: q , requestFlush } = this;
|
|
2704
|
+
if (!q.length) {
|
|
2705
|
+
requestFlush();
|
|
2706
|
+
this.flushing = true;
|
|
2707
|
+
}
|
|
2708
|
+
// Equivalent to push, but avoids a function call.
|
|
2709
|
+
q[q.length] = task;
|
|
2710
|
+
}
|
|
2711
|
+
constructor(){
|
|
2712
|
+
this.queue = [];
|
|
2713
|
+
// We queue errors to ensure they are thrown in right order (FIFO).
|
|
2714
|
+
// Array-as-queue is good enough here, since we are just dealing with exceptions.
|
|
2715
|
+
this.pendingErrors = [];
|
|
2716
|
+
// Once a flush has been requested, no further calls to `requestFlush` are
|
|
2717
|
+
// necessary until the next `flush` completes.
|
|
2718
|
+
// @ts-ignore
|
|
2719
|
+
this.flushing = false;
|
|
2720
|
+
// The position of the next task to execute in the task queue. This is
|
|
2721
|
+
// preserved between calls to `flush` so that it can be resumed if
|
|
2722
|
+
// a task throws an exception.
|
|
2723
|
+
this.index = 0;
|
|
2724
|
+
// If a task schedules additional tasks recursively, the task queue can grow
|
|
2725
|
+
// unbounded. To prevent memory exhaustion, the task queue will periodically
|
|
2726
|
+
// truncate already-completed tasks.
|
|
2727
|
+
this.capacity = 1024;
|
|
2728
|
+
// The flush function processes all tasks that have been scheduled with
|
|
2729
|
+
// `rawAsap` unless and until one of those tasks throws an exception.
|
|
2730
|
+
// If a task throws an exception, `flush` ensures that its state will remain
|
|
2731
|
+
// consistent and will resume where it left off when called again.
|
|
2732
|
+
// However, `flush` does not make any arrangements to be called again if an
|
|
2733
|
+
// exception is thrown.
|
|
2734
|
+
this.flush = ()=>{
|
|
2735
|
+
const { queue: q } = this;
|
|
2736
|
+
while(this.index < q.length){
|
|
2737
|
+
const currentIndex = this.index;
|
|
2738
|
+
// Advance the index before calling the task. This ensures that we will
|
|
2739
|
+
// begin flushing on the next task the task throws an error.
|
|
2740
|
+
this.index++;
|
|
2741
|
+
q[currentIndex].call();
|
|
2742
|
+
// Prevent leaking memory for long chains of recursive calls to `asap`.
|
|
2743
|
+
// If we call `asap` within tasks scheduled by `asap`, the queue will
|
|
2744
|
+
// grow, but to avoid an O(n) walk for every task we execute, we don't
|
|
2745
|
+
// shift tasks off the queue after they have been executed.
|
|
2746
|
+
// Instead, we periodically shift 1024 tasks off the queue.
|
|
2747
|
+
if (this.index > this.capacity) {
|
|
2748
|
+
// Manually shift all values starting at the index back to the
|
|
2749
|
+
// beginning of the queue.
|
|
2750
|
+
for(let scan = 0, newLength = q.length - this.index; scan < newLength; scan++){
|
|
2751
|
+
q[scan] = q[scan + this.index];
|
|
2752
|
+
}
|
|
2753
|
+
q.length -= this.index;
|
|
2754
|
+
this.index = 0;
|
|
2755
|
+
}
|
|
2756
|
+
}
|
|
2757
|
+
q.length = 0;
|
|
2758
|
+
this.index = 0;
|
|
2759
|
+
this.flushing = false;
|
|
2760
|
+
};
|
|
2761
|
+
// In a web browser, exceptions are not fatal. However, to avoid
|
|
2762
|
+
// slowing down the queue of pending tasks, we rethrow the error in a
|
|
2763
|
+
// lower priority turn.
|
|
2764
|
+
this.registerPendingError = (err)=>{
|
|
2765
|
+
this.pendingErrors.push(err);
|
|
2766
|
+
this.requestErrorThrow();
|
|
2767
|
+
};
|
|
2768
|
+
// `requestFlush` requests that the high priority event queue be flushed as
|
|
2769
|
+
// soon as possible.
|
|
2770
|
+
// This is useful to prevent an error thrown in a task from stalling the event
|
|
2771
|
+
// queue if the exception handled by Node.js’s
|
|
2772
|
+
// `process.on("uncaughtException")` or by a domain.
|
|
2773
|
+
// `requestFlush` is implemented using a strategy based on data collected from
|
|
2774
|
+
// every available SauceLabs Selenium web driver worker at time of writing.
|
|
2775
|
+
// https://docs.google.com/spreadsheets/d/1mG-5UYGup5qxGdEMWkhP6BWCz053NUb2E1QoUTU16uA/edit#gid=783724593
|
|
2776
|
+
this.requestFlush = makeRequestCall(this.flush);
|
|
2777
|
+
this.requestErrorThrow = makeRequestCallFromTimer(()=>{
|
|
2778
|
+
// Throw first error
|
|
2779
|
+
if (this.pendingErrors.length) {
|
|
2780
|
+
throw this.pendingErrors.shift();
|
|
2781
|
+
}
|
|
2782
|
+
});
|
|
2783
|
+
}
|
|
2784
|
+
} // The message channel technique was discovered by Malte Ubl and was the
|
|
2785
|
+
// original foundation for this library.
|
|
2786
|
+
// http://www.nonblocking.io/2011/06/windownexttick.html
|
|
2787
|
+
// Safari 6.0.5 (at least) intermittently fails to create message ports on a
|
|
2788
|
+
// page's first load. Thankfully, this version of Safari supports
|
|
2789
|
+
// MutationObservers, so we don't need to fall back in that case.
|
|
2790
|
+
// function makeRequestCallFromMessageChannel(callback) {
|
|
2791
|
+
// var channel = new MessageChannel();
|
|
2792
|
+
// channel.port1.onmessage = callback;
|
|
2793
|
+
// return function requestCall() {
|
|
2794
|
+
// channel.port2.postMessage(0);
|
|
2795
|
+
// };
|
|
2796
|
+
// }
|
|
2797
|
+
// For reasons explained above, we are also unable to use `setImmediate`
|
|
2798
|
+
// under any circumstances.
|
|
2799
|
+
// Even if we were, there is another bug in Internet Explorer 10.
|
|
2800
|
+
// It is not sufficient to assign `setImmediate` to `requestFlush` because
|
|
2801
|
+
// `setImmediate` must be called *by name* and therefore must be wrapped in a
|
|
2802
|
+
// closure.
|
|
2803
|
+
// Never forget.
|
|
2804
|
+
// function makeRequestCallFromSetImmediate(callback) {
|
|
2805
|
+
// return function requestCall() {
|
|
2806
|
+
// setImmediate(callback);
|
|
2807
|
+
// };
|
|
2808
|
+
// }
|
|
2809
|
+
// Safari 6.0 has a problem where timers will get lost while the user is
|
|
2810
|
+
// scrolling. This problem does not impact ASAP because Safari 6.0 supports
|
|
2811
|
+
// mutation observers, so that implementation is used instead.
|
|
2812
|
+
// However, if we ever elect to use timers in Safari, the prevalent work-around
|
|
2813
|
+
// is to add a scroll event listener that calls for a flush.
|
|
2814
|
+
// `setTimeout` does not call the passed callback if the delay is less than
|
|
2815
|
+
// approximately 7 in web workers in Firefox 8 through 18, and sometimes not
|
|
2816
|
+
// even then.
|
|
2817
|
+
// This is for `asap.js` only.
|
|
2818
|
+
// Its name will be periodically randomized to break any code that depends on
|
|
2819
|
+
// // its existence.
|
|
2820
|
+
// rawAsap.makeRequestCallFromTimer = makeRequestCallFromTimer
|
|
2821
|
+
// ASAP was originally a nextTick shim included in Q. This was factored out
|
|
2822
|
+
// into this ASAP package. It was later adapted to RSVP which made further
|
|
2823
|
+
// amendments. These decisions, particularly to marginalize MessageChannel and
|
|
2824
|
+
// to capture the MutationObserver implementation in a closure, were integrated
|
|
2825
|
+
// back into ASAP proper.
|
|
2826
|
+
// https://github.com/tildeio/rsvp.js/blob/cddf7232546a9cf858524b75cde6f9edf72620a7/lib/rsvp/asap.js
|
|
2827
|
+
|
|
2828
|
+
// `call`, just like a function.
|
|
2829
|
+
class RawTask {
|
|
2830
|
+
call() {
|
|
2831
|
+
try {
|
|
2832
|
+
this.task && this.task();
|
|
2833
|
+
} catch (error) {
|
|
2834
|
+
this.onError(error);
|
|
2835
|
+
} finally{
|
|
2836
|
+
this.task = null;
|
|
2837
|
+
this.release(this);
|
|
2838
|
+
}
|
|
2839
|
+
}
|
|
2840
|
+
constructor(onError, release){
|
|
2841
|
+
this.onError = onError;
|
|
2842
|
+
this.release = release;
|
|
2843
|
+
this.task = null;
|
|
2844
|
+
}
|
|
2845
|
+
}
|
|
2846
|
+
|
|
2847
|
+
class TaskFactory {
|
|
2848
|
+
create(task) {
|
|
2849
|
+
const tasks = this.freeTasks;
|
|
2850
|
+
const t1 = tasks.length ? tasks.pop() : new RawTask(this.onError, (t)=>tasks[tasks.length] = t
|
|
2851
|
+
);
|
|
2852
|
+
t1.task = task;
|
|
2853
|
+
return t1;
|
|
2854
|
+
}
|
|
2855
|
+
constructor(onError){
|
|
2856
|
+
this.onError = onError;
|
|
2857
|
+
this.freeTasks = [];
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
|
|
2861
|
+
const asapQueue = new AsapQueue();
|
|
2862
|
+
const taskFactory = new TaskFactory(asapQueue.registerPendingError);
|
|
2863
|
+
/**
|
|
2864
|
+
* Calls a task as soon as possible after returning, in its own event, with priority
|
|
2865
|
+
* over other events like animation, reflow, and repaint. An error thrown from an
|
|
2866
|
+
* event will not interrupt, nor even substantially slow down the processing of
|
|
2867
|
+
* other events, but will be rather postponed to a lower priority event.
|
|
2868
|
+
* @param {{call}} task A callable object, typically a function that takes no
|
|
2869
|
+
* arguments.
|
|
2870
|
+
*/ function asap(task) {
|
|
2871
|
+
asapQueue.enqueueTask(taskFactory.create(task));
|
|
2872
|
+
}
|
|
2873
|
+
|
|
2874
|
+
const ADD_SOURCE = 'dnd-core/ADD_SOURCE';
|
|
2875
|
+
const ADD_TARGET = 'dnd-core/ADD_TARGET';
|
|
2876
|
+
const REMOVE_SOURCE = 'dnd-core/REMOVE_SOURCE';
|
|
2877
|
+
const REMOVE_TARGET = 'dnd-core/REMOVE_TARGET';
|
|
2878
|
+
function addSource(sourceId) {
|
|
2879
|
+
return {
|
|
2880
|
+
type: ADD_SOURCE,
|
|
2881
|
+
payload: {
|
|
2882
|
+
sourceId
|
|
2883
|
+
}
|
|
1530
2884
|
};
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
return newFn;
|
|
2885
|
+
}
|
|
2886
|
+
function addTarget(targetId) {
|
|
2887
|
+
return {
|
|
2888
|
+
type: ADD_TARGET,
|
|
2889
|
+
payload: {
|
|
2890
|
+
targetId
|
|
1538
2891
|
}
|
|
1539
|
-
|
|
1540
|
-
|
|
2892
|
+
};
|
|
2893
|
+
}
|
|
2894
|
+
function removeSource(sourceId) {
|
|
2895
|
+
return {
|
|
2896
|
+
type: REMOVE_SOURCE,
|
|
2897
|
+
payload: {
|
|
2898
|
+
sourceId
|
|
1541
2899
|
}
|
|
1542
|
-
|
|
1543
|
-
|
|
2900
|
+
};
|
|
2901
|
+
}
|
|
2902
|
+
function removeTarget(targetId) {
|
|
2903
|
+
return {
|
|
2904
|
+
type: REMOVE_TARGET,
|
|
2905
|
+
payload: {
|
|
2906
|
+
targetId
|
|
1544
2907
|
}
|
|
1545
|
-
return newFn;
|
|
1546
2908
|
};
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
2909
|
+
}
|
|
2910
|
+
|
|
2911
|
+
function validateSourceContract(source) {
|
|
2912
|
+
invariant(typeof source.canDrag === 'function', 'Expected canDrag to be a function.');
|
|
2913
|
+
invariant(typeof source.beginDrag === 'function', 'Expected beginDrag to be a function.');
|
|
2914
|
+
invariant(typeof source.endDrag === 'function', 'Expected endDrag to be a function.');
|
|
2915
|
+
}
|
|
2916
|
+
function validateTargetContract(target) {
|
|
2917
|
+
invariant(typeof target.canDrop === 'function', 'Expected canDrop to be a function.');
|
|
2918
|
+
invariant(typeof target.hover === 'function', 'Expected hover to be a function.');
|
|
2919
|
+
invariant(typeof target.drop === 'function', 'Expected beginDrag to be a function.');
|
|
2920
|
+
}
|
|
2921
|
+
function validateType(type, allowArray) {
|
|
2922
|
+
if (allowArray && Array.isArray(type)) {
|
|
2923
|
+
type.forEach((t)=>validateType(t, false)
|
|
2924
|
+
);
|
|
2925
|
+
return;
|
|
2926
|
+
}
|
|
2927
|
+
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.');
|
|
2928
|
+
}
|
|
2929
|
+
|
|
2930
|
+
var HandlerRole;
|
|
2931
|
+
(function(HandlerRole) {
|
|
2932
|
+
HandlerRole["SOURCE"] = "SOURCE";
|
|
2933
|
+
HandlerRole["TARGET"] = "TARGET";
|
|
2934
|
+
})(HandlerRole || (HandlerRole = {}));
|
|
2935
|
+
|
|
2936
|
+
let nextUniqueId = 0;
|
|
2937
|
+
function getNextUniqueId() {
|
|
2938
|
+
return nextUniqueId++;
|
|
2939
|
+
}
|
|
2940
|
+
|
|
2941
|
+
function getNextHandlerId(role) {
|
|
2942
|
+
const id = getNextUniqueId().toString();
|
|
2943
|
+
switch(role){
|
|
2944
|
+
case HandlerRole.SOURCE:
|
|
2945
|
+
return `S${id}`;
|
|
2946
|
+
case HandlerRole.TARGET:
|
|
2947
|
+
return `T${id}`;
|
|
2948
|
+
default:
|
|
2949
|
+
throw new Error(`Unknown Handler Role: ${role}`);
|
|
2950
|
+
}
|
|
2951
|
+
}
|
|
2952
|
+
function parseRoleFromHandlerId(handlerId) {
|
|
2953
|
+
switch(handlerId[0]){
|
|
2954
|
+
case 'S':
|
|
2955
|
+
return HandlerRole.SOURCE;
|
|
2956
|
+
case 'T':
|
|
2957
|
+
return HandlerRole.TARGET;
|
|
2958
|
+
default:
|
|
2959
|
+
throw new Error(`Cannot parse handler ID: ${handlerId}`);
|
|
2960
|
+
}
|
|
2961
|
+
}
|
|
2962
|
+
function mapContainsValue(map, searchValue) {
|
|
2963
|
+
const entries = map.entries();
|
|
2964
|
+
let isDone = false;
|
|
2965
|
+
do {
|
|
2966
|
+
const { done , value: [, value] , } = entries.next();
|
|
2967
|
+
if (value === searchValue) {
|
|
2968
|
+
return true;
|
|
1553
2969
|
}
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
2970
|
+
isDone = !!done;
|
|
2971
|
+
}while (!isDone)
|
|
2972
|
+
return false;
|
|
2973
|
+
}
|
|
2974
|
+
class HandlerRegistryImpl {
|
|
2975
|
+
addSource(type, source) {
|
|
2976
|
+
validateType(type);
|
|
2977
|
+
validateSourceContract(source);
|
|
2978
|
+
const sourceId = this.addHandler(HandlerRole.SOURCE, type, source);
|
|
2979
|
+
this.store.dispatch(addSource(sourceId));
|
|
2980
|
+
return sourceId;
|
|
2981
|
+
}
|
|
2982
|
+
addTarget(type, target) {
|
|
2983
|
+
validateType(type, true);
|
|
2984
|
+
validateTargetContract(target);
|
|
2985
|
+
const targetId = this.addHandler(HandlerRole.TARGET, type, target);
|
|
2986
|
+
this.store.dispatch(addTarget(targetId));
|
|
2987
|
+
return targetId;
|
|
2988
|
+
}
|
|
2989
|
+
containsHandler(handler) {
|
|
2990
|
+
return mapContainsValue(this.dragSources, handler) || mapContainsValue(this.dropTargets, handler);
|
|
2991
|
+
}
|
|
2992
|
+
getSource(sourceId, includePinned = false) {
|
|
2993
|
+
invariant(this.isSourceId(sourceId), 'Expected a valid source ID.');
|
|
2994
|
+
const isPinned = includePinned && sourceId === this.pinnedSourceId;
|
|
2995
|
+
const source = isPinned ? this.pinnedSource : this.dragSources.get(sourceId);
|
|
2996
|
+
return source;
|
|
2997
|
+
}
|
|
2998
|
+
getTarget(targetId) {
|
|
2999
|
+
invariant(this.isTargetId(targetId), 'Expected a valid target ID.');
|
|
3000
|
+
return this.dropTargets.get(targetId);
|
|
3001
|
+
}
|
|
3002
|
+
getSourceType(sourceId) {
|
|
3003
|
+
invariant(this.isSourceId(sourceId), 'Expected a valid source ID.');
|
|
3004
|
+
return this.types.get(sourceId);
|
|
3005
|
+
}
|
|
3006
|
+
getTargetType(targetId) {
|
|
3007
|
+
invariant(this.isTargetId(targetId), 'Expected a valid target ID.');
|
|
3008
|
+
return this.types.get(targetId);
|
|
3009
|
+
}
|
|
3010
|
+
isSourceId(handlerId) {
|
|
3011
|
+
const role = parseRoleFromHandlerId(handlerId);
|
|
3012
|
+
return role === HandlerRole.SOURCE;
|
|
3013
|
+
}
|
|
3014
|
+
isTargetId(handlerId) {
|
|
3015
|
+
const role = parseRoleFromHandlerId(handlerId);
|
|
3016
|
+
return role === HandlerRole.TARGET;
|
|
3017
|
+
}
|
|
3018
|
+
removeSource(sourceId) {
|
|
3019
|
+
invariant(this.getSource(sourceId), 'Expected an existing source.');
|
|
3020
|
+
this.store.dispatch(removeSource(sourceId));
|
|
3021
|
+
asap(()=>{
|
|
3022
|
+
this.dragSources.delete(sourceId);
|
|
3023
|
+
this.types.delete(sourceId);
|
|
1562
3024
|
});
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
3025
|
+
}
|
|
3026
|
+
removeTarget(targetId) {
|
|
3027
|
+
invariant(this.getTarget(targetId), 'Expected an existing target.');
|
|
3028
|
+
this.store.dispatch(removeTarget(targetId));
|
|
3029
|
+
this.dropTargets.delete(targetId);
|
|
3030
|
+
this.types.delete(targetId);
|
|
3031
|
+
}
|
|
3032
|
+
pinSource(sourceId) {
|
|
3033
|
+
const source = this.getSource(sourceId);
|
|
3034
|
+
invariant(source, 'Expected an existing source.');
|
|
3035
|
+
this.pinnedSourceId = sourceId;
|
|
3036
|
+
this.pinnedSource = source;
|
|
3037
|
+
}
|
|
3038
|
+
unpinSource() {
|
|
3039
|
+
invariant(this.pinnedSource, 'No source is pinned at the time.');
|
|
3040
|
+
this.pinnedSourceId = null;
|
|
3041
|
+
this.pinnedSource = null;
|
|
3042
|
+
}
|
|
3043
|
+
addHandler(role, type, handler) {
|
|
3044
|
+
const id = getNextHandlerId(role);
|
|
3045
|
+
this.types.set(id, type);
|
|
3046
|
+
if (role === HandlerRole.SOURCE) {
|
|
3047
|
+
this.dragSources.set(id, handler);
|
|
3048
|
+
} else if (role === HandlerRole.TARGET) {
|
|
3049
|
+
this.dropTargets.set(id, handler);
|
|
3050
|
+
}
|
|
3051
|
+
return id;
|
|
3052
|
+
}
|
|
3053
|
+
constructor(store){
|
|
3054
|
+
this.types = new Map();
|
|
3055
|
+
this.dragSources = new Map();
|
|
3056
|
+
this.dropTargets = new Map();
|
|
3057
|
+
this.pinnedSourceId = null;
|
|
3058
|
+
this.pinnedSource = null;
|
|
3059
|
+
this.store = store;
|
|
3060
|
+
}
|
|
3061
|
+
}
|
|
3062
|
+
|
|
3063
|
+
const strictEquality = (a, b)=>a === b
|
|
3064
|
+
;
|
|
3065
|
+
/**
|
|
3066
|
+
* Determine if two cartesian coordinate offsets are equal
|
|
3067
|
+
* @param offsetA
|
|
3068
|
+
* @param offsetB
|
|
3069
|
+
*/ function areCoordsEqual(offsetA, offsetB) {
|
|
3070
|
+
if (!offsetA && !offsetB) {
|
|
3071
|
+
return true;
|
|
3072
|
+
} else if (!offsetA || !offsetB) {
|
|
3073
|
+
return false;
|
|
3074
|
+
} else {
|
|
3075
|
+
return offsetA.x === offsetB.x && offsetA.y === offsetB.y;
|
|
3076
|
+
}
|
|
3077
|
+
}
|
|
3078
|
+
/**
|
|
3079
|
+
* Determines if two arrays of items are equal
|
|
3080
|
+
* @param a The first array of items
|
|
3081
|
+
* @param b The second array of items
|
|
3082
|
+
*/ function areArraysEqual(a, b, isEqual = strictEquality) {
|
|
3083
|
+
if (a.length !== b.length) {
|
|
3084
|
+
return false;
|
|
3085
|
+
}
|
|
3086
|
+
for(let i = 0; i < a.length; ++i){
|
|
3087
|
+
if (!isEqual(a[i], b[i])) {
|
|
3088
|
+
return false;
|
|
3089
|
+
}
|
|
3090
|
+
}
|
|
3091
|
+
return true;
|
|
3092
|
+
}
|
|
3093
|
+
|
|
3094
|
+
function reduce$5(// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
3095
|
+
_state = NONE, action) {
|
|
3096
|
+
switch(action.type){
|
|
3097
|
+
case HOVER:
|
|
3098
|
+
break;
|
|
3099
|
+
case ADD_SOURCE:
|
|
3100
|
+
case ADD_TARGET:
|
|
3101
|
+
case REMOVE_TARGET:
|
|
3102
|
+
case REMOVE_SOURCE:
|
|
3103
|
+
return NONE;
|
|
3104
|
+
case BEGIN_DRAG:
|
|
3105
|
+
case PUBLISH_DRAG_SOURCE:
|
|
3106
|
+
case END_DRAG:
|
|
3107
|
+
case DROP:
|
|
3108
|
+
default:
|
|
3109
|
+
return ALL;
|
|
3110
|
+
}
|
|
3111
|
+
const { targetIds =[] , prevTargetIds =[] } = action.payload;
|
|
3112
|
+
const result = xor(targetIds, prevTargetIds);
|
|
3113
|
+
const didChange = result.length > 0 || !areArraysEqual(targetIds, prevTargetIds);
|
|
3114
|
+
if (!didChange) {
|
|
3115
|
+
return NONE;
|
|
3116
|
+
}
|
|
3117
|
+
// Check the target ids at the innermost position. If they are valid, add them
|
|
3118
|
+
// to the result
|
|
3119
|
+
const prevInnermostTargetId = prevTargetIds[prevTargetIds.length - 1];
|
|
3120
|
+
const innermostTargetId = targetIds[targetIds.length - 1];
|
|
3121
|
+
if (prevInnermostTargetId !== innermostTargetId) {
|
|
3122
|
+
if (prevInnermostTargetId) {
|
|
3123
|
+
result.push(prevInnermostTargetId);
|
|
3124
|
+
}
|
|
3125
|
+
if (innermostTargetId) {
|
|
3126
|
+
result.push(innermostTargetId);
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3129
|
+
return result;
|
|
3130
|
+
}
|
|
3131
|
+
|
|
3132
|
+
function _defineProperty$2(obj, key, value) {
|
|
3133
|
+
if (key in obj) {
|
|
3134
|
+
Object.defineProperty(obj, key, {
|
|
3135
|
+
value: value,
|
|
3136
|
+
enumerable: true,
|
|
3137
|
+
configurable: true,
|
|
3138
|
+
writable: true
|
|
3139
|
+
});
|
|
3140
|
+
} else {
|
|
3141
|
+
obj[key] = value;
|
|
3142
|
+
}
|
|
3143
|
+
return obj;
|
|
3144
|
+
}
|
|
3145
|
+
function _objectSpread$2(target) {
|
|
3146
|
+
for(var i = 1; i < arguments.length; i++){
|
|
3147
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
3148
|
+
var ownKeys = Object.keys(source);
|
|
3149
|
+
if (typeof Object.getOwnPropertySymbols === 'function') {
|
|
3150
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
3151
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
3152
|
+
}));
|
|
3153
|
+
}
|
|
3154
|
+
ownKeys.forEach(function(key) {
|
|
3155
|
+
_defineProperty$2(target, key, source[key]);
|
|
3156
|
+
});
|
|
3157
|
+
}
|
|
3158
|
+
return target;
|
|
3159
|
+
}
|
|
3160
|
+
const initialState$1 = {
|
|
3161
|
+
initialSourceClientOffset: null,
|
|
3162
|
+
initialClientOffset: null,
|
|
3163
|
+
clientOffset: null
|
|
3164
|
+
};
|
|
3165
|
+
function reduce$4(state = initialState$1, action) {
|
|
3166
|
+
const { payload } = action;
|
|
3167
|
+
switch(action.type){
|
|
3168
|
+
case INIT_COORDS:
|
|
3169
|
+
case BEGIN_DRAG:
|
|
3170
|
+
return {
|
|
3171
|
+
initialSourceClientOffset: payload.sourceClientOffset,
|
|
3172
|
+
initialClientOffset: payload.clientOffset,
|
|
3173
|
+
clientOffset: payload.clientOffset
|
|
3174
|
+
};
|
|
3175
|
+
case HOVER:
|
|
3176
|
+
if (areCoordsEqual(state.clientOffset, payload.clientOffset)) {
|
|
3177
|
+
return state;
|
|
1570
3178
|
}
|
|
3179
|
+
return _objectSpread$2({}, state, {
|
|
3180
|
+
clientOffset: payload.clientOffset
|
|
3181
|
+
});
|
|
3182
|
+
case END_DRAG:
|
|
3183
|
+
case DROP:
|
|
3184
|
+
return initialState$1;
|
|
3185
|
+
default:
|
|
3186
|
+
return state;
|
|
3187
|
+
}
|
|
3188
|
+
}
|
|
3189
|
+
|
|
3190
|
+
function _defineProperty$1(obj, key, value) {
|
|
3191
|
+
if (key in obj) {
|
|
3192
|
+
Object.defineProperty(obj, key, {
|
|
3193
|
+
value: value,
|
|
3194
|
+
enumerable: true,
|
|
3195
|
+
configurable: true,
|
|
3196
|
+
writable: true
|
|
1571
3197
|
});
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1577
|
-
|
|
1578
|
-
|
|
1579
|
-
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
if (!from || !to) {
|
|
1586
|
-
console.warn("Invalid nodes for connection");
|
|
1587
|
-
return newFn;
|
|
3198
|
+
} else {
|
|
3199
|
+
obj[key] = value;
|
|
3200
|
+
}
|
|
3201
|
+
return obj;
|
|
3202
|
+
}
|
|
3203
|
+
function _objectSpread$1(target) {
|
|
3204
|
+
for(var i = 1; i < arguments.length; i++){
|
|
3205
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
3206
|
+
var ownKeys = Object.keys(source);
|
|
3207
|
+
if (typeof Object.getOwnPropertySymbols === 'function') {
|
|
3208
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
3209
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
3210
|
+
}));
|
|
1588
3211
|
}
|
|
1589
|
-
|
|
1590
|
-
|
|
3212
|
+
ownKeys.forEach(function(key) {
|
|
3213
|
+
_defineProperty$1(target, key, source[key]);
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
return target;
|
|
3217
|
+
}
|
|
3218
|
+
const initialState = {
|
|
3219
|
+
itemType: null,
|
|
3220
|
+
item: null,
|
|
3221
|
+
sourceId: null,
|
|
3222
|
+
targetIds: [],
|
|
3223
|
+
dropResult: null,
|
|
3224
|
+
didDrop: false,
|
|
3225
|
+
isSourcePublic: null
|
|
3226
|
+
};
|
|
3227
|
+
function reduce$3(state = initialState, action) {
|
|
3228
|
+
const { payload } = action;
|
|
3229
|
+
switch(action.type){
|
|
3230
|
+
case BEGIN_DRAG:
|
|
3231
|
+
return _objectSpread$1({}, state, {
|
|
3232
|
+
itemType: payload.itemType,
|
|
3233
|
+
item: payload.item,
|
|
3234
|
+
sourceId: payload.sourceId,
|
|
3235
|
+
isSourcePublic: payload.isSourcePublic,
|
|
3236
|
+
dropResult: null,
|
|
3237
|
+
didDrop: false
|
|
3238
|
+
});
|
|
3239
|
+
case PUBLISH_DRAG_SOURCE:
|
|
3240
|
+
return _objectSpread$1({}, state, {
|
|
3241
|
+
isSourcePublic: true
|
|
3242
|
+
});
|
|
3243
|
+
case HOVER:
|
|
3244
|
+
return _objectSpread$1({}, state, {
|
|
3245
|
+
targetIds: payload.targetIds
|
|
3246
|
+
});
|
|
3247
|
+
case REMOVE_TARGET:
|
|
3248
|
+
if (state.targetIds.indexOf(payload.targetId) === -1) {
|
|
3249
|
+
return state;
|
|
3250
|
+
}
|
|
3251
|
+
return _objectSpread$1({}, state, {
|
|
3252
|
+
targetIds: without(state.targetIds, payload.targetId)
|
|
3253
|
+
});
|
|
3254
|
+
case DROP:
|
|
3255
|
+
return _objectSpread$1({}, state, {
|
|
3256
|
+
dropResult: payload.dropResult,
|
|
3257
|
+
didDrop: true,
|
|
3258
|
+
targetIds: []
|
|
3259
|
+
});
|
|
3260
|
+
case END_DRAG:
|
|
3261
|
+
return _objectSpread$1({}, state, {
|
|
3262
|
+
itemType: null,
|
|
3263
|
+
item: null,
|
|
3264
|
+
sourceId: null,
|
|
3265
|
+
dropResult: null,
|
|
3266
|
+
didDrop: false,
|
|
3267
|
+
isSourcePublic: null,
|
|
3268
|
+
targetIds: []
|
|
3269
|
+
});
|
|
3270
|
+
default:
|
|
3271
|
+
return state;
|
|
3272
|
+
}
|
|
3273
|
+
}
|
|
3274
|
+
|
|
3275
|
+
function reduce$2(state = 0, action) {
|
|
3276
|
+
switch(action.type){
|
|
3277
|
+
case ADD_SOURCE:
|
|
3278
|
+
case ADD_TARGET:
|
|
3279
|
+
return state + 1;
|
|
3280
|
+
case REMOVE_SOURCE:
|
|
3281
|
+
case REMOVE_TARGET:
|
|
3282
|
+
return state - 1;
|
|
3283
|
+
default:
|
|
3284
|
+
return state;
|
|
3285
|
+
}
|
|
3286
|
+
}
|
|
3287
|
+
|
|
3288
|
+
function reduce$1(state = 0) {
|
|
3289
|
+
return state + 1;
|
|
3290
|
+
}
|
|
3291
|
+
|
|
3292
|
+
function _defineProperty(obj, key, value) {
|
|
3293
|
+
if (key in obj) {
|
|
3294
|
+
Object.defineProperty(obj, key, {
|
|
3295
|
+
value: value,
|
|
3296
|
+
enumerable: true,
|
|
3297
|
+
configurable: true,
|
|
3298
|
+
writable: true
|
|
3299
|
+
});
|
|
3300
|
+
} else {
|
|
3301
|
+
obj[key] = value;
|
|
3302
|
+
}
|
|
3303
|
+
return obj;
|
|
3304
|
+
}
|
|
3305
|
+
function _objectSpread(target) {
|
|
3306
|
+
for(var i = 1; i < arguments.length; i++){
|
|
3307
|
+
var source = arguments[i] != null ? arguments[i] : {};
|
|
3308
|
+
var ownKeys = Object.keys(source);
|
|
3309
|
+
if (typeof Object.getOwnPropertySymbols === 'function') {
|
|
3310
|
+
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
|
|
3311
|
+
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
3312
|
+
}));
|
|
1591
3313
|
}
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
3314
|
+
ownKeys.forEach(function(key) {
|
|
3315
|
+
_defineProperty(target, key, source[key]);
|
|
3316
|
+
});
|
|
3317
|
+
}
|
|
3318
|
+
return target;
|
|
3319
|
+
}
|
|
3320
|
+
function reduce(state = {}, action) {
|
|
3321
|
+
return {
|
|
3322
|
+
dirtyHandlerIds: reduce$5(state.dirtyHandlerIds, {
|
|
3323
|
+
type: action.type,
|
|
3324
|
+
payload: _objectSpread({}, action.payload, {
|
|
3325
|
+
prevTargetIds: get(state, 'dragOperation.targetIds', [])
|
|
3326
|
+
})
|
|
3327
|
+
}),
|
|
3328
|
+
dragOffset: reduce$4(state.dragOffset, action),
|
|
3329
|
+
refCount: reduce$2(state.refCount, action),
|
|
3330
|
+
dragOperation: reduce$3(state.dragOperation, action),
|
|
3331
|
+
stateId: reduce$1(state.stateId)
|
|
1596
3332
|
};
|
|
1597
|
-
|
|
1598
|
-
}());
|
|
3333
|
+
}
|
|
1599
3334
|
|
|
1600
|
-
|
|
1601
|
-
|
|
1602
|
-
|
|
1603
|
-
|
|
1604
|
-
|
|
3335
|
+
function createDragDropManager(backendFactory, globalContext = undefined, backendOptions = {}, debugMode = false) {
|
|
3336
|
+
const store = makeStoreInstance(debugMode);
|
|
3337
|
+
const monitor = new DragDropMonitorImpl(store, new HandlerRegistryImpl(store));
|
|
3338
|
+
const manager = new DragDropManagerImpl(store, monitor);
|
|
3339
|
+
const backend = backendFactory(manager, globalContext, backendOptions);
|
|
3340
|
+
manager.receiveBackend(backend);
|
|
3341
|
+
return manager;
|
|
3342
|
+
}
|
|
3343
|
+
function makeStoreInstance(debugMode) {
|
|
3344
|
+
// TODO: if we ever make a react-native version of this,
|
|
3345
|
+
// we'll need to consider how to pull off dev-tooling
|
|
3346
|
+
const reduxDevTools = typeof window !== 'undefined' && window.__REDUX_DEVTOOLS_EXTENSION__;
|
|
3347
|
+
return createStore(reduce, debugMode && reduxDevTools && reduxDevTools({
|
|
3348
|
+
name: 'dnd-core',
|
|
3349
|
+
instanceId: 'dnd-core'
|
|
3350
|
+
}));
|
|
3351
|
+
}
|
|
1605
3352
|
|
|
1606
|
-
|
|
1607
|
-
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
if (format === undefined) {
|
|
1618
|
-
throw new Error('invariant requires an error message argument');
|
|
3353
|
+
function _objectWithoutProperties(source, excluded) {
|
|
3354
|
+
if (source == null) return {};
|
|
3355
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
3356
|
+
var key, i;
|
|
3357
|
+
if (Object.getOwnPropertySymbols) {
|
|
3358
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
3359
|
+
for(i = 0; i < sourceSymbolKeys.length; i++){
|
|
3360
|
+
key = sourceSymbolKeys[i];
|
|
3361
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
3362
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
3363
|
+
target[key] = source[key];
|
|
1619
3364
|
}
|
|
1620
3365
|
}
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
3366
|
+
return target;
|
|
3367
|
+
}
|
|
3368
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
3369
|
+
if (source == null) return {};
|
|
3370
|
+
var target = {};
|
|
3371
|
+
var sourceKeys = Object.keys(source);
|
|
3372
|
+
var key, i;
|
|
3373
|
+
for(i = 0; i < sourceKeys.length; i++){
|
|
3374
|
+
key = sourceKeys[i];
|
|
3375
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
3376
|
+
target[key] = source[key];
|
|
3377
|
+
}
|
|
3378
|
+
return target;
|
|
3379
|
+
}
|
|
3380
|
+
let refCount = 0;
|
|
3381
|
+
const INSTANCE_SYM = Symbol.for('__REACT_DND_CONTEXT_INSTANCE__');
|
|
3382
|
+
var DndProvider = /*#__PURE__*/ React.memo(function DndProvider(_param) {
|
|
3383
|
+
var { children } = _param, props = _objectWithoutProperties(_param, [
|
|
3384
|
+
"children"
|
|
3385
|
+
]);
|
|
3386
|
+
const [manager, isGlobalInstance] = getDndContextValue(props) // memoized from props
|
|
3387
|
+
;
|
|
3388
|
+
/**
|
|
3389
|
+
* If the global context was used to store the DND context
|
|
3390
|
+
* then where theres no more references to it we should
|
|
3391
|
+
* clean it up to avoid memory leaks
|
|
3392
|
+
*/ React.useEffect(()=>{
|
|
3393
|
+
if (isGlobalInstance) {
|
|
3394
|
+
const context = getGlobalContext();
|
|
3395
|
+
++refCount;
|
|
3396
|
+
return ()=>{
|
|
3397
|
+
if (--refCount === 0) {
|
|
3398
|
+
context[INSTANCE_SYM] = null;
|
|
3399
|
+
}
|
|
3400
|
+
};
|
|
1631
3401
|
}
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
3402
|
+
return;
|
|
3403
|
+
}, []);
|
|
3404
|
+
return /*#__PURE__*/ jsxRuntime.jsx(DndContext.Provider, {
|
|
3405
|
+
value: manager,
|
|
3406
|
+
children: children
|
|
3407
|
+
});
|
|
3408
|
+
});
|
|
3409
|
+
function getDndContextValue(props) {
|
|
3410
|
+
if ('manager' in props) {
|
|
3411
|
+
const manager = {
|
|
3412
|
+
dragDropManager: props.manager
|
|
3413
|
+
};
|
|
3414
|
+
return [
|
|
3415
|
+
manager,
|
|
3416
|
+
false
|
|
3417
|
+
];
|
|
3418
|
+
}
|
|
3419
|
+
const manager = createSingletonDndContext(props.backend, props.context, props.options, props.debugMode);
|
|
3420
|
+
const isGlobalInstance = !props.context;
|
|
3421
|
+
return [
|
|
3422
|
+
manager,
|
|
3423
|
+
isGlobalInstance
|
|
3424
|
+
];
|
|
3425
|
+
}
|
|
3426
|
+
function createSingletonDndContext(backend, context = getGlobalContext(), options, debugMode) {
|
|
3427
|
+
const ctx = context;
|
|
3428
|
+
if (!ctx[INSTANCE_SYM]) {
|
|
3429
|
+
ctx[INSTANCE_SYM] = {
|
|
3430
|
+
dragDropManager: createDragDropManager(backend, context, options, debugMode)
|
|
3431
|
+
};
|
|
1635
3432
|
}
|
|
3433
|
+
return ctx[INSTANCE_SYM];
|
|
1636
3434
|
}
|
|
1637
|
-
function
|
|
1638
|
-
return typeof
|
|
3435
|
+
function getGlobalContext() {
|
|
3436
|
+
return typeof global !== 'undefined' ? global : window;
|
|
1639
3437
|
}
|
|
1640
3438
|
|
|
1641
3439
|
function getDefaultExportFromCjs (x) {
|
|
@@ -3295,6 +5093,12 @@ function useFunction(engine, fn, mount) {
|
|
|
3295
5093
|
}); }, [builtFn, run, result]);
|
|
3296
5094
|
}
|
|
3297
5095
|
|
|
5096
|
+
function DDContext(_a) {
|
|
5097
|
+
var children = _a.children;
|
|
5098
|
+
return React.createElement(DndProvider, { backend: reactDndHtml5Backend.HTML5Backend }, children);
|
|
5099
|
+
}
|
|
5100
|
+
|
|
5101
|
+
exports.DDContext = DDContext;
|
|
3298
5102
|
exports.DISCARD = DISCARD;
|
|
3299
5103
|
exports.Engine = Engine;
|
|
3300
5104
|
exports.Flow = Flow;
|