UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

107 lines (98 loc) 4.77 kB
import $f5b828bbb980a05d$export$2e2bcd8739ae039 from "./hyper.1919039d.js"; import {NoteLayoutContext as $00c4b971e86fe1d8$export$20c7bffdb69233c9} from "./layout.4f2206ef.js"; import {NoteEditorContext as $788eb3ac0fd4a0dc$export$cbc16735c48a2e0f} from "./editor.72e577d2.js"; import {NoteConnector as $dd4ef284e468ce5f$export$a05ee380fe56e446, NotePositioner as $dd4ef284e468ce5f$export$ae56508882661985} from "./connector.97c7f22d.js"; import {useContext as $1dQzA$useContext, forwardRef as $1dQzA$forwardRef, createRef as $1dQzA$createRef, Component as $1dQzA$Component} from "react"; const $d5159dd74a2bc947$var$NoteBody = function(props) { const { note: note } = props; const { setEditingNote: setEditingNote, editingNote: editingNote } = (0, $1dQzA$useContext)((0, $788eb3ac0fd4a0dc$export$cbc16735c48a2e0f)); const { noteComponent: noteComponent } = (0, $1dQzA$useContext)((0, $00c4b971e86fe1d8$export$20c7bffdb69233c9)); const isEditing = editingNote === note; const onClick = ()=>setEditingNote(note); const visibility = isEditing ? "hidden" : "inherit"; return (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)(noteComponent, { visibility: visibility, note: note, onClick: onClick }); }; const $d5159dd74a2bc947$var$NoteMain = (0, $1dQzA$forwardRef)(function(props, ref) { const { note: note, offsetY: offsetY, noteHeight: noteHeight } = props; const { editingNote: editingNote } = (0, $1dQzA$useContext)((0, $788eb3ac0fd4a0dc$export$cbc16735c48a2e0f)); if (editingNote === note) return null; return (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)("g.note", [ (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)((0, $dd4ef284e468ce5f$export$a05ee380fe56e446), { note: note }), (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)((0, $dd4ef284e468ce5f$export$ae56508882661985), { offsetY: offsetY, noteHeight: noteHeight, ref: ref }, [ (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)($d5159dd74a2bc947$var$NoteBody, { note: note }) ]) ]); }); class $d5159dd74a2bc947$export$6c88bf799aca3d2b extends (0, $1dQzA$Component) { static{ this.contextType = (0, $00c4b971e86fe1d8$export$20c7bffdb69233c9); } constructor(props){ super(props); this.updateHeight = this.updateHeight.bind(this); this.componentDidMount = this.componentDidMount.bind(this); this.componentDidUpdate = this.componentDidUpdate.bind(this); this.element = (0, $1dQzA$createRef)(); this.state = { height: null }; } render() { const { style: style, note: note, editHandler: editHandler, editable: editable } = this.props; const { scale: scale, nodes: nodes, columnIndex: columnIndex, width: width, paddingLeft: paddingLeft } = this.context; const node = nodes[note.id]; let offsetY = scale(note.height); if (node != null) offsetY = node.currentPos; const noteHeight = this.state.height || 0; return (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)($d5159dd74a2bc947$var$NoteMain, { offsetY: offsetY, note: note, noteHeight: noteHeight, ref: this.element }); } updateHeight(prevProps) { const node = this.element.current; if (node == null) return; const height = node.offsetHeight; if (height == null) return; if (prevProps != null && prevProps.note === this.props.note) return; this.setState({ height: height }); return this.context.registerHeight(this.props.note.id, height); } componentDidMount() { return this.updateHeight.apply(this, arguments); } componentDidUpdate() { return this.updateHeight.apply(this, arguments); } } const $d5159dd74a2bc947$export$53e4fd4e0e3d986 = function(props) { let { inEditMode: editable, ...rest } = props; if (editable == null) editable = false; const { notes: notes } = (0, $1dQzA$useContext)((0, $00c4b971e86fe1d8$export$20c7bffdb69233c9)); return (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)("g", notes.map((note)=>{ return (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)($d5159dd74a2bc947$export$6c88bf799aca3d2b, { key: note.id, note: note, editable: editable, ...rest }); })); }; export {$d5159dd74a2bc947$export$6c88bf799aca3d2b as Note, $d5159dd74a2bc947$export$53e4fd4e0e3d986 as NotesList, $dd4ef284e468ce5f$export$ae56508882661985 as NotePositioner, $dd4ef284e468ce5f$export$a05ee380fe56e446 as NoteConnector}; //# sourceMappingURL=note.a33dfc43.js.map