import autosize from "autosize"; import $ from "jquery"; import * as blueslip from "./blueslip"; import * as compose_state from "./compose_state"; import * as compose_ui from "./compose_ui"; import * as message_viewport from "./message_viewport"; function get_bottom_whitespace_height() { return message_viewport.height() * 0.4; } function get_new_heights() { const res = {}; const viewport_height = message_viewport.height(); const right_sidebar_shortcuts_height = $(".right-sidebar-shortcuts").outerHeight(true) ?? 0; res.stream_filters_max_height = viewport_height - Number.parseInt($("#left-sidebar").css("paddingTop"), 10) - Number.parseInt($("#left-sidebar-navigation-area").css("marginTop"), 10) - Number.parseInt($("#left-sidebar-navigation-area").css("marginBottom"), 10) - ($("#left-sidebar-navigation-list").outerHeight(true) ?? 0) - ($("#private_messages_sticky_header").outerHeight(true) ?? 0); // Don't let us crush the stream sidebar completely out of view res.stream_filters_max_height = Math.max(80, res.stream_filters_max_height); // RIGHT SIDEBAR const usable_height = viewport_height - Number.parseInt($("#right-sidebar").css("paddingTop"), 10) - ($("#userlist-header").outerHeight(true) ?? 0) - ($("#user_search_section").outerHeight(true) ?? 0) - right_sidebar_shortcuts_height; res.buddy_list_wrapper_max_height = Math.max(80, usable_height); return res; } export function watch_manual_resize(element) { const box = document.querySelector(element); if (!box) { blueslip.error("Bad selector in watch_manual_resize", {element}); return undefined; } const meta = { box, height: null, mousedown: false, }; const box_handler = function () { meta.mousedown = true; meta.height = meta.box.clientHeight; }; meta.box.addEventListener("mousedown", box_handler); // If the user resizes the textarea manually, we use the // callback to stop autosize from adjusting the height. // It will be re-enabled when this component is next opened. const body_handler = function () { if (meta.mousedown === true) { meta.mousedown = false; if (meta.height !== meta.box.clientHeight) { meta.height = meta.box.clientHeight; autosize.destroy($(element)).height(meta.height + "px"); } } }; document.body.addEventListener("mouseup", body_handler); return [box_handler, body_handler]; } export function reset_compose_message_max_height(bottom_whitespace_height) { // If the compose-box is open, we set the `max-height` property of // `compose-textarea` and `preview-textarea`, so that the // compose-box's maximum extent does not overlap the last message // in the current stream. We also leave a tiny bit of space after // the last message of the current stream. // Compute bottom_whitespace_height if not provided by caller. if (typeof bottom_whitespace_height !== "number") { bottom_whitespace_height = get_bottom_whitespace_height(); } const compose_height = $("#compose").get(0).getBoundingClientRect().height; const compose_textarea_height = Math.max( $("textarea#compose-textarea").get(0).getBoundingClientRect().height, $("#preview_message_area").get(0).getBoundingClientRect().height, ); const compose_non_textarea_height = compose_height - compose_textarea_height; // We ensure that the last message is not overlapped by compose box. $("textarea#compose-textarea").css( "max-height", // Because