diff --git a/src/main.js b/src/main.js index ebdb7ee..01a0b11 100644 --- a/src/main.js +++ b/src/main.js @@ -1,6 +1,6 @@ import {generatePrivateKey, getPublicKey, nip19, signEvent} from 'nostr-tools'; import {zeroLeadingBitsCount} from './utils/crypto'; -import {elem, elemCanvas, elemShrink, parseTextContent} from './utils/dom'; +import {elem, elemCanvas, elemShrink, parseTextContent, updateElemHeight} from './utils/dom'; import {bounce, dateTime, formatTime} from './utils/time'; import {getHost, getNoxyUrl, isWssUrl} from './utils/url'; import {powEvent} from './system'; @@ -561,17 +561,6 @@ writeInput.addEventListener('input', () => { }); writeInput.addEventListener('blur', () => sendStatus.textContent = ''); -function updateElemHeight(el) { - el.style.removeProperty('height'); - if (el.value) { - el.style.paddingBottom = 0; - el.style.paddingTop = 0; - el.style.height = el.scrollHeight + 'px'; - el.style.removeProperty('padding-bottom'); - el.style.removeProperty('padding-top'); - } -} - diff --git a/src/utils/dom.ts b/src/utils/dom.ts index 81e9d7f..5088a5b 100644 --- a/src/utils/dom.ts +++ b/src/utils/dom.ts @@ -162,3 +162,17 @@ export const elemShrink = (el: HTMLElement) => { shrink.addEventListener('animationend', () => shrink.remove(), {once: true}); return shrink; }; + + +export const updateElemHeight = ( + el: HTMLInputElement | HTMLTextAreaElement +) => { + el.style.removeProperty('height'); + if (el.value) { + el.style.paddingBottom = '0'; + el.style.paddingTop = '0'; + el.style.height = el.scrollHeight + 'px'; + el.style.removeProperty('padding-bottom'); + el.style.removeProperty('padding-top'); + } +};