widgetize: Move widget registration to new widgets module.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2023-10-06 10:22:44 -07:00 committed by Tim Abbott
parent 0c991d813f
commit e48771993b
4 changed files with 16 additions and 9 deletions

View File

@ -143,6 +143,7 @@ import * as user_status from "./user_status";
import * as user_status_ui from "./user_status_ui";
import * as user_topic_popover from "./user_topic_popover";
import * as user_topics from "./user_topics";
import * as widgets from "./widgets";
// This is where most of our initialization takes place.
// TODO: Organize it a lot better. In particular, move bigger
@ -532,6 +533,7 @@ export function initialize_everything() {
}
i18n.initialize(i18n_params);
widgets.initialize();
tippyjs.initialize();
compose_tooltips.initialize();
message_list_tooltips.initialize();

View File

@ -3,16 +3,8 @@ import $ from "jquery";
import * as blueslip from "./blueslip";
import * as message_lists from "./message_lists";
import * as narrow_state from "./narrow_state";
import * as poll_widget from "./poll_widget";
import * as todo_widget from "./todo_widget";
import * as zform from "./zform";
const widgets = new Map([
["poll", poll_widget],
["todo", todo_widget],
["zform", zform],
]);
export const widgets = new Map();
export const widget_contents = new Map();
export function clear_for_testing() {

10
web/src/widgets.js Normal file
View File

@ -0,0 +1,10 @@
import * as poll_widget from "./poll_widget";
import * as todo_widget from "./todo_widget";
import * as widgetize from "./widgetize";
import * as zform from "./zform";
export function initialize() {
widgetize.widgets.set("poll", poll_widget);
widgetize.widgets.set("todo", todo_widget);
widgetize.widgets.set("zform", zform);
}

View File

@ -61,6 +61,9 @@ mock_esm("../src/poll_widget", fake_poll_widget);
set_global("document", "document-stub");
const widgetize = zrequire("widgetize");
const widgets = zrequire("widgets");
widgets.initialize();
function test(label, f) {
run_test(label, ({override}) => {