From 9dd03998f86f5a0df024ecd648d6848c29218aec Mon Sep 17 00:00:00 2001 From: Anders Kaseorg Date: Wed, 10 Feb 2021 07:54:18 -0800 Subject: [PATCH] js: Convert static/js/zcommand.js to ES6 module. Signed-off-by: Anders Kaseorg --- .eslintrc.json | 1 - frontend_tests/node_tests/compose.js | 1 - static/js/bundles/app.js | 1 - static/js/compose.js | 1 + static/js/global.d.ts | 1 - static/js/zcommand.js | 66 +++++++++++++--------------- 6 files changed, 32 insertions(+), 39 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 3a2870d51e..6fade139bb 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.js index 61c7cb5711..2ffeda9516 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.js index 84d1800463..4f27936bd2 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.js index 351b0a84bb..bccb137f6d 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.html diff --git a/static/js/global.d.ts b/static/js/global.d.ts index 43710d7f35..133d8bf78e 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.js index 0069f7e80e..29c09ad287 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; +}