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