@macrostrat/column-components
Version:
React rendering primitives for stratigraphic columns
3 lines (2 loc) • 4.66 kB
JavaScript
import"./column-components.298cc9f3.js";import"./column-components.746beab7.js";import"./column-components.511bed71.js";import"./column-components.df0ea532.js";import"./column-components.0f346a0e.js";import"./column-components.8ae02d44.js";import{createContext as e,useContext as t,useState as o}from"react";import{EditableText as n}from"@blueprintjs/core";import l from"classnames";import i from"react-draggable";import{ErrorBoundary as r}from"@macrostrat/ui-components";var a=globalThis,d={},s={},u=a.parcelRequirea149;null==u&&((u=function(e){if(e in d)return d[e].exports;if(e in s){var t=s[e];delete s[e];var o={id:e,exports:{}};return d[e]=o,t.call(o.exports,o,o.exports),o.exports}var n=Error("Cannot find module '"+e+"'");throw n.code="MODULE_NOT_FOUND",n}).register=function(e,t){s[e]=t},a.parcelRequirea149=u),u.register;var f=u("aVUB5"),c=u("4bJ9d"),h=u("fwzVu"),m=u("dl5CL"),p=u("7LSYr"),g=u("7j1lu");let N=e({inEditMode:!1}),b=function(e){let{updateModel:t}=(0,f.useModelEditor)(),{note:o}=e;return(0,c.default)(n,{multiline:!0,className:"col-note-label note-editing",defaultValue:o.note,isEditing:!0,onConfirm:e=>t({note:{$set:e}})})};function E(e){let{children:n,inEditMode:l=!1,noteEditor:i}=e,{notes:r}=t(m.NoteLayoutContext),[a,d]=o(null),s=function(){return d(null),e.onDeleteNote(a)};return(0,c.default)(N.Provider,{value:{editingNote:a,setEditingNote:d,deleteNote:s,inEditMode:l,noteEditor:i,onCreateNote:function(e){let{height:t,top_height:o}=e;return d({height:t,top_height:o,note:null,symbol:null})}}},[(0,c.default)(f.ModelEditorProvider,{model:a,onDelete:s,onConfirmChanges:function(t){return t?.note==null&&t==a?void console.log("No changes to note"):r.includes(t)?void 0:e.onUpdateNote(t)},logUpdates:!0,alwaysConfirm:!0},n)])}let x=function(e){let{d:t,offsetX:o,className:n}=e;return(0,c.default)("path",{d:t,className:n,transform:`translate(${o})`,fill:"transparent"})},y=function(e){let{notes:o,nodes:n,columnIndex:l,generatePath:i,createNodeForNote:r}=t(m.NoteLayoutContext),{note:a,node:d,index:s}=e;null!=a.id&&(d=n[a.id]),null==d&&(d=r(a));let u=5*l[a.id]||0,f=i(d,u);return(0,c.default)([(0,c.default)(x,{className:"note-connector",d:f,offsetX:u}),(0,c.default)(h.ForeignObject,{width:30,x:u,y:0,height:1,style:{overflowY:"visible"}},(0,c.default)(_,{note:a}))])},v=function(e){let{height:t,size:o,className:n,...r}=e;return n=l("handle point-handle",n),null==o&&(o=10),(0,c.default)(i,{position:{x:0,y:t},axis:"y",...r},(0,c.default)("div.handle",{style:{height:o,width:o,marginLeft:-o/2,marginTop:-o/2,position:"absolute"},className:n}))};function _(e){let o,{note:n,margin:a}=e;null==a&&(a=3);let{scaleClamped:d}=t(f.ColumnContext);if({updateModel:o,editedModel:n}=(0,f.useModelEditor)(),null==n)return null;let s=(0,g.hasSpan)(n),u=d(n.height),h=u,m=0;return s&&(m=Math.abs((h=d(n.top_height))-u)),(0,c.default)(r,null,(0,c.default)("div.position-editor",[(0,c.default)(i,{handle:".handle",position:{x:0,y:h},onDrag:function(e,t){let{y:n}=t,l={height:{$set:d.invert(n+m)}};return s&&(l.top_height={$set:d.invert(n)}),o(l)},axis:"y"},(0,c.default)("div",[(0,c.default)("div.handle",{className:"handle",style:{height:m,width:2*a,marginLeft:-a,marginTop:-a,position:"absolute"}})])),(0,c.default)(v,{height:s?h:h-15,onDrag:function(e,t){let n={top_height:{$set:d.invert(t.y)}};return 2>Math.abs(t.y-u)&&(n.top_height={$set:null}),o(n)},className:l("top-handle",{"add-span-handle":!s}),bounds:{bottom:u}}),(0,c.default)(v,{height:u,onDrag:function(e,t){let n={height:{$set:d.invert(t.y)}};return 2>Math.abs(t.y-h)&&(n.top_height={$set:null}),o(n)},className:"bottom-handle",bounds:s?{top:h}:null})]))}let $=function({padding:e}){let{width:o}=t(m.NoteLayoutContext),{setEditingNote:n}=t(N);return(0,c.default)(m.NoteRect,{fill:"rgba(255,255,255,0.8)",style:{pointerEvents:"none"},className:"underlay"})},C=function(e){let{allowPositionEditing:o}=e,{noteEditor:n}=t(N),{notes:l,nodes:i,elementHeights:a,createNodeForNote:d}=t(m.NoteLayoutContext),{editedModel:s}=(0,f.useModelEditor)();if(null==s)return null;let u=l.indexOf(s),{id:h}=s,g=i[h]||d(s),b=a[h]||20;if(null!=s.height){let e=d(s);e.currentPos=g.currentPos;let t=e.centerPos||e.idealPos,o=t-g.currentPos;o>50&&(e.currentPos=t-50),o<-50&&(e.currentPos=t+50),g=e}return(0,c.default)(r,[(0,c.default)("g.note-editor.note",[(0,c.default)($),c.default.if(!o)(p.NoteConnector,{note:s}),c.default.if(o)(y,{note:s,node:g}),(0,c.default)(p.NotePositioner,{offsetY:g.currentPos,noteHeight:b},[(0,c.default)(n,{note:s,key:u})])])])};export{N as NoteEditorContext,b as NoteTextEditor,E as NoteEditorProvider,C as NoteEditor};
//# sourceMappingURL=column-components.ce0796ca.js.map