@rkmodules/rules 0.0.51 → 0.0.53

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