UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

180 lines (179 loc) 3.93 kB
import { useContext } from "react"; import h from "../hyper.js"; import { NotesList } from "./note.js"; import NoteDefs from "./defs.js"; import { NoteLayoutProvider, NoteUnderlay } from "./layout.js"; import { NoteTextEditor, NoteEditorProvider, NoteEditor, NoteEditorContext } from "./editor.js"; import { NewNotePositioner } from "./new.js"; import { ColumnContext } from "../context/column.js"; function NoteComponent(props) { const { visibility, note, onClick } = props; const text = note.note; return h( "p.col-note-label", { style: { visibility }, onClick }, text ); } const CancelEditUnderlay = function() { const { setEditingNote } = useContext(NoteEditorContext); return h(NoteUnderlay, { onClick(evt) { setEditingNote(null); evt.stopPropagation(); } }); }; function EditableNotesColumn(props) { const { width, paddingLeft = 60, transform, notes, inEditMode = false, onUpdateNote, onDeleteNote, onCreateNote, noteComponent = NoteComponent, noteEditor = NoteTextEditor, allowPositionEditing = false, forceOptions, onClickNote } = props; const innerWidth = width - paddingLeft; return h( NoteLayoutProvider, { notes, width: innerWidth, paddingLeft, noteComponent, forceOptions }, [ h( NoteEditorProvider, { inEditMode, noteEditor, onCreateNote, onUpdateNote, onDeleteNote }, [ h("g.section-log", { transform, className: "focusable editable" }, [ h(NoteDefs), h(CancelEditUnderlay), h(NotesList, { onClickNote }), h(NewNotePositioner), h(NoteEditor, { allowPositionEditing }) ]) ] ) ] ); } function FocusableNoteColumn(props) { const { width, paddingLeft = 60, transform, notes, forceOptions, noteComponent = NoteComponent, focusedNoteComponent = NoteComponent, deltaConnectorAttachment, onClickNote } = props; const innerWidth = width - paddingLeft; return h( NoteLayoutProvider, { notes, width: innerWidth, paddingLeft, noteComponent, forceOptions }, [ h( NoteEditorProvider, { inEditMode: true, noteEditor: focusedNoteComponent }, [ h("g.section-log", { transform, className: "focusable" }, [ h(NoteDefs), h(CancelEditUnderlay), h(NotesList, { onClickNote, deltaConnectorAttachment }), h(NoteEditor, { allowPositionEditing: false }) ]) ] ) ] ); } function StaticNotesColumn(props) { const { width, paddingLeft = 60, transform, notes, noteComponent = NoteComponent, deltaConnectorAttachment, onClickNote, forceOptions, children } = props; const innerWidth = width - paddingLeft; return h( NoteLayoutProvider, { notes, width: innerWidth, paddingLeft, noteComponent, forceOptions }, [ h("g.section-log", { transform }, [ h(NoteDefs), h(NotesList, { deltaConnectorAttachment, onClickNote }), children ]) ] ); } function NotesColumn(props) { const { editable = false, ...rest } = props; const ctx = useContext(ColumnContext); if (ctx?.scaleClamped == null) return null; let c = StaticNotesColumn; if (editable) { c = EditableNotesColumn; } else if (rest.focusedNoteComponent != null) { c = FocusableNoteColumn; } return h(c, rest); } export { NoteComponent, NoteEditor, NoteEditorContext, NoteTextEditor, NotesColumn, StaticNotesColumn }; //# sourceMappingURL=index.js.map