refactor(classnames): use faster classcat alternative
This commit is contained in:
Generated
+5
@@ -6177,6 +6177,11 @@
|
|||||||
"integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==",
|
"integrity": "sha512-5tK7EtrZ0N+OLFMthtqOj4fI2Jeb88C4CAZPu25LDVUgXJ0A3Js4PMGqrn0JU1W0Mh1/Z8wZzYPxqUrXeBboCQ==",
|
||||||
"dev": true
|
"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": {
|
"classnames": {
|
||||||
"version": "2.2.6",
|
"version": "2.2.6",
|
||||||
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.2.6.tgz",
|
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.2.6.tgz",
|
||||||
|
|||||||
+1
-1
@@ -24,7 +24,7 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@welldone-software/why-did-you-render": "^4.2.5",
|
"@welldone-software/why-did-you-render": "^4.2.5",
|
||||||
"classnames": "^2.2.6",
|
"classcat": "^4.1.0",
|
||||||
"d3-selection": "^1.4.1",
|
"d3-selection": "^1.4.1",
|
||||||
"d3-zoom": "^1.8.3",
|
"d3-zoom": "^1.8.3",
|
||||||
"easy-peasy": "^3.3.1",
|
"easy-peasy": "^3.3.1",
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { memo, HTMLAttributes } from 'react';
|
import React, { memo, HTMLAttributes } from 'react';
|
||||||
import classnames from 'classnames';
|
import cc from 'classcat';
|
||||||
|
|
||||||
import { useStoreState } from '../../store/hooks';
|
import { useStoreState } from '../../store/hooks';
|
||||||
import { BackgroundVariant } from '../../types';
|
import { BackgroundVariant } from '../../types';
|
||||||
@@ -25,7 +25,7 @@ const Background = memo(
|
|||||||
const height = useStoreState((s) => s.height);
|
const height = useStoreState((s) => s.height);
|
||||||
const [x, y, scale] = useStoreState((s) => s.transform);
|
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 bgColor = color ? color : defaultColors[variant];
|
||||||
const scaledGap = gap * scale;
|
const scaledGap = gap * scale;
|
||||||
const xOffset = x % scaledGap;
|
const xOffset = x % scaledGap;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import classnames from 'classnames';
|
import cc from 'classcat';
|
||||||
|
|
||||||
import { useStoreState, useStoreActions } from '../../store/hooks';
|
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 zoomOut = useStoreActions((actions) => actions.zoomOut);
|
||||||
|
|
||||||
const isInteractive = useStoreState((s) => s.nodesDraggable && s.nodesConnectable && s.elementsSelectable);
|
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 (
|
return (
|
||||||
<div className={mapClasses} style={style}>
|
<div className={mapClasses} style={style}>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import classnames from 'classnames';
|
import cc from 'classcat';
|
||||||
|
|
||||||
import { useStoreState } from '../../store/hooks';
|
import { useStoreState } from '../../store/hooks';
|
||||||
import { getRectOfNodes, getBoundsofRects } from '../../utils/graph';
|
import { getRectOfNodes, getBoundsofRects } from '../../utils/graph';
|
||||||
@@ -31,7 +31,7 @@ const MiniMap = ({
|
|||||||
const [tX, tY, tScale] = useStoreState((s) => s.transform);
|
const [tX, tY, tScale] = useStoreState((s) => s.transform);
|
||||||
const nodes = useStoreState((s) => s.nodes);
|
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 elementWidth = (style.width || defaultWidth)! as number;
|
||||||
const elementHeight = (style.height || defaultHeight)! as number;
|
const elementHeight = (style.height || defaultHeight)! as number;
|
||||||
const nodeColorFunc = (nodeColor instanceof Function ? nodeColor : () => nodeColor) as StringFunc;
|
const nodeColorFunc = (nodeColor instanceof Function ? nodeColor : () => nodeColor) as StringFunc;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useEffect, useState, CSSProperties } from 'react';
|
import React, { useEffect, useState, CSSProperties } from 'react';
|
||||||
import cx from 'classnames';
|
import cc from 'classcat';
|
||||||
|
|
||||||
import { getBezierPath } from '../Edges/BezierEdge';
|
import { getBezierPath } from '../Edges/BezierEdge';
|
||||||
import { getStepPath } from '../Edges/StepEdge';
|
import { getStepPath } from '../Edges/StepEdge';
|
||||||
@@ -46,7 +46,7 @@ export default ({
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
const connectionLineClasses: string = cx('react-flow__connection', className);
|
const connectionLineClasses: string = cc(['react-flow__connection', className]);
|
||||||
|
|
||||||
const sourceHandle = handleId
|
const sourceHandle = handleId
|
||||||
? sourceNode.__rf.handleBounds[connectionHandleType].find((d: HandleElement) => d.id === handleId)
|
? sourceNode.__rf.handleBounds[connectionHandleType].find((d: HandleElement) => d.id === handleId)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { memo, ComponentType, CSSProperties } from 'react';
|
import React, { memo, ComponentType, CSSProperties } from 'react';
|
||||||
import cx from 'classnames';
|
import cc from 'classcat';
|
||||||
|
|
||||||
import { useStoreActions } from '../../store/hooks';
|
import { useStoreActions } from '../../store/hooks';
|
||||||
import { ElementId, Edge, EdgeCompProps } from '../../types';
|
import { ElementId, Edge, EdgeCompProps } from '../../types';
|
||||||
@@ -39,7 +39,7 @@ export default (EdgeComponent: ComponentType<EdgeCompProps>) => {
|
|||||||
...rest
|
...rest
|
||||||
}: EdgeWrapperProps) => {
|
}: EdgeWrapperProps) => {
|
||||||
const setSelectedElements = useStoreActions((a) => a.setSelectedElements);
|
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 = {
|
const edgeGroupStyle: CSSProperties = {
|
||||||
pointerEvents: elementsSelectable ? 'all' : 'none',
|
pointerEvents: elementsSelectable ? 'all' : 'none',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { memo, MouseEvent as ReactMouseEvent, CSSProperties } from 'react';
|
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';
|
import { HandleType, ElementId, Position, XYPosition, OnConnectFunc, Connection, SetConnectionId } from '../../types';
|
||||||
|
|
||||||
@@ -144,10 +144,16 @@ const BaseHandle = memo(
|
|||||||
...rest
|
...rest
|
||||||
}: BaseHandleProps) => {
|
}: BaseHandleProps) => {
|
||||||
const isTarget = type === 'target';
|
const isTarget = type === 'target';
|
||||||
const handleClasses = cx('react-flow__handle', `react-flow__handle-${position}`, 'nodrag', className, {
|
const handleClasses = cc([
|
||||||
source: !isTarget,
|
'react-flow__handle',
|
||||||
target: isTarget,
|
`react-flow__handle-${position}`,
|
||||||
});
|
'nodrag',
|
||||||
|
className,
|
||||||
|
{
|
||||||
|
source: !isTarget,
|
||||||
|
target: isTarget,
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
const nodeIdWithHandleId = id ? `${nodeId}__${id}` : nodeId;
|
const nodeIdWithHandleId = id ? `${nodeId}__${id}` : nodeId;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { memo, useContext } from 'react';
|
import React, { memo, useContext } from 'react';
|
||||||
import classnames from 'classnames';
|
import cc from 'classcat';
|
||||||
|
|
||||||
import { useStoreActions, useStoreState } from '../../store/hooks';
|
import { useStoreActions, useStoreState } from '../../store/hooks';
|
||||||
import BaseHandle from './BaseHandle';
|
import BaseHandle from './BaseHandle';
|
||||||
@@ -26,7 +26,7 @@ const Handle = memo(
|
|||||||
onConnectAction(params);
|
onConnectAction(params);
|
||||||
onConnect(params);
|
onConnect(params);
|
||||||
};
|
};
|
||||||
const handleClasses = classnames(className, { connectable: isConnectable });
|
const handleClasses = cc([className, { connectable: isConnectable }]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<BaseHandle
|
<BaseHandle
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ import React, {
|
|||||||
useCallback,
|
useCallback,
|
||||||
} from 'react';
|
} from 'react';
|
||||||
import { DraggableCore } from 'react-draggable';
|
import { DraggableCore } from 'react-draggable';
|
||||||
import cx from 'classnames';
|
import cc from 'classcat';
|
||||||
|
|
||||||
import { ResizeObserver } from 'resize-observer';
|
import { ResizeObserver } from 'resize-observer';
|
||||||
import { useStoreActions } from '../../store/hooks';
|
import { useStoreActions } from '../../store/hooks';
|
||||||
|
|
||||||
@@ -192,10 +193,15 @@ export default (NodeComponent: ComponentType<NodeComponentProps>) => {
|
|||||||
const [offset, setOffset] = useState({ x: 0, y: 0 });
|
const [offset, setOffset] = useState({ x: 0, y: 0 });
|
||||||
const [isDragging, setDragging] = useState(false);
|
const [isDragging, setDragging] = useState(false);
|
||||||
const position = { x: xPos, y: yPos };
|
const position = { x: xPos, y: yPos };
|
||||||
const nodeClasses = cx('react-flow__node', `react-flow__node-${type}`, className, {
|
const nodeClasses = cc([
|
||||||
selected,
|
'react-flow__node',
|
||||||
selectable: isSelectable,
|
`react-flow__node-${type}`,
|
||||||
});
|
className,
|
||||||
|
{
|
||||||
|
selected,
|
||||||
|
selectable: isSelectable,
|
||||||
|
},
|
||||||
|
]);
|
||||||
const node = { id, type, position, data };
|
const node = { id, type, position, data };
|
||||||
const onMouseEnterHandler = useMemo(() => {
|
const onMouseEnterHandler = useMemo(() => {
|
||||||
if (!onMouseEnter || isDragging) {
|
if (!onMouseEnter || isDragging) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useMemo, CSSProperties, HTMLAttributes, MouseEvent } from 'react';
|
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;
|
const nodeEnv: string = process.env.NODE_ENV as string;
|
||||||
|
|
||||||
@@ -98,9 +98,10 @@ const ReactFlow = ({
|
|||||||
}: ReactFlowProps) => {
|
}: ReactFlowProps) => {
|
||||||
const nodeTypesParsed = useMemo(() => createNodeTypes(nodeTypes), []);
|
const nodeTypesParsed = useMemo(() => createNodeTypes(nodeTypes), []);
|
||||||
const edgeTypesParsed = useMemo(() => createEdgeTypes(edgeTypes), []);
|
const edgeTypesParsed = useMemo(() => createEdgeTypes(edgeTypes), []);
|
||||||
|
const reactFlowClasses = cc(['react-flow', className]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={style} className={cx('react-flow', className)}>
|
<div style={style} className={reactFlowClasses}>
|
||||||
<Wrapper>
|
<Wrapper>
|
||||||
<GraphView
|
<GraphView
|
||||||
onLoad={onLoad}
|
onLoad={onLoad}
|
||||||
|
|||||||
Reference in New Issue
Block a user