@macrostrat/column-components
Version:
React rendering primitives for stratigraphic columns
102 lines (92 loc) • 4.28 kB
JavaScript
import $f5b828bbb980a05d$export$2e2bcd8739ae039 from "./column-components.e1d11b63.js";
import {NoteLayoutContext as $00c4b971e86fe1d8$export$20c7bffdb69233c9, NoteRect as $00c4b971e86fe1d8$export$b74b5a117fd60a1d} from "./column-components.2a78b581.js";
import {ModelEditorContext as $OuF28$ModelEditorContext} from "./column-components.fa405a9f.js";
import {NoteEditorContext as $788eb3ac0fd4a0dc$export$cbc16735c48a2e0f} from "./column-components.2126e2f4.js";
import {HeightRangeAnnotation as $dfac63f354e170ff$export$664019b81938583} from "./column-components.f9292ad0.js";
import $d674d3f092d90ef7$export$2e2bcd8739ae039 from "./column-components.f725b2e5.js";
import {useContext as $OuF28$useContext, useState as $OuF28$useState} from "react";
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const $97f1c9639f0dd9c0$var$getHeights = function(position, tolerance = 0.1) {
let { startHeight: startHeight, dragHeight: dragHeight, ...rest } = position;
if (dragHeight == null) dragHeight = startHeight;
let rng = [
startHeight,
dragHeight
];
rng.sort();
let [height, top_height] = rng;
if (top_height - height < tolerance) top_height = null;
return {
height: height,
top_height: top_height,
...rest
};
};
const $97f1c9639f0dd9c0$var$HeightRange = function(props) {
let { position: position, tolerance: tolerance } = props;
if (!position) return null;
if (tolerance == null) tolerance = 0.1;
const val = $97f1c9639f0dd9c0$var$getHeights(position, tolerance);
return (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)((0, $dfac63f354e170ff$export$664019b81938583), val);
};
const $97f1c9639f0dd9c0$export$b6af173e35939b8f = function(props) {
const { paddingLeft: paddingLeft, scale: scale } = (0, $OuF28$useContext)((0, $00c4b971e86fe1d8$export$20c7bffdb69233c9));
const { onCreateNote: onCreateNote } = (0, $OuF28$useContext)((0, $788eb3ac0fd4a0dc$export$cbc16735c48a2e0f));
if (onCreateNote == null) return null;
const { tolerance: tolerance } = props;
const [notePosition, setPosition] = (0, $OuF28$useState)(null);
const { model: model } = (0, $OuF28$useContext)((0, $OuF28$ModelEditorContext));
if (model != null) return null;
const eventHeight = (evt)=>scale.invert(evt.nativeEvent.offsetY);
return (0, $f5b828bbb980a05d$export$2e2bcd8739ae039)("g.new-note", [
(0, $f5b828bbb980a05d$export$2e2bcd8739ae039)((0, $d674d3f092d90ef7$export$2e2bcd8739ae039), {
fill: "dodgerblue",
size: 4,
prefix: "new_"
}),
(0, $f5b828bbb980a05d$export$2e2bcd8739ae039)((0, $00c4b971e86fe1d8$export$b74b5a117fd60a1d), {
width: paddingLeft,
fill: "transparent",
padding: 0,
style: {
cursor: "drag"
},
onMouseDown (evt) {
if (notePosition != null) return;
return setPosition({
startHeight: eventHeight(evt),
offsetX: evt.nativeEvent.offsetX
});
},
onMouseMove (evt) {
if (notePosition == null) return;
return setPosition({
...notePosition,
dragHeight: eventHeight(evt)
});
},
onMouseUp (evt) {
const dragHeight = eventHeight(evt);
const finalPos = $97f1c9639f0dd9c0$var$getHeights({
...notePosition,
dragHeight: dragHeight
});
setPosition(null);
return onCreateNote(finalPos);
}
}),
(0, $f5b828bbb980a05d$export$2e2bcd8739ae039)($97f1c9639f0dd9c0$var$HeightRange, {
position: notePosition
})
]);
};
$97f1c9639f0dd9c0$export$b6af173e35939b8f.defaultProps = {
tolerance: 0.1
};
export {$97f1c9639f0dd9c0$export$b6af173e35939b8f as NewNotePositioner};
//# sourceMappingURL=column-components.d72701d4.js.map