(props: TextNodeProps, ref: React.ForwardedRef<SVGTextElement>)
| 15 | |
| 16 | // eslint-disable-next-line jsdoc/require-jsdoc |
| 17 | function Component(props: TextNodeProps, ref: React.ForwardedRef<SVGTextElement>) { |
| 18 | const { |
| 19 | children, |
| 20 | eol, |
| 21 | x, |
| 22 | textVerticalAnchor, |
| 23 | lineHeight, |
| 24 | textPath, |
| 25 | annotations, |
| 26 | includeAnnotationIndices, |
| 27 | displayEmpty, |
| 28 | width, |
| 29 | height, |
| 30 | textWrap, |
| 31 | ...rest |
| 32 | } = props; |
| 33 | |
| 34 | const textRef = useCombinedRef<SVGTextElement>(ref); |
| 35 | const cellId = useCellId(); |
| 36 | const graph = useGraph(); |
| 37 | useEffect(() => { |
| 38 | if (!textRef.current) { |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | if (typeof children !== 'string') { |
| 43 | throw new TypeError('TextNode children must be a string'); |
| 44 | } |
| 45 | |
| 46 | let text = children; |
| 47 | if (textWrap) { |
| 48 | let breakTextWidth = width; |
| 49 | |
| 50 | if (isNumber(breakTextWidth)) { |
| 51 | breakTextWidth = Math.max(0, breakTextWidth); |
| 52 | } else if (breakTextWidth == undefined) { |
| 53 | const element = graph.getCell(cellId); |
| 54 | if (!element.isElement()) { |
| 55 | throw new TypeError('TextNode must be used inside a MeasuredNode'); |
| 56 | } |
| 57 | breakTextWidth = element.size().width; |
| 58 | } |
| 59 | |
| 60 | const options: util.BreakTextOptions = typeof textWrap === 'object' ? textWrap : {}; |
| 61 | text = util.breakText(text, { width: breakTextWidth, height }, {}, options); |
| 62 | } |
| 63 | |
| 64 | V(textRef.current).text(text, { |
| 65 | textVerticalAnchor, |
| 66 | lineHeight, |
| 67 | annotations, |
| 68 | displayEmpty, |
| 69 | eol, |
| 70 | includeAnnotationIndices, |
| 71 | textPath, |
| 72 | x, |
| 73 | }); |
| 74 | }, [ |
nothing calls this directly
no test coverage detected