mirror of
https://github.com/zulip/zulip.git
synced 2025-11-12 09:58:06 +00:00
js: Convert static/js/widgetize.js to ES6 module.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
3e8ddc229b
commit
68872f44f6
@@ -151,7 +151,6 @@
|
||||
"subs": false,
|
||||
"ui": false,
|
||||
"ui_init": false,
|
||||
"widgetize": false,
|
||||
"zxcvbn": false
|
||||
}
|
||||
},
|
||||
|
||||
@@ -4,12 +4,13 @@ const {strict: assert} = require("assert");
|
||||
|
||||
const rewiremock = require("rewiremock/node");
|
||||
|
||||
const {set_global, zrequire} = require("../zjsunit/namespace");
|
||||
const {zrequire} = require("../zjsunit/namespace");
|
||||
const {run_test} = require("../zjsunit/test");
|
||||
|
||||
const channel = {__esModule: true};
|
||||
rewiremock("../../static/js/channel").with(channel);
|
||||
const widgetize = set_global("widgetize", {});
|
||||
const widgetize = {__esModule: true};
|
||||
rewiremock("../../static/js/widgetize").with(widgetize);
|
||||
const message_store = {__esModule: true};
|
||||
|
||||
rewiremock("../../static/js/message_store").with(message_store);
|
||||
|
||||
@@ -16,7 +16,6 @@ import "flatpickr/dist/plugins/confirmDate/confirmDate";
|
||||
import "../i18n";
|
||||
import "../fold_dict";
|
||||
import "../setup";
|
||||
import "../widgetize";
|
||||
import "../message_list";
|
||||
import "../narrow";
|
||||
import "../reload";
|
||||
|
||||
1
static/js/global.d.ts
vendored
1
static/js/global.d.ts
vendored
@@ -20,7 +20,6 @@ declare let pointer: any;
|
||||
declare let settings_profile_fields: any;
|
||||
declare let subs: any;
|
||||
declare let ui: any;
|
||||
declare let widgetize: any;
|
||||
declare let zulip_test: any;
|
||||
|
||||
interface JQuery {
|
||||
|
||||
@@ -31,6 +31,7 @@ const ui_util = require("./ui_util");
|
||||
const unread = require("./unread");
|
||||
const unread_ops = require("./unread_ops");
|
||||
const util = require("./util");
|
||||
const widgetize = require("./widgetize");
|
||||
|
||||
let unnarrow_times;
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import * as channel from "./channel";
|
||||
import * as message_store from "./message_store";
|
||||
import * as widgetize from "./widgetize";
|
||||
|
||||
export function get_message_events(message) {
|
||||
if (message.locally_echoed) {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
"use strict";
|
||||
|
||||
const narrow_state = require("./narrow_state");
|
||||
const poll_widget = require("./poll_widget");
|
||||
const todo_widget = require("./todo_widget");
|
||||
const zform = require("./zform");
|
||||
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],
|
||||
@@ -11,15 +9,14 @@ const widgets = new Map([
|
||||
["zform", zform],
|
||||
]);
|
||||
|
||||
const widget_contents = new Map();
|
||||
exports.widget_contents = widget_contents;
|
||||
export const widget_contents = new Map();
|
||||
|
||||
function set_widget_in_message(row, widget_elem) {
|
||||
const content_holder = row.find(".message_content");
|
||||
content_holder.empty().append(widget_elem);
|
||||
}
|
||||
|
||||
exports.activate = function (in_opts) {
|
||||
export function activate(in_opts) {
|
||||
const widget_type = in_opts.widget_type;
|
||||
const extra_data = in_opts.extra_data;
|
||||
const events = in_opts.events;
|
||||
@@ -76,18 +73,18 @@ exports.activate = function (in_opts) {
|
||||
if (events.length > 0) {
|
||||
widget_elem.handle_events(events);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.set_widgets_for_list = function () {
|
||||
export function set_widgets_for_list() {
|
||||
for (const [idx, widget_elem] of widget_contents) {
|
||||
if (current_msg_list.get(idx) !== undefined) {
|
||||
const row = current_msg_list.get_row(idx);
|
||||
set_widget_in_message(row, widget_elem);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
exports.handle_event = function (widget_event) {
|
||||
export function handle_event(widget_event) {
|
||||
const widget_elem = widget_contents.get(widget_event.message_id);
|
||||
|
||||
if (!widget_elem) {
|
||||
@@ -100,6 +97,4 @@ exports.handle_event = function (widget_event) {
|
||||
const events = [widget_event];
|
||||
|
||||
widget_elem.handle_events(events);
|
||||
};
|
||||
|
||||
window.widgetize = exports;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user