/* eslint-disable react-hooks/rules-of-hooks */ import { DefaultFontFamilies, Editor, HTMLContainer, Rectangle2d, ShapeUtil, SvgExportContext, TLOnEditEndHandler, TLOnResizeHandler, TLShapeUtilFlag, TLTextShape, Vec2d, WeakMapCache, getDefaultColorTheme, stopEventPropagation, textShapeMigrations, textShapeProps, toDomPrecision, useEditor, } from '@bigbluebutton/editor' import { createTextSvgElementFromSpans } from '../shared/createTextSvgElementFromSpans' import { FONT_FAMILIES, FONT_SIZES, TEXT_PROPS } from '../shared/default-shape-constants' import { getFontDefForExport } from '../shared/defaultStyleDefs' import { resizeScaled } from '../shared/resizeScaled' import { useEditableText } from '../shared/useEditableText' const sizeCache = new WeakMapCache() /** @public */ export class TextShapeUtil extends ShapeUtil { static override type = 'text' as const static override props = textShapeProps static override migrations = textShapeMigrations getDefaultProps(): TLTextShape['props'] { return { color: 'black', size: 'm', w: 8, text: '', font: 'draw', align: 'middle', autoSize: true, scale: 1, } } getMinDimensions(shape: TLTextShape) { return sizeCache.get(shape.props, (props) => getTextSize(this.editor, props)) } getGeometry(shape: TLTextShape) { const { scale } = shape.props const { width, height } = this.getMinDimensions(shape)! return new Rectangle2d({ width: width * scale, height: height * scale, isFilled: true, }) } override canEdit = () => true override isAspectRatioLocked: TLShapeUtilFlag = () => true component(shape: TLTextShape) { const { id, type, props: { text, color }, } = shape const theme = getDefaultColorTheme({ isDarkMode: this.editor.user.getIsDarkMode() }) const { width, height } = this.getMinDimensions(shape) const { rInput, isEmpty, isEditing, handleFocus, handleChange, handleKeyDown, handleBlur, handleInputPointerDown, handleDoubleClick, } = useEditableText(id, type, text) return (
{text}
{isEditing ? (