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/keydown_util.js to ES6 module.

Anders Kaseorgf85924dd0a37
diff --git a/.eslintrc.json b/.eslintrc.json
index cd9db74ba73..b003eab8179 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -167,7 +167,6 @@
"info_overlay": false,
"input_pill": false,
"jQuery": false,
- "keydown_util": false,
"lightbox": false,
"list_util": false,
"ListWidget": false,
diff --git a/frontend_tests/node_tests/activity.js b/frontend_tests/node_tests/activity.js
index 576f5c74d6d..f8b67591fb7 100644
--- a/frontend_tests/node_tests/activity.js
+++ b/frontend_tests/node_tests/activity.js
@@ -2,6 +2,8 @@
const {strict: assert} = require("assert");
+const rewiremock = require("rewiremock/node");
+
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
const $ = require("../zjsunit/zjquery");
@@ -30,6 +32,8 @@ const _ui = {
};
const _keydown_util = {
+ __esModule: true,
+
handle: (opts) => {
filter_key_handlers = opts.handlers;
},
@@ -66,7 +70,7 @@ set_global("padded_widget", {
set_global("channel", channel);
set_global("compose_state", compose_state);
set_global("document", _document);
-set_global("keydown_util", _keydown_util);
+rewiremock("../../static/js/keydown_util").with(_keydown_util);
set_global("pm_list", _pm_list);
set_global("popovers", _popovers);
set_global("resize", _resize);
@@ -77,6 +81,8 @@ set_global("server_events", {
check_for_unsuspend() {},
});
+rewiremock.enable();
+
const huddle_data = zrequire("huddle_data");
const compose_fade = zrequire("compose_fade");
zrequire("unread");
@@ -750,3 +756,4 @@ test_ui("test_send_or_receive_no_presence_for_web_public_visitor", () => {
page_params.is_web_public_visitor = true;
activity.send_presence_to_server();
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/components.js b/frontend_tests/node_tests/components.js
index aeaf821bff3..32762ebbc2d 100644
--- a/frontend_tests/node_tests/components.js
+++ b/frontend_tests/node_tests/components.js
@@ -7,7 +7,6 @@ const _ = require("lodash");
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
-zrequire("keydown_util");
const components = zrequire("components");
const noop = () => {};
diff --git a/frontend_tests/node_tests/stream_list.js b/frontend_tests/node_tests/stream_list.js
index f7c3036ad35..c24f410c3ba 100644
--- a/frontend_tests/node_tests/stream_list.js
+++ b/frontend_tests/node_tests/stream_list.js
@@ -2,6 +2,8 @@
const {strict: assert} = require("assert");
+const rewiremock = require("rewiremock/node");
+
const {stub_templates} = require("../zjsunit/handlebars");
const {set_global, zrequire} = require("../zjsunit/namespace");
const {run_test} = require("../zjsunit/test");
@@ -20,10 +22,12 @@ const topic_list = set_global("topic_list", {});
set_global("overlays", {});
set_global("popovers", {});
-set_global("keydown_util", {
+rewiremock("../../static/js/keydown_util").with({
handle: noop,
});
+rewiremock.enable();
+
zrequire("unread_ui");
const Filter = zrequire("Filter", "js/filter");
const stream_sort = zrequire("stream_sort");
@@ -747,3 +751,4 @@ test_ui("create_initial_sidebar_rows", () => {
assert.equal(html_dict.get(1000), "<div>stub-html-devel");
assert.equal(html_dict.get(5000), "<div>stub-html-Denmark");
});
+rewiremock.disable();
diff --git a/frontend_tests/node_tests/ui_init.js b/frontend_tests/node_tests/ui_init.js
index cbda5417524..cde492c0e2c 100644
--- a/frontend_tests/node_tests/ui_init.js
+++ b/frontend_tests/node_tests/ui_init.js
@@ -128,7 +128,6 @@ zrequire("search_suggestion");
zrequire("search");
zrequire("notifications");
zrequire("pm_list");
-zrequire("keydown_util");
zrequire("stream_list");
zrequire("topic_list");
zrequire("sent_messages");
diff --git a/static/js/activity.js b/static/js/activity.js
index a375558f06b..6bcb2c18acb 100644
--- a/static/js/activity.js
+++ b/static/js/activity.js
@@ -2,6 +2,7 @@
const _ = require("lodash");
+const keydown_util = require("./keydown_util");
const {ListCursor} = require("./list_cursor");
const people = require("./people");
const {UserSearch} = require("./user_search");
diff --git a/static/js/bundles/app.js b/static/js/bundles/app.js
index 24954c15f85..1c57c727291 100644
--- a/static/js/bundles/app.js
+++ b/static/js/bundles/app.js
@@ -14,7 +14,6 @@ import "flatpickr/dist/plugins/confirmDate/confirmDate";
// Import app JS
import "../i18n";
-import "../keydown_util";
import "../rtl";
import "../fold_dict";
import "../scroll_util";
diff --git a/static/js/components.js b/static/js/components.js
index 8bc80361f47..76dbc1d45e9 100644
--- a/static/js/components.js
+++ b/static/js/components.js
@@ -1,3 +1,4 @@
+import * as keydown_util from "./keydown_util";
/* USAGE:
Toggle x = components.toggle({
selected: Integer selected_index,
diff --git a/static/js/global.d.ts b/static/js/global.d.ts
index c6849a05718..5c22190c7e5 100644
--- a/static/js/global.d.ts
+++ b/static/js/global.d.ts
@@ -43,7 +43,6 @@ declare let hotspots: any;
declare let i18n: any;
declare let info_overlay: any;
declare let input_pill: any;
-declare let keydown_util: any;
declare let lightbox: any;
declare let list_util: any;
declare let list_widget: any;
diff --git a/static/js/info_overlay.js b/static/js/info_overlay.js
index 7ad50b1db57..755c155c256 100644
--- a/static/js/info_overlay.js
+++ b/static/js/info_overlay.js
@@ -2,6 +2,7 @@
const common = require("./common");
const components = require("./components");
+const keydown_util = require("./keydown_util");
// Make it explicit that our toggler is undefined until
// set_up_toggler is called.
diff --git a/static/js/keydown_util.js b/static/js/keydown_util.js
index 92ec7bde73c..ace21ffabcc 100644
--- a/static/js/keydown_util.js
+++ b/static/js/keydown_util.js
@@ -1,5 +1,3 @@
-"use strict";
-
/*
See hotkey.js for handlers that are more app-wide.
*/
@@ -12,7 +10,7 @@ const keys = {
40: "down_arrow",
};
-exports.handle = function (opts) {
+export function handle(opts) {
opts.elem.on("keydown", (e) => {
const key = e.which || e.keyCode;
@@ -37,6 +35,4 @@ exports.handle = function (opts) {
e.stopPropagation();
}
});
-};
-
-window.keydown_util = exports;
+}
diff --git a/static/js/settings_panel_menu.js b/static/js/settings_panel_menu.js
index 8d2bdcdc950..9de647a8213 100644
--- a/static/js/settings_panel_menu.js
+++ b/static/js/settings_panel_menu.js
@@ -1,5 +1,7 @@
"use strict";
+const keydown_util = require("./keydown_util");
+
exports.mobile_deactivate_section = function () {
const $settings_overlay_container = $("#settings_overlay_container");
$settings_overlay_container.find(".right").removeClass("show");
diff --git a/static/js/stream_list.js b/static/js/stream_list.js
index 8603d851aed..9010baf50bf 100644
--- a/static/js/stream_list.js
+++ b/static/js/stream_list.js
@@ -5,6 +5,7 @@ const _ = require("lodash");
const render_stream_privacy = require("../templates/stream_privacy.hbs");
const render_stream_sidebar_row = require("../templates/stream_sidebar_row.hbs");
+const keydown_util = require("./keydown_util");
const {ListCursor} = require("./list_cursor");
const stream_sort = require("./stream_sort");
const topic_zoom = require("./topic_zoom");