Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
js: Convert static/js/zcommand.js to ES6 module.
Anders Kaseorg9dd03998f86f
diff --git a/.eslintrc.json b/.eslintrc.jsonindex 3a2870d51ec..6fade139bbf 100644--- a/.eslintrc.json+++ b/.eslintrc.json@@ -304,7 +304,6 @@"poll_widget": false,"vdom": false,"widgetize": false,- "zcommand": false,"zxcvbn": false}},diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.jsindex 61c7cb5711e..2ffeda9516e 100644--- a/frontend_tests/node_tests/compose.js+++ b/frontend_tests/node_tests/compose.js@@ -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");diff --git a/static/js/bundles/app.js b/static/js/bundles/app.jsindex 84d1800463a..4f27936bd2b 100644--- a/static/js/bundles/app.js+++ b/static/js/bundles/app.js@@ -61,7 +61,6 @@ import "../sent_messages";import "../compose_state";import "../compose_actions";import "../transmit";-import "../zcommand";import "../compose";import "../upload";import "../color_data";diff --git a/static/js/compose.js b/static/js/compose.jsindex 351b0a84bb4..bccb137f6d4 100644--- a/static/js/compose.js+++ b/static/js/compose.js@@ -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.htmldiff --git a/static/js/global.d.ts b/static/js/global.d.tsindex 43710d7f356..133d8bf78eb 100644--- a/static/js/global.d.ts+++ b/static/js/global.d.ts@@ -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;diff --git a/static/js/zcommand.js b/static/js/zcommand.jsindex 0069f7e80e5..29c09ad287b 100644--- a/static/js/zcommand.js+++ b/static/js/zcommand.js@@ -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;+}