@macrostrat/column-components
Version:
React rendering primitives for stratigraphic columns
180 lines (179 loc) • 4.27 kB
JavaScript
"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const React = require("react");
const hyper = require("../hyper.cjs");
const note = require("./note.cjs");
const defs = require("./defs.cjs");
const layout = require("./layout.cjs");
const editor = require("./editor.cjs");
const _new = require("./new.cjs");
const column = require("../context/column.cjs");
function NoteComponent(props) {
const { visibility, note: note2, onClick } = props;
const text = note2.note;
return hyper(
"p.col-note-label",
{
style: { visibility },
onClick
},
text
);
}
const CancelEditUnderlay = function() {
const { setEditingNote } = React.useContext(editor.NoteEditorContext);
return hyper(layout.NoteUnderlay, {
onClick(evt) {
setEditingNote(null);
evt.stopPropagation();
}
});
};
function EditableNotesColumn(props) {
const {
width,
paddingLeft = 60,
transform,
notes,
inEditMode = false,
onUpdateNote,
onDeleteNote,
onCreateNote,
noteComponent = NoteComponent,
noteEditor = editor.NoteTextEditor,
allowPositionEditing = false,
forceOptions,
onClickNote
} = props;
const innerWidth = width - paddingLeft;
return hyper(
layout.NoteLayoutProvider,
{
notes,
width: innerWidth,
paddingLeft,
noteComponent,
forceOptions
},
[
hyper(
editor.NoteEditorProvider,
{
inEditMode,
noteEditor,
onCreateNote,
onUpdateNote,
onDeleteNote
},
[
hyper("g.section-log", { transform, className: "focusable editable" }, [
hyper(defs),
hyper(CancelEditUnderlay),
hyper(note.NotesList, {
onClickNote
}),
hyper(_new.NewNotePositioner),
hyper(editor.NoteEditor, { allowPositionEditing })
])
]
)
]
);
}
function FocusableNoteColumn(props) {
const {
width,
paddingLeft = 60,
transform,
notes,
forceOptions,
noteComponent = NoteComponent,
focusedNoteComponent = NoteComponent,
deltaConnectorAttachment,
onClickNote
} = props;
const innerWidth = width - paddingLeft;
return hyper(
layout.NoteLayoutProvider,
{
notes,
width: innerWidth,
paddingLeft,
noteComponent,
forceOptions
},
[
hyper(
editor.NoteEditorProvider,
{
inEditMode: true,
noteEditor: focusedNoteComponent
},
[
hyper("g.section-log", { transform, className: "focusable" }, [
hyper(defs),
hyper(CancelEditUnderlay),
hyper(note.NotesList, {
onClickNote,
deltaConnectorAttachment
}),
hyper(editor.NoteEditor, { allowPositionEditing: false })
])
]
)
]
);
}
function StaticNotesColumn(props) {
const {
width,
paddingLeft = 60,
transform,
notes,
noteComponent = NoteComponent,
deltaConnectorAttachment,
onClickNote,
forceOptions,
children
} = props;
const innerWidth = width - paddingLeft;
return hyper(
layout.NoteLayoutProvider,
{
notes,
width: innerWidth,
paddingLeft,
noteComponent,
forceOptions
},
[
hyper("g.section-log", { transform }, [
hyper(defs),
hyper(note.NotesList, {
deltaConnectorAttachment,
onClickNote
}),
children
])
]
);
}
function NotesColumn(props) {
const { editable = false, ...rest } = props;
const ctx = React.useContext(column.ColumnContext);
if (ctx?.scaleClamped == null) return null;
let c = StaticNotesColumn;
if (editable) {
c = EditableNotesColumn;
} else if (rest.focusedNoteComponent != null) {
c = FocusableNoteColumn;
}
return hyper(c, rest);
}
exports.NoteEditor = editor.NoteEditor;
exports.NoteEditorContext = editor.NoteEditorContext;
exports.NoteTextEditor = editor.NoteTextEditor;
exports.NoteComponent = NoteComponent;
exports.NotesColumn = NotesColumn;
exports.StaticNotesColumn = StaticNotesColumn;
//# sourceMappingURL=index.cjs.map