feat(react): ssr

This commit is contained in:
moklick
2023-10-05 17:28:05 +02:00
parent f37a2d9a19
commit 1acc59e44c
10 changed files with 90 additions and 22 deletions
@@ -52,6 +52,8 @@ export default (NodeComponent: ComponentType<NodeProps>) => {
disableKeyboardA11y,
ariaLabel,
rfId,
dimensionWidth,
dimensionHeight,
}: WrapNodeProps) => {
const store = useStoreApi();
const nodeRef = useRef<HTMLDivElement>(null);
@@ -181,7 +183,9 @@ export default (NodeComponent: ComponentType<NodeProps>) => {
zIndex,
transform: `translate(${xPosOrigin}px,${yPosOrigin}px)`,
pointerEvents: hasPointerEvents ? 'all' : 'none',
visibility: initialized ? 'visible' : 'visible',
visibility: initialized ? 'visible' : 'hidden',
width: dimensionWidth,
height: dimensionHeight,
...style,
}}
data-id={id}
@@ -6,11 +6,23 @@ import { Provider } from '../../contexts/RFStoreContext';
import { createRFStore } from '../../store';
import type { ReactFlowState, Node, Edge } from '../../types';
function ReactFlowProvider({ children, nodes, edges }: { children: ReactNode; nodes?: Node[]; edges?: Edge[] }) {
function ReactFlowProvider({
children,
nodes,
edges,
width,
height,
}: {
children: ReactNode;
nodes?: Node[];
edges?: Edge[];
width?: number;
height?: number;
}) {
const storeRef = useRef<UseBoundStoreWithEqualityFn<StoreApi<ReactFlowState>> | null>(null);
if (!storeRef.current) {
storeRef.current = createRFStore({ nodes, edges });
storeRef.current = createRFStore({ nodes, edges, width, height });
}
return <Provider value={storeRef.current}>{children}</Provider>;