{"version":3,"file":"cell-visibility.cjs","sources":["../../../src/presets/cell-visibility.ts"],"sourcesContent":["import type { dia } from '@joint/core';\n\n/**\n * Context handed to a {@link CellVisibility} callback each time the paper decides\n * whether to render a cell.\n * @group Types\n * @expand\n */\nexport interface CellVisibilityParams {\n  /** The cell whose visibility is being decided. */\n  readonly model: dia.Cell;\n  /** Whether the cell currently has a view mounted in the paper. */\n  readonly isMounted: boolean;\n  /** The paper rendering the cell. */\n  readonly paper: dia.Paper;\n  /** The graph the cell belongs to. */\n  readonly graph: dia.Graph;\n}\n\n/**\n * Decides whether a cell is rendered on the paper. Return `false` to skip\n * rendering it (handy for viewport culling or hiding cells by state), `true` to\n * render it. Pass it to the `cellVisibility` prop of `<Paper>`; the callback\n * receives a structured {@link CellVisibilityParams} context instead of the\n * native positional arguments.\n * @group Types\n * @example\n * ```tsx\n * import { GraphProvider, Paper } from '@joint/react';\n * import type { CellVisibility } from '@joint/react';\n *\n * // Hide every cell flagged as collapsed.\n * const cellVisibility: CellVisibility = ({ model }) => !model.get('collapsed');\n *\n * <GraphProvider>\n *   <Paper cellVisibility={cellVisibility} renderElement={() => <rect width={80} height={40} />} />\n * </GraphProvider>;\n * ```\n */\nexport type CellVisibility = (context: CellVisibilityParams) => boolean;\n\n/**\n * Adapt a context-form {@link CellVisibility} callback to the native\n * `dia.Paper.Options['cellVisibility']` signature\n * `(this: paper, model, isMounted) => boolean`.\n * @param cb - user-supplied context-form predicate\n * @returns native predicate, or `undefined` when no callback supplied\n */\nexport function toNativeCellVisibility(\n  cb: CellVisibility | undefined\n): dia.Paper.Options['cellVisibility'] {\n  if (!cb) return undefined;\n  return function (this: dia.Paper, model: dia.Cell, isMounted: boolean) {\n    return cb({ model, isMounted, paper: this, graph: this.model });\n  };\n}\n"],"names":[],"mappings":";;;;;;;;;AAgDO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAS,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EACd,CAAA,CAAA,CAAA,CACqC,CAAA;AACrC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAI,CAAC,CAAA,GAAI,OAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA;AAChB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAA2B,CAAA,CAAA,CAAA,CAAA,GAAiB,SAAA,CAAA,CAAoB,CAAA;AACrE,CAAA,CAAA,CAAA,CAAA,OAAO,CAAA,CAAA,CAAG,EAAE,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,SAAA,CAAA,CAAW,CAAA,CAAA,CAAA,CAAA,GAAO,CAAA,CAAA,CAAA,CAAA,EAAM,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAO,IAAA,CAAK,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,CAAA,CAAA;AAAA,CAAA,CAChE,CAAA,CAAA;AACF,CAAA;;"}