@rkmodules/rules 0.0.54 → 0.0.55

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