feat: composer block fits its content, keeps a height the person dragged to
Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
1 parent
360d93f589
commit
406f00f0e4
6 files changed
+260
-14
No files matched your search
@@ -516,3 +516,55 @@ export function directSendBlocked({ draining, mode, status, queue }) {
|
||||
if (mode === "now" || status === "blocked") return false;
|
||||
return queueBlocksDirectSend(queue);
|
||||
}
|
||||
|
||||
// --- the height of the composer block ----------------------------------------
|
||||
//
|
||||
// The block is as tall as its content (menu, queue, notices, card, strip),
|
||||
// unless the person dragged its border: then that height is the floor.
|
||||
|
||||
/**
|
||||
* The height the block should have, in the pixels of the layout.
|
||||
*
|
||||
* What the content measures is in logical pixels (layout px times the zoom of
|
||||
* the app), plus the padding of the root; the floor is what the person dragged
|
||||
* the block to (`userMin`, 0 for none); the result stays inside the range the
|
||||
* layout allows.
|
||||
*
|
||||
* @param {{contentHeight:number, padding:number, zoom:number, userMin:number, min:number, max:number}} input
|
||||
* @returns {number}
|
||||
*/
|
||||
export function blockTargetPx({ contentHeight, padding, zoom, userMin, min, max }) {
|
||||
const factor = Number.isFinite(zoom) && zoom > 0 ? zoom : 1;
|
||||
const need = Math.ceil((contentHeight + padding) / factor);
|
||||
const wanted = Math.max(need, Number.isFinite(userMin) ? userMin : 0);
|
||||
return Math.round(Math.min(max, Math.max(min, wanted)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the difference worth a `layout.resize`? Under 5 px it is not: typing and
|
||||
* the growing of the field must not make the block twitch.
|
||||
*
|
||||
* @param {number|null|undefined} current
|
||||
* @param {number|null|undefined} target
|
||||
* @param {number} [threshold]
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function shouldResize(current, target, threshold = 4) {
|
||||
if (!Number.isFinite(current) || !Number.isFinite(target)) return false;
|
||||
return Math.abs(current - target) > threshold;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is a reported height the person's drag?
|
||||
*
|
||||
* The composer keeps the height it ordered last (`orderedPx`); a height it did
|
||||
* not order is somebody dragging the border. Before anything was ordered the
|
||||
* first height is the layout's own, not a drag.
|
||||
*
|
||||
* @param {{reportedPx:number, orderedPx:number|null, tolerance?:number}} input
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function isManualResize({ reportedPx, orderedPx, tolerance = 3 }) {
|
||||
if (!Number.isFinite(reportedPx) || !Number.isFinite(orderedPx)) return false;
|
||||
return Math.abs(reportedPx - orderedPx) > tolerance;
|
||||
}
|
||||
Reference in new issue
Block a user