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

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg 2021-02-10 07:54:18 -08:00 committed by Tim Abbott
parent 1a45d53f3a
commit 9dd03998f8
6 changed files with 32 additions and 39 deletions

View File

@ -304,7 +304,6 @@
"poll_widget": false,
"vdom": false,
"widgetize": false,
"zcommand": false,
"zxcvbn": false
}
},

View File

@ -75,7 +75,6 @@ document.location.host = "foo.com";
const fake_now = 555;
MockDate.set(new Date(fake_now * 1000));
zrequire("zcommand");
const compose_ui = zrequire("compose_ui");
const peer_data = zrequire("peer_data");
const util = zrequire("util");

View File

@ -61,7 +61,6 @@ import "../sent_messages";
import "../compose_state";
import "../compose_actions";
import "../transmit";
import "../zcommand";
import "../compose";
import "../upload";
import "../color_data";

View File

@ -15,6 +15,7 @@ const people = require("./people");
const rendered_markdown = require("./rendered_markdown");
const settings_config = require("./settings_config");
const util = require("./util");
const zcommand = require("./zcommand");
// Docs: https://zulip.readthedocs.io/en/latest/subsystems/sending-messages.html

View File

@ -167,4 +167,3 @@ declare let user_pill: any;
declare let user_status: any;
declare let user_status_ui: any;
declare let widgetize: any;
declare let zcommand: any;

View File

@ -1,8 +1,6 @@
"use strict";
import marked from "../third/marked/lib/marked";
const marked = require("../third/marked/lib/marked");
const feedback_widget = require("./feedback_widget");
import * as feedback_widget from "./feedback_widget";
/*
@ -22,7 +20,7 @@ What in the heck is a zcommand?
*/
exports.send = function (opts) {
export function send(opts) {
const command = opts.command;
const on_success = opts.on_success;
const data = {
@ -38,12 +36,12 @@ exports.send = function (opts) {
}
},
error() {
exports.tell_user("server did not respond");
tell_user("server did not respond");
},
});
};
}
exports.tell_user = function (msg) {
export function tell_user(msg) {
// This is a bit hacky, but we don't have a super easy API now
// for just telling users stuff.
$("#compose-send-status")
@ -52,10 +50,10 @@ exports.tell_user = function (msg) {
.stop(true)
.fadeTo(0, 1);
$("#compose-error-msg").text(msg);
};
}
exports.enter_day_mode = function () {
exports.send({
export function enter_day_mode() {
send({
command: "/day",
on_success(data) {
night_mode.disable();
@ -65,7 +63,7 @@ exports.enter_day_mode = function () {
container.html(rendered_msg);
},
on_undo() {
exports.send({
send({
command: "/night",
});
},
@ -74,10 +72,10 @@ exports.enter_day_mode = function () {
});
},
});
};
}
exports.enter_night_mode = function () {
exports.send({
export function enter_night_mode() {
send({
command: "/night",
on_success(data) {
night_mode.enable();
@ -87,7 +85,7 @@ exports.enter_night_mode = function () {
container.html(rendered_msg);
},
on_undo() {
exports.send({
send({
command: "/day",
});
},
@ -96,10 +94,10 @@ exports.enter_night_mode = function () {
});
},
});
};
}
exports.enter_fluid_mode = function () {
exports.send({
export function enter_fluid_mode() {
send({
command: "/fluid-width",
on_success(data) {
scroll_bar.set_layout_width();
@ -109,7 +107,7 @@ exports.enter_fluid_mode = function () {
container.html(rendered_msg);
},
on_undo() {
exports.send({
send({
command: "/fixed-width",
});
},
@ -118,10 +116,10 @@ exports.enter_fluid_mode = function () {
});
},
});
};
}
exports.enter_fixed_mode = function () {
exports.send({
export function enter_fixed_mode() {
send({
command: "/fixed-width",
on_success(data) {
scroll_bar.set_layout_width();
@ -131,7 +129,7 @@ exports.enter_fixed_mode = function () {
container.html(rendered_msg);
},
on_undo() {
exports.send({
send({
command: "/fluid-width",
});
},
@ -140,22 +138,22 @@ exports.enter_fixed_mode = function () {
});
},
});
};
}
exports.process = function (message_content) {
export function process(message_content) {
const content = message_content.trim();
if (content === "/ping") {
const start_time = new Date();
exports.send({
send({
command: content,
on_success() {
const end_time = new Date();
let diff = end_time - start_time;
diff = Math.round(diff);
const msg = "ping time: " + diff + "ms";
exports.tell_user(msg);
tell_user(msg);
},
});
return true;
@ -163,23 +161,23 @@ exports.process = function (message_content) {
const day_commands = ["/day", "/light"];
if (day_commands.includes(content)) {
exports.enter_day_mode();
enter_day_mode();
return true;
}
const night_commands = ["/night", "/dark"];
if (night_commands.includes(content)) {
exports.enter_night_mode();
enter_night_mode();
return true;
}
if (content === "/fluid-width") {
exports.enter_fluid_mode();
enter_fluid_mode();
return true;
}
if (content === "/fixed-width") {
exports.enter_fixed_mode();
enter_fixed_mode();
return true;
}
@ -192,6 +190,4 @@ exports.process = function (message_content) {
// if we don't see an actual zcommand, so that compose.js
// knows this is a normal message.
return false;
};
window.zcommand = exports;
}