From ac06e2affd615b926e240a2b15279d3c60360bd4 Mon Sep 17 00:00:00 2001 From: bobzel Date: Thu, 25 Jul 2024 10:52:55 -0400 Subject: cleaned up labelBox --- .../collections/CollectionStackedTimeline.tsx | 2 +- src/client/views/nodes/LabelBox.tsx | 58 ++++++++++------------ 2 files changed, 27 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/CollectionStackedTimeline.tsx b/src/client/views/collections/CollectionStackedTimeline.tsx index fac885300..b03f0cffa 100644 --- a/src/client/views/collections/CollectionStackedTimeline.tsx +++ b/src/client/views/collections/CollectionStackedTimeline.tsx @@ -850,7 +850,7 @@ class StackedTimelineAnchor extends ObservableReactComponent() { public static LayoutString(fieldKey: string) { return FieldView.LayoutString(LabelBox, fieldKey); } - public static LayoutStringWithTitle(fieldStr: string, label?: string) { - return !label ? LabelBox.LayoutString(fieldStr) : ``; // e.g., "" - } private dropDisposer?: DragManager.DragDropDisposer; private _timeout: NodeJS.Timeout | undefined; - _divRef: HTMLDivElement|null = null; + _divRef: HTMLDivElement | null = null; constructor(props: FieldViewProps) { super(props); @@ -53,8 +50,7 @@ export class LabelBox extends ViewBoxBaseComponent() { this._timeout && clearTimeout(this._timeout); } - specificContextMenu = (): void => { - }; + specificContextMenu = (): void => {}; drop = (/* e: Event, de: DragManager.DropEvent */) => { return false; @@ -73,15 +69,16 @@ export class LabelBox extends ViewBoxBaseComponent() { return anchor; }; - fitTextToBox = (r: HTMLElement | null | undefined): { - minFontSize: number, - maxFontSize: number, - multiLine: boolean, - alignHoriz: boolean, - alignVert: boolean, - detectMultiLine: boolean, - } => - { + fitTextToBox = ( + r: HTMLElement | null | undefined + ): { + minFontSize: number; + maxFontSize: number; + multiLine: boolean; + alignHoriz: boolean; + alignVert: boolean; + detectMultiLine: boolean; + } => { this._timeout && clearTimeout(this._timeout); const textfitParams = { minFontSize: NumCast(this.layoutDoc._label_minFontSize, 1), @@ -105,14 +102,9 @@ export class LabelBox extends ViewBoxBaseComponent() { render() { trace(); const boxParams = this.fitTextToBox(undefined); // this causes mobx to trigger re-render when data changes - const label = this.Title.startsWith("#") ? null : this.Title; + const label = this.Title.startsWith('#') ? null : this.Title; return ( -
+
() { height: this._props.PanelHeight(), whiteSpace: 'multiLine' in boxParams && boxParams.multiLine ? 'pre-wrap' : 'pre', }}> -
{ e.stopPropagation(); })} onKeyUp={action(e => { e.stopPropagation(); if (e.key === 'Enter') { - this.dataDoc[this.fieldKey] = this._divRef?.innerText ?? ""; + this.dataDoc[this.fieldKey] = this._divRef?.innerText ?? ''; setTimeout(() => this._props.select(false)); } })} onBlur={() => { - this.dataDoc[this.fieldKey] = this._divRef?.innerText ?? ""; + this.dataDoc[this.fieldKey] = this._divRef?.innerText ?? ''; }} - contentEditable={this._props.onClickScript?.() ? false: true} - ref={r => {this._divRef = r; + contentEditable={this._props.onClickScript?.() ? false : true} + ref={r => { + this._divRef = r; this.fitTextToBox(r); if (this._props.isSelected() && this._divRef) { const range = document.createRange(); range.setStart(this._divRef, this._divRef.childNodes.length); - range.setEnd(this._divRef, this._divRef.childNodes.length) + range.setEnd(this._divRef, this._divRef.childNodes.length); const sel = window.getSelection(); sel?.removeAllRanges(); sel?.addRange(range); -- cgit v1.2.3-70-g09d2