import { dia, shapes } from '@joint/core'; import { ReactElement } from '../models/react-element'; import type { GraphElement } from '../types/element-types'; import type { GraphLink } from '../types/link-types'; import type { CellMap } from '../utils/cell/cell-map'; export declare const DEFAULT_CELL_NAMESPACE: { ReactElement: typeof ReactElement; standard: typeof shapes.standard; devs: typeof shapes.devs; }; export interface StoreOptions { /** * Graph instance to use. If not provided, a new graph instance will be created. * @see https://docs.jointjs.com/api/dia/Graph * @default new dia.Graph({}, { cellNamespace: shapes }) */ readonly graph?: dia.Graph; /** * Namespace for cell models. * @default shapes * @see https://docs.jointjs.com/api/shapes */ readonly cellNamespace?: unknown; /** * Custom cell model to use. * @see https://docs.jointjs.com/api/dia/Cell */ readonly cellModel?: typeof dia.Cell; /** * Initial elements to be added to graph * It's loaded just once, so it cannot be used as React state. */ readonly initialElements?: Array; /** * Initial links to be added to graph * It's loaded just once, so it cannot be used as React state. */ readonly initialLinks?: Array; } export interface Store { /** * The JointJS graph instance. */ readonly graph: dia.Graph; /** * Subscribes to the store changes. */ readonly subscribe: (onStoreChange: (changedIds?: Set) => void) => () => void; /** * Get elements */ readonly getElements: () => CellMap; /** * Get element by id */ readonly getElement: (id: dia.Cell.ID) => Element; /** * Get links */ readonly getLinks: () => CellMap; /** * Get link by id */ readonly getLink: (id: dia.Cell.ID) => GraphLink; /** * Remove all listeners and cleanup the graph. */ readonly destroy: () => void; /** * Set the measured node element. * For safety, each node, can use only one measured node, do not matter how many papers the graph is using, * only one paper and one node can use measured node, otherwise it can lead to unexpected behavior * when many nodes or same node with many measuredNodes try to adjust the size. */ readonly setMeasuredNode: (id: dia.Cell.ID) => () => void; /** * Check if the graph has already measured node for the given element id. */ readonly hasMeasuredNode: (id: dia.Cell.ID) => boolean; } /** * Building block of `@joint/react`. * It listen to cell changes and updates UI based on the `dia.graph` changes. * It use `useSyncExternalStore` to avoid memory leaks and state duplicates. * * Under the hood, @joint/react works by listening to changes in the `dia.Graph` via this store. `dia.graph` is the single source of truth. * When you update something—like adding or modifying cells—you do it directly through the `dia.Graph` API, just like in a standard JointJS app. * React components automatically observe and react to changes in the graph, keeping the UI in sync via `useSyncExternalStore` API. * Hooks like `useUpdateElement` are just convenience helpers (**syntactic sugar**) that update the graph directly behind the scenes. * You can also access the graph yourself using `useGraph()` and call methods like `graph.setCells()` or any other JointJS method as needed and react will update it accordingly. * @group Data * @internal * @param options - Options for creating the graph store. * @returns The graph store instance. * @example * ```ts * const { graph, forceUpdate, subscribe } = createStore(); * const unsubscribe = subscribe(() => { * console.log('Graph changed'); * }); * graph.addCell(new joint.shapes.standard.Rectangle()); * forceUpdate(); * unsubscribe(); * ``` */ export declare function createStore(options?: StoreOptions): Store;