{"version":3,"file":"connector.cjs","sources":["../../src/notes/connector.ts"],"sourcesContent":["import { useContext, forwardRef, ReactNode } from \"react\";\nimport h from \"../hyper\";\nimport { NoteLayoutContext } from \"./layout\";\nimport { HeightRangeAnnotation } from \"./height-range\";\nimport { ForeignObject } from \"../util\";\n\ninterface NotePositionerProps {\n  offsetY: number;\n  noteHeight: number;\n  children?: ReactNode;\n  onClick?: (event: React.MouseEvent) => void;\n}\n\nconst NotePositioner = forwardRef(function (\n  props: NotePositionerProps,\n  ref: any,\n) {\n  let { offsetY, noteHeight, onClick, children } = props;\n  const { width, paddingLeft } = useContext(NoteLayoutContext);\n  if (noteHeight == null) {\n    noteHeight = 0;\n  }\n  const outerPad = 5;\n\n  let y = offsetY - noteHeight / 2 - outerPad;\n\n  return h(\n    ForeignObject,\n    {\n      width: width - paddingLeft + 2 * outerPad,\n      x: paddingLeft - outerPad,\n      y,\n      height: noteHeight + 2 * outerPad,\n      overflow: \"visible\",\n      style: { overflowY: \"visible\" },\n    },\n    [\n      h(\n        \"div.note-inner\",\n        {\n          ref,\n          onClick,\n        },\n        children,\n      ),\n    ],\n  );\n});\n\nconst findIndex = function (note) {\n  const { notes } = useContext(NoteLayoutContext);\n  return notes.indexOf(note);\n};\n\nexport interface NodeConnectorOptions {\n  deltaConnectorAttachment?: number; // Delta for connector attachment\n}\n\ntype NodeConnectorProps = NodeConnectorOptions & {\n  note: any; // Note data type\n  node?: any; // Node data type\n  index?: number; // Index of the note in the layout\n};\n\nconst NoteConnector = function (props: NodeConnectorProps) {\n  let { note, node, deltaConnectorAttachment, index } = props;\n  // Try to avoid scanning for index if we can\n  if (index == null) {\n    index = findIndex(note);\n  }\n  const { nodes, columnIndex, generatePath } = useContext(NoteLayoutContext);\n  const { height, top_height } = note;\n\n  if (node == null) {\n    node = nodes[note.id];\n  }\n\n  if (node != null && deltaConnectorAttachment != null) {\n    node.currentPos += deltaConnectorAttachment;\n  }\n\n  const offsetX = (columnIndex[index] || 0) * 5;\n\n  return h([\n    h(HeightRangeAnnotation, {\n      offsetX,\n      height,\n      top_height,\n    }),\n    h(\"path.link.col-note-link\", {\n      d: generatePath(node, offsetX),\n      transform: `translate(${offsetX})`,\n    }),\n  ]);\n};\n\nexport { NotePositioner, NoteConnector };\n"],"names":["forwardRef","useContext","NoteLayoutContext","h","ForeignObject","index","HeightRangeAnnotation"],"mappings":";;;;;;;AAaA,MAAM,iBAAiBA,MAAAA,WAAW,SAChC,OACA,KACA;AACA,MAAI,EAAE,SAAS,YAAY,SAAS,aAAa;AACjD,QAAM,EAAE,OAAO,gBAAgBC,MAAAA,WAAWC,OAAAA,iBAAiB;AAC3D,MAAI,cAAc,MAAM;AACtB,iBAAa;AAAA,EACf;AACA,QAAM,WAAW;AAEjB,MAAI,IAAI,UAAU,aAAa,IAAI;AAEnC,SAAOC;AAAAA,IACLC,MAAAA;AAAAA,IACA;AAAA,MACE,OAAO,QAAQ,cAAc,IAAI;AAAA,MACjC,GAAG,cAAc;AAAA,MACjB;AAAA,MACA,QAAQ,aAAa,IAAI;AAAA,MACzB,UAAU;AAAA,MACV,OAAO,EAAE,WAAW,UAAA;AAAA,IAAU;AAAA,IAEhC;AAAA,MACED;AAAAA,QACE;AAAA,QACA;AAAA,UACE;AAAA,UACA;AAAA,QAAA;AAAA,QAEF;AAAA,MAAA;AAAA,IACF;AAAA,EACF;AAEJ,CAAC;AAED,MAAM,YAAY,SAAU,MAAM;AAChC,QAAM,EAAE,MAAA,IAAUF,MAAAA,WAAWC,wBAAiB;AAC9C,SAAO,MAAM,QAAQ,IAAI;AAC3B;AAYA,MAAM,gBAAgB,SAAU,OAA2B;AACzD,MAAI,EAAE,MAAM,MAAM,0BAA0B,OAAAG,WAAU;AAEtD,MAAIA,UAAS,MAAM;AACjB,IAAAA,SAAQ,UAAU,IAAI;AAAA,EACxB;AACA,QAAM,EAAE,OAAO,aAAa,aAAA,IAAiBJ,MAAAA,WAAWC,OAAAA,iBAAiB;AACzE,QAAM,EAAE,QAAQ,W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