UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

71 lines (70 loc) 2.02 kB
"use strict"; Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" }); const React = require("react"); const hyper = require("../hyper.cjs"); const layout = require("./layout.cjs"); const heightRange = require("./height-range.cjs"); const index = require("../util/index.cjs"); const NotePositioner = React.forwardRef(function(props, ref) { let { offsetY, noteHeight, onClick, children } = props; const { width, paddingLeft } = React.useContext(layout.NoteLayoutContext); if (noteHeight == null) { noteHeight = 0; } const outerPad = 5; let y = offsetY - noteHeight / 2 - outerPad; return hyper( index.ForeignObject, { width: width - paddingLeft + 2 * outerPad, x: paddingLeft - outerPad, y, height: noteHeight + 2 * outerPad, overflow: "visible", style: { overflowY: "visible" } }, [ hyper( "div.note-inner", { ref, onClick }, children ) ] ); }); const findIndex = function(note) { const { notes } = React.useContext(layout.NoteLayoutContext); return notes.indexOf(note); }; const NoteConnector = function(props) { let { note, node, deltaConnectorAttachment, index: index2 } = props; if (index2 == null) { index2 = findIndex(note); } const { nodes, columnIndex, generatePath } = React.useContext(layout.NoteLayoutContext); const { height, top_height } = note; if (node == null) { node = nodes[note.id]; } if (node != null && deltaConnectorAttachment != null) { node.currentPos += deltaConnectorAttachment; } const offsetX = (columnIndex[index2] || 0) * 5; return hyper([ hyper(heightRange.HeightRangeAnnotation, { offsetX, height, top_height }), hyper("path.link.col-note-link", { d: generatePath(node, offsetX), transform: `translate(${offsetX})` }) ]); }; exports.NoteConnector = NoteConnector; exports.NotePositioner = NotePositioner; //# sourceMappingURL=connector.cjs.map