UNPKG

@joint/react

Version:

React bindings and hooks for JointJS to build interactive diagrams and graphs.

3 lines (2 loc) 1.13 kB
import{util as V,V as g}from"@joint/core";import{forwardRef as N,useEffect as G}from"react";import{useCombinedRef as R}from"../../hooks/use-combined-ref";import{isNumber as S}from"../../utils/is";import{useCellId as k,useGraph as A}from"../../hooks";import{jsx as z}from"react/jsx-runtime";function C(b,y){const{children:o,eol:s,x:n,textVerticalAnchor:d,lineHeight:l,textPath:x,annotations:a,includeAnnotationIndices:p,displayEmpty:m,width:f,height:c,textWrap:t,...w}=b,r=R(y),u=k(),h=A();return G(()=>{if(!r.current)return;if(typeof o!="string")throw new TypeError("TextNode children must be a string");let i=o;if(t){let e=f;if(S(e))e=Math.max(0,e);else if(e==null){const T=h.getCell(u);if(!T.isElement())throw new TypeError("TextNode must be used inside a MeasuredNode");e=T.size().width}const E=typeof t=="object"?t:{};i=V.breakText(i,{width:e,height:c},{},E)}g(r.current).text(i,{textVerticalAnchor:d,lineHeight:l,annotations:a,displayEmpty:m,eol:s,includeAnnotationIndices:p,textPath:x,x:n})},[a,o,m,s,c,p,t,l,x,r,d,f,n,h,u]),z("text",{ref:r,...w,x:n})}const M=N(C);export{M as TextNode}; //# sourceMappingURL=text-node.js.map