@macrostrat/column-components
Version:
React rendering primitives for stratigraphic columns
113 lines (103 loc) • 4.98 kB
JavaScript
import $f5b828bbb980a05d$export$2e2bcd8739ae039 from "./column-components.de2f942b.js";
import {useNoteLayout as $00c4b971e86fe1d8$export$77b5a6d4f65baae} from "./column-components.fea107a9.js";
import {NoteEditorContext as $788eb3ac0fd4a0dc$export$cbc16735c48a2e0f} from "./column-components.69f8f6d2.js";
import {NoteConnector as $dd4ef284e468ce5f$export$a05ee380fe56e446, NotePositioner as $dd4ef284e468ce5f$export$ae56508882661985} from "./column-components.97c1913a.js";
import {useColumn as $1dQzA$useColumn} from "./column-components.0ccab336.js";
import {useMemo as $1dQzA$useMemo, useRef as $1dQzA$useRef, useEffect as $1dQzA$useEffect, useContext as $1dQzA$useContext} from "react";
function $d5159dd74a2bc947$export$53e4fd4e0e3d986(props) {
let { onClickNote: onClickNote, ...rest } = props;
const { notes: notes, nodes: nodeIndex, updateHeight: updateHeight, noteComponent: noteComponent, scale: scale } = (0, $00c4b971e86fe1d8$export$77b5a6d4f65baae)();
const { pixelHeight: columnHeight } = (0, $1dQzA$useColumn)();
const notesInfo = (0, $1dQzA$useMemo)(()=>{
let notes1 = notes.map((note)=>{
const node = nodeIndex[note.id];
const pixelHeight = node?.width ?? 10;
const pixelOffset = node?.currentPos ?? scale(note.top_height);
return {
note: note,
node: node,
pixelOffset: pixelOffset,
pixelHeight: pixelHeight,
spacing: {
above: pixelOffset - pixelHeight,
below: columnHeight - pixelOffset
}
};
});
// Adjust spacing to account for nearby nodes
for(let i = 0; i < notes1.length; i++){
const { spacing: spacing, pixelOffset: pixelOffset } = notes1[i];
if (i > 0) {
const prevNote = notes1[i - 1];
// Get distance from the previous note's bottom
// to the current note's top
spacing.above = pixelOffset - prevNote.pixelOffset - prevNote.pixelHeight;
prevNote.spacing.below = spacing.above;
}
}
return notes1;
}, [
notes,
nodeIndex,
scale
]);
return (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)("g.notes-list", notesInfo.map(({ note: note, pixelOffset: pixelOffset, pixelHeight: pixelHeight, spacing: spacing })=>{
// If the note has a bad pixelOffset, skip it
if (pixelOffset == null || pixelHeight == null) return null;
return (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)($d5159dd74a2bc947$var$Note, {
key: note.id,
note: note,
pixelOffset: pixelOffset,
pixelHeight: pixelHeight,
updateHeight: updateHeight,
onClick: onClickNote,
noteBodyComponent: noteComponent,
spacing: spacing,
...rest
});
}));
}
function $d5159dd74a2bc947$var$Note(props) {
const { note: note, pixelOffset: pixelOffset, pixelHeight: pixelHeight, updateHeight: updateHeight, deltaConnectorAttachment: deltaConnectorAttachment, noteBodyComponent: noteBodyComponent, spacing: spacing, onClick: onClick } = props;
const ref = (0, $1dQzA$useRef)(null);
(0, $1dQzA$useEffect)(()=>{
if (ref.current) {
const newHeight = ref.current.offsetHeight;
if (newHeight !== pixelHeight) updateHeight(note.id, newHeight);
}
}, [
note,
pixelHeight,
updateHeight
]);
const offsetY = pixelOffset;
const noteHeight = pixelHeight;
const { setEditingNote: setEditingNote, editingNote: editingNote } = (0, $1dQzA$useContext)((0, $788eb3ac0fd4a0dc$export$cbc16735c48a2e0f));
const onClick_ = onClick ?? setEditingNote;
const _onClickHandler = (0, $1dQzA$useMemo)(()=>{
if (!onClick_) return undefined;
return (evt)=>{
onClick_(note);
};
}, [
onClick_
]);
if (editingNote === note) return null;
return (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)("g.note", [
(0, $f5b828bbb980a05d$export$2e2bcd8739ae039)((0, $dd4ef284e468ce5f$export$a05ee380fe56e446), {
note: note,
deltaConnectorAttachment: deltaConnectorAttachment
}),
(0, $f5b828bbb980a05d$export$2e2bcd8739ae039)((0, $dd4ef284e468ce5f$export$ae56508882661985), {
offsetY: offsetY,
noteHeight: noteHeight,
ref: ref,
onClick: _onClickHandler
}, (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)(noteBodyComponent, {
note: note,
spacing: spacing
}))
]);
}
export {$d5159dd74a2bc947$export$53e4fd4e0e3d986 as NotesList, $dd4ef284e468ce5f$export$ae56508882661985 as NotePositioner, $dd4ef284e468ce5f$export$a05ee380fe56e446 as NoteConnector};
//# sourceMappingURL=column-components.d201ed99.js.map