UNPKG

@macrostrat/column-components

Version:

React rendering primitives for stratigraphic columns

3 lines (2 loc) 4.66 kB
import"./column-components.b2a20dc1.js";import"./column-components.c66242f5.js";import"./column-components.e7f1a130.js";import"./column-components.a60d0bb9.js";import"./column-components.f57c6dd5.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"})},v=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}))])},y=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)(y,{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)(y,{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})]))}function $(){return(0,c.default)(m.NoteRect,{style:{pointerEvents:"none"},className:"underlay"})}function C(e){let{allowPositionEditing:o}=e,{noteEditor:n,setEditingNote:l}=t(N),{notes:i,nodes:a,elementHeights:d,createNodeForNote:s}=t(m.NoteLayoutContext),{editedModel:u,model:h}=(0,f.useModelEditor)();if(null==u)return null;let g=i.indexOf(u),{id:b}=u,E=a[b]||s(u),x=d[b]||20;if(null!=u.height){let e=s(u);e.currentPos=E.currentPos;let t=e.centerPos||e.idealPos,o=t-E.currentPos;o>50&&(e.currentPos=t-50),o<-50&&(e.currentPos=t+50),E=e}let y=u===h;return(0,c.default)(r,[(0,c.default)("g.note-editor.note",[(0,c.default)($),c.default.if(!o)(p.NoteConnector,{note:u}),c.default.if(o)(v,{note:u,node:E}),(0,c.default)(p.NotePositioner,{offsetY:E.currentPos,noteHeight:x,onClick(e){y&&(l(null),e.stopPropagation())}},[(0,c.default)(n,{note:u,key:g,focused:!0,edited:y})])])])}export{N as NoteEditorContext,b as NoteTextEditor,E as NoteEditorProvider,C as NoteEditor}; //# sourceMappingURL=column-components.c077d708.js.map