@rkmodules/rules 0.0.51 → 0.0.52

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,7 +1,6 @@
1
1
  import { create, all } from 'mathjs';
2
- import React from 'react';
2
+ import React, { createContext, useLayoutEffect, useEffect, useState, useCallback, useMemo, isValidElement, cloneElement, useContext } from 'react';
3
3
  import { Handle, Position, useConnection, getSimpleBezierPath, ReactFlowProvider, useOnSelectionChange, applyNodeChanges, applyEdgeChanges, ReactFlow, Background, BackgroundVariant, Controls } from '@xyflow/react';
4
- import { useDrop, useDrag } from 'react-dnd';
5
4
  import katex from 'katex';
6
5
  import classNames from 'classnames';
7
6
  import rcin from 'rc-input-number';
@@ -1594,6 +1593,985 @@ var Engine = /** @class */ (function () {
1594
1593
  return Engine;
1595
1594
  }());
1596
1595
 
1596
+ /**
1597
+ * Create the React Context
1598
+ */ const DndContext = createContext({
1599
+ dragDropManager: undefined
1600
+ });
1601
+
1602
+ /**
1603
+ * Use invariant() to assert state which your program assumes to be true.
1604
+ *
1605
+ * Provide sprintf-style format (only %s is supported) and arguments
1606
+ * to provide information about what broke and what you were
1607
+ * expecting.
1608
+ *
1609
+ * The invariant message will be stripped in production, but the invariant
1610
+ * will remain to ensure logic does not differ in production.
1611
+ */ function invariant(condition, format, ...args) {
1612
+ if (isProduction()) {
1613
+ if (format === undefined) {
1614
+ throw new Error('invariant requires an error message argument');
1615
+ }
1616
+ }
1617
+ if (!condition) {
1618
+ let error;
1619
+ if (format === undefined) {
1620
+ error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
1621
+ } else {
1622
+ let argIndex = 0;
1623
+ error = new Error(format.replace(/%s/g, function() {
1624
+ return args[argIndex++];
1625
+ }));
1626
+ error.name = 'Invariant Violation';
1627
+ }
1628
+ error.framesToPop = 1 // we don't care about invariant's own frame
1629
+ ;
1630
+ throw error;
1631
+ }
1632
+ }
1633
+ function isProduction() {
1634
+ return typeof process !== 'undefined' && process.env['NODE_ENV'] === 'production';
1635
+ }
1636
+
1637
+ function getDefaultExportFromCjs (x) {
1638
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
1639
+ }
1640
+
1641
+ var fastDeepEqual;
1642
+ var hasRequiredFastDeepEqual;
1643
+
1644
+ function requireFastDeepEqual () {
1645
+ if (hasRequiredFastDeepEqual) return fastDeepEqual;
1646
+ hasRequiredFastDeepEqual = 1;
1647
+
1648
+ // do not edit .js files directly - edit src/index.jst
1649
+
1650
+
1651
+
1652
+ fastDeepEqual = function equal(a, b) {
1653
+ if (a === b) return true;
1654
+
1655
+ if (a && b && typeof a == 'object' && typeof b == 'object') {
1656
+ if (a.constructor !== b.constructor) return false;
1657
+
1658
+ var length, i, keys;
1659
+ if (Array.isArray(a)) {
1660
+ length = a.length;
1661
+ if (length != b.length) return false;
1662
+ for (i = length; i-- !== 0;)
1663
+ if (!equal(a[i], b[i])) return false;
1664
+ return true;
1665
+ }
1666
+
1667
+
1668
+
1669
+ if (a.constructor === RegExp) return a.source === b.source && a.flags === b.flags;
1670
+ if (a.valueOf !== Object.prototype.valueOf) return a.valueOf() === b.valueOf();
1671
+ if (a.toString !== Object.prototype.toString) return a.toString() === b.toString();
1672
+
1673
+ keys = Object.keys(a);
1674
+ length = keys.length;
1675
+ if (length !== Object.keys(b).length) return false;
1676
+
1677
+ for (i = length; i-- !== 0;)
1678
+ if (!Object.prototype.hasOwnProperty.call(b, keys[i])) return false;
1679
+
1680
+ for (i = length; i-- !== 0;) {
1681
+ var key = keys[i];
1682
+
1683
+ if (!equal(a[key], b[key])) return false;
1684
+ }
1685
+
1686
+ return true;
1687
+ }
1688
+
1689
+ // true if both NaN, false otherwise
1690
+ return a!==a && b!==b;
1691
+ };
1692
+ return fastDeepEqual;
1693
+ }
1694
+
1695
+ var fastDeepEqualExports = requireFastDeepEqual();
1696
+ var equal = /*@__PURE__*/getDefaultExportFromCjs(fastDeepEqualExports);
1697
+
1698
+ // suppress the useLayoutEffect warning on server side.
1699
+ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
1700
+
1701
+ /**
1702
+ *
1703
+ * @param monitor The monitor to collect state from
1704
+ * @param collect The collecting function
1705
+ * @param onUpdate A method to invoke when updates occur
1706
+ */ function useCollector(monitor, collect, onUpdate) {
1707
+ const [collected, setCollected] = useState(()=>collect(monitor)
1708
+ );
1709
+ const updateCollected = useCallback(()=>{
1710
+ const nextValue = collect(monitor);
1711
+ // This needs to be a deep-equality check because some monitor-collected values
1712
+ // include XYCoord objects that may be equivalent, but do not have instance equality.
1713
+ if (!equal(collected, nextValue)) {
1714
+ setCollected(nextValue);
1715
+ if (onUpdate) {
1716
+ onUpdate();
1717
+ }
1718
+ }
1719
+ }, [
1720
+ collected,
1721
+ monitor,
1722
+ onUpdate
1723
+ ]);
1724
+ // update the collected properties after react renders.
1725
+ // Note that the "Dustbin Stress Test" fails if this is not
1726
+ // done when the component updates
1727
+ useIsomorphicLayoutEffect(updateCollected);
1728
+ return [
1729
+ collected,
1730
+ updateCollected
1731
+ ];
1732
+ }
1733
+
1734
+ function useMonitorOutput(monitor, collect, onCollect) {
1735
+ const [collected, updateCollected] = useCollector(monitor, collect, onCollect);
1736
+ useIsomorphicLayoutEffect(function subscribeToMonitorStateChange() {
1737
+ const handlerId = monitor.getHandlerId();
1738
+ if (handlerId == null) {
1739
+ return;
1740
+ }
1741
+ return monitor.subscribeToStateChange(updateCollected, {
1742
+ handlerIds: [
1743
+ handlerId
1744
+ ]
1745
+ });
1746
+ }, [
1747
+ monitor,
1748
+ updateCollected
1749
+ ]);
1750
+ return collected;
1751
+ }
1752
+
1753
+ function useCollectedProps(collector, monitor, connector) {
1754
+ return useMonitorOutput(monitor, collector || (()=>({})
1755
+ ), ()=>connector.reconnect()
1756
+ );
1757
+ }
1758
+
1759
+ function useOptionalFactory(arg, deps) {
1760
+ const memoDeps = [
1761
+ ...[]
1762
+ ];
1763
+ if (typeof arg !== 'function') {
1764
+ memoDeps.push(arg);
1765
+ }
1766
+ return useMemo(()=>{
1767
+ return typeof arg === 'function' ? arg() : arg;
1768
+ }, memoDeps);
1769
+ }
1770
+
1771
+ function useConnectDragSource(connector) {
1772
+ return useMemo(()=>connector.hooks.dragSource()
1773
+ , [
1774
+ connector
1775
+ ]);
1776
+ }
1777
+ function useConnectDragPreview(connector) {
1778
+ return useMemo(()=>connector.hooks.dragPreview()
1779
+ , [
1780
+ connector
1781
+ ]);
1782
+ }
1783
+
1784
+ let isCallingCanDrag = false;
1785
+ let isCallingIsDragging = false;
1786
+ class DragSourceMonitorImpl {
1787
+ receiveHandlerId(sourceId) {
1788
+ this.sourceId = sourceId;
1789
+ }
1790
+ getHandlerId() {
1791
+ return this.sourceId;
1792
+ }
1793
+ canDrag() {
1794
+ invariant(!isCallingCanDrag, 'You may not call monitor.canDrag() inside your canDrag() implementation. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor');
1795
+ try {
1796
+ isCallingCanDrag = true;
1797
+ return this.internalMonitor.canDragSource(this.sourceId);
1798
+ } finally{
1799
+ isCallingCanDrag = false;
1800
+ }
1801
+ }
1802
+ isDragging() {
1803
+ if (!this.sourceId) {
1804
+ return false;
1805
+ }
1806
+ invariant(!isCallingIsDragging, 'You may not call monitor.isDragging() inside your isDragging() implementation. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs/api/drag-source-monitor');
1807
+ try {
1808
+ isCallingIsDragging = true;
1809
+ return this.internalMonitor.isDraggingSource(this.sourceId);
1810
+ } finally{
1811
+ isCallingIsDragging = false;
1812
+ }
1813
+ }
1814
+ subscribeToStateChange(listener, options) {
1815
+ return this.internalMonitor.subscribeToStateChange(listener, options);
1816
+ }
1817
+ isDraggingSource(sourceId) {
1818
+ return this.internalMonitor.isDraggingSource(sourceId);
1819
+ }
1820
+ isOverTarget(targetId, options) {
1821
+ return this.internalMonitor.isOverTarget(targetId, options);
1822
+ }
1823
+ getTargetIds() {
1824
+ return this.internalMonitor.getTargetIds();
1825
+ }
1826
+ isSourcePublic() {
1827
+ return this.internalMonitor.isSourcePublic();
1828
+ }
1829
+ getSourceId() {
1830
+ return this.internalMonitor.getSourceId();
1831
+ }
1832
+ subscribeToOffsetChange(listener) {
1833
+ return this.internalMonitor.subscribeToOffsetChange(listener);
1834
+ }
1835
+ canDragSource(sourceId) {
1836
+ return this.internalMonitor.canDragSource(sourceId);
1837
+ }
1838
+ canDropOnTarget(targetId) {
1839
+ return this.internalMonitor.canDropOnTarget(targetId);
1840
+ }
1841
+ getItemType() {
1842
+ return this.internalMonitor.getItemType();
1843
+ }
1844
+ getItem() {
1845
+ return this.internalMonitor.getItem();
1846
+ }
1847
+ getDropResult() {
1848
+ return this.internalMonitor.getDropResult();
1849
+ }
1850
+ didDrop() {
1851
+ return this.internalMonitor.didDrop();
1852
+ }
1853
+ getInitialClientOffset() {
1854
+ return this.internalMonitor.getInitialClientOffset();
1855
+ }
1856
+ getInitialSourceClientOffset() {
1857
+ return this.internalMonitor.getInitialSourceClientOffset();
1858
+ }
1859
+ getSourceClientOffset() {
1860
+ return this.internalMonitor.getSourceClientOffset();
1861
+ }
1862
+ getClientOffset() {
1863
+ return this.internalMonitor.getClientOffset();
1864
+ }
1865
+ getDifferenceFromInitialOffset() {
1866
+ return this.internalMonitor.getDifferenceFromInitialOffset();
1867
+ }
1868
+ constructor(manager){
1869
+ this.sourceId = null;
1870
+ this.internalMonitor = manager.getMonitor();
1871
+ }
1872
+ }
1873
+
1874
+ let isCallingCanDrop = false;
1875
+ class DropTargetMonitorImpl {
1876
+ receiveHandlerId(targetId) {
1877
+ this.targetId = targetId;
1878
+ }
1879
+ getHandlerId() {
1880
+ return this.targetId;
1881
+ }
1882
+ subscribeToStateChange(listener, options) {
1883
+ return this.internalMonitor.subscribeToStateChange(listener, options);
1884
+ }
1885
+ canDrop() {
1886
+ // Cut out early if the target id has not been set. This should prevent errors
1887
+ // where the user has an older version of dnd-core like in
1888
+ // https://github.com/react-dnd/react-dnd/issues/1310
1889
+ if (!this.targetId) {
1890
+ return false;
1891
+ }
1892
+ invariant(!isCallingCanDrop, 'You may not call monitor.canDrop() inside your canDrop() implementation. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs/api/drop-target-monitor');
1893
+ try {
1894
+ isCallingCanDrop = true;
1895
+ return this.internalMonitor.canDropOnTarget(this.targetId);
1896
+ } finally{
1897
+ isCallingCanDrop = false;
1898
+ }
1899
+ }
1900
+ isOver(options) {
1901
+ if (!this.targetId) {
1902
+ return false;
1903
+ }
1904
+ return this.internalMonitor.isOverTarget(this.targetId, options);
1905
+ }
1906
+ getItemType() {
1907
+ return this.internalMonitor.getItemType();
1908
+ }
1909
+ getItem() {
1910
+ return this.internalMonitor.getItem();
1911
+ }
1912
+ getDropResult() {
1913
+ return this.internalMonitor.getDropResult();
1914
+ }
1915
+ didDrop() {
1916
+ return this.internalMonitor.didDrop();
1917
+ }
1918
+ getInitialClientOffset() {
1919
+ return this.internalMonitor.getInitialClientOffset();
1920
+ }
1921
+ getInitialSourceClientOffset() {
1922
+ return this.internalMonitor.getInitialSourceClientOffset();
1923
+ }
1924
+ getSourceClientOffset() {
1925
+ return this.internalMonitor.getSourceClientOffset();
1926
+ }
1927
+ getClientOffset() {
1928
+ return this.internalMonitor.getClientOffset();
1929
+ }
1930
+ getDifferenceFromInitialOffset() {
1931
+ return this.internalMonitor.getDifferenceFromInitialOffset();
1932
+ }
1933
+ constructor(manager){
1934
+ this.targetId = null;
1935
+ this.internalMonitor = manager.getMonitor();
1936
+ }
1937
+ }
1938
+
1939
+ function registerTarget(type, target, manager) {
1940
+ const registry = manager.getRegistry();
1941
+ const targetId = registry.addTarget(type, target);
1942
+ return [
1943
+ targetId,
1944
+ ()=>registry.removeTarget(targetId)
1945
+ ];
1946
+ }
1947
+ function registerSource(type, source, manager) {
1948
+ const registry = manager.getRegistry();
1949
+ const sourceId = registry.addSource(type, source);
1950
+ return [
1951
+ sourceId,
1952
+ ()=>registry.removeSource(sourceId)
1953
+ ];
1954
+ }
1955
+
1956
+ function shallowEqual(objA, objB, compare, compareContext) {
1957
+ let compareResult = void 0;
1958
+ if (compareResult !== void 0) {
1959
+ return !!compareResult;
1960
+ }
1961
+ if (objA === objB) {
1962
+ return true;
1963
+ }
1964
+ if (typeof objA !== 'object' || !objA || typeof objB !== 'object' || !objB) {
1965
+ return false;
1966
+ }
1967
+ const keysA = Object.keys(objA);
1968
+ const keysB = Object.keys(objB);
1969
+ if (keysA.length !== keysB.length) {
1970
+ return false;
1971
+ }
1972
+ const bHasOwnProperty = Object.prototype.hasOwnProperty.bind(objB);
1973
+ // Test for A's keys different from B.
1974
+ for(let idx = 0; idx < keysA.length; idx++){
1975
+ const key = keysA[idx];
1976
+ if (!bHasOwnProperty(key)) {
1977
+ return false;
1978
+ }
1979
+ const valueA = objA[key];
1980
+ const valueB = objB[key];
1981
+ compareResult = void 0;
1982
+ if (compareResult === false || compareResult === void 0 && valueA !== valueB) {
1983
+ return false;
1984
+ }
1985
+ }
1986
+ return true;
1987
+ }
1988
+
1989
+ function isRef(obj) {
1990
+ return(// eslint-disable-next-line no-prototype-builtins
1991
+ obj !== null && typeof obj === 'object' && Object.prototype.hasOwnProperty.call(obj, 'current'));
1992
+ }
1993
+
1994
+ function throwIfCompositeComponentElement(element) {
1995
+ // Custom components can no longer be wrapped directly in React DnD 2.0
1996
+ // so that we don't need to depend on findDOMNode() from react-dom.
1997
+ if (typeof element.type === 'string') {
1998
+ return;
1999
+ }
2000
+ const displayName = element.type.displayName || element.type.name || 'the component';
2001
+ throw new Error('Only native element nodes can now be passed to React DnD connectors.' + `You can either wrap ${displayName} into a <div>, or turn it into a ` + 'drag source or a drop target itself.');
2002
+ }
2003
+ function wrapHookToRecognizeElement(hook) {
2004
+ return (elementOrNode = null, options = null)=>{
2005
+ // When passed a node, call the hook straight away.
2006
+ if (!isValidElement(elementOrNode)) {
2007
+ const node = elementOrNode;
2008
+ hook(node, options);
2009
+ // return the node so it can be chained (e.g. when within callback refs
2010
+ // <div ref={node => connectDragSource(connectDropTarget(node))}/>
2011
+ return node;
2012
+ }
2013
+ // If passed a ReactElement, clone it and attach this function as a ref.
2014
+ // This helps us achieve a neat API where user doesn't even know that refs
2015
+ // are being used under the hood.
2016
+ const element = elementOrNode;
2017
+ throwIfCompositeComponentElement(element);
2018
+ // When no options are passed, use the hook directly
2019
+ const ref = options ? (node)=>hook(node, options)
2020
+ : hook;
2021
+ return cloneWithRef(element, ref);
2022
+ };
2023
+ }
2024
+ function wrapConnectorHooks(hooks) {
2025
+ const wrappedHooks = {};
2026
+ Object.keys(hooks).forEach((key)=>{
2027
+ const hook = hooks[key];
2028
+ // ref objects should be passed straight through without wrapping
2029
+ if (key.endsWith('Ref')) {
2030
+ wrappedHooks[key] = hooks[key];
2031
+ } else {
2032
+ const wrappedHook = wrapHookToRecognizeElement(hook);
2033
+ wrappedHooks[key] = ()=>wrappedHook
2034
+ ;
2035
+ }
2036
+ });
2037
+ return wrappedHooks;
2038
+ }
2039
+ function setRef(ref, node) {
2040
+ if (typeof ref === 'function') {
2041
+ ref(node);
2042
+ } else {
2043
+ ref.current = node;
2044
+ }
2045
+ }
2046
+ function cloneWithRef(element, newRef) {
2047
+ const previousRef = element.ref;
2048
+ invariant(typeof previousRef !== 'string', 'Cannot connect React DnD to an element with an existing string ref. ' + 'Please convert it to use a callback ref instead, or wrap it into a <span> or <div>. ' + 'Read more: https://reactjs.org/docs/refs-and-the-dom.html#callback-refs');
2049
+ if (!previousRef) {
2050
+ // When there is no ref on the element, use the new ref directly
2051
+ return cloneElement(element, {
2052
+ ref: newRef
2053
+ });
2054
+ } else {
2055
+ return cloneElement(element, {
2056
+ ref: (node)=>{
2057
+ setRef(previousRef, node);
2058
+ setRef(newRef, node);
2059
+ }
2060
+ });
2061
+ }
2062
+ }
2063
+
2064
+ class SourceConnector {
2065
+ receiveHandlerId(newHandlerId) {
2066
+ if (this.handlerId === newHandlerId) {
2067
+ return;
2068
+ }
2069
+ this.handlerId = newHandlerId;
2070
+ this.reconnect();
2071
+ }
2072
+ get connectTarget() {
2073
+ return this.dragSource;
2074
+ }
2075
+ get dragSourceOptions() {
2076
+ return this.dragSourceOptionsInternal;
2077
+ }
2078
+ set dragSourceOptions(options) {
2079
+ this.dragSourceOptionsInternal = options;
2080
+ }
2081
+ get dragPreviewOptions() {
2082
+ return this.dragPreviewOptionsInternal;
2083
+ }
2084
+ set dragPreviewOptions(options) {
2085
+ this.dragPreviewOptionsInternal = options;
2086
+ }
2087
+ reconnect() {
2088
+ const didChange = this.reconnectDragSource();
2089
+ this.reconnectDragPreview(didChange);
2090
+ }
2091
+ reconnectDragSource() {
2092
+ const dragSource = this.dragSource;
2093
+ // if nothing has changed then don't resubscribe
2094
+ const didChange = this.didHandlerIdChange() || this.didConnectedDragSourceChange() || this.didDragSourceOptionsChange();
2095
+ if (didChange) {
2096
+ this.disconnectDragSource();
2097
+ }
2098
+ if (!this.handlerId) {
2099
+ return didChange;
2100
+ }
2101
+ if (!dragSource) {
2102
+ this.lastConnectedDragSource = dragSource;
2103
+ return didChange;
2104
+ }
2105
+ if (didChange) {
2106
+ this.lastConnectedHandlerId = this.handlerId;
2107
+ this.lastConnectedDragSource = dragSource;
2108
+ this.lastConnectedDragSourceOptions = this.dragSourceOptions;
2109
+ this.dragSourceUnsubscribe = this.backend.connectDragSource(this.handlerId, dragSource, this.dragSourceOptions);
2110
+ }
2111
+ return didChange;
2112
+ }
2113
+ reconnectDragPreview(forceDidChange = false) {
2114
+ const dragPreview = this.dragPreview;
2115
+ // if nothing has changed then don't resubscribe
2116
+ const didChange = forceDidChange || this.didHandlerIdChange() || this.didConnectedDragPreviewChange() || this.didDragPreviewOptionsChange();
2117
+ if (didChange) {
2118
+ this.disconnectDragPreview();
2119
+ }
2120
+ if (!this.handlerId) {
2121
+ return;
2122
+ }
2123
+ if (!dragPreview) {
2124
+ this.lastConnectedDragPreview = dragPreview;
2125
+ return;
2126
+ }
2127
+ if (didChange) {
2128
+ this.lastConnectedHandlerId = this.handlerId;
2129
+ this.lastConnectedDragPreview = dragPreview;
2130
+ this.lastConnectedDragPreviewOptions = this.dragPreviewOptions;
2131
+ this.dragPreviewUnsubscribe = this.backend.connectDragPreview(this.handlerId, dragPreview, this.dragPreviewOptions);
2132
+ }
2133
+ }
2134
+ didHandlerIdChange() {
2135
+ return this.lastConnectedHandlerId !== this.handlerId;
2136
+ }
2137
+ didConnectedDragSourceChange() {
2138
+ return this.lastConnectedDragSource !== this.dragSource;
2139
+ }
2140
+ didConnectedDragPreviewChange() {
2141
+ return this.lastConnectedDragPreview !== this.dragPreview;
2142
+ }
2143
+ didDragSourceOptionsChange() {
2144
+ return !shallowEqual(this.lastConnectedDragSourceOptions, this.dragSourceOptions);
2145
+ }
2146
+ didDragPreviewOptionsChange() {
2147
+ return !shallowEqual(this.lastConnectedDragPreviewOptions, this.dragPreviewOptions);
2148
+ }
2149
+ disconnectDragSource() {
2150
+ if (this.dragSourceUnsubscribe) {
2151
+ this.dragSourceUnsubscribe();
2152
+ this.dragSourceUnsubscribe = undefined;
2153
+ }
2154
+ }
2155
+ disconnectDragPreview() {
2156
+ if (this.dragPreviewUnsubscribe) {
2157
+ this.dragPreviewUnsubscribe();
2158
+ this.dragPreviewUnsubscribe = undefined;
2159
+ this.dragPreviewNode = null;
2160
+ this.dragPreviewRef = null;
2161
+ }
2162
+ }
2163
+ get dragSource() {
2164
+ return this.dragSourceNode || this.dragSourceRef && this.dragSourceRef.current;
2165
+ }
2166
+ get dragPreview() {
2167
+ return this.dragPreviewNode || this.dragPreviewRef && this.dragPreviewRef.current;
2168
+ }
2169
+ clearDragSource() {
2170
+ this.dragSourceNode = null;
2171
+ this.dragSourceRef = null;
2172
+ }
2173
+ clearDragPreview() {
2174
+ this.dragPreviewNode = null;
2175
+ this.dragPreviewRef = null;
2176
+ }
2177
+ constructor(backend){
2178
+ this.hooks = wrapConnectorHooks({
2179
+ dragSource: (node, options)=>{
2180
+ this.clearDragSource();
2181
+ this.dragSourceOptions = options || null;
2182
+ if (isRef(node)) {
2183
+ this.dragSourceRef = node;
2184
+ } else {
2185
+ this.dragSourceNode = node;
2186
+ }
2187
+ this.reconnectDragSource();
2188
+ },
2189
+ dragPreview: (node, options)=>{
2190
+ this.clearDragPreview();
2191
+ this.dragPreviewOptions = options || null;
2192
+ if (isRef(node)) {
2193
+ this.dragPreviewRef = node;
2194
+ } else {
2195
+ this.dragPreviewNode = node;
2196
+ }
2197
+ this.reconnectDragPreview();
2198
+ }
2199
+ });
2200
+ this.handlerId = null;
2201
+ // The drop target may either be attached via ref or connect function
2202
+ this.dragSourceRef = null;
2203
+ this.dragSourceOptionsInternal = null;
2204
+ // The drag preview may either be attached via ref or connect function
2205
+ this.dragPreviewRef = null;
2206
+ this.dragPreviewOptionsInternal = null;
2207
+ this.lastConnectedHandlerId = null;
2208
+ this.lastConnectedDragSource = null;
2209
+ this.lastConnectedDragSourceOptions = null;
2210
+ this.lastConnectedDragPreview = null;
2211
+ this.lastConnectedDragPreviewOptions = null;
2212
+ this.backend = backend;
2213
+ }
2214
+ }
2215
+
2216
+ class TargetConnector {
2217
+ get connectTarget() {
2218
+ return this.dropTarget;
2219
+ }
2220
+ reconnect() {
2221
+ // if nothing has changed then don't resubscribe
2222
+ const didChange = this.didHandlerIdChange() || this.didDropTargetChange() || this.didOptionsChange();
2223
+ if (didChange) {
2224
+ this.disconnectDropTarget();
2225
+ }
2226
+ const dropTarget = this.dropTarget;
2227
+ if (!this.handlerId) {
2228
+ return;
2229
+ }
2230
+ if (!dropTarget) {
2231
+ this.lastConnectedDropTarget = dropTarget;
2232
+ return;
2233
+ }
2234
+ if (didChange) {
2235
+ this.lastConnectedHandlerId = this.handlerId;
2236
+ this.lastConnectedDropTarget = dropTarget;
2237
+ this.lastConnectedDropTargetOptions = this.dropTargetOptions;
2238
+ this.unsubscribeDropTarget = this.backend.connectDropTarget(this.handlerId, dropTarget, this.dropTargetOptions);
2239
+ }
2240
+ }
2241
+ receiveHandlerId(newHandlerId) {
2242
+ if (newHandlerId === this.handlerId) {
2243
+ return;
2244
+ }
2245
+ this.handlerId = newHandlerId;
2246
+ this.reconnect();
2247
+ }
2248
+ get dropTargetOptions() {
2249
+ return this.dropTargetOptionsInternal;
2250
+ }
2251
+ set dropTargetOptions(options) {
2252
+ this.dropTargetOptionsInternal = options;
2253
+ }
2254
+ didHandlerIdChange() {
2255
+ return this.lastConnectedHandlerId !== this.handlerId;
2256
+ }
2257
+ didDropTargetChange() {
2258
+ return this.lastConnectedDropTarget !== this.dropTarget;
2259
+ }
2260
+ didOptionsChange() {
2261
+ return !shallowEqual(this.lastConnectedDropTargetOptions, this.dropTargetOptions);
2262
+ }
2263
+ disconnectDropTarget() {
2264
+ if (this.unsubscribeDropTarget) {
2265
+ this.unsubscribeDropTarget();
2266
+ this.unsubscribeDropTarget = undefined;
2267
+ }
2268
+ }
2269
+ get dropTarget() {
2270
+ return this.dropTargetNode || this.dropTargetRef && this.dropTargetRef.current;
2271
+ }
2272
+ clearDropTarget() {
2273
+ this.dropTargetRef = null;
2274
+ this.dropTargetNode = null;
2275
+ }
2276
+ constructor(backend){
2277
+ this.hooks = wrapConnectorHooks({
2278
+ dropTarget: (node, options)=>{
2279
+ this.clearDropTarget();
2280
+ this.dropTargetOptions = options;
2281
+ if (isRef(node)) {
2282
+ this.dropTargetRef = node;
2283
+ } else {
2284
+ this.dropTargetNode = node;
2285
+ }
2286
+ this.reconnect();
2287
+ }
2288
+ });
2289
+ this.handlerId = null;
2290
+ // The drop target may either be attached via ref or connect function
2291
+ this.dropTargetRef = null;
2292
+ this.dropTargetOptionsInternal = null;
2293
+ this.lastConnectedHandlerId = null;
2294
+ this.lastConnectedDropTarget = null;
2295
+ this.lastConnectedDropTargetOptions = null;
2296
+ this.backend = backend;
2297
+ }
2298
+ }
2299
+
2300
+ /**
2301
+ * A hook to retrieve the DragDropManager from Context
2302
+ */ function useDragDropManager() {
2303
+ const { dragDropManager } = useContext(DndContext);
2304
+ invariant(dragDropManager != null, 'Expected drag drop context');
2305
+ return dragDropManager;
2306
+ }
2307
+
2308
+ function useDragSourceConnector(dragSourceOptions, dragPreviewOptions) {
2309
+ const manager = useDragDropManager();
2310
+ const connector = useMemo(()=>new SourceConnector(manager.getBackend())
2311
+ , [
2312
+ manager
2313
+ ]);
2314
+ useIsomorphicLayoutEffect(()=>{
2315
+ connector.dragSourceOptions = dragSourceOptions || null;
2316
+ connector.reconnect();
2317
+ return ()=>connector.disconnectDragSource()
2318
+ ;
2319
+ }, [
2320
+ connector,
2321
+ dragSourceOptions
2322
+ ]);
2323
+ useIsomorphicLayoutEffect(()=>{
2324
+ connector.dragPreviewOptions = dragPreviewOptions || null;
2325
+ connector.reconnect();
2326
+ return ()=>connector.disconnectDragPreview()
2327
+ ;
2328
+ }, [
2329
+ connector,
2330
+ dragPreviewOptions
2331
+ ]);
2332
+ return connector;
2333
+ }
2334
+
2335
+ function useDragSourceMonitor() {
2336
+ const manager = useDragDropManager();
2337
+ return useMemo(()=>new DragSourceMonitorImpl(manager)
2338
+ , [
2339
+ manager
2340
+ ]);
2341
+ }
2342
+
2343
+ class DragSourceImpl {
2344
+ beginDrag() {
2345
+ const spec = this.spec;
2346
+ const monitor = this.monitor;
2347
+ let result = null;
2348
+ if (typeof spec.item === 'object') {
2349
+ result = spec.item;
2350
+ } else if (typeof spec.item === 'function') {
2351
+ result = spec.item(monitor);
2352
+ } else {
2353
+ result = {};
2354
+ }
2355
+ return result !== null && result !== void 0 ? result : null;
2356
+ }
2357
+ canDrag() {
2358
+ const spec = this.spec;
2359
+ const monitor = this.monitor;
2360
+ if (typeof spec.canDrag === 'boolean') {
2361
+ return spec.canDrag;
2362
+ } else if (typeof spec.canDrag === 'function') {
2363
+ return spec.canDrag(monitor);
2364
+ } else {
2365
+ return true;
2366
+ }
2367
+ }
2368
+ isDragging(globalMonitor, target) {
2369
+ const spec = this.spec;
2370
+ const monitor = this.monitor;
2371
+ const { isDragging } = spec;
2372
+ return isDragging ? isDragging(monitor) : target === globalMonitor.getSourceId();
2373
+ }
2374
+ endDrag() {
2375
+ const spec = this.spec;
2376
+ const monitor = this.monitor;
2377
+ const connector = this.connector;
2378
+ const { end } = spec;
2379
+ if (end) {
2380
+ end(monitor.getItem(), monitor);
2381
+ }
2382
+ connector.reconnect();
2383
+ }
2384
+ constructor(spec, monitor, connector){
2385
+ this.spec = spec;
2386
+ this.monitor = monitor;
2387
+ this.connector = connector;
2388
+ }
2389
+ }
2390
+
2391
+ function useDragSource(spec, monitor, connector) {
2392
+ const handler = useMemo(()=>new DragSourceImpl(spec, monitor, connector)
2393
+ , [
2394
+ monitor,
2395
+ connector
2396
+ ]);
2397
+ useEffect(()=>{
2398
+ handler.spec = spec;
2399
+ }, [
2400
+ spec
2401
+ ]);
2402
+ return handler;
2403
+ }
2404
+
2405
+ function useDragType(spec) {
2406
+ return useMemo(()=>{
2407
+ const result = spec.type;
2408
+ invariant(result != null, 'spec.type must be defined');
2409
+ return result;
2410
+ }, [
2411
+ spec
2412
+ ]);
2413
+ }
2414
+
2415
+ function useRegisteredDragSource(spec, monitor, connector) {
2416
+ const manager = useDragDropManager();
2417
+ const handler = useDragSource(spec, monitor, connector);
2418
+ const itemType = useDragType(spec);
2419
+ useIsomorphicLayoutEffect(function registerDragSource() {
2420
+ if (itemType != null) {
2421
+ const [handlerId, unregister] = registerSource(itemType, handler, manager);
2422
+ monitor.receiveHandlerId(handlerId);
2423
+ connector.receiveHandlerId(handlerId);
2424
+ return unregister;
2425
+ }
2426
+ return;
2427
+ }, [
2428
+ manager,
2429
+ monitor,
2430
+ connector,
2431
+ handler,
2432
+ itemType
2433
+ ]);
2434
+ }
2435
+
2436
+ /**
2437
+ * useDragSource hook
2438
+ * @param sourceSpec The drag source specification (object or function, function preferred)
2439
+ * @param deps The memoization deps array to use when evaluating spec changes
2440
+ */ function useDrag(specArg, deps) {
2441
+ const spec = useOptionalFactory(specArg);
2442
+ invariant(!spec.begin, `useDrag::spec.begin was deprecated in v14. Replace spec.begin() with spec.item(). (see more here - https://react-dnd.github.io/react-dnd/docs/api/use-drag)`);
2443
+ const monitor = useDragSourceMonitor();
2444
+ const connector = useDragSourceConnector(spec.options, spec.previewOptions);
2445
+ useRegisteredDragSource(spec, monitor, connector);
2446
+ return [
2447
+ useCollectedProps(spec.collect, monitor, connector),
2448
+ useConnectDragSource(connector),
2449
+ useConnectDragPreview(connector),
2450
+ ];
2451
+ }
2452
+
2453
+ function useConnectDropTarget(connector) {
2454
+ return useMemo(()=>connector.hooks.dropTarget()
2455
+ , [
2456
+ connector
2457
+ ]);
2458
+ }
2459
+
2460
+ function useDropTargetConnector(options) {
2461
+ const manager = useDragDropManager();
2462
+ const connector = useMemo(()=>new TargetConnector(manager.getBackend())
2463
+ , [
2464
+ manager
2465
+ ]);
2466
+ useIsomorphicLayoutEffect(()=>{
2467
+ connector.dropTargetOptions = options || null;
2468
+ connector.reconnect();
2469
+ return ()=>connector.disconnectDropTarget()
2470
+ ;
2471
+ }, [
2472
+ options
2473
+ ]);
2474
+ return connector;
2475
+ }
2476
+
2477
+ function useDropTargetMonitor() {
2478
+ const manager = useDragDropManager();
2479
+ return useMemo(()=>new DropTargetMonitorImpl(manager)
2480
+ , [
2481
+ manager
2482
+ ]);
2483
+ }
2484
+
2485
+ /**
2486
+ * Internal utility hook to get an array-version of spec.accept.
2487
+ * The main utility here is that we aren't creating a new array on every render if a non-array spec.accept is passed in.
2488
+ * @param spec
2489
+ */ function useAccept(spec) {
2490
+ const { accept } = spec;
2491
+ return useMemo(()=>{
2492
+ invariant(spec.accept != null, 'accept must be defined');
2493
+ return Array.isArray(accept) ? accept : [
2494
+ accept
2495
+ ];
2496
+ }, [
2497
+ accept
2498
+ ]);
2499
+ }
2500
+
2501
+ class DropTargetImpl {
2502
+ canDrop() {
2503
+ const spec = this.spec;
2504
+ const monitor = this.monitor;
2505
+ return spec.canDrop ? spec.canDrop(monitor.getItem(), monitor) : true;
2506
+ }
2507
+ hover() {
2508
+ const spec = this.spec;
2509
+ const monitor = this.monitor;
2510
+ if (spec.hover) {
2511
+ spec.hover(monitor.getItem(), monitor);
2512
+ }
2513
+ }
2514
+ drop() {
2515
+ const spec = this.spec;
2516
+ const monitor = this.monitor;
2517
+ if (spec.drop) {
2518
+ return spec.drop(monitor.getItem(), monitor);
2519
+ }
2520
+ return;
2521
+ }
2522
+ constructor(spec, monitor){
2523
+ this.spec = spec;
2524
+ this.monitor = monitor;
2525
+ }
2526
+ }
2527
+
2528
+ function useDropTarget(spec, monitor) {
2529
+ const dropTarget = useMemo(()=>new DropTargetImpl(spec, monitor)
2530
+ , [
2531
+ monitor
2532
+ ]);
2533
+ useEffect(()=>{
2534
+ dropTarget.spec = spec;
2535
+ }, [
2536
+ spec
2537
+ ]);
2538
+ return dropTarget;
2539
+ }
2540
+
2541
+ function useRegisteredDropTarget(spec, monitor, connector) {
2542
+ const manager = useDragDropManager();
2543
+ const dropTarget = useDropTarget(spec, monitor);
2544
+ const accept = useAccept(spec);
2545
+ useIsomorphicLayoutEffect(function registerDropTarget() {
2546
+ const [handlerId, unregister] = registerTarget(accept, dropTarget, manager);
2547
+ monitor.receiveHandlerId(handlerId);
2548
+ connector.receiveHandlerId(handlerId);
2549
+ return unregister;
2550
+ }, [
2551
+ manager,
2552
+ monitor,
2553
+ dropTarget,
2554
+ connector,
2555
+ accept.map((a)=>a.toString()
2556
+ ).join('|'),
2557
+ ]);
2558
+ }
2559
+
2560
+ /**
2561
+ * useDropTarget Hook
2562
+ * @param spec The drop target specification (object or function, function preferred)
2563
+ * @param deps The memoization deps array to use when evaluating spec changes
2564
+ */ function useDrop(specArg, deps) {
2565
+ const spec = useOptionalFactory(specArg);
2566
+ const monitor = useDropTargetMonitor();
2567
+ const connector = useDropTargetConnector(spec.options);
2568
+ useRegisteredDropTarget(spec, monitor, connector);
2569
+ return [
2570
+ useCollectedProps(spec.collect, monitor, connector),
2571
+ useConnectDropTarget(connector),
2572
+ ];
2573
+ }
2574
+
1597
2575
  var dummyEngine = new Engine();
1598
2576
  var FlowContext = React.createContext({
1599
2577
  engine: dummyEngine,