import { useTranslation } from 'next-i18next' import { Tr, KeyTd, ValTd, Attributes, pointCoords, pathInfo } from './path.mjs' const textInfo = ({ point, pointName, partName }) => point ? (
Text info
Coordinates{pointCoords(point)}Name{pointName}Part{partName}Attributes
) : null const XrayText = ({ point, pointName, partName, attr, showInfo }) => ( showInfo(evt, textInfo({ point, pointName, partName }))} /> ) const TextSpans = ({ point, className = '', style = {}, onClick = null }) => { const { t } = useTranslation(['plugin']) let text = [] // Handle translation let translated = '' for (const string of point.attributes.getAsArray('data-text')) { if (string) translated += t(string.toString()).replace(/"/g, '"') + ' ' } // Handle muti-line text if (translated.indexOf('\n') !== -1) { let key = 0 let lines = translated.split('\n') text.push({lines.shift()}) for (let line of lines) { key++ text.push( {line.toString().replace(/"/g, '"')} ) } } else text.push( {translated} ) return text } export const Text = ({ point, ui, pointName, partName, showInfo }) => { const attr = point.attributes.asPropsIfPrefixIs('data-text-') return ( <> {ui.xray?.enabled && } ) } const XrayTextOnPath = ({ pathId, path, partName, attr, translated, units, showInfo }) => ( showInfo(evt, pathInfo({ pathId, path, partName, units, showInfo }))} /> ) export const TextOnPath = ({ path, pathId, ui, showInfo }) => { const { t } = useTranslation(['plugin']) // Handle translation (and spaces) let translated = '' for (let string of path.attributes.getAsArray('data-text')) { translated += t(string).replace(/"/g, '"') + ' ' } const textPathProps = { xlinkHref: '#' + pathId, startOffset: '0%', } const align = path.attributes.get('data-text-class') if (align && align.indexOf('center') > -1) textPathProps.startOffset = '50%' else if (align && align.indexOf('right') > -1) textPathProps.startOffset = '100%' const attr = path.attributes.asPropsIfPrefixIs('data-text-') return ( {ui.xray?.enabled && ( )} ) }