mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	js: Convert static/js/rows.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							fe4d1e839c
						
					
				
				
					commit
					592cd780f5
				
			@@ -204,7 +204,6 @@
 | 
			
		||||
                "reload_state": false,
 | 
			
		||||
                "reminder": false,
 | 
			
		||||
                "resize": false,
 | 
			
		||||
                "rows": false,
 | 
			
		||||
                "scroll_bar": false,
 | 
			
		||||
                "search": false,
 | 
			
		||||
                "search_pill_widget": false,
 | 
			
		||||
 
 | 
			
		||||
@@ -20,7 +20,7 @@ const rows = zrequire("rows");
 | 
			
		||||
const lightbox = zrequire("lightbox");
 | 
			
		||||
const message_store = set_global("message_store", {});
 | 
			
		||||
 | 
			
		||||
rows.is_draft_row = () => false;
 | 
			
		||||
rows.__Rewire__("is_draft_row", () => false);
 | 
			
		||||
 | 
			
		||||
run_test("pan_and_zoom", (override) => {
 | 
			
		||||
    const img = $.create("img-stub");
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@
 | 
			
		||||
const {strict: assert} = require("assert");
 | 
			
		||||
 | 
			
		||||
const _ = require("lodash");
 | 
			
		||||
const rewiremock = require("rewiremock/node");
 | 
			
		||||
 | 
			
		||||
const {set_global, zrequire} = require("../zjsunit/namespace");
 | 
			
		||||
const {run_test} = require("../zjsunit/test");
 | 
			
		||||
@@ -32,7 +33,7 @@ set_global("timerender", {
 | 
			
		||||
    },
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
set_global("rows", {
 | 
			
		||||
rewiremock("../../static/js/rows").with({
 | 
			
		||||
    get_table() {
 | 
			
		||||
        return {
 | 
			
		||||
            children() {
 | 
			
		||||
@@ -44,6 +45,8 @@ set_global("rows", {
 | 
			
		||||
    },
 | 
			
		||||
});
 | 
			
		||||
 | 
			
		||||
rewiremock.enable();
 | 
			
		||||
 | 
			
		||||
const Filter = zrequire("Filter", "js/filter");
 | 
			
		||||
const MessageListView = zrequire("MessageListView", "js/message_list_view");
 | 
			
		||||
const message_list = zrequire("message_list");
 | 
			
		||||
@@ -542,3 +545,4 @@ run_test("render_windows", () => {
 | 
			
		||||
    verify_move(197, [0, 400]);
 | 
			
		||||
    verify_no_move_range(0, 350);
 | 
			
		||||
});
 | 
			
		||||
rewiremock.disable();
 | 
			
		||||
 
 | 
			
		||||
@@ -17,7 +17,9 @@ set_global("page_params", {
 | 
			
		||||
    realm_email_address_visibility: 3,
 | 
			
		||||
    custom_profile_fields: [],
 | 
			
		||||
});
 | 
			
		||||
const rows = set_global("rows", {});
 | 
			
		||||
const rows = {__esModule: true};
 | 
			
		||||
 | 
			
		||||
rewiremock("../../static/js/rows").with(rows);
 | 
			
		||||
 | 
			
		||||
rewiremock("../../static/js/message_viewport").with({
 | 
			
		||||
    height: () => 500,
 | 
			
		||||
 
 | 
			
		||||
@@ -18,7 +18,6 @@ import "../fold_dict";
 | 
			
		||||
import "../input_pill";
 | 
			
		||||
import "../setup";
 | 
			
		||||
import "../unread_ops";
 | 
			
		||||
import "../rows";
 | 
			
		||||
import "../user_groups";
 | 
			
		||||
import "../unread";
 | 
			
		||||
import "../topic_list";
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,7 @@ const render_buddy_list_tooltip_content = require("../templates/buddy_list_toolt
 | 
			
		||||
const channel = require("./channel");
 | 
			
		||||
const message_edit_history = require("./message_edit_history");
 | 
			
		||||
const muting_ui = require("./muting_ui");
 | 
			
		||||
const rows = require("./rows");
 | 
			
		||||
const settings_panel_menu = require("./settings_panel_menu");
 | 
			
		||||
const user_status_ui = require("./user_status_ui");
 | 
			
		||||
const util = require("./util");
 | 
			
		||||
 
 | 
			
		||||
@@ -4,6 +4,7 @@ const _ = require("lodash");
 | 
			
		||||
 | 
			
		||||
const message_viewport = require("./message_viewport");
 | 
			
		||||
const people = require("./people");
 | 
			
		||||
const rows = require("./rows");
 | 
			
		||||
const util = require("./util");
 | 
			
		||||
 | 
			
		||||
let focused_recipient;
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,7 @@ const typeahead = require("../shared/js/typeahead");
 | 
			
		||||
const channel = require("./channel");
 | 
			
		||||
const compose_pm_pill = require("./compose_pm_pill");
 | 
			
		||||
const people = require("./people");
 | 
			
		||||
const rows = require("./rows");
 | 
			
		||||
const settings_data = require("./settings_data");
 | 
			
		||||
const user_pill = require("./user_pill");
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
const message_viewport = require("./message_viewport");
 | 
			
		||||
const rows = require("./rows");
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
This library implements two related, similar concepts:
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
import TurndownService from "turndown/lib/turndown.cjs";
 | 
			
		||||
 | 
			
		||||
import * as rows from "./rows";
 | 
			
		||||
 | 
			
		||||
function find_boundary_tr(initial_tr, iterate_row) {
 | 
			
		||||
    let j;
 | 
			
		||||
    let skip_same_td_check = false;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
import * as alert_words from "./alert_words";
 | 
			
		||||
import * as people from "./people";
 | 
			
		||||
import * as rows from "./rows";
 | 
			
		||||
import * as util from "./util";
 | 
			
		||||
 | 
			
		||||
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html
 | 
			
		||||
 
 | 
			
		||||
@@ -8,6 +8,8 @@ const render_emoji_popover_content = require("../templates/emoji_popover_content
 | 
			
		||||
const render_emoji_popover_search_results = require("../templates/emoji_popover_search_results.hbs");
 | 
			
		||||
const render_emoji_showcase = require("../templates/emoji_showcase.hbs");
 | 
			
		||||
 | 
			
		||||
const rows = require("./rows");
 | 
			
		||||
 | 
			
		||||
// Emoji picker is of fixed width and height. Update these
 | 
			
		||||
// whenever these values are changed in `reactions.css`.
 | 
			
		||||
const APPROX_HEIGHT = 375;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
const rows = require("./rows");
 | 
			
		||||
 | 
			
		||||
let is_floating_recipient_bar_showing = false;
 | 
			
		||||
 | 
			
		||||
function top_offset(elem) {
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1
									
								
								static/js/global.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								static/js/global.d.ts
									
									
									
									
										vendored
									
									
								
							@@ -77,7 +77,6 @@ declare let reload: any;
 | 
			
		||||
declare let reload_state: any;
 | 
			
		||||
declare let reminder: any;
 | 
			
		||||
declare let resize: any;
 | 
			
		||||
declare let rows: any;
 | 
			
		||||
declare let scroll_bar: any;
 | 
			
		||||
declare let search: any;
 | 
			
		||||
declare let search_pill_widget: any;
 | 
			
		||||
 
 | 
			
		||||
@@ -2,6 +2,7 @@
 | 
			
		||||
 | 
			
		||||
const {LightboxCanvas} = require("./lightbox_canvas");
 | 
			
		||||
const people = require("./people");
 | 
			
		||||
const rows = require("./rows");
 | 
			
		||||
 | 
			
		||||
let is_open = false;
 | 
			
		||||
// the asset map is a map of all retrieved images and YouTube videos that are
 | 
			
		||||
 
 | 
			
		||||
@@ -9,6 +9,7 @@ const channel = require("./channel");
 | 
			
		||||
const echo = require("./echo");
 | 
			
		||||
const loading = require("./loading");
 | 
			
		||||
const message_viewport = require("./message_viewport");
 | 
			
		||||
const rows = require("./rows");
 | 
			
		||||
 | 
			
		||||
const currently_editing_messages = new Map();
 | 
			
		||||
let currently_deleting_messages = [];
 | 
			
		||||
 
 | 
			
		||||
@@ -11,6 +11,7 @@ const render_single_message = require("../templates/single_message.hbs");
 | 
			
		||||
const message_viewport = require("./message_viewport");
 | 
			
		||||
const people = require("./people");
 | 
			
		||||
const rendered_markdown = require("./rendered_markdown");
 | 
			
		||||
const rows = require("./rows");
 | 
			
		||||
const util = require("./util");
 | 
			
		||||
 | 
			
		||||
function same_day(earlier_msg, later_msg) {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,5 @@
 | 
			
		||||
import {media_breakpoints} from "./css_variables";
 | 
			
		||||
import * as rows from "./rows";
 | 
			
		||||
import * as util from "./util";
 | 
			
		||||
 | 
			
		||||
export let message_pane;
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
const message_viewport = require("./message_viewport");
 | 
			
		||||
const rows = require("./rows");
 | 
			
		||||
 | 
			
		||||
function go_to_row(msg_id) {
 | 
			
		||||
    current_msg_list.select_id(msg_id, {then_scroll: true, from_scroll: true});
 | 
			
		||||
 
 | 
			
		||||
@@ -22,6 +22,7 @@ const message_viewport = require("./message_viewport");
 | 
			
		||||
const muting = require("./muting");
 | 
			
		||||
const muting_ui = require("./muting_ui");
 | 
			
		||||
const people = require("./people");
 | 
			
		||||
const rows = require("./rows");
 | 
			
		||||
const settings_config = require("./settings_config");
 | 
			
		||||
const settings_data = require("./settings_data");
 | 
			
		||||
const user_status = require("./user_status");
 | 
			
		||||
 
 | 
			
		||||
@@ -1,9 +1,7 @@
 | 
			
		||||
"use strict";
 | 
			
		||||
 | 
			
		||||
// We don't need an andSelf() here because we already know
 | 
			
		||||
// that our next element is *not* a message_row, so this
 | 
			
		||||
// isn't going to end up empty unless we're at the bottom or top.
 | 
			
		||||
exports.next_visible = function (message_row) {
 | 
			
		||||
export function next_visible(message_row) {
 | 
			
		||||
    if (message_row === undefined || message_row.length === 0) {
 | 
			
		||||
        return $();
 | 
			
		||||
    }
 | 
			
		||||
@@ -11,15 +9,15 @@ exports.next_visible = function (message_row) {
 | 
			
		||||
    if (row.length !== 0) {
 | 
			
		||||
        return row;
 | 
			
		||||
    }
 | 
			
		||||
    const recipient_row = exports.get_message_recipient_row(message_row);
 | 
			
		||||
    const recipient_row = get_message_recipient_row(message_row);
 | 
			
		||||
    const next_recipient_rows = $(recipient_row).nextAll(".recipient_row");
 | 
			
		||||
    if (next_recipient_rows.length === 0) {
 | 
			
		||||
        return $();
 | 
			
		||||
    }
 | 
			
		||||
    return $(".selectable_row", next_recipient_rows[0]).first();
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.prev_visible = function (message_row) {
 | 
			
		||||
export function prev_visible(message_row) {
 | 
			
		||||
    if (message_row === undefined || message_row.length === 0) {
 | 
			
		||||
        return $();
 | 
			
		||||
    }
 | 
			
		||||
@@ -27,23 +25,23 @@ exports.prev_visible = function (message_row) {
 | 
			
		||||
    if (row.length !== 0) {
 | 
			
		||||
        return row;
 | 
			
		||||
    }
 | 
			
		||||
    const recipient_row = exports.get_message_recipient_row(message_row);
 | 
			
		||||
    const recipient_row = get_message_recipient_row(message_row);
 | 
			
		||||
    const prev_recipient_rows = $(recipient_row).prevAll(".recipient_row");
 | 
			
		||||
    if (prev_recipient_rows.length === 0) {
 | 
			
		||||
        return $();
 | 
			
		||||
    }
 | 
			
		||||
    return $(".selectable_row", prev_recipient_rows[0]).last();
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.first_visible = function () {
 | 
			
		||||
export function first_visible() {
 | 
			
		||||
    return $(".focused_table .selectable_row").first();
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.last_visible = function () {
 | 
			
		||||
export function last_visible() {
 | 
			
		||||
    return $(".focused_table .selectable_row").last();
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.visible_range = function (start_id, end_id) {
 | 
			
		||||
export function visible_range(start_id, end_id) {
 | 
			
		||||
    /*
 | 
			
		||||
        Get all visible rows between start_id
 | 
			
		||||
        and end_in, being inclusive on both ends.
 | 
			
		||||
@@ -52,7 +50,7 @@ exports.visible_range = function (start_id, end_id) {
 | 
			
		||||
    const rows = [];
 | 
			
		||||
 | 
			
		||||
    let row = current_msg_list.get_row(start_id);
 | 
			
		||||
    let msg_id = exports.id(row);
 | 
			
		||||
    let msg_id = id(row);
 | 
			
		||||
 | 
			
		||||
    while (msg_id <= end_id) {
 | 
			
		||||
        rows.push(row);
 | 
			
		||||
@@ -60,19 +58,19 @@ exports.visible_range = function (start_id, end_id) {
 | 
			
		||||
        if (msg_id >= end_id) {
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
        row = exports.next_visible(row);
 | 
			
		||||
        msg_id = exports.id(row);
 | 
			
		||||
        row = next_visible(row);
 | 
			
		||||
        msg_id = id(row);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return rows;
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.is_draft_row = function (row) {
 | 
			
		||||
export function is_draft_row(row) {
 | 
			
		||||
    return row.find(".restore-draft").length >= 1;
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.id = function (message_row) {
 | 
			
		||||
    if (exports.is_draft_row(message_row)) {
 | 
			
		||||
export function id(message_row) {
 | 
			
		||||
    if (is_draft_row(message_row)) {
 | 
			
		||||
        blueslip.error("Drafts have no zid");
 | 
			
		||||
        return undefined;
 | 
			
		||||
    }
 | 
			
		||||
@@ -96,9 +94,9 @@ exports.id = function (message_row) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return Number.parseFloat(zid);
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.local_echo_id = function (message_row) {
 | 
			
		||||
export function local_echo_id(message_row) {
 | 
			
		||||
    const zid = message_row.attr("zid");
 | 
			
		||||
 | 
			
		||||
    if (zid === undefined) {
 | 
			
		||||
@@ -111,63 +109,59 @@ exports.local_echo_id = function (message_row) {
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return zid;
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
const valid_table_names = new Set(["zhome", "zfilt"]);
 | 
			
		||||
 | 
			
		||||
exports.get_table = function (table_name) {
 | 
			
		||||
export function get_table(table_name) {
 | 
			
		||||
    if (!valid_table_names.has(table_name)) {
 | 
			
		||||
        return $();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return $(`#${CSS.escape(table_name)}`);
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.get_message_id = function (elem) {
 | 
			
		||||
export function get_message_id(elem) {
 | 
			
		||||
    // Gets the message_id for elem, where elem is a DOM
 | 
			
		||||
    // element inside a message.  This is typically used
 | 
			
		||||
    // in click handlers for things like the reaction button.
 | 
			
		||||
    const row = $(elem).closest(".message_row");
 | 
			
		||||
    const message_id = exports.id(row);
 | 
			
		||||
    const message_id = id(row);
 | 
			
		||||
    return message_id;
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.get_closest_group = function (element) {
 | 
			
		||||
export function get_closest_group(element) {
 | 
			
		||||
    // This gets the closest message row to an element, whether it's
 | 
			
		||||
    // a recipient bar or message.  With our current markup,
 | 
			
		||||
    // this is the most reliable way to do it.
 | 
			
		||||
    return $(element).closest("div.recipient_row");
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.first_message_in_group = function (message_group) {
 | 
			
		||||
export function first_message_in_group(message_group) {
 | 
			
		||||
    return $("div.message_row", message_group).first();
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.get_message_recipient_row = function (message_row) {
 | 
			
		||||
export function get_message_recipient_row(message_row) {
 | 
			
		||||
    return $(message_row).parent(".recipient_row").expectOne();
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.get_message_recipient_header = function (message_row) {
 | 
			
		||||
export function get_message_recipient_header(message_row) {
 | 
			
		||||
    return $(message_row).parent(".recipient_row").find(".message_header").expectOne();
 | 
			
		||||
};
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.recipient_from_group = function (message_group) {
 | 
			
		||||
    return message_store.get(
 | 
			
		||||
        exports.id($(message_group).children(".message_row").first().expectOne()),
 | 
			
		||||
    );
 | 
			
		||||
};
 | 
			
		||||
export function recipient_from_group(message_group) {
 | 
			
		||||
    return message_store.get(id($(message_group).children(".message_row").first().expectOne()));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
exports.id_for_recipient_row = function (recipient_row) {
 | 
			
		||||
export function id_for_recipient_row(recipient_row) {
 | 
			
		||||
    // A recipient row can be either a normal recipient row, or
 | 
			
		||||
    // the FRB, which is a fake recipient row. If it's a FRB, it has
 | 
			
		||||
    // a 'zid' property that stores the message id it is directly over
 | 
			
		||||
    const msg_row = exports.first_message_in_group(recipient_row);
 | 
			
		||||
    const msg_row = first_message_in_group(recipient_row);
 | 
			
		||||
    if (msg_row.length === 0) {
 | 
			
		||||
        // If we're narrowing from the FRB, take the msg id
 | 
			
		||||
        // directly from it
 | 
			
		||||
        return exports.id(recipient_row);
 | 
			
		||||
        return id(recipient_row);
 | 
			
		||||
    }
 | 
			
		||||
    return id(msg_row);
 | 
			
		||||
}
 | 
			
		||||
    return exports.id(msg_row);
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
window.rows = exports;
 | 
			
		||||
 
 | 
			
		||||
@@ -20,6 +20,7 @@ const message_viewport = require("./message_viewport");
 | 
			
		||||
const muting = require("./muting");
 | 
			
		||||
const people = require("./people");
 | 
			
		||||
const pm_conversations = require("./pm_conversations");
 | 
			
		||||
const rows = require("./rows");
 | 
			
		||||
const spoilers = require("./spoilers");
 | 
			
		||||
const topic_zoom = require("./topic_zoom");
 | 
			
		||||
const tutorial = require("./tutorial");
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user