Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

js: Convert static/js/rows.js to ES6 module.

Anders Kaseorg592cd780f533
diff --git a/.eslintrc.json b/.eslintrc.json
index 2e542a824f0..8e4140cd050 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -204,7 +204,6 @@
"reload_state": false,
"reminder": false,
"resize": false,
- "rows": false,
"scroll_bar": false,
"search": false,
"search_pill_widget": false,
diff --git a/frontend_tests/node_tests/lightbox.js b/frontend_tests/node_tests/lightbox.js
index 5c5fb34b856..bce5ee54366 100644
--- a/frontend_tests/node_tests/lightbox.js
+++ b/frontend_tests/node_tests/lightbox.js
@@ -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");
diff --git a/frontend_tests/node_tests/message_list_view.js b/frontend_tests/node_tests/message_list_view.js
index a6a76f3986d..9589d6ff982 100644
--- a/frontend_tests/node_tests/message_list_view.js
+++ b/frontend_tests/node_tests/message_list_view.js
@@ -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();
diff --git a/frontend_tests/node_tests/popovers.js b/frontend_tests/node_tests/popovers.js
index 4bf872ca7ba..2dcf4732694 100644
--- a/frontend_tests/node_tests/popovers.js
+++ b/frontend_tests/node_tests/popovers.js
@@ -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,
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index fdd18547b8c..723ca82f49e 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -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";
diff --git a/static/js/click_handlers.js b/static/js/click_handlers.js
index 2d1998d6986..804d7b0a56e 100644
--- a/static/js/click_handlers.js
+++ b/static/js/click_handlers.js
@@ -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");
diff --git a/static/js/compose_fade.js b/static/js/compose_fade.js
index 119e597eaf7..16550af0a46 100644
--- a/static/js/compose_fade.js
+++ b/static/js/compose_fade.js
@@ -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;
diff --git a/static/js/composebox_typeahead.js b/static/js/composebox_typeahead.js
index 45d7a9d64a5..b58cf061347 100644
--- a/static/js/composebox_typeahead.js
+++ b/static/js/composebox_typeahead.js
@@ -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");
diff --git a/static/js/condense.js b/static/js/condense.js
index 1b1917e3e3d..8faadb9ff0f 100644
--- a/static/js/condense.js
+++ b/static/js/condense.js
@@ -1,6 +1,7 @@
"use strict";
const message_viewport = require("./message_viewport");
+const rows = require("./rows");
/*
This library implements two related, similar concepts:
diff --git a/static/js/copy_and_paste.js b/static/js/copy_and_paste.js
index f2b553bcc73..d23b6380ad7 100644
--- a/static/js/copy_and_paste.js
+++ b/static/js/copy_and_paste.js
@@ -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;
diff --git a/static/js/echo.js b/static/js/echo.js
index a26a8632181..66cf60dabb0 100644
--- a/static/js/echo.js
+++ b/static/js/echo.js
@@ -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
diff --git a/static/js/emoji_picker.js b/static/js/emoji_picker.js
index 97518403ace..7eaf7641218 100644
--- a/static/js/emoji_picker.js
+++ b/static/js/emoji_picker.js
@@ -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;
diff --git a/static/js/floating_recipient_bar.js b/static/js/floating_recipient_bar.js
index 3bb68dab4f1..6f0e152f2cd 100644
--- a/static/js/floating_recipient_bar.js
+++ b/static/js/floating_recipient_bar.js
@@ -1,5 +1,7 @@
"use strict";
+const rows = require("./rows");
+
let is_floating_recipient_bar_showing = false;
function top_offset(elem) {
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index f20fae8e535..9dc256f2f1e 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -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;
diff --git a/static/js/lightbox.js b/static/js/lightbox.js
index 53089132d88..bf4cbf85eff 100644
--- a/static/js/lightbox.js
+++ b/static/js/lightbox.js
@@ -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
diff --git a/static/js/message_edit.js b/static/js/message_edit.js
index 3eacdff2ad9..ab1c5aaba0d 100644
--- a/static/js/message_edit.js
+++ b/static/js/message_edit.js
@@ -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 = [];
diff --git a/static/js/message_list_view.js b/static/js/message_list_view.js
index 32d8156cfc6..bffae9b481c 100644
--- a/static/js/message_list_view.js
+++ b/static/js/message_list_view.js
@@ -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) {
diff --git a/static/js/message_viewport.js b/static/js/message_viewport.js
index a63c34c113a..635248c9ef4 100644
--- a/static/js/message_viewport.js
+++ b/static/js/message_viewport.js
@@ -1,4 +1,5 @@
import {media_breakpoints} from "./css_variables";
+import * as rows from "./rows";
import * as util from "./util";
export let message_pane;
diff --git a/static/js/navigate.js b/static/js/navigate.js
index c0227335944..552ecf5e610 100644
--- a/static/js/navigate.js
+++ b/static/js/navigate.js
@@ -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});
diff --git a/static/js/popovers.js b/static/js/popovers.js
index 2d9161be702..af58b51dde5 100644
--- a/static/js/popovers.js
+++ b/static/js/popovers.js
@@ -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");
diff --git a/static/js/rows.js b/static/js/rows.js
index 512c43b9d8d..f83697294b0 100644
--- a/static/js/rows.js
+++ b/static/js/rows.js
@@ -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 exports.id(msg_row);
-};
-
-window.rows = exports;
+ return id(msg_row);
+}
diff --git a/static/js/ui_init.js b/static/js/ui_init.js
index 1d7ef09dd38..44098ae2fd4 100644
--- a/static/js/ui_init.js
+++ b/static/js/ui_init.js
@@ -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");