diff --git a/package-lock.json b/package-lock.json index 6c7af995..015fd92b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6177,6 +6177,11 @@ "integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==", "dev": true }, + "classcat": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/classcat/-/classcat-4.1.0.tgz", + "integrity": "sha512-RA8O5oCi1I1CF6rR4cRBROh8MtZzM4w7xKLm0jd+S6UN2G4FIto+9DVOeFc46JEZFN5PVe/EZWLQO1VU/AUH4A==" + }, "classnames": { "version": "2.2.6", "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.2.6.tgz", diff --git a/package.json b/package.json index fcfa20a8..c09688a8 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ }, "dependencies": { "@welldone-software/why-did-you-render": "^4.2.5", - "classnames": "^2.2.6", + "classcat": "^4.1.0", "d3-selection": "^1.4.1", "d3-zoom": "^1.8.3", "easy-peasy": "^3.3.1", diff --git a/src/additional-components/Background/index.tsx b/src/additional-components/Background/index.tsx index 4228a089..86a24a09 100644 --- a/src/additional-components/Background/index.tsx +++ b/src/additional-components/Background/index.tsx @@ -1,5 +1,5 @@ import React, { memo, HTMLAttributes } from 'react'; -import classnames from 'classnames'; +import cc from 'classcat'; import { useStoreState } from '../../store/hooks'; import { BackgroundVariant } from '../../types'; @@ -25,7 +25,7 @@ const Background = memo( const height = useStoreState((s) => s.height); const [x, y, scale] = useStoreState((s) => s.transform); - const bgClasses = classnames('react-flow__background', className); + const bgClasses = cc(['react-flow__background', className]); const bgColor = color ? color : defaultColors[variant]; const scaledGap = gap * scale; const xOffset = x % scaledGap; diff --git a/src/additional-components/Controls/index.tsx b/src/additional-components/Controls/index.tsx index 0852f340..d1c78370 100644 --- a/src/additional-components/Controls/index.tsx +++ b/src/additional-components/Controls/index.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import classnames from 'classnames'; +import cc from 'classcat'; import { useStoreState, useStoreActions } from '../../store/hooks'; @@ -24,7 +24,7 @@ const Controls = ({ style, showZoom = true, showFitView = true, showInteractive const zoomOut = useStoreActions((actions) => actions.zoomOut); const isInteractive = useStoreState((s) => s.nodesDraggable && s.nodesConnectable && s.elementsSelectable); - const mapClasses = classnames('react-flow__controls', className); + const mapClasses = cc(['react-flow__controls', className]); return (
diff --git a/src/additional-components/MiniMap/index.tsx b/src/additional-components/MiniMap/index.tsx index 021ed7c1..6c109d7f 100644 --- a/src/additional-components/MiniMap/index.tsx +++ b/src/additional-components/MiniMap/index.tsx @@ -1,5 +1,5 @@ import React from 'react'; -import classnames from 'classnames'; +import cc from 'classcat'; import { useStoreState } from '../../store/hooks'; import { getRectOfNodes, getBoundsofRects } from '../../utils/graph'; @@ -31,7 +31,7 @@ const MiniMap = ({ const [tX, tY, tScale] = useStoreState((s) => s.transform); const nodes = useStoreState((s) => s.nodes); - const mapClasses = classnames('react-flow__minimap', className); + const mapClasses = cc(['react-flow__minimap', className]); const elementWidth = (style.width || defaultWidth)! as number; const elementHeight = (style.height || defaultHeight)! as number; const nodeColorFunc = (nodeColor instanceof Function ? nodeColor : () => nodeColor) as StringFunc; diff --git a/src/components/ConnectionLine/index.tsx b/src/components/ConnectionLine/index.tsx index d7b7033d..6daba9cb 100644 --- a/src/components/ConnectionLine/index.tsx +++ b/src/components/ConnectionLine/index.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useState, CSSProperties } from 'react'; -import cx from 'classnames'; +import cc from 'classcat'; import { getBezierPath } from '../Edges/BezierEdge'; import { getStepPath } from '../Edges/StepEdge'; @@ -46,7 +46,7 @@ export default ({ return null; } - const connectionLineClasses: string = cx('react-flow__connection', className); + const connectionLineClasses: string = cc(['react-flow__connection', className]); const sourceHandle = handleId ? sourceNode.__rf.handleBounds[connectionHandleType].find((d: HandleElement) => d.id === handleId) diff --git a/src/components/Edges/wrapEdge.tsx b/src/components/Edges/wrapEdge.tsx index 2b45535e..01eda6b7 100644 --- a/src/components/Edges/wrapEdge.tsx +++ b/src/components/Edges/wrapEdge.tsx @@ -1,5 +1,5 @@ import React, { memo, ComponentType, CSSProperties } from 'react'; -import cx from 'classnames'; +import cc from 'classcat'; import { useStoreActions } from '../../store/hooks'; import { ElementId, Edge, EdgeCompProps } from '../../types'; @@ -39,7 +39,7 @@ export default (EdgeComponent: ComponentType) => { ...rest }: EdgeWrapperProps) => { const setSelectedElements = useStoreActions((a) => a.setSelectedElements); - const edgeClasses = cx('react-flow__edge', `react-flow__edge-${type}`, className, { selected, animated }); + const edgeClasses = cc(['react-flow__edge', `react-flow__edge-${type}`, className, { selected, animated }]); const edgeGroupStyle: CSSProperties = { pointerEvents: elementsSelectable ? 'all' : 'none', }; diff --git a/src/components/Handle/BaseHandle.tsx b/src/components/Handle/BaseHandle.tsx index 57cc5443..7a16a001 100644 --- a/src/components/Handle/BaseHandle.tsx +++ b/src/components/Handle/BaseHandle.tsx @@ -1,5 +1,5 @@ import React, { memo, MouseEvent as ReactMouseEvent, CSSProperties } from 'react'; -import cx from 'classnames'; +import cc from 'classcat'; import { HandleType, ElementId, Position, XYPosition, OnConnectFunc, Connection, SetConnectionId } from '../../types'; @@ -144,10 +144,16 @@ const BaseHandle = memo( ...rest }: BaseHandleProps) => { const isTarget = type === 'target'; - const handleClasses = cx('react-flow__handle', `react-flow__handle-${position}`, 'nodrag', className, { - source: !isTarget, - target: isTarget, - }); + const handleClasses = cc([ + 'react-flow__handle', + `react-flow__handle-${position}`, + 'nodrag', + className, + { + source: !isTarget, + target: isTarget, + }, + ]); const nodeIdWithHandleId = id ? `${nodeId}__${id}` : nodeId; diff --git a/src/components/Handle/index.tsx b/src/components/Handle/index.tsx index 4c4d8875..adfdacd2 100644 --- a/src/components/Handle/index.tsx +++ b/src/components/Handle/index.tsx @@ -1,5 +1,5 @@ import React, { memo, useContext } from 'react'; -import classnames from 'classnames'; +import cc from 'classcat'; import { useStoreActions, useStoreState } from '../../store/hooks'; import BaseHandle from './BaseHandle'; @@ -26,7 +26,7 @@ const Handle = memo( onConnectAction(params); onConnect(params); }; - const handleClasses = classnames(className, { connectable: isConnectable }); + const handleClasses = cc([className, { connectable: isConnectable }]); return ( ) => { const [offset, setOffset] = useState({ x: 0, y: 0 }); const [isDragging, setDragging] = useState(false); const position = { x: xPos, y: yPos }; - const nodeClasses = cx('react-flow__node', `react-flow__node-${type}`, className, { - selected, - selectable: isSelectable, - }); + const nodeClasses = cc([ + 'react-flow__node', + `react-flow__node-${type}`, + className, + { + selected, + selectable: isSelectable, + }, + ]); const node = { id, type, position, data }; const onMouseEnterHandler = useMemo(() => { if (!onMouseEnter || isDragging) { diff --git a/src/container/ReactFlow/index.tsx b/src/container/ReactFlow/index.tsx index b3d5ff11..44a23d39 100644 --- a/src/container/ReactFlow/index.tsx +++ b/src/container/ReactFlow/index.tsx @@ -1,5 +1,5 @@ import React, { useMemo, CSSProperties, HTMLAttributes, MouseEvent } from 'react'; -import cx from 'classnames'; +import cc from 'classcat'; const nodeEnv: string = process.env.NODE_ENV as string; @@ -98,9 +98,10 @@ const ReactFlow = ({ }: ReactFlowProps) => { const nodeTypesParsed = useMemo(() => createNodeTypes(nodeTypes), []); const edgeTypesParsed = useMemo(() => createEdgeTypes(edgeTypes), []); + const reactFlowClasses = cc(['react-flow', className]); return ( -
+